tor  0.4.2.1-alpha-dev
Macros | Functions
onion.c File Reference
#include "core/or/or.h"
#include "app/config/config.h"
#include "core/crypto/onion_crypto.h"
#include "core/crypto/onion_fast.h"
#include "core/crypto/onion_ntor.h"
#include "core/crypto/onion_tap.h"
#include "core/or/onion.h"
#include "feature/nodelist/networkstatus.h"
#include "core/or/cell_st.h"
#include "trunnel/ed25519_cert.h"

Go to the source code of this file.

Macros

#define NTOR_CREATE_MAGIC   "ntorNTORntorNTOR"
 

Functions

static int check_create_cell (const create_cell_t *cell, int unknown_ok)
 
void create_cell_init (create_cell_t *cell_out, uint8_t cell_type, uint16_t handshake_type, uint16_t handshake_len, const uint8_t *onionskin)
 
static int parse_create2_payload (create_cell_t *cell_out, const uint8_t *p, size_t p_len)
 
int create_cell_parse (create_cell_t *cell_out, const cell_t *cell_in)
 
static int check_created_cell (const created_cell_t *cell)
 
int created_cell_parse (created_cell_t *cell_out, const cell_t *cell_in)
 
static int check_extend_cell (const extend_cell_t *cell)
 
static int extend_cell_from_extend1_cell_body (extend_cell_t *cell_out, const extend1_cell_body_t *cell)
 
static int create_cell_from_create2_cell_body (create_cell_t *cell_out, const create2_cell_body_t *cell)
 
static int extend_cell_from_extend2_cell_body (extend_cell_t *cell_out, const extend2_cell_body_t *cell)
 
int extend_cell_parse (extend_cell_t *cell_out, const uint8_t command, const uint8_t *payload, size_t payload_length)
 
static int check_extended_cell (const extended_cell_t *cell)
 
int extended_cell_parse (extended_cell_t *cell_out, const uint8_t command, const uint8_t *payload, size_t payload_len)
 
static int create_cell_format_impl (cell_t *cell_out, const create_cell_t *cell_in, int relayed)
 
int create_cell_format (cell_t *cell_out, const create_cell_t *cell_in)
 
int create_cell_format_relayed (cell_t *cell_out, const create_cell_t *cell_in)
 
int created_cell_format (cell_t *cell_out, const created_cell_t *cell_in)
 
static int should_include_ed25519_id_extend_cells (const networkstatus_t *ns, const or_options_t *options)
 
int extend_cell_format (uint8_t *command_out, uint16_t *len_out, uint8_t *payload_out, const extend_cell_t *cell_in)
 
int extended_cell_format (uint8_t *command_out, uint16_t *len_out, uint8_t *payload_out, const extended_cell_t *cell_in)
 

Detailed Description

Functions to queue create cells, and parse and create the CREATE cell and its allies.

This module has a few functions, all related to the CREATE/CREATED handshake that we use on links in order to create a circuit, and the related EXTEND/EXTENDED handshake that we use over circuits in order to extend them an additional hop.

Clients invoke these functions when creating or extending a circuit, from circuitbuild.c.

Relays invoke these functions when they receive a CREATE or EXTEND cell in command.c or relay.c, in order to queue the pending request. They also invoke them from cpuworker.c, which handles dispatching onionskin requests to different worker threads.


This module also handles:

Definition in file onion.c.

Macro Definition Documentation

◆ NTOR_CREATE_MAGIC

#define NTOR_CREATE_MAGIC   "ntorNTORntorNTOR"

Magic string which, in a CREATE or EXTEND cell, indicates that a seeming TAP payload is really an ntor payload. We'd do away with this if every relay supported EXTEND2, but we want to be able to extend from A to B with ntor even when A doesn't understand EXTEND2 and so can't generate a CREATE2 cell.

Definition at line 149 of file onion.c.

Function Documentation

◆ check_create_cell()

static int check_create_cell ( const create_cell_t cell,
int  unknown_ok 
)
static

Helper: return 0 if cell appears valid, -1 otherwise. If unknown_ok is true, allow cells with handshake types we don't recognize.

Definition at line 60 of file onion.c.

References create_cell_t::cell_type.

Referenced by create_cell_format_impl().

◆ check_created_cell()

static int check_created_cell ( const created_cell_t cell)
static

Helper: return 0 if cell appears valid, -1 otherwise.

Definition at line 185 of file onion.c.

References created_cell_t::cell_type.

Referenced by created_cell_format().

◆ check_extend_cell()

static int check_extend_cell ( const extend_cell_t cell)
static

Helper: return 0 if cell appears valid, -1 otherwise.

Definition at line 241 of file onion.c.

References create_cell_t::cell_type, extend_cell_t::create_cell, extend_cell_t::node_id, extend_cell_t::orport_ipv4, tor_addr_family(), and tor_digest_is_zero().

Referenced by extend_cell_format().

◆ check_extended_cell()

static int check_extended_cell ( const extended_cell_t cell)
static

Helper: return 0 if cell appears valid, -1 otherwise.

Definition at line 428 of file onion.c.

