]> git.proxmox.com Git - mirror_frr.git/blob - zebra/zebra_mpls_netlink.c
Merge pull request #1375 from donaldsharp/make_dist
[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
23 #ifdef HAVE_NETLINK
24
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 */
32 int kernel_add_lsp(zebra_lsp_t *lsp)
33 {
34 int ret;
35
36 if (!lsp || !lsp->best_nhlfe) // unexpected
37 return -1;
38
39 ret = netlink_mpls_multipath(RTM_NEWROUTE, lsp);
40
41 return ret;
42 }
43
44 /*
45 * Update Label Forwarding entry in the kernel. This means that the Label
46 * forwarding entry is already installed and needs an update - either a new
47 * path is to be added, an installed path has changed (e.g., outgoing label)
48 * or an installed path (but not all paths) has to be removed.
49 * TODO: Performs a DEL followed by ADD now, need to change to REPLACE. Note
50 * that REPLACE was originally implemented for IPv4 nexthops but removed as
51 * it was not functioning when moving from swap to PHP as that was signaled
52 * through the metric field (before kernel-MPLS). This shouldn't be an issue
53 * any longer, so REPLACE can be reintroduced.
54 */
55 int kernel_upd_lsp(zebra_lsp_t *lsp)
56 {
57 int ret;
58 zebra_nhlfe_t *nhlfe;
59 struct nexthop *nexthop;
60
61 if (!lsp || !lsp->best_nhlfe) // unexpected
62 return -1;
63
64 /* Any NHLFE that was installed but is not selected now needs to
65 * have its flags updated.
66 */
67 for (nhlfe = lsp->nhlfe_list; nhlfe; nhlfe = nhlfe->next) {
68 nexthop = nhlfe->nexthop;
69 if (!nexthop)
70 continue;
71
72 if (CHECK_FLAG(nhlfe->flags, NHLFE_FLAG_INSTALLED) &&
73 !CHECK_FLAG(nhlfe->flags, NHLFE_FLAG_SELECTED)) {
74 UNSET_FLAG(nhlfe->flags, NHLFE_FLAG_INSTALLED);
75 UNSET_FLAG(nexthop->flags, NEXTHOP_FLAG_FIB);
76 }
77 }
78
79 ret = netlink_mpls_multipath(RTM_NEWROUTE, lsp);
80
81 return ret;
82 }
83
84 /*
85 * Delete Label Forwarding entry from the kernel.
86 */
87 int kernel_del_lsp(zebra_lsp_t *lsp)
88 {
89 int ret;
90
91 if (!lsp) // unexpected
92 return -1;
93
94 if (!CHECK_FLAG(lsp->flags, LSP_FLAG_INSTALLED))
95 return -1;
96
97 ret = netlink_mpls_multipath(RTM_DELROUTE, lsp);
98
99 return ret;
100 }
101
102 int 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 };
114
115 #endif /* HAVE_NETLINK */