netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Richard Weinberger <richard@nod.at>
To: davem@davemloft.net
Cc: coreteam@netfilter.org, netfilter-devel@vger.kernel.org,
	linux-kernel@vger.kernel.org, netdev@vger.kernel.org,
	bhutchings@solarflare.com, john.fastabend@gmail.com,
	herbert@gondor.apana.org.au, vyasevic@redhat.com,
	jiri@resnulli.us, vfalico@gmail.com, therbert@google.com,
	edumazet@google.com, yoshfuji@linux-ipv6.org, jmorris@namei.org,
	kuznet@ms2.inr.ac.ru, kadlec@blackhole.kfki.hu, kaber@trash.net,
	pablo@netfilter.org, kay@vrfy.org, stephen@networkplumber.org,
	Richard Weinberger <richard@nod.at>
Subject: [PATCH 3/3] x_tables: Factor out 16bit aligment ifname_compare()
Date: Sun, 11 Jan 2015 21:52:51 +0100	[thread overview]
Message-ID: <1421009571-5279-4-git-send-email-richard@nod.at> (raw)
In-Reply-To: <1421009571-5279-1-git-send-email-richard@nod.at>

arp_tables.c has a 16bit aligment ifname_compare(), factor
it out to use it for all tables.

Signed-off-by: Richard Weinberger <richard@nod.at>
---
 include/linux/netfilter/x_tables.h | 25 ++++++++++++++++++-------
 net/ipv4/netfilter/arp_tables.c    | 37 ++-----------------------------------
 2 files changed, 20 insertions(+), 42 deletions(-)

diff --git a/include/linux/netfilter/x_tables.h b/include/linux/netfilter/x_tables.h
index 15bda23..26dddc1 100644
--- a/include/linux/netfilter/x_tables.h
+++ b/include/linux/netfilter/x_tables.h
@@ -331,14 +331,15 @@ static inline void xt_write_recseq_end(unsigned int addend)
 /*
  * This helper is performance critical and must be inlined
  */
