Skip to content

Commit 24ba144

Browse files
wenxudavem330
authored andcommitted
route: Add multipath_hash in flowi_common to make user-define hash
Current fib_multipath_hash_policy can make hash based on the L3 or L4. But it only work on the outer IP. So a specific tunnel always has the same hash value. But a specific tunnel may contain so many inner connections. This patch provide a generic multipath_hash in floi_common. It can make a user-define hash which can mix with L3 or L4 hash. Signed-off-by: wenxu <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 8f4ef49 commit 24ba144

File tree

6 files changed

+13
-6
lines changed

6 files changed

+13
-6
lines changed

drivers/net/ethernet/mellanox/mlxsw/spectrum_span.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ mlxsw_sp_span_gretap4_route(const struct net_device *to_dev,
305305

306306
parms = mlxsw_sp_ipip_netdev_parms4(to_dev);
307307
ip_tunnel_init_flow(&fl4, parms.iph.protocol, *daddrp, *saddrp,
308-
0, 0, parms.link, tun->fwmark);
308+
0, 0, parms.link, tun->fwmark, 0);
309309

310310
rt = ip_route_output_key(tun->net, &fl4);
311311
if (IS_ERR(rt))

include/net/flow.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ struct flowi_common {
4040
__u32 flowic_secid;
4141
kuid_t flowic_uid;
4242
struct flowi_tunnel flowic_tun_key;
43+
__u32 flowic_multipath_hash;
4344
};
4445

4546
union flowi_uli {
@@ -78,6 +79,7 @@ struct flowi4 {
7879
#define flowi4_secid __fl_common.flowic_secid
7980
#define flowi4_tun_key __fl_common.flowic_tun_key
8081
#define flowi4_uid __fl_common.flowic_uid
82+
#define flowi4_multipath_hash __fl_common.flowic_multipath_hash
8183

8284
/* (saddr,daddr) must be grouped, same order as in IP header */
8385
__be32 saddr;

include/net/ip_tunnels.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ static inline void ip_tunnel_init_flow(struct flowi4 *fl4,
241241
int proto,
242242
__be32 daddr, __be32 saddr,
243243
__be32 key, __u8 tos, int oif,
244-
__u32 mark)
244+
__u32 mark, __u32 tun_inner_hash)
245245
{
246246
memset(fl4, 0, sizeof(*fl4));
247247
fl4->flowi4_oif = oif;
@@ -251,6 +251,7 @@ static inline void ip_tunnel_init_flow(struct flowi4 *fl4,
251251
fl4->flowi4_proto = proto;
252252
fl4->fl4_gre_key = key;
253253
fl4->flowi4_mark = mark;
254+
fl4->flowi4_multipath_hash = tun_inner_hash;
254255
}
255256

256257
int ip_tunnel_init(struct net_device *dev);

net/ipv4/ip_gre.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ static int gre_fill_metadata_dst(struct net_device *dev, struct sk_buff *skb)
578578
key = &info->key;
579579
ip_tunnel_init_flow(&fl4, IPPROTO_GRE, key->u.ipv4.dst, key->u.ipv4.src,
580580
tunnel_id_to_key32(key->tun_id), key->tos, 0,
581-
skb->mark);
581+
skb->mark, skb_get_hash(skb));
582582
rt = ip_route_output_key(dev_net(dev), &fl4);
583583
if (IS_ERR(rt))
584584
return PTR_ERR(rt);

net/ipv4/ip_tunnel.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ static int ip_tunnel_bind_dev(struct net_device *dev)
310310
ip_tunnel_init_flow(&fl4, iph->protocol, iph->daddr,
311311
iph->saddr, tunnel->parms.o_key,
312312
RT_TOS(iph->tos), tunnel->parms.link,
313-
tunnel->fwmark);
313+
tunnel->fwmark, 0);
314314
rt = ip_route_output_key(tunnel->net, &fl4);
315315

316316
if (!IS_ERR(rt)) {
@@ -584,7 +584,7 @@ void ip_md_tunnel_xmit(struct sk_buff *skb, struct net_device *dev,
584584
}
585585
ip_tunnel_init_flow(&fl4, proto, key->u.ipv4.dst, key->u.ipv4.src,
586586
tunnel_id_to_key32(key->tun_id), RT_TOS(tos),
587-
0, skb->mark);
587+
0, skb->mark, skb_get_hash(skb));
588588
if (tunnel->encap.type != TUNNEL_ENCAP_NONE)
589589
goto tx_error;
590590

@@ -744,7 +744,7 @@ void ip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev,
744744

745745
ip_tunnel_init_flow(&fl4, protocol, dst, tnl_params->saddr,
746746
tunnel->parms.o_key, RT_TOS(tos), tunnel->parms.link,
747-
tunnel->fwmark);
747+
tunnel->fwmark, skb_get_hash(skb));
748748

749749
if (ip_tunnel_encap(skb, tunnel, &protocol, &fl4) < 0)
750750
goto tx_error;

net/ipv4/route.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1820,6 +1820,7 @@ static void ip_multipath_l3_keys(const struct sk_buff *skb,
18201820
int fib_multipath_hash(const struct net *net, const struct flowi4 *fl4,
18211821
const struct sk_buff *skb, struct flow_keys *flkeys)
18221822
{
1823+
u32 multipath_hash = fl4->flowi4_multipath_hash;
18231824
struct flow_keys hash_keys;
18241825
u32 mhash;
18251826

@@ -1870,6 +1871,9 @@ int fib_multipath_hash(const struct net *net, const struct flowi4 *fl4,
18701871
}
18711872
mhash = flow_hash_from_keys(&hash_keys);
18721873

1874+
if (multipath_hash)
1875+
mhash = jhash_2words(mhash, multipath_hash, 0);
1876+
18731877
return mhash >> 1;
18741878
}
18751879
#endif /* CONFIG_IP_ROUTE_MULTIPATH */

0 commit comments

Comments
 (0)