Skip to content

Commit bae0ecd

Browse files
Pramodh Pallapothumilan-zededa
authored andcommitted
An empty IP can be represented using an empty slice or nil, so check 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 <[email protected]>
1 parent 24c45ff commit bae0ecd

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

pkg/pillar/cmd/zedrouter/dnsmasq.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ func checkAndPublishDhcpLeases(ctx *zedrouterContext) {
573573
}
574574

575575
func isEmptyIP(ip net.IP) bool {
576-
return ip.Equal(net.IP{})
576+
return ip == nil || ip.Equal(net.IP{})
577577
}
578578

579579
func ipListEqual(one []net.IP, two []string) bool {

pkg/pillar/cmd/zedrouter/networkinstance.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,7 +1083,7 @@ func handleMetaDataServerChange(ctx *zedrouterContext, dnstatus *types.DeviceNet
10831083
if addr.String() == status.MetaDataServerIP {
10841084
continue
10851085
}
1086-
if (err != nil || (addr.String() == "" && status.MetaDataServerIP != "")) &&
1086+
if (err != nil || (isEmptyIP(addr) && status.MetaDataServerIP != "")) &&
10871087
status.Server4Running == true {
10881088
// Bridge had a valid IP and it is gone now
10891089
deleteServer4(ctx, status.MetaDataServerIP, status.BridgeName)
@@ -1102,7 +1102,7 @@ func handleMetaDataServerChange(ctx *zedrouterContext, dnstatus *types.DeviceNet
11021102
status.MetaDataServerIP, status.BridgeName)
11031103
status.Server4Running = false
11041104
}
1105-
if addr.String() != "" {
1105+
if !isEmptyIP(addr) {
11061106
// Start new meta-data server
11071107
status.MetaDataServerIP = addr.String()
11081108
err := createServer4(ctx, status.MetaDataServerIP, status.BridgeName)

0 commit comments

Comments
 (0)