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