diff --git a/filter/f-inst.c b/filter/f-inst.c index 2a837537..93886494 100644 --- a/filter/f-inst.c +++ b/filter/f-inst.c @@ -526,7 +526,7 @@ case SA_FROM: RESULT(sa.f_type, ip, rta->from); break; case SA_GW: RESULT(sa.f_type, ip, rta->nh.gw); break; case SA_NET: RESULT(sa.f_type, net, (*fs->rte)->net->n.addr); break; - case SA_PROTO: RESULT(sa.f_type, s, rta->src->proto->name); break; + case SA_PROTO: RESULT(sa.f_type, s, (*fs->rte)->src->proto->name); break; case SA_SOURCE: RESULT(sa.f_type, i, rta->source); break; case SA_SCOPE: RESULT(sa.f_type, i, rta->scope); break; case SA_DEST: RESULT(sa.f_type, i, rta->dest); break; @@ -562,7 +562,7 @@ { ip_addr ip = v1.val.ip; struct iface *ifa = ipa_is_link_local(ip) ? rta->nh.iface : NULL; - neighbor *n = neigh_find(rta->src->proto, ip, ifa, 0); + neighbor *n = neigh_find((*fs->rte)->src->proto, ip, ifa, 0); if (!n || (n->scope == SCOPE_HOST)) runtime( "Invalid gw address" ); diff --git a/nest/route.h b/nest/route.h index aec867e2..1dea058f 100644 --- a/nest/route.h +++ b/nest/route.h @@ -236,6 +236,7 @@ struct hostentry { typedef struct rte { struct rte *next; net *net; /* Network this RTE belongs to */ + struct rte_src *src; /* Route source that created the route */ struct channel *sender; /* Channel used to send the route to the routing table */ struct rta *attrs; /* Attributes of this route */ u32 id; /* Table specific route id */ @@ -326,7 +327,7 @@ static inline net *net_get(rtable *tab, const net_addr *addr) { return (net *) f void *net_route(rtable *tab, const net_addr *n); int net_roa_check(rtable *tab, const net_addr *n, u32 asn); rte *rte_find(net *net, struct rte_src *src); -rte *rte_get_temp(struct rta *); +rte *rte_get_temp(struct rta *, struct rte_src *src); void rte_update2(struct channel *c, const net_addr *n, rte *new, struct rte_src *src); /* rte_update() moved to protocol.h to avoid dependency conflicts */ int rt_examine(rtable *t, net_addr *a, struct proto *p, const struct filter *filter); @@ -441,7 +442,6 @@ typedef struct rta { u32 uc; /* Use count */ u32 hash_key; /* Hash over important fields */ struct ea_list *eattrs; /* Extended Attribute chain */ - struct rte_src *src; /* Route source that created the route */ struct hostentry *hostentry; /* Hostentry for recursive next-hops */ ip_addr from; /* Advertising router */ u32 igp_metric; /* IGP metric to next hop (for iBGP routes) */ diff --git a/nest/rt-attr.c b/nest/rt-attr.c index 4198b552..4057bf37 100644 --- a/nest/rt-attr.c +++ b/nest/rt-attr.c @@ -1105,7 +1105,6 @@ rta_hash(rta *a) 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); @@ -1121,8 +1120,7 @@ rta_hash(rta *a) static inline int rta_same(rta *x, rta *y) { - return (x->src == y->src && - x->source == y->source && + return (x->source == y->source && x->scope == y->scope && x->dest == y->dest && x->igp_metric == y->igp_metric && @@ -1212,7 +1210,6 @@ rta_lookup(rta *o) r = rta_copy(o); r->hash_key = h; r->cached = 1; - rt_lock_source(r->src); rt_lock_hostentry(r->hostentry); rta_insert(r); @@ -1231,7 +1228,6 @@ rta__free(rta *a) if (a->next) a->next->pprev = a->pprev; rt_unlock_hostentry(a->hostentry); - rt_unlock_source(a->src); if (a->nh.next) nexthop_free(a->nh.next); ea_free(a->eattrs); @@ -1270,8 +1266,8 @@ rta_dump(rta *a) "RTS_OSPF_EXT2", "RTS_BGP", "RTS_PIPE", "RTS_BABEL" }; static char *rtd[] = { "", " DEV", " HOLE", " UNREACH", " PROHIBIT" }; - 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), + debug("pref=%d uc=%d %s %s%s h=%04x", + a->pref, a->uc, rts[a->source], ip_scope_text(a->scope), rtd[a->dest], a->hash_key); if (!a->cached) debug(" !CACHED"); diff --git a/nest/rt-dev.c b/nest/rt-dev.c index b8e945cf..e2e65926 100644 --- a/nest/rt-dev.c +++ b/nest/rt-dev.c @@ -83,7 +83,6 @@ dev_ifa_notify(struct proto *P, uint flags, struct ifa *ad) struct rte_src *src = rt_get_source(P, ad->iface->index); rta a0 = { - .src = src, .pref = c->preference, .source = RTS_DEVICE, .scope = SCOPE_UNIVERSE, @@ -92,7 +91,7 @@ dev_ifa_notify(struct proto *P, uint flags, struct ifa *ad) }; a = rta_lookup(&a0); - e = rte_get_temp(a); + e = rte_get_temp(a, src); e->pflags = 0; rte_update2(c, net, e, src); } diff --git a/nest/rt-show.c b/nest/rt-show.c index a0c675de..05065134 100644 --- a/nest/rt-show.c +++ b/nest/rt-show.c @@ -56,7 +56,7 @@ rt_show_rte(struct cli *c, byte *ia, rte *e, struct rt_show_data *d, int primary if (d->verbose && !rta_is_cached(a) && a->eattrs) ea_normalize(a->eattrs); - get_route_info = a->src->proto->proto->get_route_info; + get_route_info = e->src->proto->proto->get_route_info; if (get_route_info) get_route_info(e, info); else @@ -66,7 +66,7 @@ rt_show_rte(struct cli *c, byte *ia, rte *e, struct rt_show_data *d, int primary rt_show_table(c, d); cli_printf(c, -1007, "%-20s %s [%s %s%s]%s%s", ia, rta_dest_name(a->dest), - a->src->proto->name, tm, from, primary ? (sync_error ? " !" : " *") : "", info); + e->src->proto->name, tm, from, primary ? (sync_error ? " !" : " *") : "", info); if (a->dest == RTD_UNICAST) for (nh = &(a->nh); nh; nh = nh->next) @@ -180,7 +180,7 @@ rt_show_net(struct cli *c, net *n, struct rt_show_data *d) } } - if (d->show_protocol && (d->show_protocol != e->attrs->src->proto)) + if (d->show_protocol && (d->show_protocol != e->src->proto)) goto skip; if (f_run(d->filter, &e, c->show_pool, 0) > F_ACCEPT) diff --git a/nest/rt-table.c b/nest/rt-table.c index 0b06be92..a869bb18 100644 --- a/nest/rt-table.c +++ b/nest/rt-table.c @@ -264,7 +264,7 @@ rte_find(net *net, struct rte_src *src) { rte *e = net->routes; - while (e && e->attrs->src != src) + while (e && e->src != src) e = e->next; return e; } @@ -279,13 +279,14 @@ rte_find(net *net, struct rte_src *src) * the protocol. */ rte * -rte_get_temp(rta *a) +rte_get_temp(rta *a, struct rte_src *src) { rte *e = sl_alloc(rte_slab); e->attrs = a; e->id = 0; e->flags = 0; + rt_lock_source(e->src = src); return e; } @@ -295,6 +296,8 @@ rte_do_cow(rte *r) rte *e = sl_alloc(rte_slab); memcpy(e, r, sizeof(rte)); + + rt_lock_source(e->src); e->attrs = rta_clone(r->attrs); e->flags = 0; return e; @@ -341,6 +344,7 @@ rte_cow_rta(rte *r, linpool *lp) void rte_free(rte *e) { + rt_unlock_source(e->src); if (rta_is_cached(e->attrs)) rta_free(e->attrs); sl_free(rte_slab, e); @@ -349,6 +353,7 @@ rte_free(rte *e) static inline void rte_free_quick(rte *e) { + rt_unlock_source(e->src); rta_free(e->attrs); sl_free(rte_slab, e); } @@ -473,7 +478,7 @@ void rte_make_tmp_attrs(rte **r, linpool *lp, rta **old_attrs) { void (*make_tmp_attrs)(rte *r, linpool *lp); - make_tmp_attrs = (*r)->attrs->src->proto->make_tmp_attrs; + make_tmp_attrs = (*r)->src->proto->make_tmp_attrs; if (!make_tmp_attrs) return; @@ -502,7 +507,7 @@ static void rte_store_tmp_attrs(rte *r, linpool *lp, rta *old_attrs) { void (*store_tmp_attrs)(rte *rt, linpool *lp); - store_tmp_attrs = r->attrs->src->proto->store_tmp_attrs; + store_tmp_attrs = r->src->proto->store_tmp_attrs; if (!store_tmp_attrs) return; @@ -536,16 +541,16 @@ rte_better(rte *new, rte *old) return 1; if (new->attrs->pref < old->attrs->pref) return 0; - if (new->attrs->src->proto->proto != old->attrs->src->proto->proto) + if (new->src->proto->proto != old->src->proto->proto) { /* * If the user has configured protocol preferences, so that two different protocols * have the same preference, try to break the tie by comparing addresses. Not too * useful, but keeps the ordering of routes unambiguous. */ - return new->attrs->src->proto->proto > old->attrs->src->proto->proto; + return new->src->proto->proto > old->src->proto->proto; } - if (better = new->attrs->src->proto->rte_better) + if (better = new->src->proto->rte_better) return better(new, old); return 0; } @@ -561,10 +566,10 @@ rte_mergable(rte *pri, rte *sec) if (pri->attrs->pref != sec->attrs->pref) return 0; - if (pri->attrs->src->proto->proto != sec->attrs->src->proto->proto) + if (pri->src->proto->proto != sec->src->proto->proto) return 0; - if (mergable = pri->attrs->src->proto->rte_mergable) + if (mergable = pri->src->proto->rte_mergable) return mergable(pri, sec); return 0; @@ -1079,7 +1084,8 @@ rte_same(rte *x, rte *y) return x->attrs == y->attrs && x->pflags == y->pflags && - (!x->attrs->src->proto->rte_same || x->attrs->src->proto->rte_same(x, y)) && + x->src == y->src && + (!x->src->proto->rte_same || x->src->proto->rte_same(x, y)) && rte_is_filtered(x) == rte_is_filtered(y); } @@ -1100,7 +1106,7 @@ rte_recalculate(struct channel *c, net *net, rte *new, struct rte_src *src) k = &net->routes; /* Find and remove original route from the same protocol */ while (old = *k) { - if (old->attrs->src == src) + if (old->src == src) { /* If there is the same route in the routing table but from * a different sender, then there are two paths from the @@ -1561,7 +1567,7 @@ static inline void rte_discard(rte *old) /* Non-filtered route deletion, used during garbage collection */ { rte_update_lock(); - rte_recalculate(old->sender, old->net, NULL, old->attrs->src); + rte_recalculate(old->sender, old->net, NULL, old->src); rte_update_unlock(); } @@ -1581,7 +1587,7 @@ rte_modify(rte *old) new->flags = (old->flags & ~REF_MODIFY) | REF_COW; } - rte_recalculate(old->sender, old->net, new, old->attrs->src); + rte_recalculate(old->sender, old->net, new, old->src); } rte_update_unlock(); @@ -1707,8 +1713,8 @@ rte_dump(rte *e) debug("%-1N ", n->n.addr); 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); + if (e->src->proto->proto->dump_attrs) + e->src->proto->proto->dump_attrs(e); debug("\n"); } @@ -2222,6 +2228,7 @@ rt_next_hop_update_rte(rtable *tab UNUSED, rte *old) rte *e = sl_alloc(rte_slab); memcpy(e, old, sizeof(rte)); e->attrs = rta_lookup(a); + rt_lock_source(e->src); return e; } @@ -2248,8 +2255,8 @@ rt_next_hop_update_net(rtable *tab, net *n) /* Call a pre-comparison hook */ /* Not really an efficient way to compute this */ - if (e->attrs->src->proto->rte_recalculate) - e->attrs->src->proto->rte_recalculate(tab, n, new, e, NULL); + if (e->src->proto->rte_recalculate) + e->src->proto->rte_recalculate(tab, n, new, e, NULL); if (e != old_best) rte_free_quick(e); @@ -2584,7 +2591,7 @@ rte_update_in(struct channel *c, const net_addr *n, rte *new, struct rte_src *sr /* Find the old rte */ for (pos = &net->routes; old = *pos; pos = &old->next) - if (old->attrs->src == src) + if (old->src == src) { if (new && rte_same(old, new)) { @@ -2689,7 +2696,7 @@ rt_reload_channel(struct channel *c) return 0; } - rte_update2(c, e->net->n.addr, rte_do_cow(e), e->attrs->src); + rte_update2(c, e->net->n.addr, rte_do_cow(e), e->src); } c->reload_next_rte = NULL; @@ -2772,7 +2779,7 @@ rte_update_out(struct channel *c, const net_addr *n, rte *new, rte *old0, rte ** if (new) { net = net_get(tab, n); - src = new->attrs->src; + src = new->src; rte_store_tmp_attrs(new, rte_update_pool, NULL); @@ -2782,7 +2789,7 @@ rte_update_out(struct channel *c, const net_addr *n, rte *new, rte *old0, rte ** else { net = net_find(tab, n); - src = old0->attrs->src; + src = old0->src; if (!net) goto drop_withdraw; @@ -2790,7 +2797,7 @@ rte_update_out(struct channel *c, const net_addr *n, rte *new, rte *old0, rte ** /* Find the old rte */ for (pos = &net->routes; old = *pos; pos = &old->next) - if ((c->ra_mode != RA_ANY) || (old->attrs->src == src)) + if ((c->ra_mode != RA_ANY) || (old->src == src)) { if (new && rte_same(old, new)) { diff --git a/proto/babel/babel.c b/proto/babel/babel.c index 246eea00..1d23aef7 100644 --- a/proto/babel/babel.c +++ b/proto/babel/babel.c @@ -641,7 +641,6 @@ babel_announce_rte(struct babel_proto *p, struct babel_entry *e) if (r) { rta a0 = { - .src = p->p.main_source, .source = RTS_BABEL, .scope = SCOPE_UNIVERSE, .dest = RTD_UNICAST, @@ -660,7 +659,7 @@ babel_announce_rte(struct babel_proto *p, struct babel_entry *e) a0.nh.flags = RNF_ONLINK; rta *a = rta_lookup(&a0); - rte *rte = rte_get_temp(a); + rte *rte = rte_get_temp(a, p->p.main_source); rte->u.babel.seqno = r->seqno; rte->u.babel.metric = r->metric; rte->u.babel.router_id = r->router_id; @@ -673,7 +672,6 @@ babel_announce_rte(struct babel_proto *p, struct babel_entry *e) { /* Unreachable */ rta a0 = { - .src = p->p.main_source, .source = RTS_BABEL, .scope = SCOPE_UNIVERSE, .dest = RTD_UNREACHABLE, @@ -681,7 +679,7 @@ babel_announce_rte(struct babel_proto *p, struct babel_entry *e) }; rta *a = rta_lookup(&a0); - rte *rte = rte_get_temp(a); + rte *rte = rte_get_temp(a, p->p.main_source); memset(&rte->u.babel, 0, sizeof(rte->u.babel)); rte->pflags = 0; @@ -2236,7 +2234,7 @@ babel_preexport(struct proto *P, struct rte *new) { struct rta *a = new->attrs; /* Reject our own unreachable routes */ - if ((a->dest == RTD_UNREACHABLE) && (a->src->proto == P)) + if ((a->dest == RTD_UNREACHABLE) && (new->src->proto == P)) return -1; return 0; @@ -2277,7 +2275,7 @@ babel_rt_notify(struct proto *P, struct channel *c UNUSED, struct network *net, if (new) { /* Update */ - uint internal = (new->attrs->src->proto == P); + uint internal = (new->src->proto == P); uint rt_seqno = internal ? new->u.babel.seqno : p->update_seqno; uint rt_metric = ea_get_int(new->attrs->eattrs, EA_BABEL_METRIC, 0); u64 rt_router_id = internal ? new->u.babel.router_id : p->router_id; diff --git a/proto/bgp/attrs.c b/proto/bgp/attrs.c index 3bdc7596..10706088 100644 --- a/proto/bgp/attrs.c +++ b/proto/bgp/attrs.c @@ -1663,7 +1663,7 @@ bgp_free_prefix(struct bgp_channel *c, struct bgp_prefix *px) int bgp_preexport(struct proto *P, rte *e) { - struct proto *SRC = e->attrs->src->proto; + struct proto *SRC = e->src->proto; struct bgp_proto *p = (struct bgp_proto *) P; struct bgp_proto *src = (SRC->proto == &proto_bgp) ? (struct bgp_proto *) SRC : NULL; @@ -1718,7 +1718,7 @@ bgp_preexport(struct proto *P, rte *e) static ea_list * bgp_update_attrs(struct bgp_proto *p, struct bgp_channel *c, rte *e, ea_list *attrs0, struct linpool *pool) { - struct proto *SRC = e->attrs->src->proto; + struct proto *SRC = e->src->proto; struct bgp_proto *src = (SRC->proto == &proto_bgp) ? (void *) SRC : NULL; struct bgp_export_state s = { .proto = p, .channel = c, .pool = pool, .src = src, .route = e, .mpls = c->desc->mpls }; ea_list *attrs = attrs0; @@ -1846,14 +1846,14 @@ bgp_rt_notify(struct proto *P, struct channel *C, net *n, rte *new, rte *old) /* If attributes are invalid, we fail back to withdraw */ buck = attrs ? bgp_get_bucket(c, attrs) : bgp_get_withdraw_bucket(c); - path = new->attrs->src->global_id; + path = new->src->global_id; lp_flush(bgp_linpool2); } else { buck = bgp_get_withdraw_bucket(c); - path = old->attrs->src->global_id; + path = old->src->global_id; } px = bgp_get_prefix(c, n->n.addr, c->add_path_tx ? path : 0); @@ -1873,7 +1873,7 @@ bgp_get_neighbor(rte *r) return as; /* If AS_PATH is not defined, we treat rte as locally originated */ - struct bgp_proto *p = (void *) r->attrs->src->proto; + struct bgp_proto *p = (void *) r->src->proto; return p->cf->confederation ?: p->local_as; } @@ -1893,8 +1893,8 @@ rte_stale(rte *r) int bgp_rte_better(rte *new, rte *old) { - struct bgp_proto *new_bgp = (struct bgp_proto *) new->attrs->src->proto; - struct bgp_proto *old_bgp = (struct bgp_proto *) old->attrs->src->proto; + struct bgp_proto *new_bgp = (struct bgp_proto *) new->src->proto; + struct bgp_proto *old_bgp = (struct bgp_proto *) old->src->proto; eattr *x, *y; u32 n, o; @@ -2038,8 +2038,8 @@ bgp_rte_better(rte *new, rte *old) int bgp_rte_mergable(rte *pri, rte *sec) { - struct bgp_proto *pri_bgp = (struct bgp_proto *) pri->attrs->src->proto; - struct bgp_proto *sec_bgp = (struct bgp_proto *) sec->attrs->src->proto; + struct bgp_proto *pri_bgp = (struct bgp_proto *) pri->src->proto; + struct bgp_proto *sec_bgp = (struct bgp_proto *) sec->src->proto; eattr *x, *y; u32 p, s; @@ -2123,7 +2123,7 @@ same_group(rte *r, u32 lpref, u32 lasn) static inline int use_deterministic_med(rte *r) { - struct proto *P = r->attrs->src->proto; + struct proto *P = r->src->proto; return (P->proto == &proto_bgp) && ((struct bgp_proto *) P)->cf->deterministic_med; } diff --git a/proto/bgp/packets.c b/proto/bgp/packets.c index 8d107795..b8d80513 100644 --- a/proto/bgp/packets.c +++ b/proto/bgp/packets.c @@ -1356,8 +1356,6 @@ bgp_rte_update(struct bgp_parse_state *s, net_addr *n, u32 path_id, rta *a0) /* Prepare cached route attributes */ if (s->cached_rta == NULL) { - a0->src = s->last_src; - /* Workaround for rta_lookup() breaking eattrs */ ea_list *ea = a0->eattrs; s->cached_rta = rta_lookup(a0); @@ -1365,7 +1363,7 @@ bgp_rte_update(struct bgp_parse_state *s, net_addr *n, u32 path_id, rta *a0) } rta *a = rta_clone(s->cached_rta); - rte *e = rte_get_temp(a); + rte *e = rte_get_temp(a, s->last_src); e->pflags = 0; e->u.bgp.suppressed = 0; diff --git a/proto/mrt/mrt.c b/proto/mrt/mrt.c index 8d97c860..ed9ab325 100644 --- a/proto/mrt/mrt.c +++ b/proto/mrt/mrt.c @@ -472,9 +472,9 @@ mrt_rib_table_entry(struct mrt_table_dump_state *s, rte *r) #ifdef CONFIG_BGP /* Find peer index */ - if (r->attrs->src->proto->proto == &proto_bgp) + if (r->src->proto->proto == &proto_bgp) { - struct bgp_proto *p = (void *) r->attrs->src->proto; + struct bgp_proto *p = (void *) r->src->proto; struct mrt_peer_entry *n = HASH_FIND(s->peer_hash, PEER, p->remote_id, p->remote_as, p->remote_ip); @@ -488,7 +488,7 @@ mrt_rib_table_entry(struct mrt_table_dump_state *s, rte *r) /* Path Identifier */ if (s->add_path) - mrt_put_u32(b, r->attrs->src->private_id); + mrt_put_u32(b, r->src->private_id); /* Route Attributes */ mrt_put_u16(b, 0); @@ -519,7 +519,7 @@ mrt_rib_table_dump(struct mrt_table_dump_state *s, net *n, int add_path) continue; /* Skip routes that should be reported in the other phase */ - if (!s->always_add_path && (!rt->attrs->src->private_id != !s->add_path)) + if (!s->always_add_path && (!rt->src->private_id != !s->add_path)) { s->want_add_path = 1; continue; diff --git a/proto/ospf/ospf.c b/proto/ospf/ospf.c index 4b69e011..03b16350 100644 --- a/proto/ospf/ospf.c +++ b/proto/ospf/ospf.c @@ -490,7 +490,7 @@ ospf_preexport(struct proto *P, rte *e) struct ospf_area *oa = ospf_main_area(p); /* Reject our own routes */ - if (e->attrs->src->proto == P) + if (e->src->proto == P) return -1; /* Do not export routes to stub areas */ diff --git a/proto/ospf/rt.c b/proto/ospf/rt.c index eb2aa393..cda464e0 100644 --- a/proto/ospf/rt.c +++ b/proto/ospf/rt.c @@ -2053,7 +2053,6 @@ again1: if (nf->n.type) /* Add the route */ { rta a0 = { - .src = p->p.main_source, .source = nf->n.type, .scope = SCOPE_UNIVERSE, .dest = RTD_UNICAST, @@ -2064,7 +2063,7 @@ again1: if (reload || ort_changed(nf, &a0)) { rta *a = rta_lookup(&a0); - rte *e = rte_get_temp(a); + rte *e = rte_get_temp(a, p->p.main_source); rta_free(nf->old_rta); nf->old_rta = rta_clone(a); diff --git a/proto/perf/perf.c b/proto/perf/perf.c index 692be2c0..52784c14 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 = { - .src = p->p.main_source, .source = RTS_PERF, .scope = SCOPE_UNIVERSE, .dest = RTD_UNICAST, @@ -162,7 +161,7 @@ perf_loop(void *data) clock_gettime(CLOCK_MONOTONIC, &ts_generated); for (uint i=0; idata[i].a); + rte *e = rte_get_temp(p->data[i].a, p->p.main_source); e->pflags = 0; rte_update(P, &(p->data[i].net), e); diff --git a/proto/pipe/pipe.c b/proto/pipe/pipe.c index a2fc2ddf..de86b62b 100644 --- a/proto/pipe/pipe.c +++ b/proto/pipe/pipe.c @@ -65,12 +65,14 @@ pipe_rt_notify(struct proto *P, struct channel *src_ch, net *n, rte *new, rte *o if (new) { + src = new->src; + a = alloca(rta_size(new->attrs)); memcpy(a, new->attrs, rta_size(new->attrs)); a->cached = 0; a->hostentry = NULL; - e = rte_get_temp(a); + e = rte_get_temp(a, src); e->pflags = 0; /* Copy protocol specific embedded attributes. */ @@ -79,16 +81,14 @@ pipe_rt_notify(struct proto *P, struct channel *src_ch, net *n, rte *new, rte *o #ifdef CONFIG_BGP /* Hack to cleanup cached value */ - if (e->attrs->src->proto->proto == &proto_bgp) + if (e->src->proto->proto == &proto_bgp) e->u.bgp.stale = -1; #endif - - src = a->src; } else { e = NULL; - src = old->attrs->src; + src = old->src; } src_ch->table->pipe_busy = 1; diff --git a/proto/rip/rip.c b/proto/rip/rip.c index 65147a1f..f2e56e93 100644 --- a/proto/rip/rip.c +++ b/proto/rip/rip.c @@ -145,7 +145,6 @@ rip_announce_rte(struct rip_proto *p, struct rip_entry *en) { /* Update */ rta a0 = { - .src = p->p.main_source, .pref = p->p.main_channel->preference, .source = RTS_RIP, .scope = SCOPE_UNIVERSE, @@ -190,7 +189,7 @@ rip_announce_rte(struct rip_proto *p, struct rip_entry *en) } rta *a = rta_lookup(&a0); - rte *e = rte_get_temp(a); + rte *e = rte_get_temp(a, p->p.main_source); e->u.rip.from = a0.nh.iface; e->u.rip.metric = rt_metric; @@ -340,7 +339,7 @@ rip_rt_notify(struct proto *P, struct channel *ch UNUSED, struct network *net, s en->valid = RIP_ENTRY_VALID; en->metric = rt_metric; en->tag = rt_tag; - en->from = (new->attrs->src->proto == P) ? new->u.rip.from : NULL; + en->from = (new->src->proto == P) ? new->u.rip.from : NULL; en->iface = new->attrs->nh.iface; en->next_hop = new->attrs->nh.gw; } diff --git a/proto/rpki/rpki.c b/proto/rpki/rpki.c index fefea4b4..be3d19ab 100644 --- a/proto/rpki/rpki.c +++ b/proto/rpki/rpki.c @@ -121,7 +121,6 @@ rpki_table_add_roa(struct rpki_cache *cache, struct channel *channel, const net_ struct rpki_proto *p = cache->p; rta a0 = { - .src = p->p.main_source, .pref = channel->preference, .source = RTS_RPKI, .scope = SCOPE_UNIVERSE, @@ -129,11 +128,11 @@ rpki_table_add_roa(struct rpki_cache *cache, struct channel *channel, const net_ }; rta *a = rta_lookup(&a0); - rte *e = rte_get_temp(a); + rte *e = rte_get_temp(a, p->p.main_source); e->pflags = 0; - rte_update2(channel, &pfxr->n, e, a0.src); + rte_update2(channel, &pfxr->n, e, e->src); } void diff --git a/proto/static/static.c b/proto/static/static.c index 2d141c07..6d3871cc 100644 --- a/proto/static/static.c +++ b/proto/static/static.c @@ -56,7 +56,7 @@ static void static_announce_rte(struct static_proto *p, struct static_route *r) { rta *a = allocz(RTA_MAX_SIZE); - a->src = static_get_source(p, r->index); + struct rte_src *src = static_get_source(p, r->index); a->source = RTS_STATIC; a->scope = SCOPE_UNIVERSE; a->dest = r->dest; @@ -103,7 +103,7 @@ static_announce_rte(struct static_proto *p, struct static_route *r) return; /* We skip rta_lookup() here */ - rte *e = rte_get_temp(a); + rte *e = rte_get_temp(a, src); e->pflags = 0; if (r->cmds) @@ -120,7 +120,7 @@ static_announce_rte(struct static_proto *p, struct static_route *r) e->net = NULL; } - rte_update2(p->p.main_channel, r->net, e, a->src); + rte_update2(p->p.main_channel, r->net, e, src); r->state = SRS_CLEAN; if (r->cmds) @@ -132,7 +132,7 @@ withdraw: if (r->state == SRS_DOWN) return; - rte_update2(p->p.main_channel, r->net, NULL, a->src); + rte_update2(p->p.main_channel, r->net, NULL, src); r->state = SRS_DOWN; } diff --git a/sysdep/linux/netlink.c b/sysdep/linux/netlink.c index fdf3f2db..ac092871 100644 --- a/sysdep/linux/netlink.c +++ b/sysdep/linux/netlink.c @@ -1488,7 +1488,7 @@ nl_mergable_route(struct nl_parse_state *s, net *net, struct krt_proto *p, uint static void nl_announce_route(struct nl_parse_state *s) { - rte *e = rte_get_temp(s->attrs); + rte *e = rte_get_temp(s->attrs, s->proto->p.main_source); e->net = s->net; e->u.krt.src = s->krt_src; e->u.krt.proto = s->krt_proto; @@ -1659,7 +1659,6 @@ nl_parse_route(struct nl_parse_state *s, struct nlmsghdr *h) nl_announce_route(s); rta *ra = lp_allocz(s->pool, RTA_MAX_SIZE); - ra->src = p->p.main_source; ra->source = RTS_INHERIT; ra->scope = SCOPE_UNIVERSE; diff --git a/sysdep/unix/krt.c b/sysdep/unix/krt.c index 65d8d968..c03fa047 100644 --- a/sysdep/unix/krt.c +++ b/sysdep/unix/krt.c @@ -300,7 +300,7 @@ krt_learn_announce_update(struct krt_proto *p, rte *e) { net *n = e->net; rta *aa = rta_clone(e->attrs); - rte *ee = rte_get_temp(aa); + rte *ee = rte_get_temp(aa, p->p.main_source); ee->pflags = EA_ID_FLAG(EA_KRT_SOURCE) | EA_ID_FLAG(EA_KRT_METRIC); ee->u.krt = e->u.krt; rte_update(&p->p, n->n.addr, ee); @@ -909,7 +909,7 @@ static int krt_preexport(struct proto *P, rte *e) { // struct krt_proto *p = (struct krt_proto *) P; - if (e->attrs->src->proto == P) + if (e->src->proto == P) return -1; if (!krt_capable(e))