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