mirror of
https://github.com/tailscale/tailscale.git
synced 2024-11-26 03:25:35 +00:00
7b73c9628d
WSL has started to set the eth0 default route interface default to 1280 MTU, which is too low to carry 1280 byte packets from tailscale0 once wrapped in WireGuard. The change down to 1280 is very likely smaller than necessary for almost all users. We can not easily determine the ideal MTU, but if all the preconditions match, we raise the MTU to 1360, which is just enough for Tailscale traffic to work. Updates #4833 Updates #7346 Signed-off-by: James Tucker <james@tailscale.com>
144 lines
3.2 KiB
Go
144 lines
3.2 KiB
Go
// Copyright (c) Tailscale Inc & AUTHORS
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
// Package distro reports which distro we're running on.
|
|
package distro
|
|
|
|
import (
|
|
"bytes"
|
|
"io"
|
|
"os"
|
|
"runtime"
|
|
"strconv"
|
|
|
|
"tailscale.com/types/lazy"
|
|
"tailscale.com/util/lineread"
|
|
)
|
|
|
|
type Distro string
|
|
|
|
const (
|
|
Debian = Distro("debian")
|
|
Arch = Distro("arch")
|
|
Synology = Distro("synology")
|
|
OpenWrt = Distro("openwrt")
|
|
NixOS = Distro("nixos")
|
|
QNAP = Distro("qnap")
|
|
Pfsense = Distro("pfsense")
|
|
OPNsense = Distro("opnsense")
|
|
TrueNAS = Distro("truenas")
|
|
Gokrazy = Distro("gokrazy")
|
|
WDMyCloud = Distro("wdmycloud")
|
|
)
|
|
|
|
var distro lazy.SyncValue[Distro]
|
|
var isWSL lazy.SyncValue[bool]
|
|
|
|
// Get returns the current distro, or the empty string if unknown.
|
|
func Get() Distro {
|
|
return distro.Get(func() Distro {
|
|
switch runtime.GOOS {
|
|
case "linux":
|
|
return linuxDistro()
|
|
case "freebsd":
|
|
return freebsdDistro()
|
|
default:
|
|
return Distro("")
|
|
}
|
|
})
|
|
}
|
|
|
|
// IsWSL reports whether we're running in the Windows Subsystem for Linux.
|
|
func IsWSL() bool {
|
|
return runtime.GOOS == "linux" && isWSL.Get(func() bool {
|
|
// We could look for $WSL_INTEROP instead, however that may be missing if
|
|
// the user has started to use systemd in WSL2.
|
|
return have("/proc/sys/fs/binfmt_misc/WSLInterop") || have("/mnt/wsl")
|
|
})
|
|
}
|
|
|
|
func have(file string) bool {
|
|
_, err := os.Stat(file)
|
|
return err == nil
|
|
}
|
|
|
|
func haveDir(file string) bool {
|
|
fi, err := os.Stat(file)
|
|
return err == nil && fi.IsDir()
|
|
}
|
|
|
|
func linuxDistro() Distro {
|
|
switch {
|
|
case haveDir("/usr/syno"):
|
|
return Synology
|
|
case have("/usr/local/bin/freenas-debug"):
|
|
// TrueNAS Scale runs on debian
|
|
return TrueNAS
|
|
case have("/etc/debian_version"):
|
|
return Debian
|
|
case have("/etc/arch-release"):
|
|
return Arch
|
|
case have("/etc/openwrt_version"):
|
|
return OpenWrt
|
|
case have("/run/current-system/sw/bin/nixos-version"):
|
|
return NixOS
|
|
case have("/etc/config/uLinux.conf"):
|
|
return QNAP
|
|
case haveDir("/gokrazy"):
|
|
return Gokrazy
|
|
case have("/usr/local/wdmcserver/bin/wdmc.xml"): // Western Digital MyCloud OS3
|
|
return WDMyCloud
|
|
case have("/usr/sbin/wd_crontab.sh"): // Western Digital MyCloud OS5
|
|
return WDMyCloud
|
|
}
|
|
return ""
|
|
}
|
|
|
|
func freebsdDistro() Distro {
|
|
switch {
|
|
case have("/etc/pfSense-rc"):
|
|
return Pfsense
|
|
case have("/usr/local/sbin/opnsense-shell"):
|
|
return OPNsense
|
|
case have("/usr/local/bin/freenas-debug"):
|
|
// TrueNAS Core runs on FreeBSD
|
|
return TrueNAS
|
|
}
|
|
return ""
|
|
}
|
|
|
|
var dsmVersion lazy.SyncValue[int]
|
|
|
|
// DSMVersion reports the Synology DSM major version.
|
|
//
|
|
// If not Synology, it reports 0.
|
|
func DSMVersion() int {
|
|
if runtime.GOOS != "linux" {
|
|
return 0
|
|
}
|
|
return dsmVersion.Get(func() int {
|
|
if Get() != Synology {
|
|
return 0
|
|
}
|
|
// This is set when running as a package:
|
|
v, _ := strconv.Atoi(os.Getenv("SYNOPKG_DSM_VERSION_MAJOR"))
|
|
if v != 0 {
|
|
return v
|
|
}
|
|
// But when run from the command line, we have to read it from the file:
|
|
lineread.File("/etc/VERSION", func(line []byte) error {
|
|
line = bytes.TrimSpace(line)
|
|
if string(line) == `majorversion="7"` {
|
|
v = 7
|
|
return io.EOF
|
|
}
|
|
if string(line) == `majorversion="6"` {
|
|
v = 6
|
|
return io.EOF
|
|
}
|
|
return nil
|
|
})
|
|
return v
|
|
})
|
|
}
|