ipnlocal, net/*: deprecate interfaces.GetState, use netmon more for it

Updates #cleanup

Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
pull/8766/head
Brad Fitzpatrick 1 year ago committed by Brad Fitzpatrick
parent 6d65c04987
commit 66e46bf501

@ -4463,7 +4463,7 @@ func (b *LocalBackend) CheckIPForwarding() error {
} }
// TODO: let the caller pass in the ranges. // TODO: let the caller pass in the ranges.
warn, err := netutil.CheckIPForwarding(tsaddr.ExitRoutes(), nil) warn, err := netutil.CheckIPForwarding(tsaddr.ExitRoutes(), b.sys.NetMon.Get().InterfaceState())
if err != nil { if err != nil {
return err return err
} }

@ -1282,8 +1282,8 @@ func (h *peerAPIHandler) handleWakeOnLAN(w http.ResponseWriter, r *http.Request)
return return
} }
var password []byte // TODO(bradfitz): support? var password []byte // TODO(bradfitz): support?
st, err := interfaces.GetState() st := h.ps.b.sys.NetMon.Get().InterfaceState()
if err != nil { if st == nil {
http.Error(w, "failed to get interfaces state", http.StatusInternalServerError) http.Error(w, "failed to get interfaces state", http.StatusInternalServerError)
return return
} }

@ -506,6 +506,8 @@ var getPAC func() string
// GetState returns the state of all the current machine's network interfaces. // 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. // It does not set the returned State.IsExpensive. The caller can populate that.
//
// Deprecated: use netmon.Monitor.InterfaceState instead.
func GetState() (*State, error) { func GetState() (*State, error) {
s := &State{ s := &State{
InterfaceIPs: make(map[string][]netip.Prefix), InterfaceIPs: make(map[string][]netip.Prefix),

@ -166,6 +166,8 @@ type Client struct {
// NetMon optionally provides a netmon.Monitor to use to get the current // NetMon optionally provides a netmon.Monitor to use to get the current
// (cached) network interface. // (cached) network interface.
// If nil, the interface will be looked up dynamically. // If nil, the interface will be looked up dynamically.
// TODO(bradfitz): make NetMon required. As of 2023-08-01, it basically always is
// present anyway.
NetMon *netmon.Monitor NetMon *netmon.Monitor
// TimeNow, if non-nil, is used instead of time.Now. // TimeNow, if non-nil, is used instead of time.Now.

@ -51,7 +51,7 @@ func protocolsRequiredForForwarding(routes []netip.Prefix, state *interfaces.Sta
// CheckIPForwarding reports whether IP forwarding is enabled correctly // CheckIPForwarding reports whether IP forwarding is enabled correctly
// for subnet routing and exit node functionality on any interface. // for subnet routing and exit node functionality on any interface.
// The state param can be nil, in which case interfaces.GetState is used. // The state param must not be nil.
// The routes should only be advertised routes, and should not contain the // The routes should only be advertised routes, and should not contain the
// nodes Tailscale IPs. // nodes Tailscale IPs.
// It returns an error if it is unable to determine if IP forwarding is enabled. // It returns an error if it is unable to determine if IP forwarding is enabled.
@ -65,14 +65,10 @@ func CheckIPForwarding(routes []netip.Prefix, state *interfaces.State) (warn, er
} }
return nil, nil return nil, nil
} }
const kbLink = "\nSee https://tailscale.com/s/ip-forwarding"
if state == nil { if state == nil {
var err error return nil, fmt.Errorf("Couldn't check system's IP forwarding configuration; no link state")
state, err = interfaces.GetState()
if err != nil {
return nil, err
}
} }
const kbLink = "\nSee https://tailscale.com/s/ip-forwarding"
wantV4, wantV6 := protocolsRequiredForForwarding(routes, state) wantV4, wantV6 := protocolsRequiredForForwarding(routes, state)
if !wantV4 && !wantV6 { if !wantV4 && !wantV6 {
return nil, nil return nil, nil

Loading…
Cancel
Save