Skip to content

Commit a7ccc9e

Browse files
riastradhriastradh
riastradh
authored and
riastradh
committed
wg(4): Add debug log for which address we send handshake msgs to.
Maybe this will help to diagnose: PR kern/58938: wg tunnel dies after a few days
1 parent 5c1d931 commit a7ccc9e

File tree

1 file changed

+40
-12
lines changed

1 file changed

+40
-12
lines changed

sys/net/if_wg.c

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $NetBSD: if_wg.c,v 1.133 2024/11/28 15:35:27 riastradh Exp $ */
1+
/* $NetBSD: if_wg.c,v 1.134 2024/12/27 15:55:19 riastradh Exp $ */
22

33
/*
44
* Copyright (C) Ryota Ozaki <[email protected]>
@@ -43,7 +43,7 @@
4343
*/
4444

4545
#include <sys/cdefs.h>
46-
__KERNEL_RCSID(0, "$NetBSD: if_wg.c,v 1.133 2024/11/28 15:35:27 riastradh Exp $");
46+
__KERNEL_RCSID(0, "$NetBSD: if_wg.c,v 1.134 2024/12/27 15:55:19 riastradh Exp $");
4747

4848
#ifdef _KERNEL_OPT
4949
#include "opt_altq_enabled.h"
@@ -785,8 +785,8 @@ static void wg_clear_states(struct wg_session *);
785785
static void wg_get_peer(struct wg_peer *, struct psref *);
786786
static void wg_put_peer(struct wg_peer *, struct psref *);
787787

788-
static int wg_send_so(struct wg_peer *, struct mbuf *);
789-
static int wg_send_udp(struct wg_peer *, struct mbuf *);
788+
static int wg_send_hs(struct wg_peer *, struct mbuf *);
789+
static int wg_send_data(struct wg_peer *, struct mbuf *);
790790
static int wg_output(struct ifnet *, struct mbuf *,
791791
const struct sockaddr *, const struct rtentry *);
792792
static void wg_input(struct ifnet *, struct mbuf *, const int);
@@ -814,8 +814,8 @@ struct wg_ops {
814814
};
815815

816816
struct wg_ops wg_ops_rumpkernel = {
817-
.send_hs_msg = wg_send_so,
818-
.send_data_msg = wg_send_udp,
817+
.send_hs_msg = wg_send_hs,
818+
.send_data_msg = wg_send_data,
819819
.input = wg_input,
820820
.bind_port = wg_bind_port,
821821
};
@@ -824,13 +824,14 @@ struct wg_ops wg_ops_rumpkernel = {
824824
static bool wg_user_mode(struct wg_softc *);
825825
static int wg_ioctl_linkstr(struct wg_softc *, struct ifdrv *);
826826

827-
static int wg_send_user(struct wg_peer *, struct mbuf *);
827+
static int wg_send_hs_user(struct wg_peer *, struct mbuf *);
828+
static int wg_send_data_user(struct wg_peer *, struct mbuf *);
828829
static void wg_input_user(struct ifnet *, struct mbuf *, const int);
829830
static int wg_bind_port_user(struct wg_softc *, const uint16_t);
830831

831832
struct wg_ops wg_ops_rumpuser = {
832-
.send_hs_msg = wg_send_user,
833-
.send_data_msg = wg_send_user,
833+
.send_hs_msg = wg_send_hs_user,
834+
.send_data_msg = wg_send_data_user,
834835
.input = wg_input_user,
835836
.bind_port = wg_bind_port_user,
836837
};
@@ -1898,14 +1899,19 @@ wg_put_sa(struct wg_peer *wgp, struct wg_sockaddr *wgsa, struct psref *psref)
18981899
}
18991900

19001901
static int
1901-
wg_send_so(struct wg_peer *wgp, struct mbuf *m)
1902+
wg_send_hs(struct wg_peer *wgp, struct mbuf *m)
19021903
{
19031904
int error;
19041905
struct socket *so;
19051906
struct psref psref;
19061907
struct wg_sockaddr *wgsa;
19071908

19081909
wgsa = wg_get_endpoint_sa(wgp, &psref);
1910+
#ifdef WG_DEBUG_LOG
1911+
char addr[128];
1912+
sockaddr_format(wgsatosa(wgsa), addr, sizeof(addr));
1913+
WG_DLOG("send handshake msg to %s\n", addr);
1914+
#endif
19091915
so = wg_get_so_by_peer(wgp, wgsa);
19101916
error = sosend(so, wgsatosa(wgsa), NULL, m, NULL, 0, curlwp);
19111917
wg_put_sa(wgp, wgsa, &psref);
@@ -4399,7 +4405,7 @@ out0: m_freem(m);
43994405
}
44004406

44014407
static int
4402-
wg_send_udp(struct wg_peer *wgp, struct mbuf *m)
4408+
wg_send_data(struct wg_peer *wgp, struct mbuf *m)
44034409
{
44044410
struct psref psref;
44054411
struct wg_sockaddr *wgsa;
@@ -5452,7 +5458,7 @@ wg_ioctl_linkstr(struct wg_softc *wg, struct ifdrv *ifd)
54525458
}
54535459

54545460
static int
5455-
wg_send_user(struct wg_peer *wgp, struct mbuf *m)
5461+
wg_send_user(struct wg_peer *wgp, struct mbuf *m, bool handshake)
54565462
{
54575463
int error;
54585464
struct psref psref;
@@ -5462,6 +5468,14 @@ wg_send_user(struct wg_peer *wgp, struct mbuf *m)
54625468

54635469
wgsa = wg_get_endpoint_sa(wgp, &psref);
54645470

5471+
#ifdef WG_DEBUG_LOG
5472+
if (handshake) {
5473+
char addr[128];
5474+
sockaddr_format(wgsatosa(wgsa), addr, sizeof(addr));
5475+
WG_DLOG("send handshake msg to %s\n", addr);
5476+
}
5477+
#endif
5478+
54655479
iov[0].iov_base = mtod(m, void *);
54665480
iov[0].iov_len = m->m_len;
54675481

@@ -5475,6 +5489,20 @@ wg_send_user(struct wg_peer *wgp, struct mbuf *m)
54755489
return error;
54765490
}
54775491

5492+
static int
5493+
wg_send_hs_user(struct wg_peer *wgp, struct mbuf *m)
5494+
{
5495+
5496+
return wg_send_user(wgp, m, /*handshake*/true);
5497+
}
5498+
5499+
static int
5500+
wg_send_hs_data(struct wg_peer *wgp, struct mbuf *m)
5501+
{
5502+
5503+
return wg_send_user(wgp, m, /*handshake*/false);
5504+
}
5505+
54785506
static void
54795507
wg_input_user(struct ifnet *ifp, struct mbuf *m, const int af)
54805508
{

0 commit comments

Comments
 (0)