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