From 77f75b406d84cb799b03fd3977a3c9407af69a5b Mon Sep 17 00:00:00 2001 From: Sol Jerome Date: Sun, 8 Jul 2012 16:24:06 -0500 Subject: Add IPv6 support Signed-off-by: Sol Jerome --- src/lib/Bcfg2/Component.py | 11 +++++++---- src/lib/Bcfg2/Proxy.py | 10 +++++++++- src/lib/Bcfg2/SSLServer.py | 11 ++++++++++- 3 files changed, 26 insertions(+), 6 deletions(-) (limited to 'src') 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 -- cgit v1.2.3-1-g7c22