Skip to contentSkip to conversation

net/ipv6: Add support for path selection using hash of 5-tuple

RFC PATCH In review David Ahern 4 participants 24 messages Feb 13, 2018 – Feb 21, 2018

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

cover net/ipv6: Add support for path selection using hash of 5-tuple

Hardware supports multipath selection using the standard L4 5-tuple instead of just L3 and the flow label. In addition, some network operators prefer IPv6 path selection to use the 5-tuple. To that end, add support to IPv6 for multipath hash policy similar to bf4e0a3db97eb ("net: ipv4: add support for ECMP hash policy choice"). The default is still L3 which covers source and destination addresses along with flow label and IPv6 protocol.

A separate sysctl is added for IPv6, allowing IPv4 and IPv6 to use different algorithms if desired.

The first 2 patches modify the IPv4 variant so that at the end of the patch set the ipv4 and ipv6 implementations are direct parallels.

Patch 3 refactors the existing rt6_multipath_hash in preparation for adding the policy option.

Patch 4 renames the existing netevent to have IPv4 in the name so ipv4 changes can be distinguished from IPv6 if the netevent handler cares.

Patch 5 adds the L4 hash support.

Patch 6 adds the hook for the netevent to the spectrum driver to update the ASIC.

Patch 7 removes no longer used code.

David Ahern (7):
net/ipv4: Pass net to fib_multipath_hash instead of fib_info
net: Align ip_multipath_l3_keys and ip6_multipath_l3_keys net/ipv6: Make rt6_multipath_hash similar to fib_multipath_hash
net: Rename NETEVENT_MULTIPATH_HASH_UPDATE
net/ipv6: Add support for path selection using hash of 5-tuple
mlxsw: spectrum_router: Add support for ipv6 hash policy update
net: Remove unused get_hash_from_flow functions

 Documentation/networking/ip-sysctl.txt             |  7 +++
 .../net/ethernet/mellanox/mlxsw/spectrum_router.c  | 13 ++++-
 include/net/flow.h                                 | 15 -----
 include/net/ip6_route.h                            |  3 +-
 include/net/ip_fib.h                               |  2 +-
 include/net/netevent.h                             |  3 +-
 include/net/netns/ipv6.h                           |  1 +
 net/core/flow_dissector.c                          | 16 ------
 net/ipv4/fib_semantics.c                           |  2 +-
 net/ipv4/route.c                                   | 25 +++++----
 net/ipv4/sysctl_net_ipv4.c                         |  2 +-
 net/ipv6/icmp.c                                    |  2 +-
 net/ipv6/route.c                                   | 64 ++++++++++++++++++----
 net/ipv6/sysctl_net_ipv6.c                         | 26 +++++++++
 14 files changed, 118 insertions(+), 63 deletions(-)
Signature · 1 line
2.11.0
#1 lore raw

RFC PATCH 1/7 net/ipv4: Pass net to fib_multipath_hash instead of fib_info

fib_multipath_hash only needs net struct to check a sysctl. Make it clear by passing net instead of fib_info. In the need this allows alignment between the ipv4 and ipv6 versions.

---
 include/net/ip_fib.h     | 2 +-
 net/ipv4/fib_semantics.c | 2 +-
 net/ipv4/route.c         | 5 ++---
 3 files changed, 4 insertions(+), 5 deletions(-)
include/net/ip_fib.h +1 -1
index f80524396c06..0472bf774a5a 100644
@@ -370,7 +370,7 @@ int fib_sync_down_addr(struct net_device *dev, __be32 local);
 int fib_sync_up(struct net_device *dev, unsigned int nh_flags);
 
 #ifdef CONFIG_IP_ROUTE_MULTIPATH
