mirror of
https://github.com/juanfont/headscale.git
synced 2024-11-26 17:03:06 +00:00
utils: extract GetIPPrefixEndpoints from anonymous function
This commit is contained in:
parent
bf7ee78324
commit
6220836050
1 changed files with 8 additions and 5 deletions
13
utils.go
13
utils.go
|
@ -147,6 +147,13 @@ func (h *Headscale) getAvailableIPs() (ips MachineAddresses, err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetIPPrefixEndpoints(na netaddr.IPPrefix) (network, broadcast netaddr.IP) {
|
||||||
|
ipRange := na.Range()
|
||||||
|
network = ipRange.From()
|
||||||
|
broadcast = ipRange.To()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: Is this concurrency safe?
|
// TODO: Is this concurrency safe?
|
||||||
// What would happen if multiple hosts were to register at the same time?
|
// What would happen if multiple hosts were to register at the same time?
|
||||||
// Would we attempt to assign the same addresses to multiple nodes?
|
// Would we attempt to assign the same addresses to multiple nodes?
|
||||||
|
@ -156,11 +163,7 @@ func (h *Headscale) getAvailableIP(ipPrefix netaddr.IPPrefix) (*netaddr.IP, erro
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
ipPrefixNetworkAddress, ipPrefixBroadcastAddress := func() (netaddr.IP, netaddr.IP) {
|
ipPrefixNetworkAddress, ipPrefixBroadcastAddress := GetIPPrefixEndpoints(ipPrefix)
|
||||||
ipRange := ipPrefix.Range()
|
|
||||||
|
|
||||||
return ipRange.From(), ipRange.To()
|
|
||||||
}()
|
|
||||||
|
|
||||||
// Get the first IP in our prefix
|
// Get the first IP in our prefix
|
||||||
ip := ipPrefixNetworkAddress.Next()
|
ip := ipPrefixNetworkAddress.Next()
|
||||||
|
|
Loading…
Reference in a new issue