This patch adds new device SitDevice to setup a sit tunnel device.
Signed-off-by: Jan Tluka jtluka@redhat.com --- lnst/Devices/SitDevice.py | 68 +++++++++++++++++++++++++++++++++++++++ lnst/Devices/__init__.py | 2 ++ 2 files changed, 70 insertions(+) create mode 100644 lnst/Devices/SitDevice.py
diff --git a/lnst/Devices/SitDevice.py b/lnst/Devices/SitDevice.py new file mode 100644 index 00000000..a509e110 --- /dev/null +++ b/lnst/Devices/SitDevice.py @@ -0,0 +1,68 @@ +""" +Defines the SitDevice class. + +Copyright 2021 Red Hat, Inc. +Licensed under the GNU General Public License, version 2 as +published by the Free Software Foundation; see COPYING for details. +""" + +__author__ = """ +jtluka@redhat.com (Jan Tluka) +""" + +from lnst.Common.IpAddress import ipaddress +from lnst.Devices.SoftDevice import SoftDevice +from lnst.Common.DeviceError import DeviceError + +class SitDevice(SoftDevice): + _name_template = "t_sit" + _link_type = "sit" + _mandatory_opts = ["local", "remote"] + _mode_mapping = { + 'any': 0, + 'ipv6/ipv4': 41, + 'ip6ip': 41, + 'ipip': 4, + 'ip4ip4': 4, + 'mpls/ipv4': 137, + 'mplsip': 137 + } + + def __init__(self, ifmanager, *args, **kwargs): + if kwargs.get("mode", False) and not kwargs['mode'] in self._mode_mapping: + raise DeviceError("Invalid mode specified for the sit device") + + super(SitDevice, self).__init__(ifmanager, *args, **kwargs) + + @property + def local(self): + try: + return ipaddress(self._get_linkinfo_data_attr("IFLA_SIT_LOCAL")) + except: + return None + + @local.setter + def local(self, val): + self._set_linkinfo_data_attr("IFLA_SIT_LOCAL", str(ipaddress(val))) + self._nl_link_sync("set") + + @property + def remote(self): + try: + return ipaddress(self._get_linkinfo_data_attr("IFLA_SIT_REMOTE")) + except: + return None + + @remote.setter + def remote(self, val): + self._set_linkinfo_data_attr("IFLA_SIT_REMOTE", str(ipaddress(val))) + self._nl_link_sync("set") + + @property + def mode(self): + return self._get_linkinfo_data_attr("IFLA_SIT_PROTO") + + @mode.setter + def mode(self, val): + self._set_linkinfo_data_attr("IFLA_SIT_PROTO", self._mode_mapping[val]) + self._nl_link_sync("set") diff --git a/lnst/Devices/__init__.py b/lnst/Devices/__init__.py index 2a604de8..4f68cb50 100644 --- a/lnst/Devices/__init__.py +++ b/lnst/Devices/__init__.py @@ -9,6 +9,7 @@ from lnst.Devices.VlanDevice import VlanDevice from lnst.Devices.VxlanDevice import VxlanDevice from lnst.Devices.GreDevice import GreDevice from lnst.Devices.Ip6GreDevice import Ip6GreDevice +from lnst.Devices.SitDevice import SitDevice from lnst.Devices.VtiDevice import VtiDevice, Vti6Device from lnst.Devices.VethDevice import VethDevice, PairedVethDevice from lnst.Devices.VethPair import VethPair @@ -24,6 +25,7 @@ device_classes = [ ("VxlanDevice", VxlanDevice), ("GreDevice", GreDevice), ("Ip6GreDevice", Ip6GreDevice), + ("SitDevice", SitDevice), ("VethDevice", VethDevice), ("PairedVethDevice", PairedVethDevice), ("VtiDevice", VtiDevice),