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