From: David Goulet Date: Thu, 24 Aug 2023 18:33:59 +0000 (-0400) Subject: prop340: Put in subproto request for RelayCell=1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b43d6f9575b6bc861018c50548533943cf162a57;p=thirdparty%2Ftor.git prop340: Put in subproto request for RelayCell=1 Related #40791 Signed-off-by: David Goulet --- diff --git a/src/core/crypto/onion_crypto.c b/src/core/crypto/onion_crypto.c index 8507f9f163..0668681bf3 100644 --- a/src/core/crypto/onion_crypto.c +++ b/src/core/crypto/onion_crypto.c @@ -33,6 +33,7 @@ #include "core/or/or.h" #include "core/or/extendinfo.h" #include "core/or/protover.h" +#include "core/or/relay_msg.h" #include "core/crypto/onion_crypto.h" #include "core/crypto/onion_fast.h" #include "core/crypto/onion_ntor.h" @@ -94,6 +95,14 @@ parse_subproto_extension(const trn_extension_field_t *field, params_out->subproto.flow_ctrl = req->proto_version; params_out->cc_enabled = true; break; + case PRT_RELAY_CELL: + if (!relay_msg_is_enabled() || + !protover_is_supported_here(PRT_RELAY_CELL, req->proto_version)) { + ret = false; + goto end; + } + params_out->subproto.relay_cell = req->proto_version; + break; default: /* Reject any unknown values. */ ret = false; @@ -444,6 +453,12 @@ validate_ntor3_params_server(const circuit_params_t *our_ns_params, circ_params->cc_enabled = circ_params->cc_enabled && our_ns_params->cc_enabled; + /* If the circuit relay cell protocol version is higher than ours it means we + * don't support it so error. */ + if (circ_params->subproto.relay_cell > our_ns_params->subproto.relay_cell) { + return false; + } + return true; } @@ -466,8 +481,6 @@ negotiate_v3_ntor_server_circ_params(const uint8_t *param_request_msg, uint8_t **resp_msg_out, size_t *resp_msg_len_out) { - int ret = -1; - /* Failed to parse the extension. */ if (!parse_ntor3_server_ext(param_request_msg, param_request_len, params_out)) { @@ -491,10 +504,10 @@ negotiate_v3_ntor_server_circ_params(const uint8_t *param_request_msg, params_out->sendme_inc_cells = our_ns_params->sendme_inc_cells; /* Success. */ - ret = 0; + return 0; err: - return ret; + return -1; } /* This is the maximum value for keys_out_len passed to diff --git a/src/core/crypto/onion_crypto.h b/src/core/crypto/onion_crypto.h index 233df9a1a0..6b3413f274 100644 --- a/src/core/crypto/onion_crypto.h +++ b/src/core/crypto/onion_crypto.h @@ -29,6 +29,7 @@ void onion_handshake_state_release(onion_handshake_state_t *state); /** Negotiated subprotocol versions set after a ntorv3 handshake. */ typedef struct circuit_subproto_t { uint8_t flow_ctrl; + uint8_t relay_cell; } circuit_subproto_t; /** diff --git a/src/core/mainloop/cpuworker.c b/src/core/mainloop/cpuworker.c index a42dbb528d..294560dc75 100644 --- a/src/core/mainloop/cpuworker.c +++ b/src/core/mainloop/cpuworker.c @@ -24,6 +24,7 @@ #include "core/or/connection_or.h" #include "core/or/congestion_control_common.h" #include "core/or/congestion_control_flow.h" +#include "core/or/protover.h" #include "app/config/config.h" #include "core/mainloop/cpuworker.h" #include "lib/crypt_ops/crypto_rand.h" @@ -625,6 +626,7 @@ assign_onionskin_to_cpuworker(or_circuit_t *circ, * circuit negotiation into the CPU worker context */ req.circ_ns_params.cc_enabled = congestion_control_enabled(); req.circ_ns_params.sendme_inc_cells = congestion_control_sendme_inc(); + req.circ_ns_params.subproto.relay_cell = PROTOVER_RELAY_CELL_PROTO; job = tor_malloc_zero(sizeof(cpuworker_job_t)); job->circ = circ; diff --git a/src/core/or/extend_info_st.h b/src/core/or/extend_info_st.h index 44edadaf17..c7653b2cba 100644 --- a/src/core/or/extend_info_st.h +++ b/src/core/or/extend_info_st.h @@ -45,6 +45,8 @@ struct extend_info_t { /** True iff this hop supports the ntorv3 subprotocol request which is * defined by Relay=5 */ bool supports_ntorv3_subproto_req; + /** True iff this hop supports the RelayCell=1 protocol. */ + bool supports_relay_cell_proto; }; #endif /* !defined(EXTEND_INFO_ST_H) */ diff --git a/src/core/or/extendinfo.c b/src/core/or/extendinfo.c index 66b01c8788..f98d7bd052 100644 --- a/src/core/or/extendinfo.c +++ b/src/core/or/extendinfo.c @@ -62,6 +62,8 @@ extend_info_new(const char *nickname, if (pv && for_exit_use) { info->exit_supports_congestion_control = pv->supports_congestion_control; + info->supports_relay_cell_proto = + pv->supports_relay_cell_proto; } if (pv) { diff --git a/src/core/or/protover.c b/src/core/or/protover.c index 1eef2b8f7e..b084cb5f36 100644 --- a/src/core/or/protover.c +++ b/src/core/or/protover.c @@ -926,6 +926,15 @@ protover_build_ntor3_ext_request(const extend_info_t *ei) PROTOVER_FLOWCTRL_CC); trn_ntorv3_ext_subproto_add_reqs(req, proto_req); } + /* Build the RelayCell version request. */ + if (ei->supports_relay_cell_proto) { + trn_ntorv3_ext_subproto_req_t *proto_req = + trn_ntorv3_ext_subproto_req_new(); + trn_ntorv3_ext_subproto_req_set_proto_id(proto_req, PRT_RELAY_CELL); + trn_ntorv3_ext_subproto_req_set_proto_version(proto_req, + PROTOVER_RELAY_CELL_PROTO); + trn_ntorv3_ext_subproto_add_reqs(req, proto_req); + } /* Encoding into an extension field. */ ret = trn_ntorv3_ext_subproto_encoded_len(req);