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