]> xenbits.xensource.com Git - people/pauldu/linux.git/commitdiff
skbuff: re-jig hash internals
authorPaul Durrant <paul.durrant@citrix.com>
Fri, 9 Oct 2015 13:10:53 +0000 (14:10 +0100)
committerPaul Durrant <paul.durrant@citrix.com>
Fri, 9 Oct 2015 14:31:39 +0000 (15:31 +0100)
Signed-off-by: Paul Durrant <paul.durrant@citrix.com>
include/linux/skbuff.h
include/net/sock.h
include/trace/events/net.h
net/core/flow_dissector.c

index 4398411236f16c3f87691162909dc6197fb62b08..54fbeb1e215f33e6e3dadfc7fccf6f6b1cd78815 100644 (file)
@@ -506,8 +506,6 @@ static inline u32 skb_mstamp_us_delta(const struct skb_mstamp *t1,
  *     @xmit_more: More SKBs are pending for this queue
  *     @ndisc_nodetype: router type (from link layer)
  *     @ooo_okay: allow the mapping of a socket to a queue to be changed
- *     @l4_hash: indicate hash is a canonical 4-tuple hash over transport
- *             ports.
  *     @sw_hash: indicates hash was computed in software stack
  *     @wifi_acked_valid: wifi_acked was set
  *     @wifi_acked: whether frame was acked on wifi or not
@@ -612,7 +610,7 @@ struct sk_buff {
        __u8                    nf_trace:1;
        __u8                    ip_summed:2;
        __u8                    ooo_okay:1;
-       __u8                    l4_hash:1;
+       /* 1 bit hole */
        __u8                    sw_hash:1;
        __u8                    wifi_acked_valid:1;
        __u8                    wifi_acked:1;
@@ -632,7 +630,8 @@ struct sk_buff {
        __u8                    ipvs_property:1;
        __u8                    inner_protocol_type:1;
        __u8                    remcsum_offload:1;
-       /* 3 or 5 bit hole */
+       __u8                    hash_type:2; /* see enum pkt_hash_types */
+       /* 1 or 3 bit hole */
 
 #ifdef CONFIG_NET_SCHED
        __u16                   tc_index;       /* traffic control index */
@@ -941,19 +940,35 @@ static inline void skb_clear_hash(struct sk_buff *skb)
 {
        skb->hash = 0;
        skb->sw_hash = 0;
-       skb->l4_hash = 0;
+       skb->hash_type = 0;
+}
+
+static inline bool skb_has_l4_hash(struct sk_buff *skb)
+{
+       return skb->hash_type == PKT_HASH_TYPE_L4;
+}
+
+static inline bool skb_has_l3_hash(struct sk_buff *skb)
+{
+       return skb->hash_type == PKT_HASH_TYPE_L3;
+}
+
+static inline bool skb_has_sw_hash(struct sk_buff *skb)
+{
+       return !!skb->sw_hash;
 }
 
 static inline void skb_clear_hash_if_not_l4(struct sk_buff *skb)
 {
-       if (!skb->l4_hash)
+       if (skb_has_l4_hash(skb))
                skb_clear_hash(skb);
 }
 
 static inline void
-__skb_set_hash(struct sk_buff *skb, __u32 hash, bool is_sw, bool is_l4)
+__skb_set_hash(struct sk_buff *skb, __u32 hash, bool is_sw,
+              enum pkt_hash_types type)
 {
-       skb->l4_hash = is_l4;
+       skb->hash_type = type;
        skb->sw_hash = is_sw;
        skb->hash = hash;
 }
@@ -962,13 +977,13 @@ static inline void
 skb_set_hash(struct sk_buff *skb, __u32 hash, enum pkt_hash_types type)
 {
        /* Used by drivers to set hash from HW */
-       __skb_set_hash(skb, hash, false, type == PKT_HASH_TYPE_L4);
+       __skb_set_hash(skb, hash, false, type);
 }
 
-static inline void
-__skb_set_sw_hash(struct sk_buff *skb, __u32 hash, bool is_l4)
+static void
+skb_set_sw_hash(struct sk_buff *skb, __u32 hash, enum pkt_hash_types type)
 {
-       __skb_set_hash(skb, hash, true, is_l4);
+       __skb_set_hash(skb, hash, true, type);
 }
 
 void __skb_get_hash(struct sk_buff *skb);
@@ -1023,7 +1038,7 @@ static inline bool skb_flow_dissect_flow_keys_buf(struct flow_keys *flow,
 
 static inline __u32 skb_get_hash(struct sk_buff *skb)
 {
-       if (!skb->l4_hash && !skb->sw_hash)
+       if (!skb_has_l4_hash(skb) && !skb_has_sw_hash(skb))
                __skb_get_hash(skb);
 
        return skb->hash;
@@ -1033,11 +1048,12 @@ __u32 __skb_get_hash_flowi6(struct sk_buff *skb, const struct flowi6 *fl6);
 
 static inline __u32 skb_get_hash_flowi6(struct sk_buff *skb, const struct flowi6 *fl6)
 {
-       if (!skb->l4_hash && !skb->sw_hash) {
+       if (!skb_has_l4_hash(skb) && !skb_has_sw_hash(skb)) {
                struct flow_keys keys;
                __u32 hash = __get_hash_from_flowi6(fl6, &keys);
 
-               __skb_set_sw_hash(skb, hash, flow_keys_have_l4(&keys));
+               skb_set_sw_hash(skb, hash, flow_keys_have_l4(&keys) ?
+                               PKT_HASH_TYPE_L4 : PKT_HASH_TYPE_L3);
        }
 
        return skb->hash;
@@ -1047,11 +1063,12 @@ __u32 __skb_get_hash_flowi4(struct sk_buff *skb, const struct flowi4 *fl);
 
 static inline __u32 skb_get_hash_flowi4(struct sk_buff *skb, const struct flowi4 *fl4)
 {
-       if (!skb->l4_hash && !skb->sw_hash) {
+       if (!skb_has_l4_hash(skb) && !skb_has_sw_hash(skb)) {
                struct flow_keys keys;
                __u32 hash = __get_hash_from_flowi4(fl4, &keys);
 
-               __skb_set_sw_hash(skb, hash, flow_keys_have_l4(&keys));
+               skb_set_sw_hash(skb, hash, flow_keys_have_l4(&keys) ?
+                               PKT_HASH_TYPE_L4 : PKT_HASH_TYPE_L3);
        }
 
        return skb->hash;
@@ -1068,7 +1085,7 @@ static inline void skb_copy_hash(struct sk_buff *to, const struct sk_buff *from)
 {
        to->hash = from->hash;
        to->sw_hash = from->sw_hash;
-       to->l4_hash = from->l4_hash;
+       to->hash_type = from->hash_type;
 };
 
 static inline void skb_sender_cpu_clear(struct sk_buff *skb)
index dfe2eb8e1132796ec9467d8fc50209ba9ff50f2d..c92c0b82fafa4edcbf77276b6ff44e66c99deede 100644 (file)
@@ -1916,7 +1916,7 @@ static inline void sock_poll_wait(struct file *filp,
 static inline void skb_set_hash_from_sk(struct sk_buff *skb, struct sock *sk)
 {
        if (sk->sk_txhash) {
-               skb->l4_hash = 1;
+               skb->hash_type = PKT_HASH_TYPE_L4;
                skb->hash = sk->sk_txhash;
        }
 }
index 49cc7c3de25221f2e014c80f12189bb1edc3b946..25e79794d641e9232363b4ec188025b64b50ff60 100644 (file)
@@ -180,7 +180,7 @@ DECLARE_EVENT_CLASS(net_dev_rx_verbose_template,
                __entry->protocol = ntohs(skb->protocol);
                __entry->ip_summed = skb->ip_summed;
                __entry->hash = skb->hash;
-               __entry->l4_hash = skb->l4_hash;
+               __entry->l4_hash = skb->hash_type == PKT_HASH_TYPE_L4;
                __entry->len = skb->len;
                __entry->data_len = skb->data_len;
                __entry->truesize = skb->truesize;
index d79699c9d1b9eb9f250254e360b2d5a7b4ff6e34..481ba2e38682581a606e4a47bdf816869a055f43 100644 (file)
@@ -667,8 +667,9 @@ void __skb_get_hash(struct sk_buff *skb)
 
        __flow_hash_secret_init();
 
-       __skb_set_sw_hash(skb, ___skb_get_hash(skb, &keys, hashrnd),
-                         flow_keys_have_l4(&keys));
+       skb_set_sw_hash(skb, ___skb_get_hash(skb, &keys, hashrnd),
+                        flow_keys_have_l4(&keys) ?
+                        PKT_HASH_TYPE_L4 : PKT_HASH_TYPE_L3);
 }
 EXPORT_SYMBOL(__skb_get_hash);
 
@@ -697,8 +698,9 @@ __u32 __skb_get_hash_flowi6(struct sk_buff *skb, const struct flowi6 *fl6)
        keys.tags.flow_label = (__force u32)fl6->flowlabel;
        keys.basic.ip_proto = fl6->flowi6_proto;
 
-       __skb_set_sw_hash(skb, flow_hash_from_keys(&keys),
-                         flow_keys_have_l4(&keys));
+       skb_set_sw_hash(skb, flow_hash_from_keys(&keys),
+                       flow_keys_have_l4(&keys) ?
+                       PKT_HASH_TYPE_L4 : PKT_HASH_TYPE_L3);
 
        return skb->hash;
 }
@@ -718,8 +720,9 @@ __u32 __skb_get_hash_flowi4(struct sk_buff *skb, const struct flowi4 *fl4)
        keys.keyid.keyid = fl4->fl4_gre_key;
        keys.basic.ip_proto = fl4->flowi4_proto;
 
-       __skb_set_sw_hash(skb, flow_hash_from_keys(&keys),
-                         flow_keys_have_l4(&keys));
+       skb_set_sw_hash(skb, flow_hash_from_keys(&keys),
+                       flow_keys_have_l4(&keys) ?
+                       PKT_HASH_TYPE_L4 : PKT_HASH_TYPE_L3);
 
        return skb->hash;
 }