* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include "vty.h"
#include "zclient.h"
#include <lib/json.h>
+#include "ospf_errors.h"
#include "ospfd/ospfd.h"
#include "ospfd/ospf_interface.h"
}
/* Compare 2 Router ID hash entries based on SR Node */
-static int sr_cmp(const void *p1, const void *p2)
+static bool sr_cmp(const void *p1, const void *p2)
{
const struct sr_node *srn = p1;
const struct in_addr *rid = p2;
del_sid_nhlfe(srl->nhlfe[0]);
del_sid_nhlfe(srl->nhlfe[1]);
XFREE(MTYPE_OSPF_SR_PARAMS, val);
-
}
/* Functions to remove an SR Prefix */
del_sid_nhlfe(srp->nhlfe);
XFREE(MTYPE_OSPF_SR_PARAMS, val);
-
}
/* Allocate new Segment Routine node */
/* Allocate Segment Routing node memory */
new = XCALLOC(MTYPE_OSPF_SR_PARAMS, sizeof(struct sr_node));
- /* Sanity Check */
- if (new == NULL) {
- zlog_err("SR (%s): Abort! can't create new SR node", __func__);
- return NULL;
- }
-
/* Default Algorithm, SRGB and MSD */
for (int i = 0; i < ALGORITHM_COUNT; i++)
new->algo[i] = SR_ALGORITHM_UNSET;
return;
/* Clean Extended Link */
- list_delete_and_null(&srn->ext_link);
+ list_delete(&srn->ext_link);
/* Clean Prefix List */
- list_delete_and_null(&srn->ext_prefix);
+ list_delete(&srn->ext_prefix);
XFREE(MTYPE_OSPF_SR_PARAMS, srn);
}
srn = hash_get(OspfSR.neighbors, (void *)&(ospf->router_id),
(void *)sr_node_new);
- /* Sanity Check */
- if (srn == NULL)
- return rc;
-
/* Complete & Store self SR Node */
srn->srgb.range_size = OspfSR.srgb.range_size;
srn->srgb.lower_bound = OspfSR.srgb.lower_bound;
/* Start by looking to Router Info & Extended LSA in lsdb */
if ((ospf != NULL) && (ospf->backbone != NULL)) {
- LSDB_LOOP(OPAQUE_AREA_LSDB(ospf->backbone), rn, lsa)
- {
+ LSDB_LOOP (OPAQUE_AREA_LSDB(ospf->backbone), rn, lsa) {
if (IS_LSA_MAXAGE(lsa) || IS_LSA_SELF(lsa))
continue;
int lsa_id =
/*
* Remove all SR Nodes from the Hash table. Prefix and Link SID will
- * be remove though list_delete_and_null() call. See sr_node_del()
+ * be remove though list_delete() call. See sr_node_del()
*/
hash_clean(OspfSR.neighbors, (void *)sr_node_del);
}
static struct ospf_path *get_nexthop_by_addr(struct ospf *top,
struct prefix_ipv4 p)
{
- struct ospf_route *or;
+ struct ospf_route * or ;
struct ospf_path *path;
struct listnode *node;
struct route_node *rn;
srl = XCALLOC(MTYPE_OSPF_SR_PARAMS, sizeof(struct sr_link));
- if (srl == NULL)
- return NULL;
-
/* Initialize TLV browsing */
length = ntohs(tlvh->length) - EXT_TLV_LINK_SIZE;
sub_tlvh = (struct tlv_header *)((char *)(tlvh) + TLV_HDR_SIZE
srp = XCALLOC(MTYPE_OSPF_SR_PARAMS, sizeof(struct sr_prefix));
- if (srp == NULL)
- return NULL;
-
/* Initialize TLV browsing */
length = ntohs(tlvh->length) - EXT_TLV_PREFIX_SIZE;
sub_tlvh = (struct tlv_header *)((char *)(tlvh) + TLV_HDR_SIZE
case EXT_SUBTLV_PREFIX_SID:
psid = (struct ext_subtlv_prefix_sid *)sub_tlvh;
if (psid->algorithm != SR_ALGORITHM_SPF) {
- zlog_err(
- "SR (%s): Unsupported Algorithm",
- __func__);
+ flog_err(EC_OSPF_INVALID_ALGORITHM,
+ "SR (%s): Unsupported Algorithm",
+ __func__);
XFREE(MTYPE_OSPF_SR_PARAMS, srp);
return NULL;
}
/* Update Segment Link of given Segment Routing Node */
static void update_ext_link_sid(struct sr_node *srn, struct sr_link *srl,
- u_char lsa_flags)
+ uint8_t lsa_flags)
{
struct listnode *node;
struct sr_link *lk;
zlog_debug(
"SR (%s): Process Router "
"Information LSA 4.0.0.%u from %s",
- __func__,
- GET_OPAQUE_ID(ntohl(lsah->id.s_addr)),
+ __func__, GET_OPAQUE_ID(ntohl(lsah->id.s_addr)),
inet_ntoa(lsah->adv_router));
/* Sanity check */
return;
if (OspfSR.neighbors == NULL) {
- zlog_err("SR (%s): Abort! no valid SR DataBase", __func__);
+ flog_err(EC_OSPF_SR_INVALID_DB,
+ "SR (%s): Abort! no valid SR DataBase", __func__);
return;
}
/* Sanity check */
if (srn == NULL) {
- zlog_err(
- "SR (%s): Abort! can't create SR node in hash table",
- __func__);
+ flog_err(EC_OSPF_SR_NODE_CREATE,
+ "SR (%s): Abort! can't create SR node in hash table",
+ __func__);
return;
}
if ((srn->instance != 0) && (srn->instance != ntohl(lsah->id.s_addr))) {
- zlog_err(
- "SR (%s): Abort! Wrong "
- "LSA ID 4.0.0.%u for SR node %s/%u",
- __func__,
- GET_OPAQUE_ID(ntohl(lsah->id.s_addr)),
- inet_ntoa(lsah->adv_router), srn->instance);
+ flog_err(EC_OSPF_SR_INVALID_LSA_ID,
+ "SR (%s): Abort! Wrong "
+ "LSA ID 4.0.0.%u for SR node %s/%u",
+ __func__, GET_OPAQUE_ID(ntohl(lsah->id.s_addr)),
+ inet_ntoa(lsah->adv_router), srn->instance);
return;
}
/* Check that we collect mandatory parameters */
if (srn->algo[0] == SR_ALGORITHM_UNSET || srgb.range_size == 0
|| srgb.lower_bound == 0) {
- zlog_warn(
- "SR (%s): Missing mandatory parameters. Abort!",
- __func__);
+ flog_err(EC_OSPF_SR_NODE_CREATE,
+ "SR (%s): Missing mandatory parameters. Abort!",
+ __func__);
hash_release(OspfSR.neighbors, &(srn->adv_router));
XFREE(MTYPE_OSPF_SR_PARAMS, srn);
return;
void *))update_out_nhlfe,
(void *)srn);
}
-
}
/*
struct lsa_header *lsah = (struct lsa_header *)lsa->data;
if (IS_DEBUG_OSPF_SR)
- zlog_debug(
- "SR (%s): Remove SR node %s from lsa_id 4.0.0.%u",
- __func__, inet_ntoa(lsah->adv_router),
- GET_OPAQUE_ID(ntohl(lsah->id.s_addr)));
+ zlog_debug("SR (%s): Remove SR node %s from lsa_id 4.0.0.%u",
+ __func__, inet_ntoa(lsah->adv_router),
+ GET_OPAQUE_ID(ntohl(lsah->id.s_addr)));
/* Sanity check */
if (OspfSR.neighbors == NULL) {
- zlog_err("SR (%s): Abort! no valid SR Data Base", __func__);
+ flog_err(EC_OSPF_SR_INVALID_DB,
+ "SR (%s): Abort! no valid SR Data Base", __func__);
return;
}
/* Sanity check */
if (srn == NULL) {
- zlog_err(
- "SR (%s): Abort! no entry in SRDB for SR Node %s",
- __func__, inet_ntoa(lsah->adv_router));
+ flog_err(EC_OSPF_SR_NODE_CREATE,
+ "SR (%s): Abort! no entry in SRDB for SR Node %s",
+ __func__, inet_ntoa(lsah->adv_router));
return;
}
if ((srn->instance != 0) && (srn->instance != ntohl(lsah->id.s_addr))) {
- zlog_err(
- "SR (%s): Abort! Wrong LSA ID 4.0.0.%u for SR node %s",
- __func__, GET_OPAQUE_ID(ntohl(lsah->id.s_addr)),
- inet_ntoa(lsah->adv_router));
+ flog_err(EC_OSPF_SR_INVALID_LSA_ID,
+ "SR (%s): Abort! Wrong LSA ID 4.0.0.%u for SR node %s",
+ __func__, GET_OPAQUE_ID(ntohl(lsah->id.s_addr)),
+ inet_ntoa(lsah->adv_router));
return;
}
/* Remove SR node */
sr_node_del(srn);
-
}
/* Update Segment Routing from Extended Link LSA */
/* Sanity check */
if (OspfSR.neighbors == NULL) {
- zlog_err("SR (%s): Abort! no valid SR DataBase", __func__);
+ flog_err(EC_OSPF_SR_INVALID_DB,
+ "SR (%s): Abort! no valid SR DataBase", __func__);
return;
}
/* Sanity check */
if (srn == NULL) {
- zlog_err(
- "SR (%s): Abort! can't create SR node in hash table",
- __func__);
+ flog_err(EC_OSPF_SR_NODE_CREATE,
+ "SR (%s): Abort! can't create SR node in hash table",
+ __func__);
return;
}
uint32_t instance = ntohl(lsah->id.s_addr);
if (IS_DEBUG_OSPF_SR)
- zlog_debug(
- "SR (%s): Remove Extended Link LSA 8.0.0.%u from %s",
- __func__, GET_OPAQUE_ID(ntohl(lsah->id.s_addr)),
- inet_ntoa(lsah->adv_router));
+ zlog_debug("SR (%s): Remove Extended Link LSA 8.0.0.%u from %s",
+ __func__, GET_OPAQUE_ID(ntohl(lsah->id.s_addr)),
+ inet_ntoa(lsah->adv_router));
/* Sanity check */
if (OspfSR.neighbors == NULL) {
- zlog_err("SR (%s): Abort! no valid SR DataBase", __func__);
+ flog_err(EC_OSPF_SR_INVALID_DB,
+ "SR (%s): Abort! no valid SR DataBase", __func__);
return;
}
* processing Router Information LSA deletion
*/
if (srn == NULL) {
- zlog_warn(
- "SR (%s): Stop! no entry in SRDB for SR Node %s",
- __func__, inet_ntoa(lsah->adv_router));
+ flog_err(EC_OSPF_SR_INVALID_DB,
+ "SR (%s): Stop! no entry in SRDB for SR Node %s",
+ __func__, inet_ntoa(lsah->adv_router));
return;
}
listnode_delete(srn->ext_link, srl);
XFREE(MTYPE_OSPF_SR_PARAMS, srl);
} else {
- zlog_warn(
- "SR (%s): Didn't found corresponding SR Link 8.0.0.%u "
- "for SR Node %s", __func__,
- GET_OPAQUE_ID(ntohl(lsah->id.s_addr)),
- inet_ntoa(lsah->adv_router));
+ flog_err(EC_OSPF_SR_INVALID_DB,
+ "SR (%s): Didn't found corresponding SR Link 8.0.0.%u "
+ "for SR Node %s",
+ __func__, GET_OPAQUE_ID(ntohl(lsah->id.s_addr)),
+ inet_ntoa(lsah->adv_router));
}
-
}
/* Update Segment Routing from Extended Prefix LSA */
if (IS_DEBUG_OSPF_SR)
zlog_debug(
"SR (%s): Process Extended Prefix LSA "
- "7.0.0.%u from %s", __func__,
- GET_OPAQUE_ID(ntohl(lsah->id.s_addr)),
+ "7.0.0.%u from %s",
+ __func__, GET_OPAQUE_ID(ntohl(lsah->id.s_addr)),
inet_ntoa(lsah->adv_router));
/* Sanity check */
if (OspfSR.neighbors == NULL) {
- zlog_err("SR (%s): Abort! no valid SR DataBase", __func__);
+ flog_err(EC_OSPF_SR_INVALID_DB,
+ "SR (%s): Abort! no valid SR DataBase", __func__);
return;
}
/* Sanity check */
if (srn == NULL) {
- zlog_err(
- "SR (%s): Abort! can't create SR node in hash table",
- __func__);
+ flog_err(EC_OSPF_SR_NODE_CREATE,
+ "SR (%s): Abort! can't create SR node in hash table",
+ __func__);
return;
}
/* Sanity check */
if (OspfSR.neighbors == NULL) {
- zlog_err("SR (%s): Abort! no valid SR DataBase", __func__);
+ flog_err(EC_OSPF_SR_INVALID_DB,
+ "SR (%s): Abort! no valid SR DataBase", __func__);
return;
}
* processing Router Information LSA deletion
*/
if (srn == NULL) {
- zlog_warn(
- "SR (%s): Stop! no entry in SRDB for SR Node %s",
- __func__, inet_ntoa(lsah->adv_router));
+ flog_err(EC_OSPF_SR_INVALID_DB,
+ "SR (%s): Stop! no entry in SRDB for SR Node %s",
+ __func__, inet_ntoa(lsah->adv_router));
return;
}
listnode_delete(srn->ext_link, srp);
XFREE(MTYPE_OSPF_SR_PARAMS, srp);
} else {
- zlog_warn(
- "SR (%s): Didn't found corresponding SR Prefix "
- "7.0.0.%u for SR Node %s", __func__,
- GET_OPAQUE_ID(ntohl(lsah->id.s_addr)),
+ flog_err(
+ EC_OSPF_SR_INVALID_DB,
+ "SR (%s): Didn't found corresponding SR Prefix 7.0.0.%u for SR Node %s",
+ __func__, GET_OPAQUE_ID(ntohl(lsah->id.s_addr)),
inet_ntoa(lsah->adv_router));
}
-
}
/* Get Label for Extended Link SID */
for (ALL_LIST_ELEMENTS_RO(OspfSR.self->ext_prefix, node, srp)) {
if ((srp->nhlfe.ifindex == ifp->ifindex)
|| ((IPV4_ADDR_SAME(&srp->nhlfe.prefv4.prefix,
- &p->u.prefix4))
- && (srp->nhlfe.prefv4.prefixlen == p->prefixlen))) {
+ &p->u.prefix4))
+ && (srp->nhlfe.prefv4.prefixlen == p->prefixlen))) {
/* Update Interface & Prefix info */
srp->nhlfe.ifindex = ifp->ifindex;
IPV4_ADDR_COPY(&srp->nhlfe.prefv4.prefix,
- &p->u.prefix4);
+ &p->u.prefix4);
srp->nhlfe.prefv4.prefixlen = p->prefixlen;
srp->nhlfe.prefv4.family = p->family;
IPV4_ADDR_COPY(&srp->nhlfe.nexthop, &p->u.prefix4);
/* OK. Let's Schedule Extended Prefix LSA */
- srp->instance = ospf_ext_schedule_prefix_index(ifp,
- srp->sid, &srp->nhlfe.prefv4, srp->flags);
+ srp->instance = ospf_ext_schedule_prefix_index(
+ ifp, srp->sid, &srp->nhlfe.prefv4, srp->flags);
/* Install NHLFE if NO-PHP is requested */
if (CHECK_FLAG(srp->flags,
- EXT_SUBTLV_PREFIX_SID_NPFLG)) {
- srp->nhlfe.label_in = index2label(srp->sid,
- OspfSR.self->srgb);
+ EXT_SUBTLV_PREFIX_SID_NPFLG)) {
+ srp->nhlfe.label_in = index2label(
+ srp->sid, OspfSR.self->srgb);
srp->nhlfe.label_out = MPLS_LABEL_IMPLICIT_NULL;
add_sid_nhlfe(srp->nhlfe);
}
struct sr_nhlfe old;
int rc;
- /* Sanity Check */
- if (srn == NULL)
- return;
-
if (IS_DEBUG_OSPF_SR)
zlog_debug(" |- Update Prefix for SR Node %s",
inet_ntoa(srn->adv_router));
zlog_debug("SR (%s): SPF Processing Time(usecs): %lld\n",
__func__,
(stop_time.tv_sec - start_time.tv_sec) * 1000000LL
- + (stop_time.tv_usec - start_time.tv_usec));
+ + (stop_time.tv_usec - start_time.tv_usec));
OspfSR.update = false;
return 1;
if ((OspfSR.srgb.lower_bound != MPLS_DEFAULT_MIN_SRGB_LABEL)
|| (OspfSR.srgb.range_size != MPLS_DEFAULT_MAX_SRGB_SIZE)) {
vty_out(vty, " segment-routing global-block %u %u\n",
- OspfSR.srgb.lower_bound,
- OspfSR.srgb.lower_bound +
- OspfSR.srgb.range_size - 1);
+ OspfSR.srgb.lower_bound,
+ OspfSR.srgb.lower_bound + OspfSR.srgb.range_size
+ - 1);
}
if (OspfSR.msd != 0)
vty_out(vty, " segment-routing node-msd %u\n",
inet_ntoa(srp->nhlfe.prefv4.prefix),
srp->nhlfe.prefv4.prefixlen, srp->sid,
CHECK_FLAG(srp->flags,
- EXT_SUBTLV_PREFIX_SID_NPFLG) ?
- " no-php-flag" : "");
+ EXT_SUBTLV_PREFIX_SID_NPFLG)
+ ? " no-php-flag"
+ : "");
}
}
}
return CMD_SUCCESS;
if (ospf->vrf_id != VRF_DEFAULT) {
- vty_out(vty, "Segment Routing is only supported in default "
- "VRF\n");
+ vty_out(vty,
+ "Segment Routing is only supported in default "
+ "VRF\n");
return CMD_WARNING_CONFIG_FAILED;
}
/* Start Segment Routing */
OspfSR.enabled = true;
- if (!ospf_sr_start(ospf)) {
- zlog_warn("SR: Unable to start Segment Routing. Abort!");
- return CMD_WARNING;
- }
+ ospf_sr_start(ospf);
/* Set Router Information SR parameters */
if (IS_DEBUG_OSPF_EVENT)
/* Get network prefix */
argv_find(argv, argc, "A.B.C.D/M", &idx);
if (!str2prefix(argv[idx]->arg, &p)) {
- vty_out(vty, "Invalid prefix format %s\n",
- argv[idx]->arg);
+ vty_out(vty, "Invalid prefix format %s\n", argv[idx]->arg);
return CMD_WARNING_CONFIG_FAILED;
}
}
if (IS_DEBUG_OSPF_SR)
- zlog_debug(
- "SR (%s): Add new index %u to Prefix %s/%u",
- __func__, index, inet_ntoa(new->nhlfe.prefv4.prefix),
- new->nhlfe.prefv4.prefixlen);
+ zlog_debug("SR (%s): Add new index %u to Prefix %s/%u",
+ __func__, index, inet_ntoa(new->nhlfe.prefv4.prefix),
+ new->nhlfe.prefv4.prefixlen);
/* Get Interface and check if it is a Loopback */
ifp = if_lookup_prefix(&p, VRF_DEFAULT);
* update of this Extended Prefix
*/
listnode_add(OspfSR.self->ext_prefix, new);
- zlog_warn(
+ zlog_info(
"Interface for prefix %s/%u not found. Deferred LSA "
- "flooding", inet_ntoa(p.u.prefix4), p.prefixlen);
+ "flooding",
+ inet_ntoa(p.u.prefix4), p.prefixlen);
return CMD_SUCCESS;
}
/* Search if this prefix already exist */
for (ALL_LIST_ELEMENTS_RO(OspfSR.self->ext_prefix, node, srp)) {
if ((IPV4_ADDR_SAME(&srp->nhlfe.prefv4.prefix, &p.u.prefix4)
- && srp->nhlfe.prefv4.prefixlen == p.prefixlen))
+ && srp->nhlfe.prefv4.prefixlen == p.prefixlen))
break;
else
srp = NULL;
}
/* Finally, update Extended Prefix LSA */
- new->instance = ospf_ext_schedule_prefix_index(ifp, new->sid,
- &new->nhlfe.prefv4, new->flags);
+ new->instance = ospf_ext_schedule_prefix_index(
+ ifp, new->sid, &new->nhlfe.prefv4, new->flags);
if (new->instance == 0) {
vty_out(vty, "Unable to set index %u for prefix %s/%u\n", index,
inet_ntoa(p.u.prefix4), p.prefixlen);
bool found = false;
int rc;
+ if (!ospf_sr_enabled(vty))
+ return CMD_WARNING_CONFIG_FAILED;
+
/* Get network prefix */
argv_find(argv, argc, "A.B.C.D/M", &idx);
rc = str2prefix(argv[idx]->arg, &p);
if (!rc) {
- vty_out(vty, "Invalid prefix format %s\n",
- argv[idx]->arg);
+ vty_out(vty, "Invalid prefix format %s\n", argv[idx]->arg);
return CMD_WARNING_CONFIG_FAILED;
}
}
if (IS_DEBUG_OSPF_SR)
- zlog_debug(
- "SR (%s): Remove Prefix %s/%u with index %u",
- __func__, inet_ntoa(srp->nhlfe.prefv4.prefix),
- srp->nhlfe.prefv4.prefixlen, srp->sid);
+ zlog_debug("SR (%s): Remove Prefix %s/%u with index %u",
+ __func__, inet_ntoa(srp->nhlfe.prefv4.prefix),
+ srp->nhlfe.prefv4.prefixlen, srp->sid);
/* Delete NHLFE is NO-PHP is set */
if (CHECK_FLAG(srp->flags, EXT_SUBTLV_PREFIX_SID_NPFLG))
}
-
static void show_sr_node(struct vty *vty, struct json_object *json,
- struct sr_node *srn)
+ struct sr_node *srn)
{
struct listnode *node;
if (json) {
json_node = json_object_new_object();
json_object_string_add(json_node, "routerID",
- inet_ntoa(srn->adv_router));
+ inet_ntoa(srn->adv_router));
json_object_int_add(json_node, "srgbSize",
- srn->srgb.range_size);
+ srn->srgb.range_size);
json_object_int_add(json_node, "srgbLabel",
- srn->srgb.lower_bound);
+ srn->srgb.lower_bound);
json_algo = json_object_new_array();
json_object_object_add(json_node, "algorithms", json_algo);
for (int i = 0; i < ALGORITHM_COUNT; i++) {
snprintf(tmp, 2, "%u", i);
json_object_string_add(json_obj, tmp,
- srn->algo[i] == SR_ALGORITHM_SPF ?
- "SPF" : "S-SPF");
+ srn->algo[i] == SR_ALGORITHM_SPF
+ ? "SPF"
+ : "S-SPF");
json_object_array_add(json_algo, json_obj);
}
if (srn->msd != 0)
json_object_int_add(json_node, "nodeMsd", srn->msd);
} else {
vty_out(vty, "SR-Node: %s", inet_ntoa(srn->adv_router));
- vty_out(vty, "\tSRGB (Size/Label): %u/%u",
- srn->srgb.range_size, srn->srgb.lower_bound);
+ vty_out(vty, "\tSRGB (Size/Label): %u/%u", srn->srgb.range_size,
+ srn->srgb.lower_bound);
vty_out(vty, "\tAlgorithm(s): %s",
srn->algo[0] == SR_ALGORITHM_SPF ? "SPF" : "S-SPF");
for (int i = 1; i < ALGORITHM_COUNT; i++) {
if (srn->algo[i] == SR_ALGORITHM_UNSET)
continue;
vty_out(vty, "/%s",
- srn->algo[i] == SR_ALGORITHM_SPF ?
- "SPF" : "S-SPF");
+ srn->algo[i] == SR_ALGORITHM_SPF ? "SPF"
+ : "S-SPF");
}
if (srn->msd != 0)
vty_out(vty, "\tMSD: %u", srn->msd);
"--------------------- --------- ---------------\n");
}
for (ALL_LIST_ELEMENTS_RO(srn->ext_prefix, node, srp)) {
- snprintf(pref, 19, "%s/%u",
- inet_ntoa(srp->nhlfe.prefv4.prefix),
- srp->nhlfe.prefv4.prefixlen);
+ snprintf(pref, 19, "%s/%u", inet_ntoa(srp->nhlfe.prefv4.prefix),
+ srp->nhlfe.prefv4.prefixlen);
snprintf(sid, 22, "SR Pfx (idx %u)", srp->sid);
if (srp->nhlfe.label_out == MPLS_LABEL_IMPLICIT_NULL)
sprintf(label, "pop");
if (!json_prefix) {
json_prefix = json_object_new_array();
json_object_object_add(json_node,
- "extendedPrefix", json_prefix);
+ "extendedPrefix",
+ json_prefix);
}
json_obj = json_object_new_object();
json_object_string_add(json_obj, "prefix", pref);
json_object_int_add(json_obj, "sid", srp->sid);
json_object_int_add(json_obj, "inputLabel",
- srp->nhlfe.label_in);
- json_object_string_add(json_obj, "outputLabel",
- label);
+ srp->nhlfe.label_in);
+ json_object_string_add(json_obj, "outputLabel", label);
json_object_string_add(json_obj, "interface",
- itf ? itf->name : "-");
+ itf ? itf->name : "-");
json_object_string_add(json_obj, "nexthop",
- inet_ntoa(srp->nhlfe.nexthop));
+ inet_ntoa(srp->nhlfe.nexthop));
json_object_array_add(json_prefix, json_obj);
} else {
- vty_out(vty, "%18s %8u %9s %21s %9s %15s\n",
- pref, srp->nhlfe.label_in, label,
- sid, itf ? itf->name : "-",
+ vty_out(vty, "%18s %8u %9s %21s %9s %15s\n", pref,
+ srp->nhlfe.label_in, label, sid,
+ itf ? itf->name : "-",
inet_ntoa(srp->nhlfe.nexthop));
}
}
for (ALL_LIST_ELEMENTS_RO(srn->ext_link, node, srl)) {
snprintf(pref, 19, "%s/%u",
- inet_ntoa(srl->nhlfe[0].prefv4.prefix),
- srl->nhlfe[0].prefv4.prefixlen);
+ inet_ntoa(srl->nhlfe[0].prefv4.prefix),
+ srl->nhlfe[0].prefv4.prefixlen);
snprintf(sid, 22, "SR Adj. (lbl %u)", srl->sid[0]);
if (srl->nhlfe[0].label_out == MPLS_LABEL_IMPLICIT_NULL)
sprintf(label, "pop");
if (json) {
if (!json_link) {
json_link = json_object_new_array();
- json_object_object_add(json_node,
- "extendedLink", json_link);
+ json_object_object_add(
+ json_node, "extendedLink", json_link);
}
/* Primary Link */
json_obj = json_object_new_object();
json_object_string_add(json_obj, "prefix", pref);
json_object_int_add(json_obj, "sid", srl->sid[0]);
json_object_int_add(json_obj, "inputLabel",
- srl->nhlfe[0].label_in);
- json_object_string_add(json_obj, "outputLabel",
- label);
+ srl->nhlfe[0].label_in);
+ json_object_string_add(json_obj, "outputLabel", label);
json_object_string_add(json_obj, "interface",
- itf ? itf->name : "-");
- json_object_string_add(json_obj, "nexthop",
+ itf ? itf->name : "-");
+ json_object_string_add(
+ json_obj, "nexthop",
inet_ntoa(srl->nhlfe[0].nexthop));
json_object_array_add(json_link, json_obj);
/* Backup Link */
json_object_string_add(json_obj, "prefix", pref);
json_object_int_add(json_obj, "sid", srl->sid[1]);
json_object_int_add(json_obj, "inputLabel",
- srl->nhlfe[1].label_in);
- json_object_string_add(json_obj, "outputLabel",
- label);
+ srl->nhlfe[1].label_in);
+ json_object_string_add(json_obj, "outputLabel", label);
json_object_string_add(json_obj, "interface",
- itf ? itf->name : "-");
- json_object_string_add(json_obj, "nexthop",
+ itf ? itf->name : "-");
+ json_object_string_add(
+ json_obj, "nexthop",
inet_ntoa(srl->nhlfe[1].nexthop));
json_object_array_add(json_link, json_obj);
} else {
- vty_out(vty, "%18s %8u %9s %21s %9s %15s\n",
- pref, srl->nhlfe[0].label_in,
- label, sid, itf ? itf->name : "-",
+ vty_out(vty, "%18s %8u %9s %21s %9s %15s\n", pref,
+ srl->nhlfe[0].label_in, label, sid,
+ itf ? itf->name : "-",
inet_ntoa(srl->nhlfe[0].nexthop));
snprintf(sid, 22, "SR Adj. (lbl %u)", srl->sid[1]);
if (srl->nhlfe[1].label_out == MPLS_LABEL_IMPLICIT_NULL)
sprintf(label, "pop");
else
sprintf(label, "%u", srl->nhlfe[1].label_out);
- vty_out(vty, "%18s %8u %9s %21s %9s %15s\n",
- pref, srl->nhlfe[1].label_in,
- label, sid, itf ? itf->name : "-",
+ vty_out(vty, "%18s %8u %9s %21s %9s %15s\n", pref,
+ srl->nhlfe[1].label_in, label, sid,
+ itf ? itf->name : "-",
inet_ntoa(srl->nhlfe[1].nexthop));
}
}
int idx = 0;
struct in_addr rid;
struct sr_node *srn;
- u_char uj = use_json(argc, argv);
+ bool uj = use_json(argc, argv);
json_object *json = NULL, *json_node_array = NULL;
if (!OspfSR.enabled) {
json = json_object_new_object();
json_node_array = json_object_new_array();
json_object_string_add(json, "srdbID",
- inet_ntoa(OspfSR.self->adv_router));
+ inet_ntoa(OspfSR.self->adv_router));
json_object_object_add(json, "srNodes", json_node_array);
} else {
vty_out(vty,
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_to_json_string_ext(
+ json, JSON_C_TO_STRING_PRETTY));
json_object_free(json);
}
return CMD_SUCCESS;
if (argv_find(argv, argc, "A.B.C.D", &idx)) {
if (!inet_aton(argv[idx]->arg, &rid)) {
- vty_out(vty,
- "Specified Router ID %s is invalid\n",
+ vty_out(vty, "Specified Router ID %s is invalid\n",
argv[idx]->arg);
return CMD_WARNING_CONFIG_FAILED;
}
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_to_json_string_ext(
+ json, JSON_C_TO_STRING_PRETTY));
json_object_free(json);
}
return CMD_SUCCESS;
/* No parameters have been provided, Iterate through all the SRDB */
if (uj) {
- hash_iterate(
- OspfSR.neighbors,
- (void (*)(struct hash_backet *, 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));
+ hash_iterate(OspfSR.neighbors, (void (*)(struct hash_backet *,
+ 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);
} else {
- hash_iterate(
- OspfSR.neighbors,
- (void (*)(struct hash_backet *, void *))show_vty_srdb,
- (void *)vty);
+ hash_iterate(OspfSR.neighbors, (void (*)(struct hash_backet *,
+ void *))show_vty_srdb,
+ (void *)vty);
}
return CMD_SUCCESS;
}
install_element(OSPF_NODE, &no_sr_node_msd_cmd);
install_element(OSPF_NODE, &sr_prefix_sid_cmd);
install_element(OSPF_NODE, &no_sr_prefix_sid_cmd);
-
}