From: Quentin Young Date: Mon, 13 Nov 2017 22:59:04 +0000 (-0500) Subject: bgpd: turn off keepalives when sending NOTIFY X-Git-Tag: frr-4.0-dev~120^2~4 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=934af4587f0b7ddbfc176c3930c04cca949743ba;p=matthieu%2Ffrr.git bgpd: turn off keepalives when sending NOTIFY This is necessary because otherwise between the time we wipe the output buffer and the time we push the NOTIFY onto it, the KA generation thread could have pushed a KEEPALIVE in the middle. Signed-off-by: Quentin Young --- diff --git a/bgpd/bgp_keepalives.c b/bgpd/bgp_keepalives.c index abe9739c98..afa280a799 100644 --- a/bgpd/bgp_keepalives.c +++ b/bgpd/bgp_keepalives.c @@ -232,6 +232,11 @@ void bgp_keepalives_on(struct peer *peer) /* placeholder bucket data to use for fast key lookups */ static struct pkat holder = {0}; + if (!peerhash_mtx) { + zlog_warn("%s: call bgp_keepalives_init() first", __func__); + return; + } + pthread_mutex_lock(peerhash_mtx); { holder.peer = peer; @@ -251,6 +256,11 @@ void bgp_keepalives_off(struct peer *peer) /* placeholder bucket data to use for fast key lookups */ static struct pkat holder = {0}; + if (!peerhash_mtx) { + zlog_warn("%s: call bgp_keepalives_init() first", __func__); + return; + } + pthread_mutex_lock(peerhash_mtx); { holder.peer = peer; diff --git a/bgpd/bgp_packet.c b/bgpd/bgp_packet.c index fe633413c2..09df0e35b6 100644 --- a/bgpd/bgp_packet.c +++ b/bgpd/bgp_packet.c @@ -58,6 +58,7 @@ #include "bgpd/bgp_updgrp.h" #include "bgpd/bgp_label.h" #include "bgpd/bgp_io.h" +#include "bgpd/bgp_keepalives.h" /** * Sets marker and type fields for a BGP message. @@ -655,6 +656,14 @@ void bgp_notify_send_with_data(struct peer *peer, u_char code, u_char sub_code, /* Set BGP packet length. */ length = bgp_packet_set_size(s); + /* + * Turn off keepalive generation for peer. This is necessary because + * otherwise between the time we wipe the output buffer and the time we + * push the NOTIFY onto it, the KA generation thread could have pushed + * a KEEPALIVE in the middle. + */ + bgp_keepalives_off(peer); + /* wipe output buffer */ pthread_mutex_lock(&peer->io_mtx); {