-
Notifications
You must be signed in to change notification settings - Fork 6
/
net.go
40 lines (30 loc) · 819 Bytes
/
net.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Package net includes common net functions.
package net
import (
"net/netip"
"sort"
siderolabsnet "github.com/siderolabs/net"
)
// FilterLocalNetIPs filters list of IPs with the local subnets (rfc1918, rfc4193).
func FilterLocalNetIPs(ips []netip.Addr) ([]netip.Addr, error) {
localSubnets := []string{"10.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16", "fd00::/8"}
return siderolabsnet.FilterIPs(ips, localSubnets)
}
// SortedNodeIPs gets fists IP (excluded nodeIP) from the two sorted lists.
func SortedNodeIPs(nodeIP string, first, second []string) (res []string) {
sort.Strings(first)
sort.Strings(second)
for _, ip := range first {
if ip != nodeIP {
res = append(res, ip)
break
}
}
for _, ip := range second {
if ip != nodeIP {
res = append(res, ip)
break
}
}
return res
}