[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [tor/master] Add a function for comparing the orport on an extendinfo.
commit 81d312f12c196a87f6fb0a4ba7c445afe95b6d4a
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date: Tue Jun 30 15:45:02 2020 -0400
Add a function for comparing the orport on an extendinfo.
---
src/core/or/channeltls.c | 8 ++++----
src/core/or/circuituse.c | 4 ++--
src/core/or/connection_edge.c | 5 +++--
src/core/or/extendinfo.c | 13 +++++++++++++
src/core/or/extendinfo.h | 2 ++
5 files changed, 24 insertions(+), 8 deletions(-)
diff --git a/src/core/or/channeltls.c b/src/core/or/channeltls.c
index f9937ce88..a51fbf1dd 100644
--- a/src/core/or/channeltls.c
+++ b/src/core/or/channeltls.c
@@ -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);
}
/**
diff --git a/src/core/or/circuituse.c b/src/core/or/circuituse.c
index 0704f8521..6ff308dae 100644
--- a/src/core/or/circuituse.c
+++ b/src/core/or/circuituse.c
@@ -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;
}
}
diff --git a/src/core/or/connection_edge.c b/src/core/or/connection_edge.c
index fc77db833..2826a9924 100644
--- a/src/core/or/connection_edge.c
+++ b/src/core/or/connection_edge.c
@@ -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 "
diff --git a/src/core/or/extendinfo.c b/src/core/or/extendinfo.c
index 74d4a54a3..874a0a58f 100644
--- a/src/core/or/extendinfo.c
+++ b/src/core/or/extendinfo.c
@@ -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;
+}
diff --git a/src/core/or/extendinfo.h b/src/core/or/extendinfo.h
index 1e542efe2..6ebacccf1 100644
--- a/src/core/or/extendinfo.h
+++ b/src/core/or/extendinfo.h
@@ -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) */
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits