summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bgpd/bgp_fsm.c2
-rw-r--r--bgpd/bgp_packet.c7
-rw-r--r--bgpd/bgp_snmp.c4
-rw-r--r--bgpd/bgp_vty.c21
-rw-r--r--bgpd/bgpd.c67
-rw-r--r--bgpd/bgpd.h5
-rw-r--r--ospfd/ospf_network.c5
-rw-r--r--ospfd/ospf_vty.c1106
8 files changed, 819 insertions, 398 deletions
diff --git a/bgpd/bgp_fsm.c b/bgpd/bgp_fsm.c
index b609abac69..aa350d3dd4 100644
--- a/bgpd/bgp_fsm.c
+++ b/bgpd/bgp_fsm.c
@@ -1096,7 +1096,7 @@ int bgp_stop(struct peer *peer)
}
/* Reset keepalive and holdtime */
- if (CHECK_FLAG(peer->config, PEER_CONFIG_TIMER)) {
+ if (PEER_OR_GROUP_TIMER_SET(peer)) {
peer->v_keepalive = peer->keepalive;
peer->v_holdtime = peer->holdtime;
} else {
diff --git a/bgpd/bgp_packet.c b/bgpd/bgp_packet.c
index a66d0590c9..28700dd241 100644
--- a/bgpd/bgp_packet.c
+++ b/bgpd/bgp_packet.c
@@ -529,7 +529,7 @@ void bgp_open_send(struct peer *peer)
u_int16_t send_holdtime;
as_t local_as;
- if (CHECK_FLAG(peer->config, PEER_CONFIG_TIMER))
+ if (PEER_OR_GROUP_TIMER_SET(peer))
send_holdtime = peer->holdtime;
else
send_holdtime = peer->bgp->default_holdtime;
@@ -1087,7 +1087,7 @@ static int bgp_open_receive(struct peer *peer, bgp_size_t size)
implementation MAY adjust the rate at which it sends KEEPALIVE
messages as a function of the Hold Time interval. */
- if (CHECK_FLAG(peer->config, PEER_CONFIG_TIMER))
+ if (PEER_OR_GROUP_TIMER_SET(peer))
send_holdtime = peer->holdtime;
else
send_holdtime = peer->bgp->default_holdtime;
@@ -1097,7 +1097,8 @@ static int bgp_open_receive(struct peer *peer, bgp_size_t size)
else
peer->v_holdtime = send_holdtime;
- if (CHECK_FLAG(peer->config, PEER_CONFIG_TIMER))
+ if ((PEER_OR_GROUP_TIMER_SET(peer))
+ && (peer->keepalive < peer->v_holdtime / 3))
peer->v_keepalive = peer->keepalive;
else
peer->v_keepalive = peer->v_holdtime / 3;
diff --git a/bgpd/bgp_snmp.c b/bgpd/bgp_snmp.c
index 8a9d61f305..484ea7c433 100644
--- a/bgpd/bgp_snmp.c
+++ b/bgpd/bgp_snmp.c
@@ -615,14 +615,14 @@ static u_char *bgpPeerTable(struct variable *v, oid name[], size_t *length,
break;
case BGPPEERHOLDTIMECONFIGURED:
*write_method = write_bgpPeerTable;
- if (CHECK_FLAG(peer->config, PEER_CONFIG_TIMER))
+ if (PEER_OR_GROUP_TIMER_SET(peer))
return SNMP_INTEGER(peer->holdtime);
else
return SNMP_INTEGER(peer->v_holdtime);
break;
case BGPPEERKEEPALIVECONFIGURED:
*write_method = write_bgpPeerTable;
- if (CHECK_FLAG(peer->config, PEER_CONFIG_TIMER))
+ if (PEER_OR_GROUP_TIMER_SET(peer))
return SNMP_INTEGER(peer->keepalive);
else
return SNMP_INTEGER(peer->v_keepalive);
diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c
index 18190a4f95..db19835f88 100644
--- a/bgpd/bgp_vty.c
+++ b/bgpd/bgp_vty.c
@@ -8272,7 +8272,7 @@ static void bgp_show_peer(struct vty *vty, struct peer *p, u_char use_json,
"bgpTimerKeepAliveIntervalMsecs",
p->v_keepalive * 1000);
- if (CHECK_FLAG(p->config, PEER_CONFIG_TIMER)) {
+ if (PEER_OR_GROUP_TIMER_SET(p)) {
json_object_int_add(json_neigh,
"bgpTimerConfiguredHoldTimeMsecs",
p->holdtime * 1000);
@@ -8280,6 +8280,16 @@ static void bgp_show_peer(struct vty *vty, struct peer *p, u_char use_json,
json_neigh,
"bgpTimerConfiguredKeepAliveIntervalMsecs",
p->keepalive * 1000);
+ } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
+ || (bgp->default_keepalive !=
+ BGP_DEFAULT_KEEPALIVE)) {
+ json_object_int_add(json_neigh,
+ "bgpTimerConfiguredHoldTimeMsecs",
+ bgp->default_holdtime);
+ json_object_int_add(
+ json_neigh,
+ "bgpTimerConfiguredKeepAliveIntervalMsecs",
+ bgp->default_keepalive);
}
} else {
/* Administrative shutdown. */
@@ -8326,11 +8336,18 @@ static void bgp_show_peer(struct vty *vty, struct peer *p, u_char use_json,
vty_out(vty,
" Hold time is %d, keepalive interval is %d seconds\n",
p->v_holdtime, p->v_keepalive);
- if (CHECK_FLAG(p->config, PEER_CONFIG_TIMER)) {
+ if (PEER_OR_GROUP_TIMER_SET(p)) {
vty_out(vty, " Configured hold time is %d",
p->holdtime);
vty_out(vty, ", keepalive interval is %d seconds\n",
p->keepalive);
+ } else if ((bgp->default_holdtime != BGP_DEFAULT_HOLDTIME)
+ || (bgp->default_keepalive !=
+ BGP_DEFAULT_KEEPALIVE)) {
+ vty_out(vty, " Configured hold time is %d",
+ bgp->default_holdtime);
+ vty_out(vty, ", keepalive interval is %d seconds\n",
+ bgp->default_keepalive);
}
}
/* Capability. */
diff --git a/bgpd/bgpd.c b/bgpd/bgpd.c
index a39ff3b271..345ceab9ed 100644
--- a/bgpd/bgpd.c
+++ b/bgpd/bgpd.c
@@ -2301,6 +2301,7 @@ struct peer_group *peer_group_get(struct bgp *bgp, const char *name)
group->conf->gtsm_hops = 0;
group->conf->v_routeadv = BGP_DEFAULT_EBGP_ROUTEADV;
UNSET_FLAG(group->conf->config, PEER_CONFIG_TIMER);
+ UNSET_FLAG(group->conf->config, PEER_GROUP_CONFIG_TIMER);
UNSET_FLAG(group->conf->config, PEER_CONFIG_CONNECT);
group->conf->keepalive = 0;
group->conf->holdtime = 0;
@@ -4582,20 +4583,30 @@ int peer_timers_set(struct peer *peer, u_int32_t keepalive, u_int32_t holdtime)
return BGP_ERR_INVALID_VALUE;
/* Set value to the configuration. */
- SET_FLAG(peer->config, PEER_CONFIG_TIMER);
peer->holdtime = holdtime;
peer->keepalive = (keepalive < holdtime / 3 ? keepalive : holdtime / 3);
- if (!CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP))
- return 0;
-
- /* peer-group member updates. */
- group = peer->group;
- for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
+ /* First work on real peers with timers */
+ if (!CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) {
SET_FLAG(peer->config, PEER_CONFIG_TIMER);
- peer->holdtime = group->conf->holdtime;
- peer->keepalive = group->conf->keepalive;
+ UNSET_FLAG(peer->config, PEER_GROUP_CONFIG_TIMER);
+ } else {
+ /* Now work on the peer-group timers */
+ SET_FLAG(peer->config, PEER_GROUP_CONFIG_TIMER);
+
+ /* peer-group member updates. */
+ group = peer->group;
+ for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
+ /* Skip peers that have their own timers */
+ if (CHECK_FLAG(peer->config, PEER_CONFIG_TIMER))
+ continue;
+
+ SET_FLAG(peer->config, PEER_GROUP_CONFIG_TIMER);
+ peer->holdtime = group->conf->holdtime;
+ peer->keepalive = group->conf->keepalive;
+ }
}
+
return 0;
}
@@ -4604,20 +4615,32 @@ int peer_timers_unset(struct peer *peer)
struct peer_group *group;
struct listnode *node, *nnode;
- /* Clear configuration. */
- UNSET_FLAG(peer->config, PEER_CONFIG_TIMER);
- peer->keepalive = 0;
- peer->holdtime = 0;
-
- if (!CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP))
- return 0;
-
- /* peer-group member updates. */
- group = peer->group;
- for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
+ /* First work on real peers vs the peer-group */
+ if (!CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) {
UNSET_FLAG(peer->config, PEER_CONFIG_TIMER);
- peer->holdtime = 0;
peer->keepalive = 0;
+ peer->holdtime = 0;
+
+ if (peer->group && peer->group->conf->holdtime) {
+ SET_FLAG(peer->config, PEER_GROUP_CONFIG_TIMER);
+ peer->keepalive = peer->group->conf->keepalive;
+ peer->holdtime = peer->group->conf->holdtime;
+ }
+ } else {
+ /* peer-group member updates. */
+ group = peer->group;
+ for (ALL_LIST_ELEMENTS(group->peer, node, nnode, peer)) {
+ if (!CHECK_FLAG(peer->config, PEER_CONFIG_TIMER)) {
+ UNSET_FLAG(peer->config,
+ PEER_GROUP_CONFIG_TIMER);
+ peer->holdtime = 0;
+ peer->keepalive = 0;
+ }
+ }
+
+ UNSET_FLAG(group->conf->config, PEER_GROUP_CONFIG_TIMER);
+ group->conf->holdtime = 0;
+ group->conf->keepalive = 0;
}
return 0;
@@ -6535,7 +6558,7 @@ static void bgp_config_write_peer_global(struct vty *vty, struct bgp *bgp,
}
/* timers */
- if (CHECK_FLAG(peer->config, PEER_CONFIG_TIMER)
+ if ((PEER_OR_GROUP_TIMER_SET(peer))
&& ((!peer_group_active(peer)
&& (peer->keepalive != BGP_DEFAULT_KEEPALIVE
|| peer->holdtime != BGP_DEFAULT_HOLDTIME))
diff --git a/bgpd/bgpd.h b/bgpd/bgpd.h
index 9c38a65b40..69ffe086d2 100644
--- a/bgpd/bgpd.h
+++ b/bgpd/bgpd.h
@@ -771,6 +771,11 @@ struct peer {
#define PEER_CONFIG_TIMER (1 << 0) /* keepalive & holdtime */
#define PEER_CONFIG_CONNECT (1 << 1) /* connect */
#define PEER_CONFIG_ROUTEADV (1 << 2) /* route advertise */
+#define PEER_GROUP_CONFIG_TIMER (1 << 3) /* timers from peer-group */
+
+#define PEER_OR_GROUP_TIMER_SET(peer) \
+ (CHECK_FLAG(peer->config, PEER_CONFIG_TIMER) \
+ || CHECK_FLAG(peer->config, PEER_GROUP_CONFIG_TIMER))
u_int32_t holdtime;
u_int32_t keepalive;
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 f349979d18..cfbe7a459a 100644
--- a/ospfd/ospf_vty.c
+++ b/ospfd/ospf_vty.c
@@ -139,48 +139,51 @@ static struct ospf *ospf_cmd_lookup_ospf(struct vty *vty,
u_short *instance)
{
struct ospf *ospf = NULL;
- int idx_vrf = 0;
+ int idx_vrf = 0, idx_inst = 0;
const char *vrf_name = NULL;
+ *instance = 0;
+ if (argv_find(argv, argc, "(1-65535)", &idx_inst))
+ *instance = strtoul(argv[idx_inst]->arg, NULL, 10);
+
if (argv_find(argv, argc, "vrf", &idx_vrf)) {
vrf_name = argv[idx_vrf + 1]->arg;
if (enable) {
- if (argc > 4)
- *instance = strtoul(argv[2]->arg, NULL, 10);
/* Allocate VRF aware instance */
ospf = ospf_get(*instance, vrf_name);
} else {
- if (argc > 5)
- *instance = strtoul(argv[3]->arg, NULL, 10);
ospf = ospf_lookup_by_inst_name(*instance, vrf_name);
}
} else {
if (enable) {
- ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
- if (!ospf)
- vty_out(vty,
- "There isn't active ospf instance\n");
- if (argc > 2)
- *instance = strtoul(argv[2]->arg, NULL, 10);
+ ospf = ospf_get(*instance, NULL);
} else {
- if (argc > 3)
- *instance = strtoul(argv[3]->arg, NULL, 10);
ospf = ospf_lookup_instance(*instance);
}
}
+
return ospf;
}
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
@@ -241,6 +244,7 @@ DEFUN (no_router_ospf,
else
return CMD_WARNING;
}
+ zlog_debug("%s: no router ospf ", __PRETTY_FUNCTION__);
ospf_finish(ospf);
return CMD_SUCCESS;
@@ -2909,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 {
@@ -2932,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",
@@ -2945,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,
@@ -2963,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 {
@@ -2979,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",
@@ -2994,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,
@@ -3023,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,
@@ -3042,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) {
@@ -3071,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",
@@ -3113,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,
@@ -3123,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,
@@ -3134,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,
@@ -3148,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,
@@ -3163,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",
@@ -3172,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");
@@ -3219,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;
}
@@ -3264,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);
@@ -3273,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,
@@ -3595,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) {
@@ -3615,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)) {
@@ -3629,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");
@@ -3651,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");
@@ -3721,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) {
@@ -3739,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) {
@@ -3767,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);
}
}
}
@@ -3798,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;
}
@@ -3829,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;
@@ -3883,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);
@@ -3896,9 +4006,20 @@ DEFUN (show_ip_ospf_instance_interface,
return CMD_SUCCESS;
if (uj)
- argc--;
+ json = json_object_new_object();
- return show_ip_ospf_interface_common(vty, ospf, argc, argv, 5, uj);
+ 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 ret;
}
DEFUN (show_ip_ospf_interface_traffic,
@@ -3921,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)
@@ -3941,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;
@@ -3978,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)
@@ -4113,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");
@@ -4147,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;
}
@@ -4195,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);
@@ -4204,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();
+
+ 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 show_ip_ospf_neighbor_common(vty, ospf, uj);
+ 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)) {
@@ -4278,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 ",
@@ -4294,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");
@@ -4323,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;
}
@@ -4372,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);
@@ -4380,14 +4606,24 @@ DEFUN (show_ip_ospf_instance_neighbor_all,
if (!ospf->oi_running)
return CMD_SUCCESS;
+ if (uj)
+ json = json_object_new_object();
+
+ 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 show_ip_ospf_neighbor_all_common(vty, ospf, uj);
+ 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;
@@ -4404,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);
@@ -4462,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;
@@ -4499,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,
@@ -4582,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;
@@ -4798,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;
@@ -4818,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) {
@@ -4833,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);
}
}
@@ -4866,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;
@@ -4897,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;
@@ -4930,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);
}
}
}
@@ -4939,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");
@@ -4968,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;
}
@@ -5014,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);
@@ -5023,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)
@@ -5045,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;
@@ -5058,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;
@@ -5068,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");
}
@@ -5105,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;
}
@@ -5152,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);
@@ -5161,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,
@@ -5207,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);
}
}
}
@@ -5848,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;
@@ -5857,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));
@@ -5943,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)
@@ -5954,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;
@@ -5997,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);
@@ -6007,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;
@@ -6064,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;
@@ -6080,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));
@@ -6143,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);
@@ -6154,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 */
@@ -6181,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(
@@ -8645,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");
@@ -8685,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;
@@ -8736,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");
@@ -8782,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;
}
@@ -8806,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;
}
@@ -8832,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);
}
@@ -8899,7 +9277,7 @@ DEFUN (show_ip_ospf_vrfs,
json_object_free(json);
} else {
if (count)
- vty_out(vty, "\nTotal number of OSPF VRFs (including default): %d\n",
+ vty_out(vty, "\nTotal number of OSPF VRFs: %d\n",
count);
}