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