summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Sherson <caretaker82@euclid.shersonb.net>2013-12-04 02:31:46 -0800
committerBrian Sherson <caretaker82@euclid.shersonb.net>2013-12-04 02:31:46 -0800
commited39e25609b8d5388df8bf682d9e4d6138a97717 (patch)
tree3dbbaef62f301a3755304c2a8bd4b80cb514c5df
parent0d802dab5b586d511a6291248702c910502acaf7 (diff)
Move hostname lookup into Bouncer connection handler thread, detect IPv4 connections when also listening for IPv6 connections.
-rw-r--r--bouncer.py38
1 files changed, 25 insertions, 13 deletions
diff --git a/bouncer.py b/bouncer.py
index 9cfc786..3c321fa 100644
--- a/bouncer.py
+++ b/bouncer.py
@@ -60,12 +60,6 @@ class Bouncer (Thread):
(connection, addr) = self.socket.accept()
if self.ssl:
connection = ssl.wrap_socket(connection, server_side=True, certfile=self.certfile, keyfile=self.keyfile, ssl_version=ssl.PROTOCOL_SSLv23)
- try:
- hostname, aliaslist, addresslist = socket.gethostbyaddr(
- addr[0])
- addr = (hostname, addr[1])
- except:
- pass
#print ((self,"New client connecting from %s:%s"%addr))
except socket.error:
#print "Shutting down Listener"
@@ -354,12 +348,7 @@ class BouncerConnection (Thread):
#print "Initializing ListenThread..."
self.bouncer = bouncer
self.connection = connection
- if len(addr) == 4:
- self.host, self.port = self.addr = addr[:2]
- self.ipv6 = True
- else:
- self.host, self.port = self.addr = addr
- self.ipv6 = False
+ self.host, self.port = self.addr = addr[:2]
self.IRC = None
self.pwd = None
self.nick = None
@@ -396,7 +385,14 @@ class BouncerConnection (Thread):
nick = "*"
ident = "*"
host = "*"
- protocol = "ircs" if self.IRC.ssl else "irc"
+ if self.IRC.ssl and self.IRC.ipv6:
+ protocol = "ircs6"
+ elif self.IRC.ssl:
+ protocol = "ircs"
+ elif self.IRC.ipv6:
+ protocol = "irc6"
+ else:
+ protocol = "irc"
addr = self.host
return "<Bouncer connection from %(addr)s to %(nick)s!%(ident)s@%(host)s on %(protocol)s://%(server)s:%(port)s>" % locals()
@@ -416,6 +412,22 @@ class BouncerConnection (Thread):
self.quitting = True
def run(self):
+ ### Name loopup should happen here instead
+ ipv4match = re.findall(
+ r"^::ffff:((\d+)\.(\d+)\.(\d+)\.(\d+))$", self.host)
+ if self.bouncer.ipv6 and ipv4match:
+ addr, a, b, c, d = ipv4match[0]
+ if max(int(a), int(b), int(c), int(d)) < 256:
+ self.host = addr
+ self.ipv6 = False
+ elif self.bouncer.ipv6:
+ self.ipv6 = True
+ try:
+ self.host, aliaslist, addresslist = socket.gethostbyaddr(self.host)
+ self.addr = (self.host, addr[1])
+ except:
+ pass
+
### Add connection to connection list.
listnumerics = dict(b=(367, 368, "channel ban list"),