diff options
| -rw-r--r-- | bgpd/bgp_updgrp_adv.c | 2 | ||||
| -rw-r--r-- | ospfd/ospf_network.c | 5 | ||||
| -rw-r--r-- | ospfd/ospf_vty.c | 1083 |
3 files changed, 735 insertions, 355 deletions
diff --git a/bgpd/bgp_updgrp_adv.c b/bgpd/bgp_updgrp_adv.c index 8a24cba598..b4f18c9f5e 100644 --- a/bgpd/bgp_updgrp_adv.c +++ b/bgpd/bgp_updgrp_adv.c @@ -691,7 +691,7 @@ void subgroup_default_originate(struct update_subgroup *subgrp, int withdraw) p.family = afi2family(afi); p.prefixlen = 0; - if (afi == AFI_IP6) { + if ((afi == AFI_IP6) || peer_cap_enhe(peer, afi, safi)) { /* IPv6 global nexthop must be included. */ attr.mp_nexthop_len = BGP_ATTR_NHLEN_IPV6_GLOBAL; diff --git a/ospfd/ospf_network.c b/ospfd/ospf_network.c index 519e3f9cf4..ed5e8e027d 100644 --- a/ospfd/ospf_network.c +++ b/ospfd/ospf_network.c @@ -184,11 +184,8 @@ int ospf_bind_vrfdevice(struct ospf *ospf, int ospf_sock) zlog_warn("%s: Could not setsockopt SO_BINDTODEVICE %s", __PRETTY_FUNCTION__, safe_strerror(save_errno)); - } else { - zlog_debug("%s: Bind socket %d to vrf %s id %u device", - __PRETTY_FUNCTION__, ospf_sock, - ospf->name, ospf->vrf_id); } + } #endif return ret; diff --git a/ospfd/ospf_vty.c b/ospfd/ospf_vty.c index 9d1a691d9a..cfbe7a459a 100644 --- a/ospfd/ospf_vty.c +++ b/ospfd/ospf_vty.c @@ -166,15 +166,24 @@ static struct ospf *ospf_cmd_lookup_ospf(struct vty *vty, } static void ospf_show_vrf_name(struct ospf *ospf, struct vty *vty, - json_object *json) + json_object *json, u_char use_vrf) { - if (ospf->name) { - if (json) - json_object_string_add(json, "vrfName", ospf->name); - else - vty_out(vty, "VRF Name: %s\n", ospf->name); + if (use_vrf) { + if (json) { + if (ospf->vrf_id == VRF_DEFAULT) + json_object_string_add(json, "vrfName", + "default"); + else + json_object_string_add(json, "vrfName", + ospf->name); + json_object_int_add(json, "vrfId", ospf->vrf_id); + } else { + if (ospf->vrf_id == VRF_DEFAULT) + vty_out(vty, "VRF Name: %s\n", "default"); + else if (ospf->name) + vty_out(vty, "VRF Name: %s\n", ospf->name); + } } - } #ifndef VTYSH_EXTRACT_PL @@ -2904,22 +2913,25 @@ static void show_ip_ospf_area(struct vty *vty, struct ospf_area *area, } static int show_ip_ospf_common(struct vty *vty, struct ospf *ospf, - u_char use_json) + json_object *json, u_char use_vrf) { struct listnode *node, *nnode; struct ospf_area *area; struct timeval result; char timebuf[OSPF_TIME_DUMP_SIZE]; - json_object *json = NULL; + json_object *json_vrf = NULL; json_object *json_areas = NULL; - if (use_json) { - json = json_object_new_object(); + if (json) { + if (use_vrf) + json_vrf = json_object_new_object(); + else + json_vrf = json; json_areas = json_object_new_object(); } if (ospf->instance) { - if (use_json) { + if (json) { json_object_int_add(json, "ospfInstance", ospf->instance); } else { @@ -2927,11 +2939,11 @@ static int show_ip_ospf_common(struct vty *vty, struct ospf *ospf, } } - ospf_show_vrf_name(ospf, vty, json); + ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); /* Show Router ID. */ - if (use_json) { - json_object_string_add(json, "routerId", + if (json) { + json_object_string_add(json_vrf, "routerId", inet_ntoa(ospf->router_id)); } else { vty_out(vty, " OSPF Routing Process, Router ID: %s\n", @@ -2940,14 +2952,14 @@ static int show_ip_ospf_common(struct vty *vty, struct ospf *ospf, /* Graceful shutdown */ if (ospf->t_deferred_shutdown) { - if (use_json) { + if (json) { long time_store; time_store = monotime_until( &ospf->t_deferred_shutdown->u.sands, NULL) / 1000LL; - json_object_int_add(json, "deferredShutdownMsecs", + json_object_int_add(json_vrf, "deferredShutdownMsecs", time_store); } else { vty_out(vty, @@ -2958,11 +2970,11 @@ static int show_ip_ospf_common(struct vty *vty, struct ospf *ospf, } /* Show capability. */ - if (use_json) { - json_object_boolean_true_add(json, "tosRoutesOnly"); - json_object_boolean_true_add(json, "rfc2328Conform"); + if (json) { + json_object_boolean_true_add(json_vrf, "tosRoutesOnly"); + json_object_boolean_true_add(json_vrf, "rfc2328Conform"); if (CHECK_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE)) { - json_object_boolean_true_add(json, + json_object_boolean_true_add(json_vrf, "rfc1583Compatibility"); } } else { @@ -2974,9 +2986,9 @@ static int show_ip_ospf_common(struct vty *vty, struct ospf *ospf, : "disabled"); } - if (use_json) { + if (json) { if (CHECK_FLAG(ospf->config, OSPF_OPAQUE_CAPABLE)) { - json_object_boolean_true_add(json, "opaqueCapable"); + json_object_boolean_true_add(json_vrf, "opaqueCapable"); } } else { vty_out(vty, " OpaqueCapability flag is %s\n", @@ -2989,17 +3001,18 @@ static int show_ip_ospf_common(struct vty *vty, struct ospf *ospf, if (ospf->stub_router_startup_time != OSPF_STUB_ROUTER_UNCONFIGURED || ospf->stub_router_shutdown_time != OSPF_STUB_ROUTER_UNCONFIGURED) { - if (use_json) { - json_object_boolean_true_add(json, "stubAdvertisement"); + if (json) { + json_object_boolean_true_add(json_vrf, + "stubAdvertisement"); if (ospf->stub_router_startup_time != OSPF_STUB_ROUTER_UNCONFIGURED) json_object_int_add( - json, "postStartEnabledMsecs", + json_vrf, "postStartEnabledMsecs", ospf->stub_router_startup_time / 1000); if (ospf->stub_router_shutdown_time != OSPF_STUB_ROUTER_UNCONFIGURED) json_object_int_add( - json, "preShutdownEnabledMsecs", + json_vrf, "preShutdownEnabledMsecs", ospf->stub_router_shutdown_time / 1000); } else { vty_out(vty, @@ -3018,14 +3031,14 @@ static int show_ip_ospf_common(struct vty *vty, struct ospf *ospf, } /* Show SPF timers. */ - if (use_json) { - json_object_int_add(json, "spfScheduleDelayMsecs", + if (json) { + json_object_int_add(json_vrf, "spfScheduleDelayMsecs", ospf->spf_delay); - json_object_int_add(json, "holdtimeMinMsecs", + json_object_int_add(json_vrf, "holdtimeMinMsecs", ospf->spf_holdtime); - json_object_int_add(json, "holdtimeMaxMsecs", + json_object_int_add(json_vrf, "holdtimeMaxMsecs", ospf->spf_max_holdtime); - json_object_int_add(json, "holdtimeMultplier", + json_object_int_add(json_vrf, "holdtimeMultplier", ospf->spf_hold_multiplier); } else { vty_out(vty, @@ -3037,21 +3050,21 @@ static int show_ip_ospf_common(struct vty *vty, struct ospf *ospf, ospf->spf_max_holdtime, ospf->spf_hold_multiplier); } - if (use_json) { + if (json) { if (ospf->ts_spf.tv_sec || ospf->ts_spf.tv_usec) { long time_store = 0; time_store = monotime_since(&ospf->ts_spf, NULL) / 1000LL; - json_object_int_add(json, "spfLastExecutedMsecs", + json_object_int_add(json_vrf, "spfLastExecutedMsecs", time_store); time_store = (1000 * ospf->ts_spf_duration.tv_sec) + (ospf->ts_spf_duration.tv_usec / 1000); - json_object_int_add(json, "spfLastDurationMsecs", + json_object_int_add(json_vrf, "spfLastDurationMsecs", time_store); } else - json_object_boolean_true_add(json, "spfHasNotRun"); + json_object_boolean_true_add(json_vrf, "spfHasNotRun"); } else { vty_out(vty, " SPF algorithm "); if (ospf->ts_spf.tv_sec || ospf->ts_spf.tv_usec) { @@ -3066,25 +3079,25 @@ static int show_ip_ospf_common(struct vty *vty, struct ospf *ospf, vty_out(vty, "has not been run\n"); } - if (use_json) { + if (json) { if (ospf->t_spf_calc) { long time_store; time_store = monotime_until(&ospf->t_spf_calc->u.sands, NULL) / 1000LL; - json_object_int_add(json, "spfTimerDueInMsecs", + json_object_int_add(json_vrf, "spfTimerDueInMsecs", time_store); } - json_object_int_add(json, "lsaMinIntervalMsecs", + json_object_int_add(json_vrf, "lsaMinIntervalMsecs", ospf->min_ls_interval); - json_object_int_add(json, "lsaMinArrivalMsecs", + json_object_int_add(json_vrf, "lsaMinArrivalMsecs", ospf->min_ls_arrival); /* Show write multiplier values */ - json_object_int_add(json, "writeMultiplier", + json_object_int_add(json_vrf, "writeMultiplier", ospf->write_oi_count); /* Show refresh parameters. */ - json_object_int_add(json, "refreshTimerMsecs", + json_object_int_add(json_vrf, "refreshTimerMsecs", ospf->lsa_refresh_interval * 1000); } else { vty_out(vty, " SPF timer %s%s\n", @@ -3108,9 +3121,9 @@ static int show_ip_ospf_common(struct vty *vty, struct ospf *ospf, /* Show ABR/ASBR flags. */ if (CHECK_FLAG(ospf->flags, OSPF_FLAG_ABR)) { - if (use_json) + if (json) json_object_string_add( - json, "abrType", + json_vrf, "abrType", ospf_abr_type_descr_str[ospf->abr_type]); else vty_out(vty, @@ -3118,9 +3131,9 @@ static int show_ip_ospf_common(struct vty *vty, struct ospf *ospf, ospf_abr_type_descr_str[ospf->abr_type]); } if (CHECK_FLAG(ospf->flags, OSPF_FLAG_ASBR)) { - if (use_json) + if (json) json_object_string_add( - json, "asbrRouter", + json_vrf, "asbrRouter", "injectingExternalRoutingInformation"); else vty_out(vty, @@ -3129,12 +3142,12 @@ static int show_ip_ospf_common(struct vty *vty, struct ospf *ospf, } /* Show Number of AS-external-LSAs. */ - if (use_json) { + if (json) { json_object_int_add( - json, "lsaExternalCounter", + json_vrf, "lsaExternalCounter", ospf_lsdb_count(ospf->lsdb, OSPF_AS_EXTERNAL_LSA)); json_object_int_add( - json, "lsaExternalChecksum", + json_vrf, "lsaExternalChecksum", ospf_lsdb_checksum(ospf->lsdb, OSPF_AS_EXTERNAL_LSA)); } else { vty_out(vty, @@ -3143,12 +3156,12 @@ static int show_ip_ospf_common(struct vty *vty, struct ospf *ospf, ospf_lsdb_checksum(ospf->lsdb, OSPF_AS_EXTERNAL_LSA)); } - if (use_json) { + if (json) { json_object_int_add( - json, "lsaAsopaqueCounter", + json_vrf, "lsaAsopaqueCounter", ospf_lsdb_count(ospf->lsdb, OSPF_OPAQUE_AS_LSA)); json_object_int_add( - json, "lsaAsOpaqueChecksum", + json_vrf, "lsaAsOpaqueChecksum", ospf_lsdb_checksum(ospf->lsdb, OSPF_OPAQUE_AS_LSA)); } else { vty_out(vty, @@ -3158,8 +3171,8 @@ static int show_ip_ospf_common(struct vty *vty, struct ospf *ospf, } /* Show number of areas attached. */ - if (use_json) - json_object_int_add(json, "attachedAreaCounter", + if (json) + json_object_int_add(json_vrf, "attachedAreaCounter", listcount(ospf->areas)); else vty_out(vty, " Number of areas attached to this router: %d\n", @@ -3167,29 +3180,36 @@ static int show_ip_ospf_common(struct vty *vty, struct ospf *ospf, if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES)) { if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL)) { - if (use_json) + if (json) json_object_boolean_true_add( - json, "adjacencyChangesLoggedAll"); + json_vrf, "adjacencyChangesLoggedAll"); else vty_out(vty, " All adjacency changes are logged\n"); } else { - if (use_json) + if (json) json_object_boolean_true_add( - json, "adjacencyChangesLogged"); + json_vrf, "adjacencyChangesLogged"); else vty_out(vty, " Adjacency changes are logged\n"); } } /* Show each area status. */ for (ALL_LIST_ELEMENTS(ospf->areas, node, nnode, area)) - show_ip_ospf_area(vty, area, json_areas, use_json); - - if (use_json) { - json_object_object_add(json, "areas", json_areas); - vty_out(vty, "%s\n", json_object_to_json_string_ext( - json, JSON_C_TO_STRING_PRETTY)); - json_object_free(json); + show_ip_ospf_area(vty, area, json_areas, json ? 1 : 0); + + if (json) { + if (use_vrf) { + json_object_object_add(json_vrf, "areas", json_areas); + if (ospf->vrf_id == VRF_DEFAULT) + json_object_object_add(json, "default", + json_vrf); + else + json_object_object_add(json, ospf->name, + json_vrf); + } else { + json_object_object_add(json, "areas", json_areas); + } } else vty_out(vty, "\n"); @@ -3214,34 +3234,60 @@ DEFUN (show_ip_ospf, int ret = CMD_SUCCESS; int inst = 0; int idx_vrf = 0; + json_object *json = NULL; + u_char use_vrf = 0; if (listcount(om->ospf) == 0) return CMD_SUCCESS; OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); + if (uj) + json = json_object_new_object(); + /* vrf input is provided could be all or specific vrf*/ if (vrf_name) { + use_vrf = 1; if (all_vrf) { for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { if (!ospf->oi_running) continue; - ret = show_ip_ospf_common(vty, ospf, uj); + ret = show_ip_ospf_common(vty, ospf, json, + use_vrf); + } + if (uj) { + vty_out(vty, "%s\n", + json_object_to_json_string_ext(json, + JSON_C_TO_STRING_PRETTY)); + json_object_free(json); } return ret; } ospf = ospf_lookup_by_inst_name(inst, vrf_name); - if ((ospf == NULL) || !ospf->oi_running) + if ((ospf == NULL) || !ospf->oi_running) { + if (uj) + json_object_free(json); return CMD_SUCCESS; + } } else { ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); /* Display default ospf (instance 0) info */ - if (ospf == NULL || !ospf->oi_running) + if (ospf == NULL || !ospf->oi_running) { + if (uj) + json_object_free(json); return CMD_SUCCESS; + } } - if (ospf) - show_ip_ospf_common(vty, ospf, uj); + if (ospf) { + show_ip_ospf_common(vty, ospf, json, use_vrf); + if (uj) + vty_out(vty, "%s\n", json_object_to_json_string_ext( + json, JSON_C_TO_STRING_PRETTY)); + } + + if (uj) + json_object_free(json); return ret; } @@ -3259,6 +3305,8 @@ DEFUN (show_ip_ospf_instance, struct ospf *ospf; u_short instance = 0; u_char uj = use_json(argc, argv); + int ret = CMD_SUCCESS; + json_object *json = NULL; instance = strtoul(argv[idx_number]->arg, NULL, 10); ospf = ospf_lookup_instance(instance); @@ -3268,7 +3316,18 @@ DEFUN (show_ip_ospf_instance, if (!ospf->oi_running) return CMD_SUCCESS; - return (show_ip_ospf_common(vty, ospf, uj)); + if (uj) + json = json_object_new_object(); + + ret = show_ip_ospf_common(vty, ospf, json, 0); + + if (uj) { + vty_out(vty, "%s\n", json_object_to_json_string_ext(json, + JSON_C_TO_STRING_PRETTY)); + json_object_free(json); + } + + return ret; } static void show_ip_ospf_interface_sub(struct vty *vty, struct ospf *ospf, @@ -3590,16 +3649,19 @@ static void show_ip_ospf_interface_sub(struct vty *vty, struct ospf *ospf, } static int show_ip_ospf_interface_common(struct vty *vty, struct ospf *ospf, - int argc, struct cmd_token **argv, - int iface_argv, u_char use_json) + char *intf_name, u_char use_vrf, + json_object *json, u_char use_json) { struct interface *ifp; struct vrf *vrf = vrf_lookup_by_id(ospf->vrf_id); - json_object *json = NULL; + json_object *json_vrf = NULL; json_object *json_interface_sub = NULL; if (use_json) { - json = json_object_new_object(); + if (use_vrf) + json_vrf = json_object_new_object(); + else + json_vrf = json; } if (ospf->instance) { @@ -3610,7 +3672,9 @@ static int show_ip_ospf_interface_common(struct vty *vty, struct ospf *ospf, vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); } - if (argc == iface_argv) { + ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); + + if (intf_name == NULL) { /* Show All Interfaces.*/ FOR_ALL_INTERFACES (vrf, ifp) { if (ospf_oi_count(ifp)) { @@ -3624,17 +3688,16 @@ static int show_ip_ospf_interface_common(struct vty *vty, struct ospf *ospf, if (use_json) json_object_object_add( - json, ifp->name, + json_vrf, ifp->name, json_interface_sub); } } } else { /* Interface name is specified. */ - if ((ifp = if_lookup_by_name(argv[iface_argv]->arg, - ospf->vrf_id)) - == NULL) { + ifp = if_lookup_by_name(intf_name, ospf->vrf_id); + if (ifp == NULL) { if (use_json) - json_object_boolean_true_add(json, + json_object_boolean_true_add(json_vrf, "noSuchIface"); else vty_out(vty, "No such interface name\n"); @@ -3646,15 +3709,20 @@ static int show_ip_ospf_interface_common(struct vty *vty, struct ospf *ospf, vty, ospf, ifp, json_interface_sub, use_json); if (use_json) - json_object_object_add(json, ifp->name, + json_object_object_add(json_vrf, ifp->name, json_interface_sub); } } if (use_json) { - vty_out(vty, "%s\n", json_object_to_json_string_ext( - json, JSON_C_TO_STRING_PRETTY)); - json_object_free(json); + if (use_vrf) { + if (ospf->vrf_id == VRF_DEFAULT) + json_object_object_add(json, "default", + json_vrf); + else + json_object_object_add(json, ospf->name, + json_vrf); + } } else vty_out(vty, "\n"); @@ -3716,12 +3784,14 @@ static void show_ip_ospf_interface_traffic_sub(struct vty *vty, static int show_ip_ospf_interface_traffic_common(struct vty *vty, struct ospf *ospf, char *intf_name, + json_object *json, int display_once, + u_char use_vrf, u_char use_json) { struct vrf *vrf = NULL; struct interface *ifp = NULL; - json_object *json = NULL; + json_object *json_vrf = NULL; json_object *json_interface_sub = NULL; if (!use_json && !display_once) { @@ -3734,9 +3804,14 @@ static int show_ip_ospf_interface_traffic_common(struct vty *vty, vty_out(vty, "--------------------------------------------------------------------------------------------\n"); } else if (use_json) { - json = json_object_new_object(); + if (use_vrf) + json_vrf = json_object_new_object(); + else + json_vrf = json; } + ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); + if (intf_name == NULL) { vrf = vrf_lookup_by_id(ospf->vrf_id); FOR_ALL_INTERFACES (vrf, ifp) { @@ -3762,8 +3837,9 @@ static int show_ip_ospf_interface_traffic_common(struct vty *vty, json_interface_sub, use_json); if (use_json) { - json_object_object_add(json, ifp->name, - json_interface_sub); + json_object_object_add(json_vrf, + ifp->name, + json_interface_sub); } } } @@ -3793,18 +3869,25 @@ static int show_ip_ospf_interface_traffic_common(struct vty *vty, json_interface_sub, use_json); if (use_json) { - json_object_object_add(json, ifp->name, - json_interface_sub); + json_object_object_add(json_vrf, + ifp->name, + json_interface_sub); } } } } if (use_json) { - vty_out(vty, "%s\n", json_object_to_json_string_ext( - json, JSON_C_TO_STRING_PRETTY)); - json_object_free(json); - } + if (use_vrf) { + if (ospf->vrf_id == VRF_DEFAULT) + json_object_object_add(json, "default", + json_vrf); + else + json_object_object_add(json, ospf->name, + json_vrf); + } + } else + vty_out(vty, "\n"); return CMD_SUCCESS; } @@ -3824,43 +3907,71 @@ DEFUN (show_ip_ospf_interface, struct ospf *ospf; u_char uj = use_json(argc, argv); struct listnode *node = NULL; - char *vrf_name = NULL; + char *vrf_name = NULL, *intf_name = NULL; bool all_vrf = FALSE; int ret = CMD_SUCCESS; int inst = 0; - int idx_vrf = 0; + int idx_vrf = 0, idx_intf = 0; + u_char use_vrf = 0; + json_object *json = NULL; OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); + if (argv_find(argv, argc, "INTERFACE", &idx_intf)) + intf_name = argv[idx_intf]->arg; + if (uj) - argc--; + json = json_object_new_object(); /* vrf input is provided could be all or specific vrf*/ if (vrf_name) { + use_vrf = 1; if (all_vrf) { for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { if (!ospf->oi_running) continue; ret = show_ip_ospf_interface_common(vty, - ospf, argc, - argv, 6, + ospf, + intf_name, + use_vrf, + json, uj); } + + if (uj) { + vty_out(vty, "%s\n", + json_object_to_json_string_ext(json, + JSON_C_TO_STRING_PRETTY)); + json_object_free(json); + } + return ret; } ospf = ospf_lookup_by_inst_name(inst, vrf_name); - if (ospf == NULL || !ospf->oi_running) + if (ospf == NULL || !ospf->oi_running) { + if (uj) + json_object_free(json); return CMD_SUCCESS; - ret = show_ip_ospf_interface_common(vty, ospf, - argc, argv, 6, uj); + } + ret = show_ip_ospf_interface_common(vty, ospf, intf_name, + use_vrf, json, uj); } else { /* Display default ospf (instance 0) info */ ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); - if (ospf == NULL || !ospf->oi_running) + if (ospf == NULL || !ospf->oi_running) { + if (uj) + json_object_free(json); return CMD_SUCCESS; - ret = show_ip_ospf_interface_common(vty, ospf, - argc, argv, 4, uj); + } + ret = show_ip_ospf_interface_common(vty, ospf, intf_name, + use_vrf, json, uj); + } + + if (uj) { + vty_out(vty, "%s\n", json_object_to_json_string_ext(json, + JSON_C_TO_STRING_PRETTY)); + json_object_free(json); } return ret; @@ -3878,9 +3989,13 @@ DEFUN (show_ip_ospf_instance_interface, JSON_STR) { int idx_number = 3; + int idx_intf = 0; struct ospf *ospf; u_short instance = 0; u_char uj = use_json(argc, argv); + char *intf_name = NULL; + int ret = CMD_SUCCESS; + json_object *json = NULL; instance = strtoul(argv[idx_number]->arg, NULL, 10); ospf = ospf_lookup_instance(instance); @@ -3891,9 +4006,20 @@ DEFUN (show_ip_ospf_instance_interface, return CMD_SUCCESS; if (uj) - argc--; + json = json_object_new_object(); + + if (argv_find(argv, argc, "INTERFACE", &idx_intf)) + intf_name = argv[idx_intf]->arg; + + ret = show_ip_ospf_interface_common(vty, ospf, intf_name, 0, json, uj); + + if (uj) { + vty_out(vty, "%s\n", json_object_to_json_string_ext(json, + JSON_C_TO_STRING_PRETTY)); + json_object_free(json); + } - return show_ip_ospf_interface_common(vty, ospf, argc, argv, 5, uj); + return ret; } DEFUN (show_ip_ospf_interface_traffic, @@ -3916,19 +4042,21 @@ DEFUN (show_ip_ospf_interface_traffic, int inst = 0; int idx_vrf = 0, idx_intf = 0; u_char uj = use_json(argc, argv); + json_object *json = NULL; int ret = CMD_SUCCESS; int display_once = 0; - - if (uj) - argc--; - + u_char use_vrf = 0; OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); if (argv_find(argv, argc, "INTERFACE", &idx_intf)) intf_name = argv[idx_intf]->arg; + if (uj) + json = json_object_new_object(); + if (vrf_name) { + use_vrf = 1; if (all_vrf) { for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { if (!ospf->oi_running) @@ -3936,25 +4064,51 @@ DEFUN (show_ip_ospf_interface_traffic, ret = show_ip_ospf_interface_traffic_common(vty, ospf, intf_name, + json, display_once, + use_vrf, uj); display_once = 1; } + + if (uj) { + vty_out(vty, "%s\n", + json_object_to_json_string_ext(json, + JSON_C_TO_STRING_PRETTY)); + json_object_free(json); + } + return ret; } ospf = ospf_lookup_by_inst_name(inst, vrf_name); - if (ospf == NULL || !ospf->oi_running) + if (ospf == NULL || !ospf->oi_running) { + if (uj) + json_object_free(json); return CMD_SUCCESS; + } + ret = show_ip_ospf_interface_traffic_common(vty, ospf, - intf_name, - display_once, uj); + intf_name, json, + display_once, + use_vrf, uj); } else { ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); - if (ospf == NULL || !ospf->oi_running) + if (ospf == NULL || !ospf->oi_running) { + if (uj) + json_object_free(json); return CMD_SUCCESS; + } + ret = show_ip_ospf_interface_traffic_common(vty, ospf, - intf_name, - display_once, uj); + intf_name, json, + display_once, + use_vrf, uj); + } + + if (uj) { + vty_out(vty, "%s\n", json_object_to_json_string_ext(json, + JSON_C_TO_STRING_PRETTY)); + json_object_free(json); } return ret; @@ -3973,132 +4127,131 @@ static void show_ip_ospf_neighbor_sub(struct vty *vty, json_object *json, u_char use_json) { struct route_node *rn; - struct ospf_neighbor *nbr; + struct ospf_neighbor *nbr, *prev_nbr = NULL; char msgbuf[16]; char timebuf[OSPF_TIME_DUMP_SIZE]; - json_object *json_neighbor = NULL; + json_object *json_neighbor = NULL, *json_neigh_array = NULL; for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) { if ((nbr = rn->info)) { /* Do not show myself. */ - if (nbr != oi->nbr_self) { - /* Down state is not shown. */ - if (nbr->state != NSM_Down) { - if (use_json) { - json_neighbor = - json_object_new_object(); - ospf_nbr_state_message( - nbr, msgbuf, 16); - - long time_store; - - time_store = - monotime_until( - &nbr->t_inactivity - ->u - .sands, - NULL) - / 1000LL; - - json_object_int_add( - json_neighbor, - "priority", - nbr->priority); - json_object_string_add( - json_neighbor, "state", - msgbuf); - json_object_int_add( - json_neighbor, - "deadTimeMsecs", - time_store); - json_object_string_add( - json_neighbor, - "address", - inet_ntoa(nbr->src)); - json_object_string_add( - json_neighbor, - "ifaceName", - IF_NAME(oi)); - json_object_int_add( - json_neighbor, - "retransmitCounter", - ospf_ls_retransmit_count( - nbr)); - json_object_int_add( - json_neighbor, - "requestCounter", - ospf_ls_request_count( - nbr)); - json_object_int_add( - json_neighbor, - "dbSummaryCounter", - ospf_db_summary_count( - nbr)); - if (nbr->state == NSM_Attempt - && nbr->router_id.s_addr - == 0) - json_object_object_add( - json, - "neighbor", - json_neighbor); - else - json_object_object_add( - json, - inet_ntoa( - nbr->router_id), - json_neighbor); - } else { - ospf_nbr_state_message( - nbr, msgbuf, 16); - - if (nbr->state == NSM_Attempt - && nbr->router_id.s_addr - == 0) - vty_out(vty, - "%-15s %3d %-15s ", - "-", - nbr->priority, - msgbuf); - else - vty_out(vty, - "%-15s %3d %-15s ", - inet_ntoa( - nbr->router_id), - nbr->priority, - msgbuf); - - vty_out(vty, "%9s ", - ospf_timer_dump( - nbr->t_inactivity, - timebuf, - sizeof(timebuf))); - vty_out(vty, "%-15s ", - inet_ntoa(nbr->src)); - vty_out(vty, - "%-20s %5ld %5ld %5d\n", - IF_NAME(oi), - ospf_ls_retransmit_count( - nbr), - ospf_ls_request_count( - nbr), - ospf_db_summary_count( - nbr)); - } + if (nbr == oi->nbr_self) + continue; + /* Down state is not shown. */ + if (nbr->state == NSM_Down) + continue; + if (use_json) { + char neigh_str[INET_ADDRSTRLEN]; + + if (prev_nbr && + !IPV4_ADDR_SAME(&prev_nbr->src, &nbr->src)) { + /* Start new neigh list */ + json_neigh_array = NULL; + } + + if (nbr->state == NSM_Attempt && + nbr->router_id.s_addr == 0) + strncpy(neigh_str, "neighbor", + INET_ADDRSTRLEN); + else + strncpy(neigh_str, + inet_ntoa(nbr->router_id), + INET_ADDRSTRLEN); + + json_object_object_get_ex(json, neigh_str, + &json_neigh_array); + + if (!json_neigh_array) { + json_neigh_array = json_object_new_array(); + json_object_object_add(json, neigh_str, + json_neigh_array); } + + json_neighbor = + json_object_new_object(); + + ospf_nbr_state_message(nbr, msgbuf, 16); + + long time_store; + + time_store = monotime_until( + &nbr->t_inactivity->u.sands, + NULL) / 1000LL; + + json_object_int_add(json_neighbor, + "priority", + nbr->priority); + json_object_string_add(json_neighbor, "state", + msgbuf); + json_object_int_add(json_neighbor, + "deadTimeMsecs", + time_store); + json_object_string_add(json_neighbor, + "address", + inet_ntoa(nbr->src)); + json_object_string_add(json_neighbor, + "ifaceName", + IF_NAME(oi)); + json_object_int_add(json_neighbor, + "retransmitCounter", + ospf_ls_retransmit_count(nbr)); + json_object_int_add(json_neighbor, + "requestCounter", + ospf_ls_request_count(nbr)); + json_object_int_add(json_neighbor, + "dbSummaryCounter", + ospf_db_summary_count(nbr)); + + json_object_array_add(json_neigh_array, + json_neighbor); + } else { + ospf_nbr_state_message(nbr, msgbuf, 16); + + if (nbr->state == NSM_Attempt && + nbr->router_id.s_addr == 0) + vty_out(vty, + "%-15s %3d %-15s ", + "-", + nbr->priority, + msgbuf); + else + vty_out(vty, + "%-15s %3d %-15s ", + inet_ntoa(nbr->router_id), + nbr->priority, + msgbuf); + + vty_out(vty, "%9s ", + ospf_timer_dump(nbr->t_inactivity, + timebuf, + sizeof(timebuf))); + vty_out(vty, "%-15s ", inet_ntoa(nbr->src)); + vty_out(vty, + "%-20s %5ld %5ld %5d\n", + IF_NAME(oi), + ospf_ls_retransmit_count(nbr), + ospf_ls_request_count(nbr), + ospf_db_summary_count(nbr)); } + prev_nbr = nbr; } } } static int show_ip_ospf_neighbor_common(struct vty *vty, struct ospf *ospf, - u_char use_json) + json_object *json, u_char use_json, + u_char use_vrf) { struct ospf_interface *oi; struct listnode *node; - json_object *json = NULL; + json_object *json_vrf = NULL; - if (use_json) - json = json_object_new_object(); + if (use_json) { + if (use_vrf) + json_vrf = json_object_new_object(); + else + json_vrf = json; + } if (ospf->instance) { if (use_json) @@ -4108,15 +4261,22 @@ static int show_ip_ospf_neighbor_common(struct vty *vty, struct ospf *ospf, vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); } - ospf_show_vrf_name(ospf, vty, json); + ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); + if (!use_json) + show_ip_ospf_neighbour_header(vty); for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) - show_ip_ospf_neighbor_sub(vty, oi, json, use_json); + show_ip_ospf_neighbor_sub(vty, oi, json_vrf, use_json); if (use_json) { - vty_out(vty, "%s\n", json_object_to_json_string_ext( - json, JSON_C_TO_STRING_PRETTY)); - json_object_free(json); + if (use_vrf) { + if (ospf->vrf_id == VRF_DEFAULT) + json_object_object_add(json, "default", + json_vrf); + else + json_object_object_add(json, ospf->name, + json_vrf); + } } else vty_out(vty, "\n"); @@ -4142,35 +4302,65 @@ DEFUN (show_ip_ospf_neighbor, int ret = CMD_SUCCESS; int inst = 0; int idx_vrf = 0; + u_char use_vrf = 0; + json_object *json = NULL; OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); - if (!uj) - show_ip_ospf_neighbour_header(vty); + if (uj) + json = json_object_new_object(); /* vrf input is provided could be all or specific vrf*/ if (vrf_name) { + use_vrf = 1; if (all_vrf) { for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { if (!ospf->oi_running) continue; ret = show_ip_ospf_neighbor_common(vty, ospf, - uj); + json, uj, + use_vrf); } + + if (uj) { + vty_out(vty, "%s\n", + json_object_to_json_string_ext(json, + JSON_C_TO_STRING_PRETTY)); + json_object_free(json); + } + return ret; } + ospf = ospf_lookup_by_inst_name(inst, vrf_name); - if (ospf == NULL || !ospf->oi_running) + if (ospf == NULL || !ospf->oi_running) { + if (uj) + json_object_free(json); return CMD_SUCCESS; + } } else { /* Display default ospf (instance 0) info */ ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); - if (ospf == NULL || !ospf->oi_running) + if (ospf == NULL || !ospf->oi_running) { + if (uj) + json_object_free(json); return CMD_SUCCESS; + } } - if (ospf) - ret = show_ip_ospf_neighbor_common(vty, ospf, uj); + if (ospf) { + ret = show_ip_ospf_neighbor_common(vty, ospf, json, uj, + use_vrf); + + if (uj) { + vty_out(vty, "%s\n", + json_object_to_json_string_ext(json, + JSON_C_TO_STRING_PRETTY)); + } + } + + if (uj) + json_object_free(json); return ret; } @@ -4190,6 +4380,8 @@ DEFUN (show_ip_ospf_instance_neighbor, struct ospf *ospf; u_short instance = 0; u_char uj = use_json(argc, argv); + json_object *json = NULL; + int ret = CMD_SUCCESS; instance = strtoul(argv[idx_number]->arg, NULL, 10); ospf = ospf_lookup_instance(instance); @@ -4199,54 +4391,55 @@ DEFUN (show_ip_ospf_instance_neighbor, if (!ospf->oi_running) return CMD_SUCCESS; - if (!uj) - show_ip_ospf_neighbour_header(vty); + if (uj) + json = json_object_new_object(); - return show_ip_ospf_neighbor_common(vty, ospf, uj); + ret = show_ip_ospf_neighbor_common(vty, ospf, json, uj, 0); + + if (uj) { + vty_out(vty, "%s\n", json_object_to_json_string_ext(json, + JSON_C_TO_STRING_PRETTY)); + json_object_free(json); + } + + return ret; } static int show_ip_ospf_neighbor_all_common(struct vty *vty, struct ospf *ospf, - u_char use_json) + json_object *json, + u_char use_json, + u_char use_vrf) { struct listnode *node; struct ospf_interface *oi; - json_object *json = NULL; + json_object *json_vrf = NULL; json_object *json_neighbor_sub = NULL; if (use_json) { - json = json_object_new_object(); + if (use_vrf) + json_vrf = json_object_new_object(); + else + json_vrf = json; json_neighbor_sub = json_object_new_object(); } + ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); + if (!use_json) + show_ip_ospf_neighbour_header(vty); + if (ospf->instance) { if (use_json) - json_object_int_add(json, "ospfInstance", + json_object_int_add(json_vrf, "ospfInstance", ospf->instance); else vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); } - if (ospf->name) { - if (use_json) { - json_object_int_add(json, "vrfId", - (ospf->vrf_id == VRF_UNKNOWN) - ? -1 : ospf->vrf_id); - json_object_string_add(json, "vrfName", - (ospf->vrf_id == VRF_DEFAULT) - ? "Default" : ospf->name); - } else { - vty_out(vty, "\nOSPF vrf: %s\n\n", - ospf->vrf_id == VRF_DEFAULT - ? "Default" : ospf->name); - } - } - - for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) { struct listnode *nbr_node; struct ospf_nbr_nbma *nbr_nbma; - show_ip_ospf_neighbor_sub(vty, oi, json, use_json); + show_ip_ospf_neighbor_sub(vty, oi, json_vrf, use_json); /* print Down neighbor status */ for (ALL_LIST_ELEMENTS_RO(oi->nbr_nbma, nbr_node, nbr_nbma)) { @@ -4273,7 +4466,8 @@ static int show_ip_ospf_neighbor_all_common(struct vty *vty, struct ospf *ospf, json_neighbor_sub, "nbrNbmaDbSummaryCounter", 0); json_object_object_add( - json, inet_ntoa(nbr_nbma->addr), + json_vrf, + inet_ntoa(nbr_nbma->addr), json_neighbor_sub); } else { vty_out(vty, "%-15s %3d %-15s %9s ", @@ -4289,9 +4483,14 @@ static int show_ip_ospf_neighbor_all_common(struct vty *vty, struct ospf *ospf, } if (use_json) { - vty_out(vty, "%s\n", json_object_to_json_string_ext( - json, JSON_C_TO_STRING_PRETTY)); - json_object_free(json); + if (use_vrf) { + if (ospf->vrf_id == VRF_DEFAULT) + json_object_object_add(json, "default", + json_vrf); + else + json_object_object_add(json, ospf->name, + json_vrf); + } } else vty_out(vty, "\n"); @@ -4318,36 +4517,66 @@ DEFUN (show_ip_ospf_neighbor_all, int ret = CMD_SUCCESS; int inst = 0; int idx_vrf = 0; + u_char use_vrf = 0; + json_object *json = NULL; OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); - if (!uj) - show_ip_ospf_neighbour_header(vty); + if (uj) + json = json_object_new_object(); /* vrf input is provided could be all or specific vrf*/ if (vrf_name) { + use_vrf = 1; if (all_vrf) { for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { if (!ospf->oi_running) continue; ret = show_ip_ospf_neighbor_all_common(vty, ospf, - uj); + json, + uj, + use_vrf); + } + + if (uj) { + vty_out(vty, "%s\n", + json_object_to_json_string_ext(json, + JSON_C_TO_STRING_PRETTY)); + json_object_free(json); } + return ret; } + ospf = ospf_lookup_by_inst_name(inst, vrf_name); - if (ospf == NULL || !ospf->oi_running) + if (ospf == NULL || !ospf->oi_running) { + if (uj) + json_object_free(json); return CMD_SUCCESS; + } } else { /* Display default ospf (instance 0) info */ ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); - if (ospf == NULL || !ospf->oi_running) + if (ospf == NULL || !ospf->oi_running) { + if (uj) + json_object_free(json); return CMD_SUCCESS; + } } - if (ospf) - ret = show_ip_ospf_neighbor_all_common(vty, ospf, uj); + if (ospf) { + ret = show_ip_ospf_neighbor_all_common(vty, ospf, json, uj, + use_vrf); + if (uj) { + vty_out(vty, "%s\n", + json_object_to_json_string_ext(json, + JSON_C_TO_STRING_PRETTY)); + } + } + + if (uj) + json_object_free(json); return ret; } @@ -4367,6 +4596,8 @@ DEFUN (show_ip_ospf_instance_neighbor_all, struct ospf *ospf; u_short instance = 0; u_char uj = use_json(argc, argv); + json_object *json = NULL; + int ret = CMD_SUCCESS; instance = strtoul(argv[idx_number]->arg, NULL, 10); ospf = ospf_lookup_instance(instance); @@ -4375,14 +4606,24 @@ DEFUN (show_ip_ospf_instance_neighbor_all, if (!ospf->oi_running) return CMD_SUCCESS; + if (uj) + json = json_object_new_object(); - return show_ip_ospf_neighbor_all_common(vty, ospf, uj); + ret = show_ip_ospf_neighbor_all_common(vty, ospf, json, uj, 0); + + if (uj) { + vty_out(vty, "%s\n", json_object_to_json_string_ext( + json, JSON_C_TO_STRING_PRETTY)); + json_object_free(json); + } + + return ret; } static int show_ip_ospf_neighbor_int_common(struct vty *vty, struct ospf *ospf, int arg_base, struct cmd_token **argv, - u_char use_json) + u_char use_json, u_char use_vrf) { struct interface *ifp; struct route_node *rn; @@ -4399,7 +4640,7 @@ static int show_ip_ospf_neighbor_int_common(struct vty *vty, struct ospf *ospf, vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); } - ospf_show_vrf_name(ospf, vty, json); + ospf_show_vrf_name(ospf, vty, json, use_vrf); /*ifp = if_lookup_by_name(argv[arg_base]->arg, ospf->vrf_id);*/ ifp = if_lookup_by_name_all_vrf(argv[arg_base]->arg); @@ -4457,7 +4698,7 @@ DEFUN (show_ip_ospf_neighbor_int, if (!ifp || ifp->vrf_id != ospf->vrf_id) continue; ret = show_ip_ospf_neighbor_int_common(vty, ospf, - idx_ifname, argv, uj); + idx_ifname, argv, uj, 0); } return ret; @@ -4494,7 +4735,8 @@ DEFUN (show_ip_ospf_instance_neighbor_int, if (!uj) show_ip_ospf_neighbour_header(vty); - return show_ip_ospf_neighbor_int_common(vty, ospf, idx_ifname, argv, uj); + return show_ip_ospf_neighbor_int_common(vty, ospf, idx_ifname, + argv, uj, 0); } static void show_ip_ospf_nbr_nbma_detail_sub(struct vty *vty, @@ -4577,7 +4819,8 @@ static void show_ip_ospf_nbr_nbma_detail_sub(struct vty *vty, static void show_ip_ospf_neighbor_detail_sub(struct vty *vty, struct ospf_interface *oi, struct ospf_neighbor *nbr, - u_char use_json, json_object *json) + json_object *json, + u_char use_json) { char timebuf[OSPF_TIME_DUMP_SIZE]; json_object *json_sub = NULL; @@ -4793,7 +5036,8 @@ static void show_ip_ospf_neighbor_detail_sub(struct vty *vty, static int show_ip_ospf_neighbor_id_common(struct vty *vty, struct ospf *ospf, int arg_base, struct cmd_token **argv, - u_char use_json) + u_char use_json, + u_char use_vrf) { struct listnode *node; struct ospf_neighbor *nbr; @@ -4813,7 +5057,7 @@ static int show_ip_ospf_neighbor_id_common(struct vty *vty, struct ospf *ospf, vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); } - ospf_show_vrf_name(ospf, vty, json); + ospf_show_vrf_name(ospf, vty, json, use_vrf); ret = inet_aton(argv[arg_base]->arg, &router_id); if (!ret) { @@ -4828,8 +5072,8 @@ static int show_ip_ospf_neighbor_id_common(struct vty *vty, struct ospf *ospf, for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) { if ((nbr = ospf_nbr_lookup_by_routerid(oi->nbrs, &router_id))) { - show_ip_ospf_neighbor_detail_sub(vty, oi, nbr, use_json, - json); + show_ip_ospf_neighbor_detail_sub(vty, oi, nbr, json, + use_json); } } @@ -4861,7 +5105,8 @@ DEFUN (show_ip_ospf_neighbor_id, for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { if (!ospf->oi_running) continue; - ret = show_ip_ospf_neighbor_id_common(vty, ospf, 0, argv, uj); + ret = show_ip_ospf_neighbor_id_common(vty, ospf, 0, + argv, uj, 0); } return ret; @@ -4892,29 +5137,35 @@ DEFUN (show_ip_ospf_instance_neighbor_id, if (!ospf->oi_running) return CMD_SUCCESS; - return show_ip_ospf_neighbor_id_common(vty, ospf, idx_router_id, argv, uj); + return show_ip_ospf_neighbor_id_common(vty, ospf, idx_router_id, argv, + uj, 0); } static int show_ip_ospf_neighbor_detail_common(struct vty *vty, struct ospf *ospf, - u_char use_json) + json_object *json, + u_char use_json, + u_char use_vrf) { struct ospf_interface *oi; struct listnode *node; - json_object *json = NULL; - - if (use_json) - json = json_object_new_object(); + json_object *json_vrf = NULL; + if (use_json) { + if (use_vrf) + json_vrf = json_object_new_object(); + else + json_vrf = json; + } if (ospf->instance) { if (use_json) - json_object_int_add(json, "ospfInstance", + json_object_int_add(json_vrf, "ospfInstance", ospf->instance); else vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); } - ospf_show_vrf_name(ospf, vty, json); + ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) { struct route_node *rn; @@ -4925,8 +5176,8 @@ static int show_ip_ospf_neighbor_detail_common(struct vty *vty, if (nbr != oi->nbr_self) { if (nbr->state != NSM_Down) { show_ip_ospf_neighbor_detail_sub( - vty, oi, nbr, use_json, - json); + vty, oi, nbr, json_vrf, + use_json); } } } @@ -4934,9 +5185,14 @@ static int show_ip_ospf_neighbor_detail_common(struct vty *vty, } if (use_json) { - vty_out(vty, "%s\n", json_object_to_json_string_ext( - json, JSON_C_TO_STRING_PRETTY)); - json_object_free(json); + if (use_vrf) { + if (ospf->vrf_id == VRF_DEFAULT) + json_object_object_add(json, "default", + json_vrf); + else + json_object_object_add(json, ospf->name, + json_vrf); + } } else vty_out(vty, "\n"); @@ -4963,33 +5219,64 @@ DEFUN (show_ip_ospf_neighbor_detail, int ret = CMD_SUCCESS; int inst = 0; int idx_vrf = 0; + u_char use_vrf = 0; + json_object *json = NULL; OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); + if (uj) + json = json_object_new_object(); + /* vrf input is provided could be all or specific vrf*/ if (vrf_name) { + use_vrf = 1; if (all_vrf) { for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { if (!ospf->oi_running) continue; ret = show_ip_ospf_neighbor_detail_common(vty, - ospf, - uj); + ospf, + json, + uj, + use_vrf); + } + if (uj) { + vty_out(vty, "%s\n", + json_object_to_json_string_ext(json, + JSON_C_TO_STRING_PRETTY)); + json_object_free(json); } + return ret; } ospf = ospf_lookup_by_inst_name(inst, vrf_name); - if (ospf == NULL || !ospf->oi_running) + if (ospf == NULL || !ospf->oi_running) { + if (uj) + json_object_free(json); return CMD_SUCCESS; + } } else { /* Display default ospf (instance 0) info */ ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); - if (ospf == NULL || !ospf->oi_running) + if (ospf == NULL || !ospf->oi_running) { + if (uj) + json_object_free(json); return CMD_SUCCESS; + } } - if (ospf) - ret = show_ip_ospf_neighbor_detail_common(vty, ospf, uj); + if (ospf) { + ret = show_ip_ospf_neighbor_detail_common(vty, ospf, json, uj, + use_vrf); + if (uj) { + vty_out(vty, "%s\n", + json_object_to_json_string_ext(json, + JSON_C_TO_STRING_PRETTY)); + } + } + + if (uj) + json_object_free(json); return ret; } @@ -5009,6 +5296,8 @@ DEFUN (show_ip_ospf_instance_neighbor_detail, struct ospf *ospf; u_short instance = 0; u_char uj = use_json(argc, argv); + json_object *json = NULL; + int ret = CMD_SUCCESS; instance = strtoul(argv[idx_number]->arg, NULL, 10); ospf = ospf_lookup_instance(instance); @@ -5018,19 +5307,36 @@ DEFUN (show_ip_ospf_instance_neighbor_detail, if (!ospf->oi_running) return CMD_SUCCESS; - return show_ip_ospf_neighbor_detail_common(vty, ospf, uj); + if (uj) + json = json_object_new_object(); + + ret = show_ip_ospf_neighbor_detail_common(vty, ospf, json, uj, 0); + + if (uj) { + vty_out(vty, "%s\n", json_object_to_json_string_ext( + json, JSON_C_TO_STRING_PRETTY)); + json_object_free(json); + } + + return ret; } static int show_ip_ospf_neighbor_detail_all_common(struct vty *vty, struct ospf *ospf, - u_char use_json) + json_object *json, + u_char use_json, + u_char use_vrf) { struct listnode *node; struct ospf_interface *oi; - json_object *json = NULL; + json_object *json_vrf = NULL; - if (use_json) - json = json_object_new_object(); + if (use_json) { + if (use_vrf) + json_vrf = json_object_new_object(); + else + json_vrf = json; + } if (ospf->instance) { if (use_json) @@ -5040,7 +5346,7 @@ static int show_ip_ospf_neighbor_detail_all_common(struct vty *vty, vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); } - ospf_show_vrf_name(ospf, vty, json); + ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) { struct route_node *rn; @@ -5053,7 +5359,7 @@ static int show_ip_ospf_neighbor_detail_all_common(struct vty *vty, if (nbr->state != NSM_Down) show_ip_ospf_neighbor_detail_sub( vty, oi, rn->info, - use_json, json); + json_vrf, use_json); if (oi->type == OSPF_IFTYPE_NBMA) { struct listnode *nd; @@ -5063,15 +5369,20 @@ static int show_ip_ospf_neighbor_detail_all_common(struct vty *vty, || nbr_nbma->nbr->state == NSM_Down) show_ip_ospf_nbr_nbma_detail_sub( vty, oi, nbr_nbma, use_json, - json); + json_vrf); } } } if (use_json) { - vty_out(vty, "%s\n", json_object_to_json_string_ext( - json, JSON_C_TO_STRING_PRETTY)); - json_object_free(json); + if (use_vrf) { + if (ospf->vrf_id == VRF_DEFAULT) + json_object_object_add(json, "default", + json_vrf); + else + json_object_object_add(json, ospf->name, + json_vrf); + } } else { vty_out(vty, "\n"); } @@ -5100,33 +5411,65 @@ DEFUN (show_ip_ospf_neighbor_detail_all, int ret = CMD_SUCCESS; int inst = 0; int idx_vrf = 0; + u_char use_vrf = 0; + json_object *json = NULL; OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); + if (uj) + json = json_object_new_object(); + /* vrf input is provided could be all or specific vrf*/ if (vrf_name) { + use_vrf = 1; if (all_vrf) { for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { if (!ospf->oi_running) continue; ret = show_ip_ospf_neighbor_detail_all_common(vty, - ospf, - uj); + ospf, + json, + uj, + use_vrf); } + + if (uj) { + vty_out(vty, "%s\n", + json_object_to_json_string_ext(json, + JSON_C_TO_STRING_PRETTY)); + json_object_free(json); + } + return ret; } ospf = ospf_lookup_by_inst_name(inst, vrf_name); - if (ospf == NULL || !ospf->oi_running) + if (ospf == NULL || !ospf->oi_running) { + if (uj) + json_object_free(json); return CMD_SUCCESS; + } } else { /* Display default ospf (instance 0) info */ ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); - if (ospf == NULL || !ospf->oi_running) + if (ospf == NULL || !ospf->oi_running) { + if (uj) + json_object_free(json); return CMD_SUCCESS; + } } - if (ospf) - ret = show_ip_ospf_neighbor_detail_all_common(vty, ospf, uj); + if (ospf) { + ret = show_ip_ospf_neighbor_detail_all_common(vty, ospf, json, + uj, use_vrf); + if (uj) { + vty_out(vty, "%s\n", + json_object_to_json_string_ext(json, + JSON_C_TO_STRING_PRETTY)); + } + } + + if (uj) + json_object_free(json); return ret; } @@ -5147,6 +5490,8 @@ DEFUN (show_ip_ospf_instance_neighbor_detail_all, struct ospf *ospf; u_short instance = 0; u_char uj = use_json(argc, argv); + json_object *json = NULL; + int ret = CMD_SUCCESS; instance = strtoul(argv[idx_number]->arg, NULL, 10); ospf = ospf_lookup_instance(instance); @@ -5156,7 +5501,18 @@ DEFUN (show_ip_ospf_instance_neighbor_detail_all, if (!ospf->oi_running) return CMD_SUCCESS; - return show_ip_ospf_neighbor_detail_all_common(vty, ospf, uj); + if (uj) + json = json_object_new_object(); + + ret = show_ip_ospf_neighbor_detail_all_common(vty, ospf, json, uj, 0); + + if (uj) { + vty_out(vty, "%s\n", json_object_to_json_string_ext(json, + JSON_C_TO_STRING_PRETTY)); + json_object_free(json); + } + + return ret; } static int show_ip_ospf_neighbor_int_detail_common(struct vty *vty, @@ -5202,7 +5558,7 @@ static int show_ip_ospf_neighbor_int_detail_common(struct vty *vty, if (nbr->state != NSM_Down) show_ip_ospf_neighbor_detail_sub( vty, oi, nbr, - use_json, json); + json, use_json); } } } @@ -5843,7 +6199,8 @@ static void show_ip_ospf_database_maxage(struct vty *vty, struct ospf *ospf) static int show_ip_ospf_database_common(struct vty *vty, struct ospf *ospf, int arg_base, int argc, - struct cmd_token **argv) + struct cmd_token **argv, + u_char use_vrf) { int idx_type = 4; int type, ret; @@ -5852,7 +6209,7 @@ static int show_ip_ospf_database_common(struct vty *vty, struct ospf *ospf, if (ospf->instance) vty_out(vty, "\nOSPF Instance: %d\n", ospf->instance); - ospf_show_vrf_name(ospf, vty, NULL); + ospf_show_vrf_name(ospf, vty, NULL, use_vrf); vty_out(vty, "\n OSPF Router with ID (%s)\n\n", inet_ntoa(ospf->router_id)); @@ -5938,10 +6295,12 @@ DEFUN (show_ip_ospf_database_max, int ret = CMD_SUCCESS; int inst = 0; int idx_vrf = 0; + u_char use_vrf = 0; OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); if (vrf_name) { + use_vrf = 1; if (all_vrf) { for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { if (!ospf->oi_running) @@ -5949,21 +6308,24 @@ DEFUN (show_ip_ospf_database_max, ret = show_ip_ospf_database_common(vty, ospf, idx_vrf ? 2 : 0, argc, - argv); + argv, + use_vrf); } } else { ospf = ospf_lookup_by_inst_name(inst, vrf_name); if (ospf == NULL || !ospf->oi_running) return CMD_SUCCESS; ret = (show_ip_ospf_database_common(vty, ospf, idx_vrf ? - 2 : 0, argc, argv)); + 2 : 0, argc, argv, + use_vrf)); } } else { /* Display default ospf (instance 0) info */ ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); if (ospf == NULL || !ospf->oi_running) return CMD_SUCCESS; - ret = show_ip_ospf_database_common(vty, ospf, 0, argc, argv); + ret = show_ip_ospf_database_common(vty, ospf, 0, argc, argv, + use_vrf); } return ret; @@ -5992,6 +6354,7 @@ DEFUN (show_ip_ospf_instance_database, int ret = CMD_SUCCESS; int inst = 0; int idx = 0; + u_char use_vrf = 0; if (argv_find(argv, argc, "(1-65535)", &idx)) { instance = strtoul(argv[idx]->arg, NULL, 10); @@ -6002,34 +6365,38 @@ DEFUN (show_ip_ospf_instance_database, return CMD_SUCCESS; return (show_ip_ospf_database_common(vty, ospf, idx ? 1 : 0, - argc, argv)); + argc, argv, use_vrf)); } else if (argv_find(argv, argc, "vrf", &idx)) { vrf_name = argv[++idx]->arg; all_vrf = strmatch(vrf_name, "all"); } if (vrf_name) { + use_vrf = 1; if (all_vrf) { for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { if (!ospf->oi_running) continue; ret = (show_ip_ospf_database_common(vty, ospf, idx ? 2 : 0, - argc, argv)); + argc, argv, + use_vrf)); } } else { ospf = ospf_lookup_by_inst_name(inst, vrf_name); if ((ospf == NULL) || !ospf->oi_running) return CMD_SUCCESS; ret = (show_ip_ospf_database_common(vty, ospf, idx ? 2 : - 0, argc, argv)); + 0, argc, argv, + use_vrf)); } } else { /* Display default ospf (instance 0) info */ ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); if (ospf == NULL || !ospf->oi_running) return CMD_SUCCESS; - ret = (show_ip_ospf_database_common(vty, ospf, 0, argc, argv)); + ret = (show_ip_ospf_database_common(vty, ospf, 0, argc, argv, + use_vrf)); } return ret; @@ -6059,14 +6426,15 @@ DEFUN (show_ip_ospf_instance_database_max, if (!ospf->oi_running) return CMD_SUCCESS; - return (show_ip_ospf_database_common(vty, ospf, 1, argc, argv)); + return show_ip_ospf_database_common(vty, ospf, 1, argc, argv, 0); } static int show_ip_ospf_database_type_adv_router_common(struct vty *vty, struct ospf *ospf, int arg_base, int argc, - struct cmd_token **argv) + struct cmd_token **argv, + u_char use_vrf) { int idx_type = 4; int type, ret; @@ -6075,7 +6443,7 @@ static int show_ip_ospf_database_type_adv_router_common(struct vty *vty, if (ospf->instance) vty_out(vty, "\nOSPF Instance: %d\n", ospf->instance); - ospf_show_vrf_name(ospf, vty, NULL); + ospf_show_vrf_name(ospf, vty, NULL, use_vrf); vty_out(vty, "\n OSPF Router with ID (%s)\n\n", inet_ntoa(ospf->router_id)); @@ -6138,6 +6506,7 @@ DEFUN (show_ip_ospf_instance_database_type_adv_router, int ret = CMD_SUCCESS; int inst = 0; int idx = 0, idx_vrf = 0; + u_char use_vrf = 0; if (argv_find(argv, argc, "(1-65535)", &idx)) { instance = strtoul(argv[idx]->arg, NULL, 10); @@ -6149,25 +6518,29 @@ DEFUN (show_ip_ospf_instance_database_type_adv_router, return (show_ip_ospf_database_type_adv_router_common(vty, ospf, idx ? 1 : 0, argc, - argv)); + argv, + use_vrf)); } OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); if (vrf_name) { + use_vrf = 1; if (all_vrf) { for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { if (!ospf->oi_running) continue; ret = show_ip_ospf_database_type_adv_router_common(vty, - ospf, idx ? 1 : 0, argc, argv); + ospf, idx ? 1 : 0, argc, argv, + use_vrf); } } else { ospf = ospf_lookup_by_inst_name(inst, vrf_name); if ((ospf == NULL) || !ospf->oi_running) return CMD_SUCCESS; ret = show_ip_ospf_database_type_adv_router_common(vty, - ospf, idx ? 1 : 0, argc, argv); + ospf, idx ? 1 : 0, argc, argv, + use_vrf); } } else { /* Display default ospf (instance 0) info */ @@ -6176,7 +6549,8 @@ DEFUN (show_ip_ospf_instance_database_type_adv_router, return CMD_SUCCESS; ret = show_ip_ospf_database_type_adv_router_common(vty, ospf, idx ? 1 : 0, - argc, argv); + argc, argv, + use_vrf); } return ret; /*return (show_ip_ospf_database_type_adv_router_common( @@ -8640,12 +9014,13 @@ static void show_ip_ospf_route_external(struct vty *vty, struct ospf *ospf, } static int show_ip_ospf_border_routers_common(struct vty *vty, - struct ospf *ospf) + struct ospf *ospf, + u_char use_vrf) { if (ospf->instance) vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); - ospf_show_vrf_name(ospf, vty, NULL); + ospf_show_vrf_name(ospf, vty, NULL, use_vrf); if (ospf->new_table == NULL) { vty_out(vty, "No OSPF routing information exist\n"); @@ -8680,31 +9055,35 @@ DEFUN (show_ip_ospf_border_routers, int ret = CMD_SUCCESS; int inst = 0; int idx_vrf = 0; + u_char use_vrf = 0; OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); if (vrf_name) { + use_vrf = 1; if (all_vrf) { for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { if (!ospf->oi_running) continue; ret = show_ip_ospf_border_routers_common(vty, - ospf); + ospf, + use_vrf); } } else { ospf = ospf_lookup_by_inst_name(inst, vrf_name); if (ospf == NULL || !ospf->oi_running) return CMD_SUCCESS; - ret = show_ip_ospf_border_routers_common(vty, ospf); + ret = show_ip_ospf_border_routers_common(vty, ospf, + use_vrf); } } else { /* Display default ospf (instance 0) info */ ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); if (ospf == NULL || !ospf->oi_running) return CMD_SUCCESS; - ret = show_ip_ospf_border_routers_common(vty, ospf); + ret = show_ip_ospf_border_routers_common(vty, ospf, use_vrf); } return ret; @@ -8731,15 +9110,16 @@ DEFUN (show_ip_ospf_instance_border_routers, if (!ospf->oi_running) return CMD_SUCCESS; - return show_ip_ospf_border_routers_common(vty, ospf); + return show_ip_ospf_border_routers_common(vty, ospf, 0); } -static int show_ip_ospf_route_common(struct vty *vty, struct ospf *ospf) +static int show_ip_ospf_route_common(struct vty *vty, struct ospf *ospf, + u_char use_vrf) { if (ospf->instance) vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); - ospf_show_vrf_name(ospf, vty, NULL); + ospf_show_vrf_name(ospf, vty, NULL, use_vrf); if (ospf->new_table == NULL) { vty_out(vty, "No OSPF routing information exist\n"); @@ -8777,16 +9157,19 @@ DEFUN (show_ip_ospf_route, int ret = CMD_SUCCESS; int inst = 0; int idx_vrf = 0; + u_char use_vrf = 0; OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); /* vrf input is provided could be all or specific vrf*/ if (vrf_name) { + use_vrf = 1; if (all_vrf) { for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { if (!ospf->oi_running) continue; - ret = show_ip_ospf_route_common(vty, ospf); + ret = show_ip_ospf_route_common(vty, ospf, + use_vrf); } return ret; } @@ -8801,7 +9184,7 @@ DEFUN (show_ip_ospf_route, } if (ospf) - ret = show_ip_ospf_route_common(vty, ospf); + ret = show_ip_ospf_route_common(vty, ospf, use_vrf); return ret; } @@ -8827,7 +9210,7 @@ DEFUN (show_ip_ospf_instance_route, if (!ospf->oi_running) return CMD_SUCCESS; - return show_ip_ospf_route_common(vty, ospf); + return show_ip_ospf_route_common(vty, ospf, 0); } |
