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