diff options
| -rw-r--r-- | bgpd/bgp_attr.c | 14 | ||||
| -rw-r--r-- | bgpd/bgp_evpn.c | 2 | ||||
| -rw-r--r-- | bgpd/bgp_io.c | 22 | ||||
| -rw-r--r-- | bgpd/bgp_io.h | 10 | ||||
| -rw-r--r-- | bgpd/bgpd.c | 8 | ||||
| -rw-r--r-- | bgpd/bgpd.h | 1 | ||||
| -rw-r--r-- | lib/frr_pthread.c | 6 | ||||
| -rw-r--r-- | lib/frr_pthread.h | 3 |
8 files changed, 50 insertions, 16 deletions
diff --git a/bgpd/bgp_attr.c b/bgpd/bgp_attr.c index 00bad08fbe..5b917fc814 100644 --- a/bgpd/bgp_attr.c +++ b/bgpd/bgp_attr.c @@ -74,6 +74,7 @@ static const struct message attr_str[] = { {BGP_ATTR_AS4_PATH, "AS4_PATH"}, {BGP_ATTR_AS4_AGGREGATOR, "AS4_AGGREGATOR"}, {BGP_ATTR_AS_PATHLIMIT, "AS_PATHLIMIT"}, + {BGP_ATTR_PMSI_TUNNEL, "PMSI_TUNNEL_ATTRIBUTE"}, {BGP_ATTR_ENCAP, "ENCAP"}, #if ENABLE_BGP_VNC {BGP_ATTR_VNC, "VNC"}, @@ -1034,6 +1035,8 @@ const u_int8_t attr_flags_values[] = { BGP_ATTR_FLAG_OPTIONAL | BGP_ATTR_FLAG_TRANS, [BGP_ATTR_AS4_AGGREGATOR] = BGP_ATTR_FLAG_OPTIONAL | BGP_ATTR_FLAG_TRANS, + [BGP_ATTR_PMSI_TUNNEL] = + BGP_ATTR_FLAG_OPTIONAL | BGP_ATTR_FLAG_TRANS, [BGP_ATTR_LARGE_COMMUNITIES] = BGP_ATTR_FLAG_OPTIONAL | BGP_ATTR_FLAG_TRANS, [BGP_ATTR_PREFIX_SID] = @@ -3246,6 +3249,17 @@ bgp_size_t bgp_packet_attribute(struct bgp *bgp, struct peer *peer, #endif } + /* PMSI Tunnel */ + if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_PMSI_TUNNEL)) { + stream_putc(s, BGP_ATTR_FLAG_OPTIONAL | BGP_ATTR_FLAG_TRANS); + stream_putc(s, BGP_ATTR_PMSI_TUNNEL); + stream_putc(s, 9); // Length + stream_putc(s, 0); // Flags + stream_putc(s, 6); // Tunnel type: Ingress Replication (6) + stream_put(s, &(attr->label), BGP_LABEL_BYTES); // MPLS Label / VXLAN VNI + stream_put_ipv4(s, attr->nexthop.s_addr); // Unicast tunnel endpoint IP address + } + /* Unknown transit attribute. */ if (attr->transit) stream_put(s, attr->transit->val, attr->transit->length); diff --git a/bgpd/bgp_evpn.c b/bgpd/bgp_evpn.c index 182a6c64f2..ca2e1a54d4 100644 --- a/bgpd/bgp_evpn.c +++ b/bgpd/bgp_evpn.c @@ -834,6 +834,8 @@ static int update_evpn_route(struct bgp *bgp, struct bgpevpn *vpn, attr.mp_nexthop_global_in = vpn->originator_ip; attr.mp_nexthop_len = BGP_ATTR_NHLEN_IPV4; attr.sticky = CHECK_FLAG(flags, ZEBRA_MAC_TYPE_STICKY) ? 1 : 0; + attr.flag |= ATTR_FLAG_BIT(BGP_ATTR_PMSI_TUNNEL); + vni2label(vpn->vni, &(attr.label)); /* Set up RT and ENCAP extended community. */ build_evpn_route_extcomm(vpn, &attr); diff --git a/bgpd/bgp_io.c b/bgpd/bgp_io.c index 548167b3a3..cc9c1bda56 100644 --- a/bgpd/bgp_io.c +++ b/bgpd/bgp_io.c @@ -109,13 +109,15 @@ int bgp_io_stop(void **result, struct frr_pthread *fpt) } /* Extern API -------------------------------------------------------------- */ +void bgp_io_running(void) +{ + while (!atomic_load_explicit(&bgp_io_thread_started, + memory_order_seq_cst)) + frr_pthread_yield(); +} void bgp_writes_on(struct peer *peer) { - while ( - !atomic_load_explicit(&bgp_io_thread_started, memory_order_seq_cst)) - ; - assert(peer->status != Deleted); assert(peer->obuf); assert(peer->ibuf); @@ -133,10 +135,6 @@ void bgp_writes_on(struct peer *peer) void bgp_writes_off(struct peer *peer) { - while ( - !atomic_load_explicit(&bgp_io_thread_started, memory_order_seq_cst)) - ; - struct frr_pthread *fpt = frr_pthread_get(PTHREAD_IO); thread_cancel_async(fpt->master, &peer->t_write, NULL); @@ -147,10 +145,6 @@ void bgp_writes_off(struct peer *peer) void bgp_reads_on(struct peer *peer) { - while ( - !atomic_load_explicit(&bgp_io_thread_started, memory_order_seq_cst)) - ; - assert(peer->status != Deleted); assert(peer->ibuf); assert(peer->fd); @@ -170,10 +164,6 @@ void bgp_reads_on(struct peer *peer) void bgp_reads_off(struct peer *peer) { - while ( - !atomic_load_explicit(&bgp_io_thread_started, memory_order_seq_cst)) - ; - struct frr_pthread *fpt = frr_pthread_get(PTHREAD_IO); thread_cancel_async(fpt->master, &peer->t_read, NULL); diff --git a/bgpd/bgp_io.h b/bgpd/bgp_io.h index c4bd3c2dd9..73587366d7 100644 --- a/bgpd/bgp_io.h +++ b/bgpd/bgp_io.h @@ -37,6 +37,16 @@ extern void bgp_io_init(void); /** + * Ensure that the BGP IO thread is actually up and running + * + * This function must be called immediately after the thread + * has been created for running. This is because we want + * to make sure that the io thread is ready before other + * threads start attempting to use it. + */ +extern void bgp_io_running(void); + +/** * Start function for write thread. * * @param arg - unused diff --git a/bgpd/bgpd.c b/bgpd/bgpd.c index 6dcb603cb6..4d8e4ffe37 100644 --- a/bgpd/bgpd.c +++ b/bgpd/bgpd.c @@ -7437,7 +7437,15 @@ void bgp_pthreads_run() pthread_attr_init(&attr); pthread_attr_setschedpolicy(&attr, SCHED_FIFO); + /* + * Please ensure that the io thread is running + * by calling bgp_io_running. The BGP threads + * depend on it being running when we start + * looking for it. + */ frr_pthread_run(PTHREAD_IO, &attr, NULL); + bgp_io_running(); + frr_pthread_run(PTHREAD_KEEPALIVES, &attr, NULL); } diff --git a/bgpd/bgpd.h b/bgpd/bgpd.h index 6bb49e0c53..ce56587727 100644 --- a/bgpd/bgpd.h +++ b/bgpd/bgpd.h @@ -1020,6 +1020,7 @@ struct bgp_nlri { #define BGP_ATTR_AS4_PATH 17 #define BGP_ATTR_AS4_AGGREGATOR 18 #define BGP_ATTR_AS_PATHLIMIT 21 +#define BGP_ATTR_PMSI_TUNNEL 22 #define BGP_ATTR_ENCAP 23 #define BGP_ATTR_LARGE_COMMUNITIES 32 #define BGP_ATTR_PREFIX_SID 40 diff --git a/lib/frr_pthread.c b/lib/frr_pthread.c index 8b23640fa4..19dfbaf54b 100644 --- a/lib/frr_pthread.c +++ b/lib/frr_pthread.c @@ -19,6 +19,7 @@ #include <zebra.h> #include <pthread.h> +#include <sched.h> #include "frr_pthread.h" #include "memory.h" @@ -182,3 +183,8 @@ unsigned int frr_pthread_get_id() { return next_id++; } + +void frr_pthread_yield(void) +{ + (void)sched_yield(); +} diff --git a/lib/frr_pthread.h b/lib/frr_pthread.h index 9dee5fcca4..f6000340a7 100644 --- a/lib/frr_pthread.h +++ b/lib/frr_pthread.h @@ -130,6 +130,9 @@ int frr_pthread_stop(unsigned int id, void **result); /* Stops all frr_pthread's. */ void frr_pthread_stop_all(void); +/* Yields the current thread of execution */ +void frr_pthread_yield(void); + /* Returns a unique identifier for use with frr_pthread_new(). * * Internally, this is an integer that increments after each call to this |
