m/n/core/network/dhcp4c: fix logic bug in DNSServers
This previously accepted all non-undefined (0.0.0.0) IPs as servers on
account of the `|| ip4Num != 0` in the condition. That's unnecessary
anyways, so let's drop it.
While we're in there I also changed the deduplicating map from a
map[uint32]struct{} to a map[uint32]bool, making the code a bit shorter.
Change-Id: Ic15cb96217a300913ebc58580d4314a6449da923
Reviewed-on: https://review.monogon.dev/c/monogon/+/516
Reviewed-by: Sergiusz Bazanski <serge@monogon.tech>
diff --git a/metropolis/node/core/network/dhcp4c/lease.go b/metropolis/node/core/network/dhcp4c/lease.go
index 86daa0c..354a3e8 100644
--- a/metropolis/node/core/network/dhcp4c/lease.go
+++ b/metropolis/node/core/network/dhcp4c/lease.go
@@ -227,14 +227,14 @@
}
rawServers := dhcpv4.GetIPs(dhcpv4.OptionDomainNameServer, l.Options)
var servers DNSServers
- serversSeenMap := make(map[uint32]struct{})
+ serversSeenMap := make(map[uint32]bool)
for _, s := range rawServers {
ip4Num := ip4toInt(s)
- if s.IsGlobalUnicast() || s.IsLinkLocalUnicast() || ip4Num != 0 {
- if _, ok := serversSeenMap[ip4Num]; ok {
+ if s.IsGlobalUnicast() || s.IsLinkLocalUnicast() {
+ if serversSeenMap[ip4Num] {
continue
}
- serversSeenMap[ip4Num] = struct{}{}
+ serversSeenMap[ip4Num] = true
servers = append(servers, s)
}
}