]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - include/net/netfilter/nf_queue.h
netfilter: Use nf_hook_state in nf_queue_entry.
[mirror_ubuntu-artful-kernel.git] / include / net / netfilter / nf_queue.h
1 #ifndef _NF_QUEUE_H
2 #define _NF_QUEUE_H
3
4 #include <linux/ip.h>
5 #include <linux/ipv6.h>
6 #include <linux/jhash.h>
7
8 /* Each queued (to userspace) skbuff has one of these. */
9 struct nf_queue_entry {
10 struct list_head list;
11 struct sk_buff *skb;
12 unsigned int id;
13
14 struct nf_hook_ops *elem;
15 struct nf_hook_state state;
16 u16 size; /* sizeof(entry) + saved route keys */
17
18 /* extra space to store route keys */
19 };
20
21 #define nf_queue_entry_reroute(x) ((void *)x + sizeof(struct nf_queue_entry))
22
23 /* Packet queuing */
24 struct nf_queue_handler {
25 int (*outfn)(struct nf_queue_entry *entry,
26 unsigned int queuenum);
27 };
28
29 void nf_register_queue_handler(const struct nf_queue_handler *qh);
30 void nf_unregister_queue_handler(void);
31 void nf_reinject(struct nf_queue_entry *entry, unsigned int verdict);
32
33 bool nf_queue_entry_get_refs(struct nf_queue_entry *entry);
34 void nf_queue_entry_release_refs(struct nf_queue_entry *entry);
35
36 static inline void init_hashrandom(u32 *jhash_initval)
37 {
38 while (*jhash_initval == 0)
39 *jhash_initval = prandom_u32();
40 }
41
42 static inline u32 hash_v4(const struct sk_buff *skb, u32 jhash_initval)
43 {
44 const struct iphdr *iph = ip_hdr(skb);
45
46 /* packets in either direction go into same queue */
47 if ((__force u32)iph->saddr < (__force u32)iph->daddr)
48 return jhash_3words((__force u32)iph->saddr,
49 (__force u32)iph->daddr, iph->protocol, jhash_initval);
50
51 return jhash_3words((__force u32)iph->daddr,
52 (__force u32)iph->saddr, iph->protocol, jhash_initval);
53 }
54
55 #if IS_ENABLED(CONFIG_IP6_NF_IPTABLES)
56 static inline u32 hash_v6(const struct sk_buff *skb, u32 jhash_initval)
57 {
58 const struct ipv6hdr *ip6h = ipv6_hdr(skb);
59 u32 a, b, c;
60
61 if ((__force u32)ip6h->saddr.s6_addr32[3] <
62 (__force u32)ip6h->daddr.s6_addr32[3]) {
63 a = (__force u32) ip6h->saddr.s6_addr32[3];
64 b = (__force u32) ip6h->daddr.s6_addr32[3];
65 } else {
66 b = (__force u32) ip6h->saddr.s6_addr32[3];
67 a = (__force u32) ip6h->daddr.s6_addr32[3];
68 }
69
70 if ((__force u32)ip6h->saddr.s6_addr32[1] <
71 (__force u32)ip6h->daddr.s6_addr32[1])
72 c = (__force u32) ip6h->saddr.s6_addr32[1];
73 else
74 c = (__force u32) ip6h->daddr.s6_addr32[1];
75
76 return jhash_3words(a, b, c, jhash_initval);
77 }
78 #endif
79
80 static inline u32
81 nfqueue_hash(const struct sk_buff *skb, u16 queue, u16 queues_total, u8 family,
82 u32 jhash_initval)
83 {
84 if (family == NFPROTO_IPV4)
85 queue += ((u64) hash_v4(skb, jhash_initval) * queues_total) >> 32;
86 #if IS_ENABLED(CONFIG_IP6_NF_IPTABLES)
87 else if (family == NFPROTO_IPV6)
88 queue += ((u64) hash_v6(skb, jhash_initval) * queues_total) >> 32;
89 #endif
90
91 return queue;
92 }
93
94 #endif /* _NF_QUEUE_H */