0004-ifconfig-Implement-hardware-list-for-BSD-systems.patch 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. From 3891528b1a2979fcda2c17fd6987e85894504983 Mon Sep 17 00:00:00 2001
  2. From: Mats Erik Andersson <gnu@gisladisker.se>
  3. Date: Tue, 21 Jul 2015 23:04:46 +0200
  4. Subject: [PATCH 04/60] ifconfig: Implement hardware list for BSD systems.
  5. Let formats `gnu' and `osf' report tunnel endpoints.
  6. ---
  7. ChangeLog | 26 ++++++++
  8. ifconfig/flags.c | 3 +
  9. ifconfig/options.c | 6 ++
  10. ifconfig/system/bsd.c | 143 ++++++++++++++++++++++++++++++++++++------
  11. 4 files changed, 160 insertions(+), 18 deletions(-)
  12. diff --git a/ChangeLog b/ChangeLog
  13. index d0172fa8..47c70e3a 100644
  14. --- a/ChangeLog
  15. +++ b/ChangeLog
  16. @@ -1,3 +1,29 @@
  17. +2015-07-21 Mats Erik Andersson <gnu@gisladisker.se>
  18. +
  19. + ifconfig: Implement a hardware list for BSD systems.
  20. + Patterned on the hardware recognition already in use
  21. + by GNU/Linux, use a similar mechanism for all of BSD.
  22. +
  23. + * ifconfig/system/bsd.c (print_hwaddr_ether): New function.
  24. + (ift_symbols): New variable.
  25. + (ift_findvalue): New function.
  26. + (system_fh_hwaddr_query, system_fh_hwaddr)
  27. + (system_fh_hwtype_query, system_fh_hwtype): Adjust mechanisms
  28. + to use the table `ift_symbols' via ift_findvalue().
  29. +
  30. +
  31. + ifconfig: Report tunnels in two more formats.
  32. +
  33. + * ifconfig/options.c (formats) <gnu-one-entry format>:
  34. + Add two entries for the endpoints of tunnels.
  35. + <osf format>: Add a line to display tunnels.
  36. +
  37. +
  38. + ifconfig: Add a missing interface flag.
  39. +
  40. + * ifconfig/flags.c [IFF_CANTCONFIG] (if_flags): Add the
  41. + extended interface flag `CANTCONFIG'.
  42. +
  43. 2015-07-20 Mats Erik Andersson <gnu@gisladisker.se>
  44. ifconfig: More info on tunnel interfaces.
  45. diff --git a/ifconfig/flags.c b/ifconfig/flags.c
  46. index ee4f6e02..003e535d 100644
  47. --- a/ifconfig/flags.c
  48. +++ b/ifconfig/flags.c
  49. @@ -218,6 +218,9 @@ struct if_flag
  50. #ifdef IFF_SNAP /* Ethernet driver outputs SNAP header. */
  51. {"SNAP", IFF_SNAP, 0},
  52. #endif
  53. +#ifdef IFF_CANTCONFIG
  54. + {"CANTCONFIG", IFF_CANTCONFIG, 0},
  55. +#endif
  56. #ifdef IFF_MONITOR
  57. {"MONITOR", IFF_MONITOR, 0},
  58. #endif
  59. diff --git a/ifconfig/options.c b/ifconfig/options.c
  60. index 2f20e75f..9478f310 100644
  61. --- a/ifconfig/options.c
  62. +++ b/ifconfig/options.c
  63. @@ -84,6 +84,10 @@ struct format formats[] = {
  64. "${netmask?}{ netmask ${tab}{16}${netmask}${\\n}}"
  65. "${brdaddr?}{ broadcast ${tab}{16}${brdaddr}${\\n}}"
  66. "${dstaddr?}{ peer address ${tab}{16}${dstaddr}${\\n}}"
  67. + "${exists?}{tunnel?}{"
  68. + "${tunnel?}{ tunnel src ${tab}{16}${tunsrc}${\\n}}}"
  69. + "${exists?}{tunnel?}{"
  70. + "${tunnel?}{ tunnel dst ${tab}{16}${tundst}${\\n}}}"
  71. "${flags?}{ flags ${tab}{16}${flags}${\\n}}"
  72. "${mtu?}{ mtu ${tab}{16}${mtu}${\\n}}"
  73. "${metric?}{ metric ${tab}{16}${metric}${\\n}}"
  74. @@ -182,6 +186,8 @@ struct format formats[] = {
  75. "${format}{check-existence}"
  76. "${ifdisplay?}{"
  77. "${name}: flags=${flags}{number}{%x}<${flags}{string}{,}>${\\n}"
  78. + "${exists?}{tunnel?}{"
  79. + "${tunnel?}{${\\t}inet tunnel src ${tunsrc} tunnel dst ${tundst}${\\n}}}"
  80. "${addr?}{${\\t}inet ${addr}"
  81. "${dstaddr?}{ --> ${dstaddr}}"
  82. " netmask ${netmask}{0}{%02x}${netmask}{1}{%02x}"
  83. diff --git a/ifconfig/system/bsd.c b/ifconfig/system/bsd.c
  84. index 910a75ef..1db525ba 100644
  85. --- a/ifconfig/system/bsd.c
  86. +++ b/ifconfig/system/bsd.c
  87. @@ -200,6 +200,73 @@ struct ifmediareq ifm;
  88. struct if_nameindex* (*system_if_nameindex) (void) = if_nameindex;
  89. +static void
  90. +print_hwaddr_ether (format_data_t form, unsigned char *data)
  91. +{
  92. + put_string (form, ether_ntoa ((struct ether_addr *) data));
  93. + had_output = 1;
  94. +}
  95. +
  96. +struct ift_symbol
  97. +{
  98. + const char *name;
  99. + const char *title;
  100. + int value;
  101. + void (*print_hwaddr) (format_data_t form, unsigned char *data);
  102. +} ift_symbols[] =
  103. + {
  104. +#ifdef IFT_ETHER /* Ethernet CSMA/CD */
  105. +# ifdef ETHERNAME
  106. + { "ETHER", ETHERNAME, IFT_ETHER, print_hwaddr_ether},
  107. +# else
  108. + { "ETHER", "ether", IFT_ETHER, print_hwaddr_ether},
  109. +# endif /* !ETHERNAME */
  110. +#endif /* IFT_ETHER */
  111. +#ifdef IFT_GIF /* Generic tunnel (gif) */
  112. + { "IPGIF", "IPIP tunnel", IFT_GIF, NULL},
  113. +#endif
  114. +#ifdef IFT_FAITH /* IPv6-to-IPv4 TCP relay capture */
  115. + { "FAITH", "TCP relay capture", IFT_FAITH, NULL},
  116. +#endif
  117. +#ifdef IFT_LOOP /* Local loopback */
  118. + { "LOOPBACK", "Local loopback", IFT_LOOP, NULL},
  119. +#endif
  120. +#ifdef IFT_PFLOG /* Packet filter logging */
  121. + { "PFLOG", "Packet filter logger", IFT_PFLOG, NULL},
  122. +#endif
  123. +#ifdef IFT_PFSYNC /* Packet filter state synching */
  124. + { "PFSYNC", "Packet filter state synching", IFT_PFSYNC, NULL},
  125. +#endif
  126. +#ifdef IFT_PPP /* Point-to-Point serial protocol */
  127. + { "PPP", "Point-to-Point over serial", IFT_PPP, NULL},
  128. +#endif
  129. +#ifdef IFT_SLIP /* IP over generic TTY */
  130. + { "SLIP", "Serial line IP", IFT_SLIP, NULL},
  131. +#endif
  132. +#ifdef IFT_TUNNEL /* Encapsulation (gre) */
  133. + { "IPGRE", "GRE over IP", IFT_TUNNEL, NULL},
  134. +#endif
  135. + { NULL, NULL, 0, NULL}
  136. + };
  137. +
  138. +static struct ift_symbol *
  139. +ift_findvalue (int value)
  140. +{
  141. + struct ift_symbol *ift = ift_symbols;
  142. +
  143. + while (ift->name != NULL)
  144. + {
  145. + if (ift->value == value)
  146. + break;
  147. + ift++;
  148. + }
  149. +
  150. + if (ift->name)
  151. + return ift;
  152. + else
  153. + return NULL;
  154. +}
  155. +
  156. void
  157. system_fh_brdaddr_query (format_data_t form, int argc, char *argv[])
  158. {
  159. @@ -274,11 +341,16 @@ system_fh_hwaddr_query (format_data_t form, int argc, char *argv[])
  160. continue;
  161. dl = (struct sockaddr_dl *) fp->ifa_addr;
  162. - if (dl && (dl->sdl_len > 0) &&
  163. - dl->sdl_type == IFT_ETHER) /* XXX: More cases? */
  164. - missing = 0;
  165. + if (dl && (dl->sdl_len > 0))
  166. + {
  167. + struct ift_symbol *ift = ift_findvalue (dl->sdl_type);
  168. +
  169. + if (ift && ift->print_hwaddr)
  170. + missing = 0;
  171. + }
  172. break;
  173. }
  174. +
  175. select_arg (form, argc, argv, missing);
  176. }
  177. }
  178. @@ -304,11 +376,16 @@ system_fh_hwaddr (format_data_t form, int argc _GL_UNUSED_PARAMETER,
  179. continue;
  180. dl = (struct sockaddr_dl *) fp->ifa_addr;
  181. - if (dl && (dl->sdl_len > 0) &&
  182. - dl->sdl_type == IFT_ETHER) /* XXX: More cases? */
  183. + if (dl && (dl->sdl_len > 0))
  184. {
  185. - missing = 0;
  186. - put_string (form, ether_ntoa ((struct ether_addr *) LLADDR (dl)));
  187. + struct ift_symbol *ift = ift_findvalue (dl->sdl_type);
  188. +
  189. + if (ift && ift->print_hwaddr)
  190. + {
  191. + missing = 0;
  192. + ift->print_hwaddr (form,
  193. + (unsigned char *) LLADDR (dl));
  194. + }
  195. }
  196. break;
  197. }
  198. @@ -320,19 +397,44 @@ system_fh_hwaddr (format_data_t form, int argc _GL_UNUSED_PARAMETER,
  199. void
  200. system_fh_hwtype_query (format_data_t form, int argc, char *argv[])
  201. {
  202. - system_fh_hwaddr_query (form, argc, argv);
  203. + int missing = 1;
  204. +
  205. + ESTABLISH_IFADDRS
  206. + if (ifp)
  207. + {
  208. + struct ifaddrs *fp;
  209. + struct sockaddr_dl *dl = NULL;
  210. +
  211. + for (fp = ifp; fp; fp = fp->ifa_next)
  212. + {
  213. + if (fp->ifa_addr->sa_family != AF_LINK ||
  214. + strcmp (fp->ifa_name, form->ifr->ifr_name))
  215. + continue;
  216. +
  217. + dl = (struct sockaddr_dl *) fp->ifa_addr;
  218. + if (dl && (dl->sdl_len > 0))
  219. + {
  220. + struct ift_symbol *ift = ift_findvalue (dl->sdl_type);
  221. +
  222. + if (ift && ift->title)
  223. + missing = 0;
  224. + }
  225. + break;
  226. + }
  227. + }
  228. +
  229. + select_arg (form, argc, argv, missing);
  230. }
  231. void
  232. system_fh_hwtype (format_data_t form, int argc _GL_UNUSED_PARAMETER,
  233. char *argv[] _GL_UNUSED_PARAMETER)
  234. {
  235. + int found = 0;
  236. +
  237. ESTABLISH_IFADDRS
  238. - if (!ifp)
  239. - put_string (form, "(hwtype unknown)");
  240. - else
  241. + if (ifp)
  242. {
  243. - int found = 0;
  244. struct ifaddrs *fp;
  245. struct sockaddr_dl *dl = NULL;
  246. @@ -343,17 +445,22 @@ system_fh_hwtype (format_data_t form, int argc _GL_UNUSED_PARAMETER,
  247. continue;
  248. dl = (struct sockaddr_dl *) fp->ifa_addr;
  249. - if (dl && (dl->sdl_len > 0) &&
  250. - dl->sdl_type == IFT_ETHER) /* XXX: More cases? */
  251. + if (dl && (dl->sdl_len > 0))
  252. {
  253. - found = 1;
  254. - put_string (form, ETHERNAME);
  255. + struct ift_symbol *ift = ift_findvalue (dl->sdl_type);
  256. +
  257. + if (ift && ift->title)
  258. + {
  259. + found = 1;
  260. + put_string (form, ift->title);
  261. + }
  262. }
  263. break;
  264. }
  265. - if (!found)
  266. - put_string (form, "(unknown hwtype)");
  267. }
  268. +
  269. + if (!found)
  270. + put_string (form, "(unknown hwtype)");
  271. }
  272. /* Lookup structures provided by the system, each decoding
  273. --
  274. 2.26.0.292.g33ef6b2f38