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