From 83ee97498db28cb3e092f26f1a9169fbff1b1c6e Mon Sep 17 00:00:00 2001 From: Pablo Neira Ayuso Date: Thu, 30 Oct 2008 13:24:13 +0100 Subject: API: use of __builtin_expect in error checking paths This patch introduces likely() and unlikely() that use __builtin_expect to assist the compiler in the branch decisions. I am assuming that we have no clients of libnetfilter_conntrack that use gcc < 2.96. Signed-off-by: Pablo Neira Ayuso --- src/conntrack/api.c | 16 ++++++++-------- src/conntrack/objopt.c | 4 ++-- 2 files changed, 10 insertions(+), 10 deletions(-) (limited to 'src/conntrack') diff --git a/src/conntrack/api.c b/src/conntrack/api.c index 7943082..61d3237 100644 --- a/src/conntrack/api.c +++ b/src/conntrack/api.c @@ -103,7 +103,7 @@ int nfct_setobjopt(struct nf_conntrack *ct, unsigned int option) { assert(ct != NULL); - if (option > NFCT_SOPT_MAX) { + if (unlikely(option > NFCT_SOPT_MAX)) { errno = EOPNOTSUPP; return -1; } @@ -123,7 +123,7 @@ int nfct_getobjopt(const struct nf_conntrack *ct, unsigned int option) { assert(ct != NULL); - if (option > NFCT_GOPT_MAX) { + if (unlikely(option > NFCT_GOPT_MAX)) { errno = EOPNOTSUPP; return -1; } @@ -218,7 +218,7 @@ void nfct_set_attr(struct nf_conntrack *ct, assert(ct != NULL); assert(value != NULL); - if (type >= ATTR_MAX) + if (unlikely(type >= ATTR_MAX)) return; if (set_attr_array[type]) { @@ -279,7 +279,7 @@ const void *nfct_get_attr(const struct nf_conntrack *ct, { assert(ct != NULL); - if (type >= ATTR_MAX) { + if (unlikely(type >= ATTR_MAX)) { errno = EINVAL; return NULL; } @@ -355,7 +355,7 @@ int nfct_attr_is_set(const struct nf_conntrack *ct, { assert(ct != NULL); - if (type >= ATTR_MAX) { + if (unlikely(type >= ATTR_MAX)) { errno = EINVAL; return -1; } @@ -375,7 +375,7 @@ int nfct_attr_unset(struct nf_conntrack *ct, { assert(ct != NULL); - if (type >= ATTR_MAX) { + if (unlikely(type >= ATTR_MAX)) { errno = EINVAL; return -1; } @@ -893,7 +893,7 @@ void nfct_filter_add_attr(struct nfct_filter *filter, assert(filter != NULL); assert(value != NULL); - if (type >= NFCT_FILTER_MAX) + if (unlikely(type >= NFCT_FILTER_MAX)) return; if (filter_attr_array[type]) { @@ -934,7 +934,7 @@ int nfct_filter_set_logic(struct nfct_filter *filter, const enum nfct_filter_attr type, const enum nfct_filter_logic logic) { - if (type >= NFCT_FILTER_MAX) { + if (unlikely(type >= NFCT_FILTER_MAX)) { errno = ENOTSUP; return -1; } diff --git a/src/conntrack/objopt.c b/src/conntrack/objopt.c index 822215f..682cba1 100644 --- a/src/conntrack/objopt.c +++ b/src/conntrack/objopt.c @@ -83,7 +83,7 @@ setobjopt setobjopt_array[] = { int __setobjopt(struct nf_conntrack *ct, unsigned int option) { - if (option > NFCT_SOPT_MAX) + if (unlikely(option > NFCT_SOPT_MAX)) return -1; setobjopt_array[option](ct); @@ -131,7 +131,7 @@ getobjopt getobjopt_array[] = { int __getobjopt(const struct nf_conntrack *ct, unsigned int option) { - if (option > NFCT_GOPT_MAX) + if (unlikely(option > NFCT_GOPT_MAX)) return -1; return getobjopt_array[option](ct); -- cgit v1.2.3