magicsock: set the don't fragment sockopt (#8715)
This sets the Don't Fragment flag, for now behind the TS_DEBUG_ENABLE_PMTUD envknob. Updates #311. Signed-off-by: Val <valerie@tailscale.com> Signed-off-by: salman <salman@tailscale.com>main
parent
16bc9350e3
commit
99e06d3544
@ -0,0 +1,35 @@ |
||||
// Copyright (c) Tailscale Inc & AUTHORS
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
//go:build darwin && !ios
|
||||
|
||||
package magicsock |
||||
|
||||
import ( |
||||
"net" |
||||
"syscall" |
||||
|
||||
"golang.org/x/sys/unix" |
||||
"tailscale.com/types/nettype" |
||||
) |
||||
|
||||
func setDontFragment(pconn nettype.PacketConn, network string) (err error) { |
||||
if c, ok := pconn.(*net.UDPConn); ok { |
||||
rc, err := c.SyscallConn() |
||||
if err == nil { |
||||
rc.Control(func(fd uintptr) { |
||||
if network == "udp4" { |
||||
err = syscall.SetsockoptInt(int(fd), syscall.IPPROTO_IP, unix.IP_DONTFRAG, 1) |
||||
} |
||||
if network == "udp6" { |
||||
err = syscall.SetsockoptInt(int(fd), syscall.IPPROTO_IPV6, unix.IPV6_DONTFRAG, 1) |
||||
} |
||||
}) |
||||
} |
||||
} |
||||
return err |
||||
} |
||||
|
||||
func CanPMTUD() bool { |
||||
return debugPMTUD() // only if the envknob is for now.
|
||||
} |
||||
@ -0,0 +1,24 @@ |
||||
// Copyright (c) Tailscale Inc & AUTHORS
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
//go:build (!linux && !darwin) || android || ios
|
||||
|
||||
package magicsock |
||||
|
||||
import ( |
||||
"errors" |
||||
|
||||
"tailscale.com/types/nettype" |
||||
) |
||||
|
||||
// setDontFragment sets the dontfragment sockopt on pconn on the platforms that support it,
|
||||
// for both IPv4 and IPv6.
|
||||
// (C.f. https://datatracker.ietf.org/doc/html/rfc3542#section-11.2 for IPv6 fragmentation)
|
||||
func setDontFragment(pconn nettype.PacketConn, network string) (err error) { |
||||
return errors.New("setting don't fragment bit not supported on this OS") |
||||
} |
||||
|
||||
// CanPMTUD returns whether this platform supports performing peet path MTU discovery.
|
||||
func CanPMTUD() bool { |
||||
return false |
||||
} |
||||
@ -0,0 +1,34 @@ |
||||
// Copyright (c) Tailscale Inc & AUTHORS
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
//go:build linux && !android
|
||||
|
||||
package magicsock |
||||
|
||||
import ( |
||||
"net" |
||||
"syscall" |
||||
|
||||
"tailscale.com/types/nettype" |
||||
) |
||||
|
||||
func setDontFragment(pconn nettype.PacketConn, network string) (err error) { |
||||
if c, ok := pconn.(*net.UDPConn); ok { |
||||
rc, err := c.SyscallConn() |
||||
if err == nil { |
||||
rc.Control(func(fd uintptr) { |
||||
if network == "udp4" { |
||||
err = syscall.SetsockoptInt(int(fd), syscall.IPPROTO_IP, syscall.IP_MTU_DISCOVER, syscall.IP_PMTUDISC_DO) |
||||
} |
||||
if network == "udp6" { |
||||
err = syscall.SetsockoptInt(int(fd), syscall.IPPROTO_IPV6, syscall.IP_MTU_DISCOVER, syscall.IP_PMTUDISC_DO) |
||||
} |
||||
}) |
||||
} |
||||
} |
||||
return err |
||||
} |
||||
|
||||
func CanPMTUD() bool { |
||||
return debugPMTUD() // only if the envknob is enabled, for now.
|
||||
} |
||||
Loading…
Reference in new issue