]> git.proxmox.com Git - mirror_frr.git/blobdiff - zebra/zebra_mpls.c
Merge pull request #8639 from idryzhov/isis-new-bfd-lib
[mirror_frr.git] / zebra / zebra_mpls.c
index 66aea8936e0fa76a92c11c9ff158819a5902e5c4..850ca1763682fc9cfd23f3f877e9857260572b82 100644 (file)
 #include "zebra/zebra_router.h"
 #include "zebra/redistribute.h"
 #include "zebra/debug.h"
-#include "zebra/zebra_memory.h"
 #include "zebra/zebra_vrf.h"
 #include "zebra/zebra_mpls.h"
 #include "zebra/zebra_srte.h"
 #include "zebra/zebra_errors.h"
 
-DEFINE_MTYPE_STATIC(ZEBRA, LSP, "MPLS LSP object")
-DEFINE_MTYPE_STATIC(ZEBRA, FEC, "MPLS FEC object")
-DEFINE_MTYPE_STATIC(ZEBRA, NHLFE, "MPLS nexthop object")
+DEFINE_MTYPE_STATIC(ZEBRA, LSP, "MPLS LSP object");
+DEFINE_MTYPE_STATIC(ZEBRA, FEC, "MPLS FEC object");
+DEFINE_MTYPE_STATIC(ZEBRA, NHLFE, "MPLS nexthop object");
 
 int mpls_enabled;
 
@@ -331,7 +330,6 @@ static void fec_evaluate(struct zebra_vrf *zvrf)
        zebra_fec_t *fec;
        uint32_t old_label, new_label;
        int af;
-       char buf[BUFSIZ];
 
        for (af = AFI_IP; af < AFI_MAX; af++) {
                if (zvrf->fec_table[af] == NULL)
@@ -348,9 +346,6 @@ static void fec_evaluate(struct zebra_vrf *zvrf)
                            || fec->label_index == MPLS_INVALID_LABEL_INDEX)
                                continue;
 
-                       if (IS_ZEBRA_DEBUG_MPLS)
-                               prefix2str(&rn->p, buf, BUFSIZ);
-
                        /* Save old label, determine new label. */
                        old_label = fec->label;
                        new_label =
@@ -364,8 +359,8 @@ static void fec_evaluate(struct zebra_vrf *zvrf)
 
                        if (IS_ZEBRA_DEBUG_MPLS)
                                zlog_debug(
-                                       "Update fec %s new label %u upon label block",
-                                       buf, new_label);
+                                       "Update fec %pRN new label %u upon label block",
+                                       rn, new_label);
 
                        fec->label = new_label;
                        fec_update_clients(fec);
@@ -494,8 +489,7 @@ static void fec_print(zebra_fec_t *fec, struct vty *vty)
        char buf[BUFSIZ];
 
        rn = fec->rn;
-       prefix2str(&rn->p, buf, BUFSIZ);
-       vty_out(vty, "%s\n", buf);
+       vty_out(vty, "%pRN\n", rn);
        vty_out(vty, "  Label: %s", label2str(fec->label, buf, BUFSIZ));
        if (fec->label_index != MPLS_INVALID_LABEL_INDEX)
                vty_out(vty, ", Label Index: %u", fec->label_index);
@@ -878,6 +872,22 @@ static void lsp_schedule(struct hash_bucket *bucket, void *ctxt)
        zebra_lsp_t *lsp;
 
        lsp = (zebra_lsp_t *)bucket->data;
+
+       /* In the common flow, this is used when external events occur. For
+        * LSPs with backup nhlfes, we'll assume that the forwarding
+        * plane will use the backups to handle these events, until the
+        * owning protocol can react.
+        */
+       if (ctxt == NULL) {
+               /* Skip LSPs with backups */
+               if (nhlfe_list_first(&lsp->backup_nhlfe_list) != NULL) {
+                       if (IS_ZEBRA_DEBUG_MPLS_DETAIL)
+                               zlog_debug("%s: skip LSP in-label %u",
+                                          __func__, lsp->ile.in_label);
+                       return;
+               }
+       }
+
        (void)lsp_processq_add(lsp);
 }
 
