]> git.proxmox.com Git - mirror_frr.git/blobdiff - ospfd/ospf_ext.c
lib: enforce vrf_name_to_id by returning default_vrf when name is null
[mirror_frr.git] / ospfd / ospf_ext.c
index f6ed9b81b964d04915f6f9b9f01e64e7998be741..df64fca883cdaf5577fea0e36bcef0d48ab1b59a 100644 (file)
@@ -62,6 +62,7 @@
 #include "ospfd/ospf_zebra.h"
 #include "ospfd/ospf_sr.h"
 #include "ospfd/ospf_ext.h"
+#include "ospfd/ospf_errors.h"
 
 /* Following structure are internal use only. */
 
@@ -136,7 +137,8 @@ int ospf_ext_init(void)
                NULL);                       /* del_lsa_hook */
 
        if (rc != 0) {
-               zlog_warn("EXT (%s): Failed to register Extended Link LSA",
+               flog_warn(EC_OSPF_OPAQUE_REGISTRATION,
+                         "EXT (%s): Failed to register Extended Link LSA",
                          __func__);
                return rc;
        }
@@ -157,7 +159,8 @@ int ospf_ext_init(void)
                ospf_ext_pref_lsa_update,    /* new_lsa_hook */
                NULL);                       /* del_lsa_hook */
        if (rc != 0) {
-               zlog_warn("EXT (%s): Failed to register Extended Prefix LSA",
+               flog_warn(EC_OSPF_OPAQUE_REGISTRATION,
+                         "EXT (%s): Failed to register Extended Prefix LSA",
                          __func__);
                return rc;
        }
@@ -174,19 +177,15 @@ int ospf_ext_init(void)
 void ospf_ext_term(void)
 {
 
-       if ((OspfEXT.scope != OSPF_OPAQUE_AREA_LSA)
-           && (OspfEXT.scope != OSPF_OPAQUE_AS_LSA))
-               zlog_warn(
-                       "EXT: Unable to unregister Extended Prefix "
-                       "Opaque LSA functions: Wrong scope!");
-       else
+       if ((OspfEXT.scope == OSPF_OPAQUE_AREA_LSA)
+           || (OspfEXT.scope == OSPF_OPAQUE_AS_LSA))
                ospf_delete_opaque_functab(OspfEXT.scope,
                                           OPAQUE_TYPE_EXTENDED_PREFIX_LSA);
 
        ospf_delete_opaque_functab(OSPF_OPAQUE_AREA_LSA,
                                   OPAQUE_TYPE_EXTENDED_LINK_LSA);
 
-       list_delete_and_null(&OspfEXT.iflist);
+       list_delete(&OspfEXT.iflist);
        OspfEXT.scope = 0;
        OspfEXT.enabled = false;
 
@@ -316,8 +315,9 @@ static void set_prefix_sid(struct ext_itf *exti, uint8_t algorithm,
 
        if ((algorithm != SR_ALGORITHM_SPF)
            && (algorithm != SR_ALGORITHM_STRICT_SPF)) {
-               zlog_warn("EXT (%s): unrecognized algorithm, not SPF or S-SPF",
-                         __func__);
+               flog_err(EC_OSPF_INVALID_ALGORITHM,
+                        "EXT (%s): unrecognized algorithm, not SPF or S-SPF",
+                        __func__);
                return;
        }
 
@@ -538,8 +538,6 @@ static int ospf_ext_link_new_if(struct interface *ifp)
        int rc = -1;
 
        if (lookup_ext_by_ifp(ifp) != NULL) {
-               zlog_warn("EXT (%s): interface %s is already in use", __func__,
-                         ifp ? ifp->name : "-");
                rc = 0; /* Do nothing here. */
                return rc;
        }
@@ -573,7 +571,8 @@ static int ospf_ext_link_del_if(struct interface *ifp)
 
                rc = 0;
        } else {
-               zlog_warn("EXT (%s): interface %s is not found", __func__,
+               flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED,
+                         "EXT (%s): interface %s is not found", __func__,
                          ifp ? ifp->name : "-");
        }
 
@@ -590,11 +589,8 @@ static void ospf_ext_link_ism_change(struct ospf_interface *oi, int old_status)
 
        /* Get interface information for Segment Routing */
        exti = lookup_ext_by_ifp(oi->ifp);
-       if (exti == NULL) {
-               zlog_warn("EXT (%s): Cannot get Extended info. from OI(%s)",
-                         __func__, IF_NAME(oi));
+       if (exti == NULL)
                return;
-       }
 
        /* Determine if interface is related to Adjacency or LAN Adj. SID */
        if (oi->type != OSPF_IFTYPE_LOOPBACK) {
@@ -623,7 +619,8 @@ static void ospf_ext_pref_ism_change(struct ospf_interface *oi, int old_status)
        /* Get interface information for Segment Routing */
        exti = lookup_ext_by_ifp(oi->ifp);
        if (exti == NULL) {
-               zlog_warn("EXT (%s): Cannot get Extended info. from OI(%s)",
+               flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED,
+                         "EXT (%s): Cannot get Extended info. from OI(%s)",
                          __func__, IF_NAME(oi));
                return;
        }
@@ -660,13 +657,15 @@ static void ospf_ext_link_nsm_change(struct ospf_neighbor *nbr, int old_status)
        /* Get interface information for Segment Routing */
        exti = lookup_ext_by_ifp(oi->ifp);
        if (exti == NULL) {
-               zlog_warn("EXT (%s): Cannot get Extended info. from OI(%s)",
+               flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED,
+                         "EXT (%s): Cannot get Extended info. from OI(%s)",
                          __func__, IF_NAME(oi));
                return;
        }
 
        if (oi->area == NULL || oi->area->ospf == NULL) {
-               zlog_warn("EXT (%s): Cannot refer to OSPF from OI(%s)",
+               flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED,
+                         "EXT (%s): Cannot refer to OSPF from OI(%s)",
                          __func__, IF_NAME(oi));
                return;
        }
@@ -761,7 +760,8 @@ static int ospf_ext_link_lsa_update(struct ospf_lsa *lsa)
 {
        /* Sanity Check */
        if (lsa == NULL) {
-               zlog_warn("EXT (%s): Abort! LSA is NULL", __func__);
+               flog_warn(EC_OSPF_LSA_NULL, "EXT (%s): Abort! LSA is NULL",
+                         __func__);
                return -1;
        }
 
@@ -794,7 +794,8 @@ static int ospf_ext_pref_lsa_update(struct ospf_lsa *lsa)
 
        /* Sanity Check */
        if (lsa == NULL) {
-               zlog_warn("EXT (%s): Abort! LSA is NULL", __func__);
+               flog_warn(EC_OSPF_LSA_NULL, "EXT (%s): Abort! LSA is NULL",
+                         __func__);
                return -1;
        }
 
@@ -929,10 +930,6 @@ static struct ospf_lsa *ospf_ext_pref_lsa_new(struct ospf_area *area,
 
        /* Create a stream for LSA. */
        s = stream_new(OSPF_MAX_LSA_SIZE);
-       if (s == NULL) {
-               zlog_warn("EXT (%s): stream_new() error", __func__);
-               return NULL;
-       }
 
        /* Prepare LSA Header */
        lsah = (struct lsa_header *)STREAM_DATA(s);
@@ -1007,10 +1004,6 @@ static struct ospf_lsa *ospf_ext_link_lsa_new(struct ospf_area *area,
 
        /* Create a stream for LSA. */
        s = stream_new(OSPF_MAX_LSA_SIZE);
-       if (s == NULL) {
-               zlog_warn("EXT (%s): stream_new() error", __func__);
-               return NULL;
-       }
        lsah = (struct lsa_header *)STREAM_DATA(s);
 
        options = OSPF_OPTION_O;          /* Don't forget this :-) */
@@ -1069,13 +1062,15 @@ static int ospf_ext_pref_lsa_originate1(struct ospf_area *area,
        /* Create new Opaque-LSA/Extended Prefix Opaque LSA instance. */
        new = ospf_ext_pref_lsa_new(area, exti);
        if (new == NULL) {
-               zlog_warn("EXT (%s): ospf_ext_pref_lsa_new() error", __func__);
+               flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED,
+                         "EXT (%s): ospf_ext_pref_lsa_new() error", __func__);
                return rc;
        }
 
        /* Install this LSA into LSDB. */
        if (ospf_lsa_install(area->ospf, NULL /*oi */, new) == NULL) {
-               zlog_warn("EXT (%s): ospf_lsa_install() error", __func__);
+               flog_warn(EC_OSPF_LSA_INSTALL_FAILURE,
+                         "EXT (%s): ospf_lsa_install() error", __func__);
                ospf_lsa_unlock(&new);
                return rc;
        }
@@ -1121,13 +1116,15 @@ static int ospf_ext_link_lsa_originate1(struct ospf_area *area,
        /* Create new Opaque-LSA/Extended Link Opaque LSA instance. */
        new = ospf_ext_link_lsa_new(area, exti);
        if (new == NULL) {
-               zlog_warn("EXT (%s): ospf_ext_link_lsa_new() error", __func__);
+               flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED,
+                         "EXT (%s): ospf_ext_link_lsa_new() error", __func__);
                return rc;
        }
 
        /* Install this LSA into LSDB. */
        if (ospf_lsa_install(area->ospf, NULL /*oi */, new) == NULL) {
-               zlog_warn("EXT (%s): ospf_lsa_install() error", __func__);
+               flog_warn(EC_OSPF_LSA_INSTALL_FAILURE,
+                         "EXT (%s): ospf_lsa_install() error", __func__);
                ospf_lsa_unlock(&new);
                return rc;
        }
@@ -1193,9 +1190,9 @@ static int ospf_ext_pref_lsa_originate(void *arg)
                if (CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ENGAGED)) {
                        if (CHECK_FLAG(exti->flags,
                                       EXT_LPFLG_LSA_FORCED_REFRESH)) {
-                               zlog_warn(
-                                       "EXT (%s): Refresh instead of "
-                                       "Originate",
+                               flog_warn(
+                                       EC_OSPF_EXT_LSA_UNEXPECTED,
+                                       "EXT (%s): Refresh instead of Originate",
                                        __func__);
                                UNSET_FLAG(exti->flags,
                                           EXT_LPFLG_LSA_FORCED_REFRESH);
@@ -1251,9 +1248,9 @@ static int ospf_ext_link_lsa_originate(void *arg)
                if (CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ENGAGED)) {
                        if (CHECK_FLAG(exti->flags,
                                       EXT_LPFLG_LSA_FORCED_REFRESH)) {
-                               zlog_warn(
-                                       "EXT (%s): Refresh instead of "
-                                       "Originate",
+                               flog_warn(
+                                       EC_OSPF_EXT_LSA_UNEXPECTED,
+                                       "EXT (%s): Refresh instead of Originate",
                                        __func__);
                                UNSET_FLAG(exti->flags,
                                           EXT_LPFLG_LSA_FORCED_REFRESH);
@@ -1303,14 +1300,16 @@ static struct ospf_lsa *ospf_ext_pref_lsa_refresh(struct ospf_lsa *lsa)
        /* Lookup this lsa corresponding Extended parameters */
        exti = lookup_ext_by_instance(lsa);
        if (exti == NULL) {
-               zlog_warn("EXT (%s): Invalid parameter LSA ID", __func__);
+               flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED,
+                         "EXT (%s): Invalid parameter LSA ID", __func__);
                /* Flush it anyway. */
                lsa->data->ls_age = htons(OSPF_LSA_MAXAGE);
        }
 
        /* Check if Interface was not disable in the interval */
        if ((exti != NULL) && !CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ACTIVE)) {
-               zlog_warn("EXT (%s): Interface was Disabled: Flush it!",
+               flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED,
+                         "EXT (%s): Interface was Disabled: Flush it!",
                          __func__);
                /* Flush it anyway. */
                lsa->data->ls_age = htons(OSPF_LSA_MAXAGE);
@@ -1328,7 +1327,8 @@ static struct ospf_lsa *ospf_ext_pref_lsa_refresh(struct ospf_lsa *lsa)
        new = ospf_ext_pref_lsa_new(area, exti);
 
        if (new == NULL) {
-               zlog_warn("EXT (%s): ospf_ext_pref_lsa_new() error", __func__);
+               flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED,
+                         "EXT (%s): ospf_ext_pref_lsa_new() error", __func__);
                return NULL;
        }
        new->data->ls_seqnum = lsa_seqnum_increment(lsa);
@@ -1345,7 +1345,8 @@ static struct ospf_lsa *ospf_ext_pref_lsa_refresh(struct ospf_lsa *lsa)
                top = ospf_lookup_by_vrf_id(VRF_DEFAULT);
 
        if (ospf_lsa_install(top, NULL /*oi */, new) == NULL) {
-               zlog_warn("EXT (%s): ospf_lsa_install() error", __func__);
+               flog_warn(EC_OSPF_LSA_INSTALL_FAILURE,
+                         "EXT (%s): ospf_lsa_install() error", __func__);
                ospf_lsa_unlock(&new);
                return NULL;
        }
@@ -1386,14 +1387,16 @@ static struct ospf_lsa *ospf_ext_link_lsa_refresh(struct ospf_lsa *lsa)
        /* Lookup this LSA corresponding Extended parameters */
        exti = lookup_ext_by_instance(lsa);
        if (exti == NULL) {
-               zlog_warn("EXT (%s): Invalid parameter LSA ID", __func__);
+               flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED,
+                         "EXT (%s): Invalid parameter LSA ID", __func__);
                /* Flush it anyway. */
                lsa->data->ls_age = htons(OSPF_LSA_MAXAGE);
        }
 
        /* Check if Interface was not disable in the interval */
        if ((exti != NULL) && !CHECK_FLAG(exti->flags, EXT_LPFLG_LSA_ACTIVE)) {
-               zlog_warn("EXT (%s): Interface was Disabled: Flush it!",
+               flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED,
+                         "EXT (%s): Interface was Disabled: Flush it!",
                          __func__);
                lsa->data->ls_age = htons(OSPF_LSA_MAXAGE);
        }
@@ -1409,7 +1412,8 @@ static struct ospf_lsa *ospf_ext_link_lsa_refresh(struct ospf_lsa *lsa)
        /* Create new Opaque-LSA/Extended Link instance */
        new = ospf_ext_link_lsa_new(area, exti);
        if (new == NULL) {
-               zlog_warn("EXT (%s): Error creating new LSA", __func__);
+               flog_warn(EC_OSPF_EXT_LSA_UNEXPECTED,
+                         "EXT (%s): Error creating new LSA", __func__);
                return NULL;
        }
        new->data->ls_seqnum = lsa_seqnum_increment(lsa);
@@ -1417,7 +1421,8 @@ static struct ospf_lsa *ospf_ext_link_lsa_refresh(struct ospf_lsa *lsa)
        /* Install this LSA into LSDB. */
        /* Given "lsa" will be freed in the next function */
        if (ospf_lsa_install(top, NULL /*oi */, new) == NULL) {
-               zlog_warn("EXT (%s): Error installing new LSA", __func__);
+               flog_warn(EC_OSPF_LSA_INSTALL_FAILURE,
+                         "EXT (%s): Error installing new LSA", __func__);
                ospf_lsa_unlock(&new);
                return NULL;
        }
@@ -1464,9 +1469,9 @@ static void ospf_ext_pref_lsa_schedule(struct ext_itf *exti,
 
        /* Set LSA header information */
        if (exti->area == NULL) {
-               zlog_warn(
-                       "EXT (%s): Flooding is Area scope but area is not yet "
-                       "set",
+               flog_warn(
+                       EC_OSPF_EXT_LSA_UNEXPECTED,
+                       "EXT (%s): Flooding is Area scope but area is not yet set",
                        __func__);
                if (OspfEXT.area == NULL) {
                        top = ospf_lookup_by_vrf_id(VRF_DEFAULT);
@@ -1494,9 +1499,6 @@ static void ospf_ext_pref_lsa_schedule(struct ext_itf *exti,
                UNSET_FLAG(exti->flags, EXT_LPFLG_LSA_ENGAGED);
                ospf_opaque_lsa_flush_schedule(&lsa);
                break;
-       default:
-               zlog_warn("EXT (%s): Unknown opcode", __func__);
-               break;
        }
 }
 
@@ -1528,9 +1530,9 @@ static void ospf_ext_link_lsa_schedule(struct ext_itf *exti,
 
        /* Set LSA header information */
        if (exti->area == NULL) {
-               zlog_warn(
-                       "EXT (%s): Flooding is Area scope but area is not "
-                       "yet set",
+               flog_warn(
+                       EC_OSPF_EXT_LSA_UNEXPECTED,
+                       "EXT (%s): Flooding is Area scope but area is not yet set",
                        __func__);
                if (OspfEXT.area == NULL) {
                        top = ospf_lookup_by_vrf_id(VRF_DEFAULT);
@@ -1558,9 +1560,6 @@ static void ospf_ext_link_lsa_schedule(struct ext_itf *exti,
                UNSET_FLAG(exti->flags, EXT_LPFLG_LSA_ENGAGED);
                ospf_opaque_lsa_flush_schedule(&lsa);
                break;
-       default:
-               zlog_warn("EXT (%s): Unknown opcode", __func__);
-               break;
        }
 }