-static inline unsigned long ifname_compare_aligned(const char *_a,
-						   const char *_b,
-						   const char *_mask)
+static inline unsigned long ifname_compare(const char *_a,
+					   const char *_b,
+					   const char *_mask)
 {
+	unsigned long ret;
+#ifdef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
 	const unsigned long *a = (const unsigned long *)_a;
 	const unsigned long *b = (const unsigned long *)_b;
 	const unsigned long *mask = (const unsigned long *)_mask;
-	unsigned long ret;
 
 	ret = (a[0] ^ b[0]) & mask[0];
 	if (IFNAMSIZ > sizeof(unsigned long))
@@ -348,11 +349,21 @@ static inline unsigned long ifname_compare_aligned(const char *_a,
 	if (IFNAMSIZ > 3 * sizeof(unsigned long))
 		ret |= (a[3] ^ b[3]) & mask[3];
 	BUILD_BUG_ON(IFNAMSIZ > 4 * sizeof(unsigned long));
+#else
+	const u16 *a = (const u16 *)_a;
+	const u16 *b = (const u16 *)_b;
+	const u16 *mask = (const u16 *)_mask;
+	int i;
+
+	ret = 0;
+	for (i = 0; i < IFNAMSIZ/sizeof(u16); i++)
+		ret |= (a[i] ^ b[i]) & mask[i];
+#endif
 	return ret;
 }
 
 /*
- * A wrapper around ifname_compare_aligned() to match against dev->name and
+ * A wrapper around ifname_compare() to match against dev->name and
  * dev->ifalias.
  */
 static inline unsigned long ifname_compare_all(const struct net_device *dev,
@@ -364,9 +375,9 @@ static inline unsigned long ifname_compare_all(const struct net_device *dev,
 	if (!dev)
 		goto out;
 
-	res = ifname_compare_aligned(dev->name, name, mask);
+	res = ifname_compare(dev->name, name, mask);
 	if (unlikely(dev->ifalias && res))
-		res = ifname_compare_aligned(dev->ifalias, name, mask);
+		res = ifname_compare(dev->ifalias, name, mask);
 
 out:
 	return res;
diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
index 457d4ed..c978691 100644
--- a/net/ipv4/netfilter/arp_tables.c
+++ b/net/ipv4/netfilter/arp_tables.c
@@ -76,39 +76,6 @@ static inline int arp_devaddr_compare(const struct arpt_devaddr_info *ap,
 	return ret != 0;
 }
 
-/*
- * Unfortunately, _b and _mask are not aligned to an int (or long int)
- * Some arches dont care, unrolling the loop is a win on them.
- * For other arches, we only have a 16bit alignement.
- */
-static unsigned long ifname_compare(const struct net_device *dev,
-				    const char *_b, const char *_mask)
-{
-#ifdef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
-	unsigned long ret = ifname_compare_all(dev, _b, _mask);
-#else
-	unsigned long ret = 0;
-	const u16 *a = (const u16 *)dev->name;
-	const u16 *b = (const u16 *)_b;
-	const u16 *mask = (const u16 *)_mask;
-	int i;
-
-	for (i = 0; i < IFNAMSIZ/sizeof(u16); i++)
-		ret |= (a[i] ^ b[i]) & mask[i];
-
-	if (likely(!(dev->ifalias && ret)))
-		goto out;
-
-	ret = 0;
-	a = (const u16 *)dev->ifalias;
-	for (i = 0; i < IFNAMSIZ/sizeof(u16); i++)
-		ret |= (a[i] ^ b[i]) & mask[i];
-
-out:
-#endif
-	return ret;
-}
-
 /* Returns whether packet matches rule or not. */
 static inline int arp_packet_match(const struct arphdr *arphdr,
 				   struct net_device *dev,
@@ -192,7 +159,7 @@ static inline int arp_packet_match(const struct arphdr *arphdr,
 	}
 
 	/* Look for ifname matches.  */
-	ret = ifname_compare(indev, arpinfo->iniface, arpinfo->iniface_mask);
+	ret = ifname_compare_all(indev, arpinfo->iniface, arpinfo->iniface_mask);
 
 	if (FWINV(ret != 0, ARPT_INV_VIA_IN)) {
 		dprintf("VIA in mismatch (%s vs %s).%s\n",
@@ -201,7 +168,7 @@ static inline int arp_packet_match(const struct arphdr *arphdr,
 		return 0;
 	}
 
-	ret = ifname_compare(outdev, arpinfo->outiface, arpinfo->outiface_mask);
+	ret = ifname_compare_all(outdev, arpinfo->outiface, arpinfo->outiface_mask);
 
 	if (FWINV(ret != 0, ARPT_INV_VIA_OUT)) {
 		dprintf("VIA out mismatch (%s vs %s).%s\n",
-- 
1.8.4.5

  parent reply	other threads:[~2015-01-11 20:52 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-11 20:52 [RFC] Make predictable/persistent network interface names more handy Richard Weinberger
2015-01-11 20:52 ` [PATCH 1/3] net: Make interface aliases available for general usage Richard Weinberger
2015-01-11 22:40   ` Stephen Hemminger
2015-01-11 22:43     ` Richard Weinberger
2015-01-11 20:52 ` [PATCH 2/3] x_tables: Use also dev->ifalias for interface matching Richard Weinberger
2015-01-12 16:04   ` Eric Dumazet
2015-01-12 16:12     ` Richard Weinberger
2015-01-12 16:32     ` Jan Engelhardt
2015-01-12 16:46       ` Eric Dumazet
     [not found]     ` <1425960.ovH4s7sjue@rofl>
2015-01-12 16:51       ` Eric Dumazet
2015-01-12 17:19         ` Patrick Schaaf
2015-01-12 17:22           ` Patrick McHardy
2015-01-12 17:41             ` Patrick Schaaf
2015-01-11 20:52 ` Richard Weinberger [this message]
2015-01-11 20:59   ` [PATCH 3/3] x_tables: Factor out 16bit aligment ifname_compare() Joe Perches
2015-01-11 21:02     ` Richard Weinberger
2015-01-11 21:14       ` Joe Perches
2015-01-11 21:30         ` Richard Weinberger
2015-01-11 21:39           ` Joe Perches
2015-01-11 21:42             ` Richard Weinberger
2015-01-12  2:50               ` David Miller
2015-01-12  8:18                 ` Richard Weinberger
2015-01-12  8:40                   ` Joe Perches
2015-01-11 22:23           ` Jan Engelhardt
2015-01-11 22:42 ` [RFC] Make predictable/persistent network interface names more handy Stephen Hemminger
2015-01-11 22:47   ` Richard Weinberger
2015-01-11 22:51   ` Richard Weinberger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1421009571-5279-4-git-send-email-richard@nod.at \
    --to=richard@nod.at \
    --cc=bhutchings@solarflare.com \
    --cc=coreteam@netfilter.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=jiri@resnulli.us \
    --cc=jmorris@namei.org \
    --cc=john.fastabend@gmail.com \
    --cc=kaber@trash.net \
    --cc=kadlec@blackhole.kfki.hu \
    --cc=kay@vrfy.org \
    --cc=kuznet@ms2.inr.ac.ru \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=pablo@netfilter.org \
    --cc=stephen@networkplumber.org \
    --cc=therbert@google.com \
    --cc=vfalico@gmail.com \
    --cc=vyasevic@redhat.com \
    --cc=yoshfuji@linux-ipv6.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).