]> git.puffer.fish Git - mirror/frr.git/commitdiff
zebra: Use built in list handler for route entries now 4242/head
authorDonald Sharp <sharpd@cumulusnetworks.com>
Thu, 2 May 2019 20:57:03 +0000 (16:57 -0400)
committerDonald Sharp <sharpd@cumulusnetworks.com>
Thu, 2 May 2019 21:41:35 +0000 (17:41 -0400)
The route entry code was using a custom linked list to handle
route entries.  Remove and replace with the new lib link list
code.  This reduces the size of the route entry by a further
8 bytes.

Observant people will notice that the current linked list
implementation is singly linked, while the Route Entry
is doubly linked.  I am not terribly concerned about this
change as that 1) we do not see a large number of route
entries per prefix( say 2 maybe 3 items ) and route entries
do not come and go that often.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
zebra/rib.h
zebra/zebra_rib.c

index fd2aeabf57d7c4109bf3ee9fc997ac70a0fc1ef4..8a59cea6d0d5a7000c3999958c4d4faf0de0a93f 100644 (file)
@@ -81,10 +81,11 @@ struct rnh {
 #define DISTANCE_INFINITY  255
 #define ZEBRA_KERNEL_TABLE_MAX 252 /* support for no more than this rt tables */
 
+PREDECL_LIST(re_list)
+
 struct route_entry {
        /* Link list. */
-       struct route_entry *next;
-       struct route_entry *prev;
+       struct re_list_item next;
 
        /* Nexthop structure */
        struct nexthop_group ng;
@@ -174,7 +175,7 @@ typedef struct rib_dest_t_ {
        /*
         * Doubly-linked list of routes for this prefix.
         */
-       struct route_entry *routes;
+       struct re_list_head routes;
 
        struct route_entry *selected_fib;
 
@@ -200,6 +201,7 @@ typedef struct rib_dest_t_ {
 } rib_dest_t;
 
 DECLARE_LIST(rnh_list, struct rnh, rnh_list_item);
+DECLARE_LIST(re_list, struct route_entry, next);
 
 #define RIB_ROUTE_QUEUED(x)    (1 << (x))
 // If MQ_SIZE is modified this value needs to be updated.
@@ -228,14 +230,16 @@ DECLARE_LIST(rnh_list, struct rnh, rnh_list_item);
  * Macro to iterate over each route for a destination (prefix).
  */
 #define RE_DEST_FOREACH_ROUTE(dest, re)                                        \
-       for ((re) = (dest) ? (dest)->routes : NULL; (re); (re) = (re)->next)
+       for ((re) = (dest) ? re_list_first(&((dest)->routes)) : NULL; (re);    \
+            (re) = re_list_next(&((dest)->routes), (re)))
 
 /*
  * Same as above, but allows the current node to be unlinked.
  */
 #define RE_DEST_FOREACH_ROUTE_SAFE(dest, re, next)                             \
-       for ((re) = (dest) ? (dest)->routes : NULL;                            \
-            (re) && ((next) = (re)->next, 1); (re) = (next))
+       for ((re) = (dest) ? re_list_first(&((dest)->routes)) : NULL;          \
+            (re) && ((next) = re_list_next(&((dest)->routes), (re)), 1);      \
+            (re) = (next))
 
 #define RNODE_FOREACH_RE(rn, re)                                               \
        RE_DEST_FOREACH_ROUTE (rib_dest_from_rnode(rn), re)
@@ -447,7 +451,7 @@ static inline struct route_entry *rnode_to_ribs(struct route_node *rn)
        if (!dest)
                return NULL;
 
-       return dest->routes;
+       return re_list_first(&dest->routes);
 }
 
 /*
index f5ba619afa9b1384d8940e0b12d09a30de4d7846..412d9b520cf402176911278d99ced2c285bcbbba 100644 (file)
@@ -1176,7 +1176,7 @@ static void rib_uninstall(struct route_node *rn, struct route_entry *re)
  */
 static int rib_can_delete_dest(rib_dest_t *dest)
 {
-       if (dest->routes) {
+       if (re_list_first(&dest->routes)) {
                return 0;
        }
 
@@ -2404,7 +2404,6 @@ rib_dest_t *zebra_rib_create_dest(struct route_node *rn)
 /* Add RE to head of the route node. */
 static void rib_link(struct route_node *rn, struct route_entry *re, int process)
 {
-       struct route_entry *head;
        rib_dest_t *dest;
        afi_t afi;
        const char *rmap_name;
@@ -2419,12 +2418,7 @@ static void rib_link(struct route_node *rn, struct route_entry *re, int process)
                dest = zebra_rib_create_dest(rn);
        }
 
-       head = dest->routes;
-       if (head) {
-               head->prev = re;
-       }
-       re->next = head;
-       dest->routes = re;
+       re_list_add_head(&dest->routes, re);
 
        afi = (rn->p.family == AF_INET)
                      ? AFI_IP
@@ -2474,14 +2468,7 @@ void rib_unlink(struct route_node *rn, struct route_entry *re)
 
        dest = rib_dest_from_rnode(rn);
 
-       if (re->next)
-               re->next->prev = re->prev;
-
-       if (re->prev)
-               re->prev->next = re->next;
-       else {
-               dest->routes = re->next;
-       }
+       re_list_del(&dest->routes, re);
 
        if (dest->selected_fib == re)
                dest->selected_fib = NULL;