From: Ondrej Lichtner <olichtne(a)redhat.com>
Changed the link_local and multicast address types attributes to
properties named:
is_multicast
is_link_local
Also removed a dependecy on hexlify library since we can check the
prefix values directly using the self.addr byte array.
Signed-off-by: Ondrej Lichtner <olichtne(a)redhat.com>
---
lnst/Common/IpAddress.py | 13 ++++++-------
lnst/Devices/VxlanDevice.py | 4 ++--
lnst/Recipes/ENRT/BaseEnrtRecipe.py | 2 +-
lnst/Recipes/ENRT/SimpleMacsecRecipe.py | 2 +-
4 files changed, 10 insertions(+), 11 deletions(-)
diff --git a/lnst/Common/IpAddress.py b/lnst/Common/IpAddress.py
index 3579fa2..ef410c6 100644
--- a/lnst/Common/IpAddress.py
+++ b/lnst/Common/IpAddress.py
@@ -11,9 +11,8 @@
"""
import re
-from socket import inet_pton, inet_ntop, AF_INET, AF_INET6
-from binascii import hexlify
import socket
+from socket import inet_pton, inet_ntop, AF_INET, AF_INET6
from lnst.Common.LnstError import LnstError
#TODO create various generators for IPNetworks and IPaddresses in the same
@@ -74,6 +73,7 @@ def _parse_addr(addr):
return addr, prefixlen
+ @property
def is_multicast(self):
aton = socket.inet_aton
return aton("224.0.0.0") <= self.addr <=
aton("239.255.255.255")
@@ -83,7 +83,6 @@ def __init__(self, addr):
super(Ip6Address, self).__init__(addr)
self.family = AF_INET6
- self.link_local = self.is_link_local()
@staticmethod
def _parse_addr(addr):
@@ -104,13 +103,13 @@ def _parse_addr(addr):
return addr, prefixlen
+ @property
def is_link_local(self):
- left_half = hexlify(socket.inet_pton(socket.AF_INET6, str(self)))[:16]
- return left_half == 'fe80000000000000'
+ return self.addr[:8] == b'\xfe\x80\x00\x00\x00\x00\x00\x00'
+ @property
def is_multicast(self):
- prefix = hexlify(socket.inet_pton(socket.AF_INET6, str(self)))[:2]
- return prefix == 'ff'
+ return self.addr[:1] == b'\xff'
def ipaddress(addr):
"""Factory method to create a BaseIpAddress object"""
diff --git a/lnst/Devices/VxlanDevice.py b/lnst/Devices/VxlanDevice.py
index 130ba5d..780d1b2 100644
--- a/lnst/Devices/VxlanDevice.py
+++ b/lnst/Devices/VxlanDevice.py
@@ -31,10 +31,10 @@ def __init__(self, ifmanager, *args, **kwargs):
if "group" not in kwargs and "remote" not in kwargs:
raise DeviceError("One of group or remote must be specified for
vxlan")
- if kwargs.get("remote", False) and
ipaddress(kwargs["remote"]).is_multicast():
+ if kwargs.get("remote", False) and
ipaddress(kwargs["remote"]).is_multicast:
logging.debug("ATTENTION: non-unicast remote IP set: %s" %
str(kwargs["remote"]))
- if kwargs.get("group", False) and not
ipaddress(kwargs["group"]).is_multicast():
+ if kwargs.get("group", False) and not
ipaddress(kwargs["group"]).is_multicast:
logging.debug("ATTENTION: non-multicast group IP set: %s" %
str(kwargs["group"]))
super(VxlanDevice, self).__init__(ifmanager, *args, **kwargs)
diff --git a/lnst/Recipes/ENRT/BaseEnrtRecipe.py b/lnst/Recipes/ENRT/BaseEnrtRecipe.py
index 95678aa..249fffa 100644
--- a/lnst/Recipes/ENRT/BaseEnrtRecipe.py
+++ b/lnst/Recipes/ENRT/BaseEnrtRecipe.py
@@ -193,7 +193,7 @@ def generate_ping_configurations(self, main_config, sub_config):
kwargs.update(family = AF_INET)
elif ipv == "ipv6":
kwargs.update(family = AF_INET6)
- kwargs.update(link_local = False)
+ kwargs.update(is_link_local = False)
client_ips = client_nic.ips_filter(**kwargs)
server_ips = server_nic.ips_filter(**kwargs)
diff --git a/lnst/Recipes/ENRT/SimpleMacsecRecipe.py
b/lnst/Recipes/ENRT/SimpleMacsecRecipe.py
index c8f81d5..47ab907 100644
--- a/lnst/Recipes/ENRT/SimpleMacsecRecipe.py
+++ b/lnst/Recipes/ENRT/SimpleMacsecRecipe.py
@@ -178,7 +178,7 @@ def generate_ping_configurations(self, main_config, sub_config):
kwargs.update(family = AF_INET)
elif ipv == "ipv6":
kwargs.update(family = AF_INET6)
- kwargs.update(link_local = False)
+ kwargs.update(is_link_local = False)
client_ips = client_nic.ips_filter(**kwargs)
server_ips = server_nic.ips_filter(**kwargs)
--
2.21.0