Commit 3bfd8472 authored by David Ahern's avatar David Ahern Committed by David S. Miller
Browse files

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 dev eth0 dev eth0  proto kernel  scope link  src dev eth0  scope link  metric 1003 dev eth1  proto kernel  scope link  src

$ ip route ls table 10 dev eth2  scope link

Without this patch adding a nexthop route fails:

$ ip route add table 10 via
RTNETLINK answers: Network is unreachable

With this patch the route is added successfully.
Signed-off-by: default avatarDavid Ahern <>
Signed-off-by: default avatarDavid S. Miller <>
parent 021dd3b8
......@@ -691,6 +691,7 @@ static int fib_check_nh(struct fib_config *cfg, struct fib_info *fi,
struct fib_table *tbl = NULL;
struct flowi4 fl4 = {
.daddr = nh->nh_gw,
.flowi4_scope = cfg->fc_scope + 1,
......@@ -701,8 +702,16 @@ static int fib_check_nh(struct fib_config *cfg, struct fib_info *fi,
/* It is not necessary, but requires a bit of thinking */
if (fl4.flowi4_scope < RT_SCOPE_LINK)
fl4.flowi4_scope = RT_SCOPE_LINK;
err = fib_lookup(net, &fl4, &res,
if (cfg->fc_table)
tbl = fib_get_table(net, cfg->fc_table);
if (tbl)
err = fib_table_lookup(tbl, &fl4, &res,
err = fib_lookup(net, &fl4, &res,
if (err) {
return err;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment