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