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