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