diff --git a/bgpd/bgp_bmp.c b/bgpd/bgp_bmp.c index 2b3c2193e7..65a99d75e7 100644 --- a/bgpd/bgp_bmp.c +++ b/bgpd/bgp_bmp.c @@ -285,13 +285,6 @@ static inline int bmp_get_peer_distinguisher(struct bgp *bgp, afi_t afi, uint8_t if (peer_type == BMP_PEER_TYPE_LOCAL_INSTANCE || bgp->vrf_id == VRF_UNKNOWN) return 1; - /* remove this check when the other peer types get correct peer dist. - *(RFC7854) impl. - * for now, always return no error and 0 peer distinguisher as before - */ - if (peer_type != BMP_PEER_TYPE_LOC_RIB_INSTANCE) - return (*result_ref = 0); - /* vrf default => ok, distinguisher 0 */ if (bgp->inst_type == VRF_DEFAULT) return (*result_ref = 0); @@ -795,16 +788,23 @@ static void bmp_wrmirror_lost(struct bmp *bmp, struct pullwr *pullwr) struct stream *s; struct timeval tv; uint8_t peer_type_flag; + uint64_t peer_distinguisher = 0; gettimeofday(&tv, NULL); peer_type_flag = bmp_get_peer_type_vrf(bmp->targets->bgp->vrf_id); + if (bmp_get_peer_distinguisher(bmp->targets->bgp, AFI_UNSPEC, peer_type_flag, + &peer_distinguisher)) { + zlog_warn("skipping bmp message for reason: can't get peer distinguisher"); + return; + } + s = stream_new(BGP_MAX_PACKET_SIZE); bmp_common_hdr(s, BMP_VERSION_3, BMP_TYPE_ROUTE_MIRRORING); - bmp_per_peer_hdr(s, bmp->targets->bgp, bmp->targets->bgp->peer_self, 0, peer_type_flag, 0, - &tv); + bmp_per_peer_hdr(s, bmp->targets->bgp, bmp->targets->bgp->peer_self, 0, peer_type_flag, + peer_distinguisher, &tv); stream_putw(s, BMP_MIRROR_TLV_TYPE_INFO); stream_putw(s, 2); @@ -822,6 +822,7 @@ static bool bmp_wrmirror(struct bmp *bmp, struct pullwr *pullwr) struct peer *peer; bool written = false; uint8_t peer_type_flag; + uint64_t peer_distinguisher = 0; if (bmp->mirror_lost) { bmp_wrmirror_lost(bmp, pullwr); @@ -841,11 +842,18 @@ static bool bmp_wrmirror(struct bmp *bmp, struct pullwr *pullwr) peer_type_flag = bmp_get_peer_type_vrf(bmp->targets->bgp->vrf_id); + if (bmp_get_peer_distinguisher(peer->bgp, AFI_UNSPEC, peer_type_flag, &peer_distinguisher)) { + zlog_warn("skipping bmp message for peer %s: can't get peer distinguisher", + peer->host); + goto out; + } + struct stream *s; s = stream_new(BGP_MAX_PACKET_SIZE); bmp_common_hdr(s, BMP_VERSION_3, BMP_TYPE_ROUTE_MIRRORING); - bmp_per_peer_hdr(s, bmp->targets->bgp, peer, 0, peer_type_flag, 0, &bmq->tv); + bmp_per_peer_hdr(s, bmp->targets->bgp, peer, 0, peer_type_flag, peer_distinguisher, + &bmq->tv); /* BMP Mirror TLV. */ stream_putw(s, BMP_MIRROR_TLV_TYPE_BGP_MESSAGE); diff --git a/tests/topotests/bgp_bmp/bmp1vrf/bmp-update-post-policy-step1.json b/tests/topotests/bgp_bmp/bmp1vrf/bmp-update-post-policy-step1.json index 18f40b16c7..04e01623df 100644 --- a/tests/topotests/bgp_bmp/bmp1vrf/bmp-update-post-policy-step1.json +++ b/tests/topotests/bgp_bmp/bmp1vrf/bmp-update-post-policy-step1.json @@ -10,7 +10,7 @@ "origin": "IGP", "peer_asn": 65502, "peer_bgp_id": "192.168.0.2", - "peer_distinguisher": "0:0", + "peer_distinguisher": "444:1", "peer_ip": "192.168.0.2", "peer_type": "route distinguisher instance", "policy": "post-policy" @@ -25,7 +25,7 @@ "origin": "IGP", "peer_asn": 65502, "peer_bgp_id": "192.168.0.2", - "peer_distinguisher": "0:0", + "peer_distinguisher": "555:1", "peer_ip": "192:168::2", "peer_type": "route distinguisher instance", "policy": "post-policy", diff --git a/tests/topotests/bgp_bmp/bmp1vrf/bmp-update-pre-policy-step1.json b/tests/topotests/bgp_bmp/bmp1vrf/bmp-update-pre-policy-step1.json index 61ef0eab86..760ee0409a 100644 --- a/tests/topotests/bgp_bmp/bmp1vrf/bmp-update-pre-policy-step1.json +++ b/tests/topotests/bgp_bmp/bmp1vrf/bmp-update-pre-policy-step1.json @@ -10,7 +10,7 @@ "origin": "IGP", "peer_asn": 65502, "peer_bgp_id": "192.168.0.2", - "peer_distinguisher": "0:0", + "peer_distinguisher": "444:1", "peer_ip": "192.168.0.2", "peer_type": "route distinguisher instance", "policy": "pre-policy" @@ -25,7 +25,7 @@ "origin": "IGP", "peer_asn": 65502, "peer_bgp_id": "192.168.0.2", - "peer_distinguisher": "0:0", + "peer_distinguisher": "555:1", "peer_ip": "192:168::2", "peer_type": "route distinguisher instance", "policy": "pre-policy", diff --git a/tests/topotests/bgp_bmp/bmp1vrf/bmp-withdraw-post-policy-step1.json b/tests/topotests/bgp_bmp/bmp1vrf/bmp-withdraw-post-policy-step1.json index c28ce851a2..f57b1a51ce 100644 --- a/tests/topotests/bgp_bmp/bmp1vrf/bmp-withdraw-post-policy-step1.json +++ b/tests/topotests/bgp_bmp/bmp1vrf/bmp-withdraw-post-policy-step1.json @@ -7,7 +7,7 @@ "ipv6": false, "peer_asn": 65502, "peer_bgp_id": "192.168.0.2", - "peer_distinguisher": "0:0", + "peer_distinguisher": "444:1", "peer_ip": "192.168.0.2", "peer_type": "route distinguisher instance", "policy": "post-policy" @@ -19,7 +19,7 @@ "ipv6": true, "peer_asn": 65502, "peer_bgp_id": "192.168.0.2", - "peer_distinguisher": "0:0", + "peer_distinguisher": "555:1", "peer_ip": "192:168::2", "peer_type": "route distinguisher instance", "policy": "post-policy", diff --git a/tests/topotests/bgp_bmp/bmp1vrf/bmp-withdraw-pre-policy-step1.json b/tests/topotests/bgp_bmp/bmp1vrf/bmp-withdraw-pre-policy-step1.json index 976c7d4716..a52308c789 100644 --- a/tests/topotests/bgp_bmp/bmp1vrf/bmp-withdraw-pre-policy-step1.json +++ b/tests/topotests/bgp_bmp/bmp1vrf/bmp-withdraw-pre-policy-step1.json @@ -7,7 +7,7 @@ "ipv6": false, "peer_asn": 65502, "peer_bgp_id": "192.168.0.2", - "peer_distinguisher": "0:0", + "peer_distinguisher": "444:1", "peer_ip": "192.168.0.2", "peer_type": "route distinguisher instance", "policy": "pre-policy" @@ -19,7 +19,7 @@ "ipv6": true, "peer_asn": 65502, "peer_bgp_id": "192.168.0.2", - "peer_distinguisher": "0:0", + "peer_distinguisher": "555:1", "peer_ip": "192:168::2", "peer_type": "route distinguisher instance", "policy": "pre-policy",