diff options
author | Maria Matejka <mq@ucw.cz> | 2022-05-05 18:08:37 +0200 |
---|---|---|
committer | Maria Matejka <mq@ucw.cz> | 2022-05-26 12:34:26 +0200 |
commit | f15f2fcee7eeb5a100bd204a0e67018e25953420 (patch) | |
tree | 12a99cfb8b6ee5aba555af282b356fb712457b18 /proto/static/static.c | |
parent | f2e725a76882ba6b75c3ce4fb3c760bd83462410 (diff) |
Moved nexthop from struct rta to extended attribute.
This doesn't do anything more than to put the whole structure inside
adata. The overall performance is certainly going downhill; we'll
optimize this later.
Anyway, this is one of the latest items inside rta and in several
commits we may drop rta completely and move to eattrs-only routes.
Diffstat (limited to 'proto/static/static.c')
-rw-r--r-- | proto/static/static.c | 34 |
1 files changed, 21 insertions, 13 deletions
diff --git a/proto/static/static.c b/proto/static/static.c index e792a148..2e4a46a6 100644 --- a/proto/static/static.c +++ b/proto/static/static.c @@ -61,32 +61,40 @@ static_announce_rte(struct static_proto *p, struct static_route *r) if (r->dest == RTD_UNICAST) { - struct static_route *r2; - struct nexthop *nhs = NULL; + uint sz = 0; + for (struct static_route *r2 = r; r2; r2 = r2->mp_next) + if (r2->active) + sz += NEXTHOP_SIZE_CNT(r2->mls ? r2->mls->length / sizeof(u32) : 0); - for (r2 = r; r2; r2 = r2->mp_next) + if (!sz) + goto withdraw; + + struct nexthop_adata *nhad = allocz(sz + sizeof *nhad); + struct nexthop *nh = &nhad->nh; + + for (struct static_route *r2 = r; r2; r2 = r2->mp_next) { if (!r2->active) continue; - struct nexthop *nh = allocz(NEXTHOP_MAX_SIZE); - nh->gw = r2->via; - nh->iface = r2->neigh->iface; - nh->flags = r2->onlink ? RNF_ONLINK : 0; - nh->weight = r2->weight; + *nh = (struct nexthop) { + .gw = r2->via, + .iface = r2->neigh->iface, + .flags = r2->onlink ? RNF_ONLINK : 0, + .weight = r2->weight, + }; + if (r2->mls) { nh->labels = r2->mls->length / sizeof(u32); memcpy(nh->label, r2->mls->data, r2->mls->length); } - nexthop_insert(&nhs, nh); + nh = NEXTHOP_NEXT(nh); } - if (!nhs) - goto withdraw; - - nexthop_link(a, nhs); + ea_set_attr_data(&a->eattrs, &ea_gen_nexthop, 0, + nhad->ad.data, (void *) nh - (void *) nhad->ad.data); } if (r->dest == RTDX_RECURSIVE) |