mirror of
https://github.com/juanfont/headscale.git
synced 2025-09-06 17:54:31 +02:00
remove compareprefix, use tsaddr version
Signed-off-by: Kristoffer Dalby <kristoffer@tailscale.com>
This commit is contained in:
parent
17fa0bcaa5
commit
d4de4e99be
@ -1153,6 +1153,7 @@ func (h *Headscale) loadPolicyManager() error {
|
|||||||
errOut = fmt.Errorf("creating policy manager: %w", err)
|
errOut = fmt.Errorf("creating policy manager: %w", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
log.Info().Msgf("Using policy manager version: %d", h.polMan.Version())
|
||||||
|
|
||||||
if len(nodes) > 0 {
|
if len(nodes) > 0 {
|
||||||
_, err = h.polMan.SSHPolicy(nodes[0])
|
_, err = h.polMan.SSHPolicy(nodes[0])
|
||||||
|
@ -22,6 +22,7 @@ import (
|
|||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
"gorm.io/gorm/logger"
|
"gorm.io/gorm/logger"
|
||||||
"gorm.io/gorm/schema"
|
"gorm.io/gorm/schema"
|
||||||
|
"tailscale.com/net/tsaddr"
|
||||||
"tailscale.com/util/set"
|
"tailscale.com/util/set"
|
||||||
"zgo.at/zcache/v2"
|
"zgo.at/zcache/v2"
|
||||||
)
|
)
|
||||||
@ -655,7 +656,7 @@ AND auth_key_id NOT IN (
|
|||||||
}
|
}
|
||||||
|
|
||||||
for nodeID, routes := range nodeRoutes {
|
for nodeID, routes := range nodeRoutes {
|
||||||
slices.SortFunc(routes, util.ComparePrefix)
|
tsaddr.SortPrefixes(routes)
|
||||||
slices.Compact(routes)
|
slices.Compact(routes)
|
||||||
|
|
||||||
data, err := json.Marshal(routes)
|
data, err := json.Marshal(routes)
|
||||||
|
@ -19,6 +19,7 @@ import (
|
|||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"gopkg.in/check.v1"
|
"gopkg.in/check.v1"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
|
"tailscale.com/net/tsaddr"
|
||||||
"tailscale.com/tailcfg"
|
"tailscale.com/tailcfg"
|
||||||
"tailscale.com/types/key"
|
"tailscale.com/types/key"
|
||||||
"tailscale.com/types/ptr"
|
"tailscale.com/types/ptr"
|
||||||
|
@ -348,7 +348,7 @@ func (api headscaleV1APIServer) SetApprovedRoutes(
|
|||||||
routes = append(routes, prefix)
|
routes = append(routes, prefix)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
slices.SortFunc(routes, util.ComparePrefix)
|
tsaddr.SortPrefixes(routes)
|
||||||
slices.Compact(routes)
|
slices.Compact(routes)
|
||||||
|
|
||||||
node, err := db.Write(api.h.db.DB, func(tx *gorm.DB) (*types.Node, error) {
|
node, err := db.Write(api.h.db.DB, func(tx *gorm.DB) (*types.Node, error) {
|
||||||
|
@ -16,24 +16,6 @@ func GrpcSocketDialer(ctx context.Context, addr string) (net.Conn, error) {
|
|||||||
return d.DialContext(ctx, "unix", addr)
|
return d.DialContext(ctx, "unix", addr)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(kradalby): Remove when in stdlib;
|
|
||||||
// https://github.com/golang/go/issues/61642
|
|
||||||
// Compare returns an integer comparing two prefixes.
|
|
||||||
// The result will be 0 if p == p2, -1 if p < p2, and +1 if p > p2.
|
|
||||||
// Prefixes sort first by validity (invalid before valid), then
|
|
||||||
// address family (IPv4 before IPv6), then prefix length, then
|
|
||||||
// address.
|
|
||||||
func ComparePrefix(p, p2 netip.Prefix) int {
|
|
||||||
if c := cmp.Compare(p.Addr().BitLen(), p2.Addr().BitLen()); c != 0 {
|
|
||||||
return c
|
|
||||||
}
|
|
||||||
if c := cmp.Compare(p.Bits(), p2.Bits()); c != 0 {
|
|
||||||
return c
|
|
||||||
}
|
|
||||||
|
|
||||||
return p.Addr().Compare(p2.Addr())
|
|
||||||
}
|
|
||||||
|
|
||||||
func PrefixesToString(prefixes []netip.Prefix) []string {
|
func PrefixesToString(prefixes []netip.Prefix) []string {
|
||||||
ret := make([]string, 0, len(prefixes))
|
ret := make([]string, 0, len(prefixes))
|
||||||
for _, prefix := range prefixes {
|
for _, prefix := range prefixes {
|
||||||
|
Loading…
Reference in New Issue
Block a user