]> git.proxmox.com Git - mirror_frr.git/blob - zebra/zebra_mpls_netlink.c
Merge pull request #6569 from xThaid/dplane_batching_cleanup
[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/debug.h"
26 #include "zebra/rt.h"
27 #include "zebra/rt_netlink.h"
28 #include "zebra/zebra_mpls.h"
29 #include "zebra/kernel_netlink.h"
30
31 /*
32 * LSP forwarding update using dataplane context information.
33 */
34 enum zebra_dplane_result kernel_lsp_update(struct zebra_dplane_ctx *ctx)
35 {
36 uint8_t nl_pkt[NL_PKT_BUF_SIZE];
37 ssize_t ret = -1;
38 int cmd;
39
40 /* Call to netlink layer based on type of update */
41 if (dplane_ctx_get_op(ctx) == DPLANE_OP_LSP_DELETE) {
42 cmd = RTM_DELROUTE;
43 } else if (dplane_ctx_get_op(ctx) == DPLANE_OP_LSP_INSTALL ||
44 dplane_ctx_get_op(ctx) == DPLANE_OP_LSP_UPDATE) {
45
46 /* Validate */
47 if (dplane_ctx_get_best_nhlfe(ctx) == NULL) {
48 if (IS_ZEBRA_DEBUG_KERNEL || IS_ZEBRA_DEBUG_MPLS)
49 zlog_debug("LSP in-label %u: update fails, no best NHLFE",
50 dplane_ctx_get_in_label(ctx));
51 goto done;
52 }
53
54 cmd = RTM_NEWROUTE;
55 } else
56 /* Invalid op? */
57 goto done;
58
59 ret = netlink_mpls_multipath_msg_encode(cmd, ctx, nl_pkt,
60 sizeof(nl_pkt));
61 if (ret <= 0)
62 return ZEBRA_DPLANE_REQUEST_FAILURE;
63
64 ret = netlink_talk_info(netlink_talk_filter, (struct nlmsghdr *)nl_pkt,
65 dplane_ctx_get_ns(ctx), 0);
66
67 done:
68
69 return (ret == 0 ?
70 ZEBRA_DPLANE_REQUEST_SUCCESS : ZEBRA_DPLANE_REQUEST_FAILURE);
71 }
72
73 /*
74 * Pseudowire update api - not supported by netlink as of 12/18,
75 * but note that the default has been to report 'success' for pw updates
76 * on unsupported platforms.
77 */
78 enum zebra_dplane_result kernel_pw_update(struct zebra_dplane_ctx *ctx)
79 {
80 return ZEBRA_DPLANE_REQUEST_SUCCESS;
81 }
82
83 int mpls_kernel_init(void)
84 {
85 struct stat st;
86
87 /*
88 * Check if the MPLS module is loaded in the kernel.
89 */
90 if (stat("/proc/sys/net/mpls", &st) != 0)
91 return -1;
92
93 return 0;
94 };
95
96 #endif /* HAVE_NETLINK */