command.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566
  1. /* Copyright (c) 2001 Matej Pfajfar.
  2. * Copyright (c) 2001-2004, Roger Dingledine.
  3. * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
  4. * Copyright (c) 2007-2008, The Tor Project, Inc. */
  5. /* See LICENSE for licensing information */
  6. /* $Id$ */
  7. const char command_c_id[] =
  8. "$Id$";
  9. /**
  10. * \file command.c
  11. * \brief Functions for processing incoming cells.
  12. **/
  13. /* In-points to command.c:
  14. *
  15. * - command_process_cell(), called from
  16. * connection_or_process_cells_from_inbuf() in connection_or.c
  17. */
  18. #include "or.h"
  19. /** Keep statistics about how many of each type of cell we've received. */
  20. uint64_t stats_n_padding_cells_processed = 0;
  21. uint64_t stats_n_create_cells_processed = 0;
  22. uint64_t stats_n_created_cells_processed = 0;
  23. uint64_t stats_n_relay_cells_processed = 0;
  24. uint64_t stats_n_destroy_cells_processed = 0;
  25. uint64_t stats_n_versions_cells_processed = 0;
  26. uint64_t stats_n_netinfo_cells_processed = 0;
  27. uint64_t stats_n_cert_cells_processed = 0;
  28. uint64_t stats_n_link_auth_cells_processed = 0;
  29. /* These are the main functions for processing cells */
  30. static void command_process_create_cell(cell_t *cell, or_connection_t *conn);
  31. static void command_process_created_cell(cell_t *cell, or_connection_t *conn);
  32. static void command_process_relay_cell(cell_t *cell, or_connection_t *conn);
  33. static void command_process_destroy_cell(cell_t *cell, or_connection_t *conn);
  34. static void command_process_versions_cell(var_cell_t *cell,
  35. or_connection_t *conn);
  36. static void command_process_netinfo_cell(cell_t *cell, or_connection_t *conn);
  37. #ifdef KEEP_TIMING_STATS
  38. /** This is a wrapper function around the actual function that processes the
  39. * <b>cell</b> that just arrived on <b>conn</b>. Increment <b>*time</b>
  40. * by the number of microseconds used by the call to <b>*func(cell, conn)</b>.
  41. */
  42. static void
  43. command_time_process_cell(cell_t *cell, or_connection_t *conn, int *time,
  44. void (*func)(cell_t *, or_connection_t *))
  45. {
  46. struct timeval start, end;
  47. long time_passed;
  48. tor_gettimeofday(&start);
  49. (*func)(cell, conn);
  50. tor_gettimeofday(&end);
  51. time_passed = tv_udiff(&start, &end) ;
  52. if (time_passed > 10000) { /* more than 10ms */
  53. log_debug(LD_OR,"That call just took %ld ms.",time_passed/1000);
  54. }
  55. if (time_passed < 0) {
  56. log_info(LD_GENERAL,"That call took us back in time!");
  57. time_passed = 0;
  58. }
  59. *time += time_passed;
  60. }
  61. #endif
  62. /** Process a <b>cell</b> that was just received on <b>conn</b>. Keep internal
  63. * statistics about how many of each cell we've processed so far
  64. * this second, and the total number of microseconds it took to
  65. * process each type of cell.
  66. */
  67. void
  68. command_process_cell(cell_t *cell, or_connection_t *conn)
  69. {
  70. int handshaking = (conn->_base.state == OR_CONN_STATE_OR_HANDSHAKING);
  71. #ifdef KEEP_TIMING_STATS
  72. /* how many of each cell have we seen so far this second? needs better
  73. * name. */
  74. static int num_create=0, num_created=0, num_relay=0, num_destroy=0;
  75. /* how long has it taken to process each type of cell? */
  76. static int create_time=0, created_time=0, relay_time=0, destroy_time=0;
  77. static time_t current_second = 0; /* from previous calls to time */
  78. time_t now = time(NULL);
  79. if (now > current_second) { /* the second has rolled over */
  80. /* print stats */
  81. log_info(LD_OR,
  82. "At end of second: %d creates (%d ms), %d createds (%d ms), "
  83. "%d relays (%d ms), %d destroys (%d ms)",
  84. num_create, create_time/1000,
  85. num_created, created_time/1000,
  86. num_relay, relay_time/1000,
  87. num_destroy, destroy_time/1000);
  88. /* zero out stats */
  89. num_create = num_created = num_relay = num_destroy = 0;
  90. create_time = created_time = relay_time = destroy_time = 0;
  91. /* remember which second it is, for next time */
  92. current_second = now;
  93. }
  94. #endif
  95. #ifdef KEEP_TIMING_STATS
  96. #define PROCESS_CELL(tp, cl, cn) STMT_BEGIN { \
  97. ++num ## tp; \
  98. command_time_process_cell(cl, cn, & tp ## time , \
  99. command_process_ ## tp ## _cell); \
  100. } STMT_END
  101. #else
  102. #define PROCESS_CELL(tp, cl, cn) command_process_ ## tp ## _cell(cl, cn)
  103. #endif
  104. /* Reject all but VERSIONS when handshaking. */
  105. if (handshaking && cell->command != CELL_VERSIONS)
  106. return;
  107. switch (cell->command) {
  108. case CELL_PADDING:
  109. ++stats_n_padding_cells_processed;
  110. /* do nothing */
  111. break;
  112. case CELL_CREATE:
  113. case CELL_CREATE_FAST:
  114. ++stats_n_create_cells_processed;
  115. PROCESS_CELL(create, cell, conn);
  116. break;
  117. case CELL_CREATED:
  118. case CELL_CREATED_FAST:
  119. ++stats_n_created_cells_processed;
  120. PROCESS_CELL(created, cell, conn);
  121. break;
  122. case CELL_RELAY:
  123. case CELL_RELAY_EARLY:
  124. ++stats_n_relay_cells_processed;
  125. PROCESS_CELL(relay, cell, conn);
  126. break;
  127. case CELL_DESTROY:
  128. ++stats_n_destroy_cells_processed;
  129. PROCESS_CELL(destroy, cell, conn);
  130. break;
  131. case CELL_VERSIONS:
  132. tor_fragile_assert();
  133. break;
  134. case CELL_NETINFO:
  135. ++stats_n_netinfo_cells_processed;
  136. PROCESS_CELL(netinfo, cell, conn);
  137. break;
  138. default:
  139. log_fn(LOG_INFO, LD_PROTOCOL,
  140. "Cell of unknown type (%d) received. Dropping.", cell->command);
  141. break;
  142. }
  143. }
  144. /** Process a <b>cell</b> that was just received on <b>conn</b>. Keep internal
  145. * statistics about how many of each cell we've processed so far
  146. * this second, and the total number of microseconds it took to
  147. * process each type of cell.
  148. */
  149. void
  150. command_process_var_cell(var_cell_t *cell, or_connection_t *conn)
  151. {
  152. #ifdef KEEP_TIMING_STATS
  153. /* how many of each cell have we seen so far this second? needs better
  154. * name. */
  155. static int num_versions=0, num_cert=0;
  156. time_t now = time(NULL);
  157. if (now > current_second) { /* the second has rolled over */
  158. /* print stats */
  159. log_info(LD_OR,
  160. "At end of second: %d versions (%d ms), %d cert (%d ms)",
  161. num_versions, versions_time/1000,
  162. cert, cert_time/1000);
  163. num_versions = num_cert = 0;
  164. versions_time = cert_time = 0;
  165. /* remember which second it is, for next time */
  166. current_second = now;
  167. }
  168. #endif
  169. /* reject all when not handshaking. */
  170. if (conn->_base.state != OR_CONN_STATE_OR_HANDSHAKING)
  171. return;
  172. switch (cell->command) {
  173. case CELL_VERSIONS:
  174. ++stats_n_versions_cells_processed;
  175. PROCESS_CELL(versions, cell, conn);
  176. break;
  177. default:
  178. log_warn(LD_BUG,
  179. "Variable-length cell of unknown type (%d) received.",
  180. cell->command);
  181. tor_fragile_assert();
  182. break;
  183. }
  184. }
  185. /** Process a 'create' <b>cell</b> that just arrived from <b>conn</b>. Make a
  186. * new circuit with the p_circ_id specified in cell. Put the circuit in state
  187. * onionskin_pending, and pass the onionskin to the cpuworker. Circ will get
  188. * picked up again when the cpuworker finishes decrypting it.
  189. */
  190. static void
  191. command_process_create_cell(cell_t *cell, or_connection_t *conn)
  192. {
  193. or_circuit_t *circ;
  194. int id_is_high;
  195. if (we_are_hibernating()) {
  196. log_info(LD_OR,
  197. "Received create cell but we're shutting down. Sending back "
  198. "destroy.");
  199. connection_or_send_destroy(cell->circ_id, conn,
  200. END_CIRC_REASON_HIBERNATING);
  201. return;
  202. }
  203. if (!server_mode(get_options())) {
  204. log_fn(LOG_PROTOCOL_WARN, LD_PROTOCOL,
  205. "Received create cell (type %d) from %s:%d, but we're a client. "
  206. "Sending back a destroy.",
  207. (int)cell->command, conn->_base.address, conn->_base.port);
  208. connection_or_send_destroy(cell->circ_id, conn,
  209. END_CIRC_REASON_TORPROTOCOL);
  210. return;
  211. }
  212. /* If the high bit of the circuit ID is not as expected, close the
  213. * circ. */
  214. id_is_high = cell->circ_id & (1<<15);
  215. if ((id_is_high && conn->circ_id_type == CIRC_ID_TYPE_HIGHER) ||
  216. (!id_is_high && conn->circ_id_type == CIRC_ID_TYPE_LOWER)) {
  217. log_fn(LOG_PROTOCOL_WARN, LD_PROTOCOL,
  218. "Received create cell with unexpected circ_id %d. Closing.",
  219. cell->circ_id);
  220. connection_or_send_destroy(cell->circ_id, conn,
  221. END_CIRC_REASON_TORPROTOCOL);
  222. return;
  223. }
  224. if (circuit_get_by_circid_orconn(cell->circ_id, conn)) {
  225. routerinfo_t *router = router_get_by_digest(conn->identity_digest);
  226. log_fn(LOG_PROTOCOL_WARN, LD_PROTOCOL,
  227. "Received CREATE cell (circID %d) for known circ. "
  228. "Dropping (age %d).",
  229. cell->circ_id, (int)(time(NULL) - conn->_base.timestamp_created));
  230. if (router)
  231. log_fn(LOG_PROTOCOL_WARN, LD_PROTOCOL,
  232. "Details: nickname \"%s\", platform %s.",
  233. router->nickname, escaped(router->platform));
  234. return;
  235. }
  236. circ = or_circuit_new(cell->circ_id, conn);
  237. circ->_base.purpose = CIRCUIT_PURPOSE_OR;
  238. circuit_set_state(TO_CIRCUIT(circ), CIRCUIT_STATE_ONIONSKIN_PENDING);
  239. if (cell->command == CELL_CREATE) {
  240. char *onionskin = tor_malloc(ONIONSKIN_CHALLENGE_LEN);
  241. memcpy(onionskin, cell->payload, ONIONSKIN_CHALLENGE_LEN);
  242. /* hand it off to the cpuworkers, and then return. */
  243. if (assign_onionskin_to_cpuworker(NULL, circ, onionskin) < 0) {
  244. log_warn(LD_GENERAL,"Failed to hand off onionskin. Closing.");
  245. circuit_mark_for_close(TO_CIRCUIT(circ), END_CIRC_REASON_INTERNAL);
  246. return;
  247. }
  248. log_debug(LD_OR,"success: handed off onionskin.");
  249. } else {
  250. /* This is a CREATE_FAST cell; we can handle it immediately without using
  251. * a CPU worker. */
  252. char keys[CPATH_KEY_MATERIAL_LEN];
  253. char reply[DIGEST_LEN*2];
  254. tor_assert(cell->command == CELL_CREATE_FAST);
  255. if (fast_server_handshake(cell->payload, reply, keys, sizeof(keys))<0) {
  256. log_warn(LD_OR,"Failed to generate key material. Closing.");
  257. circuit_mark_for_close(TO_CIRCUIT(circ), END_CIRC_REASON_INTERNAL);
  258. return;
  259. }
  260. if (onionskin_answer(circ, CELL_CREATED_FAST, reply, keys)<0) {
  261. log_warn(LD_OR,"Failed to reply to CREATE_FAST cell. Closing.");
  262. circuit_mark_for_close(TO_CIRCUIT(circ), END_CIRC_REASON_INTERNAL);
  263. return;
  264. }
  265. }
  266. }
  267. /** Process a 'created' <b>cell</b> that just arrived from <b>conn</b>.
  268. * Find the circuit
  269. * that it's intended for. If we're not the origin of the circuit, package
  270. * the 'created' cell in an 'extended' relay cell and pass it back. If we
  271. * are the origin of the circuit, send it to circuit_finish_handshake() to
  272. * finish processing keys, and then call circuit_send_next_onion_skin() to
  273. * extend to the next hop in the circuit if necessary.
  274. */
  275. static void
  276. command_process_created_cell(cell_t *cell, or_connection_t *conn)
  277. {
  278. circuit_t *circ;
  279. circ = circuit_get_by_circid_orconn(cell->circ_id, conn);
  280. if (!circ) {
  281. log_info(LD_OR,
  282. "(circID %d) unknown circ (probably got a destroy earlier). "
  283. "Dropping.", cell->circ_id);
  284. return;
  285. }
  286. if (circ->n_circ_id != cell->circ_id) {
  287. log_fn(LOG_PROTOCOL_WARN,LD_PROTOCOL,
  288. "got created cell from Tor client? Closing.");
  289. circuit_mark_for_close(circ, END_CIRC_REASON_TORPROTOCOL);
  290. return;
  291. }
  292. if (CIRCUIT_IS_ORIGIN(circ)) { /* we're the OP. Handshake this. */
  293. origin_circuit_t *origin_circ = TO_ORIGIN_CIRCUIT(circ);
  294. int err_reason = 0;
  295. log_debug(LD_OR,"at OP. Finishing handshake.");
  296. if ((err_reason = circuit_finish_handshake(origin_circ, cell->command,
  297. cell->payload)) < 0) {
  298. log_warn(LD_OR,"circuit_finish_handshake failed.");
  299. circuit_mark_for_close(circ, -err_reason);
  300. return;
  301. }
  302. log_debug(LD_OR,"Moving to next skin.");
  303. if ((err_reason = circuit_send_next_onion_skin(origin_circ)) < 0) {
  304. log_info(LD_OR,"circuit_send_next_onion_skin failed.");
  305. /* XXX push this circuit_close lower */
  306. circuit_mark_for_close(circ, -err_reason);
  307. return;
  308. }
  309. } else { /* pack it into an extended relay cell, and send it. */
  310. log_debug(LD_OR,
  311. "Converting created cell to extended relay cell, sending.");
  312. relay_send_command_from_edge(0, circ, RELAY_COMMAND_EXTENDED,
  313. cell->payload, ONIONSKIN_REPLY_LEN,
  314. NULL);
  315. }
  316. }
  317. /** Process a 'relay' <b>cell</b> that just arrived from <b>conn</b>. Make sure
  318. * it came in with a recognized circ_id. Pass it on to
  319. * circuit_receive_relay_cell() for actual processing.
  320. */
  321. static void
  322. command_process_relay_cell(cell_t *cell, or_connection_t *conn)
  323. {
  324. circuit_t *circ;
  325. int reason, direction;
  326. circ = circuit_get_by_circid_orconn(cell->circ_id, conn);
  327. if (!circ) {
  328. log_debug(LD_OR,
  329. "unknown circuit %d on connection from %s:%d. Dropping.",
  330. cell->circ_id, conn->_base.address, conn->_base.port);
  331. return;
  332. }
  333. if (circ->state == CIRCUIT_STATE_ONIONSKIN_PENDING) {
  334. log_fn(LOG_PROTOCOL_WARN,LD_PROTOCOL,"circuit in create_wait. Closing.");
  335. circuit_mark_for_close(circ, END_CIRC_REASON_TORPROTOCOL);
  336. return;
  337. }
  338. if (CIRCUIT_IS_ORIGIN(circ)) {
  339. /* if we're a relay and treating connections with recent local
  340. * traffic better, then this is one of them. */
  341. conn->client_used = time(NULL);
  342. }
  343. if (!CIRCUIT_IS_ORIGIN(circ) &&
  344. cell->circ_id == TO_OR_CIRCUIT(circ)->p_circ_id)
  345. direction = CELL_DIRECTION_OUT;
  346. else
  347. direction = CELL_DIRECTION_IN;
  348. if ((reason = circuit_receive_relay_cell(cell, circ, direction)) < 0) {
  349. log_fn(LOG_PROTOCOL_WARN,LD_PROTOCOL,"circuit_receive_relay_cell "
  350. "(%s) failed. Closing.",
  351. direction==CELL_DIRECTION_OUT?"forward":"backward");
  352. circuit_mark_for_close(circ, -reason);
  353. }
  354. }
  355. /** Process a 'destroy' <b>cell</b> that just arrived from
  356. * <b>conn</b>. Find the circ that it refers to (if any).
  357. *
  358. * If the circ is in state
  359. * onionskin_pending, then call onion_pending_remove() to remove it
  360. * from the pending onion list (note that if it's already being
  361. * processed by the cpuworker, it won't be in the list anymore; but
  362. * when the cpuworker returns it, the circuit will be gone, and the
  363. * cpuworker response will be dropped).
  364. *
  365. * Then mark the circuit for close (which marks all edges for close,
  366. * and passes the destroy cell onward if necessary).
  367. */
  368. static void
  369. command_process_destroy_cell(cell_t *cell, or_connection_t *conn)
  370. {
  371. circuit_t *circ;
  372. int reason;
  373. circ = circuit_get_by_circid_orconn(cell->circ_id, conn);
  374. reason = (uint8_t)cell->payload[0];
  375. if (!circ) {
  376. log_info(LD_OR,"unknown circuit %d on connection from %s:%d. Dropping.",
  377. cell->circ_id, conn->_base.address, conn->_base.port);
  378. return;
  379. }
  380. log_debug(LD_OR,"Received for circID %d.",cell->circ_id);
  381. if (!CIRCUIT_IS_ORIGIN(circ) &&
  382. cell->circ_id == TO_OR_CIRCUIT(circ)->p_circ_id) {
  383. /* the destroy came from behind */
  384. circuit_set_p_circid_orconn(TO_OR_CIRCUIT(circ), 0, NULL);
  385. circuit_mark_for_close(circ, reason|END_CIRC_REASON_FLAG_REMOTE);
  386. } else { /* the destroy came from ahead */
  387. circuit_set_n_circid_orconn(circ, 0, NULL);
  388. if (CIRCUIT_IS_ORIGIN(circ)) {
  389. circuit_mark_for_close(circ, reason|END_CIRC_REASON_FLAG_REMOTE);
  390. } else {
  391. char payload[1];
  392. log_debug(LD_OR, "Delivering 'truncated' back.");
  393. payload[0] = (char)reason;
  394. relay_send_command_from_edge(0, circ, RELAY_COMMAND_TRUNCATED,
  395. payload, sizeof(payload), NULL);
  396. }
  397. }
  398. }
  399. /** Process a 'versions' cell. The current link protocol version must be 0
  400. * to indicate that no version has yet been negotiated. DOCDOC say more. */
  401. static void
  402. command_process_versions_cell(var_cell_t *cell, or_connection_t *conn)
  403. {
  404. int highest_supported_version = 0;
  405. const char *cp, *end;
  406. if (conn->link_proto != 0 ||
  407. conn->_base.state != OR_CONN_STATE_OR_HANDSHAKING ||
  408. (conn->handshake_state && conn->handshake_state->received_versions)) {
  409. log_fn(LOG_PROTOCOL_WARN, LD_OR,
  410. "Received a VERSIONS cell on a connection with its version "
  411. "already set to %d; dropping", (int) conn->link_proto);
  412. return;
  413. }
  414. tor_assert(conn->handshake_state);
  415. end = cell->payload + cell->payload_len;
  416. for (cp = cell->payload; cp+1 < end; ++cp) {
  417. uint16_t v = ntohs(get_uint16(cp));
  418. if (is_or_protocol_version_known(v) && v > highest_supported_version)
  419. highest_supported_version = v;
  420. }
  421. if (!highest_supported_version) {
  422. log_fn(LOG_PROTOCOL_WARN, LD_OR,
  423. "Couldn't find a version in common between my version list and the "
  424. "list in the VERSIONS cell; closing connection.");
  425. connection_mark_for_close(TO_CONN(conn));
  426. return;
  427. }
  428. conn->link_proto = highest_supported_version;
  429. conn->handshake_state->received_versions = 1;
  430. // log_notice(LD_OR, "Negotiated version %d", highest_supported_version);
  431. if (highest_supported_version >= 2) {
  432. if (connection_or_send_netinfo(conn) < 0) {
  433. connection_mark_for_close(TO_CONN(conn));
  434. return;
  435. }
  436. } else {
  437. /* Should be impossible. */
  438. tor_fragile_assert();
  439. }
  440. }
  441. /** Process a 'netinfo' cell. DOCDOC say more. */
  442. static void
  443. command_process_netinfo_cell(cell_t *cell, or_connection_t *conn)
  444. {
  445. time_t timestamp;
  446. uint8_t my_addr_type;
  447. uint8_t my_addr_len;
  448. const char *my_addr_ptr;
  449. const char *cp, *end;
  450. uint8_t n_other_addrs;
  451. time_t now = time(NULL);
  452. if (conn->link_proto < 2) {
  453. log_fn(LOG_PROTOCOL_WARN, LD_OR,
  454. "Received a NETINFO cell on %s connection; dropping.",
  455. conn->link_proto == 0 ? "non-versioned" : "a v1");
  456. return;
  457. }
  458. if (conn->_base.state != OR_CONN_STATE_OR_HANDSHAKING) {
  459. log_fn(LOG_PROTOCOL_WARN, LD_OR,
  460. "Received a NETINFO cell on a non-handshaking; dropping.");
  461. return;
  462. }
  463. tor_assert(conn->handshake_state &&
  464. conn->handshake_state->received_versions);
  465. if (conn->handshake_state->received_netinfo) {
  466. log_fn(LOG_PROTOCOL_WARN, LD_OR,
  467. "Received a duplicate NETINFO cell; dropping.");
  468. return;
  469. }
  470. /* Decode the cell. */
  471. timestamp = ntohl(get_uint32(cell->payload));
  472. if (abs(now - conn->handshake_state->sent_versions_at) < 180) {
  473. conn->handshake_state->apparent_skew = now - timestamp;
  474. }
  475. my_addr_type = (uint8_t) cell->payload[4];
  476. my_addr_len = (uint8_t) cell->payload[5];
  477. my_addr_ptr = cell->payload + 6;
  478. end = cell->payload + CELL_PAYLOAD_SIZE;
  479. cp = cell->payload + 6 + my_addr_len;
  480. if (cp >= end) {
  481. log_fn(LOG_PROTOCOL_WARN, LD_OR,
  482. "Addresses too long in netinfo cell; closing connection.");
  483. connection_mark_for_close(TO_CONN(conn));
  484. return;
  485. } else if (my_addr_type == RESOLVED_TYPE_IPV4 && my_addr_len == 4) {
  486. conn->handshake_state->my_apparent_addr = ntohl(get_uint32(my_addr_ptr));
  487. }
  488. n_other_addrs = (uint8_t) *cp++;
  489. while (n_other_addrs && cp < end-2) {
  490. /* Consider all the other addresses; if any matches, this connection is
  491. * "canonical." */
  492. uint8_t other_addr_type = (uint8_t) *cp++;
  493. uint8_t other_addr_len = (uint8_t) *cp++;
  494. if (cp + other_addr_len >= end) {
  495. log_fn(LOG_PROTOCOL_WARN, LD_OR,
  496. "Address too long in netinfo cell; closing connection.");
  497. connection_mark_for_close(TO_CONN(conn));
  498. return;
  499. }
  500. if (other_addr_type == RESOLVED_TYPE_IPV4 && other_addr_len == 4) {
  501. uint32_t addr = ntohl(get_uint32(cp));
  502. if (addr == conn->real_addr) {
  503. conn->handshake_state->apparently_canonical = 1;
  504. break;
  505. }
  506. }
  507. cp += other_addr_len;
  508. --n_other_addrs;
  509. }
  510. conn->handshake_state->received_netinfo = 1;
  511. }