Merge pull request #3276 from lucas-clemente/windows-disable-pmtud

disable Path MTU Discovery on Windows
This commit is contained in:
Marten Seemann
2021-10-13 08:55:42 +01:00
committed by GitHub
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.
@@ -745,7 +749,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)
}
@@ -809,7 +813,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
@@ -1770,7 +1774,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,33 +1682,35 @@ var _ = Describe("Session", func() {
time.Sleep(50 * time.Millisecond)
})
It("sends a Path MTU probe packet", func() {
mtuDiscoverer := NewMockMtuDiscoverer(mockCtrl)
sess.mtuDiscoverer = mtuDiscoverer
sess.config.DisablePathMTUDiscovery = false
sph.EXPECT().SentPacket(gomock.Any())
sph.EXPECT().HasPacingBudget().Return(true).AnyTimes()
sph.EXPECT().SendMode().Return(ackhandler.SendAny)
sph.EXPECT().SendMode().Return(ackhandler.SendNone)
written := make(chan struct{}, 1)
sender.EXPECT().WouldBlock().AnyTimes()
sender.EXPECT().Send(gomock.Any()).DoAndReturn(func(p *packetBuffer) { written <- struct{}{} })
gomock.InOrder(
mtuDiscoverer.EXPECT().NextProbeTime(),
mtuDiscoverer.EXPECT().ShouldSendProbe(gomock.Any()).Return(true),
mtuDiscoverer.EXPECT().NextProbeTime(),
)
ping := ackhandler.Frame{Frame: &wire.PingFrame{}}
mtuDiscoverer.EXPECT().GetPing().Return(ping, protocol.ByteCount(1234))
packer.EXPECT().PackMTUProbePacket(ping, protocol.ByteCount(1234)).Return(getPacket(1), nil)
go func() {
defer GinkgoRecover()
cryptoSetup.EXPECT().RunHandshake().MaxTimes(1)
sess.run()
}()
sess.scheduleSending()
Eventually(written).Should(Receive())
})
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
sess.config.DisablePathMTUDiscovery = false
sph.EXPECT().SentPacket(gomock.Any())
sph.EXPECT().HasPacingBudget().Return(true).AnyTimes()
sph.EXPECT().SendMode().Return(ackhandler.SendAny)
sph.EXPECT().SendMode().Return(ackhandler.SendNone)
written := make(chan struct{}, 1)
sender.EXPECT().WouldBlock().AnyTimes()
sender.EXPECT().Send(gomock.Any()).DoAndReturn(func(p *packetBuffer) { written <- struct{}{} })
gomock.InOrder(
mtuDiscoverer.EXPECT().NextProbeTime(),
mtuDiscoverer.EXPECT().ShouldSendProbe(gomock.Any()).Return(true),
mtuDiscoverer.EXPECT().NextProbeTime(),
)
ping := ackhandler.Frame{Frame: &wire.PingFrame{}}
mtuDiscoverer.EXPECT().GetPing().Return(ping, protocol.ByteCount(1234))
packer.EXPECT().PackMTUProbePacket(ping, protocol.ByteCount(1234)).Return(getPacket(1), nil)
go func() {
defer GinkgoRecover()
cryptoSetup.EXPECT().RunHandshake().MaxTimes(1)
sess.run()
}()
sess.scheduleSending()
Eventually(written).Should(Receive())
})
}
})
Context("scheduling sending", func() {