[or-cvs] r9458: Add a couple of fixes I turned up while writing regression t (in tor/trunk: . src/or)

nickm at seul.org nickm at seul.org
Mon Jan 29 18:13:47 UTC 2007


Author: nickm
Date: 2007-01-29 13:13:42 -0500 (Mon, 29 Jan 2007)
New Revision: 9458

Modified:
   tor/trunk/
   tor/trunk/ChangeLog
   tor/trunk/src/or/eventdns.c
Log:
 r11586 at catbus:  nickm | 2007-01-29 13:13:27 -0500
 Add a couple of fixes I turned up while writing regression tests for libevent: Allow DNS servers on ports other than 53, and handle TTLs correctly on reverse hostname lookups.



Property changes on: tor/trunk
___________________________________________________________________
 svk:merge ticket from /tor/trunk [r11586] on 8246c3cf-6607-4228-993b-4d95d33730f1

Modified: tor/trunk/ChangeLog
===================================================================
--- tor/trunk/ChangeLog	2007-01-29 18:13:39 UTC (rev 9457)
+++ tor/trunk/ChangeLog	2007-01-29 18:13:42 UTC (rev 9458)
@@ -60,6 +60,7 @@
       to wait for 0.2.0.)
     - If the user asks to use invalid exit nodes, be willing to use the
       unstable ones.
+    - Handle TTL values correctly on reverse DNS lookups.
 
   o Major features:
     - Weight directory requests by advertised bandwidth. Now we can
@@ -82,6 +83,7 @@
       directory tunnel without knowing a descriptor first. Still not
       ready yet. As part of the change, now assume we can use a
       create_fast cell if we don't know anything about a router.
+    - Allow exit nodes to use nameservers running on ports other than 53.
 
   o Minor features (controller):
     - Track reasons for OR connection failure; make these reasons

Modified: tor/trunk/src/or/eventdns.c
===================================================================
--- tor/trunk/src/or/eventdns.c	2007-01-29 18:13:39 UTC (rev 9457)
+++ tor/trunk/src/or/eventdns.c	2007-01-29 18:13:42 UTC (rev 9458)
@@ -322,6 +322,8 @@
 static void server_port_free(struct evdns_server_port *port);
 static void server_port_ready_callback(int fd, short events, void *arg);
 
+static int strtoint(const char *const str);
+
 #ifdef WIN32
 static int
 last_error(int sock)
@@ -884,6 +886,7 @@
 			if (name_parse(packet, length, &j, reply.data.ptr.name,
 						   sizeof(reply.data.ptr.name))<0)
 				return -1;
+			ttl_r = MIN(ttl_r, ttl);
 			reply.have_answer = 1;
 			break;
 		} else if (type == TYPE_AAAA && class == CLASS_INET) {
@@ -2019,9 +2022,8 @@
 	return 0;
 }
 
-// exported function
-int
-evdns_nameserver_add(unsigned long int address) {
+static int
+_evdns_nameserver_add_impl(unsigned long int address, int port) {
 	// first check to see if we already have this nameserver
 
 	const struct nameserver *server = server_head, *const started_at = server_head;
@@ -2051,7 +2053,7 @@
 	fcntl(ns->socket, F_SETFL, O_NONBLOCK);
 #endif
 	sin.sin_addr.s_addr = address;
-	sin.sin_port = htons(53);
+	sin.sin_port = htons(port);
 	sin.sin_family = AF_INET;
 	if (connect(ns->socket, (struct sockaddr *) &sin, sizeof(sin)) != 0) {
 		err = 2;
@@ -2096,11 +2098,37 @@
 
 // exported function
 int
+evdns_nameserver_add(unsigned long int address) {
+	return _evdns_nameserver_add_impl(address, 53);
+}
+
+// exported function
+int
 evdns_nameserver_ip_add(const char *ip_as_string) {
 	struct in_addr ina;
-	if (!inet_aton(ip_as_string, &ina))
+	int port;
+	char buf[20];
+	const char *cp;
+	cp = strchr(ip_as_string, ':');
+	if (! cp) {
+		cp = ip_as_string;
+		port = 53;
+	} else {
+		port = strtoint(cp+1);
+		if (port < 0 || port > 65535) {
+			return 4;
+		}
+		if ((cp-ip_as_string) >= (int)sizeof(buf)) {
+			return 4;
+		}
+		memcpy(buf, ip_as_string, cp-ip_as_string);
+		buf[cp-ip_as_string] = '\0';
+		cp = buf;
+	}
+	if (!inet_aton(cp, &ina)) {
 		return 4;
-	return evdns_nameserver_add(ina.s_addr);
+	}
+	return _evdns_nameserver_add_impl(ina.s_addr, port);
 }
 
 // insert into the tail of the queue
@@ -2711,7 +2739,7 @@
 		while (ISSPACE(*ips) || *ips == ',' || *ips == '\t')
 			++ips;
 		addr = ips;
-		while (ISDIGIT(*ips) || *ips == '.')
+		while (ISDIGIT(*ips) || *ips == '.' || *ips == ':')
 			++ips;
 		buf = malloc(ips-addr+1);
 		if (!buf) return 4;



More information about the tor-commits mailing list