-int fib_multipath_hash(const struct fib_info *fi, const struct flowi4 *fl4,
+int fib_multipath_hash(const struct net *net, const struct flowi4 *fl4,
 		       const struct sk_buff *skb);
 #endif
 void fib_select_multipath(struct fib_result *res, int hash);
net/ipv4/fib_semantics.c +1 -1
index c586597da20d..e22443244190 100644
@@ -1767,7 +1767,7 @@ void fib_select_path(struct net *net, struct fib_result *res,
 
 #ifdef CONFIG_IP_ROUTE_MULTIPATH
 	if (res->fi->fib_nhs > 1 && oif_check) {
-		int h = fib_multipath_hash(res->fi, fl4, skb);
+		int h = fib_multipath_hash(res->fi->fib_net, fl4, skb);
 
 		fib_select_multipath(res, h);
 	}
net/ipv4/route.c +2 -3
index 49cc1c1df1ba..975c4b7cff07 100644
@@ -1797,10 +1797,9 @@ static void ip_multipath_l3_keys(const struct sk_buff *skb,
 }
 
 /* if skb is set it will be used and fl4 can be NULL */
-int fib_multipath_hash(const struct fib_info *fi, const struct flowi4 *fl4,
+int fib_multipath_hash(const struct net *net, const struct flowi4 *fl4,
 		       const struct sk_buff *skb)
 {
-	struct net *net = fi->fib_net;
 	struct flow_keys hash_keys;
 	u32 mhash;
 
@@ -1856,7 +1855,7 @@ static int ip_mkroute_input(struct sk_buff *skb,
 {
 #ifdef CONFIG_IP_ROUTE_MULTIPATH
 	if (res->fi && res->fi->fib_nhs > 1) {
-		int h = fib_multipath_hash(res->fi, NULL, skb);
+		int h = fib_multipath_hash(res->fi->fib_net, NULL, skb);
 
 		fib_select_multipath(res, h);
 	}
Signature · 1 line
2.11.0
#2 lore raw

RFC PATCH 2/7 net: Align ip_multipath_l3_keys and ip6_multipath_l3_keys

In reply to David Ahern

Symmetry is good and allows easy comparison that ipv4 and ipv6 are doing the same thing. To that end, change ip_multipath_l3_keys to set addresses at the end after the icmp compares, and move the initialization of ipv6 flow keys to rt6_multipath_hash.

---
 net/ipv4/route.c | 20 +++++++++++---------
 net/ipv6/route.c |  4 ++--
 2 files changed, 13 insertions(+), 11 deletions(-)
net/ipv4/route.c +11 -9
index 975c4b7cff07..228af793d154 100644
@@ -1763,37 +1763,39 @@ static void ip_multipath_l3_keys(const struct sk_buff *skb,
 				 struct flow_keys *hash_keys)
 {
 	const struct iphdr *outer_iph = ip_hdr(skb);
+	const struct iphdr *key_iph = outer_iph;
 	const struct iphdr *inner_iph;
 	const struct icmphdr *icmph;
 	struct iphdr _inner_iph;
 	struct icmphdr _icmph;
 
-	hash_keys->addrs.v4addrs.src = outer_iph->saddr;
-	hash_keys->addrs.v4addrs.dst = outer_iph->daddr;
 	if (likely(outer_iph->protocol != IPPROTO_ICMP))
-		return;
+		goto out;
 
 	if (unlikely((outer_iph->frag_off & htons(IP_OFFSET)) != 0))
-		return;
+		goto out;
 
 	icmph = skb_header_pointer(skb, outer_iph->ihl * 4, sizeof(_icmph),
 				   &_icmph);
 	if (!icmph)
-		return;
+		goto out;
 
 	if (icmph->type != ICMP_DEST_UNREACH &&
 	    icmph->type != ICMP_REDIRECT &&
 	    icmph->type != ICMP_TIME_EXCEEDED &&
 	    icmph->type != ICMP_PARAMETERPROB)
-		return;
+		goto out;
 
 	inner_iph = skb_header_pointer(skb,
 				       outer_iph->ihl * 4 + sizeof(_icmph),
 				       sizeof(_inner_iph), &_inner_iph);
 	if (!inner_iph)
-		return;
-	hash_keys->addrs.v4addrs.src = inner_iph->saddr;
-	hash_keys->addrs.v4addrs.dst = inner_iph->daddr;
+		goto out;
+
+	key_iph = inner_iph;
+out:
+	hash_keys->addrs.v4addrs.src = key_iph->saddr;
+	hash_keys->addrs.v4addrs.dst = key_iph->daddr;
 }
 
 /* if skb is set it will be used and fl4 can be NULL */
net/ipv6/route.c +2 -2
index 9dcfadddd800..baef18635f96 100644
@@ -1812,8 +1812,6 @@ static void ip6_multipath_l3_keys(const struct sk_buff *skb,
 
 	key_iph = inner_iph;
 out:
-	memset(keys, 0, sizeof(*keys));
-	keys->control.addr_type = FLOW_DISSECTOR_KEY_IPV6_ADDRS;
 	keys->addrs.v6addrs.src = key_iph->saddr;
 	keys->addrs.v6addrs.dst = key_iph->daddr;
 	keys->tags.flow_label = ip6_flowinfo(key_iph);
@@ -1826,6 +1824,8 @@ u32 rt6_multipath_hash(const struct flowi6 *fl6, const struct sk_buff *skb)
 	struct flow_keys hash_keys;
 
 	if (skb) {
+		memset(&hash_keys, 0, sizeof(hash_keys));
+		hash_keys.control.addr_type = FLOW_DISSECTOR_KEY_IPV6_ADDRS;
 		ip6_multipath_l3_keys(skb, &hash_keys);
 		return flow_hash_from_keys(&hash_keys) >> 1;
 	}
Signature · 1 line
2.11.0
#3 lore raw

RFC PATCH 3/7 net/ipv6: Make rt6_multipath_hash similar to fib_multipath_hash

In reply to David Ahern

Make rt6_multipath_hash more of a direct parallel to fib_multipath_hash and reduce stack and overhead in the process: get_hash_from_flowi6 is just a wrapper around __get_hash_from_flowi6 with another stack allocation for flow_keys. Move setting the addresses, protocol and label into rt6_multipath_hash and allow it to make the call to flow_hash_from_keys.

---
 net/ipv6/route.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
net/ipv6/route.c +10 -4
index baef18635f96..8d3a95eed662 100644
@@ -1822,15 +1822,21 @@ static void ip6_multipath_l3_keys(const struct sk_buff *skb,
 u32 rt6_multipath_hash(const struct flowi6 *fl6, const struct sk_buff *skb)
 {
 	struct flow_keys hash_keys;
+	u32 mhash;
 
+	memset(&hash_keys, 0, sizeof(hash_keys));
+	hash_keys.control.addr_type = FLOW_DISSECTOR_KEY_IPV6_ADDRS;
 	if (skb) {
-		memset(&hash_keys, 0, sizeof(hash_keys));
-		hash_keys.control.addr_type = FLOW_DISSECTOR_KEY_IPV6_ADDRS;
 		ip6_multipath_l3_keys(skb, &hash_keys);
-		return flow_hash_from_keys(&hash_keys) >> 1;
+	} else {
+		hash_keys.addrs.v6addrs.src = fl6->saddr;
+		hash_keys.addrs.v6addrs.dst = fl6->daddr;
+		hash_keys.tags.flow_label = (__force u32)fl6->flowlabel;
+		hash_keys.basic.ip_proto = fl6->flowi6_proto;
 	}
+	mhash = flow_hash_from_keys(&hash_keys);
 
-	return get_hash_from_flowi6(fl6) >> 1;
+	return mhash >> 1;
 }
 
 void ip6_route_input(struct sk_buff *skb)
Signature · 1 line
2.11.0
#4 lore raw

RFC PATCH 4/7 net: Rename NETEVENT_MULTIPATH_HASH_UPDATE

In reply to David Ahern

Rename NETEVENT_MULTIPATH_HASH_UPDATE to NETEVENT_IPV4_MPATH_HASH_UPDATE to denote it relates to a change in the IPv4 hash policy.

---
 drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c | 2 +-
 include/net/netevent.h                                | 2 +-
 net/ipv4/sysctl_net_ipv4.c                            | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c +1 -1
index f0b25baba09a..3071b75af6e0 100644
@@ -2413,7 +2413,7 @@ static int mlxsw_sp_router_netevent_event(struct notifier_block *nb,
 		mlxsw_core_schedule_work(&net_work->work);
 		mlxsw_sp_port_dev_put(mlxsw_sp_port);
 		break;
-	case NETEVENT_MULTIPATH_HASH_UPDATE:
+	case NETEVENT_IPV4_MPATH_HASH_UPDATE:
 		net = ptr;
 
 		if (!net_eq(net, &init_net))
include/net/netevent.h +1 -1
index 40e7bab68490..baee605a94ab 100644
@@ -26,7 +26,7 @@ enum netevent_notif_type {
 	NETEVENT_NEIGH_UPDATE = 1, /* arg is struct neighbour ptr */
 	NETEVENT_REDIRECT,	   /* arg is struct netevent_redirect ptr */
 	NETEVENT_DELAY_PROBE_TIME_UPDATE, /* arg is struct neigh_parms ptr */
-	NETEVENT_MULTIPATH_HASH_UPDATE, /* arg is struct net ptr */
+	NETEVENT_IPV4_MPATH_HASH_UPDATE, /* arg is struct net ptr */
 };
 
 int register_netevent_notifier(struct notifier_block *nb);
net/ipv4/sysctl_net_ipv4.c +1 -1
index 93e172118a94..52d869d17554 100644
@@ -400,7 +400,7 @@ static int proc_fib_multipath_hash_policy(struct ctl_table *table, int write,
 
 	ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
 	if (write && ret == 0)
-		call_netevent_notifiers(NETEVENT_MULTIPATH_HASH_UPDATE, net);
+		call_netevent_notifiers(NETEVENT_IPV4_MPATH_HASH_UPDATE, net);
 
 	return ret;
 }
Signature · 1 line
2.11.0
#5 lore raw

RFC PATCH 5/7 net/ipv6: Add support for path selection using hash of 5-tuple

In reply to David Ahern

Some operators prefer IPv6 path selection to use a standard 5-tuple hash rather than just an L3 hash with the flow the label. To that end add support to IPv6 for multipath hash policy similar to bf4e0a3db97eb ("net: ipv4: add support for ECMP hash policy choice"). The default is still L3 which covers source and destination addresses along with flow label and IPv6 protocol.

---
 Documentation/networking/ip-sysctl.txt |  7 ++++
 include/net/ip6_route.h                |  3 +-
 include/net/netevent.h                 |  1 +
 include/net/netns/ipv6.h               |  1 +
 net/ipv6/icmp.c                        |  2 +-
 net/ipv6/route.c                       | 64 ++++++++++++++++++++++++++--------
 net/ipv6/sysctl_net_ipv6.c             | 26 ++++++++++++++
 7 files changed, 87 insertions(+), 17 deletions(-)
Documentation/networking/ip-sysctl.txt +7 -0
index a553d4e4a0fb..783675a730e5 100644
@@ -1363,6 +1363,13 @@ flowlabel_reflect - BOOLEAN
 	FALSE: disabled
 	Default: FALSE
 
+fib_multipath_hash_policy - INTEGER
+	Controls which hash policy to use for multipath routes.
+	Default: 0 (Layer 3)
+	Possible values:
+	0 - Layer 3 (source and destination addresses plus flow label)
+	1 - Layer 4 (standard 5-tuple)
+
 anycast_src_echo_reply - BOOLEAN
 	Controls the use of anycast addresses as source addresses for ICMPv6
 	echo reply
include/net/ip6_route.h +2 -1
index 27d23a65f3cd..f13657a62e5c 100644
@@ -127,7 +127,8 @@ static inline int ip6_route_get_saddr(struct net *net, struct rt6_info *rt,
 
 struct rt6_info *rt6_lookup(struct net *net, const struct in6_addr *daddr,
 			    const struct in6_addr *saddr, int oif, int flags);
-u32 rt6_multipath_hash(const struct flowi6 *fl6, const struct sk_buff *skb);
+u32 rt6_multipath_hash(const struct net *net, const struct flowi6 *fl6,
+		       const struct sk_buff *skb);
 
 struct dst_entry *icmp6_dst_alloc(struct net_device *dev, struct flowi6 *fl6);
 
include/net/netevent.h +1 -0
index baee605a94ab..d9918261701c 100644
@@ -27,6 +27,7 @@ enum netevent_notif_type {
 	NETEVENT_REDIRECT,	   /* arg is struct netevent_redirect ptr */
 	NETEVENT_DELAY_PROBE_TIME_UPDATE, /* arg is struct neigh_parms ptr */
 	NETEVENT_IPV4_MPATH_HASH_UPDATE, /* arg is struct net ptr */
+	NETEVENT_IPV6_MPATH_HASH_UPDATE, /* arg is struct net ptr */
 };
 
 int register_netevent_notifier(struct notifier_block *nb);
include/net/netns/ipv6.h +1 -0
index 987cc4569cb8..6b0de3b71bbf 100644
@@ -28,6 +28,7 @@ struct netns_sysctl_ipv6 {
 	int ip6_rt_gc_elasticity;
 	int ip6_rt_mtu_expires;
 	int ip6_rt_min_advmss;
+	int multipath_hash_policy;
 	int flowlabel_consistency;
 	int auto_flowlabels;
 	int icmpv6_time;
net/ipv6/icmp.c +1 -1
index 6ae5dd3f4d0d..e255c9dd9b57 100644
@@ -522,7 +522,7 @@ static void icmp6_send(struct sk_buff *skb, u8 type, u8 code, __u32 info,
 	fl6.fl6_icmp_type = type;
 	fl6.fl6_icmp_code = code;
 	fl6.flowi6_uid = sock_net_uid(net, NULL);
-	fl6.mp_hash = rt6_multipath_hash(&fl6, skb);
+	fl6.mp_hash = rt6_multipath_hash(net, &fl6, skb);
 	security_skb_classify_flow(skb, flowi6_to_flowi(&fl6));
 
 	sk = icmpv6_xmit_lock(net);
net/ipv6/route.c +49 -15

104 lines not on this page · raw message

net/ipv6/sysctl_net_ipv6.c +26 -0
index a789a8ac6a64..ca4696b46483 100644
@@ -16,14 +16,31 @@
 #include <net/ipv6.h>
 #include <net/addrconf.h>
 #include <net/inet_frag.h>
+#include <net/netevent.h>
 #ifdef CONFIG_NETLABEL
 #include <net/calipso.h>
 #endif
 
+static int zero;
 static int one = 1;
 static int auto_flowlabels_min;
 static int auto_flowlabels_max = IP6_AUTO_FLOW_LABEL_MAX;
 
+static int proc_rt6_multipath_hash_policy(struct ctl_table *table, int write,
+					  void __user *buffer, size_t *lenp,
+					  loff_t *ppos)
+{
+	struct net *net;
+	int ret;
+
+	net = container_of(table->data, struct net,
+			   ipv6.sysctl.multipath_hash_policy);
+	ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
+	if (write && ret == 0)
+		call_netevent_notifiers(NETEVENT_IPV6_MPATH_HASH_UPDATE, net);
+
+	return ret;
+}
 
 static struct ctl_table ipv6_table_template[] = {
 	{
@@ -126,6 +143,15 @@ static struct ctl_table ipv6_table_template[] = {
 		.mode		= 0644,
 		.proc_handler	= proc_dointvec
 	},
+	{
+		.procname	= "fib_multipath_hash_policy",
+		.data		= &init_net.ipv6.sysctl.multipath_hash_policy,
+		.maxlen		= sizeof(int),
+		.mode		= 0644,
+		.proc_handler   = proc_rt6_multipath_hash_policy,
+		.extra1		= &zero,
+		.extra2		= &one,
+	},
 	{ }
 };
 
Signature · 1 line
2.11.0
#13 lore raw

RFC PATCH 6/7 mlxsw: spectrum_router: Add support for ipv6 hash policy update

In reply to David Ahern

Similar to 28678f07f127d ("mlxsw: spectrum_router: Update multipath hash parameters upon netevents") for IPv4, make sure the kernel and asic are using the same hash algorithm for path selection.

---
 drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c +10 -1
index 3071b75af6e0..d23ed0002a4a 100644
@@ -2414,6 +2414,7 @@ static int mlxsw_sp_router_netevent_event(struct notifier_block *nb,
 		mlxsw_sp_port_dev_put(mlxsw_sp_port);
 		break;
 	case NETEVENT_IPV4_MPATH_HASH_UPDATE:
+	case NETEVENT_IPV6_MPATH_HASH_UPDATE:
 		net = ptr;
 
 		if (!net_eq(net, &init_net))
@@ -7006,13 +7007,21 @@ static void mlxsw_sp_mp4_hash_init(char *recr2_pl)
 
 static void mlxsw_sp_mp6_hash_init(char *recr2_pl)
 {
+	bool only_l3 = !init_net.ipv6.sysctl.multipath_hash_policy;
+
 	mlxsw_sp_mp_hash_header_set(recr2_pl,
 				    MLXSW_REG_RECR2_IPV6_EN_NOT_TCP_NOT_UDP);
 	mlxsw_sp_mp_hash_header_set(recr2_pl, MLXSW_REG_RECR2_IPV6_EN_TCP_UDP);
 	mlxsw_reg_recr2_ipv6_sip_enable(recr2_pl);
 	mlxsw_reg_recr2_ipv6_dip_enable(recr2_pl);
-	mlxsw_sp_mp_hash_field_set(recr2_pl, MLXSW_REG_RECR2_IPV6_FLOW_LABEL);
 	mlxsw_sp_mp_hash_field_set(recr2_pl, MLXSW_REG_RECR2_IPV6_NEXT_HEADER);
+	if (only_l3) {
+		mlxsw_sp_mp_hash_field_set(recr2_pl, MLXSW_REG_RECR2_IPV6_FLOW_LABEL);
+	} else {
+		mlxsw_sp_mp_hash_header_set(recr2_pl, MLXSW_REG_RECR2_TCP_UDP_EN_IPV6);
+		mlxsw_sp_mp_hash_field_set(recr2_pl, MLXSW_REG_RECR2_TCP_UDP_SPORT);
+		mlxsw_sp_mp_hash_field_set(recr2_pl, MLXSW_REG_RECR2_TCP_UDP_DPORT);
+	}
 }
 
 static int mlxsw_sp_mp_hash_init(struct mlxsw_sp *mlxsw_sp)
Signature · 1 line
2.11.0
#14 lore raw

RFC PATCH 7/7 net: Remove unused get_hash_from_flow functions

In reply to David Ahern

__get_hash_from_flowi6 is still used for flowlabels, but the IPv4 variant and the wrappers to both are not used. Remove them.

---
 include/net/flow.h        | 15 ---------------
 net/core/flow_dissector.c | 16 ----------------
 2 files changed, 31 deletions(-)
include/net/flow.h +0 -15
index f1624fd5b1d0..871c27af6577 100644
@@ -221,21 +221,6 @@ static inline unsigned int flow_key_size(u16 family)
 }
 
 __u32 __get_hash_from_flowi6(const struct flowi6 *fl6, struct flow_keys *keys);
-
-static inline __u32 get_hash_from_flowi6(const struct flowi6 *fl6)
-{
-	struct flow_keys keys;
-
-	return __get_hash_from_flowi6(fl6, &keys);
-}
-
 __u32 __get_hash_from_flowi4(const struct flowi4 *fl4, struct flow_keys *keys);
 
-static inline __u32 get_hash_from_flowi4(const struct flowi4 *fl4)
-{
-	struct flow_keys keys;
-
-	return __get_hash_from_flowi4(fl4, &keys);
-}
-
 #endif
net/core/flow_dissector.c +0 -16
index 559db9ea8d86..d29f09bc5ff9 100644
@@ -1341,22 +1341,6 @@ __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,
Signature · 1 line
2.11.0
#15 lore raw
In reply to David Ahern
Quoted 3 lines · David Ahern

Hardware supports multipath selection using the standard L4 5-tuple instead of just L3 and the flow label. In addition, some network operators prefer IPv6 path selection to use the 5-tuple.

The HW supports using flow label and AFAIK that is the preferred approach by the community (?)

Quoted 1 line

To that end, add support to IPv6 for multipath hash policy

so a question comes up if/what are the disadvantaged
to support 5-tuple. E.g Tom was commenting that such DPI is problematic when multiple IPv6 header extensions are used.

Quoted 6 lines

similar to bf4e0a3db97eb ("net: ipv4: add support for ECMP hash policy choice"). The default is still L3 which covers source and destination addresses along with flow label and IPv6 protocol.

A separate sysctl is added for IPv6, allowing IPv4 and IPv6 to use different algorithms if desired.

#23 lore raw
In reply to David Ahern

Hi David,

Quoted 20 lines · David Ahern

Hardware supports multipath selection using the standard L4 5-tuple instead of just L3 and the flow label. In addition, some network operators prefer IPv6 path selection to use the 5-tuple. To that end, add support to IPv6 for multipath hash policy similar to bf4e0a3db97eb ("net: ipv4: add support for ECMP hash policy choice"). The default is still L3 which covers source and destination addresses along with flow label and IPv6 protocol.

A separate sysctl is added for IPv6, allowing IPv4 and IPv6 to use different algorithms if desired.

The first 2 patches modify the IPv4 variant so that at the end of the patch set the ipv4 and ipv6 implementations are direct parallels.

Patch 3 refactors the existing rt6_multipath_hash in preparation for adding the policy option.

Patch 4 renames the existing netevent to have IPv4 in the name so ipv4 changes can be distinguished from IPv6 if the netevent handler cares.

Quoted 6 lines

Patch 5 adds the L4 hash support.

Patch 6 adds the hook for the netevent to the spectrum driver to update the ASIC.

Patch 7 removes no longer used code.

Thanks for working on this.

I've yet to review the patches, but I did test them. The good news is that the offloaded path works as expected. Different flows (random UDP destination port, zero flowlabel) are hashed to different nexthops. With the default policy all the flows are hashed to the same nexthop.

However, it seems that the kernel isn't spreading the traffic as expected and the same nexthop is always hit. I'll look into it later this week when I have some more time.

Thanks!

#16 lore raw
In reply to Or Gerlitz
Quoted 5 lines · Or Gerlitz
Quoted 3 lines · David Ahern

Hardware supports multipath selection using the standard L4 5-tuple instead of just L3 and the flow label. In addition, some network operators prefer IPv6 path selection to use the 5-tuple.

Quoted 8 lines

The HW supports using flow label and AFAIK that is the preferred approach by the community (?)

Quoted 1 line

To that end, add support to IPv6 for multipath hash policy

so a question comes up if/what are the disadvantaged
to support 5-tuple. E.g Tom was commenting that such DPI is problematic when multiple IPv6 header extensions are used.

Tom is much more qualified to answer this, but I think the problem is that the flow label isn't always set. Also, apparently some devices change the flow label mid flow. See:

"At Fastly, this hashing is performed by an Ethernet switch ASIC, and to avoid breakage, the IPv6 hashing function must not include the flow label. As in IPv4, the hash function includes the source and destination information in the L3 and L4 headers."
https://blog.apnic.net/2018/01/11/ipv6-flow-label-misuse-hashing/
https://www.youtube.com/watch?v=b0CRjOpnT7w
https://pc.nanog.org/static/published/meetings/NANOG71/1531/20171003_Jaeggli_Lightning_Talk_Ipv6_v1.pdf

#17 lore raw
Quoted 11 lines · Ido Schimmel
Quoted 10 lines · Or Gerlitz
Quoted 3 lines · David Ahern

Hardware supports multipath selection using the standard L4 5-tuple instead of just L3 and the flow label. In addition, some network operators prefer IPv6 path selection to use the 5-tuple.

The HW supports using flow label and AFAIK that is the preferred approach by the community (?)

Quoted 1 line

To that end, add support to IPv6 for multipath hash policy

Quoted 7 lines
Quoted 3 lines

so a question comes up if/what are the disadvantaged
to support 5-tuple. E.g Tom was commenting that such DPI is problematic when multiple IPv6 header extensions are used.

Tom is much more qualified to answer this, but I think the problem is that the flow label isn't always set. Also, apparently some devices change the flow label mid flow. See:

OK. But note we have two ends to deal with here (1) generation (2) usage

E.g if the kernel generates flow label but uses source port we have inconsistent environment. Problem is that the generation and usage typically don't happen on the same network point.

#19 lore raw
In reply to Ido Schimmel
Quoted 6 lines · Ido Schimmel
Quoted 5 lines · Or Gerlitz
Quoted 3 lines · David Ahern

Hardware supports multipath selection using the standard L4 5-tuple instead of just L3 and the flow label. In addition, some network operators prefer IPv6 path selection to use the 5-tuple.

Quoted 8 lines
Quoted 8 lines

The HW supports using flow label and AFAIK that is the preferred approach by the community (?)

Quoted 1 line

To that end, add support to IPv6 for multipath hash policy

so a question comes up if/what are the disadvantaged
to support 5-tuple. E.g Tom was commenting that such DPI is problematic when multiple IPv6 header extensions are used.

Pros and cons to both approaches (L3 only or L4). We (Cumulus Networks) use L4 5-tuple hash for both IPv4 and IPv6. When I asked around various experts all of them gave me a puzzled look as to why I was asking the question. Basically, the unanimous response was of course it is an L4 hash.

Quoted 13 lines

Tom is much more qualified to answer this, but I think the problem is that the flow label isn't always set. Also, apparently some devices change the flow label mid flow. See:

"At Fastly, this hashing is performed by an Ethernet switch ASIC, and to avoid breakage, the IPv6 hashing function must not include the flow label. As in IPv4, the hash function includes the source and destination information in the L3 and L4 headers."
https://blog.apnic.net/2018/01/11/ipv6-flow-label-misuse-hashing/
https://www.youtube.com/watch?v=b0CRjOpnT7w
https://pc.nanog.org/static/published/meetings/NANOG71/1531/20171003_Jaeggli_Lightning_Talk_Ipv6_v1.pdf

#6 lore raw
In reply to David Ahern

Le 13/02/2018 à 01:06, David Ahern a écrit :

Quoted 9 lines

Some operators prefer IPv6 path selection to use a standard 5-tuple hash rather than just an L3 hash with the flow the label. To that end add support to IPv6 for multipath hash policy similar to bf4e0a3db97eb ("net: ipv4: add support for ECMP hash policy choice"). The default is still L3 which covers source and destination addresses along with flow label and IPv6 protocol.

---

Do you plan to add the nl NETCONF support for this new sysctl?

Regards,
Nicolas

#7 lore raw
Quoted 8 lines · Nicolas Dichtel

Le 13/02/2018 à 01:06, David Ahern a écrit :

Quoted 7 lines

Some operators prefer IPv6 path selection to use a standard 5-tuple hash rather than just an L3 hash with the flow the label. To that end add support to IPv6 for multipath hash policy similar to bf4e0a3db97eb ("net: ipv4: add support for ECMP hash policy choice"). The default is still L3 which covers source and destination addresses along with flow label and IPv6 protocol.

Quoted 4 lines
Quoted 2 lines

---

Do you plan to add the nl NETCONF support for this new sysctl?

hmmm.... doesn't exist for the current IPv4 version, but in-kernel drivers are notified. I wasn't planning on it, but it can be added.

#8 lore raw

Le 13/02/2018 à 21:35, David Ahern a écrit :

Quoted 9 lines · Nicolas Dichtel
Quoted 8 lines

Le 13/02/2018 à 01:06, David Ahern a écrit :

Quoted 7 lines

Some operators prefer IPv6 path selection to use a standard 5-tuple hash rather than just an L3 hash with the flow the label. To that end add support to IPv6 for multipath hash policy similar to bf4e0a3db97eb ("net: ipv4: add support for ECMP hash policy choice"). The default is still L3 which covers source and destination addresses along with flow label and IPv6 protocol.

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

---

Do you plan to add the nl NETCONF support for this new sysctl?

hmmm.... doesn't exist for the current IPv4 version, but in-kernel drivers are notified. I wasn't planning on it, but it can be added.

Right for ipv4, it was on my todo list ;-)

#9 lore raw
Quoted 12 lines · Nicolas Dichtel

Le 13/02/2018 à 21:35, David Ahern a écrit :

Quoted 11 lines · Nicolas Dichtel
Quoted 10 lines

Le 13/02/2018 à 01:06, David Ahern a écrit :

Quoted 9 lines

Some operators prefer IPv6 path selection to use a standard 5-tuple hash rather than just an L3 hash with the flow the label. To that end add support to IPv6 for multipath hash policy similar to bf4e0a3db97eb ("net: ipv4: add support for ECMP hash policy choice"). The default is still L3 which covers source and destination addresses along with flow label and IPv6 protocol.

---

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

Do you plan to add the nl NETCONF support for this new sysctl?

hmmm.... doesn't exist for the current IPv4 version, but in-kernel drivers are notified. I wasn't planning on it, but it can be added.

Right for ipv4, it was on my todo list ;-)

Awesome, then ipv6 is a 1-liner after you add ipv4 support. :-)

#10 lore raw

Le 13/02/2018 à 22:02, David Ahern a écrit :

Quoted 16 lines · Nicolas Dichtel
Quoted 15 lines

Le 13/02/2018 à 21:35, David Ahern a écrit :

Quoted 14 lines · Nicolas Dichtel
Quoted 12 lines

Le 13/02/2018 à 01:06, David Ahern a écrit :

Quoted 9 lines

Some operators prefer IPv6 path selection to use a standard 5-tuple hash rather than just an L3 hash with the flow the label. To that end add support to IPv6 for multipath hash policy similar to bf4e0a3db97eb ("net: ipv4: add support for ECMP hash policy choice"). The default is still L3 which covers source and destination addresses along with flow label and IPv6 protocol.

---

Do you plan to add the nl NETCONF support for this new sysctl?

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

hmmm.... doesn't exist for the current IPv4 version, but in-kernel drivers are notified. I wasn't planning on it, but it can be added.

Right for ipv4, it was on my todo list ;-)

Awesome, then ipv6 is a 1-liner after you add ipv4 support. :-)

Sure :)

#20 lore raw
In reply to David Ahern
Quoted 12 lines · David Ahern
Quoted 11 lines · Ido Schimmel
Quoted 10 lines · Or Gerlitz
Quoted 3 lines · David Ahern

Hardware supports multipath selection using the standard L4 5-tuple instead of just L3 and the flow label. In addition, some network operators prefer IPv6 path selection to use the 5-tuple.

The HW supports using flow label and AFAIK that is the preferred approach by the community (?)

Quoted 1 line

To that end, add support to IPv6 for multipath hash policy

Quoted 8 lines
Quoted 3 lines
Quoted 3 lines

so a question comes up if/what are the disadvantaged
to support 5-tuple. E.g Tom was commenting that such DPI is problematic when multiple IPv6 header extensions are used.

Pros and cons to both approaches (L3 only or L4). We (Cumulus Networks) use L4 5-tuple hash for both IPv4 and IPv6. When I asked around various experts all of them gave me a puzzled look as to why I was asking the question. Basically, the unanimous response was of course it is an L4 hash.

how the various systems you are dealing with do with traffic that involves ipv6 extension headers? what about environments with GRE? in ipv4 GRE fabrics are just broken for ECMP, in ipv6 they can fly with flow label but will crash again with L4 hash.

#18 lore raw
In reply to Or Gerlitz
Quoted 5 lines · Or Gerlitz

[...] note we have two ends to deal with here (1) generation (2) usage

E.g if the kernel generates flow label but uses source port we have inconsistent environment. Problem is that the generation and usage typically don't happen on the same network point.

David, what's your thinking here? e.g for overly networks environments

#21 lore raw
In reply to Or Gerlitz
Quoted 22 lines · Or Gerlitz
Quoted 12 lines · David Ahern
Quoted 11 lines · Ido Schimmel
Quoted 10 lines · Or Gerlitz
Quoted 3 lines · David Ahern

Hardware supports multipath selection using the standard L4 5-tuple instead of just L3 and the flow label. In addition, some network operators prefer IPv6 path selection to use the 5-tuple.

The HW supports using flow label and AFAIK that is the preferred approach by the community (?)

Quoted 1 line

To that end, add support to IPv6 for multipath hash policy

Quoted 8 lines
Quoted 3 lines
Quoted 3 lines

so a question comes up if/what are the disadvantaged
to support 5-tuple. E.g Tom was commenting that such DPI is problematic when multiple IPv6 header extensions are used.

Pros and cons to both approaches (L3 only or L4). We (Cumulus Networks) use L4 5-tuple hash for both IPv4 and IPv6. When I asked around various experts all of them gave me a puzzled look as to why I was asking the question. Basically, the unanimous response was of course it is an L4 hash.

Quoted 5 lines

how the various systems you are dealing with do with traffic that involves ipv6 extension headers? what about environments with GRE? in ipv4 GRE fabrics are just broken for ECMP, in ipv6 they can fly with flow label but will crash again with L4 hash.

If you like your ecmp hash algorithm, you can keep your ecmp hash algorithm.

This gives users a choice; it is not a requirement to move from L3 only to L4. Further, this makes IPv6 on par with IPv4 with a choice between L3 and L4 and allows users to decide what works best for them.

#22 lore raw
Quoted 7 lines · David Ahern
Quoted 4 lines · Or Gerlitz

how the various systems you are dealing with do with traffic that involves ipv6 extension headers? what about environments with GRE? in ipv4 GRE fabrics are just broken for ECMP, in ipv6 they can fly with flow label but will crash again with L4 hash.

Quoted 5 lines

If you like your ecmp hash algorithm, you can keep your ecmp hash algorithm.

This gives users a choice; it is not a requirement to move from L3 only to L4. Further, this makes IPv6 on par with IPv4 with a choice between L3 and L4 and allows users to decide what works best for them.

Looking in the code for tunnels e.g in the vxlan xmit path (but I believe this is the case for
other UDP tunnels as well), a call is made to generate the source udp port as the hash of
the overlay tuple regardless if we are on v4/v6. Next, when it comes to ipv6, the kernel
computes the flow label which effectively takes into account the inner header.

#11 lore raw
In reply to David Ahern
Quoted 8 lines · David Ahern

Some operators prefer IPv6 path selection to use a standard 5-tuple hash rather than just an L3 hash with the flow the label. To that end add support to IPv6 for multipath hash policy similar to bf4e0a3db97eb ("net: ipv4: add support for ECMP hash policy choice"). The default is still L3 which covers source and destination addresses along with flow label and IPv6 protocol.

[...]

Quoted 38 lines
net/ipv6/route.c +20 -10
@@ -1819,20 +1820,53 @@ static void ip6_multipath_l3_keys(const struct sk_buff *skb,
 }
 
 /* if skb is set it will be used and fl6 can be NULL */
-u32 rt6_multipath_hash(const struct flowi6 *fl6, const struct sk_buff *skb)
+u32 rt6_multipath_hash(const struct net *net, const struct flowi6 *fl6,
+		       const struct sk_buff *skb)
 {
 	struct flow_keys hash_keys;
 	u32 mhash;
 
-	memset(&hash_keys, 0, sizeof(hash_keys));
-	hash_keys.control.addr_type = FLOW_DISSECTOR_KEY_IPV6_ADDRS;
-	if (skb) {
-		ip6_multipath_l3_keys(skb, &hash_keys);
-	} else {
-		hash_keys.addrs.v6addrs.src = fl6->saddr;
-		hash_keys.addrs.v6addrs.dst = fl6->daddr;
-		hash_keys.tags.flow_label = (__force u32)fl6->flowlabel;
-		hash_keys.basic.ip_proto = fl6->flowi6_proto;
+	switch (net->ipv6.sysctl.multipath_hash_policy) {
+	case 0:
+		memset(&hash_keys, 0, sizeof(hash_keys));
+		hash_keys.control.addr_type = FLOW_DISSECTOR_KEY_IPV6_ADDRS;
+		if (skb) {
+			ip6_multipath_l3_keys(skb, &hash_keys);
+		} else {
+			hash_keys.addrs.v6addrs.src = fl6->saddr;
+			hash_keys.addrs.v6addrs.dst = fl6->daddr;
+			hash_keys.tags.flow_label = (__force u32)fl6->flowlabel;
+			hash_keys.basic.ip_proto = fl6->flowi6_proto;
+		}
+		break;
+	case 1:
+		if (skb) {
+			unsigned int flag = FLOW_DISSECTOR_F_STOP_AT_ENCAP;
+			struct flow_keys keys;
+

net/ipv6/route.c static void ip6_multipath_l3_keys(const struct sk_buff *skb, · line 1856

Quoted 10 lines
net/ipv6/route.c +10 -0
+			/* short-circuit if we already have L4 hash present */
+			if (skb->l4_hash)
+				return skb_get_hash_raw(skb) >> 1;
+
+			memset(&hash_keys, 0, sizeof(hash_keys));
+
+			skb_flow_dissect_flow_keys(skb, &keys, flag);
+
+			hash_keys.addrs.v6addrs.src = keys.addrs.v6addrs.src;
+			hash_keys.addrs.v6addrs.dst = keys.addrs.v6addrs.dst;

Shouldn't you add:

hash_keys.control.addr_type = FLOW_DISSECTOR_KEY_IPV6_ADDRS;

?

Otherwise flow_hash_from_keys() will not consistentify the ports and the addresses and it will also not use the addresses for the hash computation.

It's missing from fib_multipath_hash() as well, so I might be missing something.

net/ipv6/route.c static void ip6_multipath_l3_keys(const struct sk_buff *skb, · line 1859

Quoted 3 lines
net/ipv6/route.c +3 -0
+			hash_keys.ports.src = keys.ports.src;
+			hash_keys.ports.dst = keys.ports.dst;
+			hash_keys.tags.flow_label = keys.tags.flow_label;

Why are you using the flow label?

Quoted 22 lines
net/ipv6/route.c +11 -1
+			hash_keys.basic.ip_proto = keys.basic.ip_proto;
+		} else {
+			memset(&hash_keys, 0, sizeof(hash_keys));
+			hash_keys.control.addr_type = FLOW_DISSECTOR_KEY_IPV6_ADDRS;
+			hash_keys.addrs.v6addrs.src = fl6->saddr;
+			hash_keys.addrs.v6addrs.dst = fl6->daddr;
+			hash_keys.ports.src = fl6->fl6_sport;
+			hash_keys.ports.dst = fl6->fl6_dport;
+			hash_keys.basic.ip_proto = fl6->flowi6_proto;
+		}
 	}
 	mhash = flow_hash_from_keys(&hash_keys);
 
@@ -1858,7 +1892,7 @@ void ip6_route_input(struct sk_buff *skb)
 	if (tun_info && !(tun_info->mode & IP_TUNNEL_INFO_TX))
 		fl6.flowi6_tun_key.tun_id = tun_info->key.tun_id;
 	if (unlikely(fl6.flowi6_proto == IPPROTO_ICMPV6))
-		fl6.mp_hash = rt6_multipath_hash(&fl6, skb);
+		fl6.mp_hash = rt6_multipath_hash(net, &fl6, skb);
 	skb_dst_drop(skb);
 	skb_dst_set(skb, ip6_route_input_lookup(net, skb->dev, &fl6, flags));
 }
#12 lore raw
Quoted 48 lines · Ido Schimmel
Quoted 33 lines
net/ipv6/route.c +20 -9
+u32 rt6_multipath_hash(const struct net *net, const struct flowi6 *fl6,
+		       const struct sk_buff *skb)
 {
 	struct flow_keys hash_keys;
 	u32 mhash;
 
-	memset(&hash_keys, 0, sizeof(hash_keys));
-	hash_keys.control.addr_type = FLOW_DISSECTOR_KEY_IPV6_ADDRS;
-	if (skb) {
-		ip6_multipath_l3_keys(skb, &hash_keys);
-	} else {
-		hash_keys.addrs.v6addrs.src = fl6->saddr;
-		hash_keys.addrs.v6addrs.dst = fl6->daddr;
-		hash_keys.tags.flow_label = (__force u32)fl6->flowlabel;
-		hash_keys.basic.ip_proto = fl6->flowi6_proto;
+	switch (net->ipv6.sysctl.multipath_hash_policy) {
+	case 0:
+		memset(&hash_keys, 0, sizeof(hash_keys));
+		hash_keys.control.addr_type = FLOW_DISSECTOR_KEY_IPV6_ADDRS;
+		if (skb) {
+			ip6_multipath_l3_keys(skb, &hash_keys);
+		} else {
+			hash_keys.addrs.v6addrs.src = fl6->saddr;
+			hash_keys.addrs.v6addrs.dst = fl6->daddr;
+			hash_keys.tags.flow_label = (__force u32)fl6->flowlabel;
+			hash_keys.basic.ip_proto = fl6->flowi6_proto;
+		}
+		break;
+	case 1:
+		if (skb) {
+			unsigned int flag = FLOW_DISSECTOR_F_STOP_AT_ENCAP;
+			struct flow_keys keys;
+

net/ipv6/route.c static void ip6_multipath_l3_keys(const struct sk_buff *skb, · line 1856

Quoted 10 lines
net/ipv6/route.c +10 -0
+			/* short-circuit if we already have L4 hash present */
+			if (skb->l4_hash)
+				return skb_get_hash_raw(skb) >> 1;
+
+			memset(&hash_keys, 0, sizeof(hash_keys));
+
+			skb_flow_dissect_flow_keys(skb, &keys, flag);
+
+			hash_keys.addrs.v6addrs.src = keys.addrs.v6addrs.src;
+			hash_keys.addrs.v6addrs.dst = keys.addrs.v6addrs.dst;

Shouldn't you add:

hash_keys.control.addr_type = FLOW_DISSECTOR_KEY_IPV6_ADDRS;

Quoted 8 lines

?

Otherwise flow_hash_from_keys() will not consistentify the ports and the addresses and it will also not use the addresses for the hash computation.

It's missing from fib_multipath_hash() as well, so I might be missing something.

Yes, I think you are correct. The oversight here is based on the missing set in the ipv4 variant.

Quoted 6 lines

net/ipv6/route.c static void ip6_multipath_l3_keys(const struct sk_buff *skb, · line 1859

Quoted 4 lines
net/ipv6/route.c +3 -0
+			hash_keys.ports.src = keys.ports.src;
+			hash_keys.ports.dst = keys.ports.dst;
+			hash_keys.tags.flow_label = keys.tags.flow_label;

Why are you using the flow label?

will remove. It is supposed to be an L4 hash.