stream_putw (s, pkt_afi); /* AFI */
stream_putc (s, pkt_safi); /* SAFI */
- if (afi == AFI_L2VPN)
- nh_afi = AFI_L2VPN;
- else if (nh_afi == AFI_MAX)
- nh_afi = BGP_NEXTHOP_AFI_FROM_NHLEN(attr->extra->mp_nexthop_len);
/* Nexthop */
switch (nh_afi)
stream_putw_at (s, sizep, (stream_get_endp (s) - sizep) - 2);
}
+
+/* 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,
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;
{
size_t mpattrlen_pos = 0;
- mpattrlen_pos = bgp_packet_mpattr_start(s, afi, safi,
- (peer_cap_enhe(peer, afi, safi) ? AFI_IP6 :
- AFI_MAX), /* get from NH */
- vecarr, attr);
+ nh_afi = bgp_nexthop_afi(peer, afi, safi, attr);
+ mpattrlen_pos = bgp_packet_mpattr_start(s, afi, safi, nh_afi, 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);
extern struct attr *bgp_attr_aggregate_intern (struct bgp *, u_char,
struct aspath *,
struct community *, int as_set, u_char);
+extern afi_t bgp_nexthop_afi (struct peer *peer, afi_t afi, safi_t safi,
+ struct attr *attr);
extern bgp_size_t bgp_packet_attribute (struct bgp *bgp, struct peer *,
struct stream *, struct attr *,
struct bpacket_attr_vec_arr *vecarr,
u_int32_t addpath_tx_id = 0;
struct prefix_rd *prd = NULL;
char label_buf[20];
+ afi_t nh_afi;
if (!subgrp)
return NULL;
if (bgp_labeled_safi(safi))
sprintf (label_buf, "label %u", label_pton(tag));
- if (stream_empty (snlri))
- mpattrlen_pos = bgp_packet_mpattr_start (snlri, afi, safi,
- (peer_cap_enhe(peer, afi, safi) ? AFI_IP6 :
- AFI_MAX), /* get from NH */
+ 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,
&vecarr, adv->baa->attr);
+ }
bgp_packet_mpattr_prefix (snlri, afi, safi, &rn->p, prd,
tag, addpath_encode, addpath_tx_id, adv->baa->attr);