github.com/sagernet/sing@v0.4.0-beta.19.0.20240518125136-f67a0988a636/common/control/frag_linux.go (about) 1 package control 2 3 import ( 4 "os" 5 "syscall" 6 7 N "github.com/sagernet/sing/common/network" 8 9 "golang.org/x/sys/unix" 10 ) 11 12 func DisableUDPFragment() Func { 13 return func(network, address string, conn syscall.RawConn) error { 14 switch N.NetworkName(network) { 15 case N.NetworkUDP: 16 default: 17 return nil 18 } 19 return Raw(conn, func(fd uintptr) error { 20 if err := unix.SetsockoptInt(int(fd), unix.IPPROTO_IP, unix.IP_MTU_DISCOVER, unix.IP_PMTUDISC_DO); err != nil { 21 return os.NewSyscallError("SETSOCKOPT IP_MTU_DISCOVER IP_PMTUDISC_DO", err) 22 } 23 if network == "udp6" { 24 if err := unix.SetsockoptInt(int(fd), unix.IPPROTO_IPV6, unix.IPV6_MTU_DISCOVER, unix.IP_PMTUDISC_DO); err != nil { 25 return os.NewSyscallError("SETSOCKOPT IPV6_MTU_DISCOVER IP_PMTUDISC_DO", err) 26 } 27 } 28 return nil 29 }) 30 } 31 }