Commit 367efcb9 authored by Martin KaFai Lau's avatar Martin KaFai Lau Committed by David S. Miller

ipv6: Avoid redoing fib6_lookup() with reachable = 0 by saving fn

This patch save the fn before doing rt6_backtrack.
Hence, without redo-ing the fib6_lookup(), saved_fn can be used
to redo rt6_select() with RT6_LOOKUP_F_REACHABLE off.

Some minor changes I think make sense to review as a single patch:
* Remove the 'out:' goto label.
* Remove the 'reachable' variable. Only use the 'strict' variable instead.

After this patch, "failing ip6_ins_rt()" should be the only case that
requires a redo of fib6_lookup().

Cc: David Miller <davem@davemloft.net>
Cc: Hannes Frederic Sowa <hannes@stressinduktion.org>
Signed-off-by: default avatarMartin KaFai Lau <kafai@fb.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 94c77bb4
...@@ -917,31 +917,40 @@ static struct rt6_info *rt6_alloc_clone(struct rt6_info *ort, ...@@ -917,31 +917,40 @@ static struct rt6_info *rt6_alloc_clone(struct rt6_info *ort,
static struct rt6_info *ip6_pol_route(struct net *net, struct fib6_table *table, int oif, static struct rt6_info *ip6_pol_route(struct net *net, struct fib6_table *table, int oif,
struct flowi6 *fl6, int flags) struct flowi6 *fl6, int flags)
{ {
struct fib6_node *fn; struct fib6_node *fn, *saved_fn;
struct rt6_info *rt, *nrt; struct rt6_info *rt, *nrt;
int strict = 0; int strict = 0;
int attempts = 3; int attempts = 3;
int err; int err;
int reachable = net->ipv6.devconf_all->forwarding ? 0 : RT6_LOOKUP_F_REACHABLE;
strict |= flags & RT6_LOOKUP_F_IFACE; strict |= flags & RT6_LOOKUP_F_IFACE;
if (net->ipv6.devconf_all->forwarding == 0)
strict |= RT6_LOOKUP_F_REACHABLE;
redo_fib6_lookup_lock: redo_fib6_lookup_lock:
read_lock_bh(&table->tb6_lock); read_lock_bh(&table->tb6_lock);
redo_fib6_lookup:
fn = fib6_lookup(&table->tb6_root, &fl6->daddr, &fl6->saddr); fn = fib6_lookup(&table->tb6_root, &fl6->daddr, &fl6->saddr);
saved_fn = fn;
redo_rt6_select: redo_rt6_select:
rt = rt6_select(fn, oif, strict | reachable); rt = rt6_select(fn, oif, strict);
if (rt->rt6i_nsiblings) if (rt->rt6i_nsiblings)
rt = rt6_multipath_select(rt, fl6, oif, strict | reachable); rt = rt6_multipath_select(rt, fl6, oif, strict);
if (rt == net->ipv6.ip6_null_entry) { if (rt == net->ipv6.ip6_null_entry) {
fn = fib6_backtrack(fn, &fl6->saddr); fn = fib6_backtrack(fn, &fl6->saddr);
if (fn) if (fn)
goto redo_rt6_select; goto redo_rt6_select;
else else if (strict & RT6_LOOKUP_F_REACHABLE) {
goto out; /* also consider unreachable route */
strict &= ~RT6_LOOKUP_F_REACHABLE;
fn = saved_fn;
goto redo_rt6_select;
} else {
dst_hold(&rt->dst);
read_unlock_bh(&table->tb6_lock);
goto out2;
}
} }
dst_hold(&rt->dst); dst_hold(&rt->dst);
...@@ -977,13 +986,6 @@ static struct rt6_info *ip6_pol_route(struct net *net, struct fib6_table *table, ...@@ -977,13 +986,6 @@ static struct rt6_info *ip6_pol_route(struct net *net, struct fib6_table *table,
ip6_rt_put(rt); ip6_rt_put(rt);
goto redo_fib6_lookup_lock; goto redo_fib6_lookup_lock;
out:
if (reachable) {
reachable = 0;
goto redo_fib6_lookup;
}
dst_hold(&rt->dst);
read_unlock_bh(&table->tb6_lock);
out2: out2:
rt->dst.lastuse = jiffies; rt->dst.lastuse = jiffies;
rt->dst.__use++; rt->dst.__use++;
......
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