summaryrefslogtreecommitdiff
path: root/sys/net/if_pfsync.c
diff options
context:
space:
mode:
authorcheloha <cheloha@cvs.openbsd.org>2020-06-24 22:03:46 +0000
committercheloha <cheloha@cvs.openbsd.org>2020-06-24 22:03:46 +0000
commitca98724d303a2d2852e5afc6ca4f8df91ce7c4f1 (patch)
tree78c03b913ca4a13ca82e30fea2eea3633977a5a0 /sys/net/if_pfsync.c
parentd5d00fdfec2707a72d8f409ed3069c27bc916b04 (diff)
kernel: use gettime(9)/getuptime(9) in lieu of time_second(9)/time_uptime(9)
time_second(9) and time_uptime(9) are widely used in the kernel to quickly get the system UTC or system uptime as a time_t. However, time_t is 64-bit everywhere, so it is not generally safe to use them on 32-bit platforms: you have a split-read problem if your hardware cannot perform atomic 64-bit reads. This patch replaces time_second(9) with gettime(9), a safer successor interface, throughout the kernel. Similarly, time_uptime(9) is replaced with getuptime(9). There is a performance cost on 32-bit platforms in exchange for eliminating the split-read problem: instead of two register reads you now have a lockless read loop to pull the values from the timehands. This is really not *too* bad in the grand scheme of things, but compared to what we were doing before it is several times slower. There is no performance cost on 64-bit (__LP64__) platforms. With input from visa@, dlg@, and tedu@. Several bugs squashed by visa@. ok kettenis@
Diffstat (limited to 'sys/net/if_pfsync.c')
-rw-r--r--sys/net/if_pfsync.c26
1 files changed, 13 insertions, 13 deletions
diff --git a/sys/net/if_pfsync.c b/sys/net/if_pfsync.c
index ce9b909d4e7..515504d38e9 100644
--- a/sys/net/if_pfsync.c
+++ b/sys/net/if_pfsync.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: if_pfsync.c,v 1.270 2020/04/12 11:56:52 mpi Exp $ */
+/* $OpenBSD: if_pfsync.c,v 1.271 2020/06/24 22:03:43 cheloha Exp $ */
/*
* Copyright (c) 2002 Michael Shalayeff
@@ -590,8 +590,8 @@ pfsync_state_import(struct pfsync_state *sp, int flags)
/* copy to state */
bcopy(&sp->rt_addr, &st->rt_addr, sizeof(st->rt_addr));
- st->creation = time_uptime - ntohl(sp->creation);
- st->expire = time_uptime;
+ st->creation = getuptime() - ntohl(sp->creation);
+ st->expire = getuptime();
if (ntohl(sp->expire)) {
u_int32_t timeout;
@@ -622,7 +622,7 @@ pfsync_state_import(struct pfsync_state *sp, int flags)
st->anchor.ptr = NULL;
st->rt_kif = NULL;
- st->pfsync_time = time_uptime;
+ st->pfsync_time = getuptime();
st->sync_state = PFSYNC_S_NONE;
refcnt_init(&st->refcnt);
@@ -962,10 +962,10 @@ pfsync_in_upd(caddr_t buf, int len, int count, int flags)
if (sync < 2) {
pfsync_alloc_scrub_memory(&sp->dst, &st->dst);
pf_state_peer_ntoh(&sp->dst, &st->dst);
- st->expire = time_uptime;
+ st->expire = getuptime();
st->timeout = sp->timeout;
}
- st->pfsync_time = time_uptime;
+ st->pfsync_time = getuptime();
if (sync) {
pfsyncstat_inc(pfsyncs_stale);
@@ -1036,10 +1036,10 @@ pfsync_in_upd_c(caddr_t buf, int len, int count, int flags)
if (sync < 2) {
pfsync_alloc_scrub_memory(&up->dst, &st->dst);
pf_state_peer_ntoh(&up->dst, &st->dst);
- st->expire = time_uptime;
+ st->expire = getuptime();
st->timeout = up->timeout;
}
- st->pfsync_time = time_uptime;
+ st->pfsync_time = getuptime();
if (sync) {
pfsyncstat_inc(pfsyncs_stale);
@@ -1160,7 +1160,7 @@ pfsync_in_bus(caddr_t buf, int len, int count, int flags)
break;
case PFSYNC_BUS_END:
- if (time_uptime - ntohl(bus->endtime) >=
+ if (getuptime() - ntohl(bus->endtime) >=
sc->sc_ureq_sent) {
/* that's it, we're happy */
sc->sc_ureq_sent = 0;
@@ -1947,7 +1947,7 @@ pfsync_update_state_locked(struct pf_state *st)
st->sync_state);
}
- if (sync || (time_uptime - st->pfsync_time) < 2)
+ if (sync || (getuptime() - st->pfsync_time) < 2)
schednetisr(NETISR_PFSYNC);
}
@@ -1998,7 +1998,7 @@ pfsync_request_full_update(struct pfsync_softc *sc)
{
if (sc->sc_sync_if && ISSET(sc->sc_if.if_flags, IFF_RUNNING)) {
/* Request a full state table update. */
- sc->sc_ureq_sent = time_uptime;
+ sc->sc_ureq_sent = getuptime();
#if NCARP > 0
if (!sc->sc_link_demoted && pfsync_sync_ok)
carp_group_demote_adj(&sc->sc_if, 1,
@@ -2306,7 +2306,7 @@ pfsync_bulk_start(void)
if (TAILQ_EMPTY(&state_list))
pfsync_bulk_status(PFSYNC_BUS_END);
else {
- sc->sc_ureq_received = time_uptime;
+ sc->sc_ureq_received = getuptime();
if (sc->sc_bulk_next == NULL)
sc->sc_bulk_next = TAILQ_FIRST(&state_list);
@@ -2379,7 +2379,7 @@ pfsync_bulk_status(u_int8_t status)
r.subh.count = htons(1);
r.bus.creatorid = pf_status.hostid;
- r.bus.endtime = htonl(time_uptime - sc->sc_ureq_received);
+ r.bus.endtime = htonl(getuptime() - sc->sc_ureq_received);
r.bus.status = status;
pfsync_send_plus(&r, sizeof(r));