summaryrefslogtreecommitdiff
path: root/proto/mrt/mrt.c
diff options
context:
space:
mode:
Diffstat (limited to 'proto/mrt/mrt.c')
-rw-r--r--proto/mrt/mrt.c90
1 files changed, 38 insertions, 52 deletions
diff --git a/proto/mrt/mrt.c b/proto/mrt/mrt.c
index b40592d2..f07f9ca2 100644
--- a/proto/mrt/mrt.c
+++ b/proto/mrt/mrt.c
@@ -243,21 +243,15 @@ mrt_next_table(struct mrt_table_dump_state *s)
rtable *tab = mrt_next_table_(s->table, s->table_ptr, s->table_expr);
if (s->table)
- {
- RT_LOCK(s->table);
- rt_unlock_table(RT_PRIV(s->table));
- RT_UNLOCK(s->table);
- }
+ RT_LOCKED(s->table, tab)
+ rt_unlock_table(tab);
s->table = tab;
s->ipv4 = tab ? (tab->addr_type == NET_IP4) : 0;
if (s->table)
- {
- RT_LOCK(s->table);
- rt_lock_table(RT_PRIV(s->table));
- RT_UNLOCK(s->table);
- }
+ RT_LOCKED(s->table, tab)
+ rt_lock_table(tab);
return s->table;
}
@@ -431,7 +425,7 @@ mrt_rib_table_header(struct mrt_table_dump_state *s, net_addr *n)
static void
mrt_rib_table_entry_bgp_attrs(struct mrt_table_dump_state *s, rte *r)
{
- struct ea_list *eattrs = r->attrs->eattrs;
+ struct ea_list *eattrs = r->attrs;
buffer *b = &s->buf;
if (!eattrs)
@@ -439,7 +433,7 @@ mrt_rib_table_entry_bgp_attrs(struct mrt_table_dump_state *s, rte *r)
/* Attribute list must be normalized for bgp_encode_attrs() */
if (!rta_is_cached(r->attrs))
- ea_normalize(eattrs);
+ eattrs = ea_normalize(eattrs, 0);
mrt_buffer_need(b, MRT_ATTR_BUFFER_SIZE);
byte *pos = b->pos;
@@ -533,7 +527,7 @@ mrt_rib_table_dump(struct mrt_table_dump_state *s, net *n, int add_path)
}
rte e = rt->rte;
- if (f_run(s->filter, &e, s->linpool, 0) <= F_ACCEPT)
+ if (f_run(s->filter, &e, 0) <= F_ACCEPT)
mrt_rib_table_entry(s, &e);
lp_flush(s->linpool);
@@ -565,8 +559,8 @@ mrt_table_dump_init(pool *pp)
struct mrt_table_dump_state *s = mb_allocz(pool, sizeof(struct mrt_table_dump_state));
s->pool = pool;
- s->linpool = lp_new(pool, 4080);
- s->peer_lp = lp_new(pool, 4080);
+ s->linpool = lp_new(pool);
+ s->peer_lp = lp_new(pool);
mrt_buffer_init(&s->buf, pool, 2 * MRT_ATTR_BUFFER_SIZE);
/* We lock the current config as we may reference it indirectly by filter */
@@ -582,22 +576,17 @@ static void
mrt_table_dump_free(struct mrt_table_dump_state *s)
{
if (s->table)
- {
- RT_LOCK(s->table);
-
- if (s->table_open)
- FIB_ITERATE_UNLINK(&s->fit, &RT_PRIV(s->table)->fib);
+ RT_LOCKED(s->table, tab)
+ {
+ if (s->table_open)
+ FIB_ITERATE_UNLINK(&s->fit, &tab->fib);
- rt_unlock_table(RT_PRIV(s->table));
- RT_UNLOCK(s->table);
- }
+ rt_unlock_table(tab);
+ }
if (s->table_ptr)
- {
- RT_LOCK(s->table_ptr);
- rt_unlock_table(RT_PRIV(s->table_ptr));
- RT_UNLOCK(s->table_ptr);
- }
+ RT_LOCKED(s->table_ptr, tab)
+ rt_unlock_table(tab);
config_del_obstacle(s->config);
@@ -613,14 +602,8 @@ mrt_table_dump_step(struct mrt_table_dump_state *s)
s->max = 2048;
s->bws = &bws;
- rtable_private *tab;
-
if (s->table_open)
- {
- RT_LOCK(s->table);
- tab = RT_PRIV(s->table);
goto step;
- }
while (mrt_next_table(s))
{
@@ -629,8 +612,9 @@ mrt_table_dump_step(struct mrt_table_dump_state *s)
mrt_peer_table_dump(s);
- RT_LOCK(s->table);
- tab = RT_PRIV(s->table);
+ RT_LOCKED(s->table, tab)
+ {
+
FIB_ITERATE_INIT(&s->fit, &tab->fib);
s->table_open = 1;
@@ -640,8 +624,7 @@ mrt_table_dump_step(struct mrt_table_dump_state *s)
if (s->max < 0)
{
FIB_ITERATE_PUT(&s->fit);
- RT_UNLOCK(s->table);
- return 0;
+ RT_RETURN(tab, 0);
}
/* With Always ADD_PATH option, we jump directly to second phase */
@@ -656,11 +639,12 @@ mrt_table_dump_step(struct mrt_table_dump_state *s)
FIB_ITERATE_END;
s->table_open = 0;
+ }
+
mrt_close_file(s);
mrt_peer_table_flush(s);
}
- RT_UNLOCK(s->table);
return 1;
}
@@ -688,11 +672,8 @@ mrt_timer(timer *t)
s->always_add_path = cf->always_add_path;
if (s->table_ptr)
- {
- RT_LOCK(s->table_ptr);
- rt_lock_table(RT_PRIV(s->table_ptr));
- RT_UNLOCK(s->table_ptr);
- }
+ RT_LOCKED(s->table_ptr, tab)
+ rt_lock_table(tab);
p->table_dump = s;
ev_schedule(p->event);
@@ -734,14 +715,17 @@ mrt_dump_cont(struct cli *c)
cli_printf(c, 0, "");
mrt_table_dump_free(c->rover);
- c->cont = c->cleanup = c->rover = NULL;
+ c->cont = NULL;
+ c->cleanup = NULL;
+ c->rover = NULL;
}
-static void
+static int
mrt_dump_cleanup(struct cli *c)
{
mrt_table_dump_free(c->rover);
c->rover = NULL;
+ return 0;
}
void
@@ -765,11 +749,8 @@ mrt_dump_cmd(struct mrt_dump_data *d)
s->filename = d->filename;
if (s->table_ptr)
- {
- RT_LOCK(s->table_ptr);
- rt_lock_table(RT_PRIV(s->table_ptr));
- RT_UNLOCK(s->table_ptr);
- }
+ RT_LOCKED(s->table_ptr, tab)
+ rt_lock_table(tab);
this_cli->cont = mrt_dump_cont;
this_cli->cleanup = mrt_dump_cleanup;
@@ -939,7 +920,6 @@ mrt_copy_config(struct proto_config *dest UNUSED, struct proto_config *src UNUSE
struct protocol proto_mrt = {
.name = "MRT",
.template = "mrt%d",
- .class = PROTOCOL_MRT,
.proto_size = sizeof(struct mrt_proto),
.config_size = sizeof(struct mrt_config),
.init = mrt_init,
@@ -948,3 +928,9 @@ struct protocol proto_mrt = {
.reconfigure = mrt_reconfigure,
.copy_config = mrt_copy_config,
};
+
+void
+mrt_build(void)
+{
+ proto_build(&proto_mrt);
+}