diff options
author | Maria Matejka <mq@ucw.cz> | 2022-03-09 10:56:06 +0100 |
---|---|---|
committer | Maria Matejka <mq@ucw.cz> | 2022-03-09 10:56:06 +0100 |
commit | 83d9920f90738e4df75b3cf57335b43c094051cd (patch) | |
tree | ef427685ad08c0ca468db1c0c2f462c3b79b3c14 /nest | |
parent | ff47cd80dd04bc11692248a40cbf52ee8d351064 (diff) | |
parent | 5cff1d5f022755df61af6fc21cc4f2e5d384404e (diff) |
Merge commit '5cff1d5f' into haugesund
Conflicts:
proto/bgp/attrs.c
proto/pipe/pipe.c
Diffstat (limited to 'nest')
-rw-r--r-- | nest/route.h | 23 | ||||
-rw-r--r-- | nest/rt-attr.c | 30 | ||||
-rw-r--r-- | nest/rt-dev.c | 4 | ||||
-rw-r--r-- | nest/rt-show.c | 8 | ||||
-rw-r--r-- | nest/rt-table.c | 73 |
5 files changed, 64 insertions, 74 deletions
diff --git a/nest/route.h b/nest/route.h index 75890a71..19c13538 100644 --- a/nest/route.h +++ b/nest/route.h @@ -255,12 +255,12 @@ 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 */ byte flags; /* Flags (REF_...) */ byte pflags; /* Protocol-specific flags */ - word pref; /* Route preference */ btime lastmod; /* Last modified */ union { /* Protocol-dependent data (metrics etc.) */ #ifdef CONFIG_RIP @@ -352,7 +352,7 @@ net *net_get(rtable *tab, const net_addr *addr); net *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); @@ -487,14 +487,14 @@ 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) */ - u8 source; /* Route source (RTS_...) */ - u8 scope; /* Route scope (SCOPE_... -- see ip.h) */ - u8 dest; /* Route destination type (RTD_...) */ - u8 aflags; + u16 cached:1; /* Are attributes cached? */ + u16 source:7; /* Route source (RTS_...) */ + u16 scope:4; /* Route scope (SCOPE_... -- see ip.h) */ + u16 dest:4; /* Route destination type (RTD_...) */ + word pref; struct nexthop nh; /* Next hop */ } rta; @@ -516,11 +516,6 @@ typedef struct rta { #define RTS_PERF 15 /* Perf checker */ #define RTS_MAX 16 -#define RTC_UNICAST 0 -#define RTC_BROADCAST 1 -#define RTC_MULTICAST 2 -#define RTC_ANYCAST 3 /* IPv6 Anycast */ - #define RTD_NONE 0 /* Undefined next hop */ #define RTD_UNICAST 1 /* Next hop is neighbor router */ #define RTD_BLACKHOLE 2 /* Silently drop packets */ @@ -528,8 +523,6 @@ typedef struct rta { #define RTD_PROHIBIT 4 /* Administratively prohibited */ #define RTD_MAX 5 -#define RTAF_CACHED 1 /* This is a cached rta */ - #define IGP_METRIC_UNKNOWN 0x80000000 /* Default igp_metric used when no other protocol-specific metric is availabe */ @@ -718,7 +711,7 @@ void rta_init(void); static inline size_t rta_size(const rta *a) { return sizeof(rta) + sizeof(u32)*a->nh.labels; } #define RTA_MAX_SIZE (sizeof(rta) + sizeof(u32)*MPLS_MAX_LABEL_STACK) rta *rta_lookup(rta *); /* Get rta equivalent to this one, uc++ */ -static inline int rta_is_cached(rta *r) { return r->aflags & RTAF_CACHED; } +static inline int rta_is_cached(rta *r) { return r->cached; } static inline rta *rta_clone(rta *r) { r->uc++; return r; } void rta__free(rta *r); static inline void rta_free(rta *r) { if (r && !--r->uc) rta__free(r); } diff --git a/nest/rt-attr.c b/nest/rt-attr.c index c630aa95..4057bf37 100644 --- a/nest/rt-attr.c +++ b/nest/rt-attr.c @@ -1104,13 +1104,14 @@ rta_hash(rta *a) u64 h; mem_hash_init(&h); #define MIX(f) mem_hash_mix(&h, &(a->f), sizeof(a->f)); - MIX(src); +#define BMIX(f) mem_hash_mix_num(&h, a->f); MIX(hostentry); MIX(from); MIX(igp_metric); - MIX(source); - MIX(scope); - MIX(dest); + BMIX(source); + BMIX(scope); + BMIX(dest); + MIX(pref); #undef MIX return mem_hash_value(&h) ^ nexthop_hash(&(a->nh)) ^ ea_hash(a->eattrs); @@ -1119,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 && @@ -1198,7 +1198,7 @@ rta_lookup(rta *o) rta *r; uint h; - ASSERT(!(o->aflags & RTAF_CACHED)); + ASSERT(!o->cached); if (o->eattrs) ea_normalize(o->eattrs); @@ -1209,8 +1209,7 @@ rta_lookup(rta *o) r = rta_copy(o); r->hash_key = h; - r->aflags = RTAF_CACHED; - rt_lock_source(r->src); + r->cached = 1; rt_lock_hostentry(r->hostentry); rta_insert(r); @@ -1223,17 +1222,16 @@ rta_lookup(rta *o) void rta__free(rta *a) { - ASSERT(rta_cache_count && (a->aflags & RTAF_CACHED)); + ASSERT(rta_cache_count && a->cached); rta_cache_count--; *a->pprev = a->next; 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); - a->aflags = 0; /* Poison the entry */ + a->cached = 0; sl_free(rta_slab(a), a); } @@ -1248,7 +1246,7 @@ rta_do_cow(rta *o, linpool *lp) memcpy(*nhn, nho, nexthop_size(nho)); nhn = &((*nhn)->next); } - r->aflags = 0; + r->cached = 0; r->uc = 0; return r; } @@ -1268,10 +1266,10 @@ rta_dump(rta *a) "RTS_OSPF_EXT2", "RTS_BGP", "RTS_PIPE", "RTS_BABEL" }; static char *rtd[] = { "", " DEV", " HOLE", " UNREACH", " PROHIBIT" }; - debug("p=%s uc=%d %s %s%s h=%04x", - a->src->proto->name, 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->aflags & RTAF_CACHED)) + if (!a->cached) debug(" !CACHED"); debug(" <-%I", a->from); if (a->dest == RTD_UNICAST) diff --git a/nest/rt-dev.c b/nest/rt-dev.c index 61f025ce..e2e65926 100644 --- a/nest/rt-dev.c +++ b/nest/rt-dev.c @@ -83,7 +83,7 @@ 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, .dest = RTD_UNICAST, @@ -91,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 b24befa2..35342180 100644 --- a/nest/rt-show.c +++ b/nest/rt-show.c @@ -57,17 +57,17 @@ 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 - bsprintf(info, " (%d)", e->pref); + bsprintf(info, " (%d)", a->pref); if (d->last_table != d->tab) 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 36bf1364..65ff2a59 100644 --- a/nest/rt-table.c +++ b/nest/rt-table.c @@ -548,7 +548,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; } @@ -563,14 +563,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; - e->pref = 0; + rt_lock_source(e->src = src); return e; } @@ -580,6 +580,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; @@ -626,6 +628,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); @@ -634,6 +637,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); } @@ -758,7 +762,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; @@ -787,7 +791,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; @@ -817,20 +821,20 @@ rte_better(rte *new, rte *old) if (!rte_is_valid(new)) return 0; - if (new->pref > old->pref) + if (new->attrs->pref > old->attrs->pref) return 1; - if (new->pref < old->pref) + 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; } @@ -843,13 +847,13 @@ rte_mergable(rte *pri, rte *sec) if (!rte_is_valid(pri) || !rte_is_valid(sec)) return 0; - if (pri->pref != sec->pref) + 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; @@ -1377,8 +1381,8 @@ rte_same(rte *x, rte *y) return x->attrs == y->attrs && x->pflags == y->pflags && - x->pref == y->pref && - (!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); } @@ -1399,7 +1403,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 @@ -1766,9 +1770,6 @@ rte_update2(struct channel *c, const net_addr *n, rte *new, struct rte_src *src) new->net = nn; new->sender = c; - if (!new->pref) - new->pref = c->preference; - stats->imp_updates_received++; if (!rte_validate(new)) { @@ -1863,7 +1864,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(); } @@ -1883,7 +1884,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(); @@ -2007,10 +2008,10 @@ rte_dump(rte *e) { net *n = e->net; debug("%-1N ", n->n.addr); - debug("PF=%02x pref=%d ", e->pflags, e->pref); + 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"); } @@ -2724,11 +2725,12 @@ rt_next_hop_update_rte(rtable *tab UNUSED, rte *old) memcpy(mls.stack, &a->nh.label[a->nh.labels - mls.len], mls.len * sizeof(u32)); rta_apply_hostentry(a, old->attrs->hostentry, &mls); - a->aflags = 0; + a->cached = 0; rte *e = sl_alloc(rte_slab); memcpy(e, old, sizeof(rte)); e->attrs = rta_lookup(a); + rt_lock_source(e->src); return e; } @@ -2856,7 +2858,7 @@ rt_flowspec_update_rte(rtable *tab, rte *r) return NULL; const net_addr *n = r->net->n.addr; - struct bgp_proto *p = (void *) r->attrs->src->proto; + struct bgp_proto *p = (void *) r->src->proto; int valid = rt_flowspec_check(r->u.bgp.base_table, tab, n, r->attrs, p->is_interior); int dest = valid ? RTD_NONE : RTD_UNREACHABLE; @@ -2866,7 +2868,7 @@ rt_flowspec_update_rte(rtable *tab, rte *r) rta *a = alloca(RTA_MAX_SIZE); memcpy(a, r->attrs, rta_size(r->attrs)); a->dest = dest; - a->aflags = 0; + a->cached = 0; rte *new = sl_alloc(rte_slab); memcpy(new, r, sizeof(rte)); @@ -2906,8 +2908,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); @@ -3240,9 +3242,6 @@ rte_update_in(struct channel *c, const net_addr *n, rte *new, struct rte_src *sr { net = net_get(tab, n); - if (!new->pref) - new->pref = c->preference; - if (!rta_is_cached(new->attrs)) new->attrs = rta_lookup(new->attrs); } @@ -3256,7 +3255,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)) { @@ -3361,7 +3360,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; @@ -3444,7 +3443,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); @@ -3454,7 +3453,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; @@ -3462,7 +3461,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)) { |