]> git.proxmox.com Git - mirror_frr.git/blobdiff - zebra/zebra_mpls.c
Merge pull request #3503 from qlyoung/fix-bgpd-show-ip-neigh-json-double-free
[mirror_frr.git] / zebra / zebra_mpls.c
index cfe208d35b0b9960b544ebc59f673cb58b4c1b81..5fe01161586c76fbd44b4a697aed718c26009d76 100644 (file)
@@ -45,6 +45,7 @@
 #include "zebra/zebra_memory.h"
 #include "zebra/zebra_vrf.h"
 #include "zebra/zebra_mpls.h"
+#include "zebra/zebra_errors.h"
 
 DEFINE_MTYPE_STATIC(ZEBRA, LSP, "MPLS LSP object")
 DEFINE_MTYPE_STATIC(ZEBRA, FEC, "MPLS FEC object")
@@ -78,7 +79,7 @@ static zebra_fec_t *fec_add(struct route_table *table, struct prefix *p,
 static int fec_del(zebra_fec_t *fec);
 
 static unsigned int label_hash(void *p);
-static int label_cmp(const void *p1, const void *p2);
+static bool label_cmp(const void *p1, const void *p2);
 static int nhlfe_nexthop_active_ipv4(zebra_nhlfe_t *nhlfe,
                                     struct nexthop *nexthop);
 static int nhlfe_nexthop_active_ipv6(zebra_nhlfe_t *nhlfe,
@@ -550,8 +551,6 @@ static zebra_fec_t *fec_add(struct route_table *table, struct prefix *p,
 
        if (!fec) {
                fec = XCALLOC(MTYPE_FEC, sizeof(zebra_fec_t));
-               if (!fec)
-                       return NULL;
 
                rn->info = fec;
                fec->rn = rn;
@@ -573,7 +572,7 @@ static zebra_fec_t *fec_add(struct route_table *table, struct prefix *p,
  */
 static int fec_del(zebra_fec_t *fec)
 {
-       list_delete_and_null(&fec->client_list);
+       list_delete(&fec->client_list);
        fec->rn->info = NULL;
        route_unlock_node(fec->rn);
        XFREE(MTYPE_FEC, fec);
@@ -593,7 +592,7 @@ static unsigned int label_hash(void *p)
 /*
  * Compare 2 LSP hash entries based on in-label.
  */
-static int label_cmp(const void *p1, const void *p2)
+static bool label_cmp(const void *p1, const void *p2)
 {
        const zebra_ile_t *ile1 = p1;
        const zebra_ile_t *ile2 = p2;
@@ -918,12 +917,14 @@ static wq_item_status lsp_process(struct work_queue *wq, void *data)
 
                        UNSET_FLAG(lsp->flags, LSP_FLAG_CHANGED);
                        switch (kernel_add_lsp(lsp)) {
-                       case DP_REQUEST_QUEUED:
-                               zlog_err("No current DataPlane interfaces can return this, please fix");
+                       case ZEBRA_DPLANE_REQUEST_QUEUED:
+                               flog_err(
+                                       EC_ZEBRA_DP_INVALID_RC,
+                                       "No current DataPlane interfaces can return this, please fix");
                                break;
-                       case DP_REQUEST_FAILURE:
+                       case ZEBRA_DPLANE_REQUEST_FAILURE:
                                break;
-                       case DP_REQUEST_SUCCESS:
+                       case ZEBRA_DPLANE_REQUEST_SUCCESS:
                                zvrf->lsp_installs++;
                                break;
                        }
@@ -933,12 +934,14 @@ static wq_item_status lsp_process(struct work_queue *wq, void *data)
                if (!newbest) {
 
                        switch (kernel_del_lsp(lsp)) {
-                       case DP_REQUEST_QUEUED:
-                               zlog_err("No current DataPlane interfaces can return this, please fix");
+                       case ZEBRA_DPLANE_REQUEST_QUEUED:
+                               flog_err(
+                                       EC_ZEBRA_DP_INVALID_RC,
+                                       "No current DataPlane interfaces can return this, please fix");
                                break;
-                       case DP_REQUEST_FAILURE:
+                       case ZEBRA_DPLANE_REQUEST_FAILURE:
                                break;
-                       case DP_REQUEST_SUCCESS:
+                       case ZEBRA_DPLANE_REQUEST_SUCCESS:
                                zvrf->lsp_removals++;
                                break;
                        }
@@ -971,12 +974,14 @@ static wq_item_status lsp_process(struct work_queue *wq, void *data)
                        }
 
                        switch (kernel_upd_lsp(lsp)) {
-                       case DP_REQUEST_QUEUED:
-                               zlog_err("No current DataPlane interfaces can return this, please fix");
+                       case ZEBRA_DPLANE_REQUEST_QUEUED:
+                               flog_err(
+                                       EC_ZEBRA_DP_INVALID_RC,
+                                       "No current DataPlane interfaces can return this, please fix");
                                break;
-                       case DP_REQUEST_FAILURE:
+                       case ZEBRA_DPLANE_REQUEST_FAILURE:
                                break;
-                       case DP_REQUEST_SUCCESS:
+                       case ZEBRA_DPLANE_REQUEST_SUCCESS:
                                zvrf->lsp_installs++;
                                break;
                        }
@@ -1050,7 +1055,8 @@ static int lsp_processq_add(zebra_lsp_t *lsp)
                return 0;
 
        if (zebrad.lsp_process_q == NULL) {
-               zlog_err("%s: work_queue does not exist!", __func__);
+               flog_err(EC_ZEBRA_WQ_NONEXISTENT,
+                        "%s: work_queue does not exist!", __func__);
                return -1;
        }
 
@@ -1181,8 +1187,6 @@ static zebra_nhlfe_t *nhlfe_add(zebra_lsp_t *lsp, enum lsp_types_t lsp_type,
                return NULL;
 
        nhlfe = XCALLOC(MTYPE_NHLFE, sizeof(zebra_nhlfe_t));
-       if (!nhlfe)
-               return NULL;
 
        nhlfe->lsp = lsp;
        nhlfe->type = lsp_type;
@@ -1694,7 +1698,8 @@ static int mpls_processq_init(struct zebra_t *zebra)
 {
        zebra->lsp_process_q = work_queue_new(zebra->master, "LSP processing");
        if (!zebra->lsp_process_q) {
-               zlog_err("%s: could not initialise work queue!", __func__);
+               flog_err(EC_ZEBRA_WQ_NONEXISTENT,
+                        "%s: could not initialise work queue!", __func__);
                return -1;
        }
 
@@ -1711,7 +1716,7 @@ static int mpls_processq_init(struct zebra_t *zebra)
 
 /* Public functions */
 
-void kernel_lsp_pass_fail(zebra_lsp_t *lsp, enum dp_results res)
+void kernel_lsp_pass_fail(zebra_lsp_t *lsp, enum zebra_dplane_status res)
 {
        struct nexthop *nexthop;
        zebra_nhlfe_t *nhlfe;
@@ -1720,12 +1725,13 @@ void kernel_lsp_pass_fail(zebra_lsp_t *lsp, enum dp_results res)
                return;
 
        switch (res) {
-       case DP_INSTALL_FAILURE:
+       case ZEBRA_DPLANE_INSTALL_FAILURE:
                UNSET_FLAG(lsp->flags, LSP_FLAG_INSTALLED);
                clear_nhlfe_installed(lsp);
-               zlog_warn("LSP Install Failure: %u", lsp->ile.in_label);
+               flog_warn(EC_ZEBRA_LSP_INSTALL_FAILURE,
+                         "LSP Install Failure: %u", lsp->ile.in_label);
                break;
-       case DP_INSTALL_SUCCESS:
+       case ZEBRA_DPLANE_INSTALL_SUCCESS:
                SET_FLAG(lsp->flags, LSP_FLAG_INSTALLED);
                for (nhlfe = lsp->nhlfe_list; nhlfe; nhlfe = nhlfe->next) {
                        nexthop = nhlfe->nexthop;
@@ -1736,12 +1742,15 @@ void kernel_lsp_pass_fail(zebra_lsp_t *lsp, enum dp_results res)
                        SET_FLAG(nexthop->flags, NEXTHOP_FLAG_FIB);
                }
                break;
-       case DP_DELETE_SUCCESS:
+       case ZEBRA_DPLANE_DELETE_SUCCESS:
                UNSET_FLAG(lsp->flags, LSP_FLAG_INSTALLED);
                clear_nhlfe_installed(lsp);
                break;
-       case DP_DELETE_FAILURE:
-               zlog_warn("LSP Deletion Failure: %u", lsp->ile.in_label);
+       case ZEBRA_DPLANE_DELETE_FAILURE:
+               flog_warn(EC_ZEBRA_LSP_DELETE_FAILURE,
+                         "LSP Deletion Failure: %u", lsp->ile.in_label);
+               break;
+       case ZEBRA_DPLANE_STATUS_NONE:
                break;
        }
 }
@@ -1829,7 +1838,8 @@ int zebra_mpls_fec_register(struct zebra_vrf *zvrf, struct prefix *p,
                fec = fec_add(table, p, MPLS_INVALID_LABEL, 0, label_index);
                if (!fec) {
                        prefix2str(p, buf, BUFSIZ);
-                       zlog_err(
+                       flog_err(
+                               EC_ZEBRA_FEC_ADD_FAILED,
                                "Failed to add FEC %s upon register, client %s",
                                buf, zebra_route_string(client->proto));
                        return -1;
@@ -1909,7 +1919,8 @@ int zebra_mpls_fec_unregister(struct zebra_vrf *zvrf, struct prefix *p,
        fec = fec_find(table, p);
        if (!fec) {
                prefix2str(p, buf, BUFSIZ);
-               zlog_err("Failed to find FEC %s upon unregister, client %s",
+               flog_err(EC_ZEBRA_FEC_RM_FAILED,
+                        "Failed to find FEC %s upon unregister, client %s",
                         buf, zebra_route_string(client->proto));
                return -1;
        }
@@ -2040,7 +2051,8 @@ int zebra_mpls_static_fec_add(struct zebra_vrf *zvrf, struct prefix *p,
                              MPLS_INVALID_LABEL_INDEX);
                if (!fec) {
                        prefix2str(p, buf, BUFSIZ);
-                       zlog_err("Failed to add FEC %s upon config", buf);
+                       flog_err(EC_ZEBRA_FEC_ADD_FAILED,
+                                "Failed to add FEC %s upon config", buf);
                        return -1;
                }
 
@@ -2087,7 +2099,8 @@ int zebra_mpls_static_fec_del(struct zebra_vrf *zvrf, struct prefix *p)
        fec = fec_find(table, p);
        if (!fec) {
                prefix2str(p, buf, BUFSIZ);
-               zlog_err("Failed to find FEC %s upon delete", buf);
+               flog_err(EC_ZEBRA_FEC_RM_FAILED,
+                        "Failed to find FEC %s upon delete", buf);
                return -1;
        }
 
@@ -2437,7 +2450,7 @@ void mpls_ldp_lsp_uninstall_all(struct hash_backet *backet, void *ctxt)
        struct hash *lsp_table;
 
        lsp = (zebra_lsp_t *)backet->data;
-       if (!lsp || !lsp->nhlfe_list)
+       if (!lsp->nhlfe_list)
                return;
 
        lsp_table = ctxt;
@@ -2689,7 +2702,7 @@ void zebra_mpls_lsp_schedule(struct zebra_vrf *zvrf)
  * (VTY command handler).
  */
 void zebra_mpls_print_lsp(struct vty *vty, struct zebra_vrf *zvrf,
-                         mpls_label_t label, uint8_t use_json)
+                         mpls_label_t label, bool use_json)
 {
        struct hash *lsp_table;
        zebra_lsp_t *lsp;
@@ -2720,7 +2733,7 @@ void zebra_mpls_print_lsp(struct vty *vty, struct zebra_vrf *zvrf,
  * Display MPLS label forwarding table (VTY command handler).
  */
 void zebra_mpls_print_lsp_table(struct vty *vty, struct zebra_vrf *zvrf,
-                               uint8_t use_json)
+                               bool use_json)
 {
        char buf[BUFSIZ];
        json_object *json = NULL;
@@ -2797,7 +2810,7 @@ void zebra_mpls_print_lsp_table(struct vty *vty, struct zebra_vrf *zvrf,
                vty_out(vty, "\n");
        }
 
-       list_delete_and_null(&lsp_list);
+       list_delete(&lsp_list);
 }
 
 /*
@@ -2836,7 +2849,7 @@ int zebra_mpls_write_lsp_config(struct vty *vty, struct zebra_vrf *zvrf)
                }
        }
 
-       list_delete_and_null(&slsp_list);
+       list_delete(&slsp_list);
        return (zvrf->slsp_table->count ? 1 : 0);
 }
 
@@ -2936,7 +2949,8 @@ void zebra_mpls_init(void)
        mpls_enabled = 0;
 
        if (mpls_kernel_init() < 0) {
-               zlog_warn("Disabling MPLS support (no kernel support)");
+               flog_warn(EC_ZEBRA_MPLS_SUPPORT_DISABLED,
+                         "Disabling MPLS support (no kernel support)");
                return;
        }