]> git.proxmox.com Git - mirror_frr.git/blobdiff - zebra/zebra_mpls_netlink.c
Merge pull request #5789 from donaldsharp/bgp_ebgp_reason
[mirror_frr.git] / zebra / zebra_mpls_netlink.c
index d0c4acb3709a6f2b5822878ff78dbc7847aed795..a9233530dc9c16968bffa25f07f6fda3381d4cc4 100644 (file)
  */
 
 #include <zebra.h>
+
+#ifdef HAVE_NETLINK
+
+#include "zebra/debug.h"
 #include "zebra/rt.h"
 #include "zebra/rt_netlink.h"
 #include "zebra/zebra_mpls.h"
 
 /*
- * Install Label Forwarding entry into the kernel.
+ * LSP forwarding update using dataplane context information.
  */
-int
-kernel_add_lsp (zebra_lsp_t *lsp)
+enum zebra_dplane_result kernel_lsp_update(struct zebra_dplane_ctx *ctx)
 {
-  int ret;
-
-  if (!lsp || !lsp->best_nhlfe) // unexpected
-    return -1;
-
-  UNSET_FLAG (lsp->flags, LSP_FLAG_CHANGED);
-  ret = netlink_mpls_multipath (RTM_NEWROUTE, lsp);
-  if (!ret)
-    SET_FLAG (lsp->flags, LSP_FLAG_INSTALLED);
-  else
-    clear_nhlfe_installed (lsp);
-
-  return ret;
-}
+       int cmd, ret = -1;
 
-/*
- * Update Label Forwarding entry in the kernel. This means that the Label
- * forwarding entry is already installed and needs an update - either a new
- * path is to be added, an installed path has changed (e.g., outgoing label)
- * or an installed path (but not all paths) has to be removed.
- * TODO: Performs a DEL followed by ADD now, need to change to REPLACE. Note
- * that REPLACE was originally implemented for IPv4 nexthops but removed as
- * it was not functioning when moving from swap to PHP as that was signaled
- * through the metric field (before kernel-MPLS). This shouldn't be an issue
- * any longer, so REPLACE can be reintroduced.
- */
-int
-kernel_upd_lsp (zebra_lsp_t *lsp)
-{
-  int ret;
+       /* Call to netlink layer based on type of update */
+       if (dplane_ctx_get_op(ctx) == DPLANE_OP_LSP_DELETE) {
+               cmd = RTM_DELROUTE;
+       } else if (dplane_ctx_get_op(ctx) == DPLANE_OP_LSP_INSTALL ||
+                  dplane_ctx_get_op(ctx) == DPLANE_OP_LSP_UPDATE) {
 
-  if (!lsp || !lsp->best_nhlfe) // unexpected
-    return -1;
+               /* Validate */
+               if (dplane_ctx_get_best_nhlfe(ctx) == NULL) {
+                       if (IS_ZEBRA_DEBUG_KERNEL || IS_ZEBRA_DEBUG_MPLS)
+                               zlog_debug("LSP in-label %u: update fails, no best NHLFE",
+                                          dplane_ctx_get_in_label(ctx));
+                       goto done;
+               }
 
-  UNSET_FLAG (lsp->flags, LSP_FLAG_CHANGED);
+               cmd = RTM_NEWROUTE;
+       } else
+               /* Invalid op? */
+               goto done;
 
-  /* First issue a DEL and clear the installed flag. */
-  netlink_mpls_multipath (RTM_DELROUTE, lsp);
-  UNSET_FLAG (lsp->flags, LSP_FLAG_INSTALLED);
+       ret = netlink_mpls_multipath(cmd, ctx);
 
-  /* Then issue an ADD. */
-  ret = netlink_mpls_multipath (RTM_NEWROUTE, lsp);
-  if (!ret)
-    SET_FLAG (lsp->flags, LSP_FLAG_INSTALLED);
-  else
-    clear_nhlfe_installed (lsp);
+done:
 
-  return ret;
+       return (ret == 0 ?
+               ZEBRA_DPLANE_REQUEST_SUCCESS : ZEBRA_DPLANE_REQUEST_FAILURE);
 }
 
 /*
- * Delete Label Forwarding entry from the kernel.
+ * Pseudowire update api - not supported by netlink as of 12/18,
+ * but note that the default has been to report 'success' for pw updates
+ * on unsupported platforms.
  */
-int
-kernel_del_lsp (zebra_lsp_t *lsp)
+enum zebra_dplane_result kernel_pw_update(struct zebra_dplane_ctx *ctx)
 {
-  if (!lsp) // unexpected
-    return -1;
-
-  if (CHECK_FLAG (lsp->flags, LSP_FLAG_INSTALLED))
-    {
-      netlink_mpls_multipath (RTM_DELROUTE, lsp);
-      UNSET_FLAG (lsp->flags, LSP_FLAG_INSTALLED);
-    }
-
-  return 0;
+       return ZEBRA_DPLANE_REQUEST_SUCCESS;
 }
 
-int
-mpls_kernel_init (void)
+int mpls_kernel_init(void)
 {
-  struct stat st;
+       struct stat st;
 
-  /*
-   * Check if the MPLS module is loaded in the kernel.
-   */
-  if (stat ("/proc/sys/net/mpls", &st) != 0)
-    return -1;
+       /*
+        * Check if the MPLS module is loaded in the kernel.
+        */
+       if (stat("/proc/sys/net/mpls", &st) != 0)
+               return -1;
 
-  return 0;
+       return 0;
 };
+
+#endif /* HAVE_NETLINK */