test_address.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207
  1. /* Copyright (c) 2014-2018, The Tor Project, Inc. */
  2. /* See LICENSE for licensing information */
  3. #define ADDRESS_PRIVATE
  4. #include "orconfig.h"
  5. #ifdef _WIN32
  6. #include <winsock2.h>
  7. /* For access to structs needed by GetAdaptersAddresses */
  8. #include <iphlpapi.h>
  9. #endif
  10. #ifdef HAVE_IFADDRS_TO_SMARTLIST
  11. #include <net/if.h>
  12. #include <ifaddrs.h>
  13. #endif
  14. #ifdef HAVE_IFCONF_TO_SMARTLIST
  15. #ifdef HAVE_SYS_IOCTL_H
  16. #include <sys/ioctl.h>
  17. #endif
  18. #include <net/if.h>
  19. #endif /* defined(HAVE_IFCONF_TO_SMARTLIST) */
  20. #include "core/or/or.h"
  21. #include "feature/nodelist/nodelist.h"
  22. #include "lib/net/address.h"
  23. #include "test/test.h"
  24. #include "test/log_test_helpers.h"
  25. /** Return 1 iff <b>sockaddr1</b> and <b>sockaddr2</b> represent
  26. * the same IP address and port combination. Otherwise, return 0.
  27. */
  28. static uint8_t
  29. sockaddr_in_are_equal(struct sockaddr_in *sockaddr1,
  30. struct sockaddr_in *sockaddr2)
  31. {
  32. return ((sockaddr1->sin_family == sockaddr2->sin_family) &&
  33. (sockaddr1->sin_port == sockaddr2->sin_port) &&
  34. (sockaddr1->sin_addr.s_addr == sockaddr2->sin_addr.s_addr));
  35. }
  36. /** Return 1 iff <b>sockaddr1</b> and <b>sockaddr2</b> represent
  37. * the same IP address and port combination. Otherwise, return 0.
  38. */
  39. static uint8_t
  40. sockaddr_in6_are_equal(struct sockaddr_in6 *sockaddr1,
  41. struct sockaddr_in6 *sockaddr2)
  42. {
  43. return ((sockaddr1->sin6_family == sockaddr2->sin6_family) &&
  44. (sockaddr1->sin6_port == sockaddr2->sin6_port) &&
  45. (tor_memeq(sockaddr1->sin6_addr.s6_addr,
  46. sockaddr2->sin6_addr.s6_addr,16)));
  47. }
  48. /** Create a sockaddr_in structure from IP address string <b>ip_str</b>.
  49. *
  50. * If <b>out</b> is not NULL, write the result
  51. * to the memory address in <b>out</b>. Otherwise, allocate the memory
  52. * for result. On success, return pointer to result. Otherwise, return
  53. * NULL.
  54. */
  55. static struct sockaddr_in *
  56. sockaddr_in_from_string(const char *ip_str, struct sockaddr_in *out)
  57. {
  58. // [FIXME: add some error checking?]
  59. if (!out)
  60. out = tor_malloc_zero(sizeof(struct sockaddr_in));
  61. out->sin_family = AF_INET;
  62. out->sin_port = 0;
  63. tor_inet_pton(AF_INET,ip_str,&(out->sin_addr));
  64. return out;
  65. }
  66. /** Return 1 iff <b>smartlist</b> contains a tor_addr_t structure
  67. * that is an IPv4 or IPv6 localhost address. Otherwise, return 0.
  68. */
  69. static int
  70. smartlist_contains_localhost_tor_addr(smartlist_t *smartlist)
  71. {
  72. SMARTLIST_FOREACH_BEGIN(smartlist, tor_addr_t *, tor_addr) {
  73. if (tor_addr_is_loopback(tor_addr)) {
  74. return 1;
  75. }
  76. } SMARTLIST_FOREACH_END(tor_addr);
  77. return 0;
  78. }
  79. /** Return 1 iff <b>smartlist</b> contains a tor_addr_t structure
  80. * that is an IPv4 or IPv6 multicast address. Otherwise, return 0.
  81. */
  82. static int
  83. smartlist_contains_multicast_tor_addr(smartlist_t *smartlist)
  84. {
  85. SMARTLIST_FOREACH_BEGIN(smartlist, tor_addr_t *, tor_addr) {
  86. if (tor_addr_is_multicast(tor_addr)) {
  87. return 1;
  88. }
  89. } SMARTLIST_FOREACH_END(tor_addr);
  90. return 0;
  91. }
  92. /** Return 1 iff <b>smartlist</b> contains a tor_addr_t structure
  93. * that is an IPv4 or IPv6 internal address. Otherwise, return 0.
  94. */
  95. static int
  96. smartlist_contains_internal_tor_addr(smartlist_t *smartlist)
  97. {
  98. SMARTLIST_FOREACH_BEGIN(smartlist, tor_addr_t *, tor_addr) {
  99. if (tor_addr_is_internal(tor_addr, 0)) {
  100. return 1;
  101. }
  102. } SMARTLIST_FOREACH_END(tor_addr);
  103. return 0;
  104. }
  105. /** Return 1 iff <b>smartlist</b> contains a tor_addr_t structure
  106. * that is NULL or the null tor_addr_t. Otherwise, return 0.
  107. */
  108. static int
  109. smartlist_contains_null_tor_addr(smartlist_t *smartlist)
  110. {
  111. SMARTLIST_FOREACH_BEGIN(smartlist, tor_addr_t *, tor_addr) {
  112. if (tor_addr == NULL || tor_addr_is_null(tor_addr)) {
  113. return 1;
  114. }
  115. } SMARTLIST_FOREACH_END(tor_addr);
  116. return 0;
  117. }
  118. /** Return 1 iff <b>smartlist</b> contains a tor_addr_t structure
  119. * that is an IPv4 address. Otherwise, return 0.
  120. */
  121. static int
  122. smartlist_contains_ipv4_tor_addr(smartlist_t *smartlist)
  123. {
  124. SMARTLIST_FOREACH_BEGIN(smartlist, tor_addr_t *, tor_addr) {
  125. if (tor_addr_is_v4(tor_addr)) {
  126. return 1;
  127. }
  128. } SMARTLIST_FOREACH_END(tor_addr);
  129. return 0;
  130. }
  131. /** Return 1 iff <b>smartlist</b> contains a tor_addr_t structure
  132. * that is an IPv6 address. Otherwise, return 0.
  133. */
  134. static int
  135. smartlist_contains_ipv6_tor_addr(smartlist_t *smartlist)
  136. {
  137. SMARTLIST_FOREACH_BEGIN(smartlist, tor_addr_t *, tor_addr) {
  138. /* Since there's no tor_addr_is_v6, assume all non-v4s are v6 */
  139. if (!tor_addr_is_v4(tor_addr)) {
  140. return 1;
  141. }
  142. } SMARTLIST_FOREACH_END(tor_addr);
  143. return 0;
  144. }
  145. #ifdef HAVE_IFADDRS_TO_SMARTLIST
  146. static void
  147. test_address_ifaddrs_to_smartlist(void *arg)
  148. {
  149. struct ifaddrs *ifa = NULL;
  150. struct ifaddrs *ifa_ipv4 = NULL;
  151. struct ifaddrs *ifa_ipv6 = NULL;
  152. struct sockaddr_in *ipv4_sockaddr_local = NULL;
  153. struct sockaddr_in *netmask_slash8 = NULL;
  154. struct sockaddr_in *ipv4_sockaddr_remote = NULL;
  155. struct sockaddr_in6 *ipv6_sockaddr = NULL;
  156. smartlist_t *smartlist = NULL;
  157. tor_addr_t *tor_addr = NULL;
  158. struct sockaddr *sockaddr_to_check = NULL;
  159. socklen_t addr_len;
  160. (void)arg;
  161. netmask_slash8 = sockaddr_in_from_string("255.0.0.0",NULL);
  162. ipv4_sockaddr_local = sockaddr_in_from_string("127.0.0.1",NULL);
  163. ipv4_sockaddr_remote = sockaddr_in_from_string("128.52.160.20",NULL);
  164. ipv6_sockaddr = tor_malloc(sizeof(struct sockaddr_in6));
  165. ipv6_sockaddr->sin6_family = AF_INET6;
  166. ipv6_sockaddr->sin6_port = 0;
  167. tor_inet_pton(AF_INET6, "2001:db8:8714:3a90::12",
  168. &(ipv6_sockaddr->sin6_addr));
  169. ifa = tor_malloc(sizeof(struct ifaddrs));
  170. ifa_ipv4 = tor_malloc(sizeof(struct ifaddrs));
  171. ifa_ipv6 = tor_malloc(sizeof(struct ifaddrs));
  172. ifa->ifa_next = ifa_ipv4;
  173. ifa->ifa_name = tor_strdup("eth0");
  174. ifa->ifa_flags = IFF_UP | IFF_RUNNING;
  175. ifa->ifa_addr = (struct sockaddr *)ipv4_sockaddr_local;
  176. ifa->ifa_netmask = (struct sockaddr *)netmask_slash8;
  177. ifa->ifa_dstaddr = NULL;
  178. ifa->ifa_data = NULL;
  179. ifa_ipv4->ifa_next = ifa_ipv6;
  180. ifa_ipv4->ifa_name = tor_strdup("eth1");
  181. ifa_ipv4->ifa_flags = IFF_UP | IFF_RUNNING;
  182. ifa_ipv4->ifa_addr = (struct sockaddr *)ipv4_sockaddr_remote;
  183. ifa_ipv4->ifa_netmask = (struct sockaddr *)netmask_slash8;
  184. ifa_ipv4->ifa_dstaddr = NULL;
  185. ifa_ipv4->ifa_data = NULL;
  186. ifa_ipv6->ifa_next = NULL;
  187. ifa_ipv6->ifa_name = tor_strdup("eth2");
  188. ifa_ipv6->ifa_flags = IFF_UP | IFF_RUNNING;
  189. ifa_ipv6->ifa_addr = (struct sockaddr *)ipv6_sockaddr;
  190. ifa_ipv6->ifa_netmask = NULL;
  191. ifa_ipv6->ifa_dstaddr = NULL;
  192. ifa_ipv6->ifa_data = NULL;
  193. smartlist = ifaddrs_to_smartlist(ifa, AF_UNSPEC);
  194. tt_assert(smartlist);
  195. tt_int_op(smartlist_len(smartlist), OP_EQ, 3);
  196. sockaddr_to_check = tor_malloc(sizeof(struct sockaddr_in6));
  197. tor_addr = smartlist_get(smartlist,0);
  198. addr_len =
  199. tor_addr_to_sockaddr(tor_addr,0,sockaddr_to_check,
  200. sizeof(struct sockaddr_in));
  201. tt_int_op(addr_len,OP_EQ,sizeof(struct sockaddr_in));
  202. tt_assert(sockaddr_in_are_equal((struct sockaddr_in *)sockaddr_to_check,
  203. ipv4_sockaddr_local));
  204. tor_addr = smartlist_get(smartlist,1);
  205. addr_len =
  206. tor_addr_to_sockaddr(tor_addr,0,sockaddr_to_check,
  207. sizeof(struct sockaddr_in));
  208. tt_int_op(addr_len,OP_EQ,sizeof(struct sockaddr_in));
  209. tt_assert(sockaddr_in_are_equal((struct sockaddr_in *)sockaddr_to_check,
  210. ipv4_sockaddr_remote));
  211. tor_addr = smartlist_get(smartlist,2);
  212. addr_len =
  213. tor_addr_to_sockaddr(tor_addr,0,sockaddr_to_check,
  214. sizeof(struct sockaddr_in6));
  215. tt_int_op(addr_len,OP_EQ,sizeof(struct sockaddr_in6));
  216. tt_assert(sockaddr_in6_are_equal((struct sockaddr_in6*)sockaddr_to_check,
  217. ipv6_sockaddr));
  218. done:
  219. tor_free(netmask_slash8);
  220. tor_free(ipv4_sockaddr_local);
  221. tor_free(ipv4_sockaddr_remote);
  222. tor_free(ipv6_sockaddr);
  223. tor_free(ifa->ifa_name);
  224. tor_free(ifa_ipv4->ifa_name);
  225. tor_free(ifa_ipv6->ifa_name);
  226. tor_free(ifa);
  227. tor_free(ifa_ipv4);
  228. tor_free(ifa_ipv6);
  229. tor_free(sockaddr_to_check);
  230. if (smartlist) {
  231. SMARTLIST_FOREACH(smartlist, tor_addr_t *, t, tor_free(t));
  232. smartlist_free(smartlist);
  233. }
  234. return;
  235. }
  236. static void
  237. test_address_get_if_addrs_ifaddrs(void *arg)
  238. {
  239. smartlist_t *results = NULL;
  240. (void)arg;
  241. results = get_interface_addresses_ifaddrs(LOG_ERR, AF_UNSPEC);
  242. tt_assert(results);
  243. /* Some FreeBSD jails don't have localhost IP address. Instead, they only
  244. * have the address assigned to the jail (whatever that may be).
  245. * And a jail without a network connection might not have any addresses at
  246. * all. */
  247. tt_assert(!smartlist_contains_null_tor_addr(results));
  248. /* If there are addresses, they must be IPv4 or IPv6 */
  249. if (smartlist_len(results) > 0) {
  250. tt_assert(smartlist_contains_ipv4_tor_addr(results)
  251. || smartlist_contains_ipv6_tor_addr(results));
  252. }
  253. done:
  254. if (results) {
  255. SMARTLIST_FOREACH(results, tor_addr_t *, t, tor_free(t));
  256. }
  257. smartlist_free(results);
  258. return;
  259. }
  260. #endif /* defined(HAVE_IFADDRS_TO_SMARTLIST) */
  261. #ifdef HAVE_IP_ADAPTER_TO_SMARTLIST
  262. static void
  263. test_address_get_if_addrs_win32(void *arg)
  264. {
  265. smartlist_t *results = NULL;
  266. (void)arg;
  267. results = get_interface_addresses_win32(LOG_ERR, AF_UNSPEC);
  268. tt_int_op(smartlist_len(results),OP_GE,1);
  269. tt_assert(smartlist_contains_localhost_tor_addr(results));
  270. tt_assert(!smartlist_contains_null_tor_addr(results));
  271. /* If there are addresses, they must be IPv4 or IPv6 */
  272. if (smartlist_len(results) > 0) {
  273. tt_assert(smartlist_contains_ipv4_tor_addr(results)
  274. || smartlist_contains_ipv6_tor_addr(results));
  275. }
  276. done:
  277. SMARTLIST_FOREACH(results, tor_addr_t *, t, tor_free(t));
  278. tor_free(results);
  279. return;
  280. }
  281. static void
  282. test_address_ip_adapter_addresses_to_smartlist(void *arg)
  283. {
  284. IP_ADAPTER_ADDRESSES *addrs1;
  285. IP_ADAPTER_ADDRESSES *addrs2;
  286. IP_ADAPTER_UNICAST_ADDRESS *unicast11;
  287. IP_ADAPTER_UNICAST_ADDRESS *unicast12;
  288. IP_ADAPTER_UNICAST_ADDRESS *unicast21;
  289. smartlist_t *result = NULL;
  290. struct sockaddr_in *sockaddr_test1;
  291. struct sockaddr_in *sockaddr_test2;
  292. struct sockaddr_in *sockaddr_localhost;
  293. struct sockaddr_in *sockaddr_to_check;
  294. tor_addr_t *tor_addr;
  295. (void)arg;
  296. (void)sockaddr_in6_are_equal;
  297. sockaddr_to_check = tor_malloc_zero(sizeof(struct sockaddr_in));
  298. addrs1 =
  299. tor_malloc_zero(sizeof(IP_ADAPTER_ADDRESSES));
  300. addrs1->FirstUnicastAddress =
  301. unicast11 = tor_malloc_zero(sizeof(IP_ADAPTER_UNICAST_ADDRESS));
  302. sockaddr_test1 = sockaddr_in_from_string("86.59.30.40",NULL);
  303. unicast11->Address.lpSockaddr = (LPSOCKADDR)sockaddr_test1;
  304. unicast11->Next = unicast12 =
  305. tor_malloc_zero(sizeof(IP_ADAPTER_UNICAST_ADDRESS));
  306. sockaddr_test2 = sockaddr_in_from_string("93.95.227.222", NULL);
  307. unicast12->Address.lpSockaddr = (LPSOCKADDR)sockaddr_test2;
  308. addrs1->Next = addrs2 =
  309. tor_malloc_zero(sizeof(IP_ADAPTER_ADDRESSES));
  310. addrs2->FirstUnicastAddress =
  311. unicast21 = tor_malloc_zero(sizeof(IP_ADAPTER_UNICAST_ADDRESS));
  312. sockaddr_localhost = sockaddr_in_from_string("127.0.0.1", NULL);
  313. unicast21->Address.lpSockaddr = (LPSOCKADDR)sockaddr_localhost;
  314. result = ip_adapter_addresses_to_smartlist(addrs1);
  315. tt_assert(result);
  316. tt_int_op(smartlist_len(result), OP_EQ, 3);
  317. tor_addr = smartlist_get(result,0);
  318. tor_addr_to_sockaddr(tor_addr,0,(struct sockaddr *)sockaddr_to_check,
  319. sizeof(struct sockaddr_in));
  320. tt_assert(sockaddr_in_are_equal(sockaddr_test1,sockaddr_to_check));
  321. tor_addr = smartlist_get(result,1);
  322. tor_addr_to_sockaddr(tor_addr,0,(struct sockaddr *)sockaddr_to_check,
  323. sizeof(struct sockaddr_in));
  324. tt_assert(sockaddr_in_are_equal(sockaddr_test2,sockaddr_to_check));
  325. tor_addr = smartlist_get(result,2);
  326. tor_addr_to_sockaddr(tor_addr,0,(struct sockaddr *)sockaddr_to_check,
  327. sizeof(struct sockaddr_in));
  328. tt_assert(sockaddr_in_are_equal(sockaddr_localhost,sockaddr_to_check));
  329. done:
  330. SMARTLIST_FOREACH(result, tor_addr_t *, t, tor_free(t));
  331. smartlist_free(result);
  332. tor_free(addrs1);
  333. tor_free(addrs2);
  334. tor_free(unicast11->Address.lpSockaddr);
  335. tor_free(unicast11);
  336. tor_free(unicast12->Address.lpSockaddr);
  337. tor_free(unicast12);
  338. tor_free(unicast21->Address.lpSockaddr);
  339. tor_free(unicast21);
  340. tor_free(sockaddr_to_check);
  341. return;
  342. }
  343. #endif /* defined(HAVE_IP_ADAPTER_TO_SMARTLIST) */
  344. #ifdef HAVE_IFCONF_TO_SMARTLIST
  345. static void
  346. test_address_ifreq_to_smartlist(void *arg)
  347. {
  348. smartlist_t *results = NULL;
  349. const tor_addr_t *tor_addr = NULL;
  350. struct sockaddr_in *sockaddr = NULL;
  351. struct sockaddr_in *sockaddr_eth1 = NULL;
  352. struct sockaddr_in *sockaddr_to_check = NULL;
  353. struct ifconf *ifc;
  354. struct ifreq *ifr;
  355. struct ifreq *ifr_next;
  356. socklen_t addr_len;
  357. (void)arg;
  358. sockaddr_to_check = tor_malloc(sizeof(struct sockaddr_in));
  359. ifr = tor_malloc(sizeof(struct ifreq));
  360. memset(ifr,0,sizeof(struct ifreq));
  361. strlcpy(ifr->ifr_name,"lo",3);
  362. sockaddr = (struct sockaddr_in *) &(ifr->ifr_ifru.ifru_addr);
  363. sockaddr_in_from_string("127.0.0.1",sockaddr);
  364. ifc = tor_malloc(sizeof(struct ifconf));
  365. memset(ifc,0,sizeof(struct ifconf));
  366. ifc->ifc_len = sizeof(struct ifreq);
  367. ifc->ifc_ifcu.ifcu_req = ifr;
  368. results = ifreq_to_smartlist(ifc->ifc_buf,ifc->ifc_len);
  369. tt_int_op(smartlist_len(results),OP_EQ,1);
  370. tor_addr = smartlist_get(results, 0);
  371. addr_len =
  372. tor_addr_to_sockaddr(tor_addr,0,(struct sockaddr *)sockaddr_to_check,
  373. sizeof(struct sockaddr_in));
  374. tt_int_op(addr_len,OP_EQ,sizeof(struct sockaddr_in));
  375. tt_assert(sockaddr_in_are_equal(sockaddr,sockaddr_to_check));
  376. ifr = tor_realloc(ifr,2*sizeof(struct ifreq));
  377. ifr_next = ifr+1;
  378. strlcpy(ifr_next->ifr_name,"eth1",5);
  379. ifc->ifc_len = 2*sizeof(struct ifreq);
  380. ifc->ifc_ifcu.ifcu_req = ifr;
  381. sockaddr = (struct sockaddr_in *) &(ifr->ifr_ifru.ifru_addr);
  382. sockaddr_eth1 = (struct sockaddr_in *) &(ifr_next->ifr_ifru.ifru_addr);
  383. sockaddr_in_from_string("192.168.10.55",sockaddr_eth1);
  384. SMARTLIST_FOREACH(results, tor_addr_t *, t, tor_free(t));
  385. smartlist_free(results);
  386. results = ifreq_to_smartlist(ifc->ifc_buf,ifc->ifc_len);
  387. tt_int_op(smartlist_len(results),OP_EQ,2);
  388. tor_addr = smartlist_get(results, 0);
  389. addr_len =
  390. tor_addr_to_sockaddr(tor_addr,0,(struct sockaddr *)sockaddr_to_check,
  391. sizeof(struct sockaddr_in));
  392. tt_int_op(addr_len,OP_EQ,sizeof(struct sockaddr_in));
  393. tt_assert(sockaddr_in_are_equal(sockaddr,sockaddr_to_check));
  394. tor_addr = smartlist_get(results, 1);
  395. addr_len =
  396. tor_addr_to_sockaddr(tor_addr,0,(struct sockaddr *)sockaddr_to_check,
  397. sizeof(struct sockaddr_in));
  398. tt_int_op(addr_len,OP_EQ,sizeof(struct sockaddr_in));
  399. tt_assert(sockaddr_in_are_equal(sockaddr_eth1,sockaddr_to_check));
  400. done:
  401. tor_free(sockaddr_to_check);
  402. SMARTLIST_FOREACH(results, tor_addr_t *, t, tor_free(t));
  403. smartlist_free(results);
  404. tor_free(ifc);
  405. tor_free(ifr);
  406. return;
  407. }
  408. static void
  409. test_address_get_if_addrs_ioctl(void *arg)
  410. {
  411. smartlist_t *result = NULL;
  412. (void)arg;
  413. result = get_interface_addresses_ioctl(LOG_ERR, AF_INET);
  414. /* On an IPv6-only system, this will fail and return NULL
  415. tt_assert(result);
  416. */
  417. /* Some FreeBSD jails don't have localhost IP address. Instead, they only
  418. * have the address assigned to the jail (whatever that may be).
  419. * And a jail without a network connection might not have any addresses at
  420. * all. */
  421. if (result) {
  422. tt_assert(!smartlist_contains_null_tor_addr(result));
  423. /* If there are addresses, they must be IPv4 or IPv6.
  424. * (AIX supports IPv6 from SIOCGIFCONF.) */
  425. if (smartlist_len(result) > 0) {
  426. tt_assert(smartlist_contains_ipv4_tor_addr(result)
  427. || smartlist_contains_ipv6_tor_addr(result));
  428. }
  429. }
  430. done:
  431. if (result) {
  432. SMARTLIST_FOREACH(result, tor_addr_t *, t, tor_free(t));
  433. smartlist_free(result);
  434. }
  435. return;
  436. }
  437. #endif /* defined(HAVE_IFCONF_TO_SMARTLIST) */
  438. #define FAKE_SOCKET_FD (42)
  439. static tor_socket_t
  440. fake_open_socket(int domain, int type, int protocol)
  441. {
  442. (void)domain;
  443. (void)type;
  444. (void)protocol;
  445. return FAKE_SOCKET_FD;
  446. }
  447. static int
  448. fake_close_socket(tor_socket_t s)
  449. {
  450. (void)s;
  451. return 0;
  452. }
  453. static int last_connected_socket_fd = 0;
  454. static int connect_retval = 0;
  455. static tor_socket_t
  456. pretend_to_connect(tor_socket_t sock, const struct sockaddr *address,
  457. socklen_t address_len)
  458. {
  459. (void)address;
  460. (void)address_len;
  461. last_connected_socket_fd = sock;
  462. return connect_retval;
  463. }
  464. static struct sockaddr *mock_addr = NULL;
  465. static int
  466. fake_getsockname(tor_socket_t sock, struct sockaddr *address,
  467. socklen_t *address_len)
  468. {
  469. socklen_t bytes_to_copy = 0;
  470. (void) sock;
  471. if (!mock_addr)
  472. return -1;
  473. if (mock_addr->sa_family == AF_INET) {
  474. bytes_to_copy = sizeof(struct sockaddr_in);
  475. } else if (mock_addr->sa_family == AF_INET6) {
  476. bytes_to_copy = sizeof(struct sockaddr_in6);
  477. } else {
  478. return -1;
  479. }
  480. if (*address_len < bytes_to_copy) {
  481. return -1;
  482. }
  483. memcpy(address,mock_addr,bytes_to_copy);
  484. *address_len = bytes_to_copy;
  485. return 0;
  486. }
  487. static void
  488. test_address_udp_socket_trick_whitebox(void *arg)
  489. {
  490. int hack_retval;
  491. tor_addr_t *addr_from_hack = tor_malloc_zero(sizeof(tor_addr_t));
  492. struct sockaddr_in6 *mock_addr6;
  493. struct sockaddr_in6 *ipv6_to_check =
  494. tor_malloc_zero(sizeof(struct sockaddr_in6));
  495. (void)arg;
  496. MOCK(tor_open_socket,fake_open_socket);
  497. MOCK(tor_connect_socket,pretend_to_connect);
  498. MOCK(tor_getsockname,fake_getsockname);
  499. MOCK(tor_close_socket,fake_close_socket);
  500. mock_addr = tor_malloc_zero(sizeof(struct sockaddr_storage));
  501. sockaddr_in_from_string("23.32.246.118",(struct sockaddr_in *)mock_addr);
  502. hack_retval =
  503. get_interface_address6_via_udp_socket_hack(LOG_DEBUG,
  504. AF_INET, addr_from_hack);
  505. tt_int_op(hack_retval,OP_EQ,0);
  506. tt_assert(tor_addr_eq_ipv4h(addr_from_hack, 0x1720f676));
  507. /* Now, lets do an IPv6 case. */
  508. memset(mock_addr,0,sizeof(struct sockaddr_storage));
  509. mock_addr6 = (struct sockaddr_in6 *)mock_addr;
  510. mock_addr6->sin6_family = AF_INET6;
  511. mock_addr6->sin6_port = 0;
  512. tor_inet_pton(AF_INET6,"2001:cdba::3257:9652",&(mock_addr6->sin6_addr));
  513. hack_retval =
  514. get_interface_address6_via_udp_socket_hack(LOG_DEBUG,
  515. AF_INET6, addr_from_hack);
  516. tt_int_op(hack_retval,OP_EQ,0);
  517. tor_addr_to_sockaddr(addr_from_hack,0,(struct sockaddr *)ipv6_to_check,
  518. sizeof(struct sockaddr_in6));
  519. tt_assert(sockaddr_in6_are_equal(mock_addr6,ipv6_to_check));
  520. done:
  521. UNMOCK(tor_open_socket);
  522. UNMOCK(tor_connect_socket);
  523. UNMOCK(tor_getsockname);
  524. UNMOCK(tor_close_socket);
  525. tor_free(ipv6_to_check);
  526. tor_free(mock_addr);
  527. tor_free(addr_from_hack);
  528. return;
  529. }
  530. static void
  531. test_address_udp_socket_trick_blackbox(void *arg)
  532. {
  533. /* We want get_interface_address6_via_udp_socket_hack() to yield
  534. * the same valid address that get_interface_address6() returns.
  535. * If the latter is unable to find a valid address, we want
  536. * _hack() to fail and return-1.
  537. *
  538. * Furthermore, we want _hack() never to crash, even if
  539. * get_interface_addresses_raw() is returning NULL.
  540. */
  541. tor_addr_t addr4;
  542. tor_addr_t addr4_to_check;
  543. tor_addr_t addr6;
  544. tor_addr_t addr6_to_check;
  545. int retval, retval_reference;
  546. (void)arg;
  547. #if 0
  548. retval_reference = get_interface_address6(LOG_DEBUG,AF_INET,&addr4);
  549. retval = get_interface_address6_via_udp_socket_hack(LOG_DEBUG,
  550. AF_INET,
  551. &addr4_to_check);
  552. tt_int_op(retval,OP_EQ,retval_reference);
  553. tt_assert( (retval == -1 && retval_reference == -1) ||
  554. (tor_addr_compare(&addr4,&addr4_to_check,CMP_EXACT) == 0) );
  555. retval_reference = get_interface_address6(LOG_DEBUG,AF_INET6,&addr6);
  556. retval = get_interface_address6_via_udp_socket_hack(LOG_DEBUG,
  557. AF_INET6,
  558. &addr6_to_check);
  559. tt_int_op(retval,OP_EQ,retval_reference);
  560. tt_assert( (retval == -1 && retval_reference == -1) ||
  561. (tor_addr_compare(&addr6,&addr6_to_check,CMP_EXACT) == 0) );
  562. #else /* !(0) */
  563. /* Both of the blackbox test cases fail horribly if:
  564. * * The host has no external addreses.
  565. * * There are multiple interfaces with either AF_INET or AF_INET6.
  566. * * The last address isn't the one associated with the default route.
  567. *
  568. * The tests SHOULD be re-enabled when #12377 is fixed correctly, but till
  569. * then this fails a lot, in situations we expect failures due to knowing
  570. * about the code being broken.
  571. */
  572. (void)addr4_to_check;
  573. (void)addr6_to_check;
  574. (void)addr6;
  575. (void) retval_reference;
  576. #endif /* 0 */
  577. /* When family is neither AF_INET nor AF_INET6, we want _hack to
  578. * fail and return -1.
  579. */
  580. retval = get_interface_address6_via_udp_socket_hack(LOG_DEBUG,
  581. AF_INET+AF_INET6,&addr4);
  582. tt_int_op(retval, OP_EQ, -1);
  583. done:
  584. return;
  585. }
  586. static void
  587. test_address_get_if_addrs_list_internal(void *arg)
  588. {
  589. smartlist_t *results = NULL;
  590. (void)arg;
  591. results = get_interface_address_list(LOG_ERR, 1);
  592. tt_ptr_op(results, OP_NE, NULL);
  593. /* When the network is down, a system might not have any non-local
  594. * non-multicast addresseses, not even internal ones.
  595. * Unit tests shouldn't fail because of this. */
  596. tt_int_op(smartlist_len(results),OP_GE,0);
  597. tt_assert(!smartlist_contains_localhost_tor_addr(results));
  598. tt_assert(!smartlist_contains_multicast_tor_addr(results));
  599. /* The list may or may not contain internal addresses */
  600. tt_assert(!smartlist_contains_null_tor_addr(results));
  601. /* if there are any addresses, they must be IPv4 */
  602. if (smartlist_len(results) > 0) {
  603. tt_assert(smartlist_contains_ipv4_tor_addr(results));
  604. }
  605. tt_assert(!smartlist_contains_ipv6_tor_addr(results));
  606. done:
  607. interface_address_list_free(results);
  608. return;
  609. }
  610. static void
  611. test_address_get_if_addrs_list_no_internal(void *arg)
  612. {
  613. smartlist_t *results = NULL;
  614. (void)arg;
  615. results = get_interface_address_list(LOG_ERR, 0);
  616. tt_ptr_op(results, OP_NE, NULL);
  617. /* Work even on systems with only internal IPv4 addresses */
  618. tt_int_op(smartlist_len(results),OP_GE,0);
  619. tt_assert(!smartlist_contains_localhost_tor_addr(results));
  620. tt_assert(!smartlist_contains_multicast_tor_addr(results));
  621. tt_assert(!smartlist_contains_internal_tor_addr(results));
  622. tt_assert(!smartlist_contains_null_tor_addr(results));
  623. /* if there are any addresses, they must be IPv4 */
  624. if (smartlist_len(results) > 0) {
  625. tt_assert(smartlist_contains_ipv4_tor_addr(results));
  626. }
  627. tt_assert(!smartlist_contains_ipv6_tor_addr(results));
  628. done:
  629. interface_address_list_free(results);
  630. return;
  631. }
  632. static void
  633. test_address_get_if_addrs6_list_internal(void *arg)
  634. {
  635. smartlist_t *results = NULL;
  636. (void)arg;
  637. /* We might drop a log_err */
  638. setup_full_capture_of_logs(LOG_ERR);
  639. results = get_interface_address6_list(LOG_ERR, AF_INET6, 1);
  640. tt_int_op(smartlist_len(mock_saved_logs()), OP_LE, 1);
  641. if (smartlist_len(mock_saved_logs()) == 1) {
  642. expect_log_msg_containing_either4("connect() failed",
  643. "unable to create socket",
  644. "Address that we determined via UDP "
  645. "socket magic is unsuitable for public "
  646. "comms.",
  647. "getsockname() to determine interface "
  648. "failed");
  649. }
  650. teardown_capture_of_logs();
  651. tt_ptr_op(results, OP_NE, NULL);
  652. /* Work even on systems without IPv6 interfaces */
  653. tt_int_op(smartlist_len(results),OP_GE,0);
  654. tt_assert(!smartlist_contains_localhost_tor_addr(results));
  655. tt_assert(!smartlist_contains_multicast_tor_addr(results));
  656. /* The list may or may not contain internal addresses */
  657. tt_assert(!smartlist_contains_null_tor_addr(results));
  658. /* if there are any addresses, they must be IPv6 */
  659. tt_assert(!smartlist_contains_ipv4_tor_addr(results));
  660. if (smartlist_len(results) > 0) {
  661. tt_assert(smartlist_contains_ipv6_tor_addr(results));
  662. }
  663. done:
  664. interface_address6_list_free(results);
  665. teardown_capture_of_logs();
  666. return;
  667. }
  668. static void
  669. test_address_get_if_addrs6_list_no_internal(void *arg)
  670. {
  671. smartlist_t *results = NULL;
  672. (void)arg;
  673. /* We might drop a log_err */
  674. setup_full_capture_of_logs(LOG_ERR);
  675. results = get_interface_address6_list(LOG_ERR, AF_INET6, 0);
  676. tt_int_op(smartlist_len(mock_saved_logs()), OP_LE, 1);
  677. if (smartlist_len(mock_saved_logs()) == 1) {
  678. expect_log_msg_containing_either4("connect() failed",
  679. "unable to create socket",
  680. "Address that we determined via UDP "
  681. "socket magic is unsuitable for public "
  682. "comms.",
  683. "getsockname() to determine interface "
  684. "failed");
  685. }
  686. teardown_capture_of_logs();
  687. tt_ptr_op(results, OP_NE, NULL);
  688. /* Work even on systems without IPv6 interfaces */
  689. tt_int_op(smartlist_len(results),OP_GE,0);
  690. tt_assert(!smartlist_contains_localhost_tor_addr(results));
  691. tt_assert(!smartlist_contains_multicast_tor_addr(results));
  692. tt_assert(!smartlist_contains_internal_tor_addr(results));
  693. tt_assert(!smartlist_contains_null_tor_addr(results));
  694. /* if there are any addresses, they must be IPv6 */
  695. tt_assert(!smartlist_contains_ipv4_tor_addr(results));
  696. if (smartlist_len(results) > 0) {
  697. tt_assert(smartlist_contains_ipv6_tor_addr(results));
  698. }
  699. done:
  700. teardown_capture_of_logs();
  701. interface_address6_list_free(results);
  702. return;
  703. }
  704. static int called_get_interface_addresses_raw = 0;
  705. static smartlist_t *
  706. mock_get_interface_addresses_raw_fail(int severity, sa_family_t family)
  707. {
  708. (void)severity;
  709. (void)family;
  710. called_get_interface_addresses_raw++;
  711. return smartlist_new();
  712. }
  713. static int called_get_interface_address6_via_udp_socket_hack = 0;
  714. static int
  715. mock_get_interface_address6_via_udp_socket_hack_fail(int severity,
  716. sa_family_t family,
  717. tor_addr_t *addr)
  718. {
  719. (void)severity;
  720. (void)family;
  721. (void)addr;
  722. called_get_interface_address6_via_udp_socket_hack++;
  723. return -1;
  724. }
  725. static void
  726. test_address_get_if_addrs_internal_fail(void *arg)
  727. {
  728. smartlist_t *results1 = NULL, *results2 = NULL;
  729. int rv = 0;
  730. uint32_t ipv4h_addr = 0;
  731. tor_addr_t ipv6_addr;
  732. memset(&ipv6_addr, 0, sizeof(tor_addr_t));
  733. (void)arg;
  734. MOCK(get_interface_addresses_raw,
  735. mock_get_interface_addresses_raw_fail);
  736. MOCK(get_interface_address6_via_udp_socket_hack,
  737. mock_get_interface_address6_via_udp_socket_hack_fail);
  738. results1 = get_interface_address6_list(LOG_ERR, AF_INET6, 1);
  739. tt_ptr_op(results1, OP_NE, NULL);
  740. tt_int_op(smartlist_len(results1),OP_EQ,0);
  741. results2 = get_interface_address_list(LOG_ERR, 1);
  742. tt_ptr_op(results2, OP_NE, NULL);
  743. tt_int_op(smartlist_len(results2),OP_EQ,0);
  744. rv = get_interface_address6(LOG_ERR, AF_INET6, &ipv6_addr);
  745. tt_int_op(rv, OP_EQ, -1);
  746. rv = get_interface_address(LOG_ERR, &ipv4h_addr);
  747. tt_int_op(rv, OP_EQ, -1);
  748. done:
  749. UNMOCK(get_interface_addresses_raw);
  750. UNMOCK(get_interface_address6_via_udp_socket_hack);
  751. interface_address6_list_free(results1);
  752. interface_address6_list_free(results2);
  753. return;
  754. }
  755. static void
  756. test_address_get_if_addrs_no_internal_fail(void *arg)
  757. {
  758. smartlist_t *results1 = NULL, *results2 = NULL;
  759. (void)arg;
  760. MOCK(get_interface_addresses_raw,
  761. mock_get_interface_addresses_raw_fail);
  762. MOCK(get_interface_address6_via_udp_socket_hack,
  763. mock_get_interface_address6_via_udp_socket_hack_fail);
  764. results1 = get_interface_address6_list(LOG_ERR, AF_INET6, 0);
  765. tt_ptr_op(results1, OP_NE, NULL);
  766. tt_int_op(smartlist_len(results1),OP_EQ,0);
  767. results2 = get_interface_address_list(LOG_ERR, 0);
  768. tt_ptr_op(results2, OP_NE, NULL);
  769. tt_int_op(smartlist_len(results2),OP_EQ,0);
  770. done:
  771. UNMOCK(get_interface_addresses_raw);
  772. UNMOCK(get_interface_address6_via_udp_socket_hack);
  773. interface_address6_list_free(results1);
  774. interface_address6_list_free(results2);
  775. return;
  776. }
  777. static void
  778. test_address_get_if_addrs(void *arg)
  779. {
  780. int rv;
  781. uint32_t addr_h = 0;
  782. tor_addr_t tor_addr;
  783. (void)arg;
  784. rv = get_interface_address(LOG_ERR, &addr_h);
  785. /* When the network is down, a system might not have any non-local
  786. * non-multicast IPv4 addresses, not even internal ones.
  787. * Unit tests shouldn't fail because of this. */
  788. if (rv == 0) {
  789. tor_addr_from_ipv4h(&tor_addr, addr_h);
  790. tt_assert(!tor_addr_is_loopback(&tor_addr));
  791. tt_assert(!tor_addr_is_multicast(&tor_addr));
  792. /* The address may or may not be an internal address */
  793. tt_assert(tor_addr_is_v4(&tor_addr));
  794. }
  795. done:
  796. return;
  797. }
  798. static void
  799. test_address_get_if_addrs6(void *arg)
  800. {
  801. int rv;
  802. tor_addr_t tor_addr;
  803. (void)arg;
  804. rv = get_interface_address6(LOG_ERR, AF_INET6, &tor_addr);
  805. /* Work even on systems without IPv6 interfaces */
  806. if (rv == 0) {
  807. tt_assert(!tor_addr_is_loopback(&tor_addr));
  808. tt_assert(!tor_addr_is_multicast(&tor_addr));
  809. /* The address may or may not be an internal address */
  810. tt_assert(!tor_addr_is_v4(&tor_addr));
  811. }
  812. done:
  813. return;
  814. }
  815. static void
  816. test_address_tor_addr_to_in6(void *ignored)
  817. {
  818. (void)ignored;
  819. tor_addr_t *a = tor_malloc_zero(sizeof(tor_addr_t));
  820. const struct in6_addr *res;
  821. uint8_t expected[16] = {42, 1, 2, 3, 4, 5, 6, 7, 8, 9,
  822. 10, 11, 12, 13, 14, 15};
  823. a->family = AF_INET;
  824. res = tor_addr_to_in6(a);
  825. tt_assert(!res);
  826. a->family = AF_INET6;
  827. memcpy(a->addr.in6_addr.s6_addr, expected, 16);
  828. res = tor_addr_to_in6(a);
  829. tt_assert(res);
  830. tt_mem_op(res->s6_addr, OP_EQ, expected, 16);
  831. done:
  832. tor_free(a);
  833. }
  834. static void
  835. test_address_tor_addr_to_in(void *ignored)
  836. {
  837. (void)ignored;
  838. tor_addr_t *a = tor_malloc_zero(sizeof(tor_addr_t));
  839. const struct in_addr *res;
  840. a->family = AF_INET6;
  841. res = tor_addr_to_in(a);
  842. tt_assert(!res);
  843. a->family = AF_INET;
  844. a->addr.in_addr.s_addr = 44;
  845. res = tor_addr_to_in(a);
  846. tt_assert(res);
  847. tt_int_op(res->s_addr, OP_EQ, 44);
  848. done:
  849. tor_free(a);
  850. }
  851. static void
  852. test_address_tor_addr_to_ipv4n(void *ignored)
  853. {
  854. (void)ignored;
  855. tor_addr_t *a = tor_malloc_zero(sizeof(tor_addr_t));
  856. uint32_t res;
  857. a->family = AF_INET6;
  858. res = tor_addr_to_ipv4n(a);
  859. tt_assert(!res);
  860. a->family = AF_INET;
  861. a->addr.in_addr.s_addr = 43;
  862. res = tor_addr_to_ipv4n(a);
  863. tt_assert(res);
  864. tt_int_op(res, OP_EQ, 43);
  865. done:
  866. tor_free(a);
  867. }
  868. static void
  869. test_address_tor_addr_to_mapped_ipv4h(void *ignored)
  870. {
  871. (void)ignored;
  872. tor_addr_t *a = tor_malloc_zero(sizeof(tor_addr_t));
  873. uint32_t res;
  874. uint8_t toset[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 0, 0, 0, 42};
  875. a->family = AF_INET;
  876. res = tor_addr_to_mapped_ipv4h(a);
  877. tt_assert(!res);
  878. a->family = AF_INET6;
  879. memcpy(a->addr.in6_addr.s6_addr, toset, 16);
  880. res = tor_addr_to_mapped_ipv4h(a);
  881. tt_assert(res);
  882. tt_int_op(res, OP_EQ, 42);
  883. done:
  884. tor_free(a);
  885. }
  886. static void
  887. test_address_tor_addr_eq_ipv4h(void *ignored)
  888. {
  889. (void)ignored;
  890. tor_addr_t *a = tor_malloc_zero(sizeof(tor_addr_t));
  891. int res;
  892. a->family = AF_INET6;
  893. res = tor_addr_eq_ipv4h(a, 42);
  894. tt_assert(!res);
  895. a->family = AF_INET;
  896. a->addr.in_addr.s_addr = 52;
  897. res = tor_addr_eq_ipv4h(a, 42);
  898. tt_assert(!res);
  899. a->addr.in_addr.s_addr = 52;
  900. res = tor_addr_eq_ipv4h(a, ntohl(52));
  901. tt_assert(res);
  902. done:
  903. tor_free(a);
  904. }
  905. static void
  906. test_address_tor_addr_in_same_network_family(void *ignored)
  907. {
  908. (void)ignored;
  909. tor_addr_t a, b;
  910. tor_addr_parse(&a, "8.8.8.8");
  911. tor_addr_parse(&b, "8.8.4.4");
  912. tt_int_op(addrs_in_same_network_family(&a, &b), OP_EQ, 1);
  913. tor_addr_parse(&a, "8.8.8.8");
  914. tor_addr_parse(&b, "1.1.1.1");
  915. tt_int_op(addrs_in_same_network_family(&a, &b), OP_EQ, 0);
  916. tor_addr_parse(&a, "8.8.8.8");
  917. tor_addr_parse(&b, "2001:4860:4860::8844");
  918. tt_int_op(addrs_in_same_network_family(&a, &b), OP_EQ, 0);
  919. tor_addr_parse(&a, "2001:4860:4860::8888");
  920. tor_addr_parse(&b, "2001:4860:4860::8844");
  921. tt_int_op(addrs_in_same_network_family(&a, &b), OP_EQ, 1);
  922. tor_addr_parse(&a, "2001:4860:4860::8888");
  923. tor_addr_parse(&b, "2001:470:20::2");
  924. tt_int_op(addrs_in_same_network_family(&a, &b), OP_EQ, 0);
  925. done:
  926. return;
  927. }
  928. #define ADDRESS_TEST(name, flags) \
  929. { #name, test_address_ ## name, flags, NULL, NULL }
  930. struct testcase_t address_tests[] = {
  931. ADDRESS_TEST(udp_socket_trick_whitebox, TT_FORK),
  932. ADDRESS_TEST(udp_socket_trick_blackbox, TT_FORK),
  933. ADDRESS_TEST(get_if_addrs_list_internal, 0),
  934. ADDRESS_TEST(get_if_addrs_list_no_internal, 0),
  935. ADDRESS_TEST(get_if_addrs6_list_internal, 0),
  936. ADDRESS_TEST(get_if_addrs6_list_no_internal, TT_FORK),
  937. ADDRESS_TEST(get_if_addrs_internal_fail, 0),
  938. ADDRESS_TEST(get_if_addrs_no_internal_fail, 0),
  939. ADDRESS_TEST(get_if_addrs, 0),
  940. ADDRESS_TEST(get_if_addrs6, 0),
  941. #ifdef HAVE_IFADDRS_TO_SMARTLIST
  942. ADDRESS_TEST(get_if_addrs_ifaddrs, TT_FORK),
  943. ADDRESS_TEST(ifaddrs_to_smartlist, 0),
  944. #endif
  945. #ifdef HAVE_IP_ADAPTER_TO_SMARTLIST
  946. ADDRESS_TEST(get_if_addrs_win32, TT_FORK),
  947. ADDRESS_TEST(ip_adapter_addresses_to_smartlist, 0),
  948. #endif
  949. #ifdef HAVE_IFCONF_TO_SMARTLIST
  950. ADDRESS_TEST(get_if_addrs_ioctl, TT_FORK),
  951. ADDRESS_TEST(ifreq_to_smartlist, 0),
  952. #endif
  953. ADDRESS_TEST(tor_addr_to_in6, 0),
  954. ADDRESS_TEST(tor_addr_to_in, 0),
  955. ADDRESS_TEST(tor_addr_to_ipv4n, 0),
  956. ADDRESS_TEST(tor_addr_to_mapped_ipv4h, 0),
  957. ADDRESS_TEST(tor_addr_eq_ipv4h, 0),
  958. ADDRESS_TEST(tor_addr_in_same_network_family, 0),
  959. END_OF_TESTCASES
  960. };