Commit 5c33448c authored by holger@eitzenberger.org's avatar holger@eitzenberger.org Committed by Pablo Neira Ayuso

netfilter: xt_NFQUEUE: coalesce IPv4 and IPv6 hashing

Because rev1 and rev3 of the target share the same hashing
generalize it by introduing nfqueue_hash().
Signed-off-by: default avatarHolger Eitzenberger <holger@eitzenberger.org>
Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
parent 8746ddcf
...@@ -76,22 +76,31 @@ static u32 hash_v6(const struct sk_buff *skb) ...@@ -76,22 +76,31 @@ static u32 hash_v6(const struct sk_buff *skb)
} }
#endif #endif
static unsigned int static u32
nfqueue_tg_v1(struct sk_buff *skb, const struct xt_action_param *par) nfqueue_hash(const struct sk_buff *skb, const struct xt_action_param *par)
{ {
const struct xt_NFQ_info_v1 *info = par->targinfo; const struct xt_NFQ_info_v1 *info = par->targinfo;
u32 queue = info->queuenum; u32 queue = info->queuenum;
if (info->queues_total > 1) {
if (par->family == NFPROTO_IPV4) if (par->family == NFPROTO_IPV4)
queue = (((u64) hash_v4(skb) * info->queues_total) >> queue += ((u64) hash_v4(skb) * info->queues_total) >> 32;
32) + queue;
#if IS_ENABLED(CONFIG_IP6_NF_IPTABLES) #if IS_ENABLED(CONFIG_IP6_NF_IPTABLES)
else if (par->family == NFPROTO_IPV6) else if (par->family == NFPROTO_IPV6)
queue = (((u64) hash_v6(skb) * info->queues_total) >> queue += ((u64) hash_v6(skb) * info->queues_total) >> 32;
32) + queue;
#endif #endif
}
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 = info->queuenum;
if (info->queues_total > 1)
queue = nfqueue_hash(skb, par);
return NF_QUEUE_NR(queue); return NF_QUEUE_NR(queue);
} }
...@@ -144,17 +153,10 @@ nfqueue_tg_v3(struct sk_buff *skb, const struct xt_action_param *par) ...@@ -144,17 +153,10 @@ nfqueue_tg_v3(struct sk_buff *skb, const struct xt_action_param *par)
int cpu = smp_processor_id(); int cpu = smp_processor_id();
queue = info->queuenum + cpu % info->queues_total; queue = info->queuenum + cpu % info->queues_total;
} else { } else
if (par->family == NFPROTO_IPV4) queue = nfqueue_hash(skb, par);
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
}
} }
return NF_QUEUE_NR(queue); return NF_QUEUE_NR(queue);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment