1
0

1621687045.aoetools-36-11-g4a3ee18.aoe-sancheck-refine-interface-probing.patch 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. Subject: Aoe-sancheck: Refine interface probing
  2. Origin: aoetools-36-11-g4a3ee18 <https://github.com/OpenAoE/aoetools/commit/aoetools-36-11-g4a3ee18>
  3. Upstream-Author: Christoph Biedl <debian.axhn@manchmal.in-ulm.de>
  4. Date: Sat May 22 14:37:25 2021 +0200
  5. There are two issues in the ethlist function in aoe-sancheck.c:
  6. First it skips all network interfaces that do not start with "eth". This
  7. is a problem these days where people use different naming schemes like the
  8. so-called predictable interface names as mandated by udev/systemd.
  9. Second it only probes for interfaces with an interface number of up
  10. to 15. At least in current Linux, that number can take huge values and
  11. those interfaces will be ignored completely.
  12. About the first: Probe all interfaces (but lo) that support the ARP
  13. protocol, assuming that is a fair indicator for ethernet support.
  14. About the second, use the if_nameindex function to get a list of all
  15. interfaces currently known to the kernel and operate on that one.
  16. --- a/aoe-sancheck.c
  17. +++ b/aoe-sancheck.c
  18. @@ -501,23 +501,38 @@
  19. int
  20. ethlist(char **ifs, int nifs)
  21. {
  22. - int i, s, n;
  23. + int s, n;
  24. struct ifreq ifr;
  25. + struct if_nameindex *if_ni, *i;
  26. s = socket(AF_INET, SOCK_STREAM, 0);
  27. if (s < 0)
  28. return 0;
  29. +
  30. + if_ni = if_nameindex();
  31. + if (if_ni == NULL)
  32. + return 0;
  33. +
  34. n = 0;
  35. - for (i=0; i<nifs; i++) {
  36. + for (i = if_ni; ! (i->if_index == 0 && i->if_name == NULL); i++) {
  37. memset(&ifr, 0, sizeof ifr);
  38. - ifr.ifr_ifindex = i;
  39. - if (ioctl(s, SIOCGIFNAME, &ifr) < 0)
  40. + ifr.ifr_ifindex = i->if_index;
  41. + strcpy(ifr.ifr_name, i->if_name);
  42. + // get interface flags
  43. + if (ioctl(s, SIOCGIFFLAGS, &ifr) < 0)
  44. + continue;
  45. + // only use interfaces that use arp protocol
  46. + if (ifr.ifr_flags & IFF_NOARP)
  47. continue;
  48. - if (strncmp(ifr.ifr_name, "eth", 3))
  49. + // skip loopback interfaces
  50. + if (ifr.ifr_flags & IFF_LOOPBACK)
  51. continue;
  52. + if (n == nifs)
  53. + break;
  54. inserteth(ifs, nifs, ifr.ifr_name);
  55. n++;
  56. }
  57. + if_freenameindex(if_ni);
  58. close(s);
  59. return n;
  60. }