1 /* Zebra MPLS VTY functions
2 * Copyright (C) 2002 Kunihiro Ishiguro
4 * This file is part of GNU Zebra.
6 * GNU Zebra 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
11 * GNU Zebra 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.
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
34 #include "zebra/zserv.h"
35 #include "zebra/zebra_vrf.h"
36 #include "zebra/zebra_mpls.h"
37 #include "zebra/zebra_rnh.h"
38 #include "zebra/redistribute.h"
39 #include "zebra/zebra_routemap.h"
41 static int zebra_mpls_transit_lsp(struct vty
*vty
, int add_cmd
,
42 const char *inlabel_str
, const char *gate_str
,
43 const char *outlabel_str
,
46 struct zebra_vrf
*zvrf
;
48 enum nexthop_types_t gtype
;
51 mpls_label_t in_label
, out_label
;
55 "%% MPLS not turned on in kernel, ignoring command\n");
56 return CMD_WARNING_CONFIG_FAILED
;
59 zvrf
= vrf_info_lookup(VRF_DEFAULT
);
61 vty_out(vty
, "%% Default VRF does not exist\n");
62 return CMD_WARNING_CONFIG_FAILED
;
66 vty_out(vty
, "%% No Label Information\n");
67 return CMD_WARNING_CONFIG_FAILED
;
70 out_label
= MPLS_LABEL_IMPLICIT_NULL
; /* as initialization */
71 label
= atoi(inlabel_str
);
72 if (!IS_MPLS_UNRESERVED_LABEL(label
)) {
73 vty_out(vty
, "%% Invalid label\n");
74 return CMD_WARNING_CONFIG_FAILED
;
79 vty_out(vty
, "%% No Nexthop Information\n");
80 return CMD_WARNING_CONFIG_FAILED
;
83 vty_out(vty
, "%% No Outgoing label Information\n");
84 return CMD_WARNING_CONFIG_FAILED
;
89 gtype
= NEXTHOP_TYPE_BLACKHOLE
; /* as initialization */
92 /* Gateway is a IPv4 or IPv6 nexthop. */
93 ret
= inet_pton(AF_INET6
, gate_str
, &gate
.ipv6
);
95 gtype
= NEXTHOP_TYPE_IPV6
;
97 ret
= inet_pton(AF_INET
, gate_str
, &gate
.ipv4
);
99 gtype
= NEXTHOP_TYPE_IPV4
;
101 vty_out(vty
, "%% Invalid nexthop\n");
102 return CMD_WARNING_CONFIG_FAILED
;
108 if (outlabel_str
[0] == 'i')
109 out_label
= MPLS_LABEL_IMPLICIT_NULL
;
110 else if (outlabel_str
[0] == 'e' && gtype
== NEXTHOP_TYPE_IPV4
)
111 out_label
= MPLS_LABEL_IPV4_EXPLICIT_NULL
;
112 else if (outlabel_str
[0] == 'e' && gtype
== NEXTHOP_TYPE_IPV6
)
113 out_label
= MPLS_LABEL_IPV6_EXPLICIT_NULL
;
115 out_label
= atoi(outlabel_str
);
119 #if defined(HAVE_CUMULUS)
120 /* Check that label value is consistent. */
121 if (!zebra_mpls_lsp_label_consistent(zvrf
, in_label
, out_label
,
123 vty_out(vty
, "%% Label value not consistent\n");
124 return CMD_WARNING_CONFIG_FAILED
;
126 #endif /* HAVE_CUMULUS */
128 ret
= zebra_mpls_static_lsp_add(zvrf
, in_label
, out_label
,
131 ret
= zebra_mpls_static_lsp_del(zvrf
, in_label
, gtype
, &gate
,
135 vty_out(vty
, "%% LSP cannot be %s\n",
136 add_cmd
? "added" : "deleted");
137 return CMD_WARNING_CONFIG_FAILED
;
143 DEFUN (mpls_transit_lsp
,
144 mpls_transit_lsp_cmd
,
145 "mpls lsp (16-1048575) <A.B.C.D|X:X::X:X> <(16-1048575)|explicit-null|implicit-null>",
147 "Establish label switched path\n"
148 "Incoming MPLS label\n"
149 "IPv4 gateway address\n"
150 "IPv6 gateway address\n"
151 "Outgoing MPLS label\n"
152 "Use Explicit-Null label\n"
153 "Use Implicit-Null label\n")
155 return zebra_mpls_transit_lsp(vty
, 1, argv
[2]->arg
, argv
[3]->arg
,
159 DEFUN (no_mpls_transit_lsp
,
160 no_mpls_transit_lsp_cmd
,
161 "no mpls lsp (16-1048575) <A.B.C.D|X:X::X:X>",
164 "Establish label switched path\n"
165 "Incoming MPLS label\n"
166 "IPv4 gateway address\n"
167 "IPv6 gateway address\n")
169 return zebra_mpls_transit_lsp(vty
, 0, argv
[3]->arg
, argv
[4]->arg
, NULL
,
173 ALIAS(no_mpls_transit_lsp
, no_mpls_transit_lsp_out_label_cmd
,
174 "no mpls lsp (16-1048575) <A.B.C.D|X:X::X:X> <(16-1048575)|explicit-null|implicit-null>",
176 "Establish label switched path\n"
177 "Incoming MPLS label\n"
178 "IPv4 gateway address\n"
179 "IPv6 gateway address\n"
180 "Outgoing MPLS label\n"
181 "Use Explicit-Null label\n"
182 "Use Implicit-Null label\n")
184 DEFUN (no_mpls_transit_lsp_all
,
185 no_mpls_transit_lsp_all_cmd
,
186 "no mpls lsp (16-1048575)",
189 "Establish label switched path\n"
190 "Incoming MPLS label\n")
192 return zebra_mpls_transit_lsp(vty
, 0, argv
[3]->arg
, NULL
, NULL
, NULL
);
195 static int zebra_mpls_bind(struct vty
*vty
, int add_cmd
, const char *prefix
,
196 const char *label_str
)
198 struct zebra_vrf
*zvrf
;
203 zvrf
= vrf_info_lookup(VRF_DEFAULT
);
205 vty_out(vty
, "%% Default VRF does not exist\n");
206 return CMD_WARNING_CONFIG_FAILED
;
209 memset(&p
, 0, sizeof(struct prefix
));
210 ret
= str2prefix(prefix
, &p
);
212 vty_out(vty
, "%% Malformed address\n");
213 return CMD_WARNING_CONFIG_FAILED
;
218 vty_out(vty
, "%% No label binding specified\n");
219 return CMD_WARNING_CONFIG_FAILED
;
222 if (!strcmp(label_str
, "implicit-null"))
223 label
= MPLS_LABEL_IMPLICIT_NULL
;
224 else if (!strcmp(label_str
, "explicit-null")) {
225 if (p
.family
== AF_INET
)
226 label
= MPLS_LABEL_IPV4_EXPLICIT_NULL
;
228 label
= MPLS_LABEL_IPV6_EXPLICIT_NULL
;
230 label
= atoi(label_str
);
231 if (!IS_MPLS_UNRESERVED_LABEL(label
)) {
232 vty_out(vty
, "%% Invalid label\n");
233 return CMD_WARNING_CONFIG_FAILED
;
235 if (zebra_mpls_label_already_bound(zvrf
, label
)) {
237 "%% Label already bound to a FEC\n");
238 return CMD_WARNING_CONFIG_FAILED
;
242 ret
= zebra_mpls_static_fec_add(zvrf
, &p
, label
);
244 ret
= zebra_mpls_static_fec_del(zvrf
, &p
);
247 vty_out(vty
, "%% FEC to label binding cannot be %s\n",
248 add_cmd
? "added" : "deleted");
249 return CMD_WARNING_CONFIG_FAILED
;
255 DEFUN (mpls_label_bind
,
257 "mpls label bind <A.B.C.D/M|X:X::X:X/M> <(16-1048575)|implicit-null|explicit-null>",
259 "Label configuration\n"
260 "Establish FEC to label binding\n"
263 "MPLS Label to bind\n"
264 "Use Implicit-Null Label\n"
265 "Use Explicit-Null Label\n")
267 return zebra_mpls_bind(vty
, 1, argv
[3]->arg
, argv
[4]->arg
);
270 DEFUN (no_mpls_label_bind
,
271 no_mpls_label_bind_cmd
,
272 "no mpls label bind <A.B.C.D/M|X:X::X:X/M> [<(16-1048575)|implicit-null>]",
275 "Label configuration\n"
276 "Establish FEC to label binding\n"
279 "MPLS Label to bind\n"
280 "Use Implicit-Null Label\n")
282 return zebra_mpls_bind(vty
, 0, argv
[4]->arg
, NULL
);
285 /* MPLS LSP configuration write function. */
286 static int zebra_mpls_config(struct vty
*vty
)
289 struct zebra_vrf
*zvrf
;
291 zvrf
= vrf_info_lookup(VRF_DEFAULT
);
295 write
+= zebra_mpls_write_lsp_config(vty
, zvrf
);
296 write
+= zebra_mpls_write_fec_config(vty
, zvrf
);
297 write
+= zebra_mpls_write_label_block_config(vty
, zvrf
);
301 DEFUN (show_mpls_fec
,
303 "show mpls fec [<A.B.C.D/M|X:X::X:X/M>]",
307 "FEC to display information about\n"
308 "FEC to display information about\n")
310 struct zebra_vrf
*zvrf
;
314 zvrf
= vrf_info_lookup(VRF_DEFAULT
);
319 zebra_mpls_print_fec_table(vty
, zvrf
);
321 memset(&p
, 0, sizeof(struct prefix
));
322 ret
= str2prefix(argv
[3]->arg
, &p
);
324 vty_out(vty
, "%% Malformed address\n");
327 zebra_mpls_print_fec(vty
, zvrf
, &p
);
333 DEFUN (show_mpls_table
,
335 "show mpls table [json]",
341 struct zebra_vrf
*zvrf
;
342 bool uj
= use_json(argc
, argv
);
344 zvrf
= vrf_info_lookup(VRF_DEFAULT
);
345 zebra_mpls_print_lsp_table(vty
, zvrf
, uj
);
349 DEFUN (show_mpls_table_lsp
,
350 show_mpls_table_lsp_cmd
,
351 "show mpls table (16-1048575) [json]",
355 "LSP to display information about\n"
359 struct zebra_vrf
*zvrf
;
360 bool uj
= use_json(argc
, argv
);
362 zvrf
= vrf_info_lookup(VRF_DEFAULT
);
363 label
= atoi(argv
[3]->arg
);
364 zebra_mpls_print_lsp(vty
, zvrf
, label
, uj
);
368 DEFUN (show_mpls_status
,
369 show_mpls_status_cmd
,
375 vty_out(vty
, "MPLS support enabled: %s\n",
376 (mpls_enabled
) ? "yes"
377 : "no (mpls kernel extensions not detected)");
381 static int zebra_mpls_global_block(struct vty
*vty
, int add_cmd
,
382 const char *start_label_str
,
383 const char *end_label_str
)
386 uint32_t start_label
;
388 struct zebra_vrf
*zvrf
;
390 zvrf
= zebra_vrf_lookup_by_id(VRF_DEFAULT
);
392 vty_out(vty
, "%% Default VRF does not exist\n");
393 return CMD_WARNING_CONFIG_FAILED
;
397 if (!start_label_str
|| !end_label_str
) {
398 vty_out(vty
, "%% Labels not specified\n");
399 return CMD_WARNING_CONFIG_FAILED
;
402 start_label
= atoi(start_label_str
);
403 end_label
= atoi(end_label_str
);
404 if (!IS_MPLS_UNRESERVED_LABEL(start_label
)
405 || !IS_MPLS_UNRESERVED_LABEL(end_label
)) {
406 vty_out(vty
, "%% Invalid label\n");
407 return CMD_WARNING_CONFIG_FAILED
;
409 if (end_label
< start_label
) {
410 vty_out(vty
, "%% End label is less than Start label\n");
411 return CMD_WARNING_CONFIG_FAILED
;
414 ret
= zebra_mpls_label_block_add(zvrf
, start_label
, end_label
);
416 ret
= zebra_mpls_label_block_del(zvrf
);
419 vty_out(vty
, "%% Global label block could not be %s\n",
420 add_cmd
? "added" : "deleted");
421 return CMD_WARNING_CONFIG_FAILED
;
427 DEFUN (mpls_label_global_block
,
428 mpls_label_global_block_cmd
,
429 "mpls label global-block (16-1048575) (16-1048575)",
431 "Label configuration\n"
432 "Configure global label block\n"
436 return zebra_mpls_global_block(vty
, 1, argv
[3]->arg
, argv
[4]->arg
);
439 DEFUN (no_mpls_label_global_block
,
440 no_mpls_label_global_block_cmd
,
441 "no mpls label global-block [(16-1048575) (16-1048575)]",
444 "Label configuration\n"
445 "Configure global label block\n"
449 return zebra_mpls_global_block(vty
, 0, NULL
, NULL
);
452 /* MPLS node for MPLS LSP. */
453 static struct cmd_node mpls_node
= {
460 void zebra_mpls_vty_init(void)
462 install_element(VIEW_NODE
, &show_mpls_status_cmd
);
464 install_node(&mpls_node
, zebra_mpls_config
);
466 install_element(CONFIG_NODE
, &mpls_transit_lsp_cmd
);
467 install_element(CONFIG_NODE
, &no_mpls_transit_lsp_cmd
);
468 install_element(CONFIG_NODE
, &no_mpls_transit_lsp_out_label_cmd
);
469 install_element(CONFIG_NODE
, &no_mpls_transit_lsp_all_cmd
);
471 install_element(CONFIG_NODE
, &mpls_label_bind_cmd
);
472 install_element(CONFIG_NODE
, &no_mpls_label_bind_cmd
);
474 install_element(CONFIG_NODE
, &mpls_label_global_block_cmd
);
475 install_element(CONFIG_NODE
, &no_mpls_label_global_block_cmd
);
477 install_element(VIEW_NODE
, &show_mpls_table_cmd
);
478 install_element(VIEW_NODE
, &show_mpls_table_lsp_cmd
);
479 install_element(VIEW_NODE
, &show_mpls_fec_cmd
);