2023-08-11 09:34:51 +01:00
|
|
|
// 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" {
|
2023-09-14 16:49:53 +01:00
|
|
|
err = syscall.SetsockoptInt(int(fd), syscall.IPPROTO_IPV6, syscall.IPV6_MTU_DISCOVER, syscall.IP_PMTUDISC_DO)
|
2023-08-11 09:34:51 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
func CanPMTUD() bool {
|
2023-09-13 15:18:35 +01:00
|
|
|
return debugEnablePMTUD() // only if the envknob is enabled, for now.
|
2023-08-11 09:34:51 +01:00
|
|
|
}
|