From b4f3d41bfd3d595c28a084a90fc78540adb0c4b4 Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Sat, 27 Mar 2021 22:41:44 +0100 Subject: [PATCH] nhrpd: convert SA list to DLIST Signed-off-by: David Lamparter --- nhrpd/nhrp_vc.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/nhrpd/nhrp_vc.c b/nhrpd/nhrp_vc.c index b5de0e91c4..4b45389dad 100644 --- a/nhrpd/nhrp_vc.c +++ b/nhrpd/nhrp_vc.c @@ -19,14 +19,18 @@ DEFINE_MTYPE_STATIC(NHRPD, NHRP_VC, "NHRP virtual connection"); +PREDECL_DLIST(childlist); + struct child_sa { uint32_t id; struct nhrp_vc *vc; - struct list_head childlist_entry; + struct childlist_item childlist_entry; }; +DECLARE_DLIST(childlist, struct child_sa, childlist_entry); + static struct hash *nhrp_vc_hash; -static struct list_head childlist_head[512]; +static struct childlist_head childlist_head[512]; static unsigned int nhrp_vc_key(const void *peer_data) { @@ -104,8 +108,7 @@ int nhrp_vc_ipsec_updown(uint32_t child_id, struct nhrp_vc *vc) uint32_t child_hash = child_id % array_size(childlist_head); int abort_migration = 0; - list_for_each_entry(lsa, &childlist_head[child_hash], childlist_entry) - { + frr_each (childlist, &childlist_head[child_hash], lsa) { if (lsa->id == child_id) { sa = lsa; break; @@ -120,12 +123,9 @@ int nhrp_vc_ipsec_updown(uint32_t child_id, struct nhrp_vc *vc) *sa = (struct child_sa){ .id = child_id, - .childlist_entry = - LIST_INITIALIZER(sa->childlist_entry), .vc = NULL, }; - list_add_tail(&sa->childlist_entry, - &childlist_head[child_hash]); + childlist_add_tail(&childlist_head[child_hash], sa); } if (sa->vc == vc) @@ -155,7 +155,7 @@ int nhrp_vc_ipsec_updown(uint32_t child_id, struct nhrp_vc *vc) /* Update */ sa->vc = vc; if (!vc) { - list_del(&sa->childlist_entry); + childlist_del(&childlist_head[child_hash], sa); XFREE(MTYPE_NHRP_VC, sa); } @@ -200,17 +200,16 @@ void nhrp_vc_init(void) nhrp_vc_hash = hash_create(nhrp_vc_key, nhrp_vc_cmp, "NHRP VC hash"); for (i = 0; i < array_size(childlist_head); i++) - list_init(&childlist_head[i]); + childlist_init(&childlist_head[i]); } void nhrp_vc_reset(void) { - struct child_sa *sa, *n; + struct child_sa *sa; size_t i; for (i = 0; i < array_size(childlist_head); i++) { - list_for_each_entry_safe(sa, n, &childlist_head[i], - childlist_entry) + frr_each_safe (childlist, &childlist_head[i], sa) nhrp_vc_ipsec_updown(sa->id, 0); } } -- 2.39.5