]> git.puffer.fish Git - matthieu/frr.git/commitdiff
lib: add route_node_lookup_maynull
authorDavid Lamparter <equinox@opensourcerouting.org>
Tue, 6 May 2014 17:21:51 +0000 (19:21 +0200)
committerChristian Franke <chris@opensourcerouting.org>
Mon, 30 Jan 2017 12:47:04 +0000 (13:47 +0100)
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 <equinox@opensourcerouting.org>
lib/table.c
lib/table.h

index 7335b2a81711226759c5e6a6bcbe04eaa2a93160..f80f3e81f056bafe675b0a55a4db44a2cd6ff3a9 100644 (file)
@@ -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)
index 5f3eb8de376aa0a737d7ae908a8075c4c07e2aab..e35e55dc1c9698f92d146d8f5e485d9f7a26d090 100644 (file)
@@ -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 *);