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