mirror of
https://github.com/juanfont/headscale.git
synced 2024-12-22 07:57:34 +00:00
Migrate routes to net/netip
This commit is contained in:
parent
290ec8bb19
commit
7af78152a4
11
routes.go
11
routes.go
@ -2,8 +2,7 @@ package headscale
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net/netip"
|
||||||
"inet.af/netaddr"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -16,7 +15,7 @@ const (
|
|||||||
func (h *Headscale) GetAdvertisedNodeRoutes(
|
func (h *Headscale) GetAdvertisedNodeRoutes(
|
||||||
namespace string,
|
namespace string,
|
||||||
nodeName string,
|
nodeName string,
|
||||||
) (*[]netaddr.IPPrefix, error) {
|
) (*[]netip.Prefix, error) {
|
||||||
machine, err := h.GetMachine(namespace, nodeName)
|
machine, err := h.GetMachine(namespace, nodeName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -31,7 +30,7 @@ func (h *Headscale) GetAdvertisedNodeRoutes(
|
|||||||
func (h *Headscale) GetEnabledNodeRoutes(
|
func (h *Headscale) GetEnabledNodeRoutes(
|
||||||
namespace string,
|
namespace string,
|
||||||
nodeName string,
|
nodeName string,
|
||||||
) ([]netaddr.IPPrefix, error) {
|
) ([]netip.Prefix, error) {
|
||||||
machine, err := h.GetMachine(namespace, nodeName)
|
machine, err := h.GetMachine(namespace, nodeName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -47,7 +46,7 @@ func (h *Headscale) IsNodeRouteEnabled(
|
|||||||
nodeName string,
|
nodeName string,
|
||||||
routeStr string,
|
routeStr string,
|
||||||
) bool {
|
) bool {
|
||||||
route, err := netaddr.ParseIPPrefix(routeStr)
|
route, err := netip.ParsePrefix(routeStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@ -79,7 +78,7 @@ func (h *Headscale) EnableNodeRoute(
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
route, err := netaddr.ParseIPPrefix(routeStr)
|
route, err := netip.ParsePrefix(routeStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
package headscale
|
package headscale
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"net/netip"
|
||||||
|
|
||||||
"gopkg.in/check.v1"
|
"gopkg.in/check.v1"
|
||||||
"inet.af/netaddr"
|
|
||||||
"tailscale.com/tailcfg"
|
"tailscale.com/tailcfg"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -16,11 +17,11 @@ func (s *Suite) TestGetRoutes(c *check.C) {
|
|||||||
_, err = app.GetMachine("test", "test_get_route_machine")
|
_, err = app.GetMachine("test", "test_get_route_machine")
|
||||||
c.Assert(err, check.NotNil)
|
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)
|
c.Assert(err, check.IsNil)
|
||||||
|
|
||||||
hostInfo := tailcfg.Hostinfo{
|
hostInfo := tailcfg.Hostinfo{
|
||||||
RoutableIPs: []netaddr.IPPrefix{route},
|
RoutableIPs: []netip.Prefix{route},
|
||||||
}
|
}
|
||||||
|
|
||||||
machine := Machine{
|
machine := Machine{
|
||||||
@ -60,18 +61,18 @@ func (s *Suite) TestGetEnableRoutes(c *check.C) {
|
|||||||
_, err = app.GetMachine("test", "test_enable_route_machine")
|
_, err = app.GetMachine("test", "test_enable_route_machine")
|
||||||
c.Assert(err, check.NotNil)
|
c.Assert(err, check.NotNil)
|
||||||
|
|
||||||
route, err := netaddr.ParseIPPrefix(
|
route, err := netip.ParsePrefix(
|
||||||
"10.0.0.0/24",
|
"10.0.0.0/24",
|
||||||
)
|
)
|
||||||
c.Assert(err, check.IsNil)
|
c.Assert(err, check.IsNil)
|
||||||
|
|
||||||
route2, err := netaddr.ParseIPPrefix(
|
route2, err := netip.ParsePrefix(
|
||||||
"150.0.10.0/25",
|
"150.0.10.0/25",
|
||||||
)
|
)
|
||||||
c.Assert(err, check.IsNil)
|
c.Assert(err, check.IsNil)
|
||||||
|
|
||||||
hostInfo := tailcfg.Hostinfo{
|
hostInfo := tailcfg.Hostinfo{
|
||||||
RoutableIPs: []netaddr.IPPrefix{route, route2},
|
RoutableIPs: []netip.Prefix{route, route2},
|
||||||
}
|
}
|
||||||
|
|
||||||
machine := Machine{
|
machine := Machine{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user