net/tstun: diagnose /dev/net/tun fd leak, give better failure message

Updates #5029

Change-Id: Ibee5e0c9076fe764eb5d856d5ef8b09f4d0e2921
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
Brad Fitzpatrick
2022-07-16 14:10:20 -07:00
committed by Brad Fitzpatrick
parent 931f18b575
commit 0d52674a84
4 changed files with 17 additions and 6 deletions

View File

@@ -6,6 +6,7 @@ package tstun
import (
"bytes"
"errors"
"os"
"os/exec"
"strings"
@@ -19,7 +20,14 @@ func init() {
tunDiagnoseFailure = diagnoseLinuxTUNFailure
}
func diagnoseLinuxTUNFailure(tunName string, logf logger.Logf) {
func diagnoseLinuxTUNFailure(tunName string, logf logger.Logf, createErr error) {
if errors.Is(createErr, syscall.EBUSY) {
logf("TUN device %s is busy; another process probably still has it open (from old version of Tailscale that had a bug)", tunName)
logf("To fix, kill the process that has it open. Find with:\n\n$ sudo lsof -n /dev/net/tun\n\n")
logf("... and then kill those PID(s)")
return
}
var un syscall.Utsname
err := syscall.Uname(&un)
if err != nil {