net/ipv6: Add support for path selection using hash of 5-tuple
Subsystems (5)
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. This gives users a choice in hash algorithms if they believe L3 only and the IPv6 flow label are not sufficient for their use case.
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.
RFC to v1:
- rebase to top of net-next
- fix addr_type in hash_keys and removed flow label as noticed by Ido
- added a comment to cover letter about choice in algorithms based on use case per Or's comments
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
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
@@ -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
@@ -1770,7 +1770,7 @@ void fib_select_path(struct net *net, struct fib_result *res,#ifdef CONFIG_IP_ROUTE_MULTIPATH if (res->fi->fib_nhs >1 ) { -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
@@ -1782,10 +1782,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;
@@ -1840,7 +1839,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
PATCH 2/7 net: Align ip_multipath_l3_keys and ip6_multipath_l3_keys
In reply to David AhernSymmetry 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
@@ -1748,37 +1748,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
@@ -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
PATCH 3/7 net/ipv6: Make rt6_multipath_hash similar to fib_multipath_hash
In reply to David AhernMake 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
@@ -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
PATCH 4/7 net: Rename NETEVENT_MULTIPATH_HASH_UPDATE
In reply to David AhernRename 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
@@ -2427,7 +2427,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
@@ -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
@@ -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
PATCH 5/7 net/ipv6: Add support for path selection using hash of 5-tuple
In reply to David AhernSome 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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
Hi David,
Quoted 102 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.Signed-off-by David Ahern <[email protected]>--- 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@@ -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 replyinclude/net/ip6_route.h +2
-1@@ -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@@ -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@@ -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@@ -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 +2
-1@@ -450,7 +450,8 @@ static bool rt6_check_expired(const struct rt6_info *rt)return false; } -static struct rt6_info *rt6_multipath_select (struct rt6_info *match, +static struct rt6_info *rt6_multipath_select (const struct net *net, +struct rt6_info *match,struct flowi6 *fl6,int oif,int strict) {
net/ipv6/route.c static struct rt6_info *rt6_multipath_select(struct rt6_info *match, · line 464
Quoted 5 lines
net/ipv6/route.c +1
-1@@ -460,7 +461,7 @@ static struct rt6_info *rt6_multipath_select(struct rt6_info *match,* case it will always be non-zero. Otherwise now is the time to do it. */ if (!fl6->mp_hash) - fl6->mp_hash =rt6_multipath_hash (fl6,NULL ); + fl6->mp_hash =rt6_multipath_hash (net, fl6,NULL );
My test is failing and all the packets hit the same nexthop despite the fact I'm using random UDP ports. This is because only the flow info is passed here and it doesn't include the ports.
The equivalent IPv4 code passes the skb and I believe this is what we need to do here as well.
Quoted 149 lines
net/ipv6/route.c +46
-13if (fl6->mp_hash <=atomic_read (&match->rt6i_nh_upper_bound))return match;@@ -929,7 +930,7 @@ static struct rt6_info *ip6_pol_route_lookup(struct net *net, rt =rt6_device_match (net, rt, &fl6->saddr, fl6->flowi6_oif, flags);if (rt->rt6i_nsiblings && fl6->flowi6_oif ==0 ) - rt =rt6_multipath_select (rt, fl6, + rt =rt6_multipath_select (net, rt, fl6, fl6->flowi6_oif, flags); }if (rt == net->ipv6.ip6_null_entry) {@@ -1669,7 +1670,7 @@ struct rt6_info *ip6_pol_route(struct net *net, struct fib6_table *table, redo_rt6_select: rt =rt6_select (net, fn, oif, strict);if (rt->rt6i_nsiblings) - rt =rt6_multipath_select (rt, fl6, oif, strict); + rt =rt6_multipath_select (net, rt, fl6, oif, strict);if (rt == net->ipv6.ip6_null_entry) { fn =fib6_backtrack (fn, &fl6->saddr);if (fn)@@ -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; + +/* 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.control.addr_type =FLOW_DISSECTOR_KEY_IPV6_ADDRS ; + hash_keys.addrs.v6addrs.src = keys.addrs.v6addrs.src; + hash_keys.addrs.v6addrs.dst = keys.addrs.v6addrs.dst; + hash_keys.ports.src = keys.ports.src; + hash_keys.ports.dst = keys.ports.dst; + 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)); }net/ipv6/sysctl_net_ipv6.c +26
-0@@ -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
PATCH 6/7 mlxsw: spectrum_router: Add support for ipv6 hash policy update
In reply to David AhernSimilar 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
@@ -2428,6 +2428,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))
@@ -7023,13 +7024,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
Re: [PATCH net-next 6/7] mlxsw: spectrum_router: Add support for ipv6 hash policy update
Quoted 5 lines · 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.Signed-off-by David Ahern <[email protected]>
Will review the rest and test tomorrow morning first thing.
Thanks a lot!
Re: [PATCH net-next 6/7] mlxsw: spectrum_router: Add support for ipv6 hash policy update
In reply to David AhernQuoted 5 lines · 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.Signed-off-by David Ahern <[email protected]>
kbuild test robot
build botRe: [PATCH net-next 6/7] mlxsw: spectrum_router: Add support for ipv6 hash policy update
In reply to David AhernI love your patch! Yet something to improve:
Hi David,
I love your patch! Yet something to improve:
[auto build test ERROR on net-next/master]
url: https://github.com/0day-ci/linux/commits/David-Ahern/net-ipv6-Add-support-for-path-selection-using-hash-of-5-tuple/20180222-222437
config: x86_64-randconfig-u0-02240002 (attached as .config)
compiler: gcc-5 (Debian 5.5.0-3) 5.4.1 20171010 reproduce:
# save the attached .config to linux build tree
make ARCH=x86_64 All errors (new ones prefixed by >>):
drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c: In function 'mlxsw_sp_mp6_hash_init':
>> drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c:7027:26: error: 'struct net' has no member named 'ipv6'
bool only_l3 = !init_net.ipv6.sysctl.multipath_hash_policy;
^vim +7027 drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c
7024
7025 static void mlxsw_sp_mp6_hash_init(char *recr2_pl)
7026 {
> 7027 bool only_l3 = !init_net.ipv6.sysctl.multipath_hash_policy;
7028
7029 mlxsw_sp_mp_hash_header_set(recr2_pl,
7030 MLXSW_REG_RECR2_IPV6_EN_NOT_TCP_NOT_UDP);
7031 mlxsw_sp_mp_hash_header_set(recr2_pl, MLXSW_REG_RECR2_IPV6_EN_TCP_UDP);
7032 mlxsw_reg_recr2_ipv6_sip_enable(recr2_pl);
7033 mlxsw_reg_recr2_ipv6_dip_enable(recr2_pl);
7034 mlxsw_sp_mp_hash_field_set(recr2_pl, MLXSW_REG_RECR2_IPV6_NEXT_HEADER);
7035 if (only_l3) {
7036 mlxsw_sp_mp_hash_field_set(recr2_pl, MLXSW_REG_RECR2_IPV6_FLOW_LABEL);
7037 } else {
7038 mlxsw_sp_mp_hash_header_set(recr2_pl, MLXSW_REG_RECR2_TCP_UDP_EN_IPV6);
7039 mlxsw_sp_mp_hash_field_set(recr2_pl, MLXSW_REG_RECR2_TCP_UDP_SPORT);
7040 mlxsw_sp_mp_hash_field_set(recr2_pl, MLXSW_REG_RECR2_TCP_UDP_DPORT);
7041 }
7042 }
7043
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
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
@@ -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
@@ -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
David Miller
maintainerFrom: David Ahern <[email protected]>
Date: Wed, 21 Feb 2018 10:49:47 -0800
Quoted 1 line
Patch 5 adds the L4 hash support.
Please address Ido's feedback about how the ports aren't actually being taken into consideration because they aren't present in the flow information being used.
Thanks.
Quoted 8 lines · David Miller
From: David Ahern <[email protected]>
Date: Wed, 21 Feb 2018 10:49:47 -0800Quoted 1 line
Patch 5 adds the L4 hash support.
Please address Ido's feedback about how the ports aren't actually being taken into consideration because they aren't present in the flow information being used.
It's the forwarding case; I need to add the skb to the route lookup functions. I'll send a v2 with that change in the next few days.
David Miller
maintainerFrom: David Ahern <[email protected]>
Date: Thu, 22 Feb 2018 12:31:01 -0700
Quoted 12 lines · David Miller
Quoted 8 lines
From: David Ahern <[email protected]>
Date: Wed, 21 Feb 2018 10:49:47 -0800Quoted 1 line
Patch 5 adds the L4 hash support.
Please address Ido's feedback about how the ports aren't actually being taken into consideration because they aren't present in the flow information being used.
It's the forwarding case; I need to add the skb to the route lookup functions. I'll send a v2 with that change in the next few days.
Ok, thank you.