0001-aoe-sancheck-Refine-interface-probing.patch 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. From 4a3ee184e6e76aead8e55c412be3c9c924e76e24 Mon Sep 17 00:00:00 2001
  2. From: Christoph Biedl <debian.axhn@manchmal.in-ulm.de>
  3. Date: Sat, 22 May 2021 14:37:25 +0200
  4. Subject: [PATCH 1/2] aoe-sancheck: Refine interface probing
  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. ---
  17. aoe-sancheck.c | 25 ++++++++++++++++++++-----
  18. 1 file changed, 20 insertions(+), 5 deletions(-)
  19. --- a/aoe-sancheck.c
  20. +++ b/aoe-sancheck.c
  21. @@ -501,23 +501,38 @@
  22. int
  23. ethlist(char **ifs, int nifs)
  24. {
  25. - int i, s, n;
  26. + int s, n;
  27. struct ifreq ifr;
  28. + struct if_nameindex *if_ni, *i;
  29. s = socket(AF_INET, SOCK_STREAM, 0);
  30. if (s < 0)
  31. return 0;
  32. +
  33. + if_ni = if_nameindex();
  34. + if (if_ni == NULL)
  35. + return 0;
  36. +
  37. n = 0;
  38. - for (i=0; i<nifs; i++) {
  39. + for (i = if_ni; ! (i->if_index == 0 && i->if_name == NULL); i++) {
  40. memset(&ifr, 0, sizeof ifr);
  41. - ifr.ifr_ifindex = i;
  42. - if (ioctl(s, SIOCGIFNAME, &ifr) < 0)
  43. + ifr.ifr_ifindex = i->if_index;
  44. + strcpy(ifr.ifr_name, i->if_name);
  45. + // get interface flags
  46. + if (ioctl(s, SIOCGIFFLAGS, &ifr) < 0)
  47. + continue;
  48. + // only use interfaces that use arp protocol
  49. + if (ifr.ifr_flags & IFF_NOARP)
  50. continue;
  51. - if (strncmp(ifr.ifr_name, "eth", 3))
  52. + // skip loopback interfaces
  53. + if (ifr.ifr_flags & IFF_LOOPBACK)
  54. continue;
  55. + if (n == nifs)
  56. + break;
  57. inserteth(ifs, nifs, ifr.ifr_name);
  58. n++;
  59. }
  60. + if_freenameindex(if_ni);
  61. close(s);
  62. return n;
  63. }