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