-/* $OpenBSD: if_pfsync.c,v 1.291 2021/06/15 08:36:19 dlg Exp $ */
+/* $OpenBSD: if_pfsync.c,v 1.292 2021/06/15 10:10:22 dlg Exp $ */
/*
* Copyright (c) 2002 Michael Shalayeff
#include "bpfilter.h"
#include "pfsync.h"
+#define PFSYNC_DEFER_NSEC 20000000ULL
+
#define PFSYNC_MINPKT ( \
sizeof(struct ip) + \
sizeof(struct pfsync_header))
TAILQ_ENTRY(pfsync_deferral) pd_entry;
struct pf_state *pd_st;
struct mbuf *pd_m;
- struct timeval pd_deadline;
+ uint64_t pd_deadline;
};
TAILQ_HEAD(pfsync_deferrals, pfsync_deferral);
{
struct pfsync_softc *sc = pfsyncif;
struct pfsync_deferral *pd;
- struct timeval now;
unsigned int sched;
- static const struct timeval defer = { 0, 20000 };
NET_ASSERT_LOCKED();
pd->pd_st = pf_state_ref(st);
pd->pd_m = m;
- getmicrouptime(&now);
- timeradd(&now, &defer, &pd->pd_deadline);
+ pd->pd_deadline = getnsecuptime() + PFSYNC_DEFER_NSEC;
mtx_enter(&sc->sc_deferrals_mtx);
sched = TAILQ_EMPTY(&sc->sc_deferrals);
mtx_leave(&sc->sc_deferrals_mtx);
if (sched)
- timeout_add_tv(&sc->sc_deferrals_tmo, &defer);
+ timeout_add_nsec(&sc->sc_deferrals_tmo, PFSYNC_DEFER_NSEC);
schednetisr(NETISR_PFSYNC);
{
struct pfsync_softc *sc = arg;
struct pfsync_deferral *pd;
- struct timeval now, tv;
+ uint64_t now, nsec = 0;
struct pfsync_deferrals pds = TAILQ_HEAD_INITIALIZER(pds);
- getmicrouptime(&now);
+ now = getnsecuptime();
mtx_enter(&sc->sc_deferrals_mtx);
for (;;) {
if (pd == NULL)
break;
- if (timercmp(&now, &pd->pd_deadline, <)) {
- timersub(&now, &pd->pd_deadline, &tv);
+ if (now < pd->pd_deadline) {
+ nsec = pd->pd_deadline - now;
break;
}
}
mtx_leave(&sc->sc_deferrals_mtx);
- if (pd != NULL) {
+ if (nsec > 0) {
/* we were looking at a pd, but it wasn't old enough */
- timeout_add_tv(&sc->sc_deferrals_tmo, &tv);
+ timeout_add_nsec(&sc->sc_deferrals_tmo, nsec);
}
if (TAILQ_EMPTY(&pds))