]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
prop340: Put in subproto request for RelayCell=1
authorDavid Goulet <dgoulet@torproject.org>
Thu, 24 Aug 2023 18:33:59 +0000 (14:33 -0400)
committerDavid Goulet <dgoulet@torproject.org>
Wed, 31 Jan 2024 15:16:02 +0000 (10:16 -0500)
Related #40791

Signed-off-by: David Goulet <dgoulet@torproject.org>
src/core/crypto/onion_crypto.c
src/core/crypto/onion_crypto.h
src/core/mainloop/cpuworker.c
src/core/or/extend_info_st.h
src/core/or/extendinfo.c
src/core/or/protover.c

index 8507f9f1639a75d24728679b2e5362d9257639e3..0668681bf3924eef0c0d67e77a4696179883c3f8 100644 (file)
@@ -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
index 233df9a1a010481f83558d60952356915bed3e7d..6b3413f274a8a302152762c9c2733cd060b1b171 100644 (file)
@@ -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;
 
 /**
index a42dbb528d59ea20bccaba100283e58d44903063..294560dc75058da4da6518e9aa3c89adf4585f4c 100644 (file)
@@ -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;
index 44edadaf17b678f61f39b56abfd2f4e27ff0ee4e..c7653b2cbac88d4c01492e35829fc6a47dcdac6c 100644 (file)
@@ -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) */
index 66b01c8788fb381d49aee3d0bdc50c02075983f9..f98d7bd052abc9337f7e3a40ac87a8f1fb3e7dae 100644 (file)
@@ -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) {
index 1eef2b8f7ea0a4bca459cf7720f482ed269b488f..b084cb5f3661eb1c90e8309c05e21b59a610f78a 100644 (file)
@@ -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);