Skip to content

Commit bcc8383

Browse files
tomratbertdavem330
authored andcommitted
skbuff: Make __skb_set_sw_hash a general function
Move __skb_set_sw_hash to skbuff.h and add __skb_set_hash which is a common method (between __skb_set_sw_hash and skb_set_hash) to set the hash in an skbuff. Also, move skb_clear_hash to be closer to __skb_set_hash. Signed-off-by: Tom Herbert <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent e527693 commit bcc8383

File tree

3 files changed

+40
-28
lines changed

3 files changed

+40
-28
lines changed

include/linux/skbuff.h

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -937,14 +937,40 @@ enum pkt_hash_types {
937937
PKT_HASH_TYPE_L4, /* Input: src_IP, dst_IP, src_port, dst_port */
938938
};
939939

940-
static inline void
941-
skb_set_hash(struct sk_buff *skb, __u32 hash, enum pkt_hash_types type)
940+
static inline void skb_clear_hash(struct sk_buff *skb)
942941
{
943-
skb->l4_hash = (type == PKT_HASH_TYPE_L4);
942+
skb->hash = 0;
944943
skb->sw_hash = 0;
944+
skb->l4_hash = 0;
945+
}
946+
947+
static inline void skb_clear_hash_if_not_l4(struct sk_buff *skb)
948+
{
949+
if (!skb->l4_hash)
950+
skb_clear_hash(skb);
951+
}
952+
953+
static inline void
954+
__skb_set_hash(struct sk_buff *skb, __u32 hash, bool is_sw, bool is_l4)
955+
{
956+
skb->l4_hash = is_l4;
957+
skb->sw_hash = is_sw;
945958
skb->hash = hash;
946959
}
947960

961+
static inline void
962+
skb_set_hash(struct sk_buff *skb, __u32 hash, enum pkt_hash_types type)
963+
{
964+
/* Used by drivers to set hash from HW */
965+
__skb_set_hash(skb, hash, false, type == PKT_HASH_TYPE_L4);
966+
}
967+
968+
static inline void
969+
__skb_set_sw_hash(struct sk_buff *skb, __u32 hash, bool is_l4)
970+
{
971+
__skb_set_hash(skb, hash, true, is_l4);
972+
}
973+
948974
void __skb_get_hash(struct sk_buff *skb);
949975
u32 skb_get_poff(const struct sk_buff *skb);
950976
u32 __skb_get_poff(const struct sk_buff *skb, void *data,
@@ -1027,19 +1053,6 @@ static inline __u32 skb_get_hash_raw(const struct sk_buff *skb)
10271053
return skb->hash;
10281054
}
10291055

1030-
static inline void skb_clear_hash(struct sk_buff *skb)
1031-
{
1032-
skb->hash = 0;
1033-
skb->sw_hash = 0;
1034-
skb->l4_hash = 0;
1035-
}
1036-
1037-
static inline void skb_clear_hash_if_not_l4(struct sk_buff *skb)
1038-
{
1039-
if (!skb->l4_hash)
1040-
skb_clear_hash(skb);
1041-
}
1042-
10431056
static inline void skb_copy_hash(struct sk_buff *to, const struct sk_buff *from)
10441057
{
10451058
to->hash = from->hash;

include/net/flow_dissector.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,4 +167,9 @@ struct flow_keys_digest {
167167
void make_flow_keys_digest(struct flow_keys_digest *digest,
168168
const struct flow_keys *flow);
169169

170+
static inline bool flow_keys_have_l4(struct flow_keys *keys)
171+
{
172+
return (keys->ports.ports || keys->tags.flow_label);
173+
}
174+
170175
#endif

net/core/flow_dissector.c

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -590,15 +590,6 @@ void make_flow_keys_digest(struct flow_keys_digest *digest,
590590
}
591591
EXPORT_SYMBOL(make_flow_keys_digest);
592592

593-
static inline void __skb_set_sw_hash(struct sk_buff *skb, u32 hash,
594-
struct flow_keys *keys)
595-
{
596-
if (keys->ports.ports)
597-
skb->l4_hash = 1;
598-
skb->sw_hash = 1;
599-
skb->hash = hash;
600-
}
601-
602593
/**
603594
* __skb_get_hash: calculate a flow hash
604595
* @skb: sk_buff to calculate flow hash from
@@ -619,7 +610,8 @@ void __skb_get_hash(struct sk_buff *skb)
619610
if (!hash)
620611
return;
621612

622-
__skb_set_sw_hash(skb, hash, &keys);
613+
__skb_set_sw_hash(skb, hash,
614+
flow_keys_have_l4(&keys));
623615
}
624616
EXPORT_SYMBOL(__skb_get_hash);
625617

@@ -648,7 +640,8 @@ __u32 __skb_get_hash_flowi6(struct sk_buff *skb, struct flowi6 *fl6)
648640
keys.tags.flow_label = (__force u32)fl6->flowlabel;
649641
keys.basic.ip_proto = fl6->flowi6_proto;
650642

651-
__skb_set_sw_hash(skb, flow_hash_from_keys(&keys), &keys);
643+
__skb_set_sw_hash(skb, flow_hash_from_keys(&keys),
644+
flow_keys_have_l4(&keys));
652645

653646
return skb->hash;
654647
}
@@ -668,7 +661,8 @@ __u32 __skb_get_hash_flowi4(struct sk_buff *skb, struct flowi4 *fl4)
668661
keys.keyid.keyid = fl4->fl4_gre_key;
669662
keys.basic.ip_proto = fl4->flowi4_proto;
670663

671-
__skb_set_sw_hash(skb, flow_hash_from_keys(&keys), &keys);
664+
__skb_set_sw_hash(skb, flow_hash_from_keys(&keys),
665+
flow_keys_have_l4(&keys));
672666

673667
return skb->hash;
674668
}

0 commit comments

Comments
 (0)