check for ipv6 address using netaddr.valid_ipv6

This commit is contained in:
Shaun Voigt 2020-04-07 07:44:23 +09:30
parent ba18853509
commit 8dfdd6171d

View file

@ -3,6 +3,7 @@ Clients for dealing with bridge/interface commands.
""" """
import json import json
from typing import Callable from typing import Callable
import netaddr
from core.constants import ETHTOOL_BIN, IP_BIN, OVS_BIN, SYSCTL_BIN, TC_BIN from core.constants import ETHTOOL_BIN, IP_BIN, OVS_BIN, SYSCTL_BIN, TC_BIN
@ -168,7 +169,7 @@ class LinuxNetClient:
) )
else: else:
self.run(f"{IP_BIN} address add {address} dev {device}") self.run(f"{IP_BIN} address add {address} dev {device}")
if ":" in address: if netaddr.valid_ipv6(address.split("/")[0]):
# IPv6 addresses are removed by default on interface down. # IPv6 addresses are removed by default on interface down.
# Make sure that the IPv6 address we add is not removed # Make sure that the IPv6 address we add is not removed
self.run(f"{SYSCTL_BIN} -w net.ipv6.conf.{device}.keep_addr_on_down=1") self.run(f"{SYSCTL_BIN} -w net.ipv6.conf.{device}.keep_addr_on_down=1")