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