From: David Goulet Date: Mon, 22 Jan 2024 15:12:28 +0000 (-0500) Subject: trunnel: Add subproto request definition X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e9dac65c4f35890388f891bc38c7cf1a6db684a7;p=thirdparty%2Ftor.git trunnel: Add subproto request definition Signed-off-by: David Goulet --- diff --git a/src/trunnel/include.am b/src/trunnel/include.am index 8154a5e932..3c20acecaa 100644 --- a/src/trunnel/include.am +++ b/src/trunnel/include.am @@ -17,7 +17,8 @@ TRUNNELINPUTS = \ src/trunnel/congestion_control.trunnel \ src/trunnel/socks5.trunnel \ src/trunnel/circpad_negotiation.trunnel \ - src/trunnel/conflux.trunnel + src/trunnel/conflux.trunnel \ + src/trunnel/ntorv3.trunnel TRUNNELSOURCES = \ src/ext/trunnel/trunnel.c \ @@ -35,7 +36,8 @@ TRUNNELSOURCES = \ src/trunnel/socks5.c \ src/trunnel/netinfo.c \ src/trunnel/circpad_negotiation.c \ - src/trunnel/conflux.c + src/trunnel/conflux.c \ + src/trunnel/ntorv3.c TRUNNELHEADERS = \ src/ext/trunnel/trunnel.h \ @@ -55,7 +57,8 @@ TRUNNELHEADERS = \ src/trunnel/socks5.h \ src/trunnel/netinfo.h \ src/trunnel/circpad_negotiation.h \ - src/trunnel/conflux.h + src/trunnel/conflux.h \ + src/trunnel/ntorv3.h src_trunnel_libor_trunnel_a_SOURCES = $(TRUNNELSOURCES) src_trunnel_libor_trunnel_a_CPPFLAGS = \ diff --git a/src/trunnel/ntorv3.c b/src/trunnel/ntorv3.c new file mode 100644 index 0000000000..ff10fbff29 --- /dev/null +++ b/src/trunnel/ntorv3.c @@ -0,0 +1,456 @@ +/* ntorv3.c -- generated by Trunnel v1.5.3. + * https://gitweb.torproject.org/trunnel.git + * You probably shouldn't edit this file. + */ +#include +#include "trunnel-impl.h" + +#include "ntorv3.h" + +#define TRUNNEL_SET_ERROR_CODE(obj) \ + do { \ + (obj)->trunnel_error_code_ = 1; \ + } while (0) + +#if defined(__COVERITY__) || defined(__clang_analyzer__) +/* If we're running a static analysis tool, we don't want it to complain + * that some of our remaining-bytes checks are dead-code. */ +int ntorv_deadcode_dummy__ = 0; +#define OR_DEADCODE_DUMMY || ntorv_deadcode_dummy__ +#else +#define OR_DEADCODE_DUMMY +#endif + +#define CHECK_REMAINING(nbytes, label) \ + do { \ + if (remaining < (nbytes) OR_DEADCODE_DUMMY) { \ + goto label; \ + } \ + } while (0) + +trn_ntorv3_ext_subproto_req_t * +trn_ntorv3_ext_subproto_req_new(void) +{ + trn_ntorv3_ext_subproto_req_t *val = trunnel_calloc(1, sizeof(trn_ntorv3_ext_subproto_req_t)); + if (NULL == val) + return NULL; + return val; +} + +/** Release all storage held inside 'obj', but do not free 'obj'. + */ +static void +trn_ntorv3_ext_subproto_req_clear(trn_ntorv3_ext_subproto_req_t *obj) +{ + (void) obj; +} + +void +trn_ntorv3_ext_subproto_req_free(trn_ntorv3_ext_subproto_req_t *obj) +{ + if (obj == NULL) + return; + trn_ntorv3_ext_subproto_req_clear(obj); + trunnel_memwipe(obj, sizeof(trn_ntorv3_ext_subproto_req_t)); + trunnel_free_(obj); +} + +uint8_t +trn_ntorv3_ext_subproto_req_get_proto_id(const trn_ntorv3_ext_subproto_req_t *inp) +{ + return inp->proto_id; +} +int +trn_ntorv3_ext_subproto_req_set_proto_id(trn_ntorv3_ext_subproto_req_t *inp, uint8_t val) +{ + inp->proto_id = val; + return 0; +} +uint8_t +trn_ntorv3_ext_subproto_req_get_proto_version(const trn_ntorv3_ext_subproto_req_t *inp) +{ + return inp->proto_version; +} +int +trn_ntorv3_ext_subproto_req_set_proto_version(trn_ntorv3_ext_subproto_req_t *inp, uint8_t val) +{ + inp->proto_version = val; + return 0; +} +const char * +trn_ntorv3_ext_subproto_req_check(const trn_ntorv3_ext_subproto_req_t *obj) +{ + if (obj == NULL) + return "Object was NULL"; + if (obj->trunnel_error_code_) + return "A set function failed on this object"; + return NULL; +} + +ssize_t +trn_ntorv3_ext_subproto_req_encoded_len(const trn_ntorv3_ext_subproto_req_t *obj) +{ + ssize_t result = 0; + + if (NULL != trn_ntorv3_ext_subproto_req_check(obj)) + return -1; + + + /* Length of u8 proto_id */ + result += 1; + + /* Length of u8 proto_version */ + result += 1; + return result; +} +int +trn_ntorv3_ext_subproto_req_clear_errors(trn_ntorv3_ext_subproto_req_t *obj) +{ + int r = obj->trunnel_error_code_; + obj->trunnel_error_code_ = 0; + return r; +} +ssize_t +trn_ntorv3_ext_subproto_req_encode(uint8_t *output, const size_t avail, const trn_ntorv3_ext_subproto_req_t *obj) +{ + ssize_t result = 0; + size_t written = 0; + uint8_t *ptr = output; + const char *msg; +#ifdef TRUNNEL_CHECK_ENCODED_LEN + const ssize_t encoded_len = trn_ntorv3_ext_subproto_req_encoded_len(obj); +#endif + + if (NULL != (msg = trn_ntorv3_ext_subproto_req_check(obj))) + goto check_failed; + +#ifdef TRUNNEL_CHECK_ENCODED_LEN + trunnel_assert(encoded_len >= 0); +#endif + + /* Encode u8 proto_id */ + trunnel_assert(written <= avail); + if (avail - written < 1) + goto truncated; + trunnel_set_uint8(ptr, (obj->proto_id)); + written += 1; ptr += 1; + + /* Encode u8 proto_version */ + trunnel_assert(written <= avail); + if (avail - written < 1) + goto truncated; + trunnel_set_uint8(ptr, (obj->proto_version)); + written += 1; ptr += 1; + + + trunnel_assert(ptr == output + written); +#ifdef TRUNNEL_CHECK_ENCODED_LEN + { + trunnel_assert(encoded_len >= 0); + trunnel_assert((size_t)encoded_len == written); + } + +#endif + + return written; + + truncated: + result = -2; + goto fail; + check_failed: + (void)msg; + result = -1; + goto fail; + fail: + trunnel_assert(result < 0); + return result; +} + +/** As trn_ntorv3_ext_subproto_req_parse(), but do not allocate the + * output object. + */ +static ssize_t +trn_ntorv3_ext_subproto_req_parse_into(trn_ntorv3_ext_subproto_req_t *obj, const uint8_t *input, const size_t len_in) +{ + const uint8_t *ptr = input; + size_t remaining = len_in; + ssize_t result = 0; + (void)result; + + /* Parse u8 proto_id */ + CHECK_REMAINING(1, truncated); + obj->proto_id = (trunnel_get_uint8(ptr)); + remaining -= 1; ptr += 1; + + /* Parse u8 proto_version */ + CHECK_REMAINING(1, truncated); + obj->proto_version = (trunnel_get_uint8(ptr)); + remaining -= 1; ptr += 1; + trunnel_assert(ptr + remaining == input + len_in); + return len_in - remaining; + + truncated: + return -2; +} + +ssize_t +trn_ntorv3_ext_subproto_req_parse(trn_ntorv3_ext_subproto_req_t **output, const uint8_t *input, const size_t len_in) +{ + ssize_t result; + *output = trn_ntorv3_ext_subproto_req_new(); + if (NULL == *output) + return -1; + result = trn_ntorv3_ext_subproto_req_parse_into(*output, input, len_in); + if (result < 0) { + trn_ntorv3_ext_subproto_req_free(*output); + *output = NULL; + } + return result; +} +trn_ntorv3_ext_subproto_t * +trn_ntorv3_ext_subproto_new(void) +{ + trn_ntorv3_ext_subproto_t *val = trunnel_calloc(1, sizeof(trn_ntorv3_ext_subproto_t)); + if (NULL == val) + return NULL; + return val; +} + +/** Release all storage held inside 'obj', but do not free 'obj'. + */ +static void +trn_ntorv3_ext_subproto_clear(trn_ntorv3_ext_subproto_t *obj) +{ + (void) obj; + { + + unsigned idx; + for (idx = 0; idx < TRUNNEL_DYNARRAY_LEN(&obj->reqs); ++idx) { + trn_ntorv3_ext_subproto_req_free(TRUNNEL_DYNARRAY_GET(&obj->reqs, idx)); + } + } + TRUNNEL_DYNARRAY_WIPE(&obj->reqs); + TRUNNEL_DYNARRAY_CLEAR(&obj->reqs); +} + +void +trn_ntorv3_ext_subproto_free(trn_ntorv3_ext_subproto_t *obj) +{ + if (obj == NULL) + return; + trn_ntorv3_ext_subproto_clear(obj); + trunnel_memwipe(obj, sizeof(trn_ntorv3_ext_subproto_t)); + trunnel_free_(obj); +} + +size_t +trn_ntorv3_ext_subproto_getlen_reqs(const trn_ntorv3_ext_subproto_t *inp) +{ + return TRUNNEL_DYNARRAY_LEN(&inp->reqs); +} + +struct trn_ntorv3_ext_subproto_req_st * +trn_ntorv3_ext_subproto_get_reqs(trn_ntorv3_ext_subproto_t *inp, size_t idx) +{ + return TRUNNEL_DYNARRAY_GET(&inp->reqs, idx); +} + + const struct trn_ntorv3_ext_subproto_req_st * +trn_ntorv3_ext_subproto_getconst_reqs(const trn_ntorv3_ext_subproto_t *inp, size_t idx) +{ + return trn_ntorv3_ext_subproto_get_reqs((trn_ntorv3_ext_subproto_t*)inp, idx); +} +int +trn_ntorv3_ext_subproto_set_reqs(trn_ntorv3_ext_subproto_t *inp, size_t idx, struct trn_ntorv3_ext_subproto_req_st * elt) +{ + trn_ntorv3_ext_subproto_req_t *oldval = TRUNNEL_DYNARRAY_GET(&inp->reqs, idx); + if (oldval && oldval != elt) + trn_ntorv3_ext_subproto_req_free(oldval); + return trn_ntorv3_ext_subproto_set0_reqs(inp, idx, elt); +} +int +trn_ntorv3_ext_subproto_set0_reqs(trn_ntorv3_ext_subproto_t *inp, size_t idx, struct trn_ntorv3_ext_subproto_req_st * elt) +{ + TRUNNEL_DYNARRAY_SET(&inp->reqs, idx, elt); + return 0; +} +int +trn_ntorv3_ext_subproto_add_reqs(trn_ntorv3_ext_subproto_t *inp, struct trn_ntorv3_ext_subproto_req_st * elt) +{ + TRUNNEL_DYNARRAY_ADD(struct trn_ntorv3_ext_subproto_req_st *, &inp->reqs, elt, {}); + return 0; + trunnel_alloc_failed: + TRUNNEL_SET_ERROR_CODE(inp); + return -1; +} + +struct trn_ntorv3_ext_subproto_req_st * * +trn_ntorv3_ext_subproto_getarray_reqs(trn_ntorv3_ext_subproto_t *inp) +{ + return inp->reqs.elts_; +} +const struct trn_ntorv3_ext_subproto_req_st * const * +trn_ntorv3_ext_subproto_getconstarray_reqs(const trn_ntorv3_ext_subproto_t *inp) +{ + return (const struct trn_ntorv3_ext_subproto_req_st * const *)trn_ntorv3_ext_subproto_getarray_reqs((trn_ntorv3_ext_subproto_t*)inp); +} +int +trn_ntorv3_ext_subproto_setlen_reqs(trn_ntorv3_ext_subproto_t *inp, size_t newlen) +{ + struct trn_ntorv3_ext_subproto_req_st * *newptr; + newptr = trunnel_dynarray_setlen(&inp->reqs.allocated_, + &inp->reqs.n_, inp->reqs.elts_, newlen, + sizeof(inp->reqs.elts_[0]), (trunnel_free_fn_t) trn_ntorv3_ext_subproto_req_free, + &inp->trunnel_error_code_); + if (newlen != 0 && newptr == NULL) + goto trunnel_alloc_failed; + inp->reqs.elts_ = newptr; + return 0; + trunnel_alloc_failed: + TRUNNEL_SET_ERROR_CODE(inp); + return -1; +} +const char * +trn_ntorv3_ext_subproto_check(const trn_ntorv3_ext_subproto_t *obj) +{ + if (obj == NULL) + return "Object was NULL"; + if (obj->trunnel_error_code_) + return "A set function failed on this object"; + { + const char *msg; + + unsigned idx; + for (idx = 0; idx < TRUNNEL_DYNARRAY_LEN(&obj->reqs); ++idx) { + if (NULL != (msg = trn_ntorv3_ext_subproto_req_check(TRUNNEL_DYNARRAY_GET(&obj->reqs, idx)))) + return msg; + } + } + return NULL; +} + +ssize_t +trn_ntorv3_ext_subproto_encoded_len(const trn_ntorv3_ext_subproto_t *obj) +{ + ssize_t result = 0; + + if (NULL != trn_ntorv3_ext_subproto_check(obj)) + return -1; + + + /* Length of struct trn_ntorv3_ext_subproto_req reqs[] */ + { + + unsigned idx; + for (idx = 0; idx < TRUNNEL_DYNARRAY_LEN(&obj->reqs); ++idx) { + result += trn_ntorv3_ext_subproto_req_encoded_len(TRUNNEL_DYNARRAY_GET(&obj->reqs, idx)); + } + } + return result; +} +int +trn_ntorv3_ext_subproto_clear_errors(trn_ntorv3_ext_subproto_t *obj) +{ + int r = obj->trunnel_error_code_; + obj->trunnel_error_code_ = 0; + return r; +} +ssize_t +trn_ntorv3_ext_subproto_encode(uint8_t *output, const size_t avail, const trn_ntorv3_ext_subproto_t *obj) +{ + ssize_t result = 0; + size_t written = 0; + uint8_t *ptr = output; + const char *msg; +#ifdef TRUNNEL_CHECK_ENCODED_LEN + const ssize_t encoded_len = trn_ntorv3_ext_subproto_encoded_len(obj); +#endif + + if (NULL != (msg = trn_ntorv3_ext_subproto_check(obj))) + goto check_failed; + +#ifdef TRUNNEL_CHECK_ENCODED_LEN + trunnel_assert(encoded_len >= 0); +#endif + + /* Encode struct trn_ntorv3_ext_subproto_req reqs[] */ + { + + unsigned idx; + for (idx = 0; idx < TRUNNEL_DYNARRAY_LEN(&obj->reqs); ++idx) { + trunnel_assert(written <= avail); + result = trn_ntorv3_ext_subproto_req_encode(ptr, avail - written, TRUNNEL_DYNARRAY_GET(&obj->reqs, idx)); + if (result < 0) + goto fail; /* XXXXXXX !*/ + written += result; ptr += result; + } + } + + + trunnel_assert(ptr == output + written); +#ifdef TRUNNEL_CHECK_ENCODED_LEN + { + trunnel_assert(encoded_len >= 0); + trunnel_assert((size_t)encoded_len == written); + } + +#endif + + return written; + + check_failed: + (void)msg; + result = -1; + goto fail; + fail: + trunnel_assert(result < 0); + return result; +} + +/** As trn_ntorv3_ext_subproto_parse(), but do not allocate the output + * object. + */ +static ssize_t +trn_ntorv3_ext_subproto_parse_into(trn_ntorv3_ext_subproto_t *obj, const uint8_t *input, const size_t len_in) +{ + const uint8_t *ptr = input; + size_t remaining = len_in; + ssize_t result = 0; + (void)result; + + /* Parse struct trn_ntorv3_ext_subproto_req reqs[] */ + { + trn_ntorv3_ext_subproto_req_t * elt; + while (remaining > 0) { + result = trn_ntorv3_ext_subproto_req_parse(&elt, ptr, remaining); + if (result < 0) + goto fail; + trunnel_assert((size_t)result <= remaining); + remaining -= result; ptr += result; + TRUNNEL_DYNARRAY_ADD(trn_ntorv3_ext_subproto_req_t *, &obj->reqs, elt, {trn_ntorv3_ext_subproto_req_free(elt);}); + } + } + trunnel_assert(ptr + remaining == input + len_in); + return len_in - remaining; + + trunnel_alloc_failed: + return -1; + fail: + result = -1; + return result; +} + +ssize_t +trn_ntorv3_ext_subproto_parse(trn_ntorv3_ext_subproto_t **output, const uint8_t *input, const size_t len_in) +{ + ssize_t result; + *output = trn_ntorv3_ext_subproto_new(); + if (NULL == *output) + return -1; + result = trn_ntorv3_ext_subproto_parse_into(*output, input, len_in); + if (result < 0) { + trn_ntorv3_ext_subproto_free(*output); + *output = NULL; + } + return result; +} diff --git a/src/trunnel/ntorv3.h b/src/trunnel/ntorv3.h new file mode 100644 index 0000000000..5999e179b2 --- /dev/null +++ b/src/trunnel/ntorv3.h @@ -0,0 +1,158 @@ +/* ntorv3.h -- generated by Trunnel v1.5.3. + * https://gitweb.torproject.org/trunnel.git + * You probably shouldn't edit this file. + */ +#ifndef TRUNNEL_NTORV3_H +#define TRUNNEL_NTORV3_H + +#include +#include "trunnel.h" + +#if !defined(TRUNNEL_OPAQUE) && !defined(TRUNNEL_OPAQUE_TRN_NTORV3_EXT_SUBPROTO_REQ) +struct trn_ntorv3_ext_subproto_req_st { + uint8_t proto_id; + uint8_t proto_version; + uint8_t trunnel_error_code_; +}; +#endif +typedef struct trn_ntorv3_ext_subproto_req_st trn_ntorv3_ext_subproto_req_t; +#if !defined(TRUNNEL_OPAQUE) && !defined(TRUNNEL_OPAQUE_TRN_NTORV3_EXT_SUBPROTO) +struct trn_ntorv3_ext_subproto_st { + TRUNNEL_DYNARRAY_HEAD(, struct trn_ntorv3_ext_subproto_req_st *) reqs; + uint8_t trunnel_error_code_; +}; +#endif +typedef struct trn_ntorv3_ext_subproto_st trn_ntorv3_ext_subproto_t; +/** Return a newly allocated trn_ntorv3_ext_subproto_req with all + * elements set to zero. + */ +trn_ntorv3_ext_subproto_req_t *trn_ntorv3_ext_subproto_req_new(void); +/** Release all storage held by the trn_ntorv3_ext_subproto_req in + * 'victim'. (Do nothing if 'victim' is NULL.) + */ +void trn_ntorv3_ext_subproto_req_free(trn_ntorv3_ext_subproto_req_t *victim); +/** Try to parse a trn_ntorv3_ext_subproto_req from the buffer in + * 'input', using up to 'len_in' bytes from the input buffer. On + * success, return the number of bytes consumed and set *output to the + * newly allocated trn_ntorv3_ext_subproto_req_t. On failure, return + * -2 if the input appears truncated, and -1 if the input is otherwise + * invalid. + */ +ssize_t trn_ntorv3_ext_subproto_req_parse(trn_ntorv3_ext_subproto_req_t **output, const uint8_t *input, const size_t len_in); +/** Return the number of bytes we expect to need to encode the + * trn_ntorv3_ext_subproto_req in 'obj'. On failure, return a negative + * value. Note that this value may be an overestimate, and can even be + * an underestimate for certain unencodeable objects. + */ +ssize_t trn_ntorv3_ext_subproto_req_encoded_len(const trn_ntorv3_ext_subproto_req_t *obj); +/** Try to encode the trn_ntorv3_ext_subproto_req from 'input' into + * the buffer at 'output', using up to 'avail' bytes of the output + * buffer. On success, return the number of bytes used. On failure, + * return -2 if the buffer was not long enough, and -1 if the input + * was invalid. + */ +ssize_t trn_ntorv3_ext_subproto_req_encode(uint8_t *output, size_t avail, const trn_ntorv3_ext_subproto_req_t *input); +/** Check whether the internal state of the + * trn_ntorv3_ext_subproto_req in 'obj' is consistent. Return NULL if + * it is, and a short message if it is not. + */ +const char *trn_ntorv3_ext_subproto_req_check(const trn_ntorv3_ext_subproto_req_t *obj); +/** Clear any errors that were set on the object 'obj' by its setter + * functions. Return true iff errors were cleared. + */ +int trn_ntorv3_ext_subproto_req_clear_errors(trn_ntorv3_ext_subproto_req_t *obj); +/** Return the value of the proto_id field of the + * trn_ntorv3_ext_subproto_req_t in 'inp' + */ +uint8_t trn_ntorv3_ext_subproto_req_get_proto_id(const trn_ntorv3_ext_subproto_req_t *inp); +/** Set the value of the proto_id field of the + * trn_ntorv3_ext_subproto_req_t in 'inp' to 'val'. Return 0 on + * success; return -1 and set the error code on 'inp' on failure. + */ +int trn_ntorv3_ext_subproto_req_set_proto_id(trn_ntorv3_ext_subproto_req_t *inp, uint8_t val); +/** Return the value of the proto_version field of the + * trn_ntorv3_ext_subproto_req_t in 'inp' + */ +uint8_t trn_ntorv3_ext_subproto_req_get_proto_version(const trn_ntorv3_ext_subproto_req_t *inp); +/** Set the value of the proto_version field of the + * trn_ntorv3_ext_subproto_req_t in 'inp' to 'val'. Return 0 on + * success; return -1 and set the error code on 'inp' on failure. + */ +int trn_ntorv3_ext_subproto_req_set_proto_version(trn_ntorv3_ext_subproto_req_t *inp, uint8_t val); +/** Return a newly allocated trn_ntorv3_ext_subproto with all elements + * set to zero. + */ +trn_ntorv3_ext_subproto_t *trn_ntorv3_ext_subproto_new(void); +/** Release all storage held by the trn_ntorv3_ext_subproto in + * 'victim'. (Do nothing if 'victim' is NULL.) + */ +void trn_ntorv3_ext_subproto_free(trn_ntorv3_ext_subproto_t *victim); +/** Try to parse a trn_ntorv3_ext_subproto from the buffer in 'input', + * using up to 'len_in' bytes from the input buffer. On success, + * return the number of bytes consumed and set *output to the newly + * allocated trn_ntorv3_ext_subproto_t. On failure, return -2 if the + * input appears truncated, and -1 if the input is otherwise invalid. + */ +ssize_t trn_ntorv3_ext_subproto_parse(trn_ntorv3_ext_subproto_t **output, const uint8_t *input, const size_t len_in); +/** Return the number of bytes we expect to need to encode the + * trn_ntorv3_ext_subproto in 'obj'. On failure, return a negative + * value. Note that this value may be an overestimate, and can even be + * an underestimate for certain unencodeable objects. + */ +ssize_t trn_ntorv3_ext_subproto_encoded_len(const trn_ntorv3_ext_subproto_t *obj); +/** Try to encode the trn_ntorv3_ext_subproto from 'input' into the + * buffer at 'output', using up to 'avail' bytes of the output buffer. + * On success, return the number of bytes used. On failure, return -2 + * if the buffer was not long enough, and -1 if the input was invalid. + */ +ssize_t trn_ntorv3_ext_subproto_encode(uint8_t *output, size_t avail, const trn_ntorv3_ext_subproto_t *input); +/** Check whether the internal state of the trn_ntorv3_ext_subproto in + * 'obj' is consistent. Return NULL if it is, and a short message if + * it is not. + */ +const char *trn_ntorv3_ext_subproto_check(const trn_ntorv3_ext_subproto_t *obj); +/** Clear any errors that were set on the object 'obj' by its setter + * functions. Return true iff errors were cleared. + */ +int trn_ntorv3_ext_subproto_clear_errors(trn_ntorv3_ext_subproto_t *obj); +/** Return the length of the dynamic array holding the reqs field of + * the trn_ntorv3_ext_subproto_t in 'inp'. + */ +size_t trn_ntorv3_ext_subproto_getlen_reqs(const trn_ntorv3_ext_subproto_t *inp); +/** Return the element at position 'idx' of the dynamic array field + * reqs of the trn_ntorv3_ext_subproto_t in 'inp'. + */ +struct trn_ntorv3_ext_subproto_req_st * trn_ntorv3_ext_subproto_get_reqs(trn_ntorv3_ext_subproto_t *inp, size_t idx); +/** As trn_ntorv3_ext_subproto_get_reqs, but take and return a const + * pointer + */ + const struct trn_ntorv3_ext_subproto_req_st * trn_ntorv3_ext_subproto_getconst_reqs(const trn_ntorv3_ext_subproto_t *inp, size_t idx); +/** Change the element at position 'idx' of the dynamic array field + * reqs of the trn_ntorv3_ext_subproto_t in 'inp', so that it will + * hold the value 'elt'. Free the previous value, if any. + */ +int trn_ntorv3_ext_subproto_set_reqs(trn_ntorv3_ext_subproto_t *inp, size_t idx, struct trn_ntorv3_ext_subproto_req_st * elt); +/** As trn_ntorv3_ext_subproto_set_reqs, but does not free the + * previous value. + */ +int trn_ntorv3_ext_subproto_set0_reqs(trn_ntorv3_ext_subproto_t *inp, size_t idx, struct trn_ntorv3_ext_subproto_req_st * elt); +/** Append a new element 'elt' to the dynamic array field reqs of the + * trn_ntorv3_ext_subproto_t in 'inp'. + */ +int trn_ntorv3_ext_subproto_add_reqs(trn_ntorv3_ext_subproto_t *inp, struct trn_ntorv3_ext_subproto_req_st * elt); +/** Return a pointer to the variable-length array field reqs of 'inp'. + */ +struct trn_ntorv3_ext_subproto_req_st * * trn_ntorv3_ext_subproto_getarray_reqs(trn_ntorv3_ext_subproto_t *inp); +/** As trn_ntorv3_ext_subproto_get_reqs, but take and return a const + * pointer + */ +const struct trn_ntorv3_ext_subproto_req_st * const * trn_ntorv3_ext_subproto_getconstarray_reqs(const trn_ntorv3_ext_subproto_t *inp); +/** Change the length of the variable-length array field reqs of 'inp' + * to 'newlen'.Fill extra elements with NULL; free removed elements. + * Return 0 on success; return -1 and set the error code on 'inp' on + * failure. + */ +int trn_ntorv3_ext_subproto_setlen_reqs(trn_ntorv3_ext_subproto_t *inp, size_t newlen); + + +#endif diff --git a/src/trunnel/ntorv3.trunnel b/src/trunnel/ntorv3.trunnel new file mode 100644 index 0000000000..fba3bdeeb1 --- /dev/null +++ b/src/trunnel/ntorv3.trunnel @@ -0,0 +1,16 @@ +/* + * Extension used to negotiate subprotocol versions detailed in proposal 346. + */ +struct trn_ntorv3_ext_subproto { + struct trn_ntorv3_ext_subproto_req reqs[]; +} + +/* + * Single subproto request. + */ +struct trn_ntorv3_ext_subproto_req { + /* Protocol ID. */ + u8 proto_id; + /* Protocol version being requested. */ + u8 proto_version; +}