From 938742decc6e1d6d3a0375dd012b75172e747bbc Mon Sep 17 00:00:00 2001 From: Maria Matejka Date: Mon, 30 May 2022 12:03:03 +0200 Subject: 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. --- sysdep/linux/netlink.c | 40 +++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 21 deletions(-) (limited to 'sysdep/linux') 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); } } -- cgit v1.2.3