]> git.proxmox.com Git - mirror_frr.git/blobdiff - ospfd/ospf_ext.c
Merge pull request #7155 from donaldsharp/TRAP
[mirror_frr.git] / ospfd / ospf_ext.c
index 1543e2015dd122f3ff9feb224ddc07d620d2d91b..90dc108c0ed7c8b373d9165127ac128147e434c0 100644 (file)
@@ -98,6 +98,7 @@ static void ospf_ext_link_lsa_schedule(struct ext_itf *exti,
 static void ospf_ext_lsa_schedule(struct ext_itf *exti, enum lsa_opcode op);
 static int ospf_ext_link_lsa_update(struct ospf_lsa *lsa);
 static int ospf_ext_pref_lsa_update(struct ospf_lsa *lsa);
+static void ospf_ext_link_delete_adj_sid(struct ext_itf *exti);
 static void del_ext_info(void *val);
 
 /*
@@ -434,6 +435,20 @@ static void set_lan_adj_sid(struct ext_itf *exti, bool backup, uint32_t value,
        exti->lan_sid[index].neighbor_id = neighbor_id;
 }
 
+static void unset_adjacency_sid(struct ext_itf *exti)
+{
+       /* Reset Adjacency TLV */
+       if (exti->type == ADJ_SID) {
+               TLV_TYPE(exti->adj_sid[0]) = 0;
+               TLV_TYPE(exti->adj_sid[1]) = 0;
+       }
+       /* or Lan-Adjacency TLV */
+       if (exti->type == LAN_ADJ_SID) {
+               TLV_TYPE(exti->lan_sid[0]) = 0;
+               TLV_TYPE(exti->lan_sid[1]) = 0;
+       }
+}
+
 /* Experimental SubTLV from Cisco */
 static void set_rmt_itf_addr(struct ext_itf *exti, struct in_addr rmtif)
 {
@@ -443,6 +458,34 @@ static void set_rmt_itf_addr(struct ext_itf *exti, struct in_addr rmtif)
        exti->rmt_itf_addr.value = rmtif;
 }
 
+/* Delete Extended LSA */
+static void ospf_extended_lsa_delete(struct ext_itf *exti)
+{
+
+       /* Process only Active Extended Prefix/Link LSA */
+       if (!CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ACTIVE))
+               return;
+
+       osr_debug("EXT (%s): Disable %s%s%s-SID on interface %s", __func__,
+                 exti->stype == LOCAL_SID ? "Prefix" : "",
+                 exti->stype == ADJ_SID ? "Adjacency" : "",
+                 exti->stype == LAN_ADJ_SID ? "LAN-Adjacency" : "",
+                 exti->ifp->name);
+
+       /* Flush LSA if already engaged */
+       if (CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ENGAGED)) {
+               ospf_ext_lsa_schedule(exti, FLUSH_THIS_LSA);
+               UNSET_FLAG(exti->flags, EXT_LPFLG_LSA_ENGAGED);
+       }
+
+       /* De-activate this Extended Prefix/Link and remove corresponding
+        * Segment-Routing Prefix-SID or (LAN)-ADJ-SID */
+       if (exti->stype == ADJ_SID || exti->stype == LAN_ADJ_SID)
+               ospf_ext_link_delete_adj_sid(exti);
+       else
+               ospf_sr_ext_itf_delete(exti);
+}
+
 /*
  * Update Extended prefix SID index for Loopback interface type
  *
@@ -465,12 +508,7 @@ uint32_t ospf_ext_schedule_prefix_index(struct interface *ifp, uint32_t index,
                return rc;
 
        if (p != NULL) {
-               if (IS_DEBUG_OSPF_SR)
-                       zlog_debug(
-                               "EXT (%s): Schedule new prefix %s/%u with "
-                               "index %u on interface %s",
-                               __func__, inet_ntoa(p->prefix), p->prefixlen,
-                               index, ifp->name);
+               osr_debug("EXT (%s): Schedule new prefix %pFX with index %u on interface %s", __func__, p, index, ifp->name);
 
                /* Set first Extended Prefix then the Prefix SID information */
                set_ext_prefix(exti, OSPF_PATH_INTRA_AREA, EXT_TLV_PREF_NFLG,
@@ -478,7 +516,6 @@ uint32_t ospf_ext_schedule_prefix_index(struct interface *ifp, uint32_t index,
                set_prefix_sid(exti, SR_ALGORITHM_SPF, index, SID_INDEX, flags);
 
                /* Try to Schedule LSA */
-               // SET_FLAG(exti->flags, EXT_LPFLG_LSA_ACTIVE);
                if (CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ACTIVE)) {
                        if (CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ENGAGED))
                                ospf_ext_pref_lsa_schedule(exti,
@@ -488,19 +525,107 @@ uint32_t ospf_ext_schedule_prefix_index(struct interface *ifp, uint32_t index,
                                        exti, REORIGINATE_THIS_LSA);
                }
        } else {
-               if (IS_DEBUG_OSPF_SR)
-                       zlog_debug("EXT (%s): Remove prefix for interface %s",
-                                  __func__, ifp->name);
+               osr_debug("EXT (%s): Remove prefix for interface %s", __func__,
+                         ifp->name);
 
-               if (CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ENGAGED)) {
+               if (CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ENGAGED))
                        ospf_ext_pref_lsa_schedule(exti, FLUSH_THIS_LSA);
