]> git.proxmox.com Git - mirror_frr.git/blob - zebra/zebra_mpls_netlink.c
lib: msg: refactor common connection code from mgmtd
[mirror_frr.git] / zebra / zebra_mpls_netlink.c
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* MPLS forwarding table updates using netlink over GNU/Linux system.
3 * Copyright (C) 2016 Cumulus Networks, Inc.
4 */
5
6 #include <zebra.h>
7
8 #ifdef HAVE_NETLINK
9
10 #include "zebra/debug.h"
11 #include "zebra/rt.h"
12 #include "zebra/rt_netlink.h"
13 #include "zebra/zebra_mpls.h"
14 #include "zebra/kernel_netlink.h"
15
16 ssize_t netlink_lsp_msg_encoder(struct zebra_dplane_ctx *ctx, void *buf,
17 size_t buflen)
18 {
19 int cmd;
20
21 /* Call to netlink layer based on type of update */
22 if (dplane_ctx_get_op(ctx) == DPLANE_OP_LSP_DELETE) {
23 cmd = RTM_DELROUTE;
24 } else if (dplane_ctx_get_op(ctx) == DPLANE_OP_LSP_INSTALL ||
25 dplane_ctx_get_op(ctx) == DPLANE_OP_LSP_UPDATE) {
26
27 /* Validate */
28 if (dplane_ctx_get_best_nhlfe(ctx) == NULL) {
29 if (IS_ZEBRA_DEBUG_KERNEL || IS_ZEBRA_DEBUG_MPLS)
30 zlog_debug("LSP in-label %u: update fails, no best NHLFE",
31 dplane_ctx_get_in_label(ctx));
32 return -1;
33 }
34
35 cmd = RTM_NEWROUTE;
36 } else
37 /* Invalid op? */
38 return -1;
39
40 return netlink_mpls_multipath_msg_encode(cmd, ctx, buf, buflen);
41 }
42
43 enum netlink_msg_status netlink_put_lsp_update_msg(struct nl_batch *bth,
44 struct zebra_dplane_ctx *ctx)
45 {
46 return netlink_batch_add_msg(bth, ctx, netlink_lsp_msg_encoder, false);
47 }
48
49 /*
50 * Pseudowire update api - not supported by netlink as of 12/18,
51 * but note that the default has been to report 'success' for pw updates
52 * on unsupported platforms.
53 */
54 enum netlink_msg_status netlink_put_pw_update_msg(struct nl_batch *bth,
55 struct zebra_dplane_ctx *ctx)
56 {
57 return FRR_NETLINK_SUCCESS;
58 }
59
60 int mpls_kernel_init(void)
61 {
62 struct stat st;
63
64 /*
65 * Check if the MPLS module is loaded in the kernel.
66 */
67 if (stat("/proc/sys/net/mpls", &st) != 0)
68 return -1;
69
70 return 0;
71 };
72
73 #endif /* HAVE_NETLINK */