From bea6f612ae6db196ea459669c8734470185a1fde Mon Sep 17 00:00:00 2001 From: Philippe Guibert Date: Mon, 13 Feb 2023 12:17:28 +0100 Subject: [PATCH 1/2] bgpd: factorise ipv6 vpn nexthop encoding Because mp_nexthop_len attribute value stands for the length to encode in the stream, simplify the way the nexthop is forged. Signed-off-by: Philippe Guibert (cherry picked from commit 558e8f58012a2f5473e72d70dc74ab7749443dc4) --- bgpd/bgp_attr.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/bgpd/bgp_attr.c b/bgpd/bgp_attr.c index 392b558805..59ccf30a84 100644 --- a/bgpd/bgp_attr.c +++ b/bgpd/bgp_attr.c @@ -4028,23 +4028,21 @@ size_t bgp_packet_mpattr_start(struct stream *s, struct peer *peer, afi_t afi, } } break; case SAFI_MPLS_VPN: { + if (attr->mp_nexthop_len == + BGP_ATTR_NHLEN_VPNV6_GLOBAL_AND_LL) + stream_putc(s, attr->mp_nexthop_len); + else + stream_putc(s, BGP_ATTR_NHLEN_VPNV6_GLOBAL); + stream_putl(s, 0); /* RD = 0, per RFC */ + stream_putl(s, 0); + stream_put(s, &attr->mp_nexthop_global, + IPV6_MAX_BYTELEN); if (attr->mp_nexthop_len == BGP_ATTR_NHLEN_VPNV6_GLOBAL_AND_LL) { - stream_putc(s, 48); - stream_putl(s, 0); /* RD = 0, per RFC */ - stream_putl(s, 0); - stream_put(s, &attr->mp_nexthop_global, - IPV6_MAX_BYTELEN); stream_putl(s, 0); /* RD = 0, per RFC */ stream_putl(s, 0); stream_put(s, &attr->mp_nexthop_local, IPV6_MAX_BYTELEN); - } else { - stream_putc(s, 24); - stream_putl(s, 0); /* RD = 0, per RFC */ - stream_putl(s, 0); - stream_put(s, &attr->mp_nexthop_global, - IPV6_MAX_BYTELEN); } } break; case SAFI_ENCAP: From fd5dcbacfa3b6a495edbf9a068c6da1dbb3dc453 Mon Sep 17 00:00:00 2001 From: Philippe Guibert Date: Mon, 13 Feb 2023 12:18:33 +0100 Subject: [PATCH 2/2] bgpd: clarify when the vpnv6 nexthop length must be modified Using a route-map to update the local ipv6 address has to be better clarified. Actually, when a VPN SAFI is used, the nexthop length must be changed to 48 bytes. Other cases, the length will be 32 bytes. Fixes: 9795e9f23465 ("bgpd: fix when route-map changes the link local nexthop for vpnv6") Signed-off-by: Philippe Guibert (cherry picked from commit 5bbcc78202f53f67082aa0d3026a8b7e8c44909a) --- bgpd/bgp_routemap.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/bgpd/bgp_routemap.c b/bgpd/bgp_routemap.c index d00bdd2571..61cff27e9e 100644 --- a/bgpd/bgp_routemap.c +++ b/bgpd/bgp_routemap.c @@ -3576,17 +3576,29 @@ route_set_ipv6_nexthop_local(void *rule, const struct prefix *p, void *object) { struct in6_addr *address; struct bgp_path_info *path; + struct bgp_dest *dest; + struct bgp_table *table = NULL; /* Fetch routemap's rule information. */ address = rule; path = object; + dest = path->net; + + if (!dest) + return RMAP_OKAY; + + table = bgp_dest_table(dest); + if (!table) + return RMAP_OKAY; /* Set next hop value. */ path->attr->mp_nexthop_local = *address; /* Set nexthop length. */ - if (path->attr->mp_nexthop_len != BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL && - path->attr->mp_nexthop_len != BGP_ATTR_NHLEN_VPNV6_GLOBAL_AND_LL) + if (table->safi == SAFI_MPLS_VPN || table->safi == SAFI_ENCAP || + table->safi == SAFI_EVPN) + path->attr->mp_nexthop_len = BGP_ATTR_NHLEN_VPNV6_GLOBAL_AND_LL; + else path->attr->mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL; SET_FLAG(path->attr->rmap_change_flags,