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