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