diff options
author | Ondrej Zajicek (work) <santiago@crfreenet.org> | 2019-03-14 17:22:22 +0100 |
---|---|---|
committer | Ondrej Zajicek (work) <santiago@crfreenet.org> | 2019-03-14 17:31:40 +0100 |
commit | 875cc073b067f295cccc668008e10218f8e98dd3 (patch) | |
tree | 28f65beeab81c8b422dd9d7c18a4f4f331adeb31 /proto/babel/babel.c | |
parent | 9aa77fccebc4d84b5e1496884cd124d09893041b (diff) |
Nest: Update handling of temporary attributes
The temporary atttributes are no longer removed by ea_do_prune(), but
they are undefined by store_tmp_attrs() protocol hooks. This fixes
several bugs where temporary attributes were removed when they should
not or not removed when they should be. The flag EAF_TEMP is no longer
needed and was removed.
Update all protocol make_tmp_attrs() / store_tmp_attrs() hooks to use
helper functions and to handle unset attributes properly.
Also fix some related bugs like improper handling of empty eattr list.
Diffstat (limited to 'proto/babel/babel.c')
-rw-r--r-- | proto/babel/babel.c | 45 |
1 files changed, 14 insertions, 31 deletions
diff --git a/proto/babel/babel.c b/proto/babel/babel.c index d321f1d8..177ff3a3 100644 --- a/proto/babel/babel.c +++ b/proto/babel/babel.c @@ -645,7 +645,7 @@ babel_announce_rte(struct babel_proto *p, struct babel_entry *e) rte->u.babel.seqno = r->seqno; rte->u.babel.metric = r->metric; rte->u.babel.router_id = r->router_id; - rte->pflags = 0; + rte->pflags = EA_ID_FLAG(EA_BABEL_METRIC) | EA_ID_FLAG(EA_BABEL_ROUTER_ID); e->unreachable = 0; rte_update2(c, e->n.addr, rte, p->p.main_source); @@ -2077,32 +2077,6 @@ babel_kick_timer(struct babel_proto *p) } -static struct ea_list * -babel_prepare_attrs(struct linpool *pool, ea_list *next, uint metric, u64 router_id) -{ - struct ea_list *l = lp_alloc(pool, sizeof(struct ea_list) + 2*sizeof(eattr)); - struct adata *rid = lp_alloc(pool, sizeof(struct adata) + sizeof(u64)); - rid->length = sizeof(u64); - memcpy(&rid->data, &router_id, sizeof(u64)); - - l->next = next; - l->flags = EALF_SORTED; - l->count = 2; - - l->attrs[0].id = EA_BABEL_METRIC; - l->attrs[0].flags = 0; - l->attrs[0].type = EAF_TYPE_INT | EAF_TEMP; - l->attrs[0].u.data = metric; - - l->attrs[1].id = EA_BABEL_ROUTER_ID; - l->attrs[1].flags = 0; - l->attrs[1].type = EAF_TYPE_OPAQUE | EAF_TEMP; - l->attrs[1].u.ptr = rid; - - return l; -} - - static int babel_preexport(struct proto *P, struct rte **new, struct linpool *pool UNUSED) { @@ -2115,16 +2089,25 @@ babel_preexport(struct proto *P, struct rte **new, struct linpool *pool UNUSED) return 0; } -static struct ea_list * +static void babel_make_tmp_attrs(struct rte *rt, struct linpool *pool) { - return babel_prepare_attrs(pool, NULL, rt->u.babel.metric, rt->u.babel.router_id); + struct adata *id = lp_alloc_adata(pool, sizeof(u64)); + memcpy(id->data, &rt->u.babel.router_id, sizeof(u64)); + + rte_init_tmp_attrs(rt, pool, 2); + rte_make_tmp_attr(rt, EA_BABEL_METRIC, EAF_TYPE_INT, rt->u.babel.metric); + rte_make_tmp_attr(rt, EA_BABEL_ROUTER_ID, EAF_TYPE_OPAQUE, (uintptr_t) id); } static void -babel_store_tmp_attrs(struct rte *rt) +babel_store_tmp_attrs(struct rte *rt, struct linpool *pool) { - rt->u.babel.metric = ea_get_int(rt->attrs->eattrs, EA_BABEL_METRIC, 0); + rte_init_tmp_attrs(rt, pool, 2); + rt->u.babel.metric = rte_store_tmp_attr(rt, EA_BABEL_METRIC); + + /* EA_BABEL_ROUTER_ID is read-only, we do not really save the value */ + rte_store_tmp_attr(rt, EA_BABEL_ROUTER_ID); } /* |