Skip to content

Commit

Permalink
An empty IP can be represented using an empty slice or nil, so check …
Browse files Browse the repository at this point in the history
…for both.

This code is inspired from commit 3720584 where isEmptyIP is fixed to handle both nil and "" IP

An incorrectly performed IP-emptiness check may lead to zedrouter trying to stop metadata server which has not been yet started, resulting in panic triggered from log.Fatal.

Signed-off-by: Pramodh Pallapothu <pramodh@zededa.com>
  • Loading branch information
Pramodh Pallapothu authored and milan-zededa committed Jul 25, 2023
1 parent 24c45ff commit bae0ecd
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pkg/pillar/cmd/zedrouter/dnsmasq.go
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ func checkAndPublishDhcpLeases(ctx *zedrouterContext) {
}

func isEmptyIP(ip net.IP) bool {
return ip.Equal(net.IP{})
return ip == nil || ip.Equal(net.IP{})
}

func ipListEqual(one []net.IP, two []string) bool {
Expand Down
4 changes: 2 additions & 2 deletions pkg/pillar/cmd/zedrouter/networkinstance.go
Original file line number Diff line number Diff line change
Expand Up @@ -1083,7 +1083,7 @@ func handleMetaDataServerChange(ctx *zedrouterContext, dnstatus *types.DeviceNet
if addr.String() == status.MetaDataServerIP {
continue
}
if (err != nil || (addr.String() == "" && status.MetaDataServerIP != "")) &&
if (err != nil || (isEmptyIP(addr) && status.MetaDataServerIP != "")) &&
status.Server4Running == true {
// Bridge had a valid IP and it is gone now
deleteServer4(ctx, status.MetaDataServerIP, status.BridgeName)
Expand All @@ -1102,7 +1102,7 @@ func handleMetaDataServerChange(ctx *zedrouterContext, dnstatus *types.DeviceNet
status.MetaDataServerIP, status.BridgeName)
status.Server4Running = false
}
if addr.String() != "" {
if !isEmptyIP(addr) {
// Start new meta-data server
status.MetaDataServerIP = addr.String()
err := createServer4(ctx, status.MetaDataServerIP, status.BridgeName)
Expand Down

0 comments on commit bae0ecd

Please sign in to comment.