bgpd: Make keepalive pthread be connection based.

Again instead of making the keepalives be peer based
use the connection to make it happen.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
This commit is contained in:
Donald Sharp 2025-02-18 11:37:51 -05:00
parent 2cd1d00dde
commit 23bdaba147

View file

@ -31,7 +31,7 @@ DEFINE_MTYPE_STATIC(BGPD, BGP_MUTEX, "BGP Peer pthread Mutex");
*/ */
struct pkat { struct pkat {
/* the peer to send keepalives to */ /* the peer to send keepalives to */
struct peer *peer; struct peer_connection *connection;
/* absolute time of last keepalive sent */ /* absolute time of last keepalive sent */
struct timeval last; struct timeval last;
}; };
@ -41,10 +41,10 @@ static pthread_mutex_t *peerhash_mtx;
static pthread_cond_t *peerhash_cond; static pthread_cond_t *peerhash_cond;
static struct hash *peerhash; static struct hash *peerhash;
static struct pkat *pkat_new(struct peer *peer) static struct pkat *pkat_new(struct peer_connection *connection)
{ {
struct pkat *pkat = XMALLOC(MTYPE_BGP_PKAT, sizeof(struct pkat)); struct pkat *pkat = XMALLOC(MTYPE_BGP_PKAT, sizeof(struct pkat));
pkat->peer = peer; pkat->connection = connection;
monotime(&pkat->last); monotime(&pkat->last);
return pkat; return pkat;
} }
@ -54,7 +54,6 @@ static void pkat_del(void *pkat)
XFREE(MTYPE_BGP_PKAT, pkat); XFREE(MTYPE_BGP_PKAT, pkat);
} }
/* /*
* Callback for hash_iterate. Determines if a peer needs a keepalive and if so, * Callback for hash_iterate. Determines if a peer needs a keepalive and if so,
* generates and sends it. * generates and sends it.
@ -77,7 +76,7 @@ static void pkat_del(void *pkat)
static void peer_process(struct hash_bucket *hb, void *arg) static void peer_process(struct hash_bucket *hb, void *arg)
{ {
struct pkat *pkat = hb->data; struct pkat *pkat = hb->data;
struct peer *peer = pkat->connection->peer;
struct timeval *next_update = arg; struct timeval *next_update = arg;
static struct timeval elapsed; // elapsed time since keepalive static struct timeval elapsed; // elapsed time since keepalive
@ -86,8 +85,7 @@ static void peer_process(struct hash_bucket *hb, void *arg)
static const struct timeval tolerance = {0, 100000}; static const struct timeval tolerance = {0, 100000};
uint32_t v_ka = atomic_load_explicit(&pkat->peer->v_keepalive, uint32_t v_ka = atomic_load_explicit(&peer->v_keepalive, memory_order_relaxed);
memory_order_relaxed);
/* 0 keepalive timer means no keepalives */ /* 0 keepalive timer means no keepalives */
if (v_ka == 0) if (v_ka == 0)
@ -104,11 +102,10 @@ static void peer_process(struct hash_bucket *hb, void *arg)
elapsed.tv_sec >= ka.tv_sec || timercmp(&diff, &tolerance, <); elapsed.tv_sec >= ka.tv_sec || timercmp(&diff, &tolerance, <);
if (send_keepalive) { if (send_keepalive) {
if (bgp_debug_keepalive(pkat->peer)) if (bgp_debug_keepalive(peer))
zlog_debug("%s [FSM] Timer (keepalive timer expire)", zlog_debug("%s [FSM] Timer (keepalive timer expire)", peer->host);
pkat->peer->host);
bgp_keepalive_send(pkat->peer->connection); bgp_keepalive_send(pkat->connection);
monotime(&pkat->last); monotime(&pkat->last);
memset(&elapsed, 0, sizeof(elapsed)); memset(&elapsed, 0, sizeof(elapsed));
diff = ka; diff = ka;
@ -124,13 +121,13 @@ static bool peer_hash_cmp(const void *f, const void *s)
const struct pkat *p1 = f; const struct pkat *p1 = f;
const struct pkat *p2 = s; const struct pkat *p2 = s;
return p1->peer == p2->peer; return p1->connection == p2->connection;
} }
static unsigned int peer_hash_key(const void *arg) static unsigned int peer_hash_key(const void *arg)
{ {
const struct pkat *pkat = arg; const struct pkat *pkat = arg;
return (uintptr_t)pkat->peer; return (uintptr_t)pkat->connection;
} }
/* Cleanup handler / deinitializer. */ /* Cleanup handler / deinitializer. */
@ -248,9 +245,9 @@ void bgp_keepalives_on(struct peer_connection *connection)
assert(peerhash_mtx); assert(peerhash_mtx);
frr_with_mutex (peerhash_mtx) { frr_with_mutex (peerhash_mtx) {
holder.peer = peer; holder.connection = connection;
if (!hash_lookup(peerhash, &holder)) { if (!hash_lookup(peerhash, &holder)) {
struct pkat *pkat = pkat_new(peer); struct pkat *pkat = pkat_new(connection);
(void)hash_get(peerhash, pkat, hash_alloc_intern); (void)hash_get(peerhash, pkat, hash_alloc_intern);
peer_lock(peer); peer_lock(peer);
} }
@ -279,7 +276,7 @@ void bgp_keepalives_off(struct peer_connection *connection)
assert(peerhash_mtx); assert(peerhash_mtx);
frr_with_mutex (peerhash_mtx) { frr_with_mutex (peerhash_mtx) {
holder.peer = peer; holder.connection = connection;
struct pkat *res = hash_release(peerhash, &holder); struct pkat *res = hash_release(peerhash, &holder);
if (res) { if (res) {
pkat_del(res); pkat_del(res);