2023-01-27 21:37:20 +00:00
|
|
|
// Copyright (c) Tailscale Inc & AUTHORS
|
|
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
2020-02-21 16:13:21 +00:00
|
|
|
|
|
|
|
// Package interfaces contains helpers for looking up system network interfaces.
|
|
|
|
package interfaces
|
|
|
|
|
|
|
|
import (
|
2021-03-26 16:09:12 +00:00
|
|
|
"bytes"
|
2020-03-27 20:26:35 +00:00
|
|
|
"fmt"
|
2020-02-21 16:13:21 +00:00
|
|
|
"net"
|
2020-08-13 22:25:54 +00:00
|
|
|
"net/http"
|
2022-07-26 03:55:44 +00:00
|
|
|
"net/netip"
|
2021-01-26 23:14:59 +00:00
|
|
|
"runtime"
|
2023-08-23 18:48:05 +00:00
|
|
|
"slices"
|
2020-10-02 19:07:00 +00:00
|
|
|
"sort"
|
2020-02-21 16:13:21 +00:00
|
|
|
"strings"
|
2020-05-28 16:58:52 +00:00
|
|
|
|
2023-12-19 21:27:52 +00:00
|
|
|
"tailscale.com/envknob"
|
2021-06-15 20:42:18 +00:00
|
|
|
"tailscale.com/hostinfo"
|
2022-07-25 03:08:42 +00:00
|
|
|
"tailscale.com/net/netaddr"
|
2020-07-07 05:33:29 +00:00
|
|
|
"tailscale.com/net/tsaddr"
|
2020-08-13 22:25:54 +00:00
|
|
|
"tailscale.com/net/tshttpproxy"
|
2020-02-21 16:13:21 +00:00
|
|
|
)
|
|
|
|
|
2020-08-13 22:25:54 +00:00
|
|
|
// LoginEndpointForProxyDetermination is the URL used for testing
|
|
|
|
// which HTTP proxy the system should use.
|
2021-06-25 14:05:46 +00:00
|
|
|
var LoginEndpointForProxyDetermination = "https://controlplane.tailscale.com/"
|
2020-08-13 22:25:54 +00:00
|
|
|
|
2020-03-02 18:38:44 +00:00
|
|
|
func isUp(nif *net.Interface) bool { return nif.Flags&net.FlagUp != 0 }
|
|
|
|
func isLoopback(nif *net.Interface) bool { return nif.Flags&net.FlagLoopback != 0 }
|
|
|
|
|
2021-01-26 23:14:59 +00:00
|
|
|
func isProblematicInterface(nif *net.Interface) bool {
|
|
|
|
name := nif.Name
|
|
|
|
// Don't try to send disco/etc packets over zerotier; they effectively
|
|
|
|
// DoS each other by doing traffic amplification, both of them
|
|
|
|
// preferring/trying to use each other for transport. See:
|
|
|
|
// https://github.com/tailscale/tailscale/issues/1208
|
|
|
|
if strings.HasPrefix(name, "zt") || (runtime.GOOS == "windows" && strings.Contains(name, "ZeroTier")) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2020-03-02 18:38:44 +00:00
|
|
|
// LocalAddresses returns the machine's IP addresses, separated by
|
2021-06-15 20:42:18 +00:00
|
|
|
// whether they're loopback addresses. If there are no regular addresses
|
|
|
|
// it will return any IPv4 linklocal or IPv6 unique local addresses because we
|
|
|
|
// know of environments where these are used with NAT to provide connectivity.
|
all: convert more code to use net/netip directly
perl -i -npe 's,netaddr.IPPrefixFrom,netip.PrefixFrom,' $(git grep -l -F netaddr.)
perl -i -npe 's,netaddr.IPPortFrom,netip.AddrPortFrom,' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPrefix,netip.Prefix,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPort,netip.AddrPort,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IP\b,netip.Addr,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPv6Raw\b,netip.AddrFrom16,g' $(git grep -l -F netaddr. )
goimports -w .
Then delete some stuff from the net/netaddr shim package which is no
longer neeed.
Updates #5162
Change-Id: Ia7a86893fe21c7e3ee1ec823e8aba288d4566cd8
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2022-07-26 04:14:09 +00:00
|
|
|
func LocalAddresses() (regular, loopback []netip.Addr, err error) {
|
2020-03-02 18:38:44 +00:00
|
|
|
// TODO(crawshaw): don't serve interface addresses that we are routing
|
2021-10-04 16:33:33 +00:00
|
|
|
ifaces, err := netInterfaces()
|
2020-03-02 18:38:44 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
all: convert more code to use net/netip directly
perl -i -npe 's,netaddr.IPPrefixFrom,netip.PrefixFrom,' $(git grep -l -F netaddr.)
perl -i -npe 's,netaddr.IPPortFrom,netip.AddrPortFrom,' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPrefix,netip.Prefix,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPort,netip.AddrPort,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IP\b,netip.Addr,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPv6Raw\b,netip.AddrFrom16,g' $(git grep -l -F netaddr. )
goimports -w .
Then delete some stuff from the net/netaddr shim package which is no
longer neeed.
Updates #5162
Change-Id: Ia7a86893fe21c7e3ee1ec823e8aba288d4566cd8
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2022-07-26 04:14:09 +00:00
|
|
|
var regular4, regular6, linklocal4, ula6 []netip.Addr
|
2021-10-04 16:33:33 +00:00
|
|
|
for _, iface := range ifaces {
|
|
|
|
stdIf := iface.Interface
|
|
|
|
if !isUp(stdIf) || isProblematicInterface(stdIf) {
|
2021-01-26 23:14:59 +00:00
|
|
|
// Skip down interfaces and ones that are
|
|
|
|
// problematic that we don't want to try to
|
|
|
|
// send Tailscale traffic over.
|
2020-03-02 18:38:44 +00:00
|
|
|
continue
|
|
|
|
}
|
2021-10-04 16:33:33 +00:00
|
|
|
ifcIsLoopback := isLoopback(stdIf)
|
2020-03-02 18:38:44 +00:00
|
|
|
|
|
|
|
addrs, err := iface.Addrs()
|
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
for _, a := range addrs {
|
|
|
|
switch v := a.(type) {
|
|
|
|
case *net.IPNet:
|
2022-08-02 20:38:11 +00:00
|
|
|
ip, ok := netip.AddrFromSlice(v.IP)
|
2020-05-28 16:58:52 +00:00
|
|
|
if !ok {
|
|
|
|
continue
|
|
|
|
}
|
2022-08-02 20:38:11 +00:00
|
|
|
ip = ip.Unmap()
|
2020-03-02 18:38:44 +00:00
|
|
|
// TODO(apenwarr): don't special case cgNAT.
|
|
|
|
// In the general wireguard case, it might
|
|
|
|
// very well be something we can route to
|
|
|
|
// directly, because both nodes are
|
|
|
|
// behind the same CGNAT router.
|
2020-07-07 05:33:29 +00:00
|
|
|
if tsaddr.IsTailscaleIP(ip) {
|
2020-03-02 18:38:44 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
if ip.IsLoopback() || ifcIsLoopback {
|
2021-03-04 06:02:45 +00:00
|
|
|
loopback = append(loopback, ip)
|
2021-06-15 20:42:18 +00:00
|
|
|
} else if ip.IsLinkLocalUnicast() {
|
|
|
|
if ip.Is4() {
|
|
|
|
linklocal4 = append(linklocal4, ip)
|
|
|
|
}
|
|
|
|
|
|
|
|
// We know of no cases where the IPv6 fe80:: addresses
|
|
|
|
// are used to provide WAN connectivity. It is also very
|
|
|
|
// common for users to have no IPv6 WAN connectivity,
|
|
|
|
// but their OS supports IPv6 so they have an fe80::
|
|
|
|
// address. We don't want to report all of those
|
|
|
|
// IPv6 LL to Control.
|
2021-07-28 18:23:43 +00:00
|
|
|
} else if ip.Is6() && ip.IsPrivate() {
|
2021-06-15 20:42:18 +00:00
|
|
|
// Google Cloud Run uses NAT with IPv6 Unique
|
|
|
|
// Local Addresses to provide IPv6 connectivity.
|
|
|
|
ula6 = append(ula6, ip)
|
2020-03-02 18:38:44 +00:00
|
|
|
} else {
|
2021-06-15 20:42:18 +00:00
|
|
|
if ip.Is4() {
|
|
|
|
regular4 = append(regular4, ip)
|
|
|
|
} else {
|
|
|
|
regular6 = append(regular6, ip)
|
|
|
|
}
|
2020-03-02 18:38:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-06-15 20:42:18 +00:00
|
|
|
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:
|
net/interfaces: also allow link-local for AzureAppServices.
In May 2021, Azure App Services used 172.16.x.x addresses:
```
10: eth0@if11: <BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN> 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: <BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN> 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 <dgentry@tailscale.com>
2023-03-19 13:37:07 +00:00
|
|
|
// + 169.254.x.x (AWS Lambda and Azure App Services use NAT with these)
|
2021-06-15 20:42:18 +00:00
|
|
|
// + IPv6 ULA (Google Cloud Run uses these with address translation)
|
net/interfaces: also allow link-local for AzureAppServices.
In May 2021, Azure App Services used 172.16.x.x addresses:
```
10: eth0@if11: <BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN> 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: <BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN> 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 <dgentry@tailscale.com>
2023-03-19 13:37:07 +00:00
|
|
|
regular4 = linklocal4
|
2021-06-15 20:42:18 +00:00
|
|
|
regular6 = ula6
|
|
|
|
}
|
|
|
|
regular = append(regular4, regular6...)
|
2021-03-04 06:02:45 +00:00
|
|
|
sortIPs(regular)
|
|
|
|
sortIPs(loopback)
|
2020-03-02 18:38:44 +00:00
|
|
|
return regular, loopback, nil
|
|
|
|
}
|
|
|
|
|
all: convert more code to use net/netip directly
perl -i -npe 's,netaddr.IPPrefixFrom,netip.PrefixFrom,' $(git grep -l -F netaddr.)
perl -i -npe 's,netaddr.IPPortFrom,netip.AddrPortFrom,' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPrefix,netip.Prefix,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPort,netip.AddrPort,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IP\b,netip.Addr,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPv6Raw\b,netip.AddrFrom16,g' $(git grep -l -F netaddr. )
goimports -w .
Then delete some stuff from the net/netaddr shim package which is no
longer neeed.
Updates #5162
Change-Id: Ia7a86893fe21c7e3ee1ec823e8aba288d4566cd8
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2022-07-26 04:14:09 +00:00
|
|
|
func sortIPs(s []netip.Addr) {
|
2021-03-04 06:02:45 +00:00
|
|
|
sort.Slice(s, func(i, j int) bool { return s[i].Less(s[j]) })
|
|
|
|
}
|
|
|
|
|
2020-03-10 18:02:30 +00:00
|
|
|
// Interface is a wrapper around Go's net.Interface with some extra methods.
|
|
|
|
type Interface struct {
|
|
|
|
*net.Interface
|
2021-10-04 16:33:33 +00:00
|
|
|
AltAddrs []net.Addr // if non-nil, returned by Addrs
|
2021-12-29 18:37:33 +00:00
|
|
|
Desc string // extra description (used on Windows)
|
2020-03-10 18:02:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (i Interface) IsLoopback() bool { return isLoopback(i.Interface) }
|
|
|
|
func (i Interface) IsUp() bool { return isUp(i.Interface) }
|
2021-10-04 16:33:33 +00:00
|
|
|
func (i Interface) Addrs() ([]net.Addr, error) {
|
|
|
|
if i.AltAddrs != nil {
|
|
|
|
return i.AltAddrs, nil
|
|
|
|
}
|
|
|
|
return i.Interface.Addrs()
|
|
|
|
}
|
2020-03-10 18:02:30 +00:00
|
|
|
|
2021-10-14 21:55:55 +00:00
|
|
|
// ForeachInterfaceAddress is a wrapper for GetList, then
|
|
|
|
// List.ForeachInterfaceAddress.
|
all: convert more code to use net/netip directly
perl -i -npe 's,netaddr.IPPrefixFrom,netip.PrefixFrom,' $(git grep -l -F netaddr.)
perl -i -npe 's,netaddr.IPPortFrom,netip.AddrPortFrom,' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPrefix,netip.Prefix,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPort,netip.AddrPort,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IP\b,netip.Addr,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPv6Raw\b,netip.AddrFrom16,g' $(git grep -l -F netaddr. )
goimports -w .
Then delete some stuff from the net/netaddr shim package which is no
longer neeed.
Updates #5162
Change-Id: Ia7a86893fe21c7e3ee1ec823e8aba288d4566cd8
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2022-07-26 04:14:09 +00:00
|
|
|
func ForeachInterfaceAddress(fn func(Interface, netip.Prefix)) error {
|
2021-10-14 21:55:55 +00:00
|
|
|
ifaces, err := GetList()
|
2020-03-10 18:02:30 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2021-10-14 21:55:55 +00:00
|
|
|
return ifaces.ForeachInterfaceAddress(fn)
|
|
|
|
}
|
|
|
|
|
|
|
|
// ForeachInterfaceAddress calls fn for each interface in ifaces, with
|
|
|
|
// all its addresses. The IPPrefix's IP is the IP address assigned to
|
|
|
|
// the interface, and Bits are the subnet mask.
|
all: convert more code to use net/netip directly
perl -i -npe 's,netaddr.IPPrefixFrom,netip.PrefixFrom,' $(git grep -l -F netaddr.)
perl -i -npe 's,netaddr.IPPortFrom,netip.AddrPortFrom,' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPrefix,netip.Prefix,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPort,netip.AddrPort,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IP\b,netip.Addr,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPv6Raw\b,netip.AddrFrom16,g' $(git grep -l -F netaddr. )
goimports -w .
Then delete some stuff from the net/netaddr shim package which is no
longer neeed.
Updates #5162
Change-Id: Ia7a86893fe21c7e3ee1ec823e8aba288d4566cd8
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2022-07-26 04:14:09 +00:00
|
|
|
func (ifaces List) ForeachInterfaceAddress(fn func(Interface, netip.Prefix)) error {
|
2021-10-04 16:33:33 +00:00
|
|
|
for _, iface := range ifaces {
|
2020-03-10 18:02:30 +00:00
|
|
|
addrs, err := iface.Addrs()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
for _, a := range addrs {
|
|
|
|
switch v := a.(type) {
|
|
|
|
case *net.IPNet:
|
2021-02-23 04:43:35 +00:00
|
|
|
if pfx, ok := netaddr.FromStdIPNet(v); ok {
|
2021-10-04 16:33:33 +00:00
|
|
|
fn(iface, pfx)
|
2020-05-28 16:58:52 +00:00
|
|
|
}
|
2020-03-10 18:02:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-10-14 21:55:55 +00:00
|
|
|
// ForeachInterface is a wrapper for GetList, then
|
|
|
|
// List.ForeachInterface.
|
all: convert more code to use net/netip directly
perl -i -npe 's,netaddr.IPPrefixFrom,netip.PrefixFrom,' $(git grep -l -F netaddr.)
perl -i -npe 's,netaddr.IPPortFrom,netip.AddrPortFrom,' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPrefix,netip.Prefix,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPort,netip.AddrPort,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IP\b,netip.Addr,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPv6Raw\b,netip.AddrFrom16,g' $(git grep -l -F netaddr. )
goimports -w .
Then delete some stuff from the net/netaddr shim package which is no
longer neeed.
Updates #5162
Change-Id: Ia7a86893fe21c7e3ee1ec823e8aba288d4566cd8
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2022-07-26 04:14:09 +00:00
|
|
|
func ForeachInterface(fn func(Interface, []netip.Prefix)) error {
|
2021-10-14 21:55:55 +00:00
|
|
|
ifaces, err := GetList()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return ifaces.ForeachInterface(fn)
|
|
|
|
}
|
|
|
|
|
|
|
|
// ForeachInterface calls fn for each interface in ifaces, with
|
2021-02-23 04:43:35 +00:00
|
|
|
// all its addresses. The IPPrefix's IP is the IP address assigned to
|
|
|
|
// the interface, and Bits are the subnet mask.
|
all: convert more code to use net/netip directly
perl -i -npe 's,netaddr.IPPrefixFrom,netip.PrefixFrom,' $(git grep -l -F netaddr.)
perl -i -npe 's,netaddr.IPPortFrom,netip.AddrPortFrom,' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPrefix,netip.Prefix,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPort,netip.AddrPort,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IP\b,netip.Addr,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPv6Raw\b,netip.AddrFrom16,g' $(git grep -l -F netaddr. )
goimports -w .
Then delete some stuff from the net/netaddr shim package which is no
longer neeed.
Updates #5162
Change-Id: Ia7a86893fe21c7e3ee1ec823e8aba288d4566cd8
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2022-07-26 04:14:09 +00:00
|
|
|
func (ifaces List) ForeachInterface(fn func(Interface, []netip.Prefix)) error {
|
2021-10-04 16:33:33 +00:00
|
|
|
for _, iface := range ifaces {
|
2021-02-25 23:47:29 +00:00
|
|
|
addrs, err := iface.Addrs()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
all: convert more code to use net/netip directly
perl -i -npe 's,netaddr.IPPrefixFrom,netip.PrefixFrom,' $(git grep -l -F netaddr.)
perl -i -npe 's,netaddr.IPPortFrom,netip.AddrPortFrom,' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPrefix,netip.Prefix,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPort,netip.AddrPort,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IP\b,netip.Addr,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPv6Raw\b,netip.AddrFrom16,g' $(git grep -l -F netaddr. )
goimports -w .
Then delete some stuff from the net/netaddr shim package which is no
longer neeed.
Updates #5162
Change-Id: Ia7a86893fe21c7e3ee1ec823e8aba288d4566cd8
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2022-07-26 04:14:09 +00:00
|
|
|
var pfxs []netip.Prefix
|
2021-02-25 23:47:29 +00:00
|
|
|
for _, a := range addrs {
|
|
|
|
switch v := a.(type) {
|
|
|
|
case *net.IPNet:
|
2021-02-23 04:43:35 +00:00
|
|
|
if pfx, ok := netaddr.FromStdIPNet(v); ok {
|
|
|
|
pfxs = append(pfxs, pfx)
|
2021-02-25 23:47:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-03-26 16:09:12 +00:00
|
|
|
sort.Slice(pfxs, func(i, j int) bool {
|
2022-07-25 03:08:42 +00:00
|
|
|
return pfxs[i].Addr().Less(pfxs[j].Addr())
|
2021-03-26 16:09:12 +00:00
|
|
|
})
|
2021-10-04 16:33:33 +00:00
|
|
|
fn(iface, pfxs)
|
2021-02-25 23:47:29 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-03-10 19:25:42 +00:00
|
|
|
// State is intended to store the state of the machine's network interfaces,
|
|
|
|
// routing table, and other network configuration.
|
|
|
|
// For now it's pretty basic.
|
|
|
|
type State struct {
|
2021-02-23 04:43:35 +00:00
|
|
|
// InterfaceIPs maps from an interface name to the IP addresses
|
|
|
|
// configured on that interface. Each address is represented as an
|
|
|
|
// IPPrefix, where the IP is the interface IP address and Bits is
|
|
|
|
// the subnet mask.
|
all: convert more code to use net/netip directly
perl -i -npe 's,netaddr.IPPrefixFrom,netip.PrefixFrom,' $(git grep -l -F netaddr.)
perl -i -npe 's,netaddr.IPPortFrom,netip.AddrPortFrom,' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPrefix,netip.Prefix,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPort,netip.AddrPort,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IP\b,netip.Addr,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPv6Raw\b,netip.AddrFrom16,g' $(git grep -l -F netaddr. )
goimports -w .
Then delete some stuff from the net/netaddr shim package which is no
longer neeed.
Updates #5162
Change-Id: Ia7a86893fe21c7e3ee1ec823e8aba288d4566cd8
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2022-07-26 04:14:09 +00:00
|
|
|
InterfaceIPs map[string][]netip.Prefix
|
2021-03-26 04:26:01 +00:00
|
|
|
Interface map[string]Interface
|
2020-04-10 02:10:55 +00:00
|
|
|
|
2021-06-18 00:49:15 +00:00
|
|
|
// HaveV6 is whether this machine has an IPv6 Global or Unique Local Address
|
|
|
|
// which might provide connectivity on a non-Tailscale interface that's up.
|
|
|
|
HaveV6 bool
|
2020-05-28 16:58:52 +00:00
|
|
|
|
2020-10-06 22:22:46 +00:00
|
|
|
// HaveV4 is whether the machine has some non-localhost,
|
|
|
|
// non-link-local IPv4 address on a non-Tailscale interface that's up.
|
2020-05-28 16:58:52 +00:00
|
|
|
HaveV4 bool
|
|
|
|
|
2020-04-10 02:10:55 +00:00
|
|
|
// IsExpensive is whether the current network interface is
|
|
|
|
// considered "expensive", which currently means LTE/etc
|
|
|
|
// instead of Wifi. This field is not populated by GetState.
|
|
|
|
IsExpensive bool
|
2020-08-12 19:48:34 +00:00
|
|
|
|
2021-12-29 18:37:33 +00:00
|
|
|
// DefaultRouteInterface is the interface name for the
|
|
|
|
// machine's default route.
|
|
|
|
//
|
2020-08-12 19:48:34 +00:00
|
|
|
// It is not yet populated on all OSes.
|
2021-12-29 18:37:33 +00:00
|
|
|
//
|
|
|
|
// When non-empty, its value is the map key into Interface and
|
|
|
|
// InterfaceIPs.
|
2020-08-12 19:48:34 +00:00
|
|
|
DefaultRouteInterface string
|
2020-08-13 22:25:54 +00:00
|
|
|
|
2021-12-29 18:37:33 +00:00
|
|
|
// HTTPProxy is the HTTP proxy to use, if any.
|
2020-08-13 22:25:54 +00:00
|
|
|
HTTPProxy string
|
2020-10-01 22:33:37 +00:00
|
|
|
|
|
|
|
// PAC is the URL to the Proxy Autoconfig URL, if applicable.
|
|
|
|
PAC string
|
2020-03-10 19:25:42 +00:00
|
|
|
}
|
|
|
|
|
2020-10-02 19:07:00 +00:00
|
|
|
func (s *State) String() string {
|
|
|
|
var sb strings.Builder
|
2021-12-29 18:37:33 +00:00
|
|
|
fmt.Fprintf(&sb, "interfaces.State{defaultRoute=%v ", s.DefaultRouteInterface)
|
|
|
|
if s.DefaultRouteInterface != "" {
|
|
|
|
if iface, ok := s.Interface[s.DefaultRouteInterface]; ok && iface.Desc != "" {
|
|
|
|
fmt.Fprintf(&sb, "(%s) ", iface.Desc)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sb.WriteString("ifs={")
|
2023-08-23 18:48:05 +00:00
|
|
|
var ifs []string
|
2021-03-26 04:26:01 +00:00
|
|
|
for k := range s.Interface {
|
2023-08-23 18:48:05 +00:00
|
|
|
if s.keepInterfaceInStringSummary(k) {
|
2021-02-13 02:38:16 +00:00
|
|
|
ifs = append(ifs, k)
|
2020-10-02 19:07:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
sort.Slice(ifs, func(i, j int) bool {
|
2021-03-26 04:26:01 +00:00
|
|
|
upi, upj := s.Interface[ifs[i]].IsUp(), s.Interface[ifs[j]].IsUp()
|
2020-10-02 19:07:00 +00:00
|
|
|
if upi != upj {
|
|
|
|
// Up sorts before down.
|
|
|
|
return upi
|
|
|
|
}
|
|
|
|
return ifs[i] < ifs[j]
|
|
|
|
})
|
|
|
|
for i, ifName := range ifs {
|
|
|
|
if i > 0 {
|
|
|
|
sb.WriteString(" ")
|
|
|
|
}
|
2023-08-23 18:48:05 +00:00
|
|
|
iface := s.Interface[ifName]
|
|
|
|
if iface.Interface == nil {
|
|
|
|
fmt.Fprintf(&sb, "%s:nil", ifName)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if !iface.IsUp() {
|
|
|
|
fmt.Fprintf(&sb, "%s:down", ifName)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
fmt.Fprintf(&sb, "%s:[", ifName)
|
|
|
|
needSpace := false
|
|
|
|
for _, pfx := range s.InterfaceIPs[ifName] {
|
|
|
|
a := pfx.Addr()
|
|
|
|
if a.IsMulticast() {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
fam := "4"
|
|
|
|
if a.Is6() {
|
|
|
|
fam = "6"
|
|
|
|
}
|
|
|
|
if needSpace {
|
|
|
|
sb.WriteString(" ")
|
|
|
|
}
|
|
|
|
needSpace = true
|
|
|
|
switch {
|
|
|
|
case a.IsLoopback():
|
|
|
|
fmt.Fprintf(&sb, "lo%s", fam)
|
|
|
|
case a.IsLinkLocalUnicast():
|
|
|
|
fmt.Fprintf(&sb, "llu%s", fam)
|
|
|
|
default:
|
2021-02-23 04:43:35 +00:00
|
|
|
fmt.Fprintf(&sb, "%s", pfx)
|
2020-10-02 19:07:00 +00:00
|
|
|
}
|
|
|
|
}
|
2023-08-23 18:48:05 +00:00
|
|
|
sb.WriteString("]")
|
2020-10-02 19:07:00 +00:00
|
|
|
}
|
|
|
|
sb.WriteString("}")
|
|
|
|
|
|
|
|
if s.IsExpensive {
|
|
|
|
sb.WriteString(" expensive")
|
|
|
|
}
|
|
|
|
if s.HTTPProxy != "" {
|
|
|
|
fmt.Fprintf(&sb, " httpproxy=%s", s.HTTPProxy)
|
|
|
|
}
|
|
|
|
if s.PAC != "" {
|
|
|
|
fmt.Fprintf(&sb, " pac=%s", s.PAC)
|
|
|
|
}
|
2021-06-18 00:49:15 +00:00
|
|
|
fmt.Fprintf(&sb, " v4=%v v6=%v}", s.HaveV4, s.HaveV6)
|
2020-10-02 19:07:00 +00:00
|
|
|
return sb.String()
|
|
|
|
}
|
|
|
|
|
2023-08-23 18:48:05 +00:00
|
|
|
// Equal reports whether s and s2 are exactly equal.
|
|
|
|
func (s *State) Equal(s2 *State) bool {
|
2021-03-26 16:09:12 +00:00
|
|
|
if s == nil && s2 == nil {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
if s == nil || s2 == nil {
|
|
|
|
return false
|
|
|
|
}
|
2021-06-18 00:49:15 +00:00
|
|
|
if s.HaveV6 != s2.HaveV6 ||
|
2021-03-26 16:09:12 +00:00
|
|
|
s.HaveV4 != s2.HaveV4 ||
|
|
|
|
s.IsExpensive != s2.IsExpensive ||
|
|
|
|
s.DefaultRouteInterface != s2.DefaultRouteInterface ||
|
|
|
|
s.HTTPProxy != s2.HTTPProxy ||
|
|
|
|
s.PAC != s2.PAC {
|
|
|
|
return false
|
|
|
|
}
|
2024-04-16 20:06:13 +00:00
|
|
|
// If s2 has more interfaces than s, it's not equal.
|
|
|
|
if len(s.Interface) != len(s2.Interface) || len(s.InterfaceIPs) != len(s2.InterfaceIPs) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
// Now that we know that both states have the same number of
|
|
|
|
// interfaces, we can check each interface in s against s2. If it's not
|
|
|
|
// present or not exactly equal, then the states are not equal.
|
2021-03-26 16:09:12 +00:00
|
|
|
for iname, i := range s.Interface {
|
|
|
|
i2, ok := s2.Interface[iname]
|
|
|
|
if !ok {
|
|
|
|
return false
|
|
|
|
}
|
2023-08-23 18:48:05 +00:00
|
|
|
if !i.Equal(i2) {
|
2021-03-26 16:09:12 +00:00
|
|
|
return false
|
|
|
|
}
|
2023-08-23 18:48:05 +00:00
|
|
|
}
|
|
|
|
for iname, vv := range s.InterfaceIPs {
|
|
|
|
if !slices.Equal(vv, s2.InterfaceIPs[iname]) {
|
2021-03-26 16:09:12 +00:00
|
|
|
return false
|
net/interfaces, wgengine/monitor: fix false positives link changes
interfaces.State.String tries to print a concise summary of the
network state, removing any interfaces that don't have any or any
interesting IP addresses. On macOS and iOS, for instance, there are a
ton of misc things.
But the link monitor based its are-there-changes decision on
interfaces.State.Equal, which just used reflect.DeepEqual, including
comparing all the boring interfaces. On macOS, when turning wifi on or off, there
are a ton of misc boring interface changes, resulting in hitting an earlier
check I'd added on suspicion this was happening:
[unexpected] network state changed, but stringification didn't
This fixes that by instead adding a new
interfaces.State.RemoveUninterestingInterfacesAndAddresses method that
does, uh, that. Then use that in the monitor. So then when Equal is
used later, it's DeepEqualing the already-cleaned version with only
interesting interfaces.
This makes cmd/tailscaled debug --monitor much less noisy.
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2021-03-09 04:41:23 +00:00
|
|
|
}
|
|
|
|
}
|
2021-03-26 16:09:12 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2022-11-13 16:47:34 +00:00
|
|
|
// HasIP reports whether any interface has the provided IP address.
|
|
|
|
func (s *State) HasIP(ip netip.Addr) bool {
|
|
|
|
if s == nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
for _, pv := range s.InterfaceIPs {
|
|
|
|
for _, p := range pv {
|
2023-09-01 05:54:21 +00:00
|
|
|
if p.Contains(ip) {
|
2022-11-13 16:47:34 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2023-08-23 18:48:05 +00:00
|
|
|
func (a Interface) Equal(b Interface) bool {
|
|
|
|
if (a.Interface == nil) != (b.Interface == nil) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if !(a.Desc == b.Desc && netAddrsEqual(a.AltAddrs, b.AltAddrs)) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if a.Interface != nil && !(a.Index == b.Index &&
|
2021-03-26 16:09:12 +00:00
|
|
|
a.MTU == b.MTU &&
|
|
|
|
a.Name == b.Name &&
|
|
|
|
a.Flags == b.Flags &&
|
2023-08-23 18:48:05 +00:00
|
|
|
bytes.Equal([]byte(a.HardwareAddr), []byte(b.HardwareAddr))) {
|
2021-03-26 16:09:12 +00:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *State) HasPAC() bool { return s != nil && s.PAC != "" }
|
|
|
|
|
|
|
|
// AnyInterfaceUp reports whether any interface seems like it has Internet access.
|
|
|
|
func (s *State) AnyInterfaceUp() bool {
|
2023-08-30 12:23:38 +00:00
|
|
|
if runtime.GOOS == "js" || runtime.GOOS == "tamago" {
|
2021-10-20 19:13:52 +00:00
|
|
|
return true
|
|
|
|
}
|
2021-06-18 00:49:15 +00:00
|
|
|
return s != nil && (s.HaveV4 || s.HaveV6)
|
2020-03-10 19:25:42 +00:00
|
|
|
}
|
|
|
|
|
2023-08-23 18:48:05 +00:00
|
|
|
func netAddrsEqual(a, b []net.Addr) bool {
|
|
|
|
if len(a) != len(b) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
for i, av := range a {
|
|
|
|
if av.Network() != b[i].Network() || av.String() != b[i].String() {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
all: convert more code to use net/netip directly
perl -i -npe 's,netaddr.IPPrefixFrom,netip.PrefixFrom,' $(git grep -l -F netaddr.)
perl -i -npe 's,netaddr.IPPortFrom,netip.AddrPortFrom,' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPrefix,netip.Prefix,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPort,netip.AddrPort,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IP\b,netip.Addr,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPv6Raw\b,netip.AddrFrom16,g' $(git grep -l -F netaddr. )
goimports -w .
Then delete some stuff from the net/netaddr shim package which is no
longer neeed.
Updates #5162
Change-Id: Ia7a86893fe21c7e3ee1ec823e8aba288d4566cd8
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2022-07-26 04:14:09 +00:00
|
|
|
func hasTailscaleIP(pfxs []netip.Prefix) bool {
|
2021-02-23 04:43:35 +00:00
|
|
|
for _, pfx := range pfxs {
|
2022-07-25 03:08:42 +00:00
|
|
|
if tsaddr.IsTailscaleIP(pfx.Addr()) {
|
2021-02-25 23:47:29 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
all: convert more code to use net/netip directly
perl -i -npe 's,netaddr.IPPrefixFrom,netip.PrefixFrom,' $(git grep -l -F netaddr.)
perl -i -npe 's,netaddr.IPPortFrom,netip.AddrPortFrom,' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPrefix,netip.Prefix,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPort,netip.AddrPort,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IP\b,netip.Addr,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPv6Raw\b,netip.AddrFrom16,g' $(git grep -l -F netaddr. )
goimports -w .
Then delete some stuff from the net/netaddr shim package which is no
longer neeed.
Updates #5162
Change-Id: Ia7a86893fe21c7e3ee1ec823e8aba288d4566cd8
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2022-07-26 04:14:09 +00:00
|
|
|
func isTailscaleInterface(name string, ips []netip.Prefix) bool {
|
2021-02-25 23:47:29 +00:00
|
|
|
if runtime.GOOS == "darwin" && strings.HasPrefix(name, "utun") && hasTailscaleIP(ips) {
|
|
|
|
// On macOS in the sandboxed app (at least as of
|
|
|
|
// 2021-02-25), we often see two utun devices
|
|
|
|
// (e.g. utun4 and utun7) with the same IPv4 and IPv6
|
|
|
|
// addresses. Just remove all utun devices with
|
|
|
|
// Tailscale IPs until we know what's happening with
|
|
|
|
// macOS NetworkExtensions and utun devices.
|
|
|
|
return true
|
|
|
|
}
|
2020-10-06 22:22:46 +00:00
|
|
|
return name == "Tailscale" || // as it is on Windows
|
|
|
|
strings.HasPrefix(name, "tailscale") // TODO: use --tun flag value, etc; see TODO in method doc
|
|
|
|
}
|
|
|
|
|
2020-10-01 22:33:37 +00:00
|
|
|
// getPAC, if non-nil, returns the current PAC file URL.
|
|
|
|
var getPAC func() string
|
|
|
|
|
2020-04-10 02:10:55 +00:00
|
|
|
// GetState returns the state of all the current machine's network interfaces.
|
|
|
|
//
|
|
|
|
// It does not set the returned State.IsExpensive. The caller can populate that.
|
2023-08-01 22:47:54 +00:00
|
|
|
//
|
|
|
|
// Deprecated: use netmon.Monitor.InterfaceState instead.
|
2020-03-10 19:25:42 +00:00
|
|
|
func GetState() (*State, error) {
|
2020-04-10 02:10:55 +00:00
|
|
|
s := &State{
|
all: convert more code to use net/netip directly
perl -i -npe 's,netaddr.IPPrefixFrom,netip.PrefixFrom,' $(git grep -l -F netaddr.)
perl -i -npe 's,netaddr.IPPortFrom,netip.AddrPortFrom,' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPrefix,netip.Prefix,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPort,netip.AddrPort,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IP\b,netip.Addr,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPv6Raw\b,netip.AddrFrom16,g' $(git grep -l -F netaddr. )
goimports -w .
Then delete some stuff from the net/netaddr shim package which is no
longer neeed.
Updates #5162
Change-Id: Ia7a86893fe21c7e3ee1ec823e8aba288d4566cd8
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2022-07-26 04:14:09 +00:00
|
|
|
InterfaceIPs: make(map[string][]netip.Prefix),
|
2021-03-26 04:26:01 +00:00
|
|
|
Interface: make(map[string]Interface),
|
2020-04-10 02:10:55 +00:00
|
|
|
}
|
all: convert more code to use net/netip directly
perl -i -npe 's,netaddr.IPPrefixFrom,netip.PrefixFrom,' $(git grep -l -F netaddr.)
perl -i -npe 's,netaddr.IPPortFrom,netip.AddrPortFrom,' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPrefix,netip.Prefix,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPort,netip.AddrPort,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IP\b,netip.Addr,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPv6Raw\b,netip.AddrFrom16,g' $(git grep -l -F netaddr. )
goimports -w .
Then delete some stuff from the net/netaddr shim package which is no
longer neeed.
Updates #5162
Change-Id: Ia7a86893fe21c7e3ee1ec823e8aba288d4566cd8
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2022-07-26 04:14:09 +00:00
|
|
|
if err := ForeachInterface(func(ni Interface, pfxs []netip.Prefix) {
|
2020-10-06 22:22:46 +00:00
|
|
|
ifUp := ni.IsUp()
|
2021-03-26 04:26:01 +00:00
|
|
|
s.Interface[ni.Name] = ni
|
2021-02-23 04:43:35 +00:00
|
|
|
s.InterfaceIPs[ni.Name] = append(s.InterfaceIPs[ni.Name], pfxs...)
|
|
|
|
if !ifUp || isTailscaleInterface(ni.Name, pfxs) {
|
2021-02-25 23:47:29 +00:00
|
|
|
return
|
|
|
|
}
|
2021-02-23 04:43:35 +00:00
|
|
|
for _, pfx := range pfxs {
|
2022-07-25 03:08:42 +00:00
|
|
|
if pfx.Addr().IsLoopback() {
|
2021-02-25 23:47:29 +00:00
|
|
|
continue
|
|
|
|
}
|
2022-07-25 03:08:42 +00:00
|
|
|
s.HaveV6 = s.HaveV6 || isUsableV6(pfx.Addr())
|
|
|
|
s.HaveV4 = s.HaveV4 || isUsableV4(pfx.Addr())
|
2020-10-06 22:22:46 +00:00
|
|
|
}
|
2020-03-10 19:25:42 +00:00
|
|
|
}); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
net/interfaces, wgengine/monitor: fix false positives link changes
interfaces.State.String tries to print a concise summary of the
network state, removing any interfaces that don't have any or any
interesting IP addresses. On macOS and iOS, for instance, there are a
ton of misc things.
But the link monitor based its are-there-changes decision on
interfaces.State.Equal, which just used reflect.DeepEqual, including
comparing all the boring interfaces. On macOS, when turning wifi on or off, there
are a ton of misc boring interface changes, resulting in hitting an earlier
check I'd added on suspicion this was happening:
[unexpected] network state changed, but stringification didn't
This fixes that by instead adding a new
interfaces.State.RemoveUninterestingInterfacesAndAddresses method that
does, uh, that. Then use that in the monitor. So then when Equal is
used later, it's DeepEqualing the already-cleaned version with only
interesting interfaces.
This makes cmd/tailscaled debug --monitor much less noisy.
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2021-03-09 04:41:23 +00:00
|
|
|
|
2021-12-29 18:37:33 +00:00
|
|
|
dr, _ := DefaultRoute()
|
|
|
|
s.DefaultRouteInterface = dr.InterfaceName
|
|
|
|
|
|
|
|
// Populate description (for Windows, primarily) if present.
|
|
|
|
if desc := dr.InterfaceDesc; desc != "" {
|
|
|
|
if iface, ok := s.Interface[dr.InterfaceName]; ok {
|
|
|
|
iface.Desc = desc
|
|
|
|
s.Interface[dr.InterfaceName] = iface
|
|
|
|
}
|
|
|
|
}
|
2020-08-13 22:25:54 +00:00
|
|
|
|
2020-10-06 22:22:46 +00:00
|
|
|
if s.AnyInterfaceUp() {
|
|
|
|
req, err := http.NewRequest("GET", LoginEndpointForProxyDetermination, nil)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if u, err := tshttpproxy.ProxyFromEnvironment(req); err == nil && u != nil {
|
|
|
|
s.HTTPProxy = u.String()
|
|
|
|
}
|
|
|
|
if getPAC != nil {
|
|
|
|
s.PAC = getPAC()
|
|
|
|
}
|
2020-10-01 22:33:37 +00:00
|
|
|
}
|
2020-08-13 22:25:54 +00:00
|
|
|
|
2020-03-10 19:25:42 +00:00
|
|
|
return s, nil
|
|
|
|
}
|
2020-03-27 20:26:35 +00:00
|
|
|
|
|
|
|
// HTTPOfListener returns the HTTP address to ln.
|
|
|
|
// If the listener is listening on the unspecified address, it
|
|
|
|
// it tries to find a reasonable interface address on the machine to use.
|
|
|
|
func HTTPOfListener(ln net.Listener) string {
|
|
|
|
ta, ok := ln.Addr().(*net.TCPAddr)
|
|
|
|
if !ok || !ta.IP.IsUnspecified() {
|
|
|
|
return fmt.Sprintf("http://%v/", ln.Addr())
|
|
|
|
}
|
|
|
|
|
|
|
|
var goodIP string
|
|
|
|
var privateIP string
|
all: convert more code to use net/netip directly
perl -i -npe 's,netaddr.IPPrefixFrom,netip.PrefixFrom,' $(git grep -l -F netaddr.)
perl -i -npe 's,netaddr.IPPortFrom,netip.AddrPortFrom,' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPrefix,netip.Prefix,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPort,netip.AddrPort,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IP\b,netip.Addr,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPv6Raw\b,netip.AddrFrom16,g' $(git grep -l -F netaddr. )
goimports -w .
Then delete some stuff from the net/netaddr shim package which is no
longer neeed.
Updates #5162
Change-Id: Ia7a86893fe21c7e3ee1ec823e8aba288d4566cd8
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2022-07-26 04:14:09 +00:00
|
|
|
ForeachInterfaceAddress(func(i Interface, pfx netip.Prefix) {
|
2022-07-25 03:08:42 +00:00
|
|
|
ip := pfx.Addr()
|
2021-07-27 02:51:18 +00:00
|
|
|
if ip.IsPrivate() {
|
2020-03-27 20:26:35 +00:00
|
|
|
if privateIP == "" {
|
|
|
|
privateIP = ip.String()
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
goodIP = ip.String()
|
|
|
|
})
|
|
|
|
if privateIP != "" {
|
|
|
|
goodIP = privateIP
|
|
|
|
}
|
|
|
|
if goodIP != "" {
|
|
|
|
return fmt.Sprintf("http://%v/", net.JoinHostPort(goodIP, fmt.Sprint(ta.Port)))
|
|
|
|
}
|
|
|
|
return fmt.Sprintf("http://localhost:%v/", fmt.Sprint(ta.Port))
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2023-12-19 21:27:52 +00:00
|
|
|
// likelyHomeRouterIP, if present, is a platform-specific function that is used
|
|
|
|
// to determine the likely home router IP of the current system. The signature
|
|
|
|
// of this function is:
|
|
|
|
//
|
|
|
|
// func() (homeRouter, localAddr netip.Addr, ok bool)
|
|
|
|
//
|
|
|
|
// It should return a homeRouter IP and ok=true, or no homeRouter IP and
|
|
|
|
// ok=false. Optionally, an implementation can return the "self" IP address as
|
|
|
|
// well, which will be used instead of attempting to determine it by reading
|
|
|
|
// the system's interfaces.
|
|
|
|
var likelyHomeRouterIP func() (netip.Addr, netip.Addr, bool)
|
|
|
|
|
|
|
|
// For debugging the new behaviour where likelyHomeRouterIP can return the
|
|
|
|
// "self" IP; should remove after we're confidant this won't cause issues.
|
|
|
|
var disableLikelyHomeRouterIPSelf = envknob.RegisterBool("TS_DEBUG_DISABLE_LIKELY_HOME_ROUTER_IP_SELF")
|
2020-07-06 17:34:52 +00:00
|
|
|
|
|
|
|
// LikelyHomeRouterIP returns the likely IP of the residential router,
|
|
|
|
// which will always be an IPv4 private address, if found.
|
2020-07-06 20:51:17 +00:00
|
|
|
// In addition, it returns the IP address of the current machine on
|
|
|
|
// the LAN using that gateway.
|
2020-07-06 17:34:52 +00:00
|
|
|
// This is used as the destination for UPnP, NAT-PMP, PCP, etc queries.
|
all: convert more code to use net/netip directly
perl -i -npe 's,netaddr.IPPrefixFrom,netip.PrefixFrom,' $(git grep -l -F netaddr.)
perl -i -npe 's,netaddr.IPPortFrom,netip.AddrPortFrom,' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPrefix,netip.Prefix,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPort,netip.AddrPort,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IP\b,netip.Addr,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPv6Raw\b,netip.AddrFrom16,g' $(git grep -l -F netaddr. )
goimports -w .
Then delete some stuff from the net/netaddr shim package which is no
longer neeed.
Updates #5162
Change-Id: Ia7a86893fe21c7e3ee1ec823e8aba288d4566cd8
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2022-07-26 04:14:09 +00:00
|
|
|
func LikelyHomeRouterIP() (gateway, myIP netip.Addr, ok bool) {
|
2023-12-19 21:27:52 +00:00
|
|
|
// If we don't have a way to get the home router IP, then we can't do
|
|
|
|
// anything; just return.
|
|
|
|
if likelyHomeRouterIP == nil {
|
|
|
|
return
|
2020-07-06 20:51:17 +00:00
|
|
|
}
|
2023-12-19 21:27:52 +00:00
|
|
|
|
|
|
|
// Get the gateway next; if that fails, we can't continue.
|
|
|
|
gateway, myIP, ok = likelyHomeRouterIP()
|
2020-07-06 20:51:17 +00:00
|
|
|
if !ok {
|
|
|
|
return
|
2020-07-06 17:34:52 +00:00
|
|
|
}
|
2023-12-19 21:27:52 +00:00
|
|
|
|
|
|
|
// If the platform-specific implementation returned a valid myIP, then
|
|
|
|
// we can return it as-is without needing to iterate through all
|
|
|
|
// interface addresses.
|
|
|
|
if disableLikelyHomeRouterIPSelf() {
|
|
|
|
myIP = netip.Addr{}
|
|
|
|
}
|
|
|
|
if myIP.IsValid() {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// The platform-specific implementation didn't return a valid myIP;
|
|
|
|
// iterate through all interfaces and try to find the correct one.
|
all: convert more code to use net/netip directly
perl -i -npe 's,netaddr.IPPrefixFrom,netip.PrefixFrom,' $(git grep -l -F netaddr.)
perl -i -npe 's,netaddr.IPPortFrom,netip.AddrPortFrom,' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPrefix,netip.Prefix,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPort,netip.AddrPort,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IP\b,netip.Addr,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPv6Raw\b,netip.AddrFrom16,g' $(git grep -l -F netaddr. )
goimports -w .
Then delete some stuff from the net/netaddr shim package which is no
longer neeed.
Updates #5162
Change-Id: Ia7a86893fe21c7e3ee1ec823e8aba288d4566cd8
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2022-07-26 04:14:09 +00:00
|
|
|
ForeachInterfaceAddress(func(i Interface, pfx netip.Prefix) {
|
2023-03-03 22:19:02 +00:00
|
|
|
if !i.IsUp() {
|
|
|
|
// Skip interfaces that aren't up.
|
|
|
|
return
|
|
|
|
} else if myIP.IsValid() {
|
|
|
|
// We already have a valid self IP; skip this one.
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-07-25 03:08:42 +00:00
|
|
|
ip := pfx.Addr()
|
2023-03-03 22:19:02 +00:00
|
|
|
if !ip.IsValid() || !ip.Is4() {
|
|
|
|
// Skip IPs that aren't valid or aren't IPv4, since we
|
|
|
|
// always return an IPv4 address.
|
2020-07-06 20:51:17 +00:00
|
|
|
return
|
|
|
|
}
|
net/interfaces: ensure we return valid 'self' IP in LikelyHomeRouterIP
Before this fix, LikelyHomeRouterIP could return a 'self' IP that
doesn't correspond to the gateway address, since it picks the first
private address when iterating over the set interfaces as the 'self' IP,
without checking that the address corresponds with the
previously-detected gateway.
This behaviour was introduced by accident in aaf2df7, where we deleted
the following code:
for _, prefix := range privatev4s {
if prefix.Contains(gateway) && prefix.Contains(ip) {
myIP = ip
ok = true
return
}
}
Other than checking that 'gateway' and 'ip' were private IP addresses
(which were correctly replaced with a call to the netip.Addr.IsPrivate
method), it also implicitly checked that both 'gateway' and 'ip' were a
part of the *same* prefix, and thus likely to be the same interface.
Restore that behaviour by explicitly checking pfx.Contains(gateway),
which, given that the 'ip' variable is derived from our prefix 'pfx',
ensures that the 'self' IP will correspond to the returned 'gateway'.
Fixes #10466
Signed-off-by: Andrew Dunham <andrew@du.nham.ca>
Change-Id: Iddd2ee70cefb9fb40071986fefeace9ca2441ee6
2023-12-05 14:44:32 +00:00
|
|
|
|
|
|
|
// If this prefix ("interface") doesn't contain the gateway,
|
|
|
|
// then we skip it; this can happen if we have multiple valid
|
|
|
|
// interfaces and the interface with the route to the internet
|
|
|
|
// is ordered after another valid+running interface.
|
|
|
|
if !pfx.Contains(gateway) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-07-27 02:51:18 +00:00
|
|
|
if gateway.IsPrivate() && ip.IsPrivate() {
|
|
|
|
myIP = ip
|
|
|
|
ok = true
|
|
|
|
return
|
2020-07-06 20:51:17 +00:00
|
|
|
}
|
|
|
|
})
|
2022-07-25 03:08:42 +00:00
|
|
|
return gateway, myIP, myIP.IsValid()
|
2020-07-06 17:34:52 +00:00
|
|
|
}
|
|
|
|
|
2021-06-15 20:42:18 +00:00
|
|
|
// isUsableV4 reports whether ip is a usable IPv4 address which could
|
|
|
|
// conceivably be used to get Internet connectivity. Globally routable and
|
|
|
|
// private IPv4 addresses are always Usable, and link local 169.254.x.x
|
|
|
|
// addresses are in some environments.
|
all: convert more code to use net/netip directly
perl -i -npe 's,netaddr.IPPrefixFrom,netip.PrefixFrom,' $(git grep -l -F netaddr.)
perl -i -npe 's,netaddr.IPPortFrom,netip.AddrPortFrom,' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPrefix,netip.Prefix,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPort,netip.AddrPort,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IP\b,netip.Addr,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPv6Raw\b,netip.AddrFrom16,g' $(git grep -l -F netaddr. )
goimports -w .
Then delete some stuff from the net/netaddr shim package which is no
longer neeed.
Updates #5162
Change-Id: Ia7a86893fe21c7e3ee1ec823e8aba288d4566cd8
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2022-07-26 04:14:09 +00:00
|
|
|
func isUsableV4(ip netip.Addr) bool {
|
2021-06-15 20:42:18 +00:00
|
|
|
if !ip.Is4() || ip.IsLoopback() {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if ip.IsLinkLocalUnicast() {
|
net/interfaces: also allow link-local for AzureAppServices.
In May 2021, Azure App Services used 172.16.x.x addresses:
```
10: eth0@if11: <BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN> 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: <BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN> 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 <dgentry@tailscale.com>
2023-03-19 13:37:07 +00:00
|
|
|
switch hostinfo.GetEnvType() {
|
|
|
|
case hostinfo.AWSLambda:
|
|
|
|
return true
|
|
|
|
case hostinfo.AzureAppService:
|
|
|
|
return true
|
|
|
|
default:
|
|
|
|
return false
|
|
|
|
}
|
2021-06-15 20:42:18 +00:00
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
// isUsableV6 reports whether ip is a usable IPv6 address which could
|
|
|
|
// conceivably be used to get Internet connectivity. Globally routable
|
|
|
|
// IPv6 addresses are always Usable, and Unique Local Addresses
|
|
|
|
// (fc00::/7) are in some environments used with address translation.
|
all: convert more code to use net/netip directly
perl -i -npe 's,netaddr.IPPrefixFrom,netip.PrefixFrom,' $(git grep -l -F netaddr.)
perl -i -npe 's,netaddr.IPPortFrom,netip.AddrPortFrom,' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPrefix,netip.Prefix,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPort,netip.AddrPort,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IP\b,netip.Addr,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPv6Raw\b,netip.AddrFrom16,g' $(git grep -l -F netaddr. )
goimports -w .
Then delete some stuff from the net/netaddr shim package which is no
longer neeed.
Updates #5162
Change-Id: Ia7a86893fe21c7e3ee1ec823e8aba288d4566cd8
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2022-07-26 04:14:09 +00:00
|
|
|
func isUsableV6(ip netip.Addr) bool {
|
2021-03-27 01:38:05 +00:00
|
|
|
return v6Global1.Contains(ip) ||
|
2021-07-28 18:30:06 +00:00
|
|
|
(ip.Is6() && ip.IsPrivate() && !tsaddr.TailscaleULARange().Contains(ip))
|
2020-05-28 16:58:52 +00:00
|
|
|
}
|
|
|
|
|
2020-03-27 20:26:35 +00:00
|
|
|
var (
|
2022-07-26 03:55:44 +00:00
|
|
|
v6Global1 = netip.MustParsePrefix("2000::/3")
|
2020-03-27 20:26:35 +00:00
|
|
|
)
|
2020-10-02 19:07:00 +00:00
|
|
|
|
2023-08-23 18:48:05 +00:00
|
|
|
// keepInterfaceInStringSummary reports whether the named interface should be included
|
|
|
|
// in the String method's summary string.
|
|
|
|
func (s *State) keepInterfaceInStringSummary(ifName string) bool {
|
|
|
|
iface, ok := s.Interface[ifName]
|
|
|
|
if !ok || iface.Interface == nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if ifName == s.DefaultRouteInterface {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
up := iface.IsUp()
|
|
|
|
for _, p := range s.InterfaceIPs[ifName] {
|
|
|
|
a := p.Addr()
|
|
|
|
if a.IsLinkLocalUnicast() || a.IsLoopback() {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if up || a.IsGlobalUnicast() || a.IsPrivate() {
|
2021-02-13 02:38:16 +00:00
|
|
|
return true
|
2020-10-02 19:07:00 +00:00
|
|
|
}
|
|
|
|
}
|
2021-02-13 02:38:16 +00:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2021-10-04 16:33:33 +00:00
|
|
|
var altNetInterfaces func() ([]Interface, error)
|
|
|
|
|
|
|
|
// RegisterInterfaceGetter sets the function that's used to query
|
|
|
|
// the system network interfaces.
|
|
|
|
func RegisterInterfaceGetter(getInterfaces func() ([]Interface, error)) {
|
|
|
|
altNetInterfaces = getInterfaces
|
|
|
|
}
|
|
|
|
|
2021-10-14 21:55:55 +00:00
|
|
|
// List is a list of interfaces on the machine.
|
|
|
|
type List []Interface
|
|
|
|
|
|
|
|
// GetList returns the list of interfaces on the machine.
|
|
|
|
func GetList() (List, error) {
|
|
|
|
return netInterfaces()
|
|
|
|
}
|
|
|
|
|
2021-10-04 16:33:33 +00:00
|
|
|
// netInterfaces is a wrapper around the standard library's net.Interfaces
|
|
|
|
// that returns a []*Interface instead of a []net.Interface.
|
|
|
|
// It exists because Android SDK 30 no longer permits Go's net.Interfaces
|
|
|
|
// to work (Issue 2293); this wrapper lets us the Android app register
|
|
|
|
// an alternate implementation.
|
|
|
|
func netInterfaces() ([]Interface, error) {
|
|
|
|
if altNetInterfaces != nil {
|
|
|
|
return altNetInterfaces()
|
|
|
|
}
|
|
|
|
ifs, err := net.Interfaces()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
ret := make([]Interface, len(ifs))
|
|
|
|
for i := range ifs {
|
|
|
|
ret[i].Interface = &ifs[i]
|
|
|
|
}
|
|
|
|
return ret, nil
|
|
|
|
}
|
2021-12-29 18:37:33 +00:00
|
|
|
|
2022-02-28 22:49:37 +00:00
|
|
|
// DefaultRouteDetails are the details about a default route returned
|
|
|
|
// by DefaultRoute.
|
2021-12-29 18:37:33 +00:00
|
|
|
type DefaultRouteDetails struct {
|
|
|
|
// InterfaceName is the interface name. It must always be populated.
|
|
|
|
// It's like "eth0" (Linux), "Ethernet 2" (Windows), "en0" (macOS).
|
|
|
|
InterfaceName string
|
|
|
|
|
|
|
|
// InterfaceDesc is populated on Windows at least. It's a
|
|
|
|
// longer description, like "Red Hat VirtIO Ethernet Adapter".
|
|
|
|
InterfaceDesc string
|
|
|
|
|
|
|
|
// InterfaceIndex is like net.Interface.Index.
|
|
|
|
// Zero means not populated.
|
|
|
|
InterfaceIndex int
|
|
|
|
|
|
|
|
// TODO(bradfitz): break this out into v4-vs-v6 once that need arises.
|
|
|
|
}
|
|
|
|
|
|
|
|
// DefaultRouteInterface is like DefaultRoute but only returns the
|
|
|
|
// interface name.
|
|
|
|
func DefaultRouteInterface() (string, error) {
|
|
|
|
dr, err := DefaultRoute()
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
return dr.InterfaceName, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// DefaultRoute returns details of the network interface that owns
|
|
|
|
// the default route, not including any tailscale interfaces.
|
|
|
|
func DefaultRoute() (DefaultRouteDetails, error) {
|
|
|
|
return defaultRoute()
|
|
|
|
}
|
2022-06-29 20:25:45 +00:00
|
|
|
|
|
|
|
// HasCGNATInterface reports whether there are any non-Tailscale interfaces that
|
|
|
|
// use a CGNAT IP range.
|
|
|
|
func HasCGNATInterface() (bool, error) {
|
|
|
|
hasCGNATInterface := false
|
|
|
|
cgnatRange := tsaddr.CGNATRange()
|
all: convert more code to use net/netip directly
perl -i -npe 's,netaddr.IPPrefixFrom,netip.PrefixFrom,' $(git grep -l -F netaddr.)
perl -i -npe 's,netaddr.IPPortFrom,netip.AddrPortFrom,' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPrefix,netip.Prefix,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPort,netip.AddrPort,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IP\b,netip.Addr,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPv6Raw\b,netip.AddrFrom16,g' $(git grep -l -F netaddr. )
goimports -w .
Then delete some stuff from the net/netaddr shim package which is no
longer neeed.
Updates #5162
Change-Id: Ia7a86893fe21c7e3ee1ec823e8aba288d4566cd8
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2022-07-26 04:14:09 +00:00
|
|
|
err := ForeachInterface(func(i Interface, pfxs []netip.Prefix) {
|
2022-06-29 20:25:45 +00:00
|
|
|
if hasCGNATInterface || !i.IsUp() || isTailscaleInterface(i.Name, pfxs) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
for _, pfx := range pfxs {
|
|
|
|
if cgnatRange.Overlaps(pfx) {
|
|
|
|
hasCGNATInterface = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return false, err
|
|
|
|
}
|
|
|
|
return hasCGNATInterface, nil
|
|
|
|
}
|
2023-02-23 19:48:03 +00:00
|
|
|
|
|
|
|
var interfaceDebugExtras func(ifIndex int) (string, error)
|
|
|
|
|
|
|
|
// InterfaceDebugExtras returns extra debugging information about an interface
|
|
|
|
// if any (an empty string will be returned if there are no additional details).
|
|
|
|
// Formatting is platform-dependent and should not be parsed.
|
|
|
|
func InterfaceDebugExtras(ifIndex int) (string, error) {
|
|
|
|
if interfaceDebugExtras != nil {
|
|
|
|
return interfaceDebugExtras(ifIndex)
|
|
|
|
}
|
|
|
|
return "", nil
|
|
|
|
}
|