mirror of
https://github.com/juanfont/headscale.git
synced 2024-11-23 18:15:26 +00:00
replace netaddr usage with netip
This commit is contained in:
parent
9810d84e2d
commit
842c28adff
@ -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...)
|
||||
}
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user