ipv4: Hash-based multipath routing
Subsystems (3)
v5 cover ipv4: Hash-based multipath routing
When the routing cache was removed in 3.6, the IPv4 multipath algorithm changed from more or less being destination-based into being quasi-random per-packet scheduling. This increases the risk of out-of-order packets and makes it impossible to use multipath together with anycast services.
This patch series replaces the old implementation with flow-based load balancing based on a hash over the source and destination addresses.
Distribution of the hash is done with thresholds as described in RFC 2992. This reduces the disruption when a path is added/remove when having more than two paths.
To futher the chance of successful usage in conjuction with anycast, ICMP error packets are hashed over the inner IP addresses. This ensures that PMTU will work together with anycast or load-balancers such as IPVS.
Port numbers are not considered since fragments could cause problems with anycast and IPVS. Relying on the DF-flag for TCP packets is also insufficient, since ICMP inspection effectively extracts information from the opposite flow which might have a different state of the DF-flag. This is also why the RSS hash is not used. These are typically based on the NDIS RSS spec which mandates TCP support.
Measurements of the additional overhead of a two-path multipath (p_mkroute_input excl. __mkroute_input) on a Xeon X3550 (4 cores, 2.66GHz):
Original per-packet: ~394 cycles/packet
L3 hash: ~76 cycles/packet
Changes in v5:
- Fixed compilation error
Changes in v4:
- Functions take hash directly instead of func ptr
- Added inline hash function
- Added dummy macros to minimize ifdefs
- Use upper 31 bits of hash instead of lower
Changes in v3:
- Multipath algorithm is no longer configurable (always L3)
- Added random seed to hash
- Moved ICMP inspection to isolated function
- Ignore source quench packets (deprecated as per RFC 6633)
Changes in v2:
- Replaced 8-bit xor hash with 31-bit jenkins hash
- Don't scale weights (since 31-bit)
- Avoided unnecesary renaming of variables
- Rely on DF-bit instead of fragment offset when checking for fragmentation
- upper_bound is now inclusive to avoid overflow
- Use a callback to postpone extracting flow information until necessary
- Skipped ICMP inspection entirely with L4 hashing
- Handle newly added sysctl ignore_routes_with_linkdown
Best Regards
Peter Nørlund
Peter Nørlund (2):
ipv4: L3 hash-based multipath
ipv4: ICMP packet inspection for multipath
include/net/ip_fib.h | 14 ++++- include/net/route.h | 11 +++- net/ipv4/fib_semantics.c | 140 ++++++++++++++++++++++-------------------- net/ipv4/icmp.c | 19 +++++- net/ipv4/route.c | 65 ++++++++++++++++++-- 5 files changed, 173 insertions(+), 76 deletions(-)
PATCH v5 1/2 ipv4: L3 hash-based multipath
From: Peter Nørlund <[email protected]>
Replaces the per-packet multipath with a hash-based multipath using source and destination address.
--- include/net/ip_fib.h | 14 ++++- net/ipv4/fib_semantics.c | 140 +++++++++++++++++++++++++--------------------- net/ipv4/route.c | 16 ++++-- 3 files changed, 98 insertions(+), 72 deletions(-)
include/net/ip_fib.h +11 -3
@@ -79,7 +79,7 @@ struct fib_nh {unsigned char nh_scope;#ifdef CONFIG_IP_ROUTE_MULTIPATH int nh_weight; -int nh_power; +atomic_t nh_upper_bound;#endif #ifdef CONFIG_IP_ROUTE_CLASSID __u32 nh_tclassid;
@@ -118,7 +118,7 @@ struct fib_info {#define fib_advmss fib_metrics[RTAX_ADVMSS-1]int fib_nhs;#ifdef CONFIG_IP_ROUTE_MULTIPATH -int fib_power; +int fib_weight;#endif struct rcu_head rcu;struct fib_nh fib_nh[0 ];
@@ -320,7 +320,15 @@ int ip_fib_check_default(__be32 gw, struct net_device *dev);int fib_sync_down_dev (struct net_device *dev,unsigned long event);int fib_sync_down_addr (struct net *net,__be32 local);int fib_sync_up (struct net_device *dev,unsigned int nh_flags); -void fib_select_multipath (struct fib_result *res); + +extern u32 fib_multipath_secret__read_mostly ; + +static inline int fib_multipath_hash (__be32 saddr,__be32 daddr) +{ +return jhash_2words (saddr, daddr, fib_multipath_secret) >>1 ; +} + +void fib_select_multipath (struct fib_result *res,int hash);/* Exported by fib_trie.c */ void fib_trie_init (void );
net/ipv4/fib_semantics.c +75 -65
198 lines not on this page · raw message
net/ipv4/route.c +12 -4
@@ -1653,8 +1653,12 @@ static int ip_mkroute_input(struct sk_buff *skb, __be32 daddr, __be32 saddr, u32 tos) { #ifdef CONFIG_IP_ROUTE_MULTIPATH - if (res->fi && res->fi->fib_nhs > 1) - fib_select_multipath(res); + if (res->fi && res->fi->fib_nhs > 1) { + int h; + + h =fib_multipath_hash (saddr, daddr); +fib_select_multipath (res, h); + }#endif /* create a routing cache entry */
@@ -2202,8 +2206,12 @@ struct rtable *__ip_route_output_key(struct net *net, struct flowi4 *fl4) }#ifdef CONFIG_IP_ROUTE_MULTIPATH -if (res.fi->fib_nhs >1 && fl4->flowi4_oif ==0 ) -fib_select_multipath (&res); +if (res.fi->fib_nhs >1 && fl4->flowi4_oif ==0 ) { +int h; + + h =fib_multipath_hash (fl4->saddr, fl4->daddr); +fib_select_multipath (&res, h); + } else#endif if (!res.prefixlen &&
Signature · 1 line
1.7.10.4
PATCH v5 2/2 ipv4: ICMP packet inspection for multipath
In reply to Peter NørlundFrom: Peter Nørlund <[email protected]>
ICMP packets are inspected to let them route together with the flow they belong to, minimizing the chance that a problematic path will affect flows on other paths, and so that anycast environments can work with ECMP.
--- include/net/route.h | 11 +++++++++- net/ipv4/icmp.c | 19 ++++++++++++++++- net/ipv4/route.c | 59 +++++++++++++++++++++++++++++++++++++++++++++------ 3 files changed, 80 insertions(+), 9 deletions(-)
include/net/route.h +10 -1
@@ -28,6 +28,7 @@#include <net/inetpeer.h> #include <net/flow.h> #include <net/inet_sock.h> +#include <net/ip_fib.h> #include <linux/in_route.h> #include <linux/rtnetlink.h> #include <linux/rcupdate.h>
@@ -110,7 +111,15 @@ struct in_device;int ip_rt_init (void );void rt_cache_flush (struct net *net);void rt_flush_dev (struct net_device *dev); -struct rtable *__ip_route_output_key (struct net *,struct flowi4 *flp); +struct rtable *__ip_route_output_key_hash (struct net *,struct flowi4 *flp, +int mp_hash); + +static inline struct rtable *__ip_route_output_key (struct net *net, +struct flowi4 *flp) +{ +return __ip_route_output_key_hash (net, flp,-1 ); +} +struct rtable *ip_route_output_flow (struct net *,struct flowi4 *flp,struct sock *sk); struct dst_entry *ipv4_blackhole_route(struct net *net,
net/ipv4/icmp.c +18 -1
@@ -440,6 +440,22 @@ out_unlock:icmp_xmit_unlock (sk); } +#ifdef CONFIG_IP_ROUTE_MULTIPATH + +/* Source and destination is swapped. See ip_multipath_icmp_hash */ +static int icmp_multipath_hash_skb (const struct sk_buff *skb) +{ +const struct iphdr *iph =ip_hdr (skb); + +return fib_multipath_hash (iph->daddr, iph->saddr); +} + +#else + +#define icmp_multipath_hash_skb (skb) (-1) + +#endif + static struct rtable *icmp_route_lookup(struct net *net, struct flowi4 *fl4, struct sk_buff *skb_in,
@@ -464,7 +480,8 @@ static struct rtable *icmp_route_lookup(struct net *net, fl4->flowi4_oif =vrf_master_ifindex (skb_in->dev);security_skb_classify_flow (skb_in,flowi4_to_flowi (fl4)); - rt =__ip_route_output_key (net, fl4); + rt =__ip_route_output_key_hash (net, fl4, +icmp_multipath_hash_skb (skb_in));if (IS_ERR (rt))return rt;
net/ipv4/route.c +52 -7
89 lines not on this page · raw message
Signature · 1 line
1.7.10.4
David Miller
maintainerFrom: Peter Nørlund <[email protected]>
Date: Wed, 30 Sep 2015 10:12:20 +0200
Quoted 7 lines
When the routing cache was removed in 3.6, the IPv4 multipath algorithm changed from more or less being destination-based into being quasi-random per-packet scheduling. This increases the risk of out-of-order packets and makes it impossible to use multipath together with anycast services.
This patch series replaces the old implementation with flow-based load balancing based on a hash over the source and destination addresses.
...
Series applied, thank you.