[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] Add port ranges to exit policies



Update of /home/or/cvsroot/src/or
In directory moria.mit.edu:/tmp/cvs-serv23595/src/or

Modified Files:
	or.h router.c routerlist.c test.c 
Log Message:
Add port ranges to exit policies

Index: or.h
===================================================================
RCS file: /home/or/cvsroot/src/or/or.h,v
retrieving revision 1.201
retrieving revision 1.202
diff -u -d -r1.201 -r1.202
--- or.h	12 Dec 2003 23:03:25 -0000	1.201
+++ or.h	13 Dec 2003 02:44:02 -0000	1.202
@@ -329,7 +329,8 @@
   char *string;
   uint32_t addr;
   uint32_t msk;
-  uint16_t prt;
+  uint16_t prt_min;
+  uint16_t prt_max;
 
   struct exit_policy_t *next;
 };

Index: router.c
===================================================================
RCS file: /home/or/cvsroot/src/or/router.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- router.c	8 Dec 2003 23:45:36 -0000	1.2
+++ router.c	13 Dec 2003 02:44:02 -0000	1.3
@@ -453,16 +453,22 @@
         return -1;
       written += result;
     }
-    if (tmpe->prt) {
-      result = snprintf(s+written, maxlen-written, ":%d\n", tmpe->prt);
+    if (tmpe->prt_min == 1 && tmpe->prt_max == 65535) {
+      if (written > maxlen-4)
+        return -1;
+      strcat(s+written, ":*\n");
+      written += 3;
+    } else if (tmpe->prt_min == tmpe->prt_max) {
+      result = snprintf(s+written, maxlen-written, ":%d\n", tmpe->prt_min);
       if (result<0 || result+written > maxlen)
         return -1;
       written += result;
     } else {
-      if (written > maxlen-4)
+      result = snprintf(s+written, maxlen-written, ":%d-%d\n", tmpe->prt_min,
+                        tmpe->prt_max);
+      if (result<0 || result+written > maxlen)
         return -1;
-      strcat(s+written, ":*\n");
-      written += 3;
+      written += result;
     }
   } /* end for */
   if (written > maxlen-256) /* Not enough room for signature. */

Index: routerlist.c
===================================================================
RCS file: /home/or/cvsroot/src/or/routerlist.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- routerlist.c	13 Dec 2003 01:43:21 -0000	1.6
+++ routerlist.c	13 Dec 2003 02:44:02 -0000	1.7
@@ -424,10 +424,10 @@
     log_fn(LOG_DEBUG,"Considering exit policy %s", tmpe->string);
     if (!addr) {
       /* Address is unknown. */
-      if (tmpe->msk == 0 && (!tmpe || port == tmpe->prt)) {
+      if (tmpe->msk == 0 && (port >= tmpe->prt_min && port <= tmpe->prt_max)) {
         /* The exit policy is accept/reject *:port */
         match = 1;
-      } else if ((!tmpe->prt || port == tmpe->prt) && 
+      } else if (port >= tmpe->prt_min && port <= tmpe->prt_max && 
                  tmpe->policy_type == EXIT_POLICY_REJECT) {
         /* The exit policy is reject ???:port */
         maybe_reject = 1;
@@ -435,7 +435,7 @@
     } else {
       /* Address is known */
       if ( (addr & tmpe->msk) == (tmpe->addr & tmpe->msk) &&
-           (!tmpe->prt || port == tmpe->prt) ) {
+           (port >= tmpe->prt_min && port <= tmpe->prt_max) ) {
         /* Exact match for the policy */
         match = 1;
       }
@@ -947,23 +947,34 @@
     }
   }
   if (strcmp(port, "*") == 0) {
-    newe->prt = 0;
+    newe->prt_min = 1;
+    newe->prt_max = 65535;
   } else {
     endptr = NULL;
-    newe->prt = strtol(port, &endptr, 10);
-    if (*endptr) {
+    newe->prt_min = strtol(port, &endptr, 10);
+    if (*endptr == '-') {
+      port = endptr+1;
+      endptr = NULL;
+      newe->prt_max = strtol(port, &endptr, 10);
+      if (*endptr) {
+      log_fn(LOG_WARN, "Malformed port %s on exit policy; rejecting.",
+             port);
+      }
+    } else if (*endptr) {
       log_fn(LOG_WARN, "Malformed port %s on exit policy; rejecting.",
              port);
       goto policy_read_failed;
+    } else {
+      newe->prt_max = newe->prt_min;
     }
   }
 
   in.s_addr = htonl(newe->addr);
   address = tor_strdup(inet_ntoa(in));
   in.s_addr = htonl(newe->msk);
-  log_fn(LOG_DEBUG,"%s %s/%s:%d",
+  log_fn(LOG_DEBUG,"%s %s/%s:%d-%d",
          newe->policy_type == EXIT_POLICY_REJECT ? "reject" : "accept",
-         address, inet_ntoa(in), newe->prt);
+         address, inet_ntoa(in), newe->prt_min, newe->prt_max);
   tor_free(address);
 
   /* now link newe onto the end of exit_policy */

Index: test.c
===================================================================
RCS file: /home/or/cvsroot/src/or/test.c,v
retrieving revision 1.52
retrieving revision 1.53
diff -u -d -r1.52 -r1.53
--- test.c	8 Dec 2003 23:45:37 -0000	1.52
+++ test.c	13 Dec 2003 02:44:02 -0000	1.53
@@ -560,12 +560,12 @@
   ex1.string = NULL;
   ex1.addr = 0;
   ex1.msk = 0;
-  ex1.prt = 80;
+  ex1.prt_min = ex1.prt_max = 80;
   ex1.next = &ex2;
   ex2.policy_type = EXIT_POLICY_REJECT;
   ex2.addr = 18 << 24;
   ex2.msk = 0xFF000000u;
-  ex2.prt = 24;
+  ex2.prt_min = ex1.prt_max = 24;
   ex2.next = NULL;
   r2.address = "tor.tor.tor";
   r2.addr = 0x0a030201u; /* 10.3.2.1 */