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"
40 #include "zebra/zebra_static.h"
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
,
47 struct zebra_vrf
*zvrf
;
49 enum nexthop_types_t gtype
;
52 mpls_label_t in_label
, out_label
;
56 "%% MPLS not turned on in kernel, ignoring command\n");
57 return CMD_WARNING_CONFIG_FAILED
;
60 zvrf
= vrf_info_lookup(VRF_DEFAULT
);
62 vty_out(vty
, "%% Default VRF does not exist\n");
63 return CMD_WARNING_CONFIG_FAILED
;
67 vty_out(vty
, "%% No Label Information\n");
68 return CMD_WARNING_CONFIG_FAILED
;
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
;
80 vty_out(vty
, "%% No Nexthop Information\n");
81 return CMD_WARNING_CONFIG_FAILED
;
84 vty_out(vty
, "%% No Outgoing label Information\n");
85 return CMD_WARNING_CONFIG_FAILED
;
90 gtype
= NEXTHOP_TYPE_BLACKHOLE
; /* as initialization */
93 /* Gateway is a IPv4 or IPv6 nexthop. */
94 ret
= inet_pton(AF_INET6
, gate_str
, &gate
.ipv6
);
96 gtype
= NEXTHOP_TYPE_IPV6
;
98 ret
= inet_pton(AF_INET
, gate_str
, &gate
.ipv4
);
100 gtype
= NEXTHOP_TYPE_IPV4
;
102 vty_out(vty
, "%% Invalid nexthop\n");
103 return CMD_WARNING_CONFIG_FAILED
;
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
;
116 out_label
= atoi(outlabel_str
);
120 #if defined(HAVE_CUMULUS)
121 /* Check that label value is consistent. */
122 if (!zebra_mpls_lsp_label_consistent(zvrf
, in_label
, out_label
,
124 vty_out(vty
, "%% Label value not consistent\n");
125 return CMD_WARNING_CONFIG_FAILED
;
127 #endif /* HAVE_CUMULUS */
129 ret
= zebra_mpls_static_lsp_add(zvrf
, in_label
, out_label
,
132 ret
= zebra_mpls_static_lsp_del(zvrf
, in_label
, gtype
, &gate
,
136 vty_out(vty
, "%% LSP cannot be %s\n",
137 add_cmd
? "added" : "deleted");
138 return CMD_WARNING_CONFIG_FAILED
;
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>",
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")
156 return zebra_mpls_transit_lsp(vty
, 1, argv
[2]->arg
, argv
[3]->arg
,
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>",
165 "Establish label switched path\n"
166 "Incoming MPLS label\n"
167 "IPv4 gateway address\n"
168 "IPv6 gateway address\n")
170 return zebra_mpls_transit_lsp(vty
, 0, argv
[3]->arg
, argv
[4]->arg
, NULL
,
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>",
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")
185 DEFUN (no_mpls_transit_lsp_all
,
186 no_mpls_transit_lsp_all_cmd
,
187 "no mpls lsp (16-1048575)",
190 "Establish label switched path\n"
191 "Incoming MPLS label\n")
193 return zebra_mpls_transit_lsp(vty
, 0, argv
[3]->arg
, NULL
, NULL
, NULL
);
196 static int zebra_mpls_bind(struct vty
*vty
, int add_cmd
, const char *prefix
,
197 const char *label_str
)
199 struct zebra_vrf
*zvrf
;
204 zvrf
= vrf_info_lookup(VRF_DEFAULT
);
206 vty_out(vty
, "%% Default VRF does not exist\n");
207 return CMD_WARNING_CONFIG_FAILED
;
210 memset(&p
, 0, sizeof(struct prefix
));
211 ret
= str2prefix(prefix
, &p
);
213 vty_out(vty
, "%% Malformed address\n");
214 return CMD_WARNING_CONFIG_FAILED
;
219 vty_out(vty
, "%% No label binding specified\n");
220 return CMD_WARNING_CONFIG_FAILED
;
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
;
229 label
= MPLS_V6_EXP_NULL_LABEL
;
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
;
236 if (zebra_mpls_label_already_bound(zvrf
, label
)) {
238 "%% Label already bound to a FEC\n");
239 return CMD_WARNING_CONFIG_FAILED
;
243 ret
= zebra_mpls_static_fec_add(zvrf
, &p
, label
);
245 ret
= zebra_mpls_static_fec_del(zvrf
, &p
);
248 vty_out(vty
, "%% FEC to label binding cannot be %s\n",
249 add_cmd
? "added" : "deleted");
250 return CMD_WARNING_CONFIG_FAILED
;
256 DEFUN (mpls_label_bind
,
258 "mpls label bind <A.B.C.D/M|X:X::X:X/M> <(16-1048575)|implicit-null|explicit-null>",
260 "Label configuration\n"
261 "Establish FEC to label binding\n"
264 "MPLS Label to bind\n"
265 "Use Implicit-Null Label\n"
266 "Use Explicit-Null Label\n")
268 return zebra_mpls_bind(vty
, 1, argv
[3]->arg
, argv
[4]->arg
);
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>]",
276 "Label configuration\n"
277 "Establish FEC to label binding\n"
280 "MPLS Label to bind\n"
281 "Use Implicit-Null Label\n")
283 return zebra_mpls_bind(vty
, 0, argv
[4]->arg
, NULL
);
286 /* Static route configuration. */
287 DEFUN (ip_route_label
,
289 "ip route A.B.C.D/M <A.B.C.D|INTERFACE|null0> label WORD",
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"
298 return zebra_static_ipv4(vty
, SAFI_UNICAST
, 1, argv
[2]->arg
, NULL
,
299 argv
[3]->arg
, NULL
, NULL
, NULL
, NULL
,
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",
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"
312 "Set tag for this route\n"
316 return zebra_static_ipv4(vty
, SAFI_UNICAST
, 1, argv
[2]->arg
, NULL
,
317 argv
[3]->arg
, NULL
, argv
[5]->arg
, NULL
, NULL
,
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",
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"
334 return zebra_static_ipv4(vty
, SAFI_UNICAST
, 1, argv
[2]->arg
,
335 argv
[3]->arg
, argv
[4]->arg
, NULL
, NULL
, NULL
,
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",
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"
349 "Set tag for this route\n"
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
);
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",
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"
368 "Distance value for this route\n"
371 return zebra_static_ipv4(vty
, SAFI_UNICAST
, 1, argv
[2]->arg
, NULL
,
372 argv
[3]->arg
, NULL
, NULL
, argv
[4]->arg
, NULL
,
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",
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"
385 "Set tag for this route\n"
387 "Distance value for this route\n"
390 return zebra_static_ipv4(vty
, SAFI_UNICAST
, 1, argv
[2]->arg
, NULL
,
391 argv
[3]->arg
, NULL
, argv
[5]->arg
, argv
[6]->arg
,
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",
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"
405 "Distance value for this route\n"
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
);
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",
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"
423 "Set tag for this route\n"
425 "Distance value for this route\n"
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
);
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",
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"
445 return zebra_static_ipv4(vty
, SAFI_UNICAST
, 0, argv
[3]->arg
, NULL
,
446 argv
[4]->arg
, NULL
, NULL
, NULL
, NULL
,
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",
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"
460 "Tag of this route\n"
464 return zebra_static_ipv4(vty
, SAFI_UNICAST
, 0, argv
[3]->arg
, NULL
,
465 argv
[4]->arg
, NULL
, argv
[6]->arg
, NULL
, NULL
,
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",
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"
482 return zebra_static_ipv4(vty
, SAFI_UNICAST
, 0, argv
[3]->arg
,
483 argv
[4]->arg
, argv
[5]->arg
, NULL
, NULL
, NULL
,
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",
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"
498 "Tag of this route\n"
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
);
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",
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"
517 "Distance value for this route\n"
520 return zebra_static_ipv4(vty
, SAFI_UNICAST
, 0, argv
[3]->arg
, NULL
,
521 argv
[4]->arg
, NULL
, NULL
, argv
[5]->arg
, NULL
,
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",
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"
535 "Tag of this route\n"
537 "Distance value for this route\n"
540 return zebra_static_ipv4(vty
, SAFI_UNICAST
, 0, argv
[3]->arg
, NULL
,
541 argv
[4]->arg
, NULL
, argv
[6]->arg
, argv
[7]->arg
,
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",
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"
556 "Distance value for this route\n"
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
);
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",
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"
575 "Tag of this route\n"
577 "Distance value for this route\n"
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
);
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",
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"
595 return static_ipv6_func(vty
, 1, argv
[2]->arg
, NULL
, argv
[3]->arg
, NULL
,
596 NULL
, NULL
, NULL
, NULL
, argv
[5]->arg
);
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",
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"
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
);
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",
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"
625 return static_ipv6_func(vty
, 1, argv
[2]->arg
, NULL
, argv
[3]->arg
,
626 argv
[4]->arg
, NULL
, NULL
, NULL
, NULL
,
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",
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"
641 return static_ipv6_func(vty
, 1, argv
[2]->arg
, NULL
, argv
[3]->arg
,
642 argv
[4]->arg
, NULL
, argv
[6]->arg
, NULL
, NULL
,
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",
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"
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
);
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",
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"
671 "Distance value for this prefix\n"
674 return static_ipv6_func(vty
, 1, argv
[2]->arg
, NULL
, argv
[3]->arg
, NULL
,
675 NULL
, argv
[5]->arg
, argv
[6]->arg
, NULL
,
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",
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"
690 return static_ipv6_func(vty
, 1, argv
[2]->arg
, NULL
, argv
[3]->arg
,
691 argv
[4]->arg
, NULL
, NULL
, argv
[5]->arg
, NULL
,
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",
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"
705 "Distance value for this prefix\n"
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
,
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",
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"
724 return static_ipv6_func(vty
, 0, argv
[3]->arg
, NULL
, argv
[4]->arg
, NULL
,
725 NULL
, NULL
, NULL
, NULL
, argv
[6]->arg
);
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",
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"
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
);
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",
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"
756 return static_ipv6_func(vty
, 0, argv
[3]->arg
, NULL
, argv
[4]->arg
,
757 argv
[5]->arg
, NULL
, NULL
, NULL
, NULL
,
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",
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"
774 return static_ipv6_func(vty
, 0, argv
[3]->arg
, NULL
, argv
[4]->arg
,
775 argv
[5]->arg
, NULL
, argv
[7]->arg
, NULL
, NULL
,
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",
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"
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
);
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",
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"
806 "Distance value for this prefix\n"
809 return static_ipv6_func(vty
, 0, argv
[3]->arg
, NULL
, argv
[4]->arg
, NULL
,
810 NULL
, argv
[6]->arg
, argv
[7]->arg
, NULL
,
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",
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"
826 return static_ipv6_func(vty
, 0, argv
[3]->arg
, NULL
, argv
[4]->arg
,
827 argv
[5]->arg
, NULL
, NULL
, argv
[6]->arg
, NULL
,
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",
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"
842 "Distance value for this prefix\n"
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
);
850 /* MPLS LSP configuration write function. */
851 static int zebra_mpls_config(struct vty
*vty
)
854 struct zebra_vrf
*zvrf
;
856 zvrf
= vrf_info_lookup(VRF_DEFAULT
);
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
);
866 DEFUN (show_mpls_fec
,
868 "show mpls fec [<A.B.C.D/M|X:X::X:X/M>]",
872 "FEC to display information about\n"
873 "FEC to display information about\n")
875 struct zebra_vrf
*zvrf
;
879 zvrf
= vrf_info_lookup(VRF_DEFAULT
);
884 zebra_mpls_print_fec_table(vty
, zvrf
);
886 memset(&p
, 0, sizeof(struct prefix
));
887 ret
= str2prefix(argv
[3]->arg
, &p
);
889 vty_out(vty
, "%% Malformed address\n");
892 zebra_mpls_print_fec(vty
, zvrf
, &p
);
898 DEFUN (show_mpls_table
,
900 "show mpls table [json]",
906 struct zebra_vrf
*zvrf
;
907 u_char uj
= use_json(argc
, argv
);
909 zvrf
= vrf_info_lookup(VRF_DEFAULT
);
910 zebra_mpls_print_lsp_table(vty
, zvrf
, uj
);
914 DEFUN (show_mpls_table_lsp
,
915 show_mpls_table_lsp_cmd
,
916 "show mpls table (16-1048575) [json]",
920 "LSP to display information about\n"
924 struct zebra_vrf
*zvrf
;
925 u_char uj
= use_json(argc
, argv
);
927 zvrf
= vrf_info_lookup(VRF_DEFAULT
);
928 label
= atoi(argv
[3]->arg
);
929 zebra_mpls_print_lsp(vty
, zvrf
, label
, uj
);
933 DEFUN (show_mpls_status
,
934 show_mpls_status_cmd
,
940 vty_out(vty
, "MPLS support enabled: %s\n",
941 (mpls_enabled
) ? "yes"
942 : "no (mpls kernel extensions not detected)");
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
)
951 u_int32_t start_label
;
953 struct zebra_vrf
*zvrf
;
955 zvrf
= zebra_vrf_lookup_by_id(VRF_DEFAULT
);
957 vty_out(vty
, "%% Default VRF does not exist\n");
958 return CMD_WARNING_CONFIG_FAILED
;
962 if (!start_label_str
|| !end_label_str
) {
963 vty_out(vty
, "%% Labels not specified\n");
964 return CMD_WARNING_CONFIG_FAILED
;
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
;
974 if (end_label
< start_label
) {
975 vty_out(vty
, "%% End label is less than Start label\n");
976 return CMD_WARNING_CONFIG_FAILED
;
979 ret
= zebra_mpls_label_block_add(zvrf
, start_label
, end_label
);
981 ret
= zebra_mpls_label_block_del(zvrf
);
984 vty_out(vty
, "%% Global label block could not be %s\n",
985 add_cmd
? "added" : "deleted");
986 return CMD_WARNING_CONFIG_FAILED
;
992 DEFUN (mpls_label_global_block
,
993 mpls_label_global_block_cmd
,
994 "mpls label global-block (16-1048575) (16-1048575)",
996 "Label configuration\n"
997 "Configure global label block\n"
1001 return zebra_mpls_global_block(vty
, 1, argv
[3]->arg
, argv
[4]->arg
);
1004 DEFUN (no_mpls_label_global_block
,
1005 no_mpls_label_global_block_cmd
,
1006 "no mpls label global-block [(16-1048575) (16-1048575)]",
1009 "Label configuration\n"
1010 "Configure global label block\n"
1014 return zebra_mpls_global_block(vty
, 0, NULL
, NULL
);
1017 /* MPLS node for MPLS LSP. */
1018 static struct cmd_node mpls_node
= {MPLS_NODE
, "", 1};
1021 void zebra_mpls_vty_init(void)
1023 install_element(VIEW_NODE
, &show_mpls_status_cmd
);
1025 install_node(&mpls_node
, zebra_mpls_config
);
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
);
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
);
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
);
1068 install_element(CONFIG_NODE
, &mpls_label_global_block_cmd
);
1069 install_element(CONFIG_NODE
, &no_mpls_label_global_block_cmd
);
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
);