*
* @return maximum time to wait until next update (0 if infinity)
*/
-static void peer_process(struct hash_backet *hb, void *arg)
+static void peer_process(struct hash_bucket *hb, void *arg)
{
struct pkat *pkat = hb->data;
static struct timeval ka = {0}; // peer->v_keepalive as a timeval
static struct timeval diff; // ka - elapsed
- static struct timeval tolerance = {0, 100000};
+ static const struct timeval tolerance = {0, 100000};
+
+ uint32_t v_ka = atomic_load_explicit(&pkat->peer->v_keepalive,
+ memory_order_relaxed);
+
+ /* 0 keepalive timer means no keepalives */
+ if (v_ka == 0)
+ return;
/* calculate elapsed time since last keepalive */
monotime_since(&pkat->last, &elapsed);
/* calculate difference between elapsed time and configured time */
- ka.tv_sec = pkat->peer->v_keepalive;
+ ka.tv_sec = v_ka;
timersub(&ka, &elapsed, &diff);
int send_keepalive =
return p1->peer == p2->peer;
}
-static unsigned int peer_hash_key(void *arg)
+static unsigned int peer_hash_key(const void *arg)
{
- struct pkat *pkat = arg;
+ const struct pkat *pkat = arg;
return (uintptr_t)pkat->peer;
}
*/
assert(peerhash_mtx);
- pthread_mutex_lock(peerhash_mtx);
- {
+ frr_with_mutex(peerhash_mtx) {
holder.peer = peer;
if (!hash_lookup(peerhash, &holder)) {
struct pkat *pkat = pkat_new(peer);
}
SET_FLAG(peer->thread_flags, PEER_THREAD_KEEPALIVES_ON);
}
- pthread_mutex_unlock(peerhash_mtx);
bgp_keepalives_wake();
}
*/
assert(peerhash_mtx);
- pthread_mutex_lock(peerhash_mtx);
- {
+ frr_with_mutex(peerhash_mtx) {
holder.peer = peer;
struct pkat *res = hash_release(peerhash, &holder);
if (res) {
}
UNSET_FLAG(peer->thread_flags, PEER_THREAD_KEEPALIVES_ON);
}
- pthread_mutex_unlock(peerhash_mtx);
}
void bgp_keepalives_wake(void)
{
- pthread_mutex_lock(peerhash_mtx);
- {
+ frr_with_mutex(peerhash_mtx) {
pthread_cond_signal(peerhash_cond);
}
- pthread_mutex_unlock(peerhash_mtx);
}
int bgp_keepalives_stop(struct frr_pthread *fpt, void **result)