diff options
author | David Lamparter <equinox@diac24.net> | 2021-03-27 22:30:51 +0100 |
---|---|---|
committer | David Lamparter <equinox@opensourcerouting.org> | 2021-10-19 14:55:39 +0200 |
commit | 2ab2a7610131d0d12a4361f851c3e742b058ddd4 (patch) | |
tree | 00e480b6144a49b71f721489a194dff200cab73a | |
parent | nhrpd: convert notifier list to DLIST (diff) | |
download | frr-2ab2a7610131d0d12a4361f851c3e742b058ddd4.tar.xz frr-2ab2a7610131d0d12a4361f851c3e742b058ddd4.zip |
nhrpd: convert nhs list to DLIST
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
-rw-r--r-- | nhrpd/nhrp_interface.c | 2 | ||||
-rw-r--r-- | nhrpd/nhrp_nhs.c | 62 | ||||
-rw-r--r-- | nhrpd/nhrp_vty.c | 4 | ||||
-rw-r--r-- | nhrpd/nhrpd.h | 10 |
4 files changed, 34 insertions, 44 deletions
diff --git a/nhrpd/nhrp_interface.c b/nhrpd/nhrp_interface.c index 7597526f7..0211bdd50 100644 --- a/nhrpd/nhrp_interface.c +++ b/nhrpd/nhrp_interface.c @@ -79,7 +79,7 @@ static int nhrp_if_new_hook(struct interface *ifp) for (afi = 0; afi < AFI_MAX; afi++) { struct nhrp_afi_data *ad = &nifp->afi[afi]; ad->holdtime = NHRPD_DEFAULT_HOLDTIME; - list_init(&ad->nhslist_head); + nhrp_nhslist_init(&ad->nhslist_head); list_init(&ad->mcastlist_head); } diff --git a/nhrpd/nhrp_nhs.c b/nhrpd/nhrp_nhs.c index 5179f15eb..53c3be4c1 100644 --- a/nhrpd/nhrp_nhs.c +++ b/nhrpd/nhrp_nhs.c @@ -344,8 +344,7 @@ int nhrp_nhs_add(struct interface *ifp, afi_t afi, union sockunion *proto_addr, && sockunion_family(proto_addr) != afi2family(afi)) return NHRP_ERR_PROTOCOL_ADDRESS_MISMATCH; - list_for_each_entry(nhs, &nifp->afi[afi].nhslist_head, nhslist_entry) - { + frr_each (nhrp_nhslist, &nifp->afi[afi].nhslist_head, nhs) { if (sockunion_family(&nhs->proto_addr) != AF_UNSPEC && sockunion_family(proto_addr) != AF_UNSPEC && sockunion_same(&nhs->proto_addr, proto_addr)) @@ -364,7 +363,7 @@ int nhrp_nhs_add(struct interface *ifp, afi_t afi, union sockunion *proto_addr, .nbma_fqdn = strdup(nbma_fqdn), .reglist_head = LIST_INITIALIZER(nhs->reglist_head), }; - list_add_tail(&nhs->nhslist_entry, &nifp->afi[afi].nhslist_head); + nhrp_nhslist_add_tail(&nifp->afi[afi].nhslist_head, nhs); thread_add_timer_msec(master, nhrp_nhs_resolve, nhs, 1000, &nhs->t_resolve); @@ -375,36 +374,34 @@ int nhrp_nhs_del(struct interface *ifp, afi_t afi, union sockunion *proto_addr, const char *nbma_fqdn) { struct nhrp_interface *nifp = ifp->info; - struct nhrp_nhs *nhs, *nnhs; + struct nhrp_nhs *nhs; int ret = NHRP_ERR_ENTRY_NOT_FOUND; if (sockunion_family(proto_addr) != AF_UNSPEC && sockunion_family(proto_addr) != afi2family(afi)) return NHRP_ERR_PROTOCOL_ADDRESS_MISMATCH; - list_for_each_entry_safe(nhs, nnhs, &nifp->afi[afi].nhslist_head, - nhslist_entry) - { + frr_each_safe (nhrp_nhslist, &nifp->afi[afi].nhslist_head, nhs) { if (!sockunion_same(&nhs->proto_addr, proto_addr)) continue; if (strcmp(nhs->nbma_fqdn, nbma_fqdn) != 0) continue; - nhrp_nhs_free(nhs); + nhrp_nhs_free(nifp, afi, nhs); ret = NHRP_OK; } return ret; } -int nhrp_nhs_free(struct nhrp_nhs *nhs) +int nhrp_nhs_free(struct nhrp_interface *nifp, afi_t afi, struct nhrp_nhs *nhs) { struct nhrp_registration *r, *rn; list_for_each_entry_safe(r, rn, &nhs->reglist_head, reglist_entry) nhrp_reg_delete(r); THREAD_OFF(nhs->t_resolve); - list_del(&nhs->nhslist_entry); + nhrp_nhslist_del(&nifp->afi[afi].nhslist_head, nhs); free((void *)nhs->nbma_fqdn); XFREE(MTYPE_NHRP_NHS, nhs); return 0; @@ -413,18 +410,15 @@ int nhrp_nhs_free(struct nhrp_nhs *nhs) void nhrp_nhs_interface_del(struct interface *ifp) { struct nhrp_interface *nifp = ifp->info; - struct nhrp_nhs *nhs, *tmp; + struct nhrp_nhs *nhs; afi_t afi; for (afi = 0; afi < AFI_MAX; afi++) { - debugf(NHRP_DEBUG_COMMON, "Cleaning up nhs entries (%d)", - !list_empty(&nifp->afi[afi].nhslist_head)); + debugf(NHRP_DEBUG_COMMON, "Cleaning up nhs entries (%zu)", + nhrp_nhslist_count(&nifp->afi[afi].nhslist_head)); - list_for_each_entry_safe(nhs, tmp, &nifp->afi[afi].nhslist_head, - nhslist_entry) - { - nhrp_nhs_free(nhs); - } + frr_each_safe (nhrp_nhslist, &nifp->afi[afi].nhslist_head, nhs) + nhrp_nhs_free(nifp, afi, nhs); } } @@ -433,15 +427,15 @@ void nhrp_nhs_terminate(void) struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT); struct interface *ifp; struct nhrp_interface *nifp; - struct nhrp_nhs *nhs, *tmp; + struct nhrp_nhs *nhs; afi_t afi; FOR_ALL_INTERFACES (vrf, ifp) { nifp = ifp->info; for (afi = 0; afi < AFI_MAX; afi++) { - list_for_each_entry_safe( - nhs, tmp, &nifp->afi[afi].nhslist_head, - nhslist_entry) nhrp_nhs_free(nhs); + frr_each_safe (nhrp_nhslist, + &nifp->afi[afi].nhslist_head, nhs) + nhrp_nhs_free(nifp, afi, nhs); } } } @@ -455,8 +449,7 @@ void nhrp_nhs_foreach(struct interface *ifp, afi_t afi, struct nhrp_nhs *nhs; struct nhrp_registration *reg; - list_for_each_entry(nhs, &nifp->afi[afi].nhslist_head, nhslist_entry) - { + frr_each (nhrp_nhslist, &nifp->afi[afi].nhslist_head, nhs) { if (!list_empty(&nhs->reglist_head)) { list_for_each_entry(reg, &nhs->reglist_head, reglist_entry) cb(nhs, reg, ctx); @@ -472,19 +465,14 @@ int nhrp_nhs_match_ip(union sockunion *in_ip, struct nhrp_interface *nifp) struct nhrp_registration *reg; for (i = 0; i < AFI_MAX; i++) { - list_for_each_entry(nhs, &nifp->afi[i].nhslist_head, - nhslist_entry) - { - if (!list_empty(&nhs->reglist_head)) { - list_for_each_entry(reg, &nhs->reglist_head, - reglist_entry) - { - if (!sockunion_cmp( - in_ip, - ®->peer->vc->remote - .nbma)) - return 1; - } + frr_each (nhrp_nhslist, &nifp->afi[i].nhslist_head, nhs) { + if (!nhrp_reglist_count(&nhs->reglist_head)) + continue; + + frr_each (nhrp_reglist, &nhs->reglist_head, reg) { + if (!sockunion_cmp(in_ip, + ®->peer->vc->remote.nbma)) + return 1; } } } diff --git a/nhrpd/nhrp_vty.c b/nhrpd/nhrp_vty.c index 50161dae2..c6f9a1725 100644 --- a/nhrpd/nhrp_vty.c +++ b/nhrpd/nhrp_vty.c @@ -1200,9 +1200,7 @@ static int interface_config_write(struct vty *vty) nhrp_cache_config_foreach( ifp, interface_config_write_nhrp_map, &mapctx); - list_for_each_entry(nhs, &ad->nhslist_head, - nhslist_entry) - { + frr_each (nhrp_nhslist, &ad->nhslist_head, nhs) { vty_out(vty, " %s nhrp nhs ", aficmd); if (sockunion_family(&nhs->proto_addr) == AF_UNSPEC) diff --git a/nhrpd/nhrpd.h b/nhrpd/nhrpd.h index e88a4576f..7e4a86cd5 100644 --- a/nhrpd/nhrpd.h +++ b/nhrpd/nhrpd.h @@ -268,9 +268,11 @@ struct nhrp_shortcut { struct notifier_block cache_notifier; }; +PREDECL_DLIST(nhrp_nhslist); + struct nhrp_nhs { struct interface *ifp; - struct list_head nhslist_entry; + struct nhrp_nhslist_item nhslist_entry; unsigned hub : 1; afi_t afi; @@ -282,6 +284,8 @@ struct nhrp_nhs { struct list_head reglist_head; }; +DECLARE_DLIST(nhrp_nhslist, struct nhrp_nhs, nhslist_entry); + struct nhrp_multicast { struct interface *ifp; struct list_head list_entry; @@ -335,7 +339,7 @@ struct nhrp_interface { short configured_mtu; unsigned short mtu; unsigned int holdtime; - struct list_head nhslist_head; + struct nhrp_nhslist_head nhslist_head; struct list_head mcastlist_head; } afi[AFI_MAX]; }; @@ -386,7 +390,7 @@ int nhrp_nhs_add(struct interface *ifp, afi_t afi, union sockunion *proto_addr, const char *nbma_fqdn); int nhrp_nhs_del(struct interface *ifp, afi_t afi, union sockunion *proto_addr, const char *nbma_fqdn); -int nhrp_nhs_free(struct nhrp_nhs *nhs); +int nhrp_nhs_free(struct nhrp_interface *nifp, afi_t afi, struct nhrp_nhs *nhs); void nhrp_nhs_terminate(void); void nhrp_nhs_foreach(struct interface *ifp, afi_t afi, void (*cb)(struct nhrp_nhs *, struct nhrp_registration *, |