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