summaryrefslogtreecommitdiffstats
path: root/sys/net/if_wg.c
diff options
context:
space:
mode:
authorMatt Dunwoodie <ncon@noconroy.net>2021-04-04 22:55:44 +1000
committerMatt Dunwoodie <ncon@noconroy.net>2021-04-13 15:47:31 +1000
commit95bae487f1f4bae3ae1773b5a00015188be1ba2a (patch)
treed13799edc9bb2724672c8b72aa04b58d6baafc30 /sys/net/if_wg.c
parentReplace timer lock with SMR (diff)
downloadwireguard-openbsd-95bae487f1f4bae3ae1773b5a00015188be1ba2a.tar.xz
wireguard-openbsd-95bae487f1f4bae3ae1773b5a00015188be1ba2a.zip
Merge wg_timers and wg_peer
The primary motivator here is to get rid of CONTAINER_OF, which is quite an ugly macro. However, any reader should also be aware of the change from d_DISabled to p_ENabled.
Diffstat (limited to '')
-rw-r--r--sys/net/if_wg.c335
1 files changed, 155 insertions, 180 deletions
diff --git a/sys/net/if_wg.c b/sys/net/if_wg.c
index ae29bf4d49c..b1dd3dd7c19 100644
--- a/sys/net/if_wg.c
+++ b/sys/net/if_wg.c
@@ -67,10 +67,6 @@
#define DPRINTF(sc, str, ...) do { if (ISSET((sc)->sc_if.if_flags, IFF_DEBUG))\
printf("%s: " str, (sc)->sc_if.if_xname, ##__VA_ARGS__); } while (0)
-#define CONTAINER_OF(ptr, type, member) ({ \
- const __typeof( ((type *)0)->member ) *__mptr = (ptr); \
- (type *)( (char *)__mptr - offsetof(type,member) );})
-
/* First byte indicating packet type on the wire */
#define WG_PKT_INITIATION htole32(1)
#define WG_PKT_RESPONSE htole32(2)
@@ -129,21 +125,6 @@ struct wg_endpoint {
} e_local;
};
-struct wg_timers {
- int t_disabled;
- int t_need_another_keepalive;
- uint16_t t_persistent_keepalive_interval;
- struct timeout t_new_handshake;
- struct timeout t_send_keepalive;
- struct timeout t_retry_handshake;
- struct timeout t_zero_key_material;
- struct timeout t_persistent_keepalive;
-
- struct mutex t_handshake_mtx;
- struct timespec t_handshake_complete; /* nanotime */
- int t_handshake_retries;
-};
-
struct wg_aip {
struct art_node a_node;
LIST_ENTRY(wg_aip) a_entry;
@@ -184,7 +165,6 @@ struct wg_peer {
struct noise_remote *p_remote;
struct cookie_maker p_cookie;
- struct wg_timers p_timers;
struct mutex p_counters_mtx;
uint64_t p_counters_tx;
@@ -200,6 +180,19 @@ struct wg_peer {
struct wg_queue p_encap_serial;
struct wg_queue p_decap_serial;
+ int p_enabled;
+ int p_need_another_keepalive;
+ uint16_t p_persistent_keepalive_interval;
+ struct timeout p_new_handshake;
+ struct timeout p_send_keepalive;
+ struct timeout p_retry_handshake;
+ struct timeout p_zero_key_material;
+ struct timeout p_persistent_keepalive;
+
+ struct mutex p_handshake_mtx;
+ struct timespec p_handshake_complete; /* nanotime */
+ int p_handshake_retries;
+
LIST_HEAD(,wg_aip) p_aip;
SLIST_ENTRY(wg_peer) p_start_list;
@@ -266,27 +259,24 @@ void wg_send_buf(struct wg_softc *, struct wg_endpoint *, uint8_t *,
struct wg_tag *
wg_tag_get(struct mbuf *);
-void wg_timers_init(struct wg_timers *);
-void wg_timers_enable(struct wg_timers *);
-void wg_timers_disable(struct wg_timers *);
-void wg_timers_set_persistent_keepalive(struct wg_timers *, uint16_t);
-int wg_timers_get_persistent_keepalive(struct wg_timers *, uint16_t *);
-void wg_timers_get_last_handshake(struct wg_timers *, struct timespec *);
-int wg_timers_expired_handshake_last_sent(struct wg_timers *);
-int wg_timers_check_handshake_last_sent(struct wg_timers *);
-
-void wg_timers_event_data_sent(struct wg_timers *);
-void wg_timers_event_data_received(struct wg_timers *);
-void wg_timers_event_any_authenticated_packet_sent(struct wg_timers *);
-void wg_timers_event_any_authenticated_packet_received(struct wg_timers *);
-void wg_timers_event_any_authenticated_packet_traversal(struct wg_timers *);
-void wg_timers_event_handshake_initiated(struct wg_timers *);
-void wg_timers_event_handshake_responded(struct wg_timers *);
-void wg_timers_event_handshake_complete(struct wg_timers *);
-void wg_timers_event_session_derived(struct wg_timers *);
-void wg_timers_event_want_initiation(struct wg_timers *);
-
-void wg_timers_run_send_initiation(void *, int);
+void wg_timers_enable(struct wg_peer *);
+void wg_timers_disable(struct wg_peer *);
+void wg_timers_set_persistent_keepalive(struct wg_peer *, uint16_t);
+int wg_timers_get_persistent_keepalive(struct wg_peer *, uint16_t *);
+void wg_timers_get_last_handshake(struct wg_peer *, struct timespec *);
+
+void wg_timers_event_data_sent(struct wg_peer *);
+void wg_timers_event_data_received(struct wg_peer *);
+void wg_timers_event_any_authenticated_packet_sent(struct wg_peer *);
+void wg_timers_event_any_authenticated_packet_received(struct wg_peer *);
+void wg_timers_event_any_authenticated_packet_traversal(struct wg_peer *);
+void wg_timers_event_handshake_initiated(struct wg_peer *);
+void wg_timers_event_handshake_responded(struct wg_peer *);
+void wg_timers_event_handshake_complete(struct wg_peer *);
+void wg_timers_event_session_derived(struct wg_peer *);
+void wg_timers_event_want_initiation(struct wg_peer *);
+
+void wg_timers_run_send_initiation(struct wg_peer *, int);
void wg_timers_run_retry_handshake(void *);
void wg_timers_run_send_keepalive(void *);
void wg_timers_run_new_handshake(void *);
@@ -361,7 +351,6 @@ wg_peer_create(struct wg_softc *sc, uint8_t public[WG_KEY_SIZE],
peer->p_sc = sc;
cookie_maker_init(&peer->p_cookie, public);
- wg_timers_init(&peer->p_timers);
mtx_init(&peer->p_counters_mtx, IPL_NET);
peer->p_counters_tx = 0;
@@ -377,6 +366,24 @@ wg_peer_create(struct wg_softc *sc, uint8_t public[WG_KEY_SIZE],
wg_queue_init(&peer->p_encap_serial);
wg_queue_init(&peer->p_decap_serial);
+ peer->p_enabled = ISSET(sc->sc_if.if_flags, IFF_RUNNING);
+ peer->p_need_another_keepalive = 0;
+ peer->p_persistent_keepalive_interval = 0;
+ timeout_set_flags(&peer->p_new_handshake,
+ wg_timers_run_new_handshake, peer, TIMEOUT_PROC);
+ timeout_set_flags(&peer->p_send_keepalive,
+ wg_timers_run_send_keepalive, peer, TIMEOUT_PROC);
+ timeout_set_flags(&peer->p_retry_handshake,
+ wg_timers_run_retry_handshake, peer, TIMEOUT_PROC);
+ timeout_set_flags(&peer->p_persistent_keepalive,
+ wg_timers_run_persistent_keepalive, peer, TIMEOUT_PROC);
+ timeout_set_flags(&peer->p_zero_key_material,
+ wg_timers_run_zero_key_material, peer, TIMEOUT_PROC);
+
+ mtx_init(&peer->p_handshake_mtx, IPL_NET);
+ bzero(&peer->p_handshake_complete, sizeof(peer->p_handshake_complete));
+ peer->p_handshake_retries = 0;
+
LIST_INIT(&peer->p_aip);
peer->p_start_onlist = 0;
@@ -415,7 +422,7 @@ wg_peer_destroy(struct wg_peer *peer)
LIST_FOREACH_SAFE(aip, &peer->p_aip, a_entry, taip)
wg_aip_remove(sc, peer, &aip->a_data);
- wg_timers_disable(&peer->p_timers);
+ wg_timers_disable(peer);
noise_remote_free(peer->p_remote, wg_peer_free);
DPRINTF(sc, "Peer %llu destroyed\n", peer->p_id);
@@ -810,239 +817,215 @@ wg_tag_get(struct mbuf *m)
* tx: data failed, old keys expiring
*/
void
-wg_timers_init(struct wg_timers *t)
-{
- bzero(t, sizeof(*t));
- mtx_init(&t->t_handshake_mtx, IPL_NET);
-
- timeout_set_flags(&t->t_new_handshake,
- wg_timers_run_new_handshake, t, TIMEOUT_PROC);
- timeout_set_flags(&t->t_send_keepalive,
- wg_timers_run_send_keepalive, t, TIMEOUT_PROC);
- timeout_set_flags(&t->t_retry_handshake,
- wg_timers_run_retry_handshake, t, TIMEOUT_PROC);
- timeout_set_flags(&t->t_persistent_keepalive,
- wg_timers_run_persistent_keepalive, t, TIMEOUT_PROC);
- timeout_set_flags(&t->t_zero_key_material,
- wg_timers_run_zero_key_material, t, TIMEOUT_PROC);
-}
-
-void
-wg_timers_enable(struct wg_timers *t)
+wg_timers_enable(struct wg_peer *peer)
{
- WRITE_ONCE(t->t_disabled, 0);
- wg_timers_run_persistent_keepalive(t);
+ WRITE_ONCE(peer->p_enabled, 1);
+ wg_timers_run_persistent_keepalive(peer);
}
void
-wg_timers_disable(struct wg_timers *t)
+wg_timers_disable(struct wg_peer *peer)
{
- WRITE_ONCE(t->t_disabled, 1);
+ WRITE_ONCE(peer->p_enabled, 0);
smr_barrier();
- WRITE_ONCE(t->t_need_another_keepalive, 0);
+ WRITE_ONCE(peer->p_need_another_keepalive, 0);
- timeout_del_barrier(&t->t_new_handshake);
- timeout_del_barrier(&t->t_send_keepalive);
- timeout_del_barrier(&t->t_retry_handshake);
- timeout_del_barrier(&t->t_persistent_keepalive);
- timeout_del_barrier(&t->t_zero_key_material);
+ timeout_del_barrier(&peer->p_new_handshake);
+ timeout_del_barrier(&peer->p_send_keepalive);
+ timeout_del_barrier(&peer->p_retry_handshake);
+ timeout_del_barrier(&peer->p_persistent_keepalive);
+ timeout_del_barrier(&peer->p_zero_key_material);
}
void
-wg_timers_set_persistent_keepalive(struct wg_timers *t, uint16_t interval)
+wg_timers_set_persistent_keepalive(struct wg_peer *peer, uint16_t interval)
{
- if (interval != t->t_persistent_keepalive_interval) {
- WRITE_ONCE(t->t_persistent_keepalive_interval, interval);
+ if (interval != peer->p_persistent_keepalive_interval) {
+ WRITE_ONCE(peer->p_persistent_keepalive_interval, interval);
smr_read_enter();
- if (!t->t_disabled)
- wg_timers_run_persistent_keepalive(t);
+ if (peer->p_enabled)
+ wg_timers_run_persistent_keepalive(peer);
smr_read_leave();
}
}
int
-wg_timers_get_persistent_keepalive(struct wg_timers *t, uint16_t *interval)
+wg_timers_get_persistent_keepalive(struct wg_peer *peer, uint16_t *interval)
{
- *interval = t->t_persistent_keepalive_interval;
+ *interval = peer->p_persistent_keepalive_interval;
return *interval > 0 ? 0 : ENOENT;
}
void
-wg_timers_get_last_handshake(struct wg_timers *t, struct timespec *time)
+wg_timers_get_last_handshake(struct wg_peer *peer, struct timespec *time)
{
- mtx_enter(&t->t_handshake_mtx);
- *time = t->t_handshake_complete;
- mtx_leave(&t->t_handshake_mtx);
+ mtx_enter(&peer->p_handshake_mtx);
+ *time = peer->p_handshake_complete;
+ mtx_leave(&peer->p_handshake_mtx);
}
void
-wg_timers_event_data_sent(struct wg_timers *t)
+wg_timers_event_data_sent(struct wg_peer *peer)
{
int msecs = NEW_HANDSHAKE_TIMEOUT * 1000;
msecs += arc4random_uniform(REKEY_TIMEOUT_JITTER);
smr_read_enter();
- if (!t->t_disabled && !timeout_pending(&t->t_new_handshake))
- timeout_add_msec(&t->t_new_handshake, msecs);
+ if (peer->p_enabled && !timeout_pending(&peer->p_new_handshake))
+ timeout_add_msec(&peer->p_new_handshake, msecs);
smr_read_leave();
}
void
-wg_timers_event_data_received(struct wg_timers *t)
+wg_timers_event_data_received(struct wg_peer *peer)
{
smr_read_enter();
- if (!t->t_disabled) {
- if (!timeout_pending(&t->t_send_keepalive))
- timeout_add_sec(&t->t_send_keepalive,
+ if (peer->p_enabled) {
+ if (!timeout_pending(&peer->p_send_keepalive))
+ timeout_add_sec(&peer->p_send_keepalive,
KEEPALIVE_TIMEOUT);
else
- WRITE_ONCE(t->t_need_another_keepalive, 1);
+ WRITE_ONCE(peer->p_need_another_keepalive, 1);
}
smr_read_leave();
}
void
-wg_timers_event_any_authenticated_packet_sent(struct wg_timers *t)
+wg_timers_event_any_authenticated_packet_sent(struct wg_peer *peer)
{
- timeout_del(&t->t_send_keepalive);
+ timeout_del(&peer->p_send_keepalive);
}
void
-wg_timers_event_any_authenticated_packet_received(struct wg_timers *t)
+wg_timers_event_any_authenticated_packet_received(struct wg_peer *peer)
{
- timeout_del(&t->t_new_handshake);
+ timeout_del(&peer->p_new_handshake);
}
void
-wg_timers_event_any_authenticated_packet_traversal(struct wg_timers *t)
+wg_timers_event_any_authenticated_packet_traversal(struct wg_peer *peer)
{
uint16_t interval;
smr_read_enter();
- interval = READ_ONCE(t->t_persistent_keepalive_interval);
- if (!t->t_disabled && interval > 0)
- timeout_add_sec(&t->t_persistent_keepalive, interval);
+ interval = READ_ONCE(peer->p_persistent_keepalive_interval);
+ if (peer->p_enabled && interval > 0)
+ timeout_add_sec(&peer->p_persistent_keepalive, interval);
smr_read_leave();
}
void
-wg_timers_event_handshake_initiated(struct wg_timers *t)
+wg_timers_event_handshake_initiated(struct wg_peer *peer)
{
int msecs = REKEY_TIMEOUT * 1000;
msecs += arc4random_uniform(REKEY_TIMEOUT_JITTER);
smr_read_enter();
- if (!t->t_disabled)
- timeout_add_msec(&t->t_retry_handshake, msecs);
+ if (peer->p_enabled)
+ timeout_add_msec(&peer->p_retry_handshake, msecs);
smr_read_leave();
}
void
-wg_timers_event_handshake_complete(struct wg_timers *t)
+wg_timers_event_handshake_complete(struct wg_peer *peer)
{
smr_read_enter();
- if (!t->t_disabled) {
- mtx_enter(&t->t_handshake_mtx);
- timeout_del(&t->t_retry_handshake);
- t->t_handshake_retries = 0;
- getnanotime(&t->t_handshake_complete);
- mtx_leave(&t->t_handshake_mtx);
- wg_timers_run_send_keepalive(t);
+ if (peer->p_enabled) {
+ mtx_enter(&peer->p_handshake_mtx);
+ timeout_del(&peer->p_retry_handshake);
+ peer->p_handshake_retries = 0;
+ getnanotime(&peer->p_handshake_complete);
+ mtx_leave(&peer->p_handshake_mtx);
+ wg_timers_run_send_keepalive(peer);
}
smr_read_leave();
}
void
-wg_timers_event_session_derived(struct wg_timers *t)
+wg_timers_event_session_derived(struct wg_peer *peer)
{
smr_read_enter();
- if (!t->t_disabled)
- timeout_add_sec(&t->t_zero_key_material, REJECT_AFTER_TIME * 3);
+ if (peer->p_enabled)
+ timeout_add_sec(&peer->p_zero_key_material, REJECT_AFTER_TIME * 3);
smr_read_leave();
}
void
-wg_timers_event_want_initiation(struct wg_timers *t)
+wg_timers_event_want_initiation(struct wg_peer *peer)
{
smr_read_enter();
- if (!t->t_disabled)
- wg_timers_run_send_initiation(t, 0);
+ if (peer->p_enabled)
+ wg_timers_run_send_initiation(peer, 0);
smr_read_leave();
}
void
-wg_timers_run_send_initiation(void *_t, int is_retry)
+wg_timers_run_send_initiation(struct wg_peer *peer, int is_retry)
{
- struct wg_timers *t = _t;
- struct wg_peer *peer = CONTAINER_OF(t, struct wg_peer, p_timers);
if (!is_retry)
- t->t_handshake_retries = 0;
+ peer->p_handshake_retries = 0;
if (noise_remote_initiation_expired(peer->p_remote) == ETIMEDOUT)
wg_send_initiation(peer);
}
void
-wg_timers_run_retry_handshake(void *_t)
+wg_timers_run_retry_handshake(void *_peer)
{
- struct wg_timers *t = _t;
- struct wg_peer *peer = CONTAINER_OF(t, struct wg_peer, p_timers);
+ struct wg_peer *peer = _peer;
- mtx_enter(&t->t_handshake_mtx);
- if (t->t_handshake_retries <= MAX_TIMER_HANDSHAKES) {
- t->t_handshake_retries++;
- mtx_leave(&t->t_handshake_mtx);
+ mtx_enter(&peer->p_handshake_mtx);
+ if (peer->p_handshake_retries <= MAX_TIMER_HANDSHAKES) {
+ peer->p_handshake_retries++;
+ mtx_leave(&peer->p_handshake_mtx);
DPRINTF(peer->p_sc, "Handshake for peer %llu did not complete "
"after %d seconds, retrying (try %d)\n", peer->p_id,
- REKEY_TIMEOUT, t->t_handshake_retries + 1);
+ REKEY_TIMEOUT, peer->p_handshake_retries + 1);
wg_peer_clear_src(peer);
- wg_timers_run_send_initiation(t, 1);
+ wg_timers_run_send_initiation(peer, 1);
} else {
- mtx_leave(&t->t_handshake_mtx);
+ mtx_leave(&peer->p_handshake_mtx);
DPRINTF(peer->p_sc, "Handshake for peer %llu did not complete "
"after %d retries, giving up\n", peer->p_id,
MAX_TIMER_HANDSHAKES + 2);
- timeout_del(&t->t_send_keepalive);
+ timeout_del(&peer->p_send_keepalive);
mq_purge(&peer->p_stage_queue);
- if (!timeout_pending(&t->t_zero_key_material))
- timeout_add_sec(&t->t_zero_key_material,
+ if (!timeout_pending(&peer->p_zero_key_material))
+ timeout_add_sec(&peer->p_zero_key_material,
REJECT_AFTER_TIME * 3);
}
}
void
-wg_timers_run_send_keepalive(void *_t)
+wg_timers_run_send_keepalive(void *_peer)
{
- struct wg_timers *t = _t;
- struct wg_peer *peer = CONTAINER_OF(t, struct wg_peer, p_timers);
+ struct wg_peer *peer = _peer;
wg_send_keepalive(peer);
- if (READ_ONCE(t->t_need_another_keepalive)) {
- WRITE_ONCE(t->t_need_another_keepalive, 0);
- timeout_add_sec(&t->t_send_keepalive, KEEPALIVE_TIMEOUT);
+ if (READ_ONCE(peer->p_need_another_keepalive)) {
+ WRITE_ONCE(peer->p_need_another_keepalive, 0);
+ timeout_add_sec(&peer->p_send_keepalive, KEEPALIVE_TIMEOUT);
}
}
void
-wg_timers_run_new_handshake(void *_t)
+wg_timers_run_new_handshake(void *_peer)
{
- struct wg_timers *t = _t;
- struct wg_peer *peer = CONTAINER_OF(t, struct wg_peer, p_timers);
+ struct wg_peer *peer = _peer;
DPRINTF(peer->p_sc, "Retrying handshake with peer %llu because we "
"stopped hearing back after %d seconds\n",
peer->p_id, NEW_HANDSHAKE_TIMEOUT);
wg_peer_clear_src(peer);
- wg_timers_run_send_initiation(t, 0);
+ wg_timers_run_send_initiation(peer, 0);
}
void
-wg_timers_run_zero_key_material(void *_t)
+wg_timers_run_zero_key_material(void *_peer)
{
- struct wg_timers *t = _t;
- struct wg_peer *peer = CONTAINER_OF(t, struct wg_peer, p_timers);
+ struct wg_peer *peer = _peer;
DPRINTF(peer->p_sc, "Zeroing out keys for peer %llu, since we "
"haven't received a new one in %d seconds\n",
@@ -1051,12 +1034,11 @@ wg_timers_run_zero_key_material(void *_t)
}
void
-wg_timers_run_persistent_keepalive(void *_t)
+wg_timers_run_persistent_keepalive(void *_peer)
{
- struct wg_timers *t = _t;
- struct wg_peer *peer = CONTAINER_OF(t, struct wg_peer, p_timers);
+ struct wg_peer *peer = _peer;
- if (READ_ONCE(t->t_persistent_keepalive_interval) > 0)
+ if (READ_ONCE(peer->p_persistent_keepalive_interval) > 0)
wg_send_keepalive(peer);
}
@@ -1067,8 +1049,8 @@ wg_peer_send_buf(struct wg_peer *peer, uint8_t *buf, size_t len)
struct wg_endpoint endpoint;
wg_peer_counters_add(peer, len, 0);
- wg_timers_event_any_authenticated_packet_traversal(&peer->p_timers);
- wg_timers_event_any_authenticated_packet_sent(&peer->p_timers);
+ wg_timers_event_any_authenticated_packet_traversal(peer);
+ wg_timers_event_any_authenticated_packet_sent(peer);
wg_peer_get_endpoint(peer, &endpoint);
wg_send_buf(peer->p_sc, &endpoint, buf, len);
}
@@ -1089,7 +1071,7 @@ wg_send_initiation(struct wg_peer *peer)
cookie_maker_mac(&peer->p_cookie, &pkt.m, &pkt,
sizeof(pkt)-sizeof(pkt.m));
wg_peer_send_buf(peer, (uint8_t *)&pkt, sizeof(pkt));
- wg_timers_event_handshake_initiated(&peer->p_timers);
+ wg_timers_event_handshake_initiated(peer);
}
void
@@ -1103,7 +1085,7 @@ wg_send_response(struct wg_peer *peer)
if (noise_create_response(peer->p_remote, &pkt.s_idx, &pkt.r_idx,
pkt.ue, pkt.en) != 0)
return;
- wg_timers_event_session_derived(&peer->p_timers);
+ wg_timers_event_session_derived(peer);
pkt.t = WG_PKT_RESPONSE;
cookie_maker_mac(&peer->p_cookie, &pkt.m, &pkt,
sizeof(pkt)-sizeof(pkt.m));
@@ -1254,8 +1236,8 @@ wg_handshake(struct wg_softc *sc, struct wg_packet *pkt)
DPRINTF(sc, "Receiving handshake response from peer %llu\n", peer->p_id);
wg_peer_set_endpoint(peer, e);
- wg_timers_event_session_derived(&peer->p_timers);
- wg_timers_event_handshake_complete(&peer->p_timers);
+ wg_timers_event_session_derived(peer);
+ wg_timers_event_handshake_complete(peer);
break;
case WG_PKT_COOKIE:
cook = mtod(m, struct wg_pkt_cookie *);
@@ -1282,8 +1264,8 @@ wg_handshake(struct wg_softc *sc, struct wg_packet *pkt)
panic("invalid packet in handshake queue");
}
- wg_timers_event_any_authenticated_packet_received(&peer->p_timers);
- wg_timers_event_any_authenticated_packet_traversal(&peer->p_timers);
+ wg_timers_event_any_authenticated_packet_received(peer);
+ wg_timers_event_any_authenticated_packet_traversal(peer);
wg_peer_counters_add(peer, 0, m->m_pkthdr.len);
error:
if (remote != NULL)
@@ -1423,7 +1405,7 @@ wg_decap(struct wg_softc *sc, struct wg_packet *pkt)
if (__predict_false(res == EINVAL)) {
goto error_free;
} else if (__predict_false(res == ECONNRESET)) {
- wg_timers_event_handshake_complete(&peer->p_timers);
+ wg_timers_event_handshake_complete(peer);
} else if (__predict_false(res != 0)) {
panic("unexpected response: %d\n", res);
}
@@ -1548,13 +1530,11 @@ wg_deliver_out(void *_peer)
ret = wg_send(sc, &endpoint, m);
if (ret == 0) {
- wg_timers_event_any_authenticated_packet_traversal(
- &peer->p_timers);
- wg_timers_event_any_authenticated_packet_sent(
- &peer->p_timers);
+ wg_timers_event_any_authenticated_packet_traversal(peer);
+ wg_timers_event_any_authenticated_packet_sent(peer);
if (data)
- wg_timers_event_data_sent(&peer->p_timers);
+ wg_timers_event_data_sent(peer);
} else if (ret == EADDRNOTAVAIL) {
wg_peer_clear_src(peer);
wg_peer_get_endpoint(peer, &endpoint);
@@ -1568,7 +1548,7 @@ wg_deliver_out(void *_peer)
pool_put(&wg_packet_pool, pkt);
}
if (noise_keep_key_fresh_send(peer->p_remote))
- wg_timers_event_want_initiation(&peer->p_timers);
+ wg_timers_event_want_initiation(peer);
}
void
@@ -1587,10 +1567,8 @@ wg_deliver_in(void *_peer)
goto put;
}
- wg_timers_event_any_authenticated_packet_received(
- &peer->p_timers);
- wg_timers_event_any_authenticated_packet_traversal(
- &peer->p_timers);
+ wg_timers_event_any_authenticated_packet_received(peer);
+ wg_timers_event_any_authenticated_packet_traversal(peer);
wg_peer_set_endpoint(peer, &pkt->p_endpoint);
if (m->m_pkthdr.len == 0) {
@@ -1615,7 +1593,7 @@ wg_deliver_in(void *_peer)
panic("invalid ph_family");
NET_UNLOCK();
- wg_timers_event_data_received(&peer->p_timers);
+ wg_timers_event_data_received(peer);
} else {
m_freem(m);
}
@@ -1624,7 +1602,7 @@ put:
pool_put(&wg_packet_pool, pkt);
}
if (noise_keep_key_fresh_recv(peer->p_remote))
- wg_timers_event_want_initiation(&peer->p_timers);
+ wg_timers_event_want_initiation(peer);
}
void
@@ -1684,7 +1662,7 @@ wg_queue_out(struct wg_softc *sc, struct wg_peer *peer)
struct mbuf *m;
if ((keypair = noise_keypair_current(peer->p_remote)) == NULL) {
- wg_timers_event_want_initiation(&peer->p_timers);
+ wg_timers_event_want_initiation(peer);
return;
}
@@ -2088,8 +2066,7 @@ wg_ioctl_set(struct wg_softc *sc, struct wg_data_io *data)
noise_remote_set_psk(peer->p_remote, peer_o.p_psk);
if (peer_o.p_flags & WG_PEER_HAS_PKA)
- wg_timers_set_persistent_keepalive(&peer->p_timers,
- peer_o.p_pka);
+ wg_timers_set_persistent_keepalive(peer, peer_o.p_pka);
if (peer_o.p_flags & WG_PEER_REPLACE_AIPS) {
LIST_FOREACH_SAFE(aip, &peer->p_aip, a_entry, taip) {
@@ -2182,8 +2159,7 @@ wg_ioctl_get(struct wg_softc *sc, struct wg_data_io *data)
peer_o.p_psk) == 0)
peer_o.p_flags |= WG_PEER_HAS_PSK;
- if (wg_timers_get_persistent_keepalive(&peer->p_timers,
- &peer_o.p_pka) == 0)
+ if (wg_timers_get_persistent_keepalive(peer, &peer_o.p_pka) == 0)
peer_o.p_flags |= WG_PEER_HAS_PKA;
if (wg_peer_get_sockaddr(peer, &peer_o.p_sa) == 0)
@@ -2194,8 +2170,7 @@ wg_ioctl_get(struct wg_softc *sc, struct wg_data_io *data)
peer_o.p_rxbytes = peer->p_counters_rx;
mtx_leave(&peer->p_counters_mtx);
- wg_timers_get_last_handshake(&peer->p_timers,
- &peer_o.p_last_handshake);
+ wg_timers_get_last_handshake(peer, &peer_o.p_last_handshake);
aip_count = 0;
aip_p = &peer_p->p_aips[0];
@@ -2297,7 +2272,7 @@ wg_up(struct wg_softc *sc)
ret = wg_bind(sc, &sc->sc_udp_port, &sc->sc_udp_rtable);
if (ret == 0) {
TAILQ_FOREACH(peer, &sc->sc_peers, p_entry)
- wg_timers_enable(&peer->p_timers);
+ wg_timers_enable(peer);
}
rw_exit_write(&sc->sc_lock);
@@ -2326,7 +2301,7 @@ wg_down(struct wg_softc *sc)
rw_enter_read(&sc->sc_lock);
TAILQ_FOREACH(peer, &sc->sc_peers, p_entry) {
mq_purge(&peer->p_stage_queue);
- wg_timers_disable(&peer->p_timers);
+ wg_timers_disable(peer);
}
taskq_barrier(wg_handshake_taskq);