From 84e03e59760ceee37359688871bb0688fcc4e98f Mon Sep 17 00:00:00 2001 From: Toby Date: Tue, 20 Apr 2021 22:39:39 -0700 Subject: [PATCH] set the don't fragment (DF) bit on Windows (#3155) --- conn_windows.go | 20 +++++++++++++++++++- conn_windows_test.go | 22 ++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 conn_windows_test.go diff --git a/conn_windows.go b/conn_windows.go index 833f2374..d1f0240a 100644 --- a/conn_windows.go +++ b/conn_windows.go @@ -11,8 +11,26 @@ import ( "golang.org/x/sys/windows" ) +const IP_DONTFRAGMENT = 14 + func newConn(c net.PacketConn) (connection, error) { - return &basicConn{PacketConn: c}, nil + conn, ok := c.(interface { + SyscallConn() (syscall.RawConn, error) + }) + if !ok { + return nil, errors.New("doesn't have a SyscallConn") + } + rawConn, err := conn.SyscallConn() + if err != nil { + return nil, fmt.Errorf("couldn't get syscall.RawConn: %w", err) + } + var serr error + if err := rawConn.Control(func(fd uintptr) { + serr = windows.SetsockoptInt(windows.Handle(fd), windows.IPPROTO_IP, IP_DONTFRAGMENT, 1) + }); err != nil { + return nil, err + } + return &basicConn{PacketConn: c}, serr } func inspectReadBuffer(c net.PacketConn) (int, error) { diff --git a/conn_windows_test.go b/conn_windows_test.go new file mode 100644 index 00000000..8e6ef9c2 --- /dev/null +++ b/conn_windows_test.go @@ -0,0 +1,22 @@ +// +build windows + +package quic + +import ( + "net" + + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" +) + +var _ = Describe("Windows Conn Test", func() { + It("try newConn", func() { + addr, err := net.ResolveUDPAddr("udp4", "localhost:0") + Expect(err).ToNot(HaveOccurred()) + udpConn, err := net.ListenUDP("udp4", addr) + Expect(err).ToNot(HaveOccurred()) + conn, err := newConn(udpConn) + Expect(err).ToNot(HaveOccurred()) + _ = conn.Close() + }) +})