summaryrefslogtreecommitdiff
path: root/nest/rt-table.c
diff options
context:
space:
mode:
authorMaria Matejka <mq@ucw.cz>2020-04-10 17:08:29 +0200
committerMaria Matejka <mq@ucw.cz>2021-10-13 19:09:04 +0200
commit5cff1d5f022755df61af6fc21cc4f2e5d384404e (patch)
treed98b4b352a47257fe3943dcb050ff73c5c14aecf /nest/rt-table.c
parenteb937358c087eaeb6f209660cc7ecfe6d6eff739 (diff)
Route: moved rte_src pointer from rta to rte
It is an auxiliary key in the routing table, not a route attribute.
Diffstat (limited to 'nest/rt-table.c')
-rw-r--r--nest/rt-table.c51
1 files changed, 29 insertions, 22 deletions
diff --git a/nest/rt-table.c b/nest/rt-table.c
index 0b06be92..a869bb18 100644
--- a/nest/rt-table.c
+++ b/nest/rt-table.c
@@ -264,7 +264,7 @@ rte_find(net *net, struct rte_src *src)
{
rte *e = net->routes;
- while (e && e->attrs->src != src)
+ while (e && e->src != src)
e = e->next;
return e;
}
@@ -279,13 +279,14 @@ rte_find(net *net, struct rte_src *src)
* the protocol.
*/
rte *
-rte_get_temp(rta *a)
+rte_get_temp(rta *a, struct rte_src *src)
{
rte *e = sl_alloc(rte_slab);
e->attrs = a;
e->id = 0;
e->flags = 0;
+ rt_lock_source(e->src = src);
return e;
}
@@ -295,6 +296,8 @@ rte_do_cow(rte *r)
rte *e = sl_alloc(rte_slab);
memcpy(e, r, sizeof(rte));
+
+ rt_lock_source(e->src);
e->attrs = rta_clone(r->attrs);
e->flags = 0;
return e;
@@ -341,6 +344,7 @@ rte_cow_rta(rte *r, linpool *lp)
void
rte_free(rte *e)
{
+ rt_unlock_source(e->src);
if (rta_is_cached(e->attrs))
rta_free(e->attrs);
sl_free(rte_slab, e);
@@ -349,6 +353,7 @@ rte_free(rte *e)
static inline void
rte_free_quick(rte *e)
{
+ rt_unlock_source(e->src);
rta_free(e->attrs);
sl_free(rte_slab, e);
}
@@ -473,7 +478,7 @@ void
rte_make_tmp_attrs(rte **r, linpool *lp, rta **old_attrs)
{
void (*make_tmp_attrs)(rte *r, linpool *lp);
- make_tmp_attrs = (*r)->attrs->src->proto->make_tmp_attrs;
+ make_tmp_attrs = (*r)->src->proto->make_tmp_attrs;
if (!make_tmp_attrs)
return;
@@ -502,7 +507,7 @@ static void
rte_store_tmp_attrs(rte *r, linpool *lp, rta *old_attrs)
{
void (*store_tmp_attrs)(rte *rt, linpool *lp);
- store_tmp_attrs = r->attrs->src->proto->store_tmp_attrs;
+ store_tmp_attrs = r->src->proto->store_tmp_attrs;
if (!store_tmp_attrs)
return;
@@ -536,16 +541,16 @@ rte_better(rte *new, rte *old)
return 1;
if (new->attrs->pref < old->attrs->pref)
return 0;
- if (new->attrs->src->proto->proto != old->attrs->src->proto->proto)
+ if (new->src->proto->proto != old->src->proto->proto)
{
/*
* If the user has configured protocol preferences, so that two different protocols
* have the same preference, try to break the tie by comparing addresses. Not too
* useful, but keeps the ordering of routes unambiguous.
*/
- return new->attrs->src->proto->proto > old->attrs->src->proto->proto;
+ return new->src->proto->proto > old->src->proto->proto;
}
- if (better = new->attrs->src->proto->rte_better)
+ if (better = new->src->proto->rte_better)
return better(new, old);
return 0;
}
@@ -561,10 +566,10 @@ rte_mergable(rte *pri, rte *sec)
if (pri->attrs->pref != sec->attrs->pref)
return 0;
- if (pri->attrs->src->proto->proto != sec->attrs->src->proto->proto)
+ if (pri->src->proto->proto != sec->src->proto->proto)
return 0;
- if (mergable = pri->attrs->src->proto->rte_mergable)
+ if (mergable = pri->src->proto->rte_mergable)
return mergable(pri, sec);
return 0;
@@ -1079,7 +1084,8 @@ rte_same(rte *x, rte *y)
return
x->attrs == y->attrs &&
x->pflags == y->pflags &&
- (!x->attrs->src->proto->rte_same || x->attrs->src->proto->rte_same(x, y)) &&
+ x->src == y->src &&
+ (!x->src->proto->rte_same || x->src->proto->rte_same(x, y)) &&
rte_is_filtered(x) == rte_is_filtered(y);
}
@@ -1100,7 +1106,7 @@ rte_recalculate(struct channel *c, net *net, rte *new, struct rte_src *src)
k = &net->routes; /* Find and remove original route from the same protocol */
while (old = *k)
{
- if (old->attrs->src == src)
+ if (old->src == src)
{
/* If there is the same route in the routing table but from
* a different sender, then there are two paths from the
@@ -1561,7 +1567,7 @@ static inline void
rte_discard(rte *old) /* Non-filtered route deletion, used during garbage collection */
{
rte_update_lock();
- rte_recalculate(old->sender, old->net, NULL, old->attrs->src);
+ rte_recalculate(old->sender, old->net, NULL, old->src);
rte_update_unlock();
}
@@ -1581,7 +1587,7 @@ rte_modify(rte *old)
new->flags = (old->flags & ~REF_MODIFY) | REF_COW;
}
- rte_recalculate(old->sender, old->net, new, old->attrs->src);
+ rte_recalculate(old->sender, old->net, new, old->src);
}
rte_update_unlock();
@@ -1707,8 +1713,8 @@ rte_dump(rte *e)
debug("%-1N ", n->n.addr);
debug("PF=%02x ", e->pflags);
rta_dump(e->attrs);
- if (e->attrs->src->proto->proto->dump_attrs)
- e->attrs->src->proto->proto->dump_attrs(e);
+ if (e->src->proto->proto->dump_attrs)
+ e->src->proto->proto->dump_attrs(e);
debug("\n");
}
@@ -2222,6 +2228,7 @@ rt_next_hop_update_rte(rtable *tab UNUSED, rte *old)
rte *e = sl_alloc(rte_slab);
memcpy(e, old, sizeof(rte));
e->attrs = rta_lookup(a);
+ rt_lock_source(e->src);
return e;
}
@@ -2248,8 +2255,8 @@ rt_next_hop_update_net(rtable *tab, net *n)
/* Call a pre-comparison hook */
/* Not really an efficient way to compute this */
- if (e->attrs->src->proto->rte_recalculate)
- e->attrs->src->proto->rte_recalculate(tab, n, new, e, NULL);
+ if (e->src->proto->rte_recalculate)
+ e->src->proto->rte_recalculate(tab, n, new, e, NULL);
if (e != old_best)
rte_free_quick(e);
@@ -2584,7 +2591,7 @@ rte_update_in(struct channel *c, const net_addr *n, rte *new, struct rte_src *sr
/* Find the old rte */
for (pos = &net->routes; old = *pos; pos = &old->next)
- if (old->attrs->src == src)
+ if (old->src == src)
{
if (new && rte_same(old, new))
{
@@ -2689,7 +2696,7 @@ rt_reload_channel(struct channel *c)
return 0;
}
- rte_update2(c, e->net->n.addr, rte_do_cow(e), e->attrs->src);
+ rte_update2(c, e->net->n.addr, rte_do_cow(e), e->src);
}
c->reload_next_rte = NULL;
@@ -2772,7 +2779,7 @@ rte_update_out(struct channel *c, const net_addr *n, rte *new, rte *old0, rte **
if (new)
{
net = net_get(tab, n);
- src = new->attrs->src;
+ src = new->src;
rte_store_tmp_attrs(new, rte_update_pool, NULL);
@@ -2782,7 +2789,7 @@ rte_update_out(struct channel *c, const net_addr *n, rte *new, rte *old0, rte **
else
{
net = net_find(tab, n);
- src = old0->attrs->src;
+ src = old0->src;
if (!net)
goto drop_withdraw;
@@ -2790,7 +2797,7 @@ rte_update_out(struct channel *c, const net_addr *n, rte *new, rte *old0, rte **
/* Find the old rte */
for (pos = &net->routes; old = *pos; pos = &old->next)
- if ((c->ra_mode != RA_ANY) || (old->attrs->src == src))
+ if ((c->ra_mode != RA_ANY) || (old->src == src))
{
if (new && rte_same(old, new))
{