Avoid callout_halt under lock.

- We could pass the lock in, except we hold another lock too.

- We could halt before taking the other lock, but it's not safe to
  sleep after getting the session pointer before taking its lock.

- We could halt before getting the session pointer, but then there's
  no point in doing it under the lock.

So just halt a little earlier instead.
This commit is contained in:
riastradh 2020-08-20 21:35:44 +00:00
parent 383259a8b8
commit 7b6ff34c76
1 changed files with 4 additions and 3 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: if_wg.c,v 1.17 2020/08/20 21:35:33 riastradh Exp $ */
/* $NetBSD: if_wg.c,v 1.18 2020/08/20 21:35:44 riastradh Exp $ */
/*
* Copyright (C) Ryota Ozaki <ozaki.ryota@gmail.com>
@ -43,7 +43,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: if_wg.c,v 1.17 2020/08/20 21:35:33 riastradh Exp $");
__KERNEL_RCSID(0, "$NetBSD: if_wg.c,v 1.18 2020/08/20 21:35:44 riastradh Exp $");
#ifdef _KERNEL_OPT
#include "opt_inet.h"
@ -1829,13 +1829,14 @@ wg_handle_msg_resp(struct wg_softc *wg, const struct wg_msg_resp *wgmr,
wg_clear_states(wgs);
WG_TRACE("WGS_STATE_ESTABLISHED");
wg_stop_handshake_timeout_timer(wgp);
mutex_enter(wgp->wgp_lock);
wg_swap_sessions(wgp);
wgs_prev = wgp->wgp_session_unstable;
mutex_enter(wgs_prev->wgs_lock);
getnanotime(&wgp->wgp_last_handshake_time);
wg_stop_handshake_timeout_timer(wgp);
wgp->wgp_handshake_start_time = 0;
wgp->wgp_last_sent_mac1_valid = false;
wgp->wgp_last_sent_cookie_valid = false;