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