-                       exti->flags = EXT_LPFLG_LSA_INACTIVE;
-               }
        }
 
        return SET_OPAQUE_LSID(exti->type, exti->instance);
 }
 
+/**
+ * Update Adjacecny-SID for Extended Link LSA
+ *
+ * @param exti Extended Link information
+ */
+static void ospf_ext_link_update_adj_sid(struct ext_itf *exti)
+{
+       mpls_label_t label;
+       mpls_label_t bck_label;
+
+       /* Process only (LAN)Adjacency-SID Type */
+       if (exti->stype != ADJ_SID && exti->stype != LAN_ADJ_SID)
+               return;
+
+       /* Request Primary & Backup Labels from Label Manager */
+       bck_label = ospf_sr_local_block_request_label();
+       label = ospf_sr_local_block_request_label();
+       if (bck_label == MPLS_INVALID_LABEL || label == MPLS_INVALID_LABEL) {
+               if (CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ENGAGED))
+                       ospf_ext_lsa_schedule(exti, FLUSH_THIS_LSA);
+               return;
+       }
+
+       /* Set Adjacency-SID, backup first */
+       if (exti->stype == ADJ_SID) {
+               set_adj_sid(exti, true, bck_label, SID_LABEL);
+               set_adj_sid(exti, false, label, SID_LABEL);
+       } else {
+               set_lan_adj_sid(exti, true, bck_label, SID_LABEL,
+                               exti->lan_sid[0].neighbor_id);
+               set_lan_adj_sid(exti, false, label, SID_LABEL,
+                               exti->lan_sid[1].neighbor_id);
+       }
+
+       /* Finally, add corresponding SR Link in SRDB & MPLS LFIB */
+       SET_FLAG(exti->flags, EXT_LPFLG_FIB_ENTRY_SET);
+       ospf_sr_ext_itf_add(exti);
+}
+
+/**
+ * Delete Adjacecny-SID for Extended Link LSA
+ *
+ * @param exti Extended Link information
+ */
+static void ospf_ext_link_delete_adj_sid(struct ext_itf *exti)
+{
+       /* Process only (LAN)Adjacency-SID Type */
+       if (exti->stype != ADJ_SID && exti->stype != LAN_ADJ_SID)
+               return;
+
+       /* Release Primary & Backup Labels from Label Manager */
+       if (exti->stype == ADJ_SID) {
+               ospf_sr_local_block_release_label(exti->adj_sid[0].value);
+               ospf_sr_local_block_release_label(exti->adj_sid[1].value);
+       } else {
+               ospf_sr_local_block_release_label(exti->lan_sid[0].value);
+               ospf_sr_local_block_release_label(exti->lan_sid[1].value);
+       }
+       /* And reset corresponding TLV */
+       unset_adjacency_sid(exti);
+
+       /* Finally, remove corresponding SR Link in SRDB & MPLS LFIB */
+       UNSET_FLAG(exti->flags, EXT_LPFLG_FIB_ENTRY_SET);
+       ospf_sr_ext_itf_delete(exti);
+}
+
+/**
+ * Update Extended Link LSA once Segment Routing Label Block has been changed.
+ */
+void ospf_ext_link_srlb_update(void)
+{
+       struct listnode *node;
+       struct ext_itf *exti;
+
+
+       osr_debug("EXT (%s): Update Extended Links with new SRLB", __func__);
+
+       /* Update all Extended Link Adjaceny-SID  */
+       for (ALL_LIST_ELEMENTS_RO(OspfEXT.iflist, node, exti)) {
+               /* Skip Extended Prefix */
+               if (exti->stype == PREF_SID || exti->stype == LOCAL_SID)
+                       continue;
+
+               /* Skip inactive Extended Link */
+               if (!CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ACTIVE))
+                       continue;
+
+               ospf_ext_link_update_adj_sid(exti);
+       }
+}
+
 /*
  * Used by Segment Routing to activate/deactivate Extended Link/Prefix flooding
  *
@@ -513,18 +638,23 @@ void ospf_ext_update_sr(bool enable)
        struct listnode *node;
        struct ext_itf *exti;
 
-       if (IS_DEBUG_OSPF_SR)
-               zlog_debug("EXT (%s): %s Extended LSAs for Segment Routing ",
-                          __func__, enable ? "Enable" : "Disable");
+       osr_debug("EXT (%s): %s Extended LSAs for Segment Routing ", __func__,
+                 enable ? "Enable" : "Disable");
 
        if (enable) {
                OspfEXT.enabled = true;
 
                /* Refresh LSAs if already engaged or originate */
                for (ALL_LIST_ELEMENTS_RO(OspfEXT.iflist, node, exti)) {
+                       /* Skip Inactive Extended Link */
                        if (!CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ACTIVE))
                                continue;
 
