Skip to content

Commit 38fbeee

Browse files
tracywwnjdavem330
authored andcommitted
ipv6: prepare fib6_locate() for exception table
fib6_locate() is used to find the fib6_node according to the passed in prefix address key. It currently tries to find the fib6_node with the exact match of the passed in key. However, when we move cached routes into the exception table, fib6_locate() will fail to find the fib6_node for it as the cached routes will be stored in the exception table under the fib6_node with the longest prefix match of the cache's dst addr key. This commit adds a new parameter to let the caller specify if it needs exact match or longest prefix match. Right now, all callers still does exact match when calling fib6_locate(). It will be changed in later commit where exception table is hooked up to store cached routes. 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 c757faa commit 38fbeee

File tree

4 files changed

+29
-11
lines changed

4 files changed

+29
-11
lines changed

include/net/ip6_fib.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,8 @@ struct fib6_node *fib6_lookup(struct fib6_node *root,
357357

358358
struct fib6_node *fib6_locate(struct fib6_node *root,
359359
const struct in6_addr *daddr, int dst_len,
360-
const struct in6_addr *saddr, int src_len);
360+
const struct in6_addr *saddr, int src_len,
361+
bool exact_match);
361362

362363
void fib6_clean_all(struct net *net, int (*func)(struct rt6_info *, void *arg),
363364
void *arg);

net/ipv6/addrconf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2322,7 +2322,7 @@ static struct rt6_info *addrconf_get_prefix_route(const struct in6_addr *pfx,
23222322
return NULL;
23232323

23242324
read_lock_bh(&table->tb6_lock);
2325-
fn = fib6_locate(&table->tb6_root, pfx, plen, NULL, 0);
2325+
fn = fib6_locate(&table->tb6_root, pfx, plen, NULL, 0, true);
23262326
if (!fn)
23272327
goto out;
23282328

net/ipv6/ip6_fib.c

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,14 +1343,21 @@ struct fib6_node *fib6_lookup(struct fib6_node *root, const struct in6_addr *dad
13431343
/*
13441344
* Get node with specified destination prefix (and source prefix,
13451345
* if subtrees are used)
1346+
* exact_match == true means we try to find fn with exact match of
1347+
* the passed in prefix addr
1348+
* exact_match == false means we try to find fn with longest prefix
1349+
* match of the passed in prefix addr. This is useful for finding fn
1350+
* for cached route as it will be stored in the exception table under
1351+
* the node with longest prefix length.
13461352
*/
13471353

13481354

13491355
static struct fib6_node *fib6_locate_1(struct fib6_node *root,
13501356
const struct in6_addr *addr,
1351-
int plen, int offset)
1357+
int plen, int offset,
1358+
bool exact_match)
13521359
{
1353-
struct fib6_node *fn;
1360+
struct fib6_node *fn, *prev = NULL;
13541361

13551362
for (fn = root; fn ; ) {
13561363
struct rt6key *key = (struct rt6key *)((u8 *)fn->leaf + offset);
@@ -1360,11 +1367,13 @@ static struct fib6_node *fib6_locate_1(struct fib6_node *root,
13601367
*/
13611368
if (plen < fn->fn_bit ||
13621369
!ipv6_prefix_equal(&key->addr, addr, fn->fn_bit))
1363-
return NULL;
1370+
goto out;
13641371

13651372
if (plen == fn->fn_bit)
13661373
return fn;
13671374

1375+
prev = fn;
1376+
13681377
/*
13691378
* We have more bits to go
13701379
*/
@@ -1373,24 +1382,31 @@ static struct fib6_node *fib6_locate_1(struct fib6_node *root,
13731382
else
13741383
fn = fn->left;
13751384
}
1376-
return NULL;
1385+
out:
1386+
if (exact_match)
1387+
return NULL;
1388+
else
1389+
return prev;
13771390
}
13781391

13791392
struct fib6_node *fib6_locate(struct fib6_node *root,
13801393
const struct in6_addr *daddr, int dst_len,
1381-
const struct in6_addr *saddr, int src_len)
1394+
const struct in6_addr *saddr, int src_len,
1395+
bool exact_match)
13821396
{
13831397
struct fib6_node *fn;
13841398

13851399
fn = fib6_locate_1(root, daddr, dst_len,
1386-
offsetof(struct rt6_info, rt6i_dst));
1400+
offsetof(struct rt6_info, rt6i_dst),
1401+
exact_match);
13871402

13881403
#ifdef CONFIG_IPV6_SUBTREES
13891404
if (src_len) {
13901405
WARN_ON(saddr == NULL);
13911406
if (fn && fn->subtree)
13921407
fn = fib6_locate_1(fn->subtree, saddr, src_len,
1393-
offsetof(struct rt6_info, rt6i_src));
1408+
offsetof(struct rt6_info, rt6i_src),
1409+
exact_match);
13941410
}
13951411
#endif
13961412

net/ipv6/route.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2800,7 +2800,8 @@ static int ip6_route_del(struct fib6_config *cfg,
28002800

28012801
fn = fib6_locate(&table->tb6_root,
28022802
&cfg->fc_dst, cfg->fc_dst_len,
2803-
&cfg->fc_src, cfg->fc_src_len);
2803+
&cfg->fc_src, cfg->fc_src_len,
2804+
true);
28042805

28052806
if (fn) {
28062807
for (rt = fn->leaf; rt; rt = rt->dst.rt6_next) {
@@ -3009,7 +3010,7 @@ static struct rt6_info *rt6_get_route_info(struct net *net,
30093010
return NULL;
30103011

30113012
read_lock_bh(&table->tb6_lock);
3012-
fn = fib6_locate(&table->tb6_root, prefix, prefixlen, NULL, 0);
3013+
fn = fib6_locate(&table->tb6_root, prefix, prefixlen, NULL, 0, true);
30133014
if (!fn)
30143015
goto out;
30153016

0 commit comments

Comments
 (0)