disable Path MTU Discovery on Windows

This commit is contained in:
Marten Seemann
2021-09-14 18:39:23 +02:00
parent 3b46d7402c
commit d410b590e9
8 changed files with 56 additions and 34 deletions

View File

@@ -5,6 +5,8 @@ package quic
import "net"
const disablePathMTUDiscovery = false
func newConn(c net.PacketConn) (connection, error) {
return &basicConn{PacketConn: c}, nil
}

View File

@@ -5,7 +5,10 @@ package quic
import "golang.org/x/sys/unix"
const msgTypeIPTOS = unix.IP_RECVTOS
const (
msgTypeIPTOS = unix.IP_RECVTOS
disablePathMTUDiscovery = false
)
const (
ipv4RECVPKTINFO = unix.IP_RECVPKTINFO

View File

@@ -5,7 +5,10 @@ package quic
import "golang.org/x/sys/unix"
const msgTypeIPTOS = unix.IP_RECVTOS
const (
msgTypeIPTOS = unix.IP_RECVTOS
disablePathMTUDiscovery = false
)
const (
ipv4RECVPKTINFO = 0x7

View File

@@ -5,7 +5,10 @@ package quic
import "golang.org/x/sys/unix"
const msgTypeIPTOS = unix.IP_TOS
const (
msgTypeIPTOS = unix.IP_TOS
disablePathMTUDiscovery = false
)
const (
ipv4RECVPKTINFO = unix.IP_PKTINFO

View File

@@ -12,7 +12,10 @@ import (
"golang.org/x/sys/windows"
)
const IP_DONTFRAGMENT = 14
const (
disablePathMTUDiscovery = true
IP_DONTFRAGMENT = 14
)
func newConn(c OOBCapablePacketConn) (connection, error) {
rawConn, err := c.SyscallConn()

View File

@@ -283,6 +283,7 @@ type Config struct {
KeepAlive bool
// DisablePathMTUDiscovery disables Path MTU Discovery (RFC 8899).
// Packets will then be at most 1252 (IPv4) / 1232 (IPv6) bytes in size.
// Note that Path MTU discovery is always disabled on Windows, see https://github.com/lucas-clemente/quic-go/issues/3273.
DisablePathMTUDiscovery bool
// DisableVersionNegotiationPackets disables the sending of Version Negotiation packets.
// This can be useful if version information is exchanged out-of-band.

View File

@@ -130,6 +130,10 @@ func (e *errCloseForRecreating) Error() string {
var sessionTracingID uint64 // to be accessed atomically
func nextSessionTracingID() uint64 { return atomic.AddUint64(&sessionTracingID, 1) }
func pathMTUDiscoveryEnabled(config *Config) bool {
return !disablePathMTUDiscovery && !config.DisablePathMTUDiscovery
}
// A Session is a QUIC session
type session struct {
// Destination connection ID used during the handshake.
@@ -743,7 +747,7 @@ func (s *session) maybeResetTimer() {
deadline = s.idleTimeoutStartTime().Add(s.idleTimeout)
}
}
if s.handshakeConfirmed && !s.config.DisablePathMTUDiscovery {
if s.handshakeConfirmed && pathMTUDiscoveryEnabled(s.config) {
if probeTime := s.mtuDiscoverer.NextProbeTime(); !probeTime.IsZero() {
deadline = utils.MinTime(deadline, probeTime)
}
@@ -807,7 +811,7 @@ func (s *session) handleHandshakeConfirmed() {
s.sentPacketHandler.SetHandshakeConfirmed()
s.cryptoStreamHandler.SetHandshakeConfirmed()
if !s.config.DisablePathMTUDiscovery {
if pathMTUDiscoveryEnabled(s.config) {
maxPacketSize := s.peerParams.MaxUDPPayloadSize
if maxPacketSize == 0 {
maxPacketSize = protocol.MaxByteCount
@@ -1768,7 +1772,7 @@ func (s *session) sendPacket() (bool, error) {
s.sendQueue.Send(packet.buffer)
return true, nil
}
if !s.config.DisablePathMTUDiscovery && s.mtuDiscoverer.ShouldSendProbe(now) {
if pathMTUDiscoveryEnabled(s.config) && s.mtuDiscoverer.ShouldSendProbe(now) {
packet, err := s.packer.PackMTUProbePacket(s.mtuDiscoverer.GetPing())
if err != nil {
return false, err

View File

@@ -9,6 +9,7 @@ import (
"fmt"
"io"
"net"
"runtime"
"runtime/pprof"
"strings"
"time"
@@ -1681,6 +1682,7 @@ var _ = Describe("Session", func() {
time.Sleep(50 * time.Millisecond)
})
if runtime.GOOS != "windows" { // Path MTU Discovery is disabled on Windows
It("sends a Path MTU probe packet", func() {
mtuDiscoverer := NewMockMtuDiscoverer(mockCtrl)
sess.mtuDiscoverer = mtuDiscoverer
@@ -1708,6 +1710,7 @@ var _ = Describe("Session", func() {
sess.scheduleSending()
Eventually(written).Should(Receive())
})
}
})
Context("scheduling sending", func() {