#include "filter/f-inst.h"
pool *proto_pool;
-list STATIC_LIST_INIT(proto_list);
+static TLIST_LIST(proto) global_proto_list;
static list STATIC_LIST_INIT(protocol_list);
}
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 proto *p = pr->init(c);
p->proto_state = PS_DOWN;
p->last_state_change = current_time();
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);
struct proto_config *oc, *nc;
struct symbol *sym;
struct proto *p;
- node *n;
-
DBG("protos_commit:\n");
if (old)
}
struct proto *first_dev_proto = NULL;
+ struct proto *after = NULL;
- n = NODE &(proto_list.head);
WALK_LIST(nc, new->protos)
if (!nc->proto)
{
if (old)
log(L_INFO "Adding protocol %s", nc->name);
- p = proto_init(nc, n);
- n = NODE p;
+ p = proto_init(nc, after);
+ after = p;
if (p->proto == &proto_unix_iface)
first_dev_proto = p;
}
else
- n = NODE nc->proto;
+ after = nc->proto;
DBG("Protocol start\n");
}
/* Start all new protocols */
- WALK_LIST_DELSAFE(p, n, proto_list)
+ WALK_TLIST_DELSAFE(proto, p, &global_proto_list)
proto_rethink_goal(p);
}
if (p->reconfiguring && !p->active)
{
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);
p->cf->proto = NULL;
config_del_obstacle(p->cf->global);
proto_remove_channels(p);
- rem_node(&p->n);
+ proto_rem_node(&global_proto_list, p);
rfree(p->event);
mb_free(p->message);
mb_free(p);
if (!nc)
return;
- p = proto_init(nc, n);
+ p = proto_init(nc, after);
}
/* Determine what state we want to reach */
struct proto *
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;
proto_rethink_goal(p);
return p;
log(L_INFO "Graceful restart done");
graceful_restart_state = GRS_DONE;
- struct proto *p;
- WALK_LIST(p, proto_list)
+ WALK_TLIST(proto, p, &global_proto_list)
{
if (!p->gr_recovery)
continue;
{
debug("Protocols:\n");
- struct proto *p;
- WALK_LIST(p, proto_list) PROTO_LOCKED_FROM_MAIN(p)
+ WALK_TLIST(proto, p, &global_proto_list) PROTO_LOCKED_FROM_MAIN(p)
{
#define DPF(x) (p->x ? " " #x : "")
debug(" protocol %s (%p) state %s with %d active channels flags: %s%s%s%s\n",
static void
proto_apply_cmd_patt(const char *patt, void (* cmd)(struct proto *, uintptr_t, int), uintptr_t arg)
{
- struct proto *p;
int cnt = 0;
- WALK_LIST(p, proto_list)
+ WALK_TLIST(proto, p, &global_proto_list)
if (!patt || patmatch(patt, p->name))
PROTO_LOCKED_FROM_MAIN(p)
cmd(p, arg, cnt++);
struct proto *
proto_get_named(struct symbol *sym, struct protocol *pr)
{
- struct proto *p, *q;
+ struct proto *p;
if (sym)
{
else
{
p = NULL;
- WALK_LIST(q, proto_list)
+ WALK_TLIST(proto, q, &global_proto_list)
if ((q->proto == pr) && (q->proto_state != PS_DOWN))
{
if (p)
}
else
{
- for (struct proto *p = !old ? HEAD(proto_list) : NODE_NEXT(old);
- NODE_VALID(p);
- p = NODE_NEXT(p))
+ for (struct proto *p = old ? old->n.next : global_proto_list.first;
+ p;
+ p = p->n.next)
{
if ((p->proto == proto) && (p->proto_state != PS_DOWN))
{
/* 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 */
struct proto {
- node n; /* Node in global proto_list */
+ TLIST_DEFAULT_NODE; /* Node in global proto_list */
struct protocol *proto; /* Protocol */
struct proto_config *cf; /* Configuration data */
struct proto_config *cf_new; /* Configuration we want to switch to after shutdown (NULL=delete) */
/* Hic sunt protocol-specific data */
};
+#include "lib/tlists.h"
+
struct proto_spec {
const void *ptr;
int patt;
extern pool *proto_pool;
-extern list proto_list;
/*
* Each protocol instance runs two different state machines: