From f71a7461e44a98e862810bed3d0b9d280ee5dae0 Mon Sep 17 00:00:00 2001 From: Thomas Mangin Date: Mon, 23 Mar 2020 02:35:46 +0000 Subject: tunnel: T31: add support for vrf on tunnels --- interface-definitions/interfaces-tunnel.xml.in | 1 + python/vyos/ifconfig/control.py | 4 ++-- python/vyos/ifconfig/interface.py | 9 +++++++-- src/conf_mode/interfaces-tunnel.py | 6 ++++-- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/interface-definitions/interfaces-tunnel.xml.in b/interface-definitions/interfaces-tunnel.xml.in index 848d6a1c7..c66628ec8 100644 --- a/interface-definitions/interfaces-tunnel.xml.in +++ b/interface-definitions/interfaces-tunnel.xml.in @@ -21,6 +21,7 @@ #include #include #include + #include #include diff --git a/python/vyos/ifconfig/control.py b/python/vyos/ifconfig/control.py index 635b626e8..89deba40a 100644 --- a/python/vyos/ifconfig/control.py +++ b/python/vyos/ifconfig/control.py @@ -48,7 +48,7 @@ class Control: """ Using the defined names, set data write to sysfs. """ - if not value: + if not value and not self._command_set[name].get('force', False): return None # the code can pass int as int @@ -108,7 +108,7 @@ class Control: """ Using the defined names, set data write to sysfs. """ - if not value: + if not value and not self._sysfs_set[name].get('force', False): return None # the code can pass int as int diff --git a/python/vyos/ifconfig/interface.py b/python/vyos/ifconfig/interface.py index 21ffa88f6..9de24d729 100644 --- a/python/vyos/ifconfig/interface.py +++ b/python/vyos/ifconfig/interface.py @@ -89,7 +89,12 @@ class Interface(Control): 'shellcmd': 'ip link set dev {ifname} master {value}', }, 'del_vrf': { - 'shellcmd': 'ip link set dev {ifname} nomaster {value}', + 'shellcmd': 'ip link set dev {ifname} nomaster', + }, + 'vrf': { + 'force': True, + 'convert': lambda v: f'master {v}' if v else 'nomaster', + 'shellcmd': 'ip link set dev {ifname} {value}', }, } @@ -308,7 +313,7 @@ class Interface(Control): """ self.set_interface('add_vrf', vrf) - def del_vrf(self, vrf): + def del_vrf(self, vrf=''): """ Remove interface from given VRF instance. diff --git a/src/conf_mode/interfaces-tunnel.py b/src/conf_mode/interfaces-tunnel.py index 67b58719b..3d4f26374 100755 --- a/src/conf_mode/interfaces-tunnel.py +++ b/src/conf_mode/interfaces-tunnel.py @@ -129,6 +129,7 @@ class ConfigurationState (Config): default_config_data = { # interface definition + 'vrf': '', 'addresses-add': [], 'addresses-del': [], 'state': 'up', @@ -180,6 +181,7 @@ mapping = { 'dhcp-interface': ('dhcp-interface', False, None), 'state': ('disable', False, 'down'), 'link_detect': ('disable-link-detect', False, 2), + 'vrf': ('vrf', False, None), 'addresses-add': ('address', True, None), } @@ -326,7 +328,7 @@ def verify(conf): # what are the tunnel options we can set / modified / deleted kls = get_class(options) - valid = kls.updates + ['alias', 'addresses-add', 'addresses-del'] + valid = kls.updates + ['alias', 'addresses-add', 'addresses-del', 'vrf'] if changes['section'] == 'create': valid.extend(['type',]) @@ -466,7 +468,7 @@ def apply(conf): tunnel.set_interface(option, options[option]) # set other interface properties - for option in ('alias', 'mtu', 'link_detect', 'multicast', 'allmulticast'): + for option in ('alias', 'mtu', 'link_detect', 'multicast', 'allmulticast', 'vrf'): tunnel.set_interface(option, options[option]) # Configure interface address(es) -- cgit v1.2.3