diff --git a/bgpd/bgp_bmp.c b/bgpd/bgp_bmp.c index 964139d1f30f..205973c02da5 100644 --- a/bgpd/bgp_bmp.c +++ b/bgpd/bgp_bmp.c @@ -269,7 +269,6 @@ static inline uint64_t bmp_get_peer_distinguisher(struct bmp *bmp, afi_t afi, // sending vrf_id or rd could be turned into an option at some point struct bgp *bgp = bmp->targets->bgp; - struct prefix_rd *prd = &bgp->vpn_policy[afi].tovpn_rd; /* * default vrf => can't have RD => 0 * vrf => has RD? @@ -277,10 +276,18 @@ static inline uint64_t bmp_get_peer_distinguisher(struct bmp *bmp, afi_t afi, * else => use vrf_id and convert it so that * peer_distinguisher is 0::vrf_id */ - return bgp->inst_type == VRF_DEFAULT - ? 0 - : prd ? *(uint64_t *)prd->val - : (((uint64_t)htonl(bgp->vrf_id)) << 32); + if (bgp->inst_type == VRF_DEFAULT) + return 0; + + struct prefix_rd *prd = &bgp->vpn_policy[afi].tovpn_rd; + if (CHECK_FLAG(bgp->vpn_policy[afi].flags, BGP_VPN_POLICY_TOVPN_RD_SET)) { + uint64_t peerd = 0; + memcpy(&peerd, prd->val, sizeof(prd->val)); + return peerd; + } + + uint32_t vrf_id_n = htonl(bgp->vrf_id); + return ((uint64_t)vrf_id_n) << 32; } static void bmp_common_hdr(struct stream *s, uint8_t ver, uint8_t type)