[or-cvs] Code to parse (but not yet actually use) RedirectExit lines

Nick Mathewson nickm at seul.org
Sat Oct 16 22:37:10 UTC 2004


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

Modified Files:
	config.c or.h 
Log Message:
Code to parse (but not yet actually use) RedirectExit lines

Index: config.c
===================================================================
RCS file: /home/or/cvsroot/src/or/config.c,v
retrieving revision 1.176
retrieving revision 1.177
diff -u -d -r1.176 -r1.177
--- config.c	16 Oct 2004 22:14:51 -0000	1.176
+++ config.c	16 Oct 2004 22:37:08 -0000	1.177
@@ -277,6 +277,7 @@
       config_compare(list, "PidFile",        CONFIG_TYPE_STRING, &options->PidFile) ||
       config_compare(list, "PathlenCoinWeight",CONFIG_TYPE_DOUBLE, &options->PathlenCoinWeight) ||
 
+      config_compare(list, "RedirectExit",   CONFIG_TYPE_LINELIST, &options->RedirectExit) ||
       config_compare(list, "RouterFile",     CONFIG_TYPE_OBSOLETE, NULL) ||
       config_compare(list, "RunAsDaemon",    CONFIG_TYPE_BOOL, &options->RunAsDaemon) ||
       config_compare(list, "RunTesting",     CONFIG_TYPE_BOOL, &options->RunTesting) ||
@@ -478,6 +479,12 @@
   config_free_lines(options->DirServers);
   config_free_lines(options->RecommendedVersions);
   config_free_lines(options->NodeFamilies);
+  config_free_lines(options->RedirectExit);
+  if (options->RedirectExitList) {
+    SMARTLIST_FOREACH(options->RedirectExit,exit_redirect_t *, p, tor_free(p));
+    smartlist_free(options->RedirectExit);
+    options->RedirectExit = NULL;                      
+  }
   if (options->FirewallPorts) {
     SMARTLIST_FOREACH(options->FirewallPorts, char *, cp, tor_free(cp));
     smartlist_free(options->FirewallPorts);
@@ -868,6 +875,13 @@
       return -1;
   }
 
+  if (!options->RedirectExitList)
+    options->RedirectExitList = smartlist_create();
+  for (cl = options->RedirectExit; cl; cl = cl->next) {
+    if (parse_redirect_line(options, cl)<0)
+      return -1;
+  }
+
   clear_trusted_dir_servers();
   if (!options->DirServers) {
     add_default_trusted_dirservers();
@@ -1051,6 +1065,48 @@
   }
 }
 
+static int parse_redirect_line(or_options_t *options, 
+                               struct config_line_t *line)
+{
+  smartlist_t *elements = NULL;
+  exit_redirect_t *r;
+
+  tor_assert(options);
+  tor_assert(options->RedirectExitList);
+  tor_assert(line);
+
+  r = tor_malloc_zero(sizeof(exit_redirect_t));
+  smartlist_split_string(elements, line->value, " ",
+                         SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK, 0);
+  if (smartlist_len(elements) != 2) {
+    log_fn(LOG_WARN, "Wrong number of elements in RedirectExit line");
+    goto err;
+  }
+  if (parse_addr_and_port_range(smartlist_get(elements,0),&r->addr,&r->mask,
+                                &r->port_min,&r->port_max)) {
+    log_fn(LOG_WARN, "Error parsing source address in RedirectExit line");
+    goto err;
+  }
+  if (parse_addr_port(smartlist_get(elements,1),NULL,&r->addr_dest,
+                      &r->port_dest)) {
+    log_fn(LOG_WARN, "Error parseing dest address in RedirectExit line");
+    goto err;
+  }
+
+  goto done;
+ err:
+  tor_free(r);
+ done:
+  SMARTLIST_FOREACH(elements, char *, cp, tor_free(cp));
+  smartlist_free(elements);
+  if (r) {
+    smartlist_add(options->RedirectExitList, r);
+    return 0;
+  } else {
+    return -1;
+  }
+}
+
 static int parse_dir_server_line(const char *line)
 {
   smartlist_t *items = NULL;

Index: or.h
===================================================================
RCS file: /home/or/cvsroot/src/or/or.h,v
retrieving revision 1.437
retrieving revision 1.438
diff -u -d -r1.437 -r1.438
--- or.h	16 Oct 2004 22:14:51 -0000	1.437
+++ or.h	16 Oct 2004 22:37:08 -0000	1.438
@@ -818,6 +818,16 @@
 #define ALLOW_UNVERIFIED_RENDEZVOUS   8
 #define ALLOW_UNVERIFIED_INTRODUCTION 16
 
+typedef struct exit_redirect_t {
+  uint32_t addr;
+  uint32_t mask;
+  uint16_t port_min;
+  uint16_t port_max;
+
+  uint32_t addr_dest;
+  uint32_t port_dest;
+} exit_redirect_t;
+
 /** Configuration options for a Tor process */
 typedef struct {
   struct config_line_t *LogOptions; /**< List of configuration lines
@@ -905,6 +915,9 @@
   char *MyFamily; /**< Declared family for this OR. */
   struct config_line_t *NodeFamilies; /**< List of config lines for
                                        * node families */
+  struct config_line_t *RedirectExit; /**< List of config lines for simple
+                                       * addr/port redirection */
+  smartlist_t *RedirectExitList; /** List of exit_redirect_t */
 } or_options_t;
 
 /* XXX are these good enough defaults? */



More information about the tor-commits mailing list