Commit e659ba31 authored by David Ahern's avatar David Ahern Committed by David S. Miller

ipv6: Handle all fib6_nh in a nexthop in exception handling

Add a hook in rt6_flush_exceptions, rt6_remove_exception_rt,
rt6_update_exception_stamp_rt, and rt6_age_exceptions to handle
nexthop struct in a fib6_info.
Signed-off-by: default avatarDavid Ahern <dsahern@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 2c170e07
...@@ -1742,8 +1742,21 @@ static void fib6_nh_flush_exceptions(struct fib6_nh *nh, struct fib6_info *from) ...@@ -1742,8 +1742,21 @@ static void fib6_nh_flush_exceptions(struct fib6_nh *nh, struct fib6_info *from)
spin_unlock_bh(&rt6_exception_lock); spin_unlock_bh(&rt6_exception_lock);
} }
static int rt6_nh_flush_exceptions(struct fib6_nh *nh, void *arg)
{
struct fib6_info *f6i = arg;
fib6_nh_flush_exceptions(nh, f6i);
return 0;
}
void rt6_flush_exceptions(struct fib6_info *f6i) void rt6_flush_exceptions(struct fib6_info *f6i)
{ {
if (f6i->nh)
nexthop_for_each_fib6_nh(f6i->nh, rt6_nh_flush_exceptions,
f6i);
else
fib6_nh_flush_exceptions(f6i->fib6_nh, f6i); fib6_nh_flush_exceptions(f6i->fib6_nh, f6i);
} }
...@@ -1831,6 +1844,23 @@ static int fib6_nh_remove_exception(const struct fib6_nh *nh, int plen, ...@@ -1831,6 +1844,23 @@ static int fib6_nh_remove_exception(const struct fib6_nh *nh, int plen,
return err; return err;
} }
struct fib6_nh_excptn_arg {
struct rt6_info *rt;
int plen;
};
static int rt6_nh_remove_exception_rt(struct fib6_nh *nh, void *_arg)
{
struct fib6_nh_excptn_arg *arg = _arg;
int err;
err = fib6_nh_remove_exception(nh, arg->plen, arg->rt);
if (err == 0)
return 1;
return 0;
}
static int rt6_remove_exception_rt(struct rt6_info *rt) static int rt6_remove_exception_rt(struct rt6_info *rt)
{ {
struct fib6_info *from; struct fib6_info *from;
...@@ -1839,6 +1869,20 @@ static int rt6_remove_exception_rt(struct rt6_info *rt) ...@@ -1839,6 +1869,20 @@ static int rt6_remove_exception_rt(struct rt6_info *rt)
if (!from || !(rt->rt6i_flags & RTF_CACHE)) if (!from || !(rt->rt6i_flags & RTF_CACHE))
return -EINVAL; return -EINVAL;
if (from->nh) {
struct fib6_nh_excptn_arg arg = {
.rt = rt,
.plen = from->fib6_src.plen
};
int rc;
/* rc = 1 means an entry was found */
rc = nexthop_for_each_fib6_nh(from->nh,
rt6_nh_remove_exception_rt,
&arg);
return rc ? 0 : -ENOENT;
}
return fib6_nh_remove_exception(from->fib6_nh, return fib6_nh_remove_exception(from->fib6_nh,
from->fib6_src.plen, rt); from->fib6_src.plen, rt);
} }
...@@ -1869,9 +1913,33 @@ static void fib6_nh_update_exception(const struct fib6_nh *nh, int plen, ...@@ -1869,9 +1913,33 @@ static void fib6_nh_update_exception(const struct fib6_nh *nh, int plen,
rt6_ex->stamp = jiffies; rt6_ex->stamp = jiffies;
} }
struct fib6_nh_match_arg {
const struct net_device *dev;
const struct in6_addr *gw;
struct fib6_nh *match;
};
/* determine if fib6_nh has given device and gateway */
static int fib6_nh_find_match(struct fib6_nh *nh, void *_arg)
{
struct fib6_nh_match_arg *arg = _arg;
if (arg->dev != nh->fib_nh_dev ||
(arg->gw && !nh->fib_nh_gw_family) ||
(!arg->gw && nh->fib_nh_gw_family) ||
(arg->gw && !ipv6_addr_equal(arg->gw, &nh->fib_nh_gw6)))
return 0;
arg->match = nh;
/* found a match, break the loop */
return 1;
}
static void rt6_update_exception_stamp_rt(struct rt6_info *rt) static void rt6_update_exception_stamp_rt(struct rt6_info *rt)
{ {
struct fib6_info *from; struct fib6_info *from;
struct fib6_nh *fib6_nh;
rcu_read_lock(); rcu_read_lock();
...@@ -1879,7 +1947,21 @@ static void rt6_update_exception_stamp_rt(struct rt6_info *rt) ...@@ -1879,7 +1947,21 @@ static void rt6_update_exception_stamp_rt(struct rt6_info *rt)
if (!from || !(rt->rt6i_flags & RTF_CACHE)) if (!from || !(rt->rt6i_flags & RTF_CACHE))
goto unlock; goto unlock;
fib6_nh_update_exception(from->fib6_nh, from->fib6_src.plen, rt); if (from->nh) {
struct fib6_nh_match_arg arg = {
.dev = rt->dst.dev,
.gw = &rt->rt6i_gateway,
};
nexthop_for_each_fib6_nh(from->nh, fib6_nh_find_match, &arg);
if (!arg.match)
return;
fib6_nh = arg.match;
} else {
fib6_nh = from->fib6_nh;
}
fib6_nh_update_exception(fib6_nh, from->fib6_src.plen, rt);
unlock: unlock:
rcu_read_unlock(); rcu_read_unlock();
} }
...@@ -2041,11 +2123,34 @@ static void fib6_nh_age_exceptions(const struct fib6_nh *nh, ...@@ -2041,11 +2123,34 @@ static void fib6_nh_age_exceptions(const struct fib6_nh *nh,
rcu_read_unlock_bh(); rcu_read_unlock_bh();
} }
struct fib6_nh_age_excptn_arg {
struct fib6_gc_args *gc_args;
unsigned long now;
};
static int rt6_nh_age_exceptions(struct fib6_nh *nh, void *_arg)
{
struct fib6_nh_age_excptn_arg *arg = _arg;
fib6_nh_age_exceptions(nh, arg->gc_args, arg->now);
return 0;
}
void rt6_age_exceptions(struct fib6_info *f6i, void rt6_age_exceptions(struct fib6_info *f6i,
struct fib6_gc_args *gc_args, struct fib6_gc_args *gc_args,
unsigned long now) unsigned long now)
{ {
if (f6i->nh) {
struct fib6_nh_age_excptn_arg arg = {
.gc_args = gc_args,
.now = now
};
nexthop_for_each_fib6_nh(f6i->nh, rt6_nh_age_exceptions,
&arg);
} else {
fib6_nh_age_exceptions(f6i->fib6_nh, gc_args, now); fib6_nh_age_exceptions(f6i->fib6_nh, gc_args, now);
}
} }
/* must be called with rcu lock held */ /* must be called with rcu lock held */
......
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