mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2025-02-24 22:58:50 +01:00
Combine entry_port_cfg_t fields in listener_connection_t
Also, revise the code using these options with this cocci script: @@ listener_connection_t *conn; @@ conn-> +entry_cfg. \( isolation_flags \| session_group \| socks_prefer_no_auth \| ipv4_traffic \| ipv6_traffic \| prefer_ipv6 \| cache_ipv4_answers \| cache_ipv6_answers \| use_cached_ipv4_answers \| use_cached_ipv6_answers \| prefer_ipv6_virtaddr \)
This commit is contained in:
parent
f444f2b1d3
commit
58d17add5e
3 changed files with 73 additions and 118 deletions
|
@ -1199,9 +1199,9 @@ connection_listener_new(const struct sockaddr *listensockaddr,
|
|||
tor_addr_copy(&conn->addr, &addr);
|
||||
|
||||
if (port_cfg->entry_cfg.isolation_flags) {
|
||||
lis_conn->isolation_flags = port_cfg->entry_cfg.isolation_flags;
|
||||
lis_conn->entry_cfg.isolation_flags = port_cfg->entry_cfg.isolation_flags;
|
||||
if (port_cfg->entry_cfg.session_group >= 0) {
|
||||
lis_conn->session_group = port_cfg->entry_cfg.session_group;
|
||||
lis_conn->entry_cfg.session_group = port_cfg->entry_cfg.session_group;
|
||||
} else {
|
||||
/* This can wrap after around INT_MAX listeners are opened. But I don't
|
||||
* believe that matters, since you would need to open a ridiculous
|
||||
|
@ -1209,23 +1209,23 @@ connection_listener_new(const struct sockaddr *listensockaddr,
|
|||
* hit this. An OR with a dozen ports open, for example, would have to
|
||||
* close and re-open its listeners every second for 4 years nonstop.
|
||||
*/
|
||||
lis_conn->session_group = global_next_session_group--;
|
||||
lis_conn->entry_cfg.session_group = global_next_session_group--;
|
||||
}
|
||||
}
|
||||
if (type == CONN_TYPE_AP_LISTENER) {
|
||||
lis_conn->socks_ipv4_traffic = port_cfg->entry_cfg.ipv4_traffic;
|
||||
lis_conn->socks_ipv6_traffic = port_cfg->entry_cfg.ipv6_traffic;
|
||||
lis_conn->socks_prefer_ipv6 = port_cfg->entry_cfg.prefer_ipv6;
|
||||
lis_conn->entry_cfg.ipv4_traffic = port_cfg->entry_cfg.ipv4_traffic;
|
||||
lis_conn->entry_cfg.ipv6_traffic = port_cfg->entry_cfg.ipv6_traffic;
|
||||
lis_conn->entry_cfg.prefer_ipv6 = port_cfg->entry_cfg.prefer_ipv6;
|
||||
} else {
|
||||
lis_conn->socks_ipv4_traffic = 1;
|
||||
lis_conn->socks_ipv6_traffic = 1;
|
||||
lis_conn->entry_cfg.ipv4_traffic = 1;
|
||||
lis_conn->entry_cfg.ipv6_traffic = 1;
|
||||
}
|
||||
lis_conn->cache_ipv4_answers = port_cfg->entry_cfg.cache_ipv4_answers;
|
||||
lis_conn->cache_ipv6_answers = port_cfg->entry_cfg.cache_ipv6_answers;
|
||||
lis_conn->use_cached_ipv4_answers = port_cfg->entry_cfg.use_cached_ipv4_answers;
|
||||
lis_conn->use_cached_ipv6_answers = port_cfg->entry_cfg.use_cached_ipv6_answers;
|
||||
lis_conn->prefer_ipv6_virtaddr = port_cfg->entry_cfg.prefer_ipv6_virtaddr;
|
||||
lis_conn->socks_prefer_no_auth = port_cfg->entry_cfg.socks_prefer_no_auth;
|
||||
lis_conn->entry_cfg.cache_ipv4_answers = port_cfg->entry_cfg.cache_ipv4_answers;
|
||||
lis_conn->entry_cfg.cache_ipv6_answers = port_cfg->entry_cfg.cache_ipv6_answers;
|
||||
lis_conn->entry_cfg.use_cached_ipv4_answers = port_cfg->entry_cfg.use_cached_ipv4_answers;
|
||||
lis_conn->entry_cfg.use_cached_ipv6_answers = port_cfg->entry_cfg.use_cached_ipv6_answers;
|
||||
lis_conn->entry_cfg.prefer_ipv6_virtaddr = port_cfg->entry_cfg.prefer_ipv6_virtaddr;
|
||||
lis_conn->entry_cfg.socks_prefer_no_auth = port_cfg->entry_cfg.socks_prefer_no_auth;
|
||||
|
||||
if (connection_add(conn) < 0) { /* no space, forget it */
|
||||
log_warn(LD_NET,"connection_add for listener failed. Giving up.");
|
||||
|
@ -1419,7 +1419,7 @@ connection_handle_listener_read(connection_t *conn, int new_type)
|
|||
|
||||
if (new_type == CONN_TYPE_AP) {
|
||||
TO_ENTRY_CONN(newconn)->socks_request->socks_prefer_no_auth =
|
||||
TO_LISTENER_CONN(conn)->socks_prefer_no_auth;
|
||||
TO_LISTENER_CONN(conn)->entry_cfg.socks_prefer_no_auth;
|
||||
}
|
||||
if (new_type == CONN_TYPE_CONTROL) {
|
||||
log_notice(LD_CONTROL, "New control connection opened from %s.",
|
||||
|
@ -1483,21 +1483,21 @@ connection_init_accepted_conn(connection_t *conn,
|
|||
return rv;
|
||||
break;
|
||||
case CONN_TYPE_AP:
|
||||
TO_ENTRY_CONN(conn)->isolation_flags = listener->isolation_flags;
|
||||
TO_ENTRY_CONN(conn)->session_group = listener->session_group;
|
||||
TO_ENTRY_CONN(conn)->isolation_flags = listener->entry_cfg.isolation_flags;
|
||||
TO_ENTRY_CONN(conn)->session_group = listener->entry_cfg.session_group;
|
||||
TO_ENTRY_CONN(conn)->nym_epoch = get_signewnym_epoch();
|
||||
TO_ENTRY_CONN(conn)->socks_request->listener_type = listener->base_.type;
|
||||
TO_ENTRY_CONN(conn)->ipv4_traffic_ok = listener->socks_ipv4_traffic;
|
||||
TO_ENTRY_CONN(conn)->ipv6_traffic_ok = listener->socks_ipv6_traffic;
|
||||
TO_ENTRY_CONN(conn)->prefer_ipv6_traffic = listener->socks_prefer_ipv6;
|
||||
TO_ENTRY_CONN(conn)->cache_ipv4_answers = listener->cache_ipv4_answers;
|
||||
TO_ENTRY_CONN(conn)->cache_ipv6_answers = listener->cache_ipv6_answers;
|
||||
TO_ENTRY_CONN(conn)->ipv4_traffic_ok = listener->entry_cfg.ipv4_traffic;
|
||||
TO_ENTRY_CONN(conn)->ipv6_traffic_ok = listener->entry_cfg.ipv6_traffic;
|
||||
TO_ENTRY_CONN(conn)->prefer_ipv6_traffic = listener->entry_cfg.prefer_ipv6;
|
||||
TO_ENTRY_CONN(conn)->cache_ipv4_answers = listener->entry_cfg.cache_ipv4_answers;
|
||||
TO_ENTRY_CONN(conn)->cache_ipv6_answers = listener->entry_cfg.cache_ipv6_answers;
|
||||
TO_ENTRY_CONN(conn)->use_cached_ipv4_answers =
|
||||
listener->use_cached_ipv4_answers;
|
||||
listener->entry_cfg.use_cached_ipv4_answers;
|
||||
TO_ENTRY_CONN(conn)->use_cached_ipv6_answers =
|
||||
listener->use_cached_ipv6_answers;
|
||||
listener->entry_cfg.use_cached_ipv6_answers;
|
||||
TO_ENTRY_CONN(conn)->prefer_ipv6_virtaddr =
|
||||
listener->prefer_ipv6_virtaddr;
|
||||
listener->entry_cfg.prefer_ipv6_virtaddr;
|
||||
|
||||
switch (TO_CONN(listener)->type) {
|
||||
case CONN_TYPE_AP_LISTENER:
|
||||
|
|
|
@ -155,8 +155,8 @@ evdns_server_callback(struct evdns_server_request *req, void *data_)
|
|||
|
||||
entry_conn->socks_request->listener_type = listener->base_.type;
|
||||
entry_conn->dns_server_request = req;
|
||||
entry_conn->isolation_flags = listener->isolation_flags;
|
||||
entry_conn->session_group = listener->session_group;
|
||||
entry_conn->isolation_flags = listener->entry_cfg.isolation_flags;
|
||||
entry_conn->session_group = listener->entry_cfg.session_group;
|
||||
entry_conn->nym_epoch = get_signewnym_epoch();
|
||||
|
||||
if (connection_add(ENTRY_TO_CONN(entry_conn)) < 0) {
|
||||
|
|
137
src/or/or.h
137
src/or/or.h
|
@ -1143,6 +1143,51 @@ typedef struct socks_request_t socks_request_t;
|
|||
#define generic_buffer_t buf_t
|
||||
#endif
|
||||
|
||||
typedef struct entry_port_cfg_t {
|
||||
/* Client port types (socks, dns, trans, natd) only: */
|
||||
uint8_t isolation_flags; /**< Zero or more isolation flags */
|
||||
int session_group; /**< A session group, or -1 if this port is not in a
|
||||
* session group. */
|
||||
|
||||
/* Socks only: */
|
||||
/** When both no-auth and user/pass are advertised by a SOCKS client, select
|
||||
* no-auth. */
|
||||
unsigned int socks_prefer_no_auth : 1;
|
||||
|
||||
/* Client port types only: */
|
||||
unsigned int ipv4_traffic : 1;
|
||||
unsigned int ipv6_traffic : 1;
|
||||
unsigned int prefer_ipv6 : 1;
|
||||
|
||||
/** For a socks listener: should we cache IPv4/IPv6 DNS information that
|
||||
* exit nodes tell us?
|
||||
*
|
||||
* @{ */
|
||||
unsigned int cache_ipv4_answers : 1;
|
||||
unsigned int cache_ipv6_answers : 1;
|
||||
/** @} */
|
||||
/** For a socks listeners: if we find an answer in our client-side DNS cache,
|
||||
* should we use it?
|
||||
*
|
||||
* @{ */
|
||||
unsigned int use_cached_ipv4_answers : 1;
|
||||
unsigned int use_cached_ipv6_answers : 1;
|
||||
/** @} */
|
||||
/** For socks listeners: When we can automap an address to IPv4 or IPv6,
|
||||
* do we prefer IPv6? */
|
||||
unsigned int prefer_ipv6_virtaddr : 1;
|
||||
|
||||
} entry_port_cfg_t;
|
||||
|
||||
typedef struct server_port_cfg_t {
|
||||
/* Server port types (or, dir) only: */
|
||||
unsigned int no_advertise : 1;
|
||||
unsigned int no_listen : 1;
|
||||
unsigned int all_addrs : 1;
|
||||
unsigned int bind_ipv4_only : 1;
|
||||
unsigned int bind_ipv6_only : 1;
|
||||
} server_port_cfg_t;
|
||||
|
||||
/* Values for connection_t.magic: used to make sure that downcasts (casts from
|
||||
* connection_t to foo_connection_t) are safe. */
|
||||
#define BASE_CONNECTION_MAGIC 0x7C3C304Eu
|
||||
|
@ -1278,52 +1323,7 @@ typedef struct listener_connection_t {
|
|||
* to the evdns_server_port it uses to listen to and answer connections. */
|
||||
struct evdns_server_port *dns_server_port;
|
||||
|
||||
/** @name Isolation parameters
|
||||
*
|
||||
* For an AP listener, these fields describe how to isolate streams that
|
||||
* arrive on the listener.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
/** The session group for this listener. */
|
||||
int session_group;
|
||||
/** One or more ISO_ flags to describe how to isolate streams. */
|
||||
uint8_t isolation_flags;
|
||||
/**@}*/
|
||||
/** For SOCKS connections only: If this is set, we will choose "no
|
||||
* authentication" instead of "username/password" authentication if both
|
||||
* are offered. Used as input to parse_socks. */
|
||||
unsigned int socks_prefer_no_auth : 1;
|
||||
|
||||
/** For a SOCKS listeners, these fields describe whether we should
|
||||
* allow IPv4 and IPv6 addresses from our exit nodes, respectively.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
unsigned int socks_ipv4_traffic : 1;
|
||||
unsigned int socks_ipv6_traffic : 1;
|
||||
/** @} */
|
||||
/** For a socks listener: should we tell the exit that we prefer IPv6
|
||||
* addresses? */
|
||||
unsigned int socks_prefer_ipv6 : 1;
|
||||
|
||||
/** For a socks listener: should we cache IPv4/IPv6 DNS information that
|
||||
* exit nodes tell us?
|
||||
*
|
||||
* @{ */
|
||||
unsigned int cache_ipv4_answers : 1;
|
||||
unsigned int cache_ipv6_answers : 1;
|
||||
/** @} */
|
||||
/** For a socks listeners: if we find an answer in our client-side DNS cache,
|
||||
* should we use it?
|
||||
*
|
||||
* @{ */
|
||||
unsigned int use_cached_ipv4_answers : 1;
|
||||
unsigned int use_cached_ipv6_answers : 1;
|
||||
/** @} */
|
||||
/** For socks listeners: When we can automap an address to IPv4 or IPv6,
|
||||
* do we prefer IPv6? */
|
||||
unsigned int prefer_ipv6_virtaddr : 1;
|
||||
entry_port_cfg_t entry_cfg;
|
||||
|
||||
} listener_connection_t;
|
||||
|
||||
|
@ -3334,51 +3334,6 @@ typedef enum invalid_router_usage_t {
|
|||
/** First automatically allocated session group number */
|
||||
#define SESSION_GROUP_FIRST_AUTO -4
|
||||
|
||||
typedef struct entry_port_cfg_t {
|
||||
/* Client port types (socks, dns, trans, natd) only: */
|
||||
uint8_t isolation_flags; /**< Zero or more isolation flags */
|
||||
int session_group; /**< A session group, or -1 if this port is not in a
|
||||
* session group. */
|
||||
|
||||
/* Socks only: */
|
||||
/** When both no-auth and user/pass are advertised by a SOCKS client, select
|
||||
* no-auth. */
|
||||
unsigned int socks_prefer_no_auth : 1;
|
||||
|
||||
/* Client port types only: */
|
||||
unsigned int ipv4_traffic : 1;
|
||||
unsigned int ipv6_traffic : 1;
|
||||
unsigned int prefer_ipv6 : 1;
|
||||
|
||||
/** For a socks listener: should we cache IPv4/IPv6 DNS information that
|
||||
* exit nodes tell us?
|
||||
*
|
||||
* @{ */
|
||||
unsigned int cache_ipv4_answers : 1;
|
||||
unsigned int cache_ipv6_answers : 1;
|
||||
/** @} */
|
||||
/** For a socks listeners: if we find an answer in our client-side DNS cache,
|
||||
* should we use it?
|
||||
*
|
||||
* @{ */
|
||||
unsigned int use_cached_ipv4_answers : 1;
|
||||
unsigned int use_cached_ipv6_answers : 1;
|
||||
/** @} */
|
||||
/** For socks listeners: When we can automap an address to IPv4 or IPv6,
|
||||
* do we prefer IPv6? */
|
||||
unsigned int prefer_ipv6_virtaddr : 1;
|
||||
|
||||
} entry_port_cfg_t;
|
||||
|
||||
typedef struct server_port_cfg_t {
|
||||
/* Server port types (or, dir) only: */
|
||||
unsigned int no_advertise : 1;
|
||||
unsigned int no_listen : 1;
|
||||
unsigned int all_addrs : 1;
|
||||
unsigned int bind_ipv4_only : 1;
|
||||
unsigned int bind_ipv6_only : 1;
|
||||
} server_port_cfg_t;
|
||||
|
||||
/** Configuration for a single port that we're listening on. */
|
||||
typedef struct port_cfg_t {
|
||||
tor_addr_t addr; /**< The actual IP to listen on, if !is_unix_addr. */
|
||||
|
|
Loading…
Add table
Reference in a new issue