Commit 1a54b1c6 authored by Martin Mareš's avatar Martin Mareš

Implemented real cleanup and pruning of routing table on protocol shutdown.

parent ab749558
...@@ -26,23 +26,40 @@ list proto_list; ...@@ -26,23 +26,40 @@ list proto_list;
static list inactive_proto_list; static list inactive_proto_list;
static list initial_proto_list; static list initial_proto_list;
static list flush_proto_list;
static event *proto_flush_event;
static char *p_states[] = { "DOWN", "START", "UP", "STOP" }; static char *p_states[] = { "DOWN", "START", "UP", "STOP" };
static char *c_states[] = { "HUNGRY", "FEEDING", "HAPPY", "FLUSHING" }; static char *c_states[] = { "HUNGRY", "FEEDING", "HAPPY", "FLUSHING" };
static void proto_flush_all(void *);
static void static void
proto_relink(struct proto *p) proto_relink(struct proto *p)
{ {
list *l;
rem_node(&p->n); rem_node(&p->n);
add_tail(p->core_state == FS_HAPPY ? &proto_list : &inactive_proto_list, &p->n); switch (p->core_state)
{
case FS_HAPPY:
l = &proto_list;
break;
case FS_FLUSHING:
l = &flush_proto_list;
break;
default:
l = &inactive_proto_list;
}
add_tail(l, &p->n);
} }
void * void *
proto_new(struct proto_config *c, unsigned size) proto_new(struct proto_config *c, unsigned size)
{ {
struct protocol *pr = c->proto; struct protocol *pr = c->proto;
pool *r = rp_new(proto_pool, c->name); struct proto *p = mb_alloc(proto_pool, size);
struct proto *p = mb_alloc(r, size);
p->cf = c; p->cf = c;
p->debug = c->debug; p->debug = c->debug;
...@@ -50,12 +67,19 @@ proto_new(struct proto_config *c, unsigned size) ...@@ -50,12 +67,19 @@ proto_new(struct proto_config *c, unsigned size)
p->preference = c->preference; p->preference = c->preference;
p->disabled = c->disabled; p->disabled = c->disabled;
p->proto = pr; p->proto = pr;
p->pool = r;
p->attn = ev_new(r);
p->attn->data = p;
return p; return p;
} }
static void
proto_init_instance(struct proto *p)
{
struct proto_config *c = p->cf;
p->pool = rp_new(proto_pool, c->name);
p->attn = ev_new(p->pool);
p->attn->data = p;
}
void * void *
proto_config_new(struct protocol *pr, unsigned size) proto_config_new(struct protocol *pr, unsigned size)
{ {
...@@ -77,6 +101,7 @@ protos_preconfig(struct config *c) ...@@ -77,6 +101,7 @@ protos_preconfig(struct config *c)
init_list(&proto_list); init_list(&proto_list);
init_list(&inactive_proto_list); init_list(&inactive_proto_list);
init_list(&initial_proto_list); init_list(&initial_proto_list);
init_list(&flush_proto_list);
debug("Protocol preconfig:"); debug("Protocol preconfig:");
WALK_LIST(p, protocol_list) WALK_LIST(p, protocol_list)
{ {
...@@ -136,6 +161,7 @@ proto_rethink_goal(struct proto *p) ...@@ -136,6 +161,7 @@ proto_rethink_goal(struct proto *p)
if (p->core_state == FS_HUNGRY && p->proto_state == PS_DOWN) if (p->core_state == FS_HUNGRY && p->proto_state == PS_DOWN)
{ {
DBG("Kicking %s up\n", p->name); DBG("Kicking %s up\n", p->name);
proto_init_instance(p);
proto_notify_state(p, (q->start ? q->start(p) : PS_UP)); proto_notify_state(p, (q->start ? q->start(p) : PS_UP));
} }
} }
...@@ -201,6 +227,8 @@ protos_build(void) ...@@ -201,6 +227,8 @@ protos_build(void)
add_tail(&protocol_list, &proto_static.n); add_tail(&protocol_list, &proto_static.n);
#endif #endif
proto_pool = rp_new(&root_pool, "Protocols"); proto_pool = rp_new(&root_pool, "Protocols");
proto_flush_event = ev_new(proto_pool);
proto_flush_event->hook = proto_flush_all;
} }
static void static void
...@@ -223,15 +251,6 @@ proto_feed(void *P) ...@@ -223,15 +251,6 @@ proto_feed(void *P)
DBG("Protocol %s up and running\n", p->name); DBG("Protocol %s up and running\n", p->name);
} }
static void
proto_flush(void *P)
{
struct proto *p = P;
DBG("Flushing protocol %s\n", p->name);
bug("Protocol flushing not supported yet!"); /* FIXME */
}
void void
proto_notify_state(struct proto *p, unsigned ps) proto_notify_state(struct proto *p, unsigned ps)
{ {
...@@ -270,8 +289,7 @@ proto_notify_state(struct proto *p, unsigned ps) ...@@ -270,8 +289,7 @@ proto_notify_state(struct proto *p, unsigned ps)
schedule_flush: schedule_flush:
DBG("%s: Scheduling flush\n", p->name); DBG("%s: Scheduling flush\n", p->name);
cs = FS_FLUSHING; cs = FS_FLUSHING;
p->attn->hook = proto_flush; ev_schedule(proto_flush_event);
ev_schedule(p->attn);
} }
default: default:
error: error:
...@@ -281,3 +299,20 @@ proto_notify_state(struct proto *p, unsigned ps) ...@@ -281,3 +299,20 @@ proto_notify_state(struct proto *p, unsigned ps)
p->core_state = cs; p->core_state = cs;
proto_relink(p); proto_relink(p);
} }
static void
proto_flush_all(void *unused)
{
struct proto *p;
rt_prune(&master_table);
while ((p = HEAD(flush_proto_list))->n.next)
{
DBG("Flushing protocol %s\n", p->name);
rfree(p->pool);
p->pool = NULL;
p->core_state = FS_HUNGRY;
proto_relink(p);
proto_rethink_goal(p);
}
}
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
#include <string.h> #include <string.h>
#define LOCAL_DEBUG
#include "nest/bird.h" #include "nest/bird.h"
#include "nest/route.h" #include "nest/route.h"
#include "nest/protocol.h" #include "nest/protocol.h"
...@@ -282,3 +284,33 @@ rt_init(void) ...@@ -282,3 +284,33 @@ rt_init(void)
rt_setup(&master_table, "master"); rt_setup(&master_table, "master");
rte_slab = sl_new(&root_pool, sizeof(rte)); rte_slab = sl_new(&root_pool, sizeof(rte));
} }
void
rt_prune(rtable *tab)
{
struct fib_iterator fit;
int cnt = 0;
DBG("Pruning route table %s\n", tab->name);
while (tab)
{
FIB_ITERATE_INIT(&fit, &tab->fib);
again:
FIB_ITERATE_START(&tab->fib, &fit, f)
{
net *n = (net *) f;
rte *e;
for (e=n->routes; e; e=e->next)
if (e->attrs->proto->core_state != FS_HAPPY)
{
FIB_ITERATE_PUT(&fit, f);
rte_discard(e);
cnt++;
goto again;
}
}
FIB_ITERATE_END(f);
tab = tab->sibling;
}
DBG("Pruned %d routes\n", cnt);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment