test_relaycell.c 18 KB

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