netfilter: replace list_head with single linked list
[cascardo/linux.git] / include / net / netfilter / nf_queue.h
index 0dbce55..2280cfe 100644 (file)
@@ -11,7 +11,6 @@ struct nf_queue_entry {
        struct sk_buff          *skb;
        unsigned int            id;
 
-       struct nf_hook_ops      *elem;
        struct nf_hook_state    state;
        u16                     size; /* sizeof(entry) + saved route keys */
 
@@ -22,10 +21,10 @@ struct nf_queue_entry {
 
 /* Packet queuing */
 struct nf_queue_handler {
-       int                     (*outfn)(struct nf_queue_entry *entry,
-                                        unsigned int queuenum);
-       void                    (*nf_hook_drop)(struct net *net,
-                                               struct nf_hook_ops *ops);
+       int             (*outfn)(struct nf_queue_entry *entry,
+                                unsigned int queuenum);
+       void            (*nf_hook_drop)(struct net *net,
+                                       const struct nf_hook_entry *hooks);
 };
 
 void nf_register_queue_handler(struct net *net, const struct nf_queue_handler *qh);
@@ -41,23 +40,19 @@ static inline void init_hashrandom(u32 *jhash_initval)
                *jhash_initval = prandom_u32();
 }
 
-static inline u32 hash_v4(const struct sk_buff *skb, u32 jhash_initval)
+static inline u32 hash_v4(const struct iphdr *iph, u32 initval)
 {
-       const struct iphdr *iph = ip_hdr(skb);
-
        /* packets in either direction go into same queue */
        if ((__force u32)iph->saddr < (__force u32)iph->daddr)
                return jhash_3words((__force u32)iph->saddr,
-                       (__force u32)iph->daddr, iph->protocol, jhash_initval);
+                       (__force u32)iph->daddr, iph->protocol, initval);
 
        return jhash_3words((__force u32)iph->daddr,
-                       (__force u32)iph->saddr, iph->protocol, jhash_initval);
+                       (__force u32)iph->saddr, iph->protocol, initval);
 }
 
-#if IS_ENABLED(CONFIG_IP6_NF_IPTABLES)
-static inline u32 hash_v6(const struct sk_buff *skb, u32 jhash_initval)
+static inline u32 hash_v6(const struct ipv6hdr *ip6h, u32 initval)
 {
-       const struct ipv6hdr *ip6h = ipv6_hdr(skb);
        u32 a, b, c;
 
        if ((__force u32)ip6h->saddr.s6_addr32[3] <
@@ -75,20 +70,50 @@ static inline u32 hash_v6(const struct sk_buff *skb, u32 jhash_initval)
        else
                c = (__force u32) ip6h->daddr.s6_addr32[1];
 
-       return jhash_3words(a, b, c, jhash_initval);
+       return jhash_3words(a, b, c, initval);
+}
+
+static inline u32 hash_bridge(const struct sk_buff *skb, u32 initval)
+{
+       struct ipv6hdr *ip6h, _ip6h;
+       struct iphdr *iph, _iph;
+
+       switch (eth_hdr(skb)->h_proto) {
+       case htons(ETH_P_IP):
+               iph = skb_header_pointer(skb, skb_network_offset(skb),
+                                        sizeof(*iph), &_iph);
+               if (iph)
+                       return hash_v4(iph, initval);
+               break;
+       case htons(ETH_P_IPV6):
+               ip6h = skb_header_pointer(skb, skb_network_offset(skb),
+                                         sizeof(*ip6h), &_ip6h);
+               if (ip6h)
+                       return hash_v6(ip6h, initval);
+               break;
+       }
+
+       return 0;
 }
-#endif
 
 static inline u32
 nfqueue_hash(const struct sk_buff *skb, u16 queue, u16 queues_total, u8 family,
-            u32 jhash_initval)
+            u32 initval)
 {
-       if (family == NFPROTO_IPV4)
-               queue += ((u64) hash_v4(skb, jhash_initval) * queues_total) >> 32;
-#if IS_ENABLED(CONFIG_IP6_NF_IPTABLES)
-       else if (family == NFPROTO_IPV6)
-               queue += ((u64) hash_v6(skb, jhash_initval) * queues_total) >> 32;
-#endif
+       switch (family) {
+       case NFPROTO_IPV4:
+               queue += reciprocal_scale(hash_v4(ip_hdr(skb), initval),
+                                         queues_total);
+               break;
+       case NFPROTO_IPV6:
+               queue += reciprocal_scale(hash_v6(ipv6_hdr(skb), initval),
+                                         queues_total);
+               break;
+       case NFPROTO_BRIDGE:
+               queue += reciprocal_scale(hash_bridge(skb, initval),
+                                         queues_total);
+               break;
+       }
 
        return queue;
 }