+                       /* Update Extended Link (LAN)Adj-SID if not set  */
+                       if (!CHECK_FLAG(exti->flags, EXT_LPFLG_FIB_ENTRY_SET))
+                               ospf_ext_link_update_adj_sid(exti);
+
+                       /* Finally, flood the extended Link */
                        if (CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ENGAGED))
                                ospf_ext_lsa_schedule(exti, REFRESH_THIS_LSA);
                        else
@@ -532,17 +662,15 @@ void ospf_ext_update_sr(bool enable)
                                                      REORIGINATE_THIS_LSA);
                }
        } else {
-               /* Start by Flushing engaged LSAs */
-               for (ALL_LIST_ELEMENTS_RO(OspfEXT.iflist, node, exti)) {
-                       if (CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ENGAGED))
-                               ospf_ext_lsa_schedule(exti, FLUSH_THIS_LSA);
-                       exti->flags = EXT_LPFLG_LSA_INACTIVE;
-               }
+               /* Start by Removing Extended LSA */
+               for (ALL_LIST_ELEMENTS_RO(OspfEXT.iflist, node, exti))
+                       ospf_extended_lsa_delete(exti);
 
                /* And then disable Extended Link/Prefix */
                OspfEXT.enabled = false;
        }
 }
+
 /*
  * -----------------------------------------------------------------------
  * Followings are callback functions against generic Opaque-LSAs handling
@@ -580,10 +708,11 @@ static int ospf_ext_link_del_if(struct interface *ifp)
 
        exti = lookup_ext_by_ifp(ifp);
        if (exti != NULL) {
-               struct list *iflist = OspfEXT.iflist;
+               /* Flush LSA and remove Adjacency SID */
+               ospf_extended_lsa_delete(exti);
 
                /* Dequeue listnode entry from the list. */
-               listnode_delete(iflist, exti);
+               listnode_delete(OspfEXT.iflist, exti);
 
                XFREE(MTYPE_OSPF_EXT_PARAMS, exti);
 
@@ -616,6 +745,7 @@ static void ospf_ext_ism_change(struct ospf_interface *oi, int old_status)
 
        /* Reset Extended information if ospf interface goes Down */
        if (oi->state == ISM_Down) {
+               ospf_extended_lsa_delete(exti);
                exti->area = NULL;
                exti->flags = EXT_LPFLG_LSA_INACTIVE;
                return;
@@ -629,12 +759,12 @@ static void ospf_ext_ism_change(struct ospf_interface *oi, int old_status)
                exti->instance = get_ext_pref_instance_value();
                exti->area = oi->area;
 
-               zlog_debug("EXT (%s): Set Prefix SID to interface %s ",
-                          __func__, oi->ifp->name);
+               osr_debug("EXT (%s): Set Prefix SID to interface %s ",
+                         __func__, oi->ifp->name);
 
                /* Complete SRDB if the interface belongs to a Prefix */
                if (OspfEXT.enabled)
-                       ospf_sr_update_prefix(oi->ifp, oi->address);
+                       ospf_sr_update_local_prefix(oi->ifp, oi->address);
        } else {
                /* Determine if interface is related to Adj. or LAN Adj. SID */
                if (oi->state == ISM_DR)
@@ -650,9 +780,9 @@ static void ospf_ext_ism_change(struct ospf_interface *oi, int old_status)
                 * Note: Adjacency SID information are completed when ospf
                 * adjacency become up see ospf_ext_link_nsm_change()
                 */
-               zlog_debug("EXT (%s): Set %sAdjacency SID for interface %s ",
-                          __func__, exti->stype == ADJ_SID ? "" : "LAN-",
-                          oi->ifp->name);
+               osr_debug("EXT (%s): Set %sAdjacency SID for interface %s ",
+                         __func__, exti->stype == ADJ_SID ? "" : "LAN-",
+                         oi->ifp->name);
        }
 }
 
