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 /nhrpd/nhrp_nhs.c | |
| parent | 865bf787fa1213fe62d8747953c1a612b42a3984 (diff) | |
nhrpd: convert nhs list to DLIST
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
Diffstat (limited to 'nhrpd/nhrp_nhs.c')
| -rw-r--r-- | nhrpd/nhrp_nhs.c | 62 | 
1 files changed, 25 insertions, 37 deletions
diff --git a/nhrpd/nhrp_nhs.c b/nhrpd/nhrp_nhs.c index 5179f15ebf..53c3be4c1a 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;  			}  		}  	}  | 
