diff options
author | Maria Matejka <mq@ucw.cz> | 2022-05-30 17:26:25 +0200 |
---|---|---|
committer | Maria Matejka <mq@ucw.cz> | 2022-05-30 17:26:25 +0200 |
commit | 41508ceac3cdd74ca705d3bfc6a79464bf38e0b5 (patch) | |
tree | 4a0506a93849b3b7e61faeeaba1af289e13d646a /nest | |
parent | 65254128e105903b6b470c6b4bb4729f56cf81bc (diff) | |
parent | 1c30b689ddd032ef8000fb7836348a48ba3184ff (diff) |
Merge commit '1c30b689ddd032ef8000fb7836348a48ba3184ff' into haugesund
Diffstat (limited to 'nest')
-rw-r--r-- | nest/rt-attr.c | 32 | ||||
-rw-r--r-- | nest/rt-dev.c | 2 | ||||
-rw-r--r-- | nest/rt-table.c | 8 |
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 5d4233dc..b0ad34e6 100644 --- a/nest/rt-dev.c +++ b/nest/rt-dev.c @@ -80,12 +80,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); rte e0 = { .attrs = rta_lookup(&a0), diff --git a/nest/rt-table.c b/nest/rt-table.c index 3d42c9de..3f3aee18 100644 --- a/nest/rt-table.c +++ b/nest/rt-table.c @@ -2705,7 +2705,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 */ @@ -2737,7 +2737,7 @@ rt_flowspec_check(rtable *tab_ip, rtable *tab_flow, const net_addr *n, rta *a, i continue; const rte *rc = &nc->routes->rte; - 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) @@ -2754,7 +2754,7 @@ static struct rte_storage * rt_flowspec_update_rte(rtable *tab, net *n, 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; @@ -3549,7 +3549,7 @@ rt_get_igp_metric(const 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) |