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