net/ipv4: multipath routing: configurable seed
Subsystems (4)
PATCH v5 1/3 net/ipv4: multipath routing: configurable seed
Ability for a user to assign seed value to multipath route hashes. Now kernel uses random seed value to prevent hash-flooding DoS attacks; however, it disables some use cases, f.e:
+-------+ +------+ +--------+ | |-eth0---| FW0 |---eth0-| | | | +------+ | | | GW0 |ECMP ECMP| GW1 | | | +------+ | | | |-eth1---| FW1 |---eth1-| | +-------+ +------+ +--------+
In this use case, two ECMP routers balance traffic between two firewalls. If some flow transmits a response over a different channel than request, such flow will be dropped, because keep-state rules are created on the other firewall.
This patch adds sysctl variable: net.ipv4.fib_multipath_hash_seed. User can set the same seed value on GW0 and GW1 for traffic to be mirror-balanced. By default, random value is used.
Signed-off-by Balaev Pavel <[email protected]>
--- Documentation/networking/ip-sysctl.rst | 14 ++++ include/net/flow_dissector.h | 2 + include/net/netns/ipv4.h | 2 + net/core/flow_dissector.c | 7 ++ net/ipv4/route.c | 10 ++- net/ipv4/sysctl_net_ipv4.c | 97 ++++++++++++++++++++++++++ 6 files changed, 131 insertions(+), 1 deletion(-)
Documentation/networking/ip-sysctl.rst +14 -0
@@ -100,6 +100,20 @@ fib_multipath_hash_policy - INTEGER - 1 - Layer 4 - 2 - Layer 3 or inner Layer 3 if present +fib_multipath_hash_seed - STRING + Controls seed value for multipath route hashes. By default + random value is used. Only valid for kernels built with + CONFIG_IP_ROUTE_MULTIPATH enabled. + + Valid format: two hex values set off with comma or "random" + keyword. + + Example to generate the seed value:: + + RAND=$(openssl rand -hex 16) && echo "${RAND:0:16},${RAND:16:16}" + + Default: "random" + fib_sync_mem - UNSIGNED INTEGER Amount of dirty memory from fib entries that can be backlogged before synchronize_rcu is forced.
include/net/flow_dissector.h +2 -0
@@ -348,6 +348,8 @@ static inline bool flow_keys_have_l4(const struct flow_keys *keys) }u32 flow_hash_from_keys (struct flow_keys *keys); +u32 flow_multipath_hash_from_keys (struct flow_keys *keys, +const siphash_key_t *seed);void skb_flow_get_icmp_tci (const struct sk_buff *skb,struct flow_dissector_key_icmp *key_icmp,const void *data,int thoff,int hlen);
include/net/netns/ipv4.h +2 -0
@@ -222,6 +222,8 @@ struct netns_ipv4 {#ifdef CONFIG_IP_ROUTE_MULTIPATH u8 sysctl_fib_multipath_use_neigh;u8 sysctl_fib_multipath_hash_policy; +int sysctl_fib_multipath_hash_seed; +siphash_key_t __rcu *fib_multipath_hash_seed_ctx;#endif struct fib_notifier_ops *notifier_ops;
net/core/flow_dissector.c +7 -0
@@ -1560,6 +1560,13 @@ u32 flow_hash_from_keys(struct flow_keys *keys) }EXPORT_SYMBOL (flow_hash_from_keys); +u32 flow_multipath_hash_from_keys (struct flow_keys *keys, +const siphash_key_t *seed) +{ +return __flow_hash_from_keys (keys, seed); +} +EXPORT_SYMBOL (flow_multipath_hash_from_keys); +static inline u32 ___skb_get_hash (const struct sk_buff *skb,struct flow_keys *keys,const siphash_key_t *keyval)
net/ipv4/route.c +9 -1
@@ -1912,6 +1912,7 @@ int fib_multipath_hash(const struct net *net, const struct flowi4 *fl4, {u32 multipath_hash = fl4 ? fl4->flowi4_multipath_hash :0 ;struct flow_keys hash_keys; +siphash_key_t *seed_ctx;u32 mhash;switch (net->ipv4.sysctl_fib_multipath_hash_policy) {
@@ -1989,7 +1990,14 @@ int fib_multipath_hash(const struct net *net, const struct flowi4 *fl4, }break ; } - mhash =flow_hash_from_keys (&hash_keys); + +rcu_read_lock (); + seed_ctx =rcu_dereference (net->ipv4.fib_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 ();if (multipath_hash) mhash =jhash_2words (mhash, multipath_hash,0 );
net/ipv4/sysctl_net_ipv4.c +97 -0
115 lines not on this page · raw message
Signature · 1 line
2.31.1