Commit 529cf52b authored by Xavier Thompson's avatar Xavier Thompson

slapformat: Fix tap IPv6 prefix

Instead of forcing prefix to /128 for tap IPv6, use noprefixroute
to avoid the unwanted automatic routing.
parent ebe7240e
...@@ -1126,7 +1126,11 @@ class Interface(object): ...@@ -1126,7 +1126,11 @@ class Interface(object):
for q in netifaces.ifaddresses(interface_name)[af] for q in netifaces.ifaddresses(interface_name)[af]
]: ]:
# add an address # add an address
code, _ = callAndRead(['ip', 'addr', 'add', address_string, 'dev', interface_name]) command = ['ip', 'addr', 'add', address_string, 'dev', interface_name]
if tap and ipv6:
# taps are routed manually via the first address in the range
command.append('noprefixroute')
code, _ = callAndRead(command)
if code != 0: if code != 0:
return False return False
...@@ -1293,11 +1297,9 @@ class Interface(object): ...@@ -1293,11 +1297,9 @@ class Interface(object):
address_dict['prefixlen'] = lenNetmaskIpv6(address_dict['netmask']) address_dict['prefixlen'] = lenNetmaskIpv6(address_dict['netmask'])
if tap: if tap:
result_addr = getTapIpv6Range(address_dict, partition_index) result_addr = getTapIpv6Range(address_dict, partition_index)
# the netmask of the tap itself is always 128 bits
result_addr['netmask'] = netmaskFromLenIPv6(128)
else: else:
result_addr = getPartitionIpv6Addr(address_dict, partition_index) result_addr = getPartitionIpv6Addr(address_dict, partition_index)
result_addr['netmask'] = netmaskFromLenIPv6(result_addr['prefixlen']) result_addr['netmask'] = netmaskFromLenIPv6(result_addr['prefixlen'])
if not tap or self._checkIpv6Range(result_addr['addr'], result_addr['prefixlen']): if not tap or self._checkIpv6Range(result_addr['addr'], result_addr['prefixlen']):
if self._addSystemAddress(result_addr['addr'], result_addr['netmask'], tap=tap): if self._addSystemAddress(result_addr['addr'], result_addr['netmask'], tap=tap):
if tap: if tap:
...@@ -1316,8 +1318,6 @@ class Interface(object): ...@@ -1316,8 +1318,6 @@ class Interface(object):
for _ in range(10): for _ in range(10):
if tap: if tap:
result_addr = self._generateRandomIPv6Range(address_dict, suffix='1') result_addr = self._generateRandomIPv6Range(address_dict, suffix='1')
# the netmask of the tap itself is always 128 bits
result_addr['netmask'] = netmaskFromLenIPv6(128)
else: else:
result_addr = self._generateRandomIPv6Addr(address_dict) result_addr = self._generateRandomIPv6Addr(address_dict)
# Checking the validity of the IPv6 address # Checking the validity of the IPv6 address
......
...@@ -495,7 +495,7 @@ class TestComputer(SlapformatMixin): ...@@ -495,7 +495,7 @@ class TestComputer(SlapformatMixin):
self.assertEqual([ self.assertEqual([
'ip tuntap add dev tap mode tap user testuser', 'ip tuntap add dev tap mode tap user testuser',
'ip link set tap up', 'ip link set tap up',
'ip addr add ip/ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff dev tap', 'ip addr add ip/ffff:ffff:ffff:ffff:ffff:: dev tap noprefixroute',
'ip -6 addr list tap', 'ip -6 addr list tap',
'ip -6 route show ip', 'ip -6 route show ip',
'ip -6 route add ip dev tap', 'ip -6 route add ip dev tap',
...@@ -550,7 +550,7 @@ class TestComputer(SlapformatMixin): ...@@ -550,7 +550,7 @@ class TestComputer(SlapformatMixin):
self.assertEqual([ self.assertEqual([
'ip tuntap add dev tap mode tap user testuser', 'ip tuntap add dev tap mode tap user testuser',
'ip link set tap up', 'ip link set tap up',
'ip addr add ip/ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff dev tap', 'ip addr add ip/ffff:ffff:ffff:ffff:ffff:ffff:: dev tap noprefixroute',
'ip -6 addr list tap', 'ip -6 addr list tap',
'ip route show 10.8.0.2', 'ip route show 10.8.0.2',
'ip route add 10.8.0.2 dev tap', 'ip route add 10.8.0.2 dev tap',
......
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