1 /* MPLS forwarding table updates using netlink over GNU/Linux system.
2 * Copyright (C) 2016 Cumulus Networks, Inc.
4 * This file is part of Quagga.
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
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.
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
26 #include "zebra/rt_netlink.h"
27 #include "zebra/zebra_mpls.h"
30 * Install Label Forwarding entry into the kernel.
32 void kernel_add_lsp(zebra_lsp_t
*lsp
)
36 if (!lsp
|| !lsp
->best_nhlfe
) { // unexpected
37 kernel_lsp_pass_fail(lsp
, SOUTHBOUND_INSTALL_FAILURE
);
41 ret
= netlink_mpls_multipath(RTM_NEWROUTE
, lsp
);
43 kernel_lsp_pass_fail(lsp
,
44 (!ret
) ? SOUTHBOUND_INSTALL_SUCCESS
45 : SOUTHBOUND_INSTALL_FAILURE
);
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.
59 void kernel_upd_lsp(zebra_lsp_t
*lsp
)
63 if (!lsp
|| !lsp
->best_nhlfe
) { // unexpected
64 kernel_lsp_pass_fail(lsp
, SOUTHBOUND_INSTALL_FAILURE
);
68 ret
= netlink_mpls_multipath(RTM_NEWROUTE
, lsp
);
70 kernel_lsp_pass_fail(lsp
,
71 (!ret
) ? SOUTHBOUND_INSTALL_SUCCESS
72 : SOUTHBOUND_INSTALL_FAILURE
);
76 * Delete Label Forwarding entry from the kernel.
78 void kernel_del_lsp(zebra_lsp_t
*lsp
)
82 if (!lsp
) { // unexpected
83 kernel_lsp_pass_fail(lsp
, SOUTHBOUND_DELETE_FAILURE
);
87 if (!CHECK_FLAG(lsp
->flags
, LSP_FLAG_INSTALLED
)) {
88 kernel_lsp_pass_fail(lsp
, SOUTHBOUND_DELETE_FAILURE
);
92 ret
= netlink_mpls_multipath(RTM_DELROUTE
, lsp
);
94 kernel_lsp_pass_fail(lsp
,
95 (!ret
) ? SOUTHBOUND_DELETE_SUCCESS
96 : SOUTHBOUND_DELETE_FAILURE
);
99 int mpls_kernel_init(void)
104 * Check if the MPLS module is loaded in the kernel.
106 if (stat("/proc/sys/net/mpls", &st
) != 0)
112 #endif /* HAVE_NETLINK */