From 1db9032ff5dfd96e6bd2e1064226065d79d40561 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Tue, 3 Aug 2021 19:33:17 -0700 Subject: [PATCH] cmd/tailscaled: let portmap debug mode have an gateway/IP override knob For testing pfSense clients "behind" pfSense on Digital Ocean where the main interface still exists. This is easier for debugging. Signed-off-by: Brad Fitzpatrick --- cmd/tailscaled/debug.go | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/cmd/tailscaled/debug.go b/cmd/tailscaled/debug.go index 7a674a32a..bf9842eed 100644 --- a/cmd/tailscaled/debug.go +++ b/cmd/tailscaled/debug.go @@ -19,8 +19,10 @@ import ( "net/http/httptrace" "net/url" "os" + "strings" "time" + "inet.af/netaddr" "tailscale.com/derp/derphttp" "tailscale.com/ipn" "tailscale.com/net/interfaces" @@ -226,7 +228,25 @@ func debugPortmap(ctx context.Context) error { if err != nil { return err } - c.SetGatewayLookupFunc(linkMon.GatewayAndSelfIP) + + gatewayAndSelfIP := func() (gw, self netaddr.IP, ok bool) { + if v := os.Getenv("TS_DEBUG_GW_SELF"); strings.Contains(v, "/") { + i := strings.Index(v, "/") + gw = netaddr.MustParseIP(v[:i]) + self = netaddr.MustParseIP(v[i+1:]) + return gw, self, true + } + return linkMon.GatewayAndSelfIP() + } + + c.SetGatewayLookupFunc(gatewayAndSelfIP) + + gw, selfIP, ok := gatewayAndSelfIP() + if !ok { + logf("no gateway or self IP; %v", linkMon.InterfaceState()) + return nil + } + logf("gw=%v; self=%v", gw, selfIP) res, err := c.Probe(ctx) if err != nil {