]> git.proxmox.com Git - mirror_frr.git/commitdiff
nhrpd: convert nhs list to DLIST
authorDavid Lamparter <equinox@diac24.net>
Sat, 27 Mar 2021 21:30:51 +0000 (22:30 +0100)
committerDavid Lamparter <equinox@opensourcerouting.org>
Tue, 19 Oct 2021 12:55:39 +0000 (14:55 +0200)
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
nhrpd/nhrp_interface.c
nhrpd/nhrp_nhs.c
nhrpd/nhrp_vty.c
nhrpd/nhrpd.h

index 7597526f736f19125485cd102078164faa91419b..0211bdd50b9d28d5311569365ba72a61b05b06e9 100644 (file)
@@ -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);
        }
 
index 5179f15ebf8504f65f88efa5983336676f26d016..53c3be4c1aecd914a1e9c582af495115946b6008 100644 (file)
@@ -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,
-                                                   &reg->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,
+                                                  &reg->peer->vc->remote.nbma))
+                                       return 1;
                        }
                }
        }
index 50161dae2fc39735add099c593627d5a48f0af65..c6f9a172589cfa4581085c1ed7d4f349734979a4 100644 (file)
@@ -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)
index e88a4576fb6b4d46d15835c55e3ae33272727c6a..7e4a86cd5521b06461f8d78e302a338c166e10b6 100644 (file)
@@ -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 *,