Skip to content

Commit 3e453ca

Browse files
pmachatakuba-moo
authored andcommitted
net: ipv4,ipv6: Pass multipath hash computation through a helper
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>
1 parent 32b0660 commit 3e453ca

File tree

3 files changed

+19
-12
lines changed

3 files changed

+19
-12
lines changed

include/net/ip_fib.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,13 @@ void fib_nhc_update_mtu(struct fib_nh_common *nhc, u32 new, u32 orig);
521521
int fib_multipath_hash(const struct net *net, const struct flowi4 *fl4,
522522
const struct sk_buff *skb, struct flow_keys *flkeys);
523523
#endif
524+
525+
static inline u32 fib_multipath_hash_from_keys(const struct net *net,
526+
struct flow_keys *keys)
527+
{
528+
return flow_hash_from_keys(keys);
529+
}
530+
524531
int fib_check_nh(struct net *net, struct fib_nh *nh, u32 table, u8 scope,
525532
struct netlink_ext_ack *extack);
526533
void fib_select_multipath(struct fib_result *res, int hash);

net/ipv4/route.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1923,7 +1923,7 @@ static u32 fib_multipath_custom_hash_outer(const struct net *net,
19231923
hash_keys.ports.dst = keys.ports.dst;
19241924

19251925
*p_has_inner = !!(keys.control.flags & FLOW_DIS_ENCAPSULATION);
1926-
return flow_hash_from_keys(&hash_keys);
1926+
return fib_multipath_hash_from_keys(net, &hash_keys);
19271927
}
19281928

19291929
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,
19721972
if (hash_fields & FIB_MULTIPATH_HASH_FIELD_INNER_DST_PORT)
19731973
hash_keys.ports.dst = keys.ports.dst;
19741974

1975-
return flow_hash_from_keys(&hash_keys);
1975+
return fib_multipath_hash_from_keys(net, &hash_keys);
19761976
}
19771977

19781978
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,
20092009
if (hash_fields & FIB_MULTIPATH_HASH_FIELD_DST_PORT)
20102010
hash_keys.ports.dst = fl4->fl4_dport;
20112011

2012-
return flow_hash_from_keys(&hash_keys);
2012+
return fib_multipath_hash_from_keys(net, &hash_keys);
20132013
}
20142014

20152015
/* 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,
20302030
hash_keys.addrs.v4addrs.src = fl4->saddr;
20312031
hash_keys.addrs.v4addrs.dst = fl4->daddr;
20322032
}
2033-
mhash = flow_hash_from_keys(&hash_keys);
2033+
mhash = fib_multipath_hash_from_keys(net, &hash_keys);
20342034
break;
20352035
case 1:
20362036
/* skb is currently provided only when forwarding */
@@ -2064,7 +2064,7 @@ int fib_multipath_hash(const struct net *net, const struct flowi4 *fl4,
20642064
hash_keys.ports.dst = fl4->fl4_dport;
20652065
hash_keys.basic.ip_proto = fl4->flowi4_proto;
20662066
}
2067-
mhash = flow_hash_from_keys(&hash_keys);
2067+
mhash = fib_multipath_hash_from_keys(net, &hash_keys);
20682068
break;
20692069
case 2:
20702070
memset(&hash_keys, 0, sizeof(hash_keys));
@@ -2095,7 +2095,7 @@ int fib_multipath_hash(const struct net *net, const struct flowi4 *fl4,
20952095
hash_keys.addrs.v4addrs.src = fl4->saddr;
20962096
hash_keys.addrs.v4addrs.dst = fl4->daddr;
20972097
}
2098-
mhash = flow_hash_from_keys(&hash_keys);
2098+
mhash = fib_multipath_hash_from_keys(net, &hash_keys);
20992099
break;
21002100
case 3:
21012101
if (skb)

net/ipv6/route.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2372,7 +2372,7 @@ static u32 rt6_multipath_custom_hash_outer(const struct net *net,
23722372
hash_keys.ports.dst = keys.ports.dst;
23732373

23742374
*p_has_inner = !!(keys.control.flags & FLOW_DIS_ENCAPSULATION);
2375-
return flow_hash_from_keys(&hash_keys);
2375+
return fib_multipath_hash_from_keys(net, &hash_keys);
23762376
}
23772377

23782378
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,
24212421
if (hash_fields & FIB_MULTIPATH_HASH_FIELD_INNER_DST_PORT)
24222422
hash_keys.ports.dst = keys.ports.dst;
24232423

2424-
return flow_hash_from_keys(&hash_keys);
2424+
return fib_multipath_hash_from_keys(net, &hash_keys);
24252425
}
24262426

24272427
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,
24602460
if (hash_fields & FIB_MULTIPATH_HASH_FIELD_DST_PORT)
24612461
hash_keys.ports.dst = fl6->fl6_dport;
24622462

2463-
return flow_hash_from_keys(&hash_keys);
2463+
return fib_multipath_hash_from_keys(net, &hash_keys);
24642464
}
24652465

24662466
/* 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,
24822482
hash_keys.tags.flow_label = (__force u32)flowi6_get_flowlabel(fl6);
24832483
hash_keys.basic.ip_proto = fl6->flowi6_proto;
24842484
}
2485-
mhash = flow_hash_from_keys(&hash_keys);
2485+
mhash = fib_multipath_hash_from_keys(net, &hash_keys);
24862486
break;
24872487
case 1:
24882488
if (skb) {
@@ -2514,7 +2514,7 @@ u32 rt6_multipath_hash(const struct net *net, const struct flowi6 *fl6,
25142514
hash_keys.ports.dst = fl6->fl6_dport;
25152515
hash_keys.basic.ip_proto = fl6->flowi6_proto;
25162516
}
2517-
mhash = flow_hash_from_keys(&hash_keys);
2517+
mhash = fib_multipath_hash_from_keys(net, &hash_keys);
25182518
break;
25192519
case 2:
25202520
memset(&hash_keys, 0, sizeof(hash_keys));
@@ -2551,7 +2551,7 @@ u32 rt6_multipath_hash(const struct net *net, const struct flowi6 *fl6,
25512551
hash_keys.tags.flow_label = (__force u32)flowi6_get_flowlabel(fl6);
25522552
hash_keys.basic.ip_proto = fl6->flowi6_proto;
25532553
}
2554-
mhash = flow_hash_from_keys(&hash_keys);
2554+
mhash = fib_multipath_hash_from_keys(net, &hash_keys);
25552555
break;
25562556
case 3:
25572557
if (skb)

0 commit comments

Comments
 (0)