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