From: Christos Sfakianakis <csfakian(a)redhat.com>
Add "link_local" attribute in Ip6Address to be used for filtering
off ipv6 link-local addresses when this is desirable (e.g by using
the "ips_filter" method of the Device module). The value of this
attribute is determined by the "is_link_local" method.
Signed-off-by: Christos Sfakianakis <csfakian(a)redhat.com>
---
lnst/Common/IpAddress.py | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/lnst/Common/IpAddress.py b/lnst/Common/IpAddress.py
index e54553d..53dc047 100644
--- a/lnst/Common/IpAddress.py
+++ b/lnst/Common/IpAddress.py
@@ -12,6 +12,8 @@ olichtne(a)redhat.com (Ondrej Lichtner)
import re
from socket import inet_pton, inet_ntop, AF_INET, AF_INET6
+from binascii import hexlify
+import socket
from lnst.Common.LnstError import LnstError
#TODO create various generators for IPNetworks and IPaddresses in the same
@@ -77,6 +79,7 @@ class Ip6Address(BaseIpAddress):
super(Ip6Address, self).__init__(addr)
self.family = AF_INET6
+ self.link_local = self.is_link_local()
@staticmethod
def _parse_addr(addr):
@@ -97,6 +100,10 @@ class Ip6Address(BaseIpAddress):
return addr, prefixlen
+ def is_link_local(self):
+ left_half = hexlify(socket.inet_pton(socket.AF_INET6, str(self)))[:16]
+ return left_half == 'fe80000000000000'
+
def ipaddress(addr):
"""Factory method to create a BaseIpAddress object"""
if isinstance(addr, BaseIpAddress):
--
2.17.1
Show replies by thread