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"
@ -122,6 +123,7 @@ type firewallTweaker struct {
logf logger.Logf logf logger.Logf
mu sync.Mutex mu sync.Mutex
didProcRule bool
running bool // doAsyncSet goroutine is running running bool // doAsyncSet goroutine is running
known bool // firewall is in known state (in lastVal) known bool // firewall is in known state (in lastVal)
want []string // next value we want, or "" to delete the firewall rule want []string // next value we want, or "" to delete the firewall rule
@ -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