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