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