]>
Commit | Line | Data |
---|---|---|
acddc0ed | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
3c3877cd DL |
2 | /* MPLS forwarding table updates using netlink over GNU/Linux system. |
3 | * Copyright (C) 2016 Cumulus Networks, Inc. | |
3c3877cd DL |
4 | */ |
5 | ||
be0dba35 | 6 | #include <zebra.h> |
ddfeb486 DL |
7 | |
8 | #ifdef HAVE_NETLINK | |
9 | ||
d37f4d6c | 10 | #include "zebra/debug.h" |
be0dba35 RW |
11 | #include "zebra/rt.h" |
12 | #include "zebra/rt_netlink.h" | |
13 | #include "zebra/zebra_mpls.h" | |
0be6e7d7 | 14 | #include "zebra/kernel_netlink.h" |
be0dba35 | 15 | |
b300c8bb DE |
16 | ssize_t netlink_lsp_msg_encoder(struct zebra_dplane_ctx *ctx, void *buf, |
17 | size_t buflen) | |
16c628de | 18 | { |
0be6e7d7 | 19 | int cmd; |
d37f4d6c MS |
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)); | |
67e3369e | 32 | return -1; |
d37f4d6c MS |
33 | } |
34 | ||
35 | cmd = RTM_NEWROUTE; | |
36 | } else | |
37 | /* Invalid op? */ | |
67e3369e | 38 | return -1; |
d37f4d6c | 39 | |
67e3369e JU |
40 | return netlink_mpls_multipath_msg_encode(cmd, ctx, buf, buflen); |
41 | } | |
0be6e7d7 | 42 | |
67e3369e JU |
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 | } | |
d37f4d6c | 48 | |
97d8d05a MS |
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 | */ | |
67e3369e JU |
54 | enum netlink_msg_status netlink_put_pw_update_msg(struct nl_batch *bth, |
55 | struct zebra_dplane_ctx *ctx) | |
97d8d05a | 56 | { |
67e3369e | 57 | return FRR_NETLINK_SUCCESS; |
97d8d05a MS |
58 | } |
59 | ||
d62a17ae | 60 | int mpls_kernel_init(void) |
fe6c7157 | 61 | { |
d62a17ae | 62 | struct stat st; |
fe6c7157 | 63 | |
d62a17ae | 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; | |
fe6c7157 | 69 | |
d62a17ae | 70 | return 0; |
fe6c7157 | 71 | }; |
ddfeb486 DL |
72 | |
73 | #endif /* HAVE_NETLINK */ |