nhrpd: convert notifier list to DLIST

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
This commit is contained in:
David Lamparter 2021-03-27 22:20:10 +01:00 committed by David Lamparter
parent e1111c5faf
commit 865bf787fa
5 changed files with 30 additions and 18 deletions

View File

@ -315,7 +315,7 @@ static void nhrp_cache_peer_notifier(struct notifier_block *n,
static void nhrp_cache_reset_new(struct nhrp_cache *c) static void nhrp_cache_reset_new(struct nhrp_cache *c)
{ {
THREAD_OFF(c->t_auth); THREAD_OFF(c->t_auth);
if (list_hashed(&c->newpeer_notifier.notifier_entry)) if (notifier_list_anywhere(&c->newpeer_notifier))
nhrp_peer_notify_del(c->new.peer, &c->newpeer_notifier); nhrp_peer_notify_del(c->new.peer, &c->newpeer_notifier);
nhrp_peer_unref(c->new.peer); nhrp_peer_unref(c->new.peer);
memset(&c->new, 0, sizeof(c->new)); memset(&c->new, 0, sizeof(c->new));
@ -574,5 +574,5 @@ void nhrp_cache_notify_add(struct nhrp_cache *c, struct notifier_block *n,
void nhrp_cache_notify_del(struct nhrp_cache *c, struct notifier_block *n) void nhrp_cache_notify_del(struct nhrp_cache *c, struct notifier_block *n)
{ {
notifier_del(n); notifier_del(n, &c->notifier_list);
} }

View File

@ -224,8 +224,12 @@ void nhrp_interface_update_nbma(struct interface *ifp,
nbmanifp = nbmaifp->info; nbmanifp = nbmaifp->info;
if (nbmaifp != nifp->nbmaifp) { if (nbmaifp != nifp->nbmaifp) {
if (nifp->nbmaifp) if (nifp->nbmaifp) {
notifier_del(&nifp->nbmanifp_notifier); struct nhrp_interface *prev_nifp = nifp->nbmaifp->info;
notifier_del(&nifp->nbmanifp_notifier,
&prev_nifp->notifier_list);
}
nifp->nbmaifp = nbmaifp; nifp->nbmaifp = nbmaifp;
if (nbmaifp) { if (nbmaifp) {
notifier_add(&nifp->nbmanifp_notifier, notifier_add(&nifp->nbmanifp_notifier,
@ -509,12 +513,15 @@ void nhrp_interface_notify_add(struct interface *ifp, struct notifier_block *n,
notifier_fn_t fn) notifier_fn_t fn)
{ {
struct nhrp_interface *nifp = ifp->info; struct nhrp_interface *nifp = ifp->info;
notifier_add(n, &nifp->notifier_list, fn); notifier_add(n, &nifp->notifier_list, fn);
} }
void nhrp_interface_notify_del(struct interface *ifp, struct notifier_block *n) void nhrp_interface_notify_del(struct interface *ifp, struct notifier_block *n)
{ {
notifier_del(n); struct nhrp_interface *nifp = ifp->info;
notifier_del(n, &nifp->notifier_list);
} }
void nhrp_interface_set_protection(struct interface *ifp, const char *profile, void nhrp_interface_set_protection(struct interface *ifp, const char *profile,

View File

@ -359,7 +359,7 @@ void nhrp_peer_notify_add(struct nhrp_peer *p, struct notifier_block *n,
void nhrp_peer_notify_del(struct nhrp_peer *p, struct notifier_block *n) void nhrp_peer_notify_del(struct nhrp_peer *p, struct notifier_block *n)
{ {
notifier_del(n); notifier_del(n, &p->notifier_list);
nhrp_peer_check_delete(p); nhrp_peer_check_delete(p);
} }

View File

@ -170,7 +170,7 @@ void nhrp_vc_notify_add(struct nhrp_vc *vc, struct notifier_block *n,
void nhrp_vc_notify_del(struct nhrp_vc *vc, struct notifier_block *n) void nhrp_vc_notify_del(struct nhrp_vc *vc, struct notifier_block *n)
{ {
notifier_del(n); notifier_del(n, &vc->notifier_list);
nhrp_vc_check_delete(vc); nhrp_vc_check_delete(vc);
} }

View File

@ -42,48 +42,53 @@ struct notifier_block;
typedef void (*notifier_fn_t)(struct notifier_block *, unsigned long); typedef void (*notifier_fn_t)(struct notifier_block *, unsigned long);
PREDECL_DLIST(notifier_list);
struct notifier_block { struct notifier_block {
struct list_head notifier_entry; struct notifier_list_item notifier_entry;
notifier_fn_t action; notifier_fn_t action;
}; };
DECLARE_DLIST(notifier_list, struct notifier_block, notifier_entry);
struct notifier_list { struct notifier_list {
struct list_head notifier_head; struct notifier_list_head head;
}; };
#define NOTIFIER_LIST_INITIALIZER(l) \ #define NOTIFIER_LIST_INITIALIZER(l) \
{ \ { \
.notifier_head = LIST_INITIALIZER((l)->notifier_head) \ .head = INIT_DLIST((l)->head) \
} }
static inline void notifier_init(struct notifier_list *l) static inline void notifier_init(struct notifier_list *l)
{ {
list_init(&l->notifier_head); notifier_list_init(&l->head);
} }
static inline void notifier_add(struct notifier_block *n, static inline void notifier_add(struct notifier_block *n,
struct notifier_list *l, notifier_fn_t action) struct notifier_list *l, notifier_fn_t action)
{ {
n->action = action; n->action = action;
list_add_tail(&n->notifier_entry, &l->notifier_head); notifier_list_add_tail(&l->head, n);
} }
static inline void notifier_del(struct notifier_block *n) static inline void notifier_del(struct notifier_block *n,
struct notifier_list *l)
{ {
list_del(&n->notifier_entry); notifier_list_del(&l->head, n);
} }
static inline void notifier_call(struct notifier_list *l, int cmd) static inline void notifier_call(struct notifier_list *l, int cmd)
{ {
struct notifier_block *n, *nn; struct notifier_block *n;
list_for_each_entry_safe(n, nn, &l->notifier_head, notifier_entry) {
frr_each_safe (notifier_list, &l->head, n)
n->action(n, cmd); n->action(n, cmd);
}
} }
static inline int notifier_active(struct notifier_list *l) static inline int notifier_active(struct notifier_list *l)
{ {
return !list_empty(&l->notifier_head); return notifier_list_count(&l->head) > 0;
} }
extern struct hash *nhrp_gre_list; extern struct hash *nhrp_gre_list;