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