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