github.com/amnezia-vpn/amneziawg-go@v0.2.8/conn/features_linux.go (about) 1 /* SPDX-License-Identifier: MIT 2 * 3 * Copyright (C) 2017-2023 WireGuard LLC. All Rights Reserved. 4 */ 5 6 package conn 7 8 import ( 9 "net" 10 11 "golang.org/x/sys/unix" 12 ) 13 14 func supportsUDPOffload(conn *net.UDPConn) (txOffload, rxOffload bool) { 15 rc, err := conn.SyscallConn() 16 if err != nil { 17 return 18 } 19 err = rc.Control(func(fd uintptr) { 20 _, errSyscall := unix.GetsockoptInt(int(fd), unix.IPPROTO_UDP, unix.UDP_SEGMENT) 21 txOffload = errSyscall == nil 22 // getsockopt(IPPROTO_UDP, UDP_GRO) is not supported in android 23 // use setsockopt workaround 24 errSyscall = unix.SetsockoptInt(int(fd), unix.IPPROTO_UDP, unix.UDP_GRO, 1) 25 rxOffload = errSyscall == nil 26 }) 27 if err != nil { 28 return false, false 29 } 30 return txOffload, rxOffload 31 }