From 1a629a4715d740959556d472dc8a9db843fe3257 Mon Sep 17 00:00:00 2001 From: Josh Bleecher Snyder Date: Mon, 22 Nov 2021 10:27:56 -0800 Subject: [PATCH] net/portmapper: mark fewer PMP probe failures as unexpected There are lots of lines in the logs of the form: portmapper: unexpected PMP probe response: {OpCode:128 ResultCode:3 SecondsSinceEpoch:NNN MappingValidSeconds:0 InternalPort:0 ExternalPort:0 PublicAddr:0.0.0.0} ResultCode 3 here means a network failure, e.g. the NAT box itself has not obtained a DHCP lease. This is not an indication that something is wrong in the Tailscale client, so use different wording here to reflect that. Keep logging, so that we can analyze and debug the reasons that PMP probes fail. Signed-off-by: Josh Bleecher Snyder --- net/portmapper/portmapper.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/net/portmapper/portmapper.go b/net/portmapper/portmapper.go index cf4227b0c..a2f98b2a2 100644 --- a/net/portmapper/portmapper.go +++ b/net/portmapper/portmapper.go @@ -798,7 +798,12 @@ func (c *Client) Probe(ctx context.Context) (res ProbeResult, err error) { c.logf("unexpected PCP probe response: %+v", pres) } if pres, ok := parsePMPResponse(buf[:n]); ok { - if pres.OpCode == pmpOpReply|pmpOpMapPublicAddr && pres.ResultCode == pmpCodeOK { + if pres.OpCode != pmpOpReply|pmpOpMapPublicAddr { + c.logf("unexpected PMP probe response opcode: %+v", pres) + continue + } + switch pres.ResultCode { + case pmpCodeOK: c.logf("[v1] Got PMP response; IP: %v, epoch: %v", pres.PublicAddr, pres.SecondsSinceEpoch) res.PMP = true c.mu.Lock() @@ -807,6 +812,10 @@ func (c *Client) Probe(ctx context.Context) (res ProbeResult, err error) { c.pmpLastEpoch = pres.SecondsSinceEpoch c.mu.Unlock() continue + case pmpCodeNotAuthorized, pmpCodeNetworkFailure, pmpCodeOutOfResources: + // Normal failures. + c.logf("PMP probe failed due result code: %+v", pres) + continue } c.logf("unexpected PMP probe response: %+v", pres) }