From: rl1987 Date: Mon, 7 May 2018 12:26:27 +0000 (+0200) Subject: Minor code cleanups X-Git-Tag: tor-0.3.5.1-alpha~47^2~9 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=74a474a2e78fdc977372cccfde37a2e92694f2df;p=thirdparty%2Ftor.git Minor code cleanups --- diff --git a/src/core/mainloop/connection.c b/src/core/mainloop/connection.c index a32e3b4f27..200ea42433 100644 --- a/src/core/mainloop/connection.c +++ b/src/core/mainloop/connection.c @@ -1213,7 +1213,8 @@ connection_listener_new(const struct sockaddr *listensockaddr, tor_addr_t addr; int exhaustion = 0; - if (addr_in_use) *addr_in_use = 0; + if (addr_in_use) + *addr_in_use = 0; if (listensockaddr->sa_family == AF_INET || listensockaddr->sa_family == AF_INET6) { @@ -1295,7 +1296,8 @@ connection_listener_new(const struct sockaddr *listensockaddr, int e = tor_socket_errno(s); if (ERRNO_IS_EADDRINUSE(e)) { helpfulhint = ". Is Tor already running?"; - if (addr_in_use) *addr_in_use = 1; + if (addr_in_use) + *addr_in_use = 1; } log_warn(LD_NET, "Could not bind to %s:%u: %s%s", address, usePort, tor_socket_strerror(e), helpfulhint); @@ -1523,7 +1525,8 @@ connection_listener_new_for_port(const port_cfg_t *port, *defer = 0; if (port->server_cfg.no_listen) { - if (defer) *defer = 1; + if (defer) + *defer = 1; return NULL; } @@ -1533,7 +1536,8 @@ connection_listener_new_for_port(const port_cfg_t *port, const or_options_t *options = get_options(); if (port->is_unix_addr && !geteuid() && (options->User) && strcmp(options->User, "root")) { - if (defer) *defer = 1; + if (defer) + *defer = 1; return NULL; } #endif /* !defined(_WIN32) */ @@ -2674,12 +2678,6 @@ connection_read_proxy_handshake(connection_t *conn) return ret; } -struct replacement_s -{ - connection_t *old_conn; - port_cfg_t *new_port; -}; - /** Given a list of listener connections in old_conns, and list of * port_cfg_t entries in ports, open a new listener for every port in * ports that does not already have a listener in old_conns. @@ -2687,8 +2685,8 @@ struct replacement_s * Remove from old_conns every connection that has a corresponding * entry in ports. Add to new_conns new every connection we * launch. If we may need to perform socket rebind when creating new - * listener that replaces old one, create a replacement_s struct - * for affected pair and add it to replacements. For more + * listener that replaces old one, create a listener_replacement_t + * struct for affected pair and add it to replacements. For more * information, see ticket #17873. * * If control_listeners_only is true, then we only open control @@ -2760,11 +2758,11 @@ retry_listener_ports(smartlist_t *old_conns, port_matches_exact && bool_neq(tor_addr_is_null(&wanted->addr), tor_addr_is_null(&conn->addr)); if (replacements && may_need_rebind) { - struct replacement_s *replacement = - tor_malloc(sizeof(struct replacement_s)); + listener_replacement_t *replacement = + tor_malloc(sizeof(listener_replacement_t)); replacement->old_conn = conn; - replacement->new_port = (port_cfg_t *)wanted; + replacement->new_port = wanted; smartlist_add(replacements, replacement); SMARTLIST_DEL_CURRENT(launch, wanted); @@ -2834,7 +2832,7 @@ retry_all_listeners(smartlist_t *new_conns, int close_all_noncontrol) retval = -1; #ifdef ENABLE_LISTENER_REBIND - SMARTLIST_FOREACH_BEGIN(replacements, struct replacement_s *, r) { + SMARTLIST_FOREACH_BEGIN(replacements, listener_replacement_t *, r) { int addr_in_use = 0; int skip = 0; diff --git a/src/core/mainloop/connection.h b/src/core/mainloop/connection.h index 2552808fd8..b569bb038e 100644 --- a/src/core/mainloop/connection.h +++ b/src/core/mainloop/connection.h @@ -81,6 +81,17 @@ struct buf_t; /** State for any listener connection. */ #define LISTENER_STATE_READY 0 +/** + * This struct associates an old listener connection to be replaced + * by new connection described by port configuration. Only used when + * moving listeners to/from wildcard IP address. + */ +typedef struct +{ + connection_t *old_conn; /* Old listener connection to be replaced */ + const port_cfg_t *new_port; /* New port configuration */ +} listener_replacement_t; + const char *conn_type_to_string(int type); const char *conn_state_to_string(int type, int state); int conn_listener_type_supports_af_unix(int type);