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