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