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