From 46c04db29f1c682cb49afdc45e895b5559ffd7d0 Mon Sep 17 00:00:00 2001 From: xjasonlyu Date: Fri, 26 May 2023 16:23:01 +0800 Subject: [PATCH] Fix: tun issue with virtio_net_hdr (#254) --- core/device/tun/tun_wireguard_linux.go | 24 ++++++++++++++++++++++++ core/device/tun/tun_wireguard_unix.go | 3 +-- 2 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 core/device/tun/tun_wireguard_linux.go diff --git a/core/device/tun/tun_wireguard_linux.go b/core/device/tun/tun_wireguard_linux.go new file mode 100644 index 0000000..dc74bf9 --- /dev/null +++ b/core/device/tun/tun_wireguard_linux.go @@ -0,0 +1,24 @@ +//go:build linux && !(amd64 || arm64) + +package tun + +import ( + "unsafe" +) + +const ( + virtioNetHdrLen = int(unsafe.Sizeof(virtioNetHdr{})) + offset = virtioNetHdrLen + 0 /* NO_PI */ + defaultMTU = 1500 +) + +// virtioNetHdr is defined in the kernel in include/uapi/linux/virtio_net.h. The +// kernel symbol is virtio_net_hdr. +type virtioNetHdr struct { + flags uint8 + gsoType uint8 + hdrLen uint16 + gsoSize uint16 + csumStart uint16 + csumOffset uint16 +} diff --git a/core/device/tun/tun_wireguard_unix.go b/core/device/tun/tun_wireguard_unix.go index 550eb32..5842df3 100644 --- a/core/device/tun/tun_wireguard_unix.go +++ b/core/device/tun/tun_wireguard_unix.go @@ -1,8 +1,7 @@ -//go:build unix +//go:build unix && !linux package tun -//nolint:all const ( offset = 4 /* 4 bytes TUN_PI */ defaultMTU = 1500