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