From 558e8f58012a2f5473e72d70dc74ab7749443dc4 Mon Sep 17 00:00:00 2001 From: Philippe Guibert Date: Mon, 13 Feb 2023 12:17:28 +0100 Subject: [PATCH] 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 --- 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 572475f068..fec897f2f1 100644 --- a/bgpd/bgp_attr.c +++ b/bgpd/bgp_attr.c @@ -3983,23 +3983,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: -- 2.39.5