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

[or-cvs] Forward-port ]Test and document last patch.



Update of /home/or/cvsroot/tor/src/or
In directory moria:/tmp/cvs-serv5460/src/or

Modified Files:
	config.c connection_edge.c or.h 
Log Message:
[Forward-port ]Test and document last patch.

Index: config.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/config.c,v
retrieving revision 1.559
retrieving revision 1.560
diff -u -p -d -r1.559 -r1.560
--- config.c	18 Apr 2006 03:36:28 -0000	1.559
+++ config.c	18 Apr 2006 03:51:18 -0000	1.560
@@ -678,7 +678,7 @@ options_act(or_options_t *old_options)
   size_t len;
   or_options_t *options = get_options();
   int running_tor = options->command == CMD_RUN_TOR;
-  const char *msg;
+  char *msg;
 
   clear_trusted_dir_servers();
   if (options->DirServers) {
@@ -2407,7 +2407,7 @@ options_validate(or_options_t *old_optio
   if (rend_config_services(options, 1) < 0)
     REJECT("Failed to configure rendezvous options. See logs for details.");
 
-  if (parse_virtual_addr_network(options->VirtualAddrNetwork, 1, msg)<0)
+  if (parse_virtual_addr_network(options->VirtualAddrNetwork, 1, NULL)<0)
     return -1;
 
   return 0;

Index: connection_edge.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/connection_edge.c,v
retrieving revision 1.394
retrieving revision 1.395
diff -u -p -d -r1.394 -r1.395
--- connection_edge.c	18 Apr 2006 03:36:28 -0000	1.394
+++ connection_edge.c	18 Apr 2006 03:51:18 -0000	1.395
@@ -764,38 +764,41 @@ static uint32_t next_virtual_addr    = 0
 
 /** Read a netmask of the form 127.192.0.0/10 from "val", and check whether
  * it's a valid set of virtual addresses to hand out in response to MAPADDRESS
- * requests.  Return 0 on success; set *msg and return -1 on failure.  If
- * validate_only is false, sets the actual virtual address range to the parsed
- * value. */
+ * requests.  Return 0 on success; set *msg (if provided) to a newly allocated
+ * string and return -1 on failure.  If validate_only is false, sets the
+ * actual virtual address range to the parsed value. */
 int
 parse_virtual_addr_network(const char *val, int validate_only,
-                           const char **msg)
+                           char **msg)
 {
   uint32_t addr, mask;
   uint16_t port_min, port_max;
   int bits;
 
   if (parse_addr_and_port_range(val, &addr, &mask, &port_min, &port_max)) {
-    *msg = "Error parsing VirtualAddressNetwork";
+    if (msg) *msg = tor_strdup("Error parsing VirtualAddressNetwork");
     return -1;
   }
 
   if (port_min != 1 || port_max != 65535) {
-    *msg = "Can't specify ports on VirtualAddressNetwork";
+    if (msg) *msg = tor_strdup("Can't specify ports on VirtualAddressNetwork");
     return -1;
   }
 
   bits = addr_mask_get_bits(mask);
   if (bits < 0) {
-    *msg = "VirtualAddressNetwork must have a mask that can be expressed "
-      "as a prefix";
+    if (msg) *msg = tor_strdup("VirtualAddressNetwork must have a mask that "
+                               "can be expressed as a prefix");
     return -1;
   }
 
+#if 0
   if (bits > 16) {
-    *msg = "VirtualAddressNetwork expects a class B network or larger";
+    if (msg) *msg = tor_strdup("VirtualAddressNetwork expects a class B "
+                               "network or larger");
     return -1;
   }
+#endif
 
   if (validate_only)
     return 0;
@@ -848,7 +851,9 @@ addressmap_get_virtual_address(int type)
     } while (strmap_get(addressmap, buf));
     return tor_strdup(buf);
   } else if (type == RESOLVED_TYPE_IPV4) {
-    uint32_t available = 1u << virtual_addr_netmask_bits;
+    // This is an imperfect estimate of how many addresses are available, but
+    // that's ok.
+    uint32_t available = 1u << (32-virtual_addr_netmask_bits);
     while (available) {
       /* Don't hand out any .0 or .255 address. */
       while ((next_virtual_addr & 0xff) == 0 ||
@@ -862,6 +867,7 @@ addressmap_get_virtual_address(int type)
 
       ++next_virtual_addr;
       --available;
+      log_notice(LD_CONFIG, "%d addrs available", (int)available);
       if (! --available) {
         log_warn(LD_CONFIG, "Ran out of virtual addresses!");
         return NULL;

Index: or.h
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/or.h,v
retrieving revision 1.829
retrieving revision 1.830
diff -u -p -d -r1.829 -r1.830
--- or.h	18 Apr 2006 03:36:28 -0000	1.829
+++ or.h	18 Apr 2006 03:51:18 -0000	1.830
@@ -1729,7 +1729,7 @@ int addressmap_already_mapped(const char
 void addressmap_register(const char *address, char *new_address,
                          time_t expires);
 int parse_virtual_addr_network(const char *val, int validate_only,
-                               const char **msg);
+                               char **msg);
 int client_dns_incr_failures(const char *address);
 void client_dns_clear_failures(const char *address);
 void client_dns_set_addressmap(const char *address, uint32_t val,