Commit c9b674d5 authored by teor's avatar teor
Browse files

relay: Protocol warn when a client gets an extend

circuit_extend() may be called when a client receives an extend cell,
even if the relay module is disabled.

Log a protocol warning when the relay module is disabled.

Part of 33633.
parent f863954f
Loading
Loading
Loading
Loading
+7 −11
Original line number Original line Diff line number Diff line
@@ -39,11 +39,8 @@
#include "feature/relay/routermode.h"
#include "feature/relay/routermode.h"
#include "feature/relay/selftest.h"
#include "feature/relay/selftest.h"


/** Take the 'extend' <b>cell</b>, pull out addr/port plus the onion
/* Before replying to an extend cell, check the state of the circuit
 * skin and identity digest for the next hop. If we're already connected,
 * <b>circ</b>, and the configured tor mode.
 * pass the onion skin to the next hop using a create cell; otherwise
 * launch a new OR connection, and <b>circ</b> will notice when the
 * connection succeeds or fails.
 *
 *
 * Return -1 if we want to warn and tear down the circuit, else return 0.
 * Return -1 if we want to warn and tear down the circuit, else return 0.
 */
 */
@@ -56,6 +53,11 @@ circuit_extend(struct cell_t *cell, struct circuit_t *circ)
  const char *msg = NULL;
  const char *msg = NULL;
  int should_launch = 0;
  int should_launch = 0;


  if (!server_mode(get_options())) {
    circuitbuild_warn_client_extend();
    return -1;
  }

  if (circ->n_chan) {
  if (circ->n_chan) {
    log_fn(LOG_PROTOCOL_WARN, LD_PROTOCOL,
    log_fn(LOG_PROTOCOL_WARN, LD_PROTOCOL,
           "n_chan already set. Bug/attack. Closing.");
           "n_chan already set. Bug/attack. Closing.");
@@ -67,12 +69,6 @@ circuit_extend(struct cell_t *cell, struct circuit_t *circ)
    return -1;
    return -1;
  }
  }


  if (!server_mode(get_options())) {
    log_fn(LOG_PROTOCOL_WARN, LD_PROTOCOL,
           "Got an extend cell, but running as a client. Closing.");
    return -1;
  }

  relay_header_unpack(&rh, cell->payload);
  relay_header_unpack(&rh, cell->payload);


  if (extend_cell_parse(&ec, rh.command,
  if (extend_cell_parse(&ec, rh.command,
+12 −1
Original line number Original line Diff line number Diff line
@@ -13,6 +13,9 @@
#define TOR_FEATURE_RELAY_CIRCUITBUILD_RELAY_H
#define TOR_FEATURE_RELAY_CIRCUITBUILD_RELAY_H


#include "lib/cc/torint.h"
#include "lib/cc/torint.h"
#include "lib/log/log.h"

#include "app/config/config.h"


struct cell_t;
struct cell_t;
struct created_cell_t;
struct created_cell_t;
@@ -20,6 +23,14 @@ struct created_cell_t;
struct circuit_t;
struct circuit_t;
struct or_circuit_t;
struct or_circuit_t;


/* Log a protocol warning about getting an extend cell on a client. */
static inline void
circuitbuild_warn_client_extend(void)
{
  log_fn(LOG_PROTOCOL_WARN, LD_PROTOCOL,
         "Got an extend cell, but running as a client. Closing.");
}

#ifdef HAVE_MODULE_RELAY
#ifdef HAVE_MODULE_RELAY


int circuit_extend(struct cell_t *cell, struct circuit_t *circ);
int circuit_extend(struct cell_t *cell, struct circuit_t *circ);
@@ -36,7 +47,7 @@ circuit_extend(struct cell_t *cell, struct circuit_t *circ)
{
{
  (void)cell;
  (void)cell;
  (void)circ;
  (void)circ;
  tor_assert_nonfatal_unreached();
  circuitbuild_warn_client_extend();
  return -1;
  return -1;
}
}