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-2021, The Tor Project, Inc. */
5 /* See LICENSE for licensing information */
6 
7 /**
8  * @file circuitbuild_relay.h
9  * @brief Header for feature/relay/circuitbuild_relay.c
10  **/
11 
12 #ifndef TOR_FEATURE_RELAY_CIRCUITBUILD_RELAY_H
13 #define TOR_FEATURE_RELAY_CIRCUITBUILD_RELAY_H
14 
15 #include "lib/cc/torint.h"
16 #include "lib/log/log.h"
17 
18 #include "app/config/config.h"
19 
20 struct cell_t;
21 struct created_cell_t;
22 
23 struct circuit_t;
24 struct or_circuit_t;
25 struct extend_cell_t;
26 
27 /* Log a protocol warning about getting an extend cell on a client. */
28 static inline void
circuitbuild_warn_client_extend(void)29 circuitbuild_warn_client_extend(void)
30 {
31   log_fn(LOG_PROTOCOL_WARN, LD_PROTOCOL,
32          "Got an extend cell, but running as a client. Closing.");
33 }
34 
35 #ifdef HAVE_MODULE_RELAY
36 
37 int circuit_extend(struct cell_t *cell, struct circuit_t *circ);
38 
39 int onionskin_answer(struct or_circuit_t *circ,
40                      const struct created_cell_t *created_cell,
41                      const char *keys, size_t keys_len,
42                      const uint8_t *rend_circ_nonce);
43 
44 #else /* !defined(HAVE_MODULE_RELAY) */
45 
46 static inline int
circuit_extend(struct cell_t * cell,struct circuit_t * circ)47 circuit_extend(struct cell_t *cell, struct circuit_t *circ)
48 {
49   (void)cell;
50   (void)circ;
51   circuitbuild_warn_client_extend();
52   return -1;
53 }
54 
55 static inline int
onionskin_answer(struct or_circuit_t * circ,const struct created_cell_t * created_cell,const char * keys,size_t keys_len,const uint8_t * rend_circ_nonce)56 onionskin_answer(struct or_circuit_t *circ,
57                  const struct created_cell_t *created_cell,
58                  const char *keys, size_t keys_len,
59                  const uint8_t *rend_circ_nonce)
60 {
61   (void)circ;
62   (void)created_cell;
63   (void)keys;
64   (void)keys_len;
65   (void)rend_circ_nonce;
66   tor_assert_nonfatal_unreached();
67   return -1;
68 }
69 
70 #endif /* defined(HAVE_MODULE_RELAY) */
71 
72 #ifdef TOR_UNIT_TESTS
73 
74 STATIC int circuit_extend_state_valid_helper(const struct circuit_t *circ);
75 STATIC int circuit_extend_add_ed25519_helper(struct extend_cell_t *ec);
76 STATIC int circuit_extend_add_ipv4_helper(struct extend_cell_t *ec);
77 STATIC int circuit_extend_add_ipv6_helper(struct extend_cell_t *ec);
78 STATIC int circuit_extend_lspec_valid_helper(const struct extend_cell_t *ec,
79                                              const struct circuit_t *circ);
80 STATIC const tor_addr_port_t * circuit_choose_ip_ap_for_extend(
81                                              const tor_addr_port_t *ipv4_ap,
82                                              const tor_addr_port_t *ipv6_ap);
83 STATIC void circuit_open_connection_for_extend(const struct extend_cell_t *ec,
84                                                struct circuit_t *circ,
85                                                int should_launch);
86 
87 #endif /* defined(TOR_UNIT_TESTS) */
88 
89 #endif /* !defined(TOR_FEATURE_RELAY_CIRCUITBUILD_RELAY_H) */
90