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