Commit b6280b47 authored by Neil Horman's avatar Neil Horman Committed by David S. Miller

ipv4 routing: Ensure that route cache entries are usable and reclaimable with caching is off

When route caching is disabled (rt_caching returns false), We still use route
cache entries that are created and passed into rt_intern_hash once.  These
routes need to be made usable for the one call path that holds a reference to
them, and they need to be reclaimed when they're finished with their use.  To be
made usable, they need to be associated with a neighbor table entry (which they
currently are not), otherwise iproute_finish2 just discards the packet, since we
don't know which L2 peer to send the packet to.  To do this binding, we need to
follow the path a bit higher up in rt_intern_hash, which calls
arp_bind_neighbour, but not assign the route entry to the hash table.
Currently, if caching is off, we simply assign the route to the rp pointer and
are reutrn success.  This patch associates us with a neighbor entry first.

Secondly, we need to make sure that any single use routes like this are known to
the garbage collector when caching is off.  If caching is off, and we try to
hash in a route, it will leak when its refcount reaches zero.  To avoid this,
this patch calls rt_free on the route cache entry passed into rt_intern_hash.
This places us on the gc list for the route cache garbage collector, so that
when its refcount reaches zero, it will be reclaimed (Thanks to Alexey for this
suggestion).

I've tested this on a local system here, and with these patches in place, I'm
able to maintain routed connectivity to remote systems, even if I set
/proc/sys/net/ipv4/rt_cache_rebuild_count to -1, which forces rt_caching to
return false.
Signed-off-by: default avatarNeil Horman <nhorman@redhat.com>
Reported-by: default avatarJarek Poplawski <jarkao2@gmail.com>
Reported-by: default avatarMaxime Bizon <mbizon@freebox.fr>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent d55d87fd
...@@ -1093,8 +1093,27 @@ static int rt_intern_hash(unsigned hash, struct rtable *rt, ...@@ -1093,8 +1093,27 @@ static int rt_intern_hash(unsigned hash, struct rtable *rt,
* If we drop it here, the callers have no way to resolve routes * If we drop it here, the callers have no way to resolve routes
* when we're not caching. Instead, just point *rp at rt, so * when we're not caching. Instead, just point *rp at rt, so
* the caller gets a single use out of the route * the caller gets a single use out of the route
* Note that we do rt_free on this new route entry, so that
* once its refcount hits zero, we are still able to reap it
* (Thanks Alexey)
* Note also the rt_free uses call_rcu. We don't actually
* need rcu protection here, this is just our path to get
* on the route gc list.
*/ */
goto report_and_exit;
if (rt->rt_type == RTN_UNICAST || rt->fl.iif == 0) {
int err = arp_bind_neighbour(&rt->u.dst);
if (err) {
if (net_ratelimit())
printk(KERN_WARNING
"Neighbour table failure & not caching routes.\n");
rt_drop(rt);
return err;
}
}
rt_free(rt);
goto skip_hashing;
} }
rthp = &rt_hash_table[hash].chain; rthp = &rt_hash_table[hash].chain;
...@@ -1211,7 +1230,8 @@ static int rt_intern_hash(unsigned hash, struct rtable *rt, ...@@ -1211,7 +1230,8 @@ static int rt_intern_hash(unsigned hash, struct rtable *rt,
#if RT_CACHE_DEBUG >= 2 #if RT_CACHE_DEBUG >= 2
if (rt->u.dst.rt_next) { if (rt->u.dst.rt_next) {
struct rtable *trt; struct rtable *trt;
printk(KERN_DEBUG "rt_cache @%02x: %pI4", hash, &rt->rt_dst); printk(KERN_DEBUG "rt_cache @%02x: %pI4",
hash, &rt->rt_dst);
for (trt = rt->u.dst.rt_next; trt; trt = trt->u.dst.rt_next) for (trt = rt->u.dst.rt_next; trt; trt = trt->u.dst.rt_next)
printk(" . %pI4", &trt->rt_dst); printk(" . %pI4", &trt->rt_dst);
printk("\n"); printk("\n");
...@@ -1226,7 +1246,7 @@ static int rt_intern_hash(unsigned hash, struct rtable *rt, ...@@ -1226,7 +1246,7 @@ static int rt_intern_hash(unsigned hash, struct rtable *rt,
spin_unlock_bh(rt_hash_lock_addr(hash)); spin_unlock_bh(rt_hash_lock_addr(hash));
report_and_exit: skip_hashing:
if (rp) if (rp)
*rp = rt; *rp = rt;
else else
......
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