diff options
author | Mikael Magnusson <mikma@users.sourceforge.net> | 2023-11-25 23:42:08 +0100 |
---|---|---|
committer | Mikael Magnusson <mikma@users.sourceforge.net> | 2023-11-25 23:42:08 +0100 |
commit | 99094c898d91d9e344eec45645ac632a7979e3fc (patch) | |
tree | 9576f85ea71bedd05e889850394f0423dbfe5c61 /nest | |
parent | 020539e6c178fd7063855b2981a6a41589cca8e4 (diff) | |
parent | b6385decb3f9f4d4029ee7bfc2f013b495a725f8 (diff) |
Merge commit 'b6385dec' into wireguard-next-tmp7-1
Diffstat (limited to 'nest')
-rw-r--r-- | nest/mpls.c | 37 | ||||
-rw-r--r-- | nest/mpls.h | 3 |
2 files changed, 24 insertions, 16 deletions
diff --git a/nest/mpls.c b/nest/mpls.c index 03180913..c9ae78f8 100644 --- a/nest/mpls.c +++ b/nest/mpls.c @@ -78,8 +78,7 @@ * TODO: * - protocols should do route refresh instead of restart when reconfiguration * requires changing labels (e.g. different label range) - * - registering static allocations - * - checking range in static allocations + * - handle label allocation failures * - special handling of reserved labels */ @@ -481,12 +480,14 @@ mpls_free_handle(struct mpls_domain *m UNUSED, struct mpls_handle *h) */ uint -mpls_new_label(struct mpls_domain *m, struct mpls_handle *h) +mpls_new_label(struct mpls_domain *m, struct mpls_handle *h, uint n) { struct mpls_range *r = h->range; - uint n = lmap_first_zero_in_range(&m->labels, r->lo, r->hi); - if (n >= r->hi) + if (!n) + n = lmap_first_zero_in_range(&m->labels, r->lo, r->hi); + + if ((n < r->lo) || (n >= r->hi) || lmap_test(&m->labels, n)) return 0; m->label_count++; @@ -583,8 +584,7 @@ mpls_channel_postconfig(struct channel_config *CC) cf_error("MPLS domain not specified"); if (!cc->range) - cc->range = (cc->label_policy == MPLS_POLICY_STATIC) ? - cc->domain->static_range : cc->domain->dynamic_range; + cc->range = cc->domain->dynamic_range; if (cc->range->domain != cc->domain) cf_error("MPLS label range from different MPLS domain"); @@ -684,11 +684,14 @@ mpls_fec_map_free(struct mpls_fec_map *m) /* Free allocated labels */ HASH_WALK(m->label_hash, next_l, fec) { - if (fec->policy != MPLS_POLICY_STATIC) - mpls_free_label(m->domain, m->handle, fec->label); + struct mpls_handle *h = (fec->policy != MPLS_POLICY_STATIC) ? m->handle : m->static_handle; + mpls_free_label(m->domain, h, fec->label); } HASH_WALK_END; + if (m->static_handle) + mpls_free_handle(m->domain, m->static_handle); + mpls_free_handle(m->domain, m->handle); mpls_unlock_domain(m->domain); @@ -717,13 +720,17 @@ struct mpls_fec * mpls_get_fec_by_label(struct mpls_fec_map *m, u32 label) { struct mpls_fec *fec = HASH_FIND(m->label_hash, LABEL, label); + /* FIXME: check if (fec->policy == MPLS_POLICY_STATIC) */ if (fec) return fec; fec = sl_allocz(mpls_slab(m, 0)); - fec->label = label; + if (!m->static_handle) + m->static_handle = mpls_new_handle(m->domain, m->domain->cf->static_range->range); + + fec->label = mpls_new_label(m->domain, m->static_handle, label); fec->policy = MPLS_POLICY_STATIC; DBG("New FEC lab %u\n", fec->label); @@ -751,7 +758,7 @@ mpls_get_fec_by_net(struct mpls_fec_map *m, const net_addr *net, u32 path_id) fec->path_id = path_id; net_copy(fec->net, net); - fec->label = mpls_new_label(m->domain, m->handle); + fec->label = mpls_new_label(m->domain, m->handle, 0); fec->policy = MPLS_POLICY_PREFIX; DBG("New FEC net %u\n", fec->label); @@ -784,7 +791,7 @@ mpls_get_fec_by_rta(struct mpls_fec_map *m, const rta *src, u32 class_id) fec->class_id = class_id; fec->rta = rta; - fec->label = mpls_new_label(m->domain, m->handle); + fec->label = mpls_new_label(m->domain, m->handle, 0); fec->policy = MPLS_POLICY_AGGREGATE; DBG("New FEC rta %u\n", fec->label); @@ -805,7 +812,7 @@ mpls_get_fec_for_vrf(struct mpls_fec_map *m) fec = sl_allocz(mpls_slab(m, 0)); - fec->label = mpls_new_label(m->domain, m->handle); + fec->label = mpls_new_label(m->domain, m->handle, 0); fec->policy = MPLS_POLICY_VRF; fec->iface = m->vrf_iface; @@ -825,8 +832,8 @@ mpls_free_fec(struct mpls_fec_map *m, struct mpls_fec *fec) DBG("Free FEC %u\n", fec->label); - if (fec->policy != MPLS_POLICY_STATIC) - mpls_free_label(m->domain, m->handle, fec->label); + struct mpls_handle *h = (fec->policy != MPLS_POLICY_STATIC) ? m->handle : m->static_handle; + mpls_free_label(m->domain, h, fec->label); HASH_REMOVE2(m->label_hash, LABEL, m->pool, fec); diff --git a/nest/mpls.h b/nest/mpls.h index 6452220a..52865f1c 100644 --- a/nest/mpls.h +++ b/nest/mpls.h @@ -91,7 +91,7 @@ void mpls_domain_postconfig(struct mpls_domain_config *cf); struct mpls_range_config * mpls_range_config_new(struct mpls_domain_config *m, struct symbol *s); void mpls_preconfig(struct config *c); void mpls_commit(struct config *new, struct config *old); -uint mpls_new_label(struct mpls_domain *m, struct mpls_handle *h); +uint mpls_new_label(struct mpls_domain *m, struct mpls_handle *h, uint n); void mpls_free_label(struct mpls_domain *m, struct mpls_handle *h, uint n); static inline struct mpls_domain_config *cf_default_mpls_domain(struct config *cfg) @@ -153,6 +153,7 @@ struct mpls_fec_map { struct channel *channel; /* MPLS channel for FEC announcement */ struct mpls_domain *domain; /* MPLS domain, keeping reference */ struct mpls_handle *handle; /* Handle for allocation of labels */ + struct mpls_handle *static_handle; /* Handle for static label allocations, optional */ struct iface *vrf_iface; u8 mpls_rts; /* Source value used for MPLS routes (RTS_*) */ |