summaryrefslogtreecommitdiffstats
path: root/sys/net
diff options
context:
space:
mode:
authorcheloha <cheloha@openbsd.org>2020-06-24 22:03:40 +0000
committercheloha <cheloha@openbsd.org>2020-06-24 22:03:40 +0000
commit3209772dfcc3950dd5df01bc44eebf75e637511e (patch)
tree674a3736a2e3e277e801c3c22c1430cb8a2d032f /sys/net
parentFirst stab at making signal handling work. (diff)
downloadwireguard-openbsd-3209772dfcc3950dd5df01bc44eebf75e637511e.tar.xz
wireguard-openbsd-3209772dfcc3950dd5df01bc44eebf75e637511e.zip
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')
-rw-r--r--sys/net/bridgectl.c6
-rw-r--r--sys/net/if_bpe.c12
-rw-r--r--sys/net/if_bridge.c6
-rw-r--r--sys/net/if_pflow.c32
-rw-r--r--sys/net/if_pfsync.c26
-rw-r--r--sys/net/if_ppp.c14
-rw-r--r--sys/net/pf.c40
-rw-r--r--sys/net/pf_if.c10
-rw-r--r--sys/net/pf_ioctl.c12
-rw-r--r--sys/net/pf_norm.c8
-rw-r--r--sys/net/pf_table.c20
-rw-r--r--sys/net/route.c8
-rw-r--r--sys/net/rtsock.c10
13 files changed, 102 insertions, 102 deletions
diff --git a/sys/net/bridgectl.c b/sys/net/bridgectl.c
index be0f03a7f70..491770f9543 100644
--- a/sys/net/bridgectl.c
+++ b/sys/net/bridgectl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: bridgectl.c,v 1.20 2019/07/09 15:15:49 mpi Exp $ */
+/* $OpenBSD: bridgectl.c,v 1.21 2020/06/24 22:03:42 cheloha Exp $ */
/*
* Copyright (c) 1999, 2000 Jason L. Wright (jason@thought.net)
@@ -397,9 +397,9 @@ bridge_rtagenode(struct ifnet *ifp, int age)
LIST_FOREACH(n, &sc->sc_rts[i], brt_next) {
/* Cap the expiry time to 'age' */
if (n->brt_ifidx == ifp->if_index &&
- n->brt_age > time_uptime + age &&
+ n->brt_age > getuptime() + age &&
(n->brt_flags & IFBAF_TYPEMASK) == IFBAF_DYNAMIC)
- n->brt_age = time_uptime + age;
+ n->brt_age = getuptime() + age;
}
}
mtx_leave(&sc->sc_mtx);
diff --git a/sys/net/if_bpe.c b/sys/net/if_bpe.c
index b9a88be8efa..13224499bb1 100644
--- a/sys/net/if_bpe.c
+++ b/sys/net/if_bpe.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: if_bpe.c,v 1.10 2019/11/07 07:36:31 dlg Exp $ */
+/* $OpenBSD: if_bpe.c,v 1.11 2020/06/24 22:03:43 cheloha Exp $ */
/*
* Copyright (c) 2018 David Gwynne <dlg@openbsd.org>
*
@@ -230,7 +230,7 @@ bpe_entry_valid(struct bpe_softc *sc, const struct bpe_entry *be)
if (be->be_type == BPE_ENTRY_STATIC)
return (1);
- diff = time_uptime - be->be_age;
+ diff = getuptime() - be->be_age;
if (diff < sc->sc_bridge_tmo)
return (1);
@@ -343,7 +343,7 @@ bpe_bridge_age(void *arg)
if (be->be_type != BPE_ENTRY_DYNAMIC)
continue;
- diff = time_uptime - be->be_age;
+ diff = getuptime() - be->be_age;
if (diff < sc->sc_bridge_tmo)
continue;
@@ -402,7 +402,7 @@ bpe_rtfind(struct bpe_softc *sc, struct ifbaconf *baconf)
switch (be->be_type) {
case BPE_ENTRY_DYNAMIC:
- age = time_uptime - be->be_age;
+ age = getuptime() - be->be_age;
bareq.ifba_age = MIN(age, 0xff);
bareq.ifba_flags = IFBAF_DYNAMIC;
break;
@@ -833,7 +833,7 @@ bpe_input_map(struct bpe_softc *sc, const uint8_t *ba, const uint8_t *ca)
if (be == NULL)
new = 1;
else {
- be->be_age = time_uptime; /* only a little bit racy */
+ be->be_age = getuptime(); /* only a little bit racy */
if (be->be_type != BPE_ENTRY_DYNAMIC ||
ETHER_IS_EQ(ba, &be->be_b_da))
@@ -857,7 +857,7 @@ bpe_input_map(struct bpe_softc *sc, const uint8_t *ba, const uint8_t *ca)
memcpy(&be->be_b_da, ba, sizeof(be->be_b_da));
be->be_type = BPE_ENTRY_DYNAMIC;
refcnt_init(&be->be_refs);
- be->be_age = time_uptime;
+ be->be_age = getuptime();
rw_enter_write(&sc->sc_bridge_lock);
num = sc->sc_bridge_num;
diff --git a/sys/net/if_bridge.c b/sys/net/if_bridge.c
index de8cdfe0d93..5a1ff7884da 100644
--- a/sys/net/if_bridge.c
+++ b/sys/net/if_bridge.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: if_bridge.c,v 1.339 2020/04/12 06:48:46 visa Exp $ */
+/* $OpenBSD: if_bridge.c,v 1.340 2020/06/24 22:03:42 cheloha Exp $ */
/*
* Copyright (c) 1999, 2000 Jason L. Wright (jason@thought.net)
@@ -1541,7 +1541,7 @@ bridge_ipsec(struct ifnet *ifp, struct ether_header *eh, int hassnap,
if (tdb != NULL && (tdb->tdb_flags & TDBF_INVALID) == 0 &&
tdb->tdb_xform != NULL) {
if (tdb->tdb_first_use == 0) {
- tdb->tdb_first_use = time_second;
+ tdb->tdb_first_use = gettime();
if (tdb->tdb_flags & TDBF_FIRSTUSE)
timeout_add_sec(&tdb->tdb_first_tmo,
tdb->tdb_exp_first_use);
@@ -1586,7 +1586,7 @@ bridge_ipsec(struct ifnet *ifp, struct ether_header *eh, int hassnap,
if ((af == AF_INET) &&
ip_mtudisc && (ip->ip_off & htons(IP_DF)) &&
tdb->tdb_mtu && ntohs(ip->ip_len) > tdb->tdb_mtu &&
- tdb->tdb_mtutimeout > time_second)
+ tdb->tdb_mtutimeout > gettime())
bridge_send_icmp_err(ifp, eh, m,
hassnap, llc, tdb->tdb_mtu,
ICMP_UNREACH, ICMP_UNREACH_NEEDFRAG);
diff --git a/sys/net/if_pflow.c b/sys/net/if_pflow.c
index e78eeb9090d..1d482865013 100644
--- a/sys/net/if_pflow.c
+++ b/sys/net/if_pflow.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: if_pflow.c,v 1.90 2018/07/30 12:22:14 mpi Exp $ */
+/* $OpenBSD: if_pflow.c,v 1.91 2020/06/24 22:03:42 cheloha Exp $ */
/*
* Copyright (c) 2011 Florian Obser <florian@narrans.de>
@@ -734,13 +734,13 @@ copy_flow_ipfix_4_data(struct pflow_ipfix_flow4 *flow1,
* is in the future of the last time a package was seen due to pfsync.
*/
if (st->creation > st->expire)
- flow1->flow_start = flow2->flow_start = htobe64((time_second -
- time_uptime)*1000);
+ flow1->flow_start = flow2->flow_start = htobe64((gettime() -
+ getuptime())*1000);
else
- flow1->flow_start = flow2->flow_start = htobe64((time_second -
- (time_uptime - st->creation))*1000);
- flow1->flow_finish = flow2->flow_finish = htobe64((time_second -
- (time_uptime - st->expire))*1000);
+ flow1->flow_start = flow2->flow_start = htobe64((gettime() -
+ (getuptime() - st->creation))*1000);
+ flow1->flow_finish = flow2->flow_finish = htobe64((gettime() -
+ (getuptime() - st->expire))*1000);
flow1->protocol = flow2->protocol = sk->proto;
flow1->tos = flow2->tos = st->rule.ptr->tos;
@@ -773,13 +773,13 @@ copy_flow_ipfix_6_data(struct pflow_ipfix_flow6 *flow1,
* is in the future of the last time a package was seen due to pfsync.
*/
if (st->creation > st->expire)
- flow1->flow_start = flow2->flow_start = htobe64((time_second -
- time_uptime)*1000);
+ flow1->flow_start = flow2->flow_start = htobe64((gettime() -
+ getuptime())*1000);
else
- flow1->flow_start = flow2->flow_start = htobe64((time_second -
- (time_uptime - st->creation))*1000);
- flow1->flow_finish = flow2->flow_finish = htobe64((time_second -
- (time_uptime - st->expire))*1000);
+ flow1->flow_start = flow2->flow_start = htobe64((gettime() -
+ (getuptime() - st->creation))*1000);
+ flow1->flow_finish = flow2->flow_finish = htobe64((gettime() -
+ (getuptime() - st->expire))*1000);
flow1->protocol = flow2->protocol = sk->proto;
flow1->tos = flow2->tos = st->rule.ptr->tos;
@@ -1082,7 +1082,7 @@ pflow_sendout_v5(struct pflow_softc *sc)
h->count = htons(sc->sc_count);
/* populate pflow_header */
- h->uptime_ms = htonl(time_uptime * 1000);
+ h->uptime_ms = htonl(getuptime() * 1000);
getnanotime(&tv);
h->time_sec = htonl(tv.tv_sec); /* XXX 2038 */
@@ -1145,7 +1145,7 @@ pflow_sendout_ipfix(struct pflow_softc *sc, sa_family_t af)
h10 = mtod(m, struct pflow_v10_header *);
h10->version = htons(PFLOW_PROTO_10);
h10->length = htons(PFLOW_IPFIX_HDRLEN + set_length);
- h10->time_sec = htonl(time_second); /* XXX 2038 */
+ h10->time_sec = htonl(gettime()); /* XXX 2038 */
h10->flow_sequence = htonl(sc->sc_sequence);
sc->sc_sequence += count;
h10->observation_dom = htonl(PFLOW_ENGINE_TYPE);
@@ -1186,7 +1186,7 @@ pflow_sendout_ipfix_tmpl(struct pflow_softc *sc)
h10->version = htons(PFLOW_PROTO_10);
h10->length = htons(PFLOW_IPFIX_HDRLEN + sizeof(struct
pflow_ipfix_tmpl));
- h10->time_sec = htonl(time_second); /* XXX 2038 */
+ h10->time_sec = htonl(gettime()); /* XXX 2038 */
h10->flow_sequence = htonl(sc->sc_sequence);
h10->observation_dom = htonl(PFLOW_ENGINE_TYPE);
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));
diff --git a/sys/net/if_ppp.c b/sys/net/if_ppp.c
index 3f03d18b6ab..19b486a50c3 100644
--- a/sys/net/if_ppp.c
+++ b/sys/net/if_ppp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: if_ppp.c,v 1.113 2020/05/20 06:44:30 mpi Exp $ */
+/* $OpenBSD: if_ppp.c,v 1.114 2020/06/24 22:03:42 cheloha Exp $ */
/* $NetBSD: if_ppp.c,v 1.39 1997/05/17 21:11:59 christos Exp $ */
/*
@@ -294,7 +294,7 @@ pppalloc(pid_t pid)
for (i = 0; i < NUM_NP; ++i)
sc->sc_npmode[i] = NPMODE_ERROR;
ml_init(&sc->sc_npqueue);
- sc->sc_last_sent = sc->sc_last_recv = time_uptime;
+ sc->sc_last_sent = sc->sc_last_recv = getuptime();
return sc;
}
@@ -514,7 +514,7 @@ pppioctl(struct ppp_softc *sc, u_long cmd, caddr_t data, int flag,
break;
case PPPIOCGIDLE:
- t = time_uptime;
+ t = getuptime();
((struct ppp_idle *)data)->xmit_idle = t - sc->sc_last_sent;
((struct ppp_idle *)data)->recv_idle = t - sc->sc_last_recv;
break;
@@ -744,14 +744,14 @@ pppoutput(struct ifnet *ifp, struct mbuf *m0, struct sockaddr *dst,
if (sc->sc_active_filt.bf_insns == 0 ||
bpf_filter(sc->sc_active_filt.bf_insns, (u_char *)m0,
len, 0))
- sc->sc_last_sent = time_uptime;
+ sc->sc_last_sent = getuptime();
*mtod(m0, u_char *) = address;
#else
/*
* Update the time we sent the most recent packet.
*/
- sc->sc_last_sent = time_uptime;
+ sc->sc_last_sent = getuptime();
#endif
}
@@ -1356,14 +1356,14 @@ ppp_inproc(struct ppp_softc *sc, struct mbuf *m)
if (sc->sc_active_filt.bf_insns == 0 ||
bpf_filter(sc->sc_active_filt.bf_insns, (u_char *)m,
ilen, 0))
- sc->sc_last_recv = time_uptime;
+ sc->sc_last_recv = getuptime();
*mtod(m, u_char *) = adrs;
#else
/*
* Record the time that we received this packet.
*/
- sc->sc_last_recv = time_uptime;
+ sc->sc_last_recv = getuptime();
#endif
}
diff --git a/sys/net/pf.c b/sys/net/pf.c
index d31ef989743..034c138e234 100644
--- a/sys/net/pf.c
+++ b/sys/net/pf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pf.c,v 1.1092 2020/06/17 06:45:22 dlg Exp $ */
+/* $OpenBSD: pf.c,v 1.1093 2020/06/24 22:03:42 cheloha Exp $ */
/*
* Copyright (c) 2001 Daniel Hartmeier
@@ -417,13 +417,13 @@ pf_init_threshold(struct pf_threshold *threshold,
threshold->limit = limit * PF_THRESHOLD_MULT;
threshold->seconds = seconds;
threshold->count = 0;
- threshold->last = time_uptime;
+ threshold->last = getuptime();
}
void
pf_add_threshold(struct pf_threshold *threshold)
{
- u_int32_t t = time_uptime, diff = t - threshold->last;
+ u_int32_t t = getuptime(), diff = t - threshold->last;
if (diff >= threshold->seconds)
threshold->count = 0;
@@ -496,7 +496,7 @@ pf_src_connlimit(struct pf_state **state)
}
pfr_insert_kentry((*state)->rule.ptr->overload_tbl,
- &p, time_second);
+ &p, gettime());
/* kill existing states if that's required. */
if ((*state)->rule.ptr->flush) {
@@ -584,7 +584,7 @@ pf_insert_src_node(struct pf_src_node **sn, struct pf_rule *rule,
pool_put(&pf_src_tree_pl, *sn);
return (-1);
}
- (*sn)->creation = time_uptime;
+ (*sn)->creation = getuptime();
(*sn)->rule.ptr->src_nodes++;
if (kif != NULL) {
(*sn)->kif = kif;
@@ -605,7 +605,7 @@ pf_insert_src_node(struct pf_src_node **sn, struct pf_rule *rule,
void
pf_remove_src_node(struct pf_src_node *sn)
{
- if (sn->states > 0 || sn->expire > time_uptime)
+ if (sn->states > 0 || sn->expire > getuptime())
return;
sn->rule.ptr->src_nodes--;
@@ -1187,12 +1187,12 @@ pf_state_export(struct pfsync_state *sp, struct pf_state *st)
/* copy from state */
strlcpy(sp->ifname, st->kif->pfik_name, sizeof(sp->ifname));
memcpy(&sp->rt_addr, &st->rt_addr, sizeof(sp->rt_addr));
- sp->creation = htonl(time_uptime - st->creation);
+ sp->creation = htonl(getuptime() - st->creation);
expire = pf_state_expires(st);
- if (expire <= time_uptime)
+ if (expire <= getuptime())
sp->expire = htonl(0);
else
- sp->expire = htonl(expire - time_uptime);
+ sp->expire = htonl(expire - getuptime());
sp->direction = st->direction;
#if NPFLOG > 0
@@ -1342,7 +1342,7 @@ pf_purge_expired_src_nodes(void)
for (cur = RB_MIN(pf_src_tree, &tree_src_tracking); cur; cur = next) {
next = RB_NEXT(pf_src_tree, &tree_src_tracking, cur);
- if (cur->states == 0 && cur->expire <= time_uptime) {
+ if (cur->states == 0 && cur->expire <= getuptime()) {
next = RB_NEXT(pf_src_tree, &tree_src_tracking, cur);
pf_remove_src_node(cur);
}
@@ -1364,7 +1364,7 @@ pf_src_tree_remove_state(struct pf_state *s)
if (!timeout)
timeout =
pf_default_rule.timeout[PFTM_SRC_NODE];
- sni->sn->expire = time_uptime + timeout;
+ sni->sn->expire = getuptime() + timeout;
}
pool_put(&pf_sn_item_pl, sni);
}
@@ -1477,7 +1477,7 @@ pf_purge_expired_states(u_int32_t maxcheck)
next = TAILQ_NEXT(cur, entry_list);
if ((cur->timeout == PFTM_UNLINKED) ||
- (pf_state_expires(cur) <= time_uptime))
+ (pf_state_expires(cur) <= getuptime()))
SLIST_INSERT_HEAD(&gcl, cur, gc_list);
else
pf_state_unref(cur);
@@ -3976,7 +3976,7 @@ pf_test_rule(struct pf_pdesc *pd, struct pf_rule **rm, struct pf_state **sm,
if (((rule_flag & PFRULE_EXPIRED) == 0) &&
atomic_cas_uint(&r->rule_flag, rule_flag,
rule_flag | PFRULE_EXPIRED) == rule_flag) {
- r->exptime = time_second;
+ r->exptime = gettime();
SLIST_INSERT_HEAD(&pf_rule_gcl, r, gcle);
}
}
@@ -4095,8 +4095,8 @@ pf_create_state(struct pf_pdesc *pd, struct pf_rule *r, struct pf_rule *a,
s->timeout = PFTM_OTHER_FIRST_PACKET;
}
- s->creation = time_uptime;
- s->expire = time_uptime;
+ s->creation = getuptime();
+ s->expire = getuptime();
if (pd->proto == IPPROTO_TCP) {
if (s->state_flags & PFSTATE_SCRUB_TCP &&
@@ -4478,7 +4478,7 @@ pf_tcp_track_full(struct pf_pdesc *pd, struct pf_state **state, u_short *reason,
pf_set_protostate(*state, PF_PEER_BOTH, TCPS_TIME_WAIT);
/* update expire time */
- (*state)->expire = time_uptime;
+ (*state)->expire = getuptime();
if (src->state >= TCPS_FIN_WAIT_2 &&
dst->state >= TCPS_FIN_WAIT_2)
(*state)->timeout = PFTM_TCP_CLOSED;
@@ -4671,7 +4671,7 @@ pf_tcp_track_sloppy(struct pf_pdesc *pd, struct pf_state **state,
pf_set_protostate(*state, PF_PEER_BOTH, TCPS_TIME_WAIT);
/* update expire time */
- (*state)->expire = time_uptime;
+ (*state)->expire = getuptime();
if (src->state >= TCPS_FIN_WAIT_2 &&
dst->state >= TCPS_FIN_WAIT_2)
(*state)->timeout = PFTM_TCP_CLOSED;
@@ -4878,7 +4878,7 @@ pf_test_state(struct pf_pdesc *pd, struct pf_state **state, u_short *reason,
pf_set_protostate(*state, pdst, PFUDPS_MULTIPLE);
/* update expire time */
- (*state)->expire = time_uptime;
+ (*state)->expire = getuptime();
if (src->state == PFUDPS_MULTIPLE &&
dst->state == PFUDPS_MULTIPLE)
(*state)->timeout = PFTM_UDP_MULTIPLE;
@@ -4893,7 +4893,7 @@ pf_test_state(struct pf_pdesc *pd, struct pf_state **state, u_short *reason,
pf_set_protostate(*state, pdst, PFOTHERS_MULTIPLE);
/* update expire time */
- (*state)->expire = time_uptime;
+ (*state)->expire = getuptime();
if (src->state == PFOTHERS_MULTIPLE &&
dst->state == PFOTHERS_MULTIPLE)
(*state)->timeout = PFTM_OTHER_MULTIPLE;
@@ -5045,7 +5045,7 @@ pf_test_state_icmp(struct pf_pdesc *pd, struct pf_state **state,
if (ret >= 0)
return (ret);
- (*state)->expire = time_uptime;
+ (*state)->expire = getuptime();
(*state)->timeout = PFTM_ICMP_ERROR_REPLY;
/* translate source/destination address, if necessary */
diff --git a/sys/net/pf_if.c b/sys/net/pf_if.c
index 76bb90b2f91..30552d106f5 100644
--- a/sys/net/pf_if.c
+++ b/sys/net/pf_if.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pf_if.c,v 1.99 2019/11/18 03:23:41 dlg Exp $ */
+/* $OpenBSD: pf_if.c,v 1.100 2020/06/24 22:03:42 cheloha Exp $ */
/*
* Copyright 2005 Henning Brauer <henning@openbsd.org>
@@ -121,7 +121,7 @@ pfi_kif_get(const char *kif_name)
return (NULL);
strlcpy(kif->pfik_name, kif_name, sizeof(kif->pfik_name));
- kif->pfik_tzero = time_second;
+ kif->pfik_tzero = gettime();
TAILQ_INIT(&kif->pfik_dynaddrs);
if (!strcmp(kif->pfik_name, "any")) {
@@ -650,7 +650,7 @@ pfi_update_status(const char *name, struct pf_status *pfs)
RB_FOREACH(p, pfi_ifhead, &pfi_ifs) {
memset(p->pfik_packets, 0, sizeof(p->pfik_packets));
memset(p->pfik_bytes, 0, sizeof(p->pfik_bytes));
- p->pfik_tzero = time_second;
+ p->pfik_tzero = gettime();
}
return;
}
@@ -683,7 +683,7 @@ pfi_update_status(const char *name, struct pf_status *pfs)
if (pfs == NULL) {
memset(p->pfik_packets, 0, sizeof(p->pfik_packets));
memset(p->pfik_bytes, 0, sizeof(p->pfik_bytes));
- p->pfik_tzero = time_second;
+ p->pfik_tzero = gettime();
continue;
}
for (i = 0; i < 2; i++)
@@ -709,7 +709,7 @@ pfi_get_ifaces(const char *name, struct pfi_kif *buf, int *size)
continue;
if (*size > n++) {
if (!p->pfik_tzero)
- p->pfik_tzero = time_second;
+ p->pfik_tzero = gettime();
pfi_kif_ref(p, PFI_KIF_REF_RULE);
if (copyout(p, buf++, sizeof(*buf))) {
pfi_kif_unref(p, PFI_KIF_REF_RULE);
diff --git a/sys/net/pf_ioctl.c b/sys/net/pf_ioctl.c
index 931bdcb98cd..a486745bc1c 100644
--- a/sys/net/pf_ioctl.c
+++ b/sys/net/pf_ioctl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pf_ioctl.c,v 1.352 2020/05/27 11:19:28 mpi Exp $ */
+/* $OpenBSD: pf_ioctl.c,v 1.353 2020/06/24 22:03:42 cheloha Exp $ */
/*
* Copyright (c) 2001 Daniel Hartmeier
@@ -1033,9 +1033,9 @@ pfioctl(dev_t dev, u_long cmd, caddr_t addr, int flags, struct proc *p)
error = EEXIST;
else {
pf_status.running = 1;
- pf_status.since = time_uptime;
+ pf_status.since = getuptime();
if (pf_status.stateid == 0) {
- pf_status.stateid = time_second;
+ pf_status.stateid = gettime();
pf_status.stateid = pf_status.stateid << 32;
}
timeout_add_sec(&pf_purge_to, 1);
@@ -1051,7 +1051,7 @@ pfioctl(dev_t dev, u_long cmd, caddr_t addr, int flags, struct proc *p)
error = ENOENT;
else {
pf_status.running = 0;
- pf_status.since = time_uptime;
+ pf_status.since = getuptime();
pf_remove_queues();
DPFPRINTF(LOG_NOTICE, "pf: stopped");
}
@@ -1793,7 +1793,7 @@ pfioctl(dev_t dev, u_long cmd, caddr_t addr, int flags, struct proc *p)
memset(pf_status.counters, 0, sizeof(pf_status.counters));
memset(pf_status.fcounters, 0, sizeof(pf_status.fcounters));
memset(pf_status.scounters, 0, sizeof(pf_status.scounters));
- pf_status.since = time_uptime;
+ pf_status.since = getuptime();
PF_UNLOCK();
break;
@@ -2571,7 +2571,7 @@ pfioctl(dev_t dev, u_long cmd, caddr_t addr, int flags, struct proc *p)
p = psn->psn_src_nodes;
RB_FOREACH(n, pf_src_tree, &tree_src_tracking) {
- int secs = time_uptime, diff;
+ int secs = getuptime(), diff;
if ((nr + 1) * sizeof(*p) > psn->psn_len)
break;
diff --git a/sys/net/pf_norm.c b/sys/net/pf_norm.c
index 570d0523cfc..0a438543e10 100644
--- a/sys/net/pf_norm.c
+++ b/sys/net/pf_norm.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pf_norm.c,v 1.218 2019/02/28 20:20:47 bluhm Exp $ */
+/* $OpenBSD: pf_norm.c,v 1.219 2020/06/24 22:03:43 cheloha Exp $ */
/*
* Copyright 2001 Niels Provos <provos@citi.umich.edu>
@@ -220,7 +220,7 @@ pf_purge_expired_fragments(void)
PF_ASSERT_UNLOCKED();
- expire = time_uptime - pf_default_rule.timeout[PFTM_FRAG];
+ expire = getuptime() - pf_default_rule.timeout[PFTM_FRAG];
PF_FRAG_LOCK();
while ((frag = TAILQ_LAST(&pf_fragqueue, pf_fragqueue)) != NULL) {
@@ -589,7 +589,7 @@ pf_fillup_fragment(struct pf_frnode *key, u_int32_t id,
memset(frag->fr_entries, 0, sizeof(frag->fr_entries));
TAILQ_INIT(&frag->fr_queue);
frag->fr_id = id;
- frag->fr_timeout = time_uptime;
+ frag->fr_timeout = getuptime();
frag->fr_gen = frnode->fn_gen++;
frag->fr_maxlen = frent->fe_len;
frag->fr_holes = 1;
@@ -1352,7 +1352,7 @@ pf_normalize_tcp_stateful(struct pf_pdesc *pd, u_short *reason,
getmicrouptime(&uptime);
if (src->scrub && (src->scrub->pfss_flags & PFSS_PAWS) &&
(uptime.tv_sec - src->scrub->pfss_last.tv_sec > TS_MAX_IDLE ||
- time_uptime - state->creation > TS_MAX_CONN)) {
+ getuptime() - state->creation > TS_MAX_CONN)) {
if (pf_status.debug >= LOG_NOTICE) {
log(LOG_NOTICE, "pf: src idled out of PAWS ");
pf_print_state(state);
diff --git a/sys/net/pf_table.c b/sys/net/pf_table.c
index 487207dcd0e..07ec189a12f 100644
--- a/sys/net/pf_table.c
+++ b/sys/net/pf_table.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pf_table.c,v 1.132 2020/06/04 04:27:51 yasuoka Exp $ */
+/* $OpenBSD: pf_table.c,v 1.133 2020/06/24 22:03:43 cheloha Exp $ */
/*
* Copyright (c) 2002 Cedric Berger
@@ -271,7 +271,7 @@ pfr_add_addrs(struct pfr_table *tbl, struct pfr_addr *addr, int size,
struct pfr_kentry *p, *q;
struct pfr_addr ad;
int i, rv, xadd = 0;
- time_t tzero = time_second;
+ time_t tzero = gettime();
ACCEPT_FLAGS(flags, PFR_FLAG_DUMMY | PFR_FLAG_FEEDBACK);
if (pfr_validate_table(tbl, 0, flags & PFR_FLAG_USERIOCTL))
@@ -438,7 +438,7 @@ pfr_set_addrs(struct pfr_table *tbl, struct pfr_addr *addr, int size,
struct pfr_kentry *p, *q;
struct pfr_addr ad;
int i, rv, xadd = 0, xdel = 0, xchange = 0;
- time_t tzero = time_second;
+ time_t tzero = gettime();
ACCEPT_FLAGS(flags, PFR_FLAG_DUMMY | PFR_FLAG_FEEDBACK);
if (pfr_validate_table(tbl, ignore_pfrt_flags, flags &
@@ -630,7 +630,7 @@ pfr_get_astats(struct pfr_table *tbl, struct pfr_astats *addr, int *size,
struct pfr_walktree w;
struct pfr_kentryworkq workq;
int rv;
- time_t tzero = time_second;
+ time_t tzero = gettime();
if (pfr_validate_table(tbl, 0, 0))
return (EINVAL);
@@ -703,7 +703,7 @@ pfr_clr_astats(struct pfr_table *tbl, struct pfr_addr *addr, int size,
}
if (!(flags & PFR_FLAG_DUMMY)) {
- pfr_clstats_kentries(&workq, time_second, 0);
+ pfr_clstats_kentries(&workq, gettime(), 0);
}
if (nzero != NULL)
*nzero = xzero;
@@ -1285,7 +1285,7 @@ pfr_add_tables(struct pfr_table *tbl, int size, int *nadd, int flags)
struct pfr_ktableworkq addq, changeq;
struct pfr_ktable *p, *q, *r, key;
int i, rv, xadd = 0;
- time_t tzero = time_second;
+ time_t tzero = gettime();
ACCEPT_FLAGS(flags, PFR_FLAG_DUMMY);
SLIST_INIT(&addq);
@@ -1438,7 +1438,7 @@ pfr_get_tstats(struct pfr_table *filter, struct pfr_tstats *tbl, int *size,
struct pfr_ktable *p;
struct pfr_ktableworkq workq;
int n, nn;
- time_t tzero = time_second;
+ time_t tzero = gettime();
/* XXX PFR_FLAG_CLSTATS disabled */
ACCEPT_FLAGS(flags, PFR_FLAG_ALLRSETS);
@@ -1479,7 +1479,7 @@ pfr_clr_tstats(struct pfr_table *tbl, int size, int *nzero, int flags)
struct pfr_ktableworkq workq;
struct pfr_ktable *p, key;
int i, xzero = 0;
- time_t tzero = time_second;
+ time_t tzero = gettime();
ACCEPT_FLAGS(flags, PFR_FLAG_DUMMY | PFR_FLAG_ADDRSTOO);
SLIST_INIT(&workq);
@@ -1732,7 +1732,7 @@ pfr_ina_commit(struct pfr_table *trs, u_int32_t ticket, int *nadd,
struct pfr_ktableworkq workq;
struct pf_ruleset *rs;
int xadd = 0, xchange = 0;
- time_t tzero = time_second;
+ time_t tzero = gettime();
ACCEPT_FLAGS(flags, PFR_FLAG_DUMMY);
rs = pf_find_ruleset(trs->pfrt_anchor);
@@ -2226,7 +2226,7 @@ pfr_attach_table(struct pf_ruleset *rs, char *name, int intr)
strlcpy(tbl.pfrt_anchor, ac->path, sizeof(tbl.pfrt_anchor));
kt = pfr_lookup_table(&tbl);
if (kt == NULL) {
- kt = pfr_create_ktable(&tbl, time_second, 1, intr);
+ kt = pfr_create_ktable(&tbl, gettime(), 1, intr);
if (kt == NULL)
return (NULL);
if (ac != NULL) {
diff --git a/sys/net/route.c b/sys/net/route.c
index 083f5f3a594..90ccb1ae477 100644
--- a/sys/net/route.c
+++ b/sys/net/route.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: route.c,v 1.393 2020/04/20 17:25:23 krw Exp $ */
+/* $OpenBSD: route.c,v 1.394 2020/06/24 22:03:43 cheloha Exp $ */
/* $NetBSD: route.c,v 1.14 1996/02/13 22:00:46 christos Exp $ */
/*
@@ -1469,8 +1469,8 @@ rt_timer_add(struct rtentry *rt, void (*func)(struct rtentry *,
struct rttimer *r;
long current_time;
- current_time = time_uptime;
- rt->rt_expire = time_uptime + queue->rtq_timeout;
+ current_time = getuptime();
+ rt->rt_expire = getuptime() + queue->rtq_timeout;
/*
* If there's already a timer with this action, destroy it before
@@ -1513,7 +1513,7 @@ rt_timer_timer(void *arg)
struct rttimer *r;
long current_time;
- current_time = time_uptime;
+ current_time = getuptime();
NET_LOCK();
LIST_FOREACH(rtq, &rttimer_queue_head, rtq_link) {
diff --git a/sys/net/rtsock.c b/sys/net/rtsock.c
index e00e94997e7..9d4ccadd4e2 100644
--- a/sys/net/rtsock.c
+++ b/sys/net/rtsock.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rtsock.c,v 1.298 2020/03/24 13:50:18 tobhe Exp $ */
+/* $OpenBSD: rtsock.c,v 1.299 2020/06/24 22:03:42 cheloha Exp $ */
/* $NetBSD: rtsock.c,v 1.18 1996/03/29 00:32:10 cgd Exp $ */
/*
@@ -1325,8 +1325,8 @@ rtm_setmetrics(u_long which, const struct rt_metrics *in,
if (which & RTV_EXPIRE) {
expire = in->rmx_expire;
if (expire != 0) {
- expire -= time_second;
- expire += time_uptime;
+ expire -= gettime();
+ expire += getuptime();
}
out->rmx_expire = expire;
@@ -1340,8 +1340,8 @@ rtm_getmetrics(const struct rt_kmetrics *in, struct rt_metrics *out)
expire = in->rmx_expire;
if (expire != 0) {
- expire -= time_uptime;
- expire += time_second;
+ expire -= getuptime();
+ expire += gettime();
}
bzero(out, sizeof(*out));