1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- Subject: Aoe-sancheck: Refine interface probing
- Origin: aoetools-36-11-g4a3ee18 <https://github.com/OpenAoE/aoetools/commit/aoetools-36-11-g4a3ee18>
- Upstream-Author: Christoph Biedl <debian.axhn@manchmal.in-ulm.de>
- Date: Sat May 22 14:37:25 2021 +0200
- Forwarded: not-needed (cherry-picked)
- There are two issues in the ethlist function in aoe-sancheck.c:
- First it skips all network interfaces that do not start with "eth". This
- is a problem these days where people use different naming schemes like the
- so-called predictable interface names as mandated by udev/systemd.
- Second it only probes for interfaces with an interface number of up
- to 15. At least in current Linux, that number can take huge values and
- those interfaces will be ignored completely.
- About the first: Probe all interfaces (but lo) that support the ARP
- protocol, assuming that is a fair indicator for ethernet support.
- About the second, use the if_nameindex function to get a list of all
- interfaces currently known to the kernel and operate on that one.
- --- a/aoe-sancheck.c
- +++ b/aoe-sancheck.c
- @@ -501,23 +501,38 @@
- int
- ethlist(char **ifs, int nifs)
- {
- - int i, s, n;
- + int s, n;
- struct ifreq ifr;
- + struct if_nameindex *if_ni, *i;
-
- s = socket(AF_INET, SOCK_STREAM, 0);
- if (s < 0)
- return 0;
- +
- + if_ni = if_nameindex();
- + if (if_ni == NULL)
- + return 0;
- +
- n = 0;
- - for (i=0; i<nifs; i++) {
- + for (i = if_ni; ! (i->if_index == 0 && i->if_name == NULL); i++) {
- memset(&ifr, 0, sizeof ifr);
- - ifr.ifr_ifindex = i;
- - if (ioctl(s, SIOCGIFNAME, &ifr) < 0)
- + ifr.ifr_ifindex = i->if_index;
- + strcpy(ifr.ifr_name, i->if_name);
- + // get interface flags
- + if (ioctl(s, SIOCGIFFLAGS, &ifr) < 0)
- + continue;
- + // only use interfaces that use arp protocol
- + if (ifr.ifr_flags & IFF_NOARP)
- continue;
- - if (strncmp(ifr.ifr_name, "eth", 3))
- + // skip loopback interfaces
- + if (ifr.ifr_flags & IFF_LOOPBACK)
- continue;
- + if (n == nifs)
- + break;
- inserteth(ifs, nifs, ifr.ifr_name);
- n++;
- }
- + if_freenameindex(if_ni);
- close(s);
- return n;
- }
|