]> git.proxmox.com Git - mirror_frr.git/blame - zebra/zebra_mpls_netlink.c
isisd: implement the 'lsp-too-large' notification
[mirror_frr.git] / zebra / zebra_mpls_netlink.c
CommitLineData
3c3877cd
DL
1/* MPLS forwarding table updates using netlink over GNU/Linux system.
2 * Copyright (C) 2016 Cumulus Networks, Inc.
3 *
4 * This file is part of Quagga.
5 *
6 * Quagga is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
9 * later version.
10 *
11 * Quagga is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
896014f4
DL
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
3c3877cd
DL
19 */
20
be0dba35 21#include <zebra.h>
ddfeb486
DL
22
23#ifdef HAVE_NETLINK
24
be0dba35
RW
25#include "zebra/rt.h"
26#include "zebra/rt_netlink.h"
27#include "zebra/zebra_mpls.h"
28
29/*
30 * Install Label Forwarding entry into the kernel.
31 */
ea1c14f6 32enum zebra_dplane_result kernel_add_lsp(zebra_lsp_t *lsp)
be0dba35 33{
d62a17ae 34 int ret;
be0dba35 35
4a83e7a0 36 if (!lsp || !lsp->best_nhlfe) { // unexpected
ea1c14f6
MS
37 kernel_lsp_pass_fail(lsp, ZEBRA_DPLANE_INSTALL_FAILURE);
38 return ZEBRA_DPLANE_REQUEST_FAILURE;
4a83e7a0 39 }
be0dba35 40
d62a17ae 41 ret = netlink_mpls_multipath(RTM_NEWROUTE, lsp);
be0dba35 42
4a83e7a0 43 kernel_lsp_pass_fail(lsp,
ea1c14f6
MS
44 (!ret) ? ZEBRA_DPLANE_INSTALL_SUCCESS
45 : ZEBRA_DPLANE_INSTALL_FAILURE);
7c5d0e18 46
ea1c14f6 47 return ZEBRA_DPLANE_REQUEST_SUCCESS;
be0dba35
RW
48}
49
50/*
51 * Update Label Forwarding entry in the kernel. This means that the Label
52 * forwarding entry is already installed and needs an update - either a new
53 * path is to be added, an installed path has changed (e.g., outgoing label)
54 * or an installed path (but not all paths) has to be removed.
55 * TODO: Performs a DEL followed by ADD now, need to change to REPLACE. Note
56 * that REPLACE was originally implemented for IPv4 nexthops but removed as
57 * it was not functioning when moving from swap to PHP as that was signaled
58 * through the metric field (before kernel-MPLS). This shouldn't be an issue
59 * any longer, so REPLACE can be reintroduced.
60 */
ea1c14f6 61enum zebra_dplane_result kernel_upd_lsp(zebra_lsp_t *lsp)
be0dba35 62{
d62a17ae 63 int ret;
be0dba35 64
4a83e7a0 65 if (!lsp || !lsp->best_nhlfe) { // unexpected
ea1c14f6
MS
66 kernel_lsp_pass_fail(lsp, ZEBRA_DPLANE_INSTALL_FAILURE);
67 return ZEBRA_DPLANE_REQUEST_FAILURE;
4a83e7a0 68 }
be0dba35 69
d62a17ae 70 ret = netlink_mpls_multipath(RTM_NEWROUTE, lsp);
be0dba35 71
4a83e7a0 72 kernel_lsp_pass_fail(lsp,
ea1c14f6
MS
73 (!ret) ? ZEBRA_DPLANE_INSTALL_SUCCESS
74 : ZEBRA_DPLANE_INSTALL_FAILURE);
7c5d0e18 75
ea1c14f6 76 return ZEBRA_DPLANE_REQUEST_SUCCESS;
be0dba35
RW
77}
78
79/*
80 * Delete Label Forwarding entry from the kernel.
81 */
ea1c14f6 82enum zebra_dplane_result kernel_del_lsp(zebra_lsp_t *lsp)
be0dba35 83{
2b63430c
DS
84 int ret;
85
4a83e7a0 86 if (!lsp) { // unexpected
ea1c14f6
MS
87 kernel_lsp_pass_fail(lsp, ZEBRA_DPLANE_DELETE_FAILURE);
88 return ZEBRA_DPLANE_REQUEST_FAILURE;
4a83e7a0 89 }
be0dba35 90
4a83e7a0 91 if (!CHECK_FLAG(lsp->flags, LSP_FLAG_INSTALLED)) {
ea1c14f6
MS
92 kernel_lsp_pass_fail(lsp, ZEBRA_DPLANE_DELETE_FAILURE);
93 return ZEBRA_DPLANE_REQUEST_FAILURE;
4a83e7a0 94 }
be0dba35 95
2b63430c
DS
96 ret = netlink_mpls_multipath(RTM_DELROUTE, lsp);
97
4a83e7a0 98 kernel_lsp_pass_fail(lsp,
ea1c14f6
MS
99 (!ret) ? ZEBRA_DPLANE_DELETE_SUCCESS
100 : ZEBRA_DPLANE_DELETE_FAILURE);
7c5d0e18 101
ea1c14f6 102 return ZEBRA_DPLANE_REQUEST_SUCCESS;
be0dba35 103}
d3e2c74a 104
d62a17ae 105int mpls_kernel_init(void)
fe6c7157 106{
d62a17ae 107 struct stat st;
fe6c7157 108
d62a17ae 109 /*
110 * Check if the MPLS module is loaded in the kernel.
111 */
112 if (stat("/proc/sys/net/mpls", &st) != 0)
113 return -1;
fe6c7157 114
d62a17ae 115 return 0;
fe6c7157 116};
ddfeb486
DL
117
118#endif /* HAVE_NETLINK */