summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Breunig <christian@breunig.cc>2023-07-12 21:05:12 +0200
committerChristian Breunig <christian@breunig.cc>2023-07-12 21:16:56 +0200
commit6e621e42f463d8643b504916a1cc7c967f5bd6f1 (patch)
treed6b17a1fceab9e9aaf8d836576c881640235ac22 /src
parent6a44472d0b94ff225499f61ce057ad7709c9fafc (diff)
downloadvyos-1x-6e621e42f463d8643b504916a1cc7c967f5bd6f1.tar.gz
vyos-1x-6e621e42f463d8643b504916a1cc7c967f5bd6f1.zip
bgp: T5338: simplify XML and code handling
Diffstat (limited to 'src')
-rwxr-xr-xsrc/conf_mode/protocols_bgp.py36
1 files changed, 9 insertions, 27 deletions
diff --git a/src/conf_mode/protocols_bgp.py b/src/conf_mode/protocols_bgp.py
index 532970735..79d97860b 100755
--- a/src/conf_mode/protocols_bgp.py
+++ b/src/conf_mode/protocols_bgp.py
@@ -28,7 +28,7 @@ from vyos.template import is_ip
from vyos.template import is_interface
from vyos.template import render_to_string
from vyos.util import dict_search
-from vyos.util import get_interface_config
+from vyos.utils.network import get_interface_vrf
from vyos.validate import is_addr_assigned
from vyos import ConfigError
from vyos import frr
@@ -56,20 +56,12 @@ def get_config(config=None):
key_mangling=('-', '_'),
get_first_key=True,
no_tag_node_value_mangle=True)
- # if config removed
+
+ # Remove per interface MPLS configuration - get a list if changed
+ # nodes under the interface tagNode
interfaces_removed = node_changed(conf, base + ['interface'])
if interfaces_removed:
bgp['interface_removed'] = list(interfaces_removed)
- # Add vrf mapping in <bgp interface ifname>
- if 'interface' in bgp:
- for interface in bgp['interface']:
- tmp = get_interface_config(interface)
- if dict_search('linkinfo.info_slave_kind', tmp) and \
- tmp['linkinfo']['info_slave_kind'] == 'vrf':
- if 'master' in tmp:
- bgp['interface'][interface]['applied_vrf'] = tmp['master']
- else:
- bgp['interface'][interface]['applied_vrf'] = 'default'
# Assign the name of our VRF context. This MUST be done before the return
# statement below, else on deletion we will delete the default instance
@@ -249,20 +241,10 @@ def verify(bgp):
# Verify vrf on interface and bgp section
if 'interface' in bgp:
- for interface in dict_search('interface', bgp):
- if dict_search(f'interface.{interface}.mpls', bgp):
- if 'forwarding' in bgp['interface'][interface]['mpls']:
- if 'vrf' in bgp:
- if bgp['interface'][interface]['applied_vrf'] != bgp['vrf']:
- raise ConfigError(
- f'Can not set mpls forwarding. Interface {interface} in different vrf')
- else:
- if bgp['interface'][interface]['applied_vrf'] != 'default':
- raise ConfigError(
- f'Can not set mpls forwarding. Interface {interface} in different vrf')
- else:
- raise ConfigError(
- f'<protocols bgp interface {interface}> command should have options')
+ for interface in bgp['interface']:
+ tmp = get_interface_vrf(interface)
+ if ('vrf' in bgp and bgp['vrf'] != tmp) or tmp != 'default':
+ raise ConfigError(f'Interface "{interface}" belongs to different VRF instance!')
# Common verification for both peer-group and neighbor statements
for neighbor in ['neighbor', 'peer_group']:
@@ -554,7 +536,7 @@ def apply(bgp):
frr_cfg.load_configuration(bgp_daemon)
- #If bgp interface config removed
+ # Remove interface specific config
for key in ['interface', 'interface_removed']:
if key not in bgp:
continue