Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More connection cleanup #18195

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Prev Previous commit
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>
  • Loading branch information
donaldsharp committed Feb 19, 2025
commit 6fe0eb34ea0c9a9b0e55f29948e6c60dfc1e2b4c
29 changes: 13 additions & 16 deletions bgpd/bgp_keepalives.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ DEFINE_MTYPE_STATIC(BGPD, BGP_MUTEX, "BGP Peer pthread Mutex");
*/
struct pkat {
/* the peer to send keepalives to */
struct peer *peer;
struct peer_connection *connection;
/* absolute time of last keepalive sent */
struct timeval last;
};
Expand All @@ -41,10 +41,10 @@ static pthread_mutex_t *peerhash_mtx;
static pthread_cond_t *peerhash_cond;
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));
pkat->peer = peer;
pkat->connection = connection;
monotime(&pkat->last);
return pkat;
}
Expand All @@ -54,7 +54,6 @@ static void pkat_del(void *pkat)
XFREE(MTYPE_BGP_PKAT, pkat);
}


/*
* Callback for hash_iterate. Determines if a peer needs a keepalive and if so,
* generates and sends it.
Expand All @@ -77,7 +76,7 @@ static void pkat_del(void *pkat)
static void peer_process(struct hash_bucket *hb, void *arg)
{
struct pkat *pkat = hb->data;

struct peer *peer = pkat->connection->peer;
struct timeval *next_update = arg;

static struct timeval elapsed; // elapsed time since keepalive
Expand All @@ -86,8 +85,7 @@ static void peer_process(struct hash_bucket *hb, void *arg)

static const struct timeval tolerance = {0, 100000};

uint32_t v_ka = atomic_load_explicit(&pkat->peer->v_keepalive,
memory_order_relaxed);
uint32_t v_ka = atomic_load_explicit(&peer->v_keepalive, memory_order_relaxed);

/* 0 keepalive timer means no keepalives */
if (v_ka == 0)
Expand All @@ -104,11 +102,10 @@ static void peer_process(struct hash_bucket *hb, void *arg)
elapsed.tv_sec >= ka.tv_sec || timercmp(&diff, &tolerance, <);

if (send_keepalive) {
if (bgp_debug_keepalive(pkat->peer))
zlog_debug("%s [FSM] Timer (keepalive timer expire)",
pkat->peer->host);
if (bgp_debug_keepalive(peer))
zlog_debug("%s [FSM] Timer (keepalive timer expire)", peer->host);

bgp_keepalive_send(pkat->peer->connection);
bgp_keepalive_send(pkat->connection);
monotime(&pkat->last);
memset(&elapsed, 0, sizeof(elapsed));
diff = ka;
Expand All @@ -124,13 +121,13 @@ static bool peer_hash_cmp(const void *f, const void *s)
const struct pkat *p1 = f;
const struct pkat *p2 = s;

return p1->peer == p2->peer;
return p1->connection == p2->connection;
}

static unsigned int peer_hash_key(const void *arg)
{
const struct pkat *pkat = arg;
return (uintptr_t)pkat->peer;
return (uintptr_t)pkat->connection;
}

/* Cleanup handler / deinitializer. */
Expand Down Expand Up @@ -248,9 +245,9 @@ void bgp_keepalives_on(struct peer_connection *connection)
assert(peerhash_mtx);

frr_with_mutex (peerhash_mtx) {
holder.peer = peer;
holder.connection = connection;
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);
peer_lock(peer);
}
Expand Down Expand Up @@ -279,7 +276,7 @@ void bgp_keepalives_off(struct peer_connection *connection)
assert(peerhash_mtx);

frr_with_mutex (peerhash_mtx) {
holder.peer = peer;
holder.connection = connection;
struct pkat *res = hash_release(peerhash, &holder);
if (res) {
pkat_del(res);
Expand Down
Loading