Skip to content

Commit 0b34eb0

Browse files
dsaherndavem330
authored andcommitted
ipv6: Refactor __ip6_route_redirect
Move the nexthop evaluation of a fib entry to a helper that can be leveraged for each fib6_nh in a multipath nexthop object. In the move, 'continue' statements means the helper returns false (loop should continue) and 'break' means return true (found the entry of interest). Signed-off-by: David Ahern <dsahern@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 0c59d00 commit 0b34eb0

1 file changed

Lines changed: 33 additions & 23 deletions

File tree

‎net/ipv6/route.c‎

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2407,6 +2407,35 @@ void ip6_sk_dst_store_flow(struct sock *sk, struct dst_entry *dst,
24072407
NULL);
24082408
}
24092409

2410+
static bool ip6_redirect_nh_match(struct fib6_info *f6i,
2411+
struct fib6_nh *nh,
2412+
struct flowi6 *fl6,
2413+
const struct in6_addr *gw,
2414+
struct rt6_info **ret)
2415+
{
2416+
if (nh->fib_nh_flags & RTNH_F_DEAD || !nh->fib_nh_gw_family ||
2417+
fl6->flowi6_oif != nh->fib_nh_dev->ifindex)
2418+
return false;
2419+
2420+
/* rt_cache's gateway might be different from its 'parent'
2421+
* in the case of an ip redirect.
2422+
* So we keep searching in the exception table if the gateway
2423+
* is different.
2424+
*/
2425+
if (!ipv6_addr_equal(gw, &nh->fib_nh_gw6)) {
2426+
struct rt6_info *rt_cache;
2427+
2428+
rt_cache = rt6_find_cached_rt(f6i, &fl6->daddr, &fl6->saddr);
2429+
if (rt_cache &&
2430+
ipv6_addr_equal(gw, &rt_cache->rt6i_gateway)) {
2431+
*ret = rt_cache;
2432+
return true;
2433+
}
2434+
return false;
2435+
}
2436+
return true;
2437+
}
2438+
24102439
/* Handle redirects */
24112440
struct ip6rd_flowi {
24122441
struct flowi6 fl6;
@@ -2420,7 +2449,7 @@ static struct rt6_info *__ip6_route_redirect(struct net *net,
24202449
int flags)
24212450
{
24222451
struct ip6rd_flowi *rdfl = (struct ip6rd_flowi *)fl6;
2423-
struct rt6_info *ret = NULL, *rt_cache;
2452+
struct rt6_info *ret = NULL;
24242453
struct fib6_info *rt;
24252454
struct fib6_node *fn;
24262455

@@ -2438,34 +2467,15 @@ static struct rt6_info *__ip6_route_redirect(struct net *net,
24382467
fn = fib6_node_lookup(&table->tb6_root, &fl6->daddr, &fl6->saddr);
24392468
restart:
24402469
for_each_fib6_node_rt_rcu(fn) {
2441-
if (rt->fib6_nh.fib_nh_flags & RTNH_F_DEAD)
2442-
continue;
24432470
if (fib6_check_expired(rt))
24442471
continue;
24452472
if (rt->fib6_flags & RTF_REJECT)
24462473
break;
2447-
if (!rt->fib6_nh.fib_nh_gw_family)
2448-
continue;
24492474
if (fl6->flowi6_oif != rt->fib6_nh.fib_nh_dev->ifindex)
24502475
continue;
2451-
/* rt_cache's gateway might be different from its 'parent'
2452-
* in the case of an ip redirect.
2453-
* So we keep searching in the exception table if the gateway
2454-
* is different.
2455-
*/
2456-
if (!ipv6_addr_equal(&rdfl->gateway, &rt->fib6_nh.fib_nh_gw6)) {
2457-
rt_cache = rt6_find_cached_rt(rt,
2458-
&fl6->daddr,
2459-
&fl6->saddr);
2460-
if (rt_cache &&
2461-
ipv6_addr_equal(&rdfl->gateway,
2462-
&rt_cache->rt6i_gateway)) {
2463-
ret = rt_cache;
2464-
break;
2465-
}
2466-
continue;
2467-
}
2468-
break;
2476+
if (ip6_redirect_nh_match(rt, &rt->fib6_nh, fl6,
2477+
&rdfl->gateway, &ret))
2478+
goto out;
24692479
}
24702480

24712481
if (!rt)

0 commit comments

Comments
 (0)