Line data Source code
1 : /* OSPF VTY interface.
2 : * Copyright (C) 2005 6WIND <alain.ritoux@6wind.com>
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 : *
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
20 : */
21 :
22 : #include <zebra.h>
23 : #include <string.h>
24 :
25 : #include "printfrr.h"
26 : #include "monotime.h"
27 : #include "memory.h"
28 : #include "thread.h"
29 : #include "prefix.h"
30 : #include "table.h"
31 : #include "vty.h"
32 : #include "command.h"
33 : #include "plist.h"
34 : #include "log.h"
35 : #include "zclient.h"
36 : #include <lib/json.h>
37 : #include "defaults.h"
38 : #include "lib/printfrr.h"
39 :
40 : #include "ospfd/ospfd.h"
41 : #include "ospfd/ospf_asbr.h"
42 : #include "ospfd/ospf_lsa.h"
43 : #include "ospfd/ospf_lsdb.h"
44 : #include "ospfd/ospf_ism.h"
45 : #include "ospfd/ospf_interface.h"
46 : #include "ospfd/ospf_nsm.h"
47 : #include "ospfd/ospf_neighbor.h"
48 : #include "ospfd/ospf_flood.h"
49 : #include "ospfd/ospf_abr.h"
50 : #include "ospfd/ospf_spf.h"
51 : #include "ospfd/ospf_route.h"
52 : #include "ospfd/ospf_zebra.h"
53 : /*#include "ospfd/ospf_routemap.h" */
54 : #include "ospfd/ospf_vty.h"
55 : #include "ospfd/ospf_dump.h"
56 : #include "ospfd/ospf_bfd.h"
57 : #include "ospfd/ospf_ldp_sync.h"
58 :
59 :
60 4 : FRR_CFG_DEFAULT_BOOL(OSPF_LOG_ADJACENCY_CHANGES,
61 : { .val_bool = true, .match_profile = "datacenter", },
62 : { .val_bool = false },
63 : );
64 :
65 : static const char *const ospf_network_type_str[] = {
66 : "Null", "POINTOPOINT", "BROADCAST", "NBMA", "POINTOMULTIPOINT",
67 : "VIRTUALLINK", "LOOPBACK"};
68 :
69 : /* Utility functions. */
70 6 : int str2area_id(const char *str, struct in_addr *area_id, int *area_id_fmt)
71 : {
72 6 : char *ep;
73 :
74 6 : area_id->s_addr = htonl(strtoul(str, &ep, 10));
75 6 : if (*ep && !inet_aton(str, area_id))
76 : return -1;
77 :
78 12 : *area_id_fmt =
79 6 : *ep ? OSPF_AREA_ID_FMT_DOTTEDQUAD : OSPF_AREA_ID_FMT_DECIMAL;
80 :
81 6 : return 0;
82 : }
83 :
84 0 : static void area_id2str(char *buf, int length, struct in_addr *area_id,
85 : int area_id_fmt)
86 : {
87 0 : if (area_id_fmt == OSPF_AREA_ID_FMT_DOTTEDQUAD)
88 0 : inet_ntop(AF_INET, area_id, buf, length);
89 : else
90 0 : snprintf(buf, length, "%lu",
91 0 : (unsigned long)ntohl(area_id->s_addr));
92 0 : }
93 :
94 0 : static int str2metric(const char *str, int *metric)
95 : {
96 : /* Sanity check. */
97 0 : if (str == NULL)
98 : return 0;
99 :
100 0 : *metric = strtol(str, NULL, 10);
101 0 : if (*metric < 0 || *metric > 16777214) {
102 : /* vty_out (vty, "OSPF metric value is invalid\n"); */
103 : return 0;
104 : }
105 :
106 : return 1;
107 : }
108 :
109 0 : static int str2metric_type(const char *str, int *metric_type)
110 : {
111 : /* Sanity check. */
112 0 : if (str == NULL)
113 : return 0;
114 :
115 0 : if (strncmp(str, "1", 1) == 0)
116 : *metric_type = EXTERNAL_METRIC_TYPE_1;
117 0 : else if (strncmp(str, "2", 1) == 0)
118 : *metric_type = EXTERNAL_METRIC_TYPE_2;
119 : else
120 : return 0;
121 :
122 : return 1;
123 : }
124 :
125 0 : int ospf_oi_count(struct interface *ifp)
126 : {
127 0 : struct route_node *rn;
128 0 : int i = 0;
129 :
130 0 : for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn))
131 0 : if (rn->info)
132 0 : i++;
133 :
134 0 : return i;
135 : }
136 :
137 : #define OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf) \
138 : if (argv_find(argv, argc, "vrf", &idx_vrf)) { \
139 : vrf_name = argv[idx_vrf + 1]->arg; \
140 : all_vrf = strmatch(vrf_name, "all"); \
141 : }
142 :
143 4 : static int ospf_router_cmd_parse(struct vty *vty, struct cmd_token *argv[],
144 : const int argc, unsigned short *instance,
145 : const char **vrf_name)
146 : {
147 4 : int idx_vrf = 0, idx_inst = 0;
148 :
149 4 : *instance = 0;
150 4 : if (argv_find(argv, argc, "(1-65535)", &idx_inst)) {
151 0 : if (ospf_instance == 0) {
152 0 : vty_out(vty,
153 : "%% OSPF is not running in instance mode\n");
154 0 : return CMD_WARNING_CONFIG_FAILED;
155 : }
156 :
157 0 : *instance = strtoul(argv[idx_inst]->arg, NULL, 10);
158 : }
159 :
160 4 : *vrf_name = VRF_DEFAULT_NAME;
161 4 : if (argv_find(argv, argc, "vrf", &idx_vrf)) {
162 0 : if (ospf_instance != 0) {
163 0 : vty_out(vty,
164 : "%% VRF is not supported in instance mode\n");
165 0 : return CMD_WARNING_CONFIG_FAILED;
166 : }
167 :
168 0 : *vrf_name = argv[idx_vrf + 1]->arg;
169 : }
170 :
171 : return CMD_SUCCESS;
172 : }
173 :
174 112 : static void ospf_show_vrf_name(struct ospf *ospf, struct vty *vty,
175 : json_object *json, uint8_t use_vrf)
176 : {
177 112 : if (use_vrf) {
178 0 : if (json) {
179 0 : json_object_string_add(json, "vrfName",
180 : ospf_get_name(ospf));
181 0 : json_object_int_add(json, "vrfId", ospf->vrf_id);
182 : } else
183 0 : vty_out(vty, "VRF Name: %s\n", ospf_get_name(ospf));
184 : }
185 112 : }
186 :
187 : #include "ospfd/ospf_vty_clippy.c"
188 :
189 4 : DEFUN_NOSH (router_ospf,
190 : router_ospf_cmd,
191 : "router ospf [{(1-65535)|vrf NAME}]",
192 : "Enable a routing process\n"
193 : "Start OSPF configuration\n"
194 : "Instance ID\n"
195 : VRF_CMD_HELP_STR)
196 : {
197 4 : unsigned short instance;
198 4 : const char *vrf_name;
199 4 : bool created = false;
200 4 : struct ospf *ospf;
201 4 : int ret;
202 :
203 4 : ret = ospf_router_cmd_parse(vty, argv, argc, &instance, &vrf_name);
204 4 : if (ret != CMD_SUCCESS)
205 : return ret;
206 :
207 4 : if (instance != ospf_instance) {
208 0 : VTY_PUSH_CONTEXT_NULL(OSPF_NODE);
209 0 : return CMD_NOT_MY_INSTANCE;
210 : }
211 :
212 4 : ospf = ospf_get(instance, vrf_name, &created);
213 :
214 4 : if (created)
215 4 : if (DFLT_OSPF_LOG_ADJACENCY_CHANGES)
216 0 : SET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES);
217 :
218 4 : if (IS_DEBUG_OSPF_EVENT)
219 4 : zlog_debug(
220 : "Config command 'router ospf %d' received, vrf %s id %u oi_running %u",
221 : ospf->instance, ospf_get_name(ospf), ospf->vrf_id,
222 : ospf->oi_running);
223 :
224 4 : VTY_PUSH_CONTEXT(OSPF_NODE, ospf);
225 :
226 4 : return ret;
227 : }
228 :
229 0 : DEFUN (no_router_ospf,
230 : no_router_ospf_cmd,
231 : "no router ospf [{(1-65535)|vrf NAME}]",
232 : NO_STR
233 : "Enable a routing process\n"
234 : "Start OSPF configuration\n"
235 : "Instance ID\n"
236 : VRF_CMD_HELP_STR)
237 : {
238 0 : unsigned short instance;
239 0 : const char *vrf_name;
240 0 : struct ospf *ospf;
241 0 : int ret;
242 :
243 0 : ret = ospf_router_cmd_parse(vty, argv, argc, &instance, &vrf_name);
244 0 : if (ret != CMD_SUCCESS)
245 : return ret;
246 :
247 0 : if (instance != ospf_instance)
248 : return CMD_NOT_MY_INSTANCE;
249 :
250 0 : ospf = ospf_lookup(instance, vrf_name);
251 0 : if (ospf)
252 0 : ospf_finish(ospf);
253 : else
254 : ret = CMD_WARNING_CONFIG_FAILED;
255 :
256 : return ret;
257 : }
258 :
259 :
260 4 : DEFPY (ospf_router_id,
261 : ospf_router_id_cmd,
262 : "ospf router-id A.B.C.D",
263 : "OSPF specific commands\n"
264 : "router-id for the OSPF process\n"
265 : "OSPF router-id in IP address format\n")
266 : {
267 4 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
268 :
269 4 : struct listnode *node;
270 4 : struct ospf_area *area;
271 :
272 4 : ospf->router_id_static = router_id;
273 :
274 8 : for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area))
275 0 : if (area->full_nbrs) {
276 0 : vty_out(vty,
277 : "For this router-id change to take effect, use \"clear ip ospf process\" command\n");
278 0 : return CMD_SUCCESS;
279 : }
280 :
281 4 : ospf_router_id_update(ospf);
282 :
283 4 : return CMD_SUCCESS;
284 : }
285 :
286 0 : DEFUN_HIDDEN (ospf_router_id_old,
287 : ospf_router_id_old_cmd,
288 : "router-id A.B.C.D",
289 : "router-id for the OSPF process\n"
290 : "OSPF router-id in IP address format\n")
291 : {
292 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
293 0 : int idx_ipv4 = 1;
294 0 : struct listnode *node;
295 0 : struct ospf_area *area;
296 0 : struct in_addr router_id;
297 0 : int ret;
298 :
299 0 : ret = inet_aton(argv[idx_ipv4]->arg, &router_id);
300 0 : if (!ret) {
301 0 : vty_out(vty, "Please specify Router ID by A.B.C.D\n");
302 0 : return CMD_WARNING_CONFIG_FAILED;
303 : }
304 :
305 0 : ospf->router_id_static = router_id;
306 :
307 0 : for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area))
308 0 : if (area->full_nbrs) {
309 0 : vty_out(vty,
310 : "For this router-id change to take effect, use \"clear ip ospf process\" command\n");
311 0 : return CMD_SUCCESS;
312 : }
313 :
314 0 : ospf_router_id_update(ospf);
315 :
316 0 : return CMD_SUCCESS;
317 : }
318 :
319 0 : DEFPY (no_ospf_router_id,
320 : no_ospf_router_id_cmd,
321 : "no ospf router-id [A.B.C.D]",
322 : NO_STR
323 : "OSPF specific commands\n"
324 : "router-id for the OSPF process\n"
325 : "OSPF router-id in IP address format\n")
326 : {
327 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
328 0 : struct listnode *node;
329 0 : struct ospf_area *area;
330 :
331 0 : if (router_id_str) {
332 0 : if (!IPV4_ADDR_SAME(&ospf->router_id_static, &router_id)) {
333 0 : vty_out(vty, "%% OSPF router-id doesn't match\n");
334 0 : return CMD_WARNING_CONFIG_FAILED;
335 : }
336 : }
337 :
338 0 : ospf->router_id_static.s_addr = 0;
339 :
340 0 : for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area))
341 0 : if (area->full_nbrs) {
342 0 : vty_out(vty,
343 : "For this router-id change to take effect, use \"clear ip ospf process\" command\n");
344 0 : return CMD_SUCCESS;
345 : }
346 :
347 0 : ospf_router_id_update(ospf);
348 :
349 0 : return CMD_SUCCESS;
350 : }
351 :
352 :
353 0 : static void ospf_passive_interface_default_update(struct ospf *ospf,
354 : uint8_t newval)
355 : {
356 0 : struct listnode *ln;
357 0 : struct ospf_interface *oi;
358 :
359 0 : ospf->passive_interface_default = newval;
360 :
361 : /* update multicast memberships */
362 0 : for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, ln, oi))
363 0 : ospf_if_set_multicast(oi);
364 0 : }
365 :
366 0 : static void ospf_passive_interface_update(struct interface *ifp,
367 : struct ospf_if_params *params,
368 : struct in_addr addr, uint8_t newval)
369 : {
370 0 : struct route_node *rn;
371 :
372 0 : if (OSPF_IF_PARAM_CONFIGURED(params, passive_interface)) {
373 0 : if (params->passive_interface == newval)
374 : return;
375 :
376 0 : params->passive_interface = newval;
377 0 : UNSET_IF_PARAM(params, passive_interface);
378 0 : if (params != IF_DEF_PARAMS(ifp)) {
379 0 : ospf_free_if_params(ifp, addr);
380 0 : ospf_if_update_params(ifp, addr);
381 : }
382 : } else {
383 0 : params->passive_interface = newval;
384 0 : SET_IF_PARAM(params, passive_interface);
385 : }
386 :
387 : /*
388 : * XXX We should call ospf_if_set_multicast on exactly those
389 : * interfaces for which the passive property changed. It is too much
390 : * work to determine this set, so we do this for every interface.
391 : * This is safe and reasonable because ospf_if_set_multicast uses a
392 : * record of joined groups to avoid systems calls if the desired
393 : * memberships match the current memership.
394 : */
395 :
396 0 : for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) {
397 0 : struct ospf_interface *oi = rn->info;
398 :
399 0 : if (oi)
400 0 : ospf_if_set_multicast(oi);
401 : }
402 :
403 : /*
404 : * XXX It is not clear what state transitions the interface needs to
405 : * undergo when going from active to passive and vice versa. Fixing
406 : * this will require precise identification of interfaces having such a
407 : * transition.
408 : */
409 : }
410 :
411 0 : DEFUN (ospf_passive_interface_default,
412 : ospf_passive_interface_default_cmd,
413 : "passive-interface default",
414 : "Suppress routing updates on an interface\n"
415 : "Suppress routing updates on interfaces by default\n")
416 : {
417 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
418 :
419 0 : ospf_passive_interface_default_update(ospf, OSPF_IF_PASSIVE);
420 :
421 0 : return CMD_SUCCESS;
422 : }
423 :
424 0 : DEFUN_HIDDEN (ospf_passive_interface_addr,
425 : ospf_passive_interface_addr_cmd,
426 : "passive-interface IFNAME [A.B.C.D]",
427 : "Suppress routing updates on an interface\n"
428 : "Interface's name\n"
429 : "IPv4 address\n")
430 : {
431 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
432 0 : int idx_ipv4 = 2;
433 0 : struct interface *ifp = NULL;
434 0 : struct in_addr addr = {.s_addr = INADDR_ANY};
435 0 : struct ospf_if_params *params;
436 0 : int ret;
437 :
438 0 : vty_out(vty,
439 : "This command is deprecated, because it is not VRF-aware.\n");
440 0 : vty_out(vty,
441 : "Please, use \"ip ospf passive\" on an interface instead.\n");
442 :
443 0 : if (ospf->vrf_id != VRF_UNKNOWN)
444 0 : ifp = if_get_by_name(argv[1]->arg, ospf->vrf_id, ospf->name);
445 :
446 0 : if (ifp == NULL) {
447 0 : vty_out(vty, "interface %s not found.\n", (char *)argv[1]->arg);
448 0 : return CMD_WARNING_CONFIG_FAILED;
449 : }
450 :
451 0 : if (argc == 3) {
452 0 : ret = inet_aton(argv[idx_ipv4]->arg, &addr);
453 0 : if (!ret) {
454 0 : vty_out(vty,
455 : "Please specify interface address by A.B.C.D\n");
456 0 : return CMD_WARNING_CONFIG_FAILED;
457 : }
458 :
459 0 : params = ospf_get_if_params(ifp, addr);
460 0 : ospf_if_update_params(ifp, addr);
461 : } else {
462 0 : params = IF_DEF_PARAMS(ifp);
463 : }
464 :
465 0 : ospf_passive_interface_update(ifp, params, addr, OSPF_IF_PASSIVE);
466 :
467 0 : return CMD_SUCCESS;
468 : }
469 :
470 0 : DEFUN (no_ospf_passive_interface_default,
471 : no_ospf_passive_interface_default_cmd,
472 : "no passive-interface default",
473 : NO_STR
474 : "Allow routing updates on an interface\n"
475 : "Allow routing updates on interfaces by default\n")
476 : {
477 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
478 :
479 0 : ospf_passive_interface_default_update(ospf, OSPF_IF_ACTIVE);
480 :
481 0 : return CMD_SUCCESS;
482 : }
483 :
484 0 : DEFUN_HIDDEN (no_ospf_passive_interface,
485 : no_ospf_passive_interface_addr_cmd,
486 : "no passive-interface IFNAME [A.B.C.D]",
487 : NO_STR
488 : "Allow routing updates on an interface\n"
489 : "Interface's name\n"
490 : "IPv4 address\n")
491 : {
492 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
493 0 : int idx_ipv4 = 3;
494 0 : struct interface *ifp = NULL;
495 0 : struct in_addr addr = {.s_addr = INADDR_ANY};
496 0 : struct ospf_if_params *params;
497 0 : int ret;
498 :
499 0 : vty_out(vty,
500 : "This command is deprecated, because it is not VRF-aware.\n");
501 0 : vty_out(vty,
502 : "Please, use \"no ip ospf passive\" on an interface instead.\n");
503 :
504 0 : if (ospf->vrf_id != VRF_UNKNOWN)
505 0 : ifp = if_get_by_name(argv[2]->arg, ospf->vrf_id, ospf->name);
506 :
507 0 : if (ifp == NULL) {
508 0 : vty_out(vty, "interface %s not found.\n", (char *)argv[2]->arg);
509 0 : return CMD_WARNING_CONFIG_FAILED;
510 : }
511 :
512 0 : if (argc == 4) {
513 0 : ret = inet_aton(argv[idx_ipv4]->arg, &addr);
514 0 : if (!ret) {
515 0 : vty_out(vty,
516 : "Please specify interface address by A.B.C.D\n");
517 0 : return CMD_WARNING_CONFIG_FAILED;
518 : }
519 0 : params = ospf_lookup_if_params(ifp, addr);
520 0 : if (params == NULL)
521 : return CMD_SUCCESS;
522 : } else {
523 0 : params = IF_DEF_PARAMS(ifp);
524 : }
525 :
526 0 : ospf_passive_interface_update(ifp, params, addr, OSPF_IF_ACTIVE);
527 :
528 0 : return CMD_SUCCESS;
529 : }
530 :
531 :
532 6 : DEFUN (ospf_network_area,
533 : ospf_network_area_cmd,
534 : "network A.B.C.D/M area <A.B.C.D|(0-4294967295)>",
535 : "Enable routing on an IP network\n"
536 : "OSPF network prefix\n"
537 : "Set the OSPF area ID\n"
538 : "OSPF area ID in IP address format\n"
539 : "OSPF area ID as a decimal value\n")
540 : {
541 6 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
542 6 : int idx_ipv4_prefixlen = 1;
543 6 : int idx_ipv4_number = 3;
544 6 : struct prefix_ipv4 p;
545 6 : struct in_addr area_id;
546 6 : int ret, format;
547 6 : uint32_t count;
548 :
549 6 : if (ospf->instance) {
550 0 : vty_out(vty,
551 : "The network command is not supported in multi-instance ospf\n");
552 0 : return CMD_WARNING_CONFIG_FAILED;
553 : }
554 :
555 6 : count = ospf_count_area_params(ospf);
556 6 : if (count > 0) {
557 0 : vty_out(vty,
558 : "Please remove all ip ospf area x.x.x.x commands first.\n");
559 0 : if (IS_DEBUG_OSPF_EVENT)
560 0 : zlog_debug(
561 : "%s ospf vrf %s num of %u ip ospf area x config",
562 : __func__, ospf_get_name(ospf), count);
563 0 : return CMD_WARNING_CONFIG_FAILED;
564 : }
565 :
566 : /* Get network prefix and Area ID. */
567 6 : str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p);
568 6 : VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg);
569 :
570 6 : ret = ospf_network_set(ospf, &p, area_id, format);
571 6 : if (ret == 0) {
572 0 : vty_out(vty, "There is already same network statement.\n");
573 0 : return CMD_WARNING_CONFIG_FAILED;
574 : }
575 :
576 : return CMD_SUCCESS;
577 : }
578 :
579 0 : DEFUN (no_ospf_network_area,
580 : no_ospf_network_area_cmd,
581 : "no network A.B.C.D/M area <A.B.C.D|(0-4294967295)>",
582 : NO_STR
583 : "Enable routing on an IP network\n"
584 : "OSPF network prefix\n"
585 : "Set the OSPF area ID\n"
586 : "OSPF area ID in IP address format\n"
587 : "OSPF area ID as a decimal value\n")
588 : {
589 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
590 0 : int idx_ipv4_prefixlen = 2;
591 0 : int idx_ipv4_number = 4;
592 0 : struct prefix_ipv4 p;
593 0 : struct in_addr area_id;
594 0 : int ret, format;
595 :
596 0 : if (ospf->instance) {
597 0 : vty_out(vty,
598 : "The network command is not supported in multi-instance ospf\n");
599 0 : return CMD_WARNING_CONFIG_FAILED;
600 : }
601 :
602 : /* Get network prefix and Area ID. */
603 0 : str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p);
604 0 : VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg);
605 :
606 0 : ret = ospf_network_unset(ospf, &p, area_id);
607 0 : if (ret == 0) {
608 0 : vty_out(vty,
609 : "Can't find specified network area configuration.\n");
610 0 : return CMD_WARNING_CONFIG_FAILED;
611 : }
612 :
613 : return CMD_SUCCESS;
614 : }
615 :
616 0 : DEFUN (ospf_area_range,
617 : ospf_area_range_cmd,
618 : "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M [advertise [cost (0-16777215)]]",
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 : "Advertise this range (default)\n"
625 : "User specified metric for this range\n"
626 : "Advertised metric for this range\n")
627 : {
628 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
629 0 : int idx_ipv4_number = 1;
630 0 : int idx_ipv4_prefixlen = 3;
631 0 : int idx_cost = 6;
632 0 : struct prefix_ipv4 p;
633 0 : struct in_addr area_id;
634 0 : int format;
635 0 : uint32_t cost;
636 :
637 0 : VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg);
638 0 : str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p);
639 :
640 0 : ospf_area_range_set(ospf, area_id, &p, OSPF_AREA_RANGE_ADVERTISE);
641 0 : ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id),
642 : format);
643 0 : if (argc > 5) {
644 0 : cost = strtoul(argv[idx_cost]->arg, NULL, 10);
645 0 : ospf_area_range_cost_set(ospf, area_id, &p, cost);
646 : }
647 :
648 : return CMD_SUCCESS;
649 : }
650 :
651 0 : DEFUN (ospf_area_range_cost,
652 : ospf_area_range_cost_cmd,
653 : "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M {cost (0-16777215)|substitute A.B.C.D/M}",
654 : "OSPF area parameters\n"
655 : "OSPF area ID in IP address format\n"
656 : "OSPF area ID as a decimal value\n"
657 : "Summarize routes matching address/mask (border routers only)\n"
658 : "Area range prefix\n"
659 : "User specified metric for this range\n"
660 : "Advertised metric for this range\n"
661 : "Announce area range as another prefix\n"
662 : "Network prefix to be announced instead of range\n")
663 : {
664 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
665 0 : int idx_ipv4_number = 1;
666 0 : int idx_ipv4_prefixlen = 3;
667 0 : int idx = 4;
668 0 : struct prefix_ipv4 p, s;
669 0 : struct in_addr area_id;
670 0 : int format;
671 0 : uint32_t cost;
672 :
673 0 : VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg);
674 0 : str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p);
675 :
676 0 : ospf_area_range_set(ospf, area_id, &p, OSPF_AREA_RANGE_ADVERTISE);
677 0 : ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id),
678 : format);
679 :
680 0 : if (argv_find(argv, argc, "cost", &idx)) {
681 0 : cost = strtoul(argv[idx + 1]->arg, NULL, 10);
682 0 : ospf_area_range_cost_set(ospf, area_id, &p, cost);
683 : }
684 :
685 0 : idx = 4;
686 0 : if (argv_find(argv, argc, "substitute", &idx)) {
687 0 : str2prefix_ipv4(argv[idx + 1]->arg, &s);
688 0 : ospf_area_range_substitute_set(ospf, area_id, &p, &s);
689 : }
690 :
691 : return CMD_SUCCESS;
692 : }
693 :
694 0 : DEFUN (ospf_area_range_not_advertise,
695 : ospf_area_range_not_advertise_cmd,
696 : "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M not-advertise",
697 : "OSPF area parameters\n"
698 : "OSPF area ID in IP address format\n"
699 : "OSPF area ID as a decimal value\n"
700 : "Summarize routes matching address/mask (border routers only)\n"
701 : "Area range prefix\n"
702 : "DoNotAdvertise this range\n")
703 : {
704 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
705 0 : int idx_ipv4_number = 1;
706 0 : int idx_ipv4_prefixlen = 3;
707 0 : struct prefix_ipv4 p;
708 0 : struct in_addr area_id;
709 0 : int format;
710 :
711 0 : VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg);
712 0 : str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p);
713 :
714 0 : ospf_area_range_set(ospf, area_id, &p, 0);
715 0 : ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id),
716 : format);
717 0 : ospf_area_range_substitute_unset(ospf, area_id, &p);
718 :
719 0 : return CMD_SUCCESS;
720 : }
721 :
722 0 : DEFUN (no_ospf_area_range,
723 : no_ospf_area_range_cmd,
724 : "no area <A.B.C.D|(0-4294967295)> range A.B.C.D/M [<cost (0-16777215)|advertise [cost (0-16777215)]|not-advertise>]",
725 : NO_STR
726 : "OSPF area parameters\n"
727 : "OSPF area ID in IP address format\n"
728 : "OSPF area ID as a decimal value\n"
729 : "Summarize routes matching address/mask (border routers only)\n"
730 : "Area range prefix\n"
731 : "User specified metric for this range\n"
732 : "Advertised metric for this range\n"
733 : "Advertise this range (default)\n"
734 : "User specified metric for this range\n"
735 : "Advertised metric for this range\n"
736 : "DoNotAdvertise this range\n")
737 : {
738 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
739 0 : int idx_ipv4_number = 2;
740 0 : int idx_ipv4_prefixlen = 4;
741 0 : struct prefix_ipv4 p;
742 0 : struct in_addr area_id;
743 0 : int format;
744 :
745 0 : VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg);
746 0 : str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p);
747 :
748 0 : ospf_area_range_unset(ospf, area_id, &p);
749 :
750 0 : return CMD_SUCCESS;
751 : }
752 :
753 0 : DEFUN (no_ospf_area_range_substitute,
754 : no_ospf_area_range_substitute_cmd,
755 : "no area <A.B.C.D|(0-4294967295)> range A.B.C.D/M substitute A.B.C.D/M",
756 : NO_STR
757 : "OSPF area parameters\n"
758 : "OSPF area ID in IP address format\n"
759 : "OSPF area ID as a decimal value\n"
760 : "Summarize routes matching address/mask (border routers only)\n"
761 : "Area range prefix\n"
762 : "Announce area range as another prefix\n"
763 : "Network prefix to be announced instead of range\n")
764 : {
765 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
766 0 : int idx_ipv4_number = 2;
767 0 : int idx_ipv4_prefixlen = 4;
768 0 : int idx_ipv4_prefixlen_2 = 6;
769 0 : struct prefix_ipv4 p, s;
770 0 : struct in_addr area_id;
771 0 : int format;
772 :
773 0 : VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg);
774 0 : str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p);
775 0 : str2prefix_ipv4(argv[idx_ipv4_prefixlen_2]->arg, &s);
776 :
777 0 : ospf_area_range_substitute_unset(ospf, area_id, &p);
778 :
779 0 : return CMD_SUCCESS;
780 : }
781 :
782 :
783 : /* Command Handler Logic in VLink stuff is delicate!!
784 :
785 : ALTER AT YOUR OWN RISK!!!!
786 :
787 : Various dummy values are used to represent 'NoChange' state for
788 : VLink configuration NOT being changed by a VLink command, and
789 : special syntax is used within the command strings so that the
790 : typed in command verbs can be seen in the configuration command
791 : bacckend handler. This is to drastically reduce the verbeage
792 : required to coe up with a reasonably compatible Cisco VLink command
793 :
794 : - Matthew Grant <grantma@anathoth.gen.nz>
795 : Wed, 21 Feb 2001 15:13:52 +1300
796 : */
797 :
798 : /* Configuration data for virtual links
799 : */
800 : struct ospf_vl_config_data {
801 : struct vty *vty; /* vty stuff */
802 : struct in_addr area_id; /* area ID from command line */
803 : int area_id_fmt; /* command line area ID format */
804 : struct in_addr vl_peer; /* command line vl_peer */
805 : int auth_type; /* Authehntication type, if given */
806 : char *auth_key; /* simple password if present */
807 : int crypto_key_id; /* Cryptographic key ID */
808 : char *md5_key; /* MD5 authentication key */
809 : int hello_interval; /* Obvious what these are... */
810 : int retransmit_interval;
811 : int transmit_delay;
812 : int dead_interval;
813 : };
814 :
815 0 : static void ospf_vl_config_data_init(struct ospf_vl_config_data *vl_config,
816 : struct vty *vty)
817 : {
818 0 : memset(vl_config, 0, sizeof(struct ospf_vl_config_data));
819 0 : vl_config->auth_type = OSPF_AUTH_CMD_NOTSEEN;
820 0 : vl_config->vty = vty;
821 : }
822 :
823 : static struct ospf_vl_data *
824 0 : ospf_find_vl_data(struct ospf *ospf, struct ospf_vl_config_data *vl_config)
825 : {
826 0 : struct ospf_area *area;
827 0 : struct ospf_vl_data *vl_data;
828 0 : struct vty *vty;
829 0 : struct in_addr area_id;
830 :
831 0 : vty = vl_config->vty;
832 0 : area_id = vl_config->area_id;
833 :
834 0 : if (area_id.s_addr == OSPF_AREA_BACKBONE) {
835 0 : vty_out(vty,
836 : "Configuring VLs over the backbone is not allowed\n");
837 0 : return NULL;
838 : }
839 0 : area = ospf_area_get(ospf, area_id);
840 0 : ospf_area_display_format_set(ospf, area, vl_config->area_id_fmt);
841 :
842 0 : if (area->external_routing != OSPF_AREA_DEFAULT) {
843 0 : if (vl_config->area_id_fmt == OSPF_AREA_ID_FMT_DOTTEDQUAD)
844 0 : vty_out(vty, "Area %pI4 is %s\n", &area_id,
845 : area->external_routing == OSPF_AREA_NSSA
846 : ? "nssa"
847 : : "stub");
848 : else
849 0 : vty_out(vty, "Area %ld is %s\n",
850 0 : (unsigned long)ntohl(area_id.s_addr),
851 : area->external_routing == OSPF_AREA_NSSA
852 : ? "nssa"
853 : : "stub");
854 0 : return NULL;
855 : }
856 :
857 0 : if ((vl_data = ospf_vl_lookup(ospf, area, vl_config->vl_peer))
858 : == NULL) {
859 0 : vl_data = ospf_vl_data_new(area, vl_config->vl_peer);
860 0 : if (vl_data->vl_oi == NULL) {
861 0 : vl_data->vl_oi = ospf_vl_new(ospf, vl_data);
862 0 : ospf_vl_add(ospf, vl_data);
863 0 : ospf_spf_calculate_schedule(ospf,
864 : SPF_FLAG_CONFIG_CHANGE);
865 : }
866 : }
867 : return vl_data;
868 : }
869 :
870 :
871 0 : static int ospf_vl_set_security(struct ospf_vl_data *vl_data,
872 : struct ospf_vl_config_data *vl_config)
873 : {
874 0 : struct crypt_key *ck;
875 0 : struct vty *vty;
876 0 : struct interface *ifp = vl_data->vl_oi->ifp;
877 :
878 0 : vty = vl_config->vty;
879 :
880 0 : if (vl_config->auth_type != OSPF_AUTH_CMD_NOTSEEN) {
881 0 : SET_IF_PARAM(IF_DEF_PARAMS(ifp), auth_type);
882 0 : IF_DEF_PARAMS(ifp)->auth_type = vl_config->auth_type;
883 : }
884 :
885 0 : if (vl_config->auth_key) {
886 0 : memset(IF_DEF_PARAMS(ifp)->auth_simple, 0,
887 : OSPF_AUTH_SIMPLE_SIZE + 1);
888 0 : strlcpy((char *)IF_DEF_PARAMS(ifp)->auth_simple,
889 0 : vl_config->auth_key,
890 : sizeof(IF_DEF_PARAMS(ifp)->auth_simple));
891 0 : } else if (vl_config->md5_key) {
892 0 : if (ospf_crypt_key_lookup(IF_DEF_PARAMS(ifp)->auth_crypt,
893 0 : vl_config->crypto_key_id)
894 : != NULL) {
895 0 : vty_out(vty, "OSPF: Key %d already exists\n",
896 : vl_config->crypto_key_id);
897 0 : return CMD_WARNING;
898 : }
899 0 : ck = ospf_crypt_key_new();
900 0 : ck->key_id = vl_config->crypto_key_id;
901 0 : memset(ck->auth_key, 0, OSPF_AUTH_MD5_SIZE + 1);
902 0 : strlcpy((char *)ck->auth_key, vl_config->md5_key,
903 : sizeof(ck->auth_key));
904 :
905 0 : ospf_crypt_key_add(IF_DEF_PARAMS(ifp)->auth_crypt, ck);
906 0 : } else if (vl_config->crypto_key_id != 0) {
907 : /* Delete a key */
908 :
909 0 : if (ospf_crypt_key_lookup(IF_DEF_PARAMS(ifp)->auth_crypt,
910 : vl_config->crypto_key_id)
911 : == NULL) {
912 0 : vty_out(vty, "OSPF: Key %d does not exist\n",
913 : vl_config->crypto_key_id);
914 0 : return CMD_WARNING_CONFIG_FAILED;
915 : }
916 :
917 0 : ospf_crypt_key_delete(IF_DEF_PARAMS(ifp)->auth_crypt,
918 0 : vl_config->crypto_key_id);
919 : }
920 :
921 : return CMD_SUCCESS;
922 : }
923 :
924 0 : static int ospf_vl_set_timers(struct ospf_vl_data *vl_data,
925 : struct ospf_vl_config_data *vl_config)
926 : {
927 0 : struct interface *ifp = vl_data->vl_oi->ifp;
928 : /* Virtual Link data initialised to defaults, so only set
929 : if a value given */
930 0 : if (vl_config->hello_interval) {
931 0 : SET_IF_PARAM(IF_DEF_PARAMS(ifp), v_hello);
932 0 : IF_DEF_PARAMS(ifp)->v_hello = vl_config->hello_interval;
933 : }
934 :
935 0 : if (vl_config->dead_interval) {
936 0 : SET_IF_PARAM(IF_DEF_PARAMS(ifp), v_wait);
937 0 : IF_DEF_PARAMS(ifp)->v_wait = vl_config->dead_interval;
938 : }
939 :
940 0 : if (vl_config->retransmit_interval) {
941 0 : SET_IF_PARAM(IF_DEF_PARAMS(ifp), retransmit_interval);
942 0 : IF_DEF_PARAMS(ifp)->retransmit_interval =
943 0 : vl_config->retransmit_interval;
944 : }
945 :
946 0 : if (vl_config->transmit_delay) {
947 0 : SET_IF_PARAM(IF_DEF_PARAMS(ifp), transmit_delay);
948 0 : IF_DEF_PARAMS(ifp)->transmit_delay = vl_config->transmit_delay;
949 : }
950 :
951 0 : return CMD_SUCCESS;
952 : }
953 :
954 :
955 : /* The business end of all of the above */
956 0 : static int ospf_vl_set(struct ospf *ospf, struct ospf_vl_config_data *vl_config)
957 : {
958 0 : struct ospf_vl_data *vl_data;
959 0 : int ret;
960 :
961 0 : vl_data = ospf_find_vl_data(ospf, vl_config);
962 0 : if (!vl_data)
963 : return CMD_WARNING_CONFIG_FAILED;
964 :
965 : /* Process this one first as it can have a fatal result, which can
966 : only logically occur if the virtual link exists already
967 : Thus a command error does not result in a change to the
968 : running configuration such as unexpectedly altered timer
969 : values etc.*/
970 0 : ret = ospf_vl_set_security(vl_data, vl_config);
971 0 : if (ret != CMD_SUCCESS)
972 : return ret;
973 :
974 : /* Set any time based parameters, these area already range checked */
975 :
976 0 : ret = ospf_vl_set_timers(vl_data, vl_config);
977 0 : if (ret != CMD_SUCCESS)
978 : return ret;
979 :
980 : return CMD_SUCCESS;
981 : }
982 :
983 : /* This stuff exists to make specifying all the alias commands A LOT simpler
984 : */
985 : #define VLINK_HELPSTR_IPADDR \
986 : "OSPF area parameters\n" \
987 : "OSPF area ID in IP address format\n" \
988 : "OSPF area ID as a decimal value\n" \
989 : "Configure a virtual link\n" \
990 : "Router ID of the remote ABR\n"
991 :
992 : #define VLINK_HELPSTR_AUTHTYPE_SIMPLE \
993 : "Enable authentication on this virtual link\n" \
994 : "dummy string \n"
995 :
996 : #define VLINK_HELPSTR_AUTHTYPE_ALL \
997 : VLINK_HELPSTR_AUTHTYPE_SIMPLE \
998 : "Use null authentication\n" \
999 : "Use message-digest authentication\n"
1000 :
1001 : #define VLINK_HELPSTR_TIME_PARAM \
1002 : "Time between HELLO packets\n" \
1003 : "Seconds\n" \
1004 : "Time between retransmitting lost link state advertisements\n" \
1005 : "Seconds\n" \
1006 : "Link state transmit delay\n" \
1007 : "Seconds\n" \
1008 : "Interval time after which a neighbor is declared down\n" \
1009 : "Seconds\n"
1010 :
1011 : #define VLINK_HELPSTR_AUTH_SIMPLE \
1012 : "Authentication password (key)\n" \
1013 : "The OSPF password (key)\n"
1014 :
1015 : #define VLINK_HELPSTR_AUTH_MD5 \
1016 : "Message digest authentication password (key)\n" \
1017 : "Key ID\n" \
1018 : "Use MD5 algorithm\n" \
1019 : "The OSPF password (key)\n"
1020 :
1021 0 : DEFUN (ospf_area_vlink,
1022 : ospf_area_vlink_cmd,
1023 : "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>]",
1024 : VLINK_HELPSTR_IPADDR
1025 : "Enable authentication on this virtual link\n"
1026 : "Use message-digest authentication\n"
1027 : "Use null authentication\n"
1028 : VLINK_HELPSTR_AUTH_MD5
1029 : VLINK_HELPSTR_AUTH_SIMPLE)
1030 : {
1031 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
1032 0 : int idx_ipv4_number = 1;
1033 0 : int idx_ipv4 = 3;
1034 0 : struct ospf_vl_config_data vl_config;
1035 0 : char auth_key[OSPF_AUTH_SIMPLE_SIZE + 1];
1036 0 : char md5_key[OSPF_AUTH_MD5_SIZE + 1];
1037 0 : int ret;
1038 0 : int idx = 0;
1039 :
1040 0 : ospf_vl_config_data_init(&vl_config, vty);
1041 :
1042 : /* Read off first 2 parameters and check them */
1043 0 : ret = str2area_id(argv[idx_ipv4_number]->arg, &vl_config.area_id,
1044 : &vl_config.area_id_fmt);
1045 0 : if (ret < 0) {
1046 0 : vty_out(vty, "OSPF area ID is invalid\n");
1047 0 : return CMD_WARNING_CONFIG_FAILED;
1048 : }
1049 :
1050 0 : ret = inet_aton(argv[idx_ipv4]->arg, &vl_config.vl_peer);
1051 0 : if (!ret) {
1052 0 : vty_out(vty, "Please specify valid Router ID as a.b.c.d\n");
1053 0 : return CMD_WARNING_CONFIG_FAILED;
1054 : }
1055 :
1056 0 : if (argc <= 4) {
1057 : /* Thats all folks! - BUGS B. strikes again!!!*/
1058 :
1059 0 : return ospf_vl_set(ospf, &vl_config);
1060 : }
1061 :
1062 0 : if (argv_find(argv, argc, "authentication", &idx)) {
1063 : /* authentication - this option can only occur
1064 : at start of command line */
1065 0 : vl_config.auth_type = OSPF_AUTH_SIMPLE;
1066 : }
1067 :
1068 0 : if (argv_find(argv, argc, "message-digest", &idx)) {
1069 : /* authentication message-digest */
1070 0 : vl_config.auth_type = OSPF_AUTH_CRYPTOGRAPHIC;
1071 0 : } else if (argv_find(argv, argc, "null", &idx)) {
1072 : /* "authentication null" */
1073 0 : vl_config.auth_type = OSPF_AUTH_NULL;
1074 : }
1075 :
1076 0 : if (argv_find(argv, argc, "message-digest-key", &idx)) {
1077 0 : vl_config.md5_key = NULL;
1078 0 : vl_config.crypto_key_id = strtol(argv[idx + 1]->arg, NULL, 10);
1079 0 : if (vl_config.crypto_key_id < 0)
1080 : return CMD_WARNING_CONFIG_FAILED;
1081 :
1082 0 : strlcpy(md5_key, argv[idx + 3]->arg, sizeof(md5_key));
1083 0 : vl_config.md5_key = md5_key;
1084 : }
1085 :
1086 0 : if (argv_find(argv, argc, "authentication-key", &idx)) {
1087 0 : strlcpy(auth_key, argv[idx + 1]->arg, sizeof(auth_key));
1088 0 : vl_config.auth_key = auth_key;
1089 : }
1090 :
1091 : /* Action configuration */
1092 :
1093 0 : return ospf_vl_set(ospf, &vl_config);
1094 : }
1095 :
1096 0 : DEFUN (no_ospf_area_vlink,
1097 : no_ospf_area_vlink_cmd,
1098 : "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>]",
1099 : NO_STR
1100 : VLINK_HELPSTR_IPADDR
1101 : "Enable authentication on this virtual link\n"
1102 : "Use message-digest authentication\n"
1103 : "Use null authentication\n"
1104 : VLINK_HELPSTR_AUTH_MD5
1105 : VLINK_HELPSTR_AUTH_SIMPLE)
1106 : {
1107 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
1108 0 : int idx_ipv4_number = 2;
1109 0 : int idx_ipv4 = 4;
1110 0 : struct ospf_area *area;
1111 0 : struct ospf_vl_config_data vl_config;
1112 0 : struct ospf_vl_data *vl_data = NULL;
1113 0 : char auth_key[OSPF_AUTH_SIMPLE_SIZE + 1];
1114 0 : int idx = 0;
1115 0 : int ret, format;
1116 :
1117 0 : ospf_vl_config_data_init(&vl_config, vty);
1118 :
1119 0 : ret = str2area_id(argv[idx_ipv4_number]->arg, &vl_config.area_id,
1120 : &format);
1121 0 : if (ret < 0) {
1122 0 : vty_out(vty, "OSPF area ID is invalid\n");
1123 0 : return CMD_WARNING_CONFIG_FAILED;
1124 : }
1125 :
1126 0 : area = ospf_area_lookup_by_area_id(ospf, vl_config.area_id);
1127 0 : if (!area) {
1128 0 : vty_out(vty, "Area does not exist\n");
1129 0 : return CMD_WARNING_CONFIG_FAILED;
1130 : }
1131 :
1132 0 : ret = inet_aton(argv[idx_ipv4]->arg, &vl_config.vl_peer);
1133 0 : if (!ret) {
1134 0 : vty_out(vty, "Please specify valid Router ID as a.b.c.d\n");
1135 0 : return CMD_WARNING_CONFIG_FAILED;
1136 : }
1137 :
1138 0 : vl_data = ospf_vl_lookup(ospf, area, vl_config.vl_peer);
1139 0 : if (!vl_data) {
1140 0 : vty_out(vty, "Virtual link does not exist\n");
1141 0 : return CMD_WARNING_CONFIG_FAILED;
1142 : }
1143 :
1144 0 : if (argc <= 5) {
1145 : /* Basic VLink no command */
1146 : /* Thats all folks! - BUGS B. strikes again!!!*/
1147 0 : ospf_vl_delete(ospf, vl_data);
1148 0 : ospf_area_check_free(ospf, vl_config.area_id);
1149 0 : return CMD_SUCCESS;
1150 : }
1151 :
1152 : /* If we are down here, we are reseting parameters */
1153 : /* Deal with other parameters */
1154 :
1155 0 : if (argv_find(argv, argc, "authentication", &idx)) {
1156 : /* authentication - this option can only occur
1157 : at start of command line */
1158 0 : vl_config.auth_type = OSPF_AUTH_NOTSET;
1159 : }
1160 :
1161 0 : if (argv_find(argv, argc, "message-digest-key", &idx)) {
1162 0 : vl_config.md5_key = NULL;
1163 0 : vl_config.crypto_key_id = strtol(argv[idx + 1]->arg, NULL, 10);
1164 0 : if (vl_config.crypto_key_id < 0)
1165 : return CMD_WARNING_CONFIG_FAILED;
1166 : }
1167 :
1168 0 : if (argv_find(argv, argc, "authentication-key", &idx)) {
1169 : /* Reset authentication-key to 0 */
1170 0 : memset(auth_key, 0, OSPF_AUTH_SIMPLE_SIZE + 1);
1171 0 : vl_config.auth_key = auth_key;
1172 : }
1173 :
1174 : /* Action configuration */
1175 :
1176 0 : return ospf_vl_set(ospf, &vl_config);
1177 : }
1178 :
1179 0 : DEFUN (ospf_area_vlink_intervals,
1180 : ospf_area_vlink_intervals_cmd,
1181 : "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)}",
1182 : VLINK_HELPSTR_IPADDR
1183 : VLINK_HELPSTR_TIME_PARAM)
1184 : {
1185 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
1186 0 : struct ospf_vl_config_data vl_config;
1187 0 : int ret = 0;
1188 :
1189 0 : ospf_vl_config_data_init(&vl_config, vty);
1190 :
1191 0 : char *area_id = argv[1]->arg;
1192 0 : char *router_id = argv[3]->arg;
1193 :
1194 0 : ret = str2area_id(area_id, &vl_config.area_id, &vl_config.area_id_fmt);
1195 0 : if (ret < 0) {
1196 0 : vty_out(vty, "OSPF area ID is invalid\n");
1197 0 : return CMD_WARNING_CONFIG_FAILED;
1198 : }
1199 :
1200 0 : ret = inet_aton(router_id, &vl_config.vl_peer);
1201 0 : if (!ret) {
1202 0 : vty_out(vty, "Please specify valid Router ID as a.b.c.d\n");
1203 0 : return CMD_WARNING_CONFIG_FAILED;
1204 : }
1205 :
1206 0 : for (int idx = 4; idx < argc; idx++) {
1207 0 : if (strmatch(argv[idx]->text, "hello-interval"))
1208 0 : vl_config.hello_interval =
1209 0 : strtol(argv[++idx]->arg, NULL, 10);
1210 0 : else if (strmatch(argv[idx]->text, "retransmit-interval"))
1211 0 : vl_config.retransmit_interval =
1212 0 : strtol(argv[++idx]->arg, NULL, 10);
1213 0 : else if (strmatch(argv[idx]->text, "transmit-delay"))
1214 0 : vl_config.transmit_delay =
1215 0 : strtol(argv[++idx]->arg, NULL, 10);
1216 0 : else if (strmatch(argv[idx]->text, "dead-interval"))
1217 0 : vl_config.dead_interval =
1218 0 : strtol(argv[++idx]->arg, NULL, 10);
1219 : }
1220 :
1221 : /* Action configuration */
1222 0 : return ospf_vl_set(ospf, &vl_config);
1223 : }
1224 :
1225 0 : DEFUN (no_ospf_area_vlink_intervals,
1226 : no_ospf_area_vlink_intervals_cmd,
1227 : "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)}",
1228 : NO_STR
1229 : VLINK_HELPSTR_IPADDR
1230 : VLINK_HELPSTR_TIME_PARAM)
1231 : {
1232 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
1233 0 : struct ospf_vl_config_data vl_config;
1234 0 : int ret = 0;
1235 :
1236 0 : ospf_vl_config_data_init(&vl_config, vty);
1237 :
1238 0 : char *area_id = argv[2]->arg;
1239 0 : char *router_id = argv[4]->arg;
1240 :
1241 0 : ret = str2area_id(area_id, &vl_config.area_id, &vl_config.area_id_fmt);
1242 0 : if (ret < 0) {
1243 0 : vty_out(vty, "OSPF area ID is invalid\n");
1244 0 : return CMD_WARNING_CONFIG_FAILED;
1245 : }
1246 :
1247 0 : ret = inet_aton(router_id, &vl_config.vl_peer);
1248 0 : if (!ret) {
1249 0 : vty_out(vty, "Please specify valid Router ID as a.b.c.d\n");
1250 0 : return CMD_WARNING_CONFIG_FAILED;
1251 : }
1252 :
1253 0 : for (int idx = 5; idx < argc; idx++) {
1254 0 : if (strmatch(argv[idx]->text, "hello-interval"))
1255 0 : vl_config.hello_interval = OSPF_HELLO_INTERVAL_DEFAULT;
1256 0 : else if (strmatch(argv[idx]->text, "retransmit-interval"))
1257 0 : vl_config.retransmit_interval =
1258 : OSPF_RETRANSMIT_INTERVAL_DEFAULT;
1259 0 : else if (strmatch(argv[idx]->text, "transmit-delay"))
1260 0 : vl_config.transmit_delay = OSPF_TRANSMIT_DELAY_DEFAULT;
1261 0 : else if (strmatch(argv[idx]->text, "dead-interval"))
1262 0 : vl_config.dead_interval =
1263 : OSPF_ROUTER_DEAD_INTERVAL_DEFAULT;
1264 : }
1265 :
1266 : /* Action configuration */
1267 0 : return ospf_vl_set(ospf, &vl_config);
1268 : }
1269 :
1270 0 : DEFUN (ospf_area_shortcut,
1271 : ospf_area_shortcut_cmd,
1272 : "area <A.B.C.D|(0-4294967295)> shortcut <default|enable|disable>",
1273 : "OSPF area parameters\n"
1274 : "OSPF area ID in IP address format\n"
1275 : "OSPF area ID as a decimal value\n"
1276 : "Configure the area's shortcutting mode\n"
1277 : "Set default shortcutting behavior\n"
1278 : "Enable shortcutting through the area\n"
1279 : "Disable shortcutting through the area\n")
1280 : {
1281 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
1282 0 : int idx_ipv4_number = 1;
1283 0 : int idx_enable_disable = 3;
1284 0 : struct ospf_area *area;
1285 0 : struct in_addr area_id;
1286 0 : int mode;
1287 0 : int format;
1288 :
1289 0 : VTY_GET_OSPF_AREA_ID_NO_BB("shortcut", area_id, format,
1290 0 : argv[idx_ipv4_number]->arg);
1291 :
1292 0 : area = ospf_area_get(ospf, area_id);
1293 0 : ospf_area_display_format_set(ospf, area, format);
1294 :
1295 0 : if (strncmp(argv[idx_enable_disable]->arg, "de", 2) == 0)
1296 : mode = OSPF_SHORTCUT_DEFAULT;
1297 0 : else if (strncmp(argv[idx_enable_disable]->arg, "di", 2) == 0)
1298 : mode = OSPF_SHORTCUT_DISABLE;
1299 0 : else if (strncmp(argv[idx_enable_disable]->arg, "e", 1) == 0)
1300 : mode = OSPF_SHORTCUT_ENABLE;
1301 : else
1302 : return CMD_WARNING_CONFIG_FAILED;
1303 :
1304 0 : ospf_area_shortcut_set(ospf, area, mode);
1305 :
1306 0 : if (ospf->abr_type != OSPF_ABR_SHORTCUT)
1307 0 : vty_out(vty,
1308 : "Shortcut area setting will take effect only when the router is configured as Shortcut ABR\n");
1309 :
1310 : return CMD_SUCCESS;
1311 : }
1312 :
1313 0 : DEFUN (no_ospf_area_shortcut,
1314 : no_ospf_area_shortcut_cmd,
1315 : "no area <A.B.C.D|(0-4294967295)> shortcut <enable|disable>",
1316 : NO_STR
1317 : "OSPF area parameters\n"
1318 : "OSPF area ID in IP address format\n"
1319 : "OSPF area ID as a decimal value\n"
1320 : "Deconfigure the area's shortcutting mode\n"
1321 : "Deconfigure enabled shortcutting through the area\n"
1322 : "Deconfigure disabled shortcutting through the area\n")
1323 : {
1324 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
1325 0 : int idx_ipv4_number = 2;
1326 0 : struct ospf_area *area;
1327 0 : struct in_addr area_id;
1328 0 : int format;
1329 :
1330 0 : VTY_GET_OSPF_AREA_ID_NO_BB("shortcut", area_id, format,
1331 0 : argv[idx_ipv4_number]->arg);
1332 :
1333 0 : area = ospf_area_lookup_by_area_id(ospf, area_id);
1334 0 : if (!area)
1335 : return CMD_SUCCESS;
1336 :
1337 0 : ospf_area_shortcut_unset(ospf, area);
1338 :
1339 0 : return CMD_SUCCESS;
1340 : }
1341 :
1342 :
1343 0 : DEFUN (ospf_area_stub,
1344 : ospf_area_stub_cmd,
1345 : "area <A.B.C.D|(0-4294967295)> stub",
1346 : "OSPF area parameters\n"
1347 : "OSPF area ID in IP address format\n"
1348 : "OSPF area ID as a decimal value\n"
1349 : "Configure OSPF area as stub\n")
1350 : {
1351 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
1352 0 : int idx_ipv4_number = 1;
1353 0 : struct in_addr area_id;
1354 0 : int ret, format;
1355 :
1356 0 : VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id, format,
1357 0 : argv[idx_ipv4_number]->arg);
1358 :
1359 0 : ret = ospf_area_stub_set(ospf, area_id);
1360 0 : ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id),
1361 : format);
1362 0 : if (ret == 0) {
1363 0 : vty_out(vty,
1364 : "First deconfigure all virtual link through this area\n");
1365 0 : return CMD_WARNING_CONFIG_FAILED;
1366 : }
1367 :
1368 : /* Flush the external LSAs from the specified area */
1369 0 : ospf_flush_lsa_from_area(ospf, area_id, OSPF_AS_EXTERNAL_LSA);
1370 0 : ospf_area_no_summary_unset(ospf, area_id);
1371 :
1372 0 : return CMD_SUCCESS;
1373 : }
1374 :
1375 0 : DEFUN (ospf_area_stub_no_summary,
1376 : ospf_area_stub_no_summary_cmd,
1377 : "area <A.B.C.D|(0-4294967295)> stub no-summary",
1378 : "OSPF stub parameters\n"
1379 : "OSPF area ID in IP address format\n"
1380 : "OSPF area ID as a decimal value\n"
1381 : "Configure OSPF area as stub\n"
1382 : "Do not inject inter-area routes into stub\n")
1383 : {
1384 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
1385 0 : int idx_ipv4_number = 1;
1386 0 : struct in_addr area_id;
1387 0 : int ret, format;
1388 :
1389 0 : VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id, format,
1390 0 : argv[idx_ipv4_number]->arg);
1391 :
1392 0 : ret = ospf_area_stub_set(ospf, area_id);
1393 0 : ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id),
1394 : format);
1395 0 : if (ret == 0) {
1396 0 : vty_out(vty,
1397 : "%% Area cannot be stub as it contains a virtual link\n");
1398 0 : return CMD_WARNING_CONFIG_FAILED;
1399 : }
1400 :
1401 0 : ospf_area_no_summary_set(ospf, area_id);
1402 :
1403 0 : return CMD_SUCCESS;
1404 : }
1405 :
1406 0 : DEFUN (no_ospf_area_stub,
1407 : no_ospf_area_stub_cmd,
1408 : "no area <A.B.C.D|(0-4294967295)> stub",
1409 : NO_STR
1410 : "OSPF area parameters\n"
1411 : "OSPF area ID in IP address format\n"
1412 : "OSPF area ID as a decimal value\n"
1413 : "Configure OSPF area as stub\n")
1414 : {
1415 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
1416 0 : int idx_ipv4_number = 2;
1417 0 : struct in_addr area_id;
1418 0 : int format;
1419 :
1420 0 : VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id, format,
1421 0 : argv[idx_ipv4_number]->arg);
1422 :
1423 0 : ospf_area_stub_unset(ospf, area_id);
1424 0 : ospf_area_no_summary_unset(ospf, area_id);
1425 :
1426 0 : return CMD_SUCCESS;
1427 : }
1428 :
1429 0 : DEFUN (no_ospf_area_stub_no_summary,
1430 : no_ospf_area_stub_no_summary_cmd,
1431 : "no area <A.B.C.D|(0-4294967295)> stub no-summary",
1432 : NO_STR
1433 : "OSPF area parameters\n"
1434 : "OSPF area ID in IP address format\n"
1435 : "OSPF area ID as a decimal value\n"
1436 : "Configure OSPF area as stub\n"
1437 : "Do not inject inter-area routes into area\n")
1438 : {
1439 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
1440 0 : int idx_ipv4_number = 2;
1441 0 : struct in_addr area_id;
1442 0 : int format;
1443 :
1444 0 : VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id, format,
1445 0 : argv[idx_ipv4_number]->arg);
1446 0 : ospf_area_no_summary_unset(ospf, area_id);
1447 :
1448 0 : return CMD_SUCCESS;
1449 : }
1450 :
1451 0 : static int ospf_area_nssa_cmd_handler(struct vty *vty, int argc,
1452 : struct cmd_token **argv, int cfg_nosum,
1453 : int nosum)
1454 : {
1455 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
1456 0 : struct in_addr area_id;
1457 0 : int ret, format;
1458 :
1459 0 : VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id, format, argv[1]->arg);
1460 :
1461 0 : ret = ospf_area_nssa_set(ospf, area_id);
1462 0 : ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id),
1463 : format);
1464 0 : if (ret == 0) {
1465 0 : vty_out(vty,
1466 : "%% Area cannot be nssa as it contains a virtual link\n");
1467 0 : return CMD_WARNING_CONFIG_FAILED;
1468 : }
1469 :
1470 0 : if (argc > 3) {
1471 0 : if (strncmp(argv[3]->text, "translate-c", 11) == 0)
1472 0 : ospf_area_nssa_translator_role_set(
1473 : ospf, area_id, OSPF_NSSA_ROLE_CANDIDATE);
1474 0 : else if (strncmp(argv[3]->text, "translate-n", 11) == 0)
1475 0 : ospf_area_nssa_translator_role_set(
1476 : ospf, area_id, OSPF_NSSA_ROLE_NEVER);
1477 0 : else if (strncmp(argv[3]->text, "translate-a", 11) == 0)
1478 0 : ospf_area_nssa_translator_role_set(
1479 : ospf, area_id, OSPF_NSSA_ROLE_ALWAYS);
1480 : } else {
1481 0 : ospf_area_nssa_translator_role_set(ospf, area_id,
1482 : OSPF_NSSA_ROLE_CANDIDATE);
1483 : }
1484 :
1485 0 : if (cfg_nosum) {
1486 0 : if (nosum)
1487 0 : ospf_area_no_summary_set(ospf, area_id);
1488 : else
1489 0 : ospf_area_no_summary_unset(ospf, area_id);
1490 : }
1491 :
1492 : /* Flush the external LSA for the specified area */
1493 0 : ospf_flush_lsa_from_area(ospf, area_id, OSPF_AS_EXTERNAL_LSA);
1494 0 : ospf_schedule_abr_task(ospf);
1495 0 : ospf_schedule_asbr_nssa_redist_update(ospf);
1496 :
1497 0 : return CMD_SUCCESS;
1498 : }
1499 :
1500 :
1501 0 : DEFUN (ospf_area_nssa_translate,
1502 : ospf_area_nssa_translate_cmd,
1503 : "area <A.B.C.D|(0-4294967295)> nssa <translate-candidate|translate-never|translate-always>",
1504 : "OSPF area parameters\n"
1505 : "OSPF area ID in IP address format\n"
1506 : "OSPF area ID as a decimal value\n"
1507 : "Configure OSPF area as nssa\n"
1508 : "Configure NSSA-ABR for translate election (default)\n"
1509 : "Configure NSSA-ABR to never translate\n"
1510 : "Configure NSSA-ABR to always translate\n")
1511 : {
1512 0 : return ospf_area_nssa_cmd_handler(vty, argc, argv, 0, 0);
1513 : }
1514 :
1515 0 : DEFUN (ospf_area_nssa,
1516 : ospf_area_nssa_cmd,
1517 : "area <A.B.C.D|(0-4294967295)> nssa",
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 : {
1523 0 : return ospf_area_nssa_cmd_handler(vty, argc, argv, 0, 0);
1524 : }
1525 :
1526 0 : DEFUN(ospf_area_nssa_suppress_fa, ospf_area_nssa_suppress_fa_cmd,
1527 : "area <A.B.C.D|(0-4294967295)> nssa suppress-fa",
1528 : "OSPF area parameters\n"
1529 : "OSPF area ID in IP address format\n"
1530 : "OSPF area ID as a decimal value\n"
1531 : "Configure OSPF area as nssa\n"
1532 : "Suppress forwarding address\n")
1533 : {
1534 0 : int idx_ipv4_number = 1;
1535 0 : struct in_addr area_id;
1536 0 : int format;
1537 :
1538 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
1539 0 : VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id, format,
1540 0 : argv[idx_ipv4_number]->arg);
1541 :
1542 0 : ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id),
1543 : format);
1544 0 : ospf_area_nssa_suppress_fa_set(ospf, area_id);
1545 :
1546 0 : ospf_schedule_abr_task(ospf);
1547 :
1548 0 : return CMD_SUCCESS;
1549 : }
1550 :
1551 0 : DEFUN(no_ospf_area_nssa_suppress_fa, no_ospf_area_nssa_suppress_fa_cmd,
1552 : "no area <A.B.C.D|(0-4294967295)> nssa suppress-fa",
1553 : NO_STR
1554 : "OSPF area parameters\n"
1555 : "OSPF area ID in IP address format\n"
1556 : "OSPF area ID as a decimal value\n"
1557 : "Configure OSPF area as nssa\n"
1558 : "Suppress forwarding address\n")
1559 : {
1560 0 : int idx_ipv4_number = 2;
1561 0 : struct in_addr area_id;
1562 0 : int format;
1563 :
1564 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
1565 :
1566 0 : VTY_GET_OSPF_AREA_ID_NO_BB("nssa", area_id, format,
1567 0 : argv[idx_ipv4_number]->arg);
1568 :
1569 0 : ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id),
1570 : format);
1571 0 : ospf_area_nssa_suppress_fa_unset(ospf, area_id);
1572 :
1573 0 : ospf_schedule_abr_task(ospf);
1574 :
1575 0 : return CMD_SUCCESS;
1576 : }
1577 :
1578 0 : DEFUN (ospf_area_nssa_no_summary,
1579 : ospf_area_nssa_no_summary_cmd,
1580 : "area <A.B.C.D|(0-4294967295)> nssa no-summary",
1581 : "OSPF area parameters\n"
1582 : "OSPF area ID in IP address format\n"
1583 : "OSPF area ID as a decimal value\n"
1584 : "Configure OSPF area as nssa\n"
1585 : "Do not inject inter-area routes into nssa\n")
1586 : {
1587 0 : int idx_ipv4_number = 1;
1588 0 : struct in_addr area_id;
1589 0 : int format;
1590 :
1591 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
1592 0 : VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id, format,
1593 0 : argv[idx_ipv4_number]->arg);
1594 :
1595 0 : ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id),
1596 : format);
1597 0 : ospf_area_nssa_no_summary_set(ospf, area_id);
1598 :
1599 0 : ospf_schedule_abr_task(ospf);
1600 :
1601 0 : return CMD_SUCCESS;
1602 : }
1603 :
1604 0 : DEFUN (no_ospf_area_nssa_no_summary,
1605 : no_ospf_area_nssa_no_summary_cmd,
1606 : "no area <A.B.C.D|(0-4294967295)> nssa no-summary",
1607 : NO_STR
1608 : "OSPF area parameters\n"
1609 : "OSPF area ID in IP address format\n"
1610 : "OSPF area ID as a decimal value\n"
1611 : "Configure OSPF area as nssa\n"
1612 : "Do not inject inter-area routes into nssa\n")
1613 : {
1614 0 : int idx_ipv4_number = 2;
1615 0 : struct in_addr area_id;
1616 0 : int format;
1617 :
1618 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
1619 :
1620 0 : VTY_GET_OSPF_AREA_ID_NO_BB("nssa", area_id, format,
1621 0 : argv[idx_ipv4_number]->arg);
1622 :
1623 0 : ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id),
1624 : format);
1625 0 : ospf_area_no_summary_unset(ospf, area_id);
1626 :
1627 0 : ospf_schedule_abr_task(ospf);
1628 :
1629 0 : return CMD_SUCCESS;
1630 : }
1631 :
1632 0 : DEFUN (no_ospf_area_nssa,
1633 : no_ospf_area_nssa_cmd,
1634 : "no area <A.B.C.D|(0-4294967295)> nssa [<translate-candidate|translate-never|translate-always>]",
1635 : NO_STR
1636 : "OSPF area parameters\n"
1637 : "OSPF area ID in IP address format\n"
1638 : "OSPF area ID as a decimal value\n"
1639 : "Configure OSPF area as nssa\n"
1640 : "Configure NSSA-ABR for translate election (default)\n"
1641 : "Configure NSSA-ABR to never translate\n"
1642 : "Configure NSSA-ABR to always translate\n")
1643 : {
1644 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
1645 0 : int idx_ipv4_number = 2;
1646 0 : struct in_addr area_id;
1647 0 : int format;
1648 :
1649 0 : VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id, format,
1650 0 : argv[idx_ipv4_number]->arg);
1651 :
1652 : /* Flush the NSSA LSA for the specified area */
1653 0 : ospf_flush_lsa_from_area(ospf, area_id, OSPF_AS_NSSA_LSA);
1654 0 : ospf_area_nssa_unset(ospf, area_id, argc);
1655 :
1656 0 : ospf_schedule_abr_task(ospf);
1657 :
1658 0 : return CMD_SUCCESS;
1659 : }
1660 :
1661 :
1662 0 : DEFUN (ospf_area_default_cost,
1663 : ospf_area_default_cost_cmd,
1664 : "area <A.B.C.D|(0-4294967295)> default-cost (0-16777215)",
1665 : "OSPF area parameters\n"
1666 : "OSPF area ID in IP address format\n"
1667 : "OSPF area ID as a decimal value\n"
1668 : "Set the summary-default cost of a NSSA or stub area\n"
1669 : "Stub's advertised default summary cost\n")
1670 : {
1671 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
1672 0 : int idx_ipv4_number = 1;
1673 0 : int idx_number = 3;
1674 0 : struct ospf_area *area;
1675 0 : struct in_addr area_id;
1676 0 : uint32_t cost;
1677 0 : int format;
1678 0 : struct prefix_ipv4 p;
1679 :
1680 0 : VTY_GET_OSPF_AREA_ID_NO_BB("default-cost", area_id, format,
1681 0 : argv[idx_ipv4_number]->arg);
1682 0 : cost = strtoul(argv[idx_number]->arg, NULL, 10);
1683 :
1684 0 : area = ospf_area_get(ospf, area_id);
1685 0 : ospf_area_display_format_set(ospf, area, format);
1686 :
1687 0 : if (area->external_routing == OSPF_AREA_DEFAULT) {
1688 0 : vty_out(vty, "The area is neither stub, nor NSSA\n");
1689 0 : return CMD_WARNING_CONFIG_FAILED;
1690 : }
1691 :
1692 0 : area->default_cost = cost;
1693 :
1694 0 : p.family = AF_INET;
1695 0 : p.prefix.s_addr = OSPF_DEFAULT_DESTINATION;
1696 0 : p.prefixlen = 0;
1697 0 : if (IS_DEBUG_OSPF_EVENT)
1698 0 : zlog_debug(
1699 : "ospf_abr_announce_stub_defaults(): announcing 0.0.0.0/0 to area %pI4",
1700 : &area->area_id);
1701 0 : ospf_abr_announce_network_to_area(&p, area->default_cost, area);
1702 :
1703 0 : return CMD_SUCCESS;
1704 : }
1705 :
1706 0 : DEFUN (no_ospf_area_default_cost,
1707 : no_ospf_area_default_cost_cmd,
1708 : "no area <A.B.C.D|(0-4294967295)> default-cost (0-16777215)",
1709 : NO_STR
1710 : "OSPF area parameters\n"
1711 : "OSPF area ID in IP address format\n"
1712 : "OSPF area ID as a decimal value\n"
1713 : "Set the summary-default cost of a NSSA or stub area\n"
1714 : "Stub's advertised default summary cost\n")
1715 : {
1716 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
1717 0 : int idx_ipv4_number = 2;
1718 0 : struct ospf_area *area;
1719 0 : struct in_addr area_id;
1720 0 : int format;
1721 0 : struct prefix_ipv4 p;
1722 :
1723 0 : VTY_GET_OSPF_AREA_ID_NO_BB("default-cost", area_id, format,
1724 0 : argv[idx_ipv4_number]->arg);
1725 :
1726 0 : area = ospf_area_lookup_by_area_id(ospf, area_id);
1727 0 : if (area == NULL)
1728 : return CMD_SUCCESS;
1729 :
1730 0 : if (area->external_routing == OSPF_AREA_DEFAULT) {
1731 0 : vty_out(vty, "The area is neither stub, nor NSSA\n");
1732 0 : return CMD_WARNING_CONFIG_FAILED;
1733 : }
1734 :
1735 0 : area->default_cost = 1;
1736 :
1737 0 : p.family = AF_INET;
1738 0 : p.prefix.s_addr = OSPF_DEFAULT_DESTINATION;
1739 0 : p.prefixlen = 0;
1740 0 : if (IS_DEBUG_OSPF_EVENT)
1741 0 : zlog_debug(
1742 : "ospf_abr_announce_stub_defaults(): announcing 0.0.0.0/0 to area %pI4",
1743 : &area->area_id);
1744 0 : ospf_abr_announce_network_to_area(&p, area->default_cost, area);
1745 :
1746 :
1747 0 : ospf_area_check_free(ospf, area_id);
1748 :
1749 0 : return CMD_SUCCESS;
1750 : }
1751 :
1752 0 : DEFUN (ospf_area_export_list,
1753 : ospf_area_export_list_cmd,
1754 : "area <A.B.C.D|(0-4294967295)> export-list ACCESSLIST4_NAME",
1755 : "OSPF area parameters\n"
1756 : "OSPF area ID in IP address format\n"
1757 : "OSPF area ID as a decimal value\n"
1758 : "Set the filter for networks announced to other areas\n"
1759 : "Name of the access-list\n")
1760 : {
1761 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
1762 0 : int idx_ipv4_number = 1;
1763 0 : struct ospf_area *area;
1764 0 : struct in_addr area_id;
1765 0 : int format;
1766 :
1767 0 : VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg);
1768 :
1769 0 : area = ospf_area_get(ospf, area_id);
1770 0 : ospf_area_display_format_set(ospf, area, format);
1771 0 : ospf_area_export_list_set(ospf, area, argv[3]->arg);
1772 :
1773 0 : return CMD_SUCCESS;
1774 : }
1775 :
1776 0 : DEFUN (no_ospf_area_export_list,
1777 : no_ospf_area_export_list_cmd,
1778 : "no area <A.B.C.D|(0-4294967295)> export-list ACCESSLIST4_NAME",
1779 : NO_STR
1780 : "OSPF area parameters\n"
1781 : "OSPF area ID in IP address format\n"
1782 : "OSPF area ID as a decimal value\n"
1783 : "Unset the filter for networks announced to other areas\n"
1784 : "Name of the access-list\n")
1785 : {
1786 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
1787 0 : int idx_ipv4_number = 2;
1788 0 : struct ospf_area *area;
1789 0 : struct in_addr area_id;
1790 0 : int format;
1791 :
1792 0 : VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg);
1793 :
1794 0 : area = ospf_area_lookup_by_area_id(ospf, area_id);
1795 0 : if (area == NULL)
1796 : return CMD_SUCCESS;
1797 :
1798 0 : ospf_area_export_list_unset(ospf, area);
1799 :
1800 0 : return CMD_SUCCESS;
1801 : }
1802 :
1803 :
1804 0 : DEFUN (ospf_area_import_list,
1805 : ospf_area_import_list_cmd,
1806 : "area <A.B.C.D|(0-4294967295)> import-list ACCESSLIST4_NAME",
1807 : "OSPF area parameters\n"
1808 : "OSPF area ID in IP address format\n"
1809 : "OSPF area ID as a decimal value\n"
1810 : "Set the filter for networks from other areas announced to the specified one\n"
1811 : "Name of the access-list\n")
1812 : {
1813 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
1814 0 : int idx_ipv4_number = 1;
1815 0 : struct ospf_area *area;
1816 0 : struct in_addr area_id;
1817 0 : int format;
1818 :
1819 0 : VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg);
1820 :
1821 0 : area = ospf_area_get(ospf, area_id);
1822 0 : ospf_area_display_format_set(ospf, area, format);
1823 0 : ospf_area_import_list_set(ospf, area, argv[3]->arg);
1824 :
1825 0 : return CMD_SUCCESS;
1826 : }
1827 :
1828 0 : DEFUN (no_ospf_area_import_list,
1829 : no_ospf_area_import_list_cmd,
1830 : "no area <A.B.C.D|(0-4294967295)> import-list ACCESSLIST4_NAME",
1831 : NO_STR
1832 : "OSPF area parameters\n"
1833 : "OSPF area ID in IP address format\n"
1834 : "OSPF area ID as a decimal value\n"
1835 : "Unset the filter for networks announced to other areas\n"
1836 : "Name of the access-list\n")
1837 : {
1838 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
1839 0 : int idx_ipv4_number = 2;
1840 0 : struct ospf_area *area;
1841 0 : struct in_addr area_id;
1842 0 : int format;
1843 :
1844 0 : VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg);
1845 :
1846 0 : area = ospf_area_lookup_by_area_id(ospf, area_id);
1847 0 : if (area == NULL)
1848 : return CMD_SUCCESS;
1849 :
1850 0 : ospf_area_import_list_unset(ospf, area);
1851 :
1852 0 : return CMD_SUCCESS;
1853 : }
1854 :
1855 0 : DEFUN (ospf_area_filter_list,
1856 : ospf_area_filter_list_cmd,
1857 : "area <A.B.C.D|(0-4294967295)> filter-list prefix PREFIXLIST_NAME <in|out>",
1858 : "OSPF area parameters\n"
1859 : "OSPF area ID in IP address format\n"
1860 : "OSPF area ID as a decimal value\n"
1861 : "Filter networks between OSPF areas\n"
1862 : "Filter prefixes between OSPF areas\n"
1863 : "Name of an IP prefix-list\n"
1864 : "Filter networks sent to this area\n"
1865 : "Filter networks sent from this area\n")
1866 : {
1867 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
1868 0 : int idx_ipv4_number = 1;
1869 0 : int idx_word = 4;
1870 0 : int idx_in_out = 5;
1871 0 : struct ospf_area *area;
1872 0 : struct in_addr area_id;
1873 0 : struct prefix_list *plist;
1874 0 : int format;
1875 :
1876 0 : VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg);
1877 :
1878 0 : area = ospf_area_get(ospf, area_id);
1879 0 : ospf_area_display_format_set(ospf, area, format);
1880 0 : plist = prefix_list_lookup(AFI_IP, argv[idx_word]->arg);
1881 0 : if (strncmp(argv[idx_in_out]->arg, "in", 2) == 0) {
1882 0 : PREFIX_LIST_IN(area) = plist;
1883 0 : if (PREFIX_NAME_IN(area))
1884 0 : free(PREFIX_NAME_IN(area));
1885 :
1886 0 : PREFIX_NAME_IN(area) = strdup(argv[idx_word]->arg);
1887 0 : ospf_schedule_abr_task(ospf);
1888 : } else {
1889 0 : PREFIX_LIST_OUT(area) = plist;
1890 0 : if (PREFIX_NAME_OUT(area))
1891 0 : free(PREFIX_NAME_OUT(area));
1892 :
1893 0 : PREFIX_NAME_OUT(area) = strdup(argv[idx_word]->arg);
1894 0 : ospf_schedule_abr_task(ospf);
1895 : }
1896 :
1897 : return CMD_SUCCESS;
1898 : }
1899 :
1900 0 : DEFUN (no_ospf_area_filter_list,
1901 : no_ospf_area_filter_list_cmd,
1902 : "no area <A.B.C.D|(0-4294967295)> filter-list prefix PREFIXLIST_NAME <in|out>",
1903 : NO_STR
1904 : "OSPF area parameters\n"
1905 : "OSPF area ID in IP address format\n"
1906 : "OSPF area ID as a decimal value\n"
1907 : "Filter networks between OSPF areas\n"
1908 : "Filter prefixes between OSPF areas\n"
1909 : "Name of an IP prefix-list\n"
1910 : "Filter networks sent to this area\n"
1911 : "Filter networks sent from this area\n")
1912 : {
1913 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
1914 0 : int idx_ipv4_number = 2;
1915 0 : int idx_word = 5;
1916 0 : int idx_in_out = 6;
1917 0 : struct ospf_area *area;
1918 0 : struct in_addr area_id;
1919 0 : int format;
1920 :
1921 0 : VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg);
1922 :
1923 0 : if ((area = ospf_area_lookup_by_area_id(ospf, area_id)) == NULL)
1924 : return CMD_SUCCESS;
1925 :
1926 0 : if (strncmp(argv[idx_in_out]->arg, "in", 2) == 0) {
1927 0 : if (PREFIX_NAME_IN(area))
1928 0 : if (strcmp(PREFIX_NAME_IN(area), argv[idx_word]->arg)
1929 : != 0)
1930 : return CMD_SUCCESS;
1931 :
1932 0 : PREFIX_LIST_IN(area) = NULL;
1933 0 : if (PREFIX_NAME_IN(area))
1934 0 : free(PREFIX_NAME_IN(area));
1935 :
1936 0 : PREFIX_NAME_IN(area) = NULL;
1937 :
1938 0 : ospf_schedule_abr_task(ospf);
1939 : } else {
1940 0 : if (PREFIX_NAME_OUT(area))
1941 0 : if (strcmp(PREFIX_NAME_OUT(area), argv[idx_word]->arg)
1942 : != 0)
1943 : return CMD_SUCCESS;
1944 :
1945 0 : PREFIX_LIST_OUT(area) = NULL;
1946 0 : if (PREFIX_NAME_OUT(area))
1947 0 : free(PREFIX_NAME_OUT(area));
1948 :
1949 0 : PREFIX_NAME_OUT(area) = NULL;
1950 :
1951 0 : ospf_schedule_abr_task(ospf);
1952 : }
1953 :
1954 : return CMD_SUCCESS;
1955 : }
1956 :
1957 :
1958 0 : DEFUN (ospf_area_authentication_message_digest,
1959 : ospf_area_authentication_message_digest_cmd,
1960 : "[no] area <A.B.C.D|(0-4294967295)> authentication message-digest",
1961 : NO_STR
1962 : "OSPF area parameters\n"
1963 : "OSPF area ID in IP address format\n"
1964 : "OSPF area ID as a decimal value\n"
1965 : "Enable authentication\n"
1966 : "Use message-digest authentication\n")
1967 : {
1968 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
1969 0 : int idx = 0;
1970 0 : struct ospf_area *area;
1971 0 : struct in_addr area_id;
1972 0 : int format;
1973 :
1974 0 : argv_find(argv, argc, "area", &idx);
1975 0 : VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx + 1]->arg);
1976 :
1977 0 : area = ospf_area_get(ospf, area_id);
1978 0 : ospf_area_display_format_set(ospf, area, format);
1979 0 : area->auth_type = strmatch(argv[0]->text, "no")
1980 : ? OSPF_AUTH_NULL
1981 0 : : OSPF_AUTH_CRYPTOGRAPHIC;
1982 :
1983 0 : return CMD_SUCCESS;
1984 : }
1985 :
1986 0 : DEFUN (ospf_area_authentication,
1987 : ospf_area_authentication_cmd,
1988 : "area <A.B.C.D|(0-4294967295)> authentication",
1989 : "OSPF area parameters\n"
1990 : "OSPF area ID in IP address format\n"
1991 : "OSPF area ID as a decimal value\n"
1992 : "Enable authentication\n")
1993 : {
1994 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
1995 0 : int idx_ipv4_number = 1;
1996 0 : struct ospf_area *area;
1997 0 : struct in_addr area_id;
1998 0 : int format;
1999 :
2000 0 : VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg);
2001 :
2002 0 : area = ospf_area_get(ospf, area_id);
2003 0 : ospf_area_display_format_set(ospf, area, format);
2004 0 : area->auth_type = OSPF_AUTH_SIMPLE;
2005 :
2006 0 : return CMD_SUCCESS;
2007 : }
2008 :
2009 0 : DEFUN (no_ospf_area_authentication,
2010 : no_ospf_area_authentication_cmd,
2011 : "no area <A.B.C.D|(0-4294967295)> authentication",
2012 : NO_STR
2013 : "OSPF area parameters\n"
2014 : "OSPF area ID in IP address format\n"
2015 : "OSPF area ID as a decimal value\n"
2016 : "Enable authentication\n")
2017 : {
2018 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
2019 0 : int idx_ipv4_number = 2;
2020 0 : struct ospf_area *area;
2021 0 : struct in_addr area_id;
2022 0 : int format;
2023 :
2024 0 : VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg);
2025 :
2026 0 : area = ospf_area_lookup_by_area_id(ospf, area_id);
2027 0 : if (area == NULL)
2028 : return CMD_SUCCESS;
2029 :
2030 0 : area->auth_type = OSPF_AUTH_NULL;
2031 :
2032 0 : ospf_area_check_free(ospf, area_id);
2033 :
2034 0 : return CMD_SUCCESS;
2035 : }
2036 :
2037 :
2038 0 : DEFUN (ospf_abr_type,
2039 : ospf_abr_type_cmd,
2040 : "ospf abr-type <cisco|ibm|shortcut|standard>",
2041 : "OSPF specific commands\n"
2042 : "Set OSPF ABR type\n"
2043 : "Alternative ABR, cisco implementation\n"
2044 : "Alternative ABR, IBM implementation\n"
2045 : "Shortcut ABR\n"
2046 : "Standard behavior (RFC2328)\n")
2047 : {
2048 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
2049 0 : int idx_vendor = 2;
2050 0 : uint8_t abr_type = OSPF_ABR_UNKNOWN;
2051 :
2052 0 : if (strncmp(argv[idx_vendor]->arg, "c", 1) == 0)
2053 : abr_type = OSPF_ABR_CISCO;
2054 0 : else if (strncmp(argv[idx_vendor]->arg, "i", 1) == 0)
2055 : abr_type = OSPF_ABR_IBM;
2056 0 : else if (strncmp(argv[idx_vendor]->arg, "sh", 2) == 0)
2057 : abr_type = OSPF_ABR_SHORTCUT;
2058 0 : else if (strncmp(argv[idx_vendor]->arg, "st", 2) == 0)
2059 : abr_type = OSPF_ABR_STAND;
2060 : else
2061 : return CMD_WARNING_CONFIG_FAILED;
2062 :
2063 : /* If ABR type value is changed, schedule ABR task. */
2064 0 : if (ospf->abr_type != abr_type) {
2065 0 : ospf->abr_type = abr_type;
2066 0 : ospf_schedule_abr_task(ospf);
2067 : }
2068 :
2069 : return CMD_SUCCESS;
2070 : }
2071 :
2072 0 : DEFUN (no_ospf_abr_type,
2073 : no_ospf_abr_type_cmd,
2074 : "no ospf abr-type <cisco|ibm|shortcut|standard>",
2075 : NO_STR
2076 : "OSPF specific commands\n"
2077 : "Set OSPF ABR type\n"
2078 : "Alternative ABR, cisco implementation\n"
2079 : "Alternative ABR, IBM implementation\n"
2080 : "Shortcut ABR\n"
2081 : "Standard ABR\n")
2082 : {
2083 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
2084 0 : int idx_vendor = 3;
2085 0 : uint8_t abr_type = OSPF_ABR_UNKNOWN;
2086 :
2087 0 : if (strncmp(argv[idx_vendor]->arg, "c", 1) == 0)
2088 : abr_type = OSPF_ABR_CISCO;
2089 0 : else if (strncmp(argv[idx_vendor]->arg, "i", 1) == 0)
2090 : abr_type = OSPF_ABR_IBM;
2091 0 : else if (strncmp(argv[idx_vendor]->arg, "sh", 2) == 0)
2092 : abr_type = OSPF_ABR_SHORTCUT;
2093 0 : else if (strncmp(argv[idx_vendor]->arg, "st", 2) == 0)
2094 : abr_type = OSPF_ABR_STAND;
2095 : else
2096 : return CMD_WARNING_CONFIG_FAILED;
2097 :
2098 : /* If ABR type value is changed, schedule ABR task. */
2099 0 : if (ospf->abr_type == abr_type) {
2100 0 : ospf->abr_type = OSPF_ABR_DEFAULT;
2101 0 : ospf_schedule_abr_task(ospf);
2102 : }
2103 :
2104 : return CMD_SUCCESS;
2105 : }
2106 :
2107 0 : DEFUN (ospf_log_adjacency_changes,
2108 : ospf_log_adjacency_changes_cmd,
2109 : "log-adjacency-changes",
2110 : "Log changes in adjacency state\n")
2111 : {
2112 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
2113 :
2114 0 : SET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES);
2115 0 : UNSET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL);
2116 0 : return CMD_SUCCESS;
2117 : }
2118 :
2119 0 : DEFUN (ospf_log_adjacency_changes_detail,
2120 : ospf_log_adjacency_changes_detail_cmd,
2121 : "log-adjacency-changes detail",
2122 : "Log changes in adjacency state\n"
2123 : "Log all state changes\n")
2124 : {
2125 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
2126 :
2127 0 : SET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES);
2128 0 : SET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL);
2129 0 : return CMD_SUCCESS;
2130 : }
2131 :
2132 0 : DEFUN (no_ospf_log_adjacency_changes,
2133 : no_ospf_log_adjacency_changes_cmd,
2134 : "no log-adjacency-changes",
2135 : NO_STR
2136 : "Log changes in adjacency state\n")
2137 : {
2138 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
2139 :
2140 0 : UNSET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL);
2141 0 : UNSET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES);
2142 0 : return CMD_SUCCESS;
2143 : }
2144 :
2145 0 : DEFUN (no_ospf_log_adjacency_changes_detail,
2146 : no_ospf_log_adjacency_changes_detail_cmd,
2147 : "no log-adjacency-changes detail",
2148 : NO_STR
2149 : "Log changes in adjacency state\n"
2150 : "Log all state changes\n")
2151 : {
2152 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
2153 :
2154 0 : UNSET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL);
2155 0 : return CMD_SUCCESS;
2156 : }
2157 :
2158 0 : DEFUN (ospf_compatible_rfc1583,
2159 : ospf_compatible_rfc1583_cmd,
2160 : "compatible rfc1583",
2161 : "OSPF compatibility list\n"
2162 : "compatible with RFC 1583\n")
2163 : {
2164 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
2165 :
2166 0 : if (!CHECK_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE)) {
2167 0 : SET_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE);
2168 0 : ospf_spf_calculate_schedule(ospf, SPF_FLAG_CONFIG_CHANGE);
2169 : }
2170 : return CMD_SUCCESS;
2171 : }
2172 :
2173 0 : DEFUN (no_ospf_compatible_rfc1583,
2174 : no_ospf_compatible_rfc1583_cmd,
2175 : "no compatible rfc1583",
2176 : NO_STR
2177 : "OSPF compatibility list\n"
2178 : "compatible with RFC 1583\n")
2179 : {
2180 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
2181 :
2182 0 : if (CHECK_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE)) {
2183 0 : UNSET_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE);
2184 0 : ospf_spf_calculate_schedule(ospf, SPF_FLAG_CONFIG_CHANGE);
2185 : }
2186 : return CMD_SUCCESS;
2187 : }
2188 :
2189 : ALIAS(ospf_compatible_rfc1583, ospf_rfc1583_flag_cmd,
2190 : "ospf rfc1583compatibility",
2191 : "OSPF specific commands\n"
2192 : "Enable the RFC1583Compatibility flag\n")
2193 :
2194 : ALIAS(no_ospf_compatible_rfc1583, no_ospf_rfc1583_flag_cmd,
2195 : "no ospf rfc1583compatibility", NO_STR
2196 : "OSPF specific commands\n"
2197 : "Disable the RFC1583Compatibility flag\n")
2198 :
2199 0 : static void ospf_table_reinstall_routes(struct ospf *ospf,
2200 : struct route_table *rt)
2201 : {
2202 0 : struct route_node *rn;
2203 :
2204 0 : if (!rt)
2205 : return;
2206 :
2207 0 : for (rn = route_top(rt); rn; rn = route_next(rn)) {
2208 0 : struct ospf_route *or;
2209 :
2210 0 : or = rn->info;
2211 0 : if (!or)
2212 0 : continue;
2213 :
2214 0 : if (or->type == OSPF_DESTINATION_NETWORK)
2215 0 : ospf_zebra_add(ospf, (struct prefix_ipv4 *)&rn->p, or);
2216 0 : else if (or->type == OSPF_DESTINATION_DISCARD)
2217 0 : ospf_zebra_add_discard(ospf,
2218 0 : (struct prefix_ipv4 *)&rn->p);
2219 : }
2220 : }
2221 :
2222 0 : static void ospf_reinstall_routes(struct ospf *ospf)
2223 : {
2224 0 : ospf_table_reinstall_routes(ospf, ospf->new_table);
2225 0 : ospf_table_reinstall_routes(ospf, ospf->new_external_route);
2226 0 : }
2227 :
2228 0 : DEFPY (ospf_send_extra_data,
2229 : ospf_send_extra_data_cmd,
2230 : "[no] ospf send-extra-data zebra",
2231 : NO_STR
2232 : OSPF_STR
2233 : "Extra data to Zebra for display/use\n"
2234 : "To zebra\n")
2235 : {
2236 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
2237 :
2238 0 : if (no && CHECK_FLAG(ospf->config, OSPF_SEND_EXTRA_DATA_TO_ZEBRA)) {
2239 0 : UNSET_FLAG(ospf->config, OSPF_SEND_EXTRA_DATA_TO_ZEBRA);
2240 0 : ospf_reinstall_routes(ospf);
2241 0 : } else if (!CHECK_FLAG(ospf->config, OSPF_SEND_EXTRA_DATA_TO_ZEBRA)) {
2242 0 : SET_FLAG(ospf->config, OSPF_SEND_EXTRA_DATA_TO_ZEBRA);
2243 0 : ospf_reinstall_routes(ospf);
2244 : }
2245 :
2246 : return CMD_SUCCESS;
2247 : }
2248 :
2249 4 : static int ospf_timers_spf_set(struct vty *vty, unsigned int delay,
2250 : unsigned int hold, unsigned int max)
2251 : {
2252 4 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
2253 :
2254 4 : ospf->spf_delay = delay;
2255 4 : ospf->spf_holdtime = hold;
2256 4 : ospf->spf_max_holdtime = max;
2257 :
2258 4 : return CMD_SUCCESS;
2259 : }
2260 :
2261 4 : DEFUN (ospf_timers_min_ls_interval,
2262 : ospf_timers_min_ls_interval_cmd,
2263 : "timers throttle lsa all (0-5000)",
2264 : "Adjust routing timers\n"
2265 : "Throttling adaptive timer\n"
2266 : "LSA delay between transmissions\n"
2267 : "All LSA types\n"
2268 : "Delay (msec) between sending LSAs\n")
2269 : {
2270 4 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
2271 4 : int idx_number = 4;
2272 4 : unsigned int interval;
2273 :
2274 4 : if (argc < 5) {
2275 0 : vty_out(vty, "Insufficient arguments\n");
2276 0 : return CMD_WARNING_CONFIG_FAILED;
2277 : }
2278 :
2279 4 : interval = strtoul(argv[idx_number]->arg, NULL, 10);
2280 :
2281 4 : ospf->min_ls_interval = interval;
2282 :
2283 4 : return CMD_SUCCESS;
2284 : }
2285 :
2286 0 : DEFUN (no_ospf_timers_min_ls_interval,
2287 : no_ospf_timers_min_ls_interval_cmd,
2288 : "no timers throttle lsa all [(0-5000)]",
2289 : NO_STR
2290 : "Adjust routing timers\n"
2291 : "Throttling adaptive timer\n"
2292 : "LSA delay between transmissions\n"
2293 : "All LSA types\n"
2294 : "Delay (msec) between sending LSAs\n")
2295 : {
2296 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
2297 0 : ospf->min_ls_interval = OSPF_MIN_LS_INTERVAL;
2298 :
2299 0 : return CMD_SUCCESS;
2300 : }
2301 :
2302 4 : DEFUN (ospf_timers_throttle_spf,
2303 : ospf_timers_throttle_spf_cmd,
2304 : "timers throttle spf (0-600000) (0-600000) (0-600000)",
2305 : "Adjust routing timers\n"
2306 : "Throttling adaptive timer\n"
2307 : "OSPF SPF timers\n"
2308 : "Delay (msec) from first change received till SPF calculation\n"
2309 : "Initial hold time (msec) between consecutive SPF calculations\n"
2310 : "Maximum hold time (msec)\n")
2311 : {
2312 4 : int idx_number = 3;
2313 4 : int idx_number_2 = 4;
2314 4 : int idx_number_3 = 5;
2315 4 : unsigned int delay, hold, max;
2316 :
2317 4 : if (argc < 6) {
2318 0 : vty_out(vty, "Insufficient arguments\n");
2319 0 : return CMD_WARNING_CONFIG_FAILED;
2320 : }
2321 :
2322 4 : delay = strtoul(argv[idx_number]->arg, NULL, 10);
2323 4 : hold = strtoul(argv[idx_number_2]->arg, NULL, 10);
2324 4 : max = strtoul(argv[idx_number_3]->arg, NULL, 10);
2325 :
2326 4 : return ospf_timers_spf_set(vty, delay, hold, max);
2327 : }
2328 :
2329 0 : DEFUN (no_ospf_timers_throttle_spf,
2330 : no_ospf_timers_throttle_spf_cmd,
2331 : "no timers throttle spf [(0-600000)(0-600000)(0-600000)]",
2332 : NO_STR
2333 : "Adjust routing timers\n"
2334 : "Throttling adaptive timer\n"
2335 : "OSPF SPF timers\n"
2336 : "Delay (msec) from first change received till SPF calculation\n"
2337 : "Initial hold time (msec) between consecutive SPF calculations\n"
2338 : "Maximum hold time (msec)\n")
2339 : {
2340 0 : return ospf_timers_spf_set(vty, OSPF_SPF_DELAY_DEFAULT,
2341 : OSPF_SPF_HOLDTIME_DEFAULT,
2342 : OSPF_SPF_MAX_HOLDTIME_DEFAULT);
2343 : }
2344 :
2345 :
2346 0 : DEFUN (ospf_timers_lsa_min_arrival,
2347 : ospf_timers_lsa_min_arrival_cmd,
2348 : "timers lsa min-arrival (0-600000)",
2349 : "Adjust routing timers\n"
2350 : "OSPF LSA timers\n"
2351 : "Minimum delay in receiving new version of a LSA\n"
2352 : "Delay in milliseconds\n")
2353 : {
2354 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
2355 0 : ospf->min_ls_arrival = strtoul(argv[argc - 1]->arg, NULL, 10);
2356 0 : return CMD_SUCCESS;
2357 : }
2358 :
2359 0 : DEFUN (no_ospf_timers_lsa_min_arrival,
2360 : no_ospf_timers_lsa_min_arrival_cmd,
2361 : "no timers lsa min-arrival [(0-600000)]",
2362 : NO_STR
2363 : "Adjust routing timers\n"
2364 : "OSPF LSA timers\n"
2365 : "Minimum delay in receiving new version of a LSA\n"
2366 : "Delay in milliseconds\n")
2367 : {
2368 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
2369 0 : unsigned int minarrival;
2370 :
2371 0 : if (argc > 4) {
2372 0 : minarrival = strtoul(argv[argc - 1]->arg, NULL, 10);
2373 :
2374 0 : if (ospf->min_ls_arrival != minarrival
2375 0 : || minarrival == OSPF_MIN_LS_ARRIVAL)
2376 : return CMD_SUCCESS;
2377 : }
2378 :
2379 0 : ospf->min_ls_arrival = OSPF_MIN_LS_ARRIVAL;
2380 :
2381 0 : return CMD_SUCCESS;
2382 : }
2383 :
2384 0 : DEFUN (ospf_neighbor,
2385 : ospf_neighbor_cmd,
2386 : "neighbor A.B.C.D [priority (0-255) [poll-interval (1-65535)]]",
2387 : NEIGHBOR_STR
2388 : "Neighbor IP address\n"
2389 : "Neighbor Priority\n"
2390 : "Priority\n"
2391 : "Dead Neighbor Polling interval\n"
2392 : "Seconds\n")
2393 : {
2394 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
2395 0 : int idx_ipv4 = 1;
2396 0 : int idx_pri = 3;
2397 0 : int idx_poll = 5;
2398 0 : struct in_addr nbr_addr;
2399 0 : unsigned int priority = OSPF_NEIGHBOR_PRIORITY_DEFAULT;
2400 0 : unsigned int interval = OSPF_POLL_INTERVAL_DEFAULT;
2401 :
2402 0 : if (!inet_aton(argv[idx_ipv4]->arg, &nbr_addr)) {
2403 0 : vty_out(vty, "Please specify Neighbor ID by A.B.C.D\n");
2404 0 : return CMD_WARNING_CONFIG_FAILED;
2405 : }
2406 :
2407 0 : if (argc > 2)
2408 0 : priority = strtoul(argv[idx_pri]->arg, NULL, 10);
2409 :
2410 0 : if (argc > 4)
2411 0 : interval = strtoul(argv[idx_poll]->arg, NULL, 10);
2412 :
2413 0 : ospf_nbr_nbma_set(ospf, nbr_addr);
2414 :
2415 0 : if (argc > 2)
2416 0 : ospf_nbr_nbma_priority_set(ospf, nbr_addr, priority);
2417 :
2418 0 : if (argc > 4)
2419 0 : ospf_nbr_nbma_poll_interval_set(ospf, nbr_addr, interval);
2420 :
2421 : return CMD_SUCCESS;
2422 : }
2423 :
2424 0 : DEFUN (ospf_neighbor_poll_interval,
2425 : ospf_neighbor_poll_interval_cmd,
2426 : "neighbor A.B.C.D poll-interval (1-65535) [priority (0-255)]",
2427 : NEIGHBOR_STR
2428 : "Neighbor IP address\n"
2429 : "Dead Neighbor Polling interval\n"
2430 : "Seconds\n"
2431 : "OSPF priority of non-broadcast neighbor\n"
2432 : "Priority\n")
2433 : {
2434 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
2435 0 : int idx_ipv4 = 1;
2436 0 : int idx_poll = 3;
2437 0 : int idx_pri = 5;
2438 0 : struct in_addr nbr_addr;
2439 0 : unsigned int priority;
2440 0 : unsigned int interval;
2441 :
2442 0 : if (!inet_aton(argv[idx_ipv4]->arg, &nbr_addr)) {
2443 0 : vty_out(vty, "Please specify Neighbor ID by A.B.C.D\n");
2444 0 : return CMD_WARNING_CONFIG_FAILED;
2445 : }
2446 :
2447 0 : interval = strtoul(argv[idx_poll]->arg, NULL, 10);
2448 :
2449 0 : priority = argc > 4 ? strtoul(argv[idx_pri]->arg, NULL, 10)
2450 : : OSPF_NEIGHBOR_PRIORITY_DEFAULT;
2451 :
2452 0 : ospf_nbr_nbma_set(ospf, nbr_addr);
2453 0 : ospf_nbr_nbma_poll_interval_set(ospf, nbr_addr, interval);
2454 :
2455 0 : if (argc > 4)
2456 0 : ospf_nbr_nbma_priority_set(ospf, nbr_addr, priority);
2457 :
2458 : return CMD_SUCCESS;
2459 : }
2460 :
2461 0 : DEFUN (no_ospf_neighbor,
2462 : no_ospf_neighbor_cmd,
2463 : "no neighbor A.B.C.D [priority (0-255) [poll-interval (1-65525)]]",
2464 : NO_STR
2465 : NEIGHBOR_STR
2466 : "Neighbor IP address\n"
2467 : "Neighbor Priority\n"
2468 : "Priority\n"
2469 : "Dead Neighbor Polling interval\n"
2470 : "Seconds\n")
2471 : {
2472 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
2473 0 : int idx_ipv4 = 2;
2474 0 : struct in_addr nbr_addr;
2475 :
2476 0 : if (!inet_aton(argv[idx_ipv4]->arg, &nbr_addr)) {
2477 0 : vty_out(vty, "Please specify Neighbor ID by A.B.C.D\n");
2478 0 : return CMD_WARNING_CONFIG_FAILED;
2479 : }
2480 :
2481 0 : (void)ospf_nbr_nbma_unset(ospf, nbr_addr);
2482 :
2483 0 : return CMD_SUCCESS;
2484 : }
2485 :
2486 0 : DEFUN (no_ospf_neighbor_poll,
2487 : no_ospf_neighbor_poll_cmd,
2488 : "no neighbor A.B.C.D poll-interval (1-65535) [priority (0-255)]",
2489 : NO_STR
2490 : NEIGHBOR_STR
2491 : "Neighbor IP address\n"
2492 : "Dead Neighbor Polling interval\n"
2493 : "Seconds\n"
2494 : "Neighbor Priority\n"
2495 : "Priority\n")
2496 : {
2497 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
2498 0 : int idx_ipv4 = 2;
2499 0 : struct in_addr nbr_addr;
2500 :
2501 0 : if (!inet_aton(argv[idx_ipv4]->arg, &nbr_addr)) {
2502 0 : vty_out(vty, "Please specify Neighbor ID by A.B.C.D\n");
2503 0 : return CMD_WARNING_CONFIG_FAILED;
2504 : }
2505 :
2506 0 : (void)ospf_nbr_nbma_unset(ospf, nbr_addr);
2507 :
2508 0 : return CMD_SUCCESS;
2509 : }
2510 :
2511 0 : DEFUN (ospf_refresh_timer,
2512 : ospf_refresh_timer_cmd,
2513 : "refresh timer (10-1800)",
2514 : "Adjust refresh parameters\n"
2515 : "Set refresh timer\n"
2516 : "Timer value in seconds\n")
2517 : {
2518 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
2519 0 : int idx_number = 2;
2520 0 : unsigned int interval;
2521 :
2522 0 : interval = strtoul(argv[idx_number]->arg, NULL, 10);
2523 0 : interval = (interval / OSPF_LSA_REFRESHER_GRANULARITY)
2524 : * OSPF_LSA_REFRESHER_GRANULARITY;
2525 :
2526 0 : ospf_timers_refresh_set(ospf, interval);
2527 :
2528 0 : return CMD_SUCCESS;
2529 : }
2530 :
2531 0 : DEFUN (no_ospf_refresh_timer,
2532 : no_ospf_refresh_timer_val_cmd,
2533 : "no refresh timer [(10-1800)]",
2534 : NO_STR
2535 : "Adjust refresh parameters\n"
2536 : "Unset refresh timer\n"
2537 : "Timer value in seconds\n")
2538 : {
2539 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
2540 0 : int idx_number = 3;
2541 0 : unsigned int interval;
2542 :
2543 0 : if (argc == 1) {
2544 0 : interval = strtoul(argv[idx_number]->arg, NULL, 10);
2545 :
2546 0 : if (ospf->lsa_refresh_interval != interval
2547 0 : || interval == OSPF_LSA_REFRESH_INTERVAL_DEFAULT)
2548 : return CMD_SUCCESS;
2549 : }
2550 :
2551 0 : ospf_timers_refresh_unset(ospf);
2552 :
2553 0 : return CMD_SUCCESS;
2554 : }
2555 :
2556 :
2557 0 : DEFUN (ospf_auto_cost_reference_bandwidth,
2558 : ospf_auto_cost_reference_bandwidth_cmd,
2559 : "auto-cost reference-bandwidth (1-4294967)",
2560 : "Calculate OSPF interface cost according to bandwidth\n"
2561 : "Use reference bandwidth method to assign OSPF cost\n"
2562 : "The reference bandwidth in terms of Mbits per second\n")
2563 : {
2564 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
2565 0 : struct vrf *vrf = vrf_lookup_by_id(ospf->vrf_id);
2566 0 : int idx_number = 2;
2567 0 : uint32_t refbw;
2568 0 : struct interface *ifp;
2569 :
2570 0 : refbw = strtol(argv[idx_number]->arg, NULL, 10);
2571 0 : if (refbw < 1 || refbw > 4294967) {
2572 0 : vty_out(vty, "reference-bandwidth value is invalid\n");
2573 0 : return CMD_WARNING_CONFIG_FAILED;
2574 : }
2575 :
2576 : /* If reference bandwidth is changed. */
2577 0 : if ((refbw) == ospf->ref_bandwidth)
2578 : return CMD_SUCCESS;
2579 :
2580 0 : ospf->ref_bandwidth = refbw;
2581 0 : FOR_ALL_INTERFACES (vrf, ifp)
2582 0 : ospf_if_recalculate_output_cost(ifp);
2583 :
2584 : return CMD_SUCCESS;
2585 : }
2586 :
2587 0 : DEFUN (no_ospf_auto_cost_reference_bandwidth,
2588 : no_ospf_auto_cost_reference_bandwidth_cmd,
2589 : "no auto-cost reference-bandwidth [(1-4294967)]",
2590 : NO_STR
2591 : "Calculate OSPF interface cost according to bandwidth\n"
2592 : "Use reference bandwidth method to assign OSPF cost\n"
2593 : "The reference bandwidth in terms of Mbits per second\n")
2594 : {
2595 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
2596 0 : struct vrf *vrf = vrf_lookup_by_id(ospf->vrf_id);
2597 0 : struct interface *ifp;
2598 :
2599 0 : if (ospf->ref_bandwidth == OSPF_DEFAULT_REF_BANDWIDTH)
2600 : return CMD_SUCCESS;
2601 :
2602 0 : ospf->ref_bandwidth = OSPF_DEFAULT_REF_BANDWIDTH;
2603 0 : vty_out(vty, "%% OSPF: Reference bandwidth is changed.\n");
2604 0 : vty_out(vty,
2605 : " Please ensure reference bandwidth is consistent across all routers\n");
2606 :
2607 0 : FOR_ALL_INTERFACES (vrf, ifp)
2608 0 : ospf_if_recalculate_output_cost(ifp);
2609 :
2610 : return CMD_SUCCESS;
2611 : }
2612 :
2613 0 : DEFUN (ospf_write_multiplier,
2614 : ospf_write_multiplier_cmd,
2615 : "ospf write-multiplier (1-100)",
2616 : "OSPF specific commands\n"
2617 : "Write multiplier\n"
2618 : "Maximum number of interface serviced per write\n")
2619 : {
2620 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
2621 0 : int idx_number;
2622 0 : uint32_t write_oi_count;
2623 :
2624 0 : if (argc == 3)
2625 : idx_number = 2;
2626 : else
2627 0 : idx_number = 1;
2628 :
2629 0 : write_oi_count = strtol(argv[idx_number]->arg, NULL, 10);
2630 0 : if (write_oi_count < 1 || write_oi_count > 100) {
2631 0 : vty_out(vty, "write-multiplier value is invalid\n");
2632 0 : return CMD_WARNING_CONFIG_FAILED;
2633 : }
2634 :
2635 0 : ospf->write_oi_count = write_oi_count;
2636 0 : return CMD_SUCCESS;
2637 : }
2638 :
2639 : ALIAS(ospf_write_multiplier, write_multiplier_cmd, "write-multiplier (1-100)",
2640 : "Write multiplier\n"
2641 : "Maximum number of interface serviced per write\n")
2642 :
2643 0 : DEFUN (no_ospf_write_multiplier,
2644 : no_ospf_write_multiplier_cmd,
2645 : "no ospf write-multiplier (1-100)",
2646 : NO_STR
2647 : "OSPF specific commands\n"
2648 : "Write multiplier\n"
2649 : "Maximum number of interface serviced per write\n")
2650 : {
2651 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
2652 :
2653 0 : ospf->write_oi_count = OSPF_WRITE_INTERFACE_COUNT_DEFAULT;
2654 0 : return CMD_SUCCESS;
2655 : }
2656 :
2657 : ALIAS(no_ospf_write_multiplier, no_write_multiplier_cmd,
2658 : "no write-multiplier (1-100)", NO_STR
2659 : "Write multiplier\n"
2660 : "Maximum number of interface serviced per write\n")
2661 :
2662 0 : DEFUN(ospf_ti_lfa, ospf_ti_lfa_cmd, "fast-reroute ti-lfa [node-protection]",
2663 : "Fast Reroute for MPLS and IP resilience\n"
2664 : "Topology Independent LFA (Loop-Free Alternate)\n"
2665 : "TI-LFA node protection (default is link protection)\n")
2666 : {
2667 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
2668 :
2669 0 : ospf->ti_lfa_enabled = true;
2670 :
2671 0 : if (argc == 3)
2672 0 : ospf->ti_lfa_protection_type = OSPF_TI_LFA_NODE_PROTECTION;
2673 : else
2674 0 : ospf->ti_lfa_protection_type = OSPF_TI_LFA_LINK_PROTECTION;
2675 :
2676 0 : ospf_spf_calculate_schedule(ospf, SPF_FLAG_CONFIG_CHANGE);
2677 :
2678 0 : return CMD_SUCCESS;
2679 : }
2680 :
2681 0 : DEFUN(no_ospf_ti_lfa, no_ospf_ti_lfa_cmd,
2682 : "no fast-reroute ti-lfa [node-protection]",
2683 : NO_STR
2684 : "Fast Reroute for MPLS and IP resilience\n"
2685 : "Topology Independent LFA (Loop-Free Alternate)\n"
2686 : "TI-LFA node protection (default is link protection)\n")
2687 : {
2688 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
2689 :
2690 0 : ospf->ti_lfa_enabled = false;
2691 :
2692 0 : ospf->ti_lfa_protection_type = OSPF_TI_LFA_UNDEFINED_PROTECTION;
2693 :
2694 0 : ospf_spf_calculate_schedule(ospf, SPF_FLAG_CONFIG_CHANGE);
2695 :
2696 0 : return CMD_SUCCESS;
2697 : }
2698 :
2699 0 : static void ospf_maxpath_set(struct vty *vty, struct ospf *ospf, uint16_t paths)
2700 : {
2701 0 : if (ospf->max_multipath == paths)
2702 : return;
2703 :
2704 0 : ospf->max_multipath = paths;
2705 :
2706 : /* Send deletion notification to zebra to delete all
2707 : * ospf specific routes and reinitiat SPF to reflect
2708 : * the new max multipath.
2709 : */
2710 0 : ospf_restart_spf(ospf);
2711 : }
2712 :
2713 : /* Ospf Maximum multiple paths config support */
2714 0 : DEFUN (ospf_max_multipath,
2715 : ospf_max_multipath_cmd,
2716 : "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM),
2717 : "Max no of multiple paths for ECMP support\n"
2718 : "Number of paths\n")
2719 : {
2720 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
2721 0 : int idx_number = 1;
2722 0 : uint16_t maxpaths;
2723 :
2724 0 : maxpaths = strtol(argv[idx_number]->arg, NULL, 10);
2725 :
2726 0 : ospf_maxpath_set(vty, ospf, maxpaths);
2727 : return CMD_SUCCESS;
2728 : }
2729 :
2730 0 : DEFUN (no_ospf_max_multipath,
2731 : no_ospf_max_multipath_cmd,
2732 : "no maximum-paths",
2733 : NO_STR
2734 : "Max no of multiple paths for ECMP support\n")
2735 : {
2736 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
2737 0 : uint16_t maxpaths = MULTIPATH_NUM;
2738 :
2739 0 : ospf_maxpath_set(vty, ospf, maxpaths);
2740 : return CMD_SUCCESS;
2741 : }
2742 :
2743 : static const char *const ospf_abr_type_descr_str[] = {
2744 : "Unknown", "Standard (RFC2328)", "Alternative IBM",
2745 : "Alternative Cisco", "Alternative Shortcut"
2746 : };
2747 :
2748 : static const char *const ospf_shortcut_mode_descr_str[] = {
2749 : "Default", "Enabled", "Disabled"
2750 : };
2751 :
2752 0 : static void show_ip_ospf_area(struct vty *vty, struct ospf_area *area,
2753 : json_object *json_areas, bool use_json)
2754 : {
2755 0 : json_object *json_area = NULL;
2756 0 : char buf[PREFIX_STRLEN];
2757 :
2758 0 : if (use_json)
2759 0 : json_area = json_object_new_object();
2760 :
2761 : /* Show Area ID. */
2762 0 : if (!use_json)
2763 0 : vty_out(vty, " Area ID: %pI4", &area->area_id);
2764 :
2765 : /* Show Area type/mode. */
2766 0 : if (OSPF_IS_AREA_BACKBONE(area)) {
2767 0 : if (use_json)
2768 0 : json_object_boolean_true_add(json_area, "backbone");
2769 : else
2770 0 : vty_out(vty, " (Backbone)\n");
2771 : } else {
2772 0 : if (use_json) {
2773 0 : if (area->external_routing == OSPF_AREA_STUB) {
2774 0 : if (area->no_summary)
2775 0 : json_object_boolean_true_add(
2776 : json_area, "stubNoSummary");
2777 0 : if (area->shortcut_configured)
2778 0 : json_object_boolean_true_add(
2779 : json_area, "stubShortcut");
2780 0 : } else if (area->external_routing == OSPF_AREA_NSSA) {
2781 0 : if (area->no_summary)
2782 0 : json_object_boolean_true_add(
2783 : json_area, "nssaNoSummary");
2784 0 : if (area->shortcut_configured)
2785 0 : json_object_boolean_true_add(
2786 : json_area, "nssaShortcut");
2787 : }
2788 :
2789 0 : json_object_string_add(
2790 : json_area, "shortcuttingMode",
2791 : ospf_shortcut_mode_descr_str
2792 0 : [area->shortcut_configured]);
2793 0 : if (area->shortcut_capability)
2794 0 : json_object_boolean_true_add(json_area,
2795 : "sBitConcensus");
2796 : } else {
2797 0 : if (area->external_routing == OSPF_AREA_STUB)
2798 0 : vty_out(vty, " (Stub%s%s)",
2799 0 : area->no_summary ? ", no summary" : "",
2800 0 : area->shortcut_configured ? "; " : "");
2801 0 : else if (area->external_routing == OSPF_AREA_NSSA)
2802 0 : vty_out(vty, " (NSSA%s%s)",
2803 0 : area->no_summary ? ", no summary" : "",
2804 0 : area->shortcut_configured ? "; " : "");
2805 :
2806 0 : vty_out(vty, "\n");
2807 0 : vty_out(vty, " Shortcutting mode: %s",
2808 : ospf_shortcut_mode_descr_str
2809 0 : [area->shortcut_configured]);
2810 0 : vty_out(vty, ", S-bit consensus: %s\n",
2811 0 : area->shortcut_capability ? "ok" : "no");
2812 : }
2813 : }
2814 :
2815 : /* Show number of interfaces */
2816 0 : if (use_json) {
2817 0 : json_object_int_add(json_area, "areaIfTotalCounter",
2818 0 : listcount(area->oiflist));
2819 0 : json_object_int_add(json_area, "areaIfActiveCounter",
2820 0 : area->act_ints);
2821 : } else
2822 0 : vty_out(vty,
2823 : " Number of interfaces in this area: Total: %d, Active: %d\n",
2824 0 : listcount(area->oiflist), area->act_ints);
2825 :
2826 0 : if (area->external_routing == OSPF_AREA_NSSA) {
2827 0 : if (use_json) {
2828 0 : json_object_boolean_true_add(json_area, "nssa");
2829 0 : if (!IS_OSPF_ABR(area->ospf))
2830 0 : json_object_boolean_false_add(json_area, "abr");
2831 0 : else if (area->NSSATranslatorState) {
2832 0 : json_object_boolean_true_add(json_area, "abr");
2833 0 : if (area->NSSATranslatorRole
2834 : == OSPF_NSSA_ROLE_CANDIDATE)
2835 0 : json_object_boolean_true_add(
2836 : json_area,
2837 : "nssaTranslatorElected");
2838 0 : else if (area->NSSATranslatorRole
2839 : == OSPF_NSSA_ROLE_ALWAYS)
2840 0 : json_object_boolean_true_add(
2841 : json_area,
2842 : "nssaTranslatorAlways");
2843 : else
2844 0 : json_object_boolean_true_add(
2845 : json_area,
2846 : "nssaTranslatorNever");
2847 : } else {
2848 0 : json_object_boolean_true_add(json_area, "abr");
2849 0 : if (area->NSSATranslatorRole
2850 : == OSPF_NSSA_ROLE_CANDIDATE)
2851 0 : json_object_boolean_false_add(
2852 : json_area,
2853 : "nssaTranslatorElected");
2854 : else
2855 0 : json_object_boolean_true_add(
2856 : json_area,
2857 : "nssaTranslatorNever");
2858 : }
2859 : } else {
2860 0 : vty_out(vty,
2861 : " It is an NSSA configuration.\n Elected NSSA/ABR performs type-7/type-5 LSA translation.\n");
2862 0 : if (!IS_OSPF_ABR(area->ospf))
2863 0 : vty_out(vty,
2864 : " It is not ABR, therefore not Translator.\n");
2865 0 : else if (area->NSSATranslatorState) {
2866 0 : vty_out(vty, " We are an ABR and ");
2867 0 : if (area->NSSATranslatorRole
2868 : == OSPF_NSSA_ROLE_CANDIDATE)
2869 0 : vty_out(vty,
2870 : "the NSSA Elected Translator.\n");
2871 0 : else if (area->NSSATranslatorRole
2872 : == OSPF_NSSA_ROLE_ALWAYS)
2873 0 : vty_out(vty,
2874 : "always an NSSA Translator.\n");
2875 : else
2876 0 : vty_out(vty,
2877 : "never an NSSA Translator.\n");
2878 : } else {
2879 0 : vty_out(vty, " We are an ABR, but ");
2880 0 : if (area->NSSATranslatorRole
2881 : == OSPF_NSSA_ROLE_CANDIDATE)
2882 0 : vty_out(vty,
2883 : "not the NSSA Elected Translator.\n");
2884 : else
2885 0 : vty_out(vty,
2886 : "never an NSSA Translator.\n");
2887 : }
2888 : }
2889 : }
2890 :
2891 : /* Stub-router state for this area */
2892 0 : if (CHECK_FLAG(area->stub_router_state, OSPF_AREA_IS_STUB_ROUTED)) {
2893 0 : char timebuf[OSPF_TIME_DUMP_SIZE];
2894 :
2895 0 : if (use_json) {
2896 0 : json_object_boolean_true_add(
2897 : json_area, "originStubMaxDistRouterLsa");
2898 0 : if (CHECK_FLAG(area->stub_router_state,
2899 : OSPF_AREA_ADMIN_STUB_ROUTED))
2900 0 : json_object_boolean_true_add(
2901 : json_area, "indefiniteActiveAdmin");
2902 0 : if (area->t_stub_router) {
2903 0 : long time_store;
2904 0 : time_store =
2905 0 : monotime_until(
2906 0 : &area->t_stub_router->u.sands,
2907 : NULL)
2908 : / 1000LL;
2909 0 : json_object_int_add(
2910 : json_area,
2911 : "activeStartupRemainderMsecs",
2912 : time_store);
2913 : }
2914 : } else {
2915 0 : vty_out(vty,
2916 : " Originating stub / maximum-distance Router-LSA\n");
2917 0 : if (CHECK_FLAG(area->stub_router_state,
2918 : OSPF_AREA_ADMIN_STUB_ROUTED))
2919 0 : vty_out(vty,
2920 : " Administratively activated (indefinitely)\n");
2921 0 : if (area->t_stub_router)
2922 0 : vty_out(vty,
2923 : " Active from startup, %s remaining\n",
2924 : ospf_timer_dump(area->t_stub_router,
2925 : timebuf,
2926 : sizeof(timebuf)));
2927 : }
2928 : }
2929 :
2930 0 : if (use_json) {
2931 : /* Show number of fully adjacent neighbors. */
2932 0 : json_object_int_add(json_area, "nbrFullAdjacentCounter",
2933 0 : area->full_nbrs);
2934 :
2935 : /* Show authentication type. */
2936 0 : if (area->auth_type == OSPF_AUTH_NULL)
2937 0 : json_object_string_add(json_area, "authentication",
2938 : "authenticationNone");
2939 0 : else if (area->auth_type == OSPF_AUTH_SIMPLE)
2940 0 : json_object_string_add(json_area, "authentication",
2941 : "authenticationSimplePassword");
2942 0 : else if (area->auth_type == OSPF_AUTH_CRYPTOGRAPHIC)
2943 0 : json_object_string_add(json_area, "authentication",
2944 : "authenticationMessageDigest");
2945 :
2946 0 : if (!OSPF_IS_AREA_BACKBONE(area))
2947 0 : json_object_int_add(json_area,
2948 : "virtualAdjacenciesPassingCounter",
2949 0 : area->full_vls);
2950 :
2951 : /* Show SPF calculation times. */
2952 0 : json_object_int_add(json_area, "spfExecutedCounter",
2953 0 : area->spf_calculation);
2954 0 : json_object_int_add(json_area, "lsaNumber", area->lsdb->total);
2955 0 : json_object_int_add(
2956 : json_area, "lsaRouterNumber",
2957 0 : ospf_lsdb_count(area->lsdb, OSPF_ROUTER_LSA));
2958 0 : json_object_int_add(
2959 : json_area, "lsaRouterChecksum",
2960 0 : ospf_lsdb_checksum(area->lsdb, OSPF_ROUTER_LSA));
2961 0 : json_object_int_add(
2962 : json_area, "lsaNetworkNumber",
2963 0 : ospf_lsdb_count(area->lsdb, OSPF_NETWORK_LSA));
2964 0 : json_object_int_add(
2965 : json_area, "lsaNetworkChecksum",
2966 0 : ospf_lsdb_checksum(area->lsdb, OSPF_NETWORK_LSA));
2967 0 : json_object_int_add(
2968 : json_area, "lsaSummaryNumber",
2969 0 : ospf_lsdb_count(area->lsdb, OSPF_SUMMARY_LSA));
2970 0 : json_object_int_add(
2971 : json_area, "lsaSummaryChecksum",
2972 0 : ospf_lsdb_checksum(area->lsdb, OSPF_SUMMARY_LSA));
2973 0 : json_object_int_add(
2974 : json_area, "lsaAsbrNumber",
2975 0 : ospf_lsdb_count(area->lsdb, OSPF_ASBR_SUMMARY_LSA));
2976 0 : json_object_int_add(
2977 : json_area, "lsaAsbrChecksum",
2978 0 : ospf_lsdb_checksum(area->lsdb, OSPF_ASBR_SUMMARY_LSA));
2979 0 : json_object_int_add(
2980 : json_area, "lsaNssaNumber",
2981 0 : ospf_lsdb_count(area->lsdb, OSPF_AS_NSSA_LSA));
2982 0 : json_object_int_add(
2983 : json_area, "lsaNssaChecksum",
2984 0 : ospf_lsdb_checksum(area->lsdb, OSPF_AS_NSSA_LSA));
2985 : } else {
2986 : /* Show number of fully adjacent neighbors. */
2987 0 : vty_out(vty,
2988 : " Number of fully adjacent neighbors in this area: %d\n",
2989 : area->full_nbrs);
2990 :
2991 : /* Show authentication type. */
2992 0 : vty_out(vty, " Area has ");
2993 0 : if (area->auth_type == OSPF_AUTH_NULL)
2994 0 : vty_out(vty, "no authentication\n");
2995 0 : else if (area->auth_type == OSPF_AUTH_SIMPLE)
2996 0 : vty_out(vty, "simple password authentication\n");
2997 0 : else if (area->auth_type == OSPF_AUTH_CRYPTOGRAPHIC)
2998 0 : vty_out(vty, "message digest authentication\n");
2999 :
3000 0 : if (!OSPF_IS_AREA_BACKBONE(area))
3001 0 : vty_out(vty,
3002 : " Number of full virtual adjacencies going through this area: %d\n",
3003 : area->full_vls);
3004 :
3005 : /* Show SPF calculation times. */
3006 0 : vty_out(vty, " SPF algorithm executed %d times\n",
3007 : area->spf_calculation);
3008 :
3009 : /* Show number of LSA. */
3010 0 : vty_out(vty, " Number of LSA %ld\n", area->lsdb->total);
3011 0 : vty_out(vty,
3012 : " Number of router LSA %ld. Checksum Sum 0x%08x\n",
3013 : ospf_lsdb_count(area->lsdb, OSPF_ROUTER_LSA),
3014 : ospf_lsdb_checksum(area->lsdb, OSPF_ROUTER_LSA));
3015 0 : vty_out(vty,
3016 : " Number of network LSA %ld. Checksum Sum 0x%08x\n",
3017 : ospf_lsdb_count(area->lsdb, OSPF_NETWORK_LSA),
3018 : ospf_lsdb_checksum(area->lsdb, OSPF_NETWORK_LSA));
3019 0 : vty_out(vty,
3020 : " Number of summary LSA %ld. Checksum Sum 0x%08x\n",
3021 : ospf_lsdb_count(area->lsdb, OSPF_SUMMARY_LSA),
3022 : ospf_lsdb_checksum(area->lsdb, OSPF_SUMMARY_LSA));
3023 0 : vty_out(vty,
3024 : " Number of ASBR summary LSA %ld. Checksum Sum 0x%08x\n",
3025 : ospf_lsdb_count(area->lsdb, OSPF_ASBR_SUMMARY_LSA),
3026 : ospf_lsdb_checksum(area->lsdb, OSPF_ASBR_SUMMARY_LSA));
3027 0 : vty_out(vty, " Number of NSSA LSA %ld. Checksum Sum 0x%08x\n",
3028 : ospf_lsdb_count(area->lsdb, OSPF_AS_NSSA_LSA),
3029 : ospf_lsdb_checksum(area->lsdb, OSPF_AS_NSSA_LSA));
3030 : }
3031 :
3032 0 : if (use_json) {
3033 0 : json_object_int_add(
3034 : json_area, "lsaOpaqueLinkNumber",
3035 0 : ospf_lsdb_count(area->lsdb, OSPF_OPAQUE_LINK_LSA));
3036 0 : json_object_int_add(
3037 : json_area, "lsaOpaqueLinkChecksum",
3038 0 : ospf_lsdb_checksum(area->lsdb, OSPF_OPAQUE_LINK_LSA));
3039 0 : json_object_int_add(
3040 : json_area, "lsaOpaqueAreaNumber",
3041 0 : ospf_lsdb_count(area->lsdb, OSPF_OPAQUE_AREA_LSA));
3042 0 : json_object_int_add(
3043 : json_area, "lsaOpaqueAreaChecksum",
3044 0 : ospf_lsdb_checksum(area->lsdb, OSPF_OPAQUE_AREA_LSA));
3045 : } else {
3046 0 : vty_out(vty,
3047 : " Number of opaque link LSA %ld. Checksum Sum 0x%08x\n",
3048 : ospf_lsdb_count(area->lsdb, OSPF_OPAQUE_LINK_LSA),
3049 : ospf_lsdb_checksum(area->lsdb, OSPF_OPAQUE_LINK_LSA));
3050 0 : vty_out(vty,
3051 : " Number of opaque area LSA %ld. Checksum Sum 0x%08x\n",
3052 : ospf_lsdb_count(area->lsdb, OSPF_OPAQUE_AREA_LSA),
3053 : ospf_lsdb_checksum(area->lsdb, OSPF_OPAQUE_AREA_LSA));
3054 : }
3055 :
3056 0 : if (use_json)
3057 0 : json_object_object_add(json_areas,
3058 0 : inet_ntop(AF_INET, &area->area_id,
3059 : buf, sizeof(buf)),
3060 : json_area);
3061 : else
3062 0 : vty_out(vty, "\n");
3063 0 : }
3064 :
3065 0 : static int show_ip_ospf_common(struct vty *vty, struct ospf *ospf,
3066 : json_object *json, uint8_t use_vrf)
3067 : {
3068 0 : struct listnode *node, *nnode;
3069 0 : struct ospf_area *area;
3070 0 : struct timeval result;
3071 0 : char timebuf[OSPF_TIME_DUMP_SIZE];
3072 0 : json_object *json_vrf = NULL;
3073 0 : json_object *json_areas = NULL;
3074 :
3075 0 : if (json) {
3076 0 : if (use_vrf)
3077 0 : json_vrf = json_object_new_object();
3078 : else
3079 : json_vrf = json;
3080 0 : json_areas = json_object_new_object();
3081 : }
3082 :
3083 0 : if (ospf->instance) {
3084 0 : if (json) {
3085 0 : json_object_int_add(json, "ospfInstance",
3086 : ospf->instance);
3087 : } else {
3088 0 : vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
3089 : }
3090 : }
3091 :
3092 0 : ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf);
3093 :
3094 : /* Show Router ID. */
3095 0 : if (json) {
3096 0 : json_object_string_addf(json_vrf, "routerId", "%pI4",
3097 : &ospf->router_id);
3098 : } else {
3099 0 : vty_out(vty, " OSPF Routing Process, Router ID: %pI4\n",
3100 : &ospf->router_id);
3101 : }
3102 :
3103 : /* Graceful shutdown */
3104 0 : if (ospf->t_deferred_shutdown) {
3105 0 : if (json) {
3106 0 : long time_store;
3107 0 : time_store =
3108 0 : monotime_until(
3109 0 : &ospf->t_deferred_shutdown->u.sands,
3110 : NULL)
3111 : / 1000LL;
3112 0 : json_object_int_add(json_vrf, "deferredShutdownMsecs",
3113 : time_store);
3114 : } else {
3115 0 : vty_out(vty,
3116 : " Deferred shutdown in progress, %s remaining\n",
3117 : ospf_timer_dump(ospf->t_deferred_shutdown,
3118 : timebuf, sizeof(timebuf)));
3119 : }
3120 : }
3121 :
3122 : /* Show capability. */
3123 0 : if (json) {
3124 0 : json_object_boolean_true_add(json_vrf, "tosRoutesOnly");
3125 0 : json_object_boolean_true_add(json_vrf, "rfc2328Conform");
3126 0 : if (CHECK_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE)) {
3127 0 : json_object_boolean_true_add(json_vrf,
3128 : "rfc1583Compatibility");
3129 : }
3130 : } else {
3131 0 : vty_out(vty, " Supports only single TOS (TOS0) routes\n");
3132 0 : vty_out(vty, " This implementation conforms to RFC2328\n");
3133 0 : vty_out(vty, " RFC1583Compatibility flag is %s\n",
3134 0 : CHECK_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE)
3135 : ? "enabled"
3136 : : "disabled");
3137 : }
3138 :
3139 0 : if (json) {
3140 0 : if (CHECK_FLAG(ospf->config, OSPF_OPAQUE_CAPABLE)) {
3141 0 : json_object_boolean_true_add(json_vrf, "opaqueCapable");
3142 : }
3143 : } else {
3144 0 : vty_out(vty, " OpaqueCapability flag is %s\n",
3145 0 : CHECK_FLAG(ospf->config, OSPF_OPAQUE_CAPABLE)
3146 : ? "enabled"
3147 : : "disabled");
3148 : }
3149 :
3150 : /* Show stub-router configuration */
3151 0 : if (ospf->stub_router_startup_time != OSPF_STUB_ROUTER_UNCONFIGURED
3152 0 : || ospf->stub_router_shutdown_time
3153 : != OSPF_STUB_ROUTER_UNCONFIGURED) {
3154 0 : if (json) {
3155 0 : json_object_boolean_true_add(json_vrf,
3156 : "stubAdvertisement");
3157 0 : if (ospf->stub_router_startup_time
3158 : != OSPF_STUB_ROUTER_UNCONFIGURED)
3159 0 : json_object_int_add(
3160 : json_vrf, "postStartEnabledSecs",
3161 : ospf->stub_router_startup_time);
3162 0 : if (ospf->stub_router_shutdown_time
3163 : != OSPF_STUB_ROUTER_UNCONFIGURED)
3164 0 : json_object_int_add(
3165 : json_vrf, "preShutdownEnabledSecs",
3166 : ospf->stub_router_shutdown_time);
3167 : } else {
3168 0 : vty_out(vty,
3169 : " Stub router advertisement is configured\n");
3170 0 : if (ospf->stub_router_startup_time
3171 : != OSPF_STUB_ROUTER_UNCONFIGURED)
3172 0 : vty_out(vty,
3173 : " Enabled for %us after start-up\n",
3174 : ospf->stub_router_startup_time);
3175 0 : if (ospf->stub_router_shutdown_time
3176 : != OSPF_STUB_ROUTER_UNCONFIGURED)
3177 0 : vty_out(vty,
3178 : " Enabled for %us prior to full shutdown\n",
3179 : ospf->stub_router_shutdown_time);
3180 : }
3181 : }
3182 :
3183 : /* Show SPF timers. */
3184 0 : if (json) {
3185 0 : json_object_int_add(json_vrf, "spfScheduleDelayMsecs",
3186 0 : ospf->spf_delay);
3187 0 : json_object_int_add(json_vrf, "holdtimeMinMsecs",
3188 0 : ospf->spf_holdtime);
3189 0 : json_object_int_add(json_vrf, "holdtimeMaxMsecs",
3190 0 : ospf->spf_max_holdtime);
3191 0 : json_object_int_add(json_vrf, "holdtimeMultplier",
3192 0 : ospf->spf_hold_multiplier);
3193 : } else {
3194 0 : vty_out(vty,
3195 : " Initial SPF scheduling delay %d millisec(s)\n"
3196 : " Minimum hold time between consecutive SPFs %d millisec(s)\n"
3197 : " Maximum hold time between consecutive SPFs %d millisec(s)\n"
3198 : " Hold time multiplier is currently %d\n",
3199 : ospf->spf_delay, ospf->spf_holdtime,
3200 : ospf->spf_max_holdtime, ospf->spf_hold_multiplier);
3201 : }
3202 :
3203 0 : if (json) {
3204 0 : if (ospf->ts_spf.tv_sec || ospf->ts_spf.tv_usec) {
3205 0 : long time_store = 0;
3206 :
3207 0 : time_store =
3208 0 : monotime_since(&ospf->ts_spf, NULL) / 1000LL;
3209 0 : json_object_int_add(json_vrf, "spfLastExecutedMsecs",
3210 : time_store);
3211 :
3212 0 : time_store = (1000 * ospf->ts_spf_duration.tv_sec)
3213 0 : + (ospf->ts_spf_duration.tv_usec / 1000);
3214 0 : json_object_int_add(json_vrf, "spfLastDurationMsecs",
3215 : time_store);
3216 : } else
3217 0 : json_object_boolean_true_add(json_vrf, "spfHasNotRun");
3218 : } else {
3219 0 : vty_out(vty, " SPF algorithm ");
3220 0 : if (ospf->ts_spf.tv_sec || ospf->ts_spf.tv_usec) {
3221 0 : monotime_since(&ospf->ts_spf, &result);
3222 0 : vty_out(vty, "last executed %s ago\n",
3223 : ospf_timeval_dump(&result, timebuf,
3224 : sizeof(timebuf)));
3225 0 : vty_out(vty, " Last SPF duration %s\n",
3226 : ospf_timeval_dump(&ospf->ts_spf_duration,
3227 : timebuf, sizeof(timebuf)));
3228 : } else
3229 0 : vty_out(vty, "has not been run\n");
3230 : }
3231 :
3232 0 : if (json) {
3233 0 : if (ospf->t_spf_calc) {
3234 0 : long time_store;
3235 0 : time_store =
3236 0 : monotime_until(&ospf->t_spf_calc->u.sands, NULL)
3237 : / 1000LL;
3238 0 : json_object_int_add(json_vrf, "spfTimerDueInMsecs",
3239 : time_store);
3240 : }
3241 :
3242 0 : json_object_int_add(json_vrf, "lsaMinIntervalMsecs",
3243 0 : ospf->min_ls_interval);
3244 0 : json_object_int_add(json_vrf, "lsaMinArrivalMsecs",
3245 0 : ospf->min_ls_arrival);
3246 : /* Show write multiplier values */
3247 0 : json_object_int_add(json_vrf, "writeMultiplier",
3248 0 : ospf->write_oi_count);
3249 : /* Show refresh parameters. */
3250 0 : json_object_int_add(json_vrf, "refreshTimerMsecs",
3251 0 : ospf->lsa_refresh_interval * 1000);
3252 :
3253 : /* show max multipath */
3254 0 : json_object_int_add(json_vrf, "maximumPaths",
3255 0 : ospf->max_multipath);
3256 :
3257 : /* show administrative distance */
3258 0 : json_object_int_add(json_vrf, "preference",
3259 0 : ospf->distance_all
3260 : ? ospf->distance_all
3261 : : ZEBRA_OSPF_DISTANCE_DEFAULT);
3262 : } else {
3263 0 : vty_out(vty, " SPF timer %s%s\n",
3264 0 : (ospf->t_spf_calc ? "due in " : "is "),
3265 : ospf_timer_dump(ospf->t_spf_calc, timebuf,
3266 : sizeof(timebuf)));
3267 :
3268 0 : vty_out(vty, " LSA minimum interval %d msecs\n",
3269 : ospf->min_ls_interval);
3270 0 : vty_out(vty, " LSA minimum arrival %d msecs\n",
3271 : ospf->min_ls_arrival);
3272 :
3273 : /* Show write multiplier values */
3274 0 : vty_out(vty, " Write Multiplier set to %d \n",
3275 : ospf->write_oi_count);
3276 :
3277 : /* Show refresh parameters. */
3278 0 : vty_out(vty, " Refresh timer %d secs\n",
3279 0 : ospf->lsa_refresh_interval);
3280 :
3281 : /* show max multipath */
3282 0 : vty_out(vty, " Maximum multiple paths(ECMP) supported %d\n",
3283 0 : ospf->max_multipath);
3284 :
3285 : /* show administrative distance */
3286 0 : vty_out(vty, " Administrative distance %u\n",
3287 0 : ospf->distance_all ? ospf->distance_all
3288 : : ZEBRA_OSPF_DISTANCE_DEFAULT);
3289 : }
3290 :
3291 : /* Show ABR/ASBR flags. */
3292 0 : if (CHECK_FLAG(ospf->flags, OSPF_FLAG_ABR)) {
3293 0 : if (json)
3294 0 : json_object_string_add(
3295 : json_vrf, "abrType",
3296 0 : ospf_abr_type_descr_str[ospf->abr_type]);
3297 : else
3298 0 : vty_out(vty,
3299 : " This router is an ABR, ABR type is: %s\n",
3300 0 : ospf_abr_type_descr_str[ospf->abr_type]);
3301 : }
3302 0 : if (CHECK_FLAG(ospf->flags, OSPF_FLAG_ASBR)) {
3303 0 : if (json)
3304 0 : json_object_string_add(
3305 : json_vrf, "asbrRouter",
3306 : "injectingExternalRoutingInformation");
3307 : else
3308 0 : vty_out(vty,
3309 : " This router is an ASBR (injecting external routing information)\n");
3310 : }
3311 :
3312 : /* Show Number of AS-external-LSAs. */
3313 0 : if (json) {
3314 0 : json_object_int_add(
3315 : json_vrf, "lsaExternalCounter",
3316 0 : ospf_lsdb_count(ospf->lsdb, OSPF_AS_EXTERNAL_LSA));
3317 0 : json_object_int_add(
3318 : json_vrf, "lsaExternalChecksum",
3319 0 : ospf_lsdb_checksum(ospf->lsdb, OSPF_AS_EXTERNAL_LSA));
3320 : } else {
3321 0 : vty_out(vty,
3322 : " Number of external LSA %ld. Checksum Sum 0x%08x\n",
3323 : ospf_lsdb_count(ospf->lsdb, OSPF_AS_EXTERNAL_LSA),
3324 : ospf_lsdb_checksum(ospf->lsdb, OSPF_AS_EXTERNAL_LSA));
3325 : }
3326 :
3327 0 : if (json) {
3328 0 : json_object_int_add(
3329 : json_vrf, "lsaAsopaqueCounter",
3330 0 : ospf_lsdb_count(ospf->lsdb, OSPF_OPAQUE_AS_LSA));
3331 0 : json_object_int_add(
3332 : json_vrf, "lsaAsOpaqueChecksum",
3333 0 : ospf_lsdb_checksum(ospf->lsdb, OSPF_OPAQUE_AS_LSA));
3334 : } else {
3335 0 : vty_out(vty,
3336 : " Number of opaque AS LSA %ld. Checksum Sum 0x%08x\n",
3337 : ospf_lsdb_count(ospf->lsdb, OSPF_OPAQUE_AS_LSA),
3338 : ospf_lsdb_checksum(ospf->lsdb, OSPF_OPAQUE_AS_LSA));
3339 : }
3340 :
3341 : /* Show number of areas attached. */
3342 0 : if (json)
3343 0 : json_object_int_add(json_vrf, "attachedAreaCounter",
3344 0 : listcount(ospf->areas));
3345 : else
3346 0 : vty_out(vty, " Number of areas attached to this router: %d\n",
3347 0 : listcount(ospf->areas));
3348 :
3349 0 : if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES)) {
3350 0 : if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL)) {
3351 0 : if (json)
3352 0 : json_object_boolean_true_add(
3353 : json_vrf, "adjacencyChangesLoggedAll");
3354 : else
3355 0 : vty_out(vty,
3356 : " All adjacency changes are logged\n");
3357 : } else {
3358 0 : if (json)
3359 0 : json_object_boolean_true_add(
3360 : json_vrf, "adjacencyChangesLogged");
3361 : else
3362 0 : vty_out(vty, " Adjacency changes are logged\n");
3363 : }
3364 : }
3365 :
3366 : /* show LDP-Sync status */
3367 0 : ospf_ldp_sync_show_info(vty, ospf, json_vrf, json ? 1 : 0);
3368 :
3369 : /* Show each area status. */
3370 0 : for (ALL_LIST_ELEMENTS(ospf->areas, node, nnode, area))
3371 0 : show_ip_ospf_area(vty, area, json_areas, json ? 1 : 0);
3372 :
3373 0 : if (json) {
3374 0 : if (use_vrf) {
3375 0 : json_object_object_add(json_vrf, "areas", json_areas);
3376 0 : json_object_object_add(json, ospf_get_name(ospf),
3377 : json_vrf);
3378 : } else {
3379 0 : json_object_object_add(json, "areas", json_areas);
3380 : }
3381 : } else
3382 0 : vty_out(vty, "\n");
3383 :
3384 0 : return CMD_SUCCESS;
3385 : }
3386 :
3387 0 : DEFUN (show_ip_ospf,
3388 : show_ip_ospf_cmd,
3389 : "show ip ospf [vrf <NAME|all>] [json]",
3390 : SHOW_STR
3391 : IP_STR
3392 : "OSPF information\n"
3393 : VRF_CMD_HELP_STR
3394 : "All VRFs\n"
3395 : JSON_STR)
3396 : {
3397 0 : struct ospf *ospf;
3398 0 : bool uj = use_json(argc, argv);
3399 0 : struct listnode *node = NULL;
3400 0 : char *vrf_name = NULL;
3401 0 : bool all_vrf = false;
3402 0 : int ret = CMD_SUCCESS;
3403 0 : int inst = 0;
3404 0 : int idx_vrf = 0;
3405 0 : json_object *json = NULL;
3406 0 : uint8_t use_vrf = 0;
3407 :
3408 0 : if (listcount(om->ospf) == 0)
3409 : return CMD_SUCCESS;
3410 :
3411 0 : OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
3412 :
3413 0 : if (uj)
3414 0 : json = json_object_new_object();
3415 :
3416 : /* vrf input is provided could be all or specific vrf*/
3417 0 : if (vrf_name) {
3418 0 : bool ospf_output = false;
3419 :
3420 0 : use_vrf = 1;
3421 :
3422 0 : if (all_vrf) {
3423 0 : for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
3424 0 : if (!ospf->oi_running)
3425 0 : continue;
3426 0 : ospf_output = true;
3427 0 : ret = show_ip_ospf_common(vty, ospf, json,
3428 : use_vrf);
3429 : }
3430 0 : if (uj)
3431 0 : vty_json(vty, json);
3432 0 : else if (!ospf_output)
3433 0 : vty_out(vty, "%% OSPF is not enabled\n");
3434 0 : return ret;
3435 : }
3436 0 : ospf = ospf_lookup_by_inst_name(inst, vrf_name);
3437 0 : if ((ospf == NULL) || !ospf->oi_running) {
3438 0 : if (uj)
3439 0 : vty_json(vty, json);
3440 : else
3441 0 : vty_out(vty,
3442 : "%% OSPF is not enabled in vrf %s\n",
3443 : vrf_name);
3444 :
3445 0 : return CMD_SUCCESS;
3446 : }
3447 : } else {
3448 0 : ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
3449 : /* Display default ospf (instance 0) info */
3450 0 : if (ospf == NULL || !ospf->oi_running) {
3451 0 : if (uj)
3452 0 : vty_json(vty, json);
3453 : else
3454 0 : vty_out(vty,
3455 : "%% OSPF is not enabled in vrf default\n");
3456 :
3457 0 : return CMD_SUCCESS;
3458 : }
3459 : }
3460 :
3461 : if (ospf) {
3462 0 : show_ip_ospf_common(vty, ospf, json, use_vrf);
3463 0 : if (uj)
3464 0 : vty_out(vty, "%s\n",
3465 : json_object_to_json_string_ext(
3466 : json, JSON_C_TO_STRING_PRETTY));
3467 : }
3468 :
3469 0 : if (uj)
3470 0 : json_object_free(json);
3471 :
3472 : return ret;
3473 : }
3474 :
3475 0 : DEFUN (show_ip_ospf_instance,
3476 : show_ip_ospf_instance_cmd,
3477 : "show ip ospf (1-65535) [json]",
3478 : SHOW_STR
3479 : IP_STR
3480 : "OSPF information\n"
3481 : "Instance ID\n"
3482 : JSON_STR)
3483 : {
3484 0 : int idx_number = 3;
3485 0 : struct ospf *ospf;
3486 0 : unsigned short instance = 0;
3487 0 : bool uj = use_json(argc, argv);
3488 0 : int ret = CMD_SUCCESS;
3489 0 : json_object *json = NULL;
3490 :
3491 0 : instance = strtoul(argv[idx_number]->arg, NULL, 10);
3492 0 : if (instance != ospf_instance)
3493 : return CMD_NOT_MY_INSTANCE;
3494 :
3495 0 : ospf = ospf_lookup_instance(instance);
3496 0 : if (!ospf || !ospf->oi_running)
3497 : return CMD_SUCCESS;
3498 :
3499 0 : if (uj)
3500 0 : json = json_object_new_object();
3501 :
3502 0 : ret = show_ip_ospf_common(vty, ospf, json, 0);
3503 :
3504 0 : if (uj)
3505 0 : vty_json(vty, json);
3506 :
3507 : return ret;
3508 : }
3509 :
3510 0 : static void ospf_interface_auth_show(struct vty *vty, struct ospf_interface *oi,
3511 : json_object *json, bool use_json)
3512 : {
3513 0 : int auth_type;
3514 :
3515 0 : auth_type = OSPF_IF_PARAM(oi, auth_type);
3516 :
3517 0 : switch (auth_type) {
3518 0 : case OSPF_AUTH_NULL:
3519 0 : if (use_json)
3520 0 : json_object_string_add(json, "authentication",
3521 : "authenticationNone");
3522 : else
3523 0 : vty_out(vty, " Authentication NULL is enabled\n");
3524 : break;
3525 0 : case OSPF_AUTH_SIMPLE: {
3526 0 : if (use_json)
3527 0 : json_object_string_add(json, "authentication",
3528 : "authenticationSimplePassword");
3529 : else
3530 0 : vty_out(vty,
3531 : " Simple password authentication enabled\n");
3532 : break;
3533 : }
3534 0 : case OSPF_AUTH_CRYPTOGRAPHIC: {
3535 0 : struct crypt_key *ckey;
3536 :
3537 0 : if (list_isempty(OSPF_IF_PARAM(oi, auth_crypt)))
3538 : return;
3539 :
3540 0 : ckey = listgetdata(listtail(OSPF_IF_PARAM(oi, auth_crypt)));
3541 0 : if (ckey) {
3542 0 : if (use_json) {
3543 0 : json_object_string_add(json, "authentication",
3544 : "authenticationMessageDigest");
3545 : } else {
3546 0 : vty_out(vty,
3547 : " Cryptographic authentication enabled\n");
3548 0 : vty_out(vty, " Algorithm:MD5\n");
3549 : }
3550 : }
3551 : break;
3552 : }
3553 : default:
3554 : break;
3555 : }
3556 : }
3557 :
3558 0 : static void show_ip_ospf_interface_sub(struct vty *vty, struct ospf *ospf,
3559 : struct interface *ifp,
3560 : json_object *json_interface_sub,
3561 : bool use_json)
3562 : {
3563 0 : int is_up;
3564 0 : struct ospf_neighbor *nbr;
3565 0 : struct route_node *rn;
3566 0 : uint32_t bandwidth = ifp->bandwidth ? ifp->bandwidth : ifp->speed;
3567 :
3568 : /* Is interface up? */
3569 0 : if (use_json) {
3570 0 : is_up = if_is_operative(ifp);
3571 0 : if (is_up)
3572 0 : json_object_boolean_true_add(json_interface_sub,
3573 : "ifUp");
3574 : else
3575 0 : json_object_boolean_false_add(json_interface_sub,
3576 : "ifDown");
3577 :
3578 0 : json_object_int_add(json_interface_sub, "ifIndex",
3579 0 : ifp->ifindex);
3580 0 : json_object_int_add(json_interface_sub, "mtuBytes", ifp->mtu);
3581 0 : json_object_int_add(json_interface_sub, "bandwidthMbit",
3582 : bandwidth);
3583 0 : json_object_string_add(json_interface_sub, "ifFlags",
3584 : if_flag_dump(ifp->flags));
3585 : } else {
3586 0 : vty_out(vty, "%s is %s\n", ifp->name,
3587 0 : ((is_up = if_is_operative(ifp)) ? "up" : "down"));
3588 0 : vty_out(vty, " ifindex %u, MTU %u bytes, BW %u Mbit %s\n",
3589 : ifp->ifindex, ifp->mtu, bandwidth,
3590 : if_flag_dump(ifp->flags));
3591 : }
3592 :
3593 : /* Is interface OSPF enabled? */
3594 0 : if (use_json) {
3595 0 : if (ospf_oi_count(ifp) == 0) {
3596 0 : json_object_boolean_false_add(json_interface_sub,
3597 : "ospfEnabled");
3598 0 : return;
3599 0 : } else if (!is_up) {
3600 0 : json_object_boolean_false_add(json_interface_sub,
3601 : "ospfRunning");
3602 0 : return;
3603 : } else
3604 0 : json_object_boolean_true_add(json_interface_sub,
3605 : "ospfEnabled");
3606 : } else {
3607 0 : if (ospf_oi_count(ifp) == 0) {
3608 0 : vty_out(vty, " OSPF not enabled on this interface\n");
3609 0 : return;
3610 0 : } else if (!is_up) {
3611 0 : vty_out(vty,
3612 : " OSPF is enabled, but not running on this interface\n");
3613 0 : return;
3614 : }
3615 : }
3616 :
3617 0 : for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) {
3618 0 : struct ospf_interface *oi = rn->info;
3619 :
3620 0 : if (oi == NULL)
3621 0 : continue;
3622 :
3623 0 : if (CHECK_FLAG(oi->connected->flags, ZEBRA_IFA_UNNUMBERED)) {
3624 0 : if (use_json)
3625 0 : json_object_boolean_true_add(json_interface_sub,
3626 : "ifUnnumbered");
3627 : else
3628 0 : vty_out(vty, " This interface is UNNUMBERED,");
3629 : } else {
3630 0 : struct in_addr dest;
3631 0 : const char *dstr;
3632 :
3633 : /* Show OSPF interface information. */
3634 0 : if (use_json) {
3635 0 : json_object_string_addf(
3636 : json_interface_sub, "ipAddress", "%pI4",
3637 0 : &oi->address->u.prefix4);
3638 0 : json_object_int_add(json_interface_sub,
3639 : "ipAddressPrefixlen",
3640 0 : oi->address->prefixlen);
3641 : } else
3642 0 : vty_out(vty, " Internet Address %pFX,",
3643 : oi->address);
3644 :
3645 : /* For Vlinks, showing the peer address is
3646 : * probably more informative than the local
3647 : * interface that is being used */
3648 0 : if (oi->type == OSPF_IFTYPE_VIRTUALLINK) {
3649 0 : dstr = "Peer";
3650 0 : dest = oi->vl_data->peer_addr;
3651 0 : } else if (CONNECTED_PEER(oi->connected)
3652 0 : && oi->connected->destination) {
3653 0 : dstr = "Peer";
3654 0 : dest = oi->connected->destination->u.prefix4;
3655 : } else {
3656 0 : dstr = "Broadcast";
3657 0 : dest.s_addr = ipv4_broadcast_addr(
3658 : oi->connected->address->u.prefix4.s_addr,
3659 0 : oi->connected->address->prefixlen);
3660 : }
3661 :
3662 0 : if (use_json) {
3663 0 : json_object_string_add(
3664 : json_interface_sub,
3665 : "ospfIfType", dstr);
3666 0 : if (oi->type == OSPF_IFTYPE_VIRTUALLINK)
3667 0 : json_object_string_addf(
3668 : json_interface_sub, "vlinkPeer",
3669 : "%pI4", &dest);
3670 : else
3671 0 : json_object_string_addf(
3672 : json_interface_sub,
3673 : "localIfUsed", "%pI4", &dest);
3674 : } else
3675 0 : vty_out(vty, " %s %pI4,", dstr,
3676 : &dest);
3677 : }
3678 0 : if (use_json) {
3679 0 : json_object_string_add(json_interface_sub, "area",
3680 : ospf_area_desc_string(oi->area));
3681 0 : if (OSPF_IF_PARAM(oi, mtu_ignore))
3682 0 : json_object_boolean_true_add(
3683 : json_interface_sub,
3684 : "mtuMismatchDetect");
3685 0 : json_object_string_addf(json_interface_sub, "routerId",
3686 : "%pI4", &ospf->router_id);
3687 0 : json_object_string_add(json_interface_sub,
3688 : "networkType",
3689 0 : ospf_network_type_str[oi->type]);
3690 0 : json_object_int_add(json_interface_sub, "cost",
3691 0 : oi->output_cost);
3692 0 : json_object_int_add(
3693 : json_interface_sub, "transmitDelaySecs",
3694 0 : OSPF_IF_PARAM(oi, transmit_delay));
3695 0 : json_object_string_add(json_interface_sub, "state",
3696 : lookup_msg(ospf_ism_state_msg,
3697 0 : oi->state, NULL));
3698 0 : json_object_int_add(json_interface_sub, "priority",
3699 0 : PRIORITY(oi));
3700 : } else {
3701 0 : vty_out(vty, " Area %s\n",
3702 : ospf_area_desc_string(oi->area));
3703 :
3704 0 : vty_out(vty, " MTU mismatch detection: %s\n",
3705 0 : OSPF_IF_PARAM(oi, mtu_ignore) ? "disabled"
3706 : : "enabled");
3707 :
3708 0 : vty_out(vty,
3709 : " Router ID %pI4, Network Type %s, Cost: %d\n",
3710 : &ospf->router_id,
3711 0 : ospf_network_type_str[oi->type],
3712 : oi->output_cost);
3713 :
3714 0 : vty_out(vty,
3715 : " Transmit Delay is %d sec, State %s, Priority %d\n",
3716 0 : OSPF_IF_PARAM(oi, transmit_delay),
3717 0 : lookup_msg(ospf_ism_state_msg, oi->state, NULL),
3718 0 : PRIORITY(oi));
3719 : }
3720 :
3721 : /* Show DR information. */
3722 0 : if (DR(oi).s_addr == INADDR_ANY) {
3723 0 : if (!use_json)
3724 0 : vty_out(vty,
3725 : " No backup designated router on this network\n");
3726 : } else {
3727 0 : nbr = ospf_nbr_lookup_by_addr(oi->nbrs, &DR(oi));
3728 0 : if (nbr) {
3729 0 : if (use_json) {
3730 0 : json_object_string_addf(
3731 : json_interface_sub, "drId",
3732 : "%pI4", &nbr->router_id);
3733 0 : json_object_string_addf(
3734 : json_interface_sub, "drAddress",
3735 : "%pI4",
3736 : &nbr->address.u.prefix4);
3737 : } else {
3738 0 : vty_out(vty,
3739 : " Designated Router (ID) %pI4",
3740 : &nbr->router_id);
3741 0 : vty_out(vty,
3742 : " Interface Address %pFX\n",
3743 : &nbr->address);
3744 : }
3745 : }
3746 0 : nbr = NULL;
3747 :
3748 0 : nbr = ospf_nbr_lookup_by_addr(oi->nbrs, &BDR(oi));
3749 0 : if (nbr == NULL) {
3750 0 : if (!use_json)
3751 0 : vty_out(vty,
3752 : " No backup designated router on this network\n");
3753 : } else {
3754 0 : if (use_json) {
3755 0 : json_object_string_addf(
3756 : json_interface_sub, "bdrId",
3757 : "%pI4", &nbr->router_id);
3758 0 : json_object_string_addf(
3759 : json_interface_sub,
3760 : "bdrAddress", "%pI4",
3761 : &nbr->address.u.prefix4);
3762 : } else {
3763 0 : vty_out(vty,
3764 : " Backup Designated Router (ID) %pI4,",
3765 : &nbr->router_id);
3766 0 : vty_out(vty, " Interface Address %pI4\n",
3767 : &nbr->address.u.prefix4);
3768 : }
3769 : }
3770 : }
3771 :
3772 : /* Next network-LSA sequence number we'll use, if we're elected
3773 : * DR */
3774 0 : if (oi->params
3775 0 : && ntohl(oi->params->network_lsa_seqnum)
3776 : != OSPF_INITIAL_SEQUENCE_NUMBER) {
3777 0 : if (use_json)
3778 0 : json_object_int_add(
3779 : json_interface_sub,
3780 : "networkLsaSequence",
3781 0 : ntohl(oi->params->network_lsa_seqnum));
3782 : else
3783 0 : vty_out(vty,
3784 : " Saved Network-LSA sequence number 0x%x\n",
3785 : ntohl(oi->params->network_lsa_seqnum));
3786 : }
3787 :
3788 0 : if (use_json) {
3789 0 : if (OI_MEMBER_CHECK(oi, MEMBER_ALLROUTERS)
3790 : || OI_MEMBER_CHECK(oi, MEMBER_DROUTERS)) {
3791 0 : if (OI_MEMBER_CHECK(oi, MEMBER_ALLROUTERS))
3792 0 : json_object_boolean_true_add(
3793 : json_interface_sub,
3794 : "mcastMemberOspfAllRouters");
3795 0 : if (OI_MEMBER_CHECK(oi, MEMBER_DROUTERS))
3796 0 : json_object_boolean_true_add(
3797 : json_interface_sub,
3798 : "mcastMemberOspfDesignatedRouters");
3799 : }
3800 : } else {
3801 0 : vty_out(vty, " Multicast group memberships:");
3802 0 : if (OI_MEMBER_CHECK(oi, MEMBER_ALLROUTERS)
3803 : || OI_MEMBER_CHECK(oi, MEMBER_DROUTERS)) {
3804 0 : if (OI_MEMBER_CHECK(oi, MEMBER_ALLROUTERS))
3805 0 : vty_out(vty, " OSPFAllRouters");
3806 0 : if (OI_MEMBER_CHECK(oi, MEMBER_DROUTERS))
3807 0 : vty_out(vty, " OSPFDesignatedRouters");
3808 : } else
3809 0 : vty_out(vty, " <None>");
3810 0 : vty_out(vty, "\n");
3811 : }
3812 :
3813 0 : if (use_json) {
3814 0 : if (OSPF_IF_PARAM(oi, fast_hello) == 0)
3815 0 : json_object_int_add(
3816 : json_interface_sub, "timerMsecs",
3817 0 : OSPF_IF_PARAM(oi, v_hello) * 1000);
3818 : else
3819 0 : json_object_int_add(
3820 : json_interface_sub, "timerMsecs",
3821 0 : 1000 / OSPF_IF_PARAM(oi, fast_hello));
3822 0 : json_object_int_add(json_interface_sub,
3823 : "timerDeadSecs",
3824 0 : OSPF_IF_PARAM(oi, v_wait));
3825 0 : json_object_int_add(json_interface_sub,
3826 : "timerWaitSecs",
3827 0 : OSPF_IF_PARAM(oi, v_wait));
3828 0 : json_object_int_add(
3829 : json_interface_sub, "timerRetransmitSecs",
3830 0 : OSPF_IF_PARAM(oi, retransmit_interval));
3831 : } else {
3832 0 : vty_out(vty, " Timer intervals configured,");
3833 0 : vty_out(vty, " Hello ");
3834 0 : if (OSPF_IF_PARAM(oi, fast_hello) == 0)
3835 0 : vty_out(vty, "%ds,",
3836 0 : OSPF_IF_PARAM(oi, v_hello));
3837 : else
3838 0 : vty_out(vty, "%dms,",
3839 0 : 1000 / OSPF_IF_PARAM(oi, fast_hello));
3840 0 : vty_out(vty, " Dead %ds, Wait %ds, Retransmit %d\n",
3841 0 : OSPF_IF_PARAM(oi, v_wait),
3842 0 : OSPF_IF_PARAM(oi, v_wait),
3843 0 : OSPF_IF_PARAM(oi, retransmit_interval));
3844 : }
3845 :
3846 0 : if (OSPF_IF_PASSIVE_STATUS(oi) == OSPF_IF_ACTIVE) {
3847 0 : char timebuf[OSPF_TIME_DUMP_SIZE];
3848 0 : if (use_json) {
3849 0 : long time_store = 0;
3850 0 : if (oi->t_hello)
3851 0 : time_store =
3852 0 : monotime_until(
3853 0 : &oi->t_hello->u.sands,
3854 : NULL)
3855 : / 1000LL;
3856 0 : json_object_int_add(json_interface_sub,
3857 : "timerHelloInMsecs",
3858 : time_store);
3859 : } else
3860 0 : vty_out(vty, " Hello due in %s\n",
3861 : ospf_timer_dump(oi->t_hello, timebuf,
3862 : sizeof(timebuf)));
3863 : } else /* passive-interface is set */
3864 : {
3865 0 : if (use_json)
3866 0 : json_object_boolean_true_add(
3867 : json_interface_sub,
3868 : "timerPassiveIface");
3869 : else
3870 0 : vty_out(vty,
3871 : " No Hellos (Passive interface)\n");
3872 : }
3873 :
3874 0 : if (use_json) {
3875 0 : json_object_int_add(json_interface_sub, "nbrCount",
3876 0 : ospf_nbr_count(oi, 0));
3877 0 : json_object_int_add(json_interface_sub,
3878 : "nbrAdjacentCount",
3879 0 : ospf_nbr_count(oi, NSM_Full));
3880 : } else
3881 0 : vty_out(vty,
3882 : " Neighbor Count is %d, Adjacent neighbor count is %d\n",
3883 : ospf_nbr_count(oi, 0),
3884 : ospf_nbr_count(oi, NSM_Full));
3885 :
3886 0 : ospf_interface_bfd_show(vty, ifp, json_interface_sub);
3887 :
3888 : /* OSPF Authentication information */
3889 0 : ospf_interface_auth_show(vty, oi, json_interface_sub, use_json);
3890 : }
3891 : }
3892 :
3893 0 : static int show_ip_ospf_interface_common(struct vty *vty, struct ospf *ospf,
3894 : char *intf_name, uint8_t use_vrf,
3895 : json_object *json, bool use_json)
3896 : {
3897 0 : struct interface *ifp;
3898 0 : struct vrf *vrf = vrf_lookup_by_id(ospf->vrf_id);
3899 0 : json_object *json_vrf = NULL;
3900 0 : json_object *json_interface_sub = NULL, *json_interface = NULL;
3901 :
3902 0 : if (use_json) {
3903 0 : if (use_vrf)
3904 0 : json_vrf = json_object_new_object();
3905 : else
3906 : json_vrf = json;
3907 0 : json_interface = json_object_new_object();
3908 : }
3909 :
3910 0 : if (ospf->instance) {
3911 0 : if (use_json)
3912 0 : json_object_int_add(json, "ospfInstance",
3913 : ospf->instance);
3914 : else
3915 0 : vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
3916 : }
3917 :
3918 0 : ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf);
3919 :
3920 0 : if (intf_name == NULL) {
3921 : /* Show All Interfaces.*/
3922 0 : FOR_ALL_INTERFACES (vrf, ifp) {
3923 0 : if (ospf_oi_count(ifp)) {
3924 0 : if (use_json) {
3925 0 : json_interface_sub =
3926 0 : json_object_new_object();
3927 : }
3928 0 : show_ip_ospf_interface_sub(vty, ospf, ifp,
3929 : json_interface_sub,
3930 : use_json);
3931 :
3932 0 : if (use_json) {
3933 0 : json_object_object_add(
3934 0 : json_interface, ifp->name,
3935 : json_interface_sub);
3936 : }
3937 : }
3938 : }
3939 0 : if (use_json)
3940 0 : json_object_object_add(json_vrf, "interfaces",
3941 : json_interface);
3942 : } else {
3943 : /* Interface name is specified. */
3944 0 : ifp = if_lookup_by_name(intf_name, ospf->vrf_id);
3945 0 : if (ifp == NULL) {
3946 0 : if (use_json)
3947 0 : json_object_boolean_true_add(json_vrf,
3948 : "noSuchIface");
3949 : else
3950 0 : vty_out(vty, "No such interface name\n");
3951 : } else {
3952 0 : if (use_json) {
3953 0 : json_interface_sub = json_object_new_object();
3954 0 : json_interface = json_object_new_object();
3955 : }
3956 :
3957 0 : show_ip_ospf_interface_sub(
3958 : vty, ospf, ifp, json_interface_sub, use_json);
3959 :
3960 0 : if (use_json) {
3961 0 : json_object_object_add(json_interface,
3962 0 : ifp->name,
3963 : json_interface_sub);
3964 0 : json_object_object_add(json_vrf, "interfaces",
3965 : json_interface);
3966 : }
3967 : }
3968 : }
3969 :
3970 0 : if (use_json) {
3971 0 : if (use_vrf) {
3972 0 : json_object_object_add(json, ospf_get_name(ospf),
3973 : json_vrf);
3974 : }
3975 : } else
3976 0 : vty_out(vty, "\n");
3977 :
3978 0 : return CMD_SUCCESS;
3979 : }
3980 :
3981 0 : static void show_ip_ospf_interface_traffic_sub(struct vty *vty,
3982 : struct ospf_interface *oi,
3983 : json_object *json_interface_sub,
3984 : bool use_json)
3985 : {
3986 0 : if (use_json) {
3987 0 : json_object_int_add(json_interface_sub, "ifIndex",
3988 0 : oi->ifp->ifindex);
3989 0 : json_object_int_add(json_interface_sub, "helloIn",
3990 0 : oi->hello_in);
3991 0 : json_object_int_add(json_interface_sub, "helloOut",
3992 0 : oi->hello_out);
3993 0 : json_object_int_add(json_interface_sub, "dbDescIn",
3994 0 : oi->db_desc_in);
3995 0 : json_object_int_add(json_interface_sub, "dbDescOut",
3996 0 : oi->db_desc_out);
3997 0 : json_object_int_add(json_interface_sub, "lsReqIn",
3998 0 : oi->ls_req_in);
3999 0 : json_object_int_add(json_interface_sub, "lsReqOut",
4000 0 : oi->ls_req_out);
4001 0 : json_object_int_add(json_interface_sub, "lsUpdIn",
4002 0 : oi->ls_upd_in);
4003 0 : json_object_int_add(json_interface_sub, "lsUpdOut",
4004 0 : oi->ls_upd_out);
4005 0 : json_object_int_add(json_interface_sub, "lsAckIn",
4006 0 : oi->ls_ack_in);
4007 0 : json_object_int_add(json_interface_sub, "lsAckOut",
4008 0 : oi->ls_ack_out);
4009 0 : json_object_int_add(json_interface_sub, "packetsQueued",
4010 0 : listcount(oi->obuf));
4011 : } else {
4012 0 : vty_out(vty,
4013 : "%-10s %8u/%-8u %7u/%-7u %7u/%-7u %7u/%-7u %7u/%-7u %12lu\n",
4014 0 : oi->ifp->name, oi->hello_in, oi->hello_out,
4015 : oi->db_desc_in, oi->db_desc_out, oi->ls_req_in,
4016 : oi->ls_req_out, oi->ls_upd_in, oi->ls_upd_out,
4017 0 : oi->ls_ack_in, oi->ls_ack_out, listcount(oi->obuf));
4018 : }
4019 0 : }
4020 :
4021 : /* OSPFv2 Packet Counters */
4022 0 : static int show_ip_ospf_interface_traffic_common(
4023 : struct vty *vty, struct ospf *ospf, char *intf_name, json_object *json,
4024 : int display_once, uint8_t use_vrf, bool use_json)
4025 : {
4026 0 : struct vrf *vrf = NULL;
4027 0 : struct interface *ifp = NULL;
4028 0 : json_object *json_vrf = NULL;
4029 0 : json_object *json_interface_sub = NULL;
4030 :
4031 0 : if (!use_json && !display_once) {
4032 0 : vty_out(vty, "\n");
4033 0 : vty_out(vty, "%-12s%-17s%-17s%-17s%-17s%-17s%-17s\n",
4034 : "Interface", " HELLO", " DB-Desc", " LS-Req",
4035 : " LS-Update", " LS-Ack", " Packets");
4036 0 : vty_out(vty, "%-10s%-18s%-18s%-17s%-17s%-17s%-17s\n", "",
4037 : " Rx/Tx", " Rx/Tx", " Rx/Tx", " Rx/Tx",
4038 : " Rx/Tx", " Queued");
4039 0 : vty_out(vty,
4040 : "-------------------------------------------------------------------------------------------------------------\n");
4041 0 : } else if (use_json) {
4042 0 : if (use_vrf)
4043 0 : json_vrf = json_object_new_object();
4044 : else
4045 : json_vrf = json;
4046 : }
4047 :
4048 0 : ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf);
4049 :
4050 0 : if (intf_name == NULL) {
4051 0 : vrf = vrf_lookup_by_id(ospf->vrf_id);
4052 0 : FOR_ALL_INTERFACES (vrf, ifp) {
4053 0 : struct route_node *rn;
4054 0 : struct ospf_interface *oi;
4055 :
4056 0 : if (ospf_oi_count(ifp) == 0)
4057 0 : continue;
4058 :
4059 0 : for (rn = route_top(IF_OIFS(ifp)); rn;
4060 0 : rn = route_next(rn)) {
4061 0 : oi = rn->info;
4062 :
4063 0 : if (oi == NULL)
4064 0 : continue;
4065 :
4066 0 : if (use_json) {
4067 0 : json_interface_sub =
4068 0 : json_object_new_object();
4069 : }
4070 :
4071 0 : show_ip_ospf_interface_traffic_sub(
4072 : vty, oi, json_interface_sub, use_json);
4073 0 : if (use_json) {
4074 0 : json_object_object_add(
4075 0 : json_vrf, ifp->name,
4076 : json_interface_sub);
4077 : }
4078 : }
4079 : }
4080 : } else {
4081 : /* Interface name is specified. */
4082 0 : ifp = if_lookup_by_name(intf_name, ospf->vrf_id);
4083 0 : if (ifp != NULL) {
4084 0 : struct route_node *rn;
4085 0 : struct ospf_interface *oi;
4086 :
4087 0 : if (ospf_oi_count(ifp) == 0) {
4088 0 : vty_out(vty,
4089 : " OSPF not enabled on this interface %s\n",
4090 0 : ifp->name);
4091 0 : return CMD_SUCCESS;
4092 : }
4093 :
4094 0 : for (rn = route_top(IF_OIFS(ifp)); rn;
4095 0 : rn = route_next(rn)) {
4096 0 : oi = rn->info;
4097 :
4098 0 : if (use_json) {
4099 0 : json_interface_sub =
4100 0 : json_object_new_object();
4101 : }
4102 :
4103 0 : show_ip_ospf_interface_traffic_sub(
4104 : vty, oi, json_interface_sub, use_json);
4105 0 : if (use_json) {
4106 0 : json_object_object_add(
4107 0 : json_vrf, ifp->name,
4108 : json_interface_sub);
4109 : }
4110 : }
4111 : }
4112 : }
4113 :
4114 0 : if (use_json) {
4115 0 : if (use_vrf)
4116 0 : json_object_object_add(json, ospf_get_name(ospf),
4117 : json_vrf);
4118 : } else
4119 0 : vty_out(vty, "\n");
4120 :
4121 : return CMD_SUCCESS;
4122 : }
4123 :
4124 0 : DEFUN (show_ip_ospf_interface,
4125 : show_ip_ospf_interface_cmd,
4126 : "show ip ospf [vrf <NAME|all>] interface [INTERFACE] [json]",
4127 : SHOW_STR
4128 : IP_STR
4129 : "OSPF information\n"
4130 : VRF_CMD_HELP_STR
4131 : "All VRFs\n"
4132 : "Interface information\n"
4133 : "Interface name\n"
4134 : JSON_STR)
4135 : {
4136 0 : struct ospf *ospf;
4137 0 : bool uj = use_json(argc, argv);
4138 0 : struct listnode *node = NULL;
4139 0 : char *vrf_name = NULL, *intf_name = NULL;
4140 0 : bool all_vrf = false;
4141 0 : int ret = CMD_SUCCESS;
4142 0 : int inst = 0;
4143 0 : int idx_vrf = 0, idx_intf = 0;
4144 0 : uint8_t use_vrf = 0;
4145 0 : json_object *json = NULL;
4146 :
4147 0 : OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
4148 :
4149 0 : if (argv_find(argv, argc, "INTERFACE", &idx_intf))
4150 0 : intf_name = argv[idx_intf]->arg;
4151 :
4152 0 : if (uj)
4153 0 : json = json_object_new_object();
4154 :
4155 : /* vrf input is provided could be all or specific vrf*/
4156 0 : if (vrf_name) {
4157 0 : use_vrf = 1;
4158 0 : if (all_vrf) {
4159 0 : for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
4160 0 : if (!ospf->oi_running)
4161 0 : continue;
4162 0 : ret = show_ip_ospf_interface_common(
4163 : vty, ospf, intf_name, use_vrf, json,
4164 : uj);
4165 : }
4166 :
4167 0 : if (uj)
4168 0 : vty_json(vty, json);
4169 0 : else if (!ospf)
4170 0 : vty_out(vty, "%% OSPF is not enabled\n");
4171 :
4172 0 : return ret;
4173 : }
4174 0 : ospf = ospf_lookup_by_inst_name(inst, vrf_name);
4175 0 : if (ospf == NULL || !ospf->oi_running) {
4176 0 : if (uj)
4177 0 : vty_json(vty, json);
4178 : else
4179 0 : vty_out(vty,
4180 : "%% OSPF is not enabled in vrf %s\n",
4181 : vrf_name);
4182 :
4183 0 : return CMD_SUCCESS;
4184 : }
4185 0 : ret = show_ip_ospf_interface_common(vty, ospf, intf_name,
4186 : use_vrf, json, uj);
4187 :
4188 : } else {
4189 : /* Display default ospf (instance 0) info */
4190 0 : ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
4191 0 : if (ospf == NULL || !ospf->oi_running) {
4192 0 : if (uj)
4193 0 : vty_json(vty, json);
4194 : else
4195 0 : vty_out(vty,
4196 : "%% OSPF is not enabled in vrf default\n");
4197 :
4198 0 : return CMD_SUCCESS;
4199 : }
4200 0 : ret = show_ip_ospf_interface_common(vty, ospf, intf_name,
4201 : use_vrf, json, uj);
4202 : }
4203 :
4204 0 : if (uj)
4205 0 : vty_json(vty, json);
4206 :
4207 : return ret;
4208 : }
4209 :
4210 0 : DEFUN (show_ip_ospf_instance_interface,
4211 : show_ip_ospf_instance_interface_cmd,
4212 : "show ip ospf (1-65535) interface [INTERFACE] [json]",
4213 : SHOW_STR
4214 : IP_STR
4215 : "OSPF information\n"
4216 : "Instance ID\n"
4217 : "Interface information\n"
4218 : "Interface name\n"
4219 : JSON_STR)
4220 : {
4221 0 : int idx_number = 3;
4222 0 : int idx_intf = 0;
4223 0 : struct ospf *ospf;
4224 0 : unsigned short instance = 0;
4225 0 : bool uj = use_json(argc, argv);
4226 0 : char *intf_name = NULL;
4227 0 : int ret = CMD_SUCCESS;
4228 0 : json_object *json = NULL;
4229 :
4230 0 : instance = strtoul(argv[idx_number]->arg, NULL, 10);
4231 0 : if (instance != ospf_instance)
4232 : return CMD_NOT_MY_INSTANCE;
4233 :
4234 0 : ospf = ospf_lookup_instance(instance);
4235 0 : if (!ospf || !ospf->oi_running)
4236 : return CMD_SUCCESS;
4237 :
4238 0 : if (uj)
4239 0 : json = json_object_new_object();
4240 :
4241 0 : if (argv_find(argv, argc, "INTERFACE", &idx_intf))
4242 0 : intf_name = argv[idx_intf]->arg;
4243 :
4244 0 : ret = show_ip_ospf_interface_common(vty, ospf, intf_name, 0, json, uj);
4245 :
4246 0 : if (uj)
4247 0 : vty_json(vty, json);
4248 :
4249 : return ret;
4250 : }
4251 :
4252 0 : DEFUN (show_ip_ospf_interface_traffic,
4253 : show_ip_ospf_interface_traffic_cmd,
4254 : "show ip ospf [vrf <NAME|all>] interface traffic [INTERFACE] [json]",
4255 : SHOW_STR
4256 : IP_STR
4257 : "OSPF information\n"
4258 : VRF_CMD_HELP_STR
4259 : "All VRFs\n"
4260 : "Interface information\n"
4261 : "Protocol Packet counters\n"
4262 : "Interface name\n"
4263 : JSON_STR)
4264 : {
4265 0 : struct ospf *ospf = NULL;
4266 0 : struct listnode *node = NULL;
4267 0 : char *vrf_name = NULL, *intf_name = NULL;
4268 0 : bool all_vrf = false;
4269 0 : int inst = 0;
4270 0 : int idx_vrf = 0, idx_intf = 0;
4271 0 : bool uj = use_json(argc, argv);
4272 0 : json_object *json = NULL;
4273 0 : int ret = CMD_SUCCESS;
4274 0 : int display_once = 0;
4275 0 : uint8_t use_vrf = 0;
4276 :
4277 0 : OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
4278 :
4279 0 : if (argv_find(argv, argc, "INTERFACE", &idx_intf))
4280 0 : intf_name = argv[idx_intf]->arg;
4281 :
4282 0 : if (uj)
4283 0 : json = json_object_new_object();
4284 :
4285 0 : if (vrf_name) {
4286 0 : use_vrf = 1;
4287 0 : if (all_vrf) {
4288 0 : for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
4289 0 : if (!ospf->oi_running)
4290 0 : continue;
4291 :
4292 0 : ret = show_ip_ospf_interface_traffic_common(
4293 : vty, ospf, intf_name, json,
4294 : display_once, use_vrf, uj);
4295 0 : display_once = 1;
4296 : }
4297 :
4298 0 : if (uj)
4299 0 : vty_json(vty, json);
4300 :
4301 0 : return ret;
4302 : }
4303 0 : ospf = ospf_lookup_by_inst_name(inst, vrf_name);
4304 0 : if (ospf == NULL || !ospf->oi_running) {
4305 0 : if (uj)
4306 0 : json_object_free(json);
4307 0 : return CMD_SUCCESS;
4308 : }
4309 :
4310 0 : ret = show_ip_ospf_interface_traffic_common(
4311 : vty, ospf, intf_name, json, display_once, use_vrf, uj);
4312 : } else {
4313 0 : ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
4314 0 : if (ospf == NULL || !ospf->oi_running) {
4315 0 : if (uj)
4316 0 : json_object_free(json);
4317 0 : return CMD_SUCCESS;
4318 : }
4319 :
4320 0 : ret = show_ip_ospf_interface_traffic_common(
4321 : vty, ospf, intf_name, json, display_once, use_vrf, uj);
4322 : }
4323 :
4324 0 : if (uj)
4325 0 : vty_json(vty, json);
4326 :
4327 : return ret;
4328 : }
4329 :
4330 :
4331 0 : static void show_ip_ospf_neighbour_header(struct vty *vty)
4332 : {
4333 0 : vty_out(vty, "\n%-15s %-3s %-15s %-15s %-9s %-15s %-32s %5s %5s %5s\n",
4334 : "Neighbor ID", "Pri", "State", "Up Time", "Dead Time",
4335 : "Address", "Interface", "RXmtL", "RqstL", "DBsmL");
4336 0 : }
4337 :
4338 0 : static void show_ip_ospf_neighbour_brief(struct vty *vty,
4339 : struct ospf_neighbor *nbr,
4340 : struct ospf_neighbor *prev_nbr,
4341 : json_object *json, bool use_json)
4342 : {
4343 0 : char msgbuf[16];
4344 0 : char timebuf[OSPF_TIME_DUMP_SIZE];
4345 0 : json_object *json_neighbor = NULL, *json_neigh_array = NULL;
4346 0 : struct timeval res = {.tv_sec = 0, .tv_usec = 0};
4347 0 : long time_val = 0;
4348 0 : char uptime[OSPF_TIME_DUMP_SIZE];
4349 :
4350 0 : if (nbr->ts_last_progress.tv_sec || nbr->ts_last_progress.tv_usec)
4351 0 : time_val =
4352 0 : monotime_since(&nbr->ts_last_progress, &res) / 1000LL;
4353 :
4354 0 : if (use_json) {
4355 0 : char neigh_str[INET_ADDRSTRLEN];
4356 :
4357 0 : if (prev_nbr && !IPV4_ADDR_SAME(&prev_nbr->src, &nbr->src)) {
4358 : /* Start new neigh list */
4359 0 : json_neigh_array = NULL;
4360 : }
4361 :
4362 0 : if (nbr->state == NSM_Attempt &&
4363 0 : nbr->router_id.s_addr == INADDR_ANY)
4364 0 : strlcpy(neigh_str, "neighbor", sizeof(neigh_str));
4365 : else
4366 0 : inet_ntop(AF_INET, &nbr->router_id, neigh_str,
4367 : sizeof(neigh_str));
4368 :
4369 0 : json_object_object_get_ex(json, neigh_str, &json_neigh_array);
4370 :
4371 0 : if (!json_neigh_array) {
4372 0 : json_neigh_array = json_object_new_array();
4373 0 : json_object_object_add(json, neigh_str,
4374 : json_neigh_array);
4375 : }
4376 :
4377 0 : json_neighbor = json_object_new_object();
4378 :
4379 0 : ospf_nbr_ism_state_message(nbr, msgbuf, sizeof(msgbuf));
4380 : #if CONFDATE > 20230321
4381 : CPP_NOTICE(
4382 : "Remove show_ip_ospf_neighbor_sub() JSON keys: priority, state, deadTimeMsecs, address, retransmitCounter, requestCounter, dbSummaryCounter")
4383 : #endif
4384 0 : json_object_int_add(json_neighbor, "priority", nbr->priority);
4385 0 : json_object_string_add(json_neighbor, "state", msgbuf);
4386 0 : json_object_int_add(json_neighbor, "nbrPriority",
4387 0 : nbr->priority);
4388 0 : json_object_string_add(json_neighbor, "nbrState", msgbuf);
4389 :
4390 0 : json_object_string_add(
4391 : json_neighbor, "converged",
4392 0 : lookup_msg(ospf_nsm_state_msg, nbr->state, NULL));
4393 0 : json_object_string_add(json_neighbor, "role",
4394 : lookup_msg(ospf_ism_state_msg,
4395 : ospf_nbr_ism_state(nbr),
4396 : NULL));
4397 0 : if (nbr->t_inactivity) {
4398 0 : long time_store;
4399 :
4400 0 : time_store = monotime_until(&nbr->t_inactivity->u.sands,
4401 : NULL) /
4402 : 1000LL;
4403 0 : json_object_int_add(json_neighbor, "upTimeInMsec",
4404 : time_val);
4405 0 : json_object_int_add(json_neighbor, "deadTimeMsecs",
4406 : time_store);
4407 0 : json_object_int_add(json_neighbor,
4408 : "routerDeadIntervalTimerDueMsec",
4409 : time_store);
4410 0 : json_object_string_add(
4411 : json_neighbor, "upTime",
4412 : ospf_timeval_dump(&res, uptime,
4413 : sizeof(uptime)));
4414 0 : json_object_string_add(
4415 : json_neighbor, "deadTime",
4416 : ospf_timer_dump(nbr->t_inactivity, timebuf,
4417 : sizeof(timebuf)));
4418 : } else {
4419 0 : json_object_string_add(json_neighbor, "deadTimeMsecs",
4420 : "inactive");
4421 0 : json_object_string_add(json_neighbor,
4422 : "routerDeadIntervalTimerDueMsec",
4423 : "inactive");
4424 : }
4425 0 : json_object_string_addf(json_neighbor, "address", "%pI4",
4426 : &nbr->src);
4427 0 : json_object_string_addf(json_neighbor, "ifaceAddress", "%pI4",
4428 : &nbr->src);
4429 0 : json_object_string_add(json_neighbor, "ifaceName",
4430 : IF_NAME(nbr->oi));
4431 0 : json_object_int_add(json_neighbor, "retransmitCounter",
4432 0 : ospf_ls_retransmit_count(nbr));
4433 0 : json_object_int_add(json_neighbor,
4434 : "linkStateRetransmissionListCounter",
4435 0 : ospf_ls_retransmit_count(nbr));
4436 0 : json_object_int_add(json_neighbor, "requestCounter",
4437 0 : ospf_ls_request_count(nbr));
4438 0 : json_object_int_add(json_neighbor,
4439 : "linkStateRequestListCounter",
4440 0 : ospf_ls_request_count(nbr));
4441 0 : json_object_int_add(json_neighbor, "dbSummaryCounter",
4442 0 : ospf_db_summary_count(nbr));
4443 0 : json_object_int_add(json_neighbor, "databaseSummaryListCounter",
4444 0 : ospf_db_summary_count(nbr));
4445 :
4446 0 : json_object_array_add(json_neigh_array, json_neighbor);
4447 : } else {
4448 0 : ospf_nbr_ism_state_message(nbr, msgbuf, sizeof(msgbuf));
4449 :
4450 0 : if (nbr->state == NSM_Attempt &&
4451 0 : nbr->router_id.s_addr == INADDR_ANY)
4452 0 : vty_out(vty, "%-15s %3d %-15s ", "-", nbr->priority,
4453 : msgbuf);
4454 : else
4455 0 : vty_out(vty, "%-15pI4 %3d %-15s ", &nbr->router_id,
4456 : nbr->priority, msgbuf);
4457 :
4458 0 : vty_out(vty, "%-15s ",
4459 : ospf_timeval_dump(&res, uptime, sizeof(uptime)));
4460 :
4461 0 : vty_out(vty, "%9s ",
4462 : ospf_timer_dump(nbr->t_inactivity, timebuf,
4463 : sizeof(timebuf)));
4464 0 : vty_out(vty, "%-15pI4 ", &nbr->src);
4465 0 : vty_out(vty, "%-32s %5ld %5ld %5d\n", IF_NAME(nbr->oi),
4466 : ospf_ls_retransmit_count(nbr),
4467 : ospf_ls_request_count(nbr), ospf_db_summary_count(nbr));
4468 : }
4469 0 : }
4470 :
4471 0 : static void show_ip_ospf_neighbor_sub(struct vty *vty,
4472 : struct ospf_interface *oi,
4473 : json_object *json, bool use_json)
4474 : {
4475 0 : struct route_node *rn;
4476 0 : struct ospf_neighbor *nbr, *prev_nbr = NULL;
4477 :
4478 0 : for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) {
4479 0 : nbr = rn->info;
4480 :
4481 0 : if (!nbr)
4482 0 : continue;
4483 :
4484 : /* Do not show myself. */
4485 0 : if (nbr == oi->nbr_self)
4486 0 : continue;
4487 : /* Down state is not shown. */
4488 0 : if (nbr->state == NSM_Down)
4489 0 : continue;
4490 :
4491 0 : prev_nbr = nbr;
4492 :
4493 0 : show_ip_ospf_neighbour_brief(vty, nbr, prev_nbr, json,
4494 : use_json);
4495 : }
4496 0 : }
4497 :
4498 0 : static int show_ip_ospf_neighbor_common(struct vty *vty, struct ospf *ospf,
4499 : json_object *json, bool use_json,
4500 : uint8_t use_vrf)
4501 : {
4502 0 : struct ospf_interface *oi;
4503 0 : struct listnode *node;
4504 0 : json_object *json_vrf = NULL;
4505 0 : json_object *json_nbr_sub = NULL;
4506 :
4507 0 : if (use_json) {
4508 0 : if (use_vrf)
4509 0 : json_vrf = json_object_new_object();
4510 : else
4511 : json_vrf = json;
4512 0 : json_nbr_sub = json_object_new_object();
4513 : }
4514 :
4515 0 : if (ospf->instance) {
4516 0 : if (use_json)
4517 0 : json_object_int_add(json, "ospfInstance",
4518 : ospf->instance);
4519 : else
4520 0 : vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
4521 : }
4522 :
4523 0 : ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf);
4524 0 : if (!use_json)
4525 0 : show_ip_ospf_neighbour_header(vty);
4526 :
4527 0 : for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) {
4528 0 : if (ospf_interface_neighbor_count(oi) == 0)
4529 0 : continue;
4530 0 : show_ip_ospf_neighbor_sub(vty, oi, json_nbr_sub, use_json);
4531 : }
4532 :
4533 0 : if (use_json) {
4534 0 : json_object_object_add(json_vrf, "neighbors", json_nbr_sub);
4535 0 : if (use_vrf)
4536 0 : json_object_object_add(json, ospf_get_name(ospf),
4537 : json_vrf);
4538 : } else
4539 0 : vty_out(vty, "\n");
4540 :
4541 0 : return CMD_SUCCESS;
4542 : }
4543 :
4544 0 : DEFUN (show_ip_ospf_neighbor,
4545 : show_ip_ospf_neighbor_cmd,
4546 : "show ip ospf [vrf <NAME|all>] neighbor [json]",
4547 : SHOW_STR
4548 : IP_STR
4549 : "OSPF information\n"
4550 : VRF_CMD_HELP_STR
4551 : "All VRFs\n"
4552 : "Neighbor list\n"
4553 : JSON_STR)
4554 : {
4555 0 : struct ospf *ospf;
4556 0 : bool uj = use_json(argc, argv);
4557 0 : struct listnode *node = NULL;
4558 0 : char *vrf_name = NULL;
4559 0 : bool all_vrf = false;
4560 0 : int ret = CMD_SUCCESS;
4561 0 : int inst = 0;
4562 0 : int idx_vrf = 0;
4563 0 : uint8_t use_vrf = 0;
4564 0 : json_object *json = NULL;
4565 :
4566 0 : OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
4567 :
4568 0 : if (uj)
4569 0 : json = json_object_new_object();
4570 :
4571 : /* vrf input is provided could be all or specific vrf*/
4572 0 : if (vrf_name) {
4573 0 : use_vrf = 1;
4574 0 : if (all_vrf) {
4575 0 : for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
4576 0 : if (!ospf->oi_running)
4577 0 : continue;
4578 0 : ret = show_ip_ospf_neighbor_common(
4579 : vty, ospf, json, uj, use_vrf);
4580 : }
4581 :
4582 0 : if (uj)
4583 0 : vty_json(vty, json);
4584 0 : else if (!ospf)
4585 0 : vty_out(vty, "OSPF is not enabled\n");
4586 :
4587 0 : return ret;
4588 : }
4589 :
4590 0 : ospf = ospf_lookup_by_inst_name(inst, vrf_name);
4591 0 : if (ospf == NULL || !ospf->oi_running) {
4592 0 : if (uj)
4593 0 : vty_json(vty, json);
4594 : else
4595 0 : vty_out(vty,
4596 : "%% OSPF is not enabled in vrf %s\n",
4597 : vrf_name);
4598 :
4599 0 : return CMD_SUCCESS;
4600 : }
4601 : } else {
4602 : /* Display default ospf (instance 0) info */
4603 0 : ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
4604 0 : if (ospf == NULL || !ospf->oi_running) {
4605 0 : if (uj)
4606 0 : vty_json(vty, json);
4607 : else
4608 0 : vty_out(vty,
4609 : "%% OSPF is not enabled in vrf default\n");
4610 :
4611 0 : return CMD_SUCCESS;
4612 : }
4613 : }
4614 :
4615 : if (ospf) {
4616 0 : ret = show_ip_ospf_neighbor_common(vty, ospf, json, uj,
4617 : use_vrf);
4618 :
4619 0 : if (uj) {
4620 0 : vty_out(vty, "%s\n",
4621 : json_object_to_json_string_ext(
4622 : json, JSON_C_TO_STRING_PRETTY));
4623 : }
4624 : }
4625 :
4626 0 : if (uj)
4627 0 : json_object_free(json);
4628 :
4629 : return ret;
4630 : }
4631 :
4632 :
4633 0 : DEFUN (show_ip_ospf_instance_neighbor,
4634 : show_ip_ospf_instance_neighbor_cmd,
4635 : "show ip ospf (1-65535) neighbor [json]",
4636 : SHOW_STR
4637 : IP_STR
4638 : "OSPF information\n"
4639 : "Instance ID\n"
4640 : "Neighbor list\n"
4641 : JSON_STR)
4642 : {
4643 0 : int idx_number = 3;
4644 0 : struct ospf *ospf;
4645 0 : unsigned short instance = 0;
4646 0 : bool uj = use_json(argc, argv);
4647 0 : json_object *json = NULL;
4648 0 : int ret = CMD_SUCCESS;
4649 :
4650 0 : instance = strtoul(argv[idx_number]->arg, NULL, 10);
4651 0 : if (instance != ospf_instance)
4652 : return CMD_NOT_MY_INSTANCE;
4653 :
4654 0 : ospf = ospf_lookup_instance(instance);
4655 0 : if (!ospf || !ospf->oi_running)
4656 : return CMD_SUCCESS;
4657 :
4658 0 : if (uj)
4659 0 : json = json_object_new_object();
4660 :
4661 0 : ret = show_ip_ospf_neighbor_common(vty, ospf, json, uj, 0);
4662 :
4663 0 : if (uj)
4664 0 : vty_json(vty, json);
4665 :
4666 : return ret;
4667 : }
4668 :
4669 0 : static int show_ip_ospf_neighbor_all_common(struct vty *vty, struct ospf *ospf,
4670 : json_object *json, bool use_json,
4671 : uint8_t use_vrf)
4672 : {
4673 0 : struct listnode *node;
4674 0 : struct ospf_interface *oi;
4675 0 : char buf[PREFIX_STRLEN];
4676 0 : json_object *json_vrf = NULL;
4677 0 : json_object *json_neighbor_sub = NULL;
4678 :
4679 0 : if (use_json) {
4680 0 : if (use_vrf)
4681 0 : json_vrf = json_object_new_object();
4682 : else
4683 : json_vrf = json;
4684 : }
4685 :
4686 0 : ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf);
4687 0 : if (!use_json)
4688 0 : show_ip_ospf_neighbour_header(vty);
4689 :
4690 0 : if (ospf->instance) {
4691 0 : if (use_json)
4692 0 : json_object_int_add(json_vrf, "ospfInstance",
4693 : ospf->instance);
4694 : else
4695 0 : vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
4696 : }
4697 :
4698 0 : for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) {
4699 0 : struct listnode *nbr_node;
4700 0 : struct ospf_nbr_nbma *nbr_nbma;
4701 :
4702 0 : show_ip_ospf_neighbor_sub(vty, oi, json_vrf, use_json);
4703 :
4704 : /* print Down neighbor status */
4705 0 : for (ALL_LIST_ELEMENTS_RO(oi->nbr_nbma, nbr_node, nbr_nbma)) {
4706 0 : if (nbr_nbma->nbr == NULL
4707 0 : || nbr_nbma->nbr->state == NSM_Down) {
4708 0 : if (use_json) {
4709 0 : json_neighbor_sub =
4710 0 : json_object_new_object();
4711 0 : json_object_int_add(json_neighbor_sub,
4712 : "nbrNbmaPriority",
4713 0 : nbr_nbma->priority);
4714 0 : json_object_boolean_true_add(
4715 : json_neighbor_sub,
4716 : "nbrNbmaDown");
4717 0 : json_object_string_add(
4718 : json_neighbor_sub,
4719 : "nbrNbmaIfaceName",
4720 : IF_NAME(oi));
4721 0 : json_object_int_add(
4722 : json_neighbor_sub,
4723 : "nbrNbmaRetransmitCounter", 0);
4724 0 : json_object_int_add(
4725 : json_neighbor_sub,
4726 : "nbrNbmaRequestCounter", 0);
4727 0 : json_object_int_add(
4728 : json_neighbor_sub,
4729 : "nbrNbmaDbSummaryCounter", 0);
4730 0 : json_object_object_add(
4731 : json_vrf,
4732 : inet_ntop(AF_INET,
4733 0 : &nbr_nbma->addr, buf,
4734 : sizeof(buf)),
4735 : json_neighbor_sub);
4736 : } else {
4737 0 : vty_out(vty, "%-15s %3d %-15s %9s ",
4738 0 : "-", nbr_nbma->priority, "Down",
4739 : "-");
4740 0 : vty_out(vty,
4741 : "%-32pI4 %-20s %5d %5d %5d\n",
4742 : &nbr_nbma->addr,
4743 : IF_NAME(oi), 0, 0, 0);
4744 : }
4745 : }
4746 : }
4747 : }
4748 :
4749 0 : if (use_json) {
4750 0 : if (use_vrf)
4751 0 : json_object_object_add(json, ospf_get_name(ospf),
4752 : json_vrf);
4753 : } else
4754 0 : vty_out(vty, "\n");
4755 :
4756 0 : return CMD_SUCCESS;
4757 : }
4758 :
4759 0 : DEFUN (show_ip_ospf_neighbor_all,
4760 : show_ip_ospf_neighbor_all_cmd,
4761 : "show ip ospf [vrf <NAME|all>] neighbor all [json]",
4762 : SHOW_STR
4763 : IP_STR
4764 : "OSPF information\n"
4765 : VRF_CMD_HELP_STR
4766 : "All VRFs\n"
4767 : "Neighbor list\n"
4768 : "include down status neighbor\n"
4769 : JSON_STR)
4770 : {
4771 0 : struct ospf *ospf;
4772 0 : bool uj = use_json(argc, argv);
4773 0 : struct listnode *node = NULL;
4774 0 : char *vrf_name = NULL;
4775 0 : bool all_vrf = false;
4776 0 : int ret = CMD_SUCCESS;
4777 0 : int inst = 0;
4778 0 : int idx_vrf = 0;
4779 0 : uint8_t use_vrf = 0;
4780 0 : json_object *json = NULL;
4781 :
4782 0 : OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
4783 :
4784 0 : if (uj)
4785 0 : json = json_object_new_object();
4786 :
4787 : /* vrf input is provided could be all or specific vrf*/
4788 0 : if (vrf_name) {
4789 0 : use_vrf = 1;
4790 0 : if (all_vrf) {
4791 0 : for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
4792 0 : if (!ospf->oi_running)
4793 0 : continue;
4794 0 : ret = show_ip_ospf_neighbor_all_common(
4795 : vty, ospf, json, uj, use_vrf);
4796 : }
4797 :
4798 0 : if (uj)
4799 0 : vty_json(vty, json);
4800 :
4801 0 : return ret;
4802 : }
4803 :
4804 0 : ospf = ospf_lookup_by_inst_name(inst, vrf_name);
4805 0 : if (ospf == NULL || !ospf->oi_running) {
4806 0 : if (uj)
4807 0 : json_object_free(json);
4808 0 : return CMD_SUCCESS;
4809 : }
4810 : } else {
4811 : /* Display default ospf (instance 0) info */
4812 0 : ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
4813 0 : if (ospf == NULL || !ospf->oi_running) {
4814 0 : if (uj)
4815 0 : json_object_free(json);
4816 0 : return CMD_SUCCESS;
4817 : }
4818 : }
4819 :
4820 : if (ospf) {
4821 0 : ret = show_ip_ospf_neighbor_all_common(vty, ospf, json, uj,
4822 : use_vrf);
4823 0 : if (uj) {
4824 0 : vty_out(vty, "%s\n",
4825 : json_object_to_json_string_ext(
4826 : json, JSON_C_TO_STRING_PRETTY));
4827 : }
4828 : }
4829 :
4830 0 : if (uj)
4831 0 : json_object_free(json);
4832 :
4833 : return ret;
4834 : }
4835 :
4836 0 : DEFUN (show_ip_ospf_instance_neighbor_all,
4837 : show_ip_ospf_instance_neighbor_all_cmd,
4838 : "show ip ospf (1-65535) neighbor all [json]",
4839 : SHOW_STR
4840 : IP_STR
4841 : "OSPF information\n"
4842 : "Instance ID\n"
4843 : "Neighbor list\n"
4844 : "include down status neighbor\n"
4845 : JSON_STR)
4846 : {
4847 0 : int idx_number = 3;
4848 0 : struct ospf *ospf;
4849 0 : unsigned short instance = 0;
4850 0 : bool uj = use_json(argc, argv);
4851 0 : json_object *json = NULL;
4852 0 : int ret = CMD_SUCCESS;
4853 :
4854 0 : instance = strtoul(argv[idx_number]->arg, NULL, 10);
4855 0 : if (instance != ospf_instance)
4856 : return CMD_NOT_MY_INSTANCE;
4857 :
4858 0 : ospf = ospf_lookup_instance(instance);
4859 0 : if (!ospf || !ospf->oi_running)
4860 : return CMD_SUCCESS;
4861 0 : if (uj)
4862 0 : json = json_object_new_object();
4863 :
4864 0 : ret = show_ip_ospf_neighbor_all_common(vty, ospf, json, uj, 0);
4865 :
4866 0 : if (uj)
4867 0 : vty_json(vty, json);
4868 :
4869 : return ret;
4870 : }
4871 :
4872 0 : static int show_ip_ospf_neighbor_int_common(struct vty *vty, struct ospf *ospf,
4873 : int arg_base,
4874 : struct cmd_token **argv,
4875 : bool use_json, uint8_t use_vrf)
4876 : {
4877 0 : struct interface *ifp;
4878 0 : struct route_node *rn;
4879 0 : json_object *json = NULL;
4880 :
4881 0 : if (use_json)
4882 0 : json = json_object_new_object();
4883 :
4884 0 : if (ospf->instance) {
4885 0 : if (use_json)
4886 0 : json_object_int_add(json, "ospfInstance",
4887 : ospf->instance);
4888 : else
4889 0 : vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
4890 : }
4891 :
4892 0 : ospf_show_vrf_name(ospf, vty, json, use_vrf);
4893 :
4894 0 : ifp = if_lookup_by_name(argv[arg_base]->arg, ospf->vrf_id);
4895 0 : if (!ifp) {
4896 0 : if (use_json)
4897 0 : json_object_boolean_true_add(json, "noSuchIface");
4898 : else
4899 0 : vty_out(vty, "No such interface.\n");
4900 0 : return CMD_WARNING;
4901 : }
4902 :
4903 0 : for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) {
4904 0 : struct ospf_interface *oi = rn->info;
4905 :
4906 0 : if (oi == NULL)
4907 0 : continue;
4908 :
4909 0 : show_ip_ospf_neighbor_sub(vty, oi, json, use_json);
4910 : }
4911 :
4912 0 : if (use_json)
4913 0 : vty_json(vty, json);
4914 : else
4915 0 : vty_out(vty, "\n");
4916 :
4917 : return CMD_SUCCESS;
4918 : }
4919 :
4920 0 : DEFUN (show_ip_ospf_neighbor_int,
4921 : show_ip_ospf_neighbor_int_cmd,
4922 : "show ip ospf [vrf <NAME>] neighbor IFNAME [json]",
4923 : SHOW_STR
4924 : IP_STR
4925 : "OSPF information\n"
4926 : VRF_CMD_HELP_STR
4927 : "Neighbor list\n"
4928 : "Interface name\n"
4929 : JSON_STR)
4930 : {
4931 0 : struct ospf *ospf;
4932 0 : int idx_ifname = 0;
4933 0 : int idx_vrf = 0;
4934 0 : bool uj = use_json(argc, argv);
4935 0 : int ret = CMD_SUCCESS;
4936 0 : struct interface *ifp = NULL;
4937 0 : char *vrf_name = NULL;
4938 0 : vrf_id_t vrf_id = VRF_DEFAULT;
4939 0 : struct vrf *vrf = NULL;
4940 :
4941 0 : if (argv_find(argv, argc, "vrf", &idx_vrf))
4942 0 : vrf_name = argv[idx_vrf + 1]->arg;
4943 0 : if (vrf_name && strmatch(vrf_name, VRF_DEFAULT_NAME))
4944 : vrf_name = NULL;
4945 0 : if (vrf_name) {
4946 0 : vrf = vrf_lookup_by_name(vrf_name);
4947 0 : if (vrf)
4948 0 : vrf_id = vrf->vrf_id;
4949 : }
4950 0 : ospf = ospf_lookup_by_vrf_id(vrf_id);
4951 :
4952 0 : if (!ospf || !ospf->oi_running)
4953 : return ret;
4954 :
4955 0 : if (!uj)
4956 0 : show_ip_ospf_neighbour_header(vty);
4957 :
4958 0 : argv_find(argv, argc, "IFNAME", &idx_ifname);
4959 :
4960 0 : ifp = if_lookup_by_name(argv[idx_ifname]->arg, vrf_id);
4961 0 : if (!ifp)
4962 : return ret;
4963 :
4964 0 : ret = show_ip_ospf_neighbor_int_common(vty, ospf, idx_ifname,
4965 : argv, uj, 0);
4966 0 : return ret;
4967 : }
4968 :
4969 0 : DEFUN (show_ip_ospf_instance_neighbor_int,
4970 : show_ip_ospf_instance_neighbor_int_cmd,
4971 : "show ip ospf (1-65535) neighbor IFNAME [json]",
4972 : SHOW_STR
4973 : IP_STR
4974 : "OSPF information\n"
4975 : "Instance ID\n"
4976 : "Neighbor list\n"
4977 : "Interface name\n"
4978 : JSON_STR)
4979 : {
4980 0 : int idx_number = 3;
4981 0 : int idx_ifname = 5;
4982 0 : struct ospf *ospf;
4983 0 : unsigned short instance = 0;
4984 0 : bool uj = use_json(argc, argv);
4985 :
4986 0 : if (!uj)
4987 0 : show_ip_ospf_neighbour_header(vty);
4988 :
4989 0 : instance = strtoul(argv[idx_number]->arg, NULL, 10);
4990 0 : if (instance != ospf_instance)
4991 : return CMD_NOT_MY_INSTANCE;
4992 :
4993 0 : ospf = ospf_lookup_instance(instance);
4994 0 : if (!ospf || !ospf->oi_running)
4995 : return CMD_SUCCESS;
4996 :
4997 0 : if (!uj)
4998 0 : show_ip_ospf_neighbour_header(vty);
4999 :
5000 0 : return show_ip_ospf_neighbor_int_common(vty, ospf, idx_ifname, argv, uj,
5001 : 0);
5002 : }
5003 :
5004 0 : static void show_ip_ospf_nbr_nbma_detail_sub(struct vty *vty,
5005 : struct ospf_interface *oi,
5006 : struct ospf_nbr_nbma *nbr_nbma,
5007 : bool use_json, json_object *json)
5008 : {
5009 0 : char timebuf[OSPF_TIME_DUMP_SIZE];
5010 0 : json_object *json_sub = NULL;
5011 :
5012 0 : if (use_json)
5013 0 : json_sub = json_object_new_object();
5014 : else /* Show neighbor ID. */
5015 0 : vty_out(vty, " Neighbor %s,", "-");
5016 :
5017 : /* Show interface address. */
5018 0 : if (use_json)
5019 0 : json_object_string_addf(json_sub, "ifaceAddress", "%pI4",
5020 : &nbr_nbma->addr);
5021 : else
5022 0 : vty_out(vty, " interface address %pI4\n",
5023 : &nbr_nbma->addr);
5024 :
5025 : /* Show Area ID. */
5026 0 : if (use_json) {
5027 0 : json_object_string_add(json_sub, "areaId",
5028 : ospf_area_desc_string(oi->area));
5029 0 : json_object_string_add(json_sub, "iface", IF_NAME(oi));
5030 : } else
5031 0 : vty_out(vty, " In the area %s via interface %s\n",
5032 : ospf_area_desc_string(oi->area), IF_NAME(oi));
5033 :
5034 : /* Show neighbor priority and state. */
5035 0 : if (use_json) {
5036 0 : json_object_int_add(json_sub, "nbrPriority",
5037 0 : nbr_nbma->priority);
5038 0 : json_object_string_add(json_sub, "nbrState", "down");
5039 : } else
5040 0 : vty_out(vty, " Neighbor priority is %d, State is %s,",
5041 0 : nbr_nbma->priority, "Down");
5042 :
5043 : /* Show state changes. */
5044 0 : if (use_json)
5045 0 : json_object_int_add(json_sub, "stateChangeCounter",
5046 0 : nbr_nbma->state_change);
5047 : else
5048 0 : vty_out(vty, " %d state changes\n", nbr_nbma->state_change);
5049 :
5050 : /* Show PollInterval */
5051 0 : if (use_json)
5052 0 : json_object_int_add(json_sub, "pollInterval", nbr_nbma->v_poll);
5053 : else
5054 0 : vty_out(vty, " Poll interval %d\n", nbr_nbma->v_poll);
5055 :
5056 : /* Show poll-interval timer. */
5057 0 : if (nbr_nbma->t_poll) {
5058 0 : if (use_json) {
5059 0 : long time_store;
5060 0 : time_store = monotime_until(&nbr_nbma->t_poll->u.sands,
5061 : NULL) / 1000LL;
5062 0 : json_object_int_add(json_sub,
5063 : "pollIntervalTimerDueMsec",
5064 : time_store);
5065 : } else
5066 0 : vty_out(vty, " Poll timer due in %s\n",
5067 : ospf_timer_dump(nbr_nbma->t_poll, timebuf,
5068 : sizeof(timebuf)));
5069 : }
5070 :
5071 : /* Show poll-interval timer thread. */
5072 0 : if (use_json) {
5073 0 : if (nbr_nbma->t_poll != NULL)
5074 0 : json_object_string_add(json_sub,
5075 : "pollIntervalTimerThread", "on");
5076 : } else
5077 0 : vty_out(vty, " Thread Poll Timer %s\n",
5078 0 : nbr_nbma->t_poll != NULL ? "on" : "off");
5079 :
5080 0 : if (use_json)
5081 0 : json_object_object_add(json, "noNbrId", json_sub);
5082 0 : }
5083 :
5084 0 : static void show_ip_ospf_neighbor_detail_sub(struct vty *vty,
5085 : struct ospf_interface *oi,
5086 : struct ospf_neighbor *nbr,
5087 : struct ospf_neighbor *prev_nbr,
5088 : json_object *json, bool use_json)
5089 : {
5090 0 : char timebuf[OSPF_TIME_DUMP_SIZE];
5091 0 : json_object *json_neigh = NULL, *json_neigh_array = NULL;
5092 0 : char neigh_str[INET_ADDRSTRLEN] = {0};
5093 0 : char neigh_state[16] = {0};
5094 :
5095 0 : if (use_json) {
5096 0 : if (prev_nbr &&
5097 : !IPV4_ADDR_SAME(&prev_nbr->src, &nbr->src)) {
5098 : json_neigh_array = NULL;
5099 : }
5100 :
5101 0 : if (nbr->state == NSM_Attempt
5102 0 : && nbr->router_id.s_addr == INADDR_ANY)
5103 0 : strlcpy(neigh_str, "noNbrId", sizeof(neigh_str));
5104 : else
5105 0 : inet_ntop(AF_INET, &nbr->router_id,
5106 : neigh_str, sizeof(neigh_str));
5107 :
5108 0 : json_object_object_get_ex(json, neigh_str, &json_neigh_array);
5109 :
5110 0 : if (!json_neigh_array) {
5111 0 : json_neigh_array = json_object_new_array();
5112 0 : json_object_object_add(json, neigh_str,
5113 : json_neigh_array);
5114 : }
5115 :
5116 0 : json_neigh = json_object_new_object();
5117 :
5118 : } else {
5119 : /* Show neighbor ID. */
5120 0 : if (nbr->state == NSM_Attempt
5121 0 : && nbr->router_id.s_addr == INADDR_ANY)
5122 0 : vty_out(vty, " Neighbor %s,", "-");
5123 : else
5124 0 : vty_out(vty, " Neighbor %pI4,",
5125 : &nbr->router_id);
5126 : }
5127 :
5128 : /* Show interface address. */
5129 0 : if (use_json)
5130 0 : json_object_string_addf(json_neigh, "ifaceAddress", "%pI4",
5131 : &nbr->address.u.prefix4);
5132 : else
5133 0 : vty_out(vty, " interface address %pI4\n",
5134 : &nbr->address.u.prefix4);
5135 :
5136 : /* Show Area ID. */
5137 0 : if (use_json) {
5138 0 : json_object_string_add(json_neigh, "areaId",
5139 : ospf_area_desc_string(oi->area));
5140 0 : json_object_string_add(json_neigh, "ifaceName", oi->ifp->name);
5141 : } else
5142 0 : vty_out(vty, " In the area %s via interface %s\n",
5143 0 : ospf_area_desc_string(oi->area), oi->ifp->name);
5144 :
5145 : /* Show neighbor priority and state. */
5146 0 : ospf_nbr_ism_state_message(nbr, neigh_state, sizeof(neigh_state));
5147 0 : if (use_json) {
5148 0 : json_object_int_add(json_neigh, "nbrPriority", nbr->priority);
5149 0 : json_object_string_add(json_neigh, "nbrState", neigh_state);
5150 : } else
5151 0 : vty_out(vty, " Neighbor priority is %d, State is %s,",
5152 : nbr->priority, neigh_state);
5153 :
5154 : /* Show state changes. */
5155 0 : if (use_json)
5156 0 : json_object_int_add(json_neigh, "stateChangeCounter",
5157 0 : nbr->state_change);
5158 : else
5159 0 : vty_out(vty, " %d state changes\n", nbr->state_change);
5160 :
5161 0 : if (nbr->ts_last_progress.tv_sec || nbr->ts_last_progress.tv_usec) {
5162 0 : struct timeval res;
5163 0 : long time_store;
5164 :
5165 0 : time_store =
5166 0 : monotime_since(&nbr->ts_last_progress, &res) / 1000LL;
5167 0 : if (use_json) {
5168 0 : json_object_int_add(json_neigh, "lastPrgrsvChangeMsec",
5169 : time_store);
5170 : } else {
5171 0 : vty_out(vty,
5172 : " Most recent state change statistics:\n");
5173 0 : vty_out(vty, " Progressive change %s ago\n",
5174 : ospf_timeval_dump(&res, timebuf,
5175 : sizeof(timebuf)));
5176 : }
5177 : }
5178 :
5179 0 : if (nbr->ts_last_regress.tv_sec || nbr->ts_last_regress.tv_usec) {
5180 0 : struct timeval res;
5181 0 : long time_store;
5182 :
5183 0 : time_store =
5184 0 : monotime_since(&nbr->ts_last_regress, &res) / 1000LL;
5185 0 : if (use_json) {
5186 0 : json_object_int_add(json_neigh,
5187 : "lastRegressiveChangeMsec",
5188 : time_store);
5189 0 : if (nbr->last_regress_str)
5190 0 : json_object_string_add(
5191 : json_neigh,
5192 : "lastRegressiveChangeReason",
5193 : nbr->last_regress_str);
5194 : } else {
5195 0 : vty_out(vty,
5196 : " Regressive change %s ago, due to %s\n",
5197 : ospf_timeval_dump(&res, timebuf,
5198 : sizeof(timebuf)),
5199 0 : (nbr->last_regress_str ? nbr->last_regress_str
5200 : : "??"));
5201 : }
5202 : }
5203 :
5204 : /* Show Designated Rotuer ID. */
5205 0 : if (use_json)
5206 0 : json_object_string_addf(json_neigh, "routerDesignatedId",
5207 : "%pI4", &nbr->d_router);
5208 : else
5209 0 : vty_out(vty, " DR is %pI4,", &nbr->d_router);
5210 :
5211 : /* Show Backup Designated Rotuer ID. */
5212 0 : if (use_json)
5213 0 : json_object_string_addf(json_neigh, "routerDesignatedBackupId",
5214 : "%pI4", &nbr->bd_router);
5215 : else
5216 0 : vty_out(vty, " BDR is %pI4\n", &nbr->bd_router);
5217 :
5218 : /* Show options. */
5219 0 : if (use_json) {
5220 0 : json_object_int_add(json_neigh, "optionsCounter", nbr->options);
5221 0 : json_object_string_add(json_neigh, "optionsList",
5222 0 : ospf_options_dump(nbr->options));
5223 : } else
5224 0 : vty_out(vty, " Options %d %s\n", nbr->options,
5225 0 : ospf_options_dump(nbr->options));
5226 :
5227 : /* Show Router Dead interval timer. */
5228 0 : if (use_json) {
5229 0 : if (nbr->t_inactivity) {
5230 0 : long time_store;
5231 0 : time_store = monotime_until(&nbr->t_inactivity->u.sands,
5232 : NULL)
5233 : / 1000LL;
5234 0 : json_object_int_add(json_neigh,
5235 : "routerDeadIntervalTimerDueMsec",
5236 : time_store);
5237 : } else
5238 0 : json_object_int_add(
5239 : json_neigh,
5240 : "routerDeadIntervalTimerDueMsec", -1);
5241 : } else
5242 0 : vty_out(vty, " Dead timer due in %s\n",
5243 : ospf_timer_dump(nbr->t_inactivity, timebuf,
5244 : sizeof(timebuf)));
5245 :
5246 : /* Show Database Summary list. */
5247 0 : if (use_json)
5248 0 : json_object_int_add(json_neigh, "databaseSummaryListCounter",
5249 0 : ospf_db_summary_count(nbr));
5250 : else
5251 0 : vty_out(vty, " Database Summary List %d\n",
5252 : ospf_db_summary_count(nbr));
5253 :
5254 : /* Show Link State Request list. */
5255 0 : if (use_json)
5256 0 : json_object_int_add(json_neigh, "linkStateRequestListCounter",
5257 0 : ospf_ls_request_count(nbr));
5258 : else
5259 0 : vty_out(vty, " Link State Request List %ld\n",
5260 : ospf_ls_request_count(nbr));
5261 :
5262 : /* Show Link State Retransmission list. */
5263 0 : if (use_json)
5264 0 : json_object_int_add(json_neigh,
5265 : "linkStateRetransmissionListCounter",
5266 0 : ospf_ls_retransmit_count(nbr));
5267 : else
5268 0 : vty_out(vty, " Link State Retransmission List %ld\n",
5269 : ospf_ls_retransmit_count(nbr));
5270 :
5271 : /* Show inactivity timer thread. */
5272 0 : if (use_json) {
5273 0 : if (nbr->t_inactivity != NULL)
5274 0 : json_object_string_add(json_neigh,
5275 : "threadInactivityTimer", "on");
5276 : } else
5277 0 : vty_out(vty, " Thread Inactivity Timer %s\n",
5278 0 : nbr->t_inactivity != NULL ? "on" : "off");
5279 :
5280 : /* Show Database Description retransmission thread. */
5281 0 : if (use_json) {
5282 0 : if (nbr->t_db_desc != NULL)
5283 0 : json_object_string_add(
5284 : json_neigh,
5285 : "threadDatabaseDescriptionRetransmission",
5286 : "on");
5287 : } else
5288 0 : vty_out(vty,
5289 : " Thread Database Description Retransmision %s\n",
5290 0 : nbr->t_db_desc != NULL ? "on" : "off");
5291 :
5292 : /* Show Link State Request Retransmission thread. */
5293 0 : if (use_json) {
5294 0 : if (nbr->t_ls_req != NULL)
5295 0 : json_object_string_add(
5296 : json_neigh,
5297 : "threadLinkStateRequestRetransmission", "on");
5298 : } else
5299 0 : vty_out(vty,
5300 : " Thread Link State Request Retransmission %s\n",
5301 0 : nbr->t_ls_req != NULL ? "on" : "off");
5302 :
5303 : /* Show Link State Update Retransmission thread. */
5304 0 : if (use_json) {
5305 0 : if (nbr->t_ls_upd != NULL)
5306 0 : json_object_string_add(
5307 : json_neigh,
5308 : "threadLinkStateUpdateRetransmission",
5309 : "on");
5310 : } else
5311 0 : vty_out(vty,
5312 : " Thread Link State Update Retransmission %s\n\n",
5313 0 : nbr->t_ls_upd != NULL ? "on" : "off");
5314 :
5315 0 : if (!use_json) {
5316 0 : vty_out(vty, " Graceful restart Helper info:\n");
5317 :
5318 0 : if (OSPF_GR_IS_ACTIVE_HELPER(nbr)) {
5319 0 : vty_out(vty,
5320 : " Graceful Restart HELPER Status : Inprogress.\n");
5321 :
5322 0 : vty_out(vty,
5323 : " Graceful Restart grace period time: %d (seconds).\n",
5324 : nbr->gr_helper_info.recvd_grace_period);
5325 0 : vty_out(vty, " Graceful Restart reason: %s.\n",
5326 : ospf_restart_reason2str(
5327 0 : nbr->gr_helper_info.gr_restart_reason));
5328 : } else {
5329 0 : vty_out(vty,
5330 : " Graceful Restart HELPER Status : None\n");
5331 : }
5332 :
5333 0 : if (nbr->gr_helper_info.rejected_reason
5334 : != OSPF_HELPER_REJECTED_NONE)
5335 0 : vty_out(vty, " Helper rejected reason: %s.\n",
5336 : ospf_rejected_reason2str(
5337 : nbr->gr_helper_info.rejected_reason));
5338 :
5339 0 : if (nbr->gr_helper_info.helper_exit_reason
5340 : != OSPF_GR_HELPER_EXIT_NONE)
5341 0 : vty_out(vty, " Last helper exit reason: %s.\n\n",
5342 : ospf_exit_reason2str(
5343 : nbr->gr_helper_info.helper_exit_reason));
5344 : else
5345 0 : vty_out(vty, "\n");
5346 : } else {
5347 0 : json_object_string_add(json_neigh, "grHelperStatus",
5348 0 : OSPF_GR_IS_ACTIVE_HELPER(nbr) ?
5349 : "Inprogress"
5350 : : "None");
5351 0 : if (OSPF_GR_IS_ACTIVE_HELPER(nbr)) {
5352 0 : json_object_int_add(
5353 : json_neigh, "graceInterval",
5354 0 : nbr->gr_helper_info.recvd_grace_period);
5355 0 : json_object_string_add(
5356 : json_neigh, "grRestartReason",
5357 : ospf_restart_reason2str(
5358 0 : nbr->gr_helper_info.gr_restart_reason));
5359 : }
5360 :
5361 0 : if (nbr->gr_helper_info.rejected_reason
5362 : != OSPF_HELPER_REJECTED_NONE)
5363 0 : json_object_string_add(
5364 : json_neigh, "helperRejectReason",
5365 : ospf_rejected_reason2str(
5366 : nbr->gr_helper_info.rejected_reason));
5367 :
5368 0 : if (nbr->gr_helper_info.helper_exit_reason
5369 : != OSPF_GR_HELPER_EXIT_NONE)
5370 0 : json_object_string_add(
5371 : json_neigh, "helperExitReason",
5372 : ospf_exit_reason2str(
5373 : nbr->gr_helper_info
5374 : .helper_exit_reason));
5375 : }
5376 :
5377 0 : bfd_sess_show(vty, json_neigh, nbr->bfd_session);
5378 :
5379 0 : if (use_json)
5380 0 : json_object_array_add(json_neigh_array, json_neigh);
5381 :
5382 0 : }
5383 :
5384 0 : static int show_ip_ospf_neighbor_id_common(struct vty *vty, struct ospf *ospf,
5385 : struct in_addr *router_id,
5386 : bool use_json, uint8_t use_vrf,
5387 : bool is_detail)
5388 : {
5389 0 : struct listnode *node;
5390 0 : struct ospf_neighbor *nbr;
5391 0 : struct ospf_interface *oi;
5392 0 : json_object *json = NULL;
5393 :
5394 0 : if (use_json)
5395 0 : json = json_object_new_object();
5396 :
5397 0 : if (ospf->instance) {
5398 0 : if (use_json)
5399 0 : json_object_int_add(json, "ospfInstance",
5400 : ospf->instance);
5401 : else
5402 0 : vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
5403 : }
5404 :
5405 0 : ospf_show_vrf_name(ospf, vty, json, use_vrf);
5406 :
5407 0 : for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) {
5408 0 : nbr = ospf_nbr_lookup_by_routerid(oi->nbrs, router_id);
5409 :
5410 0 : if (!nbr)
5411 0 : continue;
5412 :
5413 0 : if (is_detail)
5414 0 : show_ip_ospf_neighbor_detail_sub(vty, oi, nbr, NULL,
5415 : json, use_json);
5416 : else
5417 0 : show_ip_ospf_neighbour_brief(vty, nbr, NULL, json,
5418 : use_json);
5419 : }
5420 :
5421 0 : if (use_json)
5422 0 : vty_json(vty, json);
5423 : else
5424 0 : vty_out(vty, "\n");
5425 :
5426 0 : return CMD_SUCCESS;
5427 : }
5428 :
5429 0 : DEFPY(show_ip_ospf_neighbor_id, show_ip_ospf_neighbor_id_cmd,
5430 : "show ip ospf neighbor A.B.C.D$router_id [detail$detail] [json$json]",
5431 : SHOW_STR IP_STR
5432 : "OSPF information\n"
5433 : "Neighbor list\n"
5434 : "Neighbor ID\n"
5435 : "Detailed output\n" JSON_STR)
5436 : {
5437 0 : struct ospf *ospf;
5438 0 : struct listnode *node;
5439 0 : int ret = CMD_SUCCESS;
5440 :
5441 0 : for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
5442 0 : if (!ospf->oi_running)
5443 0 : continue;
5444 0 : ret = show_ip_ospf_neighbor_id_common(vty, ospf, &router_id,
5445 : !!json, 0, !!detail);
5446 : }
5447 :
5448 0 : return ret;
5449 : }
5450 :
5451 0 : DEFPY(show_ip_ospf_instance_neighbor_id, show_ip_ospf_instance_neighbor_id_cmd,
5452 : "show ip ospf (1-65535)$instance neighbor A.B.C.D$router_id [detail$detail] [json$json]",
5453 : SHOW_STR IP_STR
5454 : "OSPF information\n"
5455 : "Instance ID\n"
5456 : "Neighbor list\n"
5457 : "Neighbor ID\n"
5458 : "Detailed output\n" JSON_STR)
5459 : {
5460 0 : struct ospf *ospf;
5461 :
5462 0 : if (instance != ospf_instance)
5463 : return CMD_NOT_MY_INSTANCE;
5464 :
5465 0 : ospf = ospf_lookup_instance(instance);
5466 0 : if (!ospf || !ospf->oi_running)
5467 : return CMD_SUCCESS;
5468 :
5469 0 : return show_ip_ospf_neighbor_id_common(vty, ospf, &router_id, !!json, 0,
5470 : !!detail);
5471 : }
5472 :
5473 0 : static int show_ip_ospf_neighbor_detail_common(struct vty *vty,
5474 : struct ospf *ospf,
5475 : json_object *json, bool use_json,
5476 : uint8_t use_vrf)
5477 : {
5478 0 : struct ospf_interface *oi;
5479 0 : struct listnode *node;
5480 0 : json_object *json_vrf = NULL;
5481 0 : json_object *json_nbr_sub = NULL;
5482 :
5483 0 : if (use_json) {
5484 0 : if (use_vrf)
5485 0 : json_vrf = json_object_new_object();
5486 : else
5487 : json_vrf = json;
5488 :
5489 0 : json_nbr_sub = json_object_new_object();
5490 : }
5491 :
5492 0 : if (ospf->instance) {
5493 0 : if (use_json)
5494 0 : json_object_int_add(json, "ospfInstance",
5495 : ospf->instance);
5496 : else
5497 0 : vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
5498 : }
5499 :
5500 0 : ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf);
5501 :
5502 0 : for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) {
5503 0 : struct route_node *rn;
5504 0 : struct ospf_neighbor *nbr, *prev_nbr = NULL;
5505 :
5506 0 : for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) {
5507 0 : nbr = rn->info;
5508 :
5509 0 : if (!nbr)
5510 0 : continue;
5511 :
5512 0 : if (nbr != oi->nbr_self) {
5513 0 : if (nbr->state != NSM_Down) {
5514 0 : show_ip_ospf_neighbor_detail_sub(
5515 : vty, oi, nbr, prev_nbr,
5516 : json_nbr_sub, use_json);
5517 : }
5518 : }
5519 : prev_nbr = nbr;
5520 : }
5521 : }
5522 :
5523 0 : if (use_json) {
5524 0 : json_object_object_add(json_vrf, "neighbors",
5525 : json_nbr_sub);
5526 0 : if (use_vrf)
5527 0 : json_object_object_add(json, ospf_get_name(ospf),
5528 : json_vrf);
5529 : } else
5530 0 : vty_out(vty, "\n");
5531 :
5532 0 : return CMD_SUCCESS;
5533 : }
5534 :
5535 0 : DEFUN (show_ip_ospf_neighbor_detail,
5536 : show_ip_ospf_neighbor_detail_cmd,
5537 : "show ip ospf [vrf <NAME|all>] neighbor detail [json]",
5538 : SHOW_STR
5539 : IP_STR
5540 : "OSPF information\n"
5541 : VRF_CMD_HELP_STR
5542 : "All VRFs\n"
5543 : "Neighbor list\n"
5544 : "detail of all neighbors\n"
5545 : JSON_STR)
5546 : {
5547 0 : struct ospf *ospf;
5548 0 : bool uj = use_json(argc, argv);
5549 0 : struct listnode *node = NULL;
5550 0 : char *vrf_name = NULL;
5551 0 : bool all_vrf = false;
5552 0 : int ret = CMD_SUCCESS;
5553 0 : int inst = 0;
5554 0 : int idx_vrf = 0;
5555 0 : uint8_t use_vrf = 0;
5556 0 : json_object *json = NULL;
5557 :
5558 0 : OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
5559 :
5560 0 : if (uj)
5561 0 : json = json_object_new_object();
5562 :
5563 : /* vrf input is provided could be all or specific vrf*/
5564 0 : if (vrf_name) {
5565 0 : use_vrf = 1;
5566 0 : if (all_vrf) {
5567 0 : for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
5568 0 : if (!ospf->oi_running)
5569 0 : continue;
5570 0 : ret = show_ip_ospf_neighbor_detail_common(
5571 : vty, ospf, json, uj, use_vrf);
5572 : }
5573 0 : if (uj)
5574 0 : vty_json(vty, json);
5575 :
5576 0 : return ret;
5577 : }
5578 0 : ospf = ospf_lookup_by_inst_name(inst, vrf_name);
5579 0 : if (ospf == NULL || !ospf->oi_running) {
5580 0 : if (uj)
5581 0 : json_object_free(json);
5582 0 : return CMD_SUCCESS;
5583 : }
5584 : } else {
5585 : /* Display default ospf (instance 0) info */
5586 0 : ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
5587 0 : if (ospf == NULL || !ospf->oi_running) {
5588 0 : if (uj)
5589 0 : json_object_free(json);
5590 0 : return CMD_SUCCESS;
5591 : }
5592 : }
5593 :
5594 : if (ospf) {
5595 0 : ret = show_ip_ospf_neighbor_detail_common(vty, ospf, json, uj,
5596 : use_vrf);
5597 0 : if (uj) {
5598 0 : vty_out(vty, "%s\n",
5599 : json_object_to_json_string_ext(
5600 : json, JSON_C_TO_STRING_PRETTY));
5601 : }
5602 : }
5603 :
5604 0 : if (uj)
5605 0 : json_object_free(json);
5606 :
5607 : return ret;
5608 : }
5609 :
5610 0 : DEFUN (show_ip_ospf_instance_neighbor_detail,
5611 : show_ip_ospf_instance_neighbor_detail_cmd,
5612 : "show ip ospf (1-65535) neighbor detail [json]",
5613 : SHOW_STR
5614 : IP_STR
5615 : "OSPF information\n"
5616 : "Instance ID\n"
5617 : "Neighbor list\n"
5618 : "detail of all neighbors\n"
5619 : JSON_STR)
5620 : {
5621 0 : int idx_number = 3;
5622 0 : struct ospf *ospf;
5623 0 : unsigned short instance = 0;
5624 0 : bool uj = use_json(argc, argv);
5625 0 : json_object *json = NULL;
5626 0 : int ret = CMD_SUCCESS;
5627 :
5628 0 : instance = strtoul(argv[idx_number]->arg, NULL, 10);
5629 0 : if (instance != ospf_instance)
5630 : return CMD_NOT_MY_INSTANCE;
5631 :
5632 0 : ospf = ospf_lookup_instance(instance);
5633 0 : if (!ospf || !ospf->oi_running)
5634 : return CMD_SUCCESS;
5635 :
5636 0 : if (uj)
5637 0 : json = json_object_new_object();
5638 :
5639 0 : ret = show_ip_ospf_neighbor_detail_common(vty, ospf, json, uj, 0);
5640 :
5641 0 : if (uj)
5642 0 : vty_json(vty, json);
5643 :
5644 : return ret;
5645 : }
5646 :
5647 0 : static int show_ip_ospf_neighbor_detail_all_common(struct vty *vty,
5648 : struct ospf *ospf,
5649 : json_object *json,
5650 : bool use_json,
5651 : uint8_t use_vrf)
5652 : {
5653 0 : struct listnode *node;
5654 0 : struct ospf_interface *oi;
5655 0 : json_object *json_vrf = NULL;
5656 :
5657 0 : if (use_json) {
5658 0 : if (use_vrf)
5659 0 : json_vrf = json_object_new_object();
5660 : else
5661 : json_vrf = json;
5662 : }
5663 :
5664 0 : if (ospf->instance) {
5665 0 : if (use_json)
5666 0 : json_object_int_add(json, "ospfInstance",
5667 : ospf->instance);
5668 : else
5669 0 : vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
5670 : }
5671 :
5672 0 : ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf);
5673 :
5674 0 : for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) {
5675 0 : struct route_node *rn;
5676 0 : struct ospf_neighbor *nbr, *prev_nbr = NULL;
5677 0 : struct ospf_nbr_nbma *nbr_nbma;
5678 :
5679 0 : for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) {
5680 0 : nbr = rn->info;
5681 :
5682 0 : if (!nbr)
5683 0 : continue;
5684 :
5685 0 : if (nbr != oi->nbr_self)
5686 0 : if (nbr->state != NSM_Down)
5687 0 : show_ip_ospf_neighbor_detail_sub(
5688 : vty, oi, rn->info, prev_nbr,
5689 : json_vrf, use_json);
5690 : prev_nbr = nbr;
5691 : }
5692 :
5693 0 : if (oi->type != OSPF_IFTYPE_NBMA)
5694 0 : continue;
5695 :
5696 0 : struct listnode *nd;
5697 :
5698 0 : for (ALL_LIST_ELEMENTS_RO(oi->nbr_nbma, nd, nbr_nbma)) {
5699 0 : if (nbr_nbma->nbr == NULL ||
5700 0 : nbr_nbma->nbr->state == NSM_Down)
5701 0 : show_ip_ospf_nbr_nbma_detail_sub(
5702 : vty, oi, nbr_nbma, use_json, json_vrf);
5703 : }
5704 : }
5705 :
5706 0 : if (use_json) {
5707 0 : if (use_vrf)
5708 0 : json_object_object_add(json, ospf_get_name(ospf),
5709 : json_vrf);
5710 : } else {
5711 0 : vty_out(vty, "\n");
5712 : }
5713 :
5714 0 : return CMD_SUCCESS;
5715 : }
5716 :
5717 0 : DEFUN (show_ip_ospf_neighbor_detail_all,
5718 : show_ip_ospf_neighbor_detail_all_cmd,
5719 : "show ip ospf [vrf <NAME|all>] neighbor detail all [json]",
5720 : SHOW_STR
5721 : IP_STR
5722 : "OSPF information\n"
5723 : VRF_CMD_HELP_STR
5724 : "All VRFs\n"
5725 : "Neighbor list\n"
5726 : "detail of all neighbors\n"
5727 : "include down status neighbor\n"
5728 : JSON_STR)
5729 : {
5730 0 : struct ospf *ospf;
5731 0 : bool uj = use_json(argc, argv);
5732 0 : struct listnode *node = NULL;
5733 0 : char *vrf_name = NULL;
5734 0 : bool all_vrf = false;
5735 0 : int ret = CMD_SUCCESS;
5736 0 : int inst = 0;
5737 0 : int idx_vrf = 0;
5738 0 : uint8_t use_vrf = 0;
5739 0 : json_object *json = NULL;
5740 :
5741 0 : OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
5742 :
5743 0 : if (uj)
5744 0 : json = json_object_new_object();
5745 :
5746 : /* vrf input is provided could be all or specific vrf*/
5747 0 : if (vrf_name) {
5748 0 : use_vrf = 1;
5749 0 : if (all_vrf) {
5750 0 : for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
5751 0 : if (!ospf->oi_running)
5752 0 : continue;
5753 0 : ret = show_ip_ospf_neighbor_detail_all_common(
5754 : vty, ospf, json, uj, use_vrf);
5755 : }
5756 :
5757 0 : if (uj)
5758 0 : vty_json(vty, json);
5759 :
5760 0 : return ret;
5761 : }
5762 0 : ospf = ospf_lookup_by_inst_name(inst, vrf_name);
5763 0 : if (ospf == NULL || !ospf->oi_running) {
5764 0 : if (uj)
5765 0 : json_object_free(json);
5766 0 : return CMD_SUCCESS;
5767 : }
5768 : } else {
5769 : /* Display default ospf (instance 0) info */
5770 0 : ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
5771 0 : if (ospf == NULL || !ospf->oi_running) {
5772 0 : if (uj)
5773 0 : json_object_free(json);
5774 0 : return CMD_SUCCESS;
5775 : }
5776 : }
5777 :
5778 : if (ospf) {
5779 0 : ret = show_ip_ospf_neighbor_detail_all_common(vty, ospf, json,
5780 : uj, use_vrf);
5781 0 : if (uj) {
5782 0 : vty_out(vty, "%s\n",
5783 : json_object_to_json_string_ext(
5784 : json, JSON_C_TO_STRING_PRETTY));
5785 : }
5786 : }
5787 :
5788 0 : if (uj)
5789 0 : json_object_free(json);
5790 :
5791 : return ret;
5792 : }
5793 :
5794 0 : DEFUN (show_ip_ospf_instance_neighbor_detail_all,
5795 : show_ip_ospf_instance_neighbor_detail_all_cmd,
5796 : "show ip ospf (1-65535) neighbor detail all [json]",
5797 : SHOW_STR
5798 : IP_STR
5799 : "OSPF information\n"
5800 : "Instance ID\n"
5801 : "Neighbor list\n"
5802 : "detail of all neighbors\n"
5803 : "include down status neighbor\n"
5804 : JSON_STR)
5805 : {
5806 0 : int idx_number = 3;
5807 0 : struct ospf *ospf;
5808 0 : unsigned short instance = 0;
5809 0 : bool uj = use_json(argc, argv);
5810 0 : json_object *json = NULL;
5811 0 : int ret = CMD_SUCCESS;
5812 :
5813 0 : instance = strtoul(argv[idx_number]->arg, NULL, 10);
5814 0 : if (instance != ospf_instance)
5815 : return CMD_NOT_MY_INSTANCE;
5816 :
5817 0 : ospf = ospf_lookup_instance(instance);
5818 0 : if (!ospf || !ospf->oi_running)
5819 : return CMD_SUCCESS;
5820 :
5821 0 : if (uj)
5822 0 : json = json_object_new_object();
5823 :
5824 0 : ret = show_ip_ospf_neighbor_detail_all_common(vty, ospf, json, uj, 0);
5825 :
5826 0 : if (uj)
5827 0 : vty_json(vty, json);
5828 :
5829 : return ret;
5830 : }
5831 :
5832 0 : static int show_ip_ospf_neighbor_int_detail_common(struct vty *vty,
5833 : struct ospf *ospf,
5834 : int arg_base,
5835 : struct cmd_token **argv,
5836 : bool use_json)
5837 : {
5838 0 : struct ospf_interface *oi;
5839 0 : struct interface *ifp;
5840 0 : struct route_node *rn, *nrn;
5841 0 : struct ospf_neighbor *nbr;
5842 0 : json_object *json = NULL;
5843 :
5844 0 : if (use_json)
5845 0 : json = json_object_new_object();
5846 :
5847 0 : if (ospf->instance) {
5848 0 : if (use_json)
5849 0 : json_object_int_add(json, "ospfInstance",
5850 : ospf->instance);
5851 : else
5852 0 : vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
5853 : }
5854 :
5855 0 : ifp = if_lookup_by_name(argv[arg_base]->arg, ospf->vrf_id);
5856 0 : if (!ifp) {
5857 0 : if (!use_json)
5858 0 : vty_out(vty, "No such interface.\n");
5859 : else {
5860 0 : vty_out(vty, "{}\n");
5861 0 : json_object_free(json);
5862 : }
5863 0 : return CMD_WARNING;
5864 : }
5865 :
5866 0 : for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) {
5867 0 : oi = rn->info;
5868 :
5869 0 : if (!oi)
5870 0 : continue;
5871 :
5872 0 : for (nrn = route_top(oi->nbrs); nrn; nrn = route_next(nrn)) {
5873 0 : nbr = nrn->info;
5874 :
5875 0 : if (!nbr)
5876 0 : continue;
5877 :
5878 0 : if (nbr == oi->nbr_self)
5879 0 : continue;
5880 :
5881 0 : if (nbr->state == NSM_Down)
5882 0 : continue;
5883 :
5884 0 : show_ip_ospf_neighbor_detail_sub(vty, oi, nbr, NULL,
5885 : json, use_json);
5886 : }
5887 : }
5888 :
5889 0 : if (use_json)
5890 0 : vty_json(vty, json);
5891 : else
5892 0 : vty_out(vty, "\n");
5893 :
5894 : return CMD_SUCCESS;
5895 : }
5896 :
5897 0 : DEFUN (show_ip_ospf_neighbor_int_detail,
5898 : show_ip_ospf_neighbor_int_detail_cmd,
5899 : "show ip ospf neighbor IFNAME detail [json]",
5900 : SHOW_STR
5901 : IP_STR
5902 : "OSPF information\n"
5903 : "Neighbor list\n"
5904 : "Interface name\n"
5905 : "detail of all neighbors\n"
5906 : JSON_STR)
5907 : {
5908 0 : struct ospf *ospf;
5909 0 : bool uj = use_json(argc, argv);
5910 0 : struct listnode *node = NULL;
5911 0 : int ret = CMD_SUCCESS;
5912 0 : bool ospf_output = false;
5913 :
5914 0 : for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
5915 0 : if (!ospf->oi_running)
5916 0 : continue;
5917 0 : ospf_output = true;
5918 0 : ret = show_ip_ospf_neighbor_int_detail_common(vty, ospf, 4,
5919 : argv, uj);
5920 : }
5921 :
5922 0 : if (!ospf_output)
5923 0 : vty_out(vty, "%% OSPF instance not found\n");
5924 :
5925 0 : return ret;
5926 : }
5927 :
5928 0 : DEFUN (show_ip_ospf_instance_neighbor_int_detail,
5929 : show_ip_ospf_instance_neighbor_int_detail_cmd,
5930 : "show ip ospf (1-65535) neighbor IFNAME detail [json]",
5931 : SHOW_STR
5932 : IP_STR
5933 : "OSPF information\n"
5934 : "Instance ID\n"
5935 : "Neighbor list\n"
5936 : "Interface name\n"
5937 : "detail of all neighbors\n"
5938 : JSON_STR)
5939 : {
5940 0 : int idx_number = 3;
5941 0 : int idx_ifname = 5;
5942 0 : struct ospf *ospf;
5943 0 : unsigned short instance = 0;
5944 0 : bool uj = use_json(argc, argv);
5945 :
5946 0 : instance = strtoul(argv[idx_number]->arg, NULL, 10);
5947 0 : if (instance != ospf_instance)
5948 : return CMD_NOT_MY_INSTANCE;
5949 :
5950 0 : ospf = ospf_lookup_instance(instance);
5951 0 : if (!ospf || !ospf->oi_running)
5952 : return CMD_SUCCESS;
5953 :
5954 0 : return show_ip_ospf_neighbor_int_detail_common(vty, ospf, idx_ifname,
5955 : argv, uj);
5956 : }
5957 :
5958 : /* Show functions */
5959 0 : static int show_lsa_summary(struct vty *vty, struct ospf_lsa *lsa, int self,
5960 : json_object *json_lsa)
5961 : {
5962 0 : struct router_lsa *rl;
5963 0 : struct summary_lsa *sl;
5964 0 : struct as_external_lsa *asel;
5965 0 : struct prefix_ipv4 p;
5966 :
5967 0 : if (lsa != NULL) {
5968 : /* If self option is set, check LSA self flag. */
5969 0 : if (self == 0 || IS_LSA_SELF(lsa)) {
5970 :
5971 0 : if (!json_lsa) {
5972 : /* LSA common part show. */
5973 0 : vty_out(vty, "%-15pI4",
5974 0 : &lsa->data->id);
5975 0 : vty_out(vty, "%-15pI4 %4d 0x%08lx 0x%04x",
5976 0 : &lsa->data->adv_router, LS_AGE(lsa),
5977 0 : (unsigned long)ntohl(
5978 : lsa->data->ls_seqnum),
5979 0 : ntohs(lsa->data->checksum));
5980 : } else {
5981 0 : char seqnum[10];
5982 0 : char checksum[10];
5983 :
5984 0 : snprintf(seqnum, sizeof(seqnum), "%x",
5985 0 : ntohl(lsa->data->ls_seqnum));
5986 0 : snprintf(checksum, sizeof(checksum), "%x",
5987 0 : ntohs(lsa->data->checksum));
5988 0 : json_object_string_addf(json_lsa, "lsId",
5989 0 : "%pI4", &lsa->data->id);
5990 0 : json_object_string_addf(
5991 : json_lsa, "advertisedRouter", "%pI4",
5992 0 : &lsa->data->adv_router);
5993 0 : json_object_int_add(json_lsa, "lsaAge",
5994 0 : LS_AGE(lsa));
5995 0 : json_object_string_add(
5996 : json_lsa, "sequenceNumber", seqnum);
5997 0 : json_object_string_add(json_lsa, "checksum",
5998 : checksum);
5999 : }
6000 :
6001 : /* LSA specific part show. */
6002 0 : switch (lsa->data->type) {
6003 0 : case OSPF_ROUTER_LSA:
6004 0 : rl = (struct router_lsa *)lsa->data;
6005 :
6006 0 : if (!json_lsa)
6007 0 : vty_out(vty, " %-d", ntohs(rl->links));
6008 : else
6009 0 : json_object_int_add(json_lsa,
6010 : "numOfRouterLinks",
6011 0 : ntohs(rl->links));
6012 : break;
6013 0 : case OSPF_SUMMARY_LSA:
6014 0 : sl = (struct summary_lsa *)lsa->data;
6015 :
6016 0 : p.family = AF_INET;
6017 0 : p.prefix = sl->header.id;
6018 0 : p.prefixlen = ip_masklen(sl->mask);
6019 0 : apply_mask_ipv4(&p);
6020 :
6021 0 : if (!json_lsa)
6022 0 : vty_out(vty, " %pFX", &p);
6023 : else {
6024 0 : json_object_string_addf(
6025 : json_lsa, "summaryAddress",
6026 : "%pFX", &p);
6027 : }
6028 : break;
6029 0 : case OSPF_AS_EXTERNAL_LSA:
6030 : case OSPF_AS_NSSA_LSA:
6031 0 : asel = (struct as_external_lsa *)lsa->data;
6032 :
6033 0 : p.family = AF_INET;
6034 0 : p.prefix = asel->header.id;
6035 0 : p.prefixlen = ip_masklen(asel->mask);
6036 0 : apply_mask_ipv4(&p);
6037 :
6038 0 : if (!json_lsa)
6039 0 : vty_out(vty, " %s %pFX [0x%lx]",
6040 0 : IS_EXTERNAL_METRIC(
6041 : asel->e[0].tos)
6042 0 : ? "E2"
6043 : : "E1",
6044 : &p,
6045 0 : (unsigned long)ntohl(
6046 : asel->e[0].route_tag));
6047 : else {
6048 0 : json_object_string_add(
6049 : json_lsa, "metricType",
6050 0 : IS_EXTERNAL_METRIC(
6051 : asel->e[0].tos)
6052 0 : ? "E2"
6053 : : "E1");
6054 0 : json_object_string_addf(
6055 : json_lsa, "route", "%pFX", &p);
6056 0 : json_object_int_add(
6057 : json_lsa, "tag",
6058 0 : (unsigned long)ntohl(
6059 : asel->e[0].route_tag));
6060 : }
6061 : break;
6062 : case OSPF_NETWORK_LSA:
6063 : case OSPF_ASBR_SUMMARY_LSA:
6064 : case OSPF_OPAQUE_LINK_LSA:
6065 : case OSPF_OPAQUE_AREA_LSA:
6066 : case OSPF_OPAQUE_AS_LSA:
6067 : default:
6068 : break;
6069 : }
6070 :
6071 0 : if (!json_lsa)
6072 0 : vty_out(vty, "\n");
6073 : }
6074 :
6075 0 : return 1;
6076 : }
6077 :
6078 : return 0;
6079 : }
6080 :
6081 : static const char *const show_database_desc[] = {
6082 : "unknown",
6083 : "Router Link States",
6084 : "Net Link States",
6085 : "Summary Link States",
6086 : "ASBR-Summary Link States",
6087 : "AS External Link States",
6088 : "Group Membership LSA",
6089 : "NSSA-external Link States",
6090 : "Type-8 LSA",
6091 : "Link-Local Opaque-LSA",
6092 : "Area-Local Opaque-LSA",
6093 : "AS-external Opaque-LSA",
6094 : };
6095 :
6096 : static const char * const show_database_desc_json[] = {
6097 : "unknown",
6098 : "routerLinkStates",
6099 : "networkLinkStates",
6100 : "summaryLinkStates",
6101 : "asbrSummaryLinkStates",
6102 : "asExternalLinkStates",
6103 : "groupMembershipLsa",
6104 : "nssaExternalLinkStates",
6105 : "type8Lsa",
6106 : "linkLocalOpaqueLsa",
6107 : "areaLocalOpaqueLsa",
6108 : "asExternalOpaqueLsa",
6109 : };
6110 :
6111 : static const char *const show_database_desc_count_json[] = {
6112 : "unknownCount",
6113 : "routerLinkStatesCount",
6114 : "networkLinkStatesCount",
6115 : "summaryLinkStatesCount",
6116 : "asbrSummaryLinkStatesCount",
6117 : "asExternalLinkStatesCount",
6118 : "groupMembershipLsaCount",
6119 : "nssaExternalLinkStatesCount",
6120 : "type8LsaCount",
6121 : "linkLocalOpaqueLsaCount",
6122 : "areaLocalOpaqueLsaCount",
6123 : "asExternalOpaqueLsaCount",
6124 : };
6125 :
6126 : static const char *const show_database_header[] = {
6127 : "",
6128 : "Link ID ADV Router Age Seq# CkSum Link count",
6129 : "Link ID ADV Router Age Seq# CkSum",
6130 : "Link ID ADV Router Age Seq# CkSum Route",
6131 : "Link ID ADV Router Age Seq# CkSum",
6132 : "Link ID ADV Router Age Seq# CkSum Route",
6133 : " --- header for Group Member ----",
6134 : "Link ID ADV Router Age Seq# CkSum Route",
6135 : " --- type-8 ---",
6136 : "Opaque-Type/Id ADV Router Age Seq# CkSum",
6137 : "Opaque-Type/Id ADV Router Age Seq# CkSum",
6138 : "Opaque-Type/Id ADV Router Age Seq# CkSum",
6139 : };
6140 :
6141 0 : static void show_ip_ospf_database_header(struct vty *vty, struct ospf_lsa *lsa,
6142 : json_object *json)
6143 : {
6144 0 : struct router_lsa *rlsa = (struct router_lsa *)lsa->data;
6145 :
6146 0 : if (!json) {
6147 0 : vty_out(vty, " LS age: %d\n", LS_AGE(lsa));
6148 0 : vty_out(vty, " Options: 0x%-2x : %s\n", lsa->data->options,
6149 0 : ospf_options_dump(lsa->data->options));
6150 0 : vty_out(vty, " LS Flags: 0x%-2x %s\n", lsa->flags,
6151 0 : ((lsa->flags & OSPF_LSA_LOCAL_XLT)
6152 : ? "(Translated from Type-7)"
6153 : : ""));
6154 :
6155 0 : if (lsa->data->type == OSPF_ROUTER_LSA) {
6156 0 : vty_out(vty, " Flags: 0x%x", rlsa->flags);
6157 :
6158 0 : if (rlsa->flags)
6159 0 : vty_out(vty, " :%s%s%s%s",
6160 : IS_ROUTER_LSA_BORDER(rlsa) ? " ABR"
6161 : : "",
6162 : IS_ROUTER_LSA_EXTERNAL(rlsa) ? " ASBR"
6163 : : "",
6164 : IS_ROUTER_LSA_VIRTUAL(rlsa)
6165 : ? " VL-endpoint"
6166 : : "",
6167 : IS_ROUTER_LSA_SHORTCUT(rlsa)
6168 : ? " Shortcut"
6169 : : "");
6170 :
6171 0 : vty_out(vty, "\n");
6172 : }
6173 0 : vty_out(vty, " LS Type: %s\n",
6174 0 : lookup_msg(ospf_lsa_type_msg, lsa->data->type, NULL));
6175 0 : vty_out(vty, " Link State ID: %pI4 %s\n",
6176 0 : &lsa->data->id,
6177 0 : lookup_msg(ospf_link_state_id_type_msg, lsa->data->type,
6178 : NULL));
6179 0 : vty_out(vty, " Advertising Router: %pI4\n",
6180 0 : &lsa->data->adv_router);
6181 0 : vty_out(vty, " LS Seq Number: %08lx\n",
6182 0 : (unsigned long)ntohl(lsa->data->ls_seqnum));
6183 0 : vty_out(vty, " Checksum: 0x%04x\n",
6184 0 : ntohs(lsa->data->checksum));
6185 0 : vty_out(vty, " Length: %d\n\n", ntohs(lsa->data->length));
6186 : } else {
6187 0 : char seqnum[10];
6188 0 : char checksum[10];
6189 :
6190 0 : snprintf(seqnum, 10, "%x", ntohl(lsa->data->ls_seqnum));
6191 0 : snprintf(checksum, 10, "%x", ntohs(lsa->data->checksum));
6192 :
6193 0 : json_object_int_add(json, "lsaAge", LS_AGE(lsa));
6194 0 : json_object_string_add(json, "options",
6195 0 : ospf_options_dump(lsa->data->options));
6196 0 : json_object_int_add(json, "lsaFlags", lsa->flags);
6197 :
6198 0 : if (lsa->flags & OSPF_LSA_LOCAL_XLT)
6199 0 : json_object_boolean_true_add(json,
6200 : "translatedFromType7");
6201 :
6202 0 : if (lsa->data->type == OSPF_ROUTER_LSA) {
6203 0 : json_object_int_add(json, "flags", rlsa->flags);
6204 :
6205 0 : if (rlsa->flags) {
6206 0 : if (IS_ROUTER_LSA_BORDER(rlsa))
6207 0 : json_object_boolean_true_add(json,
6208 : "abr");
6209 0 : if (IS_ROUTER_LSA_EXTERNAL(rlsa))
6210 0 : json_object_boolean_true_add(json,
6211 : "asbr");
6212 0 : if (IS_ROUTER_LSA_VIRTUAL(rlsa))
6213 0 : json_object_boolean_true_add(
6214 : json, "vlEndpoint");
6215 0 : if (IS_ROUTER_LSA_SHORTCUT(rlsa))
6216 0 : json_object_boolean_true_add(
6217 : json, "shortcut");
6218 : }
6219 : }
6220 :
6221 0 : json_object_string_add(
6222 : json, "lsaType",
6223 0 : lookup_msg(ospf_lsa_type_msg, lsa->data->type, NULL));
6224 0 : json_object_string_addf(json, "linkStateId", "%pI4",
6225 0 : &lsa->data->id);
6226 0 : json_object_string_addf(json, "advertisingRouter", "%pI4",
6227 0 : &lsa->data->adv_router);
6228 0 : json_object_string_add(json, "lsaSeqNumber", seqnum);
6229 0 : json_object_string_add(json, "checksum", checksum);
6230 0 : json_object_int_add(json, "length", ntohs(lsa->data->length));
6231 : }
6232 0 : }
6233 :
6234 : static const char *const link_type_desc[] = {
6235 : "(null)",
6236 : "another Router (point-to-point)",
6237 : "a Transit Network",
6238 : "Stub Network",
6239 : "a Virtual Link",
6240 : };
6241 :
6242 : static const char *const link_id_desc[] = {
6243 : "(null)", "Neighboring Router ID", "Designated Router address",
6244 : "Net", "Neighboring Router ID",
6245 : };
6246 :
6247 : static const char *const link_data_desc[] = {
6248 : "(null)", "Router Interface address", "Router Interface address",
6249 : "Network Mask", "Router Interface address",
6250 : };
6251 :
6252 : static const char *const link_id_desc_json[] = {
6253 : "null", "neighborRouterId", "designatedRouterAddress",
6254 : "networkAddress", "neighborRouterId",
6255 : };
6256 :
6257 : static const char *const link_data_desc_json[] = {
6258 : "null", "routerInterfaceAddress", "routerInterfaceAddress",
6259 : "networkMask", "routerInterfaceAddress",
6260 : };
6261 :
6262 : /* Show router-LSA each Link information. */
6263 0 : static void show_ip_ospf_database_router_links(struct vty *vty,
6264 : struct router_lsa *rl,
6265 : json_object *json)
6266 : {
6267 0 : int len, type;
6268 0 : unsigned short i;
6269 0 : json_object *json_links = NULL;
6270 0 : json_object *json_link = NULL;
6271 0 : int metric = 0;
6272 0 : char buf[PREFIX_STRLEN];
6273 :
6274 0 : if (json)
6275 0 : json_links = json_object_new_object();
6276 :
6277 0 : len = ntohs(rl->header.length) - 4;
6278 0 : for (i = 0; i < ntohs(rl->links) && len > 0; len -= 12, i++) {
6279 0 : type = rl->link[i].type;
6280 :
6281 0 : if (json) {
6282 0 : char link[16];
6283 :
6284 0 : snprintf(link, sizeof(link), "link%u", i);
6285 0 : json_link = json_object_new_object();
6286 0 : json_object_string_add(json_link, "linkType",
6287 0 : link_type_desc[type]);
6288 0 : json_object_string_add(json_link,
6289 0 : link_id_desc_json[type],
6290 : inet_ntop(AF_INET,
6291 0 : &rl->link[i].link_id,
6292 : buf, sizeof(buf)));
6293 0 : json_object_string_add(
6294 0 : json_link, link_data_desc_json[type],
6295 0 : inet_ntop(AF_INET, &rl->link[i].link_data,
6296 : buf, sizeof(buf)));
6297 0 : json_object_int_add(json_link, "numOfTosMetrics",
6298 : metric);
6299 0 : json_object_int_add(json_link, "tos0Metric",
6300 0 : ntohs(rl->link[i].metric));
6301 0 : json_object_object_add(json_links, link, json_link);
6302 : } else {
6303 0 : vty_out(vty, " Link connected to: %s\n",
6304 0 : link_type_desc[type]);
6305 0 : vty_out(vty, " (Link ID) %s: %pI4\n",
6306 0 : link_id_desc[type],
6307 : &rl->link[i].link_id);
6308 0 : vty_out(vty, " (Link Data) %s: %pI4\n",
6309 0 : link_data_desc[type],
6310 : &rl->link[i].link_data);
6311 0 : vty_out(vty, " Number of TOS metrics: 0\n");
6312 0 : vty_out(vty, " TOS 0 Metric: %d\n",
6313 0 : ntohs(rl->link[i].metric));
6314 0 : vty_out(vty, "\n");
6315 : }
6316 : }
6317 0 : if (json)
6318 0 : json_object_object_add(json, "routerLinks", json_links);
6319 0 : }
6320 :
6321 : /* Show router-LSA detail information. */
6322 0 : static int show_router_lsa_detail(struct vty *vty, struct ospf_lsa *lsa,
6323 : json_object *json)
6324 : {
6325 0 : if (lsa != NULL) {
6326 0 : struct router_lsa *rl = (struct router_lsa *)lsa->data;
6327 :
6328 0 : show_ip_ospf_database_header(vty, lsa, json);
6329 :
6330 0 : if (!json)
6331 0 : vty_out(vty, " Number of Links: %d\n\n",
6332 0 : ntohs(rl->links));
6333 : else
6334 0 : json_object_int_add(json, "numOfLinks",
6335 0 : ntohs(rl->links));
6336 :
6337 0 : show_ip_ospf_database_router_links(vty, rl, json);
6338 :
6339 0 : if (!json)
6340 0 : vty_out(vty, "\n");
6341 : }
6342 :
6343 0 : return 0;
6344 : }
6345 :
6346 : /* Show network-LSA detail information. */
6347 0 : static int show_network_lsa_detail(struct vty *vty, struct ospf_lsa *lsa,
6348 : json_object *json)
6349 : {
6350 0 : int length, i;
6351 0 : char buf[PREFIX_STRLEN];
6352 0 : json_object *json_attached_rt = NULL;
6353 0 : json_object *json_router = NULL;
6354 :
6355 0 : if (json)
6356 0 : json_attached_rt = json_object_new_object();
6357 :
6358 0 : if (lsa != NULL) {
6359 0 : struct network_lsa *nl = (struct network_lsa *)lsa->data;
6360 0 : struct in_addr *addr;
6361 :
6362 0 : show_ip_ospf_database_header(vty, lsa, json);
6363 :
6364 0 : if (!json)
6365 0 : vty_out(vty, " Network Mask: /%d\n",
6366 0 : ip_masklen(nl->mask));
6367 : else
6368 0 : json_object_int_add(json, "networkMask",
6369 0 : ip_masklen(nl->mask));
6370 :
6371 0 : length = lsa->size - OSPF_LSA_HEADER_SIZE - 4;
6372 0 : addr = &nl->routers[0];
6373 0 : for (i = 0; length > 0 && addr;
6374 0 : length -= 4, addr = &nl->routers[++i])
6375 0 : if (!json) {
6376 0 : vty_out(vty, " Attached Router: %pI4\n",
6377 : addr);
6378 0 : vty_out(vty, "\n");
6379 : } else {
6380 0 : json_router = json_object_new_object();
6381 0 : json_object_string_add(
6382 : json_router, "attachedRouterId",
6383 : inet_ntop(AF_INET, addr, buf,
6384 : sizeof(buf)));
6385 0 : json_object_object_add(json_attached_rt,
6386 : inet_ntop(AF_INET, addr,
6387 : buf,
6388 : sizeof(buf)),
6389 : json_router);
6390 : }
6391 : }
6392 :
6393 0 : if (json)
6394 0 : json_object_object_add(json, "attchedRouters",
6395 : json_attached_rt);
6396 :
6397 0 : return 0;
6398 : }
6399 :
6400 : /* Show summary-LSA detail information. */
6401 0 : static int show_summary_lsa_detail(struct vty *vty, struct ospf_lsa *lsa,
6402 : json_object *json)
6403 : {
6404 0 : if (lsa != NULL) {
6405 0 : struct summary_lsa *sl = (struct summary_lsa *)lsa->data;
6406 :
6407 0 : show_ip_ospf_database_header(vty, lsa, json);
6408 :
6409 0 : if (!json) {
6410 0 : vty_out(vty, " Network Mask: /%d\n",
6411 0 : ip_masklen(sl->mask));
6412 0 : vty_out(vty, " TOS: 0 Metric: %d\n",
6413 0 : GET_METRIC(sl->metric));
6414 0 : vty_out(vty, "\n");
6415 : } else {
6416 0 : json_object_int_add(json, "networkMask",
6417 0 : ip_masklen(sl->mask));
6418 0 : json_object_int_add(json, "tos0Metric",
6419 0 : GET_METRIC(sl->metric));
6420 : }
6421 : }
6422 :
6423 0 : return 0;
6424 : }
6425 :
6426 : /* Show summary-ASBR-LSA detail information. */
6427 0 : static int show_summary_asbr_lsa_detail(struct vty *vty, struct ospf_lsa *lsa,
6428 : json_object *json)
6429 : {
6430 0 : if (lsa != NULL) {
6431 0 : struct summary_lsa *sl = (struct summary_lsa *)lsa->data;
6432 :
6433 0 : show_ip_ospf_database_header(vty, lsa, json);
6434 :
6435 0 : if (!json) {
6436 0 : vty_out(vty, " Network Mask: /%d\n",
6437 0 : ip_masklen(sl->mask));
6438 0 : vty_out(vty, " TOS: 0 Metric: %d\n",
6439 0 : GET_METRIC(sl->metric));
6440 0 : vty_out(vty, "\n");
6441 : } else {
6442 0 : json_object_int_add(json, "networkMask",
6443 0 : ip_masklen(sl->mask));
6444 0 : json_object_int_add(json, "tos0Metric",
6445 0 : GET_METRIC(sl->metric));
6446 : }
6447 : }
6448 :
6449 0 : return 0;
6450 : }
6451 :
6452 : /* Show AS-external-LSA detail information. */
6453 0 : static int show_as_external_lsa_detail(struct vty *vty, struct ospf_lsa *lsa,
6454 : json_object *json)
6455 : {
6456 0 : int tos = 0;
6457 :
6458 0 : if (lsa != NULL) {
6459 0 : struct as_external_lsa *al =
6460 : (struct as_external_lsa *)lsa->data;
6461 :
6462 0 : show_ip_ospf_database_header(vty, lsa, json);
6463 :
6464 0 : if (!json) {
6465 0 : vty_out(vty, " Network Mask: /%d\n",
6466 0 : ip_masklen(al->mask));
6467 0 : vty_out(vty, " Metric Type: %s\n",
6468 0 : IS_EXTERNAL_METRIC(al->e[0].tos)
6469 0 : ? "2 (Larger than any link state path)"
6470 : : "1");
6471 0 : vty_out(vty, " TOS: 0\n");
6472 0 : vty_out(vty, " Metric: %d\n",
6473 0 : GET_METRIC(al->e[0].metric));
6474 0 : vty_out(vty, " Forward Address: %pI4\n",
6475 : &al->e[0].fwd_addr);
6476 0 : vty_out(vty,
6477 : " External Route Tag: %" ROUTE_TAG_PRI "\n\n",
6478 0 : (route_tag_t)ntohl(al->e[0].route_tag));
6479 : } else {
6480 0 : json_object_int_add(json, "networkMask",
6481 0 : ip_masklen(al->mask));
6482 0 : json_object_string_add(
6483 : json, "metricType",
6484 0 : IS_EXTERNAL_METRIC(al->e[0].tos)
6485 0 : ? "E2 (Larger than any link state path)"
6486 : : "E1");
6487 0 : json_object_int_add(json, "tos", tos);
6488 0 : json_object_int_add(json, "metric",
6489 0 : GET_METRIC(al->e[0].metric));
6490 0 : json_object_string_addf(json, "forwardAddress", "%pI4",
6491 : &(al->e[0].fwd_addr));
6492 0 : json_object_int_add(
6493 : json, "externalRouteTag",
6494 0 : (route_tag_t)ntohl(al->e[0].route_tag));
6495 : }
6496 : }
6497 :
6498 0 : return 0;
6499 : }
6500 :
6501 : /* Show AS-NSSA-LSA detail information. */
6502 0 : static int show_as_nssa_lsa_detail(struct vty *vty, struct ospf_lsa *lsa,
6503 : json_object *json)
6504 : {
6505 0 : int tos = 0;
6506 :
6507 0 : if (lsa != NULL) {
6508 0 : struct as_external_lsa *al =
6509 : (struct as_external_lsa *)lsa->data;
6510 :
6511 0 : show_ip_ospf_database_header(vty, lsa, json);
6512 :
6513 0 : if (!json) {
6514 0 : vty_out(vty, " Network Mask: /%d\n",
6515 0 : ip_masklen(al->mask));
6516 0 : vty_out(vty, " Metric Type: %s\n",
6517 0 : IS_EXTERNAL_METRIC(al->e[0].tos)
6518 0 : ? "2 (Larger than any link state path)"
6519 : : "1");
6520 0 : vty_out(vty, " TOS: 0\n");
6521 0 : vty_out(vty, " Metric: %d\n",
6522 0 : GET_METRIC(al->e[0].metric));
6523 0 : vty_out(vty, " NSSA: Forward Address: %pI4\n",
6524 : &al->e[0].fwd_addr);
6525 0 : vty_out(vty,
6526 : " External Route Tag: %" ROUTE_TAG_PRI
6527 : "\n\n",
6528 0 : (route_tag_t)ntohl(al->e[0].route_tag));
6529 : } else {
6530 0 : json_object_int_add(json, "networkMask",
6531 0 : ip_masklen(al->mask));
6532 0 : json_object_string_add(
6533 : json, "metricType",
6534 0 : IS_EXTERNAL_METRIC(al->e[0].tos)
6535 0 : ? "E2 (Larger than any link state path)"
6536 : : "E1");
6537 0 : json_object_int_add(json, "tos", tos);
6538 0 : json_object_int_add(json, "metric",
6539 0 : GET_METRIC(al->e[0].metric));
6540 0 : json_object_string_addf(json, "nssaForwardAddress",
6541 : "%pI4", &al->e[0].fwd_addr);
6542 0 : json_object_int_add(
6543 : json, "externalRouteTag",
6544 0 : (route_tag_t)ntohl(al->e[0].route_tag));
6545 : }
6546 : }
6547 :
6548 0 : return 0;
6549 : }
6550 :
6551 0 : static int show_func_dummy(struct vty *vty, struct ospf_lsa *lsa,
6552 : json_object *json)
6553 : {
6554 0 : return 0;
6555 : }
6556 :
6557 0 : static int show_opaque_lsa_detail(struct vty *vty, struct ospf_lsa *lsa,
6558 : json_object *json)
6559 : {
6560 0 : if (lsa != NULL) {
6561 0 : show_ip_ospf_database_header(vty, lsa, json);
6562 0 : show_opaque_info_detail(vty, lsa, json);
6563 0 : if (!json)
6564 0 : vty_out(vty, "\n");
6565 : }
6566 0 : return 0;
6567 : }
6568 :
6569 : int (*show_function[])(struct vty *, struct ospf_lsa *, json_object *) = {
6570 : NULL,
6571 : show_router_lsa_detail,
6572 : show_network_lsa_detail,
6573 : show_summary_lsa_detail,
6574 : show_summary_asbr_lsa_detail,
6575 : show_as_external_lsa_detail,
6576 : show_func_dummy,
6577 : show_as_nssa_lsa_detail, /* almost same as external */
6578 : NULL, /* type-8 */
6579 : show_opaque_lsa_detail,
6580 : show_opaque_lsa_detail,
6581 : show_opaque_lsa_detail,
6582 : };
6583 :
6584 0 : static void show_lsa_prefix_set(struct vty *vty, struct prefix_ls *lp,
6585 : struct in_addr *id, struct in_addr *adv_router)
6586 : {
6587 0 : memset(lp, 0, sizeof(struct prefix_ls));
6588 0 : lp->family = AF_UNSPEC;
6589 0 : if (id == NULL)
6590 : lp->prefixlen = 0;
6591 0 : else if (adv_router == NULL) {
6592 0 : lp->prefixlen = IPV4_MAX_BITLEN;
6593 0 : lp->id = *id;
6594 : } else {
6595 0 : lp->prefixlen = 64;
6596 0 : lp->id = *id;
6597 0 : lp->adv_router = *adv_router;
6598 : }
6599 0 : }
6600 :
6601 0 : static void show_lsa_detail_proc(struct vty *vty, struct route_table *rt,
6602 : struct in_addr *id, struct in_addr *adv_router,
6603 : json_object *json)
6604 : {
6605 0 : struct prefix_ls lp;
6606 0 : struct route_node *rn, *start;
6607 0 : struct ospf_lsa *lsa;
6608 0 : json_object *json_lsa = NULL;
6609 :
6610 0 : show_lsa_prefix_set(vty, &lp, id, adv_router);
6611 0 : start = route_node_get(rt, (struct prefix *)&lp);
6612 0 : if (start) {
6613 0 : route_lock_node(start);
6614 0 : for (rn = start; rn; rn = route_next_until(rn, start))
6615 0 : if ((lsa = rn->info)) {
6616 0 : if (show_function[lsa->data->type] != NULL) {
6617 0 : if (json) {
6618 0 : json_lsa =
6619 0 : json_object_new_object();
6620 0 : json_object_array_add(json,
6621 : json_lsa);
6622 : }
6623 :
6624 0 : show_function[lsa->data->type](
6625 : vty, lsa, json_lsa);
6626 : }
6627 : }
6628 0 : route_unlock_node(start);
6629 : }
6630 0 : }
6631 :
6632 : /* Show detail LSA information
6633 : -- if id is NULL then show all LSAs. */
6634 0 : static void show_lsa_detail(struct vty *vty, struct ospf *ospf, int type,
6635 : struct in_addr *id, struct in_addr *adv_router,
6636 : json_object *json)
6637 : {
6638 0 : struct listnode *node;
6639 0 : struct ospf_area *area;
6640 0 : char buf[PREFIX_STRLEN];
6641 0 : json_object *json_lsa_type = NULL;
6642 0 : json_object *json_areas = NULL;
6643 0 : json_object *json_lsa_array = NULL;
6644 :
6645 0 : switch (type) {
6646 0 : case OSPF_AS_EXTERNAL_LSA:
6647 : case OSPF_OPAQUE_AS_LSA:
6648 0 : if (!json)
6649 0 : vty_out(vty, " %s \n\n",
6650 0 : show_database_desc[type]);
6651 : else
6652 0 : json_lsa_array = json_object_new_array();
6653 :
6654 0 : show_lsa_detail_proc(vty, AS_LSDB(ospf, type), id, adv_router,
6655 : json_lsa_array);
6656 0 : if (json)
6657 0 : json_object_object_add(json,
6658 0 : show_database_desc_json[type],
6659 : json_lsa_array);
6660 :
6661 : break;
6662 0 : default:
6663 0 : if (json)
6664 0 : json_areas = json_object_new_object();
6665 :
6666 0 : for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) {
6667 0 : if (!json) {
6668 0 : vty_out(vty,
6669 : "\n %s (Area %s)\n\n",
6670 0 : show_database_desc[type],
6671 : ospf_area_desc_string(area));
6672 : } else {
6673 0 : json_lsa_array = json_object_new_array();
6674 0 : json_object_object_add(json_areas,
6675 : inet_ntop(AF_INET,
6676 0 : &area->area_id,
6677 : buf,
6678 : sizeof(buf)),
6679 : json_lsa_array);
6680 : }
6681 :
6682 0 : show_lsa_detail_proc(vty, AREA_LSDB(area, type), id,
6683 : adv_router, json_lsa_array);
6684 : }
6685 :
6686 0 : if (json) {
6687 0 : json_lsa_type = json_object_new_object();
6688 0 : json_object_object_add(json_lsa_type, "areas",
6689 : json_areas);
6690 0 : json_object_object_add(json,
6691 0 : show_database_desc_json[type],
6692 : json_lsa_type);
6693 : }
6694 : break;
6695 : }
6696 0 : }
6697 :
6698 0 : static void show_lsa_detail_adv_router_proc(struct vty *vty,
6699 : struct route_table *rt,
6700 : struct in_addr *adv_router,
6701 : json_object *json)
6702 : {
6703 0 : char buf[PREFIX_STRLEN];
6704 0 : struct route_node *rn;
6705 0 : struct ospf_lsa *lsa;
6706 :
6707 0 : for (rn = route_top(rt); rn; rn = route_next(rn))
6708 0 : if ((lsa = rn->info)) {
6709 0 : json_object *json_lsa = NULL;
6710 :
6711 0 : if (IPV4_ADDR_SAME(adv_router,
6712 : &lsa->data->adv_router)) {
6713 0 : if (CHECK_FLAG(lsa->flags, OSPF_LSA_LOCAL_XLT))
6714 0 : continue;
6715 0 : if (json)
6716 0 : json_lsa = json_object_new_object();
6717 :
6718 0 : if (show_function[lsa->data->type] != NULL)
6719 0 : show_function[lsa->data->type](
6720 : vty, lsa, json_lsa);
6721 0 : if (json)
6722 0 : json_object_object_add(
6723 : json,
6724 : inet_ntop(AF_INET,
6725 0 : &lsa->data->id,
6726 : buf, sizeof(buf)),
6727 : json_lsa);
6728 : }
6729 : }
6730 0 : }
6731 :
6732 : /* Show detail LSA information. */
6733 0 : static void show_lsa_detail_adv_router(struct vty *vty, struct ospf *ospf,
6734 : int type, struct in_addr *adv_router,
6735 : json_object *json)
6736 : {
6737 0 : struct listnode *node;
6738 0 : struct ospf_area *area;
6739 0 : char buf[PREFIX_STRLEN];
6740 0 : json_object *json_lstype = NULL;
6741 0 : json_object *json_area = NULL;
6742 :
6743 0 : if (json)
6744 0 : json_lstype = json_object_new_object();
6745 :
6746 0 : switch (type) {
6747 0 : case OSPF_AS_EXTERNAL_LSA:
6748 : case OSPF_OPAQUE_AS_LSA:
6749 0 : if (!json)
6750 0 : vty_out(vty, " %s \n\n",
6751 0 : show_database_desc[type]);
6752 :
6753 0 : show_lsa_detail_adv_router_proc(vty, AS_LSDB(ospf, type),
6754 : adv_router, json_lstype);
6755 0 : break;
6756 0 : default:
6757 :
6758 0 : for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) {
6759 0 : if (json)
6760 0 : json_area = json_object_new_object();
6761 : else
6762 0 : vty_out(vty,
6763 : "\n %s (Area %s)\n\n",
6764 0 : show_database_desc[type],
6765 : ospf_area_desc_string(area));
6766 0 : show_lsa_detail_adv_router_proc(vty,
6767 0 : AREA_LSDB(area, type),
6768 : adv_router, json_area);
6769 :
6770 0 : if (json)
6771 0 : json_object_object_add(json_lstype,
6772 : inet_ntop(AF_INET,
6773 0 : &area->area_id,
6774 : buf,
6775 : sizeof(buf)),
6776 : json_area);
6777 : }
6778 : break;
6779 : }
6780 :
6781 0 : if (json)
6782 0 : json_object_object_add(json, show_database_desc[type],
6783 : json_lstype);
6784 0 : }
6785 :
6786 0 : void show_ip_ospf_database_summary(struct vty *vty, struct ospf *ospf, int self,
6787 : json_object *json)
6788 : {
6789 0 : struct ospf_lsa *lsa;
6790 0 : struct route_node *rn;
6791 0 : struct ospf_area *area;
6792 0 : struct listnode *node;
6793 0 : char buf[PREFIX_STRLEN];
6794 0 : json_object *json_areas = NULL;
6795 0 : json_object *json_area = NULL;
6796 0 : json_object *json_lsa = NULL;
6797 0 : int type;
6798 0 : json_object *json_lsa_array = NULL;
6799 0 : uint32_t count;
6800 :
6801 0 : if (json)
6802 0 : json_areas = json_object_new_object();
6803 :
6804 0 : for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) {
6805 0 : if (json)
6806 0 : json_area = json_object_new_object();
6807 :
6808 0 : for (type = OSPF_MIN_LSA; type < OSPF_MAX_LSA; type++) {
6809 0 : count = 0;
6810 0 : switch (type) {
6811 0 : case OSPF_AS_EXTERNAL_LSA:
6812 : case OSPF_OPAQUE_AS_LSA:
6813 0 : continue;
6814 : default:
6815 0 : break;
6816 : }
6817 0 : if (ospf_lsdb_count_self(area->lsdb, type) > 0
6818 0 : || (!self
6819 0 : && ospf_lsdb_count(area->lsdb, type) > 0)) {
6820 :
6821 0 : if (!json) {
6822 0 : vty_out(vty,
6823 : " %s (Area %s)\n\n",
6824 0 : show_database_desc[type],
6825 : ospf_area_desc_string(area));
6826 0 : vty_out(vty, "%s\n",
6827 0 : show_database_header[type]);
6828 : } else {
6829 0 : json_lsa_array =
6830 0 : json_object_new_array();
6831 0 : json_object_object_add(
6832 : json_area,
6833 0 : show_database_desc_json[type],
6834 : json_lsa_array);
6835 : }
6836 :
6837 0 : LSDB_LOOP (AREA_LSDB(area, type), rn, lsa) {
6838 0 : if (json) {
6839 0 : json_lsa =
6840 0 : json_object_new_object();
6841 0 : json_object_array_add(
6842 : json_lsa_array,
6843 : json_lsa);
6844 : }
6845 :
6846 0 : count += show_lsa_summary(
6847 : vty, lsa, self, json_lsa);
6848 : }
6849 :
6850 0 : if (!json)
6851 0 : vty_out(vty, "\n");
6852 : else
6853 0 : json_object_int_add(
6854 : json_area,
6855 :
6856 : show_database_desc_count_json
6857 0 : [type],
6858 : count);
6859 : }
6860 : }
6861 0 : if (json)
6862 0 : json_object_object_add(json_areas,
6863 : inet_ntop(AF_INET,
6864 0 : &area->area_id,
6865 : buf, sizeof(buf)),
6866 : json_area);
6867 : }
6868 :
6869 0 : if (json)
6870 0 : json_object_object_add(json, "areas", json_areas);
6871 :
6872 0 : for (type = OSPF_MIN_LSA; type < OSPF_MAX_LSA; type++) {
6873 0 : count = 0;
6874 0 : switch (type) {
6875 : case OSPF_AS_EXTERNAL_LSA:
6876 : case OSPF_OPAQUE_AS_LSA:
6877 0 : break;
6878 0 : default:
6879 0 : continue;
6880 : }
6881 0 : if (ospf_lsdb_count_self(ospf->lsdb, type)
6882 0 : || (!self && ospf_lsdb_count(ospf->lsdb, type))) {
6883 0 : if (!json) {
6884 0 : vty_out(vty, " %s\n\n",
6885 0 : show_database_desc[type]);
6886 0 : vty_out(vty, "%s\n",
6887 0 : show_database_header[type]);
6888 : } else {
6889 0 : json_lsa_array = json_object_new_array();
6890 0 : json_object_object_add(
6891 0 : json, show_database_desc_json[type],
6892 : json_lsa_array);
6893 : }
6894 :
6895 0 : LSDB_LOOP (AS_LSDB(ospf, type), rn, lsa) {
6896 0 : if (json) {
6897 0 : json_lsa = json_object_new_object();
6898 0 : json_object_array_add(json_lsa_array,
6899 : json_lsa);
6900 : }
6901 :
6902 0 : count += show_lsa_summary(vty, lsa, self,
6903 : json_lsa);
6904 : }
6905 :
6906 0 : if (!json)
6907 0 : vty_out(vty, "\n");
6908 : else
6909 0 : json_object_int_add(
6910 : json,
6911 0 : show_database_desc_count_json[type],
6912 : count);
6913 : }
6914 : }
6915 :
6916 0 : if (!json)
6917 0 : vty_out(vty, "\n");
6918 0 : }
6919 :
6920 0 : static void show_ip_ospf_database_maxage(struct vty *vty, struct ospf *ospf,
6921 : json_object *json)
6922 : {
6923 0 : struct route_node *rn;
6924 0 : char buf[PREFIX_STRLEN];
6925 0 : json_object *json_maxage = NULL;
6926 :
6927 0 : if (!json)
6928 0 : vty_out(vty, "\n MaxAge Link States:\n\n");
6929 : else
6930 0 : json_maxage = json_object_new_object();
6931 :
6932 0 : for (rn = route_top(ospf->maxage_lsa); rn; rn = route_next(rn)) {
6933 0 : struct ospf_lsa *lsa;
6934 0 : json_object *json_lsa = NULL;
6935 :
6936 0 : if ((lsa = rn->info) != NULL) {
6937 0 : if (!json) {
6938 0 : vty_out(vty, "Link type: %d\n",
6939 0 : lsa->data->type);
6940 0 : vty_out(vty, "Link State ID: %pI4\n",
6941 0 : &lsa->data->id);
6942 0 : vty_out(vty, "Advertising Router: %pI4\n",
6943 0 : &lsa->data->adv_router);
6944 0 : vty_out(vty, "LSA lock count: %d\n", lsa->lock);
6945 0 : vty_out(vty, "\n");
6946 : } else {
6947 0 : json_lsa = json_object_new_object();
6948 0 : json_object_int_add(json_lsa, "linkType",
6949 0 : lsa->data->type);
6950 0 : json_object_string_addf(json_lsa, "linkStateId",
6951 0 : "%pI4", &lsa->data->id);
6952 0 : json_object_string_addf(
6953 : json_lsa, "advertisingRouter", "%pI4",
6954 0 : &lsa->data->adv_router);
6955 0 : json_object_int_add(json_lsa, "lsaLockCount",
6956 0 : lsa->lock);
6957 0 : json_object_object_add(
6958 : json_maxage,
6959 : inet_ntop(AF_INET,
6960 0 : &lsa->data->id,
6961 : buf, sizeof(buf)),
6962 : json_lsa);
6963 : }
6964 : }
6965 : }
6966 0 : if (json)
6967 0 : json_object_object_add(json, "maxAgeLinkStates", json_maxage);
6968 0 : }
6969 :
6970 : #define OSPF_LSA_TYPE_NSSA_DESC "NSSA external link state\n"
6971 : #define OSPF_LSA_TYPE_NSSA_CMD_STR "|nssa-external"
6972 :
6973 : #define OSPF_LSA_TYPE_OPAQUE_LINK_DESC "Link local Opaque-LSA\n"
6974 : #define OSPF_LSA_TYPE_OPAQUE_AREA_DESC "Link area Opaque-LSA\n"
6975 : #define OSPF_LSA_TYPE_OPAQUE_AS_DESC "Link AS Opaque-LSA\n"
6976 : #define OSPF_LSA_TYPE_OPAQUE_CMD_STR "|opaque-link|opaque-area|opaque-as"
6977 :
6978 : #define OSPF_LSA_TYPES_DESC \
6979 : "ASBR summary link states\n" \
6980 : "External link states\n" \
6981 : "Network link states\n" \
6982 : "Router link states\n" \
6983 : "Network summary link states\n" OSPF_LSA_TYPE_NSSA_DESC \
6984 : OSPF_LSA_TYPE_OPAQUE_LINK_DESC OSPF_LSA_TYPE_OPAQUE_AREA_DESC \
6985 : OSPF_LSA_TYPE_OPAQUE_AS_DESC
6986 :
6987 0 : static int show_ip_ospf_database_common(struct vty *vty, struct ospf *ospf,
6988 : int arg_base, int argc,
6989 : struct cmd_token **argv,
6990 : uint8_t use_vrf, json_object *json,
6991 : bool uj)
6992 : {
6993 0 : int idx_type = 4;
6994 0 : int type, ret;
6995 0 : struct in_addr id, adv_router;
6996 0 : json_object *json_vrf = NULL;
6997 :
6998 0 : if (uj) {
6999 0 : if (use_vrf)
7000 0 : json_vrf = json_object_new_object();
7001 : else
7002 : json_vrf = json;
7003 : }
7004 :
7005 0 : if (ospf->instance) {
7006 0 : if (uj)
7007 0 : json_object_int_add(json_vrf, "ospfInstance",
7008 : ospf->instance);
7009 : else
7010 0 : vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
7011 : }
7012 :
7013 0 : ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf);
7014 :
7015 : /* Show Router ID. */
7016 0 : if (uj) {
7017 0 : json_object_string_addf(json_vrf, "routerId", "%pI4",
7018 : &ospf->router_id);
7019 : } else {
7020 0 : vty_out(vty, "\n OSPF Router with ID (%pI4)\n\n",
7021 : &ospf->router_id);
7022 : }
7023 :
7024 : /* Show all LSA. */
7025 0 : if ((argc == arg_base + 4) || (uj && (argc == arg_base + 5))) {
7026 0 : show_ip_ospf_database_summary(vty, ospf, 0, json_vrf);
7027 0 : if (json) {
7028 0 : if (use_vrf)
7029 0 : json_object_object_add(
7030 : json, ospf_get_name(ospf), json_vrf);
7031 : }
7032 0 : return CMD_SUCCESS;
7033 : }
7034 :
7035 : /* Set database type to show. */
7036 0 : if (strncmp(argv[arg_base + idx_type]->text, "r", 1) == 0)
7037 : type = OSPF_ROUTER_LSA;
7038 0 : else if (strncmp(argv[arg_base + idx_type]->text, "ne", 2) == 0)
7039 : type = OSPF_NETWORK_LSA;
7040 0 : else if (strncmp(argv[arg_base + idx_type]->text, "ns", 2) == 0)
7041 : type = OSPF_AS_NSSA_LSA;
7042 0 : else if (strncmp(argv[arg_base + idx_type]->text, "su", 2) == 0)
7043 : type = OSPF_SUMMARY_LSA;
7044 0 : else if (strncmp(argv[arg_base + idx_type]->text, "a", 1) == 0)
7045 : type = OSPF_ASBR_SUMMARY_LSA;
7046 0 : else if (strncmp(argv[arg_base + idx_type]->text, "e", 1) == 0)
7047 : type = OSPF_AS_EXTERNAL_LSA;
7048 0 : else if (strncmp(argv[arg_base + idx_type]->text, "se", 2) == 0) {
7049 0 : show_ip_ospf_database_summary(vty, ospf, 1, json_vrf);
7050 0 : if (json) {
7051 0 : if (use_vrf)
7052 0 : json_object_object_add(
7053 : json, ospf_get_name(ospf), json_vrf);
7054 : }
7055 0 : return CMD_SUCCESS;
7056 0 : } else if (strncmp(argv[arg_base + idx_type]->text, "m", 1) == 0) {
7057 0 : show_ip_ospf_database_maxage(vty, ospf, json_vrf);
7058 0 : if (json) {
7059 0 : if (use_vrf)
7060 0 : json_object_object_add(
7061 : json, ospf_get_name(ospf), json_vrf);
7062 : }
7063 0 : return CMD_SUCCESS;
7064 0 : } else if (strncmp(argv[arg_base + idx_type]->text, "opaque-l", 8) == 0)
7065 : type = OSPF_OPAQUE_LINK_LSA;
7066 0 : else if (strncmp(argv[arg_base + idx_type]->text, "opaque-ar", 9) == 0)
7067 : type = OSPF_OPAQUE_AREA_LSA;
7068 0 : else if (strncmp(argv[arg_base + idx_type]->text, "opaque-as", 9) == 0)
7069 : type = OSPF_OPAQUE_AS_LSA;
7070 : else
7071 : return CMD_WARNING;
7072 :
7073 : /* `show ip ospf database LSA'. */
7074 0 : if ((argc == arg_base + 5) || (uj && (argc == arg_base + 6)))
7075 0 : show_lsa_detail(vty, ospf, type, NULL, NULL, json_vrf);
7076 0 : else if (argc >= arg_base + 6) {
7077 0 : ret = inet_aton(argv[arg_base + 5]->arg, &id);
7078 0 : if (!ret)
7079 : return CMD_WARNING;
7080 :
7081 : /* `show ip ospf database LSA ID'. */
7082 0 : if ((argc == arg_base + 6) || (uj && (argc == arg_base + 7)))
7083 0 : show_lsa_detail(vty, ospf, type, &id, NULL, json_vrf);
7084 : /* `show ip ospf database LSA ID adv-router ADV_ROUTER'. */
7085 0 : else if ((argc == arg_base + 7)
7086 0 : || (uj && (argc == arg_base + 8))) {
7087 0 : if (strncmp(argv[arg_base + 6]->text, "s", 1) == 0)
7088 0 : adv_router = ospf->router_id;
7089 : else {
7090 0 : ret = inet_aton(argv[arg_base + 7]->arg,
7091 : &adv_router);
7092 0 : if (!ret)
7093 : return CMD_WARNING;
7094 : }
7095 0 : show_lsa_detail(vty, ospf, type, &id, &adv_router,
7096 : json_vrf);
7097 : }
7098 : }
7099 :
7100 0 : if (json) {
7101 0 : if (use_vrf)
7102 0 : json_object_object_add(json, ospf_get_name(ospf),
7103 : json_vrf);
7104 : }
7105 :
7106 : return CMD_SUCCESS;
7107 : }
7108 :
7109 0 : DEFUN (show_ip_ospf_database_max,
7110 : show_ip_ospf_database_max_cmd,
7111 : "show ip ospf [vrf <NAME|all>] database <max-age|self-originate> [json]",
7112 : SHOW_STR
7113 : IP_STR
7114 : "OSPF information\n"
7115 : VRF_CMD_HELP_STR
7116 : "All VRFs\n"
7117 : "Database summary\n"
7118 : "LSAs in MaxAge list\n"
7119 : "Self-originated link states\n"
7120 : JSON_STR)
7121 : {
7122 0 : struct ospf *ospf = NULL;
7123 0 : struct listnode *node = NULL;
7124 0 : char *vrf_name = NULL;
7125 0 : bool all_vrf = false;
7126 0 : int ret = CMD_SUCCESS;
7127 0 : int inst = 0;
7128 0 : int idx_vrf = 0;
7129 0 : uint8_t use_vrf = 0;
7130 0 : bool uj = use_json(argc, argv);
7131 0 : json_object *json = NULL;
7132 :
7133 0 : if (uj)
7134 0 : json = json_object_new_object();
7135 :
7136 0 : OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
7137 :
7138 0 : if (vrf_name) {
7139 0 : bool ospf_output = false;
7140 :
7141 0 : use_vrf = 1;
7142 :
7143 0 : if (all_vrf) {
7144 0 : for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
7145 0 : if (!ospf->oi_running)
7146 0 : continue;
7147 0 : ospf_output = true;
7148 0 : ret = show_ip_ospf_database_common(
7149 0 : vty, ospf, idx_vrf ? 2 : 0, argc, argv,
7150 : use_vrf, json, uj);
7151 : }
7152 :
7153 0 : if (!ospf_output)
7154 0 : vty_out(vty, "%% OSPF is not enabled\n");
7155 : } else {
7156 0 : ospf = ospf_lookup_by_inst_name(inst, vrf_name);
7157 0 : if (ospf == NULL || !ospf->oi_running) {
7158 0 : vty_out(vty,
7159 : "%% OSPF is not enabled in vrf %s\n",
7160 : vrf_name);
7161 0 : if (uj)
7162 0 : json_object_free(json);
7163 :
7164 0 : return CMD_SUCCESS;
7165 : }
7166 0 : ret = (show_ip_ospf_database_common(
7167 0 : vty, ospf, idx_vrf ? 2 : 0, argc, argv, use_vrf,
7168 : json, uj));
7169 : }
7170 : } else {
7171 : /* Display default ospf (instance 0) info */
7172 0 : ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
7173 0 : if (ospf == NULL || !ospf->oi_running) {
7174 0 : vty_out(vty, "%% OSPF is not enabled in vrf default\n");
7175 0 : if (uj)
7176 0 : json_object_free(json);
7177 :
7178 0 : return CMD_SUCCESS;
7179 : }
7180 :
7181 0 : ret = show_ip_ospf_database_common(vty, ospf, 0, argc, argv,
7182 : use_vrf, json, uj);
7183 : }
7184 :
7185 0 : if (uj)
7186 0 : vty_json(vty, json);
7187 :
7188 : return ret;
7189 : }
7190 :
7191 : ALIAS (show_ip_ospf_database_max,
7192 : show_ip_ospf_database_cmd,
7193 : "show ip ospf [vrf <NAME|all>] 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>]]] [json]",
7194 : SHOW_STR
7195 : IP_STR
7196 : "OSPF information\n"
7197 : VRF_CMD_HELP_STR
7198 : "All VRFs\n"
7199 : "Database summary\n"
7200 : OSPF_LSA_TYPES_DESC
7201 : "Link State ID (as an IP address)\n"
7202 : "Self-originated link states\n"
7203 : "Advertising Router link states\n"
7204 : "Advertising Router (as an IP address)\n"
7205 : JSON_STR)
7206 :
7207 0 : DEFUN (show_ip_ospf_instance_database_max,
7208 : show_ip_ospf_instance_database_max_cmd,
7209 : "show ip ospf (1-65535) database <max-age|self-originate> [json]",
7210 : SHOW_STR
7211 : IP_STR
7212 : "OSPF information\n"
7213 : "Instance ID\n"
7214 : "Database summary\n"
7215 : "LSAs in MaxAge list\n"
7216 : "Self-originated link states\n"
7217 : JSON_STR)
7218 : {
7219 0 : int idx_number = 3;
7220 0 : struct ospf *ospf;
7221 0 : unsigned short instance = 0;
7222 0 : bool uj = use_json(argc, argv);
7223 0 : json_object *json = NULL;
7224 :
7225 0 : if (uj)
7226 0 : json = json_object_new_object();
7227 :
7228 0 : instance = strtoul(argv[idx_number]->arg, NULL, 10);
7229 0 : if (instance != ospf_instance)
7230 : return CMD_NOT_MY_INSTANCE;
7231 :
7232 0 : ospf = ospf_lookup_instance(instance);
7233 0 : if (!ospf || !ospf->oi_running)
7234 : return CMD_SUCCESS;
7235 :
7236 0 : show_ip_ospf_database_common(vty, ospf, 1, argc, argv, 0, json, uj);
7237 :
7238 0 : if (uj)
7239 0 : vty_json(vty, json);
7240 :
7241 : return CMD_SUCCESS;
7242 : }
7243 :
7244 : ALIAS (show_ip_ospf_instance_database_max,
7245 : show_ip_ospf_instance_database_cmd,
7246 : "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>]]] [json]",
7247 : SHOW_STR
7248 : IP_STR
7249 : "OSPF information\n"
7250 : "Instance ID\n"
7251 : "Database summary\n"
7252 : OSPF_LSA_TYPES_DESC
7253 : "Link State ID (as an IP address)\n"
7254 : "Self-originated link states\n"
7255 : "Advertising Router link states\n"
7256 : "Advertising Router (as an IP address)\n"
7257 : JSON_STR)
7258 :
7259 0 : static int show_ip_ospf_database_type_adv_router_common(struct vty *vty,
7260 : struct ospf *ospf,
7261 : int arg_base, int argc,
7262 : struct cmd_token **argv,
7263 : uint8_t use_vrf,
7264 : json_object *json,
7265 : bool uj)
7266 : {
7267 0 : int idx_type = 4;
7268 0 : int type, ret;
7269 0 : struct in_addr adv_router;
7270 0 : json_object *json_vrf = NULL;
7271 :
7272 0 : if (uj) {
7273 0 : if (use_vrf)
7274 0 : json_vrf = json_object_new_object();
7275 : else
7276 : json_vrf = json;
7277 : }
7278 :
7279 0 : if (ospf->instance) {
7280 0 : if (uj)
7281 0 : json_object_int_add(json, "ospfInstance",
7282 : ospf->instance);
7283 : else
7284 0 : vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
7285 : }
7286 :
7287 0 : ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf);
7288 :
7289 : /* Show Router ID. */
7290 0 : if (uj) {
7291 0 : json_object_string_addf(json_vrf, "routerId", "%pI4",
7292 : &ospf->router_id);
7293 : } else {
7294 0 : vty_out(vty, "\n OSPF Router with ID (%pI4)\n\n",
7295 : &ospf->router_id);
7296 : }
7297 :
7298 : /* Set database type to show. */
7299 0 : if (strncmp(argv[arg_base + idx_type]->text, "r", 1) == 0)
7300 : type = OSPF_ROUTER_LSA;
7301 0 : else if (strncmp(argv[arg_base + idx_type]->text, "ne", 2) == 0)
7302 : type = OSPF_NETWORK_LSA;
7303 0 : else if (strncmp(argv[arg_base + idx_type]->text, "ns", 2) == 0)
7304 : type = OSPF_AS_NSSA_LSA;
7305 0 : else if (strncmp(argv[arg_base + idx_type]->text, "s", 1) == 0)
7306 : type = OSPF_SUMMARY_LSA;
7307 : else if (strncmp(argv[arg_base + idx_type]->text, "a", 1) == 0)
7308 : type = OSPF_ASBR_SUMMARY_LSA;
7309 : else if (strncmp(argv[arg_base + idx_type]->text, "e", 1) == 0)
7310 : type = OSPF_AS_EXTERNAL_LSA;
7311 0 : else if (strncmp(argv[arg_base + idx_type]->text, "opaque-l", 8) == 0)
7312 : type = OSPF_OPAQUE_LINK_LSA;
7313 0 : else if (strncmp(argv[arg_base + idx_type]->text, "opaque-ar", 9) == 0)
7314 : type = OSPF_OPAQUE_AREA_LSA;
7315 0 : else if (strncmp(argv[arg_base + idx_type]->text, "opaque-as", 9) == 0)
7316 : type = OSPF_OPAQUE_AS_LSA;
7317 : else {
7318 0 : if (uj) {
7319 0 : if (use_vrf)
7320 0 : json_object_free(json_vrf);
7321 : }
7322 0 : return CMD_WARNING;
7323 : }
7324 :
7325 : /* `show ip ospf database LSA adv-router ADV_ROUTER'. */
7326 0 : if (strncmp(argv[arg_base + 5]->text, "s", 1) == 0)
7327 0 : adv_router = ospf->router_id;
7328 : else {
7329 0 : ret = inet_aton(argv[arg_base + 6]->arg, &adv_router);
7330 0 : if (!ret) {
7331 0 : if (uj) {
7332 0 : if (use_vrf)
7333 0 : json_object_free(json_vrf);
7334 : }
7335 0 : return CMD_WARNING;
7336 : }
7337 : }
7338 :
7339 0 : show_lsa_detail_adv_router(vty, ospf, type, &adv_router, json_vrf);
7340 :
7341 0 : if (json) {
7342 0 : if (use_vrf)
7343 0 : json_object_object_add(json, ospf_get_name(ospf),
7344 : json_vrf);
7345 : }
7346 :
7347 : return CMD_SUCCESS;
7348 : }
7349 :
7350 0 : DEFUN (show_ip_ospf_database_type_adv_router,
7351 : show_ip_ospf_database_type_adv_router_cmd,
7352 : "show ip ospf [vrf <NAME|all>] database <asbr-summary|external|network|router|summary|nssa-external|opaque-link|opaque-area|opaque-as> <adv-router A.B.C.D|self-originate> [json]",
7353 : SHOW_STR
7354 : IP_STR
7355 : "OSPF information\n"
7356 : VRF_CMD_HELP_STR
7357 : "All VRFs\n"
7358 : "Database summary\n"
7359 : OSPF_LSA_TYPES_DESC
7360 : "Advertising Router link states\n"
7361 : "Advertising Router (as an IP address)\n"
7362 : "Self-originated link states\n"
7363 : JSON_STR)
7364 : {
7365 0 : struct ospf *ospf = NULL;
7366 0 : struct listnode *node = NULL;
7367 0 : char *vrf_name = NULL;
7368 0 : bool all_vrf = false;
7369 0 : int ret = CMD_SUCCESS;
7370 0 : int inst = 0;
7371 0 : int idx_vrf = 0;
7372 0 : uint8_t use_vrf = 0;
7373 0 : bool uj = use_json(argc, argv);
7374 0 : json_object *json = NULL;
7375 :
7376 0 : if (uj)
7377 0 : json = json_object_new_object();
7378 :
7379 0 : OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
7380 :
7381 0 : if (vrf_name) {
7382 0 : bool ospf_output = false;
7383 :
7384 0 : use_vrf = 1;
7385 :
7386 0 : if (all_vrf) {
7387 0 : for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
7388 0 : if (!ospf->oi_running)
7389 0 : continue;
7390 0 : ospf_output = true;
7391 0 : ret = show_ip_ospf_database_type_adv_router_common(
7392 : vty, ospf, 2, argc, argv, use_vrf, json,
7393 : uj);
7394 : }
7395 0 : if (!ospf_output)
7396 0 : vty_out(vty, "%% OSPF is not enabled\n");
7397 : } else {
7398 0 : ospf = ospf_lookup_by_inst_name(inst, vrf_name);
7399 0 : if ((ospf == NULL) || !ospf->oi_running) {
7400 0 : if (uj)
7401 0 : vty_json(vty, json);
7402 : else
7403 0 : vty_out(vty,
7404 : "%% OSPF is not enabled in vrf %s\n",
7405 : vrf_name);
7406 0 : return CMD_SUCCESS;
7407 : }
7408 :
7409 0 : ret = show_ip_ospf_database_type_adv_router_common(
7410 : vty, ospf, 2, argc, argv, use_vrf, json, uj);
7411 : }
7412 : } else {
7413 : /* Display default ospf (instance 0) info */
7414 0 : ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
7415 0 : if (ospf == NULL || !ospf->oi_running) {
7416 0 : if (uj)
7417 0 : vty_json(vty, json);
7418 : else
7419 0 : vty_out(vty,
7420 : "%% OSPF is not enabled on vrf default\n");
7421 0 : return CMD_SUCCESS;
7422 : }
7423 :
7424 0 : ret = show_ip_ospf_database_type_adv_router_common(
7425 : vty, ospf, 0, argc, argv, use_vrf, json, uj);
7426 : }
7427 :
7428 0 : if (uj) {
7429 0 : vty_out(vty, "%s\n", json_object_to_json_string(json));
7430 0 : json_object_free(json);
7431 : }
7432 :
7433 : return ret;
7434 : }
7435 :
7436 0 : DEFUN (show_ip_ospf_instance_database_type_adv_router,
7437 : show_ip_ospf_instance_database_type_adv_router_cmd,
7438 : "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> [json]",
7439 : SHOW_STR
7440 : IP_STR
7441 : "OSPF information\n"
7442 : "Instance ID\n"
7443 : "Database summary\n"
7444 : OSPF_LSA_TYPES_DESC
7445 : "Advertising Router link states\n"
7446 : "Advertising Router (as an IP address)\n"
7447 : "Self-originated link states\n"
7448 : JSON_STR)
7449 : {
7450 0 : int idx_number = 3;
7451 0 : struct ospf *ospf;
7452 0 : unsigned short instance = 0;
7453 0 : bool uj = use_json(argc, argv);
7454 0 : json_object *json = NULL;
7455 :
7456 0 : if (uj)
7457 0 : json = json_object_new_object();
7458 :
7459 0 : instance = strtoul(argv[idx_number]->arg, NULL, 10);
7460 0 : if (instance != ospf_instance)
7461 : return CMD_NOT_MY_INSTANCE;
7462 :
7463 0 : ospf = ospf_lookup_instance(instance);
7464 0 : if (!ospf || !ospf->oi_running)
7465 : return CMD_SUCCESS;
7466 :
7467 0 : show_ip_ospf_database_type_adv_router_common(vty, ospf, 1, argc, argv,
7468 : 0, json, uj);
7469 :
7470 0 : if (uj)
7471 0 : vty_json(vty, json);
7472 :
7473 : return CMD_SUCCESS;
7474 : }
7475 :
7476 0 : DEFUN (ip_ospf_authentication_args,
7477 : ip_ospf_authentication_args_addr_cmd,
7478 : "ip ospf authentication <null|message-digest> [A.B.C.D]",
7479 : "IP Information\n"
7480 : "OSPF interface commands\n"
7481 : "Enable authentication on this interface\n"
7482 : "Use null authentication\n"
7483 : "Use message-digest authentication\n"
7484 : "Address of interface\n")
7485 : {
7486 0 : VTY_DECLVAR_CONTEXT(interface, ifp);
7487 0 : int idx_encryption = 3;
7488 0 : int idx_ipv4 = 4;
7489 0 : struct in_addr addr;
7490 0 : int ret;
7491 0 : struct ospf_if_params *params;
7492 :
7493 0 : params = IF_DEF_PARAMS(ifp);
7494 :
7495 0 : if (argc == 5) {
7496 0 : ret = inet_aton(argv[idx_ipv4]->arg, &addr);
7497 0 : if (!ret) {
7498 0 : vty_out(vty,
7499 : "Please specify interface address by A.B.C.D\n");
7500 0 : return CMD_WARNING_CONFIG_FAILED;
7501 : }
7502 :
7503 0 : params = ospf_get_if_params(ifp, addr);
7504 0 : ospf_if_update_params(ifp, addr);
7505 : }
7506 :
7507 : /* Handle null authentication */
7508 0 : if (argv[idx_encryption]->arg[0] == 'n') {
7509 0 : SET_IF_PARAM(params, auth_type);
7510 0 : params->auth_type = OSPF_AUTH_NULL;
7511 0 : return CMD_SUCCESS;
7512 : }
7513 :
7514 : /* Handle message-digest authentication */
7515 0 : if (argv[idx_encryption]->arg[0] == 'm') {
7516 0 : SET_IF_PARAM(params, auth_type);
7517 0 : params->auth_type = OSPF_AUTH_CRYPTOGRAPHIC;
7518 0 : return CMD_SUCCESS;
7519 : }
7520 :
7521 0 : vty_out(vty, "You shouldn't get here!\n");
7522 0 : return CMD_WARNING_CONFIG_FAILED;
7523 : }
7524 :
7525 0 : DEFUN (ip_ospf_authentication,
7526 : ip_ospf_authentication_addr_cmd,
7527 : "ip ospf authentication [A.B.C.D]",
7528 : "IP Information\n"
7529 : "OSPF interface commands\n"
7530 : "Enable authentication on this interface\n"
7531 : "Address of interface\n")
7532 : {
7533 0 : VTY_DECLVAR_CONTEXT(interface, ifp);
7534 0 : int idx_ipv4 = 3;
7535 0 : struct in_addr addr;
7536 0 : int ret;
7537 0 : struct ospf_if_params *params;
7538 :
7539 0 : params = IF_DEF_PARAMS(ifp);
7540 :
7541 0 : if (argc == 4) {
7542 0 : ret = inet_aton(argv[idx_ipv4]->arg, &addr);
7543 0 : if (!ret) {
7544 0 : vty_out(vty,
7545 : "Please specify interface address by A.B.C.D\n");
7546 0 : return CMD_WARNING_CONFIG_FAILED;
7547 : }
7548 :
7549 0 : params = ospf_get_if_params(ifp, addr);
7550 0 : ospf_if_update_params(ifp, addr);
7551 : }
7552 :
7553 0 : SET_IF_PARAM(params, auth_type);
7554 0 : params->auth_type = OSPF_AUTH_SIMPLE;
7555 :
7556 0 : return CMD_SUCCESS;
7557 : }
7558 :
7559 0 : DEFUN (no_ip_ospf_authentication_args,
7560 : no_ip_ospf_authentication_args_addr_cmd,
7561 : "no ip ospf authentication <null|message-digest> [A.B.C.D]",
7562 : NO_STR
7563 : "IP Information\n"
7564 : "OSPF interface commands\n"
7565 : "Enable authentication on this interface\n"
7566 : "Use null authentication\n"
7567 : "Use message-digest authentication\n"
7568 : "Address of interface\n")
7569 : {
7570 0 : VTY_DECLVAR_CONTEXT(interface, ifp);
7571 0 : int idx_encryption = 4;
7572 0 : int idx_ipv4 = 5;
7573 0 : struct in_addr addr;
7574 0 : int ret;
7575 0 : struct ospf_if_params *params;
7576 0 : struct route_node *rn;
7577 0 : int auth_type;
7578 :
7579 0 : params = IF_DEF_PARAMS(ifp);
7580 :
7581 0 : if (argc == 6) {
7582 0 : ret = inet_aton(argv[idx_ipv4]->arg, &addr);
7583 0 : if (!ret) {
7584 0 : vty_out(vty,
7585 : "Please specify interface address by A.B.C.D\n");
7586 0 : return CMD_WARNING_CONFIG_FAILED;
7587 : }
7588 :
7589 0 : params = ospf_lookup_if_params(ifp, addr);
7590 0 : if (params == NULL) {
7591 0 : vty_out(vty, "Ip Address specified is unknown\n");
7592 0 : return CMD_WARNING_CONFIG_FAILED;
7593 : }
7594 0 : params->auth_type = OSPF_AUTH_NOTSET;
7595 0 : UNSET_IF_PARAM(params, auth_type);
7596 0 : if (params != IF_DEF_PARAMS(ifp)) {
7597 0 : ospf_free_if_params(ifp, addr);
7598 0 : ospf_if_update_params(ifp, addr);
7599 : }
7600 : } else {
7601 0 : if (argv[idx_encryption]->arg[0] == 'n') {
7602 : auth_type = OSPF_AUTH_NULL;
7603 0 : } else if (argv[idx_encryption]->arg[0] == 'm') {
7604 : auth_type = OSPF_AUTH_CRYPTOGRAPHIC;
7605 : } else {
7606 0 : vty_out(vty, "Unexpected input encountered\n");
7607 0 : return CMD_WARNING_CONFIG_FAILED;
7608 : }
7609 : /*
7610 : * Here we have a case where the user has entered
7611 : * 'no ip ospf authentication (null | message_digest )'
7612 : * we need to find if we have any ip addresses underneath it
7613 : * that
7614 : * correspond to the associated type.
7615 : */
7616 0 : if (params->auth_type == auth_type) {
7617 0 : params->auth_type = OSPF_AUTH_NOTSET;
7618 0 : UNSET_IF_PARAM(params, auth_type);
7619 : }
7620 :
7621 0 : for (rn = route_top(IF_OIFS_PARAMS(ifp)); rn;
7622 0 : rn = route_next(rn)) {
7623 0 : if ((params = rn->info)) {
7624 0 : if (params->auth_type == auth_type) {
7625 0 : params->auth_type = OSPF_AUTH_NOTSET;
7626 0 : UNSET_IF_PARAM(params, auth_type);
7627 0 : if (params != IF_DEF_PARAMS(ifp)) {
7628 0 : ospf_free_if_params(
7629 : ifp, rn->p.u.prefix4);
7630 0 : ospf_if_update_params(
7631 : ifp, rn->p.u.prefix4);
7632 : }
7633 : }
7634 : }
7635 : }
7636 : }
7637 :
7638 : return CMD_SUCCESS;
7639 : }
7640 :
7641 0 : DEFUN (no_ip_ospf_authentication,
7642 : no_ip_ospf_authentication_addr_cmd,
7643 : "no ip ospf authentication [A.B.C.D]",
7644 : NO_STR
7645 : "IP Information\n"
7646 : "OSPF interface commands\n"
7647 : "Enable authentication on this interface\n"
7648 : "Address of interface\n")
7649 : {
7650 0 : VTY_DECLVAR_CONTEXT(interface, ifp);
7651 0 : int idx_ipv4 = 4;
7652 0 : struct in_addr addr;
7653 0 : int ret;
7654 0 : struct ospf_if_params *params;
7655 0 : struct route_node *rn;
7656 :
7657 0 : params = IF_DEF_PARAMS(ifp);
7658 :
7659 0 : if (argc == 5) {
7660 0 : ret = inet_aton(argv[idx_ipv4]->arg, &addr);
7661 0 : if (!ret) {
7662 0 : vty_out(vty,
7663 : "Please specify interface address by A.B.C.D\n");
7664 0 : return CMD_WARNING_CONFIG_FAILED;
7665 : }
7666 :
7667 0 : params = ospf_lookup_if_params(ifp, addr);
7668 0 : if (params == NULL) {
7669 0 : vty_out(vty, "Ip Address specified is unknown\n");
7670 0 : return CMD_WARNING_CONFIG_FAILED;
7671 : }
7672 :
7673 0 : params->auth_type = OSPF_AUTH_NOTSET;
7674 0 : UNSET_IF_PARAM(params, auth_type);
7675 0 : if (params != IF_DEF_PARAMS(ifp)) {
7676 0 : ospf_free_if_params(ifp, addr);
7677 0 : ospf_if_update_params(ifp, addr);
7678 : }
7679 : } else {
7680 : /*
7681 : * When a user enters 'no ip ospf authentication'
7682 : * We should remove all authentication types from
7683 : * the interface.
7684 : */
7685 0 : if ((params->auth_type == OSPF_AUTH_NULL)
7686 0 : || (params->auth_type == OSPF_AUTH_CRYPTOGRAPHIC)
7687 0 : || (params->auth_type == OSPF_AUTH_SIMPLE)) {
7688 0 : params->auth_type = OSPF_AUTH_NOTSET;
7689 0 : UNSET_IF_PARAM(params, auth_type);
7690 : }
7691 :
7692 0 : for (rn = route_top(IF_OIFS_PARAMS(ifp)); rn;
7693 0 : rn = route_next(rn)) {
7694 0 : if ((params = rn->info)) {
7695 :
7696 0 : if ((params->auth_type == OSPF_AUTH_NULL)
7697 0 : || (params->auth_type
7698 : == OSPF_AUTH_CRYPTOGRAPHIC)
7699 0 : || (params->auth_type
7700 : == OSPF_AUTH_SIMPLE)) {
7701 0 : params->auth_type = OSPF_AUTH_NOTSET;
7702 0 : UNSET_IF_PARAM(params, auth_type);
7703 0 : if (params != IF_DEF_PARAMS(ifp)) {
7704 0 : ospf_free_if_params(
7705 : ifp, rn->p.u.prefix4);
7706 0 : ospf_if_update_params(
7707 : ifp, rn->p.u.prefix4);
7708 : }
7709 : }
7710 : }
7711 : }
7712 : }
7713 :
7714 : return CMD_SUCCESS;
7715 : }
7716 :
7717 :
7718 0 : DEFUN (ip_ospf_authentication_key,
7719 : ip_ospf_authentication_key_addr_cmd,
7720 : "ip ospf authentication-key AUTH_KEY [A.B.C.D]",
7721 : "IP Information\n"
7722 : "OSPF interface commands\n"
7723 : "Authentication password (key)\n"
7724 : "The OSPF password (key)\n"
7725 : "Address of interface\n")
7726 : {
7727 0 : VTY_DECLVAR_CONTEXT(interface, ifp);
7728 0 : int idx = 0;
7729 0 : struct in_addr addr;
7730 0 : struct ospf_if_params *params;
7731 :
7732 0 : params = IF_DEF_PARAMS(ifp);
7733 :
7734 0 : if (argv_find(argv, argc, "A.B.C.D", &idx)) {
7735 0 : if (!inet_aton(argv[idx]->arg, &addr)) {
7736 0 : vty_out(vty,
7737 : "Please specify interface address by A.B.C.D\n");
7738 0 : return CMD_WARNING_CONFIG_FAILED;
7739 : }
7740 :
7741 0 : params = ospf_get_if_params(ifp, addr);
7742 0 : ospf_if_update_params(ifp, addr);
7743 : }
7744 :
7745 0 : strlcpy((char *)params->auth_simple, argv[3]->arg,
7746 : sizeof(params->auth_simple));
7747 0 : SET_IF_PARAM(params, auth_simple);
7748 :
7749 0 : return CMD_SUCCESS;
7750 : }
7751 :
7752 0 : DEFUN_HIDDEN (ospf_authentication_key,
7753 : ospf_authentication_key_cmd,
7754 : "ospf authentication-key AUTH_KEY [A.B.C.D]",
7755 : "OSPF interface commands\n"
7756 : VLINK_HELPSTR_AUTH_SIMPLE
7757 : "Address of interface\n")
7758 : {
7759 0 : return ip_ospf_authentication_key(self, vty, argc, argv);
7760 : }
7761 :
7762 0 : DEFUN (no_ip_ospf_authentication_key,
7763 : no_ip_ospf_authentication_key_authkey_addr_cmd,
7764 : "no ip ospf authentication-key [AUTH_KEY [A.B.C.D]]",
7765 : NO_STR
7766 : "IP Information\n"
7767 : "OSPF interface commands\n"
7768 : VLINK_HELPSTR_AUTH_SIMPLE
7769 : "Address of interface\n")
7770 : {
7771 0 : VTY_DECLVAR_CONTEXT(interface, ifp);
7772 0 : int idx = 0;
7773 0 : struct in_addr addr;
7774 0 : struct ospf_if_params *params;
7775 0 : params = IF_DEF_PARAMS(ifp);
7776 :
7777 0 : if (argv_find(argv, argc, "A.B.C.D", &idx)) {
7778 0 : if (!inet_aton(argv[idx]->arg, &addr)) {
7779 0 : vty_out(vty,
7780 : "Please specify interface address by A.B.C.D\n");
7781 0 : return CMD_WARNING_CONFIG_FAILED;
7782 : }
7783 :
7784 0 : params = ospf_lookup_if_params(ifp, addr);
7785 0 : if (params == NULL)
7786 : return CMD_SUCCESS;
7787 : }
7788 :
7789 0 : memset(params->auth_simple, 0, OSPF_AUTH_SIMPLE_SIZE);
7790 0 : UNSET_IF_PARAM(params, auth_simple);
7791 :
7792 0 : if (params != IF_DEF_PARAMS(ifp)) {
7793 0 : ospf_free_if_params(ifp, addr);
7794 0 : ospf_if_update_params(ifp, addr);
7795 : }
7796 :
7797 : return CMD_SUCCESS;
7798 : }
7799 :
7800 0 : DEFUN_HIDDEN (no_ospf_authentication_key,
7801 : no_ospf_authentication_key_authkey_addr_cmd,
7802 : "no ospf authentication-key [AUTH_KEY [A.B.C.D]]",
7803 : NO_STR
7804 : "OSPF interface commands\n"
7805 : VLINK_HELPSTR_AUTH_SIMPLE
7806 : "Address of interface\n")
7807 : {
7808 0 : return no_ip_ospf_authentication_key(self, vty, argc, argv);
7809 : }
7810 :
7811 0 : DEFUN (ip_ospf_message_digest_key,
7812 : ip_ospf_message_digest_key_cmd,
7813 : "ip ospf message-digest-key (1-255) md5 KEY [A.B.C.D]",
7814 : "IP Information\n"
7815 : "OSPF interface commands\n"
7816 : "Message digest authentication password (key)\n"
7817 : "Key ID\n"
7818 : "Use MD5 algorithm\n"
7819 : "The OSPF password (key)\n"
7820 : "Address of interface\n")
7821 : {
7822 0 : VTY_DECLVAR_CONTEXT(interface, ifp);
7823 0 : struct crypt_key *ck;
7824 0 : uint8_t key_id;
7825 0 : struct in_addr addr;
7826 0 : struct ospf_if_params *params;
7827 :
7828 0 : params = IF_DEF_PARAMS(ifp);
7829 0 : int idx = 0;
7830 :
7831 0 : argv_find(argv, argc, "(1-255)", &idx);
7832 0 : char *keyid = argv[idx]->arg;
7833 0 : argv_find(argv, argc, "KEY", &idx);
7834 0 : char *cryptkey = argv[idx]->arg;
7835 :
7836 0 : if (argv_find(argv, argc, "A.B.C.D", &idx)) {
7837 0 : if (!inet_aton(argv[idx]->arg, &addr)) {
7838 0 : vty_out(vty,
7839 : "Please specify interface address by A.B.C.D\n");
7840 0 : return CMD_WARNING_CONFIG_FAILED;
7841 : }
7842 :
7843 0 : params = ospf_get_if_params(ifp, addr);
7844 0 : ospf_if_update_params(ifp, addr);
7845 : }
7846 :
7847 0 : key_id = strtol(keyid, NULL, 10);
7848 :
7849 : /* Remove existing key, if any */
7850 0 : ospf_crypt_key_delete(params->auth_crypt, key_id);
7851 :
7852 0 : ck = ospf_crypt_key_new();
7853 0 : ck->key_id = (uint8_t)key_id;
7854 0 : strlcpy((char *)ck->auth_key, cryptkey, sizeof(ck->auth_key));
7855 :
7856 0 : ospf_crypt_key_add(params->auth_crypt, ck);
7857 0 : SET_IF_PARAM(params, auth_crypt);
7858 :
7859 0 : return CMD_SUCCESS;
7860 : }
7861 :
7862 0 : DEFUN_HIDDEN (ospf_message_digest_key,
7863 : ospf_message_digest_key_cmd,
7864 : "ospf message-digest-key (1-255) md5 KEY [A.B.C.D]",
7865 : "OSPF interface commands\n"
7866 : "Message digest authentication password (key)\n"
7867 : "Key ID\n"
7868 : "Use MD5 algorithm\n"
7869 : "The OSPF password (key)\n"
7870 : "Address of interface\n")
7871 : {
7872 0 : return ip_ospf_message_digest_key(self, vty, argc, argv);
7873 : }
7874 :
7875 0 : DEFUN (no_ip_ospf_message_digest_key,
7876 : no_ip_ospf_message_digest_key_cmd,
7877 : "no ip ospf message-digest-key (1-255) [md5 KEY] [A.B.C.D]",
7878 : NO_STR
7879 : "IP Information\n"
7880 : "OSPF interface commands\n"
7881 : "Message digest authentication password (key)\n"
7882 : "Key ID\n"
7883 : "Use MD5 algorithm\n"
7884 : "The OSPF password (key)\n"
7885 : "Address of interface\n")
7886 : {
7887 0 : VTY_DECLVAR_CONTEXT(interface, ifp);
7888 0 : int idx = 0;
7889 0 : struct crypt_key *ck;
7890 0 : int key_id;
7891 0 : struct in_addr addr;
7892 0 : struct ospf_if_params *params;
7893 0 : params = IF_DEF_PARAMS(ifp);
7894 :
7895 0 : argv_find(argv, argc, "(1-255)", &idx);
7896 0 : char *keyid = argv[idx]->arg;
7897 :
7898 0 : if (argv_find(argv, argc, "A.B.C.D", &idx)) {
7899 0 : if (!inet_aton(argv[idx]->arg, &addr)) {
7900 0 : vty_out(vty,
7901 : "Please specify interface address by A.B.C.D\n");
7902 0 : return CMD_WARNING_CONFIG_FAILED;
7903 : }
7904 :
7905 0 : params = ospf_lookup_if_params(ifp, addr);
7906 0 : if (params == NULL)
7907 : return CMD_SUCCESS;
7908 : }
7909 :
7910 0 : key_id = strtol(keyid, NULL, 10);
7911 0 : ck = ospf_crypt_key_lookup(params->auth_crypt, key_id);
7912 0 : if (ck == NULL) {
7913 0 : vty_out(vty, "OSPF: Key %d does not exist\n", key_id);
7914 0 : return CMD_WARNING_CONFIG_FAILED;
7915 : }
7916 :
7917 0 : ospf_crypt_key_delete(params->auth_crypt, key_id);
7918 :
7919 0 : if (params != IF_DEF_PARAMS(ifp)) {
7920 0 : ospf_free_if_params(ifp, addr);
7921 0 : ospf_if_update_params(ifp, addr);
7922 : }
7923 :
7924 : return CMD_SUCCESS;
7925 : }
7926 :
7927 0 : DEFUN_HIDDEN (no_ospf_message_digest_key,
7928 : no_ospf_message_digest_key_cmd,
7929 : "no ospf message-digest-key (1-255) [md5 KEY] [A.B.C.D]",
7930 : NO_STR
7931 : "OSPF interface commands\n"
7932 : "Message digest authentication password (key)\n"
7933 : "Key ID\n"
7934 : "Use MD5 algorithm\n"
7935 : "The OSPF password (key)\n"
7936 : "Address of interface\n")
7937 : {
7938 0 : return no_ip_ospf_message_digest_key(self, vty, argc, argv);
7939 : }
7940 :
7941 0 : DEFUN (ip_ospf_cost,
7942 : ip_ospf_cost_cmd,
7943 : "ip ospf cost (1-65535) [A.B.C.D]",
7944 : "IP Information\n"
7945 : "OSPF interface commands\n"
7946 : "Interface cost\n"
7947 : "Cost\n"
7948 : "Address of interface\n")
7949 : {
7950 0 : VTY_DECLVAR_CONTEXT(interface, ifp);
7951 0 : int idx = 0;
7952 0 : uint32_t cost = OSPF_OUTPUT_COST_DEFAULT;
7953 0 : struct in_addr addr;
7954 0 : struct ospf_if_params *params;
7955 0 : params = IF_DEF_PARAMS(ifp);
7956 :
7957 : // get arguments
7958 0 : char *coststr = NULL, *ifaddr = NULL;
7959 :
7960 0 : argv_find(argv, argc, "(1-65535)", &idx);
7961 0 : coststr = argv[idx]->arg;
7962 0 : cost = strtol(coststr, NULL, 10);
7963 :
7964 0 : ifaddr = argv_find(argv, argc, "A.B.C.D", &idx) ? argv[idx]->arg : NULL;
7965 0 : if (ifaddr) {
7966 0 : if (!inet_aton(ifaddr, &addr)) {
7967 0 : vty_out(vty,
7968 : "Please specify interface address by A.B.C.D\n");
7969 0 : return CMD_WARNING_CONFIG_FAILED;
7970 : }
7971 :
7972 0 : params = ospf_get_if_params(ifp, addr);
7973 0 : ospf_if_update_params(ifp, addr);
7974 : }
7975 :
7976 0 : SET_IF_PARAM(params, output_cost_cmd);
7977 0 : params->output_cost_cmd = cost;
7978 :
7979 0 : ospf_if_recalculate_output_cost(ifp);
7980 :
7981 0 : return CMD_SUCCESS;
7982 : }
7983 :
7984 0 : DEFUN_HIDDEN (ospf_cost,
7985 : ospf_cost_cmd,
7986 : "ospf cost (1-65535) [A.B.C.D]",
7987 : "OSPF interface commands\n"
7988 : "Interface cost\n"
7989 : "Cost\n"
7990 : "Address of interface\n")
7991 : {
7992 0 : return ip_ospf_cost(self, vty, argc, argv);
7993 : }
7994 :
7995 0 : DEFUN (no_ip_ospf_cost,
7996 : no_ip_ospf_cost_cmd,
7997 : "no ip ospf cost [(1-65535)] [A.B.C.D]",
7998 : NO_STR
7999 : "IP Information\n"
8000 : "OSPF interface commands\n"
8001 : "Interface cost\n"
8002 : "Cost\n"
8003 : "Address of interface\n")
8004 : {
8005 0 : VTY_DECLVAR_CONTEXT(interface, ifp);
8006 0 : int idx = 0;
8007 0 : struct in_addr addr;
8008 0 : struct ospf_if_params *params;
8009 :
8010 0 : params = IF_DEF_PARAMS(ifp);
8011 :
8012 : // get arguments
8013 0 : char *ifaddr = NULL;
8014 0 : ifaddr = argv_find(argv, argc, "A.B.C.D", &idx) ? argv[idx]->arg : NULL;
8015 :
8016 : /* According to the semantics we are mimicking "no ip ospf cost N" is
8017 : * always treated as "no ip ospf cost" regardless of the actual value
8018 : * of N already configured for the interface. Thus ignore cost. */
8019 :
8020 0 : if (ifaddr) {
8021 0 : if (!inet_aton(ifaddr, &addr)) {
8022 0 : vty_out(vty,
8023 : "Please specify interface address by A.B.C.D\n");
8024 0 : return CMD_WARNING_CONFIG_FAILED;
8025 : }
8026 :
8027 0 : params = ospf_lookup_if_params(ifp, addr);
8028 0 : if (params == NULL)
8029 : return CMD_SUCCESS;
8030 : }
8031 :
8032 0 : UNSET_IF_PARAM(params, output_cost_cmd);
8033 :
8034 0 : if (params != IF_DEF_PARAMS(ifp)) {
8035 0 : ospf_free_if_params(ifp, addr);
8036 0 : ospf_if_update_params(ifp, addr);
8037 : }
8038 :
8039 0 : ospf_if_recalculate_output_cost(ifp);
8040 :
8041 0 : return CMD_SUCCESS;
8042 : }
8043 :
8044 0 : DEFUN_HIDDEN (no_ospf_cost,
8045 : no_ospf_cost_cmd,
8046 : "no ospf cost [(1-65535)] [A.B.C.D]",
8047 : NO_STR
8048 : "OSPF interface commands\n"
8049 : "Interface cost\n"
8050 : "Cost\n"
8051 : "Address of interface\n")
8052 : {
8053 0 : return no_ip_ospf_cost(self, vty, argc, argv);
8054 : }
8055 :
8056 0 : static void ospf_nbr_timer_update(struct ospf_interface *oi)
8057 : {
8058 0 : struct route_node *rn;
8059 0 : struct ospf_neighbor *nbr;
8060 :
8061 0 : for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) {
8062 0 : nbr = rn->info;
8063 :
8064 0 : if (!nbr)
8065 0 : continue;
8066 :
8067 0 : nbr->v_inactivity = OSPF_IF_PARAM(oi, v_wait);
8068 0 : nbr->v_db_desc = OSPF_IF_PARAM(oi, retransmit_interval);
8069 0 : nbr->v_ls_req = OSPF_IF_PARAM(oi, retransmit_interval);
8070 0 : nbr->v_ls_upd = OSPF_IF_PARAM(oi, retransmit_interval);
8071 : }
8072 0 : }
8073 :
8074 9 : static int ospf_vty_dead_interval_set(struct vty *vty, const char *interval_str,
8075 : const char *nbr_str,
8076 : const char *fast_hello_str)
8077 : {
8078 9 : VTY_DECLVAR_CONTEXT(interface, ifp);
8079 9 : uint32_t seconds;
8080 9 : uint8_t hellomult;
8081 9 : struct in_addr addr;
8082 9 : int ret;
8083 9 : struct ospf_if_params *params;
8084 9 : struct ospf_interface *oi;
8085 9 : struct route_node *rn;
8086 :
8087 9 : params = IF_DEF_PARAMS(ifp);
8088 :
8089 9 : if (nbr_str) {
8090 0 : ret = inet_aton(nbr_str, &addr);
8091 0 : if (!ret) {
8092 0 : vty_out(vty,
8093 : "Please specify interface address by A.B.C.D\n");
8094 0 : return CMD_WARNING_CONFIG_FAILED;
8095 : }
8096 :
8097 0 : params = ospf_get_if_params(ifp, addr);
8098 0 : ospf_if_update_params(ifp, addr);
8099 : }
8100 :
8101 9 : if (interval_str) {
8102 9 : seconds = strtoul(interval_str, NULL, 10);
8103 :
8104 : /* reset fast_hello too, just to be sure */
8105 9 : UNSET_IF_PARAM(params, fast_hello);
8106 9 : params->fast_hello = OSPF_FAST_HELLO_DEFAULT;
8107 0 : } else if (fast_hello_str) {
8108 0 : hellomult = strtoul(fast_hello_str, NULL, 10);
8109 : /* 1s dead-interval with sub-second hellos desired */
8110 0 : seconds = OSPF_ROUTER_DEAD_INTERVAL_MINIMAL;
8111 0 : SET_IF_PARAM(params, fast_hello);
8112 0 : params->fast_hello = hellomult;
8113 : } else {
8114 0 : vty_out(vty,
8115 : "Please specify dead-interval or hello-multiplier\n");
8116 0 : return CMD_WARNING_CONFIG_FAILED;
8117 : }
8118 :
8119 9 : SET_IF_PARAM(params, v_wait);
8120 9 : params->v_wait = seconds;
8121 9 : params->is_v_wait_set = true;
8122 :
8123 : /* Update timer values in neighbor structure. */
8124 9 : if (nbr_str) {
8125 0 : struct ospf *ospf = NULL;
8126 :
8127 0 : ospf = ifp->vrf->info;
8128 0 : if (ospf) {
8129 0 : oi = ospf_if_lookup_by_local_addr(ospf, ifp, addr);
8130 0 : if (oi)
8131 0 : ospf_nbr_timer_update(oi);
8132 : }
8133 : } else {
8134 9 : for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn))
8135 0 : if ((oi = rn->info))
8136 0 : ospf_nbr_timer_update(oi);
8137 : }
8138 :
8139 : return CMD_SUCCESS;
8140 : }
8141 :
8142 9 : DEFUN (ip_ospf_dead_interval,
8143 : ip_ospf_dead_interval_cmd,
8144 : "ip ospf dead-interval (1-65535) [A.B.C.D]",
8145 : "IP Information\n"
8146 : "OSPF interface commands\n"
8147 : "Interval time after which a neighbor is declared down\n"
8148 : "Seconds\n"
8149 : "Address of interface\n")
8150 : {
8151 9 : int idx = 0;
8152 9 : char *interval = argv_find(argv, argc, "(1-65535)", &idx)
8153 9 : ? argv[idx]->arg
8154 9 : : NULL;
8155 18 : char *ifaddr =
8156 9 : argv_find(argv, argc, "A.B.C.D", &idx) ? argv[idx]->arg : NULL;
8157 9 : return ospf_vty_dead_interval_set(vty, interval, ifaddr, NULL);
8158 : }
8159 :
8160 :
8161 0 : DEFUN_HIDDEN (ospf_dead_interval,
8162 : ospf_dead_interval_cmd,
8163 : "ospf dead-interval (1-65535) [A.B.C.D]",
8164 : "OSPF interface commands\n"
8165 : "Interval time after which a neighbor is declared down\n"
8166 : "Seconds\n"
8167 : "Address of interface\n")
8168 : {
8169 0 : return ip_ospf_dead_interval(self, vty, argc, argv);
8170 : }
8171 :
8172 0 : DEFUN (ip_ospf_dead_interval_minimal,
8173 : ip_ospf_dead_interval_minimal_addr_cmd,
8174 : "ip ospf dead-interval minimal hello-multiplier (1-10) [A.B.C.D]",
8175 : "IP Information\n"
8176 : "OSPF interface commands\n"
8177 : "Interval time after which a neighbor is declared down\n"
8178 : "Minimal 1s dead-interval with fast sub-second hellos\n"
8179 : "Hello multiplier factor\n"
8180 : "Number of Hellos to send each second\n"
8181 : "Address of interface\n")
8182 : {
8183 0 : int idx_number = 5;
8184 0 : int idx_ipv4 = 6;
8185 0 : if (argc == 7)
8186 0 : return ospf_vty_dead_interval_set(
8187 0 : vty, NULL, argv[idx_ipv4]->arg, argv[idx_number]->arg);
8188 : else
8189 0 : return ospf_vty_dead_interval_set(vty, NULL, NULL,
8190 0 : argv[idx_number]->arg);
8191 : }
8192 :
8193 0 : DEFUN (no_ip_ospf_dead_interval,
8194 : no_ip_ospf_dead_interval_cmd,
8195 : "no ip ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]",
8196 : NO_STR
8197 : "IP Information\n"
8198 : "OSPF interface commands\n"
8199 : "Interval time after which a neighbor is declared down\n"
8200 : "Seconds\n"
8201 : "Minimal 1s dead-interval with fast sub-second hellos\n"
8202 : "Hello multiplier factor\n"
8203 : "Number of Hellos to send each second\n"
8204 : "Address of interface\n")
8205 : {
8206 0 : VTY_DECLVAR_CONTEXT(interface, ifp);
8207 0 : int idx_ipv4 = argc - 1;
8208 0 : struct in_addr addr = {.s_addr = 0L};
8209 0 : int ret;
8210 0 : struct ospf_if_params *params;
8211 0 : struct ospf_interface *oi;
8212 0 : struct route_node *rn;
8213 :
8214 0 : params = IF_DEF_PARAMS(ifp);
8215 :
8216 0 : if (argv[idx_ipv4]->type == IPV4_TKN) {
8217 0 : ret = inet_aton(argv[idx_ipv4]->arg, &addr);
8218 0 : if (!ret) {
8219 0 : vty_out(vty,
8220 : "Please specify interface address by A.B.C.D\n");
8221 0 : return CMD_WARNING_CONFIG_FAILED;
8222 : }
8223 :
8224 0 : params = ospf_lookup_if_params(ifp, addr);
8225 0 : if (params == NULL)
8226 : return CMD_SUCCESS;
8227 : }
8228 :
8229 0 : UNSET_IF_PARAM(params, v_wait);
8230 0 : params->v_wait = OSPF_ROUTER_DEAD_INTERVAL_DEFAULT;
8231 0 : params->is_v_wait_set = false;
8232 :
8233 0 : UNSET_IF_PARAM(params, fast_hello);
8234 0 : params->fast_hello = OSPF_FAST_HELLO_DEFAULT;
8235 :
8236 0 : if (params != IF_DEF_PARAMS(ifp)) {
8237 0 : ospf_free_if_params(ifp, addr);
8238 0 : ospf_if_update_params(ifp, addr);
8239 : }
8240 :
8241 : /* Update timer values in neighbor structure. */
8242 0 : if (argc == 1) {
8243 0 : struct ospf *ospf = NULL;
8244 :
8245 0 : ospf = ifp->vrf->info;
8246 0 : if (ospf) {
8247 0 : oi = ospf_if_lookup_by_local_addr(ospf, ifp, addr);
8248 0 : if (oi)
8249 0 : ospf_nbr_timer_update(oi);
8250 : }
8251 : } else {
8252 0 : for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn))
8253 0 : if ((oi = rn->info))
8254 0 : ospf_nbr_timer_update(oi);
8255 : }
8256 :
8257 : return CMD_SUCCESS;
8258 : }
8259 :
8260 0 : DEFUN_HIDDEN (no_ospf_dead_interval,
8261 : no_ospf_dead_interval_cmd,
8262 : "no ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]",
8263 : NO_STR
8264 : "OSPF interface commands\n"
8265 : "Interval time after which a neighbor is declared down\n"
8266 : "Seconds\n"
8267 : "Minimal 1s dead-interval with fast sub-second hellos\n"
8268 : "Hello multiplier factor\n"
8269 : "Number of Hellos to send each second\n"
8270 : "Address of interface\n")
8271 : {
8272 0 : return no_ip_ospf_dead_interval(self, vty, argc, argv);
8273 : }
8274 :
8275 9 : DEFUN (ip_ospf_hello_interval,
8276 : ip_ospf_hello_interval_cmd,
8277 : "ip ospf hello-interval (1-65535) [A.B.C.D]",
8278 : "IP Information\n"
8279 : "OSPF interface commands\n"
8280 : "Time between HELLO packets\n"
8281 : "Seconds\n"
8282 : "Address of interface\n")
8283 : {
8284 9 : VTY_DECLVAR_CONTEXT(interface, ifp);
8285 9 : int idx = 0;
8286 9 : struct in_addr addr = {.s_addr = 0L};
8287 9 : struct ospf_if_params *params;
8288 9 : params = IF_DEF_PARAMS(ifp);
8289 9 : uint32_t seconds = 0;
8290 9 : bool is_addr = false;
8291 9 : uint32_t old_interval = 0;
8292 :
8293 9 : argv_find(argv, argc, "(1-65535)", &idx);
8294 9 : seconds = strtol(argv[idx]->arg, NULL, 10);
8295 :
8296 9 : if (argv_find(argv, argc, "A.B.C.D", &idx)) {
8297 0 : if (!inet_aton(argv[idx]->arg, &addr)) {
8298 0 : vty_out(vty,
8299 : "Please specify interface address by A.B.C.D\n");
8300 0 : return CMD_WARNING_CONFIG_FAILED;
8301 : }
8302 :
8303 0 : params = ospf_get_if_params(ifp, addr);
8304 0 : ospf_if_update_params(ifp, addr);
8305 0 : is_addr = true;
8306 : }
8307 :
8308 9 : old_interval = params->v_hello;
8309 :
8310 : /* Return, if same interval is configured. */
8311 9 : if (old_interval == seconds)
8312 : return CMD_SUCCESS;
8313 :
8314 9 : SET_IF_PARAM(params, v_hello);
8315 9 : params->v_hello = seconds;
8316 :
8317 9 : if (!params->is_v_wait_set) {
8318 9 : SET_IF_PARAM(params, v_wait);
8319 : /* As per RFC 4062
8320 : * The router dead interval should
8321 : * be some multiple of the HelloInterval (perhaps 4 times the
8322 : * hello interval) and must be the same for all routers
8323 : * attached to a common network.
8324 : */
8325 9 : params->v_wait = 4 * seconds;
8326 : }
8327 :
8328 9 : ospf_reset_hello_timer(ifp, addr, is_addr);
8329 :
8330 9 : return CMD_SUCCESS;
8331 : }
8332 :
8333 0 : DEFUN_HIDDEN (ospf_hello_interval,
8334 : ospf_hello_interval_cmd,
8335 : "ospf hello-interval (1-65535) [A.B.C.D]",
8336 : "OSPF interface commands\n"
8337 : "Time between HELLO packets\n"
8338 : "Seconds\n"
8339 : "Address of interface\n")
8340 : {
8341 0 : return ip_ospf_hello_interval(self, vty, argc, argv);
8342 : }
8343 :
8344 0 : DEFUN (no_ip_ospf_hello_interval,
8345 : no_ip_ospf_hello_interval_cmd,
8346 : "no ip ospf hello-interval [(1-65535) [A.B.C.D]]",
8347 : NO_STR
8348 : "IP Information\n"
8349 : "OSPF interface commands\n"
8350 : "Time between HELLO packets\n" // ignored
8351 : "Seconds\n"
8352 : "Address of interface\n")
8353 : {
8354 0 : VTY_DECLVAR_CONTEXT(interface, ifp);
8355 0 : int idx = 0;
8356 0 : struct in_addr addr = {.s_addr = 0L};
8357 0 : struct ospf_if_params *params;
8358 0 : struct route_node *rn;
8359 :
8360 0 : params = IF_DEF_PARAMS(ifp);
8361 :
8362 0 : if (argv_find(argv, argc, "A.B.C.D", &idx)) {
8363 0 : if (!inet_aton(argv[idx]->arg, &addr)) {
8364 0 : vty_out(vty,
8365 : "Please specify interface address by A.B.C.D\n");
8366 0 : return CMD_WARNING_CONFIG_FAILED;
8367 : }
8368 :
8369 0 : params = ospf_lookup_if_params(ifp, addr);
8370 0 : if (params == NULL)
8371 : return CMD_SUCCESS;
8372 : }
8373 :
8374 0 : UNSET_IF_PARAM(params, v_hello);
8375 0 : params->v_hello = OSPF_HELLO_INTERVAL_DEFAULT;
8376 :
8377 0 : if (!params->is_v_wait_set) {
8378 0 : UNSET_IF_PARAM(params, v_wait);
8379 0 : params->v_wait = OSPF_ROUTER_DEAD_INTERVAL_DEFAULT;
8380 : }
8381 :
8382 0 : for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) {
8383 0 : struct ospf_interface *oi = rn->info;
8384 :
8385 0 : if (!oi)
8386 0 : continue;
8387 :
8388 0 : oi->type = IF_DEF_PARAMS(ifp)->type;
8389 0 : oi->ptp_dmvpn = IF_DEF_PARAMS(ifp)->ptp_dmvpn;
8390 :
8391 0 : if (oi->state > ISM_Down) {
8392 0 : OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceDown);
8393 0 : OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceUp);
8394 : }
8395 : }
8396 :
8397 0 : if (params != IF_DEF_PARAMS(ifp)) {
8398 0 : ospf_free_if_params(ifp, addr);
8399 0 : ospf_if_update_params(ifp, addr);
8400 : }
8401 :
8402 : return CMD_SUCCESS;
8403 : }
8404 :
8405 0 : DEFUN_HIDDEN (no_ospf_hello_interval,
8406 : no_ospf_hello_interval_cmd,
8407 : "no ospf hello-interval [(1-65535) [A.B.C.D]]",
8408 : NO_STR
8409 : "OSPF interface commands\n"
8410 : "Time between HELLO packets\n" // ignored
8411 : "Seconds\n"
8412 : "Address of interface\n")
8413 : {
8414 0 : return no_ip_ospf_hello_interval(self, vty, argc, argv);
8415 : }
8416 :
8417 0 : DEFUN(ip_ospf_network, ip_ospf_network_cmd,
8418 : "ip ospf network <broadcast|non-broadcast|point-to-multipoint|point-to-point [dmvpn]>",
8419 : "IP Information\n"
8420 : "OSPF interface commands\n"
8421 : "Network type\n"
8422 : "Specify OSPF broadcast multi-access network\n"
8423 : "Specify OSPF NBMA network\n"
8424 : "Specify OSPF point-to-multipoint network\n"
8425 : "Specify OSPF point-to-point network\n"
8426 : "Specify OSPF point-to-point DMVPN network\n")
8427 : {
8428 0 : VTY_DECLVAR_CONTEXT(interface, ifp);
8429 0 : int idx = 0;
8430 0 : int old_type = IF_DEF_PARAMS(ifp)->type;
8431 0 : uint8_t old_ptp_dmvpn = IF_DEF_PARAMS(ifp)->ptp_dmvpn;
8432 0 : struct route_node *rn;
8433 :
8434 0 : if (old_type == OSPF_IFTYPE_LOOPBACK) {
8435 0 : vty_out(vty,
8436 : "This is a loopback interface. Can't set network type.\n");
8437 0 : return CMD_WARNING_CONFIG_FAILED;
8438 : }
8439 :
8440 0 : IF_DEF_PARAMS(ifp)->ptp_dmvpn = 0;
8441 :
8442 0 : if (argv_find(argv, argc, "broadcast", &idx))
8443 0 : IF_DEF_PARAMS(ifp)->type = OSPF_IFTYPE_BROADCAST;
8444 0 : else if (argv_find(argv, argc, "non-broadcast", &idx))
8445 0 : IF_DEF_PARAMS(ifp)->type = OSPF_IFTYPE_NBMA;
8446 0 : else if (argv_find(argv, argc, "point-to-multipoint", &idx))
8447 0 : IF_DEF_PARAMS(ifp)->type = OSPF_IFTYPE_POINTOMULTIPOINT;
8448 0 : else if (argv_find(argv, argc, "point-to-point", &idx)) {
8449 0 : IF_DEF_PARAMS(ifp)->type = OSPF_IFTYPE_POINTOPOINT;
8450 0 : if (argv_find(argv, argc, "dmvpn", &idx))
8451 0 : IF_DEF_PARAMS(ifp)->ptp_dmvpn = 1;
8452 : }
8453 :
8454 0 : if (IF_DEF_PARAMS(ifp)->type == old_type
8455 0 : && IF_DEF_PARAMS(ifp)->ptp_dmvpn == old_ptp_dmvpn)
8456 : return CMD_SUCCESS;
8457 :
8458 0 : SET_IF_PARAM(IF_DEF_PARAMS(ifp), type);
8459 :
8460 0 : for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) {
8461 0 : struct ospf_interface *oi = rn->info;
8462 :
8463 0 : if (!oi)
8464 0 : continue;
8465 :
8466 0 : oi->type = IF_DEF_PARAMS(ifp)->type;
8467 :
8468 0 : if (oi->state > ISM_Down) {
8469 0 : OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceDown);
8470 0 : OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceUp);
8471 : }
8472 : }
8473 :
8474 : return CMD_SUCCESS;
8475 : }
8476 :
8477 0 : DEFUN_HIDDEN (ospf_network,
8478 : ospf_network_cmd,
8479 : "ospf network <broadcast|non-broadcast|point-to-multipoint|point-to-point>",
8480 : "OSPF interface commands\n"
8481 : "Network type\n"
8482 : "Specify OSPF broadcast multi-access network\n"
8483 : "Specify OSPF NBMA network\n"
8484 : "Specify OSPF point-to-multipoint network\n"
8485 : "Specify OSPF point-to-point network\n")
8486 : {
8487 0 : return ip_ospf_network(self, vty, argc, argv);
8488 : }
8489 :
8490 0 : DEFUN (no_ip_ospf_network,
8491 : no_ip_ospf_network_cmd,
8492 : "no ip ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]",
8493 : NO_STR
8494 : "IP Information\n"
8495 : "OSPF interface commands\n"
8496 : "Network type\n"
8497 : "Specify OSPF broadcast multi-access network\n"
8498 : "Specify OSPF NBMA network\n"
8499 : "Specify OSPF point-to-multipoint network\n"
8500 : "Specify OSPF point-to-point network\n")
8501 : {
8502 0 : VTY_DECLVAR_CONTEXT(interface, ifp);
8503 0 : int old_type = IF_DEF_PARAMS(ifp)->type;
8504 0 : struct route_node *rn;
8505 :
8506 0 : IF_DEF_PARAMS(ifp)->type = ospf_default_iftype(ifp);
8507 0 : IF_DEF_PARAMS(ifp)->ptp_dmvpn = 0;
8508 :
8509 0 : if (IF_DEF_PARAMS(ifp)->type == old_type)
8510 : return CMD_SUCCESS;
8511 :
8512 0 : for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) {
8513 0 : struct ospf_interface *oi = rn->info;
8514 :
8515 0 : if (!oi)
8516 0 : continue;
8517 :
8518 0 : oi->type = IF_DEF_PARAMS(ifp)->type;
8519 :
8520 0 : if (oi->state > ISM_Down) {
8521 0 : OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceDown);
8522 0 : OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceUp);
8523 : }
8524 : }
8525 :
8526 : return CMD_SUCCESS;
8527 : }
8528 :
8529 0 : DEFUN_HIDDEN (no_ospf_network,
8530 : no_ospf_network_cmd,
8531 : "no ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]",
8532 : NO_STR
8533 : "OSPF interface commands\n"
8534 : "Network type\n"
8535 : "Specify OSPF broadcast multi-access network\n"
8536 : "Specify OSPF NBMA network\n"
8537 : "Specify OSPF point-to-multipoint network\n"
8538 : "Specify OSPF point-to-point network\n")
8539 : {
8540 0 : return no_ip_ospf_network(self, vty, argc, argv);
8541 : }
8542 :
8543 0 : DEFUN (ip_ospf_priority,
8544 : ip_ospf_priority_cmd,
8545 : "ip ospf priority (0-255) [A.B.C.D]",
8546 : "IP Information\n"
8547 : "OSPF interface commands\n"
8548 : "Router priority\n"
8549 : "Priority\n"
8550 : "Address of interface\n")
8551 : {
8552 0 : VTY_DECLVAR_CONTEXT(interface, ifp);
8553 0 : int idx = 0;
8554 0 : long priority;
8555 0 : struct route_node *rn;
8556 0 : struct in_addr addr;
8557 0 : struct ospf_if_params *params;
8558 0 : params = IF_DEF_PARAMS(ifp);
8559 :
8560 0 : argv_find(argv, argc, "(0-255)", &idx);
8561 0 : priority = strtol(argv[idx]->arg, NULL, 10);
8562 :
8563 0 : if (argv_find(argv, argc, "A.B.C.D", &idx)) {
8564 0 : if (!inet_aton(argv[idx]->arg, &addr)) {
8565 0 : vty_out(vty,
8566 : "Please specify interface address by A.B.C.D\n");
8567 0 : return CMD_WARNING_CONFIG_FAILED;
8568 : }
8569 :
8570 0 : params = ospf_get_if_params(ifp, addr);
8571 0 : ospf_if_update_params(ifp, addr);
8572 : }
8573 :
8574 0 : SET_IF_PARAM(params, priority);
8575 0 : params->priority = priority;
8576 :
8577 0 : for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) {
8578 0 : struct ospf_interface *oi = rn->info;
8579 :
8580 0 : if (!oi)
8581 0 : continue;
8582 :
8583 0 : if (PRIORITY(oi) != OSPF_IF_PARAM(oi, priority)) {
8584 0 : PRIORITY(oi) = OSPF_IF_PARAM(oi, priority);
8585 0 : OSPF_ISM_EVENT_SCHEDULE(oi, ISM_NeighborChange);
8586 : }
8587 : }
8588 :
8589 : return CMD_SUCCESS;
8590 : }
8591 :
8592 0 : DEFUN_HIDDEN (ospf_priority,
8593 : ospf_priority_cmd,
8594 : "ospf priority (0-255) [A.B.C.D]",
8595 : "OSPF interface commands\n"
8596 : "Router priority\n"
8597 : "Priority\n"
8598 : "Address of interface\n")
8599 : {
8600 0 : return ip_ospf_priority(self, vty, argc, argv);
8601 : }
8602 :
8603 0 : DEFUN (no_ip_ospf_priority,
8604 : no_ip_ospf_priority_cmd,
8605 : "no ip ospf priority [(0-255) [A.B.C.D]]",
8606 : NO_STR
8607 : "IP Information\n"
8608 : "OSPF interface commands\n"
8609 : "Router priority\n" // ignored
8610 : "Priority\n"
8611 : "Address of interface\n")
8612 : {
8613 0 : VTY_DECLVAR_CONTEXT(interface, ifp);
8614 0 : int idx = 0;
8615 0 : struct route_node *rn;
8616 0 : struct in_addr addr;
8617 0 : struct ospf_if_params *params;
8618 :
8619 0 : params = IF_DEF_PARAMS(ifp);
8620 :
8621 0 : if (argv_find(argv, argc, "A.B.C.D", &idx)) {
8622 0 : if (!inet_aton(argv[idx]->arg, &addr)) {
8623 0 : vty_out(vty,
8624 : "Please specify interface address by A.B.C.D\n");
8625 0 : return CMD_WARNING_CONFIG_FAILED;
8626 : }
8627 :
8628 0 : params = ospf_lookup_if_params(ifp, addr);
8629 0 : if (params == NULL)
8630 : return CMD_SUCCESS;
8631 : }
8632 :
8633 0 : UNSET_IF_PARAM(params, priority);
8634 0 : params->priority = OSPF_ROUTER_PRIORITY_DEFAULT;
8635 :
8636 0 : if (params != IF_DEF_PARAMS(ifp)) {
8637 0 : ospf_free_if_params(ifp, addr);
8638 0 : ospf_if_update_params(ifp, addr);
8639 : }
8640 :
8641 0 : for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) {
8642 0 : struct ospf_interface *oi = rn->info;
8643 :
8644 0 : if (!oi)
8645 0 : continue;
8646 :
8647 0 : if (PRIORITY(oi) != OSPF_IF_PARAM(oi, priority)) {
8648 0 : PRIORITY(oi) = OSPF_IF_PARAM(oi, priority);
8649 0 : OSPF_ISM_EVENT_SCHEDULE(oi, ISM_NeighborChange);
8650 : }
8651 : }
8652 :
8653 : return CMD_SUCCESS;
8654 : }
8655 :
8656 0 : DEFUN_HIDDEN (no_ospf_priority,
8657 : no_ospf_priority_cmd,
8658 : "no ospf priority [(0-255) [A.B.C.D]]",
8659 : NO_STR
8660 : "OSPF interface commands\n"
8661 : "Router priority\n"
8662 : "Priority\n"
8663 : "Address of interface\n")
8664 : {
8665 0 : return no_ip_ospf_priority(self, vty, argc, argv);
8666 : }
8667 :
8668 9 : DEFUN (ip_ospf_retransmit_interval,
8669 : ip_ospf_retransmit_interval_addr_cmd,
8670 : "ip ospf retransmit-interval (1-65535) [A.B.C.D]",
8671 : "IP Information\n"
8672 : "OSPF interface commands\n"
8673 : "Time between retransmitting lost link state advertisements\n"
8674 : "Seconds\n"
8675 : "Address of interface\n")
8676 : {
8677 9 : VTY_DECLVAR_CONTEXT(interface, ifp);
8678 9 : int idx = 0;
8679 9 : uint32_t seconds;
8680 9 : struct in_addr addr;
8681 9 : struct ospf_if_params *params;
8682 9 : params = IF_DEF_PARAMS(ifp);
8683 :
8684 9 : argv_find(argv, argc, "(1-65535)", &idx);
8685 9 : seconds = strtol(argv[idx]->arg, NULL, 10);
8686 :
8687 9 : if (argv_find(argv, argc, "A.B.C.D", &idx)) {
8688 0 : if (!inet_aton(argv[idx]->arg, &addr)) {
8689 0 : vty_out(vty,
8690 : "Please specify interface address by A.B.C.D\n");
8691 0 : return CMD_WARNING_CONFIG_FAILED;
8692 : }
8693 :
8694 0 : params = ospf_get_if_params(ifp, addr);
8695 0 : ospf_if_update_params(ifp, addr);
8696 : }
8697 :
8698 9 : SET_IF_PARAM(params, retransmit_interval);
8699 9 : params->retransmit_interval = seconds;
8700 :
8701 9 : return CMD_SUCCESS;
8702 : }
8703 :
8704 0 : DEFUN_HIDDEN (ospf_retransmit_interval,
8705 : ospf_retransmit_interval_cmd,
8706 : "ospf retransmit-interval (1-65535) [A.B.C.D]",
8707 : "OSPF interface commands\n"
8708 : "Time between retransmitting lost link state advertisements\n"
8709 : "Seconds\n"
8710 : "Address of interface\n")
8711 : {
8712 0 : return ip_ospf_retransmit_interval(self, vty, argc, argv);
8713 : }
8714 :
8715 0 : DEFUN (no_ip_ospf_retransmit_interval,
8716 : no_ip_ospf_retransmit_interval_addr_cmd,
8717 : "no ip ospf retransmit-interval [(1-65535)] [A.B.C.D]",
8718 : NO_STR
8719 : "IP Information\n"
8720 : "OSPF interface commands\n"
8721 : "Time between retransmitting lost link state advertisements\n"
8722 : "Seconds\n"
8723 : "Address of interface\n")
8724 : {
8725 0 : VTY_DECLVAR_CONTEXT(interface, ifp);
8726 0 : int idx = 0;
8727 0 : struct in_addr addr;
8728 0 : struct ospf_if_params *params;
8729 :
8730 0 : params = IF_DEF_PARAMS(ifp);
8731 :
8732 0 : if (argv_find(argv, argc, "A.B.C.D", &idx)) {
8733 0 : if (!inet_aton(argv[idx]->arg, &addr)) {
8734 0 : vty_out(vty,
8735 : "Please specify interface address by A.B.C.D\n");
8736 0 : return CMD_WARNING_CONFIG_FAILED;
8737 : }
8738 :
8739 0 : params = ospf_lookup_if_params(ifp, addr);
8740 0 : if (params == NULL)
8741 : return CMD_SUCCESS;
8742 : }
8743 :
8744 0 : UNSET_IF_PARAM(params, retransmit_interval);
8745 0 : params->retransmit_interval = OSPF_RETRANSMIT_INTERVAL_DEFAULT;
8746 :
8747 0 : if (params != IF_DEF_PARAMS(ifp)) {
8748 0 : ospf_free_if_params(ifp, addr);
8749 0 : ospf_if_update_params(ifp, addr);
8750 : }
8751 :
8752 : return CMD_SUCCESS;
8753 : }
8754 :
8755 0 : DEFUN_HIDDEN (no_ospf_retransmit_interval,
8756 : no_ospf_retransmit_interval_cmd,
8757 : "no ospf retransmit-interval [(1-65535)] [A.B.C.D]",
8758 : NO_STR
8759 : "OSPF interface commands\n"
8760 : "Time between retransmitting lost link state advertisements\n"
8761 : "Seconds\n"
8762 : "Address of interface\n")
8763 : {
8764 0 : return no_ip_ospf_retransmit_interval(self, vty, argc, argv);
8765 : }
8766 :
8767 0 : DEFUN (ip_ospf_transmit_delay,
8768 : ip_ospf_transmit_delay_addr_cmd,
8769 : "ip ospf transmit-delay (1-65535) [A.B.C.D]",
8770 : "IP Information\n"
8771 : "OSPF interface commands\n"
8772 : "Link state transmit delay\n"
8773 : "Seconds\n"
8774 : "Address of interface\n")
8775 : {
8776 0 : VTY_DECLVAR_CONTEXT(interface, ifp);
8777 0 : int idx = 0;
8778 0 : uint32_t seconds;
8779 0 : struct in_addr addr;
8780 0 : struct ospf_if_params *params;
8781 :
8782 0 : params = IF_DEF_PARAMS(ifp);
8783 0 : argv_find(argv, argc, "(1-65535)", &idx);
8784 0 : seconds = strtol(argv[idx]->arg, NULL, 10);
8785 :
8786 0 : if (argv_find(argv, argc, "A.B.C.D", &idx)) {
8787 0 : if (!inet_aton(argv[idx]->arg, &addr)) {
8788 0 : vty_out(vty,
8789 : "Please specify interface address by A.B.C.D\n");
8790 0 : return CMD_WARNING_CONFIG_FAILED;
8791 : }
8792 :
8793 0 : params = ospf_get_if_params(ifp, addr);
8794 0 : ospf_if_update_params(ifp, addr);
8795 : }
8796 :
8797 0 : SET_IF_PARAM(params, transmit_delay);
8798 0 : params->transmit_delay = seconds;
8799 :
8800 0 : return CMD_SUCCESS;
8801 : }
8802 :
8803 0 : DEFUN_HIDDEN (ospf_transmit_delay,
8804 : ospf_transmit_delay_cmd,
8805 : "ospf transmit-delay (1-65535) [A.B.C.D]",
8806 : "OSPF interface commands\n"
8807 : "Link state transmit delay\n"
8808 : "Seconds\n"
8809 : "Address of interface\n")
8810 : {
8811 0 : return ip_ospf_transmit_delay(self, vty, argc, argv);
8812 : }
8813 :
8814 0 : DEFUN (no_ip_ospf_transmit_delay,
8815 : no_ip_ospf_transmit_delay_addr_cmd,
8816 : "no ip ospf transmit-delay [(1-65535)] [A.B.C.D]",
8817 : NO_STR
8818 : "IP Information\n"
8819 : "OSPF interface commands\n"
8820 : "Link state transmit delay\n"
8821 : "Seconds\n"
8822 : "Address of interface\n")
8823 : {
8824 0 : VTY_DECLVAR_CONTEXT(interface, ifp);
8825 0 : int idx = 0;
8826 0 : struct in_addr addr;
8827 0 : struct ospf_if_params *params;
8828 :
8829 0 : params = IF_DEF_PARAMS(ifp);
8830 :
8831 0 : if (argv_find(argv, argc, "A.B.C.D", &idx)) {
8832 0 : if (!inet_aton(argv[idx]->arg, &addr)) {
8833 0 : vty_out(vty,
8834 : "Please specify interface address by A.B.C.D\n");
8835 0 : return CMD_WARNING_CONFIG_FAILED;
8836 : }
8837 :
8838 0 : params = ospf_lookup_if_params(ifp, addr);
8839 0 : if (params == NULL)
8840 : return CMD_SUCCESS;
8841 : }
8842 :
8843 0 : UNSET_IF_PARAM(params, transmit_delay);
8844 0 : params->transmit_delay = OSPF_TRANSMIT_DELAY_DEFAULT;
8845 :
8846 0 : if (params != IF_DEF_PARAMS(ifp)) {
8847 0 : ospf_free_if_params(ifp, addr);
8848 0 : ospf_if_update_params(ifp, addr);
8849 : }
8850 :
8851 : return CMD_SUCCESS;
8852 : }
8853 :
8854 :
8855 0 : DEFUN_HIDDEN (no_ospf_transmit_delay,
8856 : no_ospf_transmit_delay_cmd,
8857 : "no ospf transmit-delay [(1-65535) [A.B.C.D]]",
8858 : NO_STR
8859 : "OSPF interface commands\n"
8860 : "Link state transmit delay\n"
8861 : "Seconds\n"
8862 : "Address of interface\n")
8863 : {
8864 0 : return no_ip_ospf_transmit_delay(self, vty, argc, argv);
8865 : }
8866 :
8867 0 : DEFUN (ip_ospf_area,
8868 : ip_ospf_area_cmd,
8869 : "ip ospf [(1-65535)] area <A.B.C.D|(0-4294967295)> [A.B.C.D]",
8870 : "IP Information\n"
8871 : "OSPF interface commands\n"
8872 : "Instance ID\n"
8873 : "Enable OSPF on this interface\n"
8874 : "OSPF area ID in IP address format\n"
8875 : "OSPF area ID as a decimal value\n"
8876 : "Address of interface\n")
8877 : {
8878 0 : VTY_DECLVAR_CONTEXT(interface, ifp);
8879 0 : int idx = 0;
8880 0 : int format, ret;
8881 0 : struct in_addr area_id;
8882 0 : struct in_addr addr;
8883 0 : struct ospf_if_params *params = NULL;
8884 0 : struct route_node *rn;
8885 0 : struct ospf *ospf = NULL;
8886 0 : unsigned short instance = 0;
8887 0 : char *areaid;
8888 0 : uint32_t count = 0;
8889 :
8890 0 : if (argv_find(argv, argc, "(1-65535)", &idx))
8891 0 : instance = strtol(argv[idx]->arg, NULL, 10);
8892 :
8893 0 : argv_find(argv, argc, "area", &idx);
8894 0 : areaid = argv[idx + 1]->arg;
8895 :
8896 0 : if (!instance)
8897 0 : ospf = ifp->vrf->info;
8898 : else
8899 0 : ospf = ospf_lookup_instance(instance);
8900 :
8901 0 : if (instance && instance != ospf_instance) {
8902 : /*
8903 : * At this point we know we have received
8904 : * an instance and there is no ospf instance
8905 : * associated with it. This means we are
8906 : * in a situation where we have an
8907 : * ospf command that is setup for a different
8908 : * process(instance). We need to safely
8909 : * remove the command from ourselves and
8910 : * allow the other instance(process) handle
8911 : * the configuration command.
8912 : */
8913 0 : count = 0;
8914 :
8915 0 : params = IF_DEF_PARAMS(ifp);
8916 0 : if (OSPF_IF_PARAM_CONFIGURED(params, if_area)) {
8917 0 : UNSET_IF_PARAM(params, if_area);
8918 0 : count++;
8919 : }
8920 :
8921 0 : for (rn = route_top(IF_OIFS_PARAMS(ifp)); rn; rn = route_next(rn))
8922 0 : if ((params = rn->info) && OSPF_IF_PARAM_CONFIGURED(params, if_area)) {
8923 0 : UNSET_IF_PARAM(params, if_area);
8924 0 : count++;
8925 : }
8926 :
8927 0 : if (count > 0) {
8928 0 : ospf = ifp->vrf->info;
8929 0 : if (ospf)
8930 0 : ospf_interface_area_unset(ospf, ifp);
8931 : }
8932 :
8933 0 : return CMD_NOT_MY_INSTANCE;
8934 : }
8935 :
8936 0 : ret = str2area_id(areaid, &area_id, &format);
8937 0 : if (ret < 0) {
8938 0 : vty_out(vty, "Please specify area by A.B.C.D|<0-4294967295>\n");
8939 0 : return CMD_WARNING_CONFIG_FAILED;
8940 : }
8941 0 : if (memcmp(ifp->name, "VLINK", 5) == 0) {
8942 0 : vty_out(vty, "Cannot enable OSPF on a virtual link.\n");
8943 0 : return CMD_WARNING_CONFIG_FAILED;
8944 : }
8945 :
8946 0 : if (ospf) {
8947 0 : for (rn = route_top(ospf->networks); rn; rn = route_next(rn)) {
8948 0 : if (rn->info != NULL) {
8949 0 : vty_out(vty,
8950 : "Please remove all network commands first.\n");
8951 0 : return CMD_WARNING_CONFIG_FAILED;
8952 : }
8953 : }
8954 : }
8955 :
8956 0 : params = IF_DEF_PARAMS(ifp);
8957 0 : if (OSPF_IF_PARAM_CONFIGURED(params, if_area)
8958 0 : && !IPV4_ADDR_SAME(¶ms->if_area, &area_id)) {
8959 0 : vty_out(vty,
8960 : "Must remove previous area config before changing ospf area \n");
8961 0 : return CMD_WARNING_CONFIG_FAILED;
8962 : }
8963 :
8964 : // Check if we have an address arg and proccess it
8965 0 : if (argc == idx + 3) {
8966 0 : if (!inet_aton(argv[idx + 2]->arg, &addr)) {
8967 0 : vty_out(vty,
8968 : "Please specify Intf Address by A.B.C.D\n");
8969 0 : return CMD_WARNING_CONFIG_FAILED;
8970 : }
8971 : // update/create address-level params
8972 0 : params = ospf_get_if_params((ifp), (addr));
8973 0 : if (OSPF_IF_PARAM_CONFIGURED(params, if_area)) {
8974 0 : if (!IPV4_ADDR_SAME(¶ms->if_area, &area_id)) {
8975 0 : vty_out(vty,
8976 : "Must remove previous area/address config before changing ospf area\n");
8977 0 : return CMD_WARNING_CONFIG_FAILED;
8978 : } else
8979 : return CMD_SUCCESS;
8980 : }
8981 0 : ospf_if_update_params((ifp), (addr));
8982 : }
8983 :
8984 : /* enable ospf on this interface with area_id */
8985 0 : if (params) {
8986 0 : SET_IF_PARAM(params, if_area);
8987 0 : params->if_area = area_id;
8988 0 : params->if_area_id_fmt = format;
8989 : }
8990 :
8991 0 : if (ospf)
8992 0 : ospf_interface_area_set(ospf, ifp);
8993 :
8994 : return CMD_SUCCESS;
8995 : }
8996 :
8997 0 : DEFUN (no_ip_ospf_area,
8998 : no_ip_ospf_area_cmd,
8999 : "no ip ospf [(1-65535)] area [<A.B.C.D|(0-4294967295)> [A.B.C.D]]",
9000 : NO_STR
9001 : "IP Information\n"
9002 : "OSPF interface commands\n"
9003 : "Instance ID\n"
9004 : "Disable OSPF on this interface\n"
9005 : "OSPF area ID in IP address format\n"
9006 : "OSPF area ID as a decimal value\n"
9007 : "Address of interface\n")
9008 : {
9009 0 : VTY_DECLVAR_CONTEXT(interface, ifp);
9010 0 : int idx = 0;
9011 0 : struct ospf *ospf;
9012 0 : struct ospf_if_params *params;
9013 0 : unsigned short instance = 0;
9014 0 : struct in_addr addr;
9015 0 : struct in_addr area_id;
9016 :
9017 0 : if (argv_find(argv, argc, "(1-65535)", &idx))
9018 0 : instance = strtol(argv[idx]->arg, NULL, 10);
9019 :
9020 0 : if (!instance)
9021 0 : ospf = ifp->vrf->info;
9022 : else
9023 0 : ospf = ospf_lookup_instance(instance);
9024 :
9025 0 : if (instance && instance != ospf_instance)
9026 : return CMD_NOT_MY_INSTANCE;
9027 :
9028 0 : argv_find(argv, argc, "area", &idx);
9029 :
9030 : // Check if we have an address arg and proccess it
9031 0 : if (argc == idx + 3) {
9032 0 : if (!inet_aton(argv[idx + 2]->arg, &addr)) {
9033 0 : vty_out(vty,
9034 : "Please specify Intf Address by A.B.C.D\n");
9035 0 : return CMD_WARNING_CONFIG_FAILED;
9036 : }
9037 0 : params = ospf_lookup_if_params(ifp, addr);
9038 0 : if ((params) == NULL)
9039 : return CMD_SUCCESS;
9040 : } else
9041 0 : params = IF_DEF_PARAMS(ifp);
9042 :
9043 0 : area_id = params->if_area;
9044 0 : if (!OSPF_IF_PARAM_CONFIGURED(params, if_area)) {
9045 0 : vty_out(vty,
9046 : "Can't find specified interface area configuration.\n");
9047 0 : return CMD_WARNING_CONFIG_FAILED;
9048 : }
9049 :
9050 0 : UNSET_IF_PARAM(params, if_area);
9051 0 : if (params != IF_DEF_PARAMS((ifp))) {
9052 0 : ospf_free_if_params((ifp), (addr));
9053 0 : ospf_if_update_params((ifp), (addr));
9054 : }
9055 :
9056 0 : if (ospf) {
9057 0 : ospf_interface_area_unset(ospf, ifp);
9058 0 : ospf_area_check_free(ospf, area_id);
9059 : }
9060 :
9061 : return CMD_SUCCESS;
9062 : }
9063 :
9064 0 : DEFUN (ip_ospf_passive,
9065 : ip_ospf_passive_cmd,
9066 : "ip ospf passive [A.B.C.D]",
9067 : "IP Information\n"
9068 : "OSPF interface commands\n"
9069 : "Suppress routing updates on an interface\n"
9070 : "Address of interface\n")
9071 : {
9072 0 : VTY_DECLVAR_CONTEXT(interface, ifp);
9073 0 : int idx_ipv4 = 3;
9074 0 : struct in_addr addr = {.s_addr = INADDR_ANY};
9075 0 : struct ospf_if_params *params;
9076 0 : int ret;
9077 :
9078 0 : if (argc == 4) {
9079 0 : ret = inet_aton(argv[idx_ipv4]->arg, &addr);
9080 0 : if (!ret) {
9081 0 : vty_out(vty,
9082 : "Please specify interface address by A.B.C.D\n");
9083 0 : return CMD_WARNING_CONFIG_FAILED;
9084 : }
9085 0 : params = ospf_get_if_params(ifp, addr);
9086 0 : ospf_if_update_params(ifp, addr);
9087 : } else {
9088 0 : params = IF_DEF_PARAMS(ifp);
9089 : }
9090 :
9091 0 : ospf_passive_interface_update(ifp, params, addr, OSPF_IF_PASSIVE);
9092 :
9093 0 : return CMD_SUCCESS;
9094 : }
9095 :
9096 0 : DEFUN (no_ip_ospf_passive,
9097 : no_ip_ospf_passive_cmd,
9098 : "no ip ospf passive [A.B.C.D]",
9099 : NO_STR
9100 : "IP Information\n"
9101 : "OSPF interface commands\n"
9102 : "Enable routing updates on an interface\n"
9103 : "Address of interface\n")
9104 : {
9105 0 : VTY_DECLVAR_CONTEXT(interface, ifp);
9106 0 : int idx_ipv4 = 4;
9107 0 : struct in_addr addr = {.s_addr = INADDR_ANY};
9108 0 : struct ospf_if_params *params;
9109 0 : int ret;
9110 :
9111 0 : if (argc == 5) {
9112 0 : ret = inet_aton(argv[idx_ipv4]->arg, &addr);
9113 0 : if (!ret) {
9114 0 : vty_out(vty,
9115 : "Please specify interface address by A.B.C.D\n");
9116 0 : return CMD_WARNING_CONFIG_FAILED;
9117 : }
9118 0 : params = ospf_lookup_if_params(ifp, addr);
9119 0 : if (params == NULL)
9120 : return CMD_SUCCESS;
9121 : } else {
9122 0 : params = IF_DEF_PARAMS(ifp);
9123 : }
9124 :
9125 0 : ospf_passive_interface_update(ifp, params, addr, OSPF_IF_ACTIVE);
9126 :
9127 0 : return CMD_SUCCESS;
9128 : }
9129 :
9130 4 : DEFUN (ospf_redistribute_source,
9131 : ospf_redistribute_source_cmd,
9132 : "redistribute " FRR_REDIST_STR_OSPFD " [{metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]",
9133 : REDIST_STR
9134 : FRR_REDIST_HELP_STR_OSPFD
9135 : "Metric for redistributed routes\n"
9136 : "OSPF default metric\n"
9137 : "OSPF exterior metric type for redistributed routes\n"
9138 : "Set OSPF External Type 1/2 metrics\n"
9139 : "Route map reference\n"
9140 : "Pointer to route-map entries\n")
9141 : {
9142 4 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9143 4 : int idx_protocol = 1;
9144 4 : int source;
9145 4 : int type = -1;
9146 4 : int metric = -1;
9147 4 : struct ospf_redist *red;
9148 4 : int idx = 0;
9149 4 : bool update = false;
9150 :
9151 : /* Get distribute source. */
9152 4 : source = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
9153 4 : if (source < 0)
9154 : return CMD_WARNING_CONFIG_FAILED;
9155 :
9156 : /* Get metric value. */
9157 4 : if (argv_find(argv, argc, "(0-16777214)", &idx)) {
9158 0 : if (!str2metric(argv[idx]->arg, &metric))
9159 : return CMD_WARNING_CONFIG_FAILED;
9160 : }
9161 4 : idx = 1;
9162 : /* Get metric type. */
9163 4 : if (argv_find(argv, argc, "(1-2)", &idx)) {
9164 0 : if (!str2metric_type(argv[idx]->arg, &type))
9165 : return CMD_WARNING_CONFIG_FAILED;
9166 : }
9167 4 : idx = 1;
9168 :
9169 4 : red = ospf_redist_lookup(ospf, source, 0);
9170 4 : if (!red)
9171 4 : red = ospf_redist_add(ospf, source, 0);
9172 : else
9173 : update = true;
9174 :
9175 : /* Get route-map */
9176 4 : if (argv_find(argv, argc, "route-map", &idx)) {
9177 0 : ospf_routemap_set(red, argv[idx + 1]->arg);
9178 : } else
9179 4 : ospf_routemap_unset(red);
9180 :
9181 4 : if (update)
9182 0 : return ospf_redistribute_update(ospf, red, source, 0, type,
9183 : metric);
9184 : else
9185 4 : return ospf_redistribute_set(ospf, red, source, 0, type,
9186 : metric);
9187 : }
9188 :
9189 0 : DEFUN (no_ospf_redistribute_source,
9190 : no_ospf_redistribute_source_cmd,
9191 : "no redistribute " FRR_REDIST_STR_OSPFD " [{metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]",
9192 : NO_STR
9193 : REDIST_STR
9194 : FRR_REDIST_HELP_STR_OSPFD
9195 : "Metric for redistributed routes\n"
9196 : "OSPF default metric\n"
9197 : "OSPF exterior metric type for redistributed routes\n"
9198 : "Set OSPF External Type 1/2 metrics\n"
9199 : "Route map reference\n"
9200 : "Pointer to route-map entries\n")
9201 : {
9202 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9203 0 : int idx_protocol = 2;
9204 0 : int source;
9205 0 : struct ospf_redist *red;
9206 :
9207 0 : source = proto_redistnum(AFI_IP, argv[idx_protocol]->text);
9208 0 : if (source < 0)
9209 : return CMD_WARNING_CONFIG_FAILED;
9210 :
9211 0 : red = ospf_redist_lookup(ospf, source, 0);
9212 0 : if (!red)
9213 : return CMD_SUCCESS;
9214 :
9215 0 : ospf_routemap_unset(red);
9216 0 : ospf_redist_del(ospf, source, 0);
9217 :
9218 0 : return ospf_redistribute_unset(ospf, source, 0);
9219 : }
9220 :
9221 0 : DEFUN (ospf_redistribute_instance_source,
9222 : ospf_redistribute_instance_source_cmd,
9223 : "redistribute <ospf|table> (1-65535) [{metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]",
9224 : REDIST_STR
9225 : "Open Shortest Path First\n"
9226 : "Non-main Kernel Routing Table\n"
9227 : "Instance ID/Table ID\n"
9228 : "Metric for redistributed routes\n"
9229 : "OSPF default metric\n"
9230 : "OSPF exterior metric type for redistributed routes\n"
9231 : "Set OSPF External Type 1/2 metrics\n"
9232 : "Route map reference\n"
9233 : "Pointer to route-map entries\n")
9234 : {
9235 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9236 0 : int idx_ospf_table = 1;
9237 0 : int idx_number = 2;
9238 0 : int idx = 3;
9239 0 : int source;
9240 0 : int type = -1;
9241 0 : int metric = -1;
9242 0 : unsigned short instance;
9243 0 : struct ospf_redist *red;
9244 0 : bool update = false;
9245 :
9246 0 : source = proto_redistnum(AFI_IP, argv[idx_ospf_table]->text);
9247 :
9248 0 : if (source < 0) {
9249 0 : vty_out(vty, "Unknown instance redistribution\n");
9250 0 : return CMD_WARNING_CONFIG_FAILED;
9251 : }
9252 :
9253 0 : instance = strtoul(argv[idx_number]->arg, NULL, 10);
9254 :
9255 0 : if ((source == ZEBRA_ROUTE_OSPF) && !ospf->instance) {
9256 0 : vty_out(vty,
9257 : "Instance redistribution in non-instanced OSPF not allowed\n");
9258 0 : return CMD_WARNING_CONFIG_FAILED;
9259 : }
9260 :
9261 0 : if ((source == ZEBRA_ROUTE_OSPF) && (ospf->instance == instance)) {
9262 0 : vty_out(vty, "Same instance OSPF redistribution not allowed\n");
9263 0 : return CMD_WARNING_CONFIG_FAILED;
9264 : }
9265 :
9266 : /* Get metric value. */
9267 0 : if (argv_find(argv, argc, "metric", &idx))
9268 0 : if (!str2metric(argv[idx + 1]->arg, &metric))
9269 : return CMD_WARNING_CONFIG_FAILED;
9270 :
9271 0 : idx = 3;
9272 : /* Get metric type. */
9273 0 : if (argv_find(argv, argc, "metric-type", &idx))
9274 0 : if (!str2metric_type(argv[idx + 1]->arg, &type))
9275 : return CMD_WARNING_CONFIG_FAILED;
9276 :
9277 0 : red = ospf_redist_lookup(ospf, source, instance);
9278 0 : if (!red)
9279 0 : red = ospf_redist_add(ospf, source, instance);
9280 : else
9281 : update = true;
9282 :
9283 0 : idx = 3;
9284 0 : if (argv_find(argv, argc, "route-map", &idx))
9285 0 : ospf_routemap_set(red, argv[idx + 1]->arg);
9286 : else
9287 0 : ospf_routemap_unset(red);
9288 :
9289 0 : if (update)
9290 0 : return ospf_redistribute_update(ospf, red, source, instance,
9291 : type, metric);
9292 : else
9293 0 : return ospf_redistribute_set(ospf, red, source, instance, type,
9294 : metric);
9295 : }
9296 :
9297 0 : DEFUN (no_ospf_redistribute_instance_source,
9298 : no_ospf_redistribute_instance_source_cmd,
9299 : "no redistribute <ospf|table> (1-65535) [{metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]",
9300 : NO_STR
9301 : REDIST_STR
9302 : "Open Shortest Path First\n"
9303 : "Non-main Kernel Routing Table\n"
9304 : "Instance ID/Table Id\n"
9305 : "Metric for redistributed routes\n"
9306 : "OSPF default metric\n"
9307 : "OSPF exterior metric type for redistributed routes\n"
9308 : "Set OSPF External Type 1/2 metrics\n"
9309 : "Route map reference\n"
9310 : "Pointer to route-map entries\n")
9311 : {
9312 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9313 0 : int idx_ospf_table = 2;
9314 0 : int idx_number = 3;
9315 0 : unsigned int instance;
9316 0 : struct ospf_redist *red;
9317 0 : int source;
9318 :
9319 0 : if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0)
9320 : source = ZEBRA_ROUTE_OSPF;
9321 : else
9322 0 : source = ZEBRA_ROUTE_TABLE;
9323 :
9324 0 : instance = strtoul(argv[idx_number]->arg, NULL, 10);
9325 :
9326 0 : if ((source == ZEBRA_ROUTE_OSPF) && !ospf->instance) {
9327 0 : vty_out(vty,
9328 : "Instance redistribution in non-instanced OSPF not allowed\n");
9329 0 : return CMD_WARNING_CONFIG_FAILED;
9330 : }
9331 :
9332 0 : if ((source == ZEBRA_ROUTE_OSPF) && (ospf->instance == instance)) {
9333 0 : vty_out(vty, "Same instance OSPF redistribution not allowed\n");
9334 0 : return CMD_WARNING_CONFIG_FAILED;
9335 : }
9336 :
9337 0 : red = ospf_redist_lookup(ospf, source, instance);
9338 0 : if (!red)
9339 : return CMD_SUCCESS;
9340 :
9341 0 : ospf_routemap_unset(red);
9342 0 : ospf_redist_del(ospf, source, instance);
9343 :
9344 0 : return ospf_redistribute_unset(ospf, source, instance);
9345 : }
9346 :
9347 0 : DEFUN (ospf_distribute_list_out,
9348 : ospf_distribute_list_out_cmd,
9349 : "distribute-list ACCESSLIST4_NAME out " FRR_REDIST_STR_OSPFD,
9350 : "Filter networks in routing updates\n"
9351 : "Access-list name\n"
9352 : OUT_STR
9353 : FRR_REDIST_HELP_STR_OSPFD)
9354 : {
9355 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9356 0 : int idx_word = 1;
9357 0 : int source;
9358 :
9359 0 : char *proto = argv[argc - 1]->text;
9360 :
9361 : /* Get distribute source. */
9362 0 : source = proto_redistnum(AFI_IP, proto);
9363 0 : if (source < 0)
9364 : return CMD_WARNING_CONFIG_FAILED;
9365 :
9366 0 : return ospf_distribute_list_out_set(ospf, source, argv[idx_word]->arg);
9367 : }
9368 :
9369 0 : DEFUN (no_ospf_distribute_list_out,
9370 : no_ospf_distribute_list_out_cmd,
9371 : "no distribute-list ACCESSLIST4_NAME out " FRR_REDIST_STR_OSPFD,
9372 : NO_STR
9373 : "Filter networks in routing updates\n"
9374 : "Access-list name\n"
9375 : OUT_STR
9376 : FRR_REDIST_HELP_STR_OSPFD)
9377 : {
9378 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9379 0 : int idx_word = 2;
9380 0 : int source;
9381 :
9382 0 : char *proto = argv[argc - 1]->text;
9383 0 : source = proto_redistnum(AFI_IP, proto);
9384 0 : if (source < 0)
9385 : return CMD_WARNING_CONFIG_FAILED;
9386 :
9387 0 : return ospf_distribute_list_out_unset(ospf, source,
9388 0 : argv[idx_word]->arg);
9389 : }
9390 :
9391 : /* Default information originate. */
9392 0 : DEFUN (ospf_default_information_originate,
9393 : ospf_default_information_originate_cmd,
9394 : "default-information originate [{always|metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]",
9395 : "Control distribution of default information\n"
9396 : "Distribute a default route\n"
9397 : "Always advertise default route\n"
9398 : "OSPF default metric\n"
9399 : "OSPF metric\n"
9400 : "OSPF metric type for default routes\n"
9401 : "Set OSPF External Type 1/2 metrics\n"
9402 : "Route map reference\n"
9403 : "Pointer to route-map entries\n")
9404 : {
9405 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9406 0 : int default_originate = DEFAULT_ORIGINATE_ZEBRA;
9407 0 : int type = -1;
9408 0 : int metric = -1;
9409 0 : struct ospf_redist *red;
9410 0 : int idx = 0;
9411 0 : int cur_originate = ospf->default_originate;
9412 0 : bool sameRtmap = false;
9413 0 : char *rtmap = NULL;
9414 :
9415 0 : red = ospf_redist_add(ospf, DEFAULT_ROUTE, 0);
9416 :
9417 : /* Check whether "always" was specified */
9418 0 : if (argv_find(argv, argc, "always", &idx))
9419 0 : default_originate = DEFAULT_ORIGINATE_ALWAYS;
9420 0 : idx = 1;
9421 : /* Get metric value */
9422 0 : if (argv_find(argv, argc, "(0-16777214)", &idx)) {
9423 0 : if (!str2metric(argv[idx]->arg, &metric))
9424 : return CMD_WARNING_CONFIG_FAILED;
9425 : }
9426 0 : idx = 1;
9427 : /* Get metric type. */
9428 0 : if (argv_find(argv, argc, "(1-2)", &idx)) {
9429 0 : if (!str2metric_type(argv[idx]->arg, &type))
9430 : return CMD_WARNING_CONFIG_FAILED;
9431 : }
9432 0 : idx = 1;
9433 : /* Get route-map */
9434 0 : if (argv_find(argv, argc, "route-map", &idx))
9435 0 : rtmap = argv[idx + 1]->arg;
9436 :
9437 : /* To check if user is providing same route map */
9438 0 : if ((!rtmap && !ROUTEMAP_NAME(red)) ||
9439 0 : (rtmap && ROUTEMAP_NAME(red) &&
9440 0 : (strcmp(rtmap, ROUTEMAP_NAME(red)) == 0)))
9441 0 : sameRtmap = true;
9442 :
9443 : /* Don't allow if the same lsa is already originated. */
9444 0 : if ((sameRtmap)
9445 0 : && (red->dmetric.type == type)
9446 0 : && (red->dmetric.value == metric)
9447 0 : && (cur_originate == default_originate))
9448 : return CMD_SUCCESS;
9449 :
9450 : /* Updating Metric details */
9451 0 : red->dmetric.type = type;
9452 0 : red->dmetric.value = metric;
9453 :
9454 : /* updating route map details */
9455 0 : if (rtmap)
9456 0 : ospf_routemap_set(red, rtmap);
9457 : else
9458 0 : ospf_routemap_unset(red);
9459 :
9460 0 : return ospf_redistribute_default_set(ospf, default_originate, type,
9461 : metric);
9462 : }
9463 :
9464 0 : DEFUN (no_ospf_default_information_originate,
9465 : no_ospf_default_information_originate_cmd,
9466 : "no default-information originate [{always|metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]",
9467 : NO_STR
9468 : "Control distribution of default information\n"
9469 : "Distribute a default route\n"
9470 : "Always advertise default route\n"
9471 : "OSPF default metric\n"
9472 : "OSPF metric\n"
9473 : "OSPF metric type for default routes\n"
9474 : "Set OSPF External Type 1/2 metrics\n"
9475 : "Route map reference\n"
9476 : "Pointer to route-map entries\n")
9477 : {
9478 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9479 0 : struct ospf_redist *red;
9480 :
9481 0 : red = ospf_redist_lookup(ospf, DEFAULT_ROUTE, 0);
9482 0 : if (!red)
9483 : return CMD_SUCCESS;
9484 :
9485 0 : ospf_routemap_unset(red);
9486 0 : ospf_redist_del(ospf, DEFAULT_ROUTE, 0);
9487 :
9488 0 : return ospf_redistribute_default_set(ospf, DEFAULT_ORIGINATE_NONE,
9489 : 0, 0);
9490 : }
9491 :
9492 0 : DEFUN (ospf_default_metric,
9493 : ospf_default_metric_cmd,
9494 : "default-metric (0-16777214)",
9495 : "Set metric of redistributed routes\n"
9496 : "Default metric\n")
9497 : {
9498 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9499 0 : int idx_number = 1;
9500 0 : int metric = -1;
9501 :
9502 0 : if (!str2metric(argv[idx_number]->arg, &metric))
9503 : return CMD_WARNING_CONFIG_FAILED;
9504 :
9505 0 : ospf->default_metric = metric;
9506 :
9507 0 : return CMD_SUCCESS;
9508 : }
9509 :
9510 0 : DEFUN (no_ospf_default_metric,
9511 : no_ospf_default_metric_cmd,
9512 : "no default-metric [(0-16777214)]",
9513 : NO_STR
9514 : "Set metric of redistributed routes\n"
9515 : "Default metric\n")
9516 : {
9517 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9518 :
9519 0 : ospf->default_metric = -1;
9520 :
9521 0 : return CMD_SUCCESS;
9522 : }
9523 :
9524 :
9525 0 : DEFUN (ospf_distance,
9526 : ospf_distance_cmd,
9527 : "distance (1-255)",
9528 : "Administrative distance\n"
9529 : "OSPF Administrative distance\n")
9530 : {
9531 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9532 0 : int idx_number = 1;
9533 0 : uint8_t distance;
9534 :
9535 0 : distance = atoi(argv[idx_number]->arg);
9536 0 : if (ospf->distance_all != distance) {
9537 0 : ospf->distance_all = distance;
9538 0 : ospf_restart_spf(ospf);
9539 : }
9540 :
9541 : return CMD_SUCCESS;
9542 : }
9543 :
9544 0 : DEFUN (no_ospf_distance,
9545 : no_ospf_distance_cmd,
9546 : "no distance (1-255)",
9547 : NO_STR
9548 : "Administrative distance\n"
9549 : "OSPF Administrative distance\n")
9550 : {
9551 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9552 :
9553 0 : if (ospf->distance_all) {
9554 0 : ospf->distance_all = 0;
9555 0 : ospf_restart_spf(ospf);
9556 : }
9557 :
9558 : return CMD_SUCCESS;
9559 : }
9560 :
9561 0 : DEFUN (no_ospf_distance_ospf,
9562 : no_ospf_distance_ospf_cmd,
9563 : "no distance ospf [{intra-area [(1-255)]|inter-area [(1-255)]|external [(1-255)]}]",
9564 : NO_STR
9565 : "Administrative distance\n"
9566 : "OSPF administrative distance\n"
9567 : "Intra-area routes\n"
9568 : "Distance for intra-area routes\n"
9569 : "Inter-area routes\n"
9570 : "Distance for inter-area routes\n"
9571 : "External routes\n"
9572 : "Distance for external routes\n")
9573 : {
9574 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9575 0 : int idx = 0;
9576 :
9577 0 : if (argv_find(argv, argc, "intra-area", &idx) || argc == 3)
9578 0 : idx = ospf->distance_intra = 0;
9579 0 : if (argv_find(argv, argc, "inter-area", &idx) || argc == 3)
9580 0 : idx = ospf->distance_inter = 0;
9581 0 : if (argv_find(argv, argc, "external", &idx) || argc == 3)
9582 0 : ospf->distance_external = 0;
9583 :
9584 : return CMD_SUCCESS;
9585 : }
9586 :
9587 0 : DEFUN (ospf_distance_ospf,
9588 : ospf_distance_ospf_cmd,
9589 : "distance ospf {intra-area (1-255)|inter-area (1-255)|external (1-255)}",
9590 : "Administrative distance\n"
9591 : "OSPF administrative distance\n"
9592 : "Intra-area routes\n"
9593 : "Distance for intra-area routes\n"
9594 : "Inter-area routes\n"
9595 : "Distance for inter-area routes\n"
9596 : "External routes\n"
9597 : "Distance for external routes\n")
9598 : {
9599 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9600 0 : int idx = 0;
9601 :
9602 0 : ospf->distance_intra = 0;
9603 0 : ospf->distance_inter = 0;
9604 0 : ospf->distance_external = 0;
9605 :
9606 0 : if (argv_find(argv, argc, "intra-area", &idx))
9607 0 : ospf->distance_intra = atoi(argv[idx + 1]->arg);
9608 0 : idx = 0;
9609 0 : if (argv_find(argv, argc, "inter-area", &idx))
9610 0 : ospf->distance_inter = atoi(argv[idx + 1]->arg);
9611 0 : idx = 0;
9612 0 : if (argv_find(argv, argc, "external", &idx))
9613 0 : ospf->distance_external = atoi(argv[idx + 1]->arg);
9614 :
9615 : return CMD_SUCCESS;
9616 : }
9617 :
9618 0 : DEFUN (ip_ospf_mtu_ignore,
9619 : ip_ospf_mtu_ignore_addr_cmd,
9620 : "ip ospf mtu-ignore [A.B.C.D]",
9621 : "IP Information\n"
9622 : "OSPF interface commands\n"
9623 : "Disable MTU mismatch detection on this interface\n"
9624 : "Address of interface\n")
9625 : {
9626 0 : VTY_DECLVAR_CONTEXT(interface, ifp);
9627 0 : int idx_ipv4 = 3;
9628 0 : struct in_addr addr;
9629 0 : int ret;
9630 :
9631 0 : struct ospf_if_params *params;
9632 0 : params = IF_DEF_PARAMS(ifp);
9633 :
9634 0 : if (argc == 4) {
9635 0 : ret = inet_aton(argv[idx_ipv4]->arg, &addr);
9636 0 : if (!ret) {
9637 0 : vty_out(vty,
9638 : "Please specify interface address by A.B.C.D\n");
9639 0 : return CMD_WARNING_CONFIG_FAILED;
9640 : }
9641 0 : params = ospf_get_if_params(ifp, addr);
9642 0 : ospf_if_update_params(ifp, addr);
9643 : }
9644 0 : params->mtu_ignore = 1;
9645 0 : if (params->mtu_ignore != OSPF_MTU_IGNORE_DEFAULT)
9646 0 : SET_IF_PARAM(params, mtu_ignore);
9647 : else {
9648 : UNSET_IF_PARAM(params, mtu_ignore);
9649 : if (params != IF_DEF_PARAMS(ifp)) {
9650 : ospf_free_if_params(ifp, addr);
9651 : ospf_if_update_params(ifp, addr);
9652 : }
9653 : }
9654 0 : return CMD_SUCCESS;
9655 : }
9656 :
9657 0 : DEFUN (no_ip_ospf_mtu_ignore,
9658 : no_ip_ospf_mtu_ignore_addr_cmd,
9659 : "no ip ospf mtu-ignore [A.B.C.D]",
9660 : NO_STR
9661 : "IP Information\n"
9662 : "OSPF interface commands\n"
9663 : "Disable MTU mismatch detection on this interface\n"
9664 : "Address of interface\n")
9665 : {
9666 0 : VTY_DECLVAR_CONTEXT(interface, ifp);
9667 0 : int idx_ipv4 = 4;
9668 0 : struct in_addr addr;
9669 0 : int ret;
9670 :
9671 0 : struct ospf_if_params *params;
9672 0 : params = IF_DEF_PARAMS(ifp);
9673 :
9674 0 : if (argc == 5) {
9675 0 : ret = inet_aton(argv[idx_ipv4]->arg, &addr);
9676 0 : if (!ret) {
9677 0 : vty_out(vty,
9678 : "Please specify interface address by A.B.C.D\n");
9679 0 : return CMD_WARNING_CONFIG_FAILED;
9680 : }
9681 0 : params = ospf_get_if_params(ifp, addr);
9682 0 : ospf_if_update_params(ifp, addr);
9683 : }
9684 0 : params->mtu_ignore = 0;
9685 0 : if (params->mtu_ignore != OSPF_MTU_IGNORE_DEFAULT)
9686 : SET_IF_PARAM(params, mtu_ignore);
9687 : else {
9688 0 : UNSET_IF_PARAM(params, mtu_ignore);
9689 0 : if (params != IF_DEF_PARAMS(ifp)) {
9690 0 : ospf_free_if_params(ifp, addr);
9691 0 : ospf_if_update_params(ifp, addr);
9692 : }
9693 : }
9694 : return CMD_SUCCESS;
9695 : }
9696 :
9697 :
9698 0 : DEFUN (ospf_max_metric_router_lsa_admin,
9699 : ospf_max_metric_router_lsa_admin_cmd,
9700 : "max-metric router-lsa administrative",
9701 : "OSPF maximum / infinite-distance metric\n"
9702 : "Advertise own Router-LSA with infinite distance (stub router)\n"
9703 : "Administratively applied, for an indefinite period\n")
9704 : {
9705 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9706 0 : struct listnode *ln;
9707 0 : struct ospf_area *area;
9708 :
9709 0 : for (ALL_LIST_ELEMENTS_RO(ospf->areas, ln, area)) {
9710 0 : SET_FLAG(area->stub_router_state, OSPF_AREA_ADMIN_STUB_ROUTED);
9711 :
9712 0 : if (!CHECK_FLAG(area->stub_router_state,
9713 : OSPF_AREA_IS_STUB_ROUTED))
9714 0 : ospf_router_lsa_update_area(area);
9715 : }
9716 :
9717 : /* Allows for areas configured later to get the property */
9718 0 : ospf->stub_router_admin_set = OSPF_STUB_ROUTER_ADMINISTRATIVE_SET;
9719 :
9720 0 : return CMD_SUCCESS;
9721 : }
9722 :
9723 0 : DEFUN (no_ospf_max_metric_router_lsa_admin,
9724 : no_ospf_max_metric_router_lsa_admin_cmd,
9725 : "no max-metric router-lsa administrative",
9726 : NO_STR
9727 : "OSPF maximum / infinite-distance metric\n"
9728 : "Advertise own Router-LSA with infinite distance (stub router)\n"
9729 : "Administratively applied, for an indefinite period\n")
9730 : {
9731 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9732 0 : struct listnode *ln;
9733 0 : struct ospf_area *area;
9734 :
9735 0 : for (ALL_LIST_ELEMENTS_RO(ospf->areas, ln, area)) {
9736 0 : UNSET_FLAG(area->stub_router_state,
9737 : OSPF_AREA_ADMIN_STUB_ROUTED);
9738 :
9739 : /* Don't trample on the start-up stub timer */
9740 0 : if (CHECK_FLAG(area->stub_router_state,
9741 : OSPF_AREA_IS_STUB_ROUTED)
9742 0 : && !area->t_stub_router) {
9743 0 : UNSET_FLAG(area->stub_router_state,
9744 : OSPF_AREA_IS_STUB_ROUTED);
9745 0 : ospf_router_lsa_update_area(area);
9746 : }
9747 : }
9748 0 : ospf->stub_router_admin_set = OSPF_STUB_ROUTER_ADMINISTRATIVE_UNSET;
9749 0 : return CMD_SUCCESS;
9750 : }
9751 :
9752 0 : DEFUN (ospf_max_metric_router_lsa_startup,
9753 : ospf_max_metric_router_lsa_startup_cmd,
9754 : "max-metric router-lsa on-startup (5-86400)",
9755 : "OSPF maximum / infinite-distance metric\n"
9756 : "Advertise own Router-LSA with infinite distance (stub router)\n"
9757 : "Automatically advertise stub Router-LSA on startup of OSPF\n"
9758 : "Time (seconds) to advertise self as stub-router\n")
9759 : {
9760 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9761 0 : int idx_number = 3;
9762 0 : unsigned int seconds;
9763 :
9764 0 : if (argc < 4) {
9765 0 : vty_out(vty, "%% Must supply stub-router period\n");
9766 0 : return CMD_WARNING_CONFIG_FAILED;
9767 : }
9768 :
9769 0 : seconds = strtoul(argv[idx_number]->arg, NULL, 10);
9770 :
9771 0 : ospf->stub_router_startup_time = seconds;
9772 :
9773 0 : return CMD_SUCCESS;
9774 : }
9775 :
9776 0 : DEFUN (no_ospf_max_metric_router_lsa_startup,
9777 : no_ospf_max_metric_router_lsa_startup_cmd,
9778 : "no max-metric router-lsa on-startup [(5-86400)]",
9779 : NO_STR
9780 : "OSPF maximum / infinite-distance metric\n"
9781 : "Advertise own Router-LSA with infinite distance (stub router)\n"
9782 : "Automatically advertise stub Router-LSA on startup of OSPF\n"
9783 : "Time (seconds) to advertise self as stub-router\n")
9784 : {
9785 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9786 0 : struct listnode *ln;
9787 0 : struct ospf_area *area;
9788 :
9789 0 : ospf->stub_router_startup_time = OSPF_STUB_ROUTER_UNCONFIGURED;
9790 :
9791 0 : for (ALL_LIST_ELEMENTS_RO(ospf->areas, ln, area)) {
9792 0 : SET_FLAG(area->stub_router_state,
9793 : OSPF_AREA_WAS_START_STUB_ROUTED);
9794 0 : THREAD_OFF(area->t_stub_router);
9795 :
9796 : /* Don't trample on admin stub routed */
9797 0 : if (!CHECK_FLAG(area->stub_router_state,
9798 : OSPF_AREA_ADMIN_STUB_ROUTED)) {
9799 0 : UNSET_FLAG(area->stub_router_state,
9800 : OSPF_AREA_IS_STUB_ROUTED);
9801 0 : ospf_router_lsa_update_area(area);
9802 : }
9803 : }
9804 : return CMD_SUCCESS;
9805 : }
9806 :
9807 :
9808 0 : DEFUN (ospf_max_metric_router_lsa_shutdown,
9809 : ospf_max_metric_router_lsa_shutdown_cmd,
9810 : "max-metric router-lsa on-shutdown (5-100)",
9811 : "OSPF maximum / infinite-distance metric\n"
9812 : "Advertise own Router-LSA with infinite distance (stub router)\n"
9813 : "Advertise stub-router prior to full shutdown of OSPF\n"
9814 : "Time (seconds) to wait till full shutdown\n")
9815 : {
9816 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9817 0 : int idx_number = 3;
9818 0 : unsigned int seconds;
9819 :
9820 0 : if (argc < 4) {
9821 0 : vty_out(vty, "%% Must supply stub-router shutdown period\n");
9822 0 : return CMD_WARNING_CONFIG_FAILED;
9823 : }
9824 :
9825 0 : seconds = strtoul(argv[idx_number]->arg, NULL, 10);
9826 :
9827 0 : ospf->stub_router_shutdown_time = seconds;
9828 :
9829 0 : return CMD_SUCCESS;
9830 : }
9831 :
9832 0 : DEFUN (no_ospf_max_metric_router_lsa_shutdown,
9833 : no_ospf_max_metric_router_lsa_shutdown_cmd,
9834 : "no max-metric router-lsa on-shutdown [(5-100)]",
9835 : NO_STR
9836 : "OSPF maximum / infinite-distance metric\n"
9837 : "Advertise own Router-LSA with infinite distance (stub router)\n"
9838 : "Advertise stub-router prior to full shutdown of OSPF\n"
9839 : "Time (seconds) to wait till full shutdown\n")
9840 : {
9841 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9842 :
9843 0 : ospf->stub_router_shutdown_time = OSPF_STUB_ROUTER_UNCONFIGURED;
9844 :
9845 0 : return CMD_SUCCESS;
9846 : }
9847 :
9848 0 : DEFUN (ospf_proactive_arp,
9849 : ospf_proactive_arp_cmd,
9850 : "proactive-arp",
9851 : "Allow sending ARP requests proactively\n")
9852 : {
9853 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9854 :
9855 0 : ospf->proactive_arp = true;
9856 :
9857 0 : return CMD_SUCCESS;
9858 : }
9859 :
9860 0 : DEFUN (no_ospf_proactive_arp,
9861 : no_ospf_proactive_arp_cmd,
9862 : "no proactive-arp",
9863 : NO_STR
9864 : "Disallow sending ARP requests proactively\n")
9865 : {
9866 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9867 :
9868 0 : ospf->proactive_arp = false;
9869 :
9870 0 : return CMD_SUCCESS;
9871 : }
9872 :
9873 : /* Graceful Restart HELPER Commands */
9874 0 : DEFPY(ospf_gr_helper_enable, ospf_gr_helper_enable_cmd,
9875 : "graceful-restart helper enable [A.B.C.D$address]",
9876 : "OSPF Graceful Restart\n"
9877 : "OSPF GR Helper\n"
9878 : "Enable Helper support\n"
9879 : "Advertising Router-ID\n")
9880 : {
9881 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9882 :
9883 0 : if (address_str) {
9884 0 : ospf_gr_helper_support_set_per_routerid(ospf, &address,
9885 : OSPF_GR_TRUE);
9886 0 : return CMD_SUCCESS;
9887 : }
9888 :
9889 0 : ospf_gr_helper_support_set(ospf, OSPF_GR_TRUE);
9890 :
9891 0 : return CMD_SUCCESS;
9892 : }
9893 :
9894 0 : DEFPY(no_ospf_gr_helper_enable,
9895 : no_ospf_gr_helper_enable_cmd,
9896 : "no graceful-restart helper enable [A.B.C.D$address]",
9897 : NO_STR
9898 : "OSPF Graceful Restart\n"
9899 : "OSPF GR Helper\n"
9900 : "Enable Helper support\n"
9901 : "Advertising Router-ID\n")
9902 : {
9903 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9904 :
9905 0 : if (address_str) {
9906 0 : ospf_gr_helper_support_set_per_routerid(ospf, &address,
9907 : OSPF_GR_FALSE);
9908 0 : return CMD_SUCCESS;
9909 : }
9910 :
9911 0 : ospf_gr_helper_support_set(ospf, OSPF_GR_FALSE);
9912 0 : return CMD_SUCCESS;
9913 : }
9914 :
9915 0 : DEFPY(ospf_gr_helper_enable_lsacheck,
9916 : ospf_gr_helper_enable_lsacheck_cmd,
9917 : "graceful-restart helper strict-lsa-checking",
9918 : "OSPF Graceful Restart\n"
9919 : "OSPF GR Helper\n"
9920 : "Enable strict LSA check\n")
9921 : {
9922 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9923 :
9924 0 : ospf_gr_helper_lsa_check_set(ospf, OSPF_GR_TRUE);
9925 0 : return CMD_SUCCESS;
9926 : }
9927 :
9928 0 : DEFPY(no_ospf_gr_helper_enable_lsacheck,
9929 : no_ospf_gr_helper_enable_lsacheck_cmd,
9930 : "no graceful-restart helper strict-lsa-checking",
9931 : NO_STR
9932 : "OSPF Graceful Restart\n"
9933 : "OSPF GR Helper\n"
9934 : "Disable strict LSA check\n")
9935 : {
9936 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9937 :
9938 0 : ospf_gr_helper_lsa_check_set(ospf, OSPF_GR_FALSE);
9939 0 : return CMD_SUCCESS;
9940 : }
9941 :
9942 0 : DEFPY(ospf_gr_helper_supported_grace_time,
9943 : ospf_gr_helper_supported_grace_time_cmd,
9944 : "graceful-restart helper supported-grace-time (10-1800)$interval",
9945 : "OSPF Graceful Restart\n"
9946 : "OSPF GR Helper\n"
9947 : "Supported grace timer\n"
9948 : "Grace interval(in seconds)\n")
9949 : {
9950 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9951 :
9952 0 : ospf_gr_helper_supported_gracetime_set(ospf, interval);
9953 0 : return CMD_SUCCESS;
9954 : }
9955 :
9956 0 : DEFPY(no_ospf_gr_helper_supported_grace_time,
9957 : no_ospf_gr_helper_supported_grace_time_cmd,
9958 : "no graceful-restart helper supported-grace-time (10-1800)$interval",
9959 : NO_STR
9960 : "OSPF Graceful Restart\n"
9961 : "OSPF GR Helper\n"
9962 : "Supported grace timer\n"
9963 : "Grace interval(in seconds)\n")
9964 : {
9965 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9966 :
9967 0 : ospf_gr_helper_supported_gracetime_set(ospf, OSPF_MAX_GRACE_INTERVAL);
9968 0 : return CMD_SUCCESS;
9969 : }
9970 :
9971 0 : DEFPY(ospf_gr_helper_planned_only,
9972 : ospf_gr_helper_planned_only_cmd,
9973 : "graceful-restart helper planned-only",
9974 : "OSPF Graceful Restart\n"
9975 : "OSPF GR Helper\n"
9976 : "Supported only planned restart\n")
9977 : {
9978 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9979 :
9980 0 : ospf_gr_helper_set_supported_planned_only_restart(ospf, OSPF_GR_TRUE);
9981 :
9982 0 : return CMD_SUCCESS;
9983 : }
9984 :
9985 : /* External Route Aggregation */
9986 0 : DEFUN (ospf_external_route_aggregation,
9987 : ospf_external_route_aggregation_cmd,
9988 : "summary-address A.B.C.D/M [tag (1-4294967295)]",
9989 : "External summary address\n"
9990 : "Summary address prefix\n"
9991 : "Router tag \n"
9992 : "Router tag value\n")
9993 : {
9994 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
9995 0 : struct prefix_ipv4 p;
9996 0 : int idx = 1;
9997 0 : route_tag_t tag = 0;
9998 0 : int ret = OSPF_SUCCESS;
9999 :
10000 0 : str2prefix_ipv4(argv[idx]->arg, &p);
10001 :
10002 0 : if (is_default_prefix4(&p)) {
10003 0 : vty_out(vty,
10004 : "Default address shouldn't be configured as summary address.\n");
10005 0 : return CMD_SUCCESS;
10006 : }
10007 :
10008 : /* Apply mask for given prefix. */
10009 0 : apply_mask(&p);
10010 :
10011 0 : if (!is_valid_summary_addr(&p)) {
10012 0 : vty_out(vty, "Not a valid summary address.\n");
10013 0 : return CMD_WARNING_CONFIG_FAILED;
10014 : }
10015 :
10016 0 : if (argc > 2)
10017 0 : tag = strtoul(argv[idx + 2]->arg, NULL, 10);
10018 :
10019 0 : ret = ospf_asbr_external_aggregator_set(ospf, &p, tag);
10020 0 : if (ret == OSPF_INVALID)
10021 0 : vty_out(vty, "Invalid configuration!!\n");
10022 :
10023 : return CMD_SUCCESS;
10024 : }
10025 :
10026 0 : DEFUN (no_ospf_external_route_aggregation,
10027 : no_ospf_external_route_aggregation_cmd,
10028 : "no summary-address A.B.C.D/M [tag (1-4294967295)]",
10029 : NO_STR
10030 : "External summary address\n"
10031 : "Summary address prefix\n"
10032 : "Router tag\n"
10033 : "Router tag value\n")
10034 : {
10035 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
10036 0 : struct prefix_ipv4 p;
10037 0 : int idx = 2;
10038 0 : route_tag_t tag = 0;
10039 0 : int ret = OSPF_SUCCESS;
10040 :
10041 0 : str2prefix_ipv4(argv[idx]->arg, &p);
10042 :
10043 0 : if (is_default_prefix4(&p)) {
10044 0 : vty_out(vty,
10045 : "Default address shouldn't be configured as summary address.\n");
10046 0 : return CMD_SUCCESS;
10047 : }
10048 :
10049 : /* Apply mask for given prefix. */
10050 0 : apply_mask(&p);
10051 :
10052 0 : if (!is_valid_summary_addr(&p)) {
10053 0 : vty_out(vty, "Not a valid summary address.\n");
10054 0 : return CMD_WARNING_CONFIG_FAILED;
10055 : }
10056 :
10057 0 : if (argc > 3)
10058 0 : tag = strtoul(argv[idx + 2]->arg, NULL, 10);
10059 :
10060 0 : ret = ospf_asbr_external_aggregator_unset(ospf, &p, tag);
10061 0 : if (ret == OSPF_INVALID)
10062 0 : vty_out(vty, "Invalid configuration!!\n");
10063 :
10064 : return CMD_SUCCESS;
10065 : }
10066 :
10067 0 : DEFPY(no_ospf_gr_helper_planned_only,
10068 : no_ospf_gr_helper_planned_only_cmd,
10069 : "no graceful-restart helper planned-only",
10070 : NO_STR
10071 : "OSPF Graceful Restart\n"
10072 : "OSPF GR Helper\n"
10073 : "Supported only for planned restart\n")
10074 : {
10075 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
10076 :
10077 0 : ospf_gr_helper_set_supported_planned_only_restart(ospf, OSPF_GR_FALSE);
10078 :
10079 0 : return CMD_SUCCESS;
10080 : }
10081 :
10082 0 : static int ospf_print_vty_helper_dis_rtr_walkcb(struct hash_bucket *bucket,
10083 : void *arg)
10084 : {
10085 0 : struct advRtr *rtr = bucket->data;
10086 0 : struct vty *vty = (struct vty *)arg;
10087 0 : static unsigned int count;
10088 :
10089 0 : vty_out(vty, "%-6pI4,", &rtr->advRtrAddr);
10090 0 : count++;
10091 :
10092 0 : if (count % 5 == 0)
10093 0 : vty_out(vty, "\n");
10094 :
10095 0 : return HASHWALK_CONTINUE;
10096 : }
10097 :
10098 0 : static int ospf_print_json_helper_enabled_rtr_walkcb(struct hash_bucket *bucket,
10099 : void *arg)
10100 : {
10101 0 : struct advRtr *rtr = bucket->data;
10102 0 : struct json_object *json_rid_array = arg;
10103 0 : struct json_object *json_rid;
10104 :
10105 0 : json_rid = json_object_new_object();
10106 :
10107 0 : json_object_string_addf(json_rid, "routerId", "%pI4", &rtr->advRtrAddr);
10108 0 : json_object_array_add(json_rid_array, json_rid);
10109 :
10110 0 : return HASHWALK_CONTINUE;
10111 : }
10112 :
10113 0 : static int ospf_show_gr_helper_details(struct vty *vty, struct ospf *ospf,
10114 : uint8_t use_vrf, json_object *json,
10115 : bool uj, bool detail)
10116 : {
10117 0 : struct listnode *node;
10118 0 : struct ospf_interface *oi;
10119 0 : char buf[PREFIX_STRLEN];
10120 0 : json_object *json_vrf = NULL;
10121 :
10122 0 : if (uj) {
10123 0 : if (use_vrf)
10124 0 : json_vrf = json_object_new_object();
10125 : else
10126 : json_vrf = json;
10127 : }
10128 :
10129 0 : if (ospf->instance) {
10130 0 : if (uj)
10131 0 : json_object_int_add(json, "ospfInstance",
10132 : ospf->instance);
10133 : else
10134 0 : vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
10135 : }
10136 :
10137 0 : ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf);
10138 :
10139 0 : if (uj) {
10140 0 : if (use_vrf)
10141 0 : json_object_object_add(json, ospf_get_name(ospf),
10142 : json_vrf);
10143 : } else
10144 0 : vty_out(vty, "\n");
10145 :
10146 : /* Show Router ID. */
10147 0 : if (uj) {
10148 0 : json_object_string_add(json_vrf, "routerId",
10149 0 : inet_ntop(AF_INET, &ospf->router_id,
10150 : buf, sizeof(buf)));
10151 : } else {
10152 0 : vty_out(vty, "\n OSPF Router with ID (%pI4)\n\n",
10153 : &ospf->router_id);
10154 : }
10155 :
10156 0 : if (!uj) {
10157 :
10158 0 : if (ospf->is_helper_supported)
10159 0 : vty_out(vty,
10160 : " Graceful restart helper support enabled.\n");
10161 : else
10162 0 : vty_out(vty,
10163 : " Graceful restart helper support disabled.\n");
10164 :
10165 0 : if (ospf->strict_lsa_check)
10166 0 : vty_out(vty, " Strict LSA check is enabled.\n");
10167 : else
10168 0 : vty_out(vty, " Strict LSA check is disabled.\n");
10169 :
10170 0 : if (ospf->only_planned_restart)
10171 0 : vty_out(vty,
10172 : " Helper supported for planned restarts only.\n");
10173 : else
10174 0 : vty_out(vty,
10175 : " Helper supported for Planned and Unplanned Restarts.\n");
10176 :
10177 0 : vty_out(vty,
10178 : " Supported Graceful restart interval: %d(in seconds).\n",
10179 : ospf->supported_grace_time);
10180 :
10181 0 : if (OSPF_HELPER_ENABLE_RTR_COUNT(ospf)) {
10182 0 : vty_out(vty, " Enable Router list:\n");
10183 0 : vty_out(vty, " ");
10184 0 : hash_walk(ospf->enable_rtr_list,
10185 : ospf_print_vty_helper_dis_rtr_walkcb, vty);
10186 0 : vty_out(vty, "\n\n");
10187 : }
10188 :
10189 0 : if (ospf->last_exit_reason != OSPF_GR_HELPER_EXIT_NONE) {
10190 0 : vty_out(vty, " Last Helper exit Reason :%s\n",
10191 : ospf_exit_reason2str(ospf->last_exit_reason));
10192 : }
10193 :
10194 0 : if (ospf->active_restarter_cnt)
10195 0 : vty_out(vty,
10196 : " Number of Active neighbours in graceful restart: %d\n",
10197 : ospf->active_restarter_cnt);
10198 : else
10199 0 : vty_out(vty, "\n");
10200 :
10201 : } else {
10202 0 : json_object_string_add(
10203 : json_vrf, "helperSupport",
10204 0 : (ospf->is_helper_supported) ? "Enabled" : "Disabled");
10205 0 : json_object_string_add(json_vrf, "strictLsaCheck",
10206 0 : (ospf->strict_lsa_check) ? "Enabled"
10207 : : "Disabled");
10208 0 : json_object_string_add(
10209 : json_vrf, "restartSupoort",
10210 0 : (ospf->only_planned_restart)
10211 : ? "Planned Restart only"
10212 : : "Planned and Unplanned Restarts");
10213 :
10214 0 : json_object_int_add(json_vrf, "supportedGracePeriod",
10215 0 : ospf->supported_grace_time);
10216 :
10217 0 : if (ospf->last_exit_reason != OSPF_GR_HELPER_EXIT_NONE)
10218 0 : json_object_string_add(
10219 : json_vrf, "lastExitReason",
10220 : ospf_exit_reason2str(ospf->last_exit_reason));
10221 :
10222 0 : if (ospf->active_restarter_cnt)
10223 0 : json_object_int_add(json_vrf, "activeRestarterCnt",
10224 : ospf->active_restarter_cnt);
10225 :
10226 0 : if (OSPF_HELPER_ENABLE_RTR_COUNT(ospf)) {
10227 0 : struct json_object *json_rid_array =
10228 0 : json_object_new_array();
10229 :
10230 0 : json_object_object_add(json_vrf, "enabledRouterIds",
10231 : json_rid_array);
10232 :
10233 0 : hash_walk(ospf->enable_rtr_list,
10234 : ospf_print_json_helper_enabled_rtr_walkcb,
10235 : json_rid_array);
10236 : }
10237 : }
10238 :
10239 :
10240 0 : if (detail) {
10241 0 : int cnt = 1;
10242 0 : json_object *json_neighbors = NULL;
10243 :
10244 0 : for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) {
10245 0 : struct route_node *rn;
10246 0 : struct ospf_neighbor *nbr;
10247 0 : json_object *json_neigh;
10248 :
10249 0 : if (ospf_interface_neighbor_count(oi) == 0)
10250 0 : continue;
10251 :
10252 0 : if (uj) {
10253 0 : json_object_object_get_ex(json_vrf, "neighbors",
10254 : &json_neighbors);
10255 0 : if (!json_neighbors) {
10256 0 : json_neighbors =
10257 0 : json_object_new_object();
10258 0 : json_object_object_add(json_vrf,
10259 : "neighbors",
10260 : json_neighbors);
10261 : }
10262 : }
10263 :
10264 0 : for (rn = route_top(oi->nbrs); rn;
10265 0 : rn = route_next(rn)) {
10266 :
10267 0 : if (!rn->info)
10268 0 : continue;
10269 :
10270 0 : nbr = rn->info;
10271 :
10272 0 : if (!OSPF_GR_IS_ACTIVE_HELPER(nbr))
10273 0 : continue;
10274 :
10275 0 : if (!uj) {
10276 0 : vty_out(vty, " Neighbour %d :\n", cnt);
10277 0 : vty_out(vty, " Address : %pI4\n",
10278 : &nbr->address.u.prefix4);
10279 0 : vty_out(vty, " Routerid : %pI4\n",
10280 : &nbr->router_id);
10281 0 : vty_out(vty,
10282 : " Received Grace period : %d(in seconds).\n",
10283 : nbr->gr_helper_info
10284 : .recvd_grace_period);
10285 0 : vty_out(vty,
10286 : " Actual Grace period : %d(in seconds)\n",
10287 : nbr->gr_helper_info
10288 : .actual_grace_period);
10289 0 : vty_out(vty,
10290 : " Remaining GraceTime:%ld(in seconds).\n",
10291 : thread_timer_remain_second(
10292 : nbr->gr_helper_info
10293 : .t_grace_timer));
10294 0 : vty_out(vty,
10295 : " Graceful Restart reason: %s.\n\n",
10296 : ospf_restart_reason2str(
10297 : nbr->gr_helper_info
10298 0 : .gr_restart_reason));
10299 0 : cnt++;
10300 : } else {
10301 0 : json_neigh = json_object_new_object();
10302 0 : json_object_string_add(
10303 : json_neigh, "srcAddr",
10304 0 : inet_ntop(AF_INET, &nbr->src,
10305 : buf, sizeof(buf)));
10306 :
10307 0 : json_object_string_add(
10308 : json_neigh, "routerid",
10309 : inet_ntop(AF_INET,
10310 0 : &nbr->router_id,
10311 : buf, sizeof(buf)));
10312 0 : json_object_int_add(
10313 : json_neigh,
10314 : "recvdGraceInterval",
10315 : nbr->gr_helper_info
10316 0 : .recvd_grace_period);
10317 0 : json_object_int_add(
10318 : json_neigh,
10319 : "actualGraceInterval",
10320 : nbr->gr_helper_info
10321 0 : .actual_grace_period);
10322 0 : json_object_int_add(
10323 : json_neigh, "remainGracetime",
10324 0 : thread_timer_remain_second(
10325 : nbr->gr_helper_info
10326 : .t_grace_timer));
10327 0 : json_object_string_add(
10328 : json_neigh, "restartReason",
10329 : ospf_restart_reason2str(
10330 : nbr->gr_helper_info
10331 0 : .gr_restart_reason));
10332 0 : json_object_object_add(
10333 : json_neighbors,
10334 : inet_ntop(AF_INET, &nbr->src,
10335 : buf, sizeof(buf)),
10336 : json_neigh);
10337 : }
10338 : }
10339 : }
10340 : }
10341 0 : return CMD_SUCCESS;
10342 : }
10343 :
10344 0 : DEFUN (ospf_external_route_aggregation_no_adrvertise,
10345 : ospf_external_route_aggregation_no_adrvertise_cmd,
10346 : "summary-address A.B.C.D/M no-advertise",
10347 : "External summary address\n"
10348 : "Summary address prefix\n"
10349 : "Don't advertise summary route \n")
10350 : {
10351 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
10352 0 : struct prefix_ipv4 p;
10353 0 : int idx = 1;
10354 0 : int ret = OSPF_SUCCESS;
10355 :
10356 0 : str2prefix_ipv4(argv[idx]->arg, &p);
10357 :
10358 0 : if (is_default_prefix4(&p)) {
10359 0 : vty_out(vty,
10360 : "Default address shouldn't be configured as summary address.\n");
10361 0 : return CMD_SUCCESS;
10362 : }
10363 :
10364 : /* Apply mask for given prefix. */
10365 0 : apply_mask(&p);
10366 :
10367 0 : if (!is_valid_summary_addr(&p)) {
10368 0 : vty_out(vty, "Not a valid summary address.\n");
10369 0 : return CMD_WARNING_CONFIG_FAILED;
10370 : }
10371 :
10372 0 : ret = ospf_asbr_external_rt_no_advertise(ospf, &p);
10373 0 : if (ret == OSPF_INVALID)
10374 0 : vty_out(vty, "Invalid configuration!!\n");
10375 :
10376 : return CMD_SUCCESS;
10377 : }
10378 :
10379 0 : DEFUN (no_ospf_external_route_aggregation_no_adrvertise,
10380 : no_ospf_external_route_aggregation_no_adrvertise_cmd,
10381 : "no summary-address A.B.C.D/M no-advertise",
10382 : NO_STR
10383 : "External summary address\n"
10384 : "Summary address prefix\n"
10385 : "Advertise summary route to the AS \n")
10386 : {
10387 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
10388 0 : struct prefix_ipv4 p;
10389 0 : int idx = 2;
10390 0 : int ret = OSPF_SUCCESS;
10391 :
10392 0 : str2prefix_ipv4(argv[idx]->arg, &p);
10393 :
10394 0 : if (is_default_prefix4(&p)) {
10395 0 : vty_out(vty,
10396 : "Default address shouldn't be configured as summary address.\n");
10397 0 : return CMD_SUCCESS;
10398 : }
10399 :
10400 : /* Apply mask for given prefix. */
10401 0 : apply_mask(&p);
10402 :
10403 0 : if (!is_valid_summary_addr(&p)) {
10404 0 : vty_out(vty, "Not a valid summary address.\n");
10405 0 : return CMD_WARNING_CONFIG_FAILED;
10406 : }
10407 :
10408 0 : ret = ospf_asbr_external_rt_advertise(ospf, &p);
10409 0 : if (ret == OSPF_INVALID)
10410 0 : vty_out(vty, "Invalid configuration!!\n");
10411 :
10412 : return CMD_SUCCESS;
10413 : }
10414 :
10415 0 : DEFUN (ospf_route_aggregation_timer,
10416 : ospf_route_aggregation_timer_cmd,
10417 : "aggregation timer (5-1800)",
10418 : "External route aggregation\n"
10419 : "Delay timer (in seconds)\n"
10420 : "Timer interval(in seconds)\n")
10421 : {
10422 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
10423 0 : uint16_t interval = 0;
10424 :
10425 0 : interval = strtoul(argv[2]->arg, NULL, 10);
10426 :
10427 0 : ospf_external_aggregator_timer_set(ospf, interval);
10428 :
10429 0 : return CMD_SUCCESS;
10430 : }
10431 :
10432 0 : DEFPY (show_ip_ospf_gr_helper,
10433 : show_ip_ospf_gr_helper_cmd,
10434 : "show ip ospf [vrf <NAME|all>] graceful-restart helper [detail] [json]",
10435 : SHOW_STR
10436 : IP_STR
10437 : "OSPF information\n"
10438 : VRF_CMD_HELP_STR
10439 : "All VRFs\n"
10440 : "OSPF Graceful Restart\n"
10441 : "Helper details in the router\n"
10442 : "Detailed information\n"
10443 : JSON_STR)
10444 : {
10445 0 : char *vrf_name = NULL;
10446 0 : bool all_vrf = false;
10447 0 : int ret = CMD_SUCCESS;
10448 0 : int idx_vrf = 0;
10449 0 : int idx = 0;
10450 0 : uint8_t use_vrf = 0;
10451 0 : bool uj = use_json(argc, argv);
10452 0 : struct ospf *ospf = NULL;
10453 0 : json_object *json = NULL;
10454 0 : struct listnode *node = NULL;
10455 0 : int inst = 0;
10456 0 : bool detail = false;
10457 :
10458 0 : OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
10459 :
10460 0 : if (argv_find(argv, argc, "detail", &idx))
10461 0 : detail = true;
10462 :
10463 0 : if (uj)
10464 0 : json = json_object_new_object();
10465 :
10466 : /* vrf input is provided */
10467 0 : if (vrf_name) {
10468 0 : use_vrf = 1;
10469 :
10470 0 : if (all_vrf) {
10471 0 : for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
10472 0 : if (!ospf->oi_running)
10473 0 : continue;
10474 :
10475 0 : ret = ospf_show_gr_helper_details(
10476 : vty, ospf, use_vrf, json, uj, detail);
10477 : }
10478 :
10479 0 : if (uj)
10480 0 : vty_json(vty, json);
10481 :
10482 0 : return ret;
10483 : }
10484 :
10485 0 : ospf = ospf_lookup_by_inst_name(inst, vrf_name);
10486 :
10487 0 : if (ospf == NULL || !ospf->oi_running) {
10488 :
10489 0 : if (uj)
10490 0 : vty_json(vty, json);
10491 : else
10492 0 : vty_out(vty,
10493 : "%% OSPF is not enabled in vrf %s\n",
10494 : vrf_name);
10495 :
10496 0 : return CMD_SUCCESS;
10497 : }
10498 :
10499 : } else {
10500 : /* Default Vrf */
10501 0 : ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
10502 :
10503 0 : if (ospf == NULL || !ospf->oi_running) {
10504 :
10505 0 : if (uj)
10506 0 : vty_json(vty, json);
10507 : else
10508 0 : vty_out(vty,
10509 : "%% OSPF is not enabled in vrf default\n");
10510 :
10511 0 : return CMD_SUCCESS;
10512 : }
10513 :
10514 0 : ospf_show_gr_helper_details(vty, ospf, use_vrf, json, uj,
10515 : detail);
10516 : }
10517 :
10518 0 : if (uj)
10519 0 : vty_json(vty, json);
10520 :
10521 : return CMD_SUCCESS;
10522 : }
10523 : /* Graceful Restart HELPER commands end */
10524 0 : DEFUN (no_ospf_route_aggregation_timer,
10525 : no_ospf_route_aggregation_timer_cmd,
10526 : "no aggregation timer",
10527 : NO_STR
10528 : "External route aggregation\n"
10529 : "Delay timer\n")
10530 : {
10531 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf);
10532 :
10533 0 : ospf_external_aggregator_timer_set(ospf, OSPF_EXTL_AGGR_DEFAULT_DELAY);
10534 :
10535 0 : return CMD_SUCCESS;
10536 : }
10537 :
10538 : /* External Route Aggregation End */
10539 :
10540 0 : static void config_write_stub_router(struct vty *vty, struct ospf *ospf)
10541 : {
10542 0 : if (ospf->stub_router_startup_time != OSPF_STUB_ROUTER_UNCONFIGURED)
10543 0 : vty_out(vty, " max-metric router-lsa on-startup %u\n",
10544 : ospf->stub_router_startup_time);
10545 0 : if (ospf->stub_router_shutdown_time != OSPF_STUB_ROUTER_UNCONFIGURED)
10546 0 : vty_out(vty, " max-metric router-lsa on-shutdown %u\n",
10547 : ospf->stub_router_shutdown_time);
10548 0 : if (ospf->stub_router_admin_set == OSPF_STUB_ROUTER_ADMINISTRATIVE_SET)
10549 0 : vty_out(vty, " max-metric router-lsa administrative\n");
10550 :
10551 0 : return;
10552 : }
10553 :
10554 112 : static void show_ip_ospf_route_network(struct vty *vty, struct ospf *ospf,
10555 : struct route_table *rt,
10556 : json_object *json)
10557 : {
10558 112 : struct route_node *rn;
10559 112 : struct ospf_route * or ;
10560 112 : struct listnode *pnode, *pnnode;
10561 112 : struct ospf_path *path;
10562 112 : json_object *json_route = NULL, *json_nexthop_array = NULL,
10563 112 : *json_nexthop = NULL;
10564 :
10565 112 : if (!json)
10566 112 : vty_out(vty,
10567 : "============ OSPF network routing table ============\n");
10568 :
10569 528 : for (rn = route_top(rt); rn; rn = route_next(rn)) {
10570 416 : char buf1[PREFIX2STR_BUFFER];
10571 :
10572 416 : if ((or = rn->info) == NULL)
10573 152 : continue;
10574 :
10575 264 : prefix2str(&rn->p, buf1, sizeof(buf1));
10576 :
10577 264 : if (json) {
10578 0 : json_route = json_object_new_object();
10579 0 : json_object_object_add(json, buf1, json_route);
10580 : }
10581 :
10582 264 : switch (or->path_type) {
10583 45 : case OSPF_PATH_INTER_AREA:
10584 45 : if (or->type == OSPF_DESTINATION_NETWORK) {
10585 45 : if (json) {
10586 0 : json_object_string_add(json_route,
10587 : "routeType",
10588 : "N IA");
10589 0 : json_object_int_add(json_route, "cost",
10590 0 : or->cost);
10591 0 : json_object_string_addf(
10592 : json_route, "area", "%pI4",
10593 : &or->u.std.area_id);
10594 : } else {
10595 45 : vty_out(vty,
10596 : "N IA %-18s [%d] area: %pI4\n",
10597 : buf1, or->cost,
10598 : &or->u.std.area_id);
10599 : }
10600 0 : } else if (or->type == OSPF_DESTINATION_DISCARD) {
10601 0 : if (json) {
10602 0 : json_object_string_add(json_route,
10603 : "routeType",
10604 : "D IA");
10605 : } else {
10606 0 : vty_out(vty,
10607 : "D IA %-18s Discard entry\n",
10608 : buf1);
10609 : }
10610 : }
10611 : break;
10612 219 : case OSPF_PATH_INTRA_AREA:
10613 219 : if (json) {
10614 0 : json_object_string_add(json_route, "routeType",
10615 : "N");
10616 0 : json_object_int_add(json_route, "cost",
10617 0 : or->cost);
10618 0 : json_object_string_addf(json_route, "area",
10619 : "%pI4",
10620 : &or->u.std.area_id);
10621 : } else {
10622 219 : vty_out(vty, "N %-18s [%d] area: %pI4\n",
10623 : buf1, or->cost,
10624 : &or->u.std.area_id);
10625 : }
10626 : break;
10627 : default:
10628 : break;
10629 : }
10630 :
10631 264 : if (or->type == OSPF_DESTINATION_NETWORK) {
10632 264 : if (json) {
10633 0 : json_nexthop_array = json_object_new_array();
10634 0 : json_object_object_add(json_route, "nexthops",
10635 : json_nexthop_array);
10636 : }
10637 :
10638 792 : for (ALL_LIST_ELEMENTS(or->paths, pnode, pnnode,
10639 : path)) {
10640 264 : if (json) {
10641 0 : json_nexthop = json_object_new_object();
10642 0 : json_object_array_add(
10643 : json_nexthop_array,
10644 : json_nexthop);
10645 : }
10646 264 : if (if_lookup_by_index(path->ifindex,
10647 : ospf->vrf_id)) {
10648 :
10649 264 : if (path->nexthop.s_addr
10650 : == INADDR_ANY) {
10651 164 : if (json) {
10652 0 : json_object_string_add(
10653 : json_nexthop,
10654 : "ip", " ");
10655 0 : json_object_string_add(
10656 : json_nexthop,
10657 : "directlyAttachedTo",
10658 : ifindex2ifname(
10659 : path->ifindex,
10660 : ospf->vrf_id));
10661 : } else {
10662 164 : vty_out(vty,
10663 : "%24s directly attached to %s\n",
10664 : "",
10665 : ifindex2ifname(
10666 : path->ifindex,
10667 : ospf->vrf_id));
10668 : }
10669 : } else {
10670 100 : if (json) {
10671 0 : json_object_string_addf(
10672 : json_nexthop,
10673 : "ip", "%pI4",
10674 : &path->nexthop);
10675 0 : json_object_string_add(
10676 : json_nexthop,
10677 : "via",
10678 : ifindex2ifname(
10679 : path->ifindex,
10680 : ospf->vrf_id));
10681 : } else {
10682 100 : vty_out(vty,
10683 : "%24s via %pI4, %s\n",
10684 : "",
10685 : &path->nexthop,
10686 : ifindex2ifname(
10687 : path->ifindex,
10688 : ospf->vrf_id));
10689 : }
10690 : }
10691 : }
10692 : }
10693 : }
10694 : }
10695 112 : if (!json)
10696 112 : vty_out(vty, "\n");
10697 112 : }
10698 :
10699 112 : static void show_ip_ospf_route_router(struct vty *vty, struct ospf *ospf,
10700 : struct route_table *rtrs,
10701 : json_object *json)
10702 : {
10703 112 : struct route_node *rn;
10704 112 : struct ospf_route * or ;
10705 112 : struct listnode *pnode;
10706 112 : struct listnode *node;
10707 112 : struct ospf_path *path;
10708 112 : char buf[PREFIX_STRLEN];
10709 112 : json_object *json_route = NULL, *json_nexthop_array = NULL,
10710 112 : *json_nexthop = NULL;
10711 :
10712 112 : if (!json)
10713 112 : vty_out(vty, "============ OSPF %s table =============\n",
10714 112 : ospf->all_rtrs == rtrs ? "reachable routers"
10715 : : "router routing");
10716 :
10717 235 : for (rn = route_top(rtrs); rn; rn = route_next(rn)) {
10718 123 : if (rn->info == NULL)
10719 44 : continue;
10720 79 : int flag = 0;
10721 :
10722 79 : if (json) {
10723 0 : json_route = json_object_new_object();
10724 0 : json_object_object_add(
10725 0 : json, inet_ntop(AF_INET, &rn->p.u.prefix4,
10726 : buf, sizeof(buf)),
10727 : json_route);
10728 0 : json_object_string_add(json_route, "routeType", "R ");
10729 : } else {
10730 79 : vty_out(vty, "R %-15pI4 ",
10731 : &rn->p.u.prefix4);
10732 : }
10733 :
10734 237 : for (ALL_LIST_ELEMENTS_RO((struct list *)rn->info, node, or)) {
10735 79 : if (flag++) {
10736 0 : if (!json)
10737 0 : vty_out(vty, "%24s", "");
10738 : }
10739 :
10740 : /* Show path. */
10741 79 : if (json) {
10742 0 : json_object_int_add(json_route, "cost",
10743 0 : or->cost);
10744 0 : json_object_string_addf(json_route, "area",
10745 : "%pI4",
10746 : &or->u.std.area_id);
10747 0 : if (or->path_type == OSPF_PATH_INTER_AREA) {
10748 0 : json_object_boolean_true_add(json_route,
10749 : "IA");
10750 0 : json_object_boolean_true_add(json_route,
10751 : "ia");
10752 : }
10753 0 : if (or->u.std.flags & ROUTER_LSA_BORDER)
10754 0 : json_object_string_add(json_route,
10755 : "routerType",
10756 : "abr");
10757 0 : else if (or->u.std.flags & ROUTER_LSA_EXTERNAL)
10758 0 : json_object_string_add(json_route,
10759 : "routerType",
10760 : "asbr");
10761 : } else {
10762 79 : vty_out(vty, "%s [%d] area: %pI4",
10763 79 : (or->path_type == OSPF_PATH_INTER_AREA
10764 : ? "IA"
10765 : : " "),
10766 : or->cost, &or->u.std.area_id);
10767 : /* Show flags. */
10768 136 : vty_out(vty, "%s%s\n",
10769 : (or->u.std.flags & ROUTER_LSA_BORDER
10770 : ? ", ABR"
10771 : : ""),
10772 79 : (or->u.std.flags & ROUTER_LSA_EXTERNAL
10773 : ? ", ASBR"
10774 : : ""));
10775 : }
10776 :
10777 79 : if (json) {
10778 0 : json_nexthop_array = json_object_new_array();
10779 0 : json_object_object_add(json_route, "nexthops",
10780 : json_nexthop_array);
10781 : }
10782 :
10783 237 : for (ALL_LIST_ELEMENTS_RO(or->paths, pnode, path)) {
10784 79 : if (json) {
10785 0 : json_nexthop = json_object_new_object();
10786 0 : json_object_array_add(
10787 : json_nexthop_array,
10788 : json_nexthop);
10789 : }
10790 79 : if (if_lookup_by_index(path->ifindex,
10791 : ospf->vrf_id)) {
10792 79 : if (path->nexthop.s_addr
10793 : == INADDR_ANY) {
10794 0 : if (json) {
10795 0 : json_object_string_add(
10796 : json_nexthop,
10797 : "ip", " ");
10798 0 : json_object_string_add(
10799 : json_nexthop,
10800 : "directlyAttachedTo",
10801 : ifindex2ifname(
10802 : path->ifindex,
10803 : ospf->vrf_id));
10804 : } else {
10805 0 : vty_out(vty,
10806 : "%24s directly attached to %s\n",
10807 : "",
10808 : ifindex2ifname(
10809 : path->ifindex,
10810 : ospf->vrf_id));
10811 : }
10812 : } else {
10813 79 : if (json) {
10814 0 : json_object_string_addf(
10815 : json_nexthop,
10816 : "ip", "%pI4",
10817 : &path->nexthop);
10818 0 : json_object_string_add(
10819 : json_nexthop,
10820 : "via",
10821 : ifindex2ifname(
10822 : path->ifindex,
10823 : ospf->vrf_id));
10824 : } else {
10825 79 : vty_out(vty,
10826 : "%24s via %pI4, %s\n",
10827 : "",
10828 : &path->nexthop,
10829 : ifindex2ifname(
10830 : path->ifindex,
10831 : ospf->vrf_id));
10832 : }
10833 : }
10834 : }
10835 : }
10836 : }
10837 : }
10838 112 : if (!json)
10839 112 : vty_out(vty, "\n");
10840 112 : }
10841 :
10842 112 : static void show_ip_ospf_route_external(struct vty *vty, struct ospf *ospf,
10843 : struct route_table *rt,
10844 : json_object *json)
10845 : {
10846 112 : struct route_node *rn;
10847 112 : struct ospf_route *er;
10848 112 : struct listnode *pnode, *pnnode;
10849 112 : struct ospf_path *path;
10850 112 : json_object *json_route = NULL, *json_nexthop_array = NULL,
10851 112 : *json_nexthop = NULL;
10852 :
10853 112 : if (!json)
10854 112 : vty_out(vty,
10855 : "============ OSPF external routing table ===========\n");
10856 :
10857 246 : for (rn = route_top(rt); rn; rn = route_next(rn)) {
10858 134 : if ((er = rn->info) == NULL)
10859 52 : continue;
10860 :
10861 82 : char buf1[19];
10862 :
10863 82 : snprintfrr(buf1, sizeof(buf1), "%pFX", &rn->p);
10864 82 : if (json) {
10865 0 : json_route = json_object_new_object();
10866 0 : json_object_object_add(json, buf1, json_route);
10867 : }
10868 :
10869 82 : switch (er->path_type) {
10870 0 : case OSPF_PATH_TYPE1_EXTERNAL:
10871 0 : if (json) {
10872 0 : json_object_string_add(json_route, "routeType",
10873 : "N E1");
10874 0 : json_object_int_add(json_route, "cost",
10875 0 : er->cost);
10876 0 : json_object_int_add(json_route, "tag",
10877 0 : er->u.ext.tag);
10878 : } else {
10879 0 : vty_out(vty,
10880 : "N E1 %-18s [%d] tag: %" ROUTE_TAG_PRI
10881 : "\n",
10882 : buf1, er->cost, er->u.ext.tag);
10883 : }
10884 : break;
10885 82 : case OSPF_PATH_TYPE2_EXTERNAL:
10886 82 : if (json) {
10887 0 : json_object_string_add(json_route, "routeType",
10888 : "N E2");
10889 0 : json_object_int_add(json_route, "cost",
10890 0 : er->cost);
10891 0 : json_object_int_add(json_route, "type2cost",
10892 0 : er->u.ext.type2_cost);
10893 0 : json_object_int_add(json_route, "tag",
10894 0 : er->u.ext.tag);
10895 : } else {
10896 82 : vty_out(vty,
10897 : "N E2 %-18s [%d/%d] tag: %" ROUTE_TAG_PRI
10898 : "\n",
10899 : buf1, er->cost, er->u.ext.type2_cost,
10900 : er->u.ext.tag);
10901 : }
10902 : break;
10903 : }
10904 :
10905 82 : if (json) {
10906 0 : json_nexthop_array = json_object_new_array();
10907 0 : json_object_object_add(json_route, "nexthops",
10908 : json_nexthop_array);
10909 : }
10910 :
10911 246 : for (ALL_LIST_ELEMENTS(er->paths, pnode, pnnode, path)) {
10912 82 : if (json) {
10913 0 : json_nexthop = json_object_new_object();
10914 0 : json_object_array_add(json_nexthop_array,
10915 : json_nexthop);
10916 : }
10917 :
10918 82 : if (if_lookup_by_index(path->ifindex, ospf->vrf_id)) {
10919 82 : if (path->nexthop.s_addr == INADDR_ANY) {
10920 0 : if (json) {
10921 0 : json_object_string_add(
10922 : json_nexthop, "ip",
10923 : " ");
10924 0 : json_object_string_add(
10925 : json_nexthop,
10926 : "directlyAttachedTo",
10927 : ifindex2ifname(
10928 : path->ifindex,
10929 : ospf->vrf_id));
10930 : } else {
10931 0 : vty_out(vty,
10932 : "%24s directly attached to %s\n",
10933 : "",
10934 : ifindex2ifname(
10935 : path->ifindex,
10936 : ospf->vrf_id));
10937 : }
10938 : } else {
10939 82 : if (json) {
10940 0 : json_object_string_addf(
10941 : json_nexthop, "ip",
10942 : "%pI4", &path->nexthop);
10943 0 : json_object_string_add(
10944 : json_nexthop, "via",
10945 : ifindex2ifname(
10946 : path->ifindex,
10947 : ospf->vrf_id));
10948 : } else {
10949 82 : vty_out(vty,
10950 : "%24s via %pI4, %s\n",
10951 : "",
10952 : &path->nexthop,
10953 : ifindex2ifname(
10954 : path->ifindex,
10955 : ospf->vrf_id));
10956 : }
10957 : }
10958 : }
10959 : }
10960 : }
10961 112 : if (!json)
10962 112 : vty_out(vty, "\n");
10963 112 : }
10964 :
10965 0 : static int show_ip_ospf_reachable_routers_common(struct vty *vty,
10966 : struct ospf *ospf,
10967 : uint8_t use_vrf)
10968 : {
10969 0 : if (ospf->instance)
10970 0 : vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
10971 :
10972 0 : ospf_show_vrf_name(ospf, vty, NULL, use_vrf);
10973 :
10974 0 : if (ospf->all_rtrs == NULL) {
10975 0 : vty_out(vty, "No OSPF reachable router information exist\n");
10976 0 : return CMD_SUCCESS;
10977 : }
10978 :
10979 : /* Show Router routes. */
10980 0 : show_ip_ospf_route_router(vty, ospf, ospf->all_rtrs, NULL);
10981 :
10982 0 : vty_out(vty, "\n");
10983 :
10984 0 : return CMD_SUCCESS;
10985 : }
10986 :
10987 0 : DEFUN (show_ip_ospf_reachable_routers,
10988 : show_ip_ospf_reachable_routers_cmd,
10989 : "show ip ospf [vrf <NAME|all>] reachable-routers",
10990 : SHOW_STR
10991 : IP_STR
10992 : "OSPF information\n"
10993 : VRF_CMD_HELP_STR
10994 : "All VRFs\n"
10995 : "Show all the reachable OSPF routers\n")
10996 : {
10997 0 : struct ospf *ospf = NULL;
10998 0 : struct listnode *node = NULL;
10999 0 : char *vrf_name = NULL;
11000 0 : bool all_vrf = false;
11001 0 : int ret = CMD_SUCCESS;
11002 0 : int inst = 0;
11003 0 : int idx_vrf = 0;
11004 0 : uint8_t use_vrf = 0;
11005 :
11006 0 : OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
11007 :
11008 0 : if (vrf_name) {
11009 0 : bool ospf_output = false;
11010 :
11011 0 : use_vrf = 1;
11012 :
11013 0 : if (all_vrf) {
11014 0 : for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
11015 0 : if (!ospf->oi_running)
11016 0 : continue;
11017 :
11018 0 : ospf_output = true;
11019 0 : ret = show_ip_ospf_reachable_routers_common(
11020 : vty, ospf, use_vrf);
11021 : }
11022 :
11023 0 : if (!ospf_output)
11024 0 : vty_out(vty, "%% OSPF instance not found\n");
11025 : } else {
11026 0 : ospf = ospf_lookup_by_inst_name(inst, vrf_name);
11027 0 : if (ospf == NULL || !ospf->oi_running) {
11028 0 : vty_out(vty, "%% OSPF instance not found\n");
11029 0 : return CMD_SUCCESS;
11030 : }
11031 :
11032 0 : ret = show_ip_ospf_reachable_routers_common(vty, ospf,
11033 : use_vrf);
11034 : }
11035 : } else {
11036 : /* Display default ospf (instance 0) info */
11037 0 : ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
11038 0 : if (ospf == NULL || !ospf->oi_running) {
11039 0 : vty_out(vty, "%% OSPF instance not found\n");
11040 0 : return CMD_SUCCESS;
11041 : }
11042 :
11043 0 : ret = show_ip_ospf_reachable_routers_common(vty, ospf, use_vrf);
11044 : }
11045 :
11046 : return ret;
11047 : }
11048 :
11049 0 : DEFUN (show_ip_ospf_instance_reachable_routers,
11050 : show_ip_ospf_instance_reachable_routers_cmd,
11051 : "show ip ospf (1-65535) reachable-routers",
11052 : SHOW_STR
11053 : IP_STR
11054 : "OSPF information\n"
11055 : "Instance ID\n"
11056 : "Show all the reachable OSPF routers\n")
11057 : {
11058 0 : int idx_number = 3;
11059 0 : struct ospf *ospf;
11060 0 : unsigned short instance = 0;
11061 :
11062 0 : instance = strtoul(argv[idx_number]->arg, NULL, 10);
11063 0 : if (instance != ospf_instance)
11064 : return CMD_NOT_MY_INSTANCE;
11065 :
11066 0 : ospf = ospf_lookup_instance(instance);
11067 0 : if (!ospf || !ospf->oi_running)
11068 : return CMD_SUCCESS;
11069 :
11070 0 : return show_ip_ospf_reachable_routers_common(vty, ospf, 0);
11071 : }
11072 :
11073 0 : static int show_ip_ospf_border_routers_common(struct vty *vty,
11074 : struct ospf *ospf,
11075 : uint8_t use_vrf,
11076 : json_object *json)
11077 : {
11078 0 : json_object *json_vrf = NULL;
11079 0 : json_object *json_router = NULL;
11080 :
11081 0 : if (json) {
11082 0 : if (use_vrf)
11083 0 : json_vrf = json_object_new_object();
11084 : else
11085 : json_vrf = json;
11086 0 : json_router = json_object_new_object();
11087 : }
11088 :
11089 0 : if (ospf->instance) {
11090 0 : if (!json)
11091 0 : vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
11092 : else
11093 0 : json_object_int_add(json_vrf, "ospfInstance",
11094 : ospf->instance);
11095 : }
11096 :
11097 0 : ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf);
11098 :
11099 0 : if (ospf->new_table == NULL) {
11100 0 : if (!json)
11101 0 : vty_out(vty, "No OSPF routing information exist\n");
11102 : else {
11103 0 : json_object_free(json_router);
11104 0 : if (use_vrf)
11105 0 : json_object_free(json_vrf);
11106 : }
11107 0 : return CMD_SUCCESS;
11108 : }
11109 :
11110 : /* Show Network routes.
11111 : show_ip_ospf_route_network (vty, ospf->new_table); */
11112 :
11113 : /* Show Router routes. */
11114 0 : show_ip_ospf_route_router(vty, ospf, ospf->new_rtrs, json_router);
11115 :
11116 0 : if (json) {
11117 0 : json_object_object_add(json_vrf, "routers", json_router);
11118 0 : if (use_vrf) {
11119 0 : if (ospf->vrf_id == VRF_DEFAULT)
11120 0 : json_object_object_add(json, "default",
11121 : json_vrf);
11122 : else
11123 0 : json_object_object_add(json, ospf->name,
11124 : json_vrf);
11125 : }
11126 : } else {
11127 0 : vty_out(vty, "\n");
11128 : }
11129 :
11130 : return CMD_SUCCESS;
11131 : }
11132 :
11133 0 : DEFPY (show_ip_ospf_border_routers,
11134 : show_ip_ospf_border_routers_cmd,
11135 : "show ip ospf [vrf <NAME|all>] border-routers [json]",
11136 : SHOW_STR
11137 : IP_STR
11138 : "OSPF information\n"
11139 : VRF_CMD_HELP_STR
11140 : "All VRFs\n"
11141 : "Show all the ABR's and ASBR's\n"
11142 : JSON_STR)
11143 : {
11144 0 : struct ospf *ospf = NULL;
11145 0 : struct listnode *node = NULL;
11146 0 : char *vrf_name = NULL;
11147 0 : bool all_vrf = false;
11148 0 : int ret = CMD_SUCCESS;
11149 0 : int inst = 0;
11150 0 : int idx_vrf = 0;
11151 0 : uint8_t use_vrf = 0;
11152 0 : bool uj = use_json(argc, argv);
11153 0 : json_object *json = NULL;
11154 :
11155 0 : if (uj)
11156 0 : json = json_object_new_object();
11157 :
11158 0 : OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
11159 :
11160 0 : if (vrf_name) {
11161 0 : bool ospf_output = false;
11162 :
11163 0 : use_vrf = 1;
11164 :
11165 0 : if (all_vrf) {
11166 0 : for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
11167 0 : if (!ospf->oi_running)
11168 0 : continue;
11169 :
11170 0 : ospf_output = true;
11171 0 : ret = show_ip_ospf_border_routers_common(
11172 : vty, ospf, use_vrf, json);
11173 : }
11174 :
11175 0 : if (uj)
11176 0 : vty_json(vty, json);
11177 0 : else if (!ospf_output)
11178 0 : vty_out(vty, "%% OSPF is not enabled\n");
11179 :
11180 0 : return ret;
11181 : } else {
11182 0 : ospf = ospf_lookup_by_inst_name(inst, vrf_name);
11183 0 : if (ospf == NULL || !ospf->oi_running) {
11184 0 : if (uj)
11185 0 : vty_json(vty, json);
11186 : else
11187 0 : vty_out(vty,
11188 : "%% OSPF is not enabled in vrf %s\n",
11189 : vrf_name);
11190 :
11191 0 : return CMD_SUCCESS;
11192 : }
11193 : }
11194 : } else {
11195 : /* Display default ospf (instance 0) info */
11196 0 : ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
11197 0 : if (ospf == NULL || !ospf->oi_running) {
11198 0 : if (uj)
11199 0 : vty_json(vty, json);
11200 : else
11201 0 : vty_out(vty,
11202 : "%% OSPF is not enabled in vrf default\n");
11203 :
11204 0 : return CMD_SUCCESS;
11205 : }
11206 : }
11207 :
11208 : if (ospf) {
11209 0 : ret = show_ip_ospf_border_routers_common(vty, ospf, use_vrf,
11210 : json);
11211 0 : if (uj)
11212 0 : vty_json(vty, json);
11213 : }
11214 :
11215 : return ret;
11216 : }
11217 :
11218 0 : DEFUN (show_ip_ospf_instance_border_routers,
11219 : show_ip_ospf_instance_border_routers_cmd,
11220 : "show ip ospf (1-65535) border-routers",
11221 : SHOW_STR
11222 : IP_STR
11223 : "OSPF information\n"
11224 : "Instance ID\n"
11225 : "Show all the ABR's and ASBR's\n")
11226 : {
11227 0 : int idx_number = 3;
11228 0 : struct ospf *ospf;
11229 0 : unsigned short instance = 0;
11230 :
11231 0 : instance = strtoul(argv[idx_number]->arg, NULL, 10);
11232 0 : if (instance != ospf_instance)
11233 : return CMD_NOT_MY_INSTANCE;
11234 :
11235 0 : ospf = ospf_lookup_instance(instance);
11236 0 : if (!ospf || !ospf->oi_running)
11237 : return CMD_SUCCESS;
11238 :
11239 0 : return show_ip_ospf_border_routers_common(vty, ospf, 0, NULL);
11240 : }
11241 :
11242 112 : static int show_ip_ospf_route_common(struct vty *vty, struct ospf *ospf,
11243 : json_object *json, uint8_t use_vrf)
11244 : {
11245 112 : json_object *json_vrf = NULL;
11246 :
11247 112 : if (ospf->instance)
11248 0 : vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
11249 :
11250 :
11251 112 : if (json) {
11252 0 : if (use_vrf)
11253 0 : json_vrf = json_object_new_object();
11254 : else
11255 : json_vrf = json;
11256 : }
11257 :
11258 112 : ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf);
11259 :
11260 112 : if (ospf->new_table == NULL) {
11261 0 : if (json) {
11262 0 : if (use_vrf)
11263 0 : json_object_free(json_vrf);
11264 : } else {
11265 0 : vty_out(vty, "No OSPF routing information exist\n");
11266 : }
11267 0 : return CMD_SUCCESS;
11268 : }
11269 :
11270 : /* Show Network routes. */
11271 112 : show_ip_ospf_route_network(vty, ospf, ospf->new_table, json_vrf);
11272 :
11273 : /* Show Router routes. */
11274 112 : show_ip_ospf_route_router(vty, ospf, ospf->new_rtrs, json_vrf);
11275 :
11276 : /* Show Router routes. */
11277 112 : if (ospf->all_rtrs)
11278 0 : show_ip_ospf_route_router(vty, ospf, ospf->all_rtrs, json_vrf);
11279 :
11280 : /* Show AS External routes. */
11281 112 : show_ip_ospf_route_external(vty, ospf, ospf->old_external_route,
11282 : json_vrf);
11283 :
11284 112 : if (json) {
11285 0 : if (use_vrf) {
11286 : // json_object_object_add(json_vrf, "areas",
11287 : // json_areas);
11288 0 : json_object_object_add(json, ospf_get_name(ospf),
11289 : json_vrf);
11290 : }
11291 : } else {
11292 112 : vty_out(vty, "\n");
11293 : }
11294 :
11295 : return CMD_SUCCESS;
11296 : }
11297 :
11298 112 : DEFUN (show_ip_ospf_route,
11299 : show_ip_ospf_route_cmd,
11300 : "show ip ospf [vrf <NAME|all>] route [json]",
11301 : SHOW_STR
11302 : IP_STR
11303 : "OSPF information\n"
11304 : VRF_CMD_HELP_STR
11305 : "All VRFs\n"
11306 : "OSPF routing table\n"
11307 : JSON_STR)
11308 : {
11309 112 : struct ospf *ospf = NULL;
11310 112 : struct listnode *node = NULL;
11311 112 : char *vrf_name = NULL;
11312 112 : bool all_vrf = false;
11313 112 : int ret = CMD_SUCCESS;
11314 112 : int inst = 0;
11315 112 : int idx_vrf = 0;
11316 112 : uint8_t use_vrf = 0;
11317 112 : bool uj = use_json(argc, argv);
11318 112 : json_object *json = NULL;
11319 :
11320 112 : if (uj)
11321 0 : json = json_object_new_object();
11322 :
11323 112 : OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
11324 :
11325 : /* vrf input is provided could be all or specific vrf*/
11326 112 : if (vrf_name) {
11327 0 : bool ospf_output = false;
11328 :
11329 0 : use_vrf = 1;
11330 :
11331 0 : if (all_vrf) {
11332 0 : for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
11333 0 : if (!ospf->oi_running)
11334 0 : continue;
11335 0 : ospf_output = true;
11336 0 : ret = show_ip_ospf_route_common(vty, ospf, json,
11337 : use_vrf);
11338 : }
11339 :
11340 0 : if (uj) {
11341 : /* Keep Non-pretty format */
11342 0 : vty_json(vty, json);
11343 0 : } else if (!ospf_output)
11344 0 : vty_out(vty, "%% OSPF is not enabled\n");
11345 :
11346 0 : return ret;
11347 : }
11348 0 : ospf = ospf_lookup_by_inst_name(inst, vrf_name);
11349 0 : if (ospf == NULL || !ospf->oi_running) {
11350 0 : if (uj)
11351 0 : vty_json(vty, json);
11352 : else
11353 0 : vty_out(vty,
11354 : "%% OSPF is not enabled in vrf %s\n",
11355 : vrf_name);
11356 :
11357 0 : return CMD_SUCCESS;
11358 : }
11359 : } else {
11360 : /* Display default ospf (instance 0) info */
11361 112 : ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
11362 112 : if (ospf == NULL || !ospf->oi_running) {
11363 0 : if (uj)
11364 0 : vty_json(vty, json);
11365 : else
11366 0 : vty_out(vty,
11367 : "%% OSPF is not enabled in vrf default\n");
11368 :
11369 0 : return CMD_SUCCESS;
11370 : }
11371 : }
11372 :
11373 : if (ospf) {
11374 112 : ret = show_ip_ospf_route_common(vty, ospf, json, use_vrf);
11375 : /* Keep Non-pretty format */
11376 112 : if (uj)
11377 0 : vty_out(vty, "%s\n",
11378 : json_object_to_json_string_ext(
11379 : json, JSON_C_TO_STRING_NOSLASHESCAPE));
11380 : }
11381 :
11382 0 : if (uj)
11383 0 : json_object_free(json);
11384 :
11385 : return ret;
11386 : }
11387 :
11388 0 : DEFUN (show_ip_ospf_instance_route,
11389 : show_ip_ospf_instance_route_cmd,
11390 : "show ip ospf (1-65535) route",
11391 : SHOW_STR
11392 : IP_STR
11393 : "OSPF information\n"
11394 : "Instance ID\n"
11395 : "OSPF routing table\n")
11396 : {
11397 0 : int idx_number = 3;
11398 0 : struct ospf *ospf;
11399 0 : unsigned short instance = 0;
11400 :
11401 0 : instance = strtoul(argv[idx_number]->arg, NULL, 10);
11402 0 : if (instance != ospf_instance)
11403 : return CMD_NOT_MY_INSTANCE;
11404 :
11405 0 : ospf = ospf_lookup_instance(instance);
11406 0 : if (!ospf || !ospf->oi_running)
11407 : return CMD_SUCCESS;
11408 :
11409 0 : return show_ip_ospf_route_common(vty, ospf, NULL, 0);
11410 : }
11411 :
11412 :
11413 0 : DEFUN (show_ip_ospf_vrfs,
11414 : show_ip_ospf_vrfs_cmd,
11415 : "show ip ospf vrfs [json]",
11416 : SHOW_STR
11417 : IP_STR
11418 : "OSPF information\n"
11419 : "Show OSPF VRFs \n"
11420 : JSON_STR)
11421 : {
11422 0 : bool uj = use_json(argc, argv);
11423 0 : json_object *json = NULL;
11424 0 : json_object *json_vrfs = NULL;
11425 0 : struct ospf *ospf = NULL;
11426 0 : struct listnode *node = NULL;
11427 0 : int count = 0;
11428 0 : static const char header[] = "Name Id RouterId ";
11429 :
11430 0 : if (uj) {
11431 0 : json = json_object_new_object();
11432 0 : json_vrfs = json_object_new_object();
11433 : }
11434 :
11435 0 : for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
11436 0 : json_object *json_vrf = NULL;
11437 0 : const char *name = NULL;
11438 0 : int64_t vrf_id_ui = 0;
11439 :
11440 0 : count++;
11441 :
11442 0 : if (!uj && count == 1)
11443 0 : vty_out(vty, "%s\n", header);
11444 0 : if (uj)
11445 0 : json_vrf = json_object_new_object();
11446 :
11447 0 : name = ospf_get_name(ospf);
11448 :
11449 0 : vrf_id_ui = (ospf->vrf_id == VRF_UNKNOWN)
11450 : ? -1
11451 0 : : (int64_t)ospf->vrf_id;
11452 :
11453 0 : if (uj) {
11454 0 : json_object_int_add(json_vrf, "vrfId", vrf_id_ui);
11455 0 : json_object_string_addf(json_vrf, "routerId", "%pI4",
11456 : &ospf->router_id);
11457 :
11458 0 : json_object_object_add(json_vrfs, name, json_vrf);
11459 :
11460 : } else {
11461 0 : vty_out(vty, "%-25s %-5d %-16pI4 \n", name,
11462 : ospf->vrf_id, &ospf->router_id);
11463 : }
11464 : }
11465 :
11466 0 : if (uj) {
11467 0 : json_object_object_add(json, "vrfs", json_vrfs);
11468 0 : json_object_int_add(json, "totalVrfs", count);
11469 :
11470 0 : vty_json(vty, json);
11471 : } else {
11472 0 : if (count)
11473 0 : vty_out(vty, "\nTotal number of OSPF VRFs: %d\n",
11474 : count);
11475 : }
11476 :
11477 0 : return CMD_SUCCESS;
11478 : }
11479 0 : DEFPY (clear_ip_ospf_neighbor,
11480 : clear_ip_ospf_neighbor_cmd,
11481 : "clear ip ospf [(1-65535)]$instance neighbor [A.B.C.D$nbr_id]",
11482 : CLEAR_STR
11483 : IP_STR
11484 : "OSPF information\n"
11485 : "Instance ID\n"
11486 : "Reset OSPF Neighbor\n"
11487 : "Neighbor ID\n")
11488 : {
11489 0 : struct listnode *node;
11490 0 : struct ospf *ospf = NULL;
11491 :
11492 : /* If user does not specify the arguments,
11493 : * instance = 0 and nbr_id = 0.0.0.0
11494 : */
11495 0 : if (instance != 0) {
11496 : /* This means clear only the particular ospf process */
11497 0 : if (instance != ospf_instance)
11498 : return CMD_NOT_MY_INSTANCE;
11499 : }
11500 :
11501 : /* Clear all the ospf processes */
11502 0 : for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
11503 0 : if (!ospf->oi_running)
11504 0 : continue;
11505 :
11506 0 : if (nbr_id_str && IPV4_ADDR_SAME(&ospf->router_id, &nbr_id)) {
11507 0 : vty_out(vty, "Self router-id is not allowed.\r\n ");
11508 0 : return CMD_SUCCESS;
11509 : }
11510 :
11511 0 : ospf_neighbor_reset(ospf, nbr_id, nbr_id_str);
11512 : }
11513 :
11514 : return CMD_SUCCESS;
11515 : }
11516 :
11517 0 : DEFPY (clear_ip_ospf_process,
11518 : clear_ip_ospf_process_cmd,
11519 : "clear ip ospf [(1-65535)]$instance process",
11520 : CLEAR_STR
11521 : IP_STR
11522 : "OSPF information\n"
11523 : "Instance ID\n"
11524 : "Reset OSPF Process\n")
11525 : {
11526 0 : struct listnode *node;
11527 0 : struct ospf *ospf = NULL;
11528 :
11529 : /* Check if instance is not passed as an argument */
11530 0 : if (instance != 0) {
11531 : /* This means clear only the particular ospf process */
11532 0 : if (instance != ospf_instance)
11533 : return CMD_NOT_MY_INSTANCE;
11534 : }
11535 :
11536 : /* Clear all the ospf processes */
11537 0 : for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
11538 0 : if (!ospf->oi_running)
11539 0 : continue;
11540 :
11541 0 : ospf_process_reset(ospf);
11542 : }
11543 :
11544 : return CMD_SUCCESS;
11545 : }
11546 :
11547 : static const char *const ospf_abr_type_str[] = {
11548 : "unknown", "standard", "ibm", "cisco", "shortcut"
11549 : };
11550 :
11551 : static const char *const ospf_shortcut_mode_str[] = {
11552 : "default", "enable", "disable"
11553 : };
11554 0 : static int ospf_vty_external_rt_walkcb(struct hash_bucket *bucket,
11555 : void *arg)
11556 : {
11557 0 : struct external_info *ei = bucket->data;
11558 0 : struct vty *vty = (struct vty *)arg;
11559 0 : static unsigned int count;
11560 :
11561 0 : vty_out(vty, "%-4pI4/%d, ", &ei->p.prefix, ei->p.prefixlen);
11562 0 : count++;
11563 :
11564 0 : if (count % 5 == 0)
11565 0 : vty_out(vty, "\n");
11566 :
11567 0 : if (OSPF_EXTERNAL_RT_COUNT(ei->aggr_route) == count)
11568 0 : count = 0;
11569 :
11570 0 : return HASHWALK_CONTINUE;
11571 : }
11572 :
11573 0 : static int ospf_json_external_rt_walkcb(struct hash_bucket *bucket,
11574 : void *arg)
11575 : {
11576 0 : struct external_info *ei = bucket->data;
11577 0 : struct json_object *json = (struct json_object *)arg;
11578 0 : char buf[PREFIX2STR_BUFFER];
11579 0 : char exnalbuf[20];
11580 0 : static unsigned int count;
11581 :
11582 0 : prefix2str(&ei->p, buf, sizeof(buf));
11583 :
11584 0 : snprintf(exnalbuf, 20, "Exnl Addr-%d", count);
11585 :
11586 0 : json_object_string_add(json, exnalbuf, buf);
11587 :
11588 0 : count++;
11589 :
11590 0 : if (OSPF_EXTERNAL_RT_COUNT(ei->aggr_route) == count)
11591 0 : count = 0;
11592 :
11593 0 : return HASHWALK_CONTINUE;
11594 : }
11595 :
11596 0 : static int ospf_show_summary_address(struct vty *vty, struct ospf *ospf,
11597 : uint8_t use_vrf, json_object *json,
11598 : bool uj, bool detail)
11599 : {
11600 0 : struct route_node *rn;
11601 0 : json_object *json_vrf = NULL;
11602 0 : int mtype = 0;
11603 0 : int mval = 0;
11604 0 : static char header[] =
11605 : "Summary-address Metric-type Metric Tag External_Rt_count\n";
11606 :
11607 0 : mtype = metric_type(ospf, 0, ospf->instance);
11608 0 : mval = metric_value(ospf, 0, ospf->instance);
11609 :
11610 0 : if (!uj)
11611 0 : vty_out(vty, "%s\n", header);
11612 :
11613 0 : if (uj) {
11614 0 : if (use_vrf)
11615 0 : json_vrf = json_object_new_object();
11616 : else
11617 : json_vrf = json;
11618 : }
11619 :
11620 0 : if (ospf->instance) {
11621 0 : if (uj)
11622 0 : json_object_int_add(json, "ospfInstance",
11623 : ospf->instance);
11624 : else
11625 0 : vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance);
11626 : }
11627 :
11628 0 : ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf);
11629 :
11630 0 : if (!uj) {
11631 0 : vty_out(vty, "aggregation delay interval :%u(in seconds)\n\n",
11632 0 : ospf->aggr_delay_interval);
11633 : } else {
11634 0 : json_object_int_add(json_vrf, "aggregationDelayInterval",
11635 0 : ospf->aggr_delay_interval);
11636 : }
11637 :
11638 0 : for (rn = route_top(ospf->rt_aggr_tbl); rn; rn = route_next(rn))
11639 0 : if (rn->info) {
11640 0 : struct ospf_external_aggr_rt *aggr = rn->info;
11641 0 : json_object *json_aggr = NULL;
11642 0 : char buf[PREFIX2STR_BUFFER];
11643 :
11644 0 : prefix2str(&aggr->p, buf, sizeof(buf));
11645 :
11646 0 : if (uj) {
11647 :
11648 0 : json_aggr = json_object_new_object();
11649 :
11650 0 : json_object_object_add(json_vrf, buf,
11651 : json_aggr);
11652 0 : json_object_string_add(json_aggr,
11653 : "summaryAddress", buf);
11654 0 : json_object_string_add(
11655 : json_aggr, "metricType",
11656 : (mtype == EXTERNAL_METRIC_TYPE_1)
11657 : ? "E1"
11658 : : "E2");
11659 :
11660 0 : json_object_int_add(json_aggr, "metric", mval);
11661 0 : json_object_int_add(json_aggr, "tag",
11662 0 : aggr->tag);
11663 0 : json_object_int_add(
11664 : json_aggr, "externalRouteCount",
11665 0 : OSPF_EXTERNAL_RT_COUNT(aggr));
11666 :
11667 0 : if (OSPF_EXTERNAL_RT_COUNT(aggr) && detail) {
11668 0 : hash_walk(
11669 : aggr->match_extnl_hash,
11670 : ospf_json_external_rt_walkcb,
11671 : json_aggr);
11672 : }
11673 :
11674 : } else {
11675 0 : vty_out(vty, "%-20s", buf);
11676 :
11677 0 : (mtype == EXTERNAL_METRIC_TYPE_1)
11678 0 : ? vty_out(vty, "%-16s", "E1")
11679 0 : : vty_out(vty, "%-16s", "E2");
11680 0 : vty_out(vty, "%-11d", mval);
11681 :
11682 0 : vty_out(vty, "%-12u", aggr->tag);
11683 :
11684 0 : vty_out(vty, "%-5ld\n",
11685 0 : OSPF_EXTERNAL_RT_COUNT(aggr));
11686 :
11687 0 : if (OSPF_EXTERNAL_RT_COUNT(aggr) && detail) {
11688 0 : vty_out(vty,
11689 : "Matched External routes:\n");
11690 0 : hash_walk(
11691 : aggr->match_extnl_hash,
11692 : ospf_vty_external_rt_walkcb,
11693 : vty);
11694 0 : vty_out(vty, "\n");
11695 : }
11696 :
11697 0 : vty_out(vty, "\n");
11698 : }
11699 : }
11700 :
11701 0 : if (uj) {
11702 0 : if (use_vrf)
11703 0 : json_object_object_add(json, ospf_get_name(ospf),
11704 : json_vrf);
11705 : } else
11706 0 : vty_out(vty, "\n");
11707 :
11708 0 : return CMD_SUCCESS;
11709 : }
11710 :
11711 0 : DEFUN (show_ip_ospf_external_aggregator,
11712 : show_ip_ospf_external_aggregator_cmd,
11713 : "show ip ospf [vrf <NAME|all>] summary-address [detail] [json]",
11714 : SHOW_STR IP_STR
11715 : "OSPF information\n"
11716 : VRF_CMD_HELP_STR
11717 : "All VRFs\n"
11718 : "Show external summary addresses\n"
11719 : "Detailed information\n"
11720 : JSON_STR)
11721 : {
11722 0 : char *vrf_name = NULL;
11723 0 : bool all_vrf = false;
11724 0 : int ret = CMD_SUCCESS;
11725 0 : int idx_vrf = 0;
11726 0 : int idx = 0;
11727 0 : uint8_t use_vrf = 0;
11728 0 : bool uj = use_json(argc, argv);
11729 0 : struct ospf *ospf = NULL;
11730 0 : json_object *json = NULL;
11731 0 : struct listnode *node = NULL;
11732 0 : int inst = 0;
11733 0 : bool detail = false;
11734 :
11735 0 : OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf);
11736 :
11737 0 : if (argv_find(argv, argc, "detail", &idx))
11738 0 : detail = true;
11739 :
11740 0 : if (uj)
11741 0 : json = json_object_new_object();
11742 :
11743 : /* vrf input is provided */
11744 0 : if (vrf_name) {
11745 0 : use_vrf = 1;
11746 0 : if (all_vrf) {
11747 0 : for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
11748 0 : if (!ospf->oi_running)
11749 0 : continue;
11750 0 : ret = ospf_show_summary_address(
11751 : vty, ospf, use_vrf, json, uj, detail);
11752 : }
11753 :
11754 0 : if (uj)
11755 0 : vty_json(vty, json);
11756 :
11757 0 : return ret;
11758 : }
11759 :
11760 0 : ospf = ospf_lookup_by_inst_name(inst, vrf_name);
11761 :
11762 0 : if (ospf == NULL || !ospf->oi_running) {
11763 0 : if (uj)
11764 0 : vty_json(vty, json);
11765 : else
11766 0 : vty_out(vty,
11767 : "%% OSPF is not enabled in vrf %s\n",
11768 : vrf_name);
11769 :
11770 0 : return CMD_SUCCESS;
11771 : }
11772 0 : ospf_show_summary_address(vty, ospf, use_vrf, json, uj, detail);
11773 :
11774 : } else {
11775 : /* Default Vrf */
11776 0 : ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT);
11777 0 : if (ospf == NULL || !ospf->oi_running) {
11778 0 : if (uj)
11779 0 : vty_json(vty, json);
11780 : else
11781 0 : vty_out(vty,
11782 : "%% OSPF is not enabled in vrf default\n");
11783 :
11784 0 : return CMD_SUCCESS;
11785 : }
11786 :
11787 0 : ospf_show_summary_address(vty, ospf, use_vrf, json, uj, detail);
11788 : }
11789 :
11790 0 : if (uj)
11791 0 : vty_json(vty, json);
11792 : return CMD_SUCCESS;
11793 : }
11794 :
11795 : static const char *const ospf_int_type_str[] = {
11796 : "unknown", /* should never be used. */
11797 : "point-to-point",
11798 : "broadcast",
11799 : "non-broadcast",
11800 : "point-to-multipoint",
11801 : "virtual-link", /* should never be used. */
11802 : "loopback"
11803 : };
11804 :
11805 0 : static const char *interface_config_auth_str(struct ospf_if_params *params)
11806 : {
11807 0 : if (!OSPF_IF_PARAM_CONFIGURED(params, auth_type)
11808 0 : || params->auth_type == OSPF_AUTH_NOTSET)
11809 : return NULL;
11810 :
11811 : /* Translation tables are not that much help
11812 : * here due to syntax
11813 : * of the simple option */
11814 0 : switch (params->auth_type) {
11815 :
11816 : case OSPF_AUTH_NULL:
11817 : return " null";
11818 :
11819 : case OSPF_AUTH_SIMPLE:
11820 : return "";
11821 :
11822 0 : case OSPF_AUTH_CRYPTOGRAPHIC:
11823 0 : return " message-digest";
11824 : }
11825 :
11826 : return "";
11827 : }
11828 :
11829 0 : static int config_write_interface_one(struct vty *vty, struct vrf *vrf)
11830 : {
11831 0 : struct listnode *node;
11832 0 : struct interface *ifp;
11833 0 : struct crypt_key *ck;
11834 0 : struct route_node *rn = NULL;
11835 0 : struct ospf_if_params *params;
11836 0 : const char *auth_str;
11837 0 : int write = 0;
11838 :
11839 0 : FOR_ALL_INTERFACES (vrf, ifp) {
11840 :
11841 0 : if (memcmp(ifp->name, "VLINK", 5) == 0)
11842 0 : continue;
11843 :
11844 0 : if_vty_config_start(vty, ifp);
11845 :
11846 0 : if (ifp->desc)
11847 0 : vty_out(vty, " description %s\n", ifp->desc);
11848 :
11849 0 : write++;
11850 :
11851 0 : params = IF_DEF_PARAMS(ifp);
11852 :
11853 0 : do {
11854 : /* Interface Network print. */
11855 0 : if (OSPF_IF_PARAM_CONFIGURED(params, type)
11856 0 : && params->type != OSPF_IFTYPE_LOOPBACK) {
11857 0 : if (params->type != ospf_default_iftype(ifp)) {
11858 0 : vty_out(vty, " ip ospf network %s",
11859 : ospf_int_type_str
11860 0 : [params->type]);
11861 0 : if (params->type
11862 : == OSPF_IFTYPE_POINTOPOINT
11863 0 : && params->ptp_dmvpn)
11864 0 : vty_out(vty, " dmvpn");
11865 0 : if (params != IF_DEF_PARAMS(ifp) && rn)
11866 0 : vty_out(vty, " %pI4",
11867 : &rn->p.u.prefix4);
11868 0 : vty_out(vty, "\n");
11869 : }
11870 : }
11871 :
11872 : /* OSPF interface authentication print */
11873 0 : auth_str = interface_config_auth_str(params);
11874 0 : if (auth_str) {
11875 0 : vty_out(vty, " ip ospf authentication%s",
11876 : auth_str);
11877 0 : if (params != IF_DEF_PARAMS(ifp) && rn)
11878 0 : vty_out(vty, " %pI4",
11879 : &rn->p.u.prefix4);
11880 0 : vty_out(vty, "\n");
11881 : }
11882 :
11883 : /* Simple Authentication Password print. */
11884 0 : if (OSPF_IF_PARAM_CONFIGURED(params, auth_simple)
11885 0 : && params->auth_simple[0] != '\0') {
11886 0 : vty_out(vty, " ip ospf authentication-key %s",
11887 0 : params->auth_simple);
11888 0 : if (params != IF_DEF_PARAMS(ifp) && rn)
11889 0 : vty_out(vty, " %pI4",
11890 : &rn->p.u.prefix4);
11891 0 : vty_out(vty, "\n");
11892 : }
11893 :
11894 : /* Cryptographic Authentication Key print. */
11895 0 : if (params && params->auth_crypt) {
11896 0 : for (ALL_LIST_ELEMENTS_RO(params->auth_crypt,
11897 : node, ck)) {
11898 0 : vty_out(vty,
11899 : " ip ospf message-digest-key %d md5 %s",
11900 0 : ck->key_id, ck->auth_key);
11901 0 : if (params != IF_DEF_PARAMS(ifp) && rn)
11902 0 : vty_out(vty, " %pI4",
11903 : &rn->p.u.prefix4);
11904 0 : vty_out(vty, "\n");
11905 : }
11906 : }
11907 :
11908 : /* Interface Output Cost print. */
11909 0 : if (OSPF_IF_PARAM_CONFIGURED(params, output_cost_cmd)) {
11910 0 : vty_out(vty, " ip ospf cost %u",
11911 : params->output_cost_cmd);
11912 0 : if (params != IF_DEF_PARAMS(ifp) && rn)
11913 0 : vty_out(vty, " %pI4",
11914 : &rn->p.u.prefix4);
11915 0 : vty_out(vty, "\n");
11916 : }
11917 :
11918 : /* Hello Interval print. */
11919 0 : if (OSPF_IF_PARAM_CONFIGURED(params, v_hello)
11920 0 : && params->v_hello != OSPF_HELLO_INTERVAL_DEFAULT) {
11921 0 : vty_out(vty, " ip ospf hello-interval %u",
11922 : params->v_hello);
11923 0 : if (params != IF_DEF_PARAMS(ifp) && rn)
11924 0 : vty_out(vty, " %pI4",
11925 : &rn->p.u.prefix4);
11926 0 : vty_out(vty, "\n");
11927 : }
11928 :
11929 :
11930 : /* Router Dead Interval print. */
11931 0 : if (OSPF_IF_PARAM_CONFIGURED(params, v_wait)
11932 0 : && params->is_v_wait_set) {
11933 0 : vty_out(vty, " ip ospf dead-interval ");
11934 :
11935 : /* fast hello ? */
11936 0 : if (OSPF_IF_PARAM_CONFIGURED(params,
11937 : fast_hello))
11938 0 : vty_out(vty,
11939 : "minimal hello-multiplier %d",
11940 0 : params->fast_hello);
11941 : else
11942 0 : vty_out(vty, "%u", params->v_wait);
11943 :
11944 0 : if (params != IF_DEF_PARAMS(ifp) && rn)
11945 0 : vty_out(vty, " %pI4",
11946 : &rn->p.u.prefix4);
11947 0 : vty_out(vty, "\n");
11948 : }
11949 :
11950 : /* Router Priority print. */
11951 0 : if (OSPF_IF_PARAM_CONFIGURED(params, priority)
11952 0 : && params->priority
11953 : != OSPF_ROUTER_PRIORITY_DEFAULT) {
11954 0 : vty_out(vty, " ip ospf priority %u",
11955 : params->priority);
11956 0 : if (params != IF_DEF_PARAMS(ifp) && rn)
11957 0 : vty_out(vty, " %pI4",
11958 : &rn->p.u.prefix4);
11959 0 : vty_out(vty, "\n");
11960 : }
11961 :
11962 : /* Retransmit Interval print. */
11963 0 : if (OSPF_IF_PARAM_CONFIGURED(params,
11964 : retransmit_interval)
11965 0 : && params->retransmit_interval
11966 : != OSPF_RETRANSMIT_INTERVAL_DEFAULT) {
11967 0 : vty_out(vty, " ip ospf retransmit-interval %u",
11968 : params->retransmit_interval);
11969 0 : if (params != IF_DEF_PARAMS(ifp) && rn)
11970 0 : vty_out(vty, " %pI4",
11971 : &rn->p.u.prefix4);
11972 0 : vty_out(vty, "\n");
11973 : }
11974 :
11975 : /* Transmit Delay print. */
11976 0 : if (OSPF_IF_PARAM_CONFIGURED(params, transmit_delay)
11977 0 : && params->transmit_delay
11978 : != OSPF_TRANSMIT_DELAY_DEFAULT) {
11979 0 : vty_out(vty, " ip ospf transmit-delay %u",
11980 : params->transmit_delay);
11981 0 : if (params != IF_DEF_PARAMS(ifp) && rn)
11982 0 : vty_out(vty, " %pI4",
11983 : &rn->p.u.prefix4);
11984 0 : vty_out(vty, "\n");
11985 : }
11986 :
11987 : /* Area print. */
11988 0 : if (OSPF_IF_PARAM_CONFIGURED(params, if_area)) {
11989 0 : if (ospf_instance)
11990 0 : vty_out(vty, " ip ospf %d",
11991 : ospf_instance);
11992 : else
11993 0 : vty_out(vty, " ip ospf");
11994 :
11995 0 : char buf[INET_ADDRSTRLEN];
11996 :
11997 0 : area_id2str(buf, sizeof(buf), ¶ms->if_area,
11998 0 : params->if_area_id_fmt);
11999 0 : vty_out(vty, " area %s", buf);
12000 0 : if (params != IF_DEF_PARAMS(ifp) && rn)
12001 0 : vty_out(vty, " %pI4",
12002 : &rn->p.u.prefix4);
12003 0 : vty_out(vty, "\n");
12004 : }
12005 :
12006 : /* bfd print. */
12007 0 : if (params && params->bfd_config)
12008 0 : ospf_bfd_write_config(vty, params);
12009 :
12010 : /* MTU ignore print. */
12011 0 : if (OSPF_IF_PARAM_CONFIGURED(params, mtu_ignore)
12012 0 : && params->mtu_ignore != OSPF_MTU_IGNORE_DEFAULT) {
12013 0 : if (params->mtu_ignore == 0)
12014 : vty_out(vty, " no ip ospf mtu-ignore");
12015 : else
12016 0 : vty_out(vty, " ip ospf mtu-ignore");
12017 0 : if (params != IF_DEF_PARAMS(ifp) && rn)
12018 0 : vty_out(vty, " %pI4",
12019 : &rn->p.u.prefix4);
12020 0 : vty_out(vty, "\n");
12021 : }
12022 :
12023 0 : if (OSPF_IF_PARAM_CONFIGURED(params,
12024 : passive_interface)) {
12025 0 : vty_out(vty, " %sip ospf passive",
12026 0 : params->passive_interface
12027 : == OSPF_IF_ACTIVE
12028 : ? "no "
12029 : : "");
12030 0 : if (params != IF_DEF_PARAMS(ifp) && rn)
12031 0 : vty_out(vty, " %pI4", &rn->p.u.prefix4);
12032 0 : vty_out(vty, "\n");
12033 : }
12034 :
12035 : /* LDP-Sync print */
12036 0 : if (params && params->ldp_sync_info)
12037 0 : ospf_ldp_sync_if_write_config(vty, params);
12038 :
12039 0 : while (1) {
12040 0 : if (rn == NULL)
12041 0 : rn = route_top(IF_OIFS_PARAMS(ifp));
12042 : else
12043 0 : rn = route_next(rn);
12044 :
12045 0 : if (rn == NULL)
12046 : break;
12047 0 : params = rn->info;
12048 0 : if (params != NULL)
12049 : break;
12050 : }
12051 0 : } while (rn);
12052 :
12053 0 : ospf_opaque_config_write_if(vty, ifp);
12054 :
12055 0 : if_vty_config_end(vty);
12056 : }
12057 :
12058 0 : return write;
12059 : }
12060 :
12061 : /* Configuration write function for ospfd. */
12062 0 : static int config_write_interface(struct vty *vty)
12063 : {
12064 0 : int write = 0;
12065 0 : struct vrf *vrf = NULL;
12066 :
12067 : /* Display all VRF aware OSPF interface configuration */
12068 0 : RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) {
12069 0 : write += config_write_interface_one(vty, vrf);
12070 : }
12071 :
12072 0 : return write;
12073 : }
12074 :
12075 0 : static int config_write_network_area(struct vty *vty, struct ospf *ospf)
12076 : {
12077 0 : struct route_node *rn;
12078 0 : char buf[INET_ADDRSTRLEN];
12079 :
12080 : /* `network area' print. */
12081 0 : for (rn = route_top(ospf->networks); rn; rn = route_next(rn))
12082 0 : if (rn->info) {
12083 0 : struct ospf_network *n = rn->info;
12084 :
12085 : /* Create Area ID string by specified Area ID format. */
12086 0 : if (n->area_id_fmt == OSPF_AREA_ID_FMT_DOTTEDQUAD)
12087 0 : inet_ntop(AF_INET, &n->area_id, buf,
12088 : sizeof(buf));
12089 : else
12090 0 : snprintf(buf, sizeof(buf), "%lu",
12091 0 : (unsigned long int)ntohl(
12092 : n->area_id.s_addr));
12093 :
12094 : /* Network print. */
12095 0 : vty_out(vty, " network %pFX area %s\n", &rn->p, buf);
12096 : }
12097 :
12098 0 : return 0;
12099 : }
12100 :
12101 0 : static int config_write_ospf_area(struct vty *vty, struct ospf *ospf)
12102 : {
12103 0 : struct listnode *node;
12104 0 : struct ospf_area *area;
12105 0 : char buf[INET_ADDRSTRLEN];
12106 :
12107 : /* Area configuration print. */
12108 0 : for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) {
12109 0 : struct route_node *rn1;
12110 :
12111 0 : area_id2str(buf, sizeof(buf), &area->area_id,
12112 : area->area_id_fmt);
12113 :
12114 0 : if (area->auth_type != OSPF_AUTH_NULL) {
12115 0 : if (area->auth_type == OSPF_AUTH_SIMPLE)
12116 0 : vty_out(vty, " area %s authentication\n", buf);
12117 : else
12118 0 : vty_out(vty,
12119 : " area %s authentication message-digest\n",
12120 : buf);
12121 : }
12122 :
12123 0 : if (area->shortcut_configured != OSPF_SHORTCUT_DEFAULT)
12124 0 : vty_out(vty, " area %s shortcut %s\n", buf,
12125 : ospf_shortcut_mode_str
12126 0 : [area->shortcut_configured]);
12127 :
12128 0 : if ((area->external_routing == OSPF_AREA_STUB)
12129 0 : || (area->external_routing == OSPF_AREA_NSSA)) {
12130 0 : if (area->external_routing == OSPF_AREA_STUB) {
12131 0 : vty_out(vty, " area %s stub", buf);
12132 0 : if (area->no_summary)
12133 0 : vty_out(vty, " no-summary\n");
12134 0 : vty_out(vty, "\n");
12135 0 : } else if (area->external_routing == OSPF_AREA_NSSA) {
12136 0 : switch (area->NSSATranslatorRole) {
12137 0 : case OSPF_NSSA_ROLE_NEVER:
12138 0 : vty_out(vty,
12139 : " area %s nssa translate-never\n",
12140 : buf);
12141 0 : break;
12142 0 : case OSPF_NSSA_ROLE_ALWAYS:
12143 0 : vty_out(vty,
12144 : " area %s nssa translate-always\n",
12145 : buf);
12146 0 : break;
12147 0 : case OSPF_NSSA_ROLE_CANDIDATE:
12148 0 : vty_out(vty, " area %s nssa \n", buf);
12149 0 : break;
12150 : }
12151 0 : if (area->no_summary)
12152 0 : vty_out(vty,
12153 : " area %s nssa no-summary\n",
12154 : buf);
12155 0 : if (area->suppress_fa)
12156 0 : vty_out(vty,
12157 : " area %s nssa suppress-fa\n",
12158 : buf);
12159 : }
12160 :
12161 0 : if (area->default_cost != 1)
12162 0 : vty_out(vty, " area %s default-cost %d\n", buf,
12163 : area->default_cost);
12164 : }
12165 :
12166 0 : for (rn1 = route_top(area->ranges); rn1; rn1 = route_next(rn1))
12167 0 : if (rn1->info) {
12168 0 : struct ospf_area_range *range = rn1->info;
12169 :
12170 0 : vty_out(vty, " area %s range %pFX", buf,
12171 : &rn1->p);
12172 :
12173 0 : if (range->cost_config
12174 : != OSPF_AREA_RANGE_COST_UNSPEC)
12175 0 : vty_out(vty, " cost %d",
12176 : range->cost_config);
12177 :
12178 0 : if (!CHECK_FLAG(range->flags,
12179 : OSPF_AREA_RANGE_ADVERTISE))
12180 0 : vty_out(vty, " not-advertise");
12181 :
12182 0 : if (CHECK_FLAG(range->flags,
12183 : OSPF_AREA_RANGE_SUBSTITUTE))
12184 0 : vty_out(vty, " substitute %pI4/%d",
12185 : &range->subst_addr,
12186 0 : range->subst_masklen);
12187 :
12188 0 : vty_out(vty, "\n");
12189 : }
12190 :
12191 0 : if (EXPORT_NAME(area))
12192 0 : vty_out(vty, " area %s export-list %s\n", buf,
12193 : EXPORT_NAME(area));
12194 :
12195 0 : if (IMPORT_NAME(area))
12196 0 : vty_out(vty, " area %s import-list %s\n", buf,
12197 : IMPORT_NAME(area));
12198 :
12199 0 : if (PREFIX_NAME_IN(area))
12200 0 : vty_out(vty, " area %s filter-list prefix %s in\n", buf,
12201 : PREFIX_NAME_IN(area));
12202 :
12203 0 : if (PREFIX_NAME_OUT(area))
12204 0 : vty_out(vty, " area %s filter-list prefix %s out\n",
12205 : buf, PREFIX_NAME_OUT(area));
12206 : }
12207 :
12208 0 : return 0;
12209 : }
12210 :
12211 0 : static int config_write_ospf_nbr_nbma(struct vty *vty, struct ospf *ospf)
12212 : {
12213 0 : struct ospf_nbr_nbma *nbr_nbma;
12214 0 : struct route_node *rn;
12215 :
12216 : /* Static Neighbor configuration print. */
12217 0 : for (rn = route_top(ospf->nbr_nbma); rn; rn = route_next(rn))
12218 0 : if ((nbr_nbma = rn->info)) {
12219 0 : vty_out(vty, " neighbor %pI4", &nbr_nbma->addr);
12220 :
12221 0 : if (nbr_nbma->priority
12222 : != OSPF_NEIGHBOR_PRIORITY_DEFAULT)
12223 0 : vty_out(vty, " priority %d",
12224 : nbr_nbma->priority);
12225 :
12226 0 : if (nbr_nbma->v_poll != OSPF_POLL_INTERVAL_DEFAULT)
12227 0 : vty_out(vty, " poll-interval %d",
12228 : nbr_nbma->v_poll);
12229 :
12230 0 : vty_out(vty, "\n");
12231 : }
12232 :
12233 0 : return 0;
12234 : }
12235 :
12236 0 : static int config_write_virtual_link(struct vty *vty, struct ospf *ospf)
12237 : {
12238 0 : struct listnode *node;
12239 0 : struct ospf_vl_data *vl_data;
12240 0 : const char *auth_str;
12241 0 : char buf[INET_ADDRSTRLEN];
12242 :
12243 : /* Virtual-Link print */
12244 0 : for (ALL_LIST_ELEMENTS_RO(ospf->vlinks, node, vl_data)) {
12245 0 : struct listnode *n2;
12246 0 : struct crypt_key *ck;
12247 0 : struct ospf_interface *oi;
12248 :
12249 0 : if (vl_data != NULL) {
12250 0 : area_id2str(buf, sizeof(buf), &vl_data->vl_area_id,
12251 : vl_data->vl_area_id_fmt);
12252 0 : oi = vl_data->vl_oi;
12253 :
12254 : /* timers */
12255 0 : if (OSPF_IF_PARAM(oi, v_hello)
12256 0 : != OSPF_HELLO_INTERVAL_DEFAULT
12257 0 : || OSPF_IF_PARAM(oi, v_wait)
12258 0 : != OSPF_ROUTER_DEAD_INTERVAL_DEFAULT
12259 0 : || OSPF_IF_PARAM(oi, retransmit_interval)
12260 0 : != OSPF_RETRANSMIT_INTERVAL_DEFAULT
12261 0 : || OSPF_IF_PARAM(oi, transmit_delay)
12262 0 : != OSPF_TRANSMIT_DELAY_DEFAULT)
12263 0 : vty_out(vty,
12264 : " area %s virtual-link %pI4 hello-interval %d retransmit-interval %d transmit-delay %d dead-interval %d\n",
12265 : buf, &vl_data->vl_peer,
12266 0 : OSPF_IF_PARAM(oi, v_hello),
12267 0 : OSPF_IF_PARAM(oi, retransmit_interval),
12268 0 : OSPF_IF_PARAM(oi, transmit_delay),
12269 0 : OSPF_IF_PARAM(oi, v_wait));
12270 : else
12271 0 : vty_out(vty, " area %s virtual-link %pI4\n", buf,
12272 : &vl_data->vl_peer);
12273 : /* Auth type */
12274 0 : auth_str = interface_config_auth_str(
12275 0 : IF_DEF_PARAMS(oi->ifp));
12276 0 : if (auth_str)
12277 0 : vty_out(vty,
12278 : " area %s virtual-link %pI4 authentication%s\n",
12279 : buf, &vl_data->vl_peer, auth_str);
12280 : /* Auth key */
12281 0 : if (IF_DEF_PARAMS(vl_data->vl_oi->ifp)->auth_simple[0]
12282 : != '\0')
12283 0 : vty_out(vty,
12284 : " area %s virtual-link %pI4 authentication-key %s\n",
12285 : buf, &vl_data->vl_peer,
12286 : IF_DEF_PARAMS(vl_data->vl_oi->ifp)
12287 0 : ->auth_simple);
12288 : /* md5 keys */
12289 0 : for (ALL_LIST_ELEMENTS_RO(
12290 : IF_DEF_PARAMS(vl_data->vl_oi->ifp)
12291 : ->auth_crypt,
12292 : n2, ck))
12293 0 : vty_out(vty,
12294 : " area %s virtual-link %pI4 message-digest-key %d md5 %s\n",
12295 : buf, &vl_data->vl_peer,
12296 0 : ck->key_id, ck->auth_key);
12297 : }
12298 : }
12299 :
12300 0 : return 0;
12301 : }
12302 :
12303 :
12304 0 : static int config_write_ospf_redistribute(struct vty *vty, struct ospf *ospf)
12305 : {
12306 0 : int type;
12307 :
12308 : /* redistribute print. */
12309 0 : for (type = 0; type < ZEBRA_ROUTE_MAX; type++) {
12310 0 : struct list *red_list;
12311 0 : struct listnode *node;
12312 0 : struct ospf_redist *red;
12313 :
12314 0 : red_list = ospf->redist[type];
12315 0 : if (!red_list)
12316 0 : continue;
12317 :
12318 0 : for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) {
12319 0 : vty_out(vty, " redistribute %s",
12320 : zebra_route_string(type));
12321 0 : if (red->instance)
12322 0 : vty_out(vty, " %d", red->instance);
12323 :
12324 0 : if (red->dmetric.value >= 0)
12325 0 : vty_out(vty, " metric %d", red->dmetric.value);
12326 :
12327 0 : if (red->dmetric.type == EXTERNAL_METRIC_TYPE_1)
12328 0 : vty_out(vty, " metric-type 1");
12329 :
12330 0 : if (ROUTEMAP_NAME(red))
12331 0 : vty_out(vty, " route-map %s",
12332 : ROUTEMAP_NAME(red));
12333 :
12334 0 : vty_out(vty, "\n");
12335 : }
12336 : }
12337 :
12338 0 : return 0;
12339 : }
12340 :
12341 0 : static int ospf_cfg_write_helper_dis_rtr_walkcb(struct hash_bucket *bucket,
12342 : void *arg)
12343 : {
12344 0 : struct advRtr *rtr = bucket->data;
12345 0 : struct vty *vty = (struct vty *)arg;
12346 :
12347 0 : vty_out(vty, " graceful-restart helper enable %pI4\n",
12348 : &rtr->advRtrAddr);
12349 0 : return HASHWALK_CONTINUE;
12350 : }
12351 :
12352 0 : static void config_write_ospf_gr(struct vty *vty, struct ospf *ospf)
12353 : {
12354 0 : if (!ospf->gr_info.restart_support)
12355 : return;
12356 :
12357 0 : if (ospf->gr_info.grace_period == OSPF_DFLT_GRACE_INTERVAL)
12358 0 : vty_out(vty, " graceful-restart\n");
12359 : else
12360 0 : vty_out(vty, " graceful-restart grace-period %u\n",
12361 : ospf->gr_info.grace_period);
12362 : }
12363 :
12364 0 : static int config_write_ospf_gr_helper(struct vty *vty, struct ospf *ospf)
12365 : {
12366 0 : if (ospf->is_helper_supported)
12367 0 : vty_out(vty, " graceful-restart helper enable\n");
12368 :
12369 0 : if (!ospf->strict_lsa_check)
12370 0 : vty_out(vty,
12371 : " no graceful-restart helper strict-lsa-checking\n");
12372 :
12373 0 : if (ospf->only_planned_restart)
12374 0 : vty_out(vty, " graceful-restart helper planned-only\n");
12375 :
12376 0 : if (ospf->supported_grace_time != OSPF_MAX_GRACE_INTERVAL)
12377 0 : vty_out(vty,
12378 : " graceful-restart helper supported-grace-time %d\n",
12379 : ospf->supported_grace_time);
12380 :
12381 0 : if (OSPF_HELPER_ENABLE_RTR_COUNT(ospf)) {
12382 0 : hash_walk(ospf->enable_rtr_list,
12383 : ospf_cfg_write_helper_dis_rtr_walkcb, vty);
12384 : }
12385 0 : return 0;
12386 : }
12387 :
12388 0 : static int config_write_ospf_external_aggregator(struct vty *vty,
12389 : struct ospf *ospf)
12390 : {
12391 0 : struct route_node *rn;
12392 :
12393 0 : if (ospf->aggr_delay_interval != OSPF_EXTL_AGGR_DEFAULT_DELAY)
12394 0 : vty_out(vty, " aggregation timer %u\n",
12395 : ospf->aggr_delay_interval);
12396 :
12397 : /* print 'summary-address A.B.C.D/M' */
12398 0 : for (rn = route_top(ospf->rt_aggr_tbl); rn; rn = route_next(rn))
12399 0 : if (rn->info) {
12400 0 : struct ospf_external_aggr_rt *aggr = rn->info;
12401 :
12402 0 : vty_out(vty, " summary-address %pI4/%d",
12403 0 : &aggr->p.prefix, aggr->p.prefixlen);
12404 0 : if (aggr->tag)
12405 0 : vty_out(vty, " tag %u", aggr->tag);
12406 :
12407 0 : if (CHECK_FLAG(aggr->flags,
12408 : OSPF_EXTERNAL_AGGRT_NO_ADVERTISE))
12409 0 : vty_out(vty, " no-advertise");
12410 :
12411 0 : vty_out(vty, "\n");
12412 : }
12413 :
12414 0 : return 0;
12415 : }
12416 :
12417 0 : static int config_write_ospf_default_metric(struct vty *vty, struct ospf *ospf)
12418 : {
12419 0 : if (ospf->default_metric != -1)
12420 0 : vty_out(vty, " default-metric %d\n", ospf->default_metric);
12421 0 : return 0;
12422 : }
12423 :
12424 0 : static int config_write_ospf_distribute(struct vty *vty, struct ospf *ospf)
12425 : {
12426 0 : int type;
12427 0 : struct ospf_redist *red;
12428 :
12429 0 : if (ospf) {
12430 : /* distribute-list print. */
12431 0 : for (type = 0; type < ZEBRA_ROUTE_MAX; type++)
12432 0 : if (DISTRIBUTE_NAME(ospf, type))
12433 0 : vty_out(vty, " distribute-list %s out %s\n",
12434 : DISTRIBUTE_NAME(ospf, type),
12435 : zebra_route_string(type));
12436 :
12437 : /* default-information print. */
12438 0 : if (ospf->default_originate != DEFAULT_ORIGINATE_NONE) {
12439 0 : vty_out(vty, " default-information originate");
12440 0 : if (ospf->default_originate == DEFAULT_ORIGINATE_ALWAYS)
12441 0 : vty_out(vty, " always");
12442 :
12443 0 : red = ospf_redist_lookup(ospf, DEFAULT_ROUTE, 0);
12444 0 : if (red) {
12445 0 : if (red->dmetric.value >= 0)
12446 0 : vty_out(vty, " metric %d",
12447 : red->dmetric.value);
12448 :
12449 0 : if (red->dmetric.type == EXTERNAL_METRIC_TYPE_1)
12450 0 : vty_out(vty, " metric-type 1");
12451 :
12452 0 : if (ROUTEMAP_NAME(red))
12453 0 : vty_out(vty, " route-map %s",
12454 : ROUTEMAP_NAME(red));
12455 : }
12456 :
12457 0 : vty_out(vty, "\n");
12458 : }
12459 : }
12460 :
12461 0 : return 0;
12462 : }
12463 :
12464 0 : static int config_write_ospf_distance(struct vty *vty, struct ospf *ospf)
12465 : {
12466 0 : struct route_node *rn;
12467 0 : struct ospf_distance *odistance;
12468 :
12469 0 : if (ospf->distance_all)
12470 0 : vty_out(vty, " distance %d\n", ospf->distance_all);
12471 :
12472 0 : if (ospf->distance_intra || ospf->distance_inter
12473 0 : || ospf->distance_external) {
12474 0 : vty_out(vty, " distance ospf");
12475 :
12476 0 : if (ospf->distance_intra)
12477 0 : vty_out(vty, " intra-area %d", ospf->distance_intra);
12478 0 : if (ospf->distance_inter)
12479 0 : vty_out(vty, " inter-area %d", ospf->distance_inter);
12480 0 : if (ospf->distance_external)
12481 0 : vty_out(vty, " external %d", ospf->distance_external);
12482 :
12483 0 : vty_out(vty, "\n");
12484 : }
12485 :
12486 0 : for (rn = route_top(ospf->distance_table); rn; rn = route_next(rn))
12487 0 : if ((odistance = rn->info) != NULL) {
12488 0 : vty_out(vty, " distance %d %pFX %s\n",
12489 0 : odistance->distance, &rn->p,
12490 0 : odistance->access_list ? odistance->access_list
12491 : : "");
12492 : }
12493 0 : return 0;
12494 : }
12495 :
12496 0 : static int ospf_config_write_one(struct vty *vty, struct ospf *ospf)
12497 : {
12498 0 : int write = 0;
12499 :
12500 : /* `router ospf' print. */
12501 0 : if (ospf->instance && strcmp(ospf->name, VRF_DEFAULT_NAME)) {
12502 0 : vty_out(vty, "router ospf %d vrf %s\n", ospf->instance,
12503 : ospf->name);
12504 0 : } else if (ospf->instance) {
12505 0 : vty_out(vty, "router ospf %d\n", ospf->instance);
12506 0 : } else if (strcmp(ospf->name, VRF_DEFAULT_NAME)) {
12507 0 : vty_out(vty, "router ospf vrf %s\n", ospf->name);
12508 : } else
12509 0 : vty_out(vty, "router ospf\n");
12510 :
12511 0 : if (!ospf->networks) {
12512 0 : write++;
12513 : return write;
12514 : }
12515 :
12516 : /* Router ID print. */
12517 0 : if (ospf->router_id_static.s_addr != INADDR_ANY)
12518 0 : vty_out(vty, " ospf router-id %pI4\n",
12519 : &ospf->router_id_static);
12520 :
12521 : /* zebra opaque attributes configuration. */
12522 0 : if (CHECK_FLAG(ospf->config, OSPF_SEND_EXTRA_DATA_TO_ZEBRA))
12523 0 : vty_out(vty, " ospf send-extra-data zebra\n");
12524 :
12525 : /* ABR type print. */
12526 0 : if (ospf->abr_type != OSPF_ABR_DEFAULT)
12527 0 : vty_out(vty, " ospf abr-type %s\n",
12528 0 : ospf_abr_type_str[ospf->abr_type]);
12529 :
12530 : /* log-adjacency-changes flag print. */
12531 0 : if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES)) {
12532 0 : if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL))
12533 0 : vty_out(vty, " log-adjacency-changes detail\n");
12534 0 : else if (!SAVE_OSPF_LOG_ADJACENCY_CHANGES)
12535 0 : vty_out(vty, " log-adjacency-changes\n");
12536 0 : } else if (SAVE_OSPF_LOG_ADJACENCY_CHANGES) {
12537 0 : vty_out(vty, " no log-adjacency-changes\n");
12538 : }
12539 :
12540 : /* RFC1583 compatibility flag print -- Compatible with CISCO
12541 : * 12.1. */
12542 0 : if (CHECK_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE))
12543 0 : vty_out(vty, " compatible rfc1583\n");
12544 :
12545 : /* auto-cost reference-bandwidth configuration. */
12546 0 : if (ospf->ref_bandwidth != OSPF_DEFAULT_REF_BANDWIDTH) {
12547 0 : vty_out(vty,
12548 : "! Important: ensure reference bandwidth is consistent across all routers\n");
12549 0 : vty_out(vty, " auto-cost reference-bandwidth %d\n",
12550 : ospf->ref_bandwidth);
12551 : }
12552 :
12553 : /* SPF timers print. */
12554 0 : if (ospf->spf_delay != OSPF_SPF_DELAY_DEFAULT
12555 : || ospf->spf_holdtime != OSPF_SPF_HOLDTIME_DEFAULT
12556 0 : || ospf->spf_max_holdtime != OSPF_SPF_MAX_HOLDTIME_DEFAULT)
12557 0 : vty_out(vty, " timers throttle spf %d %d %d\n", ospf->spf_delay,
12558 : ospf->spf_holdtime, ospf->spf_max_holdtime);
12559 :
12560 : /* LSA timers print. */
12561 0 : if (ospf->min_ls_interval != OSPF_MIN_LS_INTERVAL)
12562 0 : vty_out(vty, " timers throttle lsa all %d\n",
12563 : ospf->min_ls_interval);
12564 0 : if (ospf->min_ls_arrival != OSPF_MIN_LS_ARRIVAL)
12565 0 : vty_out(vty, " timers lsa min-arrival %d\n",
12566 : ospf->min_ls_arrival);
12567 :
12568 : /* Write multiplier print. */
12569 0 : if (ospf->write_oi_count != OSPF_WRITE_INTERFACE_COUNT_DEFAULT)
12570 0 : vty_out(vty, " ospf write-multiplier %d\n",
12571 : ospf->write_oi_count);
12572 :
12573 0 : if (ospf->max_multipath != MULTIPATH_NUM)
12574 0 : vty_out(vty, " maximum-paths %d\n", ospf->max_multipath);
12575 :
12576 : /* Max-metric router-lsa print */
12577 0 : config_write_stub_router(vty, ospf);
12578 :
12579 : /* SPF refresh parameters print. */
12580 0 : if (ospf->lsa_refresh_interval != OSPF_LSA_REFRESH_INTERVAL_DEFAULT)
12581 0 : vty_out(vty, " refresh timer %d\n", ospf->lsa_refresh_interval);
12582 :
12583 : /* Redistribute information print. */
12584 0 : config_write_ospf_redistribute(vty, ospf);
12585 :
12586 : /* Graceful Restart print */
12587 0 : config_write_ospf_gr(vty, ospf);
12588 0 : config_write_ospf_gr_helper(vty, ospf);
12589 :
12590 : /* Print external route aggregation. */
12591 0 : config_write_ospf_external_aggregator(vty, ospf);
12592 :
12593 : /* passive-interface print. */
12594 0 : if (ospf->passive_interface_default == OSPF_IF_PASSIVE)
12595 0 : vty_out(vty, " passive-interface default\n");
12596 :
12597 : /* proactive-arp print. */
12598 0 : if (ospf->proactive_arp != OSPF_PROACTIVE_ARP_DEFAULT) {
12599 0 : if (ospf->proactive_arp)
12600 : vty_out(vty, " proactive-arp\n");
12601 : else
12602 0 : vty_out(vty, " no proactive-arp\n");
12603 : }
12604 :
12605 : /* TI-LFA print. */
12606 0 : if (ospf->ti_lfa_enabled) {
12607 0 : if (ospf->ti_lfa_protection_type == OSPF_TI_LFA_NODE_PROTECTION)
12608 0 : vty_out(vty, " fast-reroute ti-lfa node-protection\n");
12609 : else
12610 0 : vty_out(vty, " fast-reroute ti-lfa\n");
12611 : }
12612 :
12613 : /* Network area print. */
12614 0 : config_write_network_area(vty, ospf);
12615 :
12616 : /* Area config print. */
12617 0 : config_write_ospf_area(vty, ospf);
12618 :
12619 : /* static neighbor print. */
12620 0 : config_write_ospf_nbr_nbma(vty, ospf);
12621 :
12622 : /* Virtual-Link print. */
12623 0 : config_write_virtual_link(vty, ospf);
12624 :
12625 : /* Default metric configuration. */
12626 0 : config_write_ospf_default_metric(vty, ospf);
12627 :
12628 : /* Distribute-list and default-information print. */
12629 0 : config_write_ospf_distribute(vty, ospf);
12630 :
12631 : /* Distance configuration. */
12632 0 : config_write_ospf_distance(vty, ospf);
12633 :
12634 0 : ospf_opaque_config_write_router(vty, ospf);
12635 :
12636 : /* LDP-Sync print */
12637 0 : ospf_ldp_sync_write_config(vty, ospf);
12638 :
12639 0 : vty_out(vty, "exit\n");
12640 :
12641 0 : write++;
12642 0 : return write;
12643 : }
12644 :
12645 : /* OSPF configuration write function. */
12646 0 : static int ospf_config_write(struct vty *vty)
12647 : {
12648 0 : struct ospf *ospf;
12649 0 : struct listnode *ospf_node = NULL;
12650 0 : int write = 0;
12651 :
12652 0 : if (listcount(om->ospf) == 0)
12653 : return write;
12654 :
12655 0 : for (ALL_LIST_ELEMENTS_RO(om->ospf, ospf_node, ospf)) {
12656 : /* VRF Default check if it is running.
12657 : * Upon daemon start, there could be default instance
12658 : * in absence of 'router ospf'/oi_running is disabled. */
12659 0 : if (ospf->vrf_id == VRF_DEFAULT && ospf->oi_running)
12660 0 : write += ospf_config_write_one(vty, ospf);
12661 : /* For Non-Default VRF simply display the configuration,
12662 : * even if it is not oi_running. */
12663 0 : else if (ospf->vrf_id != VRF_DEFAULT)
12664 0 : write += ospf_config_write_one(vty, ospf);
12665 : }
12666 : return write;
12667 : }
12668 :
12669 4 : void ospf_vty_show_init(void)
12670 : {
12671 : /* "show ip ospf" commands. */
12672 4 : install_element(VIEW_NODE, &show_ip_ospf_cmd);
12673 :
12674 4 : install_element(VIEW_NODE, &show_ip_ospf_instance_cmd);
12675 :
12676 : /* "show ip ospf database" commands. */
12677 4 : install_element(VIEW_NODE, &show_ip_ospf_database_cmd);
12678 4 : install_element(VIEW_NODE, &show_ip_ospf_database_max_cmd);
12679 4 : install_element(VIEW_NODE,
12680 : &show_ip_ospf_database_type_adv_router_cmd);
12681 4 : install_element(VIEW_NODE,
12682 : &show_ip_ospf_instance_database_type_adv_router_cmd);
12683 4 : install_element(VIEW_NODE, &show_ip_ospf_instance_database_cmd);
12684 4 : install_element(VIEW_NODE, &show_ip_ospf_instance_database_max_cmd);
12685 :
12686 : /* "show ip ospf interface" commands. */
12687 4 : install_element(VIEW_NODE, &show_ip_ospf_interface_cmd);
12688 :
12689 4 : install_element(VIEW_NODE, &show_ip_ospf_instance_interface_cmd);
12690 : /* "show ip ospf interface traffic */
12691 4 : install_element(VIEW_NODE, &show_ip_ospf_interface_traffic_cmd);
12692 :
12693 : /* "show ip ospf neighbor" commands. */
12694 4 : install_element(VIEW_NODE, &show_ip_ospf_neighbor_int_detail_cmd);
12695 4 : install_element(VIEW_NODE, &show_ip_ospf_neighbor_int_cmd);
12696 4 : install_element(VIEW_NODE, &show_ip_ospf_neighbor_id_cmd);
12697 4 : install_element(VIEW_NODE, &show_ip_ospf_neighbor_detail_all_cmd);
12698 4 : install_element(VIEW_NODE, &show_ip_ospf_neighbor_detail_cmd);
12699 4 : install_element(VIEW_NODE, &show_ip_ospf_neighbor_cmd);
12700 4 : install_element(VIEW_NODE, &show_ip_ospf_neighbor_all_cmd);
12701 :
12702 4 : install_element(VIEW_NODE,
12703 : &show_ip_ospf_instance_neighbor_int_detail_cmd);
12704 4 : install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_int_cmd);
12705 4 : install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_id_cmd);
12706 4 : install_element(VIEW_NODE,
12707 : &show_ip_ospf_instance_neighbor_detail_all_cmd);
12708 4 : install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_detail_cmd);
12709 4 : install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_cmd);
12710 4 : install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_all_cmd);
12711 :
12712 : /* "show ip ospf route" commands. */
12713 4 : install_element(VIEW_NODE, &show_ip_ospf_route_cmd);
12714 4 : install_element(VIEW_NODE, &show_ip_ospf_border_routers_cmd);
12715 4 : install_element(VIEW_NODE, &show_ip_ospf_reachable_routers_cmd);
12716 :
12717 4 : install_element(VIEW_NODE, &show_ip_ospf_instance_route_cmd);
12718 4 : install_element(VIEW_NODE, &show_ip_ospf_instance_border_routers_cmd);
12719 4 : install_element(VIEW_NODE,
12720 : &show_ip_ospf_instance_reachable_routers_cmd);
12721 :
12722 : /* "show ip ospf vrfs" commands. */
12723 4 : install_element(VIEW_NODE, &show_ip_ospf_vrfs_cmd);
12724 :
12725 : /* "show ip ospf gr-helper details" command */
12726 4 : install_element(VIEW_NODE, &show_ip_ospf_gr_helper_cmd);
12727 :
12728 : /* "show ip ospf summary-address" command */
12729 4 : install_element(VIEW_NODE, &show_ip_ospf_external_aggregator_cmd);
12730 4 : }
12731 :
12732 : /* Initialization of OSPF interface. */
12733 4 : static void ospf_vty_if_init(void)
12734 : {
12735 : /* Install interface node. */
12736 4 : if_cmd_init(config_write_interface);
12737 :
12738 : /* "ip ospf authentication" commands. */
12739 4 : install_element(INTERFACE_NODE, &ip_ospf_authentication_args_addr_cmd);
12740 4 : install_element(INTERFACE_NODE, &ip_ospf_authentication_addr_cmd);
12741 4 : install_element(INTERFACE_NODE,
12742 : &no_ip_ospf_authentication_args_addr_cmd);
12743 4 : install_element(INTERFACE_NODE, &no_ip_ospf_authentication_addr_cmd);
12744 4 : install_element(INTERFACE_NODE, &ip_ospf_authentication_key_addr_cmd);
12745 4 : install_element(INTERFACE_NODE,
12746 : &no_ip_ospf_authentication_key_authkey_addr_cmd);
12747 4 : install_element(INTERFACE_NODE,
12748 : &no_ospf_authentication_key_authkey_addr_cmd);
12749 :
12750 : /* "ip ospf message-digest-key" commands. */
12751 4 : install_element(INTERFACE_NODE, &ip_ospf_message_digest_key_cmd);
12752 4 : install_element(INTERFACE_NODE, &no_ip_ospf_message_digest_key_cmd);
12753 :
12754 : /* "ip ospf cost" commands. */
12755 4 : install_element(INTERFACE_NODE, &ip_ospf_cost_cmd);
12756 4 : install_element(INTERFACE_NODE, &no_ip_ospf_cost_cmd);
12757 :
12758 : /* "ip ospf mtu-ignore" commands. */
12759 4 : install_element(INTERFACE_NODE, &ip_ospf_mtu_ignore_addr_cmd);
12760 4 : install_element(INTERFACE_NODE, &no_ip_ospf_mtu_ignore_addr_cmd);
12761 :
12762 : /* "ip ospf dead-interval" commands. */
12763 4 : install_element(INTERFACE_NODE, &ip_ospf_dead_interval_cmd);
12764 4 : install_element(INTERFACE_NODE,
12765 : &ip_ospf_dead_interval_minimal_addr_cmd);
12766 4 : install_element(INTERFACE_NODE, &no_ip_ospf_dead_interval_cmd);
12767 :
12768 : /* "ip ospf hello-interval" commands. */
12769 4 : install_element(INTERFACE_NODE, &ip_ospf_hello_interval_cmd);
12770 4 : install_element(INTERFACE_NODE, &no_ip_ospf_hello_interval_cmd);
12771 :
12772 : /* "ip ospf network" commands. */
12773 4 : install_element(INTERFACE_NODE, &ip_ospf_network_cmd);
12774 4 : install_element(INTERFACE_NODE, &no_ip_ospf_network_cmd);
12775 :
12776 : /* "ip ospf priority" commands. */
12777 4 : install_element(INTERFACE_NODE, &ip_ospf_priority_cmd);
12778 4 : install_element(INTERFACE_NODE, &no_ip_ospf_priority_cmd);
12779 :
12780 : /* "ip ospf retransmit-interval" commands. */
12781 4 : install_element(INTERFACE_NODE, &ip_ospf_retransmit_interval_addr_cmd);
12782 4 : install_element(INTERFACE_NODE,
12783 : &no_ip_ospf_retransmit_interval_addr_cmd);
12784 :
12785 : /* "ip ospf transmit-delay" commands. */
12786 4 : install_element(INTERFACE_NODE, &ip_ospf_transmit_delay_addr_cmd);
12787 4 : install_element(INTERFACE_NODE, &no_ip_ospf_transmit_delay_addr_cmd);
12788 :
12789 : /* "ip ospf area" commands. */
12790 4 : install_element(INTERFACE_NODE, &ip_ospf_area_cmd);
12791 4 : install_element(INTERFACE_NODE, &no_ip_ospf_area_cmd);
12792 :
12793 : /* "ip ospf passive" commands. */
12794 4 : install_element(INTERFACE_NODE, &ip_ospf_passive_cmd);
12795 4 : install_element(INTERFACE_NODE, &no_ip_ospf_passive_cmd);
12796 :
12797 : /* These commands are compatibitliy for previous version. */
12798 4 : install_element(INTERFACE_NODE, &ospf_authentication_key_cmd);
12799 4 : install_element(INTERFACE_NODE, &ospf_message_digest_key_cmd);
12800 4 : install_element(INTERFACE_NODE, &no_ospf_message_digest_key_cmd);
12801 4 : install_element(INTERFACE_NODE, &ospf_dead_interval_cmd);
12802 4 : install_element(INTERFACE_NODE, &no_ospf_dead_interval_cmd);
12803 4 : install_element(INTERFACE_NODE, &ospf_hello_interval_cmd);
12804 4 : install_element(INTERFACE_NODE, &no_ospf_hello_interval_cmd);
12805 4 : install_element(INTERFACE_NODE, &ospf_cost_cmd);
12806 4 : install_element(INTERFACE_NODE, &no_ospf_cost_cmd);
12807 4 : install_element(INTERFACE_NODE, &ospf_network_cmd);
12808 4 : install_element(INTERFACE_NODE, &no_ospf_network_cmd);
12809 4 : install_element(INTERFACE_NODE, &ospf_priority_cmd);
12810 4 : install_element(INTERFACE_NODE, &no_ospf_priority_cmd);
12811 4 : install_element(INTERFACE_NODE, &ospf_retransmit_interval_cmd);
12812 4 : install_element(INTERFACE_NODE, &no_ospf_retransmit_interval_cmd);
12813 4 : install_element(INTERFACE_NODE, &ospf_transmit_delay_cmd);
12814 4 : install_element(INTERFACE_NODE, &no_ospf_transmit_delay_cmd);
12815 4 : }
12816 :
12817 4 : static void ospf_vty_zebra_init(void)
12818 : {
12819 4 : install_element(OSPF_NODE, &ospf_redistribute_source_cmd);
12820 4 : install_element(OSPF_NODE, &no_ospf_redistribute_source_cmd);
12821 4 : install_element(OSPF_NODE, &ospf_redistribute_instance_source_cmd);
12822 4 : install_element(OSPF_NODE, &no_ospf_redistribute_instance_source_cmd);
12823 :
12824 4 : install_element(OSPF_NODE, &ospf_distribute_list_out_cmd);
12825 4 : install_element(OSPF_NODE, &no_ospf_distribute_list_out_cmd);
12826 :
12827 4 : install_element(OSPF_NODE, &ospf_default_information_originate_cmd);
12828 4 : install_element(OSPF_NODE, &no_ospf_default_information_originate_cmd);
12829 :
12830 4 : install_element(OSPF_NODE, &ospf_default_metric_cmd);
12831 4 : install_element(OSPF_NODE, &no_ospf_default_metric_cmd);
12832 :
12833 4 : install_element(OSPF_NODE, &ospf_distance_cmd);
12834 4 : install_element(OSPF_NODE, &no_ospf_distance_cmd);
12835 4 : install_element(OSPF_NODE, &no_ospf_distance_ospf_cmd);
12836 4 : install_element(OSPF_NODE, &ospf_distance_ospf_cmd);
12837 :
12838 : /*Ospf garcefull restart helper configurations */
12839 4 : install_element(OSPF_NODE, &ospf_gr_helper_enable_cmd);
12840 4 : install_element(OSPF_NODE, &no_ospf_gr_helper_enable_cmd);
12841 4 : install_element(OSPF_NODE, &ospf_gr_helper_enable_lsacheck_cmd);
12842 4 : install_element(OSPF_NODE, &no_ospf_gr_helper_enable_lsacheck_cmd);
12843 4 : install_element(OSPF_NODE, &ospf_gr_helper_supported_grace_time_cmd);
12844 4 : install_element(OSPF_NODE, &no_ospf_gr_helper_supported_grace_time_cmd);
12845 4 : install_element(OSPF_NODE, &ospf_gr_helper_planned_only_cmd);
12846 4 : install_element(OSPF_NODE, &no_ospf_gr_helper_planned_only_cmd);
12847 :
12848 : /* External LSA summarisation config commands.*/
12849 4 : install_element(OSPF_NODE, &ospf_external_route_aggregation_cmd);
12850 4 : install_element(OSPF_NODE, &no_ospf_external_route_aggregation_cmd);
12851 4 : install_element(OSPF_NODE,
12852 : &ospf_external_route_aggregation_no_adrvertise_cmd);
12853 4 : install_element(OSPF_NODE,
12854 : &no_ospf_external_route_aggregation_no_adrvertise_cmd);
12855 4 : install_element(OSPF_NODE, &ospf_route_aggregation_timer_cmd);
12856 4 : install_element(OSPF_NODE, &no_ospf_route_aggregation_timer_cmd);
12857 4 : }
12858 :
12859 : static int ospf_config_write(struct vty *vty);
12860 : static struct cmd_node ospf_node = {
12861 : .name = "ospf",
12862 : .node = OSPF_NODE,
12863 : .parent_node = CONFIG_NODE,
12864 : .prompt = "%s(config-router)# ",
12865 : .config_write = ospf_config_write,
12866 : };
12867 :
12868 0 : static void ospf_interface_clear(struct interface *ifp)
12869 : {
12870 0 : if (!if_is_operative(ifp))
12871 : return;
12872 :
12873 0 : if (IS_DEBUG_OSPF(ism, ISM_EVENTS))
12874 0 : zlog_debug("ISM[%s]: clear by reset", ifp->name);
12875 :
12876 0 : ospf_if_reset(ifp);
12877 : }
12878 :
12879 0 : DEFUN (clear_ip_ospf_interface,
12880 : clear_ip_ospf_interface_cmd,
12881 : "clear ip ospf [vrf NAME] interface [IFNAME]",
12882 : CLEAR_STR
12883 : IP_STR
12884 : "OSPF information\n"
12885 : VRF_CMD_HELP_STR
12886 : "Interface information\n"
12887 : "Interface name\n")
12888 : {
12889 0 : int idx_ifname = 0;
12890 0 : int idx_vrf = 0;
12891 0 : struct interface *ifp;
12892 0 : struct listnode *node;
12893 0 : struct ospf *ospf = NULL;
12894 0 : char *vrf_name = NULL;
12895 0 : vrf_id_t vrf_id = VRF_DEFAULT;
12896 0 : struct vrf *vrf = NULL;
12897 :
12898 0 : if (argv_find(argv, argc, "vrf", &idx_vrf))
12899 0 : vrf_name = argv[idx_vrf + 1]->arg;
12900 0 : if (vrf_name && strmatch(vrf_name, VRF_DEFAULT_NAME))
12901 : vrf_name = NULL;
12902 0 : if (vrf_name) {
12903 0 : vrf = vrf_lookup_by_name(vrf_name);
12904 0 : if (vrf)
12905 0 : vrf_id = vrf->vrf_id;
12906 : }
12907 0 : if (!argv_find(argv, argc, "IFNAME", &idx_ifname)) {
12908 : /* Clear all the ospfv2 interfaces. */
12909 0 : for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) {
12910 0 : if (vrf_id != ospf->vrf_id)
12911 0 : continue;
12912 0 : if (!vrf)
12913 0 : vrf = vrf_lookup_by_id(ospf->vrf_id);
12914 0 : FOR_ALL_INTERFACES (vrf, ifp)
12915 0 : ospf_interface_clear(ifp);
12916 : }
12917 : } else {
12918 : /* Interface name is specified. */
12919 0 : ifp = if_lookup_by_name(argv[idx_ifname]->arg, vrf_id);
12920 0 : if (ifp == NULL)
12921 0 : vty_out(vty, "No such interface name\n");
12922 : else
12923 0 : ospf_interface_clear(ifp);
12924 : }
12925 :
12926 0 : return CMD_SUCCESS;
12927 : }
12928 :
12929 0 : DEFPY_HIDDEN(ospf_lsa_refresh_timer, ospf_lsa_refresh_timer_cmd,
12930 : "[no$no] ospf lsa-refresh [(120-1800)]$value",
12931 : NO_STR OSPF_STR
12932 : "OSPF lsa refresh timer\n"
12933 : "timer value in seconds\n")
12934 : {
12935 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf)
12936 :
12937 0 : if (no)
12938 0 : ospf->lsa_refresh_timer = OSPF_LS_REFRESH_TIME;
12939 : else
12940 0 : ospf->lsa_refresh_timer = value;
12941 :
12942 : return CMD_SUCCESS;
12943 : }
12944 :
12945 0 : DEFPY_HIDDEN(ospf_maxage_delay_timer, ospf_maxage_delay_timer_cmd,
12946 : "[no$no] ospf maxage-delay [(0-60)]$value",
12947 : NO_STR OSPF_STR
12948 : "OSPF lsa maxage delay timer\n"
12949 : "timer value in seconds\n")
12950 : {
12951 0 : VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf)
12952 :
12953 0 : if (no)
12954 0 : ospf->maxage_delay = OSPF_LSA_MAXAGE_REMOVE_DELAY_DEFAULT;
12955 : else
12956 0 : ospf->maxage_delay = value;
12957 :
12958 0 : THREAD_OFF(ospf->t_maxage);
12959 0 : OSPF_TIMER_ON(ospf->t_maxage, ospf_maxage_lsa_remover,
12960 : ospf->maxage_delay);
12961 :
12962 0 : return CMD_SUCCESS;
12963 : }
12964 :
12965 4 : void ospf_vty_clear_init(void)
12966 : {
12967 4 : install_element(ENABLE_NODE, &clear_ip_ospf_interface_cmd);
12968 4 : install_element(ENABLE_NODE, &clear_ip_ospf_process_cmd);
12969 4 : install_element(ENABLE_NODE, &clear_ip_ospf_neighbor_cmd);
12970 4 : }
12971 :
12972 :
12973 : /* Install OSPF related vty commands. */
12974 4 : void ospf_vty_init(void)
12975 : {
12976 : /* Install ospf top node. */
12977 4 : install_node(&ospf_node);
12978 :
12979 : /* "router ospf" commands. */
12980 4 : install_element(CONFIG_NODE, &router_ospf_cmd);
12981 4 : install_element(CONFIG_NODE, &no_router_ospf_cmd);
12982 :
12983 :
12984 4 : install_default(OSPF_NODE);
12985 :
12986 : /* "ospf router-id" commands. */
12987 4 : install_element(OSPF_NODE, &ospf_router_id_cmd);
12988 4 : install_element(OSPF_NODE, &ospf_router_id_old_cmd);
12989 4 : install_element(OSPF_NODE, &no_ospf_router_id_cmd);
12990 :
12991 : /* "passive-interface" commands. */
12992 4 : install_element(OSPF_NODE, &ospf_passive_interface_default_cmd);
12993 4 : install_element(OSPF_NODE, &ospf_passive_interface_addr_cmd);
12994 4 : install_element(OSPF_NODE, &no_ospf_passive_interface_default_cmd);
12995 4 : install_element(OSPF_NODE, &no_ospf_passive_interface_addr_cmd);
12996 :
12997 : /* "ospf abr-type" commands. */
12998 4 : install_element(OSPF_NODE, &ospf_abr_type_cmd);
12999 4 : install_element(OSPF_NODE, &no_ospf_abr_type_cmd);
13000 :
13001 : /* "ospf log-adjacency-changes" commands. */
13002 4 : install_element(OSPF_NODE, &ospf_log_adjacency_changes_cmd);
13003 4 : install_element(OSPF_NODE, &ospf_log_adjacency_changes_detail_cmd);
13004 4 : install_element(OSPF_NODE, &no_ospf_log_adjacency_changes_cmd);
13005 4 : install_element(OSPF_NODE, &no_ospf_log_adjacency_changes_detail_cmd);
13006 :
13007 : /* "ospf rfc1583-compatible" commands. */
13008 4 : install_element(OSPF_NODE, &ospf_compatible_rfc1583_cmd);
13009 4 : install_element(OSPF_NODE, &no_ospf_compatible_rfc1583_cmd);
13010 4 : install_element(OSPF_NODE, &ospf_rfc1583_flag_cmd);
13011 4 : install_element(OSPF_NODE, &no_ospf_rfc1583_flag_cmd);
13012 :
13013 : /* "ospf send-extra-data zebra" commands. */
13014 4 : install_element(OSPF_NODE, &ospf_send_extra_data_cmd);
13015 :
13016 : /* "network area" commands. */
13017 4 : install_element(OSPF_NODE, &ospf_network_area_cmd);
13018 4 : install_element(OSPF_NODE, &no_ospf_network_area_cmd);
13019 :
13020 : /* "area authentication" commands. */
13021 4 : install_element(OSPF_NODE,
13022 : &ospf_area_authentication_message_digest_cmd);
13023 4 : install_element(OSPF_NODE, &ospf_area_authentication_cmd);
13024 4 : install_element(OSPF_NODE, &no_ospf_area_authentication_cmd);
13025 :
13026 : /* "area range" commands. */
13027 4 : install_element(OSPF_NODE, &ospf_area_range_cmd);
13028 4 : install_element(OSPF_NODE, &ospf_area_range_cost_cmd);
13029 4 : install_element(OSPF_NODE, &ospf_area_range_not_advertise_cmd);
13030 4 : install_element(OSPF_NODE, &no_ospf_area_range_cmd);
13031 4 : install_element(OSPF_NODE, &no_ospf_area_range_substitute_cmd);
13032 :
13033 : /* "area virtual-link" commands. */
13034 4 : install_element(OSPF_NODE, &ospf_area_vlink_cmd);
13035 4 : install_element(OSPF_NODE, &ospf_area_vlink_intervals_cmd);
13036 4 : install_element(OSPF_NODE, &no_ospf_area_vlink_cmd);
13037 4 : install_element(OSPF_NODE, &no_ospf_area_vlink_intervals_cmd);
13038 :
13039 :
13040 : /* "area stub" commands. */
13041 4 : install_element(OSPF_NODE, &ospf_area_stub_no_summary_cmd);
13042 4 : install_element(OSPF_NODE, &ospf_area_stub_cmd);
13043 4 : install_element(OSPF_NODE, &no_ospf_area_stub_no_summary_cmd);
13044 4 : install_element(OSPF_NODE, &no_ospf_area_stub_cmd);
13045 :
13046 : /* "area nssa" commands. */
13047 4 : install_element(OSPF_NODE, &ospf_area_nssa_cmd);
13048 4 : install_element(OSPF_NODE, &ospf_area_nssa_translate_cmd);
13049 4 : install_element(OSPF_NODE, &ospf_area_nssa_no_summary_cmd);
13050 4 : install_element(OSPF_NODE, &no_ospf_area_nssa_no_summary_cmd);
13051 4 : install_element(OSPF_NODE, &ospf_area_nssa_suppress_fa_cmd);
13052 4 : install_element(OSPF_NODE, &no_ospf_area_nssa_suppress_fa_cmd);
13053 4 : install_element(OSPF_NODE, &no_ospf_area_nssa_cmd);
13054 :
13055 4 : install_element(OSPF_NODE, &ospf_area_default_cost_cmd);
13056 4 : install_element(OSPF_NODE, &no_ospf_area_default_cost_cmd);
13057 :
13058 4 : install_element(OSPF_NODE, &ospf_area_shortcut_cmd);
13059 4 : install_element(OSPF_NODE, &no_ospf_area_shortcut_cmd);
13060 :
13061 4 : install_element(OSPF_NODE, &ospf_area_export_list_cmd);
13062 4 : install_element(OSPF_NODE, &no_ospf_area_export_list_cmd);
13063 :
13064 4 : install_element(OSPF_NODE, &ospf_area_filter_list_cmd);
13065 4 : install_element(OSPF_NODE, &no_ospf_area_filter_list_cmd);
13066 :
13067 4 : install_element(OSPF_NODE, &ospf_area_import_list_cmd);
13068 4 : install_element(OSPF_NODE, &no_ospf_area_import_list_cmd);
13069 :
13070 : /* SPF timer commands */
13071 4 : install_element(OSPF_NODE, &ospf_timers_throttle_spf_cmd);
13072 4 : install_element(OSPF_NODE, &no_ospf_timers_throttle_spf_cmd);
13073 :
13074 : /* LSA timers commands */
13075 4 : install_element(OSPF_NODE, &ospf_timers_min_ls_interval_cmd);
13076 4 : install_element(OSPF_NODE, &no_ospf_timers_min_ls_interval_cmd);
13077 4 : install_element(OSPF_NODE, &ospf_timers_lsa_min_arrival_cmd);
13078 4 : install_element(OSPF_NODE, &no_ospf_timers_lsa_min_arrival_cmd);
13079 :
13080 : /* refresh timer commands */
13081 4 : install_element(OSPF_NODE, &ospf_refresh_timer_cmd);
13082 4 : install_element(OSPF_NODE, &no_ospf_refresh_timer_val_cmd);
13083 :
13084 : /* max-metric commands */
13085 4 : install_element(OSPF_NODE, &ospf_max_metric_router_lsa_admin_cmd);
13086 4 : install_element(OSPF_NODE, &no_ospf_max_metric_router_lsa_admin_cmd);
13087 4 : install_element(OSPF_NODE, &ospf_max_metric_router_lsa_startup_cmd);
13088 4 : install_element(OSPF_NODE, &no_ospf_max_metric_router_lsa_startup_cmd);
13089 4 : install_element(OSPF_NODE, &ospf_max_metric_router_lsa_shutdown_cmd);
13090 4 : install_element(OSPF_NODE, &no_ospf_max_metric_router_lsa_shutdown_cmd);
13091 :
13092 : /* reference bandwidth commands */
13093 4 : install_element(OSPF_NODE, &ospf_auto_cost_reference_bandwidth_cmd);
13094 4 : install_element(OSPF_NODE, &no_ospf_auto_cost_reference_bandwidth_cmd);
13095 :
13096 : /* "neighbor" commands. */
13097 4 : install_element(OSPF_NODE, &ospf_neighbor_cmd);
13098 4 : install_element(OSPF_NODE, &ospf_neighbor_poll_interval_cmd);
13099 4 : install_element(OSPF_NODE, &no_ospf_neighbor_cmd);
13100 4 : install_element(OSPF_NODE, &no_ospf_neighbor_poll_cmd);
13101 :
13102 : /* write multiplier commands */
13103 4 : install_element(OSPF_NODE, &ospf_write_multiplier_cmd);
13104 4 : install_element(OSPF_NODE, &write_multiplier_cmd);
13105 4 : install_element(OSPF_NODE, &no_ospf_write_multiplier_cmd);
13106 4 : install_element(OSPF_NODE, &no_write_multiplier_cmd);
13107 :
13108 : /* "proactive-arp" commands. */
13109 4 : install_element(OSPF_NODE, &ospf_proactive_arp_cmd);
13110 4 : install_element(OSPF_NODE, &no_ospf_proactive_arp_cmd);
13111 :
13112 : /* TI-LFA commands */
13113 4 : install_element(OSPF_NODE, &ospf_ti_lfa_cmd);
13114 4 : install_element(OSPF_NODE, &no_ospf_ti_lfa_cmd);
13115 :
13116 : /* Max path configurations */
13117 4 : install_element(OSPF_NODE, &ospf_max_multipath_cmd);
13118 4 : install_element(OSPF_NODE, &no_ospf_max_multipath_cmd);
13119 :
13120 4 : vrf_cmd_init(NULL);
13121 :
13122 4 : install_element(OSPF_NODE, &ospf_lsa_refresh_timer_cmd);
13123 4 : install_element(OSPF_NODE, &ospf_maxage_delay_timer_cmd);
13124 :
13125 : /* Init interface related vty commands. */
13126 4 : ospf_vty_if_init();
13127 :
13128 : /* Init zebra related vty commands. */
13129 4 : ospf_vty_zebra_init();
13130 4 : }
|