]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Get address map resetting implemented.
authorNick Mathewson <nickm@torproject.org>
Fri, 11 Mar 2005 21:39:39 +0000 (21:39 +0000)
committerNick Mathewson <nickm@torproject.org>
Fri, 11 Mar 2005 21:39:39 +0000 (21:39 +0000)
svn:r3745

src/or/config.c
src/or/connection_edge.c
src/or/main.c
src/or/or.h

index 204a477f67be7341e490865e36ef615d1b886a81..1f4e0ffa9e1fa8732b28033c786fa6e0eec48e86 100644 (file)
@@ -1823,6 +1823,7 @@ config_register_addressmaps(or_options_t *options) {
   struct config_line_t *opt;
   char *from, *to;
 
+  addressmap_clear_configured();
   elts = smartlist_create();
   for (opt = options->AddressMap; opt; opt = opt->next) {
     smartlist_split_string(elts, opt->value, NULL,
index 87487b31810620effa99b974d80a95973ffaaec4..420047e826e66c4db986fe2d0febb6ba77ec26a4 100644 (file)
@@ -435,29 +435,26 @@ addressmap_ent_remove(const char *addr, addressmap_entry_t *ent)
   addressmap_ent_free(ent);
 }
 
-/** A helper function for addressmap_clean() below. If ent is too old,
- * then remove it from the tree and return NULL, else return ent.
- */
-static void *
-_addressmap_remove_if_expired(const char *addr,
-                              addressmap_entry_t *ent,
-                              time_t *nowp) {
-  if (ent->expires > 1 && ent->expires < *nowp) {
-    log(LOG_INFO, "Addressmap: expiring remap (%s to %s)",
-           addr, ent->new_address);
-    addressmap_ent_remove(addr,ent);
-    return NULL;
-  } else {
-    return ent;
-  }
+/** Remove all entries from the addressmap that were set via the
+ * configuration file or the command line. */
+void
+addressmap_clear_configured(void)
+{
+  addressmap_get_mappings(NULL, 0, 0);
+}
+
+/** Remove all entries from the addressmap that are set to expire, ever. */
+void
+addressmap_clear_transient(void)
+{
+  addressmap_get_mappings(NULL, 2, TIME_MAX);
 }
 
 /** Clean out entries from the addressmap cache that were
  * added long enough ago that they are no longer valid.
  */
 void addressmap_clean(time_t now) {
-  strmap_foreach(addressmap,
-                 (strmap_foreach_fn)_addressmap_remove_if_expired, &now);
+  addressmap_get_mappings(NULL, 2, now);
 }
 
 /** Free all the elements in the addressmap, and free the addressmap
@@ -708,7 +705,11 @@ address_is_invalid_destination(const char *address) {
   return 0;
 }
 
-/* DOCDOC */
+/* Iterate over all address mapings which have exipry times between
+ * min_expires and max_expires, inclusive.  If sl is provided, add an
+ * "old-addr new-addr" string to sl for each mapping.  If sl is NULL,
+ * remove the mappings.
+ */
 void
 addressmap_get_mappings(smartlist_t *sl, time_t min_expires, time_t max_expires)
 {
@@ -717,17 +718,23 @@ addressmap_get_mappings(smartlist_t *sl, time_t min_expires, time_t max_expires)
    void *_val;
    addressmap_entry_t *val;
 
-   tor_assert(sl);
-
    for (iter = strmap_iter_init(addressmap); !strmap_iter_done(iter);
         iter = strmap_iter_next(addressmap,iter)) {
      strmap_iter_get(iter, &key, &_val);
      val = _val;
      if (val->expires >= min_expires && val->expires <= max_expires) {
-       size_t len = strlen(key)+strlen(val->new_address)+2;
-       char *line = tor_malloc(len);
-       tor_snprintf(line, len, "%s %s", key, val->new_address);
-       smartlist_add(sl, line);
+       if (sl) {
+         size_t len = strlen(key)+strlen(val->new_address)+2;
+         char *line = tor_malloc(len);
+         tor_snprintf(line, len, "%s %s", key, val->new_address);
+         smartlist_add(sl, line);
+         iter = strmap_iter_next(addressmap,iter);
+       } else {
+         addressmap_ent_remove(key, val);
+         iter = strmap_iter_next_rmv(addressmap,iter);
+       }
+     } else {
+       iter = strmap_iter_next(addressmap,iter);
      }
    }
 }
index 83bd1053017a33deac9ee2e4495b3ef179d54d07..0c9eacf8c422c54f5c394e887a27f5928cd76472 100644 (file)
@@ -892,6 +892,7 @@ static int do_hup(void) {
   if (accounting_is_enabled(options))
     accounting_record_bandwidth_usage(time(NULL));
 
+  addressmap_clear_transient();
   /* first, reload config variables, in case they've changed */
   /* no need to provide argc/v, they've been cached inside init_from_config */
   if (init_from_config(0, NULL) < 0) {
index 8137cf814552df63f75202b901866d60f714a838..f14632eb0d130d5791cce9f44c043d541b0c1962 100644 (file)
@@ -1312,6 +1312,8 @@ void connection_ap_attach_pending(void);
 
 void addressmap_init(void);
 void addressmap_clean(time_t now);
+void addressmap_clear_configured(void);
+void addressmap_clear_transient(void);
 void addressmap_free_all(void);
 void addressmap_rewrite(char *address, size_t maxlen);
 int addressmap_already_mapped(const char *address);