From 045207e27cef9da81672f2906be9067e4a880568 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Thu, 2 May 2019 16:57:03 -0400 Subject: [PATCH] zebra: Use built in list handler for route entries now 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 --- zebra/rib.h | 18 +++++++++++------- zebra/zebra_rib.c | 19 +++---------------- 2 files changed, 14 insertions(+), 23 deletions(-) diff --git a/zebra/rib.h b/zebra/rib.h index fd2aeabf57..8a59cea6d0 100644 --- a/zebra/rib.h +++ b/zebra/rib.h @@ -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); } /* diff --git a/zebra/zebra_rib.c b/zebra/zebra_rib.c index f5ba619afa..412d9b520c 100644 --- a/zebra/zebra_rib.c +++ b/zebra/zebra_rib.c @@ -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; -- 2.39.5