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