@@ -664,10 +794,9 @@ static void ospf_ext_link_nsm_change(struct ospf_neighbor *nbr, int old_status)
 {
        struct ospf_interface *oi = nbr->oi;
        struct ext_itf *exti;
-       uint32_t label;
 
-       /* Process Neighbor only when its state is NSM Full */
-       if (nbr->state != NSM_Full)
+       /* Process Link only when neighbor old or new state is NSM Full */
+       if (nbr->state != NSM_Full && old_status != NSM_Full)
                return;
 
        /* Get interface information for Segment Routing */
@@ -679,6 +808,26 @@ static void ospf_ext_link_nsm_change(struct ospf_neighbor *nbr, int old_status)
                return;
        }
 
+       /* Check that we have a valid area and ospf context */
+       if (oi->area == NULL || oi->area->ospf == NULL) {
+               flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED,
+                         "EXT (%s): Cannot refer to OSPF from OI(%s)",
+                         __func__, IF_NAME(oi));
+               return;
+       }
+
+       /* Remove Extended Link if Neighbor State goes Down or Deleted */
+       if (nbr->state == NSM_Down || nbr->state == NSM_Deleted) {
+               ospf_ext_link_delete_adj_sid(exti);
+               if (CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ENGAGED))
+                       ospf_ext_link_lsa_schedule(exti, FLUSH_THIS_LSA);
+               exti->flags = EXT_LPFLG_LSA_INACTIVE;
+               return;
+       }
+
+       /* Keep Area information in combination with SR info. */
+       exti->area = oi->area;
+
        /* Process only Adjacency/LAN SID */
        if (exti->stype == PREF_SID)
                return;
@@ -692,11 +841,6 @@ static void ospf_ext_link_nsm_change(struct ospf_neighbor *nbr, int old_status)
                set_ext_link(exti, OSPF_IFTYPE_POINTOPOINT, nbr->router_id,
                             oi->address->u.prefix4);
 
-               /* Set Extended Link Adjacency SubTLVs, backup first */
-               label = get_ext_link_label_value();
-               set_adj_sid(exti, true, label, SID_LABEL);
-               label = get_ext_link_label_value();
-               set_adj_sid(exti, false, label, SID_LABEL);
                /* And Remote Interface address */
                set_rmt_itf_addr(exti, nbr->address.u.prefix4);
 
@@ -710,11 +854,9 @@ static void ospf_ext_link_nsm_change(struct ospf_neighbor *nbr, int old_status)
                set_ext_link(exti, OSPF_IFTYPE_BROADCAST, DR(oi),
                             oi->address->u.prefix4);
 
-               /* Set Extended Link Adjacency SubTLVs, backup first */
-               label = get_ext_link_label_value();
-               set_lan_adj_sid(exti, true, label, SID_LABEL, nbr->router_id);
-               label = get_ext_link_label_value();
-               set_lan_adj_sid(exti, false, label, SID_LABEL, nbr->router_id);
+               /* Set Neighbor ID */
+               exti->lan_sid[0].neighbor_id = nbr->router_id;
+               exti->lan_sid[1].neighbor_id = nbr->router_id;
 
                break;
 
@@ -727,30 +869,28 @@ static void ospf_ext_link_nsm_change(struct ospf_neighbor *nbr, int old_status)
                set_ext_link(exti, OSPF_IFTYPE_BROADCAST, DR(oi),
                             oi->address->u.prefix4);
 
-               /* Set Extended Link Adjacency SubTLVs, backup first */
-               label = get_ext_link_label_value();
-               set_adj_sid(exti, true, label, SID_LABEL);
-               label = get_ext_link_label_value();
-               set_adj_sid(exti, false, label, SID_LABEL);
-
                break;
 
        default:
+               if (CHECK_FLAG(exti->flags, EXT_LPFLG_FIB_ENTRY_SET))
+                       ospf_ext_link_delete_adj_sid(exti);
                if (CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ENGAGED))
                        ospf_ext_link_lsa_schedule(exti, FLUSH_THIS_LSA);
                exti->flags = EXT_LPFLG_LSA_INACTIVE;
                return;
        }
 
