/src/frr/zebra/zebra_mpls_netlink.c
Line | Count | Source (jump to first uncovered line) |
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 | 0 | { |
19 | 0 | int cmd; |
20 | | |
21 | | /* Call to netlink layer based on type of update */ |
22 | 0 | if (dplane_ctx_get_op(ctx) == DPLANE_OP_LSP_DELETE) { |
23 | 0 | cmd = RTM_DELROUTE; |
24 | 0 | } else if (dplane_ctx_get_op(ctx) == DPLANE_OP_LSP_INSTALL || |
25 | 0 | dplane_ctx_get_op(ctx) == DPLANE_OP_LSP_UPDATE) { |
26 | | |
27 | | /* Validate */ |
28 | 0 | if (dplane_ctx_get_best_nhlfe(ctx) == NULL) { |
29 | 0 | if (IS_ZEBRA_DEBUG_KERNEL || IS_ZEBRA_DEBUG_MPLS) |
30 | 0 | zlog_debug("LSP in-label %u: update fails, no best NHLFE", |
31 | 0 | dplane_ctx_get_in_label(ctx)); |
32 | 0 | return -1; |
33 | 0 | } |
34 | | |
35 | 0 | cmd = RTM_NEWROUTE; |
36 | 0 | } else |
37 | | /* Invalid op? */ |
38 | 0 | return -1; |
39 | | |
40 | 0 | return netlink_mpls_multipath_msg_encode(cmd, ctx, buf, buflen); |
41 | 0 | } |
42 | | |
43 | | enum netlink_msg_status netlink_put_lsp_update_msg(struct nl_batch *bth, |
44 | | struct zebra_dplane_ctx *ctx) |
45 | 0 | { |
46 | 0 | return netlink_batch_add_msg(bth, ctx, netlink_lsp_msg_encoder, false); |
47 | 0 | } |
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 | 0 | { |
57 | 0 | return FRR_NETLINK_SUCCESS; |
58 | 0 | } |
59 | | |
60 | | int mpls_kernel_init(void) |
61 | 0 | { |
62 | 0 | struct stat st; |
63 | | |
64 | | /* |
65 | | * Check if the MPLS module is loaded in the kernel. |
66 | | */ |
67 | 0 | if (stat("/proc/sys/net/mpls", &st) != 0) |
68 | 0 | return -1; |
69 | | |
70 | 0 | return 0; |
71 | 0 | }; |
72 | | |
73 | | #endif /* HAVE_NETLINK */ |