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