wgengine/router: add another Windows firewall rule to allow incoming UDP

Based on @sailorfrag's research.

Fixes #1312

Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
pull/1321/head
Brad Fitzpatrick 4 years ago committed by Brad Fitzpatrick
parent 7e201806b1
commit 1ec64bc94d

@ -7,6 +7,7 @@ package router
import ( import (
"context" "context"
"fmt" "fmt"
"os"
"os/exec" "os/exec"
"sync" "sync"
"syscall" "syscall"
@ -121,11 +122,12 @@ func cleanup(logf logger.Logf, interfaceName string) {
type firewallTweaker struct { type firewallTweaker struct {
logf logger.Logf logf logger.Logf
mu sync.Mutex mu sync.Mutex
running bool // doAsyncSet goroutine is running didProcRule bool
known bool // firewall is in known state (in lastVal) running bool // doAsyncSet goroutine is running
want []string // next value we want, or "" to delete the firewall rule known bool // firewall is in known state (in lastVal)
lastVal []string // last set value, if known want []string // next value we want, or "" to delete the firewall rule
lastVal []string // last set value, if known
} }
func (ft *firewallTweaker) clear() { ft.set(nil) } func (ft *firewallTweaker) clear() { ft.set(nil) }
@ -177,6 +179,7 @@ func (ft *firewallTweaker) doAsyncSet() {
return return
} }
needClear := !ft.known || len(ft.lastVal) > 0 || len(val) == 0 needClear := !ft.known || len(ft.lastVal) > 0 || len(val) == 0
needProcRule := !ft.didProcRule
ft.mu.Unlock() ft.mu.Unlock()
if needClear { if needClear {
@ -189,6 +192,37 @@ func (ft *firewallTweaker) doAsyncSet() {
d, _ := ft.runFirewall("delete", "rule", "name=Tailscale-In", "dir=in") d, _ := ft.runFirewall("delete", "rule", "name=Tailscale-In", "dir=in")
ft.logf("cleared Tailscale-In firewall rules in %v", d) ft.logf("cleared Tailscale-In firewall rules in %v", d)
} }
if needProcRule {
ft.logf("deleting any prior Tailscale-Process rule...")
d, err := ft.runFirewall("delete", "rule", "name=Tailscale-Process", "dir=in") // best effort
if err == nil {
ft.logf("removed old Tailscale-Process rule in %v", d)
}
var exe string
exe, err = os.Executable()
if err != nil {
ft.logf("failed to find Executable for Tailscale-Process rule: %v", err)
} else {
ft.logf("adding Tailscale-Process rule to allow UDP for %q ...", exe)
d, err = ft.runFirewall("add", "rule", "name=Tailscale-Process",
"dir=in",
"action=allow",
"edge=yes",
"program="+exe,
"protocol=udp",
"profile=any",
"enable=yes",
)
if err != nil {
ft.logf("error adding Tailscale-Process rule: %v", err)
} else {
ft.mu.Lock()
ft.didProcRule = true
ft.mu.Unlock()
ft.logf("added Tailscale-Process rule in %v", d)
}
}
}
var err error var err error
for _, cidr := range val { for _, cidr := range val {
ft.logf("adding Tailscale-In rule to allow %v ...", cidr) ft.logf("adding Tailscale-In rule to allow %v ...", cidr)

Loading…
Cancel
Save