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