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