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