ipv4: Support multipath hashing on inner IP pkts for GRE tunnel
Subsystems (4)
PATCH 1/1 ipv4: Support multipath hashing on inner IP pkts for GRE tunnel
Multipath hash policy value of 0 isn't distributing since the outer IP dest and src aren't varied eventhough the inner ones are. Since the flow is on the inner ones in the case of tunneled traffic, hashing on them is desired.
This currently only supports IP over GRE and CONFIG_NET_GRE_DEMUX must be compiled as built-in in the kernel.
--- Documentation/networking/ip-sysctl.txt | 4 ++ net/ipv4/route.c | 75 ++++++++++++++++++++++---- net/ipv4/sysctl_net_ipv4.c | 2 +- 3 files changed, 70 insertions(+), 11 deletions(-)
Documentation/networking/ip-sysctl.txt +4 -0
@@ -80,6 +80,10 @@ fib_multipath_hash_policy - INTEGER Possible values: 0 - Layer 3 1 - Layer 4 + 2 - Inner Layer 3 for tunneled IP packets. Only IP tunneled by GRE is + supported now. Others are treated as if the control is set to 0, + i.e. the outer L3 is used. GRE support is only valid when the kernel + was compiled with CONFIG_NET_GRE_DEMUX. fib_sync_mem - UNSIGNED INTEGER Amount of dirty memory from fib entries that can be backlogged before
net/ipv4/route.c +65 -10
133 lines not on this page · raw message
net/ipv4/sysctl_net_ipv4.c +1 -1
@@ -960,7 +960,7 @@ static struct ctl_table ipv4_net_table[] = { .mode = 0644, .proc_handler = proc_fib_multipath_hash_policy, .extra1 = &zero, - .extra2 = &one, + .extra2 = &two, },#endif {
Signature · 1 line
2.17.1
Quoted 15 lines · Stephen Suryaputra
Multipath hash policy value of 0 isn't distributing since the outer IP dest and src aren't varied eventhough the inner ones are. Since the flow is on the inner ones in the case of tunneled traffic, hashing on them is desired.
This currently only supports IP over GRE and
CONFIG_NET_GRE_DEMUXmust be compiled as built-in in the kernel.Signed-off-by Stephen Suryaputra <[email protected]>--- Documentation/networking/ip-sysctl.txt | 4 ++ net/ipv4/route.c | 75 ++++++++++++++++++++++---- net/ipv4/sysctl_net_ipv4.c | 2 +- 3 files changed, 70 insertions(+), 11 deletions(-)
[snip]
Quoted 14 lines
net/ipv4/route.c +10
-0@@ -1820,6 +1827,47 @@ static void ip_multipath_l3_keys(const struct sk_buff *skb, hash_keys->addrs.v4addrs.dst = key_iph->daddr; } +static void ip_multipath_inner_l3_keys (const struct sk_buff *skb, +struct flow_keys *hash_keys) +{ +const struct iphdr *outer_iph =ip_hdr (skb); +const struct iphdr *inner_iph; +struct iphdr _inner_iph; +int hdr_len; + +switch (outer_iph->protocol) { +#ifdef CONFIG_NET_GRE_DEMUX
net/ipv4/route.c static void ip_multipath_l3_keys(const struct sk_buff *skb, · line 1849
Quoted 10 lines
net/ipv4/route.c +10
-0+case IPPROTO_GRE : + { +struct tnl_ptk_info tpi; +bool csum_err = false; + + hdr_len =gre_parse_header (skb, &tpi, &csum_err, +htons (ETH_P_IP ), + outer_iph->ihl *4 ); +if (hdr_len >0 && tpi.proto ==htons (ETH_P_IP )) +break ;
Have you considered using the flow dissector and doing something similar to the bonding ? It does a full flow dissect via skb_flow_dissect_flow_keys() and uses whatever headers it needs, but that will support any tunneling protocol which the flow dissector recognizes and will be improved upon automatically by people adding to it. Also would avoid doing dissection by yourself.
The bond commit which added that was:
32819dc18348 ("bonding: modify the old and add new xmit hash policies")
Quoted 25 lines
net/ipv4/route.c +21
-0+ } +/* fallthrough */ +#endif +default : +/* Hash on outer for unknown tunnels, non IP tunneled, or non- +* tunneled pkts +*/ +ip_multipath_l3_keys (skb, hash_keys, outer_iph,0 ); +return ; + } + inner_iph =skb_header_pointer (skb, + outer_iph->ihl *4 + hdr_len, +sizeof (struct iphdr ), &_inner_iph); +if (inner_iph) { +ip_multipath_l3_keys (skb, hash_keys, inner_iph, hdr_len); + }else { +/* Use outer */ +ip_multipath_l3_keys (skb, hash_keys, outer_iph,0 ); + } +} +/* if skb is set it will be used and fl4 can be NULL */ int fib_multipath_hash (const struct net *net,const struct flowi4 *fl4,const struct sk_buff *skb,struct flow_keys *flkeys)
net/ipv4/route.c int fib_multipath_hash(const struct net *net, const struct flowi4 *fl4, · line 1880
Quoted 5 lines
net/ipv4/route.c +2
-0@@ -1828,12 +1876,13 @@ int fib_multipath_hash(const struct net *net, const struct flowi4 *fl4,struct flow_keys hash_keys;u32 mhash; +memset (&hash_keys,0 ,sizeof (hash_keys)); +
This was an optimization, it was done on purpose to avoid doing anything when we have L3+4 configured (1) and the skb has its hash already calculated.
Quoted 57 lines
net/ipv4/route.c +10
-5switch (net->ipv4.sysctl_fib_multipath_hash_policy) {case 0 : -memset (&hash_keys,0 ,sizeof (hash_keys)); hash_keys.control.addr_type =FLOW_DISSECTOR_KEY_IPV4_ADDRS ;if (skb) { -ip_multipath_l3_keys (skb, &hash_keys); +ip_multipath_l3_keys (skb, &hash_keys,NULL ,0 ); }else { hash_keys.addrs.v4addrs.src = fl4->saddr; hash_keys.addrs.v4addrs.dst = fl4->daddr;@@ -1849,8 +1898,6 @@ int fib_multipath_hash(const struct net *net, const struct flowi4 *fl4,if (skb->l4_hash)return skb_get_hash_raw (skb) >>1 ; -memset (&hash_keys,0 ,sizeof (hash_keys)); -if (!flkeys) {skb_flow_dissect_flow_keys (skb, &keys, flag); flkeys = &keys;@@ -1863,7 +1910,6 @@ int fib_multipath_hash(const struct net *net, const struct flowi4 *fl4, hash_keys.ports.dst = flkeys->ports.dst; hash_keys.basic.ip_proto = flkeys->basic.ip_proto; }else { -memset (&hash_keys,0 ,sizeof (hash_keys)); hash_keys.control.addr_type =FLOW_DISSECTOR_KEY_IPV4_ADDRS ; hash_keys.addrs.v4addrs.src = fl4->saddr; hash_keys.addrs.v4addrs.dst = fl4->daddr;@@ -1872,6 +1918,15 @@ int fib_multipath_hash(const struct net *net, const struct flowi4 *fl4, hash_keys.basic.ip_proto = fl4->flowi4_proto; }break ; +case 2 : + hash_keys.control.addr_type =FLOW_DISSECTOR_KEY_IPV4_ADDRS ; +if (skb) { +ip_multipath_inner_l3_keys (skb, &hash_keys); + }else { + hash_keys.addrs.v4addrs.src = fl4->saddr; + hash_keys.addrs.v4addrs.dst = fl4->daddr; + } +break ; } mhash =flow_hash_from_keys (&hash_keys);net/ipv4/sysctl_net_ipv4.c +1
-1@@ -960,7 +960,7 @@ static struct ctl_table ipv4_net_table[] = { .mode = 0644, .proc_handler = proc_fib_multipath_hash_policy, .extra1 = &zero, - .extra2 = &one, + .extra2 = &two, },#endif {
Quoted 10 lines · Nikolay Aleksandrov
Have you considered using the flow dissector and doing something similar to the bonding ? It does a full flow dissect via
skb_flow_dissect_flow_keys()and uses whatever headers it needs, but that will support any tunneling protocol which the flow dissector recognizes and will be improved upon automatically by people adding to it. Also would avoid doing dissection by yourself.The bond commit which added that was:
32819dc18348("bonding: modify the old and add new xmit hash policies")
I didn't consider it and should. Thanks for pointing me to that direction. It's simpler.
Quoted 7 lines
Quoted 7 lines
/* if skb is set it will be used and fl4 can be NULL */
int fib_multipath_hash(const struct net *net, const struct flowi4 *fl4,net/ipv4/route.c +0
-0const struct sk_buff *skb, struct flow_keys *flkeys)@@ -1828,12 +1876,13 @@ int fib_multipath_hash(const struct net *net, const struct flowi4 *fl4,struct flow_keys hash_keys;u32 mhash;
Quoted 6 lines
net/ipv4/route.c int fib_multipath_hash(const struct net *net, const struct flowi4 *fl4, · line 1880
Quoted 2 lines
net/ipv4/route.c +2
-0+memset (&hash_keys,0 ,sizeof (hash_keys)); +This was an optimization, it was done on purpose to avoid doing anything when we have L3+4 configured (1) and the skb has its hash already calculated.
Will revert to the original lines.
Thanks.