From 765695eaa2861f9b5e8b3efab02a0646d0381787 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Fri, 29 May 2020 22:40:26 -0700 Subject: [PATCH] net/netns: also don't err on tailscaled -fake as a regular user That's one of my dev workflows. --- net/netns/netns_linux.go | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/net/netns/netns_linux.go b/net/netns/netns_linux.go index e2b738884..30c6775b6 100644 --- a/net/netns/netns_linux.go +++ b/net/netns/netns_linux.go @@ -38,11 +38,22 @@ func control(network, address string, c syscall.RawConn) error { err := c.Control(func(fd uintptr) { controlErr = unix.SetsockoptInt(int(fd), unix.SOL_SOCKET, unix.SO_MARK, tailscaleBypassMark) }) - // Before returning some fatal error, see if we're just a regular user - // running cmd/tailscale (presumably netcheck) and ignore the error if so. + // Before returning some fatal error, skip it in some cases. if (err != nil || controlErr != nil) && os.Getuid() != 0 { - if v, _ := os.Executable(); filepath.Base(v) == "tailscale" { - return nil + v, _ := os.Executable() + switch filepath.Base(v) { + case "tailscale": + for _, arg := range os.Args { + if arg == "netcheck" { + return nil + } + } + case "tailscaled": + for _, arg := range os.Args { + if arg == "-fake" || arg == "--fake" { + return nil + } + } } } if err != nil {