flow_dissector: Use IPv6 flow label in flow_dissector
[firefly-linux-kernel-4.4.55.git] / net / core / flow_dissector.c
index 2ff8cd4dfc5fd234af1b82b4449e035533ff61d9..c5f3912dad4c9d1276a964f11d15b76f7d6c29b9 100644 (file)
@@ -80,6 +80,8 @@ ip:
        case htons(ETH_P_IPV6): {
                const struct ipv6hdr *iph;
                struct ipv6hdr _iph;
+               __be32 flow_label;
+
 ipv6:
                iph = skb_header_pointer(skb, nhoff, sizeof(_iph), &_iph);
                if (!iph)
@@ -89,6 +91,21 @@ ipv6:
                flow->src = (__force __be32)ipv6_addr_hash(&iph->saddr);
                flow->dst = (__force __be32)ipv6_addr_hash(&iph->daddr);
                nhoff += sizeof(struct ipv6hdr);
+
+               flow_label = ip6_flowlabel(iph);
+               if (flow_label) {
+                       /* Awesome, IPv6 packet has a flow label so we can
+                        * use that to represent the ports without any
+                        * further dissection.
+                        */
+                       flow->n_proto = proto;
+                       flow->ip_proto = ip_proto;
+                       flow->ports = flow_label;
+                       flow->thoff = (u16)nhoff;
+
+                       return true;
+               }
+
                break;
        }
        case htons(ETH_P_8021AD):
@@ -196,12 +213,6 @@ static __always_inline u32 __flow_hash_3words(u32 a, u32 b, u32 c)
        return jhash_3words(a, b, c, hashrnd);
 }
 
-static __always_inline u32 __flow_hash_1word(u32 a)
-{
-       __flow_hash_secret_init();
-       return jhash_1word(a, hashrnd);
-}
-
 static inline u32 __flow_hash_from_keys(struct flow_keys *keys)
 {
        u32 hash;
@@ -253,7 +264,7 @@ EXPORT_SYMBOL(__skb_get_hash);
  * Returns a Tx hash based on the given packet descriptor a Tx queues' number
  * to be used as a distribution range.
  */
-u16 __skb_tx_hash(const struct net_device *dev, const struct sk_buff *skb,
+u16 __skb_tx_hash(const struct net_device *dev, struct sk_buff *skb,
                  unsigned int num_tx_queues)
 {
        u32 hash;
@@ -273,13 +284,7 @@ u16 __skb_tx_hash(const struct net_device *dev, const struct sk_buff *skb,
                qcount = dev->tc_to_txq[tc].count;
        }
 
-       if (skb->sk && skb->sk->sk_hash)
-               hash = skb->sk->sk_hash;
-       else
-               hash = (__force u16) skb->protocol;
-       hash = __flow_hash_1word(hash);
-
-       return (u16) (((u64) hash * qcount) >> 32) + qoffset;
+       return (u16) (((u64)skb_get_hash(skb) * qcount) >> 32) + qoffset;
 }
 EXPORT_SYMBOL(__skb_tx_hash);
 
@@ -351,17 +356,10 @@ static inline int get_xps_queue(struct net_device *dev, struct sk_buff *skb)
                if (map) {
                        if (map->len == 1)
                                queue_index = map->queues[0];
-                       else {
-                               u32 hash;
-                               if (skb->sk && skb->sk->sk_hash)
-                                       hash = skb->sk->sk_hash;
-                               else
-                                       hash = (__force u16) skb->protocol ^
-                                           skb->hash;
-                               hash = __flow_hash_1word(hash);
+                       else
                                queue_index = map->queues[
-                                   ((u64)hash * map->len) >> 32];
-                       }
+                                   ((u64)skb_get_hash(skb) * map->len) >> 32];
+
                        if (unlikely(queue_index >= dev->real_num_tx_queues))
                                queue_index = -1;
                }