[PATCH] netfilter: xt_physdev fixes

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Eric Dumazet
Date: Wednesday, February 18, 2009 - 10:36 am

Hi Patrick

Please find following patch to prepare next one (loop unrolling)

I am not sure xt_physdev_info is aligned, either on an int or a long,
so please check my assertion before applying :)



Thank you

[PATCH] netfilter: xt_physdev fixes

1) physdev_mt() incorrectly assumes nulldevname[] is aligned on an int

2) It also uses word comparisons, while it could use long word ones.

Signed-off-by: Eric Dumazet <dada1@cosmosbay.com>
---
diff --git a/net/netfilter/xt_physdev.c b/net/netfilter/xt_physdev.c
index 1bcdfc1..4b13ef7 100644
--- a/net/netfilter/xt_physdev.c
+++ b/net/netfilter/xt_physdev.c
@@ -24,9 +24,9 @@ static bool
 physdev_mt(const struct sk_buff *skb, const struct xt_match_param *par)
 {
 	int i;
-	static const char nulldevname[IFNAMSIZ];
+	static const char nulldevname[IFNAMSIZ] __attribute__((aligned(sizeof(long))));
 	const struct xt_physdev_info *info = par->matchinfo;
-	bool ret;
+	unsigned long ret;
 	const char *indev, *outdev;
 	const struct nf_bridge_info *nf_bridge;
 
@@ -68,10 +68,10 @@ physdev_mt(const struct sk_buff *skb, const struct xt_match_param *par)
 	if (!(info->bitmask & XT_PHYSDEV_OP_IN))
 		goto match_outdev;
 	indev = nf_bridge->physindev ? nf_bridge->physindev->name : nulldevname;
-	for (i = 0, ret = false; i < IFNAMSIZ/sizeof(unsigned int); i++) {
-		ret |= (((const unsigned int *)indev)[i]
-			^ ((const unsigned int *)info->physindev)[i])
-			& ((const unsigned int *)info->in_mask)[i];
+	for (i = 0, ret = 0; i < IFNAMSIZ/sizeof(unsigned long); i++) {
+		ret |= (((const unsigned long *)indev)[i]
+			^ ((const unsigned long *)info->physindev)[i])
+			& ((const unsigned long *)info->in_mask)[i];
 	}
 
 	if (!ret ^ !(info->invert & XT_PHYSDEV_OP_IN))
@@ -82,13 +82,12 @@ match_outdev:
 		return true;
 	outdev = nf_bridge->physoutdev ?
 		 nf_bridge->physoutdev->name : nulldevname;
-	for (i = 0, ret = false; i < IFNAMSIZ/sizeof(unsigned int); i++) {
-		ret |= (((const unsigned int *)outdev)[i]
-			^ ((const unsigned int *)info->physoutdev)[i])
-			& ((const unsigned int *)info->out_mask)[i];
+	for (i = 0, ret = 0; i < IFNAMSIZ/sizeof(unsigned long); i++) {
+		ret |= (((const unsigned long *)outdev)[i]
+			^ ((const unsigned long *)info->physoutdev)[i])
+			& ((const unsigned long *)info->out_mask)[i];
 	}
-
-	return ret ^ !(info->invert & XT_PHYSDEV_OP_OUT);
+	return (!!ret ^ !(info->invert & XT_PHYSDEV_OP_OUT));
 }
 
 static bool physdev_mt_check(const struct xt_mtchk_param *par)
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
32 core net-next stack/netfilter &quot;scaling&quot;, Rick Jones, (Mon Jan 26, 3:15 pm)
Re: 32 core net-next stack/netfilter &quot;scaling&quot;, Stephen Hemminger, (Mon Jan 26, 4:14 pm)
Re: 32 core net-next stack/netfilter &quot;scaling&quot;, Patrick McHardy, (Tue Jan 27, 2:15 am)
Re: 32 core net-next stack/netfilter &quot;scaling&quot;, Patrick McHardy, (Tue Jan 27, 4:37 am)
Re: 32 core net-next stack/netfilter &quot;scaling&quot;, Patrick McHardy, (Tue Jan 27, 10:33 am)
Re: 32 core net-next stack/netfilter &quot;scaling&quot;, Patrick McHardy, (Wed Jan 28, 9:25 am)
Re: 32 core net-next stack/netfilter &quot;scaling&quot;, Eric Dumazet, (Wed Jan 28, 10:07 am)
Re: 32 core net-next stack/netfilter &quot;scaling&quot;, Eric Dumazet, (Wed Jan 28, 10:34 am)
Re: 32 core net-next stack/netfilter &quot;scaling&quot;, Patrick McHardy, (Mon Feb 9, 7:57 am)
Re: 32 core net-next stack/netfilter &quot;scaling&quot;, Stephen Hemminger, (Tue Feb 10, 11:44 am)
[PATCH] netfilter: xt_physdev fixes, Eric Dumazet, (Wed Feb 18, 10:36 am)
Re: [PATCH] netfilter: xt_physdev fixes, Patrick McHardy, (Wed Feb 18, 11:14 am)
[PATCH] netfilter: unfold two loops in physdev_mt(), Eric Dumazet, (Thu Feb 19, 1:00 am)
Re: [PATCH] netfilter: unfold two loops in physdev_mt(), Patrick McHardy, (Thu Feb 19, 3:17 am)