diff options
author | Christian Poessinger <christian@poessinger.com> | 2020-03-06 19:48:13 +0100 |
---|---|---|
committer | Christian Poessinger <christian@poessinger.com> | 2020-03-06 19:48:26 +0100 |
commit | 6d403e5d3831fcb1944992e70f0bfa74e1477c74 (patch) | |
tree | 50dded07f3e0b5ee1c5b66fecda857e1a1001f7b | |
parent | 18f8323b7bc22b5b7a8876f4bef8c28b4abe193f (diff) | |
download | vyos-1x-6d403e5d3831fcb1944992e70f0bfa74e1477c74.tar.gz vyos-1x-6d403e5d3831fcb1944992e70f0bfa74e1477c74.zip |
vrf: T31: enable vrf support for ethernet interface
-rw-r--r-- | interface-definitions/interfaces-ethernet.xml.in | 1 | ||||
-rwxr-xr-x | src/conf_mode/interfaces-ethernet.py | 20 |
2 files changed, 19 insertions, 2 deletions
diff --git a/interface-definitions/interfaces-ethernet.xml.in b/interface-definitions/interfaces-ethernet.xml.in index 8f5d7355b..5728d2f37 100644 --- a/interface-definitions/interfaces-ethernet.xml.in +++ b/interface-definitions/interfaces-ethernet.xml.in @@ -31,6 +31,7 @@ </leafNode> #include <include/interface-disable-link-detect.xml.i> #include <include/interface-disable.xml.i> + #include <include/interface-vrf.xml.i> <leafNode name="duplex"> <properties> <help>Duplex mode</help> diff --git a/src/conf_mode/interfaces-ethernet.py b/src/conf_mode/interfaces-ethernet.py index ede62e5e3..67cc56bb2 100755 --- a/src/conf_mode/interfaces-ethernet.py +++ b/src/conf_mode/interfaces-ethernet.py @@ -16,8 +16,9 @@ import os -from copy import deepcopy from sys import exit +from copy import deepcopy +from netifaces import interfaces from vyos.ifconfig import EthernetIf from vyos.ifconfig_vlan import apply_vlan_config @@ -59,7 +60,8 @@ default_config_data = { 'vif_s': [], 'vif_s_remove': [], 'vif': [], - 'vif_remove': [] + 'vif_remove': [], + 'vrf': '' } def get_config(): @@ -197,6 +199,10 @@ def get_config(): if conf.exists('speed'): eth['speed'] = conf.return_value('speed') + # retrieve VRF instance + if conf.exists('vrf'): + eth['vrf'] = conf.return_value('vrf') + # re-set configuration level to parse new nodes conf.set_level(cfg_base) # get vif-s interfaces (currently effective) - to determine which vif-s @@ -243,6 +249,10 @@ def verify(eth): if eth['dhcpv6_prm_only'] and eth['dhcpv6_temporary']: raise ConfigError('DHCPv6 temporary and parameters-only options are mutually exclusive!') + vrf_name = eth['vrf'] + if vrf_name and vrf_name not in interfaces(): + raise ConfigError(f'VRF "{vrf_name}" does not exist') + conf = Config() # some options can not be changed when interface is enslaved to a bond for bond in conf.list_nodes('interfaces bonding'): @@ -367,6 +377,12 @@ 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']) + # remove no longer required service VLAN interfaces (vif-s) for vif_s in eth['vif_s_remove']: e.del_vlan(vif_s) |