tor
master
|
Header file for connection_edge.c. More...
#include "testsupport.h"
Go to the source code of this file.
Macros | |
#define | connection_mark_unattached_ap(conn, endreason) connection_mark_unattached_ap_((conn), (endreason), __LINE__, SHORT_FILE__) |
#define | connection_ap_mark_as_pending_circuit(c) connection_ap_mark_as_pending_circuit_((c), __FILE__, __LINE__) |
#define | CONNECTION_AP_EXPECT_NONPENDING(c) |
Begin-cell flags | |
These flags are used in RELAY_BEGIN cells to change the default behavior of the cell. | |
#define | BEGIN_FLAG_IPV6_OK (1u<<0) |
#define | BEGIN_FLAG_IPV4_NOT_OK (1u<<1) |
#define | BEGIN_FLAG_IPV6_PREFERRED (1u<<2) |
Typedefs | |
typedef enum hostname_type_t | hostname_type_t |
Enumerations | |
enum | hostname_type_t { NORMAL_HOSTNAME, ONION_V2_HOSTNAME, ONION_V3_HOSTNAME, EXIT_HOSTNAME, BAD_HOSTNAME } |
Header file for connection_edge.c.
#define BEGIN_FLAG_IPV4_NOT_OK (1u<<1) |
When this flag is set, the client DOES NOT support connecting to IPv4 addresses. (The sense of this flag is inverted from IPV6_OK, so that the old default behavior of Tor is equivalent to having all flags set to 0.)
#define BEGIN_FLAG_IPV6_OK (1u<<0) |
When this flag is set, the client is willing to get connected to IPv6 addresses
#define BEGIN_FLAG_IPV6_PREFERRED (1u<<2) |
When this flag is set, if we find both an IPv4 and an IPv6 address, we use the IPv6 address. Otherwise we use the IPv4 address.
#define CONNECTION_AP_EXPECT_NONPENDING | ( | c | ) |
typedef enum hostname_type_t hostname_type_t |
Possible return values for parse_extended_hostname.
enum hostname_type_t |
Possible return values for parse_extended_hostname.
int address_is_invalid_destination | ( | const char * | address, |
int | client | ||
) |
Return 1 if address has funny characters in it like colons. Return 0 if it's fine, or if we're configured to allow it anyway. client should be true if we're using this address as a client; false if we're using it as a server.
void circuit_clear_isolation | ( | origin_circuit_t * | circ | ) |
Clear the isolation settings on circ.
This only works on an open circuit that has never had a stream attached to it, and whose isolation settings are hypothetical. (We set hypothetical isolation settings on circuits as we're launching them, so that we know whether they can handle more streams or whether we need to launch even more circuits. Once the circuit is open, if it turns out that we no longer have any streams to attach to it, we clear the isolation flags and data so that other streams can have a chance.)
void circuit_discard_optional_exit_enclaves | ( | extend_info_t * | info | ) |
A circuit failed to finish on its last hop info. If there are any streams waiting with this exit node in mind, but they don't absolutely require it, make them give up on it.
void connection_ap_about_to_close | ( | entry_connection_t * | entry_conn | ) |
Called when we're about to finally unlink and free an AP (client) connection: perform necessary accounting and cleanup
void connection_ap_attach_pending | ( | int | retry | ) |
Tell any AP streams that are listed as waiting for a new circuit to try again. If there is an available circuit for a stream, attach it. Otherwise, launch a new circuit.
If retry is false, only check the list if it contains at least one streams that we have not yet tried to attach to a circuit.
int connection_ap_can_use_exit | ( | const entry_connection_t * | conn, |
const node_t * | exit_node | ||
) |
Return 1 if router exit_node is likely to allow stream conn to exit from it, or 0 if it probably will not allow it. (We might be uncertain if conn's destination address has not yet been resolved.)
int connection_ap_detach_retriable | ( | entry_connection_t * | conn, |
origin_circuit_t * | circ, | ||
int | reason | ||
) |
The AP connection conn has just failed while attaching or sending a BEGIN or resolving on circ, but another circuit might work. Detach the circuit, and either reattach it, launch a new circuit, tell the controller, or give up as appropriate.
Returns -1 on err, 1 on success, 0 on not-yet-sure.
void connection_ap_expire_beginning | ( | void | ) |
Find all general-purpose AP streams waiting for a response that sent their begin/resolve cell too long ago. Detach from their current circuit, and mark their current circuit as unsuitable for new streams. Then call connection_ap_handshake_attach_circuit() to attach to a new circuit (if available) or launch a new one.
For rendezvous streams, simply give up after SocksTimeout seconds (with no retry attempt).
void connection_ap_fail_onehop | ( | const char * | failed_digest, |
cpath_build_state_t * | build_state | ||
) |
Tell any AP streams that are waiting for a one-hop tunnel to failed_digest that they are going to fail.
int connection_ap_handshake_rewrite_and_attach | ( | entry_connection_t * | conn, |
origin_circuit_t * | circ, | ||
crypt_path_t * | cpath | ||
) |
Connection conn just finished its socks handshake, or the controller asked us to take care of it. If circ is defined, then that's where we'll want to attach it. Otherwise we have to figure it out ourselves.
First, parse whether it's a .exit address, remap it, and so on. Then if it's for a general circuit, try to attach it to a circuit (or launch one as needed), else if it's for a rendezvous circuit, fetch a rendezvous descriptor first (or attach/launch a circuit if the rendezvous descriptor is already here and fresh enough).
The stream will exit from the hop indicated by cpath, or from the last hop in circ's cpath if cpath is NULL.
int connection_ap_handshake_send_resolve | ( | entry_connection_t * | ap_conn | ) |
Write a relay resolve cell, using destaddr and destport from ap_conn's socks_request field, and send it down circ.
If ap_conn is broken, mark it for close and return -1. Else return 0.
void connection_ap_handshake_socks_reply | ( | entry_connection_t * | conn, |
char * | reply, | ||
size_t | replylen, | ||
int | endreason | ||
) |
Send a socks reply to stream conn, using the appropriate socks version, etc, and mark conn as completed with SOCKS handshaking.
If reply is defined, then write replylen bytes of it to conn and return, else reply based on endreason (one of END_STREAM_REASON_*). If reply is undefined, endreason can't be 0 or REASON_DONE. Send endreason to the controller, if appropriate.
void connection_ap_handshake_socks_resolved_addr | ( | entry_connection_t * | conn, |
const tor_addr_t * | answer, | ||
int | ttl, | ||
time_t | expires | ||
) |
As connection_ap_handshake_socks_resolved, but take a tor_addr_t to send as the answer.
entry_connection_t* connection_ap_make_link | ( | connection_t * | partner, |
char * | address, | ||
uint16_t | port, | ||
const char * | digest, | ||
int | session_group, | ||
int | isolation_flags, | ||
int | use_begindir, | ||
int | want_onehop | ||
) |
Make an AP connection_t linked to the connection_t partner. make a new linked connection pair, and attach one side to the conn, connection_add it, initialize it to circuit_wait, and call connection_ap_handshake_attach_circuit(conn) on it.
Return the newly created end of the linked connection pair, or -1 if error.
void connection_ap_mark_as_non_pending_circuit | ( | entry_connection_t * | entry_conn | ) |
Mark entry_conn as no longer waiting for a circuit.
void connection_ap_mark_as_pending_circuit_ | ( | entry_connection_t * | entry_conn, |
const char * | fname, | ||
int | lineno | ||
) |
Mark entry_conn as needing to get attached to a circuit.
And entry_conn must be in AP_CONN_STATE_CIRCUIT_WAIT, should not already be pending a circuit. The circuit will get launched or the connection will get attached the next time we call connection_ap_attach_pending().
int connection_ap_process_transparent | ( | entry_connection_t * | conn | ) |
connection_init_accepted_conn() found a new trans AP conn. Get the original destination and send it to connection_ap_handshake_rewrite_and_attach().
Return -1 if an unexpected error with conn (and it should be marked for close), else return 0.
void connection_ap_rescan_and_attach_pending | ( | void | ) |
As connection_ap_attach_pending, but first scans the entire connection array to see if any elements are missing.
int connection_edge_compatible_with_circuit | ( | const entry_connection_t * | conn, |
const origin_circuit_t * | circ | ||
) |
Return true iff none of the isolation flags and fields in conn should prevent it from being attached to circ.
int connection_edge_destroy | ( | circid_t | circ_id, |
edge_connection_t * | conn | ||
) |
This edge needs to be closed, because its circuit has closed. Mark it for close and return 0.
int connection_edge_end | ( | edge_connection_t * | conn, |
uint8_t | reason | ||
) |
Send a relay end cell from stream conn down conn's circuit, and remember that we've done so. If this is not a client connection, set the relay end cell's reason for closing as reason.
Return -1 if this function has already been called on this conn, else return 0.
int connection_edge_end_errno | ( | edge_connection_t * | conn | ) |
An error has just occurred on an operation on an edge connection conn. Extract the errno; convert it to an end reason, and send an appropriate relay end cell to the other end of the connection's circuit.
int connection_edge_finished_connecting | ( | edge_connection_t * | edge_conn | ) |
Connected handler for exit connections: start writing pending data, deliver 'CONNECTED' relay cells as appropriate, and check any pending data that may have been received.
int connection_edge_finished_flushing | ( | edge_connection_t * | conn | ) |
Connection conn has finished writing and has no bytes left on its outbuf.
If it's in state 'open', stop writing, consider responding with a sendme, and return. Otherwise, stop writing and return.
If conn is broken, mark it for close and return -1, else return 0.
int connection_edge_flushed_some | ( | edge_connection_t * | conn | ) |
We just wrote some data to conn; act appropriately.
(That is, if it's open, consider sending a stream-level sendme cell if we have just flushed enough.)
void connection_edge_free_all | ( | void | ) |
Free all storage held in module-scoped variables for connection_edge.c
int connection_edge_is_rendezvous_stream | ( | const edge_connection_t * | conn | ) |
Return 1 if conn is a rendezvous stream, or 0 if it is a general stream.
int connection_edge_process_inbuf | ( | edge_connection_t * | conn, |
int | package_partial | ||
) |
Handle new bytes on conn->inbuf based on state:
Mark and return -1 if there was an unexpected error with the conn, else return 0.
int connection_edge_reached_eof | ( | edge_connection_t * | conn | ) |
There was an EOF. Send an end and mark the connection for close.
int connection_edge_update_circuit_isolation | ( | const entry_connection_t * | conn, |
origin_circuit_t * | circ, | ||
int | dry_run | ||
) |
If dry_run is false, update circ's isolation flags and fields to reflect having had conn attached to it, and return 0. Otherwise, if dry_run is true, then make no changes to circ, and return a bitfield of isolation flags that we would have to set in isolation_flags_mixed to add conn to circ, or -1 if circ has had no streams attached to it.
void connection_exit_about_to_close | ( | edge_connection_t * | edge_conn | ) |
Called when we're about to finally unlink and free an exit connection: perform necessary accounting and cleanup
A relay 'begin' or 'begin_dir' cell has arrived, and either we are an exit hop for the circuit, or we are the origin and it is a rendezvous begin.
Launch a new exit connection and initialize things appropriately.
If it's a rendezvous stream, call connection_exit_connect() on it.
For general streams, call dns_resolve() on it first, and only call connection_exit_connect() if the dns answer is already known.
Note that we don't call connection_add() on the new stream! We wait for connection_exit_connect() to do that.
Return -(some circuit end reason) if we want to tear down circ. Else return 0.
int connection_exit_begin_resolve | ( | cell_t * | cell, |
or_circuit_t * | circ | ||
) |
Called when we receive a RELAY_COMMAND_RESOLVE cell 'cell' along the circuit circ; begin resolving the hostname, and (eventually) reply with a RESOLVED cell.
void connection_exit_connect | ( | edge_connection_t * | edge_conn | ) |
Connect to conn's specified addr and port. If it worked, conn has now been added to the connection_array.
Send back a connected cell. Include the resolved IP of the destination address, but only if it's a general exit stream. (Rendezvous streams must not reveal what IP they connected to.)
streamid_t get_unique_stream_id_by_circ | ( | origin_circuit_t * | circ | ) |
Iterate over the two bytes of stream_id until we get one that is not already in use; return it. Return 0 if can't get a unique stream_id.
hostname_type_t parse_extended_hostname | ( | char * | address | ) |
If address is of the form "y.onion" with a well-formed handle y: Put a NUL after y, lower-case it, and return ONION_V2_HOSTNAME or ONION_V3_HOSTNAME depending on the HS version.
If address is of the form "x.y.onion" with a well-formed handle x: Drop "x.", put a NUL after y, lower-case it, and return ONION_V2_HOSTNAME or ONION_V3_HOSTNAME depending on the HS version.
If address is of the form "y.onion" with a badly-formed handle y: Return BAD_HOSTNAME and log a message.
If address is of the form "y.exit": Put a NUL after y and return EXIT_HOSTNAME.
Otherwise: Return NORMAL_HOSTNAME and change nothing.