0
0
mirror of https://gitlab.nic.cz/labs/bird.git synced 2025-03-21 22:07:03 +00:00

Global protocol list is typed to avoid typecast confusion

This commit is contained in:
Maria Matejka 2023-04-19 21:18:12 +02:00
parent 48dfcb60d6
commit 074739e0e9
2 changed files with 31 additions and 27 deletions

View File

@ -23,7 +23,7 @@
#include "filter/f-inst.h" #include "filter/f-inst.h"
pool *proto_pool; pool *proto_pool;
list STATIC_LIST_INIT(proto_list); static TLIST_LIST(proto) global_proto_list;
static list STATIC_LIST_INIT(protocol_list); static list STATIC_LIST_INIT(protocol_list);
@ -1190,7 +1190,7 @@ proto_new(struct proto_config *cf)
} }
static struct proto * static struct proto *
proto_init(struct proto_config *c, node *n) proto_init(struct proto_config *c, struct proto *after)
{ {
struct protocol *pr = c->protocol; struct protocol *pr = c->protocol;
struct proto *p = pr->init(c); struct proto *p = pr->init(c);
@ -1199,7 +1199,7 @@ proto_init(struct proto_config *c, node *n)
p->proto_state = PS_DOWN; p->proto_state = PS_DOWN;
p->last_state_change = current_time(); p->last_state_change = current_time();
p->vrf = c->vrf; p->vrf = c->vrf;
insert_node(&p->n, n); proto_add_after(&global_proto_list, p, after);
p->event = ev_new_init(proto_pool, proto_event, p); p->event = ev_new_init(proto_pool, proto_event, p);
@ -1430,8 +1430,6 @@ protos_commit(struct config *new, struct config *old, int force_reconfig, int ty
struct proto_config *oc, *nc; struct proto_config *oc, *nc;
struct symbol *sym; struct symbol *sym;
struct proto *p; struct proto *p;
node *n;
DBG("protos_commit:\n"); DBG("protos_commit:\n");
if (old) if (old)
@ -1518,8 +1516,8 @@ protos_commit(struct config *new, struct config *old, int force_reconfig, int ty
} }
struct proto *first_dev_proto = NULL; struct proto *first_dev_proto = NULL;
struct proto *after = NULL;
n = NODE &(proto_list.head);
WALK_LIST(nc, new->protos) WALK_LIST(nc, new->protos)
if (!nc->proto) if (!nc->proto)
{ {
@ -1527,14 +1525,14 @@ protos_commit(struct config *new, struct config *old, int force_reconfig, int ty
if (old) if (old)
log(L_INFO "Adding protocol %s", nc->name); log(L_INFO "Adding protocol %s", nc->name);
p = proto_init(nc, n); p = proto_init(nc, after);
n = NODE p; after = p;
if (p->proto == &proto_unix_iface) if (p->proto == &proto_unix_iface)
first_dev_proto = p; first_dev_proto = p;
} }
else else
n = NODE nc->proto; after = nc->proto;
DBG("Protocol start\n"); DBG("Protocol start\n");
@ -1552,7 +1550,7 @@ protos_commit(struct config *new, struct config *old, int force_reconfig, int ty
} }
/* Start all new protocols */ /* Start all new protocols */
WALK_LIST_DELSAFE(p, n, proto_list) WALK_TLIST_DELSAFE(proto, p, &global_proto_list)
proto_rethink_goal(p); proto_rethink_goal(p);
} }
@ -1574,18 +1572,19 @@ proto_rethink_goal(struct proto *p)
if (p->reconfiguring && !p->active) if (p->reconfiguring && !p->active)
{ {
struct proto_config *nc = p->cf_new; struct proto_config *nc = p->cf_new;
node *n = p->n.prev; struct proto *after = p->n.prev;
DBG("%s has shut down for reconfiguration\n", p->name); DBG("%s has shut down for reconfiguration\n", p->name);
p->cf->proto = NULL; p->cf->proto = NULL;
config_del_obstacle(p->cf->global); config_del_obstacle(p->cf->global);
proto_remove_channels(p); proto_remove_channels(p);
rem_node(&p->n); proto_rem_node(&global_proto_list, p);
rfree(p->event); rfree(p->event);
mb_free(p->message); mb_free(p->message);
mb_free(p); mb_free(p);
if (!nc) if (!nc)
return; return;
p = proto_init(nc, n); p = proto_init(nc, after);
} }
/* Determine what state we want to reach */ /* Determine what state we want to reach */
@ -1601,7 +1600,7 @@ proto_rethink_goal(struct proto *p)
struct proto * struct proto *
proto_spawn(struct proto_config *cf, uint disabled) proto_spawn(struct proto_config *cf, uint disabled)
{ {
struct proto *p = proto_init(cf, TAIL(proto_list)); struct proto *p = proto_init(cf, global_proto_list.last);
p->disabled = disabled; p->disabled = disabled;
proto_rethink_goal(p); proto_rethink_goal(p);
return p; return p;
@ -1697,8 +1696,7 @@ graceful_restart_done(timer *t UNUSED)
log(L_INFO "Graceful restart done"); log(L_INFO "Graceful restart done");
graceful_restart_state = GRS_DONE; graceful_restart_state = GRS_DONE;
struct proto *p; WALK_TLIST(proto, p, &global_proto_list)
WALK_LIST(p, proto_list)
{ {
if (!p->gr_recovery) if (!p->gr_recovery)
continue; continue;
@ -1794,8 +1792,7 @@ protos_dump_all(void)
{ {
debug("Protocols:\n"); debug("Protocols:\n");
struct proto *p; WALK_TLIST(proto, p, &global_proto_list) PROTO_LOCKED_FROM_MAIN(p)
WALK_LIST(p, proto_list) PROTO_LOCKED_FROM_MAIN(p)
{ {
#define DPF(x) (p->x ? " " #x : "") #define DPF(x) (p->x ? " " #x : "")
debug(" protocol %s (%p) state %s with %d active channels flags: %s%s%s%s\n", debug(" protocol %s (%p) state %s with %d active channels flags: %s%s%s%s\n",
@ -2481,10 +2478,9 @@ proto_apply_cmd_symbol(const struct symbol *s, void (* cmd)(struct proto *, uint
static void static void
proto_apply_cmd_patt(const char *patt, void (* cmd)(struct proto *, uintptr_t, int), uintptr_t arg) proto_apply_cmd_patt(const char *patt, void (* cmd)(struct proto *, uintptr_t, int), uintptr_t arg)
{ {
struct proto *p;
int cnt = 0; int cnt = 0;
WALK_LIST(p, proto_list) WALK_TLIST(proto, p, &global_proto_list)
if (!patt || patmatch(patt, p->name)) if (!patt || patmatch(patt, p->name))
PROTO_LOCKED_FROM_MAIN(p) PROTO_LOCKED_FROM_MAIN(p)
cmd(p, arg, cnt++); cmd(p, arg, cnt++);
@ -2511,7 +2507,7 @@ proto_apply_cmd(struct proto_spec ps, void (* cmd)(struct proto *, uintptr_t, in
struct proto * struct proto *
proto_get_named(struct symbol *sym, struct protocol *pr) proto_get_named(struct symbol *sym, struct protocol *pr)
{ {
struct proto *p, *q; struct proto *p;
if (sym) if (sym)
{ {
@ -2525,7 +2521,7 @@ proto_get_named(struct symbol *sym, struct protocol *pr)
else else
{ {
p = NULL; p = NULL;
WALK_LIST(q, proto_list) WALK_TLIST(proto, q, &global_proto_list)
if ((q->proto == pr) && (q->proto_state != PS_DOWN)) if ((q->proto == pr) && (q->proto_state != PS_DOWN))
{ {
if (p) if (p)
@ -2562,9 +2558,9 @@ proto_iterate_named(struct symbol *sym, struct protocol *proto, struct proto *ol
} }
else else
{ {
for (struct proto *p = !old ? HEAD(proto_list) : NODE_NEXT(old); for (struct proto *p = old ? old->n.next : global_proto_list.first;
NODE_VALID(p); p;
p = NODE_NEXT(p)) p = p->n.next)
{ {
if ((p->proto == proto) && (p->proto_state != PS_DOWN)) if ((p->proto == proto) && (p->proto_state != PS_DOWN))
{ {

View File

@ -116,9 +116,16 @@ struct proto_config {
/* Protocol-specific data follow... */ /* Protocol-specific data follow... */
}; };
#define TLIST_PREFIX proto
#define TLIST_TYPE struct proto
#define TLIST_ITEM n
#define TLIST_WANT_WALK
#define TLIST_WANT_ADD_TAIL
#define TLIST_WANT_ADD_AFTER
/* Protocol statistics */ /* Protocol statistics */
struct proto { struct proto {
node n; /* Node in global proto_list */ TLIST_DEFAULT_NODE; /* Node in global proto_list */
struct protocol *proto; /* Protocol */ struct protocol *proto; /* Protocol */
struct proto_config *cf; /* Configuration data */ struct proto_config *cf; /* Configuration data */
struct proto_config *cf_new; /* Configuration we want to switch to after shutdown (NULL=delete) */ struct proto_config *cf_new; /* Configuration we want to switch to after shutdown (NULL=delete) */
@ -198,6 +205,8 @@ struct proto {
/* Hic sunt protocol-specific data */ /* Hic sunt protocol-specific data */
}; };
#include "lib/tlists.h"
struct proto_spec { struct proto_spec {
const void *ptr; const void *ptr;
int patt; int patt;
@ -284,7 +293,6 @@ proto_get_router_id(struct proto_config *pc)
extern pool *proto_pool; extern pool *proto_pool;
extern list proto_list;
/* /*
* Each protocol instance runs two different state machines: * Each protocol instance runs two different state machines: