diff --git a/bgpd/bgp_updgrp_packet.c b/bgpd/bgp_updgrp_packet.c index bff52c80d8c7..75fcbda5d1fd 100644 --- a/bgpd/bgp_updgrp_packet.c +++ b/bgpd/bgp_updgrp_packet.c @@ -525,11 +525,26 @@ struct stream *bpacket_reformat_for_peer(struct bpacket *pkt, if (peer->nexthop.v4.s_addr != INADDR_ANY && (IN6_IS_ADDR_UNSPECIFIED(mod_v6nhg) || - (peer->connection->su.sa.sa_family == AF_INET && - paf->afi == AFI_IP6))) { - /* set a IPv4 mapped IPv6 address if no global IPv6 - * address is found or if announcing IPv6 prefix - * over an IPv4 BGP session. + (IN6_IS_ADDR_LINKLOCAL(mod_v6nhg) && + peer->connection->su.sa.sa_family == AF_INET && + paf->afi == AFI_IP6 && !route_map_sets_nh && + !peer_af_flag_check(peer, paf->afi, paf->safi, + PEER_FLAG_NEXTHOP_UNCHANGED) && + !CHECK_FLAG(vec->flags, + BPKT_ATTRVEC_FLAGS_RMAP_NH_UNCHANGED) && + !CHECK_FLAG(vec->flags, + PEER_FLAG_NEXTHOP_SELF) && + !peer_af_flag_check(peer, paf->afi, paf->safi, + PEER_FLAG_REFLECTOR_CLIENT) && + !peer_af_flag_check(peer, paf->afi, paf->safi, + PEER_FLAG_RSERVER_CLIENT)))) { + /* set a IPv4 mapped IPv6 address + * - if no global IPv6 address is found + * - or if a Link-Local is found (because no global is present) + * and the announced prefix is IPv6 over an IPv4 BGP session + * and no specific instructions for nexthop override or unchanged + * and not a route-reflector + * and not a route-server */ ipv4_to_ipv4_mapped_ipv6(mod_v6nhg, peer->nexthop.v4); gnh_modified = 1;