]> git.proxmox.com Git - mirror_frr.git/blob - zebra/zebra_vty.c
Merge pull request #3142 from donaldsharp/bgp_peerhash
[mirror_frr.git] / zebra / zebra_vty.c
1 /* Zebra 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 "zebra_memory.h"
25 #include "if.h"
26 #include "prefix.h"
27 #include "command.h"
28 #include "table.h"
29 #include "rib.h"
30 #include "nexthop.h"
31 #include "vrf.h"
32 #include "linklist.h"
33 #include "mpls.h"
34 #include "routemap.h"
35 #include "srcdest_table.h"
36 #include "vxlan.h"
37
38 #include "zebra/zserv.h"
39 #include "zebra/zebra_vrf.h"
40 #include "zebra/zebra_mpls.h"
41 #include "zebra/zebra_rnh.h"
42 #include "zebra/redistribute.h"
43 #include "zebra/zebra_routemap.h"
44 #include "lib/json.h"
45 #include "zebra/zebra_vxlan.h"
46 #ifndef VTYSH_EXTRACT_PL
47 #include "zebra/zebra_vty_clippy.c"
48 #endif
49 #include "zebra/zserv.h"
50 #include "zebra/router-id.h"
51 #include "zebra/ipforward.h"
52 #include "zebra/zebra_vxlan_private.h"
53 #include "zebra/zebra_pbr.h"
54
55 extern int allow_delete;
56
57 static int do_show_ip_route(struct vty *vty, const char *vrf_name, afi_t afi,
58 safi_t safi, bool use_fib, bool use_json,
59 route_tag_t tag,
60 const struct prefix *longer_prefix_p,
61 bool supernets_only, int type,
62 unsigned short ospf_instance_id);
63 static void vty_show_ip_route_detail(struct vty *vty, struct route_node *rn,
64 int mcast);
65 static void vty_show_ip_route_summary(struct vty *vty,
66 struct route_table *table);
67 static void vty_show_ip_route_summary_prefix(struct vty *vty,
68 struct route_table *table);
69
70 /* VNI range as per RFC 7432 */
71 #define CMD_VNI_RANGE "(1-16777215)"
72
73 DEFUN (ip_multicast_mode,
74 ip_multicast_mode_cmd,
75 "ip multicast rpf-lookup-mode <urib-only|mrib-only|mrib-then-urib|lower-distance|longer-prefix>",
76 IP_STR
77 "Multicast options\n"
78 "RPF lookup behavior\n"
79 "Lookup in unicast RIB only\n"
80 "Lookup in multicast RIB only\n"
81 "Try multicast RIB first, fall back to unicast RIB\n"
82 "Lookup both, use entry with lower distance\n"
83 "Lookup both, use entry with longer prefix\n")
84 {
85 char *mode = argv[3]->text;
86
87 if (strmatch(mode, "urib-only"))
88 multicast_mode_ipv4_set(MCAST_URIB_ONLY);
89 else if (strmatch(mode, "mrib-only"))
90 multicast_mode_ipv4_set(MCAST_MRIB_ONLY);
91 else if (strmatch(mode, "mrib-then-urib"))
92 multicast_mode_ipv4_set(MCAST_MIX_MRIB_FIRST);
93 else if (strmatch(mode, "lower-distance"))
94 multicast_mode_ipv4_set(MCAST_MIX_DISTANCE);
95 else if (strmatch(mode, "longer-prefix"))
96 multicast_mode_ipv4_set(MCAST_MIX_PFXLEN);
97 else {
98 vty_out(vty, "Invalid mode specified\n");
99 return CMD_WARNING_CONFIG_FAILED;
100 }
101
102 return CMD_SUCCESS;
103 }
104
105 DEFUN (no_ip_multicast_mode,
106 no_ip_multicast_mode_cmd,
107 "no ip multicast rpf-lookup-mode [<urib-only|mrib-only|mrib-then-urib|lower-distance|longer-prefix>]",
108 NO_STR
109 IP_STR
110 "Multicast options\n"
111 "RPF lookup behavior\n"
112 "Lookup in unicast RIB only\n"
113 "Lookup in multicast RIB only\n"
114 "Try multicast RIB first, fall back to unicast RIB\n"
115 "Lookup both, use entry with lower distance\n"
116 "Lookup both, use entry with longer prefix\n")
117 {
118 multicast_mode_ipv4_set(MCAST_NO_CONFIG);
119 return CMD_SUCCESS;
120 }
121
122
123 DEFUN (show_ip_rpf,
124 show_ip_rpf_cmd,
125 "show ip rpf [json]",
126 SHOW_STR
127 IP_STR
128 "Display RPF information for multicast source\n"
129 JSON_STR)
130 {
131 bool uj = use_json(argc, argv);
132 return do_show_ip_route(vty, VRF_DEFAULT_NAME, AFI_IP, SAFI_MULTICAST,
133 false, uj, 0, NULL, false, 0, 0);
134 }
135
136 DEFUN (show_ip_rpf_addr,
137 show_ip_rpf_addr_cmd,
138 "show ip rpf A.B.C.D",
139 SHOW_STR
140 IP_STR
141 "Display RPF information for multicast source\n"
142 "IP multicast source address (e.g. 10.0.0.0)\n")
143 {
144 int idx_ipv4 = 3;
145 struct in_addr addr;
146 struct route_node *rn;
147 struct route_entry *re;
148 int ret;
149
150 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
151 if (ret == 0) {
152 vty_out(vty, "%% Malformed address\n");
153 return CMD_WARNING;
154 }
155
156 re = rib_match_ipv4_multicast(VRF_DEFAULT, addr, &rn);
157
158 if (re)
159 vty_show_ip_route_detail(vty, rn, 1);
160 else
161 vty_out(vty, "%% No match for RPF lookup\n");
162
163 return CMD_SUCCESS;
164 }
165
166 /* New RIB. Detailed information for IPv4 route. */
167 static void vty_show_ip_route_detail(struct vty *vty, struct route_node *rn,
168 int mcast)
169 {
170 struct route_entry *re;
171 struct nexthop *nexthop;
172 char buf[SRCDEST2STR_BUFFER];
173 struct zebra_vrf *zvrf;
174
175 RNODE_FOREACH_RE (rn, re) {
176 const char *mcast_info = "";
177 if (mcast) {
178 rib_table_info_t *info = srcdest_rnode_table_info(rn);
179 mcast_info = (info->safi == SAFI_MULTICAST)
180 ? " using Multicast RIB"
181 : " using Unicast RIB";
182 }
183
184 vty_out(vty, "Routing entry for %s%s\n",
185 srcdest_rnode2str(rn, buf, sizeof(buf)), mcast_info);
186 vty_out(vty, " Known via \"%s", zebra_route_string(re->type));
187 if (re->instance)
188 vty_out(vty, "[%d]", re->instance);
189 vty_out(vty, "\"");
190 vty_out(vty, ", distance %u, metric %u", re->distance,
191 re->metric);
192 if (re->tag) {
193 vty_out(vty, ", tag %u", re->tag);
194 #if defined(SUPPORT_REALMS)
195 if (re->tag > 0 && re->tag <= 255)
196 vty_out(vty, "(realm)");
197 #endif
198 }
199 if (re->mtu)
200 vty_out(vty, ", mtu %u", re->mtu);
201 if (re->vrf_id != VRF_DEFAULT) {
202 zvrf = vrf_info_lookup(re->vrf_id);
203 vty_out(vty, ", vrf %s", zvrf_name(zvrf));
204 }
205 if (CHECK_FLAG(re->flags, ZEBRA_FLAG_SELECTED))
206 vty_out(vty, ", best");
207 vty_out(vty, "\n");
208
209 time_t uptime;
210 struct tm *tm;
211
212 uptime = time(NULL);
213 uptime -= re->uptime;
214 tm = gmtime(&uptime);
215
216 vty_out(vty, " Last update ");
217
218 if (uptime < ONE_DAY_SECOND)
219 vty_out(vty, "%02d:%02d:%02d", tm->tm_hour, tm->tm_min,
220 tm->tm_sec);
221 else if (uptime < ONE_WEEK_SECOND)
222 vty_out(vty, "%dd%02dh%02dm", tm->tm_yday, tm->tm_hour,
223 tm->tm_min);
224 else
225 vty_out(vty, "%02dw%dd%02dh", tm->tm_yday / 7,
226 tm->tm_yday - ((tm->tm_yday / 7) * 7),
227 tm->tm_hour);
228 vty_out(vty, " ago\n");
229
230 for (ALL_NEXTHOPS(re->ng, nexthop)) {
231 char addrstr[32];
232
233 vty_out(vty, " %c%s",
234 CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_FIB)
235 ? CHECK_FLAG(nexthop->flags,
236 NEXTHOP_FLAG_DUPLICATE)
237 ? ' '
238 : '*'
239 : ' ',
240 nexthop->rparent ? " " : "");
241
242 switch (nexthop->type) {
243 case NEXTHOP_TYPE_IPV4:
244 case NEXTHOP_TYPE_IPV4_IFINDEX:
245 vty_out(vty, " %s",
246 inet_ntoa(nexthop->gate.ipv4));
247 if (nexthop->ifindex)
248 vty_out(vty, ", via %s",
249 ifindex2ifname(
250 nexthop->ifindex,
251 nexthop->vrf_id));
252 break;
253 case NEXTHOP_TYPE_IPV6:
254 case NEXTHOP_TYPE_IPV6_IFINDEX:
255 vty_out(vty, " %s",
256 inet_ntop(AF_INET6, &nexthop->gate.ipv6,
257 buf, sizeof buf));
258 if (nexthop->ifindex)
259 vty_out(vty, ", via %s",
260 ifindex2ifname(
261 nexthop->ifindex,
262 nexthop->vrf_id));
263 break;
264 case NEXTHOP_TYPE_IFINDEX:
265 vty_out(vty, " directly connected, %s",
266 ifindex2ifname(nexthop->ifindex,
267 nexthop->vrf_id));
268 break;
269 case NEXTHOP_TYPE_BLACKHOLE:
270 vty_out(vty, " unreachable");
271 switch (nexthop->bh_type) {
272 case BLACKHOLE_REJECT:
273 vty_out(vty, " (ICMP unreachable)");
274 break;
275 case BLACKHOLE_ADMINPROHIB:
276 vty_out(vty,
277 " (ICMP admin-prohibited)");
278 break;
279 case BLACKHOLE_NULL:
280 vty_out(vty, " (blackhole)");
281 break;
282 case BLACKHOLE_UNSPEC:
283 break;
284 }
285 break;
286 default:
287 break;
288 }
289
290 if ((re->vrf_id != nexthop->vrf_id)
291 && (nexthop->type != NEXTHOP_TYPE_BLACKHOLE)) {
292 struct vrf *vrf =
293 vrf_lookup_by_id(nexthop->vrf_id);
294
295 if (vrf)
296 vty_out(vty, "(vrf %s)", vrf->name);
297 else
298 vty_out(vty, "(vrf UKNOWN)");
299 }
300
301 if (CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_DUPLICATE))
302 vty_out(vty, " (duplicate nexthop removed)");
303
304 if (!CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_ACTIVE))
305 vty_out(vty, " inactive");
306
307 if (CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_ONLINK))
308 vty_out(vty, " onlink");
309
310 if (CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_RECURSIVE))
311 vty_out(vty, " (recursive)");
312
313 switch (nexthop->type) {
314 case NEXTHOP_TYPE_IPV4:
315 case NEXTHOP_TYPE_IPV4_IFINDEX:
316 if (nexthop->src.ipv4.s_addr) {
317 if (inet_ntop(AF_INET,
318 &nexthop->src.ipv4,
319 addrstr, sizeof addrstr))
320 vty_out(vty, ", src %s",
321 addrstr);
322 }
323 break;
324 case NEXTHOP_TYPE_IPV6:
325 case NEXTHOP_TYPE_IPV6_IFINDEX:
326 if (!IPV6_ADDR_SAME(&nexthop->src.ipv6,
327 &in6addr_any)) {
328 if (inet_ntop(AF_INET6,
329 &nexthop->src.ipv6,
330 addrstr, sizeof addrstr))
331 vty_out(vty, ", src %s",
332 addrstr);
333 }
334 break;
335 default:
336 break;
337 }
338
339 if (re->nexthop_mtu)
340 vty_out(vty, ", mtu %u", re->nexthop_mtu);
341
342 /* Label information */
343 if (nexthop->nh_label
344 && nexthop->nh_label->num_labels) {
345 vty_out(vty, ", label %s",
346 mpls_label2str(
347 nexthop->nh_label->num_labels,
348 nexthop->nh_label->label, buf,
349 sizeof buf, 1));
350 }
351
352 vty_out(vty, "\n");
353 }
354 vty_out(vty, "\n");
355 }
356 }
357
358 static void vty_show_ip_route(struct vty *vty, struct route_node *rn,
359 struct route_entry *re, json_object *json)
360 {
361 struct nexthop *nexthop;
362 int len = 0;
363 char buf[SRCDEST2STR_BUFFER];
364 json_object *json_nexthops = NULL;
365 json_object *json_nexthop = NULL;
366 json_object *json_route = NULL;
367 json_object *json_labels = NULL;
368 time_t uptime;
369 struct tm *tm;
370
371 uptime = time(NULL);
372 uptime -= re->uptime;
373 tm = gmtime(&uptime);
374
375 if (json) {
376 json_route = json_object_new_object();
377 json_nexthops = json_object_new_array();
378
379 json_object_string_add(json_route, "prefix",
380 srcdest_rnode2str(rn, buf, sizeof buf));
381 json_object_string_add(json_route, "protocol",
382 zebra_route_string(re->type));
383
384 if (re->instance)
385 json_object_int_add(json_route, "instance",
386 re->instance);
387
388 if (re->vrf_id)
389 json_object_int_add(json_route, "vrfId", re->vrf_id);
390
391 if (CHECK_FLAG(re->flags, ZEBRA_FLAG_SELECTED))
392 json_object_boolean_true_add(json_route, "selected");
393
394 if (re->type != ZEBRA_ROUTE_CONNECT) {
395 json_object_int_add(json_route, "distance",
396 re->distance);
397 json_object_int_add(json_route, "metric", re->metric);
398 }
399
400 if (re->tag)
401 json_object_int_add(json_route, "tag", re->tag);
402
403 json_object_int_add(json_route, "internalStatus",
404 re->status);
405 json_object_int_add(json_route, "internalFlags",
406 re->flags);
407 if (uptime < ONE_DAY_SECOND)
408 sprintf(buf, "%02d:%02d:%02d", tm->tm_hour, tm->tm_min,
409 tm->tm_sec);
410 else if (uptime < ONE_WEEK_SECOND)
411 sprintf(buf, "%dd%02dh%02dm", tm->tm_yday, tm->tm_hour,
412 tm->tm_min);
413 else
414 sprintf(buf, "%02dw%dd%02dh", tm->tm_yday / 7,
415 tm->tm_yday - ((tm->tm_yday / 7) * 7),
416 tm->tm_hour);
417
418 json_object_string_add(json_route, "uptime", buf);
419
420 for (ALL_NEXTHOPS(re->ng, nexthop)) {
421 json_nexthop = json_object_new_object();
422
423 json_object_int_add(json_nexthop, "flags",
424 nexthop->flags);
425
426 if (CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_DUPLICATE))
427 json_object_boolean_true_add(json_nexthop,
428 "duplicate");
429
430 if (CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_FIB))
431 json_object_boolean_true_add(json_nexthop,
432 "fib");
433
434 switch (nexthop->type) {
435 case NEXTHOP_TYPE_IPV4:
436 case NEXTHOP_TYPE_IPV4_IFINDEX:
437 json_object_string_add(
438 json_nexthop, "ip",
439 inet_ntoa(nexthop->gate.ipv4));
440 json_object_string_add(json_nexthop, "afi",
441 "ipv4");
442
443 if (nexthop->ifindex) {
444 json_object_int_add(json_nexthop,
445 "interfaceIndex",
446 nexthop->ifindex);
447 json_object_string_add(
448 json_nexthop, "interfaceName",
449 ifindex2ifname(
450 nexthop->ifindex,
451 nexthop->vrf_id));
452 }
453 break;
454 case NEXTHOP_TYPE_IPV6:
455 case NEXTHOP_TYPE_IPV6_IFINDEX:
456 json_object_string_add(
457 json_nexthop, "ip",
458 inet_ntop(AF_INET6, &nexthop->gate.ipv6,
459 buf, sizeof buf));
460 json_object_string_add(json_nexthop, "afi",
461 "ipv6");
462
463 if (nexthop->ifindex) {
464 json_object_int_add(json_nexthop,
465 "interfaceIndex",
466 nexthop->ifindex);
467 json_object_string_add(
468 json_nexthop, "interfaceName",
469 ifindex2ifname(
470 nexthop->ifindex,
471 nexthop->vrf_id));
472 }
473 break;
474
475 case NEXTHOP_TYPE_IFINDEX:
476 json_object_boolean_true_add(
477 json_nexthop, "directlyConnected");
478 json_object_int_add(json_nexthop,
479 "interfaceIndex",
480 nexthop->ifindex);
481 json_object_string_add(
482 json_nexthop, "interfaceName",
483 ifindex2ifname(nexthop->ifindex,
484 nexthop->vrf_id));
485 break;
486 case NEXTHOP_TYPE_BLACKHOLE:
487 json_object_boolean_true_add(json_nexthop,
488 "unreachable");
489 switch (nexthop->bh_type) {
490 case BLACKHOLE_REJECT:
491 json_object_boolean_true_add(
492 json_nexthop, "reject");
493 break;
494 case BLACKHOLE_ADMINPROHIB:
495 json_object_boolean_true_add(
496 json_nexthop,
497 "admin-prohibited");
498 break;
499 case BLACKHOLE_NULL:
500 json_object_boolean_true_add(
501 json_nexthop, "blackhole");
502 break;
503 case BLACKHOLE_UNSPEC:
504 break;
505 }
506 break;
507 default:
508 break;
509 }
510
511 if ((nexthop->vrf_id != re->vrf_id)
512 && (nexthop->type != NEXTHOP_TYPE_BLACKHOLE)) {
513 struct vrf *vrf =
514 vrf_lookup_by_id(nexthop->vrf_id);
515
516 json_object_string_add(json_nexthop, "vrf",
517 vrf->name);
518 }
519 if (CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_DUPLICATE))
520 json_object_boolean_true_add(json_nexthop,
521 "duplicate");
522
523 if (CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_ACTIVE))
524 json_object_boolean_true_add(json_nexthop,
525 "active");
526
527 if (CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_ONLINK))
528 json_object_boolean_true_add(json_nexthop,
529 "onLink");
530
531 if (CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_RECURSIVE))
532 json_object_boolean_true_add(json_nexthop,
533 "recursive");
534
535 switch (nexthop->type) {
536 case NEXTHOP_TYPE_IPV4:
537 case NEXTHOP_TYPE_IPV4_IFINDEX:
538 if (nexthop->src.ipv4.s_addr) {
539 if (inet_ntop(AF_INET,
540 &nexthop->src.ipv4, buf,
541 sizeof buf))
542 json_object_string_add(
543 json_nexthop, "source",
544 buf);
545 }
546 break;
547 case NEXTHOP_TYPE_IPV6:
548 case NEXTHOP_TYPE_IPV6_IFINDEX:
549 if (!IPV6_ADDR_SAME(&nexthop->src.ipv6,
550 &in6addr_any)) {
551 if (inet_ntop(AF_INET6,
552 &nexthop->src.ipv6, buf,
553 sizeof buf))
554 json_object_string_add(
555 json_nexthop, "source",
556 buf);
557 }
558 break;
559 default:
560 break;
561 }
562
563 if (nexthop->nh_label
564 && nexthop->nh_label->num_labels) {
565 json_labels = json_object_new_array();
566
567 for (int label_index = 0;
568 label_index
569 < nexthop->nh_label->num_labels;
570 label_index++)
571 json_object_array_add(
572 json_labels,
573 json_object_new_int(
574 nexthop->nh_label->label
575 [label_index]));
576
577 json_object_object_add(json_nexthop, "labels",
578 json_labels);
579 }
580
581 json_object_array_add(json_nexthops, json_nexthop);
582 }
583
584 json_object_object_add(json_route, "nexthops", json_nexthops);
585 json_object_array_add(json, json_route);
586 return;
587 }
588
589 /* Nexthop information. */
590 for (ALL_NEXTHOPS(re->ng, nexthop)) {
591 if (nexthop == re->ng.nexthop) {
592 /* Prefix information. */
593 len = vty_out(vty, "%c", zebra_route_char(re->type));
594 if (re->instance)
595 len += vty_out(vty, "[%d]", re->instance);
596 len += vty_out(
597 vty, "%c%c %s",
598 CHECK_FLAG(re->flags, ZEBRA_FLAG_SELECTED)
599 ? '>'
600 : ' ',
601 CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_FIB)
602 ? '*'
603 : ' ',
604 srcdest_rnode2str(rn, buf, sizeof buf));
605
606 /* Distance and metric display. */
607 if (re->type != ZEBRA_ROUTE_CONNECT)
608 len += vty_out(vty, " [%u/%u]", re->distance,
609 re->metric);
610 } else {
611 vty_out(vty, " %c%*c",
612 CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_FIB)
613 ? CHECK_FLAG(nexthop->flags,
614 NEXTHOP_FLAG_DUPLICATE)
615 ? ' '
616 : '*'
617 : ' ',
618 len - 3 + (2 * nexthop_level(nexthop)), ' ');
619 }
620
621 switch (nexthop->type) {
622 case NEXTHOP_TYPE_IPV4:
623 case NEXTHOP_TYPE_IPV4_IFINDEX:
624 vty_out(vty, " via %s", inet_ntoa(nexthop->gate.ipv4));
625 if (nexthop->ifindex)
626 vty_out(vty, ", %s",
627 ifindex2ifname(nexthop->ifindex,
628 nexthop->vrf_id));
629 break;
630 case NEXTHOP_TYPE_IPV6:
631 case NEXTHOP_TYPE_IPV6_IFINDEX:
632 vty_out(vty, " via %s",
633 inet_ntop(AF_INET6, &nexthop->gate.ipv6, buf,
634 sizeof buf));
635 if (nexthop->ifindex)
636 vty_out(vty, ", %s",
637 ifindex2ifname(nexthop->ifindex,
638 nexthop->vrf_id));
639 break;
640
641 case NEXTHOP_TYPE_IFINDEX:
642 vty_out(vty, " is directly connected, %s",
643 ifindex2ifname(nexthop->ifindex,
644 nexthop->vrf_id));
645 break;
646 case NEXTHOP_TYPE_BLACKHOLE:
647 vty_out(vty, " unreachable");
648 switch (nexthop->bh_type) {
649 case BLACKHOLE_REJECT:
650 vty_out(vty, " (ICMP unreachable)");
651 break;
652 case BLACKHOLE_ADMINPROHIB:
653 vty_out(vty, " (ICMP admin-prohibited)");
654 break;
655 case BLACKHOLE_NULL:
656 vty_out(vty, " (blackhole)");
657 break;
658 case BLACKHOLE_UNSPEC:
659 break;
660 }
661 break;
662 default:
663 break;
664 }
665
666 if ((nexthop->vrf_id != re->vrf_id)
667 && (nexthop->type != NEXTHOP_TYPE_BLACKHOLE)) {
668 struct vrf *vrf = vrf_lookup_by_id(nexthop->vrf_id);
669
670 if (vrf)
671 vty_out(vty, "(vrf %s)", vrf->name);
672 else
673 vty_out(vty, "(vrf UKNOWN)");
674 }
675
676 if (!CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_ACTIVE))
677 vty_out(vty, " inactive");
678
679 if (CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_ONLINK))
680 vty_out(vty, " onlink");
681
682 if (CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_RECURSIVE))
683 vty_out(vty, " (recursive)");
684
685 switch (nexthop->type) {
686 case NEXTHOP_TYPE_IPV4:
687 case NEXTHOP_TYPE_IPV4_IFINDEX:
688 if (nexthop->src.ipv4.s_addr) {
689 if (inet_ntop(AF_INET, &nexthop->src.ipv4, buf,
690 sizeof buf))
691 vty_out(vty, ", src %s", buf);
692 }
693 break;
694 case NEXTHOP_TYPE_IPV6:
695 case NEXTHOP_TYPE_IPV6_IFINDEX:
696 if (!IPV6_ADDR_SAME(&nexthop->src.ipv6, &in6addr_any)) {
697 if (inet_ntop(AF_INET6, &nexthop->src.ipv6, buf,
698 sizeof buf))
699 vty_out(vty, ", src %s", buf);
700 }
701 break;
702 default:
703 break;
704 }
705
706 /* Label information */
707 if (nexthop->nh_label && nexthop->nh_label->num_labels) {
708 vty_out(vty, ", label %s",
709 mpls_label2str(nexthop->nh_label->num_labels,
710 nexthop->nh_label->label, buf,
711 sizeof buf, 1));
712 }
713
714 if (uptime < ONE_DAY_SECOND)
715 vty_out(vty, ", %02d:%02d:%02d", tm->tm_hour,
716 tm->tm_min, tm->tm_sec);
717 else if (uptime < ONE_WEEK_SECOND)
718 vty_out(vty, ", %dd%02dh%02dm", tm->tm_yday,
719 tm->tm_hour, tm->tm_min);
720 else
721 vty_out(vty, ", %02dw%dd%02dh", tm->tm_yday / 7,
722 tm->tm_yday - ((tm->tm_yday / 7) * 7),
723 tm->tm_hour);
724 vty_out(vty, "\n");
725 }
726 }
727
728 static void vty_show_ip_route_detail_json(struct vty *vty,
729 struct route_node *rn)
730 {
731 json_object *json = NULL;
732 json_object *json_prefix = NULL;
733 struct route_entry *re;
734 char buf[BUFSIZ];
735
736 json = json_object_new_object();
737
738 RNODE_FOREACH_RE (rn, re) {
739 json_prefix = json_object_new_array();
740 vty_show_ip_route(vty, rn, re, json_prefix);
741 prefix2str(&rn->p, buf, sizeof buf);
742 json_object_object_add(json, buf, json_prefix);
743 json_prefix = NULL;
744 }
745
746 vty_out(vty, "%s\n", json_object_to_json_string_ext(
747 json, JSON_C_TO_STRING_PRETTY));
748 json_object_free(json);
749 }
750
751 static void do_show_route_helper(struct vty *vty, struct zebra_vrf *zvrf,
752 struct route_table *table, afi_t afi,
753 bool use_fib, route_tag_t tag,
754 const struct prefix *longer_prefix_p,
755 bool supernets_only, int type,
756 unsigned short ospf_instance_id, bool use_json)
757 {
758 struct route_node *rn;
759 struct route_entry *re;
760 int first = 1;
761 rib_dest_t *dest;
762 json_object *json = NULL;
763 json_object *json_prefix = NULL;
764 uint32_t addr;
765 char buf[BUFSIZ];
766
767 if (use_json)
768 json = json_object_new_object();
769
770 /* Show all routes. */
771 for (rn = route_top(table); rn; rn = srcdest_route_next(rn)) {
772 dest = rib_dest_from_rnode(rn);
773
774 RNODE_FOREACH_RE (rn, re) {
775 if (use_fib && re != dest->selected_fib)
776 continue;
777
778 if (tag && re->tag != tag)
779 continue;
780
781 if (longer_prefix_p
782 && !prefix_match(longer_prefix_p, &rn->p))
783 continue;
784
785 /* This can only be true when the afi is IPv4 */
786 if (supernets_only) {
787 addr = ntohl(rn->p.u.prefix4.s_addr);
788
789 if (IN_CLASSC(addr) && rn->p.prefixlen >= 24)
790 continue;
791
792 if (IN_CLASSB(addr) && rn->p.prefixlen >= 16)
793 continue;
794
795 if (IN_CLASSA(addr) && rn->p.prefixlen >= 8)
796 continue;
797 }
798
799 if (type && re->type != type)
800 continue;
801
802 if (ospf_instance_id
803 && (re->type != ZEBRA_ROUTE_OSPF
804 || re->instance != ospf_instance_id))
805 continue;
806
807 if (use_json) {
808 if (!json_prefix)
809 json_prefix = json_object_new_array();
810 } else {
811 if (first) {
812 if (afi == AFI_IP)
813 vty_out(vty,
814 SHOW_ROUTE_V4_HEADER);
815 else
816 vty_out(vty,
817 SHOW_ROUTE_V6_HEADER);
818
819 if (zvrf_id(zvrf) != VRF_DEFAULT)
820 vty_out(vty, "\nVRF %s:\n",
821 zvrf_name(zvrf));
822
823 first = 0;
824 }
825 }
826
827 vty_show_ip_route(vty, rn, re, json_prefix);
828 }
829
830 if (json_prefix) {
831 prefix2str(&rn->p, buf, sizeof(buf));
832 json_object_object_add(json, buf, json_prefix);
833 json_prefix = NULL;
834 }
835 }
836
837 if (use_json) {
838 vty_out(vty, "%s\n", json_object_to_json_string_ext(json,
839 JSON_C_TO_STRING_PRETTY));
840 json_object_free(json);
841 }
842 }
843
844 static int do_show_ip_route(struct vty *vty, const char *vrf_name, afi_t afi,
845 safi_t safi, bool use_fib, bool use_json,
846 route_tag_t tag,
847 const struct prefix *longer_prefix_p,
848 bool supernets_only, int type,
849 unsigned short ospf_instance_id)
850 {
851 struct route_table *table;
852 struct zebra_vrf *zvrf = NULL;
853
854 if (!(zvrf = zebra_vrf_lookup_by_name(vrf_name))) {
855 if (use_json)
856 vty_out(vty, "{}\n");
857 else
858 vty_out(vty, "vrf %s not defined\n", vrf_name);
859 return CMD_SUCCESS;
860 }
861
862 if (zvrf_id(zvrf) == VRF_UNKNOWN) {
863 if (use_json)
864 vty_out(vty, "{}\n");
865 else
866 vty_out(vty, "vrf %s inactive\n", vrf_name);
867 return CMD_SUCCESS;
868 }
869
870 table = zebra_vrf_table(afi, safi, zvrf_id(zvrf));
871 if (!table) {
872 if (use_json)
873 vty_out(vty, "{}\n");
874 return CMD_SUCCESS;
875 }
876
877 do_show_route_helper(vty, zvrf, table, afi, use_fib, tag,
878 longer_prefix_p, supernets_only, type,
879 ospf_instance_id, use_json);
880
881 return CMD_SUCCESS;
882 }
883
884 DEFPY (show_route_table,
885 show_route_table_cmd,
886 "show <ip$ipv4|ipv6$ipv6> route table (1-4294967295)$table [json$json]",
887 SHOW_STR
888 IP_STR
889 IP6_STR
890 "IP routing table\n"
891 "Table to display\n"
892 "The table number to display, if available\n"
893 JSON_STR)
894 {
895 afi_t afi = ipv4 ? AFI_IP : AFI_IP6;
896 struct zebra_vrf *zvrf = zebra_vrf_lookup_by_id(VRF_DEFAULT);
897 struct route_table *t;
898
899 t = zebra_ns_find_table(zvrf->zns, table, afi);
900 if (t)
901 do_show_route_helper(vty, zvrf, t, afi, false, 0, false, false,
902 0, 0, !!json);
903
904 return CMD_SUCCESS;
905 }
906
907 DEFPY (show_route_table_vrf,
908 show_route_table_vrf_cmd,
909 "show <ip$ipv4|ipv6$ipv6> route table (1-4294967295)$table vrf NAME$vrf_name [json$json]",
910 SHOW_STR
911 IP_STR
912 IP6_STR
913 "IP routing table\n"
914 "Table to display\n"
915 "The table number to display, if available\n"
916 VRF_CMD_HELP_STR
917 JSON_STR)
918 {
919 afi_t afi = ipv4 ? AFI_IP : AFI_IP6;
920 struct zebra_vrf *zvrf;
921 struct route_table *t;
922 vrf_id_t vrf_id = VRF_DEFAULT;
923
924 if (vrf_name)
925 VRF_GET_ID(vrf_id, vrf_name, !!json);
926 zvrf = zebra_vrf_lookup_by_id(vrf_id);
927
928 t = zebra_ns_find_table(zvrf->zns, table, afi);
929 if (t)
930 do_show_route_helper(vty, zvrf, t, afi, false, 0, false, false,
931 0, 0, !!json);
932
933 return CMD_SUCCESS;
934 }
935
936 DEFUN (show_ip_nht,
937 show_ip_nht_cmd,
938 "show ip nht [vrf NAME]",
939 SHOW_STR
940 IP_STR
941 "IP nexthop tracking table\n"
942 VRF_CMD_HELP_STR)
943 {
944 int idx_vrf = 4;
945 vrf_id_t vrf_id = VRF_DEFAULT;
946
947 if (argc == 5)
948 VRF_GET_ID(vrf_id, argv[idx_vrf]->arg, false);
949
950 zebra_print_rnh_table(vrf_id, AF_INET, vty, RNH_NEXTHOP_TYPE);
951 return CMD_SUCCESS;
952 }
953
954
955 DEFUN (show_ip_nht_vrf_all,
956 show_ip_nht_vrf_all_cmd,
957 "show ip nht vrf all",
958 SHOW_STR
959 IP_STR
960 "IP nexthop tracking table\n"
961 VRF_ALL_CMD_HELP_STR)
962 {
963 struct vrf *vrf;
964 struct zebra_vrf *zvrf;
965
966 RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name)
967 if ((zvrf = vrf->info) != NULL) {
968 vty_out(vty, "\nVRF %s:\n", zvrf_name(zvrf));
969 zebra_print_rnh_table(zvrf_id(zvrf), AF_INET, vty,
970 RNH_NEXTHOP_TYPE);
971 }
972
973 return CMD_SUCCESS;
974 }
975
976 DEFUN (show_ipv6_nht,
977 show_ipv6_nht_cmd,
978 "show ipv6 nht [vrf NAME]",
979 SHOW_STR
980 IPV6_STR
981 "IPv6 nexthop tracking table\n"
982 VRF_CMD_HELP_STR)
983 {
984 int idx_vrf = 4;
985 vrf_id_t vrf_id = VRF_DEFAULT;
986
987 if (argc == 5)
988 VRF_GET_ID(vrf_id, argv[idx_vrf]->arg, false);
989
990 zebra_print_rnh_table(vrf_id, AF_INET6, vty, RNH_NEXTHOP_TYPE);
991 return CMD_SUCCESS;
992 }
993
994
995 DEFUN (show_ipv6_nht_vrf_all,
996 show_ipv6_nht_vrf_all_cmd,
997 "show ipv6 nht vrf all",
998 SHOW_STR
999 IP_STR
1000 "IPv6 nexthop tracking table\n"
1001 VRF_ALL_CMD_HELP_STR)
1002 {
1003 struct vrf *vrf;
1004 struct zebra_vrf *zvrf;
1005
1006 RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name)
1007 if ((zvrf = vrf->info) != NULL) {
1008 vty_out(vty, "\nVRF %s:\n", zvrf_name(zvrf));
1009 zebra_print_rnh_table(zvrf_id(zvrf), AF_INET6, vty,
1010 RNH_NEXTHOP_TYPE);
1011 }
1012
1013 return CMD_SUCCESS;
1014 }
1015
1016 DEFUN (ip_nht_default_route,
1017 ip_nht_default_route_cmd,
1018 "ip nht resolve-via-default",
1019 IP_STR
1020 "Filter Next Hop tracking route resolution\n"
1021 "Resolve via default route\n")
1022 {
1023 ZEBRA_DECLVAR_CONTEXT(vrf, zvrf);
1024
1025 if (!zvrf)
1026 return CMD_WARNING;
1027
1028 if (zebra_rnh_ip_default_route)
1029 return CMD_SUCCESS;
1030
1031 zebra_rnh_ip_default_route = 1;
1032
1033 zebra_evaluate_rnh(zvrf, AF_INET, 1, RNH_NEXTHOP_TYPE, NULL);
1034 return CMD_SUCCESS;
1035 }
1036
1037 DEFUN (no_ip_nht_default_route,
1038 no_ip_nht_default_route_cmd,
1039 "no ip nht resolve-via-default",
1040 NO_STR
1041 IP_STR
1042 "Filter Next Hop tracking route resolution\n"
1043 "Resolve via default route\n")
1044 {
1045 ZEBRA_DECLVAR_CONTEXT(vrf, zvrf);
1046
1047 if (!zvrf)
1048 return CMD_WARNING;
1049
1050 if (!zebra_rnh_ip_default_route)
1051 return CMD_SUCCESS;
1052
1053 zebra_rnh_ip_default_route = 0;
1054 zebra_evaluate_rnh(zvrf, AF_INET, 1, RNH_NEXTHOP_TYPE, NULL);
1055 return CMD_SUCCESS;
1056 }
1057
1058 DEFUN (ipv6_nht_default_route,
1059 ipv6_nht_default_route_cmd,
1060 "ipv6 nht resolve-via-default",
1061 IP6_STR
1062 "Filter Next Hop tracking route resolution\n"
1063 "Resolve via default route\n")
1064 {
1065 ZEBRA_DECLVAR_CONTEXT(vrf, zvrf);
1066
1067 if (!zvrf)
1068 return CMD_WARNING;
1069
1070 if (zebra_rnh_ipv6_default_route)
1071 return CMD_SUCCESS;
1072
1073 zebra_rnh_ipv6_default_route = 1;
1074 zebra_evaluate_rnh(zvrf, AF_INET6, 1, RNH_NEXTHOP_TYPE, NULL);
1075 return CMD_SUCCESS;
1076 }
1077
1078 DEFUN (no_ipv6_nht_default_route,
1079 no_ipv6_nht_default_route_cmd,
1080 "no ipv6 nht resolve-via-default",
1081 NO_STR
1082 IP6_STR
1083 "Filter Next Hop tracking route resolution\n"
1084 "Resolve via default route\n")
1085 {
1086
1087 ZEBRA_DECLVAR_CONTEXT(vrf, zvrf);
1088
1089 if (!zvrf)
1090 return CMD_WARNING;
1091
1092 if (!zebra_rnh_ipv6_default_route)
1093 return CMD_SUCCESS;
1094
1095 zebra_rnh_ipv6_default_route = 0;
1096 zebra_evaluate_rnh(zvrf, AF_INET6, 1, RNH_NEXTHOP_TYPE, NULL);
1097 return CMD_SUCCESS;
1098 }
1099
1100 DEFPY (show_route,
1101 show_route_cmd,
1102 "show\
1103 <\
1104 ip$ipv4 <fib$fib|route> [vrf <NAME$vrf_name|all$vrf_all>]\
1105 [{\
1106 tag (1-4294967295)\
1107 |A.B.C.D/M$prefix longer-prefixes\
1108 |supernets-only$supernets_only\
1109 }]\
1110 [<\
1111 " FRR_IP_REDIST_STR_ZEBRA "$type_str\
1112 |ospf$type_str (1-65535)$ospf_instance_id\
1113 >]\
1114 |ipv6$ipv6 <fib$fib|route> [vrf <NAME$vrf_name|all$vrf_all>]\
1115 [{\
1116 tag (1-4294967295)\
1117 |X:X::X:X/M$prefix longer-prefixes\
1118 }]\
1119 [" FRR_IP6_REDIST_STR_ZEBRA "$type_str]\
1120 >\
1121 [json$json]",
1122 SHOW_STR
1123 IP_STR
1124 "IP forwarding table\n"
1125 "IP routing table\n"
1126 VRF_FULL_CMD_HELP_STR
1127 "Show only routes with tag\n"
1128 "Tag value\n"
1129 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
1130 "Show route matching the specified Network/Mask pair only\n"
1131 "Show supernet entries only\n"
1132 FRR_IP_REDIST_HELP_STR_ZEBRA
1133 "Open Shortest Path First (OSPFv2)\n"
1134 "Instance ID\n"
1135 IPV6_STR
1136 "IP forwarding table\n"
1137 "IP routing table\n"
1138 VRF_FULL_CMD_HELP_STR
1139 "Show only routes with tag\n"
1140 "Tag value\n"
1141 "IPv6 prefix\n"
1142 "Show route matching the specified Network/Mask pair only\n"
1143 FRR_IP6_REDIST_HELP_STR_ZEBRA
1144 JSON_STR)
1145 {
1146 afi_t afi = ipv4 ? AFI_IP : AFI_IP6;
1147 struct vrf *vrf;
1148 int type = 0;
1149
1150 if (type_str) {
1151 type = proto_redistnum(afi, type_str);
1152 if (type < 0) {
1153 vty_out(vty, "Unknown route type\n");
1154 return CMD_WARNING;
1155 }
1156 }
1157
1158 if (vrf_all) {
1159 RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) {
1160 struct zebra_vrf *zvrf;
1161 struct route_table *table;
1162
1163 if ((zvrf = vrf->info) == NULL
1164 || (table = zvrf->table[afi][SAFI_UNICAST]) == NULL)
1165 continue;
1166
1167 do_show_ip_route(
1168 vty, zvrf_name(zvrf), afi, SAFI_UNICAST, !!fib,
1169 !!json, tag, prefix_str ? prefix : NULL,
1170 !!supernets_only, type, ospf_instance_id);
1171 }
1172 } else {
1173 vrf_id_t vrf_id = VRF_DEFAULT;
1174
1175 if (vrf_name)
1176 VRF_GET_ID(vrf_id, vrf_name, !!json);
1177 vrf = vrf_lookup_by_id(vrf_id);
1178 do_show_ip_route(vty, vrf->name, afi, SAFI_UNICAST, !!fib,
1179 !!json, tag, prefix_str ? prefix : NULL,
1180 !!supernets_only, type, ospf_instance_id);
1181 }
1182
1183 return CMD_SUCCESS;
1184 }
1185
1186 DEFPY (show_route_detail,
1187 show_route_detail_cmd,
1188 "show\
1189 <\
1190 ip$ipv4 route [vrf <NAME$vrf_name|all$vrf_all>]\
1191 <\
1192 A.B.C.D$address\
1193 |A.B.C.D/M$prefix\
1194 >\
1195 |ipv6$ipv6 route [vrf <NAME$vrf_name|all$vrf_all>]\
1196 <\
1197 X:X::X:X$address\
1198 |X:X::X:X/M$prefix\
1199 >\
1200 >\
1201 [json$json]",
1202 SHOW_STR
1203 IP_STR
1204 "IP routing table\n"
1205 VRF_FULL_CMD_HELP_STR
1206 "Network in the IP routing table to display\n"
1207 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
1208 IP6_STR
1209 "IP routing table\n"
1210 VRF_FULL_CMD_HELP_STR
1211 "IPv6 Address\n"
1212 "IPv6 prefix\n"
1213 JSON_STR)
1214 {
1215 afi_t afi = ipv4 ? AFI_IP : AFI_IP6;
1216 struct route_table *table;
1217 struct prefix p;
1218 struct route_node *rn;
1219
1220 if (address_str)
1221 prefix_str = address_str;
1222 if (str2prefix(prefix_str, &p) < 0) {
1223 vty_out(vty, "%% Malformed address\n");
1224 return CMD_WARNING;
1225 }
1226
1227 if (vrf_all) {
1228 struct vrf *vrf;
1229 struct zebra_vrf *zvrf;
1230
1231 RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) {
1232 if ((zvrf = vrf->info) == NULL
1233 || (table = zvrf->table[afi][SAFI_UNICAST]) == NULL)
1234 continue;
1235
1236 rn = route_node_match(table, &p);
1237 if (!rn)
1238 continue;
1239 if (!address_str && rn->p.prefixlen != p.prefixlen) {
1240 route_unlock_node(rn);
1241 continue;
1242 }
1243
1244 if (json)
1245 vty_show_ip_route_detail_json(vty, rn);
1246 else
1247 vty_show_ip_route_detail(vty, rn, 0);
1248
1249 route_unlock_node(rn);
1250 }
1251 } else {
1252 vrf_id_t vrf_id = VRF_DEFAULT;
1253
1254 if (vrf_name)
1255 VRF_GET_ID(vrf_id, vrf_name, false);
1256
1257 table = zebra_vrf_table(afi, SAFI_UNICAST, vrf_id);
1258 if (!table)
1259 return CMD_SUCCESS;
1260
1261 rn = route_node_match(table, &p);
1262 if (!rn) {
1263 vty_out(vty, "%% Network not in table\n");
1264 return CMD_WARNING;
1265 }
1266 if (!address_str && rn->p.prefixlen != p.prefixlen) {
1267 vty_out(vty, "%% Network not in table\n");
1268 route_unlock_node(rn);
1269 return CMD_WARNING;
1270 }
1271
1272 if (json)
1273 vty_show_ip_route_detail_json(vty, rn);
1274 else
1275 vty_show_ip_route_detail(vty, rn, 0);
1276
1277 route_unlock_node(rn);
1278 }
1279
1280 return CMD_SUCCESS;
1281 }
1282
1283 DEFPY (show_route_summary,
1284 show_route_summary_cmd,
1285 "show\
1286 <\
1287 ip$ipv4 route [vrf <NAME$vrf_name|all$vrf_all>]\
1288 summary [prefix$prefix]\
1289 |ipv6$ipv6 route [vrf <NAME$vrf_name|all$vrf_all>]\
1290 summary [prefix$prefix]\
1291 >",
1292 SHOW_STR
1293 IP_STR
1294 "IP routing table\n"
1295 VRF_FULL_CMD_HELP_STR
1296 "Summary of all routes\n"
1297 "Prefix routes\n"
1298 IP6_STR
1299 "IP routing table\n"
1300 VRF_FULL_CMD_HELP_STR
1301 "Summary of all routes\n"
1302 "Prefix routes\n")
1303 {
1304 afi_t afi = ipv4 ? AFI_IP : AFI_IP6;
1305 struct route_table *table;
1306
1307 if (vrf_all) {
1308 struct vrf *vrf;
1309 struct zebra_vrf *zvrf;
1310
1311 RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) {
1312 if ((zvrf = vrf->info) == NULL
1313 || (table = zvrf->table[afi][SAFI_UNICAST]) == NULL)
1314 continue;
1315
1316 if (prefix)
1317 vty_show_ip_route_summary_prefix(vty, table);
1318 else
1319 vty_show_ip_route_summary(vty, table);
1320 }
1321 } else {
1322 vrf_id_t vrf_id = VRF_DEFAULT;
1323
1324 if (vrf_name)
1325 VRF_GET_ID(vrf_id, vrf_name, false);
1326
1327 table = zebra_vrf_table(afi, SAFI_UNICAST, vrf_id);
1328 if (!table)
1329 return CMD_SUCCESS;
1330
1331 if (prefix)
1332 vty_show_ip_route_summary_prefix(vty, table);
1333 else
1334 vty_show_ip_route_summary(vty, table);
1335 }
1336
1337 return CMD_SUCCESS;
1338 }
1339
1340 static void vty_show_ip_route_summary(struct vty *vty,
1341 struct route_table *table)
1342 {
1343 struct route_node *rn;
1344 struct route_entry *re;
1345 #define ZEBRA_ROUTE_IBGP ZEBRA_ROUTE_MAX
1346 #define ZEBRA_ROUTE_TOTAL (ZEBRA_ROUTE_IBGP + 1)
1347 uint32_t rib_cnt[ZEBRA_ROUTE_TOTAL + 1];
1348 uint32_t fib_cnt[ZEBRA_ROUTE_TOTAL + 1];
1349 uint32_t i;
1350 uint32_t is_ibgp;
1351
1352 memset(&rib_cnt, 0, sizeof(rib_cnt));
1353 memset(&fib_cnt, 0, sizeof(fib_cnt));
1354 for (rn = route_top(table); rn; rn = srcdest_route_next(rn))
1355 RNODE_FOREACH_RE (rn, re) {
1356 is_ibgp = (re->type == ZEBRA_ROUTE_BGP
1357 && CHECK_FLAG(re->flags, ZEBRA_FLAG_IBGP));
1358
1359 rib_cnt[ZEBRA_ROUTE_TOTAL]++;
1360 if (is_ibgp)
1361 rib_cnt[ZEBRA_ROUTE_IBGP]++;
1362 else
1363 rib_cnt[re->type]++;
1364
1365 if (CHECK_FLAG(re->flags, ZEBRA_FLAG_SELECTED)) {
1366 fib_cnt[ZEBRA_ROUTE_TOTAL]++;
1367
1368 if (is_ibgp)
1369 fib_cnt[ZEBRA_ROUTE_IBGP]++;
1370 else
1371 fib_cnt[re->type]++;
1372 }
1373 }
1374
1375 vty_out(vty, "%-20s %-20s %s (vrf %s)\n", "Route Source", "Routes",
1376 "FIB", zvrf_name(((rib_table_info_t *)route_table_get_info(table))->zvrf));
1377
1378 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
1379 if ((rib_cnt[i] > 0) || (i == ZEBRA_ROUTE_BGP
1380 && rib_cnt[ZEBRA_ROUTE_IBGP] > 0)) {
1381 if (i == ZEBRA_ROUTE_BGP) {
1382 vty_out(vty, "%-20s %-20d %-20d \n", "ebgp",
1383 rib_cnt[ZEBRA_ROUTE_BGP],
1384 fib_cnt[ZEBRA_ROUTE_BGP]);
1385 vty_out(vty, "%-20s %-20d %-20d \n", "ibgp",
1386 rib_cnt[ZEBRA_ROUTE_IBGP],
1387 fib_cnt[ZEBRA_ROUTE_IBGP]);
1388 } else
1389 vty_out(vty, "%-20s %-20d %-20d \n",
1390 zebra_route_string(i), rib_cnt[i],
1391 fib_cnt[i]);
1392 }
1393 }
1394
1395 vty_out(vty, "------\n");
1396 vty_out(vty, "%-20s %-20d %-20d \n", "Totals",
1397 rib_cnt[ZEBRA_ROUTE_TOTAL], fib_cnt[ZEBRA_ROUTE_TOTAL]);
1398 vty_out(vty, "\n");
1399 }
1400
1401 /*
1402 * Implementation of the ip route summary prefix command.
1403 *
1404 * This command prints the primary prefixes that have been installed by various
1405 * protocols on the box.
1406 *
1407 */
1408 static void vty_show_ip_route_summary_prefix(struct vty *vty,
1409 struct route_table *table)
1410 {
1411 struct route_node *rn;
1412 struct route_entry *re;
1413 struct nexthop *nexthop;
1414 #define ZEBRA_ROUTE_IBGP ZEBRA_ROUTE_MAX
1415 #define ZEBRA_ROUTE_TOTAL (ZEBRA_ROUTE_IBGP + 1)
1416 uint32_t rib_cnt[ZEBRA_ROUTE_TOTAL + 1];
1417 uint32_t fib_cnt[ZEBRA_ROUTE_TOTAL + 1];
1418 uint32_t i;
1419 int cnt;
1420
1421 memset(&rib_cnt, 0, sizeof(rib_cnt));
1422 memset(&fib_cnt, 0, sizeof(fib_cnt));
1423 for (rn = route_top(table); rn; rn = srcdest_route_next(rn))
1424 RNODE_FOREACH_RE (rn, re) {
1425
1426 /*
1427 * In case of ECMP, count only once.
1428 */
1429 cnt = 0;
1430 for (nexthop = re->ng.nexthop; (!cnt && nexthop);
1431 nexthop = nexthop->next) {
1432 cnt++;
1433 rib_cnt[ZEBRA_ROUTE_TOTAL]++;
1434 rib_cnt[re->type]++;
1435 if (CHECK_FLAG(nexthop->flags,
1436 NEXTHOP_FLAG_FIB)) {
1437 fib_cnt[ZEBRA_ROUTE_TOTAL]++;
1438 fib_cnt[re->type]++;
1439 }
1440 if (re->type == ZEBRA_ROUTE_BGP
1441 && CHECK_FLAG(re->flags, ZEBRA_FLAG_IBGP)) {
1442 rib_cnt[ZEBRA_ROUTE_IBGP]++;
1443 if (CHECK_FLAG(nexthop->flags,
1444 NEXTHOP_FLAG_FIB))
1445 fib_cnt[ZEBRA_ROUTE_IBGP]++;
1446 }
1447 }
1448 }
1449
1450 vty_out(vty, "%-20s %-20s %s (vrf %s)\n", "Route Source",
1451 "Prefix Routes", "FIB",
1452 zvrf_name(((rib_table_info_t *)route_table_get_info(table))->zvrf));
1453
1454 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
1455 if (rib_cnt[i] > 0) {
1456 if (i == ZEBRA_ROUTE_BGP) {
1457 vty_out(vty, "%-20s %-20d %-20d \n", "ebgp",
1458 rib_cnt[ZEBRA_ROUTE_BGP]
1459 - rib_cnt[ZEBRA_ROUTE_IBGP],
1460 fib_cnt[ZEBRA_ROUTE_BGP]
1461 - fib_cnt[ZEBRA_ROUTE_IBGP]);
1462 vty_out(vty, "%-20s %-20d %-20d \n", "ibgp",
1463 rib_cnt[ZEBRA_ROUTE_IBGP],
1464 fib_cnt[ZEBRA_ROUTE_IBGP]);
1465 } else
1466 vty_out(vty, "%-20s %-20d %-20d \n",
1467 zebra_route_string(i), rib_cnt[i],
1468 fib_cnt[i]);
1469 }
1470 }
1471
1472 vty_out(vty, "------\n");
1473 vty_out(vty, "%-20s %-20d %-20d \n", "Totals",
1474 rib_cnt[ZEBRA_ROUTE_TOTAL], fib_cnt[ZEBRA_ROUTE_TOTAL]);
1475 vty_out(vty, "\n");
1476 }
1477
1478 /*
1479 * Show IPv6 mroute command.Used to dump
1480 * the Multicast routing table.
1481 */
1482 DEFUN (show_ipv6_mroute,
1483 show_ipv6_mroute_cmd,
1484 "show ipv6 mroute [vrf NAME]",
1485 SHOW_STR
1486 IP_STR
1487 "IPv6 Multicast routing table\n"
1488 VRF_CMD_HELP_STR)
1489 {
1490 struct route_table *table;
1491 struct route_node *rn;
1492 struct route_entry *re;
1493 int first = 1;
1494 vrf_id_t vrf_id = VRF_DEFAULT;
1495
1496 if (argc == 5)
1497 VRF_GET_ID(vrf_id, argv[4]->arg, false);
1498
1499 table = zebra_vrf_table(AFI_IP6, SAFI_MULTICAST, vrf_id);
1500 if (!table)
1501 return CMD_SUCCESS;
1502
1503 /* Show all IPv6 route. */
1504 for (rn = route_top(table); rn; rn = srcdest_route_next(rn))
1505 RNODE_FOREACH_RE (rn, re) {
1506 if (first) {
1507 vty_out(vty, SHOW_ROUTE_V6_HEADER);
1508 first = 0;
1509 }
1510 vty_show_ip_route(vty, rn, re, NULL);
1511 }
1512 return CMD_SUCCESS;
1513 }
1514
1515 DEFUN (show_ipv6_mroute_vrf_all,
1516 show_ipv6_mroute_vrf_all_cmd,
1517 "show ipv6 mroute vrf all",
1518 SHOW_STR
1519 IP_STR
1520 "IPv6 Multicast routing table\n"
1521 VRF_ALL_CMD_HELP_STR)
1522 {
1523 struct route_table *table;
1524 struct route_node *rn;
1525 struct route_entry *re;
1526 struct vrf *vrf;
1527 struct zebra_vrf *zvrf;
1528 int first = 1;
1529
1530 RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) {
1531 if ((zvrf = vrf->info) == NULL
1532 || (table = zvrf->table[AFI_IP6][SAFI_MULTICAST]) == NULL)
1533 continue;
1534
1535 /* Show all IPv6 route. */
1536 for (rn = route_top(table); rn; rn = srcdest_route_next(rn))
1537 RNODE_FOREACH_RE (rn, re) {
1538 if (first) {
1539 vty_out(vty, SHOW_ROUTE_V6_HEADER);
1540 first = 0;
1541 }
1542 vty_show_ip_route(vty, rn, re, NULL);
1543 }
1544 }
1545 return CMD_SUCCESS;
1546 }
1547
1548 DEFUN (allow_external_route_update,
1549 allow_external_route_update_cmd,
1550 "allow-external-route-update",
1551 "Allow FRR routes to be overwritten by external processes\n")
1552 {
1553 allow_delete = 1;
1554
1555 return CMD_SUCCESS;
1556 }
1557
1558 DEFUN (no_allow_external_route_update,
1559 no_allow_external_route_update_cmd,
1560 "no allow-external-route-update",
1561 NO_STR
1562 "Allow FRR routes to be overwritten by external processes\n")
1563 {
1564 allow_delete = 0;
1565
1566 return CMD_SUCCESS;
1567 }
1568
1569 /* show vrf */
1570 DEFUN (show_vrf,
1571 show_vrf_cmd,
1572 "show vrf",
1573 SHOW_STR
1574 "VRF\n")
1575 {
1576 struct vrf *vrf;
1577 struct zebra_vrf *zvrf;
1578
1579 if (vrf_is_backend_netns())
1580 vty_out(vty, "netns-based vrfs\n");
1581
1582 RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) {
1583 if (!(zvrf = vrf->info))
1584 continue;
1585 if (zvrf_id(zvrf) == VRF_DEFAULT)
1586 continue;
1587
1588 vty_out(vty, "vrf %s ", zvrf_name(zvrf));
1589 if (zvrf_id(zvrf) == VRF_UNKNOWN || !zvrf_is_active(zvrf))
1590 vty_out(vty, "inactive");
1591 else if (zvrf_ns_name(zvrf))
1592 vty_out(vty, "id %u netns %s", zvrf_id(zvrf),
1593 zvrf_ns_name(zvrf));
1594 else
1595 vty_out(vty, "id %u table %u", zvrf_id(zvrf),
1596 zvrf->table_id);
1597 if (vrf_is_user_cfged(vrf))
1598 vty_out(vty, " (configured)");
1599 vty_out(vty, "\n");
1600 }
1601
1602 return CMD_SUCCESS;
1603 }
1604
1605 DEFUN_HIDDEN (default_vrf_vni_mapping,
1606 default_vrf_vni_mapping_cmd,
1607 "vni " CMD_VNI_RANGE "[prefix-routes-only]",
1608 "VNI corresponding to the DEFAULT VRF\n"
1609 "VNI-ID\n"
1610 "Prefix routes only \n")
1611 {
1612 int ret = 0;
1613 char err[ERR_STR_SZ];
1614 struct zebra_vrf *zvrf = NULL;
1615 vni_t vni = strtoul(argv[1]->arg, NULL, 10);
1616 int filter = 0;
1617
1618 zvrf = vrf_info_lookup(VRF_DEFAULT);
1619 if (!zvrf)
1620 return CMD_WARNING;
1621
1622 if (argc == 3)
1623 filter = 1;
1624
1625 ret = zebra_vxlan_process_vrf_vni_cmd(zvrf, vni, err, ERR_STR_SZ,
1626 filter, 1);
1627 if (ret != 0) {
1628 vty_out(vty, "%s\n", err);
1629 return CMD_WARNING;
1630 }
1631
1632 return CMD_SUCCESS;
1633 }
1634
1635 DEFUN_HIDDEN (no_default_vrf_vni_mapping,
1636 no_default_vrf_vni_mapping_cmd,
1637 "no vni " CMD_VNI_RANGE,
1638 NO_STR
1639 "VNI corresponding to DEFAULT VRF\n"
1640 "VNI-ID")
1641 {
1642 int ret = 0;
1643 char err[ERR_STR_SZ];
1644 vni_t vni = strtoul(argv[2]->arg, NULL, 10);
1645 struct zebra_vrf *zvrf = NULL;
1646
1647 zvrf = vrf_info_lookup(VRF_DEFAULT);
1648 if (!zvrf)
1649 return CMD_WARNING;
1650
1651 ret = zebra_vxlan_process_vrf_vni_cmd(zvrf, vni, err, ERR_STR_SZ, 0, 0);
1652 if (ret != 0) {
1653 vty_out(vty, "%s\n", err);
1654 return CMD_WARNING;
1655 }
1656
1657 return CMD_SUCCESS;
1658 }
1659
1660 DEFUN (vrf_vni_mapping,
1661 vrf_vni_mapping_cmd,
1662 "vni " CMD_VNI_RANGE "[prefix-routes-only]",
1663 "VNI corresponding to tenant VRF\n"
1664 "VNI-ID\n"
1665 "prefix-routes-only\n")
1666 {
1667 int ret = 0;
1668 int filter = 0;
1669
1670 ZEBRA_DECLVAR_CONTEXT(vrf, zvrf);
1671 vni_t vni = strtoul(argv[1]->arg, NULL, 10);
1672 char err[ERR_STR_SZ];
1673
1674 assert(vrf);
1675 assert(zvrf);
1676
1677 if (argc == 3)
1678 filter = 1;
1679
1680 /* Mark as having FRR configuration */
1681 vrf_set_user_cfged(vrf);
1682 ret = zebra_vxlan_process_vrf_vni_cmd(zvrf, vni, err, ERR_STR_SZ,
1683 filter, 1);
1684 if (ret != 0) {
1685 vty_out(vty, "%s\n", err);
1686 return CMD_WARNING;
1687 }
1688
1689 return CMD_SUCCESS;
1690 }
1691
1692 DEFUN (no_vrf_vni_mapping,
1693 no_vrf_vni_mapping_cmd,
1694 "no vni " CMD_VNI_RANGE "[prefix-routes-only]",
1695 NO_STR
1696 "VNI corresponding to tenant VRF\n"
1697 "VNI-ID\n"
1698 "prefix-routes-only\n")
1699 {
1700 int ret = 0;
1701 int filter = 0;
1702 char err[ERR_STR_SZ];
1703 vni_t vni = strtoul(argv[2]->arg, NULL, 10);
1704
1705 ZEBRA_DECLVAR_CONTEXT(vrf, zvrf);
1706
1707 assert(vrf);
1708 assert(zvrf);
1709
1710 if (argc == 4)
1711 filter = 1;
1712
1713 ret = zebra_vxlan_process_vrf_vni_cmd(zvrf, vni, err,
1714 ERR_STR_SZ, filter, 0);
1715 if (ret != 0) {
1716 vty_out(vty, "%s\n", err);
1717 return CMD_WARNING;
1718 }
1719
1720 /* If no other FRR config for this VRF, mark accordingly. */
1721 if (!zebra_vrf_has_config(zvrf))
1722 vrf_reset_user_cfged(vrf);
1723
1724 return CMD_SUCCESS;
1725 }
1726
1727 /* show vrf */
1728 DEFUN (show_vrf_vni,
1729 show_vrf_vni_cmd,
1730 "show vrf vni [json]",
1731 SHOW_STR
1732 "VRF\n"
1733 "VNI\n"
1734 JSON_STR)
1735 {
1736 struct vrf *vrf;
1737 struct zebra_vrf *zvrf;
1738 json_object *json = NULL;
1739 json_object *json_vrfs = NULL;
1740 bool uj = use_json(argc, argv);
1741
1742 if (uj) {
1743 json = json_object_new_object();
1744 json_vrfs = json_object_new_array();
1745 }
1746
1747 if (!uj)
1748 vty_out(vty, "%-37s %-10s %-20s %-20s %-5s %-18s\n", "VRF",
1749 "VNI", "VxLAN IF", "L3-SVI", "State", "Rmac");
1750
1751 RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) {
1752 zvrf = vrf->info;
1753 if (!zvrf)
1754 continue;
1755
1756 zebra_vxlan_print_vrf_vni(vty, zvrf, json_vrfs);
1757 }
1758
1759 if (uj) {
1760 json_object_object_add(json, "vrfs", json_vrfs);
1761 vty_out(vty, "%s\n", json_object_to_json_string_ext(
1762 json, JSON_C_TO_STRING_PRETTY));
1763 json_object_free(json);
1764 }
1765
1766 return CMD_SUCCESS;
1767 }
1768
1769 DEFUN (show_evpn_global,
1770 show_evpn_global_cmd,
1771 "show evpn [json]",
1772 SHOW_STR
1773 "EVPN\n"
1774 JSON_STR)
1775 {
1776 bool uj = use_json(argc, argv);
1777
1778 zebra_vxlan_print_evpn(vty, uj);
1779 return CMD_SUCCESS;
1780 }
1781
1782 DEFUN (show_evpn_vni,
1783 show_evpn_vni_cmd,
1784 "show evpn vni [json]",
1785 SHOW_STR
1786 "EVPN\n"
1787 "VxLAN information\n"
1788 JSON_STR)
1789 {
1790 struct zebra_vrf *zvrf;
1791 bool uj = use_json(argc, argv);
1792
1793 zvrf = vrf_info_lookup(VRF_DEFAULT);
1794 zebra_vxlan_print_vnis(vty, zvrf, uj);
1795 return CMD_SUCCESS;
1796 }
1797
1798 DEFUN (show_evpn_vni_vni,
1799 show_evpn_vni_vni_cmd,
1800 "show evpn vni " CMD_VNI_RANGE "[json]",
1801 SHOW_STR
1802 "EVPN\n"
1803 "VxLAN Network Identifier\n"
1804 "VNI number\n"
1805 JSON_STR)
1806 {
1807 struct zebra_vrf *zvrf;
1808 vni_t vni;
1809 bool uj = use_json(argc, argv);
1810
1811 vni = strtoul(argv[3]->arg, NULL, 10);
1812 zvrf = vrf_info_lookup(VRF_DEFAULT);
1813 zebra_vxlan_print_vni(vty, zvrf, vni, uj);
1814 return CMD_SUCCESS;
1815 }
1816
1817 DEFUN (show_evpn_rmac_vni_mac,
1818 show_evpn_rmac_vni_mac_cmd,
1819 "show evpn rmac vni " CMD_VNI_RANGE " mac WORD [json]",
1820 SHOW_STR
1821 "EVPN\n"
1822 "RMAC\n"
1823 "L3 VNI\n"
1824 "VNI number\n"
1825 "MAC\n"
1826 "mac-address (e.g. 0a:0a:0a:0a:0a:0a)\n"
1827 JSON_STR)
1828 {
1829 vni_t l3vni = 0;
1830 struct ethaddr mac;
1831 bool uj = use_json(argc, argv);
1832
1833 l3vni = strtoul(argv[4]->arg, NULL, 10);
1834 if (!prefix_str2mac(argv[6]->arg, &mac)) {
1835 vty_out(vty, "%% Malformed MAC address\n");
1836 return CMD_WARNING;
1837 }
1838 zebra_vxlan_print_specific_rmac_l3vni(vty, l3vni, &mac, uj);
1839 return CMD_SUCCESS;
1840 }
1841
1842 DEFUN (show_evpn_rmac_vni,
1843 show_evpn_rmac_vni_cmd,
1844 "show evpn rmac vni " CMD_VNI_RANGE "[json]",
1845 SHOW_STR
1846 "EVPN\n"
1847 "RMAC\n"
1848 "L3 VNI\n"
1849 "VNI number\n"
1850 JSON_STR)
1851 {
1852 vni_t l3vni = 0;
1853 bool uj = use_json(argc, argv);
1854
1855 l3vni = strtoul(argv[4]->arg, NULL, 10);
1856 zebra_vxlan_print_rmacs_l3vni(vty, l3vni, uj);
1857
1858 return CMD_SUCCESS;
1859 }
1860
1861 DEFUN (show_evpn_rmac_vni_all,
1862 show_evpn_rmac_vni_all_cmd,
1863 "show evpn rmac vni all [json]",
1864 SHOW_STR
1865 "EVPN\n"
1866 "RMAC addresses\n"
1867 "L3 VNI\n"
1868 "All VNIs\n"
1869 JSON_STR)
1870 {
1871 bool uj = use_json(argc, argv);
1872
1873 zebra_vxlan_print_rmacs_all_l3vni(vty, uj);
1874
1875 return CMD_SUCCESS;
1876 }
1877
1878 DEFUN (show_evpn_nh_vni_ip,
1879 show_evpn_nh_vni_ip_cmd,
1880 "show evpn next-hops vni " CMD_VNI_RANGE " ip WORD [json]",
1881 SHOW_STR
1882 "EVPN\n"
1883 "Remote Vteps\n"
1884 "L3 VNI\n"
1885 "VNI number\n"
1886 "Ip address\n"
1887 "Host address (ipv4 or ipv6)\n"
1888 JSON_STR)
1889 {
1890 vni_t l3vni;
1891 struct ipaddr ip;
1892 bool uj = use_json(argc, argv);
1893
1894 l3vni = strtoul(argv[4]->arg, NULL, 10);
1895 if (str2ipaddr(argv[6]->arg, &ip) != 0) {
1896 if (!uj)
1897 vty_out(vty, "%% Malformed Neighbor address\n");
1898 return CMD_WARNING;
1899 }
1900 zebra_vxlan_print_specific_nh_l3vni(vty, l3vni, &ip, uj);
1901
1902 return CMD_SUCCESS;
1903 }
1904
1905 DEFUN (show_evpn_nh_vni,
1906 show_evpn_nh_vni_cmd,
1907 "show evpn next-hops vni " CMD_VNI_RANGE "[json]",
1908 SHOW_STR
1909 "EVPN\n"
1910 "Remote Vteps\n"
1911 "L3 VNI\n"
1912 "VNI number\n"
1913 JSON_STR)
1914 {
1915 vni_t l3vni;
1916 bool uj = use_json(argc, argv);
1917
1918 l3vni = strtoul(argv[4]->arg, NULL, 10);
1919 zebra_vxlan_print_nh_l3vni(vty, l3vni, uj);
1920
1921 return CMD_SUCCESS;
1922 }
1923
1924 DEFUN (show_evpn_nh_vni_all,
1925 show_evpn_nh_vni_all_cmd,
1926 "show evpn next-hops vni all [json]",
1927 SHOW_STR
1928 "EVPN\n"
1929 "Remote VTEPs\n"
1930 "L3 VNI\n"
1931 "All VNIs\n"
1932 JSON_STR)
1933 {
1934 bool uj = use_json(argc, argv);
1935
1936 zebra_vxlan_print_nh_all_l3vni(vty, uj);
1937
1938 return CMD_SUCCESS;
1939 }
1940
1941 DEFUN (show_evpn_mac_vni,
1942 show_evpn_mac_vni_cmd,
1943 "show evpn mac vni " CMD_VNI_RANGE "[json]",
1944 SHOW_STR
1945 "EVPN\n"
1946 "MAC addresses\n"
1947 "VxLAN Network Identifier\n"
1948 "VNI number\n"
1949 JSON_STR)
1950 {
1951 struct zebra_vrf *zvrf;
1952 vni_t vni;
1953 bool uj = use_json(argc, argv);
1954
1955 vni = strtoul(argv[4]->arg, NULL, 10);
1956 zvrf = vrf_info_lookup(VRF_DEFAULT);
1957 zebra_vxlan_print_macs_vni(vty, zvrf, vni, uj);
1958 return CMD_SUCCESS;
1959 }
1960
1961 DEFUN (show_evpn_mac_vni_all,
1962 show_evpn_mac_vni_all_cmd,
1963 "show evpn mac vni all [json]",
1964 SHOW_STR
1965 "EVPN\n"
1966 "MAC addresses\n"
1967 "VxLAN Network Identifier\n"
1968 "All VNIs\n"
1969 JSON_STR)
1970 {
1971 struct zebra_vrf *zvrf;
1972 bool uj = use_json(argc, argv);
1973
1974 zvrf = vrf_info_lookup(VRF_DEFAULT);
1975 zebra_vxlan_print_macs_all_vni(vty, zvrf, uj);
1976 return CMD_SUCCESS;
1977 }
1978
1979 DEFUN (show_evpn_mac_vni_all_vtep,
1980 show_evpn_mac_vni_all_vtep_cmd,
1981 "show evpn mac vni all vtep A.B.C.D [json]",
1982 SHOW_STR
1983 "EVPN\n"
1984 "MAC addresses\n"
1985 "VxLAN Network Identifier\n"
1986 "All VNIs\n"
1987 "Remote VTEP\n"
1988 "Remote VTEP IP address\n"
1989 JSON_STR)
1990 {
1991 struct zebra_vrf *zvrf;
1992 struct in_addr vtep_ip;
1993 bool uj = use_json(argc, argv);
1994
1995 if (!inet_aton(argv[6]->arg, &vtep_ip)) {
1996 if (!uj)
1997 vty_out(vty, "%% Malformed VTEP IP address\n");
1998 return CMD_WARNING;
1999 }
2000 zvrf = vrf_info_lookup(VRF_DEFAULT);
2001 zebra_vxlan_print_macs_all_vni_vtep(vty, zvrf, vtep_ip, uj);
2002
2003 return CMD_SUCCESS;
2004 }
2005
2006
2007 DEFUN (show_evpn_mac_vni_mac,
2008 show_evpn_mac_vni_mac_cmd,
2009 "show evpn mac vni " CMD_VNI_RANGE " mac WORD",
2010 SHOW_STR
2011 "EVPN\n"
2012 "MAC addresses\n"
2013 "VxLAN Network Identifier\n"
2014 "VNI number\n"
2015 "MAC\n"
2016 "MAC address (e.g., 00:e0:ec:20:12:62)\n")
2017 {
2018 struct zebra_vrf *zvrf;
2019 vni_t vni;
2020 struct ethaddr mac;
2021
2022 vni = strtoul(argv[4]->arg, NULL, 10);
2023 if (!prefix_str2mac(argv[6]->arg, &mac)) {
2024 vty_out(vty, "%% Malformed MAC address");
2025 return CMD_WARNING;
2026 }
2027 zvrf = vrf_info_lookup(VRF_DEFAULT);
2028 zebra_vxlan_print_specific_mac_vni(vty, zvrf, vni, &mac);
2029 return CMD_SUCCESS;
2030 }
2031
2032 DEFUN (show_evpn_mac_vni_vtep,
2033 show_evpn_mac_vni_vtep_cmd,
2034 "show evpn mac vni " CMD_VNI_RANGE " vtep A.B.C.D" "[json]",
2035 SHOW_STR
2036 "EVPN\n"
2037 "MAC addresses\n"
2038 "VxLAN Network Identifier\n"
2039 "VNI number\n"
2040 "Remote VTEP\n"
2041 "Remote VTEP IP address\n"
2042 JSON_STR)
2043 {
2044 struct zebra_vrf *zvrf;
2045 vni_t vni;
2046 struct in_addr vtep_ip;
2047 bool uj = use_json(argc, argv);
2048
2049 vni = strtoul(argv[4]->arg, NULL, 10);
2050 if (!inet_aton(argv[6]->arg, &vtep_ip)) {
2051 if (!uj)
2052 vty_out(vty, "%% Malformed VTEP IP address\n");
2053 return CMD_WARNING;
2054 }
2055
2056 zvrf = vrf_info_lookup(VRF_DEFAULT);
2057 zebra_vxlan_print_macs_vni_vtep(vty, zvrf, vni, vtep_ip, uj);
2058 return CMD_SUCCESS;
2059 }
2060
2061 DEFUN (show_evpn_neigh_vni,
2062 show_evpn_neigh_vni_cmd,
2063 "show evpn arp-cache vni " CMD_VNI_RANGE "[json]",
2064 SHOW_STR
2065 "EVPN\n"
2066 "ARP and ND cache\n"
2067 "VxLAN Network Identifier\n"
2068 "VNI number\n"
2069 JSON_STR)
2070 {
2071 struct zebra_vrf *zvrf;
2072 vni_t vni;
2073 bool uj = use_json(argc, argv);
2074
2075 vni = strtoul(argv[4]->arg, NULL, 10);
2076 zvrf = vrf_info_lookup(VRF_DEFAULT);
2077 zebra_vxlan_print_neigh_vni(vty, zvrf, vni, uj);
2078 return CMD_SUCCESS;
2079 }
2080
2081 DEFUN (show_evpn_neigh_vni_all,
2082 show_evpn_neigh_vni_all_cmd,
2083 "show evpn arp-cache vni all [json]",
2084 SHOW_STR
2085 "EVPN\n"
2086 "ARP and ND cache\n"
2087 "VxLAN Network Identifier\n"
2088 "All VNIs\n"
2089 JSON_STR)
2090 {
2091 struct zebra_vrf *zvrf;
2092 bool uj = use_json(argc, argv);
2093
2094 zvrf = vrf_info_lookup(VRF_DEFAULT);
2095 zebra_vxlan_print_neigh_all_vni(vty, zvrf, uj);
2096 return CMD_SUCCESS;
2097 }
2098
2099 DEFUN (show_evpn_neigh_vni_neigh,
2100 show_evpn_neigh_vni_neigh_cmd,
2101 "show evpn arp-cache vni " CMD_VNI_RANGE " ip WORD [json]",
2102 SHOW_STR
2103 "EVPN\n"
2104 "ARP and ND cache\n"
2105 "VxLAN Network Identifier\n"
2106 "VNI number\n"
2107 "Neighbor\n"
2108 "Neighbor address (IPv4 or IPv6 address)\n"
2109 JSON_STR)
2110 {
2111 struct zebra_vrf *zvrf;
2112 vni_t vni;
2113 struct ipaddr ip;
2114 bool uj = use_json(argc, argv);
2115
2116 vni = strtoul(argv[4]->arg, NULL, 10);
2117 if (str2ipaddr(argv[6]->arg, &ip) != 0) {
2118 if (!uj)
2119 vty_out(vty, "%% Malformed Neighbor address\n");
2120 return CMD_WARNING;
2121 }
2122 zvrf = vrf_info_lookup(VRF_DEFAULT);
2123 zebra_vxlan_print_specific_neigh_vni(vty, zvrf, vni, &ip, uj);
2124 return CMD_SUCCESS;
2125 }
2126
2127 DEFUN (show_evpn_neigh_vni_vtep,
2128 show_evpn_neigh_vni_vtep_cmd,
2129 "show evpn arp-cache vni " CMD_VNI_RANGE " vtep A.B.C.D [json]",
2130 SHOW_STR
2131 "EVPN\n"
2132 "ARP and ND cache\n"
2133 "VxLAN Network Identifier\n"
2134 "VNI number\n"
2135 "Remote VTEP\n"
2136 "Remote VTEP IP address\n"
2137 JSON_STR)
2138 {
2139 struct zebra_vrf *zvrf;
2140 vni_t vni;
2141 struct in_addr vtep_ip;
2142 bool uj = use_json(argc, argv);
2143
2144 vni = strtoul(argv[4]->arg, NULL, 10);
2145 if (!inet_aton(argv[6]->arg, &vtep_ip)) {
2146 if (!uj)
2147 vty_out(vty, "%% Malformed VTEP IP address\n");
2148 return CMD_WARNING;
2149 }
2150
2151 zvrf = vrf_info_lookup(VRF_DEFAULT);
2152 zebra_vxlan_print_neigh_vni_vtep(vty, zvrf, vni, vtep_ip, uj);
2153 return CMD_SUCCESS;
2154 }
2155
2156 /* policy routing contexts */
2157 DEFUN (show_pbr_ipset,
2158 show_pbr_ipset_cmd,
2159 "show pbr ipset [WORD]",
2160 SHOW_STR
2161 "Policy-Based Routing\n"
2162 "IPset Context information\n"
2163 "IPset Name information\n")
2164 {
2165 int idx = 0;
2166 int found = 0;
2167 found = argv_find(argv, argc, "WORD", &idx);
2168 if (!found)
2169 zebra_pbr_show_ipset_list(vty, NULL);
2170 else
2171 zebra_pbr_show_ipset_list(vty, argv[idx]->arg);
2172 return CMD_SUCCESS;
2173 }
2174
2175 /* policy routing contexts */
2176 DEFUN (show_pbr_iptable,
2177 show_pbr_iptable_cmd,
2178 "show pbr iptable [WORD]",
2179 SHOW_STR
2180 "Policy-Based Routing\n"
2181 "IPtable Context information\n"
2182 "IPtable Name information\n")
2183 {
2184 int idx = 0;
2185 int found = 0;
2186
2187 found = argv_find(argv, argc, "WORD", &idx);
2188 if (!found)
2189 zebra_pbr_show_iptable(vty, NULL);
2190 else
2191 zebra_pbr_show_iptable(vty, argv[idx]->arg);
2192 return CMD_SUCCESS;
2193 }
2194
2195 /* Static ip route configuration write function. */
2196 static int zebra_ip_config(struct vty *vty)
2197 {
2198 int write = 0;
2199
2200 write += zebra_import_table_config(vty);
2201
2202 return write;
2203 }
2204
2205 DEFUN (ip_zebra_import_table_distance,
2206 ip_zebra_import_table_distance_cmd,
2207 "ip import-table (1-252) [distance (1-255)] [route-map WORD]",
2208 IP_STR
2209 "import routes from non-main kernel table\n"
2210 "kernel routing table id\n"
2211 "Distance for imported routes\n"
2212 "Default distance value\n"
2213 "route-map for filtering\n"
2214 "route-map name\n")
2215 {
2216 uint32_t table_id = 0;
2217
2218 table_id = strtoul(argv[2]->arg, NULL, 10);
2219 int distance = ZEBRA_TABLE_DISTANCE_DEFAULT;
2220 char *rmap =
2221 strmatch(argv[argc - 2]->text, "route-map")
2222 ? XSTRDUP(MTYPE_ROUTE_MAP_NAME, argv[argc - 1]->arg)
2223 : NULL;
2224 int ret;
2225
2226 if (argc == 7 || (argc == 5 && !rmap))
2227 distance = strtoul(argv[4]->arg, NULL, 10);
2228
2229 if (!is_zebra_valid_kernel_table(table_id)) {
2230 vty_out(vty,
2231 "Invalid routing table ID, %d. Must be in range 1-252\n",
2232 table_id);
2233 if (rmap)
2234 XFREE(MTYPE_ROUTE_MAP_NAME, rmap);
2235 return CMD_WARNING;
2236 }
2237
2238 if (is_zebra_main_routing_table(table_id)) {
2239 vty_out(vty,
2240 "Invalid routing table ID, %d. Must be non-default table\n",
2241 table_id);
2242 if (rmap)
2243 XFREE(MTYPE_ROUTE_MAP_NAME, rmap);
2244 return CMD_WARNING;
2245 }
2246
2247 ret = zebra_import_table(AFI_IP, table_id, distance, rmap, 1);
2248 if (rmap)
2249 XFREE(MTYPE_ROUTE_MAP_NAME, rmap);
2250
2251 return ret;
2252 }
2253
2254 DEFUN_HIDDEN (zebra_packet_process,
2255 zebra_packet_process_cmd,
2256 "zebra zapi-packets (1-10000)",
2257 ZEBRA_STR
2258 "Zapi Protocol\n"
2259 "Number of packets to process before relinquishing thread\n")
2260 {
2261 uint32_t packets = strtoul(argv[2]->arg, NULL, 10);
2262
2263 atomic_store_explicit(&zebrad.packets_to_process, packets,
2264 memory_order_relaxed);
2265
2266 return CMD_SUCCESS;
2267 }
2268
2269 DEFUN_HIDDEN (no_zebra_packet_process,
2270 no_zebra_packet_process_cmd,
2271 "no zebra zapi-packets [(1-10000)]",
2272 NO_STR
2273 ZEBRA_STR
2274 "Zapi Protocol\n"
2275 "Number of packets to process before relinquishing thread\n")
2276 {
2277 atomic_store_explicit(&zebrad.packets_to_process,
2278 ZEBRA_ZAPI_PACKETS_TO_PROCESS,
2279 memory_order_relaxed);
2280
2281 return CMD_SUCCESS;
2282 }
2283
2284 DEFUN_HIDDEN (zebra_workqueue_timer,
2285 zebra_workqueue_timer_cmd,
2286 "zebra work-queue (0-10000)",
2287 ZEBRA_STR
2288 "Work Queue\n"
2289 "Time in milliseconds\n")
2290 {
2291 uint32_t timer = strtoul(argv[2]->arg, NULL, 10);
2292 zebrad.ribq->spec.hold = timer;
2293
2294 return CMD_SUCCESS;
2295 }
2296
2297 DEFUN_HIDDEN (no_zebra_workqueue_timer,
2298 no_zebra_workqueue_timer_cmd,
2299 "no zebra work-queue [(0-10000)]",
2300 NO_STR
2301 ZEBRA_STR
2302 "Work Queue\n"
2303 "Time in milliseconds\n")
2304 {
2305 zebrad.ribq->spec.hold = ZEBRA_RIB_PROCESS_HOLD_TIME;
2306
2307 return CMD_SUCCESS;
2308 }
2309
2310 DEFUN (no_ip_zebra_import_table,
2311 no_ip_zebra_import_table_cmd,
2312 "no ip import-table (1-252) [distance (1-255)] [route-map NAME]",
2313 NO_STR
2314 IP_STR
2315 "import routes from non-main kernel table\n"
2316 "kernel routing table id\n"
2317 "Distance for imported routes\n"
2318 "Default distance value\n"
2319 "route-map for filtering\n"
2320 "route-map name\n")
2321 {
2322 uint32_t table_id = 0;
2323 table_id = strtoul(argv[3]->arg, NULL, 10);
2324
2325 if (!is_zebra_valid_kernel_table(table_id)) {
2326 vty_out(vty,
2327 "Invalid routing table ID. Must be in range 1-252\n");
2328 return CMD_WARNING;
2329 }
2330
2331 if (is_zebra_main_routing_table(table_id)) {
2332 vty_out(vty,
2333 "Invalid routing table ID, %d. Must be non-default table\n",
2334 table_id);
2335 return CMD_WARNING;
2336 }
2337
2338 if (!is_zebra_import_table_enabled(AFI_IP, table_id))
2339 return CMD_SUCCESS;
2340
2341 return (zebra_import_table(AFI_IP, table_id, 0, NULL, 0));
2342 }
2343
2344 static int config_write_protocol(struct vty *vty)
2345 {
2346 if (allow_delete)
2347 vty_out(vty, "allow-external-route-update\n");
2348
2349 if (zebra_rnh_ip_default_route)
2350 vty_out(vty, "ip nht resolve-via-default\n");
2351
2352 if (zebra_rnh_ipv6_default_route)
2353 vty_out(vty, "ipv6 nht resolve-via-default\n");
2354
2355 if (zebrad.ribq->spec.hold != ZEBRA_RIB_PROCESS_HOLD_TIME)
2356 vty_out(vty, "zebra work-queue %u\n", zebrad.ribq->spec.hold);
2357
2358 if (zebrad.packets_to_process != ZEBRA_ZAPI_PACKETS_TO_PROCESS)
2359 vty_out(vty, "zebra zapi-packets %u\n",
2360 zebrad.packets_to_process);
2361
2362 enum multicast_mode ipv4_multicast_mode = multicast_mode_ipv4_get();
2363
2364 if (ipv4_multicast_mode != MCAST_NO_CONFIG)
2365 vty_out(vty, "ip multicast rpf-lookup-mode %s\n",
2366 ipv4_multicast_mode == MCAST_URIB_ONLY
2367 ? "urib-only"
2368 : ipv4_multicast_mode == MCAST_MRIB_ONLY
2369 ? "mrib-only"
2370 : ipv4_multicast_mode
2371 == MCAST_MIX_MRIB_FIRST
2372 ? "mrib-then-urib"
2373 : ipv4_multicast_mode
2374 == MCAST_MIX_DISTANCE
2375 ? "lower-distance"
2376 : "longer-prefix");
2377 return 1;
2378 }
2379
2380 #ifdef HAVE_NETLINK
2381 /* Display default rtm_table for all clients. */
2382 DEFUN (show_table,
2383 show_table_cmd,
2384 "show table",
2385 SHOW_STR
2386 "default routing table to use for all clients\n")
2387 {
2388 vty_out(vty, "table %d\n", zebrad.rtm_table_default);
2389 return CMD_SUCCESS;
2390 }
2391
2392 DEFUN (config_table,
2393 config_table_cmd,
2394 "table TABLENO",
2395 "Configure target kernel routing table\n"
2396 "TABLE integer\n")
2397 {
2398 zebrad.rtm_table_default = strtol(argv[1]->arg, (char **)0, 10);
2399 return CMD_SUCCESS;
2400 }
2401
2402 DEFUN (no_config_table,
2403 no_config_table_cmd,
2404 "no table [TABLENO]",
2405 NO_STR
2406 "Configure target kernel routing table\n"
2407 "TABLE integer\n")
2408 {
2409 zebrad.rtm_table_default = 0;
2410 return CMD_SUCCESS;
2411 }
2412 #endif
2413
2414 DEFUN (show_zebra,
2415 show_zebra_cmd,
2416 "show zebra",
2417 SHOW_STR
2418 ZEBRA_STR)
2419 {
2420 struct vrf *vrf;
2421
2422 vty_out(vty,
2423 " Route Route Neighbor LSP LSP\n");
2424 vty_out(vty,
2425 "VRF Installs Removals Updates Installs Removals\n");
2426
2427 RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) {
2428 struct zebra_vrf *zvrf = vrf->info;
2429
2430 vty_out(vty, "%-25s %10" PRIu64 " %10" PRIu64 " %10" PRIu64
2431 " %10" PRIu64 " %10" PRIu64 "\n",
2432 vrf->name, zvrf->installs, zvrf->removals,
2433 zvrf->neigh_updates, zvrf->lsp_installs,
2434 zvrf->lsp_removals);
2435 }
2436
2437 return CMD_SUCCESS;
2438 }
2439
2440 DEFUN (ip_forwarding,
2441 ip_forwarding_cmd,
2442 "ip forwarding",
2443 IP_STR
2444 "Turn on IP forwarding\n")
2445 {
2446 int ret;
2447
2448 ret = ipforward();
2449 if (ret == 0)
2450 ret = ipforward_on();
2451
2452 if (ret == 0) {
2453 vty_out(vty, "Can't turn on IP forwarding\n");
2454 return CMD_WARNING_CONFIG_FAILED;
2455 }
2456
2457 return CMD_SUCCESS;
2458 }
2459
2460 DEFUN (no_ip_forwarding,
2461 no_ip_forwarding_cmd,
2462 "no ip forwarding",
2463 NO_STR
2464 IP_STR
2465 "Turn off IP forwarding\n")
2466 {
2467 int ret;
2468
2469 ret = ipforward();
2470 if (ret != 0)
2471 ret = ipforward_off();
2472
2473 if (ret != 0) {
2474 vty_out(vty, "Can't turn off IP forwarding\n");
2475 return CMD_WARNING_CONFIG_FAILED;
2476 }
2477
2478 return CMD_SUCCESS;
2479 }
2480
2481 /* Only display ip forwarding is enabled or not. */
2482 DEFUN (show_ip_forwarding,
2483 show_ip_forwarding_cmd,
2484 "show ip forwarding",
2485 SHOW_STR
2486 IP_STR
2487 "IP forwarding status\n")
2488 {
2489 int ret;
2490
2491 ret = ipforward();
2492
2493 if (ret == 0)
2494 vty_out(vty, "IP forwarding is off\n");
2495 else
2496 vty_out(vty, "IP forwarding is on\n");
2497 return CMD_SUCCESS;
2498 }
2499
2500 /* Only display ipv6 forwarding is enabled or not. */
2501 DEFUN (show_ipv6_forwarding,
2502 show_ipv6_forwarding_cmd,
2503 "show ipv6 forwarding",
2504 SHOW_STR
2505 "IPv6 information\n"
2506 "Forwarding status\n")
2507 {
2508 int ret;
2509
2510 ret = ipforward_ipv6();
2511
2512 switch (ret) {
2513 case -1:
2514 vty_out(vty, "ipv6 forwarding is unknown\n");
2515 break;
2516 case 0:
2517 vty_out(vty, "ipv6 forwarding is %s\n", "off");
2518 break;
2519 case 1:
2520 vty_out(vty, "ipv6 forwarding is %s\n", "on");
2521 break;
2522 default:
2523 vty_out(vty, "ipv6 forwarding is %s\n", "off");
2524 break;
2525 }
2526 return CMD_SUCCESS;
2527 }
2528
2529 DEFUN (ipv6_forwarding,
2530 ipv6_forwarding_cmd,
2531 "ipv6 forwarding",
2532 IPV6_STR
2533 "Turn on IPv6 forwarding\n")
2534 {
2535 int ret;
2536
2537 ret = ipforward_ipv6();
2538 if (ret == 0)
2539 ret = ipforward_ipv6_on();
2540
2541 if (ret == 0) {
2542 vty_out(vty, "Can't turn on IPv6 forwarding\n");
2543 return CMD_WARNING_CONFIG_FAILED;
2544 }
2545
2546 return CMD_SUCCESS;
2547 }
2548
2549 DEFUN (no_ipv6_forwarding,
2550 no_ipv6_forwarding_cmd,
2551 "no ipv6 forwarding",
2552 NO_STR
2553 IPV6_STR
2554 "Turn off IPv6 forwarding\n")
2555 {
2556 int ret;
2557
2558 ret = ipforward_ipv6();
2559 if (ret != 0)
2560 ret = ipforward_ipv6_off();
2561
2562 if (ret != 0) {
2563 vty_out(vty, "Can't turn off IPv6 forwarding\n");
2564 return CMD_WARNING_CONFIG_FAILED;
2565 }
2566
2567 return CMD_SUCCESS;
2568 }
2569
2570 /* Table configuration write function. */
2571 static int config_write_table(struct vty *vty)
2572 {
2573 if (zebrad.rtm_table_default)
2574 vty_out(vty, "table %d\n", zebrad.rtm_table_default);
2575 return 0;
2576 }
2577
2578 /* IPForwarding configuration write function. */
2579 static int config_write_forwarding(struct vty *vty)
2580 {
2581 /* FIXME: Find better place for that. */
2582 router_id_write(vty);
2583
2584 if (!ipforward())
2585 vty_out(vty, "no ip forwarding\n");
2586 if (!ipforward_ipv6())
2587 vty_out(vty, "no ipv6 forwarding\n");
2588 vty_out(vty, "!\n");
2589 return 0;
2590 }
2591
2592 /* IP node for static routes. */
2593 static struct cmd_node ip_node = {IP_NODE, "", 1};
2594 static struct cmd_node protocol_node = {PROTOCOL_NODE, "", 1};
2595 /* table node for routing tables. */
2596 static struct cmd_node table_node = {TABLE_NODE,
2597 "", /* This node has no interface. */
2598 1};
2599 static struct cmd_node forwarding_node = {FORWARDING_NODE,
2600 "", /* This node has no interface. */
2601 1};
2602
2603 /* Route VTY. */
2604 void zebra_vty_init(void)
2605 {
2606 /* Install configuration write function. */
2607 install_node(&table_node, config_write_table);
2608 install_node(&forwarding_node, config_write_forwarding);
2609
2610 install_element(VIEW_NODE, &show_ip_forwarding_cmd);
2611 install_element(CONFIG_NODE, &ip_forwarding_cmd);
2612 install_element(CONFIG_NODE, &no_ip_forwarding_cmd);
2613 install_element(ENABLE_NODE, &show_zebra_cmd);
2614
2615 #ifdef HAVE_NETLINK
2616 install_element(VIEW_NODE, &show_table_cmd);
2617 install_element(CONFIG_NODE, &config_table_cmd);
2618 install_element(CONFIG_NODE, &no_config_table_cmd);
2619 #endif /* HAVE_NETLINK */
2620
2621 install_element(VIEW_NODE, &show_ipv6_forwarding_cmd);
2622 install_element(CONFIG_NODE, &ipv6_forwarding_cmd);
2623 install_element(CONFIG_NODE, &no_ipv6_forwarding_cmd);
2624
2625 /* Route-map */
2626 zebra_route_map_init();
2627
2628 install_node(&ip_node, zebra_ip_config);
2629 install_node(&protocol_node, config_write_protocol);
2630
2631 install_element(CONFIG_NODE, &allow_external_route_update_cmd);
2632 install_element(CONFIG_NODE, &no_allow_external_route_update_cmd);
2633
2634 install_element(CONFIG_NODE, &ip_multicast_mode_cmd);
2635 install_element(CONFIG_NODE, &no_ip_multicast_mode_cmd);
2636
2637 install_element(CONFIG_NODE, &ip_zebra_import_table_distance_cmd);
2638 install_element(CONFIG_NODE, &no_ip_zebra_import_table_cmd);
2639 install_element(CONFIG_NODE, &zebra_workqueue_timer_cmd);
2640 install_element(CONFIG_NODE, &no_zebra_workqueue_timer_cmd);
2641 install_element(CONFIG_NODE, &zebra_packet_process_cmd);
2642 install_element(CONFIG_NODE, &no_zebra_packet_process_cmd);
2643
2644 install_element(VIEW_NODE, &show_vrf_cmd);
2645 install_element(VIEW_NODE, &show_vrf_vni_cmd);
2646 install_element(VIEW_NODE, &show_route_cmd);
2647 install_element(VIEW_NODE, &show_route_table_cmd);
2648 if (vrf_is_backend_netns())
2649 install_element(VIEW_NODE, &show_route_table_vrf_cmd);
2650 install_element(VIEW_NODE, &show_route_detail_cmd);
2651 install_element(VIEW_NODE, &show_route_summary_cmd);
2652 install_element(VIEW_NODE, &show_ip_nht_cmd);
2653 install_element(VIEW_NODE, &show_ip_nht_vrf_all_cmd);
2654 install_element(VIEW_NODE, &show_ipv6_nht_cmd);
2655 install_element(VIEW_NODE, &show_ipv6_nht_vrf_all_cmd);
2656
2657 install_element(VIEW_NODE, &show_ip_rpf_cmd);
2658 install_element(VIEW_NODE, &show_ip_rpf_addr_cmd);
2659
2660 install_element(CONFIG_NODE, &ip_nht_default_route_cmd);
2661 install_element(CONFIG_NODE, &no_ip_nht_default_route_cmd);
2662 install_element(CONFIG_NODE, &ipv6_nht_default_route_cmd);
2663 install_element(CONFIG_NODE, &no_ipv6_nht_default_route_cmd);
2664 install_element(VRF_NODE, &ip_nht_default_route_cmd);
2665 install_element(VRF_NODE, &no_ip_nht_default_route_cmd);
2666 install_element(VRF_NODE, &ipv6_nht_default_route_cmd);
2667 install_element(VRF_NODE, &no_ipv6_nht_default_route_cmd);
2668 install_element(VIEW_NODE, &show_ipv6_mroute_cmd);
2669
2670 /* Commands for VRF */
2671 install_element(VIEW_NODE, &show_ipv6_mroute_vrf_all_cmd);
2672
2673 install_element(VIEW_NODE, &show_evpn_global_cmd);
2674 install_element(VIEW_NODE, &show_evpn_vni_cmd);
2675 install_element(VIEW_NODE, &show_evpn_vni_vni_cmd);
2676 install_element(VIEW_NODE, &show_evpn_rmac_vni_mac_cmd);
2677 install_element(VIEW_NODE, &show_evpn_rmac_vni_cmd);
2678 install_element(VIEW_NODE, &show_evpn_rmac_vni_all_cmd);
2679 install_element(VIEW_NODE, &show_evpn_nh_vni_ip_cmd);
2680 install_element(VIEW_NODE, &show_evpn_nh_vni_cmd);
2681 install_element(VIEW_NODE, &show_evpn_nh_vni_all_cmd);
2682 install_element(VIEW_NODE, &show_evpn_mac_vni_cmd);
2683 install_element(VIEW_NODE, &show_evpn_mac_vni_all_cmd);
2684 install_element(VIEW_NODE, &show_evpn_mac_vni_all_vtep_cmd);
2685 install_element(VIEW_NODE, &show_evpn_mac_vni_mac_cmd);
2686 install_element(VIEW_NODE, &show_evpn_mac_vni_vtep_cmd);
2687 install_element(VIEW_NODE, &show_evpn_neigh_vni_cmd);
2688 install_element(VIEW_NODE, &show_evpn_neigh_vni_all_cmd);
2689 install_element(VIEW_NODE, &show_evpn_neigh_vni_neigh_cmd);
2690 install_element(VIEW_NODE, &show_evpn_neigh_vni_vtep_cmd);
2691
2692 install_element(VIEW_NODE, &show_pbr_ipset_cmd);
2693 install_element(VIEW_NODE, &show_pbr_iptable_cmd);
2694
2695 install_element(CONFIG_NODE, &default_vrf_vni_mapping_cmd);
2696 install_element(CONFIG_NODE, &no_default_vrf_vni_mapping_cmd);
2697 install_element(VRF_NODE, &vrf_vni_mapping_cmd);
2698 install_element(VRF_NODE, &no_vrf_vni_mapping_cmd);
2699
2700
2701 }