[Openvpn-devel,net-next,3/4] net: restore __get_hash_from_flowi4

Message ID 45fd7978aa65dca13632657bcaba9fab6002f6c3.1794922487.git.ralf@mandelbit.com
State New
Headers
Series ovpn: select physical TX queues from the outer flow |

Commit Message

Ralf Lici Nov. 17, 2026, 2:11 p.m. UTC
  __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(+)
  

Patch

diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
index aaa33d44b01c..1c8bcacd4d0d 100644
--- a/include/linux/skbuff.h
+++ b/include/linux/skbuff.h
@@ -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) {
diff --git a/include/net/flow.h b/include/net/flow.h
index ae9481c40063..7a6ccd0d56bd 100644
--- a/include/net/flow.h
+++ b/include/net/flow.h
@@ -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
diff --git a/net/core/flow_dissector.c b/net/core/flow_dissector.c
index 1be6c739e3c7..8533a9ce232e 100644
--- a/net/core/flow_dissector.c
+++ b/net/core/flow_dissector.c
@@ -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,