diff options
Diffstat (limited to 'nest/rt-table.c')
-rw-r--r-- | nest/rt-table.c | 88 |
1 files changed, 42 insertions, 46 deletions
diff --git a/nest/rt-table.c b/nest/rt-table.c index 539e04d0..e3dab120 100644 --- a/nest/rt-table.c +++ b/nest/rt-table.c @@ -564,7 +564,7 @@ rte_find(net *net, struct rte_src *src) * the protocol. */ rte * -rte_get_temp(rta *a, struct rte_src *src) +rte_get_temp(ea_list *a, struct rte_src *src) { rte *e = sl_alloc(rte_slab); @@ -608,15 +608,15 @@ rte_do_cow(rte *r) * Result: a pointer to the new writable &rte with writable &rta. */ rte * -rte_cow_rta(rte *r, linpool *lp) +rte_cow_rta(rte *r) { if (!rta_is_cached(r->attrs)) return r; r = rte_cow(r); - rta *a = rta_do_cow(r->attrs, lp); + + /* This looks stupid but should DWIW. */ rta_free(r->attrs); - r->attrs = a; return r; } @@ -971,7 +971,7 @@ rt_export_merged(struct channel *c, net *net, rte **rt_free, linpool *pool, int if (rte_is_reachable(rt)) { - eattr *nhea = ea_find(rt->attrs->eattrs, &ea_gen_nexthop); + eattr *nhea = ea_find(rt->attrs, &ea_gen_nexthop); ASSERT_DIE(nhea); if (nhs) @@ -987,13 +987,13 @@ rt_export_merged(struct channel *c, net *net, rte **rt_free, linpool *pool, int if (nhs) { - eattr *nhea = ea_find(best->attrs->eattrs, &ea_gen_nexthop); + eattr *nhea = ea_find(best->attrs, &ea_gen_nexthop); ASSERT_DIE(nhea); nhs = nexthop_merge(nhs, (struct nexthop_adata *) nhea->u.ptr, c->merge_limit, pool); - best = rte_cow_rta(best, pool); - ea_set_attr(&best->attrs->eattrs, + best = rte_cow_rta(best); + ea_set_attr(&best->attrs, EA_LITERAL_DIRECT_ADATA(&ea_gen_nexthop, 0, &nhs->ad)); } @@ -1177,7 +1177,7 @@ rte_validate(rte *e) return 0; } - eattr *nhea = ea_find(e->attrs->eattrs, &ea_gen_nexthop); + eattr *nhea = ea_find(e->attrs, &ea_gen_nexthop); int dest = nhea_dest(nhea); if (net_type_match(n->n.addr, NB_DEST) == !dest) @@ -1808,7 +1808,7 @@ rte_dump(rte *e) net *n = e->net; debug("%-1N ", n->n.addr); debug("PF=%02x ", e->pflags); - rta_dump(e->attrs); + ea_dump(e->attrs); debug("\n"); } @@ -2416,21 +2416,21 @@ ea_set_hostentry(ea_list **to, struct rtable *dep, struct rtable *tab, ip_addr g static void -rta_apply_hostentry(rta *a, struct hostentry_adata *head) +rta_apply_hostentry(ea_list **to, struct hostentry_adata *head) { struct hostentry *he = head->he; u32 *labels = head->labels; u32 lnum = (u32 *) (head->ad.data + head->ad.length) - labels; - ea_set_attr_u32(&a->eattrs, &ea_gen_igp_metric, 0, he->igp_metric); + ea_set_attr_u32(to, &ea_gen_igp_metric, 0, he->igp_metric); if (!he->src) { - ea_set_dest(&a->eattrs, 0, RTD_UNREACHABLE); + ea_set_dest(to, 0, RTD_UNREACHABLE); return; } - eattr *he_nh_ea = ea_find(he->src->eattrs, &ea_gen_nexthop); + eattr *he_nh_ea = ea_find(he->src, &ea_gen_nexthop); ASSERT_DIE(he_nh_ea); struct nexthop_adata *nhad = (struct nexthop_adata *) he_nh_ea->u.ptr; @@ -2439,7 +2439,7 @@ rta_apply_hostentry(rta *a, struct hostentry_adata *head) if ((idest != RTD_UNICAST) || !lnum && he->nexthop_linkable) { /* Just link the nexthop chain, no label append happens. */ - ea_copy_attr(&a->eattrs, he->src->eattrs, &ea_gen_nexthop); + ea_copy_attr(to, he->src, &ea_gen_nexthop); return; } @@ -2466,7 +2466,7 @@ rta_apply_hostentry(rta *a, struct hostentry_adata *head) .dest = RTD_UNREACHABLE, }; - ea_set_attr_data(&a->eattrs, &ea_gen_nexthop, 0, &nha.ad.data, nha.ad.length); + ea_set_attr_data(to, &ea_gen_nexthop, 0, &nha.ad.data, nha.ad.length); return; } @@ -2500,22 +2500,22 @@ rta_apply_hostentry(rta *a, struct hostentry_adata *head) /* Fix final length */ new->ad.length = (void *) dest - (void *) new->ad.data; - ea_set_attr(&a->eattrs, EA_LITERAL_DIRECT_ADATA( + ea_set_attr(to, EA_LITERAL_DIRECT_ADATA( &ea_gen_nexthop, 0, &new->ad)); } static inline struct hostentry_adata * -rta_next_hop_outdated(rta *a) +rta_next_hop_outdated(ea_list *a) { /* First retrieve the hostentry */ - eattr *heea = ea_find(a->eattrs, &ea_gen_hostentry); + eattr *heea = ea_find(a, &ea_gen_hostentry); if (!heea) return NULL; struct hostentry_adata *head = (struct hostentry_adata *) heea->u.ptr; /* If no nexthop is present, we have to create one */ - eattr *a_nh_ea = ea_find(a->eattrs, &ea_gen_nexthop); + eattr *a_nh_ea = ea_find(a, &ea_gen_nexthop); if (!a_nh_ea) return head; @@ -2526,10 +2526,10 @@ rta_next_hop_outdated(rta *a) return NEXTHOP_IS_REACHABLE(nhad) ? head : NULL; /* Comparing our nexthop with the hostentry nexthop */ - eattr *he_nh_ea = ea_find(head->he->src->eattrs, &ea_gen_nexthop); + eattr *he_nh_ea = ea_find(head->he->src, &ea_gen_nexthop); return ( - (ea_get_int(a->eattrs, &ea_gen_igp_metric, IGP_METRIC_UNKNOWN) != head->he->igp_metric) || + (ea_get_int(a, &ea_gen_igp_metric, IGP_METRIC_UNKNOWN) != head->he->igp_metric) || (!head->he->nexthop_linkable) || (!he_nh_ea != !a_nh_ea) || (he_nh_ea && a_nh_ea && !adata_same(he_nh_ea->u.ptr, a_nh_ea->u.ptr))) @@ -2543,13 +2543,12 @@ rt_next_hop_update_rte(rtable *tab UNUSED, rte *old) if (!head) return NULL; - rta a = *old->attrs; - a.cached = 0; - rta_apply_hostentry(&a, head); + ea_list *ea = old->attrs; + rta_apply_hostentry(&ea, head); rte *e = sl_alloc(rte_slab); memcpy(e, old, sizeof(rte)); - e->attrs = rta_lookup(&a); + e->attrs = rta_lookup(ea); rt_lock_source(e->src); return e; @@ -2579,23 +2578,23 @@ net_flow_has_dst_prefix(const net_addr *n) } static inline int -rta_as_path_is_empty(rta *a) +rta_as_path_is_empty(ea_list *a) { - eattr *e = ea_find(a->eattrs, "bgp_path"); + eattr *e = ea_find(a, "bgp_path"); return !e || (as_path_getlen(e->u.ptr) == 0); } static inline u32 -rta_get_first_asn(rta *a) +rta_get_first_asn(ea_list *a) { - eattr *e = ea_find(a->eattrs, "bgp_path"); + eattr *e = ea_find(a, "bgp_path"); u32 asn; return (e && as_path_get_first_regular(e->u.ptr, &asn)) ? asn : 0; } int -rt_flowspec_check(rtable *tab_ip, rtable *tab_flow, const net_addr *n, rta *a, int interior) +rt_flowspec_check(rtable *tab_ip, rtable *tab_flow, const net_addr *n, ea_list *a, int interior) { ASSERT(rt_is_ip(tab_ip)); ASSERT(rt_is_flow(tab_flow)); @@ -2632,13 +2631,13 @@ rt_flowspec_check(rtable *tab_ip, rtable *tab_flow, const net_addr *n, rta *a, i return 0; /* Find ORIGINATOR_ID values */ - u32 orig_a = ea_get_int(a->eattrs, "bgp_originator_id", 0); - u32 orig_b = ea_get_int(rb->attrs->eattrs, "bgp_originator_id", 0); + u32 orig_a = ea_get_int(a, "bgp_originator_id", 0); + u32 orig_b = ea_get_int(rb->attrs, "bgp_originator_id", 0); /* Originator is either ORIGINATOR_ID (if present), or BGP neighbor address (if not) */ if ((orig_a != orig_b) || (!orig_a && !orig_b && !ipa_equal( - ea_get_ip(a->eattrs, &ea_gen_from, IPA_NONE), - ea_get_ip(rb->attrs->eattrs, &ea_gen_from, IPA_NONE) + ea_get_ip(a, &ea_gen_from, IPA_NONE), + ea_get_ip(rb->attrs, &ea_gen_from, IPA_NONE) ))) return 0; @@ -2691,15 +2690,12 @@ rt_flowspec_update_rte(rtable *tab, rte *r) if (old == valid) return NULL; - rta *a = alloca(RTA_MAX_SIZE); - memcpy(a, r->attrs, rta_size(r->attrs)); - a->cached = 0; - - ea_set_attr_u32(&a->eattrs, &ea_gen_flowspec_valid, 0, valid); + ea_list *a = r->attrs; + ea_set_attr_u32(&a, &ea_gen_flowspec_valid, 0, valid); rte *new = sl_alloc(rte_slab); memcpy(new, r, sizeof(rte)); - new->attrs = rta_lookup(a); + new->attrs = ea_lookup(a); return new; #else @@ -3506,7 +3502,7 @@ if_local_addr(ip_addr a, struct iface *i) u32 rt_get_igp_metric(rte *rt) { - eattr *ea = ea_find(rt->attrs->eattrs, "igp_metric"); + eattr *ea = ea_find(rt->attrs, "igp_metric"); if (ea) return ea->u.data; @@ -3523,7 +3519,7 @@ rt_get_igp_metric(rte *rt) static int rt_update_hostentry(rtable *tab, struct hostentry *he) { - rta *old_src = he->src; + ea_list *old_src = he->src; int direct = 0; int pxlen = 0; @@ -3538,10 +3534,10 @@ rt_update_hostentry(rtable *tab, struct hostentry *he) if (n) { rte *e = n->routes; - rta *a = e->attrs; + ea_list *a = e->attrs; pxlen = n->n.addr->pxlen; - if (ea_find(a->eattrs, &ea_gen_hostentry)) + if (ea_find(a, &ea_gen_hostentry)) { /* Recursive route should not depend on another recursive route */ log(L_WARN "Next hop address %I resolvable through recursive route for %N", @@ -3549,7 +3545,7 @@ rt_update_hostentry(rtable *tab, struct hostentry *he) goto done; } - eattr *nhea = ea_find(a->eattrs, &ea_gen_nexthop); + eattr *nhea = ea_find(a, &ea_gen_nexthop); ASSERT_DIE(nhea); struct nexthop_adata *nhad = (void *) nhea->u.ptr; |