Commit 2163b10a authored by Guillaume Hervier's avatar Guillaume Hervier Committed by Rafael Monnerat

portredir: Correctly format destination IPv6

parent 45468431
......@@ -10,6 +10,11 @@ from zope import interface
logger = logging.getLogger(__name__)
def _format_ip_addr(ip_addr):
if ip_addr.version == 6:
return '[{}]'.format(ip_addr)
return str(ip_addr)
class Manager(object):
interface.implements(IManager)
......@@ -126,7 +131,7 @@ class Manager(object):
command.append(socat_source)
socat_dest_type = '{rtype}{version}'.format(rtype=redir_type.upper(), version=dest_addr.version)
socat_dest = '{}:{}:{}'.format(socat_dest_type, dest_addr, dest_port)
socat_dest = '{}:{}:{}'.format(socat_dest_type, _format_ip_addr(dest_addr), dest_port)
command.append(socat_dest)
# If source port >= 1024, we don't need to run as root
......
......@@ -2783,6 +2783,21 @@ class TestSlapgridWithPortRedirection(MasterMixin, unittest.TestCase):
self.assertIn('socat-tcp-{}'.format(1234), partition_supervisord_config)
self.assertIn('socat TCP4-LISTEN:1234,fork TCP4:127.0.0.1:4321', partition_supervisord_config)
def test_ipv6_port_redirection(self):
with self._mock_requests():
self._setup_instance([
{
'srcPort': 1234,
'destPort': 4321,
'destAddress': '::1',
}
])
# Check the socat command
partition_supervisord_config = self._read_instance_supervisord_config()
self.assertIn('socat-tcp-{}'.format(1234), partition_supervisord_config)
self.assertIn('socat TCP4-LISTEN:1234,fork TCP6:[::1]:4321', partition_supervisord_config)
def test_udp_port_redirection(self):
with self._mock_requests():
self._setup_instance([
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment