diff options
author | Mikael Magnusson <mikma@users.sourceforge.net> | 2023-11-25 23:39:11 +0100 |
---|---|---|
committer | Mikael Magnusson <mikma@users.sourceforge.net> | 2023-11-25 23:39:11 +0100 |
commit | c181d9daf5185fcdc33b6fa65bbdcfe9e6b4cd12 (patch) | |
tree | e10da97e0487afb3b398a0607e0711499e961ae2 /proto/bgp | |
parent | ff1a3f8e085382bb5c5e127798afe81bb835cc5b (diff) | |
parent | 9d456d5366593c7b0ebfde003be0517adb554541 (diff) |
Merge commit '9d456d53' into wireguard-next-tmp7-1
Diffstat (limited to 'proto/bgp')
-rw-r--r-- | proto/bgp/attrs.c | 8 | ||||
-rw-r--r-- | proto/bgp/bgp.c | 18 | ||||
-rw-r--r-- | proto/bgp/config.Y | 1 | ||||
-rw-r--r-- | proto/bgp/packets.c | 5 |
4 files changed, 27 insertions, 5 deletions
diff --git a/proto/bgp/attrs.c b/proto/bgp/attrs.c index 0ca40581..dc764331 100644 --- a/proto/bgp/attrs.c +++ b/proto/bgp/attrs.c @@ -17,6 +17,7 @@ #include "nest/protocol.h" #include "nest/route.h" #include "nest/attrs.h" +#include "nest/mpls.h" #include "conf/conf.h" #include "lib/resource.h" #include "lib/string.h" @@ -1544,6 +1545,13 @@ bgp_finish_attrs(struct bgp_parse_state *s, rta *a) p->cf->local_role == BGP_ROLE_RS_CLIENT)) bgp_set_attr_u32(&a->eattrs, s->pool, BA_ONLY_TO_CUSTOMER, 0, p->cf->remote_as); } + + /* Apply MPLS policy for labeled SAFIs */ + if (s->mpls && s->proto->p.mpls_channel) + { + struct mpls_channel *mc = (void *) s->proto->p.mpls_channel; + ea_set_attr_u32(&a->eattrs, s->pool, EA_MPLS_POLICY, 0, EAF_TYPE_INT, mc->label_policy); + } } diff --git a/proto/bgp/bgp.c b/proto/bgp/bgp.c index f668b371..4651b76a 100644 --- a/proto/bgp/bgp.c +++ b/proto/bgp/bgp.c @@ -522,6 +522,8 @@ bgp_spawn(struct bgp_proto *pp, ip_addr remote_ip) void bgp_stop(struct bgp_proto *p, int subcode, byte *data, uint len) { + proto_shutdown_mpls_map(&p->p, 1); + proto_notify_state(&p->p, PS_STOP); bgp_graceful_close_conn(&p->outgoing_conn, subcode, data, len); bgp_graceful_close_conn(&p->incoming_conn, subcode, data, len); @@ -1573,6 +1575,8 @@ bgp_start(struct proto *P) p->remote_id = 0; p->link_addr = IPA_NONE; + proto_setup_mpls_map(P, RTS_BGP, 1); + /* Lock all channels when in GR recovery mode */ if (p->p.gr_recovery && p->cf->gr_mode) { @@ -1729,11 +1733,14 @@ bgp_init(struct proto_config *CF) if (cf->c.parent) cf->remote_ip = IPA_NONE; - /* Add all channels */ + /* Add all BGP channels */ struct bgp_channel_config *cc; BGP_CF_WALK_CHANNELS(cf, cc) proto_add_channel(P, &cc->c); + /* Add MPLS channel */ + proto_configure_channel(P, &P->mpls_channel, proto_cf_mpls_channel(CF)); + return P; } @@ -2153,16 +2160,23 @@ bgp_reconfigure(struct proto *P, struct proto_config *CF) WALK_LIST(C, p->p.channels) C->stale = 1; + /* Reconfigure BGP channels */ BGP_CF_WALK_CHANNELS(new, cc) { C = (struct channel *) bgp_find_channel(p, cc->afi); same = proto_configure_channel(P, &C, &cc->c) && same; } + /* Reconfigure MPLS channel */ + same = proto_configure_channel(P, &P->mpls_channel, proto_cf_mpls_channel(CF)) && same; + WALK_LIST_DELSAFE(C, C2, p->p.channels) if (C->stale) same = proto_configure_channel(P, &C, NULL) && same; + if (same) + proto_setup_mpls_map(P, RTS_BGP, 1); + if (same && (p->start_state > BSS_PREPARE)) bgp_update_bfd(p, new->bfd); @@ -2653,7 +2667,7 @@ struct protocol proto_bgp = { .template = "bgp%d", .class = PROTOCOL_BGP, .preference = DEF_PREF_BGP, - .channel_mask = NB_IP | NB_VPN | NB_FLOW, + .channel_mask = NB_IP | NB_VPN | NB_FLOW | NB_MPLS, .proto_size = sizeof(struct bgp_proto), .config_size = sizeof(struct bgp_config), .postconfig = bgp_postconfig, diff --git a/proto/bgp/config.Y b/proto/bgp/config.Y index 35c19961..3c999453 100644 --- a/proto/bgp/config.Y +++ b/proto/bgp/config.Y @@ -129,6 +129,7 @@ bgp_proto: bgp_proto_start proto_name '{' | bgp_proto proto_item ';' | bgp_proto bgp_proto_channel ';' + | bgp_proto mpls_channel ';' | bgp_proto LOCAL bgp_loc_opts ';' | bgp_proto LOCAL ipa ipa_scope bgp_loc_opts ';' { BGP_CFG->local_ip = $3; diff --git a/proto/bgp/packets.c b/proto/bgp/packets.c index 054e6c3c..b7df5a7a 100644 --- a/proto/bgp/packets.c +++ b/proto/bgp/packets.c @@ -1217,11 +1217,10 @@ bgp_update_next_hop_ip(struct bgp_export_state *s, eattr *a, ea_list **to) bgp_set_attr_data(to, s->pool, BA_NEXT_HOP, 0, nh, ipa_nonzero(nh[1]) ? 32 : 16); s->local_next_hop = 1; - /* TODO: Use local MPLS assigned label */ if (s->mpls) { - u32 implicit_null = BGP_MPLS_NULL; - bgp_set_attr_data(to, s->pool, BA_MPLS_LABEL_STACK, 0, &implicit_null, 4); + u32 label = ea_get_int(s->route->attrs->eattrs, EA_MPLS_LABEL, BGP_MPLS_NULL); + bgp_set_attr_data(to, s->pool, BA_MPLS_LABEL_STACK, 0, &label, 4); } else bgp_unset_attr(to, s->pool, BA_MPLS_LABEL_STACK); |