summaryrefslogtreecommitdiff
path: root/nest
diff options
context:
space:
mode:
authorMaria Matejka <mq@ucw.cz>2022-05-04 14:41:51 +0200
committerMaria Matejka <mq@ucw.cz>2022-05-04 15:39:53 +0200
commit1c30b689ddd032ef8000fb7836348a48ba3184ff (patch)
treec2fdb9a74c235af77e3587eb7c5c762dcdc62dd4 /nest
parent702c04fbef222e802ca4dfac645dc75ede522db6 (diff)
Moved route source attribute (RTS_*) to eattrs
Diffstat (limited to 'nest')
-rw-r--r--nest/rt-attr.c32
-rw-r--r--nest/rt-dev.c2
-rw-r--r--nest/rt-table.c8
3 files changed, 25 insertions, 17 deletions
diff --git a/nest/rt-attr.c b/nest/rt-attr.c
index a892bfd5..39fd7db4 100644
--- a/nest/rt-attr.c
+++ b/nest/rt-attr.c
@@ -92,6 +92,22 @@ const char * const rta_src_names[RTS_MAX] = {
[RTS_RPKI] = "RPKI",
};
+static void
+ea_gen_source_format(const eattr *a, byte *buf, uint size)
+{
+ if ((a->u.data >= RTS_MAX) || !rta_src_names[a->u.data])
+ bsnprintf(buf, size, "unknown");
+ else
+ bsnprintf(buf, size, "%s", rta_src_names[a->u.data]);
+}
+
+struct ea_class ea_gen_source = {
+ .name = "source",
+ .type = T_ENUM_RTS,
+ .readonly = 1,
+ .format = ea_gen_source_format,
+};
+
const char * rta_dest_names[RTD_MAX] = {
[RTD_NONE] = "",
[RTD_UNICAST] = "unicast",
@@ -1234,7 +1250,6 @@ rta_hash(rta *a)
#define MIX(f) mem_hash_mix(&h, &(a->f), sizeof(a->f));
#define BMIX(f) mem_hash_mix_num(&h, a->f);
MIX(hostentry);
- BMIX(source);
BMIX(dest);
#undef MIX
@@ -1244,8 +1259,7 @@ rta_hash(rta *a)
static inline int
rta_same(rta *x, rta *y)
{
- return (x->source == y->source &&
- x->dest == y->dest &&
+ return (x->dest == y->dest &&
x->hostentry == y->hostentry &&
nexthop_same(&(x->nh), &(y->nh)) &&
ea_same(x->eattrs, y->eattrs));
@@ -1388,15 +1402,10 @@ rta_do_cow(rta *o, linpool *lp)
void
rta_dump(rta *a)
{
- static char *rts[] = { "", "RTS_STATIC", "RTS_INHERIT", "RTS_DEVICE",
- "RTS_STAT_DEV", "RTS_REDIR", "RTS_RIP",
- "RTS_OSPF", "RTS_OSPF_IA", "RTS_OSPF_EXT1",
- "RTS_OSPF_EXT2", "RTS_BGP", "RTS_PIPE", "RTS_BABEL" };
static char *rtd[] = { "", " DEV", " HOLE", " UNREACH", " PROHIBIT" };
- debug("uc=%d %s %s h=%04x",
- a->uc, rts[a->source],
- rtd[a->dest], a->hash_key);
+ debug("uc=%d %s h=%04x",
+ a->uc, rtd[a->dest], a->hash_key);
if (!a->cached)
debug(" !CACHED");
if (a->dest == RTD_UNICAST)
@@ -1441,8 +1450,6 @@ rta_dump_all(void)
void
rta_show(struct cli *c, rta *a)
{
- cli_printf(c, -1008, "\tType: %s", rta_src_names[a->source]);
-
for(ea_list *eal = a->eattrs; eal; eal=eal->next)
for(int i=0; i<eal->count; i++)
ea_show(c, &eal->attrs[i]);
@@ -1476,6 +1483,7 @@ rta_init(void)
ea_register_init(&ea_gen_preference);
ea_register_init(&ea_gen_igp_metric);
ea_register_init(&ea_gen_from);
+ ea_register_init(&ea_gen_source);
}
/*
diff --git a/nest/rt-dev.c b/nest/rt-dev.c
index ffd5afd5..af6506f6 100644
--- a/nest/rt-dev.c
+++ b/nest/rt-dev.c
@@ -83,12 +83,12 @@ dev_ifa_notify(struct proto *P, uint flags, struct ifa *ad)
struct rte_src *src = rt_get_source(P, ad->iface->index);
rta a0 = {
- .source = RTS_DEVICE,
.dest = RTD_UNICAST,
.nh.iface = ad->iface,
};
ea_set_attr_u32(&a0.eattrs, &ea_gen_preference, 0, c->preference);
+ ea_set_attr_u32(&a0.eattrs, &ea_gen_source, 0, RTS_DEVICE);
a = rta_lookup(&a0);
e = rte_get_temp(a, src);
diff --git a/nest/rt-table.c b/nest/rt-table.c
index e8b04e0b..4f119ac0 100644
--- a/nest/rt-table.c
+++ b/nest/rt-table.c
@@ -2588,7 +2588,7 @@ rt_flowspec_check(rtable *tab_ip, rtable *tab_flow, const net_addr *n, rta *a, i
trie_add_prefix(tab_flow->flowspec_trie, &dst, (nb ? nb->n.addr->pxlen : 0), max_pxlen);
/* No best-match BGP route -> no flowspec */
- if (!rb || (rb->attrs->source != RTS_BGP))
+ if (!rb || (rt_get_source_attr(rb) != RTS_BGP))
return 0;
/* Find ORIGINATOR_ID values */
@@ -2620,7 +2620,7 @@ rt_flowspec_check(rtable *tab_ip, rtable *tab_flow, const net_addr *n, rta *a, i
continue;
rte *rc = nc->routes;
- if (rc->attrs->source != RTS_BGP)
+ if (rt_get_source_attr(rc) != RTS_BGP)
return 0;
if (rta_get_first_asn(rc->attrs) != asn_b)
@@ -2637,7 +2637,7 @@ static rte *
rt_flowspec_update_rte(rtable *tab, rte *r)
{
#ifdef CONFIG_BGP
- if (r->attrs->source != RTS_BGP)
+ if (rt_get_source_attr(r) != RTS_BGP)
return NULL;
struct bgp_channel *bc = (struct bgp_channel *) r->sender;
@@ -3471,7 +3471,7 @@ rt_get_igp_metric(rte *rt)
if (ea)
return ea->u.data;
- if (rt->attrs->source == RTS_DEVICE)
+ if (rt_get_source_attr(rt) == RTS_DEVICE)
return 0;
if (rt->src->proto->rte_igp_metric)