Module Name: src
Committed By: riastradh
Date: Fri Dec 27 15:55:19 UTC 2024
Modified Files:
src/sys/net: if_wg.c
Log Message:
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
To generate a diff of this commit:
cvs rdiff -u -r1.133 -r1.134 src/sys/net/if_wg.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/net/if_wg.c
diff -u src/sys/net/if_wg.c:1.133 src/sys/net/if_wg.c:1.134
--- src/sys/net/if_wg.c:1.133 Thu Nov 28 15:35:27 2024
+++ src/sys/net/if_wg.c Fri Dec 27 15:55:19 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: if_wg.c,v 1.133 2024/11/28 15:35:27 riastradh Exp $ */
+/* $NetBSD: if_wg.c,v 1.134 2024/12/27 15:55:19 riastradh Exp $ */
/*
* Copyright (C) Ryota Ozaki <[email protected]>
@@ -43,7 +43,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_wg.c,v 1.133 2024/11/28 15:35:27 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_wg.c,v 1.134 2024/12/27 15:55:19 riastradh Exp $");
#ifdef _KERNEL_OPT
#include "opt_altq_enabled.h"
@@ -785,8 +785,8 @@ static void wg_clear_states(struct wg_se
static void wg_get_peer(struct wg_peer *, struct psref *);
static void wg_put_peer(struct wg_peer *, struct psref *);
-static int wg_send_so(struct wg_peer *, struct mbuf *);
-static int wg_send_udp(struct wg_peer *, struct mbuf *);
+static int wg_send_hs(struct wg_peer *, struct mbuf *);
+static int wg_send_data(struct wg_peer *, struct mbuf *);
static int wg_output(struct ifnet *, struct mbuf *,
const struct sockaddr *, const struct rtentry *);
static void wg_input(struct ifnet *, struct mbuf *, const int);
@@ -814,8 +814,8 @@ struct wg_ops {
};
struct wg_ops wg_ops_rumpkernel = {
- .send_hs_msg = wg_send_so,
- .send_data_msg = wg_send_udp,
+ .send_hs_msg = wg_send_hs,
+ .send_data_msg = wg_send_data,
.input = wg_input,
.bind_port = wg_bind_port,
};
@@ -824,13 +824,14 @@ struct wg_ops wg_ops_rumpkernel = {
static bool wg_user_mode(struct wg_softc *);
static int wg_ioctl_linkstr(struct wg_softc *, struct ifdrv *);
-static int wg_send_user(struct wg_peer *, struct mbuf *);
+static int wg_send_hs_user(struct wg_peer *, struct mbuf *);
+static int wg_send_data_user(struct wg_peer *, struct mbuf *);
static void wg_input_user(struct ifnet *, struct mbuf *, const int);
static int wg_bind_port_user(struct wg_softc *, const uint16_t);
struct wg_ops wg_ops_rumpuser = {
- .send_hs_msg = wg_send_user,
- .send_data_msg = wg_send_user,
+ .send_hs_msg = wg_send_hs_user,
+ .send_data_msg = wg_send_data_user,
.input = wg_input_user,
.bind_port = wg_bind_port_user,
};
@@ -1898,7 +1899,7 @@ wg_put_sa(struct wg_peer *wgp, struct wg
}
static int
-wg_send_so(struct wg_peer *wgp, struct mbuf *m)
+wg_send_hs(struct wg_peer *wgp, struct mbuf *m)
{
int error;
struct socket *so;
@@ -1906,6 +1907,11 @@ wg_send_so(struct wg_peer *wgp, struct m
struct wg_sockaddr *wgsa;
wgsa = wg_get_endpoint_sa(wgp, &psref);
+#ifdef WG_DEBUG_LOG
+ char addr[128];
+ sockaddr_format(wgsatosa(wgsa), addr, sizeof(addr));
+ WG_DLOG("send handshake msg to %s\n", addr);
+#endif
so = wg_get_so_by_peer(wgp, wgsa);
error = sosend(so, wgsatosa(wgsa), NULL, m, NULL, 0, curlwp);
wg_put_sa(wgp, wgsa, &psref);
@@ -4399,7 +4405,7 @@ out0: m_freem(m);
}
static int
-wg_send_udp(struct wg_peer *wgp, struct mbuf *m)
+wg_send_data(struct wg_peer *wgp, struct mbuf *m)
{
struct psref psref;
struct wg_sockaddr *wgsa;
@@ -5452,7 +5458,7 @@ wg_ioctl_linkstr(struct wg_softc *wg, st
}
static int
-wg_send_user(struct wg_peer *wgp, struct mbuf *m)
+wg_send_user(struct wg_peer *wgp, struct mbuf *m, bool handshake)
{
int error;
struct psref psref;
@@ -5462,6 +5468,14 @@ wg_send_user(struct wg_peer *wgp, struct
wgsa = wg_get_endpoint_sa(wgp, &psref);
+#ifdef WG_DEBUG_LOG
+ if (handshake) {
+ char addr[128];
+ sockaddr_format(wgsatosa(wgsa), addr, sizeof(addr));
+ WG_DLOG("send handshake msg to %s\n", addr);
+ }
+#endif
+
iov[0].iov_base = mtod(m, void *);
iov[0].iov_len = m->m_len;
@@ -5475,6 +5489,20 @@ wg_send_user(struct wg_peer *wgp, struct
return error;
}
+static int
+wg_send_hs_user(struct wg_peer *wgp, struct mbuf *m)
+{
+
+ return wg_send_user(wgp, m, /*handshake*/true);
+}
+
+static int
+wg_send_hs_data(struct wg_peer *wgp, struct mbuf *m)
+{
+
+ return wg_send_user(wgp, m, /*handshake*/false);
+}
+
static void
wg_input_user(struct ifnet *ifp, struct mbuf *m, const int af)
{