nhrpd: convert nhs list to DLIST

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
This commit is contained in:
David Lamparter 2021-03-27 22:30:51 +01:00 committed by David Lamparter
parent 865bf787fa
commit 2ab2a76101
4 changed files with 34 additions and 44 deletions

View File

@ -79,7 +79,7 @@ static int nhrp_if_new_hook(struct interface *ifp)
for (afi = 0; afi < AFI_MAX; afi++) { for (afi = 0; afi < AFI_MAX; afi++) {
struct nhrp_afi_data *ad = &nifp->afi[afi]; struct nhrp_afi_data *ad = &nifp->afi[afi];
ad->holdtime = NHRPD_DEFAULT_HOLDTIME; ad->holdtime = NHRPD_DEFAULT_HOLDTIME;
list_init(&ad->nhslist_head); nhrp_nhslist_init(&ad->nhslist_head);
list_init(&ad->mcastlist_head); list_init(&ad->mcastlist_head);
} }

View 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)) && sockunion_family(proto_addr) != afi2family(afi))
return NHRP_ERR_PROTOCOL_ADDRESS_MISMATCH; 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 if (sockunion_family(&nhs->proto_addr) != AF_UNSPEC
&& sockunion_family(proto_addr) != AF_UNSPEC && sockunion_family(proto_addr) != AF_UNSPEC
&& sockunion_same(&nhs->proto_addr, proto_addr)) && 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), .nbma_fqdn = strdup(nbma_fqdn),
.reglist_head = LIST_INITIALIZER(nhs->reglist_head), .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, thread_add_timer_msec(master, nhrp_nhs_resolve, nhs, 1000,
&nhs->t_resolve); &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) const char *nbma_fqdn)
{ {
struct nhrp_interface *nifp = ifp->info; struct nhrp_interface *nifp = ifp->info;
struct nhrp_nhs *nhs, *nnhs; struct nhrp_nhs *nhs;
int ret = NHRP_ERR_ENTRY_NOT_FOUND; int ret = NHRP_ERR_ENTRY_NOT_FOUND;
if (sockunion_family(proto_addr) != AF_UNSPEC if (sockunion_family(proto_addr) != AF_UNSPEC
&& sockunion_family(proto_addr) != afi2family(afi)) && sockunion_family(proto_addr) != afi2family(afi))
return NHRP_ERR_PROTOCOL_ADDRESS_MISMATCH; return NHRP_ERR_PROTOCOL_ADDRESS_MISMATCH;
list_for_each_entry_safe(nhs, nnhs, &nifp->afi[afi].nhslist_head, frr_each_safe (nhrp_nhslist, &nifp->afi[afi].nhslist_head, nhs) {
nhslist_entry)
{
if (!sockunion_same(&nhs->proto_addr, proto_addr)) if (!sockunion_same(&nhs->proto_addr, proto_addr))
continue; continue;
if (strcmp(nhs->nbma_fqdn, nbma_fqdn) != 0) if (strcmp(nhs->nbma_fqdn, nbma_fqdn) != 0)
continue; continue;
nhrp_nhs_free(nhs); nhrp_nhs_free(nifp, afi, nhs);
ret = NHRP_OK; ret = NHRP_OK;
} }
return ret; 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; struct nhrp_registration *r, *rn;
list_for_each_entry_safe(r, rn, &nhs->reglist_head, reglist_entry) list_for_each_entry_safe(r, rn, &nhs->reglist_head, reglist_entry)
nhrp_reg_delete(r); nhrp_reg_delete(r);
THREAD_OFF(nhs->t_resolve); THREAD_OFF(nhs->t_resolve);
list_del(&nhs->nhslist_entry); nhrp_nhslist_del(&nifp->afi[afi].nhslist_head, nhs);
free((void *)nhs->nbma_fqdn); free((void *)nhs->nbma_fqdn);
XFREE(MTYPE_NHRP_NHS, nhs); XFREE(MTYPE_NHRP_NHS, nhs);
return 0; return 0;
@ -413,18 +410,15 @@ int nhrp_nhs_free(struct nhrp_nhs *nhs)
void nhrp_nhs_interface_del(struct interface *ifp) void nhrp_nhs_interface_del(struct interface *ifp)
{ {
struct nhrp_interface *nifp = ifp->info; struct nhrp_interface *nifp = ifp->info;
struct nhrp_nhs *nhs, *tmp; struct nhrp_nhs *nhs;
afi_t afi; afi_t afi;
for (afi = 0; afi < AFI_MAX; afi++) { for (afi = 0; afi < AFI_MAX; afi++) {
debugf(NHRP_DEBUG_COMMON, "Cleaning up nhs entries (%d)", debugf(NHRP_DEBUG_COMMON, "Cleaning up nhs entries (%zu)",
!list_empty(&nifp->afi[afi].nhslist_head)); nhrp_nhslist_count(&nifp->afi[afi].nhslist_head));
list_for_each_entry_safe(nhs, tmp, &nifp->afi[afi].nhslist_head, frr_each_safe (nhrp_nhslist, &nifp->afi[afi].nhslist_head, nhs)
nhslist_entry) nhrp_nhs_free(nifp, afi, nhs);
{
nhrp_nhs_free(nhs);
}
} }
} }
@ -433,15 +427,15 @@ void nhrp_nhs_terminate(void)
struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT); struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT);
struct interface *ifp; struct interface *ifp;
struct nhrp_interface *nifp; struct nhrp_interface *nifp;
struct nhrp_nhs *nhs, *tmp; struct nhrp_nhs *nhs;
afi_t afi; afi_t afi;
FOR_ALL_INTERFACES (vrf, ifp) { FOR_ALL_INTERFACES (vrf, ifp) {
nifp = ifp->info; nifp = ifp->info;
for (afi = 0; afi < AFI_MAX; afi++) { for (afi = 0; afi < AFI_MAX; afi++) {
list_for_each_entry_safe( frr_each_safe (nhrp_nhslist,
nhs, tmp, &nifp->afi[afi].nhslist_head, &nifp->afi[afi].nhslist_head, nhs)
nhslist_entry) nhrp_nhs_free(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_nhs *nhs;
struct nhrp_registration *reg; 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)) { if (!list_empty(&nhs->reglist_head)) {
list_for_each_entry(reg, &nhs->reglist_head, list_for_each_entry(reg, &nhs->reglist_head,
reglist_entry) cb(nhs, reg, ctx); reglist_entry) cb(nhs, reg, ctx);
@ -472,21 +465,16 @@ int nhrp_nhs_match_ip(union sockunion *in_ip, struct nhrp_interface *nifp)
struct nhrp_registration *reg; struct nhrp_registration *reg;
for (i = 0; i < AFI_MAX; i++) { for (i = 0; i < AFI_MAX; i++) {
list_for_each_entry(nhs, &nifp->afi[i].nhslist_head, frr_each (nhrp_nhslist, &nifp->afi[i].nhslist_head, nhs) {
nhslist_entry) if (!nhrp_reglist_count(&nhs->reglist_head))
{ continue;
if (!list_empty(&nhs->reglist_head)) {
list_for_each_entry(reg, &nhs->reglist_head, frr_each (nhrp_reglist, &nhs->reglist_head, reg) {
reglist_entry) if (!sockunion_cmp(in_ip,
{ &reg->peer->vc->remote.nbma))
if (!sockunion_cmp(
in_ip,
&reg->peer->vc->remote
.nbma))
return 1; return 1;
} }
} }
} }
}
return 0; return 0;
} }

View File

@ -1200,9 +1200,7 @@ static int interface_config_write(struct vty *vty)
nhrp_cache_config_foreach( nhrp_cache_config_foreach(
ifp, interface_config_write_nhrp_map, &mapctx); ifp, interface_config_write_nhrp_map, &mapctx);
list_for_each_entry(nhs, &ad->nhslist_head, frr_each (nhrp_nhslist, &ad->nhslist_head, nhs) {
nhslist_entry)
{
vty_out(vty, " %s nhrp nhs ", aficmd); vty_out(vty, " %s nhrp nhs ", aficmd);
if (sockunion_family(&nhs->proto_addr) if (sockunion_family(&nhs->proto_addr)
== AF_UNSPEC) == AF_UNSPEC)

View File

@ -268,9 +268,11 @@ struct nhrp_shortcut {
struct notifier_block cache_notifier; struct notifier_block cache_notifier;
}; };
PREDECL_DLIST(nhrp_nhslist);
struct nhrp_nhs { struct nhrp_nhs {
struct interface *ifp; struct interface *ifp;
struct list_head nhslist_entry; struct nhrp_nhslist_item nhslist_entry;
unsigned hub : 1; unsigned hub : 1;
afi_t afi; afi_t afi;
@ -282,6 +284,8 @@ struct nhrp_nhs {
struct list_head reglist_head; struct list_head reglist_head;
}; };
DECLARE_DLIST(nhrp_nhslist, struct nhrp_nhs, nhslist_entry);
struct nhrp_multicast { struct nhrp_multicast {
struct interface *ifp; struct interface *ifp;
struct list_head list_entry; struct list_head list_entry;
@ -335,7 +339,7 @@ struct nhrp_interface {
short configured_mtu; short configured_mtu;
unsigned short mtu; unsigned short mtu;
unsigned int holdtime; unsigned int holdtime;
struct list_head nhslist_head; struct nhrp_nhslist_head nhslist_head;
struct list_head mcastlist_head; struct list_head mcastlist_head;
} afi[AFI_MAX]; } 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); const char *nbma_fqdn);
int nhrp_nhs_del(struct interface *ifp, afi_t afi, union sockunion *proto_addr, int nhrp_nhs_del(struct interface *ifp, afi_t afi, union sockunion *proto_addr,
const char *nbma_fqdn); 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_terminate(void);
void nhrp_nhs_foreach(struct interface *ifp, afi_t afi, void nhrp_nhs_foreach(struct interface *ifp, afi_t afi,
void (*cb)(struct nhrp_nhs *, struct nhrp_registration *, void (*cb)(struct nhrp_nhs *, struct nhrp_registration *,