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