| 37 | } |
| 38 | |
| 39 | func generateInterfacesReport(st *interfaces.State) (report InterfacesReport) { |
| 40 | report.Severity = health.SeverityOK |
| 41 | for name, iface := range st.Interface { |
| 42 | // macOS has a ton of random interfaces, so to keep things helpful, let's filter out any |
| 43 | // that: |
| 44 | // |
| 45 | // - are not enabled |
| 46 | // - don't have any addresses |
| 47 | // - have only link-local addresses (e.g. fe80:...) |
| 48 | if (iface.Flags & net.FlagUp) == 0 { |
| 49 | continue |
| 50 | } |
| 51 | addrs := st.InterfaceIPs[name] |
| 52 | if len(addrs) == 0 { |
| 53 | continue |
| 54 | } |
| 55 | var r bool |
| 56 | healthIface := Interface{ |
| 57 | Name: iface.Name, |
| 58 | MTU: iface.MTU, |
| 59 | } |
| 60 | for _, addr := range addrs { |
| 61 | healthIface.Addresses = append(healthIface.Addresses, addr.String()) |
| 62 | if addr.Addr().IsLinkLocalUnicast() || addr.Addr().IsLinkLocalMulticast() { |
| 63 | continue |
| 64 | } |
| 65 | r = true |
| 66 | } |
| 67 | if !r { |
| 68 | continue |
| 69 | } |
| 70 | report.Interfaces = append(report.Interfaces, healthIface) |
| 71 | // Some loopback interfaces on Windows have a negative MTU, which we can |
| 72 | // safely ignore in diagnostics. |
| 73 | if iface.MTU > 0 && iface.MTU < safeMTU { |
| 74 | report.Severity = health.SeverityWarning |
| 75 | report.Warnings = append(report.Warnings, |
| 76 | health.Messagef(health.CodeInterfaceSmallMTU, |
| 77 | "Network interface %s has MTU %d (less than %d), which may degrade the quality of direct "+ |
| 78 | "connections or render them unusable.", iface.Name, iface.MTU, safeMTU), |
| 79 | ) |
| 80 | } |
| 81 | } |
| 82 | return report |
| 83 | } |