1 /* netinfo.h -- generated by Trunnel v1.5.3. 2 * https://gitweb.torproject.org/trunnel.git 3 * You probably shouldn't edit this file. 4 */ 5 #ifndef TRUNNEL_NETINFO_H 6 #define TRUNNEL_NETINFO_H 7 8 #include <stdint.h> 9 #include "trunnel.h" 10 11 #define NETINFO_ADDR_TYPE_IPV4 4 12 #define NETINFO_ADDR_TYPE_IPV6 6 13 #if !defined(TRUNNEL_OPAQUE) && !defined(TRUNNEL_OPAQUE_NETINFO_ADDR) 14 struct netinfo_addr_st { 15 uint8_t addr_type; 16 uint8_t len; 17 uint32_t addr_ipv4; 18 uint8_t addr_ipv6[16]; 19 uint8_t trunnel_error_code_; 20 }; 21 #endif 22 typedef struct netinfo_addr_st netinfo_addr_t; 23 #if !defined(TRUNNEL_OPAQUE) && !defined(TRUNNEL_OPAQUE_NETINFO_CELL) 24 struct netinfo_cell_st { 25 uint32_t timestamp; 26 struct netinfo_addr_st *other_addr; 27 uint8_t n_my_addrs; 28 TRUNNEL_DYNARRAY_HEAD(, struct netinfo_addr_st *) my_addrs; 29 uint8_t trunnel_error_code_; 30 }; 31 #endif 32 typedef struct netinfo_cell_st netinfo_cell_t; 33 /** Return a newly allocated netinfo_addr with all elements set to 34 * zero. 35 */ 36 netinfo_addr_t *netinfo_addr_new(void); 37 /** Release all storage held by the netinfo_addr in 'victim'. (Do 38 * nothing if 'victim' is NULL.) 39 */ 40 void netinfo_addr_free(netinfo_addr_t *victim); 41 /** Try to parse a netinfo_addr from the buffer in 'input', using up 42 * to 'len_in' bytes from the input buffer. On success, return the 43 * number of bytes consumed and set *output to the newly allocated 44 * netinfo_addr_t. On failure, return -2 if the input appears 45 * truncated, and -1 if the input is otherwise invalid. 46 */ 47 ssize_t netinfo_addr_parse(netinfo_addr_t **output, const uint8_t *input, const size_t len_in); 48 /** Return the number of bytes we expect to need to encode the 49 * netinfo_addr in 'obj'. On failure, return a negative value. Note 50 * that this value may be an overestimate, and can even be an 51 * underestimate for certain unencodeable objects. 52 */ 53 ssize_t netinfo_addr_encoded_len(const netinfo_addr_t *obj); 54 /** Try to encode the netinfo_addr from 'input' into the buffer at 55 * 'output', using up to 'avail' bytes of the output buffer. On 56 * success, return the number of bytes used. On failure, return -2 if 57 * the buffer was not long enough, and -1 if the input was invalid. 58 */ 59 ssize_t netinfo_addr_encode(uint8_t *output, size_t avail, const netinfo_addr_t *input); 60 /** Check whether the internal state of the netinfo_addr in 'obj' is 61 * consistent. Return NULL if it is, and a short message if it is not. 62 */ 63 const char *netinfo_addr_check(const netinfo_addr_t *obj); 64 /** Clear any errors that were set on the object 'obj' by its setter 65 * functions. Return true iff errors were cleared. 66 */ 67 int netinfo_addr_clear_errors(netinfo_addr_t *obj); 68 /** Return the value of the addr_type field of the netinfo_addr_t in 69 * 'inp' 70 */ 71 uint8_t netinfo_addr_get_addr_type(const netinfo_addr_t *inp); 72 /** Set the value of the addr_type field of the netinfo_addr_t in 73 * 'inp' to 'val'. Return 0 on success; return -1 and set the error 74 * code on 'inp' on failure. 75 */ 76 int netinfo_addr_set_addr_type(netinfo_addr_t *inp, uint8_t val); 77 /** Return the value of the len field of the netinfo_addr_t in 'inp' 78 */ 79 uint8_t netinfo_addr_get_len(const netinfo_addr_t *inp); 80 /** Set the value of the len field of the netinfo_addr_t in 'inp' to 81 * 'val'. Return 0 on success; return -1 and set the error code on 82 * 'inp' on failure. 83 */ 84 int netinfo_addr_set_len(netinfo_addr_t *inp, uint8_t val); 85 /** Return the value of the addr_ipv4 field of the netinfo_addr_t in 86 * 'inp' 87 */ 88 uint32_t netinfo_addr_get_addr_ipv4(const netinfo_addr_t *inp); 89 /** Set the value of the addr_ipv4 field of the netinfo_addr_t in 90 * 'inp' to 'val'. Return 0 on success; return -1 and set the error 91 * code on 'inp' on failure. 92 */ 93 int netinfo_addr_set_addr_ipv4(netinfo_addr_t *inp, uint32_t val); 94 /** Return the (constant) length of the array holding the addr_ipv6 95 * field of the netinfo_addr_t in 'inp'. 96 */ 97 size_t netinfo_addr_getlen_addr_ipv6(const netinfo_addr_t *inp); 98 /** Return the element at position 'idx' of the fixed array field 99 * addr_ipv6 of the netinfo_addr_t in 'inp'. 100 */ 101 uint8_t netinfo_addr_get_addr_ipv6(netinfo_addr_t *inp, size_t idx); 102 /** As netinfo_addr_get_addr_ipv6, but take and return a const pointer 103 */ 104 uint8_t netinfo_addr_getconst_addr_ipv6(const netinfo_addr_t *inp, size_t idx); 105 /** Change the element at position 'idx' of the fixed array field 106 * addr_ipv6 of the netinfo_addr_t in 'inp', so that it will hold the 107 * value 'elt'. 108 */ 109 int netinfo_addr_set_addr_ipv6(netinfo_addr_t *inp, size_t idx, uint8_t elt); 110 /** Return a pointer to the 16-element array field addr_ipv6 of 'inp'. 111 */ 112 uint8_t * netinfo_addr_getarray_addr_ipv6(netinfo_addr_t *inp); 113 /** As netinfo_addr_get_addr_ipv6, but take and return a const pointer 114 */ 115 const uint8_t * netinfo_addr_getconstarray_addr_ipv6(const netinfo_addr_t *inp); 116 /** Return a newly allocated netinfo_cell with all elements set to 117 * zero. 118 */ 119 netinfo_cell_t *netinfo_cell_new(void); 120 /** Release all storage held by the netinfo_cell in 'victim'. (Do 121 * nothing if 'victim' is NULL.) 122 */ 123 void netinfo_cell_free(netinfo_cell_t *victim); 124 /** Try to parse a netinfo_cell from the buffer in 'input', using up 125 * to 'len_in' bytes from the input buffer. On success, return the 126 * number of bytes consumed and set *output to the newly allocated 127 * netinfo_cell_t. On failure, return -2 if the input appears 128 * truncated, and -1 if the input is otherwise invalid. 129 */ 130 ssize_t netinfo_cell_parse(netinfo_cell_t **output, const uint8_t *input, const size_t len_in); 131 /** Return the number of bytes we expect to need to encode the 132 * netinfo_cell in 'obj'. On failure, return a negative value. Note 133 * that this value may be an overestimate, and can even be an 134 * underestimate for certain unencodeable objects. 135 */ 136 ssize_t netinfo_cell_encoded_len(const netinfo_cell_t *obj); 137 /** Try to encode the netinfo_cell from 'input' into the buffer at 138 * 'output', using up to 'avail' bytes of the output buffer. On 139 * success, return the number of bytes used. On failure, return -2 if 140 * the buffer was not long enough, and -1 if the input was invalid. 141 */ 142 ssize_t netinfo_cell_encode(uint8_t *output, size_t avail, const netinfo_cell_t *input); 143 /** Check whether the internal state of the netinfo_cell in 'obj' is 144 * consistent. Return NULL if it is, and a short message if it is not. 145 */ 146 const char *netinfo_cell_check(const netinfo_cell_t *obj); 147 /** Clear any errors that were set on the object 'obj' by its setter 148 * functions. Return true iff errors were cleared. 149 */ 150 int netinfo_cell_clear_errors(netinfo_cell_t *obj); 151 /** Return the value of the timestamp field of the netinfo_cell_t in 152 * 'inp' 153 */ 154 uint32_t netinfo_cell_get_timestamp(const netinfo_cell_t *inp); 155 /** Set the value of the timestamp field of the netinfo_cell_t in 156 * 'inp' to 'val'. Return 0 on success; return -1 and set the error 157 * code on 'inp' on failure. 158 */ 159 int netinfo_cell_set_timestamp(netinfo_cell_t *inp, uint32_t val); 160 /** Return the value of the other_addr field of the netinfo_cell_t in 161 * 'inp' 162 */ 163 struct netinfo_addr_st * netinfo_cell_get_other_addr(netinfo_cell_t *inp); 164 /** As netinfo_cell_get_other_addr, but take and return a const 165 * pointer 166 */ 167 const struct netinfo_addr_st * netinfo_cell_getconst_other_addr(const netinfo_cell_t *inp); 168 /** Set the value of the other_addr field of the netinfo_cell_t in 169 * 'inp' to 'val'. Free the old value if any. Steals the referenceto 170 * 'val'.Return 0 on success; return -1 and set the error code on 171 * 'inp' on failure. 172 */ 173 int netinfo_cell_set_other_addr(netinfo_cell_t *inp, struct netinfo_addr_st *val); 174 /** As netinfo_cell_set_other_addr, but does not free the previous 175 * value. 176 */ 177 int netinfo_cell_set0_other_addr(netinfo_cell_t *inp, struct netinfo_addr_st *val); 178 /** Return the value of the n_my_addrs field of the netinfo_cell_t in 179 * 'inp' 180 */ 181 uint8_t netinfo_cell_get_n_my_addrs(const netinfo_cell_t *inp); 182 /** Set the value of the n_my_addrs field of the netinfo_cell_t in 183 * 'inp' to 'val'. Return 0 on success; return -1 and set the error 184 * code on 'inp' on failure. 185 */ 186 int netinfo_cell_set_n_my_addrs(netinfo_cell_t *inp, uint8_t val); 187 /** Return the length of the dynamic array holding the my_addrs field 188 * of the netinfo_cell_t in 'inp'. 189 */ 190 size_t netinfo_cell_getlen_my_addrs(const netinfo_cell_t *inp); 191 /** Return the element at position 'idx' of the dynamic array field 192 * my_addrs of the netinfo_cell_t in 'inp'. 193 */ 194 struct netinfo_addr_st * netinfo_cell_get_my_addrs(netinfo_cell_t *inp, size_t idx); 195 /** As netinfo_cell_get_my_addrs, but take and return a const pointer 196 */ 197 const struct netinfo_addr_st * netinfo_cell_getconst_my_addrs(const netinfo_cell_t *inp, size_t idx); 198 /** Change the element at position 'idx' of the dynamic array field 199 * my_addrs of the netinfo_cell_t in 'inp', so that it will hold the 200 * value 'elt'. Free the previous value, if any. 201 */ 202 int netinfo_cell_set_my_addrs(netinfo_cell_t *inp, size_t idx, struct netinfo_addr_st * elt); 203 /** As netinfo_cell_set_my_addrs, but does not free the previous 204 * value. 205 */ 206 int netinfo_cell_set0_my_addrs(netinfo_cell_t *inp, size_t idx, struct netinfo_addr_st * elt); 207 /** Append a new element 'elt' to the dynamic array field my_addrs of 208 * the netinfo_cell_t in 'inp'. 209 */ 210 int netinfo_cell_add_my_addrs(netinfo_cell_t *inp, struct netinfo_addr_st * elt); 211 /** Return a pointer to the variable-length array field my_addrs of 212 * 'inp'. 213 */ 214 struct netinfo_addr_st * * netinfo_cell_getarray_my_addrs(netinfo_cell_t *inp); 215 /** As netinfo_cell_get_my_addrs, but take and return a const pointer 216 */ 217 const struct netinfo_addr_st * const * netinfo_cell_getconstarray_my_addrs(const netinfo_cell_t *inp); 218 /** Change the length of the variable-length array field my_addrs of 219 * 'inp' to 'newlen'.Fill extra elements with NULL; free removed 220 * elements. Return 0 on success; return -1 and set the error code on 221 * 'inp' on failure. 222 */ 223 int netinfo_cell_setlen_my_addrs(netinfo_cell_t *inp, size_t newlen); 224 225 226 #endif 227