Skip to content

Commit b16cb45

Browse files
tracywwnjdavem330
authored andcommitted
ipv6: prepare rt6_clean_tohost() for exception table
If we move all cached dst into the exception table under the main route, current rt6_clean_tohost() will no longer be able to access them. This commit makes fib6_clean_tohost() to also go through all cached routes in exception table and removes cached gateway routes to the passed in gateway. This is a preparation in order to move all cached routes into the exception table. Signed-off-by: Wei Wang <[email protected]> Signed-off-by: Martin KaFai Lau <[email protected]> Signed-off-by: Eric Dumazet <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent f5bbe7e commit b16cb45

File tree

1 file changed

+47
-1
lines changed

1 file changed

+47
-1
lines changed

net/ipv6/route.c

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1491,6 +1491,43 @@ static void rt6_exceptions_update_pmtu(struct rt6_info *rt, int mtu)
14911491
}
14921492
}
14931493

1494+
#define RTF_CACHE_GATEWAY (RTF_GATEWAY | RTF_CACHE)
1495+
1496+
static void rt6_exceptions_clean_tohost(struct rt6_info *rt,
1497+
struct in6_addr *gateway)
1498+
{
1499+
struct rt6_exception_bucket *bucket;
1500+
struct rt6_exception *rt6_ex;
1501+
struct hlist_node *tmp;
1502+
int i;
1503+
1504+
if (!rcu_access_pointer(rt->rt6i_exception_bucket))
1505+
return;
1506+
1507+
spin_lock_bh(&rt6_exception_lock);
1508+
bucket = rcu_dereference_protected(rt->rt6i_exception_bucket,
1509+
lockdep_is_held(&rt6_exception_lock));
1510+
1511+
if (bucket) {
1512+
for (i = 0; i < FIB6_EXCEPTION_BUCKET_SIZE; i++) {
1513+
hlist_for_each_entry_safe(rt6_ex, tmp,
1514+
&bucket->chain, hlist) {
1515+
struct rt6_info *entry = rt6_ex->rt6i;
1516+
1517+
if ((entry->rt6i_flags & RTF_CACHE_GATEWAY) ==
1518+
RTF_CACHE_GATEWAY &&
1519+
ipv6_addr_equal(gateway,
1520+
&entry->rt6i_gateway)) {
1521+
rt6_remove_exception(bucket, rt6_ex);
1522+
}
1523+
}
1524+
bucket++;
1525+
}
1526+
}
1527+
1528+
spin_unlock_bh(&rt6_exception_lock);
1529+
}
1530+
14941531
struct rt6_info *ip6_pol_route(struct net *net, struct fib6_table *table,
14951532
int oif, struct flowi6 *fl6, int flags)
14961533
{
@@ -3240,18 +3277,27 @@ void rt6_remove_prefsrc(struct inet6_ifaddr *ifp)
32403277
}
32413278

32423279
#define RTF_RA_ROUTER (RTF_ADDRCONF | RTF_DEFAULT | RTF_GATEWAY)
3243-
#define RTF_CACHE_GATEWAY (RTF_GATEWAY | RTF_CACHE)
32443280

32453281
/* Remove routers and update dst entries when gateway turn into host. */
32463282
static int fib6_clean_tohost(struct rt6_info *rt, void *arg)
32473283
{
32483284
struct in6_addr *gateway = (struct in6_addr *)arg;
32493285

3286+
/* RTF_CACHE_GATEWAY case will be removed once the exception
3287+
* table is hooked up to store all cached routes.
3288+
*/
32503289
if ((((rt->rt6i_flags & RTF_RA_ROUTER) == RTF_RA_ROUTER) ||
32513290
((rt->rt6i_flags & RTF_CACHE_GATEWAY) == RTF_CACHE_GATEWAY)) &&
32523291
ipv6_addr_equal(gateway, &rt->rt6i_gateway)) {
32533292
return -1;
32543293
}
3294+
3295+
/* Further clean up cached routes in exception table.
3296+
* This is needed because cached route may have a different
3297+
* gateway than its 'parent' in the case of an ip redirect.
3298+
*/
3299+
rt6_exceptions_clean_tohost(rt, gateway);
3300+
32553301
return 0;
32563302
}
32573303

0 commit comments

Comments
 (0)