2016-11-14 03:07:41 +01:00
|
|
|
/* MPLS forwarding table updates using netlink over GNU/Linux system.
|
|
|
|
* Copyright (C) 2016 Cumulus Networks, Inc.
|
|
|
|
*
|
|
|
|
* This file is part of Quagga.
|
|
|
|
*
|
|
|
|
* Quagga is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation; either version 2, or (at your option) any
|
|
|
|
* later version.
|
|
|
|
*
|
|
|
|
* Quagga is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
2017-05-13 10:25:29 +02:00
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; see the file COPYING; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
2016-11-14 03:07:41 +01:00
|
|
|
*/
|
|
|
|
|
2016-09-12 14:02:39 +02:00
|
|
|
#include <zebra.h>
|
2017-07-26 19:49:15 +02:00
|
|
|
|
|
|
|
#ifdef HAVE_NETLINK
|
|
|
|
|
2016-09-12 14:02:39 +02:00
|
|
|
#include "zebra/rt.h"
|
|
|
|
#include "zebra/rt_netlink.h"
|
|
|
|
#include "zebra/zebra_mpls.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Install Label Forwarding entry into the kernel.
|
|
|
|
*/
|
2018-09-12 20:42:03 +02:00
|
|
|
enum zebra_dplane_result kernel_add_lsp(zebra_lsp_t *lsp)
|
2016-09-12 14:02:39 +02:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
int ret;
|
2016-09-12 14:02:39 +02:00
|
|
|
|
2017-11-29 14:53:33 +01:00
|
|
|
if (!lsp || !lsp->best_nhlfe) { // unexpected
|
2018-09-12 20:42:03 +02:00
|
|
|
kernel_lsp_pass_fail(lsp, ZEBRA_DPLANE_INSTALL_FAILURE);
|
|
|
|
return ZEBRA_DPLANE_REQUEST_FAILURE;
|
2017-11-29 14:53:33 +01:00
|
|
|
}
|
2016-09-12 14:02:39 +02:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
ret = netlink_mpls_multipath(RTM_NEWROUTE, lsp);
|
2016-09-12 14:02:39 +02:00
|
|
|
|
2017-11-29 14:53:33 +01:00
|
|
|
kernel_lsp_pass_fail(lsp,
|
2018-09-12 20:42:03 +02:00
|
|
|
(!ret) ? ZEBRA_DPLANE_INSTALL_SUCCESS
|
|
|
|
: ZEBRA_DPLANE_INSTALL_FAILURE);
|
2018-05-25 17:07:34 +02:00
|
|
|
|
2018-09-12 20:42:03 +02:00
|
|
|
return ZEBRA_DPLANE_REQUEST_SUCCESS;
|
2016-09-12 14:02:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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)
|
2018-10-23 16:57:01 +02:00
|
|
|
* or an installed path (but not all paths) has to be removed. This performs
|
|
|
|
* a REPLACE operation, internally.
|
2016-09-12 14:02:39 +02:00
|
|
|
*/
|
2018-09-12 20:42:03 +02:00
|
|
|
enum zebra_dplane_result kernel_upd_lsp(zebra_lsp_t *lsp)
|
2016-09-12 14:02:39 +02:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
int ret;
|
2016-09-12 14:02:39 +02:00
|
|
|
|
2017-11-29 14:53:33 +01:00
|
|
|
if (!lsp || !lsp->best_nhlfe) { // unexpected
|
2018-09-12 20:42:03 +02:00
|
|
|
kernel_lsp_pass_fail(lsp, ZEBRA_DPLANE_INSTALL_FAILURE);
|
|
|
|
return ZEBRA_DPLANE_REQUEST_FAILURE;
|
2017-11-29 14:53:33 +01:00
|
|
|
}
|
2016-09-12 14:02:39 +02:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
ret = netlink_mpls_multipath(RTM_NEWROUTE, lsp);
|
2016-09-12 14:02:39 +02:00
|
|
|
|
2017-11-29 14:53:33 +01:00
|
|
|
kernel_lsp_pass_fail(lsp,
|
2018-09-12 20:42:03 +02:00
|
|
|
(!ret) ? ZEBRA_DPLANE_INSTALL_SUCCESS
|
|
|
|
: ZEBRA_DPLANE_INSTALL_FAILURE);
|
2018-05-25 17:07:34 +02:00
|
|
|
|
2018-09-12 20:42:03 +02:00
|
|
|
return ZEBRA_DPLANE_REQUEST_SUCCESS;
|
2016-09-12 14:02:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Delete Label Forwarding entry from the kernel.
|
|
|
|
*/
|
2018-09-12 20:42:03 +02:00
|
|
|
enum zebra_dplane_result kernel_del_lsp(zebra_lsp_t *lsp)
|
2016-09-12 14:02:39 +02:00
|
|
|
{
|
2017-11-16 18:46:10 +01:00
|
|
|
int ret;
|
|
|
|
|
2017-11-29 14:53:33 +01:00
|
|
|
if (!lsp) { // unexpected
|
2018-09-12 20:42:03 +02:00
|
|
|
kernel_lsp_pass_fail(lsp, ZEBRA_DPLANE_DELETE_FAILURE);
|
|
|
|
return ZEBRA_DPLANE_REQUEST_FAILURE;
|
2017-11-29 14:53:33 +01:00
|
|
|
}
|
2016-09-12 14:02:39 +02:00
|
|
|
|
2017-11-29 14:53:33 +01:00
|
|
|
if (!CHECK_FLAG(lsp->flags, LSP_FLAG_INSTALLED)) {
|
2018-09-12 20:42:03 +02:00
|
|
|
kernel_lsp_pass_fail(lsp, ZEBRA_DPLANE_DELETE_FAILURE);
|
|
|
|
return ZEBRA_DPLANE_REQUEST_FAILURE;
|
2017-11-29 14:53:33 +01:00
|
|
|
}
|
2016-09-12 14:02:39 +02:00
|
|
|
|
2017-11-16 18:46:10 +01:00
|
|
|
ret = netlink_mpls_multipath(RTM_DELROUTE, lsp);
|
|
|
|
|
2017-11-29 14:53:33 +01:00
|
|
|
kernel_lsp_pass_fail(lsp,
|
2018-09-12 20:42:03 +02:00
|
|
|
(!ret) ? ZEBRA_DPLANE_DELETE_SUCCESS
|
|
|
|
: ZEBRA_DPLANE_DELETE_FAILURE);
|
2018-05-25 17:07:34 +02:00
|
|
|
|
2018-09-12 20:42:03 +02:00
|
|
|
return ZEBRA_DPLANE_REQUEST_SUCCESS;
|
2016-09-12 14:02:39 +02:00
|
|
|
}
|
2016-06-02 13:28:15 +02:00
|
|
|
|
2018-10-23 16:57:01 +02:00
|
|
|
enum zebra_dplane_result kernel_lsp_update(struct zebra_dplane_ctx *ctx)
|
|
|
|
{
|
|
|
|
return ZEBRA_DPLANE_REQUEST_FAILURE;
|
|
|
|
}
|
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
int mpls_kernel_init(void)
|
2016-09-22 04:59:57 +02:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
struct stat st;
|
2016-09-22 04:59:57 +02:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
/*
|
|
|
|
* Check if the MPLS module is loaded in the kernel.
|
|
|
|
*/
|
|
|
|
if (stat("/proc/sys/net/mpls", &st) != 0)
|
|
|
|
return -1;
|
2016-09-22 04:59:57 +02:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
return 0;
|
2016-09-22 04:59:57 +02:00
|
|
|
};
|
2017-07-26 19:49:15 +02:00
|
|
|
|
|
|
|
#endif /* HAVE_NETLINK */
|