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