]> git.proxmox.com Git - mirror_frr.git/blame - zebra/zebra_vty.c
zebra: remove dead macro
[mirror_frr.git] / zebra / zebra_vty.c
CommitLineData
718e3744 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 *
896014f4
DL
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
718e3744 19 */
20
21#include <zebra.h>
22
7514fb77 23#include "memory.h"
4a1ab8e4 24#include "zebra_memory.h"
718e3744 25#include "if.h"
26#include "prefix.h"
27#include "command.h"
28#include "table.h"
29#include "rib.h"
fb018d25 30#include "nexthop.h"
b72ede27 31#include "vrf.h"
4060008b 32#include "linklist.h"
7758e3f3 33#include "mpls.h"
4a1ab8e4 34#include "routemap.h"
05737783 35#include "srcdest_table.h"
cec2e17d 36#include "vxlan.h"
718e3744 37
89272910 38#include "zebra/zebra_router.h"
a1ac18c4 39#include "zebra/zserv.h"
7c551956 40#include "zebra/zebra_vrf.h"
7758e3f3 41#include "zebra/zebra_mpls.h"
fb018d25 42#include "zebra/zebra_rnh.h"
7a4bb9c5 43#include "zebra/redistribute.h"
6baf7bb8 44#include "zebra/zebra_routemap.h"
1d666fcb 45#include "lib/json.h"
cec2e17d 46#include "zebra/zebra_vxlan.h"
ab59f4f7 47#ifndef VTYSH_EXTRACT_PL
00685a85 48#include "zebra/zebra_vty_clippy.c"
ab59f4f7 49#endif
3a30f50f 50#include "zebra/zserv.h"
c0d136ae
DS
51#include "zebra/router-id.h"
52#include "zebra/ipforward.h"
b7cfce93 53#include "zebra/zebra_vxlan_private.h"
586f4ccf 54#include "zebra/zebra_pbr.h"
6baf7bb8
DS
55
56extern int allow_delete;
a1ac18c4 57
d62a17ae 58static int do_show_ip_route(struct vty *vty, const char *vrf_name, afi_t afi,
9f049418 59 safi_t safi, bool use_fib, bool use_json,
ecffa493
RW
60 route_tag_t tag,
61 const struct prefix *longer_prefix_p,
d62a17ae 62 bool supernets_only, int type,
d7c0a89a 63 unsigned short ospf_instance_id);
d62a17ae 64static void vty_show_ip_route_detail(struct vty *vty, struct route_node *rn,
65 int mcast);
5ce91022
RW
66static void vty_show_ip_route_summary(struct vty *vty,
67 struct route_table *table);
68static void vty_show_ip_route_summary_prefix(struct vty *vty,
69 struct route_table *table);
b78a80d7 70
4623d897
DL
71DEFUN (ip_multicast_mode,
72 ip_multicast_mode_cmd,
6147e2c6 73 "ip multicast rpf-lookup-mode <urib-only|mrib-only|mrib-then-urib|lower-distance|longer-prefix>",
4623d897
DL
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{
d62a17ae 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 }
4623d897 99
d62a17ae 100 return CMD_SUCCESS;
4623d897
DL
101}
102
103DEFUN (no_ip_multicast_mode,
104 no_ip_multicast_mode_cmd,
b62ecea5 105 "no ip multicast rpf-lookup-mode [<urib-only|mrib-only|mrib-then-urib|lower-distance|longer-prefix>]",
4623d897
DL
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{
d62a17ae 116 multicast_mode_ipv4_set(MCAST_NO_CONFIG);
117 return CMD_SUCCESS;
4623d897
DL
118}
119
4623d897 120
b78a80d7
EM
121DEFUN (show_ip_rpf,
122 show_ip_rpf_cmd,
acb25e73 123 "show ip rpf [json]",
b78a80d7
EM
124 SHOW_STR
125 IP_STR
acb25e73
DW
126 "Display RPF information for multicast source\n"
127 JSON_STR)
b78a80d7 128{
9f049418 129 bool uj = use_json(argc, argv);
d62a17ae 130 return do_show_ip_route(vty, VRF_DEFAULT_NAME, AFI_IP, SAFI_MULTICAST,
fba31af2 131 false, uj, 0, NULL, false, 0, 0);
b78a80d7
EM
132}
133
65dd94cf
DL
134DEFUN (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{
d62a17ae 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
8f527c5e 164/* New RIB. Detailed information for IPv4 route. */
d62a17ae 165static 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
a2addae8 173 RNODE_FOREACH_RE (rn, re) {
d62a17ae 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);
0efb5e9b 190 if (re->tag) {
8526b842 191 vty_out(vty, ", tag %u", re->tag);
0efb5e9b
DS
192#if defined(SUPPORT_REALMS)
193 if (re->tag > 0 && re->tag <= 255)
194 vty_out(vty, "(realm)");
195#endif
196 }
d62a17ae 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");
d62a17ae 205 vty_out(vty, "\n");
206
14a481d9
DS
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)
996c9314
LB
217 vty_out(vty, "%02d:%02d:%02d", tm->tm_hour, tm->tm_min,
218 tm->tm_sec);
14a481d9 219 else if (uptime < ONE_WEEK_SECOND)
996c9314
LB
220 vty_out(vty, "%dd%02dh%02dm", tm->tm_yday, tm->tm_hour,
221 tm->tm_min);
14a481d9
DS
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");
d62a17ae 227
7ee30f28 228 for (ALL_NEXTHOPS(re->ng, nexthop)) {
d62a17ae 229 char addrstr[32];
230
231 vty_out(vty, " %c%s",
232 CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_FIB)
996c9314
LB
233 ? CHECK_FLAG(nexthop->flags,
234 NEXTHOP_FLAG_DUPLICATE)
235 ? ' '
236 : '*'
d62a17ae 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",
4a7371e9
DS
247 ifindex2ifname(
248 nexthop->ifindex,
249 nexthop->vrf_id));
d62a17ae 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",
4a7371e9
DS
258 ifindex2ifname(
259 nexthop->ifindex,
260 nexthop->vrf_id));
d62a17ae 261 break;
262 case NEXTHOP_TYPE_IFINDEX:
263 vty_out(vty, " directly connected, %s",
264 ifindex2ifname(nexthop->ifindex,
4a7371e9 265 nexthop->vrf_id));
d62a17ae 266 break;
267 case NEXTHOP_TYPE_BLACKHOLE:
a8309422
DL
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:
60466a63
QY
274 vty_out(vty,
275 " (ICMP admin-prohibited)");
a8309422
DL
276 break;
277 case BLACKHOLE_NULL:
278 vty_out(vty, " (blackhole)");
279 break;
280 case BLACKHOLE_UNSPEC:
281 break;
282 }
d62a17ae 283 break;
284 default:
285 break;
286 }
2793a098 287
fc132690 288 if ((re->vrf_id != nexthop->vrf_id)
bbde7a0f 289 && (nexthop->type != NEXTHOP_TYPE_BLACKHOLE)) {
2793a098 290 struct vrf *vrf =
4a7371e9 291 vrf_lookup_by_id(nexthop->vrf_id);
2793a098 292
4c66767c
DS
293 if (vrf)
294 vty_out(vty, "(vrf %s)", vrf->name);
295 else
0437e105 296 vty_out(vty, "(vrf UNKNOWN)");
2793a098
DS
297 }
298
eaf5150f
DS
299 if (CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_DUPLICATE))
300 vty_out(vty, " (duplicate nexthop removed)");
301
d62a17ae 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
1994ae60
JB
337 if (re->nexthop_mtu)
338 vty_out(vty, ", mtu %u", re->nexthop_mtu);
339
d62a17ae 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
356static 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;
14a481d9
DS
366 time_t uptime;
367 struct tm *tm;
368
369 uptime = time(NULL);
370 uptime -= re->uptime;
371 tm = gmtime(&uptime);
d62a17ae 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
925c2f88 392 if (re->type != ZEBRA_ROUTE_CONNECT) {
d62a17ae 393 json_object_int_add(json_route, "distance",
394 re->distance);
395 json_object_int_add(json_route, "metric", re->metric);
396 }
397
96d71e38
AD
398 if (re->tag)
399 json_object_int_add(json_route, "tag", re->tag);
400
f03098f9
DS
401 json_object_int_add(json_route, "internalStatus",
402 re->status);
403 json_object_int_add(json_route, "internalFlags",
404 re->flags);
14a481d9 405 if (uptime < ONE_DAY_SECOND)
996c9314
LB
406 sprintf(buf, "%02d:%02d:%02d", tm->tm_hour, tm->tm_min,
407 tm->tm_sec);
14a481d9 408 else if (uptime < ONE_WEEK_SECOND)
996c9314
LB
409 sprintf(buf, "%dd%02dh%02dm", tm->tm_yday, tm->tm_hour,
410 tm->tm_min);
14a481d9
DS
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);
d62a17ae 417
7ee30f28 418 for (ALL_NEXTHOPS(re->ng, nexthop)) {
d62a17ae 419 json_nexthop = json_object_new_object();
420
f03098f9
DS
421 json_object_int_add(json_nexthop, "flags",
422 nexthop->flags);
423
eaf5150f
DS
424 if (CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_DUPLICATE))
425 json_object_boolean_true_add(json_nexthop,
426 "duplicate");
427
d62a17ae 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",
4a7371e9
DS
447 ifindex2ifname(
448 nexthop->ifindex,
449 nexthop->vrf_id));
d62a17ae 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",
4a7371e9
DS
467 ifindex2ifname(
468 nexthop->ifindex,
469 nexthop->vrf_id));
d62a17ae 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,
4a7371e9 482 nexthop->vrf_id));
d62a17ae 483 break;
484 case NEXTHOP_TYPE_BLACKHOLE:
485 json_object_boolean_true_add(json_nexthop,
a8309422
DL
486 "unreachable");
487 switch (nexthop->bh_type) {
488 case BLACKHOLE_REJECT:
489 json_object_boolean_true_add(
60466a63 490 json_nexthop, "reject");
a8309422
DL
491 break;
492 case BLACKHOLE_ADMINPROHIB:
493 json_object_boolean_true_add(
60466a63
QY
494 json_nexthop,
495 "admin-prohibited");
a8309422
DL
496 break;
497 case BLACKHOLE_NULL:
498 json_object_boolean_true_add(
60466a63 499 json_nexthop, "blackhole");
a8309422
DL
500 break;
501 case BLACKHOLE_UNSPEC:
502 break;
503 }
d62a17ae 504 break;
505 default:
506 break;
507 }
508
fc132690 509 if ((nexthop->vrf_id != re->vrf_id)
bbde7a0f 510 && (nexthop->type != NEXTHOP_TYPE_BLACKHOLE)) {
2793a098 511 struct vrf *vrf =
4a7371e9 512 vrf_lookup_by_id(nexthop->vrf_id);
2793a098 513
996c9314 514 json_object_string_add(json_nexthop, "vrf",
2793a098
DS
515 vrf->name);
516 }
eaf5150f
DS
517 if (CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_DUPLICATE))
518 json_object_boolean_true_add(json_nexthop,
519 "duplicate");
520
d62a17ae 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. */
7ee30f28
DS
588 for (ALL_NEXTHOPS(re->ng, nexthop)) {
589 if (nexthop == re->ng.nexthop) {
d62a17ae 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. */
925c2f88 605 if (re->type != ZEBRA_ROUTE_CONNECT)
8526b842 606 len += vty_out(vty, " [%u/%u]", re->distance,
d62a17ae 607 re->metric);
eaf5150f 608 } else {
d62a17ae 609 vty_out(vty, " %c%*c",
610 CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_FIB)
996c9314
LB
611 ? CHECK_FLAG(nexthop->flags,
612 NEXTHOP_FLAG_DUPLICATE)
613 ? ' '
614 : '*'
d62a17ae 615 : ' ',
616 len - 3 + (2 * nexthop_level(nexthop)), ' ');
eaf5150f 617 }
d62a17ae 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,
4a7371e9 626 nexthop->vrf_id));
d62a17ae 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,
4a7371e9 636 nexthop->vrf_id));
d62a17ae 637 break;
638
639 case NEXTHOP_TYPE_IFINDEX:
640 vty_out(vty, " is directly connected, %s",
99b9d960 641 ifindex2ifname(nexthop->ifindex,
4a7371e9 642 nexthop->vrf_id));
d62a17ae 643 break;
644 case NEXTHOP_TYPE_BLACKHOLE:
a8309422
DL
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 }
d62a17ae 659 break;
660 default:
661 break;
662 }
2793a098 663
fc132690 664 if ((nexthop->vrf_id != re->vrf_id)
bbde7a0f 665 && (nexthop->type != NEXTHOP_TYPE_BLACKHOLE)) {
4a7371e9 666 struct vrf *vrf = vrf_lookup_by_id(nexthop->vrf_id);
2793a098 667
4c66767c
DS
668 if (vrf)
669 vty_out(vty, "(vrf %s)", vrf->name);
670 else
0437e105 671 vty_out(vty, "(vrf UNKNOWN)");
2793a098
DS
672 }
673
d62a17ae 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
14a481d9
DS
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);
d62a17ae 722 vty_out(vty, "\n");
723 }
724}
725
96d71e38
AD
726static 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();
9e7cd6fd 735 json_prefix = json_object_new_array();
96d71e38
AD
736
737 RNODE_FOREACH_RE (rn, re) {
96d71e38 738 vty_show_ip_route(vty, rn, re, json_prefix);
96d71e38
AD
739 }
740
9e7cd6fd
DS
741 prefix2str(&rn->p, buf, sizeof(buf));
742 json_object_object_add(json, buf, json_prefix);
96d71e38
AD
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
ae825b8b
DS
748static 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,
9f049418 753 unsigned short ospf_instance_id, bool use_json)
d62a17ae 754{
d62a17ae 755 struct route_node *rn;
756 struct route_entry *re;
757 int first = 1;
ae825b8b 758 rib_dest_t *dest;
d62a17ae 759 json_object *json = NULL;
760 json_object *json_prefix = NULL;
ae825b8b
DS
761 uint32_t addr;
762 char buf[BUFSIZ];
d62a17ae 763
764 if (use_json)
765 json = json_object_new_object();
766
767 /* Show all routes. */
c9591045 768 for (rn = route_top(table); rn; rn = srcdest_route_next(rn)) {
5f7a4718
DS
769 dest = rib_dest_from_rnode(rn);
770
a2addae8 771 RNODE_FOREACH_RE (rn, re) {
996c9314 772 if (use_fib && re != dest->selected_fib)
d62a17ae 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) {
96d71e38 828 prefix2str(&rn->p, buf, sizeof(buf));
d62a17ae 829 json_object_object_add(json, buf, json_prefix);
830 json_prefix = NULL;
831 }
832 }
833
834 if (use_json) {
96d71e38
AD
835 vty_out(vty, "%s\n", json_object_to_json_string_ext(json,
836 JSON_C_TO_STRING_PRETTY));
d62a17ae 837 json_object_free(json);
838 }
ae825b8b
DS
839}
840
841static int do_show_ip_route(struct vty *vty, const char *vrf_name, afi_t afi,
9f049418 842 safi_t safi, bool use_fib, bool use_json,
ae825b8b
DS
843 route_tag_t tag,
844 const struct prefix *longer_prefix_p,
845 bool supernets_only, int type,
d7c0a89a 846 unsigned short ospf_instance_id)
ae825b8b
DS
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
881DEFPY (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
89272910 896 t = zebra_router_find_table(zvrf, table, afi, SAFI_UNICAST);
ae825b8b
DS
897 if (t)
898 do_show_route_helper(vty, zvrf, t, afi, false, 0, false, false,
899 0, 0, !!json);
d62a17ae 900
901 return CMD_SUCCESS;
abbda2d4 902}
d511d7f1 903
87d6ac7a
PG
904DEFPY (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)
ec1db588 922 VRF_GET_ID(vrf_id, vrf_name, !!json);
87d6ac7a
PG
923 zvrf = zebra_vrf_lookup_by_id(vrf_id);
924
89272910 925 t = zebra_router_find_table(zvrf, table, afi, SAFI_UNICAST);
87d6ac7a
PG
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
8f527c5e
FL
933DEFUN (show_ip_nht,
934 show_ip_nht_cmd,
9bf96c84 935 "show ip nht [vrf NAME]",
8f527c5e
FL
936 SHOW_STR
937 IP_STR
9bf96c84
DW
938 "IP nexthop tracking table\n"
939 VRF_CMD_HELP_STR)
8f527c5e 940{
d62a17ae 941 int idx_vrf = 4;
942 vrf_id_t vrf_id = VRF_DEFAULT;
12f6fb97 943
d62a17ae 944 if (argc == 5)
ec1db588 945 VRF_GET_ID(vrf_id, argv[idx_vrf]->arg, false);
12f6fb97 946
73bf60a0 947 zebra_print_rnh_table(vrf_id, AFI_IP, vty, RNH_NEXTHOP_TYPE);
d62a17ae 948 return CMD_SUCCESS;
8f527c5e
FL
949}
950
b85c8275
PG
951DEFPY (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{
73bf60a0 961 afi_t afi = ipv4 ? AFI_IP : AFI_IP6;
b85c8275
PG
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));
73bf60a0 972 zebra_print_rnh_table(zvrf_id(zvrf), afi, vty,
6f95d11a 973 RNH_IMPORT_CHECK_TYPE);
b85c8275
PG
974 }
975 return CMD_SUCCESS;
976 }
977 if (vrf_name)
978 VRF_GET_ID(vrf_id, vrf_name, false);
979
73bf60a0 980 zebra_print_rnh_table(vrf_id, afi, vty, RNH_IMPORT_CHECK_TYPE);
b85c8275
PG
981 return CMD_SUCCESS;
982}
12f6fb97 983
d511d7f1
DS
984DEFUN (show_ip_nht_vrf_all,
985 show_ip_nht_vrf_all_cmd,
5bebf568 986 "show ip nht vrf all",
d511d7f1
DS
987 SHOW_STR
988 IP_STR
989 "IP nexthop tracking table\n"
990 VRF_ALL_CMD_HELP_STR)
991{
d62a17ae 992 struct vrf *vrf;
993 struct zebra_vrf *zvrf;
d511d7f1 994
a2addae8
RW
995 RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name)
996 if ((zvrf = vrf->info) != NULL) {
997 vty_out(vty, "\nVRF %s:\n", zvrf_name(zvrf));
73bf60a0 998 zebra_print_rnh_table(zvrf_id(zvrf), AFI_IP, vty,
a2addae8
RW
999 RNH_NEXTHOP_TYPE);
1000 }
d511d7f1 1001
d62a17ae 1002 return CMD_SUCCESS;
d511d7f1
DS
1003}
1004
8f527c5e
FL
1005DEFUN (show_ipv6_nht,
1006 show_ipv6_nht_cmd,
9bf96c84 1007 "show ipv6 nht [vrf NAME]",
8f527c5e 1008 SHOW_STR
689e6694 1009 IPV6_STR
9bf96c84
DW
1010 "IPv6 nexthop tracking table\n"
1011 VRF_CMD_HELP_STR)
8f527c5e 1012{
d62a17ae 1013 int idx_vrf = 4;
1014 vrf_id_t vrf_id = VRF_DEFAULT;
12f6fb97 1015
d62a17ae 1016 if (argc == 5)
ec1db588 1017 VRF_GET_ID(vrf_id, argv[idx_vrf]->arg, false);
12f6fb97 1018
73bf60a0 1019 zebra_print_rnh_table(vrf_id, AFI_IP6, vty, RNH_NEXTHOP_TYPE);
d62a17ae 1020 return CMD_SUCCESS;
8f527c5e
FL
1021}
1022
12f6fb97 1023
d511d7f1
DS
1024DEFUN (show_ipv6_nht_vrf_all,
1025 show_ipv6_nht_vrf_all_cmd,
5bebf568 1026 "show ipv6 nht vrf all",
d511d7f1
DS
1027 SHOW_STR
1028 IP_STR
1029 "IPv6 nexthop tracking table\n"
1030 VRF_ALL_CMD_HELP_STR)
1031{
d62a17ae 1032 struct vrf *vrf;
1033 struct zebra_vrf *zvrf;
d511d7f1 1034
a2addae8
RW
1035 RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name)
1036 if ((zvrf = vrf->info) != NULL) {
1037 vty_out(vty, "\nVRF %s:\n", zvrf_name(zvrf));
73bf60a0 1038 zebra_print_rnh_table(zvrf_id(zvrf), AFI_IP6, vty,
a2addae8
RW
1039 RNH_NEXTHOP_TYPE);
1040 }
d511d7f1 1041
d62a17ae 1042 return CMD_SUCCESS;
d511d7f1
DS
1043}
1044
8f527c5e
FL
1045DEFUN (ip_nht_default_route,
1046 ip_nht_default_route_cmd,
1047 "ip nht resolve-via-default",
1048 IP_STR
1049 "Filter Next Hop tracking route resolution\n"
1050 "Resolve via default route\n")
1051{
214e5c26 1052 ZEBRA_DECLVAR_CONTEXT(vrf, zvrf);
6d53d7b1 1053
1054 if (!zvrf)
1055 return CMD_WARNING;
1056
214e5c26 1057 if (zebra_rnh_ip_default_route)
1058 return CMD_SUCCESS;
1059
d62a17ae 1060 zebra_rnh_ip_default_route = 1;
214e5c26 1061
73bf60a0 1062 zebra_evaluate_rnh(zvrf, AFI_IP, 1, RNH_NEXTHOP_TYPE, NULL);
d62a17ae 1063 return CMD_SUCCESS;
8f527c5e
FL
1064}
1065
1066DEFUN (no_ip_nht_default_route,
1067 no_ip_nht_default_route_cmd,
1068 "no ip nht resolve-via-default",
1069 NO_STR
1070 IP_STR
1071 "Filter Next Hop tracking route resolution\n"
1072 "Resolve via default route\n")
1073{
214e5c26 1074 ZEBRA_DECLVAR_CONTEXT(vrf, zvrf);
6d53d7b1 1075
1076 if (!zvrf)
1077 return CMD_WARNING;
1078
214e5c26 1079 if (!zebra_rnh_ip_default_route)
1080 return CMD_SUCCESS;
1081
d62a17ae 1082 zebra_rnh_ip_default_route = 0;
73bf60a0 1083 zebra_evaluate_rnh(zvrf, AFI_IP, 1, RNH_NEXTHOP_TYPE, NULL);
d62a17ae 1084 return CMD_SUCCESS;
8f527c5e
FL
1085}
1086
1087DEFUN (ipv6_nht_default_route,
1088 ipv6_nht_default_route_cmd,
1089 "ipv6 nht resolve-via-default",
1090 IP6_STR
1091 "Filter Next Hop tracking route resolution\n"
1092 "Resolve via default route\n")
1093{
214e5c26 1094 ZEBRA_DECLVAR_CONTEXT(vrf, zvrf);
6d53d7b1 1095
1096 if (!zvrf)
1097 return CMD_WARNING;
1098
214e5c26 1099 if (zebra_rnh_ipv6_default_route)
1100 return CMD_SUCCESS;
1101
d62a17ae 1102 zebra_rnh_ipv6_default_route = 1;
73bf60a0 1103 zebra_evaluate_rnh(zvrf, AFI_IP6, 1, RNH_NEXTHOP_TYPE, NULL);
d62a17ae 1104 return CMD_SUCCESS;
8f527c5e
FL
1105}
1106
1107DEFUN (no_ipv6_nht_default_route,
1108 no_ipv6_nht_default_route_cmd,
1109 "no ipv6 nht resolve-via-default",
1110 NO_STR
1111 IP6_STR
1112 "Filter Next Hop tracking route resolution\n"
1113 "Resolve via default route\n")
1114{
8f527c5e 1115
214e5c26 1116 ZEBRA_DECLVAR_CONTEXT(vrf, zvrf);
6d53d7b1 1117
1118 if (!zvrf)
1119 return CMD_WARNING;
1120
214e5c26 1121 if (!zebra_rnh_ipv6_default_route)
1122 return CMD_SUCCESS;
1123
d62a17ae 1124 zebra_rnh_ipv6_default_route = 0;
73bf60a0 1125 zebra_evaluate_rnh(zvrf, AFI_IP6, 1, RNH_NEXTHOP_TYPE, NULL);
d62a17ae 1126 return CMD_SUCCESS;
8f527c5e
FL
1127}
1128
ecffa493
RW
1129DEFPY (show_route,
1130 show_route_cmd,
1131 "show\
1132 <\
1133 ip$ipv4 <fib$fib|route> [vrf <NAME$vrf_name|all$vrf_all>]\
a3e13ef3 1134 [{\
ecffa493
RW
1135 tag (1-4294967295)\
1136 |A.B.C.D/M$prefix longer-prefixes\
1137 |supernets-only$supernets_only\
a3e13ef3
RW
1138 }]\
1139 [<\
1140 " FRR_IP_REDIST_STR_ZEBRA "$type_str\
ecffa493 1141 |ospf$type_str (1-65535)$ospf_instance_id\
a3e13ef3 1142 >]\
ecffa493 1143 |ipv6$ipv6 <fib$fib|route> [vrf <NAME$vrf_name|all$vrf_all>]\
a3e13ef3 1144 [{\
ecffa493
RW
1145 tag (1-4294967295)\
1146 |X:X::X:X/M$prefix longer-prefixes\
a3e13ef3
RW
1147 }]\
1148 [" FRR_IP6_REDIST_STR_ZEBRA "$type_str]\
ecffa493
RW
1149 >\
1150 [json$json]",
8f527c5e
FL
1151 SHOW_STR
1152 IP_STR
87a88962 1153 "IP forwarding table\n"
8f527c5e 1154 "IP routing table\n"
ecffa493 1155 VRF_FULL_CMD_HELP_STR
8f527c5e 1156 "Show only routes with tag\n"
acb25e73
DW
1157 "Tag value\n"
1158 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
1159 "Show route matching the specified Network/Mask pair only\n"
1160 "Show supernet entries only\n"
1161 FRR_IP_REDIST_HELP_STR_ZEBRA
1162 "Open Shortest Path First (OSPFv2)\n"
1163 "Instance ID\n"
ecffa493
RW
1164 IPV6_STR
1165 "IP forwarding table\n"
1166 "IP routing table\n"
1167 VRF_FULL_CMD_HELP_STR
1168 "Show only routes with tag\n"
1169 "Tag value\n"
1170 "IPv6 prefix\n"
1171 "Show route matching the specified Network/Mask pair only\n"
1172 FRR_IP6_REDIST_HELP_STR_ZEBRA
acb25e73 1173 JSON_STR)
8f527c5e 1174{
ecffa493 1175 afi_t afi = ipv4 ? AFI_IP : AFI_IP6;
d62a17ae 1176 struct vrf *vrf;
d62a17ae 1177 int type = 0;
d62a17ae 1178
ecffa493
RW
1179 if (type_str) {
1180 type = proto_redistnum(afi, type_str);
d62a17ae 1181 if (type < 0) {
1182 vty_out(vty, "Unknown route type\n");
1183 return CMD_WARNING;
1184 }
1185 }
1186
1187 if (vrf_all) {
a2addae8 1188 RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) {
ecffa493
RW
1189 struct zebra_vrf *zvrf;
1190 struct route_table *table;
1191
d62a17ae 1192 if ((zvrf = vrf->info) == NULL
ecffa493 1193 || (table = zvrf->table[afi][SAFI_UNICAST]) == NULL)
d62a17ae 1194 continue;
1195
1196 do_show_ip_route(
ecffa493
RW
1197 vty, zvrf_name(zvrf), afi, SAFI_UNICAST, !!fib,
1198 !!json, tag, prefix_str ? prefix : NULL,
1199 !!supernets_only, type, ospf_instance_id);
d62a17ae 1200 }
1201 } else {
ecffa493
RW
1202 vrf_id_t vrf_id = VRF_DEFAULT;
1203
1204 if (vrf_name)
ec1db588 1205 VRF_GET_ID(vrf_id, vrf_name, !!json);
d62a17ae 1206 vrf = vrf_lookup_by_id(vrf_id);
ecffa493
RW
1207 do_show_ip_route(vty, vrf->name, afi, SAFI_UNICAST, !!fib,
1208 !!json, tag, prefix_str ? prefix : NULL,
1209 !!supernets_only, type, ospf_instance_id);
d62a17ae 1210 }
ecffa493 1211
d62a17ae 1212 return CMD_SUCCESS;
8f527c5e
FL
1213}
1214
5ce91022
RW
1215DEFPY (show_route_detail,
1216 show_route_detail_cmd,
1217 "show\
1218 <\
1219 ip$ipv4 route [vrf <NAME$vrf_name|all$vrf_all>]\
1220 <\
1221 A.B.C.D$address\
1222 |A.B.C.D/M$prefix\
1223 >\
1224 |ipv6$ipv6 route [vrf <NAME$vrf_name|all$vrf_all>]\
1225 <\
1226 X:X::X:X$address\
1227 |X:X::X:X/M$prefix\
1228 >\
96d71e38
AD
1229 >\
1230 [json$json]",
8f527c5e
FL
1231 SHOW_STR
1232 IP_STR
1233 "IP routing table\n"
5ce91022
RW
1234 VRF_FULL_CMD_HELP_STR
1235 "Network in the IP routing table to display\n"
1236 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
1237 IP6_STR
1238 "IP routing table\n"
1239 VRF_FULL_CMD_HELP_STR
1240 "IPv6 Address\n"
96d71e38
AD
1241 "IPv6 prefix\n"
1242 JSON_STR)
8f527c5e 1243{
5ce91022 1244 afi_t afi = ipv4 ? AFI_IP : AFI_IP6;
d62a17ae 1245 struct route_table *table;
5ce91022 1246 struct prefix p;
d62a17ae 1247 struct route_node *rn;
d511d7f1 1248
5ce91022
RW
1249 if (address_str)
1250 prefix_str = address_str;
1251 if (str2prefix(prefix_str, &p) < 0) {
1252 vty_out(vty, "%% Malformed address\n");
d62a17ae 1253 return CMD_WARNING;
1254 }
8f527c5e 1255
5ce91022
RW
1256 if (vrf_all) {
1257 struct vrf *vrf;
1258 struct zebra_vrf *zvrf;
8f527c5e 1259
996c9314 1260 RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) {
5ce91022
RW
1261 if ((zvrf = vrf->info) == NULL
1262 || (table = zvrf->table[afi][SAFI_UNICAST]) == NULL)
1263 continue;
1264
1265 rn = route_node_match(table, &p);
1266 if (!rn)
1267 continue;
1268 if (!address_str && rn->p.prefixlen != p.prefixlen) {
1269 route_unlock_node(rn);
1270 continue;
1271 }
1272
96d71e38
AD
1273 if (json)
1274 vty_show_ip_route_detail_json(vty, rn);
1275 else
1276 vty_show_ip_route_detail(vty, rn, 0);
5ce91022
RW
1277
1278 route_unlock_node(rn);
1279 }
1280 } else {
1281 vrf_id_t vrf_id = VRF_DEFAULT;
1282
1283 if (vrf_name)
ec1db588 1284 VRF_GET_ID(vrf_id, vrf_name, false);
5ce91022
RW
1285
1286 table = zebra_vrf_table(afi, SAFI_UNICAST, vrf_id);
1287 if (!table)
1288 return CMD_SUCCESS;
8f527c5e 1289
5ce91022
RW
1290 rn = route_node_match(table, &p);
1291 if (!rn) {
1292 vty_out(vty, "%% Network not in table\n");
1293 return CMD_WARNING;
1294 }
1295 if (!address_str && rn->p.prefixlen != p.prefixlen) {
1296 vty_out(vty, "%% Network not in table\n");
1297 route_unlock_node(rn);
1298 return CMD_WARNING;
1299 }
8f527c5e 1300
96d71e38
AD
1301 if (json)
1302 vty_show_ip_route_detail_json(vty, rn);
1303 else
1304 vty_show_ip_route_detail(vty, rn, 0);
5ce91022
RW
1305
1306 route_unlock_node(rn);
1307 }
8f527c5e 1308
d62a17ae 1309 return CMD_SUCCESS;
8f527c5e
FL
1310}
1311
5ce91022
RW
1312DEFPY (show_route_summary,
1313 show_route_summary_cmd,
1314 "show\
1315 <\
1316 ip$ipv4 route [vrf <NAME$vrf_name|all$vrf_all>]\
1317 summary [prefix$prefix]\
1318 |ipv6$ipv6 route [vrf <NAME$vrf_name|all$vrf_all>]\
1319 summary [prefix$prefix]\
1320 >",
8f527c5e
FL
1321 SHOW_STR
1322 IP_STR
1323 "IP routing table\n"
5ce91022
RW
1324 VRF_FULL_CMD_HELP_STR
1325 "Summary of all routes\n"
1326 "Prefix routes\n"
1327 IP6_STR
1328 "IP routing table\n"
1329 VRF_FULL_CMD_HELP_STR
1330 "Summary of all routes\n"
1331 "Prefix routes\n")
8f527c5e 1332{
5ce91022 1333 afi_t afi = ipv4 ? AFI_IP : AFI_IP6;
d62a17ae 1334 struct route_table *table;
d62a17ae 1335
5ce91022
RW
1336 if (vrf_all) {
1337 struct vrf *vrf;
1338 struct zebra_vrf *zvrf;
d511d7f1 1339
996c9314 1340 RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) {
5ce91022
RW
1341 if ((zvrf = vrf->info) == NULL
1342 || (table = zvrf->table[afi][SAFI_UNICAST]) == NULL)
1343 continue;
8f527c5e 1344
5ce91022
RW
1345 if (prefix)
1346 vty_show_ip_route_summary_prefix(vty, table);
1347 else
1348 vty_show_ip_route_summary(vty, table);
1349 }
1350 } else {
1351 vrf_id_t vrf_id = VRF_DEFAULT;
8f527c5e 1352
5ce91022 1353 if (vrf_name)
ec1db588 1354 VRF_GET_ID(vrf_id, vrf_name, false);
8f527c5e 1355
5ce91022
RW
1356 table = zebra_vrf_table(afi, SAFI_UNICAST, vrf_id);
1357 if (!table)
1358 return CMD_SUCCESS;
8f527c5e 1359
5ce91022
RW
1360 if (prefix)
1361 vty_show_ip_route_summary_prefix(vty, table);
1362 else
1363 vty_show_ip_route_summary(vty, table);
1364 }
8f527c5e 1365
d62a17ae 1366 return CMD_SUCCESS;
8f527c5e
FL
1367}
1368
d62a17ae 1369static void vty_show_ip_route_summary(struct vty *vty,
1370 struct route_table *table)
8f527c5e 1371{
d62a17ae 1372 struct route_node *rn;
1373 struct route_entry *re;
8f527c5e
FL
1374#define ZEBRA_ROUTE_IBGP ZEBRA_ROUTE_MAX
1375#define ZEBRA_ROUTE_TOTAL (ZEBRA_ROUTE_IBGP + 1)
d7c0a89a
QY
1376 uint32_t rib_cnt[ZEBRA_ROUTE_TOTAL + 1];
1377 uint32_t fib_cnt[ZEBRA_ROUTE_TOTAL + 1];
1378 uint32_t i;
1379 uint32_t is_ibgp;
d62a17ae 1380
1381 memset(&rib_cnt, 0, sizeof(rib_cnt));
1382 memset(&fib_cnt, 0, sizeof(fib_cnt));
1383 for (rn = route_top(table); rn; rn = srcdest_route_next(rn))
a2addae8 1384 RNODE_FOREACH_RE (rn, re) {
d62a17ae 1385 is_ibgp = (re->type == ZEBRA_ROUTE_BGP
1386 && CHECK_FLAG(re->flags, ZEBRA_FLAG_IBGP));
1387
1388 rib_cnt[ZEBRA_ROUTE_TOTAL]++;
1389 if (is_ibgp)
1390 rib_cnt[ZEBRA_ROUTE_IBGP]++;
1391 else
1392 rib_cnt[re->type]++;
1393
1394 if (CHECK_FLAG(re->flags, ZEBRA_FLAG_SELECTED)) {
1395 fib_cnt[ZEBRA_ROUTE_TOTAL]++;
1396
1397 if (is_ibgp)
1398 fib_cnt[ZEBRA_ROUTE_IBGP]++;
1399 else
1400 fib_cnt[re->type]++;
1401 }
1402 }
1403
1404 vty_out(vty, "%-20s %-20s %s (vrf %s)\n", "Route Source", "Routes",
6ca30e9e 1405 "FIB", zvrf_name(((rib_table_info_t *)route_table_get_info(table))->zvrf));
d62a17ae 1406
1407 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
9d303b37
DL
1408 if ((rib_cnt[i] > 0) || (i == ZEBRA_ROUTE_BGP
1409 && rib_cnt[ZEBRA_ROUTE_IBGP] > 0)) {
d62a17ae 1410 if (i == ZEBRA_ROUTE_BGP) {
1411 vty_out(vty, "%-20s %-20d %-20d \n", "ebgp",
1412 rib_cnt[ZEBRA_ROUTE_BGP],
1413 fib_cnt[ZEBRA_ROUTE_BGP]);
1414 vty_out(vty, "%-20s %-20d %-20d \n", "ibgp",
1415 rib_cnt[ZEBRA_ROUTE_IBGP],
1416 fib_cnt[ZEBRA_ROUTE_IBGP]);
1417 } else
1418 vty_out(vty, "%-20s %-20d %-20d \n",
1419 zebra_route_string(i), rib_cnt[i],
1420 fib_cnt[i]);
1421 }
1422 }
1423
1424 vty_out(vty, "------\n");
1425 vty_out(vty, "%-20s %-20d %-20d \n", "Totals",
1426 rib_cnt[ZEBRA_ROUTE_TOTAL], fib_cnt[ZEBRA_ROUTE_TOTAL]);
1427 vty_out(vty, "\n");
8f527c5e
FL
1428}
1429
1430/*
1431 * Implementation of the ip route summary prefix command.
1432 *
1433 * This command prints the primary prefixes that have been installed by various
1434 * protocols on the box.
1435 *
1436 */
d62a17ae 1437static void vty_show_ip_route_summary_prefix(struct vty *vty,
1438 struct route_table *table)
8f527c5e 1439{
d62a17ae 1440 struct route_node *rn;
1441 struct route_entry *re;
1442 struct nexthop *nexthop;
8f527c5e
FL
1443#define ZEBRA_ROUTE_IBGP ZEBRA_ROUTE_MAX
1444#define ZEBRA_ROUTE_TOTAL (ZEBRA_ROUTE_IBGP + 1)
d7c0a89a
QY
1445 uint32_t rib_cnt[ZEBRA_ROUTE_TOTAL + 1];
1446 uint32_t fib_cnt[ZEBRA_ROUTE_TOTAL + 1];
1447 uint32_t i;
d62a17ae 1448 int cnt;
1449
1450 memset(&rib_cnt, 0, sizeof(rib_cnt));
1451 memset(&fib_cnt, 0, sizeof(fib_cnt));
1452 for (rn = route_top(table); rn; rn = srcdest_route_next(rn))
a2addae8 1453 RNODE_FOREACH_RE (rn, re) {
d62a17ae 1454
1455 /*
1456 * In case of ECMP, count only once.
1457 */
1458 cnt = 0;
7ee30f28 1459 for (nexthop = re->ng.nexthop; (!cnt && nexthop);
d62a17ae 1460 nexthop = nexthop->next) {
1461 cnt++;
1462 rib_cnt[ZEBRA_ROUTE_TOTAL]++;
1463 rib_cnt[re->type]++;
1464 if (CHECK_FLAG(nexthop->flags,
1465 NEXTHOP_FLAG_FIB)) {
1466 fib_cnt[ZEBRA_ROUTE_TOTAL]++;
1467 fib_cnt[re->type]++;
1468 }
1469 if (re->type == ZEBRA_ROUTE_BGP
1470 && CHECK_FLAG(re->flags, ZEBRA_FLAG_IBGP)) {
1471 rib_cnt[ZEBRA_ROUTE_IBGP]++;
1472 if (CHECK_FLAG(nexthop->flags,
1473 NEXTHOP_FLAG_FIB))
1474 fib_cnt[ZEBRA_ROUTE_IBGP]++;
1475 }
1476 }
1477 }
1478
1479 vty_out(vty, "%-20s %-20s %s (vrf %s)\n", "Route Source",
1480 "Prefix Routes", "FIB",
6ca30e9e 1481 zvrf_name(((rib_table_info_t *)route_table_get_info(table))->zvrf));
d62a17ae 1482
1483 for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
1484 if (rib_cnt[i] > 0) {
1485 if (i == ZEBRA_ROUTE_BGP) {
1486 vty_out(vty, "%-20s %-20d %-20d \n", "ebgp",
1487 rib_cnt[ZEBRA_ROUTE_BGP]
1488 - rib_cnt[ZEBRA_ROUTE_IBGP],
1489 fib_cnt[ZEBRA_ROUTE_BGP]
1490 - fib_cnt[ZEBRA_ROUTE_IBGP]);
1491 vty_out(vty, "%-20s %-20d %-20d \n", "ibgp",
1492 rib_cnt[ZEBRA_ROUTE_IBGP],
1493 fib_cnt[ZEBRA_ROUTE_IBGP]);
1494 } else
1495 vty_out(vty, "%-20s %-20d %-20d \n",
1496 zebra_route_string(i), rib_cnt[i],
1497 fib_cnt[i]);
1498 }
1499 }
1500
1501 vty_out(vty, "------\n");
1502 vty_out(vty, "%-20s %-20d %-20d \n", "Totals",
1503 rib_cnt[ZEBRA_ROUTE_TOTAL], fib_cnt[ZEBRA_ROUTE_TOTAL]);
1504 vty_out(vty, "\n");
9343ce83
DS
1505}
1506
cddf391b
B
1507/*
1508 * Show IPv6 mroute command.Used to dump
1509 * the Multicast routing table.
1510 */
cddf391b
B
1511DEFUN (show_ipv6_mroute,
1512 show_ipv6_mroute_cmd,
9bf96c84 1513 "show ipv6 mroute [vrf NAME]",
cddf391b
B
1514 SHOW_STR
1515 IP_STR
9bf96c84
DW
1516 "IPv6 Multicast routing table\n"
1517 VRF_CMD_HELP_STR)
cddf391b 1518{
d62a17ae 1519 struct route_table *table;
1520 struct route_node *rn;
1521 struct route_entry *re;
1522 int first = 1;
1523 vrf_id_t vrf_id = VRF_DEFAULT;
1524
1525 if (argc == 5)
ec1db588 1526 VRF_GET_ID(vrf_id, argv[4]->arg, false);
d62a17ae 1527
1528 table = zebra_vrf_table(AFI_IP6, SAFI_MULTICAST, vrf_id);
1529 if (!table)
1530 return CMD_SUCCESS;
1531
1532 /* Show all IPv6 route. */
1533 for (rn = route_top(table); rn; rn = srcdest_route_next(rn))
a2addae8 1534 RNODE_FOREACH_RE (rn, re) {
d62a17ae 1535 if (first) {
1536 vty_out(vty, SHOW_ROUTE_V6_HEADER);
1537 first = 0;
1538 }
1539 vty_show_ip_route(vty, rn, re, NULL);
1540 }
1541 return CMD_SUCCESS;
cddf391b
B
1542}
1543
af41b63a
FL
1544DEFUN (show_ipv6_mroute_vrf_all,
1545 show_ipv6_mroute_vrf_all_cmd,
5bebf568 1546 "show ipv6 mroute vrf all",
af41b63a
FL
1547 SHOW_STR
1548 IP_STR
1549 "IPv6 Multicast routing table\n"
1550 VRF_ALL_CMD_HELP_STR)
1551{
d62a17ae 1552 struct route_table *table;
1553 struct route_node *rn;
1554 struct route_entry *re;
1555 struct vrf *vrf;
1556 struct zebra_vrf *zvrf;
1557 int first = 1;
1558
a2addae8 1559 RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) {
d62a17ae 1560 if ((zvrf = vrf->info) == NULL
1561 || (table = zvrf->table[AFI_IP6][SAFI_MULTICAST]) == NULL)
1562 continue;
1563
1564 /* Show all IPv6 route. */
1565 for (rn = route_top(table); rn; rn = srcdest_route_next(rn))
a2addae8 1566 RNODE_FOREACH_RE (rn, re) {
d62a17ae 1567 if (first) {
1568 vty_out(vty, SHOW_ROUTE_V6_HEADER);
1569 first = 0;
1570 }
1571 vty_show_ip_route(vty, rn, re, NULL);
1572 }
1573 }
1574 return CMD_SUCCESS;
af41b63a
FL
1575}
1576
6baf7bb8
DS
1577DEFUN (allow_external_route_update,
1578 allow_external_route_update_cmd,
1579 "allow-external-route-update",
17d990c1 1580 "Allow FRR routes to be overwritten by external processes\n")
6baf7bb8 1581{
d62a17ae 1582 allow_delete = 1;
6baf7bb8 1583
d62a17ae 1584 return CMD_SUCCESS;
6baf7bb8
DS
1585}
1586
1587DEFUN (no_allow_external_route_update,
1588 no_allow_external_route_update_cmd,
1589 "no allow-external-route-update",
17d990c1
DS
1590 NO_STR
1591 "Allow FRR routes to be overwritten by external processes\n")
6baf7bb8 1592{
d62a17ae 1593 allow_delete = 0;
6baf7bb8 1594
d62a17ae 1595 return CMD_SUCCESS;
6baf7bb8
DS
1596}
1597
12f6fb97
DS
1598/* show vrf */
1599DEFUN (show_vrf,
1600 show_vrf_cmd,
1601 "show vrf",
1602 SHOW_STR
1603 "VRF\n")
1604{
d62a17ae 1605 struct vrf *vrf;
1606 struct zebra_vrf *zvrf;
12f6fb97 1607
b73823ef
PG
1608 if (vrf_is_backend_netns())
1609 vty_out(vty, "netns-based vrfs\n");
1610
a2addae8 1611 RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) {
d62a17ae 1612 if (!(zvrf = vrf->info))
1613 continue;
90ac32c2 1614 if (zvrf_id(zvrf) == VRF_DEFAULT)
d62a17ae 1615 continue;
1616
1617 vty_out(vty, "vrf %s ", zvrf_name(zvrf));
996c9314 1618 if (zvrf_id(zvrf) == VRF_UNKNOWN || !zvrf_is_active(zvrf))
d62a17ae 1619 vty_out(vty, "inactive");
81c9005f 1620 else if (zvrf_ns_name(zvrf))
996c9314
LB
1621 vty_out(vty, "id %u netns %s", zvrf_id(zvrf),
1622 zvrf_ns_name(zvrf));
d62a17ae 1623 else
1624 vty_out(vty, "id %u table %u", zvrf_id(zvrf),
1625 zvrf->table_id);
22bd3e94 1626 if (vrf_is_user_cfged(vrf))
1627 vty_out(vty, " (configured)");
d62a17ae 1628 vty_out(vty, "\n");
1629 }
12f6fb97 1630
d62a17ae 1631 return CMD_SUCCESS;
12f6fb97
DS
1632}
1633
62710e2b 1634DEFUN_HIDDEN (default_vrf_vni_mapping,
e8d26197 1635 default_vrf_vni_mapping_cmd,
c48d9f5f 1636 "vni " CMD_VNI_RANGE "[prefix-routes-only]",
e8d26197 1637 "VNI corresponding to the DEFAULT VRF\n"
c48d9f5f
MK
1638 "VNI-ID\n"
1639 "Prefix routes only \n")
e8d26197
MK
1640{
1641 int ret = 0;
1642 char err[ERR_STR_SZ];
1643 struct zebra_vrf *zvrf = NULL;
1644 vni_t vni = strtoul(argv[1]->arg, NULL, 10);
c48d9f5f 1645 int filter = 0;
e8d26197
MK
1646
1647 zvrf = vrf_info_lookup(VRF_DEFAULT);
1648 if (!zvrf)
1649 return CMD_WARNING;
1650
c48d9f5f
MK
1651 if (argc == 3)
1652 filter = 1;
1653
1654 ret = zebra_vxlan_process_vrf_vni_cmd(zvrf, vni, err, ERR_STR_SZ,
1655 filter, 1);
e8d26197
MK
1656 if (ret != 0) {
1657 vty_out(vty, "%s\n", err);
1658 return CMD_WARNING;
1659 }
1660
1661 return CMD_SUCCESS;
1662}
1663
62710e2b 1664DEFUN_HIDDEN (no_default_vrf_vni_mapping,
e8d26197
MK
1665 no_default_vrf_vni_mapping_cmd,
1666 "no vni " CMD_VNI_RANGE,
1667 NO_STR
1668 "VNI corresponding to DEFAULT VRF\n"
1669 "VNI-ID")
1670{
1671 int ret = 0;
1672 char err[ERR_STR_SZ];
1673 vni_t vni = strtoul(argv[2]->arg, NULL, 10);
1674 struct zebra_vrf *zvrf = NULL;
1675
1676 zvrf = vrf_info_lookup(VRF_DEFAULT);
1677 if (!zvrf)
1678 return CMD_WARNING;
1679
c48d9f5f 1680 ret = zebra_vxlan_process_vrf_vni_cmd(zvrf, vni, err, ERR_STR_SZ, 0, 0);
e8d26197
MK
1681 if (ret != 0) {
1682 vty_out(vty, "%s\n", err);
1683 return CMD_WARNING;
1684 }
1685
1686 return CMD_SUCCESS;
1687}
1688
b7cfce93
MK
1689DEFUN (vrf_vni_mapping,
1690 vrf_vni_mapping_cmd,
c48d9f5f 1691 "vni " CMD_VNI_RANGE "[prefix-routes-only]",
e8d26197 1692 "VNI corresponding to tenant VRF\n"
c48d9f5f
MK
1693 "VNI-ID\n"
1694 "prefix-routes-only\n")
b7cfce93
MK
1695{
1696 int ret = 0;
c48d9f5f 1697 int filter = 0;
b7cfce93
MK
1698
1699 ZEBRA_DECLVAR_CONTEXT(vrf, zvrf);
1700 vni_t vni = strtoul(argv[1]->arg, NULL, 10);
1701 char err[ERR_STR_SZ];
1702
1703 assert(vrf);
1704 assert(zvrf);
1705
c48d9f5f
MK
1706 if (argc == 3)
1707 filter = 1;
1708
317f1fe0 1709 /* Mark as having FRR configuration */
1710 vrf_set_user_cfged(vrf);
c48d9f5f
MK
1711 ret = zebra_vxlan_process_vrf_vni_cmd(zvrf, vni, err, ERR_STR_SZ,
1712 filter, 1);
b7cfce93
MK
1713 if (ret != 0) {
1714 vty_out(vty, "%s\n", err);
1715 return CMD_WARNING;
1716 }
1717
1718 return CMD_SUCCESS;
1719}
1720
1721DEFUN (no_vrf_vni_mapping,
1722 no_vrf_vni_mapping_cmd,
cf299714 1723 "no vni " CMD_VNI_RANGE "[prefix-routes-only]",
b7cfce93 1724 NO_STR
e8d26197 1725 "VNI corresponding to tenant VRF\n"
cf299714
MK
1726 "VNI-ID\n"
1727 "prefix-routes-only\n")
b7cfce93
MK
1728{
1729 int ret = 0;
cf299714 1730 int filter = 0;
b7cfce93
MK
1731 char err[ERR_STR_SZ];
1732 vni_t vni = strtoul(argv[2]->arg, NULL, 10);
1733
1734 ZEBRA_DECLVAR_CONTEXT(vrf, zvrf);
1735
1736 assert(vrf);
1737 assert(zvrf);
1738
cf299714
MK
1739 if (argc == 4)
1740 filter = 1;
1741
1742 ret = zebra_vxlan_process_vrf_vni_cmd(zvrf, vni, err,
1743 ERR_STR_SZ, filter, 0);
b7cfce93
MK
1744 if (ret != 0) {
1745 vty_out(vty, "%s\n", err);
1746 return CMD_WARNING;
1747 }
1748
22bd3e94 1749 /* If no other FRR config for this VRF, mark accordingly. */
1750 if (!zebra_vrf_has_config(zvrf))
1751 vrf_reset_user_cfged(vrf);
1752
b7cfce93
MK
1753 return CMD_SUCCESS;
1754}
1755
1756/* show vrf */
1757DEFUN (show_vrf_vni,
1758 show_vrf_vni_cmd,
35be5542 1759 "show vrf vni [json]",
b7cfce93
MK
1760 SHOW_STR
1761 "VRF\n"
35be5542
MK
1762 "VNI\n"
1763 JSON_STR)
b7cfce93
MK
1764{
1765 struct vrf *vrf;
1766 struct zebra_vrf *zvrf;
35be5542
MK
1767 json_object *json = NULL;
1768 json_object *json_vrfs = NULL;
9f049418 1769 bool uj = use_json(argc, argv);
35be5542
MK
1770
1771 if (uj) {
1772 json = json_object_new_object();
1773 json_vrfs = json_object_new_array();
1774 }
b7cfce93 1775
4cce389e 1776 if (!uj)
996c9314
LB
1777 vty_out(vty, "%-37s %-10s %-20s %-20s %-5s %-18s\n", "VRF",
1778 "VNI", "VxLAN IF", "L3-SVI", "State", "Rmac");
4cce389e 1779
996c9314 1780 RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) {
b7cfce93
MK
1781 zvrf = vrf->info;
1782 if (!zvrf)
1783 continue;
1784
4cce389e 1785 zebra_vxlan_print_vrf_vni(vty, zvrf, json_vrfs);
35be5542
MK
1786 }
1787
1788 if (uj) {
1789 json_object_object_add(json, "vrfs", json_vrfs);
1790 vty_out(vty, "%s\n", json_object_to_json_string_ext(
1791 json, JSON_C_TO_STRING_PRETTY));
1792 json_object_free(json);
b7cfce93
MK
1793 }
1794
1795 return CMD_SUCCESS;
1796}
1797
4cce389e
MK
1798DEFUN (show_evpn_global,
1799 show_evpn_global_cmd,
1800 "show evpn [json]",
1801 SHOW_STR
1802 "EVPN\n"
1803 JSON_STR)
1804{
9f049418 1805 bool uj = use_json(argc, argv);
4cce389e
MK
1806
1807 zebra_vxlan_print_evpn(vty, uj);
1808 return CMD_SUCCESS;
1809}
1810
cec2e17d 1811DEFUN (show_evpn_vni,
1812 show_evpn_vni_cmd,
cd233079 1813 "show evpn vni [json]",
cec2e17d 1814 SHOW_STR
1815 "EVPN\n"
09af6961 1816 "VxLAN Network Identifier\n"
bd592158 1817 JSON_STR)
cec2e17d 1818{
d62a17ae 1819 struct zebra_vrf *zvrf;
9f049418 1820 bool uj = use_json(argc, argv);
cec2e17d 1821
d62a17ae 1822 zvrf = vrf_info_lookup(VRF_DEFAULT);
cd233079 1823 zebra_vxlan_print_vnis(vty, zvrf, uj);
d62a17ae 1824 return CMD_SUCCESS;
cec2e17d 1825}
1826
09af6961
NS
1827DEFUN (show_evpn_vni_detail, show_evpn_vni_detail_cmd,
1828 "show evpn vni detail [json]",
1829 SHOW_STR
1830 "EVPN\n"
1831 "VxLAN Network Identifier\n"
1832 "Detailed Information On Each VNI\n"
1833 JSON_STR)
1834{
1835 struct zebra_vrf *zvrf;
1836 bool uj = use_json(argc, argv);
1837
1838 zvrf = vrf_info_lookup(VRF_DEFAULT);
1839 zebra_vxlan_print_vnis_detail(vty, zvrf, uj);
1840 return CMD_SUCCESS;
1841}
1842
cec2e17d 1843DEFUN (show_evpn_vni_vni,
1844 show_evpn_vni_vni_cmd,
cd233079 1845 "show evpn vni " CMD_VNI_RANGE "[json]",
cec2e17d 1846 SHOW_STR
1847 "EVPN\n"
1848 "VxLAN Network Identifier\n"
cd233079 1849 "VNI number\n"
bd592158 1850 JSON_STR)
cec2e17d 1851{
d62a17ae 1852 struct zebra_vrf *zvrf;
1853 vni_t vni;
9f049418 1854 bool uj = use_json(argc, argv);
cec2e17d 1855
d62a17ae 1856 vni = strtoul(argv[3]->arg, NULL, 10);
1857 zvrf = vrf_info_lookup(VRF_DEFAULT);
cd233079 1858 zebra_vxlan_print_vni(vty, zvrf, vni, uj);
d62a17ae 1859 return CMD_SUCCESS;
cec2e17d 1860}
1861
4cce389e
MK
1862DEFUN (show_evpn_rmac_vni_mac,
1863 show_evpn_rmac_vni_mac_cmd,
1864 "show evpn rmac vni " CMD_VNI_RANGE " mac WORD [json]",
9aa741ea
MK
1865 SHOW_STR
1866 "EVPN\n"
1867 "RMAC\n"
4cce389e 1868 "L3 VNI\n"
9aa741ea
MK
1869 "VNI number\n"
1870 "MAC\n"
316f4ca4
MK
1871 "mac-address (e.g. 0a:0a:0a:0a:0a:0a)\n"
1872 JSON_STR)
9aa741ea
MK
1873{
1874 vni_t l3vni = 0;
1875 struct ethaddr mac;
9f049418 1876 bool uj = use_json(argc, argv);
9aa741ea
MK
1877
1878 l3vni = strtoul(argv[4]->arg, NULL, 10);
1879 if (!prefix_str2mac(argv[6]->arg, &mac)) {
1880 vty_out(vty, "%% Malformed MAC address\n");
1881 return CMD_WARNING;
1882 }
316f4ca4 1883 zebra_vxlan_print_specific_rmac_l3vni(vty, l3vni, &mac, uj);
9aa741ea
MK
1884 return CMD_SUCCESS;
1885}
1886
4cce389e
MK
1887DEFUN (show_evpn_rmac_vni,
1888 show_evpn_rmac_vni_cmd,
1889 "show evpn rmac vni " CMD_VNI_RANGE "[json]",
b7cfce93
MK
1890 SHOW_STR
1891 "EVPN\n"
1892 "RMAC\n"
4cce389e 1893 "L3 VNI\n"
b7cfce93
MK
1894 "VNI number\n"
1895 JSON_STR)
1896{
1897 vni_t l3vni = 0;
9f049418 1898 bool uj = use_json(argc, argv);
b7cfce93
MK
1899
1900 l3vni = strtoul(argv[4]->arg, NULL, 10);
1901 zebra_vxlan_print_rmacs_l3vni(vty, l3vni, uj);
1902
1903 return CMD_SUCCESS;
1904}
1905
4cce389e
MK
1906DEFUN (show_evpn_rmac_vni_all,
1907 show_evpn_rmac_vni_all_cmd,
1908 "show evpn rmac vni all [json]",
b7cfce93
MK
1909 SHOW_STR
1910 "EVPN\n"
1911 "RMAC addresses\n"
4cce389e 1912 "L3 VNI\n"
b7cfce93
MK
1913 "All VNIs\n"
1914 JSON_STR)
1915{
9f049418 1916 bool uj = use_json(argc, argv);
b7cfce93
MK
1917
1918 zebra_vxlan_print_rmacs_all_l3vni(vty, uj);
1919
1920 return CMD_SUCCESS;
1921}
1922
4cce389e
MK
1923DEFUN (show_evpn_nh_vni_ip,
1924 show_evpn_nh_vni_ip_cmd,
1925 "show evpn next-hops vni " CMD_VNI_RANGE " ip WORD [json]",
9aa741ea
MK
1926 SHOW_STR
1927 "EVPN\n"
1928 "Remote Vteps\n"
4cce389e 1929 "L3 VNI\n"
9aa741ea
MK
1930 "VNI number\n"
1931 "Ip address\n"
c0e519d3
MK
1932 "Host address (ipv4 or ipv6)\n"
1933 JSON_STR)
9aa741ea
MK
1934{
1935 vni_t l3vni;
9aa741ea 1936 struct ipaddr ip;
9f049418 1937 bool uj = use_json(argc, argv);
9aa741ea
MK
1938
1939 l3vni = strtoul(argv[4]->arg, NULL, 10);
1940 if (str2ipaddr(argv[6]->arg, &ip) != 0) {
1941 if (!uj)
1942 vty_out(vty, "%% Malformed Neighbor address\n");
1943 return CMD_WARNING;
1944 }
c0e519d3 1945 zebra_vxlan_print_specific_nh_l3vni(vty, l3vni, &ip, uj);
9aa741ea
MK
1946
1947 return CMD_SUCCESS;
1948}
1949
4cce389e
MK
1950DEFUN (show_evpn_nh_vni,
1951 show_evpn_nh_vni_cmd,
1952 "show evpn next-hops vni " CMD_VNI_RANGE "[json]",
b7cfce93
MK
1953 SHOW_STR
1954 "EVPN\n"
1955 "Remote Vteps\n"
4cce389e 1956 "L3 VNI\n"
b7cfce93
MK
1957 "VNI number\n"
1958 JSON_STR)
1959{
1960 vni_t l3vni;
9f049418 1961 bool uj = use_json(argc, argv);
b7cfce93
MK
1962
1963 l3vni = strtoul(argv[4]->arg, NULL, 10);
1964 zebra_vxlan_print_nh_l3vni(vty, l3vni, uj);
1965
1966 return CMD_SUCCESS;
1967}
1968
4cce389e
MK
1969DEFUN (show_evpn_nh_vni_all,
1970 show_evpn_nh_vni_all_cmd,
1971 "show evpn next-hops vni all [json]",
b7cfce93
MK
1972 SHOW_STR
1973 "EVPN\n"
1974 "Remote VTEPs\n"
4cce389e 1975 "L3 VNI\n"
b7cfce93
MK
1976 "All VNIs\n"
1977 JSON_STR)
1978{
9f049418 1979 bool uj = use_json(argc, argv);
b7cfce93
MK
1980
1981 zebra_vxlan_print_nh_all_l3vni(vty, uj);
1982
1983 return CMD_SUCCESS;
1984}
1985
cec2e17d 1986DEFUN (show_evpn_mac_vni,
1987 show_evpn_mac_vni_cmd,
cd233079 1988 "show evpn mac vni " CMD_VNI_RANGE "[json]",
cec2e17d 1989 SHOW_STR
1990 "EVPN\n"
1991 "MAC addresses\n"
1992 "VxLAN Network Identifier\n"
cd233079 1993 "VNI number\n"
bd592158 1994 JSON_STR)
cec2e17d 1995{
d62a17ae 1996 struct zebra_vrf *zvrf;
1997 vni_t vni;
9f049418 1998 bool uj = use_json(argc, argv);
cec2e17d 1999
d62a17ae 2000 vni = strtoul(argv[4]->arg, NULL, 10);
2001 zvrf = vrf_info_lookup(VRF_DEFAULT);
cd233079 2002 zebra_vxlan_print_macs_vni(vty, zvrf, vni, uj);
d62a17ae 2003 return CMD_SUCCESS;
cec2e17d 2004}
2005
2006DEFUN (show_evpn_mac_vni_all,
2007 show_evpn_mac_vni_all_cmd,
cd233079 2008 "show evpn mac vni all [json]",
cec2e17d 2009 SHOW_STR
2010 "EVPN\n"
2011 "MAC addresses\n"
2012 "VxLAN Network Identifier\n"
cd233079 2013 "All VNIs\n"
bd592158 2014 JSON_STR)
cec2e17d 2015{
d62a17ae 2016 struct zebra_vrf *zvrf;
9f049418 2017 bool uj = use_json(argc, argv);
cec2e17d 2018
d62a17ae 2019 zvrf = vrf_info_lookup(VRF_DEFAULT);
1374d4db 2020 zebra_vxlan_print_macs_all_vni(vty, zvrf, false, uj);
d62a17ae 2021 return CMD_SUCCESS;
cec2e17d 2022}
2023
cffe7580
NS
2024DEFUN (show_evpn_mac_vni_all_detail, show_evpn_mac_vni_all_detail_cmd,
2025 "show evpn mac vni all detail [json]",
2026 SHOW_STR
2027 "EVPN\n"
2028 "MAC addresses\n"
2029 "VxLAN Network Identifier\n"
2030 "All VNIs\n"
2031 "Detailed Information On Each VNI MAC\n"
2032 JSON_STR)
2033{
2034 struct zebra_vrf *zvrf;
2035 bool uj = use_json(argc, argv);
2036
2037 zvrf = vrf_info_lookup(VRF_DEFAULT);
2038 zebra_vxlan_print_macs_all_vni_detail(vty, zvrf, false, uj);
2039 return CMD_SUCCESS;
2040}
2041
cec2e17d 2042DEFUN (show_evpn_mac_vni_all_vtep,
2043 show_evpn_mac_vni_all_vtep_cmd,
cd233079 2044 "show evpn mac vni all vtep A.B.C.D [json]",
cec2e17d 2045 SHOW_STR
2046 "EVPN\n"
2047 "MAC addresses\n"
2048 "VxLAN Network Identifier\n"
2049 "All VNIs\n"
2050 "Remote VTEP\n"
cd233079 2051 "Remote VTEP IP address\n"
bd592158 2052 JSON_STR)
cec2e17d 2053{
d62a17ae 2054 struct zebra_vrf *zvrf;
2055 struct in_addr vtep_ip;
9f049418 2056 bool uj = use_json(argc, argv);
cec2e17d 2057
d62a17ae 2058 if (!inet_aton(argv[6]->arg, &vtep_ip)) {
cd233079
CS
2059 if (!uj)
2060 vty_out(vty, "%% Malformed VTEP IP address\n");
d62a17ae 2061 return CMD_WARNING;
2062 }
2063 zvrf = vrf_info_lookup(VRF_DEFAULT);
cd233079 2064 zebra_vxlan_print_macs_all_vni_vtep(vty, zvrf, vtep_ip, uj);
cec2e17d 2065
d62a17ae 2066 return CMD_SUCCESS;
cec2e17d 2067}
2068
2069
2070DEFUN (show_evpn_mac_vni_mac,
2071 show_evpn_mac_vni_mac_cmd,
24cdbd0d 2072 "show evpn mac vni " CMD_VNI_RANGE " mac WORD [json]",
cec2e17d 2073 SHOW_STR
2074 "EVPN\n"
2075 "MAC addresses\n"
2076 "VxLAN Network Identifier\n"
2077 "VNI number\n"
2078 "MAC\n"
24cdbd0d
DS
2079 "MAC address (e.g., 00:e0:ec:20:12:62)\n"
2080 JSON_STR)
2081
cec2e17d 2082{
d62a17ae 2083 struct zebra_vrf *zvrf;
2084 vni_t vni;
2085 struct ethaddr mac;
24cdbd0d 2086 bool uj = use_json(argc, argv);
cec2e17d 2087
d62a17ae 2088 vni = strtoul(argv[4]->arg, NULL, 10);
2089 if (!prefix_str2mac(argv[6]->arg, &mac)) {
2090 vty_out(vty, "%% Malformed MAC address");
2091 return CMD_WARNING;
2092 }
2093 zvrf = vrf_info_lookup(VRF_DEFAULT);
24cdbd0d 2094 zebra_vxlan_print_specific_mac_vni(vty, zvrf, vni, &mac, uj);
d62a17ae 2095 return CMD_SUCCESS;
cec2e17d 2096}
2097
2098DEFUN (show_evpn_mac_vni_vtep,
2099 show_evpn_mac_vni_vtep_cmd,
cd233079 2100 "show evpn mac vni " CMD_VNI_RANGE " vtep A.B.C.D" "[json]",
cec2e17d 2101 SHOW_STR
2102 "EVPN\n"
2103 "MAC addresses\n"
2104 "VxLAN Network Identifier\n"
2105 "VNI number\n"
2106 "Remote VTEP\n"
cd233079 2107 "Remote VTEP IP address\n"
bd592158 2108 JSON_STR)
cec2e17d 2109{
d62a17ae 2110 struct zebra_vrf *zvrf;
2111 vni_t vni;
2112 struct in_addr vtep_ip;
9f049418 2113 bool uj = use_json(argc, argv);
cec2e17d 2114
d62a17ae 2115 vni = strtoul(argv[4]->arg, NULL, 10);
2116 if (!inet_aton(argv[6]->arg, &vtep_ip)) {
cd233079
CS
2117 if (!uj)
2118 vty_out(vty, "%% Malformed VTEP IP address\n");
d62a17ae 2119 return CMD_WARNING;
2120 }
cec2e17d 2121
d62a17ae 2122 zvrf = vrf_info_lookup(VRF_DEFAULT);
cd233079 2123 zebra_vxlan_print_macs_vni_vtep(vty, zvrf, vni, vtep_ip, uj);
d62a17ae 2124 return CMD_SUCCESS;
cec2e17d 2125}
2126
1374d4db
CS
2127DEFPY (show_evpn_mac_vni_all_dad,
2128 show_evpn_mac_vni_all_dad_cmd,
2129 "show evpn mac vni all duplicate [json]",
2130 SHOW_STR
2131 "EVPN\n"
2132 "MAC addresses\n"
2133 "VxLAN Network Identifier\n"
2134 "All VNIs\n"
2135 "Duplicate address list\n"
2136 JSON_STR)
2137{
2138 struct zebra_vrf *zvrf;
2139 bool uj = use_json(argc, argv);
2140
2141 zvrf = vrf_info_lookup(VRF_DEFAULT);
2142 zebra_vxlan_print_macs_all_vni(vty, zvrf, true, uj);
2143 return CMD_SUCCESS;
2144}
2145
2146
2147DEFPY (show_evpn_mac_vni_dad,
2148 show_evpn_mac_vni_dad_cmd,
2149 "show evpn mac vni " CMD_VNI_RANGE " duplicate" "[json]",
2150 SHOW_STR
2151 "EVPN\n"
2152 "MAC addresses\n"
2153 "VxLAN Network Identifier\n"
2154 "VNI number\n"
2155 "Duplicate address list\n"
2156 JSON_STR)
2157{
2158 struct zebra_vrf *zvrf;
2159 vni_t vni;
2160 bool uj = use_json(argc, argv);
2161
2162 vni = strtoul(argv[4]->arg, NULL, 10);
2163 zvrf = vrf_info_lookup(VRF_DEFAULT);
2164
2165 zebra_vxlan_print_macs_vni_dad(vty, zvrf, vni, uj);
2166
2167 return CMD_SUCCESS;
2168}
2169
2170DEFPY (show_evpn_neigh_vni_dad,
2171 show_evpn_neigh_vni_dad_cmd,
2172 "show evpn arp-cache vni " CMD_VNI_RANGE "duplicate" "[json]",
2173 SHOW_STR
2174 "EVPN\n"
2175 "ARP and ND cache\n"
2176 "VxLAN Network Identifier\n"
2177 "VNI number\n"
2178 "Duplicate address list\n"
2179 JSON_STR)
2180{
2181 struct zebra_vrf *zvrf;
2182 vni_t vni;
2183 bool uj = use_json(argc, argv);
2184
2185 vni = strtoul(argv[4]->arg, NULL, 10);
2186 zvrf = vrf_info_lookup(VRF_DEFAULT);
2187 zebra_vxlan_print_neigh_vni_dad(vty, zvrf, vni, uj);
2188 return CMD_SUCCESS;
2189}
2190
2191DEFPY (show_evpn_neigh_vni_all_dad,
2192 show_evpn_neigh_vni_all_dad_cmd,
2193 "show evpn arp-cache vni all duplicate [json]",
2194 SHOW_STR
2195 "EVPN\n"
2196 "ARP and ND cache\n"
2197 "VxLAN Network Identifier\n"
2198 "All VNIs\n"
2199 "Duplicate address list\n"
2200 JSON_STR)
2201{
2202 struct zebra_vrf *zvrf;
2203 bool uj = use_json(argc, argv);
2204
2205 zvrf = vrf_info_lookup(VRF_DEFAULT);
2206 zebra_vxlan_print_neigh_all_vni(vty, zvrf, true, uj);
2207 return CMD_SUCCESS;
2208}
2209
2210
cec2e17d 2211DEFUN (show_evpn_neigh_vni,
2212 show_evpn_neigh_vni_cmd,
cd233079 2213 "show evpn arp-cache vni " CMD_VNI_RANGE "[json]",
cec2e17d 2214 SHOW_STR
2215 "EVPN\n"
2216 "ARP and ND cache\n"
2217 "VxLAN Network Identifier\n"
cd233079 2218 "VNI number\n"
bd592158 2219 JSON_STR)
cec2e17d 2220{
d62a17ae 2221 struct zebra_vrf *zvrf;
2222 vni_t vni;
9f049418 2223 bool uj = use_json(argc, argv);
cec2e17d 2224
d62a17ae 2225 vni = strtoul(argv[4]->arg, NULL, 10);
2226 zvrf = vrf_info_lookup(VRF_DEFAULT);
cd233079 2227 zebra_vxlan_print_neigh_vni(vty, zvrf, vni, uj);
d62a17ae 2228 return CMD_SUCCESS;
cec2e17d 2229}
2230
2231DEFUN (show_evpn_neigh_vni_all,
2232 show_evpn_neigh_vni_all_cmd,
cd233079 2233 "show evpn arp-cache vni all [json]",
cec2e17d 2234 SHOW_STR
2235 "EVPN\n"
2236 "ARP and ND cache\n"
2237 "VxLAN Network Identifier\n"
cd233079 2238 "All VNIs\n"
bd592158 2239 JSON_STR)
cec2e17d 2240{
d62a17ae 2241 struct zebra_vrf *zvrf;
9f049418 2242 bool uj = use_json(argc, argv);
cec2e17d 2243
d62a17ae 2244 zvrf = vrf_info_lookup(VRF_DEFAULT);
1374d4db 2245 zebra_vxlan_print_neigh_all_vni(vty, zvrf, false, uj);
d62a17ae 2246 return CMD_SUCCESS;
cec2e17d 2247}
2248
e3fac919
NS
2249DEFUN (show_evpn_neigh_vni_all_detail, show_evpn_neigh_vni_all_detail_cmd,
2250 "show evpn arp-cache vni all detail [json]",
2251 SHOW_STR
2252 "EVPN\n"
2253 "ARP and ND cache\n"
2254 "VxLAN Network Identifier\n"
2255 "All VNIs\n"
2256 "Neighbor details for all vnis in detail\n" JSON_STR)
2257{
2258 struct zebra_vrf *zvrf;
2259 bool uj = use_json(argc, argv);
2260
2261 zvrf = vrf_info_lookup(VRF_DEFAULT);
2262 zebra_vxlan_print_neigh_all_vni_detail(vty, zvrf, false, uj);
2263 return CMD_SUCCESS;
2264}
2265
cec2e17d 2266DEFUN (show_evpn_neigh_vni_neigh,
2267 show_evpn_neigh_vni_neigh_cmd,
cd233079 2268 "show evpn arp-cache vni " CMD_VNI_RANGE " ip WORD [json]",
cec2e17d 2269 SHOW_STR
2270 "EVPN\n"
2271 "ARP and ND cache\n"
2272 "VxLAN Network Identifier\n"
2273 "VNI number\n"
2274 "Neighbor\n"
cd233079 2275 "Neighbor address (IPv4 or IPv6 address)\n"
bd592158 2276 JSON_STR)
cec2e17d 2277{
d62a17ae 2278 struct zebra_vrf *zvrf;
2279 vni_t vni;
2280 struct ipaddr ip;
9f049418 2281 bool uj = use_json(argc, argv);
cec2e17d 2282
d62a17ae 2283 vni = strtoul(argv[4]->arg, NULL, 10);
2284 if (str2ipaddr(argv[6]->arg, &ip) != 0) {
cd233079
CS
2285 if (!uj)
2286 vty_out(vty, "%% Malformed Neighbor address\n");
d62a17ae 2287 return CMD_WARNING;
2288 }
2289 zvrf = vrf_info_lookup(VRF_DEFAULT);
cd233079 2290 zebra_vxlan_print_specific_neigh_vni(vty, zvrf, vni, &ip, uj);
d62a17ae 2291 return CMD_SUCCESS;
cec2e17d 2292}
2293
2294DEFUN (show_evpn_neigh_vni_vtep,
2295 show_evpn_neigh_vni_vtep_cmd,
cd233079 2296 "show evpn arp-cache vni " CMD_VNI_RANGE " vtep A.B.C.D [json]",
cec2e17d 2297 SHOW_STR
2298 "EVPN\n"
2299 "ARP and ND cache\n"
2300 "VxLAN Network Identifier\n"
2301 "VNI number\n"
2302 "Remote VTEP\n"
cd233079 2303 "Remote VTEP IP address\n"
bd592158 2304 JSON_STR)
cec2e17d 2305{
d62a17ae 2306 struct zebra_vrf *zvrf;
2307 vni_t vni;
2308 struct in_addr vtep_ip;
9f049418 2309 bool uj = use_json(argc, argv);
cec2e17d 2310
d62a17ae 2311 vni = strtoul(argv[4]->arg, NULL, 10);
2312 if (!inet_aton(argv[6]->arg, &vtep_ip)) {
cd233079
CS
2313 if (!uj)
2314 vty_out(vty, "%% Malformed VTEP IP address\n");
d62a17ae 2315 return CMD_WARNING;
2316 }
cec2e17d 2317
d62a17ae 2318 zvrf = vrf_info_lookup(VRF_DEFAULT);
cd233079 2319 zebra_vxlan_print_neigh_vni_vtep(vty, zvrf, vni, vtep_ip, uj);
d62a17ae 2320 return CMD_SUCCESS;
cec2e17d 2321}
2322
586f4ccf
PG
2323/* policy routing contexts */
2324DEFUN (show_pbr_ipset,
2325 show_pbr_ipset_cmd,
2326 "show pbr ipset [WORD]",
2327 SHOW_STR
2328 "Policy-Based Routing\n"
2329 "IPset Context information\n"
2330 "IPset Name information\n")
2331{
2332 int idx = 0;
2333 int found = 0;
2334 found = argv_find(argv, argc, "WORD", &idx);
2335 if (!found)
2336 zebra_pbr_show_ipset_list(vty, NULL);
2337 else
2338 zebra_pbr_show_ipset_list(vty, argv[idx]->arg);
2339 return CMD_SUCCESS;
2340}
2341
2342/* policy routing contexts */
2343DEFUN (show_pbr_iptable,
2344 show_pbr_iptable_cmd,
7929821a 2345 "show pbr iptable [WORD]",
586f4ccf
PG
2346 SHOW_STR
2347 "Policy-Based Routing\n"
7929821a
PG
2348 "IPtable Context information\n"
2349 "IPtable Name information\n")
586f4ccf 2350{
7929821a
PG
2351 int idx = 0;
2352 int found = 0;
2353
2354 found = argv_find(argv, argc, "WORD", &idx);
2355 if (!found)
2356 zebra_pbr_show_iptable(vty, NULL);
2357 else
2358 zebra_pbr_show_iptable(vty, argv[idx]->arg);
586f4ccf
PG
2359 return CMD_SUCCESS;
2360}
2361
09de9258
CS
2362DEFPY (clear_evpn_dup_addr,
2363 clear_evpn_dup_addr_cmd,
2364 "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>]>",
2365 CLEAR_STR
2366 "EVPN\n"
2367 "Duplicate address \n"
2368 "VxLAN Network Identifier\n"
2369 "VNI number\n"
2370 "All VNIs\n"
2371 "MAC\n"
2372 "MAC address (e.g., 00:e0:ec:20:12:62)\n"
2373 "IP\n"
2374 "IPv4 address\n"
2375 "IPv6 address\n")
2376{
2377 struct zebra_vrf *zvrf;
2378 vni_t vni = 0;
2379 struct ipaddr host_ip = {.ipa_type = IPADDR_NONE };
2380 struct ethaddr mac_addr;
1883de66 2381 int ret = CMD_SUCCESS;
09de9258
CS
2382
2383 zvrf = vrf_info_lookup(VRF_DEFAULT);
2384 if (vni_val) {
2385 vni = strtoul(vni_val, NULL, 10);
2386
2387 if (mac_val) {
2388 prefix_str2mac(mac_val, &mac_addr);
1883de66
CS
2389 ret = zebra_vxlan_clear_dup_detect_vni_mac(vty, zvrf,
2390 vni,
2391 &mac_addr);
2392 } else if (ip) {
09de9258
CS
2393 if (sockunion_family(ip) == AF_INET) {
2394 host_ip.ipa_type = IPADDR_V4;
2395 host_ip.ipaddr_v4.s_addr = sockunion2ip(ip);
2396 } else {
2397 host_ip.ipa_type = IPADDR_V6;
2398 memcpy(&host_ip.ipaddr_v6, &ip->sin6.sin6_addr,
2399 sizeof(struct in6_addr));
2400 }
1883de66
CS
2401 ret = zebra_vxlan_clear_dup_detect_vni_ip(vty, zvrf,
2402 vni,
2403 &host_ip);
09de9258 2404 } else
1883de66 2405 ret = zebra_vxlan_clear_dup_detect_vni(vty, zvrf, vni);
09de9258
CS
2406
2407 } else {
1883de66 2408 ret = zebra_vxlan_clear_dup_detect_vni_all(vty, zvrf);
09de9258
CS
2409 }
2410
1883de66 2411 return ret;
09de9258
CS
2412}
2413
718e3744 2414/* Static ip route configuration write function. */
d62a17ae 2415static int zebra_ip_config(struct vty *vty)
718e3744 2416{
d62a17ae 2417 int write = 0;
718e3744 2418
d62a17ae 2419 write += zebra_import_table_config(vty);
37728041 2420
d62a17ae 2421 return write;
718e3744 2422}
2423
7a4bb9c5
DS
2424DEFUN (ip_zebra_import_table_distance,
2425 ip_zebra_import_table_distance_cmd,
12dcf78e 2426 "ip import-table (1-252) [distance (1-255)] [route-map WORD]",
8902474b
DS
2427 IP_STR
2428 "import routes from non-main kernel table\n"
2429 "kernel routing table id\n"
2430 "Distance for imported routes\n"
2431 "Default distance value\n"
2432 "route-map for filtering\n"
2433 "route-map name\n")
2434{
d7c0a89a 2435 uint32_t table_id = 0;
8902474b 2436
d62a17ae 2437 table_id = strtoul(argv[2]->arg, NULL, 10);
2438 int distance = ZEBRA_TABLE_DISTANCE_DEFAULT;
2439 char *rmap =
2440 strmatch(argv[argc - 2]->text, "route-map")
2441 ? XSTRDUP(MTYPE_ROUTE_MAP_NAME, argv[argc - 1]->arg)
2442 : NULL;
2443 int ret;
d722f26e 2444
d62a17ae 2445 if (argc == 7 || (argc == 5 && !rmap))
2446 distance = strtoul(argv[4]->arg, NULL, 10);
8902474b 2447
d62a17ae 2448 if (!is_zebra_valid_kernel_table(table_id)) {
2449 vty_out(vty,
2450 "Invalid routing table ID, %d. Must be in range 1-252\n",
2451 table_id);
0af35d90
RW
2452 if (rmap)
2453 XFREE(MTYPE_ROUTE_MAP_NAME, rmap);
d62a17ae 2454 return CMD_WARNING;
2455 }
8902474b 2456
d62a17ae 2457 if (is_zebra_main_routing_table(table_id)) {
2458 vty_out(vty,
2459 "Invalid routing table ID, %d. Must be non-default table\n",
2460 table_id);
0af35d90
RW
2461 if (rmap)
2462 XFREE(MTYPE_ROUTE_MAP_NAME, rmap);
d62a17ae 2463 return CMD_WARNING;
2464 }
8902474b 2465
d62a17ae 2466 ret = zebra_import_table(AFI_IP, table_id, distance, rmap, 1);
2467 if (rmap)
2468 XFREE(MTYPE_ROUTE_MAP_NAME, rmap);
d722f26e 2469
d62a17ae 2470 return ret;
8902474b
DS
2471}
2472
62d52ded
DS
2473DEFUN_HIDDEN (zebra_packet_process,
2474 zebra_packet_process_cmd,
2475 "zebra zapi-packets (1-10000)",
2476 ZEBRA_STR
2477 "Zapi Protocol\n"
2478 "Number of packets to process before relinquishing thread\n")
2479{
2480 uint32_t packets = strtoul(argv[2]->arg, NULL, 10);
2481
ccd51bd2
QY
2482 atomic_store_explicit(&zebrad.packets_to_process, packets,
2483 memory_order_relaxed);
62d52ded
DS
2484
2485 return CMD_SUCCESS;
2486}
2487
2488DEFUN_HIDDEN (no_zebra_packet_process,
2489 no_zebra_packet_process_cmd,
2490 "no zebra zapi-packets [(1-10000)]",
2491 NO_STR
2492 ZEBRA_STR
2493 "Zapi Protocol\n"
2494 "Number of packets to process before relinquishing thread\n")
2495{
ccd51bd2
QY
2496 atomic_store_explicit(&zebrad.packets_to_process,
2497 ZEBRA_ZAPI_PACKETS_TO_PROCESS,
2498 memory_order_relaxed);
62d52ded
DS
2499
2500 return CMD_SUCCESS;
2501}
2502
3a30f50f
DS
2503DEFUN_HIDDEN (zebra_workqueue_timer,
2504 zebra_workqueue_timer_cmd,
2505 "zebra work-queue (0-10000)",
2506 ZEBRA_STR
2507 "Work Queue\n"
2508 "Time in milliseconds\n")
2509{
996c9314
LB
2510 uint32_t timer = strtoul(argv[2]->arg, NULL, 10);
2511 zebrad.ribq->spec.hold = timer;
3a30f50f 2512
996c9314 2513 return CMD_SUCCESS;
3a30f50f
DS
2514}
2515
2516DEFUN_HIDDEN (no_zebra_workqueue_timer,
2517 no_zebra_workqueue_timer_cmd,
2518 "no zebra work-queue [(0-10000)]",
2519 NO_STR
2520 ZEBRA_STR
2521 "Work Queue\n"
2522 "Time in milliseconds\n")
2523{
996c9314 2524 zebrad.ribq->spec.hold = ZEBRA_RIB_PROCESS_HOLD_TIME;
3a30f50f 2525
996c9314 2526 return CMD_SUCCESS;
3a30f50f
DS
2527}
2528
7a4bb9c5
DS
2529DEFUN (no_ip_zebra_import_table,
2530 no_ip_zebra_import_table_cmd,
b62ecea5 2531 "no ip import-table (1-252) [distance (1-255)] [route-map NAME]",
7a4bb9c5
DS
2532 NO_STR
2533 IP_STR
2534 "import routes from non-main kernel table\n"
3a2d747c
QY
2535 "kernel routing table id\n"
2536 "Distance for imported routes\n"
2537 "Default distance value\n"
2538 "route-map for filtering\n"
2539 "route-map name\n")
7a4bb9c5 2540{
d7c0a89a 2541 uint32_t table_id = 0;
d62a17ae 2542 table_id = strtoul(argv[3]->arg, NULL, 10);
7a4bb9c5 2543
d62a17ae 2544 if (!is_zebra_valid_kernel_table(table_id)) {
2545 vty_out(vty,
2546 "Invalid routing table ID. Must be in range 1-252\n");
2547 return CMD_WARNING;
2548 }
7a4bb9c5 2549
d62a17ae 2550 if (is_zebra_main_routing_table(table_id)) {
2551 vty_out(vty,
2552 "Invalid routing table ID, %d. Must be non-default table\n",
2553 table_id);
2554 return CMD_WARNING;
2555 }
7a4bb9c5 2556
d62a17ae 2557 if (!is_zebra_import_table_enabled(AFI_IP, table_id))
2558 return CMD_SUCCESS;
7a4bb9c5 2559
d62a17ae 2560 return (zebra_import_table(AFI_IP, table_id, 0, NULL, 0));
7a4bb9c5
DS
2561}
2562
d62a17ae 2563static int config_write_protocol(struct vty *vty)
6baf7bb8 2564{
d62a17ae 2565 if (allow_delete)
2566 vty_out(vty, "allow-external-route-update\n");
6baf7bb8 2567
d62a17ae 2568 if (zebra_rnh_ip_default_route)
2569 vty_out(vty, "ip nht resolve-via-default\n");
6baf7bb8 2570
d62a17ae 2571 if (zebra_rnh_ipv6_default_route)
2572 vty_out(vty, "ipv6 nht resolve-via-default\n");
6baf7bb8 2573
3a30f50f
DS
2574 if (zebrad.ribq->spec.hold != ZEBRA_RIB_PROCESS_HOLD_TIME)
2575 vty_out(vty, "zebra work-queue %u\n", zebrad.ribq->spec.hold);
2576
62d52ded 2577 if (zebrad.packets_to_process != ZEBRA_ZAPI_PACKETS_TO_PROCESS)
996c9314
LB
2578 vty_out(vty, "zebra zapi-packets %u\n",
2579 zebrad.packets_to_process);
62d52ded 2580
d62a17ae 2581 enum multicast_mode ipv4_multicast_mode = multicast_mode_ipv4_get();
4623d897 2582
d62a17ae 2583 if (ipv4_multicast_mode != MCAST_NO_CONFIG)
2584 vty_out(vty, "ip multicast rpf-lookup-mode %s\n",
2585 ipv4_multicast_mode == MCAST_URIB_ONLY
2586 ? "urib-only"
2587 : ipv4_multicast_mode == MCAST_MRIB_ONLY
2588 ? "mrib-only"
2589 : ipv4_multicast_mode
2590 == MCAST_MIX_MRIB_FIRST
2591 ? "mrib-then-urib"
2592 : ipv4_multicast_mode
2593 == MCAST_MIX_DISTANCE
2594 ? "lower-distance"
2595 : "longer-prefix");
d62a17ae 2596 return 1;
6baf7bb8
DS
2597}
2598
c0d136ae
DS
2599#ifdef HAVE_NETLINK
2600/* Display default rtm_table for all clients. */
2601DEFUN (show_table,
2602 show_table_cmd,
2603 "show table",
2604 SHOW_STR
2605 "default routing table to use for all clients\n")
2606{
2607 vty_out(vty, "table %d\n", zebrad.rtm_table_default);
2608 return CMD_SUCCESS;
2609}
2610
2611DEFUN (config_table,
2612 config_table_cmd,
2613 "table TABLENO",
2614 "Configure target kernel routing table\n"
2615 "TABLE integer\n")
2616{
2617 zebrad.rtm_table_default = strtol(argv[1]->arg, (char **)0, 10);
2618 return CMD_SUCCESS;
2619}
2620
2621DEFUN (no_config_table,
2622 no_config_table_cmd,
2623 "no table [TABLENO]",
2624 NO_STR
2625 "Configure target kernel routing table\n"
2626 "TABLE integer\n")
2627{
2628 zebrad.rtm_table_default = 0;
2629 return CMD_SUCCESS;
2630}
2631#endif
2632
2633DEFUN (show_zebra,
2634 show_zebra_cmd,
2635 "show zebra",
2636 SHOW_STR
2637 ZEBRA_STR)
2638{
2639 struct vrf *vrf;
2640
2641 vty_out(vty,
2642 " Route Route Neighbor LSP LSP\n");
2643 vty_out(vty,
2644 "VRF Installs Removals Updates Installs Removals\n");
2645
996c9314 2646 RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) {
c0d136ae
DS
2647 struct zebra_vrf *zvrf = vrf->info;
2648
2649 vty_out(vty, "%-25s %10" PRIu64 " %10" PRIu64 " %10" PRIu64
2650 " %10" PRIu64 " %10" PRIu64 "\n",
2651 vrf->name, zvrf->installs, zvrf->removals,
2652 zvrf->neigh_updates, zvrf->lsp_installs,
2653 zvrf->lsp_removals);
2654 }
2655
2656 return CMD_SUCCESS;
2657}
2658
2659DEFUN (ip_forwarding,
2660 ip_forwarding_cmd,
2661 "ip forwarding",
2662 IP_STR
2663 "Turn on IP forwarding\n")
2664{
2665 int ret;
2666
2667 ret = ipforward();
2668 if (ret == 0)
2669 ret = ipforward_on();
2670
2671 if (ret == 0) {
2672 vty_out(vty, "Can't turn on IP forwarding\n");
2673 return CMD_WARNING_CONFIG_FAILED;
2674 }
2675
2676 return CMD_SUCCESS;
2677}
2678
2679DEFUN (no_ip_forwarding,
2680 no_ip_forwarding_cmd,
2681 "no ip forwarding",
2682 NO_STR
2683 IP_STR
2684 "Turn off IP forwarding\n")
2685{
2686 int ret;
2687
2688 ret = ipforward();
2689 if (ret != 0)
2690 ret = ipforward_off();
2691
2692 if (ret != 0) {
2693 vty_out(vty, "Can't turn off IP forwarding\n");
2694 return CMD_WARNING_CONFIG_FAILED;
2695 }
2696
2697 return CMD_SUCCESS;
2698}
2699
2700/* Only display ip forwarding is enabled or not. */
2701DEFUN (show_ip_forwarding,
2702 show_ip_forwarding_cmd,
2703 "show ip forwarding",
2704 SHOW_STR
2705 IP_STR
2706 "IP forwarding status\n")
2707{
2708 int ret;
2709
2710 ret = ipforward();
2711
2712 if (ret == 0)
2713 vty_out(vty, "IP forwarding is off\n");
2714 else
2715 vty_out(vty, "IP forwarding is on\n");
2716 return CMD_SUCCESS;
2717}
2718
2719/* Only display ipv6 forwarding is enabled or not. */
2720DEFUN (show_ipv6_forwarding,
2721 show_ipv6_forwarding_cmd,
2722 "show ipv6 forwarding",
2723 SHOW_STR
2724 "IPv6 information\n"
2725 "Forwarding status\n")
2726{
2727 int ret;
2728
2729 ret = ipforward_ipv6();
2730
2731 switch (ret) {
2732 case -1:
2733 vty_out(vty, "ipv6 forwarding is unknown\n");
2734 break;
2735 case 0:
2736 vty_out(vty, "ipv6 forwarding is %s\n", "off");
2737 break;
2738 case 1:
2739 vty_out(vty, "ipv6 forwarding is %s\n", "on");
2740 break;
2741 default:
2742 vty_out(vty, "ipv6 forwarding is %s\n", "off");
2743 break;
2744 }
2745 return CMD_SUCCESS;
2746}
2747
2748DEFUN (ipv6_forwarding,
2749 ipv6_forwarding_cmd,
2750 "ipv6 forwarding",
2751 IPV6_STR
2752 "Turn on IPv6 forwarding\n")
2753{
2754 int ret;
2755
2756 ret = ipforward_ipv6();
2757 if (ret == 0)
2758 ret = ipforward_ipv6_on();
2759
2760 if (ret == 0) {
2761 vty_out(vty, "Can't turn on IPv6 forwarding\n");
2762 return CMD_WARNING_CONFIG_FAILED;
2763 }
2764
2765 return CMD_SUCCESS;
2766}
2767
2768DEFUN (no_ipv6_forwarding,
2769 no_ipv6_forwarding_cmd,
2770 "no ipv6 forwarding",
2771 NO_STR
2772 IPV6_STR
2773 "Turn off IPv6 forwarding\n")
2774{
2775 int ret;
2776
2777 ret = ipforward_ipv6();
2778 if (ret != 0)
2779 ret = ipforward_ipv6_off();
2780
2781 if (ret != 0) {
2782 vty_out(vty, "Can't turn off IPv6 forwarding\n");
2783 return CMD_WARNING_CONFIG_FAILED;
2784 }
2785
2786 return CMD_SUCCESS;
2787}
2788
1d11b21f
MS
2789/* Display dataplane info */
2790DEFUN (show_dataplane,
2791 show_dataplane_cmd,
2792 "show zebra dplane [detailed]",
2793 SHOW_STR
2794 ZEBRA_STR
2795 "Zebra dataplane information\n"
2796 "Detailed output\n")
2797{
2798 int idx = 0;
2799 bool detailed = false;
2800
2801 if (argv_find(argv, argc, "detailed", &idx))
2802 detailed = true;
2803
2804 return dplane_show_helper(vty, detailed);
2805}
2806
2807/* Display dataplane providers info */
2808DEFUN (show_dataplane_providers,
2809 show_dataplane_providers_cmd,
2810 "show zebra dplane providers [detailed]",
2811 SHOW_STR
2812 ZEBRA_STR
2813 "Zebra dataplane information\n"
2814 "Zebra dataplane provider information\n"
2815 "Detailed output\n")
2816{
2817 int idx = 0;
2818 bool detailed = false;
2819
2820 if (argv_find(argv, argc, "detailed", &idx))
2821 detailed = true;
2822
2823 return dplane_show_provs_helper(vty, detailed);
2824}
2825
91f16812
MS
2826/* Configure dataplane incoming queue limit */
2827DEFUN (zebra_dplane_queue_limit,
2828 zebra_dplane_queue_limit_cmd,
2829 "zebra dplane limit (0-10000)",
2830 ZEBRA_STR
2831 "Zebra dataplane\n"
2832 "Limit incoming queued updates\n"
2833 "Number of queued updates\n")
2834{
2835 uint32_t limit = 0;
2836
2837 limit = strtoul(argv[3]->arg, NULL, 10);
2838
2839 dplane_set_in_queue_limit(limit, true);
2840
2841 return CMD_SUCCESS;
2842}
2843
2844/* Reset dataplane queue limit to default value */
2845DEFUN (no_zebra_dplane_queue_limit,
2846 no_zebra_dplane_queue_limit_cmd,
2847 "no zebra dplane limit [(0-10000)]",
2848 NO_STR
2849 ZEBRA_STR
2850 "Zebra dataplane\n"
2851 "Limit incoming queued updates\n"
2852 "Number of queued updates\n")
2853{
2854 dplane_set_in_queue_limit(0, false);
2855
2856 return CMD_SUCCESS;
2857}
1d11b21f 2858
ac5aa23f
DS
2859DEFUN (zebra_show_routing_tables_summary,
2860 zebra_show_routing_tables_summary_cmd,
2861 "show zebra router table summary",
2862 SHOW_STR
2863 ZEBRA_STR
2864 "The Zebra Router Information\n"
2865 "Table Information about this Zebra Router\n"
2866 "Summary Information\n")
2867{
2868 zebra_router_show_table_summary(vty);
2869
2870 return CMD_SUCCESS;
2871}
2872
c0d136ae
DS
2873/* Table configuration write function. */
2874static int config_write_table(struct vty *vty)
2875{
2876 if (zebrad.rtm_table_default)
2877 vty_out(vty, "table %d\n", zebrad.rtm_table_default);
2878 return 0;
2879}
2880
2881/* IPForwarding configuration write function. */
2882static int config_write_forwarding(struct vty *vty)
2883{
2884 /* FIXME: Find better place for that. */
2885 router_id_write(vty);
2886
2887 if (!ipforward())
2888 vty_out(vty, "no ip forwarding\n");
2889 if (!ipforward_ipv6())
2890 vty_out(vty, "no ipv6 forwarding\n");
2891 vty_out(vty, "!\n");
2892 return 0;
2893}
2894
718e3744 2895/* IP node for static routes. */
d62a17ae 2896static struct cmd_node ip_node = {IP_NODE, "", 1};
2897static struct cmd_node protocol_node = {PROTOCOL_NODE, "", 1};
c0d136ae
DS
2898/* table node for routing tables. */
2899static struct cmd_node table_node = {TABLE_NODE,
2900 "", /* This node has no interface. */
2901 1};
2902static struct cmd_node forwarding_node = {FORWARDING_NODE,
2903 "", /* This node has no interface. */
2904 1};
718e3744 2905
2906/* Route VTY. */
d62a17ae 2907void zebra_vty_init(void)
2908{
c0d136ae
DS
2909 /* Install configuration write function. */
2910 install_node(&table_node, config_write_table);
2911 install_node(&forwarding_node, config_write_forwarding);
2912
2913 install_element(VIEW_NODE, &show_ip_forwarding_cmd);
2914 install_element(CONFIG_NODE, &ip_forwarding_cmd);
2915 install_element(CONFIG_NODE, &no_ip_forwarding_cmd);
2916 install_element(ENABLE_NODE, &show_zebra_cmd);
2917
2918#ifdef HAVE_NETLINK
2919 install_element(VIEW_NODE, &show_table_cmd);
2920 install_element(CONFIG_NODE, &config_table_cmd);
2921 install_element(CONFIG_NODE, &no_config_table_cmd);
2922#endif /* HAVE_NETLINK */
2923
2924 install_element(VIEW_NODE, &show_ipv6_forwarding_cmd);
2925 install_element(CONFIG_NODE, &ipv6_forwarding_cmd);
2926 install_element(CONFIG_NODE, &no_ipv6_forwarding_cmd);
2927
2928 /* Route-map */
2929 zebra_route_map_init();
2930
d62a17ae 2931 install_node(&ip_node, zebra_ip_config);
2932 install_node(&protocol_node, config_write_protocol);
2933
2934 install_element(CONFIG_NODE, &allow_external_route_update_cmd);
2935 install_element(CONFIG_NODE, &no_allow_external_route_update_cmd);
7e24fdf3 2936
d62a17ae 2937 install_element(CONFIG_NODE, &ip_multicast_mode_cmd);
2938 install_element(CONFIG_NODE, &no_ip_multicast_mode_cmd);
b3b08602 2939
d62a17ae 2940 install_element(CONFIG_NODE, &ip_zebra_import_table_distance_cmd);
2941 install_element(CONFIG_NODE, &no_ip_zebra_import_table_cmd);
3a30f50f
DS
2942 install_element(CONFIG_NODE, &zebra_workqueue_timer_cmd);
2943 install_element(CONFIG_NODE, &no_zebra_workqueue_timer_cmd);
62d52ded
DS
2944 install_element(CONFIG_NODE, &zebra_packet_process_cmd);
2945 install_element(CONFIG_NODE, &no_zebra_packet_process_cmd);
d62a17ae 2946
2947 install_element(VIEW_NODE, &show_vrf_cmd);
b7cfce93 2948 install_element(VIEW_NODE, &show_vrf_vni_cmd);
ecffa493 2949 install_element(VIEW_NODE, &show_route_cmd);
ae825b8b 2950 install_element(VIEW_NODE, &show_route_table_cmd);
87d6ac7a
PG
2951 if (vrf_is_backend_netns())
2952 install_element(VIEW_NODE, &show_route_table_vrf_cmd);
5ce91022
RW
2953 install_element(VIEW_NODE, &show_route_detail_cmd);
2954 install_element(VIEW_NODE, &show_route_summary_cmd);
d62a17ae 2955 install_element(VIEW_NODE, &show_ip_nht_cmd);
b85c8275 2956 install_element(VIEW_NODE, &show_ip_import_check_cmd);
d62a17ae 2957 install_element(VIEW_NODE, &show_ip_nht_vrf_all_cmd);
2958 install_element(VIEW_NODE, &show_ipv6_nht_cmd);
2959 install_element(VIEW_NODE, &show_ipv6_nht_vrf_all_cmd);
d62a17ae 2960
2961 install_element(VIEW_NODE, &show_ip_rpf_cmd);
2962 install_element(VIEW_NODE, &show_ip_rpf_addr_cmd);
2963
d62a17ae 2964 install_element(CONFIG_NODE, &ip_nht_default_route_cmd);
2965 install_element(CONFIG_NODE, &no_ip_nht_default_route_cmd);
2966 install_element(CONFIG_NODE, &ipv6_nht_default_route_cmd);
2967 install_element(CONFIG_NODE, &no_ipv6_nht_default_route_cmd);
214e5c26 2968 install_element(VRF_NODE, &ip_nht_default_route_cmd);
2969 install_element(VRF_NODE, &no_ip_nht_default_route_cmd);
2970 install_element(VRF_NODE, &ipv6_nht_default_route_cmd);
2971 install_element(VRF_NODE, &no_ipv6_nht_default_route_cmd);
d62a17ae 2972 install_element(VIEW_NODE, &show_ipv6_mroute_cmd);
2973
2974 /* Commands for VRF */
d62a17ae 2975 install_element(VIEW_NODE, &show_ipv6_mroute_vrf_all_cmd);
2976
4cce389e 2977 install_element(VIEW_NODE, &show_evpn_global_cmd);
d62a17ae 2978 install_element(VIEW_NODE, &show_evpn_vni_cmd);
09af6961 2979 install_element(VIEW_NODE, &show_evpn_vni_detail_cmd);
d62a17ae 2980 install_element(VIEW_NODE, &show_evpn_vni_vni_cmd);
4cce389e
MK
2981 install_element(VIEW_NODE, &show_evpn_rmac_vni_mac_cmd);
2982 install_element(VIEW_NODE, &show_evpn_rmac_vni_cmd);
2983 install_element(VIEW_NODE, &show_evpn_rmac_vni_all_cmd);
2984 install_element(VIEW_NODE, &show_evpn_nh_vni_ip_cmd);
2985 install_element(VIEW_NODE, &show_evpn_nh_vni_cmd);
2986 install_element(VIEW_NODE, &show_evpn_nh_vni_all_cmd);
d62a17ae 2987 install_element(VIEW_NODE, &show_evpn_mac_vni_cmd);
2988 install_element(VIEW_NODE, &show_evpn_mac_vni_all_cmd);
cffe7580 2989 install_element(VIEW_NODE, &show_evpn_mac_vni_all_detail_cmd);
d62a17ae 2990 install_element(VIEW_NODE, &show_evpn_mac_vni_all_vtep_cmd);
2991 install_element(VIEW_NODE, &show_evpn_mac_vni_mac_cmd);
2992 install_element(VIEW_NODE, &show_evpn_mac_vni_vtep_cmd);
1374d4db
CS
2993 install_element(VIEW_NODE, &show_evpn_mac_vni_dad_cmd);
2994 install_element(VIEW_NODE, &show_evpn_mac_vni_all_dad_cmd);
d62a17ae 2995 install_element(VIEW_NODE, &show_evpn_neigh_vni_cmd);
2996 install_element(VIEW_NODE, &show_evpn_neigh_vni_all_cmd);
e3fac919 2997 install_element(VIEW_NODE, &show_evpn_neigh_vni_all_detail_cmd);
d62a17ae 2998 install_element(VIEW_NODE, &show_evpn_neigh_vni_neigh_cmd);
2999 install_element(VIEW_NODE, &show_evpn_neigh_vni_vtep_cmd);
1374d4db
CS
3000 install_element(VIEW_NODE, &show_evpn_neigh_vni_dad_cmd);
3001 install_element(VIEW_NODE, &show_evpn_neigh_vni_all_dad_cmd);
09de9258 3002 install_element(ENABLE_NODE, &clear_evpn_dup_addr_cmd);
b7cfce93 3003
586f4ccf
PG
3004 install_element(VIEW_NODE, &show_pbr_ipset_cmd);
3005 install_element(VIEW_NODE, &show_pbr_iptable_cmd);
3006
e8d26197
MK
3007 install_element(CONFIG_NODE, &default_vrf_vni_mapping_cmd);
3008 install_element(CONFIG_NODE, &no_default_vrf_vni_mapping_cmd);
b7cfce93
MK
3009 install_element(VRF_NODE, &vrf_vni_mapping_cmd);
3010 install_element(VRF_NODE, &no_vrf_vni_mapping_cmd);
4060008b 3011
1d11b21f
MS
3012 install_element(VIEW_NODE, &show_dataplane_cmd);
3013 install_element(VIEW_NODE, &show_dataplane_providers_cmd);
91f16812
MS
3014 install_element(CONFIG_NODE, &zebra_dplane_queue_limit_cmd);
3015 install_element(CONFIG_NODE, &no_zebra_dplane_queue_limit_cmd);
ac5aa23f
DS
3016
3017 install_element(VIEW_NODE, &zebra_show_routing_tables_summary_cmd);
718e3744 3018}