Skip to content

Commit 6807352

Browse files
NicolasDichtelkuba-moo
authored andcommitted
ipv4: fix source address selection with route leak
By default, an address assigned to the output interface is selected when the source address is not specified. This is problematic when a route, configured in a vrf, uses an interface from another vrf (aka route leak). The original vrf does not own the selected source address. Let's add a check against the output interface and call the appropriate function to select the source address. CC: [email protected] Fixes: 8cbb512 ("net: Add source address lookup op for VRF") Signed-off-by: Nicolas Dichtel <[email protected]> Reviewed-by: David Ahern <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent f67a90a commit 6807352

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

net/ipv4/fib_semantics.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2270,6 +2270,15 @@ void fib_select_path(struct net *net, struct fib_result *res,
22702270
fib_select_default(fl4, res);
22712271

22722272
check_saddr:
2273-
if (!fl4->saddr)
2274-
fl4->saddr = fib_result_prefsrc(net, res);
2273+
if (!fl4->saddr) {
2274+
struct net_device *l3mdev;
2275+
2276+
l3mdev = dev_get_by_index_rcu(net, fl4->flowi4_l3mdev);
2277+
2278+
if (!l3mdev ||
2279+
l3mdev_master_dev_rcu(FIB_RES_DEV(*res)) == l3mdev)
2280+
fl4->saddr = fib_result_prefsrc(net, res);
2281+
else
2282+
fl4->saddr = inet_select_addr(l3mdev, 0, RT_SCOPE_LINK);
2283+
}
22752284
}

0 commit comments

Comments
 (0)