[or-cvs] Allow private:* in routerdescs; not generated yet (because ...

Nick Mathewson nickm at seul.org
Sun Mar 5 05:28:01 UTC 2006


Update of /home/or/cvsroot/tor/src/or
In directory moria:/tmp/cvs-serv1857/src/or

Modified Files:
	config.c routerparse.c 
Log Message:
Allow private:* in routerdescs; not generated yet (because older Tors do not understand it); needs testing.

Index: config.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/config.c,v
retrieving revision 1.521
retrieving revision 1.522
diff -u -p -d -r1.521 -r1.522
--- config.c	20 Feb 2006 01:21:48 -0000	1.521
+++ config.c	5 Mar 2006 05:27:59 -0000	1.522
@@ -3299,7 +3299,9 @@ config_parse_addr_policy(config_line_t *
           log_warn(LD_CONFIG, "Address policy element '%s' can't be expressed "
                    "as a bit prefix.", ent);
         }
-        nextp = &((*nextp)->next);
+        /* Advance nextp to the end of the policy. */
+        while (*nextp)
+          nextp = &((*nextp)->next);
       } else {
         log_warn(LD_CONFIG,"Malformed policy '%s'.", ent);
         r = -1;

Index: routerparse.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/routerparse.c,v
retrieving revision 1.174
retrieving revision 1.175
diff -u -p -d -r1.174 -r1.175
--- routerparse.c	13 Feb 2006 10:32:59 -0000	1.174
+++ routerparse.c	5 Mar 2006 05:27:59 -0000	1.175
@@ -151,6 +151,8 @@ static struct {
 /* static function prototypes */
 static int router_add_exit_policy(routerinfo_t *router,directory_token_t *tok);
 static addr_policy_t *router_parse_addr_policy(directory_token_t *tok);
+static addr_policy_t *router_parse_private_addr_policy_private(
+                                               directory_token_t *tok);
 static int router_get_hash_impl(const char *s, char *digest,
                                 const char *start_str, const char *end_str);
 static void token_free(directory_token_t *tok);
@@ -1338,6 +1340,9 @@ router_parse_addr_policy(directory_token
     return NULL;
   arg = tok->args[0];
 
+  if (!strcmpstart(arg,"private"))
+    return router_parse_private_addr_policy_private(tok);
+
   newe = tor_malloc_zero(sizeof(addr_policy_t));
 
   newe->string = tor_malloc(8+strlen(arg));
@@ -1370,6 +1375,56 @@ policy_read_failed:
   return NULL;
 }
 
+/** Parse an exit policy line of the format "accept/reject private:...".
+ * This didn't exist until Tor 0.1.1.15, so nobody should generate it in
+ * router descriptors until earlier versions are obsolete.
+ */
+static addr_policy_t *
+router_parse_private_addr_policy_private(directory_token_t *tok)
+{
+  /* XXXX duplicated from config.c */
+  static const char *private_nets[] = {
+    "0.0.0.0/8", "169.254.0.0/16",
+    "127.0.0.0/8", "192.168.0.0/16", "10.0.0.0/8", "172.16.0.0/12",NULL };
+  char *arg;
+  addr_policy_t *result, **nextp;
+  int net;
+  uint16_t port_min, port_max;
+
+  arg = tok->args[0];
+  if (strcmpstart(arg, "private"))
+    return NULL;
+  arg += strlen("private");
+  arg = (char*) eat_whitespace(arg);
+  if (!arg || *arg != ':')
+    return NULL;
+
+  if (parse_port_range(arg+1, &port_min, &port_max)<0)
+    return NULL;
+
+  nextp = &result;
+  for (net = 0; private_nets[net]; ++net) {
+    size_t len;
+    *nextp = tor_malloc_zero(sizeof(addr_policy_t));
+    (*nextp)->policy_type = (tok->tp == K_REJECT) ? ADDR_POLICY_REJECT
+      : ADDR_POLICY_ACCEPT;
+    len = strlen(arg)+strlen(private_nets[net])+16;
+    (*nextp)->string = tor_malloc(len+1);
+    tor_snprintf((*nextp)->string, len, "%s %s%s",
+                 tok->tp == K_REJECT ? "reject" : "accept",
+                 private_nets[net], arg);
+    if (parse_addr_and_port_range((*nextp)->string + 7,
+                                  &(*nextp)->addr, &(*nextp)->msk,
+                                  &(*nextp)->prt_min, &(*nextp)->prt_max)) {
+      log_warn(LD_BUG, "Couldn't parse an address range we generated!");
+      return NULL;
+    }
+    nextp = &(*nextp)->next;
+  }
+
+  return result;
+}
+
 /** Log and exit if <b>t</b> is malformed */
 void
 assert_addr_policy_ok(addr_policy_t *t)



More information about the tor-commits mailing list