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