]> git.proxmox.com Git - mirror_frr.git/blob - zebra/zebra_mpls_vty.c
merge with upstream
[mirror_frr.git] / zebra / zebra_mpls_vty.c
1 /* Zebra MPLS VTY functions
2 * Copyright (C) 2002 Kunihiro Ishiguro
3 *
4 * This file is part of GNU Zebra.
5 *
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
9 * later version.
10 *
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.
15 *
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
19 */
20
21 #include <zebra.h>
22
23 #include "memory.h"
24 #include "if.h"
25 #include "prefix.h"
26 #include "command.h"
27 #include "table.h"
28 #include "rib.h"
29 #include "nexthop.h"
30 #include "vrf.h"
31 #include "mpls.h"
32 #include "lib/json.h"
33
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"
40 #include "zebra/zebra_static.h"
41
42 static int zebra_mpls_transit_lsp(struct vty *vty, int add_cmd,
43 const char *inlabel_str, const char *gate_str,
44 const char *outlabel_str,
45 const char *flag_str)
46 {
47 struct zebra_vrf *zvrf;
48 int ret;
49 enum nexthop_types_t gtype;
50 union g_addr gate;
51 mpls_label_t label;
52 mpls_label_t in_label, out_label;
53
54 if (!mpls_enabled) {
55 vty_out(vty,
56 "%% MPLS not turned on in kernel, ignoring command\n");
57 return CMD_WARNING_CONFIG_FAILED;
58 }
59
60 zvrf = vrf_info_lookup(VRF_DEFAULT);
61 if (!zvrf) {
62 vty_out(vty, "%% Default VRF does not exist\n");
63 return CMD_WARNING_CONFIG_FAILED;
64 }
65
66 if (!inlabel_str) {
67 vty_out(vty, "%% No Label Information\n");
68 return CMD_WARNING_CONFIG_FAILED;
69 }
70
71 out_label = MPLS_IMP_NULL_LABEL; /* as initialization */
72 label = atoi(inlabel_str);
73 if (!IS_MPLS_UNRESERVED_LABEL(label)) {
74 vty_out(vty, "%% Invalid label\n");
75 return CMD_WARNING_CONFIG_FAILED;
76 }
77
78 if (add_cmd) {
79 if (!gate_str) {
80 vty_out(vty, "%% No Nexthop Information\n");
81 return CMD_WARNING_CONFIG_FAILED;
82 }
83 if (!outlabel_str) {
84 vty_out(vty, "%% No Outgoing label Information\n");
85 return CMD_WARNING_CONFIG_FAILED;
86 }
87 }
88
89 in_label = label;
90 gtype = NEXTHOP_TYPE_BLACKHOLE; /* as initialization */
91
92 if (gate_str) {
93 /* Gateway is a IPv4 or IPv6 nexthop. */
94 ret = inet_pton(AF_INET6, gate_str, &gate.ipv6);
95 if (ret)
96 gtype = NEXTHOP_TYPE_IPV6;
97 else {
98 ret = inet_pton(AF_INET, gate_str, &gate.ipv4);
99 if (ret)
100 gtype = NEXTHOP_TYPE_IPV4;
101 else {
102 vty_out(vty, "%% Invalid nexthop\n");
103 return CMD_WARNING_CONFIG_FAILED;
104 }
105 }
106 }
107
108 if (outlabel_str) {
109 if (outlabel_str[0] == 'i')
110 out_label = MPLS_IMP_NULL_LABEL;
111 else if (outlabel_str[0] == 'e' && gtype == NEXTHOP_TYPE_IPV4)
112 out_label = MPLS_V4_EXP_NULL_LABEL;
113 else if (outlabel_str[0] == 'e' && gtype == NEXTHOP_TYPE_IPV6)
114 out_label = MPLS_V6_EXP_NULL_LABEL;
115 else
116 out_label = atoi(outlabel_str);
117 }
118
119 if (add_cmd) {
120 #if defined(HAVE_CUMULUS)
121 /* Check that label value is consistent. */
122 if (!zebra_mpls_lsp_label_consistent(zvrf, in_label, out_label,
123 gtype, &gate, 0)) {
124 vty_out(vty, "%% Label value not consistent\n");
125 return CMD_WARNING_CONFIG_FAILED;
126 }
127 #endif /* HAVE_CUMULUS */
128
129 ret = zebra_mpls_static_lsp_add(zvrf, in_label, out_label,
130 gtype, &gate, 0);
131 } else
132 ret = zebra_mpls_static_lsp_del(zvrf, in_label, gtype, &gate,
133 0);
134
135 if (ret) {
136 vty_out(vty, "%% LSP cannot be %s\n",
137 add_cmd ? "added" : "deleted");
138 return CMD_WARNING_CONFIG_FAILED;
139 }
140
141 return CMD_SUCCESS;
142 }
143
144 DEFUN (mpls_transit_lsp,
145 mpls_transit_lsp_cmd,
146 "mpls lsp (16-1048575) <A.B.C.D|X:X::X:X> <(16-1048575)|explicit-null|implicit-null>",
147 MPLS_STR
148 "Establish label switched path\n"
149 "Incoming MPLS label\n"
150 "IPv4 gateway address\n"
151 "IPv6 gateway address\n"
152 "Outgoing MPLS label\n"
153 "Use Explicit-Null label\n"
154 "Use Implicit-Null label\n")
155 {
156 return zebra_mpls_transit_lsp(vty, 1, argv[2]->arg, argv[3]->arg,
157 argv[4]->arg, NULL);
158 }
159
160 DEFUN (no_mpls_transit_lsp,
161 no_mpls_transit_lsp_cmd,
162 "no mpls lsp (16-1048575) <A.B.C.D|X:X::X:X>",
163 NO_STR
164 MPLS_STR
165 "Establish label switched path\n"
166 "Incoming MPLS label\n"
167 "IPv4 gateway address\n"
168 "IPv6 gateway address\n")
169 {
170 return zebra_mpls_transit_lsp(vty, 0, argv[3]->arg, argv[4]->arg, NULL,
171 NULL);
172 }
173
174 ALIAS(no_mpls_transit_lsp, no_mpls_transit_lsp_out_label_cmd,
175 "no mpls lsp (16-1048575) <A.B.C.D|X:X::X:X> <(16-1048575)|explicit-null|implicit-null>",
176 NO_STR MPLS_STR
177 "Establish label switched path\n"
178 "Incoming MPLS label\n"
179 "IPv4 gateway address\n"
180 "IPv6 gateway address\n"
181 "Outgoing MPLS label\n"
182 "Use Explicit-Null label\n"
183 "Use Implicit-Null label\n")
184
185 DEFUN (no_mpls_transit_lsp_all,
186 no_mpls_transit_lsp_all_cmd,
187 "no mpls lsp (16-1048575)",
188 NO_STR
189 MPLS_STR
190 "Establish label switched path\n"
191 "Incoming MPLS label\n")
192 {
193 return zebra_mpls_transit_lsp(vty, 0, argv[3]->arg, NULL, NULL, NULL);
194 }
195
196 static int zebra_mpls_bind(struct vty *vty, int add_cmd, const char *prefix,
197 const char *label_str)
198 {
199 struct zebra_vrf *zvrf;
200 struct prefix p;
201 u_int32_t label;
202 int ret;
203
204 zvrf = vrf_info_lookup(VRF_DEFAULT);
205 if (!zvrf) {
206 vty_out(vty, "%% Default VRF does not exist\n");
207 return CMD_WARNING_CONFIG_FAILED;
208 }
209
210 memset(&p, 0, sizeof(struct prefix));
211 ret = str2prefix(prefix, &p);
212 if (ret <= 0) {
213 vty_out(vty, "%% Malformed address\n");
214 return CMD_WARNING_CONFIG_FAILED;
215 }
216
217 if (add_cmd) {
218 if (!label_str) {
219 vty_out(vty, "%% No label binding specified\n");
220 return CMD_WARNING_CONFIG_FAILED;
221 }
222
223 if (!strcmp(label_str, "implicit-null"))
224 label = MPLS_IMP_NULL_LABEL;
225 else if (!strcmp(label_str, "explicit-null")) {
226 if (p.family == AF_INET)
227 label = MPLS_V4_EXP_NULL_LABEL;
228 else
229 label = MPLS_V6_EXP_NULL_LABEL;
230 } else {
231 label = atoi(label_str);
232 if (!IS_MPLS_UNRESERVED_LABEL(label)) {
233 vty_out(vty, "%% Invalid label\n");
234 return CMD_WARNING_CONFIG_FAILED;
235 }
236 if (zebra_mpls_label_already_bound(zvrf, label)) {
237 vty_out(vty,
238 "%% Label already bound to a FEC\n");
239 return CMD_WARNING_CONFIG_FAILED;
240 }
241 }
242
243 ret = zebra_mpls_static_fec_add(zvrf, &p, label);
244 } else
245 ret = zebra_mpls_static_fec_del(zvrf, &p);
246
247 if (ret) {
248 vty_out(vty, "%% FEC to label binding cannot be %s\n",
249 add_cmd ? "added" : "deleted");
250 return CMD_WARNING_CONFIG_FAILED;
251 }
252
253 return CMD_SUCCESS;
254 }
255
256 DEFUN (mpls_label_bind,
257 mpls_label_bind_cmd,
258 "mpls label bind <A.B.C.D/M|X:X::X:X/M> <(16-1048575)|implicit-null|explicit-null>",
259 MPLS_STR
260 "Label configuration\n"
261 "Establish FEC to label binding\n"
262 "IPv4 prefix\n"
263 "IPv6 prefix\n"
264 "MPLS Label to bind\n"
265 "Use Implicit-Null Label\n"
266 "Use Explicit-Null Label\n")
267 {
268 return zebra_mpls_bind(vty, 1, argv[3]->arg, argv[4]->arg);
269 }
270
271 DEFUN (no_mpls_label_bind,
272 no_mpls_label_bind_cmd,
273 "no mpls label bind <A.B.C.D/M|X:X::X:X/M> [<(16-1048575)|implicit-null>]",
274 NO_STR
275 MPLS_STR
276 "Label configuration\n"
277 "Establish FEC to label binding\n"
278 "IPv4 prefix\n"
279 "IPv6 prefix\n"
280 "MPLS Label to bind\n"
281 "Use Implicit-Null Label\n")
282 {
283 return zebra_mpls_bind(vty, 0, argv[4]->arg, NULL);
284 }
285
286 /* Static route configuration. */
287 DEFUN (ip_route_label,
288 ip_route_label_cmd,
289 "ip route A.B.C.D/M <A.B.C.D|INTERFACE|null0> label WORD",
290 IP_STR
291 "Establish static routes\n"
292 "IP destination prefix (e.g. 10.0.0.0/8)\n"
293 "IP gateway address\n"
294 "IP gateway interface name\n"
295 "Null interface\n"
296 MPLS_LABEL_HELPSTR)
297 {
298 return zebra_static_ipv4(vty, SAFI_UNICAST, 1, argv[2]->arg, NULL,
299 argv[3]->arg, NULL, NULL, NULL, NULL,
300 argv[5]->arg);
301 }
302
303 DEFUN (ip_route_tag_label,
304 ip_route_tag_label_cmd,
305 "ip route A.B.C.D/M <A.B.C.D|INTERFACE|null0> tag (1-4294967295) label WORD",
306 IP_STR
307 "Establish static routes\n"
308 "IP destination prefix (e.g. 10.0.0.0/8)\n"
309 "IP gateway address\n"
310 "IP gateway interface name\n"
311 "Null interface\n"
312 "Set tag for this route\n"
313 "Tag value\n"
314 MPLS_LABEL_HELPSTR)
315 {
316 return zebra_static_ipv4(vty, SAFI_UNICAST, 1, argv[2]->arg, NULL,
317 argv[3]->arg, NULL, argv[5]->arg, NULL, NULL,
318 argv[7]->arg);
319 }
320
321 /* Mask as A.B.C.D format. */
322 DEFUN (ip_route_mask_label,
323 ip_route_mask_label_cmd,
324 "ip route A.B.C.D A.B.C.D <A.B.C.D|INTERFACE|null0> label WORD",
325 IP_STR
326 "Establish static routes\n"
327 "IP destination prefix\n"
328 "IP destination prefix mask\n"
329 "IP gateway address\n"
330 "IP gateway interface name\n"
331 "Null interface\n"
332 MPLS_LABEL_HELPSTR)
333 {
334 return zebra_static_ipv4(vty, SAFI_UNICAST, 1, argv[2]->arg,
335 argv[3]->arg, argv[4]->arg, NULL, NULL, NULL,
336 NULL, argv[6]->arg);
337 }
338
339 DEFUN (ip_route_mask_tag_label,
340 ip_route_mask_tag_label_cmd,
341 "ip route A.B.C.D A.B.C.D <A.B.C.D|INTERFACE|null0> tag (1-4294967295) label WORD",
342 IP_STR
343 "Establish static routes\n"
344 "IP destination prefix\n"
345 "IP destination prefix mask\n"
346 "IP gateway address\n"
347 "IP gateway interface name\n"
348 "Null interface\n"
349 "Set tag for this route\n"
350 "Tag value\n"
351 MPLS_LABEL_HELPSTR)
352 {
353 return zebra_static_ipv4(vty, SAFI_UNICAST, 1, argv[2]->arg,
354 argv[3]->arg, argv[4]->arg, NULL, argv[6]->arg,
355 NULL, NULL, argv[8]->arg);
356 }
357
358 /* Distance option value. */
359 DEFUN (ip_route_distance_label,
360 ip_route_distance_label_cmd,
361 "ip route A.B.C.D/M <A.B.C.D|INTERFACE|null0> (1-255) label WORD",
362 IP_STR
363 "Establish static routes\n"
364 "IP destination prefix (e.g. 10.0.0.0/8)\n"
365 "IP gateway address\n"
366 "IP gateway interface name\n"
367 "Null interface\n"
368 "Distance value for this route\n"
369 MPLS_LABEL_HELPSTR)
370 {
371 return zebra_static_ipv4(vty, SAFI_UNICAST, 1, argv[2]->arg, NULL,
372 argv[3]->arg, NULL, NULL, argv[4]->arg, NULL,
373 argv[6]->arg);
374 }
375
376 DEFUN (ip_route_tag_distance_label,
377 ip_route_tag_distance_label_cmd,
378 "ip route A.B.C.D/M <A.B.C.D|INTERFACE|null0> tag (1-4294967295) (1-255) label WORD",
379 IP_STR
380 "Establish static routes\n"
381 "IP destination prefix (e.g. 10.0.0.0/8)\n"
382 "IP gateway address\n"
383 "IP gateway interface name\n"
384 "Null interface\n"
385 "Set tag for this route\n"
386 "Tag value\n"
387 "Distance value for this route\n"
388 MPLS_LABEL_HELPSTR)
389 {
390 return zebra_static_ipv4(vty, SAFI_UNICAST, 1, argv[2]->arg, NULL,
391 argv[3]->arg, NULL, argv[5]->arg, argv[6]->arg,
392 NULL, argv[8]->arg);
393 }
394
395 DEFUN (ip_route_mask_distance_label,
396 ip_route_mask_distance_label_cmd,
397 "ip route A.B.C.D A.B.C.D <A.B.C.D|INTERFACE|null0> (1-255) label WORD",
398 IP_STR
399 "Establish static routes\n"
400 "IP destination prefix\n"
401 "IP destination prefix mask\n"
402 "IP gateway address\n"
403 "IP gateway interface name\n"
404 "Null interface\n"
405 "Distance value for this route\n"
406 MPLS_LABEL_HELPSTR)
407 {
408 return zebra_static_ipv4(vty, SAFI_UNICAST, 1, argv[2]->arg,
409 argv[3]->arg, argv[4]->arg, NULL, NULL,
410 argv[5]->arg, NULL, argv[7]->arg);
411 }
412
413 DEFUN (ip_route_mask_tag_distance_label,
414 ip_route_mask_tag_distance_label_cmd,
415 "ip route A.B.C.D A.B.C.D <A.B.C.D|INTERFACE|null0> tag (1-4294967295) (1-255) label WORD",
416 IP_STR
417 "Establish static routes\n"
418 "IP destination prefix\n"
419 "IP destination prefix mask\n"
420 "IP gateway address\n"
421 "IP gateway interface name\n"
422 "Null interface\n"
423 "Set tag for this route\n"
424 "Tag value\n"
425 "Distance value for this route\n"
426 MPLS_LABEL_HELPSTR)
427 {
428 return zebra_static_ipv4(vty, SAFI_UNICAST, 1, argv[2]->arg,
429 argv[3]->arg, argv[4]->arg, NULL, argv[6]->arg,
430 argv[7]->arg, NULL, argv[9]->arg);
431 }
432
433 DEFUN (no_ip_route_label,
434 no_ip_route_label_cmd,
435 "no ip route A.B.C.D/M <A.B.C.D|INTERFACE|null0> label WORD",
436 NO_STR
437 IP_STR
438 "Establish static routes\n"
439 "IP destination prefix (e.g. 10.0.0.0/8)\n"
440 "IP gateway address\n"
441 "IP gateway interface name\n"
442 "Null interface\n"
443 MPLS_LABEL_HELPSTR)
444 {
445 return zebra_static_ipv4(vty, SAFI_UNICAST, 0, argv[3]->arg, NULL,
446 argv[4]->arg, NULL, NULL, NULL, NULL,
447 argv[6]->arg);
448 }
449
450 DEFUN (no_ip_route_tag_label,
451 no_ip_route_tag_label_cmd,
452 "no ip route A.B.C.D/M <A.B.C.D|INTERFACE|null0> tag (1-4294967295) label WORD",
453 NO_STR
454 IP_STR
455 "Establish static routes\n"
456 "IP destination prefix (e.g. 10.0.0.0/8)\n"
457 "IP gateway address\n"
458 "IP gateway interface name\n"
459 "Null interface\n"
460 "Tag of this route\n"
461 "Tag value\n"
462 MPLS_LABEL_HELPSTR)
463 {
464 return zebra_static_ipv4(vty, SAFI_UNICAST, 0, argv[3]->arg, NULL,
465 argv[4]->arg, NULL, argv[6]->arg, NULL, NULL,
466 argv[8]->arg);
467 }
468
469 DEFUN (no_ip_route_mask_label,
470 no_ip_route_mask_label_cmd,
471 "no ip route A.B.C.D A.B.C.D <A.B.C.D|INTERFACE|null0> label WORD",
472 NO_STR
473 IP_STR
474 "Establish static routes\n"
475 "IP destination prefix\n"
476 "IP destination prefix mask\n"
477 "IP gateway address\n"
478 "IP gateway interface name\n"
479 "Null interface\n"
480 MPLS_LABEL_HELPSTR)
481 {
482 return zebra_static_ipv4(vty, SAFI_UNICAST, 0, argv[3]->arg,
483 argv[4]->arg, argv[5]->arg, NULL, NULL, NULL,
484 NULL, argv[7]->arg);
485 }
486
487 DEFUN (no_ip_route_mask_tag_label,
488 no_ip_route_mask_tag_label_cmd,
489 "no ip route A.B.C.D A.B.C.D <A.B.C.D|INTERFACE|null0> tag (1-4294967295) label WORD",
490 NO_STR
491 IP_STR
492 "Establish static routes\n"
493 "IP destination prefix\n"
494 "IP destination prefix mask\n"
495 "IP gateway address\n"
496 "IP gateway interface name\n"
497 "Null interface\n"
498 "Tag of this route\n"
499 "Tag value\n"
500 MPLS_LABEL_HELPSTR)
501 {
502 return zebra_static_ipv4(vty, SAFI_UNICAST, 0, argv[3]->arg,
503 argv[4]->arg, argv[5]->arg, NULL, argv[7]->arg,
504 NULL, NULL, argv[9]->arg);
505 }
506
507 DEFUN (no_ip_route_distance_label,
508 no_ip_route_distance_label_cmd,
509 "no ip route A.B.C.D/M <A.B.C.D|INTERFACE|null0> (1-255) label WORD",
510 NO_STR
511 IP_STR
512 "Establish static routes\n"
513 "IP destination prefix (e.g. 10.0.0.0/8)\n"
514 "IP gateway address\n"
515 "IP gateway interface name\n"
516 "Null interface\n"
517 "Distance value for this route\n"
518 MPLS_LABEL_HELPSTR)
519 {
520 return zebra_static_ipv4(vty, SAFI_UNICAST, 0, argv[3]->arg, NULL,
521 argv[4]->arg, NULL, NULL, argv[5]->arg, NULL,
522 argv[7]->arg);
523 }
524
525 DEFUN (no_ip_route_tag_distance_label,
526 no_ip_route_tag_distance_label_cmd,
527 "no ip route A.B.C.D/M <A.B.C.D|INTERFACE|null0> tag (1-4294967295) (1-255) label WORD",
528 NO_STR
529 IP_STR
530 "Establish static routes\n"
531 "IP destination prefix (e.g. 10.0.0.0/8)\n"
532 "IP gateway address\n"
533 "IP gateway interface name\n"
534 "Null interface\n"
535 "Tag of this route\n"
536 "Tag value\n"
537 "Distance value for this route\n"
538 MPLS_LABEL_HELPSTR)
539 {
540 return zebra_static_ipv4(vty, SAFI_UNICAST, 0, argv[3]->arg, NULL,
541 argv[4]->arg, NULL, argv[6]->arg, argv[7]->arg,
542 NULL, argv[9]->arg);
543 }
544
545 DEFUN (no_ip_route_mask_distance_label,
546 no_ip_route_mask_distance_label_cmd,
547 "no ip route A.B.C.D A.B.C.D <A.B.C.D|INTERFACE|null0> (1-255) label WORD",
548 NO_STR
549 IP_STR
550 "Establish static routes\n"
551 "IP destination prefix\n"
552 "IP destination prefix mask\n"
553 "IP gateway address\n"
554 "IP gateway interface name\n"
555 "Null interface\n"
556 "Distance value for this route\n"
557 MPLS_LABEL_HELPSTR)
558 {
559 return zebra_static_ipv4(vty, SAFI_UNICAST, 0, argv[3]->arg,
560 argv[4]->arg, argv[5]->arg, NULL, NULL,
561 argv[6]->arg, NULL, argv[8]->arg);
562 }
563
564 DEFUN (no_ip_route_mask_tag_distance_label,
565 no_ip_route_mask_tag_distance_label_cmd,
566 "no ip route A.B.C.D A.B.C.D <A.B.C.D|INTERFACE|null0> tag (1-4294967295) (1-255) label WORD",
567 NO_STR
568 IP_STR
569 "Establish static routes\n"
570 "IP destination prefix\n"
571 "IP destination prefix mask\n"
572 "IP gateway address\n"
573 "IP gateway interface name\n"
574 "Null interface\n"
575 "Tag of this route\n"
576 "Tag value\n"
577 "Distance value for this route\n"
578 MPLS_LABEL_HELPSTR)
579 {
580 return zebra_static_ipv4(vty, SAFI_UNICAST, 0, argv[3]->arg,
581 argv[4]->arg, argv[5]->arg, NULL, argv[7]->arg,
582 argv[8]->arg, NULL, argv[10]->arg);
583 }
584
585 DEFUN (ipv6_route_label,
586 ipv6_route_label_cmd,
587 "ipv6 route X:X::X:X/M <X:X::X:X|INTERFACE> label WORD",
588 IP_STR
589 "Establish static routes\n"
590 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
591 "IPv6 gateway address\n"
592 "IPv6 gateway interface name\n"
593 MPLS_LABEL_HELPSTR)
594 {
595 return static_ipv6_func(vty, 1, argv[2]->arg, NULL, argv[3]->arg, NULL,
596 NULL, NULL, NULL, NULL, argv[5]->arg);
597 }
598
599 DEFUN (ipv6_route_tag_label,
600 ipv6_route_tag_label_cmd,
601 "ipv6 route X:X::X:X/M <X:X::X:X|INTERFACE> tag (1-4294967295) label WORD",
602 IP_STR
603 "Establish static routes\n"
604 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
605 "IPv6 gateway address\n"
606 "IPv6 gateway interface name\n"
607 "Set tag for this route\n"
608 "Tag value\n"
609 MPLS_LABEL_HELPSTR)
610 {
611 return static_ipv6_func(vty, 1, argv[2]->arg, NULL, argv[3]->arg, NULL,
612 NULL, argv[5]->arg, NULL, NULL, argv[7]->arg);
613 }
614
615 DEFUN (ipv6_route_ifname_label,
616 ipv6_route_ifname_label_cmd,
617 "ipv6 route X:X::X:X/M X:X::X:X INTERFACE label WORD",
618 IP_STR
619 "Establish static routes\n"
620 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
621 "IPv6 gateway address\n"
622 "IPv6 gateway interface name\n"
623 MPLS_LABEL_HELPSTR)
624 {
625 return static_ipv6_func(vty, 1, argv[2]->arg, NULL, argv[3]->arg,
626 argv[4]->arg, NULL, NULL, NULL, NULL,
627 argv[6]->arg);
628 }
629 DEFUN (ipv6_route_ifname_tag_label,
630 ipv6_route_ifname_tag_label_cmd,
631 "ipv6 route X:X::X:X/M X:X::X:X INTERFACE tag (1-4294967295) label WORD",
632 IP_STR
633 "Establish static routes\n"
634 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
635 "IPv6 gateway address\n"
636 "IPv6 gateway interface name\n"
637 "Set tag for this route\n"
638 "Tag value\n"
639 MPLS_LABEL_HELPSTR)
640 {
641 return static_ipv6_func(vty, 1, argv[2]->arg, NULL, argv[3]->arg,
642 argv[4]->arg, NULL, argv[6]->arg, NULL, NULL,
643 argv[8]->arg);
644 }
645
646 DEFUN (ipv6_route_pref_label,
647 ipv6_route_pref_label_cmd,
648 "ipv6 route X:X::X:X/M <X:X::X:X|INTERFACE> (1-255) label WORD",
649 IP_STR
650 "Establish static routes\n"
651 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
652 "IPv6 gateway address\n"
653 "IPv6 gateway interface name\n"
654 "Distance value for this prefix\n"
655 MPLS_LABEL_HELPSTR)
656 {
657 return static_ipv6_func(vty, 1, argv[2]->arg, NULL, argv[3]->arg, NULL,
658 NULL, NULL, argv[4]->arg, NULL, argv[6]->arg);
659 }
660
661 DEFUN (ipv6_route_pref_tag_label,
662 ipv6_route_pref_tag_label_cmd,
663 "ipv6 route X:X::X:X/M <X:X::X:X|INTERFACE> tag (1-4294967295) (1-255) label WORD",
664 IP_STR
665 "Establish static routes\n"
666 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
667 "IPv6 gateway address\n"
668 "IPv6 gateway interface name\n"
669 "Set tag for this route\n"
670 "Tag value\n"
671 "Distance value for this prefix\n"
672 MPLS_LABEL_HELPSTR)
673 {
674 return static_ipv6_func(vty, 1, argv[2]->arg, NULL, argv[3]->arg, NULL,
675 NULL, argv[5]->arg, argv[6]->arg, NULL,
676 argv[8]->arg);
677 }
678
679 DEFUN (ipv6_route_ifname_pref_label,
680 ipv6_route_ifname_pref_label_cmd,
681 "ipv6 route X:X::X:X/M X:X::X:X INTERFACE (1-255) label WORD",
682 IP_STR
683 "Establish static routes\n"
684 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
685 "IPv6 gateway address\n"
686 "IPv6 gateway interface name\n"
687 "Distance value for this prefix\n"
688 MPLS_LABEL_HELPSTR)
689 {
690 return static_ipv6_func(vty, 1, argv[2]->arg, NULL, argv[3]->arg,
691 argv[4]->arg, NULL, NULL, argv[5]->arg, NULL,
692 argv[7]->arg);
693 }
694
695 DEFUN (ipv6_route_ifname_pref_tag_label,
696 ipv6_route_ifname_pref_tag_label_cmd,
697 "ipv6 route X:X::X:X/M X:X::X:X INTERFACE tag (1-4294967295) (1-255) label WORD",
698 IP_STR
699 "Establish static routes\n"
700 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
701 "IPv6 gateway address\n"
702 "IPv6 gateway interface name\n"
703 "Set tag for this route\n"
704 "Tag value\n"
705 "Distance value for this prefix\n"
706 MPLS_LABEL_HELPSTR)
707 {
708 return static_ipv6_func(vty, 1, argv[2]->arg, NULL, argv[3]->arg,
709 argv[4]->arg, NULL, argv[6]->arg, argv[7]->arg,
710 NULL, argv[9]->arg);
711 }
712
713 DEFUN (no_ipv6_route_label,
714 no_ipv6_route_label_cmd,
715 "no ipv6 route X:X::X:X/M <X:X::X:X|INTERFACE> label WORD",
716 NO_STR
717 IP_STR
718 "Establish static routes\n"
719 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
720 "IPv6 gateway address\n"
721 "IPv6 gateway interface name\n"
722 MPLS_LABEL_HELPSTR)
723 {
724 return static_ipv6_func(vty, 0, argv[3]->arg, NULL, argv[4]->arg, NULL,
725 NULL, NULL, NULL, NULL, argv[6]->arg);
726 }
727
728 DEFUN (no_ipv6_route_tag_label,
729 no_ipv6_route_tag_label_cmd,
730 "no ipv6 route X:X::X:X/M <X:X::X:X|INTERFACE> tag (1-4294967295) label WORD",
731 NO_STR
732 IP_STR
733 "Establish static routes\n"
734 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
735 "IPv6 gateway address\n"
736 "IPv6 gateway interface name\n"
737 "Set tag for this route\n"
738 "Tag value\n"
739 MPLS_LABEL_HELPSTR)
740 {
741 return static_ipv6_func(vty, 0, argv[3]->arg, NULL, argv[4]->arg, NULL,
742 NULL, argv[6]->arg, NULL, NULL, argv[8]->arg);
743 }
744
745 DEFUN (no_ipv6_route_ifname_label,
746 no_ipv6_route_ifname_label_cmd,
747 "no ipv6 route X:X::X:X/M X:X::X:X INTERFACE label WORD",
748 NO_STR
749 IP_STR
750 "Establish static routes\n"
751 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
752 "IPv6 gateway address\n"
753 "IPv6 gateway interface name\n"
754 MPLS_LABEL_HELPSTR)
755 {
756 return static_ipv6_func(vty, 0, argv[3]->arg, NULL, argv[4]->arg,
757 argv[5]->arg, NULL, NULL, NULL, NULL,
758 argv[7]->arg);
759 }
760
761 DEFUN (no_ipv6_route_ifname_tag_label,
762 no_ipv6_route_ifname_tag_label_cmd,
763 "no ipv6 route X:X::X:X/M X:X::X:X INTERFACE tag (1-4294967295) label WORD",
764 NO_STR
765 IP_STR
766 "Establish static routes\n"
767 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
768 "IPv6 gateway address\n"
769 "IPv6 gateway interface name\n"
770 "Set tag for this route\n"
771 "Tag value\n"
772 MPLS_LABEL_HELPSTR)
773 {
774 return static_ipv6_func(vty, 0, argv[3]->arg, NULL, argv[4]->arg,
775 argv[5]->arg, NULL, argv[7]->arg, NULL, NULL,
776 argv[9]->arg);
777 }
778
779 DEFUN (no_ipv6_route_pref_label,
780 no_ipv6_route_pref_label_cmd,
781 "no ipv6 route X:X::X:X/M <X:X::X:X|INTERFACE> (1-255) label WORD",
782 NO_STR
783 IP_STR
784 "Establish static routes\n"
785 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
786 "IPv6 gateway address\n"
787 "IPv6 gateway interface name\n"
788 "Distance value for this prefix\n"
789 MPLS_LABEL_HELPSTR)
790 {
791 return static_ipv6_func(vty, 0, argv[3]->arg, NULL, argv[4]->arg, NULL,
792 NULL, NULL, argv[5]->arg, NULL, argv[7]->arg);
793 }
794
795 DEFUN (no_ipv6_route_pref_tag_label,
796 no_ipv6_route_pref_tag_label_cmd,
797 "no ipv6 route X:X::X:X/M <X:X::X:X|INTERFACE> tag (1-4294967295) (1-255) label WORD",
798 NO_STR
799 IP_STR
800 "Establish static routes\n"
801 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
802 "IPv6 gateway address\n"
803 "IPv6 gateway interface name\n"
804 "Set tag for this route\n"
805 "Tag value\n"
806 "Distance value for this prefix\n"
807 MPLS_LABEL_HELPSTR)
808 {
809 return static_ipv6_func(vty, 0, argv[3]->arg, NULL, argv[4]->arg, NULL,
810 NULL, argv[6]->arg, argv[7]->arg, NULL,
811 argv[9]->arg);
812 }
813
814 DEFUN (no_ipv6_route_ifname_pref_label,
815 no_ipv6_route_ifname_pref_label_cmd,
816 "no ipv6 route X:X::X:X/M X:X::X:X INTERFACE (1-255) label WORD",
817 NO_STR
818 IP_STR
819 "Establish static routes\n"
820 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
821 "IPv6 gateway address\n"
822 "IPv6 gateway interface name\n"
823 "Distance value for this prefix\n"
824 MPLS_LABEL_HELPSTR)
825 {
826 return static_ipv6_func(vty, 0, argv[3]->arg, NULL, argv[4]->arg,
827 argv[5]->arg, NULL, NULL, argv[6]->arg, NULL,
828 argv[8]->arg);
829 }
830
831 DEFUN (no_ipv6_route_ifname_pref_tag_label,
832 no_ipv6_route_ifname_pref_tag_label_cmd,
833 "no ipv6 route X:X::X:X/M X:X::X:X INTERFACE tag (1-4294967295) (1-255) label WORD",
834 NO_STR
835 IP_STR
836 "Establish static routes\n"
837 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
838 "IPv6 gateway address\n"
839 "IPv6 gateway interface name\n"
840 "Set tag for this route\n"
841 "Tag value\n"
842 "Distance value for this prefix\n"
843 MPLS_LABEL_HELPSTR)
844 {
845 return static_ipv6_func(vty, 0, argv[3]->arg, NULL, argv[4]->arg,
846 argv[5]->arg, NULL, argv[7]->arg, argv[8]->arg,
847 NULL, argv[10]->arg);
848 }
849
850 /* MPLS LSP configuration write function. */
851 static int zebra_mpls_config(struct vty *vty)
852 {
853 int write = 0;
854 struct zebra_vrf *zvrf;
855
856 zvrf = vrf_info_lookup(VRF_DEFAULT);
857 if (!zvrf)
858 return 0;
859
860 write += zebra_mpls_write_lsp_config(vty, zvrf);
861 write += zebra_mpls_write_fec_config(vty, zvrf);
862 write += zebra_mpls_write_label_block_config(vty, zvrf);
863 return write;
864 }
865
866 DEFUN (show_mpls_fec,
867 show_mpls_fec_cmd,
868 "show mpls fec [<A.B.C.D/M|X:X::X:X/M>]",
869 SHOW_STR
870 MPLS_STR
871 "MPLS FEC table\n"
872 "FEC to display information about\n"
873 "FEC to display information about\n")
874 {
875 struct zebra_vrf *zvrf;
876 struct prefix p;
877 int ret;
878
879 zvrf = vrf_info_lookup(VRF_DEFAULT);
880 if (!zvrf)
881 return 0;
882
883 if (argc == 3)
884 zebra_mpls_print_fec_table(vty, zvrf);
885 else {
886 memset(&p, 0, sizeof(struct prefix));
887 ret = str2prefix(argv[3]->arg, &p);
888 if (ret <= 0) {
889 vty_out(vty, "%% Malformed address\n");
890 return CMD_WARNING;
891 }
892 zebra_mpls_print_fec(vty, zvrf, &p);
893 }
894
895 return CMD_SUCCESS;
896 }
897
898 DEFUN (show_mpls_table,
899 show_mpls_table_cmd,
900 "show mpls table [json]",
901 SHOW_STR
902 MPLS_STR
903 "MPLS table\n"
904 JSON_STR)
905 {
906 struct zebra_vrf *zvrf;
907 u_char uj = use_json(argc, argv);
908
909 zvrf = vrf_info_lookup(VRF_DEFAULT);
910 zebra_mpls_print_lsp_table(vty, zvrf, uj);
911 return CMD_SUCCESS;
912 }
913
914 DEFUN (show_mpls_table_lsp,
915 show_mpls_table_lsp_cmd,
916 "show mpls table (16-1048575) [json]",
917 SHOW_STR
918 MPLS_STR
919 "MPLS table\n"
920 "LSP to display information about\n"
921 JSON_STR)
922 {
923 u_int32_t label;
924 struct zebra_vrf *zvrf;
925 u_char uj = use_json(argc, argv);
926
927 zvrf = vrf_info_lookup(VRF_DEFAULT);
928 label = atoi(argv[3]->arg);
929 zebra_mpls_print_lsp(vty, zvrf, label, uj);
930 return CMD_SUCCESS;
931 }
932
933 DEFUN (show_mpls_status,
934 show_mpls_status_cmd,
935 "show mpls status",
936 SHOW_STR
937 "MPLS information\n"
938 "MPLS status\n")
939 {
940 vty_out(vty, "MPLS support enabled: %s\n",
941 (mpls_enabled) ? "yes"
942 : "no (mpls kernel extensions not detected)");
943 return CMD_SUCCESS;
944 }
945
946 static int zebra_mpls_global_block(struct vty *vty, int add_cmd,
947 const char *start_label_str,
948 const char *end_label_str)
949 {
950 int ret;
951 u_int32_t start_label;
952 u_int32_t end_label;
953 struct zebra_vrf *zvrf;
954
955 zvrf = zebra_vrf_lookup_by_id(VRF_DEFAULT);
956 if (!zvrf) {
957 vty_out(vty, "%% Default VRF does not exist\n");
958 return CMD_WARNING_CONFIG_FAILED;
959 }
960
961 if (add_cmd) {
962 if (!start_label_str || !end_label_str) {
963 vty_out(vty, "%% Labels not specified\n");
964 return CMD_WARNING_CONFIG_FAILED;
965 }
966
967 start_label = atoi(start_label_str);
968 end_label = atoi(end_label_str);
969 if (!IS_MPLS_UNRESERVED_LABEL(start_label)
970 || !IS_MPLS_UNRESERVED_LABEL(end_label)) {
971 vty_out(vty, "%% Invalid label\n");
972 return CMD_WARNING_CONFIG_FAILED;
973 }
974 if (end_label < start_label) {
975 vty_out(vty, "%% End label is less than Start label\n");
976 return CMD_WARNING_CONFIG_FAILED;
977 }
978
979 ret = zebra_mpls_label_block_add(zvrf, start_label, end_label);
980 } else
981 ret = zebra_mpls_label_block_del(zvrf);
982
983 if (ret) {
984 vty_out(vty, "%% Global label block could not be %s\n",
985 add_cmd ? "added" : "deleted");
986 return CMD_WARNING_CONFIG_FAILED;
987 }
988
989 return CMD_SUCCESS;
990 }
991
992 DEFUN (mpls_label_global_block,
993 mpls_label_global_block_cmd,
994 "mpls label global-block (16-1048575) (16-1048575)",
995 MPLS_STR
996 "Label configuration\n"
997 "Configure global label block\n"
998 "Start label\n"
999 "End label\n")
1000 {
1001 return zebra_mpls_global_block(vty, 1, argv[3]->arg, argv[4]->arg);
1002 }
1003
1004 DEFUN (no_mpls_label_global_block,
1005 no_mpls_label_global_block_cmd,
1006 "no mpls label global-block [(16-1048575) (16-1048575)]",
1007 NO_STR
1008 MPLS_STR
1009 "Label configuration\n"
1010 "Configure global label block\n"
1011 "Start label\n"
1012 "End label\n")
1013 {
1014 return zebra_mpls_global_block(vty, 0, NULL, NULL);
1015 }
1016
1017 /* MPLS node for MPLS LSP. */
1018 static struct cmd_node mpls_node = {MPLS_NODE, "", 1};
1019
1020 /* MPLS VTY. */
1021 void zebra_mpls_vty_init(void)
1022 {
1023 install_element(VIEW_NODE, &show_mpls_status_cmd);
1024
1025 install_node(&mpls_node, zebra_mpls_config);
1026
1027 install_element(CONFIG_NODE, &ip_route_label_cmd);
1028 install_element(CONFIG_NODE, &ip_route_tag_label_cmd);
1029 install_element(CONFIG_NODE, &ip_route_mask_label_cmd);
1030 install_element(CONFIG_NODE, &ip_route_mask_tag_label_cmd);
1031 install_element(CONFIG_NODE, &no_ip_route_label_cmd);
1032 install_element(CONFIG_NODE, &no_ip_route_tag_label_cmd);
1033 install_element(CONFIG_NODE, &no_ip_route_mask_label_cmd);
1034 install_element(CONFIG_NODE, &no_ip_route_mask_tag_label_cmd);
1035 install_element(CONFIG_NODE, &ip_route_distance_label_cmd);
1036 install_element(CONFIG_NODE, &ip_route_tag_distance_label_cmd);
1037 install_element(CONFIG_NODE, &ip_route_mask_distance_label_cmd);
1038 install_element(CONFIG_NODE, &ip_route_mask_tag_distance_label_cmd);
1039 install_element(CONFIG_NODE, &no_ip_route_distance_label_cmd);
1040 install_element(CONFIG_NODE, &no_ip_route_tag_distance_label_cmd);
1041 install_element(CONFIG_NODE, &no_ip_route_mask_distance_label_cmd);
1042 install_element(CONFIG_NODE, &no_ip_route_mask_tag_distance_label_cmd);
1043
1044 install_element(CONFIG_NODE, &ipv6_route_label_cmd);
1045 install_element(CONFIG_NODE, &ipv6_route_ifname_label_cmd);
1046 install_element(CONFIG_NODE, &no_ipv6_route_label_cmd);
1047 install_element(CONFIG_NODE, &no_ipv6_route_ifname_label_cmd);
1048 install_element(CONFIG_NODE, &ipv6_route_pref_label_cmd);
1049 install_element(CONFIG_NODE, &ipv6_route_ifname_pref_label_cmd);
1050 install_element(CONFIG_NODE, &no_ipv6_route_pref_label_cmd);
1051 install_element(CONFIG_NODE, &no_ipv6_route_ifname_pref_label_cmd);
1052 install_element(CONFIG_NODE, &ipv6_route_tag_label_cmd);
1053 install_element(CONFIG_NODE, &ipv6_route_ifname_tag_label_cmd);
1054 install_element(CONFIG_NODE, &ipv6_route_pref_tag_label_cmd);
1055 install_element(CONFIG_NODE, &ipv6_route_ifname_pref_tag_label_cmd);
1056 install_element(CONFIG_NODE, &no_ipv6_route_tag_label_cmd);
1057 install_element(CONFIG_NODE, &no_ipv6_route_ifname_tag_label_cmd);
1058 install_element(CONFIG_NODE, &no_ipv6_route_pref_tag_label_cmd);
1059 install_element(CONFIG_NODE, &no_ipv6_route_ifname_pref_tag_label_cmd);
1060
1061 install_element(CONFIG_NODE, &mpls_transit_lsp_cmd);
1062 install_element(CONFIG_NODE, &no_mpls_transit_lsp_cmd);
1063 install_element(CONFIG_NODE, &no_mpls_transit_lsp_out_label_cmd);
1064 install_element(CONFIG_NODE, &no_mpls_transit_lsp_all_cmd);
1065 install_element(CONFIG_NODE, &mpls_label_bind_cmd);
1066 install_element(CONFIG_NODE, &no_mpls_label_bind_cmd);
1067
1068 install_element(CONFIG_NODE, &mpls_label_global_block_cmd);
1069 install_element(CONFIG_NODE, &no_mpls_label_global_block_cmd);
1070
1071 install_element(VIEW_NODE, &show_mpls_table_cmd);
1072 install_element(VIEW_NODE, &show_mpls_table_lsp_cmd);
1073 install_element(VIEW_NODE, &show_mpls_fec_cmd);
1074 }