HTTP server: use two single-stack servers instead of a dual-stack one, and add a config variable to disable this behavior. Closes GH-945.

This commit is contained in:
Valentin Lorentz 2015-08-22 13:10:03 +02:00
parent 543732af3a
commit a39238aba9
2 changed files with 12 additions and 1 deletions

View File

@ -1155,8 +1155,12 @@ class IP(registry.String):
else:
registry.String.setValue(self, v)
registerGlobalValue(supybot.servers.http, 'singleStack',
registry.Boolean(True, _("""If true, uses IPV6_V6ONLY to disable
forwaring of IPv4 traffic to IPv6 sockets. On *nix, has the same
effect as setting kernel variable net.ipv6.bindv6only to 1.""")))
registerGlobalValue(supybot.servers.http, 'hosts4',
IP('', _("""Space-separated list of IPv4 hosts the HTTP server
IP('0.0.0.0', _("""Space-separated list of IPv4 hosts the HTTP server
will bind.""")))
registerGlobalValue(supybot.servers.http, 'hosts6',
IP('::0', _("""Space-separated list of IPv6 hosts the HTTP server will

View File

@ -171,6 +171,7 @@ class RealSupyHTTPServer(HTTPServer):
running = False
def __init__(self, address, protocol, callback):
self.protocol = protocol
if protocol == 4:
self.address_family = socket.AF_INET
elif protocol == 6:
@ -180,6 +181,12 @@ class RealSupyHTTPServer(HTTPServer):
HTTPServer.__init__(self, address, callback)
self.callbacks = {}
def server_bind(self):
if self.protocol == 6:
v = conf.supybot.servers.http.singleStack()
self.socket.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, v)
HTTPServer.server_bind(self)
def hook(self, subdir, callback):
if subdir in self.callbacks:
log.warning(('The HTTP subdirectory `%s` was already hooked but '