diff options
author | Maria Matejka <mq@ucw.cz> | 2022-05-30 12:03:03 +0200 |
---|---|---|
committer | Maria Matejka <mq@ucw.cz> | 2022-05-30 14:39:09 +0200 |
commit | 938742decc6e1d6d3a0375dd012b75172e747bbc (patch) | |
tree | a10d9eb2811af43075c2c5272ece7b3dbbb38cdf /sysdep | |
parent | 950775f6fa3d569a9d7cd05e33538d35e895d688 (diff) |
Squashing the route attribute structure into one level.
For now, all route attributes are stored as eattrs in ea_list. This
should make route manipulation easier and it also allows for a layered
approach of route attributes where updates from filters will be stored
as an overlay over the previous version.
Diffstat (limited to 'sysdep')
-rw-r--r-- | sysdep/linux/netlink.c | 40 | ||||
-rw-r--r-- | sysdep/unix/krt.c | 18 |
2 files changed, 27 insertions, 31 deletions
diff --git a/sysdep/linux/netlink.c b/sysdep/linux/netlink.c index 40f6212e..4cfd7c80 100644 --- a/sysdep/linux/netlink.c +++ b/sysdep/linux/netlink.c @@ -111,7 +111,7 @@ struct nl_parse_state int merge; net *net; - rta *attrs; + ea_list *attrs; struct krt_proto *proto; s8 new; s8 krt_src; @@ -1407,7 +1407,7 @@ HASH_DEFINE_REHASH_FN(RTH, struct krt_proto) int krt_capable(rte *e) { - eattr *ea = ea_find(e->attrs->eattrs, &ea_gen_nexthop); + eattr *ea = ea_find(e->attrs, &ea_gen_nexthop); if (!ea) return 0; @@ -1441,8 +1441,7 @@ nl_send_route(struct krt_proto *p, rte *e, int op, int dest, struct nexthop_adat { eattr *ea; net *net = e->net; - rta *a = e->attrs; - ea_list *eattrs = a->eattrs; + ea_list *eattrs = e->attrs; int bufsize = 128 + KRT_METRICS_MAX*8 + (nh ? nh_bufsize(nh) : 0); u32 priority = 0; @@ -1590,10 +1589,10 @@ dest: static inline int nl_add_rte(struct krt_proto *p, rte *e) { - rta *a = e->attrs; + ea_list *ea = e->attrs; int err = 0; - eattr *nhea = ea_find(a->eattrs, &ea_gen_nexthop); + eattr *nhea = ea_find(ea, &ea_gen_nexthop); struct nexthop_adata *nhad = nhea ? (struct nexthop_adata *) nhea->u.ptr : NULL; if (krt_ecmp6(p) && nhad && NEXTHOP_IS_REACHABLE(nhad) && !NEXTHOP_ONE(nhad)) @@ -1641,8 +1640,7 @@ nl_delete_rte(struct krt_proto *p, rte *e) static inline int nl_replace_rte(struct krt_proto *p, rte *e) { - rta *a = e->attrs; - eattr *nhea = ea_find(a->eattrs, &ea_gen_nexthop); + eattr *nhea = ea_find(e->attrs, &ea_gen_nexthop); struct nexthop_adata *nhad = nhea ? (struct nexthop_adata *) nhea->u.ptr : NULL; return nl_send_route(p, e, NL_OP_REPLACE, NEXTHOP_IS_REACHABLE(nhad) ? RTD_UNICAST : nhad->dest, nhad); @@ -1713,14 +1711,14 @@ nl_announce_route(struct nl_parse_state *s) e->net = s->net; EA_LOCAL_LIST(2) ea = { - .l = { .count = 2, .next = e->attrs->eattrs }, + .l = { .count = 2, .next = e->attrs }, .a = { EA_LITERAL_EMBEDDED(&ea_krt_source, 0, s->krt_proto), EA_LITERAL_EMBEDDED(&ea_krt_metric, 0, s->krt_metric), }, }; - e->attrs->eattrs = &ea.l; + e->attrs = &ea.l; if (s->scan) krt_got_route(s->proto, e, s->krt_src); @@ -1888,8 +1886,8 @@ nl_parse_route(struct nl_parse_state *s, struct nlmsghdr *h) if (s->net && !nl_mergable_route(s, net, p, priority, i->rtm_type, i->rtm_family)) nl_announce_route(s); - rta *ra = lp_allocz(s->pool, RTA_MAX_SIZE); - ea_set_attr_u32(&ra->eattrs, &ea_gen_source, 0, RTS_INHERIT); + ea_list *ra = NULL; + ea_set_attr_u32(&ra, &ea_gen_source, 0, RTS_INHERIT); if (a[RTA_FLOW]) s->rta_flow = rta_get_u32(a[RTA_FLOW]); @@ -1914,7 +1912,7 @@ nl_parse_route(struct nl_parse_state *s, struct nlmsghdr *h) if (!nh) SKIP("strange RTA_MULTIPATH\n"); - ea_set_attr(&ra->eattrs, EA_LITERAL_DIRECT_ADATA( + ea_set_attr(&ra, EA_LITERAL_DIRECT_ADATA( &ea_gen_nexthop, 0, &nh->ad)); break; } @@ -2000,20 +1998,20 @@ nl_parse_route(struct nl_parse_state *s, struct nlmsghdr *h) } if (i->rtm_scope != def_scope) - ea_set_attr(&ra->eattrs, + ea_set_attr(&ra, EA_LITERAL_EMBEDDED(&ea_krt_scope, 0, i->rtm_scope)); if (a[RTA_PREFSRC]) { ip_addr ps = rta_get_ipa(a[RTA_PREFSRC]); - ea_set_attr(&ra->eattrs, + ea_set_attr(&ra, EA_LITERAL_STORE_ADATA(&ea_krt_prefsrc, 0, &ps, sizeof(ps))); } /* Can be set per-route or per-nexthop */ if (s->rta_flow) - ea_set_attr(&ra->eattrs, + ea_set_attr(&ra, EA_LITERAL_EMBEDDED(&ea_krt_realm, 0, s->rta_flow)); if (a[RTA_METRICS]) @@ -2027,7 +2025,7 @@ nl_parse_route(struct nl_parse_state *s, struct nlmsghdr *h) for (uint t = 1; t < KRT_METRICS_MAX; t++) if (metrics[0] & (1 << t)) - ea_set_attr(&ra->eattrs, + ea_set_attr(&ra, EA_LITERAL_EMBEDDED(&ea_krt_metrics[t], 0, metrics[t])); } @@ -2045,7 +2043,7 @@ nl_parse_route(struct nl_parse_state *s, struct nlmsghdr *h) s->net = net; s->attrs = ra; - ea_set_attr_data(&ra->eattrs, &ea_gen_nexthop, 0, + ea_set_attr_data(&ra, &ea_gen_nexthop, 0, nhad.ad.data, nhad.ad.length); s->proto = p; @@ -2058,17 +2056,17 @@ nl_parse_route(struct nl_parse_state *s, struct nlmsghdr *h) else { /* Merge next hops with the stored route */ - eattr *nhea = ea_find(s->attrs->eattrs, &ea_gen_nexthop); + eattr *nhea = ea_find(s->attrs, &ea_gen_nexthop); struct nexthop_adata *nhad_old = nhea ? (struct nexthop_adata *) nhea->u.ptr : NULL; if (nhad_old) - ea_set_attr(&s->attrs->eattrs, + ea_set_attr(&s->attrs, EA_LITERAL_DIRECT_ADATA(&ea_gen_nexthop, 0, &(nexthop_merge(nhad_old, &nhad.nhad, KRT_CF->merge_paths, s->pool)->ad) )); else - ea_set_attr_data(&s->attrs->eattrs, &ea_gen_nexthop, 0, + ea_set_attr_data(&s->attrs, &ea_gen_nexthop, 0, nhad.ad.data, nhad.ad.length); } } diff --git a/sysdep/unix/krt.c b/sysdep/unix/krt.c index a0789936..3edbdfa2 100644 --- a/sysdep/unix/krt.c +++ b/sysdep/unix/krt.c @@ -286,7 +286,7 @@ static struct tbf rl_alien = TBF_DEFAULT_LOG_LIMITS; static inline u32 krt_metric(rte *a) { - eattr *ea = ea_find(a->attrs->eattrs, &ea_krt_metric); + eattr *ea = ea_find(a->attrs, &ea_krt_metric); return ea ? ea->u.data : 0; } @@ -306,8 +306,7 @@ static void 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, p->p.main_source); + rte *ee = rte_get_temp(ea_clone(e->attrs), p->p.main_source); rte_update(&p->p, n->n.addr, ee); } @@ -437,10 +436,9 @@ krt_learn_async(struct krt_proto *p, rte *e, int new) net *n = net_get(p->krt_table, n0->n.addr); rte *g, **gg, *best, **bestp, *old_best; - ASSERT(!e->attrs->cached); - ea_set_attr_u32(&e->attrs->eattrs, &ea_gen_preference, 0, p->p.main_channel->preference); - - e->attrs = rta_lookup(e->attrs); + ea_list *ea = e->attrs; + ea_set_attr_u32(&ea, &ea_gen_preference, 0, p->p.main_channel->preference); + e->attrs = rta_lookup(ea); old_best = n->routes; for(gg=&n->routes; g = *gg; gg = &g->next) @@ -606,10 +604,10 @@ reject: static int krt_same_dest(rte *k, rte *e) { - rta *ka = k->attrs, *ea = e->attrs; + ea_list *ka = k->attrs, *ea = e->attrs; - eattr *nhea_k = ea_find(ka->eattrs, &ea_gen_nexthop); - eattr *nhea_e = ea_find(ea->eattrs, &ea_gen_nexthop); + eattr *nhea_k = ea_find(ka, &ea_gen_nexthop); + eattr *nhea_e = ea_find(ea, &ea_gen_nexthop); return (!nhea_k == !nhea_e) && adata_same(nhea_k->u.ptr, nhea_e->u.ptr); } |