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