From fe8d884b564e1758216b6a2db025bf1b22e56fa7 Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Fri, 20 Nov 2020 14:05:39 +0100 Subject: tunnel: T3072: support changing tunnel encapsulation on-the-fly --- python/vyos/ifconfig/tunnel.py | 36 +++++++----------------------------- 1 file changed, 7 insertions(+), 29 deletions(-) (limited to 'python') diff --git a/python/vyos/ifconfig/tunnel.py b/python/vyos/ifconfig/tunnel.py index 7264b6296..4040187e7 100644 --- a/python/vyos/ifconfig/tunnel.py +++ b/python/vyos/ifconfig/tunnel.py @@ -85,7 +85,6 @@ class _Tunnel(Interface): updates = [] create = '' - change = '' delete = '' ip = [] # AFI of the families which can be used in the tunnel @@ -107,21 +106,14 @@ class _Tunnel(Interface): cmd = self.delete.format(**self.config) return self._cmd(cmd) - def set_interface(self, option, value): - try: - return Interface.set_interface(self, option, value) - except Exception: - pass - - if value == '': - # remove the value so that it is not used - self.config.pop(option, '') - - if self.change: - self._cmd('{} {} {}'.format( - self.change.format(**self.config), option, value)) - return True + def change_options(self): + change = 'ip tunnel cha {ifname} mode {type}' + # add " option-name option-name-value ..." for all options set + options = " ".join(["{} {}".format(k, self.config[k]) + for k in self.options if k in self.config and self.config[k]]) + print(options) + self._cmd('{} {}'.format(change.format(**self.config), options)) @classmethod def get_config(cls): @@ -229,7 +221,6 @@ class GRETapIf(_Tunnel): updates = ['mtu', ] create = 'ip link add {ifname} type {type}' - change = '' delete = 'ip link del {ifname}' @@ -255,18 +246,8 @@ class IP6GREIf(_Tunnel): 'mtu', 'multicast', 'allmulticast'] create = 'ip tunnel add {ifname} mode {type}' - change = 'ip tunnel cha {ifname} mode {type}' delete = 'ip tunnel del {ifname}' - # using "ip tunnel change" without using "mode" causes errors - # sudo ip tunnel add tun100 mode ip6gre local ::1 remote 1::1 - # sudo ip tunnel cha tun100 hoplimit 100 - # *** stack smashing detected ** *: < unknown > terminated - # sudo ip tunnel cha tun100 local: : 2 - # Error: an IP address is expected rather than "::2" - # works if mode is explicit - - class IPIPIf(_Tunnel): """ IPIP: IP Encapsulation within IP @@ -289,7 +270,6 @@ class IPIPIf(_Tunnel): 'mtu', 'multicast', 'allmulticast'] create = 'ip tunnel add {ifname} mode {type}' - change = 'ip tunnel cha {ifname}' delete = 'ip tunnel del {ifname}' @@ -314,7 +294,6 @@ class IPIP6If(_Tunnel): 'mtu', 'multicast', 'allmulticast'] create = 'ip -6 tunnel add {ifname} mode {type}' - change = 'ip -6 tunnel cha {ifname}' delete = 'ip -6 tunnel del {ifname}' @@ -350,7 +329,6 @@ class SitIf(_Tunnel): 'mtu', 'multicast', 'allmulticast'] create = 'ip tunnel add {ifname} mode {type}' - change = 'ip tunnel cha {ifname}' delete = 'ip tunnel del {ifname}' -- cgit v1.2.3