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

[or-cvs] r11928: Backport r11886 and r11887: Fix for the reported case of bug (in tor/branches/tor-0_1_2-patches: . doc src/or)



Author: nickm
Date: 2007-10-14 04:48:56 -0400 (Sun, 14 Oct 2007)
New Revision: 11928

Modified:
   tor/branches/tor-0_1_2-patches/
   tor/branches/tor-0_1_2-patches/ChangeLog
   tor/branches/tor-0_1_2-patches/doc/TODO.012
   tor/branches/tor-0_1_2-patches/src/or/circuitlist.c
   tor/branches/tor-0_1_2-patches/src/or/or.h
   tor/branches/tor-0_1_2-patches/src/or/routerlist.c
Log:
 r15763@catbus:  nickm | 2007-10-14 04:40:00 -0400
 Backport r11886 and r11887: Fix for the reported case of bug 438: check families as well as identities in circuit_find_to_cannibalize().  Code audit STILL pending. ;)



Property changes on: tor/branches/tor-0_1_2-patches
___________________________________________________________________
 svk:merge ticket from /tor/012 [r15763] on 8246c3cf-6607-4228-993b-4d95d33730f1

Modified: tor/branches/tor-0_1_2-patches/ChangeLog
===================================================================
--- tor/branches/tor-0_1_2-patches/ChangeLog	2007-10-14 08:48:54 UTC (rev 11927)
+++ tor/branches/tor-0_1_2-patches/ChangeLog	2007-10-14 08:48:56 UTC (rev 11928)
@@ -13,6 +13,9 @@
       happened inside connection_flushed_some(), do not call
       connection_finished_flushing().  Should fix bug 451. Bugfix on
       0.1.2.7-alpha.
+    - When looking for a circuit to cannibalize, consider family as well
+      as identity.  Fixes bug 438.  Bugfix on 0.1.0.x (which introduced
+      circuit cannibalization).
 
   o Minor bugfixes:
     - Don't try to access (or alter) the state file when running

Modified: tor/branches/tor-0_1_2-patches/doc/TODO.012
===================================================================
--- tor/branches/tor-0_1_2-patches/doc/TODO.012	2007-10-14 08:48:54 UTC (rev 11927)
+++ tor/branches/tor-0_1_2-patches/doc/TODO.012	2007-10-14 08:48:56 UTC (rev 11928)
@@ -5,7 +5,7 @@
   o r11166: Don't believe future dates from the state file.
   o r11828+: Detect bad sa_family from accept().
   o r11882: Avoid crash-bug 451.
-N - r11886: Consider family as well as identity when cannibalizing circuits.
+  o r11886: Consider family as well as identity when cannibalizing circuits.
 
 
 Backport for 0.1.2.x once better tested:

Modified: tor/branches/tor-0_1_2-patches/src/or/circuitlist.c
===================================================================
--- tor/branches/tor-0_1_2-patches/src/or/circuitlist.c	2007-10-14 08:48:54 UTC (rev 11927)
+++ tor/branches/tor-0_1_2-patches/src/or/circuitlist.c	2007-10-14 08:48:56 UTC (rev 11928)
@@ -779,10 +779,16 @@
         if (info) {
           /* need to make sure we don't duplicate hops */
           crypt_path_t *hop = circ->cpath;
+          routerinfo_t *ri1 = router_get_by_digest(info->identity_digest);
           do {
+            routerinfo_t *ri2;
             if (!memcmp(hop->extend_info->identity_digest,
                         info->identity_digest, DIGEST_LEN))
               goto next;
+            if (ri1 &&
+                (ri2 = router_get_by_digest(hop->extend_info->identity_digest))
+                && routers_in_same_family(ri1, ri2))
+              goto next;
             hop=hop->next;
           } while (hop!=circ->cpath);
         }

Modified: tor/branches/tor-0_1_2-patches/src/or/or.h
===================================================================
--- tor/branches/tor-0_1_2-patches/src/or/or.h	2007-10-14 08:48:54 UTC (rev 11927)
+++ tor/branches/tor-0_1_2-patches/src/or/or.h	2007-10-14 08:48:56 UTC (rev 11928)
@@ -2891,6 +2891,7 @@
 trusted_dir_server_t *router_get_trusteddirserver_by_digest(
      const char *digest);
 void routerlist_add_family(smartlist_t *sl, routerinfo_t *router);
+int routers_in_same_family(routerinfo_t *r1, routerinfo_t *r2);
 void add_nickname_list_to_smartlist(smartlist_t *sl, const char *list,
                                     int must_be_running);
 int router_nickname_is_in_list(routerinfo_t *router, const char *list);

Modified: tor/branches/tor-0_1_2-patches/src/or/routerlist.c
===================================================================
--- tor/branches/tor-0_1_2-patches/src/or/routerlist.c	2007-10-14 08:48:54 UTC (rev 11927)
+++ tor/branches/tor-0_1_2-patches/src/or/routerlist.c	2007-10-14 08:48:56 UTC (rev 11928)
@@ -765,6 +765,47 @@
   }
 }
 
+/** Return true iff r is named by some nickname in <b>lst</b>. */
+static INLINE int
+router_in_nickname_smartlist(smartlist_t *lst, routerinfo_t *r)
+{
+  if (!lst) return 0;
+  SMARTLIST_FOREACH(lst, const char *, name,
+    if (router_nickname_matches(r, name))
+      return 1;);
+  return 0;
+}
+
+/** Return true iff router1 and router2 have the same /16 network. */
+static INLINE int
+routers_in_same_network_family(routerinfo_t *r1, routerinfo_t *r2)
+{
+  return (r1->addr & 0xffff0000) == (r2->addr & 0xffff0000);
+}
+
+/** Return true iff r1 and r2 are in the same family, but not the same
+ * router. */
+int
+routers_in_same_family(routerinfo_t *r1, routerinfo_t *r2)
+{
+  or_options_t *options = get_options();
+  config_line_t *cl;
+
+  if (options->EnforceDistinctSubnets && routers_in_same_network_family(r1,r2))
+    return 1;
+
+  if (router_in_nickname_smartlist(r1->declared_family, r2) &&
+      router_in_nickname_smartlist(r2->declared_family, r1))
+    return 1;
+
+  for (cl = options->NodeFamilies; cl; cl = cl->next) {
+    if (router_nickname_is_in_list(r1, cl->value) &&
+        router_nickname_is_in_list(r2, cl->value))
+      return 1;
+  }
+  return 0;
+}
+
 /** Given a (possibly NULL) comma-and-whitespace separated list of nicknames,
  * see which nicknames in <b>list</b> name routers in our routerlist, and add
  * the routerinfos for those routers to <b>sl</b>.  If <b>must_be_running</b>,
@@ -1059,7 +1100,7 @@
   }
 
   /* Figure out how to weight exits and guards. */
-  { 
+  {
     double all_bw = U64_TO_DBL(total_exit_bw+total_nonexit_bw);
     double exit_bw = U64_TO_DBL(total_exit_bw);
     double guard_bw = U64_TO_DBL(total_guard_bw);