Skip to contentSkip to conversation

net/ipv6: multipath routing: configurable seed

PATCH In review Pavel Balaev 1 participant 1 message Apr 28, 2021

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH v6 2/3 net/ipv6: multipath routing: configurable seed

Ability for a user to assign seed value to IPv6 multipath route hashes. This patch adds sysctl variable: net.ipv6.fib_multipath_hash_seed.

---
 include/net/netns/ipv6.h   |  3 ++
 net/ipv6/route.c           | 10 +++-
 net/ipv6/sysctl_net_ipv6.c | 96 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 108 insertions(+), 1 deletion(-)
include/net/netns/ipv6.h +3 -0
index 808f0f79e..6bb383b0a 100644
@@ -8,6 +8,7 @@
 #ifndef __NETNS_IPV6_H__
 #define __NETNS_IPV6_H__
 #include <net/dst_ops.h>
+#include <linux/siphash.h>
 #include <uapi/linux/icmpv6.h>
 
 struct ctl_table_header;
@@ -30,6 +31,7 @@ struct netns_sysctl_ipv6 {
 	int ip6_rt_min_advmss;
 	u8 bindv6only;
 	u8 multipath_hash_policy;
+	u8 multipath_hash_seed;
 	u8 flowlabel_consistency;
 	u8 auto_flowlabels;
 	int icmpv6_time;
@@ -107,6 +109,7 @@ struct netns_ipv6 {
 	struct fib_rules_ops	*mr6_rules_ops;
 #endif
 #endif
+	siphash_key_t __rcu	*multipath_hash_seed_ctx;
 	atomic_t		dev_addr_genid;
 	atomic_t		fib6_sernum;
 	struct seg6_pernet_data *seg6_data;
net/ipv6/route.c +9 -1
index 28801ae80..70c488812 100644
@@ -2331,6 +2331,7 @@ u32 rt6_multipath_hash(const struct net *net, const struct flowi6 *fl6,
 		       const struct sk_buff *skb, struct flow_keys *flkeys)
 {
 	struct flow_keys hash_keys;
+	siphash_key_t *seed_ctx;
 	u32 mhash;
 
 	switch (ip6_multipath_hash_policy(net)) {
@@ -2414,7 +2415,14 @@ u32 rt6_multipath_hash(const struct net *net, const struct flowi6 *fl6,
 		}
 		break;
 	}
-	mhash = flow_hash_from_keys(&hash_keys);
+
+	rcu_read_lock();
+	seed_ctx = rcu_dereference(net->ipv6.multipath_hash_seed_ctx);
+	if (seed_ctx)
+		mhash = flow_multipath_hash_from_keys(&hash_keys, seed_ctx);
+	else
+		mhash = flow_hash_from_keys(&hash_keys);
+	rcu_read_unlock();
 
 	return mhash >> 1;
 }
net/ipv6/sysctl_net_ipv6.c +96 -0

108 lines not on this page · raw message

Signature · 1 line
2.31.1