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