]> git.proxmox.com Git - mirror_frr.git/blob - ospfd/ospf_vty.c
*: change if_lookup_by_name() api 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,
3745 vrf_lookup_by_id(ospf->vrf_id));
3746 if (ifp == NULL) {
3747 if (use_json)
3748 json_object_boolean_true_add(json_vrf,
3749 "noSuchIface");
3750 else
3751 vty_out(vty, "No such interface name\n");
3752 } else {
3753 if (use_json) {
3754 json_interface_sub = json_object_new_object();
3755 json_interface = json_object_new_object();
3756 }
3757
3758 show_ip_ospf_interface_sub(
3759 vty, ospf, ifp, json_interface_sub, use_json);
3760
3761 if (use_json) {
3762 json_object_object_add(json_interface,
3763 ifp->name,
3764 json_interface_sub);
3765 json_object_object_add(json_vrf, "interfaces",
3766 json_interface);
3767 }
3768 }
3769 }
3770
3771 if (use_json) {
3772 if (use_vrf) {
3773 if (ospf->vrf_id == VRF_DEFAULT)
3774 json_object_object_add(json, "default",
3775 json_vrf);
3776 else
3777 json_object_object_add(json, ospf->name,
3778 json_vrf);
3779 }
3780 } else
3781 vty_out(vty, "\n");
3782
3783 return CMD_SUCCESS;
3784 }
3785
3786 static void show_ip_ospf_interface_traffic_sub(struct vty *vty,
3787 struct ospf_interface *oi,
3788 json_object *json_interface_sub,
3789 bool use_json)
3790 {
3791 if (use_json) {
3792 json_object_int_add(json_interface_sub, "ifIndex",
3793 oi->ifp->ifindex);
3794 json_object_int_add(json_interface_sub, "helloIn",
3795 oi->hello_in);
3796 json_object_int_add(json_interface_sub, "helloOut",
3797 oi->hello_out);
3798 json_object_int_add(json_interface_sub, "dbDescIn",
3799 oi->db_desc_in);
3800 json_object_int_add(json_interface_sub, "dbDescOut",
3801 oi->db_desc_out);
3802 json_object_int_add(json_interface_sub, "lsReqIn",
3803 oi->ls_req_in);
3804 json_object_int_add(json_interface_sub, "lsReqOut",
3805 oi->ls_req_out);
3806 json_object_int_add(json_interface_sub, "lsUpdIn",
3807 oi->ls_upd_in);
3808 json_object_int_add(json_interface_sub, "lsUpdOut",
3809 oi->ls_upd_out);
3810 json_object_int_add(json_interface_sub, "lsAckIn",
3811 oi->ls_ack_in);
3812 json_object_int_add(json_interface_sub, "lsAckOut",
3813 oi->ls_ack_out);
3814 } else {
3815 vty_out(vty,
3816 "%-10s %8u/%-8u %7u/%-7u %7u/%-7u %7u/%-7u %7u/%-7u\n",
3817 oi->ifp->name, oi->hello_in, oi->hello_out,
3818 oi->db_desc_in, oi->db_desc_out, oi->ls_req_in,
3819 oi->ls_req_out, oi->ls_upd_in, oi->ls_upd_out,
3820 oi->ls_ack_in, oi->ls_ack_out);
3821 }
3822 }
3823
3824 /* OSPFv2 Packet Counters */
3825 static int show_ip_ospf_interface_traffic_common(
3826 struct vty *vty, struct ospf *ospf, char *intf_name, json_object *json,
3827 int display_once, uint8_t use_vrf, bool use_json)
3828 {
3829 struct vrf *vrf = NULL;
3830 struct interface *ifp = NULL;
3831 json_object *json_vrf = NULL;
3832 json_object *json_interface_sub = NULL;
3833
3834 if (!use_json && !display_once) {
3835 vty_out(vty, "\n");
3836 vty_out(vty, "%-12s%-17s%-17s%-17s%-17s%-17s\n", "Interface",
3837 " HELLO", " DB-Desc", " LS-Req", " LS-Update",
3838 " LS-Ack");
3839 vty_out(vty, "%-10s%-18s%-18s%-17s%-17s%-17s\n", "",
3840 " Rx/Tx", " Rx/Tx", " Rx/Tx", " Rx/Tx",
3841 " Rx/Tx");
3842 vty_out(vty,
3843 "--------------------------------------------------------------------------------------------\n");
3844 } else if (use_json) {
3845 if (use_vrf)
3846 json_vrf = json_object_new_object();
3847 else
3848 json_vrf = json;
3849 }
3850
3851 ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf);
3852
3853 if (intf_name == NULL) {
3854 vrf = vrf_lookup_by_id(ospf->vrf_id);
3855 FOR_ALL_INTERFACES (vrf, ifp) {
3856 struct route_node *rn;
3857 struct ospf_interface *oi;
3858
3859 if (ospf_oi_count(ifp) == 0)
3860 continue;
3861
3862 for (rn = route_top(IF_OIFS(ifp)); rn;
3863 rn = route_next(rn)) {
3864 oi = rn->info;
3865
3866 if (oi == NULL)
3867 continue;
3868
3869 if (use_json) {
3870 json_interface_sub =
3871 json_object_new_object();
3872 }
3873
3874 show_ip_ospf_interface_traffic_sub(
3875 vty, oi, json_interface_sub, use_json);
3876 if (use_json) {
3877 json_object_object_add(
3878 json_vrf, ifp->name,
3879 json_interface_sub);
3880 }
3881 }
3882 }
3883 } else {
3884 /* Interface name is specified. */
3885 ifp = if_lookup_by_name(intf_name,
3886 vrf_lookup_by_id(ospf->vrf_id));
3887 if (ifp != NULL) {
3888 struct route_node *rn;
3889 struct ospf_interface *oi;
3890
3891 if (ospf_oi_count(ifp) == 0) {
3892 vty_out(vty,
3893 " OSPF not enabled on this interface %s\n",
3894 ifp->name);
3895 return CMD_SUCCESS;
3896 }
3897
3898 for (rn = route_top(IF_OIFS(ifp)); rn;
3899 rn = route_next(rn)) {
3900 oi = rn->info;
3901
3902 if (use_json) {
3903 json_interface_sub =
3904 json_object_new_object();
3905 }
3906
3907 show_ip_ospf_interface_traffic_sub(
3908 vty, oi, json_interface_sub, use_json);
3909 if (use_json) {
3910 json_object_object_add(
3911 json_vrf, ifp->name,
3912 json_interface_sub);
3913 }
3914 }
3915 }
3916 }
3917
3918 if (use_json) {
3919 if (use_vrf) {
3920 if (ospf->vrf_id == VRF_DEFAULT)
3921 json_object_object_add(json, "default",
3922 json_vrf);
3923 else
3924 json_object_object_add(json, ospf->name,
3925 json_vrf);
3926 }
3927 } else
3928 vty_out(vty, "\n");
3929
3930 return CMD_SUCCESS;
3931 }
3932
3933 DEFUN (show_ip_ospf_interface,
3934 show_ip_ospf_interface_cmd,
3935 "show ip ospf [vrf <NAME|all>] interface [INTERFACE] [json]",
3936 SHOW_STR
3937 IP_STR
3938 "OSPF information\n"
3939 VRF_CMD_HELP_STR
3940 "All VRFs\n"
3941 "Interface information\n"
3942 "Interface name\n"
3943 JSON_STR)
3944 {
3945 struct ospf *ospf;
3946 bool uj = use_json(argc, argv);
3947 struct listnode *node = NULL;
3948 char *vrf_name = NULL, *intf_name = NULL;
3949 bool all_vrf = FALSE;
3950 int ret = CMD_SUCCESS;
3951 int inst = 0;
3952 int idx_vrf = 0, idx_intf = 0;
3953 uint8_t use_vrf = 0;
3954 json_object *json = NULL;
3955
3956 OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
3957
3958 if (argv_find(argv, argc, "INTERFACE", &idx_intf))
3959 intf_name = argv[idx_intf]->arg;
3960
3961 if (uj)
3962 json = json_object_new_object();
3963
3964 /* vrf input is provided could be all or specific vrf*/
3965 if (vrf_name) {
3966 use_vrf = 1;
3967 if (all_vrf) {
3968 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
3969 if (!ospf->oi_running)
3970 continue;
3971 ret = show_ip_ospf_interface_common(
3972 vty, ospf, intf_name, use_vrf, json,
3973 uj);
3974 }
3975
3976 if (uj) {
3977 vty_out(vty, "%s\n",
3978 json_object_to_json_string_ext(
3979 json, JSON_C_TO_STRING_PRETTY));
3980 json_object_free(json);
3981 } else if (!ospf)
3982 vty_out(vty, "%% OSPF instance not found\n");
3983
3984 return ret;
3985 }
3986 ospf = ospf_lookup_by_inst_name(inst, vrf_name);
3987 if (ospf == NULL || !ospf->oi_running) {
3988 if (uj) {
3989 vty_out(vty, "%s\n",
3990 json_object_to_json_string_ext(
3991 json, JSON_C_TO_STRING_PRETTY));
3992 json_object_free(json);
3993 } else
3994 vty_out(vty, "%% OSPF instance not found\n");
3995
3996 return CMD_SUCCESS;
3997 }
3998 ret = show_ip_ospf_interface_common(vty, ospf, intf_name,
3999 use_vrf, json, uj);
4000
4001 } else {
4002 /* Display default ospf (instance 0) info */
4003 ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
4004 if (ospf == NULL || !ospf->oi_running) {
4005 if (uj) {
4006 vty_out(vty, "%s\n",
4007 json_object_to_json_string_ext(
4008 json, JSON_C_TO_STRING_PRETTY));
4009 json_object_free(json);
4010 } else
4011 vty_out(vty, "%% OSPF instance not found\n");
4012
4013 return CMD_SUCCESS;
4014 }
4015 ret = show_ip_ospf_interface_common(vty, ospf, intf_name,
4016 use_vrf, json, uj);
4017 }
4018
4019 if (uj) {
4020 vty_out(vty, "%s\n", json_object_to_json_string_ext(
4021 json, JSON_C_TO_STRING_PRETTY));
4022 json_object_free(json);
4023 }
4024
4025 return ret;
4026 }
4027
4028 DEFUN (show_ip_ospf_instance_interface,
4029 show_ip_ospf_instance_interface_cmd,
4030 "show ip ospf (1-65535) interface [INTERFACE] [json]",
4031 SHOW_STR
4032 IP_STR
4033 "OSPF information\n"
4034 "Instance ID\n"
4035 "Interface information\n"
4036 "Interface name\n"
4037 JSON_STR)
4038 {
4039 int idx_number = 3;
4040 int idx_intf = 0;
4041 struct ospf *ospf;
4042 unsigned short instance = 0;
4043 bool uj = use_json(argc, argv);
4044 char *intf_name = NULL;
4045 int ret = CMD_SUCCESS;
4046 json_object *json = NULL;
4047
4048 instance = strtoul(argv[idx_number]->arg, NULL, 10);
4049 ospf = ospf_lookup_instance(instance);
4050 if (ospf == NULL)
4051 return CMD_NOT_MY_INSTANCE;
4052
4053 if (!ospf->oi_running)
4054 return CMD_SUCCESS;
4055
4056 if (uj)
4057 json = json_object_new_object();
4058
4059 if (argv_find(argv, argc, "INTERFACE", &idx_intf))
4060 intf_name = argv[idx_intf]->arg;
4061
4062 ret = show_ip_ospf_interface_common(vty, ospf, intf_name, 0, json, uj);
4063
4064 if (uj) {
4065 vty_out(vty, "%s\n", json_object_to_json_string_ext(
4066 json, JSON_C_TO_STRING_PRETTY));
4067 json_object_free(json);
4068 }
4069
4070 return ret;
4071 }
4072
4073 DEFUN (show_ip_ospf_interface_traffic,
4074 show_ip_ospf_interface_traffic_cmd,
4075 "show ip ospf [vrf <NAME|all>] interface traffic [INTERFACE] [json]",
4076 SHOW_STR
4077 IP_STR
4078 "OSPF information\n"
4079 VRF_CMD_HELP_STR
4080 "All VRFs\n"
4081 "Interface information\n"
4082 "Protocol Packet counters\n"
4083 "Interface name\n"
4084 JSON_STR)
4085 {
4086 struct ospf *ospf = NULL;
4087 struct listnode *node = NULL;
4088 char *vrf_name = NULL, *intf_name = NULL;
4089 bool all_vrf = FALSE;
4090 int inst = 0;
4091 int idx_vrf = 0, idx_intf = 0;
4092 bool uj = use_json(argc, argv);
4093 json_object *json = NULL;
4094 int ret = CMD_SUCCESS;
4095 int display_once = 0;
4096 uint8_t use_vrf = 0;
4097
4098 OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
4099
4100 if (argv_find(argv, argc, "INTERFACE", &idx_intf))
4101 intf_name = argv[idx_intf]->arg;
4102
4103 if (uj)
4104 json = json_object_new_object();
4105
4106 if (vrf_name) {
4107 use_vrf = 1;
4108 if (all_vrf) {
4109 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
4110 if (!ospf->oi_running)
4111 continue;
4112
4113 ret = show_ip_ospf_interface_traffic_common(
4114 vty, ospf, intf_name, json,
4115 display_once, use_vrf, uj);
4116 display_once = 1;
4117 }
4118
4119 if (uj) {
4120 vty_out(vty, "%s\n",
4121 json_object_to_json_string_ext(
4122 json, JSON_C_TO_STRING_PRETTY));
4123 json_object_free(json);
4124 }
4125
4126 return ret;
4127 }
4128 ospf = ospf_lookup_by_inst_name(inst, vrf_name);
4129 if (ospf == NULL || !ospf->oi_running) {
4130 if (uj)
4131 json_object_free(json);
4132 return CMD_SUCCESS;
4133 }
4134
4135 ret = show_ip_ospf_interface_traffic_common(
4136 vty, ospf, intf_name, json, display_once, use_vrf, uj);
4137 } else {
4138 ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
4139 if (ospf == NULL || !ospf->oi_running) {
4140 if (uj)
4141 json_object_free(json);
4142 return CMD_SUCCESS;
4143 }
4144
4145 ret = show_ip_ospf_interface_traffic_common(
4146 vty, ospf, intf_name, json, display_once, use_vrf, uj);
4147 }
4148
4149 if (uj) {
4150 vty_out(vty, "%s\n", json_object_to_json_string_ext(
4151 json, JSON_C_TO_STRING_PRETTY));
4152 json_object_free(json);
4153 }
4154
4155 return ret;
4156 }
4157
4158
4159 static void show_ip_ospf_neighbour_header(struct vty *vty)
4160 {
4161 vty_out(vty, "\n%-15s %3s %-15s %9s %-15s %-20s %5s %5s %5s\n",
4162 "Neighbor ID", "Pri", "State", "Dead Time", "Address",
4163 "Interface", "RXmtL", "RqstL", "DBsmL");
4164 }
4165
4166 static void show_ip_ospf_neighbor_sub(struct vty *vty,
4167 struct ospf_interface *oi,
4168 json_object *json, bool use_json)
4169 {
4170 struct route_node *rn;
4171 struct ospf_neighbor *nbr, *prev_nbr = NULL;
4172 char msgbuf[16];
4173 char timebuf[OSPF_TIME_DUMP_SIZE];
4174 json_object *json_neighbor = NULL, *json_neigh_array = NULL;
4175
4176 for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) {
4177 if ((nbr = rn->info)) {
4178 /* Do not show myself. */
4179 if (nbr == oi->nbr_self)
4180 continue;
4181 /* Down state is not shown. */
4182 if (nbr->state == NSM_Down)
4183 continue;
4184 if (use_json) {
4185 char neigh_str[INET_ADDRSTRLEN];
4186
4187 if (prev_nbr
4188 && !IPV4_ADDR_SAME(&prev_nbr->src,
4189 &nbr->src)) {
4190 /* Start new neigh list */
4191 json_neigh_array = NULL;
4192 }
4193
4194 if (nbr->state == NSM_Attempt
4195 && nbr->router_id.s_addr == 0)
4196 strlcpy(neigh_str, "neighbor",
4197 sizeof(neigh_str));
4198 else
4199 strlcpy(neigh_str,
4200 inet_ntoa(nbr->router_id),
4201 sizeof(neigh_str));
4202
4203 json_object_object_get_ex(json, neigh_str,
4204 &json_neigh_array);
4205
4206 if (!json_neigh_array) {
4207 json_neigh_array =
4208 json_object_new_array();
4209 json_object_object_add(
4210 json, neigh_str,
4211 json_neigh_array);
4212 }
4213
4214 json_neighbor = json_object_new_object();
4215
4216 ospf_nbr_state_message(nbr, msgbuf, 16);
4217
4218 long time_store;
4219
4220 time_store =
4221 monotime_until(
4222 &nbr->t_inactivity->u.sands,
4223 NULL)
4224 / 1000LL;
4225
4226 json_object_int_add(json_neighbor, "priority",
4227 nbr->priority);
4228 json_object_string_add(json_neighbor, "state",
4229 msgbuf);
4230 json_object_int_add(json_neighbor,
4231 "deadTimeMsecs",
4232 time_store);
4233 json_object_string_add(json_neighbor, "address",
4234 inet_ntoa(nbr->src));
4235 json_object_string_add(json_neighbor,
4236 "ifaceName",
4237 IF_NAME(oi));
4238 json_object_int_add(
4239 json_neighbor, "retransmitCounter",
4240 ospf_ls_retransmit_count(nbr));
4241 json_object_int_add(json_neighbor,
4242 "requestCounter",
4243 ospf_ls_request_count(nbr));
4244 json_object_int_add(json_neighbor,
4245 "dbSummaryCounter",
4246 ospf_db_summary_count(nbr));
4247
4248 json_object_array_add(json_neigh_array,
4249 json_neighbor);
4250 } else {
4251 ospf_nbr_state_message(nbr, msgbuf, 16);
4252
4253 if (nbr->state == NSM_Attempt
4254 && nbr->router_id.s_addr == 0)
4255 vty_out(vty, "%-15s %3d %-15s ", "-",
4256 nbr->priority, msgbuf);
4257 else
4258 vty_out(vty, "%-15s %3d %-15s ",
4259 inet_ntoa(nbr->router_id),
4260 nbr->priority, msgbuf);
4261
4262 vty_out(vty, "%9s ",
4263 ospf_timer_dump(nbr->t_inactivity,
4264 timebuf,
4265 sizeof(timebuf)));
4266 vty_out(vty, "%-15s ", inet_ntoa(nbr->src));
4267 vty_out(vty, "%-20s %5ld %5ld %5d\n",
4268 IF_NAME(oi),
4269 ospf_ls_retransmit_count(nbr),
4270 ospf_ls_request_count(nbr),
4271 ospf_db_summary_count(nbr));
4272 }
4273 prev_nbr = nbr;
4274 }
4275 }
4276 }
4277
4278 static int show_ip_ospf_neighbor_common(struct vty *vty, struct ospf *ospf,
4279 json_object *json, bool use_json,
4280 uint8_t use_vrf)
4281 {
4282 struct ospf_interface *oi;
4283 struct listnode *node;
4284 json_object *json_vrf = NULL;
4285 json_object *json_nbr_sub = NULL;
4286
4287 if (use_json) {
4288 if (use_vrf)
4289 json_vrf = json_object_new_object();
4290 else
4291 json_vrf = json;
4292 json_nbr_sub = json_object_new_object();
4293 }
4294
4295 if (ospf->instance) {
4296 if (use_json)
4297 json_object_int_add(json, "ospfInstance",
4298 ospf->instance);
4299 else
4300 vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
4301 }
4302
4303 ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf);
4304 if (!use_json)
4305 show_ip_ospf_neighbour_header(vty);
4306
4307 for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) {
4308 if (ospf_interface_neighbor_count(oi) == 0)
4309 continue;
4310 show_ip_ospf_neighbor_sub(vty, oi, json_nbr_sub, use_json);
4311 }
4312
4313 if (use_json) {
4314 json_object_object_add(json_vrf, "neighbors", json_nbr_sub);
4315 if (use_vrf) {
4316 if (ospf->vrf_id == VRF_DEFAULT)
4317 json_object_object_add(json, "default",
4318 json_vrf);
4319 else
4320 json_object_object_add(json, ospf->name,
4321 json_vrf);
4322 }
4323 } else
4324 vty_out(vty, "\n");
4325
4326 return CMD_SUCCESS;
4327 }
4328
4329 DEFUN (show_ip_ospf_neighbor,
4330 show_ip_ospf_neighbor_cmd,
4331 "show ip ospf [vrf <NAME|all>] neighbor [json]",
4332 SHOW_STR
4333 IP_STR
4334 "OSPF information\n"
4335 VRF_CMD_HELP_STR
4336 "All VRFs\n"
4337 "Neighbor list\n"
4338 JSON_STR)
4339 {
4340 struct ospf *ospf;
4341 bool uj = use_json(argc, argv);
4342 struct listnode *node = NULL;
4343 char *vrf_name = NULL;
4344 bool all_vrf = FALSE;
4345 int ret = CMD_SUCCESS;
4346 int inst = 0;
4347 int idx_vrf = 0;
4348 uint8_t use_vrf = 0;
4349 json_object *json = NULL;
4350
4351 OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
4352
4353 if (uj)
4354 json = json_object_new_object();
4355
4356 /* vrf input is provided could be all or specific vrf*/
4357 if (vrf_name) {
4358 use_vrf = 1;
4359 if (all_vrf) {
4360 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
4361 if (!ospf->oi_running)
4362 continue;
4363 ret = show_ip_ospf_neighbor_common(
4364 vty, ospf, json, uj, use_vrf);
4365 }
4366
4367 if (uj) {
4368 vty_out(vty, "%s\n",
4369 json_object_to_json_string_ext(
4370 json, JSON_C_TO_STRING_PRETTY));
4371 json_object_free(json);
4372 } else if (!ospf)
4373 vty_out(vty, "OSPF instance not found\n");
4374
4375 return ret;
4376 }
4377
4378 ospf = ospf_lookup_by_inst_name(inst, vrf_name);
4379 if (ospf == NULL || !ospf->oi_running) {
4380 if (uj) {
4381 vty_out(vty, "%s\n",
4382 json_object_to_json_string_ext(
4383 json, JSON_C_TO_STRING_PRETTY));
4384 json_object_free(json);
4385 } else
4386 vty_out(vty, "%% OSPF instance not found\n");
4387
4388 return CMD_SUCCESS;
4389 }
4390 } else {
4391 /* Display default ospf (instance 0) info */
4392 ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
4393 if (ospf == NULL || !ospf->oi_running) {
4394 if (uj) {
4395 vty_out(vty, "%s\n",
4396 json_object_to_json_string_ext(
4397 json, JSON_C_TO_STRING_PRETTY));
4398 json_object_free(json);
4399 } else
4400 vty_out(vty, "%% OSPF instance not found\n");
4401
4402 return CMD_SUCCESS;
4403 }
4404 }
4405
4406 if (ospf) {
4407 ret = show_ip_ospf_neighbor_common(vty, ospf, json, uj,
4408 use_vrf);
4409
4410 if (uj) {
4411 vty_out(vty, "%s\n",
4412 json_object_to_json_string_ext(
4413 json, JSON_C_TO_STRING_PRETTY));
4414 }
4415 }
4416
4417 if (uj)
4418 json_object_free(json);
4419
4420 return ret;
4421 }
4422
4423
4424 DEFUN (show_ip_ospf_instance_neighbor,
4425 show_ip_ospf_instance_neighbor_cmd,
4426 "show ip ospf (1-65535) neighbor [json]",
4427 SHOW_STR
4428 IP_STR
4429 "OSPF information\n"
4430 "Instance ID\n"
4431 "Neighbor list\n"
4432 JSON_STR)
4433 {
4434 int idx_number = 3;
4435 struct ospf *ospf;
4436 unsigned short instance = 0;
4437 bool uj = use_json(argc, argv);
4438 json_object *json = NULL;
4439 int ret = CMD_SUCCESS;
4440
4441 instance = strtoul(argv[idx_number]->arg, NULL, 10);
4442 ospf = ospf_lookup_instance(instance);
4443 if (ospf == NULL)
4444 return CMD_NOT_MY_INSTANCE;
4445
4446 if (!ospf->oi_running)
4447 return CMD_SUCCESS;
4448
4449 if (uj)
4450 json = json_object_new_object();
4451
4452 ret = show_ip_ospf_neighbor_common(vty, ospf, json, uj, 0);
4453
4454 if (uj) {
4455 vty_out(vty, "%s\n", json_object_to_json_string_ext(
4456 json, JSON_C_TO_STRING_PRETTY));
4457 json_object_free(json);
4458 }
4459
4460 return ret;
4461 }
4462
4463 static int show_ip_ospf_neighbor_all_common(struct vty *vty, struct ospf *ospf,
4464 json_object *json, bool use_json,
4465 uint8_t use_vrf)
4466 {
4467 struct listnode *node;
4468 struct ospf_interface *oi;
4469 json_object *json_vrf = NULL;
4470 json_object *json_neighbor_sub = NULL;
4471
4472 if (use_json) {
4473 if (use_vrf)
4474 json_vrf = json_object_new_object();
4475 else
4476 json_vrf = json;
4477 json_neighbor_sub = json_object_new_object();
4478 }
4479
4480 ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf);
4481 if (!use_json)
4482 show_ip_ospf_neighbour_header(vty);
4483
4484 if (ospf->instance) {
4485 if (use_json)
4486 json_object_int_add(json_vrf, "ospfInstance",
4487 ospf->instance);
4488 else
4489 vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
4490 }
4491
4492 for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) {
4493 struct listnode *nbr_node;
4494 struct ospf_nbr_nbma *nbr_nbma;
4495
4496 show_ip_ospf_neighbor_sub(vty, oi, json_vrf, use_json);
4497
4498 /* print Down neighbor status */
4499 for (ALL_LIST_ELEMENTS_RO(oi->nbr_nbma, nbr_node, nbr_nbma)) {
4500 if (nbr_nbma->nbr == NULL
4501 || nbr_nbma->nbr->state == NSM_Down) {
4502 if (use_json) {
4503 json_object_int_add(json_neighbor_sub,
4504 "nbrNbmaPriority",
4505 nbr_nbma->priority);
4506 json_object_boolean_true_add(
4507 json_neighbor_sub,
4508 "nbrNbmaDown");
4509 json_object_string_add(
4510 json_neighbor_sub,
4511 "nbrNbmaIfaceName",
4512 IF_NAME(oi));
4513 json_object_int_add(
4514 json_neighbor_sub,
4515 "nbrNbmaRetransmitCounter", 0);
4516 json_object_int_add(
4517 json_neighbor_sub,
4518 "nbrNbmaRequestCounter", 0);
4519 json_object_int_add(
4520 json_neighbor_sub,
4521 "nbrNbmaDbSummaryCounter", 0);
4522 json_object_object_add(
4523 json_vrf,
4524 inet_ntoa(nbr_nbma->addr),
4525 json_neighbor_sub);
4526 } else {
4527 vty_out(vty, "%-15s %3d %-15s %9s ",
4528 "-", nbr_nbma->priority, "Down",
4529 "-");
4530 vty_out(vty,
4531 "%-15s %-20s %5d %5d %5d\n",
4532 inet_ntoa(nbr_nbma->addr),
4533 IF_NAME(oi), 0, 0, 0);
4534 }
4535 }
4536 }
4537 }
4538
4539 if (use_json) {
4540 if (use_vrf) {
4541 if (ospf->vrf_id == VRF_DEFAULT)
4542 json_object_object_add(json, "default",
4543 json_vrf);
4544 else
4545 json_object_object_add(json, ospf->name,
4546 json_vrf);
4547 }
4548 } else
4549 vty_out(vty, "\n");
4550
4551 return CMD_SUCCESS;
4552 }
4553
4554 DEFUN (show_ip_ospf_neighbor_all,
4555 show_ip_ospf_neighbor_all_cmd,
4556 "show ip ospf [vrf <NAME|all>] neighbor all [json]",
4557 SHOW_STR
4558 IP_STR
4559 "OSPF information\n"
4560 VRF_CMD_HELP_STR
4561 "All VRFs\n"
4562 "Neighbor list\n"
4563 "include down status neighbor\n"
4564 JSON_STR)
4565 {
4566 struct ospf *ospf;
4567 bool uj = use_json(argc, argv);
4568 struct listnode *node = NULL;
4569 char *vrf_name = NULL;
4570 bool all_vrf = FALSE;
4571 int ret = CMD_SUCCESS;
4572 int inst = 0;
4573 int idx_vrf = 0;
4574 uint8_t use_vrf = 0;
4575 json_object *json = NULL;
4576
4577 OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
4578
4579 if (uj)
4580 json = json_object_new_object();
4581
4582 /* vrf input is provided could be all or specific vrf*/
4583 if (vrf_name) {
4584 use_vrf = 1;
4585 if (all_vrf) {
4586 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
4587 if (!ospf->oi_running)
4588 continue;
4589 ret = show_ip_ospf_neighbor_all_common(
4590 vty, ospf, json, uj, use_vrf);
4591 }
4592
4593 if (uj) {
4594 vty_out(vty, "%s\n",
4595 json_object_to_json_string_ext(
4596 json, JSON_C_TO_STRING_PRETTY));
4597 json_object_free(json);
4598 }
4599
4600 return ret;
4601 }
4602
4603 ospf = ospf_lookup_by_inst_name(inst, vrf_name);
4604 if (ospf == NULL || !ospf->oi_running) {
4605 if (uj)
4606 json_object_free(json);
4607 return CMD_SUCCESS;
4608 }
4609 } else {
4610 /* Display default ospf (instance 0) info */
4611 ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
4612 if (ospf == NULL || !ospf->oi_running) {
4613 if (uj)
4614 json_object_free(json);
4615 return CMD_SUCCESS;
4616 }
4617 }
4618
4619 if (ospf) {
4620 ret = show_ip_ospf_neighbor_all_common(vty, ospf, json, uj,
4621 use_vrf);
4622 if (uj) {
4623 vty_out(vty, "%s\n",
4624 json_object_to_json_string_ext(
4625 json, JSON_C_TO_STRING_PRETTY));
4626 }
4627 }
4628
4629 if (uj)
4630 json_object_free(json);
4631
4632 return ret;
4633 }
4634
4635 DEFUN (show_ip_ospf_instance_neighbor_all,
4636 show_ip_ospf_instance_neighbor_all_cmd,
4637 "show ip ospf (1-65535) neighbor all [json]",
4638 SHOW_STR
4639 IP_STR
4640 "OSPF information\n"
4641 "Instance ID\n"
4642 "Neighbor list\n"
4643 "include down status neighbor\n"
4644 JSON_STR)
4645 {
4646 int idx_number = 3;
4647 struct ospf *ospf;
4648 unsigned short instance = 0;
4649 bool uj = use_json(argc, argv);
4650 json_object *json = NULL;
4651 int ret = CMD_SUCCESS;
4652
4653 instance = strtoul(argv[idx_number]->arg, NULL, 10);
4654 ospf = ospf_lookup_instance(instance);
4655 if (ospf == NULL)
4656 return CMD_NOT_MY_INSTANCE;
4657
4658 if (!ospf->oi_running)
4659 return CMD_SUCCESS;
4660 if (uj)
4661 json = json_object_new_object();
4662
4663 ret = show_ip_ospf_neighbor_all_common(vty, ospf, json, uj, 0);
4664
4665 if (uj) {
4666 vty_out(vty, "%s\n", json_object_to_json_string_ext(
4667 json, JSON_C_TO_STRING_PRETTY));
4668 json_object_free(json);
4669 }
4670
4671 return ret;
4672 }
4673
4674 static int show_ip_ospf_neighbor_int_common(struct vty *vty, struct ospf *ospf,
4675 int arg_base,
4676 struct cmd_token **argv,
4677 bool use_json, uint8_t use_vrf)
4678 {
4679 struct interface *ifp;
4680 struct route_node *rn;
4681 json_object *json = NULL;
4682
4683 if (use_json)
4684 json = json_object_new_object();
4685
4686 if (ospf->instance) {
4687 if (use_json)
4688 json_object_int_add(json, "ospfInstance",
4689 ospf->instance);
4690 else
4691 vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
4692 }
4693
4694 ospf_show_vrf_name(ospf, vty, json, use_vrf);
4695
4696 ifp = if_lookup_by_name(argv[arg_base]->arg,
4697 vrf_lookup_by_id(ospf->vrf_id));
4698 if (!ifp) {
4699 if (use_json)
4700 json_object_boolean_true_add(json, "noSuchIface");
4701 else
4702 vty_out(vty, "No such interface.\n");
4703 return CMD_WARNING;
4704 }
4705
4706 for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) {
4707 struct ospf_interface *oi = rn->info;
4708
4709 if (oi == NULL)
4710 continue;
4711
4712 show_ip_ospf_neighbor_sub(vty, oi, json, use_json);
4713 }
4714
4715 if (use_json) {
4716 vty_out(vty, "%s\n", json_object_to_json_string_ext(
4717 json, JSON_C_TO_STRING_PRETTY));
4718 json_object_free(json);
4719 } else
4720 vty_out(vty, "\n");
4721
4722 return CMD_SUCCESS;
4723 }
4724
4725 DEFUN (show_ip_ospf_neighbor_int,
4726 show_ip_ospf_neighbor_int_cmd,
4727 "show ip ospf [vrf <NAME>] neighbor IFNAME [json]",
4728 SHOW_STR
4729 IP_STR
4730 "OSPF information\n"
4731 VRF_CMD_HELP_STR
4732 "Neighbor list\n"
4733 "Interface name\n"
4734 JSON_STR)
4735 {
4736 struct ospf *ospf;
4737 int idx_ifname = 0;
4738 int idx_vrf = 0;
4739 bool uj = use_json(argc, argv);
4740 int ret = CMD_SUCCESS;
4741 struct interface *ifp = NULL;
4742 char *vrf_name = NULL;
4743 vrf_id_t vrf_id = VRF_DEFAULT;
4744 struct vrf *vrf = NULL;
4745
4746 if (argv_find(argv, argc, "vrf", &idx_vrf))
4747 vrf_name = argv[idx_vrf + 1]->arg;
4748 if (vrf_name && strmatch(vrf_name, VRF_DEFAULT_NAME))
4749 vrf_name = NULL;
4750 if (vrf_name) {
4751 vrf = vrf_lookup_by_name(vrf_name);
4752 if (vrf)
4753 vrf_id = vrf->vrf_id;
4754 }
4755 ospf = ospf_lookup_by_vrf_id(vrf_id);
4756
4757 if (!ospf || !ospf->oi_running)
4758 return ret;
4759
4760 if (!uj)
4761 show_ip_ospf_neighbour_header(vty);
4762
4763 argv_find(argv, argc, "IFNAME", &idx_ifname);
4764
4765 ifp = if_lookup_by_name(argv[idx_ifname]->arg,
4766 vrf_lookup_by_id(vrf_id));
4767 if (!ifp)
4768 return ret;
4769
4770 ret = show_ip_ospf_neighbor_int_common(vty, ospf, idx_ifname,
4771 argv, uj, 0);
4772 return ret;
4773 }
4774
4775 DEFUN (show_ip_ospf_instance_neighbor_int,
4776 show_ip_ospf_instance_neighbor_int_cmd,
4777 "show ip ospf (1-65535) neighbor IFNAME [json]",
4778 SHOW_STR
4779 IP_STR
4780 "OSPF information\n"
4781 "Instance ID\n"
4782 "Neighbor list\n"
4783 "Interface name\n"
4784 JSON_STR)
4785 {
4786 int idx_number = 3;
4787 int idx_ifname = 5;
4788 struct ospf *ospf;
4789 unsigned short instance = 0;
4790 bool uj = use_json(argc, argv);
4791
4792 if (!uj)
4793 show_ip_ospf_neighbour_header(vty);
4794
4795 instance = strtoul(argv[idx_number]->arg, NULL, 10);
4796 ospf = ospf_lookup_instance(instance);
4797 if (ospf == NULL)
4798 return CMD_NOT_MY_INSTANCE;
4799
4800 if (!ospf->oi_running)
4801 return CMD_SUCCESS;
4802
4803 if (!uj)
4804 show_ip_ospf_neighbour_header(vty);
4805
4806 return show_ip_ospf_neighbor_int_common(vty, ospf, idx_ifname, argv, uj,
4807 0);
4808 }
4809
4810 static void show_ip_ospf_nbr_nbma_detail_sub(struct vty *vty,
4811 struct ospf_interface *oi,
4812 struct ospf_nbr_nbma *nbr_nbma,
4813 bool use_json, json_object *json)
4814 {
4815 char timebuf[OSPF_TIME_DUMP_SIZE];
4816 json_object *json_sub = NULL;
4817
4818 if (use_json)
4819 json_sub = json_object_new_object();
4820 else /* Show neighbor ID. */
4821 vty_out(vty, " Neighbor %s,", "-");
4822
4823 /* Show interface address. */
4824 if (use_json)
4825 json_object_string_add(json_sub, "ifaceAddress",
4826 inet_ntoa(nbr_nbma->addr));
4827 else
4828 vty_out(vty, " interface address %s\n",
4829 inet_ntoa(nbr_nbma->addr));
4830
4831 /* Show Area ID. */
4832 if (use_json) {
4833 json_object_string_add(json_sub, "areaId",
4834 ospf_area_desc_string(oi->area));
4835 json_object_string_add(json_sub, "iface", IF_NAME(oi));
4836 } else
4837 vty_out(vty, " In the area %s via interface %s\n",
4838 ospf_area_desc_string(oi->area), IF_NAME(oi));
4839
4840 /* Show neighbor priority and state. */
4841 if (use_json) {
4842 json_object_int_add(json_sub, "nbrPriority",
4843 nbr_nbma->priority);
4844 json_object_string_add(json_sub, "nbrState", "down");
4845 } else
4846 vty_out(vty, " Neighbor priority is %d, State is %s,",
4847 nbr_nbma->priority, "Down");
4848
4849 /* Show state changes. */
4850 if (use_json)
4851 json_object_int_add(json_sub, "stateChangeCounter",
4852 nbr_nbma->state_change);
4853 else
4854 vty_out(vty, " %d state changes\n", nbr_nbma->state_change);
4855
4856 /* Show PollInterval */
4857 if (use_json)
4858 json_object_int_add(json_sub, "pollInterval", nbr_nbma->v_poll);
4859 else
4860 vty_out(vty, " Poll interval %d\n", nbr_nbma->v_poll);
4861
4862 /* Show poll-interval timer. */
4863 if (nbr_nbma->t_poll) {
4864 if (use_json) {
4865 long time_store;
4866 time_store = monotime_until(&nbr_nbma->t_poll->u.sands,
4867 NULL) / 1000LL;
4868 json_object_int_add(json_sub,
4869 "pollIntervalTimerDueMsec",
4870 time_store);
4871 } else
4872 vty_out(vty, " Poll timer due in %s\n",
4873 ospf_timer_dump(nbr_nbma->t_poll, timebuf,
4874 sizeof(timebuf)));
4875 }
4876
4877 /* Show poll-interval timer thread. */
4878 if (use_json) {
4879 if (nbr_nbma->t_poll != NULL)
4880 json_object_string_add(json_sub,
4881 "pollIntervalTimerThread", "on");
4882 } else
4883 vty_out(vty, " Thread Poll Timer %s\n",
4884 nbr_nbma->t_poll != NULL ? "on" : "off");
4885
4886 if (use_json)
4887 json_object_object_add(json, "noNbrId", json_sub);
4888 }
4889
4890 static void show_ip_ospf_neighbor_detail_sub(struct vty *vty,
4891 struct ospf_interface *oi,
4892 struct ospf_neighbor *nbr,
4893 json_object *json, bool use_json)
4894 {
4895 char timebuf[OSPF_TIME_DUMP_SIZE];
4896 json_object *json_sub = NULL;
4897
4898 if (use_json)
4899 json_sub = json_object_new_object();
4900 else {
4901 /* Show neighbor ID. */
4902 if (nbr->state == NSM_Attempt && nbr->router_id.s_addr == 0)
4903 vty_out(vty, " Neighbor %s,", "-");
4904 else
4905 vty_out(vty, " Neighbor %s,",
4906 inet_ntoa(nbr->router_id));
4907 }
4908
4909 /* Show interface address. */
4910 if (use_json)
4911 json_object_string_add(json_sub, "ifaceAddress",
4912 inet_ntoa(nbr->address.u.prefix4));
4913 else
4914 vty_out(vty, " interface address %s\n",
4915 inet_ntoa(nbr->address.u.prefix4));
4916
4917 /* Show Area ID. */
4918 if (use_json) {
4919 json_object_string_add(json_sub, "areaId",
4920 ospf_area_desc_string(oi->area));
4921 json_object_string_add(json_sub, "ifaceName", oi->ifp->name);
4922 } else
4923 vty_out(vty, " In the area %s via interface %s\n",
4924 ospf_area_desc_string(oi->area), oi->ifp->name);
4925
4926 /* Show neighbor priority and state. */
4927 if (use_json) {
4928 json_object_int_add(json_sub, "nbrPriority", nbr->priority);
4929 json_object_string_add(
4930 json_sub, "nbrState",
4931 lookup_msg(ospf_nsm_state_msg, nbr->state, NULL));
4932 } else
4933 vty_out(vty, " Neighbor priority is %d, State is %s,",
4934 nbr->priority,
4935 lookup_msg(ospf_nsm_state_msg, nbr->state, NULL));
4936
4937 /* Show state changes. */
4938 if (use_json)
4939 json_object_int_add(json_sub, "stateChangeCounter",
4940 nbr->state_change);
4941 else
4942 vty_out(vty, " %d state changes\n", nbr->state_change);
4943
4944 if (nbr->ts_last_progress.tv_sec || nbr->ts_last_progress.tv_usec) {
4945 struct timeval res;
4946 long time_store;
4947
4948 time_store =
4949 monotime_since(&nbr->ts_last_progress, &res) / 1000LL;
4950 if (use_json) {
4951 json_object_int_add(json_sub, "lastPrgrsvChangeMsec",
4952 time_store);
4953 } else {
4954 vty_out(vty,
4955 " Most recent state change statistics:\n");
4956 vty_out(vty, " Progressive change %s ago\n",
4957 ospf_timeval_dump(&res, timebuf,
4958 sizeof(timebuf)));
4959 }
4960 }
4961
4962 if (nbr->ts_last_regress.tv_sec || nbr->ts_last_regress.tv_usec) {
4963 struct timeval res;
4964 long time_store;
4965
4966 time_store =
4967 monotime_since(&nbr->ts_last_regress, &res) / 1000LL;
4968 if (use_json) {
4969 json_object_int_add(json_sub,
4970 "lastRegressiveChangeMsec",
4971 time_store);
4972 if (nbr->last_regress_str)
4973 json_object_string_add(
4974 json_sub, "lastRegressiveChangeReason",
4975 nbr->last_regress_str);
4976 } else {
4977 vty_out(vty,
4978 " Regressive change %s ago, due to %s\n",
4979 ospf_timeval_dump(&res, timebuf,
4980 sizeof(timebuf)),
4981 (nbr->last_regress_str ? nbr->last_regress_str
4982 : "??"));
4983 }
4984 }
4985
4986 /* Show Designated Rotuer ID. */
4987 if (use_json)
4988 json_object_string_add(json_sub, "routerDesignatedId",
4989 inet_ntoa(nbr->d_router));
4990 else
4991 vty_out(vty, " DR is %s,", inet_ntoa(nbr->d_router));
4992
4993 /* Show Backup Designated Rotuer ID. */
4994 if (use_json)
4995 json_object_string_add(json_sub, "routerDesignatedBackupId",
4996 inet_ntoa(nbr->bd_router));
4997 else
4998 vty_out(vty, " BDR is %s\n", inet_ntoa(nbr->bd_router));
4999
5000 /* Show options. */
5001 if (use_json) {
5002 json_object_int_add(json_sub, "optionsCounter", nbr->options);
5003 json_object_string_add(json_sub, "optionsList",
5004 ospf_options_dump(nbr->options));
5005 } else
5006 vty_out(vty, " Options %d %s\n", nbr->options,
5007 ospf_options_dump(nbr->options));
5008
5009 /* Show Router Dead interval timer. */
5010 if (use_json) {
5011 if (nbr->t_inactivity) {
5012 long time_store;
5013 time_store = monotime_until(&nbr->t_inactivity->u.sands,
5014 NULL)
5015 / 1000LL;
5016 json_object_int_add(json_sub,
5017 "routerDeadIntervalTimerDueMsec",
5018 time_store);
5019 } else
5020 json_object_int_add(
5021 json_sub, "routerDeadIntervalTimerDueMsec", -1);
5022 } else
5023 vty_out(vty, " Dead timer due in %s\n",
5024 ospf_timer_dump(nbr->t_inactivity, timebuf,
5025 sizeof(timebuf)));
5026
5027 /* Show Database Summary list. */
5028 if (use_json)
5029 json_object_int_add(json_sub, "databaseSummaryListCounter",
5030 ospf_db_summary_count(nbr));
5031 else
5032 vty_out(vty, " Database Summary List %d\n",
5033 ospf_db_summary_count(nbr));
5034
5035 /* Show Link State Request list. */
5036 if (use_json)
5037 json_object_int_add(json_sub, "linkStateRequestListCounter",
5038 ospf_ls_request_count(nbr));
5039 else
5040 vty_out(vty, " Link State Request List %ld\n",
5041 ospf_ls_request_count(nbr));
5042
5043 /* Show Link State Retransmission list. */
5044 if (use_json)
5045 json_object_int_add(json_sub,
5046 "linkStateRetransmissionListCounter",
5047 ospf_ls_retransmit_count(nbr));
5048 else
5049 vty_out(vty, " Link State Retransmission List %ld\n",
5050 ospf_ls_retransmit_count(nbr));
5051
5052 /* Show inactivity timer thread. */
5053 if (use_json) {
5054 if (nbr->t_inactivity != NULL)
5055 json_object_string_add(json_sub,
5056 "threadInactivityTimer", "on");
5057 } else
5058 vty_out(vty, " Thread Inactivity Timer %s\n",
5059 nbr->t_inactivity != NULL ? "on" : "off");
5060
5061 /* Show Database Description retransmission thread. */
5062 if (use_json) {
5063 if (nbr->t_db_desc != NULL)
5064 json_object_string_add(
5065 json_sub,
5066 "threadDatabaseDescriptionRetransmission",
5067 "on");
5068 } else
5069 vty_out(vty,
5070 " Thread Database Description Retransmision %s\n",
5071 nbr->t_db_desc != NULL ? "on" : "off");
5072
5073 /* Show Link State Request Retransmission thread. */
5074 if (use_json) {
5075 if (nbr->t_ls_req != NULL)
5076 json_object_string_add(
5077 json_sub,
5078 "threadLinkStateRequestRetransmission", "on");
5079 } else
5080 vty_out(vty,
5081 " Thread Link State Request Retransmission %s\n",
5082 nbr->t_ls_req != NULL ? "on" : "off");
5083
5084 /* Show Link State Update Retransmission thread. */
5085 if (use_json) {
5086 if (nbr->t_ls_upd != NULL)
5087 json_object_string_add(
5088 json_sub, "threadLinkStateUpdateRetransmission",
5089 "on");
5090 } else
5091 vty_out(vty,
5092 " Thread Link State Update Retransmission %s\n\n",
5093 nbr->t_ls_upd != NULL ? "on" : "off");
5094
5095 if (use_json) {
5096 if (nbr->state == NSM_Attempt && nbr->router_id.s_addr == 0)
5097 json_object_object_add(json, "noNbrId", json_sub);
5098 else
5099 json_object_object_add(json, inet_ntoa(nbr->router_id),
5100 json_sub);
5101 }
5102
5103 ospf_bfd_show_info(vty, nbr->bfd_info, json, use_json, 0);
5104 }
5105
5106 static int show_ip_ospf_neighbor_id_common(struct vty *vty, struct ospf *ospf,
5107 struct in_addr *router_id,
5108 bool use_json, uint8_t use_vrf)
5109 {
5110 struct listnode *node;
5111 struct ospf_neighbor *nbr;
5112 struct ospf_interface *oi;
5113 json_object *json = NULL;
5114
5115 if (use_json)
5116 json = json_object_new_object();
5117
5118 if (ospf->instance) {
5119 if (use_json)
5120 json_object_int_add(json, "ospfInstance",
5121 ospf->instance);
5122 else
5123 vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
5124 }
5125
5126 ospf_show_vrf_name(ospf, vty, json, use_vrf);
5127
5128 for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) {
5129 if ((nbr = ospf_nbr_lookup_by_routerid(oi->nbrs, router_id))) {
5130 show_ip_ospf_neighbor_detail_sub(vty, oi, nbr, json,
5131 use_json);
5132 }
5133 }
5134
5135 if (use_json) {
5136 vty_out(vty, "%s\n", json_object_to_json_string_ext(
5137 json, JSON_C_TO_STRING_PRETTY));
5138 json_object_free(json);
5139 } else
5140 vty_out(vty, "\n");
5141
5142 return CMD_SUCCESS;
5143 }
5144
5145 DEFPY (show_ip_ospf_neighbor_id,
5146 show_ip_ospf_neighbor_id_cmd,
5147 "show ip ospf neighbor A.B.C.D$router_id [json$json]",
5148 SHOW_STR
5149 IP_STR
5150 "OSPF information\n"
5151 "Neighbor list\n"
5152 "Neighbor ID\n"
5153 JSON_STR)
5154 {
5155 struct ospf *ospf;
5156 struct listnode *node;
5157 int ret = CMD_SUCCESS;
5158
5159 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
5160 if (!ospf->oi_running)
5161 continue;
5162 ret = show_ip_ospf_neighbor_id_common(vty, ospf, &router_id,
5163 !!json, 0);
5164 }
5165
5166 return ret;
5167 }
5168
5169 DEFPY (show_ip_ospf_instance_neighbor_id,
5170 show_ip_ospf_instance_neighbor_id_cmd,
5171 "show ip ospf (1-65535)$instance neighbor A.B.C.D$router_id [json$json]",
5172 SHOW_STR
5173 IP_STR
5174 "OSPF information\n"
5175 "Instance ID\n"
5176 "Neighbor list\n"
5177 "Neighbor ID\n"
5178 JSON_STR)
5179 {
5180 struct ospf *ospf;
5181
5182 ospf = ospf_lookup_instance(instance);
5183 if (ospf == NULL)
5184 return CMD_NOT_MY_INSTANCE;
5185
5186 if (!ospf->oi_running)
5187 return CMD_SUCCESS;
5188
5189 return show_ip_ospf_neighbor_id_common(vty, ospf, &router_id, !!json,
5190 0);
5191 }
5192
5193 static int show_ip_ospf_neighbor_detail_common(struct vty *vty,
5194 struct ospf *ospf,
5195 json_object *json, bool use_json,
5196 uint8_t use_vrf)
5197 {
5198 struct ospf_interface *oi;
5199 struct listnode *node;
5200 json_object *json_vrf = NULL;
5201
5202 if (use_json) {
5203 if (use_vrf)
5204 json_vrf = json_object_new_object();
5205 else
5206 json_vrf = json;
5207 }
5208 if (ospf->instance) {
5209 if (use_json)
5210 json_object_int_add(json_vrf, "ospfInstance",
5211 ospf->instance);
5212 else
5213 vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
5214 }
5215
5216 ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf);
5217
5218 for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) {
5219 struct route_node *rn;
5220 struct ospf_neighbor *nbr;
5221
5222 for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) {
5223 if ((nbr = rn->info)) {
5224 if (nbr != oi->nbr_self) {
5225 if (nbr->state != NSM_Down) {
5226 show_ip_ospf_neighbor_detail_sub(
5227 vty, oi, nbr, json_vrf,
5228 use_json);
5229 }
5230 }
5231 }
5232 }
5233 }
5234
5235 if (use_json) {
5236 if (use_vrf) {
5237 if (ospf->vrf_id == VRF_DEFAULT)
5238 json_object_object_add(json, "default",
5239 json_vrf);
5240 else
5241 json_object_object_add(json, ospf->name,
5242 json_vrf);
5243 }
5244 } else
5245 vty_out(vty, "\n");
5246
5247 return CMD_SUCCESS;
5248 }
5249
5250 DEFUN (show_ip_ospf_neighbor_detail,
5251 show_ip_ospf_neighbor_detail_cmd,
5252 "show ip ospf [vrf <NAME|all>] neighbor detail [json]",
5253 SHOW_STR
5254 IP_STR
5255 "OSPF information\n"
5256 VRF_CMD_HELP_STR
5257 "All VRFs\n"
5258 "Neighbor list\n"
5259 "detail of all neighbors\n"
5260 JSON_STR)
5261 {
5262 struct ospf *ospf;
5263 bool uj = use_json(argc, argv);
5264 struct listnode *node = NULL;
5265 char *vrf_name = NULL;
5266 bool all_vrf = FALSE;
5267 int ret = CMD_SUCCESS;
5268 int inst = 0;
5269 int idx_vrf = 0;
5270 uint8_t use_vrf = 0;
5271 json_object *json = NULL;
5272
5273 OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
5274
5275 if (uj)
5276 json = json_object_new_object();
5277
5278 /* vrf input is provided could be all or specific vrf*/
5279 if (vrf_name) {
5280 use_vrf = 1;
5281 if (all_vrf) {
5282 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
5283 if (!ospf->oi_running)
5284 continue;
5285 ret = show_ip_ospf_neighbor_detail_common(
5286 vty, ospf, json, uj, use_vrf);
5287 }
5288 if (uj) {
5289 vty_out(vty, "%s\n",
5290 json_object_to_json_string_ext(
5291 json, JSON_C_TO_STRING_PRETTY));
5292 json_object_free(json);
5293 }
5294
5295 return ret;
5296 }
5297 ospf = ospf_lookup_by_inst_name(inst, vrf_name);
5298 if (ospf == NULL || !ospf->oi_running) {
5299 if (uj)
5300 json_object_free(json);
5301 return CMD_SUCCESS;
5302 }
5303 } else {
5304 /* Display default ospf (instance 0) info */
5305 ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
5306 if (ospf == NULL || !ospf->oi_running) {
5307 if (uj)
5308 json_object_free(json);
5309 return CMD_SUCCESS;
5310 }
5311 }
5312
5313 if (ospf) {
5314 ret = show_ip_ospf_neighbor_detail_common(vty, ospf, json, uj,
5315 use_vrf);
5316 if (uj) {
5317 vty_out(vty, "%s\n",
5318 json_object_to_json_string_ext(
5319 json, JSON_C_TO_STRING_PRETTY));
5320 }
5321 }
5322
5323 if (uj)
5324 json_object_free(json);
5325
5326 return ret;
5327 }
5328
5329 DEFUN (show_ip_ospf_instance_neighbor_detail,
5330 show_ip_ospf_instance_neighbor_detail_cmd,
5331 "show ip ospf (1-65535) neighbor detail [json]",
5332 SHOW_STR
5333 IP_STR
5334 "OSPF information\n"
5335 "Instance ID\n"
5336 "Neighbor list\n"
5337 "detail of all neighbors\n"
5338 JSON_STR)
5339 {
5340 int idx_number = 3;
5341 struct ospf *ospf;
5342 unsigned short instance = 0;
5343 bool uj = use_json(argc, argv);
5344 json_object *json = NULL;
5345 int ret = CMD_SUCCESS;
5346
5347 instance = strtoul(argv[idx_number]->arg, NULL, 10);
5348 ospf = ospf_lookup_instance(instance);
5349 if (ospf == NULL)
5350 return CMD_NOT_MY_INSTANCE;
5351
5352 if (!ospf->oi_running)
5353 return CMD_SUCCESS;
5354
5355 if (uj)
5356 json = json_object_new_object();
5357
5358 ret = show_ip_ospf_neighbor_detail_common(vty, ospf, json, uj, 0);
5359
5360 if (uj) {
5361 vty_out(vty, "%s\n", json_object_to_json_string_ext(
5362 json, JSON_C_TO_STRING_PRETTY));
5363 json_object_free(json);
5364 }
5365
5366 return ret;
5367 }
5368
5369 static int show_ip_ospf_neighbor_detail_all_common(struct vty *vty,
5370 struct ospf *ospf,
5371 json_object *json,
5372 bool use_json,
5373 uint8_t use_vrf)
5374 {
5375 struct listnode *node;
5376 struct ospf_interface *oi;
5377 json_object *json_vrf = NULL;
5378
5379 if (use_json) {
5380 if (use_vrf)
5381 json_vrf = json_object_new_object();
5382 else
5383 json_vrf = json;
5384 }
5385
5386 if (ospf->instance) {
5387 if (use_json)
5388 json_object_int_add(json, "ospfInstance",
5389 ospf->instance);
5390 else
5391 vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
5392 }
5393
5394 ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf);
5395
5396 for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) {
5397 struct route_node *rn;
5398 struct ospf_neighbor *nbr;
5399 struct ospf_nbr_nbma *nbr_nbma;
5400
5401 for (rn = route_top(oi->nbrs); rn; rn = route_next(rn))
5402 if ((nbr = rn->info))
5403 if (nbr != oi->nbr_self)
5404 if (nbr->state != NSM_Down)
5405 show_ip_ospf_neighbor_detail_sub(
5406 vty, oi, rn->info,
5407 json_vrf, use_json);
5408
5409 if (oi->type == OSPF_IFTYPE_NBMA) {
5410 struct listnode *nd;
5411
5412 for (ALL_LIST_ELEMENTS_RO(oi->nbr_nbma, nd, nbr_nbma)) {
5413 if (nbr_nbma->nbr == NULL
5414 || nbr_nbma->nbr->state == NSM_Down)
5415 show_ip_ospf_nbr_nbma_detail_sub(
5416 vty, oi, nbr_nbma, use_json,
5417 json_vrf);
5418 }
5419 }
5420 }
5421
5422 if (use_json) {
5423 if (use_vrf) {
5424 if (ospf->vrf_id == VRF_DEFAULT)
5425 json_object_object_add(json, "default",
5426 json_vrf);
5427 else
5428 json_object_object_add(json, ospf->name,
5429 json_vrf);
5430 }
5431 } else {
5432 vty_out(vty, "\n");
5433 }
5434
5435 return CMD_SUCCESS;
5436 }
5437
5438 DEFUN (show_ip_ospf_neighbor_detail_all,
5439 show_ip_ospf_neighbor_detail_all_cmd,
5440 "show ip ospf [vrf <NAME|all>] neighbor detail all [json]",
5441 SHOW_STR
5442 IP_STR
5443 "OSPF information\n"
5444 VRF_CMD_HELP_STR
5445 "All VRFs\n"
5446 "Neighbor list\n"
5447 "detail of all neighbors\n"
5448 "include down status neighbor\n"
5449 JSON_STR)
5450 {
5451 struct ospf *ospf;
5452 bool uj = use_json(argc, argv);
5453 struct listnode *node = NULL;
5454 char *vrf_name = NULL;
5455 bool all_vrf = FALSE;
5456 int ret = CMD_SUCCESS;
5457 int inst = 0;
5458 int idx_vrf = 0;
5459 uint8_t use_vrf = 0;
5460 json_object *json = NULL;
5461
5462 OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
5463
5464 if (uj)
5465 json = json_object_new_object();
5466
5467 /* vrf input is provided could be all or specific vrf*/
5468 if (vrf_name) {
5469 use_vrf = 1;
5470 if (all_vrf) {
5471 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
5472 if (!ospf->oi_running)
5473 continue;
5474 ret = show_ip_ospf_neighbor_detail_all_common(
5475 vty, ospf, json, uj, use_vrf);
5476 }
5477
5478 if (uj) {
5479 vty_out(vty, "%s\n",
5480 json_object_to_json_string_ext(
5481 json, JSON_C_TO_STRING_PRETTY));
5482 json_object_free(json);
5483 }
5484
5485 return ret;
5486 }
5487 ospf = ospf_lookup_by_inst_name(inst, vrf_name);
5488 if (ospf == NULL || !ospf->oi_running) {
5489 if (uj)
5490 json_object_free(json);
5491 return CMD_SUCCESS;
5492 }
5493 } else {
5494 /* Display default ospf (instance 0) info */
5495 ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
5496 if (ospf == NULL || !ospf->oi_running) {
5497 if (uj)
5498 json_object_free(json);
5499 return CMD_SUCCESS;
5500 }
5501 }
5502
5503 if (ospf) {
5504 ret = show_ip_ospf_neighbor_detail_all_common(vty, ospf, json,
5505 uj, use_vrf);
5506 if (uj) {
5507 vty_out(vty, "%s\n",
5508 json_object_to_json_string_ext(
5509 json, JSON_C_TO_STRING_PRETTY));
5510 }
5511 }
5512
5513 if (uj)
5514 json_object_free(json);
5515
5516 return ret;
5517 }
5518
5519 DEFUN (show_ip_ospf_instance_neighbor_detail_all,
5520 show_ip_ospf_instance_neighbor_detail_all_cmd,
5521 "show ip ospf (1-65535) neighbor detail all [json]",
5522 SHOW_STR
5523 IP_STR
5524 "OSPF information\n"
5525 "Instance ID\n"
5526 "Neighbor list\n"
5527 "detail of all neighbors\n"
5528 "include down status neighbor\n"
5529 JSON_STR)
5530 {
5531 int idx_number = 3;
5532 struct ospf *ospf;
5533 unsigned short instance = 0;
5534 bool uj = use_json(argc, argv);
5535 json_object *json = NULL;
5536 int ret = CMD_SUCCESS;
5537
5538 instance = strtoul(argv[idx_number]->arg, NULL, 10);
5539 ospf = ospf_lookup_instance(instance);
5540 if (ospf == NULL)
5541 return CMD_NOT_MY_INSTANCE;
5542
5543 if (!ospf->oi_running)
5544 return CMD_SUCCESS;
5545
5546 if (uj)
5547 json = json_object_new_object();
5548
5549 ret = show_ip_ospf_neighbor_detail_all_common(vty, ospf, json, uj, 0);
5550
5551 if (uj) {
5552 vty_out(vty, "%s\n", json_object_to_json_string_ext(
5553 json, JSON_C_TO_STRING_PRETTY));
5554 json_object_free(json);
5555 }
5556
5557 return ret;
5558 }
5559
5560 static int show_ip_ospf_neighbor_int_detail_common(struct vty *vty,
5561 struct ospf *ospf,
5562 int arg_base,
5563 struct cmd_token **argv,
5564 bool use_json)
5565 {
5566 struct ospf_interface *oi;
5567 struct interface *ifp;
5568 struct route_node *rn, *nrn;
5569 struct ospf_neighbor *nbr;
5570 json_object *json = NULL;
5571
5572 if (use_json)
5573 json = json_object_new_object();
5574
5575 if (ospf->instance) {
5576 if (use_json)
5577 json_object_int_add(json, "ospfInstance",
5578 ospf->instance);
5579 else
5580 vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
5581 }
5582
5583 ifp = if_lookup_by_name(argv[arg_base]->arg,
5584 vrf_lookup_by_id(ospf->vrf_id));
5585 if (!ifp) {
5586 if (!use_json)
5587 vty_out(vty, "No such interface.\n");
5588 else {
5589 vty_out(vty, "{}\n");
5590 json_object_free(json);
5591 }
5592 return CMD_WARNING;
5593 }
5594
5595 for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) {
5596 if ((oi = rn->info)) {
5597 for (nrn = route_top(oi->nbrs); nrn;
5598 nrn = route_next(nrn)) {
5599 if ((nbr = nrn->info)) {
5600 if (nbr != oi->nbr_self) {
5601 if (nbr->state != NSM_Down)
5602 show_ip_ospf_neighbor_detail_sub(
5603 vty, oi, nbr,
5604 json, use_json);
5605 }
5606 }
5607 }
5608 }
5609 }
5610
5611 if (use_json) {
5612 vty_out(vty, "%s\n", json_object_to_json_string_ext(
5613 json, JSON_C_TO_STRING_PRETTY));
5614 json_object_free(json);
5615 } else
5616 vty_out(vty, "\n");
5617
5618 return CMD_SUCCESS;
5619 }
5620
5621 DEFUN (show_ip_ospf_neighbor_int_detail,
5622 show_ip_ospf_neighbor_int_detail_cmd,
5623 "show ip ospf neighbor IFNAME detail [json]",
5624 SHOW_STR
5625 IP_STR
5626 "OSPF information\n"
5627 "Neighbor list\n"
5628 "Interface name\n"
5629 "detail of all neighbors\n"
5630 JSON_STR)
5631 {
5632 struct ospf *ospf;
5633 bool uj = use_json(argc, argv);
5634 struct listnode *node = NULL;
5635 int ret = CMD_SUCCESS;
5636 bool ospf_output = FALSE;
5637
5638 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
5639 if (!ospf->oi_running)
5640 continue;
5641 ospf_output = TRUE;
5642 ret = show_ip_ospf_neighbor_int_detail_common(vty, ospf, 0,
5643 argv, uj);
5644 }
5645
5646 if (!ospf_output)
5647 vty_out(vty, "%% OSPF instance not found\n");
5648
5649 return ret;
5650 }
5651
5652 DEFUN (show_ip_ospf_instance_neighbor_int_detail,
5653 show_ip_ospf_instance_neighbor_int_detail_cmd,
5654 "show ip ospf (1-65535) neighbor IFNAME detail [json]",
5655 SHOW_STR
5656 IP_STR
5657 "OSPF information\n"
5658 "Instance ID\n"
5659 "Neighbor list\n"
5660 "Interface name\n"
5661 "detail of all neighbors\n"
5662 JSON_STR)
5663 {
5664 int idx_number = 3;
5665 int idx_ifname = 5;
5666 struct ospf *ospf;
5667 unsigned short instance = 0;
5668 bool uj = use_json(argc, argv);
5669
5670 instance = strtoul(argv[idx_number]->arg, NULL, 10);
5671 ospf = ospf_lookup_instance(instance);
5672 if (ospf == NULL)
5673 return CMD_NOT_MY_INSTANCE;
5674
5675 if (!ospf->oi_running)
5676 return CMD_SUCCESS;
5677
5678 return show_ip_ospf_neighbor_int_detail_common(vty, ospf, idx_ifname,
5679 argv, uj);
5680 }
5681
5682 /* Show functions */
5683 static int show_lsa_summary(struct vty *vty, struct ospf_lsa *lsa, int self)
5684 {
5685 struct router_lsa *rl;
5686 struct summary_lsa *sl;
5687 struct as_external_lsa *asel;
5688 struct prefix_ipv4 p;
5689
5690 if (lsa != NULL)
5691 /* If self option is set, check LSA self flag. */
5692 if (self == 0 || IS_LSA_SELF(lsa)) {
5693 /* LSA common part show. */
5694 vty_out(vty, "%-15s ", inet_ntoa(lsa->data->id));
5695 vty_out(vty, "%-15s %4d 0x%08lx 0x%04x",
5696 inet_ntoa(lsa->data->adv_router), LS_AGE(lsa),
5697 (unsigned long)ntohl(lsa->data->ls_seqnum),
5698 ntohs(lsa->data->checksum));
5699 /* LSA specific part show. */
5700 switch (lsa->data->type) {
5701 case OSPF_ROUTER_LSA:
5702 rl = (struct router_lsa *)lsa->data;
5703 vty_out(vty, " %-d", ntohs(rl->links));
5704 break;
5705 case OSPF_SUMMARY_LSA:
5706 sl = (struct summary_lsa *)lsa->data;
5707
5708 p.family = AF_INET;
5709 p.prefix = sl->header.id;
5710 p.prefixlen = ip_masklen(sl->mask);
5711 apply_mask_ipv4(&p);
5712
5713 vty_out(vty, " %s/%d", inet_ntoa(p.prefix),
5714 p.prefixlen);
5715 break;
5716 case OSPF_AS_EXTERNAL_LSA:
5717 case OSPF_AS_NSSA_LSA:
5718 asel = (struct as_external_lsa *)lsa->data;
5719
5720 p.family = AF_INET;
5721 p.prefix = asel->header.id;
5722 p.prefixlen = ip_masklen(asel->mask);
5723 apply_mask_ipv4(&p);
5724
5725 vty_out(vty, " %s %s/%d [0x%lx]",
5726 IS_EXTERNAL_METRIC(asel->e[0].tos)
5727 ? "E2"
5728 : "E1",
5729 inet_ntoa(p.prefix), p.prefixlen,
5730 (unsigned long)ntohl(
5731 asel->e[0].route_tag));
5732 break;
5733 case OSPF_NETWORK_LSA:
5734 case OSPF_ASBR_SUMMARY_LSA:
5735 case OSPF_OPAQUE_LINK_LSA:
5736 case OSPF_OPAQUE_AREA_LSA:
5737 case OSPF_OPAQUE_AS_LSA:
5738 default:
5739 break;
5740 }
5741 vty_out(vty, "\n");
5742 }
5743
5744 return 0;
5745 }
5746
5747 static const char *show_database_desc[] = {
5748 "unknown",
5749 "Router Link States",
5750 "Net Link States",
5751 "Summary Link States",
5752 "ASBR-Summary Link States",
5753 "AS External Link States",
5754 "Group Membership LSA",
5755 "NSSA-external Link States",
5756 "Type-8 LSA",
5757 "Link-Local Opaque-LSA",
5758 "Area-Local Opaque-LSA",
5759 "AS-external Opaque-LSA",
5760 };
5761
5762 static const char *show_database_header[] = {
5763 "",
5764 "Link ID ADV Router Age Seq# CkSum Link count",
5765 "Link ID ADV Router Age Seq# CkSum",
5766 "Link ID ADV Router Age Seq# CkSum Route",
5767 "Link ID ADV Router Age Seq# CkSum",
5768 "Link ID ADV Router Age Seq# CkSum Route",
5769 " --- header for Group Member ----",
5770 "Link ID ADV Router Age Seq# CkSum Route",
5771 " --- type-8 ---",
5772 "Opaque-Type/Id ADV Router Age Seq# CkSum",
5773 "Opaque-Type/Id ADV Router Age Seq# CkSum",
5774 "Opaque-Type/Id ADV Router Age Seq# CkSum",
5775 };
5776
5777 static void show_ip_ospf_database_header(struct vty *vty, struct ospf_lsa *lsa)
5778 {
5779 struct router_lsa *rlsa = (struct router_lsa *)lsa->data;
5780
5781 vty_out(vty, " LS age: %d\n", LS_AGE(lsa));
5782 vty_out(vty, " Options: 0x%-2x : %s\n", lsa->data->options,
5783 ospf_options_dump(lsa->data->options));
5784 vty_out(vty, " LS Flags: 0x%-2x %s\n", lsa->flags,
5785 ((lsa->flags & OSPF_LSA_LOCAL_XLT) ? "(Translated from Type-7)"
5786 : ""));
5787
5788 if (lsa->data->type == OSPF_ROUTER_LSA) {
5789 vty_out(vty, " Flags: 0x%x", rlsa->flags);
5790
5791 if (rlsa->flags)
5792 vty_out(vty, " :%s%s%s%s",
5793 IS_ROUTER_LSA_BORDER(rlsa) ? " ABR" : "",
5794 IS_ROUTER_LSA_EXTERNAL(rlsa) ? " ASBR" : "",
5795 IS_ROUTER_LSA_VIRTUAL(rlsa) ? " VL-endpoint"
5796 : "",
5797 IS_ROUTER_LSA_SHORTCUT(rlsa) ? " Shortcut"
5798 : "");
5799
5800 vty_out(vty, "\n");
5801 }
5802 vty_out(vty, " LS Type: %s\n",
5803 lookup_msg(ospf_lsa_type_msg, lsa->data->type, NULL));
5804 vty_out(vty, " Link State ID: %s %s\n", inet_ntoa(lsa->data->id),
5805 lookup_msg(ospf_link_state_id_type_msg, lsa->data->type, NULL));
5806 vty_out(vty, " Advertising Router: %s\n",
5807 inet_ntoa(lsa->data->adv_router));
5808 vty_out(vty, " LS Seq Number: %08lx\n",
5809 (unsigned long)ntohl(lsa->data->ls_seqnum));
5810 vty_out(vty, " Checksum: 0x%04x\n", ntohs(lsa->data->checksum));
5811 vty_out(vty, " Length: %d\n\n", ntohs(lsa->data->length));
5812 }
5813
5814 const char *link_type_desc[] = {
5815 "(null)",
5816 "another Router (point-to-point)",
5817 "a Transit Network",
5818 "Stub Network",
5819 "a Virtual Link",
5820 };
5821
5822 const char *link_id_desc[] = {
5823 "(null)", "Neighboring Router ID", "Designated Router address",
5824 "Net", "Neighboring Router ID",
5825 };
5826
5827 const char *link_data_desc[] = {
5828 "(null)", "Router Interface address", "Router Interface address",
5829 "Network Mask", "Router Interface address",
5830 };
5831
5832 /* Show router-LSA each Link information. */
5833 static void show_ip_ospf_database_router_links(struct vty *vty,
5834 struct router_lsa *rl)
5835 {
5836 int len, type;
5837 unsigned int i;
5838
5839 len = ntohs(rl->header.length) - 4;
5840 for (i = 0; i < ntohs(rl->links) && len > 0; len -= 12, i++) {
5841 type = rl->link[i].type;
5842
5843 vty_out(vty, " Link connected to: %s\n",
5844 link_type_desc[type]);
5845 vty_out(vty, " (Link ID) %s: %s\n", link_id_desc[type],
5846 inet_ntoa(rl->link[i].link_id));
5847 vty_out(vty, " (Link Data) %s: %s\n", link_data_desc[type],
5848 inet_ntoa(rl->link[i].link_data));
5849 vty_out(vty, " Number of TOS metrics: 0\n");
5850 vty_out(vty, " TOS 0 Metric: %d\n",
5851 ntohs(rl->link[i].metric));
5852 vty_out(vty, "\n");
5853 }
5854 }
5855
5856 /* Show router-LSA detail information. */
5857 static int show_router_lsa_detail(struct vty *vty, struct ospf_lsa *lsa)
5858 {
5859 if (lsa != NULL) {
5860 struct router_lsa *rl = (struct router_lsa *)lsa->data;
5861
5862 show_ip_ospf_database_header(vty, lsa);
5863
5864 vty_out(vty, " Number of Links: %d\n\n", ntohs(rl->links));
5865
5866 show_ip_ospf_database_router_links(vty, rl);
5867 vty_out(vty, "\n");
5868 }
5869
5870 return 0;
5871 }
5872
5873 /* Show network-LSA detail information. */
5874 static int show_network_lsa_detail(struct vty *vty, struct ospf_lsa *lsa)
5875 {
5876 int length, i;
5877
5878 if (lsa != NULL) {
5879 struct network_lsa *nl = (struct network_lsa *)lsa->data;
5880
5881 show_ip_ospf_database_header(vty, lsa);
5882
5883 vty_out(vty, " Network Mask: /%d\n", ip_masklen(nl->mask));
5884
5885 length = ntohs(lsa->data->length) - OSPF_LSA_HEADER_SIZE - 4;
5886
5887 for (i = 0; length > 0; i++, length -= 4)
5888 vty_out(vty, " Attached Router: %s\n",
5889 inet_ntoa(nl->routers[i]));
5890
5891 vty_out(vty, "\n");
5892 }
5893
5894 return 0;
5895 }
5896
5897 /* Show summary-LSA detail information. */
5898 static int show_summary_lsa_detail(struct vty *vty, struct ospf_lsa *lsa)
5899 {
5900 if (lsa != NULL) {
5901 struct summary_lsa *sl = (struct summary_lsa *)lsa->data;
5902
5903 show_ip_ospf_database_header(vty, lsa);
5904
5905 vty_out(vty, " Network Mask: /%d\n", ip_masklen(sl->mask));
5906 vty_out(vty, " TOS: 0 Metric: %d\n",
5907 GET_METRIC(sl->metric));
5908 vty_out(vty, "\n");
5909 }
5910
5911 return 0;
5912 }
5913
5914 /* Show summary-ASBR-LSA detail information. */
5915 static int show_summary_asbr_lsa_detail(struct vty *vty, struct ospf_lsa *lsa)
5916 {
5917 if (lsa != NULL) {
5918 struct summary_lsa *sl = (struct summary_lsa *)lsa->data;
5919
5920 show_ip_ospf_database_header(vty, lsa);
5921
5922 vty_out(vty, " Network Mask: /%d\n", ip_masklen(sl->mask));
5923 vty_out(vty, " TOS: 0 Metric: %d\n",
5924 GET_METRIC(sl->metric));
5925 vty_out(vty, "\n");
5926 }
5927
5928 return 0;
5929 }
5930
5931 /* Show AS-external-LSA detail information. */
5932 static int show_as_external_lsa_detail(struct vty *vty, struct ospf_lsa *lsa)
5933 {
5934 if (lsa != NULL) {
5935 struct as_external_lsa *al =
5936 (struct as_external_lsa *)lsa->data;
5937
5938 show_ip_ospf_database_header(vty, lsa);
5939
5940 vty_out(vty, " Network Mask: /%d\n", ip_masklen(al->mask));
5941 vty_out(vty, " Metric Type: %s\n",
5942 IS_EXTERNAL_METRIC(al->e[0].tos)
5943 ? "2 (Larger than any link state path)"
5944 : "1");
5945 vty_out(vty, " TOS: 0\n");
5946 vty_out(vty, " Metric: %d\n",
5947 GET_METRIC(al->e[0].metric));
5948 vty_out(vty, " Forward Address: %s\n",
5949 inet_ntoa(al->e[0].fwd_addr));
5950
5951 vty_out(vty,
5952 " External Route Tag: %" ROUTE_TAG_PRI "\n\n",
5953 (route_tag_t)ntohl(al->e[0].route_tag));
5954 }
5955
5956 return 0;
5957 }
5958 #if 0
5959 static int
5960 show_as_external_lsa_stdvty (struct ospf_lsa *lsa)
5961 {
5962 struct as_external_lsa *al = (struct as_external_lsa *) lsa->data;
5963
5964 /* show_ip_ospf_database_header (vty, lsa); */
5965
5966 zlog_debug( " Network Mask: /%d%s",
5967 ip_masklen (al->mask), "\n");
5968 zlog_debug( " Metric Type: %s%s",
5969 IS_EXTERNAL_METRIC (al->e[0].tos) ?
5970 "2 (Larger than any link state path)" : "1", "\n");
5971 zlog_debug( " TOS: 0%s", "\n");
5972 zlog_debug( " Metric: %d%s",
5973 GET_METRIC (al->e[0].metric), "\n");
5974 zlog_debug( " Forward Address: %s%s",
5975 inet_ntoa (al->e[0].fwd_addr), "\n");
5976
5977 zlog_debug( " External Route Tag: %"ROUTE_TAG_PRI"%s%s",
5978 (route_tag_t)ntohl (al->e[0].route_tag), "\n", "\n");
5979
5980 return 0;
5981 }
5982 #endif
5983 /* Show AS-NSSA-LSA detail information. */
5984 static int show_as_nssa_lsa_detail(struct vty *vty, struct ospf_lsa *lsa)
5985 {
5986 if (lsa != NULL) {
5987 struct as_external_lsa *al =
5988 (struct as_external_lsa *)lsa->data;
5989
5990 show_ip_ospf_database_header(vty, lsa);
5991
5992 vty_out(vty, " Network Mask: /%d\n", ip_masklen(al->mask));
5993 vty_out(vty, " Metric Type: %s\n",
5994 IS_EXTERNAL_METRIC(al->e[0].tos)
5995 ? "2 (Larger than any link state path)"
5996 : "1");
5997 vty_out(vty, " TOS: 0\n");
5998 vty_out(vty, " Metric: %d\n",
5999 GET_METRIC(al->e[0].metric));
6000 vty_out(vty, " NSSA: Forward Address: %s\n",
6001 inet_ntoa(al->e[0].fwd_addr));
6002
6003 vty_out(vty,
6004 " External Route Tag: %" ROUTE_TAG_PRI "\n\n",
6005 (route_tag_t)ntohl(al->e[0].route_tag));
6006 }
6007
6008 return 0;
6009 }
6010
6011 static int show_func_dummy(struct vty *vty, struct ospf_lsa *lsa)
6012 {
6013 return 0;
6014 }
6015
6016 static int show_opaque_lsa_detail(struct vty *vty, struct ospf_lsa *lsa)
6017 {
6018 if (lsa != NULL) {
6019 show_ip_ospf_database_header(vty, lsa);
6020 show_opaque_info_detail(vty, lsa);
6021
6022 vty_out(vty, "\n");
6023 }
6024 return 0;
6025 }
6026
6027 int (*show_function[])(struct vty *, struct ospf_lsa *) = {
6028 NULL,
6029 show_router_lsa_detail,
6030 show_network_lsa_detail,
6031 show_summary_lsa_detail,
6032 show_summary_asbr_lsa_detail,
6033 show_as_external_lsa_detail,
6034 show_func_dummy,
6035 show_as_nssa_lsa_detail, /* almost same as external */
6036 NULL, /* type-8 */
6037 show_opaque_lsa_detail,
6038 show_opaque_lsa_detail,
6039 show_opaque_lsa_detail,
6040 };
6041
6042 static void show_lsa_prefix_set(struct vty *vty, struct prefix_ls *lp,
6043 struct in_addr *id, struct in_addr *adv_router)
6044 {
6045 memset(lp, 0, sizeof(struct prefix_ls));
6046 lp->family = 0;
6047 if (id == NULL)
6048 lp->prefixlen = 0;
6049 else if (adv_router == NULL) {
6050 lp->prefixlen = 32;
6051 lp->id = *id;
6052 } else {
6053 lp->prefixlen = 64;
6054 lp->id = *id;
6055 lp->adv_router = *adv_router;
6056 }
6057 }
6058
6059 static void show_lsa_detail_proc(struct vty *vty, struct route_table *rt,
6060 struct in_addr *id, struct in_addr *adv_router)
6061 {
6062 struct prefix_ls lp;
6063 struct route_node *rn, *start;
6064 struct ospf_lsa *lsa;
6065
6066 show_lsa_prefix_set(vty, &lp, id, adv_router);
6067 start = route_node_get(rt, (struct prefix *)&lp);
6068 if (start) {
6069 route_lock_node(start);
6070 for (rn = start; rn; rn = route_next_until(rn, start))
6071 if ((lsa = rn->info)) {
6072 if (show_function[lsa->data->type] != NULL)
6073 show_function[lsa->data->type](vty,
6074 lsa);
6075 }
6076 route_unlock_node(start);
6077 }
6078 }
6079
6080 /* Show detail LSA information
6081 -- if id is NULL then show all LSAs. */
6082 static void show_lsa_detail(struct vty *vty, struct ospf *ospf, int type,
6083 struct in_addr *id, struct in_addr *adv_router)
6084 {
6085 struct listnode *node;
6086 struct ospf_area *area;
6087
6088 switch (type) {
6089 case OSPF_AS_EXTERNAL_LSA:
6090 case OSPF_OPAQUE_AS_LSA:
6091 vty_out(vty, " %s \n\n",
6092 show_database_desc[type]);
6093 show_lsa_detail_proc(vty, AS_LSDB(ospf, type), id, adv_router);
6094 break;
6095 default:
6096 for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) {
6097 vty_out(vty, "\n %s (Area %s)\n\n",
6098 show_database_desc[type],
6099 ospf_area_desc_string(area));
6100 show_lsa_detail_proc(vty, AREA_LSDB(area, type), id,
6101 adv_router);
6102 }
6103 break;
6104 }
6105 }
6106
6107 static void show_lsa_detail_adv_router_proc(struct vty *vty,
6108 struct route_table *rt,
6109 struct in_addr *adv_router)
6110 {
6111 struct route_node *rn;
6112 struct ospf_lsa *lsa;
6113
6114 for (rn = route_top(rt); rn; rn = route_next(rn))
6115 if ((lsa = rn->info))
6116 if (IPV4_ADDR_SAME(adv_router,
6117 &lsa->data->adv_router)) {
6118 if (CHECK_FLAG(lsa->flags, OSPF_LSA_LOCAL_XLT))
6119 continue;
6120 if (show_function[lsa->data->type] != NULL)
6121 show_function[lsa->data->type](vty,
6122 lsa);
6123 }
6124 }
6125
6126 /* Show detail LSA information. */
6127 static void show_lsa_detail_adv_router(struct vty *vty, struct ospf *ospf,
6128 int type, struct in_addr *adv_router)
6129 {
6130 struct listnode *node;
6131 struct ospf_area *area;
6132
6133 switch (type) {
6134 case OSPF_AS_EXTERNAL_LSA:
6135 case OSPF_OPAQUE_AS_LSA:
6136 vty_out(vty, " %s \n\n",
6137 show_database_desc[type]);
6138 show_lsa_detail_adv_router_proc(vty, AS_LSDB(ospf, type),
6139 adv_router);
6140 break;
6141 default:
6142 for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) {
6143 vty_out(vty, "\n %s (Area %s)\n\n",
6144 show_database_desc[type],
6145 ospf_area_desc_string(area));
6146 show_lsa_detail_adv_router_proc(
6147 vty, AREA_LSDB(area, type), adv_router);
6148 }
6149 break;
6150 }
6151 }
6152
6153 static void show_ip_ospf_database_summary(struct vty *vty, struct ospf *ospf,
6154 int self)
6155 {
6156 struct ospf_lsa *lsa;
6157 struct route_node *rn;
6158 struct ospf_area *area;
6159 struct listnode *node;
6160 int type;
6161
6162 for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) {
6163 for (type = OSPF_MIN_LSA; type < OSPF_MAX_LSA; type++) {
6164 switch (type) {
6165 case OSPF_AS_EXTERNAL_LSA:
6166 case OSPF_OPAQUE_AS_LSA:
6167 continue;
6168 default:
6169 break;
6170 }
6171 if (ospf_lsdb_count_self(area->lsdb, type) > 0
6172 || (!self
6173 && ospf_lsdb_count(area->lsdb, type) > 0)) {
6174 vty_out(vty, " %s (Area %s)\n\n",
6175 show_database_desc[type],
6176 ospf_area_desc_string(area));
6177 vty_out(vty, "%s\n",
6178 show_database_header[type]);
6179
6180 LSDB_LOOP (AREA_LSDB(area, type), rn, lsa)
6181 show_lsa_summary(vty, lsa, self);
6182
6183 vty_out(vty, "\n");
6184 }
6185 }
6186 }
6187
6188 for (type = OSPF_MIN_LSA; type < OSPF_MAX_LSA; type++) {
6189 switch (type) {
6190 case OSPF_AS_EXTERNAL_LSA:
6191 case OSPF_OPAQUE_AS_LSA:
6192 break;
6193 default:
6194 continue;
6195 }
6196 if (ospf_lsdb_count_self(ospf->lsdb, type)
6197 || (!self && ospf_lsdb_count(ospf->lsdb, type))) {
6198 vty_out(vty, " %s\n\n",
6199 show_database_desc[type]);
6200 vty_out(vty, "%s\n", show_database_header[type]);
6201
6202 LSDB_LOOP (AS_LSDB(ospf, type), rn, lsa)
6203 show_lsa_summary(vty, lsa, self);
6204
6205 vty_out(vty, "\n");
6206 }
6207 }
6208
6209 vty_out(vty, "\n");
6210 }
6211
6212 static void show_ip_ospf_database_maxage(struct vty *vty, struct ospf *ospf)
6213 {
6214 struct route_node *rn;
6215
6216 vty_out(vty, "\n MaxAge Link States:\n\n");
6217
6218 for (rn = route_top(ospf->maxage_lsa); rn; rn = route_next(rn)) {
6219 struct ospf_lsa *lsa;
6220
6221 if ((lsa = rn->info) != NULL) {
6222 vty_out(vty, "Link type: %d\n", lsa->data->type);
6223 vty_out(vty, "Link State ID: %s\n",
6224 inet_ntoa(lsa->data->id));
6225 vty_out(vty, "Advertising Router: %s\n",
6226 inet_ntoa(lsa->data->adv_router));
6227 vty_out(vty, "LSA lock count: %d\n", lsa->lock);
6228 vty_out(vty, "\n");
6229 }
6230 }
6231 }
6232
6233 #define OSPF_LSA_TYPE_NSSA_DESC "NSSA external link state\n"
6234 #define OSPF_LSA_TYPE_NSSA_CMD_STR "|nssa-external"
6235
6236 #define OSPF_LSA_TYPE_OPAQUE_LINK_DESC "Link local Opaque-LSA\n"
6237 #define OSPF_LSA_TYPE_OPAQUE_AREA_DESC "Link area Opaque-LSA\n"
6238 #define OSPF_LSA_TYPE_OPAQUE_AS_DESC "Link AS Opaque-LSA\n"
6239 #define OSPF_LSA_TYPE_OPAQUE_CMD_STR "|opaque-link|opaque-area|opaque-as"
6240
6241 #define OSPF_LSA_TYPES_DESC \
6242 "ASBR summary link states\n" \
6243 "External link states\n" \
6244 "Network link states\n" \
6245 "Router link states\n" \
6246 "Network summary link states\n" OSPF_LSA_TYPE_NSSA_DESC \
6247 OSPF_LSA_TYPE_OPAQUE_LINK_DESC OSPF_LSA_TYPE_OPAQUE_AREA_DESC \
6248 OSPF_LSA_TYPE_OPAQUE_AS_DESC
6249
6250 static int show_ip_ospf_database_common(struct vty *vty, struct ospf *ospf,
6251 int arg_base, int argc,
6252 struct cmd_token **argv,
6253 uint8_t use_vrf)
6254 {
6255 int idx_type = 4;
6256 int type, ret;
6257 struct in_addr id, adv_router;
6258
6259 if (ospf->instance)
6260 vty_out(vty, "\nOSPF Instance: %d\n", ospf->instance);
6261
6262 ospf_show_vrf_name(ospf, vty, NULL, use_vrf);
6263
6264 vty_out(vty, "\n OSPF Router with ID (%s)\n\n",
6265 inet_ntoa(ospf->router_id));
6266
6267 /* Show all LSA. */
6268 if (argc == arg_base + 4) {
6269 show_ip_ospf_database_summary(vty, ospf, 0);
6270 return CMD_SUCCESS;
6271 }
6272
6273 /* Set database type to show. */
6274 if (strncmp(argv[arg_base + idx_type]->text, "r", 1) == 0)
6275 type = OSPF_ROUTER_LSA;
6276 else if (strncmp(argv[arg_base + idx_type]->text, "ne", 2) == 0)
6277 type = OSPF_NETWORK_LSA;
6278 else if (strncmp(argv[arg_base + idx_type]->text, "ns", 2) == 0)
6279 type = OSPF_AS_NSSA_LSA;
6280 else if (strncmp(argv[arg_base + idx_type]->text, "su", 2) == 0)
6281 type = OSPF_SUMMARY_LSA;
6282 else if (strncmp(argv[arg_base + idx_type]->text, "a", 1) == 0)
6283 type = OSPF_ASBR_SUMMARY_LSA;
6284 else if (strncmp(argv[arg_base + idx_type]->text, "e", 1) == 0)
6285 type = OSPF_AS_EXTERNAL_LSA;
6286 else if (strncmp(argv[arg_base + idx_type]->text, "se", 2) == 0) {
6287 show_ip_ospf_database_summary(vty, ospf, 1);
6288 return CMD_SUCCESS;
6289 } else if (strncmp(argv[arg_base + idx_type]->text, "m", 1) == 0) {
6290 show_ip_ospf_database_maxage(vty, ospf);
6291 return CMD_SUCCESS;
6292 } else if (strncmp(argv[arg_base + idx_type]->text, "opaque-l", 8) == 0)
6293 type = OSPF_OPAQUE_LINK_LSA;
6294 else if (strncmp(argv[arg_base + idx_type]->text, "opaque-ar", 9) == 0)
6295 type = OSPF_OPAQUE_AREA_LSA;
6296 else if (strncmp(argv[arg_base + idx_type]->text, "opaque-as", 9) == 0)
6297 type = OSPF_OPAQUE_AS_LSA;
6298 else
6299 return CMD_WARNING;
6300
6301 /* `show ip ospf database LSA'. */
6302 if (argc == arg_base + 5)
6303 show_lsa_detail(vty, ospf, type, NULL, NULL);
6304 else if (argc >= arg_base + 6) {
6305 ret = inet_aton(argv[arg_base + 5]->arg, &id);
6306 if (!ret)
6307 return CMD_WARNING;
6308
6309 /* `show ip ospf database LSA ID'. */
6310 if (argc == arg_base + 6)
6311 show_lsa_detail(vty, ospf, type, &id, NULL);
6312 /* `show ip ospf database LSA ID adv-router ADV_ROUTER'. */
6313 else if (argc == arg_base + 7) {
6314 if (strncmp(argv[arg_base + 6]->text, "s", 1) == 0)
6315 adv_router = ospf->router_id;
6316 else {
6317 ret = inet_aton(argv[arg_base + 7]->arg,
6318 &adv_router);
6319 if (!ret)
6320 return CMD_WARNING;
6321 }
6322 show_lsa_detail(vty, ospf, type, &id, &adv_router);
6323 }
6324 }
6325
6326 return CMD_SUCCESS;
6327 }
6328
6329 DEFUN (show_ip_ospf_database_max,
6330 show_ip_ospf_database_max_cmd,
6331 "show ip ospf [vrf <NAME|all>] database <max-age|self-originate>",
6332 SHOW_STR
6333 IP_STR
6334 "OSPF information\n"
6335 VRF_CMD_HELP_STR
6336 "All VRFs\n"
6337 "Database summary\n"
6338 "LSAs in MaxAge list\n"
6339 "Self-originated link states\n")
6340 {
6341 struct ospf *ospf = NULL;
6342 struct listnode *node = NULL;
6343 char *vrf_name = NULL;
6344 bool all_vrf = FALSE;
6345 int ret = CMD_SUCCESS;
6346 int inst = 0;
6347 int idx_vrf = 0;
6348 uint8_t use_vrf = 0;
6349
6350 OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
6351
6352 if (vrf_name) {
6353 bool ospf_output = FALSE;
6354
6355 use_vrf = 1;
6356
6357 if (all_vrf) {
6358 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
6359 if (!ospf->oi_running)
6360 continue;
6361 ospf_output = TRUE;
6362 ret = show_ip_ospf_database_common(
6363 vty, ospf, idx_vrf ? 2 : 0, argc, argv,
6364 use_vrf);
6365 }
6366
6367 if (!ospf_output)
6368 vty_out(vty, "%% OSPF instance not found\n");
6369 } else {
6370 ospf = ospf_lookup_by_inst_name(inst, vrf_name);
6371 if (ospf == NULL || !ospf->oi_running) {
6372 vty_out(vty, "%% OSPF instance not found\n");
6373 return CMD_SUCCESS;
6374 }
6375 ret = (show_ip_ospf_database_common(
6376 vty, ospf, idx_vrf ? 2 : 0, argc, argv,
6377 use_vrf));
6378 }
6379 } else {
6380 /* Display default ospf (instance 0) info */
6381 ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
6382 if (ospf == NULL || !ospf->oi_running) {
6383 vty_out(vty, "%% OSPF instance not found\n");
6384 return CMD_SUCCESS;
6385 }
6386
6387 ret = show_ip_ospf_database_common(vty, ospf, 0, argc, argv,
6388 use_vrf);
6389 }
6390
6391 return ret;
6392 }
6393
6394 DEFUN (show_ip_ospf_instance_database,
6395 show_ip_ospf_instance_database_cmd,
6396 "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>]]]",
6397 SHOW_STR
6398 IP_STR
6399 "OSPF information\n"
6400 "Instance ID\n"
6401 VRF_CMD_HELP_STR
6402 "Database summary\n"
6403 OSPF_LSA_TYPES_DESC
6404 "Link State ID (as an IP address)\n"
6405 "Self-originated link states\n"
6406 "Advertising Router link states\n"
6407 "Advertising Router (as an IP address)\n")
6408 {
6409 struct ospf *ospf;
6410 unsigned short instance = 0;
6411 struct listnode *node = NULL;
6412 char *vrf_name = NULL;
6413 bool all_vrf = FALSE;
6414 int ret = CMD_SUCCESS;
6415 int inst = 0;
6416 int idx = 0;
6417 uint8_t use_vrf = 0;
6418
6419 if (argv_find(argv, argc, "(1-65535)", &idx)) {
6420 instance = strtoul(argv[idx]->arg, NULL, 10);
6421 ospf = ospf_lookup_instance(instance);
6422 if (ospf == NULL)
6423 return CMD_NOT_MY_INSTANCE;
6424 if (!ospf->oi_running)
6425 return CMD_SUCCESS;
6426
6427 return (show_ip_ospf_database_common(vty, ospf, idx ? 1 : 0,
6428 argc, argv, use_vrf));
6429 } else if (argv_find(argv, argc, "vrf", &idx)) {
6430 vrf_name = argv[++idx]->arg;
6431 all_vrf = strmatch(vrf_name, "all");
6432 }
6433
6434 if (vrf_name) {
6435 use_vrf = 1;
6436 if (all_vrf) {
6437 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
6438 if (!ospf->oi_running)
6439 continue;
6440 ret = (show_ip_ospf_database_common(
6441 vty, ospf, idx ? 2 : 0, argc, argv,
6442 use_vrf));
6443 }
6444 } else {
6445 ospf = ospf_lookup_by_inst_name(inst, vrf_name);
6446 if ((ospf == NULL) || !ospf->oi_running) {
6447 vty_out(vty, "%% OSPF instance not found\n");
6448 return CMD_SUCCESS;
6449 }
6450
6451 ret = (show_ip_ospf_database_common(
6452 vty, ospf, idx ? 2 : 0, argc, argv, use_vrf));
6453 }
6454 } else {
6455 /* Display default ospf (instance 0) info */
6456 ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
6457 if (ospf == NULL || !ospf->oi_running) {
6458 vty_out(vty, "%% OSPF instance not found\n");
6459 return CMD_SUCCESS;
6460 }
6461
6462 ret = (show_ip_ospf_database_common(vty, ospf, 0, argc, argv,
6463 use_vrf));
6464 }
6465
6466 return ret;
6467 }
6468
6469 DEFUN (show_ip_ospf_instance_database_max,
6470 show_ip_ospf_instance_database_max_cmd,
6471 "show ip ospf (1-65535) database <max-age|self-originate>",
6472 SHOW_STR
6473 IP_STR
6474 "OSPF information\n"
6475 "Instance ID\n"
6476 "Database summary\n"
6477 "LSAs in MaxAge list\n"
6478 "Self-originated link states\n")
6479 {
6480 int idx_number = 3;
6481 struct ospf *ospf;
6482 unsigned short instance = 0;
6483
6484 instance = strtoul(argv[idx_number]->arg, NULL, 10);
6485
6486 ospf = ospf_lookup_instance(instance);
6487 if (ospf == NULL)
6488 return CMD_NOT_MY_INSTANCE;
6489
6490 if (!ospf->oi_running) {
6491 vty_out(vty, "%% OSPF instance not found\n");
6492 return CMD_SUCCESS;
6493 }
6494
6495 return show_ip_ospf_database_common(vty, ospf, 1, argc, argv, 0);
6496 }
6497
6498
6499 static int show_ip_ospf_database_type_adv_router_common(struct vty *vty,
6500 struct ospf *ospf,
6501 int arg_base, int argc,
6502 struct cmd_token **argv,
6503 uint8_t use_vrf)
6504 {
6505 int idx_type = 4;
6506 int type, ret;
6507 struct in_addr adv_router;
6508
6509 if (ospf->instance)
6510 vty_out(vty, "\nOSPF Instance: %d\n", ospf->instance);
6511
6512 ospf_show_vrf_name(ospf, vty, NULL, use_vrf);
6513
6514 vty_out(vty, "\n OSPF Router with ID (%s)\n\n",
6515 inet_ntoa(ospf->router_id));
6516
6517 /* Set database type to show. */
6518 if (strncmp(argv[arg_base + idx_type]->text, "r", 1) == 0)
6519 type = OSPF_ROUTER_LSA;
6520 else if (strncmp(argv[arg_base + idx_type]->text, "ne", 2) == 0)
6521 type = OSPF_NETWORK_LSA;
6522 else if (strncmp(argv[arg_base + idx_type]->text, "ns", 2) == 0)
6523 type = OSPF_AS_NSSA_LSA;
6524 else if (strncmp(argv[arg_base + idx_type]->text, "s", 1) == 0)
6525 type = OSPF_SUMMARY_LSA;
6526 else if (strncmp(argv[arg_base + idx_type]->text, "a", 1) == 0)
6527 type = OSPF_ASBR_SUMMARY_LSA;
6528 else if (strncmp(argv[arg_base + idx_type]->text, "e", 1) == 0)
6529 type = OSPF_AS_EXTERNAL_LSA;
6530 else if (strncmp(argv[arg_base + idx_type]->text, "opaque-l", 8) == 0)
6531 type = OSPF_OPAQUE_LINK_LSA;
6532 else if (strncmp(argv[arg_base + idx_type]->text, "opaque-ar", 9) == 0)
6533 type = OSPF_OPAQUE_AREA_LSA;
6534 else if (strncmp(argv[arg_base + idx_type]->text, "opaque-as", 9) == 0)
6535 type = OSPF_OPAQUE_AS_LSA;
6536 else
6537 return CMD_WARNING;
6538
6539 /* `show ip ospf database LSA adv-router ADV_ROUTER'. */
6540 if (strncmp(argv[arg_base + 5]->text, "s", 1) == 0)
6541 adv_router = ospf->router_id;
6542 else {
6543 ret = inet_aton(argv[arg_base + 6]->arg, &adv_router);
6544 if (!ret)
6545 return CMD_WARNING;
6546 }
6547
6548 show_lsa_detail_adv_router(vty, ospf, type, &adv_router);
6549
6550 return CMD_SUCCESS;
6551 }
6552
6553 DEFUN (show_ip_ospf_instance_database_type_adv_router,
6554 show_ip_ospf_instance_database_type_adv_router_cmd,
6555 "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>",
6556 SHOW_STR
6557 IP_STR
6558 "OSPF information\n"
6559 "Instance ID\n"
6560 VRF_CMD_HELP_STR
6561 "Database summary\n"
6562 OSPF_LSA_TYPES_DESC
6563 "Advertising Router link states\n"
6564 "Advertising Router (as an IP address)\n"
6565 "Self-originated link states\n")
6566 {
6567 struct ospf *ospf = NULL;
6568 unsigned short instance = 0;
6569 struct listnode *node = NULL;
6570 char *vrf_name = NULL;
6571 bool all_vrf = FALSE;
6572 int ret = CMD_SUCCESS;
6573 int inst = 0;
6574 int idx = 0, idx_vrf = 0;
6575 uint8_t use_vrf = 0;
6576
6577 if (argv_find(argv, argc, "(1-65535)", &idx)) {
6578 instance = strtoul(argv[idx]->arg, NULL, 10);
6579 ospf = ospf_lookup_instance(instance);
6580 if (ospf == NULL)
6581 return CMD_NOT_MY_INSTANCE;
6582 if (!ospf->oi_running) {
6583 vty_out(vty, "%% OSPF instance not found\n");
6584 return CMD_SUCCESS;
6585 }
6586
6587 return (show_ip_ospf_database_type_adv_router_common(
6588 vty, ospf, idx ? 1 : 0, argc, argv, use_vrf));
6589 }
6590
6591 OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
6592
6593 if (vrf_name) {
6594 bool ospf_output = FALSE;
6595
6596 use_vrf = 1;
6597
6598 if (all_vrf) {
6599 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
6600 if (!ospf->oi_running)
6601 continue;
6602 ospf_output = TRUE;
6603 ret = show_ip_ospf_database_type_adv_router_common(
6604 vty, ospf, idx ? 1 : 0, argc, argv,
6605 use_vrf);
6606 }
6607 if (!ospf_output)
6608 vty_out(vty, "%% OSPF instance not found\n");
6609 } else {
6610 ospf = ospf_lookup_by_inst_name(inst, vrf_name);
6611 if ((ospf == NULL) || !ospf->oi_running) {
6612 vty_out(vty, "%% OSPF instance not found\n");
6613 return CMD_SUCCESS;
6614 }
6615
6616 ret = show_ip_ospf_database_type_adv_router_common(
6617 vty, ospf, idx ? 1 : 0, argc, argv, use_vrf);
6618 }
6619 } else {
6620 /* Display default ospf (instance 0) info */
6621 ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
6622 if (ospf == NULL || !ospf->oi_running) {
6623 vty_out(vty, "%% OSPF instance not found\n");
6624 return CMD_SUCCESS;
6625 }
6626
6627 ret = show_ip_ospf_database_type_adv_router_common(
6628 vty, ospf, idx ? 1 : 0, argc, argv, use_vrf);
6629 }
6630 return ret;
6631 /*return (show_ip_ospf_database_type_adv_router_common(
6632 vty, ospf, idx ? 1 : 0, argc, argv));*/
6633 }
6634
6635 DEFUN (ip_ospf_authentication_args,
6636 ip_ospf_authentication_args_addr_cmd,
6637 "ip ospf authentication <null|message-digest> [A.B.C.D]",
6638 "IP Information\n"
6639 "OSPF interface commands\n"
6640 "Enable authentication on this interface\n"
6641 "Use null authentication\n"
6642 "Use message-digest authentication\n"
6643 "Address of interface\n")
6644 {
6645 VTY_DECLVAR_CONTEXT(interface, ifp);
6646 int idx_encryption = 3;
6647 int idx_ipv4 = 4;
6648 struct in_addr addr;
6649 int ret;
6650 struct ospf_if_params *params;
6651
6652 params = IF_DEF_PARAMS(ifp);
6653
6654 if (argc == 5) {
6655 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
6656 if (!ret) {
6657 vty_out(vty,
6658 "Please specify interface address by A.B.C.D\n");
6659 return CMD_WARNING_CONFIG_FAILED;
6660 }
6661
6662 params = ospf_get_if_params(ifp, addr);
6663 ospf_if_update_params(ifp, addr);
6664 }
6665
6666 /* Handle null authentication */
6667 if (argv[idx_encryption]->arg[0] == 'n') {
6668 SET_IF_PARAM(params, auth_type);
6669 params->auth_type = OSPF_AUTH_NULL;
6670 return CMD_SUCCESS;
6671 }
6672
6673 /* Handle message-digest authentication */
6674 if (argv[idx_encryption]->arg[0] == 'm') {
6675 SET_IF_PARAM(params, auth_type);
6676 params->auth_type = OSPF_AUTH_CRYPTOGRAPHIC;
6677 return CMD_SUCCESS;
6678 }
6679
6680 vty_out(vty, "You shouldn't get here!\n");
6681 return CMD_WARNING_CONFIG_FAILED;
6682 }
6683
6684 DEFUN (ip_ospf_authentication,
6685 ip_ospf_authentication_addr_cmd,
6686 "ip ospf authentication [A.B.C.D]",
6687 "IP Information\n"
6688 "OSPF interface commands\n"
6689 "Enable authentication on this interface\n"
6690 "Address of interface\n")
6691 {
6692 VTY_DECLVAR_CONTEXT(interface, ifp);
6693 int idx_ipv4 = 3;
6694 struct in_addr addr;
6695 int ret;
6696 struct ospf_if_params *params;
6697
6698 params = IF_DEF_PARAMS(ifp);
6699
6700 if (argc == 4) {
6701 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
6702 if (!ret) {
6703 vty_out(vty,
6704 "Please specify interface address by A.B.C.D\n");
6705 return CMD_WARNING_CONFIG_FAILED;
6706 }
6707
6708 params = ospf_get_if_params(ifp, addr);
6709 ospf_if_update_params(ifp, addr);
6710 }
6711
6712 SET_IF_PARAM(params, auth_type);
6713 params->auth_type = OSPF_AUTH_SIMPLE;
6714
6715 return CMD_SUCCESS;
6716 }
6717
6718 DEFUN (no_ip_ospf_authentication_args,
6719 no_ip_ospf_authentication_args_addr_cmd,
6720 "no ip ospf authentication <null|message-digest> [A.B.C.D]",
6721 NO_STR
6722 "IP Information\n"
6723 "OSPF interface commands\n"
6724 "Enable authentication on this interface\n"
6725 "Use null authentication\n"
6726 "Use message-digest authentication\n"
6727 "Address of interface\n")
6728 {
6729 VTY_DECLVAR_CONTEXT(interface, ifp);
6730 int idx_encryption = 4;
6731 int idx_ipv4 = 5;
6732 struct in_addr addr;
6733 int ret;
6734 struct ospf_if_params *params;
6735 struct route_node *rn;
6736 int auth_type;
6737
6738 params = IF_DEF_PARAMS(ifp);
6739
6740 if (argc == 6) {
6741 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
6742 if (!ret) {
6743 vty_out(vty,
6744 "Please specify interface address by A.B.C.D\n");
6745 return CMD_WARNING_CONFIG_FAILED;
6746 }
6747
6748 params = ospf_lookup_if_params(ifp, addr);
6749 if (params == NULL) {
6750 vty_out(vty, "Ip Address specified is unknown\n");
6751 return CMD_WARNING_CONFIG_FAILED;
6752 }
6753 params->auth_type = OSPF_AUTH_NOTSET;
6754 UNSET_IF_PARAM(params, auth_type);
6755 if (params != IF_DEF_PARAMS(ifp)) {
6756 ospf_free_if_params(ifp, addr);
6757 ospf_if_update_params(ifp, addr);
6758 }
6759 } else {
6760 if (argv[idx_encryption]->arg[0] == 'n') {
6761 auth_type = OSPF_AUTH_NULL;
6762 } else if (argv[idx_encryption]->arg[0] == 'm') {
6763 auth_type = OSPF_AUTH_CRYPTOGRAPHIC;
6764 } else {
6765 vty_out(vty, "Unexpected input encountered\n");
6766 return CMD_WARNING_CONFIG_FAILED;
6767 }
6768 /*
6769 * Here we have a case where the user has entered
6770 * 'no ip ospf authentication (null | message_digest )'
6771 * we need to find if we have any ip addresses underneath it
6772 * that
6773 * correspond to the associated type.
6774 */
6775 if (params->auth_type == auth_type) {
6776 params->auth_type = OSPF_AUTH_NOTSET;
6777 UNSET_IF_PARAM(params, auth_type);
6778 }
6779
6780 for (rn = route_top(IF_OIFS_PARAMS(ifp)); rn;
6781 rn = route_next(rn)) {
6782 if ((params = rn->info)) {
6783 if (params->auth_type == auth_type) {
6784 params->auth_type = OSPF_AUTH_NOTSET;
6785 UNSET_IF_PARAM(params, auth_type);
6786 if (params != IF_DEF_PARAMS(ifp)) {
6787 ospf_free_if_params(
6788 ifp, rn->p.u.prefix4);
6789 ospf_if_update_params(
6790 ifp, rn->p.u.prefix4);
6791 }
6792 }
6793 }
6794 }
6795 }
6796
6797 return CMD_SUCCESS;
6798 }
6799
6800 DEFUN (no_ip_ospf_authentication,
6801 no_ip_ospf_authentication_addr_cmd,
6802 "no ip ospf authentication [A.B.C.D]",
6803 NO_STR
6804 "IP Information\n"
6805 "OSPF interface commands\n"
6806 "Enable authentication on this interface\n"
6807 "Address of interface\n")
6808 {
6809 VTY_DECLVAR_CONTEXT(interface, ifp);
6810 int idx_ipv4 = 4;
6811 struct in_addr addr;
6812 int ret;
6813 struct ospf_if_params *params;
6814 struct route_node *rn;
6815
6816 params = IF_DEF_PARAMS(ifp);
6817
6818 if (argc == 5) {
6819 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
6820 if (!ret) {
6821 vty_out(vty,
6822 "Please specify interface address by A.B.C.D\n");
6823 return CMD_WARNING_CONFIG_FAILED;
6824 }
6825
6826 params = ospf_lookup_if_params(ifp, addr);
6827 if (params == NULL) {
6828 vty_out(vty, "Ip Address specified is unknown\n");
6829 return CMD_WARNING_CONFIG_FAILED;
6830 }
6831
6832 params->auth_type = OSPF_AUTH_NOTSET;
6833 UNSET_IF_PARAM(params, auth_type);
6834 if (params != IF_DEF_PARAMS(ifp)) {
6835 ospf_free_if_params(ifp, addr);
6836 ospf_if_update_params(ifp, addr);
6837 }
6838 } else {
6839 /*
6840 * When a user enters 'no ip ospf authentication'
6841 * We should remove all authentication types from
6842 * the interface.
6843 */
6844 if ((params->auth_type == OSPF_AUTH_NULL)
6845 || (params->auth_type == OSPF_AUTH_CRYPTOGRAPHIC)
6846 || (params->auth_type == OSPF_AUTH_SIMPLE)) {
6847 params->auth_type = OSPF_AUTH_NOTSET;
6848 UNSET_IF_PARAM(params, auth_type);
6849 }
6850
6851 for (rn = route_top(IF_OIFS_PARAMS(ifp)); rn;
6852 rn = route_next(rn)) {
6853 if ((params = rn->info)) {
6854
6855 if ((params->auth_type == OSPF_AUTH_NULL)
6856 || (params->auth_type
6857 == OSPF_AUTH_CRYPTOGRAPHIC)
6858 || (params->auth_type
6859 == OSPF_AUTH_SIMPLE)) {
6860 params->auth_type = OSPF_AUTH_NOTSET;
6861 UNSET_IF_PARAM(params, auth_type);
6862 if (params != IF_DEF_PARAMS(ifp)) {
6863 ospf_free_if_params(
6864 ifp, rn->p.u.prefix4);
6865 ospf_if_update_params(
6866 ifp, rn->p.u.prefix4);
6867 }
6868 }
6869 }
6870 }
6871 }
6872
6873 return CMD_SUCCESS;
6874 }
6875
6876
6877 DEFUN (ip_ospf_authentication_key,
6878 ip_ospf_authentication_key_addr_cmd,
6879 "ip ospf authentication-key AUTH_KEY [A.B.C.D]",
6880 "IP Information\n"
6881 "OSPF interface commands\n"
6882 "Authentication password (key)\n"
6883 "The OSPF password (key)\n"
6884 "Address of interface\n")
6885 {
6886 VTY_DECLVAR_CONTEXT(interface, ifp);
6887 int idx = 0;
6888 struct in_addr addr;
6889 struct ospf_if_params *params;
6890
6891 params = IF_DEF_PARAMS(ifp);
6892
6893 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
6894 if (!inet_aton(argv[idx]->arg, &addr)) {
6895 vty_out(vty,
6896 "Please specify interface address by A.B.C.D\n");
6897 return CMD_WARNING_CONFIG_FAILED;
6898 }
6899
6900 params = ospf_get_if_params(ifp, addr);
6901 ospf_if_update_params(ifp, addr);
6902 }
6903
6904 strlcpy((char *)params->auth_simple, argv[3]->arg,
6905 sizeof(params->auth_simple));
6906 SET_IF_PARAM(params, auth_simple);
6907
6908 return CMD_SUCCESS;
6909 }
6910
6911 DEFUN_HIDDEN (ospf_authentication_key,
6912 ospf_authentication_key_cmd,
6913 "ospf authentication-key AUTH_KEY [A.B.C.D]",
6914 "OSPF interface commands\n"
6915 VLINK_HELPSTR_AUTH_SIMPLE
6916 "Address of interface\n")
6917 {
6918 return ip_ospf_authentication_key(self, vty, argc, argv);
6919 }
6920
6921 DEFUN (no_ip_ospf_authentication_key,
6922 no_ip_ospf_authentication_key_authkey_addr_cmd,
6923 "no ip ospf authentication-key [AUTH_KEY [A.B.C.D]]",
6924 NO_STR
6925 "IP Information\n"
6926 "OSPF interface commands\n"
6927 VLINK_HELPSTR_AUTH_SIMPLE
6928 "Address of interface\n")
6929 {
6930 VTY_DECLVAR_CONTEXT(interface, ifp);
6931 int idx = 0;
6932 struct in_addr addr;
6933 struct ospf_if_params *params;
6934 params = IF_DEF_PARAMS(ifp);
6935
6936 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
6937 if (!inet_aton(argv[idx]->arg, &addr)) {
6938 vty_out(vty,
6939 "Please specify interface address by A.B.C.D\n");
6940 return CMD_WARNING_CONFIG_FAILED;
6941 }
6942
6943 params = ospf_lookup_if_params(ifp, addr);
6944 if (params == NULL)
6945 return CMD_SUCCESS;
6946 }
6947
6948 memset(params->auth_simple, 0, OSPF_AUTH_SIMPLE_SIZE);
6949 UNSET_IF_PARAM(params, auth_simple);
6950
6951 if (params != IF_DEF_PARAMS(ifp)) {
6952 ospf_free_if_params(ifp, addr);
6953 ospf_if_update_params(ifp, addr);
6954 }
6955
6956 return CMD_SUCCESS;
6957 }
6958
6959 DEFUN_HIDDEN (no_ospf_authentication_key,
6960 no_ospf_authentication_key_authkey_addr_cmd,
6961 "no ospf authentication-key [AUTH_KEY [A.B.C.D]]",
6962 NO_STR
6963 "OSPF interface commands\n"
6964 VLINK_HELPSTR_AUTH_SIMPLE
6965 "Address of interface\n")
6966 {
6967 return no_ip_ospf_authentication_key(self, vty, argc, argv);
6968 }
6969
6970 DEFUN (ip_ospf_message_digest_key,
6971 ip_ospf_message_digest_key_cmd,
6972 "ip ospf message-digest-key (1-255) md5 KEY [A.B.C.D]",
6973 "IP Information\n"
6974 "OSPF interface commands\n"
6975 "Message digest authentication password (key)\n"
6976 "Key ID\n"
6977 "Use MD5 algorithm\n"
6978 "The OSPF password (key)\n"
6979 "Address of interface\n")
6980 {
6981 VTY_DECLVAR_CONTEXT(interface, ifp);
6982 struct crypt_key *ck;
6983 uint8_t key_id;
6984 struct in_addr addr;
6985 struct ospf_if_params *params;
6986
6987 params = IF_DEF_PARAMS(ifp);
6988 int idx = 0;
6989
6990 argv_find(argv, argc, "(1-255)", &idx);
6991 char *keyid = argv[idx]->arg;
6992 argv_find(argv, argc, "KEY", &idx);
6993 char *cryptkey = argv[idx]->arg;
6994
6995 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
6996 if (!inet_aton(argv[idx]->arg, &addr)) {
6997 vty_out(vty,
6998 "Please specify interface address by A.B.C.D\n");
6999 return CMD_WARNING_CONFIG_FAILED;
7000 }
7001
7002 params = ospf_get_if_params(ifp, addr);
7003 ospf_if_update_params(ifp, addr);
7004 }
7005
7006 key_id = strtol(keyid, NULL, 10);
7007 if (ospf_crypt_key_lookup(params->auth_crypt, key_id) != NULL) {
7008 vty_out(vty, "OSPF: Key %d already exists\n", key_id);
7009 return CMD_WARNING;
7010 }
7011
7012 ck = ospf_crypt_key_new();
7013 ck->key_id = (uint8_t)key_id;
7014 strlcpy((char *)ck->auth_key, cryptkey, sizeof(ck->auth_key));
7015
7016 ospf_crypt_key_add(params->auth_crypt, ck);
7017 SET_IF_PARAM(params, auth_crypt);
7018
7019 return CMD_SUCCESS;
7020 }
7021
7022 DEFUN_HIDDEN (ospf_message_digest_key,
7023 ospf_message_digest_key_cmd,
7024 "ospf message-digest-key (1-255) md5 KEY [A.B.C.D]",
7025 "OSPF interface commands\n"
7026 "Message digest authentication password (key)\n"
7027 "Key ID\n"
7028 "Use MD5 algorithm\n"
7029 "The OSPF password (key)\n"
7030 "Address of interface\n")
7031 {
7032 return ip_ospf_message_digest_key(self, vty, argc, argv);
7033 }
7034
7035 DEFUN (no_ip_ospf_message_digest_key,
7036 no_ip_ospf_message_digest_key_cmd,
7037 "no ip ospf message-digest-key (1-255) [md5 KEY] [A.B.C.D]",
7038 NO_STR
7039 "IP Information\n"
7040 "OSPF interface commands\n"
7041 "Message digest authentication password (key)\n"
7042 "Key ID\n"
7043 "Use MD5 algorithm\n"
7044 "The OSPF password (key)\n"
7045 "Address of interface\n")
7046 {
7047 VTY_DECLVAR_CONTEXT(interface, ifp);
7048 int idx = 0;
7049 struct crypt_key *ck;
7050 int key_id;
7051 struct in_addr addr;
7052 struct ospf_if_params *params;
7053 params = IF_DEF_PARAMS(ifp);
7054
7055 argv_find(argv, argc, "(1-255)", &idx);
7056 char *keyid = argv[idx]->arg;
7057
7058 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
7059 if (!inet_aton(argv[idx]->arg, &addr)) {
7060 vty_out(vty,
7061 "Please specify interface address by A.B.C.D\n");
7062 return CMD_WARNING_CONFIG_FAILED;
7063 }
7064
7065 params = ospf_lookup_if_params(ifp, addr);
7066 if (params == NULL)
7067 return CMD_SUCCESS;
7068 }
7069
7070 key_id = strtol(keyid, NULL, 10);
7071 ck = ospf_crypt_key_lookup(params->auth_crypt, key_id);
7072 if (ck == NULL) {
7073 vty_out(vty, "OSPF: Key %d does not exist\n", key_id);
7074 return CMD_WARNING_CONFIG_FAILED;
7075 }
7076
7077 ospf_crypt_key_delete(params->auth_crypt, key_id);
7078
7079 if (params != IF_DEF_PARAMS(ifp)) {
7080 ospf_free_if_params(ifp, addr);
7081 ospf_if_update_params(ifp, addr);
7082 }
7083
7084 return CMD_SUCCESS;
7085 }
7086
7087 DEFUN_HIDDEN (no_ospf_message_digest_key,
7088 no_ospf_message_digest_key_cmd,
7089 "no ospf message-digest-key (1-255) [md5 KEY] [A.B.C.D]",
7090 NO_STR
7091 "OSPF interface commands\n"
7092 "Message digest authentication password (key)\n"
7093 "Key ID\n"
7094 "Use MD5 algorithm\n"
7095 "The OSPF password (key)\n"
7096 "Address of interface\n")
7097 {
7098 return no_ip_ospf_message_digest_key(self, vty, argc, argv);
7099 }
7100
7101 DEFUN (ip_ospf_cost,
7102 ip_ospf_cost_cmd,
7103 "ip ospf cost (1-65535) [A.B.C.D]",
7104 "IP Information\n"
7105 "OSPF interface commands\n"
7106 "Interface cost\n"
7107 "Cost\n"
7108 "Address of interface\n")
7109 {
7110 VTY_DECLVAR_CONTEXT(interface, ifp);
7111 int idx = 0;
7112 uint32_t cost = OSPF_OUTPUT_COST_DEFAULT;
7113 struct in_addr addr;
7114 struct ospf_if_params *params;
7115 params = IF_DEF_PARAMS(ifp);
7116
7117 // get arguments
7118 char *coststr = NULL, *ifaddr = NULL;
7119
7120 argv_find(argv, argc, "(1-65535)", &idx);
7121 coststr = argv[idx]->arg;
7122 cost = strtol(coststr, NULL, 10);
7123
7124 ifaddr = argv_find(argv, argc, "A.B.C.D", &idx) ? argv[idx]->arg : NULL;
7125 if (ifaddr) {
7126 if (!inet_aton(ifaddr, &addr)) {
7127 vty_out(vty,
7128 "Please specify interface address by A.B.C.D\n");
7129 return CMD_WARNING_CONFIG_FAILED;
7130 }
7131
7132 params = ospf_get_if_params(ifp, addr);
7133 ospf_if_update_params(ifp, addr);
7134 }
7135
7136 SET_IF_PARAM(params, output_cost_cmd);
7137 params->output_cost_cmd = cost;
7138
7139 ospf_if_recalculate_output_cost(ifp);
7140
7141 return CMD_SUCCESS;
7142 }
7143
7144 DEFUN_HIDDEN (ospf_cost,
7145 ospf_cost_cmd,
7146 "ospf cost (1-65535) [A.B.C.D]",
7147 "OSPF interface commands\n"
7148 "Interface cost\n"
7149 "Cost\n"
7150 "Address of interface\n")
7151 {
7152 return ip_ospf_cost(self, vty, argc, argv);
7153 }
7154
7155 DEFUN (no_ip_ospf_cost,
7156 no_ip_ospf_cost_cmd,
7157 "no ip ospf cost [(1-65535)] [A.B.C.D]",
7158 NO_STR
7159 "IP Information\n"
7160 "OSPF interface commands\n"
7161 "Interface cost\n"
7162 "Cost\n"
7163 "Address of interface\n")
7164 {
7165 VTY_DECLVAR_CONTEXT(interface, ifp);
7166 int idx = 0;
7167 struct in_addr addr;
7168 struct ospf_if_params *params;
7169
7170 params = IF_DEF_PARAMS(ifp);
7171
7172 // get arguments
7173 char *ifaddr = NULL;
7174 ifaddr = argv_find(argv, argc, "A.B.C.D", &idx) ? argv[idx]->arg : NULL;
7175
7176 /* According to the semantics we are mimicking "no ip ospf cost N" is
7177 * always treated as "no ip ospf cost" regardless of the actual value
7178 * of N already configured for the interface. Thus ignore cost. */
7179
7180 if (ifaddr) {
7181 if (!inet_aton(ifaddr, &addr)) {
7182 vty_out(vty,
7183 "Please specify interface address by A.B.C.D\n");
7184 return CMD_WARNING_CONFIG_FAILED;
7185 }
7186
7187 params = ospf_lookup_if_params(ifp, addr);
7188 if (params == NULL)
7189 return CMD_SUCCESS;
7190 }
7191
7192 UNSET_IF_PARAM(params, output_cost_cmd);
7193
7194 if (params != IF_DEF_PARAMS(ifp)) {
7195 ospf_free_if_params(ifp, addr);
7196 ospf_if_update_params(ifp, addr);
7197 }
7198
7199 ospf_if_recalculate_output_cost(ifp);
7200
7201 return CMD_SUCCESS;
7202 }
7203
7204 DEFUN_HIDDEN (no_ospf_cost,
7205 no_ospf_cost_cmd,
7206 "no ospf cost [(1-65535)] [A.B.C.D]",
7207 NO_STR
7208 "OSPF interface commands\n"
7209 "Interface cost\n"
7210 "Cost\n"
7211 "Address of interface\n")
7212 {
7213 return no_ip_ospf_cost(self, vty, argc, argv);
7214 }
7215
7216 static void ospf_nbr_timer_update(struct ospf_interface *oi)
7217 {
7218 struct route_node *rn;
7219 struct ospf_neighbor *nbr;
7220
7221 for (rn = route_top(oi->nbrs); rn; rn = route_next(rn))
7222 if ((nbr = rn->info)) {
7223 nbr->v_inactivity = OSPF_IF_PARAM(oi, v_wait);
7224 nbr->v_db_desc = OSPF_IF_PARAM(oi, retransmit_interval);
7225 nbr->v_ls_req = OSPF_IF_PARAM(oi, retransmit_interval);
7226 nbr->v_ls_upd = OSPF_IF_PARAM(oi, retransmit_interval);
7227 }
7228 }
7229
7230 static int ospf_vty_dead_interval_set(struct vty *vty, const char *interval_str,
7231 const char *nbr_str,
7232 const char *fast_hello_str)
7233 {
7234 VTY_DECLVAR_CONTEXT(interface, ifp);
7235 uint32_t seconds;
7236 uint8_t hellomult;
7237 struct in_addr addr;
7238 int ret;
7239 struct ospf_if_params *params;
7240 struct ospf_interface *oi;
7241 struct route_node *rn;
7242
7243 params = IF_DEF_PARAMS(ifp);
7244
7245 if (nbr_str) {
7246 ret = inet_aton(nbr_str, &addr);
7247 if (!ret) {
7248 vty_out(vty,
7249 "Please specify interface address by A.B.C.D\n");
7250 return CMD_WARNING_CONFIG_FAILED;
7251 }
7252
7253 params = ospf_get_if_params(ifp, addr);
7254 ospf_if_update_params(ifp, addr);
7255 }
7256
7257 if (interval_str) {
7258 seconds = strtoul(interval_str, NULL, 10);
7259
7260 /* reset fast_hello too, just to be sure */
7261 UNSET_IF_PARAM(params, fast_hello);
7262 params->fast_hello = OSPF_FAST_HELLO_DEFAULT;
7263 } else if (fast_hello_str) {
7264 hellomult = strtoul(fast_hello_str, NULL, 10);
7265 /* 1s dead-interval with sub-second hellos desired */
7266 seconds = OSPF_ROUTER_DEAD_INTERVAL_MINIMAL;
7267 SET_IF_PARAM(params, fast_hello);
7268 params->fast_hello = hellomult;
7269 } else {
7270 vty_out(vty,
7271 "Please specify dead-interval or hello-multiplier\n");
7272 return CMD_WARNING_CONFIG_FAILED;
7273 }
7274
7275 SET_IF_PARAM(params, v_wait);
7276 params->v_wait = seconds;
7277
7278 /* Update timer values in neighbor structure. */
7279 if (nbr_str) {
7280 struct ospf *ospf = NULL;
7281
7282 ospf = ospf_lookup_by_vrf_id(ifp->vrf_id);
7283 if (ospf) {
7284 oi = ospf_if_lookup_by_local_addr(ospf, ifp, addr);
7285 if (oi)
7286 ospf_nbr_timer_update(oi);
7287 }
7288 } else {
7289 for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn))
7290 if ((oi = rn->info))
7291 ospf_nbr_timer_update(oi);
7292 }
7293
7294 return CMD_SUCCESS;
7295 }
7296
7297 DEFUN (ip_ospf_dead_interval,
7298 ip_ospf_dead_interval_cmd,
7299 "ip ospf dead-interval (1-65535) [A.B.C.D]",
7300 "IP Information\n"
7301 "OSPF interface commands\n"
7302 "Interval time after which a neighbor is declared down\n"
7303 "Seconds\n"
7304 "Address of interface\n")
7305 {
7306 int idx = 0;
7307 char *interval = argv_find(argv, argc, "(1-65535)", &idx)
7308 ? argv[idx]->arg
7309 : NULL;
7310 char *ifaddr =
7311 argv_find(argv, argc, "A.B.C.D", &idx) ? argv[idx]->arg : NULL;
7312 return ospf_vty_dead_interval_set(vty, interval, ifaddr, NULL);
7313 }
7314
7315
7316 DEFUN_HIDDEN (ospf_dead_interval,
7317 ospf_dead_interval_cmd,
7318 "ospf dead-interval (1-65535) [A.B.C.D]",
7319 "OSPF interface commands\n"
7320 "Interval time after which a neighbor is declared down\n"
7321 "Seconds\n"
7322 "Address of interface\n")
7323 {
7324 return ip_ospf_dead_interval(self, vty, argc, argv);
7325 }
7326
7327 DEFUN (ip_ospf_dead_interval_minimal,
7328 ip_ospf_dead_interval_minimal_addr_cmd,
7329 "ip ospf dead-interval minimal hello-multiplier (1-10) [A.B.C.D]",
7330 "IP Information\n"
7331 "OSPF interface commands\n"
7332 "Interval time after which a neighbor is declared down\n"
7333 "Minimal 1s dead-interval with fast sub-second hellos\n"
7334 "Hello multiplier factor\n"
7335 "Number of Hellos to send each second\n"
7336 "Address of interface\n")
7337 {
7338 int idx_number = 5;
7339 int idx_ipv4 = 6;
7340 if (argc == 7)
7341 return ospf_vty_dead_interval_set(
7342 vty, NULL, argv[idx_ipv4]->arg, argv[idx_number]->arg);
7343 else
7344 return ospf_vty_dead_interval_set(vty, NULL, NULL,
7345 argv[idx_number]->arg);
7346 }
7347
7348 DEFUN (no_ip_ospf_dead_interval,
7349 no_ip_ospf_dead_interval_cmd,
7350 "no ip ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]",
7351 NO_STR
7352 "IP Information\n"
7353 "OSPF interface commands\n"
7354 "Interval time after which a neighbor is declared down\n"
7355 "Seconds\n"
7356 "Minimal 1s dead-interval with fast sub-second hellos\n"
7357 "Hello multiplier factor\n"
7358 "Number of Hellos to send each second\n"
7359 "Address of interface\n")
7360 {
7361 VTY_DECLVAR_CONTEXT(interface, ifp);
7362 int idx_ipv4 = argc - 1;
7363 struct in_addr addr = {.s_addr = 0L};
7364 int ret;
7365 struct ospf_if_params *params;
7366 struct ospf_interface *oi;
7367 struct route_node *rn;
7368
7369 params = IF_DEF_PARAMS(ifp);
7370
7371 if (argv[idx_ipv4]->type == IPV4_TKN) {
7372 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
7373 if (!ret) {
7374 vty_out(vty,
7375 "Please specify interface address by A.B.C.D\n");
7376 return CMD_WARNING_CONFIG_FAILED;
7377 }
7378
7379 params = ospf_lookup_if_params(ifp, addr);
7380 if (params == NULL)
7381 return CMD_SUCCESS;
7382 }
7383
7384 UNSET_IF_PARAM(params, v_wait);
7385 params->v_wait = OSPF_ROUTER_DEAD_INTERVAL_DEFAULT;
7386
7387 UNSET_IF_PARAM(params, fast_hello);
7388 params->fast_hello = OSPF_FAST_HELLO_DEFAULT;
7389
7390 if (params != IF_DEF_PARAMS(ifp)) {
7391 ospf_free_if_params(ifp, addr);
7392 ospf_if_update_params(ifp, addr);
7393 }
7394
7395 /* Update timer values in neighbor structure. */
7396 if (argc == 1) {
7397 struct ospf *ospf = NULL;
7398
7399 ospf = ospf_lookup_by_vrf_id(ifp->vrf_id);
7400 if (ospf) {
7401 oi = ospf_if_lookup_by_local_addr(ospf, ifp, addr);
7402 if (oi)
7403 ospf_nbr_timer_update(oi);
7404 }
7405 } else {
7406 for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn))
7407 if ((oi = rn->info))
7408 ospf_nbr_timer_update(oi);
7409 }
7410
7411 return CMD_SUCCESS;
7412 }
7413
7414 DEFUN_HIDDEN (no_ospf_dead_interval,
7415 no_ospf_dead_interval_cmd,
7416 "no ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]",
7417 NO_STR
7418 "OSPF interface commands\n"
7419 "Interval time after which a neighbor is declared down\n"
7420 "Seconds\n"
7421 "Minimal 1s dead-interval with fast sub-second hellos\n"
7422 "Hello multiplier factor\n"
7423 "Number of Hellos to send each second\n"
7424 "Address of interface\n")
7425 {
7426 return no_ip_ospf_dead_interval(self, vty, argc, argv);
7427 }
7428
7429 DEFUN (ip_ospf_hello_interval,
7430 ip_ospf_hello_interval_cmd,
7431 "ip ospf hello-interval (1-65535) [A.B.C.D]",
7432 "IP Information\n"
7433 "OSPF interface commands\n"
7434 "Time between HELLO packets\n"
7435 "Seconds\n"
7436 "Address of interface\n")
7437 {
7438 VTY_DECLVAR_CONTEXT(interface, ifp);
7439 int idx = 0;
7440 struct in_addr addr;
7441 struct ospf_if_params *params;
7442 params = IF_DEF_PARAMS(ifp);
7443 uint32_t seconds = 0;
7444
7445 argv_find(argv, argc, "(1-65535)", &idx);
7446 seconds = strtol(argv[idx]->arg, NULL, 10);
7447
7448 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
7449 if (!inet_aton(argv[idx]->arg, &addr)) {
7450 vty_out(vty,
7451 "Please specify interface address by A.B.C.D\n");
7452 return CMD_WARNING_CONFIG_FAILED;
7453 }
7454
7455 params = ospf_get_if_params(ifp, addr);
7456 ospf_if_update_params(ifp, addr);
7457 }
7458
7459 SET_IF_PARAM(params, v_hello);
7460 params->v_hello = seconds;
7461
7462 return CMD_SUCCESS;
7463 }
7464
7465 DEFUN_HIDDEN (ospf_hello_interval,
7466 ospf_hello_interval_cmd,
7467 "ospf hello-interval (1-65535) [A.B.C.D]",
7468 "OSPF interface commands\n"
7469 "Time between HELLO packets\n"
7470 "Seconds\n"
7471 "Address of interface\n")
7472 {
7473 return ip_ospf_hello_interval(self, vty, argc, argv);
7474 }
7475
7476 DEFUN (no_ip_ospf_hello_interval,
7477 no_ip_ospf_hello_interval_cmd,
7478 "no ip ospf hello-interval [(1-65535) [A.B.C.D]]",
7479 NO_STR
7480 "IP Information\n"
7481 "OSPF interface commands\n"
7482 "Time between HELLO packets\n" // ignored
7483 "Seconds\n"
7484 "Address of interface\n")
7485 {
7486 VTY_DECLVAR_CONTEXT(interface, ifp);
7487 int idx = 0;
7488 struct in_addr addr;
7489 struct ospf_if_params *params;
7490
7491 params = IF_DEF_PARAMS(ifp);
7492
7493 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
7494 if (!inet_aton(argv[idx]->arg, &addr)) {
7495 vty_out(vty,
7496 "Please specify interface address by A.B.C.D\n");
7497 return CMD_WARNING_CONFIG_FAILED;
7498 }
7499
7500 params = ospf_lookup_if_params(ifp, addr);
7501 if (params == NULL)
7502 return CMD_SUCCESS;
7503 }
7504
7505 UNSET_IF_PARAM(params, v_hello);
7506 params->v_hello = OSPF_HELLO_INTERVAL_DEFAULT;
7507
7508 if (params != IF_DEF_PARAMS(ifp)) {
7509 ospf_free_if_params(ifp, addr);
7510 ospf_if_update_params(ifp, addr);
7511 }
7512
7513 return CMD_SUCCESS;
7514 }
7515
7516 DEFUN_HIDDEN (no_ospf_hello_interval,
7517 no_ospf_hello_interval_cmd,
7518 "no ospf hello-interval [(1-65535) [A.B.C.D]]",
7519 NO_STR
7520 "OSPF interface commands\n"
7521 "Time between HELLO packets\n" // ignored
7522 "Seconds\n"
7523 "Address of interface\n")
7524 {
7525 return no_ip_ospf_hello_interval(self, vty, argc, argv);
7526 }
7527
7528 DEFUN (ip_ospf_network,
7529 ip_ospf_network_cmd,
7530 "ip ospf network <broadcast|non-broadcast|point-to-multipoint|point-to-point>",
7531 "IP Information\n"
7532 "OSPF interface commands\n"
7533 "Network type\n"
7534 "Specify OSPF broadcast multi-access network\n"
7535 "Specify OSPF NBMA network\n"
7536 "Specify OSPF point-to-multipoint network\n"
7537 "Specify OSPF point-to-point network\n")
7538 {
7539 VTY_DECLVAR_CONTEXT(interface, ifp);
7540 int idx = 0;
7541 int old_type = IF_DEF_PARAMS(ifp)->type;
7542 struct route_node *rn;
7543
7544 if (old_type == OSPF_IFTYPE_LOOPBACK) {
7545 vty_out(vty,
7546 "This is a loopback interface. Can't set network type.\n");
7547 return CMD_WARNING_CONFIG_FAILED;
7548 }
7549
7550 if (argv_find(argv, argc, "broadcast", &idx))
7551 IF_DEF_PARAMS(ifp)->type = OSPF_IFTYPE_BROADCAST;
7552 else if (argv_find(argv, argc, "non-broadcast", &idx))
7553 IF_DEF_PARAMS(ifp)->type = OSPF_IFTYPE_NBMA;
7554 else if (argv_find(argv, argc, "point-to-multipoint", &idx))
7555 IF_DEF_PARAMS(ifp)->type = OSPF_IFTYPE_POINTOMULTIPOINT;
7556 else if (argv_find(argv, argc, "point-to-point", &idx))
7557 IF_DEF_PARAMS(ifp)->type = OSPF_IFTYPE_POINTOPOINT;
7558
7559 if (IF_DEF_PARAMS(ifp)->type == old_type)
7560 return CMD_SUCCESS;
7561
7562 SET_IF_PARAM(IF_DEF_PARAMS(ifp), type);
7563
7564 for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) {
7565 struct ospf_interface *oi = rn->info;
7566
7567 if (!oi)
7568 continue;
7569
7570 oi->type = IF_DEF_PARAMS(ifp)->type;
7571
7572 if (oi->state > ISM_Down) {
7573 OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceDown);
7574 OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceUp);
7575 }
7576 }
7577
7578 return CMD_SUCCESS;
7579 }
7580
7581 DEFUN_HIDDEN (ospf_network,
7582 ospf_network_cmd,
7583 "ospf network <broadcast|non-broadcast|point-to-multipoint|point-to-point>",
7584 "OSPF interface commands\n"
7585 "Network type\n"
7586 "Specify OSPF broadcast multi-access network\n"
7587 "Specify OSPF NBMA network\n"
7588 "Specify OSPF point-to-multipoint network\n"
7589 "Specify OSPF point-to-point network\n")
7590 {
7591 return ip_ospf_network(self, vty, argc, argv);
7592 }
7593
7594 DEFUN (no_ip_ospf_network,
7595 no_ip_ospf_network_cmd,
7596 "no ip ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]",
7597 NO_STR
7598 "IP Information\n"
7599 "OSPF interface commands\n"
7600 "Network type\n"
7601 "Specify OSPF broadcast multi-access network\n"
7602 "Specify OSPF NBMA network\n"
7603 "Specify OSPF point-to-multipoint network\n"
7604 "Specify OSPF point-to-point network\n")
7605 {
7606 VTY_DECLVAR_CONTEXT(interface, ifp);
7607 int old_type = IF_DEF_PARAMS(ifp)->type;
7608 struct route_node *rn;
7609
7610 IF_DEF_PARAMS(ifp)->type = ospf_default_iftype(ifp);
7611
7612 if (IF_DEF_PARAMS(ifp)->type == old_type)
7613 return CMD_SUCCESS;
7614
7615 for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) {
7616 struct ospf_interface *oi = rn->info;
7617
7618 if (!oi)
7619 continue;
7620
7621 oi->type = IF_DEF_PARAMS(ifp)->type;
7622
7623 if (oi->state > ISM_Down) {
7624 OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceDown);
7625 OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceUp);
7626 }
7627 }
7628
7629 return CMD_SUCCESS;
7630 }
7631
7632 DEFUN_HIDDEN (no_ospf_network,
7633 no_ospf_network_cmd,
7634 "no ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]",
7635 NO_STR
7636 "OSPF interface commands\n"
7637 "Network type\n"
7638 "Specify OSPF broadcast multi-access network\n"
7639 "Specify OSPF NBMA network\n"
7640 "Specify OSPF point-to-multipoint network\n"
7641 "Specify OSPF point-to-point network\n")
7642 {
7643 return no_ip_ospf_network(self, vty, argc, argv);
7644 }
7645
7646 DEFUN (ip_ospf_priority,
7647 ip_ospf_priority_cmd,
7648 "ip ospf priority (0-255) [A.B.C.D]",
7649 "IP Information\n"
7650 "OSPF interface commands\n"
7651 "Router priority\n"
7652 "Priority\n"
7653 "Address of interface\n")
7654 {
7655 VTY_DECLVAR_CONTEXT(interface, ifp);
7656 int idx = 0;
7657 long priority;
7658 struct route_node *rn;
7659 struct in_addr addr;
7660 struct ospf_if_params *params;
7661 params = IF_DEF_PARAMS(ifp);
7662
7663 argv_find(argv, argc, "(0-255)", &idx);
7664 priority = strtol(argv[idx]->arg, NULL, 10);
7665
7666 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
7667 if (!inet_aton(argv[idx]->arg, &addr)) {
7668 vty_out(vty,
7669 "Please specify interface address by A.B.C.D\n");
7670 return CMD_WARNING_CONFIG_FAILED;
7671 }
7672
7673 params = ospf_get_if_params(ifp, addr);
7674 ospf_if_update_params(ifp, addr);
7675 }
7676
7677 SET_IF_PARAM(params, priority);
7678 params->priority = priority;
7679
7680 for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) {
7681 struct ospf_interface *oi = rn->info;
7682
7683 if (!oi)
7684 continue;
7685
7686 if (PRIORITY(oi) != OSPF_IF_PARAM(oi, priority)) {
7687 PRIORITY(oi) = OSPF_IF_PARAM(oi, priority);
7688 OSPF_ISM_EVENT_SCHEDULE(oi, ISM_NeighborChange);
7689 }
7690 }
7691
7692 return CMD_SUCCESS;
7693 }
7694
7695 DEFUN_HIDDEN (ospf_priority,
7696 ospf_priority_cmd,
7697 "ospf priority (0-255) [A.B.C.D]",
7698 "OSPF interface commands\n"
7699 "Router priority\n"
7700 "Priority\n"
7701 "Address of interface\n")
7702 {
7703 return ip_ospf_priority(self, vty, argc, argv);
7704 }
7705
7706 DEFUN (no_ip_ospf_priority,
7707 no_ip_ospf_priority_cmd,
7708 "no ip ospf priority [(0-255) [A.B.C.D]]",
7709 NO_STR
7710 "IP Information\n"
7711 "OSPF interface commands\n"
7712 "Router priority\n" // ignored
7713 "Priority\n"
7714 "Address of interface\n")
7715 {
7716 VTY_DECLVAR_CONTEXT(interface, ifp);
7717 int idx = 0;
7718 struct route_node *rn;
7719 struct in_addr addr;
7720 struct ospf_if_params *params;
7721
7722 params = IF_DEF_PARAMS(ifp);
7723
7724 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
7725 if (!inet_aton(argv[idx]->arg, &addr)) {
7726 vty_out(vty,
7727 "Please specify interface address by A.B.C.D\n");
7728 return CMD_WARNING_CONFIG_FAILED;
7729 }
7730
7731 params = ospf_lookup_if_params(ifp, addr);
7732 if (params == NULL)
7733 return CMD_SUCCESS;
7734 }
7735
7736 UNSET_IF_PARAM(params, priority);
7737 params->priority = OSPF_ROUTER_PRIORITY_DEFAULT;
7738
7739 if (params != IF_DEF_PARAMS(ifp)) {
7740 ospf_free_if_params(ifp, addr);
7741 ospf_if_update_params(ifp, addr);
7742 }
7743
7744 for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) {
7745 struct ospf_interface *oi = rn->info;
7746
7747 if (!oi)
7748 continue;
7749
7750 if (PRIORITY(oi) != OSPF_IF_PARAM(oi, priority)) {
7751 PRIORITY(oi) = OSPF_IF_PARAM(oi, priority);
7752 OSPF_ISM_EVENT_SCHEDULE(oi, ISM_NeighborChange);
7753 }
7754 }
7755
7756 return CMD_SUCCESS;
7757 }
7758
7759 DEFUN_HIDDEN (no_ospf_priority,
7760 no_ospf_priority_cmd,
7761 "no ospf priority [(0-255) [A.B.C.D]]",
7762 NO_STR
7763 "OSPF interface commands\n"
7764 "Router priority\n"
7765 "Priority\n"
7766 "Address of interface\n")
7767 {
7768 return no_ip_ospf_priority(self, vty, argc, argv);
7769 }
7770
7771 DEFUN (ip_ospf_retransmit_interval,
7772 ip_ospf_retransmit_interval_addr_cmd,
7773 "ip ospf retransmit-interval (3-65535) [A.B.C.D]",
7774 "IP Information\n"
7775 "OSPF interface commands\n"
7776 "Time between retransmitting lost link state advertisements\n"
7777 "Seconds\n"
7778 "Address of interface\n")
7779 {
7780 VTY_DECLVAR_CONTEXT(interface, ifp);
7781 int idx = 0;
7782 uint32_t seconds;
7783 struct in_addr addr;
7784 struct ospf_if_params *params;
7785 params = IF_DEF_PARAMS(ifp);
7786
7787 argv_find(argv, argc, "(3-65535)", &idx);
7788 seconds = strtol(argv[idx]->arg, NULL, 10);
7789
7790 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
7791 if (!inet_aton(argv[idx]->arg, &addr)) {
7792 vty_out(vty,
7793 "Please specify interface address by A.B.C.D\n");
7794 return CMD_WARNING_CONFIG_FAILED;
7795 }
7796
7797 params = ospf_get_if_params(ifp, addr);
7798 ospf_if_update_params(ifp, addr);
7799 }
7800
7801 SET_IF_PARAM(params, retransmit_interval);
7802 params->retransmit_interval = seconds;
7803
7804 return CMD_SUCCESS;
7805 }
7806
7807 DEFUN_HIDDEN (ospf_retransmit_interval,
7808 ospf_retransmit_interval_cmd,
7809 "ospf retransmit-interval (3-65535) [A.B.C.D]",
7810 "OSPF interface commands\n"
7811 "Time between retransmitting lost link state advertisements\n"
7812 "Seconds\n"
7813 "Address of interface\n")
7814 {
7815 return ip_ospf_retransmit_interval(self, vty, argc, argv);
7816 }
7817
7818 DEFUN (no_ip_ospf_retransmit_interval,
7819 no_ip_ospf_retransmit_interval_addr_cmd,
7820 "no ip ospf retransmit-interval [(3-65535)] [A.B.C.D]",
7821 NO_STR
7822 "IP Information\n"
7823 "OSPF interface commands\n"
7824 "Time between retransmitting lost link state advertisements\n"
7825 "Seconds\n"
7826 "Address of interface\n")
7827 {
7828 VTY_DECLVAR_CONTEXT(interface, ifp);
7829 int idx = 0;
7830 struct in_addr addr;
7831 struct ospf_if_params *params;
7832
7833 params = IF_DEF_PARAMS(ifp);
7834
7835 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
7836 if (!inet_aton(argv[idx]->arg, &addr)) {
7837 vty_out(vty,
7838 "Please specify interface address by A.B.C.D\n");
7839 return CMD_WARNING_CONFIG_FAILED;
7840 }
7841
7842 params = ospf_lookup_if_params(ifp, addr);
7843 if (params == NULL)
7844 return CMD_SUCCESS;
7845 }
7846
7847 UNSET_IF_PARAM(params, retransmit_interval);
7848 params->retransmit_interval = OSPF_RETRANSMIT_INTERVAL_DEFAULT;
7849
7850 if (params != IF_DEF_PARAMS(ifp)) {
7851 ospf_free_if_params(ifp, addr);
7852 ospf_if_update_params(ifp, addr);
7853 }
7854
7855 return CMD_SUCCESS;
7856 }
7857
7858 DEFUN_HIDDEN (no_ospf_retransmit_interval,
7859 no_ospf_retransmit_interval_cmd,
7860 "no ospf retransmit-interval [(3-65535)] [A.B.C.D]",
7861 NO_STR
7862 "OSPF interface commands\n"
7863 "Time between retransmitting lost link state advertisements\n"
7864 "Seconds\n"
7865 "Address of interface\n")
7866 {
7867 return no_ip_ospf_retransmit_interval(self, vty, argc, argv);
7868 }
7869
7870 DEFUN (ip_ospf_transmit_delay,
7871 ip_ospf_transmit_delay_addr_cmd,
7872 "ip ospf transmit-delay (1-65535) [A.B.C.D]",
7873 "IP Information\n"
7874 "OSPF interface commands\n"
7875 "Link state transmit delay\n"
7876 "Seconds\n"
7877 "Address of interface\n")
7878 {
7879 VTY_DECLVAR_CONTEXT(interface, ifp);
7880 int idx = 0;
7881 uint32_t seconds;
7882 struct in_addr addr;
7883 struct ospf_if_params *params;
7884
7885 params = IF_DEF_PARAMS(ifp);
7886 argv_find(argv, argc, "(1-65535)", &idx);
7887 seconds = strtol(argv[idx]->arg, NULL, 10);
7888
7889 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
7890 if (!inet_aton(argv[idx]->arg, &addr)) {
7891 vty_out(vty,
7892 "Please specify interface address by A.B.C.D\n");
7893 return CMD_WARNING_CONFIG_FAILED;
7894 }
7895
7896 params = ospf_get_if_params(ifp, addr);
7897 ospf_if_update_params(ifp, addr);
7898 }
7899
7900 SET_IF_PARAM(params, transmit_delay);
7901 params->transmit_delay = seconds;
7902
7903 return CMD_SUCCESS;
7904 }
7905
7906 DEFUN_HIDDEN (ospf_transmit_delay,
7907 ospf_transmit_delay_cmd,
7908 "ospf transmit-delay (1-65535) [A.B.C.D]",
7909 "OSPF interface commands\n"
7910 "Link state transmit delay\n"
7911 "Seconds\n"
7912 "Address of interface\n")
7913 {
7914 return ip_ospf_transmit_delay(self, vty, argc, argv);
7915 }
7916
7917 DEFUN (no_ip_ospf_transmit_delay,
7918 no_ip_ospf_transmit_delay_addr_cmd,
7919 "no ip ospf transmit-delay [(1-65535)] [A.B.C.D]",
7920 NO_STR
7921 "IP Information\n"
7922 "OSPF interface commands\n"
7923 "Link state transmit delay\n"
7924 "Seconds\n"
7925 "Address of interface\n")
7926 {
7927 VTY_DECLVAR_CONTEXT(interface, ifp);
7928 int idx = 0;
7929 struct in_addr addr;
7930 struct ospf_if_params *params;
7931
7932 params = IF_DEF_PARAMS(ifp);
7933
7934 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
7935 if (!inet_aton(argv[idx]->arg, &addr)) {
7936 vty_out(vty,
7937 "Please specify interface address by A.B.C.D\n");
7938 return CMD_WARNING_CONFIG_FAILED;
7939 }
7940
7941 params = ospf_lookup_if_params(ifp, addr);
7942 if (params == NULL)
7943 return CMD_SUCCESS;
7944 }
7945
7946 UNSET_IF_PARAM(params, transmit_delay);
7947 params->transmit_delay = OSPF_TRANSMIT_DELAY_DEFAULT;
7948
7949 if (params != IF_DEF_PARAMS(ifp)) {
7950 ospf_free_if_params(ifp, addr);
7951 ospf_if_update_params(ifp, addr);
7952 }
7953
7954 return CMD_SUCCESS;
7955 }
7956
7957
7958 DEFUN_HIDDEN (no_ospf_transmit_delay,
7959 no_ospf_transmit_delay_cmd,
7960 "no ospf transmit-delay [(1-65535) [A.B.C.D]]",
7961 NO_STR
7962 "OSPF interface commands\n"
7963 "Link state transmit delay\n"
7964 "Seconds\n"
7965 "Address of interface\n")
7966 {
7967 return no_ip_ospf_transmit_delay(self, vty, argc, argv);
7968 }
7969
7970 DEFUN (ip_ospf_area,
7971 ip_ospf_area_cmd,
7972 "ip ospf [(1-65535)] area <A.B.C.D|(0-4294967295)> [A.B.C.D]",
7973 "IP Information\n"
7974 "OSPF interface commands\n"
7975 "Instance ID\n"
7976 "Enable OSPF on this interface\n"
7977 "OSPF area ID in IP address format\n"
7978 "OSPF area ID as a decimal value\n"
7979 "Address of interface\n")
7980 {
7981 VTY_DECLVAR_CONTEXT(interface, ifp);
7982 int idx = 0;
7983 int format, ret;
7984 struct in_addr area_id;
7985 struct in_addr addr;
7986 struct ospf_if_params *params = NULL;
7987 struct route_node *rn;
7988 struct ospf *ospf = NULL;
7989 unsigned short instance = 0;
7990 char *areaid;
7991
7992 if (argv_find(argv, argc, "(1-65535)", &idx))
7993 instance = strtol(argv[idx]->arg, NULL, 10);
7994
7995 argv_find(argv, argc, "area", &idx);
7996 areaid = argv[idx + 1]->arg;
7997
7998 if (ifp->vrf_id && !instance)
7999 ospf = ospf_lookup_by_vrf_id(ifp->vrf_id);
8000 else
8001 ospf = ospf_lookup_instance(instance);
8002
8003 if (instance && ospf == NULL) {
8004 params = IF_DEF_PARAMS(ifp);
8005 if (OSPF_IF_PARAM_CONFIGURED(params, if_area)) {
8006 UNSET_IF_PARAM(params, if_area);
8007 ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
8008 ospf_interface_area_unset(ospf, ifp);
8009 ospf->if_ospf_cli_count--;
8010 }
8011 return CMD_NOT_MY_INSTANCE;
8012 }
8013
8014 ret = str2area_id(areaid, &area_id, &format);
8015 if (ret < 0) {
8016 vty_out(vty, "Please specify area by A.B.C.D|<0-4294967295>\n");
8017 return CMD_WARNING_CONFIG_FAILED;
8018 }
8019 if (memcmp(ifp->name, "VLINK", 5) == 0) {
8020 vty_out(vty, "Cannot enable OSPF on a virtual link.\n");
8021 return CMD_WARNING_CONFIG_FAILED;
8022 }
8023
8024 params = IF_DEF_PARAMS(ifp);
8025 if (OSPF_IF_PARAM_CONFIGURED(params, if_area)
8026 && !IPV4_ADDR_SAME(&params->if_area, &area_id)) {
8027 vty_out(vty,
8028 "Must remove previous area config before changing ospf area \n");
8029 return CMD_WARNING_CONFIG_FAILED;
8030 }
8031
8032 // Check if we have an address arg and proccess it
8033 if (argc == idx + 3) {
8034 if (!inet_aton(argv[idx + 2]->arg, &addr)) {
8035 vty_out(vty,
8036 "Please specify Intf Address by A.B.C.D\n");
8037 return CMD_WARNING_CONFIG_FAILED;
8038 }
8039 // update/create address-level params
8040 params = ospf_get_if_params((ifp), (addr));
8041 if (OSPF_IF_PARAM_CONFIGURED(params, if_area)) {
8042 vty_out(vty,
8043 "Must remove previous area/address config before changing ospf area");
8044 return CMD_WARNING_CONFIG_FAILED;
8045 }
8046 ospf_if_update_params((ifp), (addr));
8047 }
8048
8049 if (ospf) {
8050 for (rn = route_top(ospf->networks); rn; rn = route_next(rn)) {
8051 if (rn->info != NULL) {
8052 vty_out(vty,
8053 "Please remove all network commands first.\n");
8054 return CMD_WARNING_CONFIG_FAILED;
8055 }
8056 }
8057 }
8058
8059 /* enable ospf on this interface with area_id */
8060 if (params) {
8061 SET_IF_PARAM(params, if_area);
8062 params->if_area = area_id;
8063 params->if_area_id_fmt = format;
8064 }
8065
8066 if (ospf) {
8067 ospf_interface_area_set(ospf, ifp);
8068 ospf->if_ospf_cli_count++;
8069 }
8070
8071 return CMD_SUCCESS;
8072 }
8073
8074 DEFUN (no_ip_ospf_area,
8075 no_ip_ospf_area_cmd,
8076 "no ip ospf [(1-65535)] area [<A.B.C.D|(0-4294967295)> [A.B.C.D]]",
8077 NO_STR
8078 "IP Information\n"
8079 "OSPF interface commands\n"
8080 "Instance ID\n"
8081 "Disable OSPF on this interface\n"
8082 "OSPF area ID in IP address format\n"
8083 "OSPF area ID as a decimal value\n"
8084 "Address of interface\n")
8085 {
8086 VTY_DECLVAR_CONTEXT(interface, ifp);
8087 int idx = 0;
8088 struct ospf *ospf;
8089 struct ospf_if_params *params;
8090 unsigned short instance = 0;
8091 struct in_addr addr;
8092
8093 if (argv_find(argv, argc, "(1-65535)", &idx))
8094 instance = strtol(argv[idx]->arg, NULL, 10);
8095
8096 if (ifp->vrf_id && !instance)
8097 ospf = ospf_lookup_by_vrf_id(ifp->vrf_id);
8098 else
8099 ospf = ospf_lookup_instance(instance);
8100
8101 if (ospf == NULL)
8102 return CMD_NOT_MY_INSTANCE;
8103
8104 argv_find(argv, argc, "area", &idx);
8105
8106 // Check if we have an address arg and proccess it
8107 if (argc == idx + 3) {
8108 if (!inet_aton(argv[idx + 2]->arg, &addr)) {
8109 vty_out(vty,
8110 "Please specify Intf Address by A.B.C.D\n");
8111 return CMD_WARNING_CONFIG_FAILED;
8112 }
8113 params = ospf_lookup_if_params(ifp, addr);
8114 if ((params) == NULL)
8115 return CMD_SUCCESS;
8116 } else
8117 params = IF_DEF_PARAMS(ifp);
8118
8119 if (!OSPF_IF_PARAM_CONFIGURED(params, if_area)) {
8120 vty_out(vty,
8121 "Can't find specified interface area configuration.\n");
8122 return CMD_WARNING_CONFIG_FAILED;
8123 }
8124
8125 UNSET_IF_PARAM(params, if_area);
8126 if (params != IF_DEF_PARAMS((ifp))) {
8127 ospf_free_if_params((ifp), (addr));
8128 ospf_if_update_params((ifp), (addr));
8129 }
8130
8131 ospf_interface_area_unset(ospf, ifp);
8132 ospf->if_ospf_cli_count--;
8133 return CMD_SUCCESS;
8134 }
8135
8136 DEFUN (ospf_redistribute_source,
8137 ospf_redistribute_source_cmd,
8138 "redistribute " FRR_REDIST_STR_OSPFD " [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
8139 REDIST_STR
8140 FRR_REDIST_HELP_STR_OSPFD
8141 "Metric for redistributed routes\n"
8142 "OSPF default metric\n"
8143 "OSPF exterior metric type for redistributed routes\n"
8144 "Set OSPF External Type 1/2 metrics\n"
8145 "Route map reference\n"
8146 "Pointer to route-map entries\n")
8147 {
8148 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
8149 int idx_protocol = 1;
8150 int source;
8151 int type = -1;
8152 int metric = -1;
8153 struct ospf_redist *red;
8154 int idx = 0;
8155
8156 /* Get distribute source. */
8157 source = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
8158 if (source < 0)
8159 return CMD_WARNING_CONFIG_FAILED;
8160
8161 red = ospf_redist_add(ospf, source, 0);
8162
8163 /* Get metric value. */
8164 if (argv_find(argv, argc, "(0-16777214)", &idx)) {
8165 if (!str2metric(argv[idx]->arg, &metric))
8166 return CMD_WARNING_CONFIG_FAILED;
8167 }
8168 idx = 1;
8169 /* Get metric type. */
8170 if (argv_find(argv, argc, "(1-2)", &idx)) {
8171 if (!str2metric_type(argv[idx]->arg, &type))
8172 return CMD_WARNING_CONFIG_FAILED;
8173 }
8174 idx = 1;
8175 /* Get route-map */
8176 if (argv_find(argv, argc, "WORD", &idx)) {
8177 ospf_routemap_set(red, argv[idx]->arg);
8178 } else
8179 ospf_routemap_unset(red);
8180
8181 return ospf_redistribute_set(ospf, source, 0, type, metric);
8182 }
8183
8184 DEFUN (no_ospf_redistribute_source,
8185 no_ospf_redistribute_source_cmd,
8186 "no redistribute " FRR_REDIST_STR_OSPFD " [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
8187 NO_STR
8188 REDIST_STR
8189 FRR_REDIST_HELP_STR_OSPFD
8190 "Metric for redistributed routes\n"
8191 "OSPF default metric\n"
8192 "OSPF exterior metric type for redistributed routes\n"
8193 "Set OSPF External Type 1/2 metrics\n"
8194 "Route map reference\n"
8195 "Pointer to route-map entries\n")
8196 {
8197 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
8198 int idx_protocol = 2;
8199 int source;
8200 struct ospf_redist *red;
8201
8202 source = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
8203 if (source < 0)
8204 return CMD_WARNING_CONFIG_FAILED;
8205
8206 red = ospf_redist_lookup(ospf, source, 0);
8207 if (!red)
8208 return CMD_SUCCESS;
8209
8210 ospf_routemap_unset(red);
8211 ospf_redist_del(ospf, source, 0);
8212
8213 return ospf_redistribute_unset(ospf, source, 0);
8214 }
8215
8216 DEFUN (ospf_redistribute_instance_source,
8217 ospf_redistribute_instance_source_cmd,
8218 "redistribute <ospf|table> (1-65535) [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
8219 REDIST_STR
8220 "Open Shortest Path First\n"
8221 "Non-main Kernel Routing Table\n"
8222 "Instance ID/Table ID\n"
8223 "Metric for redistributed routes\n"
8224 "OSPF default metric\n"
8225 "OSPF exterior metric type for redistributed routes\n"
8226 "Set OSPF External Type 1/2 metrics\n"
8227 "Route map reference\n"
8228 "Pointer to route-map entries\n")
8229 {
8230 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
8231 int idx_ospf_table = 1;
8232 int idx_number = 2;
8233 int idx = 3;
8234 int source;
8235 int type = -1;
8236 int metric = -1;
8237 unsigned short instance;
8238 struct ospf_redist *red;
8239
8240 source = proto_redistnum(AFI_IP, argv[idx_ospf_table]->text);
8241
8242 if (source < 0) {
8243 vty_out(vty, "Unknown instance redistribution\n");
8244 return CMD_WARNING_CONFIG_FAILED;
8245 }
8246
8247 instance = strtoul(argv[idx_number]->arg, NULL, 10);
8248
8249 if ((source == ZEBRA_ROUTE_OSPF) && !ospf->instance) {
8250 vty_out(vty,
8251 "Instance redistribution in non-instanced OSPF not allowed\n");
8252 return CMD_WARNING_CONFIG_FAILED;
8253 }
8254
8255 if ((source == ZEBRA_ROUTE_OSPF) && (ospf->instance == instance)) {
8256 vty_out(vty, "Same instance OSPF redistribution not allowed\n");
8257 return CMD_WARNING_CONFIG_FAILED;
8258 }
8259
8260 /* Get metric value. */
8261 if (argv_find(argv, argc, "metric", &idx))
8262 if (!str2metric(argv[idx + 1]->arg, &metric))
8263 return CMD_WARNING_CONFIG_FAILED;
8264
8265 idx = 3;
8266 /* Get metric type. */
8267 if (argv_find(argv, argc, "metric-type", &idx))
8268 if (!str2metric_type(argv[idx + 1]->arg, &type))
8269 return CMD_WARNING_CONFIG_FAILED;
8270
8271 red = ospf_redist_add(ospf, source, instance);
8272
8273 idx = 3;
8274 if (argv_find(argv, argc, "route-map", &idx))
8275 ospf_routemap_set(red, argv[idx + 1]->arg);
8276 else
8277 ospf_routemap_unset(red);
8278
8279 return ospf_redistribute_set(ospf, source, instance, type, metric);
8280 }
8281
8282 DEFUN (no_ospf_redistribute_instance_source,
8283 no_ospf_redistribute_instance_source_cmd,
8284 "no redistribute <ospf|table> (1-65535) [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
8285 NO_STR
8286 REDIST_STR
8287 "Open Shortest Path First\n"
8288 "Non-main Kernel Routing Table\n"
8289 "Instance ID/Table Id\n"
8290 "Metric for redistributed routes\n"
8291 "OSPF default metric\n"
8292 "OSPF exterior metric type for redistributed routes\n"
8293 "Set OSPF External Type 1/2 metrics\n"
8294 "Route map reference\n"
8295 "Pointer to route-map entries\n")
8296 {
8297 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
8298 int idx_ospf_table = 2;
8299 int idx_number = 3;
8300 unsigned int instance;
8301 struct ospf_redist *red;
8302 int source;
8303
8304 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
8305 source = ZEBRA_ROUTE_OSPF;
8306 else
8307 source = ZEBRA_ROUTE_TABLE;
8308
8309 instance = strtoul(argv[idx_number]->arg, NULL, 10);
8310
8311 if ((source == ZEBRA_ROUTE_OSPF) && !ospf->instance) {
8312 vty_out(vty,
8313 "Instance redistribution in non-instanced OSPF not allowed\n");
8314 return CMD_WARNING_CONFIG_FAILED;
8315 }
8316
8317 if ((source == ZEBRA_ROUTE_OSPF) && (ospf->instance == instance)) {
8318 vty_out(vty, "Same instance OSPF redistribution not allowed\n");
8319 return CMD_WARNING_CONFIG_FAILED;
8320 }
8321
8322 red = ospf_redist_lookup(ospf, source, instance);
8323 if (!red)
8324 return CMD_SUCCESS;
8325
8326 ospf_routemap_unset(red);
8327 ospf_redist_del(ospf, source, instance);
8328
8329 return ospf_redistribute_unset(ospf, source, instance);
8330 }
8331
8332 DEFUN (ospf_distribute_list_out,
8333 ospf_distribute_list_out_cmd,
8334 "distribute-list WORD out " FRR_REDIST_STR_OSPFD,
8335 "Filter networks in routing updates\n"
8336 "Access-list name\n"
8337 OUT_STR
8338 FRR_REDIST_HELP_STR_OSPFD)
8339 {
8340 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
8341 int idx_word = 1;
8342 int source;
8343
8344 char *proto = argv[argc - 1]->text;
8345
8346 /* Get distribute source. */
8347 source = proto_redistnum(AFI_IP, proto);
8348 if (source < 0)
8349 return CMD_WARNING_CONFIG_FAILED;
8350
8351 return ospf_distribute_list_out_set(ospf, source, argv[idx_word]->arg);
8352 }
8353
8354 DEFUN (no_ospf_distribute_list_out,
8355 no_ospf_distribute_list_out_cmd,
8356 "no distribute-list WORD out " FRR_REDIST_STR_OSPFD,
8357 NO_STR
8358 "Filter networks in routing updates\n"
8359 "Access-list name\n"
8360 OUT_STR
8361 FRR_REDIST_HELP_STR_OSPFD)
8362 {
8363 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
8364 int idx_word = 2;
8365 int source;
8366
8367 char *proto = argv[argc - 1]->text;
8368 source = proto_redistnum(AFI_IP, proto);
8369 if (source < 0)
8370 return CMD_WARNING_CONFIG_FAILED;
8371
8372 return ospf_distribute_list_out_unset(ospf, source,
8373 argv[idx_word]->arg);
8374 }
8375
8376 /* Default information originate. */
8377 DEFUN (ospf_default_information_originate,
8378 ospf_default_information_originate_cmd,
8379 "default-information originate [{always|metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
8380 "Control distribution of default information\n"
8381 "Distribute a default route\n"
8382 "Always advertise default route\n"
8383 "OSPF default metric\n"
8384 "OSPF metric\n"
8385 "OSPF metric type for default routes\n"
8386 "Set OSPF External Type 1/2 metrics\n"
8387 "Route map reference\n"
8388 "Pointer to route-map entries\n")
8389 {
8390 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
8391 int default_originate = DEFAULT_ORIGINATE_ZEBRA;
8392 int type = -1;
8393 int metric = -1;
8394 struct ospf_redist *red;
8395 int idx = 0;
8396 int cur_originate = ospf->default_originate;
8397 int sameRtmap = 0;
8398 char *rtmap = NULL;
8399
8400 red = ospf_redist_add(ospf, DEFAULT_ROUTE, 0);
8401
8402 /* Check whether "always" was specified */
8403 if (argv_find(argv, argc, "always", &idx))
8404 default_originate = DEFAULT_ORIGINATE_ALWAYS;
8405 idx = 1;
8406 /* Get metric value */
8407 if (argv_find(argv, argc, "(0-16777214)", &idx)) {
8408 if (!str2metric(argv[idx]->arg, &metric))
8409 return CMD_WARNING_CONFIG_FAILED;
8410 }
8411 idx = 1;
8412 /* Get metric type. */
8413 if (argv_find(argv, argc, "(1-2)", &idx)) {
8414 if (!str2metric_type(argv[idx]->arg, &type))
8415 return CMD_WARNING_CONFIG_FAILED;
8416 }
8417 idx = 1;
8418 /* Get route-map */
8419 if (argv_find(argv, argc, "WORD", &idx))
8420 rtmap = argv[idx]->arg;
8421
8422 /* To check ,if user is providing same route map */
8423 if ((rtmap == ROUTEMAP_NAME(red)) ||
8424 (rtmap && ROUTEMAP_NAME(red)
8425 && (strcmp(rtmap, ROUTEMAP_NAME(red)) == 0)))
8426 sameRtmap = 1;
8427
8428 /* Don't allow if the same lsa is aleardy originated. */
8429 if ((sameRtmap)
8430 && (red->dmetric.type == type)
8431 && (red->dmetric.value == metric)
8432 && (cur_originate == default_originate))
8433 return CMD_SUCCESS;
8434
8435 /* Updating Metric details */
8436 red->dmetric.type = type;
8437 red->dmetric.value = metric;
8438
8439 /* updating route map details */
8440 if (rtmap)
8441 ospf_routemap_set(red, rtmap);
8442 else
8443 ospf_routemap_unset(red);
8444
8445 return ospf_redistribute_default_set(ospf, default_originate, type,
8446 metric);
8447 }
8448
8449 DEFUN (no_ospf_default_information_originate,
8450 no_ospf_default_information_originate_cmd,
8451 "no default-information originate [{always|metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
8452 NO_STR
8453 "Control distribution of default information\n"
8454 "Distribute a default route\n"
8455 "Always advertise default route\n"
8456 "OSPF default metric\n"
8457 "OSPF metric\n"
8458 "OSPF metric type for default routes\n"
8459 "Set OSPF External Type 1/2 metrics\n"
8460 "Route map reference\n"
8461 "Pointer to route-map entries\n")
8462 {
8463 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
8464 struct prefix_ipv4 p;
8465 struct ospf_external *ext;
8466 struct ospf_redist *red;
8467
8468 p.family = AF_INET;
8469 p.prefix.s_addr = 0;
8470 p.prefixlen = 0;
8471
8472 ospf_external_lsa_flush(ospf, DEFAULT_ROUTE, &p, 0);
8473
8474 ext = ospf_external_lookup(ospf, DEFAULT_ROUTE, 0);
8475 if (ext && EXTERNAL_INFO(ext)) {
8476 ospf_external_info_delete(ospf, DEFAULT_ROUTE, 0, p);
8477 ospf_external_del(ospf, DEFAULT_ROUTE, 0);
8478 }
8479
8480 red = ospf_redist_lookup(ospf, DEFAULT_ROUTE, 0);
8481 if (!red)
8482 return CMD_SUCCESS;
8483
8484 ospf_routemap_unset(red);
8485 ospf_redist_del(ospf, DEFAULT_ROUTE, 0);
8486
8487 return ospf_redistribute_default_unset(ospf);
8488 }
8489
8490 DEFUN (ospf_default_metric,
8491 ospf_default_metric_cmd,
8492 "default-metric (0-16777214)",
8493 "Set metric of redistributed routes\n"
8494 "Default metric\n")
8495 {
8496 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
8497 int idx_number = 1;
8498 int metric = -1;
8499
8500 if (!str2metric(argv[idx_number]->arg, &metric))
8501 return CMD_WARNING_CONFIG_FAILED;
8502
8503 ospf->default_metric = metric;
8504
8505 return CMD_SUCCESS;
8506 }
8507
8508 DEFUN (no_ospf_default_metric,
8509 no_ospf_default_metric_cmd,
8510 "no default-metric [(0-16777214)]",
8511 NO_STR
8512 "Set metric of redistributed routes\n"
8513 "Default metric\n")
8514 {
8515 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
8516
8517 ospf->default_metric = -1;
8518
8519 return CMD_SUCCESS;
8520 }
8521
8522
8523 DEFUN (ospf_distance,
8524 ospf_distance_cmd,
8525 "distance (1-255)",
8526 "Administrative distance\n"
8527 "OSPF Administrative distance\n")
8528 {
8529 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
8530 int idx_number = 1;
8531
8532 ospf->distance_all = atoi(argv[idx_number]->arg);
8533
8534 return CMD_SUCCESS;
8535 }
8536
8537 DEFUN (no_ospf_distance,
8538 no_ospf_distance_cmd,
8539 "no distance (1-255)",
8540 NO_STR
8541 "Administrative distance\n"
8542 "OSPF Administrative distance\n")
8543 {
8544 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
8545
8546 ospf->distance_all = 0;
8547
8548 return CMD_SUCCESS;
8549 }
8550
8551 DEFUN (no_ospf_distance_ospf,
8552 no_ospf_distance_ospf_cmd,
8553 "no distance ospf [{intra-area [(1-255)]|inter-area [(1-255)]|external [(1-255)]}]",
8554 NO_STR
8555 "Administrative distance\n"
8556 "OSPF administrative distance\n"
8557 "Intra-area routes\n"
8558 "Distance for intra-area routes\n"
8559 "Inter-area routes\n"
8560 "Distance for inter-area routes\n"
8561 "External routes\n"
8562 "Distance for external routes\n")
8563 {
8564 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
8565 int idx = 0;
8566
8567 if (argv_find(argv, argc, "intra-area", &idx) || argc == 3)
8568 idx = ospf->distance_intra = 0;
8569 if (argv_find(argv, argc, "inter-area", &idx) || argc == 3)
8570 idx = ospf->distance_inter = 0;
8571 if (argv_find(argv, argc, "external", &idx) || argc == 3)
8572 ospf->distance_external = 0;
8573
8574 return CMD_SUCCESS;
8575 }
8576
8577 DEFUN (ospf_distance_ospf,
8578 ospf_distance_ospf_cmd,
8579 "distance ospf {intra-area (1-255)|inter-area (1-255)|external (1-255)}",
8580 "Administrative distance\n"
8581 "OSPF administrative distance\n"
8582 "Intra-area routes\n"
8583 "Distance for intra-area routes\n"
8584 "Inter-area routes\n"
8585 "Distance for inter-area routes\n"
8586 "External routes\n"
8587 "Distance for external routes\n")
8588 {
8589 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
8590 int idx = 0;
8591
8592 ospf->distance_intra = 0;
8593 ospf->distance_inter = 0;
8594 ospf->distance_external = 0;
8595
8596 if (argv_find(argv, argc, "intra-area", &idx))
8597 ospf->distance_intra = atoi(argv[idx + 1]->arg);
8598 idx = 0;
8599 if (argv_find(argv, argc, "inter-area", &idx))
8600 ospf->distance_inter = atoi(argv[idx + 1]->arg);
8601 idx = 0;
8602 if (argv_find(argv, argc, "external", &idx))
8603 ospf->distance_external = atoi(argv[idx + 1]->arg);
8604
8605 return CMD_SUCCESS;
8606 }
8607
8608 #if 0
8609 DEFUN (ospf_distance_source,
8610 ospf_distance_source_cmd,
8611 "distance (1-255) A.B.C.D/M",
8612 "Administrative distance\n"
8613 "Distance value\n"
8614 "IP source prefix\n")
8615 {
8616 VTY_DECLVAR_CONTEXT(ospf, ospf);
8617 int idx_number = 1;
8618 int idx_ipv4_prefixlen = 2;
8619
8620 ospf_distance_set (vty, ospf, argv[idx_number]->arg, argv[idx_ipv4_prefixlen]->arg, NULL);
8621
8622 return CMD_SUCCESS;
8623 }
8624
8625 DEFUN (no_ospf_distance_source,
8626 no_ospf_distance_source_cmd,
8627 "no distance (1-255) A.B.C.D/M",
8628 NO_STR
8629 "Administrative distance\n"
8630 "Distance value\n"
8631 "IP source prefix\n")
8632 {
8633 VTY_DECLVAR_CONTEXT(ospf, ospf);
8634 int idx_number = 2;
8635 int idx_ipv4_prefixlen = 3;
8636
8637 ospf_distance_unset (vty, ospf, argv[idx_number]->arg, argv[idx_ipv4_prefixlen]->arg, NULL);
8638
8639 return CMD_SUCCESS;
8640 }
8641
8642 DEFUN (ospf_distance_source_access_list,
8643 ospf_distance_source_access_list_cmd,
8644 "distance (1-255) A.B.C.D/M WORD",
8645 "Administrative distance\n"
8646 "Distance value\n"
8647 "IP source prefix\n"
8648 "Access list name\n")
8649 {
8650 VTY_DECLVAR_CONTEXT(ospf, ospf);
8651 int idx_number = 1;
8652 int idx_ipv4_prefixlen = 2;
8653 int idx_word = 3;
8654
8655 ospf_distance_set (vty, ospf, argv[idx_number]->arg, argv[idx_ipv4_prefixlen]->arg, argv[idx_word]->arg);
8656
8657 return CMD_SUCCESS;
8658 }
8659
8660 DEFUN (no_ospf_distance_source_access_list,
8661 no_ospf_distance_source_access_list_cmd,
8662 "no distance (1-255) A.B.C.D/M WORD",
8663 NO_STR
8664 "Administrative distance\n"
8665 "Distance value\n"
8666 "IP source prefix\n"
8667 "Access list name\n")
8668 {
8669 VTY_DECLVAR_CONTEXT(ospf, ospf);
8670 int idx_number = 2;
8671 int idx_ipv4_prefixlen = 3;
8672 int idx_word = 4;
8673
8674 ospf_distance_unset (vty, ospf, argv[idx_number]->arg, argv[idx_ipv4_prefixlen]->arg, argv[idx_word]->arg);
8675
8676 return CMD_SUCCESS;
8677 }
8678 #endif
8679
8680 DEFUN (ip_ospf_mtu_ignore,
8681 ip_ospf_mtu_ignore_addr_cmd,
8682 "ip ospf mtu-ignore [A.B.C.D]",
8683 "IP Information\n"
8684 "OSPF interface commands\n"
8685 "Disable MTU mismatch detection on this interface\n"
8686 "Address of interface\n")
8687 {
8688 VTY_DECLVAR_CONTEXT(interface, ifp);
8689 int idx_ipv4 = 3;
8690 struct in_addr addr;
8691 int ret;
8692
8693 struct ospf_if_params *params;
8694 params = IF_DEF_PARAMS(ifp);
8695
8696 if (argc == 4) {
8697 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
8698 if (!ret) {
8699 vty_out(vty,
8700 "Please specify interface address by A.B.C.D\n");
8701 return CMD_WARNING_CONFIG_FAILED;
8702 }
8703 params = ospf_get_if_params(ifp, addr);
8704 ospf_if_update_params(ifp, addr);
8705 }
8706 params->mtu_ignore = 1;
8707 if (params->mtu_ignore != OSPF_MTU_IGNORE_DEFAULT)
8708 SET_IF_PARAM(params, mtu_ignore);
8709 else {
8710 UNSET_IF_PARAM(params, mtu_ignore);
8711 if (params != IF_DEF_PARAMS(ifp)) {
8712 ospf_free_if_params(ifp, addr);
8713 ospf_if_update_params(ifp, addr);
8714 }
8715 }
8716 return CMD_SUCCESS;
8717 }
8718
8719 DEFUN (no_ip_ospf_mtu_ignore,
8720 no_ip_ospf_mtu_ignore_addr_cmd,
8721 "no ip ospf mtu-ignore [A.B.C.D]",
8722 NO_STR
8723 "IP Information\n"
8724 "OSPF interface commands\n"
8725 "Disable MTU mismatch detection on this interface\n"
8726 "Address of interface\n")
8727 {
8728 VTY_DECLVAR_CONTEXT(interface, ifp);
8729 int idx_ipv4 = 4;
8730 struct in_addr addr;
8731 int ret;
8732
8733 struct ospf_if_params *params;
8734 params = IF_DEF_PARAMS(ifp);
8735
8736 if (argc == 5) {
8737 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
8738 if (!ret) {
8739 vty_out(vty,
8740 "Please specify interface address by A.B.C.D\n");
8741 return CMD_WARNING_CONFIG_FAILED;
8742 }
8743 params = ospf_get_if_params(ifp, addr);
8744 ospf_if_update_params(ifp, addr);
8745 }
8746 params->mtu_ignore = 0;
8747 if (params->mtu_ignore != OSPF_MTU_IGNORE_DEFAULT)
8748 SET_IF_PARAM(params, mtu_ignore);
8749 else {
8750 UNSET_IF_PARAM(params, mtu_ignore);
8751 if (params != IF_DEF_PARAMS(ifp)) {
8752 ospf_free_if_params(ifp, addr);
8753 ospf_if_update_params(ifp, addr);
8754 }
8755 }
8756 return CMD_SUCCESS;
8757 }
8758
8759
8760 DEFUN (ospf_max_metric_router_lsa_admin,
8761 ospf_max_metric_router_lsa_admin_cmd,
8762 "max-metric router-lsa administrative",
8763 "OSPF maximum / infinite-distance metric\n"
8764 "Advertise own Router-LSA with infinite distance (stub router)\n"
8765 "Administratively applied, for an indefinite period\n")
8766 {
8767 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
8768 struct listnode *ln;
8769 struct ospf_area *area;
8770
8771 for (ALL_LIST_ELEMENTS_RO(ospf->areas, ln, area)) {
8772 SET_FLAG(area->stub_router_state, OSPF_AREA_ADMIN_STUB_ROUTED);
8773
8774 if (!CHECK_FLAG(area->stub_router_state,
8775 OSPF_AREA_IS_STUB_ROUTED))
8776 ospf_router_lsa_update_area(area);
8777 }
8778
8779 /* Allows for areas configured later to get the property */
8780 ospf->stub_router_admin_set = OSPF_STUB_ROUTER_ADMINISTRATIVE_SET;
8781
8782 return CMD_SUCCESS;
8783 }
8784
8785 DEFUN (no_ospf_max_metric_router_lsa_admin,
8786 no_ospf_max_metric_router_lsa_admin_cmd,
8787 "no max-metric router-lsa administrative",
8788 NO_STR
8789 "OSPF maximum / infinite-distance metric\n"
8790 "Advertise own Router-LSA with infinite distance (stub router)\n"
8791 "Administratively applied, for an indefinite period\n")
8792 {
8793 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
8794 struct listnode *ln;
8795 struct ospf_area *area;
8796
8797 for (ALL_LIST_ELEMENTS_RO(ospf->areas, ln, area)) {
8798 UNSET_FLAG(area->stub_router_state,
8799 OSPF_AREA_ADMIN_STUB_ROUTED);
8800
8801 /* Don't trample on the start-up stub timer */
8802 if (CHECK_FLAG(area->stub_router_state,
8803 OSPF_AREA_IS_STUB_ROUTED)
8804 && !area->t_stub_router) {
8805 UNSET_FLAG(area->stub_router_state,
8806 OSPF_AREA_IS_STUB_ROUTED);
8807 ospf_router_lsa_update_area(area);
8808 }
8809 }
8810 ospf->stub_router_admin_set = OSPF_STUB_ROUTER_ADMINISTRATIVE_UNSET;
8811 return CMD_SUCCESS;
8812 }
8813
8814 DEFUN (ospf_max_metric_router_lsa_startup,
8815 ospf_max_metric_router_lsa_startup_cmd,
8816 "max-metric router-lsa on-startup (5-86400)",
8817 "OSPF maximum / infinite-distance metric\n"
8818 "Advertise own Router-LSA with infinite distance (stub router)\n"
8819 "Automatically advertise stub Router-LSA on startup of OSPF\n"
8820 "Time (seconds) to advertise self as stub-router\n")
8821 {
8822 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
8823 int idx_number = 3;
8824 unsigned int seconds;
8825
8826 if (argc < 4) {
8827 vty_out(vty, "%% Must supply stub-router period");
8828 return CMD_WARNING_CONFIG_FAILED;
8829 }
8830
8831 seconds = strtoul(argv[idx_number]->arg, NULL, 10);
8832
8833 ospf->stub_router_startup_time = seconds;
8834
8835 return CMD_SUCCESS;
8836 }
8837
8838 DEFUN (no_ospf_max_metric_router_lsa_startup,
8839 no_ospf_max_metric_router_lsa_startup_cmd,
8840 "no max-metric router-lsa on-startup [(5-86400)]",
8841 NO_STR
8842 "OSPF maximum / infinite-distance metric\n"
8843 "Advertise own Router-LSA with infinite distance (stub router)\n"
8844 "Automatically advertise stub Router-LSA on startup of OSPF\n"
8845 "Time (seconds) to advertise self as stub-router\n")
8846 {
8847 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
8848 struct listnode *ln;
8849 struct ospf_area *area;
8850
8851 ospf->stub_router_startup_time = OSPF_STUB_ROUTER_UNCONFIGURED;
8852
8853 for (ALL_LIST_ELEMENTS_RO(ospf->areas, ln, area)) {
8854 SET_FLAG(area->stub_router_state,
8855 OSPF_AREA_WAS_START_STUB_ROUTED);
8856 OSPF_TIMER_OFF(area->t_stub_router);
8857
8858 /* Don't trample on admin stub routed */
8859 if (!CHECK_FLAG(area->stub_router_state,
8860 OSPF_AREA_ADMIN_STUB_ROUTED)) {
8861 UNSET_FLAG(area->stub_router_state,
8862 OSPF_AREA_IS_STUB_ROUTED);
8863 ospf_router_lsa_update_area(area);
8864 }
8865 }
8866 return CMD_SUCCESS;
8867 }
8868
8869
8870 DEFUN (ospf_max_metric_router_lsa_shutdown,
8871 ospf_max_metric_router_lsa_shutdown_cmd,
8872 "max-metric router-lsa on-shutdown (5-100)",
8873 "OSPF maximum / infinite-distance metric\n"
8874 "Advertise own Router-LSA with infinite distance (stub router)\n"
8875 "Advertise stub-router prior to full shutdown of OSPF\n"
8876 "Time (seconds) to wait till full shutdown\n")
8877 {
8878 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
8879 int idx_number = 3;
8880 unsigned int seconds;
8881
8882 if (argc < 4) {
8883 vty_out(vty, "%% Must supply stub-router shutdown period");
8884 return CMD_WARNING_CONFIG_FAILED;
8885 }
8886
8887 seconds = strtoul(argv[idx_number]->arg, NULL, 10);
8888
8889 ospf->stub_router_shutdown_time = seconds;
8890
8891 return CMD_SUCCESS;
8892 }
8893
8894 DEFUN (no_ospf_max_metric_router_lsa_shutdown,
8895 no_ospf_max_metric_router_lsa_shutdown_cmd,
8896 "no max-metric router-lsa on-shutdown [(5-100)]",
8897 NO_STR
8898 "OSPF maximum / infinite-distance metric\n"
8899 "Advertise own Router-LSA with infinite distance (stub router)\n"
8900 "Advertise stub-router prior to full shutdown of OSPF\n"
8901 "Time (seconds) to wait till full shutdown\n")
8902 {
8903 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
8904
8905 ospf->stub_router_shutdown_time = OSPF_STUB_ROUTER_UNCONFIGURED;
8906
8907 return CMD_SUCCESS;
8908 }
8909
8910 static void config_write_stub_router(struct vty *vty, struct ospf *ospf)
8911 {
8912 struct listnode *ln;
8913 struct ospf_area *area;
8914
8915 if (ospf->stub_router_startup_time != OSPF_STUB_ROUTER_UNCONFIGURED)
8916 vty_out(vty, " max-metric router-lsa on-startup %u\n",
8917 ospf->stub_router_startup_time);
8918 if (ospf->stub_router_shutdown_time != OSPF_STUB_ROUTER_UNCONFIGURED)
8919 vty_out(vty, " max-metric router-lsa on-shutdown %u\n",
8920 ospf->stub_router_shutdown_time);
8921 for (ALL_LIST_ELEMENTS_RO(ospf->areas, ln, area)) {
8922 if (CHECK_FLAG(area->stub_router_state,
8923 OSPF_AREA_ADMIN_STUB_ROUTED)) {
8924 vty_out(vty, " max-metric router-lsa administrative\n");
8925 break;
8926 }
8927 }
8928 return;
8929 }
8930
8931 static void show_ip_ospf_route_network(struct vty *vty, struct ospf *ospf,
8932 struct route_table *rt,
8933 json_object *json)
8934 {
8935 struct route_node *rn;
8936 struct ospf_route * or ;
8937 struct listnode *pnode, *pnnode;
8938 struct ospf_path *path;
8939 json_object *json_route = NULL, *json_nexthop_array = NULL,
8940 *json_nexthop = NULL;
8941
8942 if (!json)
8943 vty_out(vty,
8944 "============ OSPF network routing table ============\n");
8945
8946 for (rn = route_top(rt); rn; rn = route_next(rn)) {
8947 if ((or = rn->info) == NULL)
8948 continue;
8949 char buf1[PREFIX2STR_BUFFER];
8950
8951 memset(buf1, 0, sizeof(buf1));
8952 prefix2str(&rn->p, buf1, sizeof(buf1));
8953
8954 json_route = json_object_new_object();
8955 if (json) {
8956 json_object_object_add(json, buf1, json_route);
8957 json_object_to_json_string_ext(
8958 json, JSON_C_TO_STRING_NOSLASHESCAPE);
8959 }
8960
8961 switch (or->path_type) {
8962 case OSPF_PATH_INTER_AREA:
8963 if (or->type == OSPF_DESTINATION_NETWORK) {
8964 if (json) {
8965 json_object_string_add(json_route,
8966 "routeType",
8967 "N IA");
8968 json_object_int_add(json_route, "cost",
8969 or->cost);
8970 json_object_string_add(
8971 json_route, "area",
8972 inet_ntoa(or->u.std.area_id));
8973 } else {
8974 vty_out(vty,
8975 "N IA %-18s [%d] area: %s\n",
8976 buf1, or->cost,
8977 inet_ntoa(or->u.std.area_id));
8978 }
8979 } else if (or->type == OSPF_DESTINATION_DISCARD) {
8980 if (json) {
8981 json_object_string_add(json_route,
8982 "routeType",
8983 "D IA");
8984 } else {
8985 vty_out(vty,
8986 "D IA %-18s Discard entry\n",
8987 buf1);
8988 }
8989 }
8990 break;
8991 case OSPF_PATH_INTRA_AREA:
8992 if (json) {
8993 json_object_string_add(json_route, "routeType",
8994 "N");
8995 json_object_int_add(json_route, "cost",
8996 or->cost);
8997 json_object_string_add(
8998 json_route, "area",
8999 inet_ntoa(or->u.std.area_id));
9000 } else {
9001 vty_out(vty, "N %-18s [%d] area: %s\n",
9002 buf1, or->cost,
9003 inet_ntoa(or->u.std.area_id));
9004 }
9005 break;
9006 default:
9007 break;
9008 }
9009
9010 if (or->type == OSPF_DESTINATION_NETWORK) {
9011 if (json) {
9012 json_nexthop_array = json_object_new_array();
9013 json_object_object_add(json_route, "nexthops",
9014 json_nexthop_array);
9015 }
9016
9017 for (ALL_LIST_ELEMENTS(or->paths, pnode, pnnode,
9018 path)) {
9019 if (json) {
9020 json_nexthop = json_object_new_object();
9021 json_object_array_add(
9022 json_nexthop_array,
9023 json_nexthop);
9024 }
9025 if (if_lookup_by_index(path->ifindex,
9026 ospf->vrf_id)) {
9027
9028 if (path->nexthop.s_addr == 0) {
9029 if (json) {
9030 json_object_string_add(
9031 json_nexthop,
9032 "ip", " ");
9033 json_object_string_add(
9034 json_nexthop,
9035 "directly attached to",
9036 ifindex2ifname(
9037 path->ifindex,
9038 ospf->vrf_id));
9039 } else {
9040 vty_out(vty,
9041 "%24s directly attached to %s\n",
9042 "",
9043 ifindex2ifname(
9044 path->ifindex,
9045 ospf->vrf_id));
9046 }
9047 } else {
9048 if (json) {
9049 json_object_string_add(
9050 json_nexthop,
9051 "ip",
9052 inet_ntoa(
9053 path->nexthop));
9054 json_object_string_add(
9055 json_nexthop,
9056 "via",
9057 ifindex2ifname(
9058 path->ifindex,
9059 ospf->vrf_id));
9060 } else {
9061 vty_out(vty,
9062 "%24s via %s, %s\n",
9063 "",
9064 inet_ntoa(
9065 path->nexthop),
9066 ifindex2ifname(
9067 path->ifindex,
9068 ospf->vrf_id));
9069 }
9070 }
9071 }
9072 }
9073 }
9074 if (!json)
9075 json_object_free(json_route);
9076 }
9077 if (!json)
9078 vty_out(vty, "\n");
9079 }
9080
9081 static void show_ip_ospf_route_router(struct vty *vty, struct ospf *ospf,
9082 struct route_table *rtrs,
9083 json_object *json)
9084 {
9085 struct route_node *rn;
9086 struct ospf_route * or ;
9087 struct listnode *pnode;
9088 struct listnode *node;
9089 struct ospf_path *path;
9090 json_object *json_route = NULL, *json_nexthop_array = NULL,
9091 *json_nexthop = NULL;
9092
9093 if (!json)
9094 vty_out(vty,
9095 "============ OSPF router routing table =============\n");
9096
9097 for (rn = route_top(rtrs); rn; rn = route_next(rn)) {
9098 if (rn->info == NULL)
9099 continue;
9100 int flag = 0;
9101
9102 json_route = json_object_new_object();
9103 if (json) {
9104 json_object_object_add(json, inet_ntoa(rn->p.u.prefix4),
9105 json_route);
9106 json_object_string_add(json_route, "routeType", "R ");
9107 } else {
9108 vty_out(vty, "R %-15s ",
9109 inet_ntoa(rn->p.u.prefix4));
9110 }
9111
9112 for (ALL_LIST_ELEMENTS_RO((struct list *)rn->info, node, or)) {
9113 if (flag++) {
9114 if (!json)
9115 vty_out(vty, "%24s", "");
9116 }
9117
9118 /* Show path. */
9119 if (json) {
9120 json_object_int_add(json_route, "cost",
9121 or->cost);
9122 json_object_string_add(
9123 json_route, "area",
9124 inet_ntoa(or->u.std.area_id));
9125 if (or->path_type == OSPF_PATH_INTER_AREA)
9126 json_object_boolean_true_add(json_route,
9127 "IA");
9128 if (or->u.std.flags & ROUTER_LSA_BORDER)
9129 json_object_string_add(json_route,
9130 "routerType",
9131 "abr");
9132 else if (or->u.std.flags & ROUTER_LSA_EXTERNAL)
9133 json_object_string_add(json_route,
9134 "routerType",
9135 "asbr");
9136 } else {
9137 vty_out(vty, "%s [%d] area: %s",
9138 (or->path_type == OSPF_PATH_INTER_AREA
9139 ? "IA"
9140 : " "),
9141 or->cost, inet_ntoa(or->u.std.area_id));
9142 /* Show flags. */
9143 vty_out(vty, "%s%s\n",
9144 (or->u.std.flags & ROUTER_LSA_BORDER
9145 ? ", ABR"
9146 : ""),
9147 (or->u.std.flags & ROUTER_LSA_EXTERNAL
9148 ? ", ASBR"
9149 : ""));
9150 }
9151
9152 if (json) {
9153 json_nexthop_array = json_object_new_array();
9154 json_object_object_add(json_route, "nexthops",
9155 json_nexthop_array);
9156 }
9157
9158 for (ALL_LIST_ELEMENTS_RO(or->paths, pnode, path)) {
9159 if (json) {
9160 json_nexthop = json_object_new_object();
9161 json_object_array_add(
9162 json_nexthop_array,
9163 json_nexthop);
9164 }
9165 if (if_lookup_by_index(path->ifindex,
9166 ospf->vrf_id)) {
9167 if (path->nexthop.s_addr == 0) {
9168 if (json) {
9169 json_object_string_add(
9170 json_nexthop,
9171 "ip", " ");
9172 json_object_string_add(
9173 json_nexthop,
9174 "directly attached to",
9175 ifindex2ifname(
9176 path->ifindex,
9177 ospf->vrf_id));
9178 } else {
9179 vty_out(vty,
9180 "%24s directly attached to %s\n",
9181 "",
9182 ifindex2ifname(
9183 path->ifindex,
9184 ospf->vrf_id));
9185 }
9186 } else {
9187 if (json) {
9188 json_object_string_add(
9189 json_nexthop,
9190 "ip",
9191 inet_ntoa(
9192 path->nexthop));
9193 json_object_string_add(
9194 json_nexthop,
9195 "via",
9196 ifindex2ifname(
9197 path->ifindex,
9198 ospf->vrf_id));
9199 } else {
9200 vty_out(vty,
9201 "%24s via %s, %s\n",
9202 "",
9203 inet_ntoa(
9204 path->nexthop),
9205 ifindex2ifname(
9206 path->ifindex,
9207 ospf->vrf_id));
9208 }
9209 }
9210 }
9211 }
9212 }
9213 if (!json)
9214 json_object_free(json_route);
9215 }
9216 if (!json)
9217 vty_out(vty, "\n");
9218 }
9219
9220 static void show_ip_ospf_route_external(struct vty *vty, struct ospf *ospf,
9221 struct route_table *rt,
9222 json_object *json)
9223 {
9224 struct route_node *rn;
9225 struct ospf_route *er;
9226 struct listnode *pnode, *pnnode;
9227 struct ospf_path *path;
9228 json_object *json_route = NULL, *json_nexthop_array = NULL,
9229 *json_nexthop = NULL;
9230
9231 if (!json)
9232 vty_out(vty,
9233 "============ OSPF external routing table ===========\n");
9234
9235 for (rn = route_top(rt); rn; rn = route_next(rn)) {
9236 if ((er = rn->info) == NULL)
9237 continue;
9238
9239 char buf1[19];
9240
9241 snprintf(buf1, 19, "%s/%d", inet_ntoa(rn->p.u.prefix4),
9242 rn->p.prefixlen);
9243 json_route = json_object_new_object();
9244 if (json) {
9245 json_object_object_add(json, buf1, json_route);
9246 json_object_to_json_string_ext(
9247 json, JSON_C_TO_STRING_NOSLASHESCAPE);
9248 }
9249
9250 switch (er->path_type) {
9251 case OSPF_PATH_TYPE1_EXTERNAL:
9252 if (json) {
9253 json_object_string_add(json_route, "routeType",
9254 "N E1");
9255 json_object_int_add(json_route, "cost",
9256 er->cost);
9257 } else {
9258 vty_out(vty,
9259 "N E1 %-18s [%d] tag: %" ROUTE_TAG_PRI
9260 "\n",
9261 buf1, er->cost, er->u.ext.tag);
9262 }
9263 break;
9264 case OSPF_PATH_TYPE2_EXTERNAL:
9265 if (json) {
9266 json_object_string_add(json_route, "routeType",
9267 "N E2");
9268 json_object_int_add(json_route, "cost",
9269 er->cost);
9270 } else {
9271 vty_out(vty,
9272 "N E2 %-18s [%d/%d] tag: %" ROUTE_TAG_PRI
9273 "\n",
9274 buf1, er->cost, er->u.ext.type2_cost,
9275 er->u.ext.tag);
9276 }
9277 break;
9278 }
9279
9280 if (json) {
9281 json_nexthop_array = json_object_new_array();
9282 json_object_object_add(json_route, "nexthops",
9283 json_nexthop_array);
9284 }
9285
9286 for (ALL_LIST_ELEMENTS(er->paths, pnode, pnnode, path)) {
9287 if (json) {
9288 json_nexthop = json_object_new_object();
9289 json_object_array_add(json_nexthop_array,
9290 json_nexthop);
9291 }
9292
9293 if (if_lookup_by_index(path->ifindex, ospf->vrf_id)) {
9294 if (path->nexthop.s_addr == 0) {
9295 if (json) {
9296 json_object_string_add(
9297 json_nexthop, "ip",
9298 " ");
9299 json_object_string_add(
9300 json_nexthop,
9301 "directly attached to",
9302 ifindex2ifname(
9303 path->ifindex,
9304 ospf->vrf_id));
9305 } else {
9306 vty_out(vty,
9307 "%24s directly attached to %s\n",
9308 "",
9309 ifindex2ifname(
9310 path->ifindex,
9311 ospf->vrf_id));
9312 }
9313 } else {
9314 if (json) {
9315 json_object_string_add(
9316 json_nexthop, "ip",
9317 inet_ntoa(
9318 path->nexthop));
9319 json_object_string_add(
9320 json_nexthop, "via",
9321 ifindex2ifname(
9322 path->ifindex,
9323 ospf->vrf_id));
9324 } else {
9325 vty_out(vty,
9326 "%24s via %s, %s\n",
9327 "",
9328 inet_ntoa(
9329 path->nexthop),
9330 ifindex2ifname(
9331 path->ifindex,
9332 ospf->vrf_id));
9333 }
9334 }
9335 }
9336 }
9337 if (!json)
9338 json_object_free(json_route);
9339 }
9340 if (!json)
9341 vty_out(vty, "\n");
9342 }
9343
9344 static int show_ip_ospf_border_routers_common(struct vty *vty,
9345 struct ospf *ospf,
9346 uint8_t use_vrf)
9347 {
9348 if (ospf->instance)
9349 vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
9350
9351 ospf_show_vrf_name(ospf, vty, NULL, use_vrf);
9352
9353 if (ospf->new_table == NULL) {
9354 vty_out(vty, "No OSPF routing information exist\n");
9355 return CMD_SUCCESS;
9356 }
9357
9358 /* Show Network routes.
9359 show_ip_ospf_route_network (vty, ospf->new_table); */
9360
9361 /* Show Router routes. */
9362 show_ip_ospf_route_router(vty, ospf, ospf->new_rtrs, NULL);
9363
9364 vty_out(vty, "\n");
9365
9366 return CMD_SUCCESS;
9367 }
9368
9369 DEFUN (show_ip_ospf_border_routers,
9370 show_ip_ospf_border_routers_cmd,
9371 "show ip ospf [vrf <NAME|all>] border-routers",
9372 SHOW_STR
9373 IP_STR
9374 "OSPF information\n"
9375 VRF_CMD_HELP_STR
9376 "All VRFs\n"
9377 "Show all the ABR's and ASBR's\n")
9378 {
9379 struct ospf *ospf = NULL;
9380 struct listnode *node = NULL;
9381 char *vrf_name = NULL;
9382 bool all_vrf = FALSE;
9383 int ret = CMD_SUCCESS;
9384 int inst = 0;
9385 int idx_vrf = 0;
9386 uint8_t use_vrf = 0;
9387
9388 OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
9389
9390 if (vrf_name) {
9391 bool ospf_output = FALSE;
9392
9393 use_vrf = 1;
9394
9395 if (all_vrf) {
9396 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
9397 if (!ospf->oi_running)
9398 continue;
9399
9400 ospf_output = TRUE;
9401 ret = show_ip_ospf_border_routers_common(
9402 vty, ospf, use_vrf);
9403 }
9404
9405 if (!ospf_output)
9406 vty_out(vty, "%% OSPF instance not found\n");
9407 } else {
9408 ospf = ospf_lookup_by_inst_name(inst, vrf_name);
9409 if (ospf == NULL || !ospf->oi_running) {
9410 vty_out(vty, "%% OSPF instance not found\n");
9411 return CMD_SUCCESS;
9412 }
9413
9414 ret = show_ip_ospf_border_routers_common(vty, ospf,
9415 use_vrf);
9416 }
9417 } else {
9418 /* Display default ospf (instance 0) info */
9419 ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
9420 if (ospf == NULL || !ospf->oi_running) {
9421 vty_out(vty, "%% OSPF instance not found\n");
9422 return CMD_SUCCESS;
9423 }
9424
9425 ret = show_ip_ospf_border_routers_common(vty, ospf, use_vrf);
9426 }
9427
9428 return ret;
9429 }
9430
9431 DEFUN (show_ip_ospf_instance_border_routers,
9432 show_ip_ospf_instance_border_routers_cmd,
9433 "show ip ospf (1-65535) border-routers",
9434 SHOW_STR
9435 IP_STR
9436 "OSPF information\n"
9437 "Instance ID\n"
9438 "Show all the ABR's and ASBR's\n")
9439 {
9440 int idx_number = 3;
9441 struct ospf *ospf;
9442 unsigned short instance = 0;
9443
9444 instance = strtoul(argv[idx_number]->arg, NULL, 10);
9445 ospf = ospf_lookup_instance(instance);
9446 if (ospf == NULL)
9447 return CMD_NOT_MY_INSTANCE;
9448
9449 if (!ospf->oi_running)
9450 return CMD_SUCCESS;
9451
9452 return show_ip_ospf_border_routers_common(vty, ospf, 0);
9453 }
9454
9455 static int show_ip_ospf_route_common(struct vty *vty, struct ospf *ospf,
9456 json_object *json, uint8_t use_vrf)
9457 {
9458 json_object *json_vrf = NULL;
9459
9460 if (ospf->instance)
9461 vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
9462
9463
9464 if (json) {
9465 if (use_vrf)
9466 json_vrf = json_object_new_object();
9467 else
9468 json_vrf = json;
9469 }
9470
9471 ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf);
9472
9473 if (ospf->new_table == NULL) {
9474 vty_out(vty, "No OSPF routing information exist\n");
9475 return CMD_SUCCESS;
9476 }
9477
9478 /* Show Network routes. */
9479 show_ip_ospf_route_network(vty, ospf, ospf->new_table, json_vrf);
9480
9481 /* Show Router routes. */
9482 show_ip_ospf_route_router(vty, ospf, ospf->new_rtrs, json_vrf);
9483
9484 /* Show AS External routes. */
9485 show_ip_ospf_route_external(vty, ospf, ospf->old_external_route,
9486 json_vrf);
9487
9488 if (json) {
9489 if (use_vrf) {
9490 // json_object_object_add(json_vrf, "areas",
9491 // json_areas);
9492 if (ospf->vrf_id == VRF_DEFAULT)
9493 json_object_object_add(json, "default",
9494 json_vrf);
9495 else
9496 json_object_object_add(json, ospf->name,
9497 json_vrf);
9498 }
9499 } else {
9500 vty_out(vty, "\n");
9501 }
9502
9503 return CMD_SUCCESS;
9504 }
9505
9506 DEFUN (show_ip_ospf_route,
9507 show_ip_ospf_route_cmd,
9508 "show ip ospf [vrf <NAME|all>] route [json]",
9509 SHOW_STR
9510 IP_STR
9511 "OSPF information\n"
9512 VRF_CMD_HELP_STR
9513 "All VRFs\n"
9514 "OSPF routing table\n"
9515 JSON_STR)
9516 {
9517 struct ospf *ospf = NULL;
9518 struct listnode *node = NULL;
9519 char *vrf_name = NULL;
9520 bool all_vrf = FALSE;
9521 int ret = CMD_SUCCESS;
9522 int inst = 0;
9523 int idx_vrf = 0;
9524 uint8_t use_vrf = 0;
9525 bool uj = use_json(argc, argv);
9526 json_object *json = NULL;
9527
9528 if (uj)
9529 json = json_object_new_object();
9530
9531 OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
9532
9533 /* vrf input is provided could be all or specific vrf*/
9534 if (vrf_name) {
9535 bool ospf_output = FALSE;
9536
9537 use_vrf = 1;
9538
9539 if (all_vrf) {
9540 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
9541 if (!ospf->oi_running)
9542 continue;
9543 ospf_output = TRUE;
9544 ret = show_ip_ospf_route_common(vty, ospf, json,
9545 use_vrf);
9546 }
9547
9548 if (uj) {
9549 /* Keep Non-pretty format */
9550 vty_out(vty, "%s\n",
9551 json_object_to_json_string(json));
9552 json_object_free(json);
9553 } else if (!ospf_output)
9554 vty_out(vty, "%% OSPF instance not found\n");
9555
9556 return ret;
9557 }
9558 ospf = ospf_lookup_by_inst_name(inst, vrf_name);
9559 if (ospf == NULL || !ospf->oi_running) {
9560 if (uj) {
9561 vty_out(vty, "%s\n",
9562 json_object_to_json_string_ext(
9563 json, JSON_C_TO_STRING_PRETTY));
9564 json_object_free(json);
9565 } else
9566 vty_out(vty, "%% OSPF instance not found\n");
9567
9568 return CMD_SUCCESS;
9569 }
9570 } else {
9571 /* Display default ospf (instance 0) info */
9572 ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
9573 if (ospf == NULL || !ospf->oi_running) {
9574 if (uj) {
9575 vty_out(vty, "%s\n",
9576 json_object_to_json_string_ext(
9577 json, JSON_C_TO_STRING_PRETTY));
9578 json_object_free(json);
9579 } else
9580 vty_out(vty, "%% OSPF instance not found\n");
9581
9582 return CMD_SUCCESS;
9583 }
9584 }
9585
9586 if (ospf) {
9587 ret = show_ip_ospf_route_common(vty, ospf, json, use_vrf);
9588 /* Keep Non-pretty format */
9589 if (uj)
9590 vty_out(vty, "%s\n", json_object_to_json_string(json));
9591 }
9592
9593 if (uj)
9594 json_object_free(json);
9595
9596 return ret;
9597 }
9598
9599 DEFUN (show_ip_ospf_instance_route,
9600 show_ip_ospf_instance_route_cmd,
9601 "show ip ospf (1-65535) route",
9602 SHOW_STR
9603 IP_STR
9604 "OSPF information\n"
9605 "Instance ID\n"
9606 "OSPF routing table\n")
9607 {
9608 int idx_number = 3;
9609 struct ospf *ospf;
9610 unsigned short instance = 0;
9611
9612 instance = strtoul(argv[idx_number]->arg, NULL, 10);
9613 ospf = ospf_lookup_instance(instance);
9614 if (ospf == NULL)
9615 return CMD_NOT_MY_INSTANCE;
9616
9617 if (!ospf->oi_running)
9618 return CMD_SUCCESS;
9619
9620 return show_ip_ospf_route_common(vty, ospf, NULL, 0);
9621 }
9622
9623
9624 DEFUN (show_ip_ospf_vrfs,
9625 show_ip_ospf_vrfs_cmd,
9626 "show ip ospf vrfs [json]",
9627 SHOW_STR
9628 IP_STR
9629 "OSPF information\n"
9630 "Show OSPF VRFs \n"
9631 JSON_STR)
9632 {
9633 bool uj = use_json(argc, argv);
9634 json_object *json = NULL;
9635 json_object *json_vrfs = NULL;
9636 struct ospf *ospf = NULL;
9637 struct listnode *node = NULL;
9638 int count = 0;
9639 static char header[] = "Name Id RouterId ";
9640
9641 if (uj) {
9642 json = json_object_new_object();
9643 json_vrfs = json_object_new_object();
9644 }
9645
9646 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
9647 json_object *json_vrf = NULL;
9648 const char *name = NULL;
9649 int64_t vrf_id_ui = 0;
9650
9651 count++;
9652
9653 if (!uj && count == 1)
9654 vty_out(vty, "%s\n", header);
9655 if (uj)
9656 json_vrf = json_object_new_object();
9657
9658 if (ospf->vrf_id == 0)
9659 name = VRF_DEFAULT_NAME;
9660 else
9661 name = ospf->name;
9662
9663 vrf_id_ui = (ospf->vrf_id == VRF_UNKNOWN)
9664 ? -1
9665 : (int64_t)ospf->vrf_id;
9666
9667 if (uj) {
9668 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
9669 json_object_string_add(json_vrf, "routerId",
9670 inet_ntoa(ospf->router_id));
9671
9672 json_object_object_add(json_vrfs, name, json_vrf);
9673
9674 } else {
9675 vty_out(vty, "%-25s %-5d %-16s \n", name,
9676 ospf->vrf_id, inet_ntoa(ospf->router_id));
9677 }
9678 }
9679
9680 if (uj) {
9681 json_object_object_add(json, "vrfs", json_vrfs);
9682 json_object_int_add(json, "totalVrfs", count);
9683
9684 vty_out(vty, "%s\n", json_object_to_json_string_ext(
9685 json, JSON_C_TO_STRING_PRETTY));
9686 json_object_free(json);
9687 } else {
9688 if (count)
9689 vty_out(vty, "\nTotal number of OSPF VRFs: %d\n",
9690 count);
9691 }
9692
9693 return CMD_SUCCESS;
9694 }
9695
9696 const char *ospf_abr_type_str[] = {"unknown", "standard", "ibm", "cisco",
9697 "shortcut"};
9698
9699 const char *ospf_shortcut_mode_str[] = {"default", "enable", "disable"};
9700
9701 const char *ospf_int_type_str[] = {"unknown", /* should never be used. */
9702 "point-to-point", "broadcast",
9703 "non-broadcast", "point-to-multipoint",
9704 "virtual-link", /* should never be used. */
9705 "loopback"};
9706
9707 static int config_write_interface_one(struct vty *vty, struct vrf *vrf)
9708 {
9709 struct listnode *node;
9710 struct interface *ifp;
9711 struct crypt_key *ck;
9712 struct route_node *rn = NULL;
9713 struct ospf_if_params *params;
9714 int write = 0;
9715 struct ospf *ospf = vrf->info;
9716
9717 FOR_ALL_INTERFACES (vrf, ifp) {
9718
9719 if (memcmp(ifp->name, "VLINK", 5) == 0)
9720 continue;
9721
9722 vty_frame(vty, "!\n");
9723 if (ifp->vrf_id == VRF_DEFAULT)
9724 vty_frame(vty, "interface %s\n", ifp->name);
9725 else
9726 vty_frame(vty, "interface %s vrf %s\n", ifp->name,
9727 vrf->name);
9728 if (ifp->desc)
9729 vty_out(vty, " description %s\n", ifp->desc);
9730
9731 write++;
9732
9733 params = IF_DEF_PARAMS(ifp);
9734
9735 do {
9736 /* Interface Network print. */
9737 if (OSPF_IF_PARAM_CONFIGURED(params, type)
9738 && params->type != OSPF_IFTYPE_LOOPBACK) {
9739 if (params->type != ospf_default_iftype(ifp)) {
9740 vty_out(vty, " ip ospf network %s",
9741 ospf_int_type_str
9742 [params->type]);
9743 if (params != IF_DEF_PARAMS(ifp) && rn)
9744 vty_out(vty, " %s",
9745 inet_ntoa(
9746 rn->p.u.prefix4));
9747 vty_out(vty, "\n");
9748 }
9749 }
9750
9751 /* OSPF interface authentication print */
9752 if (OSPF_IF_PARAM_CONFIGURED(params, auth_type)
9753 && params->auth_type != OSPF_AUTH_NOTSET) {
9754 const char *auth_str;
9755
9756 /* Translation tables are not that much help
9757 * here due to syntax
9758 * of the simple option */
9759 switch (params->auth_type) {
9760
9761 case OSPF_AUTH_NULL:
9762 auth_str = " null";
9763 break;
9764
9765 case OSPF_AUTH_SIMPLE:
9766 auth_str = "";
9767 break;
9768
9769 case OSPF_AUTH_CRYPTOGRAPHIC:
9770 auth_str = " message-digest";
9771 break;
9772
9773 default:
9774 auth_str = "";
9775 break;
9776 }
9777
9778 vty_out(vty, " ip ospf authentication%s",
9779 auth_str);
9780 if (params != IF_DEF_PARAMS(ifp) && rn)
9781 vty_out(vty, " %s",
9782 inet_ntoa(rn->p.u.prefix4));
9783 vty_out(vty, "\n");
9784 }
9785
9786 /* Simple Authentication Password print. */
9787 if (OSPF_IF_PARAM_CONFIGURED(params, auth_simple)
9788 && params->auth_simple[0] != '\0') {
9789 vty_out(vty, " ip ospf authentication-key %s",
9790 params->auth_simple);
9791 if (params != IF_DEF_PARAMS(ifp) && rn)
9792 vty_out(vty, " %s",
9793 inet_ntoa(rn->p.u.prefix4));
9794 vty_out(vty, "\n");
9795 }
9796
9797 /* Cryptographic Authentication Key print. */
9798 if (params && params->auth_crypt) {
9799 for (ALL_LIST_ELEMENTS_RO(params->auth_crypt,
9800 node, ck)) {
9801 vty_out(vty,
9802 " ip ospf message-digest-key %d md5 %s",
9803 ck->key_id, ck->auth_key);
9804 if (params != IF_DEF_PARAMS(ifp) && rn)
9805 vty_out(vty, " %s",
9806 inet_ntoa(
9807 rn->p.u.prefix4));
9808 vty_out(vty, "\n");
9809 }
9810 }
9811
9812 /* Interface Output Cost print. */
9813 if (OSPF_IF_PARAM_CONFIGURED(params, output_cost_cmd)) {
9814 vty_out(vty, " ip ospf cost %u",
9815 params->output_cost_cmd);
9816 if (params != IF_DEF_PARAMS(ifp) && rn)
9817 vty_out(vty, " %s",
9818 inet_ntoa(rn->p.u.prefix4));
9819 vty_out(vty, "\n");
9820 }
9821
9822 /* Hello Interval print. */
9823 if (OSPF_IF_PARAM_CONFIGURED(params, v_hello)
9824 && params->v_hello != OSPF_HELLO_INTERVAL_DEFAULT) {
9825 vty_out(vty, " ip ospf hello-interval %u",
9826 params->v_hello);
9827 if (params != IF_DEF_PARAMS(ifp) && rn)
9828 vty_out(vty, " %s",
9829 inet_ntoa(rn->p.u.prefix4));
9830 vty_out(vty, "\n");
9831 }
9832
9833
9834 /* Router Dead Interval print. */
9835 if (OSPF_IF_PARAM_CONFIGURED(params, v_wait)
9836 && params->v_wait
9837 != OSPF_ROUTER_DEAD_INTERVAL_DEFAULT) {
9838 vty_out(vty, " ip ospf dead-interval ");
9839
9840 /* fast hello ? */
9841 if (OSPF_IF_PARAM_CONFIGURED(params,
9842 fast_hello))
9843 vty_out(vty,
9844 "minimal hello-multiplier %d",
9845 params->fast_hello);
9846 else
9847 vty_out(vty, "%u", params->v_wait);
9848
9849 if (params != IF_DEF_PARAMS(ifp) && rn)
9850 vty_out(vty, " %s",
9851 inet_ntoa(rn->p.u.prefix4));
9852 vty_out(vty, "\n");
9853 }
9854
9855 /* Router Priority print. */
9856 if (OSPF_IF_PARAM_CONFIGURED(params, priority)
9857 && params->priority
9858 != OSPF_ROUTER_PRIORITY_DEFAULT) {
9859 vty_out(vty, " ip ospf priority %u",
9860 params->priority);
9861 if (params != IF_DEF_PARAMS(ifp) && rn)
9862 vty_out(vty, " %s",
9863 inet_ntoa(rn->p.u.prefix4));
9864 vty_out(vty, "\n");
9865 }
9866
9867 /* Retransmit Interval print. */
9868 if (OSPF_IF_PARAM_CONFIGURED(params,
9869 retransmit_interval)
9870 && params->retransmit_interval
9871 != OSPF_RETRANSMIT_INTERVAL_DEFAULT) {
9872 vty_out(vty, " ip ospf retransmit-interval %u",
9873 params->retransmit_interval);
9874 if (params != IF_DEF_PARAMS(ifp) && rn)
9875 vty_out(vty, " %s",
9876 inet_ntoa(rn->p.u.prefix4));
9877 vty_out(vty, "\n");
9878 }
9879
9880 /* Transmit Delay print. */
9881 if (OSPF_IF_PARAM_CONFIGURED(params, transmit_delay)
9882 && params->transmit_delay
9883 != OSPF_TRANSMIT_DELAY_DEFAULT) {
9884 vty_out(vty, " ip ospf transmit-delay %u",
9885 params->transmit_delay);
9886 if (params != IF_DEF_PARAMS(ifp) && rn)
9887 vty_out(vty, " %s",
9888 inet_ntoa(rn->p.u.prefix4));
9889 vty_out(vty, "\n");
9890 }
9891
9892 /* Area print. */
9893 if (OSPF_IF_PARAM_CONFIGURED(params, if_area)) {
9894 if (ospf && ospf->instance)
9895 vty_out(vty, " ip ospf %d",
9896 ospf->instance);
9897 else
9898 vty_out(vty, " ip ospf");
9899
9900 char buf[INET_ADDRSTRLEN];
9901
9902 area_id2str(buf, sizeof(buf), &params->if_area,
9903 params->if_area_id_fmt);
9904 vty_out(vty, " area %s", buf);
9905 if (params != IF_DEF_PARAMS(ifp) && rn)
9906 vty_out(vty, " %s",
9907 inet_ntoa(rn->p.u.prefix4));
9908 vty_out(vty, "\n");
9909 }
9910
9911 /* bfd print. */
9912 if (params && params->bfd_info)
9913 ospf_bfd_write_config(vty, params);
9914
9915 /* MTU ignore print. */
9916 if (OSPF_IF_PARAM_CONFIGURED(params, mtu_ignore)
9917 && params->mtu_ignore != OSPF_MTU_IGNORE_DEFAULT) {
9918 if (params->mtu_ignore == 0)
9919 vty_out(vty, " no ip ospf mtu-ignore");
9920 else
9921 vty_out(vty, " ip ospf mtu-ignore");
9922 if (params != IF_DEF_PARAMS(ifp) && rn)
9923 vty_out(vty, " %s",
9924 inet_ntoa(rn->p.u.prefix4));
9925 vty_out(vty, "\n");
9926 }
9927
9928
9929 while (1) {
9930 if (rn == NULL)
9931 rn = route_top(IF_OIFS_PARAMS(ifp));
9932 else
9933 rn = route_next(rn);
9934
9935 if (rn == NULL)
9936 break;
9937 params = rn->info;
9938 if (params != NULL)
9939 break;
9940 }
9941 } while (rn);
9942
9943 ospf_opaque_config_write_if(vty, ifp);
9944
9945 vty_endframe(vty, NULL);
9946 }
9947
9948 return write;
9949 }
9950
9951 /* Configuration write function for ospfd. */
9952 static int config_write_interface(struct vty *vty)
9953 {
9954 int write = 0;
9955 struct vrf *vrf = NULL;
9956
9957 /* Display all VRF aware OSPF interface configuration */
9958 RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) {
9959 write += config_write_interface_one(vty, vrf);
9960 }
9961
9962 return write;
9963 }
9964
9965 static int config_write_network_area(struct vty *vty, struct ospf *ospf)
9966 {
9967 struct route_node *rn;
9968 uint8_t buf[INET_ADDRSTRLEN];
9969
9970 /* `network area' print. */
9971 for (rn = route_top(ospf->networks); rn; rn = route_next(rn))
9972 if (rn->info) {
9973 struct ospf_network *n = rn->info;
9974
9975 /* Create Area ID string by specified Area ID format. */
9976 if (n->area_id_fmt == OSPF_AREA_ID_FMT_DOTTEDQUAD)
9977 inet_ntop(AF_INET, &n->area_id, (char *)buf,
9978 sizeof(buf));
9979 else
9980 sprintf((char *)buf, "%lu",
9981 (unsigned long int)ntohl(
9982 n->area_id.s_addr));
9983
9984 /* Network print. */
9985 vty_out(vty, " network %s/%d area %s\n",
9986 inet_ntoa(rn->p.u.prefix4), rn->p.prefixlen,
9987 buf);
9988 }
9989
9990 return 0;
9991 }
9992
9993 static int config_write_ospf_area(struct vty *vty, struct ospf *ospf)
9994 {
9995 struct listnode *node;
9996 struct ospf_area *area;
9997 uint8_t buf[INET_ADDRSTRLEN];
9998
9999 /* Area configuration print. */
10000 for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) {
10001 struct route_node *rn1;
10002
10003 area_id2str((char *)buf, sizeof(buf), &area->area_id,
10004 area->area_id_fmt);
10005
10006 if (area->auth_type != OSPF_AUTH_NULL) {
10007 if (area->auth_type == OSPF_AUTH_SIMPLE)
10008 vty_out(vty, " area %s authentication\n", buf);
10009 else
10010 vty_out(vty,
10011 " area %s authentication message-digest\n",
10012 buf);
10013 }
10014
10015 if (area->shortcut_configured != OSPF_SHORTCUT_DEFAULT)
10016 vty_out(vty, " area %s shortcut %s\n", buf,
10017 ospf_shortcut_mode_str
10018 [area->shortcut_configured]);
10019
10020 if ((area->external_routing == OSPF_AREA_STUB)
10021 || (area->external_routing == OSPF_AREA_NSSA)) {
10022 if (area->external_routing == OSPF_AREA_STUB) {
10023 vty_out(vty, " area %s stub", buf);
10024 if (area->no_summary)
10025 vty_out(vty, " no-summary\n");
10026 vty_out(vty, "\n");
10027 } else if (area->external_routing == OSPF_AREA_NSSA) {
10028 switch (area->NSSATranslatorRole) {
10029 case OSPF_NSSA_ROLE_NEVER:
10030 vty_out(vty,
10031 " area %s nssa translate-never\n",
10032 buf);
10033 break;
10034 case OSPF_NSSA_ROLE_ALWAYS:
10035 vty_out(vty,
10036 " area %s nssa translate-always\n",
10037 buf);
10038 break;
10039 case OSPF_NSSA_ROLE_CANDIDATE:
10040 vty_out(vty, " area %s nssa \n", buf);
10041 break;
10042 }
10043 if (area->no_summary)
10044 vty_out(vty,
10045 " area %s nssa no-summary\n",
10046 buf);
10047 }
10048
10049 if (area->default_cost != 1)
10050 vty_out(vty, " area %s default-cost %d\n", buf,
10051 area->default_cost);
10052 }
10053
10054 for (rn1 = route_top(area->ranges); rn1; rn1 = route_next(rn1))
10055 if (rn1->info) {
10056 struct ospf_area_range *range = rn1->info;
10057
10058 vty_out(vty, " area %s range %s/%d", buf,
10059 inet_ntoa(rn1->p.u.prefix4),
10060 rn1->p.prefixlen);
10061
10062 if (range->cost_config
10063 != OSPF_AREA_RANGE_COST_UNSPEC)
10064 vty_out(vty, " cost %d",
10065 range->cost_config);
10066
10067 if (!CHECK_FLAG(range->flags,
10068 OSPF_AREA_RANGE_ADVERTISE))
10069 vty_out(vty, " not-advertise");
10070
10071 if (CHECK_FLAG(range->flags,
10072 OSPF_AREA_RANGE_SUBSTITUTE))
10073 vty_out(vty, " substitute %s/%d",
10074 inet_ntoa(range->subst_addr),
10075 range->subst_masklen);
10076
10077 vty_out(vty, "\n");
10078 }
10079
10080 if (EXPORT_NAME(area))
10081 vty_out(vty, " area %s export-list %s\n", buf,
10082 EXPORT_NAME(area));
10083
10084 if (IMPORT_NAME(area))
10085 vty_out(vty, " area %s import-list %s\n", buf,
10086 IMPORT_NAME(area));
10087
10088 if (PREFIX_NAME_IN(area))
10089 vty_out(vty, " area %s filter-list prefix %s in\n", buf,
10090 PREFIX_NAME_IN(area));
10091
10092 if (PREFIX_NAME_OUT(area))
10093 vty_out(vty, " area %s filter-list prefix %s out\n",
10094 buf, PREFIX_NAME_OUT(area));
10095 }
10096
10097 return 0;
10098 }
10099
10100 static int config_write_ospf_nbr_nbma(struct vty *vty, struct ospf *ospf)
10101 {
10102 struct ospf_nbr_nbma *nbr_nbma;
10103 struct route_node *rn;
10104
10105 /* Static Neighbor configuration print. */
10106 for (rn = route_top(ospf->nbr_nbma); rn; rn = route_next(rn))
10107 if ((nbr_nbma = rn->info)) {
10108 vty_out(vty, " neighbor %s", inet_ntoa(nbr_nbma->addr));
10109
10110 if (nbr_nbma->priority
10111 != OSPF_NEIGHBOR_PRIORITY_DEFAULT)
10112 vty_out(vty, " priority %d",
10113 nbr_nbma->priority);
10114
10115 if (nbr_nbma->v_poll != OSPF_POLL_INTERVAL_DEFAULT)
10116 vty_out(vty, " poll-interval %d",
10117 nbr_nbma->v_poll);
10118
10119 vty_out(vty, "\n");
10120 }
10121
10122 return 0;
10123 }
10124
10125 static int config_write_virtual_link(struct vty *vty, struct ospf *ospf)
10126 {
10127 struct listnode *node;
10128 struct ospf_vl_data *vl_data;
10129 char buf[INET_ADDRSTRLEN];
10130
10131 /* Virtual-Link print */
10132 for (ALL_LIST_ELEMENTS_RO(ospf->vlinks, node, vl_data)) {
10133 struct listnode *n2;
10134 struct crypt_key *ck;
10135 struct ospf_interface *oi;
10136
10137 if (vl_data != NULL) {
10138 area_id2str(buf, sizeof(buf), &vl_data->vl_area_id,
10139 vl_data->vl_area_id_fmt);
10140 oi = vl_data->vl_oi;
10141
10142 /* timers */
10143 if (OSPF_IF_PARAM(oi, v_hello)
10144 != OSPF_HELLO_INTERVAL_DEFAULT
10145 || OSPF_IF_PARAM(oi, v_wait)
10146 != OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
10147 || OSPF_IF_PARAM(oi, retransmit_interval)
10148 != OSPF_RETRANSMIT_INTERVAL_DEFAULT
10149 || OSPF_IF_PARAM(oi, transmit_delay)
10150 != OSPF_TRANSMIT_DELAY_DEFAULT)
10151 vty_out(vty,
10152 " area %s virtual-link %s hello-interval %d retransmit-interval %d transmit-delay %d dead-interval %d\n",
10153 buf, inet_ntoa(vl_data->vl_peer),
10154 OSPF_IF_PARAM(oi, v_hello),
10155 OSPF_IF_PARAM(oi, retransmit_interval),
10156 OSPF_IF_PARAM(oi, transmit_delay),
10157 OSPF_IF_PARAM(oi, v_wait));
10158 else
10159 vty_out(vty, " area %s virtual-link %s\n", buf,
10160 inet_ntoa(vl_data->vl_peer));
10161 /* Auth key */
10162 if (IF_DEF_PARAMS(vl_data->vl_oi->ifp)->auth_simple[0]
10163 != '\0')
10164 vty_out(vty,
10165 " area %s virtual-link %s authentication-key %s\n",
10166 buf, inet_ntoa(vl_data->vl_peer),
10167 IF_DEF_PARAMS(vl_data->vl_oi->ifp)
10168 ->auth_simple);
10169 /* md5 keys */
10170 for (ALL_LIST_ELEMENTS_RO(
10171 IF_DEF_PARAMS(vl_data->vl_oi->ifp)
10172 ->auth_crypt,
10173 n2, ck))
10174 vty_out(vty,
10175 " area %s virtual-link %s"
10176 " message-digest-key %d md5 %s\n",
10177 buf, inet_ntoa(vl_data->vl_peer),
10178 ck->key_id, ck->auth_key);
10179 }
10180 }
10181
10182 return 0;
10183 }
10184
10185
10186 static int config_write_ospf_redistribute(struct vty *vty, struct ospf *ospf)
10187 {
10188 int type;
10189
10190 /* redistribute print. */
10191 for (type = 0; type < ZEBRA_ROUTE_MAX; type++) {
10192 struct list *red_list;
10193 struct listnode *node;
10194 struct ospf_redist *red;
10195
10196 red_list = ospf->redist[type];
10197 if (!red_list)
10198 continue;
10199
10200 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
10201 vty_out(vty, " redistribute %s",
10202 zebra_route_string(type));
10203 if (red->instance)
10204 vty_out(vty, " %d", red->instance);
10205
10206 if (red->dmetric.value >= 0)
10207 vty_out(vty, " metric %d", red->dmetric.value);
10208
10209 if (red->dmetric.type == EXTERNAL_METRIC_TYPE_1)
10210 vty_out(vty, " metric-type 1");
10211
10212 if (ROUTEMAP_NAME(red))
10213 vty_out(vty, " route-map %s",
10214 ROUTEMAP_NAME(red));
10215
10216 vty_out(vty, "\n");
10217 }
10218 }
10219
10220 return 0;
10221 }
10222
10223 static int config_write_ospf_default_metric(struct vty *vty, struct ospf *ospf)
10224 {
10225 if (ospf->default_metric != -1)
10226 vty_out(vty, " default-metric %d\n", ospf->default_metric);
10227 return 0;
10228 }
10229
10230 static int config_write_ospf_distribute(struct vty *vty, struct ospf *ospf)
10231 {
10232 int type;
10233 struct ospf_redist *red;
10234
10235 if (ospf) {
10236 /* distribute-list print. */
10237 for (type = 0; type < ZEBRA_ROUTE_MAX; type++)
10238 if (DISTRIBUTE_NAME(ospf, type))
10239 vty_out(vty, " distribute-list %s out %s\n",
10240 DISTRIBUTE_NAME(ospf, type),
10241 zebra_route_string(type));
10242
10243 /* default-information print. */
10244 if (ospf->default_originate != DEFAULT_ORIGINATE_NONE) {
10245 vty_out(vty, " default-information originate");
10246 if (ospf->default_originate == DEFAULT_ORIGINATE_ALWAYS)
10247 vty_out(vty, " always");
10248
10249 red = ospf_redist_lookup(ospf, DEFAULT_ROUTE, 0);
10250 if (red) {
10251 if (red->dmetric.value >= 0)
10252 vty_out(vty, " metric %d",
10253 red->dmetric.value);
10254
10255 if (red->dmetric.type == EXTERNAL_METRIC_TYPE_1)
10256 vty_out(vty, " metric-type 1");
10257
10258 if (ROUTEMAP_NAME(red))
10259 vty_out(vty, " route-map %s",
10260 ROUTEMAP_NAME(red));
10261 }
10262
10263 vty_out(vty, "\n");
10264 }
10265 }
10266
10267 return 0;
10268 }
10269
10270 static int config_write_ospf_distance(struct vty *vty, struct ospf *ospf)
10271 {
10272 struct route_node *rn;
10273 struct ospf_distance *odistance;
10274
10275 if (ospf->distance_all)
10276 vty_out(vty, " distance %d\n", ospf->distance_all);
10277
10278 if (ospf->distance_intra || ospf->distance_inter
10279 || ospf->distance_external) {
10280 vty_out(vty, " distance ospf");
10281
10282 if (ospf->distance_intra)
10283 vty_out(vty, " intra-area %d", ospf->distance_intra);
10284 if (ospf->distance_inter)
10285 vty_out(vty, " inter-area %d", ospf->distance_inter);
10286 if (ospf->distance_external)
10287 vty_out(vty, " external %d", ospf->distance_external);
10288
10289 vty_out(vty, "\n");
10290 }
10291
10292 for (rn = route_top(ospf->distance_table); rn; rn = route_next(rn))
10293 if ((odistance = rn->info) != NULL) {
10294 vty_out(vty, " distance %d %s/%d %s\n",
10295 odistance->distance, inet_ntoa(rn->p.u.prefix4),
10296 rn->p.prefixlen,
10297 odistance->access_list ? odistance->access_list
10298 : "");
10299 }
10300 return 0;
10301 }
10302
10303 static int ospf_config_write_one(struct vty *vty, struct ospf *ospf)
10304 {
10305 struct vrf *vrf = vrf_lookup_by_id(ospf->vrf_id);
10306 struct interface *ifp;
10307 struct ospf_interface *oi;
10308 struct listnode *node = NULL;
10309 int write = 0;
10310
10311 /* `router ospf' print. */
10312 if (ospf->instance && ospf->name) {
10313 vty_out(vty, "router ospf %d vrf %s\n", ospf->instance,
10314 ospf->name);
10315 } else if (ospf->instance) {
10316 vty_out(vty, "router ospf %d\n", ospf->instance);
10317 } else if (ospf->name) {
10318 vty_out(vty, "router ospf vrf %s\n", ospf->name);
10319 } else
10320 vty_out(vty, "router ospf\n");
10321
10322 if (!ospf->networks) {
10323 write++;
10324 return write;
10325 }
10326
10327 /* Router ID print. */
10328 if (ospf->router_id_static.s_addr != 0)
10329 vty_out(vty, " ospf router-id %s\n",
10330 inet_ntoa(ospf->router_id_static));
10331
10332 /* ABR type print. */
10333 if (ospf->abr_type != OSPF_ABR_DEFAULT)
10334 vty_out(vty, " ospf abr-type %s\n",
10335 ospf_abr_type_str[ospf->abr_type]);
10336
10337 /* log-adjacency-changes flag print. */
10338 if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES)) {
10339 if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL))
10340 vty_out(vty, " log-adjacency-changes detail\n");
10341 else if (!DFLT_OSPF_LOG_ADJACENCY_CHANGES)
10342 vty_out(vty, " log-adjacency-changes\n");
10343 } else if (DFLT_OSPF_LOG_ADJACENCY_CHANGES) {
10344 vty_out(vty, " no log-adjacency-changes\n");
10345 }
10346
10347 /* RFC1583 compatibility flag print -- Compatible with CISCO
10348 * 12.1. */
10349 if (CHECK_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE))
10350 vty_out(vty, " compatible rfc1583\n");
10351
10352 /* auto-cost reference-bandwidth configuration. */
10353 if (ospf->ref_bandwidth != OSPF_DEFAULT_REF_BANDWIDTH) {
10354 vty_out(vty,
10355 "! Important: ensure reference bandwidth "
10356 "is consistent across all routers\n");
10357 vty_out(vty, " auto-cost reference-bandwidth %d\n",
10358 ospf->ref_bandwidth);
10359 }
10360
10361 /* SPF timers print. */
10362 if (ospf->spf_delay != OSPF_SPF_DELAY_DEFAULT
10363 || ospf->spf_holdtime != OSPF_SPF_HOLDTIME_DEFAULT
10364 || ospf->spf_max_holdtime != OSPF_SPF_MAX_HOLDTIME_DEFAULT)
10365 vty_out(vty, " timers throttle spf %d %d %d\n", ospf->spf_delay,
10366 ospf->spf_holdtime, ospf->spf_max_holdtime);
10367
10368 /* LSA timers print. */
10369 if (ospf->min_ls_interval != OSPF_MIN_LS_INTERVAL)
10370 vty_out(vty, " timers throttle lsa all %d\n",
10371 ospf->min_ls_interval);
10372 if (ospf->min_ls_arrival != OSPF_MIN_LS_ARRIVAL)
10373 vty_out(vty, " timers lsa min-arrival %d\n",
10374 ospf->min_ls_arrival);
10375
10376 /* Write multiplier print. */
10377 if (ospf->write_oi_count != OSPF_WRITE_INTERFACE_COUNT_DEFAULT)
10378 vty_out(vty, " ospf write-multiplier %d\n",
10379 ospf->write_oi_count);
10380
10381 /* Max-metric router-lsa print */
10382 config_write_stub_router(vty, ospf);
10383
10384 /* SPF refresh parameters print. */
10385 if (ospf->lsa_refresh_interval != OSPF_LSA_REFRESH_INTERVAL_DEFAULT)
10386 vty_out(vty, " refresh timer %d\n", ospf->lsa_refresh_interval);
10387
10388 /* Redistribute information print. */
10389 config_write_ospf_redistribute(vty, ospf);
10390
10391 /* passive-interface print. */
10392 if (ospf->passive_interface_default == OSPF_IF_PASSIVE)
10393 vty_out(vty, " passive-interface default\n");
10394
10395 FOR_ALL_INTERFACES (vrf, ifp)
10396 if (OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(ifp),
10397 passive_interface)
10398 && IF_DEF_PARAMS(ifp)->passive_interface
10399 != ospf->passive_interface_default) {
10400 vty_out(vty, " %spassive-interface %s\n",
10401 IF_DEF_PARAMS(ifp)->passive_interface ? ""
10402 : "no ",
10403 ifp->name);
10404 }
10405 for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) {
10406 if (!OSPF_IF_PARAM_CONFIGURED(oi->params, passive_interface))
10407 continue;
10408 if (OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(oi->ifp),
10409 passive_interface)) {
10410 if (oi->params->passive_interface
10411 == IF_DEF_PARAMS(oi->ifp)->passive_interface)
10412 continue;
10413 } else if (oi->params->passive_interface
10414 == ospf->passive_interface_default)
10415 continue;
10416
10417 vty_out(vty, " %spassive-interface %s %s\n",
10418 oi->params->passive_interface ? "" : "no ",
10419 oi->ifp->name, inet_ntoa(oi->address->u.prefix4));
10420 }
10421
10422 /* Network area print. */
10423 config_write_network_area(vty, ospf);
10424
10425 /* Area config print. */
10426 config_write_ospf_area(vty, ospf);
10427
10428 /* static neighbor print. */
10429 config_write_ospf_nbr_nbma(vty, ospf);
10430
10431 /* Virtual-Link print. */
10432 config_write_virtual_link(vty, ospf);
10433
10434 /* Default metric configuration. */
10435 config_write_ospf_default_metric(vty, ospf);
10436
10437 /* Distribute-list and default-information print. */
10438 config_write_ospf_distribute(vty, ospf);
10439
10440 /* Distance configuration. */
10441 config_write_ospf_distance(vty, ospf);
10442
10443 ospf_opaque_config_write_router(vty, ospf);
10444
10445 write++;
10446 return write;
10447 }
10448
10449 /* OSPF configuration write function. */
10450 static int ospf_config_write(struct vty *vty)
10451 {
10452 struct ospf *ospf;
10453 struct listnode *ospf_node = NULL;
10454 int write = 0;
10455
10456 if (listcount(om->ospf) == 0)
10457 return write;
10458
10459 for (ALL_LIST_ELEMENTS_RO(om->ospf, ospf_node, ospf)) {
10460 /* VRF Default check if it is running.
10461 * Upon daemon start, there could be default instance
10462 * in absence of 'router ospf'/oi_running is disabled. */
10463 if (ospf->vrf_id == VRF_DEFAULT && ospf->oi_running)
10464 write += ospf_config_write_one(vty, ospf);
10465 /* For Non-Default VRF simply display the configuration,
10466 * even if it is not oi_running. */
10467 else if (ospf->vrf_id != VRF_DEFAULT)
10468 write += ospf_config_write_one(vty, ospf);
10469 }
10470 return write;
10471 }
10472
10473 void ospf_vty_show_init(void)
10474 {
10475 /* "show ip ospf" commands. */
10476 install_element(VIEW_NODE, &show_ip_ospf_cmd);
10477
10478 install_element(VIEW_NODE, &show_ip_ospf_instance_cmd);
10479
10480 /* "show ip ospf database" commands. */
10481 install_element(VIEW_NODE, &show_ip_ospf_database_max_cmd);
10482
10483 install_element(VIEW_NODE,
10484 &show_ip_ospf_instance_database_type_adv_router_cmd);
10485 install_element(VIEW_NODE, &show_ip_ospf_instance_database_cmd);
10486 install_element(VIEW_NODE, &show_ip_ospf_instance_database_max_cmd);
10487
10488 /* "show ip ospf interface" commands. */
10489 install_element(VIEW_NODE, &show_ip_ospf_interface_cmd);
10490
10491 install_element(VIEW_NODE, &show_ip_ospf_instance_interface_cmd);
10492 /* "show ip ospf interface traffic */
10493 install_element(VIEW_NODE, &show_ip_ospf_interface_traffic_cmd);
10494
10495 /* "show ip ospf neighbor" commands. */
10496 install_element(VIEW_NODE, &show_ip_ospf_neighbor_int_detail_cmd);
10497 install_element(VIEW_NODE, &show_ip_ospf_neighbor_int_cmd);
10498 install_element(VIEW_NODE, &show_ip_ospf_neighbor_id_cmd);
10499 install_element(VIEW_NODE, &show_ip_ospf_neighbor_detail_all_cmd);
10500 install_element(VIEW_NODE, &show_ip_ospf_neighbor_detail_cmd);
10501 install_element(VIEW_NODE, &show_ip_ospf_neighbor_cmd);
10502 install_element(VIEW_NODE, &show_ip_ospf_neighbor_all_cmd);
10503
10504 install_element(VIEW_NODE,
10505 &show_ip_ospf_instance_neighbor_int_detail_cmd);
10506 install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_int_cmd);
10507 install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_id_cmd);
10508 install_element(VIEW_NODE,
10509 &show_ip_ospf_instance_neighbor_detail_all_cmd);
10510 install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_detail_cmd);
10511 install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_cmd);
10512 install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_all_cmd);
10513
10514 /* "show ip ospf route" commands. */
10515 install_element(VIEW_NODE, &show_ip_ospf_route_cmd);
10516 install_element(VIEW_NODE, &show_ip_ospf_border_routers_cmd);
10517
10518 install_element(VIEW_NODE, &show_ip_ospf_instance_route_cmd);
10519 install_element(VIEW_NODE, &show_ip_ospf_instance_border_routers_cmd);
10520
10521 /* "show ip ospf vrfs" commands. */
10522 install_element(VIEW_NODE, &show_ip_ospf_vrfs_cmd);
10523 }
10524
10525
10526 /* ospfd's interface node. */
10527 static struct cmd_node interface_node = {INTERFACE_NODE, "%s(config-if)# ", 1};
10528
10529 /* Initialization of OSPF interface. */
10530 static void ospf_vty_if_init(void)
10531 {
10532 /* Install interface node. */
10533 install_node(&interface_node, config_write_interface);
10534 if_cmd_init();
10535
10536 /* "ip ospf authentication" commands. */
10537 install_element(INTERFACE_NODE, &ip_ospf_authentication_args_addr_cmd);
10538 install_element(INTERFACE_NODE, &ip_ospf_authentication_addr_cmd);
10539 install_element(INTERFACE_NODE,
10540 &no_ip_ospf_authentication_args_addr_cmd);
10541 install_element(INTERFACE_NODE, &no_ip_ospf_authentication_addr_cmd);
10542 install_element(INTERFACE_NODE, &ip_ospf_authentication_key_addr_cmd);
10543 install_element(INTERFACE_NODE,
10544 &no_ip_ospf_authentication_key_authkey_addr_cmd);
10545 install_element(INTERFACE_NODE,
10546 &no_ospf_authentication_key_authkey_addr_cmd);
10547
10548 /* "ip ospf message-digest-key" commands. */
10549 install_element(INTERFACE_NODE, &ip_ospf_message_digest_key_cmd);
10550 install_element(INTERFACE_NODE, &no_ip_ospf_message_digest_key_cmd);
10551
10552 /* "ip ospf cost" commands. */
10553 install_element(INTERFACE_NODE, &ip_ospf_cost_cmd);
10554 install_element(INTERFACE_NODE, &no_ip_ospf_cost_cmd);
10555
10556 /* "ip ospf mtu-ignore" commands. */
10557 install_element(INTERFACE_NODE, &ip_ospf_mtu_ignore_addr_cmd);
10558 install_element(INTERFACE_NODE, &no_ip_ospf_mtu_ignore_addr_cmd);
10559
10560 /* "ip ospf dead-interval" commands. */
10561 install_element(INTERFACE_NODE, &ip_ospf_dead_interval_cmd);
10562 install_element(INTERFACE_NODE,
10563 &ip_ospf_dead_interval_minimal_addr_cmd);
10564 install_element(INTERFACE_NODE, &no_ip_ospf_dead_interval_cmd);
10565
10566 /* "ip ospf hello-interval" commands. */
10567 install_element(INTERFACE_NODE, &ip_ospf_hello_interval_cmd);
10568 install_element(INTERFACE_NODE, &no_ip_ospf_hello_interval_cmd);
10569
10570 /* "ip ospf network" commands. */
10571 install_element(INTERFACE_NODE, &ip_ospf_network_cmd);
10572 install_element(INTERFACE_NODE, &no_ip_ospf_network_cmd);
10573
10574 /* "ip ospf priority" commands. */
10575 install_element(INTERFACE_NODE, &ip_ospf_priority_cmd);
10576 install_element(INTERFACE_NODE, &no_ip_ospf_priority_cmd);
10577
10578 /* "ip ospf retransmit-interval" commands. */
10579 install_element(INTERFACE_NODE, &ip_ospf_retransmit_interval_addr_cmd);
10580 install_element(INTERFACE_NODE,
10581 &no_ip_ospf_retransmit_interval_addr_cmd);
10582
10583 /* "ip ospf transmit-delay" commands. */
10584 install_element(INTERFACE_NODE, &ip_ospf_transmit_delay_addr_cmd);
10585 install_element(INTERFACE_NODE, &no_ip_ospf_transmit_delay_addr_cmd);
10586
10587 /* "ip ospf area" commands. */
10588 install_element(INTERFACE_NODE, &ip_ospf_area_cmd);
10589 install_element(INTERFACE_NODE, &no_ip_ospf_area_cmd);
10590
10591 /* These commands are compatibitliy for previous version. */
10592 install_element(INTERFACE_NODE, &ospf_authentication_key_cmd);
10593 install_element(INTERFACE_NODE, &ospf_message_digest_key_cmd);
10594 install_element(INTERFACE_NODE, &no_ospf_message_digest_key_cmd);
10595 install_element(INTERFACE_NODE, &ospf_dead_interval_cmd);
10596 install_element(INTERFACE_NODE, &no_ospf_dead_interval_cmd);
10597 install_element(INTERFACE_NODE, &ospf_hello_interval_cmd);
10598 install_element(INTERFACE_NODE, &no_ospf_hello_interval_cmd);
10599 install_element(INTERFACE_NODE, &ospf_cost_cmd);
10600 install_element(INTERFACE_NODE, &no_ospf_cost_cmd);
10601 install_element(INTERFACE_NODE, &ospf_network_cmd);
10602 install_element(INTERFACE_NODE, &no_ospf_network_cmd);
10603 install_element(INTERFACE_NODE, &ospf_priority_cmd);
10604 install_element(INTERFACE_NODE, &no_ospf_priority_cmd);
10605 install_element(INTERFACE_NODE, &ospf_retransmit_interval_cmd);
10606 install_element(INTERFACE_NODE, &no_ospf_retransmit_interval_cmd);
10607 install_element(INTERFACE_NODE, &ospf_transmit_delay_cmd);
10608 install_element(INTERFACE_NODE, &no_ospf_transmit_delay_cmd);
10609 }
10610
10611 static void ospf_vty_zebra_init(void)
10612 {
10613 install_element(OSPF_NODE, &ospf_redistribute_source_cmd);
10614 install_element(OSPF_NODE, &no_ospf_redistribute_source_cmd);
10615 install_element(OSPF_NODE, &ospf_redistribute_instance_source_cmd);
10616 install_element(OSPF_NODE, &no_ospf_redistribute_instance_source_cmd);
10617
10618 install_element(OSPF_NODE, &ospf_distribute_list_out_cmd);
10619 install_element(OSPF_NODE, &no_ospf_distribute_list_out_cmd);
10620
10621 install_element(OSPF_NODE, &ospf_default_information_originate_cmd);
10622 install_element(OSPF_NODE, &no_ospf_default_information_originate_cmd);
10623
10624 install_element(OSPF_NODE, &ospf_default_metric_cmd);
10625 install_element(OSPF_NODE, &no_ospf_default_metric_cmd);
10626
10627 install_element(OSPF_NODE, &ospf_distance_cmd);
10628 install_element(OSPF_NODE, &no_ospf_distance_cmd);
10629 install_element(OSPF_NODE, &no_ospf_distance_ospf_cmd);
10630 install_element(OSPF_NODE, &ospf_distance_ospf_cmd);
10631 #if 0
10632 install_element (OSPF_NODE, &ospf_distance_source_cmd);
10633 install_element (OSPF_NODE, &no_ospf_distance_source_cmd);
10634 install_element (OSPF_NODE, &ospf_distance_source_access_list_cmd);
10635 install_element (OSPF_NODE, &no_ospf_distance_source_access_list_cmd);
10636 #endif /* 0 */
10637 }
10638
10639 static struct cmd_node ospf_node = {OSPF_NODE, "%s(config-router)# ", 1};
10640
10641 static void ospf_interface_clear(struct interface *ifp)
10642 {
10643 if (!if_is_operative(ifp))
10644 return;
10645
10646 if (IS_DEBUG_OSPF(ism, ISM_EVENTS))
10647 zlog_debug("ISM[%s]: clear by reset", ifp->name);
10648
10649 ospf_if_reset(ifp);
10650 }
10651
10652 DEFUN (clear_ip_ospf_interface,
10653 clear_ip_ospf_interface_cmd,
10654 "clear ip ospf [vrf <NAME>] interface [IFNAME]",
10655 CLEAR_STR
10656 IP_STR
10657 "OSPF information\n"
10658 VRF_CMD_HELP_STR
10659 "Interface information\n"
10660 "Interface name\n")
10661 {
10662 int idx_ifname = 0;
10663 int idx_vrf = 0;
10664 struct interface *ifp;
10665 struct listnode *node;
10666 struct ospf *ospf = NULL;
10667 char *vrf_name = NULL;
10668 vrf_id_t vrf_id = VRF_DEFAULT;
10669 struct vrf *vrf = NULL;
10670
10671 if (argv_find(argv, argc, "vrf", &idx_vrf))
10672 vrf_name = argv[idx_vrf + 1]->arg;
10673 if (vrf_name && strmatch(vrf_name, VRF_DEFAULT_NAME))
10674 vrf_name = NULL;
10675 if (vrf_name) {
10676 vrf = vrf_lookup_by_name(vrf_name);
10677 if (vrf)
10678 vrf_id = vrf->vrf_id;
10679 }
10680 if (!argv_find(argv, argc, "IFNAME", &idx_ifname)) {
10681 /* Clear all the ospfv2 interfaces. */
10682 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
10683 if (vrf_id != ospf->vrf_id)
10684 continue;
10685 if (!vrf)
10686 vrf = vrf_lookup_by_id(ospf->vrf_id);
10687 FOR_ALL_INTERFACES (vrf, ifp)
10688 ospf_interface_clear(ifp);
10689 }
10690 } else {
10691 /* Interface name is specified. */
10692 ifp = if_lookup_by_name(argv[idx_ifname]->arg,
10693 vrf_lookup_by_id(vrf_id));
10694 if (ifp == NULL)
10695 vty_out(vty, "No such interface name\n");
10696 else
10697 ospf_interface_clear(ifp);
10698 }
10699
10700 return CMD_SUCCESS;
10701 }
10702
10703 void ospf_vty_clear_init(void)
10704 {
10705 install_element(ENABLE_NODE, &clear_ip_ospf_interface_cmd);
10706 }
10707
10708
10709 /* Install OSPF related vty commands. */
10710 void ospf_vty_init(void)
10711 {
10712 /* Install ospf top node. */
10713 install_node(&ospf_node, ospf_config_write);
10714
10715 /* "router ospf" commands. */
10716 install_element(CONFIG_NODE, &router_ospf_cmd);
10717 install_element(CONFIG_NODE, &no_router_ospf_cmd);
10718
10719
10720 install_default(OSPF_NODE);
10721
10722 /* "ospf router-id" commands. */
10723 install_element(OSPF_NODE, &ospf_router_id_cmd);
10724 install_element(OSPF_NODE, &ospf_router_id_old_cmd);
10725 install_element(OSPF_NODE, &no_ospf_router_id_cmd);
10726
10727 /* "passive-interface" commands. */
10728 install_element(OSPF_NODE, &ospf_passive_interface_addr_cmd);
10729 install_element(OSPF_NODE, &no_ospf_passive_interface_addr_cmd);
10730
10731 /* "ospf abr-type" commands. */
10732 install_element(OSPF_NODE, &ospf_abr_type_cmd);
10733 install_element(OSPF_NODE, &no_ospf_abr_type_cmd);
10734
10735 /* "ospf log-adjacency-changes" commands. */
10736 install_element(OSPF_NODE, &ospf_log_adjacency_changes_cmd);
10737 install_element(OSPF_NODE, &ospf_log_adjacency_changes_detail_cmd);
10738 install_element(OSPF_NODE, &no_ospf_log_adjacency_changes_cmd);
10739 install_element(OSPF_NODE, &no_ospf_log_adjacency_changes_detail_cmd);
10740
10741 /* "ospf rfc1583-compatible" commands. */
10742 install_element(OSPF_NODE, &ospf_compatible_rfc1583_cmd);
10743 install_element(OSPF_NODE, &no_ospf_compatible_rfc1583_cmd);
10744 install_element(OSPF_NODE, &ospf_rfc1583_flag_cmd);
10745 install_element(OSPF_NODE, &no_ospf_rfc1583_flag_cmd);
10746
10747 /* "network area" commands. */
10748 install_element(OSPF_NODE, &ospf_network_area_cmd);
10749 install_element(OSPF_NODE, &no_ospf_network_area_cmd);
10750
10751 /* "area authentication" commands. */
10752 install_element(OSPF_NODE,
10753 &ospf_area_authentication_message_digest_cmd);
10754 install_element(OSPF_NODE, &ospf_area_authentication_cmd);
10755 install_element(OSPF_NODE, &no_ospf_area_authentication_cmd);
10756
10757 /* "area range" commands. */
10758 install_element(OSPF_NODE, &ospf_area_range_cmd);
10759 install_element(OSPF_NODE, &ospf_area_range_cost_cmd);
10760 install_element(OSPF_NODE, &ospf_area_range_not_advertise_cmd);
10761 install_element(OSPF_NODE, &no_ospf_area_range_cmd);
10762 install_element(OSPF_NODE, &ospf_area_range_substitute_cmd);
10763 install_element(OSPF_NODE, &no_ospf_area_range_substitute_cmd);
10764
10765 /* "area virtual-link" commands. */
10766 install_element(OSPF_NODE, &ospf_area_vlink_cmd);
10767 install_element(OSPF_NODE, &ospf_area_vlink_intervals_cmd);
10768 install_element(OSPF_NODE, &no_ospf_area_vlink_cmd);
10769 install_element(OSPF_NODE, &no_ospf_area_vlink_intervals_cmd);
10770
10771
10772 /* "area stub" commands. */
10773 install_element(OSPF_NODE, &ospf_area_stub_no_summary_cmd);
10774 install_element(OSPF_NODE, &ospf_area_stub_cmd);
10775 install_element(OSPF_NODE, &no_ospf_area_stub_no_summary_cmd);
10776 install_element(OSPF_NODE, &no_ospf_area_stub_cmd);
10777
10778 /* "area nssa" commands. */
10779 install_element(OSPF_NODE, &ospf_area_nssa_cmd);
10780 install_element(OSPF_NODE, &ospf_area_nssa_translate_cmd);
10781 install_element(OSPF_NODE, &ospf_area_nssa_no_summary_cmd);
10782 install_element(OSPF_NODE, &no_ospf_area_nssa_no_summary_cmd);
10783 install_element(OSPF_NODE, &no_ospf_area_nssa_cmd);
10784
10785 install_element(OSPF_NODE, &ospf_area_default_cost_cmd);
10786 install_element(OSPF_NODE, &no_ospf_area_default_cost_cmd);
10787
10788 install_element(OSPF_NODE, &ospf_area_shortcut_cmd);
10789 install_element(OSPF_NODE, &no_ospf_area_shortcut_cmd);
10790
10791 install_element(OSPF_NODE, &ospf_area_export_list_cmd);
10792 install_element(OSPF_NODE, &no_ospf_area_export_list_cmd);
10793
10794 install_element(OSPF_NODE, &ospf_area_filter_list_cmd);
10795 install_element(OSPF_NODE, &no_ospf_area_filter_list_cmd);
10796
10797 install_element(OSPF_NODE, &ospf_area_import_list_cmd);
10798 install_element(OSPF_NODE, &no_ospf_area_import_list_cmd);
10799
10800 /* SPF timer commands */
10801 install_element(OSPF_NODE, &ospf_timers_throttle_spf_cmd);
10802 install_element(OSPF_NODE, &no_ospf_timers_throttle_spf_cmd);
10803
10804 /* LSA timers commands */
10805 install_element(OSPF_NODE, &ospf_timers_min_ls_interval_cmd);
10806 install_element(OSPF_NODE, &no_ospf_timers_min_ls_interval_cmd);
10807 install_element(OSPF_NODE, &ospf_timers_lsa_min_arrival_cmd);
10808 install_element(OSPF_NODE, &no_ospf_timers_lsa_min_arrival_cmd);
10809
10810 /* refresh timer commands */
10811 install_element(OSPF_NODE, &ospf_refresh_timer_cmd);
10812 install_element(OSPF_NODE, &no_ospf_refresh_timer_val_cmd);
10813
10814 /* max-metric commands */
10815 install_element(OSPF_NODE, &ospf_max_metric_router_lsa_admin_cmd);
10816 install_element(OSPF_NODE, &no_ospf_max_metric_router_lsa_admin_cmd);
10817 install_element(OSPF_NODE, &ospf_max_metric_router_lsa_startup_cmd);
10818 install_element(OSPF_NODE, &no_ospf_max_metric_router_lsa_startup_cmd);
10819 install_element(OSPF_NODE, &ospf_max_metric_router_lsa_shutdown_cmd);
10820 install_element(OSPF_NODE, &no_ospf_max_metric_router_lsa_shutdown_cmd);
10821
10822 /* reference bandwidth commands */
10823 install_element(OSPF_NODE, &ospf_auto_cost_reference_bandwidth_cmd);
10824 install_element(OSPF_NODE, &no_ospf_auto_cost_reference_bandwidth_cmd);
10825
10826 /* "neighbor" commands. */
10827 install_element(OSPF_NODE, &ospf_neighbor_cmd);
10828 install_element(OSPF_NODE, &ospf_neighbor_poll_interval_cmd);
10829 install_element(OSPF_NODE, &no_ospf_neighbor_cmd);
10830 install_element(OSPF_NODE, &no_ospf_neighbor_poll_cmd);
10831
10832 /* write multiplier commands */
10833 install_element(OSPF_NODE, &ospf_write_multiplier_cmd);
10834 install_element(OSPF_NODE, &write_multiplier_cmd);
10835 install_element(OSPF_NODE, &no_ospf_write_multiplier_cmd);
10836 install_element(OSPF_NODE, &no_write_multiplier_cmd);
10837
10838 /* Init interface related vty commands. */
10839 ospf_vty_if_init();
10840
10841 /* Init zebra related vty commands. */
10842 ospf_vty_zebra_init();
10843 }