diff options
author | Maria Matejka <mq@ucw.cz> | 2022-06-08 11:47:49 +0200 |
---|---|---|
committer | Maria Matejka <mq@ucw.cz> | 2022-06-08 11:47:49 +0200 |
commit | cae5979871ee7aa341334f8b1af6bafc60ee9692 (patch) | |
tree | 490f68c9c5d856ab560f2194fe350cd68039cccd /proto | |
parent | 8fd3811d9d29d73570e03147eb024a4e5fde199b (diff) | |
parent | 950775f6fa3d569a9d7cd05e33538d35e895d688 (diff) |
Merge commit '950775f6fa3d569a9d7cd05e33538d35e895d688' into haugesund
There were quite a lot of conflicts in flowspec validation code which
ultimately led to some code being a bit rewritten, not only adapted from
this or that branch, yet it is still in a limit of a merge.
Diffstat (limited to 'proto')
-rw-r--r-- | proto/babel/babel.c | 18 | ||||
-rw-r--r-- | proto/bgp/attrs.c | 16 | ||||
-rw-r--r-- | proto/bgp/bgp.h | 4 | ||||
-rw-r--r-- | proto/bgp/packets.c | 11 | ||||
-rw-r--r-- | proto/ospf/rt.c | 4 | ||||
-rw-r--r-- | proto/ospf/topology.c | 15 | ||||
-rw-r--r-- | proto/perf/perf.c | 4 | ||||
-rw-r--r-- | proto/rip/rip.c | 4 | ||||
-rw-r--r-- | proto/rpki/rpki.c | 4 | ||||
-rw-r--r-- | proto/static/static.c | 6 |
10 files changed, 40 insertions, 46 deletions
diff --git a/proto/babel/babel.c b/proto/babel/babel.c index f3456369..65d2567e 100644 --- a/proto/babel/babel.c +++ b/proto/babel/babel.c @@ -677,10 +677,7 @@ babel_announce_rte(struct babel_proto *p, struct babel_entry *e) } }; - rta a0 = { - .dest = RTD_UNICAST, - .eattrs = &eattrs.l, - }; + rta a0 = { .eattrs = &eattrs.l, }; rte e0 = { .attrs = &a0, @@ -693,12 +690,11 @@ babel_announce_rte(struct babel_proto *p, struct babel_entry *e) else if (e->valid && (e->router_id != p->router_id)) { /* Unreachable */ - rta a0 = { - .dest = RTD_UNREACHABLE, - }; + rta a0 = {}; ea_set_attr_u32(&a0.eattrs, &ea_gen_preference, 0, 1); ea_set_attr_u32(&a0.eattrs, &ea_gen_source, 0, RTS_BABEL); + ea_set_dest(&a0.eattrs, 0, RTD_UNREACHABLE); rte e0 = { .attrs = &a0, @@ -2266,9 +2262,13 @@ babel_kick_timer(struct babel_proto *p) static int babel_preexport(struct channel *c, struct rte *new) { - struct rta *a = new->attrs; + if (new->src->proto != c->proto) + return 0; + /* Reject our own unreachable routes */ - if ((a->dest == RTD_UNREACHABLE) && (new->src->proto == c->proto)) + eattr *ea = ea_find(new->attrs->eattrs, &ea_gen_nexthop); + struct nexthop_adata *nhad = (void *) ea->u.ptr; + if (!NEXTHOP_IS_REACHABLE(nhad)) return -1; return 0; diff --git a/proto/bgp/attrs.c b/proto/bgp/attrs.c index ccfda4df..0b715eaa 100644 --- a/proto/bgp/attrs.c +++ b/proto/bgp/attrs.c @@ -1715,8 +1715,20 @@ bgp_preexport(struct channel *c, rte *e) return 0; /* Reject flowspec that failed validation */ - if ((e->attrs->dest == RTD_UNREACHABLE) && net_is_flow(e->net)) - return -1; + if (net_is_flow(e->net)) + switch (rt_get_flowspec_valid(e)) + { + case FLOWSPEC_VALID: + break; + case FLOWSPEC_INVALID: + return -1; + case FLOWSPEC_UNKNOWN: + ASSUME((rt_get_source_attr(e) != RTS_BGP) || + !((struct bgp_channel *) SKIP_BACK(struct channel, in_req, e->sender->req))->base_table); + break; + case FLOWSPEC__MAX: + bug("This never happens."); + } /* IBGP route reflection, RFC 4456 */ if (p->is_internal && src->is_internal && (p->local_as == src->local_as)) diff --git a/proto/bgp/bgp.h b/proto/bgp/bgp.h index 8e3ed70e..662d9d48 100644 --- a/proto/bgp/bgp.h +++ b/proto/bgp/bgp.h @@ -519,7 +519,9 @@ struct rte_source *bgp_get_source(struct bgp_proto *p, u32 path_id); static inline int rta_resolvable(rta *a) { - return a->dest != RTD_UNREACHABLE; + eattr *nhea = ea_find(a->eattrs, &ea_gen_nexthop); + struct nexthop_adata *nhad = (void *) nhea->u.ptr; + return NEXTHOP_IS_REACHABLE(nhad) || (nhad->dest != RTD_UNREACHABLE); } diff --git a/proto/bgp/packets.c b/proto/bgp/packets.c index 06b563b0..9911738d 100644 --- a/proto/bgp/packets.c +++ b/proto/bgp/packets.c @@ -968,7 +968,6 @@ bgp_apply_next_hop(struct bgp_parse_state *s, rta *a, ip_addr gw, ip_addr ll) ea_set_attr_u32(&a->eattrs, &ea_gen_igp_metric, 0, c->cf->cost); - a->dest = RTD_UNICAST; struct nexthop_adata nhad = { .nh = { .gw = nbr->addr, @@ -1003,8 +1002,7 @@ bgp_apply_mpls_labels(struct bgp_parse_state *s, rta *a, u32 lnum, u32 labels[ln { REPORT("Too many MPLS labels ($u)", lnum); - a->dest = RTD_UNREACHABLE; - ea_unset_attr(&a->eattrs, 0, &ea_gen_nexthop); + ea_set_dest(&a->eattrs, 0, RTD_UNREACHABLE); return; } @@ -1092,17 +1090,14 @@ bgp_use_gateway(struct bgp_export_state *s) if (c->cf->next_hop_self && bgp_match_src(s, c->cf->next_hop_self)) return NULL; - /* Unreachable */ - if (ra->dest != RTD_UNICAST) - return NULL; - eattr *nhea = ea_find(ra->eattrs, &ea_gen_nexthop); if (!nhea) return NULL; /* We need one valid global gateway */ struct nexthop_adata *nhad = (struct nexthop_adata *) nhea->u.ptr; - if (!NEXTHOP_ONE(nhad) || ipa_zero(nhad->nh.gw) || + if (!NEXTHOP_IS_REACHABLE(nhad) || + !NEXTHOP_ONE(nhad) || ipa_zero(nhad->nh.gw) || ipa_is_link_local(nhad->nh.gw)) return NULL; diff --git a/proto/ospf/rt.c b/proto/ospf/rt.c index 0498a3c2..1c76aee7 100644 --- a/proto/ospf/rt.c +++ b/proto/ospf/rt.c @@ -1983,8 +1983,7 @@ ort_changed(ort *nf, rta *nr) 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->dest != or->dest)) + (nf->n.tag != nf->old_tag) || (nf->n.rid != nf->old_rid)) return 1; eattr *nhea_n = ea_find(nr->eattrs, &ea_gen_nexthop); @@ -2049,7 +2048,6 @@ again1: if (nf->n.type) /* Add the route */ { rta a0 = { - .dest = RTD_UNICAST, }; struct { diff --git a/proto/ospf/topology.c b/proto/ospf/topology.c index c2b12cfc..6ff6a745 100644 --- a/proto/ospf/topology.c +++ b/proto/ospf/topology.c @@ -1366,20 +1366,11 @@ ospf_rt_notify(struct proto *P, struct channel *ch UNUSED, const net_addr *n, rt uint tag = ea_get_int(a->eattrs, &ea_ospf_tag, 0); ip_addr fwd = IPA_NONE; - if (a->dest == RTD_UNICAST) - { - eattr *nhea = ea_find(a->eattrs, &ea_gen_nexthop); - if (!nhea) - { - log(L_ERR "%s: Unicast route without nexthop for %N", - p->p.name, n); - return; - } - - struct nexthop_adata *nhad = (struct nexthop_adata *) nhea->u.ptr; + eattr *nhea = ea_find(a->eattrs, &ea_gen_nexthop); + struct nexthop_adata *nhad = (struct nexthop_adata *) nhea->u.ptr; + if (NEXTHOP_IS_REACHABLE(nhad)) if (use_gw_for_fwaddr(p, nhad->nh.gw, nhad->nh.iface)) fwd = nhad->nh.gw; - } /* NSSA-LSA with P-bit set must have non-zero forwarding address */ if (oa && ipa_zero(fwd)) diff --git a/proto/perf/perf.c b/proto/perf/perf.c index 71925bf1..8a883dd7 100644 --- a/proto/perf/perf.c +++ b/proto/perf/perf.c @@ -142,9 +142,7 @@ perf_loop(void *data) *((net_addr_ip4 *) &(p->data[i].net)) = random_net_ip4(); if (!p->attrs_per_rte || !(i % p->attrs_per_rte)) { - struct rta a0 = { - .dest = RTD_UNICAST, - }; + struct rta a0 = {}; 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); diff --git a/proto/rip/rip.c b/proto/rip/rip.c index 5a66a1be..cc8b57eb 100644 --- a/proto/rip/rip.c +++ b/proto/rip/rip.c @@ -151,9 +151,7 @@ rip_announce_rte(struct rip_proto *p, struct rip_entry *en) if (rt) { /* Update */ - rta a0 = { - .dest = RTD_UNICAST, - }; + rta a0 = {}; struct { ea_list l; diff --git a/proto/rpki/rpki.c b/proto/rpki/rpki.c index 96a794fa..c8b0ff67 100644 --- a/proto/rpki/rpki.c +++ b/proto/rpki/rpki.c @@ -120,9 +120,7 @@ rpki_table_add_roa(struct rpki_cache *cache, struct channel *channel, const net_ { struct rpki_proto *p = cache->p; - rta a0 = { - .dest = RTD_NONE, - }; + rta a0 = {}; ea_set_attr_u32(&a0.eattrs, &ea_gen_preference, 0, channel->preference); ea_set_attr_u32(&a0.eattrs, &ea_gen_source, 0, RTS_RPKI); diff --git a/proto/static/static.c b/proto/static/static.c index 038ee018..6369fea5 100644 --- a/proto/static/static.c +++ b/proto/static/static.c @@ -55,7 +55,6 @@ 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->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); @@ -97,7 +96,7 @@ static_announce_rte(struct static_proto *p, struct static_route *r) nhad->ad.data, (void *) nh - (void *) nhad->ad.data); } - if (r->dest == RTDX_RECURSIVE) + else if (r->dest == RTDX_RECURSIVE) { rtable *tab = ipa_is_ip4(r->via) ? p->igp_table_ip4 : p->igp_table_ip6; u32 *labels = r->mls ? (void *) r->mls->data : NULL; @@ -107,6 +106,9 @@ static_announce_rte(struct static_proto *p, struct static_route *r) r->via, IPA_NONE, lnum, labels); } + else if (r->dest) + ea_set_dest(&a->eattrs, 0, r->dest); + /* Already announced */ if (r->state == SRS_CLEAN) return; |