-       if (IS_DEBUG_OSPF_SR)
-               zlog_debug(
-                       "EXT (%s): Complete %sAdjacency SID for interface %s ",
-                       __func__, exti->stype == ADJ_SID ? "" : "LAN-",
-                       oi->ifp->name);
-
-       /* flood this links params if everything is ok */
        SET_FLAG(exti->flags, EXT_LPFLG_LSA_ACTIVE);
+
        if (OspfEXT.enabled) {
+               osr_debug("EXT (%s): Set %sAdjacency SID for interface %s ",
+                         __func__, exti->stype == ADJ_SID ? "" : "LAN-",
+                         oi->ifp->name);
+
+               /* Update (LAN)Adjacency SID */
+               ospf_ext_link_update_adj_sid(exti);
+
+               /* flood this links params if everything is ok */
                if (CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ENGAGED))
                        ospf_ext_link_lsa_schedule(exti, REFRESH_THIS_LSA);
                else
@@ -778,6 +918,10 @@ static int ospf_ext_link_lsa_update(struct ospf_lsa *lsa)
            != OPAQUE_TYPE_EXTENDED_LINK_LSA)
                return 0;
 
+       /* Check if it is not my LSA */
+       if (IS_LSA_SELF(lsa))
+               return 0;
+
        /* Check if Extended is enable */
        if (!OspfEXT.enabled)
                return 0;
