[Openvpn-devel,net-next,3/4] net: restore __get_hash_from_flowi4
Commit Message
__get_hash_from_flowi4 was removed for lack of users in commit
de7a0f871fab ("net: Remove unused get_hash_from_flow functions"), while
its IPv6 counterpart survived for automatic flow labels. A tunnel which
routes its outer packets with a flowi can use these helpers to set the
outer flow hash without dissecting the packet, as ovpn will.
Restore the helper and add skb_get_hash_flowi4 next to
skb_get_hash_flowi6. Like the IPv6 variant, it leaves basic.n_proto
unset, so the hash is stable for a flow but not identical to the one
the flow dissector computes from the packet itself.
Signed-off-by: Ralf Lici <ralf@mandelbit.com>
---
include/linux/skbuff.h | 13 +++++++++++++
include/net/flow.h | 1 +
net/core/flow_dissector.c | 16 ++++++++++++++++
3 files changed, 30 insertions(+)
@@ -1679,6 +1679,19 @@ static inline __u32 skb_get_hash(struct sk_buff *skb)
return skb->hash;
}
+static inline __u32 skb_get_hash_flowi4(struct sk_buff *skb,
+ const struct flowi4 *fl4)
+{
+ if (!skb->l4_hash && !skb->sw_hash) {
+ struct flow_keys keys;
+ __u32 hash = __get_hash_from_flowi4(fl4, &keys);
+
+ __skb_set_sw_hash(skb, hash, flow_keys_have_l4(&keys));
+ }
+
+ return skb->hash;
+}
+
static inline __u32 skb_get_hash_flowi6(struct sk_buff *skb, const struct flowi6 *fl6)
{
if (!skb->l4_hash && !skb->sw_hash) {
@@ -194,5 +194,6 @@ static inline struct flowi_common *flowi6_to_flowi_common(struct flowi6 *fl6)
}
__u32 __get_hash_from_flowi6(const struct flowi6 *fl6, struct flow_keys *keys);
+__u32 __get_hash_from_flowi4(const struct flowi4 *fl4, struct flow_keys *keys);
#endif
@@ -2020,6 +2020,22 @@ __u32 __get_hash_from_flowi6(const struct flowi6 *fl6, struct flow_keys *keys)
}
EXPORT_SYMBOL(__get_hash_from_flowi6);
+__u32 __get_hash_from_flowi4(const struct flowi4 *fl4, struct flow_keys *keys)
+{
+ memset(keys, 0, sizeof(*keys));
+
+ keys->addrs.v4addrs.src = fl4->saddr;
+ keys->addrs.v4addrs.dst = fl4->daddr;
+ keys->control.addr_type = FLOW_DISSECTOR_KEY_IPV4_ADDRS;
+ keys->ports.src = fl4->fl4_sport;
+ keys->ports.dst = fl4->fl4_dport;
+ keys->keyid.keyid = fl4->fl4_gre_key;
+ keys->basic.ip_proto = fl4->flowi4_proto;
+
+ return flow_hash_from_keys(keys);
+}
+EXPORT_SYMBOL(__get_hash_from_flowi4);
+
static const struct flow_dissector_key flow_keys_dissector_keys[] = {
{
.key_id = FLOW_DISSECTOR_KEY_CONTROL,