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