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