Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move set DF implementation to separate files & avoid the need for OOB…
…CapablePacketConn (#3334) * move set DF implementation to separate files & avoid the need for OOBCapablePacketConn * merge err_size_* into conn_df_* & fix format
- Loading branch information
Showing
10 changed files
with
106 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
//go:build linux | ||
// +build linux | ||
|
||
package quic | ||
|
||
import ( | ||
"errors" | ||
"syscall" | ||
|
||
"github.com/lucas-clemente/quic-go/internal/utils" | ||
"golang.org/x/sys/unix" | ||
) | ||
|
||
func setDF(rawConn syscall.RawConn) error { | ||
// Enabling IP_MTU_DISCOVER will force the kernel to return "sendto: message too long" | ||
// and the datagram will not be fragmented | ||
var errDFIPv4, errDFIPv6 error | ||
if err := rawConn.Control(func(fd uintptr) { | ||
errDFIPv4 = unix.SetsockoptInt(int(fd), unix.IPPROTO_IP, unix.IP_MTU_DISCOVER, unix.IP_PMTUDISC_DO) | ||
errDFIPv6 = unix.SetsockoptInt(int(fd), unix.IPPROTO_IPV6, unix.IPV6_MTU_DISCOVER, unix.IPV6_PMTUDISC_DO) | ||
}); err != nil { | ||
return err | ||
} | ||
switch { | ||
case errDFIPv4 == nil && errDFIPv6 == nil: | ||
utils.DefaultLogger.Debugf("Setting DF for IPv4 and IPv6.") | ||
case errDFIPv4 == nil && errDFIPv6 != nil: | ||
utils.DefaultLogger.Debugf("Setting DF for IPv4.") | ||
case errDFIPv4 != nil && errDFIPv6 == nil: | ||
utils.DefaultLogger.Debugf("Setting DF for IPv6.") | ||
case errDFIPv4 != nil && errDFIPv6 != nil: | ||
return errors.New("setting DF failed for both IPv4 and IPv6") | ||
} | ||
return nil | ||
} | ||
|
||
func isMsgSizeErr(err error) bool { | ||
// https://man7.org/linux/man-pages/man7/udp.7.html | ||
return errors.Is(err, unix.EMSGSIZE) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
//go:build windows | ||
// +build windows | ||
|
||
package quic | ||
|
||
import ( | ||
"errors" | ||
"syscall" | ||
|
||
"github.com/lucas-clemente/quic-go/internal/utils" | ||
"golang.org/x/sys/windows" | ||
) | ||
|
||
const ( | ||
// same for both IPv4 and IPv6 on Windows | ||
// https://microsoft.github.io/windows-docs-rs/doc/windows/Win32/Networking/WinSock/constant.IP_DONTFRAG.html | ||
// https://microsoft.github.io/windows-docs-rs/doc/windows/Win32/Networking/WinSock/constant.IPV6_DONTFRAG.html | ||
IP_DONTFRAGMENT = 14 | ||
IPV6_DONTFRAG = 14 | ||
) | ||
|
||
func setDF(rawConn syscall.RawConn) error { | ||
var errDFIPv4, errDFIPv6 error | ||
if err := rawConn.Control(func(fd uintptr) { | ||
errDFIPv4 = windows.SetsockoptInt(windows.Handle(fd), windows.IPPROTO_IP, IP_DONTFRAGMENT, 1) | ||
errDFIPv6 = windows.SetsockoptInt(windows.Handle(fd), windows.IPPROTO_IPV6, IPV6_DONTFRAG, 1) | ||
}); err != nil { | ||
return err | ||
} | ||
switch { | ||
case errDFIPv4 == nil && errDFIPv6 == nil: | ||
utils.DefaultLogger.Debugf("Setting DF for IPv4 and IPv6.") | ||
case errDFIPv4 == nil && errDFIPv6 != nil: | ||
utils.DefaultLogger.Debugf("Setting DF for IPv4.") | ||
case errDFIPv4 != nil && errDFIPv6 == nil: | ||
utils.DefaultLogger.Debugf("Setting DF for IPv6.") | ||
case errDFIPv4 != nil && errDFIPv6 != nil: | ||
return errors.New("setting DF failed for both IPv4 and IPv6") | ||
} | ||
return nil | ||
} | ||
|
||
func isMsgSizeErr(err error) bool { | ||
// https://docs.microsoft.com/en-us/windows/win32/winsock/windows-sockets-error-codes-2 | ||
return errors.Is(err, windows.WSAEMSGSIZE) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.