summaryrefslogtreecommitdiff
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
parent6a44472d0b94ff225499f61ce057ad7709c9fafc (diff)
downloadvyos-1x-6e621e42f463d8643b504916a1cc7c967f5bd6f1.tar.gz
vyos-1x-6e621e42f463d8643b504916a1cc7c967f5bd6f1.zip
bgp: T5338: simplify XML and code handling
-rw-r--r--data/templates/frr/bgpd.frr.j27
-rw-r--r--interface-definitions/include/bgp/protocol-common-config.xml.i6
-rw-r--r--python/vyos/utils/__init__.py1
-rw-r--r--python/vyos/utils/network.py11
-rwxr-xr-xsrc/conf_mode/protocols_bgp.py36
5 files changed, 26 insertions, 35 deletions
diff --git a/data/templates/frr/bgpd.frr.j2 b/data/templates/frr/bgpd.frr.j2
index 9cfc8b7cd..ddfba2306 100644
--- a/data/templates/frr/bgpd.frr.j2
+++ b/data/templates/frr/bgpd.frr.j2
@@ -565,13 +565,14 @@ bgp route-reflector allow-outbound-policy
timers bgp {{ timers.keepalive }} {{ timers.holdtime }}
{% endif %}
exit
+!
{% if interface is vyos_defined %}
{% for iface, iface_config in interface.items() %}
- interface {{ iface }}
+interface {{ iface }}
{% if iface_config.mpls.forwarding is vyos_defined %}
mpls bgp forwarding
{% endif %}
- exit
- !
+exit
+!
{% endfor %}
{% endif %}
diff --git a/interface-definitions/include/bgp/protocol-common-config.xml.i b/interface-definitions/include/bgp/protocol-common-config.xml.i
index dde7fc8c7..12024ed8b 100644
--- a/interface-definitions/include/bgp/protocol-common-config.xml.i
+++ b/interface-definitions/include/bgp/protocol-common-config.xml.i
@@ -840,7 +840,7 @@
</node>
<tagNode name="interface">
<properties>
- <help>Enable MPLS on Interface</help>
+ <help>Configure interface related parameters, e.g. MPLS</help>
<completionHelp>
<script>${vyos_completion_dir}/list_interfaces</script>
</completionHelp>
@@ -855,12 +855,12 @@
<children>
<node name="mpls">
<properties>
- <help> MPLS options</help>
+ <help>MPLS options</help>
</properties>
<children>
<leafNode name="forwarding">
<properties>
- <help> Enable MPLS forwarding for eBGP directly connected peers</help>
+ <help>Enable MPLS forwarding for eBGP directly connected peers</help>
<valueless/>
</properties>
</leafNode>
diff --git a/python/vyos/utils/__init__.py b/python/vyos/utils/__init__.py
index 0d3998053..5c7a9ecb8 100644
--- a/python/vyos/utils/__init__.py
+++ b/python/vyos/utils/__init__.py
@@ -14,3 +14,4 @@
# License along with this library. If not, see <http://www.gnu.org/licenses/>.
from vyos.utils import network
+from vyos.utils import boot
diff --git a/python/vyos/utils/network.py b/python/vyos/utils/network.py
index 7386d44f0..209bc9ecc 100644
--- a/python/vyos/utils/network.py
+++ b/python/vyos/utils/network.py
@@ -13,8 +13,6 @@
# You should have received a copy of the GNU Lesser General Public
# License along with this library. If not, see <http://www.gnu.org/licenses/>.
-import os
-
def get_protocol_by_name(protocol_name):
"""Get protocol number by protocol name
@@ -34,3 +32,12 @@ def interface_exists_in_netns(interface_name, netns):
if rc == 0:
return True
return False
+
+def get_interface_vrf(interface):
+ """ Returns VRF of given interface """
+ from vyos.util import dict_search
+ from vyos.util import get_interface_config
+ tmp = get_interface_config(interface)
+ if dict_search('linkinfo.info_slave_kind', tmp) == 'vrf':
+ return tmp['master']
+ return 'default'
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