From 7af78152a45fb6c948700ddd3b9187d94ffd96b1 Mon Sep 17 00:00:00 2001 From: Juan Font Alonso Date: Fri, 2 Sep 2022 00:06:19 +0200 Subject: [PATCH] Migrate routes to net/netip --- routes.go | 11 +++++------ routes_test.go | 13 +++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/routes.go b/routes.go index 23217ca..676c79b 100644 --- a/routes.go +++ b/routes.go @@ -2,8 +2,7 @@ package headscale import ( "fmt" - - "inet.af/netaddr" + "net/netip" ) const ( @@ -16,7 +15,7 @@ const ( func (h *Headscale) GetAdvertisedNodeRoutes( namespace string, nodeName string, -) (*[]netaddr.IPPrefix, error) { +) (*[]netip.Prefix, error) { machine, err := h.GetMachine(namespace, nodeName) if err != nil { return nil, err @@ -31,7 +30,7 @@ func (h *Headscale) GetAdvertisedNodeRoutes( func (h *Headscale) GetEnabledNodeRoutes( namespace string, nodeName string, -) ([]netaddr.IPPrefix, error) { +) ([]netip.Prefix, error) { machine, err := h.GetMachine(namespace, nodeName) if err != nil { return nil, err @@ -47,7 +46,7 @@ func (h *Headscale) IsNodeRouteEnabled( nodeName string, routeStr string, ) bool { - route, err := netaddr.ParseIPPrefix(routeStr) + route, err := netip.ParsePrefix(routeStr) if err != nil { return false } @@ -79,7 +78,7 @@ func (h *Headscale) EnableNodeRoute( return err } - route, err := netaddr.ParseIPPrefix(routeStr) + route, err := netip.ParsePrefix(routeStr) if err != nil { return err } diff --git a/routes_test.go b/routes_test.go index 89b712b..f1ae388 100644 --- a/routes_test.go +++ b/routes_test.go @@ -1,8 +1,9 @@ package headscale import ( + "net/netip" + "gopkg.in/check.v1" - "inet.af/netaddr" "tailscale.com/tailcfg" ) @@ -16,11 +17,11 @@ func (s *Suite) TestGetRoutes(c *check.C) { _, err = app.GetMachine("test", "test_get_route_machine") c.Assert(err, check.NotNil) - route, err := netaddr.ParseIPPrefix("10.0.0.0/24") + route, err := netip.ParsePrefix("10.0.0.0/24") c.Assert(err, check.IsNil) hostInfo := tailcfg.Hostinfo{ - RoutableIPs: []netaddr.IPPrefix{route}, + RoutableIPs: []netip.Prefix{route}, } machine := Machine{ @@ -60,18 +61,18 @@ func (s *Suite) TestGetEnableRoutes(c *check.C) { _, err = app.GetMachine("test", "test_enable_route_machine") c.Assert(err, check.NotNil) - route, err := netaddr.ParseIPPrefix( + route, err := netip.ParsePrefix( "10.0.0.0/24", ) c.Assert(err, check.IsNil) - route2, err := netaddr.ParseIPPrefix( + route2, err := netip.ParsePrefix( "150.0.10.0/25", ) c.Assert(err, check.IsNil) hostInfo := tailcfg.Hostinfo{ - RoutableIPs: []netaddr.IPPrefix{route, route2}, + RoutableIPs: []netip.Prefix{route, route2}, } machine := Machine{