diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c index bde4b52af5..ef7cf89450 100644 --- a/bgpd/bgp_vty.c +++ b/bgpd/bgp_vty.c @@ -11329,15 +11329,19 @@ static int bgp_show_route_leak_vty(struct vty *vty, const char *name, json_object_array_add(json_import_vrfs, json_object_new_string(vname)); + json_object_object_add(json, "importFromVrfs", + json_import_vrfs); dir = BGP_VPN_POLICY_DIR_FROMVPN; - ecom_str = ecommunity_ecom2str( + if (bgp->vpn_policy[afi].rtlist[dir]) { + ecom_str = ecommunity_ecom2str( bgp->vpn_policy[afi].rtlist[dir], ECOMMUNITY_FORMAT_ROUTE_MAP, 0); - json_object_object_add(json, "importFromVrfs", - json_import_vrfs); - json_object_string_add(json, "importRts", ecom_str); - - XFREE(MTYPE_ECOMMUNITY_STR, ecom_str); + json_object_string_add(json, "importRts", + ecom_str); + XFREE(MTYPE_ECOMMUNITY_STR, ecom_str); + } else + json_object_string_add(json, "importRts", + "none"); } if (!CHECK_FLAG(bgp->af_flags[afi][safi], @@ -11361,12 +11365,16 @@ static int bgp_show_route_leak_vty(struct vty *vty, const char *name, buf1, RD_ADDRSTRLEN)); dir = BGP_VPN_POLICY_DIR_TOVPN; - ecom_str = ecommunity_ecom2str( + if (bgp->vpn_policy[afi].rtlist[dir]) { + ecom_str = ecommunity_ecom2str( bgp->vpn_policy[afi].rtlist[dir], ECOMMUNITY_FORMAT_ROUTE_MAP, 0); - json_object_string_add(json, "exportRts", ecom_str); - - XFREE(MTYPE_ECOMMUNITY_STR, ecom_str); + json_object_string_add(json, "exportRts", + ecom_str); + XFREE(MTYPE_ECOMMUNITY_STR, ecom_str); + } else + json_object_string_add(json, "exportRts", + "none"); } if (use_json) { @@ -11399,12 +11407,16 @@ static int bgp_show_route_leak_vty(struct vty *vty, const char *name, vty_out(vty, " %s\n", vname); dir = BGP_VPN_POLICY_DIR_FROMVPN; - ecom_str = ecommunity_ecom2str( + ecom_str = NULL; + if (bgp->vpn_policy[afi].rtlist[dir]) { + ecom_str = ecommunity_ecom2str( bgp->vpn_policy[afi].rtlist[dir], ECOMMUNITY_FORMAT_ROUTE_MAP, 0); - vty_out(vty, "Import RT(s): %s\n", ecom_str); + vty_out(vty, "Import RT(s): %s\n", ecom_str); - XFREE(MTYPE_ECOMMUNITY_STR, ecom_str); + XFREE(MTYPE_ECOMMUNITY_STR, ecom_str); + } else + vty_out(vty, "Import RT(s):\n"); } if (!CHECK_FLAG(bgp->af_flags[afi][safi], @@ -11427,11 +11439,14 @@ static int bgp_show_route_leak_vty(struct vty *vty, const char *name, buf1, RD_ADDRSTRLEN)); dir = BGP_VPN_POLICY_DIR_TOVPN; - ecom_str = ecommunity_ecom2str( + if (bgp->vpn_policy[afi].rtlist[dir]) { + ecom_str = ecommunity_ecom2str( bgp->vpn_policy[afi].rtlist[dir], ECOMMUNITY_FORMAT_ROUTE_MAP, 0); - vty_out(vty, "Export RT: %s\n", ecom_str); - XFREE(MTYPE_ECOMMUNITY_STR, ecom_str); + vty_out(vty, "Export RT: %s\n", ecom_str); + XFREE(MTYPE_ECOMMUNITY_STR, ecom_str); + } else + vty_out(vty, "Import RT(s):\n"); } }