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