[tor-dev] [PATCH 2/2] New option LocalOutboundBindAddress: whitespace changes only

Andrew Cady d at jerkface.net
Tue Nov 27 01:00:41 UTC 2012


---
 src/or/config.c     |   88 +++++++++++++++++++++++++--------------------------
 src/or/connection.c |   60 +++++++++++++++++------------------
 2 files changed, 73 insertions(+), 75 deletions(-)

diff --git a/src/or/config.c b/src/or/config.c
index 03e07f9..12f4f79 100644
--- a/src/or/config.c
+++ b/src/or/config.c
@@ -5557,55 +5557,55 @@ getinfo_helper_config(control_connection_t *conn,
 static int
 parse_outbound_addresses(or_options_t *options, int validate_only, char **msg)
 {
- int i;
- for (i=0; i<2; ++i) {
+  int i;
+  for (i=0; i<2; ++i) {
 
-  tor_addr_t *out4 = i ? &options->OutboundBindAddressIPv4_ : &options->LocalOutboundBindAddressIPv4_;
-  tor_addr_t *out6 = i ? &options->OutboundBindAddressIPv6_ : &options->LocalOutboundBindAddressIPv6_;
+    tor_addr_t *out4 = i ? &options->OutboundBindAddressIPv4_ : &options->LocalOutboundBindAddressIPv4_;
+    tor_addr_t *out6 = i ? &options->OutboundBindAddressIPv6_ : &options->LocalOutboundBindAddressIPv6_;
 
-  if (!validate_only) {
-    memset(out4, 0, sizeof(*out4));
-    memset(out6, 0, sizeof(*out6));
-  }
-
-  const config_line_t *lines = i ? options->OutboundBindAddress : options->LocalOutboundBindAddress;
-  int found_v4 = 0, found_v6 = 0;
-
-  while (lines) {
-    tor_addr_t addr, *dst_addr = NULL;
-    int af = tor_addr_parse(&addr, lines->value);
-    switch (af) {
-    case AF_INET:
-      if (found_v4) {
-        if (msg)
-          tor_asprintf(msg, "Multiple IPv4 outbound bind addresses "
-                       "configured: %s", lines->value);
-        return -1;
-      }
-      found_v4 = 1;
-      dst_addr = out4;
-      break;
-    case AF_INET6:
-      if (found_v6) {
-        if (msg)
-          tor_asprintf(msg, "Multiple IPv6 outbound bind addresses "
-                       "configured: %s", lines->value);
-        return -1;
+    if (!validate_only) {
+      memset(out4, 0, sizeof(*out4));
+      memset(out6, 0, sizeof(*out6));
+    }
+
+    const config_line_t *lines = i ? options->OutboundBindAddress : options->LocalOutboundBindAddress;
+    int found_v4 = 0, found_v6 = 0;
+
+    while (lines) {
+      tor_addr_t addr, *dst_addr = NULL;
+      int af = tor_addr_parse(&addr, lines->value);
+      switch (af) {
+      case AF_INET:
+	if (found_v4) {
+	  if (msg)
+	    tor_asprintf(msg, "Multiple IPv4 outbound bind addresses "
+			 "configured: %s", lines->value);
+	  return -1;
+	}
+	found_v4 = 1;
+	dst_addr = out4;
+	break;
+      case AF_INET6:
+	if (found_v6) {
+	  if (msg)
+	    tor_asprintf(msg, "Multiple IPv6 outbound bind addresses "
+			 "configured: %s", lines->value);
+	  return -1;
+	}
+	found_v6 = 1;
+	dst_addr = out6;
+	break;
+      default:
+	if (msg)
+	  tor_asprintf(msg, "Outbound bind address '%s' didn't parse.",
+		       lines->value);
+	return -1;
       }
-      found_v6 = 1;
-      dst_addr = out6;
-      break;
-    default:
-      if (msg)
-        tor_asprintf(msg, "Outbound bind address '%s' didn't parse.",
-                     lines->value);
-      return -1;
+      if (!validate_only)
+	tor_addr_copy(dst_addr, &addr);
+      lines = lines->next;
     }
-    if (!validate_only)
-      tor_addr_copy(dst_addr, &addr);
-    lines = lines->next;
   }
- }
  return 0;
 }
 
diff --git a/src/or/connection.c b/src/or/connection.c
index 397a2dc..021f7ab 100644
--- a/src/or/connection.c
+++ b/src/or/connection.c
@@ -1451,37 +1451,35 @@ connection_connect(connection_t *conn, const char *address,
 
   make_socket_reuseable(s);
 
-  {
-    const int is_local = tor_addr_is_loopback(addr);
-    const tor_addr_t *ext_addr = NULL;
-    const tor_addr_t *maybe_ext_addr4 = is_local ? &options->LocalOutboundBindAddressIPv4_ : &options->OutboundBindAddressIPv4_;
-    const tor_addr_t *maybe_ext_addr6 = is_local ? &options->LocalOutboundBindAddressIPv6_ : &options->OutboundBindAddressIPv6_;
-
-    if (protocol_family == AF_INET && !tor_addr_is_null(maybe_ext_addr4))
-      ext_addr = maybe_ext_addr4;
-    else if (protocol_family == AF_INET6 && !tor_addr_is_null(maybe_ext_addr6))
-      ext_addr = maybe_ext_addr6;
-
-    if (ext_addr) {
-      struct sockaddr_storage ext_addr_sa;
-      socklen_t ext_addr_len = 0;
-      memset(&ext_addr_sa, 0, sizeof(ext_addr_sa));
-      ext_addr_len = tor_addr_to_sockaddr(ext_addr, 0,
-                                          (struct sockaddr *) &ext_addr_sa,
-                                          sizeof(ext_addr_sa));
-      if (ext_addr_len == 0) {
-        log_warn(LD_NET,
-                 "Error converting OutboundBindAddress %s into sockaddr. "
-                 "Ignoring.", fmt_and_decorate_addr(ext_addr));
-      } else {
-        if (bind(s, (struct sockaddr *) &ext_addr_sa, ext_addr_len) < 0) {
-          *socket_error = tor_socket_errno(s);
-          log_warn(LD_NET,"Error binding network socket to %s: %s",
-                   fmt_and_decorate_addr(ext_addr),
-                   tor_socket_strerror(*socket_error));
-          tor_close_socket(s);
-          return -1;
-        }
+  const int is_local = tor_addr_is_loopback(addr);
+  const tor_addr_t *ext_addr = NULL;
+  const tor_addr_t *maybe_ext_addr4 = is_local ? &options->LocalOutboundBindAddressIPv4_ : &options->OutboundBindAddressIPv4_;
+  const tor_addr_t *maybe_ext_addr6 = is_local ? &options->LocalOutboundBindAddressIPv6_ : &options->OutboundBindAddressIPv6_;
+
+  if (protocol_family == AF_INET && !tor_addr_is_null(maybe_ext_addr4))
+    ext_addr = maybe_ext_addr4;
+  else if (protocol_family == AF_INET6 && !tor_addr_is_null(maybe_ext_addr6))
+    ext_addr = maybe_ext_addr6;
+
+  if (ext_addr) {
+    struct sockaddr_storage ext_addr_sa;
+    socklen_t ext_addr_len = 0;
+    memset(&ext_addr_sa, 0, sizeof(ext_addr_sa));
+    ext_addr_len = tor_addr_to_sockaddr(ext_addr, 0,
+					(struct sockaddr *) &ext_addr_sa,
+					sizeof(ext_addr_sa));
+    if (ext_addr_len == 0) {
+      log_warn(LD_NET,
+	       "Error converting OutboundBindAddress %s into sockaddr. "
+	       "Ignoring.", fmt_and_decorate_addr(ext_addr));
+    } else {
+      if (bind(s, (struct sockaddr *) &ext_addr_sa, ext_addr_len) < 0) {
+	*socket_error = tor_socket_errno(s);
+	log_warn(LD_NET,"Error binding network socket to %s: %s",
+		 fmt_and_decorate_addr(ext_addr),
+		 tor_socket_strerror(*socket_error));
+	tor_close_socket(s);
+	return -1;
       }
     }
   }
-- 
1.7.10.4



More information about the tor-dev mailing list