From 1c30b689ddd032ef8000fb7836348a48ba3184ff Mon Sep 17 00:00:00 2001 From: Maria Matejka Date: Wed, 4 May 2022 14:41:51 +0200 Subject: Moved route source attribute (RTS_*) to eattrs --- proto/babel/babel.c | 6 +++--- proto/bgp/attrs.c | 2 +- proto/bgp/config.Y | 2 +- proto/bgp/packets.c | 2 +- proto/ospf/ospf.c | 22 +++++++++++++--------- proto/ospf/rt.c | 21 ++++++++++++++++----- proto/perf/perf.c | 2 +- proto/rip/rip.c | 4 ++-- proto/rpki/rpki.c | 2 +- proto/static/static.c | 2 +- 10 files changed, 40 insertions(+), 25 deletions(-) (limited to 'proto') diff --git a/proto/babel/babel.c b/proto/babel/babel.c index cd221c7b..a7dcee09 100644 --- a/proto/babel/babel.c +++ b/proto/babel/babel.c @@ -645,12 +645,13 @@ babel_announce_rte(struct babel_proto *p, struct babel_entry *e) { struct { ea_list l; - eattr a[5]; + eattr a[6]; } eattrs = { .l.count = ARRAY_SIZE(eattrs.a), .a = { EA_LITERAL_EMBEDDED(&ea_gen_preference, 0, c->preference), EA_LITERAL_STORE_ADATA(&ea_gen_from, 0, &r->neigh->addr, sizeof(r->neigh->addr)), + EA_LITERAL_EMBEDDED(&ea_gen_source, 0, RTS_BABEL), EA_LITERAL_EMBEDDED(&ea_babel_metric, 0, r->metric), EA_LITERAL_STORE_ADATA(&ea_babel_router_id, 0, &r->router_id, sizeof(r->router_id)), EA_LITERAL_EMBEDDED(&ea_babel_seqno, 0, r->seqno), @@ -658,7 +659,6 @@ babel_announce_rte(struct babel_proto *p, struct babel_entry *e) }; rta a0 = { - .source = RTS_BABEL, .dest = RTD_UNICAST, .nh.gw = r->next_hop, .nh.iface = r->neigh->ifa->iface, @@ -683,11 +683,11 @@ babel_announce_rte(struct babel_proto *p, struct babel_entry *e) { /* Unreachable */ rta a0 = { - .source = RTS_BABEL, .dest = RTD_UNREACHABLE, }; ea_set_attr_u32(&a0.eattrs, &ea_gen_preference, 0, 1); + ea_set_attr_u32(&a0.eattrs, &ea_gen_source, 0, RTS_BABEL); rta *a = rta_lookup(&a0); rte *rte = rte_get_temp(a, p->p.main_source); diff --git a/proto/bgp/attrs.c b/proto/bgp/attrs.c index 097ba9a2..1efc26ce 100644 --- a/proto/bgp/attrs.c +++ b/proto/bgp/attrs.c @@ -402,7 +402,7 @@ bgp_total_aigp_metric_(rte *e, u64 *metric, const struct adata **ad) static inline int bgp_init_aigp_metric(rte *e, u64 *metric, const struct adata **ad) { - if (e->attrs->source == RTS_BGP) + if (rt_get_source_attr(e) == RTS_BGP) return 0; *metric = rt_get_igp_metric(e); diff --git a/proto/bgp/config.Y b/proto/bgp/config.Y index b4d8b83f..24f3ec8f 100644 --- a/proto/bgp/config.Y +++ b/proto/bgp/config.Y @@ -43,7 +43,7 @@ CF_KEYWORDS(CEASE, PREFIX, LIMIT, HIT, ADMINISTRATIVE, SHUTDOWN, RESET, PEER, CF_GRAMMAR -toksym: BGP_MED | BGP_LOCAL_PREF ; +toksym: BGP_MED | BGP_LOCAL_PREF | SOURCE ; proto: bgp_proto '}' ; diff --git a/proto/bgp/packets.c b/proto/bgp/packets.c index 62d60e9a..0aa4dc40 100644 --- a/proto/bgp/packets.c +++ b/proto/bgp/packets.c @@ -2474,11 +2474,11 @@ bgp_decode_nlri(struct bgp_parse_state *s, u32 afi, byte *nlri, uint len, ea_lis { a = allocz(RTA_MAX_SIZE); - a->source = RTS_BGP; a->eattrs = ea; ea_set_attr_data(&a->eattrs, &ea_gen_from, 0, &s->proto->remote_ip, sizeof(ip_addr)); ea_set_attr_u32(&a->eattrs, &ea_gen_preference, 0, c->c.preference); + ea_set_attr_u32(&a->eattrs, &ea_gen_source, 0, RTS_BGP); c->desc->decode_next_hop(s, nh, nh_len, a); bgp_finish_attrs(s, a); diff --git a/proto/ospf/ospf.c b/proto/ospf/ospf.c index 427c2c86..731adaa5 100644 --- a/proto/ospf/ospf.c +++ b/proto/ospf/ospf.c @@ -392,15 +392,18 @@ ospf_rte_better(struct rte *new, struct rte *old) if (new_metric1 == LSINFINITY) return 0; - if(new->attrs->source < old->attrs->source) return 1; - if(new->attrs->source > old->attrs->source) return 0; + u32 ns = rt_get_source_attr(new); + u32 os = rt_get_source_attr(old); - if(new->attrs->source == RTS_OSPF_EXT2) + if (ns < os) return 1; + if (ns > os) return 0; + + if (ns == RTS_OSPF_EXT2) { u32 old_metric2 = ea_get_int(old->attrs->eattrs, &ea_ospf_metric2, LSINFINITY); u32 new_metric2 = ea_get_int(new->attrs->eattrs, &ea_ospf_metric2, LSINFINITY); - if(new_metric2 < old_metric2) return 1; - if(new_metric2 > old_metric2) return 0; + if (new_metric2 < old_metric2) return 1; + if (new_metric2 > old_metric2) return 0; } u32 old_metric1 = ea_get_int(old->attrs->eattrs, &ea_ospf_metric1, LSINFINITY); @@ -413,7 +416,7 @@ ospf_rte_better(struct rte *new, struct rte *old) static u32 ospf_rte_igp_metric(struct rte *rt) { - if (rt->attrs->source == RTS_OSPF_EXT2) + if (rt_get_source_attr(rt) == RTS_OSPF_EXT2) return IGP_METRIC_UNKNOWN; return ea_get_int(rt->attrs->eattrs, &ea_ospf_metric1, LSINFINITY); @@ -571,7 +574,8 @@ ospf_get_route_info(rte * rte, byte * buf) { char *type = ""; - switch (rte->attrs->source) + uint source = rt_get_source_attr(rte); + switch (source) { case RTS_OSPF: type = "I"; @@ -589,10 +593,10 @@ ospf_get_route_info(rte * rte, byte * buf) buf += bsprintf(buf, " %s", type); buf += bsprintf(buf, " (%d/%d", rt_get_preference(rte), ea_get_int(rte->attrs->eattrs, &ea_ospf_metric1, LSINFINITY)); - if (rte->attrs->source == RTS_OSPF_EXT2) + if (source == RTS_OSPF_EXT2) buf += bsprintf(buf, "/%d", ea_get_int(rte->attrs->eattrs, &ea_ospf_metric2, LSINFINITY)); buf += bsprintf(buf, ")"); - if (rte->attrs->source == RTS_OSPF_EXT1 || rte->attrs->source == RTS_OSPF_EXT2) + if (source == RTS_OSPF_EXT1 || source == RTS_OSPF_EXT2) { eattr *ea = ea_find(rte->attrs->eattrs, &ea_ospf_tag); if (ea && (ea->u.data > 0)) diff --git a/proto/ospf/rt.c b/proto/ospf/rt.c index ddc5b162..91739056 100644 --- a/proto/ospf/rt.c +++ b/proto/ospf/rt.c @@ -2004,11 +2004,19 @@ static inline int ort_changed(ort *nf, rta *nr) { rta *or = nf->old_rta; - return !or || + + if (!or || (nf->n.metric1 != nf->old_metric1) || (nf->n.metric2 != nf->old_metric2) || (nf->n.tag != nf->old_tag) || (nf->n.rid != nf->old_rid) || - (nr->source != or->source) || (nr->dest != or->dest) || - !nexthop_same(&(nr->nh), &(or->nh)); + (nr->dest != or->dest) || + !nexthop_same(&(nr->nh), &(or->nh))) + return 1; + + if ( ea_get_int(nr->eattrs, &ea_gen_source, 0) + != ea_get_int(or->eattrs, &ea_gen_source, 0)) + return 1; + + return 0; } static void @@ -2053,7 +2061,6 @@ again1: if (nf->n.type) /* Add the route */ { rta a0 = { - .source = nf->n.type, .dest = RTD_UNICAST, .nh = *(nf->n.nhs), }; @@ -2067,7 +2074,7 @@ again1: struct { ea_list l; - eattr a[5]; + eattr a[6]; } eattrs; eattrs.l = (ea_list) {}; @@ -2075,6 +2082,9 @@ again1: eattrs.a[eattrs.l.count++] = EA_LITERAL_EMBEDDED(&ea_gen_preference, 0, p->p.main_channel->preference); + eattrs.a[eattrs.l.count++] = + EA_LITERAL_EMBEDDED(&ea_gen_source, 0, nf->n.type); + eattrs.a[eattrs.l.count++] = EA_LITERAL_EMBEDDED(&ea_ospf_metric1, 0, nf->n.metric1); @@ -2089,6 +2099,7 @@ again1: eattrs.a[eattrs.l.count++] = EA_LITERAL_EMBEDDED(&ea_ospf_router_id, 0, nf->n.rid); + ASSERT_DIE(ARRAY_SIZE(eattrs.a) >= eattrs.l.count); a0.eattrs = &eattrs.l; rta *a = rta_lookup(&a0); diff --git a/proto/perf/perf.c b/proto/perf/perf.c index 47a2867d..4329556c 100644 --- a/proto/perf/perf.c +++ b/proto/perf/perf.c @@ -143,7 +143,6 @@ perf_loop(void *data) if (!p->attrs_per_rte || !(i % p->attrs_per_rte)) { struct rta a0 = { - .source = RTS_PERF, .dest = RTD_UNICAST, .nh.iface = p->ifa->iface, .nh.gw = gw, @@ -151,6 +150,7 @@ perf_loop(void *data) }; ea_set_attr_u32(&a0.eattrs, &ea_gen_preference, 0, p->p.main_channel->preference); + ea_set_attr_u32(&a0.eattrs, &ea_gen_source, 0, RTS_PERF); p->data[i].a = rta_lookup(&a0); } diff --git a/proto/rip/rip.c b/proto/rip/rip.c index f5442606..f7f34c27 100644 --- a/proto/rip/rip.c +++ b/proto/rip/rip.c @@ -152,17 +152,17 @@ rip_announce_rte(struct rip_proto *p, struct rip_entry *en) { /* Update */ rta a0 = { - .source = RTS_RIP, .dest = RTD_UNICAST, }; struct { ea_list l; - eattr a[2]; + eattr a[3]; } ea_block = { .l.count = ARRAY_SIZE(ea_block.a), .a = { EA_LITERAL_EMBEDDED(&ea_gen_preference, 0, p->p.main_channel->preference), + EA_LITERAL_EMBEDDED(&ea_gen_source, 0, RTS_RIP), EA_LITERAL_EMBEDDED(&ea_rip_metric, 0, rt->metric), }, }; diff --git a/proto/rpki/rpki.c b/proto/rpki/rpki.c index af963f49..56d8add2 100644 --- a/proto/rpki/rpki.c +++ b/proto/rpki/rpki.c @@ -121,11 +121,11 @@ rpki_table_add_roa(struct rpki_cache *cache, struct channel *channel, const net_ struct rpki_proto *p = cache->p; rta a0 = { - .source = RTS_RPKI, .dest = RTD_NONE, }; ea_set_attr_u32(&a0.eattrs, &ea_gen_preference, 0, channel->preference); + ea_set_attr_u32(&a0.eattrs, &ea_gen_source, 0, RTS_RPKI); rta *a = rta_lookup(&a0); rte *e = rte_get_temp(a, p->p.main_source); diff --git a/proto/static/static.c b/proto/static/static.c index ff833b16..1400e985 100644 --- a/proto/static/static.c +++ b/proto/static/static.c @@ -55,9 +55,9 @@ static_announce_rte(struct static_proto *p, struct static_route *r) { rta *a = allocz(RTA_MAX_SIZE); struct rte_src *src = static_get_source(p, r->index); - a->source = RTS_STATIC; a->dest = r->dest; ea_set_attr_u32(&a->eattrs, &ea_gen_preference, 0, p->p.main_channel->preference); + ea_set_attr_u32(&a->eattrs, &ea_gen_source, 0, RTS_STATIC); if (r->dest == RTD_UNICAST) { -- cgit v1.2.3