[or-cvs] compress exit policies even more -- look for duplicate lines

arma at seul.org arma at seul.org
Sun Feb 12 00:03:08 UTC 2006


Update of /home2/or/cvsroot/tor/src/or
In directory moria:/home/arma/work/onion/cvs/tor/src/or

Modified Files:
	config.c 
Log Message:
compress exit policies even more -- look for duplicate lines
and remove them.


Index: config.c
===================================================================
RCS file: /home2/or/cvsroot/tor/src/or/config.c,v
retrieving revision 1.501
retrieving revision 1.502
diff -u -p -d -r1.501 -r1.502
--- config.c	11 Feb 2006 23:47:24 -0000	1.501
+++ config.c	12 Feb 2006 00:03:06 -0000	1.502
@@ -348,6 +348,7 @@ static int check_nickname_list(const cha
 static void config_register_addressmaps(or_options_t *options);
 
 static int parse_dir_server_line(const char *line, int validate_only);
+static int config_cmp_single_addr_policy(addr_policy_t *a, addr_policy_t *b);
 static int parse_redirect_line(smartlist_t *result,
                                config_line_t *line);
 static int parse_log_severity_range(const char *range, int *min_out,
@@ -3001,9 +3002,10 @@ config_expand_exit_policy_aliases(smartl
 static void
 config_exit_policy_remove_redundancies(addr_policy_t **dest)
 {
-  addr_policy_t *ap, *tmp;
+  addr_policy_t *ap, *tmp, *victim;
   int have_seen_accept=0;
 
+  /* Step one: find a *:* entry and cut off everything after it. */
   for (ap=*dest; ap; ap=ap->next) {
     if (ap->policy_type == ADDR_POLICY_ACCEPT)
       have_seen_accept=1;
@@ -3028,6 +3030,22 @@ config_exit_policy_remove_redundancies(a
       }
     }
   }
+
+  /* Step two: for every entry, see if there's an exact duplicate
+   * later on, and remove it. */
+  for (ap=*dest; ap; ap=ap->next) {
+    tmp=ap;
+    while (tmp) {
+      if (tmp->next && !config_cmp_single_addr_policy(ap, tmp->next)) {
+        victim = tmp->next;
+        tmp->next = victim->next;
+        victim->next = NULL;
+        addr_policy_free(victim);
+      } else {
+        tmp=tmp->next;
+      }
+    }
+  }
 }
 
 #define DEFAULT_EXIT_POLICY                                         \
@@ -3104,22 +3122,33 @@ config_parse_addr_policy(config_line_t *
   return r;
 }
 
-/** Compare two provided address policies, and return -1, 0, or 1 if the first
- * is less than, equal to, or greater than the second. */
+/** Compare two provided address policy items, and return -1, 0, or 1
+ * if the first is less than, equal to, or greater than the second. */
+static int
+config_cmp_single_addr_policy(addr_policy_t *a, addr_policy_t *b)
+{
+  int r;
+  if ((r=((int)a->policy_type - (int)b->policy_type)))
+    return r;
+  if ((r=((int)a->addr - (int)b->addr)))
+    return r;
+  if ((r=((int)a->msk - (int)b->msk)))
+    return r;
+  if ((r=((int)a->prt_min - (int)b->prt_min)))
+    return r;
+  if ((r=((int)a->prt_max - (int)b->prt_max)))
+    return r;
+  return 0;
+}
+
+/** Like config_cmp_single_addr_policy() above, but looks at the
+ * whole set of policies in each case. */
 int
 config_cmp_addr_policies(addr_policy_t *a, addr_policy_t *b)
 {
   int r;
   while (a && b) {
-    if ((r=((int)a->policy_type - (int)b->policy_type)))
-      return r;
-    if ((r=((int)a->addr - (int)b->addr)))
-      return r;
-    if ((r=((int)a->msk - (int)b->msk)))
-      return r;
-    if ((r=((int)a->prt_min - (int)b->prt_min)))
-      return r;
-    if ((r=((int)a->prt_max - (int)b->prt_max)))
+    if ((r=config_cmp_single_addr_policy(a,b)))
       return r;
     a = a->next;
     b = b->next;



More information about the tor-commits mailing list