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