Commit 81d312f1 authored by Nick Mathewson's avatar Nick Mathewson 🤹
Browse files

Add a function for comparing the orport on an extendinfo.

parent 8f362b7b
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -63,10 +63,10 @@
#include "trunnel/channelpadding_negotiation.h"
#include "trunnel/netinfo.h"
#include "core/or/channelpadding.h"
#include "core/or/extendinfo.h"

#include "core/or/cell_st.h"
#include "core/or/cell_queue_st.h"
#include "core/or/extend_info_st.h"
#include "core/or/or_connection_st.h"
#include "core/or/or_handshake_certs_st.h"
#include "core/or/or_handshake_state_st.h"
@@ -702,9 +702,9 @@ channel_tls_matches_extend_info_method(channel_t *chan,
    return 0;
  }

  return (tor_addr_eq(&(extend_info->addr),
                      &(TO_CONN(tlschan->conn)->addr)) &&
         (extend_info->port == TO_CONN(tlschan->conn)->port));
  return extend_info_has_orport(extend_info,
                                &TO_CONN(tlschan->conn)->addr,
                                TO_CONN(tlschan->conn)->port);
}

/**
+2 −2
Original line number Diff line number Diff line
@@ -203,8 +203,8 @@ circuit_is_acceptable(const origin_circuit_t *origin_circ,
          const int family = tor_addr_parse(&addr,
                                            conn->socks_request->address);
          if (family < 0 ||
              !tor_addr_eq(&build_state->chosen_exit->addr, &addr) ||
              build_state->chosen_exit->port != conn->socks_request->port)
              !extend_info_has_orport(build_state->chosen_exit, &addr,
                                      conn->socks_request->port))
            return 0;
        }
      }
+3 −2
Original line number Diff line number Diff line
@@ -70,6 +70,7 @@
#include "core/or/circuitpadding.h"
#include "core/or/connection_edge.h"
#include "core/or/connection_or.h"
#include "core/or/extendinfo.h"
#include "core/or/policies.h"
#include "core/or/reasons.h"
#include "core/or/relay.h"
@@ -1444,8 +1445,8 @@ connection_ap_fail_onehop(const char *failed_digest,
        continue;
      }
      if (tor_addr_parse(&addr, entry_conn->socks_request->address)<0 ||
          !tor_addr_eq(&build_state->chosen_exit->addr, &addr) ||
          build_state->chosen_exit->port != entry_conn->socks_request->port)
          !extend_info_has_orport(build_state->chosen_exit, &addr,
                                  entry_conn->socks_request->port))
        continue;
    }
    log_info(LD_APP, "Closing one-hop stream to '%s/%s' because the OR conn "
+13 −0
Original line number Diff line number Diff line
@@ -207,3 +207,16 @@ extend_info_addr_is_allowed(const tor_addr_t *addr)
 disallow:
  return 0;
}

/**
 * Return true if @a addr : @a port is a listed ORPort in @a ei.
 **/
bool
extend_info_has_orport(const extend_info_t *ei,
                       const tor_addr_t *addr, uint16_t port)
{
  IF_BUG_ONCE(ei == NULL)
    return false;

  return tor_addr_eq(&ei->addr, addr) && ei->port == port;
}
+2 −0
Original line number Diff line number Diff line
@@ -27,5 +27,7 @@ int extend_info_addr_is_allowed(const tor_addr_t *addr);
int extend_info_supports_tap(const extend_info_t* ei);
int extend_info_supports_ntor(const extend_info_t* ei);
int extend_info_has_preferred_onion_key(const extend_info_t* ei);
bool extend_info_has_orport(const extend_info_t *ei,
                            const tor_addr_t *addr, uint16_t port);

#endif /* !defined(TOR_CORE_OR_EXTENDINFO_H) */