github.com/sagernet/quic-go@v0.43.1-beta.1/sys_conn_df_linux.go (about) 1 //go:build linux 2 3 package quic 4 5 import ( 6 "errors" 7 "syscall" 8 9 "github.com/sagernet/quic-go/internal/utils" 10 "golang.org/x/sys/unix" 11 ) 12 13 func setDF(rawConn syscall.RawConn) (bool, error) { 14 // Enabling IP_MTU_DISCOVER will force the kernel to return "sendto: message too long" 15 // and the datagram will not be fragmented 16 var errDFIPv4, errDFIPv6 error 17 if err := rawConn.Control(func(fd uintptr) { 18 errDFIPv4 = unix.SetsockoptInt(int(fd), unix.IPPROTO_IP, unix.IP_MTU_DISCOVER, unix.IP_PMTUDISC_DO) 19 errDFIPv6 = unix.SetsockoptInt(int(fd), unix.IPPROTO_IPV6, unix.IPV6_MTU_DISCOVER, unix.IPV6_PMTUDISC_DO) 20 }); err != nil { 21 return false, err 22 } 23 switch { 24 case errDFIPv4 == nil && errDFIPv6 == nil: 25 utils.DefaultLogger.Debugf("Setting DF for IPv4 and IPv6.") 26 case errDFIPv4 == nil && errDFIPv6 != nil: 27 utils.DefaultLogger.Debugf("Setting DF for IPv4.") 28 case errDFIPv4 != nil && errDFIPv6 == nil: 29 utils.DefaultLogger.Debugf("Setting DF for IPv6.") 30 case errDFIPv4 != nil && errDFIPv6 != nil: 31 utils.DefaultLogger.Debugf("Setting DF failed for both IPv4 and IPv6.") 32 } 33 return true, nil 34 } 35 36 func isSendMsgSizeErr(err error) bool { 37 // https://man7.org/linux/man-pages/man7/udp.7.html 38 return errors.Is(err, unix.EMSGSIZE) 39 } 40 41 func isRecvMsgSizeErr(error) bool { return false }