-/* $OpenBSD: if_pfsync.c,v 1.300 2022/02/25 22:18:44 bluhm Exp $ */
+/* $OpenBSD: if_pfsync.c,v 1.301 2022/03/08 20:46:01 sashan Exp $ */
/*
* Copyright (c) 2002 Michael Shalayeff
struct ip sc_template;
struct pf_state_queue sc_qs[PFSYNC_S_COUNT];
- struct mutex sc_mtx[PFSYNC_S_COUNT];
+ struct mutex sc_st_mtx;
size_t sc_len;
struct pfsync_upd_reqs sc_upd_req_list;
struct pfsync_softc *sc;
struct ifnet *ifp;
int q;
- static const char *mtx_names[] = {
- "iack_mtx",
- "upd_c_mtx",
- "del_mtx",
- "ins_mtx",
- "upd_mtx",
- "" };
if (unit != 0)
return (EINVAL);
pfsync_sync_ok = 1;
sc = malloc(sizeof(*pfsyncif), M_DEVBUF, M_WAITOK|M_ZERO);
- for (q = 0; q < PFSYNC_S_COUNT; q++) {
+ for (q = 0; q < PFSYNC_S_COUNT; q++)
TAILQ_INIT(&sc->sc_qs[q]);
- mtx_init_flags(&sc->sc_mtx[q], IPL_SOFTNET, mtx_names[q], 0);
- }
+ mtx_init_flags(&sc->sc_st_mtx, IPL_SOFTNET, "st_mtx", 0);
pool_init(&sc->sc_pool, PFSYNC_PLSIZE, 0, IPL_SOFTNET, 0, "pfsync",
NULL);
sn->sn_sc = sc;
- for (q = 0; q < PFSYNC_S_COUNT; q++)
- mtx_enter(&sc->sc_mtx[q]);
-
+ mtx_enter(&sc->sc_st_mtx);
mtx_enter(&sc->sc_upd_req_mtx);
mtx_enter(&sc->sc_tdb_mtx);
mtx_leave(&sc->sc_tdb_mtx);
mtx_leave(&sc->sc_upd_req_mtx);
-
- for (q = (PFSYNC_S_COUNT - 1); q >= 0; q--)
- mtx_leave(&sc->sc_mtx[q]);
+ mtx_leave(&sc->sc_st_mtx);
}
void
panic("pfsync pkt len is too low %zd", sc->sc_len);
#endif
do {
- mtx_enter(&sc->sc_mtx[q]);
+ mtx_enter(&sc->sc_st_mtx);
/*
* If two threads are competing to insert the same state, then
* there must be just single winner.
*/
if (st->sync_state != PFSYNC_S_NONE) {
- mtx_leave(&sc->sc_mtx[q]);
+ mtx_leave(&sc->sc_st_mtx);
break;
}
sc_len = atomic_add_long_nv(&sc->sc_len, nlen);
if (sc_len > sc->sc_if.if_mtu) {
atomic_sub_long(&sc->sc_len, nlen);
- mtx_leave(&sc->sc_mtx[q]);
+ 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(&sc->sc_mtx[q]);
+ mtx_leave(&sc->sc_st_mtx);
} while (0);
}
pfsync_q_del(struct pf_state *st)
{
struct pfsync_softc *sc = pfsyncif;
- int q = st->sync_state;
+ int q;
KASSERT(st->sync_state != PFSYNC_S_NONE);
- mtx_enter(&sc->sc_mtx[q]);
+ mtx_enter(&sc->sc_st_mtx);
+ q = st->sync_state;
atomic_sub_long(&sc->sc_len, pfsync_qs[q].len);
TAILQ_REMOVE(&sc->sc_qs[q], st, sync_list);
if (TAILQ_EMPTY(&sc->sc_qs[q]))
atomic_sub_long(&sc->sc_len, sizeof (struct pfsync_subheader));
- mtx_leave(&sc->sc_mtx[q]);
-
st->sync_state = PFSYNC_S_NONE;
+ mtx_leave(&sc->sc_st_mtx);
+
pf_state_unref(st);
}