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