@@ -962,12 +1106,9 @@ static struct ospf_lsa *ospf_ext_pref_lsa_new(struct ospf_area *area,
        /* Set opaque-LSA header fields. */
        lsa_header_set(s, options, lsa_type, lsa_id, router_id);
 
-       if (IS_DEBUG_OSPF(lsa, LSA_GENERATE))
-               zlog_debug(
-                       "EXT (%s): LSA[Type%u:%s]: Create an Opaque-LSA "
-                       "Extended Prefix Opaque LSA instance",
-                       __func__, lsa_type, inet_ntoa(lsa_id));
-
+       osr_debug(
+               "EXT (%s): LSA[Type%u:%pI4]: Create an Opaque-LSA Extended Prefix Opaque LSA instance",
+               __func__, lsa_type, &lsa_id);
 
        /* Set opaque-LSA body fields. */
        ospf_ext_pref_lsa_body_set(s, exti);
@@ -1022,11 +1163,9 @@ static struct ospf_lsa *ospf_ext_link_lsa_new(struct ospf_area *area,
        tmp = SET_OPAQUE_LSID(OPAQUE_TYPE_EXTENDED_LINK_LSA, exti->instance);
        lsa_id.s_addr = htonl(tmp);
 
-       if (IS_DEBUG_OSPF(lsa, LSA_GENERATE))
-               zlog_debug(
-                       "EXT (%s) LSA[Type%u:%s]: Create an Opaque-LSA "
-                       "Extended Link Opaque LSA instance",
-                       __func__, lsa_type, inet_ntoa(lsa_id));
+       osr_debug(
+               "EXT (%s) LSA[Type%u:%pI4]: Create an Opaque-LSA Extended Link Opaque LSA instance",
+               __func__, lsa_type, &lsa_id);
 
        /* Set opaque-LSA header fields. */
        lsa_header_set(s, options, lsa_type, lsa_id, area->ospf->router_id);
@@ -1089,17 +1228,12 @@ static int ospf_ext_pref_lsa_originate1(struct ospf_area *area,
        /* Flood new LSA through area. */
        ospf_flood_through_area(area, NULL /*nbr */, new);
 
-       if (IS_DEBUG_OSPF(lsa, LSA_GENERATE)) {
-               char area_id[INET_ADDRSTRLEN];
-
-               inet_ntop(AF_INET, &area->area_id, area_id, sizeof(area_id));
-               zlog_debug(
-                       "EXT (%s): LSA[Type%u:%s]: Originate Opaque-LSA "
-                       "Extended Prefix Opaque LSA: Area(%s), Link(%s)",
-                       __func__, new->data->type, inet_ntoa(new->data->id),
-                       area_id, exti->ifp->name);
+       osr_debug(
+               "EXT (%s): LSA[Type%u:%pI4]: Originate Opaque-LSAExtended Prefix Opaque LSA: Area(%pI4), Link(%s)",
+               __func__, new->data->type, &new->data->id,
+               &area->area_id, exti->ifp->name);
+       if (IS_DEBUG_OSPF(lsa, LSA_GENERATE))
                ospf_lsa_header_dump(new->data);
-       }
 
        rc = 0;
 
@@ -1141,17 +1275,12 @@ static int ospf_ext_link_lsa_originate1(struct ospf_area *area,
        /* Flood new LSA through area. */
        ospf_flood_through_area(area, NULL /*nbr */, new);
 
-       if (IS_DEBUG_OSPF(lsa, LSA_GENERATE)) {
-               char area_id[INET_ADDRSTRLEN];
-
-               inet_ntop(AF_INET, &area->area_id, area_id, sizeof(area_id));
-               zlog_debug(
-                       "EXT (%s): LSA[Type%u:%s]: Originate Opaque-LSA "
-                       "Extended Link Opaque LSA: Area(%s), Link(%s)",
-                       __func__, new->data->type, inet_ntoa(new->data->id),
-                       area_id, exti->ifp->name);
+       osr_debug(
+               "EXT (%s): LSA[Type%u:%pI4]: Originate Opaque-LSA Extended Link Opaque LSA: Area(%pI4), Link(%s)",
+               __func__, new->data->type, &new->data->id,
+               &area->area_id, exti->ifp->name);
+       if (IS_DEBUG_OSPF(lsa, LSA_GENERATE))
                ospf_lsa_header_dump(new->data);
-       }
 
        rc = 0;
 
@@ -1168,15 +1297,13 @@ static int ospf_ext_pref_lsa_originate(void *arg)
 
        if (!OspfEXT.enabled) {
                zlog_info(
-                       "EXT (%s): Segment Routing "
-                       "functionality is Disabled now",
+                       "EXT (%s): Segment Routing functionality is Disabled now",
                        __func__);
                rc = 0; /* This is not an error case. */
                return rc;
        }
-       if (IS_DEBUG_OSPF_SR)
-               zlog_debug("EXT (%s): Start Originate Prefix LSA for area %s",
-                          __func__, inet_ntoa(area->area_id));
+       osr_debug("EXT (%s): Start Originate Prefix LSA for area %pI4",
+                 __func__, &area->area_id);
 
        /* Check if Extended Prefix Opaque LSA is already engaged */
        for (ALL_LIST_ELEMENTS_RO(OspfEXT.iflist, node, exti)) {
@@ -1206,12 +1333,9 @@ static int ospf_ext_pref_lsa_originate(void *arg)
                }
 
                /* Ok, let's try to originate an LSA */
-               if (IS_DEBUG_OSPF_SR)
-                       zlog_debug(
-                               "EXT (%s): Let's finally reoriginate the "
-                               "LSA 7.0.0.%u for Itf %s",
-                               __func__, exti->instance,
-                               exti->ifp ? exti->ifp->name : "");
+               osr_debug(
+                       "EXT (%s): Let's finally re-originate the LSA 7.0.0.%u for Itf %s", __func__, exti->instance,
+                       exti->ifp ? exti->ifp->name : "");
                ospf_ext_pref_lsa_originate1(area, exti);
        }
 
@@ -1229,8 +1353,7 @@ static int ospf_ext_link_lsa_originate(void *arg)
 
        if (!OspfEXT.enabled) {
                zlog_info(
-                       "EXT (%s): Segment Routing "
-                       "functionality is Disabled now",
+                       "EXT (%s): Segment Routing functionality is Disabled now",
                        __func__);
                rc = 0; /* This is not an error case. */
                return rc;
@@ -1242,15 +1365,15 @@ static int ospf_ext_link_lsa_originate(void *arg)
                if (exti->stype == PREF_SID)
                        continue;
 
+               /* Skip Inactive Extended Link */
+               if (!CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ACTIVE))
+                       continue;
+
                /* Process only Extended Link with valid Area ID */
                if ((exti->area == NULL)
                    || (!IPV4_ADDR_SAME(&exti->area->area_id, &area->area_id)))
                        continue;
 
-               /* Skip Extended Link which are not Active */
-               if (!CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ACTIVE))
-                       continue;
-
                /* Check if LSA not already engaged */
                if (CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ENGAGED)) {
                        if (CHECK_FLAG(exti->flags,
@@ -1268,13 +1391,10 @@ static int ospf_ext_link_lsa_originate(void *arg)
                }
 
                /* Ok, let's try to originate an LSA */
-               if (IS_DEBUG_OSPF_SR)
-                       zlog_debug(
-                               "EXT (%s): Let's finally reoriginate the "
-                               "LSA 8.0.0.%u for Itf %s through the Area %s",
-                               __func__, exti->instance,
-                               exti->ifp ? exti->ifp->name : "-",
-                               inet_ntoa(area->area_id));
+               osr_debug(
+                       "EXT (%s): Let's finally reoriginate the LSA 8.0.0.%u for Itf %s through the Area %pI4", __func__,
+                       exti->instance, exti->ifp ? exti->ifp->name : "-",
+                       &area->area_id);
                ospf_ext_link_lsa_originate1(area, exti);
        }
 
@@ -1297,8 +1417,7 @@ static struct ospf_lsa *ospf_ext_pref_lsa_refresh(struct ospf_lsa *lsa)
                 * It seems a slip among routers in the routing domain.
                 */
                zlog_info(
-                       "EXT (%s): Segment Routing functionality is "
-                       "Disabled",
+                       "EXT (%s): Segment Routing functionality is Disabled",
                        __func__);
                /* Flush it anyway. */
                lsa->data->ls_age = htons(OSPF_LSA_MAXAGE);
@@ -1362,12 +1481,11 @@ static struct ospf_lsa *ospf_ext_pref_lsa_refresh(struct ospf_lsa *lsa)
        ospf_flood_through_area(area, NULL /*nbr */, new);
 
        /* Debug logging. */
-       if (IS_DEBUG_OSPF(lsa, LSA_GENERATE)) {
-               zlog_debug(
-                       "EXT (%s): LSA[Type%u:%s] Refresh Extended Prefix LSA",
-                       __func__, new->data->type, inet_ntoa(new->data->id));
+       osr_debug("EXT (%s): LSA[Type%u:%pI4] Refresh Extended Prefix LSA",
+                 __func__, new->data->type, &new->data->id);
+       if (IS_DEBUG_OSPF(lsa, LSA_GENERATE))
                ospf_lsa_header_dump(new->data);
-       }
+
 
        return new;
 }
@@ -1438,12 +1556,10 @@ static struct ospf_lsa *ospf_ext_link_lsa_refresh(struct ospf_lsa *lsa)
        ospf_flood_through_area(area, NULL /*nbr */, new);
 
        /* Debug logging. */
-       if (IS_DEBUG_OSPF(lsa, LSA_GENERATE)) {
-               zlog_debug(
-                       "EXT (%s): LSA[Type%u:%s]: Refresh Extended Link LSA",
-                       __func__, new->data->type, inet_ntoa(new->data->id));
+       osr_debug("EXT (%s): LSA[Type%u:%pI4]: Refresh Extended Link LSA",
+                 __func__, new->data->type, &new->data->id);
+       if (IS_DEBUG_OSPF(lsa, LSA_GENERATE))
                ospf_lsa_header_dump(new->data);
-       }
 
        return new;
 }
