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