summaryrefslogtreecommitdiff
path: root/nest
diff options
context:
space:
mode:
authorMaria Matejka <mq@jmq.cz>2020-02-10 08:41:05 +0100
committerMaria Matejka <mq@ucw.cz>2021-10-13 19:09:04 +0200
commiteb937358c087eaeb6f209660cc7ecfe6d6eff739 (patch)
treeb21a471c3c7247eb226cee5cbc9bf887bae6023a /nest
parentd5a32563df1653952937117133f09143929ff0c2 (diff)
Preference moved to RTA and set explicitly in protocols
Diffstat (limited to 'nest')
-rw-r--r--nest/route.h19
-rw-r--r--nest/rt-attr.c24
-rw-r--r--nest/rt-dev.c1
-rw-r--r--nest/rt-show.c2
-rw-r--r--nest/rt-table.c18
5 files changed, 26 insertions, 38 deletions
diff --git a/nest/route.h b/nest/route.h
index 227a5f5e..aec867e2 100644
--- a/nest/route.h
+++ b/nest/route.h
@@ -241,7 +241,6 @@ typedef struct rte {
u32 id; /* Table specific route id */
byte flags; /* Flags (REF_...) */
byte pflags; /* Protocol-specific flags */
- word pref; /* Route preference */
btime lastmod; /* Last modified */
union { /* Protocol-dependent data (metrics etc.) */
#ifdef CONFIG_RIP
@@ -446,10 +445,11 @@ typedef struct rta {
struct hostentry *hostentry; /* Hostentry for recursive next-hops */
ip_addr from; /* Advertising router */
u32 igp_metric; /* IGP metric to next hop (for iBGP routes) */
- u8 source; /* Route source (RTS_...) */
- u8 scope; /* Route scope (SCOPE_... -- see ip.h) */
- u8 dest; /* Route destination type (RTD_...) */
- u8 aflags;
+ u16 cached:1; /* Are attributes cached? */
+ u16 source:7; /* Route source (RTS_...) */
+ u16 scope:4; /* Route scope (SCOPE_... -- see ip.h) */
+ u16 dest:4; /* Route destination type (RTD_...) */
+ word pref;
struct nexthop nh; /* Next hop */
} rta;
@@ -471,11 +471,6 @@ typedef struct rta {
#define RTS_PERF 15 /* Perf checker */
#define RTS_MAX 16
-#define RTC_UNICAST 0
-#define RTC_BROADCAST 1
-#define RTC_MULTICAST 2
-#define RTC_ANYCAST 3 /* IPv6 Anycast */
-
#define RTD_NONE 0 /* Undefined next hop */
#define RTD_UNICAST 1 /* Next hop is neighbor router */
#define RTD_BLACKHOLE 2 /* Silently drop packets */
@@ -483,8 +478,6 @@ typedef struct rta {
#define RTD_PROHIBIT 4 /* Administratively prohibited */
#define RTD_MAX 5
-#define RTAF_CACHED 1 /* This is a cached rta */
-
#define IGP_METRIC_UNKNOWN 0x80000000 /* Default igp_metric used when no other
protocol-specific metric is availabe */
@@ -673,7 +666,7 @@ void rta_init(void);
static inline size_t rta_size(const rta *a) { return sizeof(rta) + sizeof(u32)*a->nh.labels; }
#define RTA_MAX_SIZE (sizeof(rta) + sizeof(u32)*MPLS_MAX_LABEL_STACK)
rta *rta_lookup(rta *); /* Get rta equivalent to this one, uc++ */
-static inline int rta_is_cached(rta *r) { return r->aflags & RTAF_CACHED; }
+static inline int rta_is_cached(rta *r) { return r->cached; }
static inline rta *rta_clone(rta *r) { r->uc++; return r; }
void rta__free(rta *r);
static inline void rta_free(rta *r) { if (r && !--r->uc) rta__free(r); }
diff --git a/nest/rt-attr.c b/nest/rt-attr.c
index c630aa95..4198b552 100644
--- a/nest/rt-attr.c
+++ b/nest/rt-attr.c
@@ -1104,13 +1104,15 @@ rta_hash(rta *a)
u64 h;
mem_hash_init(&h);
#define MIX(f) mem_hash_mix(&h, &(a->f), sizeof(a->f));
+#define BMIX(f) mem_hash_mix_num(&h, a->f);
MIX(src);
MIX(hostentry);
MIX(from);
MIX(igp_metric);
- MIX(source);
- MIX(scope);
- MIX(dest);
+ BMIX(source);
+ BMIX(scope);
+ BMIX(dest);
+ MIX(pref);
#undef MIX
return mem_hash_value(&h) ^ nexthop_hash(&(a->nh)) ^ ea_hash(a->eattrs);
@@ -1198,7 +1200,7 @@ rta_lookup(rta *o)
rta *r;
uint h;
- ASSERT(!(o->aflags & RTAF_CACHED));
+ ASSERT(!o->cached);
if (o->eattrs)
ea_normalize(o->eattrs);
@@ -1209,7 +1211,7 @@ rta_lookup(rta *o)
r = rta_copy(o);
r->hash_key = h;
- r->aflags = RTAF_CACHED;
+ r->cached = 1;
rt_lock_source(r->src);
rt_lock_hostentry(r->hostentry);
rta_insert(r);
@@ -1223,7 +1225,7 @@ rta_lookup(rta *o)
void
rta__free(rta *a)
{
- ASSERT(rta_cache_count && (a->aflags & RTAF_CACHED));
+ ASSERT(rta_cache_count && a->cached);
rta_cache_count--;
*a->pprev = a->next;
if (a->next)
@@ -1233,7 +1235,7 @@ rta__free(rta *a)
if (a->nh.next)
nexthop_free(a->nh.next);
ea_free(a->eattrs);
- a->aflags = 0; /* Poison the entry */
+ a->cached = 0;
sl_free(rta_slab(a), a);
}
@@ -1248,7 +1250,7 @@ rta_do_cow(rta *o, linpool *lp)
memcpy(*nhn, nho, nexthop_size(nho));
nhn = &((*nhn)->next);
}
- r->aflags = 0;
+ r->cached = 0;
r->uc = 0;
return r;
}
@@ -1268,10 +1270,10 @@ rta_dump(rta *a)
"RTS_OSPF_EXT2", "RTS_BGP", "RTS_PIPE", "RTS_BABEL" };
static char *rtd[] = { "", " DEV", " HOLE", " UNREACH", " PROHIBIT" };
- debug("p=%s uc=%d %s %s%s h=%04x",
- a->src->proto->name, a->uc, rts[a->source], ip_scope_text(a->scope),
+ debug("p=%s pref=%d uc=%d %s %s%s h=%04x",
+ a->src->proto->name, a->pref, a->uc, rts[a->source], ip_scope_text(a->scope),
rtd[a->dest], a->hash_key);
- if (!(a->aflags & RTAF_CACHED))
+ if (!a->cached)
debug(" !CACHED");
debug(" <-%I", a->from);
if (a->dest == RTD_UNICAST)
diff --git a/nest/rt-dev.c b/nest/rt-dev.c
index 61f025ce..b8e945cf 100644
--- a/nest/rt-dev.c
+++ b/nest/rt-dev.c
@@ -84,6 +84,7 @@ dev_ifa_notify(struct proto *P, uint flags, struct ifa *ad)
rta a0 = {
.src = src,
+ .pref = c->preference,
.source = RTS_DEVICE,
.scope = SCOPE_UNIVERSE,
.dest = RTD_UNICAST,
diff --git a/nest/rt-show.c b/nest/rt-show.c
index cccd91ab..a0c675de 100644
--- a/nest/rt-show.c
+++ b/nest/rt-show.c
@@ -60,7 +60,7 @@ rt_show_rte(struct cli *c, byte *ia, rte *e, struct rt_show_data *d, int primary
if (get_route_info)
get_route_info(e, info);
else
- bsprintf(info, " (%d)", e->pref);
+ bsprintf(info, " (%d)", a->pref);
if (d->last_table != d->tab)
rt_show_table(c, d);
diff --git a/nest/rt-table.c b/nest/rt-table.c
index eb306227..0b06be92 100644
--- a/nest/rt-table.c
+++ b/nest/rt-table.c
@@ -286,7 +286,6 @@ rte_get_temp(rta *a)
e->attrs = a;
e->id = 0;
e->flags = 0;
- e->pref = 0;
return e;
}
@@ -533,9 +532,9 @@ rte_better(rte *new, rte *old)
if (!rte_is_valid(new))
return 0;
- if (new->pref > old->pref)
+ if (new->attrs->pref > old->attrs->pref)
return 1;
- if (new->pref < old->pref)
+ if (new->attrs->pref < old->attrs->pref)
return 0;
if (new->attrs->src->proto->proto != old->attrs->src->proto->proto)
{
@@ -559,7 +558,7 @@ rte_mergable(rte *pri, rte *sec)
if (!rte_is_valid(pri) || !rte_is_valid(sec))
return 0;
- if (pri->pref != sec->pref)
+ if (pri->attrs->pref != sec->attrs->pref)
return 0;
if (pri->attrs->src->proto->proto != sec->attrs->src->proto->proto)
@@ -1080,7 +1079,6 @@ rte_same(rte *x, rte *y)
return
x->attrs == y->attrs &&
x->pflags == y->pflags &&
- x->pref == y->pref &&
(!x->attrs->src->proto->rte_same || x->attrs->src->proto->rte_same(x, y)) &&
rte_is_filtered(x) == rte_is_filtered(y);
}
@@ -1469,9 +1467,6 @@ rte_update2(struct channel *c, const net_addr *n, rte *new, struct rte_src *src)
new->net = nn;
new->sender = c;
- if (!new->pref)
- new->pref = c->preference;
-
stats->imp_updates_received++;
if (!rte_validate(new))
{
@@ -1710,7 +1705,7 @@ rte_dump(rte *e)
{
net *n = e->net;
debug("%-1N ", n->n.addr);
- debug("PF=%02x pref=%d ", e->pflags, e->pref);
+ 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);
@@ -2222,7 +2217,7 @@ rt_next_hop_update_rte(rtable *tab UNUSED, rte *old)
memcpy(mls.stack, &a->nh.label[a->nh.labels - mls.len], mls.len * sizeof(u32));
rta_apply_hostentry(a, old->attrs->hostentry, &mls);
- a->aflags = 0;
+ a->cached = 0;
rte *e = sl_alloc(rte_slab);
memcpy(e, old, sizeof(rte));
@@ -2576,9 +2571,6 @@ rte_update_in(struct channel *c, const net_addr *n, rte *new, struct rte_src *sr
{
net = net_get(tab, n);
- if (!new->pref)
- new->pref = c->preference;
-
if (!rta_is_cached(new->attrs))
new->attrs = rta_lookup(new->attrs);
}