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