From 2b26882d28fb6c28930c97c4ad53d0bc3e1f29d3 Mon Sep 17 00:00:00 2001 From: Daniel Walton Date: Tue, 16 May 2017 17:28:12 +0000 Subject: [PATCH] bgpd: fix nh_afi in bgp_packet_mpattr_start() Signed-off-by: Daniel Walton --- bgpd/bgp_attr.c | 39 +++++++++++++++------------------------ bgpd/bgp_attr.h | 4 ++-- bgpd/bgp_updgrp_packet.c | 7 ++----- 3 files changed, 19 insertions(+), 31 deletions(-) diff --git a/bgpd/bgp_attr.c b/bgpd/bgp_attr.c index 5c444869b4..0eb84bda02 100644 --- a/bgpd/bgp_attr.c +++ b/bgpd/bgp_attr.c @@ -2807,13 +2807,26 @@ bgp_attr_parse (struct peer *peer, struct attr *attr, bgp_size_t size, } size_t -bgp_packet_mpattr_start (struct stream *s, afi_t afi, safi_t safi, afi_t nh_afi, +bgp_packet_mpattr_start (struct stream *s, struct peer *peer, + afi_t afi, safi_t safi, struct bpacket_attr_vec_arr *vecarr, struct attr *attr) { size_t sizep; iana_afi_t pkt_afi; safi_t pkt_safi; + afi_t nh_afi; + + if (peer_cap_enhe(peer, afi, safi)) { + nh_afi = AFI_IP6; + } else { + if (afi == AFI_L2VPN) + nh_afi = AFI_L2VPN; + else if (safi == SAFI_LABELED_UNICAST) + nh_afi = afi; + else + nh_afi = BGP_NEXTHOP_AFI_FROM_NHLEN(attr->extra->mp_nexthop_len); + } /* Set extended bit always to encode the attribute length as 2 bytes */ stream_putc (s, BGP_ATTR_FLAG_OPTIONAL|BGP_ATTR_FLAG_EXTLEN); @@ -3096,26 +3109,6 @@ bgp_packet_mpattr_end (struct stream *s, size_t sizep) } -/* Return the Nexthop AFI that should be used */ -afi_t -bgp_nexthop_afi (struct peer *peer, afi_t afi, safi_t safi, struct attr *attr) -{ - afi_t nh_afi; - - if (peer_cap_enhe(peer, afi, safi)) { - nh_afi = AFI_IP6; - } else { - if (afi == AFI_L2VPN) - nh_afi = AFI_L2VPN; - else if (safi == SAFI_LABELED_UNICAST) - nh_afi = afi; - else - nh_afi = BGP_NEXTHOP_AFI_FROM_NHLEN(attr->extra->mp_nexthop_len); - } - - return nh_afi; -} - /* Make attribute packet. */ bgp_size_t bgp_packet_attribute (struct bgp *bgp, struct peer *peer, @@ -3132,7 +3125,6 @@ bgp_packet_attribute (struct bgp *bgp, struct peer *peer, int send_as4_path = 0; int send_as4_aggregator = 0; int use32bit = (CHECK_FLAG (peer->cap, PEER_CAP_AS4_RCV)) ? 1 : 0; - afi_t nh_afi; if (! bgp) bgp = peer->bgp; @@ -3145,8 +3137,7 @@ bgp_packet_attribute (struct bgp *bgp, struct peer *peer, { size_t mpattrlen_pos = 0; - nh_afi = bgp_nexthop_afi(peer, afi, safi, attr); - mpattrlen_pos = bgp_packet_mpattr_start(s, afi, safi, nh_afi, vecarr, attr); + mpattrlen_pos = bgp_packet_mpattr_start(s, peer, afi, safi, vecarr, attr); bgp_packet_mpattr_prefix(s, afi, safi, p, prd, tag, addpath_encode, addpath_tx_id, attr); bgp_packet_mpattr_end(s, mpattrlen_pos); diff --git a/bgpd/bgp_attr.h b/bgpd/bgp_attr.h index 2931b2f2b6..e7f3e25c41 100644 --- a/bgpd/bgp_attr.h +++ b/bgpd/bgp_attr.h @@ -299,8 +299,8 @@ bgp_attr_flush_encap(struct attr *attr); * one for each NLRI that needs to be encoded into the UPDATE message, and * finally the _end() function. */ -extern size_t bgp_packet_mpattr_start(struct stream *s, afi_t afi, safi_t safi, - afi_t nh_afi, +extern size_t bgp_packet_mpattr_start(struct stream *s, struct peer *peer, + afi_t afi, safi_t safi, struct bpacket_attr_vec_arr *vecarr, struct attr *attr); extern void bgp_packet_mpattr_prefix(struct stream *s, afi_t afi, safi_t safi, diff --git a/bgpd/bgp_updgrp_packet.c b/bgpd/bgp_updgrp_packet.c index 8a4824f859..2408a8ca30 100644 --- a/bgpd/bgp_updgrp_packet.c +++ b/bgpd/bgp_updgrp_packet.c @@ -656,7 +656,6 @@ subgroup_update_packet (struct update_subgroup *subgrp) u_int32_t addpath_tx_id = 0; struct prefix_rd *prd = NULL; char label_buf[20]; - afi_t nh_afi; if (!subgrp) return NULL; @@ -768,11 +767,9 @@ subgroup_update_packet (struct update_subgroup *subgrp) if (bgp_labeled_safi(safi)) sprintf (label_buf, "label %u", label_pton(tag)); - if (stream_empty (snlri)) { - nh_afi = bgp_nexthop_afi(peer, afi, safi, adv->baa->attr); - mpattrlen_pos = bgp_packet_mpattr_start (snlri, afi, safi, nh_afi, + if (stream_empty (snlri)) + mpattrlen_pos = bgp_packet_mpattr_start (snlri, peer, afi, safi, &vecarr, adv->baa->attr); - } bgp_packet_mpattr_prefix (snlri, afi, safi, &rn->p, prd, tag, addpath_encode, addpath_tx_id, adv->baa->attr); -- 2.39.5