test_relaycell.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495
  1. /* Copyright (c) 2014-2017, The Tor Project, Inc. */
  2. /* See LICENSE for licensing information */
  3. /* Unit tests for handling different kinds of relay cell */
  4. #define RELAY_PRIVATE
  5. #define CIRCUITLIST_PRIVATE
  6. #include "or.h"
  7. #include "main.h"
  8. #include "config.h"
  9. #include "connection.h"
  10. #include "crypto.h"
  11. #include "circuitbuild.h"
  12. #include "circuitlist.h"
  13. #include "connection_edge.h"
  14. #include "relay.h"
  15. #include "test.h"
  16. static int srm_ncalls;
  17. static entry_connection_t *srm_conn;
  18. static int srm_atype;
  19. static size_t srm_alen;
  20. static int srm_answer_is_set;
  21. static uint8_t srm_answer[512];
  22. static int srm_ttl;
  23. static time_t srm_expires;
  24. void connection_free_minimal(connection_t*);
  25. int connected_cell_format_payload(uint8_t *payload_out,
  26. const tor_addr_t *addr,
  27. uint32_t ttl);
  28. /* Mock replacement for connection_ap_hannshake_socks_resolved() */
  29. static void
  30. socks_resolved_mock(entry_connection_t *conn,
  31. int answer_type,
  32. size_t answer_len,
  33. const uint8_t *answer,
  34. int ttl,
  35. time_t expires)
  36. {
  37. srm_ncalls++;
  38. srm_conn = conn;
  39. srm_atype = answer_type;
  40. srm_alen = answer_len;
  41. if (answer) {
  42. memset(srm_answer, 0, sizeof(srm_answer));
  43. memcpy(srm_answer, answer, answer_len < 512 ? answer_len : 512);
  44. srm_answer_is_set = 1;
  45. } else {
  46. srm_answer_is_set = 0;
  47. }
  48. srm_ttl = ttl;
  49. srm_expires = expires;
  50. }
  51. static int mum_ncalls;
  52. static entry_connection_t *mum_conn;
  53. static int mum_endreason;
  54. /* Mock replacement for connection_mark_unattached_ap_() */
  55. static void
  56. mark_unattached_mock(entry_connection_t *conn, int endreason,
  57. int line, const char *file)
  58. {
  59. ++mum_ncalls;
  60. mum_conn = conn;
  61. mum_endreason = endreason;
  62. (void) line;
  63. (void) file;
  64. }
  65. /* Helper: Return a newly allocated and initialized origin circuit with
  66. * purpose and flags. A default HS identifier is set to an ed25519
  67. * authentication key for introduction point. */
  68. static origin_circuit_t *
  69. helper_create_origin_circuit(int purpose, int flags)
  70. {
  71. origin_circuit_t *circ = NULL;
  72. circ = origin_circuit_init(purpose, flags);
  73. tor_assert(circ);
  74. circ->cpath = tor_malloc_zero(sizeof(crypt_path_t));
  75. circ->cpath->magic = CRYPT_PATH_MAGIC;
  76. circ->cpath->state = CPATH_STATE_OPEN;
  77. circ->cpath->package_window = circuit_initial_package_window();
  78. circ->cpath->deliver_window = CIRCWINDOW_START;
  79. circ->cpath->prev = circ->cpath;
  80. /* Create a default HS identifier. */
  81. circ->hs_ident = tor_malloc_zero(sizeof(hs_ident_circuit_t));
  82. return circ;
  83. }
  84. static void
  85. mock_connection_mark_unattached_ap_(entry_connection_t *conn, int endreason,
  86. int line, const char *file)
  87. {
  88. (void) line;
  89. (void) file;
  90. conn->edge_.end_reason = endreason;
  91. }
  92. static void
  93. mock_mark_for_close(connection_t *conn,
  94. int line, const char *file)
  95. {
  96. (void)line;
  97. (void)file;
  98. conn->marked_for_close = 1;
  99. return;
  100. }
  101. static void
  102. mock_start_reading(connection_t *conn)
  103. {
  104. (void)conn;
  105. return;
  106. }
  107. static void
  108. test_circbw_relay(void *arg)
  109. {
  110. cell_t cell;
  111. relay_header_t rh;
  112. tor_addr_t addr;
  113. edge_connection_t *edgeconn;
  114. entry_connection_t *entryconn;
  115. origin_circuit_t *circ;
  116. int delivered = 0;
  117. int overhead = 0;
  118. (void)arg;
  119. #define PACK_CELL(id, cmd, body_s) do { \
  120. memset(&cell, 0, sizeof(cell)); \
  121. memset(&rh, 0, sizeof(rh)); \
  122. memcpy(cell.payload+RELAY_HEADER_SIZE, (body_s), sizeof((body_s))-1); \
  123. rh.length = sizeof((body_s))-1; \
  124. rh.command = (cmd); \
  125. rh.stream_id = (id); \
  126. relay_header_pack((uint8_t*)&cell.payload, &rh); \
  127. } while (0)
  128. #define ASSERT_COUNTED_BW() do { \
  129. tt_int_op(circ->n_delivered_read_circ_bw, OP_EQ, delivered+rh.length); \
  130. tt_int_op(circ->n_overhead_read_circ_bw, OP_EQ, \
  131. overhead+RELAY_PAYLOAD_SIZE-rh.length); \
  132. delivered = circ->n_delivered_read_circ_bw; \
  133. overhead = circ->n_overhead_read_circ_bw; \
  134. } while (0)
  135. #define ASSERT_UNCOUNTED_BW() do { \
  136. tt_int_op(circ->n_delivered_read_circ_bw, OP_EQ, delivered); \
  137. tt_int_op(circ->n_overhead_read_circ_bw, OP_EQ, overhead); \
  138. } while (0)
  139. MOCK(connection_mark_unattached_ap_, mock_connection_mark_unattached_ap_);
  140. MOCK(connection_start_reading, mock_start_reading);
  141. MOCK(connection_mark_for_close_internal_, mock_mark_for_close);
  142. entryconn = entry_connection_new(CONN_TYPE_AP, AF_INET);
  143. edgeconn = ENTRY_TO_EDGE_CONN(entryconn);
  144. edgeconn->base_.state = AP_CONN_STATE_CONNECT_WAIT;
  145. edgeconn->deliver_window = 1000;
  146. circ = helper_create_origin_circuit(CIRCUIT_PURPOSE_C_GENERAL, 0);
  147. edgeconn->cpath_layer = circ->cpath;
  148. circ->cpath->state = CPATH_STATE_AWAITING_KEYS;
  149. circ->cpath->deliver_window = 1000;
  150. /* Stream id 0: Not counted */
  151. PACK_CELL(0, RELAY_COMMAND_END, "Data1234");
  152. connection_edge_process_relay_cell(&cell, TO_CIRCUIT(circ), edgeconn,
  153. circ->cpath);
  154. ASSERT_UNCOUNTED_BW();
  155. /* Stream id 1: Counted */
  156. PACK_CELL(1, RELAY_COMMAND_END, "Data1234");
  157. connection_edge_process_relay_cell(&cell, TO_CIRCUIT(circ), edgeconn,
  158. circ->cpath);
  159. ASSERT_COUNTED_BW();
  160. /* Properly formatted connect cell: counted */
  161. PACK_CELL(1, RELAY_COMMAND_CONNECTED, "Data1234");
  162. tor_addr_parse(&addr, "30.40.50.60");
  163. rh.length = connected_cell_format_payload(cell.payload+RELAY_HEADER_SIZE,
  164. &addr, 1024);
  165. relay_header_pack((uint8_t*)&cell.payload, &rh); \
  166. connection_edge_process_relay_cell(&cell, TO_CIRCUIT(circ), edgeconn,
  167. circ->cpath);
  168. ASSERT_COUNTED_BW();
  169. /* Properly formatted resolved cell in correct state: counted */
  170. edgeconn->base_.state = AP_CONN_STATE_RESOLVE_WAIT;
  171. entryconn->socks_request->command = SOCKS_COMMAND_RESOLVE;
  172. edgeconn->on_circuit = TO_CIRCUIT(circ);
  173. PACK_CELL(1, RELAY_COMMAND_RESOLVED,
  174. "\x04\x04\x12\x00\x00\x01\x00\x00\x02\x00");
  175. connection_edge_process_relay_cell(&cell, TO_CIRCUIT(circ), edgeconn,
  176. circ->cpath);
  177. ASSERT_COUNTED_BW();
  178. edgeconn->base_.state = AP_CONN_STATE_OPEN;
  179. entryconn->socks_request->has_finished = 1;
  180. /* Connected cell after open: not counted */
  181. PACK_CELL(1, RELAY_COMMAND_CONNECTED, "Data1234");
  182. connection_edge_process_relay_cell(&cell, TO_CIRCUIT(circ), edgeconn,
  183. circ->cpath);
  184. ASSERT_UNCOUNTED_BW();
  185. /* Resolved cell after open: not counted */
  186. PACK_CELL(1, RELAY_COMMAND_RESOLVED, "Data1234");
  187. connection_edge_process_relay_cell(&cell, TO_CIRCUIT(circ), edgeconn,
  188. circ->cpath);
  189. ASSERT_UNCOUNTED_BW();
  190. /* Drop cell: not counted */
  191. PACK_CELL(1, RELAY_COMMAND_DROP, "Data1234");
  192. connection_edge_process_relay_cell(&cell, TO_CIRCUIT(circ), edgeconn,
  193. circ->cpath);
  194. ASSERT_UNCOUNTED_BW();
  195. /* Data cell on stream 0: not counted */
  196. PACK_CELL(0, RELAY_COMMAND_DATA, "Data1234");
  197. connection_edge_process_relay_cell(&cell, TO_CIRCUIT(circ), edgeconn,
  198. circ->cpath);
  199. ASSERT_UNCOUNTED_BW();
  200. /* Data cell on open connection: counted */
  201. ENTRY_TO_CONN(entryconn)->marked_for_close = 0;
  202. PACK_CELL(1, RELAY_COMMAND_DATA, "Data1234");
  203. connection_edge_process_relay_cell(&cell, TO_CIRCUIT(circ), edgeconn,
  204. circ->cpath);
  205. ASSERT_COUNTED_BW();
  206. /* Empty Data cell on open connection: not counted */
  207. ENTRY_TO_CONN(entryconn)->marked_for_close = 0;
  208. PACK_CELL(1, RELAY_COMMAND_DATA, "");
  209. connection_edge_process_relay_cell(&cell, TO_CIRCUIT(circ), edgeconn,
  210. circ->cpath);
  211. ASSERT_UNCOUNTED_BW();
  212. /* Sendme on stream: not counted */
  213. ENTRY_TO_CONN(entryconn)->outbuf_flushlen = 0;
  214. PACK_CELL(1, RELAY_COMMAND_SENDME, "Data1234");
  215. connection_edge_process_relay_cell(&cell, TO_CIRCUIT(circ), edgeconn,
  216. circ->cpath);
  217. ASSERT_UNCOUNTED_BW();
  218. /* Sendme on circuit with full window: not counted */
  219. PACK_CELL(0, RELAY_COMMAND_SENDME, "Data1234");
  220. connection_edge_process_relay_cell(&cell, TO_CIRCUIT(circ), edgeconn,
  221. circ->cpath);
  222. ASSERT_UNCOUNTED_BW();
  223. /* Sendme on circuit with non-full window: counted */
  224. PACK_CELL(0, RELAY_COMMAND_SENDME, "Data1234");
  225. circ->cpath->package_window = 900;
  226. connection_edge_process_relay_cell(&cell, TO_CIRCUIT(circ), edgeconn,
  227. circ->cpath);
  228. ASSERT_COUNTED_BW();
  229. /* End cell on non-closed connection: counted */
  230. PACK_CELL(1, RELAY_COMMAND_END, "Data1234");
  231. connection_edge_process_relay_cell(&cell, TO_CIRCUIT(circ), edgeconn,
  232. circ->cpath);
  233. ASSERT_COUNTED_BW();
  234. /* End cell on connection that already got one: not counted */
  235. PACK_CELL(1, RELAY_COMMAND_END, "Data1234");
  236. connection_edge_process_relay_cell(&cell, TO_CIRCUIT(circ), NULL,
  237. circ->cpath);
  238. ASSERT_UNCOUNTED_BW();
  239. /* Invalid extended cell: not counted */
  240. PACK_CELL(1, RELAY_COMMAND_EXTENDED2, "Data1234");
  241. connection_edge_process_relay_cell(&cell, TO_CIRCUIT(circ), NULL,
  242. circ->cpath);
  243. ASSERT_UNCOUNTED_BW();
  244. /* Invalid extended cell: not counted */
  245. PACK_CELL(1, RELAY_COMMAND_EXTENDED, "Data1234");
  246. connection_edge_process_relay_cell(&cell, TO_CIRCUIT(circ), NULL,
  247. circ->cpath);
  248. ASSERT_UNCOUNTED_BW();
  249. /* Invalid HS cell: not counted */
  250. PACK_CELL(1, RELAY_COMMAND_ESTABLISH_INTRO, "Data1234");
  251. connection_edge_process_relay_cell(&cell, TO_CIRCUIT(circ), NULL,
  252. circ->cpath);
  253. ASSERT_UNCOUNTED_BW();
  254. /* "Valid" HS cell in expected state: counted */
  255. TO_CIRCUIT(circ)->purpose = CIRCUIT_PURPOSE_C_ESTABLISH_REND;
  256. PACK_CELL(1, RELAY_COMMAND_RENDEZVOUS_ESTABLISHED, "Data1234");
  257. connection_edge_process_relay_cell(&cell, TO_CIRCUIT(circ), NULL,
  258. circ->cpath);
  259. ASSERT_COUNTED_BW();
  260. done:
  261. UNMOCK(connection_start_reading);
  262. UNMOCK(connection_mark_unattached_ap_);
  263. UNMOCK(connection_mark_for_close_internal_);
  264. circuit_free_(TO_CIRCUIT(circ));
  265. connection_free_minimal(ENTRY_TO_CONN(entryconn));
  266. }
  267. /* Tests for connection_edge_process_resolved_cell().
  268. The point of ..process_resolved_cell() is to handle an incoming cell
  269. on an entry connection, and call connection_mark_unattached_ap() and/or
  270. connection_ap_handshake_socks_resolved().
  271. */
  272. static void
  273. test_relaycell_resolved(void *arg)
  274. {
  275. entry_connection_t *entryconn;
  276. edge_connection_t *edgeconn;
  277. cell_t cell;
  278. relay_header_t rh;
  279. int r;
  280. or_options_t *options = get_options_mutable();
  281. #define SET_CELL(s) do { \
  282. memset(&cell, 0, sizeof(cell)); \
  283. memset(&rh, 0, sizeof(rh)); \
  284. memcpy(cell.payload + RELAY_HEADER_SIZE, (s), sizeof((s))-1); \
  285. rh.length = sizeof((s))-1; \
  286. rh.command = RELAY_COMMAND_RESOLVED; \
  287. } while (0)
  288. #define MOCK_RESET() do { \
  289. srm_ncalls = mum_ncalls = 0; \
  290. } while (0)
  291. #define ASSERT_MARK_CALLED(reason) do { \
  292. tt_int_op(mum_ncalls, OP_EQ, 1); \
  293. tt_ptr_op(mum_conn, OP_EQ, entryconn); \
  294. tt_int_op(mum_endreason, OP_EQ, (reason)); \
  295. } while (0)
  296. #define ASSERT_RESOLVED_CALLED(atype, answer, ttl, expires) do { \
  297. tt_int_op(srm_ncalls, OP_EQ, 1); \
  298. tt_ptr_op(srm_conn, OP_EQ, entryconn); \
  299. tt_int_op(srm_atype, OP_EQ, (atype)); \
  300. if ((answer) != NULL) { \
  301. tt_int_op(srm_alen, OP_EQ, sizeof(answer)-1); \
  302. tt_int_op(srm_alen, OP_LT, 512); \
  303. tt_int_op(srm_answer_is_set, OP_EQ, 1); \
  304. tt_mem_op(srm_answer, OP_EQ, answer, sizeof(answer)-1); \
  305. } else { \
  306. tt_int_op(srm_answer_is_set, OP_EQ, 0); \
  307. } \
  308. tt_int_op(srm_ttl, OP_EQ, ttl); \
  309. tt_i64_op(srm_expires, OP_EQ, expires); \
  310. } while (0)
  311. (void)arg;
  312. MOCK(connection_mark_unattached_ap_, mark_unattached_mock);
  313. MOCK(connection_ap_handshake_socks_resolved, socks_resolved_mock);
  314. options->ClientDNSRejectInternalAddresses = 0;
  315. SET_CELL(/* IPv4: 127.0.1.2, ttl 256 */
  316. "\x04\x04\x7f\x00\x01\x02\x00\x00\x01\x00"
  317. /* IPv4: 18.0.0.1, ttl 512 */
  318. "\x04\x04\x12\x00\x00\x01\x00\x00\x02\x00"
  319. /* IPv6: 2003::3, ttl 1024 */
  320. "\x06\x10"
  321. "\x20\x02\x00\x00\x00\x00\x00\x00"
  322. "\x00\x00\x00\x00\x00\x00\x00\x03"
  323. "\x00\x00\x04\x00");
  324. entryconn = entry_connection_new(CONN_TYPE_AP, AF_INET);
  325. edgeconn = ENTRY_TO_EDGE_CONN(entryconn);
  326. /* Try with connection in non-RESOLVE_WAIT state: cell gets ignored */
  327. MOCK_RESET();
  328. r = connection_edge_process_resolved_cell(edgeconn, &cell, &rh);
  329. tt_int_op(r, OP_EQ, 0);
  330. tt_int_op(srm_ncalls, OP_EQ, 0);
  331. tt_int_op(mum_ncalls, OP_EQ, 0);
  332. /* Now put it in the right state. */
  333. ENTRY_TO_CONN(entryconn)->state = AP_CONN_STATE_RESOLVE_WAIT;
  334. entryconn->socks_request->command = SOCKS_COMMAND_RESOLVE;
  335. entryconn->entry_cfg.ipv4_traffic = 1;
  336. entryconn->entry_cfg.ipv6_traffic = 1;
  337. entryconn->entry_cfg.prefer_ipv6 = 0;
  338. /* We prefer ipv4, so we should get the first ipv4 answer */
  339. MOCK_RESET();
  340. r = connection_edge_process_resolved_cell(edgeconn, &cell, &rh);
  341. tt_int_op(r, OP_EQ, 0);
  342. ASSERT_MARK_CALLED(END_STREAM_REASON_DONE|
  343. END_STREAM_REASON_FLAG_ALREADY_SOCKS_REPLIED);
  344. ASSERT_RESOLVED_CALLED(RESOLVED_TYPE_IPV4, "\x7f\x00\x01\x02", 256, -1);
  345. /* But we may be discarding private answers. */
  346. MOCK_RESET();
  347. options->ClientDNSRejectInternalAddresses = 1;
  348. r = connection_edge_process_resolved_cell(edgeconn, &cell, &rh);
  349. tt_int_op(r, OP_EQ, 0);
  350. ASSERT_MARK_CALLED(END_STREAM_REASON_DONE|
  351. END_STREAM_REASON_FLAG_ALREADY_SOCKS_REPLIED);
  352. ASSERT_RESOLVED_CALLED(RESOLVED_TYPE_IPV4, "\x12\x00\x00\x01", 512, -1);
  353. /* now prefer ipv6, and get the first ipv6 answer */
  354. entryconn->entry_cfg.prefer_ipv6 = 1;
  355. MOCK_RESET();
  356. r = connection_edge_process_resolved_cell(edgeconn, &cell, &rh);
  357. tt_int_op(r, OP_EQ, 0);
  358. ASSERT_MARK_CALLED(END_STREAM_REASON_DONE|
  359. END_STREAM_REASON_FLAG_ALREADY_SOCKS_REPLIED);
  360. ASSERT_RESOLVED_CALLED(RESOLVED_TYPE_IPV6,
  361. "\x20\x02\x00\x00\x00\x00\x00\x00"
  362. "\x00\x00\x00\x00\x00\x00\x00\x03",
  363. 1024, -1);
  364. /* With a cell that only has IPv4, we report IPv4 even if we prefer IPv6 */
  365. MOCK_RESET();
  366. SET_CELL("\x04\x04\x12\x00\x00\x01\x00\x00\x02\x00");
  367. r = connection_edge_process_resolved_cell(edgeconn, &cell, &rh);
  368. tt_int_op(r, OP_EQ, 0);
  369. ASSERT_MARK_CALLED(END_STREAM_REASON_DONE|
  370. END_STREAM_REASON_FLAG_ALREADY_SOCKS_REPLIED);
  371. ASSERT_RESOLVED_CALLED(RESOLVED_TYPE_IPV4, "\x12\x00\x00\x01", 512, -1);
  372. /* But if we don't allow IPv4, we report nothing if the cell contains only
  373. * ipv4 */
  374. MOCK_RESET();
  375. entryconn->entry_cfg.ipv4_traffic = 0;
  376. r = connection_edge_process_resolved_cell(edgeconn, &cell, &rh);
  377. tt_int_op(r, OP_EQ, 0);
  378. ASSERT_MARK_CALLED(END_STREAM_REASON_DONE|
  379. END_STREAM_REASON_FLAG_ALREADY_SOCKS_REPLIED);
  380. ASSERT_RESOLVED_CALLED(RESOLVED_TYPE_ERROR, NULL, -1, -1);
  381. /* If we wanted hostnames, we report nothing, since we only had IPs. */
  382. MOCK_RESET();
  383. entryconn->entry_cfg.ipv4_traffic = 1;
  384. entryconn->socks_request->command = SOCKS_COMMAND_RESOLVE_PTR;
  385. r = connection_edge_process_resolved_cell(edgeconn, &cell, &rh);
  386. tt_int_op(r, OP_EQ, 0);
  387. ASSERT_MARK_CALLED(END_STREAM_REASON_DONE|
  388. END_STREAM_REASON_FLAG_ALREADY_SOCKS_REPLIED);
  389. ASSERT_RESOLVED_CALLED(RESOLVED_TYPE_ERROR, NULL, -1, -1);
  390. /* A hostname cell is fine though. */
  391. MOCK_RESET();
  392. SET_CELL("\x00\x0fwww.example.com\x00\x01\x00\x00");
  393. r = connection_edge_process_resolved_cell(edgeconn, &cell, &rh);
  394. tt_int_op(r, OP_EQ, 0);
  395. ASSERT_MARK_CALLED(END_STREAM_REASON_DONE|
  396. END_STREAM_REASON_FLAG_ALREADY_SOCKS_REPLIED);
  397. ASSERT_RESOLVED_CALLED(RESOLVED_TYPE_HOSTNAME, "www.example.com", 65536, -1);
  398. /* error on malformed cell */
  399. MOCK_RESET();
  400. entryconn->socks_request->command = SOCKS_COMMAND_RESOLVE;
  401. SET_CELL("\x04\x04\x01\x02\x03\x04"); /* no ttl */
  402. r = connection_edge_process_resolved_cell(edgeconn, &cell, &rh);
  403. tt_int_op(r, OP_EQ, 0);
  404. ASSERT_MARK_CALLED(END_STREAM_REASON_TORPROTOCOL);
  405. tt_int_op(srm_ncalls, OP_EQ, 0);
  406. /* error on all addresses private */
  407. MOCK_RESET();
  408. SET_CELL(/* IPv4: 127.0.1.2, ttl 256 */
  409. "\x04\x04\x7f\x00\x01\x02\x00\x00\x01\x00"
  410. /* IPv4: 192.168.1.1, ttl 256 */
  411. "\x04\x04\xc0\xa8\x01\x01\x00\x00\x01\x00");
  412. r = connection_edge_process_resolved_cell(edgeconn, &cell, &rh);
  413. tt_int_op(r, OP_EQ, 0);
  414. ASSERT_MARK_CALLED(END_STREAM_REASON_TORPROTOCOL);
  415. ASSERT_RESOLVED_CALLED(RESOLVED_TYPE_ERROR_TRANSIENT, NULL, 0, TIME_MAX);
  416. /* Legit error code */
  417. MOCK_RESET();
  418. SET_CELL("\xf0\x15" "quiet and meaningless" "\x00\x00\x0f\xff");
  419. r = connection_edge_process_resolved_cell(edgeconn, &cell, &rh);
  420. tt_int_op(r, OP_EQ, 0);
  421. ASSERT_MARK_CALLED(END_STREAM_REASON_DONE|
  422. END_STREAM_REASON_FLAG_ALREADY_SOCKS_REPLIED);
  423. ASSERT_RESOLVED_CALLED(RESOLVED_TYPE_ERROR_TRANSIENT, NULL, -1, -1);
  424. done:
  425. UNMOCK(connection_mark_unattached_ap_);
  426. UNMOCK(connection_ap_handshake_socks_resolved);
  427. }
  428. struct testcase_t relaycell_tests[] = {
  429. { "resolved", test_relaycell_resolved, TT_FORK, NULL, NULL },
  430. { "circbw", test_circbw_relay, TT_FORK, NULL, NULL },
  431. END_OF_TESTCASES
  432. };