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