]>
Commit | Line | Data |
---|---|---|
3c3877cd DL |
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 | * | |
896014f4 DL |
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 | |
3c3877cd DL |
19 | */ |
20 | ||
be0dba35 | 21 | #include <zebra.h> |
ddfeb486 DL |
22 | |
23 | #ifdef HAVE_NETLINK | |
24 | ||
d37f4d6c | 25 | #include "zebra/debug.h" |
be0dba35 RW |
26 | #include "zebra/rt.h" |
27 | #include "zebra/rt_netlink.h" | |
28 | #include "zebra/zebra_mpls.h" | |
0be6e7d7 | 29 | #include "zebra/kernel_netlink.h" |
be0dba35 | 30 | |
b300c8bb DE |
31 | ssize_t netlink_lsp_msg_encoder(struct zebra_dplane_ctx *ctx, void *buf, |
32 | size_t buflen) | |
16c628de | 33 | { |
0be6e7d7 | 34 | int cmd; |
d37f4d6c MS |
35 | |
36 | /* Call to netlink layer based on type of update */ | |
37 | if (dplane_ctx_get_op(ctx) == DPLANE_OP_LSP_DELETE) { | |
38 | cmd = RTM_DELROUTE; | |
39 | } else if (dplane_ctx_get_op(ctx) == DPLANE_OP_LSP_INSTALL || | |
40 | dplane_ctx_get_op(ctx) == DPLANE_OP_LSP_UPDATE) { | |
41 | ||
42 | /* Validate */ | |
43 | if (dplane_ctx_get_best_nhlfe(ctx) == NULL) { | |
44 | if (IS_ZEBRA_DEBUG_KERNEL || IS_ZEBRA_DEBUG_MPLS) | |
45 | zlog_debug("LSP in-label %u: update fails, no best NHLFE", | |
46 | dplane_ctx_get_in_label(ctx)); | |
67e3369e | 47 | return -1; |
d37f4d6c MS |
48 | } |
49 | ||
50 | cmd = RTM_NEWROUTE; | |
51 | } else | |
52 | /* Invalid op? */ | |
67e3369e | 53 | return -1; |
d37f4d6c | 54 | |
67e3369e JU |
55 | return netlink_mpls_multipath_msg_encode(cmd, ctx, buf, buflen); |
56 | } | |
0be6e7d7 | 57 | |
67e3369e JU |
58 | enum netlink_msg_status netlink_put_lsp_update_msg(struct nl_batch *bth, |
59 | struct zebra_dplane_ctx *ctx) | |
60 | { | |
61 | return netlink_batch_add_msg(bth, ctx, netlink_lsp_msg_encoder, false); | |
62 | } | |
d37f4d6c | 63 | |
97d8d05a MS |
64 | /* |
65 | * Pseudowire update api - not supported by netlink as of 12/18, | |
66 | * but note that the default has been to report 'success' for pw updates | |
67 | * on unsupported platforms. | |
68 | */ | |
67e3369e JU |
69 | enum netlink_msg_status netlink_put_pw_update_msg(struct nl_batch *bth, |
70 | struct zebra_dplane_ctx *ctx) | |
97d8d05a | 71 | { |
67e3369e | 72 | return FRR_NETLINK_SUCCESS; |
97d8d05a MS |
73 | } |
74 | ||
d62a17ae | 75 | int mpls_kernel_init(void) |
fe6c7157 | 76 | { |
d62a17ae | 77 | struct stat st; |
fe6c7157 | 78 | |
d62a17ae | 79 | /* |
80 | * Check if the MPLS module is loaded in the kernel. | |
81 | */ | |
82 | if (stat("/proc/sys/net/mpls", &st) != 0) | |
83 | return -1; | |
fe6c7157 | 84 | |
d62a17ae | 85 | return 0; |
fe6c7157 | 86 | }; |
ddfeb486 DL |
87 | |
88 | #endif /* HAVE_NETLINK */ |