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