From: David Lamparter Date: Tue, 6 May 2014 17:21:51 +0000 (+0200) Subject: lib: add route_node_lookup_maynull X-Git-Tag: frr-3.0-branchpoint~59^2~7 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=61cdc88971be14970d2d9ce56275387a246ac1c3;p=matthieu%2Ffrr.git lib: add route_node_lookup_maynull The sourcedest code needs to get the route_node even if its info pointer is NULL (which occurs when there are srcdest routes, but no general destination route.) Signed-off-by: David Lamparter --- diff --git a/lib/table.c b/lib/table.c index 7335b2a817..f80f3e81f0 100644 --- a/lib/table.c +++ b/lib/table.c @@ -286,6 +286,28 @@ route_node_lookup (const struct route_table *table, const struct prefix *p) return NULL; } +/* Lookup same prefix node. Return NULL when we can't find route. */ +struct route_node * +route_node_lookup_maynull (const struct route_table *table, const struct prefix *p) +{ + struct route_node *node; + u_char prefixlen = p->prefixlen; + const u_char *prefix = &p->u.prefix; + + node = table->top; + + while (node && node->p.prefixlen <= prefixlen && + prefix_match (&node->p, p)) + { + if (node->p.prefixlen == prefixlen) + return route_lock_node (node); + + node = node->link[prefix_bit(prefix, node->p.prefixlen)]; + } + + return NULL; +} + /* Add node to routing table. */ struct route_node * route_node_get (struct route_table *const table, const struct prefix *p) diff --git a/lib/table.h b/lib/table.h index 5f3eb8de37..e35e55dc1c 100644 --- a/lib/table.h +++ b/lib/table.h @@ -157,6 +157,8 @@ extern struct route_node *route_node_get (struct route_table *const, const struct prefix *); extern struct route_node *route_node_lookup (const struct route_table *, const struct prefix *); +extern struct route_node *route_node_lookup_maynull (const struct route_table *, + const struct prefix *); extern struct route_node *route_lock_node (struct route_node *node); extern struct route_node *route_node_match (const struct route_table *, const struct prefix *);