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