5 #include <linux/ipv6.h>
6 #include <linux/jhash.h>
8 /* Each queued (to userspace) skbuff has one of these. */
9 struct nf_queue_entry {
10 struct list_head list;
14 struct nf_hook_ops *elem;
16 u16 size; /* sizeof(entry) + saved route keys */
18 struct net_device *indev;
19 struct net_device *outdev;
20 int (*okfn)(struct sk_buff *);
22 /* extra space to store route keys */
25 #define nf_queue_entry_reroute(x) ((void *)x + sizeof(struct nf_queue_entry))
28 struct nf_queue_handler {
29 int (*outfn)(struct nf_queue_entry *entry,
30 unsigned int queuenum);
33 void nf_register_queue_handler(const struct nf_queue_handler *qh);
34 void nf_unregister_queue_handler(void);
35 void nf_reinject(struct nf_queue_entry *entry, unsigned int verdict);
37 bool nf_queue_entry_get_refs(struct nf_queue_entry *entry);
38 void nf_queue_entry_release_refs(struct nf_queue_entry *entry);
40 static inline void init_hashrandom(u32 *jhash_initval)
42 while (*jhash_initval == 0)
43 *jhash_initval = prandom_u32();
46 static inline u32 hash_v4(const struct sk_buff *skb, u32 jhash_initval)
48 const struct iphdr *iph = ip_hdr(skb);
50 /* packets in either direction go into same queue */
51 if ((__force u32)iph->saddr < (__force u32)iph->daddr)
52 return jhash_3words((__force u32)iph->saddr,
53 (__force u32)iph->daddr, iph->protocol, jhash_initval);
55 return jhash_3words((__force u32)iph->daddr,
56 (__force u32)iph->saddr, iph->protocol, jhash_initval);
59 #if IS_ENABLED(CONFIG_IP6_NF_IPTABLES)
60 static inline u32 hash_v6(const struct sk_buff *skb, u32 jhash_initval)
62 const struct ipv6hdr *ip6h = ipv6_hdr(skb);
65 if ((__force u32)ip6h->saddr.s6_addr32[3] <
66 (__force u32)ip6h->daddr.s6_addr32[3]) {
67 a = (__force u32) ip6h->saddr.s6_addr32[3];
68 b = (__force u32) ip6h->daddr.s6_addr32[3];
70 b = (__force u32) ip6h->saddr.s6_addr32[3];
71 a = (__force u32) ip6h->daddr.s6_addr32[3];
74 if ((__force u32)ip6h->saddr.s6_addr32[1] <
75 (__force u32)ip6h->daddr.s6_addr32[1])
76 c = (__force u32) ip6h->saddr.s6_addr32[1];
78 c = (__force u32) ip6h->daddr.s6_addr32[1];
80 return jhash_3words(a, b, c, jhash_initval);
85 nfqueue_hash(const struct sk_buff *skb, u16 queue, u16 queues_total, u8 family,
88 if (family == NFPROTO_IPV4)
89 queue += ((u64) hash_v4(skb, jhash_initval) * queues_total) >> 32;
90 #if IS_ENABLED(CONFIG_IP6_NF_IPTABLES)
91 else if (family == NFPROTO_IPV6)
92 queue += ((u64) hash_v6(skb, jhash_initval) * queues_total) >> 32;
98 #endif /* _NF_QUEUE_H */