]> git.proxmox.com Git - mirror_frr.git/blob - ospfd/ospf_vty.c
all: Fix underfull doc strings, part 1
[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 (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 "Self-originated link states\n")
5804 {
5805 struct ospf *ospf;
5806
5807 if ((ospf = ospf_lookup()) == NULL || !ospf->oi_running)
5808 return CMD_SUCCESS;
5809
5810 return (show_ip_ospf_database_type_adv_router_common(vty, ospf, 0, argc, argv));
5811 }
5812
5813 DEFUN (show_ip_ospf_instance_database_type_adv_router,
5814 show_ip_ospf_instance_database_type_adv_router_cmd,
5815 "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>",
5816 SHOW_STR
5817 IP_STR
5818 "OSPF information\n"
5819 "Instance ID\n"
5820 "Database summary\n"
5821 OSPF_LSA_TYPES_DESC
5822 "Advertising Router link states\n"
5823 "Advertising Router (as an IP address)\n")
5824 {
5825 int idx_number = 3;
5826 struct ospf *ospf;
5827 u_short instance = 0;
5828
5829 VTY_GET_INTEGER ("Instance", instance, argv[idx_number]->arg);
5830
5831 if ((ospf = ospf_lookup_instance (instance)) == NULL || !ospf->oi_running)
5832 return CMD_SUCCESS;
5833
5834 return (show_ip_ospf_database_type_adv_router_common(vty, ospf, 1, argc, argv));
5835 }
5836
5837 DEFUN (ip_ospf_authentication_args,
5838 ip_ospf_authentication_args_addr_cmd,
5839 "ip ospf authentication <null|message-digest> [A.B.C.D]",
5840 "IP Information\n"
5841 "OSPF interface commands\n"
5842 "Enable authentication on this interface\n"
5843 "Use null authentication\n"
5844 "Use message-digest authentication\n"
5845 "Address of interface\n")
5846 {
5847 int idx_encryption = 3;
5848 int idx_ipv4 = 4;
5849 struct interface *ifp;
5850 struct in_addr addr;
5851 int ret;
5852 struct ospf_if_params *params;
5853
5854 ifp = vty->index;
5855 params = IF_DEF_PARAMS (ifp);
5856
5857 if (argc == 5)
5858 {
5859 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
5860 if (!ret)
5861 {
5862 vty_out (vty, "Please specify interface address by A.B.C.D%s",
5863 VTY_NEWLINE);
5864 return CMD_WARNING;
5865 }
5866
5867 params = ospf_get_if_params (ifp, addr);
5868 ospf_if_update_params (ifp, addr);
5869 }
5870
5871 /* Handle null authentication */
5872 if ( argv[idx_encryption]->arg[0] == 'n' )
5873 {
5874 SET_IF_PARAM (params, auth_type);
5875 params->auth_type = OSPF_AUTH_NULL;
5876 return CMD_SUCCESS;
5877 }
5878
5879 /* Handle message-digest authentication */
5880 if ( argv[idx_encryption]->arg[0] == 'm' )
5881 {
5882 SET_IF_PARAM (params, auth_type);
5883 params->auth_type = OSPF_AUTH_CRYPTOGRAPHIC;
5884 return CMD_SUCCESS;
5885 }
5886
5887 vty_out (vty, "You shouldn't get here!%s", VTY_NEWLINE);
5888 return CMD_WARNING;
5889 }
5890
5891 DEFUN (ip_ospf_authentication,
5892 ip_ospf_authentication_addr_cmd,
5893 "ip ospf authentication [A.B.C.D]",
5894 "IP Information\n"
5895 "OSPF interface commands\n"
5896 "Enable authentication on this interface\n"
5897 "Address of interface")
5898 {
5899 int idx_ipv4 = 3;
5900 struct interface *ifp;
5901 struct in_addr addr;
5902 int ret;
5903 struct ospf_if_params *params;
5904
5905 ifp = vty->index;
5906 params = IF_DEF_PARAMS (ifp);
5907
5908 if (argc == 4)
5909 {
5910 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
5911 if (!ret)
5912 {
5913 vty_out (vty, "Please specify interface address by A.B.C.D%s",
5914 VTY_NEWLINE);
5915 return CMD_WARNING;
5916 }
5917
5918 params = ospf_get_if_params (ifp, addr);
5919 ospf_if_update_params (ifp, addr);
5920 }
5921
5922 SET_IF_PARAM (params, auth_type);
5923 params->auth_type = OSPF_AUTH_SIMPLE;
5924
5925 return CMD_SUCCESS;
5926 }
5927
5928 DEFUN (no_ip_ospf_authentication_args,
5929 no_ip_ospf_authentication_args_addr_cmd,
5930 "no ip ospf authentication <null|message-digest> [A.B.C.D]",
5931 NO_STR
5932 "IP Information\n"
5933 "OSPF interface commands\n"
5934 "Enable authentication on this interface\n"
5935 "Use null authentication\n"
5936 "Use message-digest authentication\n"
5937 "Address of interface")
5938 {
5939 int idx_encryption = 4;
5940 int idx_ipv4 = 5;
5941 struct interface *ifp;
5942 struct in_addr addr;
5943 int ret;
5944 struct ospf_if_params *params;
5945 struct route_node *rn;
5946 int auth_type;
5947
5948 ifp = vty->index;
5949 params = IF_DEF_PARAMS (ifp);
5950
5951 if (argc == 6)
5952 {
5953 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
5954 if (!ret)
5955 {
5956 vty_out (vty, "Please specify interface address by A.B.C.D%s",
5957 VTY_NEWLINE);
5958 return CMD_WARNING;
5959 }
5960
5961 params = ospf_lookup_if_params (ifp, addr);
5962 if (params == NULL)
5963 {
5964 vty_out (vty, "Ip Address specified is unknown%s", VTY_NEWLINE);
5965 return CMD_WARNING;
5966 }
5967 params->auth_type = OSPF_AUTH_NOTSET;
5968 UNSET_IF_PARAM (params, auth_type);
5969 if (params != IF_DEF_PARAMS (ifp))
5970 {
5971 ospf_free_if_params (ifp, addr);
5972 ospf_if_update_params (ifp, addr);
5973 }
5974 }
5975 else
5976 {
5977 if ( argv[idx_encryption]->arg[0] == 'n' )
5978 {
5979 auth_type = OSPF_AUTH_NULL;
5980 }
5981 else if ( argv[idx_encryption]->arg[0] == 'm' )
5982 {
5983 auth_type = OSPF_AUTH_CRYPTOGRAPHIC;
5984 }
5985 else
5986 {
5987 vty_out (vty, "Unexpected input encountered%s", VTY_NEWLINE);
5988 return CMD_WARNING;
5989 }
5990 /*
5991 * Here we have a case where the user has entered
5992 * 'no ip ospf authentication (null | message_digest )'
5993 * we need to find if we have any ip addresses underneath it that
5994 * correspond to the associated type.
5995 */
5996 if (params->auth_type == auth_type)
5997 {
5998 params->auth_type = OSPF_AUTH_NOTSET;
5999 UNSET_IF_PARAM (params, auth_type);
6000 }
6001
6002 for (rn = route_top (IF_OIFS_PARAMS (ifp)); rn; rn = route_next (rn))
6003 {
6004 if ((params = rn->info))
6005 {
6006 if (params->auth_type == auth_type)
6007 {
6008 params->auth_type = OSPF_AUTH_NOTSET;
6009 UNSET_IF_PARAM (params, auth_type);
6010 if (params != IF_DEF_PARAMS (ifp))
6011 {
6012 ospf_free_if_params (ifp, rn->p.u.prefix4);
6013 ospf_if_update_params(ifp, rn->p.u.prefix4);
6014 }
6015 }
6016 }
6017 }
6018 }
6019
6020 return CMD_SUCCESS;
6021 }
6022
6023 DEFUN (no_ip_ospf_authentication,
6024 no_ip_ospf_authentication_addr_cmd,
6025 "no ip ospf authentication [A.B.C.D]",
6026 NO_STR
6027 "IP Information\n"
6028 "OSPF interface commands\n"
6029 "Enable authentication on this interface\n"
6030 "Address of interface")
6031 {
6032 int idx_ipv4 = 4;
6033 struct interface *ifp;
6034 struct in_addr addr;
6035 int ret;
6036 struct ospf_if_params *params;
6037 struct route_node *rn;
6038
6039 ifp = vty->index;
6040 params = IF_DEF_PARAMS (ifp);
6041
6042 if (argc == 5)
6043 {
6044 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
6045 if (!ret)
6046 {
6047 vty_out (vty, "Please specify interface address by A.B.C.D%s",
6048 VTY_NEWLINE);
6049 return CMD_WARNING;
6050 }
6051
6052 params = ospf_lookup_if_params (ifp, addr);
6053 if (params == NULL)
6054 {
6055 vty_out (vty, "Ip Address specified is unknown%s", VTY_NEWLINE);
6056 return CMD_WARNING;
6057 }
6058
6059 params->auth_type = OSPF_AUTH_NOTSET;
6060 UNSET_IF_PARAM (params, auth_type);
6061 if (params != IF_DEF_PARAMS (ifp))
6062 {
6063 ospf_free_if_params (ifp, addr);
6064 ospf_if_update_params (ifp, addr);
6065 }
6066 }
6067 else
6068 {
6069 /*
6070 * When a user enters 'no ip ospf authentication'
6071 * We should remove all authentication types from
6072 * the interface.
6073 */
6074 if ((params->auth_type == OSPF_AUTH_NULL) ||
6075 (params->auth_type == OSPF_AUTH_CRYPTOGRAPHIC) ||
6076 (params->auth_type == OSPF_AUTH_SIMPLE))
6077 {
6078 params->auth_type = OSPF_AUTH_NOTSET;
6079 UNSET_IF_PARAM (params, auth_type);
6080 }
6081
6082 for (rn = route_top (IF_OIFS_PARAMS (ifp)); rn; rn = route_next (rn))
6083 {
6084 if ((params = rn->info))
6085 {
6086
6087 if ((params->auth_type == OSPF_AUTH_NULL) ||
6088 (params->auth_type == OSPF_AUTH_CRYPTOGRAPHIC) ||
6089 (params->auth_type == OSPF_AUTH_SIMPLE))
6090 {
6091 params->auth_type = OSPF_AUTH_NOTSET;
6092 UNSET_IF_PARAM (params, auth_type);
6093 if (params != IF_DEF_PARAMS (ifp))
6094 {
6095 ospf_free_if_params (ifp, rn->p.u.prefix4);
6096 ospf_if_update_params(ifp, rn->p.u.prefix4);
6097 }
6098 }
6099 }
6100 }
6101 }
6102
6103 return CMD_SUCCESS;
6104 }
6105
6106 DEFUN (ip_ospf_authentication_key,
6107 ip_ospf_authentication_key_addr_cmd,
6108 "ip ospf authentication-key AUTH_KEY [A.B.C.D]",
6109 "IP Information\n"
6110 "OSPF interface commands\n"
6111 "Authentication password (key)\n"
6112 "The OSPF password (key)\n"
6113 "Address of interface")
6114 {
6115 int idx_ipv4 = 4;
6116 struct interface *ifp;
6117 struct in_addr addr;
6118 int ret;
6119 struct ospf_if_params *params;
6120
6121 ifp = vty->index;
6122 params = IF_DEF_PARAMS (ifp);
6123
6124 if (argc == 5)
6125 {
6126 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
6127 if (!ret)
6128 {
6129 vty_out (vty, "Please specify interface address by A.B.C.D%s",
6130 VTY_NEWLINE);
6131 return CMD_WARNING;
6132 }
6133
6134 params = ospf_get_if_params (ifp, addr);
6135 ospf_if_update_params (ifp, addr);
6136 }
6137
6138 memset (params->auth_simple, 0, OSPF_AUTH_SIMPLE_SIZE + 1);
6139 strncpy ((char *) params->auth_simple, argv[3]->arg, OSPF_AUTH_SIMPLE_SIZE);
6140 SET_IF_PARAM (params, auth_simple);
6141
6142 return CMD_SUCCESS;
6143 }
6144
6145
6146 DEFUN_HIDDEN (ospf_authentication_key,
6147 ospf_authentication_key_cmd,
6148 "ospf authentication-key AUTH_KEY",
6149 "OSPF interface commands\n"
6150 "Authentication password (key)\n"
6151 "The OSPF password (key)")
6152 {
6153 struct interface *ifp;
6154 struct ospf_if_params *params;
6155
6156 ifp = vty->index;
6157 params = IF_DEF_PARAMS (ifp);
6158 memset (params->auth_simple, 0, OSPF_AUTH_SIMPLE_SIZE + 1);
6159 strncpy ((char *) params->auth_simple, argv[2]->arg, OSPF_AUTH_SIMPLE_SIZE);
6160 SET_IF_PARAM (params, auth_simple);
6161
6162 return CMD_SUCCESS;
6163 }
6164
6165 DEFUN (no_ospf_authentication_key,
6166 no_ospf_authentication_key_authkey_addr_cmd,
6167 "no ospf authentication-key [AUTH_KEY [A.B.C.D]]",
6168 NO_STR
6169 "OSPF interface commands\n"
6170 "Authentication password (key)\n"
6171 "The OSPF password (key)")
6172 {
6173 struct interface *ifp;
6174 struct in_addr addr;
6175 struct ospf_if_params *params;
6176 int ret;
6177
6178 ifp = vty->index;
6179 params = IF_DEF_PARAMS (ifp);
6180
6181 if (argc == 5)
6182 {
6183 ret = inet_aton(argv[4]->arg, &addr);
6184 if (!ret)
6185 {
6186 vty_out (vty, "Please specify interface address by A.B.C.D%s",
6187 VTY_NEWLINE);
6188 return CMD_WARNING;
6189 }
6190
6191 params = ospf_lookup_if_params (ifp, addr);
6192 if (params == NULL)
6193 return CMD_SUCCESS;
6194 }
6195
6196 memset (params->auth_simple, 0, OSPF_AUTH_SIMPLE_SIZE);
6197 UNSET_IF_PARAM (params, auth_simple);
6198
6199 if (params != IF_DEF_PARAMS (ifp))
6200 {
6201 ospf_free_if_params (ifp, addr);
6202 ospf_if_update_params (ifp, addr);
6203 }
6204
6205 return CMD_SUCCESS;
6206 }
6207
6208 DEFUN (no_ip_ospf_authentication_key,
6209 no_ip_ospf_authentication_key_authkey_addr_cmd,
6210 "no ip ospf authentication-key [AUTH_KEY [A.B.C.D]]",
6211 NO_STR
6212 "IP Information\n"
6213 "OSPF interface commands\n"
6214 "Authentication password (key)\n"
6215 "The OSPF password (key)")
6216 {
6217 struct interface *ifp;
6218 struct in_addr addr;
6219 struct ospf_if_params *params;
6220 int ret;
6221
6222 ifp = vty->index;
6223 params = IF_DEF_PARAMS (ifp);
6224
6225 if (argc == 6)
6226 {
6227 ret = inet_aton(argv[5]->arg, &addr);
6228 if (!ret)
6229 {
6230 vty_out (vty, "Please specify interface address by A.B.C.D%s",
6231 VTY_NEWLINE);
6232 return CMD_WARNING;
6233 }
6234
6235 params = ospf_lookup_if_params (ifp, addr);
6236 if (params == NULL)
6237 return CMD_SUCCESS;
6238 }
6239
6240 memset (params->auth_simple, 0, OSPF_AUTH_SIMPLE_SIZE);
6241 UNSET_IF_PARAM (params, auth_simple);
6242
6243 if (params != IF_DEF_PARAMS (ifp))
6244 {
6245 ospf_free_if_params (ifp, addr);
6246 ospf_if_update_params (ifp, addr);
6247 }
6248
6249 return CMD_SUCCESS;
6250 }
6251
6252 DEFUN (ip_ospf_message_digest_key,
6253 ip_ospf_message_digest_key_addr_cmd,
6254 "ip ospf message-digest-key (1-255) md5 KEY [A.B.C.D]",
6255 "IP Information\n"
6256 "OSPF interface commands\n"
6257 "Message digest authentication password (key)\n"
6258 "Key ID\n"
6259 "Use MD5 algorithm\n"
6260 "The OSPF password (key)"
6261 "Address of interface")
6262 {
6263 int idx_number = 3;
6264 int idx_ipv4 = 6;
6265 struct interface *ifp;
6266 struct crypt_key *ck;
6267 u_char key_id;
6268 struct in_addr addr;
6269 int ret;
6270 struct ospf_if_params *params;
6271
6272 ifp = vty->index;
6273 params = IF_DEF_PARAMS (ifp);
6274
6275 if (argc == 7)
6276 {
6277 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
6278 if (!ret)
6279 {
6280 vty_out (vty, "Please specify interface address by A.B.C.D%s",
6281 VTY_NEWLINE);
6282 return CMD_WARNING;
6283 }
6284
6285 params = ospf_get_if_params (ifp, addr);
6286 ospf_if_update_params (ifp, addr);
6287 }
6288
6289 key_id = strtol (argv[idx_number]->arg, NULL, 10);
6290 if (ospf_crypt_key_lookup (params->auth_crypt, key_id) != NULL)
6291 {
6292 vty_out (vty, "OSPF: Key %d already exists%s", key_id, VTY_NEWLINE);
6293 return CMD_WARNING;
6294 }
6295
6296 ck = ospf_crypt_key_new ();
6297 ck->key_id = (u_char) key_id;
6298 memset (ck->auth_key, 0, OSPF_AUTH_MD5_SIZE+1);
6299 strncpy ((char *) ck->auth_key, argv[idx_ipv4]->arg, OSPF_AUTH_MD5_SIZE);
6300
6301 ospf_crypt_key_add (params->auth_crypt, ck);
6302 SET_IF_PARAM (params, auth_crypt);
6303
6304 return CMD_SUCCESS;
6305 }
6306
6307
6308 DEFUN_HIDDEN (ospf_message_digest_key,
6309 ospf_message_digest_key_cmd,
6310 "ospf message-digest-key (1-255) md5 KEY",
6311 "OSPF interface commands\n"
6312 "Message digest authentication password (key)\n"
6313 "Key ID\n"
6314 "Use MD5 algorithm\n"
6315 "The OSPF password (key)")
6316 {
6317 int idx_number = 2;
6318 struct interface *ifp;
6319 struct crypt_key *ck;
6320 u_char key_id;
6321 struct ospf_if_params *params;
6322
6323 ifp = vty->index;
6324 params = IF_DEF_PARAMS (ifp);
6325 key_id = strtol (argv[idx_number]->arg, NULL, 10);
6326 if (ospf_crypt_key_lookup (params->auth_crypt, key_id) != NULL)
6327 {
6328 vty_out (vty, "OSPF: Key %d already exists%s", key_id, VTY_NEWLINE);
6329 return CMD_WARNING;
6330 }
6331
6332 ck = ospf_crypt_key_new ();
6333 ck->key_id = (u_char) key_id;
6334 memset (ck->auth_key, 0, OSPF_AUTH_MD5_SIZE+1);
6335 strncpy ((char *) ck->auth_key, argv[idx_number]->arg, OSPF_AUTH_MD5_SIZE);
6336
6337 ospf_crypt_key_add (params->auth_crypt, ck);
6338 SET_IF_PARAM (params, auth_crypt);
6339
6340 return CMD_SUCCESS;
6341 }
6342
6343 DEFUN (no_ip_ospf_message_digest_key_md5,
6344 no_ip_ospf_message_digest_key_md5_addr_cmd,
6345 "no ip ospf message-digest-key (1-255) md5 KEY [A.B.C.D]",
6346 NO_STR
6347 "IP Information\n"
6348 "OSPF interface commands\n"
6349 "Message digest authentication password (key)\n"
6350 "Key ID\n"
6351 "Use MD5 algorithm\n"
6352 "The OSPF password (key)"
6353 "Address of interface")
6354 {
6355 int idx_number = 4;
6356 struct interface *ifp;
6357 struct crypt_key *ck;
6358 int key_id;
6359 struct in_addr addr;
6360 int ret;
6361 struct ospf_if_params *params;
6362
6363 ifp = vty->index;
6364 params = IF_DEF_PARAMS (ifp);
6365
6366 if (argc == 8)
6367 {
6368 ret = inet_aton(argv[7]->arg, &addr);
6369 if (!ret)
6370 {
6371 vty_out (vty, "Please specify interface address by A.B.C.D%s",
6372 VTY_NEWLINE);
6373 return CMD_WARNING;
6374 }
6375
6376 params = ospf_lookup_if_params (ifp, addr);
6377 if (params == NULL)
6378 return CMD_SUCCESS;
6379 }
6380
6381 key_id = strtol (argv[idx_number]->arg, NULL, 10);
6382 ck = ospf_crypt_key_lookup (params->auth_crypt, key_id);
6383 if (ck == NULL)
6384 {
6385 vty_out (vty, "OSPF: Key %d does not exist%s", key_id, VTY_NEWLINE);
6386 return CMD_WARNING;
6387 }
6388
6389 ospf_crypt_key_delete (params->auth_crypt, key_id);
6390
6391 if (params != IF_DEF_PARAMS (ifp))
6392 {
6393 ospf_free_if_params (ifp, addr);
6394 ospf_if_update_params (ifp, addr);
6395 }
6396
6397 return CMD_SUCCESS;
6398 }
6399
6400 DEFUN (no_ospf_message_digest_key,
6401 no_ospf_message_digest_key_addr_cmd,
6402 "no ospf message-digest-key (1-255) [A.B.C.D]",
6403 NO_STR
6404 "OSPF interface commands\n"
6405 "Message digest authentication password (key)\n"
6406 "Key ID\n"
6407 "Address of interface")
6408 {
6409 int idx_number = 3;
6410 int idx_ipv4 = 4;
6411 struct interface *ifp;
6412 struct crypt_key *ck;
6413 int key_id;
6414 struct in_addr addr;
6415 int ret;
6416 struct ospf_if_params *params;
6417
6418 ifp = vty->index;
6419 params = IF_DEF_PARAMS (ifp);
6420
6421 if (argc == 5)
6422 {
6423 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
6424 if (!ret)
6425 {
6426 vty_out (vty, "Please specify interface address by A.B.C.D%s",
6427 VTY_NEWLINE);
6428 return CMD_WARNING;
6429 }
6430
6431 params = ospf_lookup_if_params (ifp, addr);
6432 if (params == NULL)
6433 return CMD_SUCCESS;
6434 }
6435
6436 key_id = strtol (argv[idx_number]->arg, NULL, 10);
6437 ck = ospf_crypt_key_lookup (params->auth_crypt, key_id);
6438 if (ck == NULL)
6439 {
6440 vty_out (vty, "OSPF: Key %d does not exist%s", key_id, VTY_NEWLINE);
6441 return CMD_WARNING;
6442 }
6443
6444 ospf_crypt_key_delete (params->auth_crypt, key_id);
6445
6446 if (params != IF_DEF_PARAMS (ifp))
6447 {
6448 ospf_free_if_params (ifp, addr);
6449 ospf_if_update_params (ifp, addr);
6450 }
6451
6452 return CMD_SUCCESS;
6453 }
6454
6455 DEFUN (no_ip_ospf_message_digest_key,
6456 no_ip_ospf_message_digest_key_addr_cmd,
6457 "no ip ospf message-digest-key (1-255) [A.B.C.D]",
6458 NO_STR
6459 "IP Information\n"
6460 "OSPF interface commands\n"
6461 "Message digest authentication password (key)\n"
6462 "Key ID\n"
6463 "Address of interface")
6464 {
6465 int idx_number = 4;
6466 int idx_ipv4 = 5;
6467 struct interface *ifp;
6468 struct crypt_key *ck;
6469 int key_id;
6470 struct in_addr addr;
6471 int ret;
6472 struct ospf_if_params *params;
6473
6474 ifp = vty->index;
6475 params = IF_DEF_PARAMS (ifp);
6476
6477 if (argc == 6)
6478 {
6479 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
6480 if (!ret)
6481 {
6482 vty_out (vty, "Please specify interface address by A.B.C.D%s",
6483 VTY_NEWLINE);
6484 return CMD_WARNING;
6485 }
6486
6487 params = ospf_lookup_if_params (ifp, addr);
6488 if (params == NULL)
6489 return CMD_SUCCESS;
6490 }
6491
6492 key_id = strtol (argv[idx_number]->arg, NULL, 10);
6493 ck = ospf_crypt_key_lookup (params->auth_crypt, key_id);
6494 if (ck == NULL)
6495 {
6496 vty_out (vty, "OSPF: Key %d does not exist%s", key_id, VTY_NEWLINE);
6497 return CMD_WARNING;
6498 }
6499
6500 ospf_crypt_key_delete (params->auth_crypt, key_id);
6501
6502 if (params != IF_DEF_PARAMS (ifp))
6503 {
6504 ospf_free_if_params (ifp, addr);
6505 ospf_if_update_params (ifp, addr);
6506 }
6507
6508 return CMD_SUCCESS;
6509 }
6510
6511 DEFUN (ip_ospf_cost,
6512 ip_ospf_cost_u32_inet4_cmd,
6513 "ip ospf cost (1-65535) [A.B.C.D]",
6514 "IP Information\n"
6515 "OSPF interface commands\n"
6516 "Interface cost\n"
6517 "Cost\n"
6518 "Address of interface")
6519 {
6520 int idx_number = 3;
6521 int idx_ipv4 = 4;
6522 struct interface *ifp = vty->index;
6523 u_int32_t cost;
6524 struct in_addr addr;
6525 int ret;
6526 struct ospf_if_params *params;
6527
6528 params = IF_DEF_PARAMS (ifp);
6529
6530 cost = strtol (argv[idx_number]->arg, NULL, 10);
6531
6532 /* cost range is <1-65535>. */
6533 if (cost < 1 || cost > 65535)
6534 {
6535 vty_out (vty, "Interface output cost is invalid%s", VTY_NEWLINE);
6536 return CMD_WARNING;
6537 }
6538
6539 if (argc == 5)
6540 {
6541 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
6542 if (!ret)
6543 {
6544 vty_out (vty, "Please specify interface address by A.B.C.D%s",
6545 VTY_NEWLINE);
6546 return CMD_WARNING;
6547 }
6548
6549 params = ospf_get_if_params (ifp, addr);
6550 ospf_if_update_params (ifp, addr);
6551 }
6552
6553 SET_IF_PARAM (params, output_cost_cmd);
6554 params->output_cost_cmd = cost;
6555
6556 ospf_if_recalculate_output_cost (ifp);
6557
6558 return CMD_SUCCESS;
6559 }
6560
6561 DEFUN_HIDDEN (ospf_cost,
6562 ospf_cost_u32_inet4_cmd,
6563 "ospf cost (1-65535) A.B.C.D",
6564 "OSPF interface commands\n"
6565 "Interface cost\n"
6566 "Cost\n"
6567 "Address of interface")
6568 {
6569 int idx_number = 2;
6570 int idx_ipv4 = 3;
6571 struct interface *ifp = vty->index;
6572 u_int32_t cost;
6573 struct in_addr addr;
6574 int ret;
6575 struct ospf_if_params *params;
6576
6577 params = IF_DEF_PARAMS (ifp);
6578
6579 cost = strtol (argv[idx_number]->arg, NULL, 10);
6580
6581 /* cost range is <1-65535>. */
6582 if (cost < 1 || cost > 65535)
6583 {
6584 vty_out (vty, "Interface output cost is invalid%s", VTY_NEWLINE);
6585 return CMD_WARNING;
6586 }
6587
6588 if (argc == 5)
6589 {
6590 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
6591 if (!ret)
6592 {
6593 vty_out (vty, "Please specify interface address by A.B.C.D%s",
6594 VTY_NEWLINE);
6595 return CMD_WARNING;
6596 }
6597
6598 params = ospf_get_if_params (ifp, addr);
6599 ospf_if_update_params (ifp, addr);
6600 }
6601
6602 SET_IF_PARAM (params, output_cost_cmd);
6603 params->output_cost_cmd = cost;
6604
6605 ospf_if_recalculate_output_cost (ifp);
6606
6607 return CMD_SUCCESS;
6608 }
6609
6610 DEFUN (no_ospf_cost,
6611 no_ospf_cost_inet4_cmd,
6612 "no ospf cost [A.B.C.D]",
6613 NO_STR
6614 "OSPF interface commands\n"
6615 "Interface cost\n"
6616 "Address of interface")
6617 {
6618 int idx_ipv4 = 3;
6619 struct interface *ifp = vty->index;
6620 struct in_addr addr;
6621 int ret;
6622 struct ospf_if_params *params;
6623
6624 ifp = vty->index;
6625 params = IF_DEF_PARAMS (ifp);
6626
6627 if (argc == 4)
6628 {
6629 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
6630 if (!ret)
6631 {
6632 vty_out (vty, "Please specify interface address by A.B.C.D%s",
6633 VTY_NEWLINE);
6634 return CMD_WARNING;
6635 }
6636
6637 params = ospf_lookup_if_params (ifp, addr);
6638 if (params == NULL)
6639 return CMD_SUCCESS;
6640 }
6641
6642 UNSET_IF_PARAM (params, output_cost_cmd);
6643
6644 if (params != IF_DEF_PARAMS (ifp))
6645 {
6646 ospf_free_if_params (ifp, addr);
6647 ospf_if_update_params (ifp, addr);
6648 }
6649
6650 ospf_if_recalculate_output_cost (ifp);
6651
6652 return CMD_SUCCESS;
6653 }
6654
6655 DEFUN (no_ip_ospf_cost,
6656 no_ip_ospf_cost_inet4_cmd,
6657 "no ip ospf cost [A.B.C.D]",
6658 NO_STR
6659 "IP Information\n"
6660 "OSPF interface commands\n"
6661 "Interface cost\n"
6662 "Address of interface")
6663 {
6664 int idx_ipv4 = 4;
6665 struct interface *ifp = vty->index;
6666 struct in_addr addr;
6667 int ret;
6668 struct ospf_if_params *params;
6669
6670 ifp = vty->index;
6671 params = IF_DEF_PARAMS (ifp);
6672
6673 if (argc == 5)
6674 {
6675 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
6676 if (!ret)
6677 {
6678 vty_out (vty, "Please specify interface address by A.B.C.D%s",
6679 VTY_NEWLINE);
6680 return CMD_WARNING;
6681 }
6682
6683 params = ospf_lookup_if_params (ifp, addr);
6684 if (params == NULL)
6685 return CMD_SUCCESS;
6686 }
6687
6688 UNSET_IF_PARAM (params, output_cost_cmd);
6689
6690 if (params != IF_DEF_PARAMS (ifp))
6691 {
6692 ospf_free_if_params (ifp, addr);
6693 ospf_if_update_params (ifp, addr);
6694 }
6695
6696 ospf_if_recalculate_output_cost (ifp);
6697
6698 return CMD_SUCCESS;
6699 }
6700
6701 DEFUN (no_ospf_cost2,
6702 no_ospf_cost_u32_cmd,
6703 "no ospf cost [(1-65535) [A.B.C.D]]",
6704 NO_STR
6705 "OSPF interface commands\n"
6706 "Interface cost\n"
6707 "Cost\n"
6708 "Address of interface\n")
6709 {
6710 int idx_number = 3;
6711 int idx_ipv4 = 4;
6712 struct interface *ifp = vty->index;
6713 struct in_addr addr;
6714 u_int32_t cost;
6715 int ret;
6716 struct ospf_if_params *params;
6717
6718 ifp = vty->index;
6719 params = IF_DEF_PARAMS (ifp);
6720
6721 /* According to the semantics we are mimicking "no ip ospf cost N" is
6722 * always treated as "no ip ospf cost" regardless of the actual value
6723 * of N already configured for the interface. Thus the first argument
6724 * is always checked to be a number, but is ignored after that.
6725 */
6726 cost = strtol (argv[idx_number]->arg, NULL, 10);
6727 if (cost < 1 || cost > 65535)
6728 {
6729 vty_out (vty, "Interface output cost is invalid%s", VTY_NEWLINE);
6730 return CMD_WARNING;
6731 }
6732
6733 if (argc == 5)
6734 {
6735 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
6736 if (!ret)
6737 {
6738 vty_out (vty, "Please specify interface address by A.B.C.D%s",
6739 VTY_NEWLINE);
6740 return CMD_WARNING;
6741 }
6742
6743 params = ospf_lookup_if_params (ifp, addr);
6744 if (params == NULL)
6745 return CMD_SUCCESS;
6746 }
6747
6748 UNSET_IF_PARAM (params, output_cost_cmd);
6749
6750 if (params != IF_DEF_PARAMS (ifp))
6751 {
6752 ospf_free_if_params (ifp, addr);
6753 ospf_if_update_params (ifp, addr);
6754 }
6755
6756 ospf_if_recalculate_output_cost (ifp);
6757
6758 return CMD_SUCCESS;
6759 }
6760
6761 DEFUN (no_ip_ospf_cost2,
6762 no_ip_ospf_cost_u32_cmd,
6763 "no ip ospf cost (1-65535) [A.B.C.D]",
6764 NO_STR
6765 "IP Information\n"
6766 "OSPF interface commands\n"
6767 "Interface cost\n"
6768 "Cost\n"
6769 "Address of interface\n")
6770 {
6771 int idx_number = 4;
6772 int idx_ipv4 = 5;
6773 struct interface *ifp = vty->index;
6774 struct in_addr addr;
6775 u_int32_t cost;
6776 int ret;
6777 struct ospf_if_params *params;
6778
6779 ifp = vty->index;
6780 params = IF_DEF_PARAMS (ifp);
6781
6782 /* According to the semantics we are mimicking "no ip ospf cost N" is
6783 * always treated as "no ip ospf cost" regardless of the actual value
6784 * of N already configured for the interface. Thus the first argument
6785 * is always checked to be a number, but is ignored after that.
6786 */
6787 cost = strtol (argv[idx_number]->arg, NULL, 10);
6788 if (cost < 1 || cost > 65535)
6789 {
6790 vty_out (vty, "Interface output cost is invalid%s", VTY_NEWLINE);
6791 return CMD_WARNING;
6792 }
6793
6794 if (argc == 5)
6795 {
6796 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
6797 if (!ret)
6798 {
6799 vty_out (vty, "Please specify interface address by A.B.C.D%s",
6800 VTY_NEWLINE);
6801 return CMD_WARNING;
6802 }
6803
6804 params = ospf_lookup_if_params (ifp, addr);
6805 if (params == NULL)
6806 return CMD_SUCCESS;
6807 }
6808
6809 UNSET_IF_PARAM (params, output_cost_cmd);
6810
6811 if (params != IF_DEF_PARAMS (ifp))
6812 {
6813 ospf_free_if_params (ifp, addr);
6814 ospf_if_update_params (ifp, addr);
6815 }
6816
6817 ospf_if_recalculate_output_cost (ifp);
6818
6819 return CMD_SUCCESS;
6820 }
6821
6822
6823
6824
6825 static void
6826 ospf_nbr_timer_update (struct ospf_interface *oi)
6827 {
6828 struct route_node *rn;
6829 struct ospf_neighbor *nbr;
6830
6831 for (rn = route_top (oi->nbrs); rn; rn = route_next (rn))
6832 if ((nbr = rn->info))
6833 {
6834 nbr->v_inactivity = OSPF_IF_PARAM (oi, v_wait);
6835 nbr->v_db_desc = OSPF_IF_PARAM (oi, retransmit_interval);
6836 nbr->v_ls_req = OSPF_IF_PARAM (oi, retransmit_interval);
6837 nbr->v_ls_upd = OSPF_IF_PARAM (oi, retransmit_interval);
6838 }
6839 }
6840
6841 static int
6842 ospf_vty_dead_interval_set (struct vty *vty, const char *interval_str,
6843 const char *nbr_str,
6844 const char *fast_hello_str)
6845 {
6846 struct interface *ifp = vty->index;
6847 u_int32_t seconds;
6848 u_char hellomult;
6849 struct in_addr addr;
6850 int ret;
6851 struct ospf_if_params *params;
6852 struct ospf_interface *oi;
6853 struct route_node *rn;
6854
6855 params = IF_DEF_PARAMS (ifp);
6856
6857 if (nbr_str)
6858 {
6859 ret = inet_aton(nbr_str, &addr);
6860 if (!ret)
6861 {
6862 vty_out (vty, "Please specify interface address by A.B.C.D%s",
6863 VTY_NEWLINE);
6864 return CMD_WARNING;
6865 }
6866
6867 params = ospf_get_if_params (ifp, addr);
6868 ospf_if_update_params (ifp, addr);
6869 }
6870
6871 if (interval_str)
6872 {
6873 VTY_GET_INTEGER_RANGE ("Router Dead Interval", seconds, interval_str,
6874 1, 65535);
6875
6876 /* reset fast_hello too, just to be sure */
6877 UNSET_IF_PARAM (params, fast_hello);
6878 params->fast_hello = OSPF_FAST_HELLO_DEFAULT;
6879 }
6880 else if (fast_hello_str)
6881 {
6882 VTY_GET_INTEGER_RANGE ("Hello Multiplier", hellomult, fast_hello_str,
6883 1, 10);
6884 /* 1s dead-interval with sub-second hellos desired */
6885 seconds = OSPF_ROUTER_DEAD_INTERVAL_MINIMAL;
6886 SET_IF_PARAM (params, fast_hello);
6887 params->fast_hello = hellomult;
6888 }
6889 else
6890 {
6891 vty_out (vty, "Please specify dead-interval or hello-multiplier%s",
6892 VTY_NEWLINE);
6893 return CMD_WARNING;
6894 }
6895
6896 SET_IF_PARAM (params, v_wait);
6897 params->v_wait = seconds;
6898
6899 /* Update timer values in neighbor structure. */
6900 if (nbr_str)
6901 {
6902 struct ospf *ospf;
6903 if ((ospf = ospf_lookup()))
6904 {
6905 oi = ospf_if_lookup_by_local_addr (ospf, ifp, addr);
6906 if (oi)
6907 ospf_nbr_timer_update (oi);
6908 }
6909 }
6910 else
6911 {
6912 for (rn = route_top (IF_OIFS (ifp)); rn; rn = route_next (rn))
6913 if ((oi = rn->info))
6914 ospf_nbr_timer_update (oi);
6915 }
6916
6917 return CMD_SUCCESS;
6918 }
6919
6920 DEFUN (ip_ospf_dead_interval,
6921 ip_ospf_dead_interval_addr_cmd,
6922 "ip ospf dead-interval (1-65535) [A.B.C.D]",
6923 "IP Information\n"
6924 "OSPF interface commands\n"
6925 "Interval after which a neighbor is declared dead\n"
6926 "Seconds\n"
6927 "Address of interface\n")
6928 {
6929 int idx_number = 3;
6930 int idx_ipv4 = 4;
6931 if (argc == 5)
6932 return ospf_vty_dead_interval_set (vty, argv[idx_number]->arg, argv[idx_ipv4]->arg, NULL);
6933 else
6934 return ospf_vty_dead_interval_set (vty, argv[idx_number]->arg, NULL, NULL);
6935 }
6936
6937
6938 DEFUN_HIDDEN (ospf_dead_interval,
6939 ospf_dead_interval_cmd,
6940 "ospf dead-interval (1-65535)",
6941 "OSPF interface commands\n"
6942 "Interval after which a neighbor is declared dead\n"
6943 "Seconds\n")
6944 {
6945 int idx_number = 2;
6946
6947 return ospf_vty_dead_interval_set (vty, argv[idx_number]->arg, NULL, NULL);
6948 }
6949
6950 DEFUN (ip_ospf_dead_interval_minimal,
6951 ip_ospf_dead_interval_minimal_addr_cmd,
6952 "ip ospf dead-interval minimal hello-multiplier (1-10) [A.B.C.D]",
6953 "IP Information\n"
6954 "OSPF interface commands\n"
6955 "Interval after which a neighbor is declared dead\n"
6956 "Minimal 1s dead-interval with fast sub-second hellos\n"
6957 "Hello multiplier factor\n"
6958 "Number of Hellos to send each second\n"
6959 "Address of interface\n")
6960 {
6961 int idx_number = 5;
6962 int idx_ipv4 = 6;
6963 if (argc == 7)
6964 return ospf_vty_dead_interval_set (vty, NULL, argv[idx_ipv4]->arg, argv[idx_number]->arg);
6965 else
6966 return ospf_vty_dead_interval_set (vty, NULL, NULL, argv[idx_number]->arg);
6967 }
6968
6969 DEFUN (no_ospf_dead_interval,
6970 no_ospf_dead_interval_cmd,
6971 "no ospf dead-interval",
6972 NO_STR
6973 "OSPF interface commands\n"
6974 "Interval after which a neighbor is declared dead\n")
6975 {
6976 struct interface *ifp = vty->index;
6977 struct ospf_if_params *params;
6978
6979 ifp = vty->index;
6980 params = IF_DEF_PARAMS (ifp);
6981
6982 UNSET_IF_PARAM (params, v_wait);
6983 params->v_wait = OSPF_ROUTER_DEAD_INTERVAL_DEFAULT;
6984
6985 UNSET_IF_PARAM (params, fast_hello);
6986 params->fast_hello = OSPF_FAST_HELLO_DEFAULT;
6987
6988 return CMD_SUCCESS;
6989 }
6990
6991 DEFUN (no_ip_ospf_dead_interval,
6992 no_ip_ospf_dead_interval_addr_cmd,
6993 "no ip ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]",
6994 NO_STR
6995 "IP Information\n"
6996 "OSPF interface commands\n"
6997 "Interval after which a neighbor is declared dead\n"
6998 "Seconds\n"
6999 "Address of interface")
7000 {
7001 int idx_ipv4 = argc - 1;
7002 struct interface *ifp = vty->index;
7003 struct in_addr addr;
7004 int ret;
7005 struct ospf_if_params *params;
7006 struct ospf_interface *oi;
7007 struct route_node *rn;
7008
7009 ifp = vty->index;
7010 params = IF_DEF_PARAMS (ifp);
7011
7012 if (argv[idx_ipv4]->type == IPV4_TKN)
7013 {
7014 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
7015 if (!ret)
7016 {
7017 vty_out (vty, "Please specify interface address by A.B.C.D%s",
7018 VTY_NEWLINE);
7019 return CMD_WARNING;
7020 }
7021
7022 params = ospf_lookup_if_params (ifp, addr);
7023 if (params == NULL)
7024 return CMD_SUCCESS;
7025 }
7026
7027 UNSET_IF_PARAM (params, v_wait);
7028 params->v_wait = OSPF_ROUTER_DEAD_INTERVAL_DEFAULT;
7029
7030 UNSET_IF_PARAM (params, fast_hello);
7031 params->fast_hello = OSPF_FAST_HELLO_DEFAULT;
7032
7033 if (params != IF_DEF_PARAMS (ifp))
7034 {
7035 ospf_free_if_params (ifp, addr);
7036 ospf_if_update_params (ifp, addr);
7037 }
7038
7039 /* Update timer values in neighbor structure. */
7040 if (argc == 1)
7041 {
7042 struct ospf *ospf;
7043
7044 if ((ospf = ospf_lookup()))
7045 {
7046 oi = ospf_if_lookup_by_local_addr (ospf, ifp, addr);
7047 if (oi)
7048 ospf_nbr_timer_update (oi);
7049 }
7050 }
7051 else
7052 {
7053 for (rn = route_top (IF_OIFS (ifp)); rn; rn = route_next (rn))
7054 if ((oi = rn->info))
7055 ospf_nbr_timer_update (oi);
7056 }
7057
7058 return CMD_SUCCESS;
7059 }
7060
7061 DEFUN (ip_ospf_hello_interval,
7062 ip_ospf_hello_interval_addr_cmd,
7063 "ip ospf hello-interval (1-65535) [A.B.C.D]",
7064 "IP Information\n"
7065 "OSPF interface commands\n"
7066 "Time between HELLO packets\n"
7067 "Seconds\n"
7068 "Address of interface")
7069 {
7070 int idx_number = 3;
7071 int idx_ipv4 = 4;
7072 struct interface *ifp = vty->index;
7073 u_int32_t seconds;
7074 struct in_addr addr;
7075 int ret;
7076 struct ospf_if_params *params;
7077
7078 params = IF_DEF_PARAMS (ifp);
7079
7080 seconds = strtol (argv[idx_number]->arg, NULL, 10);
7081
7082 /* HelloInterval range is <1-65535>. */
7083 if (seconds < 1 || seconds > 65535)
7084 {
7085 vty_out (vty, "Hello Interval is invalid%s", VTY_NEWLINE);
7086 return CMD_WARNING;
7087 }
7088
7089 if (argc == 5)
7090 {
7091 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
7092 if (!ret)
7093 {
7094 vty_out (vty, "Please specify interface address by A.B.C.D%s",
7095 VTY_NEWLINE);
7096 return CMD_WARNING;
7097 }
7098
7099 params = ospf_get_if_params (ifp, addr);
7100 ospf_if_update_params (ifp, addr);
7101 }
7102
7103 SET_IF_PARAM (params, v_hello);
7104 params->v_hello = seconds;
7105
7106 return CMD_SUCCESS;
7107 }
7108
7109
7110 DEFUN_HIDDEN (ospf_hello_interval,
7111 ospf_hello_interval_cmd,
7112 "ospf hello-interval (1-65535)",
7113 "OSPF interface commands\n"
7114 "Time between HELLO packets\n"
7115 "Seconds\n")
7116 {
7117 int idx_number = 2;
7118 struct interface *ifp = vty->index;
7119 u_int32_t seconds;
7120 struct ospf_if_params *params;
7121
7122 params = IF_DEF_PARAMS (ifp);
7123
7124 seconds = strtol (argv[idx_number]->arg, NULL, 10);
7125
7126 /* HelloInterval range is <1-65535>. */
7127 if (seconds < 1 || seconds > 65535)
7128 {
7129 vty_out (vty, "Hello Interval is invalid%s", VTY_NEWLINE);
7130 return CMD_WARNING;
7131 }
7132
7133 SET_IF_PARAM (params, v_hello);
7134 params->v_hello = seconds;
7135
7136 return CMD_SUCCESS;
7137 }
7138
7139 DEFUN (no_ip_ospf_hello_interval,
7140 no_ip_ospf_hello_interval_addr_cmd,
7141 "no [ip] ospf hello-interval [(1-65535) [A.B.C.D]]",
7142 NO_STR
7143 "IP Information\n"
7144 "OSPF interface commands\n"
7145 "Time between HELLO packets\n"
7146 "Seconds\n"
7147 "Address of interface")
7148 {
7149 int idx_ipv4 = 5;
7150 struct interface *ifp = vty->index;
7151 struct in_addr addr;
7152 int ret;
7153 struct ospf_if_params *params;
7154
7155 ifp = vty->index;
7156 params = IF_DEF_PARAMS (ifp);
7157
7158 if (strcmp (argv[1]->arg, "ip") == 0)
7159 idx_ipv4 = 4;
7160
7161 if (argc == idx_ipv4+1)
7162 {
7163 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
7164 if (!ret)
7165 {
7166 vty_out (vty, "Please specify interface address by A.B.C.D%s",
7167 VTY_NEWLINE);
7168 return CMD_WARNING;
7169 }
7170
7171 params = ospf_lookup_if_params (ifp, addr);
7172 if (params == NULL)
7173 return CMD_SUCCESS;
7174 }
7175
7176 UNSET_IF_PARAM (params, v_hello);
7177 params->v_hello = OSPF_HELLO_INTERVAL_DEFAULT;
7178
7179 if (params != IF_DEF_PARAMS (ifp))
7180 {
7181 ospf_free_if_params (ifp, addr);
7182 ospf_if_update_params (ifp, addr);
7183 }
7184
7185 return CMD_SUCCESS;
7186 }
7187
7188
7189
7190
7191 DEFUN (ip_ospf_network,
7192 ip_ospf_network_cmd,
7193 "ip ospf network <broadcast|non-broadcast|point-to-multipoint|point-to-point>",
7194 "IP Information\n"
7195 "OSPF interface commands\n"
7196 "Network type\n"
7197 "Specify OSPF broadcast multi-access network\n"
7198 "Specify OSPF NBMA network\n"
7199 "Specify OSPF point-to-multipoint network\n"
7200 "Specify OSPF point-to-point network\n")
7201 {
7202 int idx_network = 3;
7203 struct interface *ifp = vty->index;
7204 int old_type = IF_DEF_PARAMS (ifp)->type;
7205 struct route_node *rn;
7206
7207 if (old_type == OSPF_IFTYPE_LOOPBACK)
7208 {
7209 vty_out (vty, "This is a loopback interface. Can't set network type.%s", VTY_NEWLINE);
7210 return CMD_WARNING;
7211 }
7212
7213 if (strncmp (argv[idx_network]->arg, "b", 1) == 0)
7214 IF_DEF_PARAMS (ifp)->type = OSPF_IFTYPE_BROADCAST;
7215 else if (strncmp (argv[idx_network]->arg, "n", 1) == 0)
7216 IF_DEF_PARAMS (ifp)->type = OSPF_IFTYPE_NBMA;
7217 else if (strncmp (argv[idx_network]->arg, "point-to-m", 10) == 0)
7218 IF_DEF_PARAMS (ifp)->type = OSPF_IFTYPE_POINTOMULTIPOINT;
7219 else if (strncmp (argv[idx_network]->arg, "point-to-p", 10) == 0)
7220 IF_DEF_PARAMS (ifp)->type = OSPF_IFTYPE_POINTOPOINT;
7221
7222 if (IF_DEF_PARAMS (ifp)->type == old_type)
7223 return CMD_SUCCESS;
7224
7225 SET_IF_PARAM (IF_DEF_PARAMS (ifp), type);
7226
7227 for (rn = route_top (IF_OIFS (ifp)); rn; rn = route_next (rn))
7228 {
7229 struct ospf_interface *oi = rn->info;
7230
7231 if (!oi)
7232 continue;
7233
7234 oi->type = IF_DEF_PARAMS (ifp)->type;
7235
7236 if (oi->state > ISM_Down)
7237 {
7238 OSPF_ISM_EVENT_EXECUTE (oi, ISM_InterfaceDown);
7239 OSPF_ISM_EVENT_EXECUTE (oi, ISM_InterfaceUp);
7240 }
7241 }
7242
7243 return CMD_SUCCESS;
7244 }
7245
7246 DEFUN_HIDDEN (ospf_network,
7247 ospf_network_cmd,
7248 "ospf network <broadcast|non-broadcast|point-to-multipoint|point-to-point>",
7249 "OSPF interface commands\n"
7250 "Network type\n"
7251 "Specify OSPF broadcast multi-access network\n"
7252 "Specify OSPF NBMA network\n"
7253 "Specify OSPF point-to-multipoint network\n"
7254 "Specify OSPF point-to-point network\n")
7255 {
7256 int idx_network = 2;
7257 struct interface *ifp = vty->index;
7258 int old_type = IF_DEF_PARAMS (ifp)->type;
7259 struct route_node *rn;
7260
7261 if (old_type == OSPF_IFTYPE_LOOPBACK)
7262 {
7263 vty_out (vty, "This is a loopback interface. Can't set network type.%s", VTY_NEWLINE);
7264 return CMD_WARNING;
7265 }
7266
7267 if (strncmp (argv[idx_network]->arg, "b", 1) == 0)
7268 IF_DEF_PARAMS (ifp)->type = OSPF_IFTYPE_BROADCAST;
7269 else if (strncmp (argv[idx_network]->arg, "n", 1) == 0)
7270 IF_DEF_PARAMS (ifp)->type = OSPF_IFTYPE_NBMA;
7271 else if (strncmp (argv[idx_network]->arg, "point-to-m", 10) == 0)
7272 IF_DEF_PARAMS (ifp)->type = OSPF_IFTYPE_POINTOMULTIPOINT;
7273 else if (strncmp (argv[idx_network]->arg, "point-to-p", 10) == 0)
7274 IF_DEF_PARAMS (ifp)->type = OSPF_IFTYPE_POINTOPOINT;
7275
7276 if (IF_DEF_PARAMS (ifp)->type == old_type)
7277 return CMD_SUCCESS;
7278
7279 SET_IF_PARAM (IF_DEF_PARAMS (ifp), type);
7280
7281 for (rn = route_top (IF_OIFS (ifp)); rn; rn = route_next (rn))
7282 {
7283 struct ospf_interface *oi = rn->info;
7284
7285 if (!oi)
7286 continue;
7287
7288 oi->type = IF_DEF_PARAMS (ifp)->type;
7289
7290 if (oi->state > ISM_Down)
7291 {
7292 OSPF_ISM_EVENT_EXECUTE (oi, ISM_InterfaceDown);
7293 OSPF_ISM_EVENT_EXECUTE (oi, ISM_InterfaceUp);
7294 }
7295 }
7296
7297 return CMD_SUCCESS;
7298 }
7299
7300 DEFUN (no_ospf_network,
7301 no_ospf_network_cmd,
7302 "no ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]",
7303 NO_STR
7304 "OSPF interface commands\n"
7305 "Network type\n"
7306 "Specify OSPF broadcast multi-access network\n"
7307 "Specify OSPF NBMA network\n"
7308 "Specify OSPF point-to-multipoint network\n"
7309 "Specify OSPF point-to-point network\n")
7310 {
7311 struct interface *ifp = vty->index;
7312 int old_type = IF_DEF_PARAMS (ifp)->type;
7313 struct route_node *rn;
7314
7315 IF_DEF_PARAMS (ifp)->type = ospf_default_iftype(ifp);
7316
7317 if (IF_DEF_PARAMS (ifp)->type == old_type)
7318 return CMD_SUCCESS;
7319
7320 for (rn = route_top (IF_OIFS (ifp)); rn; rn = route_next (rn))
7321 {
7322 struct ospf_interface *oi = rn->info;
7323
7324 if (!oi)
7325 continue;
7326
7327 oi->type = IF_DEF_PARAMS (ifp)->type;
7328
7329 if (oi->state > ISM_Down)
7330 {
7331 OSPF_ISM_EVENT_EXECUTE (oi, ISM_InterfaceDown);
7332 OSPF_ISM_EVENT_EXECUTE (oi, ISM_InterfaceUp);
7333 }
7334 }
7335
7336 return CMD_SUCCESS;
7337 }
7338
7339 DEFUN (no_ip_ospf_network,
7340 no_ip_ospf_network_cmd,
7341 "no ip ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]",
7342 NO_STR
7343 "IP Information\n"
7344 "OSPF interface commands\n"
7345 "Network type\n"
7346 "Specify OSPF broadcast multi-access network\n"
7347 "Specify OSPF NBMA network\n"
7348 "Specify OSPF point-to-multipoint network\n"
7349 "Specify OSPF point-to-point network\n")
7350 {
7351 struct interface *ifp = vty->index;
7352 int old_type = IF_DEF_PARAMS (ifp)->type;
7353 struct route_node *rn;
7354
7355 IF_DEF_PARAMS (ifp)->type = ospf_default_iftype(ifp);
7356
7357 if (IF_DEF_PARAMS (ifp)->type == old_type)
7358 return CMD_SUCCESS;
7359
7360 for (rn = route_top (IF_OIFS (ifp)); rn; rn = route_next (rn))
7361 {
7362 struct ospf_interface *oi = rn->info;
7363
7364 if (!oi)
7365 continue;
7366
7367 oi->type = IF_DEF_PARAMS (ifp)->type;
7368
7369 if (oi->state > ISM_Down)
7370 {
7371 OSPF_ISM_EVENT_EXECUTE (oi, ISM_InterfaceDown);
7372 OSPF_ISM_EVENT_EXECUTE (oi, ISM_InterfaceUp);
7373 }
7374 }
7375
7376 return CMD_SUCCESS;
7377 }
7378
7379 DEFUN (ip_ospf_priority,
7380 ip_ospf_priority_addr_cmd,
7381 "ip ospf priority (0-255) [A.B.C.D]",
7382 "IP Information\n"
7383 "OSPF interface commands\n"
7384 "Router priority\n"
7385 "Priority\n"
7386 "Address of interface")
7387 {
7388 int idx_number = 3;
7389 int idx_ipv4 = 4;
7390 struct interface *ifp = vty->index;
7391 long priority;
7392 struct route_node *rn;
7393 struct in_addr addr;
7394 int ret;
7395 struct ospf_if_params *params;
7396
7397 params = IF_DEF_PARAMS (ifp);
7398
7399 priority = strtol (argv[idx_number]->arg, NULL, 10);
7400
7401 /* Router Priority range is <0-255>. */
7402 if (priority < 0 || priority > 255)
7403 {
7404 vty_out (vty, "Router Priority is invalid%s", VTY_NEWLINE);
7405 return CMD_WARNING;
7406 }
7407
7408 if (argc == 5)
7409 {
7410 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
7411 if (!ret)
7412 {
7413 vty_out (vty, "Please specify interface address by A.B.C.D%s",
7414 VTY_NEWLINE);
7415 return CMD_WARNING;
7416 }
7417
7418 params = ospf_get_if_params (ifp, addr);
7419 ospf_if_update_params (ifp, addr);
7420 }
7421
7422 SET_IF_PARAM (params, priority);
7423 params->priority = priority;
7424
7425 for (rn = route_top (IF_OIFS (ifp)); rn; rn = route_next (rn))
7426 {
7427 struct ospf_interface *oi = rn->info;
7428
7429 if (!oi)
7430 continue;
7431
7432 if (PRIORITY (oi) != OSPF_IF_PARAM (oi, priority))
7433 {
7434 PRIORITY (oi) = OSPF_IF_PARAM (oi, priority);
7435 OSPF_ISM_EVENT_SCHEDULE (oi, ISM_NeighborChange);
7436 }
7437 }
7438
7439 return CMD_SUCCESS;
7440 }
7441
7442
7443 DEFUN_HIDDEN (ospf_priority,
7444 ospf_priority_cmd,
7445 "ospf priority (0-255)",
7446 "OSPF interface commands\n"
7447 "Router priority\n"
7448 "Priority\n")
7449 {
7450 int idx_number = 2;
7451 struct interface *ifp = vty->index;
7452 long priority;
7453 struct route_node *rn;
7454 struct ospf_if_params *params;
7455
7456 params = IF_DEF_PARAMS (ifp);
7457
7458 priority = strtol (argv[idx_number]->arg, NULL, 10);
7459
7460 /* Router Priority range is <0-255>. */
7461 if (priority < 0 || priority > 255)
7462 {
7463 vty_out (vty, "Router Priority is invalid%s", VTY_NEWLINE);
7464 return CMD_WARNING;
7465 }
7466
7467 SET_IF_PARAM (params, priority);
7468 params->priority = priority;
7469
7470 for (rn = route_top (IF_OIFS (ifp)); rn; rn = route_next (rn))
7471 {
7472 struct ospf_interface *oi = rn->info;
7473
7474 if (!oi)
7475 continue;
7476
7477
7478 if (PRIORITY (oi) != OSPF_IF_PARAM (oi, priority))
7479 {
7480 PRIORITY (oi) = OSPF_IF_PARAM (oi, priority);
7481 OSPF_ISM_EVENT_SCHEDULE (oi, ISM_NeighborChange);
7482 }
7483 }
7484
7485 return CMD_SUCCESS;
7486 }
7487
7488 DEFUN (no_ospf_priority,
7489 no_ospf_priority_addr_cmd,
7490 "no ospf priority [(0-255) [A.B.C.D]]",
7491 NO_STR
7492 "OSPF interface commands\n"
7493 "Router priority\n"
7494 "Priority\n"
7495 "Address of interface")
7496 {
7497 int idx_ipv4 = 4;
7498 struct interface *ifp = vty->index;
7499 struct route_node *rn;
7500 struct in_addr addr;
7501 int ret;
7502 struct ospf_if_params *params;
7503
7504 ifp = vty->index;
7505 params = IF_DEF_PARAMS (ifp);
7506
7507 if (argc == 5)
7508 {
7509 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
7510 if (!ret)
7511 {
7512 vty_out (vty, "Please specify interface address by A.B.C.D%s",
7513 VTY_NEWLINE);
7514 return CMD_WARNING;
7515 }
7516
7517 params = ospf_lookup_if_params (ifp, addr);
7518 if (params == NULL)
7519 return CMD_SUCCESS;
7520 }
7521
7522 UNSET_IF_PARAM (params, priority);
7523 params->priority = OSPF_ROUTER_PRIORITY_DEFAULT;
7524
7525 if (params != IF_DEF_PARAMS (ifp))
7526 {
7527 ospf_free_if_params (ifp, addr);
7528 ospf_if_update_params (ifp, addr);
7529 }
7530
7531 for (rn = route_top (IF_OIFS (ifp)); rn; rn = route_next (rn))
7532 {
7533 struct ospf_interface *oi = rn->info;
7534
7535 if (!oi)
7536 continue;
7537
7538
7539 if (PRIORITY (oi) != OSPF_IF_PARAM (oi, priority))
7540 {
7541 PRIORITY (oi) = OSPF_IF_PARAM (oi, priority);
7542 OSPF_ISM_EVENT_SCHEDULE (oi, ISM_NeighborChange);
7543 }
7544 }
7545
7546 return CMD_SUCCESS;
7547 }
7548
7549 DEFUN (no_ip_ospf_priority,
7550 no_ip_ospf_priority_addr_cmd,
7551 "no ip ospf priority [(0-255) [A.B.C.D]]",
7552 NO_STR
7553 "IP Information\n"
7554 "OSPF interface commands\n"
7555 "Router priority\n"
7556 "Priority\n"
7557 "Address of interface")
7558 {
7559 int idx_ipv4 = 5;
7560 struct interface *ifp = vty->index;
7561 struct route_node *rn;
7562 struct in_addr addr;
7563 int ret;
7564 struct ospf_if_params *params;
7565
7566 ifp = vty->index;
7567 params = IF_DEF_PARAMS (ifp);
7568
7569 if (argc == 6)
7570 {
7571 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
7572 if (!ret)
7573 {
7574 vty_out (vty, "Please specify interface address by A.B.C.D%s",
7575 VTY_NEWLINE);
7576 return CMD_WARNING;
7577 }
7578
7579 params = ospf_lookup_if_params (ifp, addr);
7580 if (params == NULL)
7581 return CMD_SUCCESS;
7582 }
7583
7584 UNSET_IF_PARAM (params, priority);
7585 params->priority = OSPF_ROUTER_PRIORITY_DEFAULT;
7586
7587 if (params != IF_DEF_PARAMS (ifp))
7588 {
7589 ospf_free_if_params (ifp, addr);
7590 ospf_if_update_params (ifp, addr);
7591 }
7592
7593 for (rn = route_top (IF_OIFS (ifp)); rn; rn = route_next (rn))
7594 {
7595 struct ospf_interface *oi = rn->info;
7596
7597 if (!oi)
7598 continue;
7599
7600
7601 if (PRIORITY (oi) != OSPF_IF_PARAM (oi, priority))
7602 {
7603 PRIORITY (oi) = OSPF_IF_PARAM (oi, priority);
7604 OSPF_ISM_EVENT_SCHEDULE (oi, ISM_NeighborChange);
7605 }
7606 }
7607
7608 return CMD_SUCCESS;
7609 }
7610
7611
7612 DEFUN (ip_ospf_retransmit_interval,
7613 ip_ospf_retransmit_interval_addr_cmd,
7614 "ip ospf retransmit-interval (3-65535) [A.B.C.D]",
7615 "IP Information\n"
7616 "OSPF interface commands\n"
7617 "Time between retransmitting lost link state advertisements\n"
7618 "Seconds\n"
7619 "Address of interface")
7620 {
7621 int idx_number = 3;
7622 int idx_ipv4 = 4;
7623 struct interface *ifp = vty->index;
7624 u_int32_t seconds;
7625 struct in_addr addr;
7626 int ret;
7627 struct ospf_if_params *params;
7628
7629 params = IF_DEF_PARAMS (ifp);
7630 seconds = strtol (argv[idx_number]->arg, NULL, 10);
7631
7632 /* Retransmit Interval range is <3-65535>. */
7633 if (seconds < 3 || seconds > 65535)
7634 {
7635 vty_out (vty, "Retransmit Interval is invalid%s", VTY_NEWLINE);
7636 return CMD_WARNING;
7637 }
7638
7639
7640 if (argc == 5)
7641 {
7642 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
7643 if (!ret)
7644 {
7645 vty_out (vty, "Please specify interface address by A.B.C.D%s",
7646 VTY_NEWLINE);
7647 return CMD_WARNING;
7648 }
7649
7650 params = ospf_get_if_params (ifp, addr);
7651 ospf_if_update_params (ifp, addr);
7652 }
7653
7654 SET_IF_PARAM (params, retransmit_interval);
7655 params->retransmit_interval = seconds;
7656
7657 return CMD_SUCCESS;
7658 }
7659
7660 DEFUN_HIDDEN (ospf_retransmit_interval,
7661 ospf_retransmit_interval_cmd,
7662 "ospf retransmit-interval (3-65535)",
7663 "OSPF interface commands\n"
7664 "Time between retransmitting lost link state advertisements\n"
7665 "Seconds\n")
7666 {
7667 int idx_number = 2;
7668 struct interface *ifp = vty->index;
7669 u_int32_t seconds;
7670 struct ospf_if_params *params;
7671
7672 params = IF_DEF_PARAMS (ifp);
7673 seconds = strtol (argv[idx_number]->arg, NULL, 10);
7674
7675 /* Retransmit Interval range is <3-65535>. */
7676 if (seconds < 3 || seconds > 65535)
7677 {
7678 vty_out (vty, "Retransmit Interval is invalid%s", VTY_NEWLINE);
7679 return CMD_WARNING;
7680 }
7681
7682 SET_IF_PARAM (params, retransmit_interval);
7683 params->retransmit_interval = seconds;
7684
7685 return CMD_SUCCESS;
7686 }
7687
7688 DEFUN (no_ospf_retransmit_interval,
7689 no_ospf_retransmit_interval_cmd,
7690 "no ospf retransmit-interval",
7691 NO_STR
7692 "OSPF interface commands\n"
7693 "Time between retransmitting lost link state advertisements\n")
7694 {
7695 struct interface *ifp = vty->index;
7696 struct ospf_if_params *params;
7697
7698 ifp = vty->index;
7699 params = IF_DEF_PARAMS (ifp);
7700 UNSET_IF_PARAM (params, retransmit_interval);
7701 params->retransmit_interval = OSPF_RETRANSMIT_INTERVAL_DEFAULT;
7702
7703 return CMD_SUCCESS;
7704 }
7705
7706 DEFUN (no_ip_ospf_retransmit_interval,
7707 no_ip_ospf_retransmit_interval_addr_cmd,
7708 "no ip ospf retransmit-interval [<(3-65535) [A.B.C.D]|A.B.C.D>]",
7709 NO_STR
7710 "IP Information\n"
7711 "OSPF interface commands\n"
7712 "Time between retransmitting lost link state advertisements\n"
7713 "Address of interface")
7714 {
7715 struct interface *ifp = vty->index;
7716 struct in_addr addr;
7717 int ret;
7718 struct ospf_if_params *params;
7719 int addr_index;
7720
7721 ifp = vty->index;
7722 params = IF_DEF_PARAMS (ifp);
7723
7724 if (argc >= 5)
7725 {
7726 if (argc == 5)
7727 addr_index = 4;
7728 else
7729 addr_index = 5;
7730
7731 ret = inet_aton(argv[addr_index]->arg, &addr);
7732 if (!ret)
7733 {
7734 vty_out (vty, "Please specify interface address by A.B.C.D%s",
7735 VTY_NEWLINE);
7736 return CMD_WARNING;
7737 }
7738
7739 params = ospf_lookup_if_params (ifp, addr);
7740 if (params == NULL)
7741 return CMD_SUCCESS;
7742 }
7743
7744 UNSET_IF_PARAM (params, retransmit_interval);
7745 params->retransmit_interval = OSPF_RETRANSMIT_INTERVAL_DEFAULT;
7746
7747 if (params != IF_DEF_PARAMS (ifp))
7748 {
7749 ospf_free_if_params (ifp, addr);
7750 ospf_if_update_params (ifp, addr);
7751 }
7752
7753 return CMD_SUCCESS;
7754 }
7755
7756
7757 DEFUN (ip_ospf_transmit_delay,
7758 ip_ospf_transmit_delay_addr_cmd,
7759 "ip ospf transmit-delay (1-65535) [A.B.C.D]",
7760 "IP Information\n"
7761 "OSPF interface commands\n"
7762 "Link state transmit delay\n"
7763 "Seconds\n"
7764 "Address of interface")
7765 {
7766 int idx_number = 3;
7767 int idx_ipv4 = 4;
7768 struct interface *ifp = vty->index;
7769 u_int32_t seconds;
7770 struct in_addr addr;
7771 int ret;
7772 struct ospf_if_params *params;
7773
7774 params = IF_DEF_PARAMS (ifp);
7775 seconds = strtol (argv[idx_number]->arg, NULL, 10);
7776
7777 /* Transmit Delay range is <1-65535>. */
7778 if (seconds < 1 || seconds > 65535)
7779 {
7780 vty_out (vty, "Transmit Delay is invalid%s", VTY_NEWLINE);
7781 return CMD_WARNING;
7782 }
7783
7784 if (argc == 5)
7785 {
7786 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
7787 if (!ret)
7788 {
7789 vty_out (vty, "Please specify interface address by A.B.C.D%s",
7790 VTY_NEWLINE);
7791 return CMD_WARNING;
7792 }
7793
7794 params = ospf_get_if_params (ifp, addr);
7795 ospf_if_update_params (ifp, addr);
7796 }
7797
7798 SET_IF_PARAM (params, transmit_delay);
7799 params->transmit_delay = seconds;
7800
7801 return CMD_SUCCESS;
7802 }
7803
7804
7805 DEFUN_HIDDEN (ospf_transmit_delay,
7806 ospf_transmit_delay_cmd,
7807 "ospf transmit-delay (1-65535)",
7808 "OSPF interface commands\n"
7809 "Link state transmit delay\n"
7810 "Seconds\n")
7811 {
7812 int idx_number = 2;
7813 struct interface *ifp = vty->index;
7814 u_int32_t seconds;
7815 struct ospf_if_params *params;
7816
7817 params = IF_DEF_PARAMS (ifp);
7818 seconds = strtol (argv[idx_number]->arg, NULL, 10);
7819
7820 /* Transmit Delay range is <1-65535>. */
7821 if (seconds < 1 || seconds > 65535)
7822 {
7823 vty_out (vty, "Transmit Delay is invalid%s", VTY_NEWLINE);
7824 return CMD_WARNING;
7825 }
7826
7827 SET_IF_PARAM (params, transmit_delay);
7828 params->transmit_delay = seconds;
7829
7830 return CMD_SUCCESS;
7831 }
7832
7833 DEFUN (no_ip_ospf_transmit_delay,
7834 no_ip_ospf_transmit_delay_addr_cmd,
7835 "no ip ospf transmit-delay [<A.B.C.D|(1-65535) A.B.C.D>]",
7836 NO_STR
7837 "IP Information\n"
7838 "OSPF interface commands\n"
7839 "Link state transmit delay\n"
7840 "Address of interface")
7841 {
7842 struct interface *ifp = vty->index;
7843 struct in_addr addr;
7844 int ret;
7845 struct ospf_if_params *params;
7846 int addr_index;
7847
7848 ifp = vty->index;
7849 params = IF_DEF_PARAMS (ifp);
7850
7851 if (argc >= 5)
7852 {
7853 if (argc == 5)
7854 addr_index = 4;
7855 else
7856 addr_index = 5;
7857
7858 ret = inet_aton(argv[addr_index]->arg, &addr);
7859 if (!ret)
7860 {
7861 vty_out (vty, "Please specify interface address by A.B.C.D%s",
7862 VTY_NEWLINE);
7863 return CMD_WARNING;
7864 }
7865
7866 params = ospf_lookup_if_params (ifp, addr);
7867 if (params == NULL)
7868 return CMD_SUCCESS;
7869 }
7870
7871 UNSET_IF_PARAM (params, transmit_delay);
7872 params->transmit_delay = OSPF_TRANSMIT_DELAY_DEFAULT;
7873
7874 if (params != IF_DEF_PARAMS (ifp))
7875 {
7876 ospf_free_if_params (ifp, addr);
7877 ospf_if_update_params (ifp, addr);
7878 }
7879
7880 return CMD_SUCCESS;
7881 }
7882
7883
7884 DEFUN (no_ospf_transmit_delay,
7885 no_ospf_transmit_delay_cmd,
7886 "no ospf transmit-delay",
7887 NO_STR
7888 "OSPF interface commands\n"
7889 "Link state transmit delay\n")
7890 {
7891 struct interface *ifp = vty->index;
7892 struct ospf_if_params *params;
7893
7894 ifp = vty->index;
7895 params = IF_DEF_PARAMS (ifp);
7896
7897 UNSET_IF_PARAM (params, transmit_delay);
7898 params->transmit_delay = OSPF_TRANSMIT_DELAY_DEFAULT;
7899
7900 return CMD_SUCCESS;
7901 }
7902
7903 DEFUN (no_ip_ospf_transmit_delay_sec,
7904 no_ip_ospf_transmit_delay_sec_cmd,
7905 "no ip ospf transmit-delay (1-65535)",
7906 NO_STR
7907 "IP Information\n"
7908 "OSPF interface commands\n"
7909 "Link state transmit delay\n"
7910 "Seconds\n"
7911 "Address of interface")
7912 {
7913 struct interface *ifp = vty->index;
7914 struct ospf_if_params *params;
7915
7916 ifp = vty->index;
7917 params = IF_DEF_PARAMS (ifp);
7918
7919 UNSET_IF_PARAM (params, transmit_delay);
7920 params->transmit_delay = OSPF_TRANSMIT_DELAY_DEFAULT;
7921
7922 return CMD_SUCCESS;
7923 }
7924
7925 DEFUN (ip_ospf_area,
7926 ip_ospf_area_cmd,
7927 "ip ospf [(1-65535)] area <A.B.C.D|(0-4294967295)>",
7928 "IP Information\n"
7929 "OSPF interface commands\n"
7930 "Instance ID\n"
7931 "Enable OSPF on this interface\n"
7932 "OSPF area ID in IP address format\n"
7933 "OSPF area ID as a decimal value\n")
7934 {
7935 int idx_ipv4_number = 2;
7936 struct interface *ifp = vty->index;
7937 int format, ret;
7938 struct in_addr area_id;
7939 struct ospf *ospf;
7940 struct ospf_if_params *params;
7941 struct route_node *rn;
7942 u_short instance = 0;
7943
7944 if (argc == 5)
7945 VTY_GET_INTEGER ("Instance", instance, argv[idx_ipv4_number]->arg);
7946
7947 ospf = ospf_lookup_instance (instance);
7948 if (ospf == NULL)
7949 {
7950 params = IF_DEF_PARAMS (ifp);
7951 if (OSPF_IF_PARAM_CONFIGURED(params, if_area))
7952 {
7953 ospf_interface_unset (ifp);
7954 ospf = ospf_lookup();
7955 ospf->if_ospf_cli_count--;
7956 }
7957 return CMD_SUCCESS;
7958 }
7959
7960 ret = ospf_str2area_id (argv[instance ? 4 : 3]->arg, &area_id, &format);
7961 if (ret < 0)
7962 {
7963 vty_out (vty, "Please specify area by A.B.C.D|<0-4294967295>%s",
7964 VTY_NEWLINE);
7965 return CMD_WARNING;
7966 }
7967 if (memcmp (ifp->name, "VLINK", 5) == 0)
7968 {
7969 vty_out (vty, "Cannot enable OSPF on a virtual link.%s", VTY_NEWLINE);
7970 return CMD_WARNING;
7971 }
7972
7973 params = IF_DEF_PARAMS (ifp);
7974 if (OSPF_IF_PARAM_CONFIGURED(params, if_area))
7975 {
7976 vty_out (vty,
7977 "Must remove previous area config before changing ospf area %s",
7978 VTY_NEWLINE);
7979 return CMD_WARNING;
7980 }
7981
7982 for (rn = route_top (ospf->networks); rn; rn = route_next (rn))
7983 {
7984 if (rn->info != NULL)
7985 {
7986 vty_out (vty, "Please remove all network commands first.%s", VTY_NEWLINE);
7987 return CMD_WARNING;
7988 }
7989 }
7990
7991 /* enable ospf on this interface with area_id */
7992 ospf_interface_set (ifp, area_id);
7993 ospf->if_ospf_cli_count++;
7994
7995 return CMD_SUCCESS;
7996 }
7997
7998 DEFUN (no_ip_ospf_area,
7999 no_ip_ospf_area_cmd,
8000 "no ip ospf area [<A.B.C.D|(0-4294967295)>]",
8001 NO_STR
8002 "IP Information\n"
8003 "OSPF interface commands\n"
8004 "Disable OSPF on this interface\n"
8005 "OSPF area ID in IP address format\n"
8006 "OSPF area ID as a decimal value\n")
8007 {
8008 struct interface *ifp = vty->index;
8009 struct ospf *ospf;
8010 struct ospf_if_params *params;
8011 u_short instance = 0;
8012
8013 if ((ospf = ospf_lookup_instance (instance)) == NULL)
8014 return CMD_SUCCESS;
8015
8016 params = IF_DEF_PARAMS (ifp);
8017 if (!OSPF_IF_PARAM_CONFIGURED(params, if_area))
8018 {
8019 vty_out (vty, "Can't find specified inteface area configuration.%s", VTY_NEWLINE);
8020 return CMD_WARNING;
8021 }
8022
8023 ospf_interface_unset (ifp);
8024 ospf->if_ospf_cli_count--;
8025 return CMD_SUCCESS;
8026 }
8027
8028 DEFUN (no_ip_ospf_instance_area,
8029 no_ip_ospf_instance_area_cmd,
8030 "no ip ospf (1-65535) area [<A.B.C.D|(0-4294967295)>]",
8031 NO_STR
8032 "IP Information\n"
8033 "OSPF interface commands\n"
8034 "Instance ID\n"
8035 "Disable OSPF on this interface\n")
8036 {
8037 int idx_number = 3;
8038 struct interface *ifp = vty->index;
8039 struct ospf *ospf;
8040 struct ospf_if_params *params;
8041 u_short instance = 0;
8042
8043 VTY_GET_INTEGER ("Instance", instance, argv[idx_number]->arg);
8044
8045 if ((ospf = ospf_lookup_instance (instance)) == NULL)
8046 return CMD_SUCCESS;
8047
8048 params = IF_DEF_PARAMS (ifp);
8049 if (!OSPF_IF_PARAM_CONFIGURED(params, if_area))
8050 {
8051 vty_out (vty, "Can't find specified inteface area configuration.%s", VTY_NEWLINE);
8052 return CMD_WARNING;
8053 }
8054
8055 ospf_interface_unset (ifp);
8056 ospf->if_ospf_cli_count--;
8057 return CMD_SUCCESS;
8058 }
8059
8060 DEFUN (ospf_redistribute_source,
8061 ospf_redistribute_source_cmd,
8062 "redistribute <kernel|connected|static|rip|isis|bgp|pim|table> [<metric (0-16777214)|metric-type (1-2)|route-map WORD>]",
8063 REDIST_STR
8064 QUAGGA_REDIST_HELP_STR_OSPFD
8065 "Metric for redistributed routes\n"
8066 "OSPF default metric\n"
8067 "OSPF exterior metric type for redistributed routes\n"
8068 "Set OSPF External Type 1 metrics\n"
8069 "Set OSPF External Type 2 metrics\n"
8070 "Route map reference\n"
8071 "Pointer to route-map entries\n")
8072 {
8073 int idx_protocol = 1;
8074 int idx_redist_param = 2;
8075 struct ospf *ospf = vty->index;
8076 int source;
8077 int type = -1;
8078 int metric = -1;
8079 struct ospf_redist *red;
8080
8081 if (!ospf)
8082 return CMD_SUCCESS;
8083
8084 if (argc < 4)
8085 return CMD_WARNING; /* should not happen */
8086
8087 if (!ospf)
8088 return CMD_SUCCESS;
8089
8090 /* Get distribute source. */
8091 source = proto_redistnum(AFI_IP, argv[idx_protocol]->arg);
8092 if (source < 0 || source == ZEBRA_ROUTE_OSPF)
8093 return CMD_WARNING;
8094
8095 /* Get metric value. */
8096 if (strcmp (argv[idx_redist_param]->arg, "metric") == 0)
8097 if (!str2metric (argv[idx_redist_param+1]->arg, &metric))
8098 return CMD_WARNING;
8099
8100 /* Get metric type. */
8101 if (strcmp (argv[idx_redist_param]->arg, "metric-type") == 0)
8102 if (!str2metric_type (argv[idx_redist_param+1]->arg, &type))
8103 return CMD_WARNING;
8104
8105 red = ospf_redist_add(ospf, source, 0);
8106
8107 if (strcmp (argv[idx_redist_param]->arg, "route-map") == 0)
8108 ospf_routemap_set (red, argv[idx_redist_param+1]->arg);
8109 else
8110 ospf_routemap_unset (red);
8111
8112 return ospf_redistribute_set (ospf, source, 0, type, metric);
8113 }
8114
8115 DEFUN (no_ospf_redistribute_source,
8116 no_ospf_redistribute_source_cmd,
8117 "no redistribute <kernel|connected|static|rip|isis|bgp|pim|table> [<metric (0-16777214)|metric-type (1-2)|route-map WORD>]",
8118 NO_STR
8119 REDIST_STR
8120 QUAGGA_REDIST_HELP_STR_OSPFD
8121 "Metric for redistributed routes\n"
8122 "OSPF default metric\n"
8123 "OSPF exterior metric type for redistributed routes\n"
8124 "Set OSPF External Type 1 metrics\n"
8125 "Set OSPF External Type 2 metrics\n"
8126 "Route map reference\n"
8127 "Pointer to route-map entries\n")
8128 {
8129 int idx_protocol = 2;
8130 struct ospf *ospf = vty->index;
8131 int source;
8132 struct ospf_redist *red;
8133 if (!ospf)
8134 return CMD_SUCCESS;
8135
8136 source = proto_redistnum(AFI_IP, argv[idx_protocol]->arg);
8137 if (source < 0 || source == ZEBRA_ROUTE_OSPF)
8138 return CMD_WARNING;
8139
8140 red = ospf_redist_lookup(ospf, source, 0);
8141 if (!red)
8142 return CMD_SUCCESS;
8143
8144 ospf_routemap_unset (red);
8145 return ospf_redistribute_unset (ospf, source, 0);
8146 }
8147
8148 DEFUN (ospf_redistribute_instance_source,
8149 ospf_redistribute_instance_source_cmd,
8150 "redistribute <ospf|table> (1-65535) [<metric (0-16777214)|metric-type (1-2)|route-map WORD>]",
8151 REDIST_STR
8152 "Open Shortest Path First\n"
8153 "Non-main Kernel Routing Table\n"
8154 "Instance ID/Table ID\n"
8155 "Metric for redistributed routes\n"
8156 "OSPF default metric\n"
8157 "OSPF exterior metric type for redistributed routes\n"
8158 "Set OSPF External Type 1 metrics\n"
8159 "Set OSPF External Type 2 metrics\n"
8160 "Route map reference\n"
8161 "Pointer to route-map entries\n")
8162 {
8163 int idx_ospf_table = 1;
8164 int idx_number = 2;
8165 int idx_redist_param = 3;
8166 struct ospf *ospf = vty->index;
8167 int source;
8168 int type = -1;
8169 int metric = -1;
8170 u_short instance;
8171 struct ospf_redist *red;
8172
8173 if (!ospf)
8174 return CMD_SUCCESS;
8175
8176 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
8177 source = ZEBRA_ROUTE_OSPF;
8178 else
8179 source = ZEBRA_ROUTE_TABLE;
8180
8181 VTY_GET_INTEGER ("Instance ID", instance, argv[idx_number]->arg);
8182
8183 if (!ospf)
8184 return CMD_SUCCESS;
8185
8186 if ((source == ZEBRA_ROUTE_OSPF) && !ospf->instance)
8187 {
8188 vty_out (vty, "Instance redistribution in non-instanced OSPF not allowed%s",
8189 VTY_NEWLINE);
8190 return CMD_WARNING;
8191 }
8192
8193 if ((source == ZEBRA_ROUTE_OSPF) && (ospf->instance == instance))
8194 {
8195 vty_out (vty, "Same instance OSPF redistribution not allowed%s",
8196 VTY_NEWLINE);
8197 return CMD_WARNING;
8198 }
8199
8200 /* Get metric value. */
8201 if (strcmp (argv[idx_redist_param]->arg, "metric") == 0)
8202 if (!str2metric (argv[idx_redist_param+1]->arg, &metric))
8203 return CMD_WARNING;
8204
8205 /* Get metric type. */
8206 if (strcmp (argv[idx_redist_param]->arg, "metric-type") == 0)
8207 if (!str2metric_type (argv[idx_redist_param+1]->arg, &type))
8208 return CMD_WARNING;
8209
8210 red = ospf_redist_add(ospf, source, instance);
8211
8212 if (strcmp (argv[idx_redist_param]->arg, "route-map") == 0)
8213 ospf_routemap_set (red, argv[idx_redist_param+1]->arg);
8214 else
8215 ospf_routemap_unset (red);
8216
8217 return ospf_redistribute_set (ospf, source, instance, type, metric);
8218 }
8219
8220 DEFUN (no_ospf_redistribute_instance_source,
8221 no_ospf_redistribute_instance_source_cmd,
8222 "no redistribute <ospf|table> (1-65535) [<metric (0-16777214)|metric-type (1-2)|route-map WORD>]",
8223 NO_STR
8224 REDIST_STR
8225 "Open Shortest Path First\n"
8226 "Non-main Kernel Routing Table\n"
8227 "Instance ID/Table Id\n"
8228 "Metric for redistributed routes\n"
8229 "OSPF default metric\n"
8230 "OSPF exterior metric type for redistributed routes\n"
8231 "Set OSPF External Type 1 metrics\n"
8232 "Set OSPF External Type 2 metrics\n"
8233 "Route map reference\n"
8234 "Pointer to route-map entries\n")
8235 {
8236 int idx_ospf_table = 2;
8237 int idx_number = 3;
8238 struct ospf *ospf = vty->index;
8239 u_int instance;
8240 struct ospf_redist *red;
8241 int source;
8242
8243 if (!ospf)
8244 return CMD_SUCCESS;
8245
8246 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
8247 source = ZEBRA_ROUTE_OSPF;
8248 else
8249 source = ZEBRA_ROUTE_TABLE;
8250
8251 VTY_GET_INTEGER ("Instance ID", instance, argv[idx_number]->arg);
8252
8253 if ((source == ZEBRA_ROUTE_OSPF) && !ospf->instance)
8254 {
8255 vty_out (vty, "Instance redistribution in non-instanced OSPF not allowed%s",
8256 VTY_NEWLINE);
8257 return CMD_WARNING;
8258 }
8259
8260 if ((source == ZEBRA_ROUTE_OSPF) && (ospf->instance == instance))
8261 {
8262 vty_out (vty, "Same instance OSPF redistribution not allowed%s",
8263 VTY_NEWLINE);
8264 return CMD_WARNING;
8265 }
8266
8267 red = ospf_redist_lookup(ospf, source, instance);
8268 if (!red)
8269 return CMD_SUCCESS;
8270
8271 ospf_routemap_unset (red);
8272 return ospf_redistribute_unset (ospf, source, instance);
8273 }
8274
8275 DEFUN (ospf_distribute_list_out,
8276 ospf_distribute_list_out_cmd,
8277 "distribute-list WORD out <kernel|connected|static|rip|isis|bgp|pim|table>",
8278 "Filter networks in routing updates\n"
8279 "Access-list name\n"
8280 OUT_STR
8281 QUAGGA_REDIST_HELP_STR_OSPFD)
8282 {
8283 int idx_word = 1;
8284 struct ospf *ospf = vty->index;
8285 int source;
8286
8287 if (!ospf)
8288 return CMD_SUCCESS;
8289
8290 /* Get distribute source. */
8291 source = proto_redistnum(AFI_IP, argv[4]->arg);
8292 if (source < 0 || source == ZEBRA_ROUTE_OSPF)
8293 return CMD_WARNING;
8294
8295 return ospf_distribute_list_out_set (ospf, source, argv[idx_word]->arg);
8296 }
8297
8298 DEFUN (no_ospf_distribute_list_out,
8299 no_ospf_distribute_list_out_cmd,
8300 "no distribute-list WORD out <kernel|connected|static|rip|isis|bgp|pim|table>",
8301 NO_STR
8302 "Filter networks in routing updates\n"
8303 "Access-list name\n"
8304 OUT_STR
8305 QUAGGA_REDIST_HELP_STR_OSPFD)
8306 {
8307 int idx_word = 2;
8308 struct ospf *ospf = vty->index;
8309 int source;
8310
8311 if (!ospf)
8312 return CMD_SUCCESS;
8313
8314 source = proto_redistnum(AFI_IP, argv[5]->arg);
8315 if (source < 0 || source == ZEBRA_ROUTE_OSPF)
8316 return CMD_WARNING;
8317
8318 return ospf_distribute_list_out_unset (ospf, source, argv[idx_word]->arg);
8319 }
8320
8321 /* Default information originate. */
8322 DEFUN (ospf_default_information_originate,
8323 ospf_default_information_originate_cmd,
8324 "default-information originate [<always|metric (0-16777214)|metric-type (1-2)|route-map WORD>]",
8325 "Control distribution of default information\n"
8326 "Distribute a default route\n"
8327 "Always advertise default route\n"
8328 "OSPF default metric\n"
8329 "OSPF metric\n"
8330 "OSPF metric type for default routes\n"
8331 "Set OSPF External Type 1 metrics\n"
8332 "Set OSPF External Type 2 metrics\n"
8333 "Route map reference\n"
8334 "Pointer to route-map entries\n")
8335 {
8336 int idx_redist_param = 2;
8337 struct ospf *ospf = vty->index;
8338 int default_originate = DEFAULT_ORIGINATE_ZEBRA;
8339 int type = -1;
8340 int metric = -1;
8341 struct ospf_redist *red;
8342
8343 if (!ospf)
8344 return CMD_SUCCESS;
8345
8346 if (argc < 4)
8347 return CMD_WARNING; /* this should not happen */
8348
8349 /* Check whether "always" was specified */
8350 if (argv[idx_redist_param]->arg != NULL)
8351 default_originate = DEFAULT_ORIGINATE_ALWAYS;
8352
8353 red = ospf_redist_add(ospf, DEFAULT_ROUTE, 0);
8354
8355 /* Get metric value. */
8356 if (strcmp (argv[idx_redist_param]->arg, "metric") == 0)
8357 if (!str2metric (argv[idx_redist_param+1]->arg, &metric))
8358 return CMD_WARNING;
8359
8360 /* Get metric type. */
8361 if (strcmp (argv[idx_redist_param]->arg, "metric-type") == 0)
8362 if (!str2metric_type (argv[idx_redist_param+1]->arg, &type))
8363 return CMD_WARNING;
8364
8365 if (strcmp (argv[idx_redist_param]->arg, "route-map") == 0)
8366 ospf_routemap_set (red, argv[idx_redist_param+1]->arg);
8367 else
8368 ospf_routemap_unset (red);
8369
8370 return ospf_redistribute_default_set (ospf, default_originate,
8371 type, metric);
8372 }
8373
8374 DEFUN (no_ospf_default_information_originate,
8375 no_ospf_default_information_originate_cmd,
8376 "no default-information originate [<always|metric (0-16777214)|metric-type (1-2)|route-map WORD>]",
8377 NO_STR
8378 "Control distribution of default information\n"
8379 "Distribute a default route\n"
8380 "Always advertise default route\n"
8381 "OSPF default metric\n"
8382 "OSPF metric\n"
8383 "OSPF metric type for default routes\n"
8384 "Set OSPF External Type 1 metrics\n"
8385 "Set OSPF External Type 2 metrics\n"
8386 "Route map reference\n"
8387 "Pointer to route-map entries\n")
8388 {
8389 struct ospf *ospf = vty->index;
8390 struct prefix_ipv4 p;
8391 struct ospf_external *ext;
8392 struct ospf_redist *red;
8393
8394 if (!ospf)
8395 return CMD_SUCCESS;
8396
8397 p.family = AF_INET;
8398 p.prefix.s_addr = 0;
8399 p.prefixlen = 0;
8400
8401 ospf_external_lsa_flush (ospf, DEFAULT_ROUTE, &p, 0);
8402
8403 if ((ext = ospf_external_lookup(DEFAULT_ROUTE, 0)) &&
8404 EXTERNAL_INFO (ext)) {
8405 ospf_external_info_delete (DEFAULT_ROUTE, 0, p);
8406 ospf_external_del (DEFAULT_ROUTE, 0);
8407 }
8408
8409 red = ospf_redist_lookup(ospf, DEFAULT_ROUTE, 0);
8410 if (!red)
8411 return CMD_SUCCESS;
8412
8413 ospf_routemap_unset (red);
8414 return ospf_redistribute_default_unset (ospf);
8415 }
8416
8417 DEFUN (ospf_default_metric,
8418 ospf_default_metric_cmd,
8419 "default-metric (0-16777214)",
8420 "Set metric of redistributed routes\n"
8421 "Default metric\n")
8422 {
8423 int idx_number = 1;
8424 struct ospf *ospf = vty->index;
8425 int metric = -1;
8426
8427 if (!ospf)
8428 return CMD_SUCCESS;
8429
8430 if (!str2metric (argv[idx_number]->arg, &metric))
8431 return CMD_WARNING;
8432
8433 ospf->default_metric = metric;
8434
8435 return CMD_SUCCESS;
8436 }
8437
8438 DEFUN (no_ospf_default_metric,
8439 no_ospf_default_metric_cmd,
8440 "no default-metric [(0-16777214)]",
8441 NO_STR
8442 "Set metric of redistributed routes\n"
8443 "Default metric\n")
8444 {
8445 struct ospf *ospf = vty->index;
8446
8447 if (!ospf)
8448 return CMD_SUCCESS;
8449
8450 ospf->default_metric = -1;
8451
8452 return CMD_SUCCESS;
8453 }
8454
8455
8456 DEFUN (ospf_distance,
8457 ospf_distance_cmd,
8458 "distance (1-255)",
8459 "Define an administrative distance\n"
8460 "OSPF Administrative distance\n")
8461 {
8462 int idx_number = 1;
8463 struct ospf *ospf = vty->index;
8464
8465 if (!ospf)
8466 return CMD_SUCCESS;
8467
8468 ospf->distance_all = atoi (argv[idx_number]->arg);
8469
8470 return CMD_SUCCESS;
8471 }
8472
8473 DEFUN (no_ospf_distance,
8474 no_ospf_distance_cmd,
8475 "no distance (1-255)",
8476 NO_STR
8477 "Define an administrative distance\n"
8478 "OSPF Administrative distance\n")
8479 {
8480 struct ospf *ospf = vty->index;
8481
8482 if (!ospf)
8483 return CMD_SUCCESS;
8484
8485 ospf->distance_all = 0;
8486
8487 return CMD_SUCCESS;
8488 }
8489
8490 DEFUN (no_ospf_distance_ospf,
8491 no_ospf_distance_ospf_cmd,
8492 "no distance ospf [<intra-area (1-255)|inter-area (1-255)|external (1-255)>]",
8493 NO_STR
8494 "Define an administrative distance\n"
8495 "OSPF Administrative distance\n"
8496 "Intra-area routes\n"
8497 "Distance for intra-area routes\n"
8498 "Inter-area routes\n"
8499 "Distance for inter-area routes\n"
8500 "External routes\n"
8501 "Distance for external routes\n")
8502 {
8503 int idx_area_distance = 3;
8504 struct ospf *ospf = vty->index;
8505
8506 if (!ospf)
8507 return CMD_SUCCESS;
8508
8509 if (argc < 3)
8510 return CMD_WARNING;
8511
8512 if (!ospf)
8513 return CMD_SUCCESS;
8514
8515 if (argv[idx_area_distance]->arg != NULL)
8516 ospf->distance_intra = 0;
8517
8518 if (argv[1] != NULL)
8519 ospf->distance_inter = 0;
8520
8521 if (argv[2] != NULL)
8522 ospf->distance_external = 0;
8523
8524 if (argv[idx_area_distance]->arg || argv[1] || argv[2])
8525 return CMD_SUCCESS;
8526
8527 /* If no arguments are given, clear all distance information */
8528 ospf->distance_intra = 0;
8529 ospf->distance_inter = 0;
8530 ospf->distance_external = 0;
8531
8532 return CMD_SUCCESS;
8533 }
8534
8535 DEFUN (ospf_distance_ospf,
8536 ospf_distance_ospf_cmd,
8537 "distance ospf [<intra-area (1-255)|inter-area (1-255)|external (1-255)>]",
8538 "Define an administrative distance\n"
8539 "OSPF Administrative distance\n"
8540 "Intra-area routes\n"
8541 "Distance for intra-area routes\n"
8542 "Inter-area routes\n"
8543 "Distance for inter-area routes\n"
8544 "External routes\n"
8545 "Distance for external routes\n")
8546 {
8547 int idx_area_distance = 2;
8548 struct ospf *ospf = vty->index;
8549
8550 if (!ospf)
8551 return CMD_SUCCESS;
8552
8553 if (argc < 3) /* should not happen */
8554 return CMD_WARNING;
8555
8556 if (!argv[idx_area_distance]->arg && !argv[1] && !argv[2])
8557 {
8558 vty_out(vty, "%% Command incomplete. (Arguments required)%s",
8559 VTY_NEWLINE);
8560 return CMD_WARNING;
8561 }
8562
8563 if (strcmp (argv[idx_area_distance]->text, "intra") == 0)
8564 ospf->distance_intra = atoi(argv[idx_area_distance+1]->arg);
8565
8566 if (strcmp (argv[idx_area_distance]->text, "inter") == 0)
8567 ospf->distance_inter = atoi(argv[idx_area_distance+1]->arg);
8568
8569 if (strcmp (argv[idx_area_distance]->text, "external") == 0)
8570 ospf->distance_external = atoi(argv[idx_area_distance+1]->arg);
8571
8572 return CMD_SUCCESS;
8573 }
8574
8575 DEFUN (ospf_distance_source,
8576 ospf_distance_source_cmd,
8577 "distance (1-255) A.B.C.D/M",
8578 "Administrative distance\n"
8579 "Distance value\n"
8580 "IP source prefix\n")
8581 {
8582 int idx_number = 1;
8583 int idx_ipv4_prefixlen = 2;
8584 struct ospf *ospf = vty->index;
8585
8586 if (!ospf)
8587 return CMD_SUCCESS;
8588
8589 ospf_distance_set (vty, ospf, argv[idx_number]->arg, argv[idx_ipv4_prefixlen]->arg, NULL);
8590
8591 return CMD_SUCCESS;
8592 }
8593
8594 DEFUN (no_ospf_distance_source,
8595 no_ospf_distance_source_cmd,
8596 "no distance (1-255) A.B.C.D/M",
8597 NO_STR
8598 "Administrative distance\n"
8599 "Distance value\n"
8600 "IP source prefix\n")
8601 {
8602 int idx_number = 2;
8603 int idx_ipv4_prefixlen = 3;
8604 struct ospf *ospf = vty->index;
8605
8606 if (!ospf)
8607 return CMD_SUCCESS;
8608
8609 ospf_distance_unset (vty, ospf, argv[idx_number]->arg, argv[idx_ipv4_prefixlen]->arg, NULL);
8610
8611 return CMD_SUCCESS;
8612 }
8613
8614 DEFUN (ospf_distance_source_access_list,
8615 ospf_distance_source_access_list_cmd,
8616 "distance (1-255) A.B.C.D/M WORD",
8617 "Administrative distance\n"
8618 "Distance value\n"
8619 "IP source prefix\n"
8620 "Access list name\n")
8621 {
8622 int idx_number = 1;
8623 int idx_ipv4_prefixlen = 2;
8624 int idx_word = 3;
8625 struct ospf *ospf = vty->index;
8626
8627 if (!ospf)
8628 return CMD_SUCCESS;
8629
8630 ospf_distance_set (vty, ospf, argv[idx_number]->arg, argv[idx_ipv4_prefixlen]->arg, argv[idx_word]->arg);
8631
8632 return CMD_SUCCESS;
8633 }
8634
8635 DEFUN (no_ospf_distance_source_access_list,
8636 no_ospf_distance_source_access_list_cmd,
8637 "no distance (1-255) A.B.C.D/M WORD",
8638 NO_STR
8639 "Administrative distance\n"
8640 "Distance value\n"
8641 "IP source prefix\n"
8642 "Access list name\n")
8643 {
8644 int idx_number = 2;
8645 int idx_ipv4_prefixlen = 3;
8646 int idx_word = 4;
8647 struct ospf *ospf = vty->index;
8648
8649 if (!ospf)
8650 return CMD_SUCCESS;
8651
8652 ospf_distance_unset (vty, ospf, argv[idx_number]->arg, argv[idx_ipv4_prefixlen]->arg, argv[idx_word]->arg);
8653
8654 return CMD_SUCCESS;
8655 }
8656
8657 DEFUN (ip_ospf_mtu_ignore,
8658 ip_ospf_mtu_ignore_addr_cmd,
8659 "ip ospf mtu-ignore [A.B.C.D]",
8660 "IP Information\n"
8661 "OSPF interface commands\n"
8662 "Disable mtu mismatch detection\n"
8663 "Address of interface")
8664 {
8665 int idx_ipv4 = 3;
8666 struct interface *ifp = vty->index;
8667 struct in_addr addr;
8668 int ret;
8669
8670 struct ospf_if_params *params;
8671 params = IF_DEF_PARAMS (ifp);
8672
8673 if (argc == 4)
8674 {
8675 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
8676 if (!ret)
8677 {
8678 vty_out (vty, "Please specify interface address by A.B.C.D%s",
8679 VTY_NEWLINE);
8680 return CMD_WARNING;
8681 }
8682 params = ospf_get_if_params (ifp, addr);
8683 ospf_if_update_params (ifp, addr);
8684 }
8685 params->mtu_ignore = 1;
8686 if (params->mtu_ignore != OSPF_MTU_IGNORE_DEFAULT)
8687 SET_IF_PARAM (params, mtu_ignore);
8688 else
8689 {
8690 UNSET_IF_PARAM (params, mtu_ignore);
8691 if (params != IF_DEF_PARAMS (ifp))
8692 {
8693 ospf_free_if_params (ifp, addr);
8694 ospf_if_update_params (ifp, addr);
8695 }
8696 }
8697 return CMD_SUCCESS;
8698 }
8699
8700 DEFUN (no_ip_ospf_mtu_ignore,
8701 no_ip_ospf_mtu_ignore_addr_cmd,
8702 "no ip ospf mtu-ignore [A.B.C.D]",
8703 "IP Information\n"
8704 "OSPF interface commands\n"
8705 "Disable mtu mismatch detection\n"
8706 "Address of interface")
8707 {
8708 int idx_ipv4 = 4;
8709 struct interface *ifp = vty->index;
8710 struct in_addr addr;
8711 int ret;
8712
8713 struct ospf_if_params *params;
8714 params = IF_DEF_PARAMS (ifp);
8715
8716 if (argc == 5)
8717 {
8718 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
8719 if (!ret)
8720 {
8721 vty_out (vty, "Please specify interface address by A.B.C.D%s",
8722 VTY_NEWLINE);
8723 return CMD_WARNING;
8724 }
8725 params = ospf_get_if_params (ifp, addr);
8726 ospf_if_update_params (ifp, addr);
8727 }
8728 params->mtu_ignore = 0;
8729 if (params->mtu_ignore != OSPF_MTU_IGNORE_DEFAULT)
8730 SET_IF_PARAM (params, mtu_ignore);
8731 else
8732 {
8733 UNSET_IF_PARAM (params, mtu_ignore);
8734 if (params != IF_DEF_PARAMS (ifp))
8735 {
8736 ospf_free_if_params (ifp, addr);
8737 ospf_if_update_params (ifp, addr);
8738 }
8739 }
8740 return CMD_SUCCESS;
8741 }
8742
8743
8744 DEFUN (ospf_max_metric_router_lsa_admin,
8745 ospf_max_metric_router_lsa_admin_cmd,
8746 "max-metric router-lsa administrative",
8747 "OSPF maximum / infinite-distance metric\n"
8748 "Advertise own Router-LSA with infinite distance (stub router)\n"
8749 "Administratively applied, for an indefinite period\n")
8750 {
8751 struct listnode *ln;
8752 struct ospf_area *area;
8753 struct ospf *ospf = vty->index;
8754
8755 if (!ospf)
8756 return CMD_SUCCESS;
8757
8758 for (ALL_LIST_ELEMENTS_RO (ospf->areas, ln, area))
8759 {
8760 SET_FLAG (area->stub_router_state, OSPF_AREA_ADMIN_STUB_ROUTED);
8761
8762 if (!CHECK_FLAG (area->stub_router_state, OSPF_AREA_IS_STUB_ROUTED))
8763 ospf_router_lsa_update_area (area);
8764 }
8765
8766 /* Allows for areas configured later to get the property */
8767 ospf->stub_router_admin_set = OSPF_STUB_ROUTER_ADMINISTRATIVE_SET;
8768
8769 return CMD_SUCCESS;
8770 }
8771
8772 DEFUN (no_ospf_max_metric_router_lsa_admin,
8773 no_ospf_max_metric_router_lsa_admin_cmd,
8774 "no max-metric router-lsa administrative",
8775 NO_STR
8776 "OSPF maximum / infinite-distance metric\n"
8777 "Advertise own Router-LSA with infinite distance (stub router)\n"
8778 "Administratively applied, for an indefinite period\n")
8779 {
8780 struct listnode *ln;
8781 struct ospf_area *area;
8782 struct ospf *ospf = vty->index;
8783
8784 if (!ospf)
8785 return CMD_SUCCESS;
8786
8787 for (ALL_LIST_ELEMENTS_RO (ospf->areas, ln, area))
8788 {
8789 UNSET_FLAG (area->stub_router_state, OSPF_AREA_ADMIN_STUB_ROUTED);
8790
8791 /* Don't trample on the start-up stub timer */
8792 if (CHECK_FLAG (area->stub_router_state, OSPF_AREA_IS_STUB_ROUTED)
8793 && !area->t_stub_router)
8794 {
8795 UNSET_FLAG (area->stub_router_state, OSPF_AREA_IS_STUB_ROUTED);
8796 ospf_router_lsa_update_area (area);
8797 }
8798 }
8799 ospf->stub_router_admin_set = OSPF_STUB_ROUTER_ADMINISTRATIVE_UNSET;
8800 return CMD_SUCCESS;
8801 }
8802
8803 DEFUN (ospf_max_metric_router_lsa_startup,
8804 ospf_max_metric_router_lsa_startup_cmd,
8805 "max-metric router-lsa on-startup (5-86400)",
8806 "OSPF maximum / infinite-distance metric\n"
8807 "Advertise own Router-LSA with infinite distance (stub router)\n"
8808 "Automatically advertise stub Router-LSA on startup of OSPF\n"
8809 "Time (seconds) to advertise self as stub-router\n")
8810 {
8811 int idx_number = 3;
8812 unsigned int seconds;
8813 struct ospf *ospf = vty->index;
8814
8815 if (!ospf)
8816 return CMD_SUCCESS;
8817
8818 if (argc != 1)
8819 {
8820 vty_out (vty, "%% Must supply stub-router period");
8821 return CMD_WARNING;
8822 }
8823
8824 VTY_GET_INTEGER ("stub-router startup period", seconds, argv[idx_number]->arg);
8825
8826 ospf->stub_router_startup_time = seconds;
8827
8828 return CMD_SUCCESS;
8829 }
8830
8831 DEFUN (no_ospf_max_metric_router_lsa_startup,
8832 no_ospf_max_metric_router_lsa_startup_cmd,
8833 "no max-metric router-lsa on-startup [(5-86400)]",
8834 NO_STR
8835 "OSPF maximum / infinite-distance metric\n"
8836 "Advertise own Router-LSA with infinite distance (stub router)\n"
8837 "Automatically advertise stub Router-LSA on startup of OSPF\n"
8838 "Time (seconds) to advertise self as stub-router\n")
8839 {
8840 struct listnode *ln;
8841 struct ospf_area *area;
8842 struct ospf *ospf = vty->index;
8843
8844 if (!ospf)
8845 return CMD_SUCCESS;
8846
8847 ospf->stub_router_startup_time = OSPF_STUB_ROUTER_UNCONFIGURED;
8848
8849 for (ALL_LIST_ELEMENTS_RO (ospf->areas, ln, area))
8850 {
8851 SET_FLAG (area->stub_router_state, OSPF_AREA_WAS_START_STUB_ROUTED);
8852 OSPF_TIMER_OFF (area->t_stub_router);
8853
8854 /* Don't trample on admin stub routed */
8855 if (!CHECK_FLAG (area->stub_router_state, OSPF_AREA_ADMIN_STUB_ROUTED))
8856 {
8857 UNSET_FLAG (area->stub_router_state, OSPF_AREA_IS_STUB_ROUTED);
8858 ospf_router_lsa_update_area (area);
8859 }
8860 }
8861 return CMD_SUCCESS;
8862 }
8863
8864
8865 DEFUN (ospf_max_metric_router_lsa_shutdown,
8866 ospf_max_metric_router_lsa_shutdown_cmd,
8867 "max-metric router-lsa on-shutdown (5-100)",
8868 "OSPF maximum / infinite-distance metric\n"
8869 "Advertise own Router-LSA with infinite distance (stub router)\n"
8870 "Advertise stub-router prior to full shutdown of OSPF\n"
8871 "Time (seconds) to wait till full shutdown\n")
8872 {
8873 int idx_number = 3;
8874 unsigned int seconds;
8875 struct ospf *ospf = vty->index;
8876
8877 if (!ospf)
8878 return CMD_SUCCESS;
8879
8880 if (argc != 1)
8881 {
8882 vty_out (vty, "%% Must supply stub-router shutdown period");
8883 return CMD_WARNING;
8884 }
8885
8886 VTY_GET_INTEGER ("stub-router shutdown wait period", seconds, argv[idx_number]->arg);
8887
8888 ospf->stub_router_shutdown_time = seconds;
8889
8890 return CMD_SUCCESS;
8891 }
8892
8893 DEFUN (no_ospf_max_metric_router_lsa_shutdown,
8894 no_ospf_max_metric_router_lsa_shutdown_cmd,
8895 "no max-metric router-lsa on-shutdown [(5-100)]",
8896 NO_STR
8897 "OSPF maximum / infinite-distance metric\n"
8898 "Advertise own Router-LSA with infinite distance (stub router)\n"
8899 "Advertise stub-router prior to full shutdown of OSPF\n"
8900 "Time (seconds) to wait till full shutdown\n")
8901 {
8902 struct ospf *ospf = vty->index;
8903
8904 if (!ospf)
8905 return CMD_SUCCESS;
8906
8907 ospf->stub_router_shutdown_time = OSPF_STUB_ROUTER_UNCONFIGURED;
8908
8909 return CMD_SUCCESS;
8910 }
8911
8912 static void
8913 config_write_stub_router (struct vty *vty, struct ospf *ospf)
8914 {
8915 struct listnode *ln;
8916 struct ospf_area *area;
8917
8918 if (ospf->stub_router_startup_time != OSPF_STUB_ROUTER_UNCONFIGURED)
8919 vty_out (vty, " max-metric router-lsa on-startup %u%s",
8920 ospf->stub_router_startup_time, VTY_NEWLINE);
8921 if (ospf->stub_router_shutdown_time != OSPF_STUB_ROUTER_UNCONFIGURED)
8922 vty_out (vty, " max-metric router-lsa on-shutdown %u%s",
8923 ospf->stub_router_shutdown_time, VTY_NEWLINE);
8924 for (ALL_LIST_ELEMENTS_RO (ospf->areas, ln, area))
8925 {
8926 if (CHECK_FLAG (area->stub_router_state, OSPF_AREA_ADMIN_STUB_ROUTED))
8927 {
8928 vty_out (vty, " max-metric router-lsa administrative%s",
8929 VTY_NEWLINE);
8930 break;
8931 }
8932 }
8933 return;
8934 }
8935
8936 static void
8937 show_ip_ospf_route_network (struct vty *vty, struct route_table *rt)
8938 {
8939 struct route_node *rn;
8940 struct ospf_route *or;
8941 struct listnode *pnode, *pnnode;
8942 struct ospf_path *path;
8943
8944 vty_out (vty, "============ OSPF network routing table ============%s",
8945 VTY_NEWLINE);
8946
8947 for (rn = route_top (rt); rn; rn = route_next (rn))
8948 if ((or = rn->info) != NULL)
8949 {
8950 char buf1[19];
8951 snprintf (buf1, 19, "%s/%d",
8952 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen);
8953
8954 switch (or->path_type)
8955 {
8956 case OSPF_PATH_INTER_AREA:
8957 if (or->type == OSPF_DESTINATION_NETWORK)
8958 vty_out (vty, "N IA %-18s [%d] area: %s%s", buf1, or->cost,
8959 inet_ntoa (or->u.std.area_id), VTY_NEWLINE);
8960 else if (or->type == OSPF_DESTINATION_DISCARD)
8961 vty_out (vty, "D IA %-18s Discard entry%s", buf1, VTY_NEWLINE);
8962 break;
8963 case OSPF_PATH_INTRA_AREA:
8964 vty_out (vty, "N %-18s [%d] area: %s%s", buf1, or->cost,
8965 inet_ntoa (or->u.std.area_id), VTY_NEWLINE);
8966 break;
8967 default:
8968 break;
8969 }
8970
8971 if (or->type == OSPF_DESTINATION_NETWORK)
8972 for (ALL_LIST_ELEMENTS (or->paths, pnode, pnnode, path))
8973 {
8974 if (if_lookup_by_index(path->ifindex))
8975 {
8976 if (path->nexthop.s_addr == 0)
8977 vty_out (vty, "%24s directly attached to %s%s",
8978 "", ifindex2ifname (path->ifindex), VTY_NEWLINE);
8979 else
8980 vty_out (vty, "%24s via %s, %s%s", "",
8981 inet_ntoa (path->nexthop),
8982 ifindex2ifname (path->ifindex), VTY_NEWLINE);
8983 }
8984 }
8985 }
8986 vty_out (vty, "%s", VTY_NEWLINE);
8987 }
8988
8989 static void
8990 show_ip_ospf_route_router (struct vty *vty, struct route_table *rtrs)
8991 {
8992 struct route_node *rn;
8993 struct ospf_route *or;
8994 struct listnode *pnode;
8995 struct listnode *node;
8996 struct ospf_path *path;
8997
8998 vty_out (vty, "============ OSPF router routing table =============%s",
8999 VTY_NEWLINE);
9000 for (rn = route_top (rtrs); rn; rn = route_next (rn))
9001 if (rn->info)
9002 {
9003 int flag = 0;
9004
9005 vty_out (vty, "R %-15s ", inet_ntoa (rn->p.u.prefix4));
9006
9007 for (ALL_LIST_ELEMENTS_RO ((struct list *)rn->info, node, or))
9008 {
9009 if (flag++)
9010 vty_out (vty, "%24s", "");
9011
9012 /* Show path. */
9013 vty_out (vty, "%s [%d] area: %s",
9014 (or->path_type == OSPF_PATH_INTER_AREA ? "IA" : " "),
9015 or->cost, inet_ntoa (or->u.std.area_id));
9016 /* Show flags. */
9017 vty_out (vty, "%s%s%s",
9018 (or->u.std.flags & ROUTER_LSA_BORDER ? ", ABR" : ""),
9019 (or->u.std.flags & ROUTER_LSA_EXTERNAL ? ", ASBR" : ""),
9020 VTY_NEWLINE);
9021
9022 for (ALL_LIST_ELEMENTS_RO (or->paths, pnode, path))
9023 {
9024 if (if_lookup_by_index(path->ifindex))
9025 {
9026 if (path->nexthop.s_addr == 0)
9027 vty_out (vty, "%24s directly attached to %s%s",
9028 "", ifindex2ifname (path->ifindex),
9029 VTY_NEWLINE);
9030 else
9031 vty_out (vty, "%24s via %s, %s%s", "",
9032 inet_ntoa (path->nexthop),
9033 ifindex2ifname (path->ifindex),
9034 VTY_NEWLINE);
9035 }
9036 }
9037 }
9038 }
9039 vty_out (vty, "%s", VTY_NEWLINE);
9040 }
9041
9042 static void
9043 show_ip_ospf_route_external (struct vty *vty, struct route_table *rt)
9044 {
9045 struct route_node *rn;
9046 struct ospf_route *er;
9047 struct listnode *pnode, *pnnode;
9048 struct ospf_path *path;
9049
9050 vty_out (vty, "============ OSPF external routing table ===========%s",
9051 VTY_NEWLINE);
9052 for (rn = route_top (rt); rn; rn = route_next (rn))
9053 if ((er = rn->info) != NULL)
9054 {
9055 char buf1[19];
9056 snprintf (buf1, 19, "%s/%d",
9057 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen);
9058
9059 switch (er->path_type)
9060 {
9061 case OSPF_PATH_TYPE1_EXTERNAL:
9062 vty_out (vty, "N E1 %-18s [%d] tag: %"ROUTE_TAG_PRI"%s", buf1,
9063 er->cost, er->u.ext.tag, VTY_NEWLINE);
9064 break;
9065 case OSPF_PATH_TYPE2_EXTERNAL:
9066 vty_out (vty, "N E2 %-18s [%d/%d] tag: %"ROUTE_TAG_PRI"%s", buf1, er->cost,
9067 er->u.ext.type2_cost, er->u.ext.tag, VTY_NEWLINE);
9068 break;
9069 }
9070
9071 for (ALL_LIST_ELEMENTS (er->paths, pnode, pnnode, path))
9072 {
9073 if (if_lookup_by_index(path->ifindex))
9074 {
9075 if (path->nexthop.s_addr == 0)
9076 vty_out (vty, "%24s directly attached to %s%s",
9077 "", ifindex2ifname (path->ifindex), VTY_NEWLINE);
9078 else
9079 vty_out (vty, "%24s via %s, %s%s", "",
9080 inet_ntoa (path->nexthop),
9081 ifindex2ifname (path->ifindex),
9082 VTY_NEWLINE);
9083 }
9084 }
9085 }
9086 vty_out (vty, "%s", VTY_NEWLINE);
9087 }
9088
9089 static int
9090 show_ip_ospf_border_routers_common (struct vty *vty, struct ospf *ospf)
9091 {
9092 if (ospf->instance)
9093 vty_out (vty, "%sOSPF Instance: %d%s%s", VTY_NEWLINE, ospf->instance,
9094 VTY_NEWLINE, VTY_NEWLINE);
9095
9096 if (ospf->new_table == NULL)
9097 {
9098 vty_out (vty, "No OSPF routing information exist%s", VTY_NEWLINE);
9099 return CMD_SUCCESS;
9100 }
9101
9102 /* Show Network routes.
9103 show_ip_ospf_route_network (vty, ospf->new_table); */
9104
9105 /* Show Router routes. */
9106 show_ip_ospf_route_router (vty, ospf->new_rtrs);
9107
9108 vty_out (vty, "%s", VTY_NEWLINE);
9109
9110 return CMD_SUCCESS;
9111 }
9112
9113 DEFUN (show_ip_ospf_border_routers,
9114 show_ip_ospf_border_routers_cmd,
9115 "show ip ospf border-routers",
9116 SHOW_STR
9117 IP_STR
9118 "OSPF information\n"
9119 "Show all the ABR's and ASBR's\n")
9120 {
9121 struct ospf *ospf;
9122
9123 if ((ospf = ospf_lookup ()) == NULL || !ospf->oi_running)
9124 return CMD_SUCCESS;
9125
9126 return show_ip_ospf_border_routers_common(vty, ospf);
9127 }
9128
9129 DEFUN (show_ip_ospf_instance_border_routers,
9130 show_ip_ospf_instance_border_routers_cmd,
9131 "show ip ospf (1-65535) border-routers",
9132 SHOW_STR
9133 IP_STR
9134 "OSPF information\n"
9135 "Instance ID\n"
9136 "Show all the ABR's and ASBR's\n")
9137 {
9138 int idx_number = 3;
9139 struct ospf *ospf;
9140 u_short instance = 0;
9141
9142 VTY_GET_INTEGER ("Instance", instance, argv[idx_number]->arg);
9143 if ((ospf = ospf_lookup_instance (instance)) == NULL || !ospf->oi_running)
9144 return CMD_SUCCESS;
9145
9146 return show_ip_ospf_border_routers_common(vty, ospf);
9147 }
9148
9149 static int
9150 show_ip_ospf_route_common (struct vty *vty, struct ospf *ospf)
9151 {
9152 if (ospf->instance)
9153 vty_out (vty, "%sOSPF Instance: %d%s%s", VTY_NEWLINE, ospf->instance,
9154 VTY_NEWLINE, VTY_NEWLINE);
9155
9156 if (ospf->new_table == NULL)
9157 {
9158 vty_out (vty, "No OSPF routing information exist%s", VTY_NEWLINE);
9159 return CMD_SUCCESS;
9160 }
9161
9162 /* Show Network routes. */
9163 show_ip_ospf_route_network (vty, ospf->new_table);
9164
9165 /* Show Router routes. */
9166 show_ip_ospf_route_router (vty, ospf->new_rtrs);
9167
9168 /* Show AS External routes. */
9169 show_ip_ospf_route_external (vty, ospf->old_external_route);
9170
9171 vty_out (vty, "%s", VTY_NEWLINE);
9172
9173 return CMD_SUCCESS;
9174 }
9175
9176 DEFUN (show_ip_ospf_route,
9177 show_ip_ospf_route_cmd,
9178 "show ip ospf route",
9179 SHOW_STR
9180 IP_STR
9181 "OSPF information\n"
9182 "OSPF routing table\n")
9183 {
9184 struct ospf *ospf;
9185
9186 if ((ospf = ospf_lookup ()) == NULL || !ospf->oi_running)
9187 return CMD_SUCCESS;
9188
9189 return show_ip_ospf_route_common(vty, ospf);
9190 }
9191
9192 DEFUN (show_ip_ospf_instance_route,
9193 show_ip_ospf_instance_route_cmd,
9194 "show ip ospf (1-65535) route",
9195 SHOW_STR
9196 IP_STR
9197 "OSPF information\n"
9198 "Instance ID\n"
9199 "OSPF routing table\n")
9200 {
9201 int idx_number = 3;
9202 struct ospf *ospf;
9203 u_short instance = 0;
9204
9205 VTY_GET_INTEGER ("Instance", instance, argv[idx_number]->arg);
9206 if ((ospf = ospf_lookup_instance (instance)) == NULL || !ospf->oi_running)
9207 return CMD_SUCCESS;
9208
9209 return show_ip_ospf_route_common(vty, ospf);
9210 }
9211
9212 const char *ospf_abr_type_str[] =
9213 {
9214 "unknown",
9215 "standard",
9216 "ibm",
9217 "cisco",
9218 "shortcut"
9219 };
9220
9221 const char *ospf_shortcut_mode_str[] =
9222 {
9223 "default",
9224 "enable",
9225 "disable"
9226 };
9227
9228
9229 static void
9230 area_id2str (char *buf, int length, struct ospf_area *area)
9231 {
9232 memset (buf, 0, length);
9233
9234 if (area->format == OSPF_AREA_ID_FORMAT_ADDRESS)
9235 strncpy (buf, inet_ntoa (area->area_id), length);
9236 else
9237 sprintf (buf, "%lu", (unsigned long) ntohl (area->area_id.s_addr));
9238 }
9239
9240
9241 const char *ospf_int_type_str[] =
9242 {
9243 "unknown", /* should never be used. */
9244 "point-to-point",
9245 "broadcast",
9246 "non-broadcast",
9247 "point-to-multipoint",
9248 "virtual-link", /* should never be used. */
9249 "loopback"
9250 };
9251
9252 /* Configuration write function for ospfd. */
9253 static int
9254 config_write_interface (struct vty *vty)
9255 {
9256 struct listnode *n1, *n2;
9257 struct interface *ifp;
9258 struct crypt_key *ck;
9259 int write = 0;
9260 struct route_node *rn = NULL;
9261 struct ospf_if_params *params;
9262 struct ospf *ospf = ospf_lookup();
9263
9264 for (ALL_LIST_ELEMENTS_RO (vrf_iflist (VRF_DEFAULT), n1, ifp))
9265 {
9266 if (memcmp (ifp->name, "VLINK", 5) == 0)
9267 continue;
9268
9269 if (ifp->ifindex == IFINDEX_DELETED)
9270 continue;
9271
9272 vty_out (vty, "!%s", VTY_NEWLINE);
9273 vty_out (vty, "interface %s%s", ifp->name,
9274 VTY_NEWLINE);
9275 if (ifp->desc)
9276 vty_out (vty, " description %s%s", ifp->desc,
9277 VTY_NEWLINE);
9278
9279 write++;
9280
9281 params = IF_DEF_PARAMS (ifp);
9282
9283 do {
9284 /* Interface Network print. */
9285 if (OSPF_IF_PARAM_CONFIGURED (params, type) &&
9286 params->type != OSPF_IFTYPE_LOOPBACK)
9287 {
9288 if (params->type != ospf_default_iftype(ifp))
9289 {
9290 vty_out (vty, " ip ospf network %s",
9291 ospf_int_type_str[params->type]);
9292 if (params != IF_DEF_PARAMS (ifp))
9293 vty_out (vty, " %s", inet_ntoa (rn->p.u.prefix4));
9294 vty_out (vty, "%s", VTY_NEWLINE);
9295 }
9296 }
9297
9298 /* OSPF interface authentication print */
9299 if (OSPF_IF_PARAM_CONFIGURED (params, auth_type) &&
9300 params->auth_type != OSPF_AUTH_NOTSET)
9301 {
9302 const char *auth_str;
9303
9304 /* Translation tables are not that much help here due to syntax
9305 of the simple option */
9306 switch (params->auth_type)
9307 {
9308
9309 case OSPF_AUTH_NULL:
9310 auth_str = " null";
9311 break;
9312
9313 case OSPF_AUTH_SIMPLE:
9314 auth_str = "";
9315 break;
9316
9317 case OSPF_AUTH_CRYPTOGRAPHIC:
9318 auth_str = " message-digest";
9319 break;
9320
9321 default:
9322 auth_str = "";
9323 break;
9324 }
9325
9326 vty_out (vty, " ip ospf authentication%s", auth_str);
9327 if (params != IF_DEF_PARAMS (ifp))
9328 vty_out (vty, " %s", inet_ntoa (rn->p.u.prefix4));
9329 vty_out (vty, "%s", VTY_NEWLINE);
9330 }
9331
9332 /* Simple Authentication Password print. */
9333 if (OSPF_IF_PARAM_CONFIGURED (params, auth_simple) &&
9334 params->auth_simple[0] != '\0')
9335 {
9336 vty_out (vty, " ip ospf authentication-key %s",
9337 params->auth_simple);
9338 if (params != IF_DEF_PARAMS (ifp))
9339 vty_out (vty, " %s", inet_ntoa (rn->p.u.prefix4));
9340 vty_out (vty, "%s", VTY_NEWLINE);
9341 }
9342
9343 /* Cryptographic Authentication Key print. */
9344 for (ALL_LIST_ELEMENTS_RO (params->auth_crypt, n2, ck))
9345 {
9346 vty_out (vty, " ip ospf message-digest-key %d md5 %s",
9347 ck->key_id, ck->auth_key);
9348 if (params != IF_DEF_PARAMS (ifp))
9349 vty_out (vty, " %s", inet_ntoa (rn->p.u.prefix4));
9350 vty_out (vty, "%s", VTY_NEWLINE);
9351 }
9352
9353 /* Interface Output Cost print. */
9354 if (OSPF_IF_PARAM_CONFIGURED (params, output_cost_cmd))
9355 {
9356 vty_out (vty, " ip ospf cost %u", params->output_cost_cmd);
9357 if (params != IF_DEF_PARAMS (ifp))
9358 vty_out (vty, " %s", inet_ntoa (rn->p.u.prefix4));
9359 vty_out (vty, "%s", VTY_NEWLINE);
9360 }
9361
9362 /* Hello Interval print. */
9363 if (OSPF_IF_PARAM_CONFIGURED (params, v_hello) &&
9364 params->v_hello != OSPF_HELLO_INTERVAL_DEFAULT)
9365 {
9366 vty_out (vty, " ip ospf hello-interval %u", params->v_hello);
9367 if (params != IF_DEF_PARAMS (ifp))
9368 vty_out (vty, " %s", inet_ntoa (rn->p.u.prefix4));
9369 vty_out (vty, "%s", VTY_NEWLINE);
9370 }
9371
9372
9373 /* Router Dead Interval print. */
9374 if (OSPF_IF_PARAM_CONFIGURED (params, v_wait) &&
9375 params->v_wait != OSPF_ROUTER_DEAD_INTERVAL_DEFAULT)
9376 {
9377 vty_out (vty, " ip ospf dead-interval ");
9378
9379 /* fast hello ? */
9380 if (OSPF_IF_PARAM_CONFIGURED (params, fast_hello))
9381 vty_out (vty, "minimal hello-multiplier %d",
9382 params->fast_hello);
9383 else
9384 vty_out (vty, "%u", params->v_wait);
9385
9386 if (params != IF_DEF_PARAMS (ifp))
9387 vty_out (vty, " %s", inet_ntoa (rn->p.u.prefix4));
9388 vty_out (vty, "%s", VTY_NEWLINE);
9389 }
9390
9391 /* Router Priority print. */
9392 if (OSPF_IF_PARAM_CONFIGURED (params, priority) &&
9393 params->priority != OSPF_ROUTER_PRIORITY_DEFAULT)
9394 {
9395 vty_out (vty, " ip ospf priority %u", params->priority);
9396 if (params != IF_DEF_PARAMS (ifp))
9397 vty_out (vty, " %s", inet_ntoa (rn->p.u.prefix4));
9398 vty_out (vty, "%s", VTY_NEWLINE);
9399 }
9400
9401 /* Retransmit Interval print. */
9402 if (OSPF_IF_PARAM_CONFIGURED (params, retransmit_interval) &&
9403 params->retransmit_interval != OSPF_RETRANSMIT_INTERVAL_DEFAULT)
9404 {
9405 vty_out (vty, " ip ospf retransmit-interval %u",
9406 params->retransmit_interval);
9407 if (params != IF_DEF_PARAMS (ifp))
9408 vty_out (vty, " %s", inet_ntoa (rn->p.u.prefix4));
9409 vty_out (vty, "%s", VTY_NEWLINE);
9410 }
9411
9412 /* Transmit Delay print. */
9413 if (OSPF_IF_PARAM_CONFIGURED (params, transmit_delay) &&
9414 params->transmit_delay != OSPF_TRANSMIT_DELAY_DEFAULT)
9415 {
9416 vty_out (vty, " ip ospf transmit-delay %u", params->transmit_delay);
9417 if (params != IF_DEF_PARAMS (ifp))
9418 vty_out (vty, " %s", inet_ntoa (rn->p.u.prefix4));
9419 vty_out (vty, "%s", VTY_NEWLINE);
9420 }
9421
9422 /* Area print. */
9423 if (OSPF_IF_PARAM_CONFIGURED (params, if_area))
9424 {
9425 if (ospf->instance)
9426 vty_out (vty, " ip ospf %d area %s%s", ospf->instance,
9427 inet_ntoa (params->if_area), VTY_NEWLINE);
9428 else
9429 vty_out (vty, " ip ospf area %s%s",
9430 inet_ntoa (params->if_area), VTY_NEWLINE);
9431
9432 }
9433
9434 /* bfd print. */
9435 ospf_bfd_write_config(vty, params);
9436
9437 /* MTU ignore print. */
9438 if (OSPF_IF_PARAM_CONFIGURED (params, mtu_ignore) &&
9439 params->mtu_ignore != OSPF_MTU_IGNORE_DEFAULT)
9440 {
9441 if (params->mtu_ignore == 0)
9442 vty_out (vty, " no ip ospf mtu-ignore");
9443 else
9444 vty_out (vty, " ip ospf mtu-ignore");
9445 if (params != IF_DEF_PARAMS (ifp))
9446 vty_out (vty, " %s", inet_ntoa (rn->p.u.prefix4));
9447 vty_out (vty, "%s", VTY_NEWLINE);
9448 }
9449
9450
9451 while (1)
9452 {
9453 if (rn == NULL)
9454 rn = route_top (IF_OIFS_PARAMS (ifp));
9455 else
9456 rn = route_next (rn);
9457
9458 if (rn == NULL)
9459 break;
9460 params = rn->info;
9461 if (params != NULL)
9462 break;
9463 }
9464 } while (rn);
9465
9466 ospf_opaque_config_write_if (vty, ifp);
9467 }
9468
9469 return write;
9470 }
9471
9472 static int
9473 config_write_network_area (struct vty *vty, struct ospf *ospf)
9474 {
9475 struct route_node *rn;
9476 u_char buf[INET_ADDRSTRLEN];
9477
9478 /* `network area' print. */
9479 for (rn = route_top (ospf->networks); rn; rn = route_next (rn))
9480 if (rn->info)
9481 {
9482 struct ospf_network *n = rn->info;
9483
9484 memset (buf, 0, INET_ADDRSTRLEN);
9485
9486 /* Create Area ID string by specified Area ID format. */
9487 if (n->format == OSPF_AREA_ID_FORMAT_ADDRESS)
9488 strncpy ((char *) buf, inet_ntoa (n->area_id), INET_ADDRSTRLEN);
9489 else
9490 sprintf ((char *) buf, "%lu",
9491 (unsigned long int) ntohl (n->area_id.s_addr));
9492
9493 /* Network print. */
9494 vty_out (vty, " network %s/%d area %s%s",
9495 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
9496 buf, VTY_NEWLINE);
9497 }
9498
9499 return 0;
9500 }
9501
9502 static int
9503 config_write_ospf_area (struct vty *vty, struct ospf *ospf)
9504 {
9505 struct listnode *node;
9506 struct ospf_area *area;
9507 u_char buf[INET_ADDRSTRLEN];
9508
9509 /* Area configuration print. */
9510 for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
9511 {
9512 struct route_node *rn1;
9513
9514 area_id2str ((char *) buf, INET_ADDRSTRLEN, area);
9515
9516 if (area->auth_type != OSPF_AUTH_NULL)
9517 {
9518 if (area->auth_type == OSPF_AUTH_SIMPLE)
9519 vty_out (vty, " area %s authentication%s", buf, VTY_NEWLINE);
9520 else
9521 vty_out (vty, " area %s authentication message-digest%s",
9522 buf, VTY_NEWLINE);
9523 }
9524
9525 if (area->shortcut_configured != OSPF_SHORTCUT_DEFAULT)
9526 vty_out (vty, " area %s shortcut %s%s", buf,
9527 ospf_shortcut_mode_str[area->shortcut_configured],
9528 VTY_NEWLINE);
9529
9530 if ((area->external_routing == OSPF_AREA_STUB)
9531 || (area->external_routing == OSPF_AREA_NSSA)
9532 )
9533 {
9534 if (area->external_routing == OSPF_AREA_STUB)
9535 vty_out (vty, " area %s stub", buf);
9536 else if (area->external_routing == OSPF_AREA_NSSA)
9537 {
9538 vty_out (vty, " area %s nssa", buf);
9539 switch (area->NSSATranslatorRole)
9540 {
9541 case OSPF_NSSA_ROLE_NEVER:
9542 vty_out (vty, " translate-never");
9543 break;
9544 case OSPF_NSSA_ROLE_ALWAYS:
9545 vty_out (vty, " translate-always");
9546 break;
9547 case OSPF_NSSA_ROLE_CANDIDATE:
9548 default:
9549 vty_out (vty, " translate-candidate");
9550 }
9551 }
9552
9553 if (area->no_summary)
9554 vty_out (vty, " no-summary");
9555
9556 vty_out (vty, "%s", VTY_NEWLINE);
9557
9558 if (area->default_cost != 1)
9559 vty_out (vty, " area %s default-cost %d%s", buf,
9560 area->default_cost, VTY_NEWLINE);
9561 }
9562
9563 for (rn1 = route_top (area->ranges); rn1; rn1 = route_next (rn1))
9564 if (rn1->info)
9565 {
9566 struct ospf_area_range *range = rn1->info;
9567
9568 vty_out (vty, " area %s range %s/%d", buf,
9569 inet_ntoa (rn1->p.u.prefix4), rn1->p.prefixlen);
9570
9571 if (range->cost_config != OSPF_AREA_RANGE_COST_UNSPEC)
9572 vty_out (vty, " cost %d", range->cost_config);
9573
9574 if (!CHECK_FLAG (range->flags, OSPF_AREA_RANGE_ADVERTISE))
9575 vty_out (vty, " not-advertise");
9576
9577 if (CHECK_FLAG (range->flags, OSPF_AREA_RANGE_SUBSTITUTE))
9578 vty_out (vty, " substitute %s/%d",
9579 inet_ntoa (range->subst_addr), range->subst_masklen);
9580
9581 vty_out (vty, "%s", VTY_NEWLINE);
9582 }
9583
9584 if (EXPORT_NAME (area))
9585 vty_out (vty, " area %s export-list %s%s", buf,
9586 EXPORT_NAME (area), VTY_NEWLINE);
9587
9588 if (IMPORT_NAME (area))
9589 vty_out (vty, " area %s import-list %s%s", buf,
9590 IMPORT_NAME (area), VTY_NEWLINE);
9591
9592 if (PREFIX_NAME_IN (area))
9593 vty_out (vty, " area %s filter-list prefix %s in%s", buf,
9594 PREFIX_NAME_IN (area), VTY_NEWLINE);
9595
9596 if (PREFIX_NAME_OUT (area))
9597 vty_out (vty, " area %s filter-list prefix %s out%s", buf,
9598 PREFIX_NAME_OUT (area), VTY_NEWLINE);
9599 }
9600
9601 return 0;
9602 }
9603
9604 static int
9605 config_write_ospf_nbr_nbma (struct vty *vty, struct ospf *ospf)
9606 {
9607 struct ospf_nbr_nbma *nbr_nbma;
9608 struct route_node *rn;
9609
9610 /* Static Neighbor configuration print. */
9611 for (rn = route_top (ospf->nbr_nbma); rn; rn = route_next (rn))
9612 if ((nbr_nbma = rn->info))
9613 {
9614 vty_out (vty, " neighbor %s", inet_ntoa (nbr_nbma->addr));
9615
9616 if (nbr_nbma->priority != OSPF_NEIGHBOR_PRIORITY_DEFAULT)
9617 vty_out (vty, " priority %d", nbr_nbma->priority);
9618
9619 if (nbr_nbma->v_poll != OSPF_POLL_INTERVAL_DEFAULT)
9620 vty_out (vty, " poll-interval %d", nbr_nbma->v_poll);
9621
9622 vty_out (vty, "%s", VTY_NEWLINE);
9623 }
9624
9625 return 0;
9626 }
9627
9628 static int
9629 config_write_virtual_link (struct vty *vty, struct ospf *ospf)
9630 {
9631 struct listnode *node;
9632 struct ospf_vl_data *vl_data;
9633 u_char buf[INET_ADDRSTRLEN];
9634
9635 /* Virtual-Link print */
9636 for (ALL_LIST_ELEMENTS_RO (ospf->vlinks, node, vl_data))
9637 {
9638 struct listnode *n2;
9639 struct crypt_key *ck;
9640 struct ospf_interface *oi;
9641
9642 if (vl_data != NULL)
9643 {
9644 memset (buf, 0, INET_ADDRSTRLEN);
9645
9646 if (vl_data->format == OSPF_AREA_ID_FORMAT_ADDRESS)
9647 strncpy ((char *) buf, inet_ntoa (vl_data->vl_area_id), INET_ADDRSTRLEN);
9648 else
9649 sprintf ((char *) buf, "%lu",
9650 (unsigned long int) ntohl (vl_data->vl_area_id.s_addr));
9651 oi = vl_data->vl_oi;
9652
9653 /* timers */
9654 if (OSPF_IF_PARAM (oi, v_hello) != OSPF_HELLO_INTERVAL_DEFAULT ||
9655 OSPF_IF_PARAM (oi, v_wait) != OSPF_ROUTER_DEAD_INTERVAL_DEFAULT ||
9656 OSPF_IF_PARAM (oi, retransmit_interval) != OSPF_RETRANSMIT_INTERVAL_DEFAULT ||
9657 OSPF_IF_PARAM (oi, transmit_delay) != OSPF_TRANSMIT_DELAY_DEFAULT)
9658 vty_out (vty, " area %s virtual-link %s hello-interval %d retransmit-interval %d transmit-delay %d dead-interval %d%s",
9659 buf,
9660 inet_ntoa (vl_data->vl_peer),
9661 OSPF_IF_PARAM (oi, v_hello),
9662 OSPF_IF_PARAM (oi, retransmit_interval),
9663 OSPF_IF_PARAM (oi, transmit_delay),
9664 OSPF_IF_PARAM (oi, v_wait),
9665 VTY_NEWLINE);
9666 else
9667 vty_out (vty, " area %s virtual-link %s%s", buf,
9668 inet_ntoa (vl_data->vl_peer), VTY_NEWLINE);
9669 /* Auth key */
9670 if (IF_DEF_PARAMS (vl_data->vl_oi->ifp)->auth_simple[0] != '\0')
9671 vty_out (vty, " area %s virtual-link %s authentication-key %s%s",
9672 buf,
9673 inet_ntoa (vl_data->vl_peer),
9674 IF_DEF_PARAMS (vl_data->vl_oi->ifp)->auth_simple,
9675 VTY_NEWLINE);
9676 /* md5 keys */
9677 for (ALL_LIST_ELEMENTS_RO (IF_DEF_PARAMS (vl_data->vl_oi->ifp)->auth_crypt,
9678 n2, ck))
9679 vty_out (vty, " area %s virtual-link %s"
9680 " message-digest-key %d md5 %s%s",
9681 buf,
9682 inet_ntoa (vl_data->vl_peer),
9683 ck->key_id, ck->auth_key, VTY_NEWLINE);
9684
9685 }
9686 }
9687
9688 return 0;
9689 }
9690
9691
9692 static int
9693 config_write_ospf_redistribute (struct vty *vty, struct ospf *ospf)
9694 {
9695 int type;
9696
9697 /* redistribute print. */
9698 for (type = 0; type < ZEBRA_ROUTE_MAX; type++)
9699 {
9700 struct list *red_list;
9701 struct listnode *node;
9702 struct ospf_redist *red;
9703
9704 red_list = ospf->redist[type];
9705 if (!red_list)
9706 continue;
9707
9708 for (ALL_LIST_ELEMENTS_RO(red_list, node, red))
9709 {
9710 vty_out (vty, " redistribute %s", zebra_route_string(type));
9711 if (red->instance)
9712 vty_out (vty, " %d", red->instance);
9713
9714 if (red->dmetric.value >= 0)
9715 vty_out (vty, " metric %d", red->dmetric.value);
9716
9717 if (red->dmetric.type == EXTERNAL_METRIC_TYPE_1)
9718 vty_out (vty, " metric-type 1");
9719
9720 if (ROUTEMAP_NAME (red))
9721 vty_out (vty, " route-map %s", ROUTEMAP_NAME (red));
9722
9723 vty_out (vty, "%s", VTY_NEWLINE);
9724 }
9725 }
9726
9727 return 0;
9728 }
9729
9730 static int
9731 config_write_ospf_default_metric (struct vty *vty, struct ospf *ospf)
9732 {
9733 if (ospf->default_metric != -1)
9734 vty_out (vty, " default-metric %d%s", ospf->default_metric,
9735 VTY_NEWLINE);
9736 return 0;
9737 }
9738
9739 static int
9740 config_write_ospf_distribute (struct vty *vty, struct ospf *ospf)
9741 {
9742 int type;
9743 struct ospf_redist *red;
9744
9745 if (ospf)
9746 {
9747 /* distribute-list print. */
9748 for (type = 0; type < ZEBRA_ROUTE_MAX; type++)
9749 if (DISTRIBUTE_NAME (ospf, type))
9750 vty_out (vty, " distribute-list %s out %s%s",
9751 DISTRIBUTE_NAME (ospf, type),
9752 zebra_route_string(type), VTY_NEWLINE);
9753
9754 /* default-information print. */
9755 if (ospf->default_originate != DEFAULT_ORIGINATE_NONE)
9756 {
9757 vty_out (vty, " default-information originate");
9758 if (ospf->default_originate == DEFAULT_ORIGINATE_ALWAYS)
9759 vty_out (vty, " always");
9760
9761 red = ospf_redist_lookup(ospf, DEFAULT_ROUTE, 0);
9762 if (red)
9763 {
9764 if (red->dmetric.value >= 0)
9765 vty_out (vty, " metric %d",
9766 red->dmetric.value);
9767 if (red->dmetric.type == EXTERNAL_METRIC_TYPE_1)
9768 vty_out (vty, " metric-type 1");
9769
9770 if (ROUTEMAP_NAME (red))
9771 vty_out (vty, " route-map %s",
9772 ROUTEMAP_NAME (red));
9773 }
9774
9775 vty_out (vty, "%s", VTY_NEWLINE);
9776 }
9777
9778 }
9779
9780 return 0;
9781 }
9782
9783 static int
9784 config_write_ospf_distance (struct vty *vty, struct ospf *ospf)
9785 {
9786 struct route_node *rn;
9787 struct ospf_distance *odistance;
9788
9789 if (ospf->distance_all)
9790 vty_out (vty, " distance %d%s", ospf->distance_all, VTY_NEWLINE);
9791
9792 if (ospf->distance_intra
9793 || ospf->distance_inter
9794 || ospf->distance_external)
9795 {
9796 vty_out (vty, " distance ospf");
9797
9798 if (ospf->distance_intra)
9799 vty_out (vty, " intra-area %d", ospf->distance_intra);
9800 if (ospf->distance_inter)
9801 vty_out (vty, " inter-area %d", ospf->distance_inter);
9802 if (ospf->distance_external)
9803 vty_out (vty, " external %d", ospf->distance_external);
9804
9805 vty_out (vty, "%s", VTY_NEWLINE);
9806 }
9807
9808 for (rn = route_top (ospf->distance_table); rn; rn = route_next (rn))
9809 if ((odistance = rn->info) != NULL)
9810 {
9811 vty_out (vty, " distance %d %s/%d %s%s", odistance->distance,
9812 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
9813 odistance->access_list ? odistance->access_list : "",
9814 VTY_NEWLINE);
9815 }
9816 return 0;
9817 }
9818
9819 /* OSPF configuration write function. */
9820 static int
9821 ospf_config_write (struct vty *vty)
9822 {
9823 struct ospf *ospf;
9824 struct interface *ifp;
9825 struct ospf_interface *oi;
9826 struct listnode *node;
9827 int write = 0;
9828
9829 ospf = ospf_lookup ();
9830 if (ospf != NULL && ospf->oi_running)
9831 {
9832 /* `router ospf' print. */
9833 if (ospf->instance)
9834 vty_out (vty, "router ospf %d%s", ospf->instance, VTY_NEWLINE);
9835 else
9836 vty_out (vty, "router ospf%s", VTY_NEWLINE);
9837
9838 write++;
9839
9840 if (!ospf->networks)
9841 return write;
9842
9843 /* Router ID print. */
9844 if (ospf->router_id_static.s_addr != 0)
9845 vty_out (vty, " ospf router-id %s%s",
9846 inet_ntoa (ospf->router_id_static), VTY_NEWLINE);
9847
9848 /* ABR type print. */
9849 if (ospf->abr_type != OSPF_ABR_DEFAULT)
9850 vty_out (vty, " ospf abr-type %s%s",
9851 ospf_abr_type_str[ospf->abr_type], VTY_NEWLINE);
9852
9853 /* log-adjacency-changes flag print. */
9854 if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES))
9855 {
9856 if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL))
9857 vty_out(vty, " log-adjacency-changes detail%s", VTY_NEWLINE);
9858 }
9859 else
9860 {
9861 vty_out(vty, " no log-adjacency-changes%s", VTY_NEWLINE);
9862 }
9863
9864 /* RFC1583 compatibility flag print -- Compatible with CISCO 12.1. */
9865 if (CHECK_FLAG (ospf->config, OSPF_RFC1583_COMPATIBLE))
9866 vty_out (vty, " compatible rfc1583%s", VTY_NEWLINE);
9867
9868 /* auto-cost reference-bandwidth configuration. */
9869 if (ospf->ref_bandwidth != OSPF_DEFAULT_REF_BANDWIDTH)
9870 {
9871 vty_out (vty, "! Important: ensure reference bandwidth "
9872 "is consistent across all routers%s", VTY_NEWLINE);
9873 vty_out (vty, " auto-cost reference-bandwidth %d%s",
9874 ospf->ref_bandwidth, VTY_NEWLINE);
9875 }
9876
9877 /* SPF timers print. */
9878 if (ospf->spf_delay != OSPF_SPF_DELAY_DEFAULT ||
9879 ospf->spf_holdtime != OSPF_SPF_HOLDTIME_DEFAULT ||
9880 ospf->spf_max_holdtime != OSPF_SPF_MAX_HOLDTIME_DEFAULT)
9881 vty_out (vty, " timers throttle spf %d %d %d%s",
9882 ospf->spf_delay, ospf->spf_holdtime,
9883 ospf->spf_max_holdtime, VTY_NEWLINE);
9884
9885 /* LSA timers print. */
9886 if (ospf->min_ls_interval != OSPF_MIN_LS_INTERVAL)
9887 vty_out (vty, " timers throttle lsa all %d%s",
9888 ospf->min_ls_interval, VTY_NEWLINE);
9889 if (ospf->min_ls_arrival != OSPF_MIN_LS_ARRIVAL)
9890 vty_out (vty, " timers lsa min-arrival %d%s",
9891 ospf->min_ls_arrival, VTY_NEWLINE);
9892
9893 /* Write multiplier print. */
9894 if (ospf->write_oi_count != OSPF_WRITE_INTERFACE_COUNT_DEFAULT)
9895 vty_out (vty, " ospf write-multiplier %d%s",
9896 ospf->write_oi_count, VTY_NEWLINE);
9897
9898 /* Max-metric router-lsa print */
9899 config_write_stub_router (vty, ospf);
9900
9901 /* SPF refresh parameters print. */
9902 if (ospf->lsa_refresh_interval != OSPF_LSA_REFRESH_INTERVAL_DEFAULT)
9903 vty_out (vty, " refresh timer %d%s",
9904 ospf->lsa_refresh_interval, VTY_NEWLINE);
9905
9906 /* Redistribute information print. */
9907 config_write_ospf_redistribute (vty, ospf);
9908
9909 /* passive-interface print. */
9910 if (ospf->passive_interface_default == OSPF_IF_PASSIVE)
9911 vty_out (vty, " passive-interface default%s", VTY_NEWLINE);
9912
9913 for (ALL_LIST_ELEMENTS_RO (om->iflist, node, ifp))
9914 if (OSPF_IF_PARAM_CONFIGURED (IF_DEF_PARAMS (ifp), passive_interface)
9915 && IF_DEF_PARAMS (ifp)->passive_interface !=
9916 ospf->passive_interface_default)
9917 {
9918 vty_out (vty, " %spassive-interface %s%s",
9919 IF_DEF_PARAMS (ifp)->passive_interface ? "" : "no ",
9920 ifp->name, VTY_NEWLINE);
9921 }
9922 for (ALL_LIST_ELEMENTS_RO (ospf->oiflist, node, oi))
9923 {
9924 if (!OSPF_IF_PARAM_CONFIGURED (oi->params, passive_interface))
9925 continue;
9926 if (OSPF_IF_PARAM_CONFIGURED (IF_DEF_PARAMS (oi->ifp),
9927 passive_interface))
9928 {
9929 if (oi->params->passive_interface == IF_DEF_PARAMS (oi->ifp)->passive_interface)
9930 continue;
9931 }
9932 else if (oi->params->passive_interface == ospf->passive_interface_default)
9933 continue;
9934
9935 vty_out (vty, " %spassive-interface %s %s%s",
9936 oi->params->passive_interface ? "" : "no ",
9937 oi->ifp->name,
9938 inet_ntoa (oi->address->u.prefix4), VTY_NEWLINE);
9939 }
9940
9941 /* Network area print. */
9942 config_write_network_area (vty, ospf);
9943
9944 /* Area config print. */
9945 config_write_ospf_area (vty, ospf);
9946
9947 /* static neighbor print. */
9948 config_write_ospf_nbr_nbma (vty, ospf);
9949
9950 /* Virtual-Link print. */
9951 config_write_virtual_link (vty, ospf);
9952
9953 /* Default metric configuration. */
9954 config_write_ospf_default_metric (vty, ospf);
9955
9956 /* Distribute-list and default-information print. */
9957 config_write_ospf_distribute (vty, ospf);
9958
9959 /* Distance configuration. */
9960 config_write_ospf_distance (vty, ospf);
9961
9962 ospf_opaque_config_write_router (vty, ospf);
9963 }
9964
9965 return write;
9966 }
9967
9968 void
9969 ospf_vty_show_init (void)
9970 {
9971 /* "show ip ospf" commands. */
9972 install_element (VIEW_NODE, &show_ip_ospf_cmd);
9973
9974 install_element (VIEW_NODE, &show_ip_ospf_instance_cmd);
9975
9976 /* "show ip ospf database" commands. */
9977 install_element (VIEW_NODE, &show_ip_ospf_database_type_adv_router_cmd);
9978 install_element (VIEW_NODE, &show_ip_ospf_database_cmd);
9979 install_element (VIEW_NODE, &show_ip_ospf_database_max_cmd);
9980
9981 install_element (VIEW_NODE, &show_ip_ospf_instance_database_type_adv_router_cmd);
9982 install_element (VIEW_NODE, &show_ip_ospf_instance_database_cmd);
9983 install_element (VIEW_NODE, &show_ip_ospf_instance_database_max_cmd);
9984
9985 /* "show ip ospf interface" commands. */
9986 install_element (VIEW_NODE, &show_ip_ospf_interface_cmd);
9987
9988 install_element (VIEW_NODE, &show_ip_ospf_instance_interface_cmd);
9989
9990 /* "show ip ospf neighbor" commands. */
9991 install_element (VIEW_NODE, &show_ip_ospf_neighbor_int_detail_cmd);
9992 install_element (VIEW_NODE, &show_ip_ospf_neighbor_int_cmd);
9993 install_element (VIEW_NODE, &show_ip_ospf_neighbor_id_cmd);
9994 install_element (VIEW_NODE, &show_ip_ospf_neighbor_detail_all_cmd);
9995 install_element (VIEW_NODE, &show_ip_ospf_neighbor_detail_cmd);
9996 install_element (VIEW_NODE, &show_ip_ospf_neighbor_cmd);
9997 install_element (VIEW_NODE, &show_ip_ospf_neighbor_all_cmd);
9998
9999 install_element (VIEW_NODE, &show_ip_ospf_instance_neighbor_int_detail_cmd);
10000 install_element (VIEW_NODE, &show_ip_ospf_instance_neighbor_int_cmd);
10001 install_element (VIEW_NODE, &show_ip_ospf_instance_neighbor_id_cmd);
10002 install_element (VIEW_NODE, &show_ip_ospf_instance_neighbor_detail_all_cmd);
10003 install_element (VIEW_NODE, &show_ip_ospf_instance_neighbor_detail_cmd);
10004 install_element (VIEW_NODE, &show_ip_ospf_instance_neighbor_cmd);
10005 install_element (VIEW_NODE, &show_ip_ospf_instance_neighbor_all_cmd);
10006
10007 /* "show ip ospf route" commands. */
10008 install_element (VIEW_NODE, &show_ip_ospf_route_cmd);
10009 install_element (VIEW_NODE, &show_ip_ospf_border_routers_cmd);
10010
10011 install_element (VIEW_NODE, &show_ip_ospf_instance_route_cmd);
10012 install_element (VIEW_NODE, &show_ip_ospf_instance_border_routers_cmd);
10013 }
10014
10015
10016 /* ospfd's interface node. */
10017 static struct cmd_node interface_node =
10018 {
10019 INTERFACE_NODE,
10020 "%s(config-if)# ",
10021 1
10022 };
10023
10024 /* Initialization of OSPF interface. */
10025 static void
10026 ospf_vty_if_init (void)
10027 {
10028 /* Install interface node. */
10029 install_node (&interface_node, config_write_interface);
10030
10031 install_element (CONFIG_NODE, &interface_cmd);
10032 install_element (CONFIG_NODE, &no_interface_cmd);
10033 install_default (INTERFACE_NODE);
10034
10035 /* "description" commands. */
10036 install_element (INTERFACE_NODE, &interface_desc_cmd);
10037 install_element (INTERFACE_NODE, &no_interface_desc_cmd);
10038
10039 /* "ip ospf authentication" commands. */
10040 install_element (INTERFACE_NODE, &ip_ospf_authentication_args_addr_cmd);
10041 install_element (INTERFACE_NODE, &ip_ospf_authentication_addr_cmd);
10042 install_element (INTERFACE_NODE, &no_ip_ospf_authentication_args_addr_cmd);
10043 install_element (INTERFACE_NODE, &no_ip_ospf_authentication_addr_cmd);
10044 install_element (INTERFACE_NODE, &ip_ospf_authentication_key_addr_cmd);
10045 install_element (INTERFACE_NODE, &no_ip_ospf_authentication_key_authkey_addr_cmd);
10046 install_element (INTERFACE_NODE, &no_ospf_authentication_key_authkey_addr_cmd);
10047
10048 /* "ip ospf message-digest-key" commands. */
10049 install_element (INTERFACE_NODE, &ip_ospf_message_digest_key_addr_cmd);
10050 install_element (INTERFACE_NODE, &no_ip_ospf_message_digest_key_addr_cmd);
10051 install_element (INTERFACE_NODE, &no_ip_ospf_message_digest_key_md5_addr_cmd);
10052 install_element (INTERFACE_NODE, &no_ospf_message_digest_key_addr_cmd);
10053
10054 /* "ip ospf cost" commands. */
10055 install_element (INTERFACE_NODE, &ip_ospf_cost_u32_inet4_cmd);
10056 install_element (INTERFACE_NODE, &no_ip_ospf_cost_u32_cmd);
10057 install_element (INTERFACE_NODE, &no_ip_ospf_cost_inet4_cmd);
10058 install_element (INTERFACE_NODE, &no_ospf_cost_inet4_cmd);
10059 install_element (INTERFACE_NODE, &no_ospf_cost_u32_cmd);
10060
10061 /* "ip ospf mtu-ignore" commands. */
10062 install_element (INTERFACE_NODE, &ip_ospf_mtu_ignore_addr_cmd);
10063 install_element (INTERFACE_NODE, &no_ip_ospf_mtu_ignore_addr_cmd);
10064
10065 /* "ip ospf dead-interval" commands. */
10066 install_element (INTERFACE_NODE, &ip_ospf_dead_interval_addr_cmd);
10067 install_element (INTERFACE_NODE, &ip_ospf_dead_interval_minimal_addr_cmd);
10068 install_element (INTERFACE_NODE, &no_ip_ospf_dead_interval_addr_cmd);
10069
10070 /* "ip ospf hello-interval" commands. */
10071 install_element (INTERFACE_NODE, &ip_ospf_hello_interval_addr_cmd);
10072 install_element (INTERFACE_NODE, &no_ip_ospf_hello_interval_addr_cmd);
10073
10074 /* "ip ospf network" commands. */
10075 install_element (INTERFACE_NODE, &ip_ospf_network_cmd);
10076 install_element (INTERFACE_NODE, &no_ip_ospf_network_cmd);
10077 install_element (INTERFACE_NODE, &no_ospf_network_cmd);
10078
10079 /* "ip ospf priority" commands. */
10080 install_element (INTERFACE_NODE, &ip_ospf_priority_addr_cmd);
10081 install_element (INTERFACE_NODE, &no_ip_ospf_priority_addr_cmd);
10082 install_element (INTERFACE_NODE, &no_ospf_priority_addr_cmd);
10083
10084 /* "ip ospf retransmit-interval" commands. */
10085 install_element (INTERFACE_NODE, &ip_ospf_retransmit_interval_addr_cmd);
10086 install_element (INTERFACE_NODE, &no_ip_ospf_retransmit_interval_addr_cmd);
10087 install_element (INTERFACE_NODE, &no_ospf_retransmit_interval_cmd);
10088
10089 /* "ip ospf transmit-delay" commands. */
10090 install_element (INTERFACE_NODE, &ip_ospf_transmit_delay_addr_cmd);
10091 install_element (INTERFACE_NODE, &no_ip_ospf_transmit_delay_addr_cmd);
10092 install_element (INTERFACE_NODE, &no_ip_ospf_transmit_delay_sec_cmd);
10093 install_element (INTERFACE_NODE, &no_ospf_transmit_delay_cmd);
10094
10095 /* "ip ospf area" commands. */
10096 install_element (INTERFACE_NODE, &ip_ospf_area_cmd);
10097 install_element (INTERFACE_NODE, &no_ip_ospf_area_cmd);
10098 install_element (INTERFACE_NODE, &no_ip_ospf_instance_area_cmd);
10099
10100 /* These commands are compatibitliy for previous version. */
10101 install_element (INTERFACE_NODE, &ospf_authentication_key_cmd);
10102 install_element (INTERFACE_NODE, &ospf_message_digest_key_cmd);
10103 install_element (INTERFACE_NODE, &ospf_cost_u32_inet4_cmd);
10104 install_element (INTERFACE_NODE, &ospf_dead_interval_cmd);
10105 install_element (INTERFACE_NODE, &ospf_hello_interval_cmd);
10106 install_element (INTERFACE_NODE, &ospf_network_cmd);
10107 install_element (INTERFACE_NODE, &ospf_priority_cmd);
10108 install_element (INTERFACE_NODE, &ospf_retransmit_interval_cmd);
10109 install_element (INTERFACE_NODE, &ospf_transmit_delay_cmd);
10110 }
10111
10112 static void
10113 ospf_vty_zebra_init (void)
10114 {
10115 install_element (OSPF_NODE, &ospf_redistribute_source_cmd);
10116 install_element (OSPF_NODE, &no_ospf_redistribute_source_cmd);
10117 install_element (OSPF_NODE, &ospf_redistribute_instance_source_cmd);
10118 install_element (OSPF_NODE, &no_ospf_redistribute_instance_source_cmd);
10119
10120 install_element (OSPF_NODE, &ospf_distribute_list_out_cmd);
10121 install_element (OSPF_NODE, &no_ospf_distribute_list_out_cmd);
10122
10123 install_element (OSPF_NODE, &ospf_default_information_originate_cmd);
10124 install_element (OSPF_NODE, &no_ospf_default_information_originate_cmd);
10125
10126 install_element (OSPF_NODE, &ospf_default_metric_cmd);
10127 install_element (OSPF_NODE, &no_ospf_default_metric_cmd);
10128
10129 install_element (OSPF_NODE, &ospf_distance_cmd);
10130 install_element (OSPF_NODE, &no_ospf_distance_cmd);
10131 install_element (OSPF_NODE, &no_ospf_distance_ospf_cmd);
10132 install_element (OSPF_NODE, &ospf_distance_ospf_cmd);
10133 #if 0
10134 install_element (OSPF_NODE, &ospf_distance_source_cmd);
10135 install_element (OSPF_NODE, &no_ospf_distance_source_cmd);
10136 install_element (OSPF_NODE, &ospf_distance_source_access_list_cmd);
10137 install_element (OSPF_NODE, &no_ospf_distance_source_access_list_cmd);
10138 #endif /* 0 */
10139 }
10140
10141 static struct cmd_node ospf_node =
10142 {
10143 OSPF_NODE,
10144 "%s(config-router)# ",
10145 1
10146 };
10147
10148 static void
10149 ospf_interface_clear (struct interface *ifp)
10150 {
10151 if (!if_is_operative (ifp)) return;
10152
10153 if (IS_DEBUG_OSPF (ism, ISM_EVENTS))
10154 zlog (NULL, LOG_DEBUG, "ISM[%s]: clear by reset", ifp->name);
10155
10156 ospf_if_reset(ifp);
10157 }
10158
10159 DEFUN (clear_ip_ospf_interface,
10160 clear_ip_ospf_interface_cmd,
10161 "clear ip ospf interface [IFNAME]",
10162 CLEAR_STR
10163 IP_STR
10164 "OSPF information\n"
10165 "Interface information\n"
10166 "Interface name\n")
10167 {
10168 int idx_ifname = 4;
10169 struct interface *ifp;
10170 struct listnode *node;
10171
10172 if (argc == 4) /* Clear all the ospfv2 interfaces. */
10173 {
10174 for (ALL_LIST_ELEMENTS_RO (vrf_iflist (VRF_DEFAULT), node, ifp))
10175 ospf_interface_clear(ifp);
10176 }
10177 else /* Interface name is specified. */
10178 {
10179 if ((ifp = if_lookup_by_name (argv[idx_ifname]->text)) == NULL)
10180 vty_out (vty, "No such interface name%s", VTY_NEWLINE);
10181 else
10182 ospf_interface_clear(ifp);
10183 }
10184
10185 return CMD_SUCCESS;
10186 }
10187
10188 void
10189 ospf_vty_clear_init (void)
10190 {
10191 install_element (ENABLE_NODE, &clear_ip_ospf_interface_cmd);
10192 }
10193
10194
10195 /* Install OSPF related vty commands. */
10196 void
10197 ospf_vty_init (void)
10198 {
10199 /* Install ospf top node. */
10200 install_node (&ospf_node, ospf_config_write);
10201
10202 /* "router ospf" commands. */
10203 install_element (CONFIG_NODE, &router_ospf_cmd);
10204 install_element (CONFIG_NODE, &no_router_ospf_cmd);
10205
10206
10207 install_default (OSPF_NODE);
10208
10209 /* "ospf router-id" commands. */
10210 install_element (OSPF_NODE, &ospf_router_id_cmd);
10211 install_element (OSPF_NODE, &ospf_router_id_old_cmd);
10212 install_element (OSPF_NODE, &no_ospf_router_id_cmd);
10213
10214 /* "passive-interface" commands. */
10215 install_element (OSPF_NODE, &ospf_passive_interface_addr_cmd);
10216 install_element (OSPF_NODE, &no_ospf_passive_interface_addr_cmd);
10217
10218 /* "ospf abr-type" commands. */
10219 install_element (OSPF_NODE, &ospf_abr_type_cmd);
10220 install_element (OSPF_NODE, &no_ospf_abr_type_cmd);
10221
10222 /* "ospf log-adjacency-changes" commands. */
10223 install_element (OSPF_NODE, &ospf_log_adjacency_changes_cmd);
10224 install_element (OSPF_NODE, &ospf_log_adjacency_changes_detail_cmd);
10225 install_element (OSPF_NODE, &no_ospf_log_adjacency_changes_cmd);
10226 install_element (OSPF_NODE, &no_ospf_log_adjacency_changes_detail_cmd);
10227
10228 /* "ospf rfc1583-compatible" commands. */
10229 install_element (OSPF_NODE, &ospf_compatible_rfc1583_cmd);
10230 install_element (OSPF_NODE, &no_ospf_compatible_rfc1583_cmd);
10231 install_element (OSPF_NODE, &ospf_rfc1583_flag_cmd);
10232 install_element (OSPF_NODE, &no_ospf_rfc1583_flag_cmd);
10233
10234 /* "network area" commands. */
10235 install_element (OSPF_NODE, &ospf_network_area_cmd);
10236 install_element (OSPF_NODE, &no_ospf_network_area_cmd);
10237
10238 /* "area authentication" commands. */
10239 install_element (OSPF_NODE, &ospf_area_authentication_message_digest_cmd);
10240 install_element (OSPF_NODE, &ospf_area_authentication_cmd);
10241 install_element (OSPF_NODE, &no_ospf_area_authentication_cmd);
10242
10243 /* "area range" commands. */
10244 install_element (OSPF_NODE, &ospf_area_range_cmd);
10245 install_element (OSPF_NODE, &ospf_area_range_cost_cmd);
10246 install_element (OSPF_NODE, &ospf_area_range_not_advertise_cmd);
10247 install_element (OSPF_NODE, &no_ospf_area_range_cmd);
10248 install_element (OSPF_NODE, &ospf_area_range_substitute_cmd);
10249 install_element (OSPF_NODE, &no_ospf_area_range_substitute_cmd);
10250
10251 /* "area virtual-link" commands. */
10252 install_element (OSPF_NODE, &ospf_area_vlink_cmd);
10253 install_element (OSPF_NODE, &ospf_area_vlink_intervals_cmd);
10254 install_element (OSPF_NODE, &no_ospf_area_vlink_cmd);
10255 install_element (OSPF_NODE, &no_ospf_area_vlink_intervals_cmd);
10256
10257
10258
10259
10260
10261
10262
10263
10264
10265
10266 /* "area stub" commands. */
10267 install_element (OSPF_NODE, &ospf_area_stub_no_summary_cmd);
10268 install_element (OSPF_NODE, &ospf_area_stub_cmd);
10269 install_element (OSPF_NODE, &no_ospf_area_stub_no_summary_cmd);
10270 install_element (OSPF_NODE, &no_ospf_area_stub_cmd);
10271
10272 /* "area nssa" commands. */
10273 install_element (OSPF_NODE, &ospf_area_nssa_cmd);
10274 install_element (OSPF_NODE, &ospf_area_nssa_translate_no_summary_cmd);
10275 install_element (OSPF_NODE, &ospf_area_nssa_translate_cmd);
10276 install_element (OSPF_NODE, &ospf_area_nssa_no_summary_cmd);
10277 install_element (OSPF_NODE, &no_ospf_area_nssa_cmd);
10278
10279 install_element (OSPF_NODE, &ospf_area_default_cost_cmd);
10280 install_element (OSPF_NODE, &no_ospf_area_default_cost_cmd);
10281
10282 install_element (OSPF_NODE, &ospf_area_shortcut_cmd);
10283 install_element (OSPF_NODE, &no_ospf_area_shortcut_cmd);
10284
10285 install_element (OSPF_NODE, &ospf_area_export_list_cmd);
10286 install_element (OSPF_NODE, &no_ospf_area_export_list_cmd);
10287
10288 install_element (OSPF_NODE, &ospf_area_filter_list_cmd);
10289 install_element (OSPF_NODE, &no_ospf_area_filter_list_cmd);
10290
10291 install_element (OSPF_NODE, &ospf_area_import_list_cmd);
10292 install_element (OSPF_NODE, &no_ospf_area_import_list_cmd);
10293
10294 /* SPF timer commands */
10295 install_element (OSPF_NODE, &ospf_timers_throttle_spf_cmd);
10296 install_element (OSPF_NODE, &no_ospf_timers_throttle_spf_cmd);
10297
10298 /* LSA timers commands */
10299 install_element (OSPF_NODE, &ospf_timers_min_ls_interval_cmd);
10300 install_element (OSPF_NODE, &no_ospf_timers_min_ls_interval_cmd);
10301 install_element (OSPF_NODE, &ospf_timers_min_ls_arrival_cmd);
10302 install_element (OSPF_NODE, &no_ospf_timers_min_ls_arrival_cmd);
10303 install_element (OSPF_NODE, &ospf_timers_lsa_cmd);
10304 install_element (OSPF_NODE, &no_ospf_timers_lsa_cmd);
10305
10306 /* refresh timer commands */
10307 install_element (OSPF_NODE, &ospf_refresh_timer_cmd);
10308 install_element (OSPF_NODE, &no_ospf_refresh_timer_val_cmd);
10309
10310 /* max-metric commands */
10311 install_element (OSPF_NODE, &ospf_max_metric_router_lsa_admin_cmd);
10312 install_element (OSPF_NODE, &no_ospf_max_metric_router_lsa_admin_cmd);
10313 install_element (OSPF_NODE, &ospf_max_metric_router_lsa_startup_cmd);
10314 install_element (OSPF_NODE, &no_ospf_max_metric_router_lsa_startup_cmd);
10315 install_element (OSPF_NODE, &ospf_max_metric_router_lsa_shutdown_cmd);
10316 install_element (OSPF_NODE, &no_ospf_max_metric_router_lsa_shutdown_cmd);
10317
10318 /* reference bandwidth commands */
10319 install_element (OSPF_NODE, &ospf_auto_cost_reference_bandwidth_cmd);
10320 install_element (OSPF_NODE, &no_ospf_auto_cost_reference_bandwidth_cmd);
10321
10322 /* "neighbor" commands. */
10323 install_element (OSPF_NODE, &ospf_neighbor_cmd);
10324 install_element (OSPF_NODE, &ospf_neighbor_poll_interval_cmd);
10325 install_element (OSPF_NODE, &no_ospf_neighbor_cmd);
10326 install_element (OSPF_NODE, &no_ospf_neighbor_poll_cmd);
10327
10328 /* write multiplier commands */
10329 install_element (OSPF_NODE, &ospf_write_multiplier_cmd);
10330 install_element (OSPF_NODE, &write_multiplier_cmd);
10331 install_element (OSPF_NODE, &no_ospf_write_multiplier_cmd);
10332 install_element (OSPF_NODE, &no_write_multiplier_cmd);
10333
10334 /* Init interface related vty commands. */
10335 ospf_vty_if_init ();
10336
10337 /* Init zebra related vty commands. */
10338 ospf_vty_zebra_init ();
10339 }