Tor  0.4.7.0-alpha-dev
protover.h
Go to the documentation of this file.
1 /* Copyright (c) 2016-2021, The Tor Project, Inc. */
2 /* See LICENSE for licensing information */
3 
4 /**
5  * \file protover.h
6  * \brief Headers and type declarations for protover.c
7  **/
8 
9 #ifndef TOR_PROTOVER_H
10 #define TOR_PROTOVER_H
11 
12 #include <stdbool.h>
13 #include "lib/cc/torint.h"
15 struct smartlist_t;
16 
17 /** The first version of Tor that included "proto" entries in its
18  * descriptors. Authorities should use this to decide whether to
19  * guess proto lines. */
20 /* This is a guess. */
21 /// C_RUST_COUPLED: src/rust/protover/protover.rs
22 /// `FIRST_TOR_VERSION_TO_ADVERTISE_PROTOCOLS`
23 #define FIRST_TOR_VERSION_TO_ADVERTISE_PROTOCOLS "0.2.9.3-alpha"
24 
25 /** The protover version number that signifies ed25519 link handshake support
26  */
27 #define PROTOVER_LINKAUTH_ED25519_HANDSHAKE 3
28 
29 /** The protover version number that signifies extend2 cell support */
30 #define PROTOVER_RELAY_EXTEND2 2
31 /** The protover version number where relays can accept IPv6 connections */
32 #define PROTOVER_RELAY_ACCEPT_IPV6 2
33 /** The protover version number where relays can initiate IPv6 extends */
34 #define PROTOVER_RELAY_EXTEND_IPV6 3
35 /** The protover version number where relays can consider IPv6 connections
36  * canonical */
37 #define PROTOVER_RELAY_CANONICAL_IPV6 3
38 
39 /** The protover version number that signifies HSv3 intro point support */
40 #define PROTOVER_HS_INTRO_V3 4
41 /** The protover version number where intro points support denial of service
42  * resistance */
43 #define PROTOVER_HS_INTRO_DOS 5
44 
45 /** The protover version number that signifies HSv3 rendezvous point support */
46 #define PROTOVER_HS_RENDEZVOUS_POINT_V3 2
47 
48 /** The protover version number that signifies HSDir support for HSv3 */
49 #define PROTOVER_HSDIR_V3 2
50 
51 /** The protover that signals support for HS circuit setup padding machines */
52 #define PROTOVER_HS_SETUP_PADDING 2
53 
54 /** List of recognized subprotocols. */
55 /// C_RUST_COUPLED: src/rust/protover/ffi.rs `translate_to_rust`
56 /// C_RUST_COUPLED: src/rust/protover/protover.rs `Proto`
57 typedef enum protocol_type_t {
58  PRT_LINK = 0,
59  PRT_LINKAUTH = 1,
60  PRT_RELAY = 2,
61  PRT_DIRCACHE = 3,
62  PRT_HSDIR = 4,
63  PRT_HSINTRO = 5,
64  PRT_HSREND = 6,
65  PRT_DESC = 7,
66  PRT_MICRODESC = 8,
67  PRT_CONS = 9,
68  PRT_PADDING = 10,
69  PRT_FLOWCTRL = 11,
71 
72 bool protover_list_is_invalid(const char *s);
73 int protover_all_supported(const char *s, char **missing);
74 int protover_is_supported_here(protocol_type_t pr, uint32_t ver);
75 const char *protover_get_supported_protocols(void);
76 
77 char *protover_compute_vote(const struct smartlist_t *list_of_proto_strings,
78  int threshold);
79 const char *protover_compute_for_old_tor(const char *version);
81  uint32_t version);
83  protocol_type_t tp,
84  uint32_t version);
85 
86 void protover_free_all(void);
87 
88 #ifdef PROTOVER_PRIVATE
89 /** Represents a set of ranges of subprotocols of a given type. */
90 typedef struct proto_entry_t {
91  /** The name of the protocol.
92  *
93  * (This needs to handle voting on protocols which
94  * we don't recognize yet, so it's a char* rather than a protocol_type_t.)
95  */
96  char *name;
97  /** Bitmask of supported protocols. Version 'x' is included in this
98  * entry if and only if bit '1<<x' is set here. */
99  uint64_t bitmask;
100 } proto_entry_t;
101 
102 #if !defined(HAVE_RUST) && defined(TOR_UNIT_TESTS)
103 STATIC struct smartlist_t *parse_protocol_list(const char *s);
104 STATIC char *encode_protocol_list(const struct smartlist_t *sl);
106 STATIC int str_to_protocol_type(const char *s, protocol_type_t *pr_out);
107 STATIC void proto_entry_free_(proto_entry_t *entry);
108 #endif /* !defined(HAVE_RUST) && defined(TOR_UNIT_TESTS) */
109 
110 #define proto_entry_free(entry) \
111  FREE_AND_NULL(proto_entry_t, proto_entry_free_, (entry))
112 
113 #endif /* defined(PROTOVER_PRIVATE) */
114 
115 #endif /* !defined(TOR_PROTOVER_H) */
const char * name
Definition: config.c:2434
STATIC const char * protocol_type_to_str(protocol_type_t pr)
Definition: protover.c:74
STATIC void proto_entry_free_(proto_entry_t *entry)
Definition: protover.c:91
char * protover_compute_vote(const smartlist_t *list_of_proto_strings, int threshold)
Definition: protover.c:520
STATIC char * encode_protocol_list(const smartlist_t *sl)
Definition: protover.c:489
STATIC smartlist_t * parse_protocol_list(const char *s)
Definition: protover.c:265
const char * protover_compute_for_old_tor(const char *version)
C_RUST_COUPLED: src/rust/protover/protover.rs compute_for_old_tor
Definition: protover.c:708
bool protover_list_is_invalid(const char *s)
Definition: protover.c:302
const char * protover_get_supported_protocols(void)
C_RUST_COUPLED: src/rust/protover/protover.rs SUPPORTED_PROTOCOLS
Definition: protover.c:391
void protover_free_all(void)
Definition: protover.c:746
int protover_all_supported(const char *s, char **missing)
Definition: protover.c:609
int protover_is_supported_here(protocol_type_t pr, uint32_t ver)
Definition: protover.c:317
int protocol_list_supports_protocol(const char *list, protocol_type_t tp, uint32_t version)
Definition: protover.c:331
protocol_type_t
Definition: protover.h:57
int protocol_list_supports_protocol_or_later(const char *list, protocol_type_t tp, uint32_t version)
Definition: protover.c:356
void ** list
Macros to implement mocking and selective exposure for the test code.
#define STATIC
Definition: testsupport.h:32
Integer definitions used throughout Tor.