Check that IP is set before parsing

Machine is saved to db before it is assigned an ip, so we might have
empty ip fields coming back.
This commit is contained in:
Kristoffer Dalby 2021-08-03 07:42:11 +01:00
parent eda6e560c3
commit 73207decfd

View File

@ -121,6 +121,7 @@ func (h *Headscale) getUsedIPs() ([]netaddr.IP, error) {
ips := make([]netaddr.IP, len(addresses)) ips := make([]netaddr.IP, len(addresses))
for index, addr := range addresses { for index, addr := range addresses {
if addr != "" {
ip, err := netaddr.ParseIP(addr) ip, err := netaddr.ParseIP(addr)
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to parse ip from database, %w", err) return nil, fmt.Errorf("failed to parse ip from database, %w", err)
@ -128,6 +129,7 @@ func (h *Headscale) getUsedIPs() ([]netaddr.IP, error) {
ips[index] = ip ips[index] = ip
} }
}
return ips, nil return ips, nil
} }