]> git.proxmox.com Git - mirror_frr.git/blob - zebra/zebra_mpls_vty.c
Merge pull request #664 from opensourcerouting/ldpd-fixes
[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 MPLS_LABEL_HELPSTR)
325 {
326 return zebra_static_ipv4 (vty, SAFI_UNICAST, 1, argv[2]->arg, NULL, argv[3]->arg, NULL, NULL,
327 NULL, NULL, argv[5]->arg);
328 }
329
330 DEFUN (ip_route_tag_label,
331 ip_route_tag_label_cmd,
332 "ip route A.B.C.D/M <A.B.C.D|INTERFACE|null0> tag (1-4294967295) label WORD",
333 IP_STR
334 "Establish static routes\n"
335 "IP destination prefix (e.g. 10.0.0.0/8)\n"
336 "IP gateway address\n"
337 "IP gateway interface name\n"
338 "Null interface\n"
339 "Set tag for this route\n"
340 "Tag value\n"
341 MPLS_LABEL_HELPSTR)
342 {
343 return zebra_static_ipv4 (vty, SAFI_UNICAST, 1, argv[2]->arg, NULL, argv[3]->arg, NULL, argv[5]->arg,
344 NULL, NULL, argv[7]->arg);
345 }
346
347 /* Mask as A.B.C.D format. */
348 DEFUN (ip_route_mask_label,
349 ip_route_mask_label_cmd,
350 "ip route A.B.C.D A.B.C.D <A.B.C.D|INTERFACE|null0> label WORD",
351 IP_STR
352 "Establish static routes\n"
353 "IP destination prefix\n"
354 "IP destination prefix mask\n"
355 "IP gateway address\n"
356 "IP gateway interface name\n"
357 "Null interface\n"
358 MPLS_LABEL_HELPSTR)
359 {
360 return zebra_static_ipv4 (vty, SAFI_UNICAST, 1, argv[2]->arg, argv[3]->arg, argv[4]->arg, NULL, NULL,
361 NULL, NULL, argv[6]->arg);
362 }
363
364 DEFUN (ip_route_mask_tag_label,
365 ip_route_mask_tag_label_cmd,
366 "ip route A.B.C.D A.B.C.D <A.B.C.D|INTERFACE|null0> tag (1-4294967295) label WORD",
367 IP_STR
368 "Establish static routes\n"
369 "IP destination prefix\n"
370 "IP destination prefix mask\n"
371 "IP gateway address\n"
372 "IP gateway interface name\n"
373 "Null interface\n"
374 "Set tag for this route\n"
375 "Tag value\n"
376 MPLS_LABEL_HELPSTR)
377
378 {
379 return zebra_static_ipv4 (vty, SAFI_UNICAST, 1, argv[2]->arg, argv[3]->arg, argv[4]->arg, NULL, argv[6]->arg,
380 NULL, NULL, argv[8]->arg);
381 }
382
383 /* Distance option value. */
384 DEFUN (ip_route_distance_label,
385 ip_route_distance_label_cmd,
386 "ip route A.B.C.D/M <A.B.C.D|INTERFACE|null0> (1-255) label WORD",
387 IP_STR
388 "Establish static routes\n"
389 "IP destination prefix (e.g. 10.0.0.0/8)\n"
390 "IP gateway address\n"
391 "IP gateway interface name\n"
392 "Null interface\n"
393 "Distance value for this route\n"
394 MPLS_LABEL_HELPSTR)
395 {
396 return zebra_static_ipv4 (vty, SAFI_UNICAST, 1, argv[2]->arg, NULL, argv[3]->arg, NULL, NULL,
397 argv[4]->arg, NULL, argv[6]->arg);
398 }
399
400 DEFUN (ip_route_tag_distance_label,
401 ip_route_tag_distance_label_cmd,
402 "ip route A.B.C.D/M <A.B.C.D|INTERFACE|null0> tag (1-4294967295) (1-255) label WORD",
403 IP_STR
404 "Establish static routes\n"
405 "IP destination prefix (e.g. 10.0.0.0/8)\n"
406 "IP gateway address\n"
407 "IP gateway interface name\n"
408 "Null interface\n"
409 "Set tag for this route\n"
410 "Tag value\n"
411 "Distance value for this route\n"
412 MPLS_LABEL_HELPSTR)
413
414 {
415 return zebra_static_ipv4 (vty, SAFI_UNICAST, 1, argv[2]->arg, NULL, argv[3]->arg, NULL, argv[5]->arg,
416 argv[6]->arg, NULL, argv[8]->arg);
417 }
418
419 DEFUN (ip_route_mask_distance_label,
420 ip_route_mask_distance_label_cmd,
421 "ip route A.B.C.D A.B.C.D <A.B.C.D|INTERFACE|null0> (1-255) label WORD",
422 IP_STR
423 "Establish static routes\n"
424 "IP destination prefix\n"
425 "IP destination prefix mask\n"
426 "IP gateway address\n"
427 "IP gateway interface name\n"
428 "Null interface\n"
429 "Distance value for this route\n"
430 MPLS_LABEL_HELPSTR)
431 {
432 return zebra_static_ipv4 (vty, SAFI_UNICAST, 1, argv[2]->arg, argv[3]->arg, argv[4]->arg, NULL, NULL,
433 argv[5]->arg, NULL, argv[7]->arg);
434 }
435
436 DEFUN (ip_route_mask_tag_distance_label,
437 ip_route_mask_tag_distance_label_cmd,
438 "ip route A.B.C.D A.B.C.D <A.B.C.D|INTERFACE|null0> tag (1-4294967295) (1-255) label WORD",
439 IP_STR
440 "Establish static routes\n"
441 "IP destination prefix\n"
442 "IP destination prefix mask\n"
443 "IP gateway address\n"
444 "IP gateway interface name\n"
445 "Null interface\n"
446 "Set tag for this route\n"
447 "Tag value\n"
448 "Distance value for this route\n"
449 MPLS_LABEL_HELPSTR)
450 {
451 return zebra_static_ipv4 (vty, SAFI_UNICAST, 1, argv[2]->arg, argv[3]->arg, argv[4]->arg, NULL, argv[6]->arg,
452 argv[7]->arg, NULL, argv[9]->arg);
453 }
454
455 DEFUN (no_ip_route_label,
456 no_ip_route_label_cmd,
457 "no ip route A.B.C.D/M <A.B.C.D|INTERFACE|null0> label WORD",
458 NO_STR
459 IP_STR
460 "Establish static routes\n"
461 "IP destination prefix (e.g. 10.0.0.0/8)\n"
462 "IP gateway address\n"
463 "IP gateway interface name\n"
464 "Null interface\n"
465 MPLS_LABEL_HELPSTR)
466 {
467 return zebra_static_ipv4 (vty, SAFI_UNICAST, 0, argv[3]->arg, NULL, argv[4]->arg, NULL, NULL,
468 NULL, NULL, argv[6]->arg);
469 }
470
471 DEFUN (no_ip_route_tag_label,
472 no_ip_route_tag_label_cmd,
473 "no ip route A.B.C.D/M <A.B.C.D|INTERFACE|null0> tag (1-4294967295) label WORD",
474 NO_STR
475 IP_STR
476 "Establish static routes\n"
477 "IP destination prefix (e.g. 10.0.0.0/8)\n"
478 "IP gateway address\n"
479 "IP gateway interface name\n"
480 "Null interface\n"
481 "Tag of this route\n"
482 "Tag value\n"
483 MPLS_LABEL_HELPSTR)
484 {
485 return zebra_static_ipv4 (vty, SAFI_UNICAST, 0, argv[3]->arg, NULL, argv[4]->arg, NULL, argv[6]->arg,
486 NULL, NULL, argv[8]->arg);
487 }
488
489 DEFUN (no_ip_route_mask_label,
490 no_ip_route_mask_label_cmd,
491 "no ip route A.B.C.D A.B.C.D <A.B.C.D|INTERFACE|null0> label WORD",
492 NO_STR
493 IP_STR
494 "Establish static routes\n"
495 "IP destination prefix\n"
496 "IP destination prefix mask\n"
497 "IP gateway address\n"
498 "IP gateway interface name\n"
499 "Null interface\n"
500 MPLS_LABEL_HELPSTR)
501 {
502 return zebra_static_ipv4 (vty, SAFI_UNICAST, 0, argv[3]->arg, argv[4]->arg, argv[5]->arg, NULL, NULL,
503 NULL, NULL, argv[7]->arg);
504 }
505
506 DEFUN (no_ip_route_mask_tag_label,
507 no_ip_route_mask_tag_label_cmd,
508 "no ip route A.B.C.D A.B.C.D <A.B.C.D|INTERFACE|null0> tag (1-4294967295) label WORD",
509 NO_STR
510 IP_STR
511 "Establish static routes\n"
512 "IP destination prefix\n"
513 "IP destination prefix mask\n"
514 "IP gateway address\n"
515 "IP gateway interface name\n"
516 "Null interface\n"
517 "Tag of this route\n"
518 "Tag value\n"
519 MPLS_LABEL_HELPSTR)
520 {
521 return zebra_static_ipv4 (vty, SAFI_UNICAST, 0, argv[3]->arg, argv[4]->arg, argv[5]->arg, NULL, argv[7]->arg,
522 NULL, NULL, argv[9]->arg);
523 }
524
525 DEFUN (no_ip_route_distance_label,
526 no_ip_route_distance_label_cmd,
527 "no ip route A.B.C.D/M <A.B.C.D|INTERFACE|null0> (1-255) label WORD",
528 NO_STR
529 IP_STR
530 "Establish static routes\n"
531 "IP destination prefix (e.g. 10.0.0.0/8)\n"
532 "IP gateway address\n"
533 "IP gateway interface name\n"
534 "Null interface\n"
535 "Distance value for this route\n"
536 MPLS_LABEL_HELPSTR)
537 {
538 return zebra_static_ipv4 (vty, SAFI_UNICAST, 0, argv[3]->arg, NULL, argv[4]->arg, NULL, NULL,
539 argv[5]->arg, NULL, argv[7]->arg);
540 }
541
542 DEFUN (no_ip_route_tag_distance_label,
543 no_ip_route_tag_distance_label_cmd,
544 "no ip route A.B.C.D/M <A.B.C.D|INTERFACE|null0> tag (1-4294967295) (1-255) label WORD",
545 NO_STR
546 IP_STR
547 "Establish static routes\n"
548 "IP destination prefix (e.g. 10.0.0.0/8)\n"
549 "IP gateway address\n"
550 "IP gateway interface name\n"
551 "Null interface\n"
552 "Tag of this route\n"
553 "Tag value\n"
554 "Distance value for this route\n"
555 MPLS_LABEL_HELPSTR)
556 {
557 return zebra_static_ipv4 (vty, SAFI_UNICAST, 0, argv[3]->arg, NULL, argv[4]->arg, NULL, argv[6]->arg,
558 argv[7]->arg, NULL, argv[9]->arg);
559 }
560
561 DEFUN (no_ip_route_mask_distance_label,
562 no_ip_route_mask_distance_label_cmd,
563 "no ip route A.B.C.D A.B.C.D <A.B.C.D|INTERFACE|null0> (1-255) label WORD",
564 NO_STR
565 IP_STR
566 "Establish static routes\n"
567 "IP destination prefix\n"
568 "IP destination prefix mask\n"
569 "IP gateway address\n"
570 "IP gateway interface name\n"
571 "Null interface\n"
572 "Distance value for this route\n"
573 MPLS_LABEL_HELPSTR)
574 {
575 return zebra_static_ipv4 (vty, SAFI_UNICAST, 0, argv[3]->arg, argv[4]->arg, argv[5]->arg, NULL, NULL,
576 argv[6]->arg, NULL, argv[8]->arg);
577 }
578
579 DEFUN (no_ip_route_mask_tag_distance_label,
580 no_ip_route_mask_tag_distance_label_cmd,
581 "no ip route A.B.C.D A.B.C.D <A.B.C.D|INTERFACE|null0> tag (1-4294967295) (1-255) label WORD",
582 NO_STR
583 IP_STR
584 "Establish static routes\n"
585 "IP destination prefix\n"
586 "IP destination prefix mask\n"
587 "IP gateway address\n"
588 "IP gateway interface name\n"
589 "Null interface\n"
590 "Tag of this route\n"
591 "Tag value\n"
592 "Distance value for this route\n"
593 MPLS_LABEL_HELPSTR)
594 {
595 return zebra_static_ipv4 (vty, SAFI_UNICAST, 0, argv[3]->arg, argv[4]->arg, argv[5]->arg, NULL, argv[7]->arg,
596 argv[8]->arg, NULL, argv[10]->arg);
597 }
598
599 DEFUN (ipv6_route_label,
600 ipv6_route_label_cmd,
601 "ipv6 route X:X::X:X/M <X:X::X:X|INTERFACE> label WORD",
602 IP_STR
603 "Establish static routes\n"
604 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
605 "IPv6 gateway address\n"
606 "IPv6 gateway interface name\n"
607 MPLS_LABEL_HELPSTR)
608 {
609 return static_ipv6_func (vty, 1, argv[2]->arg, NULL, argv[3]->arg, NULL, NULL, NULL, NULL, NULL, argv[5]->arg);
610 }
611
612 DEFUN (ipv6_route_tag_label,
613 ipv6_route_tag_label_cmd,
614 "ipv6 route X:X::X:X/M <X:X::X:X|INTERFACE> tag (1-4294967295) label WORD",
615 IP_STR
616 "Establish static routes\n"
617 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
618 "IPv6 gateway address\n"
619 "IPv6 gateway interface name\n"
620 "Set tag for this route\n"
621 "Tag value\n"
622 MPLS_LABEL_HELPSTR)
623 {
624 return static_ipv6_func (vty, 1, argv[2]->arg, NULL, argv[3]->arg, NULL, NULL, argv[5]->arg, NULL, NULL, argv[7]->arg);
625 }
626
627 DEFUN (ipv6_route_ifname_label,
628 ipv6_route_ifname_label_cmd,
629 "ipv6 route X:X::X:X/M X:X::X:X INTERFACE label WORD",
630 IP_STR
631 "Establish static routes\n"
632 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
633 "IPv6 gateway address\n"
634 "IPv6 gateway interface name\n"
635 MPLS_LABEL_HELPSTR)
636 {
637 return static_ipv6_func (vty, 1, argv[2]->arg, NULL, argv[3]->arg, argv[4]->arg, NULL, NULL, NULL, NULL, argv[6]->arg);
638 }
639 DEFUN (ipv6_route_ifname_tag_label,
640 ipv6_route_ifname_tag_label_cmd,
641 "ipv6 route X:X::X:X/M X:X::X:X INTERFACE tag (1-4294967295) label WORD",
642 IP_STR
643 "Establish static routes\n"
644 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
645 "IPv6 gateway address\n"
646 "IPv6 gateway interface name\n"
647 "Set tag for this route\n"
648 "Tag value\n"
649 MPLS_LABEL_HELPSTR)
650 {
651 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);
652 }
653
654 DEFUN (ipv6_route_pref_label,
655 ipv6_route_pref_label_cmd,
656 "ipv6 route X:X::X:X/M <X:X::X:X|INTERFACE> (1-255) label WORD",
657 IP_STR
658 "Establish static routes\n"
659 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
660 "IPv6 gateway address\n"
661 "IPv6 gateway interface name\n"
662 "Distance value for this prefix\n"
663 MPLS_LABEL_HELPSTR)
664 {
665 return static_ipv6_func (vty, 1, argv[2]->arg, NULL, argv[3]->arg, NULL, NULL, NULL, argv[4]->arg, NULL, argv[6]->arg);
666 }
667
668 DEFUN (ipv6_route_pref_tag_label,
669 ipv6_route_pref_tag_label_cmd,
670 "ipv6 route X:X::X:X/M <X:X::X:X|INTERFACE> tag (1-4294967295) (1-255) label WORD",
671 IP_STR
672 "Establish static routes\n"
673 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
674 "IPv6 gateway address\n"
675 "IPv6 gateway interface name\n"
676 "Set tag for this route\n"
677 "Tag value\n"
678 "Distance value for this prefix\n"
679 MPLS_LABEL_HELPSTR)
680 {
681 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);
682 }
683
684 DEFUN (ipv6_route_ifname_pref_label,
685 ipv6_route_ifname_pref_label_cmd,
686 "ipv6 route X:X::X:X/M X:X::X:X INTERFACE (1-255) label WORD",
687 IP_STR
688 "Establish static routes\n"
689 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
690 "IPv6 gateway address\n"
691 "IPv6 gateway interface name\n"
692 "Distance value for this prefix\n"
693 MPLS_LABEL_HELPSTR)
694 {
695 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);
696 }
697
698 DEFUN (ipv6_route_ifname_pref_tag_label,
699 ipv6_route_ifname_pref_tag_label_cmd,
700 "ipv6 route X:X::X:X/M X:X::X:X INTERFACE tag (1-4294967295) (1-255) label WORD",
701 IP_STR
702 "Establish static routes\n"
703 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
704 "IPv6 gateway address\n"
705 "IPv6 gateway interface name\n"
706 "Set tag for this route\n"
707 "Tag value\n"
708 "Distance value for this prefix\n"
709 MPLS_LABEL_HELPSTR)
710 {
711 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);
712 }
713
714 DEFUN (no_ipv6_route_label,
715 no_ipv6_route_label_cmd,
716 "no ipv6 route X:X::X:X/M <X:X::X:X|INTERFACE> label WORD",
717 NO_STR
718 IP_STR
719 "Establish static routes\n"
720 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
721 "IPv6 gateway address\n"
722 "IPv6 gateway interface name\n"
723 MPLS_LABEL_HELPSTR)
724 {
725 return static_ipv6_func (vty, 0, argv[3]->arg, NULL, argv[4]->arg, NULL, NULL, NULL, NULL, NULL, argv[6]->arg);
726 }
727
728 DEFUN (no_ipv6_route_tag_label,
729 no_ipv6_route_tag_label_cmd,
730 "no ipv6 route X:X::X:X/M <X:X::X:X|INTERFACE> tag (1-4294967295) label WORD",
731 NO_STR
732 IP_STR
733 "Establish static routes\n"
734 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
735 "IPv6 gateway address\n"
736 "IPv6 gateway interface name\n"
737 "Set tag for this route\n"
738 "Tag value\n"
739 MPLS_LABEL_HELPSTR)
740 {
741 return static_ipv6_func (vty, 0, argv[3]->arg, NULL, argv[4]->arg, NULL, NULL, argv[6]->arg, NULL, NULL, argv[8]->arg);
742 }
743
744 DEFUN (no_ipv6_route_ifname_label,
745 no_ipv6_route_ifname_label_cmd,
746 "no ipv6 route X:X::X:X/M X:X::X:X INTERFACE label WORD",
747 NO_STR
748 IP_STR
749 "Establish static routes\n"
750 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
751 "IPv6 gateway address\n"
752 "IPv6 gateway interface name\n"
753 MPLS_LABEL_HELPSTR)
754 {
755 return static_ipv6_func (vty, 0, argv[3]->arg, NULL, argv[4]->arg, argv[5]->arg, NULL, NULL, NULL, NULL, argv[7]->arg);
756 }
757
758 DEFUN (no_ipv6_route_ifname_tag_label,
759 no_ipv6_route_ifname_tag_label_cmd,
760 "no ipv6 route X:X::X:X/M X:X::X:X INTERFACE tag (1-4294967295) label WORD",
761 NO_STR
762 IP_STR
763 "Establish static routes\n"
764 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
765 "IPv6 gateway address\n"
766 "IPv6 gateway interface name\n"
767 "Set tag for this route\n"
768 "Tag value\n"
769 MPLS_LABEL_HELPSTR)
770 {
771 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);
772 }
773
774 DEFUN (no_ipv6_route_pref_label,
775 no_ipv6_route_pref_label_cmd,
776 "no ipv6 route X:X::X:X/M <X:X::X:X|INTERFACE> (1-255) label WORD",
777 NO_STR
778 IP_STR
779 "Establish static routes\n"
780 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
781 "IPv6 gateway address\n"
782 "IPv6 gateway interface name\n"
783 "Distance value for this prefix\n"
784 MPLS_LABEL_HELPSTR)
785 {
786 return static_ipv6_func (vty, 0, argv[3]->arg, NULL, argv[4]->arg, NULL, NULL, NULL, argv[5]->arg, NULL, argv[7]->arg);
787 }
788
789 DEFUN (no_ipv6_route_pref_tag_label,
790 no_ipv6_route_pref_tag_label_cmd,
791 "no ipv6 route X:X::X:X/M <X:X::X:X|INTERFACE> tag (1-4294967295) (1-255) label WORD",
792 NO_STR
793 IP_STR
794 "Establish static routes\n"
795 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
796 "IPv6 gateway address\n"
797 "IPv6 gateway interface name\n"
798 "Set tag for this route\n"
799 "Tag value\n"
800 "Distance value for this prefix\n"
801 MPLS_LABEL_HELPSTR)
802 {
803 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);
804 }
805
806 DEFUN (no_ipv6_route_ifname_pref_label,
807 no_ipv6_route_ifname_pref_label_cmd,
808 "no ipv6 route X:X::X:X/M X:X::X:X INTERFACE (1-255) label WORD",
809 NO_STR
810 IP_STR
811 "Establish static routes\n"
812 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
813 "IPv6 gateway address\n"
814 "IPv6 gateway interface name\n"
815 "Distance value for this prefix\n"
816 MPLS_LABEL_HELPSTR)
817 {
818 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);
819 }
820
821 DEFUN (no_ipv6_route_ifname_pref_tag_label,
822 no_ipv6_route_ifname_pref_tag_label_cmd,
823 "no ipv6 route X:X::X:X/M X:X::X:X INTERFACE tag (1-4294967295) (1-255) label WORD",
824 NO_STR
825 IP_STR
826 "Establish static routes\n"
827 "IPv6 destination prefix (e.g. 3ffe:506::/32)\n"
828 "IPv6 gateway address\n"
829 "IPv6 gateway interface name\n"
830 "Set tag for this route\n"
831 "Tag value\n"
832 "Distance value for this prefix\n"
833 MPLS_LABEL_HELPSTR)
834 {
835 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);
836 }
837
838 /* MPLS LSP configuration write function. */
839 static int
840 zebra_mpls_config (struct vty *vty)
841 {
842 int write = 0;
843 struct zebra_vrf *zvrf;
844
845 zvrf = vrf_info_lookup(VRF_DEFAULT);
846 if (!zvrf)
847 return 0;
848
849 write += zebra_mpls_write_lsp_config(vty, zvrf);
850 write += zebra_mpls_write_fec_config(vty, zvrf);
851 write += zebra_mpls_write_label_block_config (vty, zvrf);
852 return write;
853 }
854
855 DEFUN (show_mpls_fec,
856 show_mpls_fec_cmd,
857 "show mpls fec [<A.B.C.D/M|X:X::X:X/M>]",
858 SHOW_STR
859 MPLS_STR
860 "MPLS FEC table\n"
861 "FEC to display information about\n"
862 "FEC to display information about\n")
863 {
864 struct zebra_vrf *zvrf;
865 struct prefix p;
866 int ret;
867
868 zvrf = vrf_info_lookup(VRF_DEFAULT);
869 if (!zvrf)
870 return 0;
871
872 if (argc == 3)
873 zebra_mpls_print_fec_table(vty, zvrf);
874 else
875 {
876 memset(&p, 0, sizeof(struct prefix));
877 ret = str2prefix(argv[3]->arg, &p);
878 if (ret <= 0)
879 {
880 vty_out (vty, "%% Malformed address%s", VTY_NEWLINE);
881 return CMD_WARNING;
882 }
883 zebra_mpls_print_fec (vty, zvrf, &p);
884 }
885
886 return CMD_SUCCESS;
887 }
888
889 DEFUN (show_mpls_table,
890 show_mpls_table_cmd,
891 "show mpls table [json]",
892 SHOW_STR
893 MPLS_STR
894 "MPLS table\n"
895 JSON_STR)
896 {
897 struct zebra_vrf *zvrf;
898 u_char uj = use_json (argc, argv);
899
900 zvrf = vrf_info_lookup(VRF_DEFAULT);
901 zebra_mpls_print_lsp_table(vty, zvrf, uj);
902 return CMD_SUCCESS;
903 }
904
905 DEFUN (show_mpls_table_lsp,
906 show_mpls_table_lsp_cmd,
907 "show mpls table (16-1048575) [json]",
908 SHOW_STR
909 MPLS_STR
910 "MPLS table\n"
911 "LSP to display information about\n"
912 JSON_STR)
913 {
914 u_int32_t label;
915 struct zebra_vrf *zvrf;
916 u_char uj = use_json (argc, argv);
917
918 zvrf = vrf_info_lookup(VRF_DEFAULT);
919 label = atoi(argv[3]->arg);
920 zebra_mpls_print_lsp (vty, zvrf, label, uj);
921 return CMD_SUCCESS;
922 }
923
924 DEFUN (show_mpls_status,
925 show_mpls_status_cmd,
926 "show mpls status",
927 SHOW_STR
928 "MPLS information\n"
929 "MPLS status\n")
930 {
931 vty_out (vty, "MPLS support enabled: %s%s", (mpls_enabled) ? "yes" :
932 "no (mpls kernel extensions not detected)", VTY_NEWLINE);
933 return CMD_SUCCESS;
934 }
935
936 static int
937 zebra_mpls_global_block (struct vty *vty, int add_cmd,
938 const char *start_label_str, const char *end_label_str)
939 {
940 int ret;
941 u_int32_t start_label;
942 u_int32_t end_label;
943 struct zebra_vrf *zvrf;
944
945 zvrf = zebra_vrf_lookup_by_id(VRF_DEFAULT);
946 if (!zvrf)
947 {
948 vty_out (vty, "%% Default VRF does not exist%s", VTY_NEWLINE);
949 return CMD_WARNING;
950 }
951
952 if (add_cmd)
953 {
954 if (!start_label_str || !end_label_str)
955 {
956 vty_out (vty, "%% Labels not specified%s", VTY_NEWLINE);
957 return CMD_WARNING;
958 }
959
960 start_label = atoi(start_label_str);
961 end_label = atoi(end_label_str);
962 if (!IS_MPLS_UNRESERVED_LABEL(start_label) ||
963 !IS_MPLS_UNRESERVED_LABEL(end_label))
964 {
965 vty_out (vty, "%% Invalid label%s", VTY_NEWLINE);
966 return CMD_WARNING;
967 }
968 if (end_label < start_label)
969 {
970 vty_out (vty, "%% End label is less than Start label%s",
971 VTY_NEWLINE);
972 return CMD_WARNING;
973 }
974
975 ret = zebra_mpls_label_block_add (zvrf, start_label, end_label);
976 }
977 else
978 ret = zebra_mpls_label_block_del (zvrf);
979
980 if (ret)
981 {
982 vty_out (vty, "%% Global label block could not be %s%s",
983 add_cmd ? "added" : "deleted", VTY_NEWLINE);
984 return CMD_WARNING;
985 }
986
987 return CMD_SUCCESS;
988 }
989
990 DEFUN (mpls_label_global_block,
991 mpls_label_global_block_cmd,
992 "mpls label global-block (16-1048575) (16-1048575)",
993 MPLS_STR
994 "Label configuration\n"
995 "Configure global label block\n"
996 "Start label\n"
997 "End label\n")
998 {
999 return zebra_mpls_global_block (vty, 1, argv[3]->arg, argv[4]->arg);
1000 }
1001
1002 DEFUN (no_mpls_label_global_block,
1003 no_mpls_label_global_block_cmd,
1004 "no mpls label global-block [(16-1048575) (16-1048575)]",
1005 NO_STR
1006 MPLS_STR
1007 "Label configuration\n"
1008 "Configure global label block\n"
1009 "Start label\n"
1010 "End label\n")
1011 {
1012 return zebra_mpls_global_block (vty, 0, NULL, NULL);
1013 }
1014
1015 /* MPLS node for MPLS LSP. */
1016 static struct cmd_node mpls_node = { MPLS_NODE, "", 1 };
1017
1018 /* MPLS VTY. */
1019 void
1020 zebra_mpls_vty_init (void)
1021 {
1022 install_element (VIEW_NODE, &show_mpls_status_cmd);
1023
1024 install_node (&mpls_node, zebra_mpls_config);
1025
1026 install_element (CONFIG_NODE, &ip_route_label_cmd);
1027 install_element (CONFIG_NODE, &ip_route_tag_label_cmd);
1028 install_element (CONFIG_NODE, &ip_route_mask_label_cmd);
1029 install_element (CONFIG_NODE, &ip_route_mask_tag_label_cmd);
1030 install_element (CONFIG_NODE, &no_ip_route_label_cmd);
1031 install_element (CONFIG_NODE, &no_ip_route_tag_label_cmd);
1032 install_element (CONFIG_NODE, &no_ip_route_mask_label_cmd);
1033 install_element (CONFIG_NODE, &no_ip_route_mask_tag_label_cmd);
1034 install_element (CONFIG_NODE, &ip_route_distance_label_cmd);
1035 install_element (CONFIG_NODE, &ip_route_tag_distance_label_cmd);
1036 install_element (CONFIG_NODE, &ip_route_mask_distance_label_cmd);
1037 install_element (CONFIG_NODE, &ip_route_mask_tag_distance_label_cmd);
1038 install_element (CONFIG_NODE, &no_ip_route_distance_label_cmd);
1039 install_element (CONFIG_NODE, &no_ip_route_tag_distance_label_cmd);
1040 install_element (CONFIG_NODE, &no_ip_route_mask_distance_label_cmd);
1041 install_element (CONFIG_NODE, &no_ip_route_mask_tag_distance_label_cmd);
1042
1043 install_element (CONFIG_NODE, &ipv6_route_label_cmd);
1044 install_element (CONFIG_NODE, &ipv6_route_ifname_label_cmd);
1045 install_element (CONFIG_NODE, &no_ipv6_route_label_cmd);
1046 install_element (CONFIG_NODE, &no_ipv6_route_ifname_label_cmd);
1047 install_element (CONFIG_NODE, &ipv6_route_pref_label_cmd);
1048 install_element (CONFIG_NODE, &ipv6_route_ifname_pref_label_cmd);
1049 install_element (CONFIG_NODE, &no_ipv6_route_pref_label_cmd);
1050 install_element (CONFIG_NODE, &no_ipv6_route_ifname_pref_label_cmd);
1051 install_element (CONFIG_NODE, &ipv6_route_tag_label_cmd);
1052 install_element (CONFIG_NODE, &ipv6_route_ifname_tag_label_cmd);
1053 install_element (CONFIG_NODE, &ipv6_route_pref_tag_label_cmd);
1054 install_element (CONFIG_NODE, &ipv6_route_ifname_pref_tag_label_cmd);
1055 install_element (CONFIG_NODE, &no_ipv6_route_tag_label_cmd);
1056 install_element (CONFIG_NODE, &no_ipv6_route_ifname_tag_label_cmd);
1057 install_element (CONFIG_NODE, &no_ipv6_route_pref_tag_label_cmd);
1058 install_element (CONFIG_NODE, &no_ipv6_route_ifname_pref_tag_label_cmd);
1059
1060 install_element (CONFIG_NODE, &mpls_transit_lsp_cmd);
1061 install_element (CONFIG_NODE, &no_mpls_transit_lsp_cmd);
1062 install_element (CONFIG_NODE, &no_mpls_transit_lsp_out_label_cmd);
1063 install_element (CONFIG_NODE, &no_mpls_transit_lsp_all_cmd);
1064 install_element (CONFIG_NODE, &mpls_label_bind_cmd);
1065 install_element (CONFIG_NODE, &no_mpls_label_bind_cmd);
1066
1067 install_element (CONFIG_NODE, &mpls_label_global_block_cmd);
1068 install_element (CONFIG_NODE, &no_mpls_label_global_block_cmd);
1069
1070 install_element (VIEW_NODE, &show_mpls_table_cmd);
1071 install_element (VIEW_NODE, &show_mpls_table_lsp_cmd);
1072 install_element (VIEW_NODE, &show_mpls_fec_cmd);
1073 }