]> git.proxmox.com Git - mirror_frr.git/blame - ospfd/ospf_vty.c
*: reindent
[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{
d62a17ae 194 VTY_DECLVAR_CONTEXT(ospf, ospf);
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{
d62a17ae 228 VTY_DECLVAR_CONTEXT(ospf, ospf);
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{
d62a17ae 264 VTY_DECLVAR_CONTEXT(ospf, ospf);
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)) {
293 if (ifp && OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(ifp),
294 passive_interface))
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{
d62a17ae 353 VTY_DECLVAR_CONTEXT(ospf, ospf);
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
397 if (oi && (OSPF_IF_PARAM(oi, passive_interface)
398 == OSPF_IF_PASSIVE))
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{
d62a17ae 420 VTY_DECLVAR_CONTEXT(ospf, ospf);
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{
d62a17ae 481 VTY_DECLVAR_CONTEXT(ospf, ospf);
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{
d62a17ae 523 VTY_DECLVAR_CONTEXT(ospf, ospf);
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{
d62a17ae 562 VTY_DECLVAR_CONTEXT(ospf, ospf);
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{
d62a17ae 594 VTY_DECLVAR_CONTEXT(ospf, ospf);
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{
d62a17ae 626 VTY_DECLVAR_CONTEXT(ospf, ospf);
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{
d62a17ae 659 VTY_DECLVAR_CONTEXT(ospf, ospf);
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{
d62a17ae 685 VTY_DECLVAR_CONTEXT(ospf, ospf);
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{
d62a17ae 716 VTY_DECLVAR_CONTEXT(ospf, ospf);
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{
d62a17ae 984 VTY_DECLVAR_CONTEXT(ospf, ospf);
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{
d62a17ae 1108 VTY_DECLVAR_CONTEXT(ospf, ospf);
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{
d62a17ae 1207 VTY_DECLVAR_CONTEXT(ospf, ospf);
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{
d62a17ae 1254 VTY_DECLVAR_CONTEXT(ospf, ospf);
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{
d62a17ae 1303 VTY_DECLVAR_CONTEXT(ospf, ospf);
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{
d62a17ae 1347 VTY_DECLVAR_CONTEXT(ospf, ospf);
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{
d62a17ae 1374 VTY_DECLVAR_CONTEXT(ospf, ospf);
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{
d62a17ae 1405 VTY_DECLVAR_CONTEXT(ospf, ospf);
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{
d62a17ae 1436 VTY_DECLVAR_CONTEXT(ospf, ospf);
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{
d62a17ae 1460 VTY_DECLVAR_CONTEXT(ospf, ospf);
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{
d62a17ae 1475 VTY_DECLVAR_CONTEXT(ospf, ospf);
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{
d62a17ae 1580 VTY_DECLVAR_CONTEXT(ospf, ospf);
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{
d62a17ae 1606 VTY_DECLVAR_CONTEXT(ospf, ospf);
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{
d62a17ae 1652 VTY_DECLVAR_CONTEXT(ospf, ospf);
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{
d62a17ae 1698 VTY_DECLVAR_CONTEXT(ospf, ospf);
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{
d62a17ae 1723 VTY_DECLVAR_CONTEXT(ospf, ospf);
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{
d62a17ae 1750 VTY_DECLVAR_CONTEXT(ospf, ospf);
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{
d62a17ae 1775 VTY_DECLVAR_CONTEXT(ospf, ospf);
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{
d62a17ae 1804 VTY_DECLVAR_CONTEXT(ospf, ospf);
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{
d62a17ae 1850 VTY_DECLVAR_CONTEXT(ospf, ospf);
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{
d62a17ae 1904 VTY_DECLVAR_CONTEXT(ospf, ospf);
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{
d62a17ae 1927 VTY_DECLVAR_CONTEXT(ospf, ospf);
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{
d62a17ae 1951 VTY_DECLVAR_CONTEXT(ospf, ospf);
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{
d62a17ae 1981 VTY_DECLVAR_CONTEXT(ospf, ospf);
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{
d62a17ae 2016 VTY_DECLVAR_CONTEXT(ospf, ospf);
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{
d62a17ae 2045 VTY_DECLVAR_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{
d62a17ae 2058 VTY_DECLVAR_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{
d62a17ae 2071 VTY_DECLVAR_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{
d62a17ae 2085 VTY_DECLVAR_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{
d62a17ae 2097 VTY_DECLVAR_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{
d62a17ae 2113 VTY_DECLVAR_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,
2128 "no ospf rfc1583compatibility", NO_STR
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{
d62a17ae 2135 VTY_DECLVAR_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{
d62a17ae 2153 VTY_DECLVAR_CONTEXT(ospf, ospf);
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{
d62a17ae 2179 VTY_DECLVAR_CONTEXT(ospf, ospf);
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{
d62a17ae 2194 VTY_DECLVAR_CONTEXT(ospf, ospf);
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{
d62a17ae 2219 VTY_DECLVAR_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{
d62a17ae 2279 VTY_DECLVAR_CONTEXT(ospf, ospf);
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{
d62a17ae 2304 VTY_DECLVAR_CONTEXT(ospf, ospf);
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{
d62a17ae 2330 VTY_DECLVAR_CONTEXT(ospf, ospf);
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{
d62a17ae 2367 VTY_DECLVAR_CONTEXT(ospf, ospf);
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{
d62a17ae 2402 VTY_DECLVAR_CONTEXT(ospf, ospf);
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{
d62a17ae 2424 VTY_DECLVAR_CONTEXT(ospf, ospf);
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{
d62a17ae 2442 VTY_DECLVAR_CONTEXT(ospf, ospf);
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{
d62a17ae 2463 VTY_DECLVAR_CONTEXT(ospf, ospf);
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{
d62a17ae 2488 VTY_DECLVAR_CONTEXT(ospf, ospf);
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{
d62a17ae 2519 VTY_DECLVAR_CONTEXT(ospf, ospf);
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{
d62a17ae 2544 VTY_DECLVAR_CONTEXT(ospf, ospf);
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{
d62a17ae 2575 VTY_DECLVAR_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,
2582 "no write-multiplier (1-100)", NO_STR
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);
3180 vty_out(vty, "%s\n", json_object_to_json_string_ext(
3181 json, JSON_C_TO_STRING_PRETTY));
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
3325 * probably more
3326 * * * * * informative than the local
3327 * interface that is being used
3328 * * * * */
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) {
3609 vty_out(vty, "%s\n", json_object_to_json_string_ext(
3610 json, JSON_C_TO_STRING_PRETTY));
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) {
3820 vty_out(vty, "%s\n", json_object_to_json_string_ext(
3821 json, JSON_C_TO_STRING_PRETTY));
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) {
3940 vty_out(vty, "%s\n", json_object_to_json_string_ext(
3941 json, JSON_C_TO_STRING_PRETTY));
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) {
4033 vty_out(vty, "%s\n", json_object_to_json_string_ext(
4034 json, JSON_C_TO_STRING_PRETTY));
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");
4405 return CMD_WARNING;
4406 }
4407
4408 for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) {
4409 if ((nbr = ospf_nbr_lookup_by_routerid(oi->nbrs, &router_id))) {
4410 show_ip_ospf_neighbor_detail_sub(vty, oi, nbr, use_json,
4411 json);
4412 }
4413 }
4414
4415 if (use_json) {
4416 vty_out(vty, "%s\n", json_object_to_json_string_ext(
4417 json, JSON_C_TO_STRING_PRETTY));
4418 json_object_free(json);
4419 } else
4420 vty_out(vty, "\n");
4421
4422 return CMD_SUCCESS;
718e3744 4423}
4424
7c8ff89e
DS
4425DEFUN (show_ip_ospf_neighbor_id,
4426 show_ip_ospf_neighbor_id_cmd,
b162fa78 4427 "show ip ospf neighbor A.B.C.D [json]",
718e3744 4428 SHOW_STR
4429 IP_STR
4430 "OSPF information\n"
4431 "Neighbor list\n"
3ac237f8 4432 "Neighbor ID\n"
9973d184 4433 JSON_STR)
718e3744 4434{
d62a17ae 4435 struct ospf *ospf;
4436 u_char uj = use_json(argc, argv);
7c8ff89e 4437
d62a17ae 4438 if ((ospf = ospf_lookup()) == NULL || !ospf->oi_running)
4439 return CMD_SUCCESS;
7c8ff89e 4440
d62a17ae 4441 return show_ip_ospf_neighbor_id_common(vty, ospf, 0, argv, uj);
7c8ff89e
DS
4442}
4443
4444DEFUN (show_ip_ospf_instance_neighbor_id,
4445 show_ip_ospf_instance_neighbor_id_cmd,
6147e2c6 4446 "show ip ospf (1-65535) neighbor A.B.C.D [json]",
7c8ff89e
DS
4447 SHOW_STR
4448 IP_STR
4449 "OSPF information\n"
4450 "Instance ID\n"
4451 "Neighbor list\n"
3ac237f8 4452 "Neighbor ID\n"
9973d184 4453 JSON_STR)
7c8ff89e 4454{
d62a17ae 4455 int idx_number = 3;
4456 struct ospf *ospf;
4457 u_short instance = 0;
4458 u_char uj = use_json(argc, argv);
7c8ff89e 4459
d62a17ae 4460 instance = strtoul(argv[idx_number]->arg, NULL, 10);
4461 if ((ospf = ospf_lookup_instance(instance)) == NULL
4462 || !ospf->oi_running)
4463 return CMD_SUCCESS;
7c8ff89e 4464
d62a17ae 4465 return show_ip_ospf_neighbor_id_common(vty, ospf, 1, argv, uj);
7c8ff89e
DS
4466}
4467
d62a17ae 4468static int show_ip_ospf_neighbor_detail_common(struct vty *vty,
4469 struct ospf *ospf,
4470 u_char use_json)
4471{
4472 struct ospf_interface *oi;
4473 struct listnode *node;
4474 json_object *json = NULL;
3ac237f8 4475
d62a17ae 4476 if (use_json)
4477 json = json_object_new_object();
4478
4479 if (ospf->instance) {
4480 if (use_json)
4481 json_object_int_add(json, "ospfInstance",
4482 ospf->instance);
4483 else
4484 vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
4485 }
4486
4487 for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) {
4488 struct route_node *rn;
4489 struct ospf_neighbor *nbr;
4490
4491 for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) {
4492 if ((nbr = rn->info)) {
4493 if (nbr != oi->nbr_self) {
4494 if (nbr->state != NSM_Down) {
4495 show_ip_ospf_neighbor_detail_sub(
4496 vty, oi, nbr, use_json,
4497 json);
4498 }
4499 }
4500 }
4501 }
4502 }
4503
4504 if (use_json) {
4505 vty_out(vty, "%s\n", json_object_to_json_string_ext(
4506 json, JSON_C_TO_STRING_PRETTY));
4507 json_object_free(json);
4508 } else
4509 vty_out(vty, "\n");
4510
4511 return CMD_SUCCESS;
718e3744 4512}
4513
7c8ff89e
DS
4514DEFUN (show_ip_ospf_neighbor_detail,
4515 show_ip_ospf_neighbor_detail_cmd,
b162fa78 4516 "show ip ospf neighbor detail [json]",
718e3744 4517 SHOW_STR
4518 IP_STR
4519 "OSPF information\n"
4520 "Neighbor list\n"
3ac237f8 4521 "detail of all neighbors\n"
9973d184 4522 JSON_STR)
718e3744 4523{
d62a17ae 4524 struct ospf *ospf;
4525 u_char uj = use_json(argc, argv);
7c8ff89e 4526
d62a17ae 4527 if ((ospf = ospf_lookup()) == NULL || !ospf->oi_running)
4528 return CMD_SUCCESS;
7c8ff89e 4529
d62a17ae 4530 return show_ip_ospf_neighbor_detail_common(vty, ospf, uj);
7c8ff89e
DS
4531}
4532
4533DEFUN (show_ip_ospf_instance_neighbor_detail,
4534 show_ip_ospf_instance_neighbor_detail_cmd,
6147e2c6 4535 "show ip ospf (1-65535) neighbor detail [json]",
7c8ff89e
DS
4536 SHOW_STR
4537 IP_STR
4538 "OSPF information\n"
4539 "Instance ID\n"
4540 "Neighbor list\n"
3ac237f8 4541 "detail of all neighbors\n"
9973d184 4542 JSON_STR)
7c8ff89e 4543{
d62a17ae 4544 int idx_number = 3;
4545 struct ospf *ospf;
4546 u_short instance = 0;
4547 u_char uj = use_json(argc, argv);
7c8ff89e 4548
d62a17ae 4549 instance = strtoul(argv[idx_number]->arg, NULL, 10);
4550 if ((ospf = ospf_lookup_instance(instance)) == NULL
4551 || !ospf->oi_running)
4552 return CMD_SUCCESS;
7c8ff89e 4553
d62a17ae 4554 return show_ip_ospf_neighbor_detail_common(vty, ospf, uj);
7c8ff89e
DS
4555}
4556
d62a17ae 4557static int show_ip_ospf_neighbor_detail_all_common(struct vty *vty,
4558 struct ospf *ospf,
4559 u_char use_json)
4560{
4561 struct listnode *node;
4562 struct ospf_interface *oi;
4563 json_object *json = NULL;
718e3744 4564
d62a17ae 4565 if (use_json)
4566 json = json_object_new_object();
4567
4568 if (ospf->instance) {
4569 if (use_json)
4570 json_object_int_add(json, "ospfInstance",
4571 ospf->instance);
4572 else
4573 vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
4574 }
4575
4576 for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) {
4577 struct route_node *rn;
4578 struct ospf_neighbor *nbr;
4579 struct ospf_nbr_nbma *nbr_nbma;
4580
4581 for (rn = route_top(oi->nbrs); rn; rn = route_next(rn))
4582 if ((nbr = rn->info))
4583 if (nbr != oi->nbr_self)
4584 if (nbr->state != NSM_Down)
4585 show_ip_ospf_neighbor_detail_sub(
4586 vty, oi, rn->info,
4587 use_json, json);
4588
4589 if (oi->type == OSPF_IFTYPE_NBMA) {
4590 struct listnode *nd;
4591
4592 for (ALL_LIST_ELEMENTS_RO(oi->nbr_nbma, nd, nbr_nbma)) {
4593 if (nbr_nbma->nbr == NULL
4594 || nbr_nbma->nbr->state == NSM_Down)
4595 show_ip_ospf_nbr_nbma_detail_sub(
4596 vty, oi, nbr_nbma, use_json,
4597 json);
4598 }
4599 }
4600 }
4601
4602 if (use_json) {
4603 vty_out(vty, "%s\n", json_object_to_json_string_ext(
4604 json, JSON_C_TO_STRING_PRETTY));
4605 json_object_free(json);
4606 } else {
4607 vty_out(vty, "\n");
4608 }
4609
4610 return CMD_SUCCESS;
718e3744 4611}
4612
7c8ff89e
DS
4613DEFUN (show_ip_ospf_neighbor_detail_all,
4614 show_ip_ospf_neighbor_detail_all_cmd,
b162fa78 4615 "show ip ospf neighbor detail all [json]",
718e3744 4616 SHOW_STR
4617 IP_STR
4618 "OSPF information\n"
4619 "Neighbor list\n"
7c8ff89e 4620 "detail of all neighbors\n"
3ac237f8 4621 "include down status neighbor\n"
9973d184 4622 JSON_STR)
718e3744 4623{
d62a17ae 4624 struct ospf *ospf;
4625 u_char uj = use_json(argc, argv);
7c8ff89e 4626
d62a17ae 4627 if ((ospf = ospf_lookup()) == NULL || !ospf->oi_running)
4628 return CMD_SUCCESS;
7c8ff89e 4629
d62a17ae 4630 return show_ip_ospf_neighbor_detail_all_common(vty, ospf, uj);
7c8ff89e
DS
4631}
4632
4633DEFUN (show_ip_ospf_instance_neighbor_detail_all,
4634 show_ip_ospf_instance_neighbor_detail_all_cmd,
6147e2c6 4635 "show ip ospf (1-65535) neighbor detail all [json]",
7c8ff89e
DS
4636 SHOW_STR
4637 IP_STR
4638 "OSPF information\n"
4639 "Instance ID\n"
4640 "Neighbor list\n"
4641 "detail of all neighbors\n"
3ac237f8 4642 "include down status neighbor\n"
9973d184 4643 JSON_STR)
7c8ff89e 4644{
d62a17ae 4645 int idx_number = 3;
4646 struct ospf *ospf;
4647 u_short instance = 0;
4648 u_char uj = use_json(argc, argv);
7c8ff89e 4649
d62a17ae 4650 instance = strtoul(argv[idx_number]->arg, NULL, 10);
4651 if ((ospf = ospf_lookup_instance(instance)) == NULL
4652 || !ospf->oi_running)
4653 return CMD_SUCCESS;
7c8ff89e 4654
d62a17ae 4655 return show_ip_ospf_neighbor_detail_all_common(vty, ospf, uj);
7c8ff89e
DS
4656}
4657
d62a17ae 4658static int show_ip_ospf_neighbor_int_detail_common(struct vty *vty,
4659 struct ospf *ospf,
4660 int arg_base,
4661 struct cmd_token **argv,
4662 u_char use_json)
4663{
4664 struct ospf_interface *oi;
4665 struct interface *ifp;
4666 struct route_node *rn, *nrn;
4667 struct ospf_neighbor *nbr;
4668 json_object *json = NULL;
718e3744 4669
d62a17ae 4670 if (use_json)
4671 json = json_object_new_object();
4672
4673 if (ospf->instance) {
4674 if (use_json)
4675 json_object_int_add(json, "ospfInstance",
4676 ospf->instance);
4677 else
4678 vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
4679 }
4680
4681 ifp = if_lookup_by_name(argv[arg_base]->arg, VRF_DEFAULT);
4682 if (!ifp) {
4683 if (!use_json)
4684 vty_out(vty, "No such interface.\n");
4685 return CMD_WARNING;
4686 }
4687
4688 for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) {
4689 if ((oi = rn->info)) {
4690 for (nrn = route_top(oi->nbrs); nrn;
4691 nrn = route_next(nrn)) {
4692 if ((nbr = nrn->info)) {
4693 if (nbr != oi->nbr_self) {
4694 if (nbr->state != NSM_Down)
4695 show_ip_ospf_neighbor_detail_sub(
4696 vty, oi, nbr,
4697 use_json, json);
4698 }
4699 }
4700 }
4701 }
4702 }
4703
4704 if (use_json) {
4705 vty_out(vty, "%s\n", json_object_to_json_string_ext(
4706 json, JSON_C_TO_STRING_PRETTY));
4707 json_object_free(json);
4708 } else
4709 vty_out(vty, "\n");
4710
4711 return CMD_SUCCESS;
718e3744 4712}
4713
7c8ff89e
DS
4714DEFUN (show_ip_ospf_neighbor_int_detail,
4715 show_ip_ospf_neighbor_int_detail_cmd,
b162fa78 4716 "show ip ospf neighbor IFNAME detail [json]",
7c8ff89e
DS
4717 SHOW_STR
4718 IP_STR
4719 "OSPF information\n"
4720 "Neighbor list\n"
4721 "Interface name\n"
3ac237f8 4722 "detail of all neighbors\n"
9973d184 4723 JSON_STR)
7c8ff89e 4724{
d62a17ae 4725 struct ospf *ospf;
4726 u_char uj = use_json(argc, argv);
7c8ff89e 4727
d62a17ae 4728 if ((ospf = ospf_lookup()) == NULL || !ospf->oi_running)
4729 return CMD_SUCCESS;
7c8ff89e 4730
d62a17ae 4731 return show_ip_ospf_neighbor_int_detail_common(vty, ospf, 0, argv, uj);
7c8ff89e
DS
4732}
4733
4734DEFUN (show_ip_ospf_instance_neighbor_int_detail,
4735 show_ip_ospf_instance_neighbor_int_detail_cmd,
6147e2c6 4736 "show ip ospf (1-65535) neighbor IFNAME detail [json]",
7c8ff89e
DS
4737 SHOW_STR
4738 IP_STR
4739 "OSPF information\n"
4740 "Instance ID\n"
4741 "Neighbor list\n"
4742 "Interface name\n"
3ac237f8 4743 "detail of all neighbors\n"
9973d184 4744 JSON_STR)
7c8ff89e 4745{
d62a17ae 4746 int idx_number = 3;
4747 struct ospf *ospf;
4748 u_short instance = 0;
4749 u_char uj = use_json(argc, argv);
7c8ff89e 4750
d62a17ae 4751 instance = strtoul(argv[idx_number]->arg, NULL, 10);
4752 if ((ospf = ospf_lookup_instance(instance)) == NULL
4753 || !ospf->oi_running)
4754 return CMD_SUCCESS;
7c8ff89e 4755
d62a17ae 4756 return show_ip_ospf_neighbor_int_detail_common(vty, ospf, 1, argv, uj);
7c8ff89e 4757}
6b0655a2 4758
718e3744 4759/* Show functions */
d62a17ae 4760static int show_lsa_summary(struct vty *vty, struct ospf_lsa *lsa, int self)
4761{
4762 struct router_lsa *rl;
4763 struct summary_lsa *sl;
4764 struct as_external_lsa *asel;
4765 struct prefix_ipv4 p;
4766
4767 if (lsa != NULL)
4768 /* If self option is set, check LSA self flag. */
4769 if (self == 0 || IS_LSA_SELF(lsa)) {
4770 /* LSA common part show. */
4771 vty_out(vty, "%-15s ", inet_ntoa(lsa->data->id));
4772 vty_out(vty, "%-15s %4d 0x%08lx 0x%04x",
4773 inet_ntoa(lsa->data->adv_router), LS_AGE(lsa),
4774 (u_long)ntohl(lsa->data->ls_seqnum),
4775 ntohs(lsa->data->checksum));
4776 /* LSA specific part show. */
4777 switch (lsa->data->type) {
4778 case OSPF_ROUTER_LSA:
4779 rl = (struct router_lsa *)lsa->data;
4780 vty_out(vty, " %-d", ntohs(rl->links));
4781 break;
4782 case OSPF_SUMMARY_LSA:
4783 sl = (struct summary_lsa *)lsa->data;
4784
4785 p.family = AF_INET;
4786 p.prefix = sl->header.id;
4787 p.prefixlen = ip_masklen(sl->mask);
4788 apply_mask_ipv4(&p);
4789
4790 vty_out(vty, " %s/%d", inet_ntoa(p.prefix),
4791 p.prefixlen);
4792 break;
4793 case OSPF_AS_EXTERNAL_LSA:
4794 case OSPF_AS_NSSA_LSA:
4795 asel = (struct as_external_lsa *)lsa->data;
4796
4797 p.family = AF_INET;
4798 p.prefix = asel->header.id;
4799 p.prefixlen = ip_masklen(asel->mask);
4800 apply_mask_ipv4(&p);
4801
4802 vty_out(vty, " %s %s/%d [0x%lx]",
4803 IS_EXTERNAL_METRIC(asel->e[0].tos)
4804 ? "E2"
4805 : "E1",
4806 inet_ntoa(p.prefix), p.prefixlen,
4807 (u_long)ntohl(asel->e[0].route_tag));
4808 break;
4809 case OSPF_NETWORK_LSA:
4810 case OSPF_ASBR_SUMMARY_LSA:
4811 case OSPF_OPAQUE_LINK_LSA:
4812 case OSPF_OPAQUE_AREA_LSA:
4813 case OSPF_OPAQUE_AS_LSA:
4814 default:
4815 break;
4816 }
4817 vty_out(vty, "\n");
4818 }
718e3744 4819
d62a17ae 4820 return 0;
4821}
4822
4823static const char *show_database_desc[] = {
4824 "unknown",
4825 "Router Link States",
4826 "Net Link States",
4827 "Summary Link States",
4828 "ASBR-Summary Link States",
4829 "AS External Link States",
4830 "Group Membership LSA",
4831 "NSSA-external Link States",
4832 "Type-8 LSA",
4833 "Link-Local Opaque-LSA",
4834 "Area-Local Opaque-LSA",
4835 "AS-external Opaque-LSA",
718e3744 4836};
4837
d62a17ae 4838static const char *show_database_header[] = {
4839 "",
4840 "Link ID ADV Router Age Seq# CkSum Link count",
4841 "Link ID ADV Router Age Seq# CkSum",
4842 "Link ID ADV Router Age Seq# CkSum Route",
4843 "Link ID ADV Router Age Seq# CkSum",
4844 "Link ID ADV Router Age Seq# CkSum Route",
4845 " --- header for Group Member ----",
4846 "Link ID ADV Router Age Seq# CkSum Route",
4847 " --- type-8 ---",
4848 "Opaque-Type/Id ADV Router Age Seq# CkSum",
4849 "Opaque-Type/Id ADV Router Age Seq# CkSum",
4850 "Opaque-Type/Id ADV Router Age Seq# CkSum",
718e3744 4851};
4852
d62a17ae 4853static void show_ip_ospf_database_header(struct vty *vty, struct ospf_lsa *lsa)
4854{
4855 struct router_lsa *rlsa = (struct router_lsa *)lsa->data;
4856
4857 vty_out(vty, " LS age: %d\n", LS_AGE(lsa));
4858 vty_out(vty, " Options: 0x%-2x : %s\n", lsa->data->options,
4859 ospf_options_dump(lsa->data->options));
4860 vty_out(vty, " LS Flags: 0x%-2x %s\n", lsa->flags,
4861 ((lsa->flags & OSPF_LSA_LOCAL_XLT) ? "(Translated from Type-7)"
4862 : ""));
4863
4864 if (lsa->data->type == OSPF_ROUTER_LSA) {
4865 vty_out(vty, " Flags: 0x%x", rlsa->flags);
4866
4867 if (rlsa->flags)
4868 vty_out(vty, " :%s%s%s%s",
4869 IS_ROUTER_LSA_BORDER(rlsa) ? " ABR" : "",
4870 IS_ROUTER_LSA_EXTERNAL(rlsa) ? " ASBR" : "",
4871 IS_ROUTER_LSA_VIRTUAL(rlsa) ? " VL-endpoint"
4872 : "",
4873 IS_ROUTER_LSA_SHORTCUT(rlsa) ? " Shortcut"
4874 : "");
4875
4876 vty_out(vty, "\n");
4877 }
4878 vty_out(vty, " LS Type: %s\n",
4879 lookup_msg(ospf_lsa_type_msg, lsa->data->type, NULL));
4880 vty_out(vty, " Link State ID: %s %s\n", inet_ntoa(lsa->data->id),
4881 lookup_msg(ospf_link_state_id_type_msg, lsa->data->type, NULL));
4882 vty_out(vty, " Advertising Router: %s\n",
4883 inet_ntoa(lsa->data->adv_router));
4884 vty_out(vty, " LS Seq Number: %08lx\n",
4885 (u_long)ntohl(lsa->data->ls_seqnum));
4886 vty_out(vty, " Checksum: 0x%04x\n", ntohs(lsa->data->checksum));
4887 vty_out(vty, " Length: %d\n\n", ntohs(lsa->data->length));
4888}
4889
4890const char *link_type_desc[] = {
4891 "(null)",
4892 "another Router (point-to-point)",
4893 "a Transit Network",
4894 "Stub Network",
4895 "a Virtual Link",
718e3744 4896};
4897
d62a17ae 4898const char *link_id_desc[] = {
4899 "(null)", "Neighboring Router ID", "Designated Router address",
4900 "Net", "Neighboring Router ID",
718e3744 4901};
4902
d62a17ae 4903const char *link_data_desc[] = {
4904 "(null)", "Router Interface address", "Router Interface address",
4905 "Network Mask", "Router Interface address",
718e3744 4906};
4907
4908/* Show router-LSA each Link information. */
d62a17ae 4909static void show_ip_ospf_database_router_links(struct vty *vty,
4910 struct router_lsa *rl)
4911{
4912 int len, type;
4913 unsigned int i;
4914
4915 len = ntohs(rl->header.length) - 4;
4916 for (i = 0; i < ntohs(rl->links) && len > 0; len -= 12, i++) {
4917 type = rl->link[i].type;
4918
4919 vty_out(vty, " Link connected to: %s\n",
4920 link_type_desc[type]);
4921 vty_out(vty, " (Link ID) %s: %s\n", link_id_desc[type],
4922 inet_ntoa(rl->link[i].link_id));
4923 vty_out(vty, " (Link Data) %s: %s\n", link_data_desc[type],
4924 inet_ntoa(rl->link[i].link_data));
4925 vty_out(vty, " Number of TOS metrics: 0\n");
4926 vty_out(vty, " TOS 0 Metric: %d\n",
4927 ntohs(rl->link[i].metric));
4928 vty_out(vty, "\n");
4929 }
718e3744 4930}
4931
4932/* Show router-LSA detail information. */
d62a17ae 4933static int show_router_lsa_detail(struct vty *vty, struct ospf_lsa *lsa)
718e3744 4934{
d62a17ae 4935 if (lsa != NULL) {
4936 struct router_lsa *rl = (struct router_lsa *)lsa->data;
718e3744 4937
d62a17ae 4938 show_ip_ospf_database_header(vty, lsa);
718e3744 4939
d62a17ae 4940 vty_out(vty, " Number of Links: %d\n\n", ntohs(rl->links));
718e3744 4941
d62a17ae 4942 show_ip_ospf_database_router_links(vty, rl);
4943 vty_out(vty, "\n");
4944 }
4945
4946 return 0;
718e3744 4947}
4948
4949/* Show network-LSA detail information. */
d62a17ae 4950static int show_network_lsa_detail(struct vty *vty, struct ospf_lsa *lsa)
718e3744 4951{
d62a17ae 4952 int length, i;
718e3744 4953
d62a17ae 4954 if (lsa != NULL) {
4955 struct network_lsa *nl = (struct network_lsa *)lsa->data;
718e3744 4956
d62a17ae 4957 show_ip_ospf_database_header(vty, lsa);
718e3744 4958
d62a17ae 4959 vty_out(vty, " Network Mask: /%d\n", ip_masklen(nl->mask));
718e3744 4960
d62a17ae 4961 length = ntohs(lsa->data->length) - OSPF_LSA_HEADER_SIZE - 4;
718e3744 4962
d62a17ae 4963 for (i = 0; length > 0; i++, length -= 4)
4964 vty_out(vty, " Attached Router: %s\n",
4965 inet_ntoa(nl->routers[i]));
718e3744 4966
d62a17ae 4967 vty_out(vty, "\n");
4968 }
718e3744 4969
d62a17ae 4970 return 0;
718e3744 4971}
4972
4973/* Show summary-LSA detail information. */
d62a17ae 4974static int show_summary_lsa_detail(struct vty *vty, struct ospf_lsa *lsa)
718e3744 4975{
d62a17ae 4976 if (lsa != NULL) {
4977 struct summary_lsa *sl = (struct summary_lsa *)lsa->data;
718e3744 4978
d62a17ae 4979 show_ip_ospf_database_header(vty, lsa);
718e3744 4980
d62a17ae 4981 vty_out(vty, " Network Mask: /%d\n", ip_masklen(sl->mask));
4982 vty_out(vty, " TOS: 0 Metric: %d\n",
4983 GET_METRIC(sl->metric));
4984 vty_out(vty, "\n");
4985 }
718e3744 4986
d62a17ae 4987 return 0;
718e3744 4988}
4989
4990/* Show summary-ASBR-LSA detail information. */
d62a17ae 4991static int show_summary_asbr_lsa_detail(struct vty *vty, struct ospf_lsa *lsa)
718e3744 4992{
d62a17ae 4993 if (lsa != NULL) {
4994 struct summary_lsa *sl = (struct summary_lsa *)lsa->data;
718e3744 4995
d62a17ae 4996 show_ip_ospf_database_header(vty, lsa);
718e3744 4997
d62a17ae 4998 vty_out(vty, " Network Mask: /%d\n", ip_masklen(sl->mask));
4999 vty_out(vty, " TOS: 0 Metric: %d\n",
5000 GET_METRIC(sl->metric));
5001 vty_out(vty, "\n");
5002 }
718e3744 5003
d62a17ae 5004 return 0;
718e3744 5005}
5006
5007/* Show AS-external-LSA detail information. */
d62a17ae 5008static int show_as_external_lsa_detail(struct vty *vty, struct ospf_lsa *lsa)
5009{
5010 if (lsa != NULL) {
5011 struct as_external_lsa *al =
5012 (struct as_external_lsa *)lsa->data;
5013
5014 show_ip_ospf_database_header(vty, lsa);
5015
5016 vty_out(vty, " Network Mask: /%d\n", ip_masklen(al->mask));
5017 vty_out(vty, " Metric Type: %s\n",
5018 IS_EXTERNAL_METRIC(al->e[0].tos)
5019 ? "2 (Larger than any link state path)"
5020 : "1");
5021 vty_out(vty, " TOS: 0\n");
5022 vty_out(vty, " Metric: %d\n",
5023 GET_METRIC(al->e[0].metric));
5024 vty_out(vty, " Forward Address: %s\n",
5025 inet_ntoa(al->e[0].fwd_addr));
5026
5027 vty_out(vty,
5028 " External Route Tag: %" ROUTE_TAG_PRI "\n\n",
5029 (route_tag_t)ntohl(al->e[0].route_tag));
5030 }
718e3744 5031
d62a17ae 5032 return 0;
718e3744 5033}
075e12f5 5034#if 0
4dadc291 5035static int
718e3744 5036show_as_external_lsa_stdvty (struct ospf_lsa *lsa)
5037{
5038 struct as_external_lsa *al = (struct as_external_lsa *) lsa->data;
5039
5040 /* show_ip_ospf_database_header (vty, lsa); */
5041
2a42e285 5042 zlog_debug( " Network Mask: /%d%s",
718e3744 5043 ip_masklen (al->mask), "\n");
2a42e285 5044 zlog_debug( " Metric Type: %s%s",
718e3744 5045 IS_EXTERNAL_METRIC (al->e[0].tos) ?
5046 "2 (Larger than any link state path)" : "1", "\n");
2a42e285 5047 zlog_debug( " TOS: 0%s", "\n");
5048 zlog_debug( " Metric: %d%s",
718e3744 5049 GET_METRIC (al->e[0].metric), "\n");
2a42e285 5050 zlog_debug( " Forward Address: %s%s",
718e3744 5051 inet_ntoa (al->e[0].fwd_addr), "\n");
5052
dc9ffce8
CF
5053 zlog_debug( " External Route Tag: %"ROUTE_TAG_PRI"%s%s",
5054 (route_tag_t)ntohl (al->e[0].route_tag), "\n", "\n");
718e3744 5055
5056 return 0;
5057}
075e12f5 5058#endif
718e3744 5059/* Show AS-NSSA-LSA detail information. */
d62a17ae 5060static int show_as_nssa_lsa_detail(struct vty *vty, struct ospf_lsa *lsa)
5061{
5062 if (lsa != NULL) {
5063 struct as_external_lsa *al =
5064 (struct as_external_lsa *)lsa->data;
5065
5066 show_ip_ospf_database_header(vty, lsa);
5067
5068 vty_out(vty, " Network Mask: /%d\n", ip_masklen(al->mask));
5069 vty_out(vty, " Metric Type: %s\n",
5070 IS_EXTERNAL_METRIC(al->e[0].tos)
5071 ? "2 (Larger than any link state path)"
5072 : "1");
5073 vty_out(vty, " TOS: 0\n");
5074 vty_out(vty, " Metric: %d\n",
5075 GET_METRIC(al->e[0].metric));
5076 vty_out(vty, " NSSA: Forward Address: %s\n",
5077 inet_ntoa(al->e[0].fwd_addr));
5078
5079 vty_out(vty,
5080 " External Route Tag: %" ROUTE_TAG_PRI "\n\n",
5081 (route_tag_t)ntohl(al->e[0].route_tag));
5082 }
718e3744 5083
d62a17ae 5084 return 0;
718e3744 5085}
5086
d62a17ae 5087static int show_func_dummy(struct vty *vty, struct ospf_lsa *lsa)
718e3744 5088{
d62a17ae 5089 return 0;
718e3744 5090}
5091
d62a17ae 5092static int show_opaque_lsa_detail(struct vty *vty, struct ospf_lsa *lsa)
718e3744 5093{
d62a17ae 5094 if (lsa != NULL) {
5095 show_ip_ospf_database_header(vty, lsa);
5096 show_opaque_info_detail(vty, lsa);
718e3744 5097
d62a17ae 5098 vty_out(vty, "\n");
5099 }
5100 return 0;
5101}
5102
5103int (*show_function[])(struct vty *, struct ospf_lsa *) = {
5104 NULL,
5105 show_router_lsa_detail,
5106 show_network_lsa_detail,
5107 show_summary_lsa_detail,
5108 show_summary_asbr_lsa_detail,
5109 show_as_external_lsa_detail,
5110 show_func_dummy,
5111 show_as_nssa_lsa_detail, /* almost same as external */
5112 NULL, /* type-8 */
5113 show_opaque_lsa_detail,
5114 show_opaque_lsa_detail,
5115 show_opaque_lsa_detail,
5116};
5117
5118static void show_lsa_prefix_set(struct vty *vty, struct prefix_ls *lp,
5119 struct in_addr *id, struct in_addr *adv_router)
5120{
5121 memset(lp, 0, sizeof(struct prefix_ls));
5122 lp->family = 0;
5123 if (id == NULL)
5124 lp->prefixlen = 0;
5125 else if (adv_router == NULL) {
5126 lp->prefixlen = 32;
5127 lp->id = *id;
5128 } else {
5129 lp->prefixlen = 64;
5130 lp->id = *id;
5131 lp->adv_router = *adv_router;
5132 }
718e3744 5133}
718e3744 5134
d62a17ae 5135static void show_lsa_detail_proc(struct vty *vty, struct route_table *rt,
5136 struct in_addr *id, struct in_addr *adv_router)
5137{
5138 struct prefix_ls lp;
5139 struct route_node *rn, *start;
5140 struct ospf_lsa *lsa;
718e3744 5141
d62a17ae 5142 show_lsa_prefix_set(vty, &lp, id, adv_router);
5143 start = route_node_get(rt, (struct prefix *)&lp);
5144 if (start) {
5145 route_lock_node(start);
5146 for (rn = start; rn; rn = route_next_until(rn, start))
5147 if ((lsa = rn->info)) {
5148 if (show_function[lsa->data->type] != NULL)
5149 show_function[lsa->data->type](vty,
5150 lsa);
5151 }
5152 route_unlock_node(start);
5153 }
718e3744 5154}
5155
5156/* Show detail LSA information
5157 -- if id is NULL then show all LSAs. */
d62a17ae 5158static void show_lsa_detail(struct vty *vty, struct ospf *ospf, int type,
5159 struct in_addr *id, struct in_addr *adv_router)
5160{
5161 struct listnode *node;
5162 struct ospf_area *area;
5163
5164 switch (type) {
5165 case OSPF_AS_EXTERNAL_LSA:
5166 case OSPF_OPAQUE_AS_LSA:
5167 vty_out(vty, " %s \n\n",
5168 show_database_desc[type]);
5169 show_lsa_detail_proc(vty, AS_LSDB(ospf, type), id, adv_router);
5170 break;
5171 default:
5172 for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) {
5173 vty_out(vty, "\n %s (Area %s)\n\n",
5174 show_database_desc[type],
5175 ospf_area_desc_string(area));
5176 show_lsa_detail_proc(vty, AREA_LSDB(area, type), id,
5177 adv_router);
5178 }
5179 break;
718e3744 5180 }
5181}
5182
d62a17ae 5183static void show_lsa_detail_adv_router_proc(struct vty *vty,
5184 struct route_table *rt,
5185 struct in_addr *adv_router)
5186{
5187 struct route_node *rn;
5188 struct ospf_lsa *lsa;
5189
5190 for (rn = route_top(rt); rn; rn = route_next(rn))
5191 if ((lsa = rn->info))
5192 if (IPV4_ADDR_SAME(adv_router,
5193 &lsa->data->adv_router)) {
5194 if (CHECK_FLAG(lsa->flags, OSPF_LSA_LOCAL_XLT))
5195 continue;
5196 if (show_function[lsa->data->type] != NULL)
5197 show_function[lsa->data->type](vty,
5198 lsa);
5199 }
5200}
5201
718e3744 5202/* Show detail LSA information. */
d62a17ae 5203static void show_lsa_detail_adv_router(struct vty *vty, struct ospf *ospf,
5204 int type, struct in_addr *adv_router)
5205{
5206 struct listnode *node;
5207 struct ospf_area *area;
5208
5209 switch (type) {
5210 case OSPF_AS_EXTERNAL_LSA:
5211 case OSPF_OPAQUE_AS_LSA:
5212 vty_out(vty, " %s \n\n",
5213 show_database_desc[type]);
5214 show_lsa_detail_adv_router_proc(vty, AS_LSDB(ospf, type),
5215 adv_router);
5216 break;
5217 default:
5218 for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) {
5219 vty_out(vty, "\n %s (Area %s)\n\n",
5220 show_database_desc[type],
5221 ospf_area_desc_string(area));
5222 show_lsa_detail_adv_router_proc(
5223 vty, AREA_LSDB(area, type), adv_router);
5224 }
5225 break;
5226 }
5227}
5228
5229static void show_ip_ospf_database_summary(struct vty *vty, struct ospf *ospf,
5230 int self)
5231{
5232 struct ospf_lsa *lsa;
5233 struct route_node *rn;
5234 struct ospf_area *area;
5235 struct listnode *node;
5236 int type;
5237
5238 for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) {
5239 for (type = OSPF_MIN_LSA; type < OSPF_MAX_LSA; type++) {
5240 switch (type) {
5241 case OSPF_AS_EXTERNAL_LSA:
5242 case OSPF_OPAQUE_AS_LSA:
5243 continue;
5244 default:
5245 break;
5246 }
5247 if (ospf_lsdb_count_self(area->lsdb, type) > 0
5248 || (!self
5249 && ospf_lsdb_count(area->lsdb, type) > 0)) {
5250 vty_out(vty, " %s (Area %s)\n\n",
5251 show_database_desc[type],
5252 ospf_area_desc_string(area));
5253 vty_out(vty, "%s\n",
5254 show_database_header[type]);
5255
5256 LSDB_LOOP(AREA_LSDB(area, type), rn, lsa)
5257 show_lsa_summary(vty, lsa, self);
5258
5259 vty_out(vty, "\n");
5260 }
5261 }
5262 }
5263
5264 for (type = OSPF_MIN_LSA; type < OSPF_MAX_LSA; type++) {
5265 switch (type) {
5266 case OSPF_AS_EXTERNAL_LSA:
5267 case OSPF_OPAQUE_AS_LSA:
5268 break;
5269 default:
5270 continue;
5271 }
5272 if (ospf_lsdb_count_self(ospf->lsdb, type)
5273 || (!self && ospf_lsdb_count(ospf->lsdb, type))) {
5274 vty_out(vty, " %s\n\n",
5275 show_database_desc[type]);
5276 vty_out(vty, "%s\n", show_database_header[type]);
5277
5278 LSDB_LOOP(AS_LSDB(ospf, type), rn, lsa)
5279 show_lsa_summary(vty, lsa, self);
5280
5281 vty_out(vty, "\n");
5282 }
5283 }
5284
5285 vty_out(vty, "\n");
5286}
5287
5288static void show_ip_ospf_database_maxage(struct vty *vty, struct ospf *ospf)
5289{
5290 struct route_node *rn;
5291
5292 vty_out(vty, "\n MaxAge Link States:\n\n");
5293
5294 for (rn = route_top(ospf->maxage_lsa); rn; rn = route_next(rn)) {
5295 struct ospf_lsa *lsa;
5296
5297 if ((lsa = rn->info) != NULL) {
5298 vty_out(vty, "Link type: %d\n", lsa->data->type);
5299 vty_out(vty, "Link State ID: %s\n",
5300 inet_ntoa(lsa->data->id));
5301 vty_out(vty, "Advertising Router: %s\n",
5302 inet_ntoa(lsa->data->adv_router));
5303 vty_out(vty, "LSA lock count: %d\n", lsa->lock);
5304 vty_out(vty, "\n");
5305 }
91e6a0e5 5306 }
718e3744 5307}
5308
718e3744 5309#define OSPF_LSA_TYPE_NSSA_DESC "NSSA external link state\n"
5310#define OSPF_LSA_TYPE_NSSA_CMD_STR "|nssa-external"
718e3744 5311
718e3744 5312#define OSPF_LSA_TYPE_OPAQUE_LINK_DESC "Link local Opaque-LSA\n"
5313#define OSPF_LSA_TYPE_OPAQUE_AREA_DESC "Link area Opaque-LSA\n"
5314#define OSPF_LSA_TYPE_OPAQUE_AS_DESC "Link AS Opaque-LSA\n"
5315#define OSPF_LSA_TYPE_OPAQUE_CMD_STR "|opaque-link|opaque-area|opaque-as"
718e3744 5316
d62a17ae 5317#define OSPF_LSA_TYPES_DESC \
5318 "ASBR summary link states\n" \
5319 "External link states\n" \
5320 "Network link states\n" \
5321 "Router link states\n" \
5322 "Network summary link states\n" OSPF_LSA_TYPE_NSSA_DESC \
5323 OSPF_LSA_TYPE_OPAQUE_LINK_DESC OSPF_LSA_TYPE_OPAQUE_AREA_DESC \
5324 OSPF_LSA_TYPE_OPAQUE_AS_DESC
5325
5326static int show_ip_ospf_database_common(struct vty *vty, struct ospf *ospf,
5327 int arg_base, int argc,
5328 struct cmd_token **argv)
5329{
5330 int idx_type = 4;
5331 int type, ret;
5332 struct in_addr id, adv_router;
5333
5334 if (ospf->instance)
5335 vty_out(vty, "\nOSPF Instance: %d\n", ospf->instance);
5336
5337 vty_out(vty, "\n OSPF Router with ID (%s)\n\n",
5338 inet_ntoa(ospf->router_id));
5339
5340 /* Show all LSA. */
5341 if (argc == arg_base + 4) {
5342 show_ip_ospf_database_summary(vty, ospf, 0);
5343 return CMD_SUCCESS;
5344 }
718e3744 5345
d62a17ae 5346 /* Set database type to show. */
5347 if (strncmp(argv[arg_base + idx_type]->text, "r", 1) == 0)
5348 type = OSPF_ROUTER_LSA;
5349 else if (strncmp(argv[arg_base + idx_type]->text, "ne", 2) == 0)
5350 type = OSPF_NETWORK_LSA;
5351 else if (strncmp(argv[arg_base + idx_type]->text, "ns", 2) == 0)
5352 type = OSPF_AS_NSSA_LSA;
5353 else if (strncmp(argv[arg_base + idx_type]->text, "su", 2) == 0)
5354 type = OSPF_SUMMARY_LSA;
5355 else if (strncmp(argv[arg_base + idx_type]->text, "a", 1) == 0)
5356 type = OSPF_ASBR_SUMMARY_LSA;
5357 else if (strncmp(argv[arg_base + idx_type]->text, "e", 1) == 0)
5358 type = OSPF_AS_EXTERNAL_LSA;
5359 else if (strncmp(argv[arg_base + idx_type]->text, "se", 2) == 0) {
5360 show_ip_ospf_database_summary(vty, ospf, 1);
5361 return CMD_SUCCESS;
5362 } else if (strncmp(argv[arg_base + idx_type]->text, "m", 1) == 0) {
5363 show_ip_ospf_database_maxage(vty, ospf);
5364 return CMD_SUCCESS;
5365 } else if (strncmp(argv[arg_base + idx_type]->text, "opaque-l", 8) == 0)
5366 type = OSPF_OPAQUE_LINK_LSA;
5367 else if (strncmp(argv[arg_base + idx_type]->text, "opaque-ar", 9) == 0)
5368 type = OSPF_OPAQUE_AREA_LSA;
5369 else if (strncmp(argv[arg_base + idx_type]->text, "opaque-as", 9) == 0)
5370 type = OSPF_OPAQUE_AS_LSA;
5371 else
718e3744 5372 return CMD_WARNING;
d62a17ae 5373
5374 /* `show ip ospf database LSA'. */
5375 if (argc == arg_base + 5)
5376 show_lsa_detail(vty, ospf, type, NULL, NULL);
5377 else if (argc >= arg_base + 6) {
5378 ret = inet_aton(argv[arg_base + 5]->arg, &id);
5379 if (!ret)
5380 return CMD_WARNING;
5381
5382 /* `show ip ospf database LSA ID'. */
5383 if (argc == arg_base + 6)
5384 show_lsa_detail(vty, ospf, type, &id, NULL);
5385 /* `show ip ospf database LSA ID adv-router ADV_ROUTER'. */
5386 else if (argc == arg_base + 7) {
5387 if (strncmp(argv[arg_base + 6]->text, "s", 1) == 0)
5388 adv_router = ospf->router_id;
5389 else {
5390 ret = inet_aton(argv[arg_base + 7]->arg,
5391 &adv_router);
5392 if (!ret)
5393 return CMD_WARNING;
5394 }
5395 show_lsa_detail(vty, ospf, type, &id, &adv_router);
5396 }
718e3744 5397 }
718e3744 5398
d62a17ae 5399 return CMD_SUCCESS;
718e3744 5400}
5401
7a7be519 5402DEFUN (show_ip_ospf_database_max,
5403 show_ip_ospf_database_max_cmd,
5404 "show ip ospf database <max-age|self-originate>",
5405 SHOW_STR
5406 IP_STR
5407 "OSPF information\n"
5408 "Database summary\n"
5409 "LSAs in MaxAge list\n"
5410 "Self-originated link states\n")
5411{
d62a17ae 5412 struct ospf *ospf;
f412b39a 5413
d62a17ae 5414 if ((ospf = ospf_lookup()) == NULL || !ospf->oi_running)
5415 return CMD_SUCCESS;
f412b39a 5416
d62a17ae 5417 return (show_ip_ospf_database_common(vty, ospf, 0, argc, argv));
7a7be519 5418}
f412b39a 5419
f412b39a
DW
5420DEFUN (show_ip_ospf_instance_database,
5421 show_ip_ospf_instance_database_cmd,
3a2d747c 5422 "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 5423 SHOW_STR
5424 IP_STR
5425 "OSPF information\n"
7c8ff89e 5426 "Instance ID\n"
7a7be519 5427 "Database summary\n"
5428 OSPF_LSA_TYPES_DESC
5429 "Link State ID (as an IP address)\n"
5430 "Self-originated link states\n"
5431 "Advertising Router link states\n"
5432 "Advertising Router (as an IP address)\n")
7c8ff89e 5433{
d62a17ae 5434 struct ospf *ospf;
5435 u_short instance = 0;
7c8ff89e 5436
d62a17ae 5437 int idx = 0;
5438 if (argv_find(argv, argc, "(1-65535)", &idx)) {
5439 instance = strtoul(argv[idx]->arg, NULL, 10);
5440 ospf = ospf_lookup_instance(instance);
5441 } else {
5442 ospf = ospf_lookup();
5443 }
7c8ff89e 5444
d62a17ae 5445 if (!ospf || !ospf->oi_running)
5446 return CMD_SUCCESS;
7c8ff89e 5447
d62a17ae 5448 return (show_ip_ospf_database_common(vty, ospf, idx ? 1 : 0, argc,
5449 argv));
7c8ff89e
DS
5450}
5451
7a7be519 5452DEFUN (show_ip_ospf_instance_database_max,
5453 show_ip_ospf_instance_database_max_cmd,
5454 "show ip ospf (1-65535) database <max-age|self-originate>",
5455 SHOW_STR
5456 IP_STR
5457 "OSPF information\n"
5458 "Instance ID\n"
5459 "Database summary\n"
5460 "LSAs in MaxAge list\n"
5461 "Self-originated link states\n")
5462{
d62a17ae 5463 int idx_number = 3;
5464 struct ospf *ospf;
5465 u_short instance = 0;
5466
5467 instance = strtoul(argv[idx_number]->arg, NULL, 10);
5468
5469 if ((ospf = ospf_lookup_instance(instance)) == NULL
5470 || !ospf->oi_running)
5471 return CMD_SUCCESS;
5472
5473 return (show_ip_ospf_database_common(vty, ospf, 1, argc, argv));
5474}
5475
5476
5477static int show_ip_ospf_database_type_adv_router_common(struct vty *vty,
5478 struct ospf *ospf,
5479 int arg_base, int argc,
5480 struct cmd_token **argv)
5481{
5482 int idx_type = 4;
5483 int type, ret;
5484 struct in_addr adv_router;
5485
5486 if (ospf->instance)
5487 vty_out(vty, "\nOSPF Instance: %d\n", ospf->instance);
5488
5489 vty_out(vty, "\n OSPF Router with ID (%s)\n\n",
5490 inet_ntoa(ospf->router_id));
5491
5492 /* Set database type to show. */
5493 if (strncmp(argv[arg_base + idx_type]->text, "r", 1) == 0)
5494 type = OSPF_ROUTER_LSA;
5495 else if (strncmp(argv[arg_base + idx_type]->text, "ne", 2) == 0)
5496 type = OSPF_NETWORK_LSA;
5497 else if (strncmp(argv[arg_base + idx_type]->text, "ns", 2) == 0)
5498 type = OSPF_AS_NSSA_LSA;
5499 else if (strncmp(argv[arg_base + idx_type]->text, "s", 1) == 0)
5500 type = OSPF_SUMMARY_LSA;
5501 else if (strncmp(argv[arg_base + idx_type]->text, "a", 1) == 0)
5502 type = OSPF_ASBR_SUMMARY_LSA;
5503 else if (strncmp(argv[arg_base + idx_type]->text, "e", 1) == 0)
5504 type = OSPF_AS_EXTERNAL_LSA;
5505 else if (strncmp(argv[arg_base + idx_type]->text, "opaque-l", 8) == 0)
5506 type = OSPF_OPAQUE_LINK_LSA;
5507 else if (strncmp(argv[arg_base + idx_type]->text, "opaque-ar", 9) == 0)
5508 type = OSPF_OPAQUE_AREA_LSA;
5509 else if (strncmp(argv[arg_base + idx_type]->text, "opaque-as", 9) == 0)
5510 type = OSPF_OPAQUE_AS_LSA;
5511 else
5512 return CMD_WARNING;
7c8ff89e 5513
d62a17ae 5514 /* `show ip ospf database LSA adv-router ADV_ROUTER'. */
5515 if (strncmp(argv[arg_base + 5]->text, "s", 1) == 0)
5516 adv_router = ospf->router_id;
5517 else {
5518 ret = inet_aton(argv[arg_base + 6]->arg, &adv_router);
5519 if (!ret)
5520 return CMD_WARNING;
5521 }
7c8ff89e 5522
d62a17ae 5523 show_lsa_detail_adv_router(vty, ospf, type, &adv_router);
7c8ff89e 5524
d62a17ae 5525 return CMD_SUCCESS;
7c8ff89e
DS
5526}
5527
7c8ff89e
DS
5528DEFUN (show_ip_ospf_instance_database_type_adv_router,
5529 show_ip_ospf_instance_database_type_adv_router_cmd,
36337a6d 5530 "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
5531 SHOW_STR
5532 IP_STR
5533 "OSPF information\n"
5534 "Instance ID\n"
5535 "Database summary\n"
5536 OSPF_LSA_TYPES_DESC
5537 "Advertising Router link states\n"
3a2d747c
QY
5538 "Advertising Router (as an IP address)\n"
5539 "Self-originated link states\n")
7c8ff89e 5540{
d62a17ae 5541 struct ospf *ospf;
5542 u_short instance = 0;
5543 int idx = 0;
7c8ff89e 5544
d62a17ae 5545 if (argv_find(argv, argc, "(1-65535)", &idx)) {
5546 instance = strtoul(argv[idx]->arg, NULL, 10);
5547 ospf = ospf_lookup_instance(instance);
5548 } else
5549 ospf = ospf_lookup();
718e3744 5550
d62a17ae 5551 if (!ospf || !ospf->oi_running)
5552 return CMD_SUCCESS;
718e3744 5553
d62a17ae 5554 return (show_ip_ospf_database_type_adv_router_common(
5555 vty, ospf, idx ? 1 : 0, argc, argv));
718e3744 5556}
5557
718e3744 5558DEFUN (ip_ospf_authentication_args,
5559 ip_ospf_authentication_args_addr_cmd,
7a7be519 5560 "ip ospf authentication <null|message-digest> [A.B.C.D]",
718e3744 5561 "IP Information\n"
5562 "OSPF interface commands\n"
5563 "Enable authentication on this interface\n"
5564 "Use null authentication\n"
5565 "Use message-digest authentication\n"
7a7be519 5566 "Address of interface\n")
718e3744 5567{
d62a17ae 5568 VTY_DECLVAR_CONTEXT(interface, ifp);
5569 int idx_encryption = 3;
5570 int idx_ipv4 = 4;
5571 struct in_addr addr;
5572 int ret;
5573 struct ospf_if_params *params;
5574
5575 params = IF_DEF_PARAMS(ifp);
5576
5577 if (argc == 5) {
5578 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
5579 if (!ret) {
5580 vty_out(vty,
5581 "Please specify interface address by A.B.C.D\n");
5582 return CMD_WARNING_CONFIG_FAILED;
5583 }
718e3744 5584
d62a17ae 5585 params = ospf_get_if_params(ifp, addr);
5586 ospf_if_update_params(ifp, addr);
5587 }
718e3744 5588
d62a17ae 5589 /* Handle null authentication */
5590 if (argv[idx_encryption]->arg[0] == 'n') {
5591 SET_IF_PARAM(params, auth_type);
5592 params->auth_type = OSPF_AUTH_NULL;
5593 return CMD_SUCCESS;
5594 }
718e3744 5595
d62a17ae 5596 /* Handle message-digest authentication */
5597 if (argv[idx_encryption]->arg[0] == 'm') {
5598 SET_IF_PARAM(params, auth_type);
5599 params->auth_type = OSPF_AUTH_CRYPTOGRAPHIC;
5600 return CMD_SUCCESS;
5601 }
718e3744 5602
d62a17ae 5603 vty_out(vty, "You shouldn't get here!\n");
5604 return CMD_WARNING_CONFIG_FAILED;
718e3744 5605}
5606
718e3744 5607DEFUN (ip_ospf_authentication,
5608 ip_ospf_authentication_addr_cmd,
7a7be519 5609 "ip ospf authentication [A.B.C.D]",
718e3744 5610 "IP Information\n"
5611 "OSPF interface commands\n"
5612 "Enable authentication on this interface\n"
5613 "Address of interface")
5614{
d62a17ae 5615 VTY_DECLVAR_CONTEXT(interface, ifp);
5616 int idx_ipv4 = 3;
5617 struct in_addr addr;
5618 int ret;
5619 struct ospf_if_params *params;
5620
5621 params = IF_DEF_PARAMS(ifp);
5622
5623 if (argc == 4) {
5624 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
5625 if (!ret) {
5626 vty_out(vty,
5627 "Please specify interface address by A.B.C.D\n");
5628 return CMD_WARNING_CONFIG_FAILED;
5629 }
5630
5631 params = ospf_get_if_params(ifp, addr);
5632 ospf_if_update_params(ifp, addr);
718e3744 5633 }
5634
d62a17ae 5635 SET_IF_PARAM(params, auth_type);
5636 params->auth_type = OSPF_AUTH_SIMPLE;
718e3744 5637
d62a17ae 5638 return CMD_SUCCESS;
718e3744 5639}
5640
b4a039bf
DS
5641DEFUN (no_ip_ospf_authentication_args,
5642 no_ip_ospf_authentication_args_addr_cmd,
7a7be519 5643 "no ip ospf authentication <null|message-digest> [A.B.C.D]",
b4a039bf
DS
5644 NO_STR
5645 "IP Information\n"
5646 "OSPF interface commands\n"
5647 "Enable authentication on this interface\n"
5648 "Use null authentication\n"
5649 "Use message-digest authentication\n"
5650 "Address of interface")
5651{
d62a17ae 5652 VTY_DECLVAR_CONTEXT(interface, ifp);
5653 int idx_encryption = 4;
5654 int idx_ipv4 = 5;
5655 struct in_addr addr;
5656 int ret;
5657 struct ospf_if_params *params;
5658 struct route_node *rn;
5659 int auth_type;
5660
5661 params = IF_DEF_PARAMS(ifp);
5662
5663 if (argc == 6) {
5664 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
5665 if (!ret) {
5666 vty_out(vty,
5667 "Please specify interface address by A.B.C.D\n");
5668 return CMD_WARNING_CONFIG_FAILED;
5669 }
b4a039bf 5670
d62a17ae 5671 params = ospf_lookup_if_params(ifp, addr);
5672 if (params == NULL) {
5673 vty_out(vty, "Ip Address specified is unknown\n");
5674 return CMD_WARNING_CONFIG_FAILED;
5675 }
5676 params->auth_type = OSPF_AUTH_NOTSET;
5677 UNSET_IF_PARAM(params, auth_type);
5678 if (params != IF_DEF_PARAMS(ifp)) {
5679 ospf_free_if_params(ifp, addr);
5680 ospf_if_update_params(ifp, addr);
5681 }
5682 } else {
5683 if (argv[idx_encryption]->arg[0] == 'n') {
5684 auth_type = OSPF_AUTH_NULL;
5685 } else if (argv[idx_encryption]->arg[0] == 'm') {
5686 auth_type = OSPF_AUTH_CRYPTOGRAPHIC;
5687 } else {
5688 vty_out(vty, "Unexpected input encountered\n");
5689 return CMD_WARNING_CONFIG_FAILED;
5690 }
5691 /*
5692 * Here we have a case where the user has entered
5693 * 'no ip ospf authentication (null | message_digest )'
5694 * we need to find if we have any ip addresses underneath it
5695 * that
5696 * correspond to the associated type.
5697 */
5698 if (params->auth_type == auth_type) {
5699 params->auth_type = OSPF_AUTH_NOTSET;
5700 UNSET_IF_PARAM(params, auth_type);
5701 }
5702
5703 for (rn = route_top(IF_OIFS_PARAMS(ifp)); rn;
5704 rn = route_next(rn)) {
5705 if ((params = rn->info)) {
5706 if (params->auth_type == auth_type) {
5707 params->auth_type = OSPF_AUTH_NOTSET;
5708 UNSET_IF_PARAM(params, auth_type);
5709 if (params != IF_DEF_PARAMS(ifp)) {
5710 ospf_free_if_params(
5711 ifp, rn->p.u.prefix4);
5712 ospf_if_update_params(
5713 ifp, rn->p.u.prefix4);
5714 }
5715 }
5716 }
b4a039bf 5717 }
b4a039bf 5718 }
b4a039bf 5719
d62a17ae 5720 return CMD_SUCCESS;
b4a039bf
DS
5721}
5722
718e3744 5723DEFUN (no_ip_ospf_authentication,
5724 no_ip_ospf_authentication_addr_cmd,
7a7be519 5725 "no ip ospf authentication [A.B.C.D]",
718e3744 5726 NO_STR
5727 "IP Information\n"
5728 "OSPF interface commands\n"
5729 "Enable authentication on this interface\n"
5730 "Address of interface")
5731{
d62a17ae 5732 VTY_DECLVAR_CONTEXT(interface, ifp);
5733 int idx_ipv4 = 4;
5734 struct in_addr addr;
5735 int ret;
5736 struct ospf_if_params *params;
5737 struct route_node *rn;
5738
5739 params = IF_DEF_PARAMS(ifp);
5740
5741 if (argc == 5) {
5742 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
5743 if (!ret) {
5744 vty_out(vty,
5745 "Please specify interface address by A.B.C.D\n");
5746 return CMD_WARNING_CONFIG_FAILED;
5747 }
718e3744 5748
d62a17ae 5749 params = ospf_lookup_if_params(ifp, addr);
5750 if (params == NULL) {
5751 vty_out(vty, "Ip Address specified is unknown\n");
5752 return CMD_WARNING_CONFIG_FAILED;
5753 }
718e3744 5754
d62a17ae 5755 params->auth_type = OSPF_AUTH_NOTSET;
5756 UNSET_IF_PARAM(params, auth_type);
5757 if (params != IF_DEF_PARAMS(ifp)) {
5758 ospf_free_if_params(ifp, addr);
5759 ospf_if_update_params(ifp, addr);
5760 }
5761 } else {
5762 /*
5763 * When a user enters 'no ip ospf authentication'
5764 * We should remove all authentication types from
5765 * the interface.
5766 */
5767 if ((params->auth_type == OSPF_AUTH_NULL)
5768 || (params->auth_type == OSPF_AUTH_CRYPTOGRAPHIC)
5769 || (params->auth_type == OSPF_AUTH_SIMPLE)) {
5770 params->auth_type = OSPF_AUTH_NOTSET;
5771 UNSET_IF_PARAM(params, auth_type);
5772 }
813d4307 5773
d62a17ae 5774 for (rn = route_top(IF_OIFS_PARAMS(ifp)); rn;
5775 rn = route_next(rn)) {
5776 if ((params = rn->info)) {
5777
5778 if ((params->auth_type == OSPF_AUTH_NULL)
5779 || (params->auth_type
5780 == OSPF_AUTH_CRYPTOGRAPHIC)
5781 || (params->auth_type
5782 == OSPF_AUTH_SIMPLE)) {
5783 params->auth_type = OSPF_AUTH_NOTSET;
5784 UNSET_IF_PARAM(params, auth_type);
5785 if (params != IF_DEF_PARAMS(ifp)) {
5786 ospf_free_if_params(
5787 ifp, rn->p.u.prefix4);
5788 ospf_if_update_params(
5789 ifp, rn->p.u.prefix4);
5790 }
5791 }
5792 }
b4a039bf 5793 }
b4a039bf 5794 }
d62a17ae 5795
5796 return CMD_SUCCESS;
718e3744 5797}
5798
0d829fa7 5799
718e3744 5800DEFUN (ip_ospf_authentication_key,
5801 ip_ospf_authentication_key_addr_cmd,
7a7be519 5802 "ip ospf authentication-key AUTH_KEY [A.B.C.D]",
718e3744 5803 "IP Information\n"
5804 "OSPF interface commands\n"
5805 "Authentication password (key)\n"
5806 "The OSPF password (key)\n"
5807 "Address of interface")
5808{
d62a17ae 5809 VTY_DECLVAR_CONTEXT(interface, ifp);
5810 int idx = 0;
5811 struct in_addr addr;
5812 struct ospf_if_params *params;
718e3744 5813
d62a17ae 5814 params = IF_DEF_PARAMS(ifp);
5815
5816 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
5817 if (!inet_aton(argv[idx]->arg, &addr)) {
5818 vty_out(vty,
5819 "Please specify interface address by A.B.C.D\n");
5820 return CMD_WARNING_CONFIG_FAILED;
5821 }
718e3744 5822
d62a17ae 5823 params = ospf_get_if_params(ifp, addr);
5824 ospf_if_update_params(ifp, addr);
5825 }
718e3744 5826
d62a17ae 5827 memset(params->auth_simple, 0, OSPF_AUTH_SIMPLE_SIZE + 1);
5828 strncpy((char *)params->auth_simple, argv[3]->arg,
5829 OSPF_AUTH_SIMPLE_SIZE);
5830 SET_IF_PARAM(params, auth_simple);
718e3744 5831
d62a17ae 5832 return CMD_SUCCESS;
718e3744 5833}
5834
7a7be519 5835DEFUN_HIDDEN (ospf_authentication_key,
747e489c 5836 ospf_authentication_key_cmd,
0d829fa7 5837 "ospf authentication-key AUTH_KEY [A.B.C.D]",
747e489c
DW
5838 "OSPF interface commands\n"
5839 "Authentication password (key)\n"
0d829fa7
QY
5840 "The OSPF password (key)\n"
5841 "Address of interface\n")
718e3744 5842{
d62a17ae 5843 return ip_ospf_authentication_key(self, vty, argc, argv);
718e3744 5844}
5845
7a7be519 5846DEFUN (no_ip_ospf_authentication_key,
5847 no_ip_ospf_authentication_key_authkey_addr_cmd,
5848 "no ip ospf authentication-key [AUTH_KEY [A.B.C.D]]",
5849 NO_STR
5850 "IP Information\n"
5851 "OSPF interface commands\n"
5852 "Authentication password (key)\n"
5853 "The OSPF password (key)")
5854{
d62a17ae 5855 VTY_DECLVAR_CONTEXT(interface, ifp);
5856 int idx = 0;
5857 struct in_addr addr;
5858 struct ospf_if_params *params;
5859 params = IF_DEF_PARAMS(ifp);
5860
5861 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
5862 if (!inet_aton(argv[idx]->arg, &addr)) {
5863 vty_out(vty,
5864 "Please specify interface address by A.B.C.D\n");
5865 return CMD_WARNING_CONFIG_FAILED;
5866 }
7a7be519 5867
d62a17ae 5868 params = ospf_lookup_if_params(ifp, addr);
5869 if (params == NULL)
5870 return CMD_SUCCESS;
7a7be519 5871 }
813d4307 5872
d62a17ae 5873 memset(params->auth_simple, 0, OSPF_AUTH_SIMPLE_SIZE);
5874 UNSET_IF_PARAM(params, auth_simple);
718e3744 5875
d62a17ae 5876 if (params != IF_DEF_PARAMS(ifp)) {
5877 ospf_free_if_params(ifp, addr);
5878 ospf_if_update_params(ifp, addr);
5879 }
813d4307 5880
d62a17ae 5881 return CMD_SUCCESS;
7a7be519 5882}
813d4307 5883
0d829fa7
QY
5884DEFUN_HIDDEN (no_ospf_authentication_key,
5885 no_ospf_authentication_key_authkey_addr_cmd,
5886 "no ospf authentication-key [AUTH_KEY [A.B.C.D]]",
5887 NO_STR
5888 "OSPF interface commands\n"
5889 "Authentication password (key)\n"
5890 "The OSPF password (key)")
5891{
d62a17ae 5892 return no_ip_ospf_authentication_key(self, vty, argc, argv);
0d829fa7
QY
5893}
5894
718e3744 5895DEFUN (ip_ospf_message_digest_key,
537eae3f 5896 ip_ospf_message_digest_key_cmd,
7a7be519 5897 "ip ospf message-digest-key (1-255) md5 KEY [A.B.C.D]",
718e3744 5898 "IP Information\n"
5899 "OSPF interface commands\n"
5900 "Message digest authentication password (key)\n"
5901 "Key ID\n"
5902 "Use MD5 algorithm\n"
fefa0d82
QY
5903 "The OSPF password (key)\n"
5904 "Address of interface\n")
718e3744 5905{
d62a17ae 5906 VTY_DECLVAR_CONTEXT(interface, ifp);
5907 struct crypt_key *ck;
5908 u_char key_id;
5909 struct in_addr addr;
5910 struct ospf_if_params *params;
5911
5912 params = IF_DEF_PARAMS(ifp);
5913 int idx = 0;
5914
5915 argv_find(argv, argc, "(1-255)", &idx);
5916 char *keyid = argv[idx]->arg;
5917 argv_find(argv, argc, "KEY", &idx);
5918 char *cryptkey = argv[idx]->arg;
5919
5920 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
5921 if (!inet_aton(argv[idx]->arg, &addr)) {
5922 vty_out(vty,
5923 "Please specify interface address by A.B.C.D\n");
5924 return CMD_WARNING_CONFIG_FAILED;
5925 }
5926
5927 params = ospf_get_if_params(ifp, addr);
5928 ospf_if_update_params(ifp, addr);
718e3744 5929 }
5930
d62a17ae 5931 key_id = strtol(keyid, NULL, 10);
5932 if (ospf_crypt_key_lookup(params->auth_crypt, key_id) != NULL) {
5933 vty_out(vty, "OSPF: Key %d already exists\n", key_id);
5934 return CMD_WARNING_CONFIG_FAILED;
5935 }
718e3744 5936
d62a17ae 5937 ck = ospf_crypt_key_new();
5938 ck->key_id = (u_char)key_id;
5939 memset(ck->auth_key, 0, OSPF_AUTH_MD5_SIZE + 1);
5940 strncpy((char *)ck->auth_key, cryptkey, OSPF_AUTH_MD5_SIZE);
718e3744 5941
d62a17ae 5942 ospf_crypt_key_add(params->auth_crypt, ck);
5943 SET_IF_PARAM(params, auth_crypt);
718e3744 5944
d62a17ae 5945 return CMD_SUCCESS;
718e3744 5946}
5947
7a7be519 5948DEFUN_HIDDEN (ospf_message_digest_key,
747e489c 5949 ospf_message_digest_key_cmd,
0d829fa7 5950 "ospf message-digest-key (1-255) md5 KEY [A.B.C.D]",
747e489c
DW
5951 "OSPF interface commands\n"
5952 "Message digest authentication password (key)\n"
5953 "Key ID\n"
5954 "Use MD5 algorithm\n"
0d829fa7
QY
5955 "The OSPF password (key)\n"
5956 "Address of interface\n")
7a7be519 5957{
d62a17ae 5958 return ip_ospf_message_digest_key(self, vty, argc, argv);
7a7be519 5959}
718e3744 5960
537eae3f
QY
5961DEFUN (no_ip_ospf_message_digest_key,
5962 no_ip_ospf_message_digest_key_cmd,
0d829fa7 5963 "no ip ospf message-digest-key (1-255) [md5 KEY] [A.B.C.D]",
813d4307
DW
5964 NO_STR
5965 "IP Information\n"
5966 "OSPF interface commands\n"
5967 "Message digest authentication password (key)\n"
5968 "Key ID\n"
5969 "Use MD5 algorithm\n"
0d829fa7
QY
5970 "The OSPF password (key)\n"
5971 "Address of interface\n")
813d4307 5972{
d62a17ae 5973 VTY_DECLVAR_CONTEXT(interface, ifp);
5974 int idx = 0;
5975 struct crypt_key *ck;
5976 int key_id;
5977 struct in_addr addr;
5978 struct ospf_if_params *params;
5979 params = IF_DEF_PARAMS(ifp);
5980
5981 argv_find(argv, argc, "(1-255)", &idx);
5982 char *keyid = argv[idx]->arg;
5983
5984 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
5985 if (!inet_aton(argv[idx]->arg, &addr)) {
5986 vty_out(vty,
5987 "Please specify interface address by A.B.C.D\n");
5988 return CMD_WARNING_CONFIG_FAILED;
5989 }
7a7be519 5990
d62a17ae 5991 params = ospf_lookup_if_params(ifp, addr);
5992 if (params == NULL)
5993 return CMD_SUCCESS;
7a7be519 5994 }
5995
d62a17ae 5996 key_id = strtol(keyid, NULL, 10);
5997 ck = ospf_crypt_key_lookup(params->auth_crypt, key_id);
5998 if (ck == NULL) {
5999 vty_out(vty, "OSPF: Key %d does not exist\n", key_id);
6000 return CMD_WARNING_CONFIG_FAILED;
6001 }
7a7be519 6002
d62a17ae 6003 ospf_crypt_key_delete(params->auth_crypt, key_id);
7a7be519 6004
d62a17ae 6005 if (params != IF_DEF_PARAMS(ifp)) {
6006 ospf_free_if_params(ifp, addr);
6007 ospf_if_update_params(ifp, addr);
6008 }
7a7be519 6009
d62a17ae 6010 return CMD_SUCCESS;
7a7be519 6011}
813d4307 6012
0d829fa7 6013DEFUN_HIDDEN (no_ospf_message_digest_key,
537eae3f 6014 no_ospf_message_digest_key_cmd,
0d829fa7
QY
6015 "no ospf message-digest-key (1-255) [md5 KEY] [A.B.C.D]",
6016 NO_STR
6017 "OSPF interface commands\n"
6018 "Message digest authentication password (key)\n"
6019 "Key ID\n"
6020 "Address of interface")
718e3744 6021{
d62a17ae 6022 return no_ip_ospf_message_digest_key(self, vty, argc, argv);
718e3744 6023}
6024
718e3744 6025DEFUN (ip_ospf_cost,
5c2fc921 6026 ip_ospf_cost_cmd,
7a7be519 6027 "ip ospf cost (1-65535) [A.B.C.D]",
718e3744 6028 "IP Information\n"
6029 "OSPF interface commands\n"
6030 "Interface cost\n"
6031 "Cost\n"
5c2fc921 6032 "Address of interface\n")
718e3744 6033{
d62a17ae 6034 VTY_DECLVAR_CONTEXT(interface, ifp);
6035 int idx = 0;
6036 u_int32_t cost;
6037 struct in_addr addr;
6038 struct ospf_if_params *params;
6039 params = IF_DEF_PARAMS(ifp);
6040
6041 // get arguments
6042 char *coststr = NULL, *ifaddr = NULL;
6043 coststr = argv_find(argv, argc, "(1-65535)", &idx) ? argv[idx]->arg
6044 : NULL;
6045 ifaddr = argv_find(argv, argc, "A.B.C.D", &idx) ? argv[idx]->arg : NULL;
6046
6047 cost = strtol(coststr, NULL, 10);
6048
6049 if (ifaddr) {
6050 if (!inet_aton(ifaddr, &addr)) {
6051 vty_out(vty,
6052 "Please specify interface address by A.B.C.D\n");
6053 return CMD_WARNING_CONFIG_FAILED;
6054 }
718e3744 6055
d62a17ae 6056 params = ospf_get_if_params(ifp, addr);
6057 ospf_if_update_params(ifp, addr);
718e3744 6058 }
6059
d62a17ae 6060 SET_IF_PARAM(params, output_cost_cmd);
6061 params->output_cost_cmd = cost;
718e3744 6062
d62a17ae 6063 ospf_if_recalculate_output_cost(ifp);
5c2fc921 6064
d62a17ae 6065 return CMD_SUCCESS;
718e3744 6066}
6067
7a7be519 6068DEFUN_HIDDEN (ospf_cost,
5c2fc921
QY
6069 ospf_cost_cmd,
6070 "ospf cost (1-65535) [A.B.C.D]",
747e489c
DW
6071 "OSPF interface commands\n"
6072 "Interface cost\n"
6073 "Cost\n"
5c2fc921 6074 "Address of interface\n")
7a7be519 6075{
d62a17ae 6076 return ip_ospf_cost(self, vty, argc, argv);
7a7be519 6077}
9eff36b3 6078
718e3744 6079DEFUN (no_ip_ospf_cost,
5c2fc921
QY
6080 no_ip_ospf_cost_cmd,
6081 "no ip ospf cost [(1-65535)] [A.B.C.D]",
718e3744 6082 NO_STR
718e3744 6083 "OSPF interface commands\n"
6084 "Interface cost\n"
6085 "Address of interface")
6086{
d62a17ae 6087 VTY_DECLVAR_CONTEXT(interface, ifp);
6088 int idx = 0;
6089 struct in_addr addr;
6090 struct ospf_if_params *params;
7a7be519 6091
d62a17ae 6092 params = IF_DEF_PARAMS(ifp);
718e3744 6093
d62a17ae 6094 // get arguments
6095 char *ifaddr = NULL;
6096 ifaddr = argv_find(argv, argc, "A.B.C.D", &idx) ? argv[idx]->arg : NULL;
718e3744 6097
d62a17ae 6098 /* According to the semantics we are mimicking "no ip ospf cost N" is
6099 * always treated as "no ip ospf cost" regardless of the actual value
6100 * of N already configured for the interface. Thus ignore cost. */
7a7be519 6101
d62a17ae 6102 if (ifaddr) {
6103 if (!inet_aton(ifaddr, &addr)) {
6104 vty_out(vty,
6105 "Please specify interface address by A.B.C.D\n");
6106 return CMD_WARNING_CONFIG_FAILED;
6107 }
7a7be519 6108
d62a17ae 6109 params = ospf_lookup_if_params(ifp, addr);
6110 if (params == NULL)
6111 return CMD_SUCCESS;
6112 }
7a7be519 6113
d62a17ae 6114 UNSET_IF_PARAM(params, output_cost_cmd);
7a7be519 6115
d62a17ae 6116 if (params != IF_DEF_PARAMS(ifp)) {
6117 ospf_free_if_params(ifp, addr);
6118 ospf_if_update_params(ifp, addr);
6119 }
7a7be519 6120
d62a17ae 6121 ospf_if_recalculate_output_cost(ifp);
7a7be519 6122
d62a17ae 6123 return CMD_SUCCESS;
7a7be519 6124}
9eff36b3 6125
5c2fc921
QY
6126DEFUN_HIDDEN (no_ospf_cost,
6127 no_ospf_cost_cmd,
6128 "no ospf cost [(1-65535)] [A.B.C.D]",
6129 NO_STR
6130 "OSPF interface commands\n"
6131 "Interface cost\n"
6132 "Cost\n"
6133 "Address of interface\n")
827341b7 6134{
d62a17ae 6135 return no_ip_ospf_cost(self, vty, argc, argv);
827341b7
DO
6136}
6137
d62a17ae 6138static void ospf_nbr_timer_update(struct ospf_interface *oi)
718e3744 6139{
d62a17ae 6140 struct route_node *rn;
6141 struct ospf_neighbor *nbr;
718e3744 6142
d62a17ae 6143 for (rn = route_top(oi->nbrs); rn; rn = route_next(rn))
6144 if ((nbr = rn->info)) {
6145 nbr->v_inactivity = OSPF_IF_PARAM(oi, v_wait);
6146 nbr->v_db_desc = OSPF_IF_PARAM(oi, retransmit_interval);
6147 nbr->v_ls_req = OSPF_IF_PARAM(oi, retransmit_interval);
6148 nbr->v_ls_upd = OSPF_IF_PARAM(oi, retransmit_interval);
6149 }
718e3744 6150}
6151
d62a17ae 6152static int ospf_vty_dead_interval_set(struct vty *vty, const char *interval_str,
6153 const char *nbr_str,
6154 const char *fast_hello_str)
6155{
6156 VTY_DECLVAR_CONTEXT(interface, ifp);
6157 u_int32_t seconds;
6158 u_char hellomult;
6159 struct in_addr addr;
6160 int ret;
6161 struct ospf_if_params *params;
6162 struct ospf_interface *oi;
6163 struct route_node *rn;
718e3744 6164
d62a17ae 6165 params = IF_DEF_PARAMS(ifp);
6166
6167 if (nbr_str) {
6168 ret = inet_aton(nbr_str, &addr);
6169 if (!ret) {
6170 vty_out(vty,
6171 "Please specify interface address by A.B.C.D\n");
6172 return CMD_WARNING_CONFIG_FAILED;
6173 }
6174
6175 params = ospf_get_if_params(ifp, addr);
6176 ospf_if_update_params(ifp, addr);
6177 }
6178
6179 if (interval_str) {
6180 seconds = strtoul(interval_str, NULL, 10);
6181
6182 /* reset fast_hello too, just to be sure */
6183 UNSET_IF_PARAM(params, fast_hello);
6184 params->fast_hello = OSPF_FAST_HELLO_DEFAULT;
6185 } else if (fast_hello_str) {
6186 hellomult = strtoul(fast_hello_str, NULL, 10);
6187 /* 1s dead-interval with sub-second hellos desired */
6188 seconds = OSPF_ROUTER_DEAD_INTERVAL_MINIMAL;
6189 SET_IF_PARAM(params, fast_hello);
6190 params->fast_hello = hellomult;
6191 } else {
6192 vty_out(vty,
6193 "Please specify dead-interval or hello-multiplier\n");
6194 return CMD_WARNING_CONFIG_FAILED;
6195 }
6196
6197 SET_IF_PARAM(params, v_wait);
6198 params->v_wait = seconds;
6199
6200 /* Update timer values in neighbor structure. */
6201 if (nbr_str) {
6202 struct ospf *ospf;
6203 if ((ospf = ospf_lookup())) {
6204 oi = ospf_if_lookup_by_local_addr(ospf, ifp, addr);
6205 if (oi)
6206 ospf_nbr_timer_update(oi);
6207 }
6208 } else {
6209 for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn))
6210 if ((oi = rn->info))
6211 ospf_nbr_timer_update(oi);
6212 }
6213
6214 return CMD_SUCCESS;
718e3744 6215}
6216
f9ad937f 6217DEFUN (ip_ospf_dead_interval,
0d829fa7 6218 ip_ospf_dead_interval_cmd,
7a7be519 6219 "ip ospf dead-interval (1-65535) [A.B.C.D]",
f9ad937f 6220 "IP Information\n"
6221 "OSPF interface commands\n"
99a522c7 6222 "Interval time after which a neighbor is declared down\n"
f9ad937f 6223 "Seconds\n"
6224 "Address of interface\n")
6225{
d62a17ae 6226 int idx = 0;
6227 char *interval = argv_find(argv, argc, "(1-65535)", &idx)
6228 ? argv[idx]->arg
6229 : NULL;
6230 char *ifaddr =
6231 argv_find(argv, argc, "A.B.C.D", &idx) ? argv[idx]->arg : NULL;
6232 return ospf_vty_dead_interval_set(vty, interval, ifaddr, NULL);
f9ad937f 6233}
6234
718e3744 6235
7a7be519 6236DEFUN_HIDDEN (ospf_dead_interval,
747e489c 6237 ospf_dead_interval_cmd,
0d829fa7 6238 "ospf dead-interval (1-65535) [A.B.C.D]",
747e489c 6239 "OSPF interface commands\n"
99a522c7 6240 "Interval time after which a neighbor is declared down\n"
0d829fa7
QY
6241 "Seconds\n"
6242 "Address of interface\n")
7a7be519 6243{
d62a17ae 6244 return ip_ospf_dead_interval(self, vty, argc, argv);
7a7be519 6245}
718e3744 6246
f9ad937f 6247DEFUN (ip_ospf_dead_interval_minimal,
6248 ip_ospf_dead_interval_minimal_addr_cmd,
7a7be519 6249 "ip ospf dead-interval minimal hello-multiplier (1-10) [A.B.C.D]",
f9ad937f 6250 "IP Information\n"
6251 "OSPF interface commands\n"
99a522c7 6252 "Interval time after which a neighbor is declared down\n"
f9ad937f 6253 "Minimal 1s dead-interval with fast sub-second hellos\n"
6254 "Hello multiplier factor\n"
6255 "Number of Hellos to send each second\n"
6256 "Address of interface\n")
6257{
d62a17ae 6258 int idx_number = 5;
6259 int idx_ipv4 = 6;
6260 if (argc == 7)
6261 return ospf_vty_dead_interval_set(
6262 vty, NULL, argv[idx_ipv4]->arg, argv[idx_number]->arg);
6263 else
6264 return ospf_vty_dead_interval_set(vty, NULL, NULL,
6265 argv[idx_number]->arg);
f9ad937f 6266}
6267
718e3744 6268DEFUN (no_ip_ospf_dead_interval,
0d829fa7 6269 no_ip_ospf_dead_interval_cmd,
e83a9414 6270 "no ip ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]",
718e3744 6271 NO_STR
6272 "IP Information\n"
6273 "OSPF interface commands\n"
99a522c7 6274 "Interval time after which a neighbor is declared down\n"
f9dfba8d 6275 "Seconds\n"
718e3744 6276 "Address of interface")
6277{
d62a17ae 6278 VTY_DECLVAR_CONTEXT(interface, ifp);
6279 int idx_ipv4 = argc - 1;
6280 struct in_addr addr = {.s_addr = 0L};
6281 int ret;
6282 struct ospf_if_params *params;
6283 struct ospf_interface *oi;
6284 struct route_node *rn;
6285
6286 params = IF_DEF_PARAMS(ifp);
6287
6288 if (argv[idx_ipv4]->type == IPV4_TKN) {
6289 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
6290 if (!ret) {
6291 vty_out(vty,
6292 "Please specify interface address by A.B.C.D\n");
6293 return CMD_WARNING_CONFIG_FAILED;
6294 }
020709f9 6295
d62a17ae 6296 params = ospf_lookup_if_params(ifp, addr);
6297 if (params == NULL)
6298 return CMD_SUCCESS;
6299 }
718e3744 6300
d62a17ae 6301 UNSET_IF_PARAM(params, v_wait);
6302 params->v_wait = OSPF_ROUTER_DEAD_INTERVAL_DEFAULT;
6303
6304 UNSET_IF_PARAM(params, fast_hello);
6305 params->fast_hello = OSPF_FAST_HELLO_DEFAULT;
6306
6307 if (params != IF_DEF_PARAMS(ifp)) {
6308 ospf_free_if_params(ifp, addr);
6309 ospf_if_update_params(ifp, addr);
718e3744 6310 }
6311
d62a17ae 6312 /* Update timer values in neighbor structure. */
6313 if (argc == 1) {
6314 struct ospf *ospf;
718e3744 6315
d62a17ae 6316 if ((ospf = ospf_lookup())) {
6317 oi = ospf_if_lookup_by_local_addr(ospf, ifp, addr);
6318 if (oi)
6319 ospf_nbr_timer_update(oi);
6320 }
6321 } else {
6322 for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn))
6323 if ((oi = rn->info))
6324 ospf_nbr_timer_update(oi);
6325 }
6326
6327 return CMD_SUCCESS;
718e3744 6328}
6329
0d829fa7
QY
6330DEFUN_HIDDEN (no_ospf_dead_interval,
6331 no_ospf_dead_interval_cmd,
6332 "no ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]",
6333 NO_STR
6334 "OSPF interface commands\n"
99a522c7 6335 "Interval time after which a neighbor is declared down\n"
0d829fa7
QY
6336 "Seconds\n"
6337 "Address of interface")
6338{
d62a17ae 6339 return no_ip_ospf_dead_interval(self, vty, argc, argv);
0d829fa7
QY
6340}
6341
718e3744 6342DEFUN (ip_ospf_hello_interval,
0d829fa7 6343 ip_ospf_hello_interval_cmd,
7a7be519 6344 "ip ospf hello-interval (1-65535) [A.B.C.D]",
718e3744 6345 "IP Information\n"
6346 "OSPF interface commands\n"
6347 "Time between HELLO packets\n"
6348 "Seconds\n"
0d829fa7 6349 "Address of interface\n")
718e3744 6350{
d62a17ae 6351 VTY_DECLVAR_CONTEXT(interface, ifp);
6352 int idx = 0;
6353 struct in_addr addr;
6354 struct ospf_if_params *params;
6355 params = IF_DEF_PARAMS(ifp);
6356 u_int32_t seconds = 0;
6357
6358 argv_find(argv, argc, "(1-65535)", &idx);
6359 seconds = strtol(argv[idx]->arg, NULL, 10);
6360
6361 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
6362 if (!inet_aton(argv[idx]->arg, &addr)) {
6363 vty_out(vty,
6364 "Please specify interface address by A.B.C.D\n");
6365 return CMD_WARNING_CONFIG_FAILED;
6366 }
718e3744 6367
d62a17ae 6368 params = ospf_get_if_params(ifp, addr);
6369 ospf_if_update_params(ifp, addr);
6370 }
718e3744 6371
d62a17ae 6372 SET_IF_PARAM(params, v_hello);
6373 params->v_hello = seconds;
718e3744 6374
d62a17ae 6375 return CMD_SUCCESS;
718e3744 6376}
6377
7a7be519 6378DEFUN_HIDDEN (ospf_hello_interval,
747e489c 6379 ospf_hello_interval_cmd,
0d829fa7 6380 "ospf hello-interval (1-65535) [A.B.C.D]",
747e489c
DW
6381 "OSPF interface commands\n"
6382 "Time between HELLO packets\n"
0d829fa7
QY
6383 "Seconds\n"
6384 "Address of interface\n")
7a7be519 6385{
d62a17ae 6386 return ip_ospf_hello_interval(self, vty, argc, argv);
7a7be519 6387}
718e3744 6388
6389DEFUN (no_ip_ospf_hello_interval,
0d829fa7
QY
6390 no_ip_ospf_hello_interval_cmd,
6391 "no ip ospf hello-interval [(1-65535) [A.B.C.D]]",
718e3744 6392 NO_STR
6393 "IP Information\n"
6394 "OSPF interface commands\n"
0d829fa7 6395 "Time between HELLO packets\n" // ignored
f9dfba8d 6396 "Seconds\n"
0d829fa7 6397 "Address of interface\n")
718e3744 6398{
d62a17ae 6399 VTY_DECLVAR_CONTEXT(interface, ifp);
6400 int idx = 0;
6401 struct in_addr addr;
6402 struct ospf_if_params *params;
df581cd3 6403
d62a17ae 6404 params = IF_DEF_PARAMS(ifp);
718e3744 6405
d62a17ae 6406 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
6407 if (!inet_aton(argv[idx]->arg, &addr)) {
6408 vty_out(vty,
6409 "Please specify interface address by A.B.C.D\n");
6410 return CMD_WARNING_CONFIG_FAILED;
6411 }
718e3744 6412
d62a17ae 6413 params = ospf_lookup_if_params(ifp, addr);
6414 if (params == NULL)
6415 return CMD_SUCCESS;
6416 }
718e3744 6417
d62a17ae 6418 UNSET_IF_PARAM(params, v_hello);
6419 params->v_hello = OSPF_HELLO_INTERVAL_DEFAULT;
718e3744 6420
d62a17ae 6421 if (params != IF_DEF_PARAMS(ifp)) {
6422 ospf_free_if_params(ifp, addr);
6423 ospf_if_update_params(ifp, addr);
6424 }
718e3744 6425
d62a17ae 6426 return CMD_SUCCESS;
718e3744 6427}
6428
0d829fa7
QY
6429DEFUN_HIDDEN (no_ospf_hello_interval,
6430 no_ospf_hello_interval_cmd,
6431 "no ospf hello-interval [(1-65535) [A.B.C.D]]",
6432 NO_STR
6433 "OSPF interface commands\n"
6434 "Time between HELLO packets\n" // ignored
6435 "Seconds\n"
6436 "Address of interface\n")
6437{
d62a17ae 6438 return no_ip_ospf_hello_interval(self, vty, argc, argv);
0d829fa7 6439}
718e3744 6440
6441DEFUN (ip_ospf_network,
6442 ip_ospf_network_cmd,
6147e2c6 6443 "ip ospf network <broadcast|non-broadcast|point-to-multipoint|point-to-point>",
718e3744 6444 "IP Information\n"
6445 "OSPF interface commands\n"
6446 "Network type\n"
6447 "Specify OSPF broadcast multi-access network\n"
6448 "Specify OSPF NBMA network\n"
6449 "Specify OSPF point-to-multipoint network\n"
6450 "Specify OSPF point-to-point network\n")
6451{
d62a17ae 6452 VTY_DECLVAR_CONTEXT(interface, ifp);
6453 int idx = 0;
6454 int old_type = IF_DEF_PARAMS(ifp)->type;
6455 struct route_node *rn;
718e3744 6456
d62a17ae 6457 if (old_type == OSPF_IFTYPE_LOOPBACK) {
6458 vty_out(vty,
6459 "This is a loopback interface. Can't set network type.\n");
6460 return CMD_WARNING_CONFIG_FAILED;
6461 }
718e3744 6462
d62a17ae 6463 if (argv_find(argv, argc, "broadcast", &idx))
6464 IF_DEF_PARAMS(ifp)->type = OSPF_IFTYPE_BROADCAST;
6465 else if (argv_find(argv, argc, "non-broadcast", &idx))
6466 IF_DEF_PARAMS(ifp)->type = OSPF_IFTYPE_NBMA;
6467 else if (argv_find(argv, argc, "point-to-multipoint", &idx))
6468 IF_DEF_PARAMS(ifp)->type = OSPF_IFTYPE_POINTOMULTIPOINT;
6469 else if (argv_find(argv, argc, "point-to-point", &idx))
6470 IF_DEF_PARAMS(ifp)->type = OSPF_IFTYPE_POINTOPOINT;
718e3744 6471
d62a17ae 6472 if (IF_DEF_PARAMS(ifp)->type == old_type)
6473 return CMD_SUCCESS;
6474
6475 SET_IF_PARAM(IF_DEF_PARAMS(ifp), type);
6476
6477 for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) {
6478 struct ospf_interface *oi = rn->info;
6479
6480 if (!oi)
6481 continue;
6482
6483 oi->type = IF_DEF_PARAMS(ifp)->type;
6484
6485 if (oi->state > ISM_Down) {
6486 OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceDown);
6487 OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceUp);
6488 }
7a7be519 6489 }
7a7be519 6490
d62a17ae 6491 return CMD_SUCCESS;
7a7be519 6492}
6493
6494DEFUN_HIDDEN (ospf_network,
6495 ospf_network_cmd,
e83a9414 6496 "ospf network <broadcast|non-broadcast|point-to-multipoint|point-to-point>",
7a7be519 6497 "OSPF interface commands\n"
6498 "Network type\n"
6499 "Specify OSPF broadcast multi-access network\n"
6500 "Specify OSPF NBMA network\n"
6501 "Specify OSPF point-to-multipoint network\n"
6502 "Specify OSPF point-to-point network\n")
6503{
d62a17ae 6504 return ip_ospf_network(self, vty, argc, argv);
7a7be519 6505}
6506
6507DEFUN (no_ip_ospf_network,
6508 no_ip_ospf_network_cmd,
6509 "no ip ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]",
6510 NO_STR
6511 "IP Information\n"
6512 "OSPF interface commands\n"
6513 "Network type\n"
6514 "Specify OSPF broadcast multi-access network\n"
6515 "Specify OSPF NBMA network\n"
6516 "Specify OSPF point-to-multipoint network\n"
6517 "Specify OSPF point-to-point network\n")
22b27e95 6518{
d62a17ae 6519 VTY_DECLVAR_CONTEXT(interface, ifp);
6520 int old_type = IF_DEF_PARAMS(ifp)->type;
6521 struct route_node *rn;
7a7be519 6522
d62a17ae 6523 IF_DEF_PARAMS(ifp)->type = ospf_default_iftype(ifp);
7a7be519 6524
d62a17ae 6525 if (IF_DEF_PARAMS(ifp)->type == old_type)
6526 return CMD_SUCCESS;
7a7be519 6527
d62a17ae 6528 for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) {
6529 struct ospf_interface *oi = rn->info;
7a7be519 6530
d62a17ae 6531 if (!oi)
6532 continue;
7a7be519 6533
d62a17ae 6534 oi->type = IF_DEF_PARAMS(ifp)->type;
7a7be519 6535
d62a17ae 6536 if (oi->state > ISM_Down) {
6537 OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceDown);
6538 OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceUp);
6539 }
7a7be519 6540 }
7a7be519 6541
d62a17ae 6542 return CMD_SUCCESS;
7a7be519 6543}
6544
0d829fa7
QY
6545DEFUN_HIDDEN (no_ospf_network,
6546 no_ospf_network_cmd,
6547 "no ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]",
6548 NO_STR
6549 "OSPF interface commands\n"
6550 "Network type\n"
6551 "Specify OSPF broadcast multi-access network\n"
6552 "Specify OSPF NBMA network\n"
6553 "Specify OSPF point-to-multipoint network\n"
6554 "Specify OSPF point-to-point network\n")
6555{
d62a17ae 6556 return no_ip_ospf_network(self, vty, argc, argv);
0d829fa7
QY
6557}
6558
7a7be519 6559DEFUN (ip_ospf_priority,
537eae3f 6560 ip_ospf_priority_cmd,
7a7be519 6561 "ip ospf priority (0-255) [A.B.C.D]",
6562 "IP Information\n"
6563 "OSPF interface commands\n"
6564 "Router priority\n"
6565 "Priority\n"
6566 "Address of interface")
6567{
d62a17ae 6568 VTY_DECLVAR_CONTEXT(interface, ifp);
6569 int idx = 0;
6570 long priority;
6571 struct route_node *rn;
6572 struct in_addr addr;
6573 struct ospf_if_params *params;
6574 params = IF_DEF_PARAMS(ifp);
6575
6576 argv_find(argv, argc, "(0-255)", &idx);
6577 priority = strtol(argv[idx]->arg, NULL, 10);
6578
6579 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
6580 if (!inet_aton(argv[idx]->arg, &addr)) {
6581 vty_out(vty,
6582 "Please specify interface address by A.B.C.D\n");
6583 return CMD_WARNING_CONFIG_FAILED;
6584 }
7a7be519 6585
d62a17ae 6586 params = ospf_get_if_params(ifp, addr);
6587 ospf_if_update_params(ifp, addr);
7a7be519 6588 }
6589
d62a17ae 6590 SET_IF_PARAM(params, priority);
6591 params->priority = priority;
7a7be519 6592
d62a17ae 6593 for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) {
6594 struct ospf_interface *oi = rn->info;
7a7be519 6595
d62a17ae 6596 if (!oi)
6597 continue;
7a7be519 6598
d62a17ae 6599 if (PRIORITY(oi) != OSPF_IF_PARAM(oi, priority)) {
6600 PRIORITY(oi) = OSPF_IF_PARAM(oi, priority);
6601 OSPF_ISM_EVENT_SCHEDULE(oi, ISM_NeighborChange);
6602 }
718e3744 6603 }
718e3744 6604
d62a17ae 6605 return CMD_SUCCESS;
718e3744 6606}
6607
7a7be519 6608DEFUN_HIDDEN (ospf_priority,
6609 ospf_priority_cmd,
0d829fa7 6610 "ospf priority (0-255) [A.B.C.D]",
7a7be519 6611 "OSPF interface commands\n"
6612 "Router priority\n"
3a2d747c
QY
6613 "Priority\n"
6614 "Address of interface")
718e3744 6615{
d62a17ae 6616 return ip_ospf_priority(self, vty, argc, argv);
718e3744 6617}
6618
718e3744 6619DEFUN (no_ip_ospf_priority,
537eae3f 6620 no_ip_ospf_priority_cmd,
7a7be519 6621 "no ip ospf priority [(0-255) [A.B.C.D]]",
718e3744 6622 NO_STR
6623 "IP Information\n"
6624 "OSPF interface commands\n"
0d829fa7 6625 "Router priority\n" // ignored
813d4307 6626 "Priority\n"
718e3744 6627 "Address of interface")
6628{
d62a17ae 6629 VTY_DECLVAR_CONTEXT(interface, ifp);
6630 int idx = 0;
6631 struct route_node *rn;
6632 struct in_addr addr;
6633 struct ospf_if_params *params;
6634
6635 params = IF_DEF_PARAMS(ifp);
6636
6637 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
6638 if (!inet_aton(argv[idx]->arg, &addr)) {
6639 vty_out(vty,
6640 "Please specify interface address by A.B.C.D\n");
6641 return CMD_WARNING_CONFIG_FAILED;
6642 }
6643
6644 params = ospf_lookup_if_params(ifp, addr);
6645 if (params == NULL)
6646 return CMD_SUCCESS;
718e3744 6647 }
6648
d62a17ae 6649 UNSET_IF_PARAM(params, priority);
6650 params->priority = OSPF_ROUTER_PRIORITY_DEFAULT;
6651
6652 if (params != IF_DEF_PARAMS(ifp)) {
6653 ospf_free_if_params(ifp, addr);
6654 ospf_if_update_params(ifp, addr);
718e3744 6655 }
d62a17ae 6656
6657 for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) {
6658 struct ospf_interface *oi = rn->info;
6659
6660 if (!oi)
6661 continue;
6662
6663 if (PRIORITY(oi) != OSPF_IF_PARAM(oi, priority)) {
6664 PRIORITY(oi) = OSPF_IF_PARAM(oi, priority);
6665 OSPF_ISM_EVENT_SCHEDULE(oi, ISM_NeighborChange);
6666 }
6667 }
6668
6669 return CMD_SUCCESS;
718e3744 6670}
6671
0d829fa7 6672DEFUN_HIDDEN (no_ospf_priority,
537eae3f 6673 no_ospf_priority_cmd,
0d829fa7
QY
6674 "no ospf priority [(0-255) [A.B.C.D]]",
6675 NO_STR
6676 "OSPF interface commands\n"
6677 "Router priority\n"
6678 "Priority\n"
6679 "Address of interface")
6680{
d62a17ae 6681 return no_ip_ospf_priority(self, vty, argc, argv);
0d829fa7 6682}
a1afa410 6683
718e3744 6684DEFUN (ip_ospf_retransmit_interval,
6685 ip_ospf_retransmit_interval_addr_cmd,
7a7be519 6686 "ip ospf retransmit-interval (3-65535) [A.B.C.D]",
718e3744 6687 "IP Information\n"
6688 "OSPF interface commands\n"
6689 "Time between retransmitting lost link state advertisements\n"
6690 "Seconds\n"
6691 "Address of interface")
6692{
d62a17ae 6693 VTY_DECLVAR_CONTEXT(interface, ifp);
6694 int idx = 0;
6695 u_int32_t seconds;
6696 struct in_addr addr;
6697 struct ospf_if_params *params;
6698 params = IF_DEF_PARAMS(ifp);
6699
6700 argv_find(argv, argc, "(3-65535)", &idx);
6701 seconds = strtol(argv[idx]->arg, NULL, 10);
6702
6703 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
6704 if (!inet_aton(argv[idx]->arg, &addr)) {
6705 vty_out(vty,
6706 "Please specify interface address by A.B.C.D\n");
6707 return CMD_WARNING_CONFIG_FAILED;
6708 }
718e3744 6709
d62a17ae 6710 params = ospf_get_if_params(ifp, addr);
6711 ospf_if_update_params(ifp, addr);
718e3744 6712 }
6713
d62a17ae 6714 SET_IF_PARAM(params, retransmit_interval);
6715 params->retransmit_interval = seconds;
718e3744 6716
d62a17ae 6717 return CMD_SUCCESS;
718e3744 6718}
6719
7a7be519 6720DEFUN_HIDDEN (ospf_retransmit_interval,
747e489c 6721 ospf_retransmit_interval_cmd,
0d829fa7 6722 "ospf retransmit-interval (3-65535) [A.B.C.D]",
747e489c
DW
6723 "OSPF interface commands\n"
6724 "Time between retransmitting lost link state advertisements\n"
3a2d747c
QY
6725 "Seconds\n"
6726 "Address of interface")
7a7be519 6727{
d62a17ae 6728 return ip_ospf_retransmit_interval(self, vty, argc, argv);
7a7be519 6729}
718e3744 6730
6731DEFUN (no_ip_ospf_retransmit_interval,
6732 no_ip_ospf_retransmit_interval_addr_cmd,
0d829fa7 6733 "no ip ospf retransmit-interval [(3-65535)] [A.B.C.D]",
718e3744 6734 NO_STR
6735 "IP Information\n"
6736 "OSPF interface commands\n"
3a2d747c
QY
6737 "Time between retransmitting lost link state advertisements\n"
6738 "Seconds\n"
0d829fa7 6739 "Address of interface\n")
718e3744 6740{
d62a17ae 6741 VTY_DECLVAR_CONTEXT(interface, ifp);
6742 int idx = 0;
6743 struct in_addr addr;
6744 struct ospf_if_params *params;
47b91972 6745
d62a17ae 6746 params = IF_DEF_PARAMS(ifp);
718e3744 6747
d62a17ae 6748 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
6749 if (!inet_aton(argv[idx]->arg, &addr)) {
6750 vty_out(vty,
6751 "Please specify interface address by A.B.C.D\n");
6752 return CMD_WARNING_CONFIG_FAILED;
6753 }
718e3744 6754
d62a17ae 6755 params = ospf_lookup_if_params(ifp, addr);
6756 if (params == NULL)
6757 return CMD_SUCCESS;
6758 }
718e3744 6759
d62a17ae 6760 UNSET_IF_PARAM(params, retransmit_interval);
6761 params->retransmit_interval = OSPF_RETRANSMIT_INTERVAL_DEFAULT;
718e3744 6762
d62a17ae 6763 if (params != IF_DEF_PARAMS(ifp)) {
6764 ospf_free_if_params(ifp, addr);
6765 ospf_if_update_params(ifp, addr);
6766 }
718e3744 6767
d62a17ae 6768 return CMD_SUCCESS;
718e3744 6769}
6770
0d829fa7
QY
6771DEFUN_HIDDEN (no_ospf_retransmit_interval,
6772 no_ospf_retransmit_interval_cmd,
6773 "no ospf retransmit-interval [(3-65535)] [A.B.C.D]",
6774 NO_STR
6775 "OSPF interface commands\n"
3a2d747c
QY
6776 "Time between retransmitting lost link state advertisements\n"
6777 "Seconds\n"
6778 "Address of interface\n")
0d829fa7 6779{
d62a17ae 6780 return no_ip_ospf_retransmit_interval(self, vty, argc, argv);
0d829fa7 6781}
813d4307 6782
718e3744 6783DEFUN (ip_ospf_transmit_delay,
6784 ip_ospf_transmit_delay_addr_cmd,
7a7be519 6785 "ip ospf transmit-delay (1-65535) [A.B.C.D]",
718e3744 6786 "IP Information\n"
6787 "OSPF interface commands\n"
6788 "Link state transmit delay\n"
6789 "Seconds\n"
6790 "Address of interface")
6791{
d62a17ae 6792 VTY_DECLVAR_CONTEXT(interface, ifp);
6793 int idx = 0;
6794 u_int32_t seconds;
6795 struct in_addr addr;
6796 struct ospf_if_params *params;
6797
6798 params = IF_DEF_PARAMS(ifp);
6799 argv_find(argv, argc, "(1-65535)", &idx);
6800 seconds = strtol(argv[idx]->arg, NULL, 10);
6801
6802 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
6803 if (!inet_aton(argv[idx]->arg, &addr)) {
6804 vty_out(vty,
6805 "Please specify interface address by A.B.C.D\n");
6806 return CMD_WARNING_CONFIG_FAILED;
6807 }
718e3744 6808
d62a17ae 6809 params = ospf_get_if_params(ifp, addr);
6810 ospf_if_update_params(ifp, addr);
718e3744 6811 }
6812
d62a17ae 6813 SET_IF_PARAM(params, transmit_delay);
6814 params->transmit_delay = seconds;
718e3744 6815
d62a17ae 6816 return CMD_SUCCESS;
718e3744 6817}
6818
7a7be519 6819DEFUN_HIDDEN (ospf_transmit_delay,
747e489c 6820 ospf_transmit_delay_cmd,
0d829fa7 6821 "ospf transmit-delay (1-65535) [A.B.C.D]",
747e489c
DW
6822 "OSPF interface commands\n"
6823 "Link state transmit delay\n"
3a2d747c
QY
6824 "Seconds\n"
6825 "Address of interface")
7a7be519 6826{
d62a17ae 6827 return ip_ospf_transmit_delay(self, vty, argc, argv);
7a7be519 6828}
718e3744 6829
6830DEFUN (no_ip_ospf_transmit_delay,
6831 no_ip_ospf_transmit_delay_addr_cmd,
0d829fa7 6832 "no ip ospf transmit-delay [(1-65535)] [A.B.C.D]",
718e3744 6833 NO_STR
6834 "IP Information\n"
6835 "OSPF interface commands\n"
6836 "Link state transmit delay\n"
6837 "Address of interface")
6838{
d62a17ae 6839 VTY_DECLVAR_CONTEXT(interface, ifp);
6840 int idx = 0;
6841 struct in_addr addr;
6842 struct ospf_if_params *params;
718e3744 6843
d62a17ae 6844 params = IF_DEF_PARAMS(ifp);
718e3744 6845
d62a17ae 6846 if (argv_find(argv, argc, "A.B.C.D", &idx)) {
6847 if (!inet_aton(argv[idx]->arg, &addr)) {
6848 vty_out(vty,
6849 "Please specify interface address by A.B.C.D\n");
6850 return CMD_WARNING_CONFIG_FAILED;
6851 }
718e3744 6852
d62a17ae 6853 params = ospf_lookup_if_params(ifp, addr);
6854 if (params == NULL)
6855 return CMD_SUCCESS;
6856 }
718e3744 6857
d62a17ae 6858 UNSET_IF_PARAM(params, transmit_delay);
6859 params->transmit_delay = OSPF_TRANSMIT_DELAY_DEFAULT;
718e3744 6860
d62a17ae 6861 if (params != IF_DEF_PARAMS(ifp)) {
6862 ospf_free_if_params(ifp, addr);
6863 ospf_if_update_params(ifp, addr);
6864 }
6865
6866 return CMD_SUCCESS;
718e3744 6867}
6868
813d4307 6869
0d829fa7
QY
6870DEFUN_HIDDEN (no_ospf_transmit_delay,
6871 no_ospf_transmit_delay_cmd,
6872 "no ospf transmit-delay",
6873 NO_STR
6874 "OSPF interface commands\n"
6875 "Link state transmit delay\n")
813d4307 6876{
d62a17ae 6877 return no_ip_ospf_transmit_delay(self, vty, argc, argv);
813d4307
DW
6878}
6879
e723861d
DS
6880DEFUN (ip_ospf_area,
6881 ip_ospf_area_cmd,
52c62ab8 6882 "ip ospf [(1-65535)] area <A.B.C.D|(0-4294967295)> [A.B.C.D]",
e723861d
DS
6883 "IP Information\n"
6884 "OSPF interface commands\n"
7a7be519 6885 "Instance ID\n"
e723861d
DS
6886 "Enable OSPF on this interface\n"
6887 "OSPF area ID in IP address format\n"
52c62ab8
JAG
6888 "OSPF area ID as a decimal value\n"
6889 "Address of interface\n")
e723861d 6890{
d62a17ae 6891 VTY_DECLVAR_CONTEXT(interface, ifp);
6892 int idx = 0;
6893 int format, ret;
6894 struct in_addr area_id;
6895 struct in_addr addr;
6896 struct ospf_if_params *params;
6897 struct route_node *rn;
6898 struct ospf *ospf;
6899 u_short instance = 0;
6900 char *areaid;
6901
6902 if (argv_find(argv, argc, "(1-65535)", &idx))
6903 instance = strtol(argv[idx]->arg, NULL, 10);
6904
6905 argv_find(argv, argc, "area", &idx);
6906 areaid = argv[idx + 1]->arg;
6907
6908 ospf = ospf_lookup_instance(instance);
6909 if (ospf == NULL) {
6910 params = IF_DEF_PARAMS(ifp);
6911 if (OSPF_IF_PARAM_CONFIGURED(params, if_area)) {
6912 UNSET_IF_PARAM(params, if_area);
6913 ospf_interface_area_unset(ifp);
6914 ospf = ospf_lookup();
6915 ospf->if_ospf_cli_count--;
6916 }
6917 return CMD_SUCCESS;
6918 }
e723861d 6919
d62a17ae 6920 ret = str2area_id(areaid, &area_id, &format);
6921 if (ret < 0) {
6922 vty_out(vty, "Please specify area by A.B.C.D|<0-4294967295>\n");
6923 return CMD_WARNING_CONFIG_FAILED;
6924 }
6925 if (memcmp(ifp->name, "VLINK", 5) == 0) {
6926 vty_out(vty, "Cannot enable OSPF on a virtual link.\n");
6927 return CMD_WARNING_CONFIG_FAILED;
6928 }
6929
6930 params = IF_DEF_PARAMS(ifp);
6931 if (OSPF_IF_PARAM_CONFIGURED(params, if_area)
6932 && !IPV4_ADDR_SAME(&params->if_area, &area_id)) {
6933 vty_out(vty,
6934 "Must remove previous area config before changing ospf area \n");
6935 return CMD_WARNING_CONFIG_FAILED;
6936 }
6937
6938 // Check if we have an address arg and proccess it
6939 if (argc == idx + 3) {
6940 inet_aton(argv[idx + 2]->arg, &addr);
6941 // update/create address-level params
6942 params = ospf_get_if_params((ifp), (addr));
6943 if (OSPF_IF_PARAM_CONFIGURED(params, if_area)) {
6944 vty_out(vty,
6945 "Must remove previous area/address config before changing ospf area");
6946 return CMD_WARNING_CONFIG_FAILED;
6947 }
6948 ospf_if_update_params((ifp), (addr));
6949 }
6950
6951 for (rn = route_top(ospf->networks); rn; rn = route_next(rn)) {
6952 if (rn->info != NULL) {
6953 vty_out(vty,
6954 "Please remove all network commands first.\n");
6955 return CMD_WARNING_CONFIG_FAILED;
6956 }
6957 }
6958
6959 /* enable ospf on this interface with area_id */
6960 SET_IF_PARAM(params, if_area);
6961 params->if_area = area_id;
6962 ospf_interface_area_set(ifp);
6963 ospf->if_ospf_cli_count++;
6964
6965 return CMD_SUCCESS;
e723861d
DS
6966}
6967
6968DEFUN (no_ip_ospf_area,
6969 no_ip_ospf_area_cmd,
52c62ab8 6970 "no ip ospf [(1-65535)] area [<A.B.C.D|(0-4294967295)> [A.B.C.D]]",
e723861d
DS
6971 NO_STR
6972 "IP Information\n"
6973 "OSPF interface commands\n"
3a2d747c 6974 "Instance ID\n"
7a7be519 6975 "Disable OSPF on this interface\n"
6976 "OSPF area ID in IP address format\n"
52c62ab8
JAG
6977 "OSPF area ID as a decimal value\n"
6978 "Address of interface\n")
e723861d 6979{
d62a17ae 6980 VTY_DECLVAR_CONTEXT(interface, ifp);
6981 int idx = 0;
6982 struct ospf *ospf;
6983 struct ospf_if_params *params;
6984 u_short instance = 0;
6985 struct in_addr addr;
6986
6987 if (argv_find(argv, argc, "(1-65535)", &idx))
6988 instance = strtol(argv[idx]->arg, NULL, 10);
6989
6990 if ((ospf = ospf_lookup_instance(instance)) == NULL)
6991 return CMD_SUCCESS;
6992
6993 argv_find(argv, argc, "area", &idx);
6994
6995 // Check if we have an address arg and proccess it
6996 if (argc == idx + 3) {
6997 inet_aton(argv[idx + 2]->arg, &addr);
6998 params = ospf_lookup_if_params(ifp, addr);
6999 if ((params) == NULL)
7000 return CMD_SUCCESS;
7001 } else
7002 params = IF_DEF_PARAMS(ifp);
7003
7004 if (!OSPF_IF_PARAM_CONFIGURED(params, if_area)) {
7005 vty_out(vty,
7006 "Can't find specified interface area configuration.\n");
7007 return CMD_WARNING_CONFIG_FAILED;
7008 }
813d4307 7009
d62a17ae 7010 UNSET_IF_PARAM(params, if_area);
7011 if (params != IF_DEF_PARAMS((ifp))) {
7012 ospf_free_if_params((ifp), (addr));
7013 ospf_if_update_params((ifp), (addr));
7014 }
7015
7016 ospf_interface_area_unset(ifp);
7017 ospf->if_ospf_cli_count--;
7018 return CMD_SUCCESS;
813d4307
DW
7019}
7020
6f2a6703
CF
7021DEFUN (ospf_redistribute_source,
7022 ospf_redistribute_source_cmd,
40d1cbfb 7023 "redistribute " FRR_REDIST_STR_OSPFD " [<metric (0-16777214)|metric-type (1-2)|route-map WORD>]",
d1c65c21 7024 REDIST_STR
ab0181ee 7025 FRR_REDIST_HELP_STR_OSPFD
718e3744 7026 "Metric for redistributed routes\n"
7027 "OSPF default metric\n"
7028 "OSPF exterior metric type for redistributed routes\n"
7111c1a0 7029 "Set OSPF External Type 1/2 metrics\n"
718e3744 7030 "Route map reference\n"
7031 "Pointer to route-map entries\n")
7032{
d62a17ae 7033 VTY_DECLVAR_CONTEXT(ospf, ospf);
7034 int idx_protocol = 1;
7035 int source;
7036 int type = -1;
7037 int metric = -1;
7038 struct ospf_redist *red;
7039 int idx = 0;
6f2a6703 7040
d62a17ae 7041 if (!ospf)
7042 return CMD_SUCCESS;
7043
7044 /* Get distribute source. */
7045 source = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
7046 if (source < 0)
7047 return CMD_WARNING_CONFIG_FAILED;
7048
7049 red = ospf_redist_add(ospf, source, 0);
7050
7051 /* Get metric value. */
7052 if (argv_find(argv, argc, "(0-16777214)", &idx)) {
7053 if (!str2metric(argv[idx]->arg, &metric))
7054 return CMD_WARNING_CONFIG_FAILED;
7055 }
7056 /* Get metric type. */
7057 else if (argv_find(argv, argc, "(1-2)", &idx)) {
7058 if (!str2metric_type(argv[idx]->arg, &type))
7059 return CMD_WARNING_CONFIG_FAILED;
7060 }
7061 /* Get route-map */
7062 else if (argv_find(argv, argc, "WORD", &idx)) {
7063 ospf_routemap_set(red, argv[idx]->arg);
7064 } else
7065 ospf_routemap_unset(red);
7c8ff89e 7066
d62a17ae 7067 return ospf_redistribute_set(ospf, source, 0, type, metric);
718e3744 7068}
7069
718e3744 7070DEFUN (no_ospf_redistribute_source,
7071 no_ospf_redistribute_source_cmd,
40d1cbfb 7072 "no redistribute " FRR_REDIST_STR_OSPFD " [<metric (0-16777214)|metric-type (1-2)|route-map WORD>]",
718e3744 7073 NO_STR
d1c65c21 7074 REDIST_STR
ab0181ee 7075 FRR_REDIST_HELP_STR_OSPFD
813d4307
DW
7076 "Metric for redistributed routes\n"
7077 "OSPF default metric\n"
7078 "OSPF exterior metric type for redistributed routes\n"
7111c1a0 7079 "Set OSPF External Type 1/2 metrics\n"
813d4307
DW
7080 "Route map reference\n"
7081 "Pointer to route-map entries\n")
718e3744 7082{
d62a17ae 7083 VTY_DECLVAR_CONTEXT(ospf, ospf);
7084 int idx_protocol = 2;
7085 int source;
7086 struct ospf_redist *red;
718e3744 7087
d62a17ae 7088 source = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
7089 if (source < 0)
7090 return CMD_WARNING_CONFIG_FAILED;
718e3744 7091
d62a17ae 7092 red = ospf_redist_lookup(ospf, source, 0);
7093 if (!red)
7094 return CMD_SUCCESS;
7c8ff89e 7095
d62a17ae 7096 ospf_routemap_unset(red);
7097 return ospf_redistribute_unset(ospf, source, 0);
7c8ff89e
DS
7098}
7099
7100DEFUN (ospf_redistribute_instance_source,
7101 ospf_redistribute_instance_source_cmd,
1a5ce38b 7102 "redistribute <ospf|table> (1-65535) [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
7c8ff89e
DS
7103 REDIST_STR
7104 "Open Shortest Path First\n"
2d627ff5
DS
7105 "Non-main Kernel Routing Table\n"
7106 "Instance ID/Table ID\n"
7c8ff89e
DS
7107 "Metric for redistributed routes\n"
7108 "OSPF default metric\n"
7109 "OSPF exterior metric type for redistributed routes\n"
7111c1a0 7110 "Set OSPF External Type 1/2 metrics\n"
7c8ff89e
DS
7111 "Route map reference\n"
7112 "Pointer to route-map entries\n")
7113{
d62a17ae 7114 VTY_DECLVAR_CONTEXT(ospf, ospf);
7115 int idx_ospf_table = 1;
7116 int idx_number = 2;
7117 int idx = 3;
7118 int source;
7119 int type = -1;
7120 int metric = -1;
7121 u_short instance;
7122 struct ospf_redist *red;
7c8ff89e 7123
d62a17ae 7124 if (!ospf)
7125 return CMD_SUCCESS;
d8f70b86 7126
d62a17ae 7127 source = proto_redistnum(AFI_IP, argv[idx_ospf_table]->text);
2d627ff5 7128
d62a17ae 7129 instance = strtoul(argv[idx_number]->arg, NULL, 10);
7c8ff89e 7130
d62a17ae 7131 if (!ospf)
7132 return CMD_SUCCESS;
7c8ff89e 7133
d62a17ae 7134 if ((source == ZEBRA_ROUTE_OSPF) && !ospf->instance) {
7135 vty_out(vty,
7136 "Instance redistribution in non-instanced OSPF not allowed\n");
7137 return CMD_WARNING_CONFIG_FAILED;
7138 }
7c8ff89e 7139
d62a17ae 7140 if ((source == ZEBRA_ROUTE_OSPF) && (ospf->instance == instance)) {
7141 vty_out(vty, "Same instance OSPF redistribution not allowed\n");
7142 return CMD_WARNING_CONFIG_FAILED;
7143 }
7c8ff89e 7144
d62a17ae 7145 /* Get metric value. */
7146 if (argv_find(argv, argc, "metric", &idx))
7147 if (!str2metric(argv[idx + 1]->arg, &metric))
7148 return CMD_WARNING_CONFIG_FAILED;
7c8ff89e 7149
d62a17ae 7150 idx = 3;
7151 /* Get metric type. */
7152 if (argv_find(argv, argc, "metric-type", &idx))
7153 if (!str2metric_type(argv[idx + 1]->arg, &type))
7154 return CMD_WARNING_CONFIG_FAILED;
7c8ff89e 7155
d62a17ae 7156 red = ospf_redist_add(ospf, source, instance);
7a7be519 7157
d62a17ae 7158 idx = 3;
7159 if (argv_find(argv, argc, "route-map", &idx))
7160 ospf_routemap_set(red, argv[idx + 1]->arg);
7161 else
7162 ospf_routemap_unset(red);
7c8ff89e 7163
d62a17ae 7164 return ospf_redistribute_set(ospf, source, instance, type, metric);
7c8ff89e
DS
7165}
7166
7167DEFUN (no_ospf_redistribute_instance_source,
7168 no_ospf_redistribute_instance_source_cmd,
1a5ce38b 7169 "no redistribute <ospf|table> (1-65535) [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]",
7c8ff89e
DS
7170 NO_STR
7171 REDIST_STR
7172 "Open Shortest Path First\n"
2d627ff5
DS
7173 "Non-main Kernel Routing Table\n"
7174 "Instance ID/Table Id\n"
7c8ff89e
DS
7175 "Metric for redistributed routes\n"
7176 "OSPF default metric\n"
7177 "OSPF exterior metric type for redistributed routes\n"
7111c1a0 7178 "Set OSPF External Type 1/2 metrics\n"
7c8ff89e
DS
7179 "Route map reference\n"
7180 "Pointer to route-map entries\n")
7181{
d62a17ae 7182 VTY_DECLVAR_CONTEXT(ospf, ospf);
7183 int idx_ospf_table = 2;
7184 int idx_number = 3;
7185 u_int instance;
7186 struct ospf_redist *red;
7187 int source;
7188
7189 if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
7190 source = ZEBRA_ROUTE_OSPF;
7191 else
7192 source = ZEBRA_ROUTE_TABLE;
7193
7194 instance = strtoul(argv[idx_number]->arg, NULL, 10);
7c8ff89e 7195
d62a17ae 7196 if ((source == ZEBRA_ROUTE_OSPF) && !ospf->instance) {
7197 vty_out(vty,
7198 "Instance redistribution in non-instanced OSPF not allowed\n");
7199 return CMD_WARNING_CONFIG_FAILED;
7200 }
7201
7202 if ((source == ZEBRA_ROUTE_OSPF) && (ospf->instance == instance)) {
7203 vty_out(vty, "Same instance OSPF redistribution not allowed\n");
7204 return CMD_WARNING_CONFIG_FAILED;
7205 }
7206
7207 red = ospf_redist_lookup(ospf, source, instance);
7208 if (!red)
7209 return CMD_SUCCESS;
7210
7211 ospf_routemap_unset(red);
7212 return ospf_redistribute_unset(ospf, source, instance);
718e3744 7213}
7214
7215DEFUN (ospf_distribute_list_out,
7216 ospf_distribute_list_out_cmd,
40d1cbfb 7217 "distribute-list WORD out " FRR_REDIST_STR_OSPFD,
718e3744 7218 "Filter networks in routing updates\n"
6f2a6703
CF
7219 "Access-list name\n"
7220 OUT_STR
ab0181ee 7221 FRR_REDIST_HELP_STR_OSPFD)
718e3744 7222{
d62a17ae 7223 VTY_DECLVAR_CONTEXT(ospf, ospf);
7224 int idx_word = 1;
7225 int source;
718e3744 7226
d62a17ae 7227 char *proto = argv[argc - 1]->text;
6d681bd8 7228
d62a17ae 7229 /* Get distribute source. */
7230 source = proto_redistnum(AFI_IP, proto);
7231 if (source < 0)
7232 return CMD_WARNING_CONFIG_FAILED;
718e3744 7233
d62a17ae 7234 return ospf_distribute_list_out_set(ospf, source, argv[idx_word]->arg);
718e3744 7235}
7236
6f2a6703
CF
7237DEFUN (no_ospf_distribute_list_out,
7238 no_ospf_distribute_list_out_cmd,
40d1cbfb 7239 "no distribute-list WORD out " FRR_REDIST_STR_OSPFD,
6f2a6703
CF
7240 NO_STR
7241 "Filter networks in routing updates\n"
7242 "Access-list name\n"
7243 OUT_STR
ab0181ee 7244 FRR_REDIST_HELP_STR_OSPFD)
718e3744 7245{
d62a17ae 7246 VTY_DECLVAR_CONTEXT(ospf, ospf);
7247 int idx_word = 2;
7248 int source;
020709f9 7249
d62a17ae 7250 char *proto = argv[argc - 1]->text;
7251 source = proto_redistnum(AFI_IP, proto);
7252 if (source < 0)
7253 return CMD_WARNING_CONFIG_FAILED;
718e3744 7254
d62a17ae 7255 return ospf_distribute_list_out_unset(ospf, source,
7256 argv[idx_word]->arg);
718e3744 7257}
7258
6f2a6703
CF
7259/* Default information originate. */
7260DEFUN (ospf_default_information_originate,
7261 ospf_default_information_originate_cmd,
e83a9414 7262 "default-information originate [<always|metric (0-16777214)|metric-type (1-2)|route-map WORD>]",
718e3744 7263 "Control distribution of default information\n"
7264 "Distribute a default route\n"
7265 "Always advertise default route\n"
6f2a6703
CF
7266 "OSPF default metric\n"
7267 "OSPF metric\n"
718e3744 7268 "OSPF metric type for default routes\n"
7111c1a0 7269 "Set OSPF External Type 1/2 metrics\n"
718e3744 7270 "Route map reference\n"
7271 "Pointer to route-map entries\n")
7272{
d62a17ae 7273 VTY_DECLVAR_CONTEXT(ospf, ospf);
7274 int default_originate = DEFAULT_ORIGINATE_ZEBRA;
7275 int type = -1;
7276 int metric = -1;
7277 struct ospf_redist *red;
7278 int idx = 0;
7279
7280 red = ospf_redist_add(ospf, DEFAULT_ROUTE, 0);
7281
7282 /* Check whether "always" was specified */
7283 if (argv_find(argv, argc, "always", &idx))
7284 default_originate = DEFAULT_ORIGINATE_ALWAYS;
7285 /* Get metric value */
7286 else if (argv_find(argv, argc, "(0-16777214)", &idx)) {
7287 if (!str2metric(argv[idx]->arg, &metric))
7288 return CMD_WARNING_CONFIG_FAILED;
7289 }
7290 /* Get metric type. */
7291 else if (argv_find(argv, argc, "(1-2)", &idx)) {
7292 if (!str2metric_type(argv[idx]->arg, &type))
7293 return CMD_WARNING_CONFIG_FAILED;
7294 }
7295 /* Get route-map */
7296 else if (argv_find(argv, argc, "WORD", &idx))
7297 ospf_routemap_set(red, argv[idx]->arg);
7298 else
7299 ospf_routemap_unset(red);
7300
7301 return ospf_redistribute_default_set(ospf, default_originate, type,
7302 metric);
718e3744 7303}
7304
7305DEFUN (no_ospf_default_information_originate,
7306 no_ospf_default_information_originate_cmd,
12dcf78e 7307 "no default-information originate [<always|metric (0-16777214)|metric-type (1-2)|route-map WORD>]",
718e3744 7308 NO_STR
7309 "Control distribution of default information\n"
813d4307
DW
7310 "Distribute a default route\n"
7311 "Always advertise default route\n"
7312 "OSPF default metric\n"
7313 "OSPF metric\n"
7314 "OSPF metric type for default routes\n"
7111c1a0 7315 "Set OSPF External Type 1/2 metrics\n"
813d4307
DW
7316 "Route map reference\n"
7317 "Pointer to route-map entries\n")
718e3744 7318{
d62a17ae 7319 VTY_DECLVAR_CONTEXT(ospf, ospf);
7320 struct prefix_ipv4 p;
7321 struct ospf_external *ext;
7322 struct ospf_redist *red;
7c8ff89e 7323
d62a17ae 7324 p.family = AF_INET;
7325 p.prefix.s_addr = 0;
7326 p.prefixlen = 0;
718e3744 7327
d62a17ae 7328 ospf_external_lsa_flush(ospf, DEFAULT_ROUTE, &p, 0);
718e3744 7329
d62a17ae 7330 if ((ext = ospf_external_lookup(DEFAULT_ROUTE, 0))
7331 && EXTERNAL_INFO(ext)) {
7332 ospf_external_info_delete(DEFAULT_ROUTE, 0, p);
7333 ospf_external_del(DEFAULT_ROUTE, 0);
7334 }
718e3744 7335
d62a17ae 7336 red = ospf_redist_lookup(ospf, DEFAULT_ROUTE, 0);
7337 if (!red)
7338 return CMD_SUCCESS;
7c8ff89e 7339
d62a17ae 7340 ospf_routemap_unset(red);
7341 return ospf_redistribute_default_unset(ospf);
718e3744 7342}
7343
7344DEFUN (ospf_default_metric,
7345 ospf_default_metric_cmd,
6147e2c6 7346 "default-metric (0-16777214)",
718e3744 7347 "Set metric of redistributed routes\n"
7348 "Default metric\n")
7349{
d62a17ae 7350 VTY_DECLVAR_CONTEXT(ospf, ospf);
7351 int idx_number = 1;
7352 int metric = -1;
718e3744 7353
d62a17ae 7354 if (!str2metric(argv[idx_number]->arg, &metric))
7355 return CMD_WARNING_CONFIG_FAILED;
718e3744 7356
d62a17ae 7357 ospf->default_metric = metric;
718e3744 7358
d62a17ae 7359 return CMD_SUCCESS;
718e3744 7360}
7361
7362DEFUN (no_ospf_default_metric,
7363 no_ospf_default_metric_cmd,
7a7be519 7364 "no default-metric [(0-16777214)]",
718e3744 7365 NO_STR
7a7be519 7366 "Set metric of redistributed routes\n"
7367 "Default metric\n")
718e3744 7368{
d62a17ae 7369 VTY_DECLVAR_CONTEXT(ospf, ospf);
68980084 7370
d62a17ae 7371 ospf->default_metric = -1;
68980084 7372
d62a17ae 7373 return CMD_SUCCESS;
718e3744 7374}
7375
718e3744 7376
7377DEFUN (ospf_distance,
7378 ospf_distance_cmd,
6147e2c6 7379 "distance (1-255)",
eaa1ae0d 7380 "Administrative distance\n"
718e3744 7381 "OSPF Administrative distance\n")
7382{
d62a17ae 7383 VTY_DECLVAR_CONTEXT(ospf, ospf);
7384 int idx_number = 1;
68980084 7385
d62a17ae 7386 ospf->distance_all = atoi(argv[idx_number]->arg);
68980084 7387
d62a17ae 7388 return CMD_SUCCESS;
718e3744 7389}
7390
7391DEFUN (no_ospf_distance,
7392 no_ospf_distance_cmd,
6147e2c6 7393 "no distance (1-255)",
718e3744 7394 NO_STR
eaa1ae0d 7395 "Administrative distance\n"
718e3744 7396 "OSPF Administrative distance\n")
7397{
d62a17ae 7398 VTY_DECLVAR_CONTEXT(ospf, ospf);
68980084 7399
d62a17ae 7400 ospf->distance_all = 0;
68980084 7401
d62a17ae 7402 return CMD_SUCCESS;
718e3744 7403}
7404
7405DEFUN (no_ospf_distance_ospf,
7406 no_ospf_distance_ospf_cmd,
eaa1ae0d 7407 "no distance ospf [{intra-area [(1-255)]|inter-area [(1-255)]|external [(1-255)]}]",
718e3744 7408 NO_STR
eaa1ae0d
QY
7409 "Administrative distance\n"
7410 "OSPF administrative distance\n"
718e3744 7411 "Intra-area routes\n"
813d4307 7412 "Distance for intra-area routes\n"
718e3744 7413 "Inter-area routes\n"
813d4307
DW
7414 "Distance for inter-area routes\n"
7415 "External routes\n"
7416 "Distance for external routes\n")
718e3744 7417{
d62a17ae 7418 VTY_DECLVAR_CONTEXT(ospf, ospf);
7419 int idx = 0;
718e3744 7420
d62a17ae 7421 if (!ospf)
7422 return CMD_SUCCESS;
7c8ff89e 7423
d62a17ae 7424 if (argv_find(argv, argc, "intra-area", &idx) || argc == 3)
7425 idx = ospf->distance_intra = 0;
7426 if (argv_find(argv, argc, "inter-area", &idx) || argc == 3)
7427 idx = ospf->distance_inter = 0;
7428 if (argv_find(argv, argc, "external", &idx) || argc == 3)
7429 ospf->distance_external = 0;
718e3744 7430
d62a17ae 7431 return CMD_SUCCESS;
718e3744 7432}
7433
6f2a6703
CF
7434DEFUN (ospf_distance_ospf,
7435 ospf_distance_ospf_cmd,
eaa1ae0d
QY
7436 "distance ospf {intra-area (1-255)|inter-area (1-255)|external (1-255)}",
7437 "Administrative distance\n"
7438 "OSPF administrative distance\n"
718e3744 7439 "Intra-area routes\n"
7440 "Distance for intra-area routes\n"
718e3744 7441 "Inter-area routes\n"
7442 "Distance for inter-area routes\n"
7443 "External routes\n"
718e3744 7444 "Distance for external routes\n")
7445{
d62a17ae 7446 VTY_DECLVAR_CONTEXT(ospf, ospf);
7447 int idx = 0;
68980084 7448
d62a17ae 7449 if (argv_find(argv, argc, "intra-area", &idx))
7450 ospf->distance_intra = atoi(argv[idx + 1]->arg);
7451 idx = 0;
7452 if (argv_find(argv, argc, "inter-area", &idx))
7453 ospf->distance_inter = atoi(argv[idx + 1]->arg);
7454 idx = 0;
7455 if (argv_find(argv, argc, "external", &idx))
7456 ospf->distance_external = atoi(argv[idx + 1]->arg);
68980084 7457
d62a17ae 7458 return CMD_SUCCESS;
718e3744 7459}
7460
d7d73ffc 7461#if 0
718e3744 7462DEFUN (ospf_distance_source,
7463 ospf_distance_source_cmd,
6147e2c6 7464 "distance (1-255) A.B.C.D/M",
718e3744 7465 "Administrative distance\n"
7466 "Distance value\n"
7467 "IP source prefix\n")
7468{
cdc2d765 7469 VTY_DECLVAR_CONTEXT(ospf, ospf);
8d769265
DW
7470 int idx_number = 1;
7471 int idx_ipv4_prefixlen = 2;
020709f9 7472
7c8ff89e
DS
7473 if (!ospf)
7474 return CMD_SUCCESS;
7475
8d769265 7476 ospf_distance_set (vty, ospf, argv[idx_number]->arg, argv[idx_ipv4_prefixlen]->arg, NULL);
68980084 7477
718e3744 7478 return CMD_SUCCESS;
7479}
7480
7481DEFUN (no_ospf_distance_source,
7482 no_ospf_distance_source_cmd,
6147e2c6 7483 "no distance (1-255) A.B.C.D/M",
718e3744 7484 NO_STR
7485 "Administrative distance\n"
7486 "Distance value\n"
7487 "IP source prefix\n")
7488{
cdc2d765 7489 VTY_DECLVAR_CONTEXT(ospf, ospf);
8d769265
DW
7490 int idx_number = 2;
7491 int idx_ipv4_prefixlen = 3;
020709f9 7492
7c8ff89e
DS
7493 if (!ospf)
7494 return CMD_SUCCESS;
7495
8d769265 7496 ospf_distance_unset (vty, ospf, argv[idx_number]->arg, argv[idx_ipv4_prefixlen]->arg, NULL);
020709f9 7497
718e3744 7498 return CMD_SUCCESS;
7499}
7500
7501DEFUN (ospf_distance_source_access_list,
7502 ospf_distance_source_access_list_cmd,
6147e2c6 7503 "distance (1-255) A.B.C.D/M WORD",
718e3744 7504 "Administrative distance\n"
7505 "Distance value\n"
7506 "IP source prefix\n"
7507 "Access list name\n")
7508{
cdc2d765 7509 VTY_DECLVAR_CONTEXT(ospf, ospf);
8d769265
DW
7510 int idx_number = 1;
7511 int idx_ipv4_prefixlen = 2;
7512 int idx_word = 3;
020709f9 7513
7c8ff89e
DS
7514 if (!ospf)
7515 return CMD_SUCCESS;
7516
8d769265 7517 ospf_distance_set (vty, ospf, argv[idx_number]->arg, argv[idx_ipv4_prefixlen]->arg, argv[idx_word]->arg);
020709f9 7518
718e3744 7519 return CMD_SUCCESS;
7520}
7521
7522DEFUN (no_ospf_distance_source_access_list,
7523 no_ospf_distance_source_access_list_cmd,
6147e2c6 7524 "no distance (1-255) A.B.C.D/M WORD",
718e3744 7525 NO_STR
7526 "Administrative distance\n"
7527 "Distance value\n"
7528 "IP source prefix\n"
7529 "Access list name\n")
7530{
cdc2d765 7531 VTY_DECLVAR_CONTEXT(ospf, ospf);
8d769265
DW
7532 int idx_number = 2;
7533 int idx_ipv4_prefixlen = 3;
7534 int idx_word = 4;
020709f9 7535
7c8ff89e
DS
7536 if (!ospf)
7537 return CMD_SUCCESS;
7538
8d769265 7539 ospf_distance_unset (vty, ospf, argv[idx_number]->arg, argv[idx_ipv4_prefixlen]->arg, argv[idx_word]->arg);
020709f9 7540
718e3744 7541 return CMD_SUCCESS;
7542}
d7d73ffc 7543#endif
718e3744 7544
ba682537 7545DEFUN (ip_ospf_mtu_ignore,
7546 ip_ospf_mtu_ignore_addr_cmd,
7a7be519 7547 "ip ospf mtu-ignore [A.B.C.D]",
ba682537 7548 "IP Information\n"
7549 "OSPF interface commands\n"
99a522c7 7550 "Disable MTU mismatch detection on this interface\n"
ba682537 7551 "Address of interface")
7552{
d62a17ae 7553 VTY_DECLVAR_CONTEXT(interface, ifp);
7554 int idx_ipv4 = 3;
7555 struct in_addr addr;
7556 int ret;
7557
7558 struct ospf_if_params *params;
7559 params = IF_DEF_PARAMS(ifp);
7560
7561 if (argc == 4) {
7562 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
7563 if (!ret) {
7564 vty_out(vty,
7565 "Please specify interface address by A.B.C.D\n");
7566 return CMD_WARNING_CONFIG_FAILED;
7567 }
7568 params = ospf_get_if_params(ifp, addr);
7569 ospf_if_update_params(ifp, addr);
7570 }
7571 params->mtu_ignore = 1;
7572 if (params->mtu_ignore != OSPF_MTU_IGNORE_DEFAULT)
7573 SET_IF_PARAM(params, mtu_ignore);
7574 else {
7575 UNSET_IF_PARAM(params, mtu_ignore);
7576 if (params != IF_DEF_PARAMS(ifp)) {
7577 ospf_free_if_params(ifp, addr);
7578 ospf_if_update_params(ifp, addr);
7579 }
7580 }
7581 return CMD_SUCCESS;
ba682537 7582}
7583
ba682537 7584DEFUN (no_ip_ospf_mtu_ignore,
7585 no_ip_ospf_mtu_ignore_addr_cmd,
7a7be519 7586 "no ip ospf mtu-ignore [A.B.C.D]",
ba682537 7587 "IP Information\n"
7588 "OSPF interface commands\n"
99a522c7 7589 "Disable MTU mismatch detection on this interface\n"
ba682537 7590 "Address of interface")
7591{
d62a17ae 7592 VTY_DECLVAR_CONTEXT(interface, ifp);
7593 int idx_ipv4 = 4;
7594 struct in_addr addr;
7595 int ret;
7596
7597 struct ospf_if_params *params;
7598 params = IF_DEF_PARAMS(ifp);
7599
7600 if (argc == 5) {
7601 ret = inet_aton(argv[idx_ipv4]->arg, &addr);
7602 if (!ret) {
7603 vty_out(vty,
7604 "Please specify interface address by A.B.C.D\n");
7605 return CMD_WARNING_CONFIG_FAILED;
7606 }
7607 params = ospf_get_if_params(ifp, addr);
7608 ospf_if_update_params(ifp, addr);
7609 }
7610 params->mtu_ignore = 0;
7611 if (params->mtu_ignore != OSPF_MTU_IGNORE_DEFAULT)
7612 SET_IF_PARAM(params, mtu_ignore);
7613 else {
7614 UNSET_IF_PARAM(params, mtu_ignore);
7615 if (params != IF_DEF_PARAMS(ifp)) {
7616 ospf_free_if_params(ifp, addr);
7617 ospf_if_update_params(ifp, addr);
7618 }
7619 }
7620 return CMD_SUCCESS;
ba682537 7621}
7622
6b0655a2 7623
88d6cf37 7624DEFUN (ospf_max_metric_router_lsa_admin,
7625 ospf_max_metric_router_lsa_admin_cmd,
7626 "max-metric router-lsa administrative",
7627 "OSPF maximum / infinite-distance metric\n"
7628 "Advertise own Router-LSA with infinite distance (stub router)\n"
7629 "Administratively applied, for an indefinite period\n")
7630{
d62a17ae 7631 VTY_DECLVAR_CONTEXT(ospf, ospf);
7632 struct listnode *ln;
7633 struct ospf_area *area;
7c8ff89e 7634
d62a17ae 7635 for (ALL_LIST_ELEMENTS_RO(ospf->areas, ln, area)) {
7636 SET_FLAG(area->stub_router_state, OSPF_AREA_ADMIN_STUB_ROUTED);
4ba4fc85 7637
d62a17ae 7638 if (!CHECK_FLAG(area->stub_router_state,
7639 OSPF_AREA_IS_STUB_ROUTED))
7640 ospf_router_lsa_update_area(area);
7641 }
4ba4fc85 7642
d62a17ae 7643 /* Allows for areas configured later to get the property */
7644 ospf->stub_router_admin_set = OSPF_STUB_ROUTER_ADMINISTRATIVE_SET;
7645
7646 return CMD_SUCCESS;
88d6cf37 7647}
7648
7649DEFUN (no_ospf_max_metric_router_lsa_admin,
7650 no_ospf_max_metric_router_lsa_admin_cmd,
7651 "no max-metric router-lsa administrative",
7652 NO_STR
7653 "OSPF maximum / infinite-distance metric\n"
7654 "Advertise own Router-LSA with infinite distance (stub router)\n"
7655 "Administratively applied, for an indefinite period\n")
7656{
d62a17ae 7657 VTY_DECLVAR_CONTEXT(ospf, ospf);
7658 struct listnode *ln;
7659 struct ospf_area *area;
7660
7661 for (ALL_LIST_ELEMENTS_RO(ospf->areas, ln, area)) {
7662 UNSET_FLAG(area->stub_router_state,
7663 OSPF_AREA_ADMIN_STUB_ROUTED);
7664
7665 /* Don't trample on the start-up stub timer */
7666 if (CHECK_FLAG(area->stub_router_state,
7667 OSPF_AREA_IS_STUB_ROUTED)
7668 && !area->t_stub_router) {
7669 UNSET_FLAG(area->stub_router_state,
7670 OSPF_AREA_IS_STUB_ROUTED);
7671 ospf_router_lsa_update_area(area);
7672 }
7673 }
7674 ospf->stub_router_admin_set = OSPF_STUB_ROUTER_ADMINISTRATIVE_UNSET;
7675 return CMD_SUCCESS;
88d6cf37 7676}
7677
7678DEFUN (ospf_max_metric_router_lsa_startup,
7679 ospf_max_metric_router_lsa_startup_cmd,
6147e2c6 7680 "max-metric router-lsa on-startup (5-86400)",
88d6cf37 7681 "OSPF maximum / infinite-distance metric\n"
7682 "Advertise own Router-LSA with infinite distance (stub router)\n"
7683 "Automatically advertise stub Router-LSA on startup of OSPF\n"
7684 "Time (seconds) to advertise self as stub-router\n")
7685{
d62a17ae 7686 VTY_DECLVAR_CONTEXT(ospf, ospf);
7687 int idx_number = 3;
7688 unsigned int seconds;
7689
7690 if (argc != 1) {
7691 vty_out(vty, "%% Must supply stub-router period");
7692 return CMD_WARNING_CONFIG_FAILED;
7693 }
7694
7695 seconds = strtoul(argv[idx_number]->arg, NULL, 10);
7696
7697 ospf->stub_router_startup_time = seconds;
7698
7699 return CMD_SUCCESS;
88d6cf37 7700}
7701
7702DEFUN (no_ospf_max_metric_router_lsa_startup,
7703 no_ospf_max_metric_router_lsa_startup_cmd,
7a7be519 7704 "no max-metric router-lsa on-startup [(5-86400)]",
88d6cf37 7705 NO_STR
7706 "OSPF maximum / infinite-distance metric\n"
7707 "Advertise own Router-LSA with infinite distance (stub router)\n"
813d4307
DW
7708 "Automatically advertise stub Router-LSA on startup of OSPF\n"
7709 "Time (seconds) to advertise self as stub-router\n")
88d6cf37 7710{
d62a17ae 7711 VTY_DECLVAR_CONTEXT(ospf, ospf);
7712 struct listnode *ln;
7713 struct ospf_area *area;
7714
7715 ospf->stub_router_startup_time = OSPF_STUB_ROUTER_UNCONFIGURED;
7716
7717 for (ALL_LIST_ELEMENTS_RO(ospf->areas, ln, area)) {
7718 SET_FLAG(area->stub_router_state,
7719 OSPF_AREA_WAS_START_STUB_ROUTED);
7720 OSPF_TIMER_OFF(area->t_stub_router);
7721
7722 /* Don't trample on admin stub routed */
7723 if (!CHECK_FLAG(area->stub_router_state,
7724 OSPF_AREA_ADMIN_STUB_ROUTED)) {
7725 UNSET_FLAG(area->stub_router_state,
7726 OSPF_AREA_IS_STUB_ROUTED);
7727 ospf_router_lsa_update_area(area);
7728 }
7729 }
7730 return CMD_SUCCESS;
88d6cf37 7731}
7732
a1afa410 7733
88d6cf37 7734DEFUN (ospf_max_metric_router_lsa_shutdown,
7735 ospf_max_metric_router_lsa_shutdown_cmd,
6147e2c6 7736 "max-metric router-lsa on-shutdown (5-100)",
88d6cf37 7737 "OSPF maximum / infinite-distance metric\n"
7738 "Advertise own Router-LSA with infinite distance (stub router)\n"
7739 "Advertise stub-router prior to full shutdown of OSPF\n"
7740 "Time (seconds) to wait till full shutdown\n")
7741{
d62a17ae 7742 VTY_DECLVAR_CONTEXT(ospf, ospf);
7743 int idx_number = 3;
7744 unsigned int seconds;
7745
7746 if (argc != 1) {
7747 vty_out(vty, "%% Must supply stub-router shutdown period");
7748 return CMD_WARNING_CONFIG_FAILED;
7749 }
7750
7751 seconds = strtoul(argv[idx_number]->arg, NULL, 10);
7752
7753 ospf->stub_router_shutdown_time = seconds;
7754
7755 return CMD_SUCCESS;
88d6cf37 7756}
7757
7758DEFUN (no_ospf_max_metric_router_lsa_shutdown,
7759 no_ospf_max_metric_router_lsa_shutdown_cmd,
7a7be519 7760 "no max-metric router-lsa on-shutdown [(5-100)]",
88d6cf37 7761 NO_STR
7762 "OSPF maximum / infinite-distance metric\n"
7763 "Advertise own Router-LSA with infinite distance (stub router)\n"
813d4307
DW
7764 "Advertise stub-router prior to full shutdown of OSPF\n"
7765 "Time (seconds) to wait till full shutdown\n")
88d6cf37 7766{
d62a17ae 7767 VTY_DECLVAR_CONTEXT(ospf, ospf);
7c8ff89e 7768
d62a17ae 7769 ospf->stub_router_shutdown_time = OSPF_STUB_ROUTER_UNCONFIGURED;
7770
7771 return CMD_SUCCESS;
88d6cf37 7772}
7773
d62a17ae 7774static void config_write_stub_router(struct vty *vty, struct ospf *ospf)
7775{
7776 struct listnode *ln;
7777 struct ospf_area *area;
7778
7779 if (ospf->stub_router_startup_time != OSPF_STUB_ROUTER_UNCONFIGURED)
7780 vty_out(vty, " max-metric router-lsa on-startup %u\n",
7781 ospf->stub_router_startup_time);
7782 if (ospf->stub_router_shutdown_time != OSPF_STUB_ROUTER_UNCONFIGURED)
7783 vty_out(vty, " max-metric router-lsa on-shutdown %u\n",
7784 ospf->stub_router_shutdown_time);
7785 for (ALL_LIST_ELEMENTS_RO(ospf->areas, ln, area)) {
7786 if (CHECK_FLAG(area->stub_router_state,
7787 OSPF_AREA_ADMIN_STUB_ROUTED)) {
7788 vty_out(vty, " max-metric router-lsa administrative\n");
7789 break;
7790 }
7791 }
7792 return;
7793}
7794
7795static void show_ip_ospf_route_network(struct vty *vty, struct route_table *rt)
7796{
7797 struct route_node *rn;
7798 struct ospf_route * or ;
7799 struct listnode *pnode, *pnnode;
7800 struct ospf_path *path;
7801
7802 vty_out(vty, "============ OSPF network routing table ============\n");
7803
7804 for (rn = route_top(rt); rn; rn = route_next(rn))
7805 if ((or = rn->info) != NULL) {
7806 char buf1[19];
7807 snprintf(buf1, 19, "%s/%d", inet_ntoa(rn->p.u.prefix4),
7808 rn->p.prefixlen);
7809
7810 switch (or->path_type) {
7811 case OSPF_PATH_INTER_AREA:
7812 if (or->type == OSPF_DESTINATION_NETWORK)
7813 vty_out(vty,
7814 "N IA %-18s [%d] area: %s\n",
7815 buf1, or->cost,
7816 inet_ntoa(or->u.std.area_id));
7817 else if (or->type == OSPF_DESTINATION_DISCARD)
7818 vty_out(vty,
7819 "D IA %-18s Discard entry\n",
7820 buf1);
7821 break;
7822 case OSPF_PATH_INTRA_AREA:
7823 vty_out(vty, "N %-18s [%d] area: %s\n",
7824 buf1, or->cost,
7825 inet_ntoa(or->u.std.area_id));
7826 break;
7827 default:
7828 break;
7829 }
7830
7831 if (or->type == OSPF_DESTINATION_NETWORK)
7832 for (ALL_LIST_ELEMENTS(or->paths, pnode, pnnode,
7833 path)) {
7834 if (if_lookup_by_index(path->ifindex,
7835 VRF_DEFAULT)) {
7836 if (path->nexthop.s_addr == 0)
7837 vty_out(vty,
7838 "%24s directly attached to %s\n",
7839 "",
7840 ifindex2ifname(
7841 path->ifindex,
7842 VRF_DEFAULT));
7843 else
7844 vty_out(vty,
7845 "%24s via %s, %s\n",
7846 "",
7847 inet_ntoa(
7848 path->nexthop),
7849 ifindex2ifname(
7850 path->ifindex,
7851 VRF_DEFAULT));
7852 }
7853 }
7854 }
7855 vty_out(vty, "\n");
7856}
7857
7858static void show_ip_ospf_route_router(struct vty *vty, struct route_table *rtrs)
7859{
7860 struct route_node *rn;
7861 struct ospf_route * or ;
7862 struct listnode *pnode;
7863 struct listnode *node;
7864 struct ospf_path *path;
7865
7866 vty_out(vty, "============ OSPF router routing table =============\n");
7867 for (rn = route_top(rtrs); rn; rn = route_next(rn))
7868 if (rn->info) {
7869 int flag = 0;
7870
7871 vty_out(vty, "R %-15s ",
7872 inet_ntoa(rn->p.u.prefix4));
7873
7874 for (ALL_LIST_ELEMENTS_RO((struct list *)rn->info, node,
7875 or)) {
7876 if (flag++)
7877 vty_out(vty, "%24s", "");
7878
7879 /* Show path. */
7880 vty_out(vty, "%s [%d] area: %s",
7881 (or->path_type == OSPF_PATH_INTER_AREA
7882 ? "IA"
7883 : " "),
7884 or->cost, inet_ntoa(or->u.std.area_id));
7885 /* Show flags. */
7886 vty_out(vty, "%s%s\n",
7887 (or->u.std.flags & ROUTER_LSA_BORDER
7888 ? ", ABR"
7889 : ""),
7890 (or->u.std.flags & ROUTER_LSA_EXTERNAL
7891 ? ", ASBR"
7892 : ""));
7893
7894 for (ALL_LIST_ELEMENTS_RO(or->paths, pnode,
7895 path)) {
7896 if (if_lookup_by_index(path->ifindex,
7897 VRF_DEFAULT)) {
7898 if (path->nexthop.s_addr == 0)
7899 vty_out(vty,
7900 "%24s directly attached to %s\n",
7901 "",
7902 ifindex2ifname(
7903 path->ifindex,
7904 VRF_DEFAULT));
7905 else
7906 vty_out(vty,
7907 "%24s via %s, %s\n",
7908 "",
7909 inet_ntoa(
7910 path->nexthop),
7911 ifindex2ifname(
7912 path->ifindex,
7913 VRF_DEFAULT));
7914 }
7915 }
7916 }
7917 }
7918 vty_out(vty, "\n");
7919}
7920
7921static void show_ip_ospf_route_external(struct vty *vty, struct route_table *rt)
7922{
7923 struct route_node *rn;
7924 struct ospf_route *er;
7925 struct listnode *pnode, *pnnode;
7926 struct ospf_path *path;
7927
7928 vty_out(vty, "============ OSPF external routing table ===========\n");
7929 for (rn = route_top(rt); rn; rn = route_next(rn))
7930 if ((er = rn->info) != NULL) {
7931 char buf1[19];
7932 snprintf(buf1, 19, "%s/%d", inet_ntoa(rn->p.u.prefix4),
7933 rn->p.prefixlen);
7934
7935 switch (er->path_type) {
7936 case OSPF_PATH_TYPE1_EXTERNAL:
7937 vty_out(vty,
7938 "N E1 %-18s [%d] tag: %" ROUTE_TAG_PRI
7939 "\n",
7940 buf1, er->cost, er->u.ext.tag);
7941 break;
7942 case OSPF_PATH_TYPE2_EXTERNAL:
7943 vty_out(vty,
7944 "N E2 %-18s [%d/%d] tag: %" ROUTE_TAG_PRI
7945 "\n",
7946 buf1, er->cost, er->u.ext.type2_cost,
7947 er->u.ext.tag);
7948 break;
7949 }
7950
7951 for (ALL_LIST_ELEMENTS(er->paths, pnode, pnnode,
7952 path)) {
7953 if (if_lookup_by_index(path->ifindex,
7954 VRF_DEFAULT)) {
7955 if (path->nexthop.s_addr == 0)
7956 vty_out(vty,
7957 "%24s directly attached to %s\n",
7958 "",
7959 ifindex2ifname(
7960 path->ifindex,
7961 VRF_DEFAULT));
7962 else
7963 vty_out(vty,
7964 "%24s via %s, %s\n",
7965 "",
7966 inet_ntoa(
7967 path->nexthop),
7968 ifindex2ifname(
7969 path->ifindex,
7970 VRF_DEFAULT));
7971 }
54bedb55 7972 }
d62a17ae 7973 }
7974 vty_out(vty, "\n");
718e3744 7975}
7976
d62a17ae 7977static int show_ip_ospf_border_routers_common(struct vty *vty,
7978 struct ospf *ospf)
718e3744 7979{
d62a17ae 7980 if (ospf->instance)
7981 vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
718e3744 7982
d62a17ae 7983 if (ospf->new_table == NULL) {
7984 vty_out(vty, "No OSPF routing information exist\n");
7985 return CMD_SUCCESS;
7986 }
718e3744 7987
d62a17ae 7988 /* Show Network routes.
7989 show_ip_ospf_route_network (vty, ospf->new_table); */
718e3744 7990
d62a17ae 7991 /* Show Router routes. */
7992 show_ip_ospf_route_router(vty, ospf->new_rtrs);
718e3744 7993
d62a17ae 7994 vty_out(vty, "\n");
7c8ff89e 7995
d62a17ae 7996 return CMD_SUCCESS;
718e3744 7997}
718e3744 7998
7c8ff89e
DS
7999DEFUN (show_ip_ospf_border_routers,
8000 show_ip_ospf_border_routers_cmd,
8001 "show ip ospf border-routers",
718e3744 8002 SHOW_STR
8003 IP_STR
8004 "OSPF information\n"
7c8ff89e 8005 "Show all the ABR's and ASBR's\n")
718e3744 8006{
d62a17ae 8007 struct ospf *ospf;
68980084 8008
d62a17ae 8009 if ((ospf = ospf_lookup()) == NULL || !ospf->oi_running)
8010 return CMD_SUCCESS;
7c8ff89e 8011
d62a17ae 8012 return show_ip_ospf_border_routers_common(vty, ospf);
7c8ff89e
DS
8013}
8014
8015DEFUN (show_ip_ospf_instance_border_routers,
8016 show_ip_ospf_instance_border_routers_cmd,
6147e2c6 8017 "show ip ospf (1-65535) border-routers",
7c8ff89e
DS
8018 SHOW_STR
8019 IP_STR
8020 "OSPF information\n"
8021 "Instance ID\n"
8022 "Show all the ABR's and ASBR's\n")
8023{
d62a17ae 8024 int idx_number = 3;
8025 struct ospf *ospf;
8026 u_short instance = 0;
7c8ff89e 8027
d62a17ae 8028 instance = strtoul(argv[idx_number]->arg, NULL, 10);
8029 if ((ospf = ospf_lookup_instance(instance)) == NULL
8030 || !ospf->oi_running)
8031 return CMD_SUCCESS;
7c8ff89e 8032
d62a17ae 8033 return show_ip_ospf_border_routers_common(vty, ospf);
7c8ff89e
DS
8034}
8035
d62a17ae 8036static int show_ip_ospf_route_common(struct vty *vty, struct ospf *ospf)
7c8ff89e 8037{
d62a17ae 8038 if (ospf->instance)
8039 vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
718e3744 8040
d62a17ae 8041 if (ospf->new_table == NULL) {
8042 vty_out(vty, "No OSPF routing information exist\n");
8043 return CMD_SUCCESS;
8044 }
718e3744 8045
d62a17ae 8046 /* Show Network routes. */
8047 show_ip_ospf_route_network(vty, ospf->new_table);
718e3744 8048
d62a17ae 8049 /* Show Router routes. */
8050 show_ip_ospf_route_router(vty, ospf->new_rtrs);
718e3744 8051
d62a17ae 8052 /* Show AS External routes. */
8053 show_ip_ospf_route_external(vty, ospf->old_external_route);
718e3744 8054
d62a17ae 8055 vty_out(vty, "\n");
7c8ff89e 8056
d62a17ae 8057 return CMD_SUCCESS;
718e3744 8058}
8059
7c8ff89e
DS
8060DEFUN (show_ip_ospf_route,
8061 show_ip_ospf_route_cmd,
8062 "show ip ospf route",
8063 SHOW_STR
8064 IP_STR
8065 "OSPF information\n"
8066 "OSPF routing table\n")
8067{
d62a17ae 8068 struct ospf *ospf;
7c8ff89e 8069
d62a17ae 8070 if ((ospf = ospf_lookup()) == NULL || !ospf->oi_running)
8071 return CMD_SUCCESS;
7c8ff89e 8072
d62a17ae 8073 return show_ip_ospf_route_common(vty, ospf);
7c8ff89e
DS
8074}
8075
8076DEFUN (show_ip_ospf_instance_route,
8077 show_ip_ospf_instance_route_cmd,
6147e2c6 8078 "show ip ospf (1-65535) route",
7c8ff89e
DS
8079 SHOW_STR
8080 IP_STR
8081 "OSPF information\n"
8082 "Instance ID\n"
8083 "OSPF routing table\n")
8084{
d62a17ae 8085 int idx_number = 3;
8086 struct ospf *ospf;
8087 u_short instance = 0;
7c8ff89e 8088
d62a17ae 8089 instance = strtoul(argv[idx_number]->arg, NULL, 10);
8090 if ((ospf = ospf_lookup_instance(instance)) == NULL
8091 || !ospf->oi_running)
8092 return CMD_SUCCESS;
7c8ff89e 8093
d62a17ae 8094 return show_ip_ospf_route_common(vty, ospf);
7c8ff89e 8095}
6b0655a2 8096
d62a17ae 8097const char *ospf_abr_type_str[] = {"unknown", "standard", "ibm", "cisco",
8098 "shortcut"};
718e3744 8099
d62a17ae 8100const char *ospf_shortcut_mode_str[] = {"default", "enable", "disable"};
718e3744 8101
d62a17ae 8102const char *ospf_int_type_str[] = {"unknown", /* should never be used. */
8103 "point-to-point", "broadcast",
8104 "non-broadcast", "point-to-multipoint",
8105 "virtual-link", /* should never be used. */
8106 "loopback"};
718e3744 8107
8108/* Configuration write function for ospfd. */
d62a17ae 8109static int config_write_interface(struct vty *vty)
8110{
8111 struct listnode *n1, *n2;
8112 struct interface *ifp;
8113 struct crypt_key *ck;
8114 int write = 0;
8115 struct route_node *rn = NULL;
8116 struct ospf_if_params *params;
8117 struct ospf *ospf = ospf_lookup();
8118
8119 for (ALL_LIST_ELEMENTS_RO(vrf_iflist(VRF_DEFAULT), n1, ifp)) {
8120 if (memcmp(ifp->name, "VLINK", 5) == 0)
8121 continue;
8122
8123 if (ifp->ifindex == IFINDEX_DELETED)
8124 continue;
8125
8126 vty_out(vty, "!\n");
8127 vty_out(vty, "interface %s\n", ifp->name);
8128 if (ifp->desc)
8129 vty_out(vty, " description %s\n", ifp->desc);
8130
8131 write++;
8132
8133 params = IF_DEF_PARAMS(ifp);
8134
8135 do {
8136 /* Interface Network print. */
8137 if (OSPF_IF_PARAM_CONFIGURED(params, type)
8138 && params->type != OSPF_IFTYPE_LOOPBACK) {
8139 if (params->type != ospf_default_iftype(ifp)) {
8140 vty_out(vty, " ip ospf network %s",
8141 ospf_int_type_str
8142 [params->type]);
8143 if (params != IF_DEF_PARAMS(ifp))
8144 vty_out(vty, " %s",
8145 inet_ntoa(
8146 rn->p.u.prefix4));
8147 vty_out(vty, "\n");
8148 }
8149 }
8150
8151 /* OSPF interface authentication print */
8152 if (OSPF_IF_PARAM_CONFIGURED(params, auth_type)
8153 && params->auth_type != OSPF_AUTH_NOTSET) {
8154 const char *auth_str;
8155
8156 /* Translation tables are not that much help
8157 here due to syntax
8158 of the simple option */
8159 switch (params->auth_type) {
8160
8161 case OSPF_AUTH_NULL:
8162 auth_str = " null";
8163 break;
8164
8165 case OSPF_AUTH_SIMPLE:
8166 auth_str = "";
8167 break;
8168
8169 case OSPF_AUTH_CRYPTOGRAPHIC:
8170 auth_str = " message-digest";
8171 break;
8172
8173 default:
8174 auth_str = "";
8175 break;
8176 }
8177
8178 vty_out(vty, " ip ospf authentication%s",
8179 auth_str);
8180 if (params != IF_DEF_PARAMS(ifp))
8181 vty_out(vty, " %s",
8182 inet_ntoa(rn->p.u.prefix4));
8183 vty_out(vty, "\n");
8184 }
8185
8186 /* Simple Authentication Password print. */
8187 if (OSPF_IF_PARAM_CONFIGURED(params, auth_simple)
8188 && params->auth_simple[0] != '\0') {
8189 vty_out(vty, " ip ospf authentication-key %s",
8190 params->auth_simple);
8191 if (params != IF_DEF_PARAMS(ifp))
8192 vty_out(vty, " %s",
8193 inet_ntoa(rn->p.u.prefix4));
8194 vty_out(vty, "\n");
8195 }
8196
8197 /* Cryptographic Authentication Key print. */
8198 for (ALL_LIST_ELEMENTS_RO(params->auth_crypt, n2, ck)) {
8199 vty_out(vty,
8200 " ip ospf message-digest-key %d md5 %s",
8201 ck->key_id, ck->auth_key);
8202 if (params != IF_DEF_PARAMS(ifp))
8203 vty_out(vty, " %s",
8204 inet_ntoa(rn->p.u.prefix4));
8205 vty_out(vty, "\n");
8206 }
8207
8208 /* Interface Output Cost print. */
8209 if (OSPF_IF_PARAM_CONFIGURED(params, output_cost_cmd)) {
8210 vty_out(vty, " ip ospf cost %u",
8211 params->output_cost_cmd);
8212 if (params != IF_DEF_PARAMS(ifp))
8213 vty_out(vty, " %s",
8214 inet_ntoa(rn->p.u.prefix4));
8215 vty_out(vty, "\n");
8216 }
8217
8218 /* Hello Interval print. */
8219 if (OSPF_IF_PARAM_CONFIGURED(params, v_hello)
8220 && params->v_hello != OSPF_HELLO_INTERVAL_DEFAULT) {
8221 vty_out(vty, " ip ospf hello-interval %u",
8222 params->v_hello);
8223 if (params != IF_DEF_PARAMS(ifp))
8224 vty_out(vty, " %s",
8225 inet_ntoa(rn->p.u.prefix4));
8226 vty_out(vty, "\n");
8227 }
8228
8229
8230 /* Router Dead Interval print. */
8231 if (OSPF_IF_PARAM_CONFIGURED(params, v_wait)
8232 && params->v_wait
8233 != OSPF_ROUTER_DEAD_INTERVAL_DEFAULT) {
8234 vty_out(vty, " ip ospf dead-interval ");
8235
8236 /* fast hello ? */
8237 if (OSPF_IF_PARAM_CONFIGURED(params,
8238 fast_hello))
8239 vty_out(vty,
8240 "minimal hello-multiplier %d",
8241 params->fast_hello);
8242 else
8243 vty_out(vty, "%u", params->v_wait);
8244
8245 if (params != IF_DEF_PARAMS(ifp))
8246 vty_out(vty, " %s",
8247 inet_ntoa(rn->p.u.prefix4));
8248 vty_out(vty, "\n");
8249 }
8250
8251 /* Router Priority print. */
8252 if (OSPF_IF_PARAM_CONFIGURED(params, priority)
8253 && params->priority
8254 != OSPF_ROUTER_PRIORITY_DEFAULT) {
8255 vty_out(vty, " ip ospf priority %u",
8256 params->priority);
8257 if (params != IF_DEF_PARAMS(ifp))
8258 vty_out(vty, " %s",
8259 inet_ntoa(rn->p.u.prefix4));
8260 vty_out(vty, "\n");
8261 }
8262
8263 /* Retransmit Interval print. */
8264 if (OSPF_IF_PARAM_CONFIGURED(params,
8265 retransmit_interval)
8266 && params->retransmit_interval
8267 != OSPF_RETRANSMIT_INTERVAL_DEFAULT) {
8268 vty_out(vty, " ip ospf retransmit-interval %u",
8269 params->retransmit_interval);
8270 if (params != IF_DEF_PARAMS(ifp))
8271 vty_out(vty, " %s",
8272 inet_ntoa(rn->p.u.prefix4));
8273 vty_out(vty, "\n");
8274 }
8275
8276 /* Transmit Delay print. */
8277 if (OSPF_IF_PARAM_CONFIGURED(params, transmit_delay)
8278 && params->transmit_delay
8279 != OSPF_TRANSMIT_DELAY_DEFAULT) {
8280 vty_out(vty, " ip ospf transmit-delay %u",
8281 params->transmit_delay);
8282 if (params != IF_DEF_PARAMS(ifp))
8283 vty_out(vty, " %s",
8284 inet_ntoa(rn->p.u.prefix4));
8285 vty_out(vty, "\n");
8286 }
8287
8288 /* Area print. */
8289 if (OSPF_IF_PARAM_CONFIGURED(params, if_area)) {
8290 if (ospf->instance)
8291 vty_out(vty, " ip ospf %d",
8292 ospf->instance);
8293 else
8294 vty_out(vty, " ip ospf");
8295
8296 vty_out(vty, " area %s",
8297 inet_ntoa(params->if_area));
8298 if (params != IF_DEF_PARAMS(ifp))
8299 vty_out(vty, " %s",
8300 inet_ntoa(rn->p.u.prefix4));
8301 vty_out(vty, "\n");
8302 }
8303
8304 /* bfd print. */
8305 ospf_bfd_write_config(vty, params);
8306
8307 /* MTU ignore print. */
8308 if (OSPF_IF_PARAM_CONFIGURED(params, mtu_ignore)
8309 && params->mtu_ignore != OSPF_MTU_IGNORE_DEFAULT) {
8310 if (params->mtu_ignore == 0)
8311 vty_out(vty, " no ip ospf mtu-ignore");
8312 else
8313 vty_out(vty, " ip ospf mtu-ignore");
8314 if (params != IF_DEF_PARAMS(ifp))
8315 vty_out(vty, " %s",
8316 inet_ntoa(rn->p.u.prefix4));
8317 vty_out(vty, "\n");
8318 }
8319
8320
8321 while (1) {
8322 if (rn == NULL)
8323 rn = route_top(IF_OIFS_PARAMS(ifp));
8324 else
8325 rn = route_next(rn);
8326
8327 if (rn == NULL)
8328 break;
8329 params = rn->info;
8330 if (params != NULL)
8331 break;
8332 }
8333 } while (rn);
8334
8335 ospf_opaque_config_write_if(vty, ifp);
8336 }
8337
8338 return write;
718e3744 8339}
8340
d62a17ae 8341static int config_write_network_area(struct vty *vty, struct ospf *ospf)
718e3744 8342{
d62a17ae 8343 struct route_node *rn;
8344 u_char buf[INET_ADDRSTRLEN];
718e3744 8345
d62a17ae 8346 /* `network area' print. */
8347 for (rn = route_top(ospf->networks); rn; rn = route_next(rn))
8348 if (rn->info) {
8349 struct ospf_network *n = rn->info;
718e3744 8350
d62a17ae 8351 memset(buf, 0, INET_ADDRSTRLEN);
718e3744 8352
d62a17ae 8353 /* Create Area ID string by specified Area ID format. */
8354 if (n->area_id_fmt == OSPF_AREA_ID_FMT_DOTTEDQUAD)
8355 strncpy((char *)buf, inet_ntoa(n->area_id),
8356 INET_ADDRSTRLEN);
8357 else
8358 sprintf((char *)buf, "%lu",
8359 (unsigned long int)ntohl(
8360 n->area_id.s_addr));
718e3744 8361
d62a17ae 8362 /* Network print. */
8363 vty_out(vty, " network %s/%d area %s\n",
8364 inet_ntoa(rn->p.u.prefix4), rn->p.prefixlen,
8365 buf);
8366 }
718e3744 8367
d62a17ae 8368 return 0;
718e3744 8369}
8370
d62a17ae 8371static int config_write_ospf_area(struct vty *vty, struct ospf *ospf)
718e3744 8372{
d62a17ae 8373 struct listnode *node;
8374 struct ospf_area *area;
8375 u_char buf[INET_ADDRSTRLEN];
718e3744 8376
d62a17ae 8377 /* Area configuration print. */
8378 for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) {
8379 struct route_node *rn1;
718e3744 8380
d62a17ae 8381 area_id2str((char *)buf, INET_ADDRSTRLEN, &area->area_id,
8382 area->area_id_fmt);
718e3744 8383
d62a17ae 8384 if (area->auth_type != OSPF_AUTH_NULL) {
8385 if (area->auth_type == OSPF_AUTH_SIMPLE)
8386 vty_out(vty, " area %s authentication\n", buf);
8387 else
8388 vty_out(vty,
8389 " area %s authentication message-digest\n",
8390 buf);
8391 }
718e3744 8392
d62a17ae 8393 if (area->shortcut_configured != OSPF_SHORTCUT_DEFAULT)
8394 vty_out(vty, " area %s shortcut %s\n", buf,
8395 ospf_shortcut_mode_str
8396 [area->shortcut_configured]);
8397
8398 if ((area->external_routing == OSPF_AREA_STUB)
8399 || (area->external_routing == OSPF_AREA_NSSA)) {
8400 if (area->external_routing == OSPF_AREA_STUB)
8401 vty_out(vty, " area %s stub", buf);
8402 else if (area->external_routing == OSPF_AREA_NSSA) {
8403 vty_out(vty, " area %s nssa", buf);
8404 switch (area->NSSATranslatorRole) {
8405 case OSPF_NSSA_ROLE_NEVER:
8406 vty_out(vty, " translate-never");
8407 break;
8408 case OSPF_NSSA_ROLE_ALWAYS:
8409 vty_out(vty, " translate-always");
8410 break;
8411 case OSPF_NSSA_ROLE_CANDIDATE:
8412 default:
8413 vty_out(vty, " translate-candidate");
8414 }
8415 }
718e3744 8416
d62a17ae 8417 if (area->no_summary)
8418 vty_out(vty, " no-summary");
718e3744 8419
d62a17ae 8420 vty_out(vty, "\n");
718e3744 8421
d62a17ae 8422 if (area->default_cost != 1)
8423 vty_out(vty, " area %s default-cost %d\n", buf,
8424 area->default_cost);
8425 }
718e3744 8426
d62a17ae 8427 for (rn1 = route_top(area->ranges); rn1; rn1 = route_next(rn1))
8428 if (rn1->info) {
8429 struct ospf_area_range *range = rn1->info;
718e3744 8430
d62a17ae 8431 vty_out(vty, " area %s range %s/%d", buf,
8432 inet_ntoa(rn1->p.u.prefix4),
8433 rn1->p.prefixlen);
718e3744 8434
d62a17ae 8435 if (range->cost_config
8436 != OSPF_AREA_RANGE_COST_UNSPEC)
8437 vty_out(vty, " cost %d",
8438 range->cost_config);
718e3744 8439
d62a17ae 8440 if (!CHECK_FLAG(range->flags,
8441 OSPF_AREA_RANGE_ADVERTISE))
8442 vty_out(vty, " not-advertise");
718e3744 8443
d62a17ae 8444 if (CHECK_FLAG(range->flags,
8445 OSPF_AREA_RANGE_SUBSTITUTE))
8446 vty_out(vty, " substitute %s/%d",
8447 inet_ntoa(range->subst_addr),
8448 range->subst_masklen);
8449
8450 vty_out(vty, "\n");
8451 }
8452
8453 if (EXPORT_NAME(area))
8454 vty_out(vty, " area %s export-list %s\n", buf,
8455 EXPORT_NAME(area));
8456
8457 if (IMPORT_NAME(area))
8458 vty_out(vty, " area %s import-list %s\n", buf,
8459 IMPORT_NAME(area));
8460
8461 if (PREFIX_NAME_IN(area))
8462 vty_out(vty, " area %s filter-list prefix %s in\n", buf,
8463 PREFIX_NAME_IN(area));
8464
8465 if (PREFIX_NAME_OUT(area))
8466 vty_out(vty, " area %s filter-list prefix %s out\n",
8467 buf, PREFIX_NAME_OUT(area));
8468 }
8469
8470 return 0;
718e3744 8471}
8472
d62a17ae 8473static int config_write_ospf_nbr_nbma(struct vty *vty, struct ospf *ospf)
718e3744 8474{
d62a17ae 8475 struct ospf_nbr_nbma *nbr_nbma;
8476 struct route_node *rn;
718e3744 8477
d62a17ae 8478 /* Static Neighbor configuration print. */
8479 for (rn = route_top(ospf->nbr_nbma); rn; rn = route_next(rn))
8480 if ((nbr_nbma = rn->info)) {
8481 vty_out(vty, " neighbor %s", inet_ntoa(nbr_nbma->addr));
718e3744 8482
d62a17ae 8483 if (nbr_nbma->priority
8484 != OSPF_NEIGHBOR_PRIORITY_DEFAULT)
8485 vty_out(vty, " priority %d",
8486 nbr_nbma->priority);
718e3744 8487
d62a17ae 8488 if (nbr_nbma->v_poll != OSPF_POLL_INTERVAL_DEFAULT)
8489 vty_out(vty, " poll-interval %d",
8490 nbr_nbma->v_poll);
8491
8492 vty_out(vty, "\n");
8493 }
8494
8495 return 0;
8496}
8497
8498static int config_write_virtual_link(struct vty *vty, struct ospf *ospf)
8499{
8500 struct listnode *node;
8501 struct ospf_vl_data *vl_data;
8502 char buf[INET_ADDRSTRLEN];
8503
8504 /* Virtual-Link print */
8505 for (ALL_LIST_ELEMENTS_RO(ospf->vlinks, node, vl_data)) {
8506 struct listnode *n2;
8507 struct crypt_key *ck;
8508 struct ospf_interface *oi;
8509
8510 if (vl_data != NULL) {
8511 memset(buf, 0, INET_ADDRSTRLEN);
8512
8513 area_id2str(buf, sizeof(buf), &vl_data->vl_area_id,
8514 vl_data->vl_area_id_fmt);
8515 oi = vl_data->vl_oi;
8516
8517 /* timers */
8518 if (OSPF_IF_PARAM(oi, v_hello)
8519 != OSPF_HELLO_INTERVAL_DEFAULT
8520 || OSPF_IF_PARAM(oi, v_wait)
8521 != OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
8522 || OSPF_IF_PARAM(oi, retransmit_interval)
8523 != OSPF_RETRANSMIT_INTERVAL_DEFAULT
8524 || OSPF_IF_PARAM(oi, transmit_delay)
8525 != OSPF_TRANSMIT_DELAY_DEFAULT)
8526 vty_out(vty,
8527 " area %s virtual-link %s hello-interval %d retransmit-interval %d transmit-delay %d dead-interval %d\n",
8528 buf, inet_ntoa(vl_data->vl_peer),
8529 OSPF_IF_PARAM(oi, v_hello),
8530 OSPF_IF_PARAM(oi, retransmit_interval),
8531 OSPF_IF_PARAM(oi, transmit_delay),
8532 OSPF_IF_PARAM(oi, v_wait));
8533 else
8534 vty_out(vty, " area %s virtual-link %s\n", buf,
8535 inet_ntoa(vl_data->vl_peer));
8536 /* Auth key */
8537 if (IF_DEF_PARAMS(vl_data->vl_oi->ifp)->auth_simple[0]
8538 != '\0')
8539 vty_out(vty,
8540 " area %s virtual-link %s authentication-key %s\n",
8541 buf, inet_ntoa(vl_data->vl_peer),
8542 IF_DEF_PARAMS(vl_data->vl_oi->ifp)
8543 ->auth_simple);
8544 /* md5 keys */
8545 for (ALL_LIST_ELEMENTS_RO(
8546 IF_DEF_PARAMS(vl_data->vl_oi->ifp)
8547 ->auth_crypt,
8548 n2, ck))
8549 vty_out(vty,
8550 " area %s virtual-link %s"
8551 " message-digest-key %d md5 %s\n",
8552 buf, inet_ntoa(vl_data->vl_peer),
8553 ck->key_id, ck->auth_key);
8554 }
8555 }
8556
8557 return 0;
718e3744 8558}
8559
6b0655a2 8560
d62a17ae 8561static int config_write_ospf_redistribute(struct vty *vty, struct ospf *ospf)
718e3744 8562{
d62a17ae 8563 int type;
718e3744 8564
d62a17ae 8565 /* redistribute print. */
8566 for (type = 0; type < ZEBRA_ROUTE_MAX; type++) {
8567 struct list *red_list;
8568 struct listnode *node;
8569 struct ospf_redist *red;
718e3744 8570
d62a17ae 8571 red_list = ospf->redist[type];
8572 if (!red_list)
8573 continue;
7c8ff89e 8574
d62a17ae 8575 for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
8576 vty_out(vty, " redistribute %s",
8577 zebra_route_string(type));
8578 if (red->instance)
8579 vty_out(vty, " %d", red->instance);
7c8ff89e 8580
d62a17ae 8581 if (red->dmetric.value >= 0)
8582 vty_out(vty, " metric %d", red->dmetric.value);
7c8ff89e 8583
d62a17ae 8584 if (red->dmetric.type == EXTERNAL_METRIC_TYPE_1)
8585 vty_out(vty, " metric-type 1");
7c8ff89e 8586
d62a17ae 8587 if (ROUTEMAP_NAME(red))
8588 vty_out(vty, " route-map %s",
8589 ROUTEMAP_NAME(red));
7c8ff89e 8590
d62a17ae 8591 vty_out(vty, "\n");
8592 }
8593 }
718e3744 8594
d62a17ae 8595 return 0;
718e3744 8596}
8597
d62a17ae 8598static int config_write_ospf_default_metric(struct vty *vty, struct ospf *ospf)
718e3744 8599{
d62a17ae 8600 if (ospf->default_metric != -1)
8601 vty_out(vty, " default-metric %d\n", ospf->default_metric);
8602 return 0;
718e3744 8603}
8604
d62a17ae 8605static int config_write_ospf_distribute(struct vty *vty, struct ospf *ospf)
8606{
8607 int type;
8608 struct ospf_redist *red;
718e3744 8609
d62a17ae 8610 if (ospf) {
8611 /* distribute-list print. */
8612 for (type = 0; type < ZEBRA_ROUTE_MAX; type++)
8613 if (DISTRIBUTE_NAME(ospf, type))
8614 vty_out(vty, " distribute-list %s out %s\n",
8615 DISTRIBUTE_NAME(ospf, type),
8616 zebra_route_string(type));
7c8ff89e 8617
d62a17ae 8618 /* default-information print. */
8619 if (ospf->default_originate != DEFAULT_ORIGINATE_NONE) {
8620 vty_out(vty, " default-information originate");
8621 if (ospf->default_originate == DEFAULT_ORIGINATE_ALWAYS)
8622 vty_out(vty, " always");
718e3744 8623
d62a17ae 8624 red = ospf_redist_lookup(ospf, DEFAULT_ROUTE, 0);
8625 if (red) {
8626 if (red->dmetric.value >= 0)
8627 vty_out(vty, " metric %d",
8628 red->dmetric.value);
8629 if (red->dmetric.type == EXTERNAL_METRIC_TYPE_1)
8630 vty_out(vty, " metric-type 1");
718e3744 8631
d62a17ae 8632 if (ROUTEMAP_NAME(red))
8633 vty_out(vty, " route-map %s",
8634 ROUTEMAP_NAME(red));
8635 }
8636
8637 vty_out(vty, "\n");
8638 }
8639 }
8640
8641 return 0;
718e3744 8642}
8643
d62a17ae 8644static int config_write_ospf_distance(struct vty *vty, struct ospf *ospf)
8645{
8646 struct route_node *rn;
8647 struct ospf_distance *odistance;
8648
8649 if (ospf->distance_all)
8650 vty_out(vty, " distance %d\n", ospf->distance_all);
8651
8652 if (ospf->distance_intra || ospf->distance_inter
8653 || ospf->distance_external) {
8654 vty_out(vty, " distance ospf");
8655
8656 if (ospf->distance_intra)
8657 vty_out(vty, " intra-area %d", ospf->distance_intra);
8658 if (ospf->distance_inter)
8659 vty_out(vty, " inter-area %d", ospf->distance_inter);
8660 if (ospf->distance_external)
8661 vty_out(vty, " external %d", ospf->distance_external);
8662
8663 vty_out(vty, "\n");
8664 }
8665
8666 for (rn = route_top(ospf->distance_table); rn; rn = route_next(rn))
8667 if ((odistance = rn->info) != NULL) {
8668 vty_out(vty, " distance %d %s/%d %s\n",
8669 odistance->distance, inet_ntoa(rn->p.u.prefix4),
8670 rn->p.prefixlen,
8671 odistance->access_list ? odistance->access_list
8672 : "");
8673 }
8674 return 0;
718e3744 8675}
8676
8677/* OSPF configuration write function. */
d62a17ae 8678static int ospf_config_write(struct vty *vty)
8679{
8680 struct ospf *ospf;
8681 struct interface *ifp;
8682 struct ospf_interface *oi;
8683 struct listnode *node;
8684 int write = 0;
8685
8686 ospf = ospf_lookup();
8687 if (ospf != NULL && ospf->oi_running) {
8688 /* `router ospf' print. */
8689 if (ospf->instance)
8690 vty_out(vty, "router ospf %d\n", ospf->instance);
8691 else
8692 vty_out(vty, "router ospf\n");
8693
8694 write++;
8695
8696 if (!ospf->networks)
8697 return write;
8698
8699 /* Router ID print. */
8700 if (ospf->router_id_static.s_addr != 0)
8701 vty_out(vty, " ospf router-id %s\n",
8702 inet_ntoa(ospf->router_id_static));
8703
8704 /* ABR type print. */
8705 if (ospf->abr_type != OSPF_ABR_DEFAULT)
8706 vty_out(vty, " ospf abr-type %s\n",
8707 ospf_abr_type_str[ospf->abr_type]);
8708
8709 /* log-adjacency-changes flag print. */
8710 if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES)) {
8711 if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL))
8712 vty_out(vty, " log-adjacency-changes detail\n");
8713 else if (!DFLT_OSPF_LOG_ADJACENCY_CHANGES)
8714 vty_out(vty, " log-adjacency-changes\n");
8715 } else if (DFLT_OSPF_LOG_ADJACENCY_CHANGES) {
8716 vty_out(vty, " no log-adjacency-changes\n");
8717 }
8718
8719 /* RFC1583 compatibility flag print -- Compatible with CISCO
8720 * 12.1. */
8721 if (CHECK_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE))
8722 vty_out(vty, " compatible rfc1583\n");
8723
8724 /* auto-cost reference-bandwidth configuration. */
8725 if (ospf->ref_bandwidth != OSPF_DEFAULT_REF_BANDWIDTH) {
8726 vty_out(vty,
8727 "! Important: ensure reference bandwidth "
8728 "is consistent across all routers\n");
8729 vty_out(vty, " auto-cost reference-bandwidth %d\n",
8730 ospf->ref_bandwidth);
8731 }
8732
8733 /* SPF timers print. */
8734 if (ospf->spf_delay != OSPF_SPF_DELAY_DEFAULT
8735 || ospf->spf_holdtime != OSPF_SPF_HOLDTIME_DEFAULT
8736 || ospf->spf_max_holdtime != OSPF_SPF_MAX_HOLDTIME_DEFAULT)
8737 vty_out(vty, " timers throttle spf %d %d %d\n",
8738 ospf->spf_delay, ospf->spf_holdtime,
8739 ospf->spf_max_holdtime);
8740
8741 /* LSA timers print. */
8742 if (ospf->min_ls_interval != OSPF_MIN_LS_INTERVAL)
8743 vty_out(vty, " timers throttle lsa all %d\n",
8744 ospf->min_ls_interval);
8745 if (ospf->min_ls_arrival != OSPF_MIN_LS_ARRIVAL)
8746 vty_out(vty, " timers lsa min-arrival %d\n",
8747 ospf->min_ls_arrival);
8748
8749 /* Write multiplier print. */
8750 if (ospf->write_oi_count != OSPF_WRITE_INTERFACE_COUNT_DEFAULT)
8751 vty_out(vty, " ospf write-multiplier %d\n",
8752 ospf->write_oi_count);
8753
8754 /* Max-metric router-lsa print */
8755 config_write_stub_router(vty, ospf);
8756
8757 /* SPF refresh parameters print. */
8758 if (ospf->lsa_refresh_interval
8759 != OSPF_LSA_REFRESH_INTERVAL_DEFAULT)
8760 vty_out(vty, " refresh timer %d\n",
8761 ospf->lsa_refresh_interval);
8762
8763 /* Redistribute information print. */
8764 config_write_ospf_redistribute(vty, ospf);
8765
8766 /* passive-interface print. */
8767 if (ospf->passive_interface_default == OSPF_IF_PASSIVE)
8768 vty_out(vty, " passive-interface default\n");
8769
8770 for (ALL_LIST_ELEMENTS_RO(om->iflist, node, ifp))
8771 if (OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(ifp),
8772 passive_interface)
8773 && IF_DEF_PARAMS(ifp)->passive_interface
8774 != ospf->passive_interface_default) {
8775 vty_out(vty, " %spassive-interface %s\n",
8776 IF_DEF_PARAMS(ifp)->passive_interface
8777 ? ""
8778 : "no ",
8779 ifp->name);
8780 }
8781 for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) {
8782 if (!OSPF_IF_PARAM_CONFIGURED(oi->params,
8783 passive_interface))
8784 continue;
8785 if (OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(oi->ifp),
8786 passive_interface)) {
8787 if (oi->params->passive_interface
8788 == IF_DEF_PARAMS(oi->ifp)
8789 ->passive_interface)
8790 continue;
8791 } else if (oi->params->passive_interface
8792 == ospf->passive_interface_default)
8793 continue;
8794
8795 vty_out(vty, " %spassive-interface %s %s\n",
8796 oi->params->passive_interface ? "" : "no ",
8797 oi->ifp->name,
8798 inet_ntoa(oi->address->u.prefix4));
8799 }
8800
8801 /* Network area print. */
8802 config_write_network_area(vty, ospf);
8803
8804 /* Area config print. */
8805 config_write_ospf_area(vty, ospf);
8806
8807 /* static neighbor print. */
8808 config_write_ospf_nbr_nbma(vty, ospf);
8809
8810 /* Virtual-Link print. */
8811 config_write_virtual_link(vty, ospf);
8812
8813 /* Default metric configuration. */
8814 config_write_ospf_default_metric(vty, ospf);
8815
8816 /* Distribute-list and default-information print. */
8817 config_write_ospf_distribute(vty, ospf);
8818
8819 /* Distance configuration. */
8820 config_write_ospf_distance(vty, ospf);
8821
8822 ospf_opaque_config_write_router(vty, ospf);
8823 }
8824
8825 return write;
8826}
8827
8828void ospf_vty_show_init(void)
8829{
8830 /* "show ip ospf" commands. */
8831 install_element(VIEW_NODE, &show_ip_ospf_cmd);
8832
8833 install_element(VIEW_NODE, &show_ip_ospf_instance_cmd);
8834
8835 /* "show ip ospf database" commands. */
8836 install_element(VIEW_NODE, &show_ip_ospf_database_max_cmd);
8837
8838 install_element(VIEW_NODE,
8839 &show_ip_ospf_instance_database_type_adv_router_cmd);
8840 install_element(VIEW_NODE, &show_ip_ospf_instance_database_cmd);
8841 install_element(VIEW_NODE, &show_ip_ospf_instance_database_max_cmd);
8842
8843 /* "show ip ospf interface" commands. */
8844 install_element(VIEW_NODE, &show_ip_ospf_interface_cmd);
8845
8846 install_element(VIEW_NODE, &show_ip_ospf_instance_interface_cmd);
8847
8848 /* "show ip ospf neighbor" commands. */
8849 install_element(VIEW_NODE, &show_ip_ospf_neighbor_int_detail_cmd);
8850 install_element(VIEW_NODE, &show_ip_ospf_neighbor_int_cmd);
8851 install_element(VIEW_NODE, &show_ip_ospf_neighbor_id_cmd);
8852 install_element(VIEW_NODE, &show_ip_ospf_neighbor_detail_all_cmd);
8853 install_element(VIEW_NODE, &show_ip_ospf_neighbor_detail_cmd);
8854 install_element(VIEW_NODE, &show_ip_ospf_neighbor_cmd);
8855 install_element(VIEW_NODE, &show_ip_ospf_neighbor_all_cmd);
8856
8857 install_element(VIEW_NODE,
8858 &show_ip_ospf_instance_neighbor_int_detail_cmd);
8859 install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_int_cmd);
8860 install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_id_cmd);
8861 install_element(VIEW_NODE,
8862 &show_ip_ospf_instance_neighbor_detail_all_cmd);
8863 install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_detail_cmd);
8864 install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_cmd);
8865 install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_all_cmd);
8866
8867 /* "show ip ospf route" commands. */
8868 install_element(VIEW_NODE, &show_ip_ospf_route_cmd);
8869 install_element(VIEW_NODE, &show_ip_ospf_border_routers_cmd);
8870
8871 install_element(VIEW_NODE, &show_ip_ospf_instance_route_cmd);
8872 install_element(VIEW_NODE, &show_ip_ospf_instance_border_routers_cmd);
718e3744 8873}
8874
6b0655a2 8875
718e3744 8876/* ospfd's interface node. */
d62a17ae 8877static struct cmd_node interface_node = {INTERFACE_NODE, "%s(config-if)# ", 1};
718e3744 8878
8879/* Initialization of OSPF interface. */
d62a17ae 8880static void ospf_vty_if_init(void)
8881{
8882 /* Install interface node. */
8883 install_node(&interface_node, config_write_interface);
8884 if_cmd_init();
8885
8886 /* "ip ospf authentication" commands. */
8887 install_element(INTERFACE_NODE, &ip_ospf_authentication_args_addr_cmd);
8888 install_element(INTERFACE_NODE, &ip_ospf_authentication_addr_cmd);
8889 install_element(INTERFACE_NODE,
8890 &no_ip_ospf_authentication_args_addr_cmd);
8891 install_element(INTERFACE_NODE, &no_ip_ospf_authentication_addr_cmd);
8892 install_element(INTERFACE_NODE, &ip_ospf_authentication_key_addr_cmd);
8893 install_element(INTERFACE_NODE,
8894 &no_ip_ospf_authentication_key_authkey_addr_cmd);
8895 install_element(INTERFACE_NODE,
8896 &no_ospf_authentication_key_authkey_addr_cmd);
8897
8898 /* "ip ospf message-digest-key" commands. */
8899 install_element(INTERFACE_NODE, &ip_ospf_message_digest_key_cmd);
8900 install_element(INTERFACE_NODE, &no_ip_ospf_message_digest_key_cmd);
8901
8902 /* "ip ospf cost" commands. */
8903 install_element(INTERFACE_NODE, &ip_ospf_cost_cmd);
8904 install_element(INTERFACE_NODE, &no_ip_ospf_cost_cmd);
8905
8906 /* "ip ospf mtu-ignore" commands. */
8907 install_element(INTERFACE_NODE, &ip_ospf_mtu_ignore_addr_cmd);
8908 install_element(INTERFACE_NODE, &no_ip_ospf_mtu_ignore_addr_cmd);
8909
8910 /* "ip ospf dead-interval" commands. */
8911 install_element(INTERFACE_NODE, &ip_ospf_dead_interval_cmd);
8912 install_element(INTERFACE_NODE,
8913 &ip_ospf_dead_interval_minimal_addr_cmd);
8914 install_element(INTERFACE_NODE, &no_ip_ospf_dead_interval_cmd);
8915
8916 /* "ip ospf hello-interval" commands. */
8917 install_element(INTERFACE_NODE, &ip_ospf_hello_interval_cmd);
8918 install_element(INTERFACE_NODE, &no_ip_ospf_hello_interval_cmd);
8919
8920 /* "ip ospf network" commands. */
8921 install_element(INTERFACE_NODE, &ip_ospf_network_cmd);
8922 install_element(INTERFACE_NODE, &no_ip_ospf_network_cmd);
8923
8924 /* "ip ospf priority" commands. */
8925 install_element(INTERFACE_NODE, &ip_ospf_priority_cmd);
8926 install_element(INTERFACE_NODE, &no_ip_ospf_priority_cmd);
8927
8928 /* "ip ospf retransmit-interval" commands. */
8929 install_element(INTERFACE_NODE, &ip_ospf_retransmit_interval_addr_cmd);
8930 install_element(INTERFACE_NODE,
8931 &no_ip_ospf_retransmit_interval_addr_cmd);
8932
8933 /* "ip ospf transmit-delay" commands. */
8934 install_element(INTERFACE_NODE, &ip_ospf_transmit_delay_addr_cmd);
8935 install_element(INTERFACE_NODE, &no_ip_ospf_transmit_delay_addr_cmd);
8936
8937 /* "ip ospf area" commands. */
8938 install_element(INTERFACE_NODE, &ip_ospf_area_cmd);
8939 install_element(INTERFACE_NODE, &no_ip_ospf_area_cmd);
8940
8941 /* These commands are compatibitliy for previous version. */
8942 install_element(INTERFACE_NODE, &ospf_authentication_key_cmd);
8943 install_element(INTERFACE_NODE, &ospf_message_digest_key_cmd);
8944 install_element(INTERFACE_NODE, &no_ospf_message_digest_key_cmd);
8945 install_element(INTERFACE_NODE, &ospf_dead_interval_cmd);
8946 install_element(INTERFACE_NODE, &no_ospf_dead_interval_cmd);
8947 install_element(INTERFACE_NODE, &ospf_hello_interval_cmd);
8948 install_element(INTERFACE_NODE, &no_ospf_hello_interval_cmd);
8949 install_element(INTERFACE_NODE, &ospf_cost_cmd);
8950 install_element(INTERFACE_NODE, &no_ospf_cost_cmd);
8951 install_element(INTERFACE_NODE, &ospf_network_cmd);
8952 install_element(INTERFACE_NODE, &no_ospf_network_cmd);
8953 install_element(INTERFACE_NODE, &ospf_priority_cmd);
8954 install_element(INTERFACE_NODE, &no_ospf_priority_cmd);
8955 install_element(INTERFACE_NODE, &ospf_retransmit_interval_cmd);
8956 install_element(INTERFACE_NODE, &no_ospf_retransmit_interval_cmd);
8957 install_element(INTERFACE_NODE, &ospf_transmit_delay_cmd);
8958 install_element(INTERFACE_NODE, &no_ospf_transmit_delay_cmd);
8959}
8960
8961static void ospf_vty_zebra_init(void)
8962{
8963 install_element(OSPF_NODE, &ospf_redistribute_source_cmd);
8964 install_element(OSPF_NODE, &no_ospf_redistribute_source_cmd);
8965 install_element(OSPF_NODE, &ospf_redistribute_instance_source_cmd);
8966 install_element(OSPF_NODE, &no_ospf_redistribute_instance_source_cmd);
8967
8968 install_element(OSPF_NODE, &ospf_distribute_list_out_cmd);
8969 install_element(OSPF_NODE, &no_ospf_distribute_list_out_cmd);
8970
8971 install_element(OSPF_NODE, &ospf_default_information_originate_cmd);
8972 install_element(OSPF_NODE, &no_ospf_default_information_originate_cmd);
8973
8974 install_element(OSPF_NODE, &ospf_default_metric_cmd);
8975 install_element(OSPF_NODE, &no_ospf_default_metric_cmd);
8976
8977 install_element(OSPF_NODE, &ospf_distance_cmd);
8978 install_element(OSPF_NODE, &no_ospf_distance_cmd);
8979 install_element(OSPF_NODE, &no_ospf_distance_ospf_cmd);
8980 install_element(OSPF_NODE, &ospf_distance_ospf_cmd);
718e3744 8981#if 0
8982 install_element (OSPF_NODE, &ospf_distance_source_cmd);
8983 install_element (OSPF_NODE, &no_ospf_distance_source_cmd);
8984 install_element (OSPF_NODE, &ospf_distance_source_access_list_cmd);
8985 install_element (OSPF_NODE, &no_ospf_distance_source_access_list_cmd);
8986#endif /* 0 */
8987}
8988
d62a17ae 8989static struct cmd_node ospf_node = {OSPF_NODE, "%s(config-router)# ", 1};
718e3744 8990
d62a17ae 8991static void ospf_interface_clear(struct interface *ifp)
09f35f8c 8992{
d62a17ae 8993 if (!if_is_operative(ifp))
8994 return;
09f35f8c 8995
d62a17ae 8996 if (IS_DEBUG_OSPF(ism, ISM_EVENTS))
8997 zlog_debug("ISM[%s]: clear by reset", ifp->name);
09f35f8c 8998
d62a17ae 8999 ospf_if_reset(ifp);
09f35f8c
DS
9000}
9001
9002DEFUN (clear_ip_ospf_interface,
9003 clear_ip_ospf_interface_cmd,
9004 "clear ip ospf interface [IFNAME]",
9005 CLEAR_STR
9006 IP_STR
9007 "OSPF information\n"
9008 "Interface information\n"
9009 "Interface name\n")
9010{
d62a17ae 9011 int idx_ifname = 4;
9012 struct interface *ifp;
9013 struct listnode *node;
09f35f8c 9014
d62a17ae 9015 if (argc == 4) /* Clear all the ospfv2 interfaces. */
9016 {
9017 for (ALL_LIST_ELEMENTS_RO(vrf_iflist(VRF_DEFAULT), node, ifp))
9018 ospf_interface_clear(ifp);
9019 } else /* Interface name is specified. */
9020 {
9021 if ((ifp = if_lookup_by_name(argv[idx_ifname]->arg,
9022 VRF_DEFAULT))
9023 == NULL)
9024 vty_out(vty, "No such interface name\n");
9025 else
9026 ospf_interface_clear(ifp);
9027 }
9028
9029 return CMD_SUCCESS;
09f35f8c
DS
9030}
9031
d62a17ae 9032void ospf_vty_clear_init(void)
09f35f8c 9033{
d62a17ae 9034 install_element(ENABLE_NODE, &clear_ip_ospf_interface_cmd);
09f35f8c
DS
9035}
9036
6b0655a2 9037
718e3744 9038/* Install OSPF related vty commands. */
d62a17ae 9039void ospf_vty_init(void)
9040{
9041 /* Install ospf top node. */
9042 install_node(&ospf_node, ospf_config_write);
9043
9044 /* "router ospf" commands. */
9045 install_element(CONFIG_NODE, &router_ospf_cmd);
9046 install_element(CONFIG_NODE, &no_router_ospf_cmd);
9047
9048
9049 install_default(OSPF_NODE);
9050
9051 /* "ospf router-id" commands. */
9052 install_element(OSPF_NODE, &ospf_router_id_cmd);
9053 install_element(OSPF_NODE, &ospf_router_id_old_cmd);
9054 install_element(OSPF_NODE, &no_ospf_router_id_cmd);
9055
9056 /* "passive-interface" commands. */
9057 install_element(OSPF_NODE, &ospf_passive_interface_addr_cmd);
9058 install_element(OSPF_NODE, &no_ospf_passive_interface_addr_cmd);
9059
9060 /* "ospf abr-type" commands. */
9061 install_element(OSPF_NODE, &ospf_abr_type_cmd);
9062 install_element(OSPF_NODE, &no_ospf_abr_type_cmd);
9063
9064 /* "ospf log-adjacency-changes" commands. */
9065 install_element(OSPF_NODE, &ospf_log_adjacency_changes_cmd);
9066 install_element(OSPF_NODE, &ospf_log_adjacency_changes_detail_cmd);
9067 install_element(OSPF_NODE, &no_ospf_log_adjacency_changes_cmd);
9068 install_element(OSPF_NODE, &no_ospf_log_adjacency_changes_detail_cmd);
9069
9070 /* "ospf rfc1583-compatible" commands. */
9071 install_element(OSPF_NODE, &ospf_compatible_rfc1583_cmd);
9072 install_element(OSPF_NODE, &no_ospf_compatible_rfc1583_cmd);
9073 install_element(OSPF_NODE, &ospf_rfc1583_flag_cmd);
9074 install_element(OSPF_NODE, &no_ospf_rfc1583_flag_cmd);
9075
9076 /* "network area" commands. */
9077 install_element(OSPF_NODE, &ospf_network_area_cmd);
9078 install_element(OSPF_NODE, &no_ospf_network_area_cmd);
9079
9080 /* "area authentication" commands. */
9081 install_element(OSPF_NODE,
9082 &ospf_area_authentication_message_digest_cmd);
9083 install_element(OSPF_NODE, &ospf_area_authentication_cmd);
9084 install_element(OSPF_NODE, &no_ospf_area_authentication_cmd);
9085
9086 /* "area range" commands. */
9087 install_element(OSPF_NODE, &ospf_area_range_cmd);
9088 install_element(OSPF_NODE, &ospf_area_range_cost_cmd);
9089 install_element(OSPF_NODE, &ospf_area_range_not_advertise_cmd);
9090 install_element(OSPF_NODE, &no_ospf_area_range_cmd);
9091 install_element(OSPF_NODE, &ospf_area_range_substitute_cmd);
9092 install_element(OSPF_NODE, &no_ospf_area_range_substitute_cmd);
9093
9094 /* "area virtual-link" commands. */
9095 install_element(OSPF_NODE, &ospf_area_vlink_cmd);
9096 install_element(OSPF_NODE, &ospf_area_vlink_intervals_cmd);
9097 install_element(OSPF_NODE, &no_ospf_area_vlink_cmd);
9098 install_element(OSPF_NODE, &no_ospf_area_vlink_intervals_cmd);
9099
9100
9101 /* "area stub" commands. */
9102 install_element(OSPF_NODE, &ospf_area_stub_no_summary_cmd);
9103 install_element(OSPF_NODE, &ospf_area_stub_cmd);
9104 install_element(OSPF_NODE, &no_ospf_area_stub_no_summary_cmd);
9105 install_element(OSPF_NODE, &no_ospf_area_stub_cmd);
9106
9107 /* "area nssa" commands. */
9108 install_element(OSPF_NODE, &ospf_area_nssa_cmd);
9109 install_element(OSPF_NODE, &ospf_area_nssa_translate_no_summary_cmd);
9110 install_element(OSPF_NODE, &ospf_area_nssa_translate_cmd);
9111 install_element(OSPF_NODE, &ospf_area_nssa_no_summary_cmd);
9112 install_element(OSPF_NODE, &no_ospf_area_nssa_cmd);
9113
9114 install_element(OSPF_NODE, &ospf_area_default_cost_cmd);
9115 install_element(OSPF_NODE, &no_ospf_area_default_cost_cmd);
9116
9117 install_element(OSPF_NODE, &ospf_area_shortcut_cmd);
9118 install_element(OSPF_NODE, &no_ospf_area_shortcut_cmd);
9119
9120 install_element(OSPF_NODE, &ospf_area_export_list_cmd);
9121 install_element(OSPF_NODE, &no_ospf_area_export_list_cmd);
9122
9123 install_element(OSPF_NODE, &ospf_area_filter_list_cmd);
9124 install_element(OSPF_NODE, &no_ospf_area_filter_list_cmd);
9125
9126 install_element(OSPF_NODE, &ospf_area_import_list_cmd);
9127 install_element(OSPF_NODE, &no_ospf_area_import_list_cmd);
9128
9129 /* SPF timer commands */
9130 install_element(OSPF_NODE, &ospf_timers_throttle_spf_cmd);
9131 install_element(OSPF_NODE, &no_ospf_timers_throttle_spf_cmd);
9132
9133 /* LSA timers commands */
9134 install_element(OSPF_NODE, &ospf_timers_min_ls_interval_cmd);
9135 install_element(OSPF_NODE, &no_ospf_timers_min_ls_interval_cmd);
9136 install_element(OSPF_NODE, &ospf_timers_min_ls_arrival_cmd);
9137 install_element(OSPF_NODE, &no_ospf_timers_min_ls_arrival_cmd);
9138 install_element(OSPF_NODE, &ospf_timers_lsa_cmd);
9139 install_element(OSPF_NODE, &no_ospf_timers_lsa_cmd);
9140
9141 /* refresh timer commands */
9142 install_element(OSPF_NODE, &ospf_refresh_timer_cmd);
9143 install_element(OSPF_NODE, &no_ospf_refresh_timer_val_cmd);
9144
9145 /* max-metric commands */
9146 install_element(OSPF_NODE, &ospf_max_metric_router_lsa_admin_cmd);
9147 install_element(OSPF_NODE, &no_ospf_max_metric_router_lsa_admin_cmd);
9148 install_element(OSPF_NODE, &ospf_max_metric_router_lsa_startup_cmd);
9149 install_element(OSPF_NODE, &no_ospf_max_metric_router_lsa_startup_cmd);
9150 install_element(OSPF_NODE, &ospf_max_metric_router_lsa_shutdown_cmd);
9151 install_element(OSPF_NODE, &no_ospf_max_metric_router_lsa_shutdown_cmd);
9152
9153 /* reference bandwidth commands */
9154 install_element(OSPF_NODE, &ospf_auto_cost_reference_bandwidth_cmd);
9155 install_element(OSPF_NODE, &no_ospf_auto_cost_reference_bandwidth_cmd);
9156
9157 /* "neighbor" commands. */
9158 install_element(OSPF_NODE, &ospf_neighbor_cmd);
9159 install_element(OSPF_NODE, &ospf_neighbor_poll_interval_cmd);
9160 install_element(OSPF_NODE, &no_ospf_neighbor_cmd);
9161 install_element(OSPF_NODE, &no_ospf_neighbor_poll_cmd);
9162
9163 /* write multiplier commands */
9164 install_element(OSPF_NODE, &ospf_write_multiplier_cmd);
9165 install_element(OSPF_NODE, &write_multiplier_cmd);
9166 install_element(OSPF_NODE, &no_ospf_write_multiplier_cmd);
9167 install_element(OSPF_NODE, &no_write_multiplier_cmd);
9168
9169 /* Init interface related vty commands. */
9170 ospf_vty_if_init();
9171
9172 /* Init zebra related vty commands. */
9173 ospf_vty_zebra_init();
718e3744 9174}