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