diff options
| author | Christian Poessinger <christian@poessinger.com> | 2022-07-25 20:51:37 +0200 | 
|---|---|---|
| committer | Christian Poessinger <christian@poessinger.com> | 2022-07-25 20:51:37 +0200 | 
| commit | 8274e9706adf33544e4c990134e65a0ddee976d8 (patch) | |
| tree | be94fdfcd974188e4129f4b62f0b04bb163f0ea2 | |
| parent | 96d2939780dcd3db0353f46faf72a71905ccbbe5 (diff) | |
| download | vyos-1x-8274e9706adf33544e4c990134e65a0ddee976d8.tar.gz vyos-1x-8274e9706adf33544e4c990134e65a0ddee976d8.zip | |
bgp: T4560: neighbor/peer-group local-as option is only allowed for eBGP
| -rwxr-xr-x | smoketest/scripts/cli/test_protocols_bgp.py | 26 | ||||
| -rwxr-xr-x | src/conf_mode/protocols_bgp.py | 6 | 
2 files changed, 32 insertions, 0 deletions
| diff --git a/smoketest/scripts/cli/test_protocols_bgp.py b/smoketest/scripts/cli/test_protocols_bgp.py index 9c0c93779..009dbc803 100755 --- a/smoketest/scripts/cli/test_protocols_bgp.py +++ b/smoketest/scripts/cli/test_protocols_bgp.py @@ -921,5 +921,31 @@ class TestProtocolsBGP(VyOSUnitTestSHIM.TestCase):          self.assertIn(f' neighbor {peer_group} peer-group', frrconfig)          self.assertIn(f' neighbor {peer_group} remote-as {remote_asn}', frrconfig) +    def test_bgp_15_local_as_ebgp(self): +        # https://phabricator.vyos.net/T4560 +        # local-as allowed only for ebgp peers + +        neighbor = '192.0.2.99' +        remote_asn = '500' +        local_asn = '400' + +        self.cli_set(base_path + ['local-as', ASN]) +        self.cli_set(base_path + ['neighbor', neighbor, 'remote-as', ASN]) +        self.cli_set(base_path + ['neighbor', neighbor, 'local-as', local_asn]) + +        # check validate() - local-as allowed only for ebgp peers +        with self.assertRaises(ConfigSessionError): +            self.cli_commit() + +        self.cli_set(base_path + ['neighbor', neighbor, 'remote-as', remote_asn]) + +        self.cli_commit() + +        frrconfig = self.getFRRconfig(f'router bgp {ASN}') +        self.assertIn(f'router bgp {ASN}', frrconfig) +        self.assertIn(f' neighbor {neighbor} remote-as {remote_asn}', frrconfig) +        self.assertIn(f' neighbor {neighbor} local-as {local_asn}', frrconfig) + +  if __name__ == '__main__':      unittest.main(verbosity=2) diff --git a/src/conf_mode/protocols_bgp.py b/src/conf_mode/protocols_bgp.py index 5aa643476..7d3687094 100755 --- a/src/conf_mode/protocols_bgp.py +++ b/src/conf_mode/protocols_bgp.py @@ -213,6 +213,12 @@ def verify(bgp):                      if 'source_interface' in peer_config['interface']:                          raise ConfigError(f'"source-interface" option not allowed for neighbor "{peer}"') +            # Local-AS allowed only for EBGP peers +            if 'local_as' in peer_config: +                remote_as = verify_remote_as(peer_config, bgp) +                if remote_as == bgp['local_as']: +                    raise ConfigError(f'local-as configured for "{peer}", allowed only for eBGP peers!') +              for afi in ['ipv4_unicast', 'ipv4_multicast', 'ipv4_labeled_unicast', 'ipv4_flowspec',                          'ipv6_unicast', 'ipv6_multicast', 'ipv6_labeled_unicast', 'ipv6_flowspec',                          'l2vpn_evpn']: | 
