netfilter: xtables: use memcmp in unconditional check

Instead of inspecting each u32/char open-coded, clean up and make use
of memcmp. On some arches, memcmp is implemented as assembly or GCC's
__builtin_memcmp which can possibly take advantages of known
alignment.

Signed-off-by: Jan Engelhardt <jengelh@medozas.de>
This commit is contained in:
Jan Engelhardt 2009-07-09 23:00:19 +02:00
parent e5afbba186
commit 47901dc2c4
3 changed files with 9 additions and 23 deletions

View File

@ -341,15 +341,11 @@ unsigned int arpt_do_table(struct sk_buff *skb,
} }
/* All zeroes == unconditional rule. */ /* All zeroes == unconditional rule. */
static inline int unconditional(const struct arpt_arp *arp) static inline bool unconditional(const struct arpt_arp *arp)
{ {
unsigned int i; static const struct arpt_arp uncond;
for (i = 0; i < sizeof(*arp)/sizeof(__u32); i++) return memcmp(arp, &uncond, sizeof(uncond)) == 0;
if (((__u32 *)arp)[i])
return 0;
return 1;
} }
/* Figures out from what hook each rule can be called: returns 0 if /* Figures out from what hook each rule can be called: returns 0 if

View File

@ -190,16 +190,11 @@ get_entry(void *base, unsigned int offset)
/* All zeroes == unconditional rule. */ /* All zeroes == unconditional rule. */
/* Mildly perf critical (only if packet tracing is on) */ /* Mildly perf critical (only if packet tracing is on) */
static inline int static inline bool unconditional(const struct ipt_ip *ip)
unconditional(const struct ipt_ip *ip)
{ {
unsigned int i; static const struct ipt_ip uncond;
for (i = 0; i < sizeof(*ip)/sizeof(__u32); i++) return memcmp(ip, &uncond, sizeof(uncond)) == 0;
if (((__u32 *)ip)[i])
return 0;
return 1;
#undef FWINV #undef FWINV
} }

View File

@ -222,16 +222,11 @@ get_entry(void *base, unsigned int offset)
/* All zeroes == unconditional rule. */ /* All zeroes == unconditional rule. */
/* Mildly perf critical (only if packet tracing is on) */ /* Mildly perf critical (only if packet tracing is on) */
static inline int static inline bool unconditional(const struct ip6t_ip6 *ipv6)
unconditional(const struct ip6t_ip6 *ipv6)
{ {
unsigned int i; static const struct ip6t_ip6 uncond;
for (i = 0; i < sizeof(*ipv6); i++) return memcmp(ipv6, &uncond, sizeof(uncond)) == 0;
if (((char *)ipv6)[i])
break;
return (i == sizeof(*ipv6));
} }
#if defined(CONFIG_NETFILTER_XT_TARGET_TRACE) || \ #if defined(CONFIG_NETFILTER_XT_TARGET_TRACE) || \