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