github.com/ooni/psiphon/tunnel-core@v0.0.0-20230105123940-fe12a24c96ee/oovendor/quic-go/conn_df_windows.go (about) 1 //go:build windows 2 // +build windows 3 4 package quic 5 6 import ( 7 "errors" 8 "syscall" 9 10 "github.com/ooni/psiphon/tunnel-core/oovendor/quic-go/internal/utils" 11 "golang.org/x/sys/windows" 12 ) 13 14 const ( 15 // same for both IPv4 and IPv6 on Windows 16 // https://microsoft.github.io/windows-docs-rs/doc/windows/Win32/Networking/WinSock/constant.IP_DONTFRAG.html 17 // https://microsoft.github.io/windows-docs-rs/doc/windows/Win32/Networking/WinSock/constant.IPV6_DONTFRAG.html 18 IP_DONTFRAGMENT = 14 19 IPV6_DONTFRAG = 14 20 ) 21 22 func setDF(rawConn syscall.RawConn) error { 23 var errDFIPv4, errDFIPv6 error 24 if err := rawConn.Control(func(fd uintptr) { 25 errDFIPv4 = windows.SetsockoptInt(windows.Handle(fd), windows.IPPROTO_IP, IP_DONTFRAGMENT, 1) 26 errDFIPv6 = windows.SetsockoptInt(windows.Handle(fd), windows.IPPROTO_IPV6, IPV6_DONTFRAG, 1) 27 }); err != nil { 28 return err 29 } 30 switch { 31 case errDFIPv4 == nil && errDFIPv6 == nil: 32 utils.DefaultLogger.Debugf("Setting DF for IPv4 and IPv6.") 33 case errDFIPv4 == nil && errDFIPv6 != nil: 34 utils.DefaultLogger.Debugf("Setting DF for IPv4.") 35 case errDFIPv4 != nil && errDFIPv6 == nil: 36 utils.DefaultLogger.Debugf("Setting DF for IPv6.") 37 case errDFIPv4 != nil && errDFIPv6 != nil: 38 return errors.New("setting DF failed for both IPv4 and IPv6") 39 } 40 return nil 41 } 42 43 func isMsgSizeErr(err error) bool { 44 // https://docs.microsoft.com/en-us/windows/win32/winsock/windows-sockets-error-codes-2 45 return errors.Is(err, windows.WSAEMSGSIZE) 46 }