@@ -1468,18 +1584,17 @@ static void ospf_ext_pref_lsa_schedule(struct ext_itf *exti,
        if (!(CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ACTIVE)))
                return;
 
-       zlog_debug("EXT (%s): Schedule %s%s%s LSA for interface %s", __func__,
-                  opcode == REORIGINATE_THIS_LSA ? "Re-Originate" : "",
-                  opcode == REFRESH_THIS_LSA ? "Refresh" : "",
-                  opcode == FLUSH_THIS_LSA ? "Flush" : "",
-                  exti->ifp ? exti->ifp->name : "-");
+       osr_debug("EXT (%s): Schedule %s%s%s LSA for interface %s", __func__,
+                 opcode == REORIGINATE_THIS_LSA ? "Re-Originate" : "",
+                 opcode == REFRESH_THIS_LSA ? "Refresh" : "",
+                 opcode == FLUSH_THIS_LSA ? "Flush" : "",
+                 exti->ifp ? exti->ifp->name : "-");
 
        /* Verify Area */
        if (exti->area == NULL) {
-               if (IS_DEBUG_OSPF(lsa, LSA_GENERATE))
-                       zlog_debug(
-                               "EXT (%s): Area is not yet set. Try to use Backbone Area",
-                               __func__);
+               osr_debug(
+                       "EXT (%s): Area is not yet set. Try to use Backbone Area",
+                       __func__);
 
                top = ospf_lookup_by_vrf_id(VRF_DEFAULT);
                struct in_addr backbone = {.s_addr = INADDR_ANY};
@@ -1533,18 +1648,17 @@ static void ospf_ext_link_lsa_schedule(struct ext_itf *exti,
        if (!(CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ACTIVE)))
                return;
 
-       zlog_debug("EXT (%s): Schedule %s%s%s LSA for interface %s", __func__,
-                  opcode == REORIGINATE_THIS_LSA ? "Re-Originate" : "",
-                  opcode == REFRESH_THIS_LSA ? "Refresh" : "",
-                  opcode == FLUSH_THIS_LSA ? "Flush" : "",
-                  exti->ifp ? exti->ifp->name : "-");
+       osr_debug("EXT (%s): Schedule %s%s%s LSA for interface %s", __func__,
+                 opcode == REORIGINATE_THIS_LSA ? "Re-Originate" : "",
+                 opcode == REFRESH_THIS_LSA ? "Refresh" : "",
+                 opcode == FLUSH_THIS_LSA ? "Flush" : "",
+                 exti->ifp ? exti->ifp->name : "-");
 
        /* Verify Area */
        if (exti->area == NULL) {
-               if (IS_DEBUG_OSPF(lsa, LSA_GENERATE))
-                       zlog_debug(
-                               "EXT (%s): Area is not yet set. Try to use Backbone Area",
-                               __func__);
+               osr_debug(
+                       "EXT (%s): Area is not yet set. Try to use Backbone Area",
+                       __func__);
 
                top = ospf_lookup_by_vrf_id(VRF_DEFAULT);
                struct in_addr backbone = {.s_addr = INADDR_ANY};
@@ -1602,8 +1716,7 @@ static uint16_t show_vty_ext_link_rmt_itf_addr(struct vty *vty,
        top = (struct ext_subtlv_rmt_itf_addr *)tlvh;
 
        vty_out(vty,
-               "  Remote Interface Address Sub-TLV: Length %u\n        "
-               "Address: %s\n",
+               "  Remote Interface Address Sub-TLV: Length %u\n        Address: %s\n",
                ntohs(top->header.length), inet_ntoa(top->value));
 
        return TLV_SIZE(tlvh);
@@ -1616,8 +1729,7 @@ static uint16_t show_vty_ext_link_adj_sid(struct vty *vty,
        struct ext_subtlv_adj_sid *top = (struct ext_subtlv_adj_sid *)tlvh;
 
        vty_out(vty,
-               "  Adj-SID Sub-TLV: Length %u\n\tFlags: "
-               "0x%x\n\tMT-ID:0x%x\n\tWeight: 0x%x\n\t%s: %u\n",
+               "  Adj-SID Sub-TLV: Length %u\n\tFlags: 0x%x\n\tMT-ID:0x%x\n\tWeight: 0x%x\n\t%s: %u\n",
                ntohs(top->header.length), top->flags, top->mtid, top->weight,
                CHECK_FLAG(top->flags, EXT_SUBTLV_LINK_ADJ_SID_VFLG) ? "Label"
                                                                     : "Index",
@@ -1636,9 +1748,7 @@ static uint16_t show_vty_ext_link_lan_adj_sid(struct vty *vty,
                (struct ext_subtlv_lan_adj_sid *)tlvh;
 
        vty_out(vty,
-               "  LAN-Adj-SID Sub-TLV: Length %u\n\tFlags: "
-               "0x%x\n\tMT-ID:0x%x\n\tWeight: 0x%x\n\tNeighbor ID: "
-               "%s\n\t%s: %u\n",
+               "  LAN-Adj-SID Sub-TLV: Length %u\n\tFlags: 0x%x\n\tMT-ID:0x%x\n\tWeight: 0x%x\n\tNeighbor ID: %s\n\t%s: %u\n",
                ntohs(top->header.length), top->flags, top->mtid, top->weight,
                inet_ntoa(top->neighbor_id),
                CHECK_FLAG(top->flags, EXT_SUBTLV_LINK_ADJ_SID_VFLG) ? "Label"
@@ -1726,8 +1836,7 @@ static uint16_t show_vty_ext_pref_pref_sid(struct vty *vty,
                (struct ext_subtlv_prefix_sid *)tlvh;
 
        vty_out(vty,
-               "  Prefix SID Sub-TLV: Length %u\n\tAlgorithm: "
-               "%u\n\tFlags: 0x%x\n\tMT-ID:0x%x\n\t%s: %u\n",
+               "  Prefix SID Sub-TLV: Length %u\n\tAlgorithm: %u\n\tFlags: 0x%x\n\tMT-ID:0x%x\n\t%s: %u\n",
                ntohs(top->header.length), top->algorithm, top->flags,
                top->mtid,
                CHECK_FLAG(top->flags, EXT_SUBTLV_PREFIX_SID_VFLG) ? "Label"