summaryrefslogtreecommitdiffstats
path: root/zebra
diff options
context:
space:
mode:
authorRenato Westphal <renato@opensourcerouting.org>2019-05-10 13:29:59 +0200
committerGitHub <noreply@github.com>2019-05-10 13:29:59 +0200
commit773fc72b1fb0f4cfb1c2ba6bd5d582aaf62bb4ff (patch)
tree210d18ff239344a50d13b554c67208075aeb314b /zebra
parentMerge pull request #4288 from qlyoung/checkpatch-unsafe-function-lints (diff)
parentzebra: Use built in list handler for route entries now (diff)
downloadfrr-773fc72b1fb0f4cfb1c2ba6bd5d582aaf62bb4ff.tar.xz
frr-773fc72b1fb0f4cfb1c2ba6bd5d582aaf62bb4ff.zip
Merge pull request #4242 from donaldsharp/zebra_diet
Zebra diet
Diffstat (limited to 'zebra')
-rw-r--r--zebra/rib.h61
-rw-r--r--zebra/zebra_rib.c26
-rw-r--r--zebra/zebra_rnh.c6
-rw-r--r--zebra/zebra_rnh.h34
-rw-r--r--zebra/zebra_vrf.c2
5 files changed, 63 insertions, 66 deletions
diff --git a/zebra/rib.h b/zebra/rib.h
index e26831e1a..8a59cea6d 100644
--- a/zebra/rib.h
+++ b/zebra/rib.h
@@ -24,6 +24,7 @@
#include "zebra.h"
#include "hook.h"
+#include "typesafe.h"
#include "linklist.h"
#include "prefix.h"
#include "table.h"
@@ -39,13 +40,52 @@
extern "C" {
#endif
+typedef enum { RNH_NEXTHOP_TYPE, RNH_IMPORT_CHECK_TYPE } rnh_type_t;
+
+PREDECL_LIST(rnh_list)
+
+/* Nexthop structure. */
+struct rnh {
+ uint8_t flags;
+
+#define ZEBRA_NHT_CONNECTED 0x1
+#define ZEBRA_NHT_DELETED 0x2
+#define ZEBRA_NHT_EXACT_MATCH 0x4
+
+ /* VRF identifier. */
+ vrf_id_t vrf_id;
+
+ afi_t afi;
+
+ rnh_type_t type;
+
+ uint32_t seqno;
+
+ struct route_entry *state;
+ struct prefix resolved_route;
+ struct list *client_list;
+
+ /* pseudowires dependent on this nh */
+ struct list *zebra_pseudowire_list;
+
+ struct route_node *node;
+
+ /*
+ * if this has been filtered for the client
+ */
+ int filtered[ZEBRA_ROUTE_MAX];
+
+ struct rnh_list_item rnh_list_item;
+};
+
#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;
@@ -135,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;
@@ -151,7 +191,7 @@ typedef struct rib_dest_t_ {
* the data plane we will run evaluate_rnh
* on these prefixes.
*/
- struct list *nht;
+ struct rnh_list_head nht;
/*
* Linkage to put dest on the FPM processing queue.
@@ -160,6 +200,9 @@ 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.
#define RIB_ROUTE_ANY_QUEUED 0x1F
@@ -187,14 +230,16 @@ typedef struct rib_dest_t_ {
* 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)
@@ -406,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 2945a5ef9..3623852af 100644
--- a/zebra/zebra_rib.c
+++ b/zebra/zebra_rib.c
@@ -1174,7 +1174,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;
}
@@ -1202,7 +1202,6 @@ static int rib_can_delete_dest(rib_dest_t *dest)
void zebra_rib_evaluate_rn_nexthops(struct route_node *rn, uint32_t seq)
{
rib_dest_t *dest = rib_dest_from_rnode(rn);
- struct listnode *node, *nnode;
struct rnh *rnh;
/*
@@ -1234,7 +1233,7 @@ void zebra_rib_evaluate_rn_nexthops(struct route_node *rn, uint32_t seq)
* nht resolution and as such we need to call the
* nexthop tracking evaluation code
*/
- for (ALL_LIST_ELEMENTS(dest->nht, node, nnode, rnh)) {
+ for_each (rnh_list, &dest->nht, rnh) {
struct zebra_vrf *zvrf =
zebra_vrf_lookup_by_id(rnh->vrf_id);
struct prefix *p = &rnh->node->p;
@@ -1310,7 +1309,7 @@ int rib_gc_dest(struct route_node *rn)
zebra_rib_evaluate_rn_nexthops(rn, zebra_router_get_next_sequence());
dest->rnode = NULL;
- list_delete(&dest->nht);
+ rnh_list_fini(&dest->nht);
XFREE(MTYPE_RIB_DEST, dest);
rn->info = NULL;
@@ -2355,7 +2354,7 @@ rib_dest_t *zebra_rib_create_dest(struct route_node *rn)
rib_dest_t *dest;
dest = XCALLOC(MTYPE_RIB_DEST, sizeof(rib_dest_t));
- dest->nht = list_new();
+ rnh_list_init(&dest->nht);
route_lock_node(rn); /* rn route table reference */
rn->info = dest;
dest->rnode = rn;
@@ -2403,7 +2402,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;
@@ -2418,12 +2416,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
@@ -2473,14 +2466,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;
diff --git a/zebra/zebra_rnh.c b/zebra/zebra_rnh.c
index 220a8006d..2917d0e7a 100644
--- a/zebra/zebra_rnh.c
+++ b/zebra/zebra_rnh.c
@@ -119,7 +119,7 @@ static void zebra_rnh_remove_from_routing_table(struct rnh *rnh)
}
dest = rib_dest_from_rnode(rn);
- listnode_delete(dest->nht, rnh);
+ rnh_list_del(&dest->nht, rnh);
route_unlock_node(rn);
}
@@ -145,7 +145,7 @@ static void zebra_rnh_store_in_routing_table(struct rnh *rnh)
}
dest = rib_dest_from_rnode(rn);
- listnode_add(dest->nht, rnh);
+ rnh_list_add_tail(&dest->nht, rnh);
route_unlock_node(rn);
}
@@ -251,7 +251,7 @@ void zebra_free_rnh(struct rnh *rnh)
route_unlock_node(rern);
dest = rib_dest_from_rnode(rern);
- listnode_delete(dest->nht, rnh);
+ rnh_list_del(&dest->nht, rnh);
}
}
free_state(rnh->vrf_id, rnh->state, rnh->node);
diff --git a/zebra/zebra_rnh.h b/zebra/zebra_rnh.h
index 9cd9116ee..95a394118 100644
--- a/zebra/zebra_rnh.h
+++ b/zebra/zebra_rnh.h
@@ -29,40 +29,6 @@
extern "C" {
#endif
-typedef enum { RNH_NEXTHOP_TYPE, RNH_IMPORT_CHECK_TYPE } rnh_type_t;
-
-/* Nexthop structure. */
-struct rnh {
- uint8_t flags;
-
-#define ZEBRA_NHT_CONNECTED 0x1
-#define ZEBRA_NHT_DELETED 0x2
-#define ZEBRA_NHT_EXACT_MATCH 0x4
-
- /* VRF identifier. */
- vrf_id_t vrf_id;
-
- afi_t afi;
-
- rnh_type_t type;
-
- uint32_t seqno;
-
- struct route_entry *state;
- struct prefix resolved_route;
- struct list *client_list;
-
- /* pseudowires dependent on this nh */
- struct list *zebra_pseudowire_list;
-
- struct route_node *node;
-
- /*
- * if this has been filtered for the client
- */
- int filtered[ZEBRA_ROUTE_MAX];
-};
-
extern int zebra_rnh_ip_default_route;
extern int zebra_rnh_ipv6_default_route;
diff --git a/zebra/zebra_vrf.c b/zebra/zebra_vrf.c
index 315d5b490..5a18534ac 100644
--- a/zebra/zebra_vrf.c
+++ b/zebra/zebra_vrf.c
@@ -355,7 +355,7 @@ void zebra_rtable_node_cleanup(struct route_table *table,
if (node->info) {
rib_dest_t *dest = node->info;
- list_delete(&dest->nht);
+ rnh_list_fini(&dest->nht);
XFREE(MTYPE_RIB_DEST, node->info);
}
}