-/* $OpenBSD: if_pfsync.c,v 1.314 2023/04/28 15:50:05 sashan Exp $ */
+/* $OpenBSD: if_pfsync.c,v 1.315 2023/05/18 12:10:04 sashan Exp $ */
/*
* Copyright (c) 2002 Michael Shalayeff
while ((st = TAILQ_FIRST(&sc->sc_qs[q])) != NULL) {
TAILQ_REMOVE(&sc->sc_qs[q], st, sync_list);
+ mtx_enter(&st->mtx);
if (st->snapped == 0) {
TAILQ_INSERT_TAIL(&sn->sn_qs[q], st, sync_snap);
st->snapped = 1;
+ mtx_leave(&st->mtx);
} else {
/*
* item is on snapshot list already, so we can
* skip it now.
*/
+ mtx_leave(&st->mtx);
pf_state_unref(st);
}
}
continue;
while ((st = TAILQ_FIRST(&sn->sn_qs[q])) != NULL) {
+ mtx_enter(&st->mtx);
KASSERT(st->sync_state == q);
KASSERT(st->snapped == 1);
TAILQ_REMOVE(&sn->sn_qs[q], st, sync_snap);
st->sync_state = PFSYNC_S_NONE;
st->snapped = 0;
+ mtx_leave(&st->mtx);
pf_state_unref(st);
}
}
count = 0;
while ((st = TAILQ_FIRST(&sn.sn_qs[q])) != NULL) {
+ mtx_enter(&st->mtx);
TAILQ_REMOVE(&sn.sn_qs[q], st, sync_snap);
KASSERT(st->sync_state == q);
KASSERT(st->snapped == 1);
st->snapped = 0;
pfsync_qs[q].write(st, m->m_data + offset);
offset += pfsync_qs[q].len;
+ mtx_leave(&st->mtx);
pf_state_unref(st);
count++;
ISSET(st->state_flags, PFSTATE_NOSYNC))
return;
- KASSERT(st->sync_state == PFSYNC_S_NONE);
-
if (sc->sc_len == PFSYNC_MINPKT)
timeout_add_sec(&sc->sc_tmo, 1);
panic("pfsync pkt len is too low %zd", sc->sc_len);
do {
mtx_enter(&sc->sc_st_mtx);
+ mtx_enter(&st->mtx);
/*
* There are either two threads trying to update the
* (is on snapshot queue).
*/
if (st->sync_state != PFSYNC_S_NONE) {
+ mtx_leave(&st->mtx);
mtx_leave(&sc->sc_st_mtx);
break;
}
sclen = atomic_add_long_nv(&sc->sc_len, nlen);
if (sclen > sc->sc_if.if_mtu) {
atomic_sub_long(&sc->sc_len, nlen);
+ mtx_leave(&st->mtx);
mtx_leave(&sc->sc_st_mtx);
pfsync_sendout();
continue;
TAILQ_INSERT_TAIL(&sc->sc_qs[q], st, sync_list);
st->sync_state = q;
+ mtx_leave(&st->mtx);
mtx_leave(&sc->sc_st_mtx);
} while (0);
}
int q;
mtx_enter(&sc->sc_st_mtx);
+ mtx_enter(&st->mtx);
q = st->sync_state;
/*
* re-check under mutex
* too late, the state is being just processed/dispatched to peer.
*/
if ((q == PFSYNC_S_NONE) || (st->snapped)) {
+ mtx_leave(&st->mtx);
mtx_leave(&sc->sc_st_mtx);
return;
}
if (TAILQ_EMPTY(&sc->sc_qs[q]))
atomic_sub_long(&sc->sc_len, sizeof (struct pfsync_subheader));
st->sync_state = PFSYNC_S_NONE;
+ mtx_leave(&st->mtx);
mtx_leave(&sc->sc_st_mtx);
pf_state_unref(st);