|
/* Lookup a node
with a prefix with given length, and
the first bits
matching our prefix p.
Multiple
matchings are not supported.*/
struct route_node *
route_node_lookup_partial
(struct route_table *table, struct prefix *p, u_char length)
{
struct route_node *node;
node = table->top;
if (p->prefixlen > length )
return NULL;
while (( node
&& node->p.prefixlen
<= length )
&& ( /* in prefix_match the former prefix
must be shorter than the latter */
( node->p.prefixlen <=
p->prefixlen && prefix_match (&node->p, p) )
|| ( node->p.prefixlen >
p->prefixlen && prefix_match (p, &node->p) )
)
)
{
if (node->p.prefixlen == length
&& node->info)
{
return route_lock_node (node);
}
if (node->p.prefixlen <
p->prefixlen)
node =
node->link[check_bit(&p->u.prefix, node->p.prefixlen)];
else if (node->p.prefixlen >=
p->prefixlen)
{ /* here we've found a node
with the first bits matching our prefix, but
the node has NULL info,
or has a too short preefix.
That mean that
there are multiple matching...
If we are looking
into the Network Database, this shouldn't happen!
However go on
searching, taking the first non-NULL link, and good luck */
if (
(node = node->link[0]) == NULL ) node = node->link[1];
}
}
return NULL;
}
|