~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/include/net/netfilter/nf_queue.h

Version: ~ [ linux-6.0-rc6 ] ~ [ linux-5.19.10 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.69 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.144 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.214 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.259 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.294 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.329 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.302 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  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_state    state;
 15         struct nf_hook_entry    *hook;
 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         void            (*nf_hook_drop)(struct net *net,
 28                                         const struct nf_hook_entry *hooks);
 29 };
 30 
 31 void nf_register_queue_handler(struct net *net, const struct nf_queue_handler *qh);
 32 void nf_unregister_queue_handler(struct net *net);
 33 void nf_reinject(struct nf_queue_entry *entry, unsigned int verdict);
 34 
 35 void nf_queue_entry_get_refs(struct nf_queue_entry *entry);
 36 void nf_queue_entry_release_refs(struct nf_queue_entry *entry);
 37 
 38 static inline void init_hashrandom(u32 *jhash_initval)
 39 {
 40         while (*jhash_initval == 0)
 41                 *jhash_initval = prandom_u32();
 42 }
 43 
 44 static inline u32 hash_v4(const struct iphdr *iph, u32 initval)
 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, initval);
 50 
 51         return jhash_3words((__force u32)iph->daddr,
 52                         (__force u32)iph->saddr, iph->protocol, initval);
 53 }
 54 
 55 static inline u32 hash_v6(const struct ipv6hdr *ip6h, u32 initval)
 56 {
 57         u32 a, b, c;
 58 
 59         if ((__force u32)ip6h->saddr.s6_addr32[3] <
 60             (__force u32)ip6h->daddr.s6_addr32[3]) {
 61                 a = (__force u32) ip6h->saddr.s6_addr32[3];
 62                 b = (__force u32) ip6h->daddr.s6_addr32[3];
 63         } else {
 64                 b = (__force u32) ip6h->saddr.s6_addr32[3];
 65                 a = (__force u32) ip6h->daddr.s6_addr32[3];
 66         }
 67 
 68         if ((__force u32)ip6h->saddr.s6_addr32[1] <
 69             (__force u32)ip6h->daddr.s6_addr32[1])
 70                 c = (__force u32) ip6h->saddr.s6_addr32[1];
 71         else
 72                 c = (__force u32) ip6h->daddr.s6_addr32[1];
 73 
 74         return jhash_3words(a, b, c, initval);
 75 }
 76 
 77 static inline u32 hash_bridge(const struct sk_buff *skb, u32 initval)
 78 {
 79         struct ipv6hdr *ip6h, _ip6h;
 80         struct iphdr *iph, _iph;
 81 
 82         switch (eth_hdr(skb)->h_proto) {
 83         case htons(ETH_P_IP):
 84                 iph = skb_header_pointer(skb, skb_network_offset(skb),
 85                                          sizeof(*iph), &_iph);
 86                 if (iph)
 87                         return hash_v4(iph, initval);
 88                 break;
 89         case htons(ETH_P_IPV6):
 90                 ip6h = skb_header_pointer(skb, skb_network_offset(skb),
 91                                           sizeof(*ip6h), &_ip6h);
 92                 if (ip6h)
 93                         return hash_v6(ip6h, initval);
 94                 break;
 95         }
 96 
 97         return 0;
 98 }
 99 
100 static inline u32
101 nfqueue_hash(const struct sk_buff *skb, u16 queue, u16 queues_total, u8 family,
102              u32 initval)
103 {
104         switch (family) {
105         case NFPROTO_IPV4:
106                 queue += reciprocal_scale(hash_v4(ip_hdr(skb), initval),
107                                           queues_total);
108                 break;
109         case NFPROTO_IPV6:
110                 queue += reciprocal_scale(hash_v6(ipv6_hdr(skb), initval),
111                                           queues_total);
112                 break;
113         case NFPROTO_BRIDGE:
114                 queue += reciprocal_scale(hash_bridge(skb, initval),
115                                           queues_total);
116                 break;
117         }
118 
119         return queue;
120 }
121 
122 #endif /* _NF_QUEUE_H */
123 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp