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 $ */
2
2
3
3
/*
4
4
* Copyright (C) Ryota Ozaki <[email protected] >
43
43
*/
44
44
45
45
#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 $" );
47
47
48
48
#ifdef _KERNEL_OPT
49
49
#include "opt_altq_enabled.h"
@@ -785,8 +785,8 @@ static void wg_clear_states(struct wg_session *);
785
785
static void wg_get_peer (struct wg_peer * , struct psref * );
786
786
static void wg_put_peer (struct wg_peer * , struct psref * );
787
787
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 * );
790
790
static int wg_output (struct ifnet * , struct mbuf * ,
791
791
const struct sockaddr * , const struct rtentry * );
792
792
static void wg_input (struct ifnet * , struct mbuf * , const int );
@@ -814,8 +814,8 @@ struct wg_ops {
814
814
};
815
815
816
816
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 ,
819
819
.input = wg_input ,
820
820
.bind_port = wg_bind_port ,
821
821
};
@@ -824,13 +824,14 @@ struct wg_ops wg_ops_rumpkernel = {
824
824
static bool wg_user_mode (struct wg_softc * );
825
825
static int wg_ioctl_linkstr (struct wg_softc * , struct ifdrv * );
826
826
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 * );
828
829
static void wg_input_user (struct ifnet * , struct mbuf * , const int );
829
830
static int wg_bind_port_user (struct wg_softc * , const uint16_t );
830
831
831
832
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 ,
834
835
.input = wg_input_user ,
835
836
.bind_port = wg_bind_port_user ,
836
837
};
@@ -1898,14 +1899,19 @@ wg_put_sa(struct wg_peer *wgp, struct wg_sockaddr *wgsa, struct psref *psref)
1898
1899
}
1899
1900
1900
1901
static int
1901
- wg_send_so (struct wg_peer * wgp , struct mbuf * m )
1902
+ wg_send_hs (struct wg_peer * wgp , struct mbuf * m )
1902
1903
{
1903
1904
int error ;
1904
1905
struct socket * so ;
1905
1906
struct psref psref ;
1906
1907
struct wg_sockaddr * wgsa ;
1907
1908
1908
1909
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
1909
1915
so = wg_get_so_by_peer (wgp , wgsa );
1910
1916
error = sosend (so , wgsatosa (wgsa ), NULL , m , NULL , 0 , curlwp );
1911
1917
wg_put_sa (wgp , wgsa , & psref );
@@ -4399,7 +4405,7 @@ out0: m_freem(m);
4399
4405
}
4400
4406
4401
4407
static int
4402
- wg_send_udp (struct wg_peer * wgp , struct mbuf * m )
4408
+ wg_send_data (struct wg_peer * wgp , struct mbuf * m )
4403
4409
{
4404
4410
struct psref psref ;
4405
4411
struct wg_sockaddr * wgsa ;
@@ -5452,7 +5458,7 @@ wg_ioctl_linkstr(struct wg_softc *wg, struct ifdrv *ifd)
5452
5458
}
5453
5459
5454
5460
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 )
5456
5462
{
5457
5463
int error ;
5458
5464
struct psref psref ;
@@ -5462,6 +5468,14 @@ wg_send_user(struct wg_peer *wgp, struct mbuf *m)
5462
5468
5463
5469
wgsa = wg_get_endpoint_sa (wgp , & psref );
5464
5470
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
+
5465
5479
iov [0 ].iov_base = mtod (m , void * );
5466
5480
iov [0 ].iov_len = m -> m_len ;
5467
5481
@@ -5475,6 +5489,20 @@ wg_send_user(struct wg_peer *wgp, struct mbuf *m)
5475
5489
return error ;
5476
5490
}
5477
5491
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
+
5478
5506
static void
5479
5507
wg_input_user (struct ifnet * ifp , struct mbuf * m , const int af )
5480
5508
{
0 commit comments