1
0
mirror of https://github.com/juanfont/headscale.git synced 2024-12-20 19:09:07 +01:00

Migrate routes to net/netip

This commit is contained in:
Juan Font Alonso 2022-09-02 00:06:19 +02:00
parent 290ec8bb19
commit 7af78152a4
2 changed files with 12 additions and 12 deletions

View File

@ -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
}

View File

@ -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{