#include "lib/resource.h"
#include "lib/lists.h"
#include "lib/event.h"
+#include "lib/string.h"
#include "conf/conf.h"
#include "nest/route.h"
#include "nest/iface.h"
static pool *proto_pool;
list protocol_list;
-list proto_list;
+static list proto_list;
+#define WALK_PROTO_LIST(p) do { \
+ node *nn; \
+ WALK_LIST(nn, proto_list) { \
+ struct proto *p = SKIP_BACK(struct proto, glob_node, nn);
+#define WALK_PROTO_LIST_END } } while(0)
+
+list active_proto_list;
static list inactive_proto_list;
static list initial_proto_list;
static list flush_proto_list;
switch (p->core_state)
{
case FS_HAPPY:
- l = &proto_list;
+ l = &active_proto_list;
break;
case FS_FLUSHING:
l = &flush_proto_list;
struct protocol *p;
init_list(&proto_list);
+ init_list(&active_proto_list);
init_list(&inactive_proto_list);
init_list(&initial_proto_list);
init_list(&flush_proto_list);
q->proto_state = PS_DOWN;
q->core_state = FS_HUNGRY;
proto_enqueue(&initial_proto_list, q);
+ add_tail(&proto_list, &q->glob_node);
/*
* HACK ALERT! In case of multiple kernel routing tables,
* the kernel syncer acts as multiple protocols which cooperate
DBG("%s has shut down for reconfiguration\n", p->name);
config_del_obstacle(p->cf->global);
rem_node(&p->n);
+ rem_node(&p->glob_node);
mb_free(p);
if (!nc)
return;
if (p->core_state == FS_HUNGRY && p->proto_state == PS_DOWN)
{
DBG("Kicking %s up\n", p->name);
- ASSERT(q->startup_counter > 0);
- q->startup_counter--;
+ if (q->startup_counter > 0) /* FIXME: Kill the startup counter hack! */
+ q->startup_counter--;
proto_init_instance(p);
proto_notify_state(p, (q->start ? q->start(p) : PS_UP));
}
debug("Protocols:\n");
- WALK_LIST(p, proto_list)
+ WALK_LIST(p, active_proto_list)
{
debug(" protocol %s (pri=%d): state %s/%s\n", p->name, p->proto->priority,
p_states[p->proto_state], c_states[p->core_state]);
debug(" inactive %s: state %s/%s\n", p->name, p_states[p->proto_state], c_states[p->core_state]);
WALK_LIST(p, initial_proto_list)
debug(" initial %s\n", p->name);
+ WALK_LIST(p, flush_proto_list)
+ debug(" flushing %s\n", p->name);
}
void
}
}
-static void
-proto_do_show_list(list *l, int verbose)
-{
- struct proto *p;
-
- WALK_LIST(p, *l)
- proto_do_show(p, verbose);
-}
-
void
proto_show(struct symbol *s, int verbose)
{
proto_do_show(((struct proto_config *)s->def)->proto, verbose);
else
{
- proto_do_show_list(&proto_list, verbose);
- proto_do_show_list(&flush_proto_list, verbose);
- proto_do_show_list(&inactive_proto_list, verbose);
+ WALK_PROTO_LIST(p)
+ proto_do_show(p, verbose);
+ WALK_PROTO_LIST_END;
}
cli_msg(0, "");
}
else
{
p = NULL;
- WALK_LIST(q, proto_list)
+ WALK_LIST(q, active_proto_list)
if (q->proto == pr)
{
if (p)
}
return p;
}
+
+void
+proto_xxable(char *pattern, int xx)
+{
+ int cnt = 0;
+ WALK_PROTO_LIST(p)
+ if (patmatch(pattern, p->name))
+ {
+ cnt++;
+ switch (xx)
+ {
+ case 0:
+ if (p->disabled)
+ cli_msg(-8, "%s: already disabled", p->name);
+ else
+ {
+ cli_msg(-9, "%s: disabled", p->name);
+ p->disabled = 1;
+ }
+ break;
+ case 1:
+ if (!p->disabled)
+ cli_msg(-10, "%s: already enabled", p->name);
+ else
+ {
+ cli_msg(-11, "%s: enabled", p->name);
+ p->disabled = 0;
+ }
+ break;
+ case 2:
+ if (p->disabled)
+ cli_msg(-8, "%s: already disabled", p->name);
+ else
+ {
+ p->disabled = 1;
+ proto_rethink_goal(p);
+ p->disabled = 0;
+ cli_msg(-12, "%s: restarted", p->name);
+ }
+ break;
+ default:
+ ASSERT(0);
+ }
+ proto_rethink_goal(p);
+ }
+ WALK_PROTO_LIST_END;
+ if (!cnt)
+ cli_msg(8003, "No protocols match");
+ else
+ cli_msg(0, "");
+}
};
struct proto {
- node n;
+ node n; /* Node in *_proto_list */
+ node glob_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) */
void proto_build(struct proto_config *);
void *proto_new(struct proto_config *, unsigned size);
void *proto_config_new(struct protocol *, unsigned size);
+
void proto_show(struct symbol *, int);
struct proto *proto_get_named(struct symbol *, struct protocol *);
+void proto_xxable(char *, int);
-extern list proto_list;
+extern list active_proto_list;
/*
* Each protocol instance runs two different state machines: