]> git.proxmox.com Git - mirror_frr.git/blame - ospfd/ospf_vty.c
bgpd lib ospfd pimd ripngd: null chk (PVS-Studio)
[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
e24be241 2339#if defined(VERSION_TYPE_DEV) && CONFDATE > 20180708
5d1a2ee8
QY
2340CPP_NOTICE("ospf: `timers lsa arrival (0-1000)` deprecated 2017/07/08")
2341#endif
996c9314
LB
2342ALIAS_HIDDEN(ospf_timers_lsa_min_arrival, ospf_timers_lsa_arrival_cmd,
2343 "timers lsa arrival (0-1000)",
2344 "adjust routing timers\n"
2345 "throttling link state advertisement delays\n"
2346 "ospf minimum arrival interval delay\n"
2347 "delay (msec) between accepted lsas\n");
0e88de35 2348
e24be241 2349#if defined(VERSION_TYPE_DEV) && CONFDATE > 20180708
5d1a2ee8
QY
2350CPP_NOTICE("ospf: `no timers lsa arrival (0-1000)` deprecated 2017/07/08")
2351#endif
996c9314
LB
2352ALIAS_HIDDEN(no_ospf_timers_lsa_min_arrival, no_ospf_timers_lsa_arrival_cmd,
2353 "no timers lsa arrival (0-1000)", NO_STR
2354 "adjust routing timers\n"
2355 "throttling link state advertisement delays\n"
2356 "ospf minimum arrival interval delay\n"
2357 "delay (msec) between accepted lsas\n");
0e88de35
QY
2358
2359
a2c62831 2360DEFUN (ospf_neighbor,
2361 ospf_neighbor_cmd,
7a7be519 2362 "neighbor A.B.C.D [priority (0-255) [poll-interval (1-65535)]]",
718e3744 2363 NEIGHBOR_STR
7a7be519 2364 "Neighbor IP address\n"
2365 "Neighbor Priority\n"
2366 "Priority\n"
2367 "Dead Neighbor Polling interval\n"
2368 "Seconds\n")
718e3744 2369{
a3d826f0 2370 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
d62a17ae 2371 int idx_ipv4 = 1;
2372 int idx_pri = 3;
2373 int idx_poll = 5;
2374 struct in_addr nbr_addr;
2375 unsigned int priority = OSPF_NEIGHBOR_PRIORITY_DEFAULT;
2376 unsigned int interval = OSPF_POLL_INTERVAL_DEFAULT;
718e3744 2377
cc9b06ad
DS
2378 if (!inet_aton(argv[idx_ipv4]->arg, &nbr_addr)) {
2379 vty_out(vty, "Please specify Neighbor ID by A.B.C.D\n");
2380 return CMD_WARNING_CONFIG_FAILED;
2381 }
718e3744 2382
d62a17ae 2383 if (argc > 2)
2384 priority = strtoul(argv[idx_pri]->arg, NULL, 10);
7a7be519 2385
d62a17ae 2386 if (argc > 4)
2387 interval = strtoul(argv[idx_poll]->arg, NULL, 10);
718e3744 2388
d62a17ae 2389 ospf_nbr_nbma_set(ospf, nbr_addr);
7a7be519 2390
d62a17ae 2391 if (argc > 2)
2392 ospf_nbr_nbma_priority_set(ospf, nbr_addr, priority);
7a7be519 2393
d62a17ae 2394 if (argc > 4)
2395 ospf_nbr_nbma_poll_interval_set(ospf, nbr_addr, interval);
718e3744 2396
d62a17ae 2397 return CMD_SUCCESS;
718e3744 2398}
2399
a2c62831 2400DEFUN (ospf_neighbor_poll_interval,
2401 ospf_neighbor_poll_interval_cmd,
7a7be519 2402 "neighbor A.B.C.D poll-interval (1-65535) [priority (0-255)]",
718e3744 2403 NEIGHBOR_STR
2404 "Neighbor IP address\n"
2405 "Dead Neighbor Polling interval\n"
7a7be519 2406 "Seconds\n"
2407 "OSPF priority of non-broadcast neighbor\n"
2408 "Priority\n")
22b27e95 2409{
a3d826f0 2410 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
d62a17ae 2411 int idx_ipv4 = 1;
2412 int idx_poll = 3;
2413 int idx_pri = 5;
2414 struct in_addr nbr_addr;
a2b6e694 2415 unsigned int priority;
2416 unsigned int interval;
718e3744 2417
cc9b06ad
DS
2418 if (!inet_aton(argv[idx_ipv4]->arg, &nbr_addr)) {
2419 vty_out(vty, "Please specify Neighbor ID by A.B.C.D\n");
2420 return CMD_WARNING_CONFIG_FAILED;
2421 }
718e3744 2422
d62a17ae 2423 interval = strtoul(argv[idx_poll]->arg, NULL, 10);
718e3744 2424
a2b6e694 2425 priority = argc > 4 ? strtoul(argv[idx_pri]->arg, NULL, 10)
2426 : OSPF_NEIGHBOR_PRIORITY_DEFAULT;
718e3744 2427
d62a17ae 2428 ospf_nbr_nbma_set(ospf, nbr_addr);
2429 ospf_nbr_nbma_poll_interval_set(ospf, nbr_addr, interval);
7a7be519 2430
d62a17ae 2431 if (argc > 4)
2432 ospf_nbr_nbma_priority_set(ospf, nbr_addr, priority);
718e3744 2433
d62a17ae 2434 return CMD_SUCCESS;
718e3744 2435}
2436
a2c62831 2437DEFUN (no_ospf_neighbor,
2438 no_ospf_neighbor_cmd,
7a7be519 2439 "no neighbor A.B.C.D [priority (0-255) [poll-interval (1-65525)]]",
718e3744 2440 NO_STR
2441 NEIGHBOR_STR
7a7be519 2442 "Neighbor IP address\n"
2443 "Neighbor Priority\n"
2444 "Priority\n"
2445 "Dead Neighbor Polling interval\n"
2446 "Seconds\n")
718e3744 2447{
a3d826f0 2448 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
d62a17ae 2449 int idx_ipv4 = 2;
2450 struct in_addr nbr_addr;
718e3744 2451
cc9b06ad
DS
2452 if (!inet_aton(argv[idx_ipv4]->arg, &nbr_addr)) {
2453 vty_out(vty, "Please specify Neighbor ID by A.B.C.D\n");
2454 return CMD_WARNING_CONFIG_FAILED;
2455 }
718e3744 2456
d62a17ae 2457 (void)ospf_nbr_nbma_unset(ospf, nbr_addr);
718e3744 2458
d62a17ae 2459 return CMD_SUCCESS;
718e3744 2460}
2461
7a7be519 2462DEFUN (no_ospf_neighbor_poll,
2463 no_ospf_neighbor_poll_cmd,
2464 "no neighbor A.B.C.D poll-interval (1-65535) [priority (0-255)]",
2465 NO_STR
2466 NEIGHBOR_STR
2467 "Neighbor IP address\n"
2468 "Dead Neighbor Polling interval\n"
2469 "Seconds\n"
2470 "Neighbor Priority\n"
2471 "Priority\n")
2472{
a3d826f0 2473 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
d62a17ae 2474 int idx_ipv4 = 2;
2475 struct in_addr nbr_addr;
7a7be519 2476
cc9b06ad
DS
2477 if (!inet_aton(argv[idx_ipv4]->arg, &nbr_addr)) {
2478 vty_out(vty, "Please specify Neighbor ID by A.B.C.D\n");
2479 return CMD_WARNING_CONFIG_FAILED;
2480 }
718e3744 2481
d62a17ae 2482 (void)ospf_nbr_nbma_unset(ospf, nbr_addr);
813d4307 2483
d62a17ae 2484 return CMD_SUCCESS;
7a7be519 2485}
718e3744 2486
bf2bfafd
DW
2487DEFUN (ospf_refresh_timer,
2488 ospf_refresh_timer_cmd,
6147e2c6 2489 "refresh timer (10-1800)",
718e3744 2490 "Adjust refresh parameters\n"
2491 "Set refresh timer\n"
2492 "Timer value in seconds\n")
2493{
a3d826f0 2494 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
d62a17ae 2495 int idx_number = 2;
2496 unsigned int interval;
7c8ff89e 2497
d62a17ae 2498 interval = strtoul(argv[idx_number]->arg, NULL, 10);
2499 interval = (interval / OSPF_LSA_REFRESHER_GRANULARITY)
2500 * OSPF_LSA_REFRESHER_GRANULARITY;
718e3744 2501
d62a17ae 2502 ospf_timers_refresh_set(ospf, interval);
718e3744 2503
d62a17ae 2504 return CMD_SUCCESS;
718e3744 2505}
2506
bf2bfafd
DW
2507DEFUN (no_ospf_refresh_timer,
2508 no_ospf_refresh_timer_val_cmd,
7a7be519 2509 "no refresh timer [(10-1800)]",
3a2d747c 2510 NO_STR
718e3744 2511 "Adjust refresh parameters\n"
2512 "Unset refresh timer\n"
2513 "Timer value in seconds\n")
2514{
a3d826f0 2515 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
d62a17ae 2516 int idx_number = 3;
2517 unsigned int interval;
718e3744 2518
d62a17ae 2519 if (argc == 1) {
2520 interval = strtoul(argv[idx_number]->arg, NULL, 10);
718e3744 2521
d62a17ae 2522 if (ospf->lsa_refresh_interval != interval
2523 || interval == OSPF_LSA_REFRESH_INTERVAL_DEFAULT)
2524 return CMD_SUCCESS;
2525 }
2526
2527 ospf_timers_refresh_unset(ospf);
2528
2529 return CMD_SUCCESS;
718e3744 2530}
2531
718e3744 2532
a2c62831 2533DEFUN (ospf_auto_cost_reference_bandwidth,
2534 ospf_auto_cost_reference_bandwidth_cmd,
6147e2c6 2535 "auto-cost reference-bandwidth (1-4294967)",
718e3744 2536 "Calculate OSPF interface cost according to bandwidth\n"
2537 "Use reference bandwidth method to assign OSPF cost\n"
2538 "The reference bandwidth in terms of Mbits per second\n")
2539{
a3d826f0 2540 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
f4e14fdb 2541 struct vrf *vrf = vrf_lookup_by_id(ospf->vrf_id);
d62a17ae 2542 int idx_number = 2;
d7c0a89a 2543 uint32_t refbw;
d62a17ae 2544 struct interface *ifp;
2545
2546 refbw = strtol(argv[idx_number]->arg, NULL, 10);
2547 if (refbw < 1 || refbw > 4294967) {
2548 vty_out(vty, "reference-bandwidth value is invalid\n");
2549 return CMD_WARNING_CONFIG_FAILED;
2550 }
2551
2552 /* If reference bandwidth is changed. */
2553 if ((refbw) == ospf->ref_bandwidth)
2554 return CMD_SUCCESS;
2555
2556 ospf->ref_bandwidth = refbw;
451fda4f 2557 FOR_ALL_INTERFACES (vrf, ifp)
d62a17ae 2558 ospf_if_recalculate_output_cost(ifp);
2559
2560 return CMD_SUCCESS;
718e3744 2561}
2562
a2c62831 2563DEFUN (no_ospf_auto_cost_reference_bandwidth,
2564 no_ospf_auto_cost_reference_bandwidth_cmd,
7a7be519 2565 "no auto-cost reference-bandwidth [(1-4294967)]",
718e3744 2566 NO_STR
2567 "Calculate OSPF interface cost according to bandwidth\n"
7a7be519 2568 "Use reference bandwidth method to assign OSPF cost\n"
2569 "The reference bandwidth in terms of Mbits per second\n")
718e3744 2570{
a3d826f0 2571 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
f4e14fdb 2572 struct vrf *vrf = vrf_lookup_by_id(ospf->vrf_id);
d62a17ae 2573 struct interface *ifp;
718e3744 2574
d62a17ae 2575 if (ospf->ref_bandwidth == OSPF_DEFAULT_REF_BANDWIDTH)
2576 return CMD_SUCCESS;
2577
2578 ospf->ref_bandwidth = OSPF_DEFAULT_REF_BANDWIDTH;
2579 vty_out(vty, "%% OSPF: Reference bandwidth is changed.\n");
2580 vty_out(vty,
2581 " Please ensure reference bandwidth is consistent across all routers\n");
2582
451fda4f 2583 FOR_ALL_INTERFACES (vrf, ifp)
d62a17ae 2584 ospf_if_recalculate_output_cost(ifp);
2585
2586 return CMD_SUCCESS;
718e3744 2587}
2588
2f8f370e
DS
2589DEFUN (ospf_write_multiplier,
2590 ospf_write_multiplier_cmd,
6147e2c6 2591 "ospf write-multiplier (1-100)",
e8f45e82
DS
2592 "OSPF specific commands\n"
2593 "Write multiplier\n"
2594 "Maximum number of interface serviced per write\n")
2f8f370e 2595{
a3d826f0 2596 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
d62a17ae 2597 int idx_number;
d7c0a89a 2598 uint32_t write_oi_count;
d62a17ae 2599
2600 if (argc == 3)
2601 idx_number = 2;
2602 else
2603 idx_number = 1;
2604
2605 write_oi_count = strtol(argv[idx_number]->arg, NULL, 10);
2606 if (write_oi_count < 1 || write_oi_count > 100) {
2607 vty_out(vty, "write-multiplier value is invalid\n");
2608 return CMD_WARNING_CONFIG_FAILED;
2609 }
2610
2611 ospf->write_oi_count = write_oi_count;
2612 return CMD_SUCCESS;
2f8f370e
DS
2613}
2614
d62a17ae 2615ALIAS(ospf_write_multiplier, write_multiplier_cmd, "write-multiplier (1-100)",
2616 "Write multiplier\n"
2617 "Maximum number of interface serviced per write\n")
e8f45e82 2618
2f8f370e
DS
2619DEFUN (no_ospf_write_multiplier,
2620 no_ospf_write_multiplier_cmd,
6147e2c6 2621 "no ospf write-multiplier (1-100)",
2f8f370e 2622 NO_STR
e8f45e82 2623 "OSPF specific commands\n"
813d4307
DW
2624 "Write multiplier\n"
2625 "Maximum number of interface serviced per write\n")
2f8f370e 2626{
a3d826f0 2627 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
2f8f370e 2628
d62a17ae 2629 ospf->write_oi_count = OSPF_WRITE_INTERFACE_COUNT_DEFAULT;
2630 return CMD_SUCCESS;
2f8f370e
DS
2631}
2632
d62a17ae 2633ALIAS(no_ospf_write_multiplier, no_write_multiplier_cmd,
9d303b37 2634 "no write-multiplier (1-100)", NO_STR
d62a17ae 2635 "Write multiplier\n"
2636 "Maximum number of interface serviced per write\n")
2637
2638const char *ospf_abr_type_descr_str[] = {"Unknown", "Standard (RFC2328)",
2639 "Alternative IBM", "Alternative Cisco",
2640 "Alternative Shortcut"};
2641
2642const char *ospf_shortcut_mode_descr_str[] = {"Default", "Enabled", "Disabled"};
2643
2644static void show_ip_ospf_area(struct vty *vty, struct ospf_area *area,
d7c0a89a 2645 json_object *json_areas, uint8_t use_json)
d62a17ae 2646{
2647 json_object *json_area = NULL;
2648
2649 if (use_json)
2650 json_area = json_object_new_object();
2651
2652 /* Show Area ID. */
2653 if (!use_json)
2654 vty_out(vty, " Area ID: %s", inet_ntoa(area->area_id));
2655
2656 /* Show Area type/mode. */
2657 if (OSPF_IS_AREA_BACKBONE(area)) {
2658 if (use_json)
2659 json_object_boolean_true_add(json_area, "backbone");
2660 else
2661 vty_out(vty, " (Backbone)\n");
2662 } else {
2663 if (use_json) {
2664 if (area->external_routing == OSPF_AREA_STUB) {
2665 if (area->no_summary)
2666 json_object_boolean_true_add(
2667 json_area, "stubNoSummary");
2668 if (area->shortcut_configured)
2669 json_object_boolean_true_add(
2670 json_area, "stubShortcut");
2671 } else if (area->external_routing == OSPF_AREA_NSSA) {
2672 if (area->no_summary)
2673 json_object_boolean_true_add(
2674 json_area, "nssaNoSummary");
2675 if (area->shortcut_configured)
2676 json_object_boolean_true_add(
2677 json_area, "nssaShortcut");
2678 }
813d4307 2679
d62a17ae 2680 json_object_string_add(
2681 json_area, "shortcuttingMode",
2682 ospf_shortcut_mode_descr_str
2683 [area->shortcut_configured]);
2684 if (area->shortcut_capability)
2685 json_object_boolean_true_add(json_area,
2686 "sBitConcensus");
2687 } else {
2688 if (area->external_routing == OSPF_AREA_STUB)
2689 vty_out(vty, " (Stub%s%s)",
2690 area->no_summary ? ", no summary" : "",
2691 area->shortcut_configured ? "; " : "");
2692 else if (area->external_routing == OSPF_AREA_NSSA)
2693 vty_out(vty, " (NSSA%s%s)",
2694 area->no_summary ? ", no summary" : "",
2695 area->shortcut_configured ? "; " : "");
2696
2697 vty_out(vty, "\n");
2698 vty_out(vty, " Shortcutting mode: %s",
2699 ospf_shortcut_mode_descr_str
2700 [area->shortcut_configured]);
2701 vty_out(vty, ", S-bit consensus: %s\n",
2702 area->shortcut_capability ? "ok" : "no");
2703 }
2704 }
718e3744 2705
d62a17ae 2706 /* Show number of interfaces */
2707 if (use_json) {
2708 json_object_int_add(json_area, "areaIfTotalCounter",
2709 listcount(area->oiflist));
2710 json_object_int_add(json_area, "areaIfActiveCounter",
2711 area->act_ints);
2712 } else
2713 vty_out(vty,
2714 " Number of interfaces in this area: Total: %d, "
2715 "Active: %d\n",
2716 listcount(area->oiflist), area->act_ints);
2717
2718 if (area->external_routing == OSPF_AREA_NSSA) {
2719 if (use_json) {
2720 json_object_boolean_true_add(json_area, "nssa");
2721 if (!IS_OSPF_ABR(area->ospf))
2722 json_object_boolean_false_add(json_area, "abr");
2723 else if (area->NSSATranslatorState) {
2724 json_object_boolean_true_add(json_area, "abr");
2725 if (area->NSSATranslatorRole
2726 == OSPF_NSSA_ROLE_CANDIDATE)
2727 json_object_boolean_true_add(
2728 json_area,
2729 "nssaTranslatorElected");
2730 else if (area->NSSATranslatorRole
2731 == OSPF_NSSA_ROLE_ALWAYS)
2732 json_object_boolean_true_add(
2733 json_area,
2734 "nssaTranslatorAlways");
2735 } else {
2736 json_object_boolean_true_add(json_area, "abr");
2737 if (area->NSSATranslatorRole
2738 == OSPF_NSSA_ROLE_CANDIDATE)
2739 json_object_boolean_false_add(
2740 json_area,
2741 "nssaTranslatorElected");
2742 else
2743 json_object_boolean_true_add(
2744 json_area,
2745 "nssaTranslatorNever");
2746 }
2747 } else {
2748 vty_out(vty,
2749 " It is an NSSA configuration. \n Elected NSSA/ABR performs type-7/type-5 LSA translation. \n");
2750 if (!IS_OSPF_ABR(area->ospf))
2751 vty_out(vty,
2752 " It is not ABR, therefore not Translator. \n");
2753 else if (area->NSSATranslatorState) {
2754 vty_out(vty, " We are an ABR and ");
2755 if (area->NSSATranslatorRole
2756 == OSPF_NSSA_ROLE_CANDIDATE)
2757 vty_out(vty,
2758 "the NSSA Elected Translator. \n");
2759 else if (area->NSSATranslatorRole
2760 == OSPF_NSSA_ROLE_ALWAYS)
2761 vty_out(vty,
2762 "always an NSSA Translator. \n");
2763 } else {
2764 vty_out(vty, " We are an ABR, but ");
2765 if (area->NSSATranslatorRole
2766 == OSPF_NSSA_ROLE_CANDIDATE)
2767 vty_out(vty,
2768 "not the NSSA Elected Translator. \n");
2769 else
2770 vty_out(vty,
2771 "never an NSSA Translator. \n");
2772 }
2773 }
2774 }
2775
2776 /* Stub-router state for this area */
2777 if (CHECK_FLAG(area->stub_router_state, OSPF_AREA_IS_STUB_ROUTED)) {
2778 char timebuf[OSPF_TIME_DUMP_SIZE];
2779
2780 if (use_json) {
2781 json_object_boolean_true_add(
2782 json_area, "originStubMaxDistRouterLsa");
2783 if (CHECK_FLAG(area->stub_router_state,
2784 OSPF_AREA_ADMIN_STUB_ROUTED))
2785 json_object_boolean_true_add(
2786 json_area, "indefiniteActiveAdmin");
2787 if (area->t_stub_router) {
2788 long time_store;
2789 time_store =
2790 monotime_until(
2791 &area->t_stub_router->u.sands,
2792 NULL)
2793 / 1000LL;
2794 json_object_int_add(
2795 json_area,
2796 "activeStartupRemainderMsecs",
2797 time_store);
2798 }
2799 } else {
2800 vty_out(vty,
2801 " Originating stub / maximum-distance Router-LSA\n");
2802 if (CHECK_FLAG(area->stub_router_state,
2803 OSPF_AREA_ADMIN_STUB_ROUTED))
2804 vty_out(vty,
2805 " Administratively activated (indefinitely)\n");
2806 if (area->t_stub_router)
2807 vty_out(vty,
2808 " Active from startup, %s remaining\n",
2809 ospf_timer_dump(area->t_stub_router,
2810 timebuf,
2811 sizeof(timebuf)));
2812 }
2813 }
2814
2815 if (use_json) {
2816 /* Show number of fully adjacent neighbors. */
2817 json_object_int_add(json_area, "nbrFullAdjacentCounter",
2818 area->full_nbrs);
2819
2820 /* Show authentication type. */
2821 if (area->auth_type == OSPF_AUTH_NULL)
2822 json_object_string_add(json_area, "authentication",
2823 "authenticationNone");
2824 else if (area->auth_type == OSPF_AUTH_SIMPLE)
2825 json_object_string_add(json_area, "authentication",
2826 "authenticationSimplePassword");
2827 else if (area->auth_type == OSPF_AUTH_CRYPTOGRAPHIC)
2828 json_object_string_add(json_area, "authentication",
2829 "authenticationMessageDigest");
2830
2831 if (!OSPF_IS_AREA_BACKBONE(area))
2832 json_object_int_add(json_area,
2833 "virtualAdjacenciesPassingCounter",
2834 area->full_vls);
2835
2836 /* Show SPF calculation times. */
2837 json_object_int_add(json_area, "spfExecutedCounter",
2838 area->spf_calculation);
2839 json_object_int_add(json_area, "lsaNumber", area->lsdb->total);
2840 json_object_int_add(
2841 json_area, "lsaRouterNumber",
2842 ospf_lsdb_count(area->lsdb, OSPF_ROUTER_LSA));
2843 json_object_int_add(
2844 json_area, "lsaRouterChecksum",
2845 ospf_lsdb_checksum(area->lsdb, OSPF_ROUTER_LSA));
2846 json_object_int_add(
2847 json_area, "lsaNetworkNumber",
2848 ospf_lsdb_count(area->lsdb, OSPF_NETWORK_LSA));
2849 json_object_int_add(
2850 json_area, "lsaNetworkChecksum",
2851 ospf_lsdb_checksum(area->lsdb, OSPF_NETWORK_LSA));
2852 json_object_int_add(
2853 json_area, "lsaSummaryNumber",
2854 ospf_lsdb_count(area->lsdb, OSPF_SUMMARY_LSA));
2855 json_object_int_add(
2856 json_area, "lsaSummaryChecksum",
2857 ospf_lsdb_checksum(area->lsdb, OSPF_SUMMARY_LSA));
2858 json_object_int_add(
2859 json_area, "lsaAsbrNumber",
2860 ospf_lsdb_count(area->lsdb, OSPF_ASBR_SUMMARY_LSA));
2861 json_object_int_add(
2862 json_area, "lsaAsbrChecksum",
2863 ospf_lsdb_checksum(area->lsdb, OSPF_ASBR_SUMMARY_LSA));
2864 json_object_int_add(
2865 json_area, "lsaNssaNumber",
2866 ospf_lsdb_count(area->lsdb, OSPF_AS_NSSA_LSA));
2867 json_object_int_add(
2868 json_area, "lsaNssaChecksum",
2869 ospf_lsdb_checksum(area->lsdb, OSPF_AS_NSSA_LSA));
2870 } else {
2871 /* Show number of fully adjacent neighbors. */
2872 vty_out(vty,
2873 " Number of fully adjacent neighbors in this area:"
2874 " %d\n",
2875 area->full_nbrs);
2876
2877 /* Show authentication type. */
2878 vty_out(vty, " Area has ");
2879 if (area->auth_type == OSPF_AUTH_NULL)
2880 vty_out(vty, "no authentication\n");
2881 else if (area->auth_type == OSPF_AUTH_SIMPLE)
2882 vty_out(vty, "simple password authentication\n");
2883 else if (area->auth_type == OSPF_AUTH_CRYPTOGRAPHIC)
2884 vty_out(vty, "message digest authentication\n");
2885
2886 if (!OSPF_IS_AREA_BACKBONE(area))
2887 vty_out(vty,
2888 " Number of full virtual adjacencies going through"
2889 " this area: %d\n",
2890 area->full_vls);
2891
2892 /* Show SPF calculation times. */
2893 vty_out(vty, " SPF algorithm executed %d times\n",
2894 area->spf_calculation);
2895
2896 /* Show number of LSA. */
2897 vty_out(vty, " Number of LSA %ld\n", area->lsdb->total);
2898 vty_out(vty,
2899 " Number of router LSA %ld. Checksum Sum 0x%08x\n",
2900 ospf_lsdb_count(area->lsdb, OSPF_ROUTER_LSA),
2901 ospf_lsdb_checksum(area->lsdb, OSPF_ROUTER_LSA));
2902 vty_out(vty,
2903 " Number of network LSA %ld. Checksum Sum 0x%08x\n",
2904 ospf_lsdb_count(area->lsdb, OSPF_NETWORK_LSA),
2905 ospf_lsdb_checksum(area->lsdb, OSPF_NETWORK_LSA));
2906 vty_out(vty,
2907 " Number of summary LSA %ld. Checksum Sum 0x%08x\n",
2908 ospf_lsdb_count(area->lsdb, OSPF_SUMMARY_LSA),
2909 ospf_lsdb_checksum(area->lsdb, OSPF_SUMMARY_LSA));
2910 vty_out(vty,
2911 " Number of ASBR summary LSA %ld. Checksum Sum 0x%08x\n",
2912 ospf_lsdb_count(area->lsdb, OSPF_ASBR_SUMMARY_LSA),
2913 ospf_lsdb_checksum(area->lsdb, OSPF_ASBR_SUMMARY_LSA));
2914 vty_out(vty, " Number of NSSA LSA %ld. Checksum Sum 0x%08x\n",
2915 ospf_lsdb_count(area->lsdb, OSPF_AS_NSSA_LSA),
2916 ospf_lsdb_checksum(area->lsdb, OSPF_AS_NSSA_LSA));
2917 }
2918
2919 if (use_json) {
2920 json_object_int_add(
2921 json_area, "lsaOpaqueLinkNumber",
2922 ospf_lsdb_count(area->lsdb, OSPF_OPAQUE_LINK_LSA));
2923 json_object_int_add(
2924 json_area, "lsaOpaqueLinkChecksum",
2925 ospf_lsdb_checksum(area->lsdb, OSPF_OPAQUE_LINK_LSA));
2926 json_object_int_add(
2927 json_area, "lsaOpaqueAreaNumber",
2928 ospf_lsdb_count(area->lsdb, OSPF_OPAQUE_AREA_LSA));
2929 json_object_int_add(
2930 json_area, "lsaOpaqueAreaChecksum",
2931 ospf_lsdb_checksum(area->lsdb, OSPF_OPAQUE_AREA_LSA));
2932 } else {
2933 vty_out(vty,
2934 " Number of opaque link LSA %ld. Checksum Sum 0x%08x\n",
2935 ospf_lsdb_count(area->lsdb, OSPF_OPAQUE_LINK_LSA),
2936 ospf_lsdb_checksum(area->lsdb, OSPF_OPAQUE_LINK_LSA));
2937 vty_out(vty,
2938 " Number of opaque area LSA %ld. Checksum Sum 0x%08x\n",
2939 ospf_lsdb_count(area->lsdb, OSPF_OPAQUE_AREA_LSA),
2940 ospf_lsdb_checksum(area->lsdb, OSPF_OPAQUE_AREA_LSA));
2941 }
718e3744 2942
d62a17ae 2943 if (use_json)
2944 json_object_object_add(json_areas, inet_ntoa(area->area_id),
2945 json_area);
2946 else
2947 vty_out(vty, "\n");
718e3744 2948}
2949
d62a17ae 2950static int show_ip_ospf_common(struct vty *vty, struct ospf *ospf,
d7c0a89a 2951 json_object *json, uint8_t use_vrf)
d62a17ae 2952{
2953 struct listnode *node, *nnode;
2954 struct ospf_area *area;
2955 struct timeval result;
2956 char timebuf[OSPF_TIME_DUMP_SIZE];
b1c3ae8c 2957 json_object *json_vrf = NULL;
d62a17ae 2958 json_object *json_areas = NULL;
718e3744 2959
b1c3ae8c
CS
2960 if (json) {
2961 if (use_vrf)
2962 json_vrf = json_object_new_object();
2963 else
2964 json_vrf = json;
d62a17ae 2965 json_areas = json_object_new_object();
2966 }
2967
2968 if (ospf->instance) {
b1c3ae8c 2969 if (json) {
d62a17ae 2970 json_object_int_add(json, "ospfInstance",
2971 ospf->instance);
2972 } else {
2973 vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
2974 }
2975 }
2976
b1c3ae8c 2977 ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf);
87bd50e8 2978
d62a17ae 2979 /* Show Router ID. */
b1c3ae8c
CS
2980 if (json) {
2981 json_object_string_add(json_vrf, "routerId",
d62a17ae 2982 inet_ntoa(ospf->router_id));
2983 } else {
2984 vty_out(vty, " OSPF Routing Process, Router ID: %s\n",
2985 inet_ntoa(ospf->router_id));
2986 }
2987
2988 /* Graceful shutdown */
2989 if (ospf->t_deferred_shutdown) {
b1c3ae8c 2990 if (json) {
d62a17ae 2991 long time_store;
2992 time_store =
2993 monotime_until(
2994 &ospf->t_deferred_shutdown->u.sands,
2995 NULL)
2996 / 1000LL;
b1c3ae8c 2997 json_object_int_add(json_vrf, "deferredShutdownMsecs",
d62a17ae 2998 time_store);
2999 } else {
3000 vty_out(vty,
3001 " Deferred shutdown in progress, %s remaining\n",
3002 ospf_timer_dump(ospf->t_deferred_shutdown,
3003 timebuf, sizeof(timebuf)));
3004 }
3005 }
3006
3007 /* Show capability. */
b1c3ae8c
CS
3008 if (json) {
3009 json_object_boolean_true_add(json_vrf, "tosRoutesOnly");
3010 json_object_boolean_true_add(json_vrf, "rfc2328Conform");
d62a17ae 3011 if (CHECK_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE)) {
b1c3ae8c 3012 json_object_boolean_true_add(json_vrf,
d62a17ae 3013 "rfc1583Compatibility");
3014 }
3015 } else {
3016 vty_out(vty, " Supports only single TOS (TOS0) routes\n");
3017 vty_out(vty, " This implementation conforms to RFC2328\n");
3018 vty_out(vty, " RFC1583Compatibility flag is %s\n",
3019 CHECK_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE)
3020 ? "enabled"
3021 : "disabled");
3022 }
3023
b1c3ae8c 3024 if (json) {
d62a17ae 3025 if (CHECK_FLAG(ospf->config, OSPF_OPAQUE_CAPABLE)) {
b1c3ae8c 3026 json_object_boolean_true_add(json_vrf, "opaqueCapable");
d62a17ae 3027 }
3028 } else {
3029 vty_out(vty, " OpaqueCapability flag is %s\n",
3030 CHECK_FLAG(ospf->config, OSPF_OPAQUE_CAPABLE)
3031 ? "enabled"
3032 : "disabled");
3033 }
3034
3035 /* Show stub-router configuration */
3036 if (ospf->stub_router_startup_time != OSPF_STUB_ROUTER_UNCONFIGURED
3037 || ospf->stub_router_shutdown_time
3038 != OSPF_STUB_ROUTER_UNCONFIGURED) {
b1c3ae8c
CS
3039 if (json) {
3040 json_object_boolean_true_add(json_vrf,
3041 "stubAdvertisement");
d62a17ae 3042 if (ospf->stub_router_startup_time
3043 != OSPF_STUB_ROUTER_UNCONFIGURED)
3044 json_object_int_add(
b1c3ae8c 3045 json_vrf, "postStartEnabledMsecs",
d62a17ae 3046 ospf->stub_router_startup_time / 1000);
3047 if (ospf->stub_router_shutdown_time
3048 != OSPF_STUB_ROUTER_UNCONFIGURED)
3049 json_object_int_add(
b1c3ae8c 3050 json_vrf, "preShutdownEnabledMsecs",
d62a17ae 3051 ospf->stub_router_shutdown_time / 1000);
3052 } else {
3053 vty_out(vty,
3054 " Stub router advertisement is configured\n");
3055 if (ospf->stub_router_startup_time
3056 != OSPF_STUB_ROUTER_UNCONFIGURED)
3057 vty_out(vty,
3058 " Enabled for %us after start-up\n",
3059 ospf->stub_router_startup_time);
3060 if (ospf->stub_router_shutdown_time
3061 != OSPF_STUB_ROUTER_UNCONFIGURED)
3062 vty_out(vty,
3063 " Enabled for %us prior to full shutdown\n",
3064 ospf->stub_router_shutdown_time);
3065 }
3066 }
3067
3068 /* Show SPF timers. */
b1c3ae8c
CS
3069 if (json) {
3070 json_object_int_add(json_vrf, "spfScheduleDelayMsecs",
d62a17ae 3071 ospf->spf_delay);
b1c3ae8c 3072 json_object_int_add(json_vrf, "holdtimeMinMsecs",
d62a17ae 3073 ospf->spf_holdtime);
b1c3ae8c 3074 json_object_int_add(json_vrf, "holdtimeMaxMsecs",
d62a17ae 3075 ospf->spf_max_holdtime);
b1c3ae8c 3076 json_object_int_add(json_vrf, "holdtimeMultplier",
d62a17ae 3077 ospf->spf_hold_multiplier);
3078 } else {
3079 vty_out(vty,
3080 " Initial SPF scheduling delay %d millisec(s)\n"
3081 " Minimum hold time between consecutive SPFs %d millisec(s)\n"
3082 " Maximum hold time between consecutive SPFs %d millisec(s)\n"
3083 " Hold time multiplier is currently %d\n",
3084 ospf->spf_delay, ospf->spf_holdtime,
3085 ospf->spf_max_holdtime, ospf->spf_hold_multiplier);
3086 }
3087
b1c3ae8c 3088 if (json) {
d62a17ae 3089 if (ospf->ts_spf.tv_sec || ospf->ts_spf.tv_usec) {
3090 long time_store = 0;
3091
3092 time_store =
3093 monotime_since(&ospf->ts_spf, NULL) / 1000LL;
b1c3ae8c 3094 json_object_int_add(json_vrf, "spfLastExecutedMsecs",
d62a17ae 3095 time_store);
3096
3097 time_store = (1000 * ospf->ts_spf_duration.tv_sec)
3098 + (ospf->ts_spf_duration.tv_usec / 1000);
b1c3ae8c 3099 json_object_int_add(json_vrf, "spfLastDurationMsecs",
d62a17ae 3100 time_store);
3101 } else
b1c3ae8c 3102 json_object_boolean_true_add(json_vrf, "spfHasNotRun");
d62a17ae 3103 } else {
3104 vty_out(vty, " SPF algorithm ");
3105 if (ospf->ts_spf.tv_sec || ospf->ts_spf.tv_usec) {
3106 monotime_since(&ospf->ts_spf, &result);
3107 vty_out(vty, "last executed %s ago\n",
3108 ospf_timeval_dump(&result, timebuf,
3109 sizeof(timebuf)));
3110 vty_out(vty, " Last SPF duration %s\n",
3111 ospf_timeval_dump(&ospf->ts_spf_duration,
3112 timebuf, sizeof(timebuf)));
3113 } else
3114 vty_out(vty, "has not been run\n");
3115 }
3116
b1c3ae8c 3117 if (json) {
d62a17ae 3118 if (ospf->t_spf_calc) {
3119 long time_store;
3120 time_store =
3121 monotime_until(&ospf->t_spf_calc->u.sands, NULL)
3122 / 1000LL;
b1c3ae8c 3123 json_object_int_add(json_vrf, "spfTimerDueInMsecs",
d62a17ae 3124 time_store);
3125 }
3126
b1c3ae8c 3127 json_object_int_add(json_vrf, "lsaMinIntervalMsecs",
d62a17ae 3128 ospf->min_ls_interval);
b1c3ae8c 3129 json_object_int_add(json_vrf, "lsaMinArrivalMsecs",
d62a17ae 3130 ospf->min_ls_arrival);
3131 /* Show write multiplier values */
b1c3ae8c 3132 json_object_int_add(json_vrf, "writeMultiplier",
d62a17ae 3133 ospf->write_oi_count);
3134 /* Show refresh parameters. */
b1c3ae8c 3135 json_object_int_add(json_vrf, "refreshTimerMsecs",
d62a17ae 3136 ospf->lsa_refresh_interval * 1000);
3137 } else {
3138 vty_out(vty, " SPF timer %s%s\n",
3139 (ospf->t_spf_calc ? "due in " : "is "),
3140 ospf_timer_dump(ospf->t_spf_calc, timebuf,
3141 sizeof(timebuf)));
3142
3143 vty_out(vty, " LSA minimum interval %d msecs\n",
3144 ospf->min_ls_interval);
3145 vty_out(vty, " LSA minimum arrival %d msecs\n",
3146 ospf->min_ls_arrival);
3147
3148 /* Show write multiplier values */
3149 vty_out(vty, " Write Multiplier set to %d \n",
3150 ospf->write_oi_count);
3151
3152 /* Show refresh parameters. */
3153 vty_out(vty, " Refresh timer %d secs\n",
3154 ospf->lsa_refresh_interval);
3155 }
3156
3157 /* Show ABR/ASBR flags. */
3158 if (CHECK_FLAG(ospf->flags, OSPF_FLAG_ABR)) {
b1c3ae8c 3159 if (json)
d62a17ae 3160 json_object_string_add(
b1c3ae8c 3161 json_vrf, "abrType",
d62a17ae 3162 ospf_abr_type_descr_str[ospf->abr_type]);
3163 else
3164 vty_out(vty,
3165 " This router is an ABR, ABR type is: %s\n",
3166 ospf_abr_type_descr_str[ospf->abr_type]);
3167 }
3168 if (CHECK_FLAG(ospf->flags, OSPF_FLAG_ASBR)) {
b1c3ae8c 3169 if (json)
d62a17ae 3170 json_object_string_add(
b1c3ae8c 3171 json_vrf, "asbrRouter",
d62a17ae 3172 "injectingExternalRoutingInformation");
3173 else
3174 vty_out(vty,
3175 " This router is an ASBR "
3176 "(injecting external routing information)\n");
3177 }
3178
3179 /* Show Number of AS-external-LSAs. */
b1c3ae8c 3180 if (json) {
d62a17ae 3181 json_object_int_add(
b1c3ae8c 3182 json_vrf, "lsaExternalCounter",
d62a17ae 3183 ospf_lsdb_count(ospf->lsdb, OSPF_AS_EXTERNAL_LSA));
3184 json_object_int_add(
b1c3ae8c 3185 json_vrf, "lsaExternalChecksum",
d62a17ae 3186 ospf_lsdb_checksum(ospf->lsdb, OSPF_AS_EXTERNAL_LSA));
3187 } else {
3188 vty_out(vty,
3189 " Number of external LSA %ld. Checksum Sum 0x%08x\n",
3190 ospf_lsdb_count(ospf->lsdb, OSPF_AS_EXTERNAL_LSA),
3191 ospf_lsdb_checksum(ospf->lsdb, OSPF_AS_EXTERNAL_LSA));
3192 }
3193
b1c3ae8c 3194 if (json) {
d62a17ae 3195 json_object_int_add(
b1c3ae8c 3196 json_vrf, "lsaAsopaqueCounter",
d62a17ae 3197 ospf_lsdb_count(ospf->lsdb, OSPF_OPAQUE_AS_LSA));
3198 json_object_int_add(
b1c3ae8c 3199 json_vrf, "lsaAsOpaqueChecksum",
d62a17ae 3200 ospf_lsdb_checksum(ospf->lsdb, OSPF_OPAQUE_AS_LSA));
3201 } else {
3202 vty_out(vty,
3203 " Number of opaque AS LSA %ld. Checksum Sum 0x%08x\n",
3204 ospf_lsdb_count(ospf->lsdb, OSPF_OPAQUE_AS_LSA),
3205 ospf_lsdb_checksum(ospf->lsdb, OSPF_OPAQUE_AS_LSA));
3206 }
3207
3208 /* Show number of areas attached. */
b1c3ae8c
CS
3209 if (json)
3210 json_object_int_add(json_vrf, "attachedAreaCounter",
d62a17ae 3211 listcount(ospf->areas));
3212 else
3213 vty_out(vty, " Number of areas attached to this router: %d\n",
3214 listcount(ospf->areas));
3215
3216 if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES)) {
3217 if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL)) {
b1c3ae8c 3218 if (json)
d62a17ae 3219 json_object_boolean_true_add(
b1c3ae8c 3220 json_vrf, "adjacencyChangesLoggedAll");
d62a17ae 3221 else
3222 vty_out(vty,
3223 " All adjacency changes are logged\n");
3224 } else {
b1c3ae8c 3225 if (json)
d62a17ae 3226 json_object_boolean_true_add(
b1c3ae8c 3227 json_vrf, "adjacencyChangesLogged");
d62a17ae 3228 else
3229 vty_out(vty, " Adjacency changes are logged\n");
3230 }
3231 }
3232 /* Show each area status. */
3233 for (ALL_LIST_ELEMENTS(ospf->areas, node, nnode, area))
b1c3ae8c
CS
3234 show_ip_ospf_area(vty, area, json_areas, json ? 1 : 0);
3235
3236 if (json) {
3237 if (use_vrf) {
3238 json_object_object_add(json_vrf, "areas", json_areas);
3239 if (ospf->vrf_id == VRF_DEFAULT)
3240 json_object_object_add(json, "default",
3241 json_vrf);
3242 else
3243 json_object_object_add(json, ospf->name,
3244 json_vrf);
3245 } else {
3246 json_object_object_add(json, "areas", json_areas);
3247 }
d62a17ae 3248 } else
3249 vty_out(vty, "\n");
3250
3251 return CMD_SUCCESS;
718e3744 3252}
3253
7c8ff89e
DS
3254DEFUN (show_ip_ospf,
3255 show_ip_ospf_cmd,
b5a8894d 3256 "show ip ospf [vrf <NAME|all>] [json]",
7c8ff89e
DS
3257 SHOW_STR
3258 IP_STR
ca08c43d 3259 "OSPF information\n"
b5a8894d
CS
3260 VRF_CMD_HELP_STR
3261 "All VRFs\n"
9973d184 3262 JSON_STR)
7c8ff89e 3263{
d62a17ae 3264 struct ospf *ospf;
d7c0a89a 3265 uint8_t uj = use_json(argc, argv);
b5a8894d
CS
3266 struct listnode *node = NULL;
3267 char *vrf_name = NULL;
3268 bool all_vrf = FALSE;
3269 int ret = CMD_SUCCESS;
3270 int inst = 0;
3271 int idx_vrf = 0;
b1c3ae8c 3272 json_object *json = NULL;
d7c0a89a 3273 uint8_t use_vrf = 0;
7c8ff89e 3274
b5a8894d 3275 if (listcount(om->ospf) == 0)
d62a17ae 3276 return CMD_SUCCESS;
7c8ff89e 3277
43b8d1d8 3278 OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
b5a8894d 3279
b1c3ae8c
CS
3280 if (uj)
3281 json = json_object_new_object();
3282
996c9314 3283 /* vrf input is provided could be all or specific vrf*/
b5a8894d 3284 if (vrf_name) {
b1c3ae8c 3285 use_vrf = 1;
b5a8894d
CS
3286 if (all_vrf) {
3287 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
3288 if (!ospf->oi_running)
3289 continue;
b1c3ae8c
CS
3290 ret = show_ip_ospf_common(vty, ospf, json,
3291 use_vrf);
3292 }
3293 if (uj) {
3294 vty_out(vty, "%s\n",
996c9314
LB
3295 json_object_to_json_string_ext(
3296 json, JSON_C_TO_STRING_PRETTY));
b1c3ae8c 3297 json_object_free(json);
b5a8894d
CS
3298 }
3299 return ret;
3300 }
3301 ospf = ospf_lookup_by_inst_name(inst, vrf_name);
b1c3ae8c
CS
3302 if ((ospf == NULL) || !ospf->oi_running) {
3303 if (uj)
3304 json_object_free(json);
b5a8894d 3305 return CMD_SUCCESS;
b1c3ae8c 3306 }
b5a8894d
CS
3307 } else {
3308 ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
3309 /* Display default ospf (instance 0) info */
b1c3ae8c
CS
3310 if (ospf == NULL || !ospf->oi_running) {
3311 if (uj)
3312 json_object_free(json);
b5a8894d 3313 return CMD_SUCCESS;
b1c3ae8c 3314 }
b5a8894d
CS
3315 }
3316
996c9314 3317 if (ospf) {
b1c3ae8c
CS
3318 show_ip_ospf_common(vty, ospf, json, use_vrf);
3319 if (uj)
996c9314
LB
3320 vty_out(vty, "%s\n",
3321 json_object_to_json_string_ext(
3322 json, JSON_C_TO_STRING_PRETTY));
b1c3ae8c
CS
3323 }
3324
3325 if (uj)
3326 json_object_free(json);
b5a8894d
CS
3327
3328 return ret;
7c8ff89e
DS
3329}
3330
3331DEFUN (show_ip_ospf_instance,
3332 show_ip_ospf_instance_cmd,
6147e2c6 3333 "show ip ospf (1-65535) [json]",
7c8ff89e
DS
3334 SHOW_STR
3335 IP_STR
3336 "OSPF information\n"
ca08c43d 3337 "Instance ID\n"
9973d184 3338 JSON_STR)
7c8ff89e 3339{
d62a17ae 3340 int idx_number = 3;
3341 struct ospf *ospf;
d7c0a89a
QY
3342 unsigned short instance = 0;
3343 uint8_t uj = use_json(argc, argv);
b1c3ae8c
CS
3344 int ret = CMD_SUCCESS;
3345 json_object *json = NULL;
d62a17ae 3346
3347 instance = strtoul(argv[idx_number]->arg, NULL, 10);
ac28e4ec
CS
3348 ospf = ospf_lookup_instance(instance);
3349 if (ospf == NULL)
3350 return CMD_NOT_MY_INSTANCE;
3351
3352 if (!ospf->oi_running)
d62a17ae 3353 return CMD_SUCCESS;
3354
b1c3ae8c
CS
3355 if (uj)
3356 json = json_object_new_object();
3357
3358 ret = show_ip_ospf_common(vty, ospf, json, 0);
3359
3360 if (uj) {
996c9314
LB
3361 vty_out(vty, "%s\n", json_object_to_json_string_ext(
3362 json, JSON_C_TO_STRING_PRETTY));
b1c3ae8c
CS
3363 json_object_free(json);
3364 }
3365
3366 return ret;
d62a17ae 3367}
3368
3369static void show_ip_ospf_interface_sub(struct vty *vty, struct ospf *ospf,
3370 struct interface *ifp,
3371 json_object *json_interface_sub,
d7c0a89a 3372 uint8_t use_json)
d62a17ae 3373{
3374 int is_up;
3375 struct ospf_neighbor *nbr;
3376 struct route_node *rn;
3377 uint32_t bandwidth = ifp->bandwidth ? ifp->bandwidth : ifp->speed;
3378
3379 /* Is interface up? */
3380 if (use_json) {
3381 is_up = if_is_operative(ifp);
3382 if (is_up)
3383 json_object_boolean_true_add(json_interface_sub,
3384 "ifUp");
3385 else
3386 json_object_boolean_false_add(json_interface_sub,
3387 "ifDown");
3388
3389 json_object_int_add(json_interface_sub, "ifIndex",
3390 ifp->ifindex);
3391 json_object_int_add(json_interface_sub, "mtuBytes", ifp->mtu);
3392 json_object_int_add(json_interface_sub, "bandwidthMbit",
3393 bandwidth);
3394 json_object_string_add(json_interface_sub, "ifFlags",
3395 if_flag_dump(ifp->flags));
3396 } else {
3397 vty_out(vty, "%s is %s\n", ifp->name,
3398 ((is_up = if_is_operative(ifp)) ? "up" : "down"));
3399 vty_out(vty, " ifindex %u, MTU %u bytes, BW %u Mbit %s\n",
3400 ifp->ifindex, ifp->mtu, bandwidth,
3401 if_flag_dump(ifp->flags));
3402 }
7c8ff89e 3403
d62a17ae 3404 /* Is interface OSPF enabled? */
3405 if (use_json) {
3406 if (ospf_oi_count(ifp) == 0) {
3407 json_object_boolean_false_add(json_interface_sub,
3408 "ospfEnabled");
3409 return;
3410 } else if (!is_up) {
3411 json_object_boolean_false_add(json_interface_sub,
3412 "ospfRunning");
3413 return;
3414 } else
3415 json_object_boolean_true_add(json_interface_sub,
3416 "ospfEnabled");
3417 } else {
3418 if (ospf_oi_count(ifp) == 0) {
3419 vty_out(vty, " OSPF not enabled on this interface\n");
3420 return;
3421 } else if (!is_up) {
3422 vty_out(vty,
3423 " OSPF is enabled, but not running on this interface\n");
3424 return;
3425 }
3426 }
3427
3428 for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) {
3429 struct ospf_interface *oi = rn->info;
3430
3431 if (oi == NULL)
3432 continue;
3433
3434 if (CHECK_FLAG(oi->connected->flags, ZEBRA_IFA_UNNUMBERED)) {
3435 if (use_json)
3436 json_object_boolean_true_add(json_interface_sub,
3437 "ifUnnumbered");
3438 else
3439 vty_out(vty, " This interface is UNNUMBERED,");
3440 } else {
3441 /* Show OSPF interface information. */
3442 if (use_json) {
3443 json_object_string_add(
3444 json_interface_sub, "ipAddress",
3445 inet_ntoa(oi->address->u.prefix4));
3446 json_object_int_add(json_interface_sub,
3447 "ipAddressPrefixlen",
3448 oi->address->prefixlen);
3449 } else
3450 vty_out(vty, " Internet Address %s/%d,",
3451 inet_ntoa(oi->address->u.prefix4),
3452 oi->address->prefixlen);
3453
3454 if (oi->connected->destination
3455 || oi->type == OSPF_IFTYPE_VIRTUALLINK) {
3456 struct in_addr *dest;
3457 const char *dstr;
3458
3459 if (CONNECTED_PEER(oi->connected)
3460 || oi->type == OSPF_IFTYPE_VIRTUALLINK)
3461 dstr = "Peer";
3462 else
3463 dstr = "Broadcast";
3464
3465 /* For Vlinks, showing the peer address is
9d303b37
DL
3466 * probably more
3467 * * * * * informative than the local
3468 * interface that is being used
3469 * * * * */
d62a17ae 3470 if (oi->type == OSPF_IFTYPE_VIRTUALLINK)
3471 dest = &oi->vl_data->peer_addr;
3472 else
3473 dest = &oi->connected->destination->u
3474 .prefix4;
3475
3476 if (use_json) {
3477 json_object_string_add(
3478 json_interface_sub,
3479 "ospfIfType", dstr);
3480 if (oi->type == OSPF_IFTYPE_VIRTUALLINK)
3481 json_object_string_add(
3482 json_interface_sub,
3483 "vlinkPeer",
3484 inet_ntoa(*dest));
3485 else
3486 json_object_string_add(
3487 json_interface_sub,
3488 "localIfUsed",
3489 inet_ntoa(*dest));
3490 } else
3491 vty_out(vty, " %s %s,", dstr,
3492 inet_ntoa(*dest));
3493 }
3494 }
3495 if (use_json) {
3496 json_object_string_add(json_interface_sub, "area",
3497 ospf_area_desc_string(oi->area));
3498 if (OSPF_IF_PARAM(oi, mtu_ignore))
3499 json_object_boolean_true_add(
3500 json_interface_sub,
3501 "mtuMismatchDetect");
3502 json_object_string_add(json_interface_sub, "routerId",
3503 inet_ntoa(ospf->router_id));
3504 json_object_string_add(json_interface_sub,
3505 "networkType",
3506 ospf_network_type_str[oi->type]);
3507 json_object_int_add(json_interface_sub, "cost",
3508 oi->output_cost);
3509 json_object_int_add(
3510 json_interface_sub, "transmitDelayMsecs",
3511 1000 / OSPF_IF_PARAM(oi, transmit_delay));
3512 json_object_string_add(json_interface_sub, "state",
3513 lookup_msg(ospf_ism_state_msg,
3514 oi->state, NULL));
3515 json_object_int_add(json_interface_sub, "priority",
3516 PRIORITY(oi));
3517 } else {
3518 vty_out(vty, " Area %s\n",
3519 ospf_area_desc_string(oi->area));
3520
3521 vty_out(vty, " MTU mismatch detection: %s\n",
3522 OSPF_IF_PARAM(oi, mtu_ignore) ? "disabled"
3523 : "enabled");
3524
3525 vty_out(vty,
3526 " Router ID %s, Network Type %s, Cost: %d\n",
3527 inet_ntoa(ospf->router_id),
3528 ospf_network_type_str[oi->type],
3529 oi->output_cost);
3530
3531 vty_out(vty,
3532 " Transmit Delay is %d sec, State %s, Priority %d\n",
3533 OSPF_IF_PARAM(oi, transmit_delay),
3534 lookup_msg(ospf_ism_state_msg, oi->state, NULL),
3535 PRIORITY(oi));
3536 }
3537
3538 /* Show DR information. */
3539 if (DR(oi).s_addr == 0) {
3540 if (!use_json)
3541 vty_out(vty,
3542 " No backup designated router on this network\n");
3543 } else {
3544 nbr = ospf_nbr_lookup_by_addr(oi->nbrs, &BDR(oi));
3545 if (nbr == NULL) {
3546 if (!use_json)
3547 vty_out(vty,
3548 " No backup designated router on this network\n");
3549 } else {
3550 if (use_json) {
3551 json_object_string_add(
3552 json_interface_sub, "bdrId",
3553 inet_ntoa(nbr->router_id));
3554 json_object_string_add(
3555 json_interface_sub,
3556 "bdrAddress",
3557 inet_ntoa(nbr->address.u
3558 .prefix4));
3559 } else {
3560 vty_out(vty,
3561 " Backup Designated Router (ID) %s,",
3562 inet_ntoa(nbr->router_id));
3563 vty_out(vty, " Interface Address %s\n",
3564 inet_ntoa(nbr->address.u
3565 .prefix4));
3566 }
3567 }
3568 }
3569
3570 /* Next network-LSA sequence number we'll use, if we're elected
3571 * DR */
3572 if (oi->params
3573 && ntohl(oi->params->network_lsa_seqnum)
3574 != OSPF_INITIAL_SEQUENCE_NUMBER) {
3575 if (use_json)
3576 json_object_int_add(
3577 json_interface_sub,
3578 "networkLsaSequence",
3579 ntohl(oi->params->network_lsa_seqnum));
3580 else
3581 vty_out(vty,
3582 " Saved Network-LSA sequence number 0x%x\n",
3583 ntohl(oi->params->network_lsa_seqnum));
3584 }
3585
3586 if (use_json) {
3587 if (OI_MEMBER_CHECK(oi, MEMBER_ALLROUTERS)
3588 || OI_MEMBER_CHECK(oi, MEMBER_DROUTERS)) {
3589 if (OI_MEMBER_CHECK(oi, MEMBER_ALLROUTERS))
3590 json_object_boolean_true_add(
3591 json_interface_sub,
3592 "mcastMemberOspfAllRouters");
3593 if (OI_MEMBER_CHECK(oi, MEMBER_DROUTERS))
3594 json_object_boolean_true_add(
3595 json_interface_sub,
3596 "mcastMemberOspfDesignatedRouters");
3597 }
3598 } else {
3599 vty_out(vty, " Multicast group memberships:");
3600 if (OI_MEMBER_CHECK(oi, MEMBER_ALLROUTERS)
3601 || OI_MEMBER_CHECK(oi, MEMBER_DROUTERS)) {
3602 if (OI_MEMBER_CHECK(oi, MEMBER_ALLROUTERS))
3603 vty_out(vty, " OSPFAllRouters");
3604 if (OI_MEMBER_CHECK(oi, MEMBER_DROUTERS))
3605 vty_out(vty, " OSPFDesignatedRouters");
3606 } else
3607 vty_out(vty, " <None>");
3608 vty_out(vty, "\n");
3609 }
3610
3611 if (use_json) {
3612 if (OSPF_IF_PARAM(oi, fast_hello) == 0)
3613 json_object_int_add(
3614 json_interface_sub, "timerMsecs",
3615 1000 / OSPF_IF_PARAM(oi, v_hello));
3616 else
3617 json_object_int_add(
3618 json_interface_sub, "timerMsecs",
3619 1000 / OSPF_IF_PARAM(oi, fast_hello));
3620 json_object_int_add(json_interface_sub,
3621 "timerDeadMsecs",
3622 1000 / OSPF_IF_PARAM(oi, v_wait));
3623 json_object_int_add(json_interface_sub,
3624 "timerWaitMsecs",
3625 1000 / OSPF_IF_PARAM(oi, v_wait));
3626 json_object_int_add(
3627 json_interface_sub, "timerRetransmit",
3628 1000 / OSPF_IF_PARAM(oi, retransmit_interval));
3629 } else {
3630 vty_out(vty, " Timer intervals configured,");
3631 vty_out(vty, " Hello ");
3632 if (OSPF_IF_PARAM(oi, fast_hello) == 0)
3633 vty_out(vty, "%ds,",
3634 OSPF_IF_PARAM(oi, v_hello));
3635 else
3636 vty_out(vty, "%dms,",
3637 1000 / OSPF_IF_PARAM(oi, fast_hello));
3638 vty_out(vty, " Dead %ds, Wait %ds, Retransmit %d\n",
3639 OSPF_IF_PARAM(oi, v_wait),
3640 OSPF_IF_PARAM(oi, v_wait),
3641 OSPF_IF_PARAM(oi, retransmit_interval));
3642 }
3643
3644 if (OSPF_IF_PASSIVE_STATUS(oi) == OSPF_IF_ACTIVE) {
3645 char timebuf[OSPF_TIME_DUMP_SIZE];
3646 if (use_json) {
3647 long time_store = 0;
3648 if (oi->t_hello)
3649 time_store =
3650 monotime_until(
3651 &oi->t_hello->u.sands,
3652 NULL)
3653 / 1000LL;
3654 json_object_int_add(json_interface_sub,
3655 "timerHelloInMsecs",
3656 time_store);
3657 } else
3658 vty_out(vty, " Hello due in %s\n",
3659 ospf_timer_dump(oi->t_hello, timebuf,
3660 sizeof(timebuf)));
3661 } else /* passive-interface is set */
3662 {
3663 if (use_json)
3664 json_object_boolean_true_add(
3665 json_interface_sub,
3666 "timerPassiveIface");
3667 else
3668 vty_out(vty,
3669 " No Hellos (Passive interface)\n");
3670 }
7c8ff89e 3671
d62a17ae 3672 if (use_json) {
3673 json_object_int_add(json_interface_sub, "nbrCount",
3674 ospf_nbr_count(oi, 0));
3675 json_object_int_add(json_interface_sub,
3676 "nbrAdjacentCount",
3677 ospf_nbr_count(oi, NSM_Full));
3678 } else
3679 vty_out(vty,
3680 " Neighbor Count is %d, Adjacent neighbor count is %d\n",
3681 ospf_nbr_count(oi, 0),
3682 ospf_nbr_count(oi, NSM_Full));
3683 ospf_bfd_interface_show(vty, ifp, json_interface_sub, use_json);
3684 }
718e3744 3685}
3686
d62a17ae 3687static int show_ip_ospf_interface_common(struct vty *vty, struct ospf *ospf,
d7c0a89a
QY
3688 char *intf_name, uint8_t use_vrf,
3689 json_object *json, uint8_t use_json)
d62a17ae 3690{
3691 struct interface *ifp;
f4e14fdb 3692 struct vrf *vrf = vrf_lookup_by_id(ospf->vrf_id);
6282e124 3693 json_object *json_vrf = NULL;
7dab10ce 3694 json_object *json_interface_sub = NULL, *json_interface = NULL;
7c8ff89e 3695
d62a17ae 3696 if (use_json) {
b1c3ae8c
CS
3697 if (use_vrf)
3698 json_vrf = json_object_new_object();
3699 else
3700 json_vrf = json;
6282e124 3701 json_interface = json_object_new_object();
d62a17ae 3702 }
3703
3704 if (ospf->instance) {
3705 if (use_json)
3706 json_object_int_add(json, "ospfInstance",
3707 ospf->instance);
3708 else
3709 vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
3710 }
3711
b1c3ae8c
CS
3712 ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf);
3713
3714 if (intf_name == NULL) {
d62a17ae 3715 /* Show All Interfaces.*/
451fda4f 3716 FOR_ALL_INTERFACES (vrf, ifp) {
d62a17ae 3717 if (ospf_oi_count(ifp)) {
7dab10ce 3718 if (use_json) {
d62a17ae 3719 json_interface_sub =
3720 json_object_new_object();
7dab10ce 3721 }
d62a17ae 3722 show_ip_ospf_interface_sub(vty, ospf, ifp,
3723 json_interface_sub,
3724 use_json);
3725
7dab10ce 3726 if (use_json) {
d62a17ae 3727 json_object_object_add(
7dab10ce 3728 json_interface, ifp->name,
d62a17ae 3729 json_interface_sub);
7dab10ce 3730 }
d62a17ae 3731 }
3732 }
6282e124
CS
3733 if (use_json)
3734 json_object_object_add(json_vrf, "interfaces",
996c9314 3735 json_interface);
d62a17ae 3736 } else {
3737 /* Interface name is specified. */
b1c3ae8c
CS
3738 ifp = if_lookup_by_name(intf_name, ospf->vrf_id);
3739 if (ifp == NULL) {
d62a17ae 3740 if (use_json)
b1c3ae8c 3741 json_object_boolean_true_add(json_vrf,
d62a17ae 3742 "noSuchIface");
3743 else
3744 vty_out(vty, "No such interface name\n");
3745 } else {
7dab10ce 3746 if (use_json) {
d62a17ae 3747 json_interface_sub = json_object_new_object();
7dab10ce 3748 json_interface = json_object_new_object();
7dab10ce 3749 }
d62a17ae 3750
3751 show_ip_ospf_interface_sub(
3752 vty, ospf, ifp, json_interface_sub, use_json);
3753
7dab10ce 3754 if (use_json) {
7dab10ce
CS
3755 json_object_object_add(json_interface,
3756 ifp->name,
d62a17ae 3757 json_interface_sub);
6282e124
CS
3758 json_object_object_add(json_vrf, "interfaces",
3759 json_interface);
7dab10ce 3760 }
d62a17ae 3761 }
3762 }
3763
3764 if (use_json) {
b1c3ae8c
CS
3765 if (use_vrf) {
3766 if (ospf->vrf_id == VRF_DEFAULT)
3767 json_object_object_add(json, "default",
3768 json_vrf);
3769 else
3770 json_object_object_add(json, ospf->name,
3771 json_vrf);
3772 }
d62a17ae 3773 } else
3774 vty_out(vty, "\n");
3775
3776 return CMD_SUCCESS;
718e3744 3777}
3778
c9339663
CS
3779static void show_ip_ospf_interface_traffic_sub(struct vty *vty,
3780 struct ospf_interface *oi,
3781 json_object *json_interface_sub,
d7c0a89a 3782 uint8_t use_json)
c9339663
CS
3783{
3784 if (use_json) {
996c9314
LB
3785 json_object_int_add(json_interface_sub, "ifIndex",
3786 oi->ifp->ifindex);
3787 json_object_int_add(json_interface_sub, "helloIn",
3788 oi->hello_in);
3789 json_object_int_add(json_interface_sub, "helloOut",
3790 oi->hello_out);
3791 json_object_int_add(json_interface_sub, "dbDescIn",
3792 oi->db_desc_in);
3793 json_object_int_add(json_interface_sub, "dbDescOut",
3794 oi->db_desc_out);
3795 json_object_int_add(json_interface_sub, "lsReqIn",
3796 oi->ls_req_in);
3797 json_object_int_add(json_interface_sub, "lsReqOut",
3798 oi->ls_req_out);
3799 json_object_int_add(json_interface_sub, "lsUpdIn",
3800 oi->ls_upd_in);
3801 json_object_int_add(json_interface_sub, "lsUpdOut",
3802 oi->ls_upd_out);
3803 json_object_int_add(json_interface_sub, "lsAckIn",
3804 oi->ls_ack_in);
3805 json_object_int_add(json_interface_sub, "lsAckOut",
3806 oi->ls_ack_out);
c9339663
CS
3807 } else {
3808 vty_out(vty,
3809 "%-10s %8u/%-8u %7u/%-7u %7u/%-7u %7u/%-7u %7u/%-7u\n",
996c9314
LB
3810 oi->ifp->name, oi->hello_in, oi->hello_out,
3811 oi->db_desc_in, oi->db_desc_out, oi->ls_req_in,
3812 oi->ls_req_out, oi->ls_upd_in, oi->ls_upd_out,
c9339663
CS
3813 oi->ls_ack_in, oi->ls_ack_out);
3814 }
3815}
3816
3817/* OSPFv2 Packet Counters */
996c9314
LB
3818static int show_ip_ospf_interface_traffic_common(
3819 struct vty *vty, struct ospf *ospf, char *intf_name, json_object *json,
d7c0a89a 3820 int display_once, uint8_t use_vrf, uint8_t use_json)
c9339663
CS
3821{
3822 struct vrf *vrf = NULL;
3823 struct interface *ifp = NULL;
b1c3ae8c 3824 json_object *json_vrf = NULL;
c9339663
CS
3825 json_object *json_interface_sub = NULL;
3826
3827 if (!use_json && !display_once) {
3828 vty_out(vty, "\n");
996c9314
LB
3829 vty_out(vty, "%-12s%-17s%-17s%-17s%-17s%-17s\n", "Interface",
3830 " HELLO", " DB-Desc", " LS-Req", " LS-Update",
3831 " LS-Ack");
c9339663 3832 vty_out(vty, "%-10s%-18s%-18s%-17s%-17s%-17s\n", "",
996c9314
LB
3833 " Rx/Tx", " Rx/Tx", " Rx/Tx", " Rx/Tx",
3834 " Rx/Tx");
c9339663 3835 vty_out(vty,
996c9314 3836 "--------------------------------------------------------------------------------------------\n");
c9339663 3837 } else if (use_json) {
b1c3ae8c
CS
3838 if (use_vrf)
3839 json_vrf = json_object_new_object();
3840 else
3841 json_vrf = json;
c9339663
CS
3842 }
3843
b1c3ae8c
CS
3844 ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf);
3845
c9339663
CS
3846 if (intf_name == NULL) {
3847 vrf = vrf_lookup_by_id(ospf->vrf_id);
3848 FOR_ALL_INTERFACES (vrf, ifp) {
3849 struct route_node *rn;
3850 struct ospf_interface *oi;
3851
3852 if (ospf_oi_count(ifp) == 0)
3853 continue;
3854
3855 for (rn = route_top(IF_OIFS(ifp)); rn;
996c9314 3856 rn = route_next(rn)) {
c9339663
CS
3857 oi = rn->info;
3858
3859 if (oi == NULL)
3860 continue;
3861
3862 if (use_json) {
3863 json_interface_sub =
3864 json_object_new_object();
3865 }
3866
996c9314
LB
3867 show_ip_ospf_interface_traffic_sub(
3868 vty, oi, json_interface_sub, use_json);
c9339663 3869 if (use_json) {
996c9314
LB
3870 json_object_object_add(
3871 json_vrf, ifp->name,
3872 json_interface_sub);
c9339663
CS
3873 }
3874 }
3875 }
3876 } else {
3877 /* Interface name is specified. */
3878 ifp = if_lookup_by_name(intf_name, ospf->vrf_id);
3879 if (ifp != NULL) {
3880 struct route_node *rn;
3881 struct ospf_interface *oi;
3882
3883 if (ospf_oi_count(ifp) == 0) {
996c9314
LB
3884 vty_out(vty,
3885 " OSPF not enabled on this interface %s\n",
c9339663
CS
3886 ifp->name);
3887 return CMD_SUCCESS;
3888 }
3889
3890 for (rn = route_top(IF_OIFS(ifp)); rn;
3891 rn = route_next(rn)) {
3892 oi = rn->info;
3893
3894 if (use_json) {
3895 json_interface_sub =
3896 json_object_new_object();
3897 }
3898
996c9314
LB
3899 show_ip_ospf_interface_traffic_sub(
3900 vty, oi, json_interface_sub, use_json);
c9339663 3901 if (use_json) {
996c9314
LB
3902 json_object_object_add(
3903 json_vrf, ifp->name,
3904 json_interface_sub);
c9339663
CS
3905 }
3906 }
3907 }
3908 }
3909
3910 if (use_json) {
b1c3ae8c
CS
3911 if (use_vrf) {
3912 if (ospf->vrf_id == VRF_DEFAULT)
3913 json_object_object_add(json, "default",
3914 json_vrf);
3915 else
3916 json_object_object_add(json, ospf->name,
3917 json_vrf);
3918 }
3919 } else
3920 vty_out(vty, "\n");
c9339663
CS
3921
3922 return CMD_SUCCESS;
3923}
3924
7c8ff89e
DS
3925DEFUN (show_ip_ospf_interface,
3926 show_ip_ospf_interface_cmd,
43b8d1d8 3927 "show ip ospf [vrf <NAME|all>] interface [INTERFACE] [json]",
7c8ff89e
DS
3928 SHOW_STR
3929 IP_STR
3930 "OSPF information\n"
b5a8894d 3931 VRF_CMD_HELP_STR
43b8d1d8 3932 "All VRFs\n"
7c8ff89e 3933 "Interface information\n"
7ec4159b 3934 "Interface name\n"
9973d184 3935 JSON_STR)
7c8ff89e 3936{
d62a17ae 3937 struct ospf *ospf;
d7c0a89a 3938 uint8_t uj = use_json(argc, argv);
b5a8894d 3939 struct listnode *node = NULL;
b1c3ae8c 3940 char *vrf_name = NULL, *intf_name = NULL;
b5a8894d
CS
3941 bool all_vrf = FALSE;
3942 int ret = CMD_SUCCESS;
3943 int inst = 0;
b1c3ae8c 3944 int idx_vrf = 0, idx_intf = 0;
d7c0a89a 3945 uint8_t use_vrf = 0;
b1c3ae8c 3946 json_object *json = NULL;
7c8ff89e 3947
43b8d1d8
CS
3948 OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
3949
b1c3ae8c
CS
3950 if (argv_find(argv, argc, "INTERFACE", &idx_intf))
3951 intf_name = argv[idx_intf]->arg;
3952
d62a17ae 3953 if (uj)
b1c3ae8c 3954 json = json_object_new_object();
6be4da3d 3955
b5a8894d
CS
3956 /* vrf input is provided could be all or specific vrf*/
3957 if (vrf_name) {
b1c3ae8c 3958 use_vrf = 1;
b5a8894d
CS
3959 if (all_vrf) {
3960 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
3961 if (!ospf->oi_running)
3962 continue;
996c9314
LB
3963 ret = show_ip_ospf_interface_common(
3964 vty, ospf, intf_name, use_vrf, json,
3965 uj);
b5a8894d 3966 }
b1c3ae8c
CS
3967
3968 if (uj) {
3969 vty_out(vty, "%s\n",
996c9314
LB
3970 json_object_to_json_string_ext(
3971 json, JSON_C_TO_STRING_PRETTY));
b1c3ae8c
CS
3972 json_object_free(json);
3973 }
3974
b5a8894d
CS
3975 return ret;
3976 }
3977 ospf = ospf_lookup_by_inst_name(inst, vrf_name);
b1c3ae8c
CS
3978 if (ospf == NULL || !ospf->oi_running) {
3979 if (uj)
3980 json_object_free(json);
b5a8894d 3981 return CMD_SUCCESS;
b1c3ae8c
CS
3982 }
3983 ret = show_ip_ospf_interface_common(vty, ospf, intf_name,
3984 use_vrf, json, uj);
b5a8894d
CS
3985
3986 } else {
3987 /* Display default ospf (instance 0) info */
3988 ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
b1c3ae8c
CS
3989 if (ospf == NULL || !ospf->oi_running) {
3990 if (uj)
3991 json_object_free(json);
b5a8894d 3992 return CMD_SUCCESS;
b1c3ae8c
CS
3993 }
3994 ret = show_ip_ospf_interface_common(vty, ospf, intf_name,
3995 use_vrf, json, uj);
3996 }
3997
3998 if (uj) {
996c9314
LB
3999 vty_out(vty, "%s\n", json_object_to_json_string_ext(
4000 json, JSON_C_TO_STRING_PRETTY));
b1c3ae8c 4001 json_object_free(json);
b5a8894d
CS
4002 }
4003
4004 return ret;
7c8ff89e
DS
4005}
4006
4007DEFUN (show_ip_ospf_instance_interface,
4008 show_ip_ospf_instance_interface_cmd,
6147e2c6 4009 "show ip ospf (1-65535) interface [INTERFACE] [json]",
7c8ff89e
DS
4010 SHOW_STR
4011 IP_STR
4012 "OSPF information\n"
4013 "Instance ID\n"
4014 "Interface information\n"
7ec4159b 4015 "Interface name\n"
9973d184 4016 JSON_STR)
7c8ff89e 4017{
d62a17ae 4018 int idx_number = 3;
b1c3ae8c 4019 int idx_intf = 0;
d62a17ae 4020 struct ospf *ospf;
d7c0a89a
QY
4021 unsigned short instance = 0;
4022 uint8_t uj = use_json(argc, argv);
b1c3ae8c
CS
4023 char *intf_name = NULL;
4024 int ret = CMD_SUCCESS;
4025 json_object *json = NULL;
d62a17ae 4026
4027 instance = strtoul(argv[idx_number]->arg, NULL, 10);
ac28e4ec
CS
4028 ospf = ospf_lookup_instance(instance);
4029 if (ospf == NULL)
4030 return CMD_NOT_MY_INSTANCE;
4031
4032 if (!ospf->oi_running)
d62a17ae 4033 return CMD_SUCCESS;
4034
4035 if (uj)
b1c3ae8c
CS
4036 json = json_object_new_object();
4037
4038 if (argv_find(argv, argc, "INTERFACE", &idx_intf))
4039 intf_name = argv[idx_intf]->arg;
4040
4041 ret = show_ip_ospf_interface_common(vty, ospf, intf_name, 0, json, uj);
4042
4043 if (uj) {
996c9314
LB
4044 vty_out(vty, "%s\n", json_object_to_json_string_ext(
4045 json, JSON_C_TO_STRING_PRETTY));
b1c3ae8c
CS
4046 json_object_free(json);
4047 }
d62a17ae 4048
b1c3ae8c 4049 return ret;
d62a17ae 4050}
4051
c9339663
CS
4052DEFUN (show_ip_ospf_interface_traffic,
4053 show_ip_ospf_interface_traffic_cmd,
4054 "show ip ospf [vrf <NAME|all>] interface traffic [INTERFACE] [json]",
4055 SHOW_STR
4056 IP_STR
4057 "OSPF information\n"
4058 VRF_CMD_HELP_STR
4059 "All VRFs\n"
4060 "Interface information\n"
4061 "Protocol Packet counters\n"
4062 "Interface name\n"
4063 JSON_STR)
4064{
4065 struct ospf *ospf = NULL;
4066 struct listnode *node = NULL;
4067 char *vrf_name = NULL, *intf_name = NULL;
4068 bool all_vrf = FALSE;
4069 int inst = 0;
4070 int idx_vrf = 0, idx_intf = 0;
d7c0a89a 4071 uint8_t uj = use_json(argc, argv);
b1c3ae8c 4072 json_object *json = NULL;
c9339663
CS
4073 int ret = CMD_SUCCESS;
4074 int display_once = 0;
d7c0a89a 4075 uint8_t use_vrf = 0;
c9339663
CS
4076
4077 OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
4078
4079 if (argv_find(argv, argc, "INTERFACE", &idx_intf))
4080 intf_name = argv[idx_intf]->arg;
4081
b1c3ae8c
CS
4082 if (uj)
4083 json = json_object_new_object();
4084
c9339663 4085 if (vrf_name) {
b1c3ae8c 4086 use_vrf = 1;
c9339663
CS
4087 if (all_vrf) {
4088 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
4089 if (!ospf->oi_running)
4090 continue;
4091
996c9314
LB
4092 ret = show_ip_ospf_interface_traffic_common(
4093 vty, ospf, intf_name, json,
4094 display_once, use_vrf, uj);
c9339663
CS
4095 display_once = 1;
4096 }
b1c3ae8c
CS
4097
4098 if (uj) {
4099 vty_out(vty, "%s\n",
996c9314
LB
4100 json_object_to_json_string_ext(
4101 json, JSON_C_TO_STRING_PRETTY));
b1c3ae8c
CS
4102 json_object_free(json);
4103 }
4104
c9339663
CS
4105 return ret;
4106 }
4107 ospf = ospf_lookup_by_inst_name(inst, vrf_name);
b1c3ae8c
CS
4108 if (ospf == NULL || !ospf->oi_running) {
4109 if (uj)
4110 json_object_free(json);
c9339663 4111 return CMD_SUCCESS;
b1c3ae8c
CS
4112 }
4113
996c9314
LB
4114 ret = show_ip_ospf_interface_traffic_common(
4115 vty, ospf, intf_name, json, display_once, use_vrf, uj);
c9339663
CS
4116 } else {
4117 ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
b1c3ae8c
CS
4118 if (ospf == NULL || !ospf->oi_running) {
4119 if (uj)
4120 json_object_free(json);
c9339663 4121 return CMD_SUCCESS;
b1c3ae8c
CS
4122 }
4123
996c9314
LB
4124 ret = show_ip_ospf_interface_traffic_common(
4125 vty, ospf, intf_name, json, display_once, use_vrf, uj);
b1c3ae8c
CS
4126 }
4127
4128 if (uj) {
996c9314
LB
4129 vty_out(vty, "%s\n", json_object_to_json_string_ext(
4130 json, JSON_C_TO_STRING_PRETTY));
b1c3ae8c 4131 json_object_free(json);
c9339663
CS
4132 }
4133
4134 return ret;
4135}
4136
4137
d62a17ae 4138static void show_ip_ospf_neighbour_header(struct vty *vty)
4139{
4140 vty_out(vty, "\n%-15s %3s %-15s %9s %-15s %-20s %5s %5s %5s\n",
4141 "Neighbor ID", "Pri", "State", "Dead Time", "Address",
4142 "Interface", "RXmtL", "RqstL", "DBsmL");
4143}
4144
4145static void show_ip_ospf_neighbor_sub(struct vty *vty,
4146 struct ospf_interface *oi,
d7c0a89a 4147 json_object *json, uint8_t use_json)
d62a17ae 4148{
4149 struct route_node *rn;
cef262c3 4150 struct ospf_neighbor *nbr, *prev_nbr = NULL;
d62a17ae 4151 char msgbuf[16];
4152 char timebuf[OSPF_TIME_DUMP_SIZE];
cef262c3 4153 json_object *json_neighbor = NULL, *json_neigh_array = NULL;
d62a17ae 4154
4155 for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) {
4156 if ((nbr = rn->info)) {
4157 /* Do not show myself. */
cef262c3
CS
4158 if (nbr == oi->nbr_self)
4159 continue;
4160 /* Down state is not shown. */
4161 if (nbr->state == NSM_Down)
4162 continue;
4163 if (use_json) {
4164 char neigh_str[INET_ADDRSTRLEN];
4165
996c9314
LB
4166 if (prev_nbr
4167 && !IPV4_ADDR_SAME(&prev_nbr->src,
4168 &nbr->src)) {
cef262c3
CS
4169 /* Start new neigh list */
4170 json_neigh_array = NULL;
4171 }
4172
996c9314
LB
4173 if (nbr->state == NSM_Attempt
4174 && nbr->router_id.s_addr == 0)
6021c6c0
CS
4175 strlcpy(neigh_str, "neighbor",
4176 sizeof(neigh_str));
cef262c3 4177 else
6021c6c0 4178 strlcpy(neigh_str,
cef262c3 4179 inet_ntoa(nbr->router_id),
6021c6c0 4180 sizeof(neigh_str));
cef262c3
CS
4181
4182 json_object_object_get_ex(json, neigh_str,
4183 &json_neigh_array);
4184
4185 if (!json_neigh_array) {
996c9314
LB
4186 json_neigh_array =
4187 json_object_new_array();
4188 json_object_object_add(
4189 json, neigh_str,
4190 json_neigh_array);
d62a17ae 4191 }
cef262c3 4192
996c9314 4193 json_neighbor = json_object_new_object();
cef262c3
CS
4194
4195 ospf_nbr_state_message(nbr, msgbuf, 16);
4196
4197 long time_store;
4198
996c9314
LB
4199 time_store =
4200 monotime_until(
cef262c3 4201 &nbr->t_inactivity->u.sands,
996c9314
LB
4202 NULL)
4203 / 1000LL;
cef262c3 4204
996c9314 4205 json_object_int_add(json_neighbor, "priority",
cef262c3
CS
4206 nbr->priority);
4207 json_object_string_add(json_neighbor, "state",
4208 msgbuf);
4209 json_object_int_add(json_neighbor,
4210 "deadTimeMsecs",
4211 time_store);
996c9314 4212 json_object_string_add(json_neighbor, "address",
cef262c3
CS
4213 inet_ntoa(nbr->src));
4214 json_object_string_add(json_neighbor,
4215 "ifaceName",
4216 IF_NAME(oi));
996c9314
LB
4217 json_object_int_add(
4218 json_neighbor, "retransmitCounter",
4219 ospf_ls_retransmit_count(nbr));
cef262c3 4220 json_object_int_add(json_neighbor,
996c9314
LB
4221 "requestCounter",
4222 ospf_ls_request_count(nbr));
cef262c3 4223 json_object_int_add(json_neighbor,
996c9314
LB
4224 "dbSummaryCounter",
4225 ospf_db_summary_count(nbr));
cef262c3
CS
4226
4227 json_object_array_add(json_neigh_array,
4228 json_neighbor);
4229 } else {
4230 ospf_nbr_state_message(nbr, msgbuf, 16);
4231
996c9314
LB
4232 if (nbr->state == NSM_Attempt
4233 && nbr->router_id.s_addr == 0)
4234 vty_out(vty, "%-15s %3d %-15s ", "-",
4235 nbr->priority, msgbuf);
cef262c3 4236 else
996c9314 4237 vty_out(vty, "%-15s %3d %-15s ",
cef262c3 4238 inet_ntoa(nbr->router_id),
996c9314 4239 nbr->priority, msgbuf);
cef262c3
CS
4240
4241 vty_out(vty, "%9s ",
4242 ospf_timer_dump(nbr->t_inactivity,
4243 timebuf,
4244 sizeof(timebuf)));
4245 vty_out(vty, "%-15s ", inet_ntoa(nbr->src));
996c9314 4246 vty_out(vty, "%-20s %5ld %5ld %5d\n",
cef262c3
CS
4247 IF_NAME(oi),
4248 ospf_ls_retransmit_count(nbr),
4249 ospf_ls_request_count(nbr),
4250 ospf_db_summary_count(nbr));
d62a17ae 4251 }
cef262c3 4252 prev_nbr = nbr;
d62a17ae 4253 }
4254 }
4255}
4256
4257static int show_ip_ospf_neighbor_common(struct vty *vty, struct ospf *ospf,
d7c0a89a
QY
4258 json_object *json, uint8_t use_json,
4259 uint8_t use_vrf)
d62a17ae 4260{
4261 struct ospf_interface *oi;
4262 struct listnode *node;
6282e124 4263 json_object *json_vrf = NULL;
2bc7673f 4264 json_object *json_nbr_sub = NULL;
7c8ff89e 4265
b1c3ae8c
CS
4266 if (use_json) {
4267 if (use_vrf)
4268 json_vrf = json_object_new_object();
4269 else
4270 json_vrf = json;
6282e124 4271 json_nbr_sub = json_object_new_object();
b1c3ae8c 4272 }
d62a17ae 4273
4274 if (ospf->instance) {
4275 if (use_json)
4276 json_object_int_add(json, "ospfInstance",
4277 ospf->instance);
4278 else
4279 vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
4280 }
7c8ff89e 4281
b1c3ae8c
CS
4282 ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf);
4283 if (!use_json)
4284 show_ip_ospf_neighbour_header(vty);
87bd50e8 4285
2bc7673f
CS
4286 for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) {
4287 if (ospf_interface_neighbor_count(oi) == 0)
4288 continue;
2bc7673f
CS
4289 show_ip_ospf_neighbor_sub(vty, oi, json_nbr_sub, use_json);
4290 }
718e3744 4291
d62a17ae 4292 if (use_json) {
996c9314 4293 json_object_object_add(json_vrf, "neighbors", json_nbr_sub);
b1c3ae8c
CS
4294 if (use_vrf) {
4295 if (ospf->vrf_id == VRF_DEFAULT)
4296 json_object_object_add(json, "default",
4297 json_vrf);
4298 else
4299 json_object_object_add(json, ospf->name,
4300 json_vrf);
4301 }
d62a17ae 4302 } else
4303 vty_out(vty, "\n");
7c8ff89e 4304
d62a17ae 4305 return CMD_SUCCESS;
718e3744 4306}
4307
7c8ff89e
DS
4308DEFUN (show_ip_ospf_neighbor,
4309 show_ip_ospf_neighbor_cmd,
b5a8894d 4310 "show ip ospf [vrf <NAME|all>] neighbor [json]",
718e3744 4311 SHOW_STR
4312 IP_STR
4313 "OSPF information\n"
b5a8894d
CS
4314 VRF_CMD_HELP_STR
4315 "All VRFs\n"
91756b38 4316 "Neighbor list\n"
9973d184 4317 JSON_STR)
718e3744 4318{
d62a17ae 4319 struct ospf *ospf;
d7c0a89a 4320 uint8_t uj = use_json(argc, argv);
b5a8894d
CS
4321 struct listnode *node = NULL;
4322 char *vrf_name = NULL;
4323 bool all_vrf = FALSE;
4324 int ret = CMD_SUCCESS;
4325 int inst = 0;
4326 int idx_vrf = 0;
d7c0a89a 4327 uint8_t use_vrf = 0;
b1c3ae8c 4328 json_object *json = NULL;
718e3744 4329
43b8d1d8 4330 OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
7c8ff89e 4331
b1c3ae8c
CS
4332 if (uj)
4333 json = json_object_new_object();
b5a8894d
CS
4334
4335 /* vrf input is provided could be all or specific vrf*/
4336 if (vrf_name) {
b1c3ae8c 4337 use_vrf = 1;
b5a8894d
CS
4338 if (all_vrf) {
4339 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
4340 if (!ospf->oi_running)
4341 continue;
996c9314
LB
4342 ret = show_ip_ospf_neighbor_common(
4343 vty, ospf, json, uj, use_vrf);
b1c3ae8c
CS
4344 }
4345
4346 if (uj) {
4347 vty_out(vty, "%s\n",
996c9314
LB
4348 json_object_to_json_string_ext(
4349 json, JSON_C_TO_STRING_PRETTY));
b1c3ae8c 4350 json_object_free(json);
b5a8894d 4351 }
b1c3ae8c 4352
b5a8894d
CS
4353 return ret;
4354 }
b1c3ae8c 4355
b5a8894d 4356 ospf = ospf_lookup_by_inst_name(inst, vrf_name);
b1c3ae8c
CS
4357 if (ospf == NULL || !ospf->oi_running) {
4358 if (uj)
4359 json_object_free(json);
b5a8894d 4360 return CMD_SUCCESS;
b1c3ae8c 4361 }
b5a8894d
CS
4362 } else {
4363 /* Display default ospf (instance 0) info */
4364 ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
b1c3ae8c
CS
4365 if (ospf == NULL || !ospf->oi_running) {
4366 if (uj)
4367 json_object_free(json);
b5a8894d 4368 return CMD_SUCCESS;
b1c3ae8c 4369 }
b5a8894d
CS
4370 }
4371
b1c3ae8c
CS
4372 if (ospf) {
4373 ret = show_ip_ospf_neighbor_common(vty, ospf, json, uj,
4374 use_vrf);
4375
4376 if (uj) {
4377 vty_out(vty, "%s\n",
996c9314
LB
4378 json_object_to_json_string_ext(
4379 json, JSON_C_TO_STRING_PRETTY));
b1c3ae8c
CS
4380 }
4381 }
4382
4383 if (uj)
4384 json_object_free(json);
b5a8894d
CS
4385
4386 return ret;
7c8ff89e
DS
4387}
4388
4389
4390DEFUN (show_ip_ospf_instance_neighbor,
4391 show_ip_ospf_instance_neighbor_cmd,
6147e2c6 4392 "show ip ospf (1-65535) neighbor [json]",
7c8ff89e
DS
4393 SHOW_STR
4394 IP_STR
4395 "OSPF information\n"
4396 "Instance ID\n"
91756b38 4397 "Neighbor list\n"
9973d184 4398 JSON_STR)
7c8ff89e 4399{
d62a17ae 4400 int idx_number = 3;
4401 struct ospf *ospf;
d7c0a89a
QY
4402 unsigned short instance = 0;
4403 uint8_t uj = use_json(argc, argv);
b1c3ae8c
CS
4404 json_object *json = NULL;
4405 int ret = CMD_SUCCESS;
7c8ff89e 4406
d62a17ae 4407 instance = strtoul(argv[idx_number]->arg, NULL, 10);
ac28e4ec
CS
4408 ospf = ospf_lookup_instance(instance);
4409 if (ospf == NULL)
4410 return CMD_NOT_MY_INSTANCE;
4411
4412 if (!ospf->oi_running)
d62a17ae 4413 return CMD_SUCCESS;
7c8ff89e 4414
b1c3ae8c
CS
4415 if (uj)
4416 json = json_object_new_object();
b5a8894d 4417
b1c3ae8c
CS
4418 ret = show_ip_ospf_neighbor_common(vty, ospf, json, uj, 0);
4419
4420 if (uj) {
996c9314
LB
4421 vty_out(vty, "%s\n", json_object_to_json_string_ext(
4422 json, JSON_C_TO_STRING_PRETTY));
b1c3ae8c
CS
4423 json_object_free(json);
4424 }
4425
4426 return ret;
7c8ff89e
DS
4427}
4428
d62a17ae 4429static int show_ip_ospf_neighbor_all_common(struct vty *vty, struct ospf *ospf,
d7c0a89a
QY
4430 json_object *json, uint8_t use_json,
4431 uint8_t use_vrf)
d62a17ae 4432{
4433 struct listnode *node;
4434 struct ospf_interface *oi;
b1c3ae8c 4435 json_object *json_vrf = NULL;
d62a17ae 4436 json_object *json_neighbor_sub = NULL;
7c8ff89e 4437
d62a17ae 4438 if (use_json) {
b1c3ae8c
CS
4439 if (use_vrf)
4440 json_vrf = json_object_new_object();
4441 else
4442 json_vrf = json;
d62a17ae 4443 json_neighbor_sub = json_object_new_object();
b5a8894d 4444 }
d62a17ae 4445
b1c3ae8c
CS
4446 ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf);
4447 if (!use_json)
4448 show_ip_ospf_neighbour_header(vty);
4449
d62a17ae 4450 if (ospf->instance) {
4451 if (use_json)
b1c3ae8c 4452 json_object_int_add(json_vrf, "ospfInstance",
d62a17ae 4453 ospf->instance);
4454 else
4455 vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
4456 }
4457
4458 for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) {
4459 struct listnode *nbr_node;
4460 struct ospf_nbr_nbma *nbr_nbma;
4461
b1c3ae8c 4462 show_ip_ospf_neighbor_sub(vty, oi, json_vrf, use_json);
d62a17ae 4463
4464 /* print Down neighbor status */
4465 for (ALL_LIST_ELEMENTS_RO(oi->nbr_nbma, nbr_node, nbr_nbma)) {
4466 if (nbr_nbma->nbr == NULL
4467 || nbr_nbma->nbr->state == NSM_Down) {
4468 if (use_json) {
4469 json_object_int_add(json_neighbor_sub,
4470 "nbrNbmaPriority",
4471 nbr_nbma->priority);
4472 json_object_boolean_true_add(
4473 json_neighbor_sub,
4474 "nbrNbmaDown");
4475 json_object_string_add(
4476 json_neighbor_sub,
4477 "nbrNbmaIfaceName",
4478 IF_NAME(oi));
4479 json_object_int_add(
4480 json_neighbor_sub,
4481 "nbrNbmaRetransmitCounter", 0);
4482 json_object_int_add(
4483 json_neighbor_sub,
4484 "nbrNbmaRequestCounter", 0);
4485 json_object_int_add(
4486 json_neighbor_sub,
4487 "nbrNbmaDbSummaryCounter", 0);
4488 json_object_object_add(
b1c3ae8c
CS
4489 json_vrf,
4490 inet_ntoa(nbr_nbma->addr),
d62a17ae 4491 json_neighbor_sub);
4492 } else {
4493 vty_out(vty, "%-15s %3d %-15s %9s ",
4494 "-", nbr_nbma->priority, "Down",
4495 "-");
4496 vty_out(vty,
4497 "%-15s %-20s %5d %5d %5d\n",
4498 inet_ntoa(nbr_nbma->addr),
4499 IF_NAME(oi), 0, 0, 0);
4500 }
4501 }
4502 }
4503 }
4504
4505 if (use_json) {
b1c3ae8c
CS
4506 if (use_vrf) {
4507 if (ospf->vrf_id == VRF_DEFAULT)
4508 json_object_object_add(json, "default",
4509 json_vrf);
4510 else
4511 json_object_object_add(json, ospf->name,
4512 json_vrf);
4513 }
d62a17ae 4514 } else
4515 vty_out(vty, "\n");
4516
4517 return CMD_SUCCESS;
718e3744 4518}
4519
7c8ff89e
DS
4520DEFUN (show_ip_ospf_neighbor_all,
4521 show_ip_ospf_neighbor_all_cmd,
b5a8894d 4522 "show ip ospf [vrf <NAME|all>] neighbor all [json]",
718e3744 4523 SHOW_STR
4524 IP_STR
4525 "OSPF information\n"
b5a8894d
CS
4526 VRF_CMD_HELP_STR
4527 "All VRFs\n"
718e3744 4528 "Neighbor list\n"
91756b38 4529 "include down status neighbor\n"
9973d184 4530 JSON_STR)
7c8ff89e 4531{
d62a17ae 4532 struct ospf *ospf;
d7c0a89a 4533 uint8_t uj = use_json(argc, argv);
b5a8894d
CS
4534 struct listnode *node = NULL;
4535 char *vrf_name = NULL;
4536 bool all_vrf = FALSE;
4537 int ret = CMD_SUCCESS;
4538 int inst = 0;
4539 int idx_vrf = 0;
d7c0a89a 4540 uint8_t use_vrf = 0;
b1c3ae8c 4541 json_object *json = NULL;
7c8ff89e 4542
43b8d1d8 4543 OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
7c8ff89e 4544
b1c3ae8c
CS
4545 if (uj)
4546 json = json_object_new_object();
b5a8894d
CS
4547
4548 /* vrf input is provided could be all or specific vrf*/
4549 if (vrf_name) {
b1c3ae8c 4550 use_vrf = 1;
b5a8894d
CS
4551 if (all_vrf) {
4552 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
4553 if (!ospf->oi_running)
4554 continue;
996c9314
LB
4555 ret = show_ip_ospf_neighbor_all_common(
4556 vty, ospf, json, uj, use_vrf);
b1c3ae8c
CS
4557 }
4558
4559 if (uj) {
4560 vty_out(vty, "%s\n",
996c9314
LB
4561 json_object_to_json_string_ext(
4562 json, JSON_C_TO_STRING_PRETTY));
b1c3ae8c 4563 json_object_free(json);
b5a8894d 4564 }
b1c3ae8c 4565
b5a8894d
CS
4566 return ret;
4567 }
b1c3ae8c 4568
b5a8894d 4569 ospf = ospf_lookup_by_inst_name(inst, vrf_name);
b1c3ae8c
CS
4570 if (ospf == NULL || !ospf->oi_running) {
4571 if (uj)
4572 json_object_free(json);
b5a8894d 4573 return CMD_SUCCESS;
b1c3ae8c 4574 }
b5a8894d
CS
4575 } else {
4576 /* Display default ospf (instance 0) info */
4577 ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
b1c3ae8c
CS
4578 if (ospf == NULL || !ospf->oi_running) {
4579 if (uj)
4580 json_object_free(json);
b5a8894d 4581 return CMD_SUCCESS;
b1c3ae8c 4582 }
b5a8894d
CS
4583 }
4584
b1c3ae8c
CS
4585 if (ospf) {
4586 ret = show_ip_ospf_neighbor_all_common(vty, ospf, json, uj,
4587 use_vrf);
4588 if (uj) {
4589 vty_out(vty, "%s\n",
996c9314
LB
4590 json_object_to_json_string_ext(
4591 json, JSON_C_TO_STRING_PRETTY));
b1c3ae8c
CS
4592 }
4593 }
4594
4595 if (uj)
4596 json_object_free(json);
b5a8894d
CS
4597
4598 return ret;
7c8ff89e
DS
4599}
4600
4601DEFUN (show_ip_ospf_instance_neighbor_all,
4602 show_ip_ospf_instance_neighbor_all_cmd,
6147e2c6 4603 "show ip ospf (1-65535) neighbor all [json]",
7c8ff89e
DS
4604 SHOW_STR
4605 IP_STR
4606 "OSPF information\n"
4607 "Instance ID\n"
4608 "Neighbor list\n"
91756b38 4609 "include down status neighbor\n"
9973d184 4610 JSON_STR)
718e3744 4611{
d62a17ae 4612 int idx_number = 3;
4613 struct ospf *ospf;
d7c0a89a
QY
4614 unsigned short instance = 0;
4615 uint8_t uj = use_json(argc, argv);
b1c3ae8c
CS
4616 json_object *json = NULL;
4617 int ret = CMD_SUCCESS;
7c8ff89e 4618
d62a17ae 4619 instance = strtoul(argv[idx_number]->arg, NULL, 10);
ac28e4ec
CS
4620 ospf = ospf_lookup_instance(instance);
4621 if (ospf == NULL)
4622 return CMD_NOT_MY_INSTANCE;
4623
4624 if (!ospf->oi_running)
d62a17ae 4625 return CMD_SUCCESS;
b1c3ae8c
CS
4626 if (uj)
4627 json = json_object_new_object();
4628
4629 ret = show_ip_ospf_neighbor_all_common(vty, ospf, json, uj, 0);
4630
4631 if (uj) {
4632 vty_out(vty, "%s\n", json_object_to_json_string_ext(
4633 json, JSON_C_TO_STRING_PRETTY));
4634 json_object_free(json);
4635 }
7c8ff89e 4636
b1c3ae8c 4637 return ret;
7c8ff89e
DS
4638}
4639
d62a17ae 4640static int show_ip_ospf_neighbor_int_common(struct vty *vty, struct ospf *ospf,
4641 int arg_base,
4642 struct cmd_token **argv,
d7c0a89a 4643 uint8_t use_json, uint8_t use_vrf)
d62a17ae 4644{
4645 struct interface *ifp;
4646 struct route_node *rn;
4647 json_object *json = NULL;
91756b38 4648
d62a17ae 4649 if (use_json)
4650 json = json_object_new_object();
d62a17ae 4651
4652 if (ospf->instance) {
4653 if (use_json)
4654 json_object_int_add(json, "ospfInstance",
4655 ospf->instance);
4656 else
4657 vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
4658 }
4659
b1c3ae8c 4660 ospf_show_vrf_name(ospf, vty, json, use_vrf);
87bd50e8 4661
b5a8894d 4662 ifp = if_lookup_by_name_all_vrf(argv[arg_base]->arg);
d62a17ae 4663 if (!ifp) {
4664 if (use_json)
4665 json_object_boolean_true_add(json, "noSuchIface");
4666 else
4667 vty_out(vty, "No such interface.\n");
4668 return CMD_WARNING;
4669 }
4670
4671 for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) {
4672 struct ospf_interface *oi = rn->info;
4673
4674 if (oi == NULL)
4675 continue;
4676
4677 show_ip_ospf_neighbor_sub(vty, oi, json, use_json);
4678 }
4679
4680 if (use_json) {
9d303b37
DL
4681 vty_out(vty, "%s\n", json_object_to_json_string_ext(
4682 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 4683 json_object_free(json);
4684 } else
4685 vty_out(vty, "\n");
4686
4687 return CMD_SUCCESS;
718e3744 4688}
4689
7c8ff89e
DS
4690DEFUN (show_ip_ospf_neighbor_int,
4691 show_ip_ospf_neighbor_int_cmd,
b162fa78 4692 "show ip ospf neighbor IFNAME [json]",
7c8ff89e
DS
4693 SHOW_STR
4694 IP_STR
4695 "OSPF information\n"
4696 "Neighbor list\n"
91756b38 4697 "Interface name\n"
9973d184 4698 JSON_STR)
7c8ff89e 4699{
d62a17ae 4700 struct ospf *ospf;
b4e84315 4701 int idx_ifname = 4;
d7c0a89a 4702 uint8_t uj = use_json(argc, argv);
b5a8894d
CS
4703 struct listnode *node = NULL;
4704 int ret = CMD_SUCCESS;
4705 struct interface *ifp = NULL;
7c8ff89e 4706
b5a8894d
CS
4707 if (!uj)
4708 show_ip_ospf_neighbour_header(vty);
7c8ff89e 4709
b5a8894d
CS
4710 ifp = if_lookup_by_name_all_vrf(argv[idx_ifname]->arg);
4711 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
4712 if (!ospf->oi_running)
4713 continue;
4714 if (!ifp || ifp->vrf_id != ospf->vrf_id)
4715 continue;
996c9314
LB
4716 ret = show_ip_ospf_neighbor_int_common(vty, ospf, idx_ifname,
4717 argv, uj, 0);
b5a8894d
CS
4718 }
4719
4720 return ret;
7c8ff89e
DS
4721}
4722
4723DEFUN (show_ip_ospf_instance_neighbor_int,
4724 show_ip_ospf_instance_neighbor_int_cmd,
6147e2c6 4725 "show ip ospf (1-65535) neighbor IFNAME [json]",
7c8ff89e
DS
4726 SHOW_STR
4727 IP_STR
4728 "OSPF information\n"
4729 "Instance ID\n"
4730 "Neighbor list\n"
91756b38 4731 "Interface name\n"
9973d184 4732 JSON_STR)
7c8ff89e 4733{
d62a17ae 4734 int idx_number = 3;
b4e84315 4735 int idx_ifname = 5;
d62a17ae 4736 struct ospf *ospf;
d7c0a89a
QY
4737 unsigned short instance = 0;
4738 uint8_t uj = use_json(argc, argv);
7c8ff89e 4739
b5a8894d
CS
4740 if (!uj)
4741 show_ip_ospf_neighbour_header(vty);
4742
d62a17ae 4743 instance = strtoul(argv[idx_number]->arg, NULL, 10);
ac28e4ec
CS
4744 ospf = ospf_lookup_instance(instance);
4745 if (ospf == NULL)
4746 return CMD_NOT_MY_INSTANCE;
4747
4748 if (!ospf->oi_running)
d62a17ae 4749 return CMD_SUCCESS;
7c8ff89e 4750
b5a8894d
CS
4751 if (!uj)
4752 show_ip_ospf_neighbour_header(vty);
4753
996c9314
LB
4754 return show_ip_ospf_neighbor_int_common(vty, ospf, idx_ifname, argv, uj,
4755 0);
718e3744 4756}
4757
d62a17ae 4758static void show_ip_ospf_nbr_nbma_detail_sub(struct vty *vty,
4759 struct ospf_interface *oi,
4760 struct ospf_nbr_nbma *nbr_nbma,
d7c0a89a
QY
4761 uint8_t use_json,
4762 json_object *json)
d62a17ae 4763{
4764 char timebuf[OSPF_TIME_DUMP_SIZE];
4765 json_object *json_sub = NULL;
718e3744 4766
d62a17ae 4767 if (use_json)
4768 json_sub = json_object_new_object();
4769 else /* Show neighbor ID. */
4770 vty_out(vty, " Neighbor %s,", "-");
4771
4772 /* Show interface address. */
4773 if (use_json)
4774 json_object_string_add(json_sub, "ifaceAddress",
4775 inet_ntoa(nbr_nbma->addr));
4776 else
4777 vty_out(vty, " interface address %s\n",
4778 inet_ntoa(nbr_nbma->addr));
4779
4780 /* Show Area ID. */
4781 if (use_json) {
4782 json_object_string_add(json_sub, "areaId",
4783 ospf_area_desc_string(oi->area));
4784 json_object_string_add(json_sub, "iface", IF_NAME(oi));
4785 } else
4786 vty_out(vty, " In the area %s via interface %s\n",
4787 ospf_area_desc_string(oi->area), IF_NAME(oi));
4788
4789 /* Show neighbor priority and state. */
4790 if (use_json) {
4791 json_object_int_add(json_sub, "nbrPriority",
4792 nbr_nbma->priority);
4793 json_object_string_add(json_sub, "nbrState", "down");
4794 } else
4795 vty_out(vty, " Neighbor priority is %d, State is %s,",
4796 nbr_nbma->priority, "Down");
4797
4798 /* Show state changes. */
4799 if (use_json)
4800 json_object_int_add(json_sub, "stateChangeCounter",
4801 nbr_nbma->state_change);
4802 else
4803 vty_out(vty, " %d state changes\n", nbr_nbma->state_change);
4804
4805 /* Show PollInterval */
4806 if (use_json)
4807 json_object_int_add(json_sub, "pollInterval", nbr_nbma->v_poll);
4808 else
4809 vty_out(vty, " Poll interval %d\n", nbr_nbma->v_poll);
4810
4811 /* Show poll-interval timer. */
b575a12c
A
4812 if (nbr_nbma->t_poll) {
4813 if (use_json) {
4814 long time_store;
4815 time_store = monotime_until(&nbr_nbma->t_poll->u.sands,
4816 NULL) / 1000LL;
4817 json_object_int_add(json_sub,
4818 "pollIntervalTimerDueMsec",
4819 time_store);
4820 } else
4821 vty_out(vty, " Poll timer due in %s\n",
4822 ospf_timer_dump(nbr_nbma->t_poll, timebuf,
4823 sizeof(timebuf)));
4824 }
d62a17ae 4825
4826 /* Show poll-interval timer thread. */
4827 if (use_json) {
4828 if (nbr_nbma->t_poll != NULL)
4829 json_object_string_add(json_sub,
4830 "pollIntervalTimerThread", "on");
4831 } else
4832 vty_out(vty, " Thread Poll Timer %s\n",
4833 nbr_nbma->t_poll != NULL ? "on" : "off");
4834
4835 if (use_json)
4836 json_object_object_add(json, "noNbrId", json_sub);
4837}
4838
4839static void show_ip_ospf_neighbor_detail_sub(struct vty *vty,
4840 struct ospf_interface *oi,
4841 struct ospf_neighbor *nbr,
d7c0a89a
QY
4842 json_object *json,
4843 uint8_t use_json)
d62a17ae 4844{
4845 char timebuf[OSPF_TIME_DUMP_SIZE];
4846 json_object *json_sub = NULL;
4847
4848 if (use_json)
4849 json_sub = json_object_new_object();
4850 else {
4851 /* Show neighbor ID. */
4852 if (nbr->state == NSM_Attempt && nbr->router_id.s_addr == 0)
4853 vty_out(vty, " Neighbor %s,", "-");
4854 else
4855 vty_out(vty, " Neighbor %s,",
4856 inet_ntoa(nbr->router_id));
4857 }
4858
4859 /* Show interface address. */
4860 if (use_json)
4861 json_object_string_add(json_sub, "ifaceAddress",
4862 inet_ntoa(nbr->address.u.prefix4));
4863 else
4864 vty_out(vty, " interface address %s\n",
4865 inet_ntoa(nbr->address.u.prefix4));
4866
4867 /* Show Area ID. */
4868 if (use_json) {
4869 json_object_string_add(json_sub, "areaId",
4870 ospf_area_desc_string(oi->area));
4871 json_object_string_add(json_sub, "ifaceName", oi->ifp->name);
4872 } else
4873 vty_out(vty, " In the area %s via interface %s\n",
4874 ospf_area_desc_string(oi->area), oi->ifp->name);
4875
4876 /* Show neighbor priority and state. */
4877 if (use_json) {
4878 json_object_int_add(json_sub, "nbrPriority", nbr->priority);
4879 json_object_string_add(
4880 json_sub, "nbrState",
4881 lookup_msg(ospf_nsm_state_msg, nbr->state, NULL));
4882 } else
4883 vty_out(vty, " Neighbor priority is %d, State is %s,",
4884 nbr->priority,
4885 lookup_msg(ospf_nsm_state_msg, nbr->state, NULL));
4886
4887 /* Show state changes. */
4888 if (use_json)
4889 json_object_int_add(json_sub, "stateChangeCounter",
4890 nbr->state_change);
4891 else
4892 vty_out(vty, " %d state changes\n", nbr->state_change);
4893
4894 if (nbr->ts_last_progress.tv_sec || nbr->ts_last_progress.tv_usec) {
4895 struct timeval res;
4896 long time_store;
4897
4898 time_store =
4899 monotime_since(&nbr->ts_last_progress, &res) / 1000LL;
4900 if (use_json) {
4901 json_object_int_add(json_sub, "lastPrgrsvChangeMsec",
4902 time_store);
4903 } else {
4904 vty_out(vty,
4905 " Most recent state change statistics:\n");
4906 vty_out(vty, " Progressive change %s ago\n",
4907 ospf_timeval_dump(&res, timebuf,
4908 sizeof(timebuf)));
4909 }
4910 }
4911
4912 if (nbr->ts_last_regress.tv_sec || nbr->ts_last_regress.tv_usec) {
4913 struct timeval res;
4914 long time_store;
4915
4916 time_store =
4917 monotime_since(&nbr->ts_last_regress, &res) / 1000LL;
4918 if (use_json) {
4919 json_object_int_add(json_sub,
4920 "lastRegressiveChangeMsec",
4921 time_store);
4922 if (nbr->last_regress_str)
4923 json_object_string_add(
4924 json_sub, "lastRegressiveChangeReason",
4925 nbr->last_regress_str);
4926 } else {
4927 vty_out(vty,
4928 " Regressive change %s ago, due to %s\n",
4929 ospf_timeval_dump(&res, timebuf,
4930 sizeof(timebuf)),
4931 (nbr->last_regress_str ? nbr->last_regress_str
4932 : "??"));
4933 }
4934 }
4935
4936 /* Show Designated Rotuer ID. */
4937 if (use_json)
4938 json_object_string_add(json_sub, "routerDesignatedId",
4939 inet_ntoa(nbr->d_router));
4940 else
4941 vty_out(vty, " DR is %s,", inet_ntoa(nbr->d_router));
4942
4943 /* Show Backup Designated Rotuer ID. */
4944 if (use_json)
4945 json_object_string_add(json_sub, "routerDesignatedBackupId",
4946 inet_ntoa(nbr->bd_router));
4947 else
4948 vty_out(vty, " BDR is %s\n", inet_ntoa(nbr->bd_router));
4949
4950 /* Show options. */
4951 if (use_json) {
4952 json_object_int_add(json_sub, "optionsCounter", nbr->options);
4953 json_object_string_add(json_sub, "optionsList",
4954 ospf_options_dump(nbr->options));
4955 } else
4956 vty_out(vty, " Options %d %s\n", nbr->options,
4957 ospf_options_dump(nbr->options));
4958
4959 /* Show Router Dead interval timer. */
4960 if (use_json) {
4961 if (nbr->t_inactivity) {
4962 long time_store;
4963 time_store = monotime_until(&nbr->t_inactivity->u.sands,
4964 NULL)
4965 / 1000LL;
4966 json_object_int_add(json_sub,
4967 "routerDeadIntervalTimerDueMsec",
4968 time_store);
4969 } else
4970 json_object_int_add(
4971 json_sub, "routerDeadIntervalTimerDueMsec", -1);
4972 } else
4973 vty_out(vty, " Dead timer due in %s\n",
4974 ospf_timer_dump(nbr->t_inactivity, timebuf,
4975 sizeof(timebuf)));
4976
4977 /* Show Database Summary list. */
4978 if (use_json)
4979 json_object_int_add(json_sub, "databaseSummaryListCounter",
4980 ospf_db_summary_count(nbr));
4981 else
4982 vty_out(vty, " Database Summary List %d\n",
4983 ospf_db_summary_count(nbr));
4984
4985 /* Show Link State Request list. */
4986 if (use_json)
4987 json_object_int_add(json_sub, "linkStateRequestListCounter",
4988 ospf_ls_request_count(nbr));
4989 else
4990 vty_out(vty, " Link State Request List %ld\n",
4991 ospf_ls_request_count(nbr));
4992
4993 /* Show Link State Retransmission list. */
4994 if (use_json)
4995 json_object_int_add(json_sub,
4996 "linkStateRetransmissionListCounter",
4997 ospf_ls_retransmit_count(nbr));
4998 else
4999 vty_out(vty, " Link State Retransmission List %ld\n",
5000 ospf_ls_retransmit_count(nbr));
5001
5002 /* Show inactivity timer thread. */
5003 if (use_json) {
5004 if (nbr->t_inactivity != NULL)
5005 json_object_string_add(json_sub,
5006 "threadInactivityTimer", "on");
5007 } else
5008 vty_out(vty, " Thread Inactivity Timer %s\n",
5009 nbr->t_inactivity != NULL ? "on" : "off");
5010
5011 /* Show Database Description retransmission thread. */
5012 if (use_json) {
5013 if (nbr->t_db_desc != NULL)
5014 json_object_string_add(
5015 json_sub,
5016 "threadDatabaseDescriptionRetransmission",
5017 "on");
5018 } else
5019 vty_out(vty,
5020 " Thread Database Description Retransmision %s\n",
5021 nbr->t_db_desc != NULL ? "on" : "off");
5022
5023 /* Show Link State Request Retransmission thread. */
5024 if (use_json) {
5025 if (nbr->t_ls_req != NULL)
5026 json_object_string_add(
5027 json_sub,
5028 "threadLinkStateRequestRetransmission", "on");
5029 } else
5030 vty_out(vty,
5031 " Thread Link State Request Retransmission %s\n",
5032 nbr->t_ls_req != NULL ? "on" : "off");
5033
5034 /* Show Link State Update Retransmission thread. */
5035 if (use_json) {
5036 if (nbr->t_ls_upd != NULL)
5037 json_object_string_add(
5038 json_sub, "threadLinkStateUpdateRetransmission",
5039 "on");
5040 } else
5041 vty_out(vty,
5042 " Thread Link State Update Retransmission %s\n\n",
5043 nbr->t_ls_upd != NULL ? "on" : "off");
5044
5045 if (use_json) {
5046 if (nbr->state == NSM_Attempt && nbr->router_id.s_addr == 0)
5047 json_object_object_add(json, "noNbrId", json_sub);
5048 else
5049 json_object_object_add(json, inet_ntoa(nbr->router_id),
5050 json_sub);
5051 }
5052
5053 ospf_bfd_show_info(vty, nbr->bfd_info, json, use_json, 0);
5054}
5055
5056static int show_ip_ospf_neighbor_id_common(struct vty *vty, struct ospf *ospf,
5057 int arg_base,
5058 struct cmd_token **argv,
d7c0a89a 5059 uint8_t use_json, uint8_t use_vrf)
d62a17ae 5060{
5061 struct listnode *node;
5062 struct ospf_neighbor *nbr;
5063 struct ospf_interface *oi;
5064 struct in_addr router_id;
5065 int ret;
5066 json_object *json = NULL;
5067
5068 if (use_json)
5069 json = json_object_new_object();
5070
5071 if (ospf->instance) {
5072 if (use_json)
5073 json_object_int_add(json, "ospfInstance",
5074 ospf->instance);
5075 else
5076 vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
5077 }
5078
b1c3ae8c 5079 ospf_show_vrf_name(ospf, vty, json, use_vrf);
87bd50e8 5080
d62a17ae 5081 ret = inet_aton(argv[arg_base]->arg, &router_id);
5082 if (!ret) {
5083 if (!use_json)
5084 vty_out(vty, "Please specify Neighbor ID by A.B.C.D\n");
16307668
RW
5085 else {
5086 vty_out(vty, "{}\n");
5087 json_object_free(json);
5088 }
d62a17ae 5089 return CMD_WARNING;
5090 }
5091
5092 for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) {
5093 if ((nbr = ospf_nbr_lookup_by_routerid(oi->nbrs, &router_id))) {
b1c3ae8c
CS
5094 show_ip_ospf_neighbor_detail_sub(vty, oi, nbr, json,
5095 use_json);
d62a17ae 5096 }
5097 }
5098
5099 if (use_json) {
9d303b37
DL
5100 vty_out(vty, "%s\n", json_object_to_json_string_ext(
5101 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 5102 json_object_free(json);
5103 } else
5104 vty_out(vty, "\n");
5105
5106 return CMD_SUCCESS;
718e3744 5107}
5108
7c8ff89e
DS
5109DEFUN (show_ip_ospf_neighbor_id,
5110 show_ip_ospf_neighbor_id_cmd,
b162fa78 5111 "show ip ospf neighbor A.B.C.D [json]",
718e3744 5112 SHOW_STR
5113 IP_STR
5114 "OSPF information\n"
5115 "Neighbor list\n"
3ac237f8 5116 "Neighbor ID\n"
9973d184 5117 JSON_STR)
718e3744 5118{
d62a17ae 5119 struct ospf *ospf;
d7c0a89a 5120 uint8_t uj = use_json(argc, argv);
b5a8894d
CS
5121 struct listnode *node = NULL;
5122 int ret = CMD_SUCCESS;
7c8ff89e 5123
b5a8894d
CS
5124 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
5125 if (!ospf->oi_running)
5126 continue;
996c9314
LB
5127 ret = show_ip_ospf_neighbor_id_common(vty, ospf, 0, argv, uj,
5128 0);
b5a8894d 5129 }
7c8ff89e 5130
b5a8894d 5131 return ret;
7c8ff89e
DS
5132}
5133
5134DEFUN (show_ip_ospf_instance_neighbor_id,
5135 show_ip_ospf_instance_neighbor_id_cmd,
6147e2c6 5136 "show ip ospf (1-65535) neighbor A.B.C.D [json]",
7c8ff89e
DS
5137 SHOW_STR
5138 IP_STR
5139 "OSPF information\n"
5140 "Instance ID\n"
5141 "Neighbor list\n"
3ac237f8 5142 "Neighbor ID\n"
9973d184 5143 JSON_STR)
7c8ff89e 5144{
d62a17ae 5145 int idx_number = 3;
b4e84315 5146 int idx_router_id = 5;
d62a17ae 5147 struct ospf *ospf;
d7c0a89a
QY
5148 unsigned short instance = 0;
5149 uint8_t uj = use_json(argc, argv);
7c8ff89e 5150
d62a17ae 5151 instance = strtoul(argv[idx_number]->arg, NULL, 10);
ac28e4ec
CS
5152 ospf = ospf_lookup_instance(instance);
5153 if (ospf == NULL)
5154 return CMD_NOT_MY_INSTANCE;
5155
5156 if (!ospf->oi_running)
d62a17ae 5157 return CMD_SUCCESS;
7c8ff89e 5158
b1c3ae8c
CS
5159 return show_ip_ospf_neighbor_id_common(vty, ospf, idx_router_id, argv,
5160 uj, 0);
7c8ff89e
DS
5161}
5162
d62a17ae 5163static int show_ip_ospf_neighbor_detail_common(struct vty *vty,
5164 struct ospf *ospf,
b1c3ae8c 5165 json_object *json,
d7c0a89a
QY
5166 uint8_t use_json,
5167 uint8_t use_vrf)
d62a17ae 5168{
5169 struct ospf_interface *oi;
5170 struct listnode *node;
b1c3ae8c 5171 json_object *json_vrf = NULL;
d62a17ae 5172
b1c3ae8c
CS
5173 if (use_json) {
5174 if (use_vrf)
5175 json_vrf = json_object_new_object();
5176 else
5177 json_vrf = json;
5178 }
d62a17ae 5179 if (ospf->instance) {
5180 if (use_json)
b1c3ae8c 5181 json_object_int_add(json_vrf, "ospfInstance",
d62a17ae 5182 ospf->instance);
5183 else
5184 vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
5185 }
5186
b1c3ae8c 5187 ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf);
87bd50e8 5188
d62a17ae 5189 for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) {
5190 struct route_node *rn;
5191 struct ospf_neighbor *nbr;
5192
5193 for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) {
5194 if ((nbr = rn->info)) {
5195 if (nbr != oi->nbr_self) {
5196 if (nbr->state != NSM_Down) {
5197 show_ip_ospf_neighbor_detail_sub(
b1c3ae8c
CS
5198 vty, oi, nbr, json_vrf,
5199 use_json);
d62a17ae 5200 }
5201 }
5202 }
5203 }
5204 }
5205
5206 if (use_json) {
b1c3ae8c
CS
5207 if (use_vrf) {
5208 if (ospf->vrf_id == VRF_DEFAULT)
5209 json_object_object_add(json, "default",
5210 json_vrf);
5211 else
5212 json_object_object_add(json, ospf->name,
5213 json_vrf);
5214 }
d62a17ae 5215 } else
5216 vty_out(vty, "\n");
5217
5218 return CMD_SUCCESS;
718e3744 5219}
5220
7c8ff89e
DS
5221DEFUN (show_ip_ospf_neighbor_detail,
5222 show_ip_ospf_neighbor_detail_cmd,
b5a8894d 5223 "show ip ospf [vrf <NAME|all>] neighbor detail [json]",
718e3744 5224 SHOW_STR
5225 IP_STR
5226 "OSPF information\n"
b5a8894d
CS
5227 VRF_CMD_HELP_STR
5228 "All VRFs\n"
718e3744 5229 "Neighbor list\n"
3ac237f8 5230 "detail of all neighbors\n"
9973d184 5231 JSON_STR)
718e3744 5232{
d62a17ae 5233 struct ospf *ospf;
d7c0a89a 5234 uint8_t uj = use_json(argc, argv);
b5a8894d
CS
5235 struct listnode *node = NULL;
5236 char *vrf_name = NULL;
5237 bool all_vrf = FALSE;
5238 int ret = CMD_SUCCESS;
5239 int inst = 0;
5240 int idx_vrf = 0;
d7c0a89a 5241 uint8_t use_vrf = 0;
b1c3ae8c 5242 json_object *json = NULL;
7c8ff89e 5243
43b8d1d8 5244 OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
7c8ff89e 5245
b1c3ae8c
CS
5246 if (uj)
5247 json = json_object_new_object();
5248
b5a8894d
CS
5249 /* vrf input is provided could be all or specific vrf*/
5250 if (vrf_name) {
b1c3ae8c 5251 use_vrf = 1;
b5a8894d
CS
5252 if (all_vrf) {
5253 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
5254 if (!ospf->oi_running)
5255 continue;
996c9314
LB
5256 ret = show_ip_ospf_neighbor_detail_common(
5257 vty, ospf, json, uj, use_vrf);
b1c3ae8c
CS
5258 }
5259 if (uj) {
5260 vty_out(vty, "%s\n",
996c9314
LB
5261 json_object_to_json_string_ext(
5262 json, JSON_C_TO_STRING_PRETTY));
b1c3ae8c 5263 json_object_free(json);
b5a8894d 5264 }
b1c3ae8c 5265
b5a8894d
CS
5266 return ret;
5267 }
5268 ospf = ospf_lookup_by_inst_name(inst, vrf_name);
b1c3ae8c
CS
5269 if (ospf == NULL || !ospf->oi_running) {
5270 if (uj)
5271 json_object_free(json);
b5a8894d 5272 return CMD_SUCCESS;
b1c3ae8c 5273 }
b5a8894d
CS
5274 } else {
5275 /* Display default ospf (instance 0) info */
5276 ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
b1c3ae8c
CS
5277 if (ospf == NULL || !ospf->oi_running) {
5278 if (uj)
5279 json_object_free(json);
b5a8894d 5280 return CMD_SUCCESS;
b1c3ae8c 5281 }
b5a8894d
CS
5282 }
5283
b1c3ae8c
CS
5284 if (ospf) {
5285 ret = show_ip_ospf_neighbor_detail_common(vty, ospf, json, uj,
5286 use_vrf);
5287 if (uj) {
5288 vty_out(vty, "%s\n",
996c9314
LB
5289 json_object_to_json_string_ext(
5290 json, JSON_C_TO_STRING_PRETTY));
b1c3ae8c
CS
5291 }
5292 }
5293
5294 if (uj)
5295 json_object_free(json);
b5a8894d
CS
5296
5297 return ret;
7c8ff89e
DS
5298}
5299
5300DEFUN (show_ip_ospf_instance_neighbor_detail,
5301 show_ip_ospf_instance_neighbor_detail_cmd,
6147e2c6 5302 "show ip ospf (1-65535) neighbor detail [json]",
7c8ff89e
DS
5303 SHOW_STR
5304 IP_STR
5305 "OSPF information\n"
5306 "Instance ID\n"
5307 "Neighbor list\n"
3ac237f8 5308 "detail of all neighbors\n"
9973d184 5309 JSON_STR)
7c8ff89e 5310{
d62a17ae 5311 int idx_number = 3;
5312 struct ospf *ospf;
d7c0a89a
QY
5313 unsigned short instance = 0;
5314 uint8_t uj = use_json(argc, argv);
b1c3ae8c
CS
5315 json_object *json = NULL;
5316 int ret = CMD_SUCCESS;
7c8ff89e 5317
d62a17ae 5318 instance = strtoul(argv[idx_number]->arg, NULL, 10);
ac28e4ec
CS
5319 ospf = ospf_lookup_instance(instance);
5320 if (ospf == NULL)
5321 return CMD_NOT_MY_INSTANCE;
5322
5323 if (!ospf->oi_running)
d62a17ae 5324 return CMD_SUCCESS;
7c8ff89e 5325
b1c3ae8c
CS
5326 if (uj)
5327 json = json_object_new_object();
5328
5329 ret = show_ip_ospf_neighbor_detail_common(vty, ospf, json, uj, 0);
5330
5331 if (uj) {
5332 vty_out(vty, "%s\n", json_object_to_json_string_ext(
5333 json, JSON_C_TO_STRING_PRETTY));
5334 json_object_free(json);
5335 }
5336
5337 return ret;
7c8ff89e
DS
5338}
5339
d62a17ae 5340static int show_ip_ospf_neighbor_detail_all_common(struct vty *vty,
5341 struct ospf *ospf,
b1c3ae8c 5342 json_object *json,
d7c0a89a
QY
5343 uint8_t use_json,
5344 uint8_t use_vrf)
d62a17ae 5345{
5346 struct listnode *node;
5347 struct ospf_interface *oi;
b1c3ae8c 5348 json_object *json_vrf = NULL;
718e3744 5349
b1c3ae8c
CS
5350 if (use_json) {
5351 if (use_vrf)
5352 json_vrf = json_object_new_object();
5353 else
5354 json_vrf = json;
5355 }
d62a17ae 5356
5357 if (ospf->instance) {
5358 if (use_json)
5359 json_object_int_add(json, "ospfInstance",
5360 ospf->instance);
5361 else
5362 vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
5363 }
5364
b1c3ae8c 5365 ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf);
87bd50e8 5366
d62a17ae 5367 for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) {
5368 struct route_node *rn;
5369 struct ospf_neighbor *nbr;
5370 struct ospf_nbr_nbma *nbr_nbma;
5371
5372 for (rn = route_top(oi->nbrs); rn; rn = route_next(rn))
5373 if ((nbr = rn->info))
5374 if (nbr != oi->nbr_self)
5375 if (nbr->state != NSM_Down)
5376 show_ip_ospf_neighbor_detail_sub(
5377 vty, oi, rn->info,
b1c3ae8c 5378 json_vrf, use_json);
d62a17ae 5379
5380 if (oi->type == OSPF_IFTYPE_NBMA) {
5381 struct listnode *nd;
5382
5383 for (ALL_LIST_ELEMENTS_RO(oi->nbr_nbma, nd, nbr_nbma)) {
5384 if (nbr_nbma->nbr == NULL
5385 || nbr_nbma->nbr->state == NSM_Down)
5386 show_ip_ospf_nbr_nbma_detail_sub(
5387 vty, oi, nbr_nbma, use_json,
b1c3ae8c 5388 json_vrf);
d62a17ae 5389 }
5390 }
5391 }
5392
5393 if (use_json) {
b1c3ae8c
CS
5394 if (use_vrf) {
5395 if (ospf->vrf_id == VRF_DEFAULT)
5396 json_object_object_add(json, "default",
5397 json_vrf);
5398 else
5399 json_object_object_add(json, ospf->name,
5400 json_vrf);
5401 }
d62a17ae 5402 } else {
5403 vty_out(vty, "\n");
5404 }
5405
5406 return CMD_SUCCESS;
718e3744 5407}
5408
7c8ff89e
DS
5409DEFUN (show_ip_ospf_neighbor_detail_all,
5410 show_ip_ospf_neighbor_detail_all_cmd,
b5a8894d 5411 "show ip ospf [vrf <NAME|all>] neighbor detail all [json]",
718e3744 5412 SHOW_STR
5413 IP_STR
5414 "OSPF information\n"
b5a8894d
CS
5415 VRF_CMD_HELP_STR
5416 "All VRFs\n"
718e3744 5417 "Neighbor list\n"
7c8ff89e 5418 "detail of all neighbors\n"
3ac237f8 5419 "include down status neighbor\n"
9973d184 5420 JSON_STR)
718e3744 5421{
d62a17ae 5422 struct ospf *ospf;
d7c0a89a 5423 uint8_t uj = use_json(argc, argv);
b5a8894d
CS
5424 struct listnode *node = NULL;
5425 char *vrf_name = NULL;
5426 bool all_vrf = FALSE;
5427 int ret = CMD_SUCCESS;
5428 int inst = 0;
5429 int idx_vrf = 0;
d7c0a89a 5430 uint8_t use_vrf = 0;
b1c3ae8c 5431 json_object *json = NULL;
7c8ff89e 5432
43b8d1d8 5433 OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
7c8ff89e 5434
b1c3ae8c
CS
5435 if (uj)
5436 json = json_object_new_object();
5437
b5a8894d
CS
5438 /* vrf input is provided could be all or specific vrf*/
5439 if (vrf_name) {
b1c3ae8c 5440 use_vrf = 1;
b5a8894d
CS
5441 if (all_vrf) {
5442 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
5443 if (!ospf->oi_running)
5444 continue;
996c9314
LB
5445 ret = show_ip_ospf_neighbor_detail_all_common(
5446 vty, ospf, json, uj, use_vrf);
b5a8894d 5447 }
b1c3ae8c
CS
5448
5449 if (uj) {
5450 vty_out(vty, "%s\n",
996c9314
LB
5451 json_object_to_json_string_ext(
5452 json, JSON_C_TO_STRING_PRETTY));
b1c3ae8c
CS
5453 json_object_free(json);
5454 }
5455
b5a8894d
CS
5456 return ret;
5457 }
5458 ospf = ospf_lookup_by_inst_name(inst, vrf_name);
b1c3ae8c
CS
5459 if (ospf == NULL || !ospf->oi_running) {
5460 if (uj)
5461 json_object_free(json);
b5a8894d 5462 return CMD_SUCCESS;
b1c3ae8c 5463 }
b5a8894d
CS
5464 } else {
5465 /* Display default ospf (instance 0) info */
5466 ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
b1c3ae8c
CS
5467 if (ospf == NULL || !ospf->oi_running) {
5468 if (uj)
5469 json_object_free(json);
b5a8894d 5470 return CMD_SUCCESS;
b1c3ae8c 5471 }
b5a8894d
CS
5472 }
5473
b1c3ae8c
CS
5474 if (ospf) {
5475 ret = show_ip_ospf_neighbor_detail_all_common(vty, ospf, json,
5476 uj, use_vrf);
5477 if (uj) {
5478 vty_out(vty, "%s\n",
996c9314
LB
5479 json_object_to_json_string_ext(
5480 json, JSON_C_TO_STRING_PRETTY));
b1c3ae8c
CS
5481 }
5482 }
5483
5484 if (uj)
5485 json_object_free(json);
b5a8894d
CS
5486
5487 return ret;
7c8ff89e
DS
5488}
5489
5490DEFUN (show_ip_ospf_instance_neighbor_detail_all,
5491 show_ip_ospf_instance_neighbor_detail_all_cmd,
6147e2c6 5492 "show ip ospf (1-65535) neighbor detail all [json]",
7c8ff89e
DS
5493 SHOW_STR
5494 IP_STR
5495 "OSPF information\n"
5496 "Instance ID\n"
5497 "Neighbor list\n"
5498 "detail of all neighbors\n"
3ac237f8 5499 "include down status neighbor\n"
9973d184 5500 JSON_STR)
7c8ff89e 5501{
d62a17ae 5502 int idx_number = 3;
5503 struct ospf *ospf;
d7c0a89a
QY
5504 unsigned short instance = 0;
5505 uint8_t uj = use_json(argc, argv);
b1c3ae8c
CS
5506 json_object *json = NULL;
5507 int ret = CMD_SUCCESS;
7c8ff89e 5508
d62a17ae 5509 instance = strtoul(argv[idx_number]->arg, NULL, 10);
ac28e4ec
CS
5510 ospf = ospf_lookup_instance(instance);
5511 if (ospf == NULL)
5512 return CMD_NOT_MY_INSTANCE;
5513
5514 if (!ospf->oi_running)
d62a17ae 5515 return CMD_SUCCESS;
7c8ff89e 5516
b1c3ae8c
CS
5517 if (uj)
5518 json = json_object_new_object();
5519
5520 ret = show_ip_ospf_neighbor_detail_all_common(vty, ospf, json, uj, 0);
5521
5522 if (uj) {
996c9314
LB
5523 vty_out(vty, "%s\n", json_object_to_json_string_ext(
5524 json, JSON_C_TO_STRING_PRETTY));
b1c3ae8c
CS
5525 json_object_free(json);
5526 }
5527
5528 return ret;
7c8ff89e
DS
5529}
5530
d62a17ae 5531static int show_ip_ospf_neighbor_int_detail_common(struct vty *vty,
5532 struct ospf *ospf,
5533 int arg_base,
5534 struct cmd_token **argv,
d7c0a89a 5535 uint8_t use_json)
d62a17ae 5536{
5537 struct ospf_interface *oi;
5538 struct interface *ifp;
5539 struct route_node *rn, *nrn;
5540 struct ospf_neighbor *nbr;
5541 json_object *json = NULL;
718e3744 5542
d62a17ae 5543 if (use_json)
5544 json = json_object_new_object();
5545
5546 if (ospf->instance) {
5547 if (use_json)
5548 json_object_int_add(json, "ospfInstance",
5549 ospf->instance);
5550 else
5551 vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
5552 }
5553
b5a8894d 5554 ifp = if_lookup_by_name_all_vrf(argv[arg_base]->arg);
d62a17ae 5555 if (!ifp) {
5556 if (!use_json)
5557 vty_out(vty, "No such interface.\n");
16307668
RW
5558 else {
5559 vty_out(vty, "{}\n");
5560 json_object_free(json);
5561 }
d62a17ae 5562 return CMD_WARNING;
5563 }
5564
5565 for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) {
5566 if ((oi = rn->info)) {
5567 for (nrn = route_top(oi->nbrs); nrn;
5568 nrn = route_next(nrn)) {
5569 if ((nbr = nrn->info)) {
5570 if (nbr != oi->nbr_self) {
5571 if (nbr->state != NSM_Down)
5572 show_ip_ospf_neighbor_detail_sub(
5573 vty, oi, nbr,
b1c3ae8c 5574 json, use_json);
d62a17ae 5575 }
5576 }
5577 }
5578 }
5579 }
5580
5581 if (use_json) {
9d303b37
DL
5582 vty_out(vty, "%s\n", json_object_to_json_string_ext(
5583 json, JSON_C_TO_STRING_PRETTY));
d62a17ae 5584 json_object_free(json);
5585 } else
5586 vty_out(vty, "\n");
5587
5588 return CMD_SUCCESS;
718e3744 5589}
5590
7c8ff89e
DS
5591DEFUN (show_ip_ospf_neighbor_int_detail,
5592 show_ip_ospf_neighbor_int_detail_cmd,
b162fa78 5593 "show ip ospf neighbor IFNAME detail [json]",
7c8ff89e
DS
5594 SHOW_STR
5595 IP_STR
5596 "OSPF information\n"
5597 "Neighbor list\n"
5598 "Interface name\n"
3ac237f8 5599 "detail of all neighbors\n"
9973d184 5600 JSON_STR)
7c8ff89e 5601{
d62a17ae 5602 struct ospf *ospf;
d7c0a89a 5603 uint8_t uj = use_json(argc, argv);
b5a8894d
CS
5604 struct listnode *node = NULL;
5605 int ret = CMD_SUCCESS;
7c8ff89e 5606
b5a8894d
CS
5607 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
5608 if (!ospf->oi_running)
5609 continue;
5610 ret = show_ip_ospf_neighbor_int_detail_common(vty, ospf, 0,
5611 argv, uj);
5612 }
7c8ff89e 5613
b5a8894d 5614 return ret;
7c8ff89e
DS
5615}
5616
5617DEFUN (show_ip_ospf_instance_neighbor_int_detail,
5618 show_ip_ospf_instance_neighbor_int_detail_cmd,
6147e2c6 5619 "show ip ospf (1-65535) neighbor IFNAME detail [json]",
7c8ff89e
DS
5620 SHOW_STR
5621 IP_STR
5622 "OSPF information\n"
5623 "Instance ID\n"
5624 "Neighbor list\n"
5625 "Interface name\n"
3ac237f8 5626 "detail of all neighbors\n"
9973d184 5627 JSON_STR)
7c8ff89e 5628{
d62a17ae 5629 int idx_number = 3;
b4e84315 5630 int idx_ifname = 5;
d62a17ae 5631 struct ospf *ospf;
d7c0a89a
QY
5632 unsigned short instance = 0;
5633 uint8_t uj = use_json(argc, argv);
7c8ff89e 5634
d62a17ae 5635 instance = strtoul(argv[idx_number]->arg, NULL, 10);
ac28e4ec
CS
5636 ospf = ospf_lookup_instance(instance);
5637 if (ospf == NULL)
5638 return CMD_NOT_MY_INSTANCE;
5639
5640 if (!ospf->oi_running)
d62a17ae 5641 return CMD_SUCCESS;
7c8ff89e 5642
996c9314
LB
5643 return show_ip_ospf_neighbor_int_detail_common(vty, ospf, idx_ifname,
5644 argv, uj);
7c8ff89e 5645}
6b0655a2 5646
718e3744 5647/* Show functions */
d62a17ae 5648static int show_lsa_summary(struct vty *vty, struct ospf_lsa *lsa, int self)
5649{
5650 struct router_lsa *rl;
5651 struct summary_lsa *sl;
5652 struct as_external_lsa *asel;
5653 struct prefix_ipv4 p;
5654
5655 if (lsa != NULL)
5656 /* If self option is set, check LSA self flag. */
5657 if (self == 0 || IS_LSA_SELF(lsa)) {
5658 /* LSA common part show. */
5659 vty_out(vty, "%-15s ", inet_ntoa(lsa->data->id));
5660 vty_out(vty, "%-15s %4d 0x%08lx 0x%04x",
5661 inet_ntoa(lsa->data->adv_router), LS_AGE(lsa),
d7c0a89a 5662 (unsigned long)ntohl(lsa->data->ls_seqnum),
d62a17ae 5663 ntohs(lsa->data->checksum));
5664 /* LSA specific part show. */
5665 switch (lsa->data->type) {
5666 case OSPF_ROUTER_LSA:
5667 rl = (struct router_lsa *)lsa->data;
5668 vty_out(vty, " %-d", ntohs(rl->links));
5669 break;
5670 case OSPF_SUMMARY_LSA:
5671 sl = (struct summary_lsa *)lsa->data;
5672
5673 p.family = AF_INET;
5674 p.prefix = sl->header.id;
5675 p.prefixlen = ip_masklen(sl->mask);
5676 apply_mask_ipv4(&p);
5677
5678 vty_out(vty, " %s/%d", inet_ntoa(p.prefix),
5679 p.prefixlen);
5680 break;
5681 case OSPF_AS_EXTERNAL_LSA:
5682 case OSPF_AS_NSSA_LSA:
5683 asel = (struct as_external_lsa *)lsa->data;
5684
5685 p.family = AF_INET;
5686 p.prefix = asel->header.id;
5687 p.prefixlen = ip_masklen(asel->mask);
5688 apply_mask_ipv4(&p);
5689
5690 vty_out(vty, " %s %s/%d [0x%lx]",
5691 IS_EXTERNAL_METRIC(asel->e[0].tos)
5692 ? "E2"
5693 : "E1",
5694 inet_ntoa(p.prefix), p.prefixlen,
d7c0a89a
QY
5695 (unsigned long)ntohl(
5696 asel->e[0].route_tag));
d62a17ae 5697 break;
5698 case OSPF_NETWORK_LSA:
5699 case OSPF_ASBR_SUMMARY_LSA:
5700 case OSPF_OPAQUE_LINK_LSA:
5701 case OSPF_OPAQUE_AREA_LSA:
5702 case OSPF_OPAQUE_AS_LSA:
5703 default:
5704 break;
5705 }
5706 vty_out(vty, "\n");
5707 }
718e3744 5708
d62a17ae 5709 return 0;
5710}
5711
5712static const char *show_database_desc[] = {
5713 "unknown",
5714 "Router Link States",
5715 "Net Link States",
5716 "Summary Link States",
5717 "ASBR-Summary Link States",
5718 "AS External Link States",
5719 "Group Membership LSA",
5720 "NSSA-external Link States",
5721 "Type-8 LSA",
5722 "Link-Local Opaque-LSA",
5723 "Area-Local Opaque-LSA",
5724 "AS-external Opaque-LSA",
718e3744 5725};
5726
d62a17ae 5727static const char *show_database_header[] = {
5728 "",
5729 "Link ID ADV Router Age Seq# CkSum Link count",
5730 "Link ID ADV Router Age Seq# CkSum",
5731 "Link ID ADV Router Age Seq# CkSum Route",
5732 "Link ID ADV Router Age Seq# CkSum",
5733 "Link ID ADV Router Age Seq# CkSum Route",
5734 " --- header for Group Member ----",
5735 "Link ID ADV Router Age Seq# CkSum Route",
5736 " --- type-8 ---",
5737 "Opaque-Type/Id ADV Router Age Seq# CkSum",
5738 "Opaque-Type/Id ADV Router Age Seq# CkSum",
5739 "Opaque-Type/Id ADV Router Age Seq# CkSum",
718e3744 5740};
5741
d62a17ae 5742static void show_ip_ospf_database_header(struct vty *vty, struct ospf_lsa *lsa)
5743{
5744 struct router_lsa *rlsa = (struct router_lsa *)lsa->data;
5745
5746 vty_out(vty, " LS age: %d\n", LS_AGE(lsa));
5747 vty_out(vty, " Options: 0x%-2x : %s\n", lsa->data->options,
5748 ospf_options_dump(lsa->data->options));
5749 vty_out(vty, " LS Flags: 0x%-2x %s\n", lsa->flags,
5750 ((lsa->flags & OSPF_LSA_LOCAL_XLT) ? "(Translated from Type-7)"
5751 : ""));
5752
5753 if (lsa->data->type == OSPF_ROUTER_LSA) {
5754 vty_out(vty, " Flags: 0x%x", rlsa->flags);
5755
5756 if (rlsa->flags)
5757 vty_out(vty, " :%s%s%s%s",
5758 IS_ROUTER_LSA_BORDER(rlsa) ? " ABR" : "",
5759 IS_ROUTER_LSA_EXTERNAL(rlsa) ? " ASBR" : "",
5760 IS_ROUTER_LSA_VIRTUAL(rlsa) ? " VL-endpoint"
5761 : "",
5762 IS_ROUTER_LSA_SHORTCUT(rlsa) ? " Shortcut"
5763 : "");
5764
5765 vty_out(vty, "\n");
5766 }
5767 vty_out(vty, " LS Type: %s\n",
5768 lookup_msg(ospf_lsa_type_msg, lsa->data->type, NULL));
5769 vty_out(vty, " Link State ID: %s %s\n", inet_ntoa(lsa->data->id),
5770 lookup_msg(ospf_link_state_id_type_msg, lsa->data->type, NULL));
5771 vty_out(vty, " Advertising Router: %s\n",
5772 inet_ntoa(lsa->data->adv_router));
5773 vty_out(vty, " LS Seq Number: %08lx\n",
d7c0a89a 5774 (unsigned long)ntohl(lsa->data->ls_seqnum));
d62a17ae 5775 vty_out(vty, " Checksum: 0x%04x\n", ntohs(lsa->data->checksum));
5776 vty_out(vty, " Length: %d\n\n", ntohs(lsa->data->length));
5777}
5778
5779const char *link_type_desc[] = {
5780 "(null)",
5781 "another Router (point-to-point)",
5782 "a Transit Network",
5783 "Stub Network",
5784 "a Virtual Link",
718e3744 5785};
5786
d62a17ae 5787const char *link_id_desc[] = {
5788 "(null)", "Neighboring Router ID", "Designated Router address",
5789 "Net", "Neighboring Router ID",
718e3744 5790};
5791
d62a17ae 5792const char *link_data_desc[] = {
5793 "(null)", "Router Interface address", "Router Interface address",
5794 "Network Mask", "Router Interface address",
718e3744 5795};
5796
5797/* Show router-LSA each Link information. */
d62a17ae 5798static void show_ip_ospf_database_router_links(struct vty *vty,
5799 struct router_lsa *rl)
5800{
5801 int len, type;
5802 unsigned int i;
5803
5804 len = ntohs(rl->header.length) - 4;
5805 for (i = 0; i < ntohs(rl->links) && len > 0; len -= 12, i++) {
5806 type = rl->link[i].type;
5807
5808 vty_out(vty, " Link connected to: %s\n",
5809 link_type_desc[type]);
5810 vty_out(vty, " (Link ID) %s: %s\n", link_id_desc[type],
5811 inet_ntoa(rl->link[i].link_id));
5812 vty_out(vty, " (Link Data) %s: %s\n", link_data_desc[type],
5813 inet_ntoa(rl->link[i].link_data));
5814 vty_out(vty, " Number of TOS metrics: 0\n");
5815 vty_out(vty, " TOS 0 Metric: %d\n",
5816 ntohs(rl->link[i].metric));
5817 vty_out(vty, "\n");
5818 }
718e3744 5819}
5820
5821/* Show router-LSA detail information. */
d62a17ae 5822static int show_router_lsa_detail(struct vty *vty, struct ospf_lsa *lsa)
718e3744 5823{
d62a17ae 5824 if (lsa != NULL) {
5825 struct router_lsa *rl = (struct router_lsa *)lsa->data;
718e3744 5826
d62a17ae 5827 show_ip_ospf_database_header(vty, lsa);
718e3744 5828
d62a17ae 5829 vty_out(vty, " Number of Links: %d\n\n", ntohs(rl->links));
718e3744 5830
d62a17ae 5831 show_ip_ospf_database_router_links(vty, rl);
5832 vty_out(vty, "\n");
5833 }
5834
5835 return 0;
718e3744 5836}
5837
5838/* Show network-LSA detail information. */
d62a17ae 5839static int show_network_lsa_detail(struct vty *vty, struct ospf_lsa *lsa)
718e3744 5840{
d62a17ae 5841 int length, i;
718e3744 5842
d62a17ae 5843 if (lsa != NULL) {
5844 struct network_lsa *nl = (struct network_lsa *)lsa->data;
718e3744 5845
d62a17ae 5846 show_ip_ospf_database_header(vty, lsa);
718e3744 5847
d62a17ae 5848 vty_out(vty, " Network Mask: /%d\n", ip_masklen(nl->mask));
718e3744 5849
d62a17ae 5850 length = ntohs(lsa->data->length) - OSPF_LSA_HEADER_SIZE - 4;
718e3744 5851
d62a17ae 5852 for (i = 0; length > 0; i++, length -= 4)
5853 vty_out(vty, " Attached Router: %s\n",
5854 inet_ntoa(nl->routers[i]));
718e3744 5855
d62a17ae 5856 vty_out(vty, "\n");
5857 }
718e3744 5858
d62a17ae 5859 return 0;
718e3744 5860}
5861
5862/* Show summary-LSA detail information. */
d62a17ae 5863static int show_summary_lsa_detail(struct vty *vty, struct ospf_lsa *lsa)
718e3744 5864{
d62a17ae 5865 if (lsa != NULL) {
5866 struct summary_lsa *sl = (struct summary_lsa *)lsa->data;
718e3744 5867
d62a17ae 5868 show_ip_ospf_database_header(vty, lsa);
718e3744 5869
d62a17ae 5870 vty_out(vty, " Network Mask: /%d\n", ip_masklen(sl->mask));
5871 vty_out(vty, " TOS: 0 Metric: %d\n",
5872 GET_METRIC(sl->metric));
5873 vty_out(vty, "\n");
5874 }
718e3744 5875
d62a17ae 5876 return 0;
718e3744 5877}
5878
5879/* Show summary-ASBR-LSA detail information. */
d62a17ae 5880static int show_summary_asbr_lsa_detail(struct vty *vty, struct ospf_lsa *lsa)
718e3744 5881{
d62a17ae 5882 if (lsa != NULL) {
5883 struct summary_lsa *sl = (struct summary_lsa *)lsa->data;
718e3744 5884
d62a17ae 5885 show_ip_ospf_database_header(vty, lsa);
718e3744 5886
d62a17ae 5887 vty_out(vty, " Network Mask: /%d\n", ip_masklen(sl->mask));
5888 vty_out(vty, " TOS: 0 Metric: %d\n",
5889 GET_METRIC(sl->metric));
5890 vty_out(vty, "\n");
5891 }
718e3744 5892
d62a17ae 5893 return 0;
718e3744 5894}
5895
5896/* Show AS-external-LSA detail information. */
d62a17ae 5897static int show_as_external_lsa_detail(struct vty *vty, struct ospf_lsa *lsa)
5898{
5899 if (lsa != NULL) {
5900 struct as_external_lsa *al =
5901 (struct as_external_lsa *)lsa->data;
5902
5903 show_ip_ospf_database_header(vty, lsa);
5904
5905 vty_out(vty, " Network Mask: /%d\n", ip_masklen(al->mask));
5906 vty_out(vty, " Metric Type: %s\n",
5907 IS_EXTERNAL_METRIC(al->e[0].tos)
5908 ? "2 (Larger than any link state path)"
5909 : "1");
5910 vty_out(vty, " TOS: 0\n");
5911 vty_out(vty, " Metric: %d\n",
5912 GET_METRIC(al->e[0].metric));
5913 vty_out(vty, " Forward Address: %s\n",
5914 inet_ntoa(al->e[0].fwd_addr));
5915
5916 vty_out(vty,
5917 " External Route Tag: %" ROUTE_TAG_PRI "\n\n",
5918 (route_tag_t)ntohl(al->e[0].route_tag));
5919 }
718e3744 5920
d62a17ae 5921 return 0;
718e3744 5922}
075e12f5 5923#if 0
4dadc291 5924static int
718e3744 5925show_as_external_lsa_stdvty (struct ospf_lsa *lsa)
5926{
5927 struct as_external_lsa *al = (struct as_external_lsa *) lsa->data;
5928
5929 /* show_ip_ospf_database_header (vty, lsa); */
5930
2a42e285 5931 zlog_debug( " Network Mask: /%d%s",
718e3744 5932 ip_masklen (al->mask), "\n");
2a42e285 5933 zlog_debug( " Metric Type: %s%s",
718e3744 5934 IS_EXTERNAL_METRIC (al->e[0].tos) ?
5935 "2 (Larger than any link state path)" : "1", "\n");
2a42e285 5936 zlog_debug( " TOS: 0%s", "\n");
5937 zlog_debug( " Metric: %d%s",
718e3744 5938 GET_METRIC (al->e[0].metric), "\n");
2a42e285 5939 zlog_debug( " Forward Address: %s%s",
718e3744 5940 inet_ntoa (al->e[0].fwd_addr), "\n");
5941
dc9ffce8
CF
5942 zlog_debug( " External Route Tag: %"ROUTE_TAG_PRI"%s%s",
5943 (route_tag_t)ntohl (al->e[0].route_tag), "\n", "\n");
718e3744 5944
5945 return 0;
5946}
075e12f5 5947#endif
718e3744 5948/* Show AS-NSSA-LSA detail information. */
d62a17ae 5949static int show_as_nssa_lsa_detail(struct vty *vty, struct ospf_lsa *lsa)
5950{
5951 if (lsa != NULL) {
5952 struct as_external_lsa *al =
5953 (struct as_external_lsa *)lsa->data;
5954
5955 show_ip_ospf_database_header(vty, lsa);
5956
5957 vty_out(vty, " Network Mask: /%d\n", ip_masklen(al->mask));
5958 vty_out(vty, " Metric Type: %s\n",
5959 IS_EXTERNAL_METRIC(al->e[0].tos)
5960 ? "2 (Larger than any link state path)"
5961 : "1");
5962 vty_out(vty, " TOS: 0\n");
5963 vty_out(vty, " Metric: %d\n",
5964 GET_METRIC(al->e[0].metric));
5965 vty_out(vty, " NSSA: Forward Address: %s\n",
5966 inet_ntoa(al->e[0].fwd_addr));
5967
5968 vty_out(vty,
5969 " External Route Tag: %" ROUTE_TAG_PRI "\n\n",
5970 (route_tag_t)ntohl(al->e[0].route_tag));
5971 }
718e3744 5972
d62a17ae 5973 return 0;
718e3744 5974}
5975
d62a17ae 5976static int show_func_dummy(struct vty *vty, struct ospf_lsa *lsa)
718e3744 5977{
d62a17ae 5978 return 0;
718e3744 5979}
5980
d62a17ae 5981static int show_opaque_lsa_detail(struct vty *vty, struct ospf_lsa *lsa)
718e3744 5982{
d62a17ae 5983 if (lsa != NULL) {
5984 show_ip_ospf_database_header(vty, lsa);
5985 show_opaque_info_detail(vty, lsa);
718e3744 5986
d62a17ae 5987 vty_out(vty, "\n");
5988 }
5989 return 0;
5990}
5991
5992int (*show_function[])(struct vty *, struct ospf_lsa *) = {
5993 NULL,
5994 show_router_lsa_detail,
5995 show_network_lsa_detail,
5996 show_summary_lsa_detail,
5997 show_summary_asbr_lsa_detail,
5998 show_as_external_lsa_detail,
5999 show_func_dummy,
6000 show_as_nssa_lsa_detail, /* almost same as external */
6001 NULL, /* type-8 */
6002 show_opaque_lsa_detail,
6003 show_opaque_lsa_detail,
6004 show_opaque_lsa_detail,
6005};
6006
6007static void show_lsa_prefix_set(struct vty *vty, struct prefix_ls *lp,
6008 struct in_addr *id, struct in_addr *adv_router)
6009{
6010 memset(lp, 0, sizeof(struct prefix_ls));
6011 lp->family = 0;
6012 if (id == NULL)
6013 lp->prefixlen = 0;
6014 else if (adv_router == NULL) {
6015 lp->prefixlen = 32;
6016 lp->id = *id;
6017 } else {
6018 lp->prefixlen = 64;
6019 lp->id = *id;
6020 lp->adv_router = *adv_router;
6021 }
718e3744 6022}
718e3744 6023
d62a17ae 6024static void show_lsa_detail_proc(struct vty *vty, struct route_table *rt,
6025 struct in_addr *id, struct in_addr *adv_router)
6026{
6027 struct prefix_ls lp;
6028 struct route_node *rn, *start;
6029 struct ospf_lsa *lsa;
718e3744 6030
d62a17ae 6031 show_lsa_prefix_set(vty, &lp, id, adv_router);
6032 start = route_node_get(rt, (struct prefix *)&lp);
6033 if (start) {
6034 route_lock_node(start);
6035 for (rn = start; rn; rn = route_next_until(rn, start))
6036 if ((lsa = rn->info)) {
6037 if (show_function[lsa->data->type] != NULL)
6038 show_function[lsa->data->type](vty,
6039 lsa);
6040 }
6041 route_unlock_node(start);
6042 }
718e3744 6043}
6044
6045/* Show detail LSA information
6046 -- if id is NULL then show all LSAs. */
d62a17ae 6047static void show_lsa_detail(struct vty *vty, struct ospf *ospf, int type,
6048 struct in_addr *id, struct in_addr *adv_router)
6049{
6050 struct listnode *node;
6051 struct ospf_area *area;
6052
6053 switch (type) {
6054 case OSPF_AS_EXTERNAL_LSA:
6055 case OSPF_OPAQUE_AS_LSA:
6056 vty_out(vty, " %s \n\n",
6057 show_database_desc[type]);
6058 show_lsa_detail_proc(vty, AS_LSDB(ospf, type), id, adv_router);
6059 break;
6060 default:
6061 for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) {
6062 vty_out(vty, "\n %s (Area %s)\n\n",
6063 show_database_desc[type],
6064 ospf_area_desc_string(area));
6065 show_lsa_detail_proc(vty, AREA_LSDB(area, type), id,
6066 adv_router);
6067 }
6068 break;
718e3744 6069 }
6070}
6071
d62a17ae 6072static void show_lsa_detail_adv_router_proc(struct vty *vty,
6073 struct route_table *rt,
6074 struct in_addr *adv_router)
6075{
6076 struct route_node *rn;
6077 struct ospf_lsa *lsa;
6078
6079 for (rn = route_top(rt); rn; rn = route_next(rn))
6080 if ((lsa = rn->info))
6081 if (IPV4_ADDR_SAME(adv_router,
6082 &lsa->data->adv_router)) {
6083 if (CHECK_FLAG(lsa->flags, OSPF_LSA_LOCAL_XLT))
6084 continue;
6085 if (show_function[lsa->data->type] != NULL)
6086 show_function[lsa->data->type](vty,
6087 lsa);
6088 }
6089}
6090
718e3744 6091/* Show detail LSA information. */
d62a17ae 6092static void show_lsa_detail_adv_router(struct vty *vty, struct ospf *ospf,
6093 int type, struct in_addr *adv_router)
6094{
6095 struct listnode *node;
6096 struct ospf_area *area;
6097
6098 switch (type) {
6099 case OSPF_AS_EXTERNAL_LSA:
6100 case OSPF_OPAQUE_AS_LSA:
6101 vty_out(vty, " %s \n\n",
6102 show_database_desc[type]);
6103 show_lsa_detail_adv_router_proc(vty, AS_LSDB(ospf, type),
6104 adv_router);
6105 break;
6106 default:
6107 for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) {
6108 vty_out(vty, "\n %s (Area %s)\n\n",
6109 show_database_desc[type],
6110 ospf_area_desc_string(area));
6111 show_lsa_detail_adv_router_proc(
6112 vty, AREA_LSDB(area, type), adv_router);
6113 }
6114 break;
6115 }
6116}
6117
6118static void show_ip_ospf_database_summary(struct vty *vty, struct ospf *ospf,
6119 int self)
6120{
6121 struct ospf_lsa *lsa;
6122 struct route_node *rn;
6123 struct ospf_area *area;
6124 struct listnode *node;
6125 int type;
6126
6127 for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) {
6128 for (type = OSPF_MIN_LSA; type < OSPF_MAX_LSA; type++) {
6129 switch (type) {
6130 case OSPF_AS_EXTERNAL_LSA:
6131 case OSPF_OPAQUE_AS_LSA:
6132 continue;
6133 default:
6134 break;
6135 }
6136 if (ospf_lsdb_count_self(area->lsdb, type) > 0
6137 || (!self
6138 && ospf_lsdb_count(area->lsdb, type) > 0)) {
6139 vty_out(vty, " %s (Area %s)\n\n",
6140 show_database_desc[type],
6141 ospf_area_desc_string(area));
6142 vty_out(vty, "%s\n",
6143 show_database_header[type]);
6144
996c9314 6145 LSDB_LOOP (AREA_LSDB(area, type), rn, lsa)
044506e7 6146 show_lsa_summary(vty, lsa, self);
d62a17ae 6147
6148 vty_out(vty, "\n");
6149 }
6150 }
6151 }
6152
6153 for (type = OSPF_MIN_LSA; type < OSPF_MAX_LSA; type++) {
6154 switch (type) {
6155 case OSPF_AS_EXTERNAL_LSA:
6156 case OSPF_OPAQUE_AS_LSA:
6157 break;
6158 default:
6159 continue;
6160 }
6161 if (ospf_lsdb_count_self(ospf->lsdb, type)
6162 || (!self && ospf_lsdb_count(ospf->lsdb, type))) {
6163 vty_out(vty, " %s\n\n",
6164 show_database_desc[type]);
6165 vty_out(vty, "%s\n", show_database_header[type]);
6166
996c9314 6167 LSDB_LOOP (AS_LSDB(ospf, type), rn, lsa)
044506e7 6168 show_lsa_summary(vty, lsa, self);
d62a17ae 6169
6170 vty_out(vty, "\n");
6171 }
6172 }
6173
6174 vty_out(vty, "\n");
6175}
6176
6177static void show_ip_ospf_database_maxage(struct vty *vty, struct ospf *ospf)
6178{
6179 struct route_node *rn;
6180
6181 vty_out(vty, "\n MaxAge Link States:\n\n");
6182
6183 for (rn = route_top(ospf->maxage_lsa); rn; rn = route_next(rn)) {
6184 struct ospf_lsa *lsa;
6185
6186 if ((lsa = rn->info) != NULL) {
6187 vty_out(vty, "Link type: %d\n", lsa->data->type);
6188 vty_out(vty, "Link State ID: %s\n",
6189 inet_ntoa(lsa->data->id));
6190 vty_out(vty, "Advertising Router: %s\n",
6191 inet_ntoa(lsa->data->adv_router));
6192 vty_out(vty, "LSA lock count: %d\n", lsa->lock);
6193 vty_out(vty, "\n");
6194 }
91e6a0e5 6195 }
718e3744 6196}
6197
718e3744 6198#define OSPF_LSA_TYPE_NSSA_DESC "NSSA external link state\n"
6199#define OSPF_LSA_TYPE_NSSA_CMD_STR "|nssa-external"
718e3744 6200
718e3744 6201#define OSPF_LSA_TYPE_OPAQUE_LINK_DESC "Link local Opaque-LSA\n"
6202#define OSPF_LSA_TYPE_OPAQUE_AREA_DESC "Link area Opaque-LSA\n"
6203#define OSPF_LSA_TYPE_OPAQUE_AS_DESC "Link AS Opaque-LSA\n"
6204#define OSPF_LSA_TYPE_OPAQUE_CMD_STR "|opaque-link|opaque-area|opaque-as"
718e3744 6205
d62a17ae 6206#define OSPF_LSA_TYPES_DESC \
6207 "ASBR summary link states\n" \
6208 "External link states\n" \
6209 "Network link states\n" \
6210 "Router link states\n" \
6211 "Network summary link states\n" OSPF_LSA_TYPE_NSSA_DESC \
6212 OSPF_LSA_TYPE_OPAQUE_LINK_DESC OSPF_LSA_TYPE_OPAQUE_AREA_DESC \
6213 OSPF_LSA_TYPE_OPAQUE_AS_DESC
6214
6215static int show_ip_ospf_database_common(struct vty *vty, struct ospf *ospf,
6216 int arg_base, int argc,
d7c0a89a
QY
6217 struct cmd_token **argv,
6218 uint8_t use_vrf)
d62a17ae 6219{
6220 int idx_type = 4;
6221 int type, ret;
6222 struct in_addr id, adv_router;
6223
6224 if (ospf->instance)
6225 vty_out(vty, "\nOSPF Instance: %d\n", ospf->instance);
6226
b1c3ae8c 6227 ospf_show_vrf_name(ospf, vty, NULL, use_vrf);
87bd50e8 6228
d62a17ae 6229 vty_out(vty, "\n OSPF Router with ID (%s)\n\n",
6230 inet_ntoa(ospf->router_id));
6231
6232 /* Show all LSA. */
6233 if (argc == arg_base + 4) {
6234 show_ip_ospf_database_summary(vty, ospf, 0);
6235 return CMD_SUCCESS;
6236 }
718e3744 6237
d62a17ae 6238 /* Set database type to show. */
6239 if (strncmp(argv[arg_base + idx_type]->text, "r", 1) == 0)
6240 type = OSPF_ROUTER_LSA;
6241 else if (strncmp(argv[arg_base + idx_type]->text, "ne", 2) == 0)
6242 type = OSPF_NETWORK_LSA;
6243 else if (strncmp(argv[arg_base + idx_type]->text, "ns", 2) == 0)
6244 type = OSPF_AS_NSSA_LSA;
6245 else if (strncmp(argv[arg_base + idx_type]->text, "su", 2) == 0)
6246 type = OSPF_SUMMARY_LSA;
6247 else if (strncmp(argv[arg_base + idx_type]->text, "a", 1) == 0)
6248 type = OSPF_ASBR_SUMMARY_LSA;
6249 else if (strncmp(argv[arg_base + idx_type]->text, "e", 1) == 0)
6250 type = OSPF_AS_EXTERNAL_LSA;
6251 else if (strncmp(argv[arg_base + idx_type]->text, "se", 2) == 0) {
6252 show_ip_ospf_database_summary(vty, ospf, 1);
6253 return CMD_SUCCESS;
6254 } else if (strncmp(argv[arg_base + idx_type]->text, "m", 1) == 0) {
6255 show_ip_ospf_database_maxage(vty, ospf);
6256 return CMD_SUCCESS;
6257 } else if (strncmp(argv[arg_base + idx_type]->text, "opaque-l", 8) == 0)
6258 type = OSPF_OPAQUE_LINK_LSA;
6259 else if (strncmp(argv[arg_base + idx_type]->text, "opaque-ar", 9) == 0)
6260 type = OSPF_OPAQUE_AREA_LSA;
6261 else if (strncmp(argv[arg_base + idx_type]->text, "opaque-as", 9) == 0)
6262 type = OSPF_OPAQUE_AS_LSA;
6263 else
718e3744 6264 return CMD_WARNING;
d62a17ae 6265
6266 /* `show ip ospf database LSA'. */
6267 if (argc == arg_base + 5)
6268 show_lsa_detail(vty, ospf, type, NULL, NULL);
6269 else if (argc >= arg_base + 6) {
6270 ret = inet_aton(argv[arg_base + 5]->arg, &id);
6271 if (!ret)
6272 return CMD_WARNING;
6273
6274 /* `show ip ospf database LSA ID'. */
6275 if (argc == arg_base + 6)
6276 show_lsa_detail(vty, ospf, type, &id, NULL);
6277 /* `show ip ospf database LSA ID adv-router ADV_ROUTER'. */
6278 else if (argc == arg_base + 7) {
6279 if (strncmp(argv[arg_base + 6]->text, "s", 1) == 0)
6280 adv_router = ospf->router_id;
6281 else {
6282 ret = inet_aton(argv[arg_base + 7]->arg,
6283 &adv_router);
6284 if (!ret)
6285 return CMD_WARNING;
6286 }
6287 show_lsa_detail(vty, ospf, type, &id, &adv_router);
6288 }
718e3744 6289 }
718e3744 6290
d62a17ae 6291 return CMD_SUCCESS;
718e3744 6292}
6293
7a7be519 6294DEFUN (show_ip_ospf_database_max,
6295 show_ip_ospf_database_max_cmd,
b5a8894d 6296 "show ip ospf [vrf <NAME|all>] database <max-age|self-originate>",
7a7be519 6297 SHOW_STR
6298 IP_STR
6299 "OSPF information\n"
b5a8894d
CS
6300 VRF_CMD_HELP_STR
6301 "All VRFs\n"
7a7be519 6302 "Database summary\n"
6303 "LSAs in MaxAge list\n"
6304 "Self-originated link states\n")
6305{
b5a8894d
CS
6306 struct ospf *ospf = NULL;
6307 struct listnode *node = NULL;
6308 char *vrf_name = NULL;
6309 bool all_vrf = FALSE;
6310 int ret = CMD_SUCCESS;
6311 int inst = 0;
6312 int idx_vrf = 0;
d7c0a89a 6313 uint8_t use_vrf = 0;
f412b39a 6314
43b8d1d8 6315 OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
f412b39a 6316
b5a8894d 6317 if (vrf_name) {
b1c3ae8c 6318 use_vrf = 1;
b5a8894d
CS
6319 if (all_vrf) {
6320 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
6321 if (!ospf->oi_running)
6322 continue;
996c9314
LB
6323 ret = show_ip_ospf_database_common(
6324 vty, ospf, idx_vrf ? 2 : 0, argc, argv,
6325 use_vrf);
b5a8894d
CS
6326 }
6327 } else {
6328 ospf = ospf_lookup_by_inst_name(inst, vrf_name);
6329 if (ospf == NULL || !ospf->oi_running)
6330 return CMD_SUCCESS;
996c9314
LB
6331 ret = (show_ip_ospf_database_common(
6332 vty, ospf, idx_vrf ? 2 : 0, argc, argv,
6333 use_vrf));
b5a8894d
CS
6334 }
6335 } else {
6336 /* Display default ospf (instance 0) info */
6337 ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
6338 if (ospf == NULL || !ospf->oi_running)
6339 return CMD_SUCCESS;
b1c3ae8c
CS
6340 ret = show_ip_ospf_database_common(vty, ospf, 0, argc, argv,
6341 use_vrf);
b5a8894d
CS
6342 }
6343
6344 return ret;
7a7be519 6345}
f412b39a 6346
f412b39a
DW
6347DEFUN (show_ip_ospf_instance_database,
6348 show_ip_ospf_instance_database_cmd,
43b8d1d8 6349 "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 6350 SHOW_STR
6351 IP_STR
6352 "OSPF information\n"
7c8ff89e 6353 "Instance ID\n"
b5a8894d 6354 VRF_CMD_HELP_STR
7a7be519 6355 "Database summary\n"
6356 OSPF_LSA_TYPES_DESC
6357 "Link State ID (as an IP address)\n"
6358 "Self-originated link states\n"
6359 "Advertising Router link states\n"
6360 "Advertising Router (as an IP address)\n")
7c8ff89e 6361{
d62a17ae 6362 struct ospf *ospf;
d7c0a89a 6363 unsigned short instance = 0;
b5a8894d
CS
6364 struct listnode *node = NULL;
6365 char *vrf_name = NULL;
6366 bool all_vrf = FALSE;
6367 int ret = CMD_SUCCESS;
6368 int inst = 0;
d62a17ae 6369 int idx = 0;
d7c0a89a 6370 uint8_t use_vrf = 0;
b5a8894d 6371
d62a17ae 6372 if (argv_find(argv, argc, "(1-65535)", &idx)) {
6373 instance = strtoul(argv[idx]->arg, NULL, 10);
6374 ospf = ospf_lookup_instance(instance);
ac28e4ec
CS
6375 if (ospf == NULL)
6376 return CMD_NOT_MY_INSTANCE;
b5a8894d
CS
6377 if (!ospf->oi_running)
6378 return CMD_SUCCESS;
6379
6380 return (show_ip_ospf_database_common(vty, ospf, idx ? 1 : 0,
b1c3ae8c 6381 argc, argv, use_vrf));
b5a8894d
CS
6382 } else if (argv_find(argv, argc, "vrf", &idx)) {
6383 vrf_name = argv[++idx]->arg;
6384 all_vrf = strmatch(vrf_name, "all");
d62a17ae 6385 }
7c8ff89e 6386
b5a8894d 6387 if (vrf_name) {
b1c3ae8c 6388 use_vrf = 1;
b5a8894d
CS
6389 if (all_vrf) {
6390 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
6391 if (!ospf->oi_running)
6392 continue;
996c9314
LB
6393 ret = (show_ip_ospf_database_common(
6394 vty, ospf, idx ? 2 : 0, argc, argv,
6395 use_vrf));
b5a8894d
CS
6396 }
6397 } else {
6398 ospf = ospf_lookup_by_inst_name(inst, vrf_name);
6399 if ((ospf == NULL) || !ospf->oi_running)
6400 return CMD_SUCCESS;
996c9314
LB
6401 ret = (show_ip_ospf_database_common(
6402 vty, ospf, idx ? 2 : 0, argc, argv, use_vrf));
b5a8894d
CS
6403 }
6404 } else {
6405 /* Display default ospf (instance 0) info */
6406 ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
6407 if (ospf == NULL || !ospf->oi_running)
6408 return CMD_SUCCESS;
b1c3ae8c
CS
6409 ret = (show_ip_ospf_database_common(vty, ospf, 0, argc, argv,
6410 use_vrf));
b5a8894d 6411 }
7c8ff89e 6412
b5a8894d 6413 return ret;
7c8ff89e
DS
6414}
6415
7a7be519 6416DEFUN (show_ip_ospf_instance_database_max,
6417 show_ip_ospf_instance_database_max_cmd,
6418 "show ip ospf (1-65535) database <max-age|self-originate>",
6419 SHOW_STR
6420 IP_STR
6421 "OSPF information\n"
6422 "Instance ID\n"
6423 "Database summary\n"
6424 "LSAs in MaxAge list\n"
6425 "Self-originated link states\n")
6426{
d62a17ae 6427 int idx_number = 3;
6428 struct ospf *ospf;
d7c0a89a 6429 unsigned short instance = 0;
d62a17ae 6430
6431 instance = strtoul(argv[idx_number]->arg, NULL, 10);
6432
ac28e4ec
CS
6433 ospf = ospf_lookup_instance(instance);
6434 if (ospf == NULL)
6435 return CMD_NOT_MY_INSTANCE;
6436
6437 if (!ospf->oi_running)
d62a17ae 6438 return CMD_SUCCESS;
6439
b1c3ae8c 6440 return show_ip_ospf_database_common(vty, ospf, 1, argc, argv, 0);
d62a17ae 6441}
6442
6443
6444static int show_ip_ospf_database_type_adv_router_common(struct vty *vty,
6445 struct ospf *ospf,
6446 int arg_base, int argc,
b1c3ae8c 6447 struct cmd_token **argv,
d7c0a89a 6448 uint8_t use_vrf)
d62a17ae 6449{
6450 int idx_type = 4;
6451 int type, ret;
6452 struct in_addr adv_router;
6453
6454 if (ospf->instance)
6455 vty_out(vty, "\nOSPF Instance: %d\n", ospf->instance);
6456
b1c3ae8c 6457 ospf_show_vrf_name(ospf, vty, NULL, use_vrf);
87bd50e8 6458
d62a17ae 6459 vty_out(vty, "\n OSPF Router with ID (%s)\n\n",
6460 inet_ntoa(ospf->router_id));
6461
6462 /* Set database type to show. */
6463 if (strncmp(argv[arg_base + idx_type]->text, "r", 1) == 0)
6464 type = OSPF_ROUTER_LSA;
6465 else if (strncmp(argv[arg_base + idx_type]->text, "ne", 2) == 0)
6466 type = OSPF_NETWORK_LSA;
6467 else if (strncmp(argv[arg_base + idx_type]->text, "ns", 2) == 0)
6468 type = OSPF_AS_NSSA_LSA;
6469 else if (strncmp(argv[arg_base + idx_type]->text, "s", 1) == 0)
6470 type = OSPF_SUMMARY_LSA;
6471 else if (strncmp(argv[arg_base + idx_type]->text, "a", 1) == 0)
6472 type = OSPF_ASBR_SUMMARY_LSA;
6473 else if (strncmp(argv[arg_base + idx_type]->text, "e", 1) == 0)
6474 type = OSPF_AS_EXTERNAL_LSA;
6475 else if (strncmp(argv[arg_base + idx_type]->text, "opaque-l", 8) == 0)
6476 type = OSPF_OPAQUE_LINK_LSA;
6477 else if (strncmp(argv[arg_base + idx_type]->text, "opaque-ar", 9) == 0)
6478 type = OSPF_OPAQUE_AREA_LSA;
6479 else if (strncmp(argv[arg_base + idx_type]->text, "opaque-as", 9) == 0)
6480 type = OSPF_OPAQUE_AS_LSA;
6481 else
6482 return CMD_WARNING;
7c8ff89e 6483
d62a17ae 6484 /* `show ip ospf database LSA adv-router ADV_ROUTER'. */
6485 if (strncmp(argv[arg_base + 5]->text, "s", 1) == 0)
6486 adv_router = ospf->router_id;
6487 else {
6488 ret = inet_aton(argv[arg_base + 6]->arg, &adv_router);
6489 if (!ret)
6490 return CMD_WARNING;
6491 }
7c8ff89e 6492
d62a17ae 6493 show_lsa_detail_adv_router(vty, ospf, type, &adv_router);
7c8ff89e 6494
d62a17ae 6495 return CMD_SUCCESS;
7c8ff89e
DS
6496}
6497
7c8ff89e
DS
6498DEFUN (show_ip_ospf_instance_database_type_adv_router,
6499 show_ip_ospf_instance_database_type_adv_router_cmd,
43b8d1d8 6500 "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
6501 SHOW_STR
6502 IP_STR
6503 "OSPF information\n"
6504 "Instance ID\n"
b5a8894d 6505 VRF_CMD_HELP_STR
7c8ff89e
DS
6506 "Database summary\n"
6507 OSPF_LSA_TYPES_DESC
6508 "Advertising Router link states\n"
3a2d747c
QY
6509 "Advertising Router (as an IP address)\n"
6510 "Self-originated link states\n")
7c8ff89e 6511{
b5a8894d 6512 struct ospf *ospf = NULL;
d7c0a89a 6513 unsigned short instance = 0;
b5a8894d
CS
6514 struct listnode *node = NULL;
6515 char *vrf_name = NULL;
6516 bool all_vrf = FALSE;
6517 int ret = CMD_SUCCESS;
6518 int inst = 0;
43b8d1d8 6519 int idx = 0, idx_vrf = 0;
d7c0a89a 6520 uint8_t use_vrf = 0;
7c8ff89e 6521
d62a17ae 6522 if (argv_find(argv, argc, "(1-65535)", &idx)) {
6523 instance = strtoul(argv[idx]->arg, NULL, 10);
6524 ospf = ospf_lookup_instance(instance);
ac28e4ec
CS
6525 if (ospf == NULL)
6526 return CMD_NOT_MY_INSTANCE;
b5a8894d
CS
6527 if (!ospf->oi_running)
6528 return CMD_SUCCESS;
996c9314
LB
6529 return (show_ip_ospf_database_type_adv_router_common(
6530 vty, ospf, idx ? 1 : 0, argc, argv, use_vrf));
b5a8894d 6531 }
43b8d1d8
CS
6532
6533 OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
6534
b5a8894d 6535 if (vrf_name) {
b1c3ae8c 6536 use_vrf = 1;
b5a8894d
CS
6537 if (all_vrf) {
6538 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
6539 if (!ospf->oi_running)
6540 continue;
996c9314
LB
6541 ret = show_ip_ospf_database_type_adv_router_common(
6542 vty, ospf, idx ? 1 : 0, argc, argv,
6543 use_vrf);
b5a8894d
CS
6544 }
6545 } else {
6546 ospf = ospf_lookup_by_inst_name(inst, vrf_name);
6547 if ((ospf == NULL) || !ospf->oi_running)
6548 return CMD_SUCCESS;
996c9314
LB
6549 ret = show_ip_ospf_database_type_adv_router_common(
6550 vty, ospf, idx ? 1 : 0, argc, argv, use_vrf);
b5a8894d
CS
6551 }
6552 } else {
6553 /* Display default ospf (instance 0) info */
6554 ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
6555 if (ospf == NULL || !ospf->oi_running)
6556 return CMD_SUCCESS;
996c9314
LB
6557 ret = show_ip_ospf_database_type_adv_router_common(
6558 vty, ospf, idx ? 1 : 0, argc, argv, use_vrf);
b5a8894d
CS
6559 }
6560 return ret;
6561 /*return (show_ip_ospf_database_type_adv_router_common(
6562 vty, ospf, idx ? 1 : 0, argc, argv));*/
718e3744 6563}
6564
718e3744 6565DEFUN (ip_ospf_authentication_args,
6566 ip_ospf_authentication_args_addr_cmd,
7a7be519 6567 "ip ospf authentication <null|message-digest> [A.B.C.D]",
718e3744 6568 "IP Information\n"
6569 "OSPF interface commands\n"
6570 "Enable authentication on this interface\n"
6571 "Use null authentication\n"
6572 "Use message-digest authentication\n"
7a7be519 6573 "Address of interface\n")
718e3744 6574{
d62a17ae 6575 VTY_DECLVAR_CONTEXT(interface, ifp);
6576 int idx_encryption = 3;
6577 int idx_ipv4 = 4;
6578 struct in_addr addr;
6579 int ret;
6580 struct ospf_if_params *params;
6581
6582 params = IF_DEF_PARAMS(ifp);
6583
6584 if (argc == 5) {
6585 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
6586 if (!ret) {
6587 vty_out(vty,
6588 "Please specify interface address by A.B.C.D\n");
6589 return CMD_WARNING_CONFIG_FAILED;
6590 }
718e3744 6591
d62a17ae 6592 params = ospf_get_if_params(ifp, addr);
6593 ospf_if_update_params(ifp, addr);
6594 }
718e3744 6595
d62a17ae 6596 /* Handle null authentication */
6597 if (argv[idx_encryption]->arg[0] == 'n') {
6598 SET_IF_PARAM(params, auth_type);
6599 params->auth_type = OSPF_AUTH_NULL;
6600 return CMD_SUCCESS;
6601 }
718e3744 6602
d62a17ae 6603 /* Handle message-digest authentication */
6604 if (argv[idx_encryption]->arg[0] == 'm') {
6605 SET_IF_PARAM(params, auth_type);
6606 params->auth_type = OSPF_AUTH_CRYPTOGRAPHIC;
6607 return CMD_SUCCESS;
6608 }
718e3744 6609
d62a17ae 6610 vty_out(vty, "You shouldn't get here!\n");
6611 return CMD_WARNING_CONFIG_FAILED;
718e3744 6612}
6613
718e3744 6614DEFUN (ip_ospf_authentication,
6615 ip_ospf_authentication_addr_cmd,
7a7be519 6616 "ip ospf authentication [A.B.C.D]",
718e3744 6617 "IP Information\n"
6618 "OSPF interface commands\n"
6619 "Enable authentication on this interface\n"
efd7904e 6620 "Address of interface\n")
718e3744 6621{
d62a17ae 6622 VTY_DECLVAR_CONTEXT(interface, ifp);
6623 int idx_ipv4 = 3;
6624 struct in_addr addr;
6625 int ret;
6626 struct ospf_if_params *params;
6627
6628 params = IF_DEF_PARAMS(ifp);
6629
6630 if (argc == 4) {
6631 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
6632 if (!ret) {
6633 vty_out(vty,
6634 "Please specify interface address by A.B.C.D\n");
6635 return CMD_WARNING_CONFIG_FAILED;
6636 }
6637
6638 params = ospf_get_if_params(ifp, addr);
6639 ospf_if_update_params(ifp, addr);
718e3744 6640 }
6641
d62a17ae 6642 SET_IF_PARAM(params, auth_type);
6643 params->auth_type = OSPF_AUTH_SIMPLE;
718e3744 6644
d62a17ae 6645 return CMD_SUCCESS;
718e3744 6646}
6647
b4a039bf
DS
6648DEFUN (no_ip_ospf_authentication_args,
6649 no_ip_ospf_authentication_args_addr_cmd,
7a7be519 6650 "no ip ospf authentication <null|message-digest> [A.B.C.D]",
b4a039bf
DS
6651 NO_STR
6652 "IP Information\n"
6653 "OSPF interface commands\n"
6654 "Enable authentication on this interface\n"
6655 "Use null authentication\n"
6656 "Use message-digest authentication\n"
efd7904e 6657 "Address of interface\n")
b4a039bf 6658{
d62a17ae 6659 VTY_DECLVAR_CONTEXT(interface, ifp);
6660 int idx_encryption = 4;
6661 int idx_ipv4 = 5;
6662 struct in_addr addr;
6663 int ret;
6664 struct ospf_if_params *params;
6665 struct route_node *rn;
6666 int auth_type;
6667
6668 params = IF_DEF_PARAMS(ifp);
6669
6670 if (argc == 6) {
6671 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
6672 if (!ret) {
6673 vty_out(vty,
6674 "Please specify interface address by A.B.C.D\n");
6675 return CMD_WARNING_CONFIG_FAILED;
6676 }
b4a039bf 6677
d62a17ae 6678 params = ospf_lookup_if_params(ifp, addr);
6679 if (params == NULL) {
6680 vty_out(vty, "Ip Address specified is unknown\n");
6681 return CMD_WARNING_CONFIG_FAILED;
6682 }
6683 params->auth_type = OSPF_AUTH_NOTSET;
6684 UNSET_IF_PARAM(params, auth_type);
6685 if (params != IF_DEF_PARAMS(ifp)) {
6686 ospf_free_if_params(ifp, addr);
6687 ospf_if_update_params(ifp, addr);
6688 }
6689 } else {
6690 if (argv[idx_encryption]->arg[0] == 'n') {
6691 auth_type = OSPF_AUTH_NULL;
6692 } else if (argv[idx_encryption]->arg[0] == 'm') {
6693 auth_type = OSPF_AUTH_CRYPTOGRAPHIC;
6694 } else {
6695 vty_out(vty, "Unexpected input encountered\n");
6696 return CMD_WARNING_CONFIG_FAILED;
6697 }
6698 /*
6699 * Here we have a case where the user has entered
6700 * 'no ip ospf authentication (null | message_digest )'
6701 * we need to find if we have any ip addresses underneath it
6702 * that
6703 * correspond to the associated type.
6704 */
6705 if (params->auth_type == auth_type) {
6706 params->auth_type = OSPF_AUTH_NOTSET;
6707 UNSET_IF_PARAM(params, auth_type);
6708 }
6709
6710 for (rn = route_top(IF_OIFS_PARAMS(ifp)); rn;
6711 rn = route_next(rn)) {
6712 if ((params = rn->info)) {
6713 if (params->auth_type == auth_type) {
6714 params->auth_type = OSPF_AUTH_NOTSET;
6715 UNSET_IF_PARAM(params, auth_type);
6716 if (params != IF_DEF_PARAMS(ifp)) {
6717 ospf_free_if_params(
6718 ifp, rn->p.u.prefix4);
6719 ospf_if_update_params(
6720 ifp, rn->p.u.prefix4);
6721 }
6722 }
6723 }
b4a039bf 6724 }
b4a039bf 6725 }
b4a039bf 6726
d62a17ae 6727 return CMD_SUCCESS;
b4a039bf
DS
6728}
6729
718e3744 6730DEFUN (no_ip_ospf_authentication,
6731 no_ip_ospf_authentication_addr_cmd,
7a7be519 6732 "no ip ospf authentication [A.B.C.D]",
718e3744 6733 NO_STR
6734 "IP Information\n"
6735 "OSPF interface commands\n"
6736 "Enable authentication on this interface\n"
efd7904e 6737 "Address of interface\n")
718e3744 6738{
d62a17ae 6739 VTY_DECLVAR_CONTEXT(interface, ifp);
6740 int idx_ipv4 = 4;
6741 struct in_addr addr;
6742 int ret;
6743 struct ospf_if_params *params;
6744 struct route_node *rn;
6745
6746 params = IF_DEF_PARAMS(ifp);
6747
6748 if (argc == 5) {
6749 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
6750 if (!ret) {
6751 vty_out(vty,
6752 "Please specify interface address by A.B.C.D\n");
6753 return CMD_WARNING_CONFIG_FAILED;
6754 }
718e3744 6755
d62a17ae 6756 params = ospf_lookup_if_params(ifp, addr);
6757 if (params == NULL) {
6758 vty_out(vty, "Ip Address specified is unknown\n");
6759 return CMD_WARNING_CONFIG_FAILED;
6760 }
718e3744 6761
d62a17ae 6762 params->auth_type = OSPF_AUTH_NOTSET;
6763 UNSET_IF_PARAM(params, auth_type);
6764 if (params != IF_DEF_PARAMS(ifp)) {
6765 ospf_free_if_params(ifp, addr);
6766 ospf_if_update_params(ifp, addr);
6767 }
6768 } else {
6769 /*
6770 * When a user enters 'no ip ospf authentication'
6771 * We should remove all authentication types from
6772 * the interface.
6773 */
6774 if ((params->auth_type == OSPF_AUTH_NULL)
6775 || (params->auth_type == OSPF_AUTH_CRYPTOGRAPHIC)
6776 || (params->auth_type == OSPF_AUTH_SIMPLE)) {
6777 params->auth_type = OSPF_AUTH_NOTSET;
6778 UNSET_IF_PARAM(params, auth_type);
6779 }
813d4307 6780
d62a17ae 6781 for (rn = route_top(IF_OIFS_PARAMS(ifp)); rn;
6782 rn = route_next(rn)) {
6783 if ((params = rn->info)) {
6784
6785 if ((params->auth_type == OSPF_AUTH_NULL)
6786 || (params->auth_type
6787 == OSPF_AUTH_CRYPTOGRAPHIC)
6788 || (params->auth_type
6789 == OSPF_AUTH_SIMPLE)) {
6790 params->auth_type = OSPF_AUTH_NOTSET;
6791 UNSET_IF_PARAM(params, auth_type);
6792 if (params != IF_DEF_PARAMS(ifp)) {
6793 ospf_free_if_params(
6794 ifp, rn->p.u.prefix4);
6795 ospf_if_update_params(
6796 ifp, rn->p.u.prefix4);
6797 }
6798 }
6799 }
b4a039bf 6800 }
b4a039bf 6801 }
d62a17ae 6802
6803 return CMD_SUCCESS;
718e3744 6804}
6805
0d829fa7 6806
718e3744 6807DEFUN (ip_ospf_authentication_key,
6808 ip_ospf_authentication_key_addr_cmd,
7a7be519 6809 "ip ospf authentication-key AUTH_KEY [A.B.C.D]",
718e3744 6810 "IP Information\n"
6811 "OSPF interface commands\n"
6812 "Authentication password (key)\n"
6813 "The OSPF password (key)\n"
efd7904e 6814 "Address of interface\n")
718e3744 6815{
d62a17ae 6816 VTY_DECLVAR_CONTEXT(interface, ifp);
6817 int idx = 0;
6818 struct in_addr addr;
6819 struct ospf_if_params *params;
718e3744 6820
d62a17ae 6821 params = IF_DEF_PARAMS(ifp);
6822
6823 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
6824 if (!inet_aton(argv[idx]->arg, &addr)) {
6825 vty_out(vty,
6826 "Please specify interface address by A.B.C.D\n");
6827 return CMD_WARNING_CONFIG_FAILED;
6828 }
718e3744 6829
d62a17ae 6830 params = ospf_get_if_params(ifp, addr);
6831 ospf_if_update_params(ifp, addr);
6832 }
718e3744 6833
d62a17ae 6834 memset(params->auth_simple, 0, OSPF_AUTH_SIMPLE_SIZE + 1);
6835 strncpy((char *)params->auth_simple, argv[3]->arg,
6836 OSPF_AUTH_SIMPLE_SIZE);
6837 SET_IF_PARAM(params, auth_simple);
718e3744 6838
d62a17ae 6839 return CMD_SUCCESS;
718e3744 6840}
6841
7a7be519 6842DEFUN_HIDDEN (ospf_authentication_key,
747e489c 6843 ospf_authentication_key_cmd,
0d829fa7 6844 "ospf authentication-key AUTH_KEY [A.B.C.D]",
747e489c 6845 "OSPF interface commands\n"
baf9eaad 6846 VLINK_HELPSTR_AUTH_SIMPLE
0d829fa7 6847 "Address of interface\n")
718e3744 6848{
d62a17ae 6849 return ip_ospf_authentication_key(self, vty, argc, argv);
718e3744 6850}
6851
7a7be519 6852DEFUN (no_ip_ospf_authentication_key,
6853 no_ip_ospf_authentication_key_authkey_addr_cmd,
6854 "no ip ospf authentication-key [AUTH_KEY [A.B.C.D]]",
6855 NO_STR
6856 "IP Information\n"
6857 "OSPF interface commands\n"
baf9eaad
CS
6858 VLINK_HELPSTR_AUTH_SIMPLE
6859 "Address of interface\n")
7a7be519 6860{
d62a17ae 6861 VTY_DECLVAR_CONTEXT(interface, ifp);
6862 int idx = 0;
6863 struct in_addr addr;
6864 struct ospf_if_params *params;
6865 params = IF_DEF_PARAMS(ifp);
6866
6867 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
6868 if (!inet_aton(argv[idx]->arg, &addr)) {
6869 vty_out(vty,
6870 "Please specify interface address by A.B.C.D\n");
6871 return CMD_WARNING_CONFIG_FAILED;
6872 }
7a7be519 6873
d62a17ae 6874 params = ospf_lookup_if_params(ifp, addr);
6875 if (params == NULL)
6876 return CMD_SUCCESS;
7a7be519 6877 }
813d4307 6878
d62a17ae 6879 memset(params->auth_simple, 0, OSPF_AUTH_SIMPLE_SIZE);
6880 UNSET_IF_PARAM(params, auth_simple);
718e3744 6881
d62a17ae 6882 if (params != IF_DEF_PARAMS(ifp)) {
6883 ospf_free_if_params(ifp, addr);
6884 ospf_if_update_params(ifp, addr);
6885 }
813d4307 6886
d62a17ae 6887 return CMD_SUCCESS;
7a7be519 6888}
813d4307 6889
0d829fa7
QY
6890DEFUN_HIDDEN (no_ospf_authentication_key,
6891 no_ospf_authentication_key_authkey_addr_cmd,
6892 "no ospf authentication-key [AUTH_KEY [A.B.C.D]]",
6893 NO_STR
6894 "OSPF interface commands\n"
baf9eaad
CS
6895 VLINK_HELPSTR_AUTH_SIMPLE
6896 "Address of interface\n")
0d829fa7 6897{
d62a17ae 6898 return no_ip_ospf_authentication_key(self, vty, argc, argv);
0d829fa7
QY
6899}
6900
718e3744 6901DEFUN (ip_ospf_message_digest_key,
537eae3f 6902 ip_ospf_message_digest_key_cmd,
7a7be519 6903 "ip ospf message-digest-key (1-255) md5 KEY [A.B.C.D]",
718e3744 6904 "IP Information\n"
6905 "OSPF interface commands\n"
6906 "Message digest authentication password (key)\n"
6907 "Key ID\n"
6908 "Use MD5 algorithm\n"
fefa0d82
QY
6909 "The OSPF password (key)\n"
6910 "Address of interface\n")
718e3744 6911{
d62a17ae 6912 VTY_DECLVAR_CONTEXT(interface, ifp);
6913 struct crypt_key *ck;
d7c0a89a 6914 uint8_t key_id;
d62a17ae 6915 struct in_addr addr;
6916 struct ospf_if_params *params;
6917
6918 params = IF_DEF_PARAMS(ifp);
6919 int idx = 0;
6920
6921 argv_find(argv, argc, "(1-255)", &idx);
6922 char *keyid = argv[idx]->arg;
6923 argv_find(argv, argc, "KEY", &idx);
6924 char *cryptkey = argv[idx]->arg;
6925
6926 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
6927 if (!inet_aton(argv[idx]->arg, &addr)) {
6928 vty_out(vty,
6929 "Please specify interface address by A.B.C.D\n");
6930 return CMD_WARNING_CONFIG_FAILED;
6931 }
6932
6933 params = ospf_get_if_params(ifp, addr);
6934 ospf_if_update_params(ifp, addr);
718e3744 6935 }
6936
d62a17ae 6937 key_id = strtol(keyid, NULL, 10);
6938 if (ospf_crypt_key_lookup(params->auth_crypt, key_id) != NULL) {
6939 vty_out(vty, "OSPF: Key %d already exists\n", key_id);
851fcbae 6940 return CMD_WARNING;
d62a17ae 6941 }
718e3744 6942
d62a17ae 6943 ck = ospf_crypt_key_new();
d7c0a89a 6944 ck->key_id = (uint8_t)key_id;
d62a17ae 6945 memset(ck->auth_key, 0, OSPF_AUTH_MD5_SIZE + 1);
6946 strncpy((char *)ck->auth_key, cryptkey, OSPF_AUTH_MD5_SIZE);
718e3744 6947
d62a17ae 6948 ospf_crypt_key_add(params->auth_crypt, ck);
6949 SET_IF_PARAM(params, auth_crypt);
718e3744 6950
d62a17ae 6951 return CMD_SUCCESS;
718e3744 6952}
6953
7a7be519 6954DEFUN_HIDDEN (ospf_message_digest_key,
747e489c 6955 ospf_message_digest_key_cmd,
0d829fa7 6956 "ospf message-digest-key (1-255) md5 KEY [A.B.C.D]",
747e489c
DW
6957 "OSPF interface commands\n"
6958 "Message digest authentication password (key)\n"
6959 "Key ID\n"
6960 "Use MD5 algorithm\n"
0d829fa7
QY
6961 "The OSPF password (key)\n"
6962 "Address of interface\n")
7a7be519 6963{
d62a17ae 6964 return ip_ospf_message_digest_key(self, vty, argc, argv);
7a7be519 6965}
718e3744 6966
537eae3f
QY
6967DEFUN (no_ip_ospf_message_digest_key,
6968 no_ip_ospf_message_digest_key_cmd,
0d829fa7 6969 "no ip ospf message-digest-key (1-255) [md5 KEY] [A.B.C.D]",
813d4307
DW
6970 NO_STR
6971 "IP Information\n"
6972 "OSPF interface commands\n"
6973 "Message digest authentication password (key)\n"
6974 "Key ID\n"
6975 "Use MD5 algorithm\n"
0d829fa7
QY
6976 "The OSPF password (key)\n"
6977 "Address of interface\n")
813d4307 6978{
d62a17ae 6979 VTY_DECLVAR_CONTEXT(interface, ifp);
6980 int idx = 0;
6981 struct crypt_key *ck;
6982 int key_id;
6983 struct in_addr addr;
6984 struct ospf_if_params *params;
6985 params = IF_DEF_PARAMS(ifp);
6986
6987 argv_find(argv, argc, "(1-255)", &idx);
6988 char *keyid = argv[idx]->arg;
6989
6990 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
6991 if (!inet_aton(argv[idx]->arg, &addr)) {
6992 vty_out(vty,
6993 "Please specify interface address by A.B.C.D\n");
6994 return CMD_WARNING_CONFIG_FAILED;
6995 }
7a7be519 6996
d62a17ae 6997 params = ospf_lookup_if_params(ifp, addr);
6998 if (params == NULL)
6999 return CMD_SUCCESS;
7a7be519 7000 }
7001
d62a17ae 7002 key_id = strtol(keyid, NULL, 10);
7003 ck = ospf_crypt_key_lookup(params->auth_crypt, key_id);
7004 if (ck == NULL) {
7005 vty_out(vty, "OSPF: Key %d does not exist\n", key_id);
7006 return CMD_WARNING_CONFIG_FAILED;
7007 }
7a7be519 7008
d62a17ae 7009 ospf_crypt_key_delete(params->auth_crypt, key_id);
7a7be519 7010
d62a17ae 7011 if (params != IF_DEF_PARAMS(ifp)) {
7012 ospf_free_if_params(ifp, addr);
7013 ospf_if_update_params(ifp, addr);
7014 }
7a7be519 7015
d62a17ae 7016 return CMD_SUCCESS;
7a7be519 7017}
813d4307 7018
0d829fa7 7019DEFUN_HIDDEN (no_ospf_message_digest_key,
537eae3f 7020 no_ospf_message_digest_key_cmd,
0d829fa7
QY
7021 "no ospf message-digest-key (1-255) [md5 KEY] [A.B.C.D]",
7022 NO_STR
7023 "OSPF interface commands\n"
7024 "Message digest authentication password (key)\n"
7025 "Key ID\n"
efd7904e
RW
7026 "Use MD5 algorithm\n"
7027 "The OSPF password (key)\n"
7028 "Address of interface\n")
718e3744 7029{
d62a17ae 7030 return no_ip_ospf_message_digest_key(self, vty, argc, argv);
718e3744 7031}
7032
718e3744 7033DEFUN (ip_ospf_cost,
5c2fc921 7034 ip_ospf_cost_cmd,
7a7be519 7035 "ip ospf cost (1-65535) [A.B.C.D]",
718e3744 7036 "IP Information\n"
7037 "OSPF interface commands\n"
7038 "Interface cost\n"
7039 "Cost\n"
5c2fc921 7040 "Address of interface\n")
718e3744 7041{
d62a17ae 7042 VTY_DECLVAR_CONTEXT(interface, ifp);
7043 int idx = 0;
d7c0a89a 7044 uint32_t cost = OSPF_OUTPUT_COST_DEFAULT;
d62a17ae 7045 struct in_addr addr;
7046 struct ospf_if_params *params;
7047 params = IF_DEF_PARAMS(ifp);
7048
7049 // get arguments
7050 char *coststr = NULL, *ifaddr = NULL;
35955c14 7051
c31a793b
VJ
7052 argv_find(argv, argc, "(1-65535)", &idx);
7053 coststr = argv[idx]->arg;
d62a17ae 7054 cost = strtol(coststr, NULL, 10);
7055
c31a793b 7056 ifaddr = argv_find(argv, argc, "A.B.C.D", &idx) ? argv[idx]->arg : NULL;
d62a17ae 7057 if (ifaddr) {
7058 if (!inet_aton(ifaddr, &addr)) {
7059 vty_out(vty,
7060 "Please specify interface address by A.B.C.D\n");
7061 return CMD_WARNING_CONFIG_FAILED;
7062 }
718e3744 7063
d62a17ae 7064 params = ospf_get_if_params(ifp, addr);
7065 ospf_if_update_params(ifp, addr);
718e3744 7066 }
7067
d62a17ae 7068 SET_IF_PARAM(params, output_cost_cmd);
7069 params->output_cost_cmd = cost;
718e3744 7070
d62a17ae 7071 ospf_if_recalculate_output_cost(ifp);
5c2fc921 7072
d62a17ae 7073 return CMD_SUCCESS;
718e3744 7074}
7075
7a7be519 7076DEFUN_HIDDEN (ospf_cost,
5c2fc921
QY
7077 ospf_cost_cmd,
7078 "ospf cost (1-65535) [A.B.C.D]",
747e489c
DW
7079 "OSPF interface commands\n"
7080 "Interface cost\n"
7081 "Cost\n"
5c2fc921 7082 "Address of interface\n")
7a7be519 7083{
d62a17ae 7084 return ip_ospf_cost(self, vty, argc, argv);
7a7be519 7085}
9eff36b3 7086
718e3744 7087DEFUN (no_ip_ospf_cost,
5c2fc921
QY
7088 no_ip_ospf_cost_cmd,
7089 "no ip ospf cost [(1-65535)] [A.B.C.D]",
718e3744 7090 NO_STR
efd7904e 7091 "IP Information\n"
718e3744 7092 "OSPF interface commands\n"
7093 "Interface cost\n"
efd7904e
RW
7094 "Cost\n"
7095 "Address of interface\n")
718e3744 7096{
d62a17ae 7097 VTY_DECLVAR_CONTEXT(interface, ifp);
7098 int idx = 0;
7099 struct in_addr addr;
7100 struct ospf_if_params *params;
7a7be519 7101
d62a17ae 7102 params = IF_DEF_PARAMS(ifp);
718e3744 7103
d62a17ae 7104 // get arguments
7105 char *ifaddr = NULL;
7106 ifaddr = argv_find(argv, argc, "A.B.C.D", &idx) ? argv[idx]->arg : NULL;
718e3744 7107
d62a17ae 7108 /* According to the semantics we are mimicking "no ip ospf cost N" is
7109 * always treated as "no ip ospf cost" regardless of the actual value
7110 * of N already configured for the interface. Thus ignore cost. */
7a7be519 7111
d62a17ae 7112 if (ifaddr) {
7113 if (!inet_aton(ifaddr, &addr)) {
7114 vty_out(vty,
7115 "Please specify interface address by A.B.C.D\n");
7116 return CMD_WARNING_CONFIG_FAILED;
7117 }
7a7be519 7118
d62a17ae 7119 params = ospf_lookup_if_params(ifp, addr);
7120 if (params == NULL)
7121 return CMD_SUCCESS;
7122 }
7a7be519 7123
d62a17ae 7124 UNSET_IF_PARAM(params, output_cost_cmd);
7a7be519 7125
d62a17ae 7126 if (params != IF_DEF_PARAMS(ifp)) {
7127 ospf_free_if_params(ifp, addr);
7128 ospf_if_update_params(ifp, addr);
7129 }
7a7be519 7130
d62a17ae 7131 ospf_if_recalculate_output_cost(ifp);
7a7be519 7132
d62a17ae 7133 return CMD_SUCCESS;
7a7be519 7134}
9eff36b3 7135
5c2fc921
QY
7136DEFUN_HIDDEN (no_ospf_cost,
7137 no_ospf_cost_cmd,
7138 "no ospf cost [(1-65535)] [A.B.C.D]",
7139 NO_STR
7140 "OSPF interface commands\n"
7141 "Interface cost\n"
7142 "Cost\n"
7143 "Address of interface\n")
827341b7 7144{
d62a17ae 7145 return no_ip_ospf_cost(self, vty, argc, argv);
827341b7
DO
7146}
7147
d62a17ae 7148static void ospf_nbr_timer_update(struct ospf_interface *oi)
718e3744 7149{
d62a17ae 7150 struct route_node *rn;
7151 struct ospf_neighbor *nbr;
718e3744 7152
d62a17ae 7153 for (rn = route_top(oi->nbrs); rn; rn = route_next(rn))
7154 if ((nbr = rn->info)) {
7155 nbr->v_inactivity = OSPF_IF_PARAM(oi, v_wait);
7156 nbr->v_db_desc = OSPF_IF_PARAM(oi, retransmit_interval);
7157 nbr->v_ls_req = OSPF_IF_PARAM(oi, retransmit_interval);
7158 nbr->v_ls_upd = OSPF_IF_PARAM(oi, retransmit_interval);
7159 }
718e3744 7160}
7161
d62a17ae 7162static int ospf_vty_dead_interval_set(struct vty *vty, const char *interval_str,
7163 const char *nbr_str,
7164 const char *fast_hello_str)
7165{
7166 VTY_DECLVAR_CONTEXT(interface, ifp);
d7c0a89a
QY
7167 uint32_t seconds;
7168 uint8_t hellomult;
d62a17ae 7169 struct in_addr addr;
7170 int ret;
7171 struct ospf_if_params *params;
7172 struct ospf_interface *oi;
7173 struct route_node *rn;
718e3744 7174
d62a17ae 7175 params = IF_DEF_PARAMS(ifp);
7176
7177 if (nbr_str) {
7178 ret = inet_aton(nbr_str, &addr);
7179 if (!ret) {
7180 vty_out(vty,
7181 "Please specify interface address by A.B.C.D\n");
7182 return CMD_WARNING_CONFIG_FAILED;
7183 }
7184
7185 params = ospf_get_if_params(ifp, addr);
7186 ospf_if_update_params(ifp, addr);
7187 }
7188
7189 if (interval_str) {
7190 seconds = strtoul(interval_str, NULL, 10);
7191
7192 /* reset fast_hello too, just to be sure */
7193 UNSET_IF_PARAM(params, fast_hello);
7194 params->fast_hello = OSPF_FAST_HELLO_DEFAULT;
7195 } else if (fast_hello_str) {
7196 hellomult = strtoul(fast_hello_str, NULL, 10);
7197 /* 1s dead-interval with sub-second hellos desired */
7198 seconds = OSPF_ROUTER_DEAD_INTERVAL_MINIMAL;
7199 SET_IF_PARAM(params, fast_hello);
7200 params->fast_hello = hellomult;
7201 } else {
7202 vty_out(vty,
7203 "Please specify dead-interval or hello-multiplier\n");
7204 return CMD_WARNING_CONFIG_FAILED;
7205 }
7206
7207 SET_IF_PARAM(params, v_wait);
7208 params->v_wait = seconds;
7209
7210 /* Update timer values in neighbor structure. */
7211 if (nbr_str) {
b5a8894d
CS
7212 struct ospf *ospf = NULL;
7213
7214 ospf = ospf_lookup_by_vrf_id(ifp->vrf_id);
7215 if (ospf) {
d62a17ae 7216 oi = ospf_if_lookup_by_local_addr(ospf, ifp, addr);
7217 if (oi)
7218 ospf_nbr_timer_update(oi);
7219 }
7220 } else {
7221 for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn))
7222 if ((oi = rn->info))
7223 ospf_nbr_timer_update(oi);
7224 }
7225
7226 return CMD_SUCCESS;
718e3744 7227}
7228
f9ad937f 7229DEFUN (ip_ospf_dead_interval,
0d829fa7 7230 ip_ospf_dead_interval_cmd,
7a7be519 7231 "ip ospf dead-interval (1-65535) [A.B.C.D]",
f9ad937f 7232 "IP Information\n"
7233 "OSPF interface commands\n"
99a522c7 7234 "Interval time after which a neighbor is declared down\n"
f9ad937f 7235 "Seconds\n"
7236 "Address of interface\n")
7237{
d62a17ae 7238 int idx = 0;
7239 char *interval = argv_find(argv, argc, "(1-65535)", &idx)
7240 ? argv[idx]->arg
7241 : NULL;
7242 char *ifaddr =
7243 argv_find(argv, argc, "A.B.C.D", &idx) ? argv[idx]->arg : NULL;
7244 return ospf_vty_dead_interval_set(vty, interval, ifaddr, NULL);
f9ad937f 7245}
7246
718e3744 7247
7a7be519 7248DEFUN_HIDDEN (ospf_dead_interval,
747e489c 7249 ospf_dead_interval_cmd,
0d829fa7 7250 "ospf dead-interval (1-65535) [A.B.C.D]",
747e489c 7251 "OSPF interface commands\n"
99a522c7 7252 "Interval time after which a neighbor is declared down\n"
0d829fa7
QY
7253 "Seconds\n"
7254 "Address of interface\n")
7a7be519 7255{
d62a17ae 7256 return ip_ospf_dead_interval(self, vty, argc, argv);
7a7be519 7257}
718e3744 7258
f9ad937f 7259DEFUN (ip_ospf_dead_interval_minimal,
7260 ip_ospf_dead_interval_minimal_addr_cmd,
7a7be519 7261 "ip ospf dead-interval minimal hello-multiplier (1-10) [A.B.C.D]",
f9ad937f 7262 "IP Information\n"
7263 "OSPF interface commands\n"
99a522c7 7264 "Interval time after which a neighbor is declared down\n"
f9ad937f 7265 "Minimal 1s dead-interval with fast sub-second hellos\n"
7266 "Hello multiplier factor\n"
7267 "Number of Hellos to send each second\n"
7268 "Address of interface\n")
7269{
d62a17ae 7270 int idx_number = 5;
7271 int idx_ipv4 = 6;
7272 if (argc == 7)
7273 return ospf_vty_dead_interval_set(
7274 vty, NULL, argv[idx_ipv4]->arg, argv[idx_number]->arg);
7275 else
7276 return ospf_vty_dead_interval_set(vty, NULL, NULL,
7277 argv[idx_number]->arg);
f9ad937f 7278}
7279
718e3744 7280DEFUN (no_ip_ospf_dead_interval,
0d829fa7 7281 no_ip_ospf_dead_interval_cmd,
e83a9414 7282 "no ip ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]",
718e3744 7283 NO_STR
7284 "IP Information\n"
7285 "OSPF interface commands\n"
99a522c7 7286 "Interval time after which a neighbor is declared down\n"
f9dfba8d 7287 "Seconds\n"
efd7904e
RW
7288 "Minimal 1s dead-interval with fast sub-second hellos\n"
7289 "Hello multiplier factor\n"
7290 "Number of Hellos to send each second\n"
7291 "Address of interface\n")
718e3744 7292{
d62a17ae 7293 VTY_DECLVAR_CONTEXT(interface, ifp);
7294 int idx_ipv4 = argc - 1;
7295 struct in_addr addr = {.s_addr = 0L};
7296 int ret;
7297 struct ospf_if_params *params;
7298 struct ospf_interface *oi;
7299 struct route_node *rn;
7300
7301 params = IF_DEF_PARAMS(ifp);
7302
7303 if (argv[idx_ipv4]->type == IPV4_TKN) {
7304 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
7305 if (!ret) {
7306 vty_out(vty,
7307 "Please specify interface address by A.B.C.D\n");
7308 return CMD_WARNING_CONFIG_FAILED;
7309 }
020709f9 7310
d62a17ae 7311 params = ospf_lookup_if_params(ifp, addr);
7312 if (params == NULL)
7313 return CMD_SUCCESS;
7314 }
718e3744 7315
d62a17ae 7316 UNSET_IF_PARAM(params, v_wait);
7317 params->v_wait = OSPF_ROUTER_DEAD_INTERVAL_DEFAULT;
7318
7319 UNSET_IF_PARAM(params, fast_hello);
7320 params->fast_hello = OSPF_FAST_HELLO_DEFAULT;
7321
7322 if (params != IF_DEF_PARAMS(ifp)) {
7323 ospf_free_if_params(ifp, addr);
7324 ospf_if_update_params(ifp, addr);
718e3744 7325 }
7326
d62a17ae 7327 /* Update timer values in neighbor structure. */
7328 if (argc == 1) {
b5a8894d 7329 struct ospf *ospf = NULL;
718e3744 7330
b5a8894d
CS
7331 ospf = ospf_lookup_by_vrf_id(ifp->vrf_id);
7332 if (ospf) {
d62a17ae 7333 oi = ospf_if_lookup_by_local_addr(ospf, ifp, addr);
7334 if (oi)
7335 ospf_nbr_timer_update(oi);
7336 }
7337 } else {
7338 for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn))
7339 if ((oi = rn->info))
7340 ospf_nbr_timer_update(oi);
7341 }
7342
7343 return CMD_SUCCESS;
718e3744 7344}
7345
0d829fa7
QY
7346DEFUN_HIDDEN (no_ospf_dead_interval,
7347 no_ospf_dead_interval_cmd,
7348 "no ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]",
7349 NO_STR
7350 "OSPF interface commands\n"
99a522c7 7351 "Interval time after which a neighbor is declared down\n"
0d829fa7 7352 "Seconds\n"
efd7904e
RW
7353 "Minimal 1s dead-interval with fast sub-second hellos\n"
7354 "Hello multiplier factor\n"
7355 "Number of Hellos to send each second\n"
7356 "Address of interface\n")
0d829fa7 7357{
d62a17ae 7358 return no_ip_ospf_dead_interval(self, vty, argc, argv);
0d829fa7
QY
7359}
7360
718e3744 7361DEFUN (ip_ospf_hello_interval,
0d829fa7 7362 ip_ospf_hello_interval_cmd,
7a7be519 7363 "ip ospf hello-interval (1-65535) [A.B.C.D]",
718e3744 7364 "IP Information\n"
7365 "OSPF interface commands\n"
7366 "Time between HELLO packets\n"
7367 "Seconds\n"
0d829fa7 7368 "Address of interface\n")
718e3744 7369{
d62a17ae 7370 VTY_DECLVAR_CONTEXT(interface, ifp);
7371 int idx = 0;
7372 struct in_addr addr;
7373 struct ospf_if_params *params;
7374 params = IF_DEF_PARAMS(ifp);
d7c0a89a 7375 uint32_t seconds = 0;
d62a17ae 7376
7377 argv_find(argv, argc, "(1-65535)", &idx);
7378 seconds = strtol(argv[idx]->arg, NULL, 10);
7379
7380 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
7381 if (!inet_aton(argv[idx]->arg, &addr)) {
7382 vty_out(vty,
7383 "Please specify interface address by A.B.C.D\n");
7384 return CMD_WARNING_CONFIG_FAILED;
7385 }
718e3744 7386
d62a17ae 7387 params = ospf_get_if_params(ifp, addr);
7388 ospf_if_update_params(ifp, addr);
7389 }
718e3744 7390
d62a17ae 7391 SET_IF_PARAM(params, v_hello);
7392 params->v_hello = seconds;
718e3744 7393
d62a17ae 7394 return CMD_SUCCESS;
718e3744 7395}
7396
7a7be519 7397DEFUN_HIDDEN (ospf_hello_interval,
747e489c 7398 ospf_hello_interval_cmd,
0d829fa7 7399 "ospf hello-interval (1-65535) [A.B.C.D]",
747e489c
DW
7400 "OSPF interface commands\n"
7401 "Time between HELLO packets\n"
0d829fa7
QY
7402 "Seconds\n"
7403 "Address of interface\n")
7a7be519 7404{
d62a17ae 7405 return ip_ospf_hello_interval(self, vty, argc, argv);
7a7be519 7406}
718e3744 7407
7408DEFUN (no_ip_ospf_hello_interval,
0d829fa7
QY
7409 no_ip_ospf_hello_interval_cmd,
7410 "no ip ospf hello-interval [(1-65535) [A.B.C.D]]",
718e3744 7411 NO_STR
7412 "IP Information\n"
7413 "OSPF interface commands\n"
0d829fa7 7414 "Time between HELLO packets\n" // ignored
f9dfba8d 7415 "Seconds\n"
0d829fa7 7416 "Address of interface\n")
718e3744 7417{
d62a17ae 7418 VTY_DECLVAR_CONTEXT(interface, ifp);
7419 int idx = 0;
7420 struct in_addr addr;
7421 struct ospf_if_params *params;
df581cd3 7422
d62a17ae 7423 params = IF_DEF_PARAMS(ifp);
718e3744 7424
d62a17ae 7425 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
7426 if (!inet_aton(argv[idx]->arg, &addr)) {
7427 vty_out(vty,
7428 "Please specify interface address by A.B.C.D\n");
7429 return CMD_WARNING_CONFIG_FAILED;
7430 }
718e3744 7431
d62a17ae 7432 params = ospf_lookup_if_params(ifp, addr);
7433 if (params == NULL)
7434 return CMD_SUCCESS;
7435 }
718e3744 7436
d62a17ae 7437 UNSET_IF_PARAM(params, v_hello);
7438 params->v_hello = OSPF_HELLO_INTERVAL_DEFAULT;
718e3744 7439
d62a17ae 7440 if (params != IF_DEF_PARAMS(ifp)) {
7441 ospf_free_if_params(ifp, addr);
7442 ospf_if_update_params(ifp, addr);
7443 }
718e3744 7444
d62a17ae 7445 return CMD_SUCCESS;
718e3744 7446}
7447
0d829fa7
QY
7448DEFUN_HIDDEN (no_ospf_hello_interval,
7449 no_ospf_hello_interval_cmd,
7450 "no ospf hello-interval [(1-65535) [A.B.C.D]]",
7451 NO_STR
7452 "OSPF interface commands\n"
7453 "Time between HELLO packets\n" // ignored
7454 "Seconds\n"
7455 "Address of interface\n")
7456{
d62a17ae 7457 return no_ip_ospf_hello_interval(self, vty, argc, argv);
0d829fa7 7458}
718e3744 7459
7460DEFUN (ip_ospf_network,
7461 ip_ospf_network_cmd,
6147e2c6 7462 "ip ospf network <broadcast|non-broadcast|point-to-multipoint|point-to-point>",
718e3744 7463 "IP Information\n"
7464 "OSPF interface commands\n"
7465 "Network type\n"
7466 "Specify OSPF broadcast multi-access network\n"
7467 "Specify OSPF NBMA network\n"
7468 "Specify OSPF point-to-multipoint network\n"
7469 "Specify OSPF point-to-point network\n")
7470{
d62a17ae 7471 VTY_DECLVAR_CONTEXT(interface, ifp);
7472 int idx = 0;
7473 int old_type = IF_DEF_PARAMS(ifp)->type;
7474 struct route_node *rn;
718e3744 7475
d62a17ae 7476 if (old_type == OSPF_IFTYPE_LOOPBACK) {
7477 vty_out(vty,
7478 "This is a loopback interface. Can't set network type.\n");
7479 return CMD_WARNING_CONFIG_FAILED;
7480 }
718e3744 7481
d62a17ae 7482 if (argv_find(argv, argc, "broadcast", &idx))
7483 IF_DEF_PARAMS(ifp)->type = OSPF_IFTYPE_BROADCAST;
7484 else if (argv_find(argv, argc, "non-broadcast", &idx))
7485 IF_DEF_PARAMS(ifp)->type = OSPF_IFTYPE_NBMA;
7486 else if (argv_find(argv, argc, "point-to-multipoint", &idx))
7487 IF_DEF_PARAMS(ifp)->type = OSPF_IFTYPE_POINTOMULTIPOINT;
7488 else if (argv_find(argv, argc, "point-to-point", &idx))
7489 IF_DEF_PARAMS(ifp)->type = OSPF_IFTYPE_POINTOPOINT;
718e3744 7490
d62a17ae 7491 if (IF_DEF_PARAMS(ifp)->type == old_type)
7492 return CMD_SUCCESS;
7493
7494 SET_IF_PARAM(IF_DEF_PARAMS(ifp), type);
7495
7496 for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) {
7497 struct ospf_interface *oi = rn->info;
7498
7499 if (!oi)
7500 continue;
7501
7502 oi->type = IF_DEF_PARAMS(ifp)->type;
7503
7504 if (oi->state > ISM_Down) {
7505 OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceDown);
7506 OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceUp);
7507 }
7a7be519 7508 }
7a7be519 7509
d62a17ae 7510 return CMD_SUCCESS;
7a7be519 7511}
7512
7513DEFUN_HIDDEN (ospf_network,
7514 ospf_network_cmd,
e83a9414 7515 "ospf network <broadcast|non-broadcast|point-to-multipoint|point-to-point>",
7a7be519 7516 "OSPF interface commands\n"
7517 "Network type\n"
7518 "Specify OSPF broadcast multi-access network\n"
7519 "Specify OSPF NBMA network\n"
7520 "Specify OSPF point-to-multipoint network\n"
7521 "Specify OSPF point-to-point network\n")
7522{
d62a17ae 7523 return ip_ospf_network(self, vty, argc, argv);
7a7be519 7524}
7525
7526DEFUN (no_ip_ospf_network,
7527 no_ip_ospf_network_cmd,
7528 "no ip ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]",
7529 NO_STR
7530 "IP Information\n"
7531 "OSPF interface commands\n"
7532 "Network type\n"
7533 "Specify OSPF broadcast multi-access network\n"
7534 "Specify OSPF NBMA network\n"
7535 "Specify OSPF point-to-multipoint network\n"
7536 "Specify OSPF point-to-point network\n")
22b27e95 7537{
d62a17ae 7538 VTY_DECLVAR_CONTEXT(interface, ifp);
7539 int old_type = IF_DEF_PARAMS(ifp)->type;
7540 struct route_node *rn;
7a7be519 7541
d62a17ae 7542 IF_DEF_PARAMS(ifp)->type = ospf_default_iftype(ifp);
7a7be519 7543
d62a17ae 7544 if (IF_DEF_PARAMS(ifp)->type == old_type)
7545 return CMD_SUCCESS;
7a7be519 7546
d62a17ae 7547 for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) {
7548 struct ospf_interface *oi = rn->info;
7a7be519 7549
d62a17ae 7550 if (!oi)
7551 continue;
7a7be519 7552
d62a17ae 7553 oi->type = IF_DEF_PARAMS(ifp)->type;
7a7be519 7554
d62a17ae 7555 if (oi->state > ISM_Down) {
7556 OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceDown);
7557 OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceUp);
7558 }
7a7be519 7559 }
7a7be519 7560
d62a17ae 7561 return CMD_SUCCESS;
7a7be519 7562}
7563
0d829fa7
QY
7564DEFUN_HIDDEN (no_ospf_network,
7565 no_ospf_network_cmd,
7566 "no ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]",
7567 NO_STR
7568 "OSPF interface commands\n"
7569 "Network type\n"
7570 "Specify OSPF broadcast multi-access network\n"
7571 "Specify OSPF NBMA network\n"
7572 "Specify OSPF point-to-multipoint network\n"
7573 "Specify OSPF point-to-point network\n")
7574{
d62a17ae 7575 return no_ip_ospf_network(self, vty, argc, argv);
0d829fa7
QY
7576}
7577
7a7be519 7578DEFUN (ip_ospf_priority,
537eae3f 7579 ip_ospf_priority_cmd,
7a7be519 7580 "ip ospf priority (0-255) [A.B.C.D]",
7581 "IP Information\n"
7582 "OSPF interface commands\n"
7583 "Router priority\n"
7584 "Priority\n"
efd7904e 7585 "Address of interface\n")
7a7be519 7586{
d62a17ae 7587 VTY_DECLVAR_CONTEXT(interface, ifp);
7588 int idx = 0;
7589 long priority;
7590 struct route_node *rn;
7591 struct in_addr addr;
7592 struct ospf_if_params *params;
7593 params = IF_DEF_PARAMS(ifp);
7594
7595 argv_find(argv, argc, "(0-255)", &idx);
7596 priority = strtol(argv[idx]->arg, NULL, 10);
7597
7598 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
7599 if (!inet_aton(argv[idx]->arg, &addr)) {
7600 vty_out(vty,
7601 "Please specify interface address by A.B.C.D\n");
7602 return CMD_WARNING_CONFIG_FAILED;
7603 }
7a7be519 7604
d62a17ae 7605 params = ospf_get_if_params(ifp, addr);
7606 ospf_if_update_params(ifp, addr);
7a7be519 7607 }
7608
d62a17ae 7609 SET_IF_PARAM(params, priority);
7610 params->priority = priority;
7a7be519 7611
d62a17ae 7612 for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) {
7613 struct ospf_interface *oi = rn->info;
7a7be519 7614
d62a17ae 7615 if (!oi)
7616 continue;
7a7be519 7617
d62a17ae 7618 if (PRIORITY(oi) != OSPF_IF_PARAM(oi, priority)) {
7619 PRIORITY(oi) = OSPF_IF_PARAM(oi, priority);
7620 OSPF_ISM_EVENT_SCHEDULE(oi, ISM_NeighborChange);
7621 }
718e3744 7622 }
718e3744 7623
d62a17ae 7624 return CMD_SUCCESS;
718e3744 7625}
7626
7a7be519 7627DEFUN_HIDDEN (ospf_priority,
7628 ospf_priority_cmd,
0d829fa7 7629 "ospf priority (0-255) [A.B.C.D]",
7a7be519 7630 "OSPF interface commands\n"
7631 "Router priority\n"
3a2d747c 7632 "Priority\n"
efd7904e 7633 "Address of interface\n")
718e3744 7634{
d62a17ae 7635 return ip_ospf_priority(self, vty, argc, argv);
718e3744 7636}
7637
718e3744 7638DEFUN (no_ip_ospf_priority,
537eae3f 7639 no_ip_ospf_priority_cmd,
7a7be519 7640 "no ip ospf priority [(0-255) [A.B.C.D]]",
718e3744 7641 NO_STR
7642 "IP Information\n"
7643 "OSPF interface commands\n"
0d829fa7 7644 "Router priority\n" // ignored
813d4307 7645 "Priority\n"
efd7904e 7646 "Address of interface\n")
718e3744 7647{
d62a17ae 7648 VTY_DECLVAR_CONTEXT(interface, ifp);
7649 int idx = 0;
7650 struct route_node *rn;
7651 struct in_addr addr;
7652 struct ospf_if_params *params;
7653
7654 params = IF_DEF_PARAMS(ifp);
7655
7656 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
7657 if (!inet_aton(argv[idx]->arg, &addr)) {
7658 vty_out(vty,
7659 "Please specify interface address by A.B.C.D\n");
7660 return CMD_WARNING_CONFIG_FAILED;
7661 }
7662
7663 params = ospf_lookup_if_params(ifp, addr);
7664 if (params == NULL)
7665 return CMD_SUCCESS;
718e3744 7666 }
7667
d62a17ae 7668 UNSET_IF_PARAM(params, priority);
7669 params->priority = OSPF_ROUTER_PRIORITY_DEFAULT;
7670
7671 if (params != IF_DEF_PARAMS(ifp)) {
7672 ospf_free_if_params(ifp, addr);
7673 ospf_if_update_params(ifp, addr);
718e3744 7674 }
d62a17ae 7675
7676 for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) {
7677 struct ospf_interface *oi = rn->info;
7678
7679 if (!oi)
7680 continue;
7681
7682 if (PRIORITY(oi) != OSPF_IF_PARAM(oi, priority)) {
7683 PRIORITY(oi) = OSPF_IF_PARAM(oi, priority);
7684 OSPF_ISM_EVENT_SCHEDULE(oi, ISM_NeighborChange);
7685 }
7686 }
7687
7688 return CMD_SUCCESS;
718e3744 7689}
7690
0d829fa7 7691DEFUN_HIDDEN (no_ospf_priority,
537eae3f 7692 no_ospf_priority_cmd,
0d829fa7
QY
7693 "no ospf priority [(0-255) [A.B.C.D]]",
7694 NO_STR
7695 "OSPF interface commands\n"
7696 "Router priority\n"
7697 "Priority\n"
efd7904e 7698 "Address of interface\n")
0d829fa7 7699{
d62a17ae 7700 return no_ip_ospf_priority(self, vty, argc, argv);
0d829fa7 7701}
a1afa410 7702
718e3744 7703DEFUN (ip_ospf_retransmit_interval,
7704 ip_ospf_retransmit_interval_addr_cmd,
7a7be519 7705 "ip ospf retransmit-interval (3-65535) [A.B.C.D]",
718e3744 7706 "IP Information\n"
7707 "OSPF interface commands\n"
7708 "Time between retransmitting lost link state advertisements\n"
7709 "Seconds\n"
efd7904e 7710 "Address of interface\n")
718e3744 7711{
d62a17ae 7712 VTY_DECLVAR_CONTEXT(interface, ifp);
7713 int idx = 0;
d7c0a89a 7714 uint32_t seconds;
d62a17ae 7715 struct in_addr addr;
7716 struct ospf_if_params *params;
7717 params = IF_DEF_PARAMS(ifp);
7718
7719 argv_find(argv, argc, "(3-65535)", &idx);
7720 seconds = strtol(argv[idx]->arg, NULL, 10);
7721
7722 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
7723 if (!inet_aton(argv[idx]->arg, &addr)) {
7724 vty_out(vty,
7725 "Please specify interface address by A.B.C.D\n");
7726 return CMD_WARNING_CONFIG_FAILED;
7727 }
718e3744 7728
d62a17ae 7729 params = ospf_get_if_params(ifp, addr);
7730 ospf_if_update_params(ifp, addr);
718e3744 7731 }
7732
d62a17ae 7733 SET_IF_PARAM(params, retransmit_interval);
7734 params->retransmit_interval = seconds;
718e3744 7735
d62a17ae 7736 return CMD_SUCCESS;
718e3744 7737}
7738
7a7be519 7739DEFUN_HIDDEN (ospf_retransmit_interval,
747e489c 7740 ospf_retransmit_interval_cmd,
0d829fa7 7741 "ospf retransmit-interval (3-65535) [A.B.C.D]",
747e489c
DW
7742 "OSPF interface commands\n"
7743 "Time between retransmitting lost link state advertisements\n"
3a2d747c 7744 "Seconds\n"
efd7904e 7745 "Address of interface\n")
7a7be519 7746{
d62a17ae 7747 return ip_ospf_retransmit_interval(self, vty, argc, argv);
7a7be519 7748}
718e3744 7749
7750DEFUN (no_ip_ospf_retransmit_interval,
7751 no_ip_ospf_retransmit_interval_addr_cmd,
0d829fa7 7752 "no ip ospf retransmit-interval [(3-65535)] [A.B.C.D]",
718e3744 7753 NO_STR
7754 "IP Information\n"
7755 "OSPF interface commands\n"
3a2d747c
QY
7756 "Time between retransmitting lost link state advertisements\n"
7757 "Seconds\n"
0d829fa7 7758 "Address of interface\n")
718e3744 7759{
d62a17ae 7760 VTY_DECLVAR_CONTEXT(interface, ifp);
7761 int idx = 0;
7762 struct in_addr addr;
7763 struct ospf_if_params *params;
47b91972 7764
d62a17ae 7765 params = IF_DEF_PARAMS(ifp);
718e3744 7766
d62a17ae 7767 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
7768 if (!inet_aton(argv[idx]->arg, &addr)) {
7769 vty_out(vty,
7770 "Please specify interface address by A.B.C.D\n");
7771 return CMD_WARNING_CONFIG_FAILED;
7772 }
718e3744 7773
d62a17ae 7774 params = ospf_lookup_if_params(ifp, addr);
7775 if (params == NULL)
7776 return CMD_SUCCESS;
7777 }
718e3744 7778
d62a17ae 7779 UNSET_IF_PARAM(params, retransmit_interval);
7780 params->retransmit_interval = OSPF_RETRANSMIT_INTERVAL_DEFAULT;
718e3744 7781
d62a17ae 7782 if (params != IF_DEF_PARAMS(ifp)) {
7783 ospf_free_if_params(ifp, addr);
7784 ospf_if_update_params(ifp, addr);
7785 }
718e3744 7786
d62a17ae 7787 return CMD_SUCCESS;
718e3744 7788}
7789
0d829fa7
QY
7790DEFUN_HIDDEN (no_ospf_retransmit_interval,
7791 no_ospf_retransmit_interval_cmd,
7792 "no ospf retransmit-interval [(3-65535)] [A.B.C.D]",
7793 NO_STR
7794 "OSPF interface commands\n"
3a2d747c
QY
7795 "Time between retransmitting lost link state advertisements\n"
7796 "Seconds\n"
7797 "Address of interface\n")
0d829fa7 7798{
d62a17ae 7799 return no_ip_ospf_retransmit_interval(self, vty, argc, argv);
0d829fa7 7800}
813d4307 7801
718e3744 7802DEFUN (ip_ospf_transmit_delay,
7803 ip_ospf_transmit_delay_addr_cmd,
7a7be519 7804 "ip ospf transmit-delay (1-65535) [A.B.C.D]",
718e3744 7805 "IP Information\n"
7806 "OSPF interface commands\n"
7807 "Link state transmit delay\n"
7808 "Seconds\n"
efd7904e 7809 "Address of interface\n")
718e3744 7810{
d62a17ae 7811 VTY_DECLVAR_CONTEXT(interface, ifp);
7812 int idx = 0;
d7c0a89a 7813 uint32_t seconds;
d62a17ae 7814 struct in_addr addr;
7815 struct ospf_if_params *params;
7816
7817 params = IF_DEF_PARAMS(ifp);
7818 argv_find(argv, argc, "(1-65535)", &idx);
7819 seconds = strtol(argv[idx]->arg, NULL, 10);
7820
7821 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
7822 if (!inet_aton(argv[idx]->arg, &addr)) {
7823 vty_out(vty,
7824 "Please specify interface address by A.B.C.D\n");
7825 return CMD_WARNING_CONFIG_FAILED;
7826 }
718e3744 7827
d62a17ae 7828 params = ospf_get_if_params(ifp, addr);
7829 ospf_if_update_params(ifp, addr);
718e3744 7830 }
7831
d62a17ae 7832 SET_IF_PARAM(params, transmit_delay);
7833 params->transmit_delay = seconds;
718e3744 7834
d62a17ae 7835 return CMD_SUCCESS;
718e3744 7836}
7837
7a7be519 7838DEFUN_HIDDEN (ospf_transmit_delay,
747e489c 7839 ospf_transmit_delay_cmd,
0d829fa7 7840 "ospf transmit-delay (1-65535) [A.B.C.D]",
747e489c
DW
7841 "OSPF interface commands\n"
7842 "Link state transmit delay\n"
3a2d747c 7843 "Seconds\n"
efd7904e 7844 "Address of interface\n")
7a7be519 7845{
d62a17ae 7846 return ip_ospf_transmit_delay(self, vty, argc, argv);
7a7be519 7847}
718e3744 7848
7849DEFUN (no_ip_ospf_transmit_delay,
7850 no_ip_ospf_transmit_delay_addr_cmd,
0d829fa7 7851 "no ip ospf transmit-delay [(1-65535)] [A.B.C.D]",
718e3744 7852 NO_STR
7853 "IP Information\n"
7854 "OSPF interface commands\n"
7855 "Link state transmit delay\n"
efd7904e
RW
7856 "Seconds\n"
7857 "Address of interface\n")
718e3744 7858{
d62a17ae 7859 VTY_DECLVAR_CONTEXT(interface, ifp);
7860 int idx = 0;
7861 struct in_addr addr;
7862 struct ospf_if_params *params;
718e3744 7863
d62a17ae 7864 params = IF_DEF_PARAMS(ifp);
718e3744 7865
d62a17ae 7866 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
7867 if (!inet_aton(argv[idx]->arg, &addr)) {
7868 vty_out(vty,
7869 "Please specify interface address by A.B.C.D\n");
7870 return CMD_WARNING_CONFIG_FAILED;
7871 }
718e3744 7872
d62a17ae 7873 params = ospf_lookup_if_params(ifp, addr);
7874 if (params == NULL)
7875 return CMD_SUCCESS;
7876 }
718e3744 7877
d62a17ae 7878 UNSET_IF_PARAM(params, transmit_delay);
7879 params->transmit_delay = OSPF_TRANSMIT_DELAY_DEFAULT;
718e3744 7880
d62a17ae 7881 if (params != IF_DEF_PARAMS(ifp)) {
7882 ospf_free_if_params(ifp, addr);
7883 ospf_if_update_params(ifp, addr);
7884 }
7885
7886 return CMD_SUCCESS;
718e3744 7887}
7888
813d4307 7889
0d829fa7
QY
7890DEFUN_HIDDEN (no_ospf_transmit_delay,
7891 no_ospf_transmit_delay_cmd,
32573073 7892 "no ospf transmit-delay [(1-65535) [A.B.C.D]]",
0d829fa7
QY
7893 NO_STR
7894 "OSPF interface commands\n"
32573073
QY
7895 "Link state transmit delay\n"
7896 "Seconds\n"
efd7904e 7897 "Address of interface\n")
813d4307 7898{
d62a17ae 7899 return no_ip_ospf_transmit_delay(self, vty, argc, argv);
813d4307
DW
7900}
7901
e723861d
DS
7902DEFUN (ip_ospf_area,
7903 ip_ospf_area_cmd,
52c62ab8 7904 "ip ospf [(1-65535)] area <A.B.C.D|(0-4294967295)> [A.B.C.D]",
e723861d
DS
7905 "IP Information\n"
7906 "OSPF interface commands\n"
7a7be519 7907 "Instance ID\n"
e723861d
DS
7908 "Enable OSPF on this interface\n"
7909 "OSPF area ID in IP address format\n"
52c62ab8
JAG
7910 "OSPF area ID as a decimal value\n"
7911 "Address of interface\n")
e723861d 7912{
d62a17ae 7913 VTY_DECLVAR_CONTEXT(interface, ifp);
7914 int idx = 0;
7915 int format, ret;
7916 struct in_addr area_id;
7917 struct in_addr addr;
35955c14 7918 struct ospf_if_params *params = NULL;
d62a17ae 7919 struct route_node *rn;
b5a8894d 7920 struct ospf *ospf = NULL;
d7c0a89a 7921 unsigned short instance = 0;
d62a17ae 7922 char *areaid;
7923
7924 if (argv_find(argv, argc, "(1-65535)", &idx))
7925 instance = strtol(argv[idx]->arg, NULL, 10);
7926
7927 argv_find(argv, argc, "area", &idx);
7928 areaid = argv[idx + 1]->arg;
7929
b5a8894d
CS
7930 if (ifp->vrf_id && !instance)
7931 ospf = ospf_lookup_by_vrf_id(ifp->vrf_id);
7932 else
7933 ospf = ospf_lookup_instance(instance);
7934
aed7cc62 7935 if (instance && ospf == NULL) {
d62a17ae 7936 params = IF_DEF_PARAMS(ifp);
7937 if (OSPF_IF_PARAM_CONFIGURED(params, if_area)) {
7938 UNSET_IF_PARAM(params, if_area);
b5a8894d
CS
7939 ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
7940 ospf_interface_area_unset(ospf, ifp);
d62a17ae 7941 ospf->if_ospf_cli_count--;
7942 }
ac28e4ec 7943 return CMD_NOT_MY_INSTANCE;
d62a17ae 7944 }
e723861d 7945
d62a17ae 7946 ret = str2area_id(areaid, &area_id, &format);
7947 if (ret < 0) {
7948 vty_out(vty, "Please specify area by A.B.C.D|<0-4294967295>\n");
7949 return CMD_WARNING_CONFIG_FAILED;
7950 }
7951 if (memcmp(ifp->name, "VLINK", 5) == 0) {
7952 vty_out(vty, "Cannot enable OSPF on a virtual link.\n");
7953 return CMD_WARNING_CONFIG_FAILED;
7954 }
7955
7956 params = IF_DEF_PARAMS(ifp);
7957 if (OSPF_IF_PARAM_CONFIGURED(params, if_area)
7958 && !IPV4_ADDR_SAME(&params->if_area, &area_id)) {
7959 vty_out(vty,
7960 "Must remove previous area config before changing ospf area \n");
7961 return CMD_WARNING_CONFIG_FAILED;
7962 }
7963
7964 // Check if we have an address arg and proccess it
7965 if (argc == idx + 3) {
cc9b06ad 7966 if (!inet_aton(argv[idx + 2]->arg, &addr)) {
996c9314
LB
7967 vty_out(vty,
7968 "Please specify Intf Address by A.B.C.D\n");
cc9b06ad
DS
7969 return CMD_WARNING_CONFIG_FAILED;
7970 }
d62a17ae 7971 // update/create address-level params
7972 params = ospf_get_if_params((ifp), (addr));
7973 if (OSPF_IF_PARAM_CONFIGURED(params, if_area)) {
7974 vty_out(vty,
7975 "Must remove previous area/address config before changing ospf area");
7976 return CMD_WARNING_CONFIG_FAILED;
7977 }
7978 ospf_if_update_params((ifp), (addr));
7979 }
7980
aed7cc62
CS
7981 if (ospf) {
7982 for (rn = route_top(ospf->networks); rn; rn = route_next(rn)) {
7983 if (rn->info != NULL) {
7984 vty_out(vty,
7985 "Please remove all network commands first.\n");
7986 return CMD_WARNING_CONFIG_FAILED;
7987 }
d62a17ae 7988 }
7989 }
7990
7991 /* enable ospf on this interface with area_id */
35955c14
CS
7992 if (params) {
7993 SET_IF_PARAM(params, if_area);
7994 params->if_area = area_id;
7995 params->if_area_id_fmt = format;
7996 }
aed7cc62
CS
7997
7998 if (ospf) {
7999 ospf_interface_area_set(ospf, ifp);
8000 ospf->if_ospf_cli_count++;
8001 }
d62a17ae 8002
8003 return CMD_SUCCESS;
e723861d
DS
8004}
8005
8006DEFUN (no_ip_ospf_area,
8007 no_ip_ospf_area_cmd,
52c62ab8 8008 "no ip ospf [(1-65535)] area [<A.B.C.D|(0-4294967295)> [A.B.C.D]]",
e723861d
DS
8009 NO_STR
8010 "IP Information\n"
8011 "OSPF interface commands\n"
3a2d747c 8012 "Instance ID\n"
7a7be519 8013 "Disable OSPF on this interface\n"
8014 "OSPF area ID in IP address format\n"
52c62ab8
JAG
8015 "OSPF area ID as a decimal value\n"
8016 "Address of interface\n")
e723861d 8017{
d62a17ae 8018 VTY_DECLVAR_CONTEXT(interface, ifp);
8019 int idx = 0;
8020 struct ospf *ospf;
8021 struct ospf_if_params *params;
d7c0a89a 8022 unsigned short instance = 0;
d62a17ae 8023 struct in_addr addr;
8024
8025 if (argv_find(argv, argc, "(1-65535)", &idx))
8026 instance = strtol(argv[idx]->arg, NULL, 10);
8027
b5a8894d
CS
8028 if (ifp->vrf_id && !instance)
8029 ospf = ospf_lookup_by_vrf_id(ifp->vrf_id);
8030 else
8031 ospf = ospf_lookup_instance(instance);
8032
ac28e4ec
CS
8033 if (ospf == NULL)
8034 return CMD_NOT_MY_INSTANCE;
d62a17ae 8035
8036 argv_find(argv, argc, "area", &idx);
8037
8038 // Check if we have an address arg and proccess it
8039 if (argc == idx + 3) {
cc9b06ad 8040 if (!inet_aton(argv[idx + 2]->arg, &addr)) {
996c9314
LB
8041 vty_out(vty,
8042 "Please specify Intf Address by A.B.C.D\n");
cc9b06ad
DS
8043 return CMD_WARNING_CONFIG_FAILED;
8044 }
d62a17ae 8045 params = ospf_lookup_if_params(ifp, addr);
8046 if ((params) == NULL)
8047 return CMD_SUCCESS;
8048 } else
8049 params = IF_DEF_PARAMS(ifp);
8050
8051 if (!OSPF_IF_PARAM_CONFIGURED(params, if_area)) {
8052 vty_out(vty,
8053 "Can't find specified interface area configuration.\n");
8054 return CMD_WARNING_CONFIG_FAILED;
8055 }
813d4307 8056
d62a17ae 8057 UNSET_IF_PARAM(params, if_area);
8058 if (params != IF_DEF_PARAMS((ifp))) {
8059 ospf_free_if_params((ifp), (addr));
8060 ospf_if_update_params((ifp), (addr));
8061 }
8062
b5a8894d 8063 ospf_interface_area_unset(ospf, ifp);
d62a17ae 8064 ospf->if_ospf_cli_count--;
8065 return CMD_SUCCESS;
813d4307
DW
8066}
8067
6f2a6703
CF
8068DEFUN (ospf_redistribute_source,
8069 ospf_redistribute_source_cmd,
ea38ced1 8070 "redistribute " FRR_REDIST_STR_OSPFD " [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
d1c65c21 8071 REDIST_STR
ab0181ee 8072 FRR_REDIST_HELP_STR_OSPFD
718e3744 8073 "Metric for redistributed routes\n"
8074 "OSPF default metric\n"
8075 "OSPF exterior metric type for redistributed routes\n"
7111c1a0 8076 "Set OSPF External Type 1/2 metrics\n"
718e3744 8077 "Route map reference\n"
8078 "Pointer to route-map entries\n")
8079{
a3d826f0 8080 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
d62a17ae 8081 int idx_protocol = 1;
8082 int source;
8083 int type = -1;
8084 int metric = -1;
8085 struct ospf_redist *red;
8086 int idx = 0;
6f2a6703 8087
d62a17ae 8088 /* Get distribute source. */
8089 source = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
8090 if (source < 0)
8091 return CMD_WARNING_CONFIG_FAILED;
8092
8093 red = ospf_redist_add(ospf, source, 0);
8094
8095 /* Get metric value. */
8096 if (argv_find(argv, argc, "(0-16777214)", &idx)) {
8097 if (!str2metric(argv[idx]->arg, &metric))
8098 return CMD_WARNING_CONFIG_FAILED;
8099 }
951da435 8100 idx = 1;
d62a17ae 8101 /* Get metric type. */
ea38ced1 8102 if (argv_find(argv, argc, "(1-2)", &idx)) {
d62a17ae 8103 if (!str2metric_type(argv[idx]->arg, &type))
8104 return CMD_WARNING_CONFIG_FAILED;
8105 }
951da435 8106 idx = 1;
d62a17ae 8107 /* Get route-map */
ea38ced1 8108 if (argv_find(argv, argc, "WORD", &idx)) {
d62a17ae 8109 ospf_routemap_set(red, argv[idx]->arg);
8110 } else
8111 ospf_routemap_unset(red);
7c8ff89e 8112
d62a17ae 8113 return ospf_redistribute_set(ospf, source, 0, type, metric);
718e3744 8114}
8115
718e3744 8116DEFUN (no_ospf_redistribute_source,
8117 no_ospf_redistribute_source_cmd,
ea38ced1 8118 "no redistribute " FRR_REDIST_STR_OSPFD " [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
718e3744 8119 NO_STR
d1c65c21 8120 REDIST_STR
ab0181ee 8121 FRR_REDIST_HELP_STR_OSPFD
813d4307
DW
8122 "Metric for redistributed routes\n"
8123 "OSPF default metric\n"
8124 "OSPF exterior metric type for redistributed routes\n"
7111c1a0 8125 "Set OSPF External Type 1/2 metrics\n"
813d4307
DW
8126 "Route map reference\n"
8127 "Pointer to route-map entries\n")
718e3744 8128{
a3d826f0 8129 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
d62a17ae 8130 int idx_protocol = 2;
8131 int source;
8132 struct ospf_redist *red;
718e3744 8133
d62a17ae 8134 source = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
8135 if (source < 0)
8136 return CMD_WARNING_CONFIG_FAILED;
718e3744 8137
d62a17ae 8138 red = ospf_redist_lookup(ospf, source, 0);
8139 if (!red)
8140 return CMD_SUCCESS;
7c8ff89e 8141
d62a17ae 8142 ospf_routemap_unset(red);
8143 return ospf_redistribute_unset(ospf, source, 0);
7c8ff89e
DS
8144}
8145
8146DEFUN (ospf_redistribute_instance_source,
8147 ospf_redistribute_instance_source_cmd,
1a5ce38b 8148 "redistribute <ospf|table> (1-65535) [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
7c8ff89e
DS
8149 REDIST_STR
8150 "Open Shortest Path First\n"
2d627ff5
DS
8151 "Non-main Kernel Routing Table\n"
8152 "Instance ID/Table ID\n"
7c8ff89e
DS
8153 "Metric for redistributed routes\n"
8154 "OSPF default metric\n"
8155 "OSPF exterior metric type for redistributed routes\n"
7111c1a0 8156 "Set OSPF External Type 1/2 metrics\n"
7c8ff89e
DS
8157 "Route map reference\n"
8158 "Pointer to route-map entries\n")
8159{
a3d826f0 8160 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
d62a17ae 8161 int idx_ospf_table = 1;
8162 int idx_number = 2;
8163 int idx = 3;
8164 int source;
8165 int type = -1;
8166 int metric = -1;
d7c0a89a 8167 unsigned short instance;
d62a17ae 8168 struct ospf_redist *red;
7c8ff89e 8169
d62a17ae 8170 source = proto_redistnum(AFI_IP, argv[idx_ospf_table]->text);
2d627ff5 8171
13f0e434 8172 if (source < 0) {
8173 vty_out(vty, "Unknown instance redistribution\n");
8174 return CMD_WARNING_CONFIG_FAILED;
8175 }
8176
d62a17ae 8177 instance = strtoul(argv[idx_number]->arg, NULL, 10);
7c8ff89e 8178
d62a17ae 8179 if ((source == ZEBRA_ROUTE_OSPF) && !ospf->instance) {
8180 vty_out(vty,
8181 "Instance redistribution in non-instanced OSPF not allowed\n");
8182 return CMD_WARNING_CONFIG_FAILED;
8183 }
7c8ff89e 8184
d62a17ae 8185 if ((source == ZEBRA_ROUTE_OSPF) && (ospf->instance == instance)) {
8186 vty_out(vty, "Same instance OSPF redistribution not allowed\n");
8187 return CMD_WARNING_CONFIG_FAILED;
8188 }
7c8ff89e 8189
d62a17ae 8190 /* Get metric value. */
8191 if (argv_find(argv, argc, "metric", &idx))
8192 if (!str2metric(argv[idx + 1]->arg, &metric))
8193 return CMD_WARNING_CONFIG_FAILED;
7c8ff89e 8194
d62a17ae 8195 idx = 3;
8196 /* Get metric type. */
8197 if (argv_find(argv, argc, "metric-type", &idx))
8198 if (!str2metric_type(argv[idx + 1]->arg, &type))
8199 return CMD_WARNING_CONFIG_FAILED;
7c8ff89e 8200
d62a17ae 8201 red = ospf_redist_add(ospf, source, instance);
7a7be519 8202
d62a17ae 8203 idx = 3;
8204 if (argv_find(argv, argc, "route-map", &idx))
8205 ospf_routemap_set(red, argv[idx + 1]->arg);
8206 else
8207 ospf_routemap_unset(red);
7c8ff89e 8208
d62a17ae 8209 return ospf_redistribute_set(ospf, source, instance, type, metric);
7c8ff89e
DS
8210}
8211
8212DEFUN (no_ospf_redistribute_instance_source,
8213 no_ospf_redistribute_instance_source_cmd,
1a5ce38b 8214 "no redistribute <ospf|table> (1-65535) [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
7c8ff89e
DS
8215 NO_STR
8216 REDIST_STR
8217 "Open Shortest Path First\n"
2d627ff5
DS
8218 "Non-main Kernel Routing Table\n"
8219 "Instance ID/Table Id\n"
7c8ff89e
DS
8220 "Metric for redistributed routes\n"
8221 "OSPF default metric\n"
8222 "OSPF exterior metric type for redistributed routes\n"
7111c1a0 8223 "Set OSPF External Type 1/2 metrics\n"
7c8ff89e
DS
8224 "Route map reference\n"
8225 "Pointer to route-map entries\n")
8226{
a3d826f0 8227 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
d62a17ae 8228 int idx_ospf_table = 2;
8229 int idx_number = 3;
d7c0a89a 8230 unsigned int instance;
d62a17ae 8231 struct ospf_redist *red;
8232 int source;
8233
8234 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
8235 source = ZEBRA_ROUTE_OSPF;
8236 else
8237 source = ZEBRA_ROUTE_TABLE;
8238
8239 instance = strtoul(argv[idx_number]->arg, NULL, 10);
7c8ff89e 8240
d62a17ae 8241 if ((source == ZEBRA_ROUTE_OSPF) && !ospf->instance) {
8242 vty_out(vty,
8243 "Instance redistribution in non-instanced OSPF not allowed\n");
8244 return CMD_WARNING_CONFIG_FAILED;
8245 }
8246
8247 if ((source == ZEBRA_ROUTE_OSPF) && (ospf->instance == instance)) {
8248 vty_out(vty, "Same instance OSPF redistribution not allowed\n");
8249 return CMD_WARNING_CONFIG_FAILED;
8250 }
8251
8252 red = ospf_redist_lookup(ospf, source, instance);
8253 if (!red)
8254 return CMD_SUCCESS;
8255
8256 ospf_routemap_unset(red);
8257 return ospf_redistribute_unset(ospf, source, instance);
718e3744 8258}
8259
8260DEFUN (ospf_distribute_list_out,
8261 ospf_distribute_list_out_cmd,
40d1cbfb 8262 "distribute-list WORD out " FRR_REDIST_STR_OSPFD,
718e3744 8263 "Filter networks in routing updates\n"
6f2a6703
CF
8264 "Access-list name\n"
8265 OUT_STR
ab0181ee 8266 FRR_REDIST_HELP_STR_OSPFD)
718e3744 8267{
a3d826f0 8268 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
d62a17ae 8269 int idx_word = 1;
8270 int source;
718e3744 8271
d62a17ae 8272 char *proto = argv[argc - 1]->text;
6d681bd8 8273
d62a17ae 8274 /* Get distribute source. */
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_set(ospf, source, argv[idx_word]->arg);
718e3744 8280}
8281
6f2a6703
CF
8282DEFUN (no_ospf_distribute_list_out,
8283 no_ospf_distribute_list_out_cmd,
40d1cbfb 8284 "no distribute-list WORD out " FRR_REDIST_STR_OSPFD,
6f2a6703
CF
8285 NO_STR
8286 "Filter networks in routing updates\n"
8287 "Access-list name\n"
8288 OUT_STR
ab0181ee 8289 FRR_REDIST_HELP_STR_OSPFD)
718e3744 8290{
a3d826f0 8291 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
d62a17ae 8292 int idx_word = 2;
8293 int source;
020709f9 8294
d62a17ae 8295 char *proto = argv[argc - 1]->text;
8296 source = proto_redistnum(AFI_IP, proto);
8297 if (source < 0)
8298 return CMD_WARNING_CONFIG_FAILED;
718e3744 8299
d62a17ae 8300 return ospf_distribute_list_out_unset(ospf, source,
8301 argv[idx_word]->arg);
718e3744 8302}
8303
6f2a6703
CF
8304/* Default information originate. */
8305DEFUN (ospf_default_information_originate,
8306 ospf_default_information_originate_cmd,
ea38ced1 8307 "default-information originate [{always|metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
718e3744 8308 "Control distribution of default information\n"
8309 "Distribute a default route\n"
8310 "Always advertise default route\n"
6f2a6703
CF
8311 "OSPF default metric\n"
8312 "OSPF metric\n"
718e3744 8313 "OSPF metric type for default routes\n"
7111c1a0 8314 "Set OSPF External Type 1/2 metrics\n"
718e3744 8315 "Route map reference\n"
8316 "Pointer to route-map entries\n")
8317{
a3d826f0 8318 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
d62a17ae 8319 int default_originate = DEFAULT_ORIGINATE_ZEBRA;
8320 int type = -1;
8321 int metric = -1;
8322 struct ospf_redist *red;
8323 int idx = 0;
8324
8325 red = ospf_redist_add(ospf, DEFAULT_ROUTE, 0);
8326
8327 /* Check whether "always" was specified */
8328 if (argv_find(argv, argc, "always", &idx))
8329 default_originate = DEFAULT_ORIGINATE_ALWAYS;
951da435 8330 idx = 1;
d62a17ae 8331 /* Get metric value */
ea38ced1 8332 if (argv_find(argv, argc, "(0-16777214)", &idx)) {
d62a17ae 8333 if (!str2metric(argv[idx]->arg, &metric))
8334 return CMD_WARNING_CONFIG_FAILED;
8335 }
951da435 8336 idx = 1;
d62a17ae 8337 /* Get metric type. */
ea38ced1 8338 if (argv_find(argv, argc, "(1-2)", &idx)) {
d62a17ae 8339 if (!str2metric_type(argv[idx]->arg, &type))
8340 return CMD_WARNING_CONFIG_FAILED;
8341 }
951da435 8342 idx = 1;
d62a17ae 8343 /* Get route-map */
ea38ced1 8344 if (argv_find(argv, argc, "WORD", &idx))
d62a17ae 8345 ospf_routemap_set(red, argv[idx]->arg);
8346 else
8347 ospf_routemap_unset(red);
8348
8349 return ospf_redistribute_default_set(ospf, default_originate, type,
8350 metric);
718e3744 8351}
8352
8353DEFUN (no_ospf_default_information_originate,
8354 no_ospf_default_information_originate_cmd,
ea38ced1 8355 "no default-information originate [{always|metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
718e3744 8356 NO_STR
8357 "Control distribution of default information\n"
813d4307
DW
8358 "Distribute a default route\n"
8359 "Always advertise default route\n"
8360 "OSPF default metric\n"
8361 "OSPF metric\n"
8362 "OSPF metric type for default routes\n"
7111c1a0 8363 "Set OSPF External Type 1/2 metrics\n"
813d4307
DW
8364 "Route map reference\n"
8365 "Pointer to route-map entries\n")
718e3744 8366{
a3d826f0 8367 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
d62a17ae 8368 struct prefix_ipv4 p;
8369 struct ospf_external *ext;
8370 struct ospf_redist *red;
7c8ff89e 8371
d62a17ae 8372 p.family = AF_INET;
8373 p.prefix.s_addr = 0;
8374 p.prefixlen = 0;
718e3744 8375
d62a17ae 8376 ospf_external_lsa_flush(ospf, DEFAULT_ROUTE, &p, 0);
718e3744 8377
de1ac5fd
CS
8378 ext = ospf_external_lookup(ospf, DEFAULT_ROUTE, 0);
8379 if (ext && EXTERNAL_INFO(ext)) {
8380 ospf_external_info_delete(ospf, DEFAULT_ROUTE, 0, p);
8381 ospf_external_del(ospf, DEFAULT_ROUTE, 0);
d62a17ae 8382 }
718e3744 8383
d62a17ae 8384 red = ospf_redist_lookup(ospf, DEFAULT_ROUTE, 0);
8385 if (!red)
8386 return CMD_SUCCESS;
7c8ff89e 8387
d62a17ae 8388 ospf_routemap_unset(red);
8389 return ospf_redistribute_default_unset(ospf);
718e3744 8390}
8391
8392DEFUN (ospf_default_metric,
8393 ospf_default_metric_cmd,
6147e2c6 8394 "default-metric (0-16777214)",
718e3744 8395 "Set metric of redistributed routes\n"
8396 "Default metric\n")
8397{
a3d826f0 8398 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
d62a17ae 8399 int idx_number = 1;
8400 int metric = -1;
718e3744 8401
d62a17ae 8402 if (!str2metric(argv[idx_number]->arg, &metric))
8403 return CMD_WARNING_CONFIG_FAILED;
718e3744 8404
d62a17ae 8405 ospf->default_metric = metric;
718e3744 8406
d62a17ae 8407 return CMD_SUCCESS;
718e3744 8408}
8409
8410DEFUN (no_ospf_default_metric,
8411 no_ospf_default_metric_cmd,
7a7be519 8412 "no default-metric [(0-16777214)]",
718e3744 8413 NO_STR
7a7be519 8414 "Set metric of redistributed routes\n"
8415 "Default metric\n")
718e3744 8416{
a3d826f0 8417 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
68980084 8418
d62a17ae 8419 ospf->default_metric = -1;
68980084 8420
d62a17ae 8421 return CMD_SUCCESS;
718e3744 8422}
8423
718e3744 8424
8425DEFUN (ospf_distance,
8426 ospf_distance_cmd,
6147e2c6 8427 "distance (1-255)",
eaa1ae0d 8428 "Administrative distance\n"
718e3744 8429 "OSPF Administrative distance\n")
8430{
a3d826f0 8431 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
d62a17ae 8432 int idx_number = 1;
68980084 8433
d62a17ae 8434 ospf->distance_all = atoi(argv[idx_number]->arg);
68980084 8435
d62a17ae 8436 return CMD_SUCCESS;
718e3744 8437}
8438
8439DEFUN (no_ospf_distance,
8440 no_ospf_distance_cmd,
6147e2c6 8441 "no distance (1-255)",
718e3744 8442 NO_STR
eaa1ae0d 8443 "Administrative distance\n"
718e3744 8444 "OSPF Administrative distance\n")
8445{
a3d826f0 8446 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
68980084 8447
d62a17ae 8448 ospf->distance_all = 0;
68980084 8449
d62a17ae 8450 return CMD_SUCCESS;
718e3744 8451}
8452
8453DEFUN (no_ospf_distance_ospf,
8454 no_ospf_distance_ospf_cmd,
eaa1ae0d 8455 "no distance ospf [{intra-area [(1-255)]|inter-area [(1-255)]|external [(1-255)]}]",
718e3744 8456 NO_STR
eaa1ae0d
QY
8457 "Administrative distance\n"
8458 "OSPF administrative distance\n"
718e3744 8459 "Intra-area routes\n"
813d4307 8460 "Distance for intra-area routes\n"
718e3744 8461 "Inter-area routes\n"
813d4307
DW
8462 "Distance for inter-area routes\n"
8463 "External routes\n"
8464 "Distance for external routes\n")
718e3744 8465{
a3d826f0 8466 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
d62a17ae 8467 int idx = 0;
718e3744 8468
d62a17ae 8469 if (argv_find(argv, argc, "intra-area", &idx) || argc == 3)
8470 idx = ospf->distance_intra = 0;
8471 if (argv_find(argv, argc, "inter-area", &idx) || argc == 3)
8472 idx = ospf->distance_inter = 0;
8473 if (argv_find(argv, argc, "external", &idx) || argc == 3)
8474 ospf->distance_external = 0;
718e3744 8475
d62a17ae 8476 return CMD_SUCCESS;
718e3744 8477}
8478
6f2a6703
CF
8479DEFUN (ospf_distance_ospf,
8480 ospf_distance_ospf_cmd,
eaa1ae0d
QY
8481 "distance ospf {intra-area (1-255)|inter-area (1-255)|external (1-255)}",
8482 "Administrative distance\n"
8483 "OSPF administrative distance\n"
718e3744 8484 "Intra-area routes\n"
8485 "Distance for intra-area routes\n"
718e3744 8486 "Inter-area routes\n"
8487 "Distance for inter-area routes\n"
8488 "External routes\n"
718e3744 8489 "Distance for external routes\n")
8490{
a3d826f0 8491 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
d62a17ae 8492 int idx = 0;
68980084 8493
926b88f0
CS
8494 ospf->distance_intra = 0;
8495 ospf->distance_inter = 0;
8496 ospf->distance_external = 0;
8497
d62a17ae 8498 if (argv_find(argv, argc, "intra-area", &idx))
8499 ospf->distance_intra = atoi(argv[idx + 1]->arg);
8500 idx = 0;
8501 if (argv_find(argv, argc, "inter-area", &idx))
8502 ospf->distance_inter = atoi(argv[idx + 1]->arg);
8503 idx = 0;
8504 if (argv_find(argv, argc, "external", &idx))
8505 ospf->distance_external = atoi(argv[idx + 1]->arg);
68980084 8506
d62a17ae 8507 return CMD_SUCCESS;
718e3744 8508}
8509
d7d73ffc 8510#if 0
718e3744 8511DEFUN (ospf_distance_source,
8512 ospf_distance_source_cmd,
6147e2c6 8513 "distance (1-255) A.B.C.D/M",
718e3744 8514 "Administrative distance\n"
8515 "Distance value\n"
8516 "IP source prefix\n")
8517{
cdc2d765 8518 VTY_DECLVAR_CONTEXT(ospf, ospf);
8d769265
DW
8519 int idx_number = 1;
8520 int idx_ipv4_prefixlen = 2;
020709f9 8521
8d769265 8522 ospf_distance_set (vty, ospf, argv[idx_number]->arg, argv[idx_ipv4_prefixlen]->arg, NULL);
68980084 8523
718e3744 8524 return CMD_SUCCESS;
8525}
8526
8527DEFUN (no_ospf_distance_source,
8528 no_ospf_distance_source_cmd,
6147e2c6 8529 "no distance (1-255) A.B.C.D/M",
718e3744 8530 NO_STR
8531 "Administrative distance\n"
8532 "Distance value\n"
8533 "IP source prefix\n")
8534{
cdc2d765 8535 VTY_DECLVAR_CONTEXT(ospf, ospf);
8d769265
DW
8536 int idx_number = 2;
8537 int idx_ipv4_prefixlen = 3;
020709f9 8538
8d769265 8539 ospf_distance_unset (vty, ospf, argv[idx_number]->arg, argv[idx_ipv4_prefixlen]->arg, NULL);
020709f9 8540
718e3744 8541 return CMD_SUCCESS;
8542}
8543
8544DEFUN (ospf_distance_source_access_list,
8545 ospf_distance_source_access_list_cmd,
6147e2c6 8546 "distance (1-255) A.B.C.D/M WORD",
718e3744 8547 "Administrative distance\n"
8548 "Distance value\n"
8549 "IP source prefix\n"
8550 "Access list name\n")
8551{
cdc2d765 8552 VTY_DECLVAR_CONTEXT(ospf, ospf);
8d769265
DW
8553 int idx_number = 1;
8554 int idx_ipv4_prefixlen = 2;
8555 int idx_word = 3;
020709f9 8556
8d769265 8557 ospf_distance_set (vty, ospf, argv[idx_number]->arg, argv[idx_ipv4_prefixlen]->arg, argv[idx_word]->arg);
020709f9 8558
718e3744 8559 return CMD_SUCCESS;
8560}
8561
8562DEFUN (no_ospf_distance_source_access_list,
8563 no_ospf_distance_source_access_list_cmd,
6147e2c6 8564 "no distance (1-255) A.B.C.D/M WORD",
718e3744 8565 NO_STR
8566 "Administrative distance\n"
8567 "Distance value\n"
8568 "IP source prefix\n"
8569 "Access list name\n")
8570{
cdc2d765 8571 VTY_DECLVAR_CONTEXT(ospf, ospf);
8d769265
DW
8572 int idx_number = 2;
8573 int idx_ipv4_prefixlen = 3;
8574 int idx_word = 4;
020709f9 8575
8d769265 8576 ospf_distance_unset (vty, ospf, argv[idx_number]->arg, argv[idx_ipv4_prefixlen]->arg, argv[idx_word]->arg);
020709f9 8577
718e3744 8578 return CMD_SUCCESS;
8579}
d7d73ffc 8580#endif
718e3744 8581
ba682537 8582DEFUN (ip_ospf_mtu_ignore,
8583 ip_ospf_mtu_ignore_addr_cmd,
7a7be519 8584 "ip ospf mtu-ignore [A.B.C.D]",
ba682537 8585 "IP Information\n"
8586 "OSPF interface commands\n"
99a522c7 8587 "Disable MTU mismatch detection on this interface\n"
efd7904e 8588 "Address of interface\n")
ba682537 8589{
d62a17ae 8590 VTY_DECLVAR_CONTEXT(interface, ifp);
8591 int idx_ipv4 = 3;
8592 struct in_addr addr;
8593 int ret;
8594
8595 struct ospf_if_params *params;
8596 params = IF_DEF_PARAMS(ifp);
8597
8598 if (argc == 4) {
8599 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
8600 if (!ret) {
8601 vty_out(vty,
8602 "Please specify interface address by A.B.C.D\n");
8603 return CMD_WARNING_CONFIG_FAILED;
8604 }
8605 params = ospf_get_if_params(ifp, addr);
8606 ospf_if_update_params(ifp, addr);
8607 }
8608 params->mtu_ignore = 1;
8609 if (params->mtu_ignore != OSPF_MTU_IGNORE_DEFAULT)
8610 SET_IF_PARAM(params, mtu_ignore);
8611 else {
8612 UNSET_IF_PARAM(params, mtu_ignore);
8613 if (params != IF_DEF_PARAMS(ifp)) {
8614 ospf_free_if_params(ifp, addr);
8615 ospf_if_update_params(ifp, addr);
8616 }
8617 }
8618 return CMD_SUCCESS;
ba682537 8619}
8620
ba682537 8621DEFUN (no_ip_ospf_mtu_ignore,
8622 no_ip_ospf_mtu_ignore_addr_cmd,
7a7be519 8623 "no ip ospf mtu-ignore [A.B.C.D]",
efd7904e 8624 NO_STR
ba682537 8625 "IP Information\n"
8626 "OSPF interface commands\n"
99a522c7 8627 "Disable MTU mismatch detection on this interface\n"
efd7904e 8628 "Address of interface\n")
ba682537 8629{
d62a17ae 8630 VTY_DECLVAR_CONTEXT(interface, ifp);
8631 int idx_ipv4 = 4;
8632 struct in_addr addr;
8633 int ret;
8634
8635 struct ospf_if_params *params;
8636 params = IF_DEF_PARAMS(ifp);
8637
8638 if (argc == 5) {
8639 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
8640 if (!ret) {
8641 vty_out(vty,
8642 "Please specify interface address by A.B.C.D\n");
8643 return CMD_WARNING_CONFIG_FAILED;
8644 }
8645 params = ospf_get_if_params(ifp, addr);
8646 ospf_if_update_params(ifp, addr);
8647 }
8648 params->mtu_ignore = 0;
8649 if (params->mtu_ignore != OSPF_MTU_IGNORE_DEFAULT)
8650 SET_IF_PARAM(params, mtu_ignore);
8651 else {
8652 UNSET_IF_PARAM(params, mtu_ignore);
8653 if (params != IF_DEF_PARAMS(ifp)) {
8654 ospf_free_if_params(ifp, addr);
8655 ospf_if_update_params(ifp, addr);
8656 }
8657 }
8658 return CMD_SUCCESS;
ba682537 8659}
8660
6b0655a2 8661
88d6cf37 8662DEFUN (ospf_max_metric_router_lsa_admin,
8663 ospf_max_metric_router_lsa_admin_cmd,
8664 "max-metric router-lsa administrative",
8665 "OSPF maximum / infinite-distance metric\n"
8666 "Advertise own Router-LSA with infinite distance (stub router)\n"
8667 "Administratively applied, for an indefinite period\n")
8668{
a3d826f0 8669 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
d62a17ae 8670 struct listnode *ln;
8671 struct ospf_area *area;
7c8ff89e 8672
d62a17ae 8673 for (ALL_LIST_ELEMENTS_RO(ospf->areas, ln, area)) {
8674 SET_FLAG(area->stub_router_state, OSPF_AREA_ADMIN_STUB_ROUTED);
4ba4fc85 8675
d62a17ae 8676 if (!CHECK_FLAG(area->stub_router_state,
8677 OSPF_AREA_IS_STUB_ROUTED))
8678 ospf_router_lsa_update_area(area);
8679 }
4ba4fc85 8680
d62a17ae 8681 /* Allows for areas configured later to get the property */
8682 ospf->stub_router_admin_set = OSPF_STUB_ROUTER_ADMINISTRATIVE_SET;
8683
8684 return CMD_SUCCESS;
88d6cf37 8685}
8686
8687DEFUN (no_ospf_max_metric_router_lsa_admin,
8688 no_ospf_max_metric_router_lsa_admin_cmd,
8689 "no max-metric router-lsa administrative",
8690 NO_STR
8691 "OSPF maximum / infinite-distance metric\n"
8692 "Advertise own Router-LSA with infinite distance (stub router)\n"
8693 "Administratively applied, for an indefinite period\n")
8694{
a3d826f0 8695 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
d62a17ae 8696 struct listnode *ln;
8697 struct ospf_area *area;
8698
8699 for (ALL_LIST_ELEMENTS_RO(ospf->areas, ln, area)) {
8700 UNSET_FLAG(area->stub_router_state,
8701 OSPF_AREA_ADMIN_STUB_ROUTED);
8702
8703 /* Don't trample on the start-up stub timer */
8704 if (CHECK_FLAG(area->stub_router_state,
8705 OSPF_AREA_IS_STUB_ROUTED)
8706 && !area->t_stub_router) {
8707 UNSET_FLAG(area->stub_router_state,
8708 OSPF_AREA_IS_STUB_ROUTED);
8709 ospf_router_lsa_update_area(area);
8710 }
8711 }
8712 ospf->stub_router_admin_set = OSPF_STUB_ROUTER_ADMINISTRATIVE_UNSET;
8713 return CMD_SUCCESS;
88d6cf37 8714}
8715
8716DEFUN (ospf_max_metric_router_lsa_startup,
8717 ospf_max_metric_router_lsa_startup_cmd,
6147e2c6 8718 "max-metric router-lsa on-startup (5-86400)",
88d6cf37 8719 "OSPF maximum / infinite-distance metric\n"
8720 "Advertise own Router-LSA with infinite distance (stub router)\n"
8721 "Automatically advertise stub Router-LSA on startup of OSPF\n"
8722 "Time (seconds) to advertise self as stub-router\n")
8723{
a3d826f0 8724 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
d62a17ae 8725 int idx_number = 3;
8726 unsigned int seconds;
8727
b5a8894d 8728 if (argc < 4) {
d62a17ae 8729 vty_out(vty, "%% Must supply stub-router period");
8730 return CMD_WARNING_CONFIG_FAILED;
8731 }
8732
8733 seconds = strtoul(argv[idx_number]->arg, NULL, 10);
8734
8735 ospf->stub_router_startup_time = seconds;
8736
8737 return CMD_SUCCESS;
88d6cf37 8738}
8739
8740DEFUN (no_ospf_max_metric_router_lsa_startup,
8741 no_ospf_max_metric_router_lsa_startup_cmd,
7a7be519 8742 "no max-metric router-lsa on-startup [(5-86400)]",
88d6cf37 8743 NO_STR
8744 "OSPF maximum / infinite-distance metric\n"
8745 "Advertise own Router-LSA with infinite distance (stub router)\n"
813d4307
DW
8746 "Automatically advertise stub Router-LSA on startup of OSPF\n"
8747 "Time (seconds) to advertise self as stub-router\n")
88d6cf37 8748{
a3d826f0 8749 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
d62a17ae 8750 struct listnode *ln;
8751 struct ospf_area *area;
8752
8753 ospf->stub_router_startup_time = OSPF_STUB_ROUTER_UNCONFIGURED;
8754
8755 for (ALL_LIST_ELEMENTS_RO(ospf->areas, ln, area)) {
8756 SET_FLAG(area->stub_router_state,
8757 OSPF_AREA_WAS_START_STUB_ROUTED);
8758 OSPF_TIMER_OFF(area->t_stub_router);
8759
8760 /* Don't trample on admin stub routed */
8761 if (!CHECK_FLAG(area->stub_router_state,
8762 OSPF_AREA_ADMIN_STUB_ROUTED)) {
8763 UNSET_FLAG(area->stub_router_state,
8764 OSPF_AREA_IS_STUB_ROUTED);
8765 ospf_router_lsa_update_area(area);
8766 }
8767 }
8768 return CMD_SUCCESS;
88d6cf37 8769}
8770
a1afa410 8771
88d6cf37 8772DEFUN (ospf_max_metric_router_lsa_shutdown,
8773 ospf_max_metric_router_lsa_shutdown_cmd,
6147e2c6 8774 "max-metric router-lsa on-shutdown (5-100)",
88d6cf37 8775 "OSPF maximum / infinite-distance metric\n"
8776 "Advertise own Router-LSA with infinite distance (stub router)\n"
8777 "Advertise stub-router prior to full shutdown of OSPF\n"
8778 "Time (seconds) to wait till full shutdown\n")
8779{
a3d826f0 8780 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
d62a17ae 8781 int idx_number = 3;
8782 unsigned int seconds;
8783
b5a8894d 8784 if (argc < 4) {
d62a17ae 8785 vty_out(vty, "%% Must supply stub-router shutdown period");
8786 return CMD_WARNING_CONFIG_FAILED;
8787 }
8788
8789 seconds = strtoul(argv[idx_number]->arg, NULL, 10);
8790
8791 ospf->stub_router_shutdown_time = seconds;
8792
8793 return CMD_SUCCESS;
88d6cf37 8794}
8795
8796DEFUN (no_ospf_max_metric_router_lsa_shutdown,
8797 no_ospf_max_metric_router_lsa_shutdown_cmd,
7a7be519 8798 "no max-metric router-lsa on-shutdown [(5-100)]",
88d6cf37 8799 NO_STR
8800 "OSPF maximum / infinite-distance metric\n"
8801 "Advertise own Router-LSA with infinite distance (stub router)\n"
813d4307
DW
8802 "Advertise stub-router prior to full shutdown of OSPF\n"
8803 "Time (seconds) to wait till full shutdown\n")
88d6cf37 8804{
a3d826f0 8805 VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
7c8ff89e 8806
d62a17ae 8807 ospf->stub_router_shutdown_time = OSPF_STUB_ROUTER_UNCONFIGURED;
8808
8809 return CMD_SUCCESS;
88d6cf37 8810}
8811
d62a17ae 8812static void config_write_stub_router(struct vty *vty, struct ospf *ospf)
8813{
8814 struct listnode *ln;
8815 struct ospf_area *area;
8816
8817 if (ospf->stub_router_startup_time != OSPF_STUB_ROUTER_UNCONFIGURED)
8818 vty_out(vty, " max-metric router-lsa on-startup %u\n",
8819 ospf->stub_router_startup_time);
8820 if (ospf->stub_router_shutdown_time != OSPF_STUB_ROUTER_UNCONFIGURED)
8821 vty_out(vty, " max-metric router-lsa on-shutdown %u\n",
8822 ospf->stub_router_shutdown_time);
8823 for (ALL_LIST_ELEMENTS_RO(ospf->areas, ln, area)) {
8824 if (CHECK_FLAG(area->stub_router_state,
8825 OSPF_AREA_ADMIN_STUB_ROUTED)) {
8826 vty_out(vty, " max-metric router-lsa administrative\n");
8827 break;
8828 }
8829 }
8830 return;
8831}
8832
b5a8894d 8833static void show_ip_ospf_route_network(struct vty *vty, struct ospf *ospf,
0f478e30
CS
8834 struct route_table *rt,
8835 json_object *json)
d62a17ae 8836{
8837 struct route_node *rn;
8838 struct ospf_route * or ;
8839 struct listnode *pnode, *pnnode;
8840 struct ospf_path *path;
0f478e30
CS
8841 json_object *json_route = NULL, *json_nexthop_array = NULL,
8842 *json_nexthop = NULL;
d62a17ae 8843
0f478e30 8844 if (!json)
996c9314
LB
8845 vty_out(vty,
8846 "============ OSPF network routing table ============\n");
d62a17ae 8847
0f478e30
CS
8848 for (rn = route_top(rt); rn; rn = route_next(rn)) {
8849 if ((or = rn->info) == NULL)
8850 continue;
8851 char buf1[PREFIX2STR_BUFFER];
8852
8853 memset(buf1, 0, sizeof(buf1));
8854 prefix2str(&rn->p, buf1, sizeof(buf1));
8855
8856 json_route = json_object_new_object();
8857 if (json) {
996c9314
LB
8858 json_object_object_add(json, buf1, json_route);
8859 json_object_to_json_string_ext(
8860 json, JSON_C_TO_STRING_NOSLASHESCAPE);
0f478e30
CS
8861 }
8862
8863 switch (or->path_type) {
8864 case OSPF_PATH_INTER_AREA:
8865 if (or->type == OSPF_DESTINATION_NETWORK) {
8866 if (json) {
8867 json_object_string_add(json_route,
996c9314
LB
8868 "routeType",
8869 "N IA");
8870 json_object_int_add(json_route, "cost",
0f478e30
CS
8871 or->cost);
8872 json_object_string_add(
996c9314
LB
8873 json_route, "area",
8874 inet_ntoa(or->u.std.area_id));
0f478e30 8875 } else {
d62a17ae 8876 vty_out(vty,
996c9314 8877 "N IA %-18s [%d] area: %s\n",
d62a17ae 8878 buf1, or->cost,
996c9314 8879 inet_ntoa(or->u.std.area_id));
0f478e30 8880 }
996c9314 8881 } else if (or->type == OSPF_DESTINATION_DISCARD) {
0f478e30
CS
8882 if (json) {
8883 json_object_string_add(json_route,
996c9314
LB
8884 "routeType",
8885 "D IA");
0f478e30 8886 } else {
d62a17ae 8887 vty_out(vty,
8888 "D IA %-18s Discard entry\n",
8889 buf1);
0f478e30
CS
8890 }
8891 }
8892 break;
8893 case OSPF_PATH_INTRA_AREA:
8894 if (json) {
996c9314
LB
8895 json_object_string_add(json_route, "routeType",
8896 "N");
0f478e30 8897 json_object_int_add(json_route, "cost",
996c9314
LB
8898 or->cost);
8899 json_object_string_add(
8900 json_route, "area",
8901 inet_ntoa(or->u.std.area_id));
0f478e30 8902 } else {
d62a17ae 8903 vty_out(vty, "N %-18s [%d] area: %s\n",
8904 buf1, or->cost,
8905 inet_ntoa(or->u.std.area_id));
0f478e30
CS
8906 }
8907 break;
8908 default:
8909 break;
8910 }
8911
8912 if (or->type == OSPF_DESTINATION_NETWORK) {
8913 if (json) {
8914 json_nexthop_array = json_object_new_array();
8915 json_object_object_add(json_route, "nexthops",
996c9314 8916 json_nexthop_array);
d62a17ae 8917 }
8918
0f478e30
CS
8919 for (ALL_LIST_ELEMENTS(or->paths, pnode, pnnode,
8920 path)) {
8921 if (json) {
996c9314
LB
8922 json_nexthop = json_object_new_object();
8923 json_object_array_add(
8924 json_nexthop_array,
8925 json_nexthop);
0f478e30
CS
8926 }
8927 if (if_lookup_by_index(path->ifindex,
8928 ospf->vrf_id)) {
8929
8930 if (path->nexthop.s_addr == 0) {
8931 if (json) {
8932 json_object_string_add(
8933 json_nexthop,
996c9314 8934 "ip", " ");
0f478e30
CS
8935 json_object_string_add(
8936 json_nexthop,
8937 "directly attached to",
d62a17ae 8938 ifindex2ifname(
996c9314
LB
8939 path->ifindex,
8940 ospf->vrf_id));
0f478e30 8941 } else {
d62a17ae 8942 vty_out(vty,
996c9314
LB
8943 "%24s directly attached to %s\n",
8944 "",
8945 ifindex2ifname(
8946 path->ifindex,
8947 ospf->vrf_id));
0f478e30
CS
8948 }
8949 } else {
8950 if (json) {
8951 json_object_string_add(
8952 json_nexthop,
8953 "ip",
d62a17ae 8954 inet_ntoa(
996c9314 8955 path->nexthop));
0f478e30
CS
8956 json_object_string_add(
8957 json_nexthop,
8958 "via",
d62a17ae 8959 ifindex2ifname(
996c9314
LB
8960 path->ifindex,
8961 ospf->vrf_id));
0f478e30
CS
8962 } else {
8963 vty_out(vty,
996c9314
LB
8964 "%24s via %s, %s\n",
8965 "",
8966 inet_ntoa(
8967 path->nexthop),
8968 ifindex2ifname(
8969 path->ifindex,
8970 ospf->vrf_id));
0f478e30 8971 }
d62a17ae 8972 }
8973 }
0f478e30 8974 }
d62a17ae 8975 }
0f478e30
CS
8976 if (!json)
8977 json_object_free(json_route);
8978 }
8979 if (!json)
8980 vty_out(vty, "\n");
d62a17ae 8981}
8982
b5a8894d 8983static void show_ip_ospf_route_router(struct vty *vty, struct ospf *ospf,
0f478e30
CS
8984 struct route_table *rtrs,
8985 json_object *json)
d62a17ae 8986{
8987 struct route_node *rn;
8988 struct ospf_route * or ;
8989 struct listnode *pnode;
8990 struct listnode *node;
8991 struct ospf_path *path;
0f478e30
CS
8992 json_object *json_route = NULL, *json_nexthop_array = NULL,
8993 *json_nexthop = NULL;
d62a17ae 8994
0f478e30 8995 if (!json)
996c9314
LB
8996 vty_out(vty,
8997 "============ OSPF router routing table =============\n");
d62a17ae 8998
0f478e30
CS
8999 for (rn = route_top(rtrs); rn; rn = route_next(rn)) {
9000 if (rn->info == NULL)
9001 continue;
9002 int flag = 0;
9003
9004 json_route = json_object_new_object();
9005 if (json) {
996c9314
LB
9006 json_object_object_add(json, inet_ntoa(rn->p.u.prefix4),
9007 json_route);
9008 json_object_string_add(json_route, "routeType", "R ");
0f478e30 9009 } else {
d62a17ae 9010 vty_out(vty, "R %-15s ",
9011 inet_ntoa(rn->p.u.prefix4));
0f478e30 9012 }
d62a17ae 9013
996c9314 9014 for (ALL_LIST_ELEMENTS_RO((struct list *)rn->info, node, or)) {
0f478e30
CS
9015 if (flag++) {
9016 if (!json)
d62a17ae 9017 vty_out(vty, "%24s", "");
0f478e30 9018 }
d62a17ae 9019
0f478e30
CS
9020 /* Show path. */
9021 if (json) {
9022 json_object_int_add(json_route, "cost",
9023 or->cost);
996c9314
LB
9024 json_object_string_add(
9025 json_route, "area",
0f478e30 9026 inet_ntoa(or->u.std.area_id));
996c9314
LB
9027 if (or->path_type == OSPF_PATH_INTER_AREA)
9028 json_object_boolean_true_add(json_route,
9029 "IA");
0f478e30 9030 if (or->u.std.flags & ROUTER_LSA_BORDER)
996c9314
LB
9031 json_object_string_add(json_route,
9032 "routerType",
9033 "abr");
9034 else if (or->u.std.flags & ROUTER_LSA_EXTERNAL)
9035 json_object_string_add(json_route,
9036 "routerType",
9037 "asbr");
0f478e30 9038 } else {
d62a17ae 9039 vty_out(vty, "%s [%d] area: %s",
996c9314
LB
9040 (or->path_type == OSPF_PATH_INTER_AREA
9041 ? "IA"
9042 : " "),
9043 or->cost, inet_ntoa(or->u.std.area_id));
d62a17ae 9044 /* Show flags. */
9045 vty_out(vty, "%s%s\n",
996c9314
LB
9046 (or->u.std.flags & ROUTER_LSA_BORDER
9047 ? ", ABR"
9048 : ""),
9049 (or->u.std.flags & ROUTER_LSA_EXTERNAL
9050 ? ", ASBR"
9051 : ""));
0f478e30
CS
9052 }
9053
9054 if (json) {
996c9314 9055 json_nexthop_array = json_object_new_array();
0f478e30 9056 json_object_object_add(json_route, "nexthops",
996c9314 9057 json_nexthop_array);
0f478e30
CS
9058 }
9059
996c9314 9060 for (ALL_LIST_ELEMENTS_RO(or->paths, pnode, path)) {
0f478e30 9061 if (json) {
996c9314 9062 json_nexthop = json_object_new_object();
0f478e30
CS
9063 json_object_array_add(
9064 json_nexthop_array,
9065 json_nexthop);
9066 }
9067 if (if_lookup_by_index(path->ifindex,
9068 ospf->vrf_id)) {
9069 if (path->nexthop.s_addr == 0) {
9070 if (json) {
9071 json_object_string_add(
9072 json_nexthop,
996c9314 9073 "ip", " ");
0f478e30
CS
9074 json_object_string_add(
9075 json_nexthop,
9076 "directly attached to",
d62a17ae 9077 ifindex2ifname(
9078 path->ifindex,
b5a8894d 9079 ospf->vrf_id));
0f478e30 9080 } else {
d62a17ae 9081 vty_out(vty,
996c9314
LB
9082 "%24s directly attached to %s\n",
9083 "",
9084 ifindex2ifname(
9085 path->ifindex,
9086 ospf->vrf_id));
0f478e30
CS
9087 }
9088 } else {
9089 if (json) {
9090 json_object_string_add(
9091 json_nexthop,
9092 "ip",
996c9314
LB
9093 inet_ntoa(
9094 path->nexthop));
0f478e30
CS
9095 json_object_string_add(
9096 json_nexthop,
9097 "via",
d62a17ae 9098 ifindex2ifname(
9099 path->ifindex,
b5a8894d 9100 ospf->vrf_id));
0f478e30
CS
9101 } else {
9102 vty_out(vty,
996c9314
LB
9103 "%24s via %s, %s\n",
9104 "",
9105 inet_ntoa(
9106 path->nexthop),
9107 ifindex2ifname(
9108 path->ifindex,
9109 ospf->vrf_id));
0f478e30 9110 }
d62a17ae 9111 }
9112 }
9113 }
9114 }
0f478e30
CS
9115 if (!json)
9116 json_object_free(json_route);
9117 }
9118 if (!json)
9119 vty_out(vty, "\n");
d62a17ae 9120}
9121
b5a8894d 9122static void show_ip_ospf_route_external(struct vty *vty, struct ospf *ospf,
0f478e30
CS
9123 struct route_table *rt,
9124 json_object *json)
d62a17ae 9125{
9126 struct route_node *rn;
9127 struct ospf_route *er;
9128 struct listnode *pnode, *pnnode;
9129 struct ospf_path *path;
0f478e30
CS
9130 json_object *json_route = NULL, *json_nexthop_array = NULL,
9131 *json_nexthop = NULL;
d62a17ae 9132
0f478e30 9133 if (!json)
996c9314
LB
9134 vty_out(vty,
9135 "============ OSPF external routing table ===========\n");
0f478e30
CS
9136
9137 for (rn = route_top(rt); rn; rn = route_next(rn)) {
9138 if ((er = rn->info) == NULL)
9139 continue;
9140
9141 char buf1[19];
9142
9143 snprintf(buf1, 19, "%s/%d", inet_ntoa(rn->p.u.prefix4),
9144 rn->p.prefixlen);
9145 json_route = json_object_new_object();
9146 if (json) {
996c9314
LB
9147 json_object_object_add(json, buf1, json_route);
9148 json_object_to_json_string_ext(
9149 json, JSON_C_TO_STRING_NOSLASHESCAPE);
0f478e30 9150 }
d62a17ae 9151
0f478e30
CS
9152 switch (er->path_type) {
9153 case OSPF_PATH_TYPE1_EXTERNAL:
9154 if (json) {
996c9314 9155 json_object_string_add(json_route, "routeType",
0f478e30
CS
9156 "N E1");
9157 json_object_int_add(json_route, "cost",
996c9314 9158 er->cost);
0f478e30 9159 } else {
d62a17ae 9160 vty_out(vty,
996c9314
LB
9161 "N E1 %-18s [%d] tag: %" ROUTE_TAG_PRI
9162 "\n",
9163 buf1, er->cost, er->u.ext.tag);
0f478e30
CS
9164 }
9165 break;
9166 case OSPF_PATH_TYPE2_EXTERNAL:
9167 if (json) {
996c9314 9168 json_object_string_add(json_route, "routeType",
0f478e30
CS
9169 "N E2");
9170 json_object_int_add(json_route, "cost",
996c9314 9171 er->cost);
0f478e30 9172 } else {
d62a17ae 9173 vty_out(vty,
996c9314
LB
9174 "N E2 %-18s [%d/%d] tag: %" ROUTE_TAG_PRI
9175 "\n",
9176 buf1, er->cost, er->u.ext.type2_cost,
d62a17ae 9177 er->u.ext.tag);
d62a17ae 9178 }
0f478e30
CS
9179 break;
9180 }
d62a17ae 9181
0f478e30
CS
9182 if (json) {
9183 json_nexthop_array = json_object_new_array();
9184 json_object_object_add(json_route, "nexthops",
996c9314 9185 json_nexthop_array);
0f478e30
CS
9186 }
9187
996c9314 9188 for (ALL_LIST_ELEMENTS(er->paths, pnode, pnnode, path)) {
0f478e30
CS
9189 if (json) {
9190 json_nexthop = json_object_new_object();
996c9314
LB
9191 json_object_array_add(json_nexthop_array,
9192 json_nexthop);
0f478e30
CS
9193 }
9194
996c9314 9195 if (if_lookup_by_index(path->ifindex, ospf->vrf_id)) {
0f478e30
CS
9196 if (path->nexthop.s_addr == 0) {
9197 if (json) {
9198 json_object_string_add(
996c9314
LB
9199 json_nexthop, "ip",
9200 " ");
0f478e30
CS
9201 json_object_string_add(
9202 json_nexthop,
9203 "directly attached to",
d62a17ae 9204 ifindex2ifname(
996c9314
LB
9205 path->ifindex,
9206 ospf->vrf_id));
0f478e30 9207 } else {
d62a17ae 9208 vty_out(vty,
996c9314
LB
9209 "%24s directly attached to %s\n",
9210 "",
9211 ifindex2ifname(
9212 path->ifindex,
9213 ospf->vrf_id));
0f478e30
CS
9214 }
9215 } else {
9216 if (json) {
9217 json_object_string_add(
996c9314 9218 json_nexthop, "ip",
d62a17ae 9219 inet_ntoa(
996c9314 9220 path->nexthop));
0f478e30 9221 json_object_string_add(
996c9314 9222 json_nexthop, "via",
d62a17ae 9223 ifindex2ifname(
996c9314
LB
9224 path->ifindex,
9225 ospf->vrf_id));
0f478e30
CS
9226 } else {
9227 vty_out(vty,
996c9314
LB
9228 "%24s via %s, %s\n",
9229 "",
9230 inet_ntoa(
9231 path->nexthop),
9232 ifindex2ifname(
9233 path->ifindex,
9234 ospf->vrf_id));
0f478e30 9235 }
d62a17ae 9236 }
54bedb55 9237 }
d62a17ae 9238 }
0f478e30
CS
9239 if (!json)
9240 json_object_free(json_route);
9241 }
9242 if (!json)
9243 vty_out(vty, "\n");
718e3744 9244}
9245
d62a17ae 9246static int show_ip_ospf_border_routers_common(struct vty *vty,
d7c0a89a
QY
9247 struct ospf *ospf,
9248 uint8_t use_vrf)
718e3744 9249{
d62a17ae 9250 if (ospf->instance)
9251 vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
718e3744 9252
b1c3ae8c 9253 ospf_show_vrf_name(ospf, vty, NULL, use_vrf);
87bd50e8 9254
d62a17ae 9255 if (ospf->new_table == NULL) {
9256 vty_out(vty, "No OSPF routing information exist\n");
9257 return CMD_SUCCESS;
9258 }
718e3744 9259
d62a17ae 9260 /* Show Network routes.
9261 show_ip_ospf_route_network (vty, ospf->new_table); */
718e3744 9262
d62a17ae 9263 /* Show Router routes. */
0f478e30 9264 show_ip_ospf_route_router(vty, ospf, ospf->new_rtrs, NULL);
718e3744 9265
d62a17ae 9266 vty_out(vty, "\n");
7c8ff89e 9267
d62a17ae 9268 return CMD_SUCCESS;
718e3744 9269}
718e3744 9270
7c8ff89e
DS
9271DEFUN (show_ip_ospf_border_routers,
9272 show_ip_ospf_border_routers_cmd,
b5a8894d 9273 "show ip ospf [vrf <NAME|all>] border-routers",
718e3744 9274 SHOW_STR
9275 IP_STR
9276 "OSPF information\n"
b5a8894d
CS
9277 VRF_CMD_HELP_STR
9278 "All VRFs\n"
7c8ff89e 9279 "Show all the ABR's and ASBR's\n")
718e3744 9280{
b5a8894d
CS
9281 struct ospf *ospf = NULL;
9282 struct listnode *node = NULL;
9283 char *vrf_name = NULL;
9284 bool all_vrf = FALSE;
9285 int ret = CMD_SUCCESS;
9286 int inst = 0;
9287 int idx_vrf = 0;
d7c0a89a 9288 uint8_t use_vrf = 0;
68980084 9289
43b8d1d8 9290 OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
7c8ff89e 9291
b5a8894d 9292 if (vrf_name) {
b1c3ae8c 9293 use_vrf = 1;
b5a8894d
CS
9294 if (all_vrf) {
9295 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
9296 if (!ospf->oi_running)
9297 continue;
b5a8894d 9298
996c9314
LB
9299 ret = show_ip_ospf_border_routers_common(
9300 vty, ospf, use_vrf);
b5a8894d
CS
9301 }
9302 } else {
9303 ospf = ospf_lookup_by_inst_name(inst, vrf_name);
9304 if (ospf == NULL || !ospf->oi_running)
9305 return CMD_SUCCESS;
9306
b1c3ae8c
CS
9307 ret = show_ip_ospf_border_routers_common(vty, ospf,
9308 use_vrf);
b5a8894d
CS
9309 }
9310 } else {
9311 /* Display default ospf (instance 0) info */
9312 ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
9313 if (ospf == NULL || !ospf->oi_running)
9314 return CMD_SUCCESS;
b1c3ae8c 9315 ret = show_ip_ospf_border_routers_common(vty, ospf, use_vrf);
b5a8894d
CS
9316 }
9317
9318 return ret;
7c8ff89e
DS
9319}
9320
9321DEFUN (show_ip_ospf_instance_border_routers,
9322 show_ip_ospf_instance_border_routers_cmd,
6147e2c6 9323 "show ip ospf (1-65535) border-routers",
7c8ff89e
DS
9324 SHOW_STR
9325 IP_STR
9326 "OSPF information\n"
9327 "Instance ID\n"
9328 "Show all the ABR's and ASBR's\n")
9329{
d62a17ae 9330 int idx_number = 3;
9331 struct ospf *ospf;
d7c0a89a 9332 unsigned short instance = 0;
7c8ff89e 9333
d62a17ae 9334 instance = strtoul(argv[idx_number]->arg, NULL, 10);
ac28e4ec
CS
9335 ospf = ospf_lookup_instance(instance);
9336 if (ospf == NULL)
9337 return CMD_NOT_MY_INSTANCE;
9338
9339 if (!ospf->oi_running)
d62a17ae 9340 return CMD_SUCCESS;
7c8ff89e 9341
b1c3ae8c 9342 return show_ip_ospf_border_routers_common(vty, ospf, 0);
7c8ff89e
DS
9343}
9344
b1c3ae8c 9345static int show_ip_ospf_route_common(struct vty *vty, struct ospf *ospf,
d7c0a89a 9346 json_object *json, uint8_t use_vrf)
7c8ff89e 9347{
0f478e30
CS
9348 json_object *json_vrf = NULL;
9349
d62a17ae 9350 if (ospf->instance)
9351 vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
718e3744 9352
0f478e30
CS
9353
9354 if (json) {
9355 if (use_vrf)
9356 json_vrf = json_object_new_object();
9357 else
9358 json_vrf = json;
9359 }
9360
9361 ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf);
87bd50e8 9362
d62a17ae 9363 if (ospf->new_table == NULL) {
9364 vty_out(vty, "No OSPF routing information exist\n");
9365 return CMD_SUCCESS;
9366 }
718e3744 9367
d62a17ae 9368 /* Show Network routes. */
0f478e30 9369 show_ip_ospf_route_network(vty, ospf, ospf->new_table, json_vrf);
718e3744 9370
d62a17ae 9371 /* Show Router routes. */
0f478e30 9372 show_ip_ospf_route_router(vty, ospf, ospf->new_rtrs, json_vrf);
718e3744 9373
d62a17ae 9374 /* Show AS External routes. */
0f478e30
CS
9375 show_ip_ospf_route_external(vty, ospf, ospf->old_external_route,
9376 json_vrf);
718e3744 9377
0f478e30
CS
9378 if (json) {
9379 if (use_vrf) {
996c9314
LB
9380 // json_object_object_add(json_vrf, "areas",
9381 // json_areas);
0f478e30
CS
9382 if (ospf->vrf_id == VRF_DEFAULT)
9383 json_object_object_add(json, "default",
9384 json_vrf);
9385 else
9386 json_object_object_add(json, ospf->name,
9387 json_vrf);
9388 }
9389 } else {
9390 vty_out(vty, "\n");
9391 }
7c8ff89e 9392
d62a17ae 9393 return CMD_SUCCESS;
718e3744 9394}
9395
7c8ff89e
DS
9396DEFUN (show_ip_ospf_route,
9397 show_ip_ospf_route_cmd,
0f478e30 9398 "show ip ospf [vrf <NAME|all>] route [json]",
b5a8894d
CS
9399 SHOW_STR
9400 IP_STR
9401 "OSPF information\n"
9402 VRF_CMD_HELP_STR
9403 "All VRFs\n"
0f478e30
CS
9404 "OSPF routing table\n"
9405 JSON_STR)
b5a8894d
CS
9406{
9407 struct ospf *ospf = NULL;
9408 struct listnode *node = NULL;
9409 char *vrf_name = NULL;
9410 bool all_vrf = FALSE;
9411 int ret = CMD_SUCCESS;
9412 int inst = 0;
9413 int idx_vrf = 0;
d7c0a89a
QY
9414 uint8_t use_vrf = 0;
9415 uint8_t uj = use_json(argc, argv);
0f478e30
CS
9416 json_object *json = NULL;
9417
9418 if (uj)
9419 json = json_object_new_object();
7c8ff89e 9420
43b8d1d8 9421 OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
7c8ff89e 9422
b5a8894d
CS
9423 /* vrf input is provided could be all or specific vrf*/
9424 if (vrf_name) {
b1c3ae8c 9425 use_vrf = 1;
b5a8894d
CS
9426 if (all_vrf) {
9427 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
9428 if (!ospf->oi_running)
9429 continue;
0f478e30 9430 ret = show_ip_ospf_route_common(vty, ospf, json,
b1c3ae8c 9431 use_vrf);
b5a8894d 9432 }
0f478e30
CS
9433
9434 if (uj) {
1406159f 9435 /* Keep Non-pretty format */
0f478e30 9436 vty_out(vty, "%s\n",
1406159f 9437 json_object_to_json_string(json));
0f478e30
CS
9438 json_object_free(json);
9439 }
9440
b5a8894d
CS
9441 return ret;
9442 }
9443 ospf = ospf_lookup_by_inst_name(inst, vrf_name);
0f478e30
CS
9444 if (ospf == NULL || !ospf->oi_running) {
9445 if (uj)
9446 json_object_free(json);
b5a8894d 9447 return CMD_SUCCESS;
0f478e30 9448 }
b5a8894d
CS
9449 } else {
9450 /* Display default ospf (instance 0) info */
9451 ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
0f478e30
CS
9452 if (ospf == NULL || !ospf->oi_running) {
9453 if (uj)
9454 json_object_free(json);
b5a8894d 9455 return CMD_SUCCESS;
0f478e30
CS
9456 }
9457 }
9458
9459 if (ospf) {
9460 ret = show_ip_ospf_route_common(vty, ospf, json, use_vrf);
1406159f 9461 /* Keep Non-pretty format */
0f478e30 9462 if (uj)
1406159f 9463 vty_out(vty, "%s\n", json_object_to_json_string(json));
b5a8894d
CS
9464 }
9465
0f478e30
CS
9466 if (uj)
9467 json_object_free(json);
b5a8894d
CS
9468
9469 return ret;
7c8ff89e
DS
9470}
9471
9472DEFUN (show_ip_ospf_instance_route,
9473 show_ip_ospf_instance_route_cmd,
6147e2c6 9474 "show ip ospf (1-65535) route",
7c8ff89e
DS
9475 SHOW_STR
9476 IP_STR
9477 "OSPF information\n"
9478 "Instance ID\n"
9479 "OSPF routing table\n")
9480{
d62a17ae 9481 int idx_number = 3;
9482 struct ospf *ospf;
d7c0a89a 9483 unsigned short instance = 0;
7c8ff89e 9484
d62a17ae 9485 instance = strtoul(argv[idx_number]->arg, NULL, 10);
ac28e4ec
CS
9486 ospf = ospf_lookup_instance(instance);
9487 if (ospf == NULL)
9488 return CMD_NOT_MY_INSTANCE;
9489
9490 if (!ospf->oi_running)
d62a17ae 9491 return CMD_SUCCESS;
7c8ff89e 9492
0f478e30 9493 return show_ip_ospf_route_common(vty, ospf, NULL, 0);
7c8ff89e 9494}
6b0655a2 9495
b5a8894d
CS
9496
9497DEFUN (show_ip_ospf_vrfs,
9498 show_ip_ospf_vrfs_cmd,
9499 "show ip ospf vrfs [json]",
9500 SHOW_STR
9501 IP_STR
9502 "OSPF information\n"
9503 "Show OSPF VRFs \n"
9504 JSON_STR)
9505{
d7c0a89a 9506 uint8_t uj = use_json(argc, argv);
b5a8894d
CS
9507 json_object *json = NULL;
9508 json_object *json_vrfs = NULL;
9509 struct ospf *ospf = NULL;
9510 struct listnode *node = NULL;
9511 int count = 0;
9512 static char header[] = "Name Id RouterId ";
9513
9514 if (uj) {
9515 json = json_object_new_object();
9516 json_vrfs = json_object_new_object();
9517 }
9518
9519 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
9520 json_object *json_vrf = NULL;
9521 const char *name = NULL;
fe3da9e7 9522 int64_t vrf_id_ui = 0;
b5a8894d
CS
9523
9524 count++;
9525
9526 if (!uj && count == 1)
9527 vty_out(vty, "%s\n", header);
9528 if (uj)
9529 json_vrf = json_object_new_object();
9530
9531 if (ospf->vrf_id == 0)
9532 name = VRF_DEFAULT_NAME;
9533 else
9534 name = ospf->name;
9535
996c9314
LB
9536 vrf_id_ui = (ospf->vrf_id == VRF_UNKNOWN)
9537 ? -1
9538 : (int64_t)ospf->vrf_id;
b5a8894d
CS
9539
9540 if (uj) {
9541 json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
9542 json_object_string_add(json_vrf, "routerId",
9543 inet_ntoa(ospf->router_id));
9544
9545 json_object_object_add(json_vrfs, name, json_vrf);
9546
9547 } else {
996c9314
LB
9548 vty_out(vty, "%-25s %-5d %-16s \n", name,
9549 ospf->vrf_id, inet_ntoa(ospf->router_id));
b5a8894d
CS
9550 }
9551 }
9552
9553 if (uj) {
9554 json_object_object_add(json, "vrfs", json_vrfs);
9555 json_object_int_add(json, "totalVrfs", count);
9556
996c9314
LB
9557 vty_out(vty, "%s\n", json_object_to_json_string_ext(
9558 json, JSON_C_TO_STRING_PRETTY));
b5a8894d
CS
9559 json_object_free(json);
9560 } else {
9561 if (count)
34d6798f 9562 vty_out(vty, "\nTotal number of OSPF VRFs: %d\n",
b5a8894d
CS
9563 count);
9564 }
9565
9566 return CMD_SUCCESS;
9567}
9568
d62a17ae 9569const char *ospf_abr_type_str[] = {"unknown", "standard", "ibm", "cisco",
9570 "shortcut"};
718e3744 9571
d62a17ae 9572const char *ospf_shortcut_mode_str[] = {"default", "enable", "disable"};
718e3744 9573
d62a17ae 9574const char *ospf_int_type_str[] = {"unknown", /* should never be used. */
9575 "point-to-point", "broadcast",
9576 "non-broadcast", "point-to-multipoint",
9577 "virtual-link", /* should never be used. */
9578 "loopback"};
718e3744 9579
545f0503 9580static int config_write_interface_one(struct vty *vty, struct vrf *vrf)
d62a17ae 9581{
f4e14fdb 9582 struct listnode *node;
d62a17ae 9583 struct interface *ifp;
9584 struct crypt_key *ck;
d62a17ae 9585 struct route_node *rn = NULL;
9586 struct ospf_if_params *params;
43b8d1d8 9587 int write = 0;
545f0503 9588 struct ospf *ospf = vrf->info;
d62a17ae 9589
545f0503 9590 FOR_ALL_INTERFACES (vrf, ifp) {
d62a17ae 9591
545f0503
CS
9592 if (memcmp(ifp->name, "VLINK", 5) == 0)
9593 continue;
35955c14 9594
545f0503
CS
9595 vty_frame(vty, "!\n");
9596 if (ifp->vrf_id == VRF_DEFAULT)
9597 vty_frame(vty, "interface %s\n", ifp->name);
9598 else
996c9314
LB
9599 vty_frame(vty, "interface %s vrf %s\n", ifp->name,
9600 vrf->name);
545f0503
CS
9601 if (ifp->desc)
9602 vty_out(vty, " description %s\n", ifp->desc);
d62a17ae 9603
545f0503 9604 write++;
43b8d1d8 9605
545f0503 9606 params = IF_DEF_PARAMS(ifp);
43b8d1d8 9607
545f0503
CS
9608 do {
9609 /* Interface Network print. */
9610 if (OSPF_IF_PARAM_CONFIGURED(params, type)
9611 && params->type != OSPF_IFTYPE_LOOPBACK) {
996c9314 9612 if (params->type != ospf_default_iftype(ifp)) {
545f0503
CS
9613 vty_out(vty, " ip ospf network %s",
9614 ospf_int_type_str
996c9314 9615 [params->type]);
545f0503
CS
9616 if (params != IF_DEF_PARAMS(ifp))
9617 vty_out(vty, " %s",
9618 inet_ntoa(
996c9314 9619 rn->p.u.prefix4));
545f0503 9620 vty_out(vty, "\n");
d62a17ae 9621 }
545f0503 9622 }
d62a17ae 9623
545f0503
CS
9624 /* OSPF interface authentication print */
9625 if (OSPF_IF_PARAM_CONFIGURED(params, auth_type)
996c9314 9626 && params->auth_type != OSPF_AUTH_NOTSET) {
545f0503 9627 const char *auth_str;
d62a17ae 9628
545f0503
CS
9629 /* Translation tables are not that much help
9630 * here due to syntax
9631 * of the simple option */
9632 switch (params->auth_type) {
d62a17ae 9633
545f0503
CS
9634 case OSPF_AUTH_NULL:
9635 auth_str = " null";
9636 break;
d62a17ae 9637
545f0503
CS
9638 case OSPF_AUTH_SIMPLE:
9639 auth_str = "";
9640 break;
b5a8894d 9641
545f0503
CS
9642 case OSPF_AUTH_CRYPTOGRAPHIC:
9643 auth_str = " message-digest";
9644 break;
d62a17ae 9645
545f0503
CS
9646 default:
9647 auth_str = "";
9648 break;
c7fd72d2 9649 }
d62a17ae 9650
545f0503
CS
9651 vty_out(vty, " ip ospf authentication%s",
9652 auth_str);
9653 if (params != IF_DEF_PARAMS(ifp))
9654 vty_out(vty, " %s",
c7fd72d2 9655 inet_ntoa(rn->p.u.prefix4));
545f0503
CS
9656 vty_out(vty, "\n");
9657 }
d62a17ae 9658
545f0503
CS
9659 /* Simple Authentication Password print. */
9660 if (OSPF_IF_PARAM_CONFIGURED(params, auth_simple)
996c9314 9661 && params->auth_simple[0] != '\0') {
545f0503
CS
9662 vty_out(vty, " ip ospf authentication-key %s",
9663 params->auth_simple);
9664 if (params != IF_DEF_PARAMS(ifp))
9665 vty_out(vty, " %s",
9666 inet_ntoa(rn->p.u.prefix4));
9667 vty_out(vty, "\n");
9668 }
c7fd72d2 9669
545f0503
CS
9670 /* Cryptographic Authentication Key print. */
9671 if (params && params->auth_crypt) {
996c9314
LB
9672 for (ALL_LIST_ELEMENTS_RO(params->auth_crypt,
9673 node, ck)) {
545f0503
CS
9674 vty_out(vty,
9675 " ip ospf message-digest-key %d md5 %s",
996c9314 9676 ck->key_id, ck->auth_key);
c7fd72d2
CS
9677 if (params != IF_DEF_PARAMS(ifp))
9678 vty_out(vty, " %s",
996c9314
LB
9679 inet_ntoa(
9680 rn->p.u.prefix4));
c7fd72d2
CS
9681 vty_out(vty, "\n");
9682 }
545f0503 9683 }
d62a17ae 9684
545f0503 9685 /* Interface Output Cost print. */
996c9314 9686 if (OSPF_IF_PARAM_CONFIGURED(params, output_cost_cmd)) {
545f0503
CS
9687 vty_out(vty, " ip ospf cost %u",
9688 params->output_cost_cmd);
9689 if (params != IF_DEF_PARAMS(ifp))
9690 vty_out(vty, " %s",
43b8d1d8 9691 inet_ntoa(rn->p.u.prefix4));
545f0503
CS
9692 vty_out(vty, "\n");
9693 }
d62a17ae 9694
545f0503
CS
9695 /* Hello Interval print. */
9696 if (OSPF_IF_PARAM_CONFIGURED(params, v_hello)
996c9314 9697 && params->v_hello != OSPF_HELLO_INTERVAL_DEFAULT) {
545f0503
CS
9698 vty_out(vty, " ip ospf hello-interval %u",
9699 params->v_hello);
9700 if (params != IF_DEF_PARAMS(ifp))
9701 vty_out(vty, " %s",
9702 inet_ntoa(rn->p.u.prefix4));
9703 vty_out(vty, "\n");
9704 }
d62a17ae 9705
d62a17ae 9706
545f0503
CS
9707 /* Router Dead Interval print. */
9708 if (OSPF_IF_PARAM_CONFIGURED(params, v_wait)
996c9314
LB
9709 && params->v_wait
9710 != OSPF_ROUTER_DEAD_INTERVAL_DEFAULT) {
545f0503 9711 vty_out(vty, " ip ospf dead-interval ");
d62a17ae 9712
545f0503
CS
9713 /* fast hello ? */
9714 if (OSPF_IF_PARAM_CONFIGURED(params,
996c9314 9715 fast_hello))
545f0503
CS
9716 vty_out(vty,
9717 "minimal hello-multiplier %d",
9718 params->fast_hello);
9719 else
996c9314 9720 vty_out(vty, "%u", params->v_wait);
d62a17ae 9721
545f0503
CS
9722 if (params != IF_DEF_PARAMS(ifp))
9723 vty_out(vty, " %s",
43b8d1d8 9724 inet_ntoa(rn->p.u.prefix4));
545f0503
CS
9725 vty_out(vty, "\n");
9726 }
d62a17ae 9727
545f0503
CS
9728 /* Router Priority print. */
9729 if (OSPF_IF_PARAM_CONFIGURED(params, priority)
996c9314
LB
9730 && params->priority
9731 != OSPF_ROUTER_PRIORITY_DEFAULT) {
545f0503
CS
9732 vty_out(vty, " ip ospf priority %u",
9733 params->priority);
9734 if (params != IF_DEF_PARAMS(ifp))
9735 vty_out(vty, " %s",
43b8d1d8 9736 inet_ntoa(rn->p.u.prefix4));
545f0503
CS
9737 vty_out(vty, "\n");
9738 }
d62a17ae 9739
545f0503
CS
9740 /* Retransmit Interval print. */
9741 if (OSPF_IF_PARAM_CONFIGURED(params,
996c9314
LB
9742 retransmit_interval)
9743 && params->retransmit_interval
9744 != OSPF_RETRANSMIT_INTERVAL_DEFAULT) {
545f0503
CS
9745 vty_out(vty, " ip ospf retransmit-interval %u",
9746 params->retransmit_interval);
9747 if (params != IF_DEF_PARAMS(ifp))
9748 vty_out(vty, " %s",
43b8d1d8 9749 inet_ntoa(rn->p.u.prefix4));
545f0503
CS
9750 vty_out(vty, "\n");
9751 }
d62a17ae 9752
545f0503 9753 /* Transmit Delay print. */
996c9314
LB
9754 if (OSPF_IF_PARAM_CONFIGURED(params, transmit_delay)
9755 && params->transmit_delay
9756 != OSPF_TRANSMIT_DELAY_DEFAULT) {
545f0503
CS
9757 vty_out(vty, " ip ospf transmit-delay %u",
9758 params->transmit_delay);
9759 if (params != IF_DEF_PARAMS(ifp))
9760 vty_out(vty, " %s",
996c9314 9761 inet_ntoa(rn->p.u.prefix4));
545f0503
CS
9762 vty_out(vty, "\n");
9763 }
d62a17ae 9764
545f0503
CS
9765 /* Area print. */
9766 if (OSPF_IF_PARAM_CONFIGURED(params, if_area)) {
9767 if (ospf && ospf->instance)
9768 vty_out(vty, " ip ospf %d",
9769 ospf->instance);
9770 else
9771 vty_out(vty, " ip ospf");
d62a17ae 9772
1f9d4e3d 9773 char buf[INET_ADDRSTRLEN];
d62a17ae 9774
996c9314
LB
9775 area_id2str(buf, sizeof(buf), &params->if_area,
9776 params->if_area_id_fmt);
545f0503
CS
9777 vty_out(vty, " area %s", buf);
9778 if (params != IF_DEF_PARAMS(ifp))
9779 vty_out(vty, " %s",
996c9314 9780 inet_ntoa(rn->p.u.prefix4));
545f0503
CS
9781 vty_out(vty, "\n");
9782 }
d62a17ae 9783
545f0503 9784 /* bfd print. */
e89ffeee 9785 if (params && params->bfd_info)
545f0503 9786 ospf_bfd_write_config(vty, params);
d62a17ae 9787
545f0503
CS
9788 /* MTU ignore print. */
9789 if (OSPF_IF_PARAM_CONFIGURED(params, mtu_ignore)
996c9314 9790 && params->mtu_ignore != OSPF_MTU_IGNORE_DEFAULT) {
545f0503
CS
9791 if (params->mtu_ignore == 0)
9792 vty_out(vty, " no ip ospf mtu-ignore");
9793 else
9794 vty_out(vty, " ip ospf mtu-ignore");
9795 if (params != IF_DEF_PARAMS(ifp))
9796 vty_out(vty, " %s",
996c9314 9797 inet_ntoa(rn->p.u.prefix4));
545f0503
CS
9798 vty_out(vty, "\n");
9799 }
a8b828f3 9800
d62a17ae 9801
545f0503
CS
9802 while (1) {
9803 if (rn == NULL)
996c9314 9804 rn = route_top(IF_OIFS_PARAMS(ifp));
545f0503
CS
9805 else
9806 rn = route_next(rn);
43b8d1d8 9807
545f0503
CS
9808 if (rn == NULL)
9809 break;
9810 params = rn->info;
9811 if (params != NULL)
9812 break;
9813 }
9814 } while (rn);
43b8d1d8 9815
545f0503
CS
9816 ospf_opaque_config_write_if(vty, ifp);
9817
9818 vty_endframe(vty, NULL);
b5a8894d 9819 }
545f0503 9820
d62a17ae 9821 return write;
718e3744 9822}
9823
43b8d1d8
CS
9824/* Configuration write function for ospfd. */
9825static int config_write_interface(struct vty *vty)
9826{
9827 int write = 0;
545f0503 9828 struct vrf *vrf = NULL;
43b8d1d8 9829
545f0503
CS
9830 /* Display all VRF aware OSPF interface configuration */
9831 RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) {
9832 write += config_write_interface_one(vty, vrf);
9833 }
43b8d1d8
CS
9834
9835 return write;
9836}
9837
d62a17ae 9838static int config_write_network_area(struct vty *vty, struct ospf *ospf)
718e3744 9839{
d62a17ae 9840 struct route_node *rn;
d7c0a89a 9841 uint8_t buf[INET_ADDRSTRLEN];
718e3744 9842
d62a17ae 9843 /* `network area' print. */
9844 for (rn = route_top(ospf->networks); rn; rn = route_next(rn))
9845 if (rn->info) {
9846 struct ospf_network *n = rn->info;
718e3744 9847
d62a17ae 9848 /* Create Area ID string by specified Area ID format. */
9849 if (n->area_id_fmt == OSPF_AREA_ID_FMT_DOTTEDQUAD)
1f9d4e3d 9850 inet_ntop(AF_INET, &n->area_id, (char *)buf,
9851 sizeof(buf));
d62a17ae 9852 else
9853 sprintf((char *)buf, "%lu",
9854 (unsigned long int)ntohl(
9855 n->area_id.s_addr));
718e3744 9856
d62a17ae 9857 /* Network print. */
9858 vty_out(vty, " network %s/%d area %s\n",
9859 inet_ntoa(rn->p.u.prefix4), rn->p.prefixlen,
9860 buf);
9861 }
718e3744 9862
d62a17ae 9863 return 0;
718e3744 9864}
9865
d62a17ae 9866static int config_write_ospf_area(struct vty *vty, struct ospf *ospf)
718e3744 9867{
d62a17ae 9868 struct listnode *node;
9869 struct ospf_area *area;
d7c0a89a 9870 uint8_t buf[INET_ADDRSTRLEN];
718e3744 9871
d62a17ae 9872 /* Area configuration print. */
9873 for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) {
9874 struct route_node *rn1;
718e3744 9875
1f9d4e3d 9876 area_id2str((char *)buf, sizeof(buf), &area->area_id,
d62a17ae 9877 area->area_id_fmt);
718e3744 9878
d62a17ae 9879 if (area->auth_type != OSPF_AUTH_NULL) {
9880 if (area->auth_type == OSPF_AUTH_SIMPLE)
9881 vty_out(vty, " area %s authentication\n", buf);
9882 else
9883 vty_out(vty,
9884 " area %s authentication message-digest\n",
9885 buf);
9886 }
718e3744 9887
d62a17ae 9888 if (area->shortcut_configured != OSPF_SHORTCUT_DEFAULT)
9889 vty_out(vty, " area %s shortcut %s\n", buf,
9890 ospf_shortcut_mode_str
9891 [area->shortcut_configured]);
9892
9893 if ((area->external_routing == OSPF_AREA_STUB)
9894 || (area->external_routing == OSPF_AREA_NSSA)) {
7ef56a73 9895 if (area->external_routing == OSPF_AREA_STUB) {
d62a17ae 9896 vty_out(vty, " area %s stub", buf);
7ef56a73
CS
9897 if (area->no_summary)
9898 vty_out(vty, " no-summary\n");
9899 vty_out(vty, "\n");
9900 } else if (area->external_routing == OSPF_AREA_NSSA) {
d62a17ae 9901 switch (area->NSSATranslatorRole) {
9902 case OSPF_NSSA_ROLE_NEVER:
7ef56a73
CS
9903 vty_out(vty,
9904 " area %s nssa translate-never\n",
9905 buf);
d62a17ae 9906 break;
9907 case OSPF_NSSA_ROLE_ALWAYS:
7ef56a73
CS
9908 vty_out(vty,
9909 " area %s nssa translate-always\n",
9910 buf);
d62a17ae 9911 break;
2643b2bc
CS
9912 case OSPF_NSSA_ROLE_CANDIDATE:
9913 vty_out(vty, " area %s nssa \n", buf);
9914 break;
d62a17ae 9915 }
7ef56a73
CS
9916 if (area->no_summary)
9917 vty_out(vty,
9918 " area %s nssa no-summary\n",
9919 buf);
d62a17ae 9920 }
718e3744 9921
d62a17ae 9922 if (area->default_cost != 1)
9923 vty_out(vty, " area %s default-cost %d\n", buf,
9924 area->default_cost);
9925 }
718e3744 9926
d62a17ae 9927 for (rn1 = route_top(area->ranges); rn1; rn1 = route_next(rn1))
9928 if (rn1->info) {
9929 struct ospf_area_range *range = rn1->info;
718e3744 9930
d62a17ae 9931 vty_out(vty, " area %s range %s/%d", buf,
9932 inet_ntoa(rn1->p.u.prefix4),
9933 rn1->p.prefixlen);
718e3744 9934
d62a17ae 9935 if (range->cost_config
9936 != OSPF_AREA_RANGE_COST_UNSPEC)
9937 vty_out(vty, " cost %d",
9938 range->cost_config);
718e3744 9939
d62a17ae 9940 if (!CHECK_FLAG(range->flags,
9941 OSPF_AREA_RANGE_ADVERTISE))
9942 vty_out(vty, " not-advertise");
718e3744 9943
d62a17ae 9944 if (CHECK_FLAG(range->flags,
9945 OSPF_AREA_RANGE_SUBSTITUTE))
9946 vty_out(vty, " substitute %s/%d",
9947 inet_ntoa(range->subst_addr),
9948 range->subst_masklen);
9949
9950 vty_out(vty, "\n");
9951 }
9952
9953 if (EXPORT_NAME(area))
9954 vty_out(vty, " area %s export-list %s\n", buf,
9955 EXPORT_NAME(area));
9956
9957 if (IMPORT_NAME(area))
9958 vty_out(vty, " area %s import-list %s\n", buf,
9959 IMPORT_NAME(area));
9960
9961 if (PREFIX_NAME_IN(area))
9962 vty_out(vty, " area %s filter-list prefix %s in\n", buf,
9963 PREFIX_NAME_IN(area));
9964
9965 if (PREFIX_NAME_OUT(area))
9966 vty_out(vty, " area %s filter-list prefix %s out\n",
9967 buf, PREFIX_NAME_OUT(area));
9968 }
9969
9970 return 0;
718e3744 9971}
9972
d62a17ae 9973static int config_write_ospf_nbr_nbma(struct vty *vty, struct ospf *ospf)
718e3744 9974{
d62a17ae 9975 struct ospf_nbr_nbma *nbr_nbma;
9976 struct route_node *rn;
718e3744 9977
d62a17ae 9978 /* Static Neighbor configuration print. */
9979 for (rn = route_top(ospf->nbr_nbma); rn; rn = route_next(rn))
9980 if ((nbr_nbma = rn->info)) {
9981 vty_out(vty, " neighbor %s", inet_ntoa(nbr_nbma->addr));
718e3744 9982
d62a17ae 9983 if (nbr_nbma->priority
9984 != OSPF_NEIGHBOR_PRIORITY_DEFAULT)
9985 vty_out(vty, " priority %d",
9986 nbr_nbma->priority);
718e3744 9987
d62a17ae 9988 if (nbr_nbma->v_poll != OSPF_POLL_INTERVAL_DEFAULT)
9989 vty_out(vty, " poll-interval %d",
9990 nbr_nbma->v_poll);
9991
9992 vty_out(vty, "\n");
9993 }
9994
9995 return 0;
9996}
9997
9998static int config_write_virtual_link(struct vty *vty, struct ospf *ospf)
9999{
10000 struct listnode *node;
10001 struct ospf_vl_data *vl_data;
10002 char buf[INET_ADDRSTRLEN];
10003
10004 /* Virtual-Link print */
10005 for (ALL_LIST_ELEMENTS_RO(ospf->vlinks, node, vl_data)) {
10006 struct listnode *n2;
10007 struct crypt_key *ck;
10008 struct ospf_interface *oi;
10009
10010 if (vl_data != NULL) {
d62a17ae 10011 area_id2str(buf, sizeof(buf), &vl_data->vl_area_id,
10012 vl_data->vl_area_id_fmt);
10013 oi = vl_data->vl_oi;
10014
10015 /* timers */
10016 if (OSPF_IF_PARAM(oi, v_hello)
10017 != OSPF_HELLO_INTERVAL_DEFAULT
10018 || OSPF_IF_PARAM(oi, v_wait)
10019 != OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
10020 || OSPF_IF_PARAM(oi, retransmit_interval)
10021 != OSPF_RETRANSMIT_INTERVAL_DEFAULT
10022 || OSPF_IF_PARAM(oi, transmit_delay)
10023 != OSPF_TRANSMIT_DELAY_DEFAULT)
10024 vty_out(vty,
10025 " area %s virtual-link %s hello-interval %d retransmit-interval %d transmit-delay %d dead-interval %d\n",
10026 buf, inet_ntoa(vl_data->vl_peer),
10027 OSPF_IF_PARAM(oi, v_hello),
10028 OSPF_IF_PARAM(oi, retransmit_interval),
10029 OSPF_IF_PARAM(oi, transmit_delay),
10030 OSPF_IF_PARAM(oi, v_wait));
10031 else
10032 vty_out(vty, " area %s virtual-link %s\n", buf,
10033 inet_ntoa(vl_data->vl_peer));
10034 /* Auth key */
10035 if (IF_DEF_PARAMS(vl_data->vl_oi->ifp)->auth_simple[0]
10036 != '\0')
10037 vty_out(vty,
10038 " area %s virtual-link %s authentication-key %s\n",
10039 buf, inet_ntoa(vl_data->vl_peer),
10040 IF_DEF_PARAMS(vl_data->vl_oi->ifp)
10041 ->auth_simple);
10042 /* md5 keys */
10043 for (ALL_LIST_ELEMENTS_RO(
10044 IF_DEF_PARAMS(vl_data->vl_oi->ifp)
10045 ->auth_crypt,
10046 n2, ck))
10047 vty_out(vty,
10048 " area %s virtual-link %s"
10049 " message-digest-key %d md5 %s\n",
10050 buf, inet_ntoa(vl_data->vl_peer),
10051 ck->key_id, ck->auth_key);
10052 }
10053 }
10054
10055 return 0;
718e3744 10056}
10057
6b0655a2 10058
d62a17ae 10059static int config_write_ospf_redistribute(struct vty *vty, struct ospf *ospf)
718e3744 10060{
d62a17ae 10061 int type;
718e3744 10062
d62a17ae 10063 /* redistribute print. */
10064 for (type = 0; type < ZEBRA_ROUTE_MAX; type++) {
10065 struct list *red_list;
10066 struct listnode *node;
10067 struct ospf_redist *red;
718e3744 10068
d62a17ae 10069 red_list = ospf->redist[type];
10070 if (!red_list)
10071 continue;
7c8ff89e 10072
d62a17ae 10073 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
10074 vty_out(vty, " redistribute %s",
10075 zebra_route_string(type));
10076 if (red->instance)
10077 vty_out(vty, " %d", red->instance);
7c8ff89e 10078
d62a17ae 10079 if (red->dmetric.value >= 0)
10080 vty_out(vty, " metric %d", red->dmetric.value);
7c8ff89e 10081
d62a17ae 10082 if (red->dmetric.type == EXTERNAL_METRIC_TYPE_1)
10083 vty_out(vty, " metric-type 1");
7c8ff89e 10084
d62a17ae 10085 if (ROUTEMAP_NAME(red))
10086 vty_out(vty, " route-map %s",
10087 ROUTEMAP_NAME(red));
7c8ff89e 10088
d62a17ae 10089 vty_out(vty, "\n");
10090 }
10091 }
718e3744 10092
d62a17ae 10093 return 0;
718e3744 10094}
10095
d62a17ae 10096static int config_write_ospf_default_metric(struct vty *vty, struct ospf *ospf)
718e3744 10097{
d62a17ae 10098 if (ospf->default_metric != -1)
10099 vty_out(vty, " default-metric %d\n", ospf->default_metric);
10100 return 0;
718e3744 10101}
10102
d62a17ae 10103static int config_write_ospf_distribute(struct vty *vty, struct ospf *ospf)
10104{
10105 int type;
10106 struct ospf_redist *red;
718e3744 10107
d62a17ae 10108 if (ospf) {
10109 /* distribute-list print. */
10110 for (type = 0; type < ZEBRA_ROUTE_MAX; type++)
10111 if (DISTRIBUTE_NAME(ospf, type))
10112 vty_out(vty, " distribute-list %s out %s\n",
10113 DISTRIBUTE_NAME(ospf, type),
10114 zebra_route_string(type));
7c8ff89e 10115
d62a17ae 10116 /* default-information print. */
10117 if (ospf->default_originate != DEFAULT_ORIGINATE_NONE) {
10118 vty_out(vty, " default-information originate");
10119 if (ospf->default_originate == DEFAULT_ORIGINATE_ALWAYS)
10120 vty_out(vty, " always");
718e3744 10121
d62a17ae 10122 red = ospf_redist_lookup(ospf, DEFAULT_ROUTE, 0);
10123 if (red) {
10124 if (red->dmetric.value >= 0)
10125 vty_out(vty, " metric %d",
10126 red->dmetric.value);
951da435 10127
d62a17ae 10128 if (red->dmetric.type == EXTERNAL_METRIC_TYPE_1)
10129 vty_out(vty, " metric-type 1");
718e3744 10130
d62a17ae 10131 if (ROUTEMAP_NAME(red))
10132 vty_out(vty, " route-map %s",
10133 ROUTEMAP_NAME(red));
10134 }
10135
10136 vty_out(vty, "\n");
10137 }
10138 }
10139
10140 return 0;
718e3744 10141}
10142
d62a17ae 10143static int config_write_ospf_distance(struct vty *vty, struct ospf *ospf)
10144{
10145 struct route_node *rn;
10146 struct ospf_distance *odistance;
10147
10148 if (ospf->distance_all)
10149 vty_out(vty, " distance %d\n", ospf->distance_all);
10150
10151 if (ospf->distance_intra || ospf->distance_inter
10152 || ospf->distance_external) {
10153 vty_out(vty, " distance ospf");
10154
10155 if (ospf->distance_intra)
10156 vty_out(vty, " intra-area %d", ospf->distance_intra);
10157 if (ospf->distance_inter)
10158 vty_out(vty, " inter-area %d", ospf->distance_inter);
10159 if (ospf->distance_external)
10160 vty_out(vty, " external %d", ospf->distance_external);
10161
10162 vty_out(vty, "\n");
10163 }
10164
10165 for (rn = route_top(ospf->distance_table); rn; rn = route_next(rn))
10166 if ((odistance = rn->info) != NULL) {
10167 vty_out(vty, " distance %d %s/%d %s\n",
10168 odistance->distance, inet_ntoa(rn->p.u.prefix4),
10169 rn->p.prefixlen,
10170 odistance->access_list ? odistance->access_list
10171 : "");
10172 }
10173 return 0;
718e3744 10174}
10175
43b8d1d8 10176static int ospf_config_write_one(struct vty *vty, struct ospf *ospf)
d62a17ae 10177{
f4e14fdb 10178 struct vrf *vrf = vrf_lookup_by_id(ospf->vrf_id);
d62a17ae 10179 struct interface *ifp;
10180 struct ospf_interface *oi;
43b8d1d8 10181 struct listnode *node = NULL;
d62a17ae 10182 int write = 0;
10183
43b8d1d8
CS
10184 /* `router ospf' print. */
10185 if (ospf->instance && ospf->name) {
996c9314
LB
10186 vty_out(vty, "router ospf %d vrf %s\n", ospf->instance,
10187 ospf->name);
43b8d1d8 10188 } else if (ospf->instance) {
996c9314 10189 vty_out(vty, "router ospf %d\n", ospf->instance);
43b8d1d8 10190 } else if (ospf->name) {
996c9314 10191 vty_out(vty, "router ospf vrf %s\n", ospf->name);
43b8d1d8
CS
10192 } else
10193 vty_out(vty, "router ospf\n");
10194
10195 if (!ospf->networks) {
10196 write++;
b5a8894d 10197 return write;
43b8d1d8 10198 }
d62a17ae 10199
43b8d1d8
CS
10200 /* Router ID print. */
10201 if (ospf->router_id_static.s_addr != 0)
10202 vty_out(vty, " ospf router-id %s\n",
10203 inet_ntoa(ospf->router_id_static));
d62a17ae 10204
43b8d1d8
CS
10205 /* ABR type print. */
10206 if (ospf->abr_type != OSPF_ABR_DEFAULT)
10207 vty_out(vty, " ospf abr-type %s\n",
10208 ospf_abr_type_str[ospf->abr_type]);
b5a8894d 10209
43b8d1d8
CS
10210 /* log-adjacency-changes flag print. */
10211 if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES)) {
10212 if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL))
10213 vty_out(vty, " log-adjacency-changes detail\n");
10214 else if (!DFLT_OSPF_LOG_ADJACENCY_CHANGES)
10215 vty_out(vty, " log-adjacency-changes\n");
10216 } else if (DFLT_OSPF_LOG_ADJACENCY_CHANGES) {
10217 vty_out(vty, " no log-adjacency-changes\n");
10218 }
b5a8894d 10219
43b8d1d8
CS
10220 /* RFC1583 compatibility flag print -- Compatible with CISCO
10221 * 12.1. */
10222 if (CHECK_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE))
10223 vty_out(vty, " compatible rfc1583\n");
d62a17ae 10224
43b8d1d8
CS
10225 /* auto-cost reference-bandwidth configuration. */
10226 if (ospf->ref_bandwidth != OSPF_DEFAULT_REF_BANDWIDTH) {
10227 vty_out(vty,
10228 "! Important: ensure reference bandwidth "
10229 "is consistent across all routers\n");
10230 vty_out(vty, " auto-cost reference-bandwidth %d\n",
10231 ospf->ref_bandwidth);
10232 }
d62a17ae 10233
43b8d1d8
CS
10234 /* SPF timers print. */
10235 if (ospf->spf_delay != OSPF_SPF_DELAY_DEFAULT
10236 || ospf->spf_holdtime != OSPF_SPF_HOLDTIME_DEFAULT
10237 || ospf->spf_max_holdtime != OSPF_SPF_MAX_HOLDTIME_DEFAULT)
996c9314
LB
10238 vty_out(vty, " timers throttle spf %d %d %d\n", ospf->spf_delay,
10239 ospf->spf_holdtime, ospf->spf_max_holdtime);
43b8d1d8
CS
10240
10241 /* LSA timers print. */
10242 if (ospf->min_ls_interval != OSPF_MIN_LS_INTERVAL)
10243 vty_out(vty, " timers throttle lsa all %d\n",
10244 ospf->min_ls_interval);
10245 if (ospf->min_ls_arrival != OSPF_MIN_LS_ARRIVAL)
10246 vty_out(vty, " timers lsa min-arrival %d\n",
10247 ospf->min_ls_arrival);
10248
10249 /* Write multiplier print. */
10250 if (ospf->write_oi_count != OSPF_WRITE_INTERFACE_COUNT_DEFAULT)
10251 vty_out(vty, " ospf write-multiplier %d\n",
10252 ospf->write_oi_count);
d62a17ae 10253
43b8d1d8
CS
10254 /* Max-metric router-lsa print */
10255 config_write_stub_router(vty, ospf);
d62a17ae 10256
43b8d1d8 10257 /* SPF refresh parameters print. */
996c9314
LB
10258 if (ospf->lsa_refresh_interval != OSPF_LSA_REFRESH_INTERVAL_DEFAULT)
10259 vty_out(vty, " refresh timer %d\n", ospf->lsa_refresh_interval);
d62a17ae 10260
43b8d1d8
CS
10261 /* Redistribute information print. */
10262 config_write_ospf_redistribute(vty, ospf);
d62a17ae 10263
43b8d1d8
CS
10264 /* passive-interface print. */
10265 if (ospf->passive_interface_default == OSPF_IF_PASSIVE)
10266 vty_out(vty, " passive-interface default\n");
d62a17ae 10267
451fda4f 10268 FOR_ALL_INTERFACES (vrf, ifp)
43b8d1d8
CS
10269 if (OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(ifp),
10270 passive_interface)
10271 && IF_DEF_PARAMS(ifp)->passive_interface
996c9314 10272 != ospf->passive_interface_default) {
43b8d1d8 10273 vty_out(vty, " %spassive-interface %s\n",
996c9314
LB
10274 IF_DEF_PARAMS(ifp)->passive_interface ? ""
10275 : "no ",
43b8d1d8
CS
10276 ifp->name);
10277 }
10278 for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) {
996c9314 10279 if (!OSPF_IF_PARAM_CONFIGURED(oi->params, passive_interface))
43b8d1d8
CS
10280 continue;
10281 if (OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(oi->ifp),
10282 passive_interface)) {
10283 if (oi->params->passive_interface
996c9314 10284 == IF_DEF_PARAMS(oi->ifp)->passive_interface)
43b8d1d8
CS
10285 continue;
10286 } else if (oi->params->passive_interface
10287 == ospf->passive_interface_default)
10288 continue;
d62a17ae 10289
43b8d1d8
CS
10290 vty_out(vty, " %spassive-interface %s %s\n",
10291 oi->params->passive_interface ? "" : "no ",
996c9314 10292 oi->ifp->name, inet_ntoa(oi->address->u.prefix4));
43b8d1d8 10293 }
d62a17ae 10294
43b8d1d8
CS
10295 /* Network area print. */
10296 config_write_network_area(vty, ospf);
d62a17ae 10297
43b8d1d8
CS
10298 /* Area config print. */
10299 config_write_ospf_area(vty, ospf);
d62a17ae 10300
43b8d1d8
CS
10301 /* static neighbor print. */
10302 config_write_ospf_nbr_nbma(vty, ospf);
10303
10304 /* Virtual-Link print. */
10305 config_write_virtual_link(vty, ospf);
10306
10307 /* Default metric configuration. */
10308 config_write_ospf_default_metric(vty, ospf);
10309
10310 /* Distribute-list and default-information print. */
10311 config_write_ospf_distribute(vty, ospf);
10312
10313 /* Distance configuration. */
10314 config_write_ospf_distance(vty, ospf);
10315
10316 ospf_opaque_config_write_router(vty, ospf);
10317
10318 write++;
10319 return write;
10320}
10321
10322/* OSPF configuration write function. */
10323static int ospf_config_write(struct vty *vty)
10324{
10325 struct ospf *ospf;
10326 struct listnode *ospf_node = NULL;
10327 int write = 0;
10328
10329 if (listcount(om->ospf) == 0)
10330 return write;
10331
10332 for (ALL_LIST_ELEMENTS_RO(om->ospf, ospf_node, ospf)) {
88d77109
CS
10333 /* VRF Default check if it is running.
10334 * Upon daemon start, there could be default instance
10335 * in absence of 'router ospf'/oi_running is disabled. */
10336 if (ospf->vrf_id == VRF_DEFAULT && ospf->oi_running)
10337 write += ospf_config_write_one(vty, ospf);
10338 /* For Non-Default VRF simply display the configuration,
10339 * even if it is not oi_running. */
10340 else if (ospf->vrf_id != VRF_DEFAULT)
43b8d1d8 10341 write += ospf_config_write_one(vty, ospf);
b5a8894d 10342 }
d62a17ae 10343 return write;
10344}
10345
10346void ospf_vty_show_init(void)
10347{
10348 /* "show ip ospf" commands. */
10349 install_element(VIEW_NODE, &show_ip_ospf_cmd);
10350
10351 install_element(VIEW_NODE, &show_ip_ospf_instance_cmd);
10352
10353 /* "show ip ospf database" commands. */
10354 install_element(VIEW_NODE, &show_ip_ospf_database_max_cmd);
10355
10356 install_element(VIEW_NODE,
10357 &show_ip_ospf_instance_database_type_adv_router_cmd);
10358 install_element(VIEW_NODE, &show_ip_ospf_instance_database_cmd);
10359 install_element(VIEW_NODE, &show_ip_ospf_instance_database_max_cmd);
10360
10361 /* "show ip ospf interface" commands. */
10362 install_element(VIEW_NODE, &show_ip_ospf_interface_cmd);
10363
10364 install_element(VIEW_NODE, &show_ip_ospf_instance_interface_cmd);
c9339663
CS
10365 /* "show ip ospf interface traffic */
10366 install_element(VIEW_NODE, &show_ip_ospf_interface_traffic_cmd);
d62a17ae 10367
10368 /* "show ip ospf neighbor" commands. */
10369 install_element(VIEW_NODE, &show_ip_ospf_neighbor_int_detail_cmd);
10370 install_element(VIEW_NODE, &show_ip_ospf_neighbor_int_cmd);
10371 install_element(VIEW_NODE, &show_ip_ospf_neighbor_id_cmd);
10372 install_element(VIEW_NODE, &show_ip_ospf_neighbor_detail_all_cmd);
10373 install_element(VIEW_NODE, &show_ip_ospf_neighbor_detail_cmd);
10374 install_element(VIEW_NODE, &show_ip_ospf_neighbor_cmd);
10375 install_element(VIEW_NODE, &show_ip_ospf_neighbor_all_cmd);
10376
10377 install_element(VIEW_NODE,
10378 &show_ip_ospf_instance_neighbor_int_detail_cmd);
10379 install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_int_cmd);
10380 install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_id_cmd);
10381 install_element(VIEW_NODE,
10382 &show_ip_ospf_instance_neighbor_detail_all_cmd);
10383 install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_detail_cmd);
10384 install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_cmd);
10385 install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_all_cmd);
10386
10387 /* "show ip ospf route" commands. */
10388 install_element(VIEW_NODE, &show_ip_ospf_route_cmd);
10389 install_element(VIEW_NODE, &show_ip_ospf_border_routers_cmd);
10390
10391 install_element(VIEW_NODE, &show_ip_ospf_instance_route_cmd);
10392 install_element(VIEW_NODE, &show_ip_ospf_instance_border_routers_cmd);
b5a8894d
CS
10393
10394 /* "show ip ospf vrfs" commands. */
10395 install_element(VIEW_NODE, &show_ip_ospf_vrfs_cmd);
718e3744 10396}
10397
6b0655a2 10398
718e3744 10399/* ospfd's interface node. */
d62a17ae 10400static struct cmd_node interface_node = {INTERFACE_NODE, "%s(config-if)# ", 1};
718e3744 10401
10402/* Initialization of OSPF interface. */
d62a17ae 10403static void ospf_vty_if_init(void)
10404{
10405 /* Install interface node. */
10406 install_node(&interface_node, config_write_interface);
10407 if_cmd_init();
10408
10409 /* "ip ospf authentication" commands. */
10410 install_element(INTERFACE_NODE, &ip_ospf_authentication_args_addr_cmd);
10411 install_element(INTERFACE_NODE, &ip_ospf_authentication_addr_cmd);
10412 install_element(INTERFACE_NODE,
10413 &no_ip_ospf_authentication_args_addr_cmd);
10414 install_element(INTERFACE_NODE, &no_ip_ospf_authentication_addr_cmd);
10415 install_element(INTERFACE_NODE, &ip_ospf_authentication_key_addr_cmd);
10416 install_element(INTERFACE_NODE,
10417 &no_ip_ospf_authentication_key_authkey_addr_cmd);
10418 install_element(INTERFACE_NODE,
10419 &no_ospf_authentication_key_authkey_addr_cmd);
10420
10421 /* "ip ospf message-digest-key" commands. */
10422 install_element(INTERFACE_NODE, &ip_ospf_message_digest_key_cmd);
10423 install_element(INTERFACE_NODE, &no_ip_ospf_message_digest_key_cmd);
10424
10425 /* "ip ospf cost" commands. */
10426 install_element(INTERFACE_NODE, &ip_ospf_cost_cmd);
10427 install_element(INTERFACE_NODE, &no_ip_ospf_cost_cmd);
10428
10429 /* "ip ospf mtu-ignore" commands. */
10430 install_element(INTERFACE_NODE, &ip_ospf_mtu_ignore_addr_cmd);
10431 install_element(INTERFACE_NODE, &no_ip_ospf_mtu_ignore_addr_cmd);
10432
10433 /* "ip ospf dead-interval" commands. */
10434 install_element(INTERFACE_NODE, &ip_ospf_dead_interval_cmd);
10435 install_element(INTERFACE_NODE,
10436 &ip_ospf_dead_interval_minimal_addr_cmd);
10437 install_element(INTERFACE_NODE, &no_ip_ospf_dead_interval_cmd);
10438
10439 /* "ip ospf hello-interval" commands. */
10440 install_element(INTERFACE_NODE, &ip_ospf_hello_interval_cmd);
10441 install_element(INTERFACE_NODE, &no_ip_ospf_hello_interval_cmd);
10442
10443 /* "ip ospf network" commands. */
10444 install_element(INTERFACE_NODE, &ip_ospf_network_cmd);
10445 install_element(INTERFACE_NODE, &no_ip_ospf_network_cmd);
10446
10447 /* "ip ospf priority" commands. */
10448 install_element(INTERFACE_NODE, &ip_ospf_priority_cmd);
10449 install_element(INTERFACE_NODE, &no_ip_ospf_priority_cmd);
10450
10451 /* "ip ospf retransmit-interval" commands. */
10452 install_element(INTERFACE_NODE, &ip_ospf_retransmit_interval_addr_cmd);
10453 install_element(INTERFACE_NODE,
10454 &no_ip_ospf_retransmit_interval_addr_cmd);
10455
10456 /* "ip ospf transmit-delay" commands. */
10457 install_element(INTERFACE_NODE, &ip_ospf_transmit_delay_addr_cmd);
10458 install_element(INTERFACE_NODE, &no_ip_ospf_transmit_delay_addr_cmd);
10459
10460 /* "ip ospf area" commands. */
10461 install_element(INTERFACE_NODE, &ip_ospf_area_cmd);
10462 install_element(INTERFACE_NODE, &no_ip_ospf_area_cmd);
10463
10464 /* These commands are compatibitliy for previous version. */
10465 install_element(INTERFACE_NODE, &ospf_authentication_key_cmd);
10466 install_element(INTERFACE_NODE, &ospf_message_digest_key_cmd);
10467 install_element(INTERFACE_NODE, &no_ospf_message_digest_key_cmd);
10468 install_element(INTERFACE_NODE, &ospf_dead_interval_cmd);
10469 install_element(INTERFACE_NODE, &no_ospf_dead_interval_cmd);
10470 install_element(INTERFACE_NODE, &ospf_hello_interval_cmd);
10471 install_element(INTERFACE_NODE, &no_ospf_hello_interval_cmd);
10472 install_element(INTERFACE_NODE, &ospf_cost_cmd);
10473 install_element(INTERFACE_NODE, &no_ospf_cost_cmd);
10474 install_element(INTERFACE_NODE, &ospf_network_cmd);
10475 install_element(INTERFACE_NODE, &no_ospf_network_cmd);
10476 install_element(INTERFACE_NODE, &ospf_priority_cmd);
10477 install_element(INTERFACE_NODE, &no_ospf_priority_cmd);
10478 install_element(INTERFACE_NODE, &ospf_retransmit_interval_cmd);
10479 install_element(INTERFACE_NODE, &no_ospf_retransmit_interval_cmd);
10480 install_element(INTERFACE_NODE, &ospf_transmit_delay_cmd);
10481 install_element(INTERFACE_NODE, &no_ospf_transmit_delay_cmd);
10482}
10483
10484static void ospf_vty_zebra_init(void)
10485{
10486 install_element(OSPF_NODE, &ospf_redistribute_source_cmd);
10487 install_element(OSPF_NODE, &no_ospf_redistribute_source_cmd);
10488 install_element(OSPF_NODE, &ospf_redistribute_instance_source_cmd);
10489 install_element(OSPF_NODE, &no_ospf_redistribute_instance_source_cmd);
10490
10491 install_element(OSPF_NODE, &ospf_distribute_list_out_cmd);
10492 install_element(OSPF_NODE, &no_ospf_distribute_list_out_cmd);
10493
10494 install_element(OSPF_NODE, &ospf_default_information_originate_cmd);
10495 install_element(OSPF_NODE, &no_ospf_default_information_originate_cmd);
10496
10497 install_element(OSPF_NODE, &ospf_default_metric_cmd);
10498 install_element(OSPF_NODE, &no_ospf_default_metric_cmd);
10499
10500 install_element(OSPF_NODE, &ospf_distance_cmd);
10501 install_element(OSPF_NODE, &no_ospf_distance_cmd);
10502 install_element(OSPF_NODE, &no_ospf_distance_ospf_cmd);
10503 install_element(OSPF_NODE, &ospf_distance_ospf_cmd);
718e3744 10504#if 0
10505 install_element (OSPF_NODE, &ospf_distance_source_cmd);
10506 install_element (OSPF_NODE, &no_ospf_distance_source_cmd);
10507 install_element (OSPF_NODE, &ospf_distance_source_access_list_cmd);
10508 install_element (OSPF_NODE, &no_ospf_distance_source_access_list_cmd);
10509#endif /* 0 */
10510}
10511
d62a17ae 10512static struct cmd_node ospf_node = {OSPF_NODE, "%s(config-router)# ", 1};
718e3744 10513
d62a17ae 10514static void ospf_interface_clear(struct interface *ifp)
09f35f8c 10515{
d62a17ae 10516 if (!if_is_operative(ifp))
10517 return;
09f35f8c 10518
d62a17ae 10519 if (IS_DEBUG_OSPF(ism, ISM_EVENTS))
10520 zlog_debug("ISM[%s]: clear by reset", ifp->name);
09f35f8c 10521
d62a17ae 10522 ospf_if_reset(ifp);
09f35f8c
DS
10523}
10524
10525DEFUN (clear_ip_ospf_interface,
10526 clear_ip_ospf_interface_cmd,
10527 "clear ip ospf interface [IFNAME]",
10528 CLEAR_STR
10529 IP_STR
10530 "OSPF information\n"
10531 "Interface information\n"
10532 "Interface name\n")
10533{
d62a17ae 10534 int idx_ifname = 4;
10535 struct interface *ifp;
f4e14fdb 10536 struct listnode *node;
b5a8894d 10537 struct ospf *ospf = NULL;
09f35f8c 10538
d62a17ae 10539 if (argc == 4) /* Clear all the ospfv2 interfaces. */
10540 {
f4e14fdb
RW
10541 for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
10542 struct vrf *vrf = vrf_lookup_by_id(ospf->vrf_id);
451fda4f 10543 FOR_ALL_INTERFACES (vrf, ifp)
b5a8894d
CS
10544 ospf_interface_clear(ifp);
10545 }
10546 } else {
10547 /* Interface name is specified. */
10548 ifp = if_lookup_by_name_all_vrf(argv[idx_ifname]->arg);
10549 if (ifp == NULL)
d62a17ae 10550 vty_out(vty, "No such interface name\n");
10551 else
10552 ospf_interface_clear(ifp);
10553 }
10554
10555 return CMD_SUCCESS;
09f35f8c
DS
10556}
10557
d62a17ae 10558void ospf_vty_clear_init(void)
09f35f8c 10559{
d62a17ae 10560 install_element(ENABLE_NODE, &clear_ip_ospf_interface_cmd);
09f35f8c
DS
10561}
10562
6b0655a2 10563
718e3744 10564/* Install OSPF related vty commands. */
d62a17ae 10565void ospf_vty_init(void)
10566{
10567 /* Install ospf top node. */
10568 install_node(&ospf_node, ospf_config_write);
10569
10570 /* "router ospf" commands. */
10571 install_element(CONFIG_NODE, &router_ospf_cmd);
10572 install_element(CONFIG_NODE, &no_router_ospf_cmd);
10573
10574
10575 install_default(OSPF_NODE);
10576
10577 /* "ospf router-id" commands. */
10578 install_element(OSPF_NODE, &ospf_router_id_cmd);
10579 install_element(OSPF_NODE, &ospf_router_id_old_cmd);
10580 install_element(OSPF_NODE, &no_ospf_router_id_cmd);
10581
10582 /* "passive-interface" commands. */
10583 install_element(OSPF_NODE, &ospf_passive_interface_addr_cmd);
10584 install_element(OSPF_NODE, &no_ospf_passive_interface_addr_cmd);
10585
10586 /* "ospf abr-type" commands. */
10587 install_element(OSPF_NODE, &ospf_abr_type_cmd);
10588 install_element(OSPF_NODE, &no_ospf_abr_type_cmd);
10589
10590 /* "ospf log-adjacency-changes" commands. */
10591 install_element(OSPF_NODE, &ospf_log_adjacency_changes_cmd);
10592 install_element(OSPF_NODE, &ospf_log_adjacency_changes_detail_cmd);
10593 install_element(OSPF_NODE, &no_ospf_log_adjacency_changes_cmd);
10594 install_element(OSPF_NODE, &no_ospf_log_adjacency_changes_detail_cmd);
10595
10596 /* "ospf rfc1583-compatible" commands. */
10597 install_element(OSPF_NODE, &ospf_compatible_rfc1583_cmd);
10598 install_element(OSPF_NODE, &no_ospf_compatible_rfc1583_cmd);
10599 install_element(OSPF_NODE, &ospf_rfc1583_flag_cmd);
10600 install_element(OSPF_NODE, &no_ospf_rfc1583_flag_cmd);
10601
10602 /* "network area" commands. */
10603 install_element(OSPF_NODE, &ospf_network_area_cmd);
10604 install_element(OSPF_NODE, &no_ospf_network_area_cmd);
10605
10606 /* "area authentication" commands. */
10607 install_element(OSPF_NODE,
10608 &ospf_area_authentication_message_digest_cmd);
10609 install_element(OSPF_NODE, &ospf_area_authentication_cmd);
10610 install_element(OSPF_NODE, &no_ospf_area_authentication_cmd);
10611
10612 /* "area range" commands. */
10613 install_element(OSPF_NODE, &ospf_area_range_cmd);
10614 install_element(OSPF_NODE, &ospf_area_range_cost_cmd);
10615 install_element(OSPF_NODE, &ospf_area_range_not_advertise_cmd);
10616 install_element(OSPF_NODE, &no_ospf_area_range_cmd);
10617 install_element(OSPF_NODE, &ospf_area_range_substitute_cmd);
10618 install_element(OSPF_NODE, &no_ospf_area_range_substitute_cmd);
10619
10620 /* "area virtual-link" commands. */
10621 install_element(OSPF_NODE, &ospf_area_vlink_cmd);
10622 install_element(OSPF_NODE, &ospf_area_vlink_intervals_cmd);
10623 install_element(OSPF_NODE, &no_ospf_area_vlink_cmd);
10624 install_element(OSPF_NODE, &no_ospf_area_vlink_intervals_cmd);
10625
10626
10627 /* "area stub" commands. */
10628 install_element(OSPF_NODE, &ospf_area_stub_no_summary_cmd);
10629 install_element(OSPF_NODE, &ospf_area_stub_cmd);
10630 install_element(OSPF_NODE, &no_ospf_area_stub_no_summary_cmd);
10631 install_element(OSPF_NODE, &no_ospf_area_stub_cmd);
10632
10633 /* "area nssa" commands. */
10634 install_element(OSPF_NODE, &ospf_area_nssa_cmd);
d62a17ae 10635 install_element(OSPF_NODE, &ospf_area_nssa_translate_cmd);
10636 install_element(OSPF_NODE, &ospf_area_nssa_no_summary_cmd);
7ef56a73 10637 install_element(OSPF_NODE, &no_ospf_area_nssa_no_summary_cmd);
d62a17ae 10638 install_element(OSPF_NODE, &no_ospf_area_nssa_cmd);
10639
10640 install_element(OSPF_NODE, &ospf_area_default_cost_cmd);
10641 install_element(OSPF_NODE, &no_ospf_area_default_cost_cmd);
10642
10643 install_element(OSPF_NODE, &ospf_area_shortcut_cmd);
10644 install_element(OSPF_NODE, &no_ospf_area_shortcut_cmd);
10645
10646 install_element(OSPF_NODE, &ospf_area_export_list_cmd);
10647 install_element(OSPF_NODE, &no_ospf_area_export_list_cmd);
10648
10649 install_element(OSPF_NODE, &ospf_area_filter_list_cmd);
10650 install_element(OSPF_NODE, &no_ospf_area_filter_list_cmd);
10651
10652 install_element(OSPF_NODE, &ospf_area_import_list_cmd);
10653 install_element(OSPF_NODE, &no_ospf_area_import_list_cmd);
10654
10655 /* SPF timer commands */
10656 install_element(OSPF_NODE, &ospf_timers_throttle_spf_cmd);
10657 install_element(OSPF_NODE, &no_ospf_timers_throttle_spf_cmd);
10658
10659 /* LSA timers commands */
10660 install_element(OSPF_NODE, &ospf_timers_min_ls_interval_cmd);
10661 install_element(OSPF_NODE, &no_ospf_timers_min_ls_interval_cmd);
0e88de35
QY
10662 install_element(OSPF_NODE, &ospf_timers_lsa_min_arrival_cmd);
10663 install_element(OSPF_NODE, &no_ospf_timers_lsa_min_arrival_cmd);
10664 install_element(OSPF_NODE, &ospf_timers_lsa_arrival_cmd);
10665 install_element(OSPF_NODE, &no_ospf_timers_lsa_arrival_cmd);
d62a17ae 10666
10667 /* refresh timer commands */
10668 install_element(OSPF_NODE, &ospf_refresh_timer_cmd);
10669 install_element(OSPF_NODE, &no_ospf_refresh_timer_val_cmd);
10670
10671 /* max-metric commands */
10672 install_element(OSPF_NODE, &ospf_max_metric_router_lsa_admin_cmd);
10673 install_element(OSPF_NODE, &no_ospf_max_metric_router_lsa_admin_cmd);
10674 install_element(OSPF_NODE, &ospf_max_metric_router_lsa_startup_cmd);
10675 install_element(OSPF_NODE, &no_ospf_max_metric_router_lsa_startup_cmd);
10676 install_element(OSPF_NODE, &ospf_max_metric_router_lsa_shutdown_cmd);
10677 install_element(OSPF_NODE, &no_ospf_max_metric_router_lsa_shutdown_cmd);
10678
10679 /* reference bandwidth commands */
10680 install_element(OSPF_NODE, &ospf_auto_cost_reference_bandwidth_cmd);
10681 install_element(OSPF_NODE, &no_ospf_auto_cost_reference_bandwidth_cmd);
10682
10683 /* "neighbor" commands. */
10684 install_element(OSPF_NODE, &ospf_neighbor_cmd);
10685 install_element(OSPF_NODE, &ospf_neighbor_poll_interval_cmd);
10686 install_element(OSPF_NODE, &no_ospf_neighbor_cmd);
10687 install_element(OSPF_NODE, &no_ospf_neighbor_poll_cmd);
10688
10689 /* write multiplier commands */
10690 install_element(OSPF_NODE, &ospf_write_multiplier_cmd);
10691 install_element(OSPF_NODE, &write_multiplier_cmd);
10692 install_element(OSPF_NODE, &no_ospf_write_multiplier_cmd);
10693 install_element(OSPF_NODE, &no_write_multiplier_cmd);
10694
10695 /* Init interface related vty commands. */
10696 ospf_vty_if_init();
10697
10698 /* Init zebra related vty commands. */
10699 ospf_vty_zebra_init();
718e3744 10700}