From 842c28adff914d6b6e6ba6cc4461df99b8f88175 Mon Sep 17 00:00:00 2001 From: Benjamin George Roberts Date: Mon, 5 Sep 2022 09:33:53 +1000 Subject: [PATCH] replace netaddr usage with netip --- acls_types.go | 7 ++++--- machine.go | 2 +- machine_test.go | 10 +++++----- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/acls_types.go b/acls_types.go index 0289e099..6ee5bfdb 100644 --- a/acls_types.go +++ b/acls_types.go @@ -111,7 +111,7 @@ func (policy ACLPolicy) IsZero() bool { // Returns the list of autoApproving namespaces, groups or tags for a given IPPrefix func (autoApprovers *AutoApprovers) GetRouteApprovers( - prefix netaddr.IPPrefix, + prefix netip.Prefix, ) ([]string, error) { if prefix.Bits() == 0 { return autoApprovers.ExitNode, nil // 0.0.0.0/0, ::/0 or equivalent @@ -120,13 +120,14 @@ func (autoApprovers *AutoApprovers) GetRouteApprovers( approverAliases := []string{} for autoApprovedPrefix, autoApproverAliases := range autoApprovers.Routes { - autoApprovedPrefix, err := netaddr.ParseIPPrefix(autoApprovedPrefix) + autoApprovedPrefix, err := netip.ParsePrefix(autoApprovedPrefix) + if err != nil { return nil, err } if autoApprovedPrefix.Bits() >= prefix.Bits() && - autoApprovedPrefix.Contains(prefix.IP()) { + autoApprovedPrefix.Contains(prefix.Masked().Addr()) { approverAliases = append(approverAliases, autoApproverAliases...) } } diff --git a/machine.go b/machine.go index 54984d8d..5b53ef22 100644 --- a/machine.go +++ b/machine.go @@ -936,7 +936,7 @@ func (h *Headscale) EnableAutoApprovedRoutes(machine *Machine) error { return nil // This machine has no IPAddresses, so can't possibly match any autoApprovers ACLs } - approvedRoutes := make([]netaddr.IPPrefix, 0, len(machine.HostInfo.RoutableIPs)) + approvedRoutes := make([]netip.Prefix, 0, len(machine.HostInfo.RoutableIPs)) thisMachine := []Machine{*machine} for _, advertisedRoute := range machine.HostInfo.RoutableIPs { diff --git a/machine_test.go b/machine_test.go index e8c9e9a0..7d50db79 100644 --- a/machine_test.go +++ b/machine_test.go @@ -1063,9 +1063,9 @@ func (s *Suite) TestAutoApproveRoutes(c *check.C) { nodeKey := key.NewNode() - defaultRoute := netaddr.MustParseIPPrefix("0.0.0.0/0") - route1 := netaddr.MustParseIPPrefix("10.10.0.0/16") - route2 := netaddr.MustParseIPPrefix("10.11.0.0/16") + defaultRoute := netip.MustParsePrefix("0.0.0.0/0") + route1 := netip.MustParsePrefix("10.10.0.0/16") + route2 := netip.MustParsePrefix("10.11.0.0/16") machine := Machine{ ID: 0, @@ -1078,9 +1078,9 @@ func (s *Suite) TestAutoApproveRoutes(c *check.C) { AuthKeyID: uint(pak.ID), HostInfo: HostInfo{ RequestTags: []string{"tag:exit"}, - RoutableIPs: []netaddr.IPPrefix{defaultRoute, route1, route2}, + RoutableIPs: []netip.Prefix{defaultRoute, route1, route2}, }, - IPAddresses: []netaddr.IP{netaddr.MustParseIP("100.64.0.1")}, + IPAddresses: []netip.Addr{netip.MustParseAddr("100.64.0.1")}, } app.db.Save(&machine)