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