]>
git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - include/net/netfilter/nf_queue.h
2280cfe86c56157f3ca1165baf6f4ad0e73a18be
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_state state
;
15 u16 size
; /* sizeof(entry) + saved route keys */
17 /* extra space to store route keys */
20 #define nf_queue_entry_reroute(x) ((void *)x + sizeof(struct nf_queue_entry))
23 struct nf_queue_handler
{
24 int (*outfn
)(struct nf_queue_entry
*entry
,
25 unsigned int queuenum
);
26 void (*nf_hook_drop
)(struct net
*net
,
27 const struct nf_hook_entry
*hooks
);
30 void nf_register_queue_handler(struct net
*net
, const struct nf_queue_handler
*qh
);
31 void nf_unregister_queue_handler(struct net
*net
);
32 void nf_reinject(struct nf_queue_entry
*entry
, unsigned int verdict
);
34 void nf_queue_entry_get_refs(struct nf_queue_entry
*entry
);
35 void nf_queue_entry_release_refs(struct nf_queue_entry
*entry
);
37 static inline void init_hashrandom(u32
*jhash_initval
)
39 while (*jhash_initval
== 0)
40 *jhash_initval
= prandom_u32();
43 static inline u32
hash_v4(const struct iphdr
*iph
, u32 initval
)
45 /* packets in either direction go into same queue */
46 if ((__force u32
)iph
->saddr
< (__force u32
)iph
->daddr
)
47 return jhash_3words((__force u32
)iph
->saddr
,
48 (__force u32
)iph
->daddr
, iph
->protocol
, initval
);
50 return jhash_3words((__force u32
)iph
->daddr
,
51 (__force u32
)iph
->saddr
, iph
->protocol
, initval
);
54 static inline u32
hash_v6(const struct ipv6hdr
*ip6h
, u32 initval
)
58 if ((__force u32
)ip6h
->saddr
.s6_addr32
[3] <
59 (__force u32
)ip6h
->daddr
.s6_addr32
[3]) {
60 a
= (__force u32
) ip6h
->saddr
.s6_addr32
[3];
61 b
= (__force u32
) ip6h
->daddr
.s6_addr32
[3];
63 b
= (__force u32
) ip6h
->saddr
.s6_addr32
[3];
64 a
= (__force u32
) ip6h
->daddr
.s6_addr32
[3];
67 if ((__force u32
)ip6h
->saddr
.s6_addr32
[1] <
68 (__force u32
)ip6h
->daddr
.s6_addr32
[1])
69 c
= (__force u32
) ip6h
->saddr
.s6_addr32
[1];
71 c
= (__force u32
) ip6h
->daddr
.s6_addr32
[1];
73 return jhash_3words(a
, b
, c
, initval
);
76 static inline u32
hash_bridge(const struct sk_buff
*skb
, u32 initval
)
78 struct ipv6hdr
*ip6h
, _ip6h
;
79 struct iphdr
*iph
, _iph
;
81 switch (eth_hdr(skb
)->h_proto
) {
83 iph
= skb_header_pointer(skb
, skb_network_offset(skb
),
86 return hash_v4(iph
, initval
);
88 case htons(ETH_P_IPV6
):
89 ip6h
= skb_header_pointer(skb
, skb_network_offset(skb
),
90 sizeof(*ip6h
), &_ip6h
);
92 return hash_v6(ip6h
, initval
);
100 nfqueue_hash(const struct sk_buff
*skb
, u16 queue
, u16 queues_total
, u8 family
,
105 queue
+= reciprocal_scale(hash_v4(ip_hdr(skb
), initval
),
109 queue
+= reciprocal_scale(hash_v6(ipv6_hdr(skb
), initval
),
113 queue
+= reciprocal_scale(hash_bridge(skb
, initval
),
121 #endif /* _NF_QUEUE_H */