]> git.proxmox.com Git - mirror_frr.git/blob - ospfd/ospf_vty.c
*: use ->text and strmatch where appropriate
[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 (strmatch(argv[1]->text, "default"))
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 (strmatch(argv[2]->text, "default"))
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 && !strmatch(argv[i + 1]->text, "message-digest-"))
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 (no_ospf_area_vlink,
1133 no_ospf_area_vlink_cmd,
1134 "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>]",
1135 NO_STR
1136 VLINK_HELPSTR_IPADDR
1137 "Enable authentication on this virtual link\n" \
1138 "Use null authentication\n" \
1139 "Use message-digest authentication\n"
1140 "Message digest authentication password (key)\n" \
1141 "Key ID\n" \
1142 "Use MD5 algorithm\n" \
1143 "The OSPF password (key)")
1144 {
1145 VTY_DECLVAR_CONTEXT(ospf, ospf);
1146 int idx_ipv4_number = 2;
1147 int idx_ipv4 = 4;
1148 struct ospf_area *area;
1149 struct ospf_vl_config_data vl_config;
1150 struct ospf_vl_data *vl_data = NULL;
1151 char auth_key[OSPF_AUTH_SIMPLE_SIZE+1];
1152 int i;
1153 int ret, format;
1154
1155 ospf_vl_config_data_init(&vl_config, vty);
1156
1157 ret = str2area_id (argv[idx_ipv4_number]->arg, &vl_config.area_id, &format);
1158 if (ret < 0)
1159 {
1160 vty_out (vty, "OSPF area ID is invalid%s", VTY_NEWLINE);
1161 return CMD_WARNING;
1162 }
1163
1164 area = ospf_area_lookup_by_area_id (ospf, vl_config.area_id);
1165 if (!area)
1166 {
1167 vty_out (vty, "Area does not exist%s", VTY_NEWLINE);
1168 return CMD_WARNING;
1169 }
1170
1171 ret = inet_aton (argv[idx_ipv4]->arg, &vl_config.vl_peer);
1172 if (! ret)
1173 {
1174 vty_out (vty, "Please specify valid Router ID as a.b.c.d%s",
1175 VTY_NEWLINE);
1176 return CMD_WARNING;
1177 }
1178
1179 if (argc <=5)
1180 {
1181 /* Basic VLink no command */
1182 /* Thats all folks! - BUGS B. strikes again!!!*/
1183 if ((vl_data = ospf_vl_lookup (ospf, area, vl_config.vl_peer)))
1184 ospf_vl_delete (ospf, vl_data);
1185
1186 ospf_area_check_free (ospf, vl_config.area_id);
1187
1188 return CMD_SUCCESS;
1189 }
1190
1191 /* If we are down here, we are reseting parameters */
1192
1193 /* Deal with other parameters */
1194 for (i=6; i < argc; i++)
1195 {
1196 /* vty_out (vty, "argv[%d] - %s%s", i, argv[i], VTY_NEWLINE); */
1197
1198 switch (argv[i]->arg[0])
1199 {
1200
1201 case 'a':
1202 if (i > 2 || strncmp (argv[i]->text, "authentication-", 15) == 0)
1203 {
1204 /* authentication-key - this option can occur anywhere on
1205 command line. At start of command line
1206 must check for authentication option. */
1207 memset (auth_key, 0, OSPF_AUTH_SIMPLE_SIZE + 1);
1208 vl_config.auth_key = auth_key;
1209 }
1210 else if (strncmp (argv[i]->text, "authentication", 14) == 0)
1211 {
1212 /* authentication - this option can only occur at start
1213 of command line */
1214 vl_config.auth_type = OSPF_AUTH_NOTSET;
1215 }
1216 break;
1217
1218 case 'm':
1219 /* message-digest-key */
1220 /* Delete one key */
1221 i++;
1222 if (i < argc)
1223 {
1224 vl_config.crypto_key_id = strtol (argv[i]->arg, NULL, 10);
1225 if (vl_config.crypto_key_id < 0)
1226 return CMD_WARNING;
1227 vl_config.md5_key = NULL;
1228 }
1229 else
1230 return CMD_WARNING;
1231 break;
1232
1233 }
1234 }
1235
1236
1237 /* Action configuration */
1238
1239 return ospf_vl_set (ospf, &vl_config);
1240 }
1241
1242 DEFUN (ospf_area_vlink_intervals,
1243 ospf_area_vlink_intervals_cmd,
1244 "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)}",
1245 VLINK_HELPSTR_IPADDR
1246 VLINK_HELPSTR_TIME_PARAM)
1247 {
1248 VTY_DECLVAR_CONTEXT(ospf, ospf);
1249 struct ospf_vl_config_data vl_config;
1250 int ret = 0;
1251
1252 ospf_vl_config_data_init(&vl_config, vty);
1253
1254 char *area_id = argv[1]->arg;
1255 char *router_id = argv[3]->arg;
1256
1257 ret = str2area_id (area_id, &vl_config.area_id, &vl_config.area_id_fmt);
1258 if (ret < 0)
1259 {
1260 vty_out (vty, "OSPF area ID is invalid%s", VTY_NEWLINE);
1261 return CMD_WARNING;
1262 }
1263
1264 ret = inet_aton (router_id, &vl_config.vl_peer);
1265 if (! ret)
1266 {
1267 vty_out (vty, "Please specify valid Router ID as a.b.c.d%s", VTY_NEWLINE);
1268 return CMD_WARNING;
1269 }
1270
1271 for (int idx = 4; idx < argc; idx++)
1272 {
1273 if (strmatch (argv[idx]->text, "hello-interval"))
1274 vl_config.hello_interval = strtol(argv[++idx]->arg, NULL, 10);
1275 else if (strmatch (argv[idx]->text, "retransmit-interval"))
1276 vl_config.retransmit_interval = strtol(argv[++idx]->arg, NULL, 10);
1277 else if (strmatch (argv[idx]->text, "transmit-delay"))
1278 vl_config.transmit_delay = strtol(argv[++idx]->arg, NULL, 10);
1279 else if (strmatch (argv[idx]->text, "dead-interval"))
1280 vl_config.dead_interval = strtol(argv[++idx]->arg, NULL, 10);
1281 }
1282
1283 /* Action configuration */
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 < 5)
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 < 4)
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 < 6)
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 < 4)
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_msg(ospf_ism_state_msg, oi->state, NULL));
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_msg(ospf_ism_state_msg, oi->state, NULL),
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 }
3539
3540 if (ospf->instance)
3541 {
3542 if (use_json)
3543 json_object_int_add(json, "ospfInstance", ospf->instance);
3544 else
3545 vty_out (vty, "%sOSPF Instance: %d%s%s", VTY_NEWLINE, ospf->instance,
3546 VTY_NEWLINE, VTY_NEWLINE);
3547 }
3548
3549 if (argc == iface_argv)
3550 {
3551 /* Show All Interfaces.*/
3552 for (ALL_LIST_ELEMENTS_RO (vrf_iflist (VRF_DEFAULT), node, ifp))
3553 {
3554 if (ospf_oi_count(ifp))
3555 {
3556 if (use_json)
3557 json_interface_sub = json_object_new_object();
3558
3559 show_ip_ospf_interface_sub (vty, ospf, ifp, json_interface_sub, use_json);
3560
3561 if (use_json)
3562 json_object_object_add (json, ifp->name, json_interface_sub);
3563 }
3564 }
3565 }
3566 else
3567 {
3568 /* Interface name is specified. */
3569 if ((ifp = if_lookup_by_name (argv[iface_argv]->arg, VRF_DEFAULT)) == NULL)
3570 {
3571 if (use_json)
3572 json_object_boolean_true_add(json, "noSuchIface");
3573 else
3574 vty_out (vty, "No such interface name%s", VTY_NEWLINE);
3575 }
3576 else
3577 {
3578 if (use_json)
3579 json_interface_sub = json_object_new_object();
3580
3581 show_ip_ospf_interface_sub (vty, ospf, ifp, json_interface_sub, use_json);
3582
3583 if (use_json)
3584 json_object_object_add(json, ifp->name, json_interface_sub);
3585 }
3586 }
3587
3588 if (use_json)
3589 {
3590 vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTY_NEWLINE);
3591 json_object_free(json);
3592 }
3593 else
3594 vty_out (vty, "%s", VTY_NEWLINE);
3595
3596 return CMD_SUCCESS;
3597 }
3598
3599 DEFUN (show_ip_ospf_interface,
3600 show_ip_ospf_interface_cmd,
3601 "show ip ospf interface [INTERFACE] [json]",
3602 SHOW_STR
3603 IP_STR
3604 "OSPF information\n"
3605 "Interface information\n"
3606 "Interface name\n"
3607 JSON_STR)
3608 {
3609 struct ospf *ospf;
3610 u_char uj = use_json(argc, argv);
3611
3612 if ((ospf = ospf_lookup()) == NULL || !ospf->oi_running)
3613 return CMD_SUCCESS;
3614
3615 if (uj)
3616 argc--;
3617
3618 return show_ip_ospf_interface_common(vty, ospf, argc, argv, 4, uj);
3619 }
3620
3621 DEFUN (show_ip_ospf_instance_interface,
3622 show_ip_ospf_instance_interface_cmd,
3623 "show ip ospf (1-65535) interface [INTERFACE] [json]",
3624 SHOW_STR
3625 IP_STR
3626 "OSPF information\n"
3627 "Instance ID\n"
3628 "Interface information\n"
3629 "Interface name\n"
3630 JSON_STR)
3631 {
3632 int idx_number = 3;
3633 struct ospf *ospf;
3634 u_short instance = 0;
3635 u_char uj = use_json(argc, argv);
3636
3637 VTY_GET_INTEGER ("Instance", instance, argv[idx_number]->arg);
3638 if ((ospf = ospf_lookup_instance (instance)) == NULL || !ospf->oi_running)
3639 return CMD_SUCCESS;
3640
3641 if (uj)
3642 argc--;
3643
3644 return show_ip_ospf_interface_common(vty, ospf, argc, argv, 5, uj);
3645 }
3646
3647 static void
3648 show_ip_ospf_neighbour_header (struct vty *vty)
3649 {
3650 vty_out (vty, "%s%-15s %3s %-15s %9s %-15s %-20s %5s %5s %5s%s",
3651 VTY_NEWLINE,
3652 "Neighbor ID", "Pri", "State", "Dead Time",
3653 "Address", "Interface", "RXmtL", "RqstL", "DBsmL",
3654 VTY_NEWLINE);
3655 }
3656
3657 static void
3658 show_ip_ospf_neighbor_sub (struct vty *vty, struct ospf_interface *oi, json_object *json, u_char use_json)
3659 {
3660 struct route_node *rn;
3661 struct ospf_neighbor *nbr;
3662 char msgbuf[16];
3663 char timebuf[OSPF_TIME_DUMP_SIZE];
3664 json_object *json_neighbor = NULL;
3665
3666 for (rn = route_top (oi->nbrs); rn; rn = route_next (rn))
3667 {
3668 if ((nbr = rn->info))
3669 {
3670 /* Do not show myself. */
3671 if (nbr != oi->nbr_self)
3672 {
3673 /* Down state is not shown. */
3674 if (nbr->state != NSM_Down)
3675 {
3676 if (use_json)
3677 {
3678 json_neighbor = json_object_new_object();
3679 ospf_nbr_state_message (nbr, msgbuf, 16);
3680
3681 long time_store;
3682
3683 time_store = monotime_until(&nbr->t_inactivity->u.sands, NULL) / 1000LL;
3684
3685 json_object_int_add (json_neighbor, "priority", nbr->priority);
3686 json_object_string_add (json_neighbor, "state", msgbuf);
3687 json_object_int_add (json_neighbor, "deadTimeMsecs", time_store);
3688 json_object_string_add (json_neighbor, "address", inet_ntoa (nbr->src));
3689 json_object_string_add (json_neighbor, "ifaceName", IF_NAME (oi));
3690 json_object_int_add (json_neighbor, "retransmitCounter", ospf_ls_retransmit_count (nbr));
3691 json_object_int_add (json_neighbor, "requestCounter", ospf_ls_request_count (nbr));
3692 json_object_int_add (json_neighbor, "dbSummaryCounter", ospf_db_summary_count (nbr));
3693 if (nbr->state == NSM_Attempt && nbr->router_id.s_addr == 0)
3694 json_object_object_add(json, "neighbor", json_neighbor);
3695 else
3696 json_object_object_add(json, inet_ntoa (nbr->router_id), json_neighbor);
3697 }
3698 else
3699 {
3700 ospf_nbr_state_message (nbr, msgbuf, 16);
3701
3702 if (nbr->state == NSM_Attempt && nbr->router_id.s_addr == 0)
3703 vty_out (vty, "%-15s %3d %-15s ",
3704 "-", nbr->priority,
3705 msgbuf);
3706 else
3707 vty_out (vty, "%-15s %3d %-15s ",
3708 inet_ntoa (nbr->router_id), nbr->priority,
3709 msgbuf);
3710
3711 vty_out (vty, "%9s ",
3712 ospf_timer_dump (nbr->t_inactivity, timebuf,
3713 sizeof(timebuf)));
3714 vty_out (vty, "%-15s ", inet_ntoa (nbr->src));
3715 vty_out (vty, "%-20s %5ld %5ld %5d%s",
3716 IF_NAME (oi), ospf_ls_retransmit_count (nbr),
3717 ospf_ls_request_count (nbr), ospf_db_summary_count (nbr),
3718 VTY_NEWLINE);
3719 }
3720 }
3721 }
3722 }
3723 }
3724 }
3725
3726 static int
3727 show_ip_ospf_neighbor_common (struct vty *vty, struct ospf *ospf, u_char use_json)
3728 {
3729 struct ospf_interface *oi;
3730 struct listnode *node;
3731 json_object *json = NULL;
3732
3733 if (use_json)
3734 json = json_object_new_object();
3735 else
3736 show_ip_ospf_neighbour_header (vty);
3737
3738 if (ospf->instance)
3739 {
3740 if (use_json)
3741 json_object_int_add(json, "ospfInstance", ospf->instance);
3742 else
3743 vty_out (vty, "%sOSPF Instance: %d%s%s", VTY_NEWLINE, ospf->instance,
3744 VTY_NEWLINE, VTY_NEWLINE);
3745 }
3746
3747 for (ALL_LIST_ELEMENTS_RO (ospf->oiflist, node, oi))
3748 show_ip_ospf_neighbor_sub (vty, oi, json, use_json);
3749
3750 if (use_json)
3751 {
3752 vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTY_NEWLINE);
3753 json_object_free(json);
3754 }
3755 else
3756 vty_out (vty, "%s", VTY_NEWLINE);
3757
3758 return CMD_SUCCESS;
3759 }
3760
3761 DEFUN (show_ip_ospf_neighbor,
3762 show_ip_ospf_neighbor_cmd,
3763 "show ip ospf neighbor [json]",
3764 SHOW_STR
3765 IP_STR
3766 "OSPF information\n"
3767 "Neighbor list\n"
3768 JSON_STR)
3769 {
3770 struct ospf *ospf;
3771 u_char uj = use_json(argc, argv);
3772
3773 if ((ospf = ospf_lookup()) == NULL || !ospf->oi_running)
3774 return CMD_SUCCESS;
3775
3776 return show_ip_ospf_neighbor_common(vty, ospf, uj);
3777 }
3778
3779
3780 DEFUN (show_ip_ospf_instance_neighbor,
3781 show_ip_ospf_instance_neighbor_cmd,
3782 "show ip ospf (1-65535) neighbor [json]",
3783 SHOW_STR
3784 IP_STR
3785 "OSPF information\n"
3786 "Instance ID\n"
3787 "Neighbor list\n"
3788 JSON_STR)
3789 {
3790 int idx_number = 3;
3791 struct ospf *ospf;
3792 u_short instance = 0;
3793 u_char uj = use_json(argc, argv);
3794
3795 VTY_GET_INTEGER ("Instance", instance, argv[idx_number]->arg);
3796 if ((ospf = ospf_lookup_instance(instance)) == NULL || !ospf->oi_running)
3797 return CMD_SUCCESS;
3798
3799 return show_ip_ospf_neighbor_common(vty, ospf, uj);
3800 }
3801
3802 static int
3803 show_ip_ospf_neighbor_all_common (struct vty *vty, struct ospf *ospf, u_char use_json)
3804 {
3805 struct listnode *node;
3806 struct ospf_interface *oi;
3807 json_object *json = NULL;
3808 json_object *json_neighbor_sub = NULL;
3809
3810 if (use_json)
3811 {
3812 json = json_object_new_object();
3813 json_neighbor_sub = json_object_new_object();
3814 }
3815 else
3816 show_ip_ospf_neighbour_header (vty);
3817
3818 if (ospf->instance)
3819 {
3820 if (use_json)
3821 json_object_int_add(json, "ospfInstance", ospf->instance);
3822 else
3823 vty_out (vty, "%sOSPF Instance: %d%s%s", VTY_NEWLINE, ospf->instance,
3824 VTY_NEWLINE, VTY_NEWLINE);
3825 }
3826
3827 for (ALL_LIST_ELEMENTS_RO (ospf->oiflist, node, oi))
3828 {
3829 struct listnode *nbr_node;
3830 struct ospf_nbr_nbma *nbr_nbma;
3831
3832 show_ip_ospf_neighbor_sub (vty, oi, json, use_json);
3833
3834 /* print Down neighbor status */
3835 for (ALL_LIST_ELEMENTS_RO (oi->nbr_nbma, nbr_node, nbr_nbma))
3836 {
3837 if (nbr_nbma->nbr == NULL
3838 || nbr_nbma->nbr->state == NSM_Down)
3839 {
3840 if (use_json)
3841 {
3842 json_object_int_add (json_neighbor_sub, "nbrNbmaPriority", nbr_nbma->priority);
3843 json_object_boolean_true_add (json_neighbor_sub, "nbrNbmaDown");
3844 json_object_string_add (json_neighbor_sub, "nbrNbmaIfaceName", IF_NAME (oi));
3845 json_object_int_add (json_neighbor_sub, "nbrNbmaRetransmitCounter", 0);
3846 json_object_int_add (json_neighbor_sub, "nbrNbmaRequestCounter", 0);
3847 json_object_int_add (json_neighbor_sub, "nbrNbmaDbSummaryCounter", 0);
3848 json_object_object_add(json, inet_ntoa (nbr_nbma->addr), json_neighbor_sub);
3849 }
3850 else
3851 {
3852 vty_out (vty, "%-15s %3d %-15s %9s ",
3853 "-", nbr_nbma->priority, "Down", "-");
3854 vty_out (vty, "%-15s %-20s %5d %5d %5d%s",
3855 inet_ntoa (nbr_nbma->addr), IF_NAME (oi),
3856 0, 0, 0, VTY_NEWLINE);
3857 }
3858 }
3859 }
3860 }
3861
3862 if (use_json)
3863 {
3864 vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTY_NEWLINE);
3865 json_object_free(json);
3866 }
3867 else
3868 vty_out (vty, "%s", VTY_NEWLINE);
3869
3870 return CMD_SUCCESS;
3871 }
3872
3873 DEFUN (show_ip_ospf_neighbor_all,
3874 show_ip_ospf_neighbor_all_cmd,
3875 "show ip ospf neighbor all [json]",
3876 SHOW_STR
3877 IP_STR
3878 "OSPF information\n"
3879 "Neighbor list\n"
3880 "include down status neighbor\n"
3881 JSON_STR)
3882 {
3883 struct ospf *ospf;
3884 u_char uj = use_json(argc, argv);
3885
3886 if ((ospf = ospf_lookup()) == NULL || !ospf->oi_running)
3887 return CMD_SUCCESS;
3888
3889 return show_ip_ospf_neighbor_all_common(vty, ospf, uj);
3890 }
3891
3892 DEFUN (show_ip_ospf_instance_neighbor_all,
3893 show_ip_ospf_instance_neighbor_all_cmd,
3894 "show ip ospf (1-65535) neighbor all [json]",
3895 SHOW_STR
3896 IP_STR
3897 "OSPF information\n"
3898 "Instance ID\n"
3899 "Neighbor list\n"
3900 "include down status neighbor\n"
3901 JSON_STR)
3902 {
3903 int idx_number = 3;
3904 struct ospf *ospf;
3905 u_short instance = 0;
3906 u_char uj = use_json(argc, argv);
3907
3908 VTY_GET_INTEGER ("Instance", instance, argv[idx_number]->arg);
3909 if ((ospf = ospf_lookup_instance(instance)) == NULL || !ospf->oi_running)
3910 return CMD_SUCCESS;
3911
3912 return show_ip_ospf_neighbor_all_common(vty, ospf, uj);
3913 }
3914
3915 static int
3916 show_ip_ospf_neighbor_int_common (struct vty *vty, struct ospf *ospf, int arg_base,
3917 struct cmd_token **argv, u_char use_json)
3918 {
3919 struct interface *ifp;
3920 struct route_node *rn;
3921 json_object *json = NULL;
3922
3923 if (use_json)
3924 json = json_object_new_object();
3925 else
3926 show_ip_ospf_neighbour_header (vty);
3927
3928 if (ospf->instance)
3929 {
3930 if (use_json)
3931 json_object_int_add(json, "ospfInstance", ospf->instance);
3932 else
3933 vty_out (vty, "%sOSPF Instance: %d%s%s", VTY_NEWLINE, ospf->instance,
3934 VTY_NEWLINE, VTY_NEWLINE);
3935 }
3936
3937 ifp = if_lookup_by_name (argv[arg_base]->arg, VRF_DEFAULT);
3938 if (!ifp)
3939 {
3940 if (use_json)
3941 json_object_boolean_true_add(json, "noSuchIface");
3942 else
3943 vty_out (vty, "No such interface.%s", VTY_NEWLINE);
3944 return CMD_WARNING;
3945 }
3946
3947 for (rn = route_top (IF_OIFS (ifp)); rn; rn = route_next (rn))
3948 {
3949 struct ospf_interface *oi = rn->info;
3950
3951 if (oi == NULL)
3952 continue;
3953
3954 show_ip_ospf_neighbor_sub (vty, oi, json, use_json);
3955 }
3956
3957 if (use_json)
3958 {
3959 vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTY_NEWLINE);
3960 json_object_free(json);
3961 }
3962 else
3963 vty_out (vty, "%s", VTY_NEWLINE);
3964
3965 return CMD_SUCCESS;
3966 }
3967
3968 DEFUN (show_ip_ospf_neighbor_int,
3969 show_ip_ospf_neighbor_int_cmd,
3970 "show ip ospf neighbor IFNAME [json]",
3971 SHOW_STR
3972 IP_STR
3973 "OSPF information\n"
3974 "Neighbor list\n"
3975 "Interface name\n"
3976 JSON_STR)
3977 {
3978 struct ospf *ospf;
3979 u_char uj = use_json(argc, argv);
3980
3981 if ((ospf = ospf_lookup()) == NULL || !ospf->oi_running)
3982 return CMD_SUCCESS;
3983
3984 return show_ip_ospf_neighbor_int_common(vty, ospf, 0, argv, uj);
3985 }
3986
3987 DEFUN (show_ip_ospf_instance_neighbor_int,
3988 show_ip_ospf_instance_neighbor_int_cmd,
3989 "show ip ospf (1-65535) neighbor IFNAME [json]",
3990 SHOW_STR
3991 IP_STR
3992 "OSPF information\n"
3993 "Instance ID\n"
3994 "Neighbor list\n"
3995 "Interface name\n"
3996 JSON_STR)
3997 {
3998 int idx_number = 3;
3999 struct ospf *ospf;
4000 u_short instance = 0;
4001 u_char uj = use_json(argc, argv);
4002
4003 VTY_GET_INTEGER ("Instance", instance, argv[idx_number]->arg);
4004 if ((ospf = ospf_lookup_instance(instance)) == NULL || !ospf->oi_running)
4005 return CMD_SUCCESS;
4006
4007 return show_ip_ospf_neighbor_int_common(vty, ospf, 1, argv, uj);
4008 }
4009
4010 static void
4011 show_ip_ospf_nbr_nbma_detail_sub (struct vty *vty, struct ospf_interface *oi, struct ospf_nbr_nbma *nbr_nbma,
4012 u_char use_json, json_object *json)
4013 {
4014 char timebuf[OSPF_TIME_DUMP_SIZE];
4015 json_object *json_sub = NULL;
4016
4017 if (use_json)
4018 json_sub = json_object_new_object();
4019 else /* Show neighbor ID. */
4020 vty_out (vty, " Neighbor %s,", "-");
4021
4022 /* Show interface address. */
4023 if (use_json)
4024 json_object_string_add(json_sub, "ifaceAddress", inet_ntoa (nbr_nbma->addr));
4025 else
4026 vty_out (vty, " interface address %s%s",
4027 inet_ntoa (nbr_nbma->addr), VTY_NEWLINE);
4028
4029 /* Show Area ID. */
4030 if (use_json)
4031 {
4032 json_object_string_add(json_sub, "areaId", ospf_area_desc_string (oi->area));
4033 json_object_string_add(json_sub, "iface", IF_NAME (oi));
4034 }
4035 else
4036 vty_out (vty, " In the area %s via interface %s%s",
4037 ospf_area_desc_string (oi->area), IF_NAME (oi), VTY_NEWLINE);
4038
4039 /* Show neighbor priority and state. */
4040 if (use_json)
4041 {
4042 json_object_int_add(json_sub, "nbrPriority", nbr_nbma->priority);
4043 json_object_string_add(json_sub, "nbrState", "down");
4044 }
4045 else
4046 vty_out (vty, " Neighbor priority is %d, State is %s,",
4047 nbr_nbma->priority, "Down");
4048
4049 /* Show state changes. */
4050 if (use_json)
4051 json_object_int_add(json_sub, "stateChangeCounter", nbr_nbma->state_change);
4052 else
4053 vty_out (vty, " %d state changes%s", nbr_nbma->state_change, VTY_NEWLINE);
4054
4055 /* Show PollInterval */
4056 if (use_json)
4057 json_object_int_add(json_sub, "pollInterval", nbr_nbma->v_poll);
4058 else
4059 vty_out (vty, " Poll interval %d%s", nbr_nbma->v_poll, VTY_NEWLINE);
4060
4061 /* Show poll-interval timer. */
4062 if (use_json)
4063 {
4064 long time_store;
4065 time_store = monotime_until(&nbr_nbma->t_poll->u.sands, NULL) / 1000LL;
4066 json_object_int_add(json_sub, "pollIntervalTimerDueMsec", time_store);
4067 }
4068 else
4069 vty_out (vty, " Poll timer due in %s%s",
4070 ospf_timer_dump (nbr_nbma->t_poll, timebuf, sizeof(timebuf)),
4071 VTY_NEWLINE);
4072
4073 /* Show poll-interval timer thread. */
4074 if (use_json)
4075 {
4076 if (nbr_nbma->t_poll != NULL)
4077 json_object_string_add(json_sub, "pollIntervalTimerThread", "on");
4078 }
4079 else
4080 vty_out (vty, " Thread Poll Timer %s%s",
4081 nbr_nbma->t_poll != NULL ? "on" : "off", VTY_NEWLINE);
4082
4083 if (use_json)
4084 json_object_object_add(json, "noNbrId", json_sub);
4085 }
4086
4087 static void
4088 show_ip_ospf_neighbor_detail_sub (struct vty *vty, struct ospf_interface *oi,
4089 struct ospf_neighbor *nbr, u_char use_json, json_object *json)
4090 {
4091 char timebuf[OSPF_TIME_DUMP_SIZE];
4092 json_object *json_sub = NULL;
4093
4094 if (use_json)
4095 json_sub = json_object_new_object();
4096 else
4097 {
4098 /* Show neighbor ID. */
4099 if (nbr->state == NSM_Attempt && nbr->router_id.s_addr == 0)
4100 vty_out (vty, " Neighbor %s,", "-");
4101 else
4102 vty_out (vty, " Neighbor %s,", inet_ntoa (nbr->router_id));
4103 }
4104
4105 /* Show interface address. */
4106 if (use_json)
4107 json_object_string_add(json_sub, "ifaceAddress", inet_ntoa (nbr->address.u.prefix4));
4108 else
4109 vty_out (vty, " interface address %s%s",
4110 inet_ntoa (nbr->address.u.prefix4), VTY_NEWLINE);
4111
4112 /* Show Area ID. */
4113 if (use_json)
4114 {
4115 json_object_string_add(json_sub, "areaId", ospf_area_desc_string (oi->area));
4116 json_object_string_add(json_sub, "ifaceName", oi->ifp->name);
4117 }
4118 else
4119 vty_out (vty, " In the area %s via interface %s%s",
4120 ospf_area_desc_string (oi->area), oi->ifp->name, VTY_NEWLINE);
4121
4122 /* Show neighbor priority and state. */
4123 if (use_json)
4124 {
4125 json_object_int_add(json_sub, "nbrPriority", nbr->priority);
4126 json_object_string_add(json_sub, "nbrState", lookup_msg(ospf_nsm_state_msg, nbr->state, NULL));
4127 }
4128 else
4129 vty_out (vty, " Neighbor priority is %d, State is %s,",
4130 nbr->priority, lookup_msg(ospf_nsm_state_msg, nbr->state, NULL));
4131
4132 /* Show state changes. */
4133 if (use_json)
4134 json_object_int_add(json_sub, "stateChangeCounter", nbr->state_change);
4135 else
4136 vty_out (vty, " %d state changes%s", nbr->state_change, VTY_NEWLINE);
4137
4138 if (nbr->ts_last_progress.tv_sec || nbr->ts_last_progress.tv_usec)
4139 {
4140 struct timeval res;
4141 long time_store;
4142
4143 time_store = monotime_since(&nbr->ts_last_progress, &res) / 1000LL;
4144 if (use_json)
4145 {
4146 json_object_int_add(json_sub, "lastPrgrsvChangeMsec", time_store);
4147 }
4148 else
4149 {
4150 vty_out (vty, " Most recent state change statistics:%s",
4151 VTY_NEWLINE);
4152 vty_out (vty, " Progressive change %s ago%s",
4153 ospf_timeval_dump (&res, timebuf, sizeof(timebuf)),
4154 VTY_NEWLINE);
4155 }
4156 }
4157
4158 if (nbr->ts_last_regress.tv_sec || nbr->ts_last_regress.tv_usec)
4159 {
4160 struct timeval res;
4161 long time_store;
4162
4163 time_store = monotime_since(&nbr->ts_last_regress, &res) / 1000LL;
4164 if (use_json)
4165 {
4166 json_object_int_add(json_sub, "lastRegressiveChangeMsec", time_store);
4167 if (nbr->last_regress_str)
4168 json_object_string_add(json_sub, "lastRegressiveChangeReason", nbr->last_regress_str);
4169 }
4170 else
4171 {
4172 vty_out (vty, " Regressive change %s ago, due to %s%s",
4173 ospf_timeval_dump (&res, timebuf, sizeof(timebuf)),
4174 (nbr->last_regress_str ? nbr->last_regress_str : "??"),
4175 VTY_NEWLINE);
4176 }
4177 }
4178
4179 /* Show Designated Rotuer ID. */
4180 if (use_json)
4181 json_object_string_add(json_sub, "routerDesignatedId", inet_ntoa (nbr->d_router));
4182 else
4183 vty_out (vty, " DR is %s,", inet_ntoa (nbr->d_router));
4184
4185 /* Show Backup Designated Rotuer ID. */
4186 if (use_json)
4187 json_object_string_add(json_sub, "routerDesignatedBackupId", inet_ntoa (nbr->bd_router));
4188 else
4189 vty_out (vty, " BDR is %s%s", inet_ntoa (nbr->bd_router), VTY_NEWLINE);
4190
4191 /* Show options. */
4192 if (use_json)
4193 {
4194 json_object_int_add(json_sub, "optionsCounter", nbr->options);
4195 json_object_string_add(json_sub, "optionsList", ospf_options_dump (nbr->options));
4196 }
4197 else
4198 vty_out (vty, " Options %d %s%s", nbr->options,
4199 ospf_options_dump (nbr->options), VTY_NEWLINE);
4200
4201 /* Show Router Dead interval timer. */
4202 if (use_json)
4203 {
4204 if (nbr->t_inactivity)
4205 {
4206 long time_store;
4207 time_store = monotime_until(&nbr->t_inactivity->u.sands, NULL) / 1000LL;
4208 json_object_int_add(json_sub, "routerDeadIntervalTimerDueMsec", time_store);
4209 }
4210 else
4211 json_object_int_add(json_sub, "routerDeadIntervalTimerDueMsec", -1);
4212 }
4213 else
4214 vty_out (vty, " Dead timer due in %s%s",
4215 ospf_timer_dump (nbr->t_inactivity, timebuf, sizeof (timebuf)),
4216 VTY_NEWLINE);
4217
4218 /* Show Database Summary list. */
4219 if (use_json)
4220 json_object_int_add(json_sub, "databaseSummaryListCounter", ospf_db_summary_count (nbr));
4221 else
4222 vty_out (vty, " Database Summary List %d%s",
4223 ospf_db_summary_count (nbr), VTY_NEWLINE);
4224
4225 /* Show Link State Request list. */
4226 if (use_json)
4227 json_object_int_add(json_sub, "linkStateRequestListCounter", ospf_ls_request_count (nbr));
4228 else
4229 vty_out (vty, " Link State Request List %ld%s",
4230 ospf_ls_request_count (nbr), VTY_NEWLINE);
4231
4232 /* Show Link State Retransmission list. */
4233 if (use_json)
4234 json_object_int_add(json_sub, "linkStateRetransmissionListCounter", ospf_ls_retransmit_count (nbr));
4235 else
4236 vty_out (vty, " Link State Retransmission List %ld%s",
4237 ospf_ls_retransmit_count (nbr), VTY_NEWLINE);
4238
4239 /* Show inactivity timer thread. */
4240 if (use_json)
4241 {
4242 if (nbr->t_inactivity != NULL)
4243 json_object_string_add(json_sub, "threadInactivityTimer", "on");
4244 }
4245 else
4246 vty_out (vty, " Thread Inactivity Timer %s%s",
4247 nbr->t_inactivity != NULL ? "on" : "off", VTY_NEWLINE);
4248
4249 /* Show Database Description retransmission thread. */
4250 if (use_json)
4251 {
4252 if (nbr->t_db_desc != NULL)
4253 json_object_string_add(json_sub, "threadDatabaseDescriptionRetransmission", "on");
4254 }
4255 else
4256 vty_out (vty, " Thread Database Description Retransmision %s%s",
4257 nbr->t_db_desc != NULL ? "on" : "off", VTY_NEWLINE);
4258
4259 /* Show Link State Request Retransmission thread. */
4260 if (use_json)
4261 {
4262 if (nbr->t_ls_req != NULL)
4263 json_object_string_add(json_sub, "threadLinkStateRequestRetransmission", "on");
4264 }
4265 else
4266 vty_out (vty, " Thread Link State Request Retransmission %s%s",
4267 nbr->t_ls_req != NULL ? "on" : "off", VTY_NEWLINE);
4268
4269 /* Show Link State Update Retransmission thread. */
4270 if (use_json)
4271 {
4272 if (nbr->t_ls_upd != NULL)
4273 json_object_string_add(json_sub, "threadLinkStateUpdateRetransmission", "on");
4274 }
4275 else
4276 vty_out (vty, " Thread Link State Update Retransmission %s%s%s",
4277 nbr->t_ls_upd != NULL ? "on" : "off", VTY_NEWLINE, VTY_NEWLINE);
4278
4279 if (use_json)
4280 {
4281 if (nbr->state == NSM_Attempt && nbr->router_id.s_addr == 0)
4282 json_object_object_add(json, "noNbrId", json_sub);
4283 else
4284 json_object_object_add(json, inet_ntoa (nbr->router_id), json_sub);
4285 }
4286
4287 ospf_bfd_show_info(vty, nbr->bfd_info, json, use_json, 0);
4288 }
4289
4290 static int
4291 show_ip_ospf_neighbor_id_common (struct vty *vty, struct ospf *ospf,
4292 int arg_base, struct cmd_token **argv, u_char use_json)
4293 {
4294 struct listnode *node;
4295 struct ospf_neighbor *nbr;
4296 struct ospf_interface *oi;
4297 struct in_addr router_id;
4298 int ret;
4299 json_object *json = NULL;
4300
4301 if (use_json)
4302 json = json_object_new_object();
4303
4304 if (ospf->instance)
4305 {
4306 if (use_json)
4307 json_object_int_add(json, "ospfInstance", ospf->instance);
4308 else
4309 vty_out (vty, "%sOSPF Instance: %d%s%s", VTY_NEWLINE, ospf->instance,
4310 VTY_NEWLINE, VTY_NEWLINE);
4311 }
4312
4313 ret = inet_aton (argv[arg_base]->arg, &router_id);
4314 if (!ret)
4315 {
4316 if (!use_json)
4317 vty_out (vty, "Please specify Neighbor ID by A.B.C.D%s", VTY_NEWLINE);
4318 return CMD_WARNING;
4319 }
4320
4321 for (ALL_LIST_ELEMENTS_RO (ospf->oiflist, node, oi))
4322 {
4323 if ((nbr = ospf_nbr_lookup_by_routerid (oi->nbrs, &router_id)))
4324 {
4325 show_ip_ospf_neighbor_detail_sub (vty, oi, nbr, use_json, json);
4326 }
4327 }
4328
4329 if (use_json)
4330 {
4331 vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTY_NEWLINE);
4332 json_object_free(json);
4333 }
4334 else
4335 vty_out (vty, "%s", VTY_NEWLINE);
4336
4337 return CMD_SUCCESS;
4338 }
4339
4340 DEFUN (show_ip_ospf_neighbor_id,
4341 show_ip_ospf_neighbor_id_cmd,
4342 "show ip ospf neighbor A.B.C.D [json]",
4343 SHOW_STR
4344 IP_STR
4345 "OSPF information\n"
4346 "Neighbor list\n"
4347 "Neighbor ID\n"
4348 JSON_STR)
4349 {
4350 struct ospf *ospf;
4351 u_char uj = use_json(argc, argv);
4352
4353 if ((ospf = ospf_lookup()) == NULL || !ospf->oi_running)
4354 return CMD_SUCCESS;
4355
4356 return show_ip_ospf_neighbor_id_common(vty, ospf, 0, argv, uj);
4357 }
4358
4359 DEFUN (show_ip_ospf_instance_neighbor_id,
4360 show_ip_ospf_instance_neighbor_id_cmd,
4361 "show ip ospf (1-65535) neighbor A.B.C.D [json]",
4362 SHOW_STR
4363 IP_STR
4364 "OSPF information\n"
4365 "Instance ID\n"
4366 "Neighbor list\n"
4367 "Neighbor ID\n"
4368 JSON_STR)
4369 {
4370 int idx_number = 3;
4371 struct ospf *ospf;
4372 u_short instance = 0;
4373 u_char uj = use_json(argc, argv);
4374
4375 VTY_GET_INTEGER ("Instance", instance, argv[idx_number]->arg);
4376 if ((ospf = ospf_lookup_instance(instance)) == NULL || !ospf->oi_running)
4377 return CMD_SUCCESS;
4378
4379 return show_ip_ospf_neighbor_id_common(vty, ospf, 1, argv, uj);
4380 }
4381
4382 static int
4383 show_ip_ospf_neighbor_detail_common (struct vty *vty, struct ospf *ospf, u_char use_json)
4384 {
4385 struct ospf_interface *oi;
4386 struct listnode *node;
4387 json_object *json = NULL;
4388
4389 if (use_json)
4390 json = json_object_new_object();
4391
4392 if (ospf->instance)
4393 {
4394 if (use_json)
4395 json_object_int_add(json, "ospfInstance", ospf->instance);
4396 else
4397 vty_out (vty, "%sOSPF Instance: %d%s%s", VTY_NEWLINE, ospf->instance,
4398 VTY_NEWLINE, VTY_NEWLINE);
4399 }
4400
4401 for (ALL_LIST_ELEMENTS_RO (ospf->oiflist, node, oi))
4402 {
4403 struct route_node *rn;
4404 struct ospf_neighbor *nbr;
4405
4406 for (rn = route_top (oi->nbrs); rn; rn = route_next (rn))
4407 {
4408 if ((nbr = rn->info))
4409 {
4410 if (nbr != oi->nbr_self)
4411 {
4412 if (nbr->state != NSM_Down)
4413 {
4414 show_ip_ospf_neighbor_detail_sub (vty, oi, nbr, use_json, json);
4415 }
4416 }
4417 }
4418 }
4419 }
4420
4421 if (use_json)
4422 {
4423 vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTY_NEWLINE);
4424 json_object_free(json);
4425 }
4426 else
4427 vty_out (vty, "%s", VTY_NEWLINE);
4428
4429 return CMD_SUCCESS;
4430 }
4431
4432 DEFUN (show_ip_ospf_neighbor_detail,
4433 show_ip_ospf_neighbor_detail_cmd,
4434 "show ip ospf neighbor detail [json]",
4435 SHOW_STR
4436 IP_STR
4437 "OSPF information\n"
4438 "Neighbor list\n"
4439 "detail of all neighbors\n"
4440 JSON_STR)
4441 {
4442 struct ospf *ospf;
4443 u_char uj = use_json(argc, argv);
4444
4445 if ((ospf = ospf_lookup()) == NULL || !ospf->oi_running)
4446 return CMD_SUCCESS;
4447
4448 return show_ip_ospf_neighbor_detail_common(vty, ospf, uj);
4449 }
4450
4451 DEFUN (show_ip_ospf_instance_neighbor_detail,
4452 show_ip_ospf_instance_neighbor_detail_cmd,
4453 "show ip ospf (1-65535) neighbor detail [json]",
4454 SHOW_STR
4455 IP_STR
4456 "OSPF information\n"
4457 "Instance ID\n"
4458 "Neighbor list\n"
4459 "detail of all neighbors\n"
4460 JSON_STR)
4461 {
4462 int idx_number = 3;
4463 struct ospf *ospf;
4464 u_short instance = 0;
4465 u_char uj = use_json(argc, argv);
4466
4467 VTY_GET_INTEGER ("Instance", instance, argv[idx_number]->arg);
4468 if ((ospf = ospf_lookup_instance (instance)) == NULL || !ospf->oi_running)
4469 return CMD_SUCCESS;
4470
4471 return show_ip_ospf_neighbor_detail_common(vty, ospf, uj);
4472 }
4473
4474 static int
4475 show_ip_ospf_neighbor_detail_all_common (struct vty *vty, struct ospf *ospf, u_char use_json)
4476 {
4477 struct listnode *node;
4478 struct ospf_interface *oi;
4479 json_object *json = NULL;
4480
4481 if (use_json)
4482 json = json_object_new_object();
4483
4484 if (ospf->instance)
4485 {
4486 if (use_json)
4487 json_object_int_add(json, "ospfInstance", ospf->instance);
4488 else
4489 vty_out (vty, "%sOSPF Instance: %d%s%s", VTY_NEWLINE, ospf->instance,
4490 VTY_NEWLINE, VTY_NEWLINE);
4491 }
4492
4493 for (ALL_LIST_ELEMENTS_RO (ospf->oiflist, node, oi))
4494 {
4495 struct route_node *rn;
4496 struct ospf_neighbor *nbr;
4497 struct ospf_nbr_nbma *nbr_nbma;
4498
4499 for (rn = route_top (oi->nbrs); rn; rn = route_next (rn))
4500 if ((nbr = rn->info))
4501 if (nbr != oi->nbr_self)
4502 if (nbr->state != NSM_Down)
4503 show_ip_ospf_neighbor_detail_sub (vty, oi, rn->info, use_json, json);
4504
4505 if (oi->type == OSPF_IFTYPE_NBMA)
4506 {
4507 struct listnode *nd;
4508
4509 for (ALL_LIST_ELEMENTS_RO (oi->nbr_nbma, nd, nbr_nbma))
4510 {
4511 if (nbr_nbma->nbr == NULL || nbr_nbma->nbr->state == NSM_Down)
4512 show_ip_ospf_nbr_nbma_detail_sub (vty, oi, nbr_nbma, use_json, json);
4513 }
4514 }
4515 }
4516
4517 if (use_json)
4518 {
4519 vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTY_NEWLINE);
4520 json_object_free(json);
4521 }
4522 else
4523 {
4524 vty_out (vty, "%s", VTY_NEWLINE);
4525 }
4526
4527 return CMD_SUCCESS;
4528 }
4529
4530 DEFUN (show_ip_ospf_neighbor_detail_all,
4531 show_ip_ospf_neighbor_detail_all_cmd,
4532 "show ip ospf neighbor detail all [json]",
4533 SHOW_STR
4534 IP_STR
4535 "OSPF information\n"
4536 "Neighbor list\n"
4537 "detail of all neighbors\n"
4538 "include down status neighbor\n"
4539 JSON_STR)
4540 {
4541 struct ospf *ospf;
4542 u_char uj = use_json(argc, argv);
4543
4544 if ((ospf = ospf_lookup()) == NULL || !ospf->oi_running)
4545 return CMD_SUCCESS;
4546
4547 return show_ip_ospf_neighbor_detail_all_common(vty, ospf, uj);
4548 }
4549
4550 DEFUN (show_ip_ospf_instance_neighbor_detail_all,
4551 show_ip_ospf_instance_neighbor_detail_all_cmd,
4552 "show ip ospf (1-65535) neighbor detail all [json]",
4553 SHOW_STR
4554 IP_STR
4555 "OSPF information\n"
4556 "Instance ID\n"
4557 "Neighbor list\n"
4558 "detail of all neighbors\n"
4559 "include down status neighbor\n"
4560 JSON_STR)
4561 {
4562 int idx_number = 3;
4563 struct ospf *ospf;
4564 u_short instance = 0;
4565 u_char uj = use_json(argc, argv);
4566
4567 VTY_GET_INTEGER ("Instance", instance, argv[idx_number]->arg);
4568 if ((ospf = ospf_lookup_instance(instance)) == NULL || !ospf->oi_running)
4569 return CMD_SUCCESS;
4570
4571 return show_ip_ospf_neighbor_detail_all_common(vty, ospf, uj);
4572 }
4573
4574 static int
4575 show_ip_ospf_neighbor_int_detail_common (struct vty *vty, struct ospf *ospf,
4576 int arg_base, struct cmd_token **argv, u_char use_json)
4577 {
4578 struct ospf_interface *oi;
4579 struct interface *ifp;
4580 struct route_node *rn, *nrn;
4581 struct ospf_neighbor *nbr;
4582 json_object *json = NULL;
4583
4584 if (use_json)
4585 json = json_object_new_object();
4586
4587 if (ospf->instance)
4588 {
4589 if (use_json)
4590 json_object_int_add(json, "ospfInstance", ospf->instance);
4591 else
4592 vty_out (vty, "%sOSPF Instance: %d%s%s", VTY_NEWLINE, ospf->instance,
4593 VTY_NEWLINE, VTY_NEWLINE);
4594 }
4595
4596 ifp = if_lookup_by_name (argv[arg_base]->arg, VRF_DEFAULT);
4597 if (!ifp)
4598 {
4599 if (!use_json)
4600 vty_out (vty, "No such interface.%s", VTY_NEWLINE);
4601 return CMD_WARNING;
4602 }
4603
4604 for (rn = route_top (IF_OIFS (ifp)); rn; rn = route_next (rn))
4605 {
4606 if ((oi = rn->info))
4607 {
4608 for (nrn = route_top (oi->nbrs); nrn; nrn = route_next (nrn))
4609 {
4610 if ((nbr = nrn->info))
4611 {
4612 if (nbr != oi->nbr_self)
4613 {
4614 if (nbr->state != NSM_Down)
4615 show_ip_ospf_neighbor_detail_sub (vty, oi, nbr, use_json, json);
4616 }
4617 }
4618 }
4619 }
4620 }
4621
4622 if (use_json)
4623 {
4624 vty_out (vty, "%s%s", json_object_to_json_string_ext(json, JSON_C_TO_STRING_PRETTY), VTY_NEWLINE);
4625 json_object_free(json);
4626 }
4627 else
4628 vty_out (vty, "%s", VTY_NEWLINE);
4629
4630 return CMD_SUCCESS;
4631 }
4632
4633 DEFUN (show_ip_ospf_neighbor_int_detail,
4634 show_ip_ospf_neighbor_int_detail_cmd,
4635 "show ip ospf neighbor IFNAME detail [json]",
4636 SHOW_STR
4637 IP_STR
4638 "OSPF information\n"
4639 "Neighbor list\n"
4640 "Interface name\n"
4641 "detail of all neighbors\n"
4642 JSON_STR)
4643 {
4644 struct ospf *ospf;
4645 u_char uj = use_json(argc, argv);
4646
4647 if ((ospf = ospf_lookup()) == NULL || !ospf->oi_running)
4648 return CMD_SUCCESS;
4649
4650 return show_ip_ospf_neighbor_int_detail_common(vty, ospf, 0, argv, uj);
4651 }
4652
4653 DEFUN (show_ip_ospf_instance_neighbor_int_detail,
4654 show_ip_ospf_instance_neighbor_int_detail_cmd,
4655 "show ip ospf (1-65535) neighbor IFNAME detail [json]",
4656 SHOW_STR
4657 IP_STR
4658 "OSPF information\n"
4659 "Instance ID\n"
4660 "Neighbor list\n"
4661 "Interface name\n"
4662 "detail of all neighbors\n"
4663 JSON_STR)
4664 {
4665 int idx_number = 3;
4666 struct ospf *ospf;
4667 u_short instance = 0;
4668 u_char uj = use_json(argc, argv);
4669
4670 VTY_GET_INTEGER ("Instance", instance, argv[idx_number]->arg);
4671 if ((ospf = ospf_lookup_instance(instance)) == NULL || !ospf->oi_running)
4672 return CMD_SUCCESS;
4673
4674 return show_ip_ospf_neighbor_int_detail_common(vty, ospf, 1, argv, uj);
4675 }
4676
4677 /* Show functions */
4678 static int
4679 show_lsa_summary (struct vty *vty, struct ospf_lsa *lsa, int self)
4680 {
4681 struct router_lsa *rl;
4682 struct summary_lsa *sl;
4683 struct as_external_lsa *asel;
4684 struct prefix_ipv4 p;
4685
4686 if (lsa != NULL)
4687 /* If self option is set, check LSA self flag. */
4688 if (self == 0 || IS_LSA_SELF (lsa))
4689 {
4690 /* LSA common part show. */
4691 vty_out (vty, "%-15s ", inet_ntoa (lsa->data->id));
4692 vty_out (vty, "%-15s %4d 0x%08lx 0x%04x",
4693 inet_ntoa (lsa->data->adv_router), LS_AGE (lsa),
4694 (u_long)ntohl (lsa->data->ls_seqnum), ntohs (lsa->data->checksum));
4695 /* LSA specific part show. */
4696 switch (lsa->data->type)
4697 {
4698 case OSPF_ROUTER_LSA:
4699 rl = (struct router_lsa *) lsa->data;
4700 vty_out (vty, " %-d", ntohs (rl->links));
4701 break;
4702 case OSPF_SUMMARY_LSA:
4703 sl = (struct summary_lsa *) lsa->data;
4704
4705 p.family = AF_INET;
4706 p.prefix = sl->header.id;
4707 p.prefixlen = ip_masklen (sl->mask);
4708 apply_mask_ipv4 (&p);
4709
4710 vty_out (vty, " %s/%d", inet_ntoa (p.prefix), p.prefixlen);
4711 break;
4712 case OSPF_AS_EXTERNAL_LSA:
4713 case OSPF_AS_NSSA_LSA:
4714 asel = (struct as_external_lsa *) lsa->data;
4715
4716 p.family = AF_INET;
4717 p.prefix = asel->header.id;
4718 p.prefixlen = ip_masklen (asel->mask);
4719 apply_mask_ipv4 (&p);
4720
4721 vty_out (vty, " %s %s/%d [0x%lx]",
4722 IS_EXTERNAL_METRIC (asel->e[0].tos) ? "E2" : "E1",
4723 inet_ntoa (p.prefix), p.prefixlen,
4724 (u_long)ntohl (asel->e[0].route_tag));
4725 break;
4726 case OSPF_NETWORK_LSA:
4727 case OSPF_ASBR_SUMMARY_LSA:
4728 case OSPF_OPAQUE_LINK_LSA:
4729 case OSPF_OPAQUE_AREA_LSA:
4730 case OSPF_OPAQUE_AS_LSA:
4731 default:
4732 break;
4733 }
4734 vty_out (vty, VTY_NEWLINE);
4735 }
4736
4737 return 0;
4738 }
4739
4740 static const char *show_database_desc[] =
4741 {
4742 "unknown",
4743 "Router Link States",
4744 "Net Link States",
4745 "Summary Link States",
4746 "ASBR-Summary Link States",
4747 "AS External Link States",
4748 "Group Membership LSA",
4749 "NSSA-external Link States",
4750 "Type-8 LSA",
4751 "Link-Local Opaque-LSA",
4752 "Area-Local Opaque-LSA",
4753 "AS-external Opaque-LSA",
4754 };
4755
4756 static const char *show_database_header[] =
4757 {
4758 "",
4759 "Link ID ADV Router Age Seq# CkSum Link count",
4760 "Link ID ADV Router Age Seq# CkSum",
4761 "Link ID ADV Router Age Seq# CkSum Route",
4762 "Link ID ADV Router Age Seq# CkSum",
4763 "Link ID ADV Router Age Seq# CkSum Route",
4764 " --- header for Group Member ----",
4765 "Link ID ADV Router Age Seq# CkSum Route",
4766 " --- type-8 ---",
4767 "Opaque-Type/Id ADV Router Age Seq# CkSum",
4768 "Opaque-Type/Id ADV Router Age Seq# CkSum",
4769 "Opaque-Type/Id ADV Router Age Seq# CkSum",
4770 };
4771
4772 static void
4773 show_ip_ospf_database_header (struct vty *vty, struct ospf_lsa *lsa)
4774 {
4775 struct router_lsa *rlsa = (struct router_lsa*) lsa->data;
4776
4777 vty_out (vty, " LS age: %d%s", LS_AGE (lsa), VTY_NEWLINE);
4778 vty_out (vty, " Options: 0x%-2x : %s%s",
4779 lsa->data->options,
4780 ospf_options_dump(lsa->data->options),
4781 VTY_NEWLINE);
4782 vty_out (vty, " LS Flags: 0x%-2x %s%s",
4783 lsa->flags,
4784 ((lsa->flags & OSPF_LSA_LOCAL_XLT) ? "(Translated from Type-7)" : ""),
4785 VTY_NEWLINE);
4786
4787 if (lsa->data->type == OSPF_ROUTER_LSA)
4788 {
4789 vty_out (vty, " Flags: 0x%x" , rlsa->flags);
4790
4791 if (rlsa->flags)
4792 vty_out (vty, " :%s%s%s%s",
4793 IS_ROUTER_LSA_BORDER (rlsa) ? " ABR" : "",
4794 IS_ROUTER_LSA_EXTERNAL (rlsa) ? " ASBR" : "",
4795 IS_ROUTER_LSA_VIRTUAL (rlsa) ? " VL-endpoint" : "",
4796 IS_ROUTER_LSA_SHORTCUT (rlsa) ? " Shortcut" : "");
4797
4798 vty_out (vty, "%s", VTY_NEWLINE);
4799 }
4800 vty_out (vty, " LS Type: %s%s",
4801 lookup_msg(ospf_lsa_type_msg, lsa->data->type, NULL), VTY_NEWLINE);
4802 vty_out (vty, " Link State ID: %s %s%s", inet_ntoa (lsa->data->id),
4803 lookup_msg(ospf_link_state_id_type_msg, lsa->data->type, NULL), VTY_NEWLINE);
4804 vty_out (vty, " Advertising Router: %s%s",
4805 inet_ntoa (lsa->data->adv_router), VTY_NEWLINE);
4806 vty_out (vty, " LS Seq Number: %08lx%s", (u_long)ntohl (lsa->data->ls_seqnum),
4807 VTY_NEWLINE);
4808 vty_out (vty, " Checksum: 0x%04x%s", ntohs (lsa->data->checksum),
4809 VTY_NEWLINE);
4810 vty_out (vty, " Length: %d%s", ntohs (lsa->data->length), VTY_NEWLINE);
4811 }
4812
4813 const char *link_type_desc[] =
4814 {
4815 "(null)",
4816 "another Router (point-to-point)",
4817 "a Transit Network",
4818 "Stub Network",
4819 "a Virtual Link",
4820 };
4821
4822 const char *link_id_desc[] =
4823 {
4824 "(null)",
4825 "Neighboring Router ID",
4826 "Designated Router address",
4827 "Net",
4828 "Neighboring Router ID",
4829 };
4830
4831 const char *link_data_desc[] =
4832 {
4833 "(null)",
4834 "Router Interface address",
4835 "Router Interface address",
4836 "Network Mask",
4837 "Router Interface address",
4838 };
4839
4840 /* Show router-LSA each Link information. */
4841 static void
4842 show_ip_ospf_database_router_links (struct vty *vty,
4843 struct router_lsa *rl)
4844 {
4845 int len, type;
4846 unsigned int i;
4847
4848 len = ntohs (rl->header.length) - 4;
4849 for (i = 0; i < ntohs (rl->links) && len > 0; len -= 12, i++)
4850 {
4851 type = rl->link[i].type;
4852
4853 vty_out (vty, " Link connected to: %s%s",
4854 link_type_desc[type], VTY_NEWLINE);
4855 vty_out (vty, " (Link ID) %s: %s%s", link_id_desc[type],
4856 inet_ntoa (rl->link[i].link_id), VTY_NEWLINE);
4857 vty_out (vty, " (Link Data) %s: %s%s", link_data_desc[type],
4858 inet_ntoa (rl->link[i].link_data), VTY_NEWLINE);
4859 vty_out (vty, " Number of TOS metrics: 0%s", VTY_NEWLINE);
4860 vty_out (vty, " TOS 0 Metric: %d%s",
4861 ntohs (rl->link[i].metric), VTY_NEWLINE);
4862 vty_out (vty, "%s", VTY_NEWLINE);
4863 }
4864 }
4865
4866 /* Show router-LSA detail information. */
4867 static int
4868 show_router_lsa_detail (struct vty *vty, struct ospf_lsa *lsa)
4869 {
4870 if (lsa != NULL)
4871 {
4872 struct router_lsa *rl = (struct router_lsa *) lsa->data;
4873
4874 show_ip_ospf_database_header (vty, lsa);
4875
4876 vty_out (vty, " Number of Links: %d%s%s", ntohs (rl->links),
4877 VTY_NEWLINE, VTY_NEWLINE);
4878
4879 show_ip_ospf_database_router_links (vty, rl);
4880 vty_out (vty, "%s", VTY_NEWLINE);
4881 }
4882
4883 return 0;
4884 }
4885
4886 /* Show network-LSA detail information. */
4887 static int
4888 show_network_lsa_detail (struct vty *vty, struct ospf_lsa *lsa)
4889 {
4890 int length, i;
4891
4892 if (lsa != NULL)
4893 {
4894 struct network_lsa *nl = (struct network_lsa *) lsa->data;
4895
4896 show_ip_ospf_database_header (vty, lsa);
4897
4898 vty_out (vty, " Network Mask: /%d%s",
4899 ip_masklen (nl->mask), VTY_NEWLINE);
4900
4901 length = ntohs (lsa->data->length) - OSPF_LSA_HEADER_SIZE - 4;
4902
4903 for (i = 0; length > 0; i++, length -= 4)
4904 vty_out (vty, " Attached Router: %s%s",
4905 inet_ntoa (nl->routers[i]), VTY_NEWLINE);
4906
4907 vty_out (vty, "%s", VTY_NEWLINE);
4908 }
4909
4910 return 0;
4911 }
4912
4913 /* Show summary-LSA detail information. */
4914 static int
4915 show_summary_lsa_detail (struct vty *vty, struct ospf_lsa *lsa)
4916 {
4917 if (lsa != NULL)
4918 {
4919 struct summary_lsa *sl = (struct summary_lsa *) lsa->data;
4920
4921 show_ip_ospf_database_header (vty, lsa);
4922
4923 vty_out (vty, " Network Mask: /%d%s", ip_masklen (sl->mask),
4924 VTY_NEWLINE);
4925 vty_out (vty, " TOS: 0 Metric: %d%s", GET_METRIC (sl->metric),
4926 VTY_NEWLINE);
4927 vty_out (vty, "%s", VTY_NEWLINE);
4928 }
4929
4930 return 0;
4931 }
4932
4933 /* Show summary-ASBR-LSA detail information. */
4934 static int
4935 show_summary_asbr_lsa_detail (struct vty *vty, struct ospf_lsa *lsa)
4936 {
4937 if (lsa != NULL)
4938 {
4939 struct summary_lsa *sl = (struct summary_lsa *) lsa->data;
4940
4941 show_ip_ospf_database_header (vty, lsa);
4942
4943 vty_out (vty, " Network Mask: /%d%s",
4944 ip_masklen (sl->mask), VTY_NEWLINE);
4945 vty_out (vty, " TOS: 0 Metric: %d%s", GET_METRIC (sl->metric),
4946 VTY_NEWLINE);
4947 vty_out (vty, "%s", VTY_NEWLINE);
4948 }
4949
4950 return 0;
4951 }
4952
4953 /* Show AS-external-LSA detail information. */
4954 static int
4955 show_as_external_lsa_detail (struct vty *vty, struct ospf_lsa *lsa)
4956 {
4957 if (lsa != NULL)
4958 {
4959 struct as_external_lsa *al = (struct as_external_lsa *) lsa->data;
4960
4961 show_ip_ospf_database_header (vty, lsa);
4962
4963 vty_out (vty, " Network Mask: /%d%s",
4964 ip_masklen (al->mask), VTY_NEWLINE);
4965 vty_out (vty, " Metric Type: %s%s",
4966 IS_EXTERNAL_METRIC (al->e[0].tos) ?
4967 "2 (Larger than any link state path)" : "1", VTY_NEWLINE);
4968 vty_out (vty, " TOS: 0%s", VTY_NEWLINE);
4969 vty_out (vty, " Metric: %d%s",
4970 GET_METRIC (al->e[0].metric), VTY_NEWLINE);
4971 vty_out (vty, " Forward Address: %s%s",
4972 inet_ntoa (al->e[0].fwd_addr), VTY_NEWLINE);
4973
4974 vty_out (vty, " External Route Tag: %"ROUTE_TAG_PRI"%s%s",
4975 (route_tag_t)ntohl (al->e[0].route_tag), VTY_NEWLINE, VTY_NEWLINE);
4976 }
4977
4978 return 0;
4979 }
4980 #if 0
4981 static int
4982 show_as_external_lsa_stdvty (struct ospf_lsa *lsa)
4983 {
4984 struct as_external_lsa *al = (struct as_external_lsa *) lsa->data;
4985
4986 /* show_ip_ospf_database_header (vty, lsa); */
4987
4988 zlog_debug( " Network Mask: /%d%s",
4989 ip_masklen (al->mask), "\n");
4990 zlog_debug( " Metric Type: %s%s",
4991 IS_EXTERNAL_METRIC (al->e[0].tos) ?
4992 "2 (Larger than any link state path)" : "1", "\n");
4993 zlog_debug( " TOS: 0%s", "\n");
4994 zlog_debug( " Metric: %d%s",
4995 GET_METRIC (al->e[0].metric), "\n");
4996 zlog_debug( " Forward Address: %s%s",
4997 inet_ntoa (al->e[0].fwd_addr), "\n");
4998
4999 zlog_debug( " External Route Tag: %"ROUTE_TAG_PRI"%s%s",
5000 (route_tag_t)ntohl (al->e[0].route_tag), "\n", "\n");
5001
5002 return 0;
5003 }
5004 #endif
5005 /* Show AS-NSSA-LSA detail information. */
5006 static int
5007 show_as_nssa_lsa_detail (struct vty *vty, struct ospf_lsa *lsa)
5008 {
5009 if (lsa != NULL)
5010 {
5011 struct as_external_lsa *al = (struct as_external_lsa *) lsa->data;
5012
5013 show_ip_ospf_database_header (vty, lsa);
5014
5015 vty_out (vty, " Network Mask: /%d%s",
5016 ip_masklen (al->mask), VTY_NEWLINE);
5017 vty_out (vty, " Metric Type: %s%s",
5018 IS_EXTERNAL_METRIC (al->e[0].tos) ?
5019 "2 (Larger than any link state path)" : "1", VTY_NEWLINE);
5020 vty_out (vty, " TOS: 0%s", VTY_NEWLINE);
5021 vty_out (vty, " Metric: %d%s",
5022 GET_METRIC (al->e[0].metric), VTY_NEWLINE);
5023 vty_out (vty, " NSSA: Forward Address: %s%s",
5024 inet_ntoa (al->e[0].fwd_addr), VTY_NEWLINE);
5025
5026 vty_out (vty, " External Route Tag: %"ROUTE_TAG_PRI"%s%s",
5027 (route_tag_t)ntohl (al->e[0].route_tag), VTY_NEWLINE, VTY_NEWLINE);
5028 }
5029
5030 return 0;
5031 }
5032
5033 static int
5034 show_func_dummy (struct vty *vty, struct ospf_lsa *lsa)
5035 {
5036 return 0;
5037 }
5038
5039 static int
5040 show_opaque_lsa_detail (struct vty *vty, struct ospf_lsa *lsa)
5041 {
5042 if (lsa != NULL)
5043 {
5044 show_ip_ospf_database_header (vty, lsa);
5045 show_opaque_info_detail (vty, lsa);
5046
5047 vty_out (vty, "%s", VTY_NEWLINE);
5048 }
5049 return 0;
5050 }
5051
5052 int (*show_function[])(struct vty *, struct ospf_lsa *) =
5053 {
5054 NULL,
5055 show_router_lsa_detail,
5056 show_network_lsa_detail,
5057 show_summary_lsa_detail,
5058 show_summary_asbr_lsa_detail,
5059 show_as_external_lsa_detail,
5060 show_func_dummy,
5061 show_as_nssa_lsa_detail, /* almost same as external */
5062 NULL, /* type-8 */
5063 show_opaque_lsa_detail,
5064 show_opaque_lsa_detail,
5065 show_opaque_lsa_detail,
5066 };
5067
5068 static void
5069 show_lsa_prefix_set (struct vty *vty, struct prefix_ls *lp, struct in_addr *id,
5070 struct in_addr *adv_router)
5071 {
5072 memset (lp, 0, sizeof (struct prefix_ls));
5073 lp->family = 0;
5074 if (id == NULL)
5075 lp->prefixlen = 0;
5076 else if (adv_router == NULL)
5077 {
5078 lp->prefixlen = 32;
5079 lp->id = *id;
5080 }
5081 else
5082 {
5083 lp->prefixlen = 64;
5084 lp->id = *id;
5085 lp->adv_router = *adv_router;
5086 }
5087 }
5088
5089 static void
5090 show_lsa_detail_proc (struct vty *vty, struct route_table *rt,
5091 struct in_addr *id, struct in_addr *adv_router)
5092 {
5093 struct prefix_ls lp;
5094 struct route_node *rn, *start;
5095 struct ospf_lsa *lsa;
5096
5097 show_lsa_prefix_set (vty, &lp, id, adv_router);
5098 start = route_node_get (rt, (struct prefix *) &lp);
5099 if (start)
5100 {
5101 route_lock_node (start);
5102 for (rn = start; rn; rn = route_next_until (rn, start))
5103 if ((lsa = rn->info))
5104 {
5105 if (show_function[lsa->data->type] != NULL)
5106 show_function[lsa->data->type] (vty, lsa);
5107 }
5108 route_unlock_node (start);
5109 }
5110 }
5111
5112 /* Show detail LSA information
5113 -- if id is NULL then show all LSAs. */
5114 static void
5115 show_lsa_detail (struct vty *vty, struct ospf *ospf, int type,
5116 struct in_addr *id, struct in_addr *adv_router)
5117 {
5118 struct listnode *node;
5119 struct ospf_area *area;
5120
5121 switch (type)
5122 {
5123 case OSPF_AS_EXTERNAL_LSA:
5124 case OSPF_OPAQUE_AS_LSA:
5125 vty_out (vty, " %s %s%s",
5126 show_database_desc[type],
5127 VTY_NEWLINE, VTY_NEWLINE);
5128 show_lsa_detail_proc (vty, AS_LSDB (ospf, type), id, adv_router);
5129 break;
5130 default:
5131 for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
5132 {
5133 vty_out (vty, "%s %s (Area %s)%s%s",
5134 VTY_NEWLINE, show_database_desc[type],
5135 ospf_area_desc_string (area), VTY_NEWLINE, VTY_NEWLINE);
5136 show_lsa_detail_proc (vty, AREA_LSDB (area, type), id, adv_router);
5137 }
5138 break;
5139 }
5140 }
5141
5142 static void
5143 show_lsa_detail_adv_router_proc (struct vty *vty, struct route_table *rt,
5144 struct in_addr *adv_router)
5145 {
5146 struct route_node *rn;
5147 struct ospf_lsa *lsa;
5148
5149 for (rn = route_top (rt); rn; rn = route_next (rn))
5150 if ((lsa = rn->info))
5151 if (IPV4_ADDR_SAME (adv_router, &lsa->data->adv_router))
5152 {
5153 if (CHECK_FLAG (lsa->flags, OSPF_LSA_LOCAL_XLT))
5154 continue;
5155 if (show_function[lsa->data->type] != NULL)
5156 show_function[lsa->data->type] (vty, lsa);
5157 }
5158 }
5159
5160 /* Show detail LSA information. */
5161 static void
5162 show_lsa_detail_adv_router (struct vty *vty, struct ospf *ospf, int type,
5163 struct in_addr *adv_router)
5164 {
5165 struct listnode *node;
5166 struct ospf_area *area;
5167
5168 switch (type)
5169 {
5170 case OSPF_AS_EXTERNAL_LSA:
5171 case OSPF_OPAQUE_AS_LSA:
5172 vty_out (vty, " %s %s%s",
5173 show_database_desc[type],
5174 VTY_NEWLINE, VTY_NEWLINE);
5175 show_lsa_detail_adv_router_proc (vty, AS_LSDB (ospf, type),
5176 adv_router);
5177 break;
5178 default:
5179 for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
5180 {
5181 vty_out (vty, "%s %s (Area %s)%s%s",
5182 VTY_NEWLINE, show_database_desc[type],
5183 ospf_area_desc_string (area), VTY_NEWLINE, VTY_NEWLINE);
5184 show_lsa_detail_adv_router_proc (vty, AREA_LSDB (area, type),
5185 adv_router);
5186 }
5187 break;
5188 }
5189 }
5190
5191 static void
5192 show_ip_ospf_database_summary (struct vty *vty, struct ospf *ospf, int self)
5193 {
5194 struct ospf_lsa *lsa;
5195 struct route_node *rn;
5196 struct ospf_area *area;
5197 struct listnode *node;
5198 int type;
5199
5200 for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
5201 {
5202 for (type = OSPF_MIN_LSA; type < OSPF_MAX_LSA; type++)
5203 {
5204 switch (type)
5205 {
5206 case OSPF_AS_EXTERNAL_LSA:
5207 case OSPF_OPAQUE_AS_LSA:
5208 continue;
5209 default:
5210 break;
5211 }
5212 if (ospf_lsdb_count_self (area->lsdb, type) > 0 ||
5213 (!self && ospf_lsdb_count (area->lsdb, type) > 0))
5214 {
5215 vty_out (vty, " %s (Area %s)%s%s",
5216 show_database_desc[type],
5217 ospf_area_desc_string (area),
5218 VTY_NEWLINE, VTY_NEWLINE);
5219 vty_out (vty, "%s%s", show_database_header[type], VTY_NEWLINE);
5220
5221 LSDB_LOOP (AREA_LSDB (area, type), rn, lsa)
5222 show_lsa_summary (vty, lsa, self);
5223
5224 vty_out (vty, "%s", VTY_NEWLINE);
5225 }
5226 }
5227 }
5228
5229 for (type = OSPF_MIN_LSA; type < OSPF_MAX_LSA; type++)
5230 {
5231 switch (type)
5232 {
5233 case OSPF_AS_EXTERNAL_LSA:
5234 case OSPF_OPAQUE_AS_LSA:
5235 break;
5236 default:
5237 continue;
5238 }
5239 if (ospf_lsdb_count_self (ospf->lsdb, type) ||
5240 (!self && ospf_lsdb_count (ospf->lsdb, type)))
5241 {
5242 vty_out (vty, " %s%s%s",
5243 show_database_desc[type],
5244 VTY_NEWLINE, VTY_NEWLINE);
5245 vty_out (vty, "%s%s", show_database_header[type],
5246 VTY_NEWLINE);
5247
5248 LSDB_LOOP (AS_LSDB (ospf, type), rn, lsa)
5249 show_lsa_summary (vty, lsa, self);
5250
5251 vty_out (vty, "%s", VTY_NEWLINE);
5252 }
5253 }
5254
5255 vty_out (vty, "%s", VTY_NEWLINE);
5256 }
5257
5258 static void
5259 show_ip_ospf_database_maxage (struct vty *vty, struct ospf *ospf)
5260 {
5261 struct route_node *rn;
5262
5263 vty_out (vty, "%s MaxAge Link States:%s%s",
5264 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
5265
5266 for (rn = route_top (ospf->maxage_lsa); rn; rn = route_next (rn))
5267 {
5268 struct ospf_lsa *lsa;
5269
5270 if ((lsa = rn->info) != NULL)
5271 {
5272 vty_out (vty, "Link type: %d%s", lsa->data->type, VTY_NEWLINE);
5273 vty_out (vty, "Link State ID: %s%s",
5274 inet_ntoa (lsa->data->id), VTY_NEWLINE);
5275 vty_out (vty, "Advertising Router: %s%s",
5276 inet_ntoa (lsa->data->adv_router), VTY_NEWLINE);
5277 vty_out (vty, "LSA lock count: %d%s", lsa->lock, VTY_NEWLINE);
5278 vty_out (vty, "%s", VTY_NEWLINE);
5279 }
5280 }
5281 }
5282
5283 #define OSPF_LSA_TYPE_NSSA_DESC "NSSA external link state\n"
5284 #define OSPF_LSA_TYPE_NSSA_CMD_STR "|nssa-external"
5285
5286 #define OSPF_LSA_TYPE_OPAQUE_LINK_DESC "Link local Opaque-LSA\n"
5287 #define OSPF_LSA_TYPE_OPAQUE_AREA_DESC "Link area Opaque-LSA\n"
5288 #define OSPF_LSA_TYPE_OPAQUE_AS_DESC "Link AS Opaque-LSA\n"
5289 #define OSPF_LSA_TYPE_OPAQUE_CMD_STR "|opaque-link|opaque-area|opaque-as"
5290
5291 #define OSPF_LSA_TYPES_DESC \
5292 "ASBR summary link states\n" \
5293 "External link states\n" \
5294 "Network link states\n" \
5295 "Router link states\n" \
5296 "Network summary link states\n" \
5297 OSPF_LSA_TYPE_NSSA_DESC \
5298 OSPF_LSA_TYPE_OPAQUE_LINK_DESC \
5299 OSPF_LSA_TYPE_OPAQUE_AREA_DESC \
5300 OSPF_LSA_TYPE_OPAQUE_AS_DESC
5301
5302 static int
5303 show_ip_ospf_database_common (struct vty *vty, struct ospf *ospf,
5304 int arg_base, int argc, struct cmd_token **argv)
5305 {
5306 int idx_type = 4;
5307 int type, ret;
5308 struct in_addr id, adv_router;
5309
5310 if (ospf->instance)
5311 vty_out (vty, "%sOSPF Instance: %d%s", VTY_NEWLINE, ospf->instance,
5312 VTY_NEWLINE);
5313
5314 vty_out (vty, "%s OSPF Router with ID (%s)%s%s", VTY_NEWLINE,
5315 inet_ntoa (ospf->router_id), VTY_NEWLINE, VTY_NEWLINE);
5316
5317 /* Show all LSA. */
5318 if (argc == arg_base + 4)
5319 {
5320 show_ip_ospf_database_summary (vty, ospf, 0);
5321 return CMD_SUCCESS;
5322 }
5323
5324 /* Set database type to show. */
5325 if (strncmp (argv[arg_base + idx_type]->text, "r", 1) == 0)
5326 type = OSPF_ROUTER_LSA;
5327 else if (strncmp (argv[arg_base + idx_type]->text, "ne", 2) == 0)
5328 type = OSPF_NETWORK_LSA;
5329 else if (strncmp (argv[arg_base + idx_type]->text, "ns", 2) == 0)
5330 type = OSPF_AS_NSSA_LSA;
5331 else if (strncmp (argv[arg_base + idx_type]->text, "su", 2) == 0)
5332 type = OSPF_SUMMARY_LSA;
5333 else if (strncmp (argv[arg_base + idx_type]->text, "a", 1) == 0)
5334 type = OSPF_ASBR_SUMMARY_LSA;
5335 else if (strncmp (argv[arg_base + idx_type]->text, "e", 1) == 0)
5336 type = OSPF_AS_EXTERNAL_LSA;
5337 else if (strncmp (argv[arg_base + idx_type]->text, "se", 2) == 0)
5338 {
5339 show_ip_ospf_database_summary (vty, ospf, 1);
5340 return CMD_SUCCESS;
5341 }
5342 else if (strncmp (argv[arg_base + idx_type]->text, "m", 1) == 0)
5343 {
5344 show_ip_ospf_database_maxage (vty, ospf);
5345 return CMD_SUCCESS;
5346 }
5347 else if (strncmp (argv[arg_base + idx_type]->text, "opaque-l", 8) == 0)
5348 type = OSPF_OPAQUE_LINK_LSA;
5349 else if (strncmp (argv[arg_base + idx_type]->text, "opaque-ar", 9) == 0)
5350 type = OSPF_OPAQUE_AREA_LSA;
5351 else if (strncmp (argv[arg_base + idx_type]->text, "opaque-as", 9) == 0)
5352 type = OSPF_OPAQUE_AS_LSA;
5353 else
5354 return CMD_WARNING;
5355
5356 /* `show ip ospf database LSA'. */
5357 if (argc == arg_base + 5)
5358 show_lsa_detail (vty, ospf, type, NULL, NULL);
5359 else if (argc >= arg_base + 6)
5360 {
5361 ret = inet_aton (argv[arg_base + 5]->arg, &id);
5362 if (!ret)
5363 return CMD_WARNING;
5364
5365 /* `show ip ospf database LSA ID'. */
5366 if (argc == arg_base + 6)
5367 show_lsa_detail (vty, ospf, type, &id, NULL);
5368 /* `show ip ospf database LSA ID adv-router ADV_ROUTER'. */
5369 else if (argc == arg_base + 7)
5370 {
5371 if (strncmp (argv[arg_base + 6]->text, "s", 1) == 0)
5372 adv_router = ospf->router_id;
5373 else
5374 {
5375 ret = inet_aton (argv[arg_base + 7]->arg, &adv_router);
5376 if (!ret)
5377 return CMD_WARNING;
5378 }
5379 show_lsa_detail (vty, ospf, type, &id, &adv_router);
5380 }
5381 }
5382
5383 return CMD_SUCCESS;
5384 }
5385
5386 DEFUN (show_ip_ospf_database_max,
5387 show_ip_ospf_database_max_cmd,
5388 "show ip ospf database <max-age|self-originate>",
5389 SHOW_STR
5390 IP_STR
5391 "OSPF information\n"
5392 "Database summary\n"
5393 "LSAs in MaxAge list\n"
5394 "Self-originated link states\n")
5395 {
5396 struct ospf *ospf;
5397
5398 if ((ospf = ospf_lookup()) == NULL || !ospf->oi_running)
5399 return CMD_SUCCESS;
5400
5401 return (show_ip_ospf_database_common(vty, ospf, 0, argc, argv));
5402 }
5403
5404 DEFUN (show_ip_ospf_instance_database,
5405 show_ip_ospf_instance_database_cmd,
5406 "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>]]]",
5407 SHOW_STR
5408 IP_STR
5409 "OSPF information\n"
5410 "Instance ID\n"
5411 "Database summary\n"
5412 OSPF_LSA_TYPES_DESC
5413 "Link State ID (as an IP address)\n"
5414 "Self-originated link states\n"
5415 "Advertising Router link states\n"
5416 "Advertising Router (as an IP address)\n")
5417 {
5418 struct ospf *ospf;
5419 u_short instance = 0;
5420
5421 int idx = 0;
5422 if (argv_find (argv, argc, "(1-65535)", &idx))
5423 {
5424 VTY_GET_INTEGER ("Instance", instance, argv[idx]->arg);
5425 ospf = ospf_lookup_instance (instance);
5426 }
5427 else {
5428 ospf = ospf_lookup();
5429 }
5430
5431 if (!ospf || !ospf->oi_running)
5432 return CMD_SUCCESS;
5433
5434 return (show_ip_ospf_database_common(vty, ospf, idx ? 1 : 0, argc, argv));
5435 }
5436
5437 DEFUN (show_ip_ospf_instance_database_max,
5438 show_ip_ospf_instance_database_max_cmd,
5439 "show ip ospf (1-65535) database <max-age|self-originate>",
5440 SHOW_STR
5441 IP_STR
5442 "OSPF information\n"
5443 "Instance ID\n"
5444 "Database summary\n"
5445 "LSAs in MaxAge list\n"
5446 "Self-originated link states\n")
5447 {
5448 int idx_number = 3;
5449 struct ospf *ospf;
5450 u_short instance = 0;
5451
5452 VTY_GET_INTEGER ("Instance", instance, argv[idx_number]->arg);
5453
5454 if ((ospf = ospf_lookup_instance (instance)) == NULL || !ospf->oi_running)
5455 return CMD_SUCCESS;
5456
5457 return (show_ip_ospf_database_common(vty, ospf, 1, argc, argv));
5458 }
5459
5460
5461 static int
5462 show_ip_ospf_database_type_adv_router_common (struct vty *vty, struct ospf *ospf,
5463 int arg_base, int argc, struct cmd_token **argv)
5464 {
5465 int idx_type = 4;
5466 int type, ret;
5467 struct in_addr adv_router;
5468
5469 if (ospf->instance)
5470 vty_out (vty, "%sOSPF Instance: %d%s", VTY_NEWLINE, ospf->instance,
5471 VTY_NEWLINE);
5472
5473 vty_out (vty, "%s OSPF Router with ID (%s)%s%s", VTY_NEWLINE,
5474 inet_ntoa (ospf->router_id), VTY_NEWLINE, VTY_NEWLINE);
5475
5476 if (argc != arg_base + 7)
5477 return CMD_WARNING;
5478
5479 /* Set database type to show. */
5480 if (strncmp (argv[arg_base + idx_type]->text, "r", 1) == 0)
5481 type = OSPF_ROUTER_LSA;
5482 else if (strncmp (argv[arg_base + idx_type]->text, "ne", 2) == 0)
5483 type = OSPF_NETWORK_LSA;
5484 else if (strncmp (argv[arg_base + idx_type]->text, "ns", 2) == 0)
5485 type = OSPF_AS_NSSA_LSA;
5486 else if (strncmp (argv[arg_base + idx_type]->text, "s", 1) == 0)
5487 type = OSPF_SUMMARY_LSA;
5488 else if (strncmp (argv[arg_base + idx_type]->text, "a", 1) == 0)
5489 type = OSPF_ASBR_SUMMARY_LSA;
5490 else if (strncmp (argv[arg_base + idx_type]->text, "e", 1) == 0)
5491 type = OSPF_AS_EXTERNAL_LSA;
5492 else if (strncmp (argv[arg_base + idx_type]->text, "opaque-l", 8) == 0)
5493 type = OSPF_OPAQUE_LINK_LSA;
5494 else if (strncmp (argv[arg_base + idx_type]->text, "opaque-ar", 9) == 0)
5495 type = OSPF_OPAQUE_AREA_LSA;
5496 else if (strncmp (argv[arg_base + idx_type]->text, "opaque-as", 9) == 0)
5497 type = OSPF_OPAQUE_AS_LSA;
5498 else
5499 return CMD_WARNING;
5500
5501 /* `show ip ospf database LSA adv-router ADV_ROUTER'. */
5502 if (strncmp (argv[arg_base + 5]->text, "s", 1) == 0)
5503 adv_router = ospf->router_id;
5504 else
5505 {
5506 ret = inet_aton (argv[arg_base + 6]->arg, &adv_router);
5507 if (!ret)
5508 return CMD_WARNING;
5509 }
5510
5511 show_lsa_detail_adv_router (vty, ospf, type, &adv_router);
5512
5513 return CMD_SUCCESS;
5514 }
5515
5516 DEFUN (show_ip_ospf_database_type_adv_router,
5517 show_ip_ospf_database_type_adv_router_cmd,
5518 "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>",
5519 SHOW_STR
5520 IP_STR
5521 "OSPF information\n"
5522 "Database summary\n"
5523 OSPF_LSA_TYPES_DESC
5524 "Advertising Router link states\n"
5525 "Advertising Router (as an IP address)\n"
5526 "Self-originated link states\n")
5527 {
5528 struct ospf *ospf;
5529
5530 if ((ospf = ospf_lookup()) == NULL || !ospf->oi_running)
5531 return CMD_SUCCESS;
5532
5533 return (show_ip_ospf_database_type_adv_router_common(vty, ospf, 0, argc, argv));
5534 }
5535
5536 DEFUN (show_ip_ospf_instance_database_type_adv_router,
5537 show_ip_ospf_instance_database_type_adv_router_cmd,
5538 "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>",
5539 SHOW_STR
5540 IP_STR
5541 "OSPF information\n"
5542 "Instance ID\n"
5543 "Database summary\n"
5544 OSPF_LSA_TYPES_DESC
5545 "Advertising Router link states\n"
5546 "Advertising Router (as an IP address)\n"
5547 "Self-originated link states\n")
5548 {
5549 int idx_number = 3;
5550 struct ospf *ospf;
5551 u_short instance = 0;
5552
5553 VTY_GET_INTEGER ("Instance", instance, argv[idx_number]->arg);
5554
5555 if ((ospf = ospf_lookup_instance (instance)) == NULL || !ospf->oi_running)
5556 return CMD_SUCCESS;
5557
5558 return (show_ip_ospf_database_type_adv_router_common(vty, ospf, 1, argc, argv));
5559 }
5560
5561 DEFUN (ip_ospf_authentication_args,
5562 ip_ospf_authentication_args_addr_cmd,
5563 "ip ospf authentication <null|message-digest> [A.B.C.D]",
5564 "IP Information\n"
5565 "OSPF interface commands\n"
5566 "Enable authentication on this interface\n"
5567 "Use null authentication\n"
5568 "Use message-digest authentication\n"
5569 "Address of interface\n")
5570 {
5571 VTY_DECLVAR_CONTEXT(interface, ifp);
5572 int idx_encryption = 3;
5573 int idx_ipv4 = 4;
5574 struct in_addr addr;
5575 int ret;
5576 struct ospf_if_params *params;
5577
5578 params = IF_DEF_PARAMS (ifp);
5579
5580 if (argc == 5)
5581 {
5582 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
5583 if (!ret)
5584 {
5585 vty_out (vty, "Please specify interface address by A.B.C.D%s",
5586 VTY_NEWLINE);
5587 return CMD_WARNING;
5588 }
5589
5590 params = ospf_get_if_params (ifp, addr);
5591 ospf_if_update_params (ifp, addr);
5592 }
5593
5594 /* Handle null authentication */
5595 if ( argv[idx_encryption]->arg[0] == 'n' )
5596 {
5597 SET_IF_PARAM (params, auth_type);
5598 params->auth_type = OSPF_AUTH_NULL;
5599 return CMD_SUCCESS;
5600 }
5601
5602 /* Handle message-digest authentication */
5603 if ( argv[idx_encryption]->arg[0] == 'm' )
5604 {
5605 SET_IF_PARAM (params, auth_type);
5606 params->auth_type = OSPF_AUTH_CRYPTOGRAPHIC;
5607 return CMD_SUCCESS;
5608 }
5609
5610 vty_out (vty, "You shouldn't get here!%s", VTY_NEWLINE);
5611 return CMD_WARNING;
5612 }
5613
5614 DEFUN (ip_ospf_authentication,
5615 ip_ospf_authentication_addr_cmd,
5616 "ip ospf authentication [A.B.C.D]",
5617 "IP Information\n"
5618 "OSPF interface commands\n"
5619 "Enable authentication on this interface\n"
5620 "Address of interface")
5621 {
5622 VTY_DECLVAR_CONTEXT(interface, ifp);
5623 int idx_ipv4 = 3;
5624 struct in_addr addr;
5625 int ret;
5626 struct ospf_if_params *params;
5627
5628 params = IF_DEF_PARAMS (ifp);
5629
5630 if (argc == 4)
5631 {
5632 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
5633 if (!ret)
5634 {
5635 vty_out (vty, "Please specify interface address by A.B.C.D%s",
5636 VTY_NEWLINE);
5637 return CMD_WARNING;
5638 }
5639
5640 params = ospf_get_if_params (ifp, addr);
5641 ospf_if_update_params (ifp, addr);
5642 }
5643
5644 SET_IF_PARAM (params, auth_type);
5645 params->auth_type = OSPF_AUTH_SIMPLE;
5646
5647 return CMD_SUCCESS;
5648 }
5649
5650 DEFUN (no_ip_ospf_authentication_args,
5651 no_ip_ospf_authentication_args_addr_cmd,
5652 "no ip ospf authentication <null|message-digest> [A.B.C.D]",
5653 NO_STR
5654 "IP Information\n"
5655 "OSPF interface commands\n"
5656 "Enable authentication on this interface\n"
5657 "Use null authentication\n"
5658 "Use message-digest authentication\n"
5659 "Address of interface")
5660 {
5661 VTY_DECLVAR_CONTEXT(interface, ifp);
5662 int idx_encryption = 4;
5663 int idx_ipv4 = 5;
5664 struct in_addr addr;
5665 int ret;
5666 struct ospf_if_params *params;
5667 struct route_node *rn;
5668 int auth_type;
5669
5670 params = IF_DEF_PARAMS (ifp);
5671
5672 if (argc == 6)
5673 {
5674 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
5675 if (!ret)
5676 {
5677 vty_out (vty, "Please specify interface address by A.B.C.D%s",
5678 VTY_NEWLINE);
5679 return CMD_WARNING;
5680 }
5681
5682 params = ospf_lookup_if_params (ifp, addr);
5683 if (params == NULL)
5684 {
5685 vty_out (vty, "Ip Address specified is unknown%s", VTY_NEWLINE);
5686 return CMD_WARNING;
5687 }
5688 params->auth_type = OSPF_AUTH_NOTSET;
5689 UNSET_IF_PARAM (params, auth_type);
5690 if (params != IF_DEF_PARAMS (ifp))
5691 {
5692 ospf_free_if_params (ifp, addr);
5693 ospf_if_update_params (ifp, addr);
5694 }
5695 }
5696 else
5697 {
5698 if ( argv[idx_encryption]->arg[0] == 'n' )
5699 {
5700 auth_type = OSPF_AUTH_NULL;
5701 }
5702 else if ( argv[idx_encryption]->arg[0] == 'm' )
5703 {
5704 auth_type = OSPF_AUTH_CRYPTOGRAPHIC;
5705 }
5706 else
5707 {
5708 vty_out (vty, "Unexpected input encountered%s", VTY_NEWLINE);
5709 return CMD_WARNING;
5710 }
5711 /*
5712 * Here we have a case where the user has entered
5713 * 'no ip ospf authentication (null | message_digest )'
5714 * we need to find if we have any ip addresses underneath it that
5715 * correspond to the associated type.
5716 */
5717 if (params->auth_type == auth_type)
5718 {
5719 params->auth_type = OSPF_AUTH_NOTSET;
5720 UNSET_IF_PARAM (params, auth_type);
5721 }
5722
5723 for (rn = route_top (IF_OIFS_PARAMS (ifp)); rn; rn = route_next (rn))
5724 {
5725 if ((params = rn->info))
5726 {
5727 if (params->auth_type == auth_type)
5728 {
5729 params->auth_type = OSPF_AUTH_NOTSET;
5730 UNSET_IF_PARAM (params, auth_type);
5731 if (params != IF_DEF_PARAMS (ifp))
5732 {
5733 ospf_free_if_params (ifp, rn->p.u.prefix4);
5734 ospf_if_update_params(ifp, rn->p.u.prefix4);
5735 }
5736 }
5737 }
5738 }
5739 }
5740
5741 return CMD_SUCCESS;
5742 }
5743
5744 DEFUN (no_ip_ospf_authentication,
5745 no_ip_ospf_authentication_addr_cmd,
5746 "no ip ospf authentication [A.B.C.D]",
5747 NO_STR
5748 "IP Information\n"
5749 "OSPF interface commands\n"
5750 "Enable authentication on this interface\n"
5751 "Address of interface")
5752 {
5753 VTY_DECLVAR_CONTEXT(interface, ifp);
5754 int idx_ipv4 = 4;
5755 struct in_addr addr;
5756 int ret;
5757 struct ospf_if_params *params;
5758 struct route_node *rn;
5759
5760 params = IF_DEF_PARAMS (ifp);
5761
5762 if (argc == 5)
5763 {
5764 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
5765 if (!ret)
5766 {
5767 vty_out (vty, "Please specify interface address by A.B.C.D%s",
5768 VTY_NEWLINE);
5769 return CMD_WARNING;
5770 }
5771
5772 params = ospf_lookup_if_params (ifp, addr);
5773 if (params == NULL)
5774 {
5775 vty_out (vty, "Ip Address specified is unknown%s", VTY_NEWLINE);
5776 return CMD_WARNING;
5777 }
5778
5779 params->auth_type = OSPF_AUTH_NOTSET;
5780 UNSET_IF_PARAM (params, auth_type);
5781 if (params != IF_DEF_PARAMS (ifp))
5782 {
5783 ospf_free_if_params (ifp, addr);
5784 ospf_if_update_params (ifp, addr);
5785 }
5786 }
5787 else
5788 {
5789 /*
5790 * When a user enters 'no ip ospf authentication'
5791 * We should remove all authentication types from
5792 * the interface.
5793 */
5794 if ((params->auth_type == OSPF_AUTH_NULL) ||
5795 (params->auth_type == OSPF_AUTH_CRYPTOGRAPHIC) ||
5796 (params->auth_type == OSPF_AUTH_SIMPLE))
5797 {
5798 params->auth_type = OSPF_AUTH_NOTSET;
5799 UNSET_IF_PARAM (params, auth_type);
5800 }
5801
5802 for (rn = route_top (IF_OIFS_PARAMS (ifp)); rn; rn = route_next (rn))
5803 {
5804 if ((params = rn->info))
5805 {
5806
5807 if ((params->auth_type == OSPF_AUTH_NULL) ||
5808 (params->auth_type == OSPF_AUTH_CRYPTOGRAPHIC) ||
5809 (params->auth_type == OSPF_AUTH_SIMPLE))
5810 {
5811 params->auth_type = OSPF_AUTH_NOTSET;
5812 UNSET_IF_PARAM (params, auth_type);
5813 if (params != IF_DEF_PARAMS (ifp))
5814 {
5815 ospf_free_if_params (ifp, rn->p.u.prefix4);
5816 ospf_if_update_params(ifp, rn->p.u.prefix4);
5817 }
5818 }
5819 }
5820 }
5821 }
5822
5823 return CMD_SUCCESS;
5824 }
5825
5826
5827 DEFUN (ip_ospf_authentication_key,
5828 ip_ospf_authentication_key_addr_cmd,
5829 "ip ospf authentication-key AUTH_KEY [A.B.C.D]",
5830 "IP Information\n"
5831 "OSPF interface commands\n"
5832 "Authentication password (key)\n"
5833 "The OSPF password (key)\n"
5834 "Address of interface")
5835 {
5836 VTY_DECLVAR_CONTEXT(interface, ifp);
5837 int idx = 0;
5838 struct in_addr addr;
5839 struct ospf_if_params *params;
5840
5841 params = IF_DEF_PARAMS (ifp);
5842
5843 if (argv_find (argv, argc, "A.B.C.D", &idx))
5844 {
5845 if (!inet_aton(argv[idx]->arg, &addr))
5846 {
5847 vty_out (vty, "Please specify interface address by A.B.C.D%s",
5848 VTY_NEWLINE);
5849 return CMD_WARNING;
5850 }
5851
5852 params = ospf_get_if_params (ifp, addr);
5853 ospf_if_update_params (ifp, addr);
5854 }
5855
5856 memset (params->auth_simple, 0, OSPF_AUTH_SIMPLE_SIZE + 1);
5857 strncpy ((char *) params->auth_simple, argv[3]->arg, OSPF_AUTH_SIMPLE_SIZE);
5858 SET_IF_PARAM (params, auth_simple);
5859
5860 return CMD_SUCCESS;
5861 }
5862
5863 DEFUN_HIDDEN (ospf_authentication_key,
5864 ospf_authentication_key_cmd,
5865 "ospf authentication-key AUTH_KEY [A.B.C.D]",
5866 "OSPF interface commands\n"
5867 "Authentication password (key)\n"
5868 "The OSPF password (key)\n"
5869 "Address of interface\n")
5870 {
5871 return ip_ospf_authentication_key (self, vty, argc, argv);
5872 }
5873
5874 DEFUN (no_ip_ospf_authentication_key,
5875 no_ip_ospf_authentication_key_authkey_addr_cmd,
5876 "no ip ospf authentication-key [AUTH_KEY [A.B.C.D]]",
5877 NO_STR
5878 "IP Information\n"
5879 "OSPF interface commands\n"
5880 "Authentication password (key)\n"
5881 "The OSPF password (key)")
5882 {
5883 VTY_DECLVAR_CONTEXT(interface, ifp);
5884 int idx = 0;
5885 struct in_addr addr;
5886 struct ospf_if_params *params;
5887 params = IF_DEF_PARAMS (ifp);
5888
5889 if (argv_find (argv, argc, "A.B.C.D", &idx))
5890 {
5891 if (!inet_aton(argv[idx]->arg, &addr))
5892 {
5893 vty_out (vty, "Please specify interface address by A.B.C.D%s",
5894 VTY_NEWLINE);
5895 return CMD_WARNING;
5896 }
5897
5898 params = ospf_lookup_if_params (ifp, addr);
5899 if (params == NULL)
5900 return CMD_SUCCESS;
5901 }
5902
5903 memset (params->auth_simple, 0, OSPF_AUTH_SIMPLE_SIZE);
5904 UNSET_IF_PARAM (params, auth_simple);
5905
5906 if (params != IF_DEF_PARAMS (ifp))
5907 {
5908 ospf_free_if_params (ifp, addr);
5909 ospf_if_update_params (ifp, addr);
5910 }
5911
5912 return CMD_SUCCESS;
5913 }
5914
5915 DEFUN_HIDDEN (no_ospf_authentication_key,
5916 no_ospf_authentication_key_authkey_addr_cmd,
5917 "no ospf authentication-key [AUTH_KEY [A.B.C.D]]",
5918 NO_STR
5919 "OSPF interface commands\n"
5920 "Authentication password (key)\n"
5921 "The OSPF password (key)")
5922 {
5923 return no_ip_ospf_authentication_key (self, vty, argc, argv);
5924 }
5925
5926 DEFUN (ip_ospf_message_digest_key,
5927 ip_ospf_message_digest_key_cmd,
5928 "ip ospf message-digest-key (1-255) md5 KEY [A.B.C.D]",
5929 "IP Information\n"
5930 "OSPF interface commands\n"
5931 "Message digest authentication password (key)\n"
5932 "Key ID\n"
5933 "Use MD5 algorithm\n"
5934 "The OSPF password (key)\n"
5935 "Address of interface\n")
5936 {
5937 VTY_DECLVAR_CONTEXT(interface, ifp);
5938 struct crypt_key *ck;
5939 u_char key_id;
5940 struct in_addr addr;
5941 struct ospf_if_params *params;
5942
5943 params = IF_DEF_PARAMS (ifp);
5944 int idx = 0;
5945
5946 argv_find (argv, argc, "(1-255)", &idx);
5947 char *keyid = argv[idx]->arg;
5948 argv_find (argv, argc, "KEY", &idx);
5949 char *cryptkey = argv[idx]->arg;
5950
5951 if (argv_find (argv, argc, "A.B.C.D", &idx))
5952 {
5953 if (!inet_aton(argv[idx]->arg, &addr))
5954 {
5955 vty_out (vty, "Please specify interface address by A.B.C.D%s",
5956 VTY_NEWLINE);
5957 return CMD_WARNING;
5958 }
5959
5960 params = ospf_get_if_params (ifp, addr);
5961 ospf_if_update_params (ifp, addr);
5962 }
5963
5964 key_id = strtol (keyid, NULL, 10);
5965 if (ospf_crypt_key_lookup (params->auth_crypt, key_id) != NULL)
5966 {
5967 vty_out (vty, "OSPF: Key %d already exists%s", key_id, VTY_NEWLINE);
5968 return CMD_WARNING;
5969 }
5970
5971 ck = ospf_crypt_key_new ();
5972 ck->key_id = (u_char) key_id;
5973 memset (ck->auth_key, 0, OSPF_AUTH_MD5_SIZE+1);
5974 strncpy ((char *) ck->auth_key, cryptkey, OSPF_AUTH_MD5_SIZE);
5975
5976 ospf_crypt_key_add (params->auth_crypt, ck);
5977 SET_IF_PARAM (params, auth_crypt);
5978
5979 return CMD_SUCCESS;
5980 }
5981
5982 DEFUN_HIDDEN (ospf_message_digest_key,
5983 ospf_message_digest_key_cmd,
5984 "ospf message-digest-key (1-255) md5 KEY [A.B.C.D]",
5985 "OSPF interface commands\n"
5986 "Message digest authentication password (key)\n"
5987 "Key ID\n"
5988 "Use MD5 algorithm\n"
5989 "The OSPF password (key)\n"
5990 "Address of interface\n")
5991 {
5992 return ip_ospf_message_digest_key (self, vty, argc, argv);
5993 }
5994
5995 DEFUN (no_ip_ospf_message_digest_key,
5996 no_ip_ospf_message_digest_key_cmd,
5997 "no ip ospf message-digest-key (1-255) [md5 KEY] [A.B.C.D]",
5998 NO_STR
5999 "IP Information\n"
6000 "OSPF interface commands\n"
6001 "Message digest authentication password (key)\n"
6002 "Key ID\n"
6003 "Use MD5 algorithm\n"
6004 "The OSPF password (key)\n"
6005 "Address of interface\n")
6006 {
6007 VTY_DECLVAR_CONTEXT(interface, ifp);
6008 int idx = 0;
6009 struct crypt_key *ck;
6010 int key_id;
6011 struct in_addr addr;
6012 struct ospf_if_params *params;
6013 params = IF_DEF_PARAMS (ifp);
6014
6015 argv_find (argv, argc, "(1-255)", &idx);
6016 char *keyid = argv[idx]->arg;
6017
6018 if (argv_find (argv, argc, "A.B.C.D", &idx))
6019 {
6020 if (!inet_aton(argv[idx]->arg, &addr))
6021 {
6022 vty_out (vty, "Please specify interface address by A.B.C.D%s",
6023 VTY_NEWLINE);
6024 return CMD_WARNING;
6025 }
6026
6027 params = ospf_lookup_if_params (ifp, addr);
6028 if (params == NULL)
6029 return CMD_SUCCESS;
6030 }
6031
6032 key_id = strtol (keyid, NULL, 10);
6033 ck = ospf_crypt_key_lookup (params->auth_crypt, key_id);
6034 if (ck == NULL)
6035 {
6036 vty_out (vty, "OSPF: Key %d does not exist%s", key_id, VTY_NEWLINE);
6037 return CMD_WARNING;
6038 }
6039
6040 ospf_crypt_key_delete (params->auth_crypt, key_id);
6041
6042 if (params != IF_DEF_PARAMS (ifp))
6043 {
6044 ospf_free_if_params (ifp, addr);
6045 ospf_if_update_params (ifp, addr);
6046 }
6047
6048 return CMD_SUCCESS;
6049 }
6050
6051 DEFUN_HIDDEN (no_ospf_message_digest_key,
6052 no_ospf_message_digest_key_cmd,
6053 "no ospf message-digest-key (1-255) [md5 KEY] [A.B.C.D]",
6054 NO_STR
6055 "OSPF interface commands\n"
6056 "Message digest authentication password (key)\n"
6057 "Key ID\n"
6058 "Address of interface")
6059 {
6060 return no_ip_ospf_message_digest_key (self, vty, argc, argv);
6061 }
6062
6063 DEFUN (ip_ospf_cost,
6064 ip_ospf_cost_cmd,
6065 "ip ospf cost (1-65535) [A.B.C.D]",
6066 "IP Information\n"
6067 "OSPF interface commands\n"
6068 "Interface cost\n"
6069 "Cost\n"
6070 "Address of interface\n")
6071 {
6072 VTY_DECLVAR_CONTEXT(interface, ifp);
6073 int idx = 0;
6074 u_int32_t cost;
6075 struct in_addr addr;
6076 struct ospf_if_params *params;
6077 params = IF_DEF_PARAMS (ifp);
6078
6079 // get arguments
6080 char *coststr = NULL, *ifaddr = NULL;
6081 coststr = argv_find (argv, argc, "(1-65535)", &idx) ? argv[idx]->arg : NULL;
6082 ifaddr = argv_find (argv, argc, "A.B.C.D", &idx) ? argv[idx]->arg : NULL;
6083
6084 cost = strtol (coststr, NULL, 10);
6085
6086 if (ifaddr)
6087 {
6088 if(!inet_aton(ifaddr, &addr))
6089 {
6090 vty_out (vty, "Please specify interface address by A.B.C.D%s",
6091 VTY_NEWLINE);
6092 return CMD_WARNING;
6093 }
6094
6095 params = ospf_get_if_params (ifp, addr);
6096 ospf_if_update_params (ifp, addr);
6097 }
6098
6099 SET_IF_PARAM (params, output_cost_cmd);
6100 params->output_cost_cmd = cost;
6101
6102 ospf_if_recalculate_output_cost (ifp);
6103
6104 return CMD_SUCCESS;
6105 }
6106
6107 DEFUN_HIDDEN (ospf_cost,
6108 ospf_cost_cmd,
6109 "ospf cost (1-65535) [A.B.C.D]",
6110 "OSPF interface commands\n"
6111 "Interface cost\n"
6112 "Cost\n"
6113 "Address of interface\n")
6114 {
6115 return ip_ospf_cost (self, vty, argc, argv);
6116 }
6117
6118 DEFUN (no_ip_ospf_cost,
6119 no_ip_ospf_cost_cmd,
6120 "no ip ospf cost [(1-65535)] [A.B.C.D]",
6121 NO_STR
6122 "OSPF interface commands\n"
6123 "Interface cost\n"
6124 "Address of interface")
6125 {
6126 VTY_DECLVAR_CONTEXT(interface, ifp);
6127 int idx = 0;
6128 struct in_addr addr;
6129 struct ospf_if_params *params;
6130
6131 params = IF_DEF_PARAMS (ifp);
6132
6133 // get arguments
6134 char *ifaddr = NULL;
6135 ifaddr = argv_find (argv, argc, "A.B.C.D", &idx) ? argv[idx]->arg : NULL;
6136
6137 /* According to the semantics we are mimicking "no ip ospf cost N" is
6138 * always treated as "no ip ospf cost" regardless of the actual value
6139 * of N already configured for the interface. Thus ignore cost. */
6140
6141 if (ifaddr)
6142 {
6143 if (!inet_aton(ifaddr, &addr))
6144 {
6145 vty_out (vty, "Please specify interface address by A.B.C.D%s",
6146 VTY_NEWLINE);
6147 return CMD_WARNING;
6148 }
6149
6150 params = ospf_lookup_if_params (ifp, addr);
6151 if (params == NULL)
6152 return CMD_SUCCESS;
6153 }
6154
6155 UNSET_IF_PARAM (params, output_cost_cmd);
6156
6157 if (params != IF_DEF_PARAMS (ifp))
6158 {
6159 ospf_free_if_params (ifp, addr);
6160 ospf_if_update_params (ifp, addr);
6161 }
6162
6163 ospf_if_recalculate_output_cost (ifp);
6164
6165 return CMD_SUCCESS;
6166 }
6167
6168 DEFUN_HIDDEN (no_ospf_cost,
6169 no_ospf_cost_cmd,
6170 "no ospf cost [(1-65535)] [A.B.C.D]",
6171 NO_STR
6172 "OSPF interface commands\n"
6173 "Interface cost\n"
6174 "Cost\n"
6175 "Address of interface\n")
6176 {
6177 return no_ip_ospf_cost (self, vty, argc, argv);
6178 }
6179
6180 static void
6181 ospf_nbr_timer_update (struct ospf_interface *oi)
6182 {
6183 struct route_node *rn;
6184 struct ospf_neighbor *nbr;
6185
6186 for (rn = route_top (oi->nbrs); rn; rn = route_next (rn))
6187 if ((nbr = rn->info))
6188 {
6189 nbr->v_inactivity = OSPF_IF_PARAM (oi, v_wait);
6190 nbr->v_db_desc = OSPF_IF_PARAM (oi, retransmit_interval);
6191 nbr->v_ls_req = OSPF_IF_PARAM (oi, retransmit_interval);
6192 nbr->v_ls_upd = OSPF_IF_PARAM (oi, retransmit_interval);
6193 }
6194 }
6195
6196 static int
6197 ospf_vty_dead_interval_set (struct vty *vty, const char *interval_str,
6198 const char *nbr_str,
6199 const char *fast_hello_str)
6200 {
6201 VTY_DECLVAR_CONTEXT(interface, ifp);
6202 u_int32_t seconds;
6203 u_char hellomult;
6204 struct in_addr addr;
6205 int ret;
6206 struct ospf_if_params *params;
6207 struct ospf_interface *oi;
6208 struct route_node *rn;
6209
6210 params = IF_DEF_PARAMS (ifp);
6211
6212 if (nbr_str)
6213 {
6214 ret = inet_aton(nbr_str, &addr);
6215 if (!ret)
6216 {
6217 vty_out (vty, "Please specify interface address by A.B.C.D%s",
6218 VTY_NEWLINE);
6219 return CMD_WARNING;
6220 }
6221
6222 params = ospf_get_if_params (ifp, addr);
6223 ospf_if_update_params (ifp, addr);
6224 }
6225
6226 if (interval_str)
6227 {
6228 VTY_GET_INTEGER_RANGE ("Router Dead Interval", seconds, interval_str,
6229 1, 65535);
6230
6231 /* reset fast_hello too, just to be sure */
6232 UNSET_IF_PARAM (params, fast_hello);
6233 params->fast_hello = OSPF_FAST_HELLO_DEFAULT;
6234 }
6235 else if (fast_hello_str)
6236 {
6237 VTY_GET_INTEGER_RANGE ("Hello Multiplier", hellomult, fast_hello_str,
6238 1, 10);
6239 /* 1s dead-interval with sub-second hellos desired */
6240 seconds = OSPF_ROUTER_DEAD_INTERVAL_MINIMAL;
6241 SET_IF_PARAM (params, fast_hello);
6242 params->fast_hello = hellomult;
6243 }
6244 else
6245 {
6246 vty_out (vty, "Please specify dead-interval or hello-multiplier%s",
6247 VTY_NEWLINE);
6248 return CMD_WARNING;
6249 }
6250
6251 SET_IF_PARAM (params, v_wait);
6252 params->v_wait = seconds;
6253
6254 /* Update timer values in neighbor structure. */
6255 if (nbr_str)
6256 {
6257 struct ospf *ospf;
6258 if ((ospf = ospf_lookup()))
6259 {
6260 oi = ospf_if_lookup_by_local_addr (ospf, ifp, addr);
6261 if (oi)
6262 ospf_nbr_timer_update (oi);
6263 }
6264 }
6265 else
6266 {
6267 for (rn = route_top (IF_OIFS (ifp)); rn; rn = route_next (rn))
6268 if ((oi = rn->info))
6269 ospf_nbr_timer_update (oi);
6270 }
6271
6272 return CMD_SUCCESS;
6273 }
6274
6275 DEFUN (ip_ospf_dead_interval,
6276 ip_ospf_dead_interval_cmd,
6277 "ip ospf dead-interval (1-65535) [A.B.C.D]",
6278 "IP Information\n"
6279 "OSPF interface commands\n"
6280 "Interval time after which a neighbor is declared down\n"
6281 "Seconds\n"
6282 "Address of interface\n")
6283 {
6284 int idx = 0;
6285 char *interval = argv_find (argv, argc, "(1-65535)", &idx) ? argv[idx]->arg : NULL;
6286 char *ifaddr = argv_find (argv, argc, "A.B.C.D", &idx) ? argv[idx]->arg : NULL;
6287 return ospf_vty_dead_interval_set (vty, interval, ifaddr, NULL);
6288 }
6289
6290
6291 DEFUN_HIDDEN (ospf_dead_interval,
6292 ospf_dead_interval_cmd,
6293 "ospf dead-interval (1-65535) [A.B.C.D]",
6294 "OSPF interface commands\n"
6295 "Interval time after which a neighbor is declared down\n"
6296 "Seconds\n"
6297 "Address of interface\n")
6298 {
6299 return ip_ospf_dead_interval (self, vty, argc, argv);
6300 }
6301
6302 DEFUN (ip_ospf_dead_interval_minimal,
6303 ip_ospf_dead_interval_minimal_addr_cmd,
6304 "ip ospf dead-interval minimal hello-multiplier (1-10) [A.B.C.D]",
6305 "IP Information\n"
6306 "OSPF interface commands\n"
6307 "Interval time after which a neighbor is declared down\n"
6308 "Minimal 1s dead-interval with fast sub-second hellos\n"
6309 "Hello multiplier factor\n"
6310 "Number of Hellos to send each second\n"
6311 "Address of interface\n")
6312 {
6313 int idx_number = 5;
6314 int idx_ipv4 = 6;
6315 if (argc == 7)
6316 return ospf_vty_dead_interval_set (vty, NULL, argv[idx_ipv4]->arg, argv[idx_number]->arg);
6317 else
6318 return ospf_vty_dead_interval_set (vty, NULL, NULL, argv[idx_number]->arg);
6319 }
6320
6321 DEFUN (no_ip_ospf_dead_interval,
6322 no_ip_ospf_dead_interval_cmd,
6323 "no ip ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]",
6324 NO_STR
6325 "IP Information\n"
6326 "OSPF interface commands\n"
6327 "Interval time after which a neighbor is declared down\n"
6328 "Seconds\n"
6329 "Address of interface")
6330 {
6331 VTY_DECLVAR_CONTEXT(interface, ifp);
6332 int idx_ipv4 = argc - 1;
6333 struct in_addr addr = { .s_addr = 0L};
6334 int ret;
6335 struct ospf_if_params *params;
6336 struct ospf_interface *oi;
6337 struct route_node *rn;
6338
6339 params = IF_DEF_PARAMS (ifp);
6340
6341 if (argv[idx_ipv4]->type == IPV4_TKN)
6342 {
6343 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
6344 if (!ret)
6345 {
6346 vty_out (vty, "Please specify interface address by A.B.C.D%s",
6347 VTY_NEWLINE);
6348 return CMD_WARNING;
6349 }
6350
6351 params = ospf_lookup_if_params (ifp, addr);
6352 if (params == NULL)
6353 return CMD_SUCCESS;
6354 }
6355
6356 UNSET_IF_PARAM (params, v_wait);
6357 params->v_wait = OSPF_ROUTER_DEAD_INTERVAL_DEFAULT;
6358
6359 UNSET_IF_PARAM (params, fast_hello);
6360 params->fast_hello = OSPF_FAST_HELLO_DEFAULT;
6361
6362 if (params != IF_DEF_PARAMS (ifp))
6363 {
6364 ospf_free_if_params (ifp, addr);
6365 ospf_if_update_params (ifp, addr);
6366 }
6367
6368 /* Update timer values in neighbor structure. */
6369 if (argc == 1)
6370 {
6371 struct ospf *ospf;
6372
6373 if ((ospf = ospf_lookup()))
6374 {
6375 oi = ospf_if_lookup_by_local_addr (ospf, ifp, addr);
6376 if (oi)
6377 ospf_nbr_timer_update (oi);
6378 }
6379 }
6380 else
6381 {
6382 for (rn = route_top (IF_OIFS (ifp)); rn; rn = route_next (rn))
6383 if ((oi = rn->info))
6384 ospf_nbr_timer_update (oi);
6385 }
6386
6387 return CMD_SUCCESS;
6388 }
6389
6390 DEFUN_HIDDEN (no_ospf_dead_interval,
6391 no_ospf_dead_interval_cmd,
6392 "no ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]",
6393 NO_STR
6394 "OSPF interface commands\n"
6395 "Interval time after which a neighbor is declared down\n"
6396 "Seconds\n"
6397 "Address of interface")
6398 {
6399 return no_ip_ospf_dead_interval (self, vty, argc, argv);
6400 }
6401
6402 DEFUN (ip_ospf_hello_interval,
6403 ip_ospf_hello_interval_cmd,
6404 "ip ospf hello-interval (1-65535) [A.B.C.D]",
6405 "IP Information\n"
6406 "OSPF interface commands\n"
6407 "Time between HELLO packets\n"
6408 "Seconds\n"
6409 "Address of interface\n")
6410 {
6411 VTY_DECLVAR_CONTEXT(interface, ifp);
6412 int idx = 0;
6413 struct in_addr addr;
6414 struct ospf_if_params *params;
6415 params = IF_DEF_PARAMS (ifp);
6416 u_int32_t seconds = 0;
6417
6418 argv_find (argv, argc, "(1-65535)", &idx);
6419 seconds = strtol (argv[idx]->arg, NULL, 10);
6420
6421 if (argv_find (argv, argc, "A.B.C.D", &idx))
6422 {
6423 if(!inet_aton(argv[idx]->arg, &addr))
6424 {
6425 vty_out (vty, "Please specify interface address by A.B.C.D%s",
6426 VTY_NEWLINE);
6427 return CMD_WARNING;
6428 }
6429
6430 params = ospf_get_if_params (ifp, addr);
6431 ospf_if_update_params (ifp, addr);
6432 }
6433
6434 SET_IF_PARAM (params, v_hello);
6435 params->v_hello = seconds;
6436
6437 return CMD_SUCCESS;
6438 }
6439
6440 DEFUN_HIDDEN (ospf_hello_interval,
6441 ospf_hello_interval_cmd,
6442 "ospf hello-interval (1-65535) [A.B.C.D]",
6443 "OSPF interface commands\n"
6444 "Time between HELLO packets\n"
6445 "Seconds\n"
6446 "Address of interface\n")
6447 {
6448 return ip_ospf_hello_interval (self, vty, argc, argv);
6449 }
6450
6451 DEFUN (no_ip_ospf_hello_interval,
6452 no_ip_ospf_hello_interval_cmd,
6453 "no ip ospf hello-interval [(1-65535) [A.B.C.D]]",
6454 NO_STR
6455 "IP Information\n"
6456 "OSPF interface commands\n"
6457 "Time between HELLO packets\n" // ignored
6458 "Seconds\n"
6459 "Address of interface\n")
6460 {
6461 VTY_DECLVAR_CONTEXT(interface, ifp);
6462 int idx = 0;
6463 struct in_addr addr;
6464 struct ospf_if_params *params;
6465
6466 params = IF_DEF_PARAMS (ifp);
6467
6468 if (argv_find (argv, argc, "A.B.C.D", &idx))
6469 {
6470 if(!inet_aton(argv[idx]->arg, &addr))
6471 {
6472 vty_out (vty, "Please specify interface address by A.B.C.D%s",
6473 VTY_NEWLINE);
6474 return CMD_WARNING;
6475 }
6476
6477 params = ospf_lookup_if_params (ifp, addr);
6478 if (params == NULL)
6479 return CMD_SUCCESS;
6480 }
6481
6482 UNSET_IF_PARAM (params, v_hello);
6483 params->v_hello = OSPF_HELLO_INTERVAL_DEFAULT;
6484
6485 if (params != IF_DEF_PARAMS (ifp))
6486 {
6487 ospf_free_if_params (ifp, addr);
6488 ospf_if_update_params (ifp, addr);
6489 }
6490
6491 return CMD_SUCCESS;
6492 }
6493
6494 DEFUN_HIDDEN (no_ospf_hello_interval,
6495 no_ospf_hello_interval_cmd,
6496 "no ospf hello-interval [(1-65535) [A.B.C.D]]",
6497 NO_STR
6498 "OSPF interface commands\n"
6499 "Time between HELLO packets\n" // ignored
6500 "Seconds\n"
6501 "Address of interface\n")
6502 {
6503 return no_ip_ospf_hello_interval (self, vty, argc, argv);
6504 }
6505
6506 DEFUN (ip_ospf_network,
6507 ip_ospf_network_cmd,
6508 "ip ospf network <broadcast|non-broadcast|point-to-multipoint|point-to-point>",
6509 "IP Information\n"
6510 "OSPF interface commands\n"
6511 "Network type\n"
6512 "Specify OSPF broadcast multi-access network\n"
6513 "Specify OSPF NBMA network\n"
6514 "Specify OSPF point-to-multipoint network\n"
6515 "Specify OSPF point-to-point network\n")
6516 {
6517 VTY_DECLVAR_CONTEXT(interface, ifp);
6518 int idx = 0;
6519 int old_type = IF_DEF_PARAMS (ifp)->type;
6520 struct route_node *rn;
6521
6522 if (old_type == OSPF_IFTYPE_LOOPBACK)
6523 {
6524 vty_out (vty, "This is a loopback interface. Can't set network type.%s", VTY_NEWLINE);
6525 return CMD_WARNING;
6526 }
6527
6528 if (argv_find (argv, argc, "broadcast", &idx))
6529 IF_DEF_PARAMS (ifp)->type = OSPF_IFTYPE_BROADCAST;
6530 else if (argv_find (argv, argc, "non-broadcast", &idx))
6531 IF_DEF_PARAMS (ifp)->type = OSPF_IFTYPE_NBMA;
6532 else if (argv_find (argv, argc, "point-to-multipoint", &idx))
6533 IF_DEF_PARAMS (ifp)->type = OSPF_IFTYPE_POINTOMULTIPOINT;
6534 else if (argv_find (argv, argc, "point-to-point", &idx))
6535 IF_DEF_PARAMS (ifp)->type = OSPF_IFTYPE_POINTOPOINT;
6536
6537 if (IF_DEF_PARAMS (ifp)->type == old_type)
6538 return CMD_SUCCESS;
6539
6540 SET_IF_PARAM (IF_DEF_PARAMS (ifp), type);
6541
6542 for (rn = route_top (IF_OIFS (ifp)); rn; rn = route_next (rn))
6543 {
6544 struct ospf_interface *oi = rn->info;
6545
6546 if (!oi)
6547 continue;
6548
6549 oi->type = IF_DEF_PARAMS (ifp)->type;
6550
6551 if (oi->state > ISM_Down)
6552 {
6553 OSPF_ISM_EVENT_EXECUTE (oi, ISM_InterfaceDown);
6554 OSPF_ISM_EVENT_EXECUTE (oi, ISM_InterfaceUp);
6555 }
6556 }
6557
6558 return CMD_SUCCESS;
6559 }
6560
6561 DEFUN_HIDDEN (ospf_network,
6562 ospf_network_cmd,
6563 "ospf network <broadcast|non-broadcast|point-to-multipoint|point-to-point>",
6564 "OSPF interface commands\n"
6565 "Network type\n"
6566 "Specify OSPF broadcast multi-access network\n"
6567 "Specify OSPF NBMA network\n"
6568 "Specify OSPF point-to-multipoint network\n"
6569 "Specify OSPF point-to-point network\n")
6570 {
6571 return ip_ospf_network (self, vty, argc, argv);
6572 }
6573
6574 DEFUN (no_ip_ospf_network,
6575 no_ip_ospf_network_cmd,
6576 "no ip ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]",
6577 NO_STR
6578 "IP Information\n"
6579 "OSPF interface commands\n"
6580 "Network type\n"
6581 "Specify OSPF broadcast multi-access network\n"
6582 "Specify OSPF NBMA network\n"
6583 "Specify OSPF point-to-multipoint network\n"
6584 "Specify OSPF point-to-point network\n")
6585 {
6586 VTY_DECLVAR_CONTEXT(interface, ifp);
6587 int old_type = IF_DEF_PARAMS (ifp)->type;
6588 struct route_node *rn;
6589
6590 IF_DEF_PARAMS (ifp)->type = ospf_default_iftype(ifp);
6591
6592 if (IF_DEF_PARAMS (ifp)->type == old_type)
6593 return CMD_SUCCESS;
6594
6595 for (rn = route_top (IF_OIFS (ifp)); rn; rn = route_next (rn))
6596 {
6597 struct ospf_interface *oi = rn->info;
6598
6599 if (!oi)
6600 continue;
6601
6602 oi->type = IF_DEF_PARAMS (ifp)->type;
6603
6604 if (oi->state > ISM_Down)
6605 {
6606 OSPF_ISM_EVENT_EXECUTE (oi, ISM_InterfaceDown);
6607 OSPF_ISM_EVENT_EXECUTE (oi, ISM_InterfaceUp);
6608 }
6609 }
6610
6611 return CMD_SUCCESS;
6612 }
6613
6614 DEFUN_HIDDEN (no_ospf_network,
6615 no_ospf_network_cmd,
6616 "no ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]",
6617 NO_STR
6618 "OSPF interface commands\n"
6619 "Network type\n"
6620 "Specify OSPF broadcast multi-access network\n"
6621 "Specify OSPF NBMA network\n"
6622 "Specify OSPF point-to-multipoint network\n"
6623 "Specify OSPF point-to-point network\n")
6624 {
6625 return no_ip_ospf_network (self, vty, argc, argv);
6626 }
6627
6628 DEFUN (ip_ospf_priority,
6629 ip_ospf_priority_cmd,
6630 "ip ospf priority (0-255) [A.B.C.D]",
6631 "IP Information\n"
6632 "OSPF interface commands\n"
6633 "Router priority\n"
6634 "Priority\n"
6635 "Address of interface")
6636 {
6637 VTY_DECLVAR_CONTEXT(interface, ifp);
6638 int idx = 0;
6639 long priority;
6640 struct route_node *rn;
6641 struct in_addr addr;
6642 struct ospf_if_params *params;
6643 params = IF_DEF_PARAMS (ifp);
6644
6645 argv_find (argv, argc, "(0-255)", &idx);
6646 priority = strtol (argv[idx]->arg, NULL, 10);
6647
6648 if (argv_find (argv, argc, "A.B.C.D", &idx))
6649 {
6650 if (!inet_aton(argv[idx]->arg, &addr))
6651 {
6652 vty_out (vty, "Please specify interface address by A.B.C.D%s",
6653 VTY_NEWLINE);
6654 return CMD_WARNING;
6655 }
6656
6657 params = ospf_get_if_params (ifp, addr);
6658 ospf_if_update_params (ifp, addr);
6659 }
6660
6661 SET_IF_PARAM (params, priority);
6662 params->priority = priority;
6663
6664 for (rn = route_top (IF_OIFS (ifp)); rn; rn = route_next (rn))
6665 {
6666 struct ospf_interface *oi = rn->info;
6667
6668 if (!oi)
6669 continue;
6670
6671 if (PRIORITY (oi) != OSPF_IF_PARAM (oi, priority))
6672 {
6673 PRIORITY (oi) = OSPF_IF_PARAM (oi, priority);
6674 OSPF_ISM_EVENT_SCHEDULE (oi, ISM_NeighborChange);
6675 }
6676 }
6677
6678 return CMD_SUCCESS;
6679 }
6680
6681 DEFUN_HIDDEN (ospf_priority,
6682 ospf_priority_cmd,
6683 "ospf priority (0-255) [A.B.C.D]",
6684 "OSPF interface commands\n"
6685 "Router priority\n"
6686 "Priority\n"
6687 "Address of interface")
6688 {
6689 return ip_ospf_priority (self, vty, argc, argv);
6690 }
6691
6692 DEFUN (no_ip_ospf_priority,
6693 no_ip_ospf_priority_cmd,
6694 "no ip ospf priority [(0-255) [A.B.C.D]]",
6695 NO_STR
6696 "IP Information\n"
6697 "OSPF interface commands\n"
6698 "Router priority\n" // ignored
6699 "Priority\n"
6700 "Address of interface")
6701 {
6702 VTY_DECLVAR_CONTEXT(interface, ifp);
6703 int idx = 0;
6704 struct route_node *rn;
6705 struct in_addr addr;
6706 struct ospf_if_params *params;
6707
6708 params = IF_DEF_PARAMS (ifp);
6709
6710 if (argv_find (argv, argc, "A.B.C.D", &idx))
6711 {
6712 if (!inet_aton(argv[idx]->arg, &addr))
6713 {
6714 vty_out (vty, "Please specify interface address by A.B.C.D%s",
6715 VTY_NEWLINE);
6716 return CMD_WARNING;
6717 }
6718
6719 params = ospf_lookup_if_params (ifp, addr);
6720 if (params == NULL)
6721 return CMD_SUCCESS;
6722 }
6723
6724 UNSET_IF_PARAM (params, priority);
6725 params->priority = OSPF_ROUTER_PRIORITY_DEFAULT;
6726
6727 if (params != IF_DEF_PARAMS (ifp))
6728 {
6729 ospf_free_if_params (ifp, addr);
6730 ospf_if_update_params (ifp, addr);
6731 }
6732
6733 for (rn = route_top (IF_OIFS (ifp)); rn; rn = route_next (rn))
6734 {
6735 struct ospf_interface *oi = rn->info;
6736
6737 if (!oi)
6738 continue;
6739
6740 if (PRIORITY (oi) != OSPF_IF_PARAM (oi, priority))
6741 {
6742 PRIORITY (oi) = OSPF_IF_PARAM (oi, priority);
6743 OSPF_ISM_EVENT_SCHEDULE (oi, ISM_NeighborChange);
6744 }
6745 }
6746
6747 return CMD_SUCCESS;
6748 }
6749
6750 DEFUN_HIDDEN (no_ospf_priority,
6751 no_ospf_priority_cmd,
6752 "no ospf priority [(0-255) [A.B.C.D]]",
6753 NO_STR
6754 "OSPF interface commands\n"
6755 "Router priority\n"
6756 "Priority\n"
6757 "Address of interface")
6758 {
6759 return no_ip_ospf_priority (self, vty, argc, argv);
6760 }
6761
6762 DEFUN (ip_ospf_retransmit_interval,
6763 ip_ospf_retransmit_interval_addr_cmd,
6764 "ip ospf retransmit-interval (3-65535) [A.B.C.D]",
6765 "IP Information\n"
6766 "OSPF interface commands\n"
6767 "Time between retransmitting lost link state advertisements\n"
6768 "Seconds\n"
6769 "Address of interface")
6770 {
6771 VTY_DECLVAR_CONTEXT(interface, ifp);
6772 int idx = 0;
6773 u_int32_t seconds;
6774 struct in_addr addr;
6775 struct ospf_if_params *params;
6776 params = IF_DEF_PARAMS (ifp);
6777
6778 argv_find (argv, argc, "(3-65535)", &idx);
6779 seconds = strtol (argv[idx]->arg, NULL, 10);
6780
6781 if (argv_find (argv, argc, "A.B.C.D", &idx))
6782 {
6783 if (!inet_aton(argv[idx]->arg, &addr))
6784 {
6785 vty_out (vty, "Please specify interface address by A.B.C.D%s",
6786 VTY_NEWLINE);
6787 return CMD_WARNING;
6788 }
6789
6790 params = ospf_get_if_params (ifp, addr);
6791 ospf_if_update_params (ifp, addr);
6792 }
6793
6794 SET_IF_PARAM (params, retransmit_interval);
6795 params->retransmit_interval = seconds;
6796
6797 return CMD_SUCCESS;
6798 }
6799
6800 DEFUN_HIDDEN (ospf_retransmit_interval,
6801 ospf_retransmit_interval_cmd,
6802 "ospf retransmit-interval (3-65535) [A.B.C.D]",
6803 "OSPF interface commands\n"
6804 "Time between retransmitting lost link state advertisements\n"
6805 "Seconds\n"
6806 "Address of interface")
6807 {
6808 return ip_ospf_retransmit_interval (self, vty, argc, argv);
6809 }
6810
6811 DEFUN (no_ip_ospf_retransmit_interval,
6812 no_ip_ospf_retransmit_interval_addr_cmd,
6813 "no ip ospf retransmit-interval [(3-65535)] [A.B.C.D]",
6814 NO_STR
6815 "IP Information\n"
6816 "OSPF interface commands\n"
6817 "Time between retransmitting lost link state advertisements\n"
6818 "Seconds\n"
6819 "Address of interface\n")
6820 {
6821 VTY_DECLVAR_CONTEXT(interface, ifp);
6822 int idx = 0;
6823 struct in_addr addr;
6824 struct ospf_if_params *params;
6825
6826 params = IF_DEF_PARAMS (ifp);
6827
6828 if (argv_find (argv, argc, "A.B.C.D", &idx))
6829 {
6830 if (!inet_aton(argv[idx]->arg, &addr))
6831 {
6832 vty_out (vty, "Please specify interface address by A.B.C.D%s",
6833 VTY_NEWLINE);
6834 return CMD_WARNING;
6835 }
6836
6837 params = ospf_lookup_if_params (ifp, addr);
6838 if (params == NULL)
6839 return CMD_SUCCESS;
6840 }
6841
6842 UNSET_IF_PARAM (params, retransmit_interval);
6843 params->retransmit_interval = OSPF_RETRANSMIT_INTERVAL_DEFAULT;
6844
6845 if (params != IF_DEF_PARAMS (ifp))
6846 {
6847 ospf_free_if_params (ifp, addr);
6848 ospf_if_update_params (ifp, addr);
6849 }
6850
6851 return CMD_SUCCESS;
6852 }
6853
6854 DEFUN_HIDDEN (no_ospf_retransmit_interval,
6855 no_ospf_retransmit_interval_cmd,
6856 "no ospf retransmit-interval [(3-65535)] [A.B.C.D]",
6857 NO_STR
6858 "OSPF interface commands\n"
6859 "Time between retransmitting lost link state advertisements\n"
6860 "Seconds\n"
6861 "Address of interface\n")
6862 {
6863 return no_ip_ospf_retransmit_interval (self, vty, argc, argv);
6864 }
6865
6866 DEFUN (ip_ospf_transmit_delay,
6867 ip_ospf_transmit_delay_addr_cmd,
6868 "ip ospf transmit-delay (1-65535) [A.B.C.D]",
6869 "IP Information\n"
6870 "OSPF interface commands\n"
6871 "Link state transmit delay\n"
6872 "Seconds\n"
6873 "Address of interface")
6874 {
6875 VTY_DECLVAR_CONTEXT(interface, ifp);
6876 int idx = 0;
6877 u_int32_t seconds;
6878 struct in_addr addr;
6879 struct ospf_if_params *params;
6880
6881 params = IF_DEF_PARAMS (ifp);
6882 argv_find (argv, argc, "(1-65535)", &idx);
6883 seconds = strtol (argv[idx]->arg, NULL, 10);
6884
6885 if (argv_find (argv, argc, "A.B.C.D", &idx))
6886 {
6887 if (!inet_aton(argv[idx]->arg, &addr))
6888 {
6889 vty_out (vty, "Please specify interface address by A.B.C.D%s",
6890 VTY_NEWLINE);
6891 return CMD_WARNING;
6892 }
6893
6894 params = ospf_get_if_params (ifp, addr);
6895 ospf_if_update_params (ifp, addr);
6896 }
6897
6898 SET_IF_PARAM (params, transmit_delay);
6899 params->transmit_delay = seconds;
6900
6901 return CMD_SUCCESS;
6902 }
6903
6904 DEFUN_HIDDEN (ospf_transmit_delay,
6905 ospf_transmit_delay_cmd,
6906 "ospf transmit-delay (1-65535) [A.B.C.D]",
6907 "OSPF interface commands\n"
6908 "Link state transmit delay\n"
6909 "Seconds\n"
6910 "Address of interface")
6911 {
6912 return ip_ospf_transmit_delay (self, vty, argc, argv);
6913 }
6914
6915 DEFUN (no_ip_ospf_transmit_delay,
6916 no_ip_ospf_transmit_delay_addr_cmd,
6917 "no ip ospf transmit-delay [(1-65535)] [A.B.C.D]",
6918 NO_STR
6919 "IP Information\n"
6920 "OSPF interface commands\n"
6921 "Link state transmit delay\n"
6922 "Address of interface")
6923 {
6924 VTY_DECLVAR_CONTEXT(interface, ifp);
6925 int idx = 0;
6926 struct in_addr addr;
6927 struct ospf_if_params *params;
6928
6929 params = IF_DEF_PARAMS (ifp);
6930
6931 if (argv_find (argv, argc, "A.B.C.D", &idx))
6932 {
6933 if (!inet_aton(argv[idx]->arg, &addr))
6934 {
6935 vty_out (vty, "Please specify interface address by A.B.C.D%s",
6936 VTY_NEWLINE);
6937 return CMD_WARNING;
6938 }
6939
6940 params = ospf_lookup_if_params (ifp, addr);
6941 if (params == NULL)
6942 return CMD_SUCCESS;
6943 }
6944
6945 UNSET_IF_PARAM (params, transmit_delay);
6946 params->transmit_delay = OSPF_TRANSMIT_DELAY_DEFAULT;
6947
6948 if (params != IF_DEF_PARAMS (ifp))
6949 {
6950 ospf_free_if_params (ifp, addr);
6951 ospf_if_update_params (ifp, addr);
6952 }
6953
6954 return CMD_SUCCESS;
6955 }
6956
6957
6958 DEFUN_HIDDEN (no_ospf_transmit_delay,
6959 no_ospf_transmit_delay_cmd,
6960 "no ospf transmit-delay",
6961 NO_STR
6962 "OSPF interface commands\n"
6963 "Link state transmit delay\n")
6964 {
6965 return no_ip_ospf_transmit_delay (self, vty, argc, argv);
6966 }
6967
6968 DEFUN (ip_ospf_area,
6969 ip_ospf_area_cmd,
6970 "ip ospf [(1-65535)] area <A.B.C.D|(0-4294967295)>",
6971 "IP Information\n"
6972 "OSPF interface commands\n"
6973 "Instance ID\n"
6974 "Enable OSPF on this interface\n"
6975 "OSPF area ID in IP address format\n"
6976 "OSPF area ID as a decimal value\n")
6977 {
6978 VTY_DECLVAR_CONTEXT(interface, ifp);
6979 int idx = 0;
6980 int format, ret;
6981 struct in_addr area_id;
6982 struct ospf *ospf;
6983 struct ospf_if_params *params;
6984 struct route_node *rn;
6985 u_short instance = 0;
6986
6987 if (argv_find (argv, argc, "(1-65535)", &idx))
6988 instance = strtol (argv[idx]->arg, NULL, 10);
6989 char *areaid = argv[argc - 1]->arg;
6990
6991 ospf = ospf_lookup_instance (instance);
6992 if (ospf == NULL)
6993 {
6994 params = IF_DEF_PARAMS (ifp);
6995 if (OSPF_IF_PARAM_CONFIGURED(params, if_area))
6996 {
6997 ospf_interface_unset (ifp);
6998 ospf = ospf_lookup();
6999 ospf->if_ospf_cli_count--;
7000 }
7001 return CMD_SUCCESS;
7002 }
7003
7004 ret = str2area_id (areaid, &area_id, &format);
7005 if (ret < 0)
7006 {
7007 vty_out (vty, "Please specify area by A.B.C.D|<0-4294967295>%s",
7008 VTY_NEWLINE);
7009 return CMD_WARNING;
7010 }
7011 if (memcmp (ifp->name, "VLINK", 5) == 0)
7012 {
7013 vty_out (vty, "Cannot enable OSPF on a virtual link.%s", VTY_NEWLINE);
7014 return CMD_WARNING;
7015 }
7016
7017 params = IF_DEF_PARAMS (ifp);
7018 if (OSPF_IF_PARAM_CONFIGURED(params, if_area))
7019 {
7020 vty_out (vty,
7021 "Must remove previous area config before changing ospf area %s",
7022 VTY_NEWLINE);
7023 return CMD_WARNING;
7024 }
7025
7026 for (rn = route_top (ospf->networks); rn; rn = route_next (rn))
7027 {
7028 if (rn->info != NULL)
7029 {
7030 vty_out (vty, "Please remove all network commands first.%s", VTY_NEWLINE);
7031 return CMD_WARNING;
7032 }
7033 }
7034
7035 /* enable ospf on this interface with area_id */
7036 ospf_interface_set (ifp, area_id);
7037 ospf->if_ospf_cli_count++;
7038
7039 return CMD_SUCCESS;
7040 }
7041
7042 DEFUN (no_ip_ospf_area,
7043 no_ip_ospf_area_cmd,
7044 "no ip ospf [(1-65535)] area [<A.B.C.D|(0-4294967295)>]",
7045 NO_STR
7046 "IP Information\n"
7047 "OSPF interface commands\n"
7048 "Instance ID\n"
7049 "Disable OSPF on this interface\n"
7050 "OSPF area ID in IP address format\n"
7051 "OSPF area ID as a decimal value\n")
7052 {
7053 VTY_DECLVAR_CONTEXT(interface, ifp);
7054 int idx = 0;
7055 struct ospf *ospf;
7056 struct ospf_if_params *params;
7057 u_short instance = 0;
7058
7059 if (argv_find (argv, argc, "(1-65535)", &idx))
7060 instance = strtol (argv[idx]->arg, NULL, 10);
7061
7062 if ((ospf = ospf_lookup_instance (instance)) == NULL)
7063 return CMD_SUCCESS;
7064
7065 params = IF_DEF_PARAMS (ifp);
7066 if (!OSPF_IF_PARAM_CONFIGURED(params, if_area))
7067 {
7068 vty_out (vty, "Can't find specified interface area configuration.%s", VTY_NEWLINE);
7069 return CMD_WARNING;
7070 }
7071
7072 ospf_interface_unset (ifp);
7073 ospf->if_ospf_cli_count--;
7074 return CMD_SUCCESS;
7075 }
7076
7077 DEFUN (ospf_redistribute_source,
7078 ospf_redistribute_source_cmd,
7079 "redistribute " FRR_REDIST_STR_OSPFD " [<metric (0-16777214)|metric-type (1-2)|route-map WORD>]",
7080 REDIST_STR
7081 FRR_REDIST_HELP_STR_OSPFD
7082 "Metric for redistributed routes\n"
7083 "OSPF default metric\n"
7084 "OSPF exterior metric type for redistributed routes\n"
7085 "Set OSPF External Type 1 metrics\n"
7086 "Set OSPF External Type 2 metrics\n"
7087 "Route map reference\n"
7088 "Pointer to route-map entries\n")
7089 {
7090 VTY_DECLVAR_CONTEXT(ospf, ospf);
7091 int idx_protocol = 1;
7092 int source;
7093 int type = -1;
7094 int metric = -1;
7095 struct ospf_redist *red;
7096 int idx = 0;
7097
7098 if (!ospf)
7099 return CMD_SUCCESS;
7100
7101 /* Get distribute source. */
7102 source = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
7103 if (source < 0)
7104 return CMD_WARNING;
7105
7106 red = ospf_redist_add(ospf, source, 0);
7107
7108 /* Get metric value. */
7109 if (argv_find (argv, argc, "(0-16777214)", &idx)) {
7110 if (!str2metric (argv[idx]->arg, &metric))
7111 return CMD_WARNING;
7112 }
7113 /* Get metric type. */
7114 else if (argv_find (argv, argc, "(1-2)", &idx)) {
7115 if (!str2metric_type (argv[idx]->arg, &type))
7116 return CMD_WARNING;
7117 }
7118 /* Get route-map */
7119 else if (argv_find (argv, argc, "WORD", &idx)) {
7120 ospf_routemap_set (red, argv[idx]->arg);
7121 }
7122 else
7123 ospf_routemap_unset (red);
7124
7125 return ospf_redistribute_set (ospf, source, 0, type, metric);
7126 }
7127
7128 DEFUN (no_ospf_redistribute_source,
7129 no_ospf_redistribute_source_cmd,
7130 "no redistribute " FRR_REDIST_STR_OSPFD " [<metric (0-16777214)|metric-type (1-2)|route-map WORD>]",
7131 NO_STR
7132 REDIST_STR
7133 FRR_REDIST_HELP_STR_OSPFD
7134 "Metric for redistributed routes\n"
7135 "OSPF default metric\n"
7136 "OSPF exterior metric type for redistributed routes\n"
7137 "Set OSPF External Type 1 metrics\n"
7138 "Set OSPF External Type 2 metrics\n"
7139 "Route map reference\n"
7140 "Pointer to route-map entries\n")
7141 {
7142 VTY_DECLVAR_CONTEXT(ospf, ospf);
7143 int idx_protocol = 2;
7144 int source;
7145 struct ospf_redist *red;
7146
7147 source = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
7148 if (source < 0)
7149 return CMD_WARNING;
7150
7151 red = ospf_redist_lookup(ospf, source, 0);
7152 if (!red)
7153 return CMD_SUCCESS;
7154
7155 ospf_routemap_unset (red);
7156 return ospf_redistribute_unset (ospf, source, 0);
7157 }
7158
7159 DEFUN (ospf_redistribute_instance_source,
7160 ospf_redistribute_instance_source_cmd,
7161 "redistribute <ospf|table> (1-65535) [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
7162 REDIST_STR
7163 "Open Shortest Path First\n"
7164 "Non-main Kernel Routing Table\n"
7165 "Instance ID/Table ID\n"
7166 "Metric for redistributed routes\n"
7167 "OSPF default metric\n"
7168 "OSPF exterior metric type for redistributed routes\n"
7169 "Set OSPF External Type 1 metrics\n"
7170 "Set OSPF External Type 2 metrics\n"
7171 "Route map reference\n"
7172 "Pointer to route-map entries\n")
7173 {
7174 VTY_DECLVAR_CONTEXT(ospf, ospf);
7175 int idx_ospf_table = 1;
7176 int idx_number = 2;
7177 int idx = 3;
7178 int source;
7179 int type = -1;
7180 int metric = -1;
7181 u_short instance;
7182 struct ospf_redist *red;
7183
7184 if (!ospf)
7185 return CMD_SUCCESS;
7186
7187 source = proto_redistnum (AFI_IP, argv[idx_ospf_table]->text);
7188
7189 VTY_GET_INTEGER ("Instance ID", instance, argv[idx_number]->arg);
7190
7191 if (!ospf)
7192 return CMD_SUCCESS;
7193
7194 if ((source == ZEBRA_ROUTE_OSPF) && !ospf->instance)
7195 {
7196 vty_out (vty, "Instance redistribution in non-instanced OSPF not allowed%s",
7197 VTY_NEWLINE);
7198 return CMD_WARNING;
7199 }
7200
7201 if ((source == ZEBRA_ROUTE_OSPF) && (ospf->instance == instance))
7202 {
7203 vty_out (vty, "Same instance OSPF redistribution not allowed%s",
7204 VTY_NEWLINE);
7205 return CMD_WARNING;
7206 }
7207
7208 /* Get metric value. */
7209 if (argv_find (argv, argc, "metric", &idx))
7210 if (!str2metric (argv[idx+1]->arg, &metric))
7211 return CMD_WARNING;
7212
7213 idx = 3;
7214 /* Get metric type. */
7215 if (argv_find (argv, argc, "metric-type", &idx))
7216 if (!str2metric_type (argv[idx+1]->arg, &type))
7217 return CMD_WARNING;
7218
7219 red = ospf_redist_add(ospf, source, instance);
7220
7221 idx = 3;
7222 if (argv_find (argv, argc, "route-map", &idx))
7223 ospf_routemap_set (red, argv[idx+1]->arg);
7224 else
7225 ospf_routemap_unset (red);
7226
7227 return ospf_redistribute_set (ospf, source, instance, type, metric);
7228 }
7229
7230 DEFUN (no_ospf_redistribute_instance_source,
7231 no_ospf_redistribute_instance_source_cmd,
7232 "no redistribute <ospf|table> (1-65535) [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
7233 NO_STR
7234 REDIST_STR
7235 "Open Shortest Path First\n"
7236 "Non-main Kernel Routing Table\n"
7237 "Instance ID/Table Id\n"
7238 "Metric for redistributed routes\n"
7239 "OSPF default metric\n"
7240 "OSPF exterior metric type for redistributed routes\n"
7241 "Set OSPF External Type 1 metrics\n"
7242 "Set OSPF External Type 2 metrics\n"
7243 "Route map reference\n"
7244 "Pointer to route-map entries\n")
7245 {
7246 VTY_DECLVAR_CONTEXT(ospf, ospf);
7247 int idx_ospf_table = 2;
7248 int idx_number = 3;
7249 u_int instance;
7250 struct ospf_redist *red;
7251 int source;
7252
7253 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
7254 source = ZEBRA_ROUTE_OSPF;
7255 else
7256 source = ZEBRA_ROUTE_TABLE;
7257
7258 VTY_GET_INTEGER ("Instance ID", instance, argv[idx_number]->arg);
7259
7260 if ((source == ZEBRA_ROUTE_OSPF) && !ospf->instance)
7261 {
7262 vty_out (vty, "Instance redistribution in non-instanced OSPF not allowed%s",
7263 VTY_NEWLINE);
7264 return CMD_WARNING;
7265 }
7266
7267 if ((source == ZEBRA_ROUTE_OSPF) && (ospf->instance == instance))
7268 {
7269 vty_out (vty, "Same instance OSPF redistribution not allowed%s",
7270 VTY_NEWLINE);
7271 return CMD_WARNING;
7272 }
7273
7274 red = ospf_redist_lookup(ospf, source, instance);
7275 if (!red)
7276 return CMD_SUCCESS;
7277
7278 ospf_routemap_unset (red);
7279 return ospf_redistribute_unset (ospf, source, instance);
7280 }
7281
7282 DEFUN (ospf_distribute_list_out,
7283 ospf_distribute_list_out_cmd,
7284 "distribute-list WORD out " FRR_REDIST_STR_OSPFD,
7285 "Filter networks in routing updates\n"
7286 "Access-list name\n"
7287 OUT_STR
7288 FRR_REDIST_HELP_STR_OSPFD)
7289 {
7290 VTY_DECLVAR_CONTEXT(ospf, ospf);
7291 int idx_word = 1;
7292 int source;
7293
7294 char *proto = argv[argc - 1]->text;
7295
7296 /* Get distribute source. */
7297 source = proto_redistnum(AFI_IP, proto);
7298 if (source < 0)
7299 return CMD_WARNING;
7300
7301 return ospf_distribute_list_out_set (ospf, source, argv[idx_word]->arg);
7302 }
7303
7304 DEFUN (no_ospf_distribute_list_out,
7305 no_ospf_distribute_list_out_cmd,
7306 "no distribute-list WORD out " FRR_REDIST_STR_OSPFD,
7307 NO_STR
7308 "Filter networks in routing updates\n"
7309 "Access-list name\n"
7310 OUT_STR
7311 FRR_REDIST_HELP_STR_OSPFD)
7312 {
7313 VTY_DECLVAR_CONTEXT(ospf, ospf);
7314 int idx_word = 2;
7315 int source;
7316
7317 char *proto = argv[argc - 1]->text;
7318 source = proto_redistnum(AFI_IP, proto);
7319 if (source < 0)
7320 return CMD_WARNING;
7321
7322 return ospf_distribute_list_out_unset (ospf, source, argv[idx_word]->arg);
7323 }
7324
7325 /* Default information originate. */
7326 DEFUN (ospf_default_information_originate,
7327 ospf_default_information_originate_cmd,
7328 "default-information originate [<always|metric (0-16777214)|metric-type (1-2)|route-map WORD>]",
7329 "Control distribution of default information\n"
7330 "Distribute a default route\n"
7331 "Always advertise default route\n"
7332 "OSPF default metric\n"
7333 "OSPF metric\n"
7334 "OSPF metric type for default routes\n"
7335 "Set OSPF External Type 1 metrics\n"
7336 "Set OSPF External Type 2 metrics\n"
7337 "Route map reference\n"
7338 "Pointer to route-map entries\n")
7339 {
7340 VTY_DECLVAR_CONTEXT(ospf, ospf);
7341 int default_originate = DEFAULT_ORIGINATE_ZEBRA;
7342 int type = -1;
7343 int metric = -1;
7344 struct ospf_redist *red;
7345 int idx = 0;
7346
7347 red = ospf_redist_add(ospf, DEFAULT_ROUTE, 0);
7348
7349 /* Check whether "always" was specified */
7350 if (argv_find (argv, argc, "always", &idx))
7351 default_originate = DEFAULT_ORIGINATE_ALWAYS;
7352 /* Get metric value */
7353 else if (argv_find (argv, argc, "(0-16777214)", &idx)) {
7354 if (!str2metric (argv[idx]->arg, &metric))
7355 return CMD_WARNING;
7356 }
7357 /* Get metric type. */
7358 else if (argv_find (argv, argc, "(1-2)", &idx)) {
7359 if (!str2metric_type (argv[idx]->arg, &type))
7360 return CMD_WARNING;
7361 }
7362 /* Get route-map */
7363 else if (argv_find (argv, argc, "WORD", &idx))
7364 ospf_routemap_set (red, argv[idx]->arg);
7365 else
7366 ospf_routemap_unset (red);
7367
7368 return ospf_redistribute_default_set (ospf, default_originate,
7369 type, metric);
7370 }
7371
7372 DEFUN (no_ospf_default_information_originate,
7373 no_ospf_default_information_originate_cmd,
7374 "no default-information originate [<always|metric (0-16777214)|metric-type (1-2)|route-map WORD>]",
7375 NO_STR
7376 "Control distribution of default information\n"
7377 "Distribute a default route\n"
7378 "Always advertise default route\n"
7379 "OSPF default metric\n"
7380 "OSPF metric\n"
7381 "OSPF metric type for default routes\n"
7382 "Set OSPF External Type 1 metrics\n"
7383 "Set OSPF External Type 2 metrics\n"
7384 "Route map reference\n"
7385 "Pointer to route-map entries\n")
7386 {
7387 VTY_DECLVAR_CONTEXT(ospf, ospf);
7388 struct prefix_ipv4 p;
7389 struct ospf_external *ext;
7390 struct ospf_redist *red;
7391
7392 p.family = AF_INET;
7393 p.prefix.s_addr = 0;
7394 p.prefixlen = 0;
7395
7396 ospf_external_lsa_flush (ospf, DEFAULT_ROUTE, &p, 0);
7397
7398 if ((ext = ospf_external_lookup(DEFAULT_ROUTE, 0)) &&
7399 EXTERNAL_INFO (ext)) {
7400 ospf_external_info_delete (DEFAULT_ROUTE, 0, p);
7401 ospf_external_del (DEFAULT_ROUTE, 0);
7402 }
7403
7404 red = ospf_redist_lookup(ospf, DEFAULT_ROUTE, 0);
7405 if (!red)
7406 return CMD_SUCCESS;
7407
7408 ospf_routemap_unset (red);
7409 return ospf_redistribute_default_unset (ospf);
7410 }
7411
7412 DEFUN (ospf_default_metric,
7413 ospf_default_metric_cmd,
7414 "default-metric (0-16777214)",
7415 "Set metric of redistributed routes\n"
7416 "Default metric\n")
7417 {
7418 VTY_DECLVAR_CONTEXT(ospf, ospf);
7419 int idx_number = 1;
7420 int metric = -1;
7421
7422 if (!str2metric (argv[idx_number]->arg, &metric))
7423 return CMD_WARNING;
7424
7425 ospf->default_metric = metric;
7426
7427 return CMD_SUCCESS;
7428 }
7429
7430 DEFUN (no_ospf_default_metric,
7431 no_ospf_default_metric_cmd,
7432 "no default-metric [(0-16777214)]",
7433 NO_STR
7434 "Set metric of redistributed routes\n"
7435 "Default metric\n")
7436 {
7437 VTY_DECLVAR_CONTEXT(ospf, ospf);
7438
7439 ospf->default_metric = -1;
7440
7441 return CMD_SUCCESS;
7442 }
7443
7444
7445 DEFUN (ospf_distance,
7446 ospf_distance_cmd,
7447 "distance (1-255)",
7448 "Administrative distance\n"
7449 "OSPF Administrative distance\n")
7450 {
7451 VTY_DECLVAR_CONTEXT(ospf, ospf);
7452 int idx_number = 1;
7453
7454 ospf->distance_all = atoi (argv[idx_number]->arg);
7455
7456 return CMD_SUCCESS;
7457 }
7458
7459 DEFUN (no_ospf_distance,
7460 no_ospf_distance_cmd,
7461 "no distance (1-255)",
7462 NO_STR
7463 "Administrative distance\n"
7464 "OSPF Administrative distance\n")
7465 {
7466 VTY_DECLVAR_CONTEXT(ospf, ospf);
7467
7468 ospf->distance_all = 0;
7469
7470 return CMD_SUCCESS;
7471 }
7472
7473 DEFUN (no_ospf_distance_ospf,
7474 no_ospf_distance_ospf_cmd,
7475 "no distance ospf [{intra-area [(1-255)]|inter-area [(1-255)]|external [(1-255)]}]",
7476 NO_STR
7477 "Administrative distance\n"
7478 "OSPF administrative distance\n"
7479 "Intra-area routes\n"
7480 "Distance for intra-area routes\n"
7481 "Inter-area routes\n"
7482 "Distance for inter-area routes\n"
7483 "External routes\n"
7484 "Distance for external routes\n")
7485 {
7486 VTY_DECLVAR_CONTEXT(ospf, ospf);
7487 int idx = 0;
7488
7489 if (!ospf)
7490 return CMD_SUCCESS;
7491
7492 if (argv_find (argv, argc, "intra-area", &idx) || argc == 3)
7493 idx = ospf->distance_intra = 0;
7494 if (argv_find (argv, argc, "inter-area", &idx) || argc == 3)
7495 idx = ospf->distance_inter = 0;
7496 if (argv_find (argv, argc, "external", &idx) || argc == 3)
7497 ospf->distance_external = 0;
7498
7499 return CMD_SUCCESS;
7500 }
7501
7502 DEFUN (ospf_distance_ospf,
7503 ospf_distance_ospf_cmd,
7504 "distance ospf {intra-area (1-255)|inter-area (1-255)|external (1-255)}",
7505 "Administrative distance\n"
7506 "OSPF administrative distance\n"
7507 "Intra-area routes\n"
7508 "Distance for intra-area routes\n"
7509 "Inter-area routes\n"
7510 "Distance for inter-area routes\n"
7511 "External routes\n"
7512 "Distance for external routes\n")
7513 {
7514 VTY_DECLVAR_CONTEXT(ospf, ospf);
7515 int idx = 0;
7516
7517 if (argv_find (argv, argc, "intra-area", &idx))
7518 ospf->distance_intra = atoi(argv[idx + 1]->arg);
7519 idx = 0;
7520 if (argv_find (argv, argc, "inter-area", &idx))
7521 ospf->distance_inter = atoi(argv[idx + 1]->arg);
7522 idx = 0;
7523 if (argv_find (argv, argc, "external", &idx))
7524 ospf->distance_external = atoi(argv[idx + 1]->arg);
7525
7526 return CMD_SUCCESS;
7527 }
7528
7529 #if 0
7530 DEFUN (ospf_distance_source,
7531 ospf_distance_source_cmd,
7532 "distance (1-255) A.B.C.D/M",
7533 "Administrative distance\n"
7534 "Distance value\n"
7535 "IP source prefix\n")
7536 {
7537 VTY_DECLVAR_CONTEXT(ospf, ospf);
7538 int idx_number = 1;
7539 int idx_ipv4_prefixlen = 2;
7540
7541 if (!ospf)
7542 return CMD_SUCCESS;
7543
7544 ospf_distance_set (vty, ospf, argv[idx_number]->arg, argv[idx_ipv4_prefixlen]->arg, NULL);
7545
7546 return CMD_SUCCESS;
7547 }
7548
7549 DEFUN (no_ospf_distance_source,
7550 no_ospf_distance_source_cmd,
7551 "no distance (1-255) A.B.C.D/M",
7552 NO_STR
7553 "Administrative distance\n"
7554 "Distance value\n"
7555 "IP source prefix\n")
7556 {
7557 VTY_DECLVAR_CONTEXT(ospf, ospf);
7558 int idx_number = 2;
7559 int idx_ipv4_prefixlen = 3;
7560
7561 if (!ospf)
7562 return CMD_SUCCESS;
7563
7564 ospf_distance_unset (vty, ospf, argv[idx_number]->arg, argv[idx_ipv4_prefixlen]->arg, NULL);
7565
7566 return CMD_SUCCESS;
7567 }
7568
7569 DEFUN (ospf_distance_source_access_list,
7570 ospf_distance_source_access_list_cmd,
7571 "distance (1-255) A.B.C.D/M WORD",
7572 "Administrative distance\n"
7573 "Distance value\n"
7574 "IP source prefix\n"
7575 "Access list name\n")
7576 {
7577 VTY_DECLVAR_CONTEXT(ospf, ospf);
7578 int idx_number = 1;
7579 int idx_ipv4_prefixlen = 2;
7580 int idx_word = 3;
7581
7582 if (!ospf)
7583 return CMD_SUCCESS;
7584
7585 ospf_distance_set (vty, ospf, argv[idx_number]->arg, argv[idx_ipv4_prefixlen]->arg, argv[idx_word]->arg);
7586
7587 return CMD_SUCCESS;
7588 }
7589
7590 DEFUN (no_ospf_distance_source_access_list,
7591 no_ospf_distance_source_access_list_cmd,
7592 "no distance (1-255) A.B.C.D/M WORD",
7593 NO_STR
7594 "Administrative distance\n"
7595 "Distance value\n"
7596 "IP source prefix\n"
7597 "Access list name\n")
7598 {
7599 VTY_DECLVAR_CONTEXT(ospf, ospf);
7600 int idx_number = 2;
7601 int idx_ipv4_prefixlen = 3;
7602 int idx_word = 4;
7603
7604 if (!ospf)
7605 return CMD_SUCCESS;
7606
7607 ospf_distance_unset (vty, ospf, argv[idx_number]->arg, argv[idx_ipv4_prefixlen]->arg, argv[idx_word]->arg);
7608
7609 return CMD_SUCCESS;
7610 }
7611 #endif
7612
7613 DEFUN (ip_ospf_mtu_ignore,
7614 ip_ospf_mtu_ignore_addr_cmd,
7615 "ip ospf mtu-ignore [A.B.C.D]",
7616 "IP Information\n"
7617 "OSPF interface commands\n"
7618 "Disable MTU mismatch detection on this interface\n"
7619 "Address of interface")
7620 {
7621 VTY_DECLVAR_CONTEXT(interface, ifp);
7622 int idx_ipv4 = 3;
7623 struct in_addr addr;
7624 int ret;
7625
7626 struct ospf_if_params *params;
7627 params = IF_DEF_PARAMS (ifp);
7628
7629 if (argc == 4)
7630 {
7631 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
7632 if (!ret)
7633 {
7634 vty_out (vty, "Please specify interface address by A.B.C.D%s",
7635 VTY_NEWLINE);
7636 return CMD_WARNING;
7637 }
7638 params = ospf_get_if_params (ifp, addr);
7639 ospf_if_update_params (ifp, addr);
7640 }
7641 params->mtu_ignore = 1;
7642 if (params->mtu_ignore != OSPF_MTU_IGNORE_DEFAULT)
7643 SET_IF_PARAM (params, mtu_ignore);
7644 else
7645 {
7646 UNSET_IF_PARAM (params, mtu_ignore);
7647 if (params != IF_DEF_PARAMS (ifp))
7648 {
7649 ospf_free_if_params (ifp, addr);
7650 ospf_if_update_params (ifp, addr);
7651 }
7652 }
7653 return CMD_SUCCESS;
7654 }
7655
7656 DEFUN (no_ip_ospf_mtu_ignore,
7657 no_ip_ospf_mtu_ignore_addr_cmd,
7658 "no ip ospf mtu-ignore [A.B.C.D]",
7659 "IP Information\n"
7660 "OSPF interface commands\n"
7661 "Disable MTU mismatch detection on this interface\n"
7662 "Address of interface")
7663 {
7664 VTY_DECLVAR_CONTEXT(interface, ifp);
7665 int idx_ipv4 = 4;
7666 struct in_addr addr;
7667 int ret;
7668
7669 struct ospf_if_params *params;
7670 params = IF_DEF_PARAMS (ifp);
7671
7672 if (argc == 5)
7673 {
7674 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
7675 if (!ret)
7676 {
7677 vty_out (vty, "Please specify interface address by A.B.C.D%s",
7678 VTY_NEWLINE);
7679 return CMD_WARNING;
7680 }
7681 params = ospf_get_if_params (ifp, addr);
7682 ospf_if_update_params (ifp, addr);
7683 }
7684 params->mtu_ignore = 0;
7685 if (params->mtu_ignore != OSPF_MTU_IGNORE_DEFAULT)
7686 SET_IF_PARAM (params, mtu_ignore);
7687 else
7688 {
7689 UNSET_IF_PARAM (params, mtu_ignore);
7690 if (params != IF_DEF_PARAMS (ifp))
7691 {
7692 ospf_free_if_params (ifp, addr);
7693 ospf_if_update_params (ifp, addr);
7694 }
7695 }
7696 return CMD_SUCCESS;
7697 }
7698
7699
7700 DEFUN (ospf_max_metric_router_lsa_admin,
7701 ospf_max_metric_router_lsa_admin_cmd,
7702 "max-metric router-lsa administrative",
7703 "OSPF maximum / infinite-distance metric\n"
7704 "Advertise own Router-LSA with infinite distance (stub router)\n"
7705 "Administratively applied, for an indefinite period\n")
7706 {
7707 VTY_DECLVAR_CONTEXT(ospf, ospf);
7708 struct listnode *ln;
7709 struct ospf_area *area;
7710
7711 for (ALL_LIST_ELEMENTS_RO (ospf->areas, ln, area))
7712 {
7713 SET_FLAG (area->stub_router_state, OSPF_AREA_ADMIN_STUB_ROUTED);
7714
7715 if (!CHECK_FLAG (area->stub_router_state, OSPF_AREA_IS_STUB_ROUTED))
7716 ospf_router_lsa_update_area (area);
7717 }
7718
7719 /* Allows for areas configured later to get the property */
7720 ospf->stub_router_admin_set = OSPF_STUB_ROUTER_ADMINISTRATIVE_SET;
7721
7722 return CMD_SUCCESS;
7723 }
7724
7725 DEFUN (no_ospf_max_metric_router_lsa_admin,
7726 no_ospf_max_metric_router_lsa_admin_cmd,
7727 "no max-metric router-lsa administrative",
7728 NO_STR
7729 "OSPF maximum / infinite-distance metric\n"
7730 "Advertise own Router-LSA with infinite distance (stub router)\n"
7731 "Administratively applied, for an indefinite period\n")
7732 {
7733 VTY_DECLVAR_CONTEXT(ospf, ospf);
7734 struct listnode *ln;
7735 struct ospf_area *area;
7736
7737 for (ALL_LIST_ELEMENTS_RO (ospf->areas, ln, area))
7738 {
7739 UNSET_FLAG (area->stub_router_state, OSPF_AREA_ADMIN_STUB_ROUTED);
7740
7741 /* Don't trample on the start-up stub timer */
7742 if (CHECK_FLAG (area->stub_router_state, OSPF_AREA_IS_STUB_ROUTED)
7743 && !area->t_stub_router)
7744 {
7745 UNSET_FLAG (area->stub_router_state, OSPF_AREA_IS_STUB_ROUTED);
7746 ospf_router_lsa_update_area (area);
7747 }
7748 }
7749 ospf->stub_router_admin_set = OSPF_STUB_ROUTER_ADMINISTRATIVE_UNSET;
7750 return CMD_SUCCESS;
7751 }
7752
7753 DEFUN (ospf_max_metric_router_lsa_startup,
7754 ospf_max_metric_router_lsa_startup_cmd,
7755 "max-metric router-lsa on-startup (5-86400)",
7756 "OSPF maximum / infinite-distance metric\n"
7757 "Advertise own Router-LSA with infinite distance (stub router)\n"
7758 "Automatically advertise stub Router-LSA on startup of OSPF\n"
7759 "Time (seconds) to advertise self as stub-router\n")
7760 {
7761 VTY_DECLVAR_CONTEXT(ospf, ospf);
7762 int idx_number = 3;
7763 unsigned int seconds;
7764
7765 if (argc != 1)
7766 {
7767 vty_out (vty, "%% Must supply stub-router period");
7768 return CMD_WARNING;
7769 }
7770
7771 VTY_GET_INTEGER ("stub-router startup period", seconds, argv[idx_number]->arg);
7772
7773 ospf->stub_router_startup_time = seconds;
7774
7775 return CMD_SUCCESS;
7776 }
7777
7778 DEFUN (no_ospf_max_metric_router_lsa_startup,
7779 no_ospf_max_metric_router_lsa_startup_cmd,
7780 "no max-metric router-lsa on-startup [(5-86400)]",
7781 NO_STR
7782 "OSPF maximum / infinite-distance metric\n"
7783 "Advertise own Router-LSA with infinite distance (stub router)\n"
7784 "Automatically advertise stub Router-LSA on startup of OSPF\n"
7785 "Time (seconds) to advertise self as stub-router\n")
7786 {
7787 VTY_DECLVAR_CONTEXT(ospf, ospf);
7788 struct listnode *ln;
7789 struct ospf_area *area;
7790
7791 ospf->stub_router_startup_time = OSPF_STUB_ROUTER_UNCONFIGURED;
7792
7793 for (ALL_LIST_ELEMENTS_RO (ospf->areas, ln, area))
7794 {
7795 SET_FLAG (area->stub_router_state, OSPF_AREA_WAS_START_STUB_ROUTED);
7796 OSPF_TIMER_OFF (area->t_stub_router);
7797
7798 /* Don't trample on admin stub routed */
7799 if (!CHECK_FLAG (area->stub_router_state, OSPF_AREA_ADMIN_STUB_ROUTED))
7800 {
7801 UNSET_FLAG (area->stub_router_state, OSPF_AREA_IS_STUB_ROUTED);
7802 ospf_router_lsa_update_area (area);
7803 }
7804 }
7805 return CMD_SUCCESS;
7806 }
7807
7808
7809 DEFUN (ospf_max_metric_router_lsa_shutdown,
7810 ospf_max_metric_router_lsa_shutdown_cmd,
7811 "max-metric router-lsa on-shutdown (5-100)",
7812 "OSPF maximum / infinite-distance metric\n"
7813 "Advertise own Router-LSA with infinite distance (stub router)\n"
7814 "Advertise stub-router prior to full shutdown of OSPF\n"
7815 "Time (seconds) to wait till full shutdown\n")
7816 {
7817 VTY_DECLVAR_CONTEXT(ospf, ospf);
7818 int idx_number = 3;
7819 unsigned int seconds;
7820
7821 if (argc != 1)
7822 {
7823 vty_out (vty, "%% Must supply stub-router shutdown period");
7824 return CMD_WARNING;
7825 }
7826
7827 VTY_GET_INTEGER ("stub-router shutdown wait period", seconds, argv[idx_number]->arg);
7828
7829 ospf->stub_router_shutdown_time = seconds;
7830
7831 return CMD_SUCCESS;
7832 }
7833
7834 DEFUN (no_ospf_max_metric_router_lsa_shutdown,
7835 no_ospf_max_metric_router_lsa_shutdown_cmd,
7836 "no max-metric router-lsa on-shutdown [(5-100)]",
7837 NO_STR
7838 "OSPF maximum / infinite-distance metric\n"
7839 "Advertise own Router-LSA with infinite distance (stub router)\n"
7840 "Advertise stub-router prior to full shutdown of OSPF\n"
7841 "Time (seconds) to wait till full shutdown\n")
7842 {
7843 VTY_DECLVAR_CONTEXT(ospf, ospf);
7844
7845 ospf->stub_router_shutdown_time = OSPF_STUB_ROUTER_UNCONFIGURED;
7846
7847 return CMD_SUCCESS;
7848 }
7849
7850 static void
7851 config_write_stub_router (struct vty *vty, struct ospf *ospf)
7852 {
7853 struct listnode *ln;
7854 struct ospf_area *area;
7855
7856 if (ospf->stub_router_startup_time != OSPF_STUB_ROUTER_UNCONFIGURED)
7857 vty_out (vty, " max-metric router-lsa on-startup %u%s",
7858 ospf->stub_router_startup_time, VTY_NEWLINE);
7859 if (ospf->stub_router_shutdown_time != OSPF_STUB_ROUTER_UNCONFIGURED)
7860 vty_out (vty, " max-metric router-lsa on-shutdown %u%s",
7861 ospf->stub_router_shutdown_time, VTY_NEWLINE);
7862 for (ALL_LIST_ELEMENTS_RO (ospf->areas, ln, area))
7863 {
7864 if (CHECK_FLAG (area->stub_router_state, OSPF_AREA_ADMIN_STUB_ROUTED))
7865 {
7866 vty_out (vty, " max-metric router-lsa administrative%s",
7867 VTY_NEWLINE);
7868 break;
7869 }
7870 }
7871 return;
7872 }
7873
7874 static void
7875 show_ip_ospf_route_network (struct vty *vty, struct route_table *rt)
7876 {
7877 struct route_node *rn;
7878 struct ospf_route *or;
7879 struct listnode *pnode, *pnnode;
7880 struct ospf_path *path;
7881
7882 vty_out (vty, "============ OSPF network routing table ============%s",
7883 VTY_NEWLINE);
7884
7885 for (rn = route_top (rt); rn; rn = route_next (rn))
7886 if ((or = rn->info) != NULL)
7887 {
7888 char buf1[19];
7889 snprintf (buf1, 19, "%s/%d",
7890 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen);
7891
7892 switch (or->path_type)
7893 {
7894 case OSPF_PATH_INTER_AREA:
7895 if (or->type == OSPF_DESTINATION_NETWORK)
7896 vty_out (vty, "N IA %-18s [%d] area: %s%s", buf1, or->cost,
7897 inet_ntoa (or->u.std.area_id), VTY_NEWLINE);
7898 else if (or->type == OSPF_DESTINATION_DISCARD)
7899 vty_out (vty, "D IA %-18s Discard entry%s", buf1, VTY_NEWLINE);
7900 break;
7901 case OSPF_PATH_INTRA_AREA:
7902 vty_out (vty, "N %-18s [%d] area: %s%s", buf1, or->cost,
7903 inet_ntoa (or->u.std.area_id), VTY_NEWLINE);
7904 break;
7905 default:
7906 break;
7907 }
7908
7909 if (or->type == OSPF_DESTINATION_NETWORK)
7910 for (ALL_LIST_ELEMENTS (or->paths, pnode, pnnode, path))
7911 {
7912 if (if_lookup_by_index(path->ifindex, VRF_DEFAULT))
7913 {
7914 if (path->nexthop.s_addr == 0)
7915 vty_out (vty, "%24s directly attached to %s%s",
7916 "", ifindex2ifname (path->ifindex, VRF_DEFAULT), VTY_NEWLINE);
7917 else
7918 vty_out (vty, "%24s via %s, %s%s", "",
7919 inet_ntoa (path->nexthop),
7920 ifindex2ifname (path->ifindex, VRF_DEFAULT), VTY_NEWLINE);
7921 }
7922 }
7923 }
7924 vty_out (vty, "%s", VTY_NEWLINE);
7925 }
7926
7927 static void
7928 show_ip_ospf_route_router (struct vty *vty, struct route_table *rtrs)
7929 {
7930 struct route_node *rn;
7931 struct ospf_route *or;
7932 struct listnode *pnode;
7933 struct listnode *node;
7934 struct ospf_path *path;
7935
7936 vty_out (vty, "============ OSPF router routing table =============%s",
7937 VTY_NEWLINE);
7938 for (rn = route_top (rtrs); rn; rn = route_next (rn))
7939 if (rn->info)
7940 {
7941 int flag = 0;
7942
7943 vty_out (vty, "R %-15s ", inet_ntoa (rn->p.u.prefix4));
7944
7945 for (ALL_LIST_ELEMENTS_RO ((struct list *)rn->info, node, or))
7946 {
7947 if (flag++)
7948 vty_out (vty, "%24s", "");
7949
7950 /* Show path. */
7951 vty_out (vty, "%s [%d] area: %s",
7952 (or->path_type == OSPF_PATH_INTER_AREA ? "IA" : " "),
7953 or->cost, inet_ntoa (or->u.std.area_id));
7954 /* Show flags. */
7955 vty_out (vty, "%s%s%s",
7956 (or->u.std.flags & ROUTER_LSA_BORDER ? ", ABR" : ""),
7957 (or->u.std.flags & ROUTER_LSA_EXTERNAL ? ", ASBR" : ""),
7958 VTY_NEWLINE);
7959
7960 for (ALL_LIST_ELEMENTS_RO (or->paths, pnode, path))
7961 {
7962 if (if_lookup_by_index(path->ifindex, VRF_DEFAULT))
7963 {
7964 if (path->nexthop.s_addr == 0)
7965 vty_out (vty, "%24s directly attached to %s%s",
7966 "", ifindex2ifname (path->ifindex, VRF_DEFAULT),
7967 VTY_NEWLINE);
7968 else
7969 vty_out (vty, "%24s via %s, %s%s", "",
7970 inet_ntoa (path->nexthop),
7971 ifindex2ifname (path->ifindex, VRF_DEFAULT),
7972 VTY_NEWLINE);
7973 }
7974 }
7975 }
7976 }
7977 vty_out (vty, "%s", VTY_NEWLINE);
7978 }
7979
7980 static void
7981 show_ip_ospf_route_external (struct vty *vty, struct route_table *rt)
7982 {
7983 struct route_node *rn;
7984 struct ospf_route *er;
7985 struct listnode *pnode, *pnnode;
7986 struct ospf_path *path;
7987
7988 vty_out (vty, "============ OSPF external routing table ===========%s",
7989 VTY_NEWLINE);
7990 for (rn = route_top (rt); rn; rn = route_next (rn))
7991 if ((er = rn->info) != NULL)
7992 {
7993 char buf1[19];
7994 snprintf (buf1, 19, "%s/%d",
7995 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen);
7996
7997 switch (er->path_type)
7998 {
7999 case OSPF_PATH_TYPE1_EXTERNAL:
8000 vty_out (vty, "N E1 %-18s [%d] tag: %"ROUTE_TAG_PRI"%s", buf1,
8001 er->cost, er->u.ext.tag, VTY_NEWLINE);
8002 break;
8003 case OSPF_PATH_TYPE2_EXTERNAL:
8004 vty_out (vty, "N E2 %-18s [%d/%d] tag: %"ROUTE_TAG_PRI"%s", buf1, er->cost,
8005 er->u.ext.type2_cost, er->u.ext.tag, VTY_NEWLINE);
8006 break;
8007 }
8008
8009 for (ALL_LIST_ELEMENTS (er->paths, pnode, pnnode, path))
8010 {
8011 if (if_lookup_by_index(path->ifindex, VRF_DEFAULT))
8012 {
8013 if (path->nexthop.s_addr == 0)
8014 vty_out (vty, "%24s directly attached to %s%s",
8015 "", ifindex2ifname (path->ifindex, VRF_DEFAULT), VTY_NEWLINE);
8016 else
8017 vty_out (vty, "%24s via %s, %s%s", "",
8018 inet_ntoa (path->nexthop),
8019 ifindex2ifname (path->ifindex, VRF_DEFAULT),
8020 VTY_NEWLINE);
8021 }
8022 }
8023 }
8024 vty_out (vty, "%s", VTY_NEWLINE);
8025 }
8026
8027 static int
8028 show_ip_ospf_border_routers_common (struct vty *vty, struct ospf *ospf)
8029 {
8030 if (ospf->instance)
8031 vty_out (vty, "%sOSPF Instance: %d%s%s", VTY_NEWLINE, ospf->instance,
8032 VTY_NEWLINE, VTY_NEWLINE);
8033
8034 if (ospf->new_table == NULL)
8035 {
8036 vty_out (vty, "No OSPF routing information exist%s", VTY_NEWLINE);
8037 return CMD_SUCCESS;
8038 }
8039
8040 /* Show Network routes.
8041 show_ip_ospf_route_network (vty, ospf->new_table); */
8042
8043 /* Show Router routes. */
8044 show_ip_ospf_route_router (vty, ospf->new_rtrs);
8045
8046 vty_out (vty, "%s", VTY_NEWLINE);
8047
8048 return CMD_SUCCESS;
8049 }
8050
8051 DEFUN (show_ip_ospf_border_routers,
8052 show_ip_ospf_border_routers_cmd,
8053 "show ip ospf border-routers",
8054 SHOW_STR
8055 IP_STR
8056 "OSPF information\n"
8057 "Show all the ABR's and ASBR's\n")
8058 {
8059 struct ospf *ospf;
8060
8061 if ((ospf = ospf_lookup ()) == NULL || !ospf->oi_running)
8062 return CMD_SUCCESS;
8063
8064 return show_ip_ospf_border_routers_common(vty, ospf);
8065 }
8066
8067 DEFUN (show_ip_ospf_instance_border_routers,
8068 show_ip_ospf_instance_border_routers_cmd,
8069 "show ip ospf (1-65535) border-routers",
8070 SHOW_STR
8071 IP_STR
8072 "OSPF information\n"
8073 "Instance ID\n"
8074 "Show all the ABR's and ASBR's\n")
8075 {
8076 int idx_number = 3;
8077 struct ospf *ospf;
8078 u_short instance = 0;
8079
8080 VTY_GET_INTEGER ("Instance", instance, argv[idx_number]->arg);
8081 if ((ospf = ospf_lookup_instance (instance)) == NULL || !ospf->oi_running)
8082 return CMD_SUCCESS;
8083
8084 return show_ip_ospf_border_routers_common(vty, ospf);
8085 }
8086
8087 static int
8088 show_ip_ospf_route_common (struct vty *vty, struct ospf *ospf)
8089 {
8090 if (ospf->instance)
8091 vty_out (vty, "%sOSPF Instance: %d%s%s", VTY_NEWLINE, ospf->instance,
8092 VTY_NEWLINE, VTY_NEWLINE);
8093
8094 if (ospf->new_table == NULL)
8095 {
8096 vty_out (vty, "No OSPF routing information exist%s", VTY_NEWLINE);
8097 return CMD_SUCCESS;
8098 }
8099
8100 /* Show Network routes. */
8101 show_ip_ospf_route_network (vty, ospf->new_table);
8102
8103 /* Show Router routes. */
8104 show_ip_ospf_route_router (vty, ospf->new_rtrs);
8105
8106 /* Show AS External routes. */
8107 show_ip_ospf_route_external (vty, ospf->old_external_route);
8108
8109 vty_out (vty, "%s", VTY_NEWLINE);
8110
8111 return CMD_SUCCESS;
8112 }
8113
8114 DEFUN (show_ip_ospf_route,
8115 show_ip_ospf_route_cmd,
8116 "show ip ospf route",
8117 SHOW_STR
8118 IP_STR
8119 "OSPF information\n"
8120 "OSPF routing table\n")
8121 {
8122 struct ospf *ospf;
8123
8124 if ((ospf = ospf_lookup ()) == NULL || !ospf->oi_running)
8125 return CMD_SUCCESS;
8126
8127 return show_ip_ospf_route_common(vty, ospf);
8128 }
8129
8130 DEFUN (show_ip_ospf_instance_route,
8131 show_ip_ospf_instance_route_cmd,
8132 "show ip ospf (1-65535) route",
8133 SHOW_STR
8134 IP_STR
8135 "OSPF information\n"
8136 "Instance ID\n"
8137 "OSPF routing table\n")
8138 {
8139 int idx_number = 3;
8140 struct ospf *ospf;
8141 u_short instance = 0;
8142
8143 VTY_GET_INTEGER ("Instance", instance, argv[idx_number]->arg);
8144 if ((ospf = ospf_lookup_instance (instance)) == NULL || !ospf->oi_running)
8145 return CMD_SUCCESS;
8146
8147 return show_ip_ospf_route_common(vty, ospf);
8148 }
8149
8150 const char *ospf_abr_type_str[] =
8151 {
8152 "unknown",
8153 "standard",
8154 "ibm",
8155 "cisco",
8156 "shortcut"
8157 };
8158
8159 const char *ospf_shortcut_mode_str[] =
8160 {
8161 "default",
8162 "enable",
8163 "disable"
8164 };
8165
8166 const char *ospf_int_type_str[] =
8167 {
8168 "unknown", /* should never be used. */
8169 "point-to-point",
8170 "broadcast",
8171 "non-broadcast",
8172 "point-to-multipoint",
8173 "virtual-link", /* should never be used. */
8174 "loopback"
8175 };
8176
8177 /* Configuration write function for ospfd. */
8178 static int
8179 config_write_interface (struct vty *vty)
8180 {
8181 struct listnode *n1, *n2;
8182 struct interface *ifp;
8183 struct crypt_key *ck;
8184 int write = 0;
8185 struct route_node *rn = NULL;
8186 struct ospf_if_params *params;
8187 struct ospf *ospf = ospf_lookup();
8188
8189 for (ALL_LIST_ELEMENTS_RO (vrf_iflist (VRF_DEFAULT), n1, ifp))
8190 {
8191 if (memcmp (ifp->name, "VLINK", 5) == 0)
8192 continue;
8193
8194 if (ifp->ifindex == IFINDEX_DELETED)
8195 continue;
8196
8197 vty_out (vty, "!%s", VTY_NEWLINE);
8198 vty_out (vty, "interface %s%s", ifp->name,
8199 VTY_NEWLINE);
8200 if (ifp->desc)
8201 vty_out (vty, " description %s%s", ifp->desc,
8202 VTY_NEWLINE);
8203
8204 write++;
8205
8206 params = IF_DEF_PARAMS (ifp);
8207
8208 do {
8209 /* Interface Network print. */
8210 if (OSPF_IF_PARAM_CONFIGURED (params, type) &&
8211 params->type != OSPF_IFTYPE_LOOPBACK)
8212 {
8213 if (params->type != ospf_default_iftype(ifp))
8214 {
8215 vty_out (vty, " ip ospf network %s",
8216 ospf_int_type_str[params->type]);
8217 if (params != IF_DEF_PARAMS (ifp))
8218 vty_out (vty, " %s", inet_ntoa (rn->p.u.prefix4));
8219 vty_out (vty, "%s", VTY_NEWLINE);
8220 }
8221 }
8222
8223 /* OSPF interface authentication print */
8224 if (OSPF_IF_PARAM_CONFIGURED (params, auth_type) &&
8225 params->auth_type != OSPF_AUTH_NOTSET)
8226 {
8227 const char *auth_str;
8228
8229 /* Translation tables are not that much help here due to syntax
8230 of the simple option */
8231 switch (params->auth_type)
8232 {
8233
8234 case OSPF_AUTH_NULL:
8235 auth_str = " null";
8236 break;
8237
8238 case OSPF_AUTH_SIMPLE:
8239 auth_str = "";
8240 break;
8241
8242 case OSPF_AUTH_CRYPTOGRAPHIC:
8243 auth_str = " message-digest";
8244 break;
8245
8246 default:
8247 auth_str = "";
8248 break;
8249 }
8250
8251 vty_out (vty, " ip ospf authentication%s", auth_str);
8252 if (params != IF_DEF_PARAMS (ifp))
8253 vty_out (vty, " %s", inet_ntoa (rn->p.u.prefix4));
8254 vty_out (vty, "%s", VTY_NEWLINE);
8255 }
8256
8257 /* Simple Authentication Password print. */
8258 if (OSPF_IF_PARAM_CONFIGURED (params, auth_simple) &&
8259 params->auth_simple[0] != '\0')
8260 {
8261 vty_out (vty, " ip ospf authentication-key %s",
8262 params->auth_simple);
8263 if (params != IF_DEF_PARAMS (ifp))
8264 vty_out (vty, " %s", inet_ntoa (rn->p.u.prefix4));
8265 vty_out (vty, "%s", VTY_NEWLINE);
8266 }
8267
8268 /* Cryptographic Authentication Key print. */
8269 for (ALL_LIST_ELEMENTS_RO (params->auth_crypt, n2, ck))
8270 {
8271 vty_out (vty, " ip ospf message-digest-key %d md5 %s",
8272 ck->key_id, ck->auth_key);
8273 if (params != IF_DEF_PARAMS (ifp))
8274 vty_out (vty, " %s", inet_ntoa (rn->p.u.prefix4));
8275 vty_out (vty, "%s", VTY_NEWLINE);
8276 }
8277
8278 /* Interface Output Cost print. */
8279 if (OSPF_IF_PARAM_CONFIGURED (params, output_cost_cmd))
8280 {
8281 vty_out (vty, " ip ospf cost %u", params->output_cost_cmd);
8282 if (params != IF_DEF_PARAMS (ifp))
8283 vty_out (vty, " %s", inet_ntoa (rn->p.u.prefix4));
8284 vty_out (vty, "%s", VTY_NEWLINE);
8285 }
8286
8287 /* Hello Interval print. */
8288 if (OSPF_IF_PARAM_CONFIGURED (params, v_hello) &&
8289 params->v_hello != OSPF_HELLO_INTERVAL_DEFAULT)
8290 {
8291 vty_out (vty, " ip ospf hello-interval %u", params->v_hello);
8292 if (params != IF_DEF_PARAMS (ifp))
8293 vty_out (vty, " %s", inet_ntoa (rn->p.u.prefix4));
8294 vty_out (vty, "%s", VTY_NEWLINE);
8295 }
8296
8297
8298 /* Router Dead Interval print. */
8299 if (OSPF_IF_PARAM_CONFIGURED (params, v_wait) &&
8300 params->v_wait != OSPF_ROUTER_DEAD_INTERVAL_DEFAULT)
8301 {
8302 vty_out (vty, " ip ospf dead-interval ");
8303
8304 /* fast hello ? */
8305 if (OSPF_IF_PARAM_CONFIGURED (params, fast_hello))
8306 vty_out (vty, "minimal hello-multiplier %d",
8307 params->fast_hello);
8308 else
8309 vty_out (vty, "%u", params->v_wait);
8310
8311 if (params != IF_DEF_PARAMS (ifp))
8312 vty_out (vty, " %s", inet_ntoa (rn->p.u.prefix4));
8313 vty_out (vty, "%s", VTY_NEWLINE);
8314 }
8315
8316 /* Router Priority print. */
8317 if (OSPF_IF_PARAM_CONFIGURED (params, priority) &&
8318 params->priority != OSPF_ROUTER_PRIORITY_DEFAULT)
8319 {
8320 vty_out (vty, " ip ospf priority %u", params->priority);
8321 if (params != IF_DEF_PARAMS (ifp))
8322 vty_out (vty, " %s", inet_ntoa (rn->p.u.prefix4));
8323 vty_out (vty, "%s", VTY_NEWLINE);
8324 }
8325
8326 /* Retransmit Interval print. */
8327 if (OSPF_IF_PARAM_CONFIGURED (params, retransmit_interval) &&
8328 params->retransmit_interval != OSPF_RETRANSMIT_INTERVAL_DEFAULT)
8329 {
8330 vty_out (vty, " ip ospf retransmit-interval %u",
8331 params->retransmit_interval);
8332 if (params != IF_DEF_PARAMS (ifp))
8333 vty_out (vty, " %s", inet_ntoa (rn->p.u.prefix4));
8334 vty_out (vty, "%s", VTY_NEWLINE);
8335 }
8336
8337 /* Transmit Delay print. */
8338 if (OSPF_IF_PARAM_CONFIGURED (params, transmit_delay) &&
8339 params->transmit_delay != OSPF_TRANSMIT_DELAY_DEFAULT)
8340 {
8341 vty_out (vty, " ip ospf transmit-delay %u", params->transmit_delay);
8342 if (params != IF_DEF_PARAMS (ifp))
8343 vty_out (vty, " %s", inet_ntoa (rn->p.u.prefix4));
8344 vty_out (vty, "%s", VTY_NEWLINE);
8345 }
8346
8347 /* Area print. */
8348 if (OSPF_IF_PARAM_CONFIGURED (params, if_area))
8349 {
8350 if (ospf->instance)
8351 vty_out (vty, " ip ospf %d area %s%s", ospf->instance,
8352 inet_ntoa (params->if_area), VTY_NEWLINE);
8353 else
8354 vty_out (vty, " ip ospf area %s%s",
8355 inet_ntoa (params->if_area), VTY_NEWLINE);
8356
8357 }
8358
8359 /* bfd print. */
8360 ospf_bfd_write_config(vty, params);
8361
8362 /* MTU ignore print. */
8363 if (OSPF_IF_PARAM_CONFIGURED (params, mtu_ignore) &&
8364 params->mtu_ignore != OSPF_MTU_IGNORE_DEFAULT)
8365 {
8366 if (params->mtu_ignore == 0)
8367 vty_out (vty, " no ip ospf mtu-ignore");
8368 else
8369 vty_out (vty, " ip ospf mtu-ignore");
8370 if (params != IF_DEF_PARAMS (ifp))
8371 vty_out (vty, " %s", inet_ntoa (rn->p.u.prefix4));
8372 vty_out (vty, "%s", VTY_NEWLINE);
8373 }
8374
8375
8376 while (1)
8377 {
8378 if (rn == NULL)
8379 rn = route_top (IF_OIFS_PARAMS (ifp));
8380 else
8381 rn = route_next (rn);
8382
8383 if (rn == NULL)
8384 break;
8385 params = rn->info;
8386 if (params != NULL)
8387 break;
8388 }
8389 } while (rn);
8390
8391 ospf_opaque_config_write_if (vty, ifp);
8392 }
8393
8394 return write;
8395 }
8396
8397 static int
8398 config_write_network_area (struct vty *vty, struct ospf *ospf)
8399 {
8400 struct route_node *rn;
8401 u_char buf[INET_ADDRSTRLEN];
8402
8403 /* `network area' print. */
8404 for (rn = route_top (ospf->networks); rn; rn = route_next (rn))
8405 if (rn->info)
8406 {
8407 struct ospf_network *n = rn->info;
8408
8409 memset (buf, 0, INET_ADDRSTRLEN);
8410
8411 /* Create Area ID string by specified Area ID format. */
8412 if (n->area_id_fmt == OSPF_AREA_ID_FMT_DOTTEDQUAD)
8413 strncpy ((char *) buf, inet_ntoa (n->area_id), INET_ADDRSTRLEN);
8414 else
8415 sprintf ((char *) buf, "%lu",
8416 (unsigned long int) ntohl (n->area_id.s_addr));
8417
8418 /* Network print. */
8419 vty_out (vty, " network %s/%d area %s%s",
8420 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
8421 buf, VTY_NEWLINE);
8422 }
8423
8424 return 0;
8425 }
8426
8427 static int
8428 config_write_ospf_area (struct vty *vty, struct ospf *ospf)
8429 {
8430 struct listnode *node;
8431 struct ospf_area *area;
8432 u_char buf[INET_ADDRSTRLEN];
8433
8434 /* Area configuration print. */
8435 for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
8436 {
8437 struct route_node *rn1;
8438
8439 area_id2str ((char *) buf, INET_ADDRSTRLEN, &area->area_id,
8440 area->area_id_fmt);
8441
8442 if (area->auth_type != OSPF_AUTH_NULL)
8443 {
8444 if (area->auth_type == OSPF_AUTH_SIMPLE)
8445 vty_out (vty, " area %s authentication%s", buf, VTY_NEWLINE);
8446 else
8447 vty_out (vty, " area %s authentication message-digest%s",
8448 buf, VTY_NEWLINE);
8449 }
8450
8451 if (area->shortcut_configured != OSPF_SHORTCUT_DEFAULT)
8452 vty_out (vty, " area %s shortcut %s%s", buf,
8453 ospf_shortcut_mode_str[area->shortcut_configured],
8454 VTY_NEWLINE);
8455
8456 if ((area->external_routing == OSPF_AREA_STUB)
8457 || (area->external_routing == OSPF_AREA_NSSA)
8458 )
8459 {
8460 if (area->external_routing == OSPF_AREA_STUB)
8461 vty_out (vty, " area %s stub", buf);
8462 else if (area->external_routing == OSPF_AREA_NSSA)
8463 {
8464 vty_out (vty, " area %s nssa", buf);
8465 switch (area->NSSATranslatorRole)
8466 {
8467 case OSPF_NSSA_ROLE_NEVER:
8468 vty_out (vty, " translate-never");
8469 break;
8470 case OSPF_NSSA_ROLE_ALWAYS:
8471 vty_out (vty, " translate-always");
8472 break;
8473 case OSPF_NSSA_ROLE_CANDIDATE:
8474 default:
8475 vty_out (vty, " translate-candidate");
8476 }
8477 }
8478
8479 if (area->no_summary)
8480 vty_out (vty, " no-summary");
8481
8482 vty_out (vty, "%s", VTY_NEWLINE);
8483
8484 if (area->default_cost != 1)
8485 vty_out (vty, " area %s default-cost %d%s", buf,
8486 area->default_cost, VTY_NEWLINE);
8487 }
8488
8489 for (rn1 = route_top (area->ranges); rn1; rn1 = route_next (rn1))
8490 if (rn1->info)
8491 {
8492 struct ospf_area_range *range = rn1->info;
8493
8494 vty_out (vty, " area %s range %s/%d", buf,
8495 inet_ntoa (rn1->p.u.prefix4), rn1->p.prefixlen);
8496
8497 if (range->cost_config != OSPF_AREA_RANGE_COST_UNSPEC)
8498 vty_out (vty, " cost %d", range->cost_config);
8499
8500 if (!CHECK_FLAG (range->flags, OSPF_AREA_RANGE_ADVERTISE))
8501 vty_out (vty, " not-advertise");
8502
8503 if (CHECK_FLAG (range->flags, OSPF_AREA_RANGE_SUBSTITUTE))
8504 vty_out (vty, " substitute %s/%d",
8505 inet_ntoa (range->subst_addr), range->subst_masklen);
8506
8507 vty_out (vty, "%s", VTY_NEWLINE);
8508 }
8509
8510 if (EXPORT_NAME (area))
8511 vty_out (vty, " area %s export-list %s%s", buf,
8512 EXPORT_NAME (area), VTY_NEWLINE);
8513
8514 if (IMPORT_NAME (area))
8515 vty_out (vty, " area %s import-list %s%s", buf,
8516 IMPORT_NAME (area), VTY_NEWLINE);
8517
8518 if (PREFIX_NAME_IN (area))
8519 vty_out (vty, " area %s filter-list prefix %s in%s", buf,
8520 PREFIX_NAME_IN (area), VTY_NEWLINE);
8521
8522 if (PREFIX_NAME_OUT (area))
8523 vty_out (vty, " area %s filter-list prefix %s out%s", buf,
8524 PREFIX_NAME_OUT (area), VTY_NEWLINE);
8525 }
8526
8527 return 0;
8528 }
8529
8530 static int
8531 config_write_ospf_nbr_nbma (struct vty *vty, struct ospf *ospf)
8532 {
8533 struct ospf_nbr_nbma *nbr_nbma;
8534 struct route_node *rn;
8535
8536 /* Static Neighbor configuration print. */
8537 for (rn = route_top (ospf->nbr_nbma); rn; rn = route_next (rn))
8538 if ((nbr_nbma = rn->info))
8539 {
8540 vty_out (vty, " neighbor %s", inet_ntoa (nbr_nbma->addr));
8541
8542 if (nbr_nbma->priority != OSPF_NEIGHBOR_PRIORITY_DEFAULT)
8543 vty_out (vty, " priority %d", nbr_nbma->priority);
8544
8545 if (nbr_nbma->v_poll != OSPF_POLL_INTERVAL_DEFAULT)
8546 vty_out (vty, " poll-interval %d", nbr_nbma->v_poll);
8547
8548 vty_out (vty, "%s", VTY_NEWLINE);
8549 }
8550
8551 return 0;
8552 }
8553
8554 static int
8555 config_write_virtual_link (struct vty *vty, struct ospf *ospf)
8556 {
8557 struct listnode *node;
8558 struct ospf_vl_data *vl_data;
8559 char buf[INET_ADDRSTRLEN];
8560
8561 /* Virtual-Link print */
8562 for (ALL_LIST_ELEMENTS_RO (ospf->vlinks, node, vl_data))
8563 {
8564 struct listnode *n2;
8565 struct crypt_key *ck;
8566 struct ospf_interface *oi;
8567
8568 if (vl_data != NULL)
8569 {
8570 memset (buf, 0, INET_ADDRSTRLEN);
8571
8572 area_id2str (buf, sizeof(buf), &vl_data->vl_area_id, vl_data->vl_area_id_fmt);
8573 oi = vl_data->vl_oi;
8574
8575 /* timers */
8576 if (OSPF_IF_PARAM (oi, v_hello) != OSPF_HELLO_INTERVAL_DEFAULT ||
8577 OSPF_IF_PARAM (oi, v_wait) != OSPF_ROUTER_DEAD_INTERVAL_DEFAULT ||
8578 OSPF_IF_PARAM (oi, retransmit_interval) != OSPF_RETRANSMIT_INTERVAL_DEFAULT ||
8579 OSPF_IF_PARAM (oi, transmit_delay) != OSPF_TRANSMIT_DELAY_DEFAULT)
8580 vty_out (vty, " area %s virtual-link %s hello-interval %d retransmit-interval %d transmit-delay %d dead-interval %d%s",
8581 buf,
8582 inet_ntoa (vl_data->vl_peer),
8583 OSPF_IF_PARAM (oi, v_hello),
8584 OSPF_IF_PARAM (oi, retransmit_interval),
8585 OSPF_IF_PARAM (oi, transmit_delay),
8586 OSPF_IF_PARAM (oi, v_wait),
8587 VTY_NEWLINE);
8588 else
8589 vty_out (vty, " area %s virtual-link %s%s", buf,
8590 inet_ntoa (vl_data->vl_peer), VTY_NEWLINE);
8591 /* Auth key */
8592 if (IF_DEF_PARAMS (vl_data->vl_oi->ifp)->auth_simple[0] != '\0')
8593 vty_out (vty, " area %s virtual-link %s authentication-key %s%s",
8594 buf,
8595 inet_ntoa (vl_data->vl_peer),
8596 IF_DEF_PARAMS (vl_data->vl_oi->ifp)->auth_simple,
8597 VTY_NEWLINE);
8598 /* md5 keys */
8599 for (ALL_LIST_ELEMENTS_RO (IF_DEF_PARAMS (vl_data->vl_oi->ifp)->auth_crypt,
8600 n2, ck))
8601 vty_out (vty, " area %s virtual-link %s"
8602 " message-digest-key %d md5 %s%s",
8603 buf,
8604 inet_ntoa (vl_data->vl_peer),
8605 ck->key_id, ck->auth_key, VTY_NEWLINE);
8606
8607 }
8608 }
8609
8610 return 0;
8611 }
8612
8613
8614 static int
8615 config_write_ospf_redistribute (struct vty *vty, struct ospf *ospf)
8616 {
8617 int type;
8618
8619 /* redistribute print. */
8620 for (type = 0; type < ZEBRA_ROUTE_MAX; type++)
8621 {
8622 struct list *red_list;
8623 struct listnode *node;
8624 struct ospf_redist *red;
8625
8626 red_list = ospf->redist[type];
8627 if (!red_list)
8628 continue;
8629
8630 for (ALL_LIST_ELEMENTS_RO(red_list, node, red))
8631 {
8632 vty_out (vty, " redistribute %s", zebra_route_string(type));
8633 if (red->instance)
8634 vty_out (vty, " %d", red->instance);
8635
8636 if (red->dmetric.value >= 0)
8637 vty_out (vty, " metric %d", red->dmetric.value);
8638
8639 if (red->dmetric.type == EXTERNAL_METRIC_TYPE_1)
8640 vty_out (vty, " metric-type 1");
8641
8642 if (ROUTEMAP_NAME (red))
8643 vty_out (vty, " route-map %s", ROUTEMAP_NAME (red));
8644
8645 vty_out (vty, "%s", VTY_NEWLINE);
8646 }
8647 }
8648
8649 return 0;
8650 }
8651
8652 static int
8653 config_write_ospf_default_metric (struct vty *vty, struct ospf *ospf)
8654 {
8655 if (ospf->default_metric != -1)
8656 vty_out (vty, " default-metric %d%s", ospf->default_metric,
8657 VTY_NEWLINE);
8658 return 0;
8659 }
8660
8661 static int
8662 config_write_ospf_distribute (struct vty *vty, struct ospf *ospf)
8663 {
8664 int type;
8665 struct ospf_redist *red;
8666
8667 if (ospf)
8668 {
8669 /* distribute-list print. */
8670 for (type = 0; type < ZEBRA_ROUTE_MAX; type++)
8671 if (DISTRIBUTE_NAME (ospf, type))
8672 vty_out (vty, " distribute-list %s out %s%s",
8673 DISTRIBUTE_NAME (ospf, type),
8674 zebra_route_string(type), VTY_NEWLINE);
8675
8676 /* default-information print. */
8677 if (ospf->default_originate != DEFAULT_ORIGINATE_NONE)
8678 {
8679 vty_out (vty, " default-information originate");
8680 if (ospf->default_originate == DEFAULT_ORIGINATE_ALWAYS)
8681 vty_out (vty, " always");
8682
8683 red = ospf_redist_lookup(ospf, DEFAULT_ROUTE, 0);
8684 if (red)
8685 {
8686 if (red->dmetric.value >= 0)
8687 vty_out (vty, " metric %d",
8688 red->dmetric.value);
8689 if (red->dmetric.type == EXTERNAL_METRIC_TYPE_1)
8690 vty_out (vty, " metric-type 1");
8691
8692 if (ROUTEMAP_NAME (red))
8693 vty_out (vty, " route-map %s",
8694 ROUTEMAP_NAME (red));
8695 }
8696
8697 vty_out (vty, "%s", VTY_NEWLINE);
8698 }
8699
8700 }
8701
8702 return 0;
8703 }
8704
8705 static int
8706 config_write_ospf_distance (struct vty *vty, struct ospf *ospf)
8707 {
8708 struct route_node *rn;
8709 struct ospf_distance *odistance;
8710
8711 if (ospf->distance_all)
8712 vty_out (vty, " distance %d%s", ospf->distance_all, VTY_NEWLINE);
8713
8714 if (ospf->distance_intra
8715 || ospf->distance_inter
8716 || ospf->distance_external)
8717 {
8718 vty_out (vty, " distance ospf");
8719
8720 if (ospf->distance_intra)
8721 vty_out (vty, " intra-area %d", ospf->distance_intra);
8722 if (ospf->distance_inter)
8723 vty_out (vty, " inter-area %d", ospf->distance_inter);
8724 if (ospf->distance_external)
8725 vty_out (vty, " external %d", ospf->distance_external);
8726
8727 vty_out (vty, "%s", VTY_NEWLINE);
8728 }
8729
8730 for (rn = route_top (ospf->distance_table); rn; rn = route_next (rn))
8731 if ((odistance = rn->info) != NULL)
8732 {
8733 vty_out (vty, " distance %d %s/%d %s%s", odistance->distance,
8734 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
8735 odistance->access_list ? odistance->access_list : "",
8736 VTY_NEWLINE);
8737 }
8738 return 0;
8739 }
8740
8741 /* OSPF configuration write function. */
8742 static int
8743 ospf_config_write (struct vty *vty)
8744 {
8745 struct ospf *ospf;
8746 struct interface *ifp;
8747 struct ospf_interface *oi;
8748 struct listnode *node;
8749 int write = 0;
8750
8751 ospf = ospf_lookup ();
8752 if (ospf != NULL && ospf->oi_running)
8753 {
8754 /* `router ospf' print. */
8755 if (ospf->instance)
8756 vty_out (vty, "router ospf %d%s", ospf->instance, VTY_NEWLINE);
8757 else
8758 vty_out (vty, "router ospf%s", VTY_NEWLINE);
8759
8760 write++;
8761
8762 if (!ospf->networks)
8763 return write;
8764
8765 /* Router ID print. */
8766 if (ospf->router_id_static.s_addr != 0)
8767 vty_out (vty, " ospf router-id %s%s",
8768 inet_ntoa (ospf->router_id_static), VTY_NEWLINE);
8769
8770 /* ABR type print. */
8771 if (ospf->abr_type != OSPF_ABR_DEFAULT)
8772 vty_out (vty, " ospf abr-type %s%s",
8773 ospf_abr_type_str[ospf->abr_type], VTY_NEWLINE);
8774
8775 /* log-adjacency-changes flag print. */
8776 if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES))
8777 {
8778 if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL))
8779 vty_out(vty, " log-adjacency-changes detail%s", VTY_NEWLINE);
8780 else if (!DFLT_OSPF_LOG_ADJACENCY_CHANGES)
8781 vty_out(vty, " log-adjacency-changes%s", VTY_NEWLINE);
8782 }
8783 else if (DFLT_OSPF_LOG_ADJACENCY_CHANGES)
8784 {
8785 vty_out(vty, " no log-adjacency-changes%s", VTY_NEWLINE);
8786 }
8787
8788 /* RFC1583 compatibility flag print -- Compatible with CISCO 12.1. */
8789 if (CHECK_FLAG (ospf->config, OSPF_RFC1583_COMPATIBLE))
8790 vty_out (vty, " compatible rfc1583%s", VTY_NEWLINE);
8791
8792 /* auto-cost reference-bandwidth configuration. */
8793 if (ospf->ref_bandwidth != OSPF_DEFAULT_REF_BANDWIDTH)
8794 {
8795 vty_out (vty, "! Important: ensure reference bandwidth "
8796 "is consistent across all routers%s", VTY_NEWLINE);
8797 vty_out (vty, " auto-cost reference-bandwidth %d%s",
8798 ospf->ref_bandwidth, VTY_NEWLINE);
8799 }
8800
8801 /* SPF timers print. */
8802 if (ospf->spf_delay != OSPF_SPF_DELAY_DEFAULT ||
8803 ospf->spf_holdtime != OSPF_SPF_HOLDTIME_DEFAULT ||
8804 ospf->spf_max_holdtime != OSPF_SPF_MAX_HOLDTIME_DEFAULT)
8805 vty_out (vty, " timers throttle spf %d %d %d%s",
8806 ospf->spf_delay, ospf->spf_holdtime,
8807 ospf->spf_max_holdtime, VTY_NEWLINE);
8808
8809 /* LSA timers print. */
8810 if (ospf->min_ls_interval != OSPF_MIN_LS_INTERVAL)
8811 vty_out (vty, " timers throttle lsa all %d%s",
8812 ospf->min_ls_interval, VTY_NEWLINE);
8813 if (ospf->min_ls_arrival != OSPF_MIN_LS_ARRIVAL)
8814 vty_out (vty, " timers lsa min-arrival %d%s",
8815 ospf->min_ls_arrival, VTY_NEWLINE);
8816
8817 /* Write multiplier print. */
8818 if (ospf->write_oi_count != OSPF_WRITE_INTERFACE_COUNT_DEFAULT)
8819 vty_out (vty, " ospf write-multiplier %d%s",
8820 ospf->write_oi_count, VTY_NEWLINE);
8821
8822 /* Max-metric router-lsa print */
8823 config_write_stub_router (vty, ospf);
8824
8825 /* SPF refresh parameters print. */
8826 if (ospf->lsa_refresh_interval != OSPF_LSA_REFRESH_INTERVAL_DEFAULT)
8827 vty_out (vty, " refresh timer %d%s",
8828 ospf->lsa_refresh_interval, VTY_NEWLINE);
8829
8830 /* Redistribute information print. */
8831 config_write_ospf_redistribute (vty, ospf);
8832
8833 /* passive-interface print. */
8834 if (ospf->passive_interface_default == OSPF_IF_PASSIVE)
8835 vty_out (vty, " passive-interface default%s", VTY_NEWLINE);
8836
8837 for (ALL_LIST_ELEMENTS_RO (om->iflist, node, ifp))
8838 if (OSPF_IF_PARAM_CONFIGURED (IF_DEF_PARAMS (ifp), passive_interface)
8839 && IF_DEF_PARAMS (ifp)->passive_interface !=
8840 ospf->passive_interface_default)
8841 {
8842 vty_out (vty, " %spassive-interface %s%s",
8843 IF_DEF_PARAMS (ifp)->passive_interface ? "" : "no ",
8844 ifp->name, VTY_NEWLINE);
8845 }
8846 for (ALL_LIST_ELEMENTS_RO (ospf->oiflist, node, oi))
8847 {
8848 if (!OSPF_IF_PARAM_CONFIGURED (oi->params, passive_interface))
8849 continue;
8850 if (OSPF_IF_PARAM_CONFIGURED (IF_DEF_PARAMS (oi->ifp),
8851 passive_interface))
8852 {
8853 if (oi->params->passive_interface == IF_DEF_PARAMS (oi->ifp)->passive_interface)
8854 continue;
8855 }
8856 else if (oi->params->passive_interface == ospf->passive_interface_default)
8857 continue;
8858
8859 vty_out (vty, " %spassive-interface %s %s%s",
8860 oi->params->passive_interface ? "" : "no ",
8861 oi->ifp->name,
8862 inet_ntoa (oi->address->u.prefix4), VTY_NEWLINE);
8863 }
8864
8865 /* Network area print. */
8866 config_write_network_area (vty, ospf);
8867
8868 /* Area config print. */
8869 config_write_ospf_area (vty, ospf);
8870
8871 /* static neighbor print. */
8872 config_write_ospf_nbr_nbma (vty, ospf);
8873
8874 /* Virtual-Link print. */
8875 config_write_virtual_link (vty, ospf);
8876
8877 /* Default metric configuration. */
8878 config_write_ospf_default_metric (vty, ospf);
8879
8880 /* Distribute-list and default-information print. */
8881 config_write_ospf_distribute (vty, ospf);
8882
8883 /* Distance configuration. */
8884 config_write_ospf_distance (vty, ospf);
8885
8886 ospf_opaque_config_write_router (vty, ospf);
8887 }
8888
8889 return write;
8890 }
8891
8892 void
8893 ospf_vty_show_init (void)
8894 {
8895 /* "show ip ospf" commands. */
8896 install_element (VIEW_NODE, &show_ip_ospf_cmd);
8897
8898 install_element (VIEW_NODE, &show_ip_ospf_instance_cmd);
8899
8900 /* "show ip ospf database" commands. */
8901 install_element (VIEW_NODE, &show_ip_ospf_database_type_adv_router_cmd);
8902 install_element (VIEW_NODE, &show_ip_ospf_database_max_cmd);
8903
8904 install_element (VIEW_NODE, &show_ip_ospf_instance_database_type_adv_router_cmd);
8905 install_element (VIEW_NODE, &show_ip_ospf_instance_database_cmd);
8906 install_element (VIEW_NODE, &show_ip_ospf_instance_database_max_cmd);
8907
8908 /* "show ip ospf interface" commands. */
8909 install_element (VIEW_NODE, &show_ip_ospf_interface_cmd);
8910
8911 install_element (VIEW_NODE, &show_ip_ospf_instance_interface_cmd);
8912
8913 /* "show ip ospf neighbor" commands. */
8914 install_element (VIEW_NODE, &show_ip_ospf_neighbor_int_detail_cmd);
8915 install_element (VIEW_NODE, &show_ip_ospf_neighbor_int_cmd);
8916 install_element (VIEW_NODE, &show_ip_ospf_neighbor_id_cmd);
8917 install_element (VIEW_NODE, &show_ip_ospf_neighbor_detail_all_cmd);
8918 install_element (VIEW_NODE, &show_ip_ospf_neighbor_detail_cmd);
8919 install_element (VIEW_NODE, &show_ip_ospf_neighbor_cmd);
8920 install_element (VIEW_NODE, &show_ip_ospf_neighbor_all_cmd);
8921
8922 install_element (VIEW_NODE, &show_ip_ospf_instance_neighbor_int_detail_cmd);
8923 install_element (VIEW_NODE, &show_ip_ospf_instance_neighbor_int_cmd);
8924 install_element (VIEW_NODE, &show_ip_ospf_instance_neighbor_id_cmd);
8925 install_element (VIEW_NODE, &show_ip_ospf_instance_neighbor_detail_all_cmd);
8926 install_element (VIEW_NODE, &show_ip_ospf_instance_neighbor_detail_cmd);
8927 install_element (VIEW_NODE, &show_ip_ospf_instance_neighbor_cmd);
8928 install_element (VIEW_NODE, &show_ip_ospf_instance_neighbor_all_cmd);
8929
8930 /* "show ip ospf route" commands. */
8931 install_element (VIEW_NODE, &show_ip_ospf_route_cmd);
8932 install_element (VIEW_NODE, &show_ip_ospf_border_routers_cmd);
8933
8934 install_element (VIEW_NODE, &show_ip_ospf_instance_route_cmd);
8935 install_element (VIEW_NODE, &show_ip_ospf_instance_border_routers_cmd);
8936 }
8937
8938
8939 /* ospfd's interface node. */
8940 static struct cmd_node interface_node =
8941 {
8942 INTERFACE_NODE,
8943 "%s(config-if)# ",
8944 1
8945 };
8946
8947 /* Initialization of OSPF interface. */
8948 static void
8949 ospf_vty_if_init (void)
8950 {
8951 /* Install interface node. */
8952 install_node (&interface_node, config_write_interface);
8953 if_cmd_init ();
8954
8955 /* "ip ospf authentication" commands. */
8956 install_element (INTERFACE_NODE, &ip_ospf_authentication_args_addr_cmd);
8957 install_element (INTERFACE_NODE, &ip_ospf_authentication_addr_cmd);
8958 install_element (INTERFACE_NODE, &no_ip_ospf_authentication_args_addr_cmd);
8959 install_element (INTERFACE_NODE, &no_ip_ospf_authentication_addr_cmd);
8960 install_element (INTERFACE_NODE, &ip_ospf_authentication_key_addr_cmd);
8961 install_element (INTERFACE_NODE, &no_ip_ospf_authentication_key_authkey_addr_cmd);
8962 install_element (INTERFACE_NODE, &no_ospf_authentication_key_authkey_addr_cmd);
8963
8964 /* "ip ospf message-digest-key" commands. */
8965 install_element (INTERFACE_NODE, &ip_ospf_message_digest_key_cmd);
8966 install_element (INTERFACE_NODE, &no_ip_ospf_message_digest_key_cmd);
8967
8968 /* "ip ospf cost" commands. */
8969 install_element (INTERFACE_NODE, &ip_ospf_cost_cmd);
8970 install_element (INTERFACE_NODE, &no_ip_ospf_cost_cmd);
8971
8972 /* "ip ospf mtu-ignore" commands. */
8973 install_element (INTERFACE_NODE, &ip_ospf_mtu_ignore_addr_cmd);
8974 install_element (INTERFACE_NODE, &no_ip_ospf_mtu_ignore_addr_cmd);
8975
8976 /* "ip ospf dead-interval" commands. */
8977 install_element (INTERFACE_NODE, &ip_ospf_dead_interval_cmd);
8978 install_element (INTERFACE_NODE, &ip_ospf_dead_interval_minimal_addr_cmd);
8979 install_element (INTERFACE_NODE, &no_ip_ospf_dead_interval_cmd);
8980
8981 /* "ip ospf hello-interval" commands. */
8982 install_element (INTERFACE_NODE, &ip_ospf_hello_interval_cmd);
8983 install_element (INTERFACE_NODE, &no_ip_ospf_hello_interval_cmd);
8984
8985 /* "ip ospf network" commands. */
8986 install_element (INTERFACE_NODE, &ip_ospf_network_cmd);
8987 install_element (INTERFACE_NODE, &no_ip_ospf_network_cmd);
8988
8989 /* "ip ospf priority" commands. */
8990 install_element (INTERFACE_NODE, &ip_ospf_priority_cmd);
8991 install_element (INTERFACE_NODE, &no_ip_ospf_priority_cmd);
8992
8993 /* "ip ospf retransmit-interval" commands. */
8994 install_element (INTERFACE_NODE, &ip_ospf_retransmit_interval_addr_cmd);
8995 install_element (INTERFACE_NODE, &no_ip_ospf_retransmit_interval_addr_cmd);
8996
8997 /* "ip ospf transmit-delay" commands. */
8998 install_element (INTERFACE_NODE, &ip_ospf_transmit_delay_addr_cmd);
8999 install_element (INTERFACE_NODE, &no_ip_ospf_transmit_delay_addr_cmd);
9000
9001 /* "ip ospf area" commands. */
9002 install_element (INTERFACE_NODE, &ip_ospf_area_cmd);
9003 install_element (INTERFACE_NODE, &no_ip_ospf_area_cmd);
9004
9005 /* These commands are compatibitliy for previous version. */
9006 install_element (INTERFACE_NODE, &ospf_authentication_key_cmd);
9007 install_element (INTERFACE_NODE, &ospf_message_digest_key_cmd);
9008 install_element (INTERFACE_NODE, &no_ospf_message_digest_key_cmd);
9009 install_element (INTERFACE_NODE, &ospf_dead_interval_cmd);
9010 install_element (INTERFACE_NODE, &no_ospf_dead_interval_cmd);
9011 install_element (INTERFACE_NODE, &ospf_hello_interval_cmd);
9012 install_element (INTERFACE_NODE, &no_ospf_hello_interval_cmd);
9013 install_element (INTERFACE_NODE, &ospf_cost_cmd);
9014 install_element (INTERFACE_NODE, &no_ospf_cost_cmd);
9015 install_element (INTERFACE_NODE, &ospf_network_cmd);
9016 install_element (INTERFACE_NODE, &no_ospf_network_cmd);
9017 install_element (INTERFACE_NODE, &ospf_priority_cmd);
9018 install_element (INTERFACE_NODE, &no_ospf_priority_cmd);
9019 install_element (INTERFACE_NODE, &ospf_retransmit_interval_cmd);
9020 install_element (INTERFACE_NODE, &no_ospf_retransmit_interval_cmd);
9021 install_element (INTERFACE_NODE, &ospf_transmit_delay_cmd);
9022 install_element (INTERFACE_NODE, &no_ospf_transmit_delay_cmd);
9023 }
9024
9025 static void
9026 ospf_vty_zebra_init (void)
9027 {
9028 install_element (OSPF_NODE, &ospf_redistribute_source_cmd);
9029 install_element (OSPF_NODE, &no_ospf_redistribute_source_cmd);
9030 install_element (OSPF_NODE, &ospf_redistribute_instance_source_cmd);
9031 install_element (OSPF_NODE, &no_ospf_redistribute_instance_source_cmd);
9032
9033 install_element (OSPF_NODE, &ospf_distribute_list_out_cmd);
9034 install_element (OSPF_NODE, &no_ospf_distribute_list_out_cmd);
9035
9036 install_element (OSPF_NODE, &ospf_default_information_originate_cmd);
9037 install_element (OSPF_NODE, &no_ospf_default_information_originate_cmd);
9038
9039 install_element (OSPF_NODE, &ospf_default_metric_cmd);
9040 install_element (OSPF_NODE, &no_ospf_default_metric_cmd);
9041
9042 install_element (OSPF_NODE, &ospf_distance_cmd);
9043 install_element (OSPF_NODE, &no_ospf_distance_cmd);
9044 install_element (OSPF_NODE, &no_ospf_distance_ospf_cmd);
9045 install_element (OSPF_NODE, &ospf_distance_ospf_cmd);
9046 #if 0
9047 install_element (OSPF_NODE, &ospf_distance_source_cmd);
9048 install_element (OSPF_NODE, &no_ospf_distance_source_cmd);
9049 install_element (OSPF_NODE, &ospf_distance_source_access_list_cmd);
9050 install_element (OSPF_NODE, &no_ospf_distance_source_access_list_cmd);
9051 #endif /* 0 */
9052 }
9053
9054 static struct cmd_node ospf_node =
9055 {
9056 OSPF_NODE,
9057 "%s(config-router)# ",
9058 1
9059 };
9060
9061 static void
9062 ospf_interface_clear (struct interface *ifp)
9063 {
9064 if (!if_is_operative (ifp)) return;
9065
9066 if (IS_DEBUG_OSPF (ism, ISM_EVENTS))
9067 zlog_debug("ISM[%s]: clear by reset", ifp->name);
9068
9069 ospf_if_reset(ifp);
9070 }
9071
9072 DEFUN (clear_ip_ospf_interface,
9073 clear_ip_ospf_interface_cmd,
9074 "clear ip ospf interface [IFNAME]",
9075 CLEAR_STR
9076 IP_STR
9077 "OSPF information\n"
9078 "Interface information\n"
9079 "Interface name\n")
9080 {
9081 int idx_ifname = 4;
9082 struct interface *ifp;
9083 struct listnode *node;
9084
9085 if (argc == 4) /* Clear all the ospfv2 interfaces. */
9086 {
9087 for (ALL_LIST_ELEMENTS_RO (vrf_iflist (VRF_DEFAULT), node, ifp))
9088 ospf_interface_clear(ifp);
9089 }
9090 else /* Interface name is specified. */
9091 {
9092 if ((ifp = if_lookup_by_name (argv[idx_ifname]->arg, VRF_DEFAULT)) == NULL)
9093 vty_out (vty, "No such interface name%s", VTY_NEWLINE);
9094 else
9095 ospf_interface_clear(ifp);
9096 }
9097
9098 return CMD_SUCCESS;
9099 }
9100
9101 void
9102 ospf_vty_clear_init (void)
9103 {
9104 install_element (ENABLE_NODE, &clear_ip_ospf_interface_cmd);
9105 }
9106
9107
9108 /* Install OSPF related vty commands. */
9109 void
9110 ospf_vty_init (void)
9111 {
9112 /* Install ospf top node. */
9113 install_node (&ospf_node, ospf_config_write);
9114
9115 /* "router ospf" commands. */
9116 install_element (CONFIG_NODE, &router_ospf_cmd);
9117 install_element (CONFIG_NODE, &no_router_ospf_cmd);
9118
9119
9120 install_default (OSPF_NODE);
9121
9122 /* "ospf router-id" commands. */
9123 install_element (OSPF_NODE, &ospf_router_id_cmd);
9124 install_element (OSPF_NODE, &ospf_router_id_old_cmd);
9125 install_element (OSPF_NODE, &no_ospf_router_id_cmd);
9126
9127 /* "passive-interface" commands. */
9128 install_element (OSPF_NODE, &ospf_passive_interface_addr_cmd);
9129 install_element (OSPF_NODE, &no_ospf_passive_interface_addr_cmd);
9130
9131 /* "ospf abr-type" commands. */
9132 install_element (OSPF_NODE, &ospf_abr_type_cmd);
9133 install_element (OSPF_NODE, &no_ospf_abr_type_cmd);
9134
9135 /* "ospf log-adjacency-changes" commands. */
9136 install_element (OSPF_NODE, &ospf_log_adjacency_changes_cmd);
9137 install_element (OSPF_NODE, &ospf_log_adjacency_changes_detail_cmd);
9138 install_element (OSPF_NODE, &no_ospf_log_adjacency_changes_cmd);
9139 install_element (OSPF_NODE, &no_ospf_log_adjacency_changes_detail_cmd);
9140
9141 /* "ospf rfc1583-compatible" commands. */
9142 install_element (OSPF_NODE, &ospf_compatible_rfc1583_cmd);
9143 install_element (OSPF_NODE, &no_ospf_compatible_rfc1583_cmd);
9144 install_element (OSPF_NODE, &ospf_rfc1583_flag_cmd);
9145 install_element (OSPF_NODE, &no_ospf_rfc1583_flag_cmd);
9146
9147 /* "network area" commands. */
9148 install_element (OSPF_NODE, &ospf_network_area_cmd);
9149 install_element (OSPF_NODE, &no_ospf_network_area_cmd);
9150
9151 /* "area authentication" commands. */
9152 install_element (OSPF_NODE, &ospf_area_authentication_message_digest_cmd);
9153 install_element (OSPF_NODE, &ospf_area_authentication_cmd);
9154 install_element (OSPF_NODE, &no_ospf_area_authentication_cmd);
9155
9156 /* "area range" commands. */
9157 install_element (OSPF_NODE, &ospf_area_range_cmd);
9158 install_element (OSPF_NODE, &ospf_area_range_cost_cmd);
9159 install_element (OSPF_NODE, &ospf_area_range_not_advertise_cmd);
9160 install_element (OSPF_NODE, &no_ospf_area_range_cmd);
9161 install_element (OSPF_NODE, &ospf_area_range_substitute_cmd);
9162 install_element (OSPF_NODE, &no_ospf_area_range_substitute_cmd);
9163
9164 /* "area virtual-link" commands. */
9165 install_element (OSPF_NODE, &ospf_area_vlink_cmd);
9166 install_element (OSPF_NODE, &ospf_area_vlink_intervals_cmd);
9167 install_element (OSPF_NODE, &no_ospf_area_vlink_cmd);
9168 install_element (OSPF_NODE, &no_ospf_area_vlink_intervals_cmd);
9169
9170
9171
9172
9173
9174
9175
9176
9177
9178
9179 /* "area stub" commands. */
9180 install_element (OSPF_NODE, &ospf_area_stub_no_summary_cmd);
9181 install_element (OSPF_NODE, &ospf_area_stub_cmd);
9182 install_element (OSPF_NODE, &no_ospf_area_stub_no_summary_cmd);
9183 install_element (OSPF_NODE, &no_ospf_area_stub_cmd);
9184
9185 /* "area nssa" commands. */
9186 install_element (OSPF_NODE, &ospf_area_nssa_cmd);
9187 install_element (OSPF_NODE, &ospf_area_nssa_translate_no_summary_cmd);
9188 install_element (OSPF_NODE, &ospf_area_nssa_translate_cmd);
9189 install_element (OSPF_NODE, &ospf_area_nssa_no_summary_cmd);
9190 install_element (OSPF_NODE, &no_ospf_area_nssa_cmd);
9191
9192 install_element (OSPF_NODE, &ospf_area_default_cost_cmd);
9193 install_element (OSPF_NODE, &no_ospf_area_default_cost_cmd);
9194
9195 install_element (OSPF_NODE, &ospf_area_shortcut_cmd);
9196 install_element (OSPF_NODE, &no_ospf_area_shortcut_cmd);
9197
9198 install_element (OSPF_NODE, &ospf_area_export_list_cmd);
9199 install_element (OSPF_NODE, &no_ospf_area_export_list_cmd);
9200
9201 install_element (OSPF_NODE, &ospf_area_filter_list_cmd);
9202 install_element (OSPF_NODE, &no_ospf_area_filter_list_cmd);
9203
9204 install_element (OSPF_NODE, &ospf_area_import_list_cmd);
9205 install_element (OSPF_NODE, &no_ospf_area_import_list_cmd);
9206
9207 /* SPF timer commands */
9208 install_element (OSPF_NODE, &ospf_timers_throttle_spf_cmd);
9209 install_element (OSPF_NODE, &no_ospf_timers_throttle_spf_cmd);
9210
9211 /* LSA timers commands */
9212 install_element (OSPF_NODE, &ospf_timers_min_ls_interval_cmd);
9213 install_element (OSPF_NODE, &no_ospf_timers_min_ls_interval_cmd);
9214 install_element (OSPF_NODE, &ospf_timers_min_ls_arrival_cmd);
9215 install_element (OSPF_NODE, &no_ospf_timers_min_ls_arrival_cmd);
9216 install_element (OSPF_NODE, &ospf_timers_lsa_cmd);
9217 install_element (OSPF_NODE, &no_ospf_timers_lsa_cmd);
9218
9219 /* refresh timer commands */
9220 install_element (OSPF_NODE, &ospf_refresh_timer_cmd);
9221 install_element (OSPF_NODE, &no_ospf_refresh_timer_val_cmd);
9222
9223 /* max-metric commands */
9224 install_element (OSPF_NODE, &ospf_max_metric_router_lsa_admin_cmd);
9225 install_element (OSPF_NODE, &no_ospf_max_metric_router_lsa_admin_cmd);
9226 install_element (OSPF_NODE, &ospf_max_metric_router_lsa_startup_cmd);
9227 install_element (OSPF_NODE, &no_ospf_max_metric_router_lsa_startup_cmd);
9228 install_element (OSPF_NODE, &ospf_max_metric_router_lsa_shutdown_cmd);
9229 install_element (OSPF_NODE, &no_ospf_max_metric_router_lsa_shutdown_cmd);
9230
9231 /* reference bandwidth commands */
9232 install_element (OSPF_NODE, &ospf_auto_cost_reference_bandwidth_cmd);
9233 install_element (OSPF_NODE, &no_ospf_auto_cost_reference_bandwidth_cmd);
9234
9235 /* "neighbor" commands. */
9236 install_element (OSPF_NODE, &ospf_neighbor_cmd);
9237 install_element (OSPF_NODE, &ospf_neighbor_poll_interval_cmd);
9238 install_element (OSPF_NODE, &no_ospf_neighbor_cmd);
9239 install_element (OSPF_NODE, &no_ospf_neighbor_poll_cmd);
9240
9241 /* write multiplier commands */
9242 install_element (OSPF_NODE, &ospf_write_multiplier_cmd);
9243 install_element (OSPF_NODE, &write_multiplier_cmd);
9244 install_element (OSPF_NODE, &no_ospf_write_multiplier_cmd);
9245 install_element (OSPF_NODE, &no_write_multiplier_cmd);
9246
9247 /* Init interface related vty commands. */
9248 ospf_vty_if_init ();
9249
9250 /* Init zebra related vty commands. */
9251 ospf_vty_zebra_init ();
9252 }