mirror of
https://github.com/juanfont/headscale.git
synced 2024-12-20 19:09:07 +01:00
Add a set of ip prefix convert helpers
This commit is contained in:
parent
94dbaa6822
commit
9acc3e0e73
35
utils.go
35
utils.go
@ -163,3 +163,38 @@ func GrpcSocketDialer(ctx context.Context, addr string) (net.Conn, error) {
|
||||
var d net.Dialer
|
||||
return d.DialContext(ctx, "unix", addr)
|
||||
}
|
||||
|
||||
func ipPrefixToString(prefixes []netaddr.IPPrefix) []string {
|
||||
result := make([]string, len(prefixes))
|
||||
|
||||
for index, prefix := range prefixes {
|
||||
result[index] = prefix.String()
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
func stringToIpPrefix(prefixes []string) ([]netaddr.IPPrefix, error) {
|
||||
result := make([]netaddr.IPPrefix, len(prefixes))
|
||||
|
||||
for index, prefixStr := range prefixes {
|
||||
prefix, err := netaddr.ParseIPPrefix(prefixStr)
|
||||
if err != nil {
|
||||
return []netaddr.IPPrefix{}, err
|
||||
}
|
||||
|
||||
result[index] = prefix
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func containsIpPrefix(prefixes []netaddr.IPPrefix, prefix netaddr.IPPrefix) bool {
|
||||
for _, p := range prefixes {
|
||||
if prefix == p {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user