From 4dece0c35972d9a2009c5db41169cd074fb9b664 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Fri, 26 Apr 2024 18:07:06 -0700 Subject: [PATCH] net/netutil: remove a use of deprecated interfaces.GetState I'm working on moving all network state queries to be on netmon.Monitor, removing old APIs. Updates tailscale/corp#10910 Updates tailscale/corp#18960 Updates #7967 Updates #3299 Change-Id: If0de137e0e2e145520f69e258597fb89cf39a2a3 Signed-off-by: Brad Fitzpatrick --- net/netutil/ip_forward.go | 9 ++------- net/netutil/netutil_test.go | 10 +++++++++- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/net/netutil/ip_forward.go b/net/netutil/ip_forward.go index 9699f34c5..c67a802c8 100644 --- a/net/netutil/ip_forward.go +++ b/net/netutil/ip_forward.go @@ -6,6 +6,7 @@ package netutil import ( "bytes" + "errors" "fmt" "net/netip" "os" @@ -145,8 +146,6 @@ func CheckIPForwarding(routes []netip.Prefix, state *interfaces.State) (warn, er // disabled or set to 'loose' mode for exit node functionality on any // interface. // -// The state param can be nil, in which case interfaces.GetState is used. -// // The routes should only be advertised routes, and should not contain the // node's Tailscale IPs. // @@ -159,11 +158,7 @@ func CheckReversePathFiltering(state *interfaces.State) (warn []string, err erro } if state == nil { - var err error - state, err = interfaces.GetState() - if err != nil { - return nil, err - } + return nil, errors.New("no link state") } // The kernel uses the maximum value for rp_filter between the 'all' diff --git a/net/netutil/netutil_test.go b/net/netutil/netutil_test.go index 3fc46f315..fdc26b02f 100644 --- a/net/netutil/netutil_test.go +++ b/net/netutil/netutil_test.go @@ -8,6 +8,8 @@ import ( "net" "runtime" "testing" + + "tailscale.com/net/netmon" ) type conn struct { @@ -70,7 +72,13 @@ func TestCheckReversePathFiltering(t *testing.T) { if runtime.GOOS != "linux" { t.Skipf("skipping on %s", runtime.GOOS) } - warn, err := CheckReversePathFiltering(nil) + netMon, err := netmon.New(t.Logf) + if err != nil { + t.Fatal(err) + } + defer netMon.Close() + + warn, err := CheckReversePathFiltering(netMon.InterfaceState()) t.Logf("err: %v", err) t.Logf("warnings: %v", warn) }