s2smanager: Compatibility with domains which use CNAMEs

Sat, 19 Sep 2009 17:47:26 +0100

author
Matthew Wild <mwild1@gmail.com>
date
Sat, 19 Sep 2009 17:47:26 +0100
changeset 1793
1fc6c2822e6b
parent 1791
42d0b68a1efd
child 1794
218f720af304
child 1796
5f7b2f940816

s2smanager: Compatibility with domains which use CNAMEs

core/s2smanager.lua file | annotate | diff | comparison | revisions
--- a/core/s2smanager.lua	Sat Sep 19 17:40:19 2009 +0100
+++ b/core/s2smanager.lua	Sat Sep 19 17:47:26 2009 +0100
@@ -37,7 +37,7 @@
 
 local dialback_secret = uuid_gen();
 
-local adns = require "net.adns";
+local adns, dns = require "net.adns", require "net.dns";
 
 local dns_timeout = config.get("*", "core", "dns_timeout") or 60;
 
@@ -240,6 +240,16 @@
 	handle = adns.lookup(function (reply)
 		handle = nil;
 		host_session.connecting = nil;
+		
+		-- COMPAT: This is a compromise for all you CNAME-(ab)users :)
+		if not (reply and reply[1] and reply[1].a) then
+			reply = dns.peek(connect_host, "CNAME", "IN");
+			while reply and reply[1] and not reply[1].a and reply[1].cname do
+				reply = dns.peek(reply[1].cname, "A", "IN") or dns.peek(reply[1].cname, "CNAME", "IN");
+			end
+		end
+		-- end of CNAME resolving
+		
 		if reply and reply[1] and reply[1].a then
 			log("debug", "DNS reply for %s gives us %s", connect_host, reply[1].a);
 			return make_connect(host_session, reply[1].a, connect_port);

mercurial