forked from Mirror/frr
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:
parent
2cd1d00dde
commit
23bdaba147
|
@ -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;
|
||||
};
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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.
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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;
|
||||
|
@ -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. */
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue