Patchwork [RFC,2/3] NFQUEUE: coalesce IPv4 and IPv6 hashing

login
register
mail settings
Submitter holger@eitzenberger.org
Date March 19, 2013, 2:14 p.m.
Message ID <20130319141605.728912499@eitzenberger.org>
Download mbox | patch
Permalink /patch/229080/
State RFC
Headers show

Comments

holger@eitzenberger.org - March 19, 2013, 2:14 p.m.
Because rev1 and rev3 of the target share the same hashing
generalize it by introduing nfqueue_hash().

Signed-off-by: Holger Eitzenberger <holger@eitzenberger.org>

---
 net/netfilter/xt_NFQUEUE.c |   49 +++++++++++++++++++++++++-------------------
 1 file changed, 28 insertions(+), 21 deletions(-)


--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
David Miller - March 19, 2013, 2:27 p.m.
From: holger@eitzenberger.org
Date: Tue, 19 Mar 2013 15:14:44 +0100

> +	if (par->family == NFPROTO_IPV4)
> +		queue = (((u64) hash_v4(skb) * info->queues_total) >>
> +			 32) + queue;
>  #if IS_ENABLED(CONFIG_IP6_NF_IPTABLES)
> -		else if (par->family == NFPROTO_IPV6)
> -			queue = (((u64) hash_v6(skb) * info->queues_total) >>
> -				 32) + queue;
> +	else if (par->family == NFPROTO_IPV6)
> +		queue = (((u64) hash_v6(skb) * info->queues_total) >>
> +			 32) + queue;
>  #endif

Similarly, add a helper function.

Since there are so many similar call sites, perhaps put it into a
common header file.
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
holger@eitzenberger.org - March 19, 2013, 2:39 p.m.
On Tue, Mar 19, 2013 at 10:27:49AM -0400, David S. Miller wrote:
> From: holger@eitzenberger.org
> Date: Tue, 19 Mar 2013 15:14:44 +0100
> 
> > +	if (par->family == NFPROTO_IPV4)
> > +		queue = (((u64) hash_v4(skb) * info->queues_total) >>
> > +			 32) + queue;
> >  #if IS_ENABLED(CONFIG_IP6_NF_IPTABLES)
> > -		else if (par->family == NFPROTO_IPV6)
> > -			queue = (((u64) hash_v6(skb) * info->queues_total) >>
> > -				 32) + queue;
> > +	else if (par->family == NFPROTO_IPV6)
> > +		queue = (((u64) hash_v6(skb) * info->queues_total) >>
> > +			 32) + queue;
> >  #endif
> 
> Similarly, add a helper function.
> 
> Since there are so many similar call sites, perhaps put it into a
> common header file.

Look at patch #2! :)

--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch

diff --git a/net/netfilter/xt_NFQUEUE.c b/net/netfilter/xt_NFQUEUE.c
index cf9c6a1..90684a1 100644
--- a/net/netfilter/xt_NFQUEUE.c
+++ b/net/netfilter/xt_NFQUEUE.c
@@ -76,22 +76,37 @@  static u32 hash_v6(const struct sk_buff *skb)
 }
 #endif
 
-static unsigned int
-nfqueue_tg_v1(struct sk_buff *skb, const struct xt_action_param *par)
+static u32
+nfqueue_hash(const struct sk_buff *skb, const struct xt_action_param *par)
 {
 	const struct xt_NFQ_info_v1 *info = par->targinfo;
-	u32 queue = info->queuenum;
+	u32 queue;
 
-	if (info->queues_total > 1) {
-		if (par->family == NFPROTO_IPV4)
-			queue = (((u64) hash_v4(skb) * info->queues_total) >>
-				 32) + queue;
+	if (par->family == NFPROTO_IPV4)
+		queue = (((u64) hash_v4(skb) * info->queues_total) >>
+			 32) + queue;
 #if IS_ENABLED(CONFIG_IP6_NF_IPTABLES)
-		else if (par->family == NFPROTO_IPV6)
-			queue = (((u64) hash_v6(skb) * info->queues_total) >>
-				 32) + queue;
+	else if (par->family == NFPROTO_IPV6)
+		queue = (((u64) hash_v6(skb) * info->queues_total) >>
+			 32) + queue;
 #endif
-	}
+	else
+		queue = info->queuenum;
+
+	return queue;
+}
+
+static unsigned int
+nfqueue_tg_v1(struct sk_buff *skb, const struct xt_action_param *par)
+{
+	const struct xt_NFQ_info_v1 *info = par->targinfo;
+	u32 queue;
+
+	if (info->queues_total > 1)
+		queue = nfqueue_hash(skb, par);
+	else
+		queue = info->queuenum;
+
 	return NF_QUEUE_NR(queue);
 }
 
@@ -144,16 +159,8 @@  nfqueue_tg_v3(struct sk_buff *skb, const struct xt_action_param *par)
 			int cpu = smp_processor_id();
 
 			queue = info->queuenum + cpu % info->queues_total;
-		} else {
-			if (par->family == NFPROTO_IPV4)
-				queue = (((u64) hash_v4(skb) * info->queues_total) >>
-						 32) + queue;
-#if IS_ENABLED(CONFIG_IP6_NF_IPTABLES)
-			else if (par->family == NFPROTO_IPV6)
-				queue = (((u64) hash_v6(skb) * info->queues_total) >>
-						 32) + queue;
-#endif
-		}
+		} else
+			queue = nfqueue_hash(skb, par);
 	}
 	return NF_QUEUE_NR(queue);
 }