[or-cvs] Generate 18.0.0.0/8 address policy format in descs when we ...

Nick Mathewson nickm at seul.org
Sun Feb 12 23:58:25 UTC 2006


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

Modified Files:
	config.c router.c 
Log Message:
Generate 18.0.0.0/8 address policy format in descs when we can; warn when the mask is not reducible to a bit-prefix.

Index: config.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/config.c,v
retrieving revision 1.506
retrieving revision 1.507
diff -u -p -d -r1.506 -r1.507
--- config.c	12 Feb 2006 22:59:38 -0000	1.506
+++ config.c	12 Feb 2006 23:58:22 -0000	1.507
@@ -3150,6 +3150,10 @@ config_parse_addr_policy(config_line_t *
       debug(LD_CONFIG,"Adding new entry '%s'",ent);
       *nextp = router_parse_addr_policy_from_string(ent, assume_action);
       if (*nextp) {
+        if (addr_mask_get_bits((*nextp)->msk)<0) {
+          warn(LD_CONFIG, "Address policy element '%s' can't be expressed "
+               "as a bit prefix.", ent);
+        }
         nextp = &((*nextp)->next);
       } else {
         warn(LD_CONFIG,"Malformed policy '%s'.", ent);

Index: router.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/router.c,v
retrieving revision 1.243
retrieving revision 1.244
diff -u -p -d -r1.243 -r1.244
--- router.c	9 Feb 2006 05:46:49 -0000	1.243
+++ router.c	12 Feb 2006 23:58:22 -0000	1.244
@@ -1111,13 +1111,18 @@ router_dump_router_to_string(char *s, si
       return -1;
     written += result;
     if (tmpe->msk != 0xFFFFFFFFu && tmpe->msk != 0) {
-      /* Write "/255.255.0.0" */
-      in.s_addr = htonl(tmpe->msk);
-      tor_inet_ntoa(&in, addrbuf, sizeof(addrbuf));
-      result = tor_snprintf(s+written, maxlen-written, "/%s", addrbuf);
-      if (result<0)
-        return -1;
-      written += result;
+      int n_bits = addr_mask_get_bits(tmpe->msk);
+      if (n_bits >= 0) {
+        if (tor_snprintf(s+written, maxlen-written, "/%d", n_bits)<0)
+          return -1;
+      } else {
+        /* Write "/255.255.0.0" */
+        in.s_addr = htonl(tmpe->msk);
+        tor_inet_ntoa(&in, addrbuf, sizeof(addrbuf));
+        if (tor_snprintf(s+written, maxlen-written, "/%s", addrbuf)<0)
+          return -1;
+      }
+      written += strlen(s+written);
     }
     if (tmpe->prt_min <= 1 && tmpe->prt_max == 65535) {
       /* There is no port set; write ":*" */



More information about the tor-commits mailing list