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