From 2bd3c1474b25f0432f805180949ac24b455de376 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Wed, 7 Feb 2024 14:27:29 -0800 Subject: [PATCH] util/cmpx: delete now that we're using Go 1.22 Updates #11058 Change-Id: I09dea8e86f03ec148b715efca339eab8b1f0f644 Signed-off-by: Brad Fitzpatrick --- client/tailscale/localclient.go | 4 ++-- cmd/derper/depaware.txt | 1 - cmd/derper/derper.go | 4 ++-- cmd/get-authkey/main.go | 4 ++-- cmd/stund/depaware.txt | 1 - cmd/tailscale/cli/cli_test.go | 4 ++-- cmd/tailscale/cli/status.go | 4 ++-- cmd/tailscale/cli/web.go | 4 ++-- cmd/tailscale/depaware.txt | 1 - cmd/tailscaled/depaware.txt | 1 - control/controlclient/map.go | 6 +++--- derp/derphttp/derphttp_client.go | 4 ++-- ipn/ipnlocal/c2n_test.go | 4 ++-- ipn/ipnlocal/dnsconfig_test.go | 4 ++-- ipn/ipnlocal/local.go | 3 +-- ipn/ipnlocal/serve_test.go | 4 ++-- net/dnscache/messagecache.go | 4 ++-- net/netcheck/netcheck.go | 6 +++--- tailcfg/tailcfg.go | 4 ++-- tsweb/tsweb.go | 4 ++-- tsweb/varz/varz.go | 8 ++++---- util/cmpx/cmpx.go | 22 ---------------------- util/cmpx/cmpx_test.go | 24 ------------------------ util/linuxfw/nftables.go | 8 ++++---- 24 files changed, 41 insertions(+), 92 deletions(-) delete mode 100644 util/cmpx/cmpx.go delete mode 100644 util/cmpx/cmpx_test.go diff --git a/client/tailscale/localclient.go b/client/tailscale/localclient.go index cb8670d8b..397703268 100644 --- a/client/tailscale/localclient.go +++ b/client/tailscale/localclient.go @@ -7,6 +7,7 @@ package tailscale import ( "bytes" + "cmp" "context" "crypto/tls" "encoding/json" @@ -37,7 +38,6 @@ import ( "tailscale.com/tka" "tailscale.com/types/key" "tailscale.com/types/tkatype" - "tailscale.com/util/cmpx" ) // defaultLocalClient is the default LocalClient when using the legacy @@ -479,7 +479,7 @@ func (lc *LocalClient) DebugPortmap(ctx context.Context, opts *DebugPortmapOpts) opts = &DebugPortmapOpts{} } - vals.Set("duration", cmpx.Or(opts.Duration, 5*time.Second).String()) + vals.Set("duration", cmp.Or(opts.Duration, 5*time.Second).String()) vals.Set("type", opts.Type) vals.Set("log_http", strconv.FormatBool(opts.LogHTTP)) diff --git a/cmd/derper/depaware.txt b/cmd/derper/depaware.txt index 3b8451cde..9b4b70a71 100644 --- a/cmd/derper/depaware.txt +++ b/cmd/derper/depaware.txt @@ -138,7 +138,6 @@ tailscale.com/cmd/derper dependencies: (generated by github.com/tailscale/depawa tailscale.com/util/clientmetric from tailscale.com/net/tshttpproxy+ tailscale.com/util/cloudenv from tailscale.com/hostinfo+ W tailscale.com/util/cmpver from tailscale.com/net/tshttpproxy - tailscale.com/util/cmpx from tailscale.com/cmd/derper+ tailscale.com/util/ctxkey from tailscale.com/tsweb+ L 💣 tailscale.com/util/dirwalk from tailscale.com/metrics tailscale.com/util/dnsname from tailscale.com/hostinfo+ diff --git a/cmd/derper/derper.go b/cmd/derper/derper.go index a1747753d..04622ec89 100644 --- a/cmd/derper/derper.go +++ b/cmd/derper/derper.go @@ -5,6 +5,7 @@ package main // import "tailscale.com/cmd/derper" import ( + "cmp" "context" "crypto/tls" "encoding/json" @@ -34,7 +35,6 @@ import ( "tailscale.com/net/stunserver" "tailscale.com/tsweb" "tailscale.com/types/key" - "tailscale.com/util/cmpx" ) var ( @@ -369,7 +369,7 @@ func defaultMeshPSKFile() string { } func rateLimitedListenAndServeTLS(srv *http.Server) error { - ln, err := net.Listen("tcp", cmpx.Or(srv.Addr, ":https")) + ln, err := net.Listen("tcp", cmp.Or(srv.Addr, ":https")) if err != nil { return err } diff --git a/cmd/get-authkey/main.go b/cmd/get-authkey/main.go index 22dd9af82..d8030252c 100644 --- a/cmd/get-authkey/main.go +++ b/cmd/get-authkey/main.go @@ -7,6 +7,7 @@ package main import ( + "cmp" "context" "flag" "fmt" @@ -16,7 +17,6 @@ import ( "golang.org/x/oauth2/clientcredentials" "tailscale.com/client/tailscale" - "tailscale.com/util/cmpx" ) func main() { @@ -40,7 +40,7 @@ func main() { log.Fatal("at least one tag must be specified") } - baseURL := cmpx.Or(os.Getenv("TS_BASE_URL"), "https://api.tailscale.com") + baseURL := cmp.Or(os.Getenv("TS_BASE_URL"), "https://api.tailscale.com") credentials := clientcredentials.Config{ ClientID: clientID, diff --git a/cmd/stund/depaware.txt b/cmd/stund/depaware.txt index d918b0c6d..09c39f3fc 100644 --- a/cmd/stund/depaware.txt +++ b/cmd/stund/depaware.txt @@ -62,7 +62,6 @@ tailscale.com/cmd/stund dependencies: (generated by github.com/tailscale/depawar tailscale.com/types/structs from tailscale.com/tailcfg+ tailscale.com/types/tkatype from tailscale.com/tailcfg+ tailscale.com/types/views from tailscale.com/net/tsaddr+ - tailscale.com/util/cmpx from tailscale.com/tailcfg+ tailscale.com/util/ctxkey from tailscale.com/tsweb+ L 💣 tailscale.com/util/dirwalk from tailscale.com/metrics tailscale.com/util/dnsname from tailscale.com/tailcfg diff --git a/cmd/tailscale/cli/cli_test.go b/cmd/tailscale/cli/cli_test.go index b97a2625d..385388641 100644 --- a/cmd/tailscale/cli/cli_test.go +++ b/cmd/tailscale/cli/cli_test.go @@ -5,6 +5,7 @@ package cli import ( "bytes" + stdcmp "cmp" "encoding/json" "flag" "fmt" @@ -24,7 +25,6 @@ import ( "tailscale.com/types/logger" "tailscale.com/types/persist" "tailscale.com/types/preftype" - "tailscale.com/util/cmpx" "tailscale.com/version/distro" ) @@ -758,7 +758,7 @@ func TestPrefsFromUpArgs(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { var warnBuf tstest.MemLogger - goos := cmpx.Or(tt.goos, "linux") + goos := stdcmp.Or(tt.goos, "linux") st := tt.st if st == nil { st = new(ipnstate.Status) diff --git a/cmd/tailscale/cli/status.go b/cmd/tailscale/cli/status.go index cb8755bc2..31ce2220d 100644 --- a/cmd/tailscale/cli/status.go +++ b/cmd/tailscale/cli/status.go @@ -5,6 +5,7 @@ package cli import ( "bytes" + "cmp" "context" "encoding/json" "errors" @@ -23,7 +24,6 @@ import ( "tailscale.com/ipn" "tailscale.com/ipn/ipnstate" "tailscale.com/net/interfaces" - "tailscale.com/util/cmpx" "tailscale.com/util/dnsname" ) @@ -316,7 +316,7 @@ func ownerLogin(st *ipnstate.Status, ps *ipnstate.PeerStatus) string { // their netmap. We've historically (2021-01..2023-08) always shown the // sharer's name in the UI. Perhaps we want to show both here? But the CLI's // a bit space constrained. - uid := cmpx.Or(ps.AltSharerUserID, ps.UserID) + uid := cmp.Or(ps.AltSharerUserID, ps.UserID) if uid.IsZero() { return "-" } diff --git a/cmd/tailscale/cli/web.go b/cmd/tailscale/cli/web.go index 44f5e357f..d5a806153 100644 --- a/cmd/tailscale/cli/web.go +++ b/cmd/tailscale/cli/web.go @@ -4,6 +4,7 @@ package cli import ( + "cmp" "context" "crypto/tls" _ "embed" @@ -21,7 +22,6 @@ import ( "github.com/peterbourgon/ff/v3/ffcli" "tailscale.com/client/web" "tailscale.com/ipn" - "tailscale.com/util/cmpx" ) var webCmd = &ffcli.Command{ @@ -160,5 +160,5 @@ func setRunWebClient(ctx context.Context, val bool) error { // urlOfListenAddr parses a given listen address into a formatted URL func urlOfListenAddr(addr string) string { host, port, _ := net.SplitHostPort(addr) - return fmt.Sprintf("http://%s", net.JoinHostPort(cmpx.Or(host, "127.0.0.1"), port)) + return fmt.Sprintf("http://%s", net.JoinHostPort(cmp.Or(host, "127.0.0.1"), port)) } diff --git a/cmd/tailscale/depaware.txt b/cmd/tailscale/depaware.txt index a0ee1e6c7..4013326cc 100644 --- a/cmd/tailscale/depaware.txt +++ b/cmd/tailscale/depaware.txt @@ -141,7 +141,6 @@ tailscale.com/cmd/tailscale dependencies: (generated by github.com/tailscale/dep tailscale.com/util/clientmetric from tailscale.com/net/netcheck+ tailscale.com/util/cloudenv from tailscale.com/net/dnscache+ tailscale.com/util/cmpver from tailscale.com/net/tshttpproxy+ - tailscale.com/util/cmpx from tailscale.com/cmd/tailscale/cli+ tailscale.com/util/ctxkey from tailscale.com/types/logger L 💣 tailscale.com/util/dirwalk from tailscale.com/metrics tailscale.com/util/dnsname from tailscale.com/cmd/tailscale/cli+ diff --git a/cmd/tailscaled/depaware.txt b/cmd/tailscaled/depaware.txt index 52387e849..655779772 100644 --- a/cmd/tailscaled/depaware.txt +++ b/cmd/tailscaled/depaware.txt @@ -347,7 +347,6 @@ tailscale.com/cmd/tailscaled dependencies: (generated by github.com/tailscale/de tailscale.com/util/clientmetric from tailscale.com/control/controlclient+ tailscale.com/util/cloudenv from tailscale.com/net/dns/resolver+ tailscale.com/util/cmpver from tailscale.com/net/dns+ - tailscale.com/util/cmpx from tailscale.com/derp/derphttp+ tailscale.com/util/ctxkey from tailscale.com/ipn/ipnlocal+ 💣 tailscale.com/util/deephash from tailscale.com/ipn/ipnlocal+ L 💣 tailscale.com/util/dirwalk from tailscale.com/metrics+ diff --git a/control/controlclient/map.go b/control/controlclient/map.go index 609e8ea0c..01e96f42f 100644 --- a/control/controlclient/map.go +++ b/control/controlclient/map.go @@ -4,6 +4,7 @@ package controlclient import ( + "cmp" "context" "encoding/json" "fmt" @@ -26,7 +27,6 @@ import ( "tailscale.com/types/ptr" "tailscale.com/types/views" "tailscale.com/util/clientmetric" - "tailscale.com/util/cmpx" "tailscale.com/util/mak" "tailscale.com/wgengine/filter" ) @@ -130,7 +130,7 @@ func (ms *mapSession) occasionallyPrintSummary(summary string) { } func (ms *mapSession) clock() tstime.Clock { - return cmpx.Or[tstime.Clock](ms.altClock, tstime.StdClock{}) + return cmp.Or[tstime.Clock](ms.altClock, tstime.StdClock{}) } func (ms *mapSession) Close() { @@ -171,7 +171,7 @@ func (ms *mapSession) HandleNonKeepAliveMapResponse(ctx context.Context, resp *t } // Call Node.InitDisplayNames on any changed nodes. - initDisplayNames(cmpx.Or(resp.Node.View(), ms.lastNode), resp) + initDisplayNames(cmp.Or(resp.Node.View(), ms.lastNode), resp) ms.patchifyPeersChanged(resp) diff --git a/derp/derphttp/derphttp_client.go b/derp/derphttp/derphttp_client.go index b2933ab4c..edaa67a3d 100644 --- a/derp/derphttp/derphttp_client.go +++ b/derp/derphttp/derphttp_client.go @@ -11,6 +11,7 @@ package derphttp import ( "bufio" + "cmp" "context" "crypto/rand" "crypto/tls" @@ -41,7 +42,6 @@ import ( "tailscale.com/tstime" "tailscale.com/types/key" "tailscale.com/types/logger" - "tailscale.com/util/cmpx" ) // Client is a DERP-over-HTTP client. @@ -701,7 +701,7 @@ func (c *Client) dialNode(ctx context.Context, n *tailcfg.DERPNode) (net.Conn, e // Start v4 dial } } - dst := cmpx.Or(dstPrimary, n.HostName) + dst := cmp.Or(dstPrimary, n.HostName) port := "443" if n.DERPPort != 0 { port = fmt.Sprint(n.DERPPort) diff --git a/ipn/ipnlocal/c2n_test.go b/ipn/ipnlocal/c2n_test.go index cc96909b4..cc31e284a 100644 --- a/ipn/ipnlocal/c2n_test.go +++ b/ipn/ipnlocal/c2n_test.go @@ -4,6 +4,7 @@ package ipnlocal import ( + "cmp" "crypto/x509" "encoding/json" "net/http/httptest" @@ -18,7 +19,6 @@ import ( "tailscale.com/tailcfg" "tailscale.com/tstest" "tailscale.com/types/logger" - "tailscale.com/util/cmpx" "tailscale.com/util/must" ) @@ -111,7 +111,7 @@ func TestHandleC2NTLSCertStatus(t *testing.T) { rec := httptest.NewRecorder() handleC2NTLSCertStatus(b, rec, httptest.NewRequest("GET", "/tls-cert-status?domain="+url.QueryEscape(tt.domain), nil)) res := rec.Result() - wantStatus := cmpx.Or(tt.wantStatus, 200) + wantStatus := cmp.Or(tt.wantStatus, 200) if res.StatusCode != wantStatus { t.Fatalf("status code = %v; want %v. Body: %s", res.Status, wantStatus, rec.Body.Bytes()) } diff --git a/ipn/ipnlocal/dnsconfig_test.go b/ipn/ipnlocal/dnsconfig_test.go index dbb40cd76..02db18ffe 100644 --- a/ipn/ipnlocal/dnsconfig_test.go +++ b/ipn/ipnlocal/dnsconfig_test.go @@ -4,6 +4,7 @@ package ipnlocal import ( + "cmp" "encoding/json" "net/netip" "reflect" @@ -16,7 +17,6 @@ import ( "tailscale.com/types/dnstype" "tailscale.com/types/netmap" "tailscale.com/util/cloudenv" - "tailscale.com/util/cmpx" "tailscale.com/util/dnsname" ) @@ -330,7 +330,7 @@ func TestDNSConfigForNetmap(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - verOS := cmpx.Or(tt.os, "linux") + verOS := cmp.Or(tt.os, "linux") var log tstest.MemLogger got := dnsConfigForNetmap(tt.nm, peersMap(tt.peers), tt.prefs.View(), log.Logf, verOS) if !reflect.DeepEqual(got, tt.want) { diff --git a/ipn/ipnlocal/local.go b/ipn/ipnlocal/local.go index 706ca524b..29e348b05 100644 --- a/ipn/ipnlocal/local.go +++ b/ipn/ipnlocal/local.go @@ -82,7 +82,6 @@ import ( "tailscale.com/types/preftype" "tailscale.com/types/ptr" "tailscale.com/types/views" - "tailscale.com/util/cmpx" "tailscale.com/util/deephash" "tailscale.com/util/dnsname" "tailscale.com/util/mak" @@ -4527,7 +4526,7 @@ func (b *LocalBackend) setNetMapLocked(nm *netmap.NetworkMap) { } var login string if nm != nil { - login = cmpx.Or(nm.UserProfiles[nm.User()].LoginName, "") + login = cmp.Or(nm.UserProfiles[nm.User()].LoginName, "") } b.netMap = nm b.updatePeersFromNetmapLocked(nm) diff --git a/ipn/ipnlocal/serve_test.go b/ipn/ipnlocal/serve_test.go index 4eeb882e8..45bd4bc2c 100644 --- a/ipn/ipnlocal/serve_test.go +++ b/ipn/ipnlocal/serve_test.go @@ -5,6 +5,7 @@ package ipnlocal import ( "bytes" + "cmp" "context" "crypto/sha256" "crypto/tls" @@ -29,7 +30,6 @@ import ( "tailscale.com/tsd" "tailscale.com/types/logid" "tailscale.com/types/netmap" - "tailscale.com/util/cmpx" "tailscale.com/util/mak" "tailscale.com/util/must" "tailscale.com/wgengine" @@ -157,7 +157,7 @@ func TestGetServeHandler(t *testing.T) { }, TLS: &tls.ConnectionState{ServerName: serverName}, } - port := cmpx.Or(tt.port, 443) + port := cmp.Or(tt.port, 443) req = req.WithContext(serveHTTPContextKey.WithValue(req.Context(), &serveHTTPContext{ DestPort: port, })) diff --git a/net/dnscache/messagecache.go b/net/dnscache/messagecache.go index ebbf20faa..040706b9c 100644 --- a/net/dnscache/messagecache.go +++ b/net/dnscache/messagecache.go @@ -4,6 +4,7 @@ package dnscache import ( + "cmp" "encoding/binary" "errors" "fmt" @@ -13,7 +14,6 @@ import ( "github.com/golang/groupcache/lru" "golang.org/x/net/dns/dnsmessage" - "tailscale.com/util/cmpx" ) // MessageCache is a cache that works at the DNS message layer, @@ -60,7 +60,7 @@ func (c *MessageCache) Flush() { // pruneLocked prunes down the cache size to the configured (or // default) max size. func (c *MessageCache) pruneLocked() { - max := cmpx.Or(c.cacheSizeSet, 500) + max := cmp.Or(c.cacheSizeSet, 500) for c.cache.Len() > max { c.cache.RemoveOldest() } diff --git a/net/netcheck/netcheck.go b/net/netcheck/netcheck.go index 0cea345c3..862743540 100644 --- a/net/netcheck/netcheck.go +++ b/net/netcheck/netcheck.go @@ -6,6 +6,7 @@ package netcheck import ( "bufio" + "cmp" "context" "crypto/tls" "errors" @@ -41,7 +42,6 @@ import ( "tailscale.com/types/opt" "tailscale.com/types/views" "tailscale.com/util/clientmetric" - "tailscale.com/util/cmpx" "tailscale.com/util/mak" ) @@ -447,7 +447,7 @@ func makeProbePlan(dm *tailcfg.DERPMap, ifState *interfaces.State, last *Report) do6 = false } n := reg.Nodes[try%len(reg.Nodes)] - prevLatency := cmpx.Or( + prevLatency := cmp.Or( last.RegionLatency[reg.RegionID]*120/100, defaultActiveRetransmitTime) delay := time.Duration(try) * prevLatency @@ -1602,7 +1602,7 @@ func (rs *reportState) runProbe(ctx context.Context, dm *tailcfg.DERPMap, probe // proto is 4 or 6 // If it returns nil, the node is skipped. func (c *Client) nodeAddr(ctx context.Context, n *tailcfg.DERPNode, proto probeProto) (ap netip.AddrPort) { - port := cmpx.Or(n.STUNPort, 3478) + port := cmp.Or(n.STUNPort, 3478) if port < 0 || port > 1<<16-1 { return } diff --git a/tailcfg/tailcfg.go b/tailcfg/tailcfg.go index 83038bb04..b058fb54e 100644 --- a/tailcfg/tailcfg.go +++ b/tailcfg/tailcfg.go @@ -7,6 +7,7 @@ package tailcfg import ( "bytes" + "cmp" "encoding/json" "errors" "fmt" @@ -22,7 +23,6 @@ import ( "tailscale.com/types/opt" "tailscale.com/types/structs" "tailscale.com/types/tkatype" - "tailscale.com/util/cmpx" "tailscale.com/util/dnsname" "tailscale.com/util/slicesx" ) @@ -475,7 +475,7 @@ func (n *Node) IsTagged() bool { // SharerOrUser Sharer if set, else User. func (n *Node) SharerOrUser() UserID { - return cmpx.Or(n.Sharer, n.User) + return cmp.Or(n.Sharer, n.User) } // IsTagged reports whether the node has any tags. diff --git a/tsweb/tsweb.go b/tsweb/tsweb.go index c69e65760..ebe4976fa 100644 --- a/tsweb/tsweb.go +++ b/tsweb/tsweb.go @@ -7,6 +7,7 @@ package tsweb import ( "bufio" "bytes" + "cmp" "context" "errors" "expvar" @@ -30,7 +31,6 @@ import ( "tailscale.com/net/tsaddr" "tailscale.com/tsweb/varz" "tailscale.com/types/logger" - "tailscale.com/util/cmpx" "tailscale.com/util/vizerror" ) @@ -156,7 +156,7 @@ func (h Port80Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { // Redirect authorized user to the debug handler. path = "/debug/" } - host := cmpx.Or(h.FQDN, r.Host) + host := cmp.Or(h.FQDN, r.Host) target := "https://" + host + path http.Redirect(w, r, target, http.StatusFound) } diff --git a/tsweb/varz/varz.go b/tsweb/varz/varz.go index c24873fc5..15a3be551 100644 --- a/tsweb/varz/varz.go +++ b/tsweb/varz/varz.go @@ -5,6 +5,7 @@ package varz import ( + "cmp" "expvar" "fmt" "io" @@ -18,7 +19,6 @@ import ( "time" "tailscale.com/metrics" - "tailscale.com/util/cmpx" "tailscale.com/version" ) @@ -100,10 +100,10 @@ func writePromExpVar(w io.Writer, prefix string, kv expvar.KeyValue) { switch v := kv.Value.(type) { case *expvar.Int: - fmt.Fprintf(w, "# TYPE %s %s\n%s %v\n", name, cmpx.Or(typ, "counter"), name, v.Value()) + fmt.Fprintf(w, "# TYPE %s %s\n%s %v\n", name, cmp.Or(typ, "counter"), name, v.Value()) return case *expvar.Float: - fmt.Fprintf(w, "# TYPE %s %s\n%s %v\n", name, cmpx.Or(typ, "gauge"), name, v.Value()) + fmt.Fprintf(w, "# TYPE %s %s\n%s %v\n", name, cmp.Or(typ, "gauge"), name, v.Value()) return case *metrics.Set: v.Do(func(kv expvar.KeyValue) { @@ -192,7 +192,7 @@ func writePromExpVar(w io.Writer, prefix string, kv expvar.KeyValue) { // IntMap uses expvar.Map on the inside, which presorts // keys. The output ordering is deterministic. v.Do(func(kv expvar.KeyValue) { - fmt.Fprintf(w, "%s{%s=%q} %v\n", name, cmpx.Or(v.Label, "label"), kv.Key, kv.Value) + fmt.Fprintf(w, "%s{%s=%q} %v\n", name, cmp.Or(v.Label, "label"), kv.Key, kv.Value) }) case *metrics.Histogram: v.PromExport(w, name) diff --git a/util/cmpx/cmpx.go b/util/cmpx/cmpx.go deleted file mode 100644 index d747f0a1d..000000000 --- a/util/cmpx/cmpx.go +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (c) Tailscale Inc & AUTHORS -// SPDX-License-Identifier: BSD-3-Clause - -// Package cmpx has code that will likely land in a future version of Go, but -// we want sooner. -package cmpx - -// Or returns the first non-zero element of list, or else returns the zero T. -// -// This is the proposal from -// https://github.com/golang/go/issues/60204#issuecomment-1581245334. -func Or[T comparable](list ...T) T { - // TODO(bradfitz): remove the comparable constraint so we can use this - // with funcs too and use reflect to see whether they're non-zero? 🤷‍♂️ - var zero T - for _, v := range list { - if v != zero { - return v - } - } - return zero -} diff --git a/util/cmpx/cmpx_test.go b/util/cmpx/cmpx_test.go deleted file mode 100644 index 768492dd7..000000000 --- a/util/cmpx/cmpx_test.go +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright (c) Tailscale Inc & AUTHORS -// SPDX-License-Identifier: BSD-3-Clause - -package cmpx - -import "testing" - -func TestOr(t *testing.T) { - if g, w := Or[string](), ""; g != w { - t.Errorf("got %v; want %v", g, w) - } - if g, w := Or[int](), 0; g != w { - t.Errorf("got %v; want %v", g, w) - } - if g, w := Or("", "foo", "bar"), "foo"; g != w { - t.Errorf("got %v; want %v", g, w) - } - if g, w := Or("foo", "bar"), "foo"; g != w { - t.Errorf("got %v; want %v", g, w) - } - if g, w := Or("", "", "bar"), "bar"; g != w { - t.Errorf("got %v; want %v", g, w) - } -} diff --git a/util/linuxfw/nftables.go b/util/linuxfw/nftables.go index 5c2723440..056563071 100644 --- a/util/linuxfw/nftables.go +++ b/util/linuxfw/nftables.go @@ -7,6 +7,7 @@ package linuxfw import ( + "cmp" "fmt" "sort" "strings" @@ -17,7 +18,6 @@ import ( "github.com/josharian/native" "golang.org/x/sys/unix" "tailscale.com/types/logger" - "tailscale.com/util/cmpx" ) // DebugNetfilter prints debug information about netfilter rules to the @@ -54,18 +54,18 @@ func DebugNetfilter(logf logger.Logf) error { for _, ex := range rule.Exprs { switch v := ex.(type) { case *expr.Meta: - key := cmpx.Or(metaKeyNames[v.Key], "UNKNOWN") + key := cmp.Or(metaKeyNames[v.Key], "UNKNOWN") logf("netfilter: Meta: key=%s source_register=%v register=%d", key, v.SourceRegister, v.Register) case *expr.Cmp: - op := cmpx.Or(cmpOpNames[v.Op], "UNKNOWN") + op := cmp.Or(cmpOpNames[v.Op], "UNKNOWN") logf("netfilter: Cmp: op=%s register=%d data=%s", op, v.Register, formatMaybePrintable(v.Data)) case *expr.Counter: // don't print case *expr.Verdict: - kind := cmpx.Or(verdictNames[v.Kind], "UNKNOWN") + kind := cmp.Or(verdictNames[v.Kind], "UNKNOWN") logf("netfilter: Verdict: kind=%s data=%s", kind, v.Chain) case *expr.Target: