31 #include "core/or/or_circuit_st.h"
55 circuit_extend_state_valid_helper(
const struct circuit_t *circ)
58 circuitbuild_warn_client_extend();
68 "n_chan already set. Bug/attack. Closing.");
74 "conn to next hop already launched. Bug/attack. Closing.");
107 "Client asked me to extend without specifying an id_digest.");
184 bool log_zero_addrs,
bool log_internal_addrs,
191 if (!tor_addr_port_is_valid_ap(ap, 0)) {
192 if (log_zero_addrs) {
194 "Client asked me to extend to a zero destination port or "
201 if (tor_addr_is_internal(&ap->addr, 0) &&
203 if (log_internal_addrs) {
205 "Client asked me to extend to a private %s address '%s'.",
224 circuit_extend_lspec_valid_helper(
const struct extend_cell_t *ec,
236 const int ipv4_valid = circuit_extend_addr_port_is_valid(&ec->
orport_ipv4,
238 const int ipv6_valid = circuit_extend_addr_port_is_valid(&ec->
orport_ipv6,
241 if (!ipv4_valid && !ipv6_valid) {
243 circuit_extend_addr_port_is_valid(&ec->
orport_ipv4,
244 true,
true, LOG_PROTOCOL_WARN);
245 circuit_extend_addr_port_is_valid(&ec->
orport_ipv6,
246 true,
true, LOG_PROTOCOL_WARN);
249 }
else if (!ipv4_valid) {
252 circuit_extend_addr_port_is_valid(&ec->
orport_ipv4,
253 false,
true, LOG_PROTOCOL_WARN);
254 }
else if (!ipv6_valid) {
255 circuit_extend_addr_port_is_valid(&ec->
orport_ipv6,
256 false,
true, LOG_PROTOCOL_WARN);
274 "Client asked me to extend back to the previous hop.");
282 "Client asked me to extend back to the previous hop "
304 if (!ipv6_supported) {
328 #define IPV6_CONNECTION_ONE_IN_N 2
331 IPV6_CONNECTION_ONE_IN_N);
350 circuit_open_connection_for_extend(
const struct extend_cell_t *ec,
362 circuit_mark_for_close(circ, END_CIRC_REASON_CONNECTFAILED);
367 const int ipv4_valid = circuit_extend_addr_port_is_valid(&ec->
orport_ipv4,
369 const int ipv6_valid = circuit_extend_addr_port_is_valid(&ec->
orport_ipv6,
374 circuit_mark_for_close(circ, END_CIRC_REASON_CONNECTFAILED);
384 "Received IPv6-only extend, but we don't have an IPv6 ORPort.");
385 circuit_mark_for_close(circ, END_CIRC_REASON_CONNECTFAILED);
406 log_info(
LD_CIRC,
"Launching n_chan failed. Closing circuit.");
407 circuit_mark_for_close(circ, END_CIRC_REASON_CONNECTFAILED);
410 log_debug(
LD_CIRC,
"connecting in progress (or finished). Good.");
428 const char *msg = NULL;
429 int should_launch = 0;
439 if (circuit_extend_state_valid_helper(circ) < 0)
448 "Can't parse extend cell. Closing circuit.");
452 if (circuit_extend_add_ed25519_helper(&ec) < 0)
455 if (circuit_extend_lspec_valid_helper(&ec, circ) < 0)
458 if (circuit_extend_add_ipv4_helper(&ec) < 0)
461 if (circuit_extend_add_ipv6_helper(&ec) < 0)
465 const int ipv4_valid = circuit_extend_addr_port_is_valid(&ec.
orport_ipv4,
467 const int ipv6_valid = circuit_extend_addr_port_is_valid(&ec.
orport_ipv6,
491 circuit_open_connection_for_extend(&ec, circ, should_launch);
536 const char *keys,
size_t keys_len,
537 const uint8_t *rend_circ_nonce)
557 tor_assert(keys_len == CPATH_KEY_MATERIAL_LEN);
560 log_warn(
LD_BUG,
"couldn't format created cell (type=%d, len=%d).",
568 log_debug(
LD_CIRC,
"init digest forward 0x%.8x, backward 0x%.8x.",
572 log_warn(
LD_BUG,
"Circuit initialization failed.");
578 int used_create_fast = (created_cell->
cell_type == CELL_CREATED_FAST);
582 log_debug(
LD_CIRC,
"Finished sending '%s' cell.",
583 used_create_fast ?
"created_fast" :
"created");
void tor_addr_copy(tor_addr_t *dest, const tor_addr_t *src)
int tor_addr_is_null(const tor_addr_t *addr)
const char * fmt_addr_family(const tor_addr_t *addr)
#define fmt_and_decorate_addr(a)
static sa_family_t tor_addr_family(const tor_addr_t *a)
static uint32_t get_uint32(const void *cp)
Fixed-size cell structure.
int channel_is_outgoing(channel_t *chan)
int channel_is_local(channel_t *chan)
int channel_get_addr_if_possible(const channel_t *chan, tor_addr_t *addr_out)
const char * channel_describe_peer(channel_t *chan)
channel_t * channel_get_for_extend(const char *rsa_id_digest, const ed25519_public_key_t *ed_id, const tor_addr_t *target_ipv4_addr, const tor_addr_t *target_ipv6_addr, bool for_origin_circ, const char **msg_out, int *launch_out)
Header file for channel.c.
int circuit_deliver_create_cell(circuit_t *circ, const struct create_cell_t *create_cell, int relayed)
channel_t * channel_connect_for_circuit(const extend_info_t *ei)
Header file for circuitbuild.c.
int circuit_extend(struct cell_t *cell, struct circuit_t *circ)
int onionskin_answer(struct or_circuit_t *circ, const created_cell_t *created_cell, const char *keys, size_t keys_len, const uint8_t *rend_circ_nonce)
Header for feature/relay/circuitbuild_relay.c.
void circuit_set_state(circuit_t *circ, uint8_t state)
Header file for circuitlist.c.
#define CIRCUIT_STATE_OPEN
#define CIRCUIT_STATE_CHAN_WAIT
const or_options_t * get_options(void)
Header file for config.c.
void ed25519_pubkey_copy(ed25519_public_key_t *dest, const ed25519_public_key_t *src)
int ed25519_public_key_is_zero(const ed25519_public_key_t *pubkey)
int ed25519_pubkey_eq(const ed25519_public_key_t *key1, const ed25519_public_key_t *key2)
Common functions for using (pseudo-)random number generators.
#define crypto_fast_rng_one_in_n(rng, n)
crypto_fast_rng_t * get_thread_fast_rng(void)
int tor_memeq(const void *a, const void *b, size_t sz)
extend_info_t * extend_info_new(const char *nickname, const char *rsa_id_digest, const ed25519_public_key_t *ed_id, crypto_pk_t *onion_key, const curve25519_public_key_t *ntor_key, const tor_addr_t *addr, uint16_t port)
Header for core/or/extendinfo.c.
#define log_fn(severity, domain, args,...)
void node_get_prim_orport(const node_t *node, tor_addr_port_t *ap_out)
bool node_supports_ed25519_link_authentication(const node_t *node, bool compatible_with_us)
const node_t * node_get_by_id(const char *identity_digest)
const ed25519_public_key_t * node_get_ed25519_id(const node_t *node)
void node_get_pref_ipv6_orport(const node_t *node, tor_addr_port_t *ap_out)
Header file for nodelist.c.
int extend_cell_parse(extend_cell_t *cell_out, const uint8_t command, const uint8_t *payload, size_t payload_length)
int created_cell_format(cell_t *cell_out, const created_cell_t *cell_in)
Master header file for Tor-specific functionality.
#define RELAY_HEADER_SIZE
void append_cell_to_circuit_queue(circuit_t *circ, channel_t *chan, cell_t *cell, cell_direction_t direction, streamid_t fromstream)
void relay_header_unpack(relay_header_t *dest, const uint8_t *src)
Header for relay_crypto.c.
int relay_crypto_init(relay_crypto_t *crypto, const char *key_data, size_t key_data_len, int reverse, int is_hs_v3)
bool router_addr_is_my_published_addr(const tor_addr_t *addr)
bool router_can_extend_over_ipv6(const or_options_t *options)
Header file for router.c.
int server_mode(const or_options_t *options)
Header file for routermode.c.
void router_orport_found_reachable(int family)
Header file for selftest.c.
uint8_t payload[CELL_PAYLOAD_SIZE]
char identity_digest[DIGEST_LEN]
tor_addr_t addr_according_to_peer
struct ed25519_public_key_t ed25519_identity
struct create_cell_t * n_chan_create_cell
tor_addr_port_t orport_ipv4
create_cell_t create_cell
struct ed25519_public_key_t ed_pubkey
uint8_t node_id[DIGEST_LEN]
tor_addr_port_t orport_ipv6
char rend_circ_nonce[DIGEST_LEN]
#define IF_BUG_ONCE(cond)
int tor_digest_is_zero(const char *digest)