From ebc630c6c098d208ccc8ea328741f1dc4530e733 Mon Sep 17 00:00:00 2001 From: Denton Gentry Date: Sun, 19 Mar 2023 06:37:07 -0700 Subject: [PATCH] net/interfaces: also allow link-local for AzureAppServices. In May 2021, Azure App Services used 172.16.x.x addresses: ``` 10: eth0@if11: mtu 1500 qdisc noqueue state UP link/ether 02:42:ac:10:01:03 brd ff:ff:ff:ff:ff:ff inet 172.16.1.3/24 brd 172.16.1.255 scope global eth0 valid_lft forever preferred_lft forever ``` Now it uses link-local: ``` 2: eth0@if6: mtu 1500 qdisc noqueue state UP link/ether 8a:30:1f:50:1d:23 brd ff:ff:ff:ff:ff:ff inet 169.254.129.3/24 brd 169.254.129.255 scope global eth0 valid_lft forever preferred_lft forever ``` This is reasonable for them to choose to do, it just broke the handling in net/interfaces. This PR proposes to: 1. Always allow link-local in LocalAddresses() if we have no better address available. 2. Continue to make isUsableV4() conditional on an environment we know requires it. I don't love the idea of having to discover these environments one by one, but I don't understand the consequences of making isUsableV4() return true unconditionally. It makes isUsableV4() essentially always return true and perform no function. Fixes https://github.com/tailscale/tailscale/issues/7603 Signed-off-by: Denton Gentry --- net/interfaces/interfaces.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/net/interfaces/interfaces.go b/net/interfaces/interfaces.go index f8f815bd8..fbde96190 100644 --- a/net/interfaces/interfaces.go +++ b/net/interfaces/interfaces.go @@ -153,11 +153,9 @@ func LocalAddresses() (regular, loopback []netip.Addr, err error) { if len(regular4) == 0 && len(regular6) == 0 { // if we have no usable IP addresses then be willing to accept // addresses we otherwise wouldn't, like: - // + 169.254.x.x (AWS Lambda uses NAT with these) + // + 169.254.x.x (AWS Lambda and Azure App Services use NAT with these) // + IPv6 ULA (Google Cloud Run uses these with address translation) - if hostinfo.GetEnvType() == hostinfo.AWSLambda { - regular4 = linklocal4 - } + regular4 = linklocal4 regular6 = ula6 } regular = append(regular4, regular6...) @@ -645,7 +643,14 @@ func isUsableV4(ip netip.Addr) bool { return false } if ip.IsLinkLocalUnicast() { - return hostinfo.GetEnvType() == hostinfo.AWSLambda + switch hostinfo.GetEnvType() { + case hostinfo.AWSLambda: + return true + case hostinfo.AzureAppService: + return true + default: + return false + } } return true }