summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2020-03-23 12:57:34 +0100
committerGitHub <noreply@github.com>2020-03-23 12:57:34 +0100
commit52e20fa562968dcfd7b524031f0cad2b6f4fff57 (patch)
tree8adba1fa5916b47a65b1b77f4b490e0b1fe6d1ae
parentcefed7ae3fbbb93142051633ff00d3a9e19889c0 (diff)
parent193d0f416807b3eb5980dcf209e93774282b85f3 (diff)
downloadvyos-1x-52e20fa562968dcfd7b524031f0cad2b6f4fff57.tar.gz
vyos-1x-52e20fa562968dcfd7b524031f0cad2b6f4fff57.zip
Merge pull request #258 from thomas-mangin/31-vrf
tunnel: T31: fix vrf deletion, add support for vrf on tunnels
-rw-r--r--interface-definitions/interfaces-tunnel.xml.in1
-rw-r--r--python/vyos/ifconfig/control.py4
-rw-r--r--python/vyos/ifconfig/interface.py28
-rw-r--r--python/vyos/ifconfig_vlan.py7
-rwxr-xr-xsrc/conf_mode/interfaces-bonding.py7
-rwxr-xr-xsrc/conf_mode/interfaces-bridge.py7
-rwxr-xr-xsrc/conf_mode/interfaces-dummy.py7
-rwxr-xr-xsrc/conf_mode/interfaces-ethernet.py7
-rwxr-xr-xsrc/conf_mode/interfaces-pseudo-ethernet.py7
-rwxr-xr-xsrc/conf_mode/interfaces-tunnel.py6
-rwxr-xr-xsrc/conf_mode/interfaces-wireless.py7
11 files changed, 30 insertions, 58 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/address-ipv4-ipv6.xml.i>
#include <include/interface-disable.xml.i>
#include <include/interface-disable-link-detect.xml.i>
+ #include <include/interface-vrf.xml.i>
#include <include/interface-mtu-64-8024.xml.i>
<leafNode name="local-ip">
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..718fe93db 100644
--- a/python/vyos/ifconfig/interface.py
+++ b/python/vyos/ifconfig/interface.py
@@ -85,11 +85,10 @@ class Interface(Control):
'validate': assert_mac,
'shellcmd': 'ip link set dev {ifname} address {value}',
},
- 'add_vrf': {
- 'shellcmd': 'ip link set dev {ifname} master {value}',
- },
- 'del_vrf': {
- 'shellcmd': 'ip link set dev {ifname} nomaster {value}',
+ 'vrf': {
+ 'force': True,
+ 'convert': lambda v: f'master {v}' if v else 'nomaster',
+ 'shellcmd': 'ip link set dev {ifname} {value}',
},
}
@@ -298,25 +297,16 @@ class Interface(Control):
"""
self.set_interface('mac', mac)
- def add_vrf(self, vrf):
- """
- Add interface to given VRF instance.
-
- Example:
- >>> from vyos.ifconfig import Interface
- >>> Interface('eth0').add_vrf('foo')
- """
- self.set_interface('add_vrf', vrf)
-
- def del_vrf(self, vrf):
+ def set_vrf(self, vrf=''):
"""
- Remove interface from given VRF instance.
+ Add/Remove interface from given VRF instance.
Example:
>>> from vyos.ifconfig import Interface
- >>> Interface('eth0').del_vrf('foo')
+ >>> Interface('eth0').set_vrf('foo')
+ >>> Interface('eth0').set_vrf()
"""
- self.set_interface('del_vrf', vrf)
+ self.set_interface('vrf', vrf)
def set_arp_cache_tmo(self, tmo):
"""
diff --git a/python/vyos/ifconfig_vlan.py b/python/vyos/ifconfig_vlan.py
index 1d57283ac..fe94a5af4 100644
--- a/python/vyos/ifconfig_vlan.py
+++ b/python/vyos/ifconfig_vlan.py
@@ -68,11 +68,8 @@ def apply_vlan_config(vlan, config):
# Maximum Transmission Unit (MTU)
vlan.set_mtu(config['mtu'])
- # assign to VRF
- if config['vrf']:
- vlan.add_vrf(config['vrf'])
- else:
- vlan.del_vrf(config['vrf'])
+ # assign/remove VRF
+ vlan.set_vrf(config['vrf'])
# Change VLAN interface MAC address
if config['mac']:
diff --git a/src/conf_mode/interfaces-bonding.py b/src/conf_mode/interfaces-bonding.py
index a75beabd1..03df6e16a 100755
--- a/src/conf_mode/interfaces-bonding.py
+++ b/src/conf_mode/interfaces-bonding.py
@@ -461,11 +461,8 @@ def apply(bond):
for addr in bond['address']:
b.add_addr(addr)
- # assign to VRF
- if bond['vrf']:
- b.add_vrf(bond['vrf'])
- else:
- b.del_vrf(bond['vrf'])
+ # assign/remove VRF
+ b.set_vrf(bond['vrf'])
# remove no longer required service VLAN interfaces (vif-s)
for vif_s in bond['vif_s_remove']:
diff --git a/src/conf_mode/interfaces-bridge.py b/src/conf_mode/interfaces-bridge.py
index f189ce36d..f8f20bf5c 100755
--- a/src/conf_mode/interfaces-bridge.py
+++ b/src/conf_mode/interfaces-bridge.py
@@ -295,11 +295,8 @@ def apply(bridge):
# store DHCPv6 config dictionary - used later on when addresses are aquired
br.set_dhcpv6_options(opt)
- # assign to VRF
- if bridge['vrf']:
- br.add_vrf(bridge['vrf'])
- else:
- br.del_vrf(bridge['vrf'])
+ # assign/remove VRF
+ br.set_vrf(bridge['vrf'])
# Change interface MAC address
if bridge['mac']:
diff --git a/src/conf_mode/interfaces-dummy.py b/src/conf_mode/interfaces-dummy.py
index 10cae5d7d..bf55b13ec 100755
--- a/src/conf_mode/interfaces-dummy.py
+++ b/src/conf_mode/interfaces-dummy.py
@@ -105,11 +105,8 @@ def apply(dummy):
for addr in dummy['address']:
d.add_addr(addr)
- # assign to VRF
- if dummy['vrf']:
- d.add_vrf(dummy['vrf'])
- else:
- d.del_vrf(dummy['vrf'])
+ # assign/remove VRF
+ d.set_vrf(dummy['vrf'])
# disable interface on demand
if dummy['disable']:
diff --git a/src/conf_mode/interfaces-ethernet.py b/src/conf_mode/interfaces-ethernet.py
index ba3a5e8c8..2f5d796b4 100755
--- a/src/conf_mode/interfaces-ethernet.py
+++ b/src/conf_mode/interfaces-ethernet.py
@@ -369,11 +369,8 @@ def apply(eth):
for addr in eth['address']:
e.add_addr(addr)
- # assign to VRF
- if eth['vrf']:
- e.add_vrf(eth['vrf'])
- else:
- e.del_vrf(eth['vrf'])
+ # assign/remove VRF
+ e.set_vrf(eth['vrf'])
# remove no longer required service VLAN interfaces (vif-s)
for vif_s in eth['vif_s_remove']:
diff --git a/src/conf_mode/interfaces-pseudo-ethernet.py b/src/conf_mode/interfaces-pseudo-ethernet.py
index 989b1432b..0afae8388 100755
--- a/src/conf_mode/interfaces-pseudo-ethernet.py
+++ b/src/conf_mode/interfaces-pseudo-ethernet.py
@@ -297,11 +297,8 @@ def apply(peth):
# Enable private VLAN proxy ARP on this interface
p.set_proxy_arp_pvlan(peth['ip_proxy_arp_pvlan'])
- # assign to VRF
- if peth['vrf']:
- p.add_vrf(peth['vrf'])
- else:
- p.del_vrf(peth['vrf'])
+ # assign/remove VRF
+ p.set_vrf(peth['vrf'])
# Change interface MAC address
if peth['mac']:
diff --git a/src/conf_mode/interfaces-tunnel.py b/src/conf_mode/interfaces-tunnel.py
index 8c2b3917d..90c1f8f71 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)
diff --git a/src/conf_mode/interfaces-wireless.py b/src/conf_mode/interfaces-wireless.py
index 35ff4567e..8132a396c 100755
--- a/src/conf_mode/interfaces-wireless.py
+++ b/src/conf_mode/interfaces-wireless.py
@@ -1461,11 +1461,8 @@ def apply(wifi):
# ignore link state changes
w.set_link_detect(wifi['disable_link_detect'])
- # assign to VRF
- if wifi['vrf']:
- w.add_vrf(wifi['vrf'])
- else:
- w.del_vrf(wifi['vrf'])
+ # assign/remove VRF
+ w.set_vrf(wifi['vrf'])
# Change interface MAC address - re-set to real hardware address (hw-id)
# if custom mac is removed