diff --git a/bgpd/bgp_packet.c b/bgpd/bgp_packet.c index 8d479c272320..6f5280c2647c 100644 --- a/bgpd/bgp_packet.c +++ b/bgpd/bgp_packet.c @@ -2015,7 +2015,9 @@ static int bgp_open_receive(struct peer_connection *connection, } (void)peer_sort(peer); } else if (peer->as_type == AS_INTERNAL) { - if (remote_as != peer->bgp->as) { + as_t local_as = peer->change_local_as ? peer->change_local_as : peer->bgp->as; + + if (remote_as != local_as) { if (bgp_debug_neighbor_events(peer)) zlog_debug( "%s bad OPEN, remote AS is %u, internal specified", @@ -2026,7 +2028,7 @@ static int bgp_open_receive(struct peer_connection *connection, notify_data_remote_as, 2); return BGP_Stop; } - peer->as = peer->local_as; + peer->as = peer->change_local_as ? peer->change_local_as : peer->local_as; } else if (peer->as_type == AS_EXTERNAL) { if (remote_as == peer->bgp->as) { if (bgp_debug_neighbor_events(peer)) diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c index 39a21e725d9e..e5ebc919b25d 100644 --- a/bgpd/bgp_vty.c +++ b/bgpd/bgp_vty.c @@ -15839,7 +15839,8 @@ static void bgp_show_peer(struct vty *vty, struct peer *p, uint16_t sh_flags, bo : ""); } /* peer type internal or confed-internal */ - if ((p->as == p->local_as) || (CHECK_FLAG(p->as_type, AS_INTERNAL))) { + if (p->as == p->local_as || (p->change_local_as && p->as == p->change_local_as) || + CHECK_FLAG(p->as_type, AS_INTERNAL)) { if (use_json) { if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)) json_object_boolean_true_add( @@ -15854,7 +15855,7 @@ static void bgp_show_peer(struct vty *vty, struct peer *p, uint16_t sh_flags, bo vty_out(vty, "internal link\n"); } /* peer type external or confed-external */ - } else if (p->as || (p->as_type == AS_EXTERNAL)) { + } else if (p->as || CHECK_FLAG(p->as_type, AS_EXTERNAL)) { if (use_json) { if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)) json_object_boolean_true_add( diff --git a/tests/topotests/bgp_remote_as_auto/r1/frr.conf b/tests/topotests/bgp_remote_as_auto/r1/frr.conf index b1c9038467e6..d919e9d4b869 100644 --- a/tests/topotests/bgp_remote_as_auto/r1/frr.conf +++ b/tests/topotests/bgp_remote_as_auto/r1/frr.conf @@ -14,12 +14,13 @@ router bgp 65001 neighbor 192.168.1.3 remote-as auto neighbor 192.168.1.3 timers 1 3 neighbor 192.168.1.3 timers connect 1 + neighbor 192.168.1.5 remote-as auto + neighbor 192.168.1.5 timers 1 3 + neighbor 192.168.1.5 timers connect 1 + neighbor 192.168.1.5 local-as 65005 no-prepend replace-as neighbor r1-eth1 interface remote-as auto neighbor r1-eth1 timers 1 3 neighbor r1-eth1 timers connect 1 - neighbor 192.168.1.5 remote-as internal - neighbor 192.168.1.5 timers 1 3 - neighbor 192.168.1.5 timers connect 1 address-family ipv4 unicast network 10.0.0.1/32 exit-address-family diff --git a/tests/topotests/bgp_remote_as_auto/r5/frr.conf b/tests/topotests/bgp_remote_as_auto/r5/frr.conf index 05b515b71698..b15a15b8dcff 100644 --- a/tests/topotests/bgp_remote_as_auto/r5/frr.conf +++ b/tests/topotests/bgp_remote_as_auto/r5/frr.conf @@ -6,9 +6,10 @@ router bgp 65001 no bgp ebgp-requires-policy neighbor PG peer-group neighbor 192.168.1.1 peer-group PG - neighbor 192.168.1.1 remote-as auto + neighbor 192.168.1.1 remote-as internal neighbor 192.168.1.1 timers 1 3 neighbor 192.168.1.1 timers connect 1 + neighbor 192.168.1.1 local-as 65005 no-prepend replace-as neighbor 192.168.1.2 peer-group PG neighbor 192.168.1.2 remote-as internal neighbor 192.168.1.2 timers 1 3 diff --git a/tests/topotests/bgp_remote_as_auto/test_bgp_remote_as_auto.py b/tests/topotests/bgp_remote_as_auto/test_bgp_remote_as_auto.py index 35047c648ba5..2748a058c426 100644 --- a/tests/topotests/bgp_remote_as_auto/test_bgp_remote_as_auto.py +++ b/tests/topotests/bgp_remote_as_auto/test_bgp_remote_as_auto.py @@ -74,6 +74,12 @@ def _bgp_converge(): "localAs": 65001, "state": "Established", }, + "192.168.1.5": { + "hostname": "r5", + "remoteAs": 65005, + "localAs": 65005, + "state": "Established", + }, } } return topotest.json_cmp(output, expected) @@ -84,6 +90,30 @@ def _bgp_converge(): _, result = topotest.run_and_expect(test_func, None, count=30, wait=1) assert result is None, "Can't see automatic iBGP/eBGP peerings" + def _bgp_neighbors(): + output = json.loads(r1.vtysh_cmd("show bgp neighbors json")) + expected = { + "r1-eth1": { + "nbrExternalLink": True, + }, + "192.168.1.2": { + "nbrExternalLink": None, + }, + "192.168.1.3": { + "nbrExternalLink": True, + }, + "192.168.1.5": { + "nbrExternalLink": None, + }, + } + return topotest.json_cmp(output, expected) + + test_func = functools.partial( + _bgp_neighbors, + ) + _, result = topotest.run_and_expect(test_func, None, count=30, wait=1) + assert result is None, "Neighbors link types are not matching" + def _bgp_converge_internal(): output = json.loads(r2.vtysh_cmd("show bgp ipv4 unicast 10.0.0.1/32 json")) expected = { @@ -162,8 +192,8 @@ def _bgp_converge_peer_group(): "peers": { "192.168.1.1": { "hostname": "r1", - "remoteAs": 65001, - "localAs": 65001, + "remoteAs": 65005, + "localAs": 65005, "state": "Established", }, "192.168.1.2": {