From 198e92c08f27aa0eb6b69b04f10f7c05bde7fd26 Mon Sep 17 00:00:00 2001 From: Juan Font Alonso Date: Sat, 3 Sep 2022 23:46:14 +0200 Subject: [PATCH] Remove dependency on netaddr --- acls.go | 6 +++--- acls_types.go | 4 ++-- cmd/headscale/cli/nodes.go | 4 ++-- go.mod | 3 --- go.sum | 6 ------ utils_test.go | 3 +-- 6 files changed, 8 insertions(+), 18 deletions(-) diff --git a/acls.go b/acls.go index 62cd04a..0b365c1 100644 --- a/acls.go +++ b/acls.go @@ -5,6 +5,7 @@ import ( "errors" "fmt" "io" + "net/netip" "os" "path/filepath" "strconv" @@ -13,7 +14,6 @@ import ( "github.com/rs/zerolog/log" "github.com/tailscale/hujson" "gopkg.in/yaml.v3" - "inet.af/netaddr" "tailscale.com/tailcfg" ) @@ -394,13 +394,13 @@ func expandAlias( } // if alias is an IP - ip, err := netaddr.ParseIP(alias) + ip, err := netip.ParseAddr(alias) if err == nil { return []string{ip.String()}, nil } // if alias is an CIDR - cidr, err := netaddr.ParseIPPrefix(alias) + cidr, err := netip.ParsePrefix(alias) if err == nil { return []string{cidr.String()}, nil } diff --git a/acls_types.go b/acls_types.go index 8ffa12f..04c6630 100644 --- a/acls_types.go +++ b/acls_types.go @@ -42,7 +42,7 @@ type ACLTest struct { Deny []string `json:"deny,omitempty" yaml:"deny,omitempty"` } -// UnmarshalJSON allows to parse the Hosts directly into netaddr objects. +// UnmarshalJSON allows to parse the Hosts directly into netip objects. func (hosts *Hosts) UnmarshalJSON(data []byte) error { newHosts := Hosts{} hostIPPrefixMap := make(map[string]string) @@ -71,7 +71,7 @@ func (hosts *Hosts) UnmarshalJSON(data []byte) error { return nil } -// UnmarshalYAML allows to parse the Hosts directly into netaddr objects. +// UnmarshalYAML allows to parse the Hosts directly into netip objects. func (hosts *Hosts) UnmarshalYAML(data []byte) error { newHosts := Hosts{} hostIPPrefixMap := make(map[string]string) diff --git a/cmd/headscale/cli/nodes.go b/cmd/headscale/cli/nodes.go index a4f2a69..375f274 100644 --- a/cmd/headscale/cli/nodes.go +++ b/cmd/headscale/cli/nodes.go @@ -3,6 +3,7 @@ package cli import ( "fmt" "log" + "net/netip" "strconv" "strings" "time" @@ -13,7 +14,6 @@ import ( "github.com/pterm/pterm" "github.com/spf13/cobra" "google.golang.org/grpc/status" - "inet.af/netaddr" "tailscale.com/types/key" ) @@ -557,7 +557,7 @@ func nodesToPtables( var IPV4Address string var IPV6Address string for _, addr := range machine.IpAddresses { - if netaddr.MustParseIP(addr).Is4() { + if netip.MustParseAddr(addr).Is4() { IPV4Address = addr } else { IPV6Address = addr diff --git a/go.mod b/go.mod index 7fff0bb..477bec2 100644 --- a/go.mod +++ b/go.mod @@ -41,7 +41,6 @@ require ( gopkg.in/yaml.v3 v3.0.1 gorm.io/driver/postgres v1.3.8 gorm.io/gorm v1.23.8 - inet.af/netaddr v0.0.0-20220617031823-097006376321 tailscale.com v1.30.0 ) @@ -132,9 +131,7 @@ require ( github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect github.com/xeipuuv/gojsonschema v1.2.0 // indirect github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 // indirect - go4.org/intern v0.0.0-20211027215823-ae77deb06f29 // indirect go4.org/mem v0.0.0-20210711025021-927187094b94 // indirect - go4.org/unsafe/assume-no-moving-gc v0.0.0-20220617031537-928513b29760 // indirect golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect golang.org/x/term v0.0.0-20220411215600-e5f449aeb171 // indirect golang.org/x/text v0.3.7 // indirect diff --git a/go.sum b/go.sum index 62119cb..fc74e80 100644 --- a/go.sum +++ b/go.sum @@ -209,7 +209,6 @@ github.com/docker/go-units v0.4.0 h1:3uh0PgVws3nIA0Q+MwDC8yjEPf9zjRfZZWXZYDct3Tw github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk= github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk= -github.com/dvyukov/go-fuzz v0.0.0-20210103155950-6a8e9d1f2415/go.mod h1:11Gm+ccJnvAhCNLlf5+cS9KjtbaD5I5zaZpFMsTHWTw= github.com/efekarakus/termcolor v1.0.1 h1:YAKFO3bnLrqZGTWyNLcYoSIAQFKVOmbqmDnwsU/znzg= github.com/efekarakus/termcolor v1.0.1/go.mod h1:AitrZNrE4nPO538fRsqf+p0WgLdAsGN5pUNrHEPsEMM= github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= @@ -1028,14 +1027,11 @@ go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= go.uber.org/zap v1.13.0/go.mod h1:zwrFLgMcdUuIBviXEYEH1YKNaOBnKXsx2IPda5bBwHM= go.uber.org/zap v1.17.0/go.mod h1:MXVU+bhUf/A7Xi2HNOnopQOrmycQ5Ih87HtOu4q5SSo= go4.org/intern v0.0.0-20211027215823-ae77deb06f29 h1:UXLjNohABv4S58tHmeuIZDO6e3mHpW2Dx33gaNt03LE= -go4.org/intern v0.0.0-20211027215823-ae77deb06f29/go.mod h1:cS2ma+47FKrLPdXFpr7CuxiTW3eyJbWew4qx0qtQWDA= go4.org/mem v0.0.0-20210711025021-927187094b94 h1:OAAkygi2Js191AJP1Ds42MhJRgeofeKGjuoUqNp1QC4= go4.org/mem v0.0.0-20210711025021-927187094b94/go.mod h1:reUoABIJ9ikfM5sgtSF3Wushcza7+WeD01VB9Lirh3g= go4.org/netipx v0.0.0-20220725152314-7e7bdc8411bf h1:IdwJUzqoIo5lkr2EOyKoe5qipUaEjbOKKY5+fzPBZ3A= go4.org/netipx v0.0.0-20220725152314-7e7bdc8411bf/go.mod h1:+QXzaoURFd0rGDIjDNpyIkv+F9R7EmeKorvlKRnhqgA= -go4.org/unsafe/assume-no-moving-gc v0.0.0-20211027215541-db492cf91b37/go.mod h1:FftLjUGFEDu5k8lt0ddY+HcrH/qU/0qk+H8j9/nTl3E= go4.org/unsafe/assume-no-moving-gc v0.0.0-20220617031537-928513b29760 h1:FyBZqvoA/jbNzuAWLQE2kG820zMAkcilx6BMjGbL/E4= -go4.org/unsafe/assume-no-moving-gc v0.0.0-20220617031537-928513b29760/go.mod h1:FftLjUGFEDu5k8lt0ddY+HcrH/qU/0qk+H8j9/nTl3E= golang.org/x/crypto v0.0.0-20180501155221-613d6eafa307/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= @@ -1638,8 +1634,6 @@ honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9 honnef.co/go/tools v0.2.1/go.mod h1:lPVVZ2BS5TfnjLyizF7o7hv7j9/L+8cZY2hLyjP9cGY= honnef.co/go/tools v0.4.0-0.dev.0.20220404092545-59d7a2877f83 h1:lZ9GIYaU+o5+X6ST702I/Ntyq9Y2oIMZ42rBQpem64A= howett.net/plist v1.0.0 h1:7CrbWYbPPO/PyNy38b2EB/+gYbjCe2DXBxgtOOZbSQM= -inet.af/netaddr v0.0.0-20220617031823-097006376321 h1:B4dC8ySKTQXasnjDTMsoCMf1sQG4WsMej0WXaHxunmU= -inet.af/netaddr v0.0.0-20220617031823-097006376321/go.mod h1:OIezDfdzOgFhuw4HuWapWq2e9l0H9tK4F1j+ETRtF3k= lukechampine.com/uint128 v1.1.1/go.mod h1:c4eWIwlEGaxC/+H1VguhU4PHXNWDCDMUlWdIWl2j1gk= modernc.org/cc/v3 v3.36.0/go.mod h1:NFUHyPn4ekoC/JHeZFfZurN6ixxawE1BnVonP/oahEI= modernc.org/ccgo/v3 v3.0.0-20220428102840-41399a37e894/go.mod h1:eI31LL8EwEBKPpNpA4bU1/i+sKOwOrQy8D87zWUcRZc= diff --git a/utils_test.go b/utils_test.go index 13f9f0b..5e9710c 100644 --- a/utils_test.go +++ b/utils_test.go @@ -5,7 +5,6 @@ import ( "go4.org/netipx" "gopkg.in/check.v1" - "inet.af/netaddr" ) func (s *Suite) TestGetAvailableIp(c *check.C) { @@ -156,7 +155,7 @@ func (s *Suite) TestGetAvailableIpMachineWithoutIP(c *check.C) { ips, err := app.getAvailableIPs() c.Assert(err, check.IsNil) - expected := netaddr.MustParseIP("10.27.0.1") + expected := netip.MustParseAddr("10.27.0.1") c.Assert(len(ips), check.Equals, 1) c.Assert(ips[0].String(), check.Equals, expected.String())