]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
net: ipv4,ipv6: Pass multipath hash computation through a helper
authorPetr Machata <petrm@nvidia.com>
Fri, 7 Jun 2024 15:13:53 +0000 (17:13 +0200)
committerJakub Kicinski <kuba@kernel.org>
Wed, 12 Jun 2024 23:42:11 +0000 (16:42 -0700)
The following patches will add a sysctl to control multipath hash
seed. In order to centralize the hash computation, add a helper,
fib_multipath_hash_from_keys(), and have all IPv4 and IPv6 route.c
invocations of flow_hash_from_keys() go through this helper instead.

Signed-off-by: Petr Machata <petrm@nvidia.com>
Reviewed-by: Ido Schimmel <idosch@nvidia.com>
Reviewed-by: Nikolay Aleksandrov <razor@blackwall.org>
Reviewed-by: David Ahern <dsahern@kernel.org>
Link: https://lore.kernel.org/r/20240607151357.421181-2-petrm@nvidia.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
include/net/ip_fib.h
net/ipv4/route.c
net/ipv6/route.c

index 9b2f69ba5e4981fb108581c229ff008d04750ade..b8b3c07e8f7bd507544822ffc9ea80651405840e 100644 (file)
@@ -521,6 +521,13 @@ void fib_nhc_update_mtu(struct fib_nh_common *nhc, u32 new, u32 orig);
 int fib_multipath_hash(const struct net *net, const struct flowi4 *fl4,
                       const struct sk_buff *skb, struct flow_keys *flkeys);
 #endif
+
+static inline u32 fib_multipath_hash_from_keys(const struct net *net,
+                                              struct flow_keys *keys)
+{
+       return flow_hash_from_keys(keys);
+}
+
 int fib_check_nh(struct net *net, struct fib_nh *nh, u32 table, u8 scope,
                 struct netlink_ext_ack *extack);
 void fib_select_multipath(struct fib_result *res, int hash);
