net/interfaces: reconcile interface filtering with address printing in logs
The interface.State logging tried to only log interfaces which had interesting IPs, but the what-is-interesting checks differed between the code that gathered the interface names to print and the printing of their addresses.pull/1335/head
parent
c7e5ab8094
commit
20e66c5b92
|
@ -197,10 +197,9 @@ func (s *State) String() string {
|
||||||
fmt.Fprintf(&sb, "interfaces.State{defaultRoute=%v ifs={", s.DefaultRouteInterface)
|
fmt.Fprintf(&sb, "interfaces.State{defaultRoute=%v ifs={", s.DefaultRouteInterface)
|
||||||
ifs := make([]string, 0, len(s.InterfaceUp))
|
ifs := make([]string, 0, len(s.InterfaceUp))
|
||||||
for k := range s.InterfaceUp {
|
for k := range s.InterfaceUp {
|
||||||
if allLoopbackIPs(s.InterfaceIPs[k]) {
|
if anyInterestingIP(s.InterfaceIPs[k]) {
|
||||||
continue
|
ifs = append(ifs, k)
|
||||||
}
|
}
|
||||||
ifs = append(ifs, k)
|
|
||||||
}
|
}
|
||||||
sort.Slice(ifs, func(i, j int) bool {
|
sort.Slice(ifs, func(i, j int) bool {
|
||||||
upi, upj := s.InterfaceUp[ifs[i]], s.InterfaceUp[ifs[j]]
|
upi, upj := s.InterfaceUp[ifs[i]], s.InterfaceUp[ifs[j]]
|
||||||
|
@ -218,7 +217,7 @@ func (s *State) String() string {
|
||||||
fmt.Fprintf(&sb, "%s:[", ifName)
|
fmt.Fprintf(&sb, "%s:[", ifName)
|
||||||
needSpace := false
|
needSpace := false
|
||||||
for _, ip := range s.InterfaceIPs[ifName] {
|
for _, ip := range s.InterfaceIPs[ifName] {
|
||||||
if ip.IsLinkLocalUnicast() {
|
if !isInterestingIP(ip) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if needSpace {
|
if needSpace {
|
||||||
|
@ -403,14 +402,23 @@ var (
|
||||||
v6Global1 = mustCIDR("2000::/3")
|
v6Global1 = mustCIDR("2000::/3")
|
||||||
)
|
)
|
||||||
|
|
||||||
func allLoopbackIPs(ips []netaddr.IP) bool {
|
// anyInterestingIP reports ips contains any IP that matches
|
||||||
if len(ips) == 0 {
|
// isInterestingIP.
|
||||||
return false
|
func anyInterestingIP(ips []netaddr.IP) bool {
|
||||||
}
|
|
||||||
for _, ip := range ips {
|
for _, ip := range ips {
|
||||||
if !ip.IsLoopback() {
|
if isInterestingIP(ip) {
|
||||||
return false
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// isInterestingIP reports whether ip is an interesting IP that we
|
||||||
|
// should log in interfaces.State logging. We don't need to show
|
||||||
|
// localhost or link-local addresses.
|
||||||
|
func isInterestingIP(ip netaddr.IP) bool {
|
||||||
|
if ip.IsLoopback() || ip.IsLinkLocalUnicast() {
|
||||||
|
return false
|
||||||
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue