Skip to content
Permalink
Browse files

Merge pull request #1016 from iocage/NAS-102815

NAS-102815 / 11.3 / Rollback specific ipv6 changes
  • Loading branch information...
sonicaj committed Aug 9, 2019
2 parents d298ad4 + 96ed187 commit 056efd6cbca2364bd54f7bef80ced2a440173c2f
Showing with 45 additions and 49 deletions.
  1. +36 −24 iocage_lib/ioc_start.py
  2. +9 −25 tests/unit_tests/1000_lib_start_test.py
@@ -988,6 +988,32 @@ def start_network(self, vnet, nat=False):
lambda v: v[0] != 'none' and v[1] != 'none',
net_configs
):
if ipv6:
# When we have ipv6, it is possible that default route
# is "fe80::20d:b9ff:fe33:8716%interface0"
# Now interface here is default gateway of the host
# machine which the jail isn't aware of. In the jail
# when adding default route, the value of interface
# should be the default gateway of the jail. Let's
# correct that behavior.
defined_interfaces = [i.split(':') for i in nics]
specified_interfaces = [
'vnet0' if '|' not in i else i.split('|')[0]
for i in ip
]
# The default gateway here for the jail would be the
# one which is present first in "defined_interfaces"
# and also in "specified_interfaces".
default_gw = 'vnet0' # Defaulting to vnet0
for i in defined_interfaces:
if i in specified_interfaces:
default_gw = i
break
default_route = f'{default_route.split("%")[0]}' \
f'%{default_gw.replace("vnet", "epair")}b'

self.log.debug(f'Setting default route {default_route}')

try:
iocage_lib.ioc_common.checkoutput(
[
@@ -1360,34 +1386,20 @@ def get_default_interface(self):

def get_default_gateway(self, address_family='ipv4'):
gateway = self.host_gateways[address_family]['gateway']
interface = self.host_gateways[address_family]['interface']
if gateway and '%' in gateway:
interface_bridge_map = self.get_interface_bridge_map()
ipv6 = gateway.split('%')[0]
if interface in interface_bridge_map:
jail_nic = interface_bridge_map[interface][0]
else:
iocage_lib.ioc_common.logit(
{
'level': 'EXCEPTION',
'message': (f'No bridge for interface {interface}'
'found in configuration.')
},
_callback=self.callback,
silent=self.silent)
return f'{ipv6}%{jail_nic.replace("vnet", "epair")}b'
elif gateway:
if gateway:
return gateway
else:
iocage_lib.ioc_common.logit(
{
'level': 'WARNING',
'message': 'No default gateway found'
f' for {address_family}.'
},
_callback=self.callback,
silent=self.silent
)
return 'none'

def get_interface_bridge_map(self):
interface_bridge_map = {}
for interface in self.get('interfaces').split(','):
nic, bridge = interface.split(':')
interface_bridge_map.setdefault(bridge, []).append(nic)
return interface_bridge_map

def get_bridge_members(self, bridge):
return [
x.split()[1] for x in
@@ -97,57 +97,41 @@ def test_should_return_default_interface(mock_logit, test_input, expected):
({'host_gateways': {'ipv4': {'gateway': None,
'interface': None},
'ipv6': {'gateway': None,
'interface': None}},
'interfaces': {'inet0': ['vnet0']}},
'interface': None}}},
{'ipv4': 'none',
'ipv6': 'none'}),
({'host_gateways': {'ipv4': {'gateway': '217.29.43.254',
'interface': 'inet0'},
'ipv6': {'gateway': 'fe80::8%inet0',
'interface': 'inet0'}},
'interfaces': {'inet0': ['vnet0']}},
'interface': 'inet0'}}},
{'ipv4': '217.29.43.254',
'ipv6': 'fe80::8%epair0b'}),
'ipv6': 'fe80::8%inet0'}),
({'host_gateways': {'ipv4': {'gateway': None,
'interface': None},
'ipv6': {'gateway': 'fe80::8%mgmt0',
'interface': 'mgmt0'}},
'interfaces': {'inet0': ['vnet0'], 'mgmt0': ['vnet1']}},
'interface': 'mgmt0'}}},
{'ipv4': 'none',
'ipv6': 'fe80::8%epair1b'}),
'ipv6': 'fe80::8%mgmt0'}),
({'host_gateways': {'ipv4': {'gateway': None,
'interface': None},
'ipv6': {'gateway': 'fe80::8%inet0',
'interface': 'inet0'}},
'interfaces': {'inet0': ['vnet0', 'vnet1'], 'mgmt0': ['vnet2']}},
'interface': 'inet0'}}},
{'ipv4': 'none',
'ipv6': 'fe80::8%epair0b'}),
'ipv6': 'fe80::8%inet0'}),
({'host_gateways': {'ipv4': {'gateway': None,
'interface': None},
'ipv6': {'gateway': 'fe80::8%inet0',
'interface': 'inet0'}},
'interfaces': {'inet0': ['vnet1', 'vnet0'], 'mgmt0': ['vnet2']}},
'interface': 'inet0'}}},
{'ipv4': 'none',
'ipv6': 'fe80::8%epair1b'})])
'ipv6': 'fe80::8%inet0'})])
def test_should_return_default_gateway(test_input, expected):
iocstart = ioc_start.IOCStart("", "", unit_test=True)
iocstart.host_gateways = test_input['host_gateways']
iocstart.get_interface_bridge_map = mock.Mock(
return_value=test_input['interfaces'])
assert iocstart.get_default_gateway() == expected['ipv4']
assert iocstart.get_default_gateway('ipv4') == expected['ipv4']
assert iocstart.get_default_gateway('ipv6') == expected['ipv6']


@pytest.mark.parametrize('interfaces,expected', [
('vnet0:inet0,vnet1:inet0', {'inet0': ['vnet0', 'vnet1']}),
('vnet0:inet0,vnet1:mgmt0', {'inet0': ['vnet0'], 'mgmt0': ['vnet1']})])
def test_get_interface_bridge_map(interfaces, expected):
iocstart = ioc_start.IOCStart("", "", unit_test=True)
iocstart.get = mock.Mock(return_value=interfaces)
assert iocstart.get_interface_bridge_map() == expected


bridge_if_config = """bridge0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
ether 00:00:00:00:00:00
nd6 options=1<PERFORMNUD>

0 comments on commit 056efd6

Please sign in to comment.
You can’t perform that action at this time.