]> git.proxmox.com Git - mirror_frr.git/blob - zebra/zebra_mpls_netlink.c
*: reindent
[mirror_frr.git] / zebra / zebra_mpls_netlink.c
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 *
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
19 */
20
21 #include <zebra.h>
22 #include "zebra/rt.h"
23 #include "zebra/rt_netlink.h"
24 #include "zebra/zebra_mpls.h"
25
26 /*
27 * Install Label Forwarding entry into the kernel.
28 */
29 int kernel_add_lsp(zebra_lsp_t *lsp)
30 {
31 int ret;
32
33 if (!lsp || !lsp->best_nhlfe) // unexpected
34 return -1;
35
36 UNSET_FLAG(lsp->flags, LSP_FLAG_CHANGED);
37 ret = netlink_mpls_multipath(RTM_NEWROUTE, lsp);
38 if (!ret)
39 SET_FLAG(lsp->flags, LSP_FLAG_INSTALLED);
40 else
41 clear_nhlfe_installed(lsp);
42
43 return ret;
44 }
45
46 /*
47 * Update Label Forwarding entry in the kernel. This means that the Label
48 * forwarding entry is already installed and needs an update - either a new
49 * path is to be added, an installed path has changed (e.g., outgoing label)
50 * or an installed path (but not all paths) has to be removed.
51 * TODO: Performs a DEL followed by ADD now, need to change to REPLACE. Note
52 * that REPLACE was originally implemented for IPv4 nexthops but removed as
53 * it was not functioning when moving from swap to PHP as that was signaled
54 * through the metric field (before kernel-MPLS). This shouldn't be an issue
55 * any longer, so REPLACE can be reintroduced.
56 */
57 int kernel_upd_lsp(zebra_lsp_t *lsp)
58 {
59 int ret;
60
61 if (!lsp || !lsp->best_nhlfe) // unexpected
62 return -1;
63
64 UNSET_FLAG(lsp->flags, LSP_FLAG_CHANGED);
65
66 /* First issue a DEL and clear the installed flag. */
67 netlink_mpls_multipath(RTM_DELROUTE, lsp);
68 UNSET_FLAG(lsp->flags, LSP_FLAG_INSTALLED);
69
70 /* Then issue an ADD. */
71 ret = netlink_mpls_multipath(RTM_NEWROUTE, lsp);
72 if (!ret)
73 SET_FLAG(lsp->flags, LSP_FLAG_INSTALLED);
74 else
75 clear_nhlfe_installed(lsp);
76
77 return ret;
78 }
79
80 /*
81 * Delete Label Forwarding entry from the kernel.
82 */
83 int kernel_del_lsp(zebra_lsp_t *lsp)
84 {
85 if (!lsp) // unexpected
86 return -1;
87
88 if (CHECK_FLAG(lsp->flags, LSP_FLAG_INSTALLED)) {
89 netlink_mpls_multipath(RTM_DELROUTE, lsp);
90 UNSET_FLAG(lsp->flags, LSP_FLAG_INSTALLED);
91 }
92
93 return 0;
94 }
95
96 int mpls_kernel_init(void)
97 {
98 struct stat st;
99
100 /*
101 * Check if the MPLS module is loaded in the kernel.
102 */
103 if (stat("/proc/sys/net/mpls", &st) != 0)
104 return -1;
105
106 return 0;
107 };