summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSol Jerome <sol.jerome@gmail.com>2012-07-08 16:24:06 -0500
committerSol Jerome <sol.jerome@gmail.com>2012-07-08 16:24:06 -0500
commit77f75b406d84cb799b03fd3977a3c9407af69a5b (patch)
treeb842f6b1090be2ea0dcc22793260c4660ebae1e5
parent95debe731f8621b4ada9218e9f8ab8fecadf163a (diff)
downloadbcfg2-77f75b406d84cb799b03fd3977a3c9407af69a5b.tar.gz
bcfg2-77f75b406d84cb799b03fd3977a3c9407af69a5b.tar.bz2
bcfg2-77f75b406d84cb799b03fd3977a3c9407af69a5b.zip
Add IPv6 support
Signed-off-by: Sol Jerome <sol.jerome@gmail.com>
-rw-r--r--src/lib/Bcfg2/Component.py11
-rw-r--r--src/lib/Bcfg2/Proxy.py10
-rw-r--r--src/lib/Bcfg2/SSLServer.py11
3 files changed, 26 insertions, 6 deletions
diff --git a/src/lib/Bcfg2/Component.py b/src/lib/Bcfg2/Component.py
index eb9ea166a..b6cea3e22 100644
--- a/src/lib/Bcfg2/Component.py
+++ b/src/lib/Bcfg2/Component.py
@@ -6,6 +6,7 @@ import inspect
import logging
import os
import pydoc
+import socket
import sys
import time
import threading
@@ -59,12 +60,14 @@ def run_component(component_cls, listen_all, location, daemon, pidfile_name,
pidfile.close()
component = component_cls(cfile=cfile, **cls_kwargs)
- up = urlparse(location)
- port = tuple(up[1].split(':'))
- port = (port[0], int(port[1]))
+ hostname, port = urlparse(location)[1].split(':')
+ server_address = socket.getaddrinfo(hostname,
+ port,
+ socket.AF_UNSPEC,
+ socket.SOCK_STREAM)[0][4]
try:
server = XMLRPCServer(listen_all,
- port,
+ server_address,
keyfile=keyfile,
certfile=certfile,
register=register,
diff --git a/src/lib/Bcfg2/Proxy.py b/src/lib/Bcfg2/Proxy.py
index 422d642db..eff9544da 100644
--- a/src/lib/Bcfg2/Proxy.py
+++ b/src/lib/Bcfg2/Proxy.py
@@ -192,7 +192,15 @@ class SSLHTTPConnection(httplib.HTTPConnection):
def _connect_py26ssl(self):
"""Initiates a connection using the ssl module."""
- rawsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+ # check for IPv6
+ hostip = socket.getaddrinfo(self.host,
+ self.port,
+ socket.AF_UNSPEC,
+ socket.SOCK_STREAM)[0][4][0]
+ if ':' in hostip:
+ rawsock = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
+ else:
+ rawsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
if self.protocol == 'xmlrpc/ssl':
ssl_protocol_ver = ssl.PROTOCOL_SSLv23
elif self.protocol == 'xmlrpc/tlsv1':
diff --git a/src/lib/Bcfg2/SSLServer.py b/src/lib/Bcfg2/SSLServer.py
index 33707eda8..aef44e419 100644
--- a/src/lib/Bcfg2/SSLServer.py
+++ b/src/lib/Bcfg2/SSLServer.py
@@ -98,14 +98,23 @@ class SSLServer (SocketServer.TCPServer, object):
timeout -- timeout for non-blocking request handling
"""
-
+ # check whether or not we should listen on all interfaces
if listen_all:
listen_address = ('', server_address[1])
else:
listen_address = (server_address[0], server_address[1])
+
+ # check for IPv6 address
+ if ':' in server_address[0]:
+ self.address_family = socket.AF_INET6
+
try:
SocketServer.TCPServer.__init__(self, listen_address,
RequestHandlerClass)
+ except socket.gaierror:
+ e = sys.exc_info()[1]
+ self.logger.error("Failed to bind to socket: %s" % e)
+ raise
except socket.error:
self.logger.error("Failed to bind to socket")
raise