aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2005-03-23 08:40:11 +0000
committerNick Mathewson <nickm@torproject.org>2005-03-23 08:40:11 +0000
commitb9016bd18faa5d470fad0c57985449c5d5c6fcb6 (patch)
tree412b8ed38b1a60c6f2ebca9b27718d813f78409c
parent291548c4e434b15b6eb34b9cc9a155d9d11c0527 (diff)
downloadtor-b9016bd18faa5d470fad0c57985449c5d5c6fcb6.tar.gz
tor-b9016bd18faa5d470fad0c57985449c5d5c6fcb6.zip
Fix several bugs (including some crashes) related to control interface; implement missing desc/name functionality.
svn:r3836
-rw-r--r--src/or/connection_edge.c53
-rw-r--r--src/or/control.c9
-rw-r--r--src/or/dirserv.c3
-rw-r--r--src/or/or.h2
4 files changed, 49 insertions, 18 deletions
diff --git a/src/or/connection_edge.c b/src/or/connection_edge.c
index 7ad1f37e6a..12b4cb1b9b 100644
--- a/src/or/connection_edge.c
+++ b/src/or/connection_edge.c
@@ -413,7 +413,7 @@ typedef struct {
} virtaddress_entry_t;
/** The tree of client-side address rewrite instructions. */
-static strmap_t *addressmap;
+static strmap_t *addressmap=NULL;
/**
* Tree mapping addresses to which virtual address, if any, we
* assigned them to.
@@ -424,7 +424,7 @@ static strmap_t *addressmap;
* if it fails, then we could end up mapping two virtual addresses to
* the same address, which is no disaster.
**/
-static strmap_t *virtaddress_reversemap;
+static strmap_t *virtaddress_reversemap=NULL;
/** Initialize addressmap. */
void addressmap_init(void) {
@@ -454,6 +454,7 @@ addressmap_virtaddress_remove(const char *addr, addressmap_entry_t *ent)
if (ent && address_is_in_virtual_range(ent->new_address)) {
virtaddress_entry_t *ve =
strmap_get(virtaddress_reversemap, ent->new_address);
+ /*log_fn(LOG_NOTICE,"remove reverse mapping for %s",ent->new_address);*/
if (ve) {
if (!strcmp(addr, ve->ipv4_address))
tor_free(ve->ipv4_address);
@@ -533,8 +534,9 @@ int addressmap_already_mapped(const char *address) {
}
/** Register a request to map <b>address</b> to <b>new_address</b>,
- * which will expire on <b>expires</b> (or 0 if never expires from config
- * file, 1 if never expires from controller).
+ * which will expire on <b>expires</b> (or 0 if never expires from
+ * config file, 1 if never expires from controller, 2 if never expires
+ * (virtual address mapping) from the controller.)
*
* <b>new_address</b> should be a newly dup'ed string, which we'll use or
* free as appropriate. We will leave address alone.
@@ -564,14 +566,17 @@ void addressmap_register(const char *address, char *new_address, time_t expires)
tor_free(new_address);
return;
}
- if (address_is_in_virtual_range(ent->new_address)) {
+ if (address_is_in_virtual_range(ent->new_address) &&
+ expires != 2) {
+ /* XXX This isn't the perfect test; we want to avoid removing
+ * mappings set from the control interface _as virtual mapping */
addressmap_virtaddress_remove(address, ent);
}
tor_free(ent->new_address);
} /* else { we have an in-progress resolve with no mapping. } */
ent->new_address = new_address;
- ent->expires = expires;
+ ent->expires = expires==2 ? 1 : expires;
ent->num_resolve_failures = 0;
log_fn(LOG_INFO, "Addressmap: (re)mapped '%s' to '%s'",
@@ -673,7 +678,7 @@ addressmap_get_virtual_address(int type)
struct in_addr in;
if (type == RESOLVED_TYPE_HOSTNAME) {
- char rand[16];
+ char rand[10];
do {
crypto_rand(rand, sizeof(rand));
base32_encode(buf,sizeof(buf),rand,sizeof(rand));
@@ -712,33 +717,53 @@ addressmap_get_virtual_address(int type)
* The string in <b>new_address</b> may be freed, or inserted into a map
* as appropriate.
**/
-char *
+const char *
addressmap_register_virtual_address(int type, char *new_address)
{
char **addrp;
virtaddress_entry_t *vent;
tor_assert(new_address);
+ tor_assert(addressmap);
+ tor_assert(virtaddress_reversemap);
vent = strmap_get(virtaddress_reversemap, new_address);
- if (!vent)
+ if (!vent) {
vent = tor_malloc_zero(sizeof(virtaddress_entry_t));
+ strmap_set(virtaddress_reversemap, new_address, vent);
+ }
addrp = (type == RESOLVED_TYPE_IPV4) ?
&vent->ipv4_address : &vent->hostname_address;
if (*addrp) {
addressmap_entry_t *ent = strmap_get(addressmap, *addrp);
- if (!strcasecmp(new_address, ent->new_address))
+ if (ent && !strcasecmp(new_address, ent->new_address)) {
+ tor_free(new_address);
return tor_strdup(*addrp);
- else
+ } else
log_fn(LOG_WARN, "Internal confusion: I thought that '%s' was mapped to by '%s', but '%s' really maps to '%s'. This is a harmless bug.",
- new_address, *addrp, *addrp, ent->new_address);
+ new_address, *addrp, *addrp, ent?ent->new_address:"(nothing)");
}
tor_free(*addrp);
*addrp = addressmap_get_virtual_address(type);
- strmap_set(virtaddress_reversemap, new_address, tor_strdup(*addrp));
- addressmap_register(*addrp, new_address, 1);
+ addressmap_register(*addrp, new_address, 2);
+
+#if 0
+ {
+ addressmap_entry_t *ent;
+ ent = strmap_get(addressmap, *addrp);
+ tor_assert(ent);
+ tor_assert(!strcasecmp(ent->new_address,new_address));
+ vent = strmap_get(virtaddress_reversemap, new_address);
+ tor_assert(vent);
+ tor_assert(!strcasecmp(*addrp,
+ (type == RESOLVED_TYPE_IPV4) ?
+ vent->ipv4_address : vent->hostname_address));
+ log_fn(LOG_INFO, "Map from %s to %s okay.",*addrp,new_address);
+ }
+#endif
+
return *addrp;
}
diff --git a/src/or/control.c b/src/or/control.c
index 3114dbf2d3..8eed8a6820 100644
--- a/src/or/control.c
+++ b/src/or/control.c
@@ -329,7 +329,7 @@ handle_control_getconf(connection_t *conn, uint32_t body_len, const char *body)
{
int recognized = config_option_is_recognized(q);
if (!recognized) {
- send_control_error(conn, ERR_UNRECOGNIZED_CONFIG_KEY, body);
+ send_control_error(conn, ERR_UNRECOGNIZED_CONFIG_KEY, q);
goto done;
} else {
struct config_line_t *answer = config_get_assigned_option(options,q);
@@ -508,7 +508,7 @@ handle_control_mapaddress(connection_t *conn, uint32_t len, const char *body)
} else if (!is_plausible_address(to)) {
log_fn(LOG_WARN,"Skipping invalid argument '%s' in MapAddress msg",to);
} else if (!strcmp(from, ".") || !strcmp(from, "0.0.0.0")) {
- char *addr = addressmap_register_virtual_address(
+ const char *addr = addressmap_register_virtual_address(
strcmp(from,".") ? RESOLVED_TYPE_HOSTNAME : RESOLVED_TYPE_IPV4,
tor_strdup(to));
if (!addr) {
@@ -518,7 +518,6 @@ handle_control_mapaddress(connection_t *conn, uint32_t len, const char *body)
size_t anslen = strlen(addr)+strlen(to)+2;
char *ans = tor_malloc(anslen);
tor_snprintf(ans, anslen, "%s %s", addr, to);
- tor_free(addr);
smartlist_add(reply, ans);
}
} else {
@@ -557,6 +556,10 @@ handle_getinfo_helper(const char *question, char **answer)
routerinfo_t *ri = router_get_by_hexdigest(question+strlen("desc/id/"));
if (ri && ri->signed_descriptor)
*answer = tor_strdup(ri->signed_descriptor);
+ } else if (!strcmpstart(question, "desc/name/")) {
+ routerinfo_t *ri = router_get_by_nickname(question+strlen("desc/name/"));
+ if (ri && ri->signed_descriptor)
+ *answer = tor_strdup(ri->signed_descriptor);
} else if (!strcmp(question, "network-status")) {
if (list_server_status(NULL, answer) < 0)
return -1;
diff --git a/src/or/dirserv.c b/src/or/dirserv.c
index 12641c714b..59768f7dd8 100644
--- a/src/or/dirserv.c
+++ b/src/or/dirserv.c
@@ -528,6 +528,9 @@ list_server_status(char **running_routers_out, char **router_status_out)
rr_entries = smartlist_create();
rs_entries = smartlist_create();
+ if (!descriptor_list)
+ descriptor_list = smartlist_create();
+
SMARTLIST_FOREACH(descriptor_list, routerinfo_t *, ri,
{
int is_live;
diff --git a/src/or/or.h b/src/or/or.h
index 70a31794ac..85718eae50 100644
--- a/src/or/or.h
+++ b/src/or/or.h
@@ -1347,7 +1347,7 @@ int addressmap_already_mapped(const char *address);
void addressmap_register(const char *address, char *new_address, time_t expires);
int client_dns_incr_failures(const char *address);
void client_dns_set_addressmap(const char *address, uint32_t val, const char *exitname);
-char *addressmap_register_virtual_address(int type, char *new_address);
+const char *addressmap_register_virtual_address(int type, char *new_address);
void addressmap_get_mappings(smartlist_t *sl, time_t min_expires, time_t max_expires);
void parse_socks_policy(void);