summaryrefslogtreecommitdiff
path: root/ospfd
diff options
context:
space:
mode:
Diffstat (limited to 'ospfd')
-rw-r--r--ospfd/ospf_asbr.c4
-rw-r--r--ospfd/ospf_ase.c13
-rw-r--r--ospfd/ospf_dump.c21
-rw-r--r--ospfd/ospf_ext.c4
-rw-r--r--ospfd/ospf_interface.c28
-rw-r--r--ospfd/ospf_ldp_sync.c36
-rw-r--r--ospfd/ospf_packet.c2
-rw-r--r--ospfd/ospf_sr.c337
-rw-r--r--ospfd/ospf_sr.h6
-rw-r--r--ospfd/ospf_te.c8
-rw-r--r--ospfd/ospf_vty.c518
-rw-r--r--ospfd/ospfd.c4
12 files changed, 440 insertions, 541 deletions
diff --git a/ospfd/ospf_asbr.c b/ospfd/ospf_asbr.c
index 982fad63ec..000c62e305 100644
--- a/ospfd/ospf_asbr.c
+++ b/ospfd/ospf_asbr.c
@@ -420,7 +420,7 @@ static void ospf_aggr_handle_external_info(void *data)
{
struct external_info *ei = (struct external_info *)data;
struct ospf_external_aggr_rt *aggr = NULL;
- struct ospf *ospf = NULL;
+ struct ospf *ospf = ei->ospf;
struct ospf_lsa *lsa = NULL;
ei->aggr_route = NULL;
@@ -431,8 +431,6 @@ static void ospf_aggr_handle_external_info(void *data)
zlog_debug("%s: Handle extrenal route(%pI4/%d)", __func__,
&ei->p.prefix, ei->p.prefixlen);
- ospf = ospf_lookup_instance(ei->instance);
-
assert(ospf);
if (!ospf_redistribute_check(ospf, ei, NULL))
diff --git a/ospfd/ospf_ase.c b/ospfd/ospf_ase.c
index aaacebca14..e9fb891d7e 100644
--- a/ospfd/ospf_ase.c
+++ b/ospfd/ospf_ase.c
@@ -280,6 +280,19 @@ int ospf_ase_calculate_route(struct ospf *ospf, struct ospf_lsa *lsa)
return 0;
}
+ /* Type-5 shouldn't be calculated if it is originated from NSSA ASBR.
+ * As per RFC 3101, expectation is to receive type-7 lsas from
+ * NSSA ASBR. Ignore calculation, if the current LSA is type-5 and
+ * originated ASBR's area is NSSA.
+ */
+ if ((lsa->data->type == OSPF_AS_EXTERNAL_LSA)
+ && (asbr_route->u.std.external_routing != OSPF_AREA_DEFAULT)) {
+ if (IS_DEBUG_OSPF(lsa, LSA))
+ zlog_debug(
+ "Route[External]: Ignore, If type-5 LSA from NSSA area.");
+ return 0;
+ }
+
/* Else, this LSA describes an AS external path to destination
N. Examine the forwarding address specified in the AS-
external-LSA. This indicates the IP address to which
diff --git a/ospfd/ospf_dump.c b/ospfd/ospf_dump.c
index fab5b7d3cc..2f7556f7ff 100644
--- a/ospfd/ospf_dump.c
+++ b/ospfd/ospf_dump.c
@@ -1645,11 +1645,15 @@ DEFUN (no_debug_ospf,
DEBUG_OFF(nsm, NSM_EVENTS);
DEBUG_OFF(nsm, NSM_STATUS);
DEBUG_OFF(nsm, NSM_TIMERS);
+ DEBUG_OFF(event, EVENT);
DEBUG_OFF(zebra, ZEBRA);
DEBUG_OFF(zebra, ZEBRA_INTERFACE);
DEBUG_OFF(zebra, ZEBRA_REDISTRIBUTE);
DEBUG_OFF(defaultinfo, DEFAULTINFO);
DEBUG_OFF(ldp_sync, LDP_SYNC);
+ DEBUG_OFF(te, TE);
+ DEBUG_OFF(sr, SR);
+ DEBUG_OFF(ti_lfa, TI_LFA);
/* BFD debugging is two parts: OSPF and library. */
DEBUG_OFF(bfd, BFD_LIB);
@@ -1682,6 +1686,9 @@ DEFUN (no_debug_ospf,
TERM_DEBUG_OFF(zebra, ZEBRA_REDISTRIBUTE);
TERM_DEBUG_OFF(defaultinfo, DEFAULTINFO);
TERM_DEBUG_OFF(ldp_sync, LDP_SYNC);
+ TERM_DEBUG_OFF(te, TE);
+ TERM_DEBUG_OFF(sr, SR);
+ TERM_DEBUG_OFF(ti_lfa, TI_LFA);
TERM_DEBUG_OFF(bfd, BFD_LIB);
return CMD_SUCCESS;
@@ -1792,6 +1799,18 @@ static int show_debugging_ospf_common(struct vty *vty)
if (IS_DEBUG_OSPF(gr, GR) == OSPF_DEBUG_GR)
vty_out(vty, " OSPF Graceful Restart debugging is on\n");
+ /* Show debug status for TE */
+ if (IS_DEBUG_OSPF(te, TE) == OSPF_DEBUG_TE)
+ vty_out(vty, " OSPF TE debugging is on\n");
+
+ /* Show debug status for SR */
+ if (IS_DEBUG_OSPF(sr, SR) == OSPF_DEBUG_SR)
+ vty_out(vty, " OSPF SR debugging is on\n");
+
+ /* Show debug status for TI-LFA */
+ if (IS_DEBUG_OSPF(ti_lfa, TI_LFA) == OSPF_DEBUG_TI_LFA)
+ vty_out(vty, " OSPF TI-LFA debugging is on\n");
+
if (IS_DEBUG_OSPF(bfd, BFD_LIB) == OSPF_DEBUG_BFD_LIB)
vty_out(vty,
" OSPF BFD integration library debugging is on\n");
@@ -1966,7 +1985,7 @@ static int config_write_debug(struct vty *vty)
}
/* debug ospf sr ti-lfa */
- if (IS_CONF_DEBUG_OSPF(sr, TI_LFA) == OSPF_DEBUG_TI_LFA) {
+ if (IS_CONF_DEBUG_OSPF(ti_lfa, TI_LFA) == OSPF_DEBUG_TI_LFA) {
vty_out(vty, "debug ospf%s ti-lfa\n", str);
write = 1;
}
diff --git a/ospfd/ospf_ext.c b/ospfd/ospf_ext.c
index ea1506ea27..0e5a7e29c0 100644
--- a/ospfd/ospf_ext.c
+++ b/ospfd/ospf_ext.c
@@ -256,10 +256,10 @@ static uint32_t get_ext_link_instance_value(void)
/* Lookup Extended Prefix/Links by ifp from OspfEXT struct iflist */
static struct ext_itf *lookup_ext_by_ifp(struct interface *ifp)
{
- struct listnode *node, *nnode;
+ struct listnode *node;
struct ext_itf *exti;
- for (ALL_LIST_ELEMENTS(OspfEXT.iflist, node, nnode, exti))
+ for (ALL_LIST_ELEMENTS_RO(OspfEXT.iflist, node, exti))
if (exti->ifp == ifp)
return exti;
diff --git a/ospfd/ospf_interface.c b/ospfd/ospf_interface.c
index 42d31414f5..299e753ccf 100644
--- a/ospfd/ospf_interface.c
+++ b/ospfd/ospf_interface.c
@@ -360,9 +360,8 @@ void ospf_if_free(struct ospf_interface *oi)
if (IS_DEBUG_OSPF_EVENT)
zlog_debug("%s: ospf interface %s vrf %s id %u deleted",
- __func__, oi->ifp->name,
- ospf_vrf_id_to_name(oi->ifp->vrf_id),
- oi->ifp->vrf_id);
+ __func__, oi->ifp->name, oi->ifp->vrf->name,
+ oi->ifp->vrf->vrf_id);
ospf_delete_from_if(oi->ifp, oi);
@@ -477,7 +476,7 @@ struct ospf_interface *ospf_if_lookup_recv_if(struct ospf *ospf,
if (oi->type == OSPF_IFTYPE_VIRTUALLINK)
continue;
- if (if_is_loopback_or_vrf(oi->ifp))
+ if (if_is_loopback(oi->ifp))
continue;
if (CHECK_FLAG(oi->connected->flags, ZEBRA_IFA_UNNUMBERED))
@@ -719,7 +718,7 @@ static int ospf_if_delete_hook(struct interface *ifp)
int ospf_if_is_enable(struct ospf_interface *oi)
{
- if (!(if_is_loopback_or_vrf(oi->ifp)))
+ if (!(if_is_loopback(oi->ifp)))
if (if_is_up(oi->ifp))
return 1;
@@ -1294,7 +1293,7 @@ uint8_t ospf_default_iftype(struct interface *ifp)
{
if (if_is_pointopoint(ifp))
return OSPF_IFTYPE_POINTOPOINT;
- else if (if_is_loopback_or_vrf(ifp))
+ else if (if_is_loopback(ifp))
return OSPF_IFTYPE_LOOPBACK;
else
return OSPF_IFTYPE_BROADCAST;
@@ -1331,10 +1330,9 @@ static int ospf_ifp_create(struct interface *ifp)
if (IS_DEBUG_OSPF(zebra, ZEBRA_INTERFACE))
zlog_debug(
"Zebra: interface add %s vrf %s[%u] index %d flags %llx metric %d mtu %d speed %u",
- ifp->name, ospf_vrf_id_to_name(ifp->vrf_id),
- ifp->vrf_id, ifp->ifindex,
- (unsigned long long)ifp->flags, ifp->metric, ifp->mtu,
- ifp->speed);
+ ifp->name, ifp->vrf->name, ifp->vrf->vrf_id,
+ ifp->ifindex, (unsigned long long)ifp->flags,
+ ifp->metric, ifp->mtu, ifp->speed);
assert(ifp->info);
@@ -1347,7 +1345,7 @@ static int ospf_ifp_create(struct interface *ifp)
IF_DEF_PARAMS(ifp)->type = ospf_default_iftype(ifp);
}
- ospf = ospf_lookup_by_vrf_id(ifp->vrf_id);
+ ospf = ifp->vrf->info;
if (!ospf)
return 0;
@@ -1431,13 +1429,13 @@ static int ospf_ifp_destroy(struct interface *ifp)
if (IS_DEBUG_OSPF(zebra, ZEBRA_INTERFACE))
zlog_debug(
"Zebra: interface delete %s vrf %s[%u] index %d flags %llx metric %d mtu %d",
- ifp->name, ospf_vrf_id_to_name(ifp->vrf_id),
- ifp->vrf_id, ifp->ifindex,
- (unsigned long long)ifp->flags, ifp->metric, ifp->mtu);
+ ifp->name, ifp->vrf->name, ifp->vrf->vrf_id,
+ ifp->ifindex, (unsigned long long)ifp->flags,
+ ifp->metric, ifp->mtu);
hook_call(ospf_if_delete, ifp);
- ospf = ospf_lookup_by_vrf_id(ifp->vrf_id);
+ ospf = ifp->vrf->info;
if (ospf) {
if (ospf_if_count_area_params(ifp) > 0)
ospf_interface_area_unset(ospf, ifp);
diff --git a/ospfd/ospf_ldp_sync.c b/ospfd/ospf_ldp_sync.c
index dbd45635b2..247ceb0a08 100644
--- a/ospfd/ospf_ldp_sync.c
+++ b/ospfd/ospf_ldp_sync.c
@@ -129,8 +129,9 @@ void ospf_ldp_sync_if_init(struct ospf_interface *oi)
* if LDP-IGP Sync is configured globally set state
* if ptop interface inform LDP LDP-SYNC is enabled
*/
- if (if_is_loopback(ifp) || (ifp->vrf_id != VRF_DEFAULT) ||
- !(CHECK_FLAG(oi->ospf->ldp_sync_cmd.flags, LDP_SYNC_FLAG_ENABLE)))
+ if (if_is_loopback(ifp) || (ifp->vrf->vrf_id != VRF_DEFAULT)
+ || !(CHECK_FLAG(oi->ospf->ldp_sync_cmd.flags,
+ LDP_SYNC_FLAG_ENABLE)))
return;
ols_debug("ldp_sync: init if %s",ifp->name);
@@ -856,7 +857,7 @@ DEFPY (mpls_ldp_sync,
return CMD_ERR_NOTHING_TODO;
}
- if (ifp->vrf_id != VRF_DEFAULT) {
+ if (ifp->vrf->vrf_id != VRF_DEFAULT) {
vty_out(vty, "ldp-sync only runs on DEFAULT VRF\n");
return CMD_ERR_NOTHING_TODO;
}
@@ -897,7 +898,7 @@ DEFPY (no_mpls_ldp_sync,
return CMD_ERR_NOTHING_TODO;
}
- if (ifp->vrf_id != VRF_DEFAULT) {
+ if (ifp->vrf->vrf_id != VRF_DEFAULT) {
vty_out(vty, "ldp-sync only runs on DEFAULT VRF\n");
return CMD_ERR_NOTHING_TODO;
}
@@ -940,7 +941,7 @@ DEFPY (mpls_ldp_sync_holddown,
return CMD_ERR_NOTHING_TODO;
}
- if (ifp->vrf_id != VRF_DEFAULT) {
+ if (ifp->vrf->vrf_id != VRF_DEFAULT) {
vty_out(vty, "ldp-sync only runs on DEFAULT VRF\n");
return CMD_ERR_NOTHING_TODO;
}
@@ -978,7 +979,7 @@ DEFPY (no_mpls_ldp_sync_holddown,
return CMD_ERR_NOTHING_TODO;
}
- if (ifp->vrf_id != VRF_DEFAULT) {
+ if (ifp->vrf->vrf_id != VRF_DEFAULT) {
vty_out(vty, "ldp-sync only runs on DEFAULT VRF\n");
return CMD_ERR_NOTHING_TODO;
}
@@ -1030,32 +1031,25 @@ DEFPY (show_ip_ospf_mpls_ldp_interface,
/* Display default ospf (instance 0) info */
ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
if (ospf == NULL || !ospf->oi_running) {
- if (uj) {
- vty_out(vty, "%s\n", json_object_to_json_string_ext(
- json, JSON_C_TO_STRING_PRETTY));
- json_object_free(json);
- } else
+ if (uj)
+ vty_json(vty, json);
+ else
vty_out(vty, "%% OSPF instance not found\n");
return CMD_SUCCESS;
}
if (!CHECK_FLAG(ospf->ldp_sync_cmd.flags, LDP_SYNC_FLAG_ENABLE)) {
- if (uj) {
- vty_out(vty, "%s\n", json_object_to_json_string_ext(
- json, JSON_C_TO_STRING_PRETTY));
- json_object_free(json);
- } else
+ if (uj)
+ vty_json(vty, json);
+ else
vty_out(vty, "LDP-sync is disabled\n");
return CMD_SUCCESS;
}
ret = show_ip_ospf_mpls_ldp_interface_common(vty, ospf, intf_name,
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);
- }
+ if (uj)
+ vty_json(vty, json);
return ret;
}
diff --git a/ospfd/ospf_packet.c b/ospfd/ospf_packet.c
index ede0ad39e6..e17e531098 100644
--- a/ospfd/ospf_packet.c
+++ b/ospfd/ospf_packet.c
@@ -3012,7 +3012,7 @@ static enum ospf_read_return_enum ospf_read_helper(struct ospf *ospf)
}
}
- if (ospf->vrf_id == VRF_DEFAULT && ospf->vrf_id != ifp->vrf_id) {
+ if (ospf->vrf_id == VRF_DEFAULT && ospf->vrf_id != ifp->vrf->vrf_id) {
/*
* We may have a situation where l3mdev_accept == 1
* let's just kindly drop the packet and move on.
diff --git a/ospfd/ospf_sr.c b/ospfd/ospf_sr.c
index 9a9e64cc23..181cc37f4f 100644
--- a/ospfd/ospf_sr.c
+++ b/ospfd/ospf_sr.c
@@ -279,17 +279,19 @@ static int sr_local_block_init(uint32_t lower_bound, uint32_t upper_bound)
*/
size = upper_bound - lower_bound + 1;
if (ospf_zebra_request_label_range(lower_bound, size)) {
- srlb->reserved = false;
+ zlog_err("SR: Error reserving SRLB [%u/%u] %u labels",
+ lower_bound, upper_bound, size);
return -1;
}
- osr_debug("SR (%s): Got new SRLB [%u/%u]", __func__, lower_bound,
- upper_bound);
+ osr_debug("SR: Got new SRLB [%u/%u], %u labels", lower_bound,
+ upper_bound, size);
/* Initialize the SRLB */
srlb->start = lower_bound;
srlb->end = upper_bound;
srlb->current = 0;
+
/* Compute the needed Used Mark number and allocate them */
srlb->max_block = size / SRLB_BLOCK_SIZE;
if ((size % SRLB_BLOCK_SIZE) != 0)
@@ -301,6 +303,31 @@ static int sr_local_block_init(uint32_t lower_bound, uint32_t upper_bound)
return 0;
}
+static int sr_global_block_init(uint32_t start, uint32_t size)
+{
+ struct sr_global_block *srgb = &OspfSR.srgb;
+
+ /* Check if already configured */
+ if (srgb->reserved)
+ return 0;
+
+ /* request chunk */
+ uint32_t end = start + size - 1;
+ if (ospf_zebra_request_label_range(start, size) < 0) {
+ zlog_err("SR: Error reserving SRGB [%u/%u], %u labels", start,
+ end, size);
+ return -1;
+ }
+
+ osr_debug("SR: Got new SRGB [%u/%u], %u labels", start, end, size);
+
+ /* success */
+ srgb->start = start;
+ srgb->size = size;
+ srgb->reserved = true;
+ return 0;
+}
+
/**
* Remove Segment Routing Local Block.
*
@@ -322,10 +349,31 @@ static void sr_local_block_delete(void)
/* Then reset SRLB structure */
if (srlb->used_mark != NULL)
XFREE(MTYPE_OSPF_SR_PARAMS, srlb->used_mark);
+
srlb->reserved = false;
}
/**
+ * Remove Segment Routing Global block
+ */
+static void sr_global_block_delete(void)
+{
+ struct sr_global_block *srgb = &OspfSR.srgb;
+
+ if (!srgb->reserved)
+ return;
+
+ osr_debug("SR (%s): Remove SRGB [%u/%u]", __func__, srgb->start,
+ srgb->start + srgb->size - 1);
+
+ ospf_zebra_release_label_range(srgb->start,
+ srgb->start + srgb->size - 1);
+
+ srgb->reserved = false;
+}
+
+
+/**
* Request a label from the Segment Routing Local Block.
*
* @return First available label on success or MPLS_INVALID_LABEL if the
@@ -337,9 +385,10 @@ mpls_label_t ospf_sr_local_block_request_label(void)
mpls_label_t label;
uint32_t index;
uint32_t pos;
+ uint32_t size = srlb->end - srlb->start + 1;
/* Check if we ran out of available labels */
- if (srlb->current >= srlb->end)
+ if (srlb->current >= size)
return MPLS_INVALID_LABEL;
/* Get first available label and mark it used */
@@ -351,7 +400,7 @@ mpls_label_t ospf_sr_local_block_request_label(void)
/* Jump to the next free position */
srlb->current++;
pos = srlb->current % SRLB_BLOCK_SIZE;
- while (srlb->current < srlb->end) {
+ while (srlb->current < size) {
if (pos == 0)
index++;
if (!((1ULL << pos) & srlb->used_mark[index]))
@@ -362,6 +411,10 @@ mpls_label_t ospf_sr_local_block_request_label(void)
}
}
+ if (srlb->current == size)
+ zlog_warn(
+ "SR: Warning, SRLB is depleted and next label request will fail");
+
return label;
}
@@ -469,16 +522,11 @@ static int ospf_sr_start(struct ospf *ospf)
* If the allocation fails, return an error to disable SR until a new
* SRLB and/or SRGB are successfully allocated.
*/
- sr_local_block_init(OspfSR.srlb.start, OspfSR.srlb.end);
- if (!OspfSR.srgb.reserved) {
- if (ospf_zebra_request_label_range(OspfSR.srgb.start,
- OspfSR.srgb.size)
- < 0) {
- OspfSR.srgb.reserved = false;
- return -1;
- } else
- OspfSR.srgb.reserved = true;
- }
+ if (sr_local_block_init(OspfSR.srlb.start, OspfSR.srlb.end) < 0)
+ return -1;
+
+ if (sr_global_block_init(OspfSR.srgb.start, OspfSR.srgb.size) < 0)
+ return -1;
/* SR is UP and ready to flood LSA */
OspfSR.status = SR_UP;
@@ -534,13 +582,10 @@ static void ospf_sr_stop(void)
/* Disable any re-attempt to connect to Label Manager */
THREAD_OFF(OspfSR.t_start_lm);
- /* Release SRGB & SRLB if active. */
- if (OspfSR.srgb.reserved) {
- ospf_zebra_release_label_range(
- OspfSR.srgb.start,
- OspfSR.srgb.start + OspfSR.srgb.size - 1);
- OspfSR.srgb.reserved = false;
- }
+ /* Release SRGB if active */
+ sr_global_block_delete();
+
+ /* Release SRLB if active */
sr_local_block_delete();
/*
@@ -581,7 +626,7 @@ int ospf_sr_init(void)
OspfSR.srgb.reserved = false;
OspfSR.srlb.start = DEFAULT_SRLB_LABEL;
- OspfSR.srlb.end = DEFAULT_SRLB_LABEL + DEFAULT_SRLB_SIZE - 1;
+ OspfSR.srlb.end = DEFAULT_SRLB_END;
OspfSR.srlb.reserved = false;
OspfSR.msd = 0;
@@ -1200,7 +1245,9 @@ static void update_ext_prefix_sid(struct sr_node *srn, struct sr_prefix *srp)
/* Search for existing Segment Prefix */
for (ALL_LIST_ELEMENTS_RO(srn->ext_prefix, node, pref))
- if (pref->instance == srp->instance) {
+ if (pref->instance == srp->instance
+ && prefix_same((struct prefix *)&srp->prefv4,
+ &pref->prefv4)) {
found = true;
break;
}
@@ -1231,9 +1278,6 @@ static void update_ext_prefix_sid(struct sr_node *srn, struct sr_prefix *srp)
/* Replace Segment Prefix */
listnode_delete(srn->ext_prefix, pref);
XFREE(MTYPE_OSPF_SR_PARAMS, pref);
- srp->srn = srn;
- IPV4_ADDR_COPY(&srp->adv_router,
- &srn->adv_router);
listnode_add(srn->ext_prefix, srp);
ospf_zebra_update_prefix_sid(srp);
} else {
@@ -2099,6 +2143,20 @@ static int ospf_sr_enabled(struct vty *vty)
return 0;
}
+/* tell if two ranges [r1_lower, r1_upper] and [r2_lower,r2_upper] overlap */
+static bool ranges_overlap(uint32_t r1_lower, uint32_t r1_upper,
+ uint32_t r2_lower, uint32_t r2_upper)
+{
+ return !((r1_upper < r2_lower) || (r1_lower > r2_upper));
+}
+
+
+/* tell if a range is valid */
+static bool sr_range_is_valid(uint32_t lower, uint32_t upper, uint32_t min_size)
+{
+ return (upper >= lower + min_size);
+}
+
/**
* Update SRGB and/or SRLB using new CLI values.
*
@@ -2136,12 +2194,8 @@ static int update_sr_blocks(uint32_t gb_lower, uint32_t gb_upper,
/* Release old SRGB if it has changed and is active. */
if (gb_changed) {
- if (OspfSR.srgb.reserved) {
- ospf_zebra_release_label_range(
- OspfSR.srgb.start,
- OspfSR.srgb.start + OspfSR.srgb.size - 1);
- OspfSR.srgb.reserved = false;
- }
+
+ sr_global_block_delete();
/* Set new SRGB values - but do not reserve yet (we need to
* release the SRLB too) */
@@ -2155,8 +2209,8 @@ static int update_sr_blocks(uint32_t gb_lower, uint32_t gb_upper,
/* Release old SRLB if it has changed and reserve new block as needed.
*/
if (lb_changed) {
- if (OspfSR.srlb.reserved)
- sr_local_block_delete();
+
+ sr_local_block_delete();
/* Set new SRLB values */
if (sr_local_block_init(lb_lower, lb_upper) < 0) {
@@ -2175,18 +2229,11 @@ static int update_sr_blocks(uint32_t gb_lower, uint32_t gb_upper,
* allocated.
*/
if (gb_changed) {
- if (ospf_zebra_request_label_range(OspfSR.srgb.start,
- OspfSR.srgb.size)
+ if (sr_global_block_init(OspfSR.srgb.start, OspfSR.srgb.size)
< 0) {
- OspfSR.srgb.reserved = false;
ospf_sr_stop();
return -1;
- } else
- OspfSR.srgb.reserved = true;
-
- osr_debug("SR(%s): Got new SRGB [%u/%u]", __func__,
- OspfSR.srgb.start,
- OspfSR.srgb.start + OspfSR.srgb.size - 1);
+ }
}
/* Update Self SR-Node */
@@ -2227,16 +2274,29 @@ DEFUN(sr_global_label_range, sr_global_label_range_cmd,
/* Get lower and upper bound for mandatory global-block */
gb_lower = strtoul(argv[idx_gb_low]->arg, NULL, 10);
gb_upper = strtoul(argv[idx_gb_up]->arg, NULL, 10);
+
/* SRLB values are taken from vtysh if there, else use the known ones */
lb_upper = argc > idx_lb_up ? strtoul(argv[idx_lb_up]->arg, NULL, 10)
: OspfSR.srlb.end;
lb_lower = argc > idx_lb_low ? strtoul(argv[idx_lb_low]->arg, NULL, 10)
: OspfSR.srlb.start;
+ /* check correctness of input SRGB */
+ if (!sr_range_is_valid(gb_lower, gb_upper, MIN_SRGB_SIZE)) {
+ vty_out(vty, "Invalid SRGB range\n");
+ return CMD_WARNING_CONFIG_FAILED;
+ }
+
+ /* check correctness of SRLB */
+ if (!sr_range_is_valid(lb_lower, lb_upper, MIN_SRLB_SIZE)) {
+ vty_out(vty, "Invalid SRLB range\n");
+ return CMD_WARNING_CONFIG_FAILED;
+ }
+
/* Validate SRGB against SRLB */
- if (!((gb_upper < lb_lower) || (gb_lower > lb_upper))) {
+ if (ranges_overlap(gb_lower, gb_upper, lb_lower, lb_upper)) {
vty_out(vty,
- "New SR Global Block (%u/%u) conflict with Local Block (%u/%u)\n",
+ "New SR Global Block (%u/%u) conflicts with Local Block (%u/%u)\n",
gb_lower, gb_upper, lb_lower, lb_upper);
return CMD_WARNING_CONFIG_FAILED;
}
@@ -2287,6 +2347,12 @@ DEFUN_HIDDEN(sr_local_label_range, sr_local_label_range_cmd,
lower = strtoul(argv[idx_low]->arg, NULL, 10);
upper = strtoul(argv[idx_up]->arg, NULL, 10);
+ /* check correctness of SRLB */
+ if (!sr_range_is_valid(lower, upper, MIN_SRLB_SIZE)) {
+ vty_out(vty, "Invalid SRLB range\n");
+ return CMD_WARNING_CONFIG_FAILED;
+ }
+
/* Check if values have changed */
if ((OspfSR.srlb.start == lower)
&& (OspfSR.srlb.end == upper))
@@ -2294,9 +2360,10 @@ DEFUN_HIDDEN(sr_local_label_range, sr_local_label_range_cmd,
/* Validate SRLB against SRGB */
srgb_upper = OspfSR.srgb.start + OspfSR.srgb.size - 1;
- if (!((upper < OspfSR.srgb.start) || (lower > srgb_upper))) {
+
+ if (ranges_overlap(OspfSR.srgb.start, srgb_upper, lower, upper)) {
vty_out(vty,
- "New SR Local Block (%u/%u) conflict with Global Block (%u/%u)\n",
+ "New SR Local Block (%u/%u) conflicts with Global Block (%u/%u)\n",
lower, upper, OspfSR.srgb.start, srgb_upper);
return CMD_WARNING_CONFIG_FAILED;
}
@@ -2319,10 +2386,10 @@ DEFUN_HIDDEN(no_sr_local_label_range, no_sr_local_label_range_cmd,
/* Validate SRLB against SRGB */
srgb_end = OspfSR.srgb.start + OspfSR.srgb.size - 1;
- if (!((DEFAULT_SRLB_END < OspfSR.srgb.start)
- || (DEFAULT_SRLB_LABEL > srgb_end))) {
+ if (ranges_overlap(OspfSR.srgb.start, srgb_end, DEFAULT_SRLB_LABEL,
+ DEFAULT_SRLB_END)) {
vty_out(vty,
- "New SR Local Block (%u/%u) conflict with Global Block (%u/%u)\n",
+ "New SR Local Block (%u/%u) conflicts with Global Block (%u/%u)\n",
DEFAULT_SRLB_LABEL, DEFAULT_SRLB_END, OspfSR.srgb.start,
srgb_end);
return CMD_WARNING_CONFIG_FAILED;
@@ -2412,11 +2479,15 @@ DEFUN (sr_prefix_sid,
"Upstream neighbor must replace prefix-sid with explicit null label\n")
{
int idx = 0;
- struct prefix p;
+ struct prefix p, pexist;
uint32_t index;
struct listnode *node;
- struct sr_prefix *srp, *new = NULL;
+ struct sr_prefix *srp, *exist = NULL;
struct interface *ifp;
+ bool no_php_flag = false;
+ bool exp_null = false;
+ bool index_in_use = false;
+ uint8_t desired_flags = 0;
if (!ospf_sr_enabled(vty))
return CMD_WARNING_CONFIG_FAILED;
@@ -2437,53 +2508,67 @@ DEFUN (sr_prefix_sid,
return CMD_WARNING_CONFIG_FAILED;
}
+ /* Get options */
+ no_php_flag = argv_find(argv, argc, "no-php-flag", &idx);
+ exp_null = argv_find(argv, argc, "explicit-null", &idx);
+
+ desired_flags |= no_php_flag ? EXT_SUBTLV_PREFIX_SID_NPFLG : 0;
+ desired_flags |= exp_null ? EXT_SUBTLV_PREFIX_SID_NPFLG : 0;
+ desired_flags |= exp_null ? EXT_SUBTLV_PREFIX_SID_EFLG : 0;
+
/* Search for an existing Prefix-SID */
for (ALL_LIST_ELEMENTS_RO(OspfSR.self->ext_prefix, node, srp)) {
+ if (prefix_same((struct prefix *)&srp->prefv4, &p))
+ exist = srp;
if (srp->sid == index) {
- if (prefix_same((struct prefix *)&srp->prefv4, &p)) {
- new = srp;
- break;
- } else {
- vty_out(vty, "Index %u is already used\n",
- index);
- return CMD_WARNING_CONFIG_FAILED;
- }
+ index_in_use = true;
+ pexist = p;
}
}
- /* Create new Extended Prefix to SRDB if not found */
- if (new == NULL) {
- new = XCALLOC(MTYPE_OSPF_SR_PARAMS, sizeof(struct sr_prefix));
- IPV4_ADDR_COPY(&new->prefv4.prefix, &p.u.prefix4);
- new->prefv4.prefixlen = p.prefixlen;
- new->prefv4.family = p.family;
- new->sid = index;
- new->type = LOCAL_SID;
+ /* done if prefix segment already there with same index and flags */
+ if (exist && exist->sid == index && exist->flags == desired_flags)
+ return CMD_SUCCESS;
+
+ /* deny if index is already in use by a distinct prefix */
+ if (!exist && index_in_use) {
+ vty_out(vty, "Index %u is already used by %pFX\n", index,
+ &pexist);
+ return CMD_WARNING_CONFIG_FAILED;
}
/* First, remove old NHLFE if installed */
- if (srp == new && CHECK_FLAG(srp->flags, EXT_SUBTLV_PREFIX_SID_NPFLG)
- && !CHECK_FLAG(srp->flags, EXT_SUBTLV_PREFIX_SID_EFLG))
- ospf_zebra_delete_prefix_sid(srp);
- /* Then, reset Flag & labels to handle flag update */
- new->flags = 0;
- new->label_in = 0;
- new->nhlfe.label_out = 0;
+ if (exist && CHECK_FLAG(exist->flags, EXT_SUBTLV_PREFIX_SID_NPFLG)
+ && !CHECK_FLAG(exist->flags, EXT_SUBTLV_PREFIX_SID_EFLG))
+ ospf_zebra_delete_prefix_sid(exist);
- /* Set NO PHP flag if present and compute NHLFE */
- if (argv_find(argv, argc, "no-php-flag", &idx)) {
- SET_FLAG(new->flags, EXT_SUBTLV_PREFIX_SID_NPFLG);
- new->label_in = index2label(new->sid, OspfSR.self->srgb);
- new->nhlfe.label_out = MPLS_LABEL_IMPLICIT_NULL;
+ /* Create new Extended Prefix to SRDB if not found */
+ if (exist == NULL) {
+ srp = XCALLOC(MTYPE_OSPF_SR_PARAMS, sizeof(struct sr_prefix));
+ IPV4_ADDR_COPY(&srp->prefv4.prefix, &p.u.prefix4);
+ srp->prefv4.prefixlen = p.prefixlen;
+ srp->prefv4.family = p.family;
+ srp->sid = index;
+ srp->type = LOCAL_SID;
+ } else {
+ /* we work on the existing SR prefix */
+ srp = exist;
}
- /* Set EXPLICIT NULL flag is present */
- if (argv_find(argv, argc, "explicit-null", &idx)) {
- SET_FLAG(new->flags, EXT_SUBTLV_PREFIX_SID_NPFLG);
- SET_FLAG(new->flags, EXT_SUBTLV_PREFIX_SID_EFLG);
+
+ /* Reset labels to handle flag update */
+ srp->label_in = 0;
+ srp->nhlfe.label_out = 0;
+ srp->sid = index;
+ srp->flags = desired_flags;
+
+ /* If NO PHP flag is present, compute NHLFE and set label */
+ if (no_php_flag) {
+ srp->label_in = index2label(srp->sid, OspfSR.self->srgb);
+ srp->nhlfe.label_out = MPLS_LABEL_IMPLICIT_NULL;
}
osr_debug("SR (%s): Add new index %u to Prefix %pFX", __func__, index,
- (struct prefix *)&new->prefv4);
+ (struct prefix *)&srp->prefv4);
/* Get Interface and check if it is a Loopback */
ifp = if_lookup_prefix(&p, VRF_DEFAULT);
@@ -2494,7 +2579,8 @@ DEFUN (sr_prefix_sid,
* ready. In this case, store the prefix SID for latter
* update of this Extended Prefix
*/
- listnode_add(OspfSR.self->ext_prefix, new);
+ if (exist == NULL)
+ listnode_add(OspfSR.self->ext_prefix, srp);
zlog_info(
"Interface for prefix %pFX not found. Deferred LSA flooding",
&p);
@@ -2503,27 +2589,26 @@ DEFUN (sr_prefix_sid,
if (!if_is_loopback(ifp)) {
vty_out(vty, "interface %s is not a Loopback\n", ifp->name);
- XFREE(MTYPE_OSPF_SR_PARAMS, new);
+ XFREE(MTYPE_OSPF_SR_PARAMS, srp);
return CMD_WARNING_CONFIG_FAILED;
}
- new->nhlfe.ifindex = ifp->ifindex;
+ srp->nhlfe.ifindex = ifp->ifindex;
- /* Add this new SR Prefix if not already found */
- if (srp != new)
- listnode_add(OspfSR.self->ext_prefix, new);
+ /* Add SR Prefix if new */
+ if (!exist)
+ listnode_add(OspfSR.self->ext_prefix, srp);
/* Update Prefix SID if SR is UP */
if (OspfSR.status == SR_UP) {
- if (CHECK_FLAG(new->flags, EXT_SUBTLV_PREFIX_SID_NPFLG)
- && !CHECK_FLAG(new->flags, EXT_SUBTLV_PREFIX_SID_EFLG))
- ospf_zebra_update_prefix_sid(new);
+ if (no_php_flag && !exp_null)
+ ospf_zebra_update_prefix_sid(srp);
} else
return CMD_SUCCESS;
/* Finally, update Extended Prefix LSA id SR is UP */
- new->instance = ospf_ext_schedule_prefix_index(
- ifp, new->sid, &new->prefv4, new->flags);
- if (new->instance == 0) {
+ srp->instance = ospf_ext_schedule_prefix_index(
+ ifp, srp->sid, &srp->prefv4, srp->flags);
+ if (srp->instance == 0) {
vty_out(vty, "Unable to set index %u for prefix %pFX\n",
index, &p);
return CMD_WARNING;
@@ -2674,10 +2759,8 @@ static void show_sr_prefix(struct sbuf *sbuf, struct json_object *json,
srp->nhlfe.label_out);
json_object_string_add(json_obj, "interface",
itf ? itf->name : "-");
- json_object_string_add(
- json_obj, "nexthop",
- inet_ntop(AF_INET, &srp->nhlfe.nexthop,
- buf, sizeof(buf)));
+ json_object_string_addf(json_obj, "nexthop", "%pI4",
+ &srp->nhlfe.nexthop);
json_object_array_add(json_route, json_obj);
} else {
sbuf_push(sbuf, 0, "%20s %9s %15s\n",
@@ -2712,10 +2795,8 @@ static void show_sr_prefix(struct sbuf *sbuf, struct json_object *json,
path->srni.label_out);
json_object_string_add(json_obj, "interface",
itf ? itf->name : "-");
- json_object_string_add(
- json_obj, "nexthop",
- inet_ntop(AF_INET, &path->nexthop,
- buf, sizeof(buf)));
+ json_object_string_addf(json_obj, "nexthop", "%pI4",
+ &path->nexthop);
json_object_array_add(json_route, json_obj);
} else {
sbuf_push(sbuf, indent, "%20s %9s %15s\n",
@@ -2755,9 +2836,8 @@ static void show_sr_node(struct vty *vty, struct json_object *json,
if (json) {
json_node = json_object_new_object();
- json_object_string_add(json_node, "routerID",
- inet_ntop(AF_INET, &srn->adv_router,
- buf, sizeof(buf)));
+ json_object_string_addf(json_node, "routerID", "%pI4",
+ &srn->adv_router);
json_object_int_add(json_node, "srgbSize",
srn->srgb.range_size);
json_object_int_add(json_node, "srgbLabel",
@@ -2846,10 +2926,8 @@ static void show_sr_node(struct vty *vty, struct json_object *json,
srl->nhlfe[0].label_out);
json_object_string_add(json_obj, "interface",
itf ? itf->name : "-");
- json_object_string_add(
- json_obj, "nexthop",
- inet_ntop(AF_INET, &srl->nhlfe[0].nexthop,
- buf, sizeof(buf)));
+ json_object_string_addf(json_obj, "nexthop", "%pI4",
+ &srl->nhlfe[0].nexthop);
json_object_array_add(json_link, json_obj);
/* Backup Link */
json_obj = json_object_new_object();
@@ -2862,10 +2940,8 @@ static void show_sr_node(struct vty *vty, struct json_object *json,
srl->nhlfe[1].label_out);
json_object_string_add(json_obj, "interface",
itf ? itf->name : "-");
- json_object_string_add(
- json_obj, "nexthop",
- inet_ntop(AF_INET, &srl->nhlfe[1].nexthop,
- buf, sizeof(buf)));
+ json_object_string_addf(json_obj, "nexthop", "%pI4",
+ &srl->nhlfe[1].nexthop);
json_object_array_add(json_link, json_obj);
} else {
sbuf_push(&sbuf, 0, "%18s %21s %20s %9s %15s\n",
@@ -2925,7 +3001,6 @@ DEFUN (show_ip_opsf_srdb,
int idx = 0;
struct in_addr rid;
struct sr_node *srn;
- char buf[PREFIX_STRLEN];
bool uj = use_json(argc, argv);
json_object *json = NULL, *json_node_array = NULL;
@@ -2937,10 +3012,8 @@ DEFUN (show_ip_opsf_srdb,
if (uj) {
json = json_object_new_object();
json_node_array = json_object_new_array();
- json_object_string_add(
- json, "srdbID",
- inet_ntop(AF_INET, &OspfSR.self->adv_router,
- buf, sizeof(buf)));
+ json_object_string_addf(json, "srdbID", "%pI4",
+ &OspfSR.self->adv_router);
json_object_object_add(json, "srNodes", json_node_array);
} else {
vty_out(vty,
@@ -2951,12 +3024,8 @@ DEFUN (show_ip_opsf_srdb,
if (argv_find(argv, argc, "self-originate", &idx)) {
srn = OspfSR.self;
show_sr_node(vty, json_node_array, srn);
- if (uj) {
- vty_out(vty, "%s\n",
- json_object_to_json_string_ext(
- json, JSON_C_TO_STRING_PRETTY));
- json_object_free(json);
- }
+ if (uj)
+ vty_json(vty, json);
return CMD_SUCCESS;
}
@@ -2970,12 +3039,8 @@ DEFUN (show_ip_opsf_srdb,
srn = (struct sr_node *)hash_lookup(OspfSR.neighbors,
(void *)&rid);
show_sr_node(vty, json_node_array, srn);
- if (uj) {
- vty_out(vty, "%s\n",
- json_object_to_json_string_ext(
- json, JSON_C_TO_STRING_PRETTY));
- json_object_free(json);
- }
+ if (uj)
+ vty_json(vty, json);
return CMD_SUCCESS;
}
@@ -2984,9 +3049,7 @@ DEFUN (show_ip_opsf_srdb,
hash_iterate(OspfSR.neighbors, (void (*)(struct hash_bucket *,
void *))show_json_srdb,
(void *)json_node_array);
- vty_out(vty, "%s\n", json_object_to_json_string_ext(
- json, JSON_C_TO_STRING_PRETTY));
- json_object_free(json);
+ vty_json(vty, json);
} else {
hash_iterate(OspfSR.neighbors, (void (*)(struct hash_bucket *,
void *))show_vty_srdb,
diff --git a/ospfd/ospf_sr.h b/ospfd/ospf_sr.h
index d706d206fb..b153a220f5 100644
--- a/ospfd/ospf_sr.h
+++ b/ospfd/ospf_sr.h
@@ -38,7 +38,9 @@
#define SET_LABEL(label) ((label << 8) & SET_LABEL_MASK)
#define GET_LABEL(label) ((label >> 8) & GET_LABEL_MASK)
-#define OSPF_SR_DEFAULT_METRIC 1
+/* smallest configurable SRGB / SRLB sizes */
+#define MIN_SRLB_SIZE 16
+#define MIN_SRGB_SIZE 16
/* Segment Routing TLVs as per RFC 8665 */
@@ -221,7 +223,7 @@ struct sr_local_block {
enum sid_type { PREF_SID, LOCAL_SID, ADJ_SID, LAN_ADJ_SID };
/* Status of Segment Routing: Off (Disable), On (Enable), (Up) Started */
-enum sr_status { SR_OFF, SR_ON, SR_UP, SR_DOWN };
+enum sr_status { SR_OFF, SR_ON, SR_UP };
/* Structure aggregating all OSPF Segment Routing information for the node */
struct ospf_sr_db {
diff --git a/ospfd/ospf_te.c b/ospfd/ospf_te.c
index c5d1079e91..999bc49d91 100644
--- a/ospfd/ospf_te.c
+++ b/ospfd/ospf_te.c
@@ -4432,12 +4432,8 @@ DEFUN (show_ip_ospf_mpls_te_db,
ls_show_ted(OspfMplsTE.ted, vty, json, verbose);
}
- if (uj) {
- vty_out(vty, "%s\n",
- json_object_to_json_string_ext(
- json, JSON_C_TO_STRING_PRETTY));
- json_object_free(json);
- }
+ if (uj)
+ vty_json(vty, json);
return CMD_SUCCESS;
}
diff --git a/ospfd/ospf_vty.c b/ospfd/ospf_vty.c
index 5b9519ea59..6979b34196 100644
--- a/ospfd/ospf_vty.c
+++ b/ospfd/ospf_vty.c
@@ -3043,7 +3043,6 @@ static int show_ip_ospf_common(struct vty *vty, struct ospf *ospf,
struct ospf_area *area;
struct timeval result;
char timebuf[OSPF_TIME_DUMP_SIZE];
- char buf[PREFIX_STRLEN];
json_object *json_vrf = NULL;
json_object *json_areas = NULL;
@@ -3068,9 +3067,8 @@ static int show_ip_ospf_common(struct vty *vty, struct ospf *ospf,
/* Show Router ID. */
if (json) {
- json_object_string_add(json_vrf, "routerId",
- inet_ntop(AF_INET, &ospf->router_id,
- buf, sizeof(buf)));
+ json_object_string_addf(json_vrf, "routerId", "%pI4",
+ &ospf->router_id);
} else {
vty_out(vty, " OSPF Routing Process, Router ID: %pI4\n",
&ospf->router_id);
@@ -3388,23 +3386,17 @@ DEFUN (show_ip_ospf,
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);
- } else if (!ospf_output)
+ if (uj)
+ vty_json(vty, json);
+ else if (!ospf_output)
vty_out(vty, "%% OSPF instance not found\n");
return ret;
}
ospf = ospf_lookup_by_inst_name(inst, vrf_name);
if ((ospf == NULL) || !ospf->oi_running) {
- if (uj) {
- vty_out(vty, "%s\n",
- json_object_to_json_string_ext(
- json, JSON_C_TO_STRING_PRETTY));
- json_object_free(json);
- } else
+ if (uj)
+ vty_json(vty, json);
+ else
vty_out(vty, "%% OSPF instance not found\n");
return CMD_SUCCESS;
@@ -3413,12 +3405,9 @@ DEFUN (show_ip_ospf,
ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
/* Display default ospf (instance 0) info */
if (ospf == NULL || !ospf->oi_running) {
- if (uj) {
- vty_out(vty, "%s\n",
- json_object_to_json_string_ext(
- json, JSON_C_TO_STRING_PRETTY));
- json_object_free(json);
- } else
+ if (uj)
+ vty_json(vty, json);
+ else
vty_out(vty, "%% OSPF instance not found\n");
return CMD_SUCCESS;
@@ -3468,11 +3457,8 @@ DEFUN (show_ip_ospf_instance,
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);
- }
+ if (uj)
+ vty_json(vty, json);
return ret;
}
@@ -3533,7 +3519,6 @@ static void show_ip_ospf_interface_sub(struct vty *vty, struct ospf *ospf,
int is_up;
struct ospf_neighbor *nbr;
struct route_node *rn;
- char buf[PREFIX_STRLEN];
uint32_t bandwidth = ifp->bandwidth ? ifp->bandwidth : ifp->speed;
/* Is interface up? */
@@ -3603,11 +3588,9 @@ static void show_ip_ospf_interface_sub(struct vty *vty, struct ospf *ospf,
/* Show OSPF interface information. */
if (use_json) {
- json_object_string_add(
- json_interface_sub, "ipAddress",
- inet_ntop(AF_INET,
- &oi->address->u.prefix4,
- buf, sizeof(buf)));
+ json_object_string_addf(
+ json_interface_sub, "ipAddress", "%pI4",
+ &oi->address->u.prefix4);
json_object_int_add(json_interface_sub,
"ipAddressPrefixlen",
oi->address->prefixlen);
@@ -3637,17 +3620,13 @@ static void show_ip_ospf_interface_sub(struct vty *vty, struct ospf *ospf,
json_interface_sub,
"ospfIfType", dstr);
if (oi->type == OSPF_IFTYPE_VIRTUALLINK)
- json_object_string_add(
- json_interface_sub,
- "vlinkPeer",
- inet_ntop(AF_INET, &dest,
- buf, sizeof(buf)));
+ json_object_string_addf(
+ json_interface_sub, "vlinkPeer",
+ "%pI4", &dest);
else
- json_object_string_add(
+ json_object_string_addf(
json_interface_sub,
- "localIfUsed",
- inet_ntop(AF_INET, &dest,
- buf, sizeof(buf)));
+ "localIfUsed", "%pI4", &dest);
} else
vty_out(vty, " %s %pI4,", dstr,
&dest);
@@ -3659,10 +3638,8 @@ static void show_ip_ospf_interface_sub(struct vty *vty, struct ospf *ospf,
json_object_boolean_true_add(
json_interface_sub,
"mtuMismatchDetect");
- json_object_string_add(
- json_interface_sub, "routerId",
- inet_ntop(AF_INET, &ospf->router_id,
- buf, sizeof(buf)));
+ json_object_string_addf(json_interface_sub, "routerId",
+ "%pI4", &ospf->router_id);
json_object_string_add(json_interface_sub,
"networkType",
ospf_network_type_str[oi->type]);
@@ -3706,17 +3683,13 @@ static void show_ip_ospf_interface_sub(struct vty *vty, struct ospf *ospf,
nbr = ospf_nbr_lookup_by_addr(oi->nbrs, &DR(oi));
if (nbr) {
if (use_json) {
- json_object_string_add(
+ json_object_string_addf(
json_interface_sub, "drId",
- inet_ntop(AF_INET,
- &nbr->router_id, buf,
- sizeof(buf)));
- json_object_string_add(
+ "%pI4", &nbr->router_id);
+ json_object_string_addf(
json_interface_sub, "drAddress",
- inet_ntop(
- AF_INET,
- &nbr->address.u.prefix4,
- buf, sizeof(buf)));
+ "%pI4",
+ &nbr->address.u.prefix4);
} else {
vty_out(vty,
" Designated Router (ID) %pI4",
@@ -3735,18 +3708,13 @@ static void show_ip_ospf_interface_sub(struct vty *vty, struct ospf *ospf,
" No backup designated router on this network\n");
} else {
if (use_json) {
- json_object_string_add(
+ json_object_string_addf(
json_interface_sub, "bdrId",
- inet_ntop(AF_INET,
- &nbr->router_id,
- buf, sizeof(buf)));
- json_object_string_add(
+ "%pI4", &nbr->router_id);
+ json_object_string_addf(
json_interface_sub,
- "bdrAddress",
- inet_ntop(AF_INET,
- &nbr->address.u
- .prefix4,
- buf, sizeof(buf)));
+ "bdrAddress", "%pI4",
+ &nbr->address.u.prefix4);
} else {
vty_out(vty,
" Backup Designated Router (ID) %pI4,",
@@ -4150,24 +4118,18 @@ DEFUN (show_ip_ospf_interface,
uj);
}
- if (uj) {
- vty_out(vty, "%s\n",
- json_object_to_json_string_ext(
- json, JSON_C_TO_STRING_PRETTY));
- json_object_free(json);
- } else if (!ospf)
+ if (uj)
+ vty_json(vty, json);
+ else if (!ospf)
vty_out(vty, "%% OSPF instance not found\n");
return ret;
}
ospf = ospf_lookup_by_inst_name(inst, vrf_name);
if (ospf == NULL || !ospf->oi_running) {
- if (uj) {
- vty_out(vty, "%s\n",
- json_object_to_json_string_ext(
- json, JSON_C_TO_STRING_PRETTY));
- json_object_free(json);
- } else
+ if (uj)
+ vty_json(vty, json);
+ else
vty_out(vty, "%% OSPF instance not found\n");
return CMD_SUCCESS;
@@ -4179,12 +4141,9 @@ DEFUN (show_ip_ospf_interface,
/* Display default ospf (instance 0) info */
ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
if (ospf == NULL || !ospf->oi_running) {
- if (uj) {
- vty_out(vty, "%s\n",
- json_object_to_json_string_ext(
- json, JSON_C_TO_STRING_PRETTY));
- json_object_free(json);
- } else
+ if (uj)
+ vty_json(vty, json);
+ else
vty_out(vty, "%% OSPF instance not found\n");
return CMD_SUCCESS;
@@ -4193,11 +4152,8 @@ DEFUN (show_ip_ospf_interface,
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);
- }
+ if (uj)
+ vty_json(vty, json);
return ret;
}
@@ -4238,11 +4194,8 @@ DEFUN (show_ip_ospf_instance_interface,
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);
- }
+ if (uj)
+ vty_json(vty, json);
return ret;
}
@@ -4293,12 +4246,8 @@ DEFUN (show_ip_ospf_interface_traffic,
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);
- }
+ if (uj)
+ vty_json(vty, json);
return ret;
}
@@ -4323,11 +4272,8 @@ DEFUN (show_ip_ospf_interface_traffic,
vty, ospf, 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);
- }
+ if (uj)
+ vty_json(vty, json);
return ret;
}
@@ -4347,7 +4293,6 @@ static void show_ip_ospf_neighbor_sub(struct vty *vty,
struct route_node *rn;
struct ospf_neighbor *nbr, *prev_nbr = NULL;
char msgbuf[16];
- char buf[PREFIX_STRLEN];
char timebuf[OSPF_TIME_DUMP_SIZE];
json_object *json_neighbor = NULL, *json_neigh_array = NULL;
struct timeval res = {.tv_sec = 0, .tv_usec = 0};
@@ -4447,10 +4392,9 @@ static void show_ip_ospf_neighbor_sub(struct vty *vty,
"deadTimeMsecs",
"inactive");
}
- json_object_string_add(
- json_neighbor, "address",
- inet_ntop(AF_INET, &nbr->src,
- buf, sizeof(buf)));
+ json_object_string_addf(json_neighbor,
+ "address", "%pI4",
+ &nbr->src);
json_object_string_add(json_neighbor,
"ifaceName",
IF_NAME(oi));
@@ -4582,12 +4526,9 @@ DEFUN (show_ip_ospf_neighbor,
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));
- json_object_free(json);
- } else if (!ospf)
+ if (uj)
+ vty_json(vty, json);
+ else if (!ospf)
vty_out(vty, "OSPF instance not found\n");
return ret;
@@ -4595,12 +4536,9 @@ DEFUN (show_ip_ospf_neighbor,
ospf = ospf_lookup_by_inst_name(inst, vrf_name);
if (ospf == NULL || !ospf->oi_running) {
- if (uj) {
- vty_out(vty, "%s\n",
- json_object_to_json_string_ext(
- json, JSON_C_TO_STRING_PRETTY));
- json_object_free(json);
- } else
+ if (uj)
+ vty_json(vty, json);
+ else
vty_out(vty, "%% OSPF instance not found\n");
return CMD_SUCCESS;
@@ -4609,12 +4547,9 @@ DEFUN (show_ip_ospf_neighbor,
/* Display default ospf (instance 0) info */
ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
if (ospf == NULL || !ospf->oi_running) {
- if (uj) {
- vty_out(vty, "%s\n",
- json_object_to_json_string_ext(
- json, JSON_C_TO_STRING_PRETTY));
- json_object_free(json);
- } else
+ if (uj)
+ vty_json(vty, json);
+ else
vty_out(vty, "%% OSPF instance not found\n");
return CMD_SUCCESS;
@@ -4669,11 +4604,8 @@ DEFUN (show_ip_ospf_instance_neighbor,
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);
- }
+ if (uj)
+ vty_json(vty, json);
return ret;
}
@@ -4807,12 +4739,8 @@ DEFUN (show_ip_ospf_neighbor_all,
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));
- json_object_free(json);
- }
+ if (uj)
+ vty_json(vty, json);
return ret;
}
@@ -4879,11 +4807,8 @@ DEFUN (show_ip_ospf_instance_neighbor_all,
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);
- }
+ if (uj)
+ vty_json(vty, json);
return ret;
}
@@ -4928,11 +4853,9 @@ static int show_ip_ospf_neighbor_int_common(struct vty *vty, struct ospf *ospf,
show_ip_ospf_neighbor_sub(vty, oi, json, 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);
- } else
+ if (use_json)
+ vty_json(vty, json);
+ else
vty_out(vty, "\n");
return CMD_SUCCESS;
@@ -5028,7 +4951,6 @@ static void show_ip_ospf_nbr_nbma_detail_sub(struct vty *vty,
bool use_json, json_object *json)
{
char timebuf[OSPF_TIME_DUMP_SIZE];
- char buf[PREFIX_STRLEN];
json_object *json_sub = NULL;
if (use_json)
@@ -5038,9 +4960,8 @@ static void show_ip_ospf_nbr_nbma_detail_sub(struct vty *vty,
/* Show interface address. */
if (use_json)
- json_object_string_add(json_sub, "ifaceAddress",
- inet_ntop(AF_INET, &nbr_nbma->addr,
- buf, sizeof(buf)));
+ json_object_string_addf(json_sub, "ifaceAddress", "%pI4",
+ &nbr_nbma->addr);
else
vty_out(vty, " interface address %pI4\n",
&nbr_nbma->addr);
@@ -5113,7 +5034,6 @@ static void show_ip_ospf_neighbor_detail_sub(struct vty *vty,
char timebuf[OSPF_TIME_DUMP_SIZE];
json_object *json_neigh = NULL, *json_neigh_array = NULL;
char neigh_str[INET_ADDRSTRLEN] = {0};
- char buf[PREFIX_STRLEN];
if (use_json) {
if (prev_nbr &&
@@ -5150,10 +5070,8 @@ static void show_ip_ospf_neighbor_detail_sub(struct vty *vty,
/* Show interface address. */
if (use_json)
- json_object_string_add(json_neigh, "ifaceAddress",
- inet_ntop(AF_INET,
- &nbr->address.u.prefix4,
- buf, sizeof(buf)));
+ json_object_string_addf(json_neigh, "ifaceAddress", "%pI4",
+ &nbr->address.u.prefix4);
else
vty_out(vty, " interface address %pI4\n",
&nbr->address.u.prefix4);
@@ -5230,17 +5148,15 @@ static void show_ip_ospf_neighbor_detail_sub(struct vty *vty,
/* Show Designated Rotuer ID. */
if (use_json)
- json_object_string_add(json_neigh, "routerDesignatedId",
- inet_ntop(AF_INET, &nbr->d_router,
- buf, sizeof(buf)));
+ json_object_string_addf(json_neigh, "routerDesignatedId",
+ "%pI4", &nbr->d_router);
else
vty_out(vty, " DR is %pI4,", &nbr->d_router);
/* Show Backup Designated Rotuer ID. */
if (use_json)
- json_object_string_add(json_neigh, "routerDesignatedBackupId",
- inet_ntop(AF_INET, &nbr->bd_router,
- buf, sizeof(buf)));
+ json_object_string_addf(json_neigh, "routerDesignatedBackupId",
+ "%pI4", &nbr->bd_router);
else
vty_out(vty, " BDR is %pI4\n", &nbr->bd_router);
@@ -5439,11 +5355,9 @@ static int show_ip_ospf_neighbor_id_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);
- } else
+ if (use_json)
+ vty_json(vty, json);
+ else
vty_out(vty, "\n");
return CMD_SUCCESS;
@@ -5594,12 +5508,8 @@ DEFUN (show_ip_ospf_neighbor_detail,
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));
- json_object_free(json);
- }
+ if (uj)
+ vty_json(vty, json);
return ret;
}
@@ -5666,11 +5576,8 @@ DEFUN (show_ip_ospf_instance_neighbor_detail,
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);
- }
+ if (uj)
+ vty_json(vty, json);
return ret;
}
@@ -5783,12 +5690,8 @@ DEFUN (show_ip_ospf_neighbor_detail_all,
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));
- json_object_free(json);
- }
+ if (uj)
+ vty_json(vty, json);
return ret;
}
@@ -5856,11 +5759,8 @@ DEFUN (show_ip_ospf_instance_neighbor_detail_all,
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);
- }
+ if (uj)
+ vty_json(vty, json);
return ret;
}
@@ -5916,11 +5816,9 @@ static int show_ip_ospf_neighbor_int_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);
- } else
+ if (use_json)
+ vty_json(vty, json);
+ else
vty_out(vty, "\n");
return CMD_SUCCESS;
@@ -5995,7 +5893,6 @@ static int show_lsa_summary(struct vty *vty, struct ospf_lsa *lsa, int self,
struct summary_lsa *sl;
struct as_external_lsa *asel;
struct prefix_ipv4 p;
- char buf[PREFIX2STR_BUFFER];
if (lsa != NULL)
/* If self option is set, check LSA self flag. */
@@ -6018,15 +5915,11 @@ static int show_lsa_summary(struct vty *vty, struct ospf_lsa *lsa, int self,
ntohl(lsa->data->ls_seqnum));
snprintf(checksum, sizeof(checksum), "%x",
ntohs(lsa->data->checksum));
- json_object_string_add(
- json_lsa, "lsId",
- inet_ntop(AF_INET, &lsa->data->id,
- buf, sizeof(buf)));
- json_object_string_add(
- json_lsa, "advertisedRouter",
- inet_ntop(AF_INET,
- &lsa->data->adv_router,
- buf, sizeof(buf)));
+ json_object_string_addf(json_lsa, "lsId",
+ "%pI4", &lsa->data->id);
+ json_object_string_addf(
+ json_lsa, "advertisedRouter", "%pI4",
+ &lsa->data->adv_router);
json_object_int_add(json_lsa, "lsaAge",
LS_AGE(lsa));
json_object_string_add(
@@ -6058,10 +5951,9 @@ static int show_lsa_summary(struct vty *vty, struct ospf_lsa *lsa, int self,
if (!json_lsa)
vty_out(vty, " %pFX", &p);
else {
- prefix2str(&p, buf, sizeof(buf));
- json_object_string_add(json_lsa,
- "summaryAddress",
- buf);
+ json_object_string_addf(
+ json_lsa, "summaryAddress",
+ "%pFX", &p);
}
break;
case OSPF_AS_EXTERNAL_LSA:
@@ -6083,15 +5975,14 @@ static int show_lsa_summary(struct vty *vty, struct ospf_lsa *lsa, int self,
(unsigned long)ntohl(
asel->e[0].route_tag));
else {
- prefix2str(&p, buf, sizeof(buf));
json_object_string_add(
json_lsa, "metricType",
IS_EXTERNAL_METRIC(
asel->e[0].tos)
? "E2"
: "E1");
- json_object_string_add(json_lsa,
- "route", buf);
+ json_object_string_addf(
+ json_lsa, "route", "%pFX", &p);
json_object_int_add(
json_lsa, "tag",
(unsigned long)ntohl(
@@ -6162,7 +6053,6 @@ static const char *const show_database_header[] = {
static void show_ip_ospf_database_header(struct vty *vty, struct ospf_lsa *lsa,
json_object *json)
{
- char buf[PREFIX_STRLEN];
struct router_lsa *rlsa = (struct router_lsa *)lsa->data;
if (!json) {
@@ -6243,13 +6133,10 @@ static void show_ip_ospf_database_header(struct vty *vty, struct ospf_lsa *lsa,
json_object_string_add(
json, "lsaType",
lookup_msg(ospf_lsa_type_msg, lsa->data->type, NULL));
- json_object_string_add(json, "linkStateId",
- inet_ntop(AF_INET, &lsa->data->id,
- buf, sizeof(buf)));
- json_object_string_add(json, "advertisingRouter",
- inet_ntop(AF_INET,
- &lsa->data->adv_router,
- buf, sizeof(buf)));
+ json_object_string_addf(json, "linkStateId", "%pI4",
+ &lsa->data->id);
+ json_object_string_addf(json, "advertisingRouter", "%pI4",
+ &lsa->data->adv_router);
json_object_string_add(json, "lsaSeqNumber", seqnum);
json_object_string_add(json, "checksum", checksum);
json_object_int_add(json, "length", ntohs(lsa->data->length));
@@ -6478,7 +6365,6 @@ static int show_summary_asbr_lsa_detail(struct vty *vty, struct ospf_lsa *lsa,
static int show_as_external_lsa_detail(struct vty *vty, struct ospf_lsa *lsa,
json_object *json)
{
- char buf[PREFIX_STRLEN];
int tos = 0;
if (lsa != NULL) {
@@ -6513,10 +6399,8 @@ static int show_as_external_lsa_detail(struct vty *vty, struct ospf_lsa *lsa,
json_object_int_add(json, "tos", tos);
json_object_int_add(json, "metric",
GET_METRIC(al->e[0].metric));
- json_object_string_add(json, "forwardAddress",
- inet_ntop(AF_INET,
- &(al->e[0].fwd_addr),
- buf, sizeof(buf)));
+ json_object_string_addf(json, "forwardAddress", "%pI4",
+ &(al->e[0].fwd_addr));
json_object_int_add(
json, "externalRouteTag",
(route_tag_t)ntohl(al->e[0].route_tag));
@@ -6530,7 +6414,6 @@ static int show_as_external_lsa_detail(struct vty *vty, struct ospf_lsa *lsa,
static int show_as_nssa_lsa_detail(struct vty *vty, struct ospf_lsa *lsa,
json_object *json)
{
- char buf[PREFIX_STRLEN];
int tos = 0;
if (lsa != NULL) {
@@ -6566,10 +6449,8 @@ static int show_as_nssa_lsa_detail(struct vty *vty, struct ospf_lsa *lsa,
json_object_int_add(json, "tos", tos);
json_object_int_add(json, "metric",
GET_METRIC(al->e[0].metric));
- json_object_string_add(json, "nssaForwardAddress",
- inet_ntop(AF_INET,
- &al->e[0].fwd_addr,
- buf, sizeof(buf)));
+ json_object_string_addf(json, "nssaForwardAddress",
+ "%pI4", &al->e[0].fwd_addr);
json_object_int_add(
json, "externalRouteTag",
(route_tag_t)ntohl(al->e[0].route_tag));
@@ -6961,15 +6842,11 @@ static void show_ip_ospf_database_maxage(struct vty *vty, struct ospf *ospf,
json_lsa = json_object_new_object();
json_object_int_add(json_lsa, "linkType",
lsa->data->type);
- json_object_string_add(
- json_lsa, "linkStateId",
- inet_ntop(AF_INET, &lsa->data->id,
- buf, sizeof(buf)));
- json_object_string_add(
- json_lsa, "advertisingRouter",
- inet_ntop(AF_INET,
- &lsa->data->adv_router,
- buf, sizeof(buf)));
+ json_object_string_addf(json_lsa, "linkStateId",
+ "%pI4", &lsa->data->id);
+ json_object_string_addf(
+ json_lsa, "advertisingRouter", "%pI4",
+ &lsa->data->adv_router);
json_object_int_add(json_lsa, "lsaLockCount",
lsa->lock);
json_object_object_add(
@@ -7011,7 +6888,6 @@ static int show_ip_ospf_database_common(struct vty *vty, struct ospf *ospf,
int idx_type = 4;
int type, ret;
struct in_addr id, adv_router;
- char buf[PREFIX_STRLEN];
json_object *json_vrf = NULL;
if (uj) {
@@ -7033,9 +6909,8 @@ static int show_ip_ospf_database_common(struct vty *vty, struct ospf *ospf,
/* Show Router ID. */
if (uj) {
- json_object_string_add(json_vrf, "routerId",
- inet_ntop(AF_INET, &ospf->router_id,
- buf, sizeof(buf)));
+ json_object_string_addf(json_vrf, "routerId", "%pI4",
+ &ospf->router_id);
} else {
vty_out(vty, "\n OSPF Router with ID (%pI4)\n\n",
&ospf->router_id);
@@ -7249,12 +7124,8 @@ DEFUN (show_ip_ospf_instance_database_max,
show_ip_ospf_database_common(vty, ospf, 1, argc, argv, 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);
- }
+ if (uj)
+ vty_json(vty, json);
return CMD_SUCCESS;
}
@@ -7285,7 +7156,6 @@ static int show_ip_ospf_database_type_adv_router_common(struct vty *vty,
int idx_type = 4;
int type, ret;
struct in_addr adv_router;
- char buf[PREFIX_STRLEN];
json_object *json_vrf = NULL;
if (uj) {
@@ -7307,9 +7177,8 @@ static int show_ip_ospf_database_type_adv_router_common(struct vty *vty,
/* Show Router ID. */
if (uj) {
- json_object_string_add(json_vrf, "routerId",
- inet_ntop(AF_INET, &ospf->router_id,
- buf, sizeof(buf)));
+ json_object_string_addf(json_vrf, "routerId", "%pI4",
+ &ospf->router_id);
} else {
vty_out(vty, "\n OSPF Router with ID (%pI4)\n\n",
&ospf->router_id);
@@ -7468,12 +7337,8 @@ DEFUN (show_ip_ospf_instance_database_type_adv_router,
show_ip_ospf_database_type_adv_router_common(vty, ospf, 1, argc, argv,
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);
- }
+ if (uj)
+ vty_json(vty, json);
return CMD_SUCCESS;
}
@@ -8125,7 +7990,7 @@ static int ospf_vty_dead_interval_set(struct vty *vty, const char *interval_str,
if (nbr_str) {
struct ospf *ospf = NULL;
- ospf = ospf_lookup_by_vrf_id(ifp->vrf_id);
+ ospf = ifp->vrf->info;
if (ospf) {
oi = ospf_if_lookup_by_local_addr(ospf, ifp, addr);
if (oi)
@@ -8243,7 +8108,7 @@ DEFUN (no_ip_ospf_dead_interval,
if (argc == 1) {
struct ospf *ospf = NULL;
- ospf = ospf_lookup_by_vrf_id(ifp->vrf_id);
+ ospf = ifp->vrf->info;
if (ospf) {
oi = ospf_if_lookup_by_local_addr(ospf, ifp, addr);
if (oi)
@@ -8895,7 +8760,7 @@ DEFUN (ip_ospf_area,
areaid = argv[idx + 1]->arg;
if (!instance)
- ospf = ospf_lookup_by_vrf_id(ifp->vrf_id);
+ ospf = ifp->vrf->info;
else
ospf = ospf_lookup_instance(instance);
@@ -8926,7 +8791,7 @@ DEFUN (ip_ospf_area,
}
if (count > 0) {
- ospf = ospf_lookup_by_vrf_id(ifp->vrf_id);
+ ospf = ifp->vrf->info;
if (ospf)
ospf_interface_area_unset(ospf, ifp);
}
@@ -9019,7 +8884,7 @@ DEFUN (no_ip_ospf_area,
instance = strtol(argv[idx]->arg, NULL, 10);
if (!instance)
- ospf = ospf_lookup_by_vrf_id(ifp->vrf_id);
+ ospf = ifp->vrf->info;
else
ospf = ospf_lookup_instance(instance);
@@ -10082,7 +9947,6 @@ static void show_ip_ospf_route_network(struct vty *vty, struct ospf *ospf,
struct ospf_route * or ;
struct listnode *pnode, *pnnode;
struct ospf_path *path;
- char buf[PREFIX_STRLEN];
json_object *json_route = NULL, *json_nexthop_array = NULL,
*json_nexthop = NULL;
@@ -10112,11 +9976,9 @@ static void show_ip_ospf_route_network(struct vty *vty, struct ospf *ospf,
"N IA");
json_object_int_add(json_route, "cost",
or->cost);
- json_object_string_add(
- json_route, "area",
- inet_ntop(AF_INET,
- &or->u.std.area_id,
- buf1, sizeof(buf1)));
+ json_object_string_addf(
+ json_route, "area", "%pI4",
+ &or->u.std.area_id);
} else {
vty_out(vty,
"N IA %-18s [%d] area: %pI4\n",
@@ -10141,10 +10003,9 @@ static void show_ip_ospf_route_network(struct vty *vty, struct ospf *ospf,
"N");
json_object_int_add(json_route, "cost",
or->cost);
- json_object_string_add(
- json_route, "area",
- inet_ntop(AF_INET, &or->u.std.area_id,
- buf1, sizeof(buf1)));
+ json_object_string_addf(json_route, "area",
+ "%pI4",
+ &or->u.std.area_id);
} else {
vty_out(vty, "N %-18s [%d] area: %pI4\n",
buf1, or->cost,
@@ -10195,14 +10056,10 @@ static void show_ip_ospf_route_network(struct vty *vty, struct ospf *ospf,
}
} else {
if (json) {
- json_object_string_add(
+ json_object_string_addf(
json_nexthop,
- "ip",
- inet_ntop(
- AF_INET,
- &path->nexthop,
- buf,
- sizeof(buf)));
+ "ip", "%pI4",
+ &path->nexthop);
json_object_string_add(
json_nexthop,
"via",
@@ -10271,10 +10128,9 @@ static void show_ip_ospf_route_router(struct vty *vty, struct ospf *ospf,
if (json) {
json_object_int_add(json_route, "cost",
or->cost);
- json_object_string_add(
- json_route, "area",
- inet_ntop(AF_INET, &or->u.std.area_id,
- buf, sizeof(buf)));
+ json_object_string_addf(json_route, "area",
+ "%pI4",
+ &or->u.std.area_id);
if (or->path_type == OSPF_PATH_INTER_AREA)
json_object_boolean_true_add(json_route,
"IA");
@@ -10339,13 +10195,10 @@ static void show_ip_ospf_route_router(struct vty *vty, struct ospf *ospf,
}
} else {
if (json) {
- json_object_string_add(
+ json_object_string_addf(
json_nexthop,
- "ip",
- inet_ntop(
- AF_INET,
- &path->nexthop,
- buf, sizeof(buf)));
+ "ip", "%pI4",
+ &path->nexthop);
json_object_string_add(
json_nexthop,
"via",
@@ -10378,7 +10231,6 @@ static void show_ip_ospf_route_external(struct vty *vty, struct ospf *ospf,
struct ospf_route *er;
struct listnode *pnode, *pnnode;
struct ospf_path *path;
- char buf[PREFIX_STRLEN];
json_object *json_route = NULL, *json_nexthop_array = NULL,
*json_nexthop = NULL;
@@ -10469,13 +10321,9 @@ static void show_ip_ospf_route_external(struct vty *vty, struct ospf *ospf,
}
} else {
if (json) {
- json_object_string_add(
+ json_object_string_addf(
json_nexthop, "ip",
- inet_ntop(
- AF_INET,
- &path->nexthop,
- buf,
- sizeof(buf)));
+ "%pI4", &path->nexthop);
json_object_string_add(
json_nexthop, "via",
ifindex2ifname(
@@ -10700,11 +10548,7 @@ DEFUN (show_ip_ospf_route,
if (uj) {
/* Keep Non-pretty format */
- vty_out(vty, "%s\n",
- json_object_to_json_string_ext(
- json,
- JSON_C_TO_STRING_NOSLASHESCAPE));
- json_object_free(json);
+ vty_json(vty, json);
} else if (!ospf_output)
vty_out(vty, "%% OSPF instance not found\n");
@@ -10712,14 +10556,9 @@ DEFUN (show_ip_ospf_route,
}
ospf = ospf_lookup_by_inst_name(inst, vrf_name);
if (ospf == NULL || !ospf->oi_running) {
- if (uj) {
- vty_out(vty, "%s\n",
- json_object_to_json_string_ext(
- json,
- JSON_C_TO_STRING_PRETTY
- | JSON_C_TO_STRING_NOSLASHESCAPE));
- json_object_free(json);
- } else
+ if (uj)
+ vty_json(vty, json);
+ else
vty_out(vty, "%% OSPF instance not found\n");
return CMD_SUCCESS;
@@ -10728,14 +10567,9 @@ DEFUN (show_ip_ospf_route,
/* Display default ospf (instance 0) info */
ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
if (ospf == NULL || !ospf->oi_running) {
- if (uj) {
- vty_out(vty, "%s\n",
- json_object_to_json_string_ext(
- json,
- JSON_C_TO_STRING_PRETTY
- | JSON_C_TO_STRING_NOSLASHESCAPE));
- json_object_free(json);
- } else
+ if (uj)
+ vty_json(vty, json);
+ else
vty_out(vty, "%% OSPF instance not found\n");
return CMD_SUCCESS;
@@ -10797,7 +10631,6 @@ DEFUN (show_ip_ospf_vrfs,
struct ospf *ospf = NULL;
struct listnode *node = NULL;
int count = 0;
- char buf[PREFIX_STRLEN];
static const char header[] = "Name Id RouterId ";
if (uj) {
@@ -10825,10 +10658,8 @@ DEFUN (show_ip_ospf_vrfs,
if (uj) {
json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
- json_object_string_add(
- json_vrf, "routerId",
- inet_ntop(AF_INET, &ospf->router_id,
- buf, sizeof(buf)));
+ json_object_string_addf(json_vrf, "routerId", "%pI4",
+ &ospf->router_id);
json_object_object_add(json_vrfs, name, json_vrf);
@@ -10842,9 +10673,7 @@ DEFUN (show_ip_ospf_vrfs,
json_object_object_add(json, "vrfs", json_vrfs);
json_object_int_add(json, "totalVrfs", count);
- vty_out(vty, "%s\n", json_object_to_json_string_ext(
- json, JSON_C_TO_STRING_PRETTY));
- json_object_free(json);
+ vty_json(vty, json);
} else {
if (count)
vty_out(vty, "\nTotal number of OSPF VRFs: %d\n",
@@ -11131,12 +10960,8 @@ DEFUN (show_ip_ospf_external_aggregator,
vty, ospf, use_vrf, json, uj, detail);
}
- if (uj) {
- vty_out(vty, "%s\n",
- json_object_to_json_string_ext(
- json, JSON_C_TO_STRING_PRETTY));
- json_object_free(json);
- }
+ if (uj)
+ vty_json(vty, json);
return ret;
}
@@ -11144,12 +10969,9 @@ DEFUN (show_ip_ospf_external_aggregator,
ospf = ospf_lookup_by_inst_name(inst, vrf_name);
if (ospf == NULL || !ospf->oi_running) {
- if (uj) {
- vty_out(vty, "%s\n",
- json_object_to_json_string_ext(
- json, JSON_C_TO_STRING_PRETTY));
- json_object_free(json);
- } else
+ if (uj)
+ vty_json(vty, json);
+ else
vty_out(vty, "%% OSPF instance not found\n");
return CMD_SUCCESS;
@@ -11160,12 +10982,9 @@ DEFUN (show_ip_ospf_external_aggregator,
/* Default Vrf */
ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
if (ospf == NULL || !ospf->oi_running) {
- if (uj) {
- vty_out(vty, "%s\n",
- json_object_to_json_string_ext(
- json, JSON_C_TO_STRING_PRETTY));
- json_object_free(json);
- } else
+ if (uj)
+ vty_json(vty, json);
+ else
vty_out(vty, "%% OSPF instance not found\n");
return CMD_SUCCESS;
@@ -11174,11 +10993,8 @@ DEFUN (show_ip_ospf_external_aggregator,
ospf_show_summary_address(vty, ospf, use_vrf, json, uj, detail);
}
- if (uj) {
- vty_out(vty, "%s\n", json_object_to_json_string_ext(
- json, JSON_C_TO_STRING_PRETTY));
- json_object_free(json);
- }
+ if (uj)
+ vty_json(vty, json);
return CMD_SUCCESS;
}
@@ -11232,7 +11048,7 @@ static int config_write_interface_one(struct vty *vty, struct vrf *vrf)
continue;
vty_frame(vty, "!\n");
- if (ifp->vrf_id == VRF_DEFAULT)
+ if (ifp->vrf->vrf_id == VRF_DEFAULT)
vty_frame(vty, "interface %s\n", ifp->name);
else
vty_frame(vty, "interface %s vrf %s\n", ifp->name,
diff --git a/ospfd/ospfd.c b/ospfd/ospfd.c
index dd0a49c9bc..05433ccb95 100644
--- a/ospfd/ospfd.c
+++ b/ospfd/ospfd.c
@@ -1443,8 +1443,8 @@ void ospf_if_update(struct ospf *ospf, struct interface *ifp)
if (IS_DEBUG_OSPF_EVENT)
zlog_debug(
- "%s: interface %s ifp->vrf_id %u ospf vrf %s vrf_id %u router_id %pI4",
- __func__, ifp->name, ifp->vrf_id,
+ "%s: interface %s vrf %s(%u) ospf vrf %s vrf_id %u router_id %pI4",
+ __func__, ifp->name, ifp->vrf->name, ifp->vrf->vrf_id,
ospf_vrf_id_to_name(ospf->vrf_id), ospf->vrf_id,
&ospf->router_id);