index cb0bdf34ed50c92688a3c0fe14c3e0c06d78b47c..54512acbead734d1b720070bcfe2ebf4859f5c5e 100644 (file)
@@ -1923,7 +1923,7 @@ static u32 fib_multipath_custom_hash_outer(const struct net *net,
                hash_keys.ports.dst = keys.ports.dst;
 
        *p_has_inner = !!(keys.control.flags & FLOW_DIS_ENCAPSULATION);
-       return flow_hash_from_keys(&hash_keys);
+       return fib_multipath_hash_from_keys(net, &hash_keys);
 }
 
 static u32 fib_multipath_custom_hash_inner(const struct net *net,
@@ -1972,7 +1972,7 @@ static u32 fib_multipath_custom_hash_inner(const struct net *net,
        if (hash_fields & FIB_MULTIPATH_HASH_FIELD_INNER_DST_PORT)
                hash_keys.ports.dst = keys.ports.dst;
 
-       return flow_hash_from_keys(&hash_keys);
+       return fib_multipath_hash_from_keys(net, &hash_keys);
 }
 
 static u32 fib_multipath_custom_hash_skb(const struct net *net,
@@ -2009,7 +2009,7 @@ static u32 fib_multipath_custom_hash_fl4(const struct net *net,
        if (hash_fields & FIB_MULTIPATH_HASH_FIELD_DST_PORT)
                hash_keys.ports.dst = fl4->fl4_dport;
 
-       return flow_hash_from_keys(&hash_keys);
+       return fib_multipath_hash_from_keys(net, &hash_keys);
 }
 
 /* if skb is set it will be used and fl4 can be NULL */
@@ -2030,7 +2030,7 @@ int fib_multipath_hash(const struct net *net, const struct flowi4 *fl4,
                        hash_keys.addrs.v4addrs.src = fl4->saddr;
                        hash_keys.addrs.v4addrs.dst = fl4->daddr;
                }
-               mhash = flow_hash_from_keys(&hash_keys);
+               mhash = fib_multipath_hash_from_keys(net, &hash_keys);
                break;
        case 1:
                /* skb is currently provided only when forwarding */
@@ -2064,7 +2064,7 @@ int fib_multipath_hash(const struct net *net, const struct flowi4 *fl4,
                        hash_keys.ports.dst = fl4->fl4_dport;
                        hash_keys.basic.ip_proto = fl4->flowi4_proto;
                }
-               mhash = flow_hash_from_keys(&hash_keys);
+               mhash = fib_multipath_hash_from_keys(net, &hash_keys);
                break;
        case 2:
                memset(&hash_keys, 0, sizeof(hash_keys));
@@ -2095,7 +2095,7 @@ int fib_multipath_hash(const struct net *net, const struct flowi4 *fl4,
                        hash_keys.addrs.v4addrs.src = fl4->saddr;
                        hash_keys.addrs.v4addrs.dst = fl4->daddr;
                }
-               mhash = flow_hash_from_keys(&hash_keys);
+               mhash = fib_multipath_hash_from_keys(net, &hash_keys);
                break;
        case 3:
                if (skb)
index ad5fff5a210c0d345a44a112f6d9f69ed3058716..1916de61539818845f9fa6f9072da7db03914a10 100644 (file)
@@ -2372,7 +2372,7 @@ static u32 rt6_multipath_custom_hash_outer(const struct net *net,
                hash_keys.ports.dst = keys.ports.dst;
 
        *p_has_inner = !!(keys.control.flags & FLOW_DIS_ENCAPSULATION);
-       return flow_hash_from_keys(&hash_keys);
+       return fib_multipath_hash_from_keys(net, &hash_keys);
 }
 
 static u32 rt6_multipath_custom_hash_inner(const struct net *net,
@@ -2421,7 +2421,7 @@ static u32 rt6_multipath_custom_hash_inner(const struct net *net,
        if (hash_fields & FIB_MULTIPATH_HASH_FIELD_INNER_DST_PORT)
                hash_keys.ports.dst = keys.ports.dst;
 
-       return flow_hash_from_keys(&hash_keys);
+       return fib_multipath_hash_from_keys(net, &hash_keys);
 }
 
 static u32 rt6_multipath_custom_hash_skb(const struct net *net,
@@ -2460,7 +2460,7 @@ static u32 rt6_multipath_custom_hash_fl6(const struct net *net,
        if (hash_fields & FIB_MULTIPATH_HASH_FIELD_DST_PORT)
                hash_keys.ports.dst = fl6->fl6_dport;
 
-       return flow_hash_from_keys(&hash_keys);
+       return fib_multipath_hash_from_keys(net, &hash_keys);
 }
 
 /* if skb is set it will be used and fl6 can be NULL */
@@ -2482,7 +2482,7 @@ u32 rt6_multipath_hash(const struct net *net, const struct flowi6 *fl6,
                        hash_keys.tags.flow_label = (__force u32)flowi6_get_flowlabel(fl6);
                        hash_keys.basic.ip_proto = fl6->flowi6_proto;
                }
-               mhash = flow_hash_from_keys(&hash_keys);
+               mhash = fib_multipath_hash_from_keys(net, &hash_keys);
                break;
        case 1:
                if (skb) {
@@ -2514,7 +2514,7 @@ u32 rt6_multipath_hash(const struct net *net, const struct flowi6 *fl6,
                        hash_keys.ports.dst = fl6->fl6_dport;
                        hash_keys.basic.ip_proto = fl6->flowi6_proto;
                }
-               mhash = flow_hash_from_keys(&hash_keys);
+               mhash = fib_multipath_hash_from_keys(net, &hash_keys);
                break;
        case 2:
                memset(&hash_keys, 0, sizeof(hash_keys));
@@ -2551,7 +2551,7 @@ u32 rt6_multipath_hash(const struct net *net, const struct flowi6 *fl6,
                        hash_keys.tags.flow_label = (__force u32)flowi6_get_flowlabel(fl6);
                        hash_keys.basic.ip_proto = fl6->flowi6_proto;
                }
-               mhash = flow_hash_from_keys(&hash_keys);
+               mhash = fib_multipath_hash_from_keys(net, &hash_keys);
                break;
        case 3:
                if (skb)