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