Skip to content

Commit

Permalink
replace netaddr usage with netip
Browse files Browse the repository at this point in the history
  • Loading branch information
tsujamin committed Sep 4, 2022
1 parent 9810d84 commit 842c28a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
7 changes: 4 additions & 3 deletions acls_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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...)
}
}
Expand Down
2 changes: 1 addition & 1 deletion machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 5 additions & 5 deletions machine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
Expand Down

0 comments on commit 842c28a

Please sign in to comment.