References created_cell_t::cell_type, extended_cell_t::created_cell, and tor_assert().

Referenced by extended_cell_format().

◆ create_cell_format_impl()

static int create_cell_format_impl ( cell_t cell_out,
const create_cell_t cell_in,
int  relayed 
)
static

Fill cell_out with a correctly formatted version of the CREATE{,_FAST,2} cell in cell_in. Return 0 on success, -1 on failure. This is a cell we didn't originate if relayed is true.

Definition at line 491 of file onion.c.

References create_cell_t::cell_type, check_create_cell(), cell_t::command, and cell_t::payload.

◆ create_cell_init()

void create_cell_init ( create_cell_t cell_out,
uint8_t  cell_type,
uint16_t  handshake_type,
uint16_t  handshake_len,
const uint8_t *  onionskin 
)

Write the various parameters into the create cell. Separate from create_cell_parse() to make unit testing easier.

Definition at line 103 of file onion.c.

References create_cell_t::cell_type, create_cell_t::handshake_len, create_cell_t::handshake_type, and create_cell_t::onionskin.

◆ create_cell_parse()

int create_cell_parse ( create_cell_t cell_out,
const cell_t cell_in 
)

Parse a CREATE, CREATE_FAST, or CREATE2 cell from cell_in into cell_out. Return 0 on success, -1 on failure. (We reject some syntactically valid CREATE2 cells that we can't generate or react to.)

Definition at line 155 of file onion.c.

References cell_t::command.

◆ created_cell_format()

int created_cell_format ( cell_t cell_out,
const created_cell_t cell_in 
)

Fill cell_out with a correctly formatted version of the CREATED{,_FAST,2} cell in cell_in. Return 0 on success, -1 on failure.

Definition at line 546 of file onion.c.

References created_cell_t::cell_type, check_created_cell(), cell_t::command, and cell_t::payload.

◆ created_cell_parse()

int created_cell_parse ( created_cell_t cell_out,
const cell_t cell_in 
)

Parse a CREATED, CREATED_FAST, or CREATED2 cell from cell_in into cell_out. Return 0 on success, -1 on failure.

Definition at line 209 of file onion.c.

References cell_t::command.

◆ extend_cell_format()

int extend_cell_format ( uint8_t *  command_out,
uint16_t *  len_out,
uint8_t *  payload_out,
const extend_cell_t cell_in 
)

Format the EXTEND{,2} cell in cell_in, storing its relay payload in payload_out, the number of bytes used in *len_out, and the relay command in *command_out. The payload_out must have RELAY_PAYLOAD_SIZE bytes available. Return 0 on success, -1 on failure.

Definition at line 591 of file onion.c.

References extend_cell_t::cell_type, check_extend_cell(), and RELAY_PAYLOAD_SIZE.

◆ extend_cell_parse()

int extend_cell_parse ( extend_cell_t cell_out,
const uint8_t  command,
const uint8_t *  payload,
size_t  payload_length 
)

Parse an EXTEND or EXTEND2 cell (according to command) from the payload_length bytes of payload into cell_out. Return 0 on success, -1 on failure.

Definition at line 378 of file onion.c.

References RELAY_PAYLOAD_SIZE, and tor_assert().

◆ extended_cell_format()

int extended_cell_format ( uint8_t *  command_out,
uint16_t *  len_out,
uint8_t *  payload_out,
const extended_cell_t cell_in 
)

Format the EXTENDED{,2} cell in cell_in, storing its relay payload in payload_out, the number of bytes used in *len_out, and the relay command in *command_out. The payload_out must have RELAY_PAYLOAD_SIZE bytes available. Return 0 on success, -1 on failure.

Definition at line 685 of file onion.c.

References extended_cell_t::cell_type, check_extended_cell(), and RELAY_PAYLOAD_SIZE.

◆ extended_cell_parse()

int extended_cell_parse ( extended_cell_t cell_out,
const uint8_t  command,
const uint8_t *  payload,
size_t  payload_len 
)

Parse an EXTENDED or EXTENDED2 cell (according to command) from the payload_length bytes of payload into cell_out. Return 0 on success, -1 on failure.

Definition at line 448 of file onion.c.

References RELAY_PAYLOAD_SIZE, and tor_assert().

◆ parse_create2_payload()

static int parse_create2_payload ( create_cell_t cell_out,
const uint8_t *  p,
size_t  p_len 
)
static

Helper: parse the CREATE2 payload at p, which could be up to p_len bytes long, and use it to fill the fields of cell_out. Return 0 on success and -1 on failure.

Note that part of the body of an EXTEND2 cell is a CREATE2 payload, so this function is also used for parsing those.

Definition at line 123 of file onion.c.

References CELL_PAYLOAD_SIZE, and get_uint16().

◆ should_include_ed25519_id_extend_cells()

static int should_include_ed25519_id_extend_cells ( const networkstatus_t ns,
const or_options_t options 
)
static

Return true iff we are configured (by torrc or by the networkstatus parameters) to use Ed25519 identities in our Extend2 cells.

Definition at line 574 of file onion.c.

References or_options_t::ExtendByEd25519ID.