diff mbox

Question about default route handling/lookup in a custom table

Message ID CAKP4w2Q_5V=2CdyUpeXrHg=dTv1LNynp87gy6nrQYWYyBuA39A@mail.gmail.com
State RFC, archived
Delegated to: David Miller
Headers show

Commit Message

JP Abgrall July 23, 2013, 1:20 a.m. UTC
The following sequence fails when adding the default route:
(wlan0 is up, nothing is trying to manage,...)

       ip route flush dev wlan0 table all
       ip route flush table 60
       ip route add 1.1.1.1/32 dev wlan0 table 60
       ip route add default via 1.1.1.1 dev wlan0 table 60

Turns out that fib_lookup() uses the
  cfg->fc_nlinfo.nl_net->ipv4.rules_ops->rules_list
which does not contain rules for table 60.

Is there something broken with my assumptions that it should work?
Is the lack for rules for table 60 in the rules_list a red herring or
needs digging into?

With my limited understanding of why things are going wrong, I'm tempted to
 - detect that fib_look() failed and cfg->cf_table is not unspecified.
 - then do an explicit fib table lookup.

This behaviour is in 3.4.39 and I haven't seen much changes in later
versions of fib_semantics.c or related files that might apply.

* diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
index c60a396..acf019d 100644
                                return err;


* This is the sequence of function calls I thought were relevant for
the "ip route add default ...table 60":

inet_rtm_newroute(): table=60 scope=0
fib_table_insert(): table=60 dst=0x0 type=1
fib_create_info(): fc_mx=0x  (null) table=60 fi=0xc5266a00
fib_create_info(): fc_mp=0x  (null) table=60 fi=0xc5266a00
fib_create_info(): props[fc_type=1].error=0 table=60 fi=0xc5266a00
fib_create_info(): cfg.table=60 scope=0
fib_check_nh(): table=60 nh_gw=0x1010101 nh_flags=0x0
fib_lookup(): table ?:
fib_rules_lookup(): rule.table=255:
fib4_rule_action(): table 255: action=1
fib_table_lookup(): tb.id=255 tb.numdflt=0
fib_table_lookup(): tb.id=255 pn{}: pref_mismatch
fib_table_lookup(): tb.id=255 pn{}: chopped_off(3) > pn->bits(2)
fib_rules_lookup(): rule.table=254:
fib4_rule_action(): table 254: action=1
fib_table_lookup(): tb.id=254 tb.numdflt=1
fib_table_lookup(): tb.id=254 pn{}: chopped_off(3) > pn->bits(2)
fib_rules_lookup(): rule.table=253:
fib4_rule_action(): table 253: action=1
fib_check_nh(): table=60 fib_lookup(fc_scope=253)=-3 res.type=0  <<<
this is where it would normally fail.
fib_check_nh(): table=60 fib_get_table(table=60)=c53d7cc0  <<< This is
where the added code kicks in.
fib_table_lookup(): tb.id=60 tb.numdflt=0
fib_table_lookup(): tb.id=60 check_leaf()=0 res.type=1
fib_check_nh(): table=60 fib_table_lookup()=0 res.type=1
fib_create_info(): cfg.table=60 check_nh()=0
fib_create_info(): table=60 fi=0xc5266a00
fib_table_insert(): table=60 fib_create_info()=xc5266a00
fib_table_insert(): table=60 created new_fa=xc4459f00->type=1
inet_rtm_newroute(): table=60 err=0  <<< It now succeeds.

--
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

Hannes Frederic Sowa July 23, 2013, 1:47 p.m. UTC | #1
Hello!

On Mon, Jul 22, 2013 at 06:20:18PM -0700, JP Abgrall wrote:
> The following sequence fails when adding the default route:
> (wlan0 is up, nothing is trying to manage,...)
> 
>        ip route flush dev wlan0 table all
>        ip route flush table 60
>        ip route add 1.1.1.1/32 dev wlan0 table 60

I am not sure but would have expected that you needed to add a rule e.g. ip
rule add oif wlan0 table 60 to successfully match the next route insertion.

>        ip route add default via 1.1.1.1 dev wlan0 table 60

Otherwise another rule lookup could alter the fib_lookup in such a way that the
nexthop is not resolveable and the routing table in its entirty could have
unresolveable holes.

I did not check the code, this is just my intuition.

Greetings,

  Hannes

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
JP Abgrall July 23, 2013, 5:58 p.m. UTC | #2
On Tue, Jul 23, 2013 at 6:47 AM, Hannes Frederic Sowa
<hannes@stressinduktion.org> wrote:
> On Mon, Jul 22, 2013 at 06:20:18PM -0700, JP Abgrall wrote:
>>        ip route add 1.1.1.1/32 dev wlan0 table 60
>
> I am not sure but would have expected that you needed to add a rule e.g. ip
> rule add oif wlan0 table 60 to successfully match the next route insertion.

Works. Thanks. Shows how much more I need to learn. Will go dig into
the code to understand it better.
--
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

--- a/net/ipv4/fib_semantics.c
+++ b/net/ipv4/fib_semantics.c
@@ -567,6 +567,14 @@  static int fib_check_nh(struct fib_config *cfg,
struct fib_info *fi,
                        if (fl4.flowi4_scope < RT_SCOPE_LINK)
                                fl4.flowi4_scope = RT_SCOPE_LINK;
                        err = fib_lookup(net, &fl4, &res);
+                       if (err && cfg->fc_table != RT_TABLE_UNSPEC) {
+                               struct fib_table *table;
+                               table = fib_get_table(net, cfg->fc_table);
+                               if (table &&
+                                   !fib_table_lookup(table, &fl4, &res,
+                                                     FIB_LOOKUP_NOREF))
+                                       err = 0;
+                       }
                        if (err) {
                                rcu_read_unlock();