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