test_addr.c 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279
  1. /* Copyright (c) 2001-2004, Roger Dingledine.
  2. * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
  3. * Copyright (c) 2007-2019, The Tor Project, Inc. */
  4. /* See LICENSE for licensing information */
  5. #define ADDRESSMAP_PRIVATE
  6. #include "orconfig.h"
  7. #include "core/or/or.h"
  8. #include "lib/crypt_ops/crypto_rand.h"
  9. #include "test/test.h"
  10. #include "feature/client/addressmap.h"
  11. #include "test/log_test_helpers.h"
  12. #include "lib/net/resolve.h"
  13. #ifdef HAVE_SYS_UN_H
  14. #include <sys/un.h>
  15. #endif
  16. static void
  17. test_addr_basic(void *arg)
  18. {
  19. (void) arg;
  20. tt_int_op(0,OP_EQ, addr_mask_get_bits(0x0u));
  21. tt_int_op(32,OP_EQ, addr_mask_get_bits(0xFFFFFFFFu));
  22. tt_int_op(16,OP_EQ, addr_mask_get_bits(0xFFFF0000u));
  23. tt_int_op(31,OP_EQ, addr_mask_get_bits(0xFFFFFFFEu));
  24. tt_int_op(1,OP_EQ, addr_mask_get_bits(0x80000000u));
  25. /* Test inet_ntop */
  26. {
  27. char tmpbuf[TOR_ADDR_BUF_LEN];
  28. const char *ip = "176.192.208.224";
  29. struct in_addr in;
  30. /* good round trip */
  31. tt_int_op(tor_inet_pton(AF_INET, ip, &in), OP_EQ, 1);
  32. tt_ptr_op(tor_inet_ntop(AF_INET, &in, tmpbuf, sizeof(tmpbuf)),
  33. OP_EQ, &tmpbuf);
  34. tt_str_op(tmpbuf,OP_EQ, ip);
  35. /* just enough buffer length */
  36. tt_str_op(tor_inet_ntop(AF_INET, &in, tmpbuf, strlen(ip) + 1), OP_EQ, ip);
  37. /* too short buffer */
  38. tt_ptr_op(tor_inet_ntop(AF_INET, &in, tmpbuf, strlen(ip)),OP_EQ, NULL);
  39. }
  40. done:
  41. ;
  42. }
  43. #define test_op_ip6_(a,op,b,e1,e2) \
  44. STMT_BEGIN \
  45. tt_assert_test_fmt_type(a,b,e1" "#op" "e2,struct in6_addr*, \
  46. (fast_memcmp(val1_->s6_addr, val2_->s6_addr, 16) op 0), \
  47. char *, "%s", \
  48. { char *cp; \
  49. cp = print_ = tor_malloc(64); \
  50. for (int ii_=0;ii_<16;++ii_) { \
  51. tor_snprintf(cp, 3,"%02x", (unsigned)value_->s6_addr[ii_]); \
  52. cp += 2; \
  53. if (ii_ != 15) *cp++ = ':'; \
  54. } \
  55. }, \
  56. { tor_free(print_); }, \
  57. TT_EXIT_TEST_FUNCTION \
  58. ); \
  59. STMT_END
  60. /** Helper: Assert that two strings both decode as IPv6 addresses with
  61. * tor_inet_pton(), and both decode to the same address. */
  62. #define test_pton6_same(a,b) STMT_BEGIN \
  63. tt_int_op(tor_inet_pton(AF_INET6, a, &a1), OP_EQ, 1); \
  64. tt_int_op(tor_inet_pton(AF_INET6, b, &a2), OP_EQ, 1); \
  65. test_op_ip6_(&a1,OP_EQ,&a2,#a,#b); \
  66. STMT_END
  67. /** Helper: Assert that <b>a</b> is recognized as a bad IPv6 address by
  68. * tor_inet_pton(). */
  69. #define test_pton6_bad(a) \
  70. tt_int_op(0, OP_EQ, tor_inet_pton(AF_INET6, a, &a1))
  71. /** Helper: assert that <b>a</b>, when parsed by tor_inet_pton() and displayed
  72. * with tor_inet_ntop(), yields <b>b</b>. Also assert that <b>b</b> parses to
  73. * the same value as <b>a</b>. */
  74. #define test_ntop6_reduces(a,b) STMT_BEGIN \
  75. tt_int_op(tor_inet_pton(AF_INET6, a, &a1), OP_EQ, 1); \
  76. tt_str_op(tor_inet_ntop(AF_INET6, &a1, buf, sizeof(buf)), OP_EQ, b); \
  77. tt_int_op(tor_inet_pton(AF_INET6, b, &a2), OP_EQ, 1); \
  78. test_op_ip6_(&a1, OP_EQ, &a2, a, b); \
  79. STMT_END
  80. /** Helper: assert that <b>a</b> parses by tor_inet_pton() into a address that
  81. * passes tor_addr_is_internal() with <b>for_listening</b>. */
  82. #define test_internal_ip(a,for_listening) STMT_BEGIN \
  83. tt_int_op(tor_inet_pton(AF_INET6, a, &t1.addr.in6_addr), OP_EQ, 1); \
  84. t1.family = AF_INET6; \
  85. if (!tor_addr_is_internal(&t1, for_listening)) \
  86. TT_DIE(("%s was not internal", a)); \
  87. STMT_END
  88. /** Helper: assert that <b>a</b> parses by tor_inet_pton() into a address that
  89. * does not pass tor_addr_is_internal() with <b>for_listening</b>. */
  90. #define test_external_ip(a,for_listening) STMT_BEGIN \
  91. tt_int_op(tor_inet_pton(AF_INET6, a, &t1.addr.in6_addr), OP_EQ, 1); \
  92. t1.family = AF_INET6; \
  93. if (tor_addr_is_internal(&t1, for_listening)) \
  94. TT_DIE(("%s was not internal", a)); \
  95. STMT_END
  96. /** Helper: Assert that <b>a</b> and <b>b</b>, when parsed by
  97. * tor_inet_pton(), give addresses that compare in the order defined by
  98. * <b>op</b> with tor_addr_compare(). */
  99. #define test_addr_compare(a, op, b) STMT_BEGIN \
  100. tt_int_op(tor_inet_pton(AF_INET6, a, &t1.addr.in6_addr), OP_EQ, 1); \
  101. tt_int_op(tor_inet_pton(AF_INET6, b, &t2.addr.in6_addr), OP_EQ, 1); \
  102. t1.family = t2.family = AF_INET6; \
  103. r = tor_addr_compare(&t1,&t2,CMP_SEMANTIC); \
  104. if (!(r op 0)) \
  105. TT_DIE(("Failed: tor_addr_compare(%s,%s) %s 0", a, b, #op));\
  106. STMT_END
  107. /** Helper: Assert that <b>a</b> and <b>b</b>, when parsed by
  108. * tor_inet_pton(), give addresses that compare in the order defined by
  109. * <b>op</b> with tor_addr_compare_masked() with <b>m</b> masked. */
  110. #define test_addr_compare_masked(a, op, b, m) STMT_BEGIN \
  111. tt_int_op(tor_inet_pton(AF_INET6, a, &t1.addr.in6_addr), OP_EQ, 1); \
  112. tt_int_op(tor_inet_pton(AF_INET6, b, &t2.addr.in6_addr), OP_EQ, 1); \
  113. t1.family = t2.family = AF_INET6; \
  114. r = tor_addr_compare_masked(&t1,&t2,m,CMP_SEMANTIC); \
  115. if (!(r op 0)) \
  116. TT_DIE(("Failed: tor_addr_compare_masked(%s,%s,%d) %s 0", \
  117. a, b, m, #op)); \
  118. STMT_END
  119. /** Helper: assert that <b>xx</b> is parseable as a masked IPv6 address with
  120. * ports by tor_parse_mask_addr_ports(), with family <b>f</b>, IP address
  121. * as 4 32-bit words <b>ip1...ip4</b>, mask bits as <b>mm</b>, and port range
  122. * as <b>pt1..pt2</b>. */
  123. #define test_addr_mask_ports_parse(xx, f, ip1, ip2, ip3, ip4, mm, pt1, pt2) \
  124. STMT_BEGIN \
  125. tt_int_op(tor_addr_parse_mask_ports(xx, 0, &t1, &mask, &port1, &port2), \
  126. OP_EQ, f); \
  127. p1=tor_inet_ntop(AF_INET6, &t1.addr.in6_addr, bug, sizeof(bug)); \
  128. tt_int_op(htonl(ip1), OP_EQ, tor_addr_to_in6_addr32(&t1)[0]); \
  129. tt_int_op(htonl(ip2), OP_EQ, tor_addr_to_in6_addr32(&t1)[1]); \
  130. tt_int_op(htonl(ip3), OP_EQ, tor_addr_to_in6_addr32(&t1)[2]); \
  131. tt_int_op(htonl(ip4), OP_EQ, tor_addr_to_in6_addr32(&t1)[3]); \
  132. tt_int_op(mask, OP_EQ, mm); \
  133. tt_uint_op(port1, OP_EQ, pt1); \
  134. tt_uint_op(port2, OP_EQ, pt2); \
  135. STMT_END
  136. /** Run unit tests for IPv6 encoding/decoding/manipulation functions. */
  137. static void
  138. test_addr_ip6_helpers(void *arg)
  139. {
  140. char buf[TOR_ADDR_BUF_LEN], bug[TOR_ADDR_BUF_LEN];
  141. char rbuf[REVERSE_LOOKUP_NAME_BUF_LEN];
  142. struct in6_addr a1, a2;
  143. tor_addr_t t1, t2;
  144. int r, i;
  145. uint16_t port1, port2;
  146. maskbits_t mask;
  147. const char *p1;
  148. struct sockaddr_storage sa_storage;
  149. struct sockaddr_in *sin;
  150. struct sockaddr_in6 *sin6;
  151. /* Test tor_inet_ntop and tor_inet_pton: IPv6 */
  152. (void)arg;
  153. {
  154. const char *ip = "2001::1234";
  155. const char *ip_ffff = "::ffff:192.168.1.2";
  156. /* good round trip */
  157. tt_int_op(tor_inet_pton(AF_INET6, ip, &a1),OP_EQ, 1);
  158. tt_ptr_op(tor_inet_ntop(AF_INET6, &a1, buf, sizeof(buf)),OP_EQ, &buf);
  159. tt_str_op(buf,OP_EQ, ip);
  160. /* good round trip - ::ffff:0:0 style */
  161. tt_int_op(tor_inet_pton(AF_INET6, ip_ffff, &a2),OP_EQ, 1);
  162. tt_ptr_op(tor_inet_ntop(AF_INET6, &a2, buf, sizeof(buf)),OP_EQ, &buf);
  163. tt_str_op(buf,OP_EQ, ip_ffff);
  164. /* just long enough buffer (remember \0) */
  165. tt_str_op(tor_inet_ntop(AF_INET6, &a1, buf, strlen(ip)+1),OP_EQ, ip);
  166. tt_str_op(tor_inet_ntop(AF_INET6, &a2, buf, strlen(ip_ffff)+1),OP_EQ,
  167. ip_ffff);
  168. /* too short buffer (remember \0) */
  169. tt_ptr_op(tor_inet_ntop(AF_INET6, &a1, buf, strlen(ip)),OP_EQ, NULL);
  170. tt_ptr_op(tor_inet_ntop(AF_INET6, &a2, buf, strlen(ip_ffff)),OP_EQ, NULL);
  171. }
  172. /* ==== Converting to and from sockaddr_t. */
  173. sin = (struct sockaddr_in *)&sa_storage;
  174. sin->sin_family = AF_INET;
  175. sin->sin_port = htons(9090);
  176. sin->sin_addr.s_addr = htonl(0x7f7f0102); /*127.127.1.2*/
  177. tor_addr_from_sockaddr(&t1, (struct sockaddr *)sin, &port1);
  178. tt_int_op(tor_addr_family(&t1),OP_EQ, AF_INET);
  179. tt_int_op(tor_addr_to_ipv4h(&t1),OP_EQ, 0x7f7f0102);
  180. tt_int_op(port1, OP_EQ, 9090);
  181. memset(&sa_storage, 0, sizeof(sa_storage));
  182. tt_int_op(sizeof(struct sockaddr_in),OP_EQ,
  183. tor_addr_to_sockaddr(&t1, 1234, (struct sockaddr *)&sa_storage,
  184. sizeof(sa_storage)));
  185. tt_int_op(1234,OP_EQ, ntohs(sin->sin_port));
  186. tt_int_op(0x7f7f0102,OP_EQ, ntohl(sin->sin_addr.s_addr));
  187. memset(&sa_storage, 0, sizeof(sa_storage));
  188. sin6 = (struct sockaddr_in6 *)&sa_storage;
  189. sin6->sin6_family = AF_INET6;
  190. sin6->sin6_port = htons(7070);
  191. sin6->sin6_addr.s6_addr[0] = 128;
  192. tor_addr_from_sockaddr(&t1, (struct sockaddr *)sin6, &port1);
  193. tt_int_op(tor_addr_family(&t1),OP_EQ, AF_INET6);
  194. tt_int_op(port1, OP_EQ, 7070);
  195. p1 = tor_addr_to_str(buf, &t1, sizeof(buf), 0);
  196. tt_str_op(p1,OP_EQ, "8000::");
  197. memset(&sa_storage, 0, sizeof(sa_storage));
  198. tt_int_op(sizeof(struct sockaddr_in6),OP_EQ,
  199. tor_addr_to_sockaddr(&t1, 9999, (struct sockaddr *)&sa_storage,
  200. sizeof(sa_storage)));
  201. tt_int_op(AF_INET6,OP_EQ, sin6->sin6_family);
  202. tt_int_op(9999,OP_EQ, ntohs(sin6->sin6_port));
  203. tt_int_op(0x80000000,OP_EQ, ntohl(S6_ADDR32(sin6->sin6_addr)[0]));
  204. /* ==== tor_addr_lookup: static cases. (Can't test dns without knowing we
  205. * have a good resolver. */
  206. tt_int_op(0,OP_EQ, tor_addr_lookup("127.128.129.130", AF_UNSPEC, &t1));
  207. tt_int_op(AF_INET,OP_EQ, tor_addr_family(&t1));
  208. tt_int_op(tor_addr_to_ipv4h(&t1),OP_EQ, 0x7f808182);
  209. tt_int_op(0,OP_EQ, tor_addr_lookup("9000::5", AF_UNSPEC, &t1));
  210. tt_int_op(AF_INET6,OP_EQ, tor_addr_family(&t1));
  211. tt_int_op(0x90,OP_EQ, tor_addr_to_in6_addr8(&t1)[0]);
  212. tt_assert(tor_mem_is_zero((char*)tor_addr_to_in6_addr8(&t1)+1, 14));
  213. tt_int_op(0x05,OP_EQ, tor_addr_to_in6_addr8(&t1)[15]);
  214. /* === Test pton: valid af_inet6 */
  215. /* Simple, valid parsing. */
  216. r = tor_inet_pton(AF_INET6,
  217. "0102:0304:0506:0708:090A:0B0C:0D0E:0F10", &a1);
  218. tt_int_op(r, OP_EQ, 1);
  219. for (i=0;i<16;++i) { tt_int_op(i+1,OP_EQ, (int)a1.s6_addr[i]); }
  220. /* ipv4 ending. */
  221. test_pton6_same("0102:0304:0506:0708:090A:0B0C:0D0E:0F10",
  222. "0102:0304:0506:0708:090A:0B0C:13.14.15.16");
  223. /* shortened words. */
  224. test_pton6_same("0001:0099:BEEF:0000:0123:FFFF:0001:0001",
  225. "1:99:BEEF:0:0123:FFFF:1:1");
  226. /* zeros at the beginning */
  227. test_pton6_same("0000:0000:0000:0000:0009:C0A8:0001:0001",
  228. "::9:c0a8:1:1");
  229. test_pton6_same("0000:0000:0000:0000:0009:C0A8:0001:0001",
  230. "::9:c0a8:0.1.0.1");
  231. /* zeros in the middle. */
  232. test_pton6_same("fe80:0000:0000:0000:0202:1111:0001:0001",
  233. "fe80::202:1111:1:1");
  234. /* zeros at the end. */
  235. test_pton6_same("1000:0001:0000:0007:0000:0000:0000:0000",
  236. "1000:1:0:7::");
  237. /* === Test ntop: af_inet6 */
  238. test_ntop6_reduces("0:0:0:0:0:0:0:0", "::");
  239. test_ntop6_reduces("0001:0099:BEEF:0006:0123:FFFF:0001:0001",
  240. "1:99:beef:6:123:ffff:1:1");
  241. //test_ntop6_reduces("0:0:0:0:0:0:c0a8:0101", "::192.168.1.1");
  242. test_ntop6_reduces("0:0:0:0:0:ffff:c0a8:0101", "::ffff:192.168.1.1");
  243. test_ntop6_reduces("0:0:0:0:0:0:c0a8:0101", "::192.168.1.1");
  244. test_ntop6_reduces("002:0:0000:0:3::4", "2::3:0:0:4");
  245. test_ntop6_reduces("0:0::1:0:3", "::1:0:3");
  246. test_ntop6_reduces("008:0::0", "8::");
  247. test_ntop6_reduces("0:0:0:0:0:ffff::1", "::ffff:0.0.0.1");
  248. test_ntop6_reduces("abcd:0:0:0:0:0:7f00::", "abcd::7f00:0");
  249. test_ntop6_reduces("0000:0000:0000:0000:0009:C0A8:0001:0001",
  250. "::9:c0a8:1:1");
  251. test_ntop6_reduces("fe80:0000:0000:0000:0202:1111:0001:0001",
  252. "fe80::202:1111:1:1");
  253. test_ntop6_reduces("1000:0001:0000:0007:0000:0000:0000:0000",
  254. "1000:1:0:7::");
  255. /* Bad af param */
  256. tt_int_op(tor_inet_pton(AF_UNSPEC, 0, 0),OP_EQ, -1);
  257. /* === Test pton: invalid in6. */
  258. test_pton6_bad("foobar.");
  259. test_pton6_bad("-1::");
  260. test_pton6_bad("00001::");
  261. test_pton6_bad("10000::");
  262. test_pton6_bad("::10000");
  263. test_pton6_bad("55555::");
  264. test_pton6_bad("9:-60::");
  265. test_pton6_bad("9:+60::");
  266. test_pton6_bad("9|60::");
  267. test_pton6_bad("0x60::");
  268. test_pton6_bad("::0x60");
  269. test_pton6_bad("9:0x60::");
  270. test_pton6_bad("1:2:33333:4:0002:3::");
  271. test_pton6_bad("1:2:3333:4:fish:3::");
  272. test_pton6_bad("1:2:3:4:5:6:7:8:9");
  273. test_pton6_bad("1:2:3:4:5:6:7");
  274. test_pton6_bad("1:2:3:4:5:6:1.2.3.4.5");
  275. test_pton6_bad("1:2:3:4:5:6:1.2.3");
  276. test_pton6_bad("::1.2.3");
  277. test_pton6_bad("::1.2.3.4.5");
  278. test_pton6_bad("::ffff:0xff.0.0.0");
  279. test_pton6_bad("::ffff:ff.0.0.0");
  280. test_pton6_bad("::ffff:256.0.0.0");
  281. test_pton6_bad("::ffff:-1.0.0.0");
  282. test_pton6_bad("99");
  283. test_pton6_bad("");
  284. test_pton6_bad(".");
  285. test_pton6_bad(":");
  286. test_pton6_bad("1::2::3:4");
  287. test_pton6_bad("a:::b:c");
  288. test_pton6_bad(":::a:b:c");
  289. test_pton6_bad("a:b:c:::");
  290. test_pton6_bad("1.2.3.4");
  291. test_pton6_bad(":1.2.3.4");
  292. test_pton6_bad(".2.3.4");
  293. /* Regression tests for 22789. */
  294. test_pton6_bad("0xfoo");
  295. test_pton6_bad("0x88");
  296. test_pton6_bad("0xyxxy");
  297. test_pton6_bad("0XFOO");
  298. test_pton6_bad("0X88");
  299. test_pton6_bad("0XYXXY");
  300. test_pton6_bad("0x");
  301. test_pton6_bad("0X");
  302. /* test internal checking */
  303. test_external_ip("fbff:ffff::2:7", 0);
  304. test_internal_ip("fc01::2:7", 0);
  305. test_internal_ip("fc01::02:7", 0);
  306. test_internal_ip("fc01::002:7", 0);
  307. test_internal_ip("fc01::0002:7", 0);
  308. test_internal_ip("fdff:ffff::f:f", 0);
  309. test_external_ip("fe00::3:f", 0);
  310. test_external_ip("fe7f:ffff::2:7", 0);
  311. test_internal_ip("fe80::2:7", 0);
  312. test_internal_ip("febf:ffff::f:f", 0);
  313. test_internal_ip("fec0::2:7:7", 0);
  314. test_internal_ip("feff:ffff::e:7:7", 0);
  315. test_external_ip("ff00::e:7:7", 0);
  316. test_internal_ip("::", 0);
  317. test_internal_ip("::1", 0);
  318. test_internal_ip("::1", 1);
  319. test_internal_ip("::", 0);
  320. test_external_ip("::", 1);
  321. test_external_ip("::2", 0);
  322. test_external_ip("2001::", 0);
  323. test_external_ip("ffff::", 0);
  324. test_external_ip("::ffff:0.0.0.0", 1);
  325. test_internal_ip("::ffff:0.0.0.0", 0);
  326. test_internal_ip("::ffff:0.255.255.255", 0);
  327. test_external_ip("::ffff:1.0.0.0", 0);
  328. test_external_ip("::ffff:9.255.255.255", 0);
  329. test_internal_ip("::ffff:10.0.0.0", 0);
  330. test_internal_ip("::ffff:10.255.255.255", 0);
  331. test_external_ip("::ffff:11.0.0.0", 0);
  332. test_external_ip("::ffff:126.255.255.255", 0);
  333. test_internal_ip("::ffff:127.0.0.0", 0);
  334. test_internal_ip("::ffff:127.255.255.255", 0);
  335. test_external_ip("::ffff:128.0.0.0", 0);
  336. test_external_ip("::ffff:172.15.255.255", 0);
  337. test_internal_ip("::ffff:172.16.0.0", 0);
  338. test_internal_ip("::ffff:172.31.255.255", 0);
  339. test_external_ip("::ffff:172.32.0.0", 0);
  340. test_external_ip("::ffff:192.167.255.255", 0);
  341. test_internal_ip("::ffff:192.168.0.0", 0);
  342. test_internal_ip("::ffff:192.168.255.255", 0);
  343. test_external_ip("::ffff:192.169.0.0", 0);
  344. test_external_ip("::ffff:169.253.255.255", 0);
  345. test_internal_ip("::ffff:169.254.0.0", 0);
  346. test_internal_ip("::ffff:169.254.255.255", 0);
  347. test_external_ip("::ffff:169.255.0.0", 0);
  348. /* tor_addr_compare(tor_addr_t x2) */
  349. test_addr_compare("ffff::", OP_EQ, "ffff::0");
  350. test_addr_compare("0::3:2:1", OP_LT, "0::ffff:0.3.2.1");
  351. test_addr_compare("0::2:2:1", OP_LT, "0::ffff:0.3.2.1");
  352. test_addr_compare("0::ffff:0.3.2.1", OP_GT, "0::0:0:0");
  353. test_addr_compare("0::ffff:5.2.2.1", OP_LT,
  354. "::ffff:6.0.0.0"); /* XXXX wrong. */
  355. tor_addr_parse_mask_ports("[::ffff:2.3.4.5]", 0, &t1, NULL, NULL, NULL);
  356. tor_addr_parse_mask_ports("2.3.4.5", 0, &t2, NULL, NULL, NULL);
  357. tt_int_op(tor_addr_compare(&t1, &t2, CMP_SEMANTIC), OP_EQ, 0);
  358. tor_addr_parse_mask_ports("[::ffff:2.3.4.4]", 0, &t1, NULL, NULL, NULL);
  359. tor_addr_parse_mask_ports("2.3.4.5", 0, &t2, NULL, NULL, NULL);
  360. tt_int_op(tor_addr_compare(&t1, &t2, CMP_SEMANTIC), OP_LT, 0);
  361. /* test compare_masked */
  362. test_addr_compare_masked("ffff::", OP_EQ, "ffff::0", 128);
  363. test_addr_compare_masked("ffff::", OP_EQ, "ffff::0", 64);
  364. test_addr_compare_masked("0::2:2:1", OP_LT, "0::8000:2:1", 81);
  365. test_addr_compare_masked("0::2:2:1", OP_EQ, "0::8000:2:1", 80);
  366. /* Test undecorated tor_addr_to_str */
  367. tt_int_op(AF_INET6,OP_EQ, tor_addr_parse(&t1, "[123:45:6789::5005:11]"));
  368. p1 = tor_addr_to_str(buf, &t1, sizeof(buf), 0);
  369. tt_str_op(p1,OP_EQ, "123:45:6789::5005:11");
  370. tt_int_op(AF_INET,OP_EQ, tor_addr_parse(&t1, "18.0.0.1"));
  371. p1 = tor_addr_to_str(buf, &t1, sizeof(buf), 0);
  372. tt_str_op(p1,OP_EQ, "18.0.0.1");
  373. /* Test decorated tor_addr_to_str */
  374. tt_int_op(AF_INET6,OP_EQ, tor_addr_parse(&t1, "[123:45:6789::5005:11]"));
  375. p1 = tor_addr_to_str(buf, &t1, sizeof(buf), 1);
  376. tt_str_op(p1,OP_EQ, "[123:45:6789::5005:11]");
  377. tt_int_op(AF_INET,OP_EQ, tor_addr_parse(&t1, "18.0.0.1"));
  378. p1 = tor_addr_to_str(buf, &t1, sizeof(buf), 1);
  379. tt_str_op(p1,OP_EQ, "18.0.0.1");
  380. /* Test buffer bounds checking of tor_addr_to_str */
  381. tt_int_op(AF_INET6,OP_EQ, tor_addr_parse(&t1, "::")); /* 2 + \0 */
  382. tt_ptr_op(tor_addr_to_str(buf, &t1, 2, 0),OP_EQ, NULL); /* too short buf */
  383. tt_str_op(tor_addr_to_str(buf, &t1, 3, 0),OP_EQ, "::");
  384. tt_ptr_op(tor_addr_to_str(buf, &t1, 4, 1),OP_EQ, NULL); /* too short buf */
  385. tt_str_op(tor_addr_to_str(buf, &t1, 5, 1),OP_EQ, "[::]");
  386. tt_int_op(AF_INET6,OP_EQ, tor_addr_parse(&t1, "2000::1337")); /* 10 + \0 */
  387. tt_ptr_op(tor_addr_to_str(buf, &t1, 10, 0),OP_EQ, NULL); /* too short buf */
  388. tt_str_op(tor_addr_to_str(buf, &t1, 11, 0),OP_EQ, "2000::1337");
  389. tt_ptr_op(tor_addr_to_str(buf, &t1, 12, 1),OP_EQ, NULL); /* too short buf */
  390. tt_str_op(tor_addr_to_str(buf, &t1, 13, 1),OP_EQ, "[2000::1337]");
  391. tt_int_op(AF_INET,OP_EQ, tor_addr_parse(&t1, "1.2.3.4")); /* 7 + \0 */
  392. tt_ptr_op(tor_addr_to_str(buf, &t1, 7, 0),OP_EQ, NULL); /* too short buf */
  393. tt_str_op(tor_addr_to_str(buf, &t1, 8, 0),OP_EQ, "1.2.3.4");
  394. tt_int_op(AF_INET, OP_EQ,
  395. tor_addr_parse(&t1, "255.255.255.255")); /* 15 + \0 */
  396. tt_ptr_op(tor_addr_to_str(buf, &t1, 15, 0),OP_EQ, NULL); /* too short buf */
  397. tt_str_op(tor_addr_to_str(buf, &t1, 16, 0),OP_EQ, "255.255.255.255");
  398. tt_ptr_op(tor_addr_to_str(buf, &t1, 15, 1),OP_EQ, NULL); /* too short buf */
  399. tt_str_op(tor_addr_to_str(buf, &t1, 16, 1),OP_EQ, "255.255.255.255");
  400. t1.family = AF_UNSPEC;
  401. tt_ptr_op(tor_addr_to_str(buf, &t1, sizeof(buf), 0),OP_EQ, NULL);
  402. /* Test tor_addr_parse_PTR_name */
  403. i = tor_addr_parse_PTR_name(&t1, "Foobar.baz", AF_UNSPEC, 0);
  404. tt_int_op(0,OP_EQ, i);
  405. i = tor_addr_parse_PTR_name(&t1, "Foobar.baz", AF_UNSPEC, 1);
  406. tt_int_op(0,OP_EQ, i);
  407. i = tor_addr_parse_PTR_name(&t1, "9999999999999999999999999999.in-addr.arpa",
  408. AF_UNSPEC, 1);
  409. tt_int_op(-1,OP_EQ, i);
  410. i = tor_addr_parse_PTR_name(&t1, "1.0.168.192.in-addr.arpa",
  411. AF_UNSPEC, 1);
  412. tt_int_op(1,OP_EQ, i);
  413. tt_int_op(tor_addr_family(&t1),OP_EQ, AF_INET);
  414. p1 = tor_addr_to_str(buf, &t1, sizeof(buf), 1);
  415. tt_str_op(p1,OP_EQ, "192.168.0.1");
  416. i = tor_addr_parse_PTR_name(&t1, "192.168.0.99", AF_UNSPEC, 0);
  417. tt_int_op(0,OP_EQ, i);
  418. i = tor_addr_parse_PTR_name(&t1, "192.168.0.99", AF_UNSPEC, 1);
  419. tt_int_op(1,OP_EQ, i);
  420. p1 = tor_addr_to_str(buf, &t1, sizeof(buf), 1);
  421. tt_str_op(p1,OP_EQ, "192.168.0.99");
  422. memset(&t1, 0, sizeof(t1));
  423. i = tor_addr_parse_PTR_name(&t1,
  424. "0.1.2.3.4.5.6.7.8.9.a.b.c.d.e.f."
  425. "f.e.e.b.1.e.b.e.e.f.f.e.e.e.d.9."
  426. "ip6.ARPA",
  427. AF_UNSPEC, 0);
  428. tt_int_op(1,OP_EQ, i);
  429. p1 = tor_addr_to_str(buf, &t1, sizeof(buf), 1);
  430. tt_str_op(p1,OP_EQ, "[9dee:effe:ebe1:beef:fedc:ba98:7654:3210]");
  431. /* Failing cases. */
  432. i = tor_addr_parse_PTR_name(&t1,
  433. "6.7.8.9.a.b.c.d.e.f."
  434. "f.e.e.b.1.e.b.e.e.f.f.e.e.e.d.9."
  435. "ip6.ARPA",
  436. AF_UNSPEC, 0);
  437. tt_int_op(i,OP_EQ, -1);
  438. i = tor_addr_parse_PTR_name(&t1,
  439. "6.7.8.9.a.b.c.d.e.f.a.b.c.d.e.f.0."
  440. "f.e.e.b.1.e.b.e.e.f.f.e.e.e.d.9."
  441. "ip6.ARPA",
  442. AF_UNSPEC, 0);
  443. tt_int_op(i,OP_EQ, -1);
  444. i = tor_addr_parse_PTR_name(&t1,
  445. "6.7.8.9.a.b.c.d.e.f.X.0.0.0.0.9."
  446. "f.e.e.b.1.e.b.e.e.f.f.e.e.e.d.9."
  447. "ip6.ARPA",
  448. AF_UNSPEC, 0);
  449. tt_int_op(i,OP_EQ, -1);
  450. i = tor_addr_parse_PTR_name(&t1, "32.1.1.in-addr.arpa",
  451. AF_UNSPEC, 0);
  452. tt_int_op(i,OP_EQ, -1);
  453. i = tor_addr_parse_PTR_name(&t1, ".in-addr.arpa",
  454. AF_UNSPEC, 0);
  455. tt_int_op(i,OP_EQ, -1);
  456. i = tor_addr_parse_PTR_name(&t1, "1.2.3.4.5.in-addr.arpa",
  457. AF_UNSPEC, 0);
  458. tt_int_op(i,OP_EQ, -1);
  459. i = tor_addr_parse_PTR_name(&t1, "1.2.3.4.5.in-addr.arpa",
  460. AF_INET6, 0);
  461. tt_int_op(i,OP_EQ, -1);
  462. i = tor_addr_parse_PTR_name(&t1,
  463. "6.7.8.9.a.b.c.d.e.f.a.b.c.d.e.0."
  464. "f.e.e.b.1.e.b.e.e.f.f.e.e.e.d.9."
  465. "ip6.ARPA",
  466. AF_INET, 0);
  467. tt_int_op(i,OP_EQ, -1);
  468. /* === Test tor_addr_to_PTR_name */
  469. /* Stage IPv4 addr */
  470. memset(&sa_storage, 0, sizeof(sa_storage));
  471. sin = (struct sockaddr_in *)&sa_storage;
  472. sin->sin_family = AF_INET;
  473. sin->sin_addr.s_addr = htonl(0x7f010203); /* 127.1.2.3 */
  474. tor_addr_from_sockaddr(&t1, (struct sockaddr *)sin, NULL);
  475. /* Check IPv4 PTR - too short buffer */
  476. tt_int_op(tor_addr_to_PTR_name(rbuf, 1, &t1),OP_EQ, -1);
  477. tt_int_op(tor_addr_to_PTR_name(rbuf,
  478. strlen("3.2.1.127.in-addr.arpa") - 1,
  479. &t1),OP_EQ, -1);
  480. /* Check IPv4 PTR - valid addr */
  481. tt_int_op(tor_addr_to_PTR_name(rbuf, sizeof(rbuf), &t1),OP_EQ,
  482. strlen("3.2.1.127.in-addr.arpa"));
  483. tt_str_op(rbuf,OP_EQ, "3.2.1.127.in-addr.arpa");
  484. /* Invalid addr family */
  485. t1.family = AF_UNSPEC;
  486. tt_int_op(tor_addr_to_PTR_name(rbuf, sizeof(rbuf), &t1),OP_EQ, -1);
  487. /* Stage IPv6 addr */
  488. memset(&sa_storage, 0, sizeof(sa_storage));
  489. sin6 = (struct sockaddr_in6 *)&sa_storage;
  490. sin6->sin6_family = AF_INET6;
  491. sin6->sin6_addr.s6_addr[0] = 0x80; /* 8000::abcd */
  492. sin6->sin6_addr.s6_addr[14] = 0xab;
  493. sin6->sin6_addr.s6_addr[15] = 0xcd;
  494. tor_addr_from_sockaddr(&t1, (struct sockaddr *)sin6, NULL);
  495. {
  496. const char* addr_PTR = "d.c.b.a.0.0.0.0.0.0.0.0.0.0.0.0."
  497. "0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.8.ip6.arpa";
  498. /* Check IPv6 PTR - too short buffer */
  499. tt_int_op(tor_addr_to_PTR_name(rbuf, 0, &t1),OP_EQ, -1);
  500. tt_int_op(tor_addr_to_PTR_name(rbuf, strlen(addr_PTR) - 1, &t1),OP_EQ, -1);
  501. /* Check IPv6 PTR - valid addr */
  502. tt_int_op(tor_addr_to_PTR_name(rbuf, sizeof(rbuf), &t1),OP_EQ,
  503. strlen(addr_PTR));
  504. tt_str_op(rbuf,OP_EQ, addr_PTR);
  505. }
  506. /* XXXX turn this into a separate function; it's not all IPv6. */
  507. /* test tor_addr_parse_mask_ports */
  508. test_addr_mask_ports_parse("[::f]/17:47-95", AF_INET6,
  509. 0, 0, 0, 0x0000000f, 17, 47, 95);
  510. tt_str_op(p1,OP_EQ, "::f");
  511. //test_addr_parse("[::fefe:4.1.1.7/120]:999-1000");
  512. //test_addr_parse_check("::fefe:401:107", 120, 999, 1000);
  513. test_addr_mask_ports_parse("[::ffff:4.1.1.7]/120:443", AF_INET6,
  514. 0, 0, 0x0000ffff, 0x04010107, 120, 443, 443);
  515. tt_str_op(p1,OP_EQ, "::ffff:4.1.1.7");
  516. test_addr_mask_ports_parse("[abcd:2::44a:0]:2-65000", AF_INET6,
  517. 0xabcd0002, 0, 0, 0x044a0000, 128, 2, 65000);
  518. tt_str_op(p1,OP_EQ, "abcd:2::44a:0");
  519. /* Try some long addresses. */
  520. r=tor_addr_parse_mask_ports("[ffff:1111:1111:1111:1111:1111:1111:1111]",
  521. 0, &t1, NULL, NULL, NULL);
  522. tt_int_op(r, OP_EQ, AF_INET6);
  523. r=tor_addr_parse_mask_ports("[ffff:1111:1111:1111:1111:1111:1111:11111]",
  524. 0, &t1, NULL, NULL, NULL);
  525. tt_int_op(r, OP_EQ, -1);
  526. r=tor_addr_parse_mask_ports("[ffff:1111:1111:1111:1111:1111:1111:1111:1]",
  527. 0, &t1, NULL, NULL, NULL);
  528. tt_int_op(r, OP_EQ, -1);
  529. r=tor_addr_parse_mask_ports(
  530. "[ffff:1111:1111:1111:1111:1111:1111:ffff:"
  531. "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff:"
  532. "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff:"
  533. "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff]",
  534. 0, &t1, NULL, NULL, NULL);
  535. tt_int_op(r, OP_EQ, -1);
  536. /* Try some failing cases. */
  537. r=tor_addr_parse_mask_ports("[fefef::]/112", 0, &t1, NULL, NULL, NULL);
  538. tt_int_op(r, OP_EQ, -1);
  539. r=tor_addr_parse_mask_ports("[fefe::/112", 0, &t1, NULL, NULL, NULL);
  540. tt_int_op(r, OP_EQ, -1);
  541. r=tor_addr_parse_mask_ports("[fefe::", 0, &t1, NULL, NULL, NULL);
  542. tt_int_op(r, OP_EQ, -1);
  543. r=tor_addr_parse_mask_ports("[fefe::X]", 0, &t1, NULL, NULL, NULL);
  544. tt_int_op(r, OP_EQ, -1);
  545. r=tor_addr_parse_mask_ports("efef::/112", 0, &t1, NULL, NULL, NULL);
  546. tt_int_op(r, OP_EQ, -1);
  547. r=tor_addr_parse_mask_ports("[f:f:f:f:f:f:f:f::]",0,&t1, NULL, NULL, NULL);
  548. tt_int_op(r, OP_EQ, -1);
  549. r=tor_addr_parse_mask_ports("[::f:f:f:f:f:f:f:f]",0,&t1, NULL, NULL, NULL);
  550. tt_int_op(r, OP_EQ, -1);
  551. r=tor_addr_parse_mask_ports("[f:f:f:f:f:f:f:f:f]",0,&t1, NULL, NULL, NULL);
  552. tt_int_op(r, OP_EQ, -1);
  553. r=tor_addr_parse_mask_ports("[f:f:f:f:f::]/fred",0,&t1,&mask, NULL, NULL);
  554. tt_int_op(r, OP_EQ, -1);
  555. r=tor_addr_parse_mask_ports("[f:f:f:f:f::]/255.255.0.0",
  556. 0,&t1, NULL, NULL, NULL);
  557. tt_int_op(r, OP_EQ, -1);
  558. /* This one will get rejected because it isn't a pure prefix. */
  559. r=tor_addr_parse_mask_ports("1.1.2.3/255.255.64.0",0,&t1, &mask,NULL,NULL);
  560. tt_int_op(r, OP_EQ, -1);
  561. /* Test for V4-mapped address with mask < 96. (arguably not valid) */
  562. r=tor_addr_parse_mask_ports("[::ffff:1.1.2.2/33]",0,&t1, &mask, NULL, NULL);
  563. tt_int_op(r, OP_EQ, -1);
  564. r=tor_addr_parse_mask_ports("1.1.2.2/33",0,&t1, &mask, NULL, NULL);
  565. tt_int_op(r, OP_EQ, -1);
  566. /* Try extended wildcard addresses with out TAPMP_EXTENDED_STAR*/
  567. r=tor_addr_parse_mask_ports("*4",0,&t1, &mask, NULL, NULL);
  568. tt_int_op(r, OP_EQ, -1);
  569. r=tor_addr_parse_mask_ports("*6",0,&t1, &mask, NULL, NULL);
  570. tt_int_op(r, OP_EQ, -1);
  571. tt_int_op(r, OP_EQ, -1);
  572. /* Try a mask with a wildcard. */
  573. r=tor_addr_parse_mask_ports("*/16",0,&t1, &mask, NULL, NULL);
  574. tt_int_op(r, OP_EQ, -1);
  575. r=tor_addr_parse_mask_ports("*4/16",TAPMP_EXTENDED_STAR,
  576. &t1, &mask, NULL, NULL);
  577. tt_int_op(r, OP_EQ, -1);
  578. r=tor_addr_parse_mask_ports("*6/30",TAPMP_EXTENDED_STAR,
  579. &t1, &mask, NULL, NULL);
  580. tt_int_op(r, OP_EQ, -1);
  581. /* Basic mask tests*/
  582. r=tor_addr_parse_mask_ports("1.1.2.2/31",0,&t1, &mask, NULL, NULL);
  583. tt_int_op(r, OP_EQ, AF_INET);
  584. tt_int_op(mask,OP_EQ,31);
  585. tt_int_op(tor_addr_family(&t1),OP_EQ,AF_INET);
  586. tt_int_op(tor_addr_to_ipv4h(&t1),OP_EQ,0x01010202);
  587. r=tor_addr_parse_mask_ports("3.4.16.032:1-2",0,&t1, &mask, &port1, &port2);
  588. tt_int_op(r, OP_EQ, AF_INET);
  589. tt_int_op(mask,OP_EQ,32);
  590. tt_int_op(tor_addr_family(&t1),OP_EQ,AF_INET);
  591. tt_int_op(tor_addr_to_ipv4h(&t1),OP_EQ,0x03041020);
  592. tt_uint_op(port1, OP_EQ, 1);
  593. tt_uint_op(port2, OP_EQ, 2);
  594. r=tor_addr_parse_mask_ports("1.1.2.3/255.255.128.0",0,&t1, &mask,NULL,NULL);
  595. tt_int_op(r, OP_EQ, AF_INET);
  596. tt_int_op(mask,OP_EQ,17);
  597. tt_int_op(tor_addr_family(&t1),OP_EQ,AF_INET);
  598. tt_int_op(tor_addr_to_ipv4h(&t1),OP_EQ,0x01010203);
  599. r=tor_addr_parse_mask_ports("[efef::]/112",0,&t1, &mask, &port1, &port2);
  600. tt_int_op(r, OP_EQ, AF_INET6);
  601. tt_uint_op(port1, OP_EQ, 1);
  602. tt_uint_op(port2, OP_EQ, 65535);
  603. /* Try regular wildcard behavior without TAPMP_EXTENDED_STAR */
  604. r=tor_addr_parse_mask_ports("*:80-443",0,&t1,&mask,&port1,&port2);
  605. tt_int_op(r,OP_EQ,AF_INET); /* Old users of this always get inet */
  606. tt_int_op(tor_addr_family(&t1),OP_EQ,AF_INET);
  607. tt_int_op(tor_addr_to_ipv4h(&t1),OP_EQ,0);
  608. tt_int_op(mask,OP_EQ,0);
  609. tt_int_op(port1,OP_EQ,80);
  610. tt_int_op(port2,OP_EQ,443);
  611. /* Now try wildcards *with* TAPMP_EXTENDED_STAR */
  612. r=tor_addr_parse_mask_ports("*:8000-9000",TAPMP_EXTENDED_STAR,
  613. &t1,&mask,&port1,&port2);
  614. tt_int_op(r,OP_EQ,AF_UNSPEC);
  615. tt_int_op(tor_addr_family(&t1),OP_EQ,AF_UNSPEC);
  616. tt_int_op(mask,OP_EQ,0);
  617. tt_int_op(port1,OP_EQ,8000);
  618. tt_int_op(port2,OP_EQ,9000);
  619. r=tor_addr_parse_mask_ports("*4:6667",TAPMP_EXTENDED_STAR,
  620. &t1,&mask,&port1,&port2);
  621. tt_int_op(r,OP_EQ,AF_INET);
  622. tt_int_op(tor_addr_family(&t1),OP_EQ,AF_INET);
  623. tt_int_op(tor_addr_to_ipv4h(&t1),OP_EQ,0);
  624. tt_int_op(mask,OP_EQ,0);
  625. tt_int_op(port1,OP_EQ,6667);
  626. tt_int_op(port2,OP_EQ,6667);
  627. r=tor_addr_parse_mask_ports("*6",TAPMP_EXTENDED_STAR,
  628. &t1,&mask,&port1,&port2);
  629. tt_int_op(r,OP_EQ,AF_INET6);
  630. tt_int_op(tor_addr_family(&t1),OP_EQ,AF_INET6);
  631. tt_assert(tor_mem_is_zero((const char*)tor_addr_to_in6_addr32(&t1), 16));
  632. tt_int_op(mask,OP_EQ,0);
  633. tt_int_op(port1,OP_EQ,1);
  634. tt_int_op(port2,OP_EQ,65535);
  635. /* make sure inet address lengths >= max */
  636. tt_int_op(INET_NTOA_BUF_LEN, OP_GE, sizeof("255.255.255.255"));
  637. tt_int_op(TOR_ADDR_BUF_LEN, OP_GE,
  638. sizeof("ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"));
  639. tt_assert(sizeof(tor_addr_t) >= sizeof(struct in6_addr));
  640. /* get interface addresses */
  641. r = get_interface_address6(LOG_DEBUG, AF_INET, &t1);
  642. tt_int_op(r, OP_LE, 0); // "it worked or it didn't"
  643. i = get_interface_address6(LOG_DEBUG, AF_INET6, &t2);
  644. tt_int_op(i, OP_LE, 0); // "it worked or it didn't"
  645. TT_BLATHER(("v4 address: %s (family=%d)", fmt_addr(&t1),
  646. tor_addr_family(&t1)));
  647. TT_BLATHER(("v6 address: %s (family=%d)", fmt_addr(&t2),
  648. tor_addr_family(&t2)));
  649. done:
  650. ;
  651. }
  652. /** Test tor_addr_parse() and tor_addr_port_parse(). */
  653. static void
  654. test_addr_parse(void *arg)
  655. {
  656. int r;
  657. tor_addr_t addr;
  658. char buf[TOR_ADDR_BUF_LEN];
  659. uint16_t port = 0;
  660. /* Correct call. */
  661. (void)arg;
  662. r= tor_addr_parse(&addr, "192.0.2.1");
  663. tt_int_op(r,OP_EQ, AF_INET);
  664. tor_addr_to_str(buf, &addr, sizeof(buf), 0);
  665. tt_str_op(buf,OP_EQ, "192.0.2.1");
  666. r= tor_addr_parse(&addr, "11:22::33:44");
  667. tt_int_op(r,OP_EQ, AF_INET6);
  668. tor_addr_to_str(buf, &addr, sizeof(buf), 0);
  669. tt_str_op(buf,OP_EQ, "11:22::33:44");
  670. r= tor_addr_parse(&addr, "[11:22::33:44]");
  671. tt_int_op(r,OP_EQ, AF_INET6);
  672. tor_addr_to_str(buf, &addr, sizeof(buf), 0);
  673. tt_str_op(buf,OP_EQ, "11:22::33:44");
  674. r= tor_addr_parse(&addr, "11:22:33:44:55:66:1.2.3.4");
  675. tt_int_op(r,OP_EQ, AF_INET6);
  676. tor_addr_to_str(buf, &addr, sizeof(buf), 0);
  677. tt_str_op(buf,OP_EQ, "11:22:33:44:55:66:102:304");
  678. r= tor_addr_parse(&addr, "11:22::33:44:1.2.3.4");
  679. tt_int_op(r,OP_EQ, AF_INET6);
  680. tor_addr_to_str(buf, &addr, sizeof(buf), 0);
  681. tt_str_op(buf,OP_EQ, "11:22::33:44:102:304");
  682. /* Empty string. */
  683. r= tor_addr_parse(&addr, "");
  684. tt_int_op(r,OP_EQ, -1);
  685. /* Square brackets around IPv4 address. */
  686. r= tor_addr_parse(&addr, "[192.0.2.1]");
  687. tt_int_op(r,OP_EQ, -1);
  688. /* Only left square bracket. */
  689. r= tor_addr_parse(&addr, "[11:22::33:44");
  690. tt_int_op(r,OP_EQ, -1);
  691. /* Only right square bracket. */
  692. r= tor_addr_parse(&addr, "11:22::33:44]");
  693. tt_int_op(r,OP_EQ, -1);
  694. /* Leading colon. */
  695. r= tor_addr_parse(&addr, ":11:22::33:44");
  696. tt_int_op(r,OP_EQ, -1);
  697. /* Trailing colon. */
  698. r= tor_addr_parse(&addr, "11:22::33:44:");
  699. tt_int_op(r,OP_EQ, -1);
  700. /* Too many hex words in IPv4-mapped IPv6 address. */
  701. r= tor_addr_parse(&addr, "11:22:33:44:55:66:77:88:1.2.3.4");
  702. tt_int_op(r,OP_EQ, -1);
  703. /* Correct call. */
  704. r= tor_addr_port_parse(LOG_DEBUG,
  705. "192.0.2.1:1234",
  706. &addr, &port, -1);
  707. tt_int_op(r, OP_EQ, 0);
  708. tor_addr_to_str(buf, &addr, sizeof(buf), 0);
  709. tt_str_op(buf,OP_EQ, "192.0.2.1");
  710. tt_int_op(port,OP_EQ, 1234);
  711. r= tor_addr_port_parse(LOG_DEBUG,
  712. "[::1]:1234",
  713. &addr, &port, -1);
  714. tt_int_op(r, OP_EQ, 0);
  715. tor_addr_to_str(buf, &addr, sizeof(buf), 0);
  716. tt_str_op(buf,OP_EQ, "::1");
  717. tt_int_op(port,OP_EQ, 1234);
  718. /* Domain name. */
  719. r= tor_addr_port_parse(LOG_DEBUG,
  720. "torproject.org:1234",
  721. &addr, &port, -1);
  722. tt_int_op(r, OP_EQ, -1);
  723. /* Only IP. */
  724. r= tor_addr_port_parse(LOG_DEBUG,
  725. "192.0.2.2",
  726. &addr, &port, -1);
  727. tt_int_op(r, OP_EQ, -1);
  728. r= tor_addr_port_parse(LOG_DEBUG,
  729. "192.0.2.2",
  730. &addr, &port, 200);
  731. tt_int_op(r, OP_EQ, 0);
  732. tt_int_op(port,OP_EQ,200);
  733. r= tor_addr_port_parse(LOG_DEBUG,
  734. "[::1]",
  735. &addr, &port, -1);
  736. tt_int_op(r, OP_EQ, -1);
  737. r= tor_addr_port_parse(LOG_DEBUG,
  738. "[::1]",
  739. &addr, &port, 400);
  740. tt_int_op(r, OP_EQ, 0);
  741. tt_int_op(port,OP_EQ,400);
  742. /* Bad port. */
  743. r= tor_addr_port_parse(LOG_DEBUG,
  744. "192.0.2.2:66666",
  745. &addr, &port, -1);
  746. tt_int_op(r, OP_EQ, -1);
  747. r= tor_addr_port_parse(LOG_DEBUG,
  748. "192.0.2.2:66666",
  749. &addr, &port, 200);
  750. tt_int_op(r, OP_EQ, -1);
  751. /* Only domain name */
  752. r= tor_addr_port_parse(LOG_DEBUG,
  753. "torproject.org",
  754. &addr, &port, -1);
  755. tt_int_op(r, OP_EQ, -1);
  756. r= tor_addr_port_parse(LOG_DEBUG,
  757. "torproject.org",
  758. &addr, &port, 200);
  759. tt_int_op(r, OP_EQ, -1);
  760. /* Bad IP address */
  761. r= tor_addr_port_parse(LOG_DEBUG,
  762. "192.0.2:1234",
  763. &addr, &port, -1);
  764. tt_int_op(r, OP_EQ, -1);
  765. /* Make sure that the default port has lower priority than the real
  766. one */
  767. r= tor_addr_port_parse(LOG_DEBUG,
  768. "192.0.2.2:1337",
  769. &addr, &port, 200);
  770. tt_int_op(r, OP_EQ, 0);
  771. tt_int_op(port,OP_EQ,1337);
  772. r= tor_addr_port_parse(LOG_DEBUG,
  773. "[::1]:1369",
  774. &addr, &port, 200);
  775. tt_int_op(r, OP_EQ, 0);
  776. tt_int_op(port,OP_EQ,1369);
  777. done:
  778. ;
  779. }
  780. static void
  781. update_difference(int ipv6, uint8_t *d,
  782. const tor_addr_t *a, const tor_addr_t *b)
  783. {
  784. const int n_bytes = ipv6 ? 16 : 4;
  785. uint8_t a_tmp[4], b_tmp[4];
  786. const uint8_t *ba, *bb;
  787. int i;
  788. if (ipv6) {
  789. ba = tor_addr_to_in6_addr8(a);
  790. bb = tor_addr_to_in6_addr8(b);
  791. } else {
  792. set_uint32(a_tmp, tor_addr_to_ipv4n(a));
  793. set_uint32(b_tmp, tor_addr_to_ipv4n(b));
  794. ba = a_tmp; bb = b_tmp;
  795. }
  796. for (i = 0; i < n_bytes; ++i) {
  797. d[i] |= ba[i] ^ bb[i];
  798. }
  799. }
  800. static void
  801. test_virtaddrmap(void *data)
  802. {
  803. /* Let's start with a bunch of random addresses. */
  804. int ipv6, bits, iter, b;
  805. virtual_addr_conf_t cfg[2];
  806. uint8_t bytes[16];
  807. (void)data;
  808. tor_addr_parse(&cfg[0].addr, "64.65.0.0");
  809. tor_addr_parse(&cfg[1].addr, "3491:c0c0::");
  810. for (ipv6 = 0; ipv6 <= 1; ++ipv6) {
  811. for (bits = 0; bits < 18; ++bits) {
  812. tor_addr_t last_a;
  813. cfg[ipv6].bits = bits;
  814. memset(bytes, 0, sizeof(bytes));
  815. tor_addr_copy(&last_a, &cfg[ipv6].addr);
  816. /* Generate 128 addresses with each addr/bits combination. */
  817. for (iter = 0; iter < 128; ++iter) {
  818. tor_addr_t a;
  819. get_random_virtual_addr(&cfg[ipv6], &a);
  820. //printf("%s\n", fmt_addr(&a));
  821. /* Make sure that the first b bits match the configured network */
  822. tt_int_op(0, OP_EQ, tor_addr_compare_masked(&a, &cfg[ipv6].addr,
  823. bits, CMP_EXACT));
  824. /* And track which bits have been different between pairs of
  825. * addresses */
  826. update_difference(ipv6, bytes, &last_a, &a);
  827. }
  828. /* Now make sure all but the first 'bits' bits of bytes are true */
  829. for (b = bits+1; b < (ipv6?128:32); ++b) {
  830. tt_assert(1 & (bytes[b/8] >> (7-(b&7))));
  831. }
  832. }
  833. }
  834. done:
  835. ;
  836. }
  837. static const char *canned_data = NULL;
  838. static size_t canned_data_len = 0;
  839. /* Mock replacement for crypto_rand() that returns canned data from
  840. * canned_data above. */
  841. static void
  842. crypto_canned(char *ptr, size_t n)
  843. {
  844. if (canned_data_len) {
  845. size_t to_copy = MIN(n, canned_data_len);
  846. memcpy(ptr, canned_data, to_copy);
  847. canned_data += to_copy;
  848. canned_data_len -= to_copy;
  849. n -= to_copy;
  850. ptr += to_copy;
  851. }
  852. if (n) {
  853. crypto_rand_unmocked(ptr, n);
  854. }
  855. }
  856. static void
  857. test_virtaddrmap_persist(void *data)
  858. {
  859. (void)data;
  860. const char *a, *b, *c;
  861. tor_addr_t addr;
  862. char *ones = NULL;
  863. addressmap_init();
  864. // Try a hostname.
  865. a = addressmap_register_virtual_address(RESOLVED_TYPE_HOSTNAME,
  866. tor_strdup("foobar.baz"));
  867. tt_assert(a);
  868. tt_assert(!strcmpend(a, ".virtual"));
  869. // mock crypto_rand to repeat the same result twice; make sure we get
  870. // different outcomes. (Because even though the odds for receiving the
  871. // same 80-bit address twice is only 1/2^40, it could still happen for
  872. // some user -- but running our test through 2^40 iterations isn't
  873. // reasonable.)
  874. canned_data = "1234567890" // the first call returns this.
  875. "1234567890" // the second call returns this.
  876. "abcdefghij"; // the third call returns this.
  877. canned_data_len = 30;
  878. MOCK(crypto_rand, crypto_canned);
  879. a = addressmap_register_virtual_address(RESOLVED_TYPE_HOSTNAME,
  880. tor_strdup("quuxit.baz"));
  881. b = addressmap_register_virtual_address(RESOLVED_TYPE_HOSTNAME,
  882. tor_strdup("nescio.baz"));
  883. tt_assert(a);
  884. tt_assert(b);
  885. tt_str_op(a, OP_EQ, "gezdgnbvgy3tqojq.virtual");
  886. tt_str_op(b, OP_EQ, "mfrggzdfmztwq2lk.virtual");
  887. // Now try something to get us an ipv4 address
  888. UNMOCK(crypto_rand);
  889. tt_int_op(0,OP_EQ, parse_virtual_addr_network("192.168.0.0/16",
  890. AF_INET, 0, NULL));
  891. a = addressmap_register_virtual_address(RESOLVED_TYPE_IPV4,
  892. tor_strdup("foobar.baz"));
  893. tt_assert(a);
  894. tt_assert(!strcmpstart(a, "192.168."));
  895. tor_addr_parse(&addr, a);
  896. tt_int_op(AF_INET, OP_EQ, tor_addr_family(&addr));
  897. b = addressmap_register_virtual_address(RESOLVED_TYPE_IPV4,
  898. tor_strdup("quuxit.baz"));
  899. tt_str_op(b, OP_NE, a);
  900. tt_assert(!strcmpstart(b, "192.168."));
  901. // Try some canned entropy and verify all the we discard duplicates,
  902. // addresses that end with 0, and addresses that end with 255.
  903. MOCK(crypto_rand, crypto_canned);
  904. canned_data = "\x01\x02\x03\x04" // okay
  905. "\x01\x02\x03\x04" // duplicate
  906. "\x03\x04\x00\x00" // bad ending 1
  907. "\x05\x05\x00\xff" // bad ending 2
  908. "\x05\x06\x07\xf0"; // okay
  909. canned_data_len = 20;
  910. a = addressmap_register_virtual_address(RESOLVED_TYPE_IPV4,
  911. tor_strdup("wumble.onion"));
  912. b = addressmap_register_virtual_address(RESOLVED_TYPE_IPV4,
  913. tor_strdup("wumpus.onion"));
  914. tt_str_op(a, OP_EQ, "192.168.3.4");
  915. tt_str_op(b, OP_EQ, "192.168.7.240");
  916. // Now try IPv6!
  917. UNMOCK(crypto_rand);
  918. tt_int_op(0,OP_EQ, parse_virtual_addr_network("1010:F000::/20",
  919. AF_INET6, 0, NULL));
  920. a = addressmap_register_virtual_address(RESOLVED_TYPE_IPV6,
  921. tor_strdup("foobar.baz"));
  922. tt_assert(a);
  923. tt_assert(!strcmpstart(a, "[1010:f"));
  924. tor_addr_parse(&addr, a);
  925. tt_int_op(AF_INET6, OP_EQ, tor_addr_family(&addr));
  926. b = addressmap_register_virtual_address(RESOLVED_TYPE_IPV6,
  927. tor_strdup("quuxit.baz"));
  928. tt_str_op(b, OP_NE, a);
  929. tt_assert(!strcmpstart(b, "[1010:f"));
  930. // Try IPv6 with canned entropy, to make sure we detect duplicates.
  931. MOCK(crypto_rand, crypto_canned);
  932. canned_data = "acanthopterygian" // okay
  933. "cinematographist" // okay
  934. "acanthopterygian" // duplicate
  935. "acanthopterygian" // duplicate
  936. "acanthopterygian" // duplicate
  937. "cinematographist" // duplicate
  938. "coadministration"; // okay
  939. canned_data_len = 16 * 7;
  940. a = addressmap_register_virtual_address(RESOLVED_TYPE_IPV6,
  941. tor_strdup("wuffle.baz"));
  942. b = addressmap_register_virtual_address(RESOLVED_TYPE_IPV6,
  943. tor_strdup("gribble.baz"));
  944. c = addressmap_register_virtual_address(RESOLVED_TYPE_IPV6,
  945. tor_strdup("surprisingly-legible.baz"));
  946. tt_str_op(a, OP_EQ, "[1010:f16e:7468:6f70:7465:7279:6769:616e]");
  947. tt_str_op(b, OP_EQ, "[1010:fe65:6d61:746f:6772:6170:6869:7374]");
  948. tt_str_op(c, OP_EQ, "[1010:f164:6d69:6e69:7374:7261:7469:6f6e]");
  949. // Try address exhaustion: make sure we can actually fail if we
  950. // get too many already-existing addresses.
  951. canned_data_len = 128*1024;
  952. canned_data = ones = tor_malloc(canned_data_len);
  953. memset(ones, 1, canned_data_len);
  954. // There is some chance this one will fail if a previous random
  955. // allocation gave out the address already.
  956. a = addressmap_register_virtual_address(RESOLVED_TYPE_IPV4,
  957. tor_strdup("might-work.onion"));
  958. if (a) {
  959. tt_str_op(a, OP_EQ, "192.168.1.1");
  960. }
  961. setup_capture_of_logs(LOG_WARN);
  962. // This one will definitely fail, since we've set up the RNG to hand
  963. // out "1" forever.
  964. b = addressmap_register_virtual_address(RESOLVED_TYPE_IPV4,
  965. tor_strdup("wont-work.onion"));
  966. tt_assert(b == NULL);
  967. expect_single_log_msg_containing("Ran out of virtual addresses!");
  968. done:
  969. UNMOCK(crypto_rand);
  970. tor_free(ones);
  971. addressmap_free_all();
  972. teardown_capture_of_logs();
  973. }
  974. static void
  975. test_addr_localname(void *arg)
  976. {
  977. (void)arg;
  978. tt_assert(tor_addr_hostname_is_local("localhost"));
  979. tt_assert(tor_addr_hostname_is_local("LOCALHOST"));
  980. tt_assert(tor_addr_hostname_is_local("LocalHost"));
  981. tt_assert(tor_addr_hostname_is_local("local"));
  982. tt_assert(tor_addr_hostname_is_local("LOCAL"));
  983. tt_assert(tor_addr_hostname_is_local("here.now.local"));
  984. tt_assert(tor_addr_hostname_is_local("here.now.LOCAL"));
  985. tt_assert(!tor_addr_hostname_is_local(" localhost"));
  986. tt_assert(!tor_addr_hostname_is_local("www.torproject.org"));
  987. done:
  988. ;
  989. }
  990. static void
  991. test_addr_dup_ip(void *arg)
  992. {
  993. char *v = NULL;
  994. (void)arg;
  995. #define CHECK(ip, s) do { \
  996. v = tor_dup_ip(ip); \
  997. tt_str_op(v,OP_EQ,(s)); \
  998. tor_free(v); \
  999. } while (0)
  1000. CHECK(0xffffffff, "255.255.255.255");
  1001. CHECK(0x00000000, "0.0.0.0");
  1002. CHECK(0x7f000001, "127.0.0.1");
  1003. CHECK(0x01020304, "1.2.3.4");
  1004. #undef CHECK
  1005. done:
  1006. tor_free(v);
  1007. }
  1008. static void
  1009. test_addr_sockaddr_to_str(void *arg)
  1010. {
  1011. char *v = NULL;
  1012. struct sockaddr_in sin;
  1013. struct sockaddr_in6 sin6;
  1014. struct sockaddr_storage ss;
  1015. #ifdef HAVE_SYS_UN_H
  1016. struct sockaddr_un s_un;
  1017. #endif
  1018. #define CHECK(sa, s) do { \
  1019. v = tor_sockaddr_to_str((const struct sockaddr*) &(sa)); \
  1020. tt_str_op(v,OP_EQ,(s)); \
  1021. tor_free(v); \
  1022. } while (0)
  1023. (void)arg;
  1024. memset(&ss,0,sizeof(ss));
  1025. ss.ss_family = AF_UNSPEC;
  1026. CHECK(ss, "unspec");
  1027. memset(&sin,0,sizeof(sin));
  1028. sin.sin_family = AF_INET;
  1029. sin.sin_addr.s_addr = htonl(0x7f808001);
  1030. sin.sin_port = htons(1234);
  1031. CHECK(sin, "127.128.128.1:1234");
  1032. #ifdef HAVE_SYS_UN_H
  1033. memset(&s_un,0,sizeof(s_un));
  1034. s_un.sun_family = AF_UNIX;
  1035. strlcpy(s_un.sun_path, "/here/is/a/path", sizeof(s_un.sun_path));
  1036. CHECK(s_un, "unix:/here/is/a/path");
  1037. #endif /* defined(HAVE_SYS_UN_H) */
  1038. memset(&sin6,0,sizeof(sin6));
  1039. sin6.sin6_family = AF_INET6;
  1040. memcpy(sin6.sin6_addr.s6_addr, "\x20\x00\x00\x00\x00\x00\x00\x00"
  1041. "\x00\x1a\x2b\x3c\x4d\x5e\x00\x01", 16);
  1042. sin6.sin6_port = htons(1234);
  1043. CHECK(sin6, "[2000::1a:2b3c:4d5e:1]:1234");
  1044. done:
  1045. tor_free(v);
  1046. }
  1047. static void
  1048. test_addr_is_loopback(void *data)
  1049. {
  1050. static const struct loopback_item {
  1051. const char *name;
  1052. int is_loopback;
  1053. } loopback_items[] = {
  1054. { "::1", 1 },
  1055. { "127.0.0.1", 1 },
  1056. { "127.99.100.101", 1 },
  1057. { "128.99.100.101", 0 },
  1058. { "8.8.8.8", 0 },
  1059. { "0.0.0.0", 0 },
  1060. { "::2", 0 },
  1061. { "::", 0 },
  1062. { "::1.0.0.0", 0 },
  1063. { NULL, 0 }
  1064. };
  1065. int i;
  1066. tor_addr_t addr;
  1067. (void)data;
  1068. for (i=0; loopback_items[i].name; ++i) {
  1069. tt_int_op(tor_addr_parse(&addr, loopback_items[i].name), OP_GE, 0);
  1070. tt_int_op(tor_addr_is_loopback(&addr), OP_EQ,
  1071. loopback_items[i].is_loopback);
  1072. }
  1073. tor_addr_make_unspec(&addr);
  1074. tt_int_op(tor_addr_is_loopback(&addr), OP_EQ, 0);
  1075. done:
  1076. ;
  1077. }
  1078. static void
  1079. test_addr_make_null(void *data)
  1080. {
  1081. tor_addr_t *addr = tor_malloc(sizeof(*addr));
  1082. tor_addr_t *zeros = tor_malloc_zero(sizeof(*addr));
  1083. char buf[TOR_ADDR_BUF_LEN];
  1084. (void) data;
  1085. /* Ensure that before tor_addr_make_null, addr != 0's */
  1086. memset(addr, 1, sizeof(*addr));
  1087. tt_int_op(fast_memcmp(addr, zeros, sizeof(*addr)), OP_NE, 0);
  1088. /* Test with AF == AF_INET */
  1089. zeros->family = AF_INET;
  1090. tor_addr_make_null(addr, AF_INET);
  1091. tt_int_op(fast_memcmp(addr, zeros, sizeof(*addr)), OP_EQ, 0);
  1092. tt_str_op(tor_addr_to_str(buf, addr, sizeof(buf), 0), OP_EQ, "0.0.0.0");
  1093. /* Test with AF == AF_INET6 */
  1094. memset(addr, 1, sizeof(*addr));
  1095. zeros->family = AF_INET6;
  1096. tor_addr_make_null(addr, AF_INET6);
  1097. tt_int_op(fast_memcmp(addr, zeros, sizeof(*addr)), OP_EQ, 0);
  1098. tt_str_op(tor_addr_to_str(buf, addr, sizeof(buf), 0), OP_EQ, "::");
  1099. done:
  1100. tor_free(addr);
  1101. tor_free(zeros);
  1102. }
  1103. #define TEST_ADDR_INTERNAL(a, for_listening, rv) STMT_BEGIN \
  1104. tor_addr_t t; \
  1105. tt_int_op(tor_inet_pton(AF_INET, a, &t.addr.in_addr), OP_EQ, 1); \
  1106. t.family = AF_INET; \
  1107. tt_int_op(tor_addr_is_internal(&t, for_listening), OP_EQ, rv); \
  1108. STMT_END;
  1109. static void
  1110. test_addr_rfc6598(void *arg)
  1111. {
  1112. (void)arg;
  1113. TEST_ADDR_INTERNAL("100.64.0.1", 0, 1);
  1114. TEST_ADDR_INTERNAL("100.64.0.1", 1, 0);
  1115. done:
  1116. ;
  1117. }
  1118. #define ADDR_LEGACY(name) \
  1119. { #name, test_addr_ ## name , 0, NULL, NULL }
  1120. struct testcase_t addr_tests[] = {
  1121. ADDR_LEGACY(basic),
  1122. ADDR_LEGACY(ip6_helpers),
  1123. ADDR_LEGACY(parse),
  1124. { "virtaddr", test_virtaddrmap, 0, NULL, NULL },
  1125. { "virtaddr_persist", test_virtaddrmap_persist, TT_FORK, NULL, NULL },
  1126. { "localname", test_addr_localname, 0, NULL, NULL },
  1127. { "dup_ip", test_addr_dup_ip, 0, NULL, NULL },
  1128. { "sockaddr_to_str", test_addr_sockaddr_to_str, 0, NULL, NULL },
  1129. { "is_loopback", test_addr_is_loopback, 0, NULL, NULL },
  1130. { "make_null", test_addr_make_null, 0, NULL, NULL },
  1131. { "rfc6598", test_addr_rfc6598, 0, NULL, NULL },
  1132. END_OF_TESTCASES
  1133. };