]>
Commit | Line | Data |
---|---|---|
718e3744 | 1 | /* OSPF VTY interface. |
ba682537 | 2 | * Copyright (C) 2005 6WIND <alain.ritoux@6wind.com> |
718e3744 | 3 | * Copyright (C) 2000 Toshiaki Takada |
4 | * | |
5 | * This file is part of GNU Zebra. | |
6 | * | |
7 | * GNU Zebra is free software; you can redistribute it and/or modify it | |
8 | * under the terms of the GNU General Public License as published by the | |
9 | * Free Software Foundation; either version 2, or (at your option) any | |
10 | * later version. | |
11 | * | |
12 | * GNU Zebra is distributed in the hope that it will be useful, but | |
13 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 | * General Public License for more details. | |
16 | * | |
896014f4 DL |
17 | * You should have received a copy of the GNU General Public License along |
18 | * with this program; see the file COPYING; if not, write to the Free Software | |
19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
718e3744 | 20 | */ |
21 | ||
22 | #include <zebra.h> | |
7ec4159b | 23 | #include <string.h> |
718e3744 | 24 | |
f328dc60 | 25 | #include "printfrr.h" |
cbf3e3eb | 26 | #include "monotime.h" |
718e3744 | 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" | |
bf2bfafd | 36 | #include <lib/json.h> |
8efe88ea | 37 | #include "defaults.h" |
96b663a3 | 38 | #include "lib/printfrr.h" |
718e3744 | 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" | |
7f342629 | 56 | #include "ospfd/ospf_bfd.h" |
132a782e | 57 | #include "ospfd/ospf_ldp_sync.h" |
718e3744 | 58 | |
f328dc60 | 59 | |
c572fbfe | 60 | FRR_CFG_DEFAULT_BOOL(OSPF_LOG_ADJACENCY_CHANGES, |
4c1458b5 DL |
61 | { .val_bool = true, .match_profile = "datacenter", }, |
62 | { .val_bool = false }, | |
67b0f40c | 63 | ); |
c572fbfe | 64 | |
2b64873d | 65 | static const char *const ospf_network_type_str[] = { |
d62a17ae | 66 | "Null", "POINTOPOINT", "BROADCAST", "NBMA", "POINTOMULTIPOINT", |
67 | "VIRTUALLINK", "LOOPBACK"}; | |
718e3744 | 68 | |
718e3744 | 69 | /* Utility functions. */ |
d62a17ae | 70 | int str2area_id(const char *str, struct in_addr *area_id, int *area_id_fmt) |
718e3744 | 71 | { |
d62a17ae | 72 | char *ep; |
718e3744 | 73 | |
d62a17ae | 74 | area_id->s_addr = htonl(strtoul(str, &ep, 10)); |
75 | if (*ep && !inet_aton(str, area_id)) | |
76 | return -1; | |
718e3744 | 77 | |
d62a17ae | 78 | *area_id_fmt = |
79 | *ep ? OSPF_AREA_ID_FMT_DOTTEDQUAD : OSPF_AREA_ID_FMT_DECIMAL; | |
718e3744 | 80 | |
d62a17ae | 81 | return 0; |
718e3744 | 82 | } |
83 | ||
1f9d4e3d | 84 | static void area_id2str(char *buf, int length, struct in_addr *area_id, |
85 | int area_id_fmt) | |
86573dcb | 86 | { |
d62a17ae | 87 | if (area_id_fmt == OSPF_AREA_ID_FMT_DOTTEDQUAD) |
1f9d4e3d | 88 | inet_ntop(AF_INET, area_id, buf, length); |
d62a17ae | 89 | else |
fc746f1c QY |
90 | snprintf(buf, length, "%lu", |
91 | (unsigned long)ntohl(area_id->s_addr)); | |
86573dcb | 92 | } |
6b0655a2 | 93 | |
d62a17ae | 94 | static int str2metric(const char *str, int *metric) |
718e3744 | 95 | { |
d62a17ae | 96 | /* Sanity check. */ |
97 | if (str == NULL) | |
98 | return 0; | |
718e3744 | 99 | |
d62a17ae | 100 | *metric = strtol(str, NULL, 10); |
1fdc969f | 101 | if (*metric < 0 || *metric > 16777214) { |
d62a17ae | 102 | /* vty_out (vty, "OSPF metric value is invalid\n"); */ |
103 | return 0; | |
104 | } | |
718e3744 | 105 | |
d62a17ae | 106 | return 1; |
718e3744 | 107 | } |
108 | ||
d62a17ae | 109 | static int str2metric_type(const char *str, int *metric_type) |
718e3744 | 110 | { |
d62a17ae | 111 | /* Sanity check. */ |
112 | if (str == NULL) | |
113 | return 0; | |
718e3744 | 114 | |
d62a17ae | 115 | if (strncmp(str, "1", 1) == 0) |
116 | *metric_type = EXTERNAL_METRIC_TYPE_1; | |
117 | else if (strncmp(str, "2", 1) == 0) | |
118 | *metric_type = EXTERNAL_METRIC_TYPE_2; | |
119 | else | |
120 | return 0; | |
718e3744 | 121 | |
d62a17ae | 122 | return 1; |
718e3744 | 123 | } |
124 | ||
d62a17ae | 125 | int ospf_oi_count(struct interface *ifp) |
718e3744 | 126 | { |
d62a17ae | 127 | struct route_node *rn; |
128 | int i = 0; | |
718e3744 | 129 | |
d62a17ae | 130 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) |
131 | if (rn->info) | |
132 | i++; | |
718e3744 | 133 | |
d62a17ae | 134 | return i; |
718e3744 | 135 | } |
136 | ||
996c9314 LB |
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"); \ | |
43b8d1d8 CS |
141 | } |
142 | ||
409f98ab IR |
143 | 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) | |
718e3744 | 146 | { |
34d6798f | 147 | int idx_vrf = 0, idx_inst = 0; |
b5a8894d | 148 | |
34d6798f | 149 | *instance = 0; |
409f98ab IR |
150 | if (argv_find(argv, argc, "(1-65535)", &idx_inst)) { |
151 | if (ospf_instance == 0) { | |
152 | vty_out(vty, | |
153 | "%% OSPF is not running in instance mode\n"); | |
154 | return CMD_WARNING_CONFIG_FAILED; | |
155 | } | |
156 | ||
34d6798f | 157 | *instance = strtoul(argv[idx_inst]->arg, NULL, 10); |
409f98ab | 158 | } |
34d6798f | 159 | |
409f98ab | 160 | *vrf_name = NULL; |
b5a8894d | 161 | if (argv_find(argv, argc, "vrf", &idx_vrf)) { |
409f98ab IR |
162 | if (ospf_instance != 0) { |
163 | vty_out(vty, | |
164 | "%% VRF is not supported in instance mode\n"); | |
165 | return CMD_WARNING_CONFIG_FAILED; | |
b5a8894d | 166 | } |
34d6798f | 167 | |
409f98ab IR |
168 | *vrf_name = argv[idx_vrf + 1]->arg; |
169 | if (*vrf_name && strmatch(*vrf_name, VRF_DEFAULT_NAME)) | |
170 | *vrf_name = NULL; | |
c572fbfe DL |
171 | } |
172 | ||
409f98ab | 173 | return CMD_SUCCESS; |
43b8d1d8 CS |
174 | } |
175 | ||
52d0c099 | 176 | static void ospf_show_vrf_name(struct ospf *ospf, struct vty *vty, |
d7c0a89a | 177 | json_object *json, uint8_t use_vrf) |
52d0c099 | 178 | { |
b1c3ae8c CS |
179 | if (use_vrf) { |
180 | if (json) { | |
181 | if (ospf->vrf_id == VRF_DEFAULT) | |
182 | json_object_string_add(json, "vrfName", | |
183 | "default"); | |
184 | else | |
185 | json_object_string_add(json, "vrfName", | |
186 | ospf->name); | |
187 | json_object_int_add(json, "vrfId", ospf->vrf_id); | |
188 | } else { | |
189 | if (ospf->vrf_id == VRF_DEFAULT) | |
190 | vty_out(vty, "VRF Name: %s\n", "default"); | |
191 | else if (ospf->name) | |
192 | vty_out(vty, "VRF Name: %s\n", ospf->name); | |
193 | } | |
52d0c099 | 194 | } |
52d0c099 CS |
195 | } |
196 | ||
43b8d1d8 | 197 | #ifndef VTYSH_EXTRACT_PL |
2e4c2296 | 198 | #include "ospfd/ospf_vty_clippy.c" |
43b8d1d8 CS |
199 | #endif |
200 | ||
201 | DEFUN_NOSH (router_ospf, | |
202 | router_ospf_cmd, | |
203 | "router ospf [{(1-65535)|vrf NAME}]", | |
204 | "Enable a routing process\n" | |
205 | "Start OSPF configuration\n" | |
206 | "Instance ID\n" | |
207 | VRF_CMD_HELP_STR) | |
208 | { | |
409f98ab IR |
209 | unsigned short instance; |
210 | const char *vrf_name; | |
211 | bool created = false; | |
212 | struct ospf *ospf; | |
213 | int ret; | |
43b8d1d8 | 214 | |
409f98ab IR |
215 | ret = ospf_router_cmd_parse(vty, argv, argc, &instance, &vrf_name); |
216 | if (ret != CMD_SUCCESS) | |
217 | return ret; | |
d62a17ae | 218 | |
409f98ab | 219 | if (instance != ospf_instance) { |
d62a17ae | 220 | VTY_PUSH_CONTEXT_NULL(OSPF_NODE); |
409f98ab | 221 | return CMD_NOT_MY_INSTANCE; |
d62a17ae | 222 | } |
223 | ||
409f98ab IR |
224 | ospf = ospf_get(instance, vrf_name, &created); |
225 | ||
226 | if (created) | |
227 | if (DFLT_OSPF_LOG_ADJACENCY_CHANGES) | |
228 | SET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES); | |
229 | ||
230 | if (IS_DEBUG_OSPF_EVENT) | |
231 | zlog_debug( | |
232 | "Config command 'router ospf %d' received, vrf %s id %u oi_running %u", | |
233 | ospf->instance, ospf->name ? ospf->name : "NIL", | |
234 | ospf->vrf_id, ospf->oi_running); | |
235 | ||
236 | VTY_PUSH_CONTEXT(OSPF_NODE, ospf); | |
237 | ||
64ac44f6 | 238 | return ret; |
718e3744 | 239 | } |
240 | ||
241 | DEFUN (no_router_ospf, | |
242 | no_router_ospf_cmd, | |
43b8d1d8 | 243 | "no router ospf [{(1-65535)|vrf NAME}]", |
718e3744 | 244 | NO_STR |
245 | "Enable a routing process\n" | |
7a7be519 | 246 | "Start OSPF configuration\n" |
b5a8894d CS |
247 | "Instance ID\n" |
248 | VRF_CMD_HELP_STR) | |
718e3744 | 249 | { |
409f98ab IR |
250 | unsigned short instance; |
251 | const char *vrf_name; | |
d62a17ae | 252 | struct ospf *ospf; |
409f98ab | 253 | int ret; |
b5a8894d | 254 | |
409f98ab IR |
255 | ret = ospf_router_cmd_parse(vty, argv, argc, &instance, &vrf_name); |
256 | if (ret != CMD_SUCCESS) | |
257 | return ret; | |
718e3744 | 258 | |
409f98ab IR |
259 | if (instance != ospf_instance) |
260 | return CMD_NOT_MY_INSTANCE; | |
261 | ||
262 | ospf = ospf_lookup(instance, vrf_name); | |
263 | if (ospf) | |
264 | ospf_finish(ospf); | |
265 | else | |
266 | ret = CMD_WARNING_CONFIG_FAILED; | |
267 | ||
268 | return ret; | |
718e3744 | 269 | } |
270 | ||
7c8ff89e | 271 | |
43b8d1d8 | 272 | DEFPY (ospf_router_id, |
718e3744 | 273 | ospf_router_id_cmd, |
274 | "ospf router-id A.B.C.D", | |
275 | "OSPF specific commands\n" | |
276 | "router-id for the OSPF process\n" | |
277 | "OSPF router-id in IP address format\n") | |
278 | { | |
a3d826f0 | 279 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
43b8d1d8 | 280 | |
d62a17ae | 281 | struct listnode *node; |
282 | struct ospf_area *area; | |
d62a17ae | 283 | |
284 | ospf->router_id_static = router_id; | |
285 | ||
286 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) | |
287 | if (area->full_nbrs) { | |
288 | vty_out(vty, | |
1b8049c7 | 289 | "For this router-id change to take effect, use \"clear ip ospf process\" command\n"); |
d62a17ae | 290 | return CMD_SUCCESS; |
291 | } | |
292 | ||
293 | ospf_router_id_update(ospf); | |
294 | ||
295 | return CMD_SUCCESS; | |
718e3744 | 296 | } |
297 | ||
7a7be519 | 298 | DEFUN_HIDDEN (ospf_router_id_old, |
747e489c DW |
299 | ospf_router_id_old_cmd, |
300 | "router-id A.B.C.D", | |
301 | "router-id for the OSPF process\n" | |
302 | "OSPF router-id in IP address format\n") | |
7a7be519 | 303 | { |
a3d826f0 | 304 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 305 | int idx_ipv4 = 1; |
306 | struct listnode *node; | |
307 | struct ospf_area *area; | |
308 | struct in_addr router_id; | |
309 | int ret; | |
310 | ||
311 | ret = inet_aton(argv[idx_ipv4]->arg, &router_id); | |
312 | if (!ret) { | |
313 | vty_out(vty, "Please specify Router ID by A.B.C.D\n"); | |
314 | return CMD_WARNING_CONFIG_FAILED; | |
315 | } | |
7a7be519 | 316 | |
d62a17ae | 317 | ospf->router_id_static = router_id; |
318 | ||
319 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) | |
320 | if (area->full_nbrs) { | |
321 | vty_out(vty, | |
1b8049c7 | 322 | "For this router-id change to take effect, use \"clear ip ospf process\" command\n"); |
d62a17ae | 323 | return CMD_SUCCESS; |
324 | } | |
325 | ||
326 | ospf_router_id_update(ospf); | |
327 | ||
328 | return CMD_SUCCESS; | |
7a7be519 | 329 | } |
747e489c | 330 | |
43b8d1d8 | 331 | DEFPY (no_ospf_router_id, |
718e3744 | 332 | no_ospf_router_id_cmd, |
7a7be519 | 333 | "no ospf router-id [A.B.C.D]", |
718e3744 | 334 | NO_STR |
335 | "OSPF specific commands\n" | |
7a7be519 | 336 | "router-id for the OSPF process\n" |
337 | "OSPF router-id in IP address format\n") | |
718e3744 | 338 | { |
a3d826f0 | 339 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 340 | struct listnode *node; |
341 | struct ospf_area *area; | |
68980084 | 342 | |
43b8d1d8 CS |
343 | if (router_id_str) { |
344 | if (!IPV4_ADDR_SAME(&ospf->router_id_static, &router_id)) { | |
345 | vty_out(vty, "%% OSPF router-id doesn't match\n"); | |
346 | return CMD_WARNING_CONFIG_FAILED; | |
347 | } | |
348 | } | |
349 | ||
d62a17ae | 350 | ospf->router_id_static.s_addr = 0; |
718e3744 | 351 | |
d62a17ae | 352 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) |
353 | if (area->full_nbrs) { | |
354 | vty_out(vty, | |
1b8049c7 | 355 | "For this router-id change to take effect, use \"clear ip ospf process\" command\n"); |
d62a17ae | 356 | return CMD_SUCCESS; |
357 | } | |
2c19a6ec | 358 | |
d62a17ae | 359 | ospf_router_id_update(ospf); |
718e3744 | 360 | |
d62a17ae | 361 | return CMD_SUCCESS; |
718e3744 | 362 | } |
363 | ||
718e3744 | 364 | |
3eec4ee0 IR |
365 | static void ospf_passive_interface_default_update(struct ospf *ospf, |
366 | uint8_t newval) | |
d62a17ae | 367 | { |
368 | struct listnode *ln; | |
d62a17ae | 369 | struct ospf_interface *oi; |
370 | ||
371 | ospf->passive_interface_default = newval; | |
372 | ||
3eec4ee0 IR |
373 | /* update multicast memberships */ |
374 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, ln, oi)) | |
d62a17ae | 375 | ospf_if_set_multicast(oi); |
d62a17ae | 376 | } |
377 | ||
82f0277b IR |
378 | static void ospf_passive_interface_update(struct interface *ifp, |
379 | struct ospf_if_params *params, | |
380 | struct in_addr addr, uint8_t newval) | |
d62a17ae | 381 | { |
3eec4ee0 | 382 | struct route_node *rn; |
d62a17ae | 383 | |
82f0277b IR |
384 | if (OSPF_IF_PARAM_CONFIGURED(params, passive_interface)) { |
385 | if (params->passive_interface == newval) | |
386 | return; | |
387 | ||
388 | params->passive_interface = newval; | |
389 | UNSET_IF_PARAM(params, passive_interface); | |
390 | if (params != IF_DEF_PARAMS(ifp)) { | |
391 | ospf_free_if_params(ifp, addr); | |
392 | ospf_if_update_params(ifp, addr); | |
393 | } | |
394 | } else { | |
395 | params->passive_interface = newval; | |
396 | SET_IF_PARAM(params, passive_interface); | |
397 | } | |
398 | ||
3eec4ee0 IR |
399 | /* |
400 | * XXX We should call ospf_if_set_multicast on exactly those | |
401 | * interfaces for which the passive property changed. It is too much | |
402 | * work to determine this set, so we do this for every interface. | |
403 | * This is safe and reasonable because ospf_if_set_multicast uses a | |
404 | * record of joined groups to avoid systems calls if the desired | |
405 | * memberships match the current memership. | |
406 | */ | |
d62a17ae | 407 | |
3eec4ee0 IR |
408 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { |
409 | struct ospf_interface *oi = rn->info; | |
d62a17ae | 410 | |
3eec4ee0 IR |
411 | if (oi) |
412 | ospf_if_set_multicast(oi); | |
d62a17ae | 413 | } |
3eec4ee0 IR |
414 | |
415 | /* | |
416 | * XXX It is not clear what state transitions the interface needs to | |
417 | * undergo when going from active to passive and vice versa. Fixing | |
418 | * this will require precise identification of interfaces having such a | |
419 | * transition. | |
420 | */ | |
d62a17ae | 421 | } |
422 | ||
3eec4ee0 IR |
423 | DEFUN (ospf_passive_interface_default, |
424 | ospf_passive_interface_default_cmd, | |
425 | "passive-interface default", | |
426 | "Suppress routing updates on an interface\n" | |
427 | "Suppress routing updates on interfaces by default\n") | |
d62a17ae | 428 | { |
3eec4ee0 IR |
429 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
430 | ||
431 | ospf_passive_interface_default_update(ospf, OSPF_IF_PASSIVE); | |
432 | ||
433 | return CMD_SUCCESS; | |
7ffa8fa2 PJ |
434 | } |
435 | ||
3eec4ee0 | 436 | DEFUN_HIDDEN (ospf_passive_interface_addr, |
a2c62831 | 437 | ospf_passive_interface_addr_cmd, |
3eec4ee0 | 438 | "passive-interface IFNAME [A.B.C.D]", |
718e3744 | 439 | "Suppress routing updates on an interface\n" |
7a7be519 | 440 | "Interface's name\n" |
3eec4ee0 | 441 | "IPv4 address\n") |
718e3744 | 442 | { |
a3d826f0 | 443 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 444 | int idx_ipv4 = 2; |
e99734f1 | 445 | struct interface *ifp = NULL; |
d62a17ae | 446 | struct in_addr addr = {.s_addr = INADDR_ANY}; |
d62a17ae | 447 | struct ospf_if_params *params; |
3eec4ee0 IR |
448 | int ret; |
449 | ||
450 | vty_out(vty, | |
451 | "This command is deprecated, because it is not VRF-aware.\n"); | |
452 | vty_out(vty, | |
453 | "Please, use \"ip ospf passive\" on an interface instead.\n"); | |
d62a17ae | 454 | |
e99734f1 | 455 | if (ospf->vrf_id != VRF_UNKNOWN) |
a36898e7 | 456 | ifp = if_get_by_name(argv[1]->arg, ospf->vrf_id); |
d62a17ae | 457 | |
b5a8894d | 458 | if (ifp == NULL) { |
996c9314 | 459 | vty_out(vty, "interface %s not found.\n", (char *)argv[1]->arg); |
e99734f1 | 460 | return CMD_WARNING_CONFIG_FAILED; |
b5a8894d | 461 | } |
d62a17ae | 462 | |
d62a17ae | 463 | if (argc == 3) { |
464 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
465 | if (!ret) { | |
466 | vty_out(vty, | |
467 | "Please specify interface address by A.B.C.D\n"); | |
468 | return CMD_WARNING_CONFIG_FAILED; | |
469 | } | |
470 | ||
471 | params = ospf_get_if_params(ifp, addr); | |
472 | ospf_if_update_params(ifp, addr); | |
3eec4ee0 IR |
473 | } else { |
474 | params = IF_DEF_PARAMS(ifp); | |
d62a17ae | 475 | } |
476 | ||
82f0277b | 477 | ospf_passive_interface_update(ifp, params, addr, OSPF_IF_PASSIVE); |
d62a17ae | 478 | |
3eec4ee0 IR |
479 | return CMD_SUCCESS; |
480 | } | |
d62a17ae | 481 | |
3eec4ee0 IR |
482 | DEFUN (no_ospf_passive_interface_default, |
483 | no_ospf_passive_interface_default_cmd, | |
484 | "no passive-interface default", | |
485 | NO_STR | |
486 | "Allow routing updates on an interface\n" | |
487 | "Allow routing updates on interfaces by default\n") | |
488 | { | |
489 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
490 | ||
491 | ospf_passive_interface_default_update(ospf, OSPF_IF_ACTIVE); | |
d62a17ae | 492 | |
493 | return CMD_SUCCESS; | |
718e3744 | 494 | } |
495 | ||
3eec4ee0 | 496 | DEFUN_HIDDEN (no_ospf_passive_interface, |
a2c62831 | 497 | no_ospf_passive_interface_addr_cmd, |
3eec4ee0 | 498 | "no passive-interface IFNAME [A.B.C.D]", |
718e3744 | 499 | NO_STR |
500 | "Allow routing updates on an interface\n" | |
7a7be519 | 501 | "Interface's name\n" |
3eec4ee0 | 502 | "IPv4 address\n") |
718e3744 | 503 | { |
a3d826f0 | 504 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 505 | int idx_ipv4 = 3; |
e99734f1 | 506 | struct interface *ifp = NULL; |
d62a17ae | 507 | struct in_addr addr = {.s_addr = INADDR_ANY}; |
508 | struct ospf_if_params *params; | |
509 | int ret; | |
d62a17ae | 510 | |
3eec4ee0 IR |
511 | vty_out(vty, |
512 | "This command is deprecated, because it is not VRF-aware.\n"); | |
513 | vty_out(vty, | |
514 | "Please, use \"no ip ospf passive\" on an interface instead.\n"); | |
43540886 | 515 | |
e99734f1 | 516 | if (ospf->vrf_id != VRF_UNKNOWN) |
a36898e7 | 517 | ifp = if_get_by_name(argv[2]->arg, ospf->vrf_id); |
e99734f1 | 518 | |
b5a8894d | 519 | if (ifp == NULL) { |
996c9314 | 520 | vty_out(vty, "interface %s not found.\n", (char *)argv[2]->arg); |
e99734f1 | 521 | return CMD_WARNING_CONFIG_FAILED; |
b5a8894d | 522 | } |
ba6454ec | 523 | |
d62a17ae | 524 | if (argc == 4) { |
525 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
526 | if (!ret) { | |
527 | vty_out(vty, | |
528 | "Please specify interface address by A.B.C.D\n"); | |
529 | return CMD_WARNING_CONFIG_FAILED; | |
530 | } | |
d62a17ae | 531 | params = ospf_lookup_if_params(ifp, addr); |
532 | if (params == NULL) | |
533 | return CMD_SUCCESS; | |
3eec4ee0 IR |
534 | } else { |
535 | params = IF_DEF_PARAMS(ifp); | |
d62a17ae | 536 | } |
d62a17ae | 537 | |
82f0277b | 538 | ospf_passive_interface_update(ifp, params, addr, OSPF_IF_ACTIVE); |
3eec4ee0 | 539 | |
d62a17ae | 540 | return CMD_SUCCESS; |
718e3744 | 541 | } |
542 | ||
718e3744 | 543 | |
a2c62831 | 544 | DEFUN (ospf_network_area, |
545 | ospf_network_area_cmd, | |
6147e2c6 | 546 | "network A.B.C.D/M area <A.B.C.D|(0-4294967295)>", |
718e3744 | 547 | "Enable routing on an IP network\n" |
548 | "OSPF network prefix\n" | |
549 | "Set the OSPF area ID\n" | |
550 | "OSPF area ID in IP address format\n" | |
551 | "OSPF area ID as a decimal value\n") | |
552 | { | |
a3d826f0 | 553 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 554 | int idx_ipv4_prefixlen = 1; |
555 | int idx_ipv4_number = 3; | |
556 | struct prefix_ipv4 p; | |
557 | struct in_addr area_id; | |
558 | int ret, format; | |
cbf32f74 | 559 | uint32_t count; |
d62a17ae | 560 | |
561 | if (ospf->instance) { | |
562 | vty_out(vty, | |
563 | "The network command is not supported in multi-instance ospf\n"); | |
564 | return CMD_WARNING_CONFIG_FAILED; | |
565 | } | |
718e3744 | 566 | |
cbf32f74 IR |
567 | count = ospf_count_area_params(ospf); |
568 | if (count > 0) { | |
d62a17ae | 569 | vty_out(vty, |
570 | "Please remove all ip ospf area x.x.x.x commands first.\n"); | |
aed7cc62 | 571 | if (IS_DEBUG_OSPF_EVENT) |
996c9314 | 572 | zlog_debug( |
d12566a1 | 573 | "%s ospf vrf %s num of %u ip ospf area x config", |
5e81f5dd | 574 | __func__, ospf->name ? ospf->name : "NIL", |
cbf32f74 | 575 | count); |
d62a17ae | 576 | return CMD_WARNING_CONFIG_FAILED; |
577 | } | |
578 | ||
579 | /* Get network prefix and Area ID. */ | |
580 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); | |
581 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); | |
582 | ||
583 | ret = ospf_network_set(ospf, &p, area_id, format); | |
584 | if (ret == 0) { | |
585 | vty_out(vty, "There is already same network statement.\n"); | |
2b0a905a | 586 | return CMD_WARNING_CONFIG_FAILED; |
d62a17ae | 587 | } |
588 | ||
589 | return CMD_SUCCESS; | |
718e3744 | 590 | } |
591 | ||
a2c62831 | 592 | DEFUN (no_ospf_network_area, |
593 | no_ospf_network_area_cmd, | |
6147e2c6 | 594 | "no network A.B.C.D/M area <A.B.C.D|(0-4294967295)>", |
718e3744 | 595 | NO_STR |
596 | "Enable routing on an IP network\n" | |
597 | "OSPF network prefix\n" | |
598 | "Set the OSPF area ID\n" | |
599 | "OSPF area ID in IP address format\n" | |
600 | "OSPF area ID as a decimal value\n") | |
601 | { | |
a3d826f0 | 602 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 603 | int idx_ipv4_prefixlen = 2; |
604 | int idx_ipv4_number = 4; | |
605 | struct prefix_ipv4 p; | |
606 | struct in_addr area_id; | |
607 | int ret, format; | |
608 | ||
609 | if (ospf->instance) { | |
610 | vty_out(vty, | |
611 | "The network command is not supported in multi-instance ospf\n"); | |
612 | return CMD_WARNING_CONFIG_FAILED; | |
613 | } | |
718e3744 | 614 | |
d62a17ae | 615 | /* Get network prefix and Area ID. */ |
616 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); | |
617 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); | |
618 | ||
619 | ret = ospf_network_unset(ospf, &p, area_id); | |
620 | if (ret == 0) { | |
621 | vty_out(vty, | |
622 | "Can't find specified network area configuration.\n"); | |
623 | return CMD_WARNING_CONFIG_FAILED; | |
624 | } | |
625 | ||
626 | return CMD_SUCCESS; | |
718e3744 | 627 | } |
628 | ||
a2c62831 | 629 | DEFUN (ospf_area_range, |
630 | ospf_area_range_cmd, | |
7a7be519 | 631 | "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M [advertise [cost (0-16777215)]]", |
718e3744 | 632 | "OSPF area parameters\n" |
633 | "OSPF area ID in IP address format\n" | |
634 | "OSPF area ID as a decimal value\n" | |
635 | "Summarize routes matching address/mask (border routers only)\n" | |
7a7be519 | 636 | "Area range prefix\n" |
637 | "Advertise this range (default)\n" | |
638 | "User specified metric for this range\n" | |
639 | "Advertised metric for this range\n") | |
718e3744 | 640 | { |
a3d826f0 | 641 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 642 | int idx_ipv4_number = 1; |
643 | int idx_ipv4_prefixlen = 3; | |
644 | int idx_cost = 6; | |
645 | struct prefix_ipv4 p; | |
646 | struct in_addr area_id; | |
647 | int format; | |
d7c0a89a | 648 | uint32_t cost; |
d62a17ae | 649 | |
650 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); | |
651 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); | |
652 | ||
653 | ospf_area_range_set(ospf, area_id, &p, OSPF_AREA_RANGE_ADVERTISE); | |
ed709ed1 GW |
654 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), |
655 | format); | |
d62a17ae | 656 | if (argc > 5) { |
657 | cost = strtoul(argv[idx_cost]->arg, NULL, 10); | |
658 | ospf_area_range_cost_set(ospf, area_id, &p, cost); | |
659 | } | |
718e3744 | 660 | |
d62a17ae | 661 | return CMD_SUCCESS; |
718e3744 | 662 | } |
663 | ||
7a7be519 | 664 | DEFUN (ospf_area_range_cost, |
665 | ospf_area_range_cost_cmd, | |
666 | "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M cost (0-16777215)", | |
667 | "OSPF area parameters\n" | |
668 | "OSPF area ID in IP address format\n" | |
669 | "OSPF area ID as a decimal value\n" | |
670 | "Summarize routes matching address/mask (border routers only)\n" | |
671 | "Area range prefix\n" | |
672 | "User specified metric for this range\n" | |
673 | "Advertised metric for this range\n") | |
674 | { | |
a3d826f0 | 675 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 676 | int idx_ipv4_number = 1; |
677 | int idx_ipv4_prefixlen = 3; | |
678 | int idx_cost = 5; | |
679 | struct prefix_ipv4 p; | |
680 | struct in_addr area_id; | |
681 | int format; | |
d7c0a89a | 682 | uint32_t cost; |
7a7be519 | 683 | |
d62a17ae | 684 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
685 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); | |
7a7be519 | 686 | |
d62a17ae | 687 | ospf_area_range_set(ospf, area_id, &p, OSPF_AREA_RANGE_ADVERTISE); |
688 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
689 | format); | |
718e3744 | 690 | |
d62a17ae | 691 | cost = strtoul(argv[idx_cost]->arg, NULL, 10); |
692 | ospf_area_range_cost_set(ospf, area_id, &p, cost); | |
718e3744 | 693 | |
d62a17ae | 694 | return CMD_SUCCESS; |
7a7be519 | 695 | } |
718e3744 | 696 | |
a2c62831 | 697 | DEFUN (ospf_area_range_not_advertise, |
698 | ospf_area_range_not_advertise_cmd, | |
6147e2c6 | 699 | "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M not-advertise", |
718e3744 | 700 | "OSPF area parameters\n" |
701 | "OSPF area ID in IP address format\n" | |
702 | "OSPF area ID as a decimal value\n" | |
703 | "Summarize routes matching address/mask (border routers only)\n" | |
704 | "Area range prefix\n" | |
705 | "DoNotAdvertise this range\n") | |
706 | { | |
a3d826f0 | 707 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 708 | int idx_ipv4_number = 1; |
709 | int idx_ipv4_prefixlen = 3; | |
710 | struct prefix_ipv4 p; | |
711 | struct in_addr area_id; | |
712 | int format; | |
718e3744 | 713 | |
d62a17ae | 714 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
715 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); | |
718e3744 | 716 | |
d62a17ae | 717 | ospf_area_range_set(ospf, area_id, &p, 0); |
718 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
719 | format); | |
990baca0 | 720 | ospf_area_range_substitute_unset(ospf, area_id, &p); |
718e3744 | 721 | |
d62a17ae | 722 | return CMD_SUCCESS; |
718e3744 | 723 | } |
724 | ||
a2c62831 | 725 | DEFUN (no_ospf_area_range, |
726 | no_ospf_area_range_cmd, | |
3a2d747c | 727 | "no area <A.B.C.D|(0-4294967295)> range A.B.C.D/M [<cost (0-16777215)|advertise [cost (0-16777215)]|not-advertise>]", |
718e3744 | 728 | NO_STR |
729 | "OSPF area parameters\n" | |
730 | "OSPF area ID in IP address format\n" | |
731 | "OSPF area ID as a decimal value\n" | |
732 | "Summarize routes matching address/mask (border routers only)\n" | |
7a7be519 | 733 | "Area range prefix\n" |
3a2d747c QY |
734 | "User specified metric for this range\n" |
735 | "Advertised metric for this range\n" | |
7a7be519 | 736 | "Advertise this range (default)\n" |
3a2d747c QY |
737 | "User specified metric for this range\n" |
738 | "Advertised metric for this range\n" | |
7a7be519 | 739 | "DoNotAdvertise this range\n") |
718e3744 | 740 | { |
a3d826f0 | 741 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 742 | int idx_ipv4_number = 2; |
743 | int idx_ipv4_prefixlen = 4; | |
744 | struct prefix_ipv4 p; | |
745 | struct in_addr area_id; | |
746 | int format; | |
718e3744 | 747 | |
d62a17ae | 748 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
749 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); | |
718e3744 | 750 | |
d62a17ae | 751 | ospf_area_range_unset(ospf, area_id, &p); |
718e3744 | 752 | |
d62a17ae | 753 | return CMD_SUCCESS; |
718e3744 | 754 | } |
755 | ||
a2c62831 | 756 | DEFUN (ospf_area_range_substitute, |
757 | ospf_area_range_substitute_cmd, | |
6147e2c6 | 758 | "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M substitute A.B.C.D/M", |
718e3744 | 759 | "OSPF area parameters\n" |
760 | "OSPF area ID in IP address format\n" | |
761 | "OSPF area ID as a decimal value\n" | |
762 | "Summarize routes matching address/mask (border routers only)\n" | |
763 | "Area range prefix\n" | |
764 | "Announce area range as another prefix\n" | |
765 | "Network prefix to be announced instead of range\n") | |
766 | { | |
a3d826f0 | 767 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 768 | int idx_ipv4_number = 1; |
769 | int idx_ipv4_prefixlen = 3; | |
770 | int idx_ipv4_prefixlen_2 = 5; | |
771 | struct prefix_ipv4 p, s; | |
772 | struct in_addr area_id; | |
773 | int format; | |
718e3744 | 774 | |
d62a17ae | 775 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
776 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); | |
777 | str2prefix_ipv4(argv[idx_ipv4_prefixlen_2]->arg, &s); | |
718e3744 | 778 | |
d62a17ae | 779 | ospf_area_range_substitute_set(ospf, area_id, &p, &s); |
780 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
781 | format); | |
718e3744 | 782 | |
d62a17ae | 783 | return CMD_SUCCESS; |
718e3744 | 784 | } |
785 | ||
a2c62831 | 786 | DEFUN (no_ospf_area_range_substitute, |
787 | no_ospf_area_range_substitute_cmd, | |
6147e2c6 | 788 | "no area <A.B.C.D|(0-4294967295)> range A.B.C.D/M substitute A.B.C.D/M", |
718e3744 | 789 | NO_STR |
790 | "OSPF area parameters\n" | |
791 | "OSPF area ID in IP address format\n" | |
792 | "OSPF area ID as a decimal value\n" | |
793 | "Summarize routes matching address/mask (border routers only)\n" | |
794 | "Area range prefix\n" | |
795 | "Announce area range as another prefix\n" | |
796 | "Network prefix to be announced instead of range\n") | |
797 | { | |
a3d826f0 | 798 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 799 | int idx_ipv4_number = 2; |
800 | int idx_ipv4_prefixlen = 4; | |
801 | int idx_ipv4_prefixlen_2 = 6; | |
802 | struct prefix_ipv4 p, s; | |
803 | struct in_addr area_id; | |
804 | int format; | |
718e3744 | 805 | |
d62a17ae | 806 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
807 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); | |
808 | str2prefix_ipv4(argv[idx_ipv4_prefixlen_2]->arg, &s); | |
718e3744 | 809 | |
d62a17ae | 810 | ospf_area_range_substitute_unset(ospf, area_id, &p); |
718e3744 | 811 | |
d62a17ae | 812 | return CMD_SUCCESS; |
718e3744 | 813 | } |
814 | ||
6b0655a2 | 815 | |
718e3744 | 816 | /* Command Handler Logic in VLink stuff is delicate!! |
817 | ||
818 | ALTER AT YOUR OWN RISK!!!! | |
819 | ||
820 | Various dummy values are used to represent 'NoChange' state for | |
821 | VLink configuration NOT being changed by a VLink command, and | |
822 | special syntax is used within the command strings so that the | |
823 | typed in command verbs can be seen in the configuration command | |
824 | bacckend handler. This is to drastically reduce the verbeage | |
825 | required to coe up with a reasonably compatible Cisco VLink command | |
826 | ||
d62a17ae | 827 | - Matthew Grant <grantma@anathoth.gen.nz> |
718e3744 | 828 | Wed, 21 Feb 2001 15:13:52 +1300 |
829 | */ | |
830 | ||
d62a17ae | 831 | /* Configuration data for virtual links |
832 | */ | |
718e3744 | 833 | struct ospf_vl_config_data { |
d62a17ae | 834 | struct vty *vty; /* vty stuff */ |
835 | struct in_addr area_id; /* area ID from command line */ | |
836 | int area_id_fmt; /* command line area ID format */ | |
837 | struct in_addr vl_peer; /* command line vl_peer */ | |
838 | int auth_type; /* Authehntication type, if given */ | |
839 | char *auth_key; /* simple password if present */ | |
840 | int crypto_key_id; /* Cryptographic key ID */ | |
841 | char *md5_key; /* MD5 authentication key */ | |
842 | int hello_interval; /* Obvious what these are... */ | |
843 | int retransmit_interval; | |
844 | int transmit_delay; | |
845 | int dead_interval; | |
718e3744 | 846 | }; |
847 | ||
d62a17ae | 848 | static void ospf_vl_config_data_init(struct ospf_vl_config_data *vl_config, |
849 | struct vty *vty) | |
718e3744 | 850 | { |
d62a17ae | 851 | memset(vl_config, 0, sizeof(struct ospf_vl_config_data)); |
852 | vl_config->auth_type = OSPF_AUTH_CMD_NOTSEEN; | |
853 | vl_config->vty = vty; | |
718e3744 | 854 | } |
855 | ||
4dadc291 | 856 | static struct ospf_vl_data * |
d62a17ae | 857 | ospf_find_vl_data(struct ospf *ospf, struct ospf_vl_config_data *vl_config) |
858 | { | |
859 | struct ospf_area *area; | |
860 | struct ospf_vl_data *vl_data; | |
861 | struct vty *vty; | |
862 | struct in_addr area_id; | |
863 | ||
864 | vty = vl_config->vty; | |
865 | area_id = vl_config->area_id; | |
866 | ||
867 | if (area_id.s_addr == OSPF_AREA_BACKBONE) { | |
868 | vty_out(vty, | |
869 | "Configuring VLs over the backbone is not allowed\n"); | |
870 | return NULL; | |
871 | } | |
872 | area = ospf_area_get(ospf, area_id); | |
873 | ospf_area_display_format_set(ospf, area, vl_config->area_id_fmt); | |
874 | ||
875 | if (area->external_routing != OSPF_AREA_DEFAULT) { | |
876 | if (vl_config->area_id_fmt == OSPF_AREA_ID_FMT_DOTTEDQUAD) | |
96b663a3 | 877 | vty_out(vty, "Area %pI4 is %s\n", &area_id, |
d62a17ae | 878 | area->external_routing == OSPF_AREA_NSSA |
879 | ? "nssa" | |
880 | : "stub"); | |
881 | else | |
882 | vty_out(vty, "Area %ld is %s\n", | |
d7c0a89a | 883 | (unsigned long)ntohl(area_id.s_addr), |
d62a17ae | 884 | area->external_routing == OSPF_AREA_NSSA |
885 | ? "nssa" | |
886 | : "stub"); | |
887 | return NULL; | |
888 | } | |
889 | ||
890 | if ((vl_data = ospf_vl_lookup(ospf, area, vl_config->vl_peer)) | |
891 | == NULL) { | |
892 | vl_data = ospf_vl_data_new(area, vl_config->vl_peer); | |
893 | if (vl_data->vl_oi == NULL) { | |
894 | vl_data->vl_oi = ospf_vl_new(ospf, vl_data); | |
895 | ospf_vl_add(ospf, vl_data); | |
896 | ospf_spf_calculate_schedule(ospf, | |
897 | SPF_FLAG_CONFIG_CHANGE); | |
898 | } | |
718e3744 | 899 | } |
d62a17ae | 900 | return vl_data; |
718e3744 | 901 | } |
902 | ||
903 | ||
d62a17ae | 904 | static int ospf_vl_set_security(struct ospf_vl_data *vl_data, |
905 | struct ospf_vl_config_data *vl_config) | |
906 | { | |
907 | struct crypt_key *ck; | |
908 | struct vty *vty; | |
909 | struct interface *ifp = vl_data->vl_oi->ifp; | |
910 | ||
911 | vty = vl_config->vty; | |
912 | ||
913 | if (vl_config->auth_type != OSPF_AUTH_CMD_NOTSEEN) { | |
914 | SET_IF_PARAM(IF_DEF_PARAMS(ifp), auth_type); | |
915 | IF_DEF_PARAMS(ifp)->auth_type = vl_config->auth_type; | |
718e3744 | 916 | } |
718e3744 | 917 | |
d62a17ae | 918 | if (vl_config->auth_key) { |
919 | memset(IF_DEF_PARAMS(ifp)->auth_simple, 0, | |
920 | OSPF_AUTH_SIMPLE_SIZE + 1); | |
4d65d927 QY |
921 | strlcpy((char *)IF_DEF_PARAMS(ifp)->auth_simple, |
922 | vl_config->auth_key, | |
923 | sizeof(IF_DEF_PARAMS(ifp)->auth_simple)); | |
d62a17ae | 924 | } else if (vl_config->md5_key) { |
925 | if (ospf_crypt_key_lookup(IF_DEF_PARAMS(ifp)->auth_crypt, | |
926 | vl_config->crypto_key_id) | |
927 | != NULL) { | |
928 | vty_out(vty, "OSPF: Key %d already exists\n", | |
929 | vl_config->crypto_key_id); | |
851fcbae | 930 | return CMD_WARNING; |
d62a17ae | 931 | } |
932 | ck = ospf_crypt_key_new(); | |
933 | ck->key_id = vl_config->crypto_key_id; | |
934 | memset(ck->auth_key, 0, OSPF_AUTH_MD5_SIZE + 1); | |
4d65d927 QY |
935 | strlcpy((char *)ck->auth_key, vl_config->md5_key, |
936 | sizeof(ck->auth_key)); | |
d62a17ae | 937 | |
938 | ospf_crypt_key_add(IF_DEF_PARAMS(ifp)->auth_crypt, ck); | |
939 | } else if (vl_config->crypto_key_id != 0) { | |
940 | /* Delete a key */ | |
941 | ||
942 | if (ospf_crypt_key_lookup(IF_DEF_PARAMS(ifp)->auth_crypt, | |
943 | vl_config->crypto_key_id) | |
944 | == NULL) { | |
945 | vty_out(vty, "OSPF: Key %d does not exist\n", | |
946 | vl_config->crypto_key_id); | |
947 | return CMD_WARNING_CONFIG_FAILED; | |
948 | } | |
949 | ||
950 | ospf_crypt_key_delete(IF_DEF_PARAMS(ifp)->auth_crypt, | |
951 | vl_config->crypto_key_id); | |
952 | } | |
953 | ||
954 | return CMD_SUCCESS; | |
718e3744 | 955 | } |
956 | ||
d62a17ae | 957 | static int ospf_vl_set_timers(struct ospf_vl_data *vl_data, |
958 | struct ospf_vl_config_data *vl_config) | |
959 | { | |
960 | struct interface *ifp = vl_data->vl_oi->ifp; | |
961 | /* Virtual Link data initialised to defaults, so only set | |
962 | if a value given */ | |
963 | if (vl_config->hello_interval) { | |
964 | SET_IF_PARAM(IF_DEF_PARAMS(ifp), v_hello); | |
965 | IF_DEF_PARAMS(ifp)->v_hello = vl_config->hello_interval; | |
966 | } | |
967 | ||
968 | if (vl_config->dead_interval) { | |
969 | SET_IF_PARAM(IF_DEF_PARAMS(ifp), v_wait); | |
970 | IF_DEF_PARAMS(ifp)->v_wait = vl_config->dead_interval; | |
971 | } | |
972 | ||
973 | if (vl_config->retransmit_interval) { | |
974 | SET_IF_PARAM(IF_DEF_PARAMS(ifp), retransmit_interval); | |
975 | IF_DEF_PARAMS(ifp)->retransmit_interval = | |
976 | vl_config->retransmit_interval; | |
977 | } | |
978 | ||
979 | if (vl_config->transmit_delay) { | |
980 | SET_IF_PARAM(IF_DEF_PARAMS(ifp), transmit_delay); | |
981 | IF_DEF_PARAMS(ifp)->transmit_delay = vl_config->transmit_delay; | |
982 | } | |
983 | ||
984 | return CMD_SUCCESS; | |
718e3744 | 985 | } |
986 | ||
987 | ||
718e3744 | 988 | /* The business end of all of the above */ |
d62a17ae | 989 | static int ospf_vl_set(struct ospf *ospf, struct ospf_vl_config_data *vl_config) |
990 | { | |
991 | struct ospf_vl_data *vl_data; | |
992 | int ret; | |
718e3744 | 993 | |
d62a17ae | 994 | vl_data = ospf_find_vl_data(ospf, vl_config); |
995 | if (!vl_data) | |
996 | return CMD_WARNING_CONFIG_FAILED; | |
997 | ||
998 | /* Process this one first as it can have a fatal result, which can | |
999 | only logically occur if the virtual link exists already | |
1000 | Thus a command error does not result in a change to the | |
1001 | running configuration such as unexpectedly altered timer | |
1002 | values etc.*/ | |
1003 | ret = ospf_vl_set_security(vl_data, vl_config); | |
1004 | if (ret != CMD_SUCCESS) | |
1005 | return ret; | |
1006 | ||
1007 | /* Set any time based parameters, these area already range checked */ | |
1008 | ||
1009 | ret = ospf_vl_set_timers(vl_data, vl_config); | |
1010 | if (ret != CMD_SUCCESS) | |
1011 | return ret; | |
718e3744 | 1012 | |
d62a17ae | 1013 | return CMD_SUCCESS; |
718e3744 | 1014 | } |
1015 | ||
1016 | /* This stuff exists to make specifying all the alias commands A LOT simpler | |
1017 | */ | |
d62a17ae | 1018 | #define VLINK_HELPSTR_IPADDR \ |
1019 | "OSPF area parameters\n" \ | |
1020 | "OSPF area ID in IP address format\n" \ | |
1021 | "OSPF area ID as a decimal value\n" \ | |
1022 | "Configure a virtual link\n" \ | |
1023 | "Router ID of the remote ABR\n" | |
1024 | ||
1025 | #define VLINK_HELPSTR_AUTHTYPE_SIMPLE \ | |
1026 | "Enable authentication on this virtual link\n" \ | |
1027 | "dummy string \n" | |
1028 | ||
1029 | #define VLINK_HELPSTR_AUTHTYPE_ALL \ | |
1030 | VLINK_HELPSTR_AUTHTYPE_SIMPLE \ | |
1031 | "Use null authentication\n" \ | |
1032 | "Use message-digest authentication\n" | |
1033 | ||
1034 | #define VLINK_HELPSTR_TIME_PARAM \ | |
1035 | "Time between HELLO packets\n" \ | |
1036 | "Seconds\n" \ | |
1037 | "Time between retransmitting lost link state advertisements\n" \ | |
1038 | "Seconds\n" \ | |
1039 | "Link state transmit delay\n" \ | |
1040 | "Seconds\n" \ | |
1041 | "Interval time after which a neighbor is declared down\n" \ | |
1042 | "Seconds\n" | |
1043 | ||
1044 | #define VLINK_HELPSTR_AUTH_SIMPLE \ | |
1045 | "Authentication password (key)\n" \ | |
baf9eaad | 1046 | "The OSPF password (key)\n" |
d62a17ae | 1047 | |
1048 | #define VLINK_HELPSTR_AUTH_MD5 \ | |
1049 | "Message digest authentication password (key)\n" \ | |
d62a17ae | 1050 | "Key ID\n" \ |
1051 | "Use MD5 algorithm\n" \ | |
baf9eaad | 1052 | "The OSPF password (key)\n" |
718e3744 | 1053 | |
a2c62831 | 1054 | DEFUN (ospf_area_vlink, |
1055 | ospf_area_vlink_cmd, | |
3d1c6dc2 | 1056 | "area <A.B.C.D|(0-4294967295)> virtual-link A.B.C.D [authentication [<message-digest|null>]] [<message-digest-key (1-255) md5 KEY|authentication-key AUTH_KEY>]", |
7a7be519 | 1057 | VLINK_HELPSTR_IPADDR |
3d1c6dc2 | 1058 | "Enable authentication on this virtual link\n" |
7a7be519 | 1059 | "Use message-digest authentication\n" |
3d1c6dc2 | 1060 | "Use null authentication\n" |
baf9eaad CS |
1061 | VLINK_HELPSTR_AUTH_MD5 |
1062 | VLINK_HELPSTR_AUTH_SIMPLE) | |
718e3744 | 1063 | { |
a3d826f0 | 1064 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1065 | int idx_ipv4_number = 1; |
1066 | int idx_ipv4 = 3; | |
1067 | struct ospf_vl_config_data vl_config; | |
1068 | char auth_key[OSPF_AUTH_SIMPLE_SIZE + 1]; | |
1069 | char md5_key[OSPF_AUTH_MD5_SIZE + 1]; | |
d62a17ae | 1070 | int ret; |
55d1da24 | 1071 | int idx = 0; |
d62a17ae | 1072 | |
1073 | ospf_vl_config_data_init(&vl_config, vty); | |
1074 | ||
1075 | /* Read off first 2 parameters and check them */ | |
1076 | ret = str2area_id(argv[idx_ipv4_number]->arg, &vl_config.area_id, | |
1077 | &vl_config.area_id_fmt); | |
1078 | if (ret < 0) { | |
1079 | vty_out(vty, "OSPF area ID is invalid\n"); | |
1080 | return CMD_WARNING_CONFIG_FAILED; | |
1081 | } | |
718e3744 | 1082 | |
d62a17ae | 1083 | ret = inet_aton(argv[idx_ipv4]->arg, &vl_config.vl_peer); |
1084 | if (!ret) { | |
1085 | vty_out(vty, "Please specify valid Router ID as a.b.c.d\n"); | |
1086 | return CMD_WARNING_CONFIG_FAILED; | |
7a7be519 | 1087 | } |
7a7be519 | 1088 | |
d62a17ae | 1089 | if (argc <= 4) { |
1090 | /* Thats all folks! - BUGS B. strikes again!!!*/ | |
7a7be519 | 1091 | |
d62a17ae | 1092 | return ospf_vl_set(ospf, &vl_config); |
1093 | } | |
1094 | ||
3d1c6dc2 CS |
1095 | if (argv_find(argv, argc, "authentication", &idx)) { |
1096 | /* authentication - this option can only occur | |
1097 | at start of command line */ | |
1098 | vl_config.auth_type = OSPF_AUTH_SIMPLE; | |
1099 | } | |
1100 | ||
3d1c6dc2 | 1101 | if (argv_find(argv, argc, "message-digest", &idx)) { |
baf9eaad | 1102 | /* authentication message-digest */ |
3d1c6dc2 CS |
1103 | vl_config.auth_type = OSPF_AUTH_CRYPTOGRAPHIC; |
1104 | } else if (argv_find(argv, argc, "null", &idx)) { | |
1105 | /* "authentication null" */ | |
1106 | vl_config.auth_type = OSPF_AUTH_NULL; | |
d62a17ae | 1107 | } |
7a7be519 | 1108 | |
3d1c6dc2 | 1109 | if (argv_find(argv, argc, "message-digest-key", &idx)) { |
3d1c6dc2 | 1110 | vl_config.md5_key = NULL; |
cbb9b53d | 1111 | vl_config.crypto_key_id = strtol(argv[idx + 1]->arg, NULL, 10); |
3d1c6dc2 CS |
1112 | if (vl_config.crypto_key_id < 0) |
1113 | return CMD_WARNING_CONFIG_FAILED; | |
1114 | ||
4d65d927 | 1115 | strlcpy(md5_key, argv[idx + 3]->arg, sizeof(md5_key)); |
3d1c6dc2 CS |
1116 | vl_config.md5_key = md5_key; |
1117 | } | |
1118 | ||
3d1c6dc2 | 1119 | if (argv_find(argv, argc, "authentication-key", &idx)) { |
4d65d927 | 1120 | strlcpy(auth_key, argv[idx + 1]->arg, sizeof(auth_key)); |
3d1c6dc2 CS |
1121 | vl_config.auth_key = auth_key; |
1122 | } | |
7a7be519 | 1123 | |
d62a17ae | 1124 | /* Action configuration */ |
1125 | ||
1126 | return ospf_vl_set(ospf, &vl_config); | |
7a7be519 | 1127 | } |
1128 | ||
a2c62831 | 1129 | DEFUN (no_ospf_area_vlink, |
1130 | no_ospf_area_vlink_cmd, | |
3d1c6dc2 | 1131 | "no area <A.B.C.D|(0-4294967295)> virtual-link A.B.C.D [authentication [<message-digest|null>]] [<message-digest-key (1-255) md5 KEY|authentication-key AUTH_KEY>]", |
718e3744 | 1132 | NO_STR |
7a7be519 | 1133 | VLINK_HELPSTR_IPADDR |
7e5ee522 IR |
1134 | "Enable authentication on this virtual link\n" |
1135 | "Use message-digest authentication\n" | |
1136 | "Use null authentication\n" | |
baf9eaad CS |
1137 | VLINK_HELPSTR_AUTH_MD5 |
1138 | VLINK_HELPSTR_AUTH_SIMPLE) | |
718e3744 | 1139 | { |
a3d826f0 | 1140 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1141 | int idx_ipv4_number = 2; |
1142 | int idx_ipv4 = 4; | |
1143 | struct ospf_area *area; | |
1144 | struct ospf_vl_config_data vl_config; | |
1145 | struct ospf_vl_data *vl_data = NULL; | |
1146 | char auth_key[OSPF_AUTH_SIMPLE_SIZE + 1]; | |
3d1c6dc2 | 1147 | int idx = 0; |
d62a17ae | 1148 | int ret, format; |
1149 | ||
1150 | ospf_vl_config_data_init(&vl_config, vty); | |
1151 | ||
1152 | ret = str2area_id(argv[idx_ipv4_number]->arg, &vl_config.area_id, | |
1153 | &format); | |
1154 | if (ret < 0) { | |
1155 | vty_out(vty, "OSPF area ID is invalid\n"); | |
1156 | return CMD_WARNING_CONFIG_FAILED; | |
1157 | } | |
1158 | ||
1159 | area = ospf_area_lookup_by_area_id(ospf, vl_config.area_id); | |
1160 | if (!area) { | |
1161 | vty_out(vty, "Area does not exist\n"); | |
1162 | return CMD_WARNING_CONFIG_FAILED; | |
1163 | } | |
1164 | ||
1165 | ret = inet_aton(argv[idx_ipv4]->arg, &vl_config.vl_peer); | |
1166 | if (!ret) { | |
1167 | vty_out(vty, "Please specify valid Router ID as a.b.c.d\n"); | |
1168 | return CMD_WARNING_CONFIG_FAILED; | |
1169 | } | |
718e3744 | 1170 | |
188823b0 EDP |
1171 | vl_data = ospf_vl_lookup(ospf, area, vl_config.vl_peer); |
1172 | if (!vl_data) { | |
1173 | vty_out(vty, "Virtual link does not exist\n"); | |
1174 | return CMD_WARNING_CONFIG_FAILED; | |
1175 | } | |
1176 | ||
d62a17ae | 1177 | if (argc <= 5) { |
1178 | /* Basic VLink no command */ | |
1179 | /* Thats all folks! - BUGS B. strikes again!!!*/ | |
188823b0 | 1180 | ospf_vl_delete(ospf, vl_data); |
d62a17ae | 1181 | ospf_area_check_free(ospf, vl_config.area_id); |
d62a17ae | 1182 | return CMD_SUCCESS; |
1183 | } | |
1184 | ||
1185 | /* If we are down here, we are reseting parameters */ | |
d62a17ae | 1186 | /* Deal with other parameters */ |
3d1c6dc2 CS |
1187 | |
1188 | if (argv_find(argv, argc, "authentication", &idx)) { | |
1189 | /* authentication - this option can only occur | |
1190 | at start of command line */ | |
1191 | vl_config.auth_type = OSPF_AUTH_NOTSET; | |
1192 | } | |
1193 | ||
3d1c6dc2 | 1194 | if (argv_find(argv, argc, "message-digest-key", &idx)) { |
3d1c6dc2 | 1195 | vl_config.md5_key = NULL; |
cbb9b53d | 1196 | vl_config.crypto_key_id = strtol(argv[idx + 1]->arg, NULL, 10); |
3d1c6dc2 CS |
1197 | if (vl_config.crypto_key_id < 0) |
1198 | return CMD_WARNING_CONFIG_FAILED; | |
d62a17ae | 1199 | } |
1200 | ||
3d1c6dc2 | 1201 | if (argv_find(argv, argc, "authentication-key", &idx)) { |
cbb9b53d | 1202 | /* Reset authentication-key to 0 */ |
3d1c6dc2 CS |
1203 | memset(auth_key, 0, OSPF_AUTH_SIMPLE_SIZE + 1); |
1204 | vl_config.auth_key = auth_key; | |
1205 | } | |
d62a17ae | 1206 | |
1207 | /* Action configuration */ | |
1208 | ||
1209 | return ospf_vl_set(ospf, &vl_config); | |
7a7be519 | 1210 | } |
1211 | ||
b1c02cec QY |
1212 | DEFUN (ospf_area_vlink_intervals, |
1213 | ospf_area_vlink_intervals_cmd, | |
1214 | "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)}", | |
1215 | VLINK_HELPSTR_IPADDR | |
1216 | VLINK_HELPSTR_TIME_PARAM) | |
1217 | { | |
a3d826f0 | 1218 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1219 | struct ospf_vl_config_data vl_config; |
1220 | int ret = 0; | |
1221 | ||
1222 | ospf_vl_config_data_init(&vl_config, vty); | |
1223 | ||
1224 | char *area_id = argv[1]->arg; | |
1225 | char *router_id = argv[3]->arg; | |
1226 | ||
1227 | ret = str2area_id(area_id, &vl_config.area_id, &vl_config.area_id_fmt); | |
1228 | if (ret < 0) { | |
1229 | vty_out(vty, "OSPF area ID is invalid\n"); | |
1230 | return CMD_WARNING_CONFIG_FAILED; | |
1231 | } | |
1232 | ||
1233 | ret = inet_aton(router_id, &vl_config.vl_peer); | |
1234 | if (!ret) { | |
1235 | vty_out(vty, "Please specify valid Router ID as a.b.c.d\n"); | |
1236 | return CMD_WARNING_CONFIG_FAILED; | |
1237 | } | |
1238 | ||
1239 | for (int idx = 4; idx < argc; idx++) { | |
1240 | if (strmatch(argv[idx]->text, "hello-interval")) | |
1241 | vl_config.hello_interval = | |
1242 | strtol(argv[++idx]->arg, NULL, 10); | |
1243 | else if (strmatch(argv[idx]->text, "retransmit-interval")) | |
1244 | vl_config.retransmit_interval = | |
1245 | strtol(argv[++idx]->arg, NULL, 10); | |
1246 | else if (strmatch(argv[idx]->text, "transmit-delay")) | |
1247 | vl_config.transmit_delay = | |
1248 | strtol(argv[++idx]->arg, NULL, 10); | |
1249 | else if (strmatch(argv[idx]->text, "dead-interval")) | |
1250 | vl_config.dead_interval = | |
1251 | strtol(argv[++idx]->arg, NULL, 10); | |
1252 | } | |
1253 | ||
1254 | /* Action configuration */ | |
1255 | return ospf_vl_set(ospf, &vl_config); | |
b1c02cec QY |
1256 | } |
1257 | ||
7a7be519 | 1258 | DEFUN (no_ospf_area_vlink_intervals, |
1259 | no_ospf_area_vlink_intervals_cmd, | |
a663a38e | 1260 | "no area <A.B.C.D|(0-4294967295)> virtual-link A.B.C.D {hello-interval (1-65535)|retransmit-interval (1-65535)|transmit-delay (1-65535)|dead-interval (1-65535)}", |
3a2d747c | 1261 | NO_STR |
7a7be519 | 1262 | VLINK_HELPSTR_IPADDR |
7a7be519 | 1263 | VLINK_HELPSTR_TIME_PARAM) |
1264 | { | |
a3d826f0 | 1265 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1266 | struct ospf_vl_config_data vl_config; |
1267 | int ret = 0; | |
1268 | ||
1269 | ospf_vl_config_data_init(&vl_config, vty); | |
1270 | ||
1271 | char *area_id = argv[2]->arg; | |
1272 | char *router_id = argv[4]->arg; | |
1273 | ||
1274 | ret = str2area_id(area_id, &vl_config.area_id, &vl_config.area_id_fmt); | |
1275 | if (ret < 0) { | |
1276 | vty_out(vty, "OSPF area ID is invalid\n"); | |
1277 | return CMD_WARNING_CONFIG_FAILED; | |
1278 | } | |
1279 | ||
1280 | ret = inet_aton(router_id, &vl_config.vl_peer); | |
1281 | if (!ret) { | |
1282 | vty_out(vty, "Please specify valid Router ID as a.b.c.d\n"); | |
1283 | return CMD_WARNING_CONFIG_FAILED; | |
1284 | } | |
1285 | ||
1286 | for (int idx = 5; idx < argc; idx++) { | |
1287 | if (strmatch(argv[idx]->text, "hello-interval")) | |
1288 | vl_config.hello_interval = OSPF_HELLO_INTERVAL_DEFAULT; | |
1289 | else if (strmatch(argv[idx]->text, "retransmit-interval")) | |
1290 | vl_config.retransmit_interval = | |
1291 | OSPF_RETRANSMIT_INTERVAL_DEFAULT; | |
1292 | else if (strmatch(argv[idx]->text, "transmit-delay")) | |
1293 | vl_config.transmit_delay = OSPF_TRANSMIT_DELAY_DEFAULT; | |
1294 | else if (strmatch(argv[idx]->text, "dead-interval")) | |
1295 | vl_config.dead_interval = | |
1296 | OSPF_ROUTER_DEAD_INTERVAL_DEFAULT; | |
1297 | } | |
1298 | ||
1299 | /* Action configuration */ | |
1300 | return ospf_vl_set(ospf, &vl_config); | |
718e3744 | 1301 | } |
1302 | ||
a2c62831 | 1303 | DEFUN (ospf_area_shortcut, |
1304 | ospf_area_shortcut_cmd, | |
6147e2c6 | 1305 | "area <A.B.C.D|(0-4294967295)> shortcut <default|enable|disable>", |
718e3744 | 1306 | "OSPF area parameters\n" |
1307 | "OSPF area ID in IP address format\n" | |
1308 | "OSPF area ID as a decimal value\n" | |
1309 | "Configure the area's shortcutting mode\n" | |
1310 | "Set default shortcutting behavior\n" | |
1311 | "Enable shortcutting through the area\n" | |
1312 | "Disable shortcutting through the area\n") | |
1313 | { | |
a3d826f0 | 1314 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1315 | int idx_ipv4_number = 1; |
1316 | int idx_enable_disable = 3; | |
1317 | struct ospf_area *area; | |
1318 | struct in_addr area_id; | |
1319 | int mode; | |
1320 | int format; | |
1321 | ||
1322 | VTY_GET_OSPF_AREA_ID_NO_BB("shortcut", area_id, format, | |
1323 | argv[idx_ipv4_number]->arg); | |
1324 | ||
1325 | area = ospf_area_get(ospf, area_id); | |
1326 | ospf_area_display_format_set(ospf, area, format); | |
1327 | ||
1328 | if (strncmp(argv[idx_enable_disable]->arg, "de", 2) == 0) | |
1329 | mode = OSPF_SHORTCUT_DEFAULT; | |
1330 | else if (strncmp(argv[idx_enable_disable]->arg, "di", 2) == 0) | |
1331 | mode = OSPF_SHORTCUT_DISABLE; | |
1332 | else if (strncmp(argv[idx_enable_disable]->arg, "e", 1) == 0) | |
1333 | mode = OSPF_SHORTCUT_ENABLE; | |
1334 | else | |
1335 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 1336 | |
d62a17ae | 1337 | ospf_area_shortcut_set(ospf, area, mode); |
718e3744 | 1338 | |
d62a17ae | 1339 | if (ospf->abr_type != OSPF_ABR_SHORTCUT) |
1340 | vty_out(vty, | |
3efd0893 | 1341 | "Shortcut area setting will take effect only when the router is configured as Shortcut ABR\n"); |
718e3744 | 1342 | |
d62a17ae | 1343 | return CMD_SUCCESS; |
718e3744 | 1344 | } |
1345 | ||
a2c62831 | 1346 | DEFUN (no_ospf_area_shortcut, |
1347 | no_ospf_area_shortcut_cmd, | |
6147e2c6 | 1348 | "no area <A.B.C.D|(0-4294967295)> shortcut <enable|disable>", |
718e3744 | 1349 | NO_STR |
1350 | "OSPF area parameters\n" | |
1351 | "OSPF area ID in IP address format\n" | |
1352 | "OSPF area ID as a decimal value\n" | |
1353 | "Deconfigure the area's shortcutting mode\n" | |
1354 | "Deconfigure enabled shortcutting through the area\n" | |
1355 | "Deconfigure disabled shortcutting through the area\n") | |
1356 | { | |
a3d826f0 | 1357 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1358 | int idx_ipv4_number = 2; |
1359 | struct ospf_area *area; | |
1360 | struct in_addr area_id; | |
1361 | int format; | |
718e3744 | 1362 | |
d62a17ae | 1363 | VTY_GET_OSPF_AREA_ID_NO_BB("shortcut", area_id, format, |
1364 | argv[idx_ipv4_number]->arg); | |
718e3744 | 1365 | |
d62a17ae | 1366 | area = ospf_area_lookup_by_area_id(ospf, area_id); |
1367 | if (!area) | |
1368 | return CMD_SUCCESS; | |
718e3744 | 1369 | |
d62a17ae | 1370 | ospf_area_shortcut_unset(ospf, area); |
718e3744 | 1371 | |
d62a17ae | 1372 | return CMD_SUCCESS; |
718e3744 | 1373 | } |
1374 | ||
6b0655a2 | 1375 | |
a2c62831 | 1376 | DEFUN (ospf_area_stub, |
1377 | ospf_area_stub_cmd, | |
6147e2c6 | 1378 | "area <A.B.C.D|(0-4294967295)> stub", |
718e3744 | 1379 | "OSPF area parameters\n" |
1380 | "OSPF area ID in IP address format\n" | |
1381 | "OSPF area ID as a decimal value\n" | |
1382 | "Configure OSPF area as stub\n") | |
1383 | { | |
a3d826f0 | 1384 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1385 | int idx_ipv4_number = 1; |
1386 | struct in_addr area_id; | |
1387 | int ret, format; | |
1388 | ||
1389 | VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id, format, | |
1390 | argv[idx_ipv4_number]->arg); | |
1391 | ||
1392 | ret = ospf_area_stub_set(ospf, area_id); | |
1393 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
1394 | format); | |
1395 | if (ret == 0) { | |
1396 | vty_out(vty, | |
1397 | "First deconfigure all virtual link through this area\n"); | |
1398 | return CMD_WARNING_CONFIG_FAILED; | |
1399 | } | |
718e3744 | 1400 | |
44445dee S |
1401 | /* Flush the external LSAs from the specified area */ |
1402 | ospf_flush_lsa_from_area(ospf, area_id, OSPF_AS_EXTERNAL_LSA); | |
d62a17ae | 1403 | ospf_area_no_summary_unset(ospf, area_id); |
718e3744 | 1404 | |
d62a17ae | 1405 | return CMD_SUCCESS; |
718e3744 | 1406 | } |
1407 | ||
a2c62831 | 1408 | DEFUN (ospf_area_stub_no_summary, |
1409 | ospf_area_stub_no_summary_cmd, | |
6147e2c6 | 1410 | "area <A.B.C.D|(0-4294967295)> stub no-summary", |
718e3744 | 1411 | "OSPF stub parameters\n" |
1412 | "OSPF area ID in IP address format\n" | |
1413 | "OSPF area ID as a decimal value\n" | |
1414 | "Configure OSPF area as stub\n" | |
1415 | "Do not inject inter-area routes into stub\n") | |
1416 | { | |
a3d826f0 | 1417 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1418 | int idx_ipv4_number = 1; |
1419 | struct in_addr area_id; | |
1420 | int ret, format; | |
1421 | ||
1422 | VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id, format, | |
1423 | argv[idx_ipv4_number]->arg); | |
1424 | ||
1425 | ret = ospf_area_stub_set(ospf, area_id); | |
1426 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
1427 | format); | |
1428 | if (ret == 0) { | |
1429 | vty_out(vty, | |
1430 | "%% Area cannot be stub as it contains a virtual link\n"); | |
1431 | return CMD_WARNING_CONFIG_FAILED; | |
1432 | } | |
718e3744 | 1433 | |
d62a17ae | 1434 | ospf_area_no_summary_set(ospf, area_id); |
718e3744 | 1435 | |
d62a17ae | 1436 | return CMD_SUCCESS; |
718e3744 | 1437 | } |
1438 | ||
a2c62831 | 1439 | DEFUN (no_ospf_area_stub, |
1440 | no_ospf_area_stub_cmd, | |
6147e2c6 | 1441 | "no area <A.B.C.D|(0-4294967295)> stub", |
718e3744 | 1442 | NO_STR |
1443 | "OSPF area parameters\n" | |
1444 | "OSPF area ID in IP address format\n" | |
1445 | "OSPF area ID as a decimal value\n" | |
1446 | "Configure OSPF area as stub\n") | |
1447 | { | |
a3d826f0 | 1448 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1449 | int idx_ipv4_number = 2; |
1450 | struct in_addr area_id; | |
1451 | int format; | |
718e3744 | 1452 | |
d62a17ae | 1453 | VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id, format, |
1454 | argv[idx_ipv4_number]->arg); | |
718e3744 | 1455 | |
d62a17ae | 1456 | ospf_area_stub_unset(ospf, area_id); |
1457 | ospf_area_no_summary_unset(ospf, area_id); | |
718e3744 | 1458 | |
d62a17ae | 1459 | return CMD_SUCCESS; |
718e3744 | 1460 | } |
1461 | ||
a2c62831 | 1462 | DEFUN (no_ospf_area_stub_no_summary, |
1463 | no_ospf_area_stub_no_summary_cmd, | |
6147e2c6 | 1464 | "no area <A.B.C.D|(0-4294967295)> stub no-summary", |
718e3744 | 1465 | NO_STR |
1466 | "OSPF area parameters\n" | |
1467 | "OSPF area ID in IP address format\n" | |
1468 | "OSPF area ID as a decimal value\n" | |
1469 | "Configure OSPF area as stub\n" | |
1470 | "Do not inject inter-area routes into area\n") | |
1471 | { | |
a3d826f0 | 1472 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1473 | int idx_ipv4_number = 2; |
1474 | struct in_addr area_id; | |
1475 | int format; | |
718e3744 | 1476 | |
d62a17ae | 1477 | VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id, format, |
1478 | argv[idx_ipv4_number]->arg); | |
1479 | ospf_area_no_summary_unset(ospf, area_id); | |
718e3744 | 1480 | |
d62a17ae | 1481 | return CMD_SUCCESS; |
718e3744 | 1482 | } |
1483 | ||
d62a17ae | 1484 | static int ospf_area_nssa_cmd_handler(struct vty *vty, int argc, |
7ef56a73 CS |
1485 | struct cmd_token **argv, int cfg_nosum, |
1486 | int nosum) | |
718e3744 | 1487 | { |
a3d826f0 | 1488 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1489 | struct in_addr area_id; |
1490 | int ret, format; | |
1491 | ||
1492 | VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id, format, argv[1]->arg); | |
1493 | ||
1494 | ret = ospf_area_nssa_set(ospf, area_id); | |
1495 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
1496 | format); | |
1497 | if (ret == 0) { | |
1498 | vty_out(vty, | |
1499 | "%% Area cannot be nssa as it contains a virtual link\n"); | |
1500 | return CMD_WARNING_CONFIG_FAILED; | |
1501 | } | |
1502 | ||
1503 | if (argc > 3) { | |
1504 | if (strncmp(argv[3]->text, "translate-c", 11) == 0) | |
1505 | ospf_area_nssa_translator_role_set( | |
1506 | ospf, area_id, OSPF_NSSA_ROLE_CANDIDATE); | |
1507 | else if (strncmp(argv[3]->text, "translate-n", 11) == 0) | |
1508 | ospf_area_nssa_translator_role_set( | |
1509 | ospf, area_id, OSPF_NSSA_ROLE_NEVER); | |
1510 | else if (strncmp(argv[3]->text, "translate-a", 11) == 0) | |
1511 | ospf_area_nssa_translator_role_set( | |
1512 | ospf, area_id, OSPF_NSSA_ROLE_ALWAYS); | |
1513 | } else { | |
1514 | ospf_area_nssa_translator_role_set(ospf, area_id, | |
1515 | OSPF_NSSA_ROLE_CANDIDATE); | |
1516 | } | |
1517 | ||
7ef56a73 CS |
1518 | if (cfg_nosum) { |
1519 | if (nosum) | |
1520 | ospf_area_no_summary_set(ospf, area_id); | |
1521 | else | |
1522 | ospf_area_no_summary_unset(ospf, area_id); | |
1523 | } | |
d62a17ae | 1524 | |
44445dee S |
1525 | /* Flush the external LSA for the specified area */ |
1526 | ospf_flush_lsa_from_area(ospf, area_id, OSPF_AS_EXTERNAL_LSA); | |
d62a17ae | 1527 | ospf_schedule_abr_task(ospf); |
1c1c342d | 1528 | ospf_schedule_asbr_nssa_redist_update(ospf); |
d62a17ae | 1529 | |
1530 | return CMD_SUCCESS; | |
718e3744 | 1531 | } |
1532 | ||
718e3744 | 1533 | |
b0a053be | 1534 | DEFUN (ospf_area_nssa_translate, |
a2c62831 | 1535 | ospf_area_nssa_translate_cmd, |
6147e2c6 | 1536 | "area <A.B.C.D|(0-4294967295)> nssa <translate-candidate|translate-never|translate-always>", |
718e3744 | 1537 | "OSPF area parameters\n" |
1538 | "OSPF area ID in IP address format\n" | |
1539 | "OSPF area ID as a decimal value\n" | |
1540 | "Configure OSPF area as nssa\n" | |
1541 | "Configure NSSA-ABR for translate election (default)\n" | |
1542 | "Configure NSSA-ABR to never translate\n" | |
1543 | "Configure NSSA-ABR to always translate\n") | |
b0a053be | 1544 | { |
7ef56a73 | 1545 | return ospf_area_nssa_cmd_handler(vty, argc, argv, 0, 0); |
b0a053be | 1546 | } |
1547 | ||
1548 | DEFUN (ospf_area_nssa, | |
1549 | ospf_area_nssa_cmd, | |
6147e2c6 | 1550 | "area <A.B.C.D|(0-4294967295)> nssa", |
b0a053be | 1551 | "OSPF area parameters\n" |
1552 | "OSPF area ID in IP address format\n" | |
1553 | "OSPF area ID as a decimal value\n" | |
1554 | "Configure OSPF area as nssa\n") | |
1555 | { | |
2643b2bc | 1556 | return ospf_area_nssa_cmd_handler(vty, argc, argv, 0, 0); |
b0a053be | 1557 | } |
718e3744 | 1558 | |
c317eddb | 1559 | DEFUN(ospf_area_nssa_suppress_fa, ospf_area_nssa_suppress_fa_cmd, |
1560 | "area <A.B.C.D|(0-4294967295)> nssa suppress-fa", | |
1561 | "OSPF area parameters\n" | |
1562 | "OSPF area ID in IP address format\n" | |
1563 | "OSPF area ID as a decimal value\n" | |
1564 | "Configure OSPF area as nssa\n" | |
1565 | "Suppress forwarding address\n") | |
1566 | { | |
1567 | int idx_ipv4_number = 1; | |
1568 | struct in_addr area_id; | |
1569 | int format; | |
1570 | ||
1571 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
1572 | VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id, format, | |
1573 | argv[idx_ipv4_number]->arg); | |
1574 | ||
1575 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
1576 | format); | |
1577 | ospf_area_nssa_suppress_fa_set(ospf, area_id); | |
1578 | ||
1579 | ospf_schedule_abr_task(ospf); | |
1580 | ||
1581 | return CMD_SUCCESS; | |
1582 | } | |
1583 | ||
1584 | DEFUN(no_ospf_area_nssa_suppress_fa, no_ospf_area_nssa_suppress_fa_cmd, | |
1585 | "no area <A.B.C.D|(0-4294967295)> nssa suppress-fa", | |
1586 | NO_STR | |
1587 | "OSPF area parameters\n" | |
1588 | "OSPF area ID in IP address format\n" | |
1589 | "OSPF area ID as a decimal value\n" | |
1590 | "Configure OSPF area as nssa\n" | |
1591 | "Suppress forwarding address\n") | |
1592 | { | |
1593 | int idx_ipv4_number = 2; | |
1594 | struct in_addr area_id; | |
1595 | int format; | |
1596 | ||
1597 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
1598 | ||
1599 | VTY_GET_OSPF_AREA_ID_NO_BB("nssa", area_id, format, | |
1600 | argv[idx_ipv4_number]->arg); | |
1601 | ||
1602 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
1603 | format); | |
1604 | ospf_area_nssa_suppress_fa_unset(ospf, area_id); | |
1605 | ||
1606 | ospf_schedule_abr_task(ospf); | |
1607 | ||
1608 | return CMD_SUCCESS; | |
1609 | } | |
1610 | ||
a2c62831 | 1611 | DEFUN (ospf_area_nssa_no_summary, |
1612 | ospf_area_nssa_no_summary_cmd, | |
6147e2c6 | 1613 | "area <A.B.C.D|(0-4294967295)> nssa no-summary", |
718e3744 | 1614 | "OSPF area parameters\n" |
1615 | "OSPF area ID in IP address format\n" | |
1616 | "OSPF area ID as a decimal value\n" | |
1617 | "Configure OSPF area as nssa\n" | |
1618 | "Do not inject inter-area routes into nssa\n") | |
1619 | { | |
7ef56a73 CS |
1620 | int idx_ipv4_number = 1; |
1621 | struct in_addr area_id; | |
1622 | int format; | |
1623 | ||
1624 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
1625 | VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id, format, | |
1626 | argv[idx_ipv4_number]->arg); | |
1627 | ||
1628 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
1629 | format); | |
1630 | ospf_area_nssa_no_summary_set(ospf, area_id); | |
1631 | ||
1632 | ospf_schedule_abr_task(ospf); | |
1633 | ||
1634 | return CMD_SUCCESS; | |
1635 | } | |
1636 | ||
1637 | DEFUN (no_ospf_area_nssa_no_summary, | |
1638 | no_ospf_area_nssa_no_summary_cmd, | |
1639 | "no area <A.B.C.D|(0-4294967295)> nssa no-summary", | |
1640 | NO_STR | |
1641 | "OSPF area parameters\n" | |
1642 | "OSPF area ID in IP address format\n" | |
1643 | "OSPF area ID as a decimal value\n" | |
1644 | "Configure OSPF area as nssa\n" | |
1645 | "Do not inject inter-area routes into nssa\n") | |
1646 | { | |
1647 | int idx_ipv4_number = 2; | |
1648 | struct in_addr area_id; | |
1649 | int format; | |
1650 | ||
1651 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
1652 | ||
1653 | VTY_GET_OSPF_AREA_ID_NO_BB("nssa", area_id, format, | |
1654 | argv[idx_ipv4_number]->arg); | |
1655 | ||
1656 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
1657 | format); | |
1658 | ospf_area_no_summary_unset(ospf, area_id); | |
1659 | ||
1660 | ospf_schedule_abr_task(ospf); | |
1661 | ||
1662 | return CMD_SUCCESS; | |
718e3744 | 1663 | } |
1664 | ||
a2c62831 | 1665 | DEFUN (no_ospf_area_nssa, |
1666 | no_ospf_area_nssa_cmd, | |
7ef56a73 | 1667 | "no area <A.B.C.D|(0-4294967295)> nssa [<translate-candidate|translate-never|translate-always>]", |
718e3744 | 1668 | NO_STR |
1669 | "OSPF area parameters\n" | |
1670 | "OSPF area ID in IP address format\n" | |
1671 | "OSPF area ID as a decimal value\n" | |
7a7be519 | 1672 | "Configure OSPF area as nssa\n" |
1673 | "Configure NSSA-ABR for translate election (default)\n" | |
1674 | "Configure NSSA-ABR to never translate\n" | |
7ef56a73 | 1675 | "Configure NSSA-ABR to always translate\n") |
22b27e95 | 1676 | { |
a3d826f0 | 1677 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1678 | int idx_ipv4_number = 2; |
1679 | struct in_addr area_id; | |
1680 | int format; | |
718e3744 | 1681 | |
d62a17ae | 1682 | VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id, format, |
1683 | argv[idx_ipv4_number]->arg); | |
718e3744 | 1684 | |
44445dee S |
1685 | /* Flush the NSSA LSA for the specified area */ |
1686 | ospf_flush_lsa_from_area(ospf, area_id, OSPF_AS_NSSA_LSA); | |
7ef56a73 | 1687 | ospf_area_nssa_unset(ospf, area_id, argc); |
718e3744 | 1688 | |
d62a17ae | 1689 | ospf_schedule_abr_task(ospf); |
b0a053be | 1690 | |
d62a17ae | 1691 | return CMD_SUCCESS; |
718e3744 | 1692 | } |
1693 | ||
718e3744 | 1694 | |
a2c62831 | 1695 | DEFUN (ospf_area_default_cost, |
1696 | ospf_area_default_cost_cmd, | |
6147e2c6 | 1697 | "area <A.B.C.D|(0-4294967295)> default-cost (0-16777215)", |
718e3744 | 1698 | "OSPF area parameters\n" |
1699 | "OSPF area ID in IP address format\n" | |
1700 | "OSPF area ID as a decimal value\n" | |
1701 | "Set the summary-default cost of a NSSA or stub area\n" | |
1702 | "Stub's advertised default summary cost\n") | |
1703 | { | |
a3d826f0 | 1704 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1705 | int idx_ipv4_number = 1; |
1706 | int idx_number = 3; | |
1707 | struct ospf_area *area; | |
1708 | struct in_addr area_id; | |
d7c0a89a | 1709 | uint32_t cost; |
d62a17ae | 1710 | int format; |
1711 | struct prefix_ipv4 p; | |
1712 | ||
1713 | VTY_GET_OSPF_AREA_ID_NO_BB("default-cost", area_id, format, | |
1714 | argv[idx_ipv4_number]->arg); | |
1715 | cost = strtoul(argv[idx_number]->arg, NULL, 10); | |
1716 | ||
1717 | area = ospf_area_get(ospf, area_id); | |
1718 | ospf_area_display_format_set(ospf, area, format); | |
1719 | ||
1720 | if (area->external_routing == OSPF_AREA_DEFAULT) { | |
1721 | vty_out(vty, "The area is neither stub, nor NSSA\n"); | |
1722 | return CMD_WARNING_CONFIG_FAILED; | |
1723 | } | |
ba682537 | 1724 | |
d62a17ae | 1725 | area->default_cost = cost; |
1726 | ||
1727 | p.family = AF_INET; | |
1728 | p.prefix.s_addr = OSPF_DEFAULT_DESTINATION; | |
1729 | p.prefixlen = 0; | |
1730 | if (IS_DEBUG_OSPF_EVENT) | |
1731 | zlog_debug( | |
96b663a3 MS |
1732 | "ospf_abr_announce_stub_defaults(): announcing 0.0.0.0/0 to area %pI4", |
1733 | &area->area_id); | |
d62a17ae | 1734 | ospf_abr_announce_network_to_area(&p, area->default_cost, area); |
1735 | ||
1736 | return CMD_SUCCESS; | |
718e3744 | 1737 | } |
1738 | ||
a2c62831 | 1739 | DEFUN (no_ospf_area_default_cost, |
1740 | no_ospf_area_default_cost_cmd, | |
6147e2c6 | 1741 | "no area <A.B.C.D|(0-4294967295)> default-cost (0-16777215)", |
718e3744 | 1742 | NO_STR |
1743 | "OSPF area parameters\n" | |
1744 | "OSPF area ID in IP address format\n" | |
1745 | "OSPF area ID as a decimal value\n" | |
1746 | "Set the summary-default cost of a NSSA or stub area\n" | |
1747 | "Stub's advertised default summary cost\n") | |
1748 | { | |
a3d826f0 | 1749 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1750 | int idx_ipv4_number = 2; |
1751 | struct ospf_area *area; | |
1752 | struct in_addr area_id; | |
1753 | int format; | |
1754 | struct prefix_ipv4 p; | |
718e3744 | 1755 | |
d62a17ae | 1756 | VTY_GET_OSPF_AREA_ID_NO_BB("default-cost", area_id, format, |
1757 | argv[idx_ipv4_number]->arg); | |
718e3744 | 1758 | |
d62a17ae | 1759 | area = ospf_area_lookup_by_area_id(ospf, area_id); |
1760 | if (area == NULL) | |
1761 | return CMD_SUCCESS; | |
718e3744 | 1762 | |
d62a17ae | 1763 | if (area->external_routing == OSPF_AREA_DEFAULT) { |
1764 | vty_out(vty, "The area is neither stub, nor NSSA\n"); | |
1765 | return CMD_WARNING_CONFIG_FAILED; | |
1766 | } | |
718e3744 | 1767 | |
d62a17ae | 1768 | area->default_cost = 1; |
718e3744 | 1769 | |
d62a17ae | 1770 | p.family = AF_INET; |
1771 | p.prefix.s_addr = OSPF_DEFAULT_DESTINATION; | |
1772 | p.prefixlen = 0; | |
1773 | if (IS_DEBUG_OSPF_EVENT) | |
1774 | zlog_debug( | |
96b663a3 MS |
1775 | "ospf_abr_announce_stub_defaults(): announcing 0.0.0.0/0 to area %pI4", |
1776 | &area->area_id); | |
d62a17ae | 1777 | ospf_abr_announce_network_to_area(&p, area->default_cost, area); |
ba682537 | 1778 | |
1779 | ||
d62a17ae | 1780 | ospf_area_check_free(ospf, area_id); |
718e3744 | 1781 | |
d62a17ae | 1782 | return CMD_SUCCESS; |
718e3744 | 1783 | } |
1784 | ||
a2c62831 | 1785 | DEFUN (ospf_area_export_list, |
1786 | ospf_area_export_list_cmd, | |
6147e2c6 | 1787 | "area <A.B.C.D|(0-4294967295)> export-list NAME", |
718e3744 | 1788 | "OSPF area parameters\n" |
1789 | "OSPF area ID in IP address format\n" | |
1790 | "OSPF area ID as a decimal value\n" | |
1791 | "Set the filter for networks announced to other areas\n" | |
1792 | "Name of the access-list\n") | |
1793 | { | |
a3d826f0 | 1794 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1795 | int idx_ipv4_number = 1; |
1796 | struct ospf_area *area; | |
1797 | struct in_addr area_id; | |
1798 | int format; | |
718e3744 | 1799 | |
d62a17ae | 1800 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
52930766 | 1801 | |
d62a17ae | 1802 | area = ospf_area_get(ospf, area_id); |
1803 | ospf_area_display_format_set(ospf, area, format); | |
1804 | ospf_area_export_list_set(ospf, area, argv[3]->arg); | |
718e3744 | 1805 | |
d62a17ae | 1806 | return CMD_SUCCESS; |
718e3744 | 1807 | } |
1808 | ||
a2c62831 | 1809 | DEFUN (no_ospf_area_export_list, |
1810 | no_ospf_area_export_list_cmd, | |
6147e2c6 | 1811 | "no area <A.B.C.D|(0-4294967295)> export-list NAME", |
718e3744 | 1812 | NO_STR |
1813 | "OSPF area parameters\n" | |
1814 | "OSPF area ID in IP address format\n" | |
1815 | "OSPF area ID as a decimal value\n" | |
1816 | "Unset the filter for networks announced to other areas\n" | |
1817 | "Name of the access-list\n") | |
1818 | { | |
a3d826f0 | 1819 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1820 | int idx_ipv4_number = 2; |
1821 | struct ospf_area *area; | |
1822 | struct in_addr area_id; | |
1823 | int format; | |
718e3744 | 1824 | |
d62a17ae | 1825 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
52930766 | 1826 | |
d62a17ae | 1827 | area = ospf_area_lookup_by_area_id(ospf, area_id); |
1828 | if (area == NULL) | |
1829 | return CMD_SUCCESS; | |
718e3744 | 1830 | |
d62a17ae | 1831 | ospf_area_export_list_unset(ospf, area); |
718e3744 | 1832 | |
d62a17ae | 1833 | return CMD_SUCCESS; |
718e3744 | 1834 | } |
1835 | ||
1836 | ||
a2c62831 | 1837 | DEFUN (ospf_area_import_list, |
1838 | ospf_area_import_list_cmd, | |
6147e2c6 | 1839 | "area <A.B.C.D|(0-4294967295)> import-list NAME", |
718e3744 | 1840 | "OSPF area parameters\n" |
1841 | "OSPF area ID in IP address format\n" | |
1842 | "OSPF area ID as a decimal value\n" | |
1843 | "Set the filter for networks from other areas announced to the specified one\n" | |
1844 | "Name of the access-list\n") | |
1845 | { | |
a3d826f0 | 1846 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1847 | int idx_ipv4_number = 1; |
1848 | struct ospf_area *area; | |
1849 | struct in_addr area_id; | |
1850 | int format; | |
718e3744 | 1851 | |
d62a17ae | 1852 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
52930766 | 1853 | |
d62a17ae | 1854 | area = ospf_area_get(ospf, area_id); |
1855 | ospf_area_display_format_set(ospf, area, format); | |
1856 | ospf_area_import_list_set(ospf, area, argv[3]->arg); | |
718e3744 | 1857 | |
d62a17ae | 1858 | return CMD_SUCCESS; |
718e3744 | 1859 | } |
1860 | ||
a2c62831 | 1861 | DEFUN (no_ospf_area_import_list, |
1862 | no_ospf_area_import_list_cmd, | |
6147e2c6 | 1863 | "no area <A.B.C.D|(0-4294967295)> import-list NAME", |
718e3744 | 1864 | NO_STR |
1865 | "OSPF area parameters\n" | |
1866 | "OSPF area ID in IP address format\n" | |
1867 | "OSPF area ID as a decimal value\n" | |
1868 | "Unset the filter for networks announced to other areas\n" | |
1869 | "Name of the access-list\n") | |
1870 | { | |
a3d826f0 | 1871 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1872 | int idx_ipv4_number = 2; |
1873 | struct ospf_area *area; | |
1874 | struct in_addr area_id; | |
1875 | int format; | |
718e3744 | 1876 | |
d62a17ae | 1877 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
52930766 | 1878 | |
d62a17ae | 1879 | area = ospf_area_lookup_by_area_id(ospf, area_id); |
1880 | if (area == NULL) | |
1881 | return CMD_SUCCESS; | |
718e3744 | 1882 | |
d62a17ae | 1883 | ospf_area_import_list_unset(ospf, area); |
718e3744 | 1884 | |
d62a17ae | 1885 | return CMD_SUCCESS; |
718e3744 | 1886 | } |
1887 | ||
a2c62831 | 1888 | DEFUN (ospf_area_filter_list, |
1889 | ospf_area_filter_list_cmd, | |
6147e2c6 | 1890 | "area <A.B.C.D|(0-4294967295)> filter-list prefix WORD <in|out>", |
718e3744 | 1891 | "OSPF area parameters\n" |
1892 | "OSPF area ID in IP address format\n" | |
1893 | "OSPF area ID as a decimal value\n" | |
1894 | "Filter networks between OSPF areas\n" | |
1895 | "Filter prefixes between OSPF areas\n" | |
1896 | "Name of an IP prefix-list\n" | |
1897 | "Filter networks sent to this area\n" | |
1898 | "Filter networks sent from this area\n") | |
1899 | { | |
a3d826f0 | 1900 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1901 | int idx_ipv4_number = 1; |
1902 | int idx_word = 4; | |
1903 | int idx_in_out = 5; | |
1904 | struct ospf_area *area; | |
1905 | struct in_addr area_id; | |
1906 | struct prefix_list *plist; | |
1907 | int format; | |
1908 | ||
1909 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); | |
1910 | ||
1911 | area = ospf_area_get(ospf, area_id); | |
1912 | ospf_area_display_format_set(ospf, area, format); | |
1913 | plist = prefix_list_lookup(AFI_IP, argv[idx_word]->arg); | |
1914 | if (strncmp(argv[idx_in_out]->arg, "in", 2) == 0) { | |
1915 | PREFIX_LIST_IN(area) = plist; | |
1916 | if (PREFIX_NAME_IN(area)) | |
1917 | free(PREFIX_NAME_IN(area)); | |
1918 | ||
1919 | PREFIX_NAME_IN(area) = strdup(argv[idx_word]->arg); | |
1920 | ospf_schedule_abr_task(ospf); | |
1921 | } else { | |
1922 | PREFIX_LIST_OUT(area) = plist; | |
1923 | if (PREFIX_NAME_OUT(area)) | |
1924 | free(PREFIX_NAME_OUT(area)); | |
1925 | ||
1926 | PREFIX_NAME_OUT(area) = strdup(argv[idx_word]->arg); | |
1927 | ospf_schedule_abr_task(ospf); | |
1928 | } | |
718e3744 | 1929 | |
d62a17ae | 1930 | return CMD_SUCCESS; |
718e3744 | 1931 | } |
1932 | ||
a2c62831 | 1933 | DEFUN (no_ospf_area_filter_list, |
1934 | no_ospf_area_filter_list_cmd, | |
6147e2c6 | 1935 | "no area <A.B.C.D|(0-4294967295)> filter-list prefix WORD <in|out>", |
718e3744 | 1936 | NO_STR |
1937 | "OSPF area parameters\n" | |
1938 | "OSPF area ID in IP address format\n" | |
1939 | "OSPF area ID as a decimal value\n" | |
1940 | "Filter networks between OSPF areas\n" | |
1941 | "Filter prefixes between OSPF areas\n" | |
1942 | "Name of an IP prefix-list\n" | |
1943 | "Filter networks sent to this area\n" | |
1944 | "Filter networks sent from this area\n") | |
1945 | { | |
a3d826f0 | 1946 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1947 | int idx_ipv4_number = 2; |
1948 | int idx_word = 5; | |
1949 | int idx_in_out = 6; | |
1950 | struct ospf_area *area; | |
1951 | struct in_addr area_id; | |
1952 | int format; | |
718e3744 | 1953 | |
d62a17ae | 1954 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
718e3744 | 1955 | |
d62a17ae | 1956 | if ((area = ospf_area_lookup_by_area_id(ospf, area_id)) == NULL) |
1957 | return CMD_SUCCESS; | |
718e3744 | 1958 | |
d62a17ae | 1959 | if (strncmp(argv[idx_in_out]->arg, "in", 2) == 0) { |
1960 | if (PREFIX_NAME_IN(area)) | |
1961 | if (strcmp(PREFIX_NAME_IN(area), argv[idx_word]->arg) | |
1962 | != 0) | |
1963 | return CMD_SUCCESS; | |
718e3744 | 1964 | |
d62a17ae | 1965 | PREFIX_LIST_IN(area) = NULL; |
1966 | if (PREFIX_NAME_IN(area)) | |
1967 | free(PREFIX_NAME_IN(area)); | |
718e3744 | 1968 | |
d62a17ae | 1969 | PREFIX_NAME_IN(area) = NULL; |
718e3744 | 1970 | |
d62a17ae | 1971 | ospf_schedule_abr_task(ospf); |
1972 | } else { | |
1973 | if (PREFIX_NAME_OUT(area)) | |
1974 | if (strcmp(PREFIX_NAME_OUT(area), argv[idx_word]->arg) | |
1975 | != 0) | |
1976 | return CMD_SUCCESS; | |
718e3744 | 1977 | |
d62a17ae | 1978 | PREFIX_LIST_OUT(area) = NULL; |
1979 | if (PREFIX_NAME_OUT(area)) | |
1980 | free(PREFIX_NAME_OUT(area)); | |
718e3744 | 1981 | |
d62a17ae | 1982 | PREFIX_NAME_OUT(area) = NULL; |
718e3744 | 1983 | |
d62a17ae | 1984 | ospf_schedule_abr_task(ospf); |
1985 | } | |
1986 | ||
1987 | return CMD_SUCCESS; | |
718e3744 | 1988 | } |
1989 | ||
6b0655a2 | 1990 | |
a2c62831 | 1991 | DEFUN (ospf_area_authentication_message_digest, |
1992 | ospf_area_authentication_message_digest_cmd, | |
32573073 QY |
1993 | "[no] area <A.B.C.D|(0-4294967295)> authentication message-digest", |
1994 | NO_STR | |
718e3744 | 1995 | "OSPF area parameters\n" |
2b00515a CF |
1996 | "OSPF area ID in IP address format\n" |
1997 | "OSPF area ID as a decimal value\n" | |
718e3744 | 1998 | "Enable authentication\n" |
1999 | "Use message-digest authentication\n") | |
2000 | { | |
a3d826f0 | 2001 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
ca19319b | 2002 | int idx = 0; |
d62a17ae | 2003 | struct ospf_area *area; |
2004 | struct in_addr area_id; | |
2005 | int format; | |
718e3744 | 2006 | |
ca19319b | 2007 | argv_find(argv, argc, "area", &idx); |
2008 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx + 1]->arg); | |
718e3744 | 2009 | |
d62a17ae | 2010 | area = ospf_area_get(ospf, area_id); |
2011 | ospf_area_display_format_set(ospf, area, format); | |
996c9314 LB |
2012 | area->auth_type = strmatch(argv[0]->text, "no") |
2013 | ? OSPF_AUTH_NULL | |
2014 | : OSPF_AUTH_CRYPTOGRAPHIC; | |
718e3744 | 2015 | |
d62a17ae | 2016 | return CMD_SUCCESS; |
718e3744 | 2017 | } |
2018 | ||
a2c62831 | 2019 | DEFUN (ospf_area_authentication, |
2020 | ospf_area_authentication_cmd, | |
6147e2c6 | 2021 | "area <A.B.C.D|(0-4294967295)> authentication", |
718e3744 | 2022 | "OSPF area parameters\n" |
2023 | "OSPF area ID in IP address format\n" | |
2024 | "OSPF area ID as a decimal value\n" | |
2025 | "Enable authentication\n") | |
2026 | { | |
a3d826f0 | 2027 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2028 | int idx_ipv4_number = 1; |
2029 | struct ospf_area *area; | |
2030 | struct in_addr area_id; | |
2031 | int format; | |
718e3744 | 2032 | |
d62a17ae | 2033 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
718e3744 | 2034 | |
d62a17ae | 2035 | area = ospf_area_get(ospf, area_id); |
2036 | ospf_area_display_format_set(ospf, area, format); | |
2037 | area->auth_type = OSPF_AUTH_SIMPLE; | |
718e3744 | 2038 | |
d62a17ae | 2039 | return CMD_SUCCESS; |
718e3744 | 2040 | } |
2041 | ||
a2c62831 | 2042 | DEFUN (no_ospf_area_authentication, |
2043 | no_ospf_area_authentication_cmd, | |
6147e2c6 | 2044 | "no area <A.B.C.D|(0-4294967295)> authentication", |
718e3744 | 2045 | NO_STR |
2046 | "OSPF area parameters\n" | |
2047 | "OSPF area ID in IP address format\n" | |
2048 | "OSPF area ID as a decimal value\n" | |
2049 | "Enable authentication\n") | |
2050 | { | |
a3d826f0 | 2051 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2052 | int idx_ipv4_number = 2; |
2053 | struct ospf_area *area; | |
2054 | struct in_addr area_id; | |
2055 | int format; | |
718e3744 | 2056 | |
d62a17ae | 2057 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
718e3744 | 2058 | |
d62a17ae | 2059 | area = ospf_area_lookup_by_area_id(ospf, area_id); |
2060 | if (area == NULL) | |
2061 | return CMD_SUCCESS; | |
718e3744 | 2062 | |
d62a17ae | 2063 | area->auth_type = OSPF_AUTH_NULL; |
718e3744 | 2064 | |
d62a17ae | 2065 | ospf_area_check_free(ospf, area_id); |
2066 | ||
2067 | return CMD_SUCCESS; | |
718e3744 | 2068 | } |
2069 | ||
6b0655a2 | 2070 | |
718e3744 | 2071 | DEFUN (ospf_abr_type, |
2072 | ospf_abr_type_cmd, | |
6147e2c6 | 2073 | "ospf abr-type <cisco|ibm|shortcut|standard>", |
718e3744 | 2074 | "OSPF specific commands\n" |
2075 | "Set OSPF ABR type\n" | |
2076 | "Alternative ABR, cisco implementation\n" | |
2077 | "Alternative ABR, IBM implementation\n" | |
2078 | "Shortcut ABR\n" | |
2079 | "Standard behavior (RFC2328)\n") | |
2080 | { | |
a3d826f0 | 2081 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2082 | int idx_vendor = 2; |
d7c0a89a | 2083 | uint8_t abr_type = OSPF_ABR_UNKNOWN; |
d62a17ae | 2084 | |
2085 | if (strncmp(argv[idx_vendor]->arg, "c", 1) == 0) | |
2086 | abr_type = OSPF_ABR_CISCO; | |
2087 | else if (strncmp(argv[idx_vendor]->arg, "i", 1) == 0) | |
2088 | abr_type = OSPF_ABR_IBM; | |
2089 | else if (strncmp(argv[idx_vendor]->arg, "sh", 2) == 0) | |
2090 | abr_type = OSPF_ABR_SHORTCUT; | |
2091 | else if (strncmp(argv[idx_vendor]->arg, "st", 2) == 0) | |
2092 | abr_type = OSPF_ABR_STAND; | |
2093 | else | |
2094 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 2095 | |
d62a17ae | 2096 | /* If ABR type value is changed, schedule ABR task. */ |
2097 | if (ospf->abr_type != abr_type) { | |
2098 | ospf->abr_type = abr_type; | |
2099 | ospf_schedule_abr_task(ospf); | |
2100 | } | |
2101 | ||
2102 | return CMD_SUCCESS; | |
718e3744 | 2103 | } |
2104 | ||
2105 | DEFUN (no_ospf_abr_type, | |
2106 | no_ospf_abr_type_cmd, | |
6147e2c6 | 2107 | "no ospf abr-type <cisco|ibm|shortcut|standard>", |
718e3744 | 2108 | NO_STR |
2109 | "OSPF specific commands\n" | |
2110 | "Set OSPF ABR type\n" | |
2111 | "Alternative ABR, cisco implementation\n" | |
2112 | "Alternative ABR, IBM implementation\n" | |
3a2d747c QY |
2113 | "Shortcut ABR\n" |
2114 | "Standard ABR\n") | |
718e3744 | 2115 | { |
a3d826f0 | 2116 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2117 | int idx_vendor = 3; |
d7c0a89a | 2118 | uint8_t abr_type = OSPF_ABR_UNKNOWN; |
d62a17ae | 2119 | |
2120 | if (strncmp(argv[idx_vendor]->arg, "c", 1) == 0) | |
2121 | abr_type = OSPF_ABR_CISCO; | |
2122 | else if (strncmp(argv[idx_vendor]->arg, "i", 1) == 0) | |
2123 | abr_type = OSPF_ABR_IBM; | |
2124 | else if (strncmp(argv[idx_vendor]->arg, "sh", 2) == 0) | |
2125 | abr_type = OSPF_ABR_SHORTCUT; | |
2126 | else if (strncmp(argv[idx_vendor]->arg, "st", 2) == 0) | |
2127 | abr_type = OSPF_ABR_STAND; | |
2128 | else | |
2129 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 2130 | |
d62a17ae | 2131 | /* If ABR type value is changed, schedule ABR task. */ |
2132 | if (ospf->abr_type == abr_type) { | |
2133 | ospf->abr_type = OSPF_ABR_DEFAULT; | |
2134 | ospf_schedule_abr_task(ospf); | |
2135 | } | |
2136 | ||
2137 | return CMD_SUCCESS; | |
718e3744 | 2138 | } |
2139 | ||
d7e60dd7 AS |
2140 | DEFUN (ospf_log_adjacency_changes, |
2141 | ospf_log_adjacency_changes_cmd, | |
2142 | "log-adjacency-changes", | |
2143 | "Log changes in adjacency state\n") | |
2144 | { | |
a3d826f0 | 2145 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d7e60dd7 | 2146 | |
d62a17ae | 2147 | SET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES); |
2148 | UNSET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL); | |
2149 | return CMD_SUCCESS; | |
d7e60dd7 AS |
2150 | } |
2151 | ||
2152 | DEFUN (ospf_log_adjacency_changes_detail, | |
2153 | ospf_log_adjacency_changes_detail_cmd, | |
2154 | "log-adjacency-changes detail", | |
2155 | "Log changes in adjacency state\n" | |
2156 | "Log all state changes\n") | |
2157 | { | |
a3d826f0 | 2158 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d7e60dd7 | 2159 | |
d62a17ae | 2160 | SET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES); |
2161 | SET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL); | |
2162 | return CMD_SUCCESS; | |
d7e60dd7 AS |
2163 | } |
2164 | ||
2165 | DEFUN (no_ospf_log_adjacency_changes, | |
2166 | no_ospf_log_adjacency_changes_cmd, | |
2167 | "no log-adjacency-changes", | |
2168 | NO_STR | |
2169 | "Log changes in adjacency state\n") | |
2170 | { | |
a3d826f0 | 2171 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d7e60dd7 | 2172 | |
d62a17ae | 2173 | UNSET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL); |
2174 | UNSET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES); | |
2175 | return CMD_SUCCESS; | |
d7e60dd7 AS |
2176 | } |
2177 | ||
2178 | DEFUN (no_ospf_log_adjacency_changes_detail, | |
2179 | no_ospf_log_adjacency_changes_detail_cmd, | |
2180 | "no log-adjacency-changes detail", | |
2181 | NO_STR | |
2182 | "Log changes in adjacency state\n" | |
2183 | "Log all state changes\n") | |
2184 | { | |
a3d826f0 | 2185 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d7e60dd7 | 2186 | |
d62a17ae | 2187 | UNSET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL); |
2188 | return CMD_SUCCESS; | |
d7e60dd7 AS |
2189 | } |
2190 | ||
718e3744 | 2191 | DEFUN (ospf_compatible_rfc1583, |
2192 | ospf_compatible_rfc1583_cmd, | |
2193 | "compatible rfc1583", | |
2194 | "OSPF compatibility list\n" | |
2195 | "compatible with RFC 1583\n") | |
2196 | { | |
a3d826f0 | 2197 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
718e3744 | 2198 | |
d62a17ae | 2199 | if (!CHECK_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE)) { |
2200 | SET_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE); | |
2201 | ospf_spf_calculate_schedule(ospf, SPF_FLAG_CONFIG_CHANGE); | |
2202 | } | |
2203 | return CMD_SUCCESS; | |
718e3744 | 2204 | } |
2205 | ||
2206 | DEFUN (no_ospf_compatible_rfc1583, | |
2207 | no_ospf_compatible_rfc1583_cmd, | |
2208 | "no compatible rfc1583", | |
2209 | NO_STR | |
2210 | "OSPF compatibility list\n" | |
2211 | "compatible with RFC 1583\n") | |
2212 | { | |
a3d826f0 | 2213 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
718e3744 | 2214 | |
d62a17ae | 2215 | if (CHECK_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE)) { |
2216 | UNSET_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE); | |
2217 | ospf_spf_calculate_schedule(ospf, SPF_FLAG_CONFIG_CHANGE); | |
2218 | } | |
2219 | return CMD_SUCCESS; | |
718e3744 | 2220 | } |
2221 | ||
d62a17ae | 2222 | ALIAS(ospf_compatible_rfc1583, ospf_rfc1583_flag_cmd, |
2223 | "ospf rfc1583compatibility", | |
2224 | "OSPF specific commands\n" | |
2225 | "Enable the RFC1583Compatibility flag\n") | |
718e3744 | 2226 | |
d62a17ae | 2227 | ALIAS(no_ospf_compatible_rfc1583, no_ospf_rfc1583_flag_cmd, |
9d303b37 | 2228 | "no ospf rfc1583compatibility", NO_STR |
d62a17ae | 2229 | "OSPF specific commands\n" |
2230 | "Disable the RFC1583Compatibility flag\n") | |
6b0655a2 | 2231 | |
d62a17ae | 2232 | static int ospf_timers_spf_set(struct vty *vty, unsigned int delay, |
2233 | unsigned int hold, unsigned int max) | |
d24f6e2a | 2234 | { |
a3d826f0 | 2235 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
7c8ff89e | 2236 | |
d62a17ae | 2237 | ospf->spf_delay = delay; |
2238 | ospf->spf_holdtime = hold; | |
2239 | ospf->spf_max_holdtime = max; | |
2240 | ||
2241 | return CMD_SUCCESS; | |
d24f6e2a | 2242 | } |
718e3744 | 2243 | |
ac7424f9 MR |
2244 | DEFUN (ospf_timers_min_ls_interval, |
2245 | ospf_timers_min_ls_interval_cmd, | |
6147e2c6 | 2246 | "timers throttle lsa all (0-5000)", |
ac7424f9 MR |
2247 | "Adjust routing timers\n" |
2248 | "Throttling adaptive timer\n" | |
2249 | "LSA delay between transmissions\n" | |
813d4307 | 2250 | "All LSA types\n" |
ac7424f9 MR |
2251 | "Delay (msec) between sending LSAs\n") |
2252 | { | |
a3d826f0 | 2253 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2254 | int idx_number = 4; |
2255 | unsigned int interval; | |
ac7424f9 | 2256 | |
d62a17ae | 2257 | if (argc < 5) { |
2258 | vty_out(vty, "Insufficient arguments\n"); | |
2259 | return CMD_WARNING_CONFIG_FAILED; | |
2260 | } | |
ac7424f9 | 2261 | |
d62a17ae | 2262 | interval = strtoul(argv[idx_number]->arg, NULL, 10); |
ac7424f9 | 2263 | |
d62a17ae | 2264 | ospf->min_ls_interval = interval; |
ac7424f9 | 2265 | |
d62a17ae | 2266 | return CMD_SUCCESS; |
ac7424f9 MR |
2267 | } |
2268 | ||
2269 | DEFUN (no_ospf_timers_min_ls_interval, | |
2270 | no_ospf_timers_min_ls_interval_cmd, | |
7a7be519 | 2271 | "no timers throttle lsa all [(0-5000)]", |
ac7424f9 MR |
2272 | NO_STR |
2273 | "Adjust routing timers\n" | |
2274 | "Throttling adaptive timer\n" | |
813d4307 | 2275 | "LSA delay between transmissions\n" |
7a7be519 | 2276 | "All LSA types\n" |
2277 | "Delay (msec) between sending LSAs\n") | |
ac7424f9 | 2278 | { |
a3d826f0 | 2279 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2280 | ospf->min_ls_interval = OSPF_MIN_LS_INTERVAL; |
ac7424f9 | 2281 | |
d62a17ae | 2282 | return CMD_SUCCESS; |
ac7424f9 MR |
2283 | } |
2284 | ||
d24f6e2a | 2285 | DEFUN (ospf_timers_throttle_spf, |
2286 | ospf_timers_throttle_spf_cmd, | |
6147e2c6 | 2287 | "timers throttle spf (0-600000) (0-600000) (0-600000)", |
d24f6e2a | 2288 | "Adjust routing timers\n" |
2289 | "Throttling adaptive timer\n" | |
2290 | "OSPF SPF timers\n" | |
2291 | "Delay (msec) from first change received till SPF calculation\n" | |
2292 | "Initial hold time (msec) between consecutive SPF calculations\n" | |
2293 | "Maximum hold time (msec)\n") | |
2294 | { | |
d62a17ae | 2295 | int idx_number = 3; |
2296 | int idx_number_2 = 4; | |
2297 | int idx_number_3 = 5; | |
2298 | unsigned int delay, hold, max; | |
2299 | ||
2300 | if (argc < 6) { | |
2301 | vty_out(vty, "Insufficient arguments\n"); | |
2302 | return CMD_WARNING_CONFIG_FAILED; | |
2303 | } | |
2304 | ||
2305 | delay = strtoul(argv[idx_number]->arg, NULL, 10); | |
2306 | hold = strtoul(argv[idx_number_2]->arg, NULL, 10); | |
2307 | max = strtoul(argv[idx_number_3]->arg, NULL, 10); | |
2308 | ||
2309 | return ospf_timers_spf_set(vty, delay, hold, max); | |
d24f6e2a | 2310 | } |
2311 | ||
d24f6e2a | 2312 | DEFUN (no_ospf_timers_throttle_spf, |
2313 | no_ospf_timers_throttle_spf_cmd, | |
7a7be519 | 2314 | "no timers throttle spf [(0-600000)(0-600000)(0-600000)]", |
718e3744 | 2315 | NO_STR |
2316 | "Adjust routing timers\n" | |
d24f6e2a | 2317 | "Throttling adaptive timer\n" |
7a7be519 | 2318 | "OSPF SPF timers\n" |
2319 | "Delay (msec) from first change received till SPF calculation\n" | |
2320 | "Initial hold time (msec) between consecutive SPF calculations\n" | |
2321 | "Maximum hold time (msec)\n") | |
22b27e95 | 2322 | { |
d62a17ae | 2323 | return ospf_timers_spf_set(vty, OSPF_SPF_DELAY_DEFAULT, |
2324 | OSPF_SPF_HOLDTIME_DEFAULT, | |
2325 | OSPF_SPF_MAX_HOLDTIME_DEFAULT); | |
718e3744 | 2326 | } |
2327 | ||
b4a039bf | 2328 | |
0e88de35 QY |
2329 | DEFUN (ospf_timers_lsa_min_arrival, |
2330 | ospf_timers_lsa_min_arrival_cmd, | |
6147e2c6 | 2331 | "timers lsa min-arrival (0-600000)", |
b6927875 DS |
2332 | "Adjust routing timers\n" |
2333 | "OSPF LSA timers\n" | |
2334 | "Minimum delay in receiving new version of a LSA\n" | |
2335 | "Delay in milliseconds\n") | |
2336 | { | |
a3d826f0 | 2337 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
0e88de35 | 2338 | ospf->min_ls_arrival = strtoul(argv[argc - 1]->arg, NULL, 10); |
d62a17ae | 2339 | return CMD_SUCCESS; |
b6927875 DS |
2340 | } |
2341 | ||
0e88de35 QY |
2342 | DEFUN (no_ospf_timers_lsa_min_arrival, |
2343 | no_ospf_timers_lsa_min_arrival_cmd, | |
7a7be519 | 2344 | "no timers lsa min-arrival [(0-600000)]", |
b6927875 DS |
2345 | NO_STR |
2346 | "Adjust routing timers\n" | |
2347 | "OSPF LSA timers\n" | |
7a7be519 | 2348 | "Minimum delay in receiving new version of a LSA\n" |
2349 | "Delay in milliseconds\n") | |
b6927875 | 2350 | { |
a3d826f0 | 2351 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2352 | unsigned int minarrival; |
b6927875 | 2353 | |
d62a17ae | 2354 | if (argc > 4) { |
0e88de35 | 2355 | minarrival = strtoul(argv[argc - 1]->arg, NULL, 10); |
b6927875 | 2356 | |
d62a17ae | 2357 | if (ospf->min_ls_arrival != minarrival |
2358 | || minarrival == OSPF_MIN_LS_ARRIVAL) | |
2359 | return CMD_SUCCESS; | |
2360 | } | |
b6927875 | 2361 | |
d62a17ae | 2362 | ospf->min_ls_arrival = OSPF_MIN_LS_ARRIVAL; |
b6927875 | 2363 | |
d62a17ae | 2364 | return CMD_SUCCESS; |
b6927875 DS |
2365 | } |
2366 | ||
a2c62831 | 2367 | DEFUN (ospf_neighbor, |
2368 | ospf_neighbor_cmd, | |
7a7be519 | 2369 | "neighbor A.B.C.D [priority (0-255) [poll-interval (1-65535)]]", |
718e3744 | 2370 | NEIGHBOR_STR |
7a7be519 | 2371 | "Neighbor IP address\n" |
2372 | "Neighbor Priority\n" | |
2373 | "Priority\n" | |
2374 | "Dead Neighbor Polling interval\n" | |
2375 | "Seconds\n") | |
718e3744 | 2376 | { |
a3d826f0 | 2377 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2378 | int idx_ipv4 = 1; |
2379 | int idx_pri = 3; | |
2380 | int idx_poll = 5; | |
2381 | struct in_addr nbr_addr; | |
2382 | unsigned int priority = OSPF_NEIGHBOR_PRIORITY_DEFAULT; | |
2383 | unsigned int interval = OSPF_POLL_INTERVAL_DEFAULT; | |
718e3744 | 2384 | |
cc9b06ad DS |
2385 | if (!inet_aton(argv[idx_ipv4]->arg, &nbr_addr)) { |
2386 | vty_out(vty, "Please specify Neighbor ID by A.B.C.D\n"); | |
2387 | return CMD_WARNING_CONFIG_FAILED; | |
2388 | } | |
718e3744 | 2389 | |
d62a17ae | 2390 | if (argc > 2) |
2391 | priority = strtoul(argv[idx_pri]->arg, NULL, 10); | |
7a7be519 | 2392 | |
d62a17ae | 2393 | if (argc > 4) |
2394 | interval = strtoul(argv[idx_poll]->arg, NULL, 10); | |
718e3744 | 2395 | |
d62a17ae | 2396 | ospf_nbr_nbma_set(ospf, nbr_addr); |
7a7be519 | 2397 | |
d62a17ae | 2398 | if (argc > 2) |
2399 | ospf_nbr_nbma_priority_set(ospf, nbr_addr, priority); | |
7a7be519 | 2400 | |
d62a17ae | 2401 | if (argc > 4) |
2402 | ospf_nbr_nbma_poll_interval_set(ospf, nbr_addr, interval); | |
718e3744 | 2403 | |
d62a17ae | 2404 | return CMD_SUCCESS; |
718e3744 | 2405 | } |
2406 | ||
a2c62831 | 2407 | DEFUN (ospf_neighbor_poll_interval, |
2408 | ospf_neighbor_poll_interval_cmd, | |
7a7be519 | 2409 | "neighbor A.B.C.D poll-interval (1-65535) [priority (0-255)]", |
718e3744 | 2410 | NEIGHBOR_STR |
2411 | "Neighbor IP address\n" | |
2412 | "Dead Neighbor Polling interval\n" | |
7a7be519 | 2413 | "Seconds\n" |
2414 | "OSPF priority of non-broadcast neighbor\n" | |
2415 | "Priority\n") | |
22b27e95 | 2416 | { |
a3d826f0 | 2417 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2418 | int idx_ipv4 = 1; |
2419 | int idx_poll = 3; | |
2420 | int idx_pri = 5; | |
2421 | struct in_addr nbr_addr; | |
a2b6e694 | 2422 | unsigned int priority; |
2423 | unsigned int interval; | |
718e3744 | 2424 | |
cc9b06ad DS |
2425 | if (!inet_aton(argv[idx_ipv4]->arg, &nbr_addr)) { |
2426 | vty_out(vty, "Please specify Neighbor ID by A.B.C.D\n"); | |
2427 | return CMD_WARNING_CONFIG_FAILED; | |
2428 | } | |
718e3744 | 2429 | |
d62a17ae | 2430 | interval = strtoul(argv[idx_poll]->arg, NULL, 10); |
718e3744 | 2431 | |
a2b6e694 | 2432 | priority = argc > 4 ? strtoul(argv[idx_pri]->arg, NULL, 10) |
2433 | : OSPF_NEIGHBOR_PRIORITY_DEFAULT; | |
718e3744 | 2434 | |
d62a17ae | 2435 | ospf_nbr_nbma_set(ospf, nbr_addr); |
2436 | ospf_nbr_nbma_poll_interval_set(ospf, nbr_addr, interval); | |
7a7be519 | 2437 | |
d62a17ae | 2438 | if (argc > 4) |
2439 | ospf_nbr_nbma_priority_set(ospf, nbr_addr, priority); | |
718e3744 | 2440 | |
d62a17ae | 2441 | return CMD_SUCCESS; |
718e3744 | 2442 | } |
2443 | ||
a2c62831 | 2444 | DEFUN (no_ospf_neighbor, |
2445 | no_ospf_neighbor_cmd, | |
7a7be519 | 2446 | "no neighbor A.B.C.D [priority (0-255) [poll-interval (1-65525)]]", |
718e3744 | 2447 | NO_STR |
2448 | NEIGHBOR_STR | |
7a7be519 | 2449 | "Neighbor IP address\n" |
2450 | "Neighbor Priority\n" | |
2451 | "Priority\n" | |
2452 | "Dead Neighbor Polling interval\n" | |
2453 | "Seconds\n") | |
718e3744 | 2454 | { |
a3d826f0 | 2455 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2456 | int idx_ipv4 = 2; |
2457 | struct in_addr nbr_addr; | |
718e3744 | 2458 | |
cc9b06ad DS |
2459 | if (!inet_aton(argv[idx_ipv4]->arg, &nbr_addr)) { |
2460 | vty_out(vty, "Please specify Neighbor ID by A.B.C.D\n"); | |
2461 | return CMD_WARNING_CONFIG_FAILED; | |
2462 | } | |
718e3744 | 2463 | |
d62a17ae | 2464 | (void)ospf_nbr_nbma_unset(ospf, nbr_addr); |
718e3744 | 2465 | |
d62a17ae | 2466 | return CMD_SUCCESS; |
718e3744 | 2467 | } |
2468 | ||
7a7be519 | 2469 | DEFUN (no_ospf_neighbor_poll, |
2470 | no_ospf_neighbor_poll_cmd, | |
2471 | "no neighbor A.B.C.D poll-interval (1-65535) [priority (0-255)]", | |
2472 | NO_STR | |
2473 | NEIGHBOR_STR | |
2474 | "Neighbor IP address\n" | |
2475 | "Dead Neighbor Polling interval\n" | |
2476 | "Seconds\n" | |
2477 | "Neighbor Priority\n" | |
2478 | "Priority\n") | |
2479 | { | |
a3d826f0 | 2480 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2481 | int idx_ipv4 = 2; |
2482 | struct in_addr nbr_addr; | |
7a7be519 | 2483 | |
cc9b06ad DS |
2484 | if (!inet_aton(argv[idx_ipv4]->arg, &nbr_addr)) { |
2485 | vty_out(vty, "Please specify Neighbor ID by A.B.C.D\n"); | |
2486 | return CMD_WARNING_CONFIG_FAILED; | |
2487 | } | |
718e3744 | 2488 | |
d62a17ae | 2489 | (void)ospf_nbr_nbma_unset(ospf, nbr_addr); |
813d4307 | 2490 | |
d62a17ae | 2491 | return CMD_SUCCESS; |
7a7be519 | 2492 | } |
718e3744 | 2493 | |
bf2bfafd DW |
2494 | DEFUN (ospf_refresh_timer, |
2495 | ospf_refresh_timer_cmd, | |
6147e2c6 | 2496 | "refresh timer (10-1800)", |
718e3744 | 2497 | "Adjust refresh parameters\n" |
2498 | "Set refresh timer\n" | |
2499 | "Timer value in seconds\n") | |
2500 | { | |
a3d826f0 | 2501 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2502 | int idx_number = 2; |
2503 | unsigned int interval; | |
7c8ff89e | 2504 | |
d62a17ae | 2505 | interval = strtoul(argv[idx_number]->arg, NULL, 10); |
2506 | interval = (interval / OSPF_LSA_REFRESHER_GRANULARITY) | |
2507 | * OSPF_LSA_REFRESHER_GRANULARITY; | |
718e3744 | 2508 | |
d62a17ae | 2509 | ospf_timers_refresh_set(ospf, interval); |
718e3744 | 2510 | |
d62a17ae | 2511 | return CMD_SUCCESS; |
718e3744 | 2512 | } |
2513 | ||
bf2bfafd DW |
2514 | DEFUN (no_ospf_refresh_timer, |
2515 | no_ospf_refresh_timer_val_cmd, | |
7a7be519 | 2516 | "no refresh timer [(10-1800)]", |
3a2d747c | 2517 | NO_STR |
718e3744 | 2518 | "Adjust refresh parameters\n" |
2519 | "Unset refresh timer\n" | |
2520 | "Timer value in seconds\n") | |
2521 | { | |
a3d826f0 | 2522 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2523 | int idx_number = 3; |
2524 | unsigned int interval; | |
718e3744 | 2525 | |
d62a17ae | 2526 | if (argc == 1) { |
2527 | interval = strtoul(argv[idx_number]->arg, NULL, 10); | |
718e3744 | 2528 | |
d62a17ae | 2529 | if (ospf->lsa_refresh_interval != interval |
2530 | || interval == OSPF_LSA_REFRESH_INTERVAL_DEFAULT) | |
2531 | return CMD_SUCCESS; | |
2532 | } | |
2533 | ||
2534 | ospf_timers_refresh_unset(ospf); | |
2535 | ||
2536 | return CMD_SUCCESS; | |
718e3744 | 2537 | } |
2538 | ||
718e3744 | 2539 | |
a2c62831 | 2540 | DEFUN (ospf_auto_cost_reference_bandwidth, |
2541 | ospf_auto_cost_reference_bandwidth_cmd, | |
6147e2c6 | 2542 | "auto-cost reference-bandwidth (1-4294967)", |
718e3744 | 2543 | "Calculate OSPF interface cost according to bandwidth\n" |
2544 | "Use reference bandwidth method to assign OSPF cost\n" | |
2545 | "The reference bandwidth in terms of Mbits per second\n") | |
2546 | { | |
a3d826f0 | 2547 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
f4e14fdb | 2548 | struct vrf *vrf = vrf_lookup_by_id(ospf->vrf_id); |
d62a17ae | 2549 | int idx_number = 2; |
d7c0a89a | 2550 | uint32_t refbw; |
d62a17ae | 2551 | struct interface *ifp; |
2552 | ||
2553 | refbw = strtol(argv[idx_number]->arg, NULL, 10); | |
2554 | if (refbw < 1 || refbw > 4294967) { | |
2555 | vty_out(vty, "reference-bandwidth value is invalid\n"); | |
2556 | return CMD_WARNING_CONFIG_FAILED; | |
2557 | } | |
2558 | ||
2559 | /* If reference bandwidth is changed. */ | |
2560 | if ((refbw) == ospf->ref_bandwidth) | |
2561 | return CMD_SUCCESS; | |
2562 | ||
2563 | ospf->ref_bandwidth = refbw; | |
451fda4f | 2564 | FOR_ALL_INTERFACES (vrf, ifp) |
d62a17ae | 2565 | ospf_if_recalculate_output_cost(ifp); |
2566 | ||
2567 | return CMD_SUCCESS; | |
718e3744 | 2568 | } |
2569 | ||
a2c62831 | 2570 | DEFUN (no_ospf_auto_cost_reference_bandwidth, |
2571 | no_ospf_auto_cost_reference_bandwidth_cmd, | |
7a7be519 | 2572 | "no auto-cost reference-bandwidth [(1-4294967)]", |
718e3744 | 2573 | NO_STR |
2574 | "Calculate OSPF interface cost according to bandwidth\n" | |
7a7be519 | 2575 | "Use reference bandwidth method to assign OSPF cost\n" |
2576 | "The reference bandwidth in terms of Mbits per second\n") | |
718e3744 | 2577 | { |
a3d826f0 | 2578 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
f4e14fdb | 2579 | struct vrf *vrf = vrf_lookup_by_id(ospf->vrf_id); |
d62a17ae | 2580 | struct interface *ifp; |
718e3744 | 2581 | |
d62a17ae | 2582 | if (ospf->ref_bandwidth == OSPF_DEFAULT_REF_BANDWIDTH) |
2583 | return CMD_SUCCESS; | |
2584 | ||
2585 | ospf->ref_bandwidth = OSPF_DEFAULT_REF_BANDWIDTH; | |
2586 | vty_out(vty, "%% OSPF: Reference bandwidth is changed.\n"); | |
2587 | vty_out(vty, | |
2588 | " Please ensure reference bandwidth is consistent across all routers\n"); | |
2589 | ||
451fda4f | 2590 | FOR_ALL_INTERFACES (vrf, ifp) |
d62a17ae | 2591 | ospf_if_recalculate_output_cost(ifp); |
2592 | ||
2593 | return CMD_SUCCESS; | |
718e3744 | 2594 | } |
2595 | ||
2f8f370e DS |
2596 | DEFUN (ospf_write_multiplier, |
2597 | ospf_write_multiplier_cmd, | |
6147e2c6 | 2598 | "ospf write-multiplier (1-100)", |
e8f45e82 DS |
2599 | "OSPF specific commands\n" |
2600 | "Write multiplier\n" | |
2601 | "Maximum number of interface serviced per write\n") | |
2f8f370e | 2602 | { |
a3d826f0 | 2603 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2604 | int idx_number; |
d7c0a89a | 2605 | uint32_t write_oi_count; |
d62a17ae | 2606 | |
2607 | if (argc == 3) | |
2608 | idx_number = 2; | |
2609 | else | |
2610 | idx_number = 1; | |
2611 | ||
2612 | write_oi_count = strtol(argv[idx_number]->arg, NULL, 10); | |
2613 | if (write_oi_count < 1 || write_oi_count > 100) { | |
2614 | vty_out(vty, "write-multiplier value is invalid\n"); | |
2615 | return CMD_WARNING_CONFIG_FAILED; | |
2616 | } | |
2617 | ||
2618 | ospf->write_oi_count = write_oi_count; | |
2619 | return CMD_SUCCESS; | |
2f8f370e DS |
2620 | } |
2621 | ||
d62a17ae | 2622 | ALIAS(ospf_write_multiplier, write_multiplier_cmd, "write-multiplier (1-100)", |
2623 | "Write multiplier\n" | |
2624 | "Maximum number of interface serviced per write\n") | |
e8f45e82 | 2625 | |
2f8f370e DS |
2626 | DEFUN (no_ospf_write_multiplier, |
2627 | no_ospf_write_multiplier_cmd, | |
6147e2c6 | 2628 | "no ospf write-multiplier (1-100)", |
2f8f370e | 2629 | NO_STR |
e8f45e82 | 2630 | "OSPF specific commands\n" |
813d4307 DW |
2631 | "Write multiplier\n" |
2632 | "Maximum number of interface serviced per write\n") | |
2f8f370e | 2633 | { |
a3d826f0 | 2634 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
2f8f370e | 2635 | |
d62a17ae | 2636 | ospf->write_oi_count = OSPF_WRITE_INTERFACE_COUNT_DEFAULT; |
2637 | return CMD_SUCCESS; | |
2f8f370e DS |
2638 | } |
2639 | ||
d62a17ae | 2640 | ALIAS(no_ospf_write_multiplier, no_write_multiplier_cmd, |
9d303b37 | 2641 | "no write-multiplier (1-100)", NO_STR |
d62a17ae | 2642 | "Write multiplier\n" |
2643 | "Maximum number of interface serviced per write\n") | |
2644 | ||
385a1e07 | 2645 | DEFUN(ospf_ti_lfa, ospf_ti_lfa_cmd, "fast-reroute ti-lfa [node-protection]", |
7fd0729f | 2646 | "Fast Reroute for MPLS and IP resilience\n" |
385a1e07 G |
2647 | "Topology Independent LFA (Loop-Free Alternate)\n" |
2648 | "TI-LFA node protection (default is link protection)\n") | |
7fd0729f G |
2649 | { |
2650 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
2651 | ||
2652 | ospf->ti_lfa_enabled = true; | |
2653 | ||
385a1e07 G |
2654 | if (argc == 3) |
2655 | ospf->ti_lfa_protection_type = OSPF_TI_LFA_NODE_PROTECTION; | |
2656 | else | |
2657 | ospf->ti_lfa_protection_type = OSPF_TI_LFA_LINK_PROTECTION; | |
2658 | ||
7fd0729f G |
2659 | ospf_spf_calculate_schedule(ospf, SPF_FLAG_CONFIG_CHANGE); |
2660 | ||
2661 | return CMD_SUCCESS; | |
2662 | } | |
2663 | ||
385a1e07 G |
2664 | DEFUN(no_ospf_ti_lfa, no_ospf_ti_lfa_cmd, |
2665 | "no fast-reroute ti-lfa [node-protection]", | |
7fd0729f G |
2666 | NO_STR |
2667 | "Fast Reroute for MPLS and IP resilience\n" | |
385a1e07 G |
2668 | "Topology Independent LFA (Loop-Free Alternate)\n" |
2669 | "TI-LFA node protection (default is link protection)\n") | |
7fd0729f G |
2670 | { |
2671 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
2672 | ||
2673 | ospf->ti_lfa_enabled = false; | |
2674 | ||
385a1e07 G |
2675 | ospf->ti_lfa_protection_type = OSPF_TI_LFA_UNDEFINED_PROTECTION; |
2676 | ||
7fd0729f G |
2677 | ospf_spf_calculate_schedule(ospf, SPF_FLAG_CONFIG_CHANGE); |
2678 | ||
2679 | return CMD_SUCCESS; | |
2680 | } | |
2681 | ||
3d5b9855 | 2682 | static void ospf_maxpath_set(struct vty *vty, struct ospf *ospf, uint16_t paths) |
2683 | { | |
2684 | if (ospf->max_multipath == paths) | |
2685 | return; | |
2686 | ||
2687 | ospf->max_multipath = paths; | |
2688 | ||
2689 | /* Send deletion notification to zebra to delete all | |
2690 | * ospf specific routes and reinitiat SPF to reflect | |
2691 | * the new max multipath. | |
2692 | */ | |
2693 | ospf_restart_spf(ospf); | |
2694 | } | |
2695 | ||
2696 | /* Ospf Maximum multiple paths config support */ | |
2697 | DEFUN (ospf_max_multipath, | |
2698 | ospf_max_multipath_cmd, | |
2699 | "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM), | |
2700 | "Max no of multiple paths for ECMP support\n" | |
2701 | "Number of paths\n") | |
2702 | { | |
2703 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
2704 | int idx_number = 1; | |
2705 | uint16_t maxpaths; | |
2706 | ||
2707 | maxpaths = strtol(argv[idx_number]->arg, NULL, 10); | |
2708 | ||
2709 | ospf_maxpath_set(vty, ospf, maxpaths); | |
2710 | return CMD_SUCCESS; | |
2711 | } | |
2712 | ||
2713 | DEFUN (no_ospf_max_multipath, | |
2714 | no_ospf_max_multipath_cmd, | |
2715 | "no maximum-paths", | |
2716 | NO_STR | |
2717 | "Max no of multiple paths for ECMP support\n") | |
2718 | { | |
2719 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
2720 | uint16_t maxpaths = MULTIPATH_NUM; | |
2721 | ||
2722 | ospf_maxpath_set(vty, ospf, maxpaths); | |
2723 | return CMD_SUCCESS; | |
2724 | } | |
2725 | ||
2b64873d DL |
2726 | static const char *const ospf_abr_type_descr_str[] = { |
2727 | "Unknown", "Standard (RFC2328)", "Alternative IBM", | |
2728 | "Alternative Cisco", "Alternative Shortcut" | |
2729 | }; | |
d62a17ae | 2730 | |
2b64873d DL |
2731 | static const char *const ospf_shortcut_mode_descr_str[] = { |
2732 | "Default", "Enabled", "Disabled" | |
2733 | }; | |
d62a17ae | 2734 | |
2735 | static void show_ip_ospf_area(struct vty *vty, struct ospf_area *area, | |
9f049418 | 2736 | json_object *json_areas, bool use_json) |
d62a17ae | 2737 | { |
2738 | json_object *json_area = NULL; | |
96b663a3 | 2739 | char buf[PREFIX_STRLEN]; |
d62a17ae | 2740 | |
2741 | if (use_json) | |
2742 | json_area = json_object_new_object(); | |
2743 | ||
2744 | /* Show Area ID. */ | |
2745 | if (!use_json) | |
96b663a3 | 2746 | vty_out(vty, " Area ID: %pI4", &area->area_id); |
d62a17ae | 2747 | |
2748 | /* Show Area type/mode. */ | |
2749 | if (OSPF_IS_AREA_BACKBONE(area)) { | |
2750 | if (use_json) | |
2751 | json_object_boolean_true_add(json_area, "backbone"); | |
2752 | else | |
2753 | vty_out(vty, " (Backbone)\n"); | |
2754 | } else { | |
2755 | if (use_json) { | |
2756 | if (area->external_routing == OSPF_AREA_STUB) { | |
2757 | if (area->no_summary) | |
2758 | json_object_boolean_true_add( | |
2759 | json_area, "stubNoSummary"); | |
2760 | if (area->shortcut_configured) | |
2761 | json_object_boolean_true_add( | |
2762 | json_area, "stubShortcut"); | |
2763 | } else if (area->external_routing == OSPF_AREA_NSSA) { | |
2764 | if (area->no_summary) | |
2765 | json_object_boolean_true_add( | |
2766 | json_area, "nssaNoSummary"); | |
2767 | if (area->shortcut_configured) | |
2768 | json_object_boolean_true_add( | |
2769 | json_area, "nssaShortcut"); | |
2770 | } | |
813d4307 | 2771 | |
d62a17ae | 2772 | json_object_string_add( |
2773 | json_area, "shortcuttingMode", | |
2774 | ospf_shortcut_mode_descr_str | |
2775 | [area->shortcut_configured]); | |
2776 | if (area->shortcut_capability) | |
2777 | json_object_boolean_true_add(json_area, | |
2778 | "sBitConcensus"); | |
2779 | } else { | |
2780 | if (area->external_routing == OSPF_AREA_STUB) | |
2781 | vty_out(vty, " (Stub%s%s)", | |
2782 | area->no_summary ? ", no summary" : "", | |
2783 | area->shortcut_configured ? "; " : ""); | |
2784 | else if (area->external_routing == OSPF_AREA_NSSA) | |
2785 | vty_out(vty, " (NSSA%s%s)", | |
2786 | area->no_summary ? ", no summary" : "", | |
2787 | area->shortcut_configured ? "; " : ""); | |
2788 | ||
2789 | vty_out(vty, "\n"); | |
2790 | vty_out(vty, " Shortcutting mode: %s", | |
2791 | ospf_shortcut_mode_descr_str | |
2792 | [area->shortcut_configured]); | |
2793 | vty_out(vty, ", S-bit consensus: %s\n", | |
2794 | area->shortcut_capability ? "ok" : "no"); | |
2795 | } | |
2796 | } | |
718e3744 | 2797 | |
d62a17ae | 2798 | /* Show number of interfaces */ |
2799 | if (use_json) { | |
2800 | json_object_int_add(json_area, "areaIfTotalCounter", | |
2801 | listcount(area->oiflist)); | |
2802 | json_object_int_add(json_area, "areaIfActiveCounter", | |
2803 | area->act_ints); | |
2804 | } else | |
2805 | vty_out(vty, | |
3efd0893 | 2806 | " Number of interfaces in this area: Total: %d, Active: %d\n", |
d62a17ae | 2807 | listcount(area->oiflist), area->act_ints); |
2808 | ||
2809 | if (area->external_routing == OSPF_AREA_NSSA) { | |
2810 | if (use_json) { | |
2811 | json_object_boolean_true_add(json_area, "nssa"); | |
2812 | if (!IS_OSPF_ABR(area->ospf)) | |
2813 | json_object_boolean_false_add(json_area, "abr"); | |
2814 | else if (area->NSSATranslatorState) { | |
2815 | json_object_boolean_true_add(json_area, "abr"); | |
2816 | if (area->NSSATranslatorRole | |
2817 | == OSPF_NSSA_ROLE_CANDIDATE) | |
2818 | json_object_boolean_true_add( | |
2819 | json_area, | |
2820 | "nssaTranslatorElected"); | |
2821 | else if (area->NSSATranslatorRole | |
2822 | == OSPF_NSSA_ROLE_ALWAYS) | |
2823 | json_object_boolean_true_add( | |
2824 | json_area, | |
2825 | "nssaTranslatorAlways"); | |
b79c3070 | 2826 | else |
2827 | json_object_boolean_true_add( | |
2828 | json_area, | |
2829 | "nssaTranslatorNever"); | |
d62a17ae | 2830 | } else { |
2831 | json_object_boolean_true_add(json_area, "abr"); | |
2832 | if (area->NSSATranslatorRole | |
2833 | == OSPF_NSSA_ROLE_CANDIDATE) | |
2834 | json_object_boolean_false_add( | |
2835 | json_area, | |
2836 | "nssaTranslatorElected"); | |
2837 | else | |
2838 | json_object_boolean_true_add( | |
2839 | json_area, | |
2840 | "nssaTranslatorNever"); | |
2841 | } | |
2842 | } else { | |
2843 | vty_out(vty, | |
b79c3070 | 2844 | " It is an NSSA configuration.\n Elected NSSA/ABR performs type-7/type-5 LSA translation.\n"); |
d62a17ae | 2845 | if (!IS_OSPF_ABR(area->ospf)) |
2846 | vty_out(vty, | |
b79c3070 | 2847 | " It is not ABR, therefore not Translator.\n"); |
d62a17ae | 2848 | else if (area->NSSATranslatorState) { |
2849 | vty_out(vty, " We are an ABR and "); | |
2850 | if (area->NSSATranslatorRole | |
2851 | == OSPF_NSSA_ROLE_CANDIDATE) | |
2852 | vty_out(vty, | |
b79c3070 | 2853 | "the NSSA Elected Translator.\n"); |
d62a17ae | 2854 | else if (area->NSSATranslatorRole |
2855 | == OSPF_NSSA_ROLE_ALWAYS) | |
2856 | vty_out(vty, | |
b79c3070 | 2857 | "always an NSSA Translator.\n"); |
2858 | else | |
2859 | vty_out(vty, | |
2860 | "never an NSSA Translator.\n"); | |
d62a17ae | 2861 | } else { |
2862 | vty_out(vty, " We are an ABR, but "); | |
2863 | if (area->NSSATranslatorRole | |
2864 | == OSPF_NSSA_ROLE_CANDIDATE) | |
2865 | vty_out(vty, | |
b79c3070 | 2866 | "not the NSSA Elected Translator.\n"); |
d62a17ae | 2867 | else |
2868 | vty_out(vty, | |
b79c3070 | 2869 | "never an NSSA Translator.\n"); |
d62a17ae | 2870 | } |
2871 | } | |
2872 | } | |
2873 | ||
2874 | /* Stub-router state for this area */ | |
2875 | if (CHECK_FLAG(area->stub_router_state, OSPF_AREA_IS_STUB_ROUTED)) { | |
2876 | char timebuf[OSPF_TIME_DUMP_SIZE]; | |
2877 | ||
2878 | if (use_json) { | |
2879 | json_object_boolean_true_add( | |
2880 | json_area, "originStubMaxDistRouterLsa"); | |
2881 | if (CHECK_FLAG(area->stub_router_state, | |
2882 | OSPF_AREA_ADMIN_STUB_ROUTED)) | |
2883 | json_object_boolean_true_add( | |
2884 | json_area, "indefiniteActiveAdmin"); | |
2885 | if (area->t_stub_router) { | |
2886 | long time_store; | |
2887 | time_store = | |
2888 | monotime_until( | |
2889 | &area->t_stub_router->u.sands, | |
2890 | NULL) | |
2891 | / 1000LL; | |
2892 | json_object_int_add( | |
2893 | json_area, | |
2894 | "activeStartupRemainderMsecs", | |
2895 | time_store); | |
2896 | } | |
2897 | } else { | |
2898 | vty_out(vty, | |
2899 | " Originating stub / maximum-distance Router-LSA\n"); | |
2900 | if (CHECK_FLAG(area->stub_router_state, | |
2901 | OSPF_AREA_ADMIN_STUB_ROUTED)) | |
2902 | vty_out(vty, | |
2903 | " Administratively activated (indefinitely)\n"); | |
2904 | if (area->t_stub_router) | |
2905 | vty_out(vty, | |
2906 | " Active from startup, %s remaining\n", | |
2907 | ospf_timer_dump(area->t_stub_router, | |
2908 | timebuf, | |
2909 | sizeof(timebuf))); | |
2910 | } | |
2911 | } | |
2912 | ||
2913 | if (use_json) { | |
2914 | /* Show number of fully adjacent neighbors. */ | |
2915 | json_object_int_add(json_area, "nbrFullAdjacentCounter", | |
2916 | area->full_nbrs); | |
2917 | ||
2918 | /* Show authentication type. */ | |
2919 | if (area->auth_type == OSPF_AUTH_NULL) | |
2920 | json_object_string_add(json_area, "authentication", | |
2921 | "authenticationNone"); | |
2922 | else if (area->auth_type == OSPF_AUTH_SIMPLE) | |
2923 | json_object_string_add(json_area, "authentication", | |
2924 | "authenticationSimplePassword"); | |
2925 | else if (area->auth_type == OSPF_AUTH_CRYPTOGRAPHIC) | |
2926 | json_object_string_add(json_area, "authentication", | |
2927 | "authenticationMessageDigest"); | |
2928 | ||
2929 | if (!OSPF_IS_AREA_BACKBONE(area)) | |
2930 | json_object_int_add(json_area, | |
2931 | "virtualAdjacenciesPassingCounter", | |
2932 | area->full_vls); | |
2933 | ||
2934 | /* Show SPF calculation times. */ | |
2935 | json_object_int_add(json_area, "spfExecutedCounter", | |
2936 | area->spf_calculation); | |
2937 | json_object_int_add(json_area, "lsaNumber", area->lsdb->total); | |
2938 | json_object_int_add( | |
2939 | json_area, "lsaRouterNumber", | |
2940 | ospf_lsdb_count(area->lsdb, OSPF_ROUTER_LSA)); | |
2941 | json_object_int_add( | |
2942 | json_area, "lsaRouterChecksum", | |
2943 | ospf_lsdb_checksum(area->lsdb, OSPF_ROUTER_LSA)); | |
2944 | json_object_int_add( | |
2945 | json_area, "lsaNetworkNumber", | |
2946 | ospf_lsdb_count(area->lsdb, OSPF_NETWORK_LSA)); | |
2947 | json_object_int_add( | |
2948 | json_area, "lsaNetworkChecksum", | |
2949 | ospf_lsdb_checksum(area->lsdb, OSPF_NETWORK_LSA)); | |
2950 | json_object_int_add( | |
2951 | json_area, "lsaSummaryNumber", | |
2952 | ospf_lsdb_count(area->lsdb, OSPF_SUMMARY_LSA)); | |
2953 | json_object_int_add( | |
2954 | json_area, "lsaSummaryChecksum", | |
2955 | ospf_lsdb_checksum(area->lsdb, OSPF_SUMMARY_LSA)); | |
2956 | json_object_int_add( | |
2957 | json_area, "lsaAsbrNumber", | |
2958 | ospf_lsdb_count(area->lsdb, OSPF_ASBR_SUMMARY_LSA)); | |
2959 | json_object_int_add( | |
2960 | json_area, "lsaAsbrChecksum", | |
2961 | ospf_lsdb_checksum(area->lsdb, OSPF_ASBR_SUMMARY_LSA)); | |
2962 | json_object_int_add( | |
2963 | json_area, "lsaNssaNumber", | |
2964 | ospf_lsdb_count(area->lsdb, OSPF_AS_NSSA_LSA)); | |
2965 | json_object_int_add( | |
2966 | json_area, "lsaNssaChecksum", | |
2967 | ospf_lsdb_checksum(area->lsdb, OSPF_AS_NSSA_LSA)); | |
2968 | } else { | |
2969 | /* Show number of fully adjacent neighbors. */ | |
2970 | vty_out(vty, | |
3efd0893 | 2971 | " Number of fully adjacent neighbors in this area: %d\n", |
d62a17ae | 2972 | area->full_nbrs); |
2973 | ||
2974 | /* Show authentication type. */ | |
2975 | vty_out(vty, " Area has "); | |
2976 | if (area->auth_type == OSPF_AUTH_NULL) | |
2977 | vty_out(vty, "no authentication\n"); | |
2978 | else if (area->auth_type == OSPF_AUTH_SIMPLE) | |
2979 | vty_out(vty, "simple password authentication\n"); | |
2980 | else if (area->auth_type == OSPF_AUTH_CRYPTOGRAPHIC) | |
2981 | vty_out(vty, "message digest authentication\n"); | |
2982 | ||
2983 | if (!OSPF_IS_AREA_BACKBONE(area)) | |
2984 | vty_out(vty, | |
3efd0893 | 2985 | " Number of full virtual adjacencies going through this area: %d\n", |
d62a17ae | 2986 | area->full_vls); |
2987 | ||
2988 | /* Show SPF calculation times. */ | |
2989 | vty_out(vty, " SPF algorithm executed %d times\n", | |
2990 | area->spf_calculation); | |
2991 | ||
2992 | /* Show number of LSA. */ | |
2993 | vty_out(vty, " Number of LSA %ld\n", area->lsdb->total); | |
2994 | vty_out(vty, | |
2995 | " Number of router LSA %ld. Checksum Sum 0x%08x\n", | |
2996 | ospf_lsdb_count(area->lsdb, OSPF_ROUTER_LSA), | |
2997 | ospf_lsdb_checksum(area->lsdb, OSPF_ROUTER_LSA)); | |
2998 | vty_out(vty, | |
2999 | " Number of network LSA %ld. Checksum Sum 0x%08x\n", | |
3000 | ospf_lsdb_count(area->lsdb, OSPF_NETWORK_LSA), | |
3001 | ospf_lsdb_checksum(area->lsdb, OSPF_NETWORK_LSA)); | |
3002 | vty_out(vty, | |
3003 | " Number of summary LSA %ld. Checksum Sum 0x%08x\n", | |
3004 | ospf_lsdb_count(area->lsdb, OSPF_SUMMARY_LSA), | |
3005 | ospf_lsdb_checksum(area->lsdb, OSPF_SUMMARY_LSA)); | |
3006 | vty_out(vty, | |
3007 | " Number of ASBR summary LSA %ld. Checksum Sum 0x%08x\n", | |
3008 | ospf_lsdb_count(area->lsdb, OSPF_ASBR_SUMMARY_LSA), | |
3009 | ospf_lsdb_checksum(area->lsdb, OSPF_ASBR_SUMMARY_LSA)); | |
3010 | vty_out(vty, " Number of NSSA LSA %ld. Checksum Sum 0x%08x\n", | |
3011 | ospf_lsdb_count(area->lsdb, OSPF_AS_NSSA_LSA), | |
3012 | ospf_lsdb_checksum(area->lsdb, OSPF_AS_NSSA_LSA)); | |
3013 | } | |
3014 | ||
3015 | if (use_json) { | |
3016 | json_object_int_add( | |
3017 | json_area, "lsaOpaqueLinkNumber", | |
3018 | ospf_lsdb_count(area->lsdb, OSPF_OPAQUE_LINK_LSA)); | |
3019 | json_object_int_add( | |
3020 | json_area, "lsaOpaqueLinkChecksum", | |
3021 | ospf_lsdb_checksum(area->lsdb, OSPF_OPAQUE_LINK_LSA)); | |
3022 | json_object_int_add( | |
3023 | json_area, "lsaOpaqueAreaNumber", | |
3024 | ospf_lsdb_count(area->lsdb, OSPF_OPAQUE_AREA_LSA)); | |
3025 | json_object_int_add( | |
3026 | json_area, "lsaOpaqueAreaChecksum", | |
3027 | ospf_lsdb_checksum(area->lsdb, OSPF_OPAQUE_AREA_LSA)); | |
3028 | } else { | |
3029 | vty_out(vty, | |
3030 | " Number of opaque link LSA %ld. Checksum Sum 0x%08x\n", | |
3031 | ospf_lsdb_count(area->lsdb, OSPF_OPAQUE_LINK_LSA), | |
3032 | ospf_lsdb_checksum(area->lsdb, OSPF_OPAQUE_LINK_LSA)); | |
3033 | vty_out(vty, | |
3034 | " Number of opaque area LSA %ld. Checksum Sum 0x%08x\n", | |
3035 | ospf_lsdb_count(area->lsdb, OSPF_OPAQUE_AREA_LSA), | |
3036 | ospf_lsdb_checksum(area->lsdb, OSPF_OPAQUE_AREA_LSA)); | |
3037 | } | |
718e3744 | 3038 | |
d62a17ae | 3039 | if (use_json) |
96b663a3 MS |
3040 | json_object_object_add(json_areas, |
3041 | inet_ntop(AF_INET, &area->area_id, | |
3042 | buf, sizeof(buf)), | |
d62a17ae | 3043 | json_area); |
3044 | else | |
3045 | vty_out(vty, "\n"); | |
718e3744 | 3046 | } |
3047 | ||
d62a17ae | 3048 | static int show_ip_ospf_common(struct vty *vty, struct ospf *ospf, |
d7c0a89a | 3049 | json_object *json, uint8_t use_vrf) |
d62a17ae | 3050 | { |
3051 | struct listnode *node, *nnode; | |
3052 | struct ospf_area *area; | |
3053 | struct timeval result; | |
3054 | char timebuf[OSPF_TIME_DUMP_SIZE]; | |
96b663a3 | 3055 | char buf[PREFIX_STRLEN]; |
b1c3ae8c | 3056 | json_object *json_vrf = NULL; |
d62a17ae | 3057 | json_object *json_areas = NULL; |
718e3744 | 3058 | |
b1c3ae8c CS |
3059 | if (json) { |
3060 | if (use_vrf) | |
3061 | json_vrf = json_object_new_object(); | |
3062 | else | |
3063 | json_vrf = json; | |
d62a17ae | 3064 | json_areas = json_object_new_object(); |
3065 | } | |
3066 | ||
3067 | if (ospf->instance) { | |
b1c3ae8c | 3068 | if (json) { |
d62a17ae | 3069 | json_object_int_add(json, "ospfInstance", |
3070 | ospf->instance); | |
3071 | } else { | |
3072 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
3073 | } | |
3074 | } | |
3075 | ||
b1c3ae8c | 3076 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); |
87bd50e8 | 3077 | |
d62a17ae | 3078 | /* Show Router ID. */ |
b1c3ae8c CS |
3079 | if (json) { |
3080 | json_object_string_add(json_vrf, "routerId", | |
96b663a3 MS |
3081 | inet_ntop(AF_INET, &ospf->router_id, |
3082 | buf, sizeof(buf))); | |
d62a17ae | 3083 | } else { |
96b663a3 MS |
3084 | vty_out(vty, " OSPF Routing Process, Router ID: %pI4\n", |
3085 | &ospf->router_id); | |
d62a17ae | 3086 | } |
3087 | ||
3088 | /* Graceful shutdown */ | |
3089 | if (ospf->t_deferred_shutdown) { | |
b1c3ae8c | 3090 | if (json) { |
d62a17ae | 3091 | long time_store; |
3092 | time_store = | |
3093 | monotime_until( | |
3094 | &ospf->t_deferred_shutdown->u.sands, | |
3095 | NULL) | |
3096 | / 1000LL; | |
b1c3ae8c | 3097 | json_object_int_add(json_vrf, "deferredShutdownMsecs", |
d62a17ae | 3098 | time_store); |
3099 | } else { | |
3100 | vty_out(vty, | |
3101 | " Deferred shutdown in progress, %s remaining\n", | |
3102 | ospf_timer_dump(ospf->t_deferred_shutdown, | |
3103 | timebuf, sizeof(timebuf))); | |
3104 | } | |
3105 | } | |
3106 | ||
3107 | /* Show capability. */ | |
b1c3ae8c CS |
3108 | if (json) { |
3109 | json_object_boolean_true_add(json_vrf, "tosRoutesOnly"); | |
3110 | json_object_boolean_true_add(json_vrf, "rfc2328Conform"); | |
d62a17ae | 3111 | if (CHECK_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE)) { |
b1c3ae8c | 3112 | json_object_boolean_true_add(json_vrf, |
d62a17ae | 3113 | "rfc1583Compatibility"); |
3114 | } | |
3115 | } else { | |
3116 | vty_out(vty, " Supports only single TOS (TOS0) routes\n"); | |
3117 | vty_out(vty, " This implementation conforms to RFC2328\n"); | |
3118 | vty_out(vty, " RFC1583Compatibility flag is %s\n", | |
3119 | CHECK_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE) | |
3120 | ? "enabled" | |
3121 | : "disabled"); | |
3122 | } | |
3123 | ||
b1c3ae8c | 3124 | if (json) { |
d62a17ae | 3125 | if (CHECK_FLAG(ospf->config, OSPF_OPAQUE_CAPABLE)) { |
b1c3ae8c | 3126 | json_object_boolean_true_add(json_vrf, "opaqueCapable"); |
d62a17ae | 3127 | } |
3128 | } else { | |
3129 | vty_out(vty, " OpaqueCapability flag is %s\n", | |
3130 | CHECK_FLAG(ospf->config, OSPF_OPAQUE_CAPABLE) | |
3131 | ? "enabled" | |
3132 | : "disabled"); | |
3133 | } | |
3134 | ||
3135 | /* Show stub-router configuration */ | |
3136 | if (ospf->stub_router_startup_time != OSPF_STUB_ROUTER_UNCONFIGURED | |
3137 | || ospf->stub_router_shutdown_time | |
3138 | != OSPF_STUB_ROUTER_UNCONFIGURED) { | |
b1c3ae8c CS |
3139 | if (json) { |
3140 | json_object_boolean_true_add(json_vrf, | |
3141 | "stubAdvertisement"); | |
d62a17ae | 3142 | if (ospf->stub_router_startup_time |
3143 | != OSPF_STUB_ROUTER_UNCONFIGURED) | |
3144 | json_object_int_add( | |
50ad4b42 MS |
3145 | json_vrf, "postStartEnabledSecs", |
3146 | ospf->stub_router_startup_time); | |
d62a17ae | 3147 | if (ospf->stub_router_shutdown_time |
3148 | != OSPF_STUB_ROUTER_UNCONFIGURED) | |
3149 | json_object_int_add( | |
50ad4b42 MS |
3150 | json_vrf, "preShutdownEnabledSecs", |
3151 | ospf->stub_router_shutdown_time); | |
d62a17ae | 3152 | } else { |
3153 | vty_out(vty, | |
3154 | " Stub router advertisement is configured\n"); | |
3155 | if (ospf->stub_router_startup_time | |
3156 | != OSPF_STUB_ROUTER_UNCONFIGURED) | |
3157 | vty_out(vty, | |
3158 | " Enabled for %us after start-up\n", | |
3159 | ospf->stub_router_startup_time); | |
3160 | if (ospf->stub_router_shutdown_time | |
3161 | != OSPF_STUB_ROUTER_UNCONFIGURED) | |
3162 | vty_out(vty, | |
3163 | " Enabled for %us prior to full shutdown\n", | |
3164 | ospf->stub_router_shutdown_time); | |
3165 | } | |
3166 | } | |
3167 | ||
3168 | /* Show SPF timers. */ | |
b1c3ae8c CS |
3169 | if (json) { |
3170 | json_object_int_add(json_vrf, "spfScheduleDelayMsecs", | |
d62a17ae | 3171 | ospf->spf_delay); |
b1c3ae8c | 3172 | json_object_int_add(json_vrf, "holdtimeMinMsecs", |
d62a17ae | 3173 | ospf->spf_holdtime); |
b1c3ae8c | 3174 | json_object_int_add(json_vrf, "holdtimeMaxMsecs", |
d62a17ae | 3175 | ospf->spf_max_holdtime); |
b1c3ae8c | 3176 | json_object_int_add(json_vrf, "holdtimeMultplier", |
d62a17ae | 3177 | ospf->spf_hold_multiplier); |
3178 | } else { | |
3179 | vty_out(vty, | |
3180 | " Initial SPF scheduling delay %d millisec(s)\n" | |
3181 | " Minimum hold time between consecutive SPFs %d millisec(s)\n" | |
3182 | " Maximum hold time between consecutive SPFs %d millisec(s)\n" | |
3183 | " Hold time multiplier is currently %d\n", | |
3184 | ospf->spf_delay, ospf->spf_holdtime, | |
3185 | ospf->spf_max_holdtime, ospf->spf_hold_multiplier); | |
3186 | } | |
3187 | ||
b1c3ae8c | 3188 | if (json) { |
d62a17ae | 3189 | if (ospf->ts_spf.tv_sec || ospf->ts_spf.tv_usec) { |
3190 | long time_store = 0; | |
3191 | ||
3192 | time_store = | |
3193 | monotime_since(&ospf->ts_spf, NULL) / 1000LL; | |
b1c3ae8c | 3194 | json_object_int_add(json_vrf, "spfLastExecutedMsecs", |
d62a17ae | 3195 | time_store); |
3196 | ||
3197 | time_store = (1000 * ospf->ts_spf_duration.tv_sec) | |
3198 | + (ospf->ts_spf_duration.tv_usec / 1000); | |
b1c3ae8c | 3199 | json_object_int_add(json_vrf, "spfLastDurationMsecs", |
d62a17ae | 3200 | time_store); |
3201 | } else | |
b1c3ae8c | 3202 | json_object_boolean_true_add(json_vrf, "spfHasNotRun"); |
d62a17ae | 3203 | } else { |
3204 | vty_out(vty, " SPF algorithm "); | |
3205 | if (ospf->ts_spf.tv_sec || ospf->ts_spf.tv_usec) { | |
3206 | monotime_since(&ospf->ts_spf, &result); | |
3207 | vty_out(vty, "last executed %s ago\n", | |
3208 | ospf_timeval_dump(&result, timebuf, | |
3209 | sizeof(timebuf))); | |
3210 | vty_out(vty, " Last SPF duration %s\n", | |
3211 | ospf_timeval_dump(&ospf->ts_spf_duration, | |
3212 | timebuf, sizeof(timebuf))); | |
3213 | } else | |
3214 | vty_out(vty, "has not been run\n"); | |
3215 | } | |
3216 | ||
b1c3ae8c | 3217 | if (json) { |
d62a17ae | 3218 | if (ospf->t_spf_calc) { |
3219 | long time_store; | |
3220 | time_store = | |
3221 | monotime_until(&ospf->t_spf_calc->u.sands, NULL) | |
3222 | / 1000LL; | |
b1c3ae8c | 3223 | json_object_int_add(json_vrf, "spfTimerDueInMsecs", |
d62a17ae | 3224 | time_store); |
3225 | } | |
3226 | ||
b1c3ae8c | 3227 | json_object_int_add(json_vrf, "lsaMinIntervalMsecs", |
d62a17ae | 3228 | ospf->min_ls_interval); |
b1c3ae8c | 3229 | json_object_int_add(json_vrf, "lsaMinArrivalMsecs", |
d62a17ae | 3230 | ospf->min_ls_arrival); |
3231 | /* Show write multiplier values */ | |
b1c3ae8c | 3232 | json_object_int_add(json_vrf, "writeMultiplier", |
d62a17ae | 3233 | ospf->write_oi_count); |
3234 | /* Show refresh parameters. */ | |
b1c3ae8c | 3235 | json_object_int_add(json_vrf, "refreshTimerMsecs", |
d62a17ae | 3236 | ospf->lsa_refresh_interval * 1000); |
3237 | } else { | |
3238 | vty_out(vty, " SPF timer %s%s\n", | |
3239 | (ospf->t_spf_calc ? "due in " : "is "), | |
3240 | ospf_timer_dump(ospf->t_spf_calc, timebuf, | |
3241 | sizeof(timebuf))); | |
3242 | ||
3243 | vty_out(vty, " LSA minimum interval %d msecs\n", | |
3244 | ospf->min_ls_interval); | |
3245 | vty_out(vty, " LSA minimum arrival %d msecs\n", | |
3246 | ospf->min_ls_arrival); | |
3247 | ||
3248 | /* Show write multiplier values */ | |
3249 | vty_out(vty, " Write Multiplier set to %d \n", | |
3250 | ospf->write_oi_count); | |
3251 | ||
3252 | /* Show refresh parameters. */ | |
3253 | vty_out(vty, " Refresh timer %d secs\n", | |
3254 | ospf->lsa_refresh_interval); | |
3d5b9855 | 3255 | |
3256 | /* show max multipath */ | |
3257 | vty_out(vty, " Maximum multiple paths(ECMP) supported %d\n", | |
3258 | ospf->max_multipath); | |
d62a17ae | 3259 | } |
3260 | ||
3261 | /* Show ABR/ASBR flags. */ | |
3262 | if (CHECK_FLAG(ospf->flags, OSPF_FLAG_ABR)) { | |
b1c3ae8c | 3263 | if (json) |
d62a17ae | 3264 | json_object_string_add( |
b1c3ae8c | 3265 | json_vrf, "abrType", |
d62a17ae | 3266 | ospf_abr_type_descr_str[ospf->abr_type]); |
3267 | else | |
3268 | vty_out(vty, | |
3269 | " This router is an ABR, ABR type is: %s\n", | |
3270 | ospf_abr_type_descr_str[ospf->abr_type]); | |
3271 | } | |
3272 | if (CHECK_FLAG(ospf->flags, OSPF_FLAG_ASBR)) { | |
b1c3ae8c | 3273 | if (json) |
d62a17ae | 3274 | json_object_string_add( |
b1c3ae8c | 3275 | json_vrf, "asbrRouter", |
d62a17ae | 3276 | "injectingExternalRoutingInformation"); |
3277 | else | |
3278 | vty_out(vty, | |
3efd0893 | 3279 | " This router is an ASBR (injecting external routing information)\n"); |
d62a17ae | 3280 | } |
3281 | ||
3282 | /* Show Number of AS-external-LSAs. */ | |
b1c3ae8c | 3283 | if (json) { |
d62a17ae | 3284 | json_object_int_add( |
b1c3ae8c | 3285 | json_vrf, "lsaExternalCounter", |
d62a17ae | 3286 | ospf_lsdb_count(ospf->lsdb, OSPF_AS_EXTERNAL_LSA)); |
3287 | json_object_int_add( | |
b1c3ae8c | 3288 | json_vrf, "lsaExternalChecksum", |
d62a17ae | 3289 | ospf_lsdb_checksum(ospf->lsdb, OSPF_AS_EXTERNAL_LSA)); |
3290 | } else { | |
3291 | vty_out(vty, | |
3292 | " Number of external LSA %ld. Checksum Sum 0x%08x\n", | |
3293 | ospf_lsdb_count(ospf->lsdb, OSPF_AS_EXTERNAL_LSA), | |
3294 | ospf_lsdb_checksum(ospf->lsdb, OSPF_AS_EXTERNAL_LSA)); | |
3295 | } | |
3296 | ||
b1c3ae8c | 3297 | if (json) { |
d62a17ae | 3298 | json_object_int_add( |
b1c3ae8c | 3299 | json_vrf, "lsaAsopaqueCounter", |
d62a17ae | 3300 | ospf_lsdb_count(ospf->lsdb, OSPF_OPAQUE_AS_LSA)); |
3301 | json_object_int_add( | |
b1c3ae8c | 3302 | json_vrf, "lsaAsOpaqueChecksum", |
d62a17ae | 3303 | ospf_lsdb_checksum(ospf->lsdb, OSPF_OPAQUE_AS_LSA)); |
3304 | } else { | |
3305 | vty_out(vty, | |
3306 | " Number of opaque AS LSA %ld. Checksum Sum 0x%08x\n", | |
3307 | ospf_lsdb_count(ospf->lsdb, OSPF_OPAQUE_AS_LSA), | |
3308 | ospf_lsdb_checksum(ospf->lsdb, OSPF_OPAQUE_AS_LSA)); | |
3309 | } | |
3310 | ||
3311 | /* Show number of areas attached. */ | |
b1c3ae8c CS |
3312 | if (json) |
3313 | json_object_int_add(json_vrf, "attachedAreaCounter", | |
d62a17ae | 3314 | listcount(ospf->areas)); |
3315 | else | |
3316 | vty_out(vty, " Number of areas attached to this router: %d\n", | |
3317 | listcount(ospf->areas)); | |
3318 | ||
3319 | if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES)) { | |
3320 | if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL)) { | |
b1c3ae8c | 3321 | if (json) |
d62a17ae | 3322 | json_object_boolean_true_add( |
b1c3ae8c | 3323 | json_vrf, "adjacencyChangesLoggedAll"); |
d62a17ae | 3324 | else |
3325 | vty_out(vty, | |
3326 | " All adjacency changes are logged\n"); | |
3327 | } else { | |
b1c3ae8c | 3328 | if (json) |
d62a17ae | 3329 | json_object_boolean_true_add( |
b1c3ae8c | 3330 | json_vrf, "adjacencyChangesLogged"); |
d62a17ae | 3331 | else |
3332 | vty_out(vty, " Adjacency changes are logged\n"); | |
3333 | } | |
3334 | } | |
132a782e | 3335 | |
3336 | /* show LDP-Sync status */ | |
3337 | ospf_ldp_sync_show_info(vty, ospf, json_vrf, json ? 1 : 0); | |
3338 | ||
d62a17ae | 3339 | /* Show each area status. */ |
3340 | for (ALL_LIST_ELEMENTS(ospf->areas, node, nnode, area)) | |
b1c3ae8c CS |
3341 | show_ip_ospf_area(vty, area, json_areas, json ? 1 : 0); |
3342 | ||
3343 | if (json) { | |
3344 | if (use_vrf) { | |
3345 | json_object_object_add(json_vrf, "areas", json_areas); | |
3346 | if (ospf->vrf_id == VRF_DEFAULT) | |
3347 | json_object_object_add(json, "default", | |
3348 | json_vrf); | |
3349 | else | |
3350 | json_object_object_add(json, ospf->name, | |
3351 | json_vrf); | |
3352 | } else { | |
3353 | json_object_object_add(json, "areas", json_areas); | |
3354 | } | |
d62a17ae | 3355 | } else |
3356 | vty_out(vty, "\n"); | |
3357 | ||
3358 | return CMD_SUCCESS; | |
718e3744 | 3359 | } |
3360 | ||
7c8ff89e DS |
3361 | DEFUN (show_ip_ospf, |
3362 | show_ip_ospf_cmd, | |
b5a8894d | 3363 | "show ip ospf [vrf <NAME|all>] [json]", |
7c8ff89e DS |
3364 | SHOW_STR |
3365 | IP_STR | |
ca08c43d | 3366 | "OSPF information\n" |
b5a8894d CS |
3367 | VRF_CMD_HELP_STR |
3368 | "All VRFs\n" | |
9973d184 | 3369 | JSON_STR) |
7c8ff89e | 3370 | { |
d62a17ae | 3371 | struct ospf *ospf; |
9f049418 | 3372 | bool uj = use_json(argc, argv); |
b5a8894d CS |
3373 | struct listnode *node = NULL; |
3374 | char *vrf_name = NULL; | |
2951a7a4 | 3375 | bool all_vrf = false; |
b5a8894d CS |
3376 | int ret = CMD_SUCCESS; |
3377 | int inst = 0; | |
3378 | int idx_vrf = 0; | |
b1c3ae8c | 3379 | json_object *json = NULL; |
d7c0a89a | 3380 | uint8_t use_vrf = 0; |
7c8ff89e | 3381 | |
b5a8894d | 3382 | if (listcount(om->ospf) == 0) |
d62a17ae | 3383 | return CMD_SUCCESS; |
7c8ff89e | 3384 | |
43b8d1d8 | 3385 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
b5a8894d | 3386 | |
b1c3ae8c CS |
3387 | if (uj) |
3388 | json = json_object_new_object(); | |
3389 | ||
996c9314 | 3390 | /* vrf input is provided could be all or specific vrf*/ |
b5a8894d | 3391 | if (vrf_name) { |
2951a7a4 | 3392 | bool ospf_output = false; |
874f58d8 | 3393 | |
b1c3ae8c | 3394 | use_vrf = 1; |
94d4c685 | 3395 | |
b5a8894d CS |
3396 | if (all_vrf) { |
3397 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
3398 | if (!ospf->oi_running) | |
3399 | continue; | |
2951a7a4 | 3400 | ospf_output = true; |
b1c3ae8c CS |
3401 | ret = show_ip_ospf_common(vty, ospf, json, |
3402 | use_vrf); | |
3403 | } | |
3404 | if (uj) { | |
3405 | vty_out(vty, "%s\n", | |
996c9314 LB |
3406 | json_object_to_json_string_ext( |
3407 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 3408 | json_object_free(json); |
9f049418 DS |
3409 | } else if (!ospf_output) |
3410 | vty_out(vty, "%% OSPF instance not found\n"); | |
b5a8894d CS |
3411 | return ret; |
3412 | } | |
3413 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
b1c3ae8c | 3414 | if ((ospf == NULL) || !ospf->oi_running) { |
9f049418 DS |
3415 | if (uj) { |
3416 | vty_out(vty, "%s\n", | |
3417 | json_object_to_json_string_ext( | |
3418 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 3419 | json_object_free(json); |
9f049418 | 3420 | } else |
94d4c685 | 3421 | vty_out(vty, "%% OSPF instance not found\n"); |
9f049418 | 3422 | |
b5a8894d | 3423 | return CMD_SUCCESS; |
b1c3ae8c | 3424 | } |
b5a8894d CS |
3425 | } else { |
3426 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
3427 | /* Display default ospf (instance 0) info */ | |
b1c3ae8c | 3428 | if (ospf == NULL || !ospf->oi_running) { |
9f049418 DS |
3429 | if (uj) { |
3430 | vty_out(vty, "%s\n", | |
3431 | json_object_to_json_string_ext( | |
3432 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 3433 | json_object_free(json); |
9f049418 | 3434 | } else |
94d4c685 | 3435 | vty_out(vty, "%% OSPF instance not found\n"); |
9f049418 | 3436 | |
b5a8894d | 3437 | return CMD_SUCCESS; |
b1c3ae8c | 3438 | } |
b5a8894d CS |
3439 | } |
3440 | ||
996c9314 | 3441 | if (ospf) { |
b1c3ae8c CS |
3442 | show_ip_ospf_common(vty, ospf, json, use_vrf); |
3443 | if (uj) | |
996c9314 LB |
3444 | vty_out(vty, "%s\n", |
3445 | json_object_to_json_string_ext( | |
3446 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c CS |
3447 | } |
3448 | ||
3449 | if (uj) | |
3450 | json_object_free(json); | |
b5a8894d CS |
3451 | |
3452 | return ret; | |
7c8ff89e DS |
3453 | } |
3454 | ||
3455 | DEFUN (show_ip_ospf_instance, | |
3456 | show_ip_ospf_instance_cmd, | |
6147e2c6 | 3457 | "show ip ospf (1-65535) [json]", |
7c8ff89e DS |
3458 | SHOW_STR |
3459 | IP_STR | |
3460 | "OSPF information\n" | |
ca08c43d | 3461 | "Instance ID\n" |
9973d184 | 3462 | JSON_STR) |
7c8ff89e | 3463 | { |
d62a17ae | 3464 | int idx_number = 3; |
3465 | struct ospf *ospf; | |
d7c0a89a | 3466 | unsigned short instance = 0; |
9f049418 | 3467 | bool uj = use_json(argc, argv); |
b1c3ae8c CS |
3468 | int ret = CMD_SUCCESS; |
3469 | json_object *json = NULL; | |
d62a17ae | 3470 | |
3471 | instance = strtoul(argv[idx_number]->arg, NULL, 10); | |
409f98ab | 3472 | if (instance != ospf_instance) |
ac28e4ec CS |
3473 | return CMD_NOT_MY_INSTANCE; |
3474 | ||
409f98ab IR |
3475 | ospf = ospf_lookup_instance(instance); |
3476 | if (!ospf || !ospf->oi_running) | |
d62a17ae | 3477 | return CMD_SUCCESS; |
3478 | ||
b1c3ae8c CS |
3479 | if (uj) |
3480 | json = json_object_new_object(); | |
3481 | ||
3482 | ret = show_ip_ospf_common(vty, ospf, json, 0); | |
3483 | ||
3484 | if (uj) { | |
996c9314 LB |
3485 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
3486 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c CS |
3487 | json_object_free(json); |
3488 | } | |
3489 | ||
3490 | return ret; | |
d62a17ae | 3491 | } |
3492 | ||
49498934 | 3493 | static void ospf_interface_auth_show(struct vty *vty, struct ospf_interface *oi, |
3494 | json_object *json, bool use_json) | |
3495 | { | |
3496 | int auth_type; | |
3497 | ||
3498 | auth_type = OSPF_IF_PARAM(oi, auth_type); | |
3499 | ||
3500 | switch (auth_type) { | |
3501 | case OSPF_AUTH_NULL: | |
3502 | if (use_json) | |
3503 | json_object_string_add(json, "authentication", | |
3504 | "authenticationNone"); | |
3505 | else | |
3506 | vty_out(vty, " Authentication NULL is enabled\n"); | |
3507 | break; | |
3508 | case OSPF_AUTH_SIMPLE: { | |
3509 | if (use_json) | |
3510 | json_object_string_add(json, "authentication", | |
3511 | "authenticationSimplePassword"); | |
3512 | else | |
3513 | vty_out(vty, | |
3514 | " Simple password authentication enabled\n"); | |
3515 | break; | |
3516 | } | |
3517 | case OSPF_AUTH_CRYPTOGRAPHIC: { | |
3518 | struct crypt_key *ckey; | |
3519 | ||
3520 | if (list_isempty(OSPF_IF_PARAM(oi, auth_crypt))) | |
3521 | return; | |
3522 | ||
3523 | ckey = listgetdata(listtail(OSPF_IF_PARAM(oi, auth_crypt))); | |
3524 | if (ckey) { | |
3525 | if (use_json) { | |
3526 | json_object_string_add(json, "authentication", | |
3527 | "authenticationMessageDigest"); | |
3528 | } else { | |
3529 | vty_out(vty, | |
3530 | " Cryptographic authentication enabled\n"); | |
3531 | vty_out(vty, " Algorithm:MD5\n"); | |
3532 | } | |
3533 | } | |
3534 | break; | |
3535 | } | |
3536 | default: | |
3537 | break; | |
3538 | } | |
3539 | } | |
3540 | ||
d62a17ae | 3541 | static void show_ip_ospf_interface_sub(struct vty *vty, struct ospf *ospf, |
3542 | struct interface *ifp, | |
3543 | json_object *json_interface_sub, | |
9f049418 | 3544 | bool use_json) |
d62a17ae | 3545 | { |
3546 | int is_up; | |
3547 | struct ospf_neighbor *nbr; | |
3548 | struct route_node *rn; | |
96b663a3 | 3549 | char buf[PREFIX_STRLEN]; |
d62a17ae | 3550 | uint32_t bandwidth = ifp->bandwidth ? ifp->bandwidth : ifp->speed; |
3551 | ||
3552 | /* Is interface up? */ | |
3553 | if (use_json) { | |
3554 | is_up = if_is_operative(ifp); | |
3555 | if (is_up) | |
3556 | json_object_boolean_true_add(json_interface_sub, | |
3557 | "ifUp"); | |
3558 | else | |
3559 | json_object_boolean_false_add(json_interface_sub, | |
3560 | "ifDown"); | |
3561 | ||
3562 | json_object_int_add(json_interface_sub, "ifIndex", | |
3563 | ifp->ifindex); | |
3564 | json_object_int_add(json_interface_sub, "mtuBytes", ifp->mtu); | |
3565 | json_object_int_add(json_interface_sub, "bandwidthMbit", | |
3566 | bandwidth); | |
3567 | json_object_string_add(json_interface_sub, "ifFlags", | |
3568 | if_flag_dump(ifp->flags)); | |
3569 | } else { | |
3570 | vty_out(vty, "%s is %s\n", ifp->name, | |
3571 | ((is_up = if_is_operative(ifp)) ? "up" : "down")); | |
3572 | vty_out(vty, " ifindex %u, MTU %u bytes, BW %u Mbit %s\n", | |
3573 | ifp->ifindex, ifp->mtu, bandwidth, | |
3574 | if_flag_dump(ifp->flags)); | |
3575 | } | |
7c8ff89e | 3576 | |
d62a17ae | 3577 | /* Is interface OSPF enabled? */ |
3578 | if (use_json) { | |
3579 | if (ospf_oi_count(ifp) == 0) { | |
3580 | json_object_boolean_false_add(json_interface_sub, | |
3581 | "ospfEnabled"); | |
3582 | return; | |
3583 | } else if (!is_up) { | |
3584 | json_object_boolean_false_add(json_interface_sub, | |
3585 | "ospfRunning"); | |
3586 | return; | |
3587 | } else | |
3588 | json_object_boolean_true_add(json_interface_sub, | |
3589 | "ospfEnabled"); | |
3590 | } else { | |
3591 | if (ospf_oi_count(ifp) == 0) { | |
3592 | vty_out(vty, " OSPF not enabled on this interface\n"); | |
3593 | return; | |
3594 | } else if (!is_up) { | |
3595 | vty_out(vty, | |
3596 | " OSPF is enabled, but not running on this interface\n"); | |
3597 | return; | |
3598 | } | |
3599 | } | |
3600 | ||
3601 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { | |
3602 | struct ospf_interface *oi = rn->info; | |
3603 | ||
3604 | if (oi == NULL) | |
3605 | continue; | |
3606 | ||
3607 | if (CHECK_FLAG(oi->connected->flags, ZEBRA_IFA_UNNUMBERED)) { | |
3608 | if (use_json) | |
3609 | json_object_boolean_true_add(json_interface_sub, | |
3610 | "ifUnnumbered"); | |
3611 | else | |
3612 | vty_out(vty, " This interface is UNNUMBERED,"); | |
3613 | } else { | |
0f3af738 JW |
3614 | struct in_addr dest; |
3615 | const char *dstr; | |
3616 | ||
d62a17ae | 3617 | /* Show OSPF interface information. */ |
3618 | if (use_json) { | |
3619 | json_object_string_add( | |
3620 | json_interface_sub, "ipAddress", | |
96b663a3 MS |
3621 | inet_ntop(AF_INET, |
3622 | &oi->address->u.prefix4, | |
3623 | buf, sizeof(buf))); | |
d62a17ae | 3624 | json_object_int_add(json_interface_sub, |
3625 | "ipAddressPrefixlen", | |
3626 | oi->address->prefixlen); | |
3627 | } else | |
ae32e1c2 DS |
3628 | vty_out(vty, " Internet Address %pFX,", |
3629 | oi->address); | |
d62a17ae | 3630 | |
0f3af738 JW |
3631 | /* For Vlinks, showing the peer address is |
3632 | * probably more informative than the local | |
3633 | * interface that is being used */ | |
3634 | if (oi->type == OSPF_IFTYPE_VIRTUALLINK) { | |
3635 | dstr = "Peer"; | |
3636 | dest = oi->vl_data->peer_addr; | |
3637 | } else if (CONNECTED_PEER(oi->connected) | |
3638 | && oi->connected->destination) { | |
3639 | dstr = "Peer"; | |
3640 | dest = oi->connected->destination->u.prefix4; | |
3641 | } else { | |
3642 | dstr = "Broadcast"; | |
3643 | dest.s_addr = ipv4_broadcast_addr( | |
3644 | oi->connected->address->u.prefix4.s_addr, | |
3645 | oi->connected->address->prefixlen); | |
3646 | } | |
d62a17ae | 3647 | |
0f3af738 JW |
3648 | if (use_json) { |
3649 | json_object_string_add( | |
3650 | json_interface_sub, | |
3651 | "ospfIfType", dstr); | |
d62a17ae | 3652 | if (oi->type == OSPF_IFTYPE_VIRTUALLINK) |
0f3af738 JW |
3653 | json_object_string_add( |
3654 | json_interface_sub, | |
3655 | "vlinkPeer", | |
96b663a3 MS |
3656 | inet_ntop(AF_INET, &dest, |
3657 | buf, sizeof(buf))); | |
d62a17ae | 3658 | else |
d62a17ae | 3659 | json_object_string_add( |
3660 | json_interface_sub, | |
0f3af738 | 3661 | "localIfUsed", |
96b663a3 MS |
3662 | inet_ntop(AF_INET, &dest, |
3663 | buf, sizeof(buf))); | |
0f3af738 | 3664 | } else |
96b663a3 MS |
3665 | vty_out(vty, " %s %pI4,", dstr, |
3666 | &dest); | |
d62a17ae | 3667 | } |
3668 | if (use_json) { | |
3669 | json_object_string_add(json_interface_sub, "area", | |
3670 | ospf_area_desc_string(oi->area)); | |
3671 | if (OSPF_IF_PARAM(oi, mtu_ignore)) | |
3672 | json_object_boolean_true_add( | |
3673 | json_interface_sub, | |
3674 | "mtuMismatchDetect"); | |
96b663a3 MS |
3675 | json_object_string_add( |
3676 | json_interface_sub, "routerId", | |
3677 | inet_ntop(AF_INET, &ospf->router_id, | |
3678 | buf, sizeof(buf))); | |
d62a17ae | 3679 | json_object_string_add(json_interface_sub, |
3680 | "networkType", | |
3681 | ospf_network_type_str[oi->type]); | |
3682 | json_object_int_add(json_interface_sub, "cost", | |
3683 | oi->output_cost); | |
3684 | json_object_int_add( | |
50ad4b42 MS |
3685 | json_interface_sub, "transmitDelaySecs", |
3686 | OSPF_IF_PARAM(oi, transmit_delay)); | |
d62a17ae | 3687 | json_object_string_add(json_interface_sub, "state", |
3688 | lookup_msg(ospf_ism_state_msg, | |
3689 | oi->state, NULL)); | |
3690 | json_object_int_add(json_interface_sub, "priority", | |
3691 | PRIORITY(oi)); | |
3692 | } else { | |
3693 | vty_out(vty, " Area %s\n", | |
3694 | ospf_area_desc_string(oi->area)); | |
3695 | ||
3696 | vty_out(vty, " MTU mismatch detection: %s\n", | |
3697 | OSPF_IF_PARAM(oi, mtu_ignore) ? "disabled" | |
3698 | : "enabled"); | |
3699 | ||
3700 | vty_out(vty, | |
96b663a3 MS |
3701 | " Router ID %pI4, Network Type %s, Cost: %d\n", |
3702 | &ospf->router_id, | |
d62a17ae | 3703 | ospf_network_type_str[oi->type], |
3704 | oi->output_cost); | |
3705 | ||
3706 | vty_out(vty, | |
3707 | " Transmit Delay is %d sec, State %s, Priority %d\n", | |
3708 | OSPF_IF_PARAM(oi, transmit_delay), | |
3709 | lookup_msg(ospf_ism_state_msg, oi->state, NULL), | |
3710 | PRIORITY(oi)); | |
3711 | } | |
3712 | ||
3713 | /* Show DR information. */ | |
975a328e | 3714 | if (DR(oi).s_addr == INADDR_ANY) { |
d62a17ae | 3715 | if (!use_json) |
3716 | vty_out(vty, | |
3717 | " No backup designated router on this network\n"); | |
3718 | } else { | |
2fbb8f45 | 3719 | nbr = ospf_nbr_lookup_by_addr(oi->nbrs, &DR(oi)); |
3720 | if (nbr) { | |
3721 | if (use_json) { | |
3722 | json_object_string_add( | |
3723 | json_interface_sub, "drId", | |
3724 | inet_ntop(AF_INET, | |
3725 | &nbr->router_id, buf, | |
3726 | sizeof(buf))); | |
3727 | json_object_string_add( | |
3728 | json_interface_sub, "drAddress", | |
3729 | inet_ntop( | |
3730 | AF_INET, | |
3731 | &nbr->address.u.prefix4, | |
3732 | buf, sizeof(buf))); | |
3733 | } else { | |
3734 | vty_out(vty, | |
3735 | " Designated Router (ID) %pI4", | |
3736 | &nbr->router_id); | |
3737 | vty_out(vty, | |
3738 | " Interface Address %pFX\n", | |
3739 | &nbr->address); | |
3740 | } | |
3741 | } | |
3742 | nbr = NULL; | |
3743 | ||
d62a17ae | 3744 | nbr = ospf_nbr_lookup_by_addr(oi->nbrs, &BDR(oi)); |
3745 | if (nbr == NULL) { | |
3746 | if (!use_json) | |
3747 | vty_out(vty, | |
3748 | " No backup designated router on this network\n"); | |
3749 | } else { | |
3750 | if (use_json) { | |
3751 | json_object_string_add( | |
3752 | json_interface_sub, "bdrId", | |
96b663a3 MS |
3753 | inet_ntop(AF_INET, |
3754 | &nbr->router_id, | |
3755 | buf, sizeof(buf))); | |
d62a17ae | 3756 | json_object_string_add( |
3757 | json_interface_sub, | |
3758 | "bdrAddress", | |
96b663a3 MS |
3759 | inet_ntop(AF_INET, |
3760 | &nbr->address.u | |
3761 | .prefix4, | |
3762 | buf, sizeof(buf))); | |
d62a17ae | 3763 | } else { |
3764 | vty_out(vty, | |
96b663a3 MS |
3765 | " Backup Designated Router (ID) %pI4,", |
3766 | &nbr->router_id); | |
3767 | vty_out(vty, " Interface Address %pI4\n", | |
3768 | &nbr->address.u.prefix4); | |
d62a17ae | 3769 | } |
3770 | } | |
3771 | } | |
3772 | ||
3773 | /* Next network-LSA sequence number we'll use, if we're elected | |
3774 | * DR */ | |
3775 | if (oi->params | |
3776 | && ntohl(oi->params->network_lsa_seqnum) | |
3777 | != OSPF_INITIAL_SEQUENCE_NUMBER) { | |
3778 | if (use_json) | |
3779 | json_object_int_add( | |
3780 | json_interface_sub, | |
3781 | "networkLsaSequence", | |
3782 | ntohl(oi->params->network_lsa_seqnum)); | |
3783 | else | |
3784 | vty_out(vty, | |
3785 | " Saved Network-LSA sequence number 0x%x\n", | |
3786 | ntohl(oi->params->network_lsa_seqnum)); | |
3787 | } | |
3788 | ||
3789 | if (use_json) { | |
3790 | if (OI_MEMBER_CHECK(oi, MEMBER_ALLROUTERS) | |
3791 | || OI_MEMBER_CHECK(oi, MEMBER_DROUTERS)) { | |
3792 | if (OI_MEMBER_CHECK(oi, MEMBER_ALLROUTERS)) | |
3793 | json_object_boolean_true_add( | |
3794 | json_interface_sub, | |
3795 | "mcastMemberOspfAllRouters"); | |
3796 | if (OI_MEMBER_CHECK(oi, MEMBER_DROUTERS)) | |
3797 | json_object_boolean_true_add( | |
3798 | json_interface_sub, | |
3799 | "mcastMemberOspfDesignatedRouters"); | |
3800 | } | |
3801 | } else { | |
3802 | vty_out(vty, " Multicast group memberships:"); | |
3803 | if (OI_MEMBER_CHECK(oi, MEMBER_ALLROUTERS) | |
3804 | || OI_MEMBER_CHECK(oi, MEMBER_DROUTERS)) { | |
3805 | if (OI_MEMBER_CHECK(oi, MEMBER_ALLROUTERS)) | |
3806 | vty_out(vty, " OSPFAllRouters"); | |
3807 | if (OI_MEMBER_CHECK(oi, MEMBER_DROUTERS)) | |
3808 | vty_out(vty, " OSPFDesignatedRouters"); | |
3809 | } else | |
3810 | vty_out(vty, " <None>"); | |
3811 | vty_out(vty, "\n"); | |
3812 | } | |
3813 | ||
3814 | if (use_json) { | |
3815 | if (OSPF_IF_PARAM(oi, fast_hello) == 0) | |
3816 | json_object_int_add( | |
3817 | json_interface_sub, "timerMsecs", | |
50ad4b42 | 3818 | OSPF_IF_PARAM(oi, v_hello) * 1000); |
d62a17ae | 3819 | else |
3820 | json_object_int_add( | |
3821 | json_interface_sub, "timerMsecs", | |
50ad4b42 | 3822 | 1000 / OSPF_IF_PARAM(oi, fast_hello)); |
d62a17ae | 3823 | json_object_int_add(json_interface_sub, |
50ad4b42 MS |
3824 | "timerDeadSecs", |
3825 | OSPF_IF_PARAM(oi, v_wait)); | |
d62a17ae | 3826 | json_object_int_add(json_interface_sub, |
50ad4b42 MS |
3827 | "timerWaitSecs", |
3828 | OSPF_IF_PARAM(oi, v_wait)); | |
d62a17ae | 3829 | json_object_int_add( |
50ad4b42 MS |
3830 | json_interface_sub, "timerRetransmitSecs", |
3831 | OSPF_IF_PARAM(oi, retransmit_interval)); | |
d62a17ae | 3832 | } else { |
3833 | vty_out(vty, " Timer intervals configured,"); | |
3834 | vty_out(vty, " Hello "); | |
3835 | if (OSPF_IF_PARAM(oi, fast_hello) == 0) | |
3836 | vty_out(vty, "%ds,", | |
3837 | OSPF_IF_PARAM(oi, v_hello)); | |
3838 | else | |
3839 | vty_out(vty, "%dms,", | |
3840 | 1000 / OSPF_IF_PARAM(oi, fast_hello)); | |
3841 | vty_out(vty, " Dead %ds, Wait %ds, Retransmit %d\n", | |
3842 | OSPF_IF_PARAM(oi, v_wait), | |
3843 | OSPF_IF_PARAM(oi, v_wait), | |
3844 | OSPF_IF_PARAM(oi, retransmit_interval)); | |
3845 | } | |
3846 | ||
3847 | if (OSPF_IF_PASSIVE_STATUS(oi) == OSPF_IF_ACTIVE) { | |
3848 | char timebuf[OSPF_TIME_DUMP_SIZE]; | |
3849 | if (use_json) { | |
3850 | long time_store = 0; | |
3851 | if (oi->t_hello) | |
3852 | time_store = | |
3853 | monotime_until( | |
3854 | &oi->t_hello->u.sands, | |
3855 | NULL) | |
3856 | / 1000LL; | |
3857 | json_object_int_add(json_interface_sub, | |
3858 | "timerHelloInMsecs", | |
3859 | time_store); | |
3860 | } else | |
3861 | vty_out(vty, " Hello due in %s\n", | |
3862 | ospf_timer_dump(oi->t_hello, timebuf, | |
3863 | sizeof(timebuf))); | |
3864 | } else /* passive-interface is set */ | |
3865 | { | |
3866 | if (use_json) | |
3867 | json_object_boolean_true_add( | |
3868 | json_interface_sub, | |
3869 | "timerPassiveIface"); | |
3870 | else | |
3871 | vty_out(vty, | |
3872 | " No Hellos (Passive interface)\n"); | |
3873 | } | |
7c8ff89e | 3874 | |
d62a17ae | 3875 | if (use_json) { |
3876 | json_object_int_add(json_interface_sub, "nbrCount", | |
3877 | ospf_nbr_count(oi, 0)); | |
3878 | json_object_int_add(json_interface_sub, | |
3879 | "nbrAdjacentCount", | |
3880 | ospf_nbr_count(oi, NSM_Full)); | |
3881 | } else | |
3882 | vty_out(vty, | |
3883 | " Neighbor Count is %d, Adjacent neighbor count is %d\n", | |
3884 | ospf_nbr_count(oi, 0), | |
3885 | ospf_nbr_count(oi, NSM_Full)); | |
659f4e40 RZ |
3886 | |
3887 | ospf_interface_bfd_show(vty, ifp, json_interface_sub); | |
49498934 | 3888 | |
3889 | /* OSPF Authentication information */ | |
3890 | ospf_interface_auth_show(vty, oi, json_interface_sub, use_json); | |
d62a17ae | 3891 | } |
718e3744 | 3892 | } |
3893 | ||
d62a17ae | 3894 | static int show_ip_ospf_interface_common(struct vty *vty, struct ospf *ospf, |
d7c0a89a | 3895 | char *intf_name, uint8_t use_vrf, |
9f049418 | 3896 | json_object *json, bool use_json) |
d62a17ae | 3897 | { |
3898 | struct interface *ifp; | |
f4e14fdb | 3899 | struct vrf *vrf = vrf_lookup_by_id(ospf->vrf_id); |
6282e124 | 3900 | json_object *json_vrf = NULL; |
7dab10ce | 3901 | json_object *json_interface_sub = NULL, *json_interface = NULL; |
7c8ff89e | 3902 | |
d62a17ae | 3903 | if (use_json) { |
b1c3ae8c CS |
3904 | if (use_vrf) |
3905 | json_vrf = json_object_new_object(); | |
3906 | else | |
3907 | json_vrf = json; | |
6282e124 | 3908 | json_interface = json_object_new_object(); |
d62a17ae | 3909 | } |
3910 | ||
3911 | if (ospf->instance) { | |
3912 | if (use_json) | |
3913 | json_object_int_add(json, "ospfInstance", | |
3914 | ospf->instance); | |
3915 | else | |
3916 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
3917 | } | |
3918 | ||
b1c3ae8c CS |
3919 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); |
3920 | ||
3921 | if (intf_name == NULL) { | |
d62a17ae | 3922 | /* Show All Interfaces.*/ |
451fda4f | 3923 | FOR_ALL_INTERFACES (vrf, ifp) { |
d62a17ae | 3924 | if (ospf_oi_count(ifp)) { |
7dab10ce | 3925 | if (use_json) { |
d62a17ae | 3926 | json_interface_sub = |
3927 | json_object_new_object(); | |
7dab10ce | 3928 | } |
d62a17ae | 3929 | show_ip_ospf_interface_sub(vty, ospf, ifp, |
3930 | json_interface_sub, | |
3931 | use_json); | |
3932 | ||
7dab10ce | 3933 | if (use_json) { |
d62a17ae | 3934 | json_object_object_add( |
7dab10ce | 3935 | json_interface, ifp->name, |
d62a17ae | 3936 | json_interface_sub); |
7dab10ce | 3937 | } |
d62a17ae | 3938 | } |
3939 | } | |
6282e124 CS |
3940 | if (use_json) |
3941 | json_object_object_add(json_vrf, "interfaces", | |
996c9314 | 3942 | json_interface); |
d62a17ae | 3943 | } else { |
3944 | /* Interface name is specified. */ | |
a36898e7 | 3945 | ifp = if_lookup_by_name(intf_name, ospf->vrf_id); |
b1c3ae8c | 3946 | if (ifp == NULL) { |
d62a17ae | 3947 | if (use_json) |
b1c3ae8c | 3948 | json_object_boolean_true_add(json_vrf, |
d62a17ae | 3949 | "noSuchIface"); |
3950 | else | |
3951 | vty_out(vty, "No such interface name\n"); | |
3952 | } else { | |
7dab10ce | 3953 | if (use_json) { |
d62a17ae | 3954 | json_interface_sub = json_object_new_object(); |
7dab10ce | 3955 | json_interface = json_object_new_object(); |
7dab10ce | 3956 | } |
d62a17ae | 3957 | |
3958 | show_ip_ospf_interface_sub( | |
3959 | vty, ospf, ifp, json_interface_sub, use_json); | |
3960 | ||
7dab10ce | 3961 | if (use_json) { |
7dab10ce CS |
3962 | json_object_object_add(json_interface, |
3963 | ifp->name, | |
d62a17ae | 3964 | json_interface_sub); |
6282e124 CS |
3965 | json_object_object_add(json_vrf, "interfaces", |
3966 | json_interface); | |
7dab10ce | 3967 | } |
d62a17ae | 3968 | } |
3969 | } | |
3970 | ||
3971 | if (use_json) { | |
b1c3ae8c CS |
3972 | if (use_vrf) { |
3973 | if (ospf->vrf_id == VRF_DEFAULT) | |
3974 | json_object_object_add(json, "default", | |
3975 | json_vrf); | |
3976 | else | |
3977 | json_object_object_add(json, ospf->name, | |
3978 | json_vrf); | |
3979 | } | |
d62a17ae | 3980 | } else |
3981 | vty_out(vty, "\n"); | |
3982 | ||
3983 | return CMD_SUCCESS; | |
718e3744 | 3984 | } |
3985 | ||
c9339663 CS |
3986 | static void show_ip_ospf_interface_traffic_sub(struct vty *vty, |
3987 | struct ospf_interface *oi, | |
3988 | json_object *json_interface_sub, | |
9f049418 | 3989 | bool use_json) |
c9339663 CS |
3990 | { |
3991 | if (use_json) { | |
996c9314 LB |
3992 | json_object_int_add(json_interface_sub, "ifIndex", |
3993 | oi->ifp->ifindex); | |
3994 | json_object_int_add(json_interface_sub, "helloIn", | |
3995 | oi->hello_in); | |
3996 | json_object_int_add(json_interface_sub, "helloOut", | |
3997 | oi->hello_out); | |
3998 | json_object_int_add(json_interface_sub, "dbDescIn", | |
3999 | oi->db_desc_in); | |
4000 | json_object_int_add(json_interface_sub, "dbDescOut", | |
4001 | oi->db_desc_out); | |
4002 | json_object_int_add(json_interface_sub, "lsReqIn", | |
4003 | oi->ls_req_in); | |
4004 | json_object_int_add(json_interface_sub, "lsReqOut", | |
4005 | oi->ls_req_out); | |
4006 | json_object_int_add(json_interface_sub, "lsUpdIn", | |
4007 | oi->ls_upd_in); | |
4008 | json_object_int_add(json_interface_sub, "lsUpdOut", | |
4009 | oi->ls_upd_out); | |
4010 | json_object_int_add(json_interface_sub, "lsAckIn", | |
4011 | oi->ls_ack_in); | |
4012 | json_object_int_add(json_interface_sub, "lsAckOut", | |
4013 | oi->ls_ack_out); | |
c9339663 CS |
4014 | } else { |
4015 | vty_out(vty, | |
4016 | "%-10s %8u/%-8u %7u/%-7u %7u/%-7u %7u/%-7u %7u/%-7u\n", | |
996c9314 LB |
4017 | oi->ifp->name, oi->hello_in, oi->hello_out, |
4018 | oi->db_desc_in, oi->db_desc_out, oi->ls_req_in, | |
4019 | oi->ls_req_out, oi->ls_upd_in, oi->ls_upd_out, | |
c9339663 CS |
4020 | oi->ls_ack_in, oi->ls_ack_out); |
4021 | } | |
4022 | } | |
4023 | ||
4024 | /* OSPFv2 Packet Counters */ | |
996c9314 LB |
4025 | static int show_ip_ospf_interface_traffic_common( |
4026 | struct vty *vty, struct ospf *ospf, char *intf_name, json_object *json, | |
9f049418 | 4027 | int display_once, uint8_t use_vrf, bool use_json) |
c9339663 CS |
4028 | { |
4029 | struct vrf *vrf = NULL; | |
4030 | struct interface *ifp = NULL; | |
b1c3ae8c | 4031 | json_object *json_vrf = NULL; |
c9339663 CS |
4032 | json_object *json_interface_sub = NULL; |
4033 | ||
4034 | if (!use_json && !display_once) { | |
4035 | vty_out(vty, "\n"); | |
996c9314 LB |
4036 | vty_out(vty, "%-12s%-17s%-17s%-17s%-17s%-17s\n", "Interface", |
4037 | " HELLO", " DB-Desc", " LS-Req", " LS-Update", | |
4038 | " LS-Ack"); | |
c9339663 | 4039 | vty_out(vty, "%-10s%-18s%-18s%-17s%-17s%-17s\n", "", |
996c9314 LB |
4040 | " Rx/Tx", " Rx/Tx", " Rx/Tx", " Rx/Tx", |
4041 | " Rx/Tx"); | |
c9339663 | 4042 | vty_out(vty, |
996c9314 | 4043 | "--------------------------------------------------------------------------------------------\n"); |
c9339663 | 4044 | } else if (use_json) { |
b1c3ae8c CS |
4045 | if (use_vrf) |
4046 | json_vrf = json_object_new_object(); | |
4047 | else | |
4048 | json_vrf = json; | |
c9339663 CS |
4049 | } |
4050 | ||
b1c3ae8c CS |
4051 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); |
4052 | ||
c9339663 CS |
4053 | if (intf_name == NULL) { |
4054 | vrf = vrf_lookup_by_id(ospf->vrf_id); | |
4055 | FOR_ALL_INTERFACES (vrf, ifp) { | |
4056 | struct route_node *rn; | |
4057 | struct ospf_interface *oi; | |
4058 | ||
4059 | if (ospf_oi_count(ifp) == 0) | |
4060 | continue; | |
4061 | ||
4062 | for (rn = route_top(IF_OIFS(ifp)); rn; | |
996c9314 | 4063 | rn = route_next(rn)) { |
c9339663 CS |
4064 | oi = rn->info; |
4065 | ||
4066 | if (oi == NULL) | |
4067 | continue; | |
4068 | ||
4069 | if (use_json) { | |
4070 | json_interface_sub = | |
4071 | json_object_new_object(); | |
4072 | } | |
4073 | ||
996c9314 LB |
4074 | show_ip_ospf_interface_traffic_sub( |
4075 | vty, oi, json_interface_sub, use_json); | |
c9339663 | 4076 | if (use_json) { |
996c9314 LB |
4077 | json_object_object_add( |
4078 | json_vrf, ifp->name, | |
4079 | json_interface_sub); | |
c9339663 CS |
4080 | } |
4081 | } | |
4082 | } | |
4083 | } else { | |
4084 | /* Interface name is specified. */ | |
a36898e7 | 4085 | ifp = if_lookup_by_name(intf_name, ospf->vrf_id); |
c9339663 CS |
4086 | if (ifp != NULL) { |
4087 | struct route_node *rn; | |
4088 | struct ospf_interface *oi; | |
4089 | ||
4090 | if (ospf_oi_count(ifp) == 0) { | |
996c9314 LB |
4091 | vty_out(vty, |
4092 | " OSPF not enabled on this interface %s\n", | |
c9339663 CS |
4093 | ifp->name); |
4094 | return CMD_SUCCESS; | |
4095 | } | |
4096 | ||
4097 | for (rn = route_top(IF_OIFS(ifp)); rn; | |
4098 | rn = route_next(rn)) { | |
4099 | oi = rn->info; | |
4100 | ||
4101 | if (use_json) { | |
4102 | json_interface_sub = | |
4103 | json_object_new_object(); | |
4104 | } | |
4105 | ||
996c9314 LB |
4106 | show_ip_ospf_interface_traffic_sub( |
4107 | vty, oi, json_interface_sub, use_json); | |
c9339663 | 4108 | if (use_json) { |
996c9314 LB |
4109 | json_object_object_add( |
4110 | json_vrf, ifp->name, | |
4111 | json_interface_sub); | |
c9339663 CS |
4112 | } |
4113 | } | |
4114 | } | |
4115 | } | |
4116 | ||
4117 | if (use_json) { | |
b1c3ae8c CS |
4118 | if (use_vrf) { |
4119 | if (ospf->vrf_id == VRF_DEFAULT) | |
4120 | json_object_object_add(json, "default", | |
4121 | json_vrf); | |
4122 | else | |
4123 | json_object_object_add(json, ospf->name, | |
4124 | json_vrf); | |
4125 | } | |
4126 | } else | |
4127 | vty_out(vty, "\n"); | |
c9339663 CS |
4128 | |
4129 | return CMD_SUCCESS; | |
4130 | } | |
4131 | ||
7c8ff89e DS |
4132 | DEFUN (show_ip_ospf_interface, |
4133 | show_ip_ospf_interface_cmd, | |
43b8d1d8 | 4134 | "show ip ospf [vrf <NAME|all>] interface [INTERFACE] [json]", |
7c8ff89e DS |
4135 | SHOW_STR |
4136 | IP_STR | |
4137 | "OSPF information\n" | |
b5a8894d | 4138 | VRF_CMD_HELP_STR |
43b8d1d8 | 4139 | "All VRFs\n" |
7c8ff89e | 4140 | "Interface information\n" |
7ec4159b | 4141 | "Interface name\n" |
9973d184 | 4142 | JSON_STR) |
7c8ff89e | 4143 | { |
d62a17ae | 4144 | struct ospf *ospf; |
9f049418 | 4145 | bool uj = use_json(argc, argv); |
b5a8894d | 4146 | struct listnode *node = NULL; |
b1c3ae8c | 4147 | char *vrf_name = NULL, *intf_name = NULL; |
2951a7a4 | 4148 | bool all_vrf = false; |
b5a8894d CS |
4149 | int ret = CMD_SUCCESS; |
4150 | int inst = 0; | |
b1c3ae8c | 4151 | int idx_vrf = 0, idx_intf = 0; |
d7c0a89a | 4152 | uint8_t use_vrf = 0; |
b1c3ae8c | 4153 | json_object *json = NULL; |
7c8ff89e | 4154 | |
43b8d1d8 CS |
4155 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
4156 | ||
b1c3ae8c CS |
4157 | if (argv_find(argv, argc, "INTERFACE", &idx_intf)) |
4158 | intf_name = argv[idx_intf]->arg; | |
4159 | ||
d62a17ae | 4160 | if (uj) |
b1c3ae8c | 4161 | json = json_object_new_object(); |
6be4da3d | 4162 | |
b5a8894d CS |
4163 | /* vrf input is provided could be all or specific vrf*/ |
4164 | if (vrf_name) { | |
b1c3ae8c | 4165 | use_vrf = 1; |
b5a8894d CS |
4166 | if (all_vrf) { |
4167 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
4168 | if (!ospf->oi_running) | |
4169 | continue; | |
996c9314 LB |
4170 | ret = show_ip_ospf_interface_common( |
4171 | vty, ospf, intf_name, use_vrf, json, | |
4172 | uj); | |
b5a8894d | 4173 | } |
b1c3ae8c CS |
4174 | |
4175 | if (uj) { | |
4176 | vty_out(vty, "%s\n", | |
996c9314 LB |
4177 | json_object_to_json_string_ext( |
4178 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 4179 | json_object_free(json); |
9f049418 | 4180 | } else if (!ospf) |
94d4c685 | 4181 | vty_out(vty, "%% OSPF instance not found\n"); |
b1c3ae8c | 4182 | |
b5a8894d CS |
4183 | return ret; |
4184 | } | |
4185 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
b1c3ae8c | 4186 | if (ospf == NULL || !ospf->oi_running) { |
9f049418 DS |
4187 | if (uj) { |
4188 | vty_out(vty, "%s\n", | |
4189 | json_object_to_json_string_ext( | |
4190 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 4191 | json_object_free(json); |
9f049418 | 4192 | } else |
94d4c685 | 4193 | vty_out(vty, "%% OSPF instance not found\n"); |
9f049418 | 4194 | |
b5a8894d | 4195 | return CMD_SUCCESS; |
b1c3ae8c CS |
4196 | } |
4197 | ret = show_ip_ospf_interface_common(vty, ospf, intf_name, | |
4198 | use_vrf, json, uj); | |
b5a8894d CS |
4199 | |
4200 | } else { | |
4201 | /* Display default ospf (instance 0) info */ | |
4202 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
b1c3ae8c | 4203 | if (ospf == NULL || !ospf->oi_running) { |
9f049418 DS |
4204 | if (uj) { |
4205 | vty_out(vty, "%s\n", | |
4206 | json_object_to_json_string_ext( | |
4207 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 4208 | json_object_free(json); |
9f049418 | 4209 | } else |
94d4c685 | 4210 | vty_out(vty, "%% OSPF instance not found\n"); |
9f049418 | 4211 | |
b5a8894d | 4212 | return CMD_SUCCESS; |
b1c3ae8c CS |
4213 | } |
4214 | ret = show_ip_ospf_interface_common(vty, ospf, intf_name, | |
4215 | use_vrf, json, uj); | |
4216 | } | |
4217 | ||
4218 | if (uj) { | |
996c9314 LB |
4219 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
4220 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 4221 | json_object_free(json); |
b5a8894d CS |
4222 | } |
4223 | ||
4224 | return ret; | |
7c8ff89e DS |
4225 | } |
4226 | ||
4227 | DEFUN (show_ip_ospf_instance_interface, | |
4228 | show_ip_ospf_instance_interface_cmd, | |
6147e2c6 | 4229 | "show ip ospf (1-65535) interface [INTERFACE] [json]", |
7c8ff89e DS |
4230 | SHOW_STR |
4231 | IP_STR | |
4232 | "OSPF information\n" | |
4233 | "Instance ID\n" | |
4234 | "Interface information\n" | |
7ec4159b | 4235 | "Interface name\n" |
9973d184 | 4236 | JSON_STR) |
7c8ff89e | 4237 | { |
d62a17ae | 4238 | int idx_number = 3; |
b1c3ae8c | 4239 | int idx_intf = 0; |
d62a17ae | 4240 | struct ospf *ospf; |
d7c0a89a | 4241 | unsigned short instance = 0; |
9f049418 | 4242 | bool uj = use_json(argc, argv); |
b1c3ae8c CS |
4243 | char *intf_name = NULL; |
4244 | int ret = CMD_SUCCESS; | |
4245 | json_object *json = NULL; | |
d62a17ae | 4246 | |
4247 | instance = strtoul(argv[idx_number]->arg, NULL, 10); | |
409f98ab | 4248 | if (instance != ospf_instance) |
ac28e4ec CS |
4249 | return CMD_NOT_MY_INSTANCE; |
4250 | ||
409f98ab IR |
4251 | ospf = ospf_lookup_instance(instance); |
4252 | if (!ospf || !ospf->oi_running) | |
d62a17ae | 4253 | return CMD_SUCCESS; |
4254 | ||
4255 | if (uj) | |
b1c3ae8c CS |
4256 | json = json_object_new_object(); |
4257 | ||
4258 | if (argv_find(argv, argc, "INTERFACE", &idx_intf)) | |
4259 | intf_name = argv[idx_intf]->arg; | |
4260 | ||
4261 | ret = show_ip_ospf_interface_common(vty, ospf, intf_name, 0, json, uj); | |
4262 | ||
4263 | if (uj) { | |
996c9314 LB |
4264 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
4265 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c CS |
4266 | json_object_free(json); |
4267 | } | |
d62a17ae | 4268 | |
b1c3ae8c | 4269 | return ret; |
d62a17ae | 4270 | } |
4271 | ||
c9339663 CS |
4272 | DEFUN (show_ip_ospf_interface_traffic, |
4273 | show_ip_ospf_interface_traffic_cmd, | |
4274 | "show ip ospf [vrf <NAME|all>] interface traffic [INTERFACE] [json]", | |
4275 | SHOW_STR | |
4276 | IP_STR | |
4277 | "OSPF information\n" | |
4278 | VRF_CMD_HELP_STR | |
4279 | "All VRFs\n" | |
4280 | "Interface information\n" | |
4281 | "Protocol Packet counters\n" | |
4282 | "Interface name\n" | |
4283 | JSON_STR) | |
4284 | { | |
4285 | struct ospf *ospf = NULL; | |
4286 | struct listnode *node = NULL; | |
4287 | char *vrf_name = NULL, *intf_name = NULL; | |
2951a7a4 | 4288 | bool all_vrf = false; |
c9339663 CS |
4289 | int inst = 0; |
4290 | int idx_vrf = 0, idx_intf = 0; | |
9f049418 | 4291 | bool uj = use_json(argc, argv); |
b1c3ae8c | 4292 | json_object *json = NULL; |
c9339663 CS |
4293 | int ret = CMD_SUCCESS; |
4294 | int display_once = 0; | |
d7c0a89a | 4295 | uint8_t use_vrf = 0; |
c9339663 CS |
4296 | |
4297 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); | |
4298 | ||
4299 | if (argv_find(argv, argc, "INTERFACE", &idx_intf)) | |
4300 | intf_name = argv[idx_intf]->arg; | |
4301 | ||
b1c3ae8c CS |
4302 | if (uj) |
4303 | json = json_object_new_object(); | |
4304 | ||
c9339663 | 4305 | if (vrf_name) { |
b1c3ae8c | 4306 | use_vrf = 1; |
c9339663 CS |
4307 | if (all_vrf) { |
4308 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
4309 | if (!ospf->oi_running) | |
4310 | continue; | |
4311 | ||
996c9314 LB |
4312 | ret = show_ip_ospf_interface_traffic_common( |
4313 | vty, ospf, intf_name, json, | |
4314 | display_once, use_vrf, uj); | |
c9339663 CS |
4315 | display_once = 1; |
4316 | } | |
b1c3ae8c CS |
4317 | |
4318 | if (uj) { | |
4319 | vty_out(vty, "%s\n", | |
996c9314 LB |
4320 | json_object_to_json_string_ext( |
4321 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c CS |
4322 | json_object_free(json); |
4323 | } | |
4324 | ||
c9339663 CS |
4325 | return ret; |
4326 | } | |
4327 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
b1c3ae8c CS |
4328 | if (ospf == NULL || !ospf->oi_running) { |
4329 | if (uj) | |
4330 | json_object_free(json); | |
c9339663 | 4331 | return CMD_SUCCESS; |
b1c3ae8c CS |
4332 | } |
4333 | ||
996c9314 LB |
4334 | ret = show_ip_ospf_interface_traffic_common( |
4335 | vty, ospf, intf_name, json, display_once, use_vrf, uj); | |
c9339663 CS |
4336 | } else { |
4337 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
b1c3ae8c CS |
4338 | if (ospf == NULL || !ospf->oi_running) { |
4339 | if (uj) | |
4340 | json_object_free(json); | |
c9339663 | 4341 | return CMD_SUCCESS; |
b1c3ae8c CS |
4342 | } |
4343 | ||
996c9314 LB |
4344 | ret = show_ip_ospf_interface_traffic_common( |
4345 | vty, ospf, intf_name, json, display_once, use_vrf, uj); | |
b1c3ae8c CS |
4346 | } |
4347 | ||
4348 | if (uj) { | |
996c9314 LB |
4349 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
4350 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 4351 | json_object_free(json); |
c9339663 CS |
4352 | } |
4353 | ||
4354 | return ret; | |
4355 | } | |
4356 | ||
4357 | ||
d62a17ae | 4358 | static void show_ip_ospf_neighbour_header(struct vty *vty) |
4359 | { | |
c84355a9 | 4360 | vty_out(vty, "\n%-15s %3s %-15s %9s %-15s %-32s %5s %5s %5s\n", |
d62a17ae | 4361 | "Neighbor ID", "Pri", "State", "Dead Time", "Address", |
4362 | "Interface", "RXmtL", "RqstL", "DBsmL"); | |
4363 | } | |
4364 | ||
4365 | static void show_ip_ospf_neighbor_sub(struct vty *vty, | |
4366 | struct ospf_interface *oi, | |
9f049418 | 4367 | json_object *json, bool use_json) |
d62a17ae | 4368 | { |
4369 | struct route_node *rn; | |
cef262c3 | 4370 | struct ospf_neighbor *nbr, *prev_nbr = NULL; |
d62a17ae | 4371 | char msgbuf[16]; |
96b663a3 | 4372 | char buf[PREFIX_STRLEN]; |
d62a17ae | 4373 | char timebuf[OSPF_TIME_DUMP_SIZE]; |
cef262c3 | 4374 | json_object *json_neighbor = NULL, *json_neigh_array = NULL; |
d62a17ae | 4375 | |
4376 | for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) { | |
4377 | if ((nbr = rn->info)) { | |
4378 | /* Do not show myself. */ | |
cef262c3 CS |
4379 | if (nbr == oi->nbr_self) |
4380 | continue; | |
4381 | /* Down state is not shown. */ | |
4382 | if (nbr->state == NSM_Down) | |
4383 | continue; | |
4384 | if (use_json) { | |
4385 | char neigh_str[INET_ADDRSTRLEN]; | |
4386 | ||
996c9314 LB |
4387 | if (prev_nbr |
4388 | && !IPV4_ADDR_SAME(&prev_nbr->src, | |
4389 | &nbr->src)) { | |
cef262c3 CS |
4390 | /* Start new neigh list */ |
4391 | json_neigh_array = NULL; | |
4392 | } | |
4393 | ||
996c9314 | 4394 | if (nbr->state == NSM_Attempt |
975a328e | 4395 | && nbr->router_id.s_addr == INADDR_ANY) |
6021c6c0 CS |
4396 | strlcpy(neigh_str, "neighbor", |
4397 | sizeof(neigh_str)); | |
cef262c3 | 4398 | else |
96b663a3 MS |
4399 | inet_ntop(AF_INET, &nbr->router_id, |
4400 | neigh_str, sizeof(neigh_str)); | |
cef262c3 CS |
4401 | |
4402 | json_object_object_get_ex(json, neigh_str, | |
4403 | &json_neigh_array); | |
4404 | ||
4405 | if (!json_neigh_array) { | |
996c9314 LB |
4406 | json_neigh_array = |
4407 | json_object_new_array(); | |
4408 | json_object_object_add( | |
4409 | json, neigh_str, | |
4410 | json_neigh_array); | |
d62a17ae | 4411 | } |
cef262c3 | 4412 | |
996c9314 | 4413 | json_neighbor = json_object_new_object(); |
cef262c3 CS |
4414 | |
4415 | ospf_nbr_state_message(nbr, msgbuf, 16); | |
4416 | ||
996c9314 | 4417 | json_object_int_add(json_neighbor, "priority", |
cef262c3 CS |
4418 | nbr->priority); |
4419 | json_object_string_add(json_neighbor, "state", | |
4420 | msgbuf); | |
b3d498f8 RW |
4421 | |
4422 | if (nbr->t_inactivity) { | |
4423 | long time_store; | |
4424 | ||
4425 | time_store = monotime_until( | |
4426 | &nbr->t_inactivity | |
4427 | ->u.sands, | |
4428 | NULL) | |
4429 | / 1000LL; | |
4430 | json_object_int_add(json_neighbor, | |
4431 | "deadTimeMsecs", | |
4432 | time_store); | |
4433 | } else { | |
4434 | json_object_string_add(json_neighbor, | |
4435 | "deadTimeMsecs", | |
4436 | "inactive"); | |
4437 | } | |
96b663a3 MS |
4438 | json_object_string_add( |
4439 | json_neighbor, "address", | |
4440 | inet_ntop(AF_INET, &nbr->src, | |
4441 | buf, sizeof(buf))); | |
cef262c3 CS |
4442 | json_object_string_add(json_neighbor, |
4443 | "ifaceName", | |
4444 | IF_NAME(oi)); | |
996c9314 LB |
4445 | json_object_int_add( |
4446 | json_neighbor, "retransmitCounter", | |
4447 | ospf_ls_retransmit_count(nbr)); | |
cef262c3 | 4448 | json_object_int_add(json_neighbor, |
996c9314 LB |
4449 | "requestCounter", |
4450 | ospf_ls_request_count(nbr)); | |
cef262c3 | 4451 | json_object_int_add(json_neighbor, |
996c9314 LB |
4452 | "dbSummaryCounter", |
4453 | ospf_db_summary_count(nbr)); | |
cef262c3 CS |
4454 | |
4455 | json_object_array_add(json_neigh_array, | |
4456 | json_neighbor); | |
4457 | } else { | |
4458 | ospf_nbr_state_message(nbr, msgbuf, 16); | |
4459 | ||
996c9314 | 4460 | if (nbr->state == NSM_Attempt |
975a328e | 4461 | && nbr->router_id.s_addr == INADDR_ANY) |
996c9314 LB |
4462 | vty_out(vty, "%-15s %3d %-15s ", "-", |
4463 | nbr->priority, msgbuf); | |
cef262c3 | 4464 | else |
96b663a3 MS |
4465 | vty_out(vty, "%-15pI4 %3d %-15s ", |
4466 | &nbr->router_id, | |
996c9314 | 4467 | nbr->priority, msgbuf); |
cef262c3 CS |
4468 | |
4469 | vty_out(vty, "%9s ", | |
4470 | ospf_timer_dump(nbr->t_inactivity, | |
4471 | timebuf, | |
4472 | sizeof(timebuf))); | |
96b663a3 | 4473 | vty_out(vty, "%-15pI4 ", &nbr->src); |
c84355a9 | 4474 | vty_out(vty, "%-32s %5ld %5ld %5d\n", |
cef262c3 CS |
4475 | IF_NAME(oi), |
4476 | ospf_ls_retransmit_count(nbr), | |
4477 | ospf_ls_request_count(nbr), | |
4478 | ospf_db_summary_count(nbr)); | |
d62a17ae | 4479 | } |
cef262c3 | 4480 | prev_nbr = nbr; |
d62a17ae | 4481 | } |
4482 | } | |
4483 | } | |
4484 | ||
4485 | static int show_ip_ospf_neighbor_common(struct vty *vty, struct ospf *ospf, | |
9f049418 | 4486 | json_object *json, bool use_json, |
d7c0a89a | 4487 | uint8_t use_vrf) |
d62a17ae | 4488 | { |
4489 | struct ospf_interface *oi; | |
4490 | struct listnode *node; | |
6282e124 | 4491 | json_object *json_vrf = NULL; |
2bc7673f | 4492 | json_object *json_nbr_sub = NULL; |
7c8ff89e | 4493 | |
b1c3ae8c CS |
4494 | if (use_json) { |
4495 | if (use_vrf) | |
4496 | json_vrf = json_object_new_object(); | |
4497 | else | |
4498 | json_vrf = json; | |
6282e124 | 4499 | json_nbr_sub = json_object_new_object(); |
b1c3ae8c | 4500 | } |
d62a17ae | 4501 | |
4502 | if (ospf->instance) { | |
4503 | if (use_json) | |
4504 | json_object_int_add(json, "ospfInstance", | |
4505 | ospf->instance); | |
4506 | else | |
4507 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
4508 | } | |
7c8ff89e | 4509 | |
b1c3ae8c CS |
4510 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); |
4511 | if (!use_json) | |
4512 | show_ip_ospf_neighbour_header(vty); | |
87bd50e8 | 4513 | |
2bc7673f CS |
4514 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) { |
4515 | if (ospf_interface_neighbor_count(oi) == 0) | |
4516 | continue; | |
2bc7673f CS |
4517 | show_ip_ospf_neighbor_sub(vty, oi, json_nbr_sub, use_json); |
4518 | } | |
718e3744 | 4519 | |
d62a17ae | 4520 | if (use_json) { |
996c9314 | 4521 | json_object_object_add(json_vrf, "neighbors", json_nbr_sub); |
b1c3ae8c CS |
4522 | if (use_vrf) { |
4523 | if (ospf->vrf_id == VRF_DEFAULT) | |
4524 | json_object_object_add(json, "default", | |
4525 | json_vrf); | |
4526 | else | |
4527 | json_object_object_add(json, ospf->name, | |
4528 | json_vrf); | |
4529 | } | |
d62a17ae | 4530 | } else |
4531 | vty_out(vty, "\n"); | |
7c8ff89e | 4532 | |
d62a17ae | 4533 | return CMD_SUCCESS; |
718e3744 | 4534 | } |
4535 | ||
7c8ff89e DS |
4536 | DEFUN (show_ip_ospf_neighbor, |
4537 | show_ip_ospf_neighbor_cmd, | |
b5a8894d | 4538 | "show ip ospf [vrf <NAME|all>] neighbor [json]", |
718e3744 | 4539 | SHOW_STR |
4540 | IP_STR | |
4541 | "OSPF information\n" | |
b5a8894d CS |
4542 | VRF_CMD_HELP_STR |
4543 | "All VRFs\n" | |
91756b38 | 4544 | "Neighbor list\n" |
9973d184 | 4545 | JSON_STR) |
718e3744 | 4546 | { |
d62a17ae | 4547 | struct ospf *ospf; |
9f049418 | 4548 | bool uj = use_json(argc, argv); |
b5a8894d CS |
4549 | struct listnode *node = NULL; |
4550 | char *vrf_name = NULL; | |
2951a7a4 | 4551 | bool all_vrf = false; |
b5a8894d CS |
4552 | int ret = CMD_SUCCESS; |
4553 | int inst = 0; | |
4554 | int idx_vrf = 0; | |
d7c0a89a | 4555 | uint8_t use_vrf = 0; |
b1c3ae8c | 4556 | json_object *json = NULL; |
718e3744 | 4557 | |
43b8d1d8 | 4558 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
7c8ff89e | 4559 | |
b1c3ae8c CS |
4560 | if (uj) |
4561 | json = json_object_new_object(); | |
b5a8894d CS |
4562 | |
4563 | /* vrf input is provided could be all or specific vrf*/ | |
4564 | if (vrf_name) { | |
b1c3ae8c | 4565 | use_vrf = 1; |
b5a8894d CS |
4566 | if (all_vrf) { |
4567 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
4568 | if (!ospf->oi_running) | |
4569 | continue; | |
996c9314 LB |
4570 | ret = show_ip_ospf_neighbor_common( |
4571 | vty, ospf, json, uj, use_vrf); | |
b1c3ae8c CS |
4572 | } |
4573 | ||
4574 | if (uj) { | |
4575 | vty_out(vty, "%s\n", | |
996c9314 LB |
4576 | json_object_to_json_string_ext( |
4577 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 4578 | json_object_free(json); |
9f049418 DS |
4579 | } else if (!ospf) |
4580 | vty_out(vty, "OSPF instance not found\n"); | |
b1c3ae8c | 4581 | |
b5a8894d CS |
4582 | return ret; |
4583 | } | |
b1c3ae8c | 4584 | |
b5a8894d | 4585 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); |
b1c3ae8c | 4586 | if (ospf == NULL || !ospf->oi_running) { |
9f049418 DS |
4587 | if (uj) { |
4588 | vty_out(vty, "%s\n", | |
4589 | json_object_to_json_string_ext( | |
4590 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 4591 | json_object_free(json); |
9f049418 DS |
4592 | } else |
4593 | vty_out(vty, "%% OSPF instance not found\n"); | |
4594 | ||
b5a8894d | 4595 | return CMD_SUCCESS; |
b1c3ae8c | 4596 | } |
b5a8894d CS |
4597 | } else { |
4598 | /* Display default ospf (instance 0) info */ | |
4599 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
b1c3ae8c | 4600 | if (ospf == NULL || !ospf->oi_running) { |
9f049418 DS |
4601 | if (uj) { |
4602 | vty_out(vty, "%s\n", | |
4603 | json_object_to_json_string_ext( | |
4604 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 4605 | json_object_free(json); |
9f049418 DS |
4606 | } else |
4607 | vty_out(vty, "%% OSPF instance not found\n"); | |
4608 | ||
b5a8894d | 4609 | return CMD_SUCCESS; |
b1c3ae8c | 4610 | } |
b5a8894d CS |
4611 | } |
4612 | ||
b1c3ae8c CS |
4613 | if (ospf) { |
4614 | ret = show_ip_ospf_neighbor_common(vty, ospf, json, uj, | |
4615 | use_vrf); | |
4616 | ||
4617 | if (uj) { | |
4618 | vty_out(vty, "%s\n", | |
996c9314 LB |
4619 | json_object_to_json_string_ext( |
4620 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c CS |
4621 | } |
4622 | } | |
4623 | ||
4624 | if (uj) | |
4625 | json_object_free(json); | |
b5a8894d CS |
4626 | |
4627 | return ret; | |
7c8ff89e DS |
4628 | } |
4629 | ||
4630 | ||
4631 | DEFUN (show_ip_ospf_instance_neighbor, | |
4632 | show_ip_ospf_instance_neighbor_cmd, | |
6147e2c6 | 4633 | "show ip ospf (1-65535) neighbor [json]", |
7c8ff89e DS |
4634 | SHOW_STR |
4635 | IP_STR | |
4636 | "OSPF information\n" | |
4637 | "Instance ID\n" | |
91756b38 | 4638 | "Neighbor list\n" |
9973d184 | 4639 | JSON_STR) |
7c8ff89e | 4640 | { |
d62a17ae | 4641 | int idx_number = 3; |
4642 | struct ospf *ospf; | |
d7c0a89a | 4643 | unsigned short instance = 0; |
9f049418 | 4644 | bool uj = use_json(argc, argv); |
b1c3ae8c CS |
4645 | json_object *json = NULL; |
4646 | int ret = CMD_SUCCESS; | |
7c8ff89e | 4647 | |
d62a17ae | 4648 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
409f98ab | 4649 | if (instance != ospf_instance) |
ac28e4ec CS |
4650 | return CMD_NOT_MY_INSTANCE; |
4651 | ||
409f98ab IR |
4652 | ospf = ospf_lookup_instance(instance); |
4653 | if (!ospf || !ospf->oi_running) | |
d62a17ae | 4654 | return CMD_SUCCESS; |
7c8ff89e | 4655 | |
b1c3ae8c CS |
4656 | if (uj) |
4657 | json = json_object_new_object(); | |
b5a8894d | 4658 | |
b1c3ae8c CS |
4659 | ret = show_ip_ospf_neighbor_common(vty, ospf, json, uj, 0); |
4660 | ||
4661 | if (uj) { | |
996c9314 LB |
4662 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
4663 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c CS |
4664 | json_object_free(json); |
4665 | } | |
4666 | ||
4667 | return ret; | |
7c8ff89e DS |
4668 | } |
4669 | ||
d62a17ae | 4670 | static int show_ip_ospf_neighbor_all_common(struct vty *vty, struct ospf *ospf, |
9f049418 | 4671 | json_object *json, bool use_json, |
d7c0a89a | 4672 | uint8_t use_vrf) |
d62a17ae | 4673 | { |
4674 | struct listnode *node; | |
4675 | struct ospf_interface *oi; | |
96b663a3 | 4676 | char buf[PREFIX_STRLEN]; |
b1c3ae8c | 4677 | json_object *json_vrf = NULL; |
d62a17ae | 4678 | json_object *json_neighbor_sub = NULL; |
7c8ff89e | 4679 | |
d62a17ae | 4680 | if (use_json) { |
b1c3ae8c CS |
4681 | if (use_vrf) |
4682 | json_vrf = json_object_new_object(); | |
4683 | else | |
4684 | json_vrf = json; | |
b5a8894d | 4685 | } |
d62a17ae | 4686 | |
b1c3ae8c CS |
4687 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); |
4688 | if (!use_json) | |
4689 | show_ip_ospf_neighbour_header(vty); | |
4690 | ||
d62a17ae | 4691 | if (ospf->instance) { |
4692 | if (use_json) | |
b1c3ae8c | 4693 | json_object_int_add(json_vrf, "ospfInstance", |
d62a17ae | 4694 | ospf->instance); |
4695 | else | |
4696 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
4697 | } | |
4698 | ||
4699 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) { | |
4700 | struct listnode *nbr_node; | |
4701 | struct ospf_nbr_nbma *nbr_nbma; | |
4702 | ||
b1c3ae8c | 4703 | show_ip_ospf_neighbor_sub(vty, oi, json_vrf, use_json); |
d62a17ae | 4704 | |
4705 | /* print Down neighbor status */ | |
4706 | for (ALL_LIST_ELEMENTS_RO(oi->nbr_nbma, nbr_node, nbr_nbma)) { | |
4707 | if (nbr_nbma->nbr == NULL | |
4708 | || nbr_nbma->nbr->state == NSM_Down) { | |
4709 | if (use_json) { | |
6f3e19b7 MR |
4710 | json_neighbor_sub = |
4711 | json_object_new_object(); | |
d62a17ae | 4712 | json_object_int_add(json_neighbor_sub, |
4713 | "nbrNbmaPriority", | |
4714 | nbr_nbma->priority); | |
4715 | json_object_boolean_true_add( | |
4716 | json_neighbor_sub, | |
4717 | "nbrNbmaDown"); | |
4718 | json_object_string_add( | |
4719 | json_neighbor_sub, | |
4720 | "nbrNbmaIfaceName", | |
4721 | IF_NAME(oi)); | |
4722 | json_object_int_add( | |
4723 | json_neighbor_sub, | |
4724 | "nbrNbmaRetransmitCounter", 0); | |
4725 | json_object_int_add( | |
4726 | json_neighbor_sub, | |
4727 | "nbrNbmaRequestCounter", 0); | |
4728 | json_object_int_add( | |
4729 | json_neighbor_sub, | |
4730 | "nbrNbmaDbSummaryCounter", 0); | |
4731 | json_object_object_add( | |
b1c3ae8c | 4732 | json_vrf, |
96b663a3 MS |
4733 | inet_ntop(AF_INET, |
4734 | &nbr_nbma->addr, buf, | |
4735 | sizeof(buf)), | |
d62a17ae | 4736 | json_neighbor_sub); |
4737 | } else { | |
4738 | vty_out(vty, "%-15s %3d %-15s %9s ", | |
4739 | "-", nbr_nbma->priority, "Down", | |
4740 | "-"); | |
4741 | vty_out(vty, | |
96b663a3 MS |
4742 | "%-32pI4 %-20s %5d %5d %5d\n", |
4743 | &nbr_nbma->addr, | |
d62a17ae | 4744 | IF_NAME(oi), 0, 0, 0); |
4745 | } | |
4746 | } | |
4747 | } | |
4748 | } | |
4749 | ||
4750 | if (use_json) { | |
b1c3ae8c CS |
4751 | if (use_vrf) { |
4752 | if (ospf->vrf_id == VRF_DEFAULT) | |
4753 | json_object_object_add(json, "default", | |
4754 | json_vrf); | |
4755 | else | |
4756 | json_object_object_add(json, ospf->name, | |
4757 | json_vrf); | |
4758 | } | |
d62a17ae | 4759 | } else |
4760 | vty_out(vty, "\n"); | |
4761 | ||
4762 | return CMD_SUCCESS; | |
718e3744 | 4763 | } |
4764 | ||
7c8ff89e DS |
4765 | DEFUN (show_ip_ospf_neighbor_all, |
4766 | show_ip_ospf_neighbor_all_cmd, | |
b5a8894d | 4767 | "show ip ospf [vrf <NAME|all>] neighbor all [json]", |
718e3744 | 4768 | SHOW_STR |
4769 | IP_STR | |
4770 | "OSPF information\n" | |
b5a8894d CS |
4771 | VRF_CMD_HELP_STR |
4772 | "All VRFs\n" | |
718e3744 | 4773 | "Neighbor list\n" |
91756b38 | 4774 | "include down status neighbor\n" |
9973d184 | 4775 | JSON_STR) |
7c8ff89e | 4776 | { |
d62a17ae | 4777 | struct ospf *ospf; |
9f049418 | 4778 | bool uj = use_json(argc, argv); |
b5a8894d CS |
4779 | struct listnode *node = NULL; |
4780 | char *vrf_name = NULL; | |
2951a7a4 | 4781 | bool all_vrf = false; |
b5a8894d CS |
4782 | int ret = CMD_SUCCESS; |
4783 | int inst = 0; | |
4784 | int idx_vrf = 0; | |
d7c0a89a | 4785 | uint8_t use_vrf = 0; |
b1c3ae8c | 4786 | json_object *json = NULL; |
7c8ff89e | 4787 | |
43b8d1d8 | 4788 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
7c8ff89e | 4789 | |
b1c3ae8c CS |
4790 | if (uj) |
4791 | json = json_object_new_object(); | |
b5a8894d CS |
4792 | |
4793 | /* vrf input is provided could be all or specific vrf*/ | |
4794 | if (vrf_name) { | |
b1c3ae8c | 4795 | use_vrf = 1; |
b5a8894d CS |
4796 | if (all_vrf) { |
4797 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
4798 | if (!ospf->oi_running) | |
4799 | continue; | |
996c9314 LB |
4800 | ret = show_ip_ospf_neighbor_all_common( |
4801 | vty, ospf, json, uj, use_vrf); | |
b1c3ae8c CS |
4802 | } |
4803 | ||
4804 | if (uj) { | |
4805 | vty_out(vty, "%s\n", | |
996c9314 LB |
4806 | json_object_to_json_string_ext( |
4807 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 4808 | json_object_free(json); |
b5a8894d | 4809 | } |
b1c3ae8c | 4810 | |
b5a8894d CS |
4811 | return ret; |
4812 | } | |
b1c3ae8c | 4813 | |
b5a8894d | 4814 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); |
b1c3ae8c CS |
4815 | if (ospf == NULL || !ospf->oi_running) { |
4816 | if (uj) | |
4817 | json_object_free(json); | |
b5a8894d | 4818 | return CMD_SUCCESS; |
b1c3ae8c | 4819 | } |
b5a8894d CS |
4820 | } else { |
4821 | /* Display default ospf (instance 0) info */ | |
4822 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
b1c3ae8c CS |
4823 | if (ospf == NULL || !ospf->oi_running) { |
4824 | if (uj) | |
4825 | json_object_free(json); | |
b5a8894d | 4826 | return CMD_SUCCESS; |
b1c3ae8c | 4827 | } |
b5a8894d CS |
4828 | } |
4829 | ||
b1c3ae8c CS |
4830 | if (ospf) { |
4831 | ret = show_ip_ospf_neighbor_all_common(vty, ospf, json, uj, | |
4832 | use_vrf); | |
4833 | if (uj) { | |
4834 | vty_out(vty, "%s\n", | |
996c9314 LB |
4835 | json_object_to_json_string_ext( |
4836 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c CS |
4837 | } |
4838 | } | |
4839 | ||
4840 | if (uj) | |
4841 | json_object_free(json); | |
b5a8894d CS |
4842 | |
4843 | return ret; | |
7c8ff89e DS |
4844 | } |
4845 | ||
4846 | DEFUN (show_ip_ospf_instance_neighbor_all, | |
4847 | show_ip_ospf_instance_neighbor_all_cmd, | |
6147e2c6 | 4848 | "show ip ospf (1-65535) neighbor all [json]", |
7c8ff89e DS |
4849 | SHOW_STR |
4850 | IP_STR | |
4851 | "OSPF information\n" | |
4852 | "Instance ID\n" | |
4853 | "Neighbor list\n" | |
91756b38 | 4854 | "include down status neighbor\n" |
9973d184 | 4855 | JSON_STR) |
718e3744 | 4856 | { |
d62a17ae | 4857 | int idx_number = 3; |
4858 | struct ospf *ospf; | |
d7c0a89a | 4859 | unsigned short instance = 0; |
9f049418 | 4860 | bool uj = use_json(argc, argv); |
b1c3ae8c CS |
4861 | json_object *json = NULL; |
4862 | int ret = CMD_SUCCESS; | |
7c8ff89e | 4863 | |
d62a17ae | 4864 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
409f98ab | 4865 | if (instance != ospf_instance) |
ac28e4ec CS |
4866 | return CMD_NOT_MY_INSTANCE; |
4867 | ||
409f98ab IR |
4868 | ospf = ospf_lookup_instance(instance); |
4869 | if (!ospf || !ospf->oi_running) | |
d62a17ae | 4870 | return CMD_SUCCESS; |
b1c3ae8c CS |
4871 | if (uj) |
4872 | json = json_object_new_object(); | |
4873 | ||
4874 | ret = show_ip_ospf_neighbor_all_common(vty, ospf, json, uj, 0); | |
4875 | ||
4876 | if (uj) { | |
4877 | vty_out(vty, "%s\n", json_object_to_json_string_ext( | |
4878 | json, JSON_C_TO_STRING_PRETTY)); | |
4879 | json_object_free(json); | |
4880 | } | |
7c8ff89e | 4881 | |
b1c3ae8c | 4882 | return ret; |
7c8ff89e DS |
4883 | } |
4884 | ||
d62a17ae | 4885 | static int show_ip_ospf_neighbor_int_common(struct vty *vty, struct ospf *ospf, |
4886 | int arg_base, | |
4887 | struct cmd_token **argv, | |
9f049418 | 4888 | bool use_json, uint8_t use_vrf) |
d62a17ae | 4889 | { |
4890 | struct interface *ifp; | |
4891 | struct route_node *rn; | |
4892 | json_object *json = NULL; | |
91756b38 | 4893 | |
d62a17ae | 4894 | if (use_json) |
4895 | json = json_object_new_object(); | |
d62a17ae | 4896 | |
4897 | if (ospf->instance) { | |
4898 | if (use_json) | |
4899 | json_object_int_add(json, "ospfInstance", | |
4900 | ospf->instance); | |
4901 | else | |
4902 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
4903 | } | |
4904 | ||
b1c3ae8c | 4905 | ospf_show_vrf_name(ospf, vty, json, use_vrf); |
87bd50e8 | 4906 | |
a36898e7 | 4907 | ifp = if_lookup_by_name(argv[arg_base]->arg, ospf->vrf_id); |
d62a17ae | 4908 | if (!ifp) { |
4909 | if (use_json) | |
4910 | json_object_boolean_true_add(json, "noSuchIface"); | |
4911 | else | |
4912 | vty_out(vty, "No such interface.\n"); | |
4913 | return CMD_WARNING; | |
4914 | } | |
4915 | ||
4916 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { | |
4917 | struct ospf_interface *oi = rn->info; | |
4918 | ||
4919 | if (oi == NULL) | |
4920 | continue; | |
4921 | ||
4922 | show_ip_ospf_neighbor_sub(vty, oi, json, use_json); | |
4923 | } | |
4924 | ||
4925 | if (use_json) { | |
9d303b37 DL |
4926 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
4927 | json, JSON_C_TO_STRING_PRETTY)); | |
d62a17ae | 4928 | json_object_free(json); |
4929 | } else | |
4930 | vty_out(vty, "\n"); | |
4931 | ||
4932 | return CMD_SUCCESS; | |
718e3744 | 4933 | } |
4934 | ||
7c8ff89e DS |
4935 | DEFUN (show_ip_ospf_neighbor_int, |
4936 | show_ip_ospf_neighbor_int_cmd, | |
03ed9f02 | 4937 | "show ip ospf [vrf <NAME>] neighbor IFNAME [json]", |
7c8ff89e DS |
4938 | SHOW_STR |
4939 | IP_STR | |
4940 | "OSPF information\n" | |
03ed9f02 | 4941 | VRF_CMD_HELP_STR |
7c8ff89e | 4942 | "Neighbor list\n" |
91756b38 | 4943 | "Interface name\n" |
9973d184 | 4944 | JSON_STR) |
7c8ff89e | 4945 | { |
d62a17ae | 4946 | struct ospf *ospf; |
03ed9f02 PG |
4947 | int idx_ifname = 0; |
4948 | int idx_vrf = 0; | |
9f049418 | 4949 | bool uj = use_json(argc, argv); |
b5a8894d CS |
4950 | int ret = CMD_SUCCESS; |
4951 | struct interface *ifp = NULL; | |
03ed9f02 PG |
4952 | char *vrf_name = NULL; |
4953 | vrf_id_t vrf_id = VRF_DEFAULT; | |
4954 | struct vrf *vrf = NULL; | |
4955 | ||
4956 | if (argv_find(argv, argc, "vrf", &idx_vrf)) | |
4957 | vrf_name = argv[idx_vrf + 1]->arg; | |
4958 | if (vrf_name && strmatch(vrf_name, VRF_DEFAULT_NAME)) | |
4959 | vrf_name = NULL; | |
4960 | if (vrf_name) { | |
4961 | vrf = vrf_lookup_by_name(vrf_name); | |
4962 | if (vrf) | |
4963 | vrf_id = vrf->vrf_id; | |
4964 | } | |
4965 | ospf = ospf_lookup_by_vrf_id(vrf_id); | |
4966 | ||
4967 | if (!ospf || !ospf->oi_running) | |
4968 | return ret; | |
7c8ff89e | 4969 | |
b5a8894d CS |
4970 | if (!uj) |
4971 | show_ip_ospf_neighbour_header(vty); | |
7c8ff89e | 4972 | |
03ed9f02 | 4973 | argv_find(argv, argc, "IFNAME", &idx_ifname); |
b5a8894d | 4974 | |
a36898e7 | 4975 | ifp = if_lookup_by_name(argv[idx_ifname]->arg, vrf_id); |
03ed9f02 PG |
4976 | if (!ifp) |
4977 | return ret; | |
4978 | ||
4979 | ret = show_ip_ospf_neighbor_int_common(vty, ospf, idx_ifname, | |
4980 | argv, uj, 0); | |
b5a8894d | 4981 | return ret; |
7c8ff89e DS |
4982 | } |
4983 | ||
4984 | DEFUN (show_ip_ospf_instance_neighbor_int, | |
4985 | show_ip_ospf_instance_neighbor_int_cmd, | |
6147e2c6 | 4986 | "show ip ospf (1-65535) neighbor IFNAME [json]", |
7c8ff89e DS |
4987 | SHOW_STR |
4988 | IP_STR | |
4989 | "OSPF information\n" | |
4990 | "Instance ID\n" | |
4991 | "Neighbor list\n" | |
91756b38 | 4992 | "Interface name\n" |
9973d184 | 4993 | JSON_STR) |
7c8ff89e | 4994 | { |
d62a17ae | 4995 | int idx_number = 3; |
b4e84315 | 4996 | int idx_ifname = 5; |
d62a17ae | 4997 | struct ospf *ospf; |
d7c0a89a | 4998 | unsigned short instance = 0; |
9f049418 | 4999 | bool uj = use_json(argc, argv); |
7c8ff89e | 5000 | |
b5a8894d CS |
5001 | if (!uj) |
5002 | show_ip_ospf_neighbour_header(vty); | |
5003 | ||
d62a17ae | 5004 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
409f98ab | 5005 | if (instance != ospf_instance) |
ac28e4ec CS |
5006 | return CMD_NOT_MY_INSTANCE; |
5007 | ||
409f98ab IR |
5008 | ospf = ospf_lookup_instance(instance); |
5009 | if (!ospf || !ospf->oi_running) | |
d62a17ae | 5010 | return CMD_SUCCESS; |
7c8ff89e | 5011 | |
b5a8894d CS |
5012 | if (!uj) |
5013 | show_ip_ospf_neighbour_header(vty); | |
5014 | ||
996c9314 LB |
5015 | return show_ip_ospf_neighbor_int_common(vty, ospf, idx_ifname, argv, uj, |
5016 | 0); | |
718e3744 | 5017 | } |
5018 | ||
d62a17ae | 5019 | static void show_ip_ospf_nbr_nbma_detail_sub(struct vty *vty, |
5020 | struct ospf_interface *oi, | |
5021 | struct ospf_nbr_nbma *nbr_nbma, | |
9f049418 | 5022 | bool use_json, json_object *json) |
d62a17ae | 5023 | { |
5024 | char timebuf[OSPF_TIME_DUMP_SIZE]; | |
96b663a3 | 5025 | char buf[PREFIX_STRLEN]; |
d62a17ae | 5026 | json_object *json_sub = NULL; |
718e3744 | 5027 | |
d62a17ae | 5028 | if (use_json) |
5029 | json_sub = json_object_new_object(); | |
5030 | else /* Show neighbor ID. */ | |
5031 | vty_out(vty, " Neighbor %s,", "-"); | |
5032 | ||
5033 | /* Show interface address. */ | |
5034 | if (use_json) | |
5035 | json_object_string_add(json_sub, "ifaceAddress", | |
96b663a3 MS |
5036 | inet_ntop(AF_INET, &nbr_nbma->addr, |
5037 | buf, sizeof(buf))); | |
d62a17ae | 5038 | else |
96b663a3 MS |
5039 | vty_out(vty, " interface address %pI4\n", |
5040 | &nbr_nbma->addr); | |
d62a17ae | 5041 | |
5042 | /* Show Area ID. */ | |
5043 | if (use_json) { | |
5044 | json_object_string_add(json_sub, "areaId", | |
5045 | ospf_area_desc_string(oi->area)); | |
5046 | json_object_string_add(json_sub, "iface", IF_NAME(oi)); | |
5047 | } else | |
5048 | vty_out(vty, " In the area %s via interface %s\n", | |
5049 | ospf_area_desc_string(oi->area), IF_NAME(oi)); | |
5050 | ||
5051 | /* Show neighbor priority and state. */ | |
5052 | if (use_json) { | |
5053 | json_object_int_add(json_sub, "nbrPriority", | |
5054 | nbr_nbma->priority); | |
5055 | json_object_string_add(json_sub, "nbrState", "down"); | |
5056 | } else | |
5057 | vty_out(vty, " Neighbor priority is %d, State is %s,", | |
5058 | nbr_nbma->priority, "Down"); | |
5059 | ||
5060 | /* Show state changes. */ | |
5061 | if (use_json) | |
5062 | json_object_int_add(json_sub, "stateChangeCounter", | |
5063 | nbr_nbma->state_change); | |
5064 | else | |
5065 | vty_out(vty, " %d state changes\n", nbr_nbma->state_change); | |
5066 | ||
5067 | /* Show PollInterval */ | |
5068 | if (use_json) | |
5069 | json_object_int_add(json_sub, "pollInterval", nbr_nbma->v_poll); | |
5070 | else | |
5071 | vty_out(vty, " Poll interval %d\n", nbr_nbma->v_poll); | |
5072 | ||
5073 | /* Show poll-interval timer. */ | |
b575a12c A |
5074 | if (nbr_nbma->t_poll) { |
5075 | if (use_json) { | |
5076 | long time_store; | |
5077 | time_store = monotime_until(&nbr_nbma->t_poll->u.sands, | |
5078 | NULL) / 1000LL; | |
5079 | json_object_int_add(json_sub, | |
5080 | "pollIntervalTimerDueMsec", | |
5081 | time_store); | |
5082 | } else | |
5083 | vty_out(vty, " Poll timer due in %s\n", | |
5084 | ospf_timer_dump(nbr_nbma->t_poll, timebuf, | |
5085 | sizeof(timebuf))); | |
5086 | } | |
d62a17ae | 5087 | |
5088 | /* Show poll-interval timer thread. */ | |
5089 | if (use_json) { | |
5090 | if (nbr_nbma->t_poll != NULL) | |
5091 | json_object_string_add(json_sub, | |
5092 | "pollIntervalTimerThread", "on"); | |
5093 | } else | |
5094 | vty_out(vty, " Thread Poll Timer %s\n", | |
5095 | nbr_nbma->t_poll != NULL ? "on" : "off"); | |
5096 | ||
5097 | if (use_json) | |
5098 | json_object_object_add(json, "noNbrId", json_sub); | |
5099 | } | |
5100 | ||
5101 | static void show_ip_ospf_neighbor_detail_sub(struct vty *vty, | |
5102 | struct ospf_interface *oi, | |
5103 | struct ospf_neighbor *nbr, | |
cb0b2ac6 | 5104 | struct ospf_neighbor *prev_nbr, |
9f049418 | 5105 | json_object *json, bool use_json) |
d62a17ae | 5106 | { |
5107 | char timebuf[OSPF_TIME_DUMP_SIZE]; | |
cb0b2ac6 CS |
5108 | json_object *json_neigh = NULL, *json_neigh_array = NULL; |
5109 | char neigh_str[INET_ADDRSTRLEN] = {0}; | |
96b663a3 | 5110 | char buf[PREFIX_STRLEN]; |
d62a17ae | 5111 | |
cb0b2ac6 CS |
5112 | if (use_json) { |
5113 | if (prev_nbr && | |
5114 | !IPV4_ADDR_SAME(&prev_nbr->src, &nbr->src)) { | |
5115 | json_neigh_array = NULL; | |
5116 | } | |
5117 | ||
975a328e DA |
5118 | if (nbr->state == NSM_Attempt |
5119 | && nbr->router_id.s_addr == INADDR_ANY) | |
cb0b2ac6 CS |
5120 | strlcpy(neigh_str, "noNbrId", sizeof(neigh_str)); |
5121 | else | |
96b663a3 MS |
5122 | inet_ntop(AF_INET, &nbr->router_id, |
5123 | neigh_str, sizeof(neigh_str)); | |
cb0b2ac6 CS |
5124 | |
5125 | json_object_object_get_ex(json, neigh_str, &json_neigh_array); | |
5126 | ||
5127 | if (!json_neigh_array) { | |
5128 | json_neigh_array = json_object_new_array(); | |
5129 | json_object_object_add(json, neigh_str, | |
5130 | json_neigh_array); | |
5131 | } | |
5132 | ||
5133 | json_neigh = json_object_new_object(); | |
5134 | ||
5135 | } else { | |
d62a17ae | 5136 | /* Show neighbor ID. */ |
975a328e DA |
5137 | if (nbr->state == NSM_Attempt |
5138 | && nbr->router_id.s_addr == INADDR_ANY) | |
d62a17ae | 5139 | vty_out(vty, " Neighbor %s,", "-"); |
5140 | else | |
96b663a3 MS |
5141 | vty_out(vty, " Neighbor %pI4,", |
5142 | &nbr->router_id); | |
d62a17ae | 5143 | } |
5144 | ||
5145 | /* Show interface address. */ | |
5146 | if (use_json) | |
cb0b2ac6 | 5147 | json_object_string_add(json_neigh, "ifaceAddress", |
96b663a3 MS |
5148 | inet_ntop(AF_INET, |
5149 | &nbr->address.u.prefix4, | |
5150 | buf, sizeof(buf))); | |
d62a17ae | 5151 | else |
96b663a3 MS |
5152 | vty_out(vty, " interface address %pI4\n", |
5153 | &nbr->address.u.prefix4); | |
d62a17ae | 5154 | |
5155 | /* Show Area ID. */ | |
5156 | if (use_json) { | |
cb0b2ac6 | 5157 | json_object_string_add(json_neigh, "areaId", |
d62a17ae | 5158 | ospf_area_desc_string(oi->area)); |
cb0b2ac6 | 5159 | json_object_string_add(json_neigh, "ifaceName", oi->ifp->name); |
d62a17ae | 5160 | } else |
5161 | vty_out(vty, " In the area %s via interface %s\n", | |
5162 | ospf_area_desc_string(oi->area), oi->ifp->name); | |
5163 | ||
5164 | /* Show neighbor priority and state. */ | |
5165 | if (use_json) { | |
cb0b2ac6 | 5166 | json_object_int_add(json_neigh, "nbrPriority", nbr->priority); |
d62a17ae | 5167 | json_object_string_add( |
cb0b2ac6 | 5168 | json_neigh, "nbrState", |
d62a17ae | 5169 | lookup_msg(ospf_nsm_state_msg, nbr->state, NULL)); |
5170 | } else | |
5171 | vty_out(vty, " Neighbor priority is %d, State is %s,", | |
5172 | nbr->priority, | |
5173 | lookup_msg(ospf_nsm_state_msg, nbr->state, NULL)); | |
5174 | ||
5175 | /* Show state changes. */ | |
5176 | if (use_json) | |
cb0b2ac6 | 5177 | json_object_int_add(json_neigh, "stateChangeCounter", |
d62a17ae | 5178 | nbr->state_change); |
5179 | else | |
5180 | vty_out(vty, " %d state changes\n", nbr->state_change); | |
5181 | ||
5182 | if (nbr->ts_last_progress.tv_sec || nbr->ts_last_progress.tv_usec) { | |
5183 | struct timeval res; | |
5184 | long time_store; | |
5185 | ||
5186 | time_store = | |
5187 | monotime_since(&nbr->ts_last_progress, &res) / 1000LL; | |
5188 | if (use_json) { | |
cb0b2ac6 | 5189 | json_object_int_add(json_neigh, "lastPrgrsvChangeMsec", |
d62a17ae | 5190 | time_store); |
5191 | } else { | |
5192 | vty_out(vty, | |
5193 | " Most recent state change statistics:\n"); | |
5194 | vty_out(vty, " Progressive change %s ago\n", | |
5195 | ospf_timeval_dump(&res, timebuf, | |
5196 | sizeof(timebuf))); | |
5197 | } | |
5198 | } | |
5199 | ||
5200 | if (nbr->ts_last_regress.tv_sec || nbr->ts_last_regress.tv_usec) { | |
5201 | struct timeval res; | |
5202 | long time_store; | |
5203 | ||
5204 | time_store = | |
5205 | monotime_since(&nbr->ts_last_regress, &res) / 1000LL; | |
5206 | if (use_json) { | |
cb0b2ac6 | 5207 | json_object_int_add(json_neigh, |
d62a17ae | 5208 | "lastRegressiveChangeMsec", |
5209 | time_store); | |
5210 | if (nbr->last_regress_str) | |
5211 | json_object_string_add( | |
cb0b2ac6 CS |
5212 | json_neigh, |
5213 | "lastRegressiveChangeReason", | |
d62a17ae | 5214 | nbr->last_regress_str); |
5215 | } else { | |
5216 | vty_out(vty, | |
5217 | " Regressive change %s ago, due to %s\n", | |
5218 | ospf_timeval_dump(&res, timebuf, | |
5219 | sizeof(timebuf)), | |
5220 | (nbr->last_regress_str ? nbr->last_regress_str | |
5221 | : "??")); | |
5222 | } | |
5223 | } | |
5224 | ||
5225 | /* Show Designated Rotuer ID. */ | |
5226 | if (use_json) | |
cb0b2ac6 | 5227 | json_object_string_add(json_neigh, "routerDesignatedId", |
96b663a3 MS |
5228 | inet_ntop(AF_INET, &nbr->d_router, |
5229 | buf, sizeof(buf))); | |
d62a17ae | 5230 | else |
96b663a3 | 5231 | vty_out(vty, " DR is %pI4,", &nbr->d_router); |
d62a17ae | 5232 | |
5233 | /* Show Backup Designated Rotuer ID. */ | |
5234 | if (use_json) | |
cb0b2ac6 | 5235 | json_object_string_add(json_neigh, "routerDesignatedBackupId", |
96b663a3 MS |
5236 | inet_ntop(AF_INET, &nbr->bd_router, |
5237 | buf, sizeof(buf))); | |
d62a17ae | 5238 | else |
96b663a3 | 5239 | vty_out(vty, " BDR is %pI4\n", &nbr->bd_router); |
d62a17ae | 5240 | |
5241 | /* Show options. */ | |
5242 | if (use_json) { | |
cb0b2ac6 CS |
5243 | json_object_int_add(json_neigh, "optionsCounter", nbr->options); |
5244 | json_object_string_add(json_neigh, "optionsList", | |
d62a17ae | 5245 | ospf_options_dump(nbr->options)); |
5246 | } else | |
5247 | vty_out(vty, " Options %d %s\n", nbr->options, | |
5248 | ospf_options_dump(nbr->options)); | |
5249 | ||
5250 | /* Show Router Dead interval timer. */ | |
5251 | if (use_json) { | |
5252 | if (nbr->t_inactivity) { | |
5253 | long time_store; | |
5254 | time_store = monotime_until(&nbr->t_inactivity->u.sands, | |
5255 | NULL) | |
5256 | / 1000LL; | |
cb0b2ac6 | 5257 | json_object_int_add(json_neigh, |
d62a17ae | 5258 | "routerDeadIntervalTimerDueMsec", |
5259 | time_store); | |
5260 | } else | |
5261 | json_object_int_add( | |
cb0b2ac6 CS |
5262 | json_neigh, |
5263 | "routerDeadIntervalTimerDueMsec", -1); | |
d62a17ae | 5264 | } else |
5265 | vty_out(vty, " Dead timer due in %s\n", | |
5266 | ospf_timer_dump(nbr->t_inactivity, timebuf, | |
5267 | sizeof(timebuf))); | |
5268 | ||
5269 | /* Show Database Summary list. */ | |
5270 | if (use_json) | |
cb0b2ac6 | 5271 | json_object_int_add(json_neigh, "databaseSummaryListCounter", |
d62a17ae | 5272 | ospf_db_summary_count(nbr)); |
5273 | else | |
5274 | vty_out(vty, " Database Summary List %d\n", | |
5275 | ospf_db_summary_count(nbr)); | |
5276 | ||
5277 | /* Show Link State Request list. */ | |
5278 | if (use_json) | |
cb0b2ac6 | 5279 | json_object_int_add(json_neigh, "linkStateRequestListCounter", |
d62a17ae | 5280 | ospf_ls_request_count(nbr)); |
5281 | else | |
5282 | vty_out(vty, " Link State Request List %ld\n", | |
5283 | ospf_ls_request_count(nbr)); | |
5284 | ||
5285 | /* Show Link State Retransmission list. */ | |
5286 | if (use_json) | |
cb0b2ac6 | 5287 | json_object_int_add(json_neigh, |
d62a17ae | 5288 | "linkStateRetransmissionListCounter", |
5289 | ospf_ls_retransmit_count(nbr)); | |
5290 | else | |
5291 | vty_out(vty, " Link State Retransmission List %ld\n", | |
5292 | ospf_ls_retransmit_count(nbr)); | |
5293 | ||
5294 | /* Show inactivity timer thread. */ | |
5295 | if (use_json) { | |
5296 | if (nbr->t_inactivity != NULL) | |
cb0b2ac6 | 5297 | json_object_string_add(json_neigh, |
d62a17ae | 5298 | "threadInactivityTimer", "on"); |
5299 | } else | |
5300 | vty_out(vty, " Thread Inactivity Timer %s\n", | |
5301 | nbr->t_inactivity != NULL ? "on" : "off"); | |
5302 | ||
5303 | /* Show Database Description retransmission thread. */ | |
5304 | if (use_json) { | |
5305 | if (nbr->t_db_desc != NULL) | |
5306 | json_object_string_add( | |
cb0b2ac6 | 5307 | json_neigh, |
d62a17ae | 5308 | "threadDatabaseDescriptionRetransmission", |
5309 | "on"); | |
5310 | } else | |
5311 | vty_out(vty, | |
5312 | " Thread Database Description Retransmision %s\n", | |
5313 | nbr->t_db_desc != NULL ? "on" : "off"); | |
5314 | ||
5315 | /* Show Link State Request Retransmission thread. */ | |
5316 | if (use_json) { | |
5317 | if (nbr->t_ls_req != NULL) | |
5318 | json_object_string_add( | |
cb0b2ac6 | 5319 | json_neigh, |
d62a17ae | 5320 | "threadLinkStateRequestRetransmission", "on"); |
5321 | } else | |
5322 | vty_out(vty, | |
5323 | " Thread Link State Request Retransmission %s\n", | |
5324 | nbr->t_ls_req != NULL ? "on" : "off"); | |
5325 | ||
5326 | /* Show Link State Update Retransmission thread. */ | |
5327 | if (use_json) { | |
5328 | if (nbr->t_ls_upd != NULL) | |
5329 | json_object_string_add( | |
cb0b2ac6 CS |
5330 | json_neigh, |
5331 | "threadLinkStateUpdateRetransmission", | |
d62a17ae | 5332 | "on"); |
5333 | } else | |
5334 | vty_out(vty, | |
5335 | " Thread Link State Update Retransmission %s\n\n", | |
5336 | nbr->t_ls_upd != NULL ? "on" : "off"); | |
5337 | ||
abd5b8c7 | 5338 | if (!use_json) { |
5339 | vty_out(vty, " Graceful restart Helper info:\n"); | |
5340 | ||
5341 | if (OSPF_GR_IS_ACTIVE_HELPER(nbr)) { | |
5342 | vty_out(vty, | |
5343 | " Graceful Restart HELPER Status : Inprogress.\n"); | |
5344 | ||
5345 | vty_out(vty, | |
5346 | " Graceful Restart grace period time: %d (seconds).\n", | |
5347 | nbr->gr_helper_info.recvd_grace_period); | |
5348 | vty_out(vty, " Graceful Restart reason: %s.\n", | |
d05d5280 MS |
5349 | ospf_restart_reason2str( |
5350 | nbr->gr_helper_info.gr_restart_reason)); | |
abd5b8c7 | 5351 | } else { |
5352 | vty_out(vty, | |
5353 | " Graceful Restart HELPER Status : None\n"); | |
5354 | } | |
5355 | ||
5356 | if (nbr->gr_helper_info.rejected_reason | |
5357 | != OSPF_HELPER_REJECTED_NONE) | |
5358 | vty_out(vty, " Helper rejected reason: %s.\n", | |
d05d5280 MS |
5359 | ospf_rejected_reason2str( |
5360 | nbr->gr_helper_info.rejected_reason)); | |
abd5b8c7 | 5361 | |
5362 | if (nbr->gr_helper_info.helper_exit_reason | |
5363 | != OSPF_GR_HELPER_EXIT_NONE) | |
5364 | vty_out(vty, " Last helper exit reason: %s.\n\n", | |
d05d5280 MS |
5365 | ospf_exit_reason2str( |
5366 | nbr->gr_helper_info.helper_exit_reason)); | |
abd5b8c7 | 5367 | else |
5368 | vty_out(vty, "\n"); | |
5369 | } else { | |
5370 | json_object_string_add(json_neigh, "grHelperStatus", | |
5371 | OSPF_GR_IS_ACTIVE_HELPER(nbr) ? | |
5372 | "Inprogress" | |
5373 | : "None"); | |
5374 | if (OSPF_GR_IS_ACTIVE_HELPER(nbr)) { | |
5375 | json_object_int_add( | |
5376 | json_neigh, "graceInterval", | |
5377 | nbr->gr_helper_info.recvd_grace_period); | |
5378 | json_object_string_add( | |
5379 | json_neigh, "grRestartReason", | |
d05d5280 MS |
5380 | ospf_restart_reason2str( |
5381 | nbr->gr_helper_info.gr_restart_reason)); | |
abd5b8c7 | 5382 | } |
5383 | ||
5384 | if (nbr->gr_helper_info.rejected_reason | |
5385 | != OSPF_HELPER_REJECTED_NONE) | |
5386 | json_object_string_add( | |
5387 | json_neigh, "helperRejectReason", | |
d05d5280 MS |
5388 | ospf_rejected_reason2str( |
5389 | nbr->gr_helper_info.rejected_reason)); | |
abd5b8c7 | 5390 | |
5391 | if (nbr->gr_helper_info.helper_exit_reason | |
5392 | != OSPF_GR_HELPER_EXIT_NONE) | |
5393 | json_object_string_add( | |
5394 | json_neigh, "helperExitReason", | |
d05d5280 MS |
5395 | ospf_exit_reason2str( |
5396 | nbr->gr_helper_info | |
5397 | .helper_exit_reason)); | |
abd5b8c7 | 5398 | } |
5399 | ||
659f4e40 | 5400 | bfd_sess_show(vty, json_neigh, nbr->bfd_session); |
cb0b2ac6 CS |
5401 | |
5402 | if (use_json) | |
5403 | json_object_array_add(json_neigh_array, json_neigh); | |
d62a17ae | 5404 | |
d62a17ae | 5405 | } |
5406 | ||
5407 | static int show_ip_ospf_neighbor_id_common(struct vty *vty, struct ospf *ospf, | |
986b87cb | 5408 | struct in_addr *router_id, |
9f049418 | 5409 | bool use_json, uint8_t use_vrf) |
d62a17ae | 5410 | { |
5411 | struct listnode *node; | |
5412 | struct ospf_neighbor *nbr; | |
5413 | struct ospf_interface *oi; | |
d62a17ae | 5414 | json_object *json = NULL; |
5415 | ||
5416 | if (use_json) | |
5417 | json = json_object_new_object(); | |
5418 | ||
5419 | if (ospf->instance) { | |
5420 | if (use_json) | |
5421 | json_object_int_add(json, "ospfInstance", | |
5422 | ospf->instance); | |
5423 | else | |
5424 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
5425 | } | |
5426 | ||
b1c3ae8c | 5427 | ospf_show_vrf_name(ospf, vty, json, use_vrf); |
87bd50e8 | 5428 | |
d62a17ae | 5429 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) { |
986b87cb | 5430 | if ((nbr = ospf_nbr_lookup_by_routerid(oi->nbrs, router_id))) { |
cb0b2ac6 CS |
5431 | show_ip_ospf_neighbor_detail_sub(vty, oi, nbr, NULL, |
5432 | json, use_json); | |
d62a17ae | 5433 | } |
5434 | } | |
5435 | ||
5436 | if (use_json) { | |
9d303b37 DL |
5437 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
5438 | json, JSON_C_TO_STRING_PRETTY)); | |
d62a17ae | 5439 | json_object_free(json); |
5440 | } else | |
5441 | vty_out(vty, "\n"); | |
5442 | ||
5443 | return CMD_SUCCESS; | |
718e3744 | 5444 | } |
5445 | ||
986b87cb | 5446 | DEFPY (show_ip_ospf_neighbor_id, |
7c8ff89e | 5447 | show_ip_ospf_neighbor_id_cmd, |
986b87cb | 5448 | "show ip ospf neighbor A.B.C.D$router_id [json$json]", |
718e3744 | 5449 | SHOW_STR |
5450 | IP_STR | |
5451 | "OSPF information\n" | |
5452 | "Neighbor list\n" | |
3ac237f8 | 5453 | "Neighbor ID\n" |
9973d184 | 5454 | JSON_STR) |
718e3744 | 5455 | { |
d62a17ae | 5456 | struct ospf *ospf; |
986b87cb | 5457 | struct listnode *node; |
b5a8894d | 5458 | int ret = CMD_SUCCESS; |
7c8ff89e | 5459 | |
b5a8894d CS |
5460 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { |
5461 | if (!ospf->oi_running) | |
5462 | continue; | |
986b87cb RW |
5463 | ret = show_ip_ospf_neighbor_id_common(vty, ospf, &router_id, |
5464 | !!json, 0); | |
b5a8894d | 5465 | } |
7c8ff89e | 5466 | |
b5a8894d | 5467 | return ret; |
7c8ff89e DS |
5468 | } |
5469 | ||
986b87cb | 5470 | DEFPY (show_ip_ospf_instance_neighbor_id, |
7c8ff89e | 5471 | show_ip_ospf_instance_neighbor_id_cmd, |
986b87cb | 5472 | "show ip ospf (1-65535)$instance neighbor A.B.C.D$router_id [json$json]", |
7c8ff89e DS |
5473 | SHOW_STR |
5474 | IP_STR | |
5475 | "OSPF information\n" | |
5476 | "Instance ID\n" | |
5477 | "Neighbor list\n" | |
3ac237f8 | 5478 | "Neighbor ID\n" |
9973d184 | 5479 | JSON_STR) |
7c8ff89e | 5480 | { |
d62a17ae | 5481 | struct ospf *ospf; |
7c8ff89e | 5482 | |
409f98ab | 5483 | if (instance != ospf_instance) |
ac28e4ec CS |
5484 | return CMD_NOT_MY_INSTANCE; |
5485 | ||
409f98ab IR |
5486 | ospf = ospf_lookup_instance(instance); |
5487 | if (!ospf || !ospf->oi_running) | |
d62a17ae | 5488 | return CMD_SUCCESS; |
7c8ff89e | 5489 | |
986b87cb RW |
5490 | return show_ip_ospf_neighbor_id_common(vty, ospf, &router_id, !!json, |
5491 | 0); | |
7c8ff89e DS |
5492 | } |
5493 | ||
d62a17ae | 5494 | static int show_ip_ospf_neighbor_detail_common(struct vty *vty, |
5495 | struct ospf *ospf, | |
9f049418 | 5496 | json_object *json, bool use_json, |
d7c0a89a | 5497 | uint8_t use_vrf) |
d62a17ae | 5498 | { |
5499 | struct ospf_interface *oi; | |
5500 | struct listnode *node; | |
b1c3ae8c | 5501 | json_object *json_vrf = NULL; |
cb0b2ac6 | 5502 | json_object *json_nbr_sub = NULL; |
d62a17ae | 5503 | |
b1c3ae8c CS |
5504 | if (use_json) { |
5505 | if (use_vrf) | |
5506 | json_vrf = json_object_new_object(); | |
5507 | else | |
5508 | json_vrf = json; | |
cb0b2ac6 CS |
5509 | |
5510 | json_nbr_sub = json_object_new_object(); | |
b1c3ae8c | 5511 | } |
cb0b2ac6 | 5512 | |
d62a17ae | 5513 | if (ospf->instance) { |
5514 | if (use_json) | |
cb0b2ac6 | 5515 | json_object_int_add(json, "ospfInstance", |
d62a17ae | 5516 | ospf->instance); |
5517 | else | |
5518 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
5519 | } | |
5520 | ||
b1c3ae8c | 5521 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); |
87bd50e8 | 5522 | |
d62a17ae | 5523 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) { |
5524 | struct route_node *rn; | |
cb0b2ac6 | 5525 | struct ospf_neighbor *nbr, *prev_nbr = NULL; |
d62a17ae | 5526 | |
5527 | for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) { | |
5528 | if ((nbr = rn->info)) { | |
5529 | if (nbr != oi->nbr_self) { | |
5530 | if (nbr->state != NSM_Down) { | |
5531 | show_ip_ospf_neighbor_detail_sub( | |
cb0b2ac6 CS |
5532 | vty, oi, nbr, prev_nbr, |
5533 | json_nbr_sub, use_json); | |
d62a17ae | 5534 | } |
5535 | } | |
cb0b2ac6 | 5536 | prev_nbr = nbr; |
d62a17ae | 5537 | } |
5538 | } | |
5539 | } | |
5540 | ||
5541 | if (use_json) { | |
cb0b2ac6 CS |
5542 | json_object_object_add(json_vrf, "neighbors", |
5543 | json_nbr_sub); | |
b1c3ae8c CS |
5544 | if (use_vrf) { |
5545 | if (ospf->vrf_id == VRF_DEFAULT) | |
5546 | json_object_object_add(json, "default", | |
5547 | json_vrf); | |
5548 | else | |
5549 | json_object_object_add(json, ospf->name, | |
5550 | json_vrf); | |
5551 | } | |
d62a17ae | 5552 | } else |
5553 | vty_out(vty, "\n"); | |
5554 | ||
5555 | return CMD_SUCCESS; | |
718e3744 | 5556 | } |
5557 | ||
7c8ff89e DS |
5558 | DEFUN (show_ip_ospf_neighbor_detail, |
5559 | show_ip_ospf_neighbor_detail_cmd, | |
b5a8894d | 5560 | "show ip ospf [vrf <NAME|all>] neighbor detail [json]", |
718e3744 | 5561 | SHOW_STR |
5562 | IP_STR | |
5563 | "OSPF information\n" | |
b5a8894d CS |
5564 | VRF_CMD_HELP_STR |
5565 | "All VRFs\n" | |
718e3744 | 5566 | "Neighbor list\n" |
3ac237f8 | 5567 | "detail of all neighbors\n" |
9973d184 | 5568 | JSON_STR) |
718e3744 | 5569 | { |
d62a17ae | 5570 | struct ospf *ospf; |
9f049418 | 5571 | bool uj = use_json(argc, argv); |
b5a8894d CS |
5572 | struct listnode *node = NULL; |
5573 | char *vrf_name = NULL; | |
2951a7a4 | 5574 | bool all_vrf = false; |
b5a8894d CS |
5575 | int ret = CMD_SUCCESS; |
5576 | int inst = 0; | |
5577 | int idx_vrf = 0; | |
d7c0a89a | 5578 | uint8_t use_vrf = 0; |
b1c3ae8c | 5579 | json_object *json = NULL; |
7c8ff89e | 5580 | |
43b8d1d8 | 5581 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
7c8ff89e | 5582 | |
b1c3ae8c CS |
5583 | if (uj) |
5584 | json = json_object_new_object(); | |
5585 | ||
b5a8894d CS |
5586 | /* vrf input is provided could be all or specific vrf*/ |
5587 | if (vrf_name) { | |
b1c3ae8c | 5588 | use_vrf = 1; |
b5a8894d CS |
5589 | if (all_vrf) { |
5590 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
5591 | if (!ospf->oi_running) | |
5592 | continue; | |
996c9314 LB |
5593 | ret = show_ip_ospf_neighbor_detail_common( |
5594 | vty, ospf, json, uj, use_vrf); | |
b1c3ae8c CS |
5595 | } |
5596 | if (uj) { | |
5597 | vty_out(vty, "%s\n", | |
996c9314 LB |
5598 | json_object_to_json_string_ext( |
5599 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 5600 | json_object_free(json); |
b5a8894d | 5601 | } |
b1c3ae8c | 5602 | |
b5a8894d CS |
5603 | return ret; |
5604 | } | |
5605 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
b1c3ae8c CS |
5606 | if (ospf == NULL || !ospf->oi_running) { |
5607 | if (uj) | |
5608 | json_object_free(json); | |
b5a8894d | 5609 | return CMD_SUCCESS; |
b1c3ae8c | 5610 | } |
b5a8894d CS |
5611 | } else { |
5612 | /* Display default ospf (instance 0) info */ | |
5613 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
b1c3ae8c CS |
5614 | if (ospf == NULL || !ospf->oi_running) { |
5615 | if (uj) | |
5616 | json_object_free(json); | |
b5a8894d | 5617 | return CMD_SUCCESS; |
b1c3ae8c | 5618 | } |
b5a8894d CS |
5619 | } |
5620 | ||
b1c3ae8c CS |
5621 | if (ospf) { |
5622 | ret = show_ip_ospf_neighbor_detail_common(vty, ospf, json, uj, | |
5623 | use_vrf); | |
5624 | if (uj) { | |
5625 | vty_out(vty, "%s\n", | |
996c9314 LB |
5626 | json_object_to_json_string_ext( |
5627 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c CS |
5628 | } |
5629 | } | |
5630 | ||
5631 | if (uj) | |
5632 | json_object_free(json); | |
b5a8894d CS |
5633 | |
5634 | return ret; | |
7c8ff89e DS |
5635 | } |
5636 | ||
5637 | DEFUN (show_ip_ospf_instance_neighbor_detail, | |
5638 | show_ip_ospf_instance_neighbor_detail_cmd, | |
6147e2c6 | 5639 | "show ip ospf (1-65535) neighbor detail [json]", |
7c8ff89e DS |
5640 | SHOW_STR |
5641 | IP_STR | |
5642 | "OSPF information\n" | |
5643 | "Instance ID\n" | |
5644 | "Neighbor list\n" | |
3ac237f8 | 5645 | "detail of all neighbors\n" |
9973d184 | 5646 | JSON_STR) |
7c8ff89e | 5647 | { |
d62a17ae | 5648 | int idx_number = 3; |
5649 | struct ospf *ospf; | |
d7c0a89a | 5650 | unsigned short instance = 0; |
9f049418 | 5651 | bool uj = use_json(argc, argv); |
b1c3ae8c CS |
5652 | json_object *json = NULL; |
5653 | int ret = CMD_SUCCESS; | |
7c8ff89e | 5654 | |
d62a17ae | 5655 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
409f98ab | 5656 | if (instance != ospf_instance) |
ac28e4ec CS |
5657 | return CMD_NOT_MY_INSTANCE; |
5658 | ||
409f98ab IR |
5659 | ospf = ospf_lookup_instance(instance); |
5660 | if (!ospf || !ospf->oi_running) | |
d62a17ae | 5661 | return CMD_SUCCESS; |
7c8ff89e | 5662 | |
b1c3ae8c CS |
5663 | if (uj) |
5664 | json = json_object_new_object(); | |
5665 | ||
5666 | ret = show_ip_ospf_neighbor_detail_common(vty, ospf, json, uj, 0); | |
5667 | ||
5668 | if (uj) { | |
5669 | vty_out(vty, "%s\n", json_object_to_json_string_ext( | |
5670 | json, JSON_C_TO_STRING_PRETTY)); | |
5671 | json_object_free(json); | |
5672 | } | |
5673 | ||
5674 | return ret; | |
7c8ff89e DS |
5675 | } |
5676 | ||
d62a17ae | 5677 | static int show_ip_ospf_neighbor_detail_all_common(struct vty *vty, |
5678 | struct ospf *ospf, | |
b1c3ae8c | 5679 | json_object *json, |
9f049418 | 5680 | bool use_json, |
d7c0a89a | 5681 | uint8_t use_vrf) |
d62a17ae | 5682 | { |
5683 | struct listnode *node; | |
5684 | struct ospf_interface *oi; | |
b1c3ae8c | 5685 | json_object *json_vrf = NULL; |
718e3744 | 5686 | |
b1c3ae8c CS |
5687 | if (use_json) { |
5688 | if (use_vrf) | |
5689 | json_vrf = json_object_new_object(); | |
5690 | else | |
5691 | json_vrf = json; | |
5692 | } | |
d62a17ae | 5693 | |
5694 | if (ospf->instance) { | |
5695 | if (use_json) | |
5696 | json_object_int_add(json, "ospfInstance", | |
5697 | ospf->instance); | |
5698 | else | |
5699 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
5700 | } | |
5701 | ||
b1c3ae8c | 5702 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); |
87bd50e8 | 5703 | |
d62a17ae | 5704 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) { |
5705 | struct route_node *rn; | |
cb0b2ac6 | 5706 | struct ospf_neighbor *nbr, *prev_nbr = NULL; |
d62a17ae | 5707 | struct ospf_nbr_nbma *nbr_nbma; |
5708 | ||
cb0b2ac6 CS |
5709 | for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) { |
5710 | if ((nbr = rn->info)) { | |
d62a17ae | 5711 | if (nbr != oi->nbr_self) |
5712 | if (nbr->state != NSM_Down) | |
5713 | show_ip_ospf_neighbor_detail_sub( | |
5714 | vty, oi, rn->info, | |
cb0b2ac6 | 5715 | prev_nbr, |
b1c3ae8c | 5716 | json_vrf, use_json); |
cb0b2ac6 CS |
5717 | prev_nbr = nbr; |
5718 | } | |
5719 | } | |
d62a17ae | 5720 | |
5721 | if (oi->type == OSPF_IFTYPE_NBMA) { | |
5722 | struct listnode *nd; | |
5723 | ||
5724 | for (ALL_LIST_ELEMENTS_RO(oi->nbr_nbma, nd, nbr_nbma)) { | |
5725 | if (nbr_nbma->nbr == NULL | |
5726 | || nbr_nbma->nbr->state == NSM_Down) | |
5727 | show_ip_ospf_nbr_nbma_detail_sub( | |
5728 | vty, oi, nbr_nbma, use_json, | |
b1c3ae8c | 5729 | json_vrf); |
d62a17ae | 5730 | } |
5731 | } | |
5732 | } | |
5733 | ||
5734 | if (use_json) { | |
b1c3ae8c CS |
5735 | if (use_vrf) { |
5736 | if (ospf->vrf_id == VRF_DEFAULT) | |
5737 | json_object_object_add(json, "default", | |
5738 | json_vrf); | |
5739 | else | |
5740 | json_object_object_add(json, ospf->name, | |
5741 | json_vrf); | |
5742 | } | |
d62a17ae | 5743 | } else { |
5744 | vty_out(vty, "\n"); | |
5745 | } | |
5746 | ||
5747 | return CMD_SUCCESS; | |
718e3744 | 5748 | } |
5749 | ||
7c8ff89e DS |
5750 | DEFUN (show_ip_ospf_neighbor_detail_all, |
5751 | show_ip_ospf_neighbor_detail_all_cmd, | |
b5a8894d | 5752 | "show ip ospf [vrf <NAME|all>] neighbor detail all [json]", |
718e3744 | 5753 | SHOW_STR |
5754 | IP_STR | |
5755 | "OSPF information\n" | |
b5a8894d CS |
5756 | VRF_CMD_HELP_STR |
5757 | "All VRFs\n" | |
718e3744 | 5758 | "Neighbor list\n" |
7c8ff89e | 5759 | "detail of all neighbors\n" |
3ac237f8 | 5760 | "include down status neighbor\n" |
9973d184 | 5761 | JSON_STR) |
718e3744 | 5762 | { |
d62a17ae | 5763 | struct ospf *ospf; |
9f049418 | 5764 | bool uj = use_json(argc, argv); |
b5a8894d CS |
5765 | struct listnode *node = NULL; |
5766 | char *vrf_name = NULL; | |
2951a7a4 | 5767 | bool all_vrf = false; |
b5a8894d CS |
5768 | int ret = CMD_SUCCESS; |
5769 | int inst = 0; | |
5770 | int idx_vrf = 0; | |
d7c0a89a | 5771 | uint8_t use_vrf = 0; |
b1c3ae8c | 5772 | json_object *json = NULL; |
7c8ff89e | 5773 | |
43b8d1d8 | 5774 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
7c8ff89e | 5775 | |
b1c3ae8c CS |
5776 | if (uj) |
5777 | json = json_object_new_object(); | |
5778 | ||
b5a8894d CS |
5779 | /* vrf input is provided could be all or specific vrf*/ |
5780 | if (vrf_name) { | |
b1c3ae8c | 5781 | use_vrf = 1; |
b5a8894d CS |
5782 | if (all_vrf) { |
5783 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
5784 | if (!ospf->oi_running) | |
5785 | continue; | |
996c9314 LB |
5786 | ret = show_ip_ospf_neighbor_detail_all_common( |
5787 | vty, ospf, json, uj, use_vrf); | |
b5a8894d | 5788 | } |
b1c3ae8c CS |
5789 | |
5790 | if (uj) { | |
5791 | vty_out(vty, "%s\n", | |
996c9314 LB |
5792 | json_object_to_json_string_ext( |
5793 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c CS |
5794 | json_object_free(json); |
5795 | } | |
5796 | ||
b5a8894d CS |
5797 | return ret; |
5798 | } | |
5799 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
b1c3ae8c CS |
5800 | if (ospf == NULL || !ospf->oi_running) { |
5801 | if (uj) | |
5802 | json_object_free(json); | |
b5a8894d | 5803 | return CMD_SUCCESS; |
b1c3ae8c | 5804 | } |
b5a8894d CS |
5805 | } else { |
5806 | /* Display default ospf (instance 0) info */ | |
5807 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
b1c3ae8c CS |
5808 | if (ospf == NULL || !ospf->oi_running) { |
5809 | if (uj) | |
5810 | json_object_free(json); | |
b5a8894d | 5811 | return CMD_SUCCESS; |
b1c3ae8c | 5812 | } |
b5a8894d CS |
5813 | } |
5814 | ||
b1c3ae8c CS |
5815 | if (ospf) { |
5816 | ret = show_ip_ospf_neighbor_detail_all_common(vty, ospf, json, | |
5817 | uj, use_vrf); | |
5818 | if (uj) { | |
5819 | vty_out(vty, "%s\n", | |
996c9314 LB |
5820 | json_object_to_json_string_ext( |
5821 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c CS |
5822 | } |
5823 | } | |
5824 | ||
5825 | if (uj) | |
5826 | json_object_free(json); | |
b5a8894d CS |
5827 | |
5828 | return ret; | |
7c8ff89e DS |
5829 | } |
5830 | ||
5831 | DEFUN (show_ip_ospf_instance_neighbor_detail_all, | |
5832 | show_ip_ospf_instance_neighbor_detail_all_cmd, | |
6147e2c6 | 5833 | "show ip ospf (1-65535) neighbor detail all [json]", |
7c8ff89e DS |
5834 | SHOW_STR |
5835 | IP_STR | |
5836 | "OSPF information\n" | |
5837 | "Instance ID\n" | |
5838 | "Neighbor list\n" | |
5839 | "detail of all neighbors\n" | |
3ac237f8 | 5840 | "include down status neighbor\n" |
9973d184 | 5841 | JSON_STR) |
7c8ff89e | 5842 | { |
d62a17ae | 5843 | int idx_number = 3; |
5844 | struct ospf *ospf; | |
d7c0a89a | 5845 | unsigned short instance = 0; |
9f049418 | 5846 | bool uj = use_json(argc, argv); |
b1c3ae8c CS |
5847 | json_object *json = NULL; |
5848 | int ret = CMD_SUCCESS; | |
7c8ff89e | 5849 | |
d62a17ae | 5850 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
409f98ab | 5851 | if (instance != ospf_instance) |
ac28e4ec CS |
5852 | return CMD_NOT_MY_INSTANCE; |
5853 | ||
409f98ab IR |
5854 | ospf = ospf_lookup_instance(instance); |
5855 | if (!ospf || !ospf->oi_running) | |
d62a17ae | 5856 | return CMD_SUCCESS; |
7c8ff89e | 5857 | |
b1c3ae8c CS |
5858 | if (uj) |
5859 | json = json_object_new_object(); | |
5860 | ||
5861 | ret = show_ip_ospf_neighbor_detail_all_common(vty, ospf, json, uj, 0); | |
5862 | ||
5863 | if (uj) { | |
996c9314 LB |
5864 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
5865 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c CS |
5866 | json_object_free(json); |
5867 | } | |
5868 | ||
5869 | return ret; | |
7c8ff89e DS |
5870 | } |
5871 | ||
d62a17ae | 5872 | static int show_ip_ospf_neighbor_int_detail_common(struct vty *vty, |
5873 | struct ospf *ospf, | |
5874 | int arg_base, | |
5875 | struct cmd_token **argv, | |
9f049418 | 5876 | bool use_json) |
d62a17ae | 5877 | { |
5878 | struct ospf_interface *oi; | |
5879 | struct interface *ifp; | |
5880 | struct route_node *rn, *nrn; | |
5881 | struct ospf_neighbor *nbr; | |
5882 | json_object *json = NULL; | |
718e3744 | 5883 | |
d62a17ae | 5884 | if (use_json) |
5885 | json = json_object_new_object(); | |
5886 | ||
5887 | if (ospf->instance) { | |
5888 | if (use_json) | |
5889 | json_object_int_add(json, "ospfInstance", | |
5890 | ospf->instance); | |
5891 | else | |
5892 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
5893 | } | |
5894 | ||
a36898e7 | 5895 | ifp = if_lookup_by_name(argv[arg_base]->arg, ospf->vrf_id); |
d62a17ae | 5896 | if (!ifp) { |
5897 | if (!use_json) | |
5898 | vty_out(vty, "No such interface.\n"); | |
16307668 RW |
5899 | else { |
5900 | vty_out(vty, "{}\n"); | |
5901 | json_object_free(json); | |
5902 | } | |
d62a17ae | 5903 | return CMD_WARNING; |
5904 | } | |
5905 | ||
5906 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { | |
5907 | if ((oi = rn->info)) { | |
5908 | for (nrn = route_top(oi->nbrs); nrn; | |
5909 | nrn = route_next(nrn)) { | |
5910 | if ((nbr = nrn->info)) { | |
5911 | if (nbr != oi->nbr_self) { | |
5912 | if (nbr->state != NSM_Down) | |
5913 | show_ip_ospf_neighbor_detail_sub( | |
5914 | vty, oi, nbr, | |
cb0b2ac6 | 5915 | NULL, |
b1c3ae8c | 5916 | json, use_json); |
d62a17ae | 5917 | } |
5918 | } | |
5919 | } | |
5920 | } | |
5921 | } | |
5922 | ||
5923 | if (use_json) { | |
9d303b37 DL |
5924 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
5925 | json, JSON_C_TO_STRING_PRETTY)); | |
d62a17ae | 5926 | json_object_free(json); |
5927 | } else | |
5928 | vty_out(vty, "\n"); | |
5929 | ||
5930 | return CMD_SUCCESS; | |
718e3744 | 5931 | } |
5932 | ||
7c8ff89e DS |
5933 | DEFUN (show_ip_ospf_neighbor_int_detail, |
5934 | show_ip_ospf_neighbor_int_detail_cmd, | |
b162fa78 | 5935 | "show ip ospf neighbor IFNAME detail [json]", |
7c8ff89e DS |
5936 | SHOW_STR |
5937 | IP_STR | |
5938 | "OSPF information\n" | |
5939 | "Neighbor list\n" | |
5940 | "Interface name\n" | |
3ac237f8 | 5941 | "detail of all neighbors\n" |
9973d184 | 5942 | JSON_STR) |
7c8ff89e | 5943 | { |
d62a17ae | 5944 | struct ospf *ospf; |
9f049418 | 5945 | bool uj = use_json(argc, argv); |
b5a8894d CS |
5946 | struct listnode *node = NULL; |
5947 | int ret = CMD_SUCCESS; | |
2951a7a4 | 5948 | bool ospf_output = false; |
7c8ff89e | 5949 | |
b5a8894d CS |
5950 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { |
5951 | if (!ospf->oi_running) | |
5952 | continue; | |
2951a7a4 | 5953 | ospf_output = true; |
cb0b2ac6 | 5954 | ret = show_ip_ospf_neighbor_int_detail_common(vty, ospf, 4, |
b5a8894d CS |
5955 | argv, uj); |
5956 | } | |
7c8ff89e | 5957 | |
9f049418 DS |
5958 | if (!ospf_output) |
5959 | vty_out(vty, "%% OSPF instance not found\n"); | |
5960 | ||
b5a8894d | 5961 | return ret; |
7c8ff89e DS |
5962 | } |
5963 | ||
5964 | DEFUN (show_ip_ospf_instance_neighbor_int_detail, | |
5965 | show_ip_ospf_instance_neighbor_int_detail_cmd, | |
6147e2c6 | 5966 | "show ip ospf (1-65535) neighbor IFNAME detail [json]", |
7c8ff89e DS |
5967 | SHOW_STR |
5968 | IP_STR | |
5969 | "OSPF information\n" | |
5970 | "Instance ID\n" | |
5971 | "Neighbor list\n" | |
5972 | "Interface name\n" | |
3ac237f8 | 5973 | "detail of all neighbors\n" |
9973d184 | 5974 | JSON_STR) |
7c8ff89e | 5975 | { |
d62a17ae | 5976 | int idx_number = 3; |
b4e84315 | 5977 | int idx_ifname = 5; |
d62a17ae | 5978 | struct ospf *ospf; |
d7c0a89a | 5979 | unsigned short instance = 0; |
9f049418 | 5980 | bool uj = use_json(argc, argv); |
7c8ff89e | 5981 | |
d62a17ae | 5982 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
409f98ab | 5983 | if (instance != ospf_instance) |
ac28e4ec CS |
5984 | return CMD_NOT_MY_INSTANCE; |
5985 | ||
409f98ab IR |
5986 | ospf = ospf_lookup_instance(instance); |
5987 | if (!ospf || !ospf->oi_running) | |
d62a17ae | 5988 | return CMD_SUCCESS; |
7c8ff89e | 5989 | |
996c9314 LB |
5990 | return show_ip_ospf_neighbor_int_detail_common(vty, ospf, idx_ifname, |
5991 | argv, uj); | |
7c8ff89e | 5992 | } |
6b0655a2 | 5993 | |
718e3744 | 5994 | /* Show functions */ |
f328dc60 | 5995 | static int show_lsa_summary(struct vty *vty, struct ospf_lsa *lsa, int self, |
5996 | json_object *json_lsa) | |
d62a17ae | 5997 | { |
5998 | struct router_lsa *rl; | |
5999 | struct summary_lsa *sl; | |
6000 | struct as_external_lsa *asel; | |
6001 | struct prefix_ipv4 p; | |
f328dc60 | 6002 | char buf[PREFIX2STR_BUFFER]; |
d62a17ae | 6003 | |
6004 | if (lsa != NULL) | |
6005 | /* If self option is set, check LSA self flag. */ | |
6006 | if (self == 0 || IS_LSA_SELF(lsa)) { | |
f328dc60 | 6007 | |
6008 | if (!json_lsa) { | |
6009 | /* LSA common part show. */ | |
6010 | vty_out(vty, "%-15pI4", | |
6011 | &lsa->data->id); | |
ce513ac6 MS |
6012 | vty_out(vty, "%-15pI4 %4d 0x%08lx 0x%04x", |
6013 | &lsa->data->adv_router, LS_AGE(lsa), | |
f328dc60 | 6014 | (unsigned long)ntohl( |
6015 | lsa->data->ls_seqnum), | |
6016 | ntohs(lsa->data->checksum)); | |
6017 | } else { | |
6018 | char seqnum[10]; | |
6019 | char checksum[10]; | |
6020 | ||
6021 | snprintf(seqnum, sizeof(seqnum), "%x", | |
6022 | ntohl(lsa->data->ls_seqnum)); | |
6023 | snprintf(checksum, sizeof(checksum), "%x", | |
6024 | ntohs(lsa->data->checksum)); | |
6025 | json_object_string_add( | |
6026 | json_lsa, "lsId", | |
ce513ac6 MS |
6027 | inet_ntop(AF_INET, &lsa->data->id, |
6028 | buf, sizeof(buf))); | |
f328dc60 | 6029 | json_object_string_add( |
6030 | json_lsa, "advertisedRouter", | |
ce513ac6 MS |
6031 | inet_ntop(AF_INET, |
6032 | &lsa->data->adv_router, | |
6033 | buf, sizeof(buf))); | |
f328dc60 | 6034 | json_object_int_add(json_lsa, "lsaAge", |
6035 | LS_AGE(lsa)); | |
6036 | json_object_string_add( | |
6037 | json_lsa, "sequenceNumber", seqnum); | |
6038 | json_object_string_add(json_lsa, "checksum", | |
6039 | checksum); | |
6040 | } | |
6041 | ||
d62a17ae | 6042 | /* LSA specific part show. */ |
6043 | switch (lsa->data->type) { | |
6044 | case OSPF_ROUTER_LSA: | |
6045 | rl = (struct router_lsa *)lsa->data; | |
f328dc60 | 6046 | |
6047 | if (!json_lsa) | |
6048 | vty_out(vty, " %-d", ntohs(rl->links)); | |
6049 | else | |
6050 | json_object_int_add(json_lsa, | |
6051 | "numOfRouterLinks", | |
6052 | ntohs(rl->links)); | |
d62a17ae | 6053 | break; |
6054 | case OSPF_SUMMARY_LSA: | |
6055 | sl = (struct summary_lsa *)lsa->data; | |
6056 | ||
6057 | p.family = AF_INET; | |
6058 | p.prefix = sl->header.id; | |
6059 | p.prefixlen = ip_masklen(sl->mask); | |
6060 | apply_mask_ipv4(&p); | |
6061 | ||
f328dc60 | 6062 | if (!json_lsa) |
6063 | vty_out(vty, " %pFX", &p); | |
6064 | else { | |
6065 | prefix2str(&p, buf, sizeof(buf)); | |
6066 | json_object_string_add(json_lsa, | |
6067 | "summaryAddress", | |
6068 | buf); | |
6069 | } | |
d62a17ae | 6070 | break; |
6071 | case OSPF_AS_EXTERNAL_LSA: | |
6072 | case OSPF_AS_NSSA_LSA: | |
6073 | asel = (struct as_external_lsa *)lsa->data; | |
6074 | ||
6075 | p.family = AF_INET; | |
6076 | p.prefix = asel->header.id; | |
6077 | p.prefixlen = ip_masklen(asel->mask); | |
6078 | apply_mask_ipv4(&p); | |
6079 | ||
f328dc60 | 6080 | if (!json_lsa) |
6081 | vty_out(vty, " %s %pFX [0x%lx]", | |
6082 | IS_EXTERNAL_METRIC( | |
6083 | asel->e[0].tos) | |
6084 | ? "E2" | |
6085 | : "E1", | |
6086 | &p, | |
6087 | (unsigned long)ntohl( | |
6088 | asel->e[0].route_tag)); | |
6089 | else { | |
6090 | prefix2str(&p, buf, sizeof(buf)); | |
6091 | json_object_string_add( | |
6092 | json_lsa, "metricType", | |
6093 | IS_EXTERNAL_METRIC( | |
6094 | asel->e[0].tos) | |
6095 | ? "E2" | |
6096 | : "E1"); | |
6097 | json_object_string_add(json_lsa, | |
6098 | "route", buf); | |
6099 | json_object_int_add( | |
6100 | json_lsa, "tag", | |
6101 | (unsigned long)ntohl( | |
6102 | asel->e[0].route_tag)); | |
6103 | } | |
d62a17ae | 6104 | break; |
6105 | case OSPF_NETWORK_LSA: | |
6106 | case OSPF_ASBR_SUMMARY_LSA: | |
6107 | case OSPF_OPAQUE_LINK_LSA: | |
6108 | case OSPF_OPAQUE_AREA_LSA: | |
6109 | case OSPF_OPAQUE_AS_LSA: | |
6110 | default: | |
6111 | break; | |
6112 | } | |
f328dc60 | 6113 | |
6114 | if (!json_lsa) | |
6115 | vty_out(vty, "\n"); | |
d62a17ae | 6116 | } |
718e3744 | 6117 | |
d62a17ae | 6118 | return 0; |
6119 | } | |
6120 | ||
2b64873d | 6121 | static const char *const show_database_desc[] = { |
d62a17ae | 6122 | "unknown", |
6123 | "Router Link States", | |
6124 | "Net Link States", | |
6125 | "Summary Link States", | |
6126 | "ASBR-Summary Link States", | |
6127 | "AS External Link States", | |
6128 | "Group Membership LSA", | |
6129 | "NSSA-external Link States", | |
6130 | "Type-8 LSA", | |
6131 | "Link-Local Opaque-LSA", | |
6132 | "Area-Local Opaque-LSA", | |
6133 | "AS-external Opaque-LSA", | |
718e3744 | 6134 | }; |
6135 | ||
f328dc60 | 6136 | static const char * const show_database_desc_json[] = { |
6137 | "unknown", | |
6138 | "routerLinkStates", | |
6139 | "networkLinkStates", | |
6140 | "summaryLinkStates", | |
6141 | "asbrSummaryLinkStates", | |
6142 | "asExternalLinkStates", | |
6143 | "groupMembershipLsa", | |
6144 | "nssaExternalLinkStates", | |
6145 | "type8Lsa", | |
6146 | "linkLocalOpaqueLsa", | |
6147 | "areaLocalOpaqueLsa", | |
6148 | "asExternalOpaqueLsa", | |
6149 | }; | |
6150 | ||
2b64873d | 6151 | static const char *const show_database_header[] = { |
d62a17ae | 6152 | "", |
6153 | "Link ID ADV Router Age Seq# CkSum Link count", | |
6154 | "Link ID ADV Router Age Seq# CkSum", | |
6155 | "Link ID ADV Router Age Seq# CkSum Route", | |
6156 | "Link ID ADV Router Age Seq# CkSum", | |
6157 | "Link ID ADV Router Age Seq# CkSum Route", | |
6158 | " --- header for Group Member ----", | |
6159 | "Link ID ADV Router Age Seq# CkSum Route", | |
6160 | " --- type-8 ---", | |
6161 | "Opaque-Type/Id ADV Router Age Seq# CkSum", | |
6162 | "Opaque-Type/Id ADV Router Age Seq# CkSum", | |
6163 | "Opaque-Type/Id ADV Router Age Seq# CkSum", | |
718e3744 | 6164 | }; |
6165 | ||
f328dc60 | 6166 | static void show_ip_ospf_database_header(struct vty *vty, struct ospf_lsa *lsa, |
6167 | json_object *json) | |
d62a17ae | 6168 | { |
ce513ac6 | 6169 | char buf[PREFIX_STRLEN]; |
d62a17ae | 6170 | struct router_lsa *rlsa = (struct router_lsa *)lsa->data; |
6171 | ||
f328dc60 | 6172 | if (!json) { |
6173 | vty_out(vty, " LS age: %d\n", LS_AGE(lsa)); | |
6174 | vty_out(vty, " Options: 0x%-2x : %s\n", lsa->data->options, | |
6175 | ospf_options_dump(lsa->data->options)); | |
6176 | vty_out(vty, " LS Flags: 0x%-2x %s\n", lsa->flags, | |
6177 | ((lsa->flags & OSPF_LSA_LOCAL_XLT) | |
6178 | ? "(Translated from Type-7)" | |
6179 | : "")); | |
6180 | ||
6181 | if (lsa->data->type == OSPF_ROUTER_LSA) { | |
6182 | vty_out(vty, " Flags: 0x%x", rlsa->flags); | |
6183 | ||
6184 | if (rlsa->flags) | |
6185 | vty_out(vty, " :%s%s%s%s", | |
6186 | IS_ROUTER_LSA_BORDER(rlsa) ? " ABR" | |
6187 | : "", | |
6188 | IS_ROUTER_LSA_EXTERNAL(rlsa) ? " ASBR" | |
6189 | : "", | |
6190 | IS_ROUTER_LSA_VIRTUAL(rlsa) | |
6191 | ? " VL-endpoint" | |
6192 | : "", | |
6193 | IS_ROUTER_LSA_SHORTCUT(rlsa) | |
6194 | ? " Shortcut" | |
6195 | : ""); | |
d62a17ae | 6196 | |
f328dc60 | 6197 | vty_out(vty, "\n"); |
6198 | } | |
6199 | vty_out(vty, " LS Type: %s\n", | |
6200 | lookup_msg(ospf_lsa_type_msg, lsa->data->type, NULL)); | |
6201 | vty_out(vty, " Link State ID: %pI4 %s\n", | |
6202 | &lsa->data->id, | |
6203 | lookup_msg(ospf_link_state_id_type_msg, lsa->data->type, | |
6204 | NULL)); | |
6205 | vty_out(vty, " Advertising Router: %pI4\n", | |
6206 | &lsa->data->adv_router); | |
6207 | vty_out(vty, " LS Seq Number: %08lx\n", | |
6208 | (unsigned long)ntohl(lsa->data->ls_seqnum)); | |
6209 | vty_out(vty, " Checksum: 0x%04x\n", | |
6210 | ntohs(lsa->data->checksum)); | |
6211 | vty_out(vty, " Length: %d\n\n", ntohs(lsa->data->length)); | |
6212 | } else { | |
6213 | char seqnum[10]; | |
6214 | char checksum[10]; | |
6215 | ||
6216 | snprintf(seqnum, 10, "%x", ntohl(lsa->data->ls_seqnum)); | |
6217 | snprintf(checksum, 10, "%x", ntohs(lsa->data->checksum)); | |
6218 | ||
6219 | json_object_int_add(json, "lsaAge", LS_AGE(lsa)); | |
6220 | json_object_string_add(json, "options", | |
6221 | ospf_options_dump(lsa->data->options)); | |
6222 | json_object_int_add(json, "lsaFlags", lsa->flags); | |
6223 | ||
6224 | if (lsa->flags & OSPF_LSA_LOCAL_XLT) | |
6225 | json_object_boolean_true_add(json, | |
6226 | "translatedFromType7"); | |
6227 | ||
6228 | if (lsa->data->type == OSPF_ROUTER_LSA) { | |
6229 | json_object_int_add(json, "flags", rlsa->flags); | |
6230 | ||
6231 | if (rlsa->flags) { | |
6232 | if (IS_ROUTER_LSA_BORDER(rlsa)) | |
6233 | json_object_boolean_true_add(json, | |
6234 | "abr"); | |
6235 | if (IS_ROUTER_LSA_EXTERNAL(rlsa)) | |
6236 | json_object_boolean_true_add(json, | |
6237 | "asbr"); | |
6238 | if (IS_ROUTER_LSA_VIRTUAL(rlsa)) | |
6239 | json_object_boolean_true_add( | |
6240 | json, "vlEndpoint"); | |
6241 | if (IS_ROUTER_LSA_SHORTCUT(rlsa)) | |
6242 | json_object_boolean_true_add( | |
6243 | json, "shortcut"); | |
6244 | } | |
6245 | } | |
6246 | ||
6247 | json_object_string_add( | |
6248 | json, "lsaType", | |
6249 | lookup_msg(ospf_lsa_type_msg, lsa->data->type, NULL)); | |
6250 | json_object_string_add(json, "linkStateId", | |
ce513ac6 MS |
6251 | inet_ntop(AF_INET, &lsa->data->id, |
6252 | buf, sizeof(buf))); | |
f328dc60 | 6253 | json_object_string_add(json, "advertisingRouter", |
ce513ac6 MS |
6254 | inet_ntop(AF_INET, |
6255 | &lsa->data->adv_router, | |
6256 | buf, sizeof(buf))); | |
f328dc60 | 6257 | json_object_string_add(json, "lsaSeqNumber", seqnum); |
6258 | json_object_string_add(json, "checksum", checksum); | |
6259 | json_object_int_add(json, "length", ntohs(lsa->data->length)); | |
d62a17ae | 6260 | } |
d62a17ae | 6261 | } |
6262 | ||
2b64873d | 6263 | static const char *const link_type_desc[] = { |
d62a17ae | 6264 | "(null)", |
6265 | "another Router (point-to-point)", | |
6266 | "a Transit Network", | |
6267 | "Stub Network", | |
6268 | "a Virtual Link", | |
718e3744 | 6269 | }; |
6270 | ||
2b64873d | 6271 | static const char *const link_id_desc[] = { |
d62a17ae | 6272 | "(null)", "Neighboring Router ID", "Designated Router address", |
6273 | "Net", "Neighboring Router ID", | |
718e3744 | 6274 | }; |
6275 | ||
2b64873d | 6276 | static const char *const link_data_desc[] = { |
d62a17ae | 6277 | "(null)", "Router Interface address", "Router Interface address", |
6278 | "Network Mask", "Router Interface address", | |
718e3744 | 6279 | }; |
6280 | ||
f328dc60 | 6281 | static const char *const link_id_desc_json[] = { |
6282 | "null", "neighborRouterId", "designatedRouterAddress", | |
6283 | "networkAddress", "neighborRouterId", | |
6284 | }; | |
6285 | ||
6286 | static const char *const link_data_desc_json[] = { | |
6287 | "null", "routerInterfaceAddress", "routerInterfaceAddress", | |
6288 | "networkMask", "routerInterfaceAddress", | |
6289 | }; | |
6290 | ||
718e3744 | 6291 | /* Show router-LSA each Link information. */ |
d62a17ae | 6292 | static void show_ip_ospf_database_router_links(struct vty *vty, |
f328dc60 | 6293 | struct router_lsa *rl, |
6294 | json_object *json) | |
d62a17ae | 6295 | { |
6296 | int len, type; | |
f328dc60 | 6297 | unsigned short i; |
6298 | json_object *json_links = NULL; | |
6299 | json_object *json_link = NULL; | |
6300 | int metric = 0; | |
ce513ac6 | 6301 | char buf[PREFIX_STRLEN]; |
f328dc60 | 6302 | |
6303 | if (json) | |
6304 | json_links = json_object_new_object(); | |
d62a17ae | 6305 | |
6306 | len = ntohs(rl->header.length) - 4; | |
6307 | for (i = 0; i < ntohs(rl->links) && len > 0; len -= 12, i++) { | |
6308 | type = rl->link[i].type; | |
6309 | ||
f328dc60 | 6310 | if (json) { |
6311 | char link[16]; | |
6312 | ||
6313 | snprintf(link, sizeof(link), "link%u", i); | |
6314 | json_link = json_object_new_object(); | |
6315 | json_object_string_add(json_link, "linkType", | |
6316 | link_type_desc[type]); | |
6317 | json_object_string_add(json_link, | |
6318 | link_id_desc_json[type], | |
ce513ac6 MS |
6319 | inet_ntop(AF_INET, |
6320 | &rl->link[i].link_id, | |
6321 | buf, sizeof(buf))); | |
f328dc60 | 6322 | json_object_string_add( |
6323 | json_link, link_data_desc_json[type], | |
ce513ac6 MS |
6324 | inet_ntop(AF_INET, &rl->link[i].link_data, |
6325 | buf, sizeof(buf))); | |
f328dc60 | 6326 | json_object_int_add(json_link, "numOfTosMetrics", |
6327 | metric); | |
6328 | json_object_int_add(json_link, "tos0Metric", | |
6329 | ntohs(rl->link[i].metric)); | |
6330 | json_object_object_add(json_links, link, json_link); | |
6331 | } else { | |
6332 | vty_out(vty, " Link connected to: %s\n", | |
6333 | link_type_desc[type]); | |
6334 | vty_out(vty, " (Link ID) %s: %pI4\n", | |
6335 | link_id_desc[type], | |
6336 | &rl->link[i].link_id); | |
6337 | vty_out(vty, " (Link Data) %s: %pI4\n", | |
6338 | link_data_desc[type], | |
6339 | &rl->link[i].link_data); | |
6340 | vty_out(vty, " Number of TOS metrics: 0\n"); | |
6341 | vty_out(vty, " TOS 0 Metric: %d\n", | |
6342 | ntohs(rl->link[i].metric)); | |
6343 | vty_out(vty, "\n"); | |
6344 | } | |
d62a17ae | 6345 | } |
f328dc60 | 6346 | if (json) |
6347 | json_object_object_add(json, "routerLinks", json_links); | |
718e3744 | 6348 | } |
6349 | ||
6350 | /* Show router-LSA detail information. */ | |
f328dc60 | 6351 | static int show_router_lsa_detail(struct vty *vty, struct ospf_lsa *lsa, |
6352 | json_object *json) | |
718e3744 | 6353 | { |
d62a17ae | 6354 | if (lsa != NULL) { |
6355 | struct router_lsa *rl = (struct router_lsa *)lsa->data; | |
718e3744 | 6356 | |
f328dc60 | 6357 | show_ip_ospf_database_header(vty, lsa, json); |
718e3744 | 6358 | |
f328dc60 | 6359 | if (!json) |
6360 | vty_out(vty, " Number of Links: %d\n\n", | |
6361 | ntohs(rl->links)); | |
6362 | else | |
6363 | json_object_int_add(json, "numOfLinks", | |
6364 | ntohs(rl->links)); | |
718e3744 | 6365 | |
f328dc60 | 6366 | show_ip_ospf_database_router_links(vty, rl, json); |
6367 | ||
6368 | if (!json) | |
6369 | vty_out(vty, "\n"); | |
d62a17ae | 6370 | } |
6371 | ||
6372 | return 0; | |
718e3744 | 6373 | } |
6374 | ||
6375 | /* Show network-LSA detail information. */ | |
f328dc60 | 6376 | static int show_network_lsa_detail(struct vty *vty, struct ospf_lsa *lsa, |
6377 | json_object *json) | |
718e3744 | 6378 | { |
d62a17ae | 6379 | int length, i; |
ce513ac6 | 6380 | char buf[PREFIX_STRLEN]; |
f328dc60 | 6381 | json_object *json_attached_rt = NULL; |
6382 | json_object *json_router = NULL; | |
6383 | ||
6384 | if (json) | |
6385 | json_attached_rt = json_object_new_object(); | |
718e3744 | 6386 | |
d62a17ae | 6387 | if (lsa != NULL) { |
6388 | struct network_lsa *nl = (struct network_lsa *)lsa->data; | |
8db278b5 | 6389 | struct in_addr *addr; |
718e3744 | 6390 | |
f328dc60 | 6391 | show_ip_ospf_database_header(vty, lsa, json); |
718e3744 | 6392 | |
f328dc60 | 6393 | if (!json) |
6394 | vty_out(vty, " Network Mask: /%d\n", | |
6395 | ip_masklen(nl->mask)); | |
6396 | else | |
6397 | json_object_int_add(json, "networkMask", | |
6398 | ip_masklen(nl->mask)); | |
718e3744 | 6399 | |
8db278b5 OD |
6400 | length = lsa->size - OSPF_LSA_HEADER_SIZE - 4; |
6401 | addr = &nl->routers[0]; | |
6402 | for (i = 0; length > 0 && addr; | |
6403 | length -= 4, addr = &nl->routers[++i]) | |
f328dc60 | 6404 | if (!json) { |
6405 | vty_out(vty, " Attached Router: %pI4\n", | |
8db278b5 | 6406 | addr); |
f328dc60 | 6407 | vty_out(vty, "\n"); |
6408 | } else { | |
6409 | json_router = json_object_new_object(); | |
6410 | json_object_string_add( | |
6411 | json_router, "attachedRouterId", | |
8db278b5 OD |
6412 | inet_ntop(AF_INET, addr, buf, |
6413 | sizeof(buf))); | |
6414 | json_object_object_add(json_attached_rt, | |
6415 | inet_ntop(AF_INET, addr, | |
6416 | buf, | |
6417 | sizeof(buf)), | |
6418 | json_router); | |
f328dc60 | 6419 | } |
d62a17ae | 6420 | } |
718e3744 | 6421 | |
f328dc60 | 6422 | if (json) |
6423 | json_object_object_add(json, "attchedRouters", | |
6424 | json_attached_rt); | |
6425 | ||
d62a17ae | 6426 | return 0; |
718e3744 | 6427 | } |
6428 | ||
6429 | /* Show summary-LSA detail information. */ | |
f328dc60 | 6430 | static int show_summary_lsa_detail(struct vty *vty, struct ospf_lsa *lsa, |
6431 | json_object *json) | |
718e3744 | 6432 | { |
d62a17ae | 6433 | if (lsa != NULL) { |
6434 | struct summary_lsa *sl = (struct summary_lsa *)lsa->data; | |
718e3744 | 6435 | |
f328dc60 | 6436 | show_ip_ospf_database_header(vty, lsa, json); |
718e3744 | 6437 | |
f328dc60 | 6438 | if (!json) { |
6439 | vty_out(vty, " Network Mask: /%d\n", | |
6440 | ip_masklen(sl->mask)); | |
6441 | vty_out(vty, " TOS: 0 Metric: %d\n", | |
6442 | GET_METRIC(sl->metric)); | |
6443 | vty_out(vty, "\n"); | |
6444 | } else { | |
6445 | json_object_int_add(json, "networkMask", | |
6446 | ip_masklen(sl->mask)); | |
6447 | json_object_int_add(json, "tos0Metric", | |
6448 | GET_METRIC(sl->metric)); | |
6449 | } | |
d62a17ae | 6450 | } |
718e3744 | 6451 | |
d62a17ae | 6452 | return 0; |
718e3744 | 6453 | } |
6454 | ||
6455 | /* Show summary-ASBR-LSA detail information. */ | |
f328dc60 | 6456 | static int show_summary_asbr_lsa_detail(struct vty *vty, struct ospf_lsa *lsa, |
6457 | json_object *json) | |
718e3744 | 6458 | { |
d62a17ae | 6459 | if (lsa != NULL) { |
6460 | struct summary_lsa *sl = (struct summary_lsa *)lsa->data; | |
718e3744 | 6461 | |
f328dc60 | 6462 | show_ip_ospf_database_header(vty, lsa, json); |
718e3744 | 6463 | |
f328dc60 | 6464 | if (!json) { |
6465 | vty_out(vty, " Network Mask: /%d\n", | |
6466 | ip_masklen(sl->mask)); | |
6467 | vty_out(vty, " TOS: 0 Metric: %d\n", | |
6468 | GET_METRIC(sl->metric)); | |
6469 | vty_out(vty, "\n"); | |
6470 | } else { | |
6471 | json_object_int_add(json, "networkMask", | |
6472 | ip_masklen(sl->mask)); | |
6473 | json_object_int_add(json, "tos0Metric", | |
6474 | GET_METRIC(sl->metric)); | |
6475 | } | |
d62a17ae | 6476 | } |
718e3744 | 6477 | |
d62a17ae | 6478 | return 0; |
718e3744 | 6479 | } |
6480 | ||
6481 | /* Show AS-external-LSA detail information. */ | |
f328dc60 | 6482 | static int show_as_external_lsa_detail(struct vty *vty, struct ospf_lsa *lsa, |
6483 | json_object *json) | |
d62a17ae | 6484 | { |
ce513ac6 | 6485 | char buf[PREFIX_STRLEN]; |
f328dc60 | 6486 | int tos = 0; |
6487 | ||
d62a17ae | 6488 | if (lsa != NULL) { |
6489 | struct as_external_lsa *al = | |
6490 | (struct as_external_lsa *)lsa->data; | |
6491 | ||
f328dc60 | 6492 | show_ip_ospf_database_header(vty, lsa, json); |
6493 | ||
6494 | if (!json) { | |
6495 | vty_out(vty, " Network Mask: /%d\n", | |
6496 | ip_masklen(al->mask)); | |
6497 | vty_out(vty, " Metric Type: %s\n", | |
6498 | IS_EXTERNAL_METRIC(al->e[0].tos) | |
6499 | ? "2 (Larger than any link state path)" | |
6500 | : "1"); | |
6501 | vty_out(vty, " TOS: 0\n"); | |
6502 | vty_out(vty, " Metric: %d\n", | |
6503 | GET_METRIC(al->e[0].metric)); | |
6504 | vty_out(vty, " Forward Address: %pI4\n", | |
6505 | &al->e[0].fwd_addr); | |
6506 | vty_out(vty, | |
6507 | " External Route Tag: %" ROUTE_TAG_PRI "\n\n", | |
6508 | (route_tag_t)ntohl(al->e[0].route_tag)); | |
6509 | } else { | |
6510 | json_object_int_add(json, "networkMask", | |
6511 | ip_masklen(al->mask)); | |
6512 | json_object_string_add( | |
6513 | json, "metricType", | |
6514 | IS_EXTERNAL_METRIC(al->e[0].tos) | |
6515 | ? "E2 (Larger than any link state path)" | |
6516 | : "E1"); | |
6517 | json_object_int_add(json, "tos", tos); | |
6518 | json_object_int_add(json, "metric", | |
6519 | GET_METRIC(al->e[0].metric)); | |
6520 | json_object_string_add(json, "forwardAddress", | |
ce513ac6 MS |
6521 | inet_ntop(AF_INET, |
6522 | &(al->e[0].fwd_addr), | |
6523 | buf, sizeof(buf))); | |
f328dc60 | 6524 | json_object_int_add( |
6525 | json, "externalRouteTag", | |
6526 | (route_tag_t)ntohl(al->e[0].route_tag)); | |
6527 | } | |
d62a17ae | 6528 | } |
718e3744 | 6529 | |
d62a17ae | 6530 | return 0; |
718e3744 | 6531 | } |
718e3744 | 6532 | |
718e3744 | 6533 | /* Show AS-NSSA-LSA detail information. */ |
f328dc60 | 6534 | static int show_as_nssa_lsa_detail(struct vty *vty, struct ospf_lsa *lsa, |
6535 | json_object *json) | |
d62a17ae | 6536 | { |
ce513ac6 | 6537 | char buf[PREFIX_STRLEN]; |
f328dc60 | 6538 | int tos = 0; |
6539 | ||
d62a17ae | 6540 | if (lsa != NULL) { |
6541 | struct as_external_lsa *al = | |
6542 | (struct as_external_lsa *)lsa->data; | |
6543 | ||
f328dc60 | 6544 | show_ip_ospf_database_header(vty, lsa, json); |
6545 | ||
6546 | if (!json) { | |
6547 | vty_out(vty, " Network Mask: /%d\n", | |
6548 | ip_masklen(al->mask)); | |
6549 | vty_out(vty, " Metric Type: %s\n", | |
6550 | IS_EXTERNAL_METRIC(al->e[0].tos) | |
6551 | ? "2 (Larger than any link state path)" | |
6552 | : "1"); | |
6553 | vty_out(vty, " TOS: 0\n"); | |
6554 | vty_out(vty, " Metric: %d\n", | |
6555 | GET_METRIC(al->e[0].metric)); | |
6556 | vty_out(vty, " NSSA: Forward Address: %pI4\n", | |
6557 | &al->e[0].fwd_addr); | |
6558 | vty_out(vty, | |
6559 | " External Route Tag: %" ROUTE_TAG_PRI | |
6560 | "\n\n", | |
6561 | (route_tag_t)ntohl(al->e[0].route_tag)); | |
6562 | } else { | |
6563 | json_object_int_add(json, "networkMask", | |
6564 | ip_masklen(al->mask)); | |
6565 | json_object_string_add( | |
6566 | json, "metricType", | |
6567 | IS_EXTERNAL_METRIC(al->e[0].tos) | |
6568 | ? "E2 (Larger than any link state path)" | |
6569 | : "E1"); | |
6570 | json_object_int_add(json, "tos", tos); | |
6571 | json_object_int_add(json, "metric", | |
6572 | GET_METRIC(al->e[0].metric)); | |
6573 | json_object_string_add(json, "nssaForwardAddress", | |
ce513ac6 MS |
6574 | inet_ntop(AF_INET, |
6575 | &al->e[0].fwd_addr, | |
6576 | buf, sizeof(buf))); | |
f328dc60 | 6577 | json_object_int_add( |
6578 | json, "externalRouteTag", | |
6579 | (route_tag_t)ntohl(al->e[0].route_tag)); | |
6580 | } | |
d62a17ae | 6581 | } |
718e3744 | 6582 | |
d62a17ae | 6583 | return 0; |
718e3744 | 6584 | } |
6585 | ||
f328dc60 | 6586 | static int show_func_dummy(struct vty *vty, struct ospf_lsa *lsa, |
6587 | json_object *json) | |
718e3744 | 6588 | { |
d62a17ae | 6589 | return 0; |
718e3744 | 6590 | } |
6591 | ||
f328dc60 | 6592 | static int show_opaque_lsa_detail(struct vty *vty, struct ospf_lsa *lsa, |
6593 | json_object *json) | |
718e3744 | 6594 | { |
d62a17ae | 6595 | if (lsa != NULL) { |
f328dc60 | 6596 | show_ip_ospf_database_header(vty, lsa, json); |
6597 | show_opaque_info_detail(vty, lsa, json); | |
6598 | if (!json) | |
6599 | vty_out(vty, "\n"); | |
d62a17ae | 6600 | } |
6601 | return 0; | |
6602 | } | |
6603 | ||
f328dc60 | 6604 | int (*show_function[])(struct vty *, struct ospf_lsa *, json_object *) = { |
d62a17ae | 6605 | NULL, |
6606 | show_router_lsa_detail, | |
6607 | show_network_lsa_detail, | |
6608 | show_summary_lsa_detail, | |
6609 | show_summary_asbr_lsa_detail, | |
6610 | show_as_external_lsa_detail, | |
6611 | show_func_dummy, | |
6612 | show_as_nssa_lsa_detail, /* almost same as external */ | |
6613 | NULL, /* type-8 */ | |
6614 | show_opaque_lsa_detail, | |
6615 | show_opaque_lsa_detail, | |
6616 | show_opaque_lsa_detail, | |
6617 | }; | |
6618 | ||
6619 | static void show_lsa_prefix_set(struct vty *vty, struct prefix_ls *lp, | |
6620 | struct in_addr *id, struct in_addr *adv_router) | |
6621 | { | |
6622 | memset(lp, 0, sizeof(struct prefix_ls)); | |
6623 | lp->family = 0; | |
6624 | if (id == NULL) | |
6625 | lp->prefixlen = 0; | |
6626 | else if (adv_router == NULL) { | |
12256b84 | 6627 | lp->prefixlen = IPV4_MAX_BITLEN; |
d62a17ae | 6628 | lp->id = *id; |
6629 | } else { | |
6630 | lp->prefixlen = 64; | |
6631 | lp->id = *id; | |
6632 | lp->adv_router = *adv_router; | |
6633 | } | |
718e3744 | 6634 | } |
718e3744 | 6635 | |
d62a17ae | 6636 | static void show_lsa_detail_proc(struct vty *vty, struct route_table *rt, |
f328dc60 | 6637 | struct in_addr *id, struct in_addr *adv_router, |
6638 | json_object *json) | |
d62a17ae | 6639 | { |
6640 | struct prefix_ls lp; | |
6641 | struct route_node *rn, *start; | |
6642 | struct ospf_lsa *lsa; | |
f328dc60 | 6643 | json_object *json_lsa = NULL; |
718e3744 | 6644 | |
d62a17ae | 6645 | show_lsa_prefix_set(vty, &lp, id, adv_router); |
6646 | start = route_node_get(rt, (struct prefix *)&lp); | |
6647 | if (start) { | |
6648 | route_lock_node(start); | |
6649 | for (rn = start; rn; rn = route_next_until(rn, start)) | |
6650 | if ((lsa = rn->info)) { | |
f328dc60 | 6651 | if (json) { |
6652 | json_lsa = json_object_new_object(); | |
6653 | json_object_array_add(json, json_lsa); | |
6654 | } | |
6655 | ||
d62a17ae | 6656 | if (show_function[lsa->data->type] != NULL) |
f328dc60 | 6657 | show_function[lsa->data->type]( |
6658 | vty, lsa, json_lsa); | |
d62a17ae | 6659 | } |
6660 | route_unlock_node(start); | |
6661 | } | |
718e3744 | 6662 | } |
6663 | ||
6664 | /* Show detail LSA information | |
6665 | -- if id is NULL then show all LSAs. */ | |
d62a17ae | 6666 | static void show_lsa_detail(struct vty *vty, struct ospf *ospf, int type, |
f328dc60 | 6667 | struct in_addr *id, struct in_addr *adv_router, |
6668 | json_object *json) | |
d62a17ae | 6669 | { |
6670 | struct listnode *node; | |
6671 | struct ospf_area *area; | |
ce513ac6 | 6672 | char buf[PREFIX_STRLEN]; |
f328dc60 | 6673 | json_object *json_lsa_type = NULL; |
6674 | json_object *json_areas = NULL; | |
6675 | json_object *json_lsa_array = NULL; | |
6676 | ||
6677 | if (json) | |
6678 | json_lsa_type = json_object_new_object(); | |
d62a17ae | 6679 | |
6680 | switch (type) { | |
6681 | case OSPF_AS_EXTERNAL_LSA: | |
6682 | case OSPF_OPAQUE_AS_LSA: | |
f328dc60 | 6683 | if (!json) |
6684 | vty_out(vty, " %s \n\n", | |
6685 | show_database_desc[type]); | |
6686 | else | |
6687 | json_lsa_array = json_object_new_array(); | |
6688 | ||
6689 | show_lsa_detail_proc(vty, AS_LSDB(ospf, type), id, adv_router, | |
6690 | json_lsa_array); | |
6691 | if (json) | |
6692 | json_object_object_add(json, | |
6693 | show_database_desc_json[type], | |
6694 | json_lsa_array); | |
6695 | ||
d62a17ae | 6696 | break; |
6697 | default: | |
f328dc60 | 6698 | if (json) |
6699 | json_areas = json_object_new_object(); | |
6700 | ||
d62a17ae | 6701 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) { |
f328dc60 | 6702 | if (!json) { |
6703 | vty_out(vty, | |
6704 | "\n %s (Area %s)\n\n", | |
6705 | show_database_desc[type], | |
6706 | ospf_area_desc_string(area)); | |
6707 | } else { | |
6708 | json_lsa_array = json_object_new_array(); | |
6709 | json_object_object_add(json_areas, | |
ce513ac6 MS |
6710 | inet_ntop(AF_INET, |
6711 | &area->area_id, | |
6712 | buf, | |
6713 | sizeof(buf)), | |
f328dc60 | 6714 | json_lsa_array); |
6715 | } | |
6716 | ||
d62a17ae | 6717 | show_lsa_detail_proc(vty, AREA_LSDB(area, type), id, |
f328dc60 | 6718 | adv_router, json_lsa_array); |
6719 | } | |
6720 | ||
6721 | if (json) { | |
6722 | json_object_object_add(json_lsa_type, "areas", | |
6723 | json_areas); | |
6724 | json_object_object_add(json, | |
6725 | show_database_desc_json[type], | |
6726 | json_lsa_type); | |
d62a17ae | 6727 | } |
6728 | break; | |
718e3744 | 6729 | } |
6730 | } | |
6731 | ||
d62a17ae | 6732 | static void show_lsa_detail_adv_router_proc(struct vty *vty, |
6733 | struct route_table *rt, | |
f328dc60 | 6734 | struct in_addr *adv_router, |
6735 | json_object *json) | |
d62a17ae | 6736 | { |
ce513ac6 | 6737 | char buf[PREFIX_STRLEN]; |
d62a17ae | 6738 | struct route_node *rn; |
6739 | struct ospf_lsa *lsa; | |
6740 | ||
6741 | for (rn = route_top(rt); rn; rn = route_next(rn)) | |
f328dc60 | 6742 | if ((lsa = rn->info)) { |
6743 | json_object *json_lsa = NULL; | |
6744 | ||
d62a17ae | 6745 | if (IPV4_ADDR_SAME(adv_router, |
6746 | &lsa->data->adv_router)) { | |
6747 | if (CHECK_FLAG(lsa->flags, OSPF_LSA_LOCAL_XLT)) | |
6748 | continue; | |
f328dc60 | 6749 | if (json) |
6750 | json_lsa = json_object_new_object(); | |
6751 | ||
d62a17ae | 6752 | if (show_function[lsa->data->type] != NULL) |
f328dc60 | 6753 | show_function[lsa->data->type]( |
6754 | vty, lsa, json_lsa); | |
6755 | if (json) | |
6756 | json_object_object_add( | |
ce513ac6 MS |
6757 | json, |
6758 | inet_ntop(AF_INET, | |
6759 | &lsa->data->id, | |
6760 | buf, sizeof(buf)), | |
f328dc60 | 6761 | json_lsa); |
d62a17ae | 6762 | } |
f328dc60 | 6763 | } |
d62a17ae | 6764 | } |
6765 | ||
718e3744 | 6766 | /* Show detail LSA information. */ |
d62a17ae | 6767 | static void show_lsa_detail_adv_router(struct vty *vty, struct ospf *ospf, |
f328dc60 | 6768 | int type, struct in_addr *adv_router, |
6769 | json_object *json) | |
d62a17ae | 6770 | { |
6771 | struct listnode *node; | |
6772 | struct ospf_area *area; | |
ce513ac6 | 6773 | char buf[PREFIX_STRLEN]; |
f328dc60 | 6774 | json_object *json_lstype = NULL; |
6775 | json_object *json_area = NULL; | |
6776 | ||
6777 | if (json) | |
6778 | json_lstype = json_object_new_object(); | |
d62a17ae | 6779 | |
6780 | switch (type) { | |
6781 | case OSPF_AS_EXTERNAL_LSA: | |
6782 | case OSPF_OPAQUE_AS_LSA: | |
f328dc60 | 6783 | if (!json) |
6784 | vty_out(vty, " %s \n\n", | |
6785 | show_database_desc[type]); | |
6786 | ||
d62a17ae | 6787 | show_lsa_detail_adv_router_proc(vty, AS_LSDB(ospf, type), |
f328dc60 | 6788 | adv_router, json_lstype); |
d62a17ae | 6789 | break; |
6790 | default: | |
f328dc60 | 6791 | |
d62a17ae | 6792 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) { |
f328dc60 | 6793 | if (json) |
6794 | json_area = json_object_new_object(); | |
6795 | else | |
6796 | vty_out(vty, | |
6797 | "\n %s (Area %s)\n\n", | |
6798 | show_database_desc[type], | |
6799 | ospf_area_desc_string(area)); | |
6800 | show_lsa_detail_adv_router_proc(vty, | |
6801 | AREA_LSDB(area, type), | |
6802 | adv_router, json_area); | |
6803 | ||
6804 | if (json) | |
6805 | json_object_object_add(json_lstype, | |
ce513ac6 MS |
6806 | inet_ntop(AF_INET, |
6807 | &area->area_id, | |
6808 | buf, | |
6809 | sizeof(buf)), | |
f328dc60 | 6810 | json_area); |
d62a17ae | 6811 | } |
6812 | break; | |
6813 | } | |
f328dc60 | 6814 | |
6815 | if (json) | |
6816 | json_object_object_add(json, show_database_desc[type], | |
6817 | json_lstype); | |
d62a17ae | 6818 | } |
6819 | ||
7fd0729f G |
6820 | void show_ip_ospf_database_summary(struct vty *vty, struct ospf *ospf, int self, |
6821 | json_object *json) | |
d62a17ae | 6822 | { |
6823 | struct ospf_lsa *lsa; | |
6824 | struct route_node *rn; | |
6825 | struct ospf_area *area; | |
6826 | struct listnode *node; | |
ce513ac6 | 6827 | char buf[PREFIX_STRLEN]; |
f328dc60 | 6828 | json_object *json_areas = NULL; |
6829 | json_object *json_area = NULL; | |
6830 | json_object *json_lsa = NULL; | |
d62a17ae | 6831 | int type; |
f328dc60 | 6832 | json_object *json_lsa_array = NULL; |
6833 | ||
6834 | if (json) | |
6835 | json_areas = json_object_new_object(); | |
d62a17ae | 6836 | |
6837 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) { | |
f328dc60 | 6838 | if (json) |
6839 | json_area = json_object_new_object(); | |
6840 | ||
d62a17ae | 6841 | for (type = OSPF_MIN_LSA; type < OSPF_MAX_LSA; type++) { |
6842 | switch (type) { | |
6843 | case OSPF_AS_EXTERNAL_LSA: | |
6844 | case OSPF_OPAQUE_AS_LSA: | |
6845 | continue; | |
6846 | default: | |
6847 | break; | |
6848 | } | |
6849 | if (ospf_lsdb_count_self(area->lsdb, type) > 0 | |
6850 | || (!self | |
6851 | && ospf_lsdb_count(area->lsdb, type) > 0)) { | |
d62a17ae | 6852 | |
f328dc60 | 6853 | if (!json) { |
6854 | vty_out(vty, | |
6855 | " %s (Area %s)\n\n", | |
6856 | show_database_desc[type], | |
6857 | ospf_area_desc_string(area)); | |
6858 | vty_out(vty, "%s\n", | |
6859 | show_database_header[type]); | |
6860 | } else { | |
6861 | json_lsa_array = | |
6862 | json_object_new_array(); | |
6863 | json_object_object_add( | |
6864 | json_area, | |
6865 | show_database_desc_json[type], | |
6866 | json_lsa_array); | |
6867 | } | |
6868 | ||
6869 | LSDB_LOOP (AREA_LSDB(area, type), rn, lsa) { | |
6870 | if (json) { | |
6871 | json_lsa = | |
6872 | json_object_new_object(); | |
6873 | json_object_array_add( | |
6874 | json_lsa_array, | |
6875 | json_lsa); | |
6876 | } | |
d62a17ae | 6877 | |
f328dc60 | 6878 | show_lsa_summary(vty, lsa, self, |
6879 | json_lsa); | |
6880 | } | |
6881 | ||
6882 | if (!json) | |
6883 | vty_out(vty, "\n"); | |
d62a17ae | 6884 | } |
6885 | } | |
f328dc60 | 6886 | if (json) |
6887 | json_object_object_add(json_areas, | |
ce513ac6 MS |
6888 | inet_ntop(AF_INET, |
6889 | &area->area_id, | |
6890 | buf, sizeof(buf)), | |
f328dc60 | 6891 | json_area); |
d62a17ae | 6892 | } |
6893 | ||
f328dc60 | 6894 | if (json) |
6895 | json_object_object_add(json, "areas", json_areas); | |
6896 | ||
d62a17ae | 6897 | for (type = OSPF_MIN_LSA; type < OSPF_MAX_LSA; type++) { |
6898 | switch (type) { | |
6899 | case OSPF_AS_EXTERNAL_LSA: | |
6900 | case OSPF_OPAQUE_AS_LSA: | |
6901 | break; | |
6902 | default: | |
6903 | continue; | |
6904 | } | |
6905 | if (ospf_lsdb_count_self(ospf->lsdb, type) | |
6906 | || (!self && ospf_lsdb_count(ospf->lsdb, type))) { | |
f328dc60 | 6907 | if (!json) { |
6908 | vty_out(vty, " %s\n\n", | |
6909 | show_database_desc[type]); | |
6910 | vty_out(vty, "%s\n", | |
6911 | show_database_header[type]); | |
6912 | } else { | |
6913 | json_lsa_array = json_object_new_array(); | |
6914 | json_object_object_add( | |
6915 | json, show_database_desc_json[type], | |
6916 | json_lsa_array); | |
6917 | } | |
d62a17ae | 6918 | |
f328dc60 | 6919 | LSDB_LOOP (AS_LSDB(ospf, type), rn, lsa) { |
6920 | if (json) { | |
6921 | json_lsa = json_object_new_object(); | |
6922 | json_object_array_add(json_lsa_array, | |
6923 | json_lsa); | |
6924 | } | |
d62a17ae | 6925 | |
f328dc60 | 6926 | show_lsa_summary(vty, lsa, self, json_lsa); |
6927 | } | |
6928 | ||
6929 | if (!json) | |
6930 | vty_out(vty, "\n"); | |
d62a17ae | 6931 | } |
6932 | } | |
6933 | ||
f328dc60 | 6934 | if (!json) |
6935 | vty_out(vty, "\n"); | |
d62a17ae | 6936 | } |
6937 | ||
f328dc60 | 6938 | static void show_ip_ospf_database_maxage(struct vty *vty, struct ospf *ospf, |
6939 | json_object *json) | |
d62a17ae | 6940 | { |
6941 | struct route_node *rn; | |
ce513ac6 | 6942 | char buf[PREFIX_STRLEN]; |
f328dc60 | 6943 | json_object *json_maxage = NULL; |
d62a17ae | 6944 | |
f328dc60 | 6945 | if (!json) |
6946 | vty_out(vty, "\n MaxAge Link States:\n\n"); | |
6947 | else | |
6948 | json_maxage = json_object_new_object(); | |
d62a17ae | 6949 | |
6950 | for (rn = route_top(ospf->maxage_lsa); rn; rn = route_next(rn)) { | |
6951 | struct ospf_lsa *lsa; | |
f328dc60 | 6952 | json_object *json_lsa = NULL; |
d62a17ae | 6953 | |
6954 | if ((lsa = rn->info) != NULL) { | |
f328dc60 | 6955 | if (!json) { |
6956 | vty_out(vty, "Link type: %d\n", | |
6957 | lsa->data->type); | |
ce513ac6 MS |
6958 | vty_out(vty, "Link State ID: %pI4\n", |
6959 | &lsa->data->id); | |
f328dc60 | 6960 | vty_out(vty, "Advertising Router: %pI4\n", |
6961 | &lsa->data->adv_router); | |
6962 | vty_out(vty, "LSA lock count: %d\n", lsa->lock); | |
6963 | vty_out(vty, "\n"); | |
6964 | } else { | |
6965 | json_lsa = json_object_new_object(); | |
6966 | json_object_int_add(json_lsa, "linkType", | |
6967 | lsa->data->type); | |
6968 | json_object_string_add( | |
6969 | json_lsa, "linkStateId", | |
ce513ac6 MS |
6970 | inet_ntop(AF_INET, &lsa->data->id, |
6971 | buf, sizeof(buf))); | |
f328dc60 | 6972 | json_object_string_add( |
6973 | json_lsa, "advertisingRouter", | |
ce513ac6 MS |
6974 | inet_ntop(AF_INET, |
6975 | &lsa->data->adv_router, | |
6976 | buf, sizeof(buf))); | |
f328dc60 | 6977 | json_object_int_add(json_lsa, "lsaLockCount", |
6978 | lsa->lock); | |
ce513ac6 MS |
6979 | json_object_object_add( |
6980 | json_maxage, | |
6981 | inet_ntop(AF_INET, | |
6982 | &lsa->data->id, | |
6983 | buf, sizeof(buf)), | |
6984 | json_lsa); | |
f328dc60 | 6985 | } |
d62a17ae | 6986 | } |
91e6a0e5 | 6987 | } |
f328dc60 | 6988 | if (json) |
6989 | json_object_object_add(json, "maxAgeLinkStates", json_maxage); | |
718e3744 | 6990 | } |
6991 | ||
718e3744 | 6992 | #define OSPF_LSA_TYPE_NSSA_DESC "NSSA external link state\n" |
6993 | #define OSPF_LSA_TYPE_NSSA_CMD_STR "|nssa-external" | |
718e3744 | 6994 | |
718e3744 | 6995 | #define OSPF_LSA_TYPE_OPAQUE_LINK_DESC "Link local Opaque-LSA\n" |
6996 | #define OSPF_LSA_TYPE_OPAQUE_AREA_DESC "Link area Opaque-LSA\n" | |
6997 | #define OSPF_LSA_TYPE_OPAQUE_AS_DESC "Link AS Opaque-LSA\n" | |
6998 | #define OSPF_LSA_TYPE_OPAQUE_CMD_STR "|opaque-link|opaque-area|opaque-as" | |
718e3744 | 6999 | |
d62a17ae | 7000 | #define OSPF_LSA_TYPES_DESC \ |
7001 | "ASBR summary link states\n" \ | |
7002 | "External link states\n" \ | |
7003 | "Network link states\n" \ | |
7004 | "Router link states\n" \ | |
7005 | "Network summary link states\n" OSPF_LSA_TYPE_NSSA_DESC \ | |
7006 | OSPF_LSA_TYPE_OPAQUE_LINK_DESC OSPF_LSA_TYPE_OPAQUE_AREA_DESC \ | |
7007 | OSPF_LSA_TYPE_OPAQUE_AS_DESC | |
7008 | ||
7009 | static int show_ip_ospf_database_common(struct vty *vty, struct ospf *ospf, | |
7010 | int arg_base, int argc, | |
d7c0a89a | 7011 | struct cmd_token **argv, |
f328dc60 | 7012 | uint8_t use_vrf, json_object *json, |
7013 | bool uj) | |
d62a17ae | 7014 | { |
7015 | int idx_type = 4; | |
7016 | int type, ret; | |
7017 | struct in_addr id, adv_router; | |
ce513ac6 | 7018 | char buf[PREFIX_STRLEN]; |
f328dc60 | 7019 | json_object *json_vrf = NULL; |
d62a17ae | 7020 | |
f328dc60 | 7021 | if (uj) { |
7022 | if (use_vrf) | |
7023 | json_vrf = json_object_new_object(); | |
7024 | else | |
7025 | json_vrf = json; | |
7026 | } | |
7027 | ||
7028 | if (ospf->instance) { | |
7029 | if (uj) | |
7030 | json_object_int_add(json_vrf, "ospfInstance", | |
7031 | ospf->instance); | |
7032 | else | |
7033 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
7034 | } | |
d62a17ae | 7035 | |
f328dc60 | 7036 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); |
87bd50e8 | 7037 | |
f328dc60 | 7038 | /* Show Router ID. */ |
7039 | if (uj) { | |
7040 | json_object_string_add(json_vrf, "routerId", | |
ce513ac6 MS |
7041 | inet_ntop(AF_INET, &ospf->router_id, |
7042 | buf, sizeof(buf))); | |
f328dc60 | 7043 | } else { |
7044 | vty_out(vty, "\n OSPF Router with ID (%pI4)\n\n", | |
7045 | &ospf->router_id); | |
7046 | } | |
d62a17ae | 7047 | |
7048 | /* Show all LSA. */ | |
f328dc60 | 7049 | if ((argc == arg_base + 4) || (uj && (argc == arg_base + 5))) { |
7050 | show_ip_ospf_database_summary(vty, ospf, 0, json_vrf); | |
7051 | if (json) { | |
7052 | if (use_vrf) { | |
7053 | if (ospf->vrf_id == VRF_DEFAULT) | |
7054 | json_object_object_add(json, "default", | |
7055 | json_vrf); | |
7056 | else | |
7057 | json_object_object_add(json, ospf->name, | |
7058 | json_vrf); | |
7059 | } | |
7060 | } | |
d62a17ae | 7061 | return CMD_SUCCESS; |
7062 | } | |
718e3744 | 7063 | |
d62a17ae | 7064 | /* Set database type to show. */ |
7065 | if (strncmp(argv[arg_base + idx_type]->text, "r", 1) == 0) | |
7066 | type = OSPF_ROUTER_LSA; | |
7067 | else if (strncmp(argv[arg_base + idx_type]->text, "ne", 2) == 0) | |
7068 | type = OSPF_NETWORK_LSA; | |
7069 | else if (strncmp(argv[arg_base + idx_type]->text, "ns", 2) == 0) | |
7070 | type = OSPF_AS_NSSA_LSA; | |
7071 | else if (strncmp(argv[arg_base + idx_type]->text, "su", 2) == 0) | |
7072 | type = OSPF_SUMMARY_LSA; | |
7073 | else if (strncmp(argv[arg_base + idx_type]->text, "a", 1) == 0) | |
7074 | type = OSPF_ASBR_SUMMARY_LSA; | |
7075 | else if (strncmp(argv[arg_base + idx_type]->text, "e", 1) == 0) | |
7076 | type = OSPF_AS_EXTERNAL_LSA; | |
7077 | else if (strncmp(argv[arg_base + idx_type]->text, "se", 2) == 0) { | |
f328dc60 | 7078 | show_ip_ospf_database_summary(vty, ospf, 1, json_vrf); |
7079 | if (json) { | |
7080 | if (use_vrf) { | |
7081 | if (ospf->vrf_id == VRF_DEFAULT) | |
7082 | json_object_object_add(json, "default", | |
7083 | json_vrf); | |
7084 | else | |
7085 | json_object_object_add(json, ospf->name, | |
7086 | json_vrf); | |
7087 | } | |
7088 | } | |
d62a17ae | 7089 | return CMD_SUCCESS; |
7090 | } else if (strncmp(argv[arg_base + idx_type]->text, "m", 1) == 0) { | |
f328dc60 | 7091 | show_ip_ospf_database_maxage(vty, ospf, json_vrf); |
7092 | if (json) { | |
7093 | if (use_vrf) { | |
7094 | if (ospf->vrf_id == VRF_DEFAULT) | |
7095 | json_object_object_add(json, "default", | |
7096 | json_vrf); | |
7097 | else | |
7098 | json_object_object_add(json, ospf->name, | |
7099 | json_vrf); | |
7100 | } | |
7101 | } | |
d62a17ae | 7102 | return CMD_SUCCESS; |
7103 | } else if (strncmp(argv[arg_base + idx_type]->text, "opaque-l", 8) == 0) | |
7104 | type = OSPF_OPAQUE_LINK_LSA; | |
7105 | else if (strncmp(argv[arg_base + idx_type]->text, "opaque-ar", 9) == 0) | |
7106 | type = OSPF_OPAQUE_AREA_LSA; | |
7107 | else if (strncmp(argv[arg_base + idx_type]->text, "opaque-as", 9) == 0) | |
7108 | type = OSPF_OPAQUE_AS_LSA; | |
7109 | else | |
718e3744 | 7110 | return CMD_WARNING; |
d62a17ae | 7111 | |
7112 | /* `show ip ospf database LSA'. */ | |
f328dc60 | 7113 | if ((argc == arg_base + 5) || (uj && (argc == arg_base + 6))) |
7114 | show_lsa_detail(vty, ospf, type, NULL, NULL, json_vrf); | |
d62a17ae | 7115 | else if (argc >= arg_base + 6) { |
7116 | ret = inet_aton(argv[arg_base + 5]->arg, &id); | |
7117 | if (!ret) | |
7118 | return CMD_WARNING; | |
7119 | ||
7120 | /* `show ip ospf database LSA ID'. */ | |
f328dc60 | 7121 | if ((argc == arg_base + 6) || (uj && (argc == arg_base + 7))) |
7122 | show_lsa_detail(vty, ospf, type, &id, NULL, json_vrf); | |
d62a17ae | 7123 | /* `show ip ospf database LSA ID adv-router ADV_ROUTER'. */ |
f328dc60 | 7124 | else if ((argc == arg_base + 7) |
7125 | || (uj && (argc == arg_base + 8))) { | |
d62a17ae | 7126 | if (strncmp(argv[arg_base + 6]->text, "s", 1) == 0) |
7127 | adv_router = ospf->router_id; | |
7128 | else { | |
7129 | ret = inet_aton(argv[arg_base + 7]->arg, | |
7130 | &adv_router); | |
7131 | if (!ret) | |
7132 | return CMD_WARNING; | |
7133 | } | |
f328dc60 | 7134 | show_lsa_detail(vty, ospf, type, &id, &adv_router, |
7135 | json_vrf); | |
7136 | } | |
7137 | } | |
7138 | ||
7139 | if (json) { | |
7140 | if (use_vrf) { | |
7141 | if (ospf->vrf_id == VRF_DEFAULT) | |
7142 | json_object_object_add(json, "default", | |
7143 | json_vrf); | |
7144 | else | |
7145 | json_object_object_add(json, ospf->name, | |
7146 | json_vrf); | |
d62a17ae | 7147 | } |
718e3744 | 7148 | } |
718e3744 | 7149 | |
d62a17ae | 7150 | return CMD_SUCCESS; |
718e3744 | 7151 | } |
7152 | ||
7a7be519 | 7153 | DEFUN (show_ip_ospf_database_max, |
7154 | show_ip_ospf_database_max_cmd, | |
f328dc60 | 7155 | "show ip ospf [vrf <NAME|all>] database <max-age|self-originate> [json]", |
7a7be519 | 7156 | SHOW_STR |
7157 | IP_STR | |
7158 | "OSPF information\n" | |
b5a8894d CS |
7159 | VRF_CMD_HELP_STR |
7160 | "All VRFs\n" | |
7a7be519 | 7161 | "Database summary\n" |
7162 | "LSAs in MaxAge list\n" | |
f328dc60 | 7163 | "Self-originated link states\n" |
7164 | JSON_STR) | |
7a7be519 | 7165 | { |
b5a8894d CS |
7166 | struct ospf *ospf = NULL; |
7167 | struct listnode *node = NULL; | |
7168 | char *vrf_name = NULL; | |
2951a7a4 | 7169 | bool all_vrf = false; |
b5a8894d CS |
7170 | int ret = CMD_SUCCESS; |
7171 | int inst = 0; | |
7172 | int idx_vrf = 0; | |
d7c0a89a | 7173 | uint8_t use_vrf = 0; |
f328dc60 | 7174 | bool uj = use_json(argc, argv); |
7175 | json_object *json = NULL; | |
7176 | ||
7177 | if (uj) | |
7178 | json = json_object_new_object(); | |
f412b39a | 7179 | |
43b8d1d8 | 7180 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
f412b39a | 7181 | |
b5a8894d | 7182 | if (vrf_name) { |
2951a7a4 | 7183 | bool ospf_output = false; |
874f58d8 | 7184 | |
b1c3ae8c | 7185 | use_vrf = 1; |
94d4c685 | 7186 | |
b5a8894d CS |
7187 | if (all_vrf) { |
7188 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
7189 | if (!ospf->oi_running) | |
7190 | continue; | |
2951a7a4 | 7191 | ospf_output = true; |
996c9314 LB |
7192 | ret = show_ip_ospf_database_common( |
7193 | vty, ospf, idx_vrf ? 2 : 0, argc, argv, | |
f328dc60 | 7194 | use_vrf, json, uj); |
b5a8894d | 7195 | } |
9f049418 DS |
7196 | |
7197 | if (!ospf_output) | |
7198 | vty_out(vty, "%% OSPF instance not found\n"); | |
b5a8894d CS |
7199 | } else { |
7200 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
9f049418 | 7201 | if (ospf == NULL || !ospf->oi_running) { |
94d4c685 | 7202 | vty_out(vty, "%% OSPF instance not found\n"); |
b5a8894d | 7203 | return CMD_SUCCESS; |
9f049418 | 7204 | } |
996c9314 | 7205 | ret = (show_ip_ospf_database_common( |
f328dc60 | 7206 | vty, ospf, idx_vrf ? 2 : 0, argc, argv, use_vrf, |
7207 | json, uj)); | |
b5a8894d CS |
7208 | } |
7209 | } else { | |
7210 | /* Display default ospf (instance 0) info */ | |
7211 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
9f049418 | 7212 | if (ospf == NULL || !ospf->oi_running) { |
94d4c685 | 7213 | vty_out(vty, "%% OSPF instance not found\n"); |
b5a8894d | 7214 | return CMD_SUCCESS; |
9f049418 DS |
7215 | } |
7216 | ||
b1c3ae8c | 7217 | ret = show_ip_ospf_database_common(vty, ospf, 0, argc, argv, |
f328dc60 | 7218 | use_vrf, json, uj); |
7219 | } | |
7220 | ||
7221 | if (uj) { | |
7222 | vty_out(vty, "%s\n", json_object_to_json_string(json)); | |
7223 | json_object_free(json); | |
b5a8894d CS |
7224 | } |
7225 | ||
7226 | return ret; | |
7a7be519 | 7227 | } |
f412b39a | 7228 | |
a11bce11 IR |
7229 | ALIAS (show_ip_ospf_database_max, |
7230 | show_ip_ospf_database_cmd, | |
7231 | "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]", | |
718e3744 | 7232 | SHOW_STR |
7233 | IP_STR | |
7234 | "OSPF information\n" | |
b5a8894d | 7235 | VRF_CMD_HELP_STR |
a11bce11 | 7236 | "All VRFs\n" |
7a7be519 | 7237 | "Database summary\n" |
7238 | OSPF_LSA_TYPES_DESC | |
7239 | "Link State ID (as an IP address)\n" | |
7240 | "Self-originated link states\n" | |
7241 | "Advertising Router link states\n" | |
f328dc60 | 7242 | "Advertising Router (as an IP address)\n" |
7243 | JSON_STR) | |
7c8ff89e | 7244 | |
7a7be519 | 7245 | DEFUN (show_ip_ospf_instance_database_max, |
7246 | show_ip_ospf_instance_database_max_cmd, | |
f328dc60 | 7247 | "show ip ospf (1-65535) database <max-age|self-originate> [json]", |
7a7be519 | 7248 | SHOW_STR |
7249 | IP_STR | |
7250 | "OSPF information\n" | |
7251 | "Instance ID\n" | |
7252 | "Database summary\n" | |
7253 | "LSAs in MaxAge list\n" | |
f328dc60 | 7254 | "Self-originated link states\n" |
7255 | JSON_STR) | |
7a7be519 | 7256 | { |
d62a17ae | 7257 | int idx_number = 3; |
7258 | struct ospf *ospf; | |
d7c0a89a | 7259 | unsigned short instance = 0; |
f328dc60 | 7260 | bool uj = use_json(argc, argv); |
7261 | json_object *json = NULL; | |
7262 | ||
7263 | if (uj) | |
7264 | json = json_object_new_object(); | |
d62a17ae | 7265 | |
7266 | instance = strtoul(argv[idx_number]->arg, NULL, 10); | |
409f98ab | 7267 | if (instance != ospf_instance) |
ac28e4ec CS |
7268 | return CMD_NOT_MY_INSTANCE; |
7269 | ||
409f98ab IR |
7270 | ospf = ospf_lookup_instance(instance); |
7271 | if (!ospf || !ospf->oi_running) | |
d62a17ae | 7272 | return CMD_SUCCESS; |
7273 | ||
f328dc60 | 7274 | show_ip_ospf_database_common(vty, ospf, 1, argc, argv, 0, json, uj); |
7275 | ||
7276 | if (uj) { | |
7277 | vty_out(vty, "%s\n", | |
7278 | json_object_to_json_string_ext( | |
7279 | json, JSON_C_TO_STRING_PRETTY)); | |
7280 | json_object_free(json); | |
7281 | } | |
7282 | ||
7283 | return CMD_SUCCESS; | |
d62a17ae | 7284 | } |
7285 | ||
a11bce11 IR |
7286 | ALIAS (show_ip_ospf_instance_database_max, |
7287 | show_ip_ospf_instance_database_cmd, | |
7288 | "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]", | |
7289 | SHOW_STR | |
7290 | IP_STR | |
7291 | "OSPF information\n" | |
7292 | "Instance ID\n" | |
7293 | "Database summary\n" | |
7294 | OSPF_LSA_TYPES_DESC | |
7295 | "Link State ID (as an IP address)\n" | |
7296 | "Self-originated link states\n" | |
7297 | "Advertising Router link states\n" | |
7298 | "Advertising Router (as an IP address)\n" | |
7299 | JSON_STR) | |
d62a17ae | 7300 | |
7301 | static int show_ip_ospf_database_type_adv_router_common(struct vty *vty, | |
7302 | struct ospf *ospf, | |
7303 | int arg_base, int argc, | |
b1c3ae8c | 7304 | struct cmd_token **argv, |
f328dc60 | 7305 | uint8_t use_vrf, |
7306 | json_object *json, | |
7307 | bool uj) | |
d62a17ae | 7308 | { |
7309 | int idx_type = 4; | |
7310 | int type, ret; | |
7311 | struct in_addr adv_router; | |
ce513ac6 | 7312 | char buf[PREFIX_STRLEN]; |
f328dc60 | 7313 | json_object *json_vrf = NULL; |
d62a17ae | 7314 | |
f328dc60 | 7315 | if (uj) { |
7316 | if (use_vrf) | |
7317 | json_vrf = json_object_new_object(); | |
7318 | else | |
7319 | json_vrf = json; | |
7320 | } | |
d62a17ae | 7321 | |
f328dc60 | 7322 | if (ospf->instance) { |
7323 | if (uj) | |
7324 | json_object_int_add(json, "ospfInstance", | |
7325 | ospf->instance); | |
7326 | else | |
7327 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
7328 | } | |
87bd50e8 | 7329 | |
f328dc60 | 7330 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); |
7331 | ||
7332 | /* Show Router ID. */ | |
7333 | if (uj) { | |
7334 | json_object_string_add(json_vrf, "routerId", | |
ce513ac6 MS |
7335 | inet_ntop(AF_INET, &ospf->router_id, |
7336 | buf, sizeof(buf))); | |
f328dc60 | 7337 | } else { |
7338 | vty_out(vty, "\n OSPF Router with ID (%pI4)\n\n", | |
7339 | &ospf->router_id); | |
7340 | } | |
d62a17ae | 7341 | |
7342 | /* Set database type to show. */ | |
7343 | if (strncmp(argv[arg_base + idx_type]->text, "r", 1) == 0) | |
7344 | type = OSPF_ROUTER_LSA; | |
7345 | else if (strncmp(argv[arg_base + idx_type]->text, "ne", 2) == 0) | |
7346 | type = OSPF_NETWORK_LSA; | |
7347 | else if (strncmp(argv[arg_base + idx_type]->text, "ns", 2) == 0) | |
7348 | type = OSPF_AS_NSSA_LSA; | |
7349 | else if (strncmp(argv[arg_base + idx_type]->text, "s", 1) == 0) | |
7350 | type = OSPF_SUMMARY_LSA; | |
7351 | else if (strncmp(argv[arg_base + idx_type]->text, "a", 1) == 0) | |
7352 | type = OSPF_ASBR_SUMMARY_LSA; | |
7353 | else if (strncmp(argv[arg_base + idx_type]->text, "e", 1) == 0) | |
7354 | type = OSPF_AS_EXTERNAL_LSA; | |
7355 | else if (strncmp(argv[arg_base + idx_type]->text, "opaque-l", 8) == 0) | |
7356 | type = OSPF_OPAQUE_LINK_LSA; | |
7357 | else if (strncmp(argv[arg_base + idx_type]->text, "opaque-ar", 9) == 0) | |
7358 | type = OSPF_OPAQUE_AREA_LSA; | |
7359 | else if (strncmp(argv[arg_base + idx_type]->text, "opaque-as", 9) == 0) | |
7360 | type = OSPF_OPAQUE_AS_LSA; | |
7361 | else | |
7362 | return CMD_WARNING; | |
7c8ff89e | 7363 | |
d62a17ae | 7364 | /* `show ip ospf database LSA adv-router ADV_ROUTER'. */ |
7365 | if (strncmp(argv[arg_base + 5]->text, "s", 1) == 0) | |
7366 | adv_router = ospf->router_id; | |
7367 | else { | |
7368 | ret = inet_aton(argv[arg_base + 6]->arg, &adv_router); | |
7369 | if (!ret) | |
7370 | return CMD_WARNING; | |
7371 | } | |
7c8ff89e | 7372 | |
f328dc60 | 7373 | show_lsa_detail_adv_router(vty, ospf, type, &adv_router, json_vrf); |
7374 | ||
7375 | if (json) { | |
7376 | if (use_vrf) { | |
7377 | if (ospf->vrf_id == VRF_DEFAULT) | |
7378 | json_object_object_add(json, "default", | |
7379 | json_vrf); | |
7380 | else | |
7381 | json_object_object_add(json, ospf->name, | |
7382 | json_vrf); | |
7383 | } | |
7384 | } | |
7c8ff89e | 7385 | |
d62a17ae | 7386 | return CMD_SUCCESS; |
7c8ff89e DS |
7387 | } |
7388 | ||
a11bce11 IR |
7389 | DEFUN (show_ip_ospf_database_type_adv_router, |
7390 | show_ip_ospf_database_type_adv_router_cmd, | |
7391 | "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]", | |
7c8ff89e DS |
7392 | SHOW_STR |
7393 | IP_STR | |
7394 | "OSPF information\n" | |
b5a8894d | 7395 | VRF_CMD_HELP_STR |
a11bce11 | 7396 | "All VRFs\n" |
7c8ff89e DS |
7397 | "Database summary\n" |
7398 | OSPF_LSA_TYPES_DESC | |
7399 | "Advertising Router link states\n" | |
3a2d747c | 7400 | "Advertising Router (as an IP address)\n" |
f328dc60 | 7401 | "Self-originated link states\n" |
7402 | JSON_STR) | |
7c8ff89e | 7403 | { |
b5a8894d | 7404 | struct ospf *ospf = NULL; |
b5a8894d CS |
7405 | struct listnode *node = NULL; |
7406 | char *vrf_name = NULL; | |
2951a7a4 | 7407 | bool all_vrf = false; |
b5a8894d CS |
7408 | int ret = CMD_SUCCESS; |
7409 | int inst = 0; | |
acaeb9fd | 7410 | int idx_vrf = 0; |
d7c0a89a | 7411 | uint8_t use_vrf = 0; |
f328dc60 | 7412 | bool uj = use_json(argc, argv); |
7413 | json_object *json = NULL; | |
7414 | ||
7415 | if (uj) | |
7416 | json = json_object_new_object(); | |
7c8ff89e | 7417 | |
43b8d1d8 CS |
7418 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
7419 | ||
b5a8894d | 7420 | if (vrf_name) { |
2951a7a4 | 7421 | bool ospf_output = false; |
874f58d8 | 7422 | |
b1c3ae8c | 7423 | use_vrf = 1; |
94d4c685 | 7424 | |
b5a8894d CS |
7425 | if (all_vrf) { |
7426 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
7427 | if (!ospf->oi_running) | |
7428 | continue; | |
2951a7a4 | 7429 | ospf_output = true; |
996c9314 | 7430 | ret = show_ip_ospf_database_type_adv_router_common( |
d68e47e1 LS |
7431 | vty, ospf, 2, argc, argv, use_vrf, json, |
7432 | uj); | |
b5a8894d | 7433 | } |
9f049418 DS |
7434 | if (!ospf_output) |
7435 | vty_out(vty, "%% OSPF instance not found\n"); | |
b5a8894d CS |
7436 | } else { |
7437 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
9f049418 | 7438 | if ((ospf == NULL) || !ospf->oi_running) { |
94d4c685 | 7439 | vty_out(vty, "%% OSPF instance not found\n"); |
b5a8894d | 7440 | return CMD_SUCCESS; |
9f049418 DS |
7441 | } |
7442 | ||
996c9314 | 7443 | ret = show_ip_ospf_database_type_adv_router_common( |
d68e47e1 | 7444 | vty, ospf, 2, argc, argv, use_vrf, json, uj); |
b5a8894d CS |
7445 | } |
7446 | } else { | |
7447 | /* Display default ospf (instance 0) info */ | |
7448 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
9f049418 | 7449 | if (ospf == NULL || !ospf->oi_running) { |
94d4c685 | 7450 | vty_out(vty, "%% OSPF instance not found\n"); |
b5a8894d | 7451 | return CMD_SUCCESS; |
9f049418 DS |
7452 | } |
7453 | ||
996c9314 | 7454 | ret = show_ip_ospf_database_type_adv_router_common( |
acaeb9fd | 7455 | vty, ospf, 0, argc, argv, use_vrf, json, uj); |
b5a8894d | 7456 | } |
f328dc60 | 7457 | |
7458 | if (uj) { | |
7459 | vty_out(vty, "%s\n", json_object_to_json_string(json)); | |
7460 | json_object_free(json); | |
7461 | } | |
7462 | ||
b5a8894d | 7463 | return ret; |
a11bce11 IR |
7464 | } |
7465 | ||
7466 | DEFUN (show_ip_ospf_instance_database_type_adv_router, | |
7467 | show_ip_ospf_instance_database_type_adv_router_cmd, | |
7468 | "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]", | |
7469 | SHOW_STR | |
7470 | IP_STR | |
7471 | "OSPF information\n" | |
7472 | "Instance ID\n" | |
7473 | "Database summary\n" | |
7474 | OSPF_LSA_TYPES_DESC | |
7475 | "Advertising Router link states\n" | |
7476 | "Advertising Router (as an IP address)\n" | |
7477 | "Self-originated link states\n" | |
7478 | JSON_STR) | |
7479 | { | |
7480 | int idx_number = 3; | |
7481 | struct ospf *ospf; | |
7482 | unsigned short instance = 0; | |
7483 | bool uj = use_json(argc, argv); | |
7484 | json_object *json = NULL; | |
7485 | ||
7486 | if (uj) | |
7487 | json = json_object_new_object(); | |
7488 | ||
7489 | instance = strtoul(argv[idx_number]->arg, NULL, 10); | |
7490 | if (instance != ospf_instance) | |
7491 | return CMD_NOT_MY_INSTANCE; | |
7492 | ||
7493 | ospf = ospf_lookup_instance(instance); | |
7494 | if (!ospf || !ospf->oi_running) | |
7495 | return CMD_SUCCESS; | |
7496 | ||
7497 | show_ip_ospf_database_type_adv_router_common(vty, ospf, 1, argc, argv, | |
7498 | 0, json, uj); | |
7499 | ||
7500 | if (uj) { | |
7501 | vty_out(vty, "%s\n", | |
7502 | json_object_to_json_string_ext( | |
7503 | json, JSON_C_TO_STRING_PRETTY)); | |
7504 | json_object_free(json); | |
7505 | } | |
7506 | ||
7507 | return CMD_SUCCESS; | |
718e3744 | 7508 | } |
7509 | ||
718e3744 | 7510 | DEFUN (ip_ospf_authentication_args, |
7511 | ip_ospf_authentication_args_addr_cmd, | |
7a7be519 | 7512 | "ip ospf authentication <null|message-digest> [A.B.C.D]", |
718e3744 | 7513 | "IP Information\n" |
7514 | "OSPF interface commands\n" | |
7515 | "Enable authentication on this interface\n" | |
7516 | "Use null authentication\n" | |
7517 | "Use message-digest authentication\n" | |
7a7be519 | 7518 | "Address of interface\n") |
718e3744 | 7519 | { |
d62a17ae | 7520 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7521 | int idx_encryption = 3; | |
7522 | int idx_ipv4 = 4; | |
7523 | struct in_addr addr; | |
7524 | int ret; | |
7525 | struct ospf_if_params *params; | |
7526 | ||
7527 | params = IF_DEF_PARAMS(ifp); | |
7528 | ||
7529 | if (argc == 5) { | |
7530 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
7531 | if (!ret) { | |
7532 | vty_out(vty, | |
7533 | "Please specify interface address by A.B.C.D\n"); | |
7534 | return CMD_WARNING_CONFIG_FAILED; | |
7535 | } | |
718e3744 | 7536 | |
d62a17ae | 7537 | params = ospf_get_if_params(ifp, addr); |
7538 | ospf_if_update_params(ifp, addr); | |
7539 | } | |
718e3744 | 7540 | |
d62a17ae | 7541 | /* Handle null authentication */ |
7542 | if (argv[idx_encryption]->arg[0] == 'n') { | |
7543 | SET_IF_PARAM(params, auth_type); | |
7544 | params->auth_type = OSPF_AUTH_NULL; | |
7545 | return CMD_SUCCESS; | |
7546 | } | |
718e3744 | 7547 | |
d62a17ae | 7548 | /* Handle message-digest authentication */ |
7549 | if (argv[idx_encryption]->arg[0] == 'm') { | |
7550 | SET_IF_PARAM(params, auth_type); | |
7551 | params->auth_type = OSPF_AUTH_CRYPTOGRAPHIC; | |
7552 | return CMD_SUCCESS; | |
7553 | } | |
718e3744 | 7554 | |
d62a17ae | 7555 | vty_out(vty, "You shouldn't get here!\n"); |
7556 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 7557 | } |
7558 | ||
718e3744 | 7559 | DEFUN (ip_ospf_authentication, |
7560 | ip_ospf_authentication_addr_cmd, | |
7a7be519 | 7561 | "ip ospf authentication [A.B.C.D]", |
718e3744 | 7562 | "IP Information\n" |
7563 | "OSPF interface commands\n" | |
7564 | "Enable authentication on this interface\n" | |
efd7904e | 7565 | "Address of interface\n") |
718e3744 | 7566 | { |
d62a17ae | 7567 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7568 | int idx_ipv4 = 3; | |
7569 | struct in_addr addr; | |
7570 | int ret; | |
7571 | struct ospf_if_params *params; | |
7572 | ||
7573 | params = IF_DEF_PARAMS(ifp); | |
7574 | ||
7575 | if (argc == 4) { | |
7576 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
7577 | if (!ret) { | |
7578 | vty_out(vty, | |
7579 | "Please specify interface address by A.B.C.D\n"); | |
7580 | return CMD_WARNING_CONFIG_FAILED; | |
7581 | } | |
7582 | ||
7583 | params = ospf_get_if_params(ifp, addr); | |
7584 | ospf_if_update_params(ifp, addr); | |
718e3744 | 7585 | } |
7586 | ||
d62a17ae | 7587 | SET_IF_PARAM(params, auth_type); |
7588 | params->auth_type = OSPF_AUTH_SIMPLE; | |
718e3744 | 7589 | |
d62a17ae | 7590 | return CMD_SUCCESS; |
718e3744 | 7591 | } |
7592 | ||
b4a039bf DS |
7593 | DEFUN (no_ip_ospf_authentication_args, |
7594 | no_ip_ospf_authentication_args_addr_cmd, | |
7a7be519 | 7595 | "no ip ospf authentication <null|message-digest> [A.B.C.D]", |
b4a039bf DS |
7596 | NO_STR |
7597 | "IP Information\n" | |
7598 | "OSPF interface commands\n" | |
7599 | "Enable authentication on this interface\n" | |
7600 | "Use null authentication\n" | |
7601 | "Use message-digest authentication\n" | |
efd7904e | 7602 | "Address of interface\n") |
b4a039bf | 7603 | { |
d62a17ae | 7604 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7605 | int idx_encryption = 4; | |
7606 | int idx_ipv4 = 5; | |
7607 | struct in_addr addr; | |
7608 | int ret; | |
7609 | struct ospf_if_params *params; | |
7610 | struct route_node *rn; | |
7611 | int auth_type; | |
7612 | ||
7613 | params = IF_DEF_PARAMS(ifp); | |
7614 | ||
7615 | if (argc == 6) { | |
7616 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
7617 | if (!ret) { | |
7618 | vty_out(vty, | |
7619 | "Please specify interface address by A.B.C.D\n"); | |
7620 | return CMD_WARNING_CONFIG_FAILED; | |
7621 | } | |
b4a039bf | 7622 | |
d62a17ae | 7623 | params = ospf_lookup_if_params(ifp, addr); |
7624 | if (params == NULL) { | |
7625 | vty_out(vty, "Ip Address specified is unknown\n"); | |
7626 | return CMD_WARNING_CONFIG_FAILED; | |
7627 | } | |
7628 | params->auth_type = OSPF_AUTH_NOTSET; | |
7629 | UNSET_IF_PARAM(params, auth_type); | |
7630 | if (params != IF_DEF_PARAMS(ifp)) { | |
7631 | ospf_free_if_params(ifp, addr); | |
7632 | ospf_if_update_params(ifp, addr); | |
7633 | } | |
7634 | } else { | |
7635 | if (argv[idx_encryption]->arg[0] == 'n') { | |
7636 | auth_type = OSPF_AUTH_NULL; | |
7637 | } else if (argv[idx_encryption]->arg[0] == 'm') { | |
7638 | auth_type = OSPF_AUTH_CRYPTOGRAPHIC; | |
7639 | } else { | |
7640 | vty_out(vty, "Unexpected input encountered\n"); | |
7641 | return CMD_WARNING_CONFIG_FAILED; | |
7642 | } | |
7643 | /* | |
7644 | * Here we have a case where the user has entered | |
7645 | * 'no ip ospf authentication (null | message_digest )' | |
7646 | * we need to find if we have any ip addresses underneath it | |
7647 | * that | |
7648 | * correspond to the associated type. | |
7649 | */ | |
7650 | if (params->auth_type == auth_type) { | |
7651 | params->auth_type = OSPF_AUTH_NOTSET; | |
7652 | UNSET_IF_PARAM(params, auth_type); | |
7653 | } | |
7654 | ||
7655 | for (rn = route_top(IF_OIFS_PARAMS(ifp)); rn; | |
7656 | rn = route_next(rn)) { | |
7657 | if ((params = rn->info)) { | |
7658 | if (params->auth_type == auth_type) { | |
7659 | params->auth_type = OSPF_AUTH_NOTSET; | |
7660 | UNSET_IF_PARAM(params, auth_type); | |
7661 | if (params != IF_DEF_PARAMS(ifp)) { | |
7662 | ospf_free_if_params( | |
7663 | ifp, rn->p.u.prefix4); | |
7664 | ospf_if_update_params( | |
7665 | ifp, rn->p.u.prefix4); | |
7666 | } | |
7667 | } | |
7668 | } | |
b4a039bf | 7669 | } |
b4a039bf | 7670 | } |
b4a039bf | 7671 | |
d62a17ae | 7672 | return CMD_SUCCESS; |
b4a039bf DS |
7673 | } |
7674 | ||
718e3744 | 7675 | DEFUN (no_ip_ospf_authentication, |
7676 | no_ip_ospf_authentication_addr_cmd, | |
7a7be519 | 7677 | "no ip ospf authentication [A.B.C.D]", |
718e3744 | 7678 | NO_STR |
7679 | "IP Information\n" | |
7680 | "OSPF interface commands\n" | |
7681 | "Enable authentication on this interface\n" | |
efd7904e | 7682 | "Address of interface\n") |
718e3744 | 7683 | { |
d62a17ae | 7684 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7685 | int idx_ipv4 = 4; | |
7686 | struct in_addr addr; | |
7687 | int ret; | |
7688 | struct ospf_if_params *params; | |
7689 | struct route_node *rn; | |
7690 | ||
7691 | params = IF_DEF_PARAMS(ifp); | |
7692 | ||
7693 | if (argc == 5) { | |
7694 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
7695 | if (!ret) { | |
7696 | vty_out(vty, | |
7697 | "Please specify interface address by A.B.C.D\n"); | |
7698 | return CMD_WARNING_CONFIG_FAILED; | |
7699 | } | |
718e3744 | 7700 | |
d62a17ae | 7701 | params = ospf_lookup_if_params(ifp, addr); |
7702 | if (params == NULL) { | |
7703 | vty_out(vty, "Ip Address specified is unknown\n"); | |
7704 | return CMD_WARNING_CONFIG_FAILED; | |
7705 | } | |
718e3744 | 7706 | |
d62a17ae | 7707 | params->auth_type = OSPF_AUTH_NOTSET; |
7708 | UNSET_IF_PARAM(params, auth_type); | |
7709 | if (params != IF_DEF_PARAMS(ifp)) { | |
7710 | ospf_free_if_params(ifp, addr); | |
7711 | ospf_if_update_params(ifp, addr); | |
7712 | } | |
7713 | } else { | |
7714 | /* | |
7715 | * When a user enters 'no ip ospf authentication' | |
7716 | * We should remove all authentication types from | |
7717 | * the interface. | |
7718 | */ | |
7719 | if ((params->auth_type == OSPF_AUTH_NULL) | |
7720 | || (params->auth_type == OSPF_AUTH_CRYPTOGRAPHIC) | |
7721 | || (params->auth_type == OSPF_AUTH_SIMPLE)) { | |
7722 | params->auth_type = OSPF_AUTH_NOTSET; | |
7723 | UNSET_IF_PARAM(params, auth_type); | |
7724 | } | |
813d4307 | 7725 | |
d62a17ae | 7726 | for (rn = route_top(IF_OIFS_PARAMS(ifp)); rn; |
7727 | rn = route_next(rn)) { | |
7728 | if ((params = rn->info)) { | |
7729 | ||
7730 | if ((params->auth_type == OSPF_AUTH_NULL) | |
7731 | || (params->auth_type | |
7732 | == OSPF_AUTH_CRYPTOGRAPHIC) | |
7733 | || (params->auth_type | |
7734 | == OSPF_AUTH_SIMPLE)) { | |
7735 | params->auth_type = OSPF_AUTH_NOTSET; | |
7736 | UNSET_IF_PARAM(params, auth_type); | |
7737 | if (params != IF_DEF_PARAMS(ifp)) { | |
7738 | ospf_free_if_params( | |
7739 | ifp, rn->p.u.prefix4); | |
7740 | ospf_if_update_params( | |
7741 | ifp, rn->p.u.prefix4); | |
7742 | } | |
7743 | } | |
7744 | } | |
b4a039bf | 7745 | } |
b4a039bf | 7746 | } |
d62a17ae | 7747 | |
7748 | return CMD_SUCCESS; | |
718e3744 | 7749 | } |
7750 | ||
0d829fa7 | 7751 | |
718e3744 | 7752 | DEFUN (ip_ospf_authentication_key, |
7753 | ip_ospf_authentication_key_addr_cmd, | |
7a7be519 | 7754 | "ip ospf authentication-key AUTH_KEY [A.B.C.D]", |
718e3744 | 7755 | "IP Information\n" |
7756 | "OSPF interface commands\n" | |
7757 | "Authentication password (key)\n" | |
7758 | "The OSPF password (key)\n" | |
efd7904e | 7759 | "Address of interface\n") |
718e3744 | 7760 | { |
d62a17ae | 7761 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7762 | int idx = 0; | |
7763 | struct in_addr addr; | |
7764 | struct ospf_if_params *params; | |
718e3744 | 7765 | |
d62a17ae | 7766 | params = IF_DEF_PARAMS(ifp); |
7767 | ||
7768 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
7769 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
7770 | vty_out(vty, | |
7771 | "Please specify interface address by A.B.C.D\n"); | |
7772 | return CMD_WARNING_CONFIG_FAILED; | |
7773 | } | |
718e3744 | 7774 | |
d62a17ae | 7775 | params = ospf_get_if_params(ifp, addr); |
7776 | ospf_if_update_params(ifp, addr); | |
7777 | } | |
718e3744 | 7778 | |
4d65d927 QY |
7779 | strlcpy((char *)params->auth_simple, argv[3]->arg, |
7780 | sizeof(params->auth_simple)); | |
d62a17ae | 7781 | SET_IF_PARAM(params, auth_simple); |
718e3744 | 7782 | |
d62a17ae | 7783 | return CMD_SUCCESS; |
718e3744 | 7784 | } |
7785 | ||
7a7be519 | 7786 | DEFUN_HIDDEN (ospf_authentication_key, |
747e489c | 7787 | ospf_authentication_key_cmd, |
0d829fa7 | 7788 | "ospf authentication-key AUTH_KEY [A.B.C.D]", |
747e489c | 7789 | "OSPF interface commands\n" |
baf9eaad | 7790 | VLINK_HELPSTR_AUTH_SIMPLE |
0d829fa7 | 7791 | "Address of interface\n") |
718e3744 | 7792 | { |
d62a17ae | 7793 | return ip_ospf_authentication_key(self, vty, argc, argv); |
718e3744 | 7794 | } |
7795 | ||
7a7be519 | 7796 | DEFUN (no_ip_ospf_authentication_key, |
7797 | no_ip_ospf_authentication_key_authkey_addr_cmd, | |
7798 | "no ip ospf authentication-key [AUTH_KEY [A.B.C.D]]", | |
7799 | NO_STR | |
7800 | "IP Information\n" | |
7801 | "OSPF interface commands\n" | |
baf9eaad CS |
7802 | VLINK_HELPSTR_AUTH_SIMPLE |
7803 | "Address of interface\n") | |
7a7be519 | 7804 | { |
d62a17ae | 7805 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7806 | int idx = 0; | |
7807 | struct in_addr addr; | |
7808 | struct ospf_if_params *params; | |
7809 | params = IF_DEF_PARAMS(ifp); | |
7810 | ||
7811 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
7812 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
7813 | vty_out(vty, | |
7814 | "Please specify interface address by A.B.C.D\n"); | |
7815 | return CMD_WARNING_CONFIG_FAILED; | |
7816 | } | |
7a7be519 | 7817 | |
d62a17ae | 7818 | params = ospf_lookup_if_params(ifp, addr); |
7819 | if (params == NULL) | |
7820 | return CMD_SUCCESS; | |
7a7be519 | 7821 | } |
813d4307 | 7822 | |
d62a17ae | 7823 | memset(params->auth_simple, 0, OSPF_AUTH_SIMPLE_SIZE); |
7824 | UNSET_IF_PARAM(params, auth_simple); | |
718e3744 | 7825 | |
d62a17ae | 7826 | if (params != IF_DEF_PARAMS(ifp)) { |
7827 | ospf_free_if_params(ifp, addr); | |
7828 | ospf_if_update_params(ifp, addr); | |
7829 | } | |
813d4307 | 7830 | |
d62a17ae | 7831 | return CMD_SUCCESS; |
7a7be519 | 7832 | } |
813d4307 | 7833 | |
0d829fa7 QY |
7834 | DEFUN_HIDDEN (no_ospf_authentication_key, |
7835 | no_ospf_authentication_key_authkey_addr_cmd, | |
7836 | "no ospf authentication-key [AUTH_KEY [A.B.C.D]]", | |
7837 | NO_STR | |
7838 | "OSPF interface commands\n" | |
baf9eaad CS |
7839 | VLINK_HELPSTR_AUTH_SIMPLE |
7840 | "Address of interface\n") | |
0d829fa7 | 7841 | { |
d62a17ae | 7842 | return no_ip_ospf_authentication_key(self, vty, argc, argv); |
0d829fa7 QY |
7843 | } |
7844 | ||
718e3744 | 7845 | DEFUN (ip_ospf_message_digest_key, |
537eae3f | 7846 | ip_ospf_message_digest_key_cmd, |
7a7be519 | 7847 | "ip ospf message-digest-key (1-255) md5 KEY [A.B.C.D]", |
718e3744 | 7848 | "IP Information\n" |
7849 | "OSPF interface commands\n" | |
7850 | "Message digest authentication password (key)\n" | |
7851 | "Key ID\n" | |
7852 | "Use MD5 algorithm\n" | |
fefa0d82 QY |
7853 | "The OSPF password (key)\n" |
7854 | "Address of interface\n") | |
718e3744 | 7855 | { |
d62a17ae | 7856 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7857 | struct crypt_key *ck; | |
d7c0a89a | 7858 | uint8_t key_id; |
d62a17ae | 7859 | struct in_addr addr; |
7860 | struct ospf_if_params *params; | |
7861 | ||
7862 | params = IF_DEF_PARAMS(ifp); | |
7863 | int idx = 0; | |
7864 | ||
7865 | argv_find(argv, argc, "(1-255)", &idx); | |
7866 | char *keyid = argv[idx]->arg; | |
7867 | argv_find(argv, argc, "KEY", &idx); | |
7868 | char *cryptkey = argv[idx]->arg; | |
7869 | ||
7870 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
7871 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
7872 | vty_out(vty, | |
7873 | "Please specify interface address by A.B.C.D\n"); | |
7874 | return CMD_WARNING_CONFIG_FAILED; | |
7875 | } | |
7876 | ||
7877 | params = ospf_get_if_params(ifp, addr); | |
7878 | ospf_if_update_params(ifp, addr); | |
718e3744 | 7879 | } |
7880 | ||
d62a17ae | 7881 | key_id = strtol(keyid, NULL, 10); |
519b1464 MS |
7882 | |
7883 | /* Remove existing key, if any */ | |
7884 | ospf_crypt_key_delete(params->auth_crypt, key_id); | |
718e3744 | 7885 | |
d62a17ae | 7886 | ck = ospf_crypt_key_new(); |
d7c0a89a | 7887 | ck->key_id = (uint8_t)key_id; |
4d65d927 | 7888 | strlcpy((char *)ck->auth_key, cryptkey, sizeof(ck->auth_key)); |
718e3744 | 7889 | |
d62a17ae | 7890 | ospf_crypt_key_add(params->auth_crypt, ck); |
7891 | SET_IF_PARAM(params, auth_crypt); | |
718e3744 | 7892 | |
d62a17ae | 7893 | return CMD_SUCCESS; |
718e3744 | 7894 | } |
7895 | ||
7a7be519 | 7896 | DEFUN_HIDDEN (ospf_message_digest_key, |
747e489c | 7897 | ospf_message_digest_key_cmd, |
0d829fa7 | 7898 | "ospf message-digest-key (1-255) md5 KEY [A.B.C.D]", |
747e489c DW |
7899 | "OSPF interface commands\n" |
7900 | "Message digest authentication password (key)\n" | |
7901 | "Key ID\n" | |
7902 | "Use MD5 algorithm\n" | |
0d829fa7 QY |
7903 | "The OSPF password (key)\n" |
7904 | "Address of interface\n") | |
7a7be519 | 7905 | { |
d62a17ae | 7906 | return ip_ospf_message_digest_key(self, vty, argc, argv); |
7a7be519 | 7907 | } |
718e3744 | 7908 | |
537eae3f QY |
7909 | DEFUN (no_ip_ospf_message_digest_key, |
7910 | no_ip_ospf_message_digest_key_cmd, | |
0d829fa7 | 7911 | "no ip ospf message-digest-key (1-255) [md5 KEY] [A.B.C.D]", |
813d4307 DW |
7912 | NO_STR |
7913 | "IP Information\n" | |
7914 | "OSPF interface commands\n" | |
7915 | "Message digest authentication password (key)\n" | |
7916 | "Key ID\n" | |
7917 | "Use MD5 algorithm\n" | |
0d829fa7 QY |
7918 | "The OSPF password (key)\n" |
7919 | "Address of interface\n") | |
813d4307 | 7920 | { |
d62a17ae | 7921 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7922 | int idx = 0; | |
7923 | struct crypt_key *ck; | |
7924 | int key_id; | |
7925 | struct in_addr addr; | |
7926 | struct ospf_if_params *params; | |
7927 | params = IF_DEF_PARAMS(ifp); | |
7928 | ||
7929 | argv_find(argv, argc, "(1-255)", &idx); | |
7930 | char *keyid = argv[idx]->arg; | |
7931 | ||
7932 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
7933 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
7934 | vty_out(vty, | |
7935 | "Please specify interface address by A.B.C.D\n"); | |
7936 | return CMD_WARNING_CONFIG_FAILED; | |
7937 | } | |
7a7be519 | 7938 | |
d62a17ae | 7939 | params = ospf_lookup_if_params(ifp, addr); |
7940 | if (params == NULL) | |
7941 | return CMD_SUCCESS; | |
7a7be519 | 7942 | } |
7943 | ||
d62a17ae | 7944 | key_id = strtol(keyid, NULL, 10); |
7945 | ck = ospf_crypt_key_lookup(params->auth_crypt, key_id); | |
7946 | if (ck == NULL) { | |
7947 | vty_out(vty, "OSPF: Key %d does not exist\n", key_id); | |
7948 | return CMD_WARNING_CONFIG_FAILED; | |
7949 | } | |
7a7be519 | 7950 | |
d62a17ae | 7951 | ospf_crypt_key_delete(params->auth_crypt, key_id); |
7a7be519 | 7952 | |
d62a17ae | 7953 | if (params != IF_DEF_PARAMS(ifp)) { |
7954 | ospf_free_if_params(ifp, addr); | |
7955 | ospf_if_update_params(ifp, addr); | |
7956 | } | |
7a7be519 | 7957 | |
d62a17ae | 7958 | return CMD_SUCCESS; |
7a7be519 | 7959 | } |
813d4307 | 7960 | |
0d829fa7 | 7961 | DEFUN_HIDDEN (no_ospf_message_digest_key, |
537eae3f | 7962 | no_ospf_message_digest_key_cmd, |
0d829fa7 QY |
7963 | "no ospf message-digest-key (1-255) [md5 KEY] [A.B.C.D]", |
7964 | NO_STR | |
7965 | "OSPF interface commands\n" | |
7966 | "Message digest authentication password (key)\n" | |
7967 | "Key ID\n" | |
efd7904e RW |
7968 | "Use MD5 algorithm\n" |
7969 | "The OSPF password (key)\n" | |
7970 | "Address of interface\n") | |
718e3744 | 7971 | { |
d62a17ae | 7972 | return no_ip_ospf_message_digest_key(self, vty, argc, argv); |
718e3744 | 7973 | } |
7974 | ||
718e3744 | 7975 | DEFUN (ip_ospf_cost, |
5c2fc921 | 7976 | ip_ospf_cost_cmd, |
7a7be519 | 7977 | "ip ospf cost (1-65535) [A.B.C.D]", |
718e3744 | 7978 | "IP Information\n" |
7979 | "OSPF interface commands\n" | |
7980 | "Interface cost\n" | |
7981 | "Cost\n" | |
5c2fc921 | 7982 | "Address of interface\n") |
718e3744 | 7983 | { |
d62a17ae | 7984 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7985 | int idx = 0; | |
d7c0a89a | 7986 | uint32_t cost = OSPF_OUTPUT_COST_DEFAULT; |
d62a17ae | 7987 | struct in_addr addr; |
7988 | struct ospf_if_params *params; | |
7989 | params = IF_DEF_PARAMS(ifp); | |
7990 | ||
7991 | // get arguments | |
7992 | char *coststr = NULL, *ifaddr = NULL; | |
35955c14 | 7993 | |
c31a793b VJ |
7994 | argv_find(argv, argc, "(1-65535)", &idx); |
7995 | coststr = argv[idx]->arg; | |
d62a17ae | 7996 | cost = strtol(coststr, NULL, 10); |
7997 | ||
c31a793b | 7998 | ifaddr = argv_find(argv, argc, "A.B.C.D", &idx) ? argv[idx]->arg : NULL; |
d62a17ae | 7999 | if (ifaddr) { |
8000 | if (!inet_aton(ifaddr, &addr)) { | |
8001 | vty_out(vty, | |
8002 | "Please specify interface address by A.B.C.D\n"); | |
8003 | return CMD_WARNING_CONFIG_FAILED; | |
8004 | } | |
718e3744 | 8005 | |
d62a17ae | 8006 | params = ospf_get_if_params(ifp, addr); |
8007 | ospf_if_update_params(ifp, addr); | |
718e3744 | 8008 | } |
8009 | ||
d62a17ae | 8010 | SET_IF_PARAM(params, output_cost_cmd); |
8011 | params->output_cost_cmd = cost; | |
718e3744 | 8012 | |
d62a17ae | 8013 | ospf_if_recalculate_output_cost(ifp); |
5c2fc921 | 8014 | |
d62a17ae | 8015 | return CMD_SUCCESS; |
718e3744 | 8016 | } |
8017 | ||
7a7be519 | 8018 | DEFUN_HIDDEN (ospf_cost, |
5c2fc921 QY |
8019 | ospf_cost_cmd, |
8020 | "ospf cost (1-65535) [A.B.C.D]", | |
747e489c DW |
8021 | "OSPF interface commands\n" |
8022 | "Interface cost\n" | |
8023 | "Cost\n" | |
5c2fc921 | 8024 | "Address of interface\n") |
7a7be519 | 8025 | { |
d62a17ae | 8026 | return ip_ospf_cost(self, vty, argc, argv); |
7a7be519 | 8027 | } |
9eff36b3 | 8028 | |
718e3744 | 8029 | DEFUN (no_ip_ospf_cost, |
5c2fc921 QY |
8030 | no_ip_ospf_cost_cmd, |
8031 | "no ip ospf cost [(1-65535)] [A.B.C.D]", | |
718e3744 | 8032 | NO_STR |
efd7904e | 8033 | "IP Information\n" |
718e3744 | 8034 | "OSPF interface commands\n" |
8035 | "Interface cost\n" | |
efd7904e RW |
8036 | "Cost\n" |
8037 | "Address of interface\n") | |
718e3744 | 8038 | { |
d62a17ae | 8039 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8040 | int idx = 0; | |
8041 | struct in_addr addr; | |
8042 | struct ospf_if_params *params; | |
7a7be519 | 8043 | |
d62a17ae | 8044 | params = IF_DEF_PARAMS(ifp); |
718e3744 | 8045 | |
d62a17ae | 8046 | // get arguments |
8047 | char *ifaddr = NULL; | |
8048 | ifaddr = argv_find(argv, argc, "A.B.C.D", &idx) ? argv[idx]->arg : NULL; | |
718e3744 | 8049 | |
d62a17ae | 8050 | /* According to the semantics we are mimicking "no ip ospf cost N" is |
8051 | * always treated as "no ip ospf cost" regardless of the actual value | |
8052 | * of N already configured for the interface. Thus ignore cost. */ | |
7a7be519 | 8053 | |
d62a17ae | 8054 | if (ifaddr) { |
8055 | if (!inet_aton(ifaddr, &addr)) { | |
8056 | vty_out(vty, | |
8057 | "Please specify interface address by A.B.C.D\n"); | |
8058 | return CMD_WARNING_CONFIG_FAILED; | |
8059 | } | |
7a7be519 | 8060 | |
d62a17ae | 8061 | params = ospf_lookup_if_params(ifp, addr); |
8062 | if (params == NULL) | |
8063 | return CMD_SUCCESS; | |
8064 | } | |
7a7be519 | 8065 | |
d62a17ae | 8066 | UNSET_IF_PARAM(params, output_cost_cmd); |
7a7be519 | 8067 | |
d62a17ae | 8068 | if (params != IF_DEF_PARAMS(ifp)) { |
8069 | ospf_free_if_params(ifp, addr); | |
8070 | ospf_if_update_params(ifp, addr); | |
8071 | } | |
7a7be519 | 8072 | |
d62a17ae | 8073 | ospf_if_recalculate_output_cost(ifp); |
7a7be519 | 8074 | |
d62a17ae | 8075 | return CMD_SUCCESS; |
7a7be519 | 8076 | } |
9eff36b3 | 8077 | |
5c2fc921 QY |
8078 | DEFUN_HIDDEN (no_ospf_cost, |
8079 | no_ospf_cost_cmd, | |
8080 | "no ospf cost [(1-65535)] [A.B.C.D]", | |
8081 | NO_STR | |
8082 | "OSPF interface commands\n" | |
8083 | "Interface cost\n" | |
8084 | "Cost\n" | |
8085 | "Address of interface\n") | |
827341b7 | 8086 | { |
d62a17ae | 8087 | return no_ip_ospf_cost(self, vty, argc, argv); |
827341b7 DO |
8088 | } |
8089 | ||
d62a17ae | 8090 | static void ospf_nbr_timer_update(struct ospf_interface *oi) |
718e3744 | 8091 | { |
d62a17ae | 8092 | struct route_node *rn; |
8093 | struct ospf_neighbor *nbr; | |
718e3744 | 8094 | |
d62a17ae | 8095 | for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) |
8096 | if ((nbr = rn->info)) { | |
8097 | nbr->v_inactivity = OSPF_IF_PARAM(oi, v_wait); | |
8098 | nbr->v_db_desc = OSPF_IF_PARAM(oi, retransmit_interval); | |
8099 | nbr->v_ls_req = OSPF_IF_PARAM(oi, retransmit_interval); | |
8100 | nbr->v_ls_upd = OSPF_IF_PARAM(oi, retransmit_interval); | |
8101 | } | |
718e3744 | 8102 | } |
8103 | ||
d62a17ae | 8104 | static int ospf_vty_dead_interval_set(struct vty *vty, const char *interval_str, |
8105 | const char *nbr_str, | |
8106 | const char *fast_hello_str) | |
8107 | { | |
8108 | VTY_DECLVAR_CONTEXT(interface, ifp); | |
d7c0a89a QY |
8109 | uint32_t seconds; |
8110 | uint8_t hellomult; | |
d62a17ae | 8111 | struct in_addr addr; |
8112 | int ret; | |
8113 | struct ospf_if_params *params; | |
8114 | struct ospf_interface *oi; | |
8115 | struct route_node *rn; | |
718e3744 | 8116 | |
d62a17ae | 8117 | params = IF_DEF_PARAMS(ifp); |
8118 | ||
8119 | if (nbr_str) { | |
8120 | ret = inet_aton(nbr_str, &addr); | |
8121 | if (!ret) { | |
8122 | vty_out(vty, | |
8123 | "Please specify interface address by A.B.C.D\n"); | |
8124 | return CMD_WARNING_CONFIG_FAILED; | |
8125 | } | |
8126 | ||
8127 | params = ospf_get_if_params(ifp, addr); | |
8128 | ospf_if_update_params(ifp, addr); | |
8129 | } | |
8130 | ||
8131 | if (interval_str) { | |
8132 | seconds = strtoul(interval_str, NULL, 10); | |
8133 | ||
8134 | /* reset fast_hello too, just to be sure */ | |
8135 | UNSET_IF_PARAM(params, fast_hello); | |
8136 | params->fast_hello = OSPF_FAST_HELLO_DEFAULT; | |
8137 | } else if (fast_hello_str) { | |
8138 | hellomult = strtoul(fast_hello_str, NULL, 10); | |
8139 | /* 1s dead-interval with sub-second hellos desired */ | |
8140 | seconds = OSPF_ROUTER_DEAD_INTERVAL_MINIMAL; | |
8141 | SET_IF_PARAM(params, fast_hello); | |
8142 | params->fast_hello = hellomult; | |
8143 | } else { | |
8144 | vty_out(vty, | |
8145 | "Please specify dead-interval or hello-multiplier\n"); | |
8146 | return CMD_WARNING_CONFIG_FAILED; | |
8147 | } | |
8148 | ||
8149 | SET_IF_PARAM(params, v_wait); | |
8150 | params->v_wait = seconds; | |
182d6bdc | 8151 | params->is_v_wait_set = true; |
d62a17ae | 8152 | |
8153 | /* Update timer values in neighbor structure. */ | |
8154 | if (nbr_str) { | |
b5a8894d CS |
8155 | struct ospf *ospf = NULL; |
8156 | ||
a36898e7 | 8157 | ospf = ospf_lookup_by_vrf_id(ifp->vrf_id); |
b5a8894d | 8158 | if (ospf) { |
d62a17ae | 8159 | oi = ospf_if_lookup_by_local_addr(ospf, ifp, addr); |
8160 | if (oi) | |
8161 | ospf_nbr_timer_update(oi); | |
8162 | } | |
8163 | } else { | |
8164 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) | |
8165 | if ((oi = rn->info)) | |
8166 | ospf_nbr_timer_update(oi); | |
8167 | } | |
8168 | ||
8169 | return CMD_SUCCESS; | |
718e3744 | 8170 | } |
8171 | ||
f9ad937f | 8172 | DEFUN (ip_ospf_dead_interval, |
0d829fa7 | 8173 | ip_ospf_dead_interval_cmd, |
7a7be519 | 8174 | "ip ospf dead-interval (1-65535) [A.B.C.D]", |
f9ad937f | 8175 | "IP Information\n" |
8176 | "OSPF interface commands\n" | |
99a522c7 | 8177 | "Interval time after which a neighbor is declared down\n" |
f9ad937f | 8178 | "Seconds\n" |
8179 | "Address of interface\n") | |
8180 | { | |
d62a17ae | 8181 | int idx = 0; |
8182 | char *interval = argv_find(argv, argc, "(1-65535)", &idx) | |
8183 | ? argv[idx]->arg | |
8184 | : NULL; | |
8185 | char *ifaddr = | |
8186 | argv_find(argv, argc, "A.B.C.D", &idx) ? argv[idx]->arg : NULL; | |
8187 | return ospf_vty_dead_interval_set(vty, interval, ifaddr, NULL); | |
f9ad937f | 8188 | } |
8189 | ||
718e3744 | 8190 | |
7a7be519 | 8191 | DEFUN_HIDDEN (ospf_dead_interval, |
747e489c | 8192 | ospf_dead_interval_cmd, |
0d829fa7 | 8193 | "ospf dead-interval (1-65535) [A.B.C.D]", |
747e489c | 8194 | "OSPF interface commands\n" |
99a522c7 | 8195 | "Interval time after which a neighbor is declared down\n" |
0d829fa7 QY |
8196 | "Seconds\n" |
8197 | "Address of interface\n") | |
7a7be519 | 8198 | { |
d62a17ae | 8199 | return ip_ospf_dead_interval(self, vty, argc, argv); |
7a7be519 | 8200 | } |
718e3744 | 8201 | |
f9ad937f | 8202 | DEFUN (ip_ospf_dead_interval_minimal, |
8203 | ip_ospf_dead_interval_minimal_addr_cmd, | |
7a7be519 | 8204 | "ip ospf dead-interval minimal hello-multiplier (1-10) [A.B.C.D]", |
f9ad937f | 8205 | "IP Information\n" |
8206 | "OSPF interface commands\n" | |
99a522c7 | 8207 | "Interval time after which a neighbor is declared down\n" |
f9ad937f | 8208 | "Minimal 1s dead-interval with fast sub-second hellos\n" |
8209 | "Hello multiplier factor\n" | |
8210 | "Number of Hellos to send each second\n" | |
8211 | "Address of interface\n") | |
8212 | { | |
d62a17ae | 8213 | int idx_number = 5; |
8214 | int idx_ipv4 = 6; | |
8215 | if (argc == 7) | |
8216 | return ospf_vty_dead_interval_set( | |
8217 | vty, NULL, argv[idx_ipv4]->arg, argv[idx_number]->arg); | |
8218 | else | |
8219 | return ospf_vty_dead_interval_set(vty, NULL, NULL, | |
8220 | argv[idx_number]->arg); | |
f9ad937f | 8221 | } |
8222 | ||
718e3744 | 8223 | DEFUN (no_ip_ospf_dead_interval, |
0d829fa7 | 8224 | no_ip_ospf_dead_interval_cmd, |
e83a9414 | 8225 | "no ip ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]", |
718e3744 | 8226 | NO_STR |
8227 | "IP Information\n" | |
8228 | "OSPF interface commands\n" | |
99a522c7 | 8229 | "Interval time after which a neighbor is declared down\n" |
f9dfba8d | 8230 | "Seconds\n" |
efd7904e RW |
8231 | "Minimal 1s dead-interval with fast sub-second hellos\n" |
8232 | "Hello multiplier factor\n" | |
8233 | "Number of Hellos to send each second\n" | |
8234 | "Address of interface\n") | |
718e3744 | 8235 | { |
d62a17ae | 8236 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8237 | int idx_ipv4 = argc - 1; | |
8238 | struct in_addr addr = {.s_addr = 0L}; | |
8239 | int ret; | |
8240 | struct ospf_if_params *params; | |
8241 | struct ospf_interface *oi; | |
8242 | struct route_node *rn; | |
8243 | ||
8244 | params = IF_DEF_PARAMS(ifp); | |
8245 | ||
8246 | if (argv[idx_ipv4]->type == IPV4_TKN) { | |
8247 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
8248 | if (!ret) { | |
8249 | vty_out(vty, | |
8250 | "Please specify interface address by A.B.C.D\n"); | |
8251 | return CMD_WARNING_CONFIG_FAILED; | |
8252 | } | |
020709f9 | 8253 | |
d62a17ae | 8254 | params = ospf_lookup_if_params(ifp, addr); |
8255 | if (params == NULL) | |
8256 | return CMD_SUCCESS; | |
8257 | } | |
718e3744 | 8258 | |
d62a17ae | 8259 | UNSET_IF_PARAM(params, v_wait); |
8260 | params->v_wait = OSPF_ROUTER_DEAD_INTERVAL_DEFAULT; | |
182d6bdc | 8261 | params->is_v_wait_set = false; |
d62a17ae | 8262 | |
8263 | UNSET_IF_PARAM(params, fast_hello); | |
8264 | params->fast_hello = OSPF_FAST_HELLO_DEFAULT; | |
8265 | ||
8266 | if (params != IF_DEF_PARAMS(ifp)) { | |
8267 | ospf_free_if_params(ifp, addr); | |
8268 | ospf_if_update_params(ifp, addr); | |
718e3744 | 8269 | } |
8270 | ||
d62a17ae | 8271 | /* Update timer values in neighbor structure. */ |
8272 | if (argc == 1) { | |
b5a8894d | 8273 | struct ospf *ospf = NULL; |
718e3744 | 8274 | |
a36898e7 | 8275 | ospf = ospf_lookup_by_vrf_id(ifp->vrf_id); |
b5a8894d | 8276 | if (ospf) { |
d62a17ae | 8277 | oi = ospf_if_lookup_by_local_addr(ospf, ifp, addr); |
8278 | if (oi) | |
8279 | ospf_nbr_timer_update(oi); | |
8280 | } | |
8281 | } else { | |
8282 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) | |
8283 | if ((oi = rn->info)) | |
8284 | ospf_nbr_timer_update(oi); | |
8285 | } | |
8286 | ||
8287 | return CMD_SUCCESS; | |
718e3744 | 8288 | } |
8289 | ||
0d829fa7 QY |
8290 | DEFUN_HIDDEN (no_ospf_dead_interval, |
8291 | no_ospf_dead_interval_cmd, | |
8292 | "no ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]", | |
8293 | NO_STR | |
8294 | "OSPF interface commands\n" | |
99a522c7 | 8295 | "Interval time after which a neighbor is declared down\n" |
0d829fa7 | 8296 | "Seconds\n" |
efd7904e RW |
8297 | "Minimal 1s dead-interval with fast sub-second hellos\n" |
8298 | "Hello multiplier factor\n" | |
8299 | "Number of Hellos to send each second\n" | |
8300 | "Address of interface\n") | |
0d829fa7 | 8301 | { |
d62a17ae | 8302 | return no_ip_ospf_dead_interval(self, vty, argc, argv); |
0d829fa7 QY |
8303 | } |
8304 | ||
718e3744 | 8305 | DEFUN (ip_ospf_hello_interval, |
0d829fa7 | 8306 | ip_ospf_hello_interval_cmd, |
7a7be519 | 8307 | "ip ospf hello-interval (1-65535) [A.B.C.D]", |
718e3744 | 8308 | "IP Information\n" |
8309 | "OSPF interface commands\n" | |
8310 | "Time between HELLO packets\n" | |
8311 | "Seconds\n" | |
0d829fa7 | 8312 | "Address of interface\n") |
718e3744 | 8313 | { |
d62a17ae | 8314 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8315 | int idx = 0; | |
be418160 | 8316 | struct in_addr addr = {.s_addr = 0L}; |
d62a17ae | 8317 | struct ospf_if_params *params; |
8318 | params = IF_DEF_PARAMS(ifp); | |
d7c0a89a | 8319 | uint32_t seconds = 0; |
be418160 | 8320 | bool is_addr = false; |
8321 | uint32_t old_interval = 0; | |
d62a17ae | 8322 | |
8323 | argv_find(argv, argc, "(1-65535)", &idx); | |
8324 | seconds = strtol(argv[idx]->arg, NULL, 10); | |
8325 | ||
8326 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
8327 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
8328 | vty_out(vty, | |
8329 | "Please specify interface address by A.B.C.D\n"); | |
8330 | return CMD_WARNING_CONFIG_FAILED; | |
8331 | } | |
718e3744 | 8332 | |
d62a17ae | 8333 | params = ospf_get_if_params(ifp, addr); |
8334 | ospf_if_update_params(ifp, addr); | |
be418160 | 8335 | is_addr = true; |
d62a17ae | 8336 | } |
718e3744 | 8337 | |
be418160 | 8338 | old_interval = params->v_hello; |
8339 | ||
8340 | /* Return, if same interval is configured. */ | |
8341 | if (old_interval == seconds) | |
8342 | return CMD_SUCCESS; | |
8343 | ||
d62a17ae | 8344 | SET_IF_PARAM(params, v_hello); |
8345 | params->v_hello = seconds; | |
718e3744 | 8346 | |
182d6bdc K |
8347 | if (!params->is_v_wait_set) { |
8348 | SET_IF_PARAM(params, v_wait); | |
8349 | /* As per RFC 4062 | |
8350 | * The router dead interval should | |
8351 | * be some multiple of the HelloInterval (perhaps 4 times the | |
8352 | * hello interval) and must be the same for all routers | |
8353 | * attached to a common network. | |
8354 | */ | |
8355 | params->v_wait = 4 * seconds; | |
8356 | } | |
8357 | ||
be418160 | 8358 | ospf_reset_hello_timer(ifp, addr, is_addr); |
8359 | ||
d62a17ae | 8360 | return CMD_SUCCESS; |
718e3744 | 8361 | } |
8362 | ||
7a7be519 | 8363 | DEFUN_HIDDEN (ospf_hello_interval, |
747e489c | 8364 | ospf_hello_interval_cmd, |
0d829fa7 | 8365 | "ospf hello-interval (1-65535) [A.B.C.D]", |
747e489c DW |
8366 | "OSPF interface commands\n" |
8367 | "Time between HELLO packets\n" | |
0d829fa7 QY |
8368 | "Seconds\n" |
8369 | "Address of interface\n") | |
7a7be519 | 8370 | { |
d62a17ae | 8371 | return ip_ospf_hello_interval(self, vty, argc, argv); |
7a7be519 | 8372 | } |
718e3744 | 8373 | |
8374 | DEFUN (no_ip_ospf_hello_interval, | |
0d829fa7 QY |
8375 | no_ip_ospf_hello_interval_cmd, |
8376 | "no ip ospf hello-interval [(1-65535) [A.B.C.D]]", | |
718e3744 | 8377 | NO_STR |
8378 | "IP Information\n" | |
8379 | "OSPF interface commands\n" | |
0d829fa7 | 8380 | "Time between HELLO packets\n" // ignored |
f9dfba8d | 8381 | "Seconds\n" |
0d829fa7 | 8382 | "Address of interface\n") |
718e3744 | 8383 | { |
d62a17ae | 8384 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8385 | int idx = 0; | |
be418160 | 8386 | struct in_addr addr = {.s_addr = 0L}; |
d62a17ae | 8387 | struct ospf_if_params *params; |
182d6bdc | 8388 | struct route_node *rn; |
df581cd3 | 8389 | |
d62a17ae | 8390 | params = IF_DEF_PARAMS(ifp); |
718e3744 | 8391 | |
d62a17ae | 8392 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { |
8393 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
8394 | vty_out(vty, | |
8395 | "Please specify interface address by A.B.C.D\n"); | |
8396 | return CMD_WARNING_CONFIG_FAILED; | |
8397 | } | |
718e3744 | 8398 | |
d62a17ae | 8399 | params = ospf_lookup_if_params(ifp, addr); |
8400 | if (params == NULL) | |
8401 | return CMD_SUCCESS; | |
8402 | } | |
718e3744 | 8403 | |
d62a17ae | 8404 | UNSET_IF_PARAM(params, v_hello); |
8405 | params->v_hello = OSPF_HELLO_INTERVAL_DEFAULT; | |
718e3744 | 8406 | |
182d6bdc K |
8407 | if (!params->is_v_wait_set) { |
8408 | UNSET_IF_PARAM(params, v_wait); | |
8409 | params->v_wait = OSPF_ROUTER_DEAD_INTERVAL_DEFAULT; | |
8410 | } | |
8411 | ||
8412 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { | |
8413 | struct ospf_interface *oi = rn->info; | |
8414 | ||
8415 | if (!oi) | |
8416 | continue; | |
8417 | ||
8418 | oi->type = IF_DEF_PARAMS(ifp)->type; | |
bc97889b | 8419 | oi->ptp_dmvpn = IF_DEF_PARAMS(ifp)->ptp_dmvpn; |
182d6bdc K |
8420 | |
8421 | if (oi->state > ISM_Down) { | |
8422 | OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceDown); | |
8423 | OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceUp); | |
8424 | } | |
8425 | } | |
8426 | ||
d62a17ae | 8427 | if (params != IF_DEF_PARAMS(ifp)) { |
8428 | ospf_free_if_params(ifp, addr); | |
8429 | ospf_if_update_params(ifp, addr); | |
8430 | } | |
718e3744 | 8431 | |
d62a17ae | 8432 | return CMD_SUCCESS; |
718e3744 | 8433 | } |
8434 | ||
0d829fa7 QY |
8435 | DEFUN_HIDDEN (no_ospf_hello_interval, |
8436 | no_ospf_hello_interval_cmd, | |
8437 | "no ospf hello-interval [(1-65535) [A.B.C.D]]", | |
8438 | NO_STR | |
8439 | "OSPF interface commands\n" | |
8440 | "Time between HELLO packets\n" // ignored | |
8441 | "Seconds\n" | |
8442 | "Address of interface\n") | |
8443 | { | |
d62a17ae | 8444 | return no_ip_ospf_hello_interval(self, vty, argc, argv); |
0d829fa7 | 8445 | } |
718e3744 | 8446 | |
bc97889b AL |
8447 | DEFUN(ip_ospf_network, ip_ospf_network_cmd, |
8448 | "ip ospf network <broadcast|non-broadcast|point-to-multipoint|point-to-point [dmvpn]>", | |
8449 | "IP Information\n" | |
8450 | "OSPF interface commands\n" | |
8451 | "Network type\n" | |
8452 | "Specify OSPF broadcast multi-access network\n" | |
8453 | "Specify OSPF NBMA network\n" | |
8454 | "Specify OSPF point-to-multipoint network\n" | |
8455 | "Specify OSPF point-to-point network\n" | |
8456 | "Specify OSPF point-to-point DMVPN network\n") | |
718e3744 | 8457 | { |
d62a17ae | 8458 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8459 | int idx = 0; | |
8460 | int old_type = IF_DEF_PARAMS(ifp)->type; | |
bc97889b | 8461 | uint8_t old_ptp_dmvpn = IF_DEF_PARAMS(ifp)->ptp_dmvpn; |
d62a17ae | 8462 | struct route_node *rn; |
718e3744 | 8463 | |
d62a17ae | 8464 | if (old_type == OSPF_IFTYPE_LOOPBACK) { |
8465 | vty_out(vty, | |
8466 | "This is a loopback interface. Can't set network type.\n"); | |
8467 | return CMD_WARNING_CONFIG_FAILED; | |
8468 | } | |
718e3744 | 8469 | |
bc97889b AL |
8470 | IF_DEF_PARAMS(ifp)->ptp_dmvpn = 0; |
8471 | ||
d62a17ae | 8472 | if (argv_find(argv, argc, "broadcast", &idx)) |
8473 | IF_DEF_PARAMS(ifp)->type = OSPF_IFTYPE_BROADCAST; | |
8474 | else if (argv_find(argv, argc, "non-broadcast", &idx)) | |
8475 | IF_DEF_PARAMS(ifp)->type = OSPF_IFTYPE_NBMA; | |
8476 | else if (argv_find(argv, argc, "point-to-multipoint", &idx)) | |
8477 | IF_DEF_PARAMS(ifp)->type = OSPF_IFTYPE_POINTOMULTIPOINT; | |
bc97889b | 8478 | else if (argv_find(argv, argc, "point-to-point", &idx)) { |
d62a17ae | 8479 | IF_DEF_PARAMS(ifp)->type = OSPF_IFTYPE_POINTOPOINT; |
bc97889b AL |
8480 | if (argv_find(argv, argc, "dmvpn", &idx)) |
8481 | IF_DEF_PARAMS(ifp)->ptp_dmvpn = 1; | |
8482 | } | |
718e3744 | 8483 | |
bc97889b AL |
8484 | if (IF_DEF_PARAMS(ifp)->type == old_type |
8485 | && IF_DEF_PARAMS(ifp)->ptp_dmvpn == old_ptp_dmvpn) | |
d62a17ae | 8486 | return CMD_SUCCESS; |
8487 | ||
8488 | SET_IF_PARAM(IF_DEF_PARAMS(ifp), type); | |
8489 | ||
8490 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { | |
8491 | struct ospf_interface *oi = rn->info; | |
8492 | ||
8493 | if (!oi) | |
8494 | continue; | |
8495 | ||
8496 | oi->type = IF_DEF_PARAMS(ifp)->type; | |
8497 | ||
8498 | if (oi->state > ISM_Down) { | |
8499 | OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceDown); | |
8500 | OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceUp); | |
8501 | } | |
7a7be519 | 8502 | } |
7a7be519 | 8503 | |
d62a17ae | 8504 | return CMD_SUCCESS; |
7a7be519 | 8505 | } |
8506 | ||
8507 | DEFUN_HIDDEN (ospf_network, | |
8508 | ospf_network_cmd, | |
e83a9414 | 8509 | "ospf network <broadcast|non-broadcast|point-to-multipoint|point-to-point>", |
7a7be519 | 8510 | "OSPF interface commands\n" |
8511 | "Network type\n" | |
8512 | "Specify OSPF broadcast multi-access network\n" | |
8513 | "Specify OSPF NBMA network\n" | |
8514 | "Specify OSPF point-to-multipoint network\n" | |
8515 | "Specify OSPF point-to-point network\n") | |
8516 | { | |
d62a17ae | 8517 | return ip_ospf_network(self, vty, argc, argv); |
7a7be519 | 8518 | } |
8519 | ||
8520 | DEFUN (no_ip_ospf_network, | |
8521 | no_ip_ospf_network_cmd, | |
8522 | "no ip ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]", | |
8523 | NO_STR | |
8524 | "IP Information\n" | |
8525 | "OSPF interface commands\n" | |
8526 | "Network type\n" | |
8527 | "Specify OSPF broadcast multi-access network\n" | |
8528 | "Specify OSPF NBMA network\n" | |
8529 | "Specify OSPF point-to-multipoint network\n" | |
8530 | "Specify OSPF point-to-point network\n") | |
22b27e95 | 8531 | { |
d62a17ae | 8532 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8533 | int old_type = IF_DEF_PARAMS(ifp)->type; | |
8534 | struct route_node *rn; | |
7a7be519 | 8535 | |
d62a17ae | 8536 | IF_DEF_PARAMS(ifp)->type = ospf_default_iftype(ifp); |
bc97889b | 8537 | IF_DEF_PARAMS(ifp)->ptp_dmvpn = 0; |
7a7be519 | 8538 | |
d62a17ae | 8539 | if (IF_DEF_PARAMS(ifp)->type == old_type) |
8540 | return CMD_SUCCESS; | |
7a7be519 | 8541 | |
d62a17ae | 8542 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { |
8543 | struct ospf_interface *oi = rn->info; | |
7a7be519 | 8544 | |
d62a17ae | 8545 | if (!oi) |
8546 | continue; | |
7a7be519 | 8547 | |
d62a17ae | 8548 | oi->type = IF_DEF_PARAMS(ifp)->type; |
7a7be519 | 8549 | |
d62a17ae | 8550 | if (oi->state > ISM_Down) { |
8551 | OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceDown); | |
8552 | OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceUp); | |
8553 | } | |
7a7be519 | 8554 | } |
7a7be519 | 8555 | |
d62a17ae | 8556 | return CMD_SUCCESS; |
7a7be519 | 8557 | } |
8558 | ||
0d829fa7 QY |
8559 | DEFUN_HIDDEN (no_ospf_network, |
8560 | no_ospf_network_cmd, | |
8561 | "no ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]", | |
8562 | NO_STR | |
8563 | "OSPF interface commands\n" | |
8564 | "Network type\n" | |
8565 | "Specify OSPF broadcast multi-access network\n" | |
8566 | "Specify OSPF NBMA network\n" | |
8567 | "Specify OSPF point-to-multipoint network\n" | |
8568 | "Specify OSPF point-to-point network\n") | |
8569 | { | |
d62a17ae | 8570 | return no_ip_ospf_network(self, vty, argc, argv); |
0d829fa7 QY |
8571 | } |
8572 | ||
7a7be519 | 8573 | DEFUN (ip_ospf_priority, |
537eae3f | 8574 | ip_ospf_priority_cmd, |
7a7be519 | 8575 | "ip ospf priority (0-255) [A.B.C.D]", |
8576 | "IP Information\n" | |
8577 | "OSPF interface commands\n" | |
8578 | "Router priority\n" | |
8579 | "Priority\n" | |
efd7904e | 8580 | "Address of interface\n") |
7a7be519 | 8581 | { |
d62a17ae | 8582 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8583 | int idx = 0; | |
8584 | long priority; | |
8585 | struct route_node *rn; | |
8586 | struct in_addr addr; | |
8587 | struct ospf_if_params *params; | |
8588 | params = IF_DEF_PARAMS(ifp); | |
8589 | ||
8590 | argv_find(argv, argc, "(0-255)", &idx); | |
8591 | priority = strtol(argv[idx]->arg, NULL, 10); | |
8592 | ||
8593 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
8594 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
8595 | vty_out(vty, | |
8596 | "Please specify interface address by A.B.C.D\n"); | |
8597 | return CMD_WARNING_CONFIG_FAILED; | |
8598 | } | |
7a7be519 | 8599 | |
d62a17ae | 8600 | params = ospf_get_if_params(ifp, addr); |
8601 | ospf_if_update_params(ifp, addr); | |
7a7be519 | 8602 | } |
8603 | ||
d62a17ae | 8604 | SET_IF_PARAM(params, priority); |
8605 | params->priority = priority; | |
7a7be519 | 8606 | |
d62a17ae | 8607 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { |
8608 | struct ospf_interface *oi = rn->info; | |
7a7be519 | 8609 | |
d62a17ae | 8610 | if (!oi) |
8611 | continue; | |
7a7be519 | 8612 | |
d62a17ae | 8613 | if (PRIORITY(oi) != OSPF_IF_PARAM(oi, priority)) { |
8614 | PRIORITY(oi) = OSPF_IF_PARAM(oi, priority); | |
8615 | OSPF_ISM_EVENT_SCHEDULE(oi, ISM_NeighborChange); | |
8616 | } | |
718e3744 | 8617 | } |
718e3744 | 8618 | |
d62a17ae | 8619 | return CMD_SUCCESS; |
718e3744 | 8620 | } |
8621 | ||
7a7be519 | 8622 | DEFUN_HIDDEN (ospf_priority, |
8623 | ospf_priority_cmd, | |
0d829fa7 | 8624 | "ospf priority (0-255) [A.B.C.D]", |
7a7be519 | 8625 | "OSPF interface commands\n" |
8626 | "Router priority\n" | |
3a2d747c | 8627 | "Priority\n" |
efd7904e | 8628 | "Address of interface\n") |
718e3744 | 8629 | { |
d62a17ae | 8630 | return ip_ospf_priority(self, vty, argc, argv); |
718e3744 | 8631 | } |
8632 | ||
718e3744 | 8633 | DEFUN (no_ip_ospf_priority, |
537eae3f | 8634 | no_ip_ospf_priority_cmd, |
7a7be519 | 8635 | "no ip ospf priority [(0-255) [A.B.C.D]]", |
718e3744 | 8636 | NO_STR |
8637 | "IP Information\n" | |
8638 | "OSPF interface commands\n" | |
0d829fa7 | 8639 | "Router priority\n" // ignored |
813d4307 | 8640 | "Priority\n" |
efd7904e | 8641 | "Address of interface\n") |
718e3744 | 8642 | { |
d62a17ae | 8643 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8644 | int idx = 0; | |
8645 | struct route_node *rn; | |
8646 | struct in_addr addr; | |
8647 | struct ospf_if_params *params; | |
8648 | ||
8649 | params = IF_DEF_PARAMS(ifp); | |
8650 | ||
8651 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
8652 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
8653 | vty_out(vty, | |
8654 | "Please specify interface address by A.B.C.D\n"); | |
8655 | return CMD_WARNING_CONFIG_FAILED; | |
8656 | } | |
8657 | ||
8658 | params = ospf_lookup_if_params(ifp, addr); | |
8659 | if (params == NULL) | |
8660 | return CMD_SUCCESS; | |
718e3744 | 8661 | } |
8662 | ||
d62a17ae | 8663 | UNSET_IF_PARAM(params, priority); |
8664 | params->priority = OSPF_ROUTER_PRIORITY_DEFAULT; | |
8665 | ||
8666 | if (params != IF_DEF_PARAMS(ifp)) { | |
8667 | ospf_free_if_params(ifp, addr); | |
8668 | ospf_if_update_params(ifp, addr); | |
718e3744 | 8669 | } |
d62a17ae | 8670 | |
8671 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { | |
8672 | struct ospf_interface *oi = rn->info; | |
8673 | ||
8674 | if (!oi) | |
8675 | continue; | |
8676 | ||
8677 | if (PRIORITY(oi) != OSPF_IF_PARAM(oi, priority)) { | |
8678 | PRIORITY(oi) = OSPF_IF_PARAM(oi, priority); | |
8679 | OSPF_ISM_EVENT_SCHEDULE(oi, ISM_NeighborChange); | |
8680 | } | |
8681 | } | |
8682 | ||
8683 | return CMD_SUCCESS; | |
718e3744 | 8684 | } |
8685 | ||
0d829fa7 | 8686 | DEFUN_HIDDEN (no_ospf_priority, |
537eae3f | 8687 | no_ospf_priority_cmd, |
0d829fa7 QY |
8688 | "no ospf priority [(0-255) [A.B.C.D]]", |
8689 | NO_STR | |
8690 | "OSPF interface commands\n" | |
8691 | "Router priority\n" | |
8692 | "Priority\n" | |
efd7904e | 8693 | "Address of interface\n") |
0d829fa7 | 8694 | { |
d62a17ae | 8695 | return no_ip_ospf_priority(self, vty, argc, argv); |
0d829fa7 | 8696 | } |
a1afa410 | 8697 | |
718e3744 | 8698 | DEFUN (ip_ospf_retransmit_interval, |
8699 | ip_ospf_retransmit_interval_addr_cmd, | |
d4badaf6 | 8700 | "ip ospf retransmit-interval (1-65535) [A.B.C.D]", |
718e3744 | 8701 | "IP Information\n" |
8702 | "OSPF interface commands\n" | |
8703 | "Time between retransmitting lost link state advertisements\n" | |
8704 | "Seconds\n" | |
efd7904e | 8705 | "Address of interface\n") |
718e3744 | 8706 | { |
d62a17ae | 8707 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8708 | int idx = 0; | |
d7c0a89a | 8709 | uint32_t seconds; |
d62a17ae | 8710 | struct in_addr addr; |
8711 | struct ospf_if_params *params; | |
8712 | params = IF_DEF_PARAMS(ifp); | |
8713 | ||
d4badaf6 | 8714 | argv_find(argv, argc, "(1-65535)", &idx); |
d62a17ae | 8715 | seconds = strtol(argv[idx]->arg, NULL, 10); |
8716 | ||
8717 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
8718 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
8719 | vty_out(vty, | |
8720 | "Please specify interface address by A.B.C.D\n"); | |
8721 | return CMD_WARNING_CONFIG_FAILED; | |
8722 | } | |
718e3744 | 8723 | |
d62a17ae | 8724 | params = ospf_get_if_params(ifp, addr); |
8725 | ospf_if_update_params(ifp, addr); | |
718e3744 | 8726 | } |
8727 | ||
d62a17ae | 8728 | SET_IF_PARAM(params, retransmit_interval); |
8729 | params->retransmit_interval = seconds; | |
718e3744 | 8730 | |
d62a17ae | 8731 | return CMD_SUCCESS; |
718e3744 | 8732 | } |
8733 | ||
7a7be519 | 8734 | DEFUN_HIDDEN (ospf_retransmit_interval, |
747e489c | 8735 | ospf_retransmit_interval_cmd, |
d4badaf6 | 8736 | "ospf retransmit-interval (1-65535) [A.B.C.D]", |
747e489c DW |
8737 | "OSPF interface commands\n" |
8738 | "Time between retransmitting lost link state advertisements\n" | |
3a2d747c | 8739 | "Seconds\n" |
efd7904e | 8740 | "Address of interface\n") |
7a7be519 | 8741 | { |
d62a17ae | 8742 | return ip_ospf_retransmit_interval(self, vty, argc, argv); |
7a7be519 | 8743 | } |
718e3744 | 8744 | |
8745 | DEFUN (no_ip_ospf_retransmit_interval, | |
8746 | no_ip_ospf_retransmit_interval_addr_cmd, | |
d4badaf6 | 8747 | "no ip ospf retransmit-interval [(1-65535)] [A.B.C.D]", |
718e3744 | 8748 | NO_STR |
8749 | "IP Information\n" | |
8750 | "OSPF interface commands\n" | |
3a2d747c QY |
8751 | "Time between retransmitting lost link state advertisements\n" |
8752 | "Seconds\n" | |
0d829fa7 | 8753 | "Address of interface\n") |
718e3744 | 8754 | { |
d62a17ae | 8755 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8756 | int idx = 0; | |
8757 | struct in_addr addr; | |
8758 | struct ospf_if_params *params; | |
47b91972 | 8759 | |
d62a17ae | 8760 | params = IF_DEF_PARAMS(ifp); |
718e3744 | 8761 | |
d62a17ae | 8762 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { |
8763 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
8764 | vty_out(vty, | |
8765 | "Please specify interface address by A.B.C.D\n"); | |
8766 | return CMD_WARNING_CONFIG_FAILED; | |
8767 | } | |
718e3744 | 8768 | |
d62a17ae | 8769 | params = ospf_lookup_if_params(ifp, addr); |
8770 | if (params == NULL) | |
8771 | return CMD_SUCCESS; | |
8772 | } | |
718e3744 | 8773 | |
d62a17ae | 8774 | UNSET_IF_PARAM(params, retransmit_interval); |
8775 | params->retransmit_interval = OSPF_RETRANSMIT_INTERVAL_DEFAULT; | |
718e3744 | 8776 | |
d62a17ae | 8777 | if (params != IF_DEF_PARAMS(ifp)) { |
8778 | ospf_free_if_params(ifp, addr); | |
8779 | ospf_if_update_params(ifp, addr); | |
8780 | } | |
718e3744 | 8781 | |
d62a17ae | 8782 | return CMD_SUCCESS; |
718e3744 | 8783 | } |
8784 | ||
0d829fa7 QY |
8785 | DEFUN_HIDDEN (no_ospf_retransmit_interval, |
8786 | no_ospf_retransmit_interval_cmd, | |
d4badaf6 | 8787 | "no ospf retransmit-interval [(1-65535)] [A.B.C.D]", |
0d829fa7 QY |
8788 | NO_STR |
8789 | "OSPF interface commands\n" | |
3a2d747c QY |
8790 | "Time between retransmitting lost link state advertisements\n" |
8791 | "Seconds\n" | |
8792 | "Address of interface\n") | |
0d829fa7 | 8793 | { |
d62a17ae | 8794 | return no_ip_ospf_retransmit_interval(self, vty, argc, argv); |
0d829fa7 | 8795 | } |
813d4307 | 8796 | |
718e3744 | 8797 | DEFUN (ip_ospf_transmit_delay, |
8798 | ip_ospf_transmit_delay_addr_cmd, | |
7a7be519 | 8799 | "ip ospf transmit-delay (1-65535) [A.B.C.D]", |
718e3744 | 8800 | "IP Information\n" |
8801 | "OSPF interface commands\n" | |
8802 | "Link state transmit delay\n" | |
8803 | "Seconds\n" | |
efd7904e | 8804 | "Address of interface\n") |
718e3744 | 8805 | { |
d62a17ae | 8806 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8807 | int idx = 0; | |
d7c0a89a | 8808 | uint32_t seconds; |
d62a17ae | 8809 | struct in_addr addr; |
8810 | struct ospf_if_params *params; | |
8811 | ||
8812 | params = IF_DEF_PARAMS(ifp); | |
8813 | argv_find(argv, argc, "(1-65535)", &idx); | |
8814 | seconds = strtol(argv[idx]->arg, NULL, 10); | |
8815 | ||
8816 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
8817 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
8818 | vty_out(vty, | |
8819 | "Please specify interface address by A.B.C.D\n"); | |
8820 | return CMD_WARNING_CONFIG_FAILED; | |
8821 | } | |
718e3744 | 8822 | |
d62a17ae | 8823 | params = ospf_get_if_params(ifp, addr); |
8824 | ospf_if_update_params(ifp, addr); | |
718e3744 | 8825 | } |
8826 | ||
d62a17ae | 8827 | SET_IF_PARAM(params, transmit_delay); |
8828 | params->transmit_delay = seconds; | |
718e3744 | 8829 | |
d62a17ae | 8830 | return CMD_SUCCESS; |
718e3744 | 8831 | } |
8832 | ||
7a7be519 | 8833 | DEFUN_HIDDEN (ospf_transmit_delay, |
747e489c | 8834 | ospf_transmit_delay_cmd, |
0d829fa7 | 8835 | "ospf transmit-delay (1-65535) [A.B.C.D]", |
747e489c DW |
8836 | "OSPF interface commands\n" |
8837 | "Link state transmit delay\n" | |
3a2d747c | 8838 | "Seconds\n" |
efd7904e | 8839 | "Address of interface\n") |
7a7be519 | 8840 | { |
d62a17ae | 8841 | return ip_ospf_transmit_delay(self, vty, argc, argv); |
7a7be519 | 8842 | } |
718e3744 | 8843 | |
8844 | DEFUN (no_ip_ospf_transmit_delay, | |
8845 | no_ip_ospf_transmit_delay_addr_cmd, | |
0d829fa7 | 8846 | "no ip ospf transmit-delay [(1-65535)] [A.B.C.D]", |
718e3744 | 8847 | NO_STR |
8848 | "IP Information\n" | |
8849 | "OSPF interface commands\n" | |
8850 | "Link state transmit delay\n" | |
efd7904e RW |
8851 | "Seconds\n" |
8852 | "Address of interface\n") | |
718e3744 | 8853 | { |
d62a17ae | 8854 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8855 | int idx = 0; | |
8856 | struct in_addr addr; | |
8857 | struct ospf_if_params *params; | |
718e3744 | 8858 | |
d62a17ae | 8859 | params = IF_DEF_PARAMS(ifp); |
718e3744 | 8860 | |
d62a17ae | 8861 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { |
8862 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
8863 | vty_out(vty, | |
8864 | "Please specify interface address by A.B.C.D\n"); | |
8865 | return CMD_WARNING_CONFIG_FAILED; | |
8866 | } | |
718e3744 | 8867 | |
d62a17ae | 8868 | params = ospf_lookup_if_params(ifp, addr); |
8869 | if (params == NULL) | |
8870 | return CMD_SUCCESS; | |
8871 | } | |
718e3744 | 8872 | |
d62a17ae | 8873 | UNSET_IF_PARAM(params, transmit_delay); |
8874 | params->transmit_delay = OSPF_TRANSMIT_DELAY_DEFAULT; | |
718e3744 | 8875 | |
d62a17ae | 8876 | if (params != IF_DEF_PARAMS(ifp)) { |
8877 | ospf_free_if_params(ifp, addr); | |
8878 | ospf_if_update_params(ifp, addr); | |
8879 | } | |
8880 | ||
8881 | return CMD_SUCCESS; | |
718e3744 | 8882 | } |
8883 | ||
813d4307 | 8884 | |
0d829fa7 QY |
8885 | DEFUN_HIDDEN (no_ospf_transmit_delay, |
8886 | no_ospf_transmit_delay_cmd, | |
32573073 | 8887 | "no ospf transmit-delay [(1-65535) [A.B.C.D]]", |
0d829fa7 QY |
8888 | NO_STR |
8889 | "OSPF interface commands\n" | |
32573073 QY |
8890 | "Link state transmit delay\n" |
8891 | "Seconds\n" | |
efd7904e | 8892 | "Address of interface\n") |
813d4307 | 8893 | { |
d62a17ae | 8894 | return no_ip_ospf_transmit_delay(self, vty, argc, argv); |
813d4307 DW |
8895 | } |
8896 | ||
e723861d DS |
8897 | DEFUN (ip_ospf_area, |
8898 | ip_ospf_area_cmd, | |
52c62ab8 | 8899 | "ip ospf [(1-65535)] area <A.B.C.D|(0-4294967295)> [A.B.C.D]", |
e723861d DS |
8900 | "IP Information\n" |
8901 | "OSPF interface commands\n" | |
7a7be519 | 8902 | "Instance ID\n" |
e723861d DS |
8903 | "Enable OSPF on this interface\n" |
8904 | "OSPF area ID in IP address format\n" | |
52c62ab8 JAG |
8905 | "OSPF area ID as a decimal value\n" |
8906 | "Address of interface\n") | |
e723861d | 8907 | { |
d62a17ae | 8908 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8909 | int idx = 0; | |
8910 | int format, ret; | |
8911 | struct in_addr area_id; | |
8912 | struct in_addr addr; | |
35955c14 | 8913 | struct ospf_if_params *params = NULL; |
d62a17ae | 8914 | struct route_node *rn; |
b5a8894d | 8915 | struct ospf *ospf = NULL; |
d7c0a89a | 8916 | unsigned short instance = 0; |
d62a17ae | 8917 | char *areaid; |
15bf52d3 | 8918 | uint32_t count = 0; |
d62a17ae | 8919 | |
8920 | if (argv_find(argv, argc, "(1-65535)", &idx)) | |
8921 | instance = strtol(argv[idx]->arg, NULL, 10); | |
8922 | ||
8923 | argv_find(argv, argc, "area", &idx); | |
8924 | areaid = argv[idx + 1]->arg; | |
8925 | ||
b56114aa | 8926 | if (!instance) |
a36898e7 | 8927 | ospf = ospf_lookup_by_vrf_id(ifp->vrf_id); |
b5a8894d CS |
8928 | else |
8929 | ospf = ospf_lookup_instance(instance); | |
8930 | ||
409f98ab | 8931 | if (instance && instance != ospf_instance) { |
2b0a32da DS |
8932 | /* |
8933 | * At this point we know we have received | |
8934 | * an instance and there is no ospf instance | |
8935 | * associated with it. This means we are | |
8936 | * in a situation where we have an | |
8937 | * ospf command that is setup for a different | |
8938 | * process(instance). We need to safely | |
8939 | * remove the command from ourselves and | |
8940 | * allow the other instance(process) handle | |
8941 | * the configuration command. | |
8942 | */ | |
15bf52d3 IR |
8943 | count = 0; |
8944 | ||
d62a17ae | 8945 | params = IF_DEF_PARAMS(ifp); |
8946 | if (OSPF_IF_PARAM_CONFIGURED(params, if_area)) { | |
8947 | UNSET_IF_PARAM(params, if_area); | |
15bf52d3 IR |
8948 | count++; |
8949 | } | |
8950 | ||
8951 | for (rn = route_top(IF_OIFS_PARAMS(ifp)); rn; rn = route_next(rn)) | |
8952 | if ((params = rn->info) && OSPF_IF_PARAM_CONFIGURED(params, if_area)) { | |
8953 | UNSET_IF_PARAM(params, if_area); | |
8954 | count++; | |
8955 | } | |
8956 | ||
8957 | if (count > 0) { | |
8958 | ospf = ospf_lookup_by_vrf_id(ifp->vrf_id); | |
cbf32f74 | 8959 | if (ospf) |
2b0a32da | 8960 | ospf_interface_area_unset(ospf, ifp); |
d62a17ae | 8961 | } |
15bf52d3 | 8962 | |
ac28e4ec | 8963 | return CMD_NOT_MY_INSTANCE; |
d62a17ae | 8964 | } |
e723861d | 8965 | |
d62a17ae | 8966 | ret = str2area_id(areaid, &area_id, &format); |
8967 | if (ret < 0) { | |
8968 | vty_out(vty, "Please specify area by A.B.C.D|<0-4294967295>\n"); | |
8969 | return CMD_WARNING_CONFIG_FAILED; | |
8970 | } | |
8971 | if (memcmp(ifp->name, "VLINK", 5) == 0) { | |
8972 | vty_out(vty, "Cannot enable OSPF on a virtual link.\n"); | |
8973 | return CMD_WARNING_CONFIG_FAILED; | |
8974 | } | |
8975 | ||
eb364867 IR |
8976 | if (ospf) { |
8977 | for (rn = route_top(ospf->networks); rn; rn = route_next(rn)) { | |
8978 | if (rn->info != NULL) { | |
8979 | vty_out(vty, | |
8980 | "Please remove all network commands first.\n"); | |
8981 | return CMD_WARNING_CONFIG_FAILED; | |
8982 | } | |
8983 | } | |
8984 | } | |
8985 | ||
d62a17ae | 8986 | params = IF_DEF_PARAMS(ifp); |
8987 | if (OSPF_IF_PARAM_CONFIGURED(params, if_area) | |
8988 | && !IPV4_ADDR_SAME(¶ms->if_area, &area_id)) { | |
8989 | vty_out(vty, | |
8990 | "Must remove previous area config before changing ospf area \n"); | |
8991 | return CMD_WARNING_CONFIG_FAILED; | |
8992 | } | |
8993 | ||
8994 | // Check if we have an address arg and proccess it | |
8995 | if (argc == idx + 3) { | |
cc9b06ad | 8996 | if (!inet_aton(argv[idx + 2]->arg, &addr)) { |
996c9314 LB |
8997 | vty_out(vty, |
8998 | "Please specify Intf Address by A.B.C.D\n"); | |
cc9b06ad DS |
8999 | return CMD_WARNING_CONFIG_FAILED; |
9000 | } | |
d62a17ae | 9001 | // update/create address-level params |
9002 | params = ospf_get_if_params((ifp), (addr)); | |
9003 | if (OSPF_IF_PARAM_CONFIGURED(params, if_area)) { | |
a900cece IR |
9004 | if (!IPV4_ADDR_SAME(¶ms->if_area, &area_id)) { |
9005 | vty_out(vty, | |
9006 | "Must remove previous area/address config before changing ospf area\n"); | |
9007 | return CMD_WARNING_CONFIG_FAILED; | |
9008 | } else | |
9009 | return CMD_SUCCESS; | |
d62a17ae | 9010 | } |
9011 | ospf_if_update_params((ifp), (addr)); | |
9012 | } | |
9013 | ||
d62a17ae | 9014 | /* enable ospf on this interface with area_id */ |
35955c14 CS |
9015 | if (params) { |
9016 | SET_IF_PARAM(params, if_area); | |
9017 | params->if_area = area_id; | |
9018 | params->if_area_id_fmt = format; | |
9019 | } | |
aed7cc62 | 9020 | |
cbf32f74 | 9021 | if (ospf) |
aed7cc62 | 9022 | ospf_interface_area_set(ospf, ifp); |
d62a17ae | 9023 | |
9024 | return CMD_SUCCESS; | |
e723861d DS |
9025 | } |
9026 | ||
9027 | DEFUN (no_ip_ospf_area, | |
9028 | no_ip_ospf_area_cmd, | |
52c62ab8 | 9029 | "no ip ospf [(1-65535)] area [<A.B.C.D|(0-4294967295)> [A.B.C.D]]", |
e723861d DS |
9030 | NO_STR |
9031 | "IP Information\n" | |
9032 | "OSPF interface commands\n" | |
3a2d747c | 9033 | "Instance ID\n" |
7a7be519 | 9034 | "Disable OSPF on this interface\n" |
9035 | "OSPF area ID in IP address format\n" | |
52c62ab8 JAG |
9036 | "OSPF area ID as a decimal value\n" |
9037 | "Address of interface\n") | |
e723861d | 9038 | { |
d62a17ae | 9039 | VTY_DECLVAR_CONTEXT(interface, ifp); |
9040 | int idx = 0; | |
9041 | struct ospf *ospf; | |
9042 | struct ospf_if_params *params; | |
d7c0a89a | 9043 | unsigned short instance = 0; |
d62a17ae | 9044 | struct in_addr addr; |
58e5d140 | 9045 | struct in_addr area_id; |
d62a17ae | 9046 | |
9047 | if (argv_find(argv, argc, "(1-65535)", &idx)) | |
9048 | instance = strtol(argv[idx]->arg, NULL, 10); | |
9049 | ||
b56114aa | 9050 | if (!instance) |
a36898e7 | 9051 | ospf = ospf_lookup_by_vrf_id(ifp->vrf_id); |
b5a8894d CS |
9052 | else |
9053 | ospf = ospf_lookup_instance(instance); | |
9054 | ||
409f98ab | 9055 | if (instance && instance != ospf_instance) |
ac28e4ec | 9056 | return CMD_NOT_MY_INSTANCE; |
d62a17ae | 9057 | |
9058 | argv_find(argv, argc, "area", &idx); | |
9059 | ||
9060 | // Check if we have an address arg and proccess it | |
9061 | if (argc == idx + 3) { | |
cc9b06ad | 9062 | if (!inet_aton(argv[idx + 2]->arg, &addr)) { |
996c9314 LB |
9063 | vty_out(vty, |
9064 | "Please specify Intf Address by A.B.C.D\n"); | |
cc9b06ad DS |
9065 | return CMD_WARNING_CONFIG_FAILED; |
9066 | } | |
d62a17ae | 9067 | params = ospf_lookup_if_params(ifp, addr); |
9068 | if ((params) == NULL) | |
9069 | return CMD_SUCCESS; | |
9070 | } else | |
9071 | params = IF_DEF_PARAMS(ifp); | |
9072 | ||
58e5d140 | 9073 | area_id = params->if_area; |
d62a17ae | 9074 | if (!OSPF_IF_PARAM_CONFIGURED(params, if_area)) { |
9075 | vty_out(vty, | |
9076 | "Can't find specified interface area configuration.\n"); | |
9077 | return CMD_WARNING_CONFIG_FAILED; | |
9078 | } | |
813d4307 | 9079 | |
d62a17ae | 9080 | UNSET_IF_PARAM(params, if_area); |
9081 | if (params != IF_DEF_PARAMS((ifp))) { | |
9082 | ospf_free_if_params((ifp), (addr)); | |
9083 | ospf_if_update_params((ifp), (addr)); | |
9084 | } | |
9085 | ||
e4129293 IR |
9086 | if (ospf) { |
9087 | ospf_interface_area_unset(ospf, ifp); | |
58e5d140 | 9088 | ospf_area_check_free(ospf, area_id); |
e4129293 IR |
9089 | } |
9090 | ||
d62a17ae | 9091 | return CMD_SUCCESS; |
813d4307 DW |
9092 | } |
9093 | ||
3eec4ee0 IR |
9094 | DEFUN (ip_ospf_passive, |
9095 | ip_ospf_passive_cmd, | |
9096 | "ip ospf passive [A.B.C.D]", | |
9097 | "IP Information\n" | |
9098 | "OSPF interface commands\n" | |
9099 | "Suppress routing updates on an interface\n" | |
9100 | "Address of interface\n") | |
9101 | { | |
9102 | VTY_DECLVAR_CONTEXT(interface, ifp); | |
9103 | int idx_ipv4 = 3; | |
82f0277b | 9104 | struct in_addr addr = {.s_addr = INADDR_ANY}; |
3eec4ee0 IR |
9105 | struct ospf_if_params *params; |
9106 | int ret; | |
9107 | ||
9108 | if (argc == 4) { | |
9109 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
9110 | if (!ret) { | |
9111 | vty_out(vty, | |
9112 | "Please specify interface address by A.B.C.D\n"); | |
9113 | return CMD_WARNING_CONFIG_FAILED; | |
9114 | } | |
9115 | params = ospf_get_if_params(ifp, addr); | |
9116 | ospf_if_update_params(ifp, addr); | |
9117 | } else { | |
9118 | params = IF_DEF_PARAMS(ifp); | |
9119 | } | |
9120 | ||
82f0277b | 9121 | ospf_passive_interface_update(ifp, params, addr, OSPF_IF_PASSIVE); |
3eec4ee0 IR |
9122 | |
9123 | return CMD_SUCCESS; | |
9124 | } | |
9125 | ||
9126 | DEFUN (no_ip_ospf_passive, | |
9127 | no_ip_ospf_passive_cmd, | |
9128 | "no ip ospf passive [A.B.C.D]", | |
9129 | NO_STR | |
9130 | "IP Information\n" | |
9131 | "OSPF interface commands\n" | |
9132 | "Enable routing updates on an interface\n" | |
9133 | "Address of interface\n") | |
9134 | { | |
9135 | VTY_DECLVAR_CONTEXT(interface, ifp); | |
9136 | int idx_ipv4 = 4; | |
82f0277b | 9137 | struct in_addr addr = {.s_addr = INADDR_ANY}; |
3eec4ee0 IR |
9138 | struct ospf_if_params *params; |
9139 | int ret; | |
9140 | ||
9141 | if (argc == 5) { | |
9142 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
9143 | if (!ret) { | |
9144 | vty_out(vty, | |
9145 | "Please specify interface address by A.B.C.D\n"); | |
9146 | return CMD_WARNING_CONFIG_FAILED; | |
9147 | } | |
9148 | params = ospf_lookup_if_params(ifp, addr); | |
9149 | if (params == NULL) | |
9150 | return CMD_SUCCESS; | |
9151 | } else { | |
9152 | params = IF_DEF_PARAMS(ifp); | |
9153 | } | |
9154 | ||
82f0277b | 9155 | ospf_passive_interface_update(ifp, params, addr, OSPF_IF_ACTIVE); |
3eec4ee0 IR |
9156 | |
9157 | return CMD_SUCCESS; | |
9158 | } | |
9159 | ||
6f2a6703 CF |
9160 | DEFUN (ospf_redistribute_source, |
9161 | ospf_redistribute_source_cmd, | |
ea38ced1 | 9162 | "redistribute " FRR_REDIST_STR_OSPFD " [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]", |
d1c65c21 | 9163 | REDIST_STR |
ab0181ee | 9164 | FRR_REDIST_HELP_STR_OSPFD |
718e3744 | 9165 | "Metric for redistributed routes\n" |
9166 | "OSPF default metric\n" | |
9167 | "OSPF exterior metric type for redistributed routes\n" | |
7111c1a0 | 9168 | "Set OSPF External Type 1/2 metrics\n" |
718e3744 | 9169 | "Route map reference\n" |
9170 | "Pointer to route-map entries\n") | |
9171 | { | |
a3d826f0 | 9172 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 9173 | int idx_protocol = 1; |
9174 | int source; | |
9175 | int type = -1; | |
9176 | int metric = -1; | |
9177 | struct ospf_redist *red; | |
9178 | int idx = 0; | |
7bced643 | 9179 | bool update = false; |
6f2a6703 | 9180 | |
d62a17ae | 9181 | /* Get distribute source. */ |
9182 | source = proto_redistnum(AFI_IP, argv[idx_protocol]->text); | |
9183 | if (source < 0) | |
9184 | return CMD_WARNING_CONFIG_FAILED; | |
9185 | ||
d62a17ae | 9186 | /* Get metric value. */ |
9187 | if (argv_find(argv, argc, "(0-16777214)", &idx)) { | |
9188 | if (!str2metric(argv[idx]->arg, &metric)) | |
9189 | return CMD_WARNING_CONFIG_FAILED; | |
9190 | } | |
951da435 | 9191 | idx = 1; |
d62a17ae | 9192 | /* Get metric type. */ |
ea38ced1 | 9193 | if (argv_find(argv, argc, "(1-2)", &idx)) { |
d62a17ae | 9194 | if (!str2metric_type(argv[idx]->arg, &type)) |
9195 | return CMD_WARNING_CONFIG_FAILED; | |
9196 | } | |
951da435 | 9197 | idx = 1; |
7bced643 IR |
9198 | |
9199 | red = ospf_redist_lookup(ospf, source, 0); | |
9200 | if (!red) | |
9201 | red = ospf_redist_add(ospf, source, 0); | |
9202 | else | |
9203 | update = true; | |
9204 | ||
d62a17ae | 9205 | /* Get route-map */ |
ea38ced1 | 9206 | if (argv_find(argv, argc, "WORD", &idx)) { |
d62a17ae | 9207 | ospf_routemap_set(red, argv[idx]->arg); |
9208 | } else | |
9209 | ospf_routemap_unset(red); | |
7c8ff89e | 9210 | |
7bced643 IR |
9211 | if (update) |
9212 | return ospf_redistribute_update(ospf, red, source, 0, type, | |
9213 | metric); | |
9214 | else | |
9215 | return ospf_redistribute_set(ospf, red, source, 0, type, | |
9216 | metric); | |
718e3744 | 9217 | } |
9218 | ||
718e3744 | 9219 | DEFUN (no_ospf_redistribute_source, |
9220 | no_ospf_redistribute_source_cmd, | |
ea38ced1 | 9221 | "no redistribute " FRR_REDIST_STR_OSPFD " [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]", |
718e3744 | 9222 | NO_STR |
d1c65c21 | 9223 | REDIST_STR |
ab0181ee | 9224 | FRR_REDIST_HELP_STR_OSPFD |
813d4307 DW |
9225 | "Metric for redistributed routes\n" |
9226 | "OSPF default metric\n" | |
9227 | "OSPF exterior metric type for redistributed routes\n" | |
7111c1a0 | 9228 | "Set OSPF External Type 1/2 metrics\n" |
813d4307 DW |
9229 | "Route map reference\n" |
9230 | "Pointer to route-map entries\n") | |
718e3744 | 9231 | { |
a3d826f0 | 9232 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 9233 | int idx_protocol = 2; |
9234 | int source; | |
9235 | struct ospf_redist *red; | |
718e3744 | 9236 | |
d62a17ae | 9237 | source = proto_redistnum(AFI_IP, argv[idx_protocol]->text); |
9238 | if (source < 0) | |
9239 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 9240 | |
d62a17ae | 9241 | red = ospf_redist_lookup(ospf, source, 0); |
9242 | if (!red) | |
9243 | return CMD_SUCCESS; | |
7c8ff89e | 9244 | |
d62a17ae | 9245 | ospf_routemap_unset(red); |
766b826f DA |
9246 | ospf_redist_del(ospf, source, 0); |
9247 | ||
d62a17ae | 9248 | return ospf_redistribute_unset(ospf, source, 0); |
7c8ff89e DS |
9249 | } |
9250 | ||
9251 | DEFUN (ospf_redistribute_instance_source, | |
9252 | ospf_redistribute_instance_source_cmd, | |
1a5ce38b | 9253 | "redistribute <ospf|table> (1-65535) [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]", |
7c8ff89e DS |
9254 | REDIST_STR |
9255 | "Open Shortest Path First\n" | |
2d627ff5 DS |
9256 | "Non-main Kernel Routing Table\n" |
9257 | "Instance ID/Table ID\n" | |
7c8ff89e DS |
9258 | "Metric for redistributed routes\n" |
9259 | "OSPF default metric\n" | |
9260 | "OSPF exterior metric type for redistributed routes\n" | |
7111c1a0 | 9261 | "Set OSPF External Type 1/2 metrics\n" |
7c8ff89e DS |
9262 | "Route map reference\n" |
9263 | "Pointer to route-map entries\n") | |
9264 | { | |
a3d826f0 | 9265 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 9266 | int idx_ospf_table = 1; |
9267 | int idx_number = 2; | |
9268 | int idx = 3; | |
9269 | int source; | |
9270 | int type = -1; | |
9271 | int metric = -1; | |
d7c0a89a | 9272 | unsigned short instance; |
d62a17ae | 9273 | struct ospf_redist *red; |
7bced643 | 9274 | bool update = false; |
7c8ff89e | 9275 | |
d62a17ae | 9276 | source = proto_redistnum(AFI_IP, argv[idx_ospf_table]->text); |
2d627ff5 | 9277 | |
13f0e434 | 9278 | if (source < 0) { |
9279 | vty_out(vty, "Unknown instance redistribution\n"); | |
9280 | return CMD_WARNING_CONFIG_FAILED; | |
9281 | } | |
9282 | ||
d62a17ae | 9283 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
7c8ff89e | 9284 | |
d62a17ae | 9285 | if ((source == ZEBRA_ROUTE_OSPF) && !ospf->instance) { |
9286 | vty_out(vty, | |
9287 | "Instance redistribution in non-instanced OSPF not allowed\n"); | |
9288 | return CMD_WARNING_CONFIG_FAILED; | |
9289 | } | |
7c8ff89e | 9290 | |
d62a17ae | 9291 | if ((source == ZEBRA_ROUTE_OSPF) && (ospf->instance == instance)) { |
9292 | vty_out(vty, "Same instance OSPF redistribution not allowed\n"); | |
9293 | return CMD_WARNING_CONFIG_FAILED; | |
9294 | } | |
7c8ff89e | 9295 | |
d62a17ae | 9296 | /* Get metric value. */ |
9297 | if (argv_find(argv, argc, "metric", &idx)) | |
9298 | if (!str2metric(argv[idx + 1]->arg, &metric)) | |
9299 | return CMD_WARNING_CONFIG_FAILED; | |
7c8ff89e | 9300 | |
d62a17ae | 9301 | idx = 3; |
9302 | /* Get metric type. */ | |
9303 | if (argv_find(argv, argc, "metric-type", &idx)) | |
9304 | if (!str2metric_type(argv[idx + 1]->arg, &type)) | |
9305 | return CMD_WARNING_CONFIG_FAILED; | |
7c8ff89e | 9306 | |
7bced643 IR |
9307 | red = ospf_redist_lookup(ospf, source, instance); |
9308 | if (!red) | |
9309 | red = ospf_redist_add(ospf, source, instance); | |
9310 | else | |
9311 | update = true; | |
7a7be519 | 9312 | |
d62a17ae | 9313 | idx = 3; |
9314 | if (argv_find(argv, argc, "route-map", &idx)) | |
9315 | ospf_routemap_set(red, argv[idx + 1]->arg); | |
9316 | else | |
9317 | ospf_routemap_unset(red); | |
7c8ff89e | 9318 | |
7bced643 IR |
9319 | if (update) |
9320 | return ospf_redistribute_update(ospf, red, source, instance, | |
9321 | type, metric); | |
9322 | else | |
9323 | return ospf_redistribute_set(ospf, red, source, instance, type, | |
9324 | metric); | |
7c8ff89e DS |
9325 | } |
9326 | ||
9327 | DEFUN (no_ospf_redistribute_instance_source, | |
9328 | no_ospf_redistribute_instance_source_cmd, | |
1a5ce38b | 9329 | "no redistribute <ospf|table> (1-65535) [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]", |
7c8ff89e DS |
9330 | NO_STR |
9331 | REDIST_STR | |
9332 | "Open Shortest Path First\n" | |
2d627ff5 DS |
9333 | "Non-main Kernel Routing Table\n" |
9334 | "Instance ID/Table Id\n" | |
7c8ff89e DS |
9335 | "Metric for redistributed routes\n" |
9336 | "OSPF default metric\n" | |
9337 | "OSPF exterior metric type for redistributed routes\n" | |
7111c1a0 | 9338 | "Set OSPF External Type 1/2 metrics\n" |
7c8ff89e DS |
9339 | "Route map reference\n" |
9340 | "Pointer to route-map entries\n") | |
9341 | { | |
a3d826f0 | 9342 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 9343 | int idx_ospf_table = 2; |
9344 | int idx_number = 3; | |
d7c0a89a | 9345 | unsigned int instance; |
d62a17ae | 9346 | struct ospf_redist *red; |
9347 | int source; | |
9348 | ||
9349 | if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0) | |
9350 | source = ZEBRA_ROUTE_OSPF; | |
9351 | else | |
9352 | source = ZEBRA_ROUTE_TABLE; | |
9353 | ||
9354 | instance = strtoul(argv[idx_number]->arg, NULL, 10); | |
7c8ff89e | 9355 | |
d62a17ae | 9356 | if ((source == ZEBRA_ROUTE_OSPF) && !ospf->instance) { |
9357 | vty_out(vty, | |
9358 | "Instance redistribution in non-instanced OSPF not allowed\n"); | |
9359 | return CMD_WARNING_CONFIG_FAILED; | |
9360 | } | |
9361 | ||
9362 | if ((source == ZEBRA_ROUTE_OSPF) && (ospf->instance == instance)) { | |
9363 | vty_out(vty, "Same instance OSPF redistribution not allowed\n"); | |
9364 | return CMD_WARNING_CONFIG_FAILED; | |
9365 | } | |
9366 | ||
9367 | red = ospf_redist_lookup(ospf, source, instance); | |
9368 | if (!red) | |
9369 | return CMD_SUCCESS; | |
9370 | ||
9371 | ospf_routemap_unset(red); | |
766b826f DA |
9372 | ospf_redist_del(ospf, source, instance); |
9373 | ||
d62a17ae | 9374 | return ospf_redistribute_unset(ospf, source, instance); |
718e3744 | 9375 | } |
9376 | ||
9377 | DEFUN (ospf_distribute_list_out, | |
9378 | ospf_distribute_list_out_cmd, | |
40d1cbfb | 9379 | "distribute-list WORD out " FRR_REDIST_STR_OSPFD, |
718e3744 | 9380 | "Filter networks in routing updates\n" |
6f2a6703 CF |
9381 | "Access-list name\n" |
9382 | OUT_STR | |
ab0181ee | 9383 | FRR_REDIST_HELP_STR_OSPFD) |
718e3744 | 9384 | { |
a3d826f0 | 9385 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 9386 | int idx_word = 1; |
9387 | int source; | |
718e3744 | 9388 | |
d62a17ae | 9389 | char *proto = argv[argc - 1]->text; |
6d681bd8 | 9390 | |
d62a17ae | 9391 | /* Get distribute source. */ |
9392 | source = proto_redistnum(AFI_IP, proto); | |
9393 | if (source < 0) | |
9394 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 9395 | |
d62a17ae | 9396 | return ospf_distribute_list_out_set(ospf, source, argv[idx_word]->arg); |
718e3744 | 9397 | } |
9398 | ||
6f2a6703 CF |
9399 | DEFUN (no_ospf_distribute_list_out, |
9400 | no_ospf_distribute_list_out_cmd, | |
40d1cbfb | 9401 | "no distribute-list WORD out " FRR_REDIST_STR_OSPFD, |
6f2a6703 CF |
9402 | NO_STR |
9403 | "Filter networks in routing updates\n" | |
9404 | "Access-list name\n" | |
9405 | OUT_STR | |
ab0181ee | 9406 | FRR_REDIST_HELP_STR_OSPFD) |
718e3744 | 9407 | { |
a3d826f0 | 9408 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 9409 | int idx_word = 2; |
9410 | int source; | |
020709f9 | 9411 | |
d62a17ae | 9412 | char *proto = argv[argc - 1]->text; |
9413 | source = proto_redistnum(AFI_IP, proto); | |
9414 | if (source < 0) | |
9415 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 9416 | |
d62a17ae | 9417 | return ospf_distribute_list_out_unset(ospf, source, |
9418 | argv[idx_word]->arg); | |
718e3744 | 9419 | } |
9420 | ||
6f2a6703 CF |
9421 | /* Default information originate. */ |
9422 | DEFUN (ospf_default_information_originate, | |
9423 | ospf_default_information_originate_cmd, | |
ea38ced1 | 9424 | "default-information originate [{always|metric (0-16777214)|metric-type (1-2)|route-map WORD}]", |
718e3744 | 9425 | "Control distribution of default information\n" |
9426 | "Distribute a default route\n" | |
9427 | "Always advertise default route\n" | |
6f2a6703 CF |
9428 | "OSPF default metric\n" |
9429 | "OSPF metric\n" | |
718e3744 | 9430 | "OSPF metric type for default routes\n" |
7111c1a0 | 9431 | "Set OSPF External Type 1/2 metrics\n" |
718e3744 | 9432 | "Route map reference\n" |
9433 | "Pointer to route-map entries\n") | |
9434 | { | |
a3d826f0 | 9435 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 9436 | int default_originate = DEFAULT_ORIGINATE_ZEBRA; |
9437 | int type = -1; | |
9438 | int metric = -1; | |
9439 | struct ospf_redist *red; | |
9440 | int idx = 0; | |
1fb93326 | 9441 | int cur_originate = ospf->default_originate; |
9442 | int sameRtmap = 0; | |
9443 | char *rtmap = NULL; | |
d62a17ae | 9444 | |
9445 | red = ospf_redist_add(ospf, DEFAULT_ROUTE, 0); | |
9446 | ||
9447 | /* Check whether "always" was specified */ | |
9448 | if (argv_find(argv, argc, "always", &idx)) | |
9449 | default_originate = DEFAULT_ORIGINATE_ALWAYS; | |
951da435 | 9450 | idx = 1; |
d62a17ae | 9451 | /* Get metric value */ |
ea38ced1 | 9452 | if (argv_find(argv, argc, "(0-16777214)", &idx)) { |
d62a17ae | 9453 | if (!str2metric(argv[idx]->arg, &metric)) |
9454 | return CMD_WARNING_CONFIG_FAILED; | |
9455 | } | |
951da435 | 9456 | idx = 1; |
d62a17ae | 9457 | /* Get metric type. */ |
ea38ced1 | 9458 | if (argv_find(argv, argc, "(1-2)", &idx)) { |
d62a17ae | 9459 | if (!str2metric_type(argv[idx]->arg, &type)) |
9460 | return CMD_WARNING_CONFIG_FAILED; | |
9461 | } | |
951da435 | 9462 | idx = 1; |
d62a17ae | 9463 | /* Get route-map */ |
ea38ced1 | 9464 | if (argv_find(argv, argc, "WORD", &idx)) |
1fb93326 | 9465 | rtmap = argv[idx]->arg; |
9466 | ||
9467 | /* To check ,if user is providing same route map */ | |
9468 | if ((rtmap == ROUTEMAP_NAME(red)) || | |
9469 | (rtmap && ROUTEMAP_NAME(red) | |
9470 | && (strcmp(rtmap, ROUTEMAP_NAME(red)) == 0))) | |
9471 | sameRtmap = 1; | |
9472 | ||
9473 | /* Don't allow if the same lsa is aleardy originated. */ | |
9474 | if ((sameRtmap) | |
9475 | && (red->dmetric.type == type) | |
9476 | && (red->dmetric.value == metric) | |
9477 | && (cur_originate == default_originate)) | |
9478 | return CMD_SUCCESS; | |
9479 | ||
9480 | /* Updating Metric details */ | |
9481 | red->dmetric.type = type; | |
9482 | red->dmetric.value = metric; | |
9483 | ||
9484 | /* updating route map details */ | |
9485 | if (rtmap) | |
9486 | ospf_routemap_set(red, rtmap); | |
d62a17ae | 9487 | else |
9488 | ospf_routemap_unset(red); | |
9489 | ||
9490 | return ospf_redistribute_default_set(ospf, default_originate, type, | |
9491 | metric); | |
718e3744 | 9492 | } |
9493 | ||
9494 | DEFUN (no_ospf_default_information_originate, | |
9495 | no_ospf_default_information_originate_cmd, | |
ea38ced1 | 9496 | "no default-information originate [{always|metric (0-16777214)|metric-type (1-2)|route-map WORD}]", |
718e3744 | 9497 | NO_STR |
9498 | "Control distribution of default information\n" | |
813d4307 DW |
9499 | "Distribute a default route\n" |
9500 | "Always advertise default route\n" | |
9501 | "OSPF default metric\n" | |
9502 | "OSPF metric\n" | |
9503 | "OSPF metric type for default routes\n" | |
7111c1a0 | 9504 | "Set OSPF External Type 1/2 metrics\n" |
813d4307 DW |
9505 | "Route map reference\n" |
9506 | "Pointer to route-map entries\n") | |
718e3744 | 9507 | { |
a3d826f0 | 9508 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 9509 | struct ospf_redist *red; |
7c8ff89e | 9510 | |
d62a17ae | 9511 | red = ospf_redist_lookup(ospf, DEFAULT_ROUTE, 0); |
9512 | if (!red) | |
9513 | return CMD_SUCCESS; | |
7c8ff89e | 9514 | |
d62a17ae | 9515 | ospf_routemap_unset(red); |
766b826f DA |
9516 | ospf_redist_del(ospf, DEFAULT_ROUTE, 0); |
9517 | ||
d5eac1e0 DL |
9518 | return ospf_redistribute_default_set(ospf, DEFAULT_ORIGINATE_NONE, |
9519 | 0, 0); | |
718e3744 | 9520 | } |
9521 | ||
9522 | DEFUN (ospf_default_metric, | |
9523 | ospf_default_metric_cmd, | |
6147e2c6 | 9524 | "default-metric (0-16777214)", |
718e3744 | 9525 | "Set metric of redistributed routes\n" |
9526 | "Default metric\n") | |
9527 | { | |
a3d826f0 | 9528 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 9529 | int idx_number = 1; |
9530 | int metric = -1; | |
718e3744 | 9531 | |
d62a17ae | 9532 | if (!str2metric(argv[idx_number]->arg, &metric)) |
9533 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 9534 | |
d62a17ae | 9535 | ospf->default_metric = metric; |
718e3744 | 9536 | |
d62a17ae | 9537 | return CMD_SUCCESS; |
718e3744 | 9538 | } |
9539 | ||
9540 | DEFUN (no_ospf_default_metric, | |
9541 | no_ospf_default_metric_cmd, | |
7a7be519 | 9542 | "no default-metric [(0-16777214)]", |
718e3744 | 9543 | NO_STR |
7a7be519 | 9544 | "Set metric of redistributed routes\n" |
9545 | "Default metric\n") | |
718e3744 | 9546 | { |
a3d826f0 | 9547 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
68980084 | 9548 | |
d62a17ae | 9549 | ospf->default_metric = -1; |
68980084 | 9550 | |
d62a17ae | 9551 | return CMD_SUCCESS; |
718e3744 | 9552 | } |
9553 | ||
718e3744 | 9554 | |
9555 | DEFUN (ospf_distance, | |
9556 | ospf_distance_cmd, | |
6147e2c6 | 9557 | "distance (1-255)", |
eaa1ae0d | 9558 | "Administrative distance\n" |
718e3744 | 9559 | "OSPF Administrative distance\n") |
9560 | { | |
a3d826f0 | 9561 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 9562 | int idx_number = 1; |
68980084 | 9563 | |
d62a17ae | 9564 | ospf->distance_all = atoi(argv[idx_number]->arg); |
68980084 | 9565 | |
d62a17ae | 9566 | return CMD_SUCCESS; |
718e3744 | 9567 | } |
9568 | ||
9569 | DEFUN (no_ospf_distance, | |
9570 | no_ospf_distance_cmd, | |
6147e2c6 | 9571 | "no distance (1-255)", |
718e3744 | 9572 | NO_STR |
eaa1ae0d | 9573 | "Administrative distance\n" |
718e3744 | 9574 | "OSPF Administrative distance\n") |
9575 | { | |
a3d826f0 | 9576 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
68980084 | 9577 | |
d62a17ae | 9578 | ospf->distance_all = 0; |
68980084 | 9579 | |
d62a17ae | 9580 | return CMD_SUCCESS; |
718e3744 | 9581 | } |
9582 | ||
9583 | DEFUN (no_ospf_distance_ospf, | |
9584 | no_ospf_distance_ospf_cmd, | |
eaa1ae0d | 9585 | "no distance ospf [{intra-area [(1-255)]|inter-area [(1-255)]|external [(1-255)]}]", |
718e3744 | 9586 | NO_STR |
eaa1ae0d QY |
9587 | "Administrative distance\n" |
9588 | "OSPF administrative distance\n" | |
718e3744 | 9589 | "Intra-area routes\n" |
813d4307 | 9590 | "Distance for intra-area routes\n" |
718e3744 | 9591 | "Inter-area routes\n" |
813d4307 DW |
9592 | "Distance for inter-area routes\n" |
9593 | "External routes\n" | |
9594 | "Distance for external routes\n") | |
718e3744 | 9595 | { |
a3d826f0 | 9596 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 9597 | int idx = 0; |
718e3744 | 9598 | |
d62a17ae | 9599 | if (argv_find(argv, argc, "intra-area", &idx) || argc == 3) |
9600 | idx = ospf->distance_intra = 0; | |
9601 | if (argv_find(argv, argc, "inter-area", &idx) || argc == 3) | |
9602 | idx = ospf->distance_inter = 0; | |
9603 | if (argv_find(argv, argc, "external", &idx) || argc == 3) | |
9604 | ospf->distance_external = 0; | |
718e3744 | 9605 | |
d62a17ae | 9606 | return CMD_SUCCESS; |
718e3744 | 9607 | } |
9608 | ||
6f2a6703 CF |
9609 | DEFUN (ospf_distance_ospf, |
9610 | ospf_distance_ospf_cmd, | |
eaa1ae0d QY |
9611 | "distance ospf {intra-area (1-255)|inter-area (1-255)|external (1-255)}", |
9612 | "Administrative distance\n" | |
9613 | "OSPF administrative distance\n" | |
718e3744 | 9614 | "Intra-area routes\n" |
9615 | "Distance for intra-area routes\n" | |
718e3744 | 9616 | "Inter-area routes\n" |
9617 | "Distance for inter-area routes\n" | |
9618 | "External routes\n" | |
718e3744 | 9619 | "Distance for external routes\n") |
9620 | { | |
a3d826f0 | 9621 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 9622 | int idx = 0; |
68980084 | 9623 | |
926b88f0 CS |
9624 | ospf->distance_intra = 0; |
9625 | ospf->distance_inter = 0; | |
9626 | ospf->distance_external = 0; | |
9627 | ||
d62a17ae | 9628 | if (argv_find(argv, argc, "intra-area", &idx)) |
9629 | ospf->distance_intra = atoi(argv[idx + 1]->arg); | |
9630 | idx = 0; | |
9631 | if (argv_find(argv, argc, "inter-area", &idx)) | |
9632 | ospf->distance_inter = atoi(argv[idx + 1]->arg); | |
9633 | idx = 0; | |
9634 | if (argv_find(argv, argc, "external", &idx)) | |
9635 | ospf->distance_external = atoi(argv[idx + 1]->arg); | |
68980084 | 9636 | |
d62a17ae | 9637 | return CMD_SUCCESS; |
718e3744 | 9638 | } |
9639 | ||
ba682537 | 9640 | DEFUN (ip_ospf_mtu_ignore, |
9641 | ip_ospf_mtu_ignore_addr_cmd, | |
7a7be519 | 9642 | "ip ospf mtu-ignore [A.B.C.D]", |
ba682537 | 9643 | "IP Information\n" |
9644 | "OSPF interface commands\n" | |
99a522c7 | 9645 | "Disable MTU mismatch detection on this interface\n" |
efd7904e | 9646 | "Address of interface\n") |
ba682537 | 9647 | { |
d62a17ae | 9648 | VTY_DECLVAR_CONTEXT(interface, ifp); |
9649 | int idx_ipv4 = 3; | |
9650 | struct in_addr addr; | |
9651 | int ret; | |
9652 | ||
9653 | struct ospf_if_params *params; | |
9654 | params = IF_DEF_PARAMS(ifp); | |
9655 | ||
9656 | if (argc == 4) { | |
9657 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
9658 | if (!ret) { | |
9659 | vty_out(vty, | |
9660 | "Please specify interface address by A.B.C.D\n"); | |
9661 | return CMD_WARNING_CONFIG_FAILED; | |
9662 | } | |
9663 | params = ospf_get_if_params(ifp, addr); | |
9664 | ospf_if_update_params(ifp, addr); | |
9665 | } | |
9666 | params->mtu_ignore = 1; | |
9667 | if (params->mtu_ignore != OSPF_MTU_IGNORE_DEFAULT) | |
9668 | SET_IF_PARAM(params, mtu_ignore); | |
9669 | else { | |
9670 | UNSET_IF_PARAM(params, mtu_ignore); | |
9671 | if (params != IF_DEF_PARAMS(ifp)) { | |
9672 | ospf_free_if_params(ifp, addr); | |
9673 | ospf_if_update_params(ifp, addr); | |
9674 | } | |
9675 | } | |
9676 | return CMD_SUCCESS; | |
ba682537 | 9677 | } |
9678 | ||
ba682537 | 9679 | DEFUN (no_ip_ospf_mtu_ignore, |
9680 | no_ip_ospf_mtu_ignore_addr_cmd, | |
7a7be519 | 9681 | "no ip ospf mtu-ignore [A.B.C.D]", |
efd7904e | 9682 | NO_STR |
ba682537 | 9683 | "IP Information\n" |
9684 | "OSPF interface commands\n" | |
99a522c7 | 9685 | "Disable MTU mismatch detection on this interface\n" |
efd7904e | 9686 | "Address of interface\n") |
ba682537 | 9687 | { |
d62a17ae | 9688 | VTY_DECLVAR_CONTEXT(interface, ifp); |
9689 | int idx_ipv4 = 4; | |
9690 | struct in_addr addr; | |
9691 | int ret; | |
9692 | ||
9693 | struct ospf_if_params *params; | |
9694 | params = IF_DEF_PARAMS(ifp); | |
9695 | ||
9696 | if (argc == 5) { | |
9697 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
9698 | if (!ret) { | |
9699 | vty_out(vty, | |
9700 | "Please specify interface address by A.B.C.D\n"); | |
9701 | return CMD_WARNING_CONFIG_FAILED; | |
9702 | } | |
9703 | params = ospf_get_if_params(ifp, addr); | |
9704 | ospf_if_update_params(ifp, addr); | |
9705 | } | |
9706 | params->mtu_ignore = 0; | |
9707 | if (params->mtu_ignore != OSPF_MTU_IGNORE_DEFAULT) | |
9708 | SET_IF_PARAM(params, mtu_ignore); | |
9709 | else { | |
9710 | UNSET_IF_PARAM(params, mtu_ignore); | |
9711 | if (params != IF_DEF_PARAMS(ifp)) { | |
9712 | ospf_free_if_params(ifp, addr); | |
9713 | ospf_if_update_params(ifp, addr); | |
9714 | } | |
9715 | } | |
9716 | return CMD_SUCCESS; | |
ba682537 | 9717 | } |
9718 | ||
6b0655a2 | 9719 | |
88d6cf37 | 9720 | DEFUN (ospf_max_metric_router_lsa_admin, |
9721 | ospf_max_metric_router_lsa_admin_cmd, | |
9722 | "max-metric router-lsa administrative", | |
9723 | "OSPF maximum / infinite-distance metric\n" | |
9724 | "Advertise own Router-LSA with infinite distance (stub router)\n" | |
9725 | "Administratively applied, for an indefinite period\n") | |
9726 | { | |
a3d826f0 | 9727 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 9728 | struct listnode *ln; |
9729 | struct ospf_area *area; | |
7c8ff89e | 9730 | |
d62a17ae | 9731 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, ln, area)) { |
9732 | SET_FLAG(area->stub_router_state, OSPF_AREA_ADMIN_STUB_ROUTED); | |
4ba4fc85 | 9733 | |
d62a17ae | 9734 | if (!CHECK_FLAG(area->stub_router_state, |
9735 | OSPF_AREA_IS_STUB_ROUTED)) | |
9736 | ospf_router_lsa_update_area(area); | |
9737 | } | |
4ba4fc85 | 9738 | |
d62a17ae | 9739 | /* Allows for areas configured later to get the property */ |
9740 | ospf->stub_router_admin_set = OSPF_STUB_ROUTER_ADMINISTRATIVE_SET; | |
9741 | ||
9742 | return CMD_SUCCESS; | |
88d6cf37 | 9743 | } |
9744 | ||
9745 | DEFUN (no_ospf_max_metric_router_lsa_admin, | |
9746 | no_ospf_max_metric_router_lsa_admin_cmd, | |
9747 | "no max-metric router-lsa administrative", | |
9748 | NO_STR | |
9749 | "OSPF maximum / infinite-distance metric\n" | |
9750 | "Advertise own Router-LSA with infinite distance (stub router)\n" | |
9751 | "Administratively applied, for an indefinite period\n") | |
9752 | { | |
a3d826f0 | 9753 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 9754 | struct listnode *ln; |
9755 | struct ospf_area *area; | |
9756 | ||
9757 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, ln, area)) { | |
9758 | UNSET_FLAG(area->stub_router_state, | |
9759 | OSPF_AREA_ADMIN_STUB_ROUTED); | |
9760 | ||
9761 | /* Don't trample on the start-up stub timer */ | |
9762 | if (CHECK_FLAG(area->stub_router_state, | |
9763 | OSPF_AREA_IS_STUB_ROUTED) | |
9764 | && !area->t_stub_router) { | |
9765 | UNSET_FLAG(area->stub_router_state, | |
9766 | OSPF_AREA_IS_STUB_ROUTED); | |
9767 | ospf_router_lsa_update_area(area); | |
9768 | } | |
9769 | } | |
9770 | ospf->stub_router_admin_set = OSPF_STUB_ROUTER_ADMINISTRATIVE_UNSET; | |
9771 | return CMD_SUCCESS; | |
88d6cf37 | 9772 | } |
9773 | ||
9774 | DEFUN (ospf_max_metric_router_lsa_startup, | |
9775 | ospf_max_metric_router_lsa_startup_cmd, | |
6147e2c6 | 9776 | "max-metric router-lsa on-startup (5-86400)", |
88d6cf37 | 9777 | "OSPF maximum / infinite-distance metric\n" |
9778 | "Advertise own Router-LSA with infinite distance (stub router)\n" | |
9779 | "Automatically advertise stub Router-LSA on startup of OSPF\n" | |
9780 | "Time (seconds) to advertise self as stub-router\n") | |
9781 | { | |
a3d826f0 | 9782 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 9783 | int idx_number = 3; |
9784 | unsigned int seconds; | |
9785 | ||
b5a8894d | 9786 | if (argc < 4) { |
d62a17ae | 9787 | vty_out(vty, "%% Must supply stub-router period"); |
9788 | return CMD_WARNING_CONFIG_FAILED; | |
9789 | } | |
9790 | ||
9791 | seconds = strtoul(argv[idx_number]->arg, NULL, 10); | |
9792 | ||
9793 | ospf->stub_router_startup_time = seconds; | |
9794 | ||
9795 | return CMD_SUCCESS; | |
88d6cf37 | 9796 | } |
9797 | ||
9798 | DEFUN (no_ospf_max_metric_router_lsa_startup, | |
9799 | no_ospf_max_metric_router_lsa_startup_cmd, | |
7a7be519 | 9800 | "no max-metric router-lsa on-startup [(5-86400)]", |
88d6cf37 | 9801 | NO_STR |
9802 | "OSPF maximum / infinite-distance metric\n" | |
9803 | "Advertise own Router-LSA with infinite distance (stub router)\n" | |
813d4307 DW |
9804 | "Automatically advertise stub Router-LSA on startup of OSPF\n" |
9805 | "Time (seconds) to advertise self as stub-router\n") | |
88d6cf37 | 9806 | { |
a3d826f0 | 9807 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 9808 | struct listnode *ln; |
9809 | struct ospf_area *area; | |
9810 | ||
9811 | ospf->stub_router_startup_time = OSPF_STUB_ROUTER_UNCONFIGURED; | |
9812 | ||
9813 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, ln, area)) { | |
9814 | SET_FLAG(area->stub_router_state, | |
9815 | OSPF_AREA_WAS_START_STUB_ROUTED); | |
9816 | OSPF_TIMER_OFF(area->t_stub_router); | |
9817 | ||
9818 | /* Don't trample on admin stub routed */ | |
9819 | if (!CHECK_FLAG(area->stub_router_state, | |
9820 | OSPF_AREA_ADMIN_STUB_ROUTED)) { | |
9821 | UNSET_FLAG(area->stub_router_state, | |
9822 | OSPF_AREA_IS_STUB_ROUTED); | |
9823 | ospf_router_lsa_update_area(area); | |
9824 | } | |
9825 | } | |
9826 | return CMD_SUCCESS; | |
88d6cf37 | 9827 | } |
9828 | ||
a1afa410 | 9829 | |
88d6cf37 | 9830 | DEFUN (ospf_max_metric_router_lsa_shutdown, |
9831 | ospf_max_metric_router_lsa_shutdown_cmd, | |
6147e2c6 | 9832 | "max-metric router-lsa on-shutdown (5-100)", |
88d6cf37 | 9833 | "OSPF maximum / infinite-distance metric\n" |
9834 | "Advertise own Router-LSA with infinite distance (stub router)\n" | |
9835 | "Advertise stub-router prior to full shutdown of OSPF\n" | |
9836 | "Time (seconds) to wait till full shutdown\n") | |
9837 | { | |
a3d826f0 | 9838 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 9839 | int idx_number = 3; |
9840 | unsigned int seconds; | |
9841 | ||
b5a8894d | 9842 | if (argc < 4) { |
d62a17ae | 9843 | vty_out(vty, "%% Must supply stub-router shutdown period"); |
9844 | return CMD_WARNING_CONFIG_FAILED; | |
9845 | } | |
9846 | ||
9847 | seconds = strtoul(argv[idx_number]->arg, NULL, 10); | |
9848 | ||
9849 | ospf->stub_router_shutdown_time = seconds; | |
9850 | ||
9851 | return CMD_SUCCESS; | |
88d6cf37 | 9852 | } |
9853 | ||
9854 | DEFUN (no_ospf_max_metric_router_lsa_shutdown, | |
9855 | no_ospf_max_metric_router_lsa_shutdown_cmd, | |
7a7be519 | 9856 | "no max-metric router-lsa on-shutdown [(5-100)]", |
88d6cf37 | 9857 | NO_STR |
9858 | "OSPF maximum / infinite-distance metric\n" | |
9859 | "Advertise own Router-LSA with infinite distance (stub router)\n" | |
813d4307 DW |
9860 | "Advertise stub-router prior to full shutdown of OSPF\n" |
9861 | "Time (seconds) to wait till full shutdown\n") | |
88d6cf37 | 9862 | { |
a3d826f0 | 9863 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
7c8ff89e | 9864 | |
d62a17ae | 9865 | ospf->stub_router_shutdown_time = OSPF_STUB_ROUTER_UNCONFIGURED; |
9866 | ||
9867 | return CMD_SUCCESS; | |
88d6cf37 | 9868 | } |
9869 | ||
a92706bb JU |
9870 | DEFUN (ospf_proactive_arp, |
9871 | ospf_proactive_arp_cmd, | |
9872 | "proactive-arp", | |
9873 | "Allow sending ARP requests proactively\n") | |
9874 | { | |
9875 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
9876 | ||
9877 | ospf->proactive_arp = true; | |
9878 | ||
9879 | return CMD_SUCCESS; | |
9880 | } | |
9881 | ||
9882 | DEFUN (no_ospf_proactive_arp, | |
9883 | no_ospf_proactive_arp_cmd, | |
9884 | "no proactive-arp", | |
9885 | NO_STR | |
9886 | "Disallow sending ARP requests proactively\n") | |
9887 | { | |
9888 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
9889 | ||
9890 | ospf->proactive_arp = false; | |
9891 | ||
9892 | return CMD_SUCCESS; | |
9893 | } | |
9894 | ||
07b33add | 9895 | /* Graceful Restart HELPER Commands */ |
9896 | DEFPY(ospf_gr_helper_enable, ospf_gr_helper_enable_cmd, | |
859bce81 | 9897 | "graceful-restart helper enable [A.B.C.D$address]", |
07b33add | 9898 | "OSPF Graceful Restart\n" |
859bce81 | 9899 | "OSPF GR Helper\n" |
07b33add | 9900 | "Enable Helper support\n" |
859bce81 | 9901 | "Advertising Router-ID\n") |
07b33add | 9902 | { |
9903 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
07b33add | 9904 | |
859bce81 RW |
9905 | if (address_str) { |
9906 | ospf_gr_helper_support_set_per_routerid(ospf, &address, | |
9907 | OSPF_GR_TRUE); | |
07b33add | 9908 | return CMD_SUCCESS; |
9909 | } | |
9910 | ||
9911 | ospf_gr_helper_support_set(ospf, OSPF_GR_TRUE); | |
9912 | ||
9913 | return CMD_SUCCESS; | |
9914 | } | |
9915 | ||
9916 | DEFPY(no_ospf_gr_helper_enable, | |
9917 | no_ospf_gr_helper_enable_cmd, | |
859bce81 | 9918 | "no graceful-restart helper enable [A.B.C.D$address]", |
07b33add | 9919 | NO_STR |
9920 | "OSPF Graceful Restart\n" | |
859bce81 RW |
9921 | "OSPF GR Helper\n" |
9922 | "Enable Helper support\n" | |
9923 | "Advertising Router-ID\n") | |
9924 | { | |
9925 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
9926 | ||
9927 | if (address_str) { | |
9928 | ospf_gr_helper_support_set_per_routerid(ospf, &address, | |
9929 | OSPF_GR_FALSE); | |
9930 | return CMD_SUCCESS; | |
9931 | } | |
9932 | ||
9933 | ospf_gr_helper_support_set(ospf, OSPF_GR_FALSE); | |
9934 | return CMD_SUCCESS; | |
9935 | } | |
9936 | ||
9937 | #if CONFDATE > 20220921 | |
9938 | CPP_NOTICE( | |
9939 | "Time to remove the deprecated \"[no] graceful-restart helper-only\" commands") | |
9940 | #endif | |
9941 | ||
9942 | DEFPY_HIDDEN(ospf_gr_helper_only, ospf_gr_helper_only_cmd, | |
9943 | "graceful-restart helper-only [A.B.C.D]", | |
9944 | "OSPF Graceful Restart\n" | |
9945 | "Enable Helper support\n" | |
07b33add | 9946 | "Advertising router id\n") |
9947 | { | |
9948 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
9949 | struct in_addr addr; | |
9950 | int ret; | |
9951 | ||
859bce81 RW |
9952 | vty_out(vty, |
9953 | "%% This command is deprecated. Please, use `graceful-restart helper enable` instead.\n"); | |
9954 | ||
9955 | if (argc == 3) { | |
9956 | ret = inet_aton(argv[2]->arg, &addr); | |
07b33add | 9957 | if (!ret) { |
9958 | vty_out(vty, | |
9959 | "Please specify the valid routerid address.\n"); | |
9960 | return CMD_WARNING_CONFIG_FAILED; | |
9961 | } | |
9962 | ||
859bce81 | 9963 | ospf_gr_helper_support_set_per_routerid(ospf, &addr, OSPF_GR_TRUE); |
07b33add | 9964 | return CMD_SUCCESS; |
9965 | } | |
9966 | ||
859bce81 RW |
9967 | ospf_gr_helper_support_set(ospf, OSPF_GR_TRUE); |
9968 | ||
07b33add | 9969 | return CMD_SUCCESS; |
9970 | } | |
9971 | ||
859bce81 RW |
9972 | ALIAS_HIDDEN(no_ospf_gr_helper_enable, |
9973 | no_ospf_gr_helper_only_cmd, | |
9974 | "no graceful-restart helper-only [A.B.C.D]", | |
9975 | NO_STR | |
9976 | "OSPF Graceful Restart\n" | |
9977 | "Disable Helper support\n" | |
9978 | "Advertising router id\n") | |
9979 | ||
07b33add | 9980 | DEFPY(ospf_gr_helper_enable_lsacheck, |
9981 | ospf_gr_helper_enable_lsacheck_cmd, | |
9982 | "graceful-restart helper strict-lsa-checking", | |
9983 | "OSPF Graceful Restart\n" | |
9984 | "OSPF GR Helper\n" | |
9985 | "Enable strict LSA check\n") | |
9986 | { | |
9987 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
9988 | ||
9989 | ospf_gr_helper_lsa_check_set(ospf, OSPF_GR_TRUE); | |
9990 | return CMD_SUCCESS; | |
9991 | } | |
9992 | ||
9993 | DEFPY(no_ospf_gr_helper_enable_lsacheck, | |
9994 | no_ospf_gr_helper_enable_lsacheck_cmd, | |
9995 | "no graceful-restart helper strict-lsa-checking", | |
9996 | NO_STR | |
9997 | "OSPF Graceful Restart\n" | |
9998 | "OSPF GR Helper\n" | |
9999 | "Disable strict LSA check\n") | |
10000 | { | |
10001 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
10002 | ||
10003 | ospf_gr_helper_lsa_check_set(ospf, OSPF_GR_FALSE); | |
10004 | return CMD_SUCCESS; | |
10005 | } | |
10006 | ||
10007 | DEFPY(ospf_gr_helper_supported_grace_time, | |
10008 | ospf_gr_helper_supported_grace_time_cmd, | |
10009 | "graceful-restart helper supported-grace-time (10-1800)$interval", | |
10010 | "OSPF Graceful Restart\n" | |
10011 | "OSPF GR Helper\n" | |
10012 | "Supported grace timer\n" | |
10013 | "Grace interval(in seconds)\n") | |
10014 | { | |
10015 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
10016 | ||
10017 | ospf_gr_helper_supported_gracetime_set(ospf, interval); | |
10018 | return CMD_SUCCESS; | |
10019 | } | |
10020 | ||
10021 | DEFPY(no_ospf_gr_helper_supported_grace_time, | |
10022 | no_ospf_gr_helper_supported_grace_time_cmd, | |
10023 | "no graceful-restart helper supported-grace-time (10-1800)$interval", | |
10024 | NO_STR | |
10025 | "OSPF Graceful Restart\n" | |
10026 | "OSPF GR Helper\n" | |
10027 | "Supported grace timer\n" | |
10028 | "Grace interval(in seconds)\n") | |
10029 | { | |
10030 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
10031 | ||
10032 | ospf_gr_helper_supported_gracetime_set(ospf, OSPF_MAX_GRACE_INTERVAL); | |
10033 | return CMD_SUCCESS; | |
10034 | } | |
10035 | ||
10036 | DEFPY(ospf_gr_helper_planned_only, | |
10037 | ospf_gr_helper_planned_only_cmd, | |
10038 | "graceful-restart helper planned-only", | |
10039 | "OSPF Graceful Restart\n" | |
10040 | "OSPF GR Helper\n" | |
10041 | "Supported only planned restart\n") | |
10042 | { | |
10043 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
10044 | ||
10045 | ospf_gr_helper_set_supported_planned_only_restart(ospf, OSPF_GR_TRUE); | |
10046 | ||
10047 | return CMD_SUCCESS; | |
10048 | } | |
10049 | ||
423e71c4 | 10050 | /* External Route Aggregation */ |
10051 | DEFUN (ospf_external_route_aggregation, | |
10052 | ospf_external_route_aggregation_cmd, | |
10053 | "summary-address A.B.C.D/M [tag (1-4294967295)]", | |
10054 | "External summary address\n" | |
10055 | "Summary address prefix (a.b.c.d/m) \n" | |
10056 | "Router tag \n" | |
10057 | "Router tag value\n") | |
10058 | { | |
10059 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
10060 | struct prefix_ipv4 p; | |
10061 | int idx = 1; | |
10062 | route_tag_t tag = 0; | |
10063 | int ret = OSPF_SUCCESS; | |
10064 | ||
10065 | str2prefix_ipv4(argv[idx]->arg, &p); | |
10066 | ||
1fe59b44 | 10067 | if (is_default_prefix4(&p)) { |
423e71c4 | 10068 | vty_out(vty, |
10069 | "Default address shouldn't be configured as summary address.\n"); | |
10070 | return CMD_SUCCESS; | |
10071 | } | |
10072 | ||
10073 | /* Apply mask for given prefix. */ | |
10074 | apply_mask((struct prefix *)&p); | |
10075 | ||
10076 | if (!is_valid_summary_addr(&p)) { | |
10077 | vty_out(vty, "Not a valid summary address.\n"); | |
10078 | return CMD_WARNING_CONFIG_FAILED; | |
10079 | } | |
10080 | ||
10081 | if (argc > 2) | |
10082 | tag = strtoul(argv[idx + 2]->arg, NULL, 10); | |
10083 | ||
10084 | ret = ospf_asbr_external_aggregator_set(ospf, &p, tag); | |
10085 | if (ret == OSPF_INVALID) | |
10086 | vty_out(vty, "Inavlid configuration!!\n"); | |
10087 | ||
10088 | return CMD_SUCCESS; | |
10089 | } | |
10090 | ||
10091 | DEFUN (no_ospf_external_route_aggregation, | |
10092 | no_ospf_external_route_aggregation_cmd, | |
10093 | "no summary-address A.B.C.D/M [tag (1-4294967295)]", | |
10094 | NO_STR | |
10095 | "External summary address\n" | |
10096 | "Summary address prefix (a.b.c.d/m)\n" | |
10097 | "Router tag\n" | |
10098 | "Router tag value\n") | |
10099 | { | |
10100 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
10101 | struct prefix_ipv4 p; | |
10102 | int idx = 2; | |
10103 | route_tag_t tag = 0; | |
10104 | int ret = OSPF_SUCCESS; | |
10105 | ||
10106 | str2prefix_ipv4(argv[idx]->arg, &p); | |
10107 | ||
1fe59b44 | 10108 | if (is_default_prefix4(&p)) { |
423e71c4 | 10109 | vty_out(vty, |
10110 | "Default address shouldn't be configured as summary address.\n"); | |
10111 | return CMD_SUCCESS; | |
10112 | } | |
10113 | ||
10114 | /* Apply mask for given prefix. */ | |
10115 | apply_mask((struct prefix *)&p); | |
10116 | ||
10117 | if (!is_valid_summary_addr(&p)) { | |
10118 | vty_out(vty, "Not a valid summary address.\n"); | |
10119 | return CMD_WARNING_CONFIG_FAILED; | |
10120 | } | |
10121 | ||
10122 | if (argc > 3) | |
10123 | tag = strtoul(argv[idx + 2]->arg, NULL, 10); | |
10124 | ||
10125 | ret = ospf_asbr_external_aggregator_unset(ospf, &p, tag); | |
10126 | if (ret == OSPF_INVALID) | |
10127 | vty_out(vty, "Inavlid configuration!!\n"); | |
10128 | ||
10129 | return CMD_SUCCESS; | |
10130 | } | |
10131 | ||
07b33add | 10132 | DEFPY(no_ospf_gr_helper_planned_only, |
10133 | no_ospf_gr_helper_planned_only_cmd, | |
10134 | "no graceful-restart helper planned-only", | |
10135 | NO_STR | |
10136 | "OSPF Graceful Restart\n" | |
10137 | "OSPF GR Helper\n" | |
10138 | "Supported only for planned restart\n") | |
10139 | { | |
10140 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
10141 | ||
10142 | ospf_gr_helper_set_supported_planned_only_restart(ospf, OSPF_GR_FALSE); | |
10143 | ||
10144 | return CMD_SUCCESS; | |
10145 | } | |
abd5b8c7 | 10146 | |
1ac88792 | 10147 | static int ospf_print_vty_helper_dis_rtr_walkcb(struct hash_bucket *bucket, |
abd5b8c7 | 10148 | void *arg) |
10149 | { | |
1ac88792 | 10150 | struct advRtr *rtr = bucket->data; |
abd5b8c7 | 10151 | struct vty *vty = (struct vty *)arg; |
10152 | static unsigned int count; | |
10153 | ||
96b663a3 | 10154 | vty_out(vty, "%-6pI4,", &rtr->advRtrAddr); |
abd5b8c7 | 10155 | count++; |
10156 | ||
10157 | if (count % 5 == 0) | |
10158 | vty_out(vty, "\n"); | |
10159 | ||
10160 | return HASHWALK_CONTINUE; | |
10161 | } | |
10162 | ||
10163 | static int ospf_show_gr_helper_details(struct vty *vty, struct ospf *ospf, | |
10164 | uint8_t use_vrf, json_object *json, | |
10165 | bool uj, bool detail) | |
10166 | { | |
10167 | struct listnode *node; | |
10168 | struct ospf_interface *oi; | |
96b663a3 | 10169 | char buf[PREFIX_STRLEN]; |
abd5b8c7 | 10170 | json_object *json_vrf = NULL; |
10171 | ||
10172 | if (uj) { | |
10173 | if (use_vrf) | |
10174 | json_vrf = json_object_new_object(); | |
10175 | else | |
10176 | json_vrf = json; | |
10177 | } | |
10178 | ||
10179 | if (ospf->instance) { | |
10180 | if (uj) | |
10181 | json_object_int_add(json, "ospfInstance", | |
10182 | ospf->instance); | |
10183 | else | |
10184 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
10185 | } | |
10186 | ||
10187 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); | |
10188 | ||
10189 | if (uj) { | |
10190 | if (use_vrf) { | |
10191 | if (ospf->vrf_id == VRF_DEFAULT) | |
10192 | json_object_object_add(json, "default", | |
10193 | json_vrf); | |
10194 | else | |
10195 | json_object_object_add(json, ospf->name, | |
10196 | json_vrf); | |
10197 | } | |
10198 | } else | |
10199 | vty_out(vty, "\n"); | |
10200 | ||
10201 | /* Show Router ID. */ | |
10202 | if (uj) { | |
10203 | json_object_string_add(json_vrf, "routerId", | |
96b663a3 MS |
10204 | inet_ntop(AF_INET, &ospf->router_id, |
10205 | buf, sizeof(buf))); | |
abd5b8c7 | 10206 | } else { |
96b663a3 MS |
10207 | vty_out(vty, "\n OSPF Router with ID (%pI4)\n\n", |
10208 | &ospf->router_id); | |
abd5b8c7 | 10209 | } |
10210 | ||
10211 | if (!uj) { | |
10212 | ||
10213 | if (ospf->is_helper_supported) | |
10214 | vty_out(vty, | |
10215 | " Graceful restart helper support enabled.\n"); | |
10216 | else | |
10217 | vty_out(vty, | |
10218 | " Graceful restart helper support disabled.\n"); | |
10219 | ||
10220 | if (ospf->strict_lsa_check) | |
10221 | vty_out(vty, " Strict LSA check is enabled.\n"); | |
10222 | else | |
10223 | vty_out(vty, " Strict LSA check is disabled.\n"); | |
10224 | ||
10225 | if (ospf->only_planned_restart) | |
10226 | vty_out(vty, | |
10227 | " Helper supported for planned restarts only.\n"); | |
10228 | else | |
10229 | vty_out(vty, | |
10230 | " Helper supported for Planned and Unplanned Restarts.\n"); | |
10231 | ||
10232 | vty_out(vty, | |
10233 | " Supported Graceful restart interval: %d(in seconds).\n", | |
10234 | ospf->supported_grace_time); | |
10235 | ||
10236 | if (OSPF_HELPER_ENABLE_RTR_COUNT(ospf)) { | |
10237 | vty_out(vty, " Enable Router list:\n"); | |
10238 | vty_out(vty, " "); | |
10239 | hash_walk(ospf->enable_rtr_list, | |
10240 | ospf_print_vty_helper_dis_rtr_walkcb, vty); | |
10241 | vty_out(vty, "\n\n"); | |
10242 | } | |
10243 | ||
10244 | if (ospf->last_exit_reason != OSPF_GR_HELPER_EXIT_NONE) { | |
10245 | vty_out(vty, " Last Helper exit Reason :%s\n", | |
d05d5280 | 10246 | ospf_exit_reason2str(ospf->last_exit_reason)); |
abd5b8c7 | 10247 | } |
10248 | ||
10249 | if (ospf->active_restarter_cnt) | |
10250 | vty_out(vty, | |
10251 | " Number of Active neighbours in graceful restart: %d\n", | |
10252 | ospf->active_restarter_cnt); | |
10253 | else | |
10254 | vty_out(vty, "\n"); | |
10255 | ||
10256 | } else { | |
10257 | json_object_string_add( | |
10258 | json_vrf, "helperSupport", | |
10259 | (ospf->is_helper_supported) ? "Enabled" : "Disabled"); | |
10260 | json_object_string_add(json_vrf, "strictLsaCheck", | |
10261 | (ospf->strict_lsa_check) ? "Enabled" | |
10262 | : "Disabled"); | |
10263 | json_object_string_add( | |
10264 | json_vrf, "restartSupoort", | |
10265 | (ospf->only_planned_restart) | |
10266 | ? "Planned Restart only" | |
10267 | : "Planned and Unplanned Restarts"); | |
10268 | ||
10269 | json_object_int_add(json_vrf, "supportedGracePeriod", | |
10270 | ospf->supported_grace_time); | |
10271 | ||
10272 | if (ospf->last_exit_reason != OSPF_GR_HELPER_EXIT_NONE) | |
10273 | json_object_string_add( | |
10274 | json_vrf, "LastExitReason", | |
d05d5280 | 10275 | ospf_exit_reason2str(ospf->last_exit_reason)); |
abd5b8c7 | 10276 | |
10277 | if (ospf->active_restarter_cnt) | |
10278 | json_object_int_add(json_vrf, "activeRestarterCnt", | |
10279 | ospf->active_restarter_cnt); | |
10280 | } | |
10281 | ||
10282 | ||
10283 | if (detail) { | |
10284 | int cnt = 1; | |
10285 | json_object *json_neighbors = NULL; | |
10286 | ||
10287 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) { | |
10288 | struct route_node *rn; | |
10289 | struct ospf_neighbor *nbr; | |
10290 | json_object *json_neigh; | |
10291 | ||
10292 | if (ospf_interface_neighbor_count(oi) == 0) | |
10293 | continue; | |
10294 | ||
10295 | if (uj) { | |
10296 | json_object_object_get_ex(json_vrf, "Neighbors", | |
10297 | &json_neighbors); | |
10298 | if (!json_neighbors) { | |
10299 | json_neighbors = | |
10300 | json_object_new_object(); | |
10301 | json_object_object_add(json_vrf, | |
10302 | "Neighbors", | |
10303 | json_neighbors); | |
10304 | } | |
10305 | } | |
10306 | ||
10307 | for (rn = route_top(oi->nbrs); rn; | |
10308 | rn = route_next(rn)) { | |
10309 | ||
10310 | if (!rn->info) | |
10311 | continue; | |
10312 | ||
10313 | nbr = rn->info; | |
10314 | ||
10315 | if (!OSPF_GR_IS_ACTIVE_HELPER(nbr)) | |
10316 | continue; | |
10317 | ||
10318 | if (!uj) { | |
10319 | vty_out(vty, " Neighbour %d :\n", cnt); | |
96b663a3 MS |
10320 | vty_out(vty, " Address : %pI4\n", |
10321 | &nbr->address.u.prefix4); | |
10322 | vty_out(vty, " Routerid : %pI4\n", | |
10323 | &nbr->router_id); | |
abd5b8c7 | 10324 | vty_out(vty, |
10325 | " Received Grace period : %d(in seconds).\n", | |
10326 | nbr->gr_helper_info | |
10327 | .recvd_grace_period); | |
10328 | vty_out(vty, | |
10329 | " Actual Grace period : %d(in seconds)\n", | |
10330 | nbr->gr_helper_info | |
10331 | .actual_grace_period); | |
10332 | vty_out(vty, | |
10333 | " Remaining GraceTime:%ld(in seconds).\n", | |
10334 | thread_timer_remain_second( | |
10335 | nbr->gr_helper_info | |
10336 | .t_grace_timer)); | |
10337 | vty_out(vty, | |
10338 | " Graceful Restart reason: %s.\n\n", | |
d05d5280 MS |
10339 | ospf_restart_reason2str( |
10340 | nbr->gr_helper_info | |
10341 | .gr_restart_reason)); | |
abd5b8c7 | 10342 | cnt++; |
10343 | } else { | |
10344 | json_neigh = json_object_new_object(); | |
10345 | json_object_string_add( | |
10346 | json_neigh, "srcAddr", | |
96b663a3 MS |
10347 | inet_ntop(AF_INET, &nbr->src, |
10348 | buf, sizeof(buf))); | |
abd5b8c7 | 10349 | |
10350 | json_object_string_add( | |
10351 | json_neigh, "routerid", | |
96b663a3 MS |
10352 | inet_ntop(AF_INET, |
10353 | &nbr->router_id, | |
10354 | buf, sizeof(buf))); | |
abd5b8c7 | 10355 | json_object_int_add( |
10356 | json_neigh, | |
10357 | "recvdGraceInterval", | |
10358 | nbr->gr_helper_info | |
10359 | .recvd_grace_period); | |
10360 | json_object_int_add( | |
10361 | json_neigh, | |
10362 | "actualGraceInterval", | |
10363 | nbr->gr_helper_info | |
10364 | .actual_grace_period); | |
10365 | json_object_int_add( | |
10366 | json_neigh, "remainGracetime", | |
10367 | thread_timer_remain_second( | |
10368 | nbr->gr_helper_info | |
10369 | .t_grace_timer)); | |
10370 | json_object_string_add( | |
10371 | json_neigh, "restartReason", | |
d05d5280 MS |
10372 | ospf_restart_reason2str( |
10373 | nbr->gr_helper_info | |
10374 | .gr_restart_reason)); | |
abd5b8c7 | 10375 | json_object_object_add( |
10376 | json_neighbors, | |
96b663a3 MS |
10377 | inet_ntop(AF_INET, &nbr->src, |
10378 | buf, sizeof(buf)), | |
abd5b8c7 | 10379 | json_neigh); |
10380 | } | |
10381 | } | |
10382 | } | |
10383 | } | |
423e71c4 | 10384 | return CMD_SUCCESS; |
10385 | } | |
10386 | ||
10387 | DEFUN (ospf_external_route_aggregation_no_adrvertise, | |
10388 | ospf_external_route_aggregation_no_adrvertise_cmd, | |
10389 | "summary-address A.B.C.D/M no-advertise", | |
10390 | "External summary address\n" | |
10391 | "Summary address prefix (a.b.c.d/m) \n" | |
10392 | "Don't advertise summary route \n") | |
10393 | { | |
10394 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
10395 | struct prefix_ipv4 p; | |
10396 | int idx = 1; | |
10397 | int ret = OSPF_SUCCESS; | |
10398 | ||
10399 | str2prefix_ipv4(argv[idx]->arg, &p); | |
10400 | ||
1fe59b44 | 10401 | if (is_default_prefix4(&p)) { |
423e71c4 | 10402 | vty_out(vty, |
10403 | "Default address shouldn't be configured as summary address.\n"); | |
10404 | return CMD_SUCCESS; | |
10405 | } | |
10406 | ||
10407 | /* Apply mask for given prefix. */ | |
10408 | apply_mask((struct prefix *)&p); | |
10409 | ||
10410 | if (!is_valid_summary_addr(&p)) { | |
10411 | vty_out(vty, "Not a valid summary address.\n"); | |
10412 | return CMD_WARNING_CONFIG_FAILED; | |
10413 | } | |
10414 | ||
10415 | ret = ospf_asbr_external_rt_no_advertise(ospf, &p); | |
10416 | if (ret == OSPF_INVALID) | |
10417 | vty_out(vty, "Inavlid configuration!!\n"); | |
10418 | ||
10419 | return CMD_SUCCESS; | |
10420 | } | |
10421 | ||
10422 | DEFUN (no_ospf_external_route_aggregation_no_adrvertise, | |
10423 | no_ospf_external_route_aggregation_no_adrvertise_cmd, | |
10424 | "no summary-address A.B.C.D/M no-advertise", | |
10425 | NO_STR | |
10426 | "External summary address\n" | |
fbc48492 DS |
10427 | "Summary address prefix (a.b.c.d/m)\n" |
10428 | "Advertise summary route to the AS \n") | |
423e71c4 | 10429 | { |
10430 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
10431 | struct prefix_ipv4 p; | |
10432 | int idx = 2; | |
10433 | int ret = OSPF_SUCCESS; | |
10434 | ||
10435 | str2prefix_ipv4(argv[idx]->arg, &p); | |
10436 | ||
1fe59b44 | 10437 | if (is_default_prefix4(&p)) { |
423e71c4 | 10438 | vty_out(vty, |
10439 | "Default address shouldn't be configured as summary address.\n"); | |
10440 | return CMD_SUCCESS; | |
10441 | } | |
10442 | ||
10443 | /* Apply mask for given prefix. */ | |
10444 | apply_mask((struct prefix *)&p); | |
10445 | ||
10446 | if (!is_valid_summary_addr(&p)) { | |
10447 | vty_out(vty, "Not a valid summary address.\n"); | |
10448 | return CMD_WARNING_CONFIG_FAILED; | |
10449 | } | |
10450 | ||
10451 | ret = ospf_asbr_external_rt_advertise(ospf, &p); | |
10452 | if (ret == OSPF_INVALID) | |
10453 | vty_out(vty, "Inavlid configuration!!\n"); | |
10454 | ||
10455 | return CMD_SUCCESS; | |
10456 | } | |
10457 | ||
10458 | DEFUN (ospf_route_aggregation_timer, | |
10459 | ospf_route_aggregation_timer_cmd, | |
10460 | "aggregation timer (5-1800)", | |
10461 | "External route aggregation\n" | |
10462 | "Delay timer (in seconds)\n" | |
10463 | "Timer interval(in seconds)\n") | |
10464 | { | |
10465 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
10466 | unsigned int interval = 0; | |
10467 | ||
10468 | interval = strtoul(argv[2]->arg, NULL, 10); | |
10469 | ||
10470 | ospf_external_aggregator_timer_set(ospf, interval); | |
abd5b8c7 | 10471 | |
10472 | return CMD_SUCCESS; | |
10473 | } | |
10474 | ||
10475 | DEFPY (show_ip_ospf_gr_helper, | |
10476 | show_ip_ospf_gr_helper_cmd, | |
10477 | "show ip ospf [vrf <NAME|all>] graceful-restart helper [detail] [json]", | |
10478 | SHOW_STR | |
10479 | IP_STR | |
10480 | "OSPF information\n" | |
10481 | VRF_CMD_HELP_STR | |
10482 | "All VRFs\n" | |
10483 | "OSPF Graceful Restart\n" | |
10484 | "Helper details in the router\n" | |
10485 | "Detailed informtion\n" | |
10486 | JSON_STR) | |
10487 | { | |
10488 | char *vrf_name = NULL; | |
10489 | bool all_vrf = false; | |
10490 | int ret = CMD_SUCCESS; | |
10491 | int idx_vrf = 0; | |
10492 | int idx = 0; | |
10493 | uint8_t use_vrf = 0; | |
10494 | bool uj = use_json(argc, argv); | |
10495 | struct ospf *ospf = NULL; | |
10496 | json_object *json = NULL; | |
10497 | struct listnode *node = NULL; | |
10498 | int inst = 0; | |
10499 | bool detail = false; | |
10500 | ||
10501 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); | |
10502 | ||
10503 | if (argv_find(argv, argc, "detail", &idx)) | |
10504 | detail = true; | |
10505 | ||
10506 | if (uj) | |
10507 | json = json_object_new_object(); | |
10508 | ||
10509 | /* vrf input is provided */ | |
10510 | if (vrf_name) { | |
10511 | use_vrf = 1; | |
10512 | ||
10513 | if (all_vrf) { | |
10514 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
10515 | if (!ospf->oi_running) | |
10516 | continue; | |
10517 | ||
10518 | ret = ospf_show_gr_helper_details( | |
10519 | vty, ospf, use_vrf, json, uj, detail); | |
10520 | } | |
10521 | ||
10522 | if (uj) { | |
10523 | vty_out(vty, "%s\n", | |
10524 | json_object_to_json_string_ext( | |
10525 | json, JSON_C_TO_STRING_PRETTY)); | |
10526 | json_object_free(json); | |
10527 | } | |
10528 | ||
10529 | return ret; | |
10530 | } | |
10531 | ||
10532 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
10533 | ||
10534 | if (ospf == NULL || !ospf->oi_running) { | |
10535 | ||
10536 | if (uj) { | |
10537 | vty_out(vty, "%s\n", | |
10538 | json_object_to_json_string_ext( | |
10539 | json, JSON_C_TO_STRING_PRETTY)); | |
10540 | json_object_free(json); | |
10541 | } else | |
10542 | vty_out(vty, "%% OSPF instance not found\n"); | |
10543 | ||
10544 | return CMD_SUCCESS; | |
10545 | } | |
10546 | ||
10547 | } else { | |
10548 | /* Default Vrf */ | |
10549 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
10550 | ||
10551 | if (ospf == NULL || !ospf->oi_running) { | |
10552 | ||
10553 | if (uj) { | |
10554 | vty_out(vty, "%s\n", | |
10555 | json_object_to_json_string_ext( | |
10556 | json, JSON_C_TO_STRING_PRETTY)); | |
10557 | json_object_free(json); | |
10558 | } else | |
10559 | vty_out(vty, "%% OSPF instance not found\n"); | |
10560 | ||
10561 | return CMD_SUCCESS; | |
10562 | } | |
10563 | ||
10564 | ospf_show_gr_helper_details(vty, ospf, use_vrf, json, uj, | |
10565 | detail); | |
10566 | } | |
10567 | ||
10568 | if (uj) { | |
10569 | vty_out(vty, "%s\n", json_object_to_json_string_ext( | |
10570 | json, JSON_C_TO_STRING_PRETTY)); | |
10571 | json_object_free(json); | |
10572 | } | |
10573 | ||
10574 | return CMD_SUCCESS; | |
10575 | } | |
07b33add | 10576 | /* Graceful Restart HELPER commands end */ |
423e71c4 | 10577 | DEFUN (no_ospf_route_aggregation_timer, |
10578 | no_ospf_route_aggregation_timer_cmd, | |
10579 | "no aggregation timer", | |
10580 | NO_STR | |
10581 | "External route aggregation\n" | |
10582 | "Delay timer\n") | |
10583 | { | |
10584 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
10585 | ||
10586 | ospf_external_aggregator_timer_set(ospf, OSPF_EXTL_AGGR_DEFAULT_DELAY); | |
10587 | ||
10588 | return CMD_SUCCESS; | |
10589 | } | |
10590 | ||
10591 | /* External Route Aggregation End */ | |
07b33add | 10592 | |
d62a17ae | 10593 | static void config_write_stub_router(struct vty *vty, struct ospf *ospf) |
10594 | { | |
10595 | struct listnode *ln; | |
10596 | struct ospf_area *area; | |
10597 | ||
10598 | if (ospf->stub_router_startup_time != OSPF_STUB_ROUTER_UNCONFIGURED) | |
10599 | vty_out(vty, " max-metric router-lsa on-startup %u\n", | |
10600 | ospf->stub_router_startup_time); | |
10601 | if (ospf->stub_router_shutdown_time != OSPF_STUB_ROUTER_UNCONFIGURED) | |
10602 | vty_out(vty, " max-metric router-lsa on-shutdown %u\n", | |
10603 | ospf->stub_router_shutdown_time); | |
10604 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, ln, area)) { | |
10605 | if (CHECK_FLAG(area->stub_router_state, | |
10606 | OSPF_AREA_ADMIN_STUB_ROUTED)) { | |
10607 | vty_out(vty, " max-metric router-lsa administrative\n"); | |
10608 | break; | |
10609 | } | |
10610 | } | |
10611 | return; | |
10612 | } | |
10613 | ||
b5a8894d | 10614 | static void show_ip_ospf_route_network(struct vty *vty, struct ospf *ospf, |
0f478e30 CS |
10615 | struct route_table *rt, |
10616 | json_object *json) | |
d62a17ae | 10617 | { |
10618 | struct route_node *rn; | |
10619 | struct ospf_route * or ; | |
10620 | struct listnode *pnode, *pnnode; | |
10621 | struct ospf_path *path; | |
96b663a3 | 10622 | char buf[PREFIX_STRLEN]; |
0f478e30 CS |
10623 | json_object *json_route = NULL, *json_nexthop_array = NULL, |
10624 | *json_nexthop = NULL; | |
d62a17ae | 10625 | |
0f478e30 | 10626 | if (!json) |
996c9314 LB |
10627 | vty_out(vty, |
10628 | "============ OSPF network routing table ============\n"); | |
d62a17ae | 10629 | |
0f478e30 | 10630 | for (rn = route_top(rt); rn; rn = route_next(rn)) { |
96b663a3 MS |
10631 | char buf1[PREFIX2STR_BUFFER]; |
10632 | ||
0f478e30 CS |
10633 | if ((or = rn->info) == NULL) |
10634 | continue; | |
0f478e30 | 10635 | |
0f478e30 CS |
10636 | prefix2str(&rn->p, buf1, sizeof(buf1)); |
10637 | ||
19d37e54 DS |
10638 | if (json) { |
10639 | json_route = json_object_new_object(); | |
996c9314 | 10640 | json_object_object_add(json, buf1, json_route); |
19d37e54 | 10641 | } |
0f478e30 CS |
10642 | |
10643 | switch (or->path_type) { | |
10644 | case OSPF_PATH_INTER_AREA: | |
10645 | if (or->type == OSPF_DESTINATION_NETWORK) { | |
10646 | if (json) { | |
10647 | json_object_string_add(json_route, | |
996c9314 LB |
10648 | "routeType", |
10649 | "N IA"); | |
10650 | json_object_int_add(json_route, "cost", | |
0f478e30 CS |
10651 | or->cost); |
10652 | json_object_string_add( | |
996c9314 | 10653 | json_route, "area", |
96b663a3 MS |
10654 | inet_ntop(AF_INET, |
10655 | &or->u.std.area_id, | |
10656 | buf1, sizeof(buf1))); | |
0f478e30 | 10657 | } else { |
d62a17ae | 10658 | vty_out(vty, |
96b663a3 | 10659 | "N IA %-18s [%d] area: %pI4\n", |
d62a17ae | 10660 | buf1, or->cost, |
96b663a3 | 10661 | &or->u.std.area_id); |
0f478e30 | 10662 | } |
996c9314 | 10663 | } else if (or->type == OSPF_DESTINATION_DISCARD) { |
0f478e30 CS |
10664 | if (json) { |
10665 | json_object_string_add(json_route, | |
996c9314 LB |
10666 | "routeType", |
10667 | "D IA"); | |
0f478e30 | 10668 | } else { |
d62a17ae | 10669 | vty_out(vty, |
10670 | "D IA %-18s Discard entry\n", | |
10671 | buf1); | |
0f478e30 CS |
10672 | } |
10673 | } | |
10674 | break; | |
10675 | case OSPF_PATH_INTRA_AREA: | |
10676 | if (json) { | |
996c9314 LB |
10677 | json_object_string_add(json_route, "routeType", |
10678 | "N"); | |
0f478e30 | 10679 | json_object_int_add(json_route, "cost", |
996c9314 LB |
10680 | or->cost); |
10681 | json_object_string_add( | |
10682 | json_route, "area", | |
96b663a3 MS |
10683 | inet_ntop(AF_INET, &or->u.std.area_id, |
10684 | buf1, sizeof(buf1))); | |
0f478e30 | 10685 | } else { |
96b663a3 | 10686 | vty_out(vty, "N %-18s [%d] area: %pI4\n", |
d62a17ae | 10687 | buf1, or->cost, |
96b663a3 | 10688 | &or->u.std.area_id); |
0f478e30 CS |
10689 | } |
10690 | break; | |
10691 | default: | |
10692 | break; | |
10693 | } | |
10694 | ||
10695 | if (or->type == OSPF_DESTINATION_NETWORK) { | |
10696 | if (json) { | |
10697 | json_nexthop_array = json_object_new_array(); | |
10698 | json_object_object_add(json_route, "nexthops", | |
996c9314 | 10699 | json_nexthop_array); |
d62a17ae | 10700 | } |
10701 | ||
0f478e30 CS |
10702 | for (ALL_LIST_ELEMENTS(or->paths, pnode, pnnode, |
10703 | path)) { | |
10704 | if (json) { | |
996c9314 LB |
10705 | json_nexthop = json_object_new_object(); |
10706 | json_object_array_add( | |
10707 | json_nexthop_array, | |
10708 | json_nexthop); | |
0f478e30 CS |
10709 | } |
10710 | if (if_lookup_by_index(path->ifindex, | |
10711 | ospf->vrf_id)) { | |
10712 | ||
3a6290bd DA |
10713 | if (path->nexthop.s_addr |
10714 | == INADDR_ANY) { | |
0f478e30 CS |
10715 | if (json) { |
10716 | json_object_string_add( | |
10717 | json_nexthop, | |
996c9314 | 10718 | "ip", " "); |
0f478e30 CS |
10719 | json_object_string_add( |
10720 | json_nexthop, | |
10721 | "directly attached to", | |
d62a17ae | 10722 | ifindex2ifname( |
996c9314 LB |
10723 | path->ifindex, |
10724 | ospf->vrf_id)); | |
0f478e30 | 10725 | } else { |
d62a17ae | 10726 | vty_out(vty, |
996c9314 LB |
10727 | "%24s directly attached to %s\n", |
10728 | "", | |
10729 | ifindex2ifname( | |
10730 | path->ifindex, | |
10731 | ospf->vrf_id)); | |
0f478e30 CS |
10732 | } |
10733 | } else { | |
10734 | if (json) { | |
10735 | json_object_string_add( | |
10736 | json_nexthop, | |
10737 | "ip", | |
96b663a3 MS |
10738 | inet_ntop( |
10739 | AF_INET, | |
10740 | &path->nexthop, | |
10741 | buf, | |
10742 | sizeof(buf))); | |
0f478e30 CS |
10743 | json_object_string_add( |
10744 | json_nexthop, | |
10745 | "via", | |
d62a17ae | 10746 | ifindex2ifname( |
996c9314 LB |
10747 | path->ifindex, |
10748 | ospf->vrf_id)); | |
0f478e30 CS |
10749 | } else { |
10750 | vty_out(vty, | |
96b663a3 | 10751 | "%24s via %pI4, %s\n", |
996c9314 | 10752 | "", |
96b663a3 | 10753 | &path->nexthop, |
996c9314 LB |
10754 | ifindex2ifname( |
10755 | path->ifindex, | |
10756 | ospf->vrf_id)); | |
0f478e30 | 10757 | } |
d62a17ae | 10758 | } |
10759 | } | |
0f478e30 | 10760 | } |
d62a17ae | 10761 | } |
0f478e30 CS |
10762 | } |
10763 | if (!json) | |
10764 | vty_out(vty, "\n"); | |
d62a17ae | 10765 | } |
10766 | ||
b5a8894d | 10767 | static void show_ip_ospf_route_router(struct vty *vty, struct ospf *ospf, |
0f478e30 CS |
10768 | struct route_table *rtrs, |
10769 | json_object *json) | |
d62a17ae | 10770 | { |
10771 | struct route_node *rn; | |
10772 | struct ospf_route * or ; | |
10773 | struct listnode *pnode; | |
10774 | struct listnode *node; | |
10775 | struct ospf_path *path; | |
96b663a3 | 10776 | char buf[PREFIX_STRLEN]; |
0f478e30 CS |
10777 | json_object *json_route = NULL, *json_nexthop_array = NULL, |
10778 | *json_nexthop = NULL; | |
d62a17ae | 10779 | |
0f478e30 | 10780 | if (!json) |
996c9314 LB |
10781 | vty_out(vty, |
10782 | "============ OSPF router routing table =============\n"); | |
d62a17ae | 10783 | |
0f478e30 CS |
10784 | for (rn = route_top(rtrs); rn; rn = route_next(rn)) { |
10785 | if (rn->info == NULL) | |
10786 | continue; | |
10787 | int flag = 0; | |
10788 | ||
0f478e30 | 10789 | if (json) { |
19d37e54 | 10790 | json_route = json_object_new_object(); |
96b663a3 MS |
10791 | json_object_object_add( |
10792 | json, inet_ntop(AF_INET, &rn->p.u.prefix4, | |
10793 | buf, sizeof(buf)), | |
10794 | json_route); | |
996c9314 | 10795 | json_object_string_add(json_route, "routeType", "R "); |
0f478e30 | 10796 | } else { |
96b663a3 MS |
10797 | vty_out(vty, "R %-15pI4 ", |
10798 | &rn->p.u.prefix4); | |
0f478e30 | 10799 | } |
d62a17ae | 10800 | |
996c9314 | 10801 | for (ALL_LIST_ELEMENTS_RO((struct list *)rn->info, node, or)) { |
0f478e30 CS |
10802 | if (flag++) { |
10803 | if (!json) | |
d62a17ae | 10804 | vty_out(vty, "%24s", ""); |
0f478e30 | 10805 | } |
d62a17ae | 10806 | |
0f478e30 CS |
10807 | /* Show path. */ |
10808 | if (json) { | |
10809 | json_object_int_add(json_route, "cost", | |
10810 | or->cost); | |
996c9314 LB |
10811 | json_object_string_add( |
10812 | json_route, "area", | |
96b663a3 MS |
10813 | inet_ntop(AF_INET, &or->u.std.area_id, |
10814 | buf, sizeof(buf))); | |
996c9314 LB |
10815 | if (or->path_type == OSPF_PATH_INTER_AREA) |
10816 | json_object_boolean_true_add(json_route, | |
10817 | "IA"); | |
0f478e30 | 10818 | if (or->u.std.flags & ROUTER_LSA_BORDER) |
996c9314 LB |
10819 | json_object_string_add(json_route, |
10820 | "routerType", | |
10821 | "abr"); | |
10822 | else if (or->u.std.flags & ROUTER_LSA_EXTERNAL) | |
10823 | json_object_string_add(json_route, | |
10824 | "routerType", | |
10825 | "asbr"); | |
0f478e30 | 10826 | } else { |
96b663a3 | 10827 | vty_out(vty, "%s [%d] area: %pI4", |
996c9314 LB |
10828 | (or->path_type == OSPF_PATH_INTER_AREA |
10829 | ? "IA" | |
10830 | : " "), | |
96b663a3 | 10831 | or->cost, &or->u.std.area_id); |
d62a17ae | 10832 | /* Show flags. */ |
10833 | vty_out(vty, "%s%s\n", | |
996c9314 LB |
10834 | (or->u.std.flags & ROUTER_LSA_BORDER |
10835 | ? ", ABR" | |
10836 | : ""), | |
10837 | (or->u.std.flags & ROUTER_LSA_EXTERNAL | |
10838 | ? ", ASBR" | |
10839 | : "")); | |
0f478e30 CS |
10840 | } |
10841 | ||
10842 | if (json) { | |
996c9314 | 10843 | json_nexthop_array = json_object_new_array(); |
0f478e30 | 10844 | json_object_object_add(json_route, "nexthops", |
996c9314 | 10845 | json_nexthop_array); |
0f478e30 CS |
10846 | } |
10847 | ||
996c9314 | 10848 | for (ALL_LIST_ELEMENTS_RO(or->paths, pnode, path)) { |
0f478e30 | 10849 | if (json) { |
996c9314 | 10850 | json_nexthop = json_object_new_object(); |
0f478e30 CS |
10851 | json_object_array_add( |
10852 | json_nexthop_array, | |
10853 | json_nexthop); | |
10854 | } | |
10855 | if (if_lookup_by_index(path->ifindex, | |
10856 | ospf->vrf_id)) { | |
3a6290bd DA |
10857 | if (path->nexthop.s_addr |
10858 | == INADDR_ANY) { | |
0f478e30 CS |
10859 | if (json) { |
10860 | json_object_string_add( | |
10861 | json_nexthop, | |
996c9314 | 10862 | "ip", " "); |
0f478e30 CS |
10863 | json_object_string_add( |
10864 | json_nexthop, | |
10865 | "directly attached to", | |
d62a17ae | 10866 | ifindex2ifname( |
10867 | path->ifindex, | |
b5a8894d | 10868 | ospf->vrf_id)); |
0f478e30 | 10869 | } else { |
d62a17ae | 10870 | vty_out(vty, |
996c9314 LB |
10871 | "%24s directly attached to %s\n", |
10872 | "", | |
10873 | ifindex2ifname( | |
10874 | path->ifindex, | |
10875 | ospf->vrf_id)); | |
0f478e30 CS |
10876 | } |
10877 | } else { | |
10878 | if (json) { | |
10879 | json_object_string_add( | |
10880 | json_nexthop, | |
10881 | "ip", | |
96b663a3 MS |
10882 | inet_ntop( |
10883 | AF_INET, | |
10884 | &path->nexthop, | |
10885 | buf, sizeof(buf))); | |
0f478e30 CS |
10886 | json_object_string_add( |
10887 | json_nexthop, | |
10888 | "via", | |
d62a17ae | 10889 | ifindex2ifname( |
10890 | path->ifindex, | |
b5a8894d | 10891 | ospf->vrf_id)); |
0f478e30 CS |
10892 | } else { |
10893 | vty_out(vty, | |
96b663a3 | 10894 | "%24s via %pI4, %s\n", |
996c9314 | 10895 | "", |
96b663a3 | 10896 | &path->nexthop, |
996c9314 LB |
10897 | ifindex2ifname( |
10898 | path->ifindex, | |
10899 | ospf->vrf_id)); | |
0f478e30 | 10900 | } |
d62a17ae | 10901 | } |
10902 | } | |
10903 | } | |
10904 | } | |
0f478e30 CS |
10905 | } |
10906 | if (!json) | |
10907 | vty_out(vty, "\n"); | |
d62a17ae | 10908 | } |
10909 | ||
b5a8894d | 10910 | static void show_ip_ospf_route_external(struct vty *vty, struct ospf *ospf, |
0f478e30 CS |
10911 | struct route_table *rt, |
10912 | json_object *json) | |
d62a17ae | 10913 | { |
10914 | struct route_node *rn; | |
10915 | struct ospf_route *er; | |
10916 | struct listnode *pnode, *pnnode; | |
10917 | struct ospf_path *path; | |
96b663a3 | 10918 | char buf[PREFIX_STRLEN]; |
0f478e30 CS |
10919 | json_object *json_route = NULL, *json_nexthop_array = NULL, |
10920 | *json_nexthop = NULL; | |
d62a17ae | 10921 | |
0f478e30 | 10922 | if (!json) |
996c9314 LB |
10923 | vty_out(vty, |
10924 | "============ OSPF external routing table ===========\n"); | |
0f478e30 CS |
10925 | |
10926 | for (rn = route_top(rt); rn; rn = route_next(rn)) { | |
10927 | if ((er = rn->info) == NULL) | |
10928 | continue; | |
10929 | ||
10930 | char buf1[19]; | |
10931 | ||
96b663a3 | 10932 | snprintfrr(buf1, sizeof(buf1), "%pFX", &rn->p); |
19d37e54 DS |
10933 | if (json) { |
10934 | json_route = json_object_new_object(); | |
996c9314 | 10935 | json_object_object_add(json, buf1, json_route); |
19d37e54 | 10936 | } |
d62a17ae | 10937 | |
0f478e30 CS |
10938 | switch (er->path_type) { |
10939 | case OSPF_PATH_TYPE1_EXTERNAL: | |
10940 | if (json) { | |
996c9314 | 10941 | json_object_string_add(json_route, "routeType", |
0f478e30 CS |
10942 | "N E1"); |
10943 | json_object_int_add(json_route, "cost", | |
996c9314 | 10944 | er->cost); |
67df3649 MR |
10945 | json_object_int_add(json_route, "tag", |
10946 | er->u.ext.tag); | |
0f478e30 | 10947 | } else { |
d62a17ae | 10948 | vty_out(vty, |
996c9314 LB |
10949 | "N E1 %-18s [%d] tag: %" ROUTE_TAG_PRI |
10950 | "\n", | |
10951 | buf1, er->cost, er->u.ext.tag); | |
0f478e30 CS |
10952 | } |
10953 | break; | |
10954 | case OSPF_PATH_TYPE2_EXTERNAL: | |
10955 | if (json) { | |
996c9314 | 10956 | json_object_string_add(json_route, "routeType", |
0f478e30 CS |
10957 | "N E2"); |
10958 | json_object_int_add(json_route, "cost", | |
996c9314 | 10959 | er->cost); |
67df3649 MR |
10960 | json_object_int_add(json_route, "type2cost", |
10961 | er->u.ext.type2_cost); | |
10962 | json_object_int_add(json_route, "tag", | |
10963 | er->u.ext.tag); | |
0f478e30 | 10964 | } else { |
d62a17ae | 10965 | vty_out(vty, |
996c9314 LB |
10966 | "N E2 %-18s [%d/%d] tag: %" ROUTE_TAG_PRI |
10967 | "\n", | |
10968 | buf1, er->cost, er->u.ext.type2_cost, | |
d62a17ae | 10969 | er->u.ext.tag); |
d62a17ae | 10970 | } |
0f478e30 CS |
10971 | break; |
10972 | } | |
d62a17ae | 10973 | |
0f478e30 CS |
10974 | if (json) { |
10975 | json_nexthop_array = json_object_new_array(); | |
10976 | json_object_object_add(json_route, "nexthops", | |
996c9314 | 10977 | json_nexthop_array); |
0f478e30 CS |
10978 | } |
10979 | ||
996c9314 | 10980 | for (ALL_LIST_ELEMENTS(er->paths, pnode, pnnode, path)) { |
0f478e30 CS |
10981 | if (json) { |
10982 | json_nexthop = json_object_new_object(); | |
996c9314 LB |
10983 | json_object_array_add(json_nexthop_array, |
10984 | json_nexthop); | |
0f478e30 CS |
10985 | } |
10986 | ||
996c9314 | 10987 | if (if_lookup_by_index(path->ifindex, ospf->vrf_id)) { |
3a6290bd | 10988 | if (path->nexthop.s_addr == INADDR_ANY) { |
0f478e30 CS |
10989 | if (json) { |
10990 | json_object_string_add( | |
996c9314 LB |
10991 | json_nexthop, "ip", |
10992 | " "); | |
0f478e30 CS |
10993 | json_object_string_add( |
10994 | json_nexthop, | |
10995 | "directly attached to", | |
d62a17ae | 10996 | ifindex2ifname( |
996c9314 LB |
10997 | path->ifindex, |
10998 | ospf->vrf_id)); | |
0f478e30 | 10999 | } else { |
d62a17ae | 11000 | vty_out(vty, |
996c9314 LB |
11001 | "%24s directly attached to %s\n", |
11002 | "", | |
11003 | ifindex2ifname( | |
11004 | path->ifindex, | |
11005 | ospf->vrf_id)); | |
0f478e30 CS |
11006 | } |
11007 | } else { | |
11008 | if (json) { | |
11009 | json_object_string_add( | |
996c9314 | 11010 | json_nexthop, "ip", |
96b663a3 MS |
11011 | inet_ntop( |
11012 | AF_INET, | |
11013 | &path->nexthop, | |
11014 | buf, | |
11015 | sizeof(buf))); | |
0f478e30 | 11016 | json_object_string_add( |
996c9314 | 11017 | json_nexthop, "via", |
d62a17ae | 11018 | ifindex2ifname( |
996c9314 LB |
11019 | path->ifindex, |
11020 | ospf->vrf_id)); | |
0f478e30 CS |
11021 | } else { |
11022 | vty_out(vty, | |
96b663a3 | 11023 | "%24s via %pI4, %s\n", |
996c9314 | 11024 | "", |
96b663a3 | 11025 | &path->nexthop, |
996c9314 LB |
11026 | ifindex2ifname( |
11027 | path->ifindex, | |
11028 | ospf->vrf_id)); | |
0f478e30 | 11029 | } |
d62a17ae | 11030 | } |
54bedb55 | 11031 | } |
d62a17ae | 11032 | } |
0f478e30 CS |
11033 | } |
11034 | if (!json) | |
11035 | vty_out(vty, "\n"); | |
718e3744 | 11036 | } |
11037 | ||
d62a17ae | 11038 | static int show_ip_ospf_border_routers_common(struct vty *vty, |
d7c0a89a QY |
11039 | struct ospf *ospf, |
11040 | uint8_t use_vrf) | |
718e3744 | 11041 | { |
d62a17ae | 11042 | if (ospf->instance) |
11043 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
718e3744 | 11044 | |
b1c3ae8c | 11045 | ospf_show_vrf_name(ospf, vty, NULL, use_vrf); |
87bd50e8 | 11046 | |
d62a17ae | 11047 | if (ospf->new_table == NULL) { |
11048 | vty_out(vty, "No OSPF routing information exist\n"); | |
11049 | return CMD_SUCCESS; | |
11050 | } | |
718e3744 | 11051 | |
d62a17ae | 11052 | /* Show Network routes. |
11053 | show_ip_ospf_route_network (vty, ospf->new_table); */ | |
718e3744 | 11054 | |
d62a17ae | 11055 | /* Show Router routes. */ |
0f478e30 | 11056 | show_ip_ospf_route_router(vty, ospf, ospf->new_rtrs, NULL); |
718e3744 | 11057 | |
d62a17ae | 11058 | vty_out(vty, "\n"); |
7c8ff89e | 11059 | |
d62a17ae | 11060 | return CMD_SUCCESS; |
718e3744 | 11061 | } |
718e3744 | 11062 | |
7c8ff89e DS |
11063 | DEFUN (show_ip_ospf_border_routers, |
11064 | show_ip_ospf_border_routers_cmd, | |
b5a8894d | 11065 | "show ip ospf [vrf <NAME|all>] border-routers", |
718e3744 | 11066 | SHOW_STR |
11067 | IP_STR | |
11068 | "OSPF information\n" | |
b5a8894d CS |
11069 | VRF_CMD_HELP_STR |
11070 | "All VRFs\n" | |
7c8ff89e | 11071 | "Show all the ABR's and ASBR's\n") |
718e3744 | 11072 | { |
b5a8894d CS |
11073 | struct ospf *ospf = NULL; |
11074 | struct listnode *node = NULL; | |
11075 | char *vrf_name = NULL; | |
2951a7a4 | 11076 | bool all_vrf = false; |
b5a8894d CS |
11077 | int ret = CMD_SUCCESS; |
11078 | int inst = 0; | |
11079 | int idx_vrf = 0; | |
d7c0a89a | 11080 | uint8_t use_vrf = 0; |
68980084 | 11081 | |
43b8d1d8 | 11082 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
7c8ff89e | 11083 | |
b5a8894d | 11084 | if (vrf_name) { |
2951a7a4 | 11085 | bool ospf_output = false; |
874f58d8 | 11086 | |
b1c3ae8c | 11087 | use_vrf = 1; |
94d4c685 | 11088 | |
b5a8894d CS |
11089 | if (all_vrf) { |
11090 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
11091 | if (!ospf->oi_running) | |
11092 | continue; | |
b5a8894d | 11093 | |
2951a7a4 | 11094 | ospf_output = true; |
996c9314 LB |
11095 | ret = show_ip_ospf_border_routers_common( |
11096 | vty, ospf, use_vrf); | |
b5a8894d | 11097 | } |
9f049418 DS |
11098 | |
11099 | if (!ospf_output) | |
94d4c685 | 11100 | vty_out(vty, "%% OSPF instance not found\n"); |
b5a8894d CS |
11101 | } else { |
11102 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
9f049418 | 11103 | if (ospf == NULL || !ospf->oi_running) { |
94d4c685 | 11104 | vty_out(vty, "%% OSPF instance not found\n"); |
b5a8894d | 11105 | return CMD_SUCCESS; |
9f049418 | 11106 | } |
b5a8894d | 11107 | |
b1c3ae8c CS |
11108 | ret = show_ip_ospf_border_routers_common(vty, ospf, |
11109 | use_vrf); | |
b5a8894d CS |
11110 | } |
11111 | } else { | |
11112 | /* Display default ospf (instance 0) info */ | |
11113 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
9f049418 | 11114 | if (ospf == NULL || !ospf->oi_running) { |
94d4c685 | 11115 | vty_out(vty, "%% OSPF instance not found\n"); |
b5a8894d | 11116 | return CMD_SUCCESS; |
9f049418 DS |
11117 | } |
11118 | ||
b1c3ae8c | 11119 | ret = show_ip_ospf_border_routers_common(vty, ospf, use_vrf); |
b5a8894d CS |
11120 | } |
11121 | ||
11122 | return ret; | |
7c8ff89e DS |
11123 | } |
11124 | ||
11125 | DEFUN (show_ip_ospf_instance_border_routers, | |
11126 | show_ip_ospf_instance_border_routers_cmd, | |
6147e2c6 | 11127 | "show ip ospf (1-65535) border-routers", |
7c8ff89e DS |
11128 | SHOW_STR |
11129 | IP_STR | |
11130 | "OSPF information\n" | |
11131 | "Instance ID\n" | |
11132 | "Show all the ABR's and ASBR's\n") | |
11133 | { | |
d62a17ae | 11134 | int idx_number = 3; |
11135 | struct ospf *ospf; | |
d7c0a89a | 11136 | unsigned short instance = 0; |
7c8ff89e | 11137 | |
d62a17ae | 11138 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
409f98ab | 11139 | if (instance != ospf_instance) |
ac28e4ec CS |
11140 | return CMD_NOT_MY_INSTANCE; |
11141 | ||
409f98ab IR |
11142 | ospf = ospf_lookup_instance(instance); |
11143 | if (!ospf || !ospf->oi_running) | |
d62a17ae | 11144 | return CMD_SUCCESS; |
7c8ff89e | 11145 | |
b1c3ae8c | 11146 | return show_ip_ospf_border_routers_common(vty, ospf, 0); |
7c8ff89e DS |
11147 | } |
11148 | ||
b1c3ae8c | 11149 | static int show_ip_ospf_route_common(struct vty *vty, struct ospf *ospf, |
d7c0a89a | 11150 | json_object *json, uint8_t use_vrf) |
7c8ff89e | 11151 | { |
0f478e30 CS |
11152 | json_object *json_vrf = NULL; |
11153 | ||
d62a17ae | 11154 | if (ospf->instance) |
11155 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
718e3744 | 11156 | |
0f478e30 CS |
11157 | |
11158 | if (json) { | |
11159 | if (use_vrf) | |
11160 | json_vrf = json_object_new_object(); | |
11161 | else | |
11162 | json_vrf = json; | |
11163 | } | |
11164 | ||
11165 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); | |
87bd50e8 | 11166 | |
d62a17ae | 11167 | if (ospf->new_table == NULL) { |
11168 | vty_out(vty, "No OSPF routing information exist\n"); | |
11169 | return CMD_SUCCESS; | |
11170 | } | |
718e3744 | 11171 | |
d62a17ae | 11172 | /* Show Network routes. */ |
0f478e30 | 11173 | show_ip_ospf_route_network(vty, ospf, ospf->new_table, json_vrf); |
718e3744 | 11174 | |
d62a17ae | 11175 | /* Show Router routes. */ |
0f478e30 | 11176 | show_ip_ospf_route_router(vty, ospf, ospf->new_rtrs, json_vrf); |
718e3744 | 11177 | |
d62a17ae | 11178 | /* Show AS External routes. */ |
0f478e30 CS |
11179 | show_ip_ospf_route_external(vty, ospf, ospf->old_external_route, |
11180 | json_vrf); | |
718e3744 | 11181 | |
0f478e30 CS |
11182 | if (json) { |
11183 | if (use_vrf) { | |
996c9314 LB |
11184 | // json_object_object_add(json_vrf, "areas", |
11185 | // json_areas); | |
0f478e30 CS |
11186 | if (ospf->vrf_id == VRF_DEFAULT) |
11187 | json_object_object_add(json, "default", | |
11188 | json_vrf); | |
11189 | else | |
11190 | json_object_object_add(json, ospf->name, | |
11191 | json_vrf); | |
11192 | } | |
11193 | } else { | |
11194 | vty_out(vty, "\n"); | |
11195 | } | |
7c8ff89e | 11196 | |
d62a17ae | 11197 | return CMD_SUCCESS; |
718e3744 | 11198 | } |
11199 | ||
7c8ff89e DS |
11200 | DEFUN (show_ip_ospf_route, |
11201 | show_ip_ospf_route_cmd, | |
0f478e30 | 11202 | "show ip ospf [vrf <NAME|all>] route [json]", |
b5a8894d CS |
11203 | SHOW_STR |
11204 | IP_STR | |
11205 | "OSPF information\n" | |
11206 | VRF_CMD_HELP_STR | |
11207 | "All VRFs\n" | |
0f478e30 CS |
11208 | "OSPF routing table\n" |
11209 | JSON_STR) | |
b5a8894d CS |
11210 | { |
11211 | struct ospf *ospf = NULL; | |
11212 | struct listnode *node = NULL; | |
11213 | char *vrf_name = NULL; | |
2951a7a4 | 11214 | bool all_vrf = false; |
b5a8894d CS |
11215 | int ret = CMD_SUCCESS; |
11216 | int inst = 0; | |
11217 | int idx_vrf = 0; | |
d7c0a89a | 11218 | uint8_t use_vrf = 0; |
9f049418 | 11219 | bool uj = use_json(argc, argv); |
0f478e30 CS |
11220 | json_object *json = NULL; |
11221 | ||
11222 | if (uj) | |
11223 | json = json_object_new_object(); | |
7c8ff89e | 11224 | |
43b8d1d8 | 11225 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
7c8ff89e | 11226 | |
b5a8894d CS |
11227 | /* vrf input is provided could be all or specific vrf*/ |
11228 | if (vrf_name) { | |
2951a7a4 | 11229 | bool ospf_output = false; |
874f58d8 | 11230 | |
b1c3ae8c | 11231 | use_vrf = 1; |
94d4c685 | 11232 | |
b5a8894d CS |
11233 | if (all_vrf) { |
11234 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
11235 | if (!ospf->oi_running) | |
11236 | continue; | |
2951a7a4 | 11237 | ospf_output = true; |
0f478e30 | 11238 | ret = show_ip_ospf_route_common(vty, ospf, json, |
b1c3ae8c | 11239 | use_vrf); |
b5a8894d | 11240 | } |
0f478e30 CS |
11241 | |
11242 | if (uj) { | |
1406159f | 11243 | /* Keep Non-pretty format */ |
0f478e30 | 11244 | vty_out(vty, "%s\n", |
e77564cc DS |
11245 | json_object_to_json_string_ext( |
11246 | json, | |
11247 | JSON_C_TO_STRING_NOSLASHESCAPE)); | |
0f478e30 | 11248 | json_object_free(json); |
9f049418 DS |
11249 | } else if (!ospf_output) |
11250 | vty_out(vty, "%% OSPF instance not found\n"); | |
0f478e30 | 11251 | |
b5a8894d CS |
11252 | return ret; |
11253 | } | |
11254 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
0f478e30 | 11255 | if (ospf == NULL || !ospf->oi_running) { |
9f049418 DS |
11256 | if (uj) { |
11257 | vty_out(vty, "%s\n", | |
11258 | json_object_to_json_string_ext( | |
e77564cc DS |
11259 | json, |
11260 | JSON_C_TO_STRING_PRETTY | |
11261 | | JSON_C_TO_STRING_NOSLASHESCAPE)); | |
0f478e30 | 11262 | json_object_free(json); |
9f049418 | 11263 | } else |
94d4c685 | 11264 | vty_out(vty, "%% OSPF instance not found\n"); |
9f049418 | 11265 | |
b5a8894d | 11266 | return CMD_SUCCESS; |
0f478e30 | 11267 | } |
b5a8894d CS |
11268 | } else { |
11269 | /* Display default ospf (instance 0) info */ | |
11270 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
0f478e30 | 11271 | if (ospf == NULL || !ospf->oi_running) { |
9f049418 DS |
11272 | if (uj) { |
11273 | vty_out(vty, "%s\n", | |
11274 | json_object_to_json_string_ext( | |
e77564cc DS |
11275 | json, |
11276 | JSON_C_TO_STRING_PRETTY | |
11277 | | JSON_C_TO_STRING_NOSLASHESCAPE)); | |
0f478e30 | 11278 | json_object_free(json); |
9f049418 | 11279 | } else |
94d4c685 | 11280 | vty_out(vty, "%% OSPF instance not found\n"); |
9f049418 | 11281 | |
b5a8894d | 11282 | return CMD_SUCCESS; |
0f478e30 CS |
11283 | } |
11284 | } | |
11285 | ||
11286 | if (ospf) { | |
11287 | ret = show_ip_ospf_route_common(vty, ospf, json, use_vrf); | |
1406159f | 11288 | /* Keep Non-pretty format */ |
0f478e30 | 11289 | if (uj) |
e77564cc DS |
11290 | vty_out(vty, "%s\n", |
11291 | json_object_to_json_string_ext( | |
11292 | json, JSON_C_TO_STRING_NOSLASHESCAPE)); | |
b5a8894d CS |
11293 | } |
11294 | ||
0f478e30 CS |
11295 | if (uj) |
11296 | json_object_free(json); | |
b5a8894d CS |
11297 | |
11298 | return ret; | |
7c8ff89e DS |
11299 | } |
11300 | ||
11301 | DEFUN (show_ip_ospf_instance_route, | |
11302 | show_ip_ospf_instance_route_cmd, | |
6147e2c6 | 11303 | "show ip ospf (1-65535) route", |
7c8ff89e DS |
11304 | SHOW_STR |
11305 | IP_STR | |
11306 | "OSPF information\n" | |
11307 | "Instance ID\n" | |
11308 | "OSPF routing table\n") | |
11309 | { | |
d62a17ae | 11310 | int idx_number = 3; |
11311 | struct ospf *ospf; | |
d7c0a89a | 11312 | unsigned short instance = 0; |
7c8ff89e | 11313 | |
d62a17ae | 11314 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
409f98ab | 11315 | if (instance != ospf_instance) |
ac28e4ec CS |
11316 | return CMD_NOT_MY_INSTANCE; |
11317 | ||
409f98ab IR |
11318 | ospf = ospf_lookup_instance(instance); |
11319 | if (!ospf || !ospf->oi_running) | |
d62a17ae | 11320 | return CMD_SUCCESS; |
7c8ff89e | 11321 | |
0f478e30 | 11322 | return show_ip_ospf_route_common(vty, ospf, NULL, 0); |
7c8ff89e | 11323 | } |
6b0655a2 | 11324 | |
b5a8894d CS |
11325 | |
11326 | DEFUN (show_ip_ospf_vrfs, | |
11327 | show_ip_ospf_vrfs_cmd, | |
11328 | "show ip ospf vrfs [json]", | |
11329 | SHOW_STR | |
11330 | IP_STR | |
11331 | "OSPF information\n" | |
11332 | "Show OSPF VRFs \n" | |
11333 | JSON_STR) | |
11334 | { | |
9f049418 | 11335 | bool uj = use_json(argc, argv); |
b5a8894d CS |
11336 | json_object *json = NULL; |
11337 | json_object *json_vrfs = NULL; | |
11338 | struct ospf *ospf = NULL; | |
11339 | struct listnode *node = NULL; | |
11340 | int count = 0; | |
96b663a3 | 11341 | char buf[PREFIX_STRLEN]; |
2b64873d | 11342 | static const char header[] = "Name Id RouterId "; |
b5a8894d CS |
11343 | |
11344 | if (uj) { | |
11345 | json = json_object_new_object(); | |
11346 | json_vrfs = json_object_new_object(); | |
11347 | } | |
11348 | ||
11349 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
11350 | json_object *json_vrf = NULL; | |
11351 | const char *name = NULL; | |
fe3da9e7 | 11352 | int64_t vrf_id_ui = 0; |
b5a8894d CS |
11353 | |
11354 | count++; | |
11355 | ||
11356 | if (!uj && count == 1) | |
11357 | vty_out(vty, "%s\n", header); | |
11358 | if (uj) | |
11359 | json_vrf = json_object_new_object(); | |
11360 | ||
946de1b9 | 11361 | if (ospf->vrf_id == VRF_DEFAULT) |
b5a8894d CS |
11362 | name = VRF_DEFAULT_NAME; |
11363 | else | |
11364 | name = ospf->name; | |
11365 | ||
996c9314 LB |
11366 | vrf_id_ui = (ospf->vrf_id == VRF_UNKNOWN) |
11367 | ? -1 | |
11368 | : (int64_t)ospf->vrf_id; | |
b5a8894d CS |
11369 | |
11370 | if (uj) { | |
11371 | json_object_int_add(json_vrf, "vrfId", vrf_id_ui); | |
96b663a3 MS |
11372 | json_object_string_add( |
11373 | json_vrf, "routerId", | |
11374 | inet_ntop(AF_INET, &ospf->router_id, | |
11375 | buf, sizeof(buf))); | |
b5a8894d CS |
11376 | |
11377 | json_object_object_add(json_vrfs, name, json_vrf); | |
11378 | ||
11379 | } else { | |
96b663a3 MS |
11380 | vty_out(vty, "%-25s %-5d %-16pI4 \n", name, |
11381 | ospf->vrf_id, &ospf->router_id); | |
b5a8894d CS |
11382 | } |
11383 | } | |
11384 | ||
11385 | if (uj) { | |
11386 | json_object_object_add(json, "vrfs", json_vrfs); | |
11387 | json_object_int_add(json, "totalVrfs", count); | |
11388 | ||
996c9314 LB |
11389 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
11390 | json, JSON_C_TO_STRING_PRETTY)); | |
b5a8894d CS |
11391 | json_object_free(json); |
11392 | } else { | |
11393 | if (count) | |
34d6798f | 11394 | vty_out(vty, "\nTotal number of OSPF VRFs: %d\n", |
b5a8894d CS |
11395 | count); |
11396 | } | |
11397 | ||
11398 | return CMD_SUCCESS; | |
11399 | } | |
f91ce319 MR |
11400 | DEFPY (clear_ip_ospf_neighbor, |
11401 | clear_ip_ospf_neighbor_cmd, | |
11402 | "clear ip ospf [(1-65535)]$instance neighbor [A.B.C.D$nbr_id]", | |
11403 | CLEAR_STR | |
11404 | IP_STR | |
11405 | "OSPF information\n" | |
11406 | "Instance ID\n" | |
11407 | "Reset OSPF Neighbor\n" | |
11408 | "Neighbor ID\n") | |
11409 | { | |
11410 | struct listnode *node; | |
11411 | struct ospf *ospf = NULL; | |
11412 | ||
11413 | /* If user does not specify the arguments, | |
11414 | * instance = 0 and nbr_id = 0.0.0.0 | |
11415 | */ | |
11416 | if (instance != 0) { | |
11417 | /* This means clear only the particular ospf process */ | |
409f98ab | 11418 | if (instance != ospf_instance) |
f91ce319 MR |
11419 | return CMD_NOT_MY_INSTANCE; |
11420 | } | |
11421 | ||
11422 | /* Clear all the ospf processes */ | |
11423 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
11424 | if (!ospf->oi_running) | |
11425 | continue; | |
11426 | ||
c88ad8ec | 11427 | if (nbr_id_str && IPV4_ADDR_SAME(&ospf->router_id, &nbr_id)) { |
11428 | vty_out(vty, "Self router-id is not allowed.\r\n "); | |
11429 | return CMD_SUCCESS; | |
11430 | } | |
11431 | ||
f91ce319 MR |
11432 | ospf_neighbor_reset(ospf, nbr_id, nbr_id_str); |
11433 | } | |
11434 | ||
11435 | return CMD_SUCCESS; | |
11436 | } | |
11437 | ||
11438 | DEFPY (clear_ip_ospf_process, | |
11439 | clear_ip_ospf_process_cmd, | |
11440 | "clear ip ospf [(1-65535)]$instance process", | |
11441 | CLEAR_STR | |
11442 | IP_STR | |
11443 | "OSPF information\n" | |
11444 | "Instance ID\n" | |
11445 | "Reset OSPF Process\n") | |
11446 | { | |
11447 | struct listnode *node; | |
11448 | struct ospf *ospf = NULL; | |
11449 | ||
11450 | /* Check if instance is not passed as an argument */ | |
11451 | if (instance != 0) { | |
11452 | /* This means clear only the particular ospf process */ | |
409f98ab | 11453 | if (instance != ospf_instance) |
f91ce319 MR |
11454 | return CMD_NOT_MY_INSTANCE; |
11455 | } | |
11456 | ||
11457 | /* Clear all the ospf processes */ | |
11458 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
11459 | if (!ospf->oi_running) | |
11460 | continue; | |
11461 | ||
11462 | ospf_process_reset(ospf); | |
11463 | } | |
11464 | ||
11465 | return CMD_SUCCESS; | |
11466 | } | |
b5a8894d | 11467 | |
2b64873d DL |
11468 | static const char *const ospf_abr_type_str[] = { |
11469 | "unknown", "standard", "ibm", "cisco", "shortcut" | |
11470 | }; | |
718e3744 | 11471 | |
2b64873d DL |
11472 | static const char *const ospf_shortcut_mode_str[] = { |
11473 | "default", "enable", "disable" | |
11474 | }; | |
1ac88792 | 11475 | static int ospf_vty_external_rt_walkcb(struct hash_bucket *bucket, |
53e44d05 | 11476 | void *arg) |
11477 | { | |
1ac88792 | 11478 | struct external_info *ei = bucket->data; |
53e44d05 | 11479 | struct vty *vty = (struct vty *)arg; |
11480 | static unsigned int count; | |
11481 | ||
11482 | vty_out(vty, "%-4pI4/%d, ", &ei->p.prefix, ei->p.prefixlen); | |
11483 | count++; | |
11484 | ||
11485 | if (count % 5 == 0) | |
11486 | vty_out(vty, "\n"); | |
11487 | ||
11488 | if (OSPF_EXTERNAL_RT_COUNT(ei->aggr_route) == count) | |
11489 | count = 0; | |
11490 | ||
11491 | return HASHWALK_CONTINUE; | |
11492 | } | |
11493 | ||
1ac88792 | 11494 | static int ospf_json_external_rt_walkcb(struct hash_bucket *bucket, |
53e44d05 | 11495 | void *arg) |
11496 | { | |
1ac88792 | 11497 | struct external_info *ei = bucket->data; |
53e44d05 | 11498 | struct json_object *json = (struct json_object *)arg; |
11499 | char buf[PREFIX2STR_BUFFER]; | |
11500 | char exnalbuf[20]; | |
11501 | static unsigned int count; | |
11502 | ||
11503 | prefix2str(&ei->p, buf, sizeof(buf)); | |
11504 | ||
11505 | snprintf(exnalbuf, 20, "Exnl Addr-%d", count); | |
11506 | ||
11507 | json_object_string_add(json, exnalbuf, buf); | |
11508 | ||
11509 | count++; | |
11510 | ||
11511 | if (OSPF_EXTERNAL_RT_COUNT(ei->aggr_route) == count) | |
11512 | count = 0; | |
11513 | ||
11514 | return HASHWALK_CONTINUE; | |
11515 | } | |
11516 | ||
11517 | static int ospf_show_summary_address(struct vty *vty, struct ospf *ospf, | |
11518 | uint8_t use_vrf, json_object *json, | |
11519 | bool uj, bool detail) | |
11520 | { | |
11521 | struct route_node *rn; | |
11522 | json_object *json_vrf = NULL; | |
11523 | int mtype = 0; | |
11524 | int mval = 0; | |
11525 | static char header[] = | |
11526 | "Summary-address Metric-type Metric Tag External_Rt_count\n"; | |
11527 | ||
11528 | mtype = metric_type(ospf, 0, ospf->instance); | |
11529 | mval = metric_value(ospf, 0, ospf->instance); | |
11530 | ||
11531 | if (!uj) | |
11532 | vty_out(vty, "%s\n", header); | |
11533 | ||
11534 | if (uj) { | |
11535 | if (use_vrf) | |
11536 | json_vrf = json_object_new_object(); | |
11537 | else | |
11538 | json_vrf = json; | |
11539 | } | |
11540 | ||
11541 | if (ospf->instance) { | |
11542 | if (uj) | |
11543 | json_object_int_add(json, "ospfInstance", | |
11544 | ospf->instance); | |
11545 | else | |
11546 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
11547 | } | |
11548 | ||
11549 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); | |
11550 | ||
11551 | if (!uj) | |
11552 | vty_out(vty, "aggregation delay interval :%d(in seconds)\n\n", | |
11553 | ospf->aggr_delay_interval); | |
11554 | else | |
11555 | json_object_int_add(json_vrf, "aggregation delay interval", | |
11556 | ospf->aggr_delay_interval); | |
11557 | ||
11558 | for (rn = route_top(ospf->rt_aggr_tbl); rn; rn = route_next(rn)) | |
11559 | if (rn->info) { | |
11560 | struct ospf_external_aggr_rt *aggr = rn->info; | |
11561 | json_object *json_aggr = NULL; | |
11562 | char buf[PREFIX2STR_BUFFER]; | |
11563 | ||
11564 | prefix2str(&aggr->p, buf, sizeof(buf)); | |
11565 | ||
11566 | if (uj) { | |
11567 | ||
11568 | json_aggr = json_object_new_object(); | |
11569 | ||
11570 | json_object_object_add(json_vrf, buf, | |
11571 | json_aggr); | |
11572 | ||
11573 | json_object_string_add(json_aggr, | |
11574 | "Summary address", buf); | |
11575 | ||
11576 | json_object_string_add( | |
11577 | json_aggr, "Metric-type", | |
11578 | (mtype == EXTERNAL_METRIC_TYPE_1) | |
11579 | ? "E1" | |
11580 | : "E2"); | |
11581 | ||
11582 | json_object_int_add(json_aggr, "Metric", mval); | |
11583 | ||
11584 | json_object_int_add(json_aggr, "Tag", | |
11585 | aggr->tag); | |
11586 | ||
11587 | json_object_int_add( | |
11588 | json_aggr, "External route count", | |
11589 | OSPF_EXTERNAL_RT_COUNT(aggr)); | |
11590 | ||
11591 | if (OSPF_EXTERNAL_RT_COUNT(aggr) && detail) { | |
11592 | hash_walk( | |
11593 | aggr->match_extnl_hash, | |
11594 | ospf_json_external_rt_walkcb, | |
11595 | json_aggr); | |
11596 | } | |
11597 | ||
11598 | } else { | |
11599 | vty_out(vty, "%-20s", buf); | |
11600 | ||
11601 | (mtype == EXTERNAL_METRIC_TYPE_1) | |
11602 | ? vty_out(vty, "%-16s", "E1") | |
11603 | : vty_out(vty, "%-16s", "E2"); | |
11604 | vty_out(vty, "%-11d", mval); | |
11605 | ||
11606 | vty_out(vty, "%-12u", aggr->tag); | |
11607 | ||
11608 | vty_out(vty, "%-5ld\n", | |
11609 | OSPF_EXTERNAL_RT_COUNT(aggr)); | |
11610 | ||
11611 | if (OSPF_EXTERNAL_RT_COUNT(aggr) && detail) { | |
11612 | vty_out(vty, | |
11613 | "Matched External routes:\n"); | |
11614 | hash_walk( | |
11615 | aggr->match_extnl_hash, | |
11616 | ospf_vty_external_rt_walkcb, | |
11617 | vty); | |
11618 | vty_out(vty, "\n"); | |
11619 | } | |
11620 | ||
11621 | vty_out(vty, "\n"); | |
11622 | } | |
11623 | } | |
11624 | ||
11625 | if (uj) { | |
11626 | if (use_vrf) { | |
11627 | if (ospf->vrf_id == VRF_DEFAULT) | |
11628 | json_object_object_add(json, "default", | |
11629 | json_vrf); | |
11630 | else | |
11631 | json_object_object_add(json, ospf->name, | |
11632 | json_vrf); | |
11633 | } | |
11634 | } else | |
11635 | vty_out(vty, "\n"); | |
11636 | ||
11637 | return CMD_SUCCESS; | |
11638 | } | |
11639 | ||
11640 | DEFUN (show_ip_ospf_external_aggregator, | |
11641 | show_ip_ospf_external_aggregator_cmd, | |
11642 | "show ip ospf [vrf <NAME|all>] summary-address [detail] [json]", | |
11643 | SHOW_STR IP_STR | |
11644 | "OSPF information\n" | |
11645 | VRF_CMD_HELP_STR | |
11646 | "All VRFs\n" | |
11647 | "Show external summary addresses\n" | |
11648 | "Detailed informtion\n" | |
11649 | JSON_STR) | |
11650 | { | |
11651 | char *vrf_name = NULL; | |
11652 | bool all_vrf = false; | |
11653 | int ret = CMD_SUCCESS; | |
11654 | int idx_vrf = 0; | |
11655 | int idx = 0; | |
11656 | uint8_t use_vrf = 0; | |
11657 | bool uj = use_json(argc, argv); | |
11658 | struct ospf *ospf = NULL; | |
11659 | json_object *json = NULL; | |
11660 | struct listnode *node = NULL; | |
11661 | int inst = 0; | |
11662 | bool detail = false; | |
11663 | ||
11664 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); | |
11665 | ||
11666 | if (argv_find(argv, argc, "detail", &idx)) | |
11667 | detail = true; | |
11668 | ||
11669 | if (uj) | |
11670 | json = json_object_new_object(); | |
11671 | ||
11672 | /* vrf input is provided */ | |
11673 | if (vrf_name) { | |
11674 | use_vrf = 1; | |
11675 | if (all_vrf) { | |
11676 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
11677 | if (!ospf->oi_running) | |
11678 | continue; | |
11679 | ret = ospf_show_summary_address( | |
11680 | vty, ospf, use_vrf, json, uj, detail); | |
11681 | } | |
11682 | ||
11683 | if (uj) { | |
11684 | vty_out(vty, "%s\n", | |
11685 | json_object_to_json_string_ext( | |
11686 | json, JSON_C_TO_STRING_PRETTY)); | |
11687 | json_object_free(json); | |
11688 | } | |
11689 | ||
11690 | return ret; | |
11691 | } | |
11692 | ||
11693 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
11694 | ||
11695 | if (ospf == NULL || !ospf->oi_running) { | |
11696 | if (uj) { | |
11697 | vty_out(vty, "%s\n", | |
11698 | json_object_to_json_string_ext( | |
11699 | json, JSON_C_TO_STRING_PRETTY)); | |
11700 | json_object_free(json); | |
11701 | } else | |
11702 | vty_out(vty, "%% OSPF instance not found\n"); | |
11703 | ||
11704 | return CMD_SUCCESS; | |
11705 | } | |
fddbafcc | 11706 | ospf_show_summary_address(vty, ospf, use_vrf, json, uj, detail); |
53e44d05 | 11707 | |
11708 | } else { | |
11709 | /* Default Vrf */ | |
11710 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
11711 | if (ospf == NULL || !ospf->oi_running) { | |
11712 | if (uj) { | |
11713 | vty_out(vty, "%s\n", | |
11714 | json_object_to_json_string_ext( | |
11715 | json, JSON_C_TO_STRING_PRETTY)); | |
11716 | json_object_free(json); | |
11717 | } else | |
11718 | vty_out(vty, "%% OSPF instance not found\n"); | |
11719 | ||
11720 | return CMD_SUCCESS; | |
11721 | } | |
11722 | ||
11723 | ospf_show_summary_address(vty, ospf, use_vrf, json, uj, detail); | |
11724 | } | |
11725 | ||
11726 | if (uj) { | |
11727 | vty_out(vty, "%s\n", json_object_to_json_string_ext( | |
11728 | json, JSON_C_TO_STRING_PRETTY)); | |
11729 | json_object_free(json); | |
11730 | } | |
11731 | return CMD_SUCCESS; | |
11732 | } | |
718e3744 | 11733 | |
2b64873d DL |
11734 | static const char *const ospf_int_type_str[] = { |
11735 | "unknown", /* should never be used. */ | |
11736 | "point-to-point", | |
11737 | "broadcast", | |
11738 | "non-broadcast", | |
11739 | "point-to-multipoint", | |
11740 | "virtual-link", /* should never be used. */ | |
11741 | "loopback" | |
11742 | }; | |
718e3744 | 11743 | |
83cc5a1f DE |
11744 | static const char *interface_config_auth_str(struct ospf_if_params *params) |
11745 | { | |
11746 | if (!OSPF_IF_PARAM_CONFIGURED(params, auth_type) | |
11747 | || params->auth_type == OSPF_AUTH_NOTSET) | |
11748 | return NULL; | |
11749 | ||
11750 | /* Translation tables are not that much help | |
11751 | * here due to syntax | |
11752 | * of the simple option */ | |
11753 | switch (params->auth_type) { | |
11754 | ||
11755 | case OSPF_AUTH_NULL: | |
11756 | return " null"; | |
11757 | ||
11758 | case OSPF_AUTH_SIMPLE: | |
11759 | return ""; | |
11760 | ||
11761 | case OSPF_AUTH_CRYPTOGRAPHIC: | |
11762 | return " message-digest"; | |
11763 | } | |
11764 | ||
11765 | return ""; | |
11766 | } | |
11767 | ||
545f0503 | 11768 | static int config_write_interface_one(struct vty *vty, struct vrf *vrf) |
d62a17ae | 11769 | { |
f4e14fdb | 11770 | struct listnode *node; |
d62a17ae | 11771 | struct interface *ifp; |
11772 | struct crypt_key *ck; | |
d62a17ae | 11773 | struct route_node *rn = NULL; |
11774 | struct ospf_if_params *params; | |
83cc5a1f | 11775 | const char *auth_str; |
43b8d1d8 | 11776 | int write = 0; |
d62a17ae | 11777 | |
545f0503 | 11778 | FOR_ALL_INTERFACES (vrf, ifp) { |
d62a17ae | 11779 | |
545f0503 CS |
11780 | if (memcmp(ifp->name, "VLINK", 5) == 0) |
11781 | continue; | |
35955c14 | 11782 | |
545f0503 | 11783 | vty_frame(vty, "!\n"); |
a36898e7 | 11784 | if (ifp->vrf_id == VRF_DEFAULT) |
545f0503 CS |
11785 | vty_frame(vty, "interface %s\n", ifp->name); |
11786 | else | |
996c9314 LB |
11787 | vty_frame(vty, "interface %s vrf %s\n", ifp->name, |
11788 | vrf->name); | |
545f0503 CS |
11789 | if (ifp->desc) |
11790 | vty_out(vty, " description %s\n", ifp->desc); | |
d62a17ae | 11791 | |
545f0503 | 11792 | write++; |
43b8d1d8 | 11793 | |
545f0503 | 11794 | params = IF_DEF_PARAMS(ifp); |
43b8d1d8 | 11795 | |
545f0503 CS |
11796 | do { |
11797 | /* Interface Network print. */ | |
11798 | if (OSPF_IF_PARAM_CONFIGURED(params, type) | |
11799 | && params->type != OSPF_IFTYPE_LOOPBACK) { | |
996c9314 | 11800 | if (params->type != ospf_default_iftype(ifp)) { |
545f0503 CS |
11801 | vty_out(vty, " ip ospf network %s", |
11802 | ospf_int_type_str | |
996c9314 | 11803 | [params->type]); |
bc97889b AL |
11804 | if (params->type |
11805 | == OSPF_IFTYPE_POINTOPOINT | |
11806 | && params->ptp_dmvpn) | |
11807 | vty_out(vty, " dmvpn"); | |
e425c019 | 11808 | if (params != IF_DEF_PARAMS(ifp) && rn) |
96b663a3 MS |
11809 | vty_out(vty, " %pI4", |
11810 | &rn->p.u.prefix4); | |
545f0503 | 11811 | vty_out(vty, "\n"); |
d62a17ae | 11812 | } |
545f0503 | 11813 | } |
d62a17ae | 11814 | |
545f0503 | 11815 | /* OSPF interface authentication print */ |
83cc5a1f DE |
11816 | auth_str = interface_config_auth_str(params); |
11817 | if (auth_str) { | |
545f0503 CS |
11818 | vty_out(vty, " ip ospf authentication%s", |
11819 | auth_str); | |
e425c019 | 11820 | if (params != IF_DEF_PARAMS(ifp) && rn) |
96b663a3 MS |
11821 | vty_out(vty, " %pI4", |
11822 | &rn->p.u.prefix4); | |
545f0503 CS |
11823 | vty_out(vty, "\n"); |
11824 | } | |
d62a17ae | 11825 | |
545f0503 CS |
11826 | /* Simple Authentication Password print. */ |
11827 | if (OSPF_IF_PARAM_CONFIGURED(params, auth_simple) | |
996c9314 | 11828 | && params->auth_simple[0] != '\0') { |
545f0503 CS |
11829 | vty_out(vty, " ip ospf authentication-key %s", |
11830 | params->auth_simple); | |
e425c019 | 11831 | if (params != IF_DEF_PARAMS(ifp) && rn) |
96b663a3 MS |
11832 | vty_out(vty, " %pI4", |
11833 | &rn->p.u.prefix4); | |
545f0503 CS |
11834 | vty_out(vty, "\n"); |
11835 | } | |
c7fd72d2 | 11836 | |
545f0503 CS |
11837 | /* Cryptographic Authentication Key print. */ |
11838 | if (params && params->auth_crypt) { | |
996c9314 LB |
11839 | for (ALL_LIST_ELEMENTS_RO(params->auth_crypt, |
11840 | node, ck)) { | |
545f0503 CS |
11841 | vty_out(vty, |
11842 | " ip ospf message-digest-key %d md5 %s", | |
996c9314 | 11843 | ck->key_id, ck->auth_key); |
e425c019 | 11844 | if (params != IF_DEF_PARAMS(ifp) && rn) |
96b663a3 MS |
11845 | vty_out(vty, " %pI4", |
11846 | &rn->p.u.prefix4); | |
c7fd72d2 CS |
11847 | vty_out(vty, "\n"); |
11848 | } | |
545f0503 | 11849 | } |
d62a17ae | 11850 | |
545f0503 | 11851 | /* Interface Output Cost print. */ |
996c9314 | 11852 | if (OSPF_IF_PARAM_CONFIGURED(params, output_cost_cmd)) { |
545f0503 CS |
11853 | vty_out(vty, " ip ospf cost %u", |
11854 | params->output_cost_cmd); | |
e425c019 | 11855 | if (params != IF_DEF_PARAMS(ifp) && rn) |
96b663a3 MS |
11856 | vty_out(vty, " %pI4", |
11857 | &rn->p.u.prefix4); | |
545f0503 CS |
11858 | vty_out(vty, "\n"); |
11859 | } | |
d62a17ae | 11860 | |
545f0503 CS |
11861 | /* Hello Interval print. */ |
11862 | if (OSPF_IF_PARAM_CONFIGURED(params, v_hello) | |
996c9314 | 11863 | && params->v_hello != OSPF_HELLO_INTERVAL_DEFAULT) { |
545f0503 CS |
11864 | vty_out(vty, " ip ospf hello-interval %u", |
11865 | params->v_hello); | |
e425c019 | 11866 | if (params != IF_DEF_PARAMS(ifp) && rn) |
96b663a3 MS |
11867 | vty_out(vty, " %pI4", |
11868 | &rn->p.u.prefix4); | |
545f0503 CS |
11869 | vty_out(vty, "\n"); |
11870 | } | |
d62a17ae | 11871 | |
d62a17ae | 11872 | |
545f0503 CS |
11873 | /* Router Dead Interval print. */ |
11874 | if (OSPF_IF_PARAM_CONFIGURED(params, v_wait) | |
2c1f2d2a | 11875 | && params->is_v_wait_set) { |
545f0503 | 11876 | vty_out(vty, " ip ospf dead-interval "); |
d62a17ae | 11877 | |
545f0503 CS |
11878 | /* fast hello ? */ |
11879 | if (OSPF_IF_PARAM_CONFIGURED(params, | |
996c9314 | 11880 | fast_hello)) |
545f0503 CS |
11881 | vty_out(vty, |
11882 | "minimal hello-multiplier %d", | |
11883 | params->fast_hello); | |
11884 | else | |
996c9314 | 11885 | vty_out(vty, "%u", params->v_wait); |
d62a17ae | 11886 | |
e425c019 | 11887 | if (params != IF_DEF_PARAMS(ifp) && rn) |
96b663a3 MS |
11888 | vty_out(vty, " %pI4", |
11889 | &rn->p.u.prefix4); | |
545f0503 CS |
11890 | vty_out(vty, "\n"); |
11891 | } | |
d62a17ae | 11892 | |
545f0503 CS |
11893 | /* Router Priority print. */ |
11894 | if (OSPF_IF_PARAM_CONFIGURED(params, priority) | |
996c9314 LB |
11895 | && params->priority |
11896 | != OSPF_ROUTER_PRIORITY_DEFAULT) { | |
545f0503 CS |
11897 | vty_out(vty, " ip ospf priority %u", |
11898 | params->priority); | |
e425c019 | 11899 | if (params != IF_DEF_PARAMS(ifp) && rn) |
96b663a3 MS |
11900 | vty_out(vty, " %pI4", |
11901 | &rn->p.u.prefix4); | |
545f0503 CS |
11902 | vty_out(vty, "\n"); |
11903 | } | |
d62a17ae | 11904 | |
545f0503 CS |
11905 | /* Retransmit Interval print. */ |
11906 | if (OSPF_IF_PARAM_CONFIGURED(params, | |
996c9314 LB |
11907 | retransmit_interval) |
11908 | && params->retransmit_interval | |
11909 | != OSPF_RETRANSMIT_INTERVAL_DEFAULT) { | |
545f0503 CS |
11910 | vty_out(vty, " ip ospf retransmit-interval %u", |
11911 | params->retransmit_interval); | |
e425c019 | 11912 | if (params != IF_DEF_PARAMS(ifp) && rn) |
96b663a3 MS |
11913 | vty_out(vty, " %pI4", |
11914 | &rn->p.u.prefix4); | |
545f0503 CS |
11915 | vty_out(vty, "\n"); |
11916 | } | |
d62a17ae | 11917 | |
545f0503 | 11918 | /* Transmit Delay print. */ |
996c9314 LB |
11919 | if (OSPF_IF_PARAM_CONFIGURED(params, transmit_delay) |
11920 | && params->transmit_delay | |
11921 | != OSPF_TRANSMIT_DELAY_DEFAULT) { | |
545f0503 CS |
11922 | vty_out(vty, " ip ospf transmit-delay %u", |
11923 | params->transmit_delay); | |
e425c019 | 11924 | if (params != IF_DEF_PARAMS(ifp) && rn) |
96b663a3 MS |
11925 | vty_out(vty, " %pI4", |
11926 | &rn->p.u.prefix4); | |
545f0503 CS |
11927 | vty_out(vty, "\n"); |
11928 | } | |
d62a17ae | 11929 | |
545f0503 CS |
11930 | /* Area print. */ |
11931 | if (OSPF_IF_PARAM_CONFIGURED(params, if_area)) { | |
409f98ab | 11932 | if (ospf_instance) |
545f0503 | 11933 | vty_out(vty, " ip ospf %d", |
409f98ab | 11934 | ospf_instance); |
545f0503 CS |
11935 | else |
11936 | vty_out(vty, " ip ospf"); | |
d62a17ae | 11937 | |
1f9d4e3d | 11938 | char buf[INET_ADDRSTRLEN]; |
d62a17ae | 11939 | |
996c9314 LB |
11940 | area_id2str(buf, sizeof(buf), ¶ms->if_area, |
11941 | params->if_area_id_fmt); | |
545f0503 | 11942 | vty_out(vty, " area %s", buf); |
e425c019 | 11943 | if (params != IF_DEF_PARAMS(ifp) && rn) |
96b663a3 MS |
11944 | vty_out(vty, " %pI4", |
11945 | &rn->p.u.prefix4); | |
545f0503 CS |
11946 | vty_out(vty, "\n"); |
11947 | } | |
d62a17ae | 11948 | |
545f0503 | 11949 | /* bfd print. */ |
659f4e40 | 11950 | if (params && params->bfd_config) |
545f0503 | 11951 | ospf_bfd_write_config(vty, params); |
d62a17ae | 11952 | |
545f0503 CS |
11953 | /* MTU ignore print. */ |
11954 | if (OSPF_IF_PARAM_CONFIGURED(params, mtu_ignore) | |
996c9314 | 11955 | && params->mtu_ignore != OSPF_MTU_IGNORE_DEFAULT) { |
545f0503 CS |
11956 | if (params->mtu_ignore == 0) |
11957 | vty_out(vty, " no ip ospf mtu-ignore"); | |
11958 | else | |
11959 | vty_out(vty, " ip ospf mtu-ignore"); | |
e425c019 | 11960 | if (params != IF_DEF_PARAMS(ifp) && rn) |
96b663a3 MS |
11961 | vty_out(vty, " %pI4", |
11962 | &rn->p.u.prefix4); | |
545f0503 CS |
11963 | vty_out(vty, "\n"); |
11964 | } | |
a8b828f3 | 11965 | |
3eec4ee0 IR |
11966 | if (OSPF_IF_PARAM_CONFIGURED(params, |
11967 | passive_interface)) { | |
82f0277b IR |
11968 | vty_out(vty, " %sip ospf passive", |
11969 | params->passive_interface | |
11970 | == OSPF_IF_ACTIVE | |
11971 | ? "no " | |
11972 | : ""); | |
3eec4ee0 IR |
11973 | if (params != IF_DEF_PARAMS(ifp) && rn) |
11974 | vty_out(vty, " %pI4", &rn->p.u.prefix4); | |
11975 | vty_out(vty, "\n"); | |
11976 | } | |
11977 | ||
132a782e | 11978 | /* LDP-Sync print */ |
11979 | if (params && params->ldp_sync_info) | |
11980 | ospf_ldp_sync_if_write_config(vty, params); | |
d62a17ae | 11981 | |
545f0503 CS |
11982 | while (1) { |
11983 | if (rn == NULL) | |
996c9314 | 11984 | rn = route_top(IF_OIFS_PARAMS(ifp)); |
545f0503 CS |
11985 | else |
11986 | rn = route_next(rn); | |
43b8d1d8 | 11987 | |
545f0503 CS |
11988 | if (rn == NULL) |
11989 | break; | |
11990 | params = rn->info; | |
11991 | if (params != NULL) | |
11992 | break; | |
11993 | } | |
11994 | } while (rn); | |
43b8d1d8 | 11995 | |
545f0503 CS |
11996 | ospf_opaque_config_write_if(vty, ifp); |
11997 | ||
07679ad9 | 11998 | vty_endframe(vty, "exit\n!\n"); |
b5a8894d | 11999 | } |
545f0503 | 12000 | |
d62a17ae | 12001 | return write; |
718e3744 | 12002 | } |
12003 | ||
43b8d1d8 CS |
12004 | /* Configuration write function for ospfd. */ |
12005 | static int config_write_interface(struct vty *vty) | |
12006 | { | |
12007 | int write = 0; | |
545f0503 | 12008 | struct vrf *vrf = NULL; |
43b8d1d8 | 12009 | |
545f0503 CS |
12010 | /* Display all VRF aware OSPF interface configuration */ |
12011 | RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) { | |
12012 | write += config_write_interface_one(vty, vrf); | |
12013 | } | |
43b8d1d8 CS |
12014 | |
12015 | return write; | |
12016 | } | |
12017 | ||
d62a17ae | 12018 | static int config_write_network_area(struct vty *vty, struct ospf *ospf) |
718e3744 | 12019 | { |
d62a17ae | 12020 | struct route_node *rn; |
fc746f1c | 12021 | char buf[INET_ADDRSTRLEN]; |
718e3744 | 12022 | |
d62a17ae | 12023 | /* `network area' print. */ |
12024 | for (rn = route_top(ospf->networks); rn; rn = route_next(rn)) | |
12025 | if (rn->info) { | |
12026 | struct ospf_network *n = rn->info; | |
718e3744 | 12027 | |
d62a17ae | 12028 | /* Create Area ID string by specified Area ID format. */ |
12029 | if (n->area_id_fmt == OSPF_AREA_ID_FMT_DOTTEDQUAD) | |
fc746f1c | 12030 | inet_ntop(AF_INET, &n->area_id, buf, |
1f9d4e3d | 12031 | sizeof(buf)); |
d62a17ae | 12032 | else |
fc746f1c QY |
12033 | snprintf(buf, sizeof(buf), "%lu", |
12034 | (unsigned long int)ntohl( | |
12035 | n->area_id.s_addr)); | |
718e3744 | 12036 | |
d62a17ae | 12037 | /* Network print. */ |
96b663a3 | 12038 | vty_out(vty, " network %pFX area %s\n", &rn->p, buf); |
d62a17ae | 12039 | } |
718e3744 | 12040 | |
d62a17ae | 12041 | return 0; |
718e3744 | 12042 | } |
12043 | ||
d62a17ae | 12044 | static int config_write_ospf_area(struct vty *vty, struct ospf *ospf) |
718e3744 | 12045 | { |
d62a17ae | 12046 | struct listnode *node; |
12047 | struct ospf_area *area; | |
fc746f1c | 12048 | char buf[INET_ADDRSTRLEN]; |
718e3744 | 12049 | |
d62a17ae | 12050 | /* Area configuration print. */ |
12051 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) { | |
12052 | struct route_node *rn1; | |
718e3744 | 12053 | |
fc746f1c | 12054 | area_id2str(buf, sizeof(buf), &area->area_id, |
d62a17ae | 12055 | area->area_id_fmt); |
718e3744 | 12056 | |
d62a17ae | 12057 | if (area->auth_type != OSPF_AUTH_NULL) { |
12058 | if (area->auth_type == OSPF_AUTH_SIMPLE) | |
12059 | vty_out(vty, " area %s authentication\n", buf); | |
12060 | else | |
12061 | vty_out(vty, | |
12062 | " area %s authentication message-digest\n", | |
12063 | buf); | |
12064 | } | |
718e3744 | 12065 | |
d62a17ae | 12066 | if (area->shortcut_configured != OSPF_SHORTCUT_DEFAULT) |
12067 | vty_out(vty, " area %s shortcut %s\n", buf, | |
12068 | ospf_shortcut_mode_str | |
12069 | [area->shortcut_configured]); | |
12070 | ||
12071 | if ((area->external_routing == OSPF_AREA_STUB) | |
12072 | || (area->external_routing == OSPF_AREA_NSSA)) { | |
7ef56a73 | 12073 | if (area->external_routing == OSPF_AREA_STUB) { |
d62a17ae | 12074 | vty_out(vty, " area %s stub", buf); |
7ef56a73 CS |
12075 | if (area->no_summary) |
12076 | vty_out(vty, " no-summary\n"); | |
12077 | vty_out(vty, "\n"); | |
12078 | } else if (area->external_routing == OSPF_AREA_NSSA) { | |
d62a17ae | 12079 | switch (area->NSSATranslatorRole) { |
12080 | case OSPF_NSSA_ROLE_NEVER: | |
7ef56a73 CS |
12081 | vty_out(vty, |
12082 | " area %s nssa translate-never\n", | |
12083 | buf); | |
d62a17ae | 12084 | break; |
12085 | case OSPF_NSSA_ROLE_ALWAYS: | |
7ef56a73 CS |
12086 | vty_out(vty, |
12087 | " area %s nssa translate-always\n", | |
12088 | buf); | |
d62a17ae | 12089 | break; |
2643b2bc CS |
12090 | case OSPF_NSSA_ROLE_CANDIDATE: |
12091 | vty_out(vty, " area %s nssa \n", buf); | |
12092 | break; | |
d62a17ae | 12093 | } |
7ef56a73 CS |
12094 | if (area->no_summary) |
12095 | vty_out(vty, | |
12096 | " area %s nssa no-summary\n", | |
12097 | buf); | |
c317eddb | 12098 | if (area->suppress_fa) |
12099 | vty_out(vty, | |
12100 | " area %s nssa suppress-fa\n", | |
12101 | buf); | |
d62a17ae | 12102 | } |
718e3744 | 12103 | |
d62a17ae | 12104 | if (area->default_cost != 1) |
12105 | vty_out(vty, " area %s default-cost %d\n", buf, | |
12106 | area->default_cost); | |
12107 | } | |
718e3744 | 12108 | |
d62a17ae | 12109 | for (rn1 = route_top(area->ranges); rn1; rn1 = route_next(rn1)) |
12110 | if (rn1->info) { | |
12111 | struct ospf_area_range *range = rn1->info; | |
718e3744 | 12112 | |
96b663a3 MS |
12113 | vty_out(vty, " area %s range %pFX", buf, |
12114 | &rn1->p); | |
718e3744 | 12115 | |
d62a17ae | 12116 | if (range->cost_config |
12117 | != OSPF_AREA_RANGE_COST_UNSPEC) | |
12118 | vty_out(vty, " cost %d", | |
12119 | range->cost_config); | |
718e3744 | 12120 | |
d62a17ae | 12121 | if (!CHECK_FLAG(range->flags, |
12122 | OSPF_AREA_RANGE_ADVERTISE)) | |
12123 | vty_out(vty, " not-advertise"); | |
718e3744 | 12124 | |
d62a17ae | 12125 | if (CHECK_FLAG(range->flags, |
12126 | OSPF_AREA_RANGE_SUBSTITUTE)) | |
96b663a3 MS |
12127 | vty_out(vty, " substitute %pI4/%d", |
12128 | &range->subst_addr, | |
d62a17ae | 12129 | range->subst_masklen); |
12130 | ||
12131 | vty_out(vty, "\n"); | |
12132 | } | |
12133 | ||
12134 | if (EXPORT_NAME(area)) | |
12135 | vty_out(vty, " area %s export-list %s\n", buf, | |
12136 | EXPORT_NAME(area)); | |
12137 | ||
12138 | if (IMPORT_NAME(area)) | |
12139 | vty_out(vty, " area %s import-list %s\n", buf, | |
12140 | IMPORT_NAME(area)); | |
12141 | ||
12142 | if (PREFIX_NAME_IN(area)) | |
12143 | vty_out(vty, " area %s filter-list prefix %s in\n", buf, | |
12144 | PREFIX_NAME_IN(area)); | |
12145 | ||
12146 | if (PREFIX_NAME_OUT(area)) | |
12147 | vty_out(vty, " area %s filter-list prefix %s out\n", | |
12148 | buf, PREFIX_NAME_OUT(area)); | |
12149 | } | |
12150 | ||
12151 | return 0; | |
718e3744 | 12152 | } |
12153 | ||
d62a17ae | 12154 | static int config_write_ospf_nbr_nbma(struct vty *vty, struct ospf *ospf) |
718e3744 | 12155 | { |
d62a17ae | 12156 | struct ospf_nbr_nbma *nbr_nbma; |
12157 | struct route_node *rn; | |
718e3744 | 12158 | |
d62a17ae | 12159 | /* Static Neighbor configuration print. */ |
12160 | for (rn = route_top(ospf->nbr_nbma); rn; rn = route_next(rn)) | |
12161 | if ((nbr_nbma = rn->info)) { | |
96b663a3 | 12162 | vty_out(vty, " neighbor %pI4", &nbr_nbma->addr); |
718e3744 | 12163 | |
d62a17ae | 12164 | if (nbr_nbma->priority |
12165 | != OSPF_NEIGHBOR_PRIORITY_DEFAULT) | |
12166 | vty_out(vty, " priority %d", | |
12167 | nbr_nbma->priority); | |
718e3744 | 12168 | |
d62a17ae | 12169 | if (nbr_nbma->v_poll != OSPF_POLL_INTERVAL_DEFAULT) |
12170 | vty_out(vty, " poll-interval %d", | |
12171 | nbr_nbma->v_poll); | |
12172 | ||
12173 | vty_out(vty, "\n"); | |
12174 | } | |
12175 | ||
12176 | return 0; | |
12177 | } | |
12178 | ||
12179 | static int config_write_virtual_link(struct vty *vty, struct ospf *ospf) | |
12180 | { | |
12181 | struct listnode *node; | |
12182 | struct ospf_vl_data *vl_data; | |
83cc5a1f | 12183 | const char *auth_str; |
d62a17ae | 12184 | char buf[INET_ADDRSTRLEN]; |
12185 | ||
12186 | /* Virtual-Link print */ | |
12187 | for (ALL_LIST_ELEMENTS_RO(ospf->vlinks, node, vl_data)) { | |
12188 | struct listnode *n2; | |
12189 | struct crypt_key *ck; | |
12190 | struct ospf_interface *oi; | |
12191 | ||
12192 | if (vl_data != NULL) { | |
d62a17ae | 12193 | area_id2str(buf, sizeof(buf), &vl_data->vl_area_id, |
12194 | vl_data->vl_area_id_fmt); | |
12195 | oi = vl_data->vl_oi; | |
12196 | ||
12197 | /* timers */ | |
12198 | if (OSPF_IF_PARAM(oi, v_hello) | |
12199 | != OSPF_HELLO_INTERVAL_DEFAULT | |
12200 | || OSPF_IF_PARAM(oi, v_wait) | |
12201 | != OSPF_ROUTER_DEAD_INTERVAL_DEFAULT | |
12202 | || OSPF_IF_PARAM(oi, retransmit_interval) | |
12203 | != OSPF_RETRANSMIT_INTERVAL_DEFAULT | |
12204 | || OSPF_IF_PARAM(oi, transmit_delay) | |
12205 | != OSPF_TRANSMIT_DELAY_DEFAULT) | |
12206 | vty_out(vty, | |
96b663a3 MS |
12207 | " area %s virtual-link %pI4 hello-interval %d retransmit-interval %d transmit-delay %d dead-interval %d\n", |
12208 | buf, &vl_data->vl_peer, | |
d62a17ae | 12209 | OSPF_IF_PARAM(oi, v_hello), |
12210 | OSPF_IF_PARAM(oi, retransmit_interval), | |
12211 | OSPF_IF_PARAM(oi, transmit_delay), | |
12212 | OSPF_IF_PARAM(oi, v_wait)); | |
12213 | else | |
96b663a3 MS |
12214 | vty_out(vty, " area %s virtual-link %pI4\n", buf, |
12215 | &vl_data->vl_peer); | |
83cc5a1f DE |
12216 | /* Auth type */ |
12217 | auth_str = interface_config_auth_str( | |
12218 | IF_DEF_PARAMS(oi->ifp)); | |
12219 | if (auth_str) | |
12220 | vty_out(vty, | |
12221 | " area %s virtual-link %pI4 authentication%s\n", | |
12222 | buf, &vl_data->vl_peer, auth_str); | |
d62a17ae | 12223 | /* Auth key */ |
12224 | if (IF_DEF_PARAMS(vl_data->vl_oi->ifp)->auth_simple[0] | |
12225 | != '\0') | |
12226 | vty_out(vty, | |
96b663a3 MS |
12227 | " area %s virtual-link %pI4 authentication-key %s\n", |
12228 | buf, &vl_data->vl_peer, | |
d62a17ae | 12229 | IF_DEF_PARAMS(vl_data->vl_oi->ifp) |
12230 | ->auth_simple); | |
12231 | /* md5 keys */ | |
12232 | for (ALL_LIST_ELEMENTS_RO( | |
12233 | IF_DEF_PARAMS(vl_data->vl_oi->ifp) | |
12234 | ->auth_crypt, | |
12235 | n2, ck)) | |
12236 | vty_out(vty, | |
96b663a3 MS |
12237 | " area %s virtual-link %pI4 message-digest-key %d md5 %s\n", |
12238 | buf, &vl_data->vl_peer, | |
d62a17ae | 12239 | ck->key_id, ck->auth_key); |
12240 | } | |
12241 | } | |
12242 | ||
12243 | return 0; | |
718e3744 | 12244 | } |
12245 | ||
6b0655a2 | 12246 | |
d62a17ae | 12247 | static int config_write_ospf_redistribute(struct vty *vty, struct ospf *ospf) |
718e3744 | 12248 | { |
d62a17ae | 12249 | int type; |
718e3744 | 12250 | |
d62a17ae | 12251 | /* redistribute print. */ |
12252 | for (type = 0; type < ZEBRA_ROUTE_MAX; type++) { | |
12253 | struct list *red_list; | |
12254 | struct listnode *node; | |
12255 | struct ospf_redist *red; | |
718e3744 | 12256 | |
d62a17ae | 12257 | red_list = ospf->redist[type]; |
12258 | if (!red_list) | |
12259 | continue; | |
7c8ff89e | 12260 | |
d62a17ae | 12261 | for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) { |
12262 | vty_out(vty, " redistribute %s", | |
12263 | zebra_route_string(type)); | |
12264 | if (red->instance) | |
12265 | vty_out(vty, " %d", red->instance); | |
7c8ff89e | 12266 | |
d62a17ae | 12267 | if (red->dmetric.value >= 0) |
12268 | vty_out(vty, " metric %d", red->dmetric.value); | |
7c8ff89e | 12269 | |
d62a17ae | 12270 | if (red->dmetric.type == EXTERNAL_METRIC_TYPE_1) |
12271 | vty_out(vty, " metric-type 1"); | |
7c8ff89e | 12272 | |
d62a17ae | 12273 | if (ROUTEMAP_NAME(red)) |
12274 | vty_out(vty, " route-map %s", | |
12275 | ROUTEMAP_NAME(red)); | |
7c8ff89e | 12276 | |
d62a17ae | 12277 | vty_out(vty, "\n"); |
12278 | } | |
12279 | } | |
718e3744 | 12280 | |
d62a17ae | 12281 | return 0; |
718e3744 | 12282 | } |
12283 | ||
1ac88792 | 12284 | static int ospf_cfg_write_helper_dis_rtr_walkcb(struct hash_bucket *bucket, |
07b33add | 12285 | void *arg) |
12286 | { | |
1ac88792 | 12287 | struct advRtr *rtr = bucket->data; |
07b33add | 12288 | struct vty *vty = (struct vty *)arg; |
12289 | ||
859bce81 | 12290 | vty_out(vty, " graceful-restart helper enable %pI4\n", |
96b663a3 | 12291 | &rtr->advRtrAddr); |
07b33add | 12292 | return HASHWALK_CONTINUE; |
12293 | } | |
12294 | ||
10514170 RW |
12295 | static void config_write_ospf_gr(struct vty *vty, struct ospf *ospf) |
12296 | { | |
12297 | if (!ospf->gr_info.restart_support) | |
12298 | return; | |
12299 | ||
12300 | if (ospf->gr_info.grace_period == OSPF_DFLT_GRACE_INTERVAL) | |
12301 | vty_out(vty, " graceful-restart\n"); | |
12302 | else | |
12303 | vty_out(vty, " graceful-restart grace-period %u\n", | |
12304 | ospf->gr_info.grace_period); | |
12305 | } | |
12306 | ||
07b33add | 12307 | static int config_write_ospf_gr_helper(struct vty *vty, struct ospf *ospf) |
12308 | { | |
12309 | if (ospf->is_helper_supported) | |
859bce81 | 12310 | vty_out(vty, " graceful-restart helper enable\n"); |
07b33add | 12311 | |
12312 | if (!ospf->strict_lsa_check) | |
96b663a3 MS |
12313 | vty_out(vty, |
12314 | " no graceful-restart helper strict-lsa-checking\n"); | |
07b33add | 12315 | |
12316 | if (ospf->only_planned_restart) | |
12317 | vty_out(vty, " graceful-restart helper planned-only\n"); | |
12318 | ||
12319 | if (ospf->supported_grace_time != OSPF_MAX_GRACE_INTERVAL) | |
12320 | vty_out(vty, | |
12321 | " graceful-restart helper supported-grace-time %d\n", | |
12322 | ospf->supported_grace_time); | |
12323 | ||
12324 | if (OSPF_HELPER_ENABLE_RTR_COUNT(ospf)) { | |
12325 | hash_walk(ospf->enable_rtr_list, | |
12326 | ospf_cfg_write_helper_dis_rtr_walkcb, vty); | |
12327 | } | |
423e71c4 | 12328 | return 0; |
12329 | } | |
12330 | ||
12331 | static int config_write_ospf_external_aggregator(struct vty *vty, | |
12332 | struct ospf *ospf) | |
12333 | { | |
12334 | struct route_node *rn; | |
12335 | ||
12336 | /* print 'summary-address A.B.C.D/M' */ | |
12337 | for (rn = route_top(ospf->rt_aggr_tbl); rn; rn = route_next(rn)) | |
12338 | if (rn->info) { | |
12339 | struct ospf_external_aggr_rt *aggr = rn->info; | |
12340 | ||
12341 | vty_out(vty, " summary-address %pI4/%d ", | |
12342 | &aggr->p.prefix, aggr->p.prefixlen); | |
12343 | if (aggr->tag) | |
12344 | vty_out(vty, " tag %u ", aggr->tag); | |
12345 | ||
12346 | if (CHECK_FLAG(aggr->flags, | |
12347 | OSPF_EXTERNAL_AGGRT_NO_ADVERTISE)) | |
12348 | vty_out(vty, " no-advertise"); | |
12349 | ||
12350 | vty_out(vty, "\n"); | |
12351 | } | |
07b33add | 12352 | |
12353 | return 0; | |
12354 | } | |
12355 | ||
d62a17ae | 12356 | static int config_write_ospf_default_metric(struct vty *vty, struct ospf *ospf) |
718e3744 | 12357 | { |
d62a17ae | 12358 | if (ospf->default_metric != -1) |
12359 | vty_out(vty, " default-metric %d\n", ospf->default_metric); | |
12360 | return 0; | |
718e3744 | 12361 | } |
12362 | ||
d62a17ae | 12363 | static int config_write_ospf_distribute(struct vty *vty, struct ospf *ospf) |
12364 | { | |
12365 | int type; | |
12366 | struct ospf_redist *red; | |
718e3744 | 12367 | |
d62a17ae | 12368 | if (ospf) { |
12369 | /* distribute-list print. */ | |
12370 | for (type = 0; type < ZEBRA_ROUTE_MAX; type++) | |
12371 | if (DISTRIBUTE_NAME(ospf, type)) | |
12372 | vty_out(vty, " distribute-list %s out %s\n", | |
12373 | DISTRIBUTE_NAME(ospf, type), | |
12374 | zebra_route_string(type)); | |
7c8ff89e | 12375 | |
d62a17ae | 12376 | /* default-information print. */ |
12377 | if (ospf->default_originate != DEFAULT_ORIGINATE_NONE) { | |
12378 | vty_out(vty, " default-information originate"); | |
12379 | if (ospf->default_originate == DEFAULT_ORIGINATE_ALWAYS) | |
12380 | vty_out(vty, " always"); | |
718e3744 | 12381 | |
d62a17ae | 12382 | red = ospf_redist_lookup(ospf, DEFAULT_ROUTE, 0); |
12383 | if (red) { | |
12384 | if (red->dmetric.value >= 0) | |
12385 | vty_out(vty, " metric %d", | |
12386 | red->dmetric.value); | |
951da435 | 12387 | |
d62a17ae | 12388 | if (red->dmetric.type == EXTERNAL_METRIC_TYPE_1) |
12389 | vty_out(vty, " metric-type 1"); | |
718e3744 | 12390 | |
d62a17ae | 12391 | if (ROUTEMAP_NAME(red)) |
12392 | vty_out(vty, " route-map %s", | |
12393 | ROUTEMAP_NAME(red)); | |
12394 | } | |
12395 | ||
12396 | vty_out(vty, "\n"); | |
12397 | } | |
12398 | } | |
12399 | ||
12400 | return 0; | |
718e3744 | 12401 | } |
12402 | ||
d62a17ae | 12403 | static int config_write_ospf_distance(struct vty *vty, struct ospf *ospf) |
12404 | { | |
12405 | struct route_node *rn; | |
12406 | struct ospf_distance *odistance; | |
12407 | ||
12408 | if (ospf->distance_all) | |
12409 | vty_out(vty, " distance %d\n", ospf->distance_all); | |
12410 | ||
12411 | if (ospf->distance_intra || ospf->distance_inter | |
12412 | || ospf->distance_external) { | |
12413 | vty_out(vty, " distance ospf"); | |
12414 | ||
12415 | if (ospf->distance_intra) | |
12416 | vty_out(vty, " intra-area %d", ospf->distance_intra); | |
12417 | if (ospf->distance_inter) | |
12418 | vty_out(vty, " inter-area %d", ospf->distance_inter); | |
12419 | if (ospf->distance_external) | |
12420 | vty_out(vty, " external %d", ospf->distance_external); | |
12421 | ||
12422 | vty_out(vty, "\n"); | |
12423 | } | |
12424 | ||
12425 | for (rn = route_top(ospf->distance_table); rn; rn = route_next(rn)) | |
12426 | if ((odistance = rn->info) != NULL) { | |
96b663a3 MS |
12427 | vty_out(vty, " distance %d %pFX %s\n", |
12428 | odistance->distance, &rn->p, | |
d62a17ae | 12429 | odistance->access_list ? odistance->access_list |
12430 | : ""); | |
12431 | } | |
12432 | return 0; | |
718e3744 | 12433 | } |
12434 | ||
43b8d1d8 | 12435 | static int ospf_config_write_one(struct vty *vty, struct ospf *ospf) |
d62a17ae | 12436 | { |
d62a17ae | 12437 | int write = 0; |
12438 | ||
43b8d1d8 CS |
12439 | /* `router ospf' print. */ |
12440 | if (ospf->instance && ospf->name) { | |
996c9314 LB |
12441 | vty_out(vty, "router ospf %d vrf %s\n", ospf->instance, |
12442 | ospf->name); | |
43b8d1d8 | 12443 | } else if (ospf->instance) { |
996c9314 | 12444 | vty_out(vty, "router ospf %d\n", ospf->instance); |
43b8d1d8 | 12445 | } else if (ospf->name) { |
996c9314 | 12446 | vty_out(vty, "router ospf vrf %s\n", ospf->name); |
43b8d1d8 CS |
12447 | } else |
12448 | vty_out(vty, "router ospf\n"); | |
12449 | ||
12450 | if (!ospf->networks) { | |
12451 | write++; | |
b5a8894d | 12452 | return write; |
43b8d1d8 | 12453 | } |
d62a17ae | 12454 | |
43b8d1d8 | 12455 | /* Router ID print. */ |
3a6290bd | 12456 | if (ospf->router_id_static.s_addr != INADDR_ANY) |
96b663a3 MS |
12457 | vty_out(vty, " ospf router-id %pI4\n", |
12458 | &ospf->router_id_static); | |
d62a17ae | 12459 | |
43b8d1d8 CS |
12460 | /* ABR type print. */ |
12461 | if (ospf->abr_type != OSPF_ABR_DEFAULT) | |
12462 | vty_out(vty, " ospf abr-type %s\n", | |
12463 | ospf_abr_type_str[ospf->abr_type]); | |
b5a8894d | 12464 | |
43b8d1d8 CS |
12465 | /* log-adjacency-changes flag print. */ |
12466 | if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES)) { | |
12467 | if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL)) | |
12468 | vty_out(vty, " log-adjacency-changes detail\n"); | |
c572fbfe | 12469 | else if (!SAVE_OSPF_LOG_ADJACENCY_CHANGES) |
43b8d1d8 | 12470 | vty_out(vty, " log-adjacency-changes\n"); |
c572fbfe | 12471 | } else if (SAVE_OSPF_LOG_ADJACENCY_CHANGES) { |
43b8d1d8 CS |
12472 | vty_out(vty, " no log-adjacency-changes\n"); |
12473 | } | |
b5a8894d | 12474 | |
43b8d1d8 CS |
12475 | /* RFC1583 compatibility flag print -- Compatible with CISCO |
12476 | * 12.1. */ | |
12477 | if (CHECK_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE)) | |
12478 | vty_out(vty, " compatible rfc1583\n"); | |
d62a17ae | 12479 | |
43b8d1d8 CS |
12480 | /* auto-cost reference-bandwidth configuration. */ |
12481 | if (ospf->ref_bandwidth != OSPF_DEFAULT_REF_BANDWIDTH) { | |
12482 | vty_out(vty, | |
3efd0893 | 12483 | "! Important: ensure reference bandwidth is consistent across all routers\n"); |
43b8d1d8 CS |
12484 | vty_out(vty, " auto-cost reference-bandwidth %d\n", |
12485 | ospf->ref_bandwidth); | |
12486 | } | |
d62a17ae | 12487 | |
43b8d1d8 CS |
12488 | /* SPF timers print. */ |
12489 | if (ospf->spf_delay != OSPF_SPF_DELAY_DEFAULT | |
12490 | || ospf->spf_holdtime != OSPF_SPF_HOLDTIME_DEFAULT | |
12491 | || ospf->spf_max_holdtime != OSPF_SPF_MAX_HOLDTIME_DEFAULT) | |
996c9314 LB |
12492 | vty_out(vty, " timers throttle spf %d %d %d\n", ospf->spf_delay, |
12493 | ospf->spf_holdtime, ospf->spf_max_holdtime); | |
43b8d1d8 CS |
12494 | |
12495 | /* LSA timers print. */ | |
12496 | if (ospf->min_ls_interval != OSPF_MIN_LS_INTERVAL) | |
12497 | vty_out(vty, " timers throttle lsa all %d\n", | |
12498 | ospf->min_ls_interval); | |
12499 | if (ospf->min_ls_arrival != OSPF_MIN_LS_ARRIVAL) | |
12500 | vty_out(vty, " timers lsa min-arrival %d\n", | |
12501 | ospf->min_ls_arrival); | |
12502 | ||
12503 | /* Write multiplier print. */ | |
12504 | if (ospf->write_oi_count != OSPF_WRITE_INTERFACE_COUNT_DEFAULT) | |
12505 | vty_out(vty, " ospf write-multiplier %d\n", | |
12506 | ospf->write_oi_count); | |
d62a17ae | 12507 | |
3d5b9855 | 12508 | if (ospf->max_multipath != MULTIPATH_NUM) |
12509 | vty_out(vty, " maximum-paths %d\n", ospf->max_multipath); | |
12510 | ||
43b8d1d8 CS |
12511 | /* Max-metric router-lsa print */ |
12512 | config_write_stub_router(vty, ospf); | |
d62a17ae | 12513 | |
43b8d1d8 | 12514 | /* SPF refresh parameters print. */ |
996c9314 LB |
12515 | if (ospf->lsa_refresh_interval != OSPF_LSA_REFRESH_INTERVAL_DEFAULT) |
12516 | vty_out(vty, " refresh timer %d\n", ospf->lsa_refresh_interval); | |
d62a17ae | 12517 | |
43b8d1d8 CS |
12518 | /* Redistribute information print. */ |
12519 | config_write_ospf_redistribute(vty, ospf); | |
d62a17ae | 12520 | |
10514170 RW |
12521 | /* Graceful Restart print */ |
12522 | config_write_ospf_gr(vty, ospf); | |
07b33add | 12523 | config_write_ospf_gr_helper(vty, ospf); |
12524 | ||
423e71c4 | 12525 | /* Print external route aggregation. */ |
12526 | config_write_ospf_external_aggregator(vty, ospf); | |
12527 | ||
43b8d1d8 CS |
12528 | /* passive-interface print. */ |
12529 | if (ospf->passive_interface_default == OSPF_IF_PASSIVE) | |
12530 | vty_out(vty, " passive-interface default\n"); | |
d62a17ae | 12531 | |
a92706bb JU |
12532 | /* proactive-arp print. */ |
12533 | if (ospf->proactive_arp != OSPF_PROACTIVE_ARP_DEFAULT) { | |
12534 | if (ospf->proactive_arp) | |
12535 | vty_out(vty, " proactive-arp\n"); | |
12536 | else | |
12537 | vty_out(vty, " no proactive-arp\n"); | |
12538 | } | |
12539 | ||
7fd0729f | 12540 | /* TI-LFA print. */ |
385a1e07 G |
12541 | if (ospf->ti_lfa_enabled) { |
12542 | if (ospf->ti_lfa_protection_type == OSPF_TI_LFA_NODE_PROTECTION) | |
12543 | vty_out(vty, " fast-reroute ti-lfa node-protection\n"); | |
12544 | else | |
12545 | vty_out(vty, " fast-reroute ti-lfa\n"); | |
12546 | } | |
7fd0729f | 12547 | |
43b8d1d8 CS |
12548 | /* Network area print. */ |
12549 | config_write_network_area(vty, ospf); | |
d62a17ae | 12550 | |
43b8d1d8 CS |
12551 | /* Area config print. */ |
12552 | config_write_ospf_area(vty, ospf); | |
d62a17ae | 12553 | |
43b8d1d8 CS |
12554 | /* static neighbor print. */ |
12555 | config_write_ospf_nbr_nbma(vty, ospf); | |
12556 | ||
12557 | /* Virtual-Link print. */ | |
12558 | config_write_virtual_link(vty, ospf); | |
12559 | ||
12560 | /* Default metric configuration. */ | |
12561 | config_write_ospf_default_metric(vty, ospf); | |
12562 | ||
12563 | /* Distribute-list and default-information print. */ | |
12564 | config_write_ospf_distribute(vty, ospf); | |
12565 | ||
12566 | /* Distance configuration. */ | |
12567 | config_write_ospf_distance(vty, ospf); | |
12568 | ||
12569 | ospf_opaque_config_write_router(vty, ospf); | |
12570 | ||
132a782e | 12571 | /* LDP-Sync print */ |
12572 | ospf_ldp_sync_write_config(vty, ospf); | |
12573 | ||
07679ad9 IR |
12574 | vty_out(vty, "exit\n"); |
12575 | ||
43b8d1d8 CS |
12576 | write++; |
12577 | return write; | |
12578 | } | |
12579 | ||
12580 | /* OSPF configuration write function. */ | |
12581 | static int ospf_config_write(struct vty *vty) | |
12582 | { | |
12583 | struct ospf *ospf; | |
12584 | struct listnode *ospf_node = NULL; | |
12585 | int write = 0; | |
12586 | ||
12587 | if (listcount(om->ospf) == 0) | |
12588 | return write; | |
12589 | ||
12590 | for (ALL_LIST_ELEMENTS_RO(om->ospf, ospf_node, ospf)) { | |
88d77109 CS |
12591 | /* VRF Default check if it is running. |
12592 | * Upon daemon start, there could be default instance | |
12593 | * in absence of 'router ospf'/oi_running is disabled. */ | |
12594 | if (ospf->vrf_id == VRF_DEFAULT && ospf->oi_running) | |
12595 | write += ospf_config_write_one(vty, ospf); | |
12596 | /* For Non-Default VRF simply display the configuration, | |
12597 | * even if it is not oi_running. */ | |
12598 | else if (ospf->vrf_id != VRF_DEFAULT) | |
43b8d1d8 | 12599 | write += ospf_config_write_one(vty, ospf); |
b5a8894d | 12600 | } |
d62a17ae | 12601 | return write; |
12602 | } | |
12603 | ||
12604 | void ospf_vty_show_init(void) | |
12605 | { | |
12606 | /* "show ip ospf" commands. */ | |
12607 | install_element(VIEW_NODE, &show_ip_ospf_cmd); | |
12608 | ||
12609 | install_element(VIEW_NODE, &show_ip_ospf_instance_cmd); | |
12610 | ||
12611 | /* "show ip ospf database" commands. */ | |
a11bce11 | 12612 | install_element(VIEW_NODE, &show_ip_ospf_database_cmd); |
d62a17ae | 12613 | install_element(VIEW_NODE, &show_ip_ospf_database_max_cmd); |
a11bce11 IR |
12614 | install_element(VIEW_NODE, |
12615 | &show_ip_ospf_database_type_adv_router_cmd); | |
d62a17ae | 12616 | install_element(VIEW_NODE, |
12617 | &show_ip_ospf_instance_database_type_adv_router_cmd); | |
12618 | install_element(VIEW_NODE, &show_ip_ospf_instance_database_cmd); | |
12619 | install_element(VIEW_NODE, &show_ip_ospf_instance_database_max_cmd); | |
12620 | ||
12621 | /* "show ip ospf interface" commands. */ | |
12622 | install_element(VIEW_NODE, &show_ip_ospf_interface_cmd); | |
12623 | ||
12624 | install_element(VIEW_NODE, &show_ip_ospf_instance_interface_cmd); | |
c9339663 CS |
12625 | /* "show ip ospf interface traffic */ |
12626 | install_element(VIEW_NODE, &show_ip_ospf_interface_traffic_cmd); | |
d62a17ae | 12627 | |
12628 | /* "show ip ospf neighbor" commands. */ | |
12629 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_int_detail_cmd); | |
12630 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_int_cmd); | |
12631 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_id_cmd); | |
12632 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_detail_all_cmd); | |
12633 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_detail_cmd); | |
12634 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_cmd); | |
12635 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_all_cmd); | |
12636 | ||
12637 | install_element(VIEW_NODE, | |
12638 | &show_ip_ospf_instance_neighbor_int_detail_cmd); | |
12639 | install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_int_cmd); | |
12640 | install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_id_cmd); | |
12641 | install_element(VIEW_NODE, | |
12642 | &show_ip_ospf_instance_neighbor_detail_all_cmd); | |
12643 | install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_detail_cmd); | |
12644 | install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_cmd); | |
12645 | install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_all_cmd); | |
12646 | ||
12647 | /* "show ip ospf route" commands. */ | |
12648 | install_element(VIEW_NODE, &show_ip_ospf_route_cmd); | |
12649 | install_element(VIEW_NODE, &show_ip_ospf_border_routers_cmd); | |
12650 | ||
12651 | install_element(VIEW_NODE, &show_ip_ospf_instance_route_cmd); | |
12652 | install_element(VIEW_NODE, &show_ip_ospf_instance_border_routers_cmd); | |
b5a8894d CS |
12653 | |
12654 | /* "show ip ospf vrfs" commands. */ | |
12655 | install_element(VIEW_NODE, &show_ip_ospf_vrfs_cmd); | |
abd5b8c7 | 12656 | |
12657 | /* "show ip ospf gr-helper details" command */ | |
12658 | install_element(VIEW_NODE, &show_ip_ospf_gr_helper_cmd); | |
718e3744 | 12659 | |
53e44d05 | 12660 | /* "show ip ospf summary-address" command */ |
12661 | install_element(VIEW_NODE, &show_ip_ospf_external_aggregator_cmd); | |
12662 | } | |
6b0655a2 | 12663 | |
718e3744 | 12664 | /* Initialization of OSPF interface. */ |
d62a17ae | 12665 | static void ospf_vty_if_init(void) |
12666 | { | |
12667 | /* Install interface node. */ | |
9da01b0b | 12668 | if_cmd_init(config_write_interface); |
d62a17ae | 12669 | |
12670 | /* "ip ospf authentication" commands. */ | |
12671 | install_element(INTERFACE_NODE, &ip_ospf_authentication_args_addr_cmd); | |
12672 | install_element(INTERFACE_NODE, &ip_ospf_authentication_addr_cmd); | |
12673 | install_element(INTERFACE_NODE, | |
12674 | &no_ip_ospf_authentication_args_addr_cmd); | |
12675 | install_element(INTERFACE_NODE, &no_ip_ospf_authentication_addr_cmd); | |
12676 | install_element(INTERFACE_NODE, &ip_ospf_authentication_key_addr_cmd); | |
12677 | install_element(INTERFACE_NODE, | |
12678 | &no_ip_ospf_authentication_key_authkey_addr_cmd); | |
12679 | install_element(INTERFACE_NODE, | |
12680 | &no_ospf_authentication_key_authkey_addr_cmd); | |
12681 | ||
12682 | /* "ip ospf message-digest-key" commands. */ | |
12683 | install_element(INTERFACE_NODE, &ip_ospf_message_digest_key_cmd); | |
12684 | install_element(INTERFACE_NODE, &no_ip_ospf_message_digest_key_cmd); | |
12685 | ||
12686 | /* "ip ospf cost" commands. */ | |
12687 | install_element(INTERFACE_NODE, &ip_ospf_cost_cmd); | |
12688 | install_element(INTERFACE_NODE, &no_ip_ospf_cost_cmd); | |
12689 | ||
12690 | /* "ip ospf mtu-ignore" commands. */ | |
12691 | install_element(INTERFACE_NODE, &ip_ospf_mtu_ignore_addr_cmd); | |
12692 | install_element(INTERFACE_NODE, &no_ip_ospf_mtu_ignore_addr_cmd); | |
12693 | ||
12694 | /* "ip ospf dead-interval" commands. */ | |
12695 | install_element(INTERFACE_NODE, &ip_ospf_dead_interval_cmd); | |
12696 | install_element(INTERFACE_NODE, | |
12697 | &ip_ospf_dead_interval_minimal_addr_cmd); | |
12698 | install_element(INTERFACE_NODE, &no_ip_ospf_dead_interval_cmd); | |
12699 | ||
12700 | /* "ip ospf hello-interval" commands. */ | |
12701 | install_element(INTERFACE_NODE, &ip_ospf_hello_interval_cmd); | |
12702 | install_element(INTERFACE_NODE, &no_ip_ospf_hello_interval_cmd); | |
12703 | ||
12704 | /* "ip ospf network" commands. */ | |
12705 | install_element(INTERFACE_NODE, &ip_ospf_network_cmd); | |
12706 | install_element(INTERFACE_NODE, &no_ip_ospf_network_cmd); | |
12707 | ||
12708 | /* "ip ospf priority" commands. */ | |
12709 | install_element(INTERFACE_NODE, &ip_ospf_priority_cmd); | |
12710 | install_element(INTERFACE_NODE, &no_ip_ospf_priority_cmd); | |
12711 | ||
12712 | /* "ip ospf retransmit-interval" commands. */ | |
12713 | install_element(INTERFACE_NODE, &ip_ospf_retransmit_interval_addr_cmd); | |
12714 | install_element(INTERFACE_NODE, | |
12715 | &no_ip_ospf_retransmit_interval_addr_cmd); | |
12716 | ||
12717 | /* "ip ospf transmit-delay" commands. */ | |
12718 | install_element(INTERFACE_NODE, &ip_ospf_transmit_delay_addr_cmd); | |
12719 | install_element(INTERFACE_NODE, &no_ip_ospf_transmit_delay_addr_cmd); | |
12720 | ||
12721 | /* "ip ospf area" commands. */ | |
12722 | install_element(INTERFACE_NODE, &ip_ospf_area_cmd); | |
12723 | install_element(INTERFACE_NODE, &no_ip_ospf_area_cmd); | |
12724 | ||
3eec4ee0 IR |
12725 | /* "ip ospf passive" commands. */ |
12726 | install_element(INTERFACE_NODE, &ip_ospf_passive_cmd); | |
12727 | install_element(INTERFACE_NODE, &no_ip_ospf_passive_cmd); | |
12728 | ||
d62a17ae | 12729 | /* These commands are compatibitliy for previous version. */ |
12730 | install_element(INTERFACE_NODE, &ospf_authentication_key_cmd); | |
12731 | install_element(INTERFACE_NODE, &ospf_message_digest_key_cmd); | |
12732 | install_element(INTERFACE_NODE, &no_ospf_message_digest_key_cmd); | |
12733 | install_element(INTERFACE_NODE, &ospf_dead_interval_cmd); | |
12734 | install_element(INTERFACE_NODE, &no_ospf_dead_interval_cmd); | |
12735 | install_element(INTERFACE_NODE, &ospf_hello_interval_cmd); | |
12736 | install_element(INTERFACE_NODE, &no_ospf_hello_interval_cmd); | |
12737 | install_element(INTERFACE_NODE, &ospf_cost_cmd); | |
12738 | install_element(INTERFACE_NODE, &no_ospf_cost_cmd); | |
12739 | install_element(INTERFACE_NODE, &ospf_network_cmd); | |
12740 | install_element(INTERFACE_NODE, &no_ospf_network_cmd); | |
12741 | install_element(INTERFACE_NODE, &ospf_priority_cmd); | |
12742 | install_element(INTERFACE_NODE, &no_ospf_priority_cmd); | |
12743 | install_element(INTERFACE_NODE, &ospf_retransmit_interval_cmd); | |
12744 | install_element(INTERFACE_NODE, &no_ospf_retransmit_interval_cmd); | |
12745 | install_element(INTERFACE_NODE, &ospf_transmit_delay_cmd); | |
12746 | install_element(INTERFACE_NODE, &no_ospf_transmit_delay_cmd); | |
12747 | } | |
12748 | ||
12749 | static void ospf_vty_zebra_init(void) | |
12750 | { | |
12751 | install_element(OSPF_NODE, &ospf_redistribute_source_cmd); | |
12752 | install_element(OSPF_NODE, &no_ospf_redistribute_source_cmd); | |
12753 | install_element(OSPF_NODE, &ospf_redistribute_instance_source_cmd); | |
12754 | install_element(OSPF_NODE, &no_ospf_redistribute_instance_source_cmd); | |
12755 | ||
12756 | install_element(OSPF_NODE, &ospf_distribute_list_out_cmd); | |
12757 | install_element(OSPF_NODE, &no_ospf_distribute_list_out_cmd); | |
12758 | ||
12759 | install_element(OSPF_NODE, &ospf_default_information_originate_cmd); | |
12760 | install_element(OSPF_NODE, &no_ospf_default_information_originate_cmd); | |
12761 | ||
12762 | install_element(OSPF_NODE, &ospf_default_metric_cmd); | |
12763 | install_element(OSPF_NODE, &no_ospf_default_metric_cmd); | |
12764 | ||
12765 | install_element(OSPF_NODE, &ospf_distance_cmd); | |
12766 | install_element(OSPF_NODE, &no_ospf_distance_cmd); | |
12767 | install_element(OSPF_NODE, &no_ospf_distance_ospf_cmd); | |
12768 | install_element(OSPF_NODE, &ospf_distance_ospf_cmd); | |
07b33add | 12769 | |
12770 | /*Ospf garcefull restart helper configurations */ | |
12771 | install_element(OSPF_NODE, &ospf_gr_helper_enable_cmd); | |
12772 | install_element(OSPF_NODE, &no_ospf_gr_helper_enable_cmd); | |
859bce81 RW |
12773 | install_element(OSPF_NODE, &ospf_gr_helper_only_cmd); |
12774 | install_element(OSPF_NODE, &no_ospf_gr_helper_only_cmd); | |
07b33add | 12775 | install_element(OSPF_NODE, &ospf_gr_helper_enable_lsacheck_cmd); |
12776 | install_element(OSPF_NODE, &no_ospf_gr_helper_enable_lsacheck_cmd); | |
12777 | install_element(OSPF_NODE, &ospf_gr_helper_supported_grace_time_cmd); | |
12778 | install_element(OSPF_NODE, &no_ospf_gr_helper_supported_grace_time_cmd); | |
12779 | install_element(OSPF_NODE, &ospf_gr_helper_planned_only_cmd); | |
12780 | install_element(OSPF_NODE, &no_ospf_gr_helper_planned_only_cmd); | |
423e71c4 | 12781 | |
12782 | /* External LSA summarisation config commands.*/ | |
12783 | install_element(OSPF_NODE, &ospf_external_route_aggregation_cmd); | |
12784 | install_element(OSPF_NODE, &no_ospf_external_route_aggregation_cmd); | |
12785 | install_element(OSPF_NODE, | |
12786 | &ospf_external_route_aggregation_no_adrvertise_cmd); | |
12787 | install_element(OSPF_NODE, | |
12788 | &no_ospf_external_route_aggregation_no_adrvertise_cmd); | |
12789 | install_element(OSPF_NODE, &ospf_route_aggregation_timer_cmd); | |
12790 | install_element(OSPF_NODE, &no_ospf_route_aggregation_timer_cmd); | |
718e3744 | 12791 | } |
12792 | ||
612c2c15 | 12793 | static int ospf_config_write(struct vty *vty); |
62b346ee | 12794 | static struct cmd_node ospf_node = { |
f4b8291f | 12795 | .name = "ospf", |
62b346ee | 12796 | .node = OSPF_NODE, |
24389580 | 12797 | .parent_node = CONFIG_NODE, |
62b346ee | 12798 | .prompt = "%s(config-router)# ", |
612c2c15 | 12799 | .config_write = ospf_config_write, |
62b346ee | 12800 | }; |
718e3744 | 12801 | |
d62a17ae | 12802 | static void ospf_interface_clear(struct interface *ifp) |
09f35f8c | 12803 | { |
d62a17ae | 12804 | if (!if_is_operative(ifp)) |
12805 | return; | |
09f35f8c | 12806 | |
d62a17ae | 12807 | if (IS_DEBUG_OSPF(ism, ISM_EVENTS)) |
12808 | zlog_debug("ISM[%s]: clear by reset", ifp->name); | |
09f35f8c | 12809 | |
d62a17ae | 12810 | ospf_if_reset(ifp); |
09f35f8c DS |
12811 | } |
12812 | ||
12813 | DEFUN (clear_ip_ospf_interface, | |
12814 | clear_ip_ospf_interface_cmd, | |
1e81afc3 | 12815 | "clear ip ospf [vrf NAME] interface [IFNAME]", |
09f35f8c DS |
12816 | CLEAR_STR |
12817 | IP_STR | |
12818 | "OSPF information\n" | |
03ed9f02 | 12819 | VRF_CMD_HELP_STR |
09f35f8c DS |
12820 | "Interface information\n" |
12821 | "Interface name\n") | |
12822 | { | |
03ed9f02 PG |
12823 | int idx_ifname = 0; |
12824 | int idx_vrf = 0; | |
d62a17ae | 12825 | struct interface *ifp; |
f4e14fdb | 12826 | struct listnode *node; |
b5a8894d | 12827 | struct ospf *ospf = NULL; |
03ed9f02 PG |
12828 | char *vrf_name = NULL; |
12829 | vrf_id_t vrf_id = VRF_DEFAULT; | |
12830 | struct vrf *vrf = NULL; | |
09f35f8c | 12831 | |
03ed9f02 PG |
12832 | if (argv_find(argv, argc, "vrf", &idx_vrf)) |
12833 | vrf_name = argv[idx_vrf + 1]->arg; | |
12834 | if (vrf_name && strmatch(vrf_name, VRF_DEFAULT_NAME)) | |
12835 | vrf_name = NULL; | |
12836 | if (vrf_name) { | |
12837 | vrf = vrf_lookup_by_name(vrf_name); | |
12838 | if (vrf) | |
12839 | vrf_id = vrf->vrf_id; | |
12840 | } | |
12841 | if (!argv_find(argv, argc, "IFNAME", &idx_ifname)) { | |
12842 | /* Clear all the ospfv2 interfaces. */ | |
f4e14fdb | 12843 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { |
03ed9f02 PG |
12844 | if (vrf_id != ospf->vrf_id) |
12845 | continue; | |
12846 | if (!vrf) | |
12847 | vrf = vrf_lookup_by_id(ospf->vrf_id); | |
451fda4f | 12848 | FOR_ALL_INTERFACES (vrf, ifp) |
b5a8894d CS |
12849 | ospf_interface_clear(ifp); |
12850 | } | |
12851 | } else { | |
12852 | /* Interface name is specified. */ | |
a36898e7 | 12853 | ifp = if_lookup_by_name(argv[idx_ifname]->arg, vrf_id); |
b5a8894d | 12854 | if (ifp == NULL) |
d62a17ae | 12855 | vty_out(vty, "No such interface name\n"); |
12856 | else | |
12857 | ospf_interface_clear(ifp); | |
12858 | } | |
12859 | ||
12860 | return CMD_SUCCESS; | |
09f35f8c DS |
12861 | } |
12862 | ||
d62a17ae | 12863 | void ospf_vty_clear_init(void) |
09f35f8c | 12864 | { |
d62a17ae | 12865 | install_element(ENABLE_NODE, &clear_ip_ospf_interface_cmd); |
f91ce319 MR |
12866 | install_element(ENABLE_NODE, &clear_ip_ospf_process_cmd); |
12867 | install_element(ENABLE_NODE, &clear_ip_ospf_neighbor_cmd); | |
09f35f8c DS |
12868 | } |
12869 | ||
6b0655a2 | 12870 | |
718e3744 | 12871 | /* Install OSPF related vty commands. */ |
d62a17ae | 12872 | void ospf_vty_init(void) |
12873 | { | |
12874 | /* Install ospf top node. */ | |
612c2c15 | 12875 | install_node(&ospf_node); |
d62a17ae | 12876 | |
12877 | /* "router ospf" commands. */ | |
12878 | install_element(CONFIG_NODE, &router_ospf_cmd); | |
12879 | install_element(CONFIG_NODE, &no_router_ospf_cmd); | |
12880 | ||
12881 | ||
12882 | install_default(OSPF_NODE); | |
12883 | ||
12884 | /* "ospf router-id" commands. */ | |
12885 | install_element(OSPF_NODE, &ospf_router_id_cmd); | |
12886 | install_element(OSPF_NODE, &ospf_router_id_old_cmd); | |
12887 | install_element(OSPF_NODE, &no_ospf_router_id_cmd); | |
12888 | ||
12889 | /* "passive-interface" commands. */ | |
3eec4ee0 | 12890 | install_element(OSPF_NODE, &ospf_passive_interface_default_cmd); |
d62a17ae | 12891 | install_element(OSPF_NODE, &ospf_passive_interface_addr_cmd); |
3eec4ee0 | 12892 | install_element(OSPF_NODE, &no_ospf_passive_interface_default_cmd); |
d62a17ae | 12893 | install_element(OSPF_NODE, &no_ospf_passive_interface_addr_cmd); |
12894 | ||
12895 | /* "ospf abr-type" commands. */ | |
12896 | install_element(OSPF_NODE, &ospf_abr_type_cmd); | |
12897 | install_element(OSPF_NODE, &no_ospf_abr_type_cmd); | |
12898 | ||
12899 | /* "ospf log-adjacency-changes" commands. */ | |
12900 | install_element(OSPF_NODE, &ospf_log_adjacency_changes_cmd); | |
12901 | install_element(OSPF_NODE, &ospf_log_adjacency_changes_detail_cmd); | |
12902 | install_element(OSPF_NODE, &no_ospf_log_adjacency_changes_cmd); | |
12903 | install_element(OSPF_NODE, &no_ospf_log_adjacency_changes_detail_cmd); | |
12904 | ||
12905 | /* "ospf rfc1583-compatible" commands. */ | |
12906 | install_element(OSPF_NODE, &ospf_compatible_rfc1583_cmd); | |
12907 | install_element(OSPF_NODE, &no_ospf_compatible_rfc1583_cmd); | |
12908 | install_element(OSPF_NODE, &ospf_rfc1583_flag_cmd); | |
12909 | install_element(OSPF_NODE, &no_ospf_rfc1583_flag_cmd); | |
12910 | ||
12911 | /* "network area" commands. */ | |
12912 | install_element(OSPF_NODE, &ospf_network_area_cmd); | |
12913 | install_element(OSPF_NODE, &no_ospf_network_area_cmd); | |
12914 | ||
12915 | /* "area authentication" commands. */ | |
12916 | install_element(OSPF_NODE, | |
12917 | &ospf_area_authentication_message_digest_cmd); | |
12918 | install_element(OSPF_NODE, &ospf_area_authentication_cmd); | |
12919 | install_element(OSPF_NODE, &no_ospf_area_authentication_cmd); | |
12920 | ||
12921 | /* "area range" commands. */ | |
12922 | install_element(OSPF_NODE, &ospf_area_range_cmd); | |
12923 | install_element(OSPF_NODE, &ospf_area_range_cost_cmd); | |
12924 | install_element(OSPF_NODE, &ospf_area_range_not_advertise_cmd); | |
12925 | install_element(OSPF_NODE, &no_ospf_area_range_cmd); | |
12926 | install_element(OSPF_NODE, &ospf_area_range_substitute_cmd); | |
12927 | install_element(OSPF_NODE, &no_ospf_area_range_substitute_cmd); | |
12928 | ||
12929 | /* "area virtual-link" commands. */ | |
12930 | install_element(OSPF_NODE, &ospf_area_vlink_cmd); | |
12931 | install_element(OSPF_NODE, &ospf_area_vlink_intervals_cmd); | |
12932 | install_element(OSPF_NODE, &no_ospf_area_vlink_cmd); | |
12933 | install_element(OSPF_NODE, &no_ospf_area_vlink_intervals_cmd); | |
12934 | ||
12935 | ||
12936 | /* "area stub" commands. */ | |
12937 | install_element(OSPF_NODE, &ospf_area_stub_no_summary_cmd); | |
12938 | install_element(OSPF_NODE, &ospf_area_stub_cmd); | |
12939 | install_element(OSPF_NODE, &no_ospf_area_stub_no_summary_cmd); | |
12940 | install_element(OSPF_NODE, &no_ospf_area_stub_cmd); | |
12941 | ||
12942 | /* "area nssa" commands. */ | |
12943 | install_element(OSPF_NODE, &ospf_area_nssa_cmd); | |
d62a17ae | 12944 | install_element(OSPF_NODE, &ospf_area_nssa_translate_cmd); |
12945 | install_element(OSPF_NODE, &ospf_area_nssa_no_summary_cmd); | |
7ef56a73 | 12946 | install_element(OSPF_NODE, &no_ospf_area_nssa_no_summary_cmd); |
c317eddb | 12947 | install_element(OSPF_NODE, &ospf_area_nssa_suppress_fa_cmd); |
12948 | install_element(OSPF_NODE, &no_ospf_area_nssa_suppress_fa_cmd); | |
d62a17ae | 12949 | install_element(OSPF_NODE, &no_ospf_area_nssa_cmd); |
12950 | ||
12951 | install_element(OSPF_NODE, &ospf_area_default_cost_cmd); | |
12952 | install_element(OSPF_NODE, &no_ospf_area_default_cost_cmd); | |
12953 | ||
12954 | install_element(OSPF_NODE, &ospf_area_shortcut_cmd); | |
12955 | install_element(OSPF_NODE, &no_ospf_area_shortcut_cmd); | |
12956 | ||
12957 | install_element(OSPF_NODE, &ospf_area_export_list_cmd); | |
12958 | install_element(OSPF_NODE, &no_ospf_area_export_list_cmd); | |
12959 | ||
12960 | install_element(OSPF_NODE, &ospf_area_filter_list_cmd); | |
12961 | install_element(OSPF_NODE, &no_ospf_area_filter_list_cmd); | |
12962 | ||
12963 | install_element(OSPF_NODE, &ospf_area_import_list_cmd); | |
12964 | install_element(OSPF_NODE, &no_ospf_area_import_list_cmd); | |
12965 | ||
12966 | /* SPF timer commands */ | |
12967 | install_element(OSPF_NODE, &ospf_timers_throttle_spf_cmd); | |
12968 | install_element(OSPF_NODE, &no_ospf_timers_throttle_spf_cmd); | |
12969 | ||
12970 | /* LSA timers commands */ | |
12971 | install_element(OSPF_NODE, &ospf_timers_min_ls_interval_cmd); | |
12972 | install_element(OSPF_NODE, &no_ospf_timers_min_ls_interval_cmd); | |
0e88de35 QY |
12973 | install_element(OSPF_NODE, &ospf_timers_lsa_min_arrival_cmd); |
12974 | install_element(OSPF_NODE, &no_ospf_timers_lsa_min_arrival_cmd); | |
d62a17ae | 12975 | |
12976 | /* refresh timer commands */ | |
12977 | install_element(OSPF_NODE, &ospf_refresh_timer_cmd); | |
12978 | install_element(OSPF_NODE, &no_ospf_refresh_timer_val_cmd); | |
12979 | ||
12980 | /* max-metric commands */ | |
12981 | install_element(OSPF_NODE, &ospf_max_metric_router_lsa_admin_cmd); | |
12982 | install_element(OSPF_NODE, &no_ospf_max_metric_router_lsa_admin_cmd); | |
12983 | install_element(OSPF_NODE, &ospf_max_metric_router_lsa_startup_cmd); | |
12984 | install_element(OSPF_NODE, &no_ospf_max_metric_router_lsa_startup_cmd); | |
12985 | install_element(OSPF_NODE, &ospf_max_metric_router_lsa_shutdown_cmd); | |
12986 | install_element(OSPF_NODE, &no_ospf_max_metric_router_lsa_shutdown_cmd); | |
12987 | ||
12988 | /* reference bandwidth commands */ | |
12989 | install_element(OSPF_NODE, &ospf_auto_cost_reference_bandwidth_cmd); | |
12990 | install_element(OSPF_NODE, &no_ospf_auto_cost_reference_bandwidth_cmd); | |
12991 | ||
12992 | /* "neighbor" commands. */ | |
12993 | install_element(OSPF_NODE, &ospf_neighbor_cmd); | |
12994 | install_element(OSPF_NODE, &ospf_neighbor_poll_interval_cmd); | |
12995 | install_element(OSPF_NODE, &no_ospf_neighbor_cmd); | |
12996 | install_element(OSPF_NODE, &no_ospf_neighbor_poll_cmd); | |
12997 | ||
12998 | /* write multiplier commands */ | |
12999 | install_element(OSPF_NODE, &ospf_write_multiplier_cmd); | |
13000 | install_element(OSPF_NODE, &write_multiplier_cmd); | |
13001 | install_element(OSPF_NODE, &no_ospf_write_multiplier_cmd); | |
13002 | install_element(OSPF_NODE, &no_write_multiplier_cmd); | |
13003 | ||
a92706bb JU |
13004 | /* "proactive-arp" commands. */ |
13005 | install_element(OSPF_NODE, &ospf_proactive_arp_cmd); | |
13006 | install_element(OSPF_NODE, &no_ospf_proactive_arp_cmd); | |
13007 | ||
7fd0729f G |
13008 | /* TI-LFA commands */ |
13009 | install_element(OSPF_NODE, &ospf_ti_lfa_cmd); | |
13010 | install_element(OSPF_NODE, &no_ospf_ti_lfa_cmd); | |
13011 | ||
3d5b9855 | 13012 | /* Max path configurations */ |
13013 | install_element(OSPF_NODE, &ospf_max_multipath_cmd); | |
13014 | install_element(OSPF_NODE, &no_ospf_max_multipath_cmd); | |
13015 | ||
cfc369c4 | 13016 | vrf_cmd_init(NULL); |
f5eef2d5 | 13017 | |
d62a17ae | 13018 | /* Init interface related vty commands. */ |
13019 | ospf_vty_if_init(); | |
13020 | ||
13021 | /* Init zebra related vty commands. */ | |
13022 | ospf_vty_zebra_init(); | |
718e3744 | 13023 | } |