mirror of
https://github.com/tailscale/tailscale.git
synced 2025-02-19 19:38:40 +00:00
net/tstun: don't exec uname -r on Linux in TUN failure diagnostics
Fixes https://twitter.com/zekjur/status/1425557520513486848 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
parent
e804ab29fd
commit
833200da6f
@ -8,6 +8,8 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"strings"
|
||||||
|
"syscall"
|
||||||
|
|
||||||
"tailscale.com/types/logger"
|
"tailscale.com/types/logger"
|
||||||
"tailscale.com/version/distro"
|
"tailscale.com/version/distro"
|
||||||
@ -18,12 +20,13 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func diagnoseLinuxTUNFailure(tunName string, logf logger.Logf) {
|
func diagnoseLinuxTUNFailure(tunName string, logf logger.Logf) {
|
||||||
kernel, err := exec.Command("uname", "-r").Output()
|
var un syscall.Utsname
|
||||||
kernel = bytes.TrimSpace(kernel)
|
err := syscall.Uname(&un)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logf("no TUN, and failed to look up kernel version: %v", err)
|
logf("no TUN, and failed to look up kernel version: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
kernel := utsField(&un.Release)
|
||||||
logf("Linux kernel version: %s", kernel)
|
logf("Linux kernel version: %s", kernel)
|
||||||
|
|
||||||
modprobeOut, err := exec.Command("/sbin/modprobe", "tun").CombinedOutput()
|
modprobeOut, err := exec.Command("/sbin/modprobe", "tun").CombinedOutput()
|
||||||
@ -55,7 +58,7 @@ func diagnoseLinuxTUNFailure(tunName string, logf logger.Logf) {
|
|||||||
logf("tun module not loaded nor found on disk")
|
logf("tun module not loaded nor found on disk")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if !bytes.Contains(dpkgOut, kernel) {
|
if !bytes.Contains(dpkgOut, []byte(kernel)) {
|
||||||
logf("kernel/drivers/net/tun.ko found on disk, but not for current kernel; are you in middle of a system update and haven't rebooted? found: %s", dpkgOut)
|
logf("kernel/drivers/net/tun.ko found on disk, but not for current kernel; are you in middle of a system update and haven't rebooted? found: %s", dpkgOut)
|
||||||
}
|
}
|
||||||
case distro.Arch:
|
case distro.Arch:
|
||||||
@ -64,7 +67,7 @@ func diagnoseLinuxTUNFailure(tunName string, logf logger.Logf) {
|
|||||||
logf("tun module not loaded nor found on disk")
|
logf("tun module not loaded nor found on disk")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if !bytes.Contains(findOut, kernel) {
|
if !bytes.Contains(findOut, []byte(kernel)) {
|
||||||
logf("kernel/drivers/net/tun.ko found on disk, but not for current kernel; are you in middle of a system update and haven't rebooted? found: %s", findOut)
|
logf("kernel/drivers/net/tun.ko found on disk, but not for current kernel; are you in middle of a system update and haven't rebooted? found: %s", findOut)
|
||||||
}
|
}
|
||||||
case distro.OpenWrt:
|
case distro.OpenWrt:
|
||||||
@ -80,3 +83,14 @@ func diagnoseLinuxTUNFailure(tunName string, logf logger.Logf) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func utsField(p *[65]int8) string {
|
||||||
|
var sb strings.Builder
|
||||||
|
for _, v := range p {
|
||||||
|
if v == 0 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
sb.WriteByte(byte(v))
|
||||||
|
}
|
||||||
|
return strings.TrimSpace(sb.String())
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user