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