@@ -2008,6 +2018,7 @@ void zebra_mpls_process_dplane_notify(struct zebra_dplane_ctx *ctx)
        int start_count = 0, end_count = 0; /* Installed counts */
        bool changed_p = false;
        bool is_debug = (IS_ZEBRA_DEBUG_DPLANE | IS_ZEBRA_DEBUG_MPLS);
+       enum zebra_sr_policy_update_label_mode update_mode;
 
        if (is_debug)
                zlog_debug("LSP dplane notif, in-label %u",
@@ -2081,10 +2092,21 @@ void zebra_mpls_process_dplane_notify(struct zebra_dplane_ctx *ctx)
        if (end_count > 0) {
                SET_FLAG(lsp->flags, LSP_FLAG_INSTALLED);
 
+               /* SR-TE update too */
+               if (start_count == 0)
+                       update_mode = ZEBRA_SR_POLICY_LABEL_CREATED;
+               else
+                       update_mode = ZEBRA_SR_POLICY_LABEL_UPDATED;
+               zebra_sr_policy_label_update(lsp->ile.in_label, update_mode);
+
                if (changed_p)
                        dplane_lsp_notif_update(lsp, DPLANE_OP_LSP_UPDATE, ctx);
 
        } else {
+               /* SR-TE update too */
+               zebra_sr_policy_label_update(lsp->ile.in_label,
+                                            ZEBRA_SR_POLICY_LABEL_REMOVED);
+
                UNSET_FLAG(lsp->flags, LSP_FLAG_INSTALLED);
                clear_nhlfe_installed(lsp);
        }
@@ -2244,7 +2266,6 @@ int zebra_mpls_fec_register(struct zebra_vrf *zvrf, struct prefix *p,
 {
        struct route_table *table;
        zebra_fec_t *fec;
-       char buf[BUFSIZ];
        bool new_client;
        bool label_change = false;
        uint32_t old_label;
@@ -2255,14 +2276,11 @@ int zebra_mpls_fec_register(struct zebra_vrf *zvrf, struct prefix *p,
        if (!table)
                return -1;
 
-       if (IS_ZEBRA_DEBUG_MPLS)
-               prefix2str(p, buf, BUFSIZ);
-
        if (label != MPLS_INVALID_LABEL && have_label_index) {
                flog_err(
                        EC_ZEBRA_FEC_LABEL_INDEX_LABEL_CONFLICT,
-                       "Rejecting FEC register for %s with both label %u and Label Index %u specified, client %s",
-                       buf, label, label_index,
+                       "Rejecting FEC register for %pFX with both label %u and Label Index %u specified, client %s",
+                       p, label, label_index,
                        zebra_route_string(client->proto));
                return -1;
        }
@@ -2274,8 +2292,8 @@ int zebra_mpls_fec_register(struct zebra_vrf *zvrf, struct prefix *p,
                if (!fec) {
                        flog_err(
                                EC_ZEBRA_FEC_ADD_FAILED,
-                               "Failed to add FEC %s upon register, client %s",
-                               buf, zebra_route_string(client->proto));
+                               "Failed to add FEC %pFX upon register, client %s",
+                               p, zebra_route_string(client->proto));
                        return -1;
                }
 
@@ -2301,7 +2319,7 @@ int zebra_mpls_fec_register(struct zebra_vrf *zvrf, struct prefix *p,
                listnode_add(fec->client_list, client);
 
        if (IS_ZEBRA_DEBUG_MPLS)
-               zlog_debug("FEC %s label%s %u %s by client %s%s", buf,
+               zlog_debug("FEC %pFX label%s %u %s by client %s%s", p,
                           have_label_index ? " index" : "",
                           have_label_index ? label_index : label,
                           new_client ? "registered" : "updated",
@@ -2352,15 +2370,11 @@ int zebra_mpls_fec_unregister(struct zebra_vrf *zvrf, struct prefix *p,
 {
        struct route_table *table;
        zebra_fec_t *fec;
-       char buf[BUFSIZ];
 
        table = zvrf->fec_table[family2afi(PREFIX_FAMILY(p))];
        if (!table)
                return -1;
 
-       if (IS_ZEBRA_DEBUG_MPLS)
-               prefix2str(p, buf, BUFSIZ);
-
        fec = fec_find(table, p);
        if (!fec) {
                flog_err(EC_ZEBRA_FEC_RM_FAILED,
@@ -2372,7 +2386,7 @@ int zebra_mpls_fec_unregister(struct zebra_vrf *zvrf, struct prefix *p,
        listnode_delete(fec->client_list, client);
 
        if (IS_ZEBRA_DEBUG_MPLS)
-               zlog_debug("FEC %s unregistered by client %s", buf,
+               zlog_debug("FEC %pFX unregistered by client %s", p,
                           zebra_route_string(client->proto));
 
        /* If not a configured entry, delete the FEC if no other clients. Before
@@ -2513,7 +2527,6 @@ int zebra_mpls_static_fec_add(struct zebra_vrf *zvrf, struct prefix *p,
 {
        struct route_table *table;
        zebra_fec_t *fec;
-       char buf[BUFSIZ];
        mpls_label_t old_label;
        int ret = 0;
 
@@ -2521,9 +2534,6 @@ int zebra_mpls_static_fec_add(struct zebra_vrf *zvrf, struct prefix *p,
        if (!table)
                return -1;
 
-       if (IS_ZEBRA_DEBUG_MPLS)
-               prefix2str(p, buf, BUFSIZ);
-
        /* Update existing FEC or create a new one. */
        fec = fec_find(table, p);
        if (!fec) {
@@ -2536,7 +2546,7 @@ int zebra_mpls_static_fec_add(struct zebra_vrf *zvrf, struct prefix *p,
                }
 
                if (IS_ZEBRA_DEBUG_MPLS)
-                       zlog_debug("Add fec %s label %u", buf, in_label);
+                       zlog_debug("Add fec %pFX label %u", p, in_label);
        } else {
                fec->flags |= FEC_FLAG_CONFIGURED;
                if (fec->label == in_label)
@@ -2546,7 +2556,7 @@ int zebra_mpls_static_fec_add(struct zebra_vrf *zvrf, struct prefix *p,
                /* Label change, update clients. */
                old_label = fec->label;
                if (IS_ZEBRA_DEBUG_MPLS)
-                       zlog_debug("Update fec %s new label %u", buf, in_label);
+                       zlog_debug("Update fec %pFX new label %u", p, in_label);
 
                fec->label = in_label;
                fec_update_clients(fec);
@@ -2569,7 +2579,6 @@ int zebra_mpls_static_fec_del(struct zebra_vrf *zvrf, struct prefix *p)
        struct route_table *table;
        zebra_fec_t *fec;
        mpls_label_t old_label;
-       char buf[BUFSIZ];
 
        table = zvrf->fec_table[family2afi(PREFIX_FAMILY(p))];
        if (!table)
@@ -2577,9 +2586,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);
                flog_err(EC_ZEBRA_FEC_RM_FAILED,
-                        "Failed to find FEC %s upon delete", buf);
+                        "Failed to find FEC %pFX upon delete", p);
                return -1;
        }
 
@@ -3944,11 +3952,18 @@ void zebra_mpls_close_tables(struct zebra_vrf *zvrf)
  */
 void zebra_mpls_init_tables(struct zebra_vrf *zvrf)
 {
+       char buffer[80];
+
        if (!zvrf)
                return;
-       zvrf->slsp_table =
-               hash_create(label_hash, label_cmp, "ZEBRA SLSP table");
-       zvrf->lsp_table = hash_create(label_hash, label_cmp, "ZEBRA LSP table");
+
+       snprintf(buffer, sizeof(buffer), "ZEBRA SLSP table: %s",
+                zvrf->vrf->name);
+       zvrf->slsp_table = hash_create_size(8, label_hash, label_cmp, buffer);
+
+       snprintf(buffer, sizeof(buffer), "ZEBRA LSP table: %s",
+                zvrf->vrf->name);
+       zvrf->lsp_table = hash_create_size(8, label_hash, label_cmp, buffer);
        zvrf->fec_table[AFI_IP] = route_table_init();
        zvrf->fec_table[AFI_IP6] = route_table_init();
        zvrf->mpls_flags = 0;