Browse Source

when an exit node gets a malformed begin cell, don't complain to
the node operator, since he can't do anything about it.


svn:r6733

Roger Dingledine 18 years ago
parent
commit
fad85f173a
8 changed files with 33 additions and 29 deletions
  1. 7 7
      src/common/util.c
  2. 2 2
      src/common/util.h
  3. 6 6
      src/or/config.c
  4. 2 2
      src/or/connection.c
  5. 8 5
      src/or/connection_edge.c
  6. 1 1
      src/or/rendservice.c
  7. 6 5
      src/or/test.c
  8. 1 1
      src/tools/tor-resolve.c

+ 7 - 7
src/common/util.c

@@ -1486,8 +1486,8 @@ is_local_IP(uint32_t ip)
  * Return 0 on success, -1 on failure.
  */
 int
-parse_addr_port(const char *addrport, char **address, uint32_t *addr,
-                uint16_t *port_out)
+parse_addr_port(int severity, const char *addrport, char **address,
+                uint32_t *addr, uint16_t *port_out)
 {
   const char *colon;
   char *_address = NULL;
@@ -1501,14 +1501,14 @@ parse_addr_port(const char *addrport, char **address, uint32_t *addr,
     _address = tor_strndup(addrport, colon-addrport);
     _port = (int) tor_parse_long(colon+1,10,1,65535,NULL,NULL);
     if (!_port) {
-      log_warn(LD_GENERAL, "Port %s out of range", escaped(colon+1));
+      log_fn(severity, LD_GENERAL, "Port %s out of range", escaped(colon+1));
       ok = 0;
     }
     if (!port_out) {
       char *esc_addrport = esc_for_log(addrport);
-      log_warn(LD_GENERAL,
-               "Port %s given on %s when not required",
-               escaped(colon+1), esc_addrport);
+      log_fn(severity, LD_GENERAL,
+             "Port %s given on %s when not required",
+             escaped(colon+1), esc_addrport);
       tor_free(esc_addrport);
       ok = 0;
     }
@@ -1520,7 +1520,7 @@ parse_addr_port(const char *addrport, char **address, uint32_t *addr,
   if (addr) {
     /* There's an addr pointer, so we need to resolve the hostname. */
     if (tor_lookup_hostname(_address,addr)) {
-      log_warn(LD_NET, "Couldn't look up %s", escaped(_address));
+      log_fn(severity, LD_NET, "Couldn't look up %s", escaped(_address));
       ok = 0;
       *addr = 0;
     }

+ 2 - 2
src/common/util.h

@@ -168,8 +168,8 @@ int path_is_relative(const char *filename);
 /* Net helpers */
 int is_internal_IP(uint32_t ip, int for_listening);
 int is_local_IP(uint32_t ip);
-int parse_addr_port(const char *addrport, char **address, uint32_t *addr,
-                    uint16_t *port);
+int parse_addr_port(int severity, const char *addrport, char **address,
+                    uint32_t *addr, uint16_t *port_out);
 int parse_port_range(const char *port, uint16_t *port_min_out,
                      uint16_t *port_max_out);
 int parse_addr_and_port_range(const char *s, uint32_t *addr_out,

+ 6 - 6
src/or/config.c

@@ -2040,7 +2040,7 @@ options_validate(or_options_t *old_options, or_options_t *options,
     for (line = options->SocksListenAddress; line; line = line->next) {
       uint16_t port;
       uint32_t addr;
-      if (parse_addr_port(line->value, &address, &addr, &port)<0)
+      if (parse_addr_port(LOG_WARN, line->value, &address, &addr, &port)<0)
         continue; /* We'll warn about this later. */
       if (!is_internal_IP(addr, 1) &&
           (!old_options || !config_lines_eq(old_options->SocksListenAddress,
@@ -2338,7 +2338,7 @@ options_validate(or_options_t *old_options, or_options_t *options,
     REJECT("Failed to parse accounting options. See logs for details.");
 
   if (options->HttpProxy) { /* parse it now */
-    if (parse_addr_port(options->HttpProxy, NULL,
+    if (parse_addr_port(LOG_WARN, options->HttpProxy, NULL,
                         &options->HttpProxyAddr, &options->HttpProxyPort) < 0)
       REJECT("HttpProxy failed to parse or resolve. Please fix.");
     if (options->HttpProxyPort == 0) { /* give it a default */
@@ -2352,7 +2352,7 @@ options_validate(or_options_t *old_options, or_options_t *options,
   }
 
   if (options->HttpsProxy) { /* parse it now */
-    if (parse_addr_port(options->HttpsProxy, NULL,
+    if (parse_addr_port(LOG_WARN, options->HttpsProxy, NULL,
                         &options->HttpsProxyAddr, &options->HttpsProxyPort) <0)
       REJECT("HttpsProxy failed to parse or resolve. Please fix.");
     if (options->HttpsProxyPort == 0) { /* give it a default */
@@ -3127,8 +3127,8 @@ parse_redirect_line(smartlist_t *result, config_line_t *line, char **msg)
   if (0==strcasecmp(smartlist_get(elements,1), "pass")) {
     r->is_redirect = 0;
   } else {
-    if (parse_addr_port(smartlist_get(elements,1),NULL,&r->addr_dest,
-                             &r->port_dest)) {
+    if (parse_addr_port(LOG_WARN, smartlist_get(elements,1),NULL,
+                        &r->addr_dest, &r->port_dest)) {
       *msg = tor_strdup("Error parsing dest address in RedirectExit line");
       goto err;
     }
@@ -3193,7 +3193,7 @@ parse_dir_server_line(const char *line, int validate_only)
     goto err;
   }
   addrport = smartlist_get(items, 0);
-  if (parse_addr_port(addrport, &address, NULL, &port)<0) {
+  if (parse_addr_port(LOG_WARN, addrport, &address, NULL, &port)<0) {
     log_warn(LD_CONFIG, "Error parsing DirServer address '%s'", addrport);
     goto err;
   }

+ 2 - 2
src/or/connection.c

@@ -522,7 +522,7 @@ connection_create_listener(const char *listenaddress, uint16_t listenport,
 #endif
 
   memset(&listenaddr,0,sizeof(struct sockaddr_in));
-  if (parse_addr_port(listenaddress, &address, &addr, &usePort)<0) {
+  if (parse_addr_port(LOG_WARN, listenaddress, &address, &addr, &usePort)<0) {
     log_warn(LD_CONFIG,
              "Error parsing/resolving ListenAddress %s", listenaddress);
     return NULL;
@@ -893,7 +893,7 @@ retry_listeners(int type, config_line_t *cfg,
       {
         char *address=NULL;
         uint16_t port;
-        if (! parse_addr_port(wanted->value, &address, NULL, &port)) {
+        if (!parse_addr_port(LOG_WARN, wanted->value, &address, NULL, &port)) {
           int addr_matches = !strcasecmp(address, conn->address);
           tor_free(address);
           if (! port)

+ 8 - 5
src/or/connection_edge.c

@@ -1587,16 +1587,19 @@ connection_exit_begin_conn(cell_t *cell, circuit_t *circ)
    */
 
   if (!memchr(cell->payload+RELAY_HEADER_SIZE, 0, rh.length)) {
-    log_warn(LD_PROTOCOL,"relay begin cell has no \\0. Dropping.");
+    log_fn(LOG_PROTOCOL_WARN, LD_PROTOCOL,
+           "Relay begin cell has no \\0. Dropping.");
     return 0;
   }
-  if (parse_addr_port(cell->payload+RELAY_HEADER_SIZE,&address,NULL,&port)<0) {
-    log_warn(LD_PROTOCOL,"Unable to parse addr:port in relay begin cell. "
-             "Dropping.");
+  if (parse_addr_port(LOG_PROTOCOL_WARN, cell->payload+RELAY_HEADER_SIZE,
+                      &address,NULL,&port)<0) {
+    log_fn(LOG_PROTOCOL_WARN, LD_PROTOCOL,
+           "Unable to parse addr:port in relay begin cell. Dropping.");
     return 0;
   }
   if (port==0) {
-    log_warn(LD_PROTOCOL,"Missing port in relay begin cell. Dropping.");
+    log_fn(LOG_PROTOCOL_WARN, LD_PROTOCOL,
+           "Missing port in relay begin cell. Dropping.");
     tor_free(address);
     return 0;
   }

+ 1 - 1
src/or/rendservice.c

@@ -179,7 +179,7 @@ parse_port_config(const char *string)
   } else {
     addrport = smartlist_get(sl,1);
     if (strchr(addrport, ':') || strchr(addrport, '.')) {
-      if (parse_addr_port(addrport, NULL, &addr, &p)<0) {
+      if (parse_addr_port(LOG_WARN, addrport, NULL, &addr, &p)<0) {
         log_warn(LD_CONFIG,"Unparseable address in hidden service port "
                  "configuration.");
         goto err;

+ 6 - 5
src/or/test.c

@@ -807,27 +807,28 @@ test_util(void)
 
   /* Test parse_addr_port */
   cp = NULL; u32 = 3; u16 = 3;
-  test_assert(!parse_addr_port("1.2.3.4", &cp, &u32, &u16));
+  test_assert(!parse_addr_port(LOG_WARN, "1.2.3.4", &cp, &u32, &u16));
   test_streq(cp, "1.2.3.4");
   test_eq(u32, 0x01020304u);
   test_eq(u16, 0);
   tor_free(cp);
-  test_assert(!parse_addr_port("4.3.2.1:99", &cp, &u32, &u16));
+  test_assert(!parse_addr_port(LOG_WARN, "4.3.2.1:99", &cp, &u32, &u16));
   test_streq(cp, "4.3.2.1");
   test_eq(u32, 0x04030201u);
   test_eq(u16, 99);
   tor_free(cp);
-  test_assert(!parse_addr_port("nonexistent.address:4040", &cp, NULL, &u16));
+  test_assert(!parse_addr_port(LOG_WARN, "nonexistent.address:4040",
+                               &cp, NULL, &u16));
   test_streq(cp, "nonexistent.address");
   test_eq(u16, 4040);
   tor_free(cp);
-  test_assert(!parse_addr_port("localhost:9999", &cp, &u32, &u16));
+  test_assert(!parse_addr_port(LOG_WARN, "localhost:9999", &cp, &u32, &u16));
   test_streq(cp, "localhost");
   test_eq(u32, 0x7f000001u);
   test_eq(u16, 9999);
   tor_free(cp);
   u32 = 3;
-  test_assert(!parse_addr_port("localhost", NULL, &u32, &u16));
+  test_assert(!parse_addr_port(LOG_WARN, "localhost", NULL, &u32, &u16));
   test_eq(cp, NULL);
   test_eq(u32, 0x7f000001u);
   test_eq(u16, 0);

+ 1 - 1
src/tools/tor-resolve.c

@@ -217,7 +217,7 @@ main(int argc, char **argv)
     sockshost = 0x7f000001u; /* localhost */
     socksport = 9050; /* 9050 */
   } else if (n_args == 2) {
-    if (parse_addr_port(arg[1], NULL, &sockshost, &socksport)<0) {
+    if (parse_addr_port(LOG_WARN, arg[1], NULL, &sockshost, &socksport)<0) {
       fprintf(stderr, "Couldn't parse/resolve address %s", arg[1]);
       return 1;
     }