Skip to content

Commit 3bfd847

Browse files
David Aherndavem330
authored andcommitted
net: Use passed in table for nexthop lookups
If a user passes in a table for new routes use that table for nexthop lookups. Specifically, this solves the case where a connected route does not exist in the main table, but only another table and then a subsequent route is added with a next hop using the connected route. ie., $ ip route ls default via 10.0.2.2 dev eth0 10.0.2.0/24 dev eth0 proto kernel scope link src 10.0.2.15 169.254.0.0/16 dev eth0 scope link metric 1003 192.168.56.0/24 dev eth1 proto kernel scope link src 192.168.56.51 $ ip route ls table 10 1.1.1.0/24 dev eth2 scope link Without this patch adding a nexthop route fails: $ ip route add table 10 2.2.2.0/24 via 1.1.1.10 RTNETLINK answers: Network is unreachable With this patch the route is added successfully. Signed-off-by: David Ahern <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 021dd3b commit 3bfd847

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
@@ -691,6 +691,7 @@ static int fib_check_nh(struct fib_config *cfg, struct fib_info *fi,
691691
}
692692
rcu_read_lock();
693693
{
694+
struct fib_table *tbl = NULL;
694695
struct flowi4 fl4 = {
695696
.daddr = nh->nh_gw,
696697
.flowi4_scope = cfg->fc_scope + 1,
@@ -701,8 +702,16 @@ static int fib_check_nh(struct fib_config *cfg, struct fib_info *fi,
701702
/* It is not necessary, but requires a bit of thinking */
702703
if (fl4.flowi4_scope < RT_SCOPE_LINK)
703704
fl4.flowi4_scope = RT_SCOPE_LINK;
704-
err = fib_lookup(net, &fl4, &res,
705-
FIB_LOOKUP_IGNORE_LINKSTATE);
705+
706+
if (cfg->fc_table)
707+
tbl = fib_get_table(net, cfg->fc_table);
708+
709+
if (tbl)
710+
err = fib_table_lookup(tbl, &fl4, &res,
711+
FIB_LOOKUP_IGNORE_LINKSTATE);
712+
else
713+
err = fib_lookup(net, &fl4, &res,
714+
FIB_LOOKUP_IGNORE_LINKSTATE);
706715
if (err) {
707716
rcu_read_unlock();
708717
return err;

0 commit comments

Comments
 (0)