]> git.proxmox.com Git - mirror_frr.git/blob - ospfd/ospf_vty.c
Merge pull request #8465 from opensourcerouting/vtysh-scan-snafu
[mirror_frr.git] / ospfd / ospf_vty.c
1 /* OSPF VTY interface.
2 * Copyright (C) 2005 6WIND <alain.ritoux@6wind.com>
3 * Copyright (C) 2000 Toshiaki Takada
4 *
5 * This file is part of GNU Zebra.
6 *
7 * GNU Zebra is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2, or (at your option) any
10 * later version.
11 *
12 * GNU Zebra is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program; see the file COPYING; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 #include <zebra.h>
23 #include <string.h>
24
25 #include "printfrr.h"
26 #include "monotime.h"
27 #include "memory.h"
28 #include "thread.h"
29 #include "prefix.h"
30 #include "table.h"
31 #include "vty.h"
32 #include "command.h"
33 #include "plist.h"
34 #include "log.h"
35 #include "zclient.h"
36 #include <lib/json.h>
37 #include "defaults.h"
38 #include "lib/printfrr.h"
39
40 #include "ospfd/ospfd.h"
41 #include "ospfd/ospf_asbr.h"
42 #include "ospfd/ospf_lsa.h"
43 #include "ospfd/ospf_lsdb.h"
44 #include "ospfd/ospf_ism.h"
45 #include "ospfd/ospf_interface.h"
46 #include "ospfd/ospf_nsm.h"
47 #include "ospfd/ospf_neighbor.h"
48 #include "ospfd/ospf_flood.h"
49 #include "ospfd/ospf_abr.h"
50 #include "ospfd/ospf_spf.h"
51 #include "ospfd/ospf_route.h"
52 #include "ospfd/ospf_zebra.h"
53 /*#include "ospfd/ospf_routemap.h" */
54 #include "ospfd/ospf_vty.h"
55 #include "ospfd/ospf_dump.h"
56 #include "ospfd/ospf_bfd.h"
57 #include "ospfd/ospf_ldp_sync.h"
58
59
60 FRR_CFG_DEFAULT_BOOL(OSPF_LOG_ADJACENCY_CHANGES,
61 { .val_bool = true, .match_profile = "datacenter", },
62 { .val_bool = false },
63 );
64
65 static const char *const ospf_network_type_str[] = {
66 "Null", "POINTOPOINT", "BROADCAST", "NBMA", "POINTOMULTIPOINT",
67 "VIRTUALLINK", "LOOPBACK"};
68
69 /* Utility functions. */
70 int str2area_id(const char *str, struct in_addr *area_id, int *area_id_fmt)
71 {
72 char *ep;
73
74 area_id->s_addr = htonl(strtoul(str, &ep, 10));
75 if (*ep && !inet_aton(str, area_id))
76 return -1;
77
78 *area_id_fmt =
79 *ep ? OSPF_AREA_ID_FMT_DOTTEDQUAD : OSPF_AREA_ID_FMT_DECIMAL;
80
81 return 0;
82 }
83
84 static void area_id2str(char *buf, int length, struct in_addr *area_id,
85 int area_id_fmt)
86 {
87 if (area_id_fmt == OSPF_AREA_ID_FMT_DOTTEDQUAD)
88 inet_ntop(AF_INET, area_id, buf, length);
89 else
90 snprintf(buf, length, "%lu",
91 (unsigned long)ntohl(area_id->s_addr));
92 }
93
94 static int str2metric(const char *str, int *metric)
95 {
96 /* Sanity check. */
97 if (str == NULL)
98 return 0;
99
100 *metric = strtol(str, NULL, 10);
101 if (*metric < 0 || *metric > 16777214) {
102 /* vty_out (vty, "OSPF metric value is invalid\n"); */
103 return 0;
104 }
105
106 return 1;
107 }
108
109 static int str2metric_type(const char *str, int *metric_type)
110 {
111 /* Sanity check. */
112 if (str == NULL)
113 return 0;
114
115 if (strncmp(str, "1", 1) == 0)
116 *metric_type = EXTERNAL_METRIC_TYPE_1;
117 else if (strncmp(str, "2", 1) == 0)
118 *metric_type = EXTERNAL_METRIC_TYPE_2;
119 else
120 return 0;
121
122 return 1;
123 }
124
125 int ospf_oi_count(struct interface *ifp)
126 {
127 struct route_node *rn;
128 int i = 0;
129
130 for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn))
131 if (rn->info)
132 i++;
133
134 return i;
135 }
136
137 #define OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf) \
138 if (argv_find(argv, argc, "vrf", &idx_vrf)) { \
139 vrf_name = argv[idx_vrf + 1]->arg; \
140 all_vrf = strmatch(vrf_name, "all"); \
141 }
142
143 static int ospf_router_cmd_parse(struct vty *vty, struct cmd_token *argv[],
144 const int argc, unsigned short *instance,
145 const char **vrf_name)
146 {
147 int idx_vrf = 0, idx_inst = 0;
148
149 *instance = 0;
150 if (argv_find(argv, argc, "(1-65535)", &idx_inst)) {
151 if (ospf_instance == 0) {
152 vty_out(vty,
153 "%% OSPF is not running in instance mode\n");
154 return CMD_WARNING_CONFIG_FAILED;
155 }
156
157 *instance = strtoul(argv[idx_inst]->arg, NULL, 10);
158 }
159
160 *vrf_name = NULL;
161 if (argv_find(argv, argc, "vrf", &idx_vrf)) {
162 if (ospf_instance != 0) {
163 vty_out(vty,
164 "%% VRF is not supported in instance mode\n");
165 return CMD_WARNING_CONFIG_FAILED;
166 }
167
168 *vrf_name = argv[idx_vrf + 1]->arg;
169 if (*vrf_name && strmatch(*vrf_name, VRF_DEFAULT_NAME))
170 *vrf_name = NULL;
171 }
172
173 return CMD_SUCCESS;
174 }
175
176 static void ospf_show_vrf_name(struct ospf *ospf, struct vty *vty,
177 json_object *json, uint8_t use_vrf)
178 {
179 if (use_vrf) {
180 if (json) {
181 if (ospf->vrf_id == VRF_DEFAULT)
182 json_object_string_add(json, "vrfName",
183 "default");
184 else
185 json_object_string_add(json, "vrfName",
186 ospf->name);
187 json_object_int_add(json, "vrfId", ospf->vrf_id);
188 } else {
189 if (ospf->vrf_id == VRF_DEFAULT)
190 vty_out(vty, "VRF Name: %s\n", "default");
191 else if (ospf->name)
192 vty_out(vty, "VRF Name: %s\n", ospf->name);
193 }
194 }
195 }
196
197 #ifndef VTYSH_EXTRACT_PL
198 #include "ospfd/ospf_vty_clippy.c"
199 #endif
200
201 DEFUN_NOSH (router_ospf,
202 router_ospf_cmd,
203 "router ospf [{(1-65535)|vrf NAME}]",
204 "Enable a routing process\n"
205 "Start OSPF configuration\n"
206 "Instance ID\n"
207 VRF_CMD_HELP_STR)
208 {
209 unsigned short instance;
210 const char *vrf_name;
211 bool created = false;
212 struct ospf *ospf;
213 int ret;
214
215 ret = ospf_router_cmd_parse(vty, argv, argc, &instance, &vrf_name);
216 if (ret != CMD_SUCCESS)
217 return ret;
218
219 if (instance != ospf_instance) {
220 VTY_PUSH_CONTEXT_NULL(OSPF_NODE);
221 return CMD_NOT_MY_INSTANCE;
222 }
223
224 ospf = ospf_get(instance, vrf_name, &created);
225
226 if (created)
227 if (DFLT_OSPF_LOG_ADJACENCY_CHANGES)
228 SET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES);
229
230 if (IS_DEBUG_OSPF_EVENT)
231 zlog_debug(
232 "Config command 'router ospf %d' received, vrf %s id %u oi_running %u",
233 ospf->instance, ospf->name ? ospf->name : "NIL",
234 ospf->vrf_id, ospf->oi_running);
235
236 VTY_PUSH_CONTEXT(OSPF_NODE, ospf);
237
238 return ret;
239 }
240
241 DEFUN (no_router_ospf,
242 no_router_ospf_cmd,
243 "no router ospf [{(1-65535)|vrf NAME}]",
244 NO_STR
245 "Enable a routing process\n"
246 "Start OSPF configuration\n"
247 "Instance ID\n"
248 VRF_CMD_HELP_STR)
249 {
250 unsigned short instance;
251 const char *vrf_name;
252 struct ospf *ospf;
253 int ret;
254
255 ret = ospf_router_cmd_parse(vty, argv, argc, &instance, &vrf_name);
256 if (ret != CMD_SUCCESS)
257 return ret;
258
259 if (instance != ospf_instance)
260 return CMD_NOT_MY_INSTANCE;
261
262 ospf = ospf_lookup(instance, vrf_name);
263 if (ospf)
264 ospf_finish(ospf);
265 else
266 ret = CMD_WARNING_CONFIG_FAILED;
267
268 return ret;
269 }
270
271
272 DEFPY (ospf_router_id,
273 ospf_router_id_cmd,
274 "ospf router-id A.B.C.D",
275 "OSPF specific commands\n"
276 "router-id for the OSPF process\n"
277 "OSPF router-id in IP address format\n")
278 {
279 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
280
281 struct listnode *node;
282 struct ospf_area *area;
283
284 ospf->router_id_static = router_id;
285
286 for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area))
287 if (area->full_nbrs) {
288 vty_out(vty,
289 "For this router-id change to take effect, use “clear ip ospf process” command\n");
290 return CMD_SUCCESS;
291 }
292
293 ospf_router_id_update(ospf);
294
295 return CMD_SUCCESS;
296 }
297
298 DEFUN_HIDDEN (ospf_router_id_old,
299 ospf_router_id_old_cmd,
300 "router-id A.B.C.D",
301 "router-id for the OSPF process\n"
302 "OSPF router-id in IP address format\n")
303 {
304 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
305 int idx_ipv4 = 1;
306 struct listnode *node;
307 struct ospf_area *area;
308 struct in_addr router_id;
309 int ret;
310
311 ret = inet_aton(argv[idx_ipv4]->arg, &router_id);
312 if (!ret) {
313 vty_out(vty, "Please specify Router ID by A.B.C.D\n");
314 return CMD_WARNING_CONFIG_FAILED;
315 }
316
317 ospf->router_id_static = router_id;
318
319 for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area))
320 if (area->full_nbrs) {
321 vty_out(vty,
322 "For this router-id change to take effect, use “clear ip ospf process” command\n");
323 return CMD_SUCCESS;
324 }
325
326 ospf_router_id_update(ospf);
327
328 return CMD_SUCCESS;
329 }
330
331 DEFPY (no_ospf_router_id,
332 no_ospf_router_id_cmd,
333 "no ospf router-id [A.B.C.D]",
334 NO_STR
335 "OSPF specific commands\n"
336 "router-id for the OSPF process\n"
337 "OSPF router-id in IP address format\n")
338 {
339 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
340 struct listnode *node;
341 struct ospf_area *area;
342
343 if (router_id_str) {
344 if (!IPV4_ADDR_SAME(&ospf->router_id_static, &router_id)) {
345 vty_out(vty, "%% OSPF router-id doesn't match\n");
346 return CMD_WARNING_CONFIG_FAILED;
347 }
348 }
349
350 ospf->router_id_static.s_addr = 0;
351
352 for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area))
353 if (area->full_nbrs) {
354 vty_out(vty,
355 "For this router-id change to take effect, use “clear ip ospf process” command\n");
356 return CMD_SUCCESS;
357 }
358
359 ospf_router_id_update(ospf);
360
361 return CMD_SUCCESS;
362 }
363
364
365 static void ospf_passive_interface_default(struct ospf *ospf, uint8_t newval)
366 {
367 struct vrf *vrf = vrf_lookup_by_id(ospf->vrf_id);
368 struct listnode *ln;
369 struct interface *ifp;
370 struct ospf_interface *oi;
371
372 ospf->passive_interface_default = newval;
373
374 FOR_ALL_INTERFACES (vrf, ifp) {
375 if (ifp && OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(ifp),
376 passive_interface))
377 UNSET_IF_PARAM(IF_DEF_PARAMS(ifp), passive_interface);
378 }
379 for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, ln, oi)) {
380 if (OSPF_IF_PARAM_CONFIGURED(oi->params, passive_interface))
381 UNSET_IF_PARAM(oi->params, passive_interface);
382 /* update multicast memberships */
383 ospf_if_set_multicast(oi);
384 }
385 }
386
387 static void ospf_passive_interface_update_addr(struct ospf *ospf,
388 struct interface *ifp,
389 struct ospf_if_params *params,
390 uint8_t value,
391 struct in_addr addr)
392 {
393 uint8_t dflt;
394
395 params->passive_interface = value;
396 if (params != IF_DEF_PARAMS(ifp)) {
397 if (OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(ifp),
398 passive_interface))
399 dflt = IF_DEF_PARAMS(ifp)->passive_interface;
400 else
401 dflt = ospf->passive_interface_default;
402
403 if (value != dflt)
404 SET_IF_PARAM(params, passive_interface);
405 else
406 UNSET_IF_PARAM(params, passive_interface);
407
408 ospf_free_if_params(ifp, addr);
409 ospf_if_update_params(ifp, addr);
410 }
411 }
412
413 static void ospf_passive_interface_update(struct ospf *ospf,
414 struct interface *ifp,
415 struct ospf_if_params *params,
416 uint8_t value)
417 {
418 params->passive_interface = value;
419 if (params == IF_DEF_PARAMS(ifp)) {
420 if (value != ospf->passive_interface_default)
421 SET_IF_PARAM(params, passive_interface);
422 else
423 UNSET_IF_PARAM(params, passive_interface);
424 }
425 }
426
427 DEFUN (ospf_passive_interface,
428 ospf_passive_interface_addr_cmd,
429 "passive-interface <IFNAME [A.B.C.D]|default>",
430 "Suppress routing updates on an interface\n"
431 "Interface's name\n"
432 "IPv4 address\n"
433 "Suppress routing updates on interfaces by default\n")
434 {
435 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
436 int idx_ipv4 = 2;
437 struct interface *ifp = NULL;
438 struct in_addr addr = {.s_addr = INADDR_ANY};
439 int ret;
440 struct ospf_if_params *params;
441 struct route_node *rn;
442
443 if (strmatch(argv[1]->text, "default")) {
444 ospf_passive_interface_default(ospf, OSPF_IF_PASSIVE);
445 return CMD_SUCCESS;
446 }
447 if (ospf->vrf_id != VRF_UNKNOWN)
448 ifp = if_get_by_name(argv[1]->arg, ospf->vrf_id);
449
450 if (ifp == NULL) {
451 vty_out(vty, "interface %s not found.\n", (char *)argv[1]->arg);
452 return CMD_WARNING_CONFIG_FAILED;
453 }
454
455 params = IF_DEF_PARAMS(ifp);
456
457 if (argc == 3) {
458 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
459 if (!ret) {
460 vty_out(vty,
461 "Please specify interface address by A.B.C.D\n");
462 return CMD_WARNING_CONFIG_FAILED;
463 }
464
465 params = ospf_get_if_params(ifp, addr);
466 ospf_if_update_params(ifp, addr);
467 ospf_passive_interface_update_addr(ospf, ifp, params,
468 OSPF_IF_PASSIVE, addr);
469 }
470
471 ospf_passive_interface_update(ospf, ifp, params, OSPF_IF_PASSIVE);
472
473 /* XXX We should call ospf_if_set_multicast on exactly those
474 * interfaces for which the passive property changed. It is too much
475 * work to determine this set, so we do this for every interface.
476 * This is safe and reasonable because ospf_if_set_multicast uses a
477 * record of joined groups to avoid systems calls if the desired
478 * memberships match the current memership.
479 */
480
481 for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) {
482 struct ospf_interface *oi = rn->info;
483
484 if (oi && (OSPF_IF_PARAM(oi, passive_interface)
485 == OSPF_IF_PASSIVE))
486 ospf_if_set_multicast(oi);
487 }
488 /*
489 * XXX It is not clear what state transitions the interface needs to
490 * undergo when going from active to passive. Fixing this will
491 * require precise identification of interfaces having such a
492 * transition.
493 */
494
495 return CMD_SUCCESS;
496 }
497
498 DEFUN (no_ospf_passive_interface,
499 no_ospf_passive_interface_addr_cmd,
500 "no passive-interface <IFNAME [A.B.C.D]|default>",
501 NO_STR
502 "Allow routing updates on an interface\n"
503 "Interface's name\n"
504 "IPv4 address\n"
505 "Allow routing updates on interfaces by default\n")
506 {
507 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
508 int idx_ipv4 = 3;
509 struct interface *ifp = NULL;
510 struct in_addr addr = {.s_addr = INADDR_ANY};
511 struct ospf_if_params *params;
512 int ret;
513 struct route_node *rn;
514
515 if (strmatch(argv[2]->text, "default")) {
516 ospf_passive_interface_default(ospf, OSPF_IF_ACTIVE);
517 return CMD_SUCCESS;
518 }
519
520 if (ospf->vrf_id != VRF_UNKNOWN)
521 ifp = if_get_by_name(argv[2]->arg, ospf->vrf_id);
522
523 if (ifp == NULL) {
524 vty_out(vty, "interface %s not found.\n", (char *)argv[2]->arg);
525 return CMD_WARNING_CONFIG_FAILED;
526 }
527
528 params = IF_DEF_PARAMS(ifp);
529
530 if (argc == 4) {
531 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
532 if (!ret) {
533 vty_out(vty,
534 "Please specify interface address by A.B.C.D\n");
535 return CMD_WARNING_CONFIG_FAILED;
536 }
537
538 params = ospf_lookup_if_params(ifp, addr);
539 if (params == NULL)
540 return CMD_SUCCESS;
541 ospf_passive_interface_update_addr(ospf, ifp, params,
542 OSPF_IF_ACTIVE, addr);
543 }
544 ospf_passive_interface_update(ospf, ifp, params, OSPF_IF_ACTIVE);
545
546 /* XXX We should call ospf_if_set_multicast on exactly those
547 * interfaces for which the passive property changed. It is too much
548 * work to determine this set, so we do this for every interface.
549 * This is safe and reasonable because ospf_if_set_multicast uses a
550 * record of joined groups to avoid systems calls if the desired
551 * memberships match the current memership.
552 */
553 for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) {
554 struct ospf_interface *oi = rn->info;
555
556 if (oi
557 && (OSPF_IF_PARAM(oi, passive_interface) == OSPF_IF_ACTIVE))
558 ospf_if_set_multicast(oi);
559 }
560
561 return CMD_SUCCESS;
562 }
563
564
565 DEFUN (ospf_network_area,
566 ospf_network_area_cmd,
567 "network A.B.C.D/M area <A.B.C.D|(0-4294967295)>",
568 "Enable routing on an IP network\n"
569 "OSPF network prefix\n"
570 "Set the OSPF area ID\n"
571 "OSPF area ID in IP address format\n"
572 "OSPF area ID as a decimal value\n")
573 {
574 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
575 int idx_ipv4_prefixlen = 1;
576 int idx_ipv4_number = 3;
577 struct prefix_ipv4 p;
578 struct in_addr area_id;
579 int ret, format;
580 uint32_t count;
581
582 if (ospf->instance) {
583 vty_out(vty,
584 "The network command is not supported in multi-instance ospf\n");
585 return CMD_WARNING_CONFIG_FAILED;
586 }
587
588 count = ospf_count_area_params(ospf);
589 if (count > 0) {
590 vty_out(vty,
591 "Please remove all ip ospf area x.x.x.x commands first.\n");
592 if (IS_DEBUG_OSPF_EVENT)
593 zlog_debug(
594 "%s ospf vrf %s num of %u ip ospf area x config",
595 __func__, ospf->name ? ospf->name : "NIL",
596 count);
597 return CMD_WARNING_CONFIG_FAILED;
598 }
599
600 /* Get network prefix and Area ID. */
601 str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p);
602 VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg);
603
604 ret = ospf_network_set(ospf, &p, area_id, format);
605 if (ret == 0) {
606 vty_out(vty, "There is already same network statement.\n");
607 return CMD_WARNING_CONFIG_FAILED;
608 }
609
610 return CMD_SUCCESS;
611 }
612
613 DEFUN (no_ospf_network_area,
614 no_ospf_network_area_cmd,
615 "no network A.B.C.D/M area <A.B.C.D|(0-4294967295)>",
616 NO_STR
617 "Enable routing on an IP network\n"
618 "OSPF network prefix\n"
619 "Set the OSPF area ID\n"
620 "OSPF area ID in IP address format\n"
621 "OSPF area ID as a decimal value\n")
622 {
623 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
624 int idx_ipv4_prefixlen = 2;
625 int idx_ipv4_number = 4;
626 struct prefix_ipv4 p;
627 struct in_addr area_id;
628 int ret, format;
629
630 if (ospf->instance) {
631 vty_out(vty,
632 "The network command is not supported in multi-instance ospf\n");
633 return CMD_WARNING_CONFIG_FAILED;
634 }
635
636 /* Get network prefix and Area ID. */
637 str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p);
638 VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg);
639
640 ret = ospf_network_unset(ospf, &p, area_id);
641 if (ret == 0) {
642 vty_out(vty,
643 "Can't find specified network area configuration.\n");
644 return CMD_WARNING_CONFIG_FAILED;
645 }
646
647 return CMD_SUCCESS;
648 }
649
650 DEFUN (ospf_area_range,
651 ospf_area_range_cmd,
652 "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M [advertise [cost (0-16777215)]]",
653 "OSPF area parameters\n"
654 "OSPF area ID in IP address format\n"
655 "OSPF area ID as a decimal value\n"
656 "Summarize routes matching address/mask (border routers only)\n"
657 "Area range prefix\n"
658 "Advertise this range (default)\n"
659 "User specified metric for this range\n"
660 "Advertised metric for this range\n")
661 {
662 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
663 int idx_ipv4_number = 1;
664 int idx_ipv4_prefixlen = 3;
665 int idx_cost = 6;
666 struct prefix_ipv4 p;
667 struct in_addr area_id;
668 int format;
669 uint32_t cost;
670
671 VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg);
672 str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p);
673
674 ospf_area_range_set(ospf, area_id, &p, OSPF_AREA_RANGE_ADVERTISE);
675 ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id),
676 format);
677 if (argc > 5) {
678 cost = strtoul(argv[idx_cost]->arg, NULL, 10);
679 ospf_area_range_cost_set(ospf, area_id, &p, cost);
680 }
681
682 return CMD_SUCCESS;
683 }
684
685 DEFUN (ospf_area_range_cost,
686 ospf_area_range_cost_cmd,
687 "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M cost (0-16777215)",
688 "OSPF area parameters\n"
689 "OSPF area ID in IP address format\n"
690 "OSPF area ID as a decimal value\n"
691 "Summarize routes matching address/mask (border routers only)\n"
692 "Area range prefix\n"
693 "User specified metric for this range\n"
694 "Advertised metric for this range\n")
695 {
696 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
697 int idx_ipv4_number = 1;
698 int idx_ipv4_prefixlen = 3;
699 int idx_cost = 5;
700 struct prefix_ipv4 p;
701 struct in_addr area_id;
702 int format;
703 uint32_t cost;
704
705 VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg);
706 str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p);
707
708 ospf_area_range_set(ospf, area_id, &p, OSPF_AREA_RANGE_ADVERTISE);
709 ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id),
710 format);
711
712 cost = strtoul(argv[idx_cost]->arg, NULL, 10);
713 ospf_area_range_cost_set(ospf, area_id, &p, cost);
714
715 return CMD_SUCCESS;
716 }
717
718 DEFUN (ospf_area_range_not_advertise,
719 ospf_area_range_not_advertise_cmd,
720 "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M not-advertise",
721 "OSPF area parameters\n"
722 "OSPF area ID in IP address format\n"
723 "OSPF area ID as a decimal value\n"
724 "Summarize routes matching address/mask (border routers only)\n"
725 "Area range prefix\n"
726 "DoNotAdvertise this range\n")
727 {
728 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
729 int idx_ipv4_number = 1;
730 int idx_ipv4_prefixlen = 3;
731 struct prefix_ipv4 p;
732 struct in_addr area_id;
733 int format;
734
735 VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg);
736 str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p);
737
738 ospf_area_range_set(ospf, area_id, &p, 0);
739 ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id),
740 format);
741 ospf_area_range_substitute_unset(ospf, area_id, &p);
742
743 return CMD_SUCCESS;
744 }
745
746 DEFUN (no_ospf_area_range,
747 no_ospf_area_range_cmd,
748 "no area <A.B.C.D|(0-4294967295)> range A.B.C.D/M [<cost (0-16777215)|advertise [cost (0-16777215)]|not-advertise>]",
749 NO_STR
750 "OSPF area parameters\n"
751 "OSPF area ID in IP address format\n"
752 "OSPF area ID as a decimal value\n"
753 "Summarize routes matching address/mask (border routers only)\n"
754 "Area range prefix\n"
755 "User specified metric for this range\n"
756 "Advertised metric for this range\n"
757 "Advertise this range (default)\n"
758 "User specified metric for this range\n"
759 "Advertised metric for this range\n"
760 "DoNotAdvertise this range\n")
761 {
762 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
763 int idx_ipv4_number = 2;
764 int idx_ipv4_prefixlen = 4;
765 struct prefix_ipv4 p;
766 struct in_addr area_id;
767 int format;
768
769 VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg);
770 str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p);
771
772 ospf_area_range_unset(ospf, area_id, &p);
773
774 return CMD_SUCCESS;
775 }
776
777 DEFUN (ospf_area_range_substitute,
778 ospf_area_range_substitute_cmd,
779 "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M substitute A.B.C.D/M",
780 "OSPF area parameters\n"
781 "OSPF area ID in IP address format\n"
782 "OSPF area ID as a decimal value\n"
783 "Summarize routes matching address/mask (border routers only)\n"
784 "Area range prefix\n"
785 "Announce area range as another prefix\n"
786 "Network prefix to be announced instead of range\n")
787 {
788 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
789 int idx_ipv4_number = 1;
790 int idx_ipv4_prefixlen = 3;
791 int idx_ipv4_prefixlen_2 = 5;
792 struct prefix_ipv4 p, s;
793 struct in_addr area_id;
794 int format;
795
796 VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg);
797 str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p);
798 str2prefix_ipv4(argv[idx_ipv4_prefixlen_2]->arg, &s);
799
800 ospf_area_range_substitute_set(ospf, area_id, &p, &s);
801 ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id),
802 format);
803
804 return CMD_SUCCESS;
805 }
806
807 DEFUN (no_ospf_area_range_substitute,
808 no_ospf_area_range_substitute_cmd,
809 "no area <A.B.C.D|(0-4294967295)> range A.B.C.D/M substitute A.B.C.D/M",
810 NO_STR
811 "OSPF area parameters\n"
812 "OSPF area ID in IP address format\n"
813 "OSPF area ID as a decimal value\n"
814 "Summarize routes matching address/mask (border routers only)\n"
815 "Area range prefix\n"
816 "Announce area range as another prefix\n"
817 "Network prefix to be announced instead of range\n")
818 {
819 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
820 int idx_ipv4_number = 2;
821 int idx_ipv4_prefixlen = 4;
822 int idx_ipv4_prefixlen_2 = 6;
823 struct prefix_ipv4 p, s;
824 struct in_addr area_id;
825 int format;
826
827 VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg);
828 str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p);
829 str2prefix_ipv4(argv[idx_ipv4_prefixlen_2]->arg, &s);
830
831 ospf_area_range_substitute_unset(ospf, area_id, &p);
832
833 return CMD_SUCCESS;
834 }
835
836
837 /* Command Handler Logic in VLink stuff is delicate!!
838
839 ALTER AT YOUR OWN RISK!!!!
840
841 Various dummy values are used to represent 'NoChange' state for
842 VLink configuration NOT being changed by a VLink command, and
843 special syntax is used within the command strings so that the
844 typed in command verbs can be seen in the configuration command
845 bacckend handler. This is to drastically reduce the verbeage
846 required to coe up with a reasonably compatible Cisco VLink command
847
848 - Matthew Grant <grantma@anathoth.gen.nz>
849 Wed, 21 Feb 2001 15:13:52 +1300
850 */
851
852 /* Configuration data for virtual links
853 */
854 struct ospf_vl_config_data {
855 struct vty *vty; /* vty stuff */
856 struct in_addr area_id; /* area ID from command line */
857 int area_id_fmt; /* command line area ID format */
858 struct in_addr vl_peer; /* command line vl_peer */
859 int auth_type; /* Authehntication type, if given */
860 char *auth_key; /* simple password if present */
861 int crypto_key_id; /* Cryptographic key ID */
862 char *md5_key; /* MD5 authentication key */
863 int hello_interval; /* Obvious what these are... */
864 int retransmit_interval;
865 int transmit_delay;
866 int dead_interval;
867 };
868
869 static void ospf_vl_config_data_init(struct ospf_vl_config_data *vl_config,
870 struct vty *vty)
871 {
872 memset(vl_config, 0, sizeof(struct ospf_vl_config_data));
873 vl_config->auth_type = OSPF_AUTH_CMD_NOTSEEN;
874 vl_config->vty = vty;
875 }
876
877 static struct ospf_vl_data *
878 ospf_find_vl_data(struct ospf *ospf, struct ospf_vl_config_data *vl_config)
879 {
880 struct ospf_area *area;
881 struct ospf_vl_data *vl_data;
882 struct vty *vty;
883 struct in_addr area_id;
884
885 vty = vl_config->vty;
886 area_id = vl_config->area_id;
887
888 if (area_id.s_addr == OSPF_AREA_BACKBONE) {
889 vty_out(vty,
890 "Configuring VLs over the backbone is not allowed\n");
891 return NULL;
892 }
893 area = ospf_area_get(ospf, area_id);
894 ospf_area_display_format_set(ospf, area, vl_config->area_id_fmt);
895
896 if (area->external_routing != OSPF_AREA_DEFAULT) {
897 if (vl_config->area_id_fmt == OSPF_AREA_ID_FMT_DOTTEDQUAD)
898 vty_out(vty, "Area %pI4 is %s\n", &area_id,
899 area->external_routing == OSPF_AREA_NSSA
900 ? "nssa"
901 : "stub");
902 else
903 vty_out(vty, "Area %ld is %s\n",
904 (unsigned long)ntohl(area_id.s_addr),
905 area->external_routing == OSPF_AREA_NSSA
906 ? "nssa"
907 : "stub");
908 return NULL;
909 }
910
911 if ((vl_data = ospf_vl_lookup(ospf, area, vl_config->vl_peer))
912 == NULL) {
913 vl_data = ospf_vl_data_new(area, vl_config->vl_peer);
914 if (vl_data->vl_oi == NULL) {
915 vl_data->vl_oi = ospf_vl_new(ospf, vl_data);
916 ospf_vl_add(ospf, vl_data);
917 ospf_spf_calculate_schedule(ospf,
918 SPF_FLAG_CONFIG_CHANGE);
919 }
920 }
921 return vl_data;
922 }
923
924
925 static int ospf_vl_set_security(struct ospf_vl_data *vl_data,
926 struct ospf_vl_config_data *vl_config)
927 {
928 struct crypt_key *ck;
929 struct vty *vty;
930 struct interface *ifp = vl_data->vl_oi->ifp;
931
932 vty = vl_config->vty;
933
934 if (vl_config->auth_type != OSPF_AUTH_CMD_NOTSEEN) {
935 SET_IF_PARAM(IF_DEF_PARAMS(ifp), auth_type);
936 IF_DEF_PARAMS(ifp)->auth_type = vl_config->auth_type;
937 }
938
939 if (vl_config->auth_key) {
940 memset(IF_DEF_PARAMS(ifp)->auth_simple, 0,
941 OSPF_AUTH_SIMPLE_SIZE + 1);
942 strlcpy((char *)IF_DEF_PARAMS(ifp)->auth_simple,
943 vl_config->auth_key,
944 sizeof(IF_DEF_PARAMS(ifp)->auth_simple));
945 } else if (vl_config->md5_key) {
946 if (ospf_crypt_key_lookup(IF_DEF_PARAMS(ifp)->auth_crypt,
947 vl_config->crypto_key_id)
948 != NULL) {
949 vty_out(vty, "OSPF: Key %d already exists\n",
950 vl_config->crypto_key_id);
951 return CMD_WARNING;
952 }
953 ck = ospf_crypt_key_new();
954 ck->key_id = vl_config->crypto_key_id;
955 memset(ck->auth_key, 0, OSPF_AUTH_MD5_SIZE + 1);
956 strlcpy((char *)ck->auth_key, vl_config->md5_key,
957 sizeof(ck->auth_key));
958
959 ospf_crypt_key_add(IF_DEF_PARAMS(ifp)->auth_crypt, ck);
960 } else if (vl_config->crypto_key_id != 0) {
961 /* Delete a key */
962
963 if (ospf_crypt_key_lookup(IF_DEF_PARAMS(ifp)->auth_crypt,
964 vl_config->crypto_key_id)
965 == NULL) {
966 vty_out(vty, "OSPF: Key %d does not exist\n",
967 vl_config->crypto_key_id);
968 return CMD_WARNING_CONFIG_FAILED;
969 }
970
971 ospf_crypt_key_delete(IF_DEF_PARAMS(ifp)->auth_crypt,
972 vl_config->crypto_key_id);
973 }
974
975 return CMD_SUCCESS;
976 }
977
978 static int ospf_vl_set_timers(struct ospf_vl_data *vl_data,
979 struct ospf_vl_config_data *vl_config)
980 {
981 struct interface *ifp = vl_data->vl_oi->ifp;
982 /* Virtual Link data initialised to defaults, so only set
983 if a value given */
984 if (vl_config->hello_interval) {
985 SET_IF_PARAM(IF_DEF_PARAMS(ifp), v_hello);
986 IF_DEF_PARAMS(ifp)->v_hello = vl_config->hello_interval;
987 }
988
989 if (vl_config->dead_interval) {
990 SET_IF_PARAM(IF_DEF_PARAMS(ifp), v_wait);
991 IF_DEF_PARAMS(ifp)->v_wait = vl_config->dead_interval;
992 }
993
994 if (vl_config->retransmit_interval) {
995 SET_IF_PARAM(IF_DEF_PARAMS(ifp), retransmit_interval);
996 IF_DEF_PARAMS(ifp)->retransmit_interval =
997 vl_config->retransmit_interval;
998 }
999
1000 if (vl_config->transmit_delay) {
1001 SET_IF_PARAM(IF_DEF_PARAMS(ifp), transmit_delay);
1002 IF_DEF_PARAMS(ifp)->transmit_delay = vl_config->transmit_delay;
1003 }
1004
1005 return CMD_SUCCESS;
1006 }
1007
1008
1009 /* The business end of all of the above */
1010 static int ospf_vl_set(struct ospf *ospf, struct ospf_vl_config_data *vl_config)
1011 {
1012 struct ospf_vl_data *vl_data;
1013 int ret;
1014
1015 vl_data = ospf_find_vl_data(ospf, vl_config);
1016 if (!vl_data)
1017 return CMD_WARNING_CONFIG_FAILED;
1018
1019 /* Process this one first as it can have a fatal result, which can
1020 only logically occur if the virtual link exists already
1021 Thus a command error does not result in a change to the
1022 running configuration such as unexpectedly altered timer
1023 values etc.*/
1024 ret = ospf_vl_set_security(vl_data, vl_config);
1025 if (ret != CMD_SUCCESS)
1026 return ret;
1027
1028 /* Set any time based parameters, these area already range checked */
1029
1030 ret = ospf_vl_set_timers(vl_data, vl_config);
1031 if (ret != CMD_SUCCESS)
1032 return ret;
1033
1034 return CMD_SUCCESS;
1035 }
1036
1037 /* This stuff exists to make specifying all the alias commands A LOT simpler
1038 */
1039 #define VLINK_HELPSTR_IPADDR \
1040 "OSPF area parameters\n" \
1041 "OSPF area ID in IP address format\n" \
1042 "OSPF area ID as a decimal value\n" \
1043 "Configure a virtual link\n" \
1044 "Router ID of the remote ABR\n"
1045
1046 #define VLINK_HELPSTR_AUTHTYPE_SIMPLE \
1047 "Enable authentication on this virtual link\n" \
1048 "dummy string \n"
1049
1050 #define VLINK_HELPSTR_AUTHTYPE_ALL \
1051 VLINK_HELPSTR_AUTHTYPE_SIMPLE \
1052 "Use null authentication\n" \
1053 "Use message-digest authentication\n"
1054
1055 #define VLINK_HELPSTR_TIME_PARAM \
1056 "Time between HELLO packets\n" \
1057 "Seconds\n" \
1058 "Time between retransmitting lost link state advertisements\n" \
1059 "Seconds\n" \
1060 "Link state transmit delay\n" \
1061 "Seconds\n" \
1062 "Interval time after which a neighbor is declared down\n" \
1063 "Seconds\n"
1064
1065 #define VLINK_HELPSTR_AUTH_SIMPLE \
1066 "Authentication password (key)\n" \
1067 "The OSPF password (key)\n"
1068
1069 #define VLINK_HELPSTR_AUTH_MD5 \
1070 "Message digest authentication password (key)\n" \
1071 "Key ID\n" \
1072 "Use MD5 algorithm\n" \
1073 "The OSPF password (key)\n"
1074
1075 DEFUN (ospf_area_vlink,
1076 ospf_area_vlink_cmd,
1077 "area <A.B.C.D|(0-4294967295)> virtual-link A.B.C.D [authentication [<message-digest|null>]] [<message-digest-key (1-255) md5 KEY|authentication-key AUTH_KEY>]",
1078 VLINK_HELPSTR_IPADDR
1079 "Enable authentication on this virtual link\n"
1080 "Use message-digest authentication\n"
1081 "Use null authentication\n"
1082 VLINK_HELPSTR_AUTH_MD5
1083 VLINK_HELPSTR_AUTH_SIMPLE)
1084 {
1085 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
1086 int idx_ipv4_number = 1;
1087 int idx_ipv4 = 3;
1088 struct ospf_vl_config_data vl_config;
1089 char auth_key[OSPF_AUTH_SIMPLE_SIZE + 1];
1090 char md5_key[OSPF_AUTH_MD5_SIZE + 1];
1091 int ret;
1092 int idx = 0;
1093
1094 ospf_vl_config_data_init(&vl_config, vty);
1095
1096 /* Read off first 2 parameters and check them */
1097 ret = str2area_id(argv[idx_ipv4_number]->arg, &vl_config.area_id,
1098 &vl_config.area_id_fmt);
1099 if (ret < 0) {
1100 vty_out(vty, "OSPF area ID is invalid\n");
1101 return CMD_WARNING_CONFIG_FAILED;
1102 }
1103
1104 ret = inet_aton(argv[idx_ipv4]->arg, &vl_config.vl_peer);
1105 if (!ret) {
1106 vty_out(vty, "Please specify valid Router ID as a.b.c.d\n");
1107 return CMD_WARNING_CONFIG_FAILED;
1108 }
1109
1110 if (argc <= 4) {
1111 /* Thats all folks! - BUGS B. strikes again!!!*/
1112
1113 return ospf_vl_set(ospf, &vl_config);
1114 }
1115
1116 if (argv_find(argv, argc, "authentication", &idx)) {
1117 /* authentication - this option can only occur
1118 at start of command line */
1119 vl_config.auth_type = OSPF_AUTH_SIMPLE;
1120 }
1121
1122 if (argv_find(argv, argc, "message-digest", &idx)) {
1123 /* authentication message-digest */
1124 vl_config.auth_type = OSPF_AUTH_CRYPTOGRAPHIC;
1125 } else if (argv_find(argv, argc, "null", &idx)) {
1126 /* "authentication null" */
1127 vl_config.auth_type = OSPF_AUTH_NULL;
1128 }
1129
1130 if (argv_find(argv, argc, "message-digest-key", &idx)) {
1131 vl_config.md5_key = NULL;
1132 vl_config.crypto_key_id = strtol(argv[idx + 1]->arg, NULL, 10);
1133 if (vl_config.crypto_key_id < 0)
1134 return CMD_WARNING_CONFIG_FAILED;
1135
1136 strlcpy(md5_key, argv[idx + 3]->arg, sizeof(md5_key));
1137 vl_config.md5_key = md5_key;
1138 }
1139
1140 if (argv_find(argv, argc, "authentication-key", &idx)) {
1141 strlcpy(auth_key, argv[idx + 1]->arg, sizeof(auth_key));
1142 vl_config.auth_key = auth_key;
1143 }
1144
1145 /* Action configuration */
1146
1147 return ospf_vl_set(ospf, &vl_config);
1148 }
1149
1150 DEFUN (no_ospf_area_vlink,
1151 no_ospf_area_vlink_cmd,
1152 "no area <A.B.C.D|(0-4294967295)> virtual-link A.B.C.D [authentication [<message-digest|null>]] [<message-digest-key (1-255) md5 KEY|authentication-key AUTH_KEY>]",
1153 NO_STR
1154 VLINK_HELPSTR_IPADDR
1155 "Enable authentication on this virtual link\n"
1156 "Use message-digest authentication\n"
1157 "Use null authentication\n"
1158 VLINK_HELPSTR_AUTH_MD5
1159 VLINK_HELPSTR_AUTH_SIMPLE)
1160 {
1161 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
1162 int idx_ipv4_number = 2;
1163 int idx_ipv4 = 4;
1164 struct ospf_area *area;
1165 struct ospf_vl_config_data vl_config;
1166 struct ospf_vl_data *vl_data = NULL;
1167 char auth_key[OSPF_AUTH_SIMPLE_SIZE + 1];
1168 int idx = 0;
1169 int ret, format;
1170
1171 ospf_vl_config_data_init(&vl_config, vty);
1172
1173 ret = str2area_id(argv[idx_ipv4_number]->arg, &vl_config.area_id,
1174 &format);
1175 if (ret < 0) {
1176 vty_out(vty, "OSPF area ID is invalid\n");
1177 return CMD_WARNING_CONFIG_FAILED;
1178 }
1179
1180 area = ospf_area_lookup_by_area_id(ospf, vl_config.area_id);
1181 if (!area) {
1182 vty_out(vty, "Area does not exist\n");
1183 return CMD_WARNING_CONFIG_FAILED;
1184 }
1185
1186 ret = inet_aton(argv[idx_ipv4]->arg, &vl_config.vl_peer);
1187 if (!ret) {
1188 vty_out(vty, "Please specify valid Router ID as a.b.c.d\n");
1189 return CMD_WARNING_CONFIG_FAILED;
1190 }
1191
1192 vl_data = ospf_vl_lookup(ospf, area, vl_config.vl_peer);
1193 if (!vl_data) {
1194 vty_out(vty, "Virtual link does not exist\n");
1195 return CMD_WARNING_CONFIG_FAILED;
1196 }
1197
1198 if (argc <= 5) {
1199 /* Basic VLink no command */
1200 /* Thats all folks! - BUGS B. strikes again!!!*/
1201 ospf_vl_delete(ospf, vl_data);
1202 ospf_area_check_free(ospf, vl_config.area_id);
1203 return CMD_SUCCESS;
1204 }
1205
1206 /* If we are down here, we are reseting parameters */
1207 /* Deal with other parameters */
1208
1209 if (argv_find(argv, argc, "authentication", &idx)) {
1210 /* authentication - this option can only occur
1211 at start of command line */
1212 vl_config.auth_type = OSPF_AUTH_NOTSET;
1213 }
1214
1215 if (argv_find(argv, argc, "message-digest-key", &idx)) {
1216 vl_config.md5_key = NULL;
1217 vl_config.crypto_key_id = strtol(argv[idx + 1]->arg, NULL, 10);
1218 if (vl_config.crypto_key_id < 0)
1219 return CMD_WARNING_CONFIG_FAILED;
1220 }
1221
1222 if (argv_find(argv, argc, "authentication-key", &idx)) {
1223 /* Reset authentication-key to 0 */
1224 memset(auth_key, 0, OSPF_AUTH_SIMPLE_SIZE + 1);
1225 vl_config.auth_key = auth_key;
1226 }
1227
1228 /* Action configuration */
1229
1230 return ospf_vl_set(ospf, &vl_config);
1231 }
1232
1233 DEFUN (ospf_area_vlink_intervals,
1234 ospf_area_vlink_intervals_cmd,
1235 "area <A.B.C.D|(0-4294967295)> virtual-link A.B.C.D {hello-interval (1-65535)|retransmit-interval (1-65535)|transmit-delay (1-65535)|dead-interval (1-65535)}",
1236 VLINK_HELPSTR_IPADDR
1237 VLINK_HELPSTR_TIME_PARAM)
1238 {
1239 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
1240 struct ospf_vl_config_data vl_config;
1241 int ret = 0;
1242
1243 ospf_vl_config_data_init(&vl_config, vty);
1244
1245 char *area_id = argv[1]->arg;
1246 char *router_id = argv[3]->arg;
1247
1248 ret = str2area_id(area_id, &vl_config.area_id, &vl_config.area_id_fmt);
1249 if (ret < 0) {
1250 vty_out(vty, "OSPF area ID is invalid\n");
1251 return CMD_WARNING_CONFIG_FAILED;
1252 }
1253
1254 ret = inet_aton(router_id, &vl_config.vl_peer);
1255 if (!ret) {
1256 vty_out(vty, "Please specify valid Router ID as a.b.c.d\n");
1257 return CMD_WARNING_CONFIG_FAILED;
1258 }
1259
1260 for (int idx = 4; idx < argc; idx++) {
1261 if (strmatch(argv[idx]->text, "hello-interval"))
1262 vl_config.hello_interval =
1263 strtol(argv[++idx]->arg, NULL, 10);
1264 else if (strmatch(argv[idx]->text, "retransmit-interval"))
1265 vl_config.retransmit_interval =
1266 strtol(argv[++idx]->arg, NULL, 10);
1267 else if (strmatch(argv[idx]->text, "transmit-delay"))
1268 vl_config.transmit_delay =
1269 strtol(argv[++idx]->arg, NULL, 10);
1270 else if (strmatch(argv[idx]->text, "dead-interval"))
1271 vl_config.dead_interval =
1272 strtol(argv[++idx]->arg, NULL, 10);
1273 }
1274
1275 /* Action configuration */
1276 return ospf_vl_set(ospf, &vl_config);
1277 }
1278
1279 DEFUN (no_ospf_area_vlink_intervals,
1280 no_ospf_area_vlink_intervals_cmd,
1281 "no area <A.B.C.D|(0-4294967295)> virtual-link A.B.C.D {hello-interval (1-65535)|retransmit-interval (1-65535)|transmit-delay (1-65535)|dead-interval (1-65535)}",
1282 NO_STR
1283 VLINK_HELPSTR_IPADDR
1284 VLINK_HELPSTR_TIME_PARAM)
1285 {
1286 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
1287 struct ospf_vl_config_data vl_config;
1288 int ret = 0;
1289
1290 ospf_vl_config_data_init(&vl_config, vty);
1291
1292 char *area_id = argv[2]->arg;
1293 char *router_id = argv[4]->arg;
1294
1295 ret = str2area_id(area_id, &vl_config.area_id, &vl_config.area_id_fmt);
1296 if (ret < 0) {
1297 vty_out(vty, "OSPF area ID is invalid\n");
1298 return CMD_WARNING_CONFIG_FAILED;
1299 }
1300
1301 ret = inet_aton(router_id, &vl_config.vl_peer);
1302 if (!ret) {
1303 vty_out(vty, "Please specify valid Router ID as a.b.c.d\n");
1304 return CMD_WARNING_CONFIG_FAILED;
1305 }
1306
1307 for (int idx = 5; idx < argc; idx++) {
1308 if (strmatch(argv[idx]->text, "hello-interval"))
1309 vl_config.hello_interval = OSPF_HELLO_INTERVAL_DEFAULT;
1310 else if (strmatch(argv[idx]->text, "retransmit-interval"))
1311 vl_config.retransmit_interval =
1312 OSPF_RETRANSMIT_INTERVAL_DEFAULT;
1313 else if (strmatch(argv[idx]->text, "transmit-delay"))
1314 vl_config.transmit_delay = OSPF_TRANSMIT_DELAY_DEFAULT;
1315 else if (strmatch(argv[idx]->text, "dead-interval"))
1316 vl_config.dead_interval =
1317 OSPF_ROUTER_DEAD_INTERVAL_DEFAULT;
1318 }
1319
1320 /* Action configuration */
1321 return ospf_vl_set(ospf, &vl_config);
1322 }
1323
1324 DEFUN (ospf_area_shortcut,
1325 ospf_area_shortcut_cmd,
1326 "area <A.B.C.D|(0-4294967295)> shortcut <default|enable|disable>",
1327 "OSPF area parameters\n"
1328 "OSPF area ID in IP address format\n"
1329 "OSPF area ID as a decimal value\n"
1330 "Configure the area's shortcutting mode\n"
1331 "Set default shortcutting behavior\n"
1332 "Enable shortcutting through the area\n"
1333 "Disable shortcutting through the area\n")
1334 {
1335 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
1336 int idx_ipv4_number = 1;
1337 int idx_enable_disable = 3;
1338 struct ospf_area *area;
1339 struct in_addr area_id;
1340 int mode;
1341 int format;
1342
1343 VTY_GET_OSPF_AREA_ID_NO_BB("shortcut", area_id, format,
1344 argv[idx_ipv4_number]->arg);
1345
1346 area = ospf_area_get(ospf, area_id);
1347 ospf_area_display_format_set(ospf, area, format);
1348
1349 if (strncmp(argv[idx_enable_disable]->arg, "de", 2) == 0)
1350 mode = OSPF_SHORTCUT_DEFAULT;
1351 else if (strncmp(argv[idx_enable_disable]->arg, "di", 2) == 0)
1352 mode = OSPF_SHORTCUT_DISABLE;
1353 else if (strncmp(argv[idx_enable_disable]->arg, "e", 1) == 0)
1354 mode = OSPF_SHORTCUT_ENABLE;
1355 else
1356 return CMD_WARNING_CONFIG_FAILED;
1357
1358 ospf_area_shortcut_set(ospf, area, mode);
1359
1360 if (ospf->abr_type != OSPF_ABR_SHORTCUT)
1361 vty_out(vty,
1362 "Shortcut area setting will take effect only when the router is configured as Shortcut ABR\n");
1363
1364 return CMD_SUCCESS;
1365 }
1366
1367 DEFUN (no_ospf_area_shortcut,
1368 no_ospf_area_shortcut_cmd,
1369 "no area <A.B.C.D|(0-4294967295)> shortcut <enable|disable>",
1370 NO_STR
1371 "OSPF area parameters\n"
1372 "OSPF area ID in IP address format\n"
1373 "OSPF area ID as a decimal value\n"
1374 "Deconfigure the area's shortcutting mode\n"
1375 "Deconfigure enabled shortcutting through the area\n"
1376 "Deconfigure disabled shortcutting through the area\n")
1377 {
1378 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
1379 int idx_ipv4_number = 2;
1380 struct ospf_area *area;
1381 struct in_addr area_id;
1382 int format;
1383
1384 VTY_GET_OSPF_AREA_ID_NO_BB("shortcut", area_id, format,
1385 argv[idx_ipv4_number]->arg);
1386
1387 area = ospf_area_lookup_by_area_id(ospf, area_id);
1388 if (!area)
1389 return CMD_SUCCESS;
1390
1391 ospf_area_shortcut_unset(ospf, area);
1392
1393 return CMD_SUCCESS;
1394 }
1395
1396
1397 DEFUN (ospf_area_stub,
1398 ospf_area_stub_cmd,
1399 "area <A.B.C.D|(0-4294967295)> stub",
1400 "OSPF area parameters\n"
1401 "OSPF area ID in IP address format\n"
1402 "OSPF area ID as a decimal value\n"
1403 "Configure OSPF area as stub\n")
1404 {
1405 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
1406 int idx_ipv4_number = 1;
1407 struct in_addr area_id;
1408 int ret, format;
1409
1410 VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id, format,
1411 argv[idx_ipv4_number]->arg);
1412
1413 ret = ospf_area_stub_set(ospf, area_id);
1414 ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id),
1415 format);
1416 if (ret == 0) {
1417 vty_out(vty,
1418 "First deconfigure all virtual link through this area\n");
1419 return CMD_WARNING_CONFIG_FAILED;
1420 }
1421
1422 /* Flush the external LSAs from the specified area */
1423 ospf_flush_lsa_from_area(ospf, area_id, OSPF_AS_EXTERNAL_LSA);
1424 ospf_area_no_summary_unset(ospf, area_id);
1425
1426 return CMD_SUCCESS;
1427 }
1428
1429 DEFUN (ospf_area_stub_no_summary,
1430 ospf_area_stub_no_summary_cmd,
1431 "area <A.B.C.D|(0-4294967295)> stub no-summary",
1432 "OSPF stub parameters\n"
1433 "OSPF area ID in IP address format\n"
1434 "OSPF area ID as a decimal value\n"
1435 "Configure OSPF area as stub\n"
1436 "Do not inject inter-area routes into stub\n")
1437 {
1438 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
1439 int idx_ipv4_number = 1;
1440 struct in_addr area_id;
1441 int ret, format;
1442
1443 VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id, format,
1444 argv[idx_ipv4_number]->arg);
1445
1446 ret = ospf_area_stub_set(ospf, area_id);
1447 ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id),
1448 format);
1449 if (ret == 0) {
1450 vty_out(vty,
1451 "%% Area cannot be stub as it contains a virtual link\n");
1452 return CMD_WARNING_CONFIG_FAILED;
1453 }
1454
1455 ospf_area_no_summary_set(ospf, area_id);
1456
1457 return CMD_SUCCESS;
1458 }
1459
1460 DEFUN (no_ospf_area_stub,
1461 no_ospf_area_stub_cmd,
1462 "no area <A.B.C.D|(0-4294967295)> stub",
1463 NO_STR
1464 "OSPF area parameters\n"
1465 "OSPF area ID in IP address format\n"
1466 "OSPF area ID as a decimal value\n"
1467 "Configure OSPF area as stub\n")
1468 {
1469 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
1470 int idx_ipv4_number = 2;
1471 struct in_addr area_id;
1472 int format;
1473
1474 VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id, format,
1475 argv[idx_ipv4_number]->arg);
1476
1477 ospf_area_stub_unset(ospf, area_id);
1478 ospf_area_no_summary_unset(ospf, area_id);
1479
1480 return CMD_SUCCESS;
1481 }
1482
1483 DEFUN (no_ospf_area_stub_no_summary,
1484 no_ospf_area_stub_no_summary_cmd,
1485 "no area <A.B.C.D|(0-4294967295)> stub no-summary",
1486 NO_STR
1487 "OSPF area parameters\n"
1488 "OSPF area ID in IP address format\n"
1489 "OSPF area ID as a decimal value\n"
1490 "Configure OSPF area as stub\n"
1491 "Do not inject inter-area routes into area\n")
1492 {
1493 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
1494 int idx_ipv4_number = 2;
1495 struct in_addr area_id;
1496 int format;
1497
1498 VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id, format,
1499 argv[idx_ipv4_number]->arg);
1500 ospf_area_no_summary_unset(ospf, area_id);
1501
1502 return CMD_SUCCESS;
1503 }
1504
1505 static int ospf_area_nssa_cmd_handler(struct vty *vty, int argc,
1506 struct cmd_token **argv, int cfg_nosum,
1507 int nosum)
1508 {
1509 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
1510 struct in_addr area_id;
1511 int ret, format;
1512
1513 VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id, format, argv[1]->arg);
1514
1515 ret = ospf_area_nssa_set(ospf, area_id);
1516 ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id),
1517 format);
1518 if (ret == 0) {
1519 vty_out(vty,
1520 "%% Area cannot be nssa as it contains a virtual link\n");
1521 return CMD_WARNING_CONFIG_FAILED;
1522 }
1523
1524 if (argc > 3) {
1525 if (strncmp(argv[3]->text, "translate-c", 11) == 0)
1526 ospf_area_nssa_translator_role_set(
1527 ospf, area_id, OSPF_NSSA_ROLE_CANDIDATE);
1528 else if (strncmp(argv[3]->text, "translate-n", 11) == 0)
1529 ospf_area_nssa_translator_role_set(
1530 ospf, area_id, OSPF_NSSA_ROLE_NEVER);
1531 else if (strncmp(argv[3]->text, "translate-a", 11) == 0)
1532 ospf_area_nssa_translator_role_set(
1533 ospf, area_id, OSPF_NSSA_ROLE_ALWAYS);
1534 } else {
1535 ospf_area_nssa_translator_role_set(ospf, area_id,
1536 OSPF_NSSA_ROLE_CANDIDATE);
1537 }
1538
1539 if (cfg_nosum) {
1540 if (nosum)
1541 ospf_area_no_summary_set(ospf, area_id);
1542 else
1543 ospf_area_no_summary_unset(ospf, area_id);
1544 }
1545
1546 /* Flush the external LSA for the specified area */
1547 ospf_flush_lsa_from_area(ospf, area_id, OSPF_AS_EXTERNAL_LSA);
1548 ospf_schedule_abr_task(ospf);
1549
1550 return CMD_SUCCESS;
1551 }
1552
1553
1554 DEFUN (ospf_area_nssa_translate,
1555 ospf_area_nssa_translate_cmd,
1556 "area <A.B.C.D|(0-4294967295)> nssa <translate-candidate|translate-never|translate-always>",
1557 "OSPF area parameters\n"
1558 "OSPF area ID in IP address format\n"
1559 "OSPF area ID as a decimal value\n"
1560 "Configure OSPF area as nssa\n"
1561 "Configure NSSA-ABR for translate election (default)\n"
1562 "Configure NSSA-ABR to never translate\n"
1563 "Configure NSSA-ABR to always translate\n")
1564 {
1565 return ospf_area_nssa_cmd_handler(vty, argc, argv, 0, 0);
1566 }
1567
1568 DEFUN (ospf_area_nssa,
1569 ospf_area_nssa_cmd,
1570 "area <A.B.C.D|(0-4294967295)> nssa",
1571 "OSPF area parameters\n"
1572 "OSPF area ID in IP address format\n"
1573 "OSPF area ID as a decimal value\n"
1574 "Configure OSPF area as nssa\n")
1575 {
1576 return ospf_area_nssa_cmd_handler(vty, argc, argv, 0, 0);
1577 }
1578
1579 DEFUN(ospf_area_nssa_suppress_fa, ospf_area_nssa_suppress_fa_cmd,
1580 "area <A.B.C.D|(0-4294967295)> nssa suppress-fa",
1581 "OSPF area parameters\n"
1582 "OSPF area ID in IP address format\n"
1583 "OSPF area ID as a decimal value\n"
1584 "Configure OSPF area as nssa\n"
1585 "Suppress forwarding address\n")
1586 {
1587 int idx_ipv4_number = 1;
1588 struct in_addr area_id;
1589 int format;
1590
1591 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
1592 VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id, format,
1593 argv[idx_ipv4_number]->arg);
1594
1595 ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id),
1596 format);
1597 ospf_area_nssa_suppress_fa_set(ospf, area_id);
1598
1599 ospf_schedule_abr_task(ospf);
1600
1601 return CMD_SUCCESS;
1602 }
1603
1604 DEFUN(no_ospf_area_nssa_suppress_fa, no_ospf_area_nssa_suppress_fa_cmd,
1605 "no area <A.B.C.D|(0-4294967295)> nssa suppress-fa",
1606 NO_STR
1607 "OSPF area parameters\n"
1608 "OSPF area ID in IP address format\n"
1609 "OSPF area ID as a decimal value\n"
1610 "Configure OSPF area as nssa\n"
1611 "Suppress forwarding address\n")
1612 {
1613 int idx_ipv4_number = 2;
1614 struct in_addr area_id;
1615 int format;
1616
1617 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
1618
1619 VTY_GET_OSPF_AREA_ID_NO_BB("nssa", area_id, format,
1620 argv[idx_ipv4_number]->arg);
1621
1622 ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id),
1623 format);
1624 ospf_area_nssa_suppress_fa_unset(ospf, area_id);
1625
1626 ospf_schedule_abr_task(ospf);
1627
1628 return CMD_SUCCESS;
1629 }
1630
1631 DEFUN (ospf_area_nssa_no_summary,
1632 ospf_area_nssa_no_summary_cmd,
1633 "area <A.B.C.D|(0-4294967295)> nssa no-summary",
1634 "OSPF area parameters\n"
1635 "OSPF area ID in IP address format\n"
1636 "OSPF area ID as a decimal value\n"
1637 "Configure OSPF area as nssa\n"
1638 "Do not inject inter-area routes into nssa\n")
1639 {
1640 int idx_ipv4_number = 1;
1641 struct in_addr area_id;
1642 int format;
1643
1644 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
1645 VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id, format,
1646 argv[idx_ipv4_number]->arg);
1647
1648 ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id),
1649 format);
1650 ospf_area_nssa_no_summary_set(ospf, area_id);
1651
1652 ospf_schedule_abr_task(ospf);
1653
1654 return CMD_SUCCESS;
1655 }
1656
1657 DEFUN (no_ospf_area_nssa_no_summary,
1658 no_ospf_area_nssa_no_summary_cmd,
1659 "no area <A.B.C.D|(0-4294967295)> nssa no-summary",
1660 NO_STR
1661 "OSPF area parameters\n"
1662 "OSPF area ID in IP address format\n"
1663 "OSPF area ID as a decimal value\n"
1664 "Configure OSPF area as nssa\n"
1665 "Do not inject inter-area routes into nssa\n")
1666 {
1667 int idx_ipv4_number = 2;
1668 struct in_addr area_id;
1669 int format;
1670
1671 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
1672
1673 VTY_GET_OSPF_AREA_ID_NO_BB("nssa", area_id, format,
1674 argv[idx_ipv4_number]->arg);
1675
1676 ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id),
1677 format);
1678 ospf_area_no_summary_unset(ospf, area_id);
1679
1680 ospf_schedule_abr_task(ospf);
1681
1682 return CMD_SUCCESS;
1683 }
1684
1685 DEFUN (no_ospf_area_nssa,
1686 no_ospf_area_nssa_cmd,
1687 "no area <A.B.C.D|(0-4294967295)> nssa [<translate-candidate|translate-never|translate-always>]",
1688 NO_STR
1689 "OSPF area parameters\n"
1690 "OSPF area ID in IP address format\n"
1691 "OSPF area ID as a decimal value\n"
1692 "Configure OSPF area as nssa\n"
1693 "Configure NSSA-ABR for translate election (default)\n"
1694 "Configure NSSA-ABR to never translate\n"
1695 "Configure NSSA-ABR to always translate\n")
1696 {
1697 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
1698 int idx_ipv4_number = 2;
1699 struct in_addr area_id;
1700 int format;
1701
1702 VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id, format,
1703 argv[idx_ipv4_number]->arg);
1704
1705 /* Flush the NSSA LSA for the specified area */
1706 ospf_flush_lsa_from_area(ospf, area_id, OSPF_AS_NSSA_LSA);
1707 ospf_area_nssa_unset(ospf, area_id, argc);
1708
1709 ospf_schedule_abr_task(ospf);
1710
1711 return CMD_SUCCESS;
1712 }
1713
1714
1715 DEFUN (ospf_area_default_cost,
1716 ospf_area_default_cost_cmd,
1717 "area <A.B.C.D|(0-4294967295)> default-cost (0-16777215)",
1718 "OSPF area parameters\n"
1719 "OSPF area ID in IP address format\n"
1720 "OSPF area ID as a decimal value\n"
1721 "Set the summary-default cost of a NSSA or stub area\n"
1722 "Stub's advertised default summary cost\n")
1723 {
1724 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
1725 int idx_ipv4_number = 1;
1726 int idx_number = 3;
1727 struct ospf_area *area;
1728 struct in_addr area_id;
1729 uint32_t cost;
1730 int format;
1731 struct prefix_ipv4 p;
1732
1733 VTY_GET_OSPF_AREA_ID_NO_BB("default-cost", area_id, format,
1734 argv[idx_ipv4_number]->arg);
1735 cost = strtoul(argv[idx_number]->arg, NULL, 10);
1736
1737 area = ospf_area_get(ospf, area_id);
1738 ospf_area_display_format_set(ospf, area, format);
1739
1740 if (area->external_routing == OSPF_AREA_DEFAULT) {
1741 vty_out(vty, "The area is neither stub, nor NSSA\n");
1742 return CMD_WARNING_CONFIG_FAILED;
1743 }
1744
1745 area->default_cost = cost;
1746
1747 p.family = AF_INET;
1748 p.prefix.s_addr = OSPF_DEFAULT_DESTINATION;
1749 p.prefixlen = 0;
1750 if (IS_DEBUG_OSPF_EVENT)
1751 zlog_debug(
1752 "ospf_abr_announce_stub_defaults(): announcing 0.0.0.0/0 to area %pI4",
1753 &area->area_id);
1754 ospf_abr_announce_network_to_area(&p, area->default_cost, area);
1755
1756 return CMD_SUCCESS;
1757 }
1758
1759 DEFUN (no_ospf_area_default_cost,
1760 no_ospf_area_default_cost_cmd,
1761 "no area <A.B.C.D|(0-4294967295)> default-cost (0-16777215)",
1762 NO_STR
1763 "OSPF area parameters\n"
1764 "OSPF area ID in IP address format\n"
1765 "OSPF area ID as a decimal value\n"
1766 "Set the summary-default cost of a NSSA or stub area\n"
1767 "Stub's advertised default summary cost\n")
1768 {
1769 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
1770 int idx_ipv4_number = 2;
1771 struct ospf_area *area;
1772 struct in_addr area_id;
1773 int format;
1774 struct prefix_ipv4 p;
1775
1776 VTY_GET_OSPF_AREA_ID_NO_BB("default-cost", area_id, format,
1777 argv[idx_ipv4_number]->arg);
1778
1779 area = ospf_area_lookup_by_area_id(ospf, area_id);
1780 if (area == NULL)
1781 return CMD_SUCCESS;
1782
1783 if (area->external_routing == OSPF_AREA_DEFAULT) {
1784 vty_out(vty, "The area is neither stub, nor NSSA\n");
1785 return CMD_WARNING_CONFIG_FAILED;
1786 }
1787
1788 area->default_cost = 1;
1789
1790 p.family = AF_INET;
1791 p.prefix.s_addr = OSPF_DEFAULT_DESTINATION;
1792 p.prefixlen = 0;
1793 if (IS_DEBUG_OSPF_EVENT)
1794 zlog_debug(
1795 "ospf_abr_announce_stub_defaults(): announcing 0.0.0.0/0 to area %pI4",
1796 &area->area_id);
1797 ospf_abr_announce_network_to_area(&p, area->default_cost, area);
1798
1799
1800 ospf_area_check_free(ospf, area_id);
1801
1802 return CMD_SUCCESS;
1803 }
1804
1805 DEFUN (ospf_area_export_list,
1806 ospf_area_export_list_cmd,
1807 "area <A.B.C.D|(0-4294967295)> export-list NAME",
1808 "OSPF area parameters\n"
1809 "OSPF area ID in IP address format\n"
1810 "OSPF area ID as a decimal value\n"
1811 "Set the filter for networks announced to other areas\n"
1812 "Name of the access-list\n")
1813 {
1814 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
1815 int idx_ipv4_number = 1;
1816 struct ospf_area *area;
1817 struct in_addr area_id;
1818 int format;
1819
1820 VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg);
1821
1822 area = ospf_area_get(ospf, area_id);
1823 ospf_area_display_format_set(ospf, area, format);
1824 ospf_area_export_list_set(ospf, area, argv[3]->arg);
1825
1826 return CMD_SUCCESS;
1827 }
1828
1829 DEFUN (no_ospf_area_export_list,
1830 no_ospf_area_export_list_cmd,
1831 "no area <A.B.C.D|(0-4294967295)> export-list NAME",
1832 NO_STR
1833 "OSPF area parameters\n"
1834 "OSPF area ID in IP address format\n"
1835 "OSPF area ID as a decimal value\n"
1836 "Unset the filter for networks announced to other areas\n"
1837 "Name of the access-list\n")
1838 {
1839 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
1840 int idx_ipv4_number = 2;
1841 struct ospf_area *area;
1842 struct in_addr area_id;
1843 int format;
1844
1845 VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg);
1846
1847 area = ospf_area_lookup_by_area_id(ospf, area_id);
1848 if (area == NULL)
1849 return CMD_SUCCESS;
1850
1851 ospf_area_export_list_unset(ospf, area);
1852
1853 return CMD_SUCCESS;
1854 }
1855
1856
1857 DEFUN (ospf_area_import_list,
1858 ospf_area_import_list_cmd,
1859 "area <A.B.C.D|(0-4294967295)> import-list NAME",
1860 "OSPF area parameters\n"
1861 "OSPF area ID in IP address format\n"
1862 "OSPF area ID as a decimal value\n"
1863 "Set the filter for networks from other areas announced to the specified one\n"
1864 "Name of the access-list\n")
1865 {
1866 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
1867 int idx_ipv4_number = 1;
1868 struct ospf_area *area;
1869 struct in_addr area_id;
1870 int format;
1871
1872 VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg);
1873
1874 area = ospf_area_get(ospf, area_id);
1875 ospf_area_display_format_set(ospf, area, format);
1876 ospf_area_import_list_set(ospf, area, argv[3]->arg);
1877
1878 return CMD_SUCCESS;
1879 }
1880
1881 DEFUN (no_ospf_area_import_list,
1882 no_ospf_area_import_list_cmd,
1883 "no area <A.B.C.D|(0-4294967295)> import-list NAME",
1884 NO_STR
1885 "OSPF area parameters\n"
1886 "OSPF area ID in IP address format\n"
1887 "OSPF area ID as a decimal value\n"
1888 "Unset the filter for networks announced to other areas\n"
1889 "Name of the access-list\n")
1890 {
1891 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
1892 int idx_ipv4_number = 2;
1893 struct ospf_area *area;
1894 struct in_addr area_id;
1895 int format;
1896
1897 VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg);
1898
1899 area = ospf_area_lookup_by_area_id(ospf, area_id);
1900 if (area == NULL)
1901 return CMD_SUCCESS;
1902
1903 ospf_area_import_list_unset(ospf, area);
1904
1905 return CMD_SUCCESS;
1906 }
1907
1908 DEFUN (ospf_area_filter_list,
1909 ospf_area_filter_list_cmd,
1910 "area <A.B.C.D|(0-4294967295)> filter-list prefix WORD <in|out>",
1911 "OSPF area parameters\n"
1912 "OSPF area ID in IP address format\n"
1913 "OSPF area ID as a decimal value\n"
1914 "Filter networks between OSPF areas\n"
1915 "Filter prefixes between OSPF areas\n"
1916 "Name of an IP prefix-list\n"
1917 "Filter networks sent to this area\n"
1918 "Filter networks sent from this area\n")
1919 {
1920 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
1921 int idx_ipv4_number = 1;
1922 int idx_word = 4;
1923 int idx_in_out = 5;
1924 struct ospf_area *area;
1925 struct in_addr area_id;
1926 struct prefix_list *plist;
1927 int format;
1928
1929 VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg);
1930
1931 area = ospf_area_get(ospf, area_id);
1932 ospf_area_display_format_set(ospf, area, format);
1933 plist = prefix_list_lookup(AFI_IP, argv[idx_word]->arg);
1934 if (strncmp(argv[idx_in_out]->arg, "in", 2) == 0) {
1935 PREFIX_LIST_IN(area) = plist;
1936 if (PREFIX_NAME_IN(area))
1937 free(PREFIX_NAME_IN(area));
1938
1939 PREFIX_NAME_IN(area) = strdup(argv[idx_word]->arg);
1940 ospf_schedule_abr_task(ospf);
1941 } else {
1942 PREFIX_LIST_OUT(area) = plist;
1943 if (PREFIX_NAME_OUT(area))
1944 free(PREFIX_NAME_OUT(area));
1945
1946 PREFIX_NAME_OUT(area) = strdup(argv[idx_word]->arg);
1947 ospf_schedule_abr_task(ospf);
1948 }
1949
1950 return CMD_SUCCESS;
1951 }
1952
1953 DEFUN (no_ospf_area_filter_list,
1954 no_ospf_area_filter_list_cmd,
1955 "no area <A.B.C.D|(0-4294967295)> filter-list prefix WORD <in|out>",
1956 NO_STR
1957 "OSPF area parameters\n"
1958 "OSPF area ID in IP address format\n"
1959 "OSPF area ID as a decimal value\n"
1960 "Filter networks between OSPF areas\n"
1961 "Filter prefixes between OSPF areas\n"
1962 "Name of an IP prefix-list\n"
1963 "Filter networks sent to this area\n"
1964 "Filter networks sent from this area\n")
1965 {
1966 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
1967 int idx_ipv4_number = 2;
1968 int idx_word = 5;
1969 int idx_in_out = 6;
1970 struct ospf_area *area;
1971 struct in_addr area_id;
1972 int format;
1973
1974 VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg);
1975
1976 if ((area = ospf_area_lookup_by_area_id(ospf, area_id)) == NULL)
1977 return CMD_SUCCESS;
1978
1979 if (strncmp(argv[idx_in_out]->arg, "in", 2) == 0) {
1980 if (PREFIX_NAME_IN(area))
1981 if (strcmp(PREFIX_NAME_IN(area), argv[idx_word]->arg)
1982 != 0)
1983 return CMD_SUCCESS;
1984
1985 PREFIX_LIST_IN(area) = NULL;
1986 if (PREFIX_NAME_IN(area))
1987 free(PREFIX_NAME_IN(area));
1988
1989 PREFIX_NAME_IN(area) = NULL;
1990
1991 ospf_schedule_abr_task(ospf);
1992 } else {
1993 if (PREFIX_NAME_OUT(area))
1994 if (strcmp(PREFIX_NAME_OUT(area), argv[idx_word]->arg)
1995 != 0)
1996 return CMD_SUCCESS;
1997
1998 PREFIX_LIST_OUT(area) = NULL;
1999 if (PREFIX_NAME_OUT(area))
2000 free(PREFIX_NAME_OUT(area));
2001
2002 PREFIX_NAME_OUT(area) = NULL;
2003
2004 ospf_schedule_abr_task(ospf);
2005 }
2006
2007 return CMD_SUCCESS;
2008 }
2009
2010
2011 DEFUN (ospf_area_authentication_message_digest,
2012 ospf_area_authentication_message_digest_cmd,
2013 "[no] area <A.B.C.D|(0-4294967295)> authentication message-digest",
2014 NO_STR
2015 "OSPF area parameters\n"
2016 "OSPF area ID in IP address format\n"
2017 "OSPF area ID as a decimal value\n"
2018 "Enable authentication\n"
2019 "Use message-digest authentication\n")
2020 {
2021 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
2022 int idx = 0;
2023 struct ospf_area *area;
2024 struct in_addr area_id;
2025 int format;
2026
2027 argv_find(argv, argc, "area", &idx);
2028 VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx + 1]->arg);
2029
2030 area = ospf_area_get(ospf, area_id);
2031 ospf_area_display_format_set(ospf, area, format);
2032 area->auth_type = strmatch(argv[0]->text, "no")
2033 ? OSPF_AUTH_NULL
2034 : OSPF_AUTH_CRYPTOGRAPHIC;
2035
2036 return CMD_SUCCESS;
2037 }
2038
2039 DEFUN (ospf_area_authentication,
2040 ospf_area_authentication_cmd,
2041 "area <A.B.C.D|(0-4294967295)> authentication",
2042 "OSPF area parameters\n"
2043 "OSPF area ID in IP address format\n"
2044 "OSPF area ID as a decimal value\n"
2045 "Enable authentication\n")
2046 {
2047 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
2048 int idx_ipv4_number = 1;
2049 struct ospf_area *area;
2050 struct in_addr area_id;
2051 int format;
2052
2053 VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg);
2054
2055 area = ospf_area_get(ospf, area_id);
2056 ospf_area_display_format_set(ospf, area, format);
2057 area->auth_type = OSPF_AUTH_SIMPLE;
2058
2059 return CMD_SUCCESS;
2060 }
2061
2062 DEFUN (no_ospf_area_authentication,
2063 no_ospf_area_authentication_cmd,
2064 "no area <A.B.C.D|(0-4294967295)> authentication",
2065 NO_STR
2066 "OSPF area parameters\n"
2067 "OSPF area ID in IP address format\n"
2068 "OSPF area ID as a decimal value\n"
2069 "Enable authentication\n")
2070 {
2071 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
2072 int idx_ipv4_number = 2;
2073 struct ospf_area *area;
2074 struct in_addr area_id;
2075 int format;
2076
2077 VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg);
2078
2079 area = ospf_area_lookup_by_area_id(ospf, area_id);
2080 if (area == NULL)
2081 return CMD_SUCCESS;
2082
2083 area->auth_type = OSPF_AUTH_NULL;
2084
2085 ospf_area_check_free(ospf, area_id);
2086
2087 return CMD_SUCCESS;
2088 }
2089
2090
2091 DEFUN (ospf_abr_type,
2092 ospf_abr_type_cmd,
2093 "ospf abr-type <cisco|ibm|shortcut|standard>",
2094 "OSPF specific commands\n"
2095 "Set OSPF ABR type\n"
2096 "Alternative ABR, cisco implementation\n"
2097 "Alternative ABR, IBM implementation\n"
2098 "Shortcut ABR\n"
2099 "Standard behavior (RFC2328)\n")
2100 {
2101 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
2102 int idx_vendor = 2;
2103 uint8_t abr_type = OSPF_ABR_UNKNOWN;
2104
2105 if (strncmp(argv[idx_vendor]->arg, "c", 1) == 0)
2106 abr_type = OSPF_ABR_CISCO;
2107 else if (strncmp(argv[idx_vendor]->arg, "i", 1) == 0)
2108 abr_type = OSPF_ABR_IBM;
2109 else if (strncmp(argv[idx_vendor]->arg, "sh", 2) == 0)
2110 abr_type = OSPF_ABR_SHORTCUT;
2111 else if (strncmp(argv[idx_vendor]->arg, "st", 2) == 0)
2112 abr_type = OSPF_ABR_STAND;
2113 else
2114 return CMD_WARNING_CONFIG_FAILED;
2115
2116 /* If ABR type value is changed, schedule ABR task. */
2117 if (ospf->abr_type != abr_type) {
2118 ospf->abr_type = abr_type;
2119 ospf_schedule_abr_task(ospf);
2120 }
2121
2122 return CMD_SUCCESS;
2123 }
2124
2125 DEFUN (no_ospf_abr_type,
2126 no_ospf_abr_type_cmd,
2127 "no ospf abr-type <cisco|ibm|shortcut|standard>",
2128 NO_STR
2129 "OSPF specific commands\n"
2130 "Set OSPF ABR type\n"
2131 "Alternative ABR, cisco implementation\n"
2132 "Alternative ABR, IBM implementation\n"
2133 "Shortcut ABR\n"
2134 "Standard ABR\n")
2135 {
2136 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
2137 int idx_vendor = 3;
2138 uint8_t abr_type = OSPF_ABR_UNKNOWN;
2139
2140 if (strncmp(argv[idx_vendor]->arg, "c", 1) == 0)
2141 abr_type = OSPF_ABR_CISCO;
2142 else if (strncmp(argv[idx_vendor]->arg, "i", 1) == 0)
2143 abr_type = OSPF_ABR_IBM;
2144 else if (strncmp(argv[idx_vendor]->arg, "sh", 2) == 0)
2145 abr_type = OSPF_ABR_SHORTCUT;
2146 else if (strncmp(argv[idx_vendor]->arg, "st", 2) == 0)
2147 abr_type = OSPF_ABR_STAND;
2148 else
2149 return CMD_WARNING_CONFIG_FAILED;
2150
2151 /* If ABR type value is changed, schedule ABR task. */
2152 if (ospf->abr_type == abr_type) {
2153 ospf->abr_type = OSPF_ABR_DEFAULT;
2154 ospf_schedule_abr_task(ospf);
2155 }
2156
2157 return CMD_SUCCESS;
2158 }
2159
2160 DEFUN (ospf_log_adjacency_changes,
2161 ospf_log_adjacency_changes_cmd,
2162 "log-adjacency-changes",
2163 "Log changes in adjacency state\n")
2164 {
2165 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
2166
2167 SET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES);
2168 UNSET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL);
2169 return CMD_SUCCESS;
2170 }
2171
2172 DEFUN (ospf_log_adjacency_changes_detail,
2173 ospf_log_adjacency_changes_detail_cmd,
2174 "log-adjacency-changes detail",
2175 "Log changes in adjacency state\n"
2176 "Log all state changes\n")
2177 {
2178 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
2179
2180 SET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES);
2181 SET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL);
2182 return CMD_SUCCESS;
2183 }
2184
2185 DEFUN (no_ospf_log_adjacency_changes,
2186 no_ospf_log_adjacency_changes_cmd,
2187 "no log-adjacency-changes",
2188 NO_STR
2189 "Log changes in adjacency state\n")
2190 {
2191 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
2192
2193 UNSET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL);
2194 UNSET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES);
2195 return CMD_SUCCESS;
2196 }
2197
2198 DEFUN (no_ospf_log_adjacency_changes_detail,
2199 no_ospf_log_adjacency_changes_detail_cmd,
2200 "no log-adjacency-changes detail",
2201 NO_STR
2202 "Log changes in adjacency state\n"
2203 "Log all state changes\n")
2204 {
2205 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
2206
2207 UNSET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL);
2208 return CMD_SUCCESS;
2209 }
2210
2211 DEFUN (ospf_compatible_rfc1583,
2212 ospf_compatible_rfc1583_cmd,
2213 "compatible rfc1583",
2214 "OSPF compatibility list\n"
2215 "compatible with RFC 1583\n")
2216 {
2217 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
2218
2219 if (!CHECK_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE)) {
2220 SET_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE);
2221 ospf_spf_calculate_schedule(ospf, SPF_FLAG_CONFIG_CHANGE);
2222 }
2223 return CMD_SUCCESS;
2224 }
2225
2226 DEFUN (no_ospf_compatible_rfc1583,
2227 no_ospf_compatible_rfc1583_cmd,
2228 "no compatible rfc1583",
2229 NO_STR
2230 "OSPF compatibility list\n"
2231 "compatible with RFC 1583\n")
2232 {
2233 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
2234
2235 if (CHECK_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE)) {
2236 UNSET_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE);
2237 ospf_spf_calculate_schedule(ospf, SPF_FLAG_CONFIG_CHANGE);
2238 }
2239 return CMD_SUCCESS;
2240 }
2241
2242 ALIAS(ospf_compatible_rfc1583, ospf_rfc1583_flag_cmd,
2243 "ospf rfc1583compatibility",
2244 "OSPF specific commands\n"
2245 "Enable the RFC1583Compatibility flag\n")
2246
2247 ALIAS(no_ospf_compatible_rfc1583, no_ospf_rfc1583_flag_cmd,
2248 "no ospf rfc1583compatibility", NO_STR
2249 "OSPF specific commands\n"
2250 "Disable the RFC1583Compatibility flag\n")
2251
2252 static int ospf_timers_spf_set(struct vty *vty, unsigned int delay,
2253 unsigned int hold, unsigned int max)
2254 {
2255 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
2256
2257 ospf->spf_delay = delay;
2258 ospf->spf_holdtime = hold;
2259 ospf->spf_max_holdtime = max;
2260
2261 return CMD_SUCCESS;
2262 }
2263
2264 DEFUN (ospf_timers_min_ls_interval,
2265 ospf_timers_min_ls_interval_cmd,
2266 "timers throttle lsa all (0-5000)",
2267 "Adjust routing timers\n"
2268 "Throttling adaptive timer\n"
2269 "LSA delay between transmissions\n"
2270 "All LSA types\n"
2271 "Delay (msec) between sending LSAs\n")
2272 {
2273 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
2274 int idx_number = 4;
2275 unsigned int interval;
2276
2277 if (argc < 5) {
2278 vty_out(vty, "Insufficient arguments\n");
2279 return CMD_WARNING_CONFIG_FAILED;
2280 }
2281
2282 interval = strtoul(argv[idx_number]->arg, NULL, 10);
2283
2284 ospf->min_ls_interval = interval;
2285
2286 return CMD_SUCCESS;
2287 }
2288
2289 DEFUN (no_ospf_timers_min_ls_interval,
2290 no_ospf_timers_min_ls_interval_cmd,
2291 "no timers throttle lsa all [(0-5000)]",
2292 NO_STR
2293 "Adjust routing timers\n"
2294 "Throttling adaptive timer\n"
2295 "LSA delay between transmissions\n"
2296 "All LSA types\n"
2297 "Delay (msec) between sending LSAs\n")
2298 {
2299 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
2300 ospf->min_ls_interval = OSPF_MIN_LS_INTERVAL;
2301
2302 return CMD_SUCCESS;
2303 }
2304
2305 DEFUN (ospf_timers_throttle_spf,
2306 ospf_timers_throttle_spf_cmd,
2307 "timers throttle spf (0-600000) (0-600000) (0-600000)",
2308 "Adjust routing timers\n"
2309 "Throttling adaptive timer\n"
2310 "OSPF SPF timers\n"
2311 "Delay (msec) from first change received till SPF calculation\n"
2312 "Initial hold time (msec) between consecutive SPF calculations\n"
2313 "Maximum hold time (msec)\n")
2314 {
2315 int idx_number = 3;
2316 int idx_number_2 = 4;
2317 int idx_number_3 = 5;
2318 unsigned int delay, hold, max;
2319
2320 if (argc < 6) {
2321 vty_out(vty, "Insufficient arguments\n");
2322 return CMD_WARNING_CONFIG_FAILED;
2323 }
2324
2325 delay = strtoul(argv[idx_number]->arg, NULL, 10);
2326 hold = strtoul(argv[idx_number_2]->arg, NULL, 10);
2327 max = strtoul(argv[idx_number_3]->arg, NULL, 10);
2328
2329 return ospf_timers_spf_set(vty, delay, hold, max);
2330 }
2331
2332 DEFUN (no_ospf_timers_throttle_spf,
2333 no_ospf_timers_throttle_spf_cmd,
2334 "no timers throttle spf [(0-600000)(0-600000)(0-600000)]",
2335 NO_STR
2336 "Adjust routing timers\n"
2337 "Throttling adaptive timer\n"
2338 "OSPF SPF timers\n"
2339 "Delay (msec) from first change received till SPF calculation\n"
2340 "Initial hold time (msec) between consecutive SPF calculations\n"
2341 "Maximum hold time (msec)\n")
2342 {
2343 return ospf_timers_spf_set(vty, OSPF_SPF_DELAY_DEFAULT,
2344 OSPF_SPF_HOLDTIME_DEFAULT,
2345 OSPF_SPF_MAX_HOLDTIME_DEFAULT);
2346 }
2347
2348
2349 DEFUN (ospf_timers_lsa_min_arrival,
2350 ospf_timers_lsa_min_arrival_cmd,
2351 "timers lsa min-arrival (0-600000)",
2352 "Adjust routing timers\n"
2353 "OSPF LSA timers\n"
2354 "Minimum delay in receiving new version of a LSA\n"
2355 "Delay in milliseconds\n")
2356 {
2357 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
2358 ospf->min_ls_arrival = strtoul(argv[argc - 1]->arg, NULL, 10);
2359 return CMD_SUCCESS;
2360 }
2361
2362 DEFUN (no_ospf_timers_lsa_min_arrival,
2363 no_ospf_timers_lsa_min_arrival_cmd,
2364 "no timers lsa min-arrival [(0-600000)]",
2365 NO_STR
2366 "Adjust routing timers\n"
2367 "OSPF LSA timers\n"
2368 "Minimum delay in receiving new version of a LSA\n"
2369 "Delay in milliseconds\n")
2370 {
2371 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
2372 unsigned int minarrival;
2373
2374 if (argc > 4) {
2375 minarrival = strtoul(argv[argc - 1]->arg, NULL, 10);
2376
2377 if (ospf->min_ls_arrival != minarrival
2378 || minarrival == OSPF_MIN_LS_ARRIVAL)
2379 return CMD_SUCCESS;
2380 }
2381
2382 ospf->min_ls_arrival = OSPF_MIN_LS_ARRIVAL;
2383
2384 return CMD_SUCCESS;
2385 }
2386
2387 DEFUN (ospf_neighbor,
2388 ospf_neighbor_cmd,
2389 "neighbor A.B.C.D [priority (0-255) [poll-interval (1-65535)]]",
2390 NEIGHBOR_STR
2391 "Neighbor IP address\n"
2392 "Neighbor Priority\n"
2393 "Priority\n"
2394 "Dead Neighbor Polling interval\n"
2395 "Seconds\n")
2396 {
2397 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
2398 int idx_ipv4 = 1;
2399 int idx_pri = 3;
2400 int idx_poll = 5;
2401 struct in_addr nbr_addr;
2402 unsigned int priority = OSPF_NEIGHBOR_PRIORITY_DEFAULT;
2403 unsigned int interval = OSPF_POLL_INTERVAL_DEFAULT;
2404
2405 if (!inet_aton(argv[idx_ipv4]->arg, &nbr_addr)) {
2406 vty_out(vty, "Please specify Neighbor ID by A.B.C.D\n");
2407 return CMD_WARNING_CONFIG_FAILED;
2408 }
2409
2410 if (argc > 2)
2411 priority = strtoul(argv[idx_pri]->arg, NULL, 10);
2412
2413 if (argc > 4)
2414 interval = strtoul(argv[idx_poll]->arg, NULL, 10);
2415
2416 ospf_nbr_nbma_set(ospf, nbr_addr);
2417
2418 if (argc > 2)
2419 ospf_nbr_nbma_priority_set(ospf, nbr_addr, priority);
2420
2421 if (argc > 4)
2422 ospf_nbr_nbma_poll_interval_set(ospf, nbr_addr, interval);
2423
2424 return CMD_SUCCESS;
2425 }
2426
2427 DEFUN (ospf_neighbor_poll_interval,
2428 ospf_neighbor_poll_interval_cmd,
2429 "neighbor A.B.C.D poll-interval (1-65535) [priority (0-255)]",
2430 NEIGHBOR_STR
2431 "Neighbor IP address\n"
2432 "Dead Neighbor Polling interval\n"
2433 "Seconds\n"
2434 "OSPF priority of non-broadcast neighbor\n"
2435 "Priority\n")
2436 {
2437 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
2438 int idx_ipv4 = 1;
2439 int idx_poll = 3;
2440 int idx_pri = 5;
2441 struct in_addr nbr_addr;
2442 unsigned int priority;
2443 unsigned int interval;
2444
2445 if (!inet_aton(argv[idx_ipv4]->arg, &nbr_addr)) {
2446 vty_out(vty, "Please specify Neighbor ID by A.B.C.D\n");
2447 return CMD_WARNING_CONFIG_FAILED;
2448 }
2449
2450 interval = strtoul(argv[idx_poll]->arg, NULL, 10);
2451
2452 priority = argc > 4 ? strtoul(argv[idx_pri]->arg, NULL, 10)
2453 : OSPF_NEIGHBOR_PRIORITY_DEFAULT;
2454
2455 ospf_nbr_nbma_set(ospf, nbr_addr);
2456 ospf_nbr_nbma_poll_interval_set(ospf, nbr_addr, interval);
2457
2458 if (argc > 4)
2459 ospf_nbr_nbma_priority_set(ospf, nbr_addr, priority);
2460
2461 return CMD_SUCCESS;
2462 }
2463
2464 DEFUN (no_ospf_neighbor,
2465 no_ospf_neighbor_cmd,
2466 "no neighbor A.B.C.D [priority (0-255) [poll-interval (1-65525)]]",
2467 NO_STR
2468 NEIGHBOR_STR
2469 "Neighbor IP address\n"
2470 "Neighbor Priority\n"
2471 "Priority\n"
2472 "Dead Neighbor Polling interval\n"
2473 "Seconds\n")
2474 {
2475 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
2476 int idx_ipv4 = 2;
2477 struct in_addr nbr_addr;
2478
2479 if (!inet_aton(argv[idx_ipv4]->arg, &nbr_addr)) {
2480 vty_out(vty, "Please specify Neighbor ID by A.B.C.D\n");
2481 return CMD_WARNING_CONFIG_FAILED;
2482 }
2483
2484 (void)ospf_nbr_nbma_unset(ospf, nbr_addr);
2485
2486 return CMD_SUCCESS;
2487 }
2488
2489 DEFUN (no_ospf_neighbor_poll,
2490 no_ospf_neighbor_poll_cmd,
2491 "no neighbor A.B.C.D poll-interval (1-65535) [priority (0-255)]",
2492 NO_STR
2493 NEIGHBOR_STR
2494 "Neighbor IP address\n"
2495 "Dead Neighbor Polling interval\n"
2496 "Seconds\n"
2497 "Neighbor Priority\n"
2498 "Priority\n")
2499 {
2500 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
2501 int idx_ipv4 = 2;
2502 struct in_addr nbr_addr;
2503
2504 if (!inet_aton(argv[idx_ipv4]->arg, &nbr_addr)) {
2505 vty_out(vty, "Please specify Neighbor ID by A.B.C.D\n");
2506 return CMD_WARNING_CONFIG_FAILED;
2507 }
2508
2509 (void)ospf_nbr_nbma_unset(ospf, nbr_addr);
2510
2511 return CMD_SUCCESS;
2512 }
2513
2514 DEFUN (ospf_refresh_timer,
2515 ospf_refresh_timer_cmd,
2516 "refresh timer (10-1800)",
2517 "Adjust refresh parameters\n"
2518 "Set refresh timer\n"
2519 "Timer value in seconds\n")
2520 {
2521 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
2522 int idx_number = 2;
2523 unsigned int interval;
2524
2525 interval = strtoul(argv[idx_number]->arg, NULL, 10);
2526 interval = (interval / OSPF_LSA_REFRESHER_GRANULARITY)
2527 * OSPF_LSA_REFRESHER_GRANULARITY;
2528
2529 ospf_timers_refresh_set(ospf, interval);
2530
2531 return CMD_SUCCESS;
2532 }
2533
2534 DEFUN (no_ospf_refresh_timer,
2535 no_ospf_refresh_timer_val_cmd,
2536 "no refresh timer [(10-1800)]",
2537 NO_STR
2538 "Adjust refresh parameters\n"
2539 "Unset refresh timer\n"
2540 "Timer value in seconds\n")
2541 {
2542 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
2543 int idx_number = 3;
2544 unsigned int interval;
2545
2546 if (argc == 1) {
2547 interval = strtoul(argv[idx_number]->arg, NULL, 10);
2548
2549 if (ospf->lsa_refresh_interval != interval
2550 || interval == OSPF_LSA_REFRESH_INTERVAL_DEFAULT)
2551 return CMD_SUCCESS;
2552 }
2553
2554 ospf_timers_refresh_unset(ospf);
2555
2556 return CMD_SUCCESS;
2557 }
2558
2559
2560 DEFUN (ospf_auto_cost_reference_bandwidth,
2561 ospf_auto_cost_reference_bandwidth_cmd,
2562 "auto-cost reference-bandwidth (1-4294967)",
2563 "Calculate OSPF interface cost according to bandwidth\n"
2564 "Use reference bandwidth method to assign OSPF cost\n"
2565 "The reference bandwidth in terms of Mbits per second\n")
2566 {
2567 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
2568 struct vrf *vrf = vrf_lookup_by_id(ospf->vrf_id);
2569 int idx_number = 2;
2570 uint32_t refbw;
2571 struct interface *ifp;
2572
2573 refbw = strtol(argv[idx_number]->arg, NULL, 10);
2574 if (refbw < 1 || refbw > 4294967) {
2575 vty_out(vty, "reference-bandwidth value is invalid\n");
2576 return CMD_WARNING_CONFIG_FAILED;
2577 }
2578
2579 /* If reference bandwidth is changed. */
2580 if ((refbw) == ospf->ref_bandwidth)
2581 return CMD_SUCCESS;
2582
2583 ospf->ref_bandwidth = refbw;
2584 FOR_ALL_INTERFACES (vrf, ifp)
2585 ospf_if_recalculate_output_cost(ifp);
2586
2587 return CMD_SUCCESS;
2588 }
2589
2590 DEFUN (no_ospf_auto_cost_reference_bandwidth,
2591 no_ospf_auto_cost_reference_bandwidth_cmd,
2592 "no auto-cost reference-bandwidth [(1-4294967)]",
2593 NO_STR
2594 "Calculate OSPF interface cost according to bandwidth\n"
2595 "Use reference bandwidth method to assign OSPF cost\n"
2596 "The reference bandwidth in terms of Mbits per second\n")
2597 {
2598 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
2599 struct vrf *vrf = vrf_lookup_by_id(ospf->vrf_id);
2600 struct interface *ifp;
2601
2602 if (ospf->ref_bandwidth == OSPF_DEFAULT_REF_BANDWIDTH)
2603 return CMD_SUCCESS;
2604
2605 ospf->ref_bandwidth = OSPF_DEFAULT_REF_BANDWIDTH;
2606 vty_out(vty, "%% OSPF: Reference bandwidth is changed.\n");
2607 vty_out(vty,
2608 " Please ensure reference bandwidth is consistent across all routers\n");
2609
2610 FOR_ALL_INTERFACES (vrf, ifp)
2611 ospf_if_recalculate_output_cost(ifp);
2612
2613 return CMD_SUCCESS;
2614 }
2615
2616 DEFUN (ospf_write_multiplier,
2617 ospf_write_multiplier_cmd,
2618 "ospf write-multiplier (1-100)",
2619 "OSPF specific commands\n"
2620 "Write multiplier\n"
2621 "Maximum number of interface serviced per write\n")
2622 {
2623 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
2624 int idx_number;
2625 uint32_t write_oi_count;
2626
2627 if (argc == 3)
2628 idx_number = 2;
2629 else
2630 idx_number = 1;
2631
2632 write_oi_count = strtol(argv[idx_number]->arg, NULL, 10);
2633 if (write_oi_count < 1 || write_oi_count > 100) {
2634 vty_out(vty, "write-multiplier value is invalid\n");
2635 return CMD_WARNING_CONFIG_FAILED;
2636 }
2637
2638 ospf->write_oi_count = write_oi_count;
2639 return CMD_SUCCESS;
2640 }
2641
2642 ALIAS(ospf_write_multiplier, write_multiplier_cmd, "write-multiplier (1-100)",
2643 "Write multiplier\n"
2644 "Maximum number of interface serviced per write\n")
2645
2646 DEFUN (no_ospf_write_multiplier,
2647 no_ospf_write_multiplier_cmd,
2648 "no ospf write-multiplier (1-100)",
2649 NO_STR
2650 "OSPF specific commands\n"
2651 "Write multiplier\n"
2652 "Maximum number of interface serviced per write\n")
2653 {
2654 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
2655
2656 ospf->write_oi_count = OSPF_WRITE_INTERFACE_COUNT_DEFAULT;
2657 return CMD_SUCCESS;
2658 }
2659
2660 ALIAS(no_ospf_write_multiplier, no_write_multiplier_cmd,
2661 "no write-multiplier (1-100)", NO_STR
2662 "Write multiplier\n"
2663 "Maximum number of interface serviced per write\n")
2664
2665 DEFUN(ospf_ti_lfa, ospf_ti_lfa_cmd, "fast-reroute ti-lfa [node-protection]",
2666 "Fast Reroute for MPLS and IP resilience\n"
2667 "Topology Independent LFA (Loop-Free Alternate)\n"
2668 "TI-LFA node protection (default is link protection)\n")
2669 {
2670 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
2671
2672 ospf->ti_lfa_enabled = true;
2673
2674 if (argc == 3)
2675 ospf->ti_lfa_protection_type = OSPF_TI_LFA_NODE_PROTECTION;
2676 else
2677 ospf->ti_lfa_protection_type = OSPF_TI_LFA_LINK_PROTECTION;
2678
2679 ospf_spf_calculate_schedule(ospf, SPF_FLAG_CONFIG_CHANGE);
2680
2681 return CMD_SUCCESS;
2682 }
2683
2684 DEFUN(no_ospf_ti_lfa, no_ospf_ti_lfa_cmd,
2685 "no fast-reroute ti-lfa [node-protection]",
2686 NO_STR
2687 "Fast Reroute for MPLS and IP resilience\n"
2688 "Topology Independent LFA (Loop-Free Alternate)\n"
2689 "TI-LFA node protection (default is link protection)\n")
2690 {
2691 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
2692
2693 ospf->ti_lfa_enabled = false;
2694
2695 ospf->ti_lfa_protection_type = OSPF_TI_LFA_UNDEFINED_PROTECTION;
2696
2697 ospf_spf_calculate_schedule(ospf, SPF_FLAG_CONFIG_CHANGE);
2698
2699 return CMD_SUCCESS;
2700 }
2701
2702 static void ospf_maxpath_set(struct vty *vty, struct ospf *ospf, uint16_t paths)
2703 {
2704 if (ospf->max_multipath == paths)
2705 return;
2706
2707 ospf->max_multipath = paths;
2708
2709 /* Send deletion notification to zebra to delete all
2710 * ospf specific routes and reinitiat SPF to reflect
2711 * the new max multipath.
2712 */
2713 ospf_restart_spf(ospf);
2714 }
2715
2716 /* Ospf Maximum multiple paths config support */
2717 DEFUN (ospf_max_multipath,
2718 ospf_max_multipath_cmd,
2719 "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2720 "Max no of multiple paths for ECMP support\n"
2721 "Number of paths\n")
2722 {
2723 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
2724 int idx_number = 1;
2725 uint16_t maxpaths;
2726
2727 maxpaths = strtol(argv[idx_number]->arg, NULL, 10);
2728
2729 ospf_maxpath_set(vty, ospf, maxpaths);
2730 return CMD_SUCCESS;
2731 }
2732
2733 DEFUN (no_ospf_max_multipath,
2734 no_ospf_max_multipath_cmd,
2735 "no maximum-paths",
2736 NO_STR
2737 "Max no of multiple paths for ECMP support\n")
2738 {
2739 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
2740 uint16_t maxpaths = MULTIPATH_NUM;
2741
2742 ospf_maxpath_set(vty, ospf, maxpaths);
2743 return CMD_SUCCESS;
2744 }
2745
2746 static const char *const ospf_abr_type_descr_str[] = {
2747 "Unknown", "Standard (RFC2328)", "Alternative IBM",
2748 "Alternative Cisco", "Alternative Shortcut"
2749 };
2750
2751 static const char *const ospf_shortcut_mode_descr_str[] = {
2752 "Default", "Enabled", "Disabled"
2753 };
2754
2755 static void show_ip_ospf_area(struct vty *vty, struct ospf_area *area,
2756 json_object *json_areas, bool use_json)
2757 {
2758 json_object *json_area = NULL;
2759 char buf[PREFIX_STRLEN];
2760
2761 if (use_json)
2762 json_area = json_object_new_object();
2763
2764 /* Show Area ID. */
2765 if (!use_json)
2766 vty_out(vty, " Area ID: %pI4", &area->area_id);
2767
2768 /* Show Area type/mode. */
2769 if (OSPF_IS_AREA_BACKBONE(area)) {
2770 if (use_json)
2771 json_object_boolean_true_add(json_area, "backbone");
2772 else
2773 vty_out(vty, " (Backbone)\n");
2774 } else {
2775 if (use_json) {
2776 if (area->external_routing == OSPF_AREA_STUB) {
2777 if (area->no_summary)
2778 json_object_boolean_true_add(
2779 json_area, "stubNoSummary");
2780 if (area->shortcut_configured)
2781 json_object_boolean_true_add(
2782 json_area, "stubShortcut");
2783 } else if (area->external_routing == OSPF_AREA_NSSA) {
2784 if (area->no_summary)
2785 json_object_boolean_true_add(
2786 json_area, "nssaNoSummary");
2787 if (area->shortcut_configured)
2788 json_object_boolean_true_add(
2789 json_area, "nssaShortcut");
2790 }
2791
2792 json_object_string_add(
2793 json_area, "shortcuttingMode",
2794 ospf_shortcut_mode_descr_str
2795 [area->shortcut_configured]);
2796 if (area->shortcut_capability)
2797 json_object_boolean_true_add(json_area,
2798 "sBitConcensus");
2799 } else {
2800 if (area->external_routing == OSPF_AREA_STUB)
2801 vty_out(vty, " (Stub%s%s)",
2802 area->no_summary ? ", no summary" : "",
2803 area->shortcut_configured ? "; " : "");
2804 else if (area->external_routing == OSPF_AREA_NSSA)
2805 vty_out(vty, " (NSSA%s%s)",
2806 area->no_summary ? ", no summary" : "",
2807 area->shortcut_configured ? "; " : "");
2808
2809 vty_out(vty, "\n");
2810 vty_out(vty, " Shortcutting mode: %s",
2811 ospf_shortcut_mode_descr_str
2812 [area->shortcut_configured]);
2813 vty_out(vty, ", S-bit consensus: %s\n",
2814 area->shortcut_capability ? "ok" : "no");
2815 }
2816 }
2817
2818 /* Show number of interfaces */
2819 if (use_json) {
2820 json_object_int_add(json_area, "areaIfTotalCounter",
2821 listcount(area->oiflist));
2822 json_object_int_add(json_area, "areaIfActiveCounter",
2823 area->act_ints);
2824 } else
2825 vty_out(vty,
2826 " Number of interfaces in this area: Total: %d, Active: %d\n",
2827 listcount(area->oiflist), area->act_ints);
2828
2829 if (area->external_routing == OSPF_AREA_NSSA) {
2830 if (use_json) {
2831 json_object_boolean_true_add(json_area, "nssa");
2832 if (!IS_OSPF_ABR(area->ospf))
2833 json_object_boolean_false_add(json_area, "abr");
2834 else if (area->NSSATranslatorState) {
2835 json_object_boolean_true_add(json_area, "abr");
2836 if (area->NSSATranslatorRole
2837 == OSPF_NSSA_ROLE_CANDIDATE)
2838 json_object_boolean_true_add(
2839 json_area,
2840 "nssaTranslatorElected");
2841 else if (area->NSSATranslatorRole
2842 == OSPF_NSSA_ROLE_ALWAYS)
2843 json_object_boolean_true_add(
2844 json_area,
2845 "nssaTranslatorAlways");
2846 else
2847 json_object_boolean_true_add(
2848 json_area,
2849 "nssaTranslatorNever");
2850 } else {
2851 json_object_boolean_true_add(json_area, "abr");
2852 if (area->NSSATranslatorRole
2853 == OSPF_NSSA_ROLE_CANDIDATE)
2854 json_object_boolean_false_add(
2855 json_area,
2856 "nssaTranslatorElected");
2857 else
2858 json_object_boolean_true_add(
2859 json_area,
2860 "nssaTranslatorNever");
2861 }
2862 } else {
2863 vty_out(vty,
2864 " It is an NSSA configuration.\n Elected NSSA/ABR performs type-7/type-5 LSA translation.\n");
2865 if (!IS_OSPF_ABR(area->ospf))
2866 vty_out(vty,
2867 " It is not ABR, therefore not Translator.\n");
2868 else if (area->NSSATranslatorState) {
2869 vty_out(vty, " We are an ABR and ");
2870 if (area->NSSATranslatorRole
2871 == OSPF_NSSA_ROLE_CANDIDATE)
2872 vty_out(vty,
2873 "the NSSA Elected Translator.\n");
2874 else if (area->NSSATranslatorRole
2875 == OSPF_NSSA_ROLE_ALWAYS)
2876 vty_out(vty,
2877 "always an NSSA Translator.\n");
2878 else
2879 vty_out(vty,
2880 "never an NSSA Translator.\n");
2881 } else {
2882 vty_out(vty, " We are an ABR, but ");
2883 if (area->NSSATranslatorRole
2884 == OSPF_NSSA_ROLE_CANDIDATE)
2885 vty_out(vty,
2886 "not the NSSA Elected Translator.\n");
2887 else
2888 vty_out(vty,
2889 "never an NSSA Translator.\n");
2890 }
2891 }
2892 }
2893
2894 /* Stub-router state for this area */
2895 if (CHECK_FLAG(area->stub_router_state, OSPF_AREA_IS_STUB_ROUTED)) {
2896 char timebuf[OSPF_TIME_DUMP_SIZE];
2897
2898 if (use_json) {
2899 json_object_boolean_true_add(
2900 json_area, "originStubMaxDistRouterLsa");
2901 if (CHECK_FLAG(area->stub_router_state,
2902 OSPF_AREA_ADMIN_STUB_ROUTED))
2903 json_object_boolean_true_add(
2904 json_area, "indefiniteActiveAdmin");
2905 if (area->t_stub_router) {
2906 long time_store;
2907 time_store =
2908 monotime_until(
2909 &area->t_stub_router->u.sands,
2910 NULL)
2911 / 1000LL;
2912 json_object_int_add(
2913 json_area,
2914 "activeStartupRemainderMsecs",
2915 time_store);
2916 }
2917 } else {
2918 vty_out(vty,
2919 " Originating stub / maximum-distance Router-LSA\n");
2920 if (CHECK_FLAG(area->stub_router_state,
2921 OSPF_AREA_ADMIN_STUB_ROUTED))
2922 vty_out(vty,
2923 " Administratively activated (indefinitely)\n");
2924 if (area->t_stub_router)
2925 vty_out(vty,
2926 " Active from startup, %s remaining\n",
2927 ospf_timer_dump(area->t_stub_router,
2928 timebuf,
2929 sizeof(timebuf)));
2930 }
2931 }
2932
2933 if (use_json) {
2934 /* Show number of fully adjacent neighbors. */
2935 json_object_int_add(json_area, "nbrFullAdjacentCounter",
2936 area->full_nbrs);
2937
2938 /* Show authentication type. */
2939 if (area->auth_type == OSPF_AUTH_NULL)
2940 json_object_string_add(json_area, "authentication",
2941 "authenticationNone");
2942 else if (area->auth_type == OSPF_AUTH_SIMPLE)
2943 json_object_string_add(json_area, "authentication",
2944 "authenticationSimplePassword");
2945 else if (area->auth_type == OSPF_AUTH_CRYPTOGRAPHIC)
2946 json_object_string_add(json_area, "authentication",
2947 "authenticationMessageDigest");
2948
2949 if (!OSPF_IS_AREA_BACKBONE(area))
2950 json_object_int_add(json_area,
2951 "virtualAdjacenciesPassingCounter",
2952 area->full_vls);
2953
2954 /* Show SPF calculation times. */
2955 json_object_int_add(json_area, "spfExecutedCounter",
2956 area->spf_calculation);
2957 json_object_int_add(json_area, "lsaNumber", area->lsdb->total);
2958 json_object_int_add(
2959 json_area, "lsaRouterNumber",
2960 ospf_lsdb_count(area->lsdb, OSPF_ROUTER_LSA));
2961 json_object_int_add(
2962 json_area, "lsaRouterChecksum",
2963 ospf_lsdb_checksum(area->lsdb, OSPF_ROUTER_LSA));
2964 json_object_int_add(
2965 json_area, "lsaNetworkNumber",
2966 ospf_lsdb_count(area->lsdb, OSPF_NETWORK_LSA));
2967 json_object_int_add(
2968 json_area, "lsaNetworkChecksum",
2969 ospf_lsdb_checksum(area->lsdb, OSPF_NETWORK_LSA));
2970 json_object_int_add(
2971 json_area, "lsaSummaryNumber",
2972 ospf_lsdb_count(area->lsdb, OSPF_SUMMARY_LSA));
2973 json_object_int_add(
2974 json_area, "lsaSummaryChecksum",
2975 ospf_lsdb_checksum(area->lsdb, OSPF_SUMMARY_LSA));
2976 json_object_int_add(
2977 json_area, "lsaAsbrNumber",
2978 ospf_lsdb_count(area->lsdb, OSPF_ASBR_SUMMARY_LSA));
2979 json_object_int_add(
2980 json_area, "lsaAsbrChecksum",
2981 ospf_lsdb_checksum(area->lsdb, OSPF_ASBR_SUMMARY_LSA));
2982 json_object_int_add(
2983 json_area, "lsaNssaNumber",
2984 ospf_lsdb_count(area->lsdb, OSPF_AS_NSSA_LSA));
2985 json_object_int_add(
2986 json_area, "lsaNssaChecksum",
2987 ospf_lsdb_checksum(area->lsdb, OSPF_AS_NSSA_LSA));
2988 } else {
2989 /* Show number of fully adjacent neighbors. */
2990 vty_out(vty,
2991 " Number of fully adjacent neighbors in this area: %d\n",
2992 area->full_nbrs);
2993
2994 /* Show authentication type. */
2995 vty_out(vty, " Area has ");
2996 if (area->auth_type == OSPF_AUTH_NULL)
2997 vty_out(vty, "no authentication\n");
2998 else if (area->auth_type == OSPF_AUTH_SIMPLE)
2999 vty_out(vty, "simple password authentication\n");
3000 else if (area->auth_type == OSPF_AUTH_CRYPTOGRAPHIC)
3001 vty_out(vty, "message digest authentication\n");
3002
3003 if (!OSPF_IS_AREA_BACKBONE(area))
3004 vty_out(vty,
3005 " Number of full virtual adjacencies going through this area: %d\n",
3006 area->full_vls);
3007
3008 /* Show SPF calculation times. */
3009 vty_out(vty, " SPF algorithm executed %d times\n",
3010 area->spf_calculation);
3011
3012 /* Show number of LSA. */
3013 vty_out(vty, " Number of LSA %ld\n", area->lsdb->total);
3014 vty_out(vty,
3015 " Number of router LSA %ld. Checksum Sum 0x%08x\n",
3016 ospf_lsdb_count(area->lsdb, OSPF_ROUTER_LSA),
3017 ospf_lsdb_checksum(area->lsdb, OSPF_ROUTER_LSA));
3018 vty_out(vty,
3019 " Number of network LSA %ld. Checksum Sum 0x%08x\n",
3020 ospf_lsdb_count(area->lsdb, OSPF_NETWORK_LSA),
3021 ospf_lsdb_checksum(area->lsdb, OSPF_NETWORK_LSA));
3022 vty_out(vty,
3023 " Number of summary LSA %ld. Checksum Sum 0x%08x\n",
3024 ospf_lsdb_count(area->lsdb, OSPF_SUMMARY_LSA),
3025 ospf_lsdb_checksum(area->lsdb, OSPF_SUMMARY_LSA));
3026 vty_out(vty,
3027 " Number of ASBR summary LSA %ld. Checksum Sum 0x%08x\n",
3028 ospf_lsdb_count(area->lsdb, OSPF_ASBR_SUMMARY_LSA),
3029 ospf_lsdb_checksum(area->lsdb, OSPF_ASBR_SUMMARY_LSA));
3030 vty_out(vty, " Number of NSSA LSA %ld. Checksum Sum 0x%08x\n",
3031 ospf_lsdb_count(area->lsdb, OSPF_AS_NSSA_LSA),
3032 ospf_lsdb_checksum(area->lsdb, OSPF_AS_NSSA_LSA));
3033 }
3034
3035 if (use_json) {
3036 json_object_int_add(
3037 json_area, "lsaOpaqueLinkNumber",
3038 ospf_lsdb_count(area->lsdb, OSPF_OPAQUE_LINK_LSA));
3039 json_object_int_add(
3040 json_area, "lsaOpaqueLinkChecksum",
3041 ospf_lsdb_checksum(area->lsdb, OSPF_OPAQUE_LINK_LSA));
3042 json_object_int_add(
3043 json_area, "lsaOpaqueAreaNumber",
3044 ospf_lsdb_count(area->lsdb, OSPF_OPAQUE_AREA_LSA));
3045 json_object_int_add(
3046 json_area, "lsaOpaqueAreaChecksum",
3047 ospf_lsdb_checksum(area->lsdb, OSPF_OPAQUE_AREA_LSA));
3048 } else {
3049 vty_out(vty,
3050 " Number of opaque link LSA %ld. Checksum Sum 0x%08x\n",
3051 ospf_lsdb_count(area->lsdb, OSPF_OPAQUE_LINK_LSA),
3052 ospf_lsdb_checksum(area->lsdb, OSPF_OPAQUE_LINK_LSA));
3053 vty_out(vty,
3054 " Number of opaque area LSA %ld. Checksum Sum 0x%08x\n",
3055 ospf_lsdb_count(area->lsdb, OSPF_OPAQUE_AREA_LSA),
3056 ospf_lsdb_checksum(area->lsdb, OSPF_OPAQUE_AREA_LSA));
3057 }
3058
3059 if (use_json)
3060 json_object_object_add(json_areas,
3061 inet_ntop(AF_INET, &area->area_id,
3062 buf, sizeof(buf)),
3063 json_area);
3064 else
3065 vty_out(vty, "\n");
3066 }
3067
3068 static int show_ip_ospf_common(struct vty *vty, struct ospf *ospf,
3069 json_object *json, uint8_t use_vrf)
3070 {
3071 struct listnode *node, *nnode;
3072 struct ospf_area *area;
3073 struct timeval result;
3074 char timebuf[OSPF_TIME_DUMP_SIZE];
3075 char buf[PREFIX_STRLEN];
3076 json_object *json_vrf = NULL;
3077 json_object *json_areas = NULL;
3078
3079 if (json) {
3080 if (use_vrf)
3081 json_vrf = json_object_new_object();
3082 else
3083 json_vrf = json;
3084 json_areas = json_object_new_object();
3085 }
3086
3087 if (ospf->instance) {
3088 if (json) {
3089 json_object_int_add(json, "ospfInstance",
3090 ospf->instance);
3091 } else {
3092 vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
3093 }
3094 }
3095
3096 ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf);
3097
3098 /* Show Router ID. */
3099 if (json) {
3100 json_object_string_add(json_vrf, "routerId",
3101 inet_ntop(AF_INET, &ospf->router_id,
3102 buf, sizeof(buf)));
3103 } else {
3104 vty_out(vty, " OSPF Routing Process, Router ID: %pI4\n",
3105 &ospf->router_id);
3106 }
3107
3108 /* Graceful shutdown */
3109 if (ospf->t_deferred_shutdown) {
3110 if (json) {
3111 long time_store;
3112 time_store =
3113 monotime_until(
3114 &ospf->t_deferred_shutdown->u.sands,
3115 NULL)
3116 / 1000LL;
3117 json_object_int_add(json_vrf, "deferredShutdownMsecs",
3118 time_store);
3119 } else {
3120 vty_out(vty,
3121 " Deferred shutdown in progress, %s remaining\n",
3122 ospf_timer_dump(ospf->t_deferred_shutdown,
3123 timebuf, sizeof(timebuf)));
3124 }
3125 }
3126
3127 /* Show capability. */
3128 if (json) {
3129 json_object_boolean_true_add(json_vrf, "tosRoutesOnly");
3130 json_object_boolean_true_add(json_vrf, "rfc2328Conform");
3131 if (CHECK_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE)) {
3132 json_object_boolean_true_add(json_vrf,
3133 "rfc1583Compatibility");
3134 }
3135 } else {
3136 vty_out(vty, " Supports only single TOS (TOS0) routes\n");
3137 vty_out(vty, " This implementation conforms to RFC2328\n");
3138 vty_out(vty, " RFC1583Compatibility flag is %s\n",
3139 CHECK_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE)
3140 ? "enabled"
3141 : "disabled");
3142 }
3143
3144 if (json) {
3145 if (CHECK_FLAG(ospf->config, OSPF_OPAQUE_CAPABLE)) {
3146 json_object_boolean_true_add(json_vrf, "opaqueCapable");
3147 }
3148 } else {
3149 vty_out(vty, " OpaqueCapability flag is %s\n",
3150 CHECK_FLAG(ospf->config, OSPF_OPAQUE_CAPABLE)
3151 ? "enabled"
3152 : "disabled");
3153 }
3154
3155 /* Show stub-router configuration */
3156 if (ospf->stub_router_startup_time != OSPF_STUB_ROUTER_UNCONFIGURED
3157 || ospf->stub_router_shutdown_time
3158 != OSPF_STUB_ROUTER_UNCONFIGURED) {
3159 if (json) {
3160 json_object_boolean_true_add(json_vrf,
3161 "stubAdvertisement");
3162 if (ospf->stub_router_startup_time
3163 != OSPF_STUB_ROUTER_UNCONFIGURED)
3164 json_object_int_add(
3165 json_vrf, "postStartEnabledSecs",
3166 ospf->stub_router_startup_time);
3167 if (ospf->stub_router_shutdown_time
3168 != OSPF_STUB_ROUTER_UNCONFIGURED)
3169 json_object_int_add(
3170 json_vrf, "preShutdownEnabledSecs",
3171 ospf->stub_router_shutdown_time);
3172 } else {
3173 vty_out(vty,
3174 " Stub router advertisement is configured\n");
3175 if (ospf->stub_router_startup_time
3176 != OSPF_STUB_ROUTER_UNCONFIGURED)
3177 vty_out(vty,
3178 " Enabled for %us after start-up\n",
3179 ospf->stub_router_startup_time);
3180 if (ospf->stub_router_shutdown_time
3181 != OSPF_STUB_ROUTER_UNCONFIGURED)
3182 vty_out(vty,
3183 " Enabled for %us prior to full shutdown\n",
3184 ospf->stub_router_shutdown_time);
3185 }
3186 }
3187
3188 /* Show SPF timers. */
3189 if (json) {
3190 json_object_int_add(json_vrf, "spfScheduleDelayMsecs",
3191 ospf->spf_delay);
3192 json_object_int_add(json_vrf, "holdtimeMinMsecs",
3193 ospf->spf_holdtime);
3194 json_object_int_add(json_vrf, "holdtimeMaxMsecs",
3195 ospf->spf_max_holdtime);
3196 json_object_int_add(json_vrf, "holdtimeMultplier",
3197 ospf->spf_hold_multiplier);
3198 } else {
3199 vty_out(vty,
3200 " Initial SPF scheduling delay %d millisec(s)\n"
3201 " Minimum hold time between consecutive SPFs %d millisec(s)\n"
3202 " Maximum hold time between consecutive SPFs %d millisec(s)\n"
3203 " Hold time multiplier is currently %d\n",
3204 ospf->spf_delay, ospf->spf_holdtime,
3205 ospf->spf_max_holdtime, ospf->spf_hold_multiplier);
3206 }
3207
3208 if (json) {
3209 if (ospf->ts_spf.tv_sec || ospf->ts_spf.tv_usec) {
3210 long time_store = 0;
3211
3212 time_store =
3213 monotime_since(&ospf->ts_spf, NULL) / 1000LL;
3214 json_object_int_add(json_vrf, "spfLastExecutedMsecs",
3215 time_store);
3216
3217 time_store = (1000 * ospf->ts_spf_duration.tv_sec)
3218 + (ospf->ts_spf_duration.tv_usec / 1000);
3219 json_object_int_add(json_vrf, "spfLastDurationMsecs",
3220 time_store);
3221 } else
3222 json_object_boolean_true_add(json_vrf, "spfHasNotRun");
3223 } else {
3224 vty_out(vty, " SPF algorithm ");
3225 if (ospf->ts_spf.tv_sec || ospf->ts_spf.tv_usec) {
3226 monotime_since(&ospf->ts_spf, &result);
3227 vty_out(vty, "last executed %s ago\n",
3228 ospf_timeval_dump(&result, timebuf,
3229 sizeof(timebuf)));
3230 vty_out(vty, " Last SPF duration %s\n",
3231 ospf_timeval_dump(&ospf->ts_spf_duration,
3232 timebuf, sizeof(timebuf)));
3233 } else
3234 vty_out(vty, "has not been run\n");
3235 }
3236
3237 if (json) {
3238 if (ospf->t_spf_calc) {
3239 long time_store;
3240 time_store =
3241 monotime_until(&ospf->t_spf_calc->u.sands, NULL)
3242 / 1000LL;
3243 json_object_int_add(json_vrf, "spfTimerDueInMsecs",
3244 time_store);
3245 }
3246
3247 json_object_int_add(json_vrf, "lsaMinIntervalMsecs",
3248 ospf->min_ls_interval);
3249 json_object_int_add(json_vrf, "lsaMinArrivalMsecs",
3250 ospf->min_ls_arrival);
3251 /* Show write multiplier values */
3252 json_object_int_add(json_vrf, "writeMultiplier",
3253 ospf->write_oi_count);
3254 /* Show refresh parameters. */
3255 json_object_int_add(json_vrf, "refreshTimerMsecs",
3256 ospf->lsa_refresh_interval * 1000);
3257 } else {
3258 vty_out(vty, " SPF timer %s%s\n",
3259 (ospf->t_spf_calc ? "due in " : "is "),
3260 ospf_timer_dump(ospf->t_spf_calc, timebuf,
3261 sizeof(timebuf)));
3262
3263 vty_out(vty, " LSA minimum interval %d msecs\n",
3264 ospf->min_ls_interval);
3265 vty_out(vty, " LSA minimum arrival %d msecs\n",
3266 ospf->min_ls_arrival);
3267
3268 /* Show write multiplier values */
3269 vty_out(vty, " Write Multiplier set to %d \n",
3270 ospf->write_oi_count);
3271
3272 /* Show refresh parameters. */
3273 vty_out(vty, " Refresh timer %d secs\n",
3274 ospf->lsa_refresh_interval);
3275
3276 /* show max multipath */
3277 vty_out(vty, " Maximum multiple paths(ECMP) supported %d\n",
3278 ospf->max_multipath);
3279 }
3280
3281 /* Show ABR/ASBR flags. */
3282 if (CHECK_FLAG(ospf->flags, OSPF_FLAG_ABR)) {
3283 if (json)
3284 json_object_string_add(
3285 json_vrf, "abrType",
3286 ospf_abr_type_descr_str[ospf->abr_type]);
3287 else
3288 vty_out(vty,
3289 " This router is an ABR, ABR type is: %s\n",
3290 ospf_abr_type_descr_str[ospf->abr_type]);
3291 }
3292 if (CHECK_FLAG(ospf->flags, OSPF_FLAG_ASBR)) {
3293 if (json)
3294 json_object_string_add(
3295 json_vrf, "asbrRouter",
3296 "injectingExternalRoutingInformation");
3297 else
3298 vty_out(vty,
3299 " This router is an ASBR (injecting external routing information)\n");
3300 }
3301
3302 /* Show Number of AS-external-LSAs. */
3303 if (json) {
3304 json_object_int_add(
3305 json_vrf, "lsaExternalCounter",
3306 ospf_lsdb_count(ospf->lsdb, OSPF_AS_EXTERNAL_LSA));
3307 json_object_int_add(
3308 json_vrf, "lsaExternalChecksum",
3309 ospf_lsdb_checksum(ospf->lsdb, OSPF_AS_EXTERNAL_LSA));
3310 } else {
3311 vty_out(vty,
3312 " Number of external LSA %ld. Checksum Sum 0x%08x\n",
3313 ospf_lsdb_count(ospf->lsdb, OSPF_AS_EXTERNAL_LSA),
3314 ospf_lsdb_checksum(ospf->lsdb, OSPF_AS_EXTERNAL_LSA));
3315 }
3316
3317 if (json) {
3318 json_object_int_add(
3319 json_vrf, "lsaAsopaqueCounter",
3320 ospf_lsdb_count(ospf->lsdb, OSPF_OPAQUE_AS_LSA));
3321 json_object_int_add(
3322 json_vrf, "lsaAsOpaqueChecksum",
3323 ospf_lsdb_checksum(ospf->lsdb, OSPF_OPAQUE_AS_LSA));
3324 } else {
3325 vty_out(vty,
3326 " Number of opaque AS LSA %ld. Checksum Sum 0x%08x\n",
3327 ospf_lsdb_count(ospf->lsdb, OSPF_OPAQUE_AS_LSA),
3328 ospf_lsdb_checksum(ospf->lsdb, OSPF_OPAQUE_AS_LSA));
3329 }
3330
3331 /* Show number of areas attached. */
3332 if (json)
3333 json_object_int_add(json_vrf, "attachedAreaCounter",
3334 listcount(ospf->areas));
3335 else
3336 vty_out(vty, " Number of areas attached to this router: %d\n",
3337 listcount(ospf->areas));
3338
3339 if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES)) {
3340 if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL)) {
3341 if (json)
3342 json_object_boolean_true_add(
3343 json_vrf, "adjacencyChangesLoggedAll");
3344 else
3345 vty_out(vty,
3346 " All adjacency changes are logged\n");
3347 } else {
3348 if (json)
3349 json_object_boolean_true_add(
3350 json_vrf, "adjacencyChangesLogged");
3351 else
3352 vty_out(vty, " Adjacency changes are logged\n");
3353 }
3354 }
3355
3356 /* show LDP-Sync status */
3357 ospf_ldp_sync_show_info(vty, ospf, json_vrf, json ? 1 : 0);
3358
3359 /* Show each area status. */
3360 for (ALL_LIST_ELEMENTS(ospf->areas, node, nnode, area))
3361 show_ip_ospf_area(vty, area, json_areas, json ? 1 : 0);
3362
3363 if (json) {
3364 if (use_vrf) {
3365 json_object_object_add(json_vrf, "areas", json_areas);
3366 if (ospf->vrf_id == VRF_DEFAULT)
3367 json_object_object_add(json, "default",
3368 json_vrf);
3369 else
3370 json_object_object_add(json, ospf->name,
3371 json_vrf);
3372 } else {
3373 json_object_object_add(json, "areas", json_areas);
3374 }
3375 } else
3376 vty_out(vty, "\n");
3377
3378 return CMD_SUCCESS;
3379 }
3380
3381 DEFUN (show_ip_ospf,
3382 show_ip_ospf_cmd,
3383 "show ip ospf [vrf <NAME|all>] [json]",
3384 SHOW_STR
3385 IP_STR
3386 "OSPF information\n"
3387 VRF_CMD_HELP_STR
3388 "All VRFs\n"
3389 JSON_STR)
3390 {
3391 struct ospf *ospf;
3392 bool uj = use_json(argc, argv);
3393 struct listnode *node = NULL;
3394 char *vrf_name = NULL;
3395 bool all_vrf = false;
3396 int ret = CMD_SUCCESS;
3397 int inst = 0;
3398 int idx_vrf = 0;
3399 json_object *json = NULL;
3400 uint8_t use_vrf = 0;
3401
3402 if (listcount(om->ospf) == 0)
3403 return CMD_SUCCESS;
3404
3405 OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
3406
3407 if (uj)
3408 json = json_object_new_object();
3409
3410 /* vrf input is provided could be all or specific vrf*/
3411 if (vrf_name) {
3412 bool ospf_output = false;
3413
3414 use_vrf = 1;
3415
3416 if (all_vrf) {
3417 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
3418 if (!ospf->oi_running)
3419 continue;
3420 ospf_output = true;
3421 ret = show_ip_ospf_common(vty, ospf, json,
3422 use_vrf);
3423 }
3424 if (uj) {
3425 vty_out(vty, "%s\n",
3426 json_object_to_json_string_ext(
3427 json, JSON_C_TO_STRING_PRETTY));
3428 json_object_free(json);
3429 } else if (!ospf_output)
3430 vty_out(vty, "%% OSPF instance not found\n");
3431 return ret;
3432 }
3433 ospf = ospf_lookup_by_inst_name(inst, vrf_name);
3434 if ((ospf == NULL) || !ospf->oi_running) {
3435 if (uj) {
3436 vty_out(vty, "%s\n",
3437 json_object_to_json_string_ext(
3438 json, JSON_C_TO_STRING_PRETTY));
3439 json_object_free(json);
3440 } else
3441 vty_out(vty, "%% OSPF instance not found\n");
3442
3443 return CMD_SUCCESS;
3444 }
3445 } else {
3446 ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
3447 /* Display default ospf (instance 0) info */
3448 if (ospf == NULL || !ospf->oi_running) {
3449 if (uj) {
3450 vty_out(vty, "%s\n",
3451 json_object_to_json_string_ext(
3452 json, JSON_C_TO_STRING_PRETTY));
3453 json_object_free(json);
3454 } else
3455 vty_out(vty, "%% OSPF instance not found\n");
3456
3457 return CMD_SUCCESS;
3458 }
3459 }
3460
3461 if (ospf) {
3462 show_ip_ospf_common(vty, ospf, json, use_vrf);
3463 if (uj)
3464 vty_out(vty, "%s\n",
3465 json_object_to_json_string_ext(
3466 json, JSON_C_TO_STRING_PRETTY));
3467 }
3468
3469 if (uj)
3470 json_object_free(json);
3471
3472 return ret;
3473 }
3474
3475 DEFUN (show_ip_ospf_instance,
3476 show_ip_ospf_instance_cmd,
3477 "show ip ospf (1-65535) [json]",
3478 SHOW_STR
3479 IP_STR
3480 "OSPF information\n"
3481 "Instance ID\n"
3482 JSON_STR)
3483 {
3484 int idx_number = 3;
3485 struct ospf *ospf;
3486 unsigned short instance = 0;
3487 bool uj = use_json(argc, argv);
3488 int ret = CMD_SUCCESS;
3489 json_object *json = NULL;
3490
3491 instance = strtoul(argv[idx_number]->arg, NULL, 10);
3492 if (instance != ospf_instance)
3493 return CMD_NOT_MY_INSTANCE;
3494
3495 ospf = ospf_lookup_instance(instance);
3496 if (!ospf || !ospf->oi_running)
3497 return CMD_SUCCESS;
3498
3499 if (uj)
3500 json = json_object_new_object();
3501
3502 ret = show_ip_ospf_common(vty, ospf, json, 0);
3503
3504 if (uj) {
3505 vty_out(vty, "%s\n", json_object_to_json_string_ext(
3506 json, JSON_C_TO_STRING_PRETTY));
3507 json_object_free(json);
3508 }
3509
3510 return ret;
3511 }
3512
3513 static void ospf_interface_auth_show(struct vty *vty, struct ospf_interface *oi,
3514 json_object *json, bool use_json)
3515 {
3516 int auth_type;
3517
3518 auth_type = OSPF_IF_PARAM(oi, auth_type);
3519
3520 switch (auth_type) {
3521 case OSPF_AUTH_NULL:
3522 if (use_json)
3523 json_object_string_add(json, "authentication",
3524 "authenticationNone");
3525 else
3526 vty_out(vty, " Authentication NULL is enabled\n");
3527 break;
3528 case OSPF_AUTH_SIMPLE: {
3529 if (use_json)
3530 json_object_string_add(json, "authentication",
3531 "authenticationSimplePassword");
3532 else
3533 vty_out(vty,
3534 " Simple password authentication enabled\n");
3535 break;
3536 }
3537 case OSPF_AUTH_CRYPTOGRAPHIC: {
3538 struct crypt_key *ckey;
3539
3540 if (list_isempty(OSPF_IF_PARAM(oi, auth_crypt)))
3541 return;
3542
3543 ckey = listgetdata(listtail(OSPF_IF_PARAM(oi, auth_crypt)));
3544 if (ckey) {
3545 if (use_json) {
3546 json_object_string_add(json, "authentication",
3547 "authenticationMessageDigest");
3548 } else {
3549 vty_out(vty,
3550 " Cryptographic authentication enabled\n");
3551 vty_out(vty, " Algorithm:MD5\n");
3552 }
3553 }
3554 break;
3555 }
3556 default:
3557 break;
3558 }
3559 }
3560
3561 static void show_ip_ospf_interface_sub(struct vty *vty, struct ospf *ospf,
3562 struct interface *ifp,
3563 json_object *json_interface_sub,
3564 bool use_json)
3565 {
3566 int is_up;
3567 struct ospf_neighbor *nbr;
3568 struct route_node *rn;
3569 char buf[PREFIX_STRLEN];
3570 uint32_t bandwidth = ifp->bandwidth ? ifp->bandwidth : ifp->speed;
3571
3572 /* Is interface up? */
3573 if (use_json) {
3574 is_up = if_is_operative(ifp);
3575 if (is_up)
3576 json_object_boolean_true_add(json_interface_sub,
3577 "ifUp");
3578 else
3579 json_object_boolean_false_add(json_interface_sub,
3580 "ifDown");
3581
3582 json_object_int_add(json_interface_sub, "ifIndex",
3583 ifp->ifindex);
3584 json_object_int_add(json_interface_sub, "mtuBytes", ifp->mtu);
3585 json_object_int_add(json_interface_sub, "bandwidthMbit",
3586 bandwidth);
3587 json_object_string_add(json_interface_sub, "ifFlags",
3588 if_flag_dump(ifp->flags));
3589 } else {
3590 vty_out(vty, "%s is %s\n", ifp->name,
3591 ((is_up = if_is_operative(ifp)) ? "up" : "down"));
3592 vty_out(vty, " ifindex %u, MTU %u bytes, BW %u Mbit %s\n",
3593 ifp->ifindex, ifp->mtu, bandwidth,
3594 if_flag_dump(ifp->flags));
3595 }
3596
3597 /* Is interface OSPF enabled? */
3598 if (use_json) {
3599 if (ospf_oi_count(ifp) == 0) {
3600 json_object_boolean_false_add(json_interface_sub,
3601 "ospfEnabled");
3602 return;
3603 } else if (!is_up) {
3604 json_object_boolean_false_add(json_interface_sub,
3605 "ospfRunning");
3606 return;
3607 } else
3608 json_object_boolean_true_add(json_interface_sub,
3609 "ospfEnabled");
3610 } else {
3611 if (ospf_oi_count(ifp) == 0) {
3612 vty_out(vty, " OSPF not enabled on this interface\n");
3613 return;
3614 } else if (!is_up) {
3615 vty_out(vty,
3616 " OSPF is enabled, but not running on this interface\n");
3617 return;
3618 }
3619 }
3620
3621 for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) {
3622 struct ospf_interface *oi = rn->info;
3623
3624 if (oi == NULL)
3625 continue;
3626
3627 if (CHECK_FLAG(oi->connected->flags, ZEBRA_IFA_UNNUMBERED)) {
3628 if (use_json)
3629 json_object_boolean_true_add(json_interface_sub,
3630 "ifUnnumbered");
3631 else
3632 vty_out(vty, " This interface is UNNUMBERED,");
3633 } else {
3634 struct in_addr dest;
3635 const char *dstr;
3636
3637 /* Show OSPF interface information. */
3638 if (use_json) {
3639 json_object_string_add(
3640 json_interface_sub, "ipAddress",
3641 inet_ntop(AF_INET,
3642 &oi->address->u.prefix4,
3643 buf, sizeof(buf)));
3644 json_object_int_add(json_interface_sub,
3645 "ipAddressPrefixlen",
3646 oi->address->prefixlen);
3647 } else
3648 vty_out(vty, " Internet Address %pFX,",
3649 oi->address);
3650
3651 /* For Vlinks, showing the peer address is
3652 * probably more informative than the local
3653 * interface that is being used */
3654 if (oi->type == OSPF_IFTYPE_VIRTUALLINK) {
3655 dstr = "Peer";
3656 dest = oi->vl_data->peer_addr;
3657 } else if (CONNECTED_PEER(oi->connected)
3658 && oi->connected->destination) {
3659 dstr = "Peer";
3660 dest = oi->connected->destination->u.prefix4;
3661 } else {
3662 dstr = "Broadcast";
3663 dest.s_addr = ipv4_broadcast_addr(
3664 oi->connected->address->u.prefix4.s_addr,
3665 oi->connected->address->prefixlen);
3666 }
3667
3668 if (use_json) {
3669 json_object_string_add(
3670 json_interface_sub,
3671 "ospfIfType", dstr);
3672 if (oi->type == OSPF_IFTYPE_VIRTUALLINK)
3673 json_object_string_add(
3674 json_interface_sub,
3675 "vlinkPeer",
3676 inet_ntop(AF_INET, &dest,
3677 buf, sizeof(buf)));
3678 else
3679 json_object_string_add(
3680 json_interface_sub,
3681 "localIfUsed",
3682 inet_ntop(AF_INET, &dest,
3683 buf, sizeof(buf)));
3684 } else
3685 vty_out(vty, " %s %pI4,", dstr,
3686 &dest);
3687 }
3688 if (use_json) {
3689 json_object_string_add(json_interface_sub, "area",
3690 ospf_area_desc_string(oi->area));
3691 if (OSPF_IF_PARAM(oi, mtu_ignore))
3692 json_object_boolean_true_add(
3693 json_interface_sub,
3694 "mtuMismatchDetect");
3695 json_object_string_add(
3696 json_interface_sub, "routerId",
3697 inet_ntop(AF_INET, &ospf->router_id,
3698 buf, sizeof(buf)));
3699 json_object_string_add(json_interface_sub,
3700 "networkType",
3701 ospf_network_type_str[oi->type]);
3702 json_object_int_add(json_interface_sub, "cost",
3703 oi->output_cost);
3704 json_object_int_add(
3705 json_interface_sub, "transmitDelaySecs",
3706 OSPF_IF_PARAM(oi, transmit_delay));
3707 json_object_string_add(json_interface_sub, "state",
3708 lookup_msg(ospf_ism_state_msg,
3709 oi->state, NULL));
3710 json_object_int_add(json_interface_sub, "priority",
3711 PRIORITY(oi));
3712 } else {
3713 vty_out(vty, " Area %s\n",
3714 ospf_area_desc_string(oi->area));
3715
3716 vty_out(vty, " MTU mismatch detection: %s\n",
3717 OSPF_IF_PARAM(oi, mtu_ignore) ? "disabled"
3718 : "enabled");
3719
3720 vty_out(vty,
3721 " Router ID %pI4, Network Type %s, Cost: %d\n",
3722 &ospf->router_id,
3723 ospf_network_type_str[oi->type],
3724 oi->output_cost);
3725
3726 vty_out(vty,
3727 " Transmit Delay is %d sec, State %s, Priority %d\n",
3728 OSPF_IF_PARAM(oi, transmit_delay),
3729 lookup_msg(ospf_ism_state_msg, oi->state, NULL),
3730 PRIORITY(oi));
3731 }
3732
3733 /* Show DR information. */
3734 if (DR(oi).s_addr == INADDR_ANY) {
3735 if (!use_json)
3736 vty_out(vty,
3737 " No backup designated router on this network\n");
3738 } else {
3739 nbr = ospf_nbr_lookup_by_addr(oi->nbrs, &BDR(oi));
3740 if (nbr == NULL) {
3741 if (!use_json)
3742 vty_out(vty,
3743 " No backup designated router on this network\n");
3744 } else {
3745 if (use_json) {
3746 json_object_string_add(
3747 json_interface_sub, "bdrId",
3748 inet_ntop(AF_INET,
3749 &nbr->router_id,
3750 buf, sizeof(buf)));
3751 json_object_string_add(
3752 json_interface_sub,
3753 "bdrAddress",
3754 inet_ntop(AF_INET,
3755 &nbr->address.u
3756 .prefix4,
3757 buf, sizeof(buf)));
3758 } else {
3759 vty_out(vty,
3760 " Backup Designated Router (ID) %pI4,",
3761 &nbr->router_id);
3762 vty_out(vty, " Interface Address %pI4\n",
3763 &nbr->address.u.prefix4);
3764 }
3765 }
3766 }
3767
3768 /* Next network-LSA sequence number we'll use, if we're elected
3769 * DR */
3770 if (oi->params
3771 && ntohl(oi->params->network_lsa_seqnum)
3772 != OSPF_INITIAL_SEQUENCE_NUMBER) {
3773 if (use_json)
3774 json_object_int_add(
3775 json_interface_sub,
3776 "networkLsaSequence",
3777 ntohl(oi->params->network_lsa_seqnum));
3778 else
3779 vty_out(vty,
3780 " Saved Network-LSA sequence number 0x%x\n",
3781 ntohl(oi->params->network_lsa_seqnum));
3782 }
3783
3784 if (use_json) {
3785 if (OI_MEMBER_CHECK(oi, MEMBER_ALLROUTERS)
3786 || OI_MEMBER_CHECK(oi, MEMBER_DROUTERS)) {
3787 if (OI_MEMBER_CHECK(oi, MEMBER_ALLROUTERS))
3788 json_object_boolean_true_add(
3789 json_interface_sub,
3790 "mcastMemberOspfAllRouters");
3791 if (OI_MEMBER_CHECK(oi, MEMBER_DROUTERS))
3792 json_object_boolean_true_add(
3793 json_interface_sub,
3794 "mcastMemberOspfDesignatedRouters");
3795 }
3796 } else {
3797 vty_out(vty, " Multicast group memberships:");
3798 if (OI_MEMBER_CHECK(oi, MEMBER_ALLROUTERS)
3799 || OI_MEMBER_CHECK(oi, MEMBER_DROUTERS)) {
3800 if (OI_MEMBER_CHECK(oi, MEMBER_ALLROUTERS))
3801 vty_out(vty, " OSPFAllRouters");
3802 if (OI_MEMBER_CHECK(oi, MEMBER_DROUTERS))
3803 vty_out(vty, " OSPFDesignatedRouters");
3804 } else
3805 vty_out(vty, " <None>");
3806 vty_out(vty, "\n");
3807 }
3808
3809 if (use_json) {
3810 if (OSPF_IF_PARAM(oi, fast_hello) == 0)
3811 json_object_int_add(
3812 json_interface_sub, "timerMsecs",
3813 OSPF_IF_PARAM(oi, v_hello) * 1000);
3814 else
3815 json_object_int_add(
3816 json_interface_sub, "timerMsecs",
3817 1000 / OSPF_IF_PARAM(oi, fast_hello));
3818 json_object_int_add(json_interface_sub,
3819 "timerDeadSecs",
3820 OSPF_IF_PARAM(oi, v_wait));
3821 json_object_int_add(json_interface_sub,
3822 "timerWaitSecs",
3823 OSPF_IF_PARAM(oi, v_wait));
3824 json_object_int_add(
3825 json_interface_sub, "timerRetransmitSecs",
3826 OSPF_IF_PARAM(oi, retransmit_interval));
3827 } else {
3828 vty_out(vty, " Timer intervals configured,");
3829 vty_out(vty, " Hello ");
3830 if (OSPF_IF_PARAM(oi, fast_hello) == 0)
3831 vty_out(vty, "%ds,",
3832 OSPF_IF_PARAM(oi, v_hello));
3833 else
3834 vty_out(vty, "%dms,",
3835 1000 / OSPF_IF_PARAM(oi, fast_hello));
3836 vty_out(vty, " Dead %ds, Wait %ds, Retransmit %d\n",
3837 OSPF_IF_PARAM(oi, v_wait),
3838 OSPF_IF_PARAM(oi, v_wait),
3839 OSPF_IF_PARAM(oi, retransmit_interval));
3840 }
3841
3842 if (OSPF_IF_PASSIVE_STATUS(oi) == OSPF_IF_ACTIVE) {
3843 char timebuf[OSPF_TIME_DUMP_SIZE];
3844 if (use_json) {
3845 long time_store = 0;
3846 if (oi->t_hello)
3847 time_store =
3848 monotime_until(
3849 &oi->t_hello->u.sands,
3850 NULL)
3851 / 1000LL;
3852 json_object_int_add(json_interface_sub,
3853 "timerHelloInMsecs",
3854 time_store);
3855 } else
3856 vty_out(vty, " Hello due in %s\n",
3857 ospf_timer_dump(oi->t_hello, timebuf,
3858 sizeof(timebuf)));
3859 } else /* passive-interface is set */
3860 {
3861 if (use_json)
3862 json_object_boolean_true_add(
3863 json_interface_sub,
3864 "timerPassiveIface");
3865 else
3866 vty_out(vty,
3867 " No Hellos (Passive interface)\n");
3868 }
3869
3870 if (use_json) {
3871 json_object_int_add(json_interface_sub, "nbrCount",
3872 ospf_nbr_count(oi, 0));
3873 json_object_int_add(json_interface_sub,
3874 "nbrAdjacentCount",
3875 ospf_nbr_count(oi, NSM_Full));
3876 } else
3877 vty_out(vty,
3878 " Neighbor Count is %d, Adjacent neighbor count is %d\n",
3879 ospf_nbr_count(oi, 0),
3880 ospf_nbr_count(oi, NSM_Full));
3881
3882 ospf_interface_bfd_show(vty, ifp, json_interface_sub);
3883
3884 /* OSPF Authentication information */
3885 ospf_interface_auth_show(vty, oi, json_interface_sub, use_json);
3886 }
3887 }
3888
3889 static int show_ip_ospf_interface_common(struct vty *vty, struct ospf *ospf,
3890 char *intf_name, uint8_t use_vrf,
3891 json_object *json, bool use_json)
3892 {
3893 struct interface *ifp;
3894 struct vrf *vrf = vrf_lookup_by_id(ospf->vrf_id);
3895 json_object *json_vrf = NULL;
3896 json_object *json_interface_sub = NULL, *json_interface = NULL;
3897
3898 if (use_json) {
3899 if (use_vrf)
3900 json_vrf = json_object_new_object();
3901 else
3902 json_vrf = json;
3903 json_interface = json_object_new_object();
3904 }
3905
3906 if (ospf->instance) {
3907 if (use_json)
3908 json_object_int_add(json, "ospfInstance",
3909 ospf->instance);
3910 else
3911 vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
3912 }
3913
3914 ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf);
3915
3916 if (intf_name == NULL) {
3917 /* Show All Interfaces.*/
3918 FOR_ALL_INTERFACES (vrf, ifp) {
3919 if (ospf_oi_count(ifp)) {
3920 if (use_json) {
3921 json_interface_sub =
3922 json_object_new_object();
3923 }
3924 show_ip_ospf_interface_sub(vty, ospf, ifp,
3925 json_interface_sub,
3926 use_json);
3927
3928 if (use_json) {
3929 json_object_object_add(
3930 json_interface, ifp->name,
3931 json_interface_sub);
3932 }
3933 }
3934 }
3935 if (use_json)
3936 json_object_object_add(json_vrf, "interfaces",
3937 json_interface);
3938 } else {
3939 /* Interface name is specified. */
3940 ifp = if_lookup_by_name(intf_name, ospf->vrf_id);
3941 if (ifp == NULL) {
3942 if (use_json)
3943 json_object_boolean_true_add(json_vrf,
3944 "noSuchIface");
3945 else
3946 vty_out(vty, "No such interface name\n");
3947 } else {
3948 if (use_json) {
3949 json_interface_sub = json_object_new_object();
3950 json_interface = json_object_new_object();
3951 }
3952
3953 show_ip_ospf_interface_sub(
3954 vty, ospf, ifp, json_interface_sub, use_json);
3955
3956 if (use_json) {
3957 json_object_object_add(json_interface,
3958 ifp->name,
3959 json_interface_sub);
3960 json_object_object_add(json_vrf, "interfaces",
3961 json_interface);
3962 }
3963 }
3964 }
3965
3966 if (use_json) {
3967 if (use_vrf) {
3968 if (ospf->vrf_id == VRF_DEFAULT)
3969 json_object_object_add(json, "default",
3970 json_vrf);
3971 else
3972 json_object_object_add(json, ospf->name,
3973 json_vrf);
3974 }
3975 } else
3976 vty_out(vty, "\n");
3977
3978 return CMD_SUCCESS;
3979 }
3980
3981 static void show_ip_ospf_interface_traffic_sub(struct vty *vty,
3982 struct ospf_interface *oi,
3983 json_object *json_interface_sub,
3984 bool use_json)
3985 {
3986 if (use_json) {
3987 json_object_int_add(json_interface_sub, "ifIndex",
3988 oi->ifp->ifindex);
3989 json_object_int_add(json_interface_sub, "helloIn",
3990 oi->hello_in);
3991 json_object_int_add(json_interface_sub, "helloOut",
3992 oi->hello_out);
3993 json_object_int_add(json_interface_sub, "dbDescIn",
3994 oi->db_desc_in);
3995 json_object_int_add(json_interface_sub, "dbDescOut",
3996 oi->db_desc_out);
3997 json_object_int_add(json_interface_sub, "lsReqIn",
3998 oi->ls_req_in);
3999 json_object_int_add(json_interface_sub, "lsReqOut",
4000 oi->ls_req_out);
4001 json_object_int_add(json_interface_sub, "lsUpdIn",
4002 oi->ls_upd_in);
4003 json_object_int_add(json_interface_sub, "lsUpdOut",
4004 oi->ls_upd_out);
4005 json_object_int_add(json_interface_sub, "lsAckIn",
4006 oi->ls_ack_in);
4007 json_object_int_add(json_interface_sub, "lsAckOut",
4008 oi->ls_ack_out);
4009 } else {
4010 vty_out(vty,
4011 "%-10s %8u/%-8u %7u/%-7u %7u/%-7u %7u/%-7u %7u/%-7u\n",
4012 oi->ifp->name, oi->hello_in, oi->hello_out,
4013 oi->db_desc_in, oi->db_desc_out, oi->ls_req_in,
4014 oi->ls_req_out, oi->ls_upd_in, oi->ls_upd_out,
4015 oi->ls_ack_in, oi->ls_ack_out);
4016 }
4017 }
4018
4019 /* OSPFv2 Packet Counters */
4020 static int show_ip_ospf_interface_traffic_common(
4021 struct vty *vty, struct ospf *ospf, char *intf_name, json_object *json,
4022 int display_once, uint8_t use_vrf, bool use_json)
4023 {
4024 struct vrf *vrf = NULL;
4025 struct interface *ifp = NULL;
4026 json_object *json_vrf = NULL;
4027 json_object *json_interface_sub = NULL;
4028
4029 if (!use_json && !display_once) {
4030 vty_out(vty, "\n");
4031 vty_out(vty, "%-12s%-17s%-17s%-17s%-17s%-17s\n", "Interface",
4032 " HELLO", " DB-Desc", " LS-Req", " LS-Update",
4033 " LS-Ack");
4034 vty_out(vty, "%-10s%-18s%-18s%-17s%-17s%-17s\n", "",
4035 " Rx/Tx", " Rx/Tx", " Rx/Tx", " Rx/Tx",
4036 " Rx/Tx");
4037 vty_out(vty,
4038 "--------------------------------------------------------------------------------------------\n");
4039 } else if (use_json) {
4040 if (use_vrf)
4041 json_vrf = json_object_new_object();
4042 else
4043 json_vrf = json;
4044 }
4045
4046 ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf);
4047
4048 if (intf_name == NULL) {
4049 vrf = vrf_lookup_by_id(ospf->vrf_id);
4050 FOR_ALL_INTERFACES (vrf, ifp) {
4051 struct route_node *rn;
4052 struct ospf_interface *oi;
4053
4054 if (ospf_oi_count(ifp) == 0)
4055 continue;
4056
4057 for (rn = route_top(IF_OIFS(ifp)); rn;
4058 rn = route_next(rn)) {
4059 oi = rn->info;
4060
4061 if (oi == NULL)
4062 continue;
4063
4064 if (use_json) {
4065 json_interface_sub =
4066 json_object_new_object();
4067 }
4068
4069 show_ip_ospf_interface_traffic_sub(
4070 vty, oi, json_interface_sub, use_json);
4071 if (use_json) {
4072 json_object_object_add(
4073 json_vrf, ifp->name,
4074 json_interface_sub);
4075 }
4076 }
4077 }
4078 } else {
4079 /* Interface name is specified. */
4080 ifp = if_lookup_by_name(intf_name, ospf->vrf_id);
4081 if (ifp != NULL) {
4082 struct route_node *rn;
4083 struct ospf_interface *oi;
4084
4085 if (ospf_oi_count(ifp) == 0) {
4086 vty_out(vty,
4087 " OSPF not enabled on this interface %s\n",
4088 ifp->name);
4089 return CMD_SUCCESS;
4090 }
4091
4092 for (rn = route_top(IF_OIFS(ifp)); rn;
4093 rn = route_next(rn)) {
4094 oi = rn->info;
4095
4096 if (use_json) {
4097 json_interface_sub =
4098 json_object_new_object();
4099 }
4100
4101 show_ip_ospf_interface_traffic_sub(
4102 vty, oi, json_interface_sub, use_json);
4103 if (use_json) {
4104 json_object_object_add(
4105 json_vrf, ifp->name,
4106 json_interface_sub);
4107 }
4108 }
4109 }
4110 }
4111
4112 if (use_json) {
4113 if (use_vrf) {
4114 if (ospf->vrf_id == VRF_DEFAULT)
4115 json_object_object_add(json, "default",
4116 json_vrf);
4117 else
4118 json_object_object_add(json, ospf->name,
4119 json_vrf);
4120 }
4121 } else
4122 vty_out(vty, "\n");
4123
4124 return CMD_SUCCESS;
4125 }
4126
4127 DEFUN (show_ip_ospf_interface,
4128 show_ip_ospf_interface_cmd,
4129 "show ip ospf [vrf <NAME|all>] interface [INTERFACE] [json]",
4130 SHOW_STR
4131 IP_STR
4132 "OSPF information\n"
4133 VRF_CMD_HELP_STR
4134 "All VRFs\n"
4135 "Interface information\n"
4136 "Interface name\n"
4137 JSON_STR)
4138 {
4139 struct ospf *ospf;
4140 bool uj = use_json(argc, argv);
4141 struct listnode *node = NULL;
4142 char *vrf_name = NULL, *intf_name = NULL;
4143 bool all_vrf = false;
4144 int ret = CMD_SUCCESS;
4145 int inst = 0;
4146 int idx_vrf = 0, idx_intf = 0;
4147 uint8_t use_vrf = 0;
4148 json_object *json = NULL;
4149
4150 OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
4151
4152 if (argv_find(argv, argc, "INTERFACE", &idx_intf))
4153 intf_name = argv[idx_intf]->arg;
4154
4155 if (uj)
4156 json = json_object_new_object();
4157
4158 /* vrf input is provided could be all or specific vrf*/
4159 if (vrf_name) {
4160 use_vrf = 1;
4161 if (all_vrf) {
4162 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
4163 if (!ospf->oi_running)
4164 continue;
4165 ret = show_ip_ospf_interface_common(
4166 vty, ospf, intf_name, use_vrf, json,
4167 uj);
4168 }
4169
4170 if (uj) {
4171 vty_out(vty, "%s\n",
4172 json_object_to_json_string_ext(
4173 json, JSON_C_TO_STRING_PRETTY));
4174 json_object_free(json);
4175 } else if (!ospf)
4176 vty_out(vty, "%% OSPF instance not found\n");
4177
4178 return ret;
4179 }
4180 ospf = ospf_lookup_by_inst_name(inst, vrf_name);
4181 if (ospf == NULL || !ospf->oi_running) {
4182 if (uj) {
4183 vty_out(vty, "%s\n",
4184 json_object_to_json_string_ext(
4185 json, JSON_C_TO_STRING_PRETTY));
4186 json_object_free(json);
4187 } else
4188 vty_out(vty, "%% OSPF instance not found\n");
4189
4190 return CMD_SUCCESS;
4191 }
4192 ret = show_ip_ospf_interface_common(vty, ospf, intf_name,
4193 use_vrf, json, uj);
4194
4195 } else {
4196 /* Display default ospf (instance 0) info */
4197 ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
4198 if (ospf == NULL || !ospf->oi_running) {
4199 if (uj) {
4200 vty_out(vty, "%s\n",
4201 json_object_to_json_string_ext(
4202 json, JSON_C_TO_STRING_PRETTY));
4203 json_object_free(json);
4204 } else
4205 vty_out(vty, "%% OSPF instance not found\n");
4206
4207 return CMD_SUCCESS;
4208 }
4209 ret = show_ip_ospf_interface_common(vty, ospf, intf_name,
4210 use_vrf, json, uj);
4211 }
4212
4213 if (uj) {
4214 vty_out(vty, "%s\n", json_object_to_json_string_ext(
4215 json, JSON_C_TO_STRING_PRETTY));
4216 json_object_free(json);
4217 }
4218
4219 return ret;
4220 }
4221
4222 DEFUN (show_ip_ospf_instance_interface,
4223 show_ip_ospf_instance_interface_cmd,
4224 "show ip ospf (1-65535) interface [INTERFACE] [json]",
4225 SHOW_STR
4226 IP_STR
4227 "OSPF information\n"
4228 "Instance ID\n"
4229 "Interface information\n"
4230 "Interface name\n"
4231 JSON_STR)
4232 {
4233 int idx_number = 3;
4234 int idx_intf = 0;
4235 struct ospf *ospf;
4236 unsigned short instance = 0;
4237 bool uj = use_json(argc, argv);
4238 char *intf_name = NULL;
4239 int ret = CMD_SUCCESS;
4240 json_object *json = NULL;
4241
4242 instance = strtoul(argv[idx_number]->arg, NULL, 10);
4243 if (instance != ospf_instance)
4244 return CMD_NOT_MY_INSTANCE;
4245
4246 ospf = ospf_lookup_instance(instance);
4247 if (!ospf || !ospf->oi_running)
4248 return CMD_SUCCESS;
4249
4250 if (uj)
4251 json = json_object_new_object();
4252
4253 if (argv_find(argv, argc, "INTERFACE", &idx_intf))
4254 intf_name = argv[idx_intf]->arg;
4255
4256 ret = show_ip_ospf_interface_common(vty, ospf, intf_name, 0, json, uj);
4257
4258 if (uj) {
4259 vty_out(vty, "%s\n", json_object_to_json_string_ext(
4260 json, JSON_C_TO_STRING_PRETTY));
4261 json_object_free(json);
4262 }
4263
4264 return ret;
4265 }
4266
4267 DEFUN (show_ip_ospf_interface_traffic,
4268 show_ip_ospf_interface_traffic_cmd,
4269 "show ip ospf [vrf <NAME|all>] interface traffic [INTERFACE] [json]",
4270 SHOW_STR
4271 IP_STR
4272 "OSPF information\n"
4273 VRF_CMD_HELP_STR
4274 "All VRFs\n"
4275 "Interface information\n"
4276 "Protocol Packet counters\n"
4277 "Interface name\n"
4278 JSON_STR)
4279 {
4280 struct ospf *ospf = NULL;
4281 struct listnode *node = NULL;
4282 char *vrf_name = NULL, *intf_name = NULL;
4283 bool all_vrf = false;
4284 int inst = 0;
4285 int idx_vrf = 0, idx_intf = 0;
4286 bool uj = use_json(argc, argv);
4287 json_object *json = NULL;
4288 int ret = CMD_SUCCESS;
4289 int display_once = 0;
4290 uint8_t use_vrf = 0;
4291
4292 OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
4293
4294 if (argv_find(argv, argc, "INTERFACE", &idx_intf))
4295 intf_name = argv[idx_intf]->arg;
4296
4297 if (uj)
4298 json = json_object_new_object();
4299
4300 if (vrf_name) {
4301 use_vrf = 1;
4302 if (all_vrf) {
4303 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
4304 if (!ospf->oi_running)
4305 continue;
4306
4307 ret = show_ip_ospf_interface_traffic_common(
4308 vty, ospf, intf_name, json,
4309 display_once, use_vrf, uj);
4310 display_once = 1;
4311 }
4312
4313 if (uj) {
4314 vty_out(vty, "%s\n",
4315 json_object_to_json_string_ext(
4316 json, JSON_C_TO_STRING_PRETTY));
4317 json_object_free(json);
4318 }
4319
4320 return ret;
4321 }
4322 ospf = ospf_lookup_by_inst_name(inst, vrf_name);
4323 if (ospf == NULL || !ospf->oi_running) {
4324 if (uj)
4325 json_object_free(json);
4326 return CMD_SUCCESS;
4327 }
4328
4329 ret = show_ip_ospf_interface_traffic_common(
4330 vty, ospf, intf_name, json, display_once, use_vrf, uj);
4331 } else {
4332 ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
4333 if (ospf == NULL || !ospf->oi_running) {
4334 if (uj)
4335 json_object_free(json);
4336 return CMD_SUCCESS;
4337 }
4338
4339 ret = show_ip_ospf_interface_traffic_common(
4340 vty, ospf, intf_name, json, display_once, use_vrf, uj);
4341 }
4342
4343 if (uj) {
4344 vty_out(vty, "%s\n", json_object_to_json_string_ext(
4345 json, JSON_C_TO_STRING_PRETTY));
4346 json_object_free(json);
4347 }
4348
4349 return ret;
4350 }
4351
4352
4353 static void show_ip_ospf_neighbour_header(struct vty *vty)
4354 {
4355 vty_out(vty, "\n%-15s %3s %-15s %9s %-15s %-32s %5s %5s %5s\n",
4356 "Neighbor ID", "Pri", "State", "Dead Time", "Address",
4357 "Interface", "RXmtL", "RqstL", "DBsmL");
4358 }
4359
4360 static void show_ip_ospf_neighbor_sub(struct vty *vty,
4361 struct ospf_interface *oi,
4362 json_object *json, bool use_json)
4363 {
4364 struct route_node *rn;
4365 struct ospf_neighbor *nbr, *prev_nbr = NULL;
4366 char msgbuf[16];
4367 char buf[PREFIX_STRLEN];
4368 char timebuf[OSPF_TIME_DUMP_SIZE];
4369 json_object *json_neighbor = NULL, *json_neigh_array = NULL;
4370
4371 for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) {
4372 if ((nbr = rn->info)) {
4373 /* Do not show myself. */
4374 if (nbr == oi->nbr_self)
4375 continue;
4376 /* Down state is not shown. */
4377 if (nbr->state == NSM_Down)
4378 continue;
4379 if (use_json) {
4380 char neigh_str[INET_ADDRSTRLEN];
4381
4382 if (prev_nbr
4383 && !IPV4_ADDR_SAME(&prev_nbr->src,
4384 &nbr->src)) {
4385 /* Start new neigh list */
4386 json_neigh_array = NULL;
4387 }
4388
4389 if (nbr->state == NSM_Attempt
4390 && nbr->router_id.s_addr == INADDR_ANY)
4391 strlcpy(neigh_str, "neighbor",
4392 sizeof(neigh_str));
4393 else
4394 inet_ntop(AF_INET, &nbr->router_id,
4395 neigh_str, sizeof(neigh_str));
4396
4397 json_object_object_get_ex(json, neigh_str,
4398 &json_neigh_array);
4399
4400 if (!json_neigh_array) {
4401 json_neigh_array =
4402 json_object_new_array();
4403 json_object_object_add(
4404 json, neigh_str,
4405 json_neigh_array);
4406 }
4407
4408 json_neighbor = json_object_new_object();
4409
4410 ospf_nbr_state_message(nbr, msgbuf, 16);
4411
4412 long time_store;
4413
4414 time_store =
4415 monotime_until(
4416 &nbr->t_inactivity->u.sands,
4417 NULL)
4418 / 1000LL;
4419
4420 json_object_int_add(json_neighbor, "priority",
4421 nbr->priority);
4422 json_object_string_add(json_neighbor, "state",
4423 msgbuf);
4424 json_object_int_add(json_neighbor,
4425 "deadTimeMsecs",
4426 time_store);
4427 json_object_string_add(
4428 json_neighbor, "address",
4429 inet_ntop(AF_INET, &nbr->src,
4430 buf, sizeof(buf)));
4431 json_object_string_add(json_neighbor,
4432 "ifaceName",
4433 IF_NAME(oi));
4434 json_object_int_add(
4435 json_neighbor, "retransmitCounter",
4436 ospf_ls_retransmit_count(nbr));
4437 json_object_int_add(json_neighbor,
4438 "requestCounter",
4439 ospf_ls_request_count(nbr));
4440 json_object_int_add(json_neighbor,
4441 "dbSummaryCounter",
4442 ospf_db_summary_count(nbr));
4443
4444 json_object_array_add(json_neigh_array,
4445 json_neighbor);
4446 } else {
4447 ospf_nbr_state_message(nbr, msgbuf, 16);
4448
4449 if (nbr->state == NSM_Attempt
4450 && nbr->router_id.s_addr == INADDR_ANY)
4451 vty_out(vty, "%-15s %3d %-15s ", "-",
4452 nbr->priority, msgbuf);
4453 else
4454 vty_out(vty, "%-15pI4 %3d %-15s ",
4455 &nbr->router_id,
4456 nbr->priority, msgbuf);
4457
4458 vty_out(vty, "%9s ",
4459 ospf_timer_dump(nbr->t_inactivity,
4460 timebuf,
4461 sizeof(timebuf)));
4462 vty_out(vty, "%-15pI4 ", &nbr->src);
4463 vty_out(vty, "%-32s %5ld %5ld %5d\n",
4464 IF_NAME(oi),
4465 ospf_ls_retransmit_count(nbr),
4466 ospf_ls_request_count(nbr),
4467 ospf_db_summary_count(nbr));
4468 }
4469 prev_nbr = nbr;
4470 }
4471 }
4472 }
4473
4474 static int show_ip_ospf_neighbor_common(struct vty *vty, struct ospf *ospf,
4475 json_object *json, bool use_json,
4476 uint8_t use_vrf)
4477 {
4478 struct ospf_interface *oi;
4479 struct listnode *node;
4480 json_object *json_vrf = NULL;
4481 json_object *json_nbr_sub = NULL;
4482
4483 if (use_json) {
4484 if (use_vrf)
4485 json_vrf = json_object_new_object();
4486 else
4487 json_vrf = json;
4488 json_nbr_sub = json_object_new_object();
4489 }
4490
4491 if (ospf->instance) {
4492 if (use_json)
4493 json_object_int_add(json, "ospfInstance",
4494 ospf->instance);
4495 else
4496 vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
4497 }
4498
4499 ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf);
4500 if (!use_json)
4501 show_ip_ospf_neighbour_header(vty);
4502
4503 for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) {
4504 if (ospf_interface_neighbor_count(oi) == 0)
4505 continue;
4506 show_ip_ospf_neighbor_sub(vty, oi, json_nbr_sub, use_json);
4507 }
4508
4509 if (use_json) {
4510 json_object_object_add(json_vrf, "neighbors", json_nbr_sub);
4511 if (use_vrf) {
4512 if (ospf->vrf_id == VRF_DEFAULT)
4513 json_object_object_add(json, "default",
4514 json_vrf);
4515 else
4516 json_object_object_add(json, ospf->name,
4517 json_vrf);
4518 }
4519 } else
4520 vty_out(vty, "\n");
4521
4522 return CMD_SUCCESS;
4523 }
4524
4525 DEFUN (show_ip_ospf_neighbor,
4526 show_ip_ospf_neighbor_cmd,
4527 "show ip ospf [vrf <NAME|all>] neighbor [json]",
4528 SHOW_STR
4529 IP_STR
4530 "OSPF information\n"
4531 VRF_CMD_HELP_STR
4532 "All VRFs\n"
4533 "Neighbor list\n"
4534 JSON_STR)
4535 {
4536 struct ospf *ospf;
4537 bool uj = use_json(argc, argv);
4538 struct listnode *node = NULL;
4539 char *vrf_name = NULL;
4540 bool all_vrf = false;
4541 int ret = CMD_SUCCESS;
4542 int inst = 0;
4543 int idx_vrf = 0;
4544 uint8_t use_vrf = 0;
4545 json_object *json = NULL;
4546
4547 OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
4548
4549 if (uj)
4550 json = json_object_new_object();
4551
4552 /* vrf input is provided could be all or specific vrf*/
4553 if (vrf_name) {
4554 use_vrf = 1;
4555 if (all_vrf) {
4556 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
4557 if (!ospf->oi_running)
4558 continue;
4559 ret = show_ip_ospf_neighbor_common(
4560 vty, ospf, json, uj, use_vrf);
4561 }
4562
4563 if (uj) {
4564 vty_out(vty, "%s\n",
4565 json_object_to_json_string_ext(
4566 json, JSON_C_TO_STRING_PRETTY));
4567 json_object_free(json);
4568 } else if (!ospf)
4569 vty_out(vty, "OSPF instance not found\n");
4570
4571 return ret;
4572 }
4573
4574 ospf = ospf_lookup_by_inst_name(inst, vrf_name);
4575 if (ospf == NULL || !ospf->oi_running) {
4576 if (uj) {
4577 vty_out(vty, "%s\n",
4578 json_object_to_json_string_ext(
4579 json, JSON_C_TO_STRING_PRETTY));
4580 json_object_free(json);
4581 } else
4582 vty_out(vty, "%% OSPF instance not found\n");
4583
4584 return CMD_SUCCESS;
4585 }
4586 } else {
4587 /* Display default ospf (instance 0) info */
4588 ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
4589 if (ospf == NULL || !ospf->oi_running) {
4590 if (uj) {
4591 vty_out(vty, "%s\n",
4592 json_object_to_json_string_ext(
4593 json, JSON_C_TO_STRING_PRETTY));
4594 json_object_free(json);
4595 } else
4596 vty_out(vty, "%% OSPF instance not found\n");
4597
4598 return CMD_SUCCESS;
4599 }
4600 }
4601
4602 if (ospf) {
4603 ret = show_ip_ospf_neighbor_common(vty, ospf, json, uj,
4604 use_vrf);
4605
4606 if (uj) {
4607 vty_out(vty, "%s\n",
4608 json_object_to_json_string_ext(
4609 json, JSON_C_TO_STRING_PRETTY));
4610 }
4611 }
4612
4613 if (uj)
4614 json_object_free(json);
4615
4616 return ret;
4617 }
4618
4619
4620 DEFUN (show_ip_ospf_instance_neighbor,
4621 show_ip_ospf_instance_neighbor_cmd,
4622 "show ip ospf (1-65535) neighbor [json]",
4623 SHOW_STR
4624 IP_STR
4625 "OSPF information\n"
4626 "Instance ID\n"
4627 "Neighbor list\n"
4628 JSON_STR)
4629 {
4630 int idx_number = 3;
4631 struct ospf *ospf;
4632 unsigned short instance = 0;
4633 bool uj = use_json(argc, argv);
4634 json_object *json = NULL;
4635 int ret = CMD_SUCCESS;
4636
4637 instance = strtoul(argv[idx_number]->arg, NULL, 10);
4638 if (instance != ospf_instance)
4639 return CMD_NOT_MY_INSTANCE;
4640
4641 ospf = ospf_lookup_instance(instance);
4642 if (!ospf || !ospf->oi_running)
4643 return CMD_SUCCESS;
4644
4645 if (uj)
4646 json = json_object_new_object();
4647
4648 ret = show_ip_ospf_neighbor_common(vty, ospf, json, uj, 0);
4649
4650 if (uj) {
4651 vty_out(vty, "%s\n", json_object_to_json_string_ext(
4652 json, JSON_C_TO_STRING_PRETTY));
4653 json_object_free(json);
4654 }
4655
4656 return ret;
4657 }
4658
4659 static int show_ip_ospf_neighbor_all_common(struct vty *vty, struct ospf *ospf,
4660 json_object *json, bool use_json,
4661 uint8_t use_vrf)
4662 {
4663 struct listnode *node;
4664 struct ospf_interface *oi;
4665 char buf[PREFIX_STRLEN];
4666 json_object *json_vrf = NULL;
4667 json_object *json_neighbor_sub = NULL;
4668
4669 if (use_json) {
4670 if (use_vrf)
4671 json_vrf = json_object_new_object();
4672 else
4673 json_vrf = json;
4674 json_neighbor_sub = json_object_new_object();
4675 }
4676
4677 ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf);
4678 if (!use_json)
4679 show_ip_ospf_neighbour_header(vty);
4680
4681 if (ospf->instance) {
4682 if (use_json)
4683 json_object_int_add(json_vrf, "ospfInstance",
4684 ospf->instance);
4685 else
4686 vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
4687 }
4688
4689 for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) {
4690 struct listnode *nbr_node;
4691 struct ospf_nbr_nbma *nbr_nbma;
4692
4693 show_ip_ospf_neighbor_sub(vty, oi, json_vrf, use_json);
4694
4695 /* print Down neighbor status */
4696 for (ALL_LIST_ELEMENTS_RO(oi->nbr_nbma, nbr_node, nbr_nbma)) {
4697 if (nbr_nbma->nbr == NULL
4698 || nbr_nbma->nbr->state == NSM_Down) {
4699 if (use_json) {
4700 json_object_int_add(json_neighbor_sub,
4701 "nbrNbmaPriority",
4702 nbr_nbma->priority);
4703 json_object_boolean_true_add(
4704 json_neighbor_sub,
4705 "nbrNbmaDown");
4706 json_object_string_add(
4707 json_neighbor_sub,
4708 "nbrNbmaIfaceName",
4709 IF_NAME(oi));
4710 json_object_int_add(
4711 json_neighbor_sub,
4712 "nbrNbmaRetransmitCounter", 0);
4713 json_object_int_add(
4714 json_neighbor_sub,
4715 "nbrNbmaRequestCounter", 0);
4716 json_object_int_add(
4717 json_neighbor_sub,
4718 "nbrNbmaDbSummaryCounter", 0);
4719 json_object_object_add(
4720 json_vrf,
4721 inet_ntop(AF_INET,
4722 &nbr_nbma->addr, buf,
4723 sizeof(buf)),
4724 json_neighbor_sub);
4725 } else {
4726 vty_out(vty, "%-15s %3d %-15s %9s ",
4727 "-", nbr_nbma->priority, "Down",
4728 "-");
4729 vty_out(vty,
4730 "%-32pI4 %-20s %5d %5d %5d\n",
4731 &nbr_nbma->addr,
4732 IF_NAME(oi), 0, 0, 0);
4733 }
4734 }
4735 }
4736 }
4737
4738 if (use_json) {
4739 if (use_vrf) {
4740 if (ospf->vrf_id == VRF_DEFAULT)
4741 json_object_object_add(json, "default",
4742 json_vrf);
4743 else
4744 json_object_object_add(json, ospf->name,
4745 json_vrf);
4746 }
4747 } else
4748 vty_out(vty, "\n");
4749
4750 return CMD_SUCCESS;
4751 }
4752
4753 DEFUN (show_ip_ospf_neighbor_all,
4754 show_ip_ospf_neighbor_all_cmd,
4755 "show ip ospf [vrf <NAME|all>] neighbor all [json]",
4756 SHOW_STR
4757 IP_STR
4758 "OSPF information\n"
4759 VRF_CMD_HELP_STR
4760 "All VRFs\n"
4761 "Neighbor list\n"
4762 "include down status neighbor\n"
4763 JSON_STR)
4764 {
4765 struct ospf *ospf;
4766 bool uj = use_json(argc, argv);
4767 struct listnode *node = NULL;
4768 char *vrf_name = NULL;
4769 bool all_vrf = false;
4770 int ret = CMD_SUCCESS;
4771 int inst = 0;
4772 int idx_vrf = 0;
4773 uint8_t use_vrf = 0;
4774 json_object *json = NULL;
4775
4776 OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
4777
4778 if (uj)
4779 json = json_object_new_object();
4780
4781 /* vrf input is provided could be all or specific vrf*/
4782 if (vrf_name) {
4783 use_vrf = 1;
4784 if (all_vrf) {
4785 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
4786 if (!ospf->oi_running)
4787 continue;
4788 ret = show_ip_ospf_neighbor_all_common(
4789 vty, ospf, json, uj, use_vrf);
4790 }
4791
4792 if (uj) {
4793 vty_out(vty, "%s\n",
4794 json_object_to_json_string_ext(
4795 json, JSON_C_TO_STRING_PRETTY));
4796 json_object_free(json);
4797 }
4798
4799 return ret;
4800 }
4801
4802 ospf = ospf_lookup_by_inst_name(inst, vrf_name);
4803 if (ospf == NULL || !ospf->oi_running) {
4804 if (uj)
4805 json_object_free(json);
4806 return CMD_SUCCESS;
4807 }
4808 } else {
4809 /* Display default ospf (instance 0) info */
4810 ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
4811 if (ospf == NULL || !ospf->oi_running) {
4812 if (uj)
4813 json_object_free(json);
4814 return CMD_SUCCESS;
4815 }
4816 }
4817
4818 if (ospf) {
4819 ret = show_ip_ospf_neighbor_all_common(vty, ospf, json, uj,
4820 use_vrf);
4821 if (uj) {
4822 vty_out(vty, "%s\n",
4823 json_object_to_json_string_ext(
4824 json, JSON_C_TO_STRING_PRETTY));
4825 }
4826 }
4827
4828 if (uj)
4829 json_object_free(json);
4830
4831 return ret;
4832 }
4833
4834 DEFUN (show_ip_ospf_instance_neighbor_all,
4835 show_ip_ospf_instance_neighbor_all_cmd,
4836 "show ip ospf (1-65535) neighbor all [json]",
4837 SHOW_STR
4838 IP_STR
4839 "OSPF information\n"
4840 "Instance ID\n"
4841 "Neighbor list\n"
4842 "include down status neighbor\n"
4843 JSON_STR)
4844 {
4845 int idx_number = 3;
4846 struct ospf *ospf;
4847 unsigned short instance = 0;
4848 bool uj = use_json(argc, argv);
4849 json_object *json = NULL;
4850 int ret = CMD_SUCCESS;
4851
4852 instance = strtoul(argv[idx_number]->arg, NULL, 10);
4853 if (instance != ospf_instance)
4854 return CMD_NOT_MY_INSTANCE;
4855
4856 ospf = ospf_lookup_instance(instance);
4857 if (!ospf || !ospf->oi_running)
4858 return CMD_SUCCESS;
4859 if (uj)
4860 json = json_object_new_object();
4861
4862 ret = show_ip_ospf_neighbor_all_common(vty, ospf, json, uj, 0);
4863
4864 if (uj) {
4865 vty_out(vty, "%s\n", json_object_to_json_string_ext(
4866 json, JSON_C_TO_STRING_PRETTY));
4867 json_object_free(json);
4868 }
4869
4870 return ret;
4871 }
4872
4873 static int show_ip_ospf_neighbor_int_common(struct vty *vty, struct ospf *ospf,
4874 int arg_base,
4875 struct cmd_token **argv,
4876 bool use_json, uint8_t use_vrf)
4877 {
4878 struct interface *ifp;
4879 struct route_node *rn;
4880 json_object *json = NULL;
4881
4882 if (use_json)
4883 json = json_object_new_object();
4884
4885 if (ospf->instance) {
4886 if (use_json)
4887 json_object_int_add(json, "ospfInstance",
4888 ospf->instance);
4889 else
4890 vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
4891 }
4892
4893 ospf_show_vrf_name(ospf, vty, json, use_vrf);
4894
4895 ifp = if_lookup_by_name(argv[arg_base]->arg, ospf->vrf_id);
4896 if (!ifp) {
4897 if (use_json)
4898 json_object_boolean_true_add(json, "noSuchIface");
4899 else
4900 vty_out(vty, "No such interface.\n");
4901 return CMD_WARNING;
4902 }
4903
4904 for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) {
4905 struct ospf_interface *oi = rn->info;
4906
4907 if (oi == NULL)
4908 continue;
4909
4910 show_ip_ospf_neighbor_sub(vty, oi, json, use_json);
4911 }
4912
4913 if (use_json) {
4914 vty_out(vty, "%s\n", json_object_to_json_string_ext(
4915 json, JSON_C_TO_STRING_PRETTY));
4916 json_object_free(json);
4917 } else
4918 vty_out(vty, "\n");
4919
4920 return CMD_SUCCESS;
4921 }
4922
4923 DEFUN (show_ip_ospf_neighbor_int,
4924 show_ip_ospf_neighbor_int_cmd,
4925 "show ip ospf [vrf <NAME>] neighbor IFNAME [json]",
4926 SHOW_STR
4927 IP_STR
4928 "OSPF information\n"
4929 VRF_CMD_HELP_STR
4930 "Neighbor list\n"
4931 "Interface name\n"
4932 JSON_STR)
4933 {
4934 struct ospf *ospf;
4935 int idx_ifname = 0;
4936 int idx_vrf = 0;
4937 bool uj = use_json(argc, argv);
4938 int ret = CMD_SUCCESS;
4939 struct interface *ifp = NULL;
4940 char *vrf_name = NULL;
4941 vrf_id_t vrf_id = VRF_DEFAULT;
4942 struct vrf *vrf = NULL;
4943
4944 if (argv_find(argv, argc, "vrf", &idx_vrf))
4945 vrf_name = argv[idx_vrf + 1]->arg;
4946 if (vrf_name && strmatch(vrf_name, VRF_DEFAULT_NAME))
4947 vrf_name = NULL;
4948 if (vrf_name) {
4949 vrf = vrf_lookup_by_name(vrf_name);
4950 if (vrf)
4951 vrf_id = vrf->vrf_id;
4952 }
4953 ospf = ospf_lookup_by_vrf_id(vrf_id);
4954
4955 if (!ospf || !ospf->oi_running)
4956 return ret;
4957
4958 if (!uj)
4959 show_ip_ospf_neighbour_header(vty);
4960
4961 argv_find(argv, argc, "IFNAME", &idx_ifname);
4962
4963 ifp = if_lookup_by_name(argv[idx_ifname]->arg, vrf_id);
4964 if (!ifp)
4965 return ret;
4966
4967 ret = show_ip_ospf_neighbor_int_common(vty, ospf, idx_ifname,
4968 argv, uj, 0);
4969 return ret;
4970 }
4971
4972 DEFUN (show_ip_ospf_instance_neighbor_int,
4973 show_ip_ospf_instance_neighbor_int_cmd,
4974 "show ip ospf (1-65535) neighbor IFNAME [json]",
4975 SHOW_STR
4976 IP_STR
4977 "OSPF information\n"
4978 "Instance ID\n"
4979 "Neighbor list\n"
4980 "Interface name\n"
4981 JSON_STR)
4982 {
4983 int idx_number = 3;
4984 int idx_ifname = 5;
4985 struct ospf *ospf;
4986 unsigned short instance = 0;
4987 bool uj = use_json(argc, argv);
4988
4989 if (!uj)
4990 show_ip_ospf_neighbour_header(vty);
4991
4992 instance = strtoul(argv[idx_number]->arg, NULL, 10);
4993 if (instance != ospf_instance)
4994 return CMD_NOT_MY_INSTANCE;
4995
4996 ospf = ospf_lookup_instance(instance);
4997 if (!ospf || !ospf->oi_running)
4998 return CMD_SUCCESS;
4999
5000 if (!uj)
5001 show_ip_ospf_neighbour_header(vty);
5002
5003 return show_ip_ospf_neighbor_int_common(vty, ospf, idx_ifname, argv, uj,
5004 0);
5005 }
5006
5007 static void show_ip_ospf_nbr_nbma_detail_sub(struct vty *vty,
5008 struct ospf_interface *oi,
5009 struct ospf_nbr_nbma *nbr_nbma,
5010 bool use_json, json_object *json)
5011 {
5012 char timebuf[OSPF_TIME_DUMP_SIZE];
5013 char buf[PREFIX_STRLEN];
5014 json_object *json_sub = NULL;
5015
5016 if (use_json)
5017 json_sub = json_object_new_object();
5018 else /* Show neighbor ID. */
5019 vty_out(vty, " Neighbor %s,", "-");
5020
5021 /* Show interface address. */
5022 if (use_json)
5023 json_object_string_add(json_sub, "ifaceAddress",
5024 inet_ntop(AF_INET, &nbr_nbma->addr,
5025 buf, sizeof(buf)));
5026 else
5027 vty_out(vty, " interface address %pI4\n",
5028 &nbr_nbma->addr);
5029
5030 /* Show Area ID. */
5031 if (use_json) {
5032 json_object_string_add(json_sub, "areaId",
5033 ospf_area_desc_string(oi->area));
5034 json_object_string_add(json_sub, "iface", IF_NAME(oi));
5035 } else
5036 vty_out(vty, " In the area %s via interface %s\n",
5037 ospf_area_desc_string(oi->area), IF_NAME(oi));
5038
5039 /* Show neighbor priority and state. */
5040 if (use_json) {
5041 json_object_int_add(json_sub, "nbrPriority",
5042 nbr_nbma->priority);
5043 json_object_string_add(json_sub, "nbrState", "down");
5044 } else
5045 vty_out(vty, " Neighbor priority is %d, State is %s,",
5046 nbr_nbma->priority, "Down");
5047
5048 /* Show state changes. */
5049 if (use_json)
5050 json_object_int_add(json_sub, "stateChangeCounter",
5051 nbr_nbma->state_change);
5052 else
5053 vty_out(vty, " %d state changes\n", nbr_nbma->state_change);
5054
5055 /* Show PollInterval */
5056 if (use_json)
5057 json_object_int_add(json_sub, "pollInterval", nbr_nbma->v_poll);
5058 else
5059 vty_out(vty, " Poll interval %d\n", nbr_nbma->v_poll);
5060
5061 /* Show poll-interval timer. */
5062 if (nbr_nbma->t_poll) {
5063 if (use_json) {
5064 long time_store;
5065 time_store = monotime_until(&nbr_nbma->t_poll->u.sands,
5066 NULL) / 1000LL;
5067 json_object_int_add(json_sub,
5068 "pollIntervalTimerDueMsec",
5069 time_store);
5070 } else
5071 vty_out(vty, " Poll timer due in %s\n",
5072 ospf_timer_dump(nbr_nbma->t_poll, timebuf,
5073 sizeof(timebuf)));
5074 }
5075
5076 /* Show poll-interval timer thread. */
5077 if (use_json) {
5078 if (nbr_nbma->t_poll != NULL)
5079 json_object_string_add(json_sub,
5080 "pollIntervalTimerThread", "on");
5081 } else
5082 vty_out(vty, " Thread Poll Timer %s\n",
5083 nbr_nbma->t_poll != NULL ? "on" : "off");
5084
5085 if (use_json)
5086 json_object_object_add(json, "noNbrId", json_sub);
5087 }
5088
5089 static void show_ip_ospf_neighbor_detail_sub(struct vty *vty,
5090 struct ospf_interface *oi,
5091 struct ospf_neighbor *nbr,
5092 struct ospf_neighbor *prev_nbr,
5093 json_object *json, bool use_json)
5094 {
5095 char timebuf[OSPF_TIME_DUMP_SIZE];
5096 json_object *json_neigh = NULL, *json_neigh_array = NULL;
5097 char neigh_str[INET_ADDRSTRLEN] = {0};
5098 char buf[PREFIX_STRLEN];
5099
5100 if (use_json) {
5101 if (prev_nbr &&
5102 !IPV4_ADDR_SAME(&prev_nbr->src, &nbr->src)) {
5103 json_neigh_array = NULL;
5104 }
5105
5106 if (nbr->state == NSM_Attempt
5107 && nbr->router_id.s_addr == INADDR_ANY)
5108 strlcpy(neigh_str, "noNbrId", sizeof(neigh_str));
5109 else
5110 inet_ntop(AF_INET, &nbr->router_id,
5111 neigh_str, sizeof(neigh_str));
5112
5113 json_object_object_get_ex(json, neigh_str, &json_neigh_array);
5114
5115 if (!json_neigh_array) {
5116 json_neigh_array = json_object_new_array();
5117 json_object_object_add(json, neigh_str,
5118 json_neigh_array);
5119 }
5120
5121 json_neigh = json_object_new_object();
5122
5123 } else {
5124 /* Show neighbor ID. */
5125 if (nbr->state == NSM_Attempt
5126 && nbr->router_id.s_addr == INADDR_ANY)
5127 vty_out(vty, " Neighbor %s,", "-");
5128 else
5129 vty_out(vty, " Neighbor %pI4,",
5130 &nbr->router_id);
5131 }
5132
5133 /* Show interface address. */
5134 if (use_json)
5135 json_object_string_add(json_neigh, "ifaceAddress",
5136 inet_ntop(AF_INET,
5137 &nbr->address.u.prefix4,
5138 buf, sizeof(buf)));
5139 else
5140 vty_out(vty, " interface address %pI4\n",
5141 &nbr->address.u.prefix4);
5142
5143 /* Show Area ID. */
5144 if (use_json) {
5145 json_object_string_add(json_neigh, "areaId",
5146 ospf_area_desc_string(oi->area));
5147 json_object_string_add(json_neigh, "ifaceName", oi->ifp->name);
5148 } else
5149 vty_out(vty, " In the area %s via interface %s\n",
5150 ospf_area_desc_string(oi->area), oi->ifp->name);
5151
5152 /* Show neighbor priority and state. */
5153 if (use_json) {
5154 json_object_int_add(json_neigh, "nbrPriority", nbr->priority);
5155 json_object_string_add(
5156 json_neigh, "nbrState",
5157 lookup_msg(ospf_nsm_state_msg, nbr->state, NULL));
5158 } else
5159 vty_out(vty, " Neighbor priority is %d, State is %s,",
5160 nbr->priority,
5161 lookup_msg(ospf_nsm_state_msg, nbr->state, NULL));
5162
5163 /* Show state changes. */
5164 if (use_json)
5165 json_object_int_add(json_neigh, "stateChangeCounter",
5166 nbr->state_change);
5167 else
5168 vty_out(vty, " %d state changes\n", nbr->state_change);
5169
5170 if (nbr->ts_last_progress.tv_sec || nbr->ts_last_progress.tv_usec) {
5171 struct timeval res;
5172 long time_store;
5173
5174 time_store =
5175 monotime_since(&nbr->ts_last_progress, &res) / 1000LL;
5176 if (use_json) {
5177 json_object_int_add(json_neigh, "lastPrgrsvChangeMsec",
5178 time_store);
5179 } else {
5180 vty_out(vty,
5181 " Most recent state change statistics:\n");
5182 vty_out(vty, " Progressive change %s ago\n",
5183 ospf_timeval_dump(&res, timebuf,
5184 sizeof(timebuf)));
5185 }
5186 }
5187
5188 if (nbr->ts_last_regress.tv_sec || nbr->ts_last_regress.tv_usec) {
5189 struct timeval res;
5190 long time_store;
5191
5192 time_store =
5193 monotime_since(&nbr->ts_last_regress, &res) / 1000LL;
5194 if (use_json) {
5195 json_object_int_add(json_neigh,
5196 "lastRegressiveChangeMsec",
5197 time_store);
5198 if (nbr->last_regress_str)
5199 json_object_string_add(
5200 json_neigh,
5201 "lastRegressiveChangeReason",
5202 nbr->last_regress_str);
5203 } else {
5204 vty_out(vty,
5205 " Regressive change %s ago, due to %s\n",
5206 ospf_timeval_dump(&res, timebuf,
5207 sizeof(timebuf)),
5208 (nbr->last_regress_str ? nbr->last_regress_str
5209 : "??"));
5210 }
5211 }
5212
5213 /* Show Designated Rotuer ID. */
5214 if (use_json)
5215 json_object_string_add(json_neigh, "routerDesignatedId",
5216 inet_ntop(AF_INET, &nbr->d_router,
5217 buf, sizeof(buf)));
5218 else
5219 vty_out(vty, " DR is %pI4,", &nbr->d_router);
5220
5221 /* Show Backup Designated Rotuer ID. */
5222 if (use_json)
5223 json_object_string_add(json_neigh, "routerDesignatedBackupId",
5224 inet_ntop(AF_INET, &nbr->bd_router,
5225 buf, sizeof(buf)));
5226 else
5227 vty_out(vty, " BDR is %pI4\n", &nbr->bd_router);
5228
5229 /* Show options. */
5230 if (use_json) {
5231 json_object_int_add(json_neigh, "optionsCounter", nbr->options);
5232 json_object_string_add(json_neigh, "optionsList",
5233 ospf_options_dump(nbr->options));
5234 } else
5235 vty_out(vty, " Options %d %s\n", nbr->options,
5236 ospf_options_dump(nbr->options));
5237
5238 /* Show Router Dead interval timer. */
5239 if (use_json) {
5240 if (nbr->t_inactivity) {
5241 long time_store;
5242 time_store = monotime_until(&nbr->t_inactivity->u.sands,
5243 NULL)
5244 / 1000LL;
5245 json_object_int_add(json_neigh,
5246 "routerDeadIntervalTimerDueMsec",
5247 time_store);
5248 } else
5249 json_object_int_add(
5250 json_neigh,
5251 "routerDeadIntervalTimerDueMsec", -1);
5252 } else
5253 vty_out(vty, " Dead timer due in %s\n",
5254 ospf_timer_dump(nbr->t_inactivity, timebuf,
5255 sizeof(timebuf)));
5256
5257 /* Show Database Summary list. */
5258 if (use_json)
5259 json_object_int_add(json_neigh, "databaseSummaryListCounter",
5260 ospf_db_summary_count(nbr));
5261 else
5262 vty_out(vty, " Database Summary List %d\n",
5263 ospf_db_summary_count(nbr));
5264
5265 /* Show Link State Request list. */
5266 if (use_json)
5267 json_object_int_add(json_neigh, "linkStateRequestListCounter",
5268 ospf_ls_request_count(nbr));
5269 else
5270 vty_out(vty, " Link State Request List %ld\n",
5271 ospf_ls_request_count(nbr));
5272
5273 /* Show Link State Retransmission list. */
5274 if (use_json)
5275 json_object_int_add(json_neigh,
5276 "linkStateRetransmissionListCounter",
5277 ospf_ls_retransmit_count(nbr));
5278 else
5279 vty_out(vty, " Link State Retransmission List %ld\n",
5280 ospf_ls_retransmit_count(nbr));
5281
5282 /* Show inactivity timer thread. */
5283 if (use_json) {
5284 if (nbr->t_inactivity != NULL)
5285 json_object_string_add(json_neigh,
5286 "threadInactivityTimer", "on");
5287 } else
5288 vty_out(vty, " Thread Inactivity Timer %s\n",
5289 nbr->t_inactivity != NULL ? "on" : "off");
5290
5291 /* Show Database Description retransmission thread. */
5292 if (use_json) {
5293 if (nbr->t_db_desc != NULL)
5294 json_object_string_add(
5295 json_neigh,
5296 "threadDatabaseDescriptionRetransmission",
5297 "on");
5298 } else
5299 vty_out(vty,
5300 " Thread Database Description Retransmision %s\n",
5301 nbr->t_db_desc != NULL ? "on" : "off");
5302
5303 /* Show Link State Request Retransmission thread. */
5304 if (use_json) {
5305 if (nbr->t_ls_req != NULL)
5306 json_object_string_add(
5307 json_neigh,
5308 "threadLinkStateRequestRetransmission", "on");
5309 } else
5310 vty_out(vty,
5311 " Thread Link State Request Retransmission %s\n",
5312 nbr->t_ls_req != NULL ? "on" : "off");
5313
5314 /* Show Link State Update Retransmission thread. */
5315 if (use_json) {
5316 if (nbr->t_ls_upd != NULL)
5317 json_object_string_add(
5318 json_neigh,
5319 "threadLinkStateUpdateRetransmission",
5320 "on");
5321 } else
5322 vty_out(vty,
5323 " Thread Link State Update Retransmission %s\n\n",
5324 nbr->t_ls_upd != NULL ? "on" : "off");
5325
5326 if (!use_json) {
5327 vty_out(vty, " Graceful restart Helper info:\n");
5328
5329 if (OSPF_GR_IS_ACTIVE_HELPER(nbr)) {
5330 vty_out(vty,
5331 " Graceful Restart HELPER Status : Inprogress.\n");
5332
5333 vty_out(vty,
5334 " Graceful Restart grace period time: %d (seconds).\n",
5335 nbr->gr_helper_info.recvd_grace_period);
5336 vty_out(vty, " Graceful Restart reason: %s.\n",
5337 ospf_restart_reason2str(
5338 nbr->gr_helper_info.gr_restart_reason));
5339 } else {
5340 vty_out(vty,
5341 " Graceful Restart HELPER Status : None\n");
5342 }
5343
5344 if (nbr->gr_helper_info.rejected_reason
5345 != OSPF_HELPER_REJECTED_NONE)
5346 vty_out(vty, " Helper rejected reason: %s.\n",
5347 ospf_rejected_reason2str(
5348 nbr->gr_helper_info.rejected_reason));
5349
5350 if (nbr->gr_helper_info.helper_exit_reason
5351 != OSPF_GR_HELPER_EXIT_NONE)
5352 vty_out(vty, " Last helper exit reason: %s.\n\n",
5353 ospf_exit_reason2str(
5354 nbr->gr_helper_info.helper_exit_reason));
5355 else
5356 vty_out(vty, "\n");
5357 } else {
5358 json_object_string_add(json_neigh, "grHelperStatus",
5359 OSPF_GR_IS_ACTIVE_HELPER(nbr) ?
5360 "Inprogress"
5361 : "None");
5362 if (OSPF_GR_IS_ACTIVE_HELPER(nbr)) {
5363 json_object_int_add(
5364 json_neigh, "graceInterval",
5365 nbr->gr_helper_info.recvd_grace_period);
5366 json_object_string_add(
5367 json_neigh, "grRestartReason",
5368 ospf_restart_reason2str(
5369 nbr->gr_helper_info.gr_restart_reason));
5370 }
5371
5372 if (nbr->gr_helper_info.rejected_reason
5373 != OSPF_HELPER_REJECTED_NONE)
5374 json_object_string_add(
5375 json_neigh, "helperRejectReason",
5376 ospf_rejected_reason2str(
5377 nbr->gr_helper_info.rejected_reason));
5378
5379 if (nbr->gr_helper_info.helper_exit_reason
5380 != OSPF_GR_HELPER_EXIT_NONE)
5381 json_object_string_add(
5382 json_neigh, "helperExitReason",
5383 ospf_exit_reason2str(
5384 nbr->gr_helper_info
5385 .helper_exit_reason));
5386 }
5387
5388 bfd_sess_show(vty, json_neigh, nbr->bfd_session);
5389
5390 if (use_json)
5391 json_object_array_add(json_neigh_array, json_neigh);
5392
5393 }
5394
5395 static int show_ip_ospf_neighbor_id_common(struct vty *vty, struct ospf *ospf,
5396 struct in_addr *router_id,
5397 bool use_json, uint8_t use_vrf)
5398 {
5399 struct listnode *node;
5400 struct ospf_neighbor *nbr;
5401 struct ospf_interface *oi;
5402 json_object *json = NULL;
5403
5404 if (use_json)
5405 json = json_object_new_object();
5406
5407 if (ospf->instance) {
5408 if (use_json)
5409 json_object_int_add(json, "ospfInstance",
5410 ospf->instance);
5411 else
5412 vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
5413 }
5414
5415 ospf_show_vrf_name(ospf, vty, json, use_vrf);
5416
5417 for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) {
5418 if ((nbr = ospf_nbr_lookup_by_routerid(oi->nbrs, router_id))) {
5419 show_ip_ospf_neighbor_detail_sub(vty, oi, nbr, NULL,
5420 json, use_json);
5421 }
5422 }
5423
5424 if (use_json) {
5425 vty_out(vty, "%s\n", json_object_to_json_string_ext(
5426 json, JSON_C_TO_STRING_PRETTY));
5427 json_object_free(json);
5428 } else
5429 vty_out(vty, "\n");
5430
5431 return CMD_SUCCESS;
5432 }
5433
5434 DEFPY (show_ip_ospf_neighbor_id,
5435 show_ip_ospf_neighbor_id_cmd,
5436 "show ip ospf neighbor A.B.C.D$router_id [json$json]",
5437 SHOW_STR
5438 IP_STR
5439 "OSPF information\n"
5440 "Neighbor list\n"
5441 "Neighbor ID\n"
5442 JSON_STR)
5443 {
5444 struct ospf *ospf;
5445 struct listnode *node;
5446 int ret = CMD_SUCCESS;
5447
5448 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
5449 if (!ospf->oi_running)
5450 continue;
5451 ret = show_ip_ospf_neighbor_id_common(vty, ospf, &router_id,
5452 !!json, 0);
5453 }
5454
5455 return ret;
5456 }
5457
5458 DEFPY (show_ip_ospf_instance_neighbor_id,
5459 show_ip_ospf_instance_neighbor_id_cmd,
5460 "show ip ospf (1-65535)$instance neighbor A.B.C.D$router_id [json$json]",
5461 SHOW_STR
5462 IP_STR
5463 "OSPF information\n"
5464 "Instance ID\n"
5465 "Neighbor list\n"
5466 "Neighbor ID\n"
5467 JSON_STR)
5468 {
5469 struct ospf *ospf;
5470
5471 if (instance != ospf_instance)
5472 return CMD_NOT_MY_INSTANCE;
5473
5474 ospf = ospf_lookup_instance(instance);
5475 if (!ospf || !ospf->oi_running)
5476 return CMD_SUCCESS;
5477
5478 return show_ip_ospf_neighbor_id_common(vty, ospf, &router_id, !!json,
5479 0);
5480 }
5481
5482 static int show_ip_ospf_neighbor_detail_common(struct vty *vty,
5483 struct ospf *ospf,
5484 json_object *json, bool use_json,
5485 uint8_t use_vrf)
5486 {
5487 struct ospf_interface *oi;
5488 struct listnode *node;
5489 json_object *json_vrf = NULL;
5490 json_object *json_nbr_sub = NULL;
5491
5492 if (use_json) {
5493 if (use_vrf)
5494 json_vrf = json_object_new_object();
5495 else
5496 json_vrf = json;
5497
5498 json_nbr_sub = json_object_new_object();
5499 }
5500
5501 if (ospf->instance) {
5502 if (use_json)
5503 json_object_int_add(json, "ospfInstance",
5504 ospf->instance);
5505 else
5506 vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
5507 }
5508
5509 ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf);
5510
5511 for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) {
5512 struct route_node *rn;
5513 struct ospf_neighbor *nbr, *prev_nbr = NULL;
5514
5515 for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) {
5516 if ((nbr = rn->info)) {
5517 if (nbr != oi->nbr_self) {
5518 if (nbr->state != NSM_Down) {
5519 show_ip_ospf_neighbor_detail_sub(
5520 vty, oi, nbr, prev_nbr,
5521 json_nbr_sub, use_json);
5522 }
5523 }
5524 prev_nbr = nbr;
5525 }
5526 }
5527 }
5528
5529 if (use_json) {
5530 json_object_object_add(json_vrf, "neighbors",
5531 json_nbr_sub);
5532 if (use_vrf) {
5533 if (ospf->vrf_id == VRF_DEFAULT)
5534 json_object_object_add(json, "default",
5535 json_vrf);
5536 else
5537 json_object_object_add(json, ospf->name,
5538 json_vrf);
5539 }
5540 } else
5541 vty_out(vty, "\n");
5542
5543 return CMD_SUCCESS;
5544 }
5545
5546 DEFUN (show_ip_ospf_neighbor_detail,
5547 show_ip_ospf_neighbor_detail_cmd,
5548 "show ip ospf [vrf <NAME|all>] neighbor detail [json]",
5549 SHOW_STR
5550 IP_STR
5551 "OSPF information\n"
5552 VRF_CMD_HELP_STR
5553 "All VRFs\n"
5554 "Neighbor list\n"
5555 "detail of all neighbors\n"
5556 JSON_STR)
5557 {
5558 struct ospf *ospf;
5559 bool uj = use_json(argc, argv);
5560 struct listnode *node = NULL;
5561 char *vrf_name = NULL;
5562 bool all_vrf = false;
5563 int ret = CMD_SUCCESS;
5564 int inst = 0;
5565 int idx_vrf = 0;
5566 uint8_t use_vrf = 0;
5567 json_object *json = NULL;
5568
5569 OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
5570
5571 if (uj)
5572 json = json_object_new_object();
5573
5574 /* vrf input is provided could be all or specific vrf*/
5575 if (vrf_name) {
5576 use_vrf = 1;
5577 if (all_vrf) {
5578 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
5579 if (!ospf->oi_running)
5580 continue;
5581 ret = show_ip_ospf_neighbor_detail_common(
5582 vty, ospf, json, uj, use_vrf);
5583 }
5584 if (uj) {
5585 vty_out(vty, "%s\n",
5586 json_object_to_json_string_ext(
5587 json, JSON_C_TO_STRING_PRETTY));
5588 json_object_free(json);
5589 }
5590
5591 return ret;
5592 }
5593 ospf = ospf_lookup_by_inst_name(inst, vrf_name);
5594 if (ospf == NULL || !ospf->oi_running) {
5595 if (uj)
5596 json_object_free(json);
5597 return CMD_SUCCESS;
5598 }
5599 } else {
5600 /* Display default ospf (instance 0) info */
5601 ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
5602 if (ospf == NULL || !ospf->oi_running) {
5603 if (uj)
5604 json_object_free(json);
5605 return CMD_SUCCESS;
5606 }
5607 }
5608
5609 if (ospf) {
5610 ret = show_ip_ospf_neighbor_detail_common(vty, ospf, json, uj,
5611 use_vrf);
5612 if (uj) {
5613 vty_out(vty, "%s\n",
5614 json_object_to_json_string_ext(
5615 json, JSON_C_TO_STRING_PRETTY));
5616 }
5617 }
5618
5619 if (uj)
5620 json_object_free(json);
5621
5622 return ret;
5623 }
5624
5625 DEFUN (show_ip_ospf_instance_neighbor_detail,
5626 show_ip_ospf_instance_neighbor_detail_cmd,
5627 "show ip ospf (1-65535) neighbor detail [json]",
5628 SHOW_STR
5629 IP_STR
5630 "OSPF information\n"
5631 "Instance ID\n"
5632 "Neighbor list\n"
5633 "detail of all neighbors\n"
5634 JSON_STR)
5635 {
5636 int idx_number = 3;
5637 struct ospf *ospf;
5638 unsigned short instance = 0;
5639 bool uj = use_json(argc, argv);
5640 json_object *json = NULL;
5641 int ret = CMD_SUCCESS;
5642
5643 instance = strtoul(argv[idx_number]->arg, NULL, 10);
5644 if (instance != ospf_instance)
5645 return CMD_NOT_MY_INSTANCE;
5646
5647 ospf = ospf_lookup_instance(instance);
5648 if (!ospf || !ospf->oi_running)
5649 return CMD_SUCCESS;
5650
5651 if (uj)
5652 json = json_object_new_object();
5653
5654 ret = show_ip_ospf_neighbor_detail_common(vty, ospf, json, uj, 0);
5655
5656 if (uj) {
5657 vty_out(vty, "%s\n", json_object_to_json_string_ext(
5658 json, JSON_C_TO_STRING_PRETTY));
5659 json_object_free(json);
5660 }
5661
5662 return ret;
5663 }
5664
5665 static int show_ip_ospf_neighbor_detail_all_common(struct vty *vty,
5666 struct ospf *ospf,
5667 json_object *json,
5668 bool use_json,
5669 uint8_t use_vrf)
5670 {
5671 struct listnode *node;
5672 struct ospf_interface *oi;
5673 json_object *json_vrf = NULL;
5674
5675 if (use_json) {
5676 if (use_vrf)
5677 json_vrf = json_object_new_object();
5678 else
5679 json_vrf = json;
5680 }
5681
5682 if (ospf->instance) {
5683 if (use_json)
5684 json_object_int_add(json, "ospfInstance",
5685 ospf->instance);
5686 else
5687 vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
5688 }
5689
5690 ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf);
5691
5692 for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) {
5693 struct route_node *rn;
5694 struct ospf_neighbor *nbr, *prev_nbr = NULL;
5695 struct ospf_nbr_nbma *nbr_nbma;
5696
5697 for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) {
5698 if ((nbr = rn->info)) {
5699 if (nbr != oi->nbr_self)
5700 if (nbr->state != NSM_Down)
5701 show_ip_ospf_neighbor_detail_sub(
5702 vty, oi, rn->info,
5703 prev_nbr,
5704 json_vrf, use_json);
5705 prev_nbr = nbr;
5706 }
5707 }
5708
5709 if (oi->type == OSPF_IFTYPE_NBMA) {
5710 struct listnode *nd;
5711
5712 for (ALL_LIST_ELEMENTS_RO(oi->nbr_nbma, nd, nbr_nbma)) {
5713 if (nbr_nbma->nbr == NULL
5714 || nbr_nbma->nbr->state == NSM_Down)
5715 show_ip_ospf_nbr_nbma_detail_sub(
5716 vty, oi, nbr_nbma, use_json,
5717 json_vrf);
5718 }
5719 }
5720 }
5721
5722 if (use_json) {
5723 if (use_vrf) {
5724 if (ospf->vrf_id == VRF_DEFAULT)
5725 json_object_object_add(json, "default",
5726 json_vrf);
5727 else
5728 json_object_object_add(json, ospf->name,
5729 json_vrf);
5730 }
5731 } else {
5732 vty_out(vty, "\n");
5733 }
5734
5735 return CMD_SUCCESS;
5736 }
5737
5738 DEFUN (show_ip_ospf_neighbor_detail_all,
5739 show_ip_ospf_neighbor_detail_all_cmd,
5740 "show ip ospf [vrf <NAME|all>] neighbor detail all [json]",
5741 SHOW_STR
5742 IP_STR
5743 "OSPF information\n"
5744 VRF_CMD_HELP_STR
5745 "All VRFs\n"
5746 "Neighbor list\n"
5747 "detail of all neighbors\n"
5748 "include down status neighbor\n"
5749 JSON_STR)
5750 {
5751 struct ospf *ospf;
5752 bool uj = use_json(argc, argv);
5753 struct listnode *node = NULL;
5754 char *vrf_name = NULL;
5755 bool all_vrf = false;
5756 int ret = CMD_SUCCESS;
5757 int inst = 0;
5758 int idx_vrf = 0;
5759 uint8_t use_vrf = 0;
5760 json_object *json = NULL;
5761
5762 OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
5763
5764 if (uj)
5765 json = json_object_new_object();
5766
5767 /* vrf input is provided could be all or specific vrf*/
5768 if (vrf_name) {
5769 use_vrf = 1;
5770 if (all_vrf) {
5771 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
5772 if (!ospf->oi_running)
5773 continue;
5774 ret = show_ip_ospf_neighbor_detail_all_common(
5775 vty, ospf, json, uj, use_vrf);
5776 }
5777
5778 if (uj) {
5779 vty_out(vty, "%s\n",
5780 json_object_to_json_string_ext(
5781 json, JSON_C_TO_STRING_PRETTY));
5782 json_object_free(json);
5783 }
5784
5785 return ret;
5786 }
5787 ospf = ospf_lookup_by_inst_name(inst, vrf_name);
5788 if (ospf == NULL || !ospf->oi_running) {
5789 if (uj)
5790 json_object_free(json);
5791 return CMD_SUCCESS;
5792 }
5793 } else {
5794 /* Display default ospf (instance 0) info */
5795 ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
5796 if (ospf == NULL || !ospf->oi_running) {
5797 if (uj)
5798 json_object_free(json);
5799 return CMD_SUCCESS;
5800 }
5801 }
5802
5803 if (ospf) {
5804 ret = show_ip_ospf_neighbor_detail_all_common(vty, ospf, json,
5805 uj, use_vrf);
5806 if (uj) {
5807 vty_out(vty, "%s\n",
5808 json_object_to_json_string_ext(
5809 json, JSON_C_TO_STRING_PRETTY));
5810 }
5811 }
5812
5813 if (uj)
5814 json_object_free(json);
5815
5816 return ret;
5817 }
5818
5819 DEFUN (show_ip_ospf_instance_neighbor_detail_all,
5820 show_ip_ospf_instance_neighbor_detail_all_cmd,
5821 "show ip ospf (1-65535) neighbor detail all [json]",
5822 SHOW_STR
5823 IP_STR
5824 "OSPF information\n"
5825 "Instance ID\n"
5826 "Neighbor list\n"
5827 "detail of all neighbors\n"
5828 "include down status neighbor\n"
5829 JSON_STR)
5830 {
5831 int idx_number = 3;
5832 struct ospf *ospf;
5833 unsigned short instance = 0;
5834 bool uj = use_json(argc, argv);
5835 json_object *json = NULL;
5836 int ret = CMD_SUCCESS;
5837
5838 instance = strtoul(argv[idx_number]->arg, NULL, 10);
5839 if (instance != ospf_instance)
5840 return CMD_NOT_MY_INSTANCE;
5841
5842 ospf = ospf_lookup_instance(instance);
5843 if (!ospf || !ospf->oi_running)
5844 return CMD_SUCCESS;
5845
5846 if (uj)
5847 json = json_object_new_object();
5848
5849 ret = show_ip_ospf_neighbor_detail_all_common(vty, ospf, json, uj, 0);
5850
5851 if (uj) {
5852 vty_out(vty, "%s\n", json_object_to_json_string_ext(
5853 json, JSON_C_TO_STRING_PRETTY));
5854 json_object_free(json);
5855 }
5856
5857 return ret;
5858 }
5859
5860 static int show_ip_ospf_neighbor_int_detail_common(struct vty *vty,
5861 struct ospf *ospf,
5862 int arg_base,
5863 struct cmd_token **argv,
5864 bool use_json)
5865 {
5866 struct ospf_interface *oi;
5867 struct interface *ifp;
5868 struct route_node *rn, *nrn;
5869 struct ospf_neighbor *nbr;
5870 json_object *json = NULL;
5871
5872 if (use_json)
5873 json = json_object_new_object();
5874
5875 if (ospf->instance) {
5876 if (use_json)
5877 json_object_int_add(json, "ospfInstance",
5878 ospf->instance);
5879 else
5880 vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
5881 }
5882
5883 ifp = if_lookup_by_name(argv[arg_base]->arg, ospf->vrf_id);
5884 if (!ifp) {
5885 if (!use_json)
5886 vty_out(vty, "No such interface.\n");
5887 else {
5888 vty_out(vty, "{}\n");
5889 json_object_free(json);
5890 }
5891 return CMD_WARNING;
5892 }
5893
5894 for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) {
5895 if ((oi = rn->info)) {
5896 for (nrn = route_top(oi->nbrs); nrn;
5897 nrn = route_next(nrn)) {
5898 if ((nbr = nrn->info)) {
5899 if (nbr != oi->nbr_self) {
5900 if (nbr->state != NSM_Down)
5901 show_ip_ospf_neighbor_detail_sub(
5902 vty, oi, nbr,
5903 NULL,
5904 json, use_json);
5905 }
5906 }
5907 }
5908 }
5909 }
5910
5911 if (use_json) {
5912 vty_out(vty, "%s\n", json_object_to_json_string_ext(
5913 json, JSON_C_TO_STRING_PRETTY));
5914 json_object_free(json);
5915 } else
5916 vty_out(vty, "\n");
5917
5918 return CMD_SUCCESS;
5919 }
5920
5921 DEFUN (show_ip_ospf_neighbor_int_detail,
5922 show_ip_ospf_neighbor_int_detail_cmd,
5923 "show ip ospf neighbor IFNAME detail [json]",
5924 SHOW_STR
5925 IP_STR
5926 "OSPF information\n"
5927 "Neighbor list\n"
5928 "Interface name\n"
5929 "detail of all neighbors\n"
5930 JSON_STR)
5931 {
5932 struct ospf *ospf;
5933 bool uj = use_json(argc, argv);
5934 struct listnode *node = NULL;
5935 int ret = CMD_SUCCESS;
5936 bool ospf_output = false;
5937
5938 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
5939 if (!ospf->oi_running)
5940 continue;
5941 ospf_output = true;
5942 ret = show_ip_ospf_neighbor_int_detail_common(vty, ospf, 4,
5943 argv, uj);
5944 }
5945
5946 if (!ospf_output)
5947 vty_out(vty, "%% OSPF instance not found\n");
5948
5949 return ret;
5950 }
5951
5952 DEFUN (show_ip_ospf_instance_neighbor_int_detail,
5953 show_ip_ospf_instance_neighbor_int_detail_cmd,
5954 "show ip ospf (1-65535) neighbor IFNAME detail [json]",
5955 SHOW_STR
5956 IP_STR
5957 "OSPF information\n"
5958 "Instance ID\n"
5959 "Neighbor list\n"
5960 "Interface name\n"
5961 "detail of all neighbors\n"
5962 JSON_STR)
5963 {
5964 int idx_number = 3;
5965 int idx_ifname = 5;
5966 struct ospf *ospf;
5967 unsigned short instance = 0;
5968 bool uj = use_json(argc, argv);
5969
5970 instance = strtoul(argv[idx_number]->arg, NULL, 10);
5971 if (instance != ospf_instance)
5972 return CMD_NOT_MY_INSTANCE;
5973
5974 ospf = ospf_lookup_instance(instance);
5975 if (!ospf || !ospf->oi_running)
5976 return CMD_SUCCESS;
5977
5978 return show_ip_ospf_neighbor_int_detail_common(vty, ospf, idx_ifname,
5979 argv, uj);
5980 }
5981
5982 /* Show functions */
5983 static int show_lsa_summary(struct vty *vty, struct ospf_lsa *lsa, int self,
5984 json_object *json_lsa)
5985 {
5986 struct router_lsa *rl;
5987 struct summary_lsa *sl;
5988 struct as_external_lsa *asel;
5989 struct prefix_ipv4 p;
5990 char buf[PREFIX2STR_BUFFER];
5991
5992 if (lsa != NULL)
5993 /* If self option is set, check LSA self flag. */
5994 if (self == 0 || IS_LSA_SELF(lsa)) {
5995
5996 if (!json_lsa) {
5997 /* LSA common part show. */
5998 vty_out(vty, "%-15pI4",
5999 &lsa->data->id);
6000 vty_out(vty, "%-15pI4 %4d 0x%08lx 0x%04x",
6001 &lsa->data->adv_router, LS_AGE(lsa),
6002 (unsigned long)ntohl(
6003 lsa->data->ls_seqnum),
6004 ntohs(lsa->data->checksum));
6005 } else {
6006 char seqnum[10];
6007 char checksum[10];
6008
6009 snprintf(seqnum, sizeof(seqnum), "%x",
6010 ntohl(lsa->data->ls_seqnum));
6011 snprintf(checksum, sizeof(checksum), "%x",
6012 ntohs(lsa->data->checksum));
6013 json_object_string_add(
6014 json_lsa, "lsId",
6015 inet_ntop(AF_INET, &lsa->data->id,
6016 buf, sizeof(buf)));
6017 json_object_string_add(
6018 json_lsa, "advertisedRouter",
6019 inet_ntop(AF_INET,
6020 &lsa->data->adv_router,
6021 buf, sizeof(buf)));
6022 json_object_int_add(json_lsa, "lsaAge",
6023 LS_AGE(lsa));
6024 json_object_string_add(
6025 json_lsa, "sequenceNumber", seqnum);
6026 json_object_string_add(json_lsa, "checksum",
6027 checksum);
6028 }
6029
6030 /* LSA specific part show. */
6031 switch (lsa->data->type) {
6032 case OSPF_ROUTER_LSA:
6033 rl = (struct router_lsa *)lsa->data;
6034
6035 if (!json_lsa)
6036 vty_out(vty, " %-d", ntohs(rl->links));
6037 else
6038 json_object_int_add(json_lsa,
6039 "numOfRouterLinks",
6040 ntohs(rl->links));
6041 break;
6042 case OSPF_SUMMARY_LSA:
6043 sl = (struct summary_lsa *)lsa->data;
6044
6045 p.family = AF_INET;
6046 p.prefix = sl->header.id;
6047 p.prefixlen = ip_masklen(sl->mask);
6048 apply_mask_ipv4(&p);
6049
6050 if (!json_lsa)
6051 vty_out(vty, " %pFX", &p);
6052 else {
6053 prefix2str(&p, buf, sizeof(buf));
6054 json_object_string_add(json_lsa,
6055 "summaryAddress",
6056 buf);
6057 }
6058 break;
6059 case OSPF_AS_EXTERNAL_LSA:
6060 case OSPF_AS_NSSA_LSA:
6061 asel = (struct as_external_lsa *)lsa->data;
6062
6063 p.family = AF_INET;
6064 p.prefix = asel->header.id;
6065 p.prefixlen = ip_masklen(asel->mask);
6066 apply_mask_ipv4(&p);
6067
6068 if (!json_lsa)
6069 vty_out(vty, " %s %pFX [0x%lx]",
6070 IS_EXTERNAL_METRIC(
6071 asel->e[0].tos)
6072 ? "E2"
6073 : "E1",
6074 &p,
6075 (unsigned long)ntohl(
6076 asel->e[0].route_tag));
6077 else {
6078 prefix2str(&p, buf, sizeof(buf));
6079 json_object_string_add(
6080 json_lsa, "metricType",
6081 IS_EXTERNAL_METRIC(
6082 asel->e[0].tos)
6083 ? "E2"
6084 : "E1");
6085 json_object_string_add(json_lsa,
6086 "route", buf);
6087 json_object_int_add(
6088 json_lsa, "tag",
6089 (unsigned long)ntohl(
6090 asel->e[0].route_tag));
6091 }
6092 break;
6093 case OSPF_NETWORK_LSA:
6094 case OSPF_ASBR_SUMMARY_LSA:
6095 case OSPF_OPAQUE_LINK_LSA:
6096 case OSPF_OPAQUE_AREA_LSA:
6097 case OSPF_OPAQUE_AS_LSA:
6098 default:
6099 break;
6100 }
6101
6102 if (!json_lsa)
6103 vty_out(vty, "\n");
6104 }
6105
6106 return 0;
6107 }
6108
6109 static const char *const show_database_desc[] = {
6110 "unknown",
6111 "Router Link States",
6112 "Net Link States",
6113 "Summary Link States",
6114 "ASBR-Summary Link States",
6115 "AS External Link States",
6116 "Group Membership LSA",
6117 "NSSA-external Link States",
6118 "Type-8 LSA",
6119 "Link-Local Opaque-LSA",
6120 "Area-Local Opaque-LSA",
6121 "AS-external Opaque-LSA",
6122 };
6123
6124 static const char * const show_database_desc_json[] = {
6125 "unknown",
6126 "routerLinkStates",
6127 "networkLinkStates",
6128 "summaryLinkStates",
6129 "asbrSummaryLinkStates",
6130 "asExternalLinkStates",
6131 "groupMembershipLsa",
6132 "nssaExternalLinkStates",
6133 "type8Lsa",
6134 "linkLocalOpaqueLsa",
6135 "areaLocalOpaqueLsa",
6136 "asExternalOpaqueLsa",
6137 };
6138
6139 static const char *const show_database_header[] = {
6140 "",
6141 "Link ID ADV Router Age Seq# CkSum Link count",
6142 "Link ID ADV Router Age Seq# CkSum",
6143 "Link ID ADV Router Age Seq# CkSum Route",
6144 "Link ID ADV Router Age Seq# CkSum",
6145 "Link ID ADV Router Age Seq# CkSum Route",
6146 " --- header for Group Member ----",
6147 "Link ID ADV Router Age Seq# CkSum Route",
6148 " --- type-8 ---",
6149 "Opaque-Type/Id ADV Router Age Seq# CkSum",
6150 "Opaque-Type/Id ADV Router Age Seq# CkSum",
6151 "Opaque-Type/Id ADV Router Age Seq# CkSum",
6152 };
6153
6154 static void show_ip_ospf_database_header(struct vty *vty, struct ospf_lsa *lsa,
6155 json_object *json)
6156 {
6157 char buf[PREFIX_STRLEN];
6158 struct router_lsa *rlsa = (struct router_lsa *)lsa->data;
6159
6160 if (!json) {
6161 vty_out(vty, " LS age: %d\n", LS_AGE(lsa));
6162 vty_out(vty, " Options: 0x%-2x : %s\n", lsa->data->options,
6163 ospf_options_dump(lsa->data->options));
6164 vty_out(vty, " LS Flags: 0x%-2x %s\n", lsa->flags,
6165 ((lsa->flags & OSPF_LSA_LOCAL_XLT)
6166 ? "(Translated from Type-7)"
6167 : ""));
6168
6169 if (lsa->data->type == OSPF_ROUTER_LSA) {
6170 vty_out(vty, " Flags: 0x%x", rlsa->flags);
6171
6172 if (rlsa->flags)
6173 vty_out(vty, " :%s%s%s%s",
6174 IS_ROUTER_LSA_BORDER(rlsa) ? " ABR"
6175 : "",
6176 IS_ROUTER_LSA_EXTERNAL(rlsa) ? " ASBR"
6177 : "",
6178 IS_ROUTER_LSA_VIRTUAL(rlsa)
6179 ? " VL-endpoint"
6180 : "",
6181 IS_ROUTER_LSA_SHORTCUT(rlsa)
6182 ? " Shortcut"
6183 : "");
6184
6185 vty_out(vty, "\n");
6186 }
6187 vty_out(vty, " LS Type: %s\n",
6188 lookup_msg(ospf_lsa_type_msg, lsa->data->type, NULL));
6189 vty_out(vty, " Link State ID: %pI4 %s\n",
6190 &lsa->data->id,
6191 lookup_msg(ospf_link_state_id_type_msg, lsa->data->type,
6192 NULL));
6193 vty_out(vty, " Advertising Router: %pI4\n",
6194 &lsa->data->adv_router);
6195 vty_out(vty, " LS Seq Number: %08lx\n",
6196 (unsigned long)ntohl(lsa->data->ls_seqnum));
6197 vty_out(vty, " Checksum: 0x%04x\n",
6198 ntohs(lsa->data->checksum));
6199 vty_out(vty, " Length: %d\n\n", ntohs(lsa->data->length));
6200 } else {
6201 char seqnum[10];
6202 char checksum[10];
6203
6204 snprintf(seqnum, 10, "%x", ntohl(lsa->data->ls_seqnum));
6205 snprintf(checksum, 10, "%x", ntohs(lsa->data->checksum));
6206
6207 json_object_int_add(json, "lsaAge", LS_AGE(lsa));
6208 json_object_string_add(json, "options",
6209 ospf_options_dump(lsa->data->options));
6210 json_object_int_add(json, "lsaFlags", lsa->flags);
6211
6212 if (lsa->flags & OSPF_LSA_LOCAL_XLT)
6213 json_object_boolean_true_add(json,
6214 "translatedFromType7");
6215
6216 if (lsa->data->type == OSPF_ROUTER_LSA) {
6217 json_object_int_add(json, "flags", rlsa->flags);
6218
6219 if (rlsa->flags) {
6220 if (IS_ROUTER_LSA_BORDER(rlsa))
6221 json_object_boolean_true_add(json,
6222 "abr");
6223 if (IS_ROUTER_LSA_EXTERNAL(rlsa))
6224 json_object_boolean_true_add(json,
6225 "asbr");
6226 if (IS_ROUTER_LSA_VIRTUAL(rlsa))
6227 json_object_boolean_true_add(
6228 json, "vlEndpoint");
6229 if (IS_ROUTER_LSA_SHORTCUT(rlsa))
6230 json_object_boolean_true_add(
6231 json, "shortcut");
6232 }
6233 }
6234
6235 json_object_string_add(
6236 json, "lsaType",
6237 lookup_msg(ospf_lsa_type_msg, lsa->data->type, NULL));
6238 json_object_string_add(json, "linkStateId",
6239 inet_ntop(AF_INET, &lsa->data->id,
6240 buf, sizeof(buf)));
6241 json_object_string_add(json, "advertisingRouter",
6242 inet_ntop(AF_INET,
6243 &lsa->data->adv_router,
6244 buf, sizeof(buf)));
6245 json_object_string_add(json, "lsaSeqNumber", seqnum);
6246 json_object_string_add(json, "checksum", checksum);
6247 json_object_int_add(json, "length", ntohs(lsa->data->length));
6248 }
6249 }
6250
6251 static const char *const link_type_desc[] = {
6252 "(null)",
6253 "another Router (point-to-point)",
6254 "a Transit Network",
6255 "Stub Network",
6256 "a Virtual Link",
6257 };
6258
6259 static const char *const link_id_desc[] = {
6260 "(null)", "Neighboring Router ID", "Designated Router address",
6261 "Net", "Neighboring Router ID",
6262 };
6263
6264 static const char *const link_data_desc[] = {
6265 "(null)", "Router Interface address", "Router Interface address",
6266 "Network Mask", "Router Interface address",
6267 };
6268
6269 static const char *const link_id_desc_json[] = {
6270 "null", "neighborRouterId", "designatedRouterAddress",
6271 "networkAddress", "neighborRouterId",
6272 };
6273
6274 static const char *const link_data_desc_json[] = {
6275 "null", "routerInterfaceAddress", "routerInterfaceAddress",
6276 "networkMask", "routerInterfaceAddress",
6277 };
6278
6279 /* Show router-LSA each Link information. */
6280 static void show_ip_ospf_database_router_links(struct vty *vty,
6281 struct router_lsa *rl,
6282 json_object *json)
6283 {
6284 int len, type;
6285 unsigned short i;
6286 json_object *json_links = NULL;
6287 json_object *json_link = NULL;
6288 int metric = 0;
6289 char buf[PREFIX_STRLEN];
6290
6291 if (json)
6292 json_links = json_object_new_object();
6293
6294 len = ntohs(rl->header.length) - 4;
6295 for (i = 0; i < ntohs(rl->links) && len > 0; len -= 12, i++) {
6296 type = rl->link[i].type;
6297
6298 if (json) {
6299 char link[16];
6300
6301 snprintf(link, sizeof(link), "link%u", i);
6302 json_link = json_object_new_object();
6303 json_object_string_add(json_link, "linkType",
6304 link_type_desc[type]);
6305 json_object_string_add(json_link,
6306 link_id_desc_json[type],
6307 inet_ntop(AF_INET,
6308 &rl->link[i].link_id,
6309 buf, sizeof(buf)));
6310 json_object_string_add(
6311 json_link, link_data_desc_json[type],
6312 inet_ntop(AF_INET, &rl->link[i].link_data,
6313 buf, sizeof(buf)));
6314 json_object_int_add(json_link, "numOfTosMetrics",
6315 metric);
6316 json_object_int_add(json_link, "tos0Metric",
6317 ntohs(rl->link[i].metric));
6318 json_object_object_add(json_links, link, json_link);
6319 } else {
6320 vty_out(vty, " Link connected to: %s\n",
6321 link_type_desc[type]);
6322 vty_out(vty, " (Link ID) %s: %pI4\n",
6323 link_id_desc[type],
6324 &rl->link[i].link_id);
6325 vty_out(vty, " (Link Data) %s: %pI4\n",
6326 link_data_desc[type],
6327 &rl->link[i].link_data);
6328 vty_out(vty, " Number of TOS metrics: 0\n");
6329 vty_out(vty, " TOS 0 Metric: %d\n",
6330 ntohs(rl->link[i].metric));
6331 vty_out(vty, "\n");
6332 }
6333 }
6334 if (json)
6335 json_object_object_add(json, "routerLinks", json_links);
6336 }
6337
6338 /* Show router-LSA detail information. */
6339 static int show_router_lsa_detail(struct vty *vty, struct ospf_lsa *lsa,
6340 json_object *json)
6341 {
6342 if (lsa != NULL) {
6343 struct router_lsa *rl = (struct router_lsa *)lsa->data;
6344
6345 show_ip_ospf_database_header(vty, lsa, json);
6346
6347 if (!json)
6348 vty_out(vty, " Number of Links: %d\n\n",
6349 ntohs(rl->links));
6350 else
6351 json_object_int_add(json, "numOfLinks",
6352 ntohs(rl->links));
6353
6354 show_ip_ospf_database_router_links(vty, rl, json);
6355
6356 if (!json)
6357 vty_out(vty, "\n");
6358 }
6359
6360 return 0;
6361 }
6362
6363 /* Show network-LSA detail information. */
6364 static int show_network_lsa_detail(struct vty *vty, struct ospf_lsa *lsa,
6365 json_object *json)
6366 {
6367 int length, i;
6368 char buf[PREFIX_STRLEN];
6369 json_object *json_attached_rt = NULL;
6370 json_object *json_router = NULL;
6371
6372 if (json)
6373 json_attached_rt = json_object_new_object();
6374
6375 if (lsa != NULL) {
6376 struct network_lsa *nl = (struct network_lsa *)lsa->data;
6377
6378 show_ip_ospf_database_header(vty, lsa, json);
6379
6380 if (!json)
6381 vty_out(vty, " Network Mask: /%d\n",
6382 ip_masklen(nl->mask));
6383 else
6384 json_object_int_add(json, "networkMask",
6385 ip_masklen(nl->mask));
6386
6387 length = ntohs(lsa->data->length) - OSPF_LSA_HEADER_SIZE - 4;
6388
6389 for (i = 0; length > 0; i++, length -= 4)
6390 if (!json) {
6391 vty_out(vty, " Attached Router: %pI4\n",
6392 &nl->routers[i]);
6393 vty_out(vty, "\n");
6394 } else {
6395 json_router = json_object_new_object();
6396 json_object_string_add(
6397 json_router, "attachedRouterId",
6398 inet_ntop(AF_INET, &nl->routers[i],
6399 buf, sizeof(buf)));
6400 json_object_object_add(
6401 json_attached_rt,
6402 inet_ntop(AF_INET, &(nl->routers[i]),
6403 buf, sizeof(buf)),
6404 json_router);
6405 }
6406 }
6407
6408 if (json)
6409 json_object_object_add(json, "attchedRouters",
6410 json_attached_rt);
6411
6412 return 0;
6413 }
6414
6415 /* Show summary-LSA detail information. */
6416 static int show_summary_lsa_detail(struct vty *vty, struct ospf_lsa *lsa,
6417 json_object *json)
6418 {
6419 if (lsa != NULL) {
6420 struct summary_lsa *sl = (struct summary_lsa *)lsa->data;
6421
6422 show_ip_ospf_database_header(vty, lsa, json);
6423
6424 if (!json) {
6425 vty_out(vty, " Network Mask: /%d\n",
6426 ip_masklen(sl->mask));
6427 vty_out(vty, " TOS: 0 Metric: %d\n",
6428 GET_METRIC(sl->metric));
6429 vty_out(vty, "\n");
6430 } else {
6431 json_object_int_add(json, "networkMask",
6432 ip_masklen(sl->mask));
6433 json_object_int_add(json, "tos0Metric",
6434 GET_METRIC(sl->metric));
6435 }
6436 }
6437
6438 return 0;
6439 }
6440
6441 /* Show summary-ASBR-LSA detail information. */
6442 static int show_summary_asbr_lsa_detail(struct vty *vty, struct ospf_lsa *lsa,
6443 json_object *json)
6444 {
6445 if (lsa != NULL) {
6446 struct summary_lsa *sl = (struct summary_lsa *)lsa->data;
6447
6448 show_ip_ospf_database_header(vty, lsa, json);
6449
6450 if (!json) {
6451 vty_out(vty, " Network Mask: /%d\n",
6452 ip_masklen(sl->mask));
6453 vty_out(vty, " TOS: 0 Metric: %d\n",
6454 GET_METRIC(sl->metric));
6455 vty_out(vty, "\n");
6456 } else {
6457 json_object_int_add(json, "networkMask",
6458 ip_masklen(sl->mask));
6459 json_object_int_add(json, "tos0Metric",
6460 GET_METRIC(sl->metric));
6461 }
6462 }
6463
6464 return 0;
6465 }
6466
6467 /* Show AS-external-LSA detail information. */
6468 static int show_as_external_lsa_detail(struct vty *vty, struct ospf_lsa *lsa,
6469 json_object *json)
6470 {
6471 char buf[PREFIX_STRLEN];
6472 int tos = 0;
6473
6474 if (lsa != NULL) {
6475 struct as_external_lsa *al =
6476 (struct as_external_lsa *)lsa->data;
6477
6478 show_ip_ospf_database_header(vty, lsa, json);
6479
6480 if (!json) {
6481 vty_out(vty, " Network Mask: /%d\n",
6482 ip_masklen(al->mask));
6483 vty_out(vty, " Metric Type: %s\n",
6484 IS_EXTERNAL_METRIC(al->e[0].tos)
6485 ? "2 (Larger than any link state path)"
6486 : "1");
6487 vty_out(vty, " TOS: 0\n");
6488 vty_out(vty, " Metric: %d\n",
6489 GET_METRIC(al->e[0].metric));
6490 vty_out(vty, " Forward Address: %pI4\n",
6491 &al->e[0].fwd_addr);
6492 vty_out(vty,
6493 " External Route Tag: %" ROUTE_TAG_PRI "\n\n",
6494 (route_tag_t)ntohl(al->e[0].route_tag));
6495 } else {
6496 json_object_int_add(json, "networkMask",
6497 ip_masklen(al->mask));
6498 json_object_string_add(
6499 json, "metricType",
6500 IS_EXTERNAL_METRIC(al->e[0].tos)
6501 ? "E2 (Larger than any link state path)"
6502 : "E1");
6503 json_object_int_add(json, "tos", tos);
6504 json_object_int_add(json, "metric",
6505 GET_METRIC(al->e[0].metric));
6506 json_object_string_add(json, "forwardAddress",
6507 inet_ntop(AF_INET,
6508 &(al->e[0].fwd_addr),
6509 buf, sizeof(buf)));
6510 json_object_int_add(
6511 json, "externalRouteTag",
6512 (route_tag_t)ntohl(al->e[0].route_tag));
6513 }
6514 }
6515
6516 return 0;
6517 }
6518
6519 /* Show AS-NSSA-LSA detail information. */
6520 static int show_as_nssa_lsa_detail(struct vty *vty, struct ospf_lsa *lsa,
6521 json_object *json)
6522 {
6523 char buf[PREFIX_STRLEN];
6524 int tos = 0;
6525
6526 if (lsa != NULL) {
6527 struct as_external_lsa *al =
6528 (struct as_external_lsa *)lsa->data;
6529
6530 show_ip_ospf_database_header(vty, lsa, json);
6531
6532 if (!json) {
6533 vty_out(vty, " Network Mask: /%d\n",
6534 ip_masklen(al->mask));
6535 vty_out(vty, " Metric Type: %s\n",
6536 IS_EXTERNAL_METRIC(al->e[0].tos)
6537 ? "2 (Larger than any link state path)"
6538 : "1");
6539 vty_out(vty, " TOS: 0\n");
6540 vty_out(vty, " Metric: %d\n",
6541 GET_METRIC(al->e[0].metric));
6542 vty_out(vty, " NSSA: Forward Address: %pI4\n",
6543 &al->e[0].fwd_addr);
6544 vty_out(vty,
6545 " External Route Tag: %" ROUTE_TAG_PRI
6546 "\n\n",
6547 (route_tag_t)ntohl(al->e[0].route_tag));
6548 } else {
6549 json_object_int_add(json, "networkMask",
6550 ip_masklen(al->mask));
6551 json_object_string_add(
6552 json, "metricType",
6553 IS_EXTERNAL_METRIC(al->e[0].tos)
6554 ? "E2 (Larger than any link state path)"
6555 : "E1");
6556 json_object_int_add(json, "tos", tos);
6557 json_object_int_add(json, "metric",
6558 GET_METRIC(al->e[0].metric));
6559 json_object_string_add(json, "nssaForwardAddress",
6560 inet_ntop(AF_INET,
6561 &al->e[0].fwd_addr,
6562 buf, sizeof(buf)));
6563 json_object_int_add(
6564 json, "externalRouteTag",
6565 (route_tag_t)ntohl(al->e[0].route_tag));
6566 }
6567 }
6568
6569 return 0;
6570 }
6571
6572 static int show_func_dummy(struct vty *vty, struct ospf_lsa *lsa,
6573 json_object *json)
6574 {
6575 return 0;
6576 }
6577
6578 static int show_opaque_lsa_detail(struct vty *vty, struct ospf_lsa *lsa,
6579 json_object *json)
6580 {
6581 if (lsa != NULL) {
6582 show_ip_ospf_database_header(vty, lsa, json);
6583 show_opaque_info_detail(vty, lsa, json);
6584 if (!json)
6585 vty_out(vty, "\n");
6586 }
6587 return 0;
6588 }
6589
6590 int (*show_function[])(struct vty *, struct ospf_lsa *, json_object *) = {
6591 NULL,
6592 show_router_lsa_detail,
6593 show_network_lsa_detail,
6594 show_summary_lsa_detail,
6595 show_summary_asbr_lsa_detail,
6596 show_as_external_lsa_detail,
6597 show_func_dummy,
6598 show_as_nssa_lsa_detail, /* almost same as external */
6599 NULL, /* type-8 */
6600 show_opaque_lsa_detail,
6601 show_opaque_lsa_detail,
6602 show_opaque_lsa_detail,
6603 };
6604
6605 static void show_lsa_prefix_set(struct vty *vty, struct prefix_ls *lp,
6606 struct in_addr *id, struct in_addr *adv_router)
6607 {
6608 memset(lp, 0, sizeof(struct prefix_ls));
6609 lp->family = 0;
6610 if (id == NULL)
6611 lp->prefixlen = 0;
6612 else if (adv_router == NULL) {
6613 lp->prefixlen = 32;
6614 lp->id = *id;
6615 } else {
6616 lp->prefixlen = 64;
6617 lp->id = *id;
6618 lp->adv_router = *adv_router;
6619 }
6620 }
6621
6622 static void show_lsa_detail_proc(struct vty *vty, struct route_table *rt,
6623 struct in_addr *id, struct in_addr *adv_router,
6624 json_object *json)
6625 {
6626 struct prefix_ls lp;
6627 struct route_node *rn, *start;
6628 struct ospf_lsa *lsa;
6629 json_object *json_lsa = NULL;
6630
6631 show_lsa_prefix_set(vty, &lp, id, adv_router);
6632 start = route_node_get(rt, (struct prefix *)&lp);
6633 if (start) {
6634 route_lock_node(start);
6635 for (rn = start; rn; rn = route_next_until(rn, start))
6636 if ((lsa = rn->info)) {
6637 if (json) {
6638 json_lsa = json_object_new_object();
6639 json_object_array_add(json, json_lsa);
6640 }
6641
6642 if (show_function[lsa->data->type] != NULL)
6643 show_function[lsa->data->type](
6644 vty, lsa, json_lsa);
6645 }
6646 route_unlock_node(start);
6647 }
6648 }
6649
6650 /* Show detail LSA information
6651 -- if id is NULL then show all LSAs. */
6652 static void show_lsa_detail(struct vty *vty, struct ospf *ospf, int type,
6653 struct in_addr *id, struct in_addr *adv_router,
6654 json_object *json)
6655 {
6656 struct listnode *node;
6657 struct ospf_area *area;
6658 char buf[PREFIX_STRLEN];
6659 json_object *json_lsa_type = NULL;
6660 json_object *json_areas = NULL;
6661 json_object *json_lsa_array = NULL;
6662
6663 if (json)
6664 json_lsa_type = json_object_new_object();
6665
6666 switch (type) {
6667 case OSPF_AS_EXTERNAL_LSA:
6668 case OSPF_OPAQUE_AS_LSA:
6669 if (!json)
6670 vty_out(vty, " %s \n\n",
6671 show_database_desc[type]);
6672 else
6673 json_lsa_array = json_object_new_array();
6674
6675 show_lsa_detail_proc(vty, AS_LSDB(ospf, type), id, adv_router,
6676 json_lsa_array);
6677 if (json)
6678 json_object_object_add(json,
6679 show_database_desc_json[type],
6680 json_lsa_array);
6681
6682 break;
6683 default:
6684 if (json)
6685 json_areas = json_object_new_object();
6686
6687 for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) {
6688 if (!json) {
6689 vty_out(vty,
6690 "\n %s (Area %s)\n\n",
6691 show_database_desc[type],
6692 ospf_area_desc_string(area));
6693 } else {
6694 json_lsa_array = json_object_new_array();
6695 json_object_object_add(json_areas,
6696 inet_ntop(AF_INET,
6697 &area->area_id,
6698 buf,
6699 sizeof(buf)),
6700 json_lsa_array);
6701 }
6702
6703 show_lsa_detail_proc(vty, AREA_LSDB(area, type), id,
6704 adv_router, json_lsa_array);
6705 }
6706
6707 if (json) {
6708 json_object_object_add(json_lsa_type, "areas",
6709 json_areas);
6710 json_object_object_add(json,
6711 show_database_desc_json[type],
6712 json_lsa_type);
6713 }
6714 break;
6715 }
6716 }
6717
6718 static void show_lsa_detail_adv_router_proc(struct vty *vty,
6719 struct route_table *rt,
6720 struct in_addr *adv_router,
6721 json_object *json)
6722 {
6723 char buf[PREFIX_STRLEN];
6724 struct route_node *rn;
6725 struct ospf_lsa *lsa;
6726
6727 for (rn = route_top(rt); rn; rn = route_next(rn))
6728 if ((lsa = rn->info)) {
6729 json_object *json_lsa = NULL;
6730
6731 if (IPV4_ADDR_SAME(adv_router,
6732 &lsa->data->adv_router)) {
6733 if (CHECK_FLAG(lsa->flags, OSPF_LSA_LOCAL_XLT))
6734 continue;
6735 if (json)
6736 json_lsa = json_object_new_object();
6737
6738 if (show_function[lsa->data->type] != NULL)
6739 show_function[lsa->data->type](
6740 vty, lsa, json_lsa);
6741 if (json)
6742 json_object_object_add(
6743 json,
6744 inet_ntop(AF_INET,
6745 &lsa->data->id,
6746 buf, sizeof(buf)),
6747 json_lsa);
6748 }
6749 }
6750 }
6751
6752 /* Show detail LSA information. */
6753 static void show_lsa_detail_adv_router(struct vty *vty, struct ospf *ospf,
6754 int type, struct in_addr *adv_router,
6755 json_object *json)
6756 {
6757 struct listnode *node;
6758 struct ospf_area *area;
6759 char buf[PREFIX_STRLEN];
6760 json_object *json_lstype = NULL;
6761 json_object *json_area = NULL;
6762
6763 if (json)
6764 json_lstype = json_object_new_object();
6765
6766 switch (type) {
6767 case OSPF_AS_EXTERNAL_LSA:
6768 case OSPF_OPAQUE_AS_LSA:
6769 if (!json)
6770 vty_out(vty, " %s \n\n",
6771 show_database_desc[type]);
6772
6773 show_lsa_detail_adv_router_proc(vty, AS_LSDB(ospf, type),
6774 adv_router, json_lstype);
6775 break;
6776 default:
6777
6778 for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) {
6779 if (json)
6780 json_area = json_object_new_object();
6781 else
6782 vty_out(vty,
6783 "\n %s (Area %s)\n\n",
6784 show_database_desc[type],
6785 ospf_area_desc_string(area));
6786 show_lsa_detail_adv_router_proc(vty,
6787 AREA_LSDB(area, type),
6788 adv_router, json_area);
6789
6790 if (json)
6791 json_object_object_add(json_lstype,
6792 inet_ntop(AF_INET,
6793 &area->area_id,
6794 buf,
6795 sizeof(buf)),
6796 json_area);
6797 }
6798 break;
6799 }
6800
6801 if (json)
6802 json_object_object_add(json, show_database_desc[type],
6803 json_lstype);
6804 }
6805
6806 void show_ip_ospf_database_summary(struct vty *vty, struct ospf *ospf, int self,
6807 json_object *json)
6808 {
6809 struct ospf_lsa *lsa;
6810 struct route_node *rn;
6811 struct ospf_area *area;
6812 struct listnode *node;
6813 char buf[PREFIX_STRLEN];
6814 json_object *json_areas = NULL;
6815 json_object *json_area = NULL;
6816 json_object *json_lsa = NULL;
6817 int type;
6818 json_object *json_lsa_array = NULL;
6819
6820 if (json)
6821 json_areas = json_object_new_object();
6822
6823 for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) {
6824 if (json)
6825 json_area = json_object_new_object();
6826
6827 for (type = OSPF_MIN_LSA; type < OSPF_MAX_LSA; type++) {
6828 switch (type) {
6829 case OSPF_AS_EXTERNAL_LSA:
6830 case OSPF_OPAQUE_AS_LSA:
6831 continue;
6832 default:
6833 break;
6834 }
6835 if (ospf_lsdb_count_self(area->lsdb, type) > 0
6836 || (!self
6837 && ospf_lsdb_count(area->lsdb, type) > 0)) {
6838
6839 if (!json) {
6840 vty_out(vty,
6841 " %s (Area %s)\n\n",
6842 show_database_desc[type],
6843 ospf_area_desc_string(area));
6844 vty_out(vty, "%s\n",
6845 show_database_header[type]);
6846 } else {
6847 json_lsa_array =
6848 json_object_new_array();
6849 json_object_object_add(
6850 json_area,
6851 show_database_desc_json[type],
6852 json_lsa_array);
6853 }
6854
6855 LSDB_LOOP (AREA_LSDB(area, type), rn, lsa) {
6856 if (json) {
6857 json_lsa =
6858 json_object_new_object();
6859 json_object_array_add(
6860 json_lsa_array,
6861 json_lsa);
6862 }
6863
6864 show_lsa_summary(vty, lsa, self,
6865 json_lsa);
6866 }
6867
6868 if (!json)
6869 vty_out(vty, "\n");
6870 }
6871 }
6872 if (json)
6873 json_object_object_add(json_areas,
6874 inet_ntop(AF_INET,
6875 &area->area_id,
6876 buf, sizeof(buf)),
6877 json_area);
6878 }
6879
6880 if (json)
6881 json_object_object_add(json, "areas", json_areas);
6882
6883 for (type = OSPF_MIN_LSA; type < OSPF_MAX_LSA; type++) {
6884 switch (type) {
6885 case OSPF_AS_EXTERNAL_LSA:
6886 case OSPF_OPAQUE_AS_LSA:
6887 break;
6888 default:
6889 continue;
6890 }
6891 if (ospf_lsdb_count_self(ospf->lsdb, type)
6892 || (!self && ospf_lsdb_count(ospf->lsdb, type))) {
6893 if (!json) {
6894 vty_out(vty, " %s\n\n",
6895 show_database_desc[type]);
6896 vty_out(vty, "%s\n",
6897 show_database_header[type]);
6898 } else {
6899 json_lsa_array = json_object_new_array();
6900 json_object_object_add(
6901 json, show_database_desc_json[type],
6902 json_lsa_array);
6903 }
6904
6905 LSDB_LOOP (AS_LSDB(ospf, type), rn, lsa) {
6906 if (json) {
6907 json_lsa = json_object_new_object();
6908 json_object_array_add(json_lsa_array,
6909 json_lsa);
6910 }
6911
6912 show_lsa_summary(vty, lsa, self, json_lsa);
6913 }
6914
6915 if (!json)
6916 vty_out(vty, "\n");
6917 }
6918 }
6919
6920 if (!json)
6921 vty_out(vty, "\n");
6922 }
6923
6924 static void show_ip_ospf_database_maxage(struct vty *vty, struct ospf *ospf,
6925 json_object *json)
6926 {
6927 struct route_node *rn;
6928 char buf[PREFIX_STRLEN];
6929 json_object *json_maxage = NULL;
6930
6931 if (!json)
6932 vty_out(vty, "\n MaxAge Link States:\n\n");
6933 else
6934 json_maxage = json_object_new_object();
6935
6936 for (rn = route_top(ospf->maxage_lsa); rn; rn = route_next(rn)) {
6937 struct ospf_lsa *lsa;
6938 json_object *json_lsa = NULL;
6939
6940 if ((lsa = rn->info) != NULL) {
6941 if (!json) {
6942 vty_out(vty, "Link type: %d\n",
6943 lsa->data->type);
6944 vty_out(vty, "Link State ID: %pI4\n",
6945 &lsa->data->id);
6946 vty_out(vty, "Advertising Router: %pI4\n",
6947 &lsa->data->adv_router);
6948 vty_out(vty, "LSA lock count: %d\n", lsa->lock);
6949 vty_out(vty, "\n");
6950 } else {
6951 json_lsa = json_object_new_object();
6952 json_object_int_add(json_lsa, "linkType",
6953 lsa->data->type);
6954 json_object_string_add(
6955 json_lsa, "linkStateId",
6956 inet_ntop(AF_INET, &lsa->data->id,
6957 buf, sizeof(buf)));
6958 json_object_string_add(
6959 json_lsa, "advertisingRouter",
6960 inet_ntop(AF_INET,
6961 &lsa->data->adv_router,
6962 buf, sizeof(buf)));
6963 json_object_int_add(json_lsa, "lsaLockCount",
6964 lsa->lock);
6965 json_object_object_add(
6966 json_maxage,
6967 inet_ntop(AF_INET,
6968 &lsa->data->id,
6969 buf, sizeof(buf)),
6970 json_lsa);
6971 }
6972 }
6973 }
6974 if (json)
6975 json_object_object_add(json, "maxAgeLinkStates", json_maxage);
6976 }
6977
6978 #define OSPF_LSA_TYPE_NSSA_DESC "NSSA external link state\n"
6979 #define OSPF_LSA_TYPE_NSSA_CMD_STR "|nssa-external"
6980
6981 #define OSPF_LSA_TYPE_OPAQUE_LINK_DESC "Link local Opaque-LSA\n"
6982 #define OSPF_LSA_TYPE_OPAQUE_AREA_DESC "Link area Opaque-LSA\n"
6983 #define OSPF_LSA_TYPE_OPAQUE_AS_DESC "Link AS Opaque-LSA\n"
6984 #define OSPF_LSA_TYPE_OPAQUE_CMD_STR "|opaque-link|opaque-area|opaque-as"
6985
6986 #define OSPF_LSA_TYPES_DESC \
6987 "ASBR summary link states\n" \
6988 "External link states\n" \
6989 "Network link states\n" \
6990 "Router link states\n" \
6991 "Network summary link states\n" OSPF_LSA_TYPE_NSSA_DESC \
6992 OSPF_LSA_TYPE_OPAQUE_LINK_DESC OSPF_LSA_TYPE_OPAQUE_AREA_DESC \
6993 OSPF_LSA_TYPE_OPAQUE_AS_DESC
6994
6995 static int show_ip_ospf_database_common(struct vty *vty, struct ospf *ospf,
6996 int arg_base, int argc,
6997 struct cmd_token **argv,
6998 uint8_t use_vrf, json_object *json,
6999 bool uj)
7000 {
7001 int idx_type = 4;
7002 int type, ret;
7003 struct in_addr id, adv_router;
7004 char buf[PREFIX_STRLEN];
7005 json_object *json_vrf = NULL;
7006
7007 if (uj) {
7008 if (use_vrf)
7009 json_vrf = json_object_new_object();
7010 else
7011 json_vrf = json;
7012 }
7013
7014 if (ospf->instance) {
7015 if (uj)
7016 json_object_int_add(json_vrf, "ospfInstance",
7017 ospf->instance);
7018 else
7019 vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
7020 }
7021
7022 ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf);
7023
7024 /* Show Router ID. */
7025 if (uj) {
7026 json_object_string_add(json_vrf, "routerId",
7027 inet_ntop(AF_INET, &ospf->router_id,
7028 buf, sizeof(buf)));
7029 } else {
7030 vty_out(vty, "\n OSPF Router with ID (%pI4)\n\n",
7031 &ospf->router_id);
7032 }
7033
7034 /* Show all LSA. */
7035 if ((argc == arg_base + 4) || (uj && (argc == arg_base + 5))) {
7036 show_ip_ospf_database_summary(vty, ospf, 0, json_vrf);
7037 if (json) {
7038 if (use_vrf) {
7039 if (ospf->vrf_id == VRF_DEFAULT)
7040 json_object_object_add(json, "default",
7041 json_vrf);
7042 else
7043 json_object_object_add(json, ospf->name,
7044 json_vrf);
7045 }
7046 }
7047 return CMD_SUCCESS;
7048 }
7049
7050 /* Set database type to show. */
7051 if (strncmp(argv[arg_base + idx_type]->text, "r", 1) == 0)
7052 type = OSPF_ROUTER_LSA;
7053 else if (strncmp(argv[arg_base + idx_type]->text, "ne", 2) == 0)
7054 type = OSPF_NETWORK_LSA;
7055 else if (strncmp(argv[arg_base + idx_type]->text, "ns", 2) == 0)
7056 type = OSPF_AS_NSSA_LSA;
7057 else if (strncmp(argv[arg_base + idx_type]->text, "su", 2) == 0)
7058 type = OSPF_SUMMARY_LSA;
7059 else if (strncmp(argv[arg_base + idx_type]->text, "a", 1) == 0)
7060 type = OSPF_ASBR_SUMMARY_LSA;
7061 else if (strncmp(argv[arg_base + idx_type]->text, "e", 1) == 0)
7062 type = OSPF_AS_EXTERNAL_LSA;
7063 else if (strncmp(argv[arg_base + idx_type]->text, "se", 2) == 0) {
7064 show_ip_ospf_database_summary(vty, ospf, 1, json_vrf);
7065 if (json) {
7066 if (use_vrf) {
7067 if (ospf->vrf_id == VRF_DEFAULT)
7068 json_object_object_add(json, "default",
7069 json_vrf);
7070 else
7071 json_object_object_add(json, ospf->name,
7072 json_vrf);
7073 }
7074 }
7075 return CMD_SUCCESS;
7076 } else if (strncmp(argv[arg_base + idx_type]->text, "m", 1) == 0) {
7077 show_ip_ospf_database_maxage(vty, ospf, json_vrf);
7078 if (json) {
7079 if (use_vrf) {
7080 if (ospf->vrf_id == VRF_DEFAULT)
7081 json_object_object_add(json, "default",
7082 json_vrf);
7083 else
7084 json_object_object_add(json, ospf->name,
7085 json_vrf);
7086 }
7087 }
7088 return CMD_SUCCESS;
7089 } else if (strncmp(argv[arg_base + idx_type]->text, "opaque-l", 8) == 0)
7090 type = OSPF_OPAQUE_LINK_LSA;
7091 else if (strncmp(argv[arg_base + idx_type]->text, "opaque-ar", 9) == 0)
7092 type = OSPF_OPAQUE_AREA_LSA;
7093 else if (strncmp(argv[arg_base + idx_type]->text, "opaque-as", 9) == 0)
7094 type = OSPF_OPAQUE_AS_LSA;
7095 else
7096 return CMD_WARNING;
7097
7098 /* `show ip ospf database LSA'. */
7099 if ((argc == arg_base + 5) || (uj && (argc == arg_base + 6)))
7100 show_lsa_detail(vty, ospf, type, NULL, NULL, json_vrf);
7101 else if (argc >= arg_base + 6) {
7102 ret = inet_aton(argv[arg_base + 5]->arg, &id);
7103 if (!ret)
7104 return CMD_WARNING;
7105
7106 /* `show ip ospf database LSA ID'. */
7107 if ((argc == arg_base + 6) || (uj && (argc == arg_base + 7)))
7108 show_lsa_detail(vty, ospf, type, &id, NULL, json_vrf);
7109 /* `show ip ospf database LSA ID adv-router ADV_ROUTER'. */
7110 else if ((argc == arg_base + 7)
7111 || (uj && (argc == arg_base + 8))) {
7112 if (strncmp(argv[arg_base + 6]->text, "s", 1) == 0)
7113 adv_router = ospf->router_id;
7114 else {
7115 ret = inet_aton(argv[arg_base + 7]->arg,
7116 &adv_router);
7117 if (!ret)
7118 return CMD_WARNING;
7119 }
7120 show_lsa_detail(vty, ospf, type, &id, &adv_router,
7121 json_vrf);
7122 }
7123 }
7124
7125 if (json) {
7126 if (use_vrf) {
7127 if (ospf->vrf_id == VRF_DEFAULT)
7128 json_object_object_add(json, "default",
7129 json_vrf);
7130 else
7131 json_object_object_add(json, ospf->name,
7132 json_vrf);
7133 }
7134 }
7135
7136 return CMD_SUCCESS;
7137 }
7138
7139 DEFUN (show_ip_ospf_database_max,
7140 show_ip_ospf_database_max_cmd,
7141 "show ip ospf [vrf <NAME|all>] database <max-age|self-originate> [json]",
7142 SHOW_STR
7143 IP_STR
7144 "OSPF information\n"
7145 VRF_CMD_HELP_STR
7146 "All VRFs\n"
7147 "Database summary\n"
7148 "LSAs in MaxAge list\n"
7149 "Self-originated link states\n"
7150 JSON_STR)
7151 {
7152 struct ospf *ospf = NULL;
7153 struct listnode *node = NULL;
7154 char *vrf_name = NULL;
7155 bool all_vrf = false;
7156 int ret = CMD_SUCCESS;
7157 int inst = 0;
7158 int idx_vrf = 0;
7159 uint8_t use_vrf = 0;
7160 bool uj = use_json(argc, argv);
7161 json_object *json = NULL;
7162
7163 if (uj)
7164 json = json_object_new_object();
7165
7166 OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
7167
7168 if (vrf_name) {
7169 bool ospf_output = false;
7170
7171 use_vrf = 1;
7172
7173 if (all_vrf) {
7174 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
7175 if (!ospf->oi_running)
7176 continue;
7177 ospf_output = true;
7178 ret = show_ip_ospf_database_common(
7179 vty, ospf, idx_vrf ? 2 : 0, argc, argv,
7180 use_vrf, json, uj);
7181 }
7182
7183 if (!ospf_output)
7184 vty_out(vty, "%% OSPF instance not found\n");
7185 } else {
7186 ospf = ospf_lookup_by_inst_name(inst, vrf_name);
7187 if (ospf == NULL || !ospf->oi_running) {
7188 vty_out(vty, "%% OSPF instance not found\n");
7189 return CMD_SUCCESS;
7190 }
7191 ret = (show_ip_ospf_database_common(
7192 vty, ospf, idx_vrf ? 2 : 0, argc, argv, use_vrf,
7193 json, uj));
7194 }
7195 } else {
7196 /* Display default ospf (instance 0) info */
7197 ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
7198 if (ospf == NULL || !ospf->oi_running) {
7199 vty_out(vty, "%% OSPF instance not found\n");
7200 return CMD_SUCCESS;
7201 }
7202
7203 ret = show_ip_ospf_database_common(vty, ospf, 0, argc, argv,
7204 use_vrf, json, uj);
7205 }
7206
7207 if (uj) {
7208 vty_out(vty, "%s\n", json_object_to_json_string(json));
7209 json_object_free(json);
7210 }
7211
7212 return ret;
7213 }
7214
7215 ALIAS (show_ip_ospf_database_max,
7216 show_ip_ospf_database_cmd,
7217 "show ip ospf [vrf <NAME|all>] database [<asbr-summary|external|network|router|summary|nssa-external|opaque-link|opaque-area|opaque-as> [A.B.C.D [<self-originate|adv-router A.B.C.D>]]] [json]",
7218 SHOW_STR
7219 IP_STR
7220 "OSPF information\n"
7221 VRF_CMD_HELP_STR
7222 "All VRFs\n"
7223 "Database summary\n"
7224 OSPF_LSA_TYPES_DESC
7225 "Link State ID (as an IP address)\n"
7226 "Self-originated link states\n"
7227 "Advertising Router link states\n"
7228 "Advertising Router (as an IP address)\n"
7229 JSON_STR)
7230
7231 DEFUN (show_ip_ospf_instance_database_max,
7232 show_ip_ospf_instance_database_max_cmd,
7233 "show ip ospf (1-65535) database <max-age|self-originate> [json]",
7234 SHOW_STR
7235 IP_STR
7236 "OSPF information\n"
7237 "Instance ID\n"
7238 "Database summary\n"
7239 "LSAs in MaxAge list\n"
7240 "Self-originated link states\n"
7241 JSON_STR)
7242 {
7243 int idx_number = 3;
7244 struct ospf *ospf;
7245 unsigned short instance = 0;
7246 bool uj = use_json(argc, argv);
7247 json_object *json = NULL;
7248
7249 if (uj)
7250 json = json_object_new_object();
7251
7252 instance = strtoul(argv[idx_number]->arg, NULL, 10);
7253 if (instance != ospf_instance)
7254 return CMD_NOT_MY_INSTANCE;
7255
7256 ospf = ospf_lookup_instance(instance);
7257 if (!ospf || !ospf->oi_running)
7258 return CMD_SUCCESS;
7259
7260 show_ip_ospf_database_common(vty, ospf, 1, argc, argv, 0, json, uj);
7261
7262 if (uj) {
7263 vty_out(vty, "%s\n",
7264 json_object_to_json_string_ext(
7265 json, JSON_C_TO_STRING_PRETTY));
7266 json_object_free(json);
7267 }
7268
7269 return CMD_SUCCESS;
7270 }
7271
7272 ALIAS (show_ip_ospf_instance_database_max,
7273 show_ip_ospf_instance_database_cmd,
7274 "show ip ospf (1-65535) database [<asbr-summary|external|network|router|summary|nssa-external|opaque-link|opaque-area|opaque-as> [A.B.C.D [<self-originate|adv-router A.B.C.D>]]] [json]",
7275 SHOW_STR
7276 IP_STR
7277 "OSPF information\n"
7278 "Instance ID\n"
7279 "Database summary\n"
7280 OSPF_LSA_TYPES_DESC
7281 "Link State ID (as an IP address)\n"
7282 "Self-originated link states\n"
7283 "Advertising Router link states\n"
7284 "Advertising Router (as an IP address)\n"
7285 JSON_STR)
7286
7287 static int show_ip_ospf_database_type_adv_router_common(struct vty *vty,
7288 struct ospf *ospf,
7289 int arg_base, int argc,
7290 struct cmd_token **argv,
7291 uint8_t use_vrf,
7292 json_object *json,
7293 bool uj)
7294 {
7295 int idx_type = 4;
7296 int type, ret;
7297 struct in_addr adv_router;
7298 char buf[PREFIX_STRLEN];
7299 json_object *json_vrf = NULL;
7300
7301 if (uj) {
7302 if (use_vrf)
7303 json_vrf = json_object_new_object();
7304 else
7305 json_vrf = json;
7306 }
7307
7308 if (ospf->instance) {
7309 if (uj)
7310 json_object_int_add(json, "ospfInstance",
7311 ospf->instance);
7312 else
7313 vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
7314 }
7315
7316 ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf);
7317
7318 /* Show Router ID. */
7319 if (uj) {
7320 json_object_string_add(json_vrf, "routerId",
7321 inet_ntop(AF_INET, &ospf->router_id,
7322 buf, sizeof(buf)));
7323 } else {
7324 vty_out(vty, "\n OSPF Router with ID (%pI4)\n\n",
7325 &ospf->router_id);
7326 }
7327
7328 /* Set database type to show. */
7329 if (strncmp(argv[arg_base + idx_type]->text, "r", 1) == 0)
7330 type = OSPF_ROUTER_LSA;
7331 else if (strncmp(argv[arg_base + idx_type]->text, "ne", 2) == 0)
7332 type = OSPF_NETWORK_LSA;
7333 else if (strncmp(argv[arg_base + idx_type]->text, "ns", 2) == 0)
7334 type = OSPF_AS_NSSA_LSA;
7335 else if (strncmp(argv[arg_base + idx_type]->text, "s", 1) == 0)
7336 type = OSPF_SUMMARY_LSA;
7337 else if (strncmp(argv[arg_base + idx_type]->text, "a", 1) == 0)
7338 type = OSPF_ASBR_SUMMARY_LSA;
7339 else if (strncmp(argv[arg_base + idx_type]->text, "e", 1) == 0)
7340 type = OSPF_AS_EXTERNAL_LSA;
7341 else if (strncmp(argv[arg_base + idx_type]->text, "opaque-l", 8) == 0)
7342 type = OSPF_OPAQUE_LINK_LSA;
7343 else if (strncmp(argv[arg_base + idx_type]->text, "opaque-ar", 9) == 0)
7344 type = OSPF_OPAQUE_AREA_LSA;
7345 else if (strncmp(argv[arg_base + idx_type]->text, "opaque-as", 9) == 0)
7346 type = OSPF_OPAQUE_AS_LSA;
7347 else
7348 return CMD_WARNING;
7349
7350 /* `show ip ospf database LSA adv-router ADV_ROUTER'. */
7351 if (strncmp(argv[arg_base + 5]->text, "s", 1) == 0)
7352 adv_router = ospf->router_id;
7353 else {
7354 ret = inet_aton(argv[arg_base + 6]->arg, &adv_router);
7355 if (!ret)
7356 return CMD_WARNING;
7357 }
7358
7359 show_lsa_detail_adv_router(vty, ospf, type, &adv_router, json_vrf);
7360
7361 if (json) {
7362 if (use_vrf) {
7363 if (ospf->vrf_id == VRF_DEFAULT)
7364 json_object_object_add(json, "default",
7365 json_vrf);
7366 else
7367 json_object_object_add(json, ospf->name,
7368 json_vrf);
7369 }
7370 }
7371
7372 return CMD_SUCCESS;
7373 }
7374
7375 DEFUN (show_ip_ospf_database_type_adv_router,
7376 show_ip_ospf_database_type_adv_router_cmd,
7377 "show ip ospf [vrf <NAME|all>] database <asbr-summary|external|network|router|summary|nssa-external|opaque-link|opaque-area|opaque-as> <adv-router A.B.C.D|self-originate> [json]",
7378 SHOW_STR
7379 IP_STR
7380 "OSPF information\n"
7381 VRF_CMD_HELP_STR
7382 "All VRFs\n"
7383 "Database summary\n"
7384 OSPF_LSA_TYPES_DESC
7385 "Advertising Router link states\n"
7386 "Advertising Router (as an IP address)\n"
7387 "Self-originated link states\n"
7388 JSON_STR)
7389 {
7390 struct ospf *ospf = NULL;
7391 struct listnode *node = NULL;
7392 char *vrf_name = NULL;
7393 bool all_vrf = false;
7394 int ret = CMD_SUCCESS;
7395 int inst = 0;
7396 int idx_vrf = 0;
7397 uint8_t use_vrf = 0;
7398 bool uj = use_json(argc, argv);
7399 json_object *json = NULL;
7400
7401 if (uj)
7402 json = json_object_new_object();
7403
7404 OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
7405
7406 if (vrf_name) {
7407 bool ospf_output = false;
7408
7409 use_vrf = 1;
7410
7411 if (all_vrf) {
7412 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
7413 if (!ospf->oi_running)
7414 continue;
7415 ospf_output = true;
7416 ret = show_ip_ospf_database_type_adv_router_common(
7417 vty, ospf, 2, argc, argv, use_vrf, json,
7418 uj);
7419 }
7420 if (!ospf_output)
7421 vty_out(vty, "%% OSPF instance not found\n");
7422 } else {
7423 ospf = ospf_lookup_by_inst_name(inst, vrf_name);
7424 if ((ospf == NULL) || !ospf->oi_running) {
7425 vty_out(vty, "%% OSPF instance not found\n");
7426 return CMD_SUCCESS;
7427 }
7428
7429 ret = show_ip_ospf_database_type_adv_router_common(
7430 vty, ospf, 2, argc, argv, use_vrf, json, uj);
7431 }
7432 } else {
7433 /* Display default ospf (instance 0) info */
7434 ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
7435 if (ospf == NULL || !ospf->oi_running) {
7436 vty_out(vty, "%% OSPF instance not found\n");
7437 return CMD_SUCCESS;
7438 }
7439
7440 ret = show_ip_ospf_database_type_adv_router_common(
7441 vty, ospf, 0, argc, argv, use_vrf, json, uj);
7442 }
7443
7444 if (uj) {
7445 vty_out(vty, "%s\n", json_object_to_json_string(json));
7446 json_object_free(json);
7447 }
7448
7449 return ret;
7450 }
7451
7452 DEFUN (show_ip_ospf_instance_database_type_adv_router,
7453 show_ip_ospf_instance_database_type_adv_router_cmd,
7454 "show ip ospf (1-65535) database <asbr-summary|external|network|router|summary|nssa-external|opaque-link|opaque-area|opaque-as> <adv-router A.B.C.D|self-originate> [json]",
7455 SHOW_STR
7456 IP_STR
7457 "OSPF information\n"
7458 "Instance ID\n"
7459 "Database summary\n"
7460 OSPF_LSA_TYPES_DESC
7461 "Advertising Router link states\n"
7462 "Advertising Router (as an IP address)\n"
7463 "Self-originated link states\n"
7464 JSON_STR)
7465 {
7466 int idx_number = 3;
7467 struct ospf *ospf;
7468 unsigned short instance = 0;
7469 bool uj = use_json(argc, argv);
7470 json_object *json = NULL;
7471
7472 if (uj)
7473 json = json_object_new_object();
7474
7475 instance = strtoul(argv[idx_number]->arg, NULL, 10);
7476 if (instance != ospf_instance)
7477 return CMD_NOT_MY_INSTANCE;
7478
7479 ospf = ospf_lookup_instance(instance);
7480 if (!ospf || !ospf->oi_running)
7481 return CMD_SUCCESS;
7482
7483 show_ip_ospf_database_type_adv_router_common(vty, ospf, 1, argc, argv,
7484 0, json, uj);
7485
7486 if (uj) {
7487 vty_out(vty, "%s\n",
7488 json_object_to_json_string_ext(
7489 json, JSON_C_TO_STRING_PRETTY));
7490 json_object_free(json);
7491 }
7492
7493 return CMD_SUCCESS;
7494 }
7495
7496 DEFUN (ip_ospf_authentication_args,
7497 ip_ospf_authentication_args_addr_cmd,
7498 "ip ospf authentication <null|message-digest> [A.B.C.D]",
7499 "IP Information\n"
7500 "OSPF interface commands\n"
7501 "Enable authentication on this interface\n"
7502 "Use null authentication\n"
7503 "Use message-digest authentication\n"
7504 "Address of interface\n")
7505 {
7506 VTY_DECLVAR_CONTEXT(interface, ifp);
7507 int idx_encryption = 3;
7508 int idx_ipv4 = 4;
7509 struct in_addr addr;
7510 int ret;
7511 struct ospf_if_params *params;
7512
7513 params = IF_DEF_PARAMS(ifp);
7514
7515 if (argc == 5) {
7516 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
7517 if (!ret) {
7518 vty_out(vty,
7519 "Please specify interface address by A.B.C.D\n");
7520 return CMD_WARNING_CONFIG_FAILED;
7521 }
7522
7523 params = ospf_get_if_params(ifp, addr);
7524 ospf_if_update_params(ifp, addr);
7525 }
7526
7527 /* Handle null authentication */
7528 if (argv[idx_encryption]->arg[0] == 'n') {
7529 SET_IF_PARAM(params, auth_type);
7530 params->auth_type = OSPF_AUTH_NULL;
7531 return CMD_SUCCESS;
7532 }
7533
7534 /* Handle message-digest authentication */
7535 if (argv[idx_encryption]->arg[0] == 'm') {
7536 SET_IF_PARAM(params, auth_type);
7537 params->auth_type = OSPF_AUTH_CRYPTOGRAPHIC;
7538 return CMD_SUCCESS;
7539 }
7540
7541 vty_out(vty, "You shouldn't get here!\n");
7542 return CMD_WARNING_CONFIG_FAILED;
7543 }
7544
7545 DEFUN (ip_ospf_authentication,
7546 ip_ospf_authentication_addr_cmd,
7547 "ip ospf authentication [A.B.C.D]",
7548 "IP Information\n"
7549 "OSPF interface commands\n"
7550 "Enable authentication on this interface\n"
7551 "Address of interface\n")
7552 {
7553 VTY_DECLVAR_CONTEXT(interface, ifp);
7554 int idx_ipv4 = 3;
7555 struct in_addr addr;
7556 int ret;
7557 struct ospf_if_params *params;
7558
7559 params = IF_DEF_PARAMS(ifp);
7560
7561 if (argc == 4) {
7562 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
7563 if (!ret) {
7564 vty_out(vty,
7565 "Please specify interface address by A.B.C.D\n");
7566 return CMD_WARNING_CONFIG_FAILED;
7567 }
7568
7569 params = ospf_get_if_params(ifp, addr);
7570 ospf_if_update_params(ifp, addr);
7571 }
7572
7573 SET_IF_PARAM(params, auth_type);
7574 params->auth_type = OSPF_AUTH_SIMPLE;
7575
7576 return CMD_SUCCESS;
7577 }
7578
7579 DEFUN (no_ip_ospf_authentication_args,
7580 no_ip_ospf_authentication_args_addr_cmd,
7581 "no ip ospf authentication <null|message-digest> [A.B.C.D]",
7582 NO_STR
7583 "IP Information\n"
7584 "OSPF interface commands\n"
7585 "Enable authentication on this interface\n"
7586 "Use null authentication\n"
7587 "Use message-digest authentication\n"
7588 "Address of interface\n")
7589 {
7590 VTY_DECLVAR_CONTEXT(interface, ifp);
7591 int idx_encryption = 4;
7592 int idx_ipv4 = 5;
7593 struct in_addr addr;
7594 int ret;
7595 struct ospf_if_params *params;
7596 struct route_node *rn;
7597 int auth_type;
7598
7599 params = IF_DEF_PARAMS(ifp);
7600
7601 if (argc == 6) {
7602 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
7603 if (!ret) {
7604 vty_out(vty,
7605 "Please specify interface address by A.B.C.D\n");
7606 return CMD_WARNING_CONFIG_FAILED;
7607 }
7608
7609 params = ospf_lookup_if_params(ifp, addr);
7610 if (params == NULL) {
7611 vty_out(vty, "Ip Address specified is unknown\n");
7612 return CMD_WARNING_CONFIG_FAILED;
7613 }
7614 params->auth_type = OSPF_AUTH_NOTSET;
7615 UNSET_IF_PARAM(params, auth_type);
7616 if (params != IF_DEF_PARAMS(ifp)) {
7617 ospf_free_if_params(ifp, addr);
7618 ospf_if_update_params(ifp, addr);
7619 }
7620 } else {
7621 if (argv[idx_encryption]->arg[0] == 'n') {
7622 auth_type = OSPF_AUTH_NULL;
7623 } else if (argv[idx_encryption]->arg[0] == 'm') {
7624 auth_type = OSPF_AUTH_CRYPTOGRAPHIC;
7625 } else {
7626 vty_out(vty, "Unexpected input encountered\n");
7627 return CMD_WARNING_CONFIG_FAILED;
7628 }
7629 /*
7630 * Here we have a case where the user has entered
7631 * 'no ip ospf authentication (null | message_digest )'
7632 * we need to find if we have any ip addresses underneath it
7633 * that
7634 * correspond to the associated type.
7635 */
7636 if (params->auth_type == auth_type) {
7637 params->auth_type = OSPF_AUTH_NOTSET;
7638 UNSET_IF_PARAM(params, auth_type);
7639 }
7640
7641 for (rn = route_top(IF_OIFS_PARAMS(ifp)); rn;
7642 rn = route_next(rn)) {
7643 if ((params = rn->info)) {
7644 if (params->auth_type == auth_type) {
7645 params->auth_type = OSPF_AUTH_NOTSET;
7646 UNSET_IF_PARAM(params, auth_type);
7647 if (params != IF_DEF_PARAMS(ifp)) {
7648 ospf_free_if_params(
7649 ifp, rn->p.u.prefix4);
7650 ospf_if_update_params(
7651 ifp, rn->p.u.prefix4);
7652 }
7653 }
7654 }
7655 }
7656 }
7657
7658 return CMD_SUCCESS;
7659 }
7660
7661 DEFUN (no_ip_ospf_authentication,
7662 no_ip_ospf_authentication_addr_cmd,
7663 "no ip ospf authentication [A.B.C.D]",
7664 NO_STR
7665 "IP Information\n"
7666 "OSPF interface commands\n"
7667 "Enable authentication on this interface\n"
7668 "Address of interface\n")
7669 {
7670 VTY_DECLVAR_CONTEXT(interface, ifp);
7671 int idx_ipv4 = 4;
7672 struct in_addr addr;
7673 int ret;
7674 struct ospf_if_params *params;
7675 struct route_node *rn;
7676
7677 params = IF_DEF_PARAMS(ifp);
7678
7679 if (argc == 5) {
7680 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
7681 if (!ret) {
7682 vty_out(vty,
7683 "Please specify interface address by A.B.C.D\n");
7684 return CMD_WARNING_CONFIG_FAILED;
7685 }
7686
7687 params = ospf_lookup_if_params(ifp, addr);
7688 if (params == NULL) {
7689 vty_out(vty, "Ip Address specified is unknown\n");
7690 return CMD_WARNING_CONFIG_FAILED;
7691 }
7692
7693 params->auth_type = OSPF_AUTH_NOTSET;
7694 UNSET_IF_PARAM(params, auth_type);
7695 if (params != IF_DEF_PARAMS(ifp)) {
7696 ospf_free_if_params(ifp, addr);
7697 ospf_if_update_params(ifp, addr);
7698 }
7699 } else {
7700 /*
7701 * When a user enters 'no ip ospf authentication'
7702 * We should remove all authentication types from
7703 * the interface.
7704 */
7705 if ((params->auth_type == OSPF_AUTH_NULL)
7706 || (params->auth_type == OSPF_AUTH_CRYPTOGRAPHIC)
7707 || (params->auth_type == OSPF_AUTH_SIMPLE)) {
7708 params->auth_type = OSPF_AUTH_NOTSET;
7709 UNSET_IF_PARAM(params, auth_type);
7710 }
7711
7712 for (rn = route_top(IF_OIFS_PARAMS(ifp)); rn;
7713 rn = route_next(rn)) {
7714 if ((params = rn->info)) {
7715
7716 if ((params->auth_type == OSPF_AUTH_NULL)
7717 || (params->auth_type
7718 == OSPF_AUTH_CRYPTOGRAPHIC)
7719 || (params->auth_type
7720 == OSPF_AUTH_SIMPLE)) {
7721 params->auth_type = OSPF_AUTH_NOTSET;
7722 UNSET_IF_PARAM(params, auth_type);
7723 if (params != IF_DEF_PARAMS(ifp)) {
7724 ospf_free_if_params(
7725 ifp, rn->p.u.prefix4);
7726 ospf_if_update_params(
7727 ifp, rn->p.u.prefix4);
7728 }
7729 }
7730 }
7731 }
7732 }
7733
7734 return CMD_SUCCESS;
7735 }
7736
7737
7738 DEFUN (ip_ospf_authentication_key,
7739 ip_ospf_authentication_key_addr_cmd,
7740 "ip ospf authentication-key AUTH_KEY [A.B.C.D]",
7741 "IP Information\n"
7742 "OSPF interface commands\n"
7743 "Authentication password (key)\n"
7744 "The OSPF password (key)\n"
7745 "Address of interface\n")
7746 {
7747 VTY_DECLVAR_CONTEXT(interface, ifp);
7748 int idx = 0;
7749 struct in_addr addr;
7750 struct ospf_if_params *params;
7751
7752 params = IF_DEF_PARAMS(ifp);
7753
7754 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
7755 if (!inet_aton(argv[idx]->arg, &addr)) {
7756 vty_out(vty,
7757 "Please specify interface address by A.B.C.D\n");
7758 return CMD_WARNING_CONFIG_FAILED;
7759 }
7760
7761 params = ospf_get_if_params(ifp, addr);
7762 ospf_if_update_params(ifp, addr);
7763 }
7764
7765 strlcpy((char *)params->auth_simple, argv[3]->arg,
7766 sizeof(params->auth_simple));
7767 SET_IF_PARAM(params, auth_simple);
7768
7769 return CMD_SUCCESS;
7770 }
7771
7772 DEFUN_HIDDEN (ospf_authentication_key,
7773 ospf_authentication_key_cmd,
7774 "ospf authentication-key AUTH_KEY [A.B.C.D]",
7775 "OSPF interface commands\n"
7776 VLINK_HELPSTR_AUTH_SIMPLE
7777 "Address of interface\n")
7778 {
7779 return ip_ospf_authentication_key(self, vty, argc, argv);
7780 }
7781
7782 DEFUN (no_ip_ospf_authentication_key,
7783 no_ip_ospf_authentication_key_authkey_addr_cmd,
7784 "no ip ospf authentication-key [AUTH_KEY [A.B.C.D]]",
7785 NO_STR
7786 "IP Information\n"
7787 "OSPF interface commands\n"
7788 VLINK_HELPSTR_AUTH_SIMPLE
7789 "Address of interface\n")
7790 {
7791 VTY_DECLVAR_CONTEXT(interface, ifp);
7792 int idx = 0;
7793 struct in_addr addr;
7794 struct ospf_if_params *params;
7795 params = IF_DEF_PARAMS(ifp);
7796
7797 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
7798 if (!inet_aton(argv[idx]->arg, &addr)) {
7799 vty_out(vty,
7800 "Please specify interface address by A.B.C.D\n");
7801 return CMD_WARNING_CONFIG_FAILED;
7802 }
7803
7804 params = ospf_lookup_if_params(ifp, addr);
7805 if (params == NULL)
7806 return CMD_SUCCESS;
7807 }
7808
7809 memset(params->auth_simple, 0, OSPF_AUTH_SIMPLE_SIZE);
7810 UNSET_IF_PARAM(params, auth_simple);
7811
7812 if (params != IF_DEF_PARAMS(ifp)) {
7813 ospf_free_if_params(ifp, addr);
7814 ospf_if_update_params(ifp, addr);
7815 }
7816
7817 return CMD_SUCCESS;
7818 }
7819
7820 DEFUN_HIDDEN (no_ospf_authentication_key,
7821 no_ospf_authentication_key_authkey_addr_cmd,
7822 "no ospf authentication-key [AUTH_KEY [A.B.C.D]]",
7823 NO_STR
7824 "OSPF interface commands\n"
7825 VLINK_HELPSTR_AUTH_SIMPLE
7826 "Address of interface\n")
7827 {
7828 return no_ip_ospf_authentication_key(self, vty, argc, argv);
7829 }
7830
7831 DEFUN (ip_ospf_message_digest_key,
7832 ip_ospf_message_digest_key_cmd,
7833 "ip ospf message-digest-key (1-255) md5 KEY [A.B.C.D]",
7834 "IP Information\n"
7835 "OSPF interface commands\n"
7836 "Message digest authentication password (key)\n"
7837 "Key ID\n"
7838 "Use MD5 algorithm\n"
7839 "The OSPF password (key)\n"
7840 "Address of interface\n")
7841 {
7842 VTY_DECLVAR_CONTEXT(interface, ifp);
7843 struct crypt_key *ck;
7844 uint8_t key_id;
7845 struct in_addr addr;
7846 struct ospf_if_params *params;
7847
7848 params = IF_DEF_PARAMS(ifp);
7849 int idx = 0;
7850
7851 argv_find(argv, argc, "(1-255)", &idx);
7852 char *keyid = argv[idx]->arg;
7853 argv_find(argv, argc, "KEY", &idx);
7854 char *cryptkey = argv[idx]->arg;
7855
7856 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
7857 if (!inet_aton(argv[idx]->arg, &addr)) {
7858 vty_out(vty,
7859 "Please specify interface address by A.B.C.D\n");
7860 return CMD_WARNING_CONFIG_FAILED;
7861 }
7862
7863 params = ospf_get_if_params(ifp, addr);
7864 ospf_if_update_params(ifp, addr);
7865 }
7866
7867 key_id = strtol(keyid, NULL, 10);
7868
7869 /* Remove existing key, if any */
7870 ospf_crypt_key_delete(params->auth_crypt, key_id);
7871
7872 ck = ospf_crypt_key_new();
7873 ck->key_id = (uint8_t)key_id;
7874 strlcpy((char *)ck->auth_key, cryptkey, sizeof(ck->auth_key));
7875
7876 ospf_crypt_key_add(params->auth_crypt, ck);
7877 SET_IF_PARAM(params, auth_crypt);
7878
7879 return CMD_SUCCESS;
7880 }
7881
7882 DEFUN_HIDDEN (ospf_message_digest_key,
7883 ospf_message_digest_key_cmd,
7884 "ospf message-digest-key (1-255) md5 KEY [A.B.C.D]",
7885 "OSPF interface commands\n"
7886 "Message digest authentication password (key)\n"
7887 "Key ID\n"
7888 "Use MD5 algorithm\n"
7889 "The OSPF password (key)\n"
7890 "Address of interface\n")
7891 {
7892 return ip_ospf_message_digest_key(self, vty, argc, argv);
7893 }
7894
7895 DEFUN (no_ip_ospf_message_digest_key,
7896 no_ip_ospf_message_digest_key_cmd,
7897 "no ip ospf message-digest-key (1-255) [md5 KEY] [A.B.C.D]",
7898 NO_STR
7899 "IP Information\n"
7900 "OSPF interface commands\n"
7901 "Message digest authentication password (key)\n"
7902 "Key ID\n"
7903 "Use MD5 algorithm\n"
7904 "The OSPF password (key)\n"
7905 "Address of interface\n")
7906 {
7907 VTY_DECLVAR_CONTEXT(interface, ifp);
7908 int idx = 0;
7909 struct crypt_key *ck;
7910 int key_id;
7911 struct in_addr addr;
7912 struct ospf_if_params *params;
7913 params = IF_DEF_PARAMS(ifp);
7914
7915 argv_find(argv, argc, "(1-255)", &idx);
7916 char *keyid = argv[idx]->arg;
7917
7918 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
7919 if (!inet_aton(argv[idx]->arg, &addr)) {
7920 vty_out(vty,
7921 "Please specify interface address by A.B.C.D\n");
7922 return CMD_WARNING_CONFIG_FAILED;
7923 }
7924
7925 params = ospf_lookup_if_params(ifp, addr);
7926 if (params == NULL)
7927 return CMD_SUCCESS;
7928 }
7929
7930 key_id = strtol(keyid, NULL, 10);
7931 ck = ospf_crypt_key_lookup(params->auth_crypt, key_id);
7932 if (ck == NULL) {
7933 vty_out(vty, "OSPF: Key %d does not exist\n", key_id);
7934 return CMD_WARNING_CONFIG_FAILED;
7935 }
7936
7937 ospf_crypt_key_delete(params->auth_crypt, key_id);
7938
7939 if (params != IF_DEF_PARAMS(ifp)) {
7940 ospf_free_if_params(ifp, addr);
7941 ospf_if_update_params(ifp, addr);
7942 }
7943
7944 return CMD_SUCCESS;
7945 }
7946
7947 DEFUN_HIDDEN (no_ospf_message_digest_key,
7948 no_ospf_message_digest_key_cmd,
7949 "no ospf message-digest-key (1-255) [md5 KEY] [A.B.C.D]",
7950 NO_STR
7951 "OSPF interface commands\n"
7952 "Message digest authentication password (key)\n"
7953 "Key ID\n"
7954 "Use MD5 algorithm\n"
7955 "The OSPF password (key)\n"
7956 "Address of interface\n")
7957 {
7958 return no_ip_ospf_message_digest_key(self, vty, argc, argv);
7959 }
7960
7961 DEFUN (ip_ospf_cost,
7962 ip_ospf_cost_cmd,
7963 "ip ospf cost (1-65535) [A.B.C.D]",
7964 "IP Information\n"
7965 "OSPF interface commands\n"
7966 "Interface cost\n"
7967 "Cost\n"
7968 "Address of interface\n")
7969 {
7970 VTY_DECLVAR_CONTEXT(interface, ifp);
7971 int idx = 0;
7972 uint32_t cost = OSPF_OUTPUT_COST_DEFAULT;
7973 struct in_addr addr;
7974 struct ospf_if_params *params;
7975 params = IF_DEF_PARAMS(ifp);
7976
7977 // get arguments
7978 char *coststr = NULL, *ifaddr = NULL;
7979
7980 argv_find(argv, argc, "(1-65535)", &idx);
7981 coststr = argv[idx]->arg;
7982 cost = strtol(coststr, NULL, 10);
7983
7984 ifaddr = argv_find(argv, argc, "A.B.C.D", &idx) ? argv[idx]->arg : NULL;
7985 if (ifaddr) {
7986 if (!inet_aton(ifaddr, &addr)) {
7987 vty_out(vty,
7988 "Please specify interface address by A.B.C.D\n");
7989 return CMD_WARNING_CONFIG_FAILED;
7990 }
7991
7992 params = ospf_get_if_params(ifp, addr);
7993 ospf_if_update_params(ifp, addr);
7994 }
7995
7996 SET_IF_PARAM(params, output_cost_cmd);
7997 params->output_cost_cmd = cost;
7998
7999 ospf_if_recalculate_output_cost(ifp);
8000
8001 return CMD_SUCCESS;
8002 }
8003
8004 DEFUN_HIDDEN (ospf_cost,
8005 ospf_cost_cmd,
8006 "ospf cost (1-65535) [A.B.C.D]",
8007 "OSPF interface commands\n"
8008 "Interface cost\n"
8009 "Cost\n"
8010 "Address of interface\n")
8011 {
8012 return ip_ospf_cost(self, vty, argc, argv);
8013 }
8014
8015 DEFUN (no_ip_ospf_cost,
8016 no_ip_ospf_cost_cmd,
8017 "no ip ospf cost [(1-65535)] [A.B.C.D]",
8018 NO_STR
8019 "IP Information\n"
8020 "OSPF interface commands\n"
8021 "Interface cost\n"
8022 "Cost\n"
8023 "Address of interface\n")
8024 {
8025 VTY_DECLVAR_CONTEXT(interface, ifp);
8026 int idx = 0;
8027 struct in_addr addr;
8028 struct ospf_if_params *params;
8029
8030 params = IF_DEF_PARAMS(ifp);
8031
8032 // get arguments
8033 char *ifaddr = NULL;
8034 ifaddr = argv_find(argv, argc, "A.B.C.D", &idx) ? argv[idx]->arg : NULL;
8035
8036 /* According to the semantics we are mimicking "no ip ospf cost N" is
8037 * always treated as "no ip ospf cost" regardless of the actual value
8038 * of N already configured for the interface. Thus ignore cost. */
8039
8040 if (ifaddr) {
8041 if (!inet_aton(ifaddr, &addr)) {
8042 vty_out(vty,
8043 "Please specify interface address by A.B.C.D\n");
8044 return CMD_WARNING_CONFIG_FAILED;
8045 }
8046
8047 params = ospf_lookup_if_params(ifp, addr);
8048 if (params == NULL)
8049 return CMD_SUCCESS;
8050 }
8051
8052 UNSET_IF_PARAM(params, output_cost_cmd);
8053
8054 if (params != IF_DEF_PARAMS(ifp)) {
8055 ospf_free_if_params(ifp, addr);
8056 ospf_if_update_params(ifp, addr);
8057 }
8058
8059 ospf_if_recalculate_output_cost(ifp);
8060
8061 return CMD_SUCCESS;
8062 }
8063
8064 DEFUN_HIDDEN (no_ospf_cost,
8065 no_ospf_cost_cmd,
8066 "no ospf cost [(1-65535)] [A.B.C.D]",
8067 NO_STR
8068 "OSPF interface commands\n"
8069 "Interface cost\n"
8070 "Cost\n"
8071 "Address of interface\n")
8072 {
8073 return no_ip_ospf_cost(self, vty, argc, argv);
8074 }
8075
8076 static void ospf_nbr_timer_update(struct ospf_interface *oi)
8077 {
8078 struct route_node *rn;
8079 struct ospf_neighbor *nbr;
8080
8081 for (rn = route_top(oi->nbrs); rn; rn = route_next(rn))
8082 if ((nbr = rn->info)) {
8083 nbr->v_inactivity = OSPF_IF_PARAM(oi, v_wait);
8084 nbr->v_db_desc = OSPF_IF_PARAM(oi, retransmit_interval);
8085 nbr->v_ls_req = OSPF_IF_PARAM(oi, retransmit_interval);
8086 nbr->v_ls_upd = OSPF_IF_PARAM(oi, retransmit_interval);
8087 }
8088 }
8089
8090 static int ospf_vty_dead_interval_set(struct vty *vty, const char *interval_str,
8091 const char *nbr_str,
8092 const char *fast_hello_str)
8093 {
8094 VTY_DECLVAR_CONTEXT(interface, ifp);
8095 uint32_t seconds;
8096 uint8_t hellomult;
8097 struct in_addr addr;
8098 int ret;
8099 struct ospf_if_params *params;
8100 struct ospf_interface *oi;
8101 struct route_node *rn;
8102
8103 params = IF_DEF_PARAMS(ifp);
8104
8105 if (nbr_str) {
8106 ret = inet_aton(nbr_str, &addr);
8107 if (!ret) {
8108 vty_out(vty,
8109 "Please specify interface address by A.B.C.D\n");
8110 return CMD_WARNING_CONFIG_FAILED;
8111 }
8112
8113 params = ospf_get_if_params(ifp, addr);
8114 ospf_if_update_params(ifp, addr);
8115 }
8116
8117 if (interval_str) {
8118 seconds = strtoul(interval_str, NULL, 10);
8119
8120 /* reset fast_hello too, just to be sure */
8121 UNSET_IF_PARAM(params, fast_hello);
8122 params->fast_hello = OSPF_FAST_HELLO_DEFAULT;
8123 } else if (fast_hello_str) {
8124 hellomult = strtoul(fast_hello_str, NULL, 10);
8125 /* 1s dead-interval with sub-second hellos desired */
8126 seconds = OSPF_ROUTER_DEAD_INTERVAL_MINIMAL;
8127 SET_IF_PARAM(params, fast_hello);
8128 params->fast_hello = hellomult;
8129 } else {
8130 vty_out(vty,
8131 "Please specify dead-interval or hello-multiplier\n");
8132 return CMD_WARNING_CONFIG_FAILED;
8133 }
8134
8135 SET_IF_PARAM(params, v_wait);
8136 params->v_wait = seconds;
8137 params->is_v_wait_set = true;
8138
8139 /* Update timer values in neighbor structure. */
8140 if (nbr_str) {
8141 struct ospf *ospf = NULL;
8142
8143 ospf = ospf_lookup_by_vrf_id(ifp->vrf_id);
8144 if (ospf) {
8145 oi = ospf_if_lookup_by_local_addr(ospf, ifp, addr);
8146 if (oi)
8147 ospf_nbr_timer_update(oi);
8148 }
8149 } else {
8150 for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn))
8151 if ((oi = rn->info))
8152 ospf_nbr_timer_update(oi);
8153 }
8154
8155 return CMD_SUCCESS;
8156 }
8157
8158 DEFUN (ip_ospf_dead_interval,
8159 ip_ospf_dead_interval_cmd,
8160 "ip ospf dead-interval (1-65535) [A.B.C.D]",
8161 "IP Information\n"
8162 "OSPF interface commands\n"
8163 "Interval time after which a neighbor is declared down\n"
8164 "Seconds\n"
8165 "Address of interface\n")
8166 {
8167 int idx = 0;
8168 char *interval = argv_find(argv, argc, "(1-65535)", &idx)
8169 ? argv[idx]->arg
8170 : NULL;
8171 char *ifaddr =
8172 argv_find(argv, argc, "A.B.C.D", &idx) ? argv[idx]->arg : NULL;
8173 return ospf_vty_dead_interval_set(vty, interval, ifaddr, NULL);
8174 }
8175
8176
8177 DEFUN_HIDDEN (ospf_dead_interval,
8178 ospf_dead_interval_cmd,
8179 "ospf dead-interval (1-65535) [A.B.C.D]",
8180 "OSPF interface commands\n"
8181 "Interval time after which a neighbor is declared down\n"
8182 "Seconds\n"
8183 "Address of interface\n")
8184 {
8185 return ip_ospf_dead_interval(self, vty, argc, argv);
8186 }
8187
8188 DEFUN (ip_ospf_dead_interval_minimal,
8189 ip_ospf_dead_interval_minimal_addr_cmd,
8190 "ip ospf dead-interval minimal hello-multiplier (1-10) [A.B.C.D]",
8191 "IP Information\n"
8192 "OSPF interface commands\n"
8193 "Interval time after which a neighbor is declared down\n"
8194 "Minimal 1s dead-interval with fast sub-second hellos\n"
8195 "Hello multiplier factor\n"
8196 "Number of Hellos to send each second\n"
8197 "Address of interface\n")
8198 {
8199 int idx_number = 5;
8200 int idx_ipv4 = 6;
8201 if (argc == 7)
8202 return ospf_vty_dead_interval_set(
8203 vty, NULL, argv[idx_ipv4]->arg, argv[idx_number]->arg);
8204 else
8205 return ospf_vty_dead_interval_set(vty, NULL, NULL,
8206 argv[idx_number]->arg);
8207 }
8208
8209 DEFUN (no_ip_ospf_dead_interval,
8210 no_ip_ospf_dead_interval_cmd,
8211 "no ip ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]",
8212 NO_STR
8213 "IP Information\n"
8214 "OSPF interface commands\n"
8215 "Interval time after which a neighbor is declared down\n"
8216 "Seconds\n"
8217 "Minimal 1s dead-interval with fast sub-second hellos\n"
8218 "Hello multiplier factor\n"
8219 "Number of Hellos to send each second\n"
8220 "Address of interface\n")
8221 {
8222 VTY_DECLVAR_CONTEXT(interface, ifp);
8223 int idx_ipv4 = argc - 1;
8224 struct in_addr addr = {.s_addr = 0L};
8225 int ret;
8226 struct ospf_if_params *params;
8227 struct ospf_interface *oi;
8228 struct route_node *rn;
8229
8230 params = IF_DEF_PARAMS(ifp);
8231
8232 if (argv[idx_ipv4]->type == IPV4_TKN) {
8233 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
8234 if (!ret) {
8235 vty_out(vty,
8236 "Please specify interface address by A.B.C.D\n");
8237 return CMD_WARNING_CONFIG_FAILED;
8238 }
8239
8240 params = ospf_lookup_if_params(ifp, addr);
8241 if (params == NULL)
8242 return CMD_SUCCESS;
8243 }
8244
8245 UNSET_IF_PARAM(params, v_wait);
8246 params->v_wait = OSPF_ROUTER_DEAD_INTERVAL_DEFAULT;
8247 params->is_v_wait_set = false;
8248
8249 UNSET_IF_PARAM(params, fast_hello);
8250 params->fast_hello = OSPF_FAST_HELLO_DEFAULT;
8251
8252 if (params != IF_DEF_PARAMS(ifp)) {
8253 ospf_free_if_params(ifp, addr);
8254 ospf_if_update_params(ifp, addr);
8255 }
8256
8257 /* Update timer values in neighbor structure. */
8258 if (argc == 1) {
8259 struct ospf *ospf = NULL;
8260
8261 ospf = ospf_lookup_by_vrf_id(ifp->vrf_id);
8262 if (ospf) {
8263 oi = ospf_if_lookup_by_local_addr(ospf, ifp, addr);
8264 if (oi)
8265 ospf_nbr_timer_update(oi);
8266 }
8267 } else {
8268 for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn))
8269 if ((oi = rn->info))
8270 ospf_nbr_timer_update(oi);
8271 }
8272
8273 return CMD_SUCCESS;
8274 }
8275
8276 DEFUN_HIDDEN (no_ospf_dead_interval,
8277 no_ospf_dead_interval_cmd,
8278 "no ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]",
8279 NO_STR
8280 "OSPF interface commands\n"
8281 "Interval time after which a neighbor is declared down\n"
8282 "Seconds\n"
8283 "Minimal 1s dead-interval with fast sub-second hellos\n"
8284 "Hello multiplier factor\n"
8285 "Number of Hellos to send each second\n"
8286 "Address of interface\n")
8287 {
8288 return no_ip_ospf_dead_interval(self, vty, argc, argv);
8289 }
8290
8291 DEFUN (ip_ospf_hello_interval,
8292 ip_ospf_hello_interval_cmd,
8293 "ip ospf hello-interval (1-65535) [A.B.C.D]",
8294 "IP Information\n"
8295 "OSPF interface commands\n"
8296 "Time between HELLO packets\n"
8297 "Seconds\n"
8298 "Address of interface\n")
8299 {
8300 VTY_DECLVAR_CONTEXT(interface, ifp);
8301 int idx = 0;
8302 struct in_addr addr;
8303 struct ospf_if_params *params;
8304 params = IF_DEF_PARAMS(ifp);
8305 uint32_t seconds = 0;
8306
8307 argv_find(argv, argc, "(1-65535)", &idx);
8308 seconds = strtol(argv[idx]->arg, NULL, 10);
8309
8310 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
8311 if (!inet_aton(argv[idx]->arg, &addr)) {
8312 vty_out(vty,
8313 "Please specify interface address by A.B.C.D\n");
8314 return CMD_WARNING_CONFIG_FAILED;
8315 }
8316
8317 params = ospf_get_if_params(ifp, addr);
8318 ospf_if_update_params(ifp, addr);
8319 }
8320
8321 SET_IF_PARAM(params, v_hello);
8322 params->v_hello = seconds;
8323
8324 if (!params->is_v_wait_set) {
8325 SET_IF_PARAM(params, v_wait);
8326 /* As per RFC 4062
8327 * The router dead interval should
8328 * be some multiple of the HelloInterval (perhaps 4 times the
8329 * hello interval) and must be the same for all routers
8330 * attached to a common network.
8331 */
8332 params->v_wait = 4 * seconds;
8333 }
8334
8335 return CMD_SUCCESS;
8336 }
8337
8338 DEFUN_HIDDEN (ospf_hello_interval,
8339 ospf_hello_interval_cmd,
8340 "ospf hello-interval (1-65535) [A.B.C.D]",
8341 "OSPF interface commands\n"
8342 "Time between HELLO packets\n"
8343 "Seconds\n"
8344 "Address of interface\n")
8345 {
8346 return ip_ospf_hello_interval(self, vty, argc, argv);
8347 }
8348
8349 DEFUN (no_ip_ospf_hello_interval,
8350 no_ip_ospf_hello_interval_cmd,
8351 "no ip ospf hello-interval [(1-65535) [A.B.C.D]]",
8352 NO_STR
8353 "IP Information\n"
8354 "OSPF interface commands\n"
8355 "Time between HELLO packets\n" // ignored
8356 "Seconds\n"
8357 "Address of interface\n")
8358 {
8359 VTY_DECLVAR_CONTEXT(interface, ifp);
8360 int idx = 0;
8361 struct in_addr addr;
8362 struct ospf_if_params *params;
8363 struct route_node *rn;
8364
8365 params = IF_DEF_PARAMS(ifp);
8366
8367 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
8368 if (!inet_aton(argv[idx]->arg, &addr)) {
8369 vty_out(vty,
8370 "Please specify interface address by A.B.C.D\n");
8371 return CMD_WARNING_CONFIG_FAILED;
8372 }
8373
8374 params = ospf_lookup_if_params(ifp, addr);
8375 if (params == NULL)
8376 return CMD_SUCCESS;
8377 }
8378
8379 UNSET_IF_PARAM(params, v_hello);
8380 params->v_hello = OSPF_HELLO_INTERVAL_DEFAULT;
8381
8382 if (!params->is_v_wait_set) {
8383 UNSET_IF_PARAM(params, v_wait);
8384 params->v_wait = OSPF_ROUTER_DEAD_INTERVAL_DEFAULT;
8385 }
8386
8387 for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) {
8388 struct ospf_interface *oi = rn->info;
8389
8390 if (!oi)
8391 continue;
8392
8393 oi->type = IF_DEF_PARAMS(ifp)->type;
8394 oi->ptp_dmvpn = IF_DEF_PARAMS(ifp)->ptp_dmvpn;
8395
8396 if (oi->state > ISM_Down) {
8397 OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceDown);
8398 OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceUp);
8399 }
8400 }
8401
8402 if (params != IF_DEF_PARAMS(ifp)) {
8403 ospf_free_if_params(ifp, addr);
8404 ospf_if_update_params(ifp, addr);
8405 }
8406
8407 return CMD_SUCCESS;
8408 }
8409
8410 DEFUN_HIDDEN (no_ospf_hello_interval,
8411 no_ospf_hello_interval_cmd,
8412 "no ospf hello-interval [(1-65535) [A.B.C.D]]",
8413 NO_STR
8414 "OSPF interface commands\n"
8415 "Time between HELLO packets\n" // ignored
8416 "Seconds\n"
8417 "Address of interface\n")
8418 {
8419 return no_ip_ospf_hello_interval(self, vty, argc, argv);
8420 }
8421
8422 DEFUN(ip_ospf_network, ip_ospf_network_cmd,
8423 "ip ospf network <broadcast|non-broadcast|point-to-multipoint|point-to-point [dmvpn]>",
8424 "IP Information\n"
8425 "OSPF interface commands\n"
8426 "Network type\n"
8427 "Specify OSPF broadcast multi-access network\n"
8428 "Specify OSPF NBMA network\n"
8429 "Specify OSPF point-to-multipoint network\n"
8430 "Specify OSPF point-to-point network\n"
8431 "Specify OSPF point-to-point DMVPN network\n")
8432 {
8433 VTY_DECLVAR_CONTEXT(interface, ifp);
8434 int idx = 0;
8435 int old_type = IF_DEF_PARAMS(ifp)->type;
8436 uint8_t old_ptp_dmvpn = IF_DEF_PARAMS(ifp)->ptp_dmvpn;
8437 struct route_node *rn;
8438
8439 if (old_type == OSPF_IFTYPE_LOOPBACK) {
8440 vty_out(vty,
8441 "This is a loopback interface. Can't set network type.\n");
8442 return CMD_WARNING_CONFIG_FAILED;
8443 }
8444
8445 IF_DEF_PARAMS(ifp)->ptp_dmvpn = 0;
8446
8447 if (argv_find(argv, argc, "broadcast", &idx))
8448 IF_DEF_PARAMS(ifp)->type = OSPF_IFTYPE_BROADCAST;
8449 else if (argv_find(argv, argc, "non-broadcast", &idx))
8450 IF_DEF_PARAMS(ifp)->type = OSPF_IFTYPE_NBMA;
8451 else if (argv_find(argv, argc, "point-to-multipoint", &idx))
8452 IF_DEF_PARAMS(ifp)->type = OSPF_IFTYPE_POINTOMULTIPOINT;
8453 else if (argv_find(argv, argc, "point-to-point", &idx)) {
8454 IF_DEF_PARAMS(ifp)->type = OSPF_IFTYPE_POINTOPOINT;
8455 if (argv_find(argv, argc, "dmvpn", &idx))
8456 IF_DEF_PARAMS(ifp)->ptp_dmvpn = 1;
8457 }
8458
8459 if (IF_DEF_PARAMS(ifp)->type == old_type
8460 && IF_DEF_PARAMS(ifp)->ptp_dmvpn == old_ptp_dmvpn)
8461 return CMD_SUCCESS;
8462
8463 SET_IF_PARAM(IF_DEF_PARAMS(ifp), type);
8464
8465 for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) {
8466 struct ospf_interface *oi = rn->info;
8467
8468 if (!oi)
8469 continue;
8470
8471 oi->type = IF_DEF_PARAMS(ifp)->type;
8472
8473 if (oi->state > ISM_Down) {
8474 OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceDown);
8475 OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceUp);
8476 }
8477 }
8478
8479 return CMD_SUCCESS;
8480 }
8481
8482 DEFUN_HIDDEN (ospf_network,
8483 ospf_network_cmd,
8484 "ospf network <broadcast|non-broadcast|point-to-multipoint|point-to-point>",
8485 "OSPF interface commands\n"
8486 "Network type\n"
8487 "Specify OSPF broadcast multi-access network\n"
8488 "Specify OSPF NBMA network\n"
8489 "Specify OSPF point-to-multipoint network\n"
8490 "Specify OSPF point-to-point network\n")
8491 {
8492 return ip_ospf_network(self, vty, argc, argv);
8493 }
8494
8495 DEFUN (no_ip_ospf_network,
8496 no_ip_ospf_network_cmd,
8497 "no ip ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]",
8498 NO_STR
8499 "IP Information\n"
8500 "OSPF interface commands\n"
8501 "Network type\n"
8502 "Specify OSPF broadcast multi-access network\n"
8503 "Specify OSPF NBMA network\n"
8504 "Specify OSPF point-to-multipoint network\n"
8505 "Specify OSPF point-to-point network\n")
8506 {
8507 VTY_DECLVAR_CONTEXT(interface, ifp);
8508 int old_type = IF_DEF_PARAMS(ifp)->type;
8509 struct route_node *rn;
8510
8511 IF_DEF_PARAMS(ifp)->type = ospf_default_iftype(ifp);
8512 IF_DEF_PARAMS(ifp)->ptp_dmvpn = 0;
8513
8514 if (IF_DEF_PARAMS(ifp)->type == old_type)
8515 return CMD_SUCCESS;
8516
8517 for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) {
8518 struct ospf_interface *oi = rn->info;
8519
8520 if (!oi)
8521 continue;
8522
8523 oi->type = IF_DEF_PARAMS(ifp)->type;
8524
8525 if (oi->state > ISM_Down) {
8526 OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceDown);
8527 OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceUp);
8528 }
8529 }
8530
8531 return CMD_SUCCESS;
8532 }
8533
8534 DEFUN_HIDDEN (no_ospf_network,
8535 no_ospf_network_cmd,
8536 "no ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]",
8537 NO_STR
8538 "OSPF interface commands\n"
8539 "Network type\n"
8540 "Specify OSPF broadcast multi-access network\n"
8541 "Specify OSPF NBMA network\n"
8542 "Specify OSPF point-to-multipoint network\n"
8543 "Specify OSPF point-to-point network\n")
8544 {
8545 return no_ip_ospf_network(self, vty, argc, argv);
8546 }
8547
8548 DEFUN (ip_ospf_priority,
8549 ip_ospf_priority_cmd,
8550 "ip ospf priority (0-255) [A.B.C.D]",
8551 "IP Information\n"
8552 "OSPF interface commands\n"
8553 "Router priority\n"
8554 "Priority\n"
8555 "Address of interface\n")
8556 {
8557 VTY_DECLVAR_CONTEXT(interface, ifp);
8558 int idx = 0;
8559 long priority;
8560 struct route_node *rn;
8561 struct in_addr addr;
8562 struct ospf_if_params *params;
8563 params = IF_DEF_PARAMS(ifp);
8564
8565 argv_find(argv, argc, "(0-255)", &idx);
8566 priority = strtol(argv[idx]->arg, NULL, 10);
8567
8568 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
8569 if (!inet_aton(argv[idx]->arg, &addr)) {
8570 vty_out(vty,
8571 "Please specify interface address by A.B.C.D\n");
8572 return CMD_WARNING_CONFIG_FAILED;
8573 }
8574
8575 params = ospf_get_if_params(ifp, addr);
8576 ospf_if_update_params(ifp, addr);
8577 }
8578
8579 SET_IF_PARAM(params, priority);
8580 params->priority = priority;
8581
8582 for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) {
8583 struct ospf_interface *oi = rn->info;
8584
8585 if (!oi)
8586 continue;
8587
8588 if (PRIORITY(oi) != OSPF_IF_PARAM(oi, priority)) {
8589 PRIORITY(oi) = OSPF_IF_PARAM(oi, priority);
8590 OSPF_ISM_EVENT_SCHEDULE(oi, ISM_NeighborChange);
8591 }
8592 }
8593
8594 return CMD_SUCCESS;
8595 }
8596
8597 DEFUN_HIDDEN (ospf_priority,
8598 ospf_priority_cmd,
8599 "ospf priority (0-255) [A.B.C.D]",
8600 "OSPF interface commands\n"
8601 "Router priority\n"
8602 "Priority\n"
8603 "Address of interface\n")
8604 {
8605 return ip_ospf_priority(self, vty, argc, argv);
8606 }
8607
8608 DEFUN (no_ip_ospf_priority,
8609 no_ip_ospf_priority_cmd,
8610 "no ip ospf priority [(0-255) [A.B.C.D]]",
8611 NO_STR
8612 "IP Information\n"
8613 "OSPF interface commands\n"
8614 "Router priority\n" // ignored
8615 "Priority\n"
8616 "Address of interface\n")
8617 {
8618 VTY_DECLVAR_CONTEXT(interface, ifp);
8619 int idx = 0;
8620 struct route_node *rn;
8621 struct in_addr addr;
8622 struct ospf_if_params *params;
8623
8624 params = IF_DEF_PARAMS(ifp);
8625
8626 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
8627 if (!inet_aton(argv[idx]->arg, &addr)) {
8628 vty_out(vty,
8629 "Please specify interface address by A.B.C.D\n");
8630 return CMD_WARNING_CONFIG_FAILED;
8631 }
8632
8633 params = ospf_lookup_if_params(ifp, addr);
8634 if (params == NULL)
8635 return CMD_SUCCESS;
8636 }
8637
8638 UNSET_IF_PARAM(params, priority);
8639 params->priority = OSPF_ROUTER_PRIORITY_DEFAULT;
8640
8641 if (params != IF_DEF_PARAMS(ifp)) {
8642 ospf_free_if_params(ifp, addr);
8643 ospf_if_update_params(ifp, addr);
8644 }
8645
8646 for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) {
8647 struct ospf_interface *oi = rn->info;
8648
8649 if (!oi)
8650 continue;
8651
8652 if (PRIORITY(oi) != OSPF_IF_PARAM(oi, priority)) {
8653 PRIORITY(oi) = OSPF_IF_PARAM(oi, priority);
8654 OSPF_ISM_EVENT_SCHEDULE(oi, ISM_NeighborChange);
8655 }
8656 }
8657
8658 return CMD_SUCCESS;
8659 }
8660
8661 DEFUN_HIDDEN (no_ospf_priority,
8662 no_ospf_priority_cmd,
8663 "no ospf priority [(0-255) [A.B.C.D]]",
8664 NO_STR
8665 "OSPF interface commands\n"
8666 "Router priority\n"
8667 "Priority\n"
8668 "Address of interface\n")
8669 {
8670 return no_ip_ospf_priority(self, vty, argc, argv);
8671 }
8672
8673 DEFUN (ip_ospf_retransmit_interval,
8674 ip_ospf_retransmit_interval_addr_cmd,
8675 "ip ospf retransmit-interval (1-65535) [A.B.C.D]",
8676 "IP Information\n"
8677 "OSPF interface commands\n"
8678 "Time between retransmitting lost link state advertisements\n"
8679 "Seconds\n"
8680 "Address of interface\n")
8681 {
8682 VTY_DECLVAR_CONTEXT(interface, ifp);
8683 int idx = 0;
8684 uint32_t seconds;
8685 struct in_addr addr;
8686 struct ospf_if_params *params;
8687 params = IF_DEF_PARAMS(ifp);
8688
8689 argv_find(argv, argc, "(1-65535)", &idx);
8690 seconds = strtol(argv[idx]->arg, NULL, 10);
8691
8692 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
8693 if (!inet_aton(argv[idx]->arg, &addr)) {
8694 vty_out(vty,
8695 "Please specify interface address by A.B.C.D\n");
8696 return CMD_WARNING_CONFIG_FAILED;
8697 }
8698
8699 params = ospf_get_if_params(ifp, addr);
8700 ospf_if_update_params(ifp, addr);
8701 }
8702
8703 SET_IF_PARAM(params, retransmit_interval);
8704 params->retransmit_interval = seconds;
8705
8706 return CMD_SUCCESS;
8707 }
8708
8709 DEFUN_HIDDEN (ospf_retransmit_interval,
8710 ospf_retransmit_interval_cmd,
8711 "ospf retransmit-interval (1-65535) [A.B.C.D]",
8712 "OSPF interface commands\n"
8713 "Time between retransmitting lost link state advertisements\n"
8714 "Seconds\n"
8715 "Address of interface\n")
8716 {
8717 return ip_ospf_retransmit_interval(self, vty, argc, argv);
8718 }
8719
8720 DEFUN (no_ip_ospf_retransmit_interval,
8721 no_ip_ospf_retransmit_interval_addr_cmd,
8722 "no ip ospf retransmit-interval [(1-65535)] [A.B.C.D]",
8723 NO_STR
8724 "IP Information\n"
8725 "OSPF interface commands\n"
8726 "Time between retransmitting lost link state advertisements\n"
8727 "Seconds\n"
8728 "Address of interface\n")
8729 {
8730 VTY_DECLVAR_CONTEXT(interface, ifp);
8731 int idx = 0;
8732 struct in_addr addr;
8733 struct ospf_if_params *params;
8734
8735 params = IF_DEF_PARAMS(ifp);
8736
8737 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
8738 if (!inet_aton(argv[idx]->arg, &addr)) {
8739 vty_out(vty,
8740 "Please specify interface address by A.B.C.D\n");
8741 return CMD_WARNING_CONFIG_FAILED;
8742 }
8743
8744 params = ospf_lookup_if_params(ifp, addr);
8745 if (params == NULL)
8746 return CMD_SUCCESS;
8747 }
8748
8749 UNSET_IF_PARAM(params, retransmit_interval);
8750 params->retransmit_interval = OSPF_RETRANSMIT_INTERVAL_DEFAULT;
8751
8752 if (params != IF_DEF_PARAMS(ifp)) {
8753 ospf_free_if_params(ifp, addr);
8754 ospf_if_update_params(ifp, addr);
8755 }
8756
8757 return CMD_SUCCESS;
8758 }
8759
8760 DEFUN_HIDDEN (no_ospf_retransmit_interval,
8761 no_ospf_retransmit_interval_cmd,
8762 "no ospf retransmit-interval [(1-65535)] [A.B.C.D]",
8763 NO_STR
8764 "OSPF interface commands\n"
8765 "Time between retransmitting lost link state advertisements\n"
8766 "Seconds\n"
8767 "Address of interface\n")
8768 {
8769 return no_ip_ospf_retransmit_interval(self, vty, argc, argv);
8770 }
8771
8772 DEFUN (ip_ospf_transmit_delay,
8773 ip_ospf_transmit_delay_addr_cmd,
8774 "ip ospf transmit-delay (1-65535) [A.B.C.D]",
8775 "IP Information\n"
8776 "OSPF interface commands\n"
8777 "Link state transmit delay\n"
8778 "Seconds\n"
8779 "Address of interface\n")
8780 {
8781 VTY_DECLVAR_CONTEXT(interface, ifp);
8782 int idx = 0;
8783 uint32_t seconds;
8784 struct in_addr addr;
8785 struct ospf_if_params *params;
8786
8787 params = IF_DEF_PARAMS(ifp);
8788 argv_find(argv, argc, "(1-65535)", &idx);
8789 seconds = strtol(argv[idx]->arg, NULL, 10);
8790
8791 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
8792 if (!inet_aton(argv[idx]->arg, &addr)) {
8793 vty_out(vty,
8794 "Please specify interface address by A.B.C.D\n");
8795 return CMD_WARNING_CONFIG_FAILED;
8796 }
8797
8798 params = ospf_get_if_params(ifp, addr);
8799 ospf_if_update_params(ifp, addr);
8800 }
8801
8802 SET_IF_PARAM(params, transmit_delay);
8803 params->transmit_delay = seconds;
8804
8805 return CMD_SUCCESS;
8806 }
8807
8808 DEFUN_HIDDEN (ospf_transmit_delay,
8809 ospf_transmit_delay_cmd,
8810 "ospf transmit-delay (1-65535) [A.B.C.D]",
8811 "OSPF interface commands\n"
8812 "Link state transmit delay\n"
8813 "Seconds\n"
8814 "Address of interface\n")
8815 {
8816 return ip_ospf_transmit_delay(self, vty, argc, argv);
8817 }
8818
8819 DEFUN (no_ip_ospf_transmit_delay,
8820 no_ip_ospf_transmit_delay_addr_cmd,
8821 "no ip ospf transmit-delay [(1-65535)] [A.B.C.D]",
8822 NO_STR
8823 "IP Information\n"
8824 "OSPF interface commands\n"
8825 "Link state transmit delay\n"
8826 "Seconds\n"
8827 "Address of interface\n")
8828 {
8829 VTY_DECLVAR_CONTEXT(interface, ifp);
8830 int idx = 0;
8831 struct in_addr addr;
8832 struct ospf_if_params *params;
8833
8834 params = IF_DEF_PARAMS(ifp);
8835
8836 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
8837 if (!inet_aton(argv[idx]->arg, &addr)) {
8838 vty_out(vty,
8839 "Please specify interface address by A.B.C.D\n");
8840 return CMD_WARNING_CONFIG_FAILED;
8841 }
8842
8843 params = ospf_lookup_if_params(ifp, addr);
8844 if (params == NULL)
8845 return CMD_SUCCESS;
8846 }
8847
8848 UNSET_IF_PARAM(params, transmit_delay);
8849 params->transmit_delay = OSPF_TRANSMIT_DELAY_DEFAULT;
8850
8851 if (params != IF_DEF_PARAMS(ifp)) {
8852 ospf_free_if_params(ifp, addr);
8853 ospf_if_update_params(ifp, addr);
8854 }
8855
8856 return CMD_SUCCESS;
8857 }
8858
8859
8860 DEFUN_HIDDEN (no_ospf_transmit_delay,
8861 no_ospf_transmit_delay_cmd,
8862 "no ospf transmit-delay [(1-65535) [A.B.C.D]]",
8863 NO_STR
8864 "OSPF interface commands\n"
8865 "Link state transmit delay\n"
8866 "Seconds\n"
8867 "Address of interface\n")
8868 {
8869 return no_ip_ospf_transmit_delay(self, vty, argc, argv);
8870 }
8871
8872 DEFUN (ip_ospf_area,
8873 ip_ospf_area_cmd,
8874 "ip ospf [(1-65535)] area <A.B.C.D|(0-4294967295)> [A.B.C.D]",
8875 "IP Information\n"
8876 "OSPF interface commands\n"
8877 "Instance ID\n"
8878 "Enable OSPF on this interface\n"
8879 "OSPF area ID in IP address format\n"
8880 "OSPF area ID as a decimal value\n"
8881 "Address of interface\n")
8882 {
8883 VTY_DECLVAR_CONTEXT(interface, ifp);
8884 int idx = 0;
8885 int format, ret;
8886 struct in_addr area_id;
8887 struct in_addr addr;
8888 struct ospf_if_params *params = NULL;
8889 struct route_node *rn;
8890 struct ospf *ospf = NULL;
8891 unsigned short instance = 0;
8892 char *areaid;
8893 uint32_t count = 0;
8894
8895 if (argv_find(argv, argc, "(1-65535)", &idx))
8896 instance = strtol(argv[idx]->arg, NULL, 10);
8897
8898 argv_find(argv, argc, "area", &idx);
8899 areaid = argv[idx + 1]->arg;
8900
8901 if (ifp->vrf_id && !instance)
8902 ospf = ospf_lookup_by_vrf_id(ifp->vrf_id);
8903 else
8904 ospf = ospf_lookup_instance(instance);
8905
8906 if (instance && instance != ospf_instance) {
8907 /*
8908 * At this point we know we have received
8909 * an instance and there is no ospf instance
8910 * associated with it. This means we are
8911 * in a situation where we have an
8912 * ospf command that is setup for a different
8913 * process(instance). We need to safely
8914 * remove the command from ourselves and
8915 * allow the other instance(process) handle
8916 * the configuration command.
8917 */
8918 count = 0;
8919
8920 params = IF_DEF_PARAMS(ifp);
8921 if (OSPF_IF_PARAM_CONFIGURED(params, if_area)) {
8922 UNSET_IF_PARAM(params, if_area);
8923 count++;
8924 }
8925
8926 for (rn = route_top(IF_OIFS_PARAMS(ifp)); rn; rn = route_next(rn))
8927 if ((params = rn->info) && OSPF_IF_PARAM_CONFIGURED(params, if_area)) {
8928 UNSET_IF_PARAM(params, if_area);
8929 count++;
8930 }
8931
8932 if (count > 0) {
8933 ospf = ospf_lookup_by_vrf_id(ifp->vrf_id);
8934 if (ospf)
8935 ospf_interface_area_unset(ospf, ifp);
8936 }
8937
8938 return CMD_NOT_MY_INSTANCE;
8939 }
8940
8941 ret = str2area_id(areaid, &area_id, &format);
8942 if (ret < 0) {
8943 vty_out(vty, "Please specify area by A.B.C.D|<0-4294967295>\n");
8944 return CMD_WARNING_CONFIG_FAILED;
8945 }
8946 if (memcmp(ifp->name, "VLINK", 5) == 0) {
8947 vty_out(vty, "Cannot enable OSPF on a virtual link.\n");
8948 return CMD_WARNING_CONFIG_FAILED;
8949 }
8950
8951 if (ospf) {
8952 for (rn = route_top(ospf->networks); rn; rn = route_next(rn)) {
8953 if (rn->info != NULL) {
8954 vty_out(vty,
8955 "Please remove all network commands first.\n");
8956 return CMD_WARNING_CONFIG_FAILED;
8957 }
8958 }
8959 }
8960
8961 params = IF_DEF_PARAMS(ifp);
8962 if (OSPF_IF_PARAM_CONFIGURED(params, if_area)
8963 && !IPV4_ADDR_SAME(&params->if_area, &area_id)) {
8964 vty_out(vty,
8965 "Must remove previous area config before changing ospf area \n");
8966 return CMD_WARNING_CONFIG_FAILED;
8967 }
8968
8969 // Check if we have an address arg and proccess it
8970 if (argc == idx + 3) {
8971 if (!inet_aton(argv[idx + 2]->arg, &addr)) {
8972 vty_out(vty,
8973 "Please specify Intf Address by A.B.C.D\n");
8974 return CMD_WARNING_CONFIG_FAILED;
8975 }
8976 // update/create address-level params
8977 params = ospf_get_if_params((ifp), (addr));
8978 if (OSPF_IF_PARAM_CONFIGURED(params, if_area)) {
8979 if (!IPV4_ADDR_SAME(&params->if_area, &area_id)) {
8980 vty_out(vty,
8981 "Must remove previous area/address config before changing ospf area\n");
8982 return CMD_WARNING_CONFIG_FAILED;
8983 } else
8984 return CMD_SUCCESS;
8985 }
8986 ospf_if_update_params((ifp), (addr));
8987 }
8988
8989 /* enable ospf on this interface with area_id */
8990 if (params) {
8991 SET_IF_PARAM(params, if_area);
8992 params->if_area = area_id;
8993 params->if_area_id_fmt = format;
8994 }
8995
8996 if (ospf)
8997 ospf_interface_area_set(ospf, ifp);
8998
8999 return CMD_SUCCESS;
9000 }
9001
9002 DEFUN (no_ip_ospf_area,
9003 no_ip_ospf_area_cmd,
9004 "no ip ospf [(1-65535)] area [<A.B.C.D|(0-4294967295)> [A.B.C.D]]",
9005 NO_STR
9006 "IP Information\n"
9007 "OSPF interface commands\n"
9008 "Instance ID\n"
9009 "Disable OSPF on this interface\n"
9010 "OSPF area ID in IP address format\n"
9011 "OSPF area ID as a decimal value\n"
9012 "Address of interface\n")
9013 {
9014 VTY_DECLVAR_CONTEXT(interface, ifp);
9015 int idx = 0;
9016 struct ospf *ospf;
9017 struct ospf_if_params *params;
9018 unsigned short instance = 0;
9019 struct in_addr addr;
9020 struct in_addr area_id;
9021
9022 if (argv_find(argv, argc, "(1-65535)", &idx))
9023 instance = strtol(argv[idx]->arg, NULL, 10);
9024
9025 if (ifp->vrf_id && !instance)
9026 ospf = ospf_lookup_by_vrf_id(ifp->vrf_id);
9027 else
9028 ospf = ospf_lookup_instance(instance);
9029
9030 if (instance && instance != ospf_instance)
9031 return CMD_NOT_MY_INSTANCE;
9032
9033 argv_find(argv, argc, "area", &idx);
9034
9035 // Check if we have an address arg and proccess it
9036 if (argc == idx + 3) {
9037 if (!inet_aton(argv[idx + 2]->arg, &addr)) {
9038 vty_out(vty,
9039 "Please specify Intf Address by A.B.C.D\n");
9040 return CMD_WARNING_CONFIG_FAILED;
9041 }
9042 params = ospf_lookup_if_params(ifp, addr);
9043 if ((params) == NULL)
9044 return CMD_SUCCESS;
9045 } else
9046 params = IF_DEF_PARAMS(ifp);
9047
9048 area_id = params->if_area;
9049 if (!OSPF_IF_PARAM_CONFIGURED(params, if_area)) {
9050 vty_out(vty,
9051 "Can't find specified interface area configuration.\n");
9052 return CMD_WARNING_CONFIG_FAILED;
9053 }
9054
9055 UNSET_IF_PARAM(params, if_area);
9056 if (params != IF_DEF_PARAMS((ifp))) {
9057 ospf_free_if_params((ifp), (addr));
9058 ospf_if_update_params((ifp), (addr));
9059 }
9060
9061 if (ospf) {
9062 ospf_interface_area_unset(ospf, ifp);
9063 ospf_area_check_free(ospf, area_id);
9064 }
9065
9066 return CMD_SUCCESS;
9067 }
9068
9069 DEFUN (ospf_redistribute_source,
9070 ospf_redistribute_source_cmd,
9071 "redistribute " FRR_REDIST_STR_OSPFD " [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
9072 REDIST_STR
9073 FRR_REDIST_HELP_STR_OSPFD
9074 "Metric for redistributed routes\n"
9075 "OSPF default metric\n"
9076 "OSPF exterior metric type for redistributed routes\n"
9077 "Set OSPF External Type 1/2 metrics\n"
9078 "Route map reference\n"
9079 "Pointer to route-map entries\n")
9080 {
9081 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9082 int idx_protocol = 1;
9083 int source;
9084 int type = -1;
9085 int metric = -1;
9086 struct ospf_redist *red;
9087 int idx = 0;
9088
9089 /* Get distribute source. */
9090 source = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
9091 if (source < 0)
9092 return CMD_WARNING_CONFIG_FAILED;
9093
9094 red = ospf_redist_add(ospf, source, 0);
9095
9096 /* Get metric value. */
9097 if (argv_find(argv, argc, "(0-16777214)", &idx)) {
9098 if (!str2metric(argv[idx]->arg, &metric))
9099 return CMD_WARNING_CONFIG_FAILED;
9100 }
9101 idx = 1;
9102 /* Get metric type. */
9103 if (argv_find(argv, argc, "(1-2)", &idx)) {
9104 if (!str2metric_type(argv[idx]->arg, &type))
9105 return CMD_WARNING_CONFIG_FAILED;
9106 }
9107 idx = 1;
9108 /* Get route-map */
9109 if (argv_find(argv, argc, "WORD", &idx)) {
9110 ospf_routemap_set(red, argv[idx]->arg);
9111 } else
9112 ospf_routemap_unset(red);
9113
9114 return ospf_redistribute_set(ospf, source, 0, type, metric);
9115 }
9116
9117 DEFUN (no_ospf_redistribute_source,
9118 no_ospf_redistribute_source_cmd,
9119 "no redistribute " FRR_REDIST_STR_OSPFD " [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
9120 NO_STR
9121 REDIST_STR
9122 FRR_REDIST_HELP_STR_OSPFD
9123 "Metric for redistributed routes\n"
9124 "OSPF default metric\n"
9125 "OSPF exterior metric type for redistributed routes\n"
9126 "Set OSPF External Type 1/2 metrics\n"
9127 "Route map reference\n"
9128 "Pointer to route-map entries\n")
9129 {
9130 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9131 int idx_protocol = 2;
9132 int source;
9133 struct ospf_redist *red;
9134
9135 source = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
9136 if (source < 0)
9137 return CMD_WARNING_CONFIG_FAILED;
9138
9139 red = ospf_redist_lookup(ospf, source, 0);
9140 if (!red)
9141 return CMD_SUCCESS;
9142
9143 ospf_routemap_unset(red);
9144 ospf_redist_del(ospf, source, 0);
9145
9146 return ospf_redistribute_unset(ospf, source, 0);
9147 }
9148
9149 DEFUN (ospf_redistribute_instance_source,
9150 ospf_redistribute_instance_source_cmd,
9151 "redistribute <ospf|table> (1-65535) [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
9152 REDIST_STR
9153 "Open Shortest Path First\n"
9154 "Non-main Kernel Routing Table\n"
9155 "Instance ID/Table ID\n"
9156 "Metric for redistributed routes\n"
9157 "OSPF default metric\n"
9158 "OSPF exterior metric type for redistributed routes\n"
9159 "Set OSPF External Type 1/2 metrics\n"
9160 "Route map reference\n"
9161 "Pointer to route-map entries\n")
9162 {
9163 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9164 int idx_ospf_table = 1;
9165 int idx_number = 2;
9166 int idx = 3;
9167 int source;
9168 int type = -1;
9169 int metric = -1;
9170 unsigned short instance;
9171 struct ospf_redist *red;
9172
9173 source = proto_redistnum(AFI_IP, argv[idx_ospf_table]->text);
9174
9175 if (source < 0) {
9176 vty_out(vty, "Unknown instance redistribution\n");
9177 return CMD_WARNING_CONFIG_FAILED;
9178 }
9179
9180 instance = strtoul(argv[idx_number]->arg, NULL, 10);
9181
9182 if ((source == ZEBRA_ROUTE_OSPF) && !ospf->instance) {
9183 vty_out(vty,
9184 "Instance redistribution in non-instanced OSPF not allowed\n");
9185 return CMD_WARNING_CONFIG_FAILED;
9186 }
9187
9188 if ((source == ZEBRA_ROUTE_OSPF) && (ospf->instance == instance)) {
9189 vty_out(vty, "Same instance OSPF redistribution not allowed\n");
9190 return CMD_WARNING_CONFIG_FAILED;
9191 }
9192
9193 /* Get metric value. */
9194 if (argv_find(argv, argc, "metric", &idx))
9195 if (!str2metric(argv[idx + 1]->arg, &metric))
9196 return CMD_WARNING_CONFIG_FAILED;
9197
9198 idx = 3;
9199 /* Get metric type. */
9200 if (argv_find(argv, argc, "metric-type", &idx))
9201 if (!str2metric_type(argv[idx + 1]->arg, &type))
9202 return CMD_WARNING_CONFIG_FAILED;
9203
9204 red = ospf_redist_add(ospf, source, instance);
9205
9206 idx = 3;
9207 if (argv_find(argv, argc, "route-map", &idx))
9208 ospf_routemap_set(red, argv[idx + 1]->arg);
9209 else
9210 ospf_routemap_unset(red);
9211
9212 return ospf_redistribute_set(ospf, source, instance, type, metric);
9213 }
9214
9215 DEFUN (no_ospf_redistribute_instance_source,
9216 no_ospf_redistribute_instance_source_cmd,
9217 "no redistribute <ospf|table> (1-65535) [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
9218 NO_STR
9219 REDIST_STR
9220 "Open Shortest Path First\n"
9221 "Non-main Kernel Routing Table\n"
9222 "Instance ID/Table Id\n"
9223 "Metric for redistributed routes\n"
9224 "OSPF default metric\n"
9225 "OSPF exterior metric type for redistributed routes\n"
9226 "Set OSPF External Type 1/2 metrics\n"
9227 "Route map reference\n"
9228 "Pointer to route-map entries\n")
9229 {
9230 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9231 int idx_ospf_table = 2;
9232 int idx_number = 3;
9233 unsigned int instance;
9234 struct ospf_redist *red;
9235 int source;
9236
9237 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
9238 source = ZEBRA_ROUTE_OSPF;
9239 else
9240 source = ZEBRA_ROUTE_TABLE;
9241
9242 instance = strtoul(argv[idx_number]->arg, NULL, 10);
9243
9244 if ((source == ZEBRA_ROUTE_OSPF) && !ospf->instance) {
9245 vty_out(vty,
9246 "Instance redistribution in non-instanced OSPF not allowed\n");
9247 return CMD_WARNING_CONFIG_FAILED;
9248 }
9249
9250 if ((source == ZEBRA_ROUTE_OSPF) && (ospf->instance == instance)) {
9251 vty_out(vty, "Same instance OSPF redistribution not allowed\n");
9252 return CMD_WARNING_CONFIG_FAILED;
9253 }
9254
9255 red = ospf_redist_lookup(ospf, source, instance);
9256 if (!red)
9257 return CMD_SUCCESS;
9258
9259 ospf_routemap_unset(red);
9260 ospf_redist_del(ospf, source, instance);
9261
9262 return ospf_redistribute_unset(ospf, source, instance);
9263 }
9264
9265 DEFUN (ospf_distribute_list_out,
9266 ospf_distribute_list_out_cmd,
9267 "distribute-list WORD out " FRR_REDIST_STR_OSPFD,
9268 "Filter networks in routing updates\n"
9269 "Access-list name\n"
9270 OUT_STR
9271 FRR_REDIST_HELP_STR_OSPFD)
9272 {
9273 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9274 int idx_word = 1;
9275 int source;
9276
9277 char *proto = argv[argc - 1]->text;
9278
9279 /* Get distribute source. */
9280 source = proto_redistnum(AFI_IP, proto);
9281 if (source < 0)
9282 return CMD_WARNING_CONFIG_FAILED;
9283
9284 return ospf_distribute_list_out_set(ospf, source, argv[idx_word]->arg);
9285 }
9286
9287 DEFUN (no_ospf_distribute_list_out,
9288 no_ospf_distribute_list_out_cmd,
9289 "no distribute-list WORD out " FRR_REDIST_STR_OSPFD,
9290 NO_STR
9291 "Filter networks in routing updates\n"
9292 "Access-list name\n"
9293 OUT_STR
9294 FRR_REDIST_HELP_STR_OSPFD)
9295 {
9296 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9297 int idx_word = 2;
9298 int source;
9299
9300 char *proto = argv[argc - 1]->text;
9301 source = proto_redistnum(AFI_IP, proto);
9302 if (source < 0)
9303 return CMD_WARNING_CONFIG_FAILED;
9304
9305 return ospf_distribute_list_out_unset(ospf, source,
9306 argv[idx_word]->arg);
9307 }
9308
9309 /* Default information originate. */
9310 DEFUN (ospf_default_information_originate,
9311 ospf_default_information_originate_cmd,
9312 "default-information originate [{always|metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
9313 "Control distribution of default information\n"
9314 "Distribute a default route\n"
9315 "Always advertise default route\n"
9316 "OSPF default metric\n"
9317 "OSPF metric\n"
9318 "OSPF metric type for default routes\n"
9319 "Set OSPF External Type 1/2 metrics\n"
9320 "Route map reference\n"
9321 "Pointer to route-map entries\n")
9322 {
9323 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9324 int default_originate = DEFAULT_ORIGINATE_ZEBRA;
9325 int type = -1;
9326 int metric = -1;
9327 struct ospf_redist *red;
9328 int idx = 0;
9329 int cur_originate = ospf->default_originate;
9330 int sameRtmap = 0;
9331 char *rtmap = NULL;
9332
9333 red = ospf_redist_add(ospf, DEFAULT_ROUTE, 0);
9334
9335 /* Check whether "always" was specified */
9336 if (argv_find(argv, argc, "always", &idx))
9337 default_originate = DEFAULT_ORIGINATE_ALWAYS;
9338 idx = 1;
9339 /* Get metric value */
9340 if (argv_find(argv, argc, "(0-16777214)", &idx)) {
9341 if (!str2metric(argv[idx]->arg, &metric))
9342 return CMD_WARNING_CONFIG_FAILED;
9343 }
9344 idx = 1;
9345 /* Get metric type. */
9346 if (argv_find(argv, argc, "(1-2)", &idx)) {
9347 if (!str2metric_type(argv[idx]->arg, &type))
9348 return CMD_WARNING_CONFIG_FAILED;
9349 }
9350 idx = 1;
9351 /* Get route-map */
9352 if (argv_find(argv, argc, "WORD", &idx))
9353 rtmap = argv[idx]->arg;
9354
9355 /* To check ,if user is providing same route map */
9356 if ((rtmap == ROUTEMAP_NAME(red)) ||
9357 (rtmap && ROUTEMAP_NAME(red)
9358 && (strcmp(rtmap, ROUTEMAP_NAME(red)) == 0)))
9359 sameRtmap = 1;
9360
9361 /* Don't allow if the same lsa is aleardy originated. */
9362 if ((sameRtmap)
9363 && (red->dmetric.type == type)
9364 && (red->dmetric.value == metric)
9365 && (cur_originate == default_originate))
9366 return CMD_SUCCESS;
9367
9368 /* Updating Metric details */
9369 red->dmetric.type = type;
9370 red->dmetric.value = metric;
9371
9372 /* updating route map details */
9373 if (rtmap)
9374 ospf_routemap_set(red, rtmap);
9375 else
9376 ospf_routemap_unset(red);
9377
9378 return ospf_redistribute_default_set(ospf, default_originate, type,
9379 metric);
9380 }
9381
9382 DEFUN (no_ospf_default_information_originate,
9383 no_ospf_default_information_originate_cmd,
9384 "no default-information originate [{always|metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
9385 NO_STR
9386 "Control distribution of default information\n"
9387 "Distribute a default route\n"
9388 "Always advertise default route\n"
9389 "OSPF default metric\n"
9390 "OSPF metric\n"
9391 "OSPF metric type for default routes\n"
9392 "Set OSPF External Type 1/2 metrics\n"
9393 "Route map reference\n"
9394 "Pointer to route-map entries\n")
9395 {
9396 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9397 struct ospf_redist *red;
9398
9399 red = ospf_redist_lookup(ospf, DEFAULT_ROUTE, 0);
9400 if (!red)
9401 return CMD_SUCCESS;
9402
9403 ospf_routemap_unset(red);
9404 ospf_redist_del(ospf, DEFAULT_ROUTE, 0);
9405
9406 return ospf_redistribute_default_set(ospf, DEFAULT_ORIGINATE_NONE,
9407 0, 0);
9408 }
9409
9410 DEFUN (ospf_default_metric,
9411 ospf_default_metric_cmd,
9412 "default-metric (0-16777214)",
9413 "Set metric of redistributed routes\n"
9414 "Default metric\n")
9415 {
9416 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9417 int idx_number = 1;
9418 int metric = -1;
9419
9420 if (!str2metric(argv[idx_number]->arg, &metric))
9421 return CMD_WARNING_CONFIG_FAILED;
9422
9423 ospf->default_metric = metric;
9424
9425 return CMD_SUCCESS;
9426 }
9427
9428 DEFUN (no_ospf_default_metric,
9429 no_ospf_default_metric_cmd,
9430 "no default-metric [(0-16777214)]",
9431 NO_STR
9432 "Set metric of redistributed routes\n"
9433 "Default metric\n")
9434 {
9435 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9436
9437 ospf->default_metric = -1;
9438
9439 return CMD_SUCCESS;
9440 }
9441
9442
9443 DEFUN (ospf_distance,
9444 ospf_distance_cmd,
9445 "distance (1-255)",
9446 "Administrative distance\n"
9447 "OSPF Administrative distance\n")
9448 {
9449 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9450 int idx_number = 1;
9451
9452 ospf->distance_all = atoi(argv[idx_number]->arg);
9453
9454 return CMD_SUCCESS;
9455 }
9456
9457 DEFUN (no_ospf_distance,
9458 no_ospf_distance_cmd,
9459 "no distance (1-255)",
9460 NO_STR
9461 "Administrative distance\n"
9462 "OSPF Administrative distance\n")
9463 {
9464 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9465
9466 ospf->distance_all = 0;
9467
9468 return CMD_SUCCESS;
9469 }
9470
9471 DEFUN (no_ospf_distance_ospf,
9472 no_ospf_distance_ospf_cmd,
9473 "no distance ospf [{intra-area [(1-255)]|inter-area [(1-255)]|external [(1-255)]}]",
9474 NO_STR
9475 "Administrative distance\n"
9476 "OSPF administrative distance\n"
9477 "Intra-area routes\n"
9478 "Distance for intra-area routes\n"
9479 "Inter-area routes\n"
9480 "Distance for inter-area routes\n"
9481 "External routes\n"
9482 "Distance for external routes\n")
9483 {
9484 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9485 int idx = 0;
9486
9487 if (argv_find(argv, argc, "intra-area", &idx) || argc == 3)
9488 idx = ospf->distance_intra = 0;
9489 if (argv_find(argv, argc, "inter-area", &idx) || argc == 3)
9490 idx = ospf->distance_inter = 0;
9491 if (argv_find(argv, argc, "external", &idx) || argc == 3)
9492 ospf->distance_external = 0;
9493
9494 return CMD_SUCCESS;
9495 }
9496
9497 DEFUN (ospf_distance_ospf,
9498 ospf_distance_ospf_cmd,
9499 "distance ospf {intra-area (1-255)|inter-area (1-255)|external (1-255)}",
9500 "Administrative distance\n"
9501 "OSPF administrative distance\n"
9502 "Intra-area routes\n"
9503 "Distance for intra-area routes\n"
9504 "Inter-area routes\n"
9505 "Distance for inter-area routes\n"
9506 "External routes\n"
9507 "Distance for external routes\n")
9508 {
9509 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9510 int idx = 0;
9511
9512 ospf->distance_intra = 0;
9513 ospf->distance_inter = 0;
9514 ospf->distance_external = 0;
9515
9516 if (argv_find(argv, argc, "intra-area", &idx))
9517 ospf->distance_intra = atoi(argv[idx + 1]->arg);
9518 idx = 0;
9519 if (argv_find(argv, argc, "inter-area", &idx))
9520 ospf->distance_inter = atoi(argv[idx + 1]->arg);
9521 idx = 0;
9522 if (argv_find(argv, argc, "external", &idx))
9523 ospf->distance_external = atoi(argv[idx + 1]->arg);
9524
9525 return CMD_SUCCESS;
9526 }
9527
9528 DEFUN (ip_ospf_mtu_ignore,
9529 ip_ospf_mtu_ignore_addr_cmd,
9530 "ip ospf mtu-ignore [A.B.C.D]",
9531 "IP Information\n"
9532 "OSPF interface commands\n"
9533 "Disable MTU mismatch detection on this interface\n"
9534 "Address of interface\n")
9535 {
9536 VTY_DECLVAR_CONTEXT(interface, ifp);
9537 int idx_ipv4 = 3;
9538 struct in_addr addr;
9539 int ret;
9540
9541 struct ospf_if_params *params;
9542 params = IF_DEF_PARAMS(ifp);
9543
9544 if (argc == 4) {
9545 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
9546 if (!ret) {
9547 vty_out(vty,
9548 "Please specify interface address by A.B.C.D\n");
9549 return CMD_WARNING_CONFIG_FAILED;
9550 }
9551 params = ospf_get_if_params(ifp, addr);
9552 ospf_if_update_params(ifp, addr);
9553 }
9554 params->mtu_ignore = 1;
9555 if (params->mtu_ignore != OSPF_MTU_IGNORE_DEFAULT)
9556 SET_IF_PARAM(params, mtu_ignore);
9557 else {
9558 UNSET_IF_PARAM(params, mtu_ignore);
9559 if (params != IF_DEF_PARAMS(ifp)) {
9560 ospf_free_if_params(ifp, addr);
9561 ospf_if_update_params(ifp, addr);
9562 }
9563 }
9564 return CMD_SUCCESS;
9565 }
9566
9567 DEFUN (no_ip_ospf_mtu_ignore,
9568 no_ip_ospf_mtu_ignore_addr_cmd,
9569 "no ip ospf mtu-ignore [A.B.C.D]",
9570 NO_STR
9571 "IP Information\n"
9572 "OSPF interface commands\n"
9573 "Disable MTU mismatch detection on this interface\n"
9574 "Address of interface\n")
9575 {
9576 VTY_DECLVAR_CONTEXT(interface, ifp);
9577 int idx_ipv4 = 4;
9578 struct in_addr addr;
9579 int ret;
9580
9581 struct ospf_if_params *params;
9582 params = IF_DEF_PARAMS(ifp);
9583
9584 if (argc == 5) {
9585 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
9586 if (!ret) {
9587 vty_out(vty,
9588 "Please specify interface address by A.B.C.D\n");
9589 return CMD_WARNING_CONFIG_FAILED;
9590 }
9591 params = ospf_get_if_params(ifp, addr);
9592 ospf_if_update_params(ifp, addr);
9593 }
9594 params->mtu_ignore = 0;
9595 if (params->mtu_ignore != OSPF_MTU_IGNORE_DEFAULT)
9596 SET_IF_PARAM(params, mtu_ignore);
9597 else {
9598 UNSET_IF_PARAM(params, mtu_ignore);
9599 if (params != IF_DEF_PARAMS(ifp)) {
9600 ospf_free_if_params(ifp, addr);
9601 ospf_if_update_params(ifp, addr);
9602 }
9603 }
9604 return CMD_SUCCESS;
9605 }
9606
9607
9608 DEFUN (ospf_max_metric_router_lsa_admin,
9609 ospf_max_metric_router_lsa_admin_cmd,
9610 "max-metric router-lsa administrative",
9611 "OSPF maximum / infinite-distance metric\n"
9612 "Advertise own Router-LSA with infinite distance (stub router)\n"
9613 "Administratively applied, for an indefinite period\n")
9614 {
9615 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9616 struct listnode *ln;
9617 struct ospf_area *area;
9618
9619 for (ALL_LIST_ELEMENTS_RO(ospf->areas, ln, area)) {
9620 SET_FLAG(area->stub_router_state, OSPF_AREA_ADMIN_STUB_ROUTED);
9621
9622 if (!CHECK_FLAG(area->stub_router_state,
9623 OSPF_AREA_IS_STUB_ROUTED))
9624 ospf_router_lsa_update_area(area);
9625 }
9626
9627 /* Allows for areas configured later to get the property */
9628 ospf->stub_router_admin_set = OSPF_STUB_ROUTER_ADMINISTRATIVE_SET;
9629
9630 return CMD_SUCCESS;
9631 }
9632
9633 DEFUN (no_ospf_max_metric_router_lsa_admin,
9634 no_ospf_max_metric_router_lsa_admin_cmd,
9635 "no max-metric router-lsa administrative",
9636 NO_STR
9637 "OSPF maximum / infinite-distance metric\n"
9638 "Advertise own Router-LSA with infinite distance (stub router)\n"
9639 "Administratively applied, for an indefinite period\n")
9640 {
9641 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9642 struct listnode *ln;
9643 struct ospf_area *area;
9644
9645 for (ALL_LIST_ELEMENTS_RO(ospf->areas, ln, area)) {
9646 UNSET_FLAG(area->stub_router_state,
9647 OSPF_AREA_ADMIN_STUB_ROUTED);
9648
9649 /* Don't trample on the start-up stub timer */
9650 if (CHECK_FLAG(area->stub_router_state,
9651 OSPF_AREA_IS_STUB_ROUTED)
9652 && !area->t_stub_router) {
9653 UNSET_FLAG(area->stub_router_state,
9654 OSPF_AREA_IS_STUB_ROUTED);
9655 ospf_router_lsa_update_area(area);
9656 }
9657 }
9658 ospf->stub_router_admin_set = OSPF_STUB_ROUTER_ADMINISTRATIVE_UNSET;
9659 return CMD_SUCCESS;
9660 }
9661
9662 DEFUN (ospf_max_metric_router_lsa_startup,
9663 ospf_max_metric_router_lsa_startup_cmd,
9664 "max-metric router-lsa on-startup (5-86400)",
9665 "OSPF maximum / infinite-distance metric\n"
9666 "Advertise own Router-LSA with infinite distance (stub router)\n"
9667 "Automatically advertise stub Router-LSA on startup of OSPF\n"
9668 "Time (seconds) to advertise self as stub-router\n")
9669 {
9670 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9671 int idx_number = 3;
9672 unsigned int seconds;
9673
9674 if (argc < 4) {
9675 vty_out(vty, "%% Must supply stub-router period");
9676 return CMD_WARNING_CONFIG_FAILED;
9677 }
9678
9679 seconds = strtoul(argv[idx_number]->arg, NULL, 10);
9680
9681 ospf->stub_router_startup_time = seconds;
9682
9683 return CMD_SUCCESS;
9684 }
9685
9686 DEFUN (no_ospf_max_metric_router_lsa_startup,
9687 no_ospf_max_metric_router_lsa_startup_cmd,
9688 "no max-metric router-lsa on-startup [(5-86400)]",
9689 NO_STR
9690 "OSPF maximum / infinite-distance metric\n"
9691 "Advertise own Router-LSA with infinite distance (stub router)\n"
9692 "Automatically advertise stub Router-LSA on startup of OSPF\n"
9693 "Time (seconds) to advertise self as stub-router\n")
9694 {
9695 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9696 struct listnode *ln;
9697 struct ospf_area *area;
9698
9699 ospf->stub_router_startup_time = OSPF_STUB_ROUTER_UNCONFIGURED;
9700
9701 for (ALL_LIST_ELEMENTS_RO(ospf->areas, ln, area)) {
9702 SET_FLAG(area->stub_router_state,
9703 OSPF_AREA_WAS_START_STUB_ROUTED);
9704 OSPF_TIMER_OFF(area->t_stub_router);
9705
9706 /* Don't trample on admin stub routed */
9707 if (!CHECK_FLAG(area->stub_router_state,
9708 OSPF_AREA_ADMIN_STUB_ROUTED)) {
9709 UNSET_FLAG(area->stub_router_state,
9710 OSPF_AREA_IS_STUB_ROUTED);
9711 ospf_router_lsa_update_area(area);
9712 }
9713 }
9714 return CMD_SUCCESS;
9715 }
9716
9717
9718 DEFUN (ospf_max_metric_router_lsa_shutdown,
9719 ospf_max_metric_router_lsa_shutdown_cmd,
9720 "max-metric router-lsa on-shutdown (5-100)",
9721 "OSPF maximum / infinite-distance metric\n"
9722 "Advertise own Router-LSA with infinite distance (stub router)\n"
9723 "Advertise stub-router prior to full shutdown of OSPF\n"
9724 "Time (seconds) to wait till full shutdown\n")
9725 {
9726 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9727 int idx_number = 3;
9728 unsigned int seconds;
9729
9730 if (argc < 4) {
9731 vty_out(vty, "%% Must supply stub-router shutdown period");
9732 return CMD_WARNING_CONFIG_FAILED;
9733 }
9734
9735 seconds = strtoul(argv[idx_number]->arg, NULL, 10);
9736
9737 ospf->stub_router_shutdown_time = seconds;
9738
9739 return CMD_SUCCESS;
9740 }
9741
9742 DEFUN (no_ospf_max_metric_router_lsa_shutdown,
9743 no_ospf_max_metric_router_lsa_shutdown_cmd,
9744 "no max-metric router-lsa on-shutdown [(5-100)]",
9745 NO_STR
9746 "OSPF maximum / infinite-distance metric\n"
9747 "Advertise own Router-LSA with infinite distance (stub router)\n"
9748 "Advertise stub-router prior to full shutdown of OSPF\n"
9749 "Time (seconds) to wait till full shutdown\n")
9750 {
9751 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9752
9753 ospf->stub_router_shutdown_time = OSPF_STUB_ROUTER_UNCONFIGURED;
9754
9755 return CMD_SUCCESS;
9756 }
9757
9758 DEFUN (ospf_proactive_arp,
9759 ospf_proactive_arp_cmd,
9760 "proactive-arp",
9761 "Allow sending ARP requests proactively\n")
9762 {
9763 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9764
9765 ospf->proactive_arp = true;
9766
9767 return CMD_SUCCESS;
9768 }
9769
9770 DEFUN (no_ospf_proactive_arp,
9771 no_ospf_proactive_arp_cmd,
9772 "no proactive-arp",
9773 NO_STR
9774 "Disallow sending ARP requests proactively\n")
9775 {
9776 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9777
9778 ospf->proactive_arp = false;
9779
9780 return CMD_SUCCESS;
9781 }
9782
9783 /* Graceful Restart HELPER Commands */
9784 DEFPY(ospf_gr_helper_enable, ospf_gr_helper_enable_cmd,
9785 "graceful-restart helper-only [A.B.C.D]",
9786 "OSPF Graceful Restart\n"
9787 "Enable Helper support\n"
9788 "Advertising router id\n")
9789 {
9790 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9791 struct in_addr addr;
9792 int ret;
9793
9794 if (argc == 3) {
9795 ret = inet_aton(argv[2]->arg, &addr);
9796 if (!ret) {
9797 vty_out(vty,
9798 "Please specify the valid routerid address.\n");
9799 return CMD_WARNING_CONFIG_FAILED;
9800 }
9801
9802 ospf_gr_helper_support_set_per_routerid(ospf, &addr, OSPF_GR_TRUE);
9803 return CMD_SUCCESS;
9804 }
9805
9806 ospf_gr_helper_support_set(ospf, OSPF_GR_TRUE);
9807
9808 return CMD_SUCCESS;
9809 }
9810
9811 DEFPY(no_ospf_gr_helper_enable,
9812 no_ospf_gr_helper_enable_cmd,
9813 "no graceful-restart helper-only [A.B.C.D]",
9814 NO_STR
9815 "OSPF Graceful Restart\n"
9816 "Disable Helper support\n"
9817 "Advertising router id\n")
9818 {
9819 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9820 struct in_addr addr;
9821 int ret;
9822
9823 if (argc == 4) {
9824 ret = inet_aton(argv[3]->arg, &addr);
9825 if (!ret) {
9826 vty_out(vty,
9827 "Please specify the valid routerid address.\n");
9828 return CMD_WARNING_CONFIG_FAILED;
9829 }
9830
9831 ospf_gr_helper_support_set_per_routerid(ospf, &addr,
9832 OSPF_GR_FALSE);
9833 return CMD_SUCCESS;
9834 }
9835
9836 ospf_gr_helper_support_set(ospf, OSPF_GR_FALSE);
9837 return CMD_SUCCESS;
9838 }
9839
9840 DEFPY(ospf_gr_helper_enable_lsacheck,
9841 ospf_gr_helper_enable_lsacheck_cmd,
9842 "graceful-restart helper strict-lsa-checking",
9843 "OSPF Graceful Restart\n"
9844 "OSPF GR Helper\n"
9845 "Enable strict LSA check\n")
9846 {
9847 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9848
9849 ospf_gr_helper_lsa_check_set(ospf, OSPF_GR_TRUE);
9850 return CMD_SUCCESS;
9851 }
9852
9853 DEFPY(no_ospf_gr_helper_enable_lsacheck,
9854 no_ospf_gr_helper_enable_lsacheck_cmd,
9855 "no graceful-restart helper strict-lsa-checking",
9856 NO_STR
9857 "OSPF Graceful Restart\n"
9858 "OSPF GR Helper\n"
9859 "Disable strict LSA check\n")
9860 {
9861 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9862
9863 ospf_gr_helper_lsa_check_set(ospf, OSPF_GR_FALSE);
9864 return CMD_SUCCESS;
9865 }
9866
9867 DEFPY(ospf_gr_helper_supported_grace_time,
9868 ospf_gr_helper_supported_grace_time_cmd,
9869 "graceful-restart helper supported-grace-time (10-1800)$interval",
9870 "OSPF Graceful Restart\n"
9871 "OSPF GR Helper\n"
9872 "Supported grace timer\n"
9873 "Grace interval(in seconds)\n")
9874 {
9875 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9876
9877 ospf_gr_helper_supported_gracetime_set(ospf, interval);
9878 return CMD_SUCCESS;
9879 }
9880
9881 DEFPY(no_ospf_gr_helper_supported_grace_time,
9882 no_ospf_gr_helper_supported_grace_time_cmd,
9883 "no graceful-restart helper supported-grace-time (10-1800)$interval",
9884 NO_STR
9885 "OSPF Graceful Restart\n"
9886 "OSPF GR Helper\n"
9887 "Supported grace timer\n"
9888 "Grace interval(in seconds)\n")
9889 {
9890 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9891
9892 ospf_gr_helper_supported_gracetime_set(ospf, OSPF_MAX_GRACE_INTERVAL);
9893 return CMD_SUCCESS;
9894 }
9895
9896 DEFPY(ospf_gr_helper_planned_only,
9897 ospf_gr_helper_planned_only_cmd,
9898 "graceful-restart helper planned-only",
9899 "OSPF Graceful Restart\n"
9900 "OSPF GR Helper\n"
9901 "Supported only planned restart\n")
9902 {
9903 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9904
9905 ospf_gr_helper_set_supported_planned_only_restart(ospf, OSPF_GR_TRUE);
9906
9907 return CMD_SUCCESS;
9908 }
9909
9910 /* External Route Aggregation */
9911 DEFUN (ospf_external_route_aggregation,
9912 ospf_external_route_aggregation_cmd,
9913 "summary-address A.B.C.D/M [tag (1-4294967295)]",
9914 "External summary address\n"
9915 "Summary address prefix (a.b.c.d/m) \n"
9916 "Router tag \n"
9917 "Router tag value\n")
9918 {
9919 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9920 struct prefix_ipv4 p;
9921 int idx = 1;
9922 route_tag_t tag = 0;
9923 int ret = OSPF_SUCCESS;
9924
9925 str2prefix_ipv4(argv[idx]->arg, &p);
9926
9927 if (is_prefix_default(&p)) {
9928 vty_out(vty,
9929 "Default address shouldn't be configured as summary address.\n");
9930 return CMD_SUCCESS;
9931 }
9932
9933 /* Apply mask for given prefix. */
9934 apply_mask((struct prefix *)&p);
9935
9936 if (!is_valid_summary_addr(&p)) {
9937 vty_out(vty, "Not a valid summary address.\n");
9938 return CMD_WARNING_CONFIG_FAILED;
9939 }
9940
9941 if (argc > 2)
9942 tag = strtoul(argv[idx + 2]->arg, NULL, 10);
9943
9944 ret = ospf_asbr_external_aggregator_set(ospf, &p, tag);
9945 if (ret == OSPF_INVALID)
9946 vty_out(vty, "Inavlid configuration!!\n");
9947
9948 return CMD_SUCCESS;
9949 }
9950
9951 DEFUN (no_ospf_external_route_aggregation,
9952 no_ospf_external_route_aggregation_cmd,
9953 "no summary-address A.B.C.D/M [tag (1-4294967295)]",
9954 NO_STR
9955 "External summary address\n"
9956 "Summary address prefix (a.b.c.d/m)\n"
9957 "Router tag\n"
9958 "Router tag value\n")
9959 {
9960 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9961 struct prefix_ipv4 p;
9962 int idx = 2;
9963 route_tag_t tag = 0;
9964 int ret = OSPF_SUCCESS;
9965
9966 str2prefix_ipv4(argv[idx]->arg, &p);
9967
9968 if (is_prefix_default(&p)) {
9969 vty_out(vty,
9970 "Default address shouldn't be configured as summary address.\n");
9971 return CMD_SUCCESS;
9972 }
9973
9974 /* Apply mask for given prefix. */
9975 apply_mask((struct prefix *)&p);
9976
9977 if (!is_valid_summary_addr(&p)) {
9978 vty_out(vty, "Not a valid summary address.\n");
9979 return CMD_WARNING_CONFIG_FAILED;
9980 }
9981
9982 if (argc > 3)
9983 tag = strtoul(argv[idx + 2]->arg, NULL, 10);
9984
9985 ret = ospf_asbr_external_aggregator_unset(ospf, &p, tag);
9986 if (ret == OSPF_INVALID)
9987 vty_out(vty, "Inavlid configuration!!\n");
9988
9989 return CMD_SUCCESS;
9990 }
9991
9992 DEFPY(no_ospf_gr_helper_planned_only,
9993 no_ospf_gr_helper_planned_only_cmd,
9994 "no graceful-restart helper planned-only",
9995 NO_STR
9996 "OSPF Graceful Restart\n"
9997 "OSPF GR Helper\n"
9998 "Supported only for planned restart\n")
9999 {
10000 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
10001
10002 ospf_gr_helper_set_supported_planned_only_restart(ospf, OSPF_GR_FALSE);
10003
10004 return CMD_SUCCESS;
10005 }
10006
10007 static int ospf_print_vty_helper_dis_rtr_walkcb(struct hash_bucket *bucket,
10008 void *arg)
10009 {
10010 struct advRtr *rtr = bucket->data;
10011 struct vty *vty = (struct vty *)arg;
10012 static unsigned int count;
10013
10014 vty_out(vty, "%-6pI4,", &rtr->advRtrAddr);
10015 count++;
10016
10017 if (count % 5 == 0)
10018 vty_out(vty, "\n");
10019
10020 return HASHWALK_CONTINUE;
10021 }
10022
10023 static int ospf_show_gr_helper_details(struct vty *vty, struct ospf *ospf,
10024 uint8_t use_vrf, json_object *json,
10025 bool uj, bool detail)
10026 {
10027 struct listnode *node;
10028 struct ospf_interface *oi;
10029 char buf[PREFIX_STRLEN];
10030 json_object *json_vrf = NULL;
10031
10032 if (uj) {
10033 if (use_vrf)
10034 json_vrf = json_object_new_object();
10035 else
10036 json_vrf = json;
10037 }
10038
10039 if (ospf->instance) {
10040 if (uj)
10041 json_object_int_add(json, "ospfInstance",
10042 ospf->instance);
10043 else
10044 vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
10045 }
10046
10047 ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf);
10048
10049 if (uj) {
10050 if (use_vrf) {
10051 if (ospf->vrf_id == VRF_DEFAULT)
10052 json_object_object_add(json, "default",
10053 json_vrf);
10054 else
10055 json_object_object_add(json, ospf->name,
10056 json_vrf);
10057 }
10058 } else
10059 vty_out(vty, "\n");
10060
10061 /* Show Router ID. */
10062 if (uj) {
10063 json_object_string_add(json_vrf, "routerId",
10064 inet_ntop(AF_INET, &ospf->router_id,
10065 buf, sizeof(buf)));
10066 } else {
10067 vty_out(vty, "\n OSPF Router with ID (%pI4)\n\n",
10068 &ospf->router_id);
10069 }
10070
10071 if (!uj) {
10072
10073 if (ospf->is_helper_supported)
10074 vty_out(vty,
10075 " Graceful restart helper support enabled.\n");
10076 else
10077 vty_out(vty,
10078 " Graceful restart helper support disabled.\n");
10079
10080 if (ospf->strict_lsa_check)
10081 vty_out(vty, " Strict LSA check is enabled.\n");
10082 else
10083 vty_out(vty, " Strict LSA check is disabled.\n");
10084
10085 if (ospf->only_planned_restart)
10086 vty_out(vty,
10087 " Helper supported for planned restarts only.\n");
10088 else
10089 vty_out(vty,
10090 " Helper supported for Planned and Unplanned Restarts.\n");
10091
10092 vty_out(vty,
10093 " Supported Graceful restart interval: %d(in seconds).\n",
10094 ospf->supported_grace_time);
10095
10096 if (OSPF_HELPER_ENABLE_RTR_COUNT(ospf)) {
10097 vty_out(vty, " Enable Router list:\n");
10098 vty_out(vty, " ");
10099 hash_walk(ospf->enable_rtr_list,
10100 ospf_print_vty_helper_dis_rtr_walkcb, vty);
10101 vty_out(vty, "\n\n");
10102 }
10103
10104 if (ospf->last_exit_reason != OSPF_GR_HELPER_EXIT_NONE) {
10105 vty_out(vty, " Last Helper exit Reason :%s\n",
10106 ospf_exit_reason2str(ospf->last_exit_reason));
10107 }
10108
10109 if (ospf->active_restarter_cnt)
10110 vty_out(vty,
10111 " Number of Active neighbours in graceful restart: %d\n",
10112 ospf->active_restarter_cnt);
10113 else
10114 vty_out(vty, "\n");
10115
10116 } else {
10117 json_object_string_add(
10118 json_vrf, "helperSupport",
10119 (ospf->is_helper_supported) ? "Enabled" : "Disabled");
10120 json_object_string_add(json_vrf, "strictLsaCheck",
10121 (ospf->strict_lsa_check) ? "Enabled"
10122 : "Disabled");
10123 json_object_string_add(
10124 json_vrf, "restartSupoort",
10125 (ospf->only_planned_restart)
10126 ? "Planned Restart only"
10127 : "Planned and Unplanned Restarts");
10128
10129 json_object_int_add(json_vrf, "supportedGracePeriod",
10130 ospf->supported_grace_time);
10131
10132 if (ospf->last_exit_reason != OSPF_GR_HELPER_EXIT_NONE)
10133 json_object_string_add(
10134 json_vrf, "LastExitReason",
10135 ospf_exit_reason2str(ospf->last_exit_reason));
10136
10137 if (ospf->active_restarter_cnt)
10138 json_object_int_add(json_vrf, "activeRestarterCnt",
10139 ospf->active_restarter_cnt);
10140 }
10141
10142
10143 if (detail) {
10144 int cnt = 1;
10145 json_object *json_neighbors = NULL;
10146
10147 for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) {
10148 struct route_node *rn;
10149 struct ospf_neighbor *nbr;
10150 json_object *json_neigh;
10151
10152 if (ospf_interface_neighbor_count(oi) == 0)
10153 continue;
10154
10155 if (uj) {
10156 json_object_object_get_ex(json_vrf, "Neighbors",
10157 &json_neighbors);
10158 if (!json_neighbors) {
10159 json_neighbors =
10160 json_object_new_object();
10161 json_object_object_add(json_vrf,
10162 "Neighbors",
10163 json_neighbors);
10164 }
10165 }
10166
10167 for (rn = route_top(oi->nbrs); rn;
10168 rn = route_next(rn)) {
10169
10170 if (!rn->info)
10171 continue;
10172
10173 nbr = rn->info;
10174
10175 if (!OSPF_GR_IS_ACTIVE_HELPER(nbr))
10176 continue;
10177
10178 if (!uj) {
10179 vty_out(vty, " Neighbour %d :\n", cnt);
10180 vty_out(vty, " Address : %pI4\n",
10181 &nbr->address.u.prefix4);
10182 vty_out(vty, " Routerid : %pI4\n",
10183 &nbr->router_id);
10184 vty_out(vty,
10185 " Received Grace period : %d(in seconds).\n",
10186 nbr->gr_helper_info
10187 .recvd_grace_period);
10188 vty_out(vty,
10189 " Actual Grace period : %d(in seconds)\n",
10190 nbr->gr_helper_info
10191 .actual_grace_period);
10192 vty_out(vty,
10193 " Remaining GraceTime:%ld(in seconds).\n",
10194 thread_timer_remain_second(
10195 nbr->gr_helper_info
10196 .t_grace_timer));
10197 vty_out(vty,
10198 " Graceful Restart reason: %s.\n\n",
10199 ospf_restart_reason2str(
10200 nbr->gr_helper_info
10201 .gr_restart_reason));
10202 cnt++;
10203 } else {
10204 json_neigh = json_object_new_object();
10205 json_object_string_add(
10206 json_neigh, "srcAddr",
10207 inet_ntop(AF_INET, &nbr->src,
10208 buf, sizeof(buf)));
10209
10210 json_object_string_add(
10211 json_neigh, "routerid",
10212 inet_ntop(AF_INET,
10213 &nbr->router_id,
10214 buf, sizeof(buf)));
10215 json_object_int_add(
10216 json_neigh,
10217 "recvdGraceInterval",
10218 nbr->gr_helper_info
10219 .recvd_grace_period);
10220 json_object_int_add(
10221 json_neigh,
10222 "actualGraceInterval",
10223 nbr->gr_helper_info
10224 .actual_grace_period);
10225 json_object_int_add(
10226 json_neigh, "remainGracetime",
10227 thread_timer_remain_second(
10228 nbr->gr_helper_info
10229 .t_grace_timer));
10230 json_object_string_add(
10231 json_neigh, "restartReason",
10232 ospf_restart_reason2str(
10233 nbr->gr_helper_info
10234 .gr_restart_reason));
10235 json_object_object_add(
10236 json_neighbors,
10237 inet_ntop(AF_INET, &nbr->src,
10238 buf, sizeof(buf)),
10239 json_neigh);
10240 }
10241 }
10242 }
10243 }
10244 return CMD_SUCCESS;
10245 }
10246
10247 DEFUN (ospf_external_route_aggregation_no_adrvertise,
10248 ospf_external_route_aggregation_no_adrvertise_cmd,
10249 "summary-address A.B.C.D/M no-advertise",
10250 "External summary address\n"
10251 "Summary address prefix (a.b.c.d/m) \n"
10252 "Don't advertise summary route \n")
10253 {
10254 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
10255 struct prefix_ipv4 p;
10256 int idx = 1;
10257 int ret = OSPF_SUCCESS;
10258
10259 str2prefix_ipv4(argv[idx]->arg, &p);
10260
10261 if (is_prefix_default(&p)) {
10262 vty_out(vty,
10263 "Default address shouldn't be configured as summary address.\n");
10264 return CMD_SUCCESS;
10265 }
10266
10267 /* Apply mask for given prefix. */
10268 apply_mask((struct prefix *)&p);
10269
10270 if (!is_valid_summary_addr(&p)) {
10271 vty_out(vty, "Not a valid summary address.\n");
10272 return CMD_WARNING_CONFIG_FAILED;
10273 }
10274
10275 ret = ospf_asbr_external_rt_no_advertise(ospf, &p);
10276 if (ret == OSPF_INVALID)
10277 vty_out(vty, "Inavlid configuration!!\n");
10278
10279 return CMD_SUCCESS;
10280 }
10281
10282 DEFUN (no_ospf_external_route_aggregation_no_adrvertise,
10283 no_ospf_external_route_aggregation_no_adrvertise_cmd,
10284 "no summary-address A.B.C.D/M no-advertise",
10285 NO_STR
10286 "External summary address\n"
10287 "Summary address prefix (a.b.c.d/m)\n"
10288 "Advertise summary route to the AS \n")
10289 {
10290 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
10291 struct prefix_ipv4 p;
10292 int idx = 2;
10293 int ret = OSPF_SUCCESS;
10294
10295 str2prefix_ipv4(argv[idx]->arg, &p);
10296
10297 if (is_prefix_default(&p)) {
10298 vty_out(vty,
10299 "Default address shouldn't be configured as summary address.\n");
10300 return CMD_SUCCESS;
10301 }
10302
10303 /* Apply mask for given prefix. */
10304 apply_mask((struct prefix *)&p);
10305
10306 if (!is_valid_summary_addr(&p)) {
10307 vty_out(vty, "Not a valid summary address.\n");
10308 return CMD_WARNING_CONFIG_FAILED;
10309 }
10310
10311 ret = ospf_asbr_external_rt_advertise(ospf, &p);
10312 if (ret == OSPF_INVALID)
10313 vty_out(vty, "Inavlid configuration!!\n");
10314
10315 return CMD_SUCCESS;
10316 }
10317
10318 DEFUN (ospf_route_aggregation_timer,
10319 ospf_route_aggregation_timer_cmd,
10320 "aggregation timer (5-1800)",
10321 "External route aggregation\n"
10322 "Delay timer (in seconds)\n"
10323 "Timer interval(in seconds)\n")
10324 {
10325 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
10326 unsigned int interval = 0;
10327
10328 interval = strtoul(argv[2]->arg, NULL, 10);
10329
10330 ospf_external_aggregator_timer_set(ospf, interval);
10331
10332 return CMD_SUCCESS;
10333 }
10334
10335 DEFPY (show_ip_ospf_gr_helper,
10336 show_ip_ospf_gr_helper_cmd,
10337 "show ip ospf [vrf <NAME|all>] graceful-restart helper [detail] [json]",
10338 SHOW_STR
10339 IP_STR
10340 "OSPF information\n"
10341 VRF_CMD_HELP_STR
10342 "All VRFs\n"
10343 "OSPF Graceful Restart\n"
10344 "Helper details in the router\n"
10345 "Detailed informtion\n"
10346 JSON_STR)
10347 {
10348 char *vrf_name = NULL;
10349 bool all_vrf = false;
10350 int ret = CMD_SUCCESS;
10351 int idx_vrf = 0;
10352 int idx = 0;
10353 uint8_t use_vrf = 0;
10354 bool uj = use_json(argc, argv);
10355 struct ospf *ospf = NULL;
10356 json_object *json = NULL;
10357 struct listnode *node = NULL;
10358 int inst = 0;
10359 bool detail = false;
10360
10361 OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
10362
10363 if (argv_find(argv, argc, "detail", &idx))
10364 detail = true;
10365
10366 if (uj)
10367 json = json_object_new_object();
10368
10369 /* vrf input is provided */
10370 if (vrf_name) {
10371 use_vrf = 1;
10372
10373 if (all_vrf) {
10374 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
10375 if (!ospf->oi_running)
10376 continue;
10377
10378 ret = ospf_show_gr_helper_details(
10379 vty, ospf, use_vrf, json, uj, detail);
10380 }
10381
10382 if (uj) {
10383 vty_out(vty, "%s\n",
10384 json_object_to_json_string_ext(
10385 json, JSON_C_TO_STRING_PRETTY));
10386 json_object_free(json);
10387 }
10388
10389 return ret;
10390 }
10391
10392 ospf = ospf_lookup_by_inst_name(inst, vrf_name);
10393
10394 if (ospf == NULL || !ospf->oi_running) {
10395
10396 if (uj) {
10397 vty_out(vty, "%s\n",
10398 json_object_to_json_string_ext(
10399 json, JSON_C_TO_STRING_PRETTY));
10400 json_object_free(json);
10401 } else
10402 vty_out(vty, "%% OSPF instance not found\n");
10403
10404 return CMD_SUCCESS;
10405 }
10406
10407 } else {
10408 /* Default Vrf */
10409 ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
10410
10411 if (ospf == NULL || !ospf->oi_running) {
10412
10413 if (uj) {
10414 vty_out(vty, "%s\n",
10415 json_object_to_json_string_ext(
10416 json, JSON_C_TO_STRING_PRETTY));
10417 json_object_free(json);
10418 } else
10419 vty_out(vty, "%% OSPF instance not found\n");
10420
10421 return CMD_SUCCESS;
10422 }
10423
10424 ospf_show_gr_helper_details(vty, ospf, use_vrf, json, uj,
10425 detail);
10426 }
10427
10428 if (uj) {
10429 vty_out(vty, "%s\n", json_object_to_json_string_ext(
10430 json, JSON_C_TO_STRING_PRETTY));
10431 json_object_free(json);
10432 }
10433
10434 return CMD_SUCCESS;
10435 }
10436 /* Graceful Restart HELPER commands end */
10437 DEFUN (no_ospf_route_aggregation_timer,
10438 no_ospf_route_aggregation_timer_cmd,
10439 "no aggregation timer",
10440 NO_STR
10441 "External route aggregation\n"
10442 "Delay timer\n")
10443 {
10444 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
10445
10446 ospf_external_aggregator_timer_set(ospf, OSPF_EXTL_AGGR_DEFAULT_DELAY);
10447
10448 return CMD_SUCCESS;
10449 }
10450
10451 /* External Route Aggregation End */
10452
10453 static void config_write_stub_router(struct vty *vty, struct ospf *ospf)
10454 {
10455 struct listnode *ln;
10456 struct ospf_area *area;
10457
10458 if (ospf->stub_router_startup_time != OSPF_STUB_ROUTER_UNCONFIGURED)
10459 vty_out(vty, " max-metric router-lsa on-startup %u\n",
10460 ospf->stub_router_startup_time);
10461 if (ospf->stub_router_shutdown_time != OSPF_STUB_ROUTER_UNCONFIGURED)
10462 vty_out(vty, " max-metric router-lsa on-shutdown %u\n",
10463 ospf->stub_router_shutdown_time);
10464 for (ALL_LIST_ELEMENTS_RO(ospf->areas, ln, area)) {
10465 if (CHECK_FLAG(area->stub_router_state,
10466 OSPF_AREA_ADMIN_STUB_ROUTED)) {
10467 vty_out(vty, " max-metric router-lsa administrative\n");
10468 break;
10469 }
10470 }
10471 return;
10472 }
10473
10474 static void show_ip_ospf_route_network(struct vty *vty, struct ospf *ospf,
10475 struct route_table *rt,
10476 json_object *json)
10477 {
10478 struct route_node *rn;
10479 struct ospf_route * or ;
10480 struct listnode *pnode, *pnnode;
10481 struct ospf_path *path;
10482 char buf[PREFIX_STRLEN];
10483 json_object *json_route = NULL, *json_nexthop_array = NULL,
10484 *json_nexthop = NULL;
10485
10486 if (!json)
10487 vty_out(vty,
10488 "============ OSPF network routing table ============\n");
10489
10490 for (rn = route_top(rt); rn; rn = route_next(rn)) {
10491 char buf1[PREFIX2STR_BUFFER];
10492
10493 if ((or = rn->info) == NULL)
10494 continue;
10495
10496 prefix2str(&rn->p, buf1, sizeof(buf1));
10497
10498 json_route = json_object_new_object();
10499 if (json) {
10500 json_object_object_add(json, buf1, json_route);
10501 json_object_to_json_string_ext(
10502 json, JSON_C_TO_STRING_NOSLASHESCAPE);
10503 }
10504
10505 switch (or->path_type) {
10506 case OSPF_PATH_INTER_AREA:
10507 if (or->type == OSPF_DESTINATION_NETWORK) {
10508 if (json) {
10509 json_object_string_add(json_route,
10510 "routeType",
10511 "N IA");
10512 json_object_int_add(json_route, "cost",
10513 or->cost);
10514 json_object_string_add(
10515 json_route, "area",
10516 inet_ntop(AF_INET,
10517 &or->u.std.area_id,
10518 buf1, sizeof(buf1)));
10519 } else {
10520 vty_out(vty,
10521 "N IA %-18s [%d] area: %pI4\n",
10522 buf1, or->cost,
10523 &or->u.std.area_id);
10524 }
10525 } else if (or->type == OSPF_DESTINATION_DISCARD) {
10526 if (json) {
10527 json_object_string_add(json_route,
10528 "routeType",
10529 "D IA");
10530 } else {
10531 vty_out(vty,
10532 "D IA %-18s Discard entry\n",
10533 buf1);
10534 }
10535 }
10536 break;
10537 case OSPF_PATH_INTRA_AREA:
10538 if (json) {
10539 json_object_string_add(json_route, "routeType",
10540 "N");
10541 json_object_int_add(json_route, "cost",
10542 or->cost);
10543 json_object_string_add(
10544 json_route, "area",
10545 inet_ntop(AF_INET, &or->u.std.area_id,
10546 buf1, sizeof(buf1)));
10547 } else {
10548 vty_out(vty, "N %-18s [%d] area: %pI4\n",
10549 buf1, or->cost,
10550 &or->u.std.area_id);
10551 }
10552 break;
10553 default:
10554 break;
10555 }
10556
10557 if (or->type == OSPF_DESTINATION_NETWORK) {
10558 if (json) {
10559 json_nexthop_array = json_object_new_array();
10560 json_object_object_add(json_route, "nexthops",
10561 json_nexthop_array);
10562 }
10563
10564 for (ALL_LIST_ELEMENTS(or->paths, pnode, pnnode,
10565 path)) {
10566 if (json) {
10567 json_nexthop = json_object_new_object();
10568 json_object_array_add(
10569 json_nexthop_array,
10570 json_nexthop);
10571 }
10572 if (if_lookup_by_index(path->ifindex,
10573 ospf->vrf_id)) {
10574
10575 if (path->nexthop.s_addr
10576 == INADDR_ANY) {
10577 if (json) {
10578 json_object_string_add(
10579 json_nexthop,
10580 "ip", " ");
10581 json_object_string_add(
10582 json_nexthop,
10583 "directly attached to",
10584 ifindex2ifname(
10585 path->ifindex,
10586 ospf->vrf_id));
10587 } else {
10588 vty_out(vty,
10589 "%24s directly attached to %s\n",
10590 "",
10591 ifindex2ifname(
10592 path->ifindex,
10593 ospf->vrf_id));
10594 }
10595 } else {
10596 if (json) {
10597 json_object_string_add(
10598 json_nexthop,
10599 "ip",
10600 inet_ntop(
10601 AF_INET,
10602 &path->nexthop,
10603 buf,
10604 sizeof(buf)));
10605 json_object_string_add(
10606 json_nexthop,
10607 "via",
10608 ifindex2ifname(
10609 path->ifindex,
10610 ospf->vrf_id));
10611 } else {
10612 vty_out(vty,
10613 "%24s via %pI4, %s\n",
10614 "",
10615 &path->nexthop,
10616 ifindex2ifname(
10617 path->ifindex,
10618 ospf->vrf_id));
10619 }
10620 }
10621 }
10622 }
10623 }
10624 if (!json)
10625 json_object_free(json_route);
10626 }
10627 if (!json)
10628 vty_out(vty, "\n");
10629 }
10630
10631 static void show_ip_ospf_route_router(struct vty *vty, struct ospf *ospf,
10632 struct route_table *rtrs,
10633 json_object *json)
10634 {
10635 struct route_node *rn;
10636 struct ospf_route * or ;
10637 struct listnode *pnode;
10638 struct listnode *node;
10639 struct ospf_path *path;
10640 char buf[PREFIX_STRLEN];
10641 json_object *json_route = NULL, *json_nexthop_array = NULL,
10642 *json_nexthop = NULL;
10643
10644 if (!json)
10645 vty_out(vty,
10646 "============ OSPF router routing table =============\n");
10647
10648 for (rn = route_top(rtrs); rn; rn = route_next(rn)) {
10649 if (rn->info == NULL)
10650 continue;
10651 int flag = 0;
10652
10653 json_route = json_object_new_object();
10654 if (json) {
10655 json_object_object_add(
10656 json, inet_ntop(AF_INET, &rn->p.u.prefix4,
10657 buf, sizeof(buf)),
10658 json_route);
10659 json_object_string_add(json_route, "routeType", "R ");
10660 } else {
10661 vty_out(vty, "R %-15pI4 ",
10662 &rn->p.u.prefix4);
10663 }
10664
10665 for (ALL_LIST_ELEMENTS_RO((struct list *)rn->info, node, or)) {
10666 if (flag++) {
10667 if (!json)
10668 vty_out(vty, "%24s", "");
10669 }
10670
10671 /* Show path. */
10672 if (json) {
10673 json_object_int_add(json_route, "cost",
10674 or->cost);
10675 json_object_string_add(
10676 json_route, "area",
10677 inet_ntop(AF_INET, &or->u.std.area_id,
10678 buf, sizeof(buf)));
10679 if (or->path_type == OSPF_PATH_INTER_AREA)
10680 json_object_boolean_true_add(json_route,
10681 "IA");
10682 if (or->u.std.flags & ROUTER_LSA_BORDER)
10683 json_object_string_add(json_route,
10684 "routerType",
10685 "abr");
10686 else if (or->u.std.flags & ROUTER_LSA_EXTERNAL)
10687 json_object_string_add(json_route,
10688 "routerType",
10689 "asbr");
10690 } else {
10691 vty_out(vty, "%s [%d] area: %pI4",
10692 (or->path_type == OSPF_PATH_INTER_AREA
10693 ? "IA"
10694 : " "),
10695 or->cost, &or->u.std.area_id);
10696 /* Show flags. */
10697 vty_out(vty, "%s%s\n",
10698 (or->u.std.flags & ROUTER_LSA_BORDER
10699 ? ", ABR"
10700 : ""),
10701 (or->u.std.flags & ROUTER_LSA_EXTERNAL
10702 ? ", ASBR"
10703 : ""));
10704 }
10705
10706 if (json) {
10707 json_nexthop_array = json_object_new_array();
10708 json_object_object_add(json_route, "nexthops",
10709 json_nexthop_array);
10710 }
10711
10712 for (ALL_LIST_ELEMENTS_RO(or->paths, pnode, path)) {
10713 if (json) {
10714 json_nexthop = json_object_new_object();
10715 json_object_array_add(
10716 json_nexthop_array,
10717 json_nexthop);
10718 }
10719 if (if_lookup_by_index(path->ifindex,
10720 ospf->vrf_id)) {
10721 if (path->nexthop.s_addr
10722 == INADDR_ANY) {
10723 if (json) {
10724 json_object_string_add(
10725 json_nexthop,
10726 "ip", " ");
10727 json_object_string_add(
10728 json_nexthop,
10729 "directly attached to",
10730 ifindex2ifname(
10731 path->ifindex,
10732 ospf->vrf_id));
10733 } else {
10734 vty_out(vty,
10735 "%24s directly attached to %s\n",
10736 "",
10737 ifindex2ifname(
10738 path->ifindex,
10739 ospf->vrf_id));
10740 }
10741 } else {
10742 if (json) {
10743 json_object_string_add(
10744 json_nexthop,
10745 "ip",
10746 inet_ntop(
10747 AF_INET,
10748 &path->nexthop,
10749 buf, sizeof(buf)));
10750 json_object_string_add(
10751 json_nexthop,
10752 "via",
10753 ifindex2ifname(
10754 path->ifindex,
10755 ospf->vrf_id));
10756 } else {
10757 vty_out(vty,
10758 "%24s via %pI4, %s\n",
10759 "",
10760 &path->nexthop,
10761 ifindex2ifname(
10762 path->ifindex,
10763 ospf->vrf_id));
10764 }
10765 }
10766 }
10767 }
10768 }
10769 if (!json)
10770 json_object_free(json_route);
10771 }
10772 if (!json)
10773 vty_out(vty, "\n");
10774 }
10775
10776 static void show_ip_ospf_route_external(struct vty *vty, struct ospf *ospf,
10777 struct route_table *rt,
10778 json_object *json)
10779 {
10780 struct route_node *rn;
10781 struct ospf_route *er;
10782 struct listnode *pnode, *pnnode;
10783 struct ospf_path *path;
10784 char buf[PREFIX_STRLEN];
10785 json_object *json_route = NULL, *json_nexthop_array = NULL,
10786 *json_nexthop = NULL;
10787
10788 if (!json)
10789 vty_out(vty,
10790 "============ OSPF external routing table ===========\n");
10791
10792 for (rn = route_top(rt); rn; rn = route_next(rn)) {
10793 if ((er = rn->info) == NULL)
10794 continue;
10795
10796 char buf1[19];
10797
10798 snprintfrr(buf1, sizeof(buf1), "%pFX", &rn->p);
10799 json_route = json_object_new_object();
10800 if (json) {
10801 json_object_object_add(json, buf1, json_route);
10802 json_object_to_json_string_ext(
10803 json, JSON_C_TO_STRING_NOSLASHESCAPE);
10804 }
10805
10806 switch (er->path_type) {
10807 case OSPF_PATH_TYPE1_EXTERNAL:
10808 if (json) {
10809 json_object_string_add(json_route, "routeType",
10810 "N E1");
10811 json_object_int_add(json_route, "cost",
10812 er->cost);
10813 } else {
10814 vty_out(vty,
10815 "N E1 %-18s [%d] tag: %" ROUTE_TAG_PRI
10816 "\n",
10817 buf1, er->cost, er->u.ext.tag);
10818 }
10819 break;
10820 case OSPF_PATH_TYPE2_EXTERNAL:
10821 if (json) {
10822 json_object_string_add(json_route, "routeType",
10823 "N E2");
10824 json_object_int_add(json_route, "cost",
10825 er->cost);
10826 } else {
10827 vty_out(vty,
10828 "N E2 %-18s [%d/%d] tag: %" ROUTE_TAG_PRI
10829 "\n",
10830 buf1, er->cost, er->u.ext.type2_cost,
10831 er->u.ext.tag);
10832 }
10833 break;
10834 }
10835
10836 if (json) {
10837 json_nexthop_array = json_object_new_array();
10838 json_object_object_add(json_route, "nexthops",
10839 json_nexthop_array);
10840 }
10841
10842 for (ALL_LIST_ELEMENTS(er->paths, pnode, pnnode, path)) {
10843 if (json) {
10844 json_nexthop = json_object_new_object();
10845 json_object_array_add(json_nexthop_array,
10846 json_nexthop);
10847 }
10848
10849 if (if_lookup_by_index(path->ifindex, ospf->vrf_id)) {
10850 if (path->nexthop.s_addr == INADDR_ANY) {
10851 if (json) {
10852 json_object_string_add(
10853 json_nexthop, "ip",
10854 " ");
10855 json_object_string_add(
10856 json_nexthop,
10857 "directly attached to",
10858 ifindex2ifname(
10859 path->ifindex,
10860 ospf->vrf_id));
10861 } else {
10862 vty_out(vty,
10863 "%24s directly attached to %s\n",
10864 "",
10865 ifindex2ifname(
10866 path->ifindex,
10867 ospf->vrf_id));
10868 }
10869 } else {
10870 if (json) {
10871 json_object_string_add(
10872 json_nexthop, "ip",
10873 inet_ntop(
10874 AF_INET,
10875 &path->nexthop,
10876 buf,
10877 sizeof(buf)));
10878 json_object_string_add(
10879 json_nexthop, "via",
10880 ifindex2ifname(
10881 path->ifindex,
10882 ospf->vrf_id));
10883 } else {
10884 vty_out(vty,
10885 "%24s via %pI4, %s\n",
10886 "",
10887 &path->nexthop,
10888 ifindex2ifname(
10889 path->ifindex,
10890 ospf->vrf_id));
10891 }
10892 }
10893 }
10894 }
10895 if (!json)
10896 json_object_free(json_route);
10897 }
10898 if (!json)
10899 vty_out(vty, "\n");
10900 }
10901
10902 static int show_ip_ospf_border_routers_common(struct vty *vty,
10903 struct ospf *ospf,
10904 uint8_t use_vrf)
10905 {
10906 if (ospf->instance)
10907 vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
10908
10909 ospf_show_vrf_name(ospf, vty, NULL, use_vrf);
10910
10911 if (ospf->new_table == NULL) {
10912 vty_out(vty, "No OSPF routing information exist\n");
10913 return CMD_SUCCESS;
10914 }
10915
10916 /* Show Network routes.
10917 show_ip_ospf_route_network (vty, ospf->new_table); */
10918
10919 /* Show Router routes. */
10920 show_ip_ospf_route_router(vty, ospf, ospf->new_rtrs, NULL);
10921
10922 vty_out(vty, "\n");
10923
10924 return CMD_SUCCESS;
10925 }
10926
10927 DEFUN (show_ip_ospf_border_routers,
10928 show_ip_ospf_border_routers_cmd,
10929 "show ip ospf [vrf <NAME|all>] border-routers",
10930 SHOW_STR
10931 IP_STR
10932 "OSPF information\n"
10933 VRF_CMD_HELP_STR
10934 "All VRFs\n"
10935 "Show all the ABR's and ASBR's\n")
10936 {
10937 struct ospf *ospf = NULL;
10938 struct listnode *node = NULL;
10939 char *vrf_name = NULL;
10940 bool all_vrf = false;
10941 int ret = CMD_SUCCESS;
10942 int inst = 0;
10943 int idx_vrf = 0;
10944 uint8_t use_vrf = 0;
10945
10946 OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
10947
10948 if (vrf_name) {
10949 bool ospf_output = false;
10950
10951 use_vrf = 1;
10952
10953 if (all_vrf) {
10954 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
10955 if (!ospf->oi_running)
10956 continue;
10957
10958 ospf_output = true;
10959 ret = show_ip_ospf_border_routers_common(
10960 vty, ospf, use_vrf);
10961 }
10962
10963 if (!ospf_output)
10964 vty_out(vty, "%% OSPF instance not found\n");
10965 } else {
10966 ospf = ospf_lookup_by_inst_name(inst, vrf_name);
10967 if (ospf == NULL || !ospf->oi_running) {
10968 vty_out(vty, "%% OSPF instance not found\n");
10969 return CMD_SUCCESS;
10970 }
10971
10972 ret = show_ip_ospf_border_routers_common(vty, ospf,
10973 use_vrf);
10974 }
10975 } else {
10976 /* Display default ospf (instance 0) info */
10977 ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
10978 if (ospf == NULL || !ospf->oi_running) {
10979 vty_out(vty, "%% OSPF instance not found\n");
10980 return CMD_SUCCESS;
10981 }
10982
10983 ret = show_ip_ospf_border_routers_common(vty, ospf, use_vrf);
10984 }
10985
10986 return ret;
10987 }
10988
10989 DEFUN (show_ip_ospf_instance_border_routers,
10990 show_ip_ospf_instance_border_routers_cmd,
10991 "show ip ospf (1-65535) border-routers",
10992 SHOW_STR
10993 IP_STR
10994 "OSPF information\n"
10995 "Instance ID\n"
10996 "Show all the ABR's and ASBR's\n")
10997 {
10998 int idx_number = 3;
10999 struct ospf *ospf;
11000 unsigned short instance = 0;
11001
11002 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11003 if (instance != ospf_instance)
11004 return CMD_NOT_MY_INSTANCE;
11005
11006 ospf = ospf_lookup_instance(instance);
11007 if (!ospf || !ospf->oi_running)
11008 return CMD_SUCCESS;
11009
11010 return show_ip_ospf_border_routers_common(vty, ospf, 0);
11011 }
11012
11013 static int show_ip_ospf_route_common(struct vty *vty, struct ospf *ospf,
11014 json_object *json, uint8_t use_vrf)
11015 {
11016 json_object *json_vrf = NULL;
11017
11018 if (ospf->instance)
11019 vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
11020
11021
11022 if (json) {
11023 if (use_vrf)
11024 json_vrf = json_object_new_object();
11025 else
11026 json_vrf = json;
11027 }
11028
11029 ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf);
11030
11031 if (ospf->new_table == NULL) {
11032 vty_out(vty, "No OSPF routing information exist\n");
11033 return CMD_SUCCESS;
11034 }
11035
11036 /* Show Network routes. */
11037 show_ip_ospf_route_network(vty, ospf, ospf->new_table, json_vrf);
11038
11039 /* Show Router routes. */
11040 show_ip_ospf_route_router(vty, ospf, ospf->new_rtrs, json_vrf);
11041
11042 /* Show AS External routes. */
11043 show_ip_ospf_route_external(vty, ospf, ospf->old_external_route,
11044 json_vrf);
11045
11046 if (json) {
11047 if (use_vrf) {
11048 // json_object_object_add(json_vrf, "areas",
11049 // json_areas);
11050 if (ospf->vrf_id == VRF_DEFAULT)
11051 json_object_object_add(json, "default",
11052 json_vrf);
11053 else
11054 json_object_object_add(json, ospf->name,
11055 json_vrf);
11056 }
11057 } else {
11058 vty_out(vty, "\n");
11059 }
11060
11061 return CMD_SUCCESS;
11062 }
11063
11064 DEFUN (show_ip_ospf_route,
11065 show_ip_ospf_route_cmd,
11066 "show ip ospf [vrf <NAME|all>] route [json]",
11067 SHOW_STR
11068 IP_STR
11069 "OSPF information\n"
11070 VRF_CMD_HELP_STR
11071 "All VRFs\n"
11072 "OSPF routing table\n"
11073 JSON_STR)
11074 {
11075 struct ospf *ospf = NULL;
11076 struct listnode *node = NULL;
11077 char *vrf_name = NULL;
11078 bool all_vrf = false;
11079 int ret = CMD_SUCCESS;
11080 int inst = 0;
11081 int idx_vrf = 0;
11082 uint8_t use_vrf = 0;
11083 bool uj = use_json(argc, argv);
11084 json_object *json = NULL;
11085
11086 if (uj)
11087 json = json_object_new_object();
11088
11089 OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
11090
11091 /* vrf input is provided could be all or specific vrf*/
11092 if (vrf_name) {
11093 bool ospf_output = false;
11094
11095 use_vrf = 1;
11096
11097 if (all_vrf) {
11098 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
11099 if (!ospf->oi_running)
11100 continue;
11101 ospf_output = true;
11102 ret = show_ip_ospf_route_common(vty, ospf, json,
11103 use_vrf);
11104 }
11105
11106 if (uj) {
11107 /* Keep Non-pretty format */
11108 vty_out(vty, "%s\n",
11109 json_object_to_json_string(json));
11110 json_object_free(json);
11111 } else if (!ospf_output)
11112 vty_out(vty, "%% OSPF instance not found\n");
11113
11114 return ret;
11115 }
11116 ospf = ospf_lookup_by_inst_name(inst, vrf_name);
11117 if (ospf == NULL || !ospf->oi_running) {
11118 if (uj) {
11119 vty_out(vty, "%s\n",
11120 json_object_to_json_string_ext(
11121 json, JSON_C_TO_STRING_PRETTY));
11122 json_object_free(json);
11123 } else
11124 vty_out(vty, "%% OSPF instance not found\n");
11125
11126 return CMD_SUCCESS;
11127 }
11128 } else {
11129 /* Display default ospf (instance 0) info */
11130 ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
11131 if (ospf == NULL || !ospf->oi_running) {
11132 if (uj) {
11133 vty_out(vty, "%s\n",
11134 json_object_to_json_string_ext(
11135 json, JSON_C_TO_STRING_PRETTY));
11136 json_object_free(json);
11137 } else
11138 vty_out(vty, "%% OSPF instance not found\n");
11139
11140 return CMD_SUCCESS;
11141 }
11142 }
11143
11144 if (ospf) {
11145 ret = show_ip_ospf_route_common(vty, ospf, json, use_vrf);
11146 /* Keep Non-pretty format */
11147 if (uj)
11148 vty_out(vty, "%s\n", json_object_to_json_string(json));
11149 }
11150
11151 if (uj)
11152 json_object_free(json);
11153
11154 return ret;
11155 }
11156
11157 DEFUN (show_ip_ospf_instance_route,
11158 show_ip_ospf_instance_route_cmd,
11159 "show ip ospf (1-65535) route",
11160 SHOW_STR
11161 IP_STR
11162 "OSPF information\n"
11163 "Instance ID\n"
11164 "OSPF routing table\n")
11165 {
11166 int idx_number = 3;
11167 struct ospf *ospf;
11168 unsigned short instance = 0;
11169
11170 instance = strtoul(argv[idx_number]->arg, NULL, 10);
11171 if (instance != ospf_instance)
11172 return CMD_NOT_MY_INSTANCE;
11173
11174 ospf = ospf_lookup_instance(instance);
11175 if (!ospf || !ospf->oi_running)
11176 return CMD_SUCCESS;
11177
11178 return show_ip_ospf_route_common(vty, ospf, NULL, 0);
11179 }
11180
11181
11182 DEFUN (show_ip_ospf_vrfs,
11183 show_ip_ospf_vrfs_cmd,
11184 "show ip ospf vrfs [json]",
11185 SHOW_STR
11186 IP_STR
11187 "OSPF information\n"
11188 "Show OSPF VRFs \n"
11189 JSON_STR)
11190 {
11191 bool uj = use_json(argc, argv);
11192 json_object *json = NULL;
11193 json_object *json_vrfs = NULL;
11194 struct ospf *ospf = NULL;
11195 struct listnode *node = NULL;
11196 int count = 0;
11197 char buf[PREFIX_STRLEN];
11198 static const char header[] = "Name Id RouterId ";
11199
11200 if (uj) {
11201 json = json_object_new_object();
11202 json_vrfs = json_object_new_object();
11203 }
11204
11205 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
11206 json_object *json_vrf = NULL;
11207 const char *name = NULL;
11208 int64_t vrf_id_ui = 0;
11209
11210 count++;
11211
11212 if (!uj && count == 1)
11213 vty_out(vty, "%s\n", header);
11214 if (uj)
11215 json_vrf = json_object_new_object();
11216
11217 if (ospf->vrf_id == VRF_DEFAULT)
11218 name = VRF_DEFAULT_NAME;
11219 else
11220 name = ospf->name;
11221
11222 vrf_id_ui = (ospf->vrf_id == VRF_UNKNOWN)
11223 ? -1
11224 : (int64_t)ospf->vrf_id;
11225
11226 if (uj) {
11227 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
11228 json_object_string_add(
11229 json_vrf, "routerId",
11230 inet_ntop(AF_INET, &ospf->router_id,
11231 buf, sizeof(buf)));
11232
11233 json_object_object_add(json_vrfs, name, json_vrf);
11234
11235 } else {
11236 vty_out(vty, "%-25s %-5d %-16pI4 \n", name,
11237 ospf->vrf_id, &ospf->router_id);
11238 }
11239 }
11240
11241 if (uj) {
11242 json_object_object_add(json, "vrfs", json_vrfs);
11243 json_object_int_add(json, "totalVrfs", count);
11244
11245 vty_out(vty, "%s\n", json_object_to_json_string_ext(
11246 json, JSON_C_TO_STRING_PRETTY));
11247 json_object_free(json);
11248 } else {
11249 if (count)
11250 vty_out(vty, "\nTotal number of OSPF VRFs: %d\n",
11251 count);
11252 }
11253
11254 return CMD_SUCCESS;
11255 }
11256 DEFPY (clear_ip_ospf_neighbor,
11257 clear_ip_ospf_neighbor_cmd,
11258 "clear ip ospf [(1-65535)]$instance neighbor [A.B.C.D$nbr_id]",
11259 CLEAR_STR
11260 IP_STR
11261 "OSPF information\n"
11262 "Instance ID\n"
11263 "Reset OSPF Neighbor\n"
11264 "Neighbor ID\n")
11265 {
11266 struct listnode *node;
11267 struct ospf *ospf = NULL;
11268
11269 /* If user does not specify the arguments,
11270 * instance = 0 and nbr_id = 0.0.0.0
11271 */
11272 if (instance != 0) {
11273 /* This means clear only the particular ospf process */
11274 if (instance != ospf_instance)
11275 return CMD_NOT_MY_INSTANCE;
11276 }
11277
11278 /* Clear all the ospf processes */
11279 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
11280 if (!ospf->oi_running)
11281 continue;
11282
11283 ospf_neighbor_reset(ospf, nbr_id, nbr_id_str);
11284 }
11285
11286 return CMD_SUCCESS;
11287 }
11288
11289 DEFPY (clear_ip_ospf_process,
11290 clear_ip_ospf_process_cmd,
11291 "clear ip ospf [(1-65535)]$instance process",
11292 CLEAR_STR
11293 IP_STR
11294 "OSPF information\n"
11295 "Instance ID\n"
11296 "Reset OSPF Process\n")
11297 {
11298 struct listnode *node;
11299 struct ospf *ospf = NULL;
11300
11301 /* Check if instance is not passed as an argument */
11302 if (instance != 0) {
11303 /* This means clear only the particular ospf process */
11304 if (instance != ospf_instance)
11305 return CMD_NOT_MY_INSTANCE;
11306 }
11307
11308 /* Clear all the ospf processes */
11309 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
11310 if (!ospf->oi_running)
11311 continue;
11312
11313 ospf_process_reset(ospf);
11314 }
11315
11316 return CMD_SUCCESS;
11317 }
11318
11319 static const char *const ospf_abr_type_str[] = {
11320 "unknown", "standard", "ibm", "cisco", "shortcut"
11321 };
11322
11323 static const char *const ospf_shortcut_mode_str[] = {
11324 "default", "enable", "disable"
11325 };
11326 static int ospf_vty_external_rt_walkcb(struct hash_bucket *bucket,
11327 void *arg)
11328 {
11329 struct external_info *ei = bucket->data;
11330 struct vty *vty = (struct vty *)arg;
11331 static unsigned int count;
11332
11333 vty_out(vty, "%-4pI4/%d, ", &ei->p.prefix, ei->p.prefixlen);
11334 count++;
11335
11336 if (count % 5 == 0)
11337 vty_out(vty, "\n");
11338
11339 if (OSPF_EXTERNAL_RT_COUNT(ei->aggr_route) == count)
11340 count = 0;
11341
11342 return HASHWALK_CONTINUE;
11343 }
11344
11345 static int ospf_json_external_rt_walkcb(struct hash_bucket *bucket,
11346 void *arg)
11347 {
11348 struct external_info *ei = bucket->data;
11349 struct json_object *json = (struct json_object *)arg;
11350 char buf[PREFIX2STR_BUFFER];
11351 char exnalbuf[20];
11352 static unsigned int count;
11353
11354 prefix2str(&ei->p, buf, sizeof(buf));
11355
11356 snprintf(exnalbuf, 20, "Exnl Addr-%d", count);
11357
11358 json_object_string_add(json, exnalbuf, buf);
11359
11360 count++;
11361
11362 if (OSPF_EXTERNAL_RT_COUNT(ei->aggr_route) == count)
11363 count = 0;
11364
11365 return HASHWALK_CONTINUE;
11366 }
11367
11368 static int ospf_show_summary_address(struct vty *vty, struct ospf *ospf,
11369 uint8_t use_vrf, json_object *json,
11370 bool uj, bool detail)
11371 {
11372 struct route_node *rn;
11373 json_object *json_vrf = NULL;
11374 int mtype = 0;
11375 int mval = 0;
11376 static char header[] =
11377 "Summary-address Metric-type Metric Tag External_Rt_count\n";
11378
11379 mtype = metric_type(ospf, 0, ospf->instance);
11380 mval = metric_value(ospf, 0, ospf->instance);
11381
11382 if (!uj)
11383 vty_out(vty, "%s\n", header);
11384
11385 if (uj) {
11386 if (use_vrf)
11387 json_vrf = json_object_new_object();
11388 else
11389 json_vrf = json;
11390 }
11391
11392 if (ospf->instance) {
11393 if (uj)
11394 json_object_int_add(json, "ospfInstance",
11395 ospf->instance);
11396 else
11397 vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
11398 }
11399
11400 ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf);
11401
11402 if (!uj)
11403 vty_out(vty, "aggregation delay interval :%d(in seconds)\n\n",
11404 ospf->aggr_delay_interval);
11405 else
11406 json_object_int_add(json_vrf, "aggregation delay interval",
11407 ospf->aggr_delay_interval);
11408
11409 for (rn = route_top(ospf->rt_aggr_tbl); rn; rn = route_next(rn))
11410 if (rn->info) {
11411 struct ospf_external_aggr_rt *aggr = rn->info;
11412 json_object *json_aggr = NULL;
11413 char buf[PREFIX2STR_BUFFER];
11414
11415 prefix2str(&aggr->p, buf, sizeof(buf));
11416
11417 if (uj) {
11418
11419 json_aggr = json_object_new_object();
11420
11421 json_object_object_add(json_vrf, buf,
11422 json_aggr);
11423
11424 json_object_string_add(json_aggr,
11425 "Summary address", buf);
11426
11427 json_object_string_add(
11428 json_aggr, "Metric-type",
11429 (mtype == EXTERNAL_METRIC_TYPE_1)
11430 ? "E1"
11431 : "E2");
11432
11433 json_object_int_add(json_aggr, "Metric", mval);
11434
11435 json_object_int_add(json_aggr, "Tag",
11436 aggr->tag);
11437
11438 json_object_int_add(
11439 json_aggr, "External route count",
11440 OSPF_EXTERNAL_RT_COUNT(aggr));
11441
11442 if (OSPF_EXTERNAL_RT_COUNT(aggr) && detail) {
11443 hash_walk(
11444 aggr->match_extnl_hash,
11445 ospf_json_external_rt_walkcb,
11446 json_aggr);
11447 }
11448
11449 } else {
11450 vty_out(vty, "%-20s", buf);
11451
11452 (mtype == EXTERNAL_METRIC_TYPE_1)
11453 ? vty_out(vty, "%-16s", "E1")
11454 : vty_out(vty, "%-16s", "E2");
11455 vty_out(vty, "%-11d", mval);
11456
11457 vty_out(vty, "%-12u", aggr->tag);
11458
11459 vty_out(vty, "%-5ld\n",
11460 OSPF_EXTERNAL_RT_COUNT(aggr));
11461
11462 if (OSPF_EXTERNAL_RT_COUNT(aggr) && detail) {
11463 vty_out(vty,
11464 "Matched External routes:\n");
11465 hash_walk(
11466 aggr->match_extnl_hash,
11467 ospf_vty_external_rt_walkcb,
11468 vty);
11469 vty_out(vty, "\n");
11470 }
11471
11472 vty_out(vty, "\n");
11473 }
11474 }
11475
11476 if (uj) {
11477 if (use_vrf) {
11478 if (ospf->vrf_id == VRF_DEFAULT)
11479 json_object_object_add(json, "default",
11480 json_vrf);
11481 else
11482 json_object_object_add(json, ospf->name,
11483 json_vrf);
11484 }
11485 } else
11486 vty_out(vty, "\n");
11487
11488 return CMD_SUCCESS;
11489 }
11490
11491 DEFUN (show_ip_ospf_external_aggregator,
11492 show_ip_ospf_external_aggregator_cmd,
11493 "show ip ospf [vrf <NAME|all>] summary-address [detail] [json]",
11494 SHOW_STR IP_STR
11495 "OSPF information\n"
11496 VRF_CMD_HELP_STR
11497 "All VRFs\n"
11498 "Show external summary addresses\n"
11499 "Detailed informtion\n"
11500 JSON_STR)
11501 {
11502 char *vrf_name = NULL;
11503 bool all_vrf = false;
11504 int ret = CMD_SUCCESS;
11505 int idx_vrf = 0;
11506 int idx = 0;
11507 uint8_t use_vrf = 0;
11508 bool uj = use_json(argc, argv);
11509 struct ospf *ospf = NULL;
11510 json_object *json = NULL;
11511 struct listnode *node = NULL;
11512 int inst = 0;
11513 bool detail = false;
11514
11515 OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
11516
11517 if (argv_find(argv, argc, "detail", &idx))
11518 detail = true;
11519
11520 if (uj)
11521 json = json_object_new_object();
11522
11523 /* vrf input is provided */
11524 if (vrf_name) {
11525 use_vrf = 1;
11526 if (all_vrf) {
11527 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
11528 if (!ospf->oi_running)
11529 continue;
11530 ret = ospf_show_summary_address(
11531 vty, ospf, use_vrf, json, uj, detail);
11532 }
11533
11534 if (uj) {
11535 vty_out(vty, "%s\n",
11536 json_object_to_json_string_ext(
11537 json, JSON_C_TO_STRING_PRETTY));
11538 json_object_free(json);
11539 }
11540
11541 return ret;
11542 }
11543
11544 ospf = ospf_lookup_by_inst_name(inst, vrf_name);
11545
11546 if (ospf == NULL || !ospf->oi_running) {
11547 if (uj) {
11548 vty_out(vty, "%s\n",
11549 json_object_to_json_string_ext(
11550 json, JSON_C_TO_STRING_PRETTY));
11551 json_object_free(json);
11552 } else
11553 vty_out(vty, "%% OSPF instance not found\n");
11554
11555 return CMD_SUCCESS;
11556 }
11557 ospf_show_summary_address(vty, ospf, use_vrf, json, uj, detail);
11558
11559 } else {
11560 /* Default Vrf */
11561 ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
11562 if (ospf == NULL || !ospf->oi_running) {
11563 if (uj) {
11564 vty_out(vty, "%s\n",
11565 json_object_to_json_string_ext(
11566 json, JSON_C_TO_STRING_PRETTY));
11567 json_object_free(json);
11568 } else
11569 vty_out(vty, "%% OSPF instance not found\n");
11570
11571 return CMD_SUCCESS;
11572 }
11573
11574 ospf_show_summary_address(vty, ospf, use_vrf, json, uj, detail);
11575 }
11576
11577 if (uj) {
11578 vty_out(vty, "%s\n", json_object_to_json_string_ext(
11579 json, JSON_C_TO_STRING_PRETTY));
11580 json_object_free(json);
11581 }
11582 return CMD_SUCCESS;
11583 }
11584
11585 static const char *const ospf_int_type_str[] = {
11586 "unknown", /* should never be used. */
11587 "point-to-point",
11588 "broadcast",
11589 "non-broadcast",
11590 "point-to-multipoint",
11591 "virtual-link", /* should never be used. */
11592 "loopback"
11593 };
11594
11595 static const char *interface_config_auth_str(struct ospf_if_params *params)
11596 {
11597 if (!OSPF_IF_PARAM_CONFIGURED(params, auth_type)
11598 || params->auth_type == OSPF_AUTH_NOTSET)
11599 return NULL;
11600
11601 /* Translation tables are not that much help
11602 * here due to syntax
11603 * of the simple option */
11604 switch (params->auth_type) {
11605
11606 case OSPF_AUTH_NULL:
11607 return " null";
11608
11609 case OSPF_AUTH_SIMPLE:
11610 return "";
11611
11612 case OSPF_AUTH_CRYPTOGRAPHIC:
11613 return " message-digest";
11614 }
11615
11616 return "";
11617 }
11618
11619 static int config_write_interface_one(struct vty *vty, struct vrf *vrf)
11620 {
11621 struct listnode *node;
11622 struct interface *ifp;
11623 struct crypt_key *ck;
11624 struct route_node *rn = NULL;
11625 struct ospf_if_params *params;
11626 const char *auth_str;
11627 int write = 0;
11628
11629 FOR_ALL_INTERFACES (vrf, ifp) {
11630
11631 if (memcmp(ifp->name, "VLINK", 5) == 0)
11632 continue;
11633
11634 vty_frame(vty, "!\n");
11635 if (ifp->vrf_id == VRF_DEFAULT)
11636 vty_frame(vty, "interface %s\n", ifp->name);
11637 else
11638 vty_frame(vty, "interface %s vrf %s\n", ifp->name,
11639 vrf->name);
11640 if (ifp->desc)
11641 vty_out(vty, " description %s\n", ifp->desc);
11642
11643 write++;
11644
11645 params = IF_DEF_PARAMS(ifp);
11646
11647 do {
11648 /* Interface Network print. */
11649 if (OSPF_IF_PARAM_CONFIGURED(params, type)
11650 && params->type != OSPF_IFTYPE_LOOPBACK) {
11651 if (params->type != ospf_default_iftype(ifp)) {
11652 vty_out(vty, " ip ospf network %s",
11653 ospf_int_type_str
11654 [params->type]);
11655 if (params->type
11656 == OSPF_IFTYPE_POINTOPOINT
11657 && params->ptp_dmvpn)
11658 vty_out(vty, " dmvpn");
11659 if (params != IF_DEF_PARAMS(ifp) && rn)
11660 vty_out(vty, " %pI4",
11661 &rn->p.u.prefix4);
11662 vty_out(vty, "\n");
11663 }
11664 }
11665
11666 /* OSPF interface authentication print */
11667 auth_str = interface_config_auth_str(params);
11668 if (auth_str) {
11669 vty_out(vty, " ip ospf authentication%s",
11670 auth_str);
11671 if (params != IF_DEF_PARAMS(ifp) && rn)
11672 vty_out(vty, " %pI4",
11673 &rn->p.u.prefix4);
11674 vty_out(vty, "\n");
11675 }
11676
11677 /* Simple Authentication Password print. */
11678 if (OSPF_IF_PARAM_CONFIGURED(params, auth_simple)
11679 && params->auth_simple[0] != '\0') {
11680 vty_out(vty, " ip ospf authentication-key %s",
11681 params->auth_simple);
11682 if (params != IF_DEF_PARAMS(ifp) && rn)
11683 vty_out(vty, " %pI4",
11684 &rn->p.u.prefix4);
11685 vty_out(vty, "\n");
11686 }
11687
11688 /* Cryptographic Authentication Key print. */
11689 if (params && params->auth_crypt) {
11690 for (ALL_LIST_ELEMENTS_RO(params->auth_crypt,
11691 node, ck)) {
11692 vty_out(vty,
11693 " ip ospf message-digest-key %d md5 %s",
11694 ck->key_id, ck->auth_key);
11695 if (params != IF_DEF_PARAMS(ifp) && rn)
11696 vty_out(vty, " %pI4",
11697 &rn->p.u.prefix4);
11698 vty_out(vty, "\n");
11699 }
11700 }
11701
11702 /* Interface Output Cost print. */
11703 if (OSPF_IF_PARAM_CONFIGURED(params, output_cost_cmd)) {
11704 vty_out(vty, " ip ospf cost %u",
11705 params->output_cost_cmd);
11706 if (params != IF_DEF_PARAMS(ifp) && rn)
11707 vty_out(vty, " %pI4",
11708 &rn->p.u.prefix4);
11709 vty_out(vty, "\n");
11710 }
11711
11712 /* Hello Interval print. */
11713 if (OSPF_IF_PARAM_CONFIGURED(params, v_hello)
11714 && params->v_hello != OSPF_HELLO_INTERVAL_DEFAULT) {
11715 vty_out(vty, " ip ospf hello-interval %u",
11716 params->v_hello);
11717 if (params != IF_DEF_PARAMS(ifp) && rn)
11718 vty_out(vty, " %pI4",
11719 &rn->p.u.prefix4);
11720 vty_out(vty, "\n");
11721 }
11722
11723
11724 /* Router Dead Interval print. */
11725 if (OSPF_IF_PARAM_CONFIGURED(params, v_wait)
11726 && params->is_v_wait_set
11727 && params->v_wait
11728 != OSPF_ROUTER_DEAD_INTERVAL_DEFAULT) {
11729 vty_out(vty, " ip ospf dead-interval ");
11730
11731 /* fast hello ? */
11732 if (OSPF_IF_PARAM_CONFIGURED(params,
11733 fast_hello))
11734 vty_out(vty,
11735 "minimal hello-multiplier %d",
11736 params->fast_hello);
11737 else
11738 vty_out(vty, "%u", params->v_wait);
11739
11740 if (params != IF_DEF_PARAMS(ifp) && rn)
11741 vty_out(vty, " %pI4",
11742 &rn->p.u.prefix4);
11743 vty_out(vty, "\n");
11744 }
11745
11746 /* Router Priority print. */
11747 if (OSPF_IF_PARAM_CONFIGURED(params, priority)
11748 && params->priority
11749 != OSPF_ROUTER_PRIORITY_DEFAULT) {
11750 vty_out(vty, " ip ospf priority %u",
11751 params->priority);
11752 if (params != IF_DEF_PARAMS(ifp) && rn)
11753 vty_out(vty, " %pI4",
11754 &rn->p.u.prefix4);
11755 vty_out(vty, "\n");
11756 }
11757
11758 /* Retransmit Interval print. */
11759 if (OSPF_IF_PARAM_CONFIGURED(params,
11760 retransmit_interval)
11761 && params->retransmit_interval
11762 != OSPF_RETRANSMIT_INTERVAL_DEFAULT) {
11763 vty_out(vty, " ip ospf retransmit-interval %u",
11764 params->retransmit_interval);
11765 if (params != IF_DEF_PARAMS(ifp) && rn)
11766 vty_out(vty, " %pI4",
11767 &rn->p.u.prefix4);
11768 vty_out(vty, "\n");
11769 }
11770
11771 /* Transmit Delay print. */
11772 if (OSPF_IF_PARAM_CONFIGURED(params, transmit_delay)
11773 && params->transmit_delay
11774 != OSPF_TRANSMIT_DELAY_DEFAULT) {
11775 vty_out(vty, " ip ospf transmit-delay %u",
11776 params->transmit_delay);
11777 if (params != IF_DEF_PARAMS(ifp) && rn)
11778 vty_out(vty, " %pI4",
11779 &rn->p.u.prefix4);
11780 vty_out(vty, "\n");
11781 }
11782
11783 /* Area print. */
11784 if (OSPF_IF_PARAM_CONFIGURED(params, if_area)) {
11785 if (ospf_instance)
11786 vty_out(vty, " ip ospf %d",
11787 ospf_instance);
11788 else
11789 vty_out(vty, " ip ospf");
11790
11791 char buf[INET_ADDRSTRLEN];
11792
11793 area_id2str(buf, sizeof(buf), &params->if_area,
11794 params->if_area_id_fmt);
11795 vty_out(vty, " area %s", buf);
11796 if (params != IF_DEF_PARAMS(ifp) && rn)
11797 vty_out(vty, " %pI4",
11798 &rn->p.u.prefix4);
11799 vty_out(vty, "\n");
11800 }
11801
11802 /* bfd print. */
11803 if (params && params->bfd_config)
11804 ospf_bfd_write_config(vty, params);
11805
11806 /* MTU ignore print. */
11807 if (OSPF_IF_PARAM_CONFIGURED(params, mtu_ignore)
11808 && params->mtu_ignore != OSPF_MTU_IGNORE_DEFAULT) {
11809 if (params->mtu_ignore == 0)
11810 vty_out(vty, " no ip ospf mtu-ignore");
11811 else
11812 vty_out(vty, " ip ospf mtu-ignore");
11813 if (params != IF_DEF_PARAMS(ifp) && rn)
11814 vty_out(vty, " %pI4",
11815 &rn->p.u.prefix4);
11816 vty_out(vty, "\n");
11817 }
11818
11819 /* LDP-Sync print */
11820 if (params && params->ldp_sync_info)
11821 ospf_ldp_sync_if_write_config(vty, params);
11822
11823 while (1) {
11824 if (rn == NULL)
11825 rn = route_top(IF_OIFS_PARAMS(ifp));
11826 else
11827 rn = route_next(rn);
11828
11829 if (rn == NULL)
11830 break;
11831 params = rn->info;
11832 if (params != NULL)
11833 break;
11834 }
11835 } while (rn);
11836
11837 ospf_opaque_config_write_if(vty, ifp);
11838
11839 vty_endframe(vty, NULL);
11840 }
11841
11842 return write;
11843 }
11844
11845 /* Configuration write function for ospfd. */
11846 static int config_write_interface(struct vty *vty)
11847 {
11848 int write = 0;
11849 struct vrf *vrf = NULL;
11850
11851 /* Display all VRF aware OSPF interface configuration */
11852 RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) {
11853 write += config_write_interface_one(vty, vrf);
11854 }
11855
11856 return write;
11857 }
11858
11859 static int config_write_network_area(struct vty *vty, struct ospf *ospf)
11860 {
11861 struct route_node *rn;
11862 char buf[INET_ADDRSTRLEN];
11863
11864 /* `network area' print. */
11865 for (rn = route_top(ospf->networks); rn; rn = route_next(rn))
11866 if (rn->info) {
11867 struct ospf_network *n = rn->info;
11868
11869 /* Create Area ID string by specified Area ID format. */
11870 if (n->area_id_fmt == OSPF_AREA_ID_FMT_DOTTEDQUAD)
11871 inet_ntop(AF_INET, &n->area_id, buf,
11872 sizeof(buf));
11873 else
11874 snprintf(buf, sizeof(buf), "%lu",
11875 (unsigned long int)ntohl(
11876 n->area_id.s_addr));
11877
11878 /* Network print. */
11879 vty_out(vty, " network %pFX area %s\n", &rn->p, buf);
11880 }
11881
11882 return 0;
11883 }
11884
11885 static int config_write_ospf_area(struct vty *vty, struct ospf *ospf)
11886 {
11887 struct listnode *node;
11888 struct ospf_area *area;
11889 char buf[INET_ADDRSTRLEN];
11890
11891 /* Area configuration print. */
11892 for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) {
11893 struct route_node *rn1;
11894
11895 area_id2str(buf, sizeof(buf), &area->area_id,
11896 area->area_id_fmt);
11897
11898 if (area->auth_type != OSPF_AUTH_NULL) {
11899 if (area->auth_type == OSPF_AUTH_SIMPLE)
11900 vty_out(vty, " area %s authentication\n", buf);
11901 else
11902 vty_out(vty,
11903 " area %s authentication message-digest\n",
11904 buf);
11905 }
11906
11907 if (area->shortcut_configured != OSPF_SHORTCUT_DEFAULT)
11908 vty_out(vty, " area %s shortcut %s\n", buf,
11909 ospf_shortcut_mode_str
11910 [area->shortcut_configured]);
11911
11912 if ((area->external_routing == OSPF_AREA_STUB)
11913 || (area->external_routing == OSPF_AREA_NSSA)) {
11914 if (area->external_routing == OSPF_AREA_STUB) {
11915 vty_out(vty, " area %s stub", buf);
11916 if (area->no_summary)
11917 vty_out(vty, " no-summary\n");
11918 vty_out(vty, "\n");
11919 } else if (area->external_routing == OSPF_AREA_NSSA) {
11920 switch (area->NSSATranslatorRole) {
11921 case OSPF_NSSA_ROLE_NEVER:
11922 vty_out(vty,
11923 " area %s nssa translate-never\n",
11924 buf);
11925 break;
11926 case OSPF_NSSA_ROLE_ALWAYS:
11927 vty_out(vty,
11928 " area %s nssa translate-always\n",
11929 buf);
11930 break;
11931 case OSPF_NSSA_ROLE_CANDIDATE:
11932 vty_out(vty, " area %s nssa \n", buf);
11933 break;
11934 }
11935 if (area->no_summary)
11936 vty_out(vty,
11937 " area %s nssa no-summary\n",
11938 buf);
11939 if (area->suppress_fa)
11940 vty_out(vty,
11941 " area %s nssa suppress-fa\n",
11942 buf);
11943 }
11944
11945 if (area->default_cost != 1)
11946 vty_out(vty, " area %s default-cost %d\n", buf,
11947 area->default_cost);
11948 }
11949
11950 for (rn1 = route_top(area->ranges); rn1; rn1 = route_next(rn1))
11951 if (rn1->info) {
11952 struct ospf_area_range *range = rn1->info;
11953
11954 vty_out(vty, " area %s range %pFX", buf,
11955 &rn1->p);
11956
11957 if (range->cost_config
11958 != OSPF_AREA_RANGE_COST_UNSPEC)
11959 vty_out(vty, " cost %d",
11960 range->cost_config);
11961
11962 if (!CHECK_FLAG(range->flags,
11963 OSPF_AREA_RANGE_ADVERTISE))
11964 vty_out(vty, " not-advertise");
11965
11966 if (CHECK_FLAG(range->flags,
11967 OSPF_AREA_RANGE_SUBSTITUTE))
11968 vty_out(vty, " substitute %pI4/%d",
11969 &range->subst_addr,
11970 range->subst_masklen);
11971
11972 vty_out(vty, "\n");
11973 }
11974
11975 if (EXPORT_NAME(area))
11976 vty_out(vty, " area %s export-list %s\n", buf,
11977 EXPORT_NAME(area));
11978
11979 if (IMPORT_NAME(area))
11980 vty_out(vty, " area %s import-list %s\n", buf,
11981 IMPORT_NAME(area));
11982
11983 if (PREFIX_NAME_IN(area))
11984 vty_out(vty, " area %s filter-list prefix %s in\n", buf,
11985 PREFIX_NAME_IN(area));
11986
11987 if (PREFIX_NAME_OUT(area))
11988 vty_out(vty, " area %s filter-list prefix %s out\n",
11989 buf, PREFIX_NAME_OUT(area));
11990 }
11991
11992 return 0;
11993 }
11994
11995 static int config_write_ospf_nbr_nbma(struct vty *vty, struct ospf *ospf)
11996 {
11997 struct ospf_nbr_nbma *nbr_nbma;
11998 struct route_node *rn;
11999
12000 /* Static Neighbor configuration print. */
12001 for (rn = route_top(ospf->nbr_nbma); rn; rn = route_next(rn))
12002 if ((nbr_nbma = rn->info)) {
12003 vty_out(vty, " neighbor %pI4", &nbr_nbma->addr);
12004
12005 if (nbr_nbma->priority
12006 != OSPF_NEIGHBOR_PRIORITY_DEFAULT)
12007 vty_out(vty, " priority %d",
12008 nbr_nbma->priority);
12009
12010 if (nbr_nbma->v_poll != OSPF_POLL_INTERVAL_DEFAULT)
12011 vty_out(vty, " poll-interval %d",
12012 nbr_nbma->v_poll);
12013
12014 vty_out(vty, "\n");
12015 }
12016
12017 return 0;
12018 }
12019
12020 static int config_write_virtual_link(struct vty *vty, struct ospf *ospf)
12021 {
12022 struct listnode *node;
12023 struct ospf_vl_data *vl_data;
12024 const char *auth_str;
12025 char buf[INET_ADDRSTRLEN];
12026
12027 /* Virtual-Link print */
12028 for (ALL_LIST_ELEMENTS_RO(ospf->vlinks, node, vl_data)) {
12029 struct listnode *n2;
12030 struct crypt_key *ck;
12031 struct ospf_interface *oi;
12032
12033 if (vl_data != NULL) {
12034 area_id2str(buf, sizeof(buf), &vl_data->vl_area_id,
12035 vl_data->vl_area_id_fmt);
12036 oi = vl_data->vl_oi;
12037
12038 /* timers */
12039 if (OSPF_IF_PARAM(oi, v_hello)
12040 != OSPF_HELLO_INTERVAL_DEFAULT
12041 || OSPF_IF_PARAM(oi, v_wait)
12042 != OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
12043 || OSPF_IF_PARAM(oi, retransmit_interval)
12044 != OSPF_RETRANSMIT_INTERVAL_DEFAULT
12045 || OSPF_IF_PARAM(oi, transmit_delay)
12046 != OSPF_TRANSMIT_DELAY_DEFAULT)
12047 vty_out(vty,
12048 " area %s virtual-link %pI4 hello-interval %d retransmit-interval %d transmit-delay %d dead-interval %d\n",
12049 buf, &vl_data->vl_peer,
12050 OSPF_IF_PARAM(oi, v_hello),
12051 OSPF_IF_PARAM(oi, retransmit_interval),
12052 OSPF_IF_PARAM(oi, transmit_delay),
12053 OSPF_IF_PARAM(oi, v_wait));
12054 else
12055 vty_out(vty, " area %s virtual-link %pI4\n", buf,
12056 &vl_data->vl_peer);
12057 /* Auth type */
12058 auth_str = interface_config_auth_str(
12059 IF_DEF_PARAMS(oi->ifp));
12060 if (auth_str)
12061 vty_out(vty,
12062 " area %s virtual-link %pI4 authentication%s\n",
12063 buf, &vl_data->vl_peer, auth_str);
12064 /* Auth key */
12065 if (IF_DEF_PARAMS(vl_data->vl_oi->ifp)->auth_simple[0]
12066 != '\0')
12067 vty_out(vty,
12068 " area %s virtual-link %pI4 authentication-key %s\n",
12069 buf, &vl_data->vl_peer,
12070 IF_DEF_PARAMS(vl_data->vl_oi->ifp)
12071 ->auth_simple);
12072 /* md5 keys */
12073 for (ALL_LIST_ELEMENTS_RO(
12074 IF_DEF_PARAMS(vl_data->vl_oi->ifp)
12075 ->auth_crypt,
12076 n2, ck))
12077 vty_out(vty,
12078 " area %s virtual-link %pI4 message-digest-key %d md5 %s\n",
12079 buf, &vl_data->vl_peer,
12080 ck->key_id, ck->auth_key);
12081 }
12082 }
12083
12084 return 0;
12085 }
12086
12087
12088 static int config_write_ospf_redistribute(struct vty *vty, struct ospf *ospf)
12089 {
12090 int type;
12091
12092 /* redistribute print. */
12093 for (type = 0; type < ZEBRA_ROUTE_MAX; type++) {
12094 struct list *red_list;
12095 struct listnode *node;
12096 struct ospf_redist *red;
12097
12098 red_list = ospf->redist[type];
12099 if (!red_list)
12100 continue;
12101
12102 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
12103 vty_out(vty, " redistribute %s",
12104 zebra_route_string(type));
12105 if (red->instance)
12106 vty_out(vty, " %d", red->instance);
12107
12108 if (red->dmetric.value >= 0)
12109 vty_out(vty, " metric %d", red->dmetric.value);
12110
12111 if (red->dmetric.type == EXTERNAL_METRIC_TYPE_1)
12112 vty_out(vty, " metric-type 1");
12113
12114 if (ROUTEMAP_NAME(red))
12115 vty_out(vty, " route-map %s",
12116 ROUTEMAP_NAME(red));
12117
12118 vty_out(vty, "\n");
12119 }
12120 }
12121
12122 return 0;
12123 }
12124
12125 static int ospf_cfg_write_helper_dis_rtr_walkcb(struct hash_bucket *bucket,
12126 void *arg)
12127 {
12128 struct advRtr *rtr = bucket->data;
12129 struct vty *vty = (struct vty *)arg;
12130
12131 vty_out(vty, " graceful-restart helper-only %pI4\n",
12132 &rtr->advRtrAddr);
12133 return HASHWALK_CONTINUE;
12134 }
12135
12136 static int config_write_ospf_gr_helper(struct vty *vty, struct ospf *ospf)
12137 {
12138 if (ospf->is_helper_supported)
12139 vty_out(vty, " graceful-restart helper-only\n");
12140
12141 if (!ospf->strict_lsa_check)
12142 vty_out(vty,
12143 " no graceful-restart helper strict-lsa-checking\n");
12144
12145 if (ospf->only_planned_restart)
12146 vty_out(vty, " graceful-restart helper planned-only\n");
12147
12148 if (ospf->supported_grace_time != OSPF_MAX_GRACE_INTERVAL)
12149 vty_out(vty,
12150 " graceful-restart helper supported-grace-time %d\n",
12151 ospf->supported_grace_time);
12152
12153 if (OSPF_HELPER_ENABLE_RTR_COUNT(ospf)) {
12154 hash_walk(ospf->enable_rtr_list,
12155 ospf_cfg_write_helper_dis_rtr_walkcb, vty);
12156 }
12157 return 0;
12158 }
12159
12160 static int config_write_ospf_external_aggregator(struct vty *vty,
12161 struct ospf *ospf)
12162 {
12163 struct route_node *rn;
12164
12165 /* print 'summary-address A.B.C.D/M' */
12166 for (rn = route_top(ospf->rt_aggr_tbl); rn; rn = route_next(rn))
12167 if (rn->info) {
12168 struct ospf_external_aggr_rt *aggr = rn->info;
12169
12170 vty_out(vty, " summary-address %pI4/%d ",
12171 &aggr->p.prefix, aggr->p.prefixlen);
12172 if (aggr->tag)
12173 vty_out(vty, " tag %u ", aggr->tag);
12174
12175 if (CHECK_FLAG(aggr->flags,
12176 OSPF_EXTERNAL_AGGRT_NO_ADVERTISE))
12177 vty_out(vty, " no-advertise");
12178
12179 vty_out(vty, "\n");
12180 }
12181
12182 return 0;
12183 }
12184
12185 static int config_write_ospf_default_metric(struct vty *vty, struct ospf *ospf)
12186 {
12187 if (ospf->default_metric != -1)
12188 vty_out(vty, " default-metric %d\n", ospf->default_metric);
12189 return 0;
12190 }
12191
12192 static int config_write_ospf_distribute(struct vty *vty, struct ospf *ospf)
12193 {
12194 int type;
12195 struct ospf_redist *red;
12196
12197 if (ospf) {
12198 /* distribute-list print. */
12199 for (type = 0; type < ZEBRA_ROUTE_MAX; type++)
12200 if (DISTRIBUTE_NAME(ospf, type))
12201 vty_out(vty, " distribute-list %s out %s\n",
12202 DISTRIBUTE_NAME(ospf, type),
12203 zebra_route_string(type));
12204
12205 /* default-information print. */
12206 if (ospf->default_originate != DEFAULT_ORIGINATE_NONE) {
12207 vty_out(vty, " default-information originate");
12208 if (ospf->default_originate == DEFAULT_ORIGINATE_ALWAYS)
12209 vty_out(vty, " always");
12210
12211 red = ospf_redist_lookup(ospf, DEFAULT_ROUTE, 0);
12212 if (red) {
12213 if (red->dmetric.value >= 0)
12214 vty_out(vty, " metric %d",
12215 red->dmetric.value);
12216
12217 if (red->dmetric.type == EXTERNAL_METRIC_TYPE_1)
12218 vty_out(vty, " metric-type 1");
12219
12220 if (ROUTEMAP_NAME(red))
12221 vty_out(vty, " route-map %s",
12222 ROUTEMAP_NAME(red));
12223 }
12224
12225 vty_out(vty, "\n");
12226 }
12227 }
12228
12229 return 0;
12230 }
12231
12232 static int config_write_ospf_distance(struct vty *vty, struct ospf *ospf)
12233 {
12234 struct route_node *rn;
12235 struct ospf_distance *odistance;
12236
12237 if (ospf->distance_all)
12238 vty_out(vty, " distance %d\n", ospf->distance_all);
12239
12240 if (ospf->distance_intra || ospf->distance_inter
12241 || ospf->distance_external) {
12242 vty_out(vty, " distance ospf");
12243
12244 if (ospf->distance_intra)
12245 vty_out(vty, " intra-area %d", ospf->distance_intra);
12246 if (ospf->distance_inter)
12247 vty_out(vty, " inter-area %d", ospf->distance_inter);
12248 if (ospf->distance_external)
12249 vty_out(vty, " external %d", ospf->distance_external);
12250
12251 vty_out(vty, "\n");
12252 }
12253
12254 for (rn = route_top(ospf->distance_table); rn; rn = route_next(rn))
12255 if ((odistance = rn->info) != NULL) {
12256 vty_out(vty, " distance %d %pFX %s\n",
12257 odistance->distance, &rn->p,
12258 odistance->access_list ? odistance->access_list
12259 : "");
12260 }
12261 return 0;
12262 }
12263
12264 static int ospf_config_write_one(struct vty *vty, struct ospf *ospf)
12265 {
12266 struct vrf *vrf = vrf_lookup_by_id(ospf->vrf_id);
12267 struct interface *ifp;
12268 struct ospf_interface *oi;
12269 struct listnode *node = NULL;
12270 int write = 0;
12271
12272 /* `router ospf' print. */
12273 if (ospf->instance && ospf->name) {
12274 vty_out(vty, "router ospf %d vrf %s\n", ospf->instance,
12275 ospf->name);
12276 } else if (ospf->instance) {
12277 vty_out(vty, "router ospf %d\n", ospf->instance);
12278 } else if (ospf->name) {
12279 vty_out(vty, "router ospf vrf %s\n", ospf->name);
12280 } else
12281 vty_out(vty, "router ospf\n");
12282
12283 if (!ospf->networks) {
12284 write++;
12285 return write;
12286 }
12287
12288 /* Router ID print. */
12289 if (ospf->router_id_static.s_addr != INADDR_ANY)
12290 vty_out(vty, " ospf router-id %pI4\n",
12291 &ospf->router_id_static);
12292
12293 /* ABR type print. */
12294 if (ospf->abr_type != OSPF_ABR_DEFAULT)
12295 vty_out(vty, " ospf abr-type %s\n",
12296 ospf_abr_type_str[ospf->abr_type]);
12297
12298 /* log-adjacency-changes flag print. */
12299 if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES)) {
12300 if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL))
12301 vty_out(vty, " log-adjacency-changes detail\n");
12302 else if (!SAVE_OSPF_LOG_ADJACENCY_CHANGES)
12303 vty_out(vty, " log-adjacency-changes\n");
12304 } else if (SAVE_OSPF_LOG_ADJACENCY_CHANGES) {
12305 vty_out(vty, " no log-adjacency-changes\n");
12306 }
12307
12308 /* RFC1583 compatibility flag print -- Compatible with CISCO
12309 * 12.1. */
12310 if (CHECK_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE))
12311 vty_out(vty, " compatible rfc1583\n");
12312
12313 /* auto-cost reference-bandwidth configuration. */
12314 if (ospf->ref_bandwidth != OSPF_DEFAULT_REF_BANDWIDTH) {
12315 vty_out(vty,
12316 "! Important: ensure reference bandwidth is consistent across all routers\n");
12317 vty_out(vty, " auto-cost reference-bandwidth %d\n",
12318 ospf->ref_bandwidth);
12319 }
12320
12321 /* SPF timers print. */
12322 if (ospf->spf_delay != OSPF_SPF_DELAY_DEFAULT
12323 || ospf->spf_holdtime != OSPF_SPF_HOLDTIME_DEFAULT
12324 || ospf->spf_max_holdtime != OSPF_SPF_MAX_HOLDTIME_DEFAULT)
12325 vty_out(vty, " timers throttle spf %d %d %d\n", ospf->spf_delay,
12326 ospf->spf_holdtime, ospf->spf_max_holdtime);
12327
12328 /* LSA timers print. */
12329 if (ospf->min_ls_interval != OSPF_MIN_LS_INTERVAL)
12330 vty_out(vty, " timers throttle lsa all %d\n",
12331 ospf->min_ls_interval);
12332 if (ospf->min_ls_arrival != OSPF_MIN_LS_ARRIVAL)
12333 vty_out(vty, " timers lsa min-arrival %d\n",
12334 ospf->min_ls_arrival);
12335
12336 /* Write multiplier print. */
12337 if (ospf->write_oi_count != OSPF_WRITE_INTERFACE_COUNT_DEFAULT)
12338 vty_out(vty, " ospf write-multiplier %d\n",
12339 ospf->write_oi_count);
12340
12341 if (ospf->max_multipath != MULTIPATH_NUM)
12342 vty_out(vty, " maximum-paths %d\n", ospf->max_multipath);
12343
12344 /* Max-metric router-lsa print */
12345 config_write_stub_router(vty, ospf);
12346
12347 /* SPF refresh parameters print. */
12348 if (ospf->lsa_refresh_interval != OSPF_LSA_REFRESH_INTERVAL_DEFAULT)
12349 vty_out(vty, " refresh timer %d\n", ospf->lsa_refresh_interval);
12350
12351 /* Redistribute information print. */
12352 config_write_ospf_redistribute(vty, ospf);
12353
12354 /* Print gr helper configs */
12355 config_write_ospf_gr_helper(vty, ospf);
12356
12357 /* Print external route aggregation. */
12358 config_write_ospf_external_aggregator(vty, ospf);
12359
12360 /* passive-interface print. */
12361 if (ospf->passive_interface_default == OSPF_IF_PASSIVE)
12362 vty_out(vty, " passive-interface default\n");
12363
12364 /* proactive-arp print. */
12365 if (ospf->proactive_arp != OSPF_PROACTIVE_ARP_DEFAULT) {
12366 if (ospf->proactive_arp)
12367 vty_out(vty, " proactive-arp\n");
12368 else
12369 vty_out(vty, " no proactive-arp\n");
12370 }
12371
12372 FOR_ALL_INTERFACES (vrf, ifp)
12373 if (OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(ifp),
12374 passive_interface)
12375 && IF_DEF_PARAMS(ifp)->passive_interface
12376 != ospf->passive_interface_default) {
12377 vty_out(vty, " %spassive-interface %s\n",
12378 IF_DEF_PARAMS(ifp)->passive_interface ? ""
12379 : "no ",
12380 ifp->name);
12381 }
12382 for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) {
12383 if (!OSPF_IF_PARAM_CONFIGURED(oi->params, passive_interface))
12384 continue;
12385 if (OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(oi->ifp),
12386 passive_interface)) {
12387 if (oi->params->passive_interface
12388 == IF_DEF_PARAMS(oi->ifp)->passive_interface)
12389 continue;
12390 } else if (oi->params->passive_interface
12391 == ospf->passive_interface_default)
12392 continue;
12393
12394 vty_out(vty, " %spassive-interface %s %pI4\n",
12395 oi->params->passive_interface ? "" : "no ",
12396 oi->ifp->name, &oi->address->u.prefix4);
12397 }
12398
12399 /* TI-LFA print. */
12400 if (ospf->ti_lfa_enabled) {
12401 if (ospf->ti_lfa_protection_type == OSPF_TI_LFA_NODE_PROTECTION)
12402 vty_out(vty, " fast-reroute ti-lfa node-protection\n");
12403 else
12404 vty_out(vty, " fast-reroute ti-lfa\n");
12405 }
12406
12407 /* Network area print. */
12408 config_write_network_area(vty, ospf);
12409
12410 /* Area config print. */
12411 config_write_ospf_area(vty, ospf);
12412
12413 /* static neighbor print. */
12414 config_write_ospf_nbr_nbma(vty, ospf);
12415
12416 /* Virtual-Link print. */
12417 config_write_virtual_link(vty, ospf);
12418
12419 /* Default metric configuration. */
12420 config_write_ospf_default_metric(vty, ospf);
12421
12422 /* Distribute-list and default-information print. */
12423 config_write_ospf_distribute(vty, ospf);
12424
12425 /* Distance configuration. */
12426 config_write_ospf_distance(vty, ospf);
12427
12428 ospf_opaque_config_write_router(vty, ospf);
12429
12430 /* LDP-Sync print */
12431 ospf_ldp_sync_write_config(vty, ospf);
12432
12433 write++;
12434 return write;
12435 }
12436
12437 /* OSPF configuration write function. */
12438 static int ospf_config_write(struct vty *vty)
12439 {
12440 struct ospf *ospf;
12441 struct listnode *ospf_node = NULL;
12442 int write = 0;
12443
12444 if (listcount(om->ospf) == 0)
12445 return write;
12446
12447 for (ALL_LIST_ELEMENTS_RO(om->ospf, ospf_node, ospf)) {
12448 /* VRF Default check if it is running.
12449 * Upon daemon start, there could be default instance
12450 * in absence of 'router ospf'/oi_running is disabled. */
12451 if (ospf->vrf_id == VRF_DEFAULT && ospf->oi_running)
12452 write += ospf_config_write_one(vty, ospf);
12453 /* For Non-Default VRF simply display the configuration,
12454 * even if it is not oi_running. */
12455 else if (ospf->vrf_id != VRF_DEFAULT)
12456 write += ospf_config_write_one(vty, ospf);
12457 }
12458 return write;
12459 }
12460
12461 void ospf_vty_show_init(void)
12462 {
12463 /* "show ip ospf" commands. */
12464 install_element(VIEW_NODE, &show_ip_ospf_cmd);
12465
12466 install_element(VIEW_NODE, &show_ip_ospf_instance_cmd);
12467
12468 /* "show ip ospf database" commands. */
12469 install_element(VIEW_NODE, &show_ip_ospf_database_cmd);
12470 install_element(VIEW_NODE, &show_ip_ospf_database_max_cmd);
12471 install_element(VIEW_NODE,
12472 &show_ip_ospf_database_type_adv_router_cmd);
12473 install_element(VIEW_NODE,
12474 &show_ip_ospf_instance_database_type_adv_router_cmd);
12475 install_element(VIEW_NODE, &show_ip_ospf_instance_database_cmd);
12476 install_element(VIEW_NODE, &show_ip_ospf_instance_database_max_cmd);
12477
12478 /* "show ip ospf interface" commands. */
12479 install_element(VIEW_NODE, &show_ip_ospf_interface_cmd);
12480
12481 install_element(VIEW_NODE, &show_ip_ospf_instance_interface_cmd);
12482 /* "show ip ospf interface traffic */
12483 install_element(VIEW_NODE, &show_ip_ospf_interface_traffic_cmd);
12484
12485 /* "show ip ospf neighbor" commands. */
12486 install_element(VIEW_NODE, &show_ip_ospf_neighbor_int_detail_cmd);
12487 install_element(VIEW_NODE, &show_ip_ospf_neighbor_int_cmd);
12488 install_element(VIEW_NODE, &show_ip_ospf_neighbor_id_cmd);
12489 install_element(VIEW_NODE, &show_ip_ospf_neighbor_detail_all_cmd);
12490 install_element(VIEW_NODE, &show_ip_ospf_neighbor_detail_cmd);
12491 install_element(VIEW_NODE, &show_ip_ospf_neighbor_cmd);
12492 install_element(VIEW_NODE, &show_ip_ospf_neighbor_all_cmd);
12493
12494 install_element(VIEW_NODE,
12495 &show_ip_ospf_instance_neighbor_int_detail_cmd);
12496 install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_int_cmd);
12497 install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_id_cmd);
12498 install_element(VIEW_NODE,
12499 &show_ip_ospf_instance_neighbor_detail_all_cmd);
12500 install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_detail_cmd);
12501 install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_cmd);
12502 install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_all_cmd);
12503
12504 /* "show ip ospf route" commands. */
12505 install_element(VIEW_NODE, &show_ip_ospf_route_cmd);
12506 install_element(VIEW_NODE, &show_ip_ospf_border_routers_cmd);
12507
12508 install_element(VIEW_NODE, &show_ip_ospf_instance_route_cmd);
12509 install_element(VIEW_NODE, &show_ip_ospf_instance_border_routers_cmd);
12510
12511 /* "show ip ospf vrfs" commands. */
12512 install_element(VIEW_NODE, &show_ip_ospf_vrfs_cmd);
12513
12514 /* "show ip ospf gr-helper details" command */
12515 install_element(VIEW_NODE, &show_ip_ospf_gr_helper_cmd);
12516
12517 /* "show ip ospf summary-address" command */
12518 install_element(VIEW_NODE, &show_ip_ospf_external_aggregator_cmd);
12519 }
12520
12521 static int config_write_interface(struct vty *vty);
12522 /* ospfd's interface node. */
12523 static struct cmd_node interface_node = {
12524 .name = "interface",
12525 .node = INTERFACE_NODE,
12526 .parent_node = CONFIG_NODE,
12527 .prompt = "%s(config-if)# ",
12528 .config_write = config_write_interface,
12529 };
12530
12531 /* Initialization of OSPF interface. */
12532 static void ospf_vty_if_init(void)
12533 {
12534 /* Install interface node. */
12535 install_node(&interface_node);
12536 if_cmd_init();
12537
12538 /* "ip ospf authentication" commands. */
12539 install_element(INTERFACE_NODE, &ip_ospf_authentication_args_addr_cmd);
12540 install_element(INTERFACE_NODE, &ip_ospf_authentication_addr_cmd);
12541 install_element(INTERFACE_NODE,
12542 &no_ip_ospf_authentication_args_addr_cmd);
12543 install_element(INTERFACE_NODE, &no_ip_ospf_authentication_addr_cmd);
12544 install_element(INTERFACE_NODE, &ip_ospf_authentication_key_addr_cmd);
12545 install_element(INTERFACE_NODE,
12546 &no_ip_ospf_authentication_key_authkey_addr_cmd);
12547 install_element(INTERFACE_NODE,
12548 &no_ospf_authentication_key_authkey_addr_cmd);
12549
12550 /* "ip ospf message-digest-key" commands. */
12551 install_element(INTERFACE_NODE, &ip_ospf_message_digest_key_cmd);
12552 install_element(INTERFACE_NODE, &no_ip_ospf_message_digest_key_cmd);
12553
12554 /* "ip ospf cost" commands. */
12555 install_element(INTERFACE_NODE, &ip_ospf_cost_cmd);
12556 install_element(INTERFACE_NODE, &no_ip_ospf_cost_cmd);
12557
12558 /* "ip ospf mtu-ignore" commands. */
12559 install_element(INTERFACE_NODE, &ip_ospf_mtu_ignore_addr_cmd);
12560 install_element(INTERFACE_NODE, &no_ip_ospf_mtu_ignore_addr_cmd);
12561
12562 /* "ip ospf dead-interval" commands. */
12563 install_element(INTERFACE_NODE, &ip_ospf_dead_interval_cmd);
12564 install_element(INTERFACE_NODE,
12565 &ip_ospf_dead_interval_minimal_addr_cmd);
12566 install_element(INTERFACE_NODE, &no_ip_ospf_dead_interval_cmd);
12567
12568 /* "ip ospf hello-interval" commands. */
12569 install_element(INTERFACE_NODE, &ip_ospf_hello_interval_cmd);
12570 install_element(INTERFACE_NODE, &no_ip_ospf_hello_interval_cmd);
12571
12572 /* "ip ospf network" commands. */
12573 install_element(INTERFACE_NODE, &ip_ospf_network_cmd);
12574 install_element(INTERFACE_NODE, &no_ip_ospf_network_cmd);
12575
12576 /* "ip ospf priority" commands. */
12577 install_element(INTERFACE_NODE, &ip_ospf_priority_cmd);
12578 install_element(INTERFACE_NODE, &no_ip_ospf_priority_cmd);
12579
12580 /* "ip ospf retransmit-interval" commands. */
12581 install_element(INTERFACE_NODE, &ip_ospf_retransmit_interval_addr_cmd);
12582 install_element(INTERFACE_NODE,
12583 &no_ip_ospf_retransmit_interval_addr_cmd);
12584
12585 /* "ip ospf transmit-delay" commands. */
12586 install_element(INTERFACE_NODE, &ip_ospf_transmit_delay_addr_cmd);
12587 install_element(INTERFACE_NODE, &no_ip_ospf_transmit_delay_addr_cmd);
12588
12589 /* "ip ospf area" commands. */
12590 install_element(INTERFACE_NODE, &ip_ospf_area_cmd);
12591 install_element(INTERFACE_NODE, &no_ip_ospf_area_cmd);
12592
12593 /* These commands are compatibitliy for previous version. */
12594 install_element(INTERFACE_NODE, &ospf_authentication_key_cmd);
12595 install_element(INTERFACE_NODE, &ospf_message_digest_key_cmd);
12596 install_element(INTERFACE_NODE, &no_ospf_message_digest_key_cmd);
12597 install_element(INTERFACE_NODE, &ospf_dead_interval_cmd);
12598 install_element(INTERFACE_NODE, &no_ospf_dead_interval_cmd);
12599 install_element(INTERFACE_NODE, &ospf_hello_interval_cmd);
12600 install_element(INTERFACE_NODE, &no_ospf_hello_interval_cmd);
12601 install_element(INTERFACE_NODE, &ospf_cost_cmd);
12602 install_element(INTERFACE_NODE, &no_ospf_cost_cmd);
12603 install_element(INTERFACE_NODE, &ospf_network_cmd);
12604 install_element(INTERFACE_NODE, &no_ospf_network_cmd);
12605 install_element(INTERFACE_NODE, &ospf_priority_cmd);
12606 install_element(INTERFACE_NODE, &no_ospf_priority_cmd);
12607 install_element(INTERFACE_NODE, &ospf_retransmit_interval_cmd);
12608 install_element(INTERFACE_NODE, &no_ospf_retransmit_interval_cmd);
12609 install_element(INTERFACE_NODE, &ospf_transmit_delay_cmd);
12610 install_element(INTERFACE_NODE, &no_ospf_transmit_delay_cmd);
12611 }
12612
12613 static void ospf_vty_zebra_init(void)
12614 {
12615 install_element(OSPF_NODE, &ospf_redistribute_source_cmd);
12616 install_element(OSPF_NODE, &no_ospf_redistribute_source_cmd);
12617 install_element(OSPF_NODE, &ospf_redistribute_instance_source_cmd);
12618 install_element(OSPF_NODE, &no_ospf_redistribute_instance_source_cmd);
12619
12620 install_element(OSPF_NODE, &ospf_distribute_list_out_cmd);
12621 install_element(OSPF_NODE, &no_ospf_distribute_list_out_cmd);
12622
12623 install_element(OSPF_NODE, &ospf_default_information_originate_cmd);
12624 install_element(OSPF_NODE, &no_ospf_default_information_originate_cmd);
12625
12626 install_element(OSPF_NODE, &ospf_default_metric_cmd);
12627 install_element(OSPF_NODE, &no_ospf_default_metric_cmd);
12628
12629 install_element(OSPF_NODE, &ospf_distance_cmd);
12630 install_element(OSPF_NODE, &no_ospf_distance_cmd);
12631 install_element(OSPF_NODE, &no_ospf_distance_ospf_cmd);
12632 install_element(OSPF_NODE, &ospf_distance_ospf_cmd);
12633
12634 /*Ospf garcefull restart helper configurations */
12635 install_element(OSPF_NODE, &ospf_gr_helper_enable_cmd);
12636 install_element(OSPF_NODE, &no_ospf_gr_helper_enable_cmd);
12637 install_element(OSPF_NODE, &ospf_gr_helper_enable_lsacheck_cmd);
12638 install_element(OSPF_NODE, &no_ospf_gr_helper_enable_lsacheck_cmd);
12639 install_element(OSPF_NODE, &ospf_gr_helper_supported_grace_time_cmd);
12640 install_element(OSPF_NODE, &no_ospf_gr_helper_supported_grace_time_cmd);
12641 install_element(OSPF_NODE, &ospf_gr_helper_planned_only_cmd);
12642 install_element(OSPF_NODE, &no_ospf_gr_helper_planned_only_cmd);
12643
12644 /* External LSA summarisation config commands.*/
12645 install_element(OSPF_NODE, &ospf_external_route_aggregation_cmd);
12646 install_element(OSPF_NODE, &no_ospf_external_route_aggregation_cmd);
12647 install_element(OSPF_NODE,
12648 &ospf_external_route_aggregation_no_adrvertise_cmd);
12649 install_element(OSPF_NODE,
12650 &no_ospf_external_route_aggregation_no_adrvertise_cmd);
12651 install_element(OSPF_NODE, &ospf_route_aggregation_timer_cmd);
12652 install_element(OSPF_NODE, &no_ospf_route_aggregation_timer_cmd);
12653 }
12654
12655 static int ospf_config_write(struct vty *vty);
12656 static struct cmd_node ospf_node = {
12657 .name = "ospf",
12658 .node = OSPF_NODE,
12659 .parent_node = CONFIG_NODE,
12660 .prompt = "%s(config-router)# ",
12661 .config_write = ospf_config_write,
12662 };
12663
12664 static void ospf_interface_clear(struct interface *ifp)
12665 {
12666 if (!if_is_operative(ifp))
12667 return;
12668
12669 if (IS_DEBUG_OSPF(ism, ISM_EVENTS))
12670 zlog_debug("ISM[%s]: clear by reset", ifp->name);
12671
12672 ospf_if_reset(ifp);
12673 }
12674
12675 DEFUN (clear_ip_ospf_interface,
12676 clear_ip_ospf_interface_cmd,
12677 "clear ip ospf [vrf NAME] interface [IFNAME]",
12678 CLEAR_STR
12679 IP_STR
12680 "OSPF information\n"
12681 VRF_CMD_HELP_STR
12682 "Interface information\n"
12683 "Interface name\n")
12684 {
12685 int idx_ifname = 0;
12686 int idx_vrf = 0;
12687 struct interface *ifp;
12688 struct listnode *node;
12689 struct ospf *ospf = NULL;
12690 char *vrf_name = NULL;
12691 vrf_id_t vrf_id = VRF_DEFAULT;
12692 struct vrf *vrf = NULL;
12693
12694 if (argv_find(argv, argc, "vrf", &idx_vrf))
12695 vrf_name = argv[idx_vrf + 1]->arg;
12696 if (vrf_name && strmatch(vrf_name, VRF_DEFAULT_NAME))
12697 vrf_name = NULL;
12698 if (vrf_name) {
12699 vrf = vrf_lookup_by_name(vrf_name);
12700 if (vrf)
12701 vrf_id = vrf->vrf_id;
12702 }
12703 if (!argv_find(argv, argc, "IFNAME", &idx_ifname)) {
12704 /* Clear all the ospfv2 interfaces. */
12705 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
12706 if (vrf_id != ospf->vrf_id)
12707 continue;
12708 if (!vrf)
12709 vrf = vrf_lookup_by_id(ospf->vrf_id);
12710 FOR_ALL_INTERFACES (vrf, ifp)
12711 ospf_interface_clear(ifp);
12712 }
12713 } else {
12714 /* Interface name is specified. */
12715 ifp = if_lookup_by_name(argv[idx_ifname]->arg, vrf_id);
12716 if (ifp == NULL)
12717 vty_out(vty, "No such interface name\n");
12718 else
12719 ospf_interface_clear(ifp);
12720 }
12721
12722 return CMD_SUCCESS;
12723 }
12724
12725 void ospf_vty_clear_init(void)
12726 {
12727 install_element(ENABLE_NODE, &clear_ip_ospf_interface_cmd);
12728 install_element(ENABLE_NODE, &clear_ip_ospf_process_cmd);
12729 install_element(ENABLE_NODE, &clear_ip_ospf_neighbor_cmd);
12730 }
12731
12732
12733 /* Install OSPF related vty commands. */
12734 void ospf_vty_init(void)
12735 {
12736 /* Install ospf top node. */
12737 install_node(&ospf_node);
12738
12739 /* "router ospf" commands. */
12740 install_element(CONFIG_NODE, &router_ospf_cmd);
12741 install_element(CONFIG_NODE, &no_router_ospf_cmd);
12742
12743
12744 install_default(OSPF_NODE);
12745
12746 /* "ospf router-id" commands. */
12747 install_element(OSPF_NODE, &ospf_router_id_cmd);
12748 install_element(OSPF_NODE, &ospf_router_id_old_cmd);
12749 install_element(OSPF_NODE, &no_ospf_router_id_cmd);
12750
12751 /* "passive-interface" commands. */
12752 install_element(OSPF_NODE, &ospf_passive_interface_addr_cmd);
12753 install_element(OSPF_NODE, &no_ospf_passive_interface_addr_cmd);
12754
12755 /* "ospf abr-type" commands. */
12756 install_element(OSPF_NODE, &ospf_abr_type_cmd);
12757 install_element(OSPF_NODE, &no_ospf_abr_type_cmd);
12758
12759 /* "ospf log-adjacency-changes" commands. */
12760 install_element(OSPF_NODE, &ospf_log_adjacency_changes_cmd);
12761 install_element(OSPF_NODE, &ospf_log_adjacency_changes_detail_cmd);
12762 install_element(OSPF_NODE, &no_ospf_log_adjacency_changes_cmd);
12763 install_element(OSPF_NODE, &no_ospf_log_adjacency_changes_detail_cmd);
12764
12765 /* "ospf rfc1583-compatible" commands. */
12766 install_element(OSPF_NODE, &ospf_compatible_rfc1583_cmd);
12767 install_element(OSPF_NODE, &no_ospf_compatible_rfc1583_cmd);
12768 install_element(OSPF_NODE, &ospf_rfc1583_flag_cmd);
12769 install_element(OSPF_NODE, &no_ospf_rfc1583_flag_cmd);
12770
12771 /* "network area" commands. */
12772 install_element(OSPF_NODE, &ospf_network_area_cmd);
12773 install_element(OSPF_NODE, &no_ospf_network_area_cmd);
12774
12775 /* "area authentication" commands. */
12776 install_element(OSPF_NODE,
12777 &ospf_area_authentication_message_digest_cmd);
12778 install_element(OSPF_NODE, &ospf_area_authentication_cmd);
12779 install_element(OSPF_NODE, &no_ospf_area_authentication_cmd);
12780
12781 /* "area range" commands. */
12782 install_element(OSPF_NODE, &ospf_area_range_cmd);
12783 install_element(OSPF_NODE, &ospf_area_range_cost_cmd);
12784 install_element(OSPF_NODE, &ospf_area_range_not_advertise_cmd);
12785 install_element(OSPF_NODE, &no_ospf_area_range_cmd);
12786 install_element(OSPF_NODE, &ospf_area_range_substitute_cmd);
12787 install_element(OSPF_NODE, &no_ospf_area_range_substitute_cmd);
12788
12789 /* "area virtual-link" commands. */
12790 install_element(OSPF_NODE, &ospf_area_vlink_cmd);
12791 install_element(OSPF_NODE, &ospf_area_vlink_intervals_cmd);
12792 install_element(OSPF_NODE, &no_ospf_area_vlink_cmd);
12793 install_element(OSPF_NODE, &no_ospf_area_vlink_intervals_cmd);
12794
12795
12796 /* "area stub" commands. */
12797 install_element(OSPF_NODE, &ospf_area_stub_no_summary_cmd);
12798 install_element(OSPF_NODE, &ospf_area_stub_cmd);
12799 install_element(OSPF_NODE, &no_ospf_area_stub_no_summary_cmd);
12800 install_element(OSPF_NODE, &no_ospf_area_stub_cmd);
12801
12802 /* "area nssa" commands. */
12803 install_element(OSPF_NODE, &ospf_area_nssa_cmd);
12804 install_element(OSPF_NODE, &ospf_area_nssa_translate_cmd);
12805 install_element(OSPF_NODE, &ospf_area_nssa_no_summary_cmd);
12806 install_element(OSPF_NODE, &no_ospf_area_nssa_no_summary_cmd);
12807 install_element(OSPF_NODE, &ospf_area_nssa_suppress_fa_cmd);
12808 install_element(OSPF_NODE, &no_ospf_area_nssa_suppress_fa_cmd);
12809 install_element(OSPF_NODE, &no_ospf_area_nssa_cmd);
12810
12811 install_element(OSPF_NODE, &ospf_area_default_cost_cmd);
12812 install_element(OSPF_NODE, &no_ospf_area_default_cost_cmd);
12813
12814 install_element(OSPF_NODE, &ospf_area_shortcut_cmd);
12815 install_element(OSPF_NODE, &no_ospf_area_shortcut_cmd);
12816
12817 install_element(OSPF_NODE, &ospf_area_export_list_cmd);
12818 install_element(OSPF_NODE, &no_ospf_area_export_list_cmd);
12819
12820 install_element(OSPF_NODE, &ospf_area_filter_list_cmd);
12821 install_element(OSPF_NODE, &no_ospf_area_filter_list_cmd);
12822
12823 install_element(OSPF_NODE, &ospf_area_import_list_cmd);
12824 install_element(OSPF_NODE, &no_ospf_area_import_list_cmd);
12825
12826 /* SPF timer commands */
12827 install_element(OSPF_NODE, &ospf_timers_throttle_spf_cmd);
12828 install_element(OSPF_NODE, &no_ospf_timers_throttle_spf_cmd);
12829
12830 /* LSA timers commands */
12831 install_element(OSPF_NODE, &ospf_timers_min_ls_interval_cmd);
12832 install_element(OSPF_NODE, &no_ospf_timers_min_ls_interval_cmd);
12833 install_element(OSPF_NODE, &ospf_timers_lsa_min_arrival_cmd);
12834 install_element(OSPF_NODE, &no_ospf_timers_lsa_min_arrival_cmd);
12835
12836 /* refresh timer commands */
12837 install_element(OSPF_NODE, &ospf_refresh_timer_cmd);
12838 install_element(OSPF_NODE, &no_ospf_refresh_timer_val_cmd);
12839
12840 /* max-metric commands */
12841 install_element(OSPF_NODE, &ospf_max_metric_router_lsa_admin_cmd);
12842 install_element(OSPF_NODE, &no_ospf_max_metric_router_lsa_admin_cmd);
12843 install_element(OSPF_NODE, &ospf_max_metric_router_lsa_startup_cmd);
12844 install_element(OSPF_NODE, &no_ospf_max_metric_router_lsa_startup_cmd);
12845 install_element(OSPF_NODE, &ospf_max_metric_router_lsa_shutdown_cmd);
12846 install_element(OSPF_NODE, &no_ospf_max_metric_router_lsa_shutdown_cmd);
12847
12848 /* reference bandwidth commands */
12849 install_element(OSPF_NODE, &ospf_auto_cost_reference_bandwidth_cmd);
12850 install_element(OSPF_NODE, &no_ospf_auto_cost_reference_bandwidth_cmd);
12851
12852 /* "neighbor" commands. */
12853 install_element(OSPF_NODE, &ospf_neighbor_cmd);
12854 install_element(OSPF_NODE, &ospf_neighbor_poll_interval_cmd);
12855 install_element(OSPF_NODE, &no_ospf_neighbor_cmd);
12856 install_element(OSPF_NODE, &no_ospf_neighbor_poll_cmd);
12857
12858 /* write multiplier commands */
12859 install_element(OSPF_NODE, &ospf_write_multiplier_cmd);
12860 install_element(OSPF_NODE, &write_multiplier_cmd);
12861 install_element(OSPF_NODE, &no_ospf_write_multiplier_cmd);
12862 install_element(OSPF_NODE, &no_write_multiplier_cmd);
12863
12864 /* "proactive-arp" commands. */
12865 install_element(OSPF_NODE, &ospf_proactive_arp_cmd);
12866 install_element(OSPF_NODE, &no_ospf_proactive_arp_cmd);
12867
12868 /* TI-LFA commands */
12869 install_element(OSPF_NODE, &ospf_ti_lfa_cmd);
12870 install_element(OSPF_NODE, &no_ospf_ti_lfa_cmd);
12871
12872 /* Max path configurations */
12873 install_element(OSPF_NODE, &ospf_max_multipath_cmd);
12874 install_element(OSPF_NODE, &no_ospf_max_multipath_cmd);
12875
12876 /* Init interface related vty commands. */
12877 ospf_vty_if_init();
12878
12879 /* Init zebra related vty commands. */
12880 ospf_vty_zebra_init();
12881 }