netinfo.h 9.7 KB

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