summaryrefslogtreecommitdiff
path: root/src/conf_mode/protocols_bgp.py
diff options
context:
space:
mode:
authoraapostoliuk <a.apostoliuk@vyos.io>2023-07-11 17:04:02 +0300
committeraapostoliuk <a.apostoliuk@vyos.io>2023-07-11 17:32:19 +0300
commitcedf7ecfb6048cce1082d234f9d859f955b0c2cd (patch)
treee9d5439e24180965b762416d11e76ccf5af06662 /src/conf_mode/protocols_bgp.py
parent0586941f7bc3bcd55721d7c44164ef7a2de9423d (diff)
downloadvyos-1x-cedf7ecfb6048cce1082d234f9d859f955b0c2cd.tar.gz
vyos-1x-cedf7ecfb6048cce1082d234f9d859f955b0c2cd.zip
bgp: T5338: Added 'protocols bgp interface <int> mpls forwarding' feature
Added 'protocols bgp interface <int> mpls forwarding' feature. It is possible to permit BGP install VPN prefixes without transport labels. This configuration will install VPN prefixes originated from an e-bgp session, and with the next-hop directly connected.
Diffstat (limited to 'src/conf_mode/protocols_bgp.py')
-rwxr-xr-xsrc/conf_mode/protocols_bgp.py43
1 files changed, 42 insertions, 1 deletions
diff --git a/src/conf_mode/protocols_bgp.py b/src/conf_mode/protocols_bgp.py
index b23584bdb..532970735 100755
--- a/src/conf_mode/protocols_bgp.py
+++ b/src/conf_mode/protocols_bgp.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
#
-# Copyright (C) 2020-2022 VyOS maintainers and contributors
+# Copyright (C) 2020-2023 VyOS maintainers and contributors
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 or later as
@@ -20,6 +20,7 @@ from sys import argv
from vyos.base import Warning
from vyos.config import Config
from vyos.configdict import dict_merge
+from vyos.configdict import node_changed
from vyos.configverify import verify_prefix_list
from vyos.configverify import verify_route_map
from vyos.configverify import verify_vrf
@@ -27,6 +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.validate import is_addr_assigned
from vyos import ConfigError
from vyos import frr
@@ -54,6 +56,20 @@ def get_config(config=None):
key_mangling=('-', '_'),
get_first_key=True,
no_tag_node_value_mangle=True)
+ # if config removed
+ 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
@@ -231,6 +247,23 @@ def verify(bgp):
if 'system_as' not in bgp:
raise ConfigError('BGP system-as number must be defined!')
+ # 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')
+
# Common verification for both peer-group and neighbor statements
for neighbor in ['neighbor', 'peer_group']:
# bail out early if there is no neighbor or peer-group statement
@@ -520,6 +553,14 @@ def apply(bgp):
vrf = ' vrf ' + bgp['vrf']
frr_cfg.load_configuration(bgp_daemon)
+
+ #If bgp interface config removed
+ for key in ['interface', 'interface_removed']:
+ if key not in bgp:
+ continue
+ for interface in bgp[key]:
+ frr_cfg.modify_section(f'^interface {interface}', stop_pattern='^exit', remove_stop_mark=True)
+
frr_cfg.modify_section(f'^router bgp \d+{vrf}', stop_pattern='^exit', remove_stop_mark=True)
if 'frr_bgpd_config' in bgp:
frr_cfg.add_before(frr.default_add_before, bgp['frr_bgpd_config'])