From adcd6cbd51dcc406df0cdf7c5cb32da6fbbbd5f0 Mon Sep 17 00:00:00 2001 From: Louis Scalbert Date: Fri, 29 Mar 2024 16:14:14 +0100 Subject: [PATCH] bgpd, tests: set ipv4-mapped ipv6 for ipv4 on ipv6 The code was expected that no IPv6 global address was present but the previous commit was replacing nexthop.v6global by the link-local address instead of un-setting it in case of removal of the IPv6 global. Set also ipv4-mapped ipv6 address as nexthop when a link-local is found and it is an ipv4 prefix over ipv6 nexthop. Signed-off-by: Louis Scalbert --- bgpd/bgp_updgrp_packet.c | 12 +++++++----- .../test_rfc5549_ebgp_unnumbered_nbr.py | 12 ++++++++---- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/bgpd/bgp_updgrp_packet.c b/bgpd/bgp_updgrp_packet.c index bed00a66402f..f4e5e16d300b 100644 --- a/bgpd/bgp_updgrp_packet.c +++ b/bgpd/bgp_updgrp_packet.c @@ -523,11 +523,13 @@ struct stream *bpacket_reformat_for_peer(struct bpacket *pkt, gnh_modified = 1; } - if (IN6_IS_ADDR_UNSPECIFIED(mod_v6nhg)) { - if (peer->nexthop.v4.s_addr != INADDR_ANY) { - ipv4_to_ipv4_mapped_ipv6(mod_v6nhg, - peer->nexthop.v4); - } + if (!peer->conf_if && peer->nexthop.v4.s_addr != INADDR_ANY && + (IN6_IS_ADDR_UNSPECIFIED(mod_v6nhg) || + (IN6_IS_ADDR_LINKLOCAL(mod_v6nhg) && + ((peer->connection->su.sa.sa_family == AF_INET6 && paf->afi == AFI_IP) || + (peer->connection->su.sa.sa_family == AF_INET && paf->afi == AFI_IP6))))) { + ipv4_to_ipv4_mapped_ipv6(mod_v6nhg, peer->nexthop.v4); + gnh_modified = 1; } if (IS_MAPPED_IPV6(&peer->nexthop.v6_global)) { diff --git a/tests/topotests/bgp_ipv4_over_ipv6/test_rfc5549_ebgp_unnumbered_nbr.py b/tests/topotests/bgp_ipv4_over_ipv6/test_rfc5549_ebgp_unnumbered_nbr.py index 8382fea18886..1730cc982fe4 100644 --- a/tests/topotests/bgp_ipv4_over_ipv6/test_rfc5549_ebgp_unnumbered_nbr.py +++ b/tests/topotests/bgp_ipv4_over_ipv6/test_rfc5549_ebgp_unnumbered_nbr.py @@ -670,10 +670,15 @@ def bgp_prefix_received_v4_mapped_v6_nh(router): { "nexthops": [ { - "ip": "::ffff:10.0.5.1", "hostname": "r1", "afi": "ipv6", "scope": "global", + }, + { + "hostname": "r1", + "afi": "ipv6", + "scope": "link-local", + "used": True, } ] } @@ -748,13 +753,12 @@ def bgp_prefix_received_v4_mapped_v6_nh(router): ! """ ) - # verify that r1 has rcvd the prefix with v4-mapped-v6 address as the nexthop + # verify that r1 has rcvd the prefix with a link-local as the nexthop test_func = functools.partial(bgp_prefix_received_v4_mapped_v6_nh, r2) _, result = topotest.run_and_expect(test_func, None, count=60, wait=0.5) assert ( result is None - ), "Testcase {} : Failed \n Error: Nexthop for prefix 11.0.20.1 \ - is not ::ffff:10.0.5.1".format( + ), "Testcase {} : Failed \n Error: Nexthop for prefix 11.0.20.1 is not the link-local address.".format( tc_name )