]> git.proxmox.com Git - mirror_frr.git/blobdiff - lib/table.c
isisd: implemented the 'sequence-number-skipped' notification
[mirror_frr.git] / lib / table.c
index 007d41778ea821d1f4a4d5b1ce71791ab3e76d8d..0026b7692be758f4fa8c922aee9aaf1b4c67cea2 100644 (file)
 #include "table.h"
 #include "memory.h"
 #include "sockunion.h"
-#include "jhash.h"
 
 DEFINE_MTYPE(LIB, ROUTE_TABLE, "Route table")
 DEFINE_MTYPE(LIB, ROUTE_NODE, "Route node")
 
-static void route_node_delete(struct route_node *);
 static void route_table_free(struct route_table *);
 
-static unsigned route_table_hash_key(void *pp)
-{
-       struct prefix copy;
-
-       /* make sure *all* unused bits are zero, particularly including
-        * alignment /
-        * padding and unused prefix bytes. */
-       memset(&copy, 0, sizeof(copy));
-       prefix_copy(&copy, (struct prefix *)pp);
-       return jhash(&copy, sizeof(copy), 0x55aa5a5a);
-}
-
-static int route_table_hash_cmp(const void *a, const void *b)
+static bool route_table_hash_cmp(const void *a, const void *b)
 {
        const struct prefix *pa = a, *pb = b;
        return prefix_cmp(pa, pb) == 0;
@@ -63,7 +49,7 @@ route_table_init_with_delegate(route_table_delegate_t *delegate)
 
        rt = XCALLOC(MTYPE_ROUTE_TABLE, sizeof(struct route_table));
        rt->delegate = delegate;
-       rt->hash = hash_create(route_table_hash_key, route_table_hash_cmp,
+       rt->hash = hash_create(prefix_hash_key, route_table_hash_cmp,
                               "route table hash");
        return rt;
 }
@@ -88,7 +74,6 @@ static struct route_node *route_node_set(struct route_table *table,
        node = route_node_new(table);
 
        prefix_copy(&node->p, prefix);
-       apply_mask(&node->p);
        node->table = table;
 
        inserted = hash_get(node->table->hash, node, hash_alloc_intern);
@@ -157,20 +142,26 @@ static void route_table_free(struct route_table *rt)
 }
 
 /* Utility mask array. */
-static const u_char maskbit[] = {0x00, 0x80, 0xc0, 0xe0, 0xf0,
-                                0xf8, 0xfc, 0xfe, 0xff};
+static const uint8_t maskbit[] = {0x00, 0x80, 0xc0, 0xe0, 0xf0,
+                                 0xf8, 0xfc, 0xfe, 0xff};
 
 /* Common prefix route genaration. */
 static void route_common(const struct prefix *n, const struct prefix *p,
                         struct prefix *new)
 {
        int i;
-       u_char diff;
-       u_char mask;
+       uint8_t diff;
+       uint8_t mask;
+       const uint8_t *np;
+       const uint8_t *pp;
+       uint8_t *newp;
 
-       const u_char *np = (const u_char *)&n->u.prefix;
-       const u_char *pp = (const u_char *)&p->u.prefix;
-       u_char *newp = (u_char *)&new->u.prefix;
+       if (n->family == AF_FLOWSPEC)
+               return prefix_copy(new, p);
+       np = (const uint8_t *)&n->u.prefix;
+       pp = (const uint8_t *)&p->u.prefix;
+
+       newp = (uint8_t *)&new->u.prefix;
 
        for (i = 0; i < p->prefixlen / 8; i++) {
                if (np[i] == pp[i])
@@ -200,23 +191,6 @@ static void set_link(struct route_node *node, struct route_node *new)
        new->parent = node;
 }
 
-/* Lock node. */
-struct route_node *route_lock_node(struct route_node *node)
-{
-       node->lock++;
-       return node;
-}
-
-/* Unlock node. */
-void route_unlock_node(struct route_node *node)
-{
-       assert(node->lock > 0);
-       node->lock--;
-
-       if (node->lock == 0)
-               route_node_delete(node);
-}
-
 /* Find matched prefix. */
 struct route_node *route_node_match(const struct route_table *table,
                                    union prefixconstptr pu)
@@ -309,9 +283,10 @@ struct route_node *route_node_get(struct route_table *const table,
        struct route_node *node;
        struct route_node *match;
        struct route_node *inserted;
-       u_char prefixlen = p->prefixlen;
-       const u_char *prefix = &p->u.prefix;
+       uint8_t prefixlen = p->prefixlen;
+       const uint8_t *prefix = &p->u.prefix;
 
+       apply_mask((struct prefix *)p);
        node = hash_get(table->hash, (void *)p, NULL);
        if (node && node->info)
                return route_lock_node(node);
@@ -361,7 +336,7 @@ struct route_node *route_node_get(struct route_table *const table,
 }
 
 /* Delete node from the routing table. */
-static void route_node_delete(struct route_node *node)
+void route_node_delete(struct route_node *node)
 {
        struct route_node *child;
        struct route_node *parent;