#include "ospfd/ospf_dump.h"
#include "ospfd/ospf_bfd.h"
-static const char *ospf_network_type_str[] = {
+static const char *const ospf_network_type_str[] = {
"Null", "POINTOPOINT", "BROADCAST", "NBMA", "POINTOMULTIPOINT",
"VIRTUALLINK", "LOOPBACK"};
"Write multiplier\n"
"Maximum number of interface serviced per write\n")
-const char *ospf_abr_type_descr_str[] = {"Unknown", "Standard (RFC2328)",
- "Alternative IBM", "Alternative Cisco",
- "Alternative Shortcut"};
+static const char *const ospf_abr_type_descr_str[] = {
+ "Unknown", "Standard (RFC2328)", "Alternative IBM",
+ "Alternative Cisco", "Alternative Shortcut"
+};
-const char *ospf_shortcut_mode_descr_str[] = {"Default", "Enabled", "Disabled"};
+static const char *const ospf_shortcut_mode_descr_str[] = {
+ "Default", "Enabled", "Disabled"
+};
static void show_ip_ospf_area(struct vty *vty, struct ospf_area *area,
json_object *json_areas, bool use_json)
else
vty_out(vty, " This interface is UNNUMBERED,");
} else {
+ struct in_addr dest;
+ const char *dstr;
+
/* Show OSPF interface information. */
if (use_json) {
json_object_string_add(
inet_ntoa(oi->address->u.prefix4),
oi->address->prefixlen);
- if (oi->connected->destination
- || oi->type == OSPF_IFTYPE_VIRTUALLINK) {
- struct in_addr *dest;
- const char *dstr;
-
- if (CONNECTED_PEER(oi->connected)
- || oi->type == OSPF_IFTYPE_VIRTUALLINK)
- dstr = "Peer";
- else
- dstr = "Broadcast";
+ /* For Vlinks, showing the peer address is
+ * probably more informative than the local
+ * interface that is being used */
+ if (oi->type == OSPF_IFTYPE_VIRTUALLINK) {
+ dstr = "Peer";
+ dest = oi->vl_data->peer_addr;
+ } else if (CONNECTED_PEER(oi->connected)
+ && oi->connected->destination) {
+ dstr = "Peer";
+ dest = oi->connected->destination->u.prefix4;
+ } else {
+ dstr = "Broadcast";
+ dest.s_addr = ipv4_broadcast_addr(
+ oi->connected->address->u.prefix4.s_addr,
+ oi->connected->address->prefixlen);
+ }
- /* For Vlinks, showing the peer address is
- * probably more
- * * * * * informative than the local
- * interface that is being used
- * * * * */
+ if (use_json) {
+ json_object_string_add(
+ json_interface_sub,
+ "ospfIfType", dstr);
if (oi->type == OSPF_IFTYPE_VIRTUALLINK)
- dest = &oi->vl_data->peer_addr;
+ json_object_string_add(
+ json_interface_sub,
+ "vlinkPeer",
+ inet_ntoa(dest));
else
- dest = &oi->connected->destination->u
- .prefix4;
-
- if (use_json) {
json_object_string_add(
json_interface_sub,
- "ospfIfType", dstr);
- if (oi->type == OSPF_IFTYPE_VIRTUALLINK)
- json_object_string_add(
- json_interface_sub,
- "vlinkPeer",
- inet_ntoa(*dest));
- else
- json_object_string_add(
- json_interface_sub,
- "localIfUsed",
- inet_ntoa(*dest));
- } else
- vty_out(vty, " %s %s,", dstr,
- inet_ntoa(*dest));
- }
+ "localIfUsed",
+ inet_ntoa(dest));
+ } else
+ vty_out(vty, " %s %s,", dstr,
+ inet_ntoa(dest));
}
if (use_json) {
json_object_string_add(json_interface_sub, "area",
static void show_ip_ospf_neighbor_detail_sub(struct vty *vty,
struct ospf_interface *oi,
struct ospf_neighbor *nbr,
+ struct ospf_neighbor *prev_nbr,
json_object *json, bool use_json)
{
char timebuf[OSPF_TIME_DUMP_SIZE];
- json_object *json_sub = NULL;
+ json_object *json_neigh = NULL, *json_neigh_array = NULL;
+ char neigh_str[INET_ADDRSTRLEN] = {0};
- if (use_json)
- json_sub = json_object_new_object();
- else {
+ if (use_json) {
+ if (prev_nbr &&
+ !IPV4_ADDR_SAME(&prev_nbr->src, &nbr->src)) {
+ json_neigh_array = NULL;
+ }
+
+ if (nbr->state == NSM_Attempt && nbr->router_id.s_addr == 0)
+ strlcpy(neigh_str, "noNbrId", sizeof(neigh_str));
+ else
+ strlcpy(neigh_str, inet_ntoa(nbr->router_id),
+ sizeof(neigh_str));
+
+ 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_neigh = json_object_new_object();
+
+ } else {
/* Show neighbor ID. */
if (nbr->state == NSM_Attempt && nbr->router_id.s_addr == 0)
vty_out(vty, " Neighbor %s,", "-");
/* Show interface address. */
if (use_json)
- json_object_string_add(json_sub, "ifaceAddress",
+ json_object_string_add(json_neigh, "ifaceAddress",
inet_ntoa(nbr->address.u.prefix4));
else
vty_out(vty, " interface address %s\n",
/* Show Area ID. */
if (use_json) {
- json_object_string_add(json_sub, "areaId",
+ json_object_string_add(json_neigh, "areaId",
ospf_area_desc_string(oi->area));
- json_object_string_add(json_sub, "ifaceName", oi->ifp->name);
+ json_object_string_add(json_neigh, "ifaceName", oi->ifp->name);
} else
vty_out(vty, " In the area %s via interface %s\n",
ospf_area_desc_string(oi->area), oi->ifp->name);
/* Show neighbor priority and state. */
if (use_json) {
- json_object_int_add(json_sub, "nbrPriority", nbr->priority);
+ json_object_int_add(json_neigh, "nbrPriority", nbr->priority);
json_object_string_add(
- json_sub, "nbrState",
+ json_neigh, "nbrState",
lookup_msg(ospf_nsm_state_msg, nbr->state, NULL));
} else
vty_out(vty, " Neighbor priority is %d, State is %s,",
/* Show state changes. */
if (use_json)
- json_object_int_add(json_sub, "stateChangeCounter",
+ json_object_int_add(json_neigh, "stateChangeCounter",
nbr->state_change);
else
vty_out(vty, " %d state changes\n", nbr->state_change);
time_store =
monotime_since(&nbr->ts_last_progress, &res) / 1000LL;
if (use_json) {
- json_object_int_add(json_sub, "lastPrgrsvChangeMsec",
+ json_object_int_add(json_neigh, "lastPrgrsvChangeMsec",
time_store);
} else {
vty_out(vty,
time_store =
monotime_since(&nbr->ts_last_regress, &res) / 1000LL;
if (use_json) {
- json_object_int_add(json_sub,
+ json_object_int_add(json_neigh,
"lastRegressiveChangeMsec",
time_store);
if (nbr->last_regress_str)
json_object_string_add(
- json_sub, "lastRegressiveChangeReason",
+ json_neigh,
+ "lastRegressiveChangeReason",
nbr->last_regress_str);
} else {
vty_out(vty,
/* Show Designated Rotuer ID. */
if (use_json)
- json_object_string_add(json_sub, "routerDesignatedId",
+ json_object_string_add(json_neigh, "routerDesignatedId",
inet_ntoa(nbr->d_router));
else
vty_out(vty, " DR is %s,", inet_ntoa(nbr->d_router));
/* Show Backup Designated Rotuer ID. */
if (use_json)
- json_object_string_add(json_sub, "routerDesignatedBackupId",
+ json_object_string_add(json_neigh, "routerDesignatedBackupId",
inet_ntoa(nbr->bd_router));
else
vty_out(vty, " BDR is %s\n", inet_ntoa(nbr->bd_router));
/* Show options. */
if (use_json) {
- json_object_int_add(json_sub, "optionsCounter", nbr->options);
- json_object_string_add(json_sub, "optionsList",
+ json_object_int_add(json_neigh, "optionsCounter", nbr->options);
+ json_object_string_add(json_neigh, "optionsList",
ospf_options_dump(nbr->options));
} else
vty_out(vty, " Options %d %s\n", nbr->options,
time_store = monotime_until(&nbr->t_inactivity->u.sands,
NULL)
/ 1000LL;
- json_object_int_add(json_sub,
+ json_object_int_add(json_neigh,
"routerDeadIntervalTimerDueMsec",
time_store);
} else
json_object_int_add(
- json_sub, "routerDeadIntervalTimerDueMsec", -1);
+ json_neigh,
+ "routerDeadIntervalTimerDueMsec", -1);
} else
vty_out(vty, " Dead timer due in %s\n",
ospf_timer_dump(nbr->t_inactivity, timebuf,
/* Show Database Summary list. */
if (use_json)
- json_object_int_add(json_sub, "databaseSummaryListCounter",
+ json_object_int_add(json_neigh, "databaseSummaryListCounter",
ospf_db_summary_count(nbr));
else
vty_out(vty, " Database Summary List %d\n",
/* Show Link State Request list. */
if (use_json)
- json_object_int_add(json_sub, "linkStateRequestListCounter",
+ json_object_int_add(json_neigh, "linkStateRequestListCounter",
ospf_ls_request_count(nbr));
else
vty_out(vty, " Link State Request List %ld\n",
/* Show Link State Retransmission list. */
if (use_json)
- json_object_int_add(json_sub,
+ json_object_int_add(json_neigh,
"linkStateRetransmissionListCounter",
ospf_ls_retransmit_count(nbr));
else
/* Show inactivity timer thread. */
if (use_json) {
if (nbr->t_inactivity != NULL)
- json_object_string_add(json_sub,
+ json_object_string_add(json_neigh,
"threadInactivityTimer", "on");
} else
vty_out(vty, " Thread Inactivity Timer %s\n",
if (use_json) {
if (nbr->t_db_desc != NULL)
json_object_string_add(
- json_sub,
+ json_neigh,
"threadDatabaseDescriptionRetransmission",
"on");
} else
if (use_json) {
if (nbr->t_ls_req != NULL)
json_object_string_add(
- json_sub,
+ json_neigh,
"threadLinkStateRequestRetransmission", "on");
} else
vty_out(vty,
if (use_json) {
if (nbr->t_ls_upd != NULL)
json_object_string_add(
- json_sub, "threadLinkStateUpdateRetransmission",
+ json_neigh,
+ "threadLinkStateUpdateRetransmission",
"on");
} else
vty_out(vty,
" Thread Link State Update Retransmission %s\n\n",
nbr->t_ls_upd != NULL ? "on" : "off");
- if (use_json) {
- if (nbr->state == NSM_Attempt && nbr->router_id.s_addr == 0)
- json_object_object_add(json, "noNbrId", json_sub);
- else
- json_object_object_add(json, inet_ntoa(nbr->router_id),
- json_sub);
- }
+ ospf_bfd_show_info(vty, nbr->bfd_info, json_neigh, use_json, 0);
+
+ if (use_json)
+ json_object_array_add(json_neigh_array, json_neigh);
- ospf_bfd_show_info(vty, nbr->bfd_info, json, use_json, 0);
}
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, json,
- use_json);
+ show_ip_ospf_neighbor_detail_sub(vty, oi, nbr, NULL,
+ json, use_json);
}
}
struct ospf_interface *oi;
struct listnode *node;
json_object *json_vrf = NULL;
+ json_object *json_nbr_sub = NULL;
if (use_json) {
if (use_vrf)
json_vrf = json_object_new_object();
else
json_vrf = json;
+
+ json_nbr_sub = json_object_new_object();
}
+
if (ospf->instance) {
if (use_json)
- json_object_int_add(json_vrf, "ospfInstance",
+ json_object_int_add(json, "ospfInstance",
ospf->instance);
else
vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) {
struct route_node *rn;
- struct ospf_neighbor *nbr;
+ struct ospf_neighbor *nbr, *prev_nbr = NULL;
for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) {
if ((nbr = rn->info)) {
if (nbr != oi->nbr_self) {
if (nbr->state != NSM_Down) {
show_ip_ospf_neighbor_detail_sub(
- vty, oi, nbr, json_vrf,
- use_json);
+ vty, oi, nbr, prev_nbr,
+ json_nbr_sub, use_json);
}
}
+ prev_nbr = nbr;
}
}
}
if (use_json) {
+ json_object_object_add(json_vrf, "neighbors",
+ json_nbr_sub);
if (use_vrf) {
if (ospf->vrf_id == VRF_DEFAULT)
json_object_object_add(json, "default",
for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) {
struct route_node *rn;
- struct ospf_neighbor *nbr;
+ struct ospf_neighbor *nbr, *prev_nbr = NULL;
struct ospf_nbr_nbma *nbr_nbma;
- for (rn = route_top(oi->nbrs); rn; rn = route_next(rn))
- if ((nbr = rn->info))
+ for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) {
+ if ((nbr = rn->info)) {
if (nbr != oi->nbr_self)
if (nbr->state != NSM_Down)
show_ip_ospf_neighbor_detail_sub(
vty, oi, rn->info,
+ prev_nbr,
json_vrf, use_json);
+ prev_nbr = nbr;
+ }
+ }
if (oi->type == OSPF_IFTYPE_NBMA) {
struct listnode *nd;
if (nbr->state != NSM_Down)
show_ip_ospf_neighbor_detail_sub(
vty, oi, nbr,
+ NULL,
json, use_json);
}
}
if (!ospf->oi_running)
continue;
ospf_output = true;
- ret = show_ip_ospf_neighbor_int_detail_common(vty, ospf, 0,
+ ret = show_ip_ospf_neighbor_int_detail_common(vty, ospf, 4,
argv, uj);
}
return 0;
}
-static const char *show_database_desc[] = {
+static const char *const show_database_desc[] = {
"unknown",
"Router Link States",
"Net Link States",
"AS-external Opaque-LSA",
};
-static const char *show_database_header[] = {
+static const char *const show_database_header[] = {
"",
"Link ID ADV Router Age Seq# CkSum Link count",
"Link ID ADV Router Age Seq# CkSum",
vty_out(vty, " Length: %d\n\n", ntohs(lsa->data->length));
}
-const char *link_type_desc[] = {
+static const char *const link_type_desc[] = {
"(null)",
"another Router (point-to-point)",
"a Transit Network",
"a Virtual Link",
};
-const char *link_id_desc[] = {
+static const char *const link_id_desc[] = {
"(null)", "Neighboring Router ID", "Designated Router address",
"Net", "Neighboring Router ID",
};
-const char *link_data_desc[] = {
+static const char *const link_data_desc[] = {
"(null)", "Router Interface address", "Router Interface address",
"Network Mask", "Router Interface address",
};
return 0;
}
-int (*show_function[])(struct vty *, struct ospf_lsa *) = {
+int (*const show_function[])(struct vty *, struct ospf_lsa *) = {
NULL,
show_router_lsa_detail,
show_network_lsa_detail,
"Pointer to route-map entries\n")
{
VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
- struct prefix_ipv4 p;
- struct ospf_external *ext;
struct ospf_redist *red;
- p.family = AF_INET;
- p.prefix.s_addr = 0;
- p.prefixlen = 0;
-
- ospf_external_lsa_flush(ospf, DEFAULT_ROUTE, &p, 0);
-
- ext = ospf_external_lookup(ospf, DEFAULT_ROUTE, 0);
- if (ext && EXTERNAL_INFO(ext)) {
- ospf_external_info_delete(ospf, DEFAULT_ROUTE, 0, p);
- ospf_external_del(ospf, DEFAULT_ROUTE, 0);
- }
-
red = ospf_redist_lookup(ospf, DEFAULT_ROUTE, 0);
if (!red)
return CMD_SUCCESS;
ospf_routemap_unset(red);
ospf_redist_del(ospf, DEFAULT_ROUTE, 0);
- return ospf_redistribute_default_unset(ospf);
+ return ospf_redistribute_default_set(ospf, DEFAULT_ORIGINATE_NONE,
+ 0, 0);
}
DEFUN (ospf_default_metric,
struct ospf *ospf = NULL;
struct listnode *node = NULL;
int count = 0;
- static char header[] = "Name Id RouterId ";
+ static const char header[] = "Name Id RouterId ";
if (uj) {
json = json_object_new_object();
return CMD_SUCCESS;
}
-const char *ospf_abr_type_str[] = {"unknown", "standard", "ibm", "cisco",
- "shortcut"};
+static const char *const ospf_abr_type_str[] = {
+ "unknown", "standard", "ibm", "cisco", "shortcut"
+};
-const char *ospf_shortcut_mode_str[] = {"default", "enable", "disable"};
+static const char *const ospf_shortcut_mode_str[] = {
+ "default", "enable", "disable"
+};
-const char *ospf_int_type_str[] = {"unknown", /* should never be used. */
- "point-to-point", "broadcast",
- "non-broadcast", "point-to-multipoint",
- "virtual-link", /* should never be used. */
- "loopback"};
+static const char *const ospf_int_type_str[] = {
+ "unknown", /* should never be used. */
+ "point-to-point",
+ "broadcast",
+ "non-broadcast",
+ "point-to-multipoint",
+ "virtual-link", /* should never be used. */
+ "loopback"
+};
static int config_write_interface_one(struct vty *vty, struct vrf *vrf)
{
DEFUN (clear_ip_ospf_interface,
clear_ip_ospf_interface_cmd,
- "clear ip ospf [vrf <NAME>] interface [IFNAME]",
+ "clear ip ospf [vrf NAME] interface [IFNAME]",
CLEAR_STR
IP_STR
"OSPF information\n"