]>
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, | |
f91ce319 | 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, | |
f91ce319 | 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, | |
f91ce319 | 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 | |
d7c0a89a | 365 | static void ospf_passive_interface_default(struct ospf *ospf, uint8_t newval) |
d62a17ae | 366 | { |
f4e14fdb | 367 | struct vrf *vrf = vrf_lookup_by_id(ospf->vrf_id); |
d62a17ae | 368 | struct listnode *ln; |
369 | struct interface *ifp; | |
370 | struct ospf_interface *oi; | |
371 | ||
372 | ospf->passive_interface_default = newval; | |
373 | ||
451fda4f | 374 | FOR_ALL_INTERFACES (vrf, ifp) { |
9d303b37 DL |
375 | if (ifp && OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(ifp), |
376 | passive_interface)) | |
d62a17ae | 377 | UNSET_IF_PARAM(IF_DEF_PARAMS(ifp), passive_interface); |
378 | } | |
379 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, ln, oi)) { | |
380 | if (OSPF_IF_PARAM_CONFIGURED(oi->params, passive_interface)) | |
381 | UNSET_IF_PARAM(oi->params, passive_interface); | |
382 | /* update multicast memberships */ | |
383 | ospf_if_set_multicast(oi); | |
384 | } | |
385 | } | |
386 | ||
387 | static void ospf_passive_interface_update_addr(struct ospf *ospf, | |
388 | struct interface *ifp, | |
389 | struct ospf_if_params *params, | |
d7c0a89a | 390 | uint8_t value, |
d62a17ae | 391 | struct in_addr addr) |
392 | { | |
d7c0a89a | 393 | uint8_t dflt; |
d62a17ae | 394 | |
395 | params->passive_interface = value; | |
396 | if (params != IF_DEF_PARAMS(ifp)) { | |
397 | if (OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(ifp), | |
398 | passive_interface)) | |
399 | dflt = IF_DEF_PARAMS(ifp)->passive_interface; | |
400 | else | |
401 | dflt = ospf->passive_interface_default; | |
402 | ||
403 | if (value != dflt) | |
404 | SET_IF_PARAM(params, passive_interface); | |
405 | else | |
406 | UNSET_IF_PARAM(params, passive_interface); | |
407 | ||
408 | ospf_free_if_params(ifp, addr); | |
409 | ospf_if_update_params(ifp, addr); | |
410 | } | |
411 | } | |
412 | ||
413 | static void ospf_passive_interface_update(struct ospf *ospf, | |
414 | struct interface *ifp, | |
415 | struct ospf_if_params *params, | |
d7c0a89a | 416 | uint8_t value) |
d62a17ae | 417 | { |
418 | params->passive_interface = value; | |
419 | if (params == IF_DEF_PARAMS(ifp)) { | |
420 | if (value != ospf->passive_interface_default) | |
421 | SET_IF_PARAM(params, passive_interface); | |
422 | else | |
423 | UNSET_IF_PARAM(params, passive_interface); | |
424 | } | |
7ffa8fa2 PJ |
425 | } |
426 | ||
a2c62831 | 427 | DEFUN (ospf_passive_interface, |
428 | ospf_passive_interface_addr_cmd, | |
7a7be519 | 429 | "passive-interface <IFNAME [A.B.C.D]|default>", |
718e3744 | 430 | "Suppress routing updates on an interface\n" |
7a7be519 | 431 | "Interface's name\n" |
3a2d747c | 432 | "IPv4 address\n" |
7a7be519 | 433 | "Suppress routing updates on interfaces by default\n") |
718e3744 | 434 | { |
a3d826f0 | 435 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 436 | int idx_ipv4 = 2; |
e99734f1 | 437 | struct interface *ifp = NULL; |
d62a17ae | 438 | struct in_addr addr = {.s_addr = INADDR_ANY}; |
439 | int ret; | |
440 | struct ospf_if_params *params; | |
441 | struct route_node *rn; | |
442 | ||
443 | if (strmatch(argv[1]->text, "default")) { | |
444 | ospf_passive_interface_default(ospf, OSPF_IF_PASSIVE); | |
445 | return CMD_SUCCESS; | |
446 | } | |
e99734f1 | 447 | if (ospf->vrf_id != VRF_UNKNOWN) |
a36898e7 | 448 | ifp = if_get_by_name(argv[1]->arg, ospf->vrf_id); |
d62a17ae | 449 | |
b5a8894d | 450 | if (ifp == NULL) { |
996c9314 | 451 | vty_out(vty, "interface %s not found.\n", (char *)argv[1]->arg); |
e99734f1 | 452 | return CMD_WARNING_CONFIG_FAILED; |
b5a8894d | 453 | } |
d62a17ae | 454 | |
455 | params = IF_DEF_PARAMS(ifp); | |
456 | ||
457 | if (argc == 3) { | |
458 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
459 | if (!ret) { | |
460 | vty_out(vty, | |
461 | "Please specify interface address by A.B.C.D\n"); | |
462 | return CMD_WARNING_CONFIG_FAILED; | |
463 | } | |
464 | ||
465 | params = ospf_get_if_params(ifp, addr); | |
466 | ospf_if_update_params(ifp, addr); | |
467 | ospf_passive_interface_update_addr(ospf, ifp, params, | |
468 | OSPF_IF_PASSIVE, addr); | |
469 | } | |
470 | ||
471 | ospf_passive_interface_update(ospf, ifp, params, OSPF_IF_PASSIVE); | |
472 | ||
473 | /* XXX We should call ospf_if_set_multicast on exactly those | |
474 | * interfaces for which the passive property changed. It is too much | |
475 | * work to determine this set, so we do this for every interface. | |
476 | * This is safe and reasonable because ospf_if_set_multicast uses a | |
477 | * record of joined groups to avoid systems calls if the desired | |
478 | * memberships match the current memership. | |
479 | */ | |
480 | ||
481 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { | |
482 | struct ospf_interface *oi = rn->info; | |
483 | ||
9d303b37 DL |
484 | if (oi && (OSPF_IF_PARAM(oi, passive_interface) |
485 | == OSPF_IF_PASSIVE)) | |
d62a17ae | 486 | ospf_if_set_multicast(oi); |
487 | } | |
488 | /* | |
489 | * XXX It is not clear what state transitions the interface needs to | |
490 | * undergo when going from active to passive. Fixing this will | |
491 | * require precise identification of interfaces having such a | |
492 | * transition. | |
493 | */ | |
494 | ||
495 | return CMD_SUCCESS; | |
718e3744 | 496 | } |
497 | ||
a2c62831 | 498 | DEFUN (no_ospf_passive_interface, |
499 | no_ospf_passive_interface_addr_cmd, | |
7a7be519 | 500 | "no passive-interface <IFNAME [A.B.C.D]|default>", |
718e3744 | 501 | NO_STR |
502 | "Allow routing updates on an interface\n" | |
7a7be519 | 503 | "Interface's name\n" |
3a2d747c | 504 | "IPv4 address\n" |
7a7be519 | 505 | "Allow routing updates on interfaces by default\n") |
718e3744 | 506 | { |
a3d826f0 | 507 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 508 | int idx_ipv4 = 3; |
e99734f1 | 509 | struct interface *ifp = NULL; |
d62a17ae | 510 | struct in_addr addr = {.s_addr = INADDR_ANY}; |
511 | struct ospf_if_params *params; | |
512 | int ret; | |
513 | struct route_node *rn; | |
514 | ||
515 | if (strmatch(argv[2]->text, "default")) { | |
516 | ospf_passive_interface_default(ospf, OSPF_IF_ACTIVE); | |
517 | return CMD_SUCCESS; | |
43540886 AS |
518 | } |
519 | ||
e99734f1 | 520 | if (ospf->vrf_id != VRF_UNKNOWN) |
a36898e7 | 521 | ifp = if_get_by_name(argv[2]->arg, ospf->vrf_id); |
e99734f1 | 522 | |
b5a8894d | 523 | if (ifp == NULL) { |
996c9314 | 524 | vty_out(vty, "interface %s not found.\n", (char *)argv[2]->arg); |
e99734f1 | 525 | return CMD_WARNING_CONFIG_FAILED; |
b5a8894d | 526 | } |
ba6454ec | 527 | |
d62a17ae | 528 | params = IF_DEF_PARAMS(ifp); |
529 | ||
530 | if (argc == 4) { | |
531 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
532 | if (!ret) { | |
533 | vty_out(vty, | |
534 | "Please specify interface address by A.B.C.D\n"); | |
535 | return CMD_WARNING_CONFIG_FAILED; | |
536 | } | |
537 | ||
538 | params = ospf_lookup_if_params(ifp, addr); | |
539 | if (params == NULL) | |
540 | return CMD_SUCCESS; | |
541 | ospf_passive_interface_update_addr(ospf, ifp, params, | |
542 | OSPF_IF_ACTIVE, addr); | |
543 | } | |
544 | ospf_passive_interface_update(ospf, ifp, params, OSPF_IF_ACTIVE); | |
545 | ||
546 | /* XXX We should call ospf_if_set_multicast on exactly those | |
547 | * interfaces for which the passive property changed. It is too much | |
548 | * work to determine this set, so we do this for every interface. | |
549 | * This is safe and reasonable because ospf_if_set_multicast uses a | |
550 | * record of joined groups to avoid systems calls if the desired | |
551 | * memberships match the current memership. | |
552 | */ | |
553 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { | |
554 | struct ospf_interface *oi = rn->info; | |
555 | ||
556 | if (oi | |
557 | && (OSPF_IF_PARAM(oi, passive_interface) == OSPF_IF_ACTIVE)) | |
558 | ospf_if_set_multicast(oi); | |
559 | } | |
560 | ||
561 | return CMD_SUCCESS; | |
718e3744 | 562 | } |
563 | ||
718e3744 | 564 | |
a2c62831 | 565 | DEFUN (ospf_network_area, |
566 | ospf_network_area_cmd, | |
6147e2c6 | 567 | "network A.B.C.D/M area <A.B.C.D|(0-4294967295)>", |
718e3744 | 568 | "Enable routing on an IP network\n" |
569 | "OSPF network prefix\n" | |
570 | "Set the OSPF area ID\n" | |
571 | "OSPF area ID in IP address format\n" | |
572 | "OSPF area ID as a decimal value\n") | |
573 | { | |
a3d826f0 | 574 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 575 | int idx_ipv4_prefixlen = 1; |
576 | int idx_ipv4_number = 3; | |
577 | struct prefix_ipv4 p; | |
578 | struct in_addr area_id; | |
579 | int ret, format; | |
cbf32f74 | 580 | uint32_t count; |
d62a17ae | 581 | |
582 | if (ospf->instance) { | |
583 | vty_out(vty, | |
584 | "The network command is not supported in multi-instance ospf\n"); | |
585 | return CMD_WARNING_CONFIG_FAILED; | |
586 | } | |
718e3744 | 587 | |
cbf32f74 IR |
588 | count = ospf_count_area_params(ospf); |
589 | if (count > 0) { | |
d62a17ae | 590 | vty_out(vty, |
591 | "Please remove all ip ospf area x.x.x.x commands first.\n"); | |
aed7cc62 | 592 | if (IS_DEBUG_OSPF_EVENT) |
996c9314 | 593 | zlog_debug( |
d12566a1 | 594 | "%s ospf vrf %s num of %u ip ospf area x config", |
5e81f5dd | 595 | __func__, ospf->name ? ospf->name : "NIL", |
cbf32f74 | 596 | count); |
d62a17ae | 597 | return CMD_WARNING_CONFIG_FAILED; |
598 | } | |
599 | ||
600 | /* Get network prefix and Area ID. */ | |
601 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); | |
602 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); | |
603 | ||
604 | ret = ospf_network_set(ospf, &p, area_id, format); | |
605 | if (ret == 0) { | |
606 | vty_out(vty, "There is already same network statement.\n"); | |
2b0a905a | 607 | return CMD_WARNING_CONFIG_FAILED; |
d62a17ae | 608 | } |
609 | ||
610 | return CMD_SUCCESS; | |
718e3744 | 611 | } |
612 | ||
a2c62831 | 613 | DEFUN (no_ospf_network_area, |
614 | no_ospf_network_area_cmd, | |
6147e2c6 | 615 | "no network A.B.C.D/M area <A.B.C.D|(0-4294967295)>", |
718e3744 | 616 | NO_STR |
617 | "Enable routing on an IP network\n" | |
618 | "OSPF network prefix\n" | |
619 | "Set the OSPF area ID\n" | |
620 | "OSPF area ID in IP address format\n" | |
621 | "OSPF area ID as a decimal value\n") | |
622 | { | |
a3d826f0 | 623 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 624 | int idx_ipv4_prefixlen = 2; |
625 | int idx_ipv4_number = 4; | |
626 | struct prefix_ipv4 p; | |
627 | struct in_addr area_id; | |
628 | int ret, format; | |
629 | ||
630 | if (ospf->instance) { | |
631 | vty_out(vty, | |
632 | "The network command is not supported in multi-instance ospf\n"); | |
633 | return CMD_WARNING_CONFIG_FAILED; | |
634 | } | |
718e3744 | 635 | |
d62a17ae | 636 | /* Get network prefix and Area ID. */ |
637 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); | |
638 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); | |
639 | ||
640 | ret = ospf_network_unset(ospf, &p, area_id); | |
641 | if (ret == 0) { | |
642 | vty_out(vty, | |
643 | "Can't find specified network area configuration.\n"); | |
644 | return CMD_WARNING_CONFIG_FAILED; | |
645 | } | |
646 | ||
647 | return CMD_SUCCESS; | |
718e3744 | 648 | } |
649 | ||
a2c62831 | 650 | DEFUN (ospf_area_range, |
651 | ospf_area_range_cmd, | |
7a7be519 | 652 | "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M [advertise [cost (0-16777215)]]", |
718e3744 | 653 | "OSPF area parameters\n" |
654 | "OSPF area ID in IP address format\n" | |
655 | "OSPF area ID as a decimal value\n" | |
656 | "Summarize routes matching address/mask (border routers only)\n" | |
7a7be519 | 657 | "Area range prefix\n" |
658 | "Advertise this range (default)\n" | |
659 | "User specified metric for this range\n" | |
660 | "Advertised metric for this range\n") | |
718e3744 | 661 | { |
a3d826f0 | 662 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 663 | int idx_ipv4_number = 1; |
664 | int idx_ipv4_prefixlen = 3; | |
665 | int idx_cost = 6; | |
666 | struct prefix_ipv4 p; | |
667 | struct in_addr area_id; | |
668 | int format; | |
d7c0a89a | 669 | uint32_t cost; |
d62a17ae | 670 | |
671 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); | |
672 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); | |
673 | ||
674 | ospf_area_range_set(ospf, area_id, &p, OSPF_AREA_RANGE_ADVERTISE); | |
ed709ed1 GW |
675 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), |
676 | format); | |
d62a17ae | 677 | if (argc > 5) { |
678 | cost = strtoul(argv[idx_cost]->arg, NULL, 10); | |
679 | ospf_area_range_cost_set(ospf, area_id, &p, cost); | |
680 | } | |
718e3744 | 681 | |
d62a17ae | 682 | return CMD_SUCCESS; |
718e3744 | 683 | } |
684 | ||
7a7be519 | 685 | DEFUN (ospf_area_range_cost, |
686 | ospf_area_range_cost_cmd, | |
687 | "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M cost (0-16777215)", | |
688 | "OSPF area parameters\n" | |
689 | "OSPF area ID in IP address format\n" | |
690 | "OSPF area ID as a decimal value\n" | |
691 | "Summarize routes matching address/mask (border routers only)\n" | |
692 | "Area range prefix\n" | |
693 | "User specified metric for this range\n" | |
694 | "Advertised metric for this range\n") | |
695 | { | |
a3d826f0 | 696 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 697 | int idx_ipv4_number = 1; |
698 | int idx_ipv4_prefixlen = 3; | |
699 | int idx_cost = 5; | |
700 | struct prefix_ipv4 p; | |
701 | struct in_addr area_id; | |
702 | int format; | |
d7c0a89a | 703 | uint32_t cost; |
7a7be519 | 704 | |
d62a17ae | 705 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
706 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); | |
7a7be519 | 707 | |
d62a17ae | 708 | ospf_area_range_set(ospf, area_id, &p, OSPF_AREA_RANGE_ADVERTISE); |
709 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
710 | format); | |
718e3744 | 711 | |
d62a17ae | 712 | cost = strtoul(argv[idx_cost]->arg, NULL, 10); |
713 | ospf_area_range_cost_set(ospf, area_id, &p, cost); | |
718e3744 | 714 | |
d62a17ae | 715 | return CMD_SUCCESS; |
7a7be519 | 716 | } |
718e3744 | 717 | |
a2c62831 | 718 | DEFUN (ospf_area_range_not_advertise, |
719 | ospf_area_range_not_advertise_cmd, | |
6147e2c6 | 720 | "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M not-advertise", |
718e3744 | 721 | "OSPF area parameters\n" |
722 | "OSPF area ID in IP address format\n" | |
723 | "OSPF area ID as a decimal value\n" | |
724 | "Summarize routes matching address/mask (border routers only)\n" | |
725 | "Area range prefix\n" | |
726 | "DoNotAdvertise this range\n") | |
727 | { | |
a3d826f0 | 728 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 729 | int idx_ipv4_number = 1; |
730 | int idx_ipv4_prefixlen = 3; | |
731 | struct prefix_ipv4 p; | |
732 | struct in_addr area_id; | |
733 | int format; | |
718e3744 | 734 | |
d62a17ae | 735 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
736 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); | |
718e3744 | 737 | |
d62a17ae | 738 | ospf_area_range_set(ospf, area_id, &p, 0); |
739 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
740 | format); | |
990baca0 | 741 | ospf_area_range_substitute_unset(ospf, area_id, &p); |
718e3744 | 742 | |
d62a17ae | 743 | return CMD_SUCCESS; |
718e3744 | 744 | } |
745 | ||
a2c62831 | 746 | DEFUN (no_ospf_area_range, |
747 | no_ospf_area_range_cmd, | |
3a2d747c | 748 | "no area <A.B.C.D|(0-4294967295)> range A.B.C.D/M [<cost (0-16777215)|advertise [cost (0-16777215)]|not-advertise>]", |
718e3744 | 749 | NO_STR |
750 | "OSPF area parameters\n" | |
751 | "OSPF area ID in IP address format\n" | |
752 | "OSPF area ID as a decimal value\n" | |
753 | "Summarize routes matching address/mask (border routers only)\n" | |
7a7be519 | 754 | "Area range prefix\n" |
3a2d747c QY |
755 | "User specified metric for this range\n" |
756 | "Advertised metric for this range\n" | |
7a7be519 | 757 | "Advertise this range (default)\n" |
3a2d747c QY |
758 | "User specified metric for this range\n" |
759 | "Advertised metric for this range\n" | |
7a7be519 | 760 | "DoNotAdvertise this range\n") |
718e3744 | 761 | { |
a3d826f0 | 762 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 763 | int idx_ipv4_number = 2; |
764 | int idx_ipv4_prefixlen = 4; | |
765 | struct prefix_ipv4 p; | |
766 | struct in_addr area_id; | |
767 | int format; | |
718e3744 | 768 | |
d62a17ae | 769 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
770 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); | |
718e3744 | 771 | |
d62a17ae | 772 | ospf_area_range_unset(ospf, area_id, &p); |
718e3744 | 773 | |
d62a17ae | 774 | return CMD_SUCCESS; |
718e3744 | 775 | } |
776 | ||
a2c62831 | 777 | DEFUN (ospf_area_range_substitute, |
778 | ospf_area_range_substitute_cmd, | |
6147e2c6 | 779 | "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M substitute A.B.C.D/M", |
718e3744 | 780 | "OSPF area parameters\n" |
781 | "OSPF area ID in IP address format\n" | |
782 | "OSPF area ID as a decimal value\n" | |
783 | "Summarize routes matching address/mask (border routers only)\n" | |
784 | "Area range prefix\n" | |
785 | "Announce area range as another prefix\n" | |
786 | "Network prefix to be announced instead of range\n") | |
787 | { | |
a3d826f0 | 788 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 789 | int idx_ipv4_number = 1; |
790 | int idx_ipv4_prefixlen = 3; | |
791 | int idx_ipv4_prefixlen_2 = 5; | |
792 | struct prefix_ipv4 p, s; | |
793 | struct in_addr area_id; | |
794 | int format; | |
718e3744 | 795 | |
d62a17ae | 796 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
797 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); | |
798 | str2prefix_ipv4(argv[idx_ipv4_prefixlen_2]->arg, &s); | |
718e3744 | 799 | |
d62a17ae | 800 | ospf_area_range_substitute_set(ospf, area_id, &p, &s); |
801 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
802 | format); | |
718e3744 | 803 | |
d62a17ae | 804 | return CMD_SUCCESS; |
718e3744 | 805 | } |
806 | ||
a2c62831 | 807 | DEFUN (no_ospf_area_range_substitute, |
808 | no_ospf_area_range_substitute_cmd, | |
6147e2c6 | 809 | "no area <A.B.C.D|(0-4294967295)> range A.B.C.D/M substitute A.B.C.D/M", |
718e3744 | 810 | NO_STR |
811 | "OSPF area parameters\n" | |
812 | "OSPF area ID in IP address format\n" | |
813 | "OSPF area ID as a decimal value\n" | |
814 | "Summarize routes matching address/mask (border routers only)\n" | |
815 | "Area range prefix\n" | |
816 | "Announce area range as another prefix\n" | |
817 | "Network prefix to be announced instead of range\n") | |
818 | { | |
a3d826f0 | 819 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 820 | int idx_ipv4_number = 2; |
821 | int idx_ipv4_prefixlen = 4; | |
822 | int idx_ipv4_prefixlen_2 = 6; | |
823 | struct prefix_ipv4 p, s; | |
824 | struct in_addr area_id; | |
825 | int format; | |
718e3744 | 826 | |
d62a17ae | 827 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
828 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); | |
829 | str2prefix_ipv4(argv[idx_ipv4_prefixlen_2]->arg, &s); | |
718e3744 | 830 | |
d62a17ae | 831 | ospf_area_range_substitute_unset(ospf, area_id, &p); |
718e3744 | 832 | |
d62a17ae | 833 | return CMD_SUCCESS; |
718e3744 | 834 | } |
835 | ||
6b0655a2 | 836 | |
718e3744 | 837 | /* Command Handler Logic in VLink stuff is delicate!! |
838 | ||
839 | ALTER AT YOUR OWN RISK!!!! | |
840 | ||
841 | Various dummy values are used to represent 'NoChange' state for | |
842 | VLink configuration NOT being changed by a VLink command, and | |
843 | special syntax is used within the command strings so that the | |
844 | typed in command verbs can be seen in the configuration command | |
845 | bacckend handler. This is to drastically reduce the verbeage | |
846 | required to coe up with a reasonably compatible Cisco VLink command | |
847 | ||
d62a17ae | 848 | - Matthew Grant <grantma@anathoth.gen.nz> |
718e3744 | 849 | Wed, 21 Feb 2001 15:13:52 +1300 |
850 | */ | |
851 | ||
d62a17ae | 852 | /* Configuration data for virtual links |
853 | */ | |
718e3744 | 854 | struct ospf_vl_config_data { |
d62a17ae | 855 | struct vty *vty; /* vty stuff */ |
856 | struct in_addr area_id; /* area ID from command line */ | |
857 | int area_id_fmt; /* command line area ID format */ | |
858 | struct in_addr vl_peer; /* command line vl_peer */ | |
859 | int auth_type; /* Authehntication type, if given */ | |
860 | char *auth_key; /* simple password if present */ | |
861 | int crypto_key_id; /* Cryptographic key ID */ | |
862 | char *md5_key; /* MD5 authentication key */ | |
863 | int hello_interval; /* Obvious what these are... */ | |
864 | int retransmit_interval; | |
865 | int transmit_delay; | |
866 | int dead_interval; | |
718e3744 | 867 | }; |
868 | ||
d62a17ae | 869 | static void ospf_vl_config_data_init(struct ospf_vl_config_data *vl_config, |
870 | struct vty *vty) | |
718e3744 | 871 | { |
d62a17ae | 872 | memset(vl_config, 0, sizeof(struct ospf_vl_config_data)); |
873 | vl_config->auth_type = OSPF_AUTH_CMD_NOTSEEN; | |
874 | vl_config->vty = vty; | |
718e3744 | 875 | } |
876 | ||
4dadc291 | 877 | static struct ospf_vl_data * |
d62a17ae | 878 | ospf_find_vl_data(struct ospf *ospf, struct ospf_vl_config_data *vl_config) |
879 | { | |
880 | struct ospf_area *area; | |
881 | struct ospf_vl_data *vl_data; | |
882 | struct vty *vty; | |
883 | struct in_addr area_id; | |
884 | ||
885 | vty = vl_config->vty; | |
886 | area_id = vl_config->area_id; | |
887 | ||
888 | if (area_id.s_addr == OSPF_AREA_BACKBONE) { | |
889 | vty_out(vty, | |
890 | "Configuring VLs over the backbone is not allowed\n"); | |
891 | return NULL; | |
892 | } | |
893 | area = ospf_area_get(ospf, area_id); | |
894 | ospf_area_display_format_set(ospf, area, vl_config->area_id_fmt); | |
895 | ||
896 | if (area->external_routing != OSPF_AREA_DEFAULT) { | |
897 | if (vl_config->area_id_fmt == OSPF_AREA_ID_FMT_DOTTEDQUAD) | |
96b663a3 | 898 | vty_out(vty, "Area %pI4 is %s\n", &area_id, |
d62a17ae | 899 | area->external_routing == OSPF_AREA_NSSA |
900 | ? "nssa" | |
901 | : "stub"); | |
902 | else | |
903 | vty_out(vty, "Area %ld is %s\n", | |
d7c0a89a | 904 | (unsigned long)ntohl(area_id.s_addr), |
d62a17ae | 905 | area->external_routing == OSPF_AREA_NSSA |
906 | ? "nssa" | |
907 | : "stub"); | |
908 | return NULL; | |
909 | } | |
910 | ||
911 | if ((vl_data = ospf_vl_lookup(ospf, area, vl_config->vl_peer)) | |
912 | == NULL) { | |
913 | vl_data = ospf_vl_data_new(area, vl_config->vl_peer); | |
914 | if (vl_data->vl_oi == NULL) { | |
915 | vl_data->vl_oi = ospf_vl_new(ospf, vl_data); | |
916 | ospf_vl_add(ospf, vl_data); | |
917 | ospf_spf_calculate_schedule(ospf, | |
918 | SPF_FLAG_CONFIG_CHANGE); | |
919 | } | |
718e3744 | 920 | } |
d62a17ae | 921 | return vl_data; |
718e3744 | 922 | } |
923 | ||
924 | ||
d62a17ae | 925 | static int ospf_vl_set_security(struct ospf_vl_data *vl_data, |
926 | struct ospf_vl_config_data *vl_config) | |
927 | { | |
928 | struct crypt_key *ck; | |
929 | struct vty *vty; | |
930 | struct interface *ifp = vl_data->vl_oi->ifp; | |
931 | ||
932 | vty = vl_config->vty; | |
933 | ||
934 | if (vl_config->auth_type != OSPF_AUTH_CMD_NOTSEEN) { | |
935 | SET_IF_PARAM(IF_DEF_PARAMS(ifp), auth_type); | |
936 | IF_DEF_PARAMS(ifp)->auth_type = vl_config->auth_type; | |
718e3744 | 937 | } |
718e3744 | 938 | |
d62a17ae | 939 | if (vl_config->auth_key) { |
940 | memset(IF_DEF_PARAMS(ifp)->auth_simple, 0, | |
941 | OSPF_AUTH_SIMPLE_SIZE + 1); | |
4d65d927 QY |
942 | strlcpy((char *)IF_DEF_PARAMS(ifp)->auth_simple, |
943 | vl_config->auth_key, | |
944 | sizeof(IF_DEF_PARAMS(ifp)->auth_simple)); | |
d62a17ae | 945 | } else if (vl_config->md5_key) { |
946 | if (ospf_crypt_key_lookup(IF_DEF_PARAMS(ifp)->auth_crypt, | |
947 | vl_config->crypto_key_id) | |
948 | != NULL) { | |
949 | vty_out(vty, "OSPF: Key %d already exists\n", | |
950 | vl_config->crypto_key_id); | |
851fcbae | 951 | return CMD_WARNING; |
d62a17ae | 952 | } |
953 | ck = ospf_crypt_key_new(); | |
954 | ck->key_id = vl_config->crypto_key_id; | |
955 | memset(ck->auth_key, 0, OSPF_AUTH_MD5_SIZE + 1); | |
4d65d927 QY |
956 | strlcpy((char *)ck->auth_key, vl_config->md5_key, |
957 | sizeof(ck->auth_key)); | |
d62a17ae | 958 | |
959 | ospf_crypt_key_add(IF_DEF_PARAMS(ifp)->auth_crypt, ck); | |
960 | } else if (vl_config->crypto_key_id != 0) { | |
961 | /* Delete a key */ | |
962 | ||
963 | if (ospf_crypt_key_lookup(IF_DEF_PARAMS(ifp)->auth_crypt, | |
964 | vl_config->crypto_key_id) | |
965 | == NULL) { | |
966 | vty_out(vty, "OSPF: Key %d does not exist\n", | |
967 | vl_config->crypto_key_id); | |
968 | return CMD_WARNING_CONFIG_FAILED; | |
969 | } | |
970 | ||
971 | ospf_crypt_key_delete(IF_DEF_PARAMS(ifp)->auth_crypt, | |
972 | vl_config->crypto_key_id); | |
973 | } | |
974 | ||
975 | return CMD_SUCCESS; | |
718e3744 | 976 | } |
977 | ||
d62a17ae | 978 | static int ospf_vl_set_timers(struct ospf_vl_data *vl_data, |
979 | struct ospf_vl_config_data *vl_config) | |
980 | { | |
981 | struct interface *ifp = vl_data->vl_oi->ifp; | |
982 | /* Virtual Link data initialised to defaults, so only set | |
983 | if a value given */ | |
984 | if (vl_config->hello_interval) { | |
985 | SET_IF_PARAM(IF_DEF_PARAMS(ifp), v_hello); | |
986 | IF_DEF_PARAMS(ifp)->v_hello = vl_config->hello_interval; | |
987 | } | |
988 | ||
989 | if (vl_config->dead_interval) { | |
990 | SET_IF_PARAM(IF_DEF_PARAMS(ifp), v_wait); | |
991 | IF_DEF_PARAMS(ifp)->v_wait = vl_config->dead_interval; | |
992 | } | |
993 | ||
994 | if (vl_config->retransmit_interval) { | |
995 | SET_IF_PARAM(IF_DEF_PARAMS(ifp), retransmit_interval); | |
996 | IF_DEF_PARAMS(ifp)->retransmit_interval = | |
997 | vl_config->retransmit_interval; | |
998 | } | |
999 | ||
1000 | if (vl_config->transmit_delay) { | |
1001 | SET_IF_PARAM(IF_DEF_PARAMS(ifp), transmit_delay); | |
1002 | IF_DEF_PARAMS(ifp)->transmit_delay = vl_config->transmit_delay; | |
1003 | } | |
1004 | ||
1005 | return CMD_SUCCESS; | |
718e3744 | 1006 | } |
1007 | ||
1008 | ||
718e3744 | 1009 | /* The business end of all of the above */ |
d62a17ae | 1010 | static int ospf_vl_set(struct ospf *ospf, struct ospf_vl_config_data *vl_config) |
1011 | { | |
1012 | struct ospf_vl_data *vl_data; | |
1013 | int ret; | |
718e3744 | 1014 | |
d62a17ae | 1015 | vl_data = ospf_find_vl_data(ospf, vl_config); |
1016 | if (!vl_data) | |
1017 | return CMD_WARNING_CONFIG_FAILED; | |
1018 | ||
1019 | /* Process this one first as it can have a fatal result, which can | |
1020 | only logically occur if the virtual link exists already | |
1021 | Thus a command error does not result in a change to the | |
1022 | running configuration such as unexpectedly altered timer | |
1023 | values etc.*/ | |
1024 | ret = ospf_vl_set_security(vl_data, vl_config); | |
1025 | if (ret != CMD_SUCCESS) | |
1026 | return ret; | |
1027 | ||
1028 | /* Set any time based parameters, these area already range checked */ | |
1029 | ||
1030 | ret = ospf_vl_set_timers(vl_data, vl_config); | |
1031 | if (ret != CMD_SUCCESS) | |
1032 | return ret; | |
718e3744 | 1033 | |
d62a17ae | 1034 | return CMD_SUCCESS; |
718e3744 | 1035 | } |
1036 | ||
1037 | /* This stuff exists to make specifying all the alias commands A LOT simpler | |
1038 | */ | |
d62a17ae | 1039 | #define VLINK_HELPSTR_IPADDR \ |
1040 | "OSPF area parameters\n" \ | |
1041 | "OSPF area ID in IP address format\n" \ | |
1042 | "OSPF area ID as a decimal value\n" \ | |
1043 | "Configure a virtual link\n" \ | |
1044 | "Router ID of the remote ABR\n" | |
1045 | ||
1046 | #define VLINK_HELPSTR_AUTHTYPE_SIMPLE \ | |
1047 | "Enable authentication on this virtual link\n" \ | |
1048 | "dummy string \n" | |
1049 | ||
1050 | #define VLINK_HELPSTR_AUTHTYPE_ALL \ | |
1051 | VLINK_HELPSTR_AUTHTYPE_SIMPLE \ | |
1052 | "Use null authentication\n" \ | |
1053 | "Use message-digest authentication\n" | |
1054 | ||
1055 | #define VLINK_HELPSTR_TIME_PARAM \ | |
1056 | "Time between HELLO packets\n" \ | |
1057 | "Seconds\n" \ | |
1058 | "Time between retransmitting lost link state advertisements\n" \ | |
1059 | "Seconds\n" \ | |
1060 | "Link state transmit delay\n" \ | |
1061 | "Seconds\n" \ | |
1062 | "Interval time after which a neighbor is declared down\n" \ | |
1063 | "Seconds\n" | |
1064 | ||
1065 | #define VLINK_HELPSTR_AUTH_SIMPLE \ | |
1066 | "Authentication password (key)\n" \ | |
baf9eaad | 1067 | "The OSPF password (key)\n" |
d62a17ae | 1068 | |
1069 | #define VLINK_HELPSTR_AUTH_MD5 \ | |
1070 | "Message digest authentication password (key)\n" \ | |
d62a17ae | 1071 | "Key ID\n" \ |
1072 | "Use MD5 algorithm\n" \ | |
baf9eaad | 1073 | "The OSPF password (key)\n" |
718e3744 | 1074 | |
a2c62831 | 1075 | DEFUN (ospf_area_vlink, |
1076 | ospf_area_vlink_cmd, | |
3d1c6dc2 | 1077 | "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 | 1078 | VLINK_HELPSTR_IPADDR |
3d1c6dc2 | 1079 | "Enable authentication on this virtual link\n" |
7a7be519 | 1080 | "Use message-digest authentication\n" |
3d1c6dc2 | 1081 | "Use null authentication\n" |
baf9eaad CS |
1082 | VLINK_HELPSTR_AUTH_MD5 |
1083 | VLINK_HELPSTR_AUTH_SIMPLE) | |
718e3744 | 1084 | { |
a3d826f0 | 1085 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1086 | int idx_ipv4_number = 1; |
1087 | int idx_ipv4 = 3; | |
1088 | struct ospf_vl_config_data vl_config; | |
1089 | char auth_key[OSPF_AUTH_SIMPLE_SIZE + 1]; | |
1090 | char md5_key[OSPF_AUTH_MD5_SIZE + 1]; | |
d62a17ae | 1091 | int ret; |
55d1da24 | 1092 | int idx = 0; |
d62a17ae | 1093 | |
1094 | ospf_vl_config_data_init(&vl_config, vty); | |
1095 | ||
1096 | /* Read off first 2 parameters and check them */ | |
1097 | ret = str2area_id(argv[idx_ipv4_number]->arg, &vl_config.area_id, | |
1098 | &vl_config.area_id_fmt); | |
1099 | if (ret < 0) { | |
1100 | vty_out(vty, "OSPF area ID is invalid\n"); | |
1101 | return CMD_WARNING_CONFIG_FAILED; | |
1102 | } | |
718e3744 | 1103 | |
d62a17ae | 1104 | ret = inet_aton(argv[idx_ipv4]->arg, &vl_config.vl_peer); |
1105 | if (!ret) { | |
1106 | vty_out(vty, "Please specify valid Router ID as a.b.c.d\n"); | |
1107 | return CMD_WARNING_CONFIG_FAILED; | |
7a7be519 | 1108 | } |
7a7be519 | 1109 | |
d62a17ae | 1110 | if (argc <= 4) { |
1111 | /* Thats all folks! - BUGS B. strikes again!!!*/ | |
7a7be519 | 1112 | |
d62a17ae | 1113 | return ospf_vl_set(ospf, &vl_config); |
1114 | } | |
1115 | ||
3d1c6dc2 CS |
1116 | if (argv_find(argv, argc, "authentication", &idx)) { |
1117 | /* authentication - this option can only occur | |
1118 | at start of command line */ | |
1119 | vl_config.auth_type = OSPF_AUTH_SIMPLE; | |
1120 | } | |
1121 | ||
3d1c6dc2 | 1122 | if (argv_find(argv, argc, "message-digest", &idx)) { |
baf9eaad | 1123 | /* authentication message-digest */ |
3d1c6dc2 CS |
1124 | vl_config.auth_type = OSPF_AUTH_CRYPTOGRAPHIC; |
1125 | } else if (argv_find(argv, argc, "null", &idx)) { | |
1126 | /* "authentication null" */ | |
1127 | vl_config.auth_type = OSPF_AUTH_NULL; | |
d62a17ae | 1128 | } |
7a7be519 | 1129 | |
3d1c6dc2 | 1130 | if (argv_find(argv, argc, "message-digest-key", &idx)) { |
3d1c6dc2 | 1131 | vl_config.md5_key = NULL; |
cbb9b53d | 1132 | vl_config.crypto_key_id = strtol(argv[idx + 1]->arg, NULL, 10); |
3d1c6dc2 CS |
1133 | if (vl_config.crypto_key_id < 0) |
1134 | return CMD_WARNING_CONFIG_FAILED; | |
1135 | ||
4d65d927 | 1136 | strlcpy(md5_key, argv[idx + 3]->arg, sizeof(md5_key)); |
3d1c6dc2 CS |
1137 | vl_config.md5_key = md5_key; |
1138 | } | |
1139 | ||
3d1c6dc2 | 1140 | if (argv_find(argv, argc, "authentication-key", &idx)) { |
4d65d927 | 1141 | strlcpy(auth_key, argv[idx + 1]->arg, sizeof(auth_key)); |
3d1c6dc2 CS |
1142 | vl_config.auth_key = auth_key; |
1143 | } | |
7a7be519 | 1144 | |
d62a17ae | 1145 | /* Action configuration */ |
1146 | ||
1147 | return ospf_vl_set(ospf, &vl_config); | |
7a7be519 | 1148 | } |
1149 | ||
a2c62831 | 1150 | DEFUN (no_ospf_area_vlink, |
1151 | no_ospf_area_vlink_cmd, | |
3d1c6dc2 | 1152 | "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 | 1153 | NO_STR |
7a7be519 | 1154 | VLINK_HELPSTR_IPADDR |
7e5ee522 IR |
1155 | "Enable authentication on this virtual link\n" |
1156 | "Use message-digest authentication\n" | |
1157 | "Use null authentication\n" | |
baf9eaad CS |
1158 | VLINK_HELPSTR_AUTH_MD5 |
1159 | VLINK_HELPSTR_AUTH_SIMPLE) | |
718e3744 | 1160 | { |
a3d826f0 | 1161 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1162 | int idx_ipv4_number = 2; |
1163 | int idx_ipv4 = 4; | |
1164 | struct ospf_area *area; | |
1165 | struct ospf_vl_config_data vl_config; | |
1166 | struct ospf_vl_data *vl_data = NULL; | |
1167 | char auth_key[OSPF_AUTH_SIMPLE_SIZE + 1]; | |
3d1c6dc2 | 1168 | int idx = 0; |
d62a17ae | 1169 | int ret, format; |
1170 | ||
1171 | ospf_vl_config_data_init(&vl_config, vty); | |
1172 | ||
1173 | ret = str2area_id(argv[idx_ipv4_number]->arg, &vl_config.area_id, | |
1174 | &format); | |
1175 | if (ret < 0) { | |
1176 | vty_out(vty, "OSPF area ID is invalid\n"); | |
1177 | return CMD_WARNING_CONFIG_FAILED; | |
1178 | } | |
1179 | ||
1180 | area = ospf_area_lookup_by_area_id(ospf, vl_config.area_id); | |
1181 | if (!area) { | |
1182 | vty_out(vty, "Area does not exist\n"); | |
1183 | return CMD_WARNING_CONFIG_FAILED; | |
1184 | } | |
1185 | ||
1186 | ret = inet_aton(argv[idx_ipv4]->arg, &vl_config.vl_peer); | |
1187 | if (!ret) { | |
1188 | vty_out(vty, "Please specify valid Router ID as a.b.c.d\n"); | |
1189 | return CMD_WARNING_CONFIG_FAILED; | |
1190 | } | |
718e3744 | 1191 | |
188823b0 EDP |
1192 | vl_data = ospf_vl_lookup(ospf, area, vl_config.vl_peer); |
1193 | if (!vl_data) { | |
1194 | vty_out(vty, "Virtual link does not exist\n"); | |
1195 | return CMD_WARNING_CONFIG_FAILED; | |
1196 | } | |
1197 | ||
d62a17ae | 1198 | if (argc <= 5) { |
1199 | /* Basic VLink no command */ | |
1200 | /* Thats all folks! - BUGS B. strikes again!!!*/ | |
188823b0 | 1201 | ospf_vl_delete(ospf, vl_data); |
d62a17ae | 1202 | ospf_area_check_free(ospf, vl_config.area_id); |
d62a17ae | 1203 | return CMD_SUCCESS; |
1204 | } | |
1205 | ||
1206 | /* If we are down here, we are reseting parameters */ | |
d62a17ae | 1207 | /* Deal with other parameters */ |
3d1c6dc2 CS |
1208 | |
1209 | if (argv_find(argv, argc, "authentication", &idx)) { | |
1210 | /* authentication - this option can only occur | |
1211 | at start of command line */ | |
1212 | vl_config.auth_type = OSPF_AUTH_NOTSET; | |
1213 | } | |
1214 | ||
3d1c6dc2 | 1215 | if (argv_find(argv, argc, "message-digest-key", &idx)) { |
3d1c6dc2 | 1216 | vl_config.md5_key = NULL; |
cbb9b53d | 1217 | vl_config.crypto_key_id = strtol(argv[idx + 1]->arg, NULL, 10); |
3d1c6dc2 CS |
1218 | if (vl_config.crypto_key_id < 0) |
1219 | return CMD_WARNING_CONFIG_FAILED; | |
d62a17ae | 1220 | } |
1221 | ||
3d1c6dc2 | 1222 | if (argv_find(argv, argc, "authentication-key", &idx)) { |
cbb9b53d | 1223 | /* Reset authentication-key to 0 */ |
3d1c6dc2 CS |
1224 | memset(auth_key, 0, OSPF_AUTH_SIMPLE_SIZE + 1); |
1225 | vl_config.auth_key = auth_key; | |
1226 | } | |
d62a17ae | 1227 | |
1228 | /* Action configuration */ | |
1229 | ||
1230 | return ospf_vl_set(ospf, &vl_config); | |
7a7be519 | 1231 | } |
1232 | ||
b1c02cec QY |
1233 | DEFUN (ospf_area_vlink_intervals, |
1234 | ospf_area_vlink_intervals_cmd, | |
1235 | "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)}", | |
1236 | VLINK_HELPSTR_IPADDR | |
1237 | VLINK_HELPSTR_TIME_PARAM) | |
1238 | { | |
a3d826f0 | 1239 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1240 | struct ospf_vl_config_data vl_config; |
1241 | int ret = 0; | |
1242 | ||
1243 | ospf_vl_config_data_init(&vl_config, vty); | |
1244 | ||
1245 | char *area_id = argv[1]->arg; | |
1246 | char *router_id = argv[3]->arg; | |
1247 | ||
1248 | ret = str2area_id(area_id, &vl_config.area_id, &vl_config.area_id_fmt); | |
1249 | if (ret < 0) { | |
1250 | vty_out(vty, "OSPF area ID is invalid\n"); | |
1251 | return CMD_WARNING_CONFIG_FAILED; | |
1252 | } | |
1253 | ||
1254 | ret = inet_aton(router_id, &vl_config.vl_peer); | |
1255 | if (!ret) { | |
1256 | vty_out(vty, "Please specify valid Router ID as a.b.c.d\n"); | |
1257 | return CMD_WARNING_CONFIG_FAILED; | |
1258 | } | |
1259 | ||
1260 | for (int idx = 4; idx < argc; idx++) { | |
1261 | if (strmatch(argv[idx]->text, "hello-interval")) | |
1262 | vl_config.hello_interval = | |
1263 | strtol(argv[++idx]->arg, NULL, 10); | |
1264 | else if (strmatch(argv[idx]->text, "retransmit-interval")) | |
1265 | vl_config.retransmit_interval = | |
1266 | strtol(argv[++idx]->arg, NULL, 10); | |
1267 | else if (strmatch(argv[idx]->text, "transmit-delay")) | |
1268 | vl_config.transmit_delay = | |
1269 | strtol(argv[++idx]->arg, NULL, 10); | |
1270 | else if (strmatch(argv[idx]->text, "dead-interval")) | |
1271 | vl_config.dead_interval = | |
1272 | strtol(argv[++idx]->arg, NULL, 10); | |
1273 | } | |
1274 | ||
1275 | /* Action configuration */ | |
1276 | return ospf_vl_set(ospf, &vl_config); | |
b1c02cec QY |
1277 | } |
1278 | ||
7a7be519 | 1279 | DEFUN (no_ospf_area_vlink_intervals, |
1280 | no_ospf_area_vlink_intervals_cmd, | |
a663a38e | 1281 | "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 | 1282 | NO_STR |
7a7be519 | 1283 | VLINK_HELPSTR_IPADDR |
7a7be519 | 1284 | VLINK_HELPSTR_TIME_PARAM) |
1285 | { | |
a3d826f0 | 1286 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1287 | struct ospf_vl_config_data vl_config; |
1288 | int ret = 0; | |
1289 | ||
1290 | ospf_vl_config_data_init(&vl_config, vty); | |
1291 | ||
1292 | char *area_id = argv[2]->arg; | |
1293 | char *router_id = argv[4]->arg; | |
1294 | ||
1295 | ret = str2area_id(area_id, &vl_config.area_id, &vl_config.area_id_fmt); | |
1296 | if (ret < 0) { | |
1297 | vty_out(vty, "OSPF area ID is invalid\n"); | |
1298 | return CMD_WARNING_CONFIG_FAILED; | |
1299 | } | |
1300 | ||
1301 | ret = inet_aton(router_id, &vl_config.vl_peer); | |
1302 | if (!ret) { | |
1303 | vty_out(vty, "Please specify valid Router ID as a.b.c.d\n"); | |
1304 | return CMD_WARNING_CONFIG_FAILED; | |
1305 | } | |
1306 | ||
1307 | for (int idx = 5; idx < argc; idx++) { | |
1308 | if (strmatch(argv[idx]->text, "hello-interval")) | |
1309 | vl_config.hello_interval = OSPF_HELLO_INTERVAL_DEFAULT; | |
1310 | else if (strmatch(argv[idx]->text, "retransmit-interval")) | |
1311 | vl_config.retransmit_interval = | |
1312 | OSPF_RETRANSMIT_INTERVAL_DEFAULT; | |
1313 | else if (strmatch(argv[idx]->text, "transmit-delay")) | |
1314 | vl_config.transmit_delay = OSPF_TRANSMIT_DELAY_DEFAULT; | |
1315 | else if (strmatch(argv[idx]->text, "dead-interval")) | |
1316 | vl_config.dead_interval = | |
1317 | OSPF_ROUTER_DEAD_INTERVAL_DEFAULT; | |
1318 | } | |
1319 | ||
1320 | /* Action configuration */ | |
1321 | return ospf_vl_set(ospf, &vl_config); | |
718e3744 | 1322 | } |
1323 | ||
a2c62831 | 1324 | DEFUN (ospf_area_shortcut, |
1325 | ospf_area_shortcut_cmd, | |
6147e2c6 | 1326 | "area <A.B.C.D|(0-4294967295)> shortcut <default|enable|disable>", |
718e3744 | 1327 | "OSPF area parameters\n" |
1328 | "OSPF area ID in IP address format\n" | |
1329 | "OSPF area ID as a decimal value\n" | |
1330 | "Configure the area's shortcutting mode\n" | |
1331 | "Set default shortcutting behavior\n" | |
1332 | "Enable shortcutting through the area\n" | |
1333 | "Disable shortcutting through the area\n") | |
1334 | { | |
a3d826f0 | 1335 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1336 | int idx_ipv4_number = 1; |
1337 | int idx_enable_disable = 3; | |
1338 | struct ospf_area *area; | |
1339 | struct in_addr area_id; | |
1340 | int mode; | |
1341 | int format; | |
1342 | ||
1343 | VTY_GET_OSPF_AREA_ID_NO_BB("shortcut", area_id, format, | |
1344 | argv[idx_ipv4_number]->arg); | |
1345 | ||
1346 | area = ospf_area_get(ospf, area_id); | |
1347 | ospf_area_display_format_set(ospf, area, format); | |
1348 | ||
1349 | if (strncmp(argv[idx_enable_disable]->arg, "de", 2) == 0) | |
1350 | mode = OSPF_SHORTCUT_DEFAULT; | |
1351 | else if (strncmp(argv[idx_enable_disable]->arg, "di", 2) == 0) | |
1352 | mode = OSPF_SHORTCUT_DISABLE; | |
1353 | else if (strncmp(argv[idx_enable_disable]->arg, "e", 1) == 0) | |
1354 | mode = OSPF_SHORTCUT_ENABLE; | |
1355 | else | |
1356 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 1357 | |
d62a17ae | 1358 | ospf_area_shortcut_set(ospf, area, mode); |
718e3744 | 1359 | |
d62a17ae | 1360 | if (ospf->abr_type != OSPF_ABR_SHORTCUT) |
1361 | vty_out(vty, | |
3efd0893 | 1362 | "Shortcut area setting will take effect only when the router is configured as Shortcut ABR\n"); |
718e3744 | 1363 | |
d62a17ae | 1364 | return CMD_SUCCESS; |
718e3744 | 1365 | } |
1366 | ||
a2c62831 | 1367 | DEFUN (no_ospf_area_shortcut, |
1368 | no_ospf_area_shortcut_cmd, | |
6147e2c6 | 1369 | "no area <A.B.C.D|(0-4294967295)> shortcut <enable|disable>", |
718e3744 | 1370 | NO_STR |
1371 | "OSPF area parameters\n" | |
1372 | "OSPF area ID in IP address format\n" | |
1373 | "OSPF area ID as a decimal value\n" | |
1374 | "Deconfigure the area's shortcutting mode\n" | |
1375 | "Deconfigure enabled shortcutting through the area\n" | |
1376 | "Deconfigure disabled shortcutting through the area\n") | |
1377 | { | |
a3d826f0 | 1378 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1379 | int idx_ipv4_number = 2; |
1380 | struct ospf_area *area; | |
1381 | struct in_addr area_id; | |
1382 | int format; | |
718e3744 | 1383 | |
d62a17ae | 1384 | VTY_GET_OSPF_AREA_ID_NO_BB("shortcut", area_id, format, |
1385 | argv[idx_ipv4_number]->arg); | |
718e3744 | 1386 | |
d62a17ae | 1387 | area = ospf_area_lookup_by_area_id(ospf, area_id); |
1388 | if (!area) | |
1389 | return CMD_SUCCESS; | |
718e3744 | 1390 | |
d62a17ae | 1391 | ospf_area_shortcut_unset(ospf, area); |
718e3744 | 1392 | |
d62a17ae | 1393 | return CMD_SUCCESS; |
718e3744 | 1394 | } |
1395 | ||
6b0655a2 | 1396 | |
a2c62831 | 1397 | DEFUN (ospf_area_stub, |
1398 | ospf_area_stub_cmd, | |
6147e2c6 | 1399 | "area <A.B.C.D|(0-4294967295)> stub", |
718e3744 | 1400 | "OSPF area parameters\n" |
1401 | "OSPF area ID in IP address format\n" | |
1402 | "OSPF area ID as a decimal value\n" | |
1403 | "Configure OSPF area as stub\n") | |
1404 | { | |
a3d826f0 | 1405 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1406 | int idx_ipv4_number = 1; |
1407 | struct in_addr area_id; | |
1408 | int ret, format; | |
1409 | ||
1410 | VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id, format, | |
1411 | argv[idx_ipv4_number]->arg); | |
1412 | ||
1413 | ret = ospf_area_stub_set(ospf, area_id); | |
1414 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
1415 | format); | |
1416 | if (ret == 0) { | |
1417 | vty_out(vty, | |
1418 | "First deconfigure all virtual link through this area\n"); | |
1419 | return CMD_WARNING_CONFIG_FAILED; | |
1420 | } | |
718e3744 | 1421 | |
44445dee S |
1422 | /* Flush the external LSAs from the specified area */ |
1423 | ospf_flush_lsa_from_area(ospf, area_id, OSPF_AS_EXTERNAL_LSA); | |
d62a17ae | 1424 | ospf_area_no_summary_unset(ospf, area_id); |
718e3744 | 1425 | |
d62a17ae | 1426 | return CMD_SUCCESS; |
718e3744 | 1427 | } |
1428 | ||
a2c62831 | 1429 | DEFUN (ospf_area_stub_no_summary, |
1430 | ospf_area_stub_no_summary_cmd, | |
6147e2c6 | 1431 | "area <A.B.C.D|(0-4294967295)> stub no-summary", |
718e3744 | 1432 | "OSPF stub parameters\n" |
1433 | "OSPF area ID in IP address format\n" | |
1434 | "OSPF area ID as a decimal value\n" | |
1435 | "Configure OSPF area as stub\n" | |
1436 | "Do not inject inter-area routes into stub\n") | |
1437 | { | |
a3d826f0 | 1438 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1439 | int idx_ipv4_number = 1; |
1440 | struct in_addr area_id; | |
1441 | int ret, format; | |
1442 | ||
1443 | VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id, format, | |
1444 | argv[idx_ipv4_number]->arg); | |
1445 | ||
1446 | ret = ospf_area_stub_set(ospf, area_id); | |
1447 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
1448 | format); | |
1449 | if (ret == 0) { | |
1450 | vty_out(vty, | |
1451 | "%% Area cannot be stub as it contains a virtual link\n"); | |
1452 | return CMD_WARNING_CONFIG_FAILED; | |
1453 | } | |
718e3744 | 1454 | |
d62a17ae | 1455 | ospf_area_no_summary_set(ospf, area_id); |
718e3744 | 1456 | |
d62a17ae | 1457 | return CMD_SUCCESS; |
718e3744 | 1458 | } |
1459 | ||
a2c62831 | 1460 | DEFUN (no_ospf_area_stub, |
1461 | no_ospf_area_stub_cmd, | |
6147e2c6 | 1462 | "no area <A.B.C.D|(0-4294967295)> stub", |
718e3744 | 1463 | NO_STR |
1464 | "OSPF area parameters\n" | |
1465 | "OSPF area ID in IP address format\n" | |
1466 | "OSPF area ID as a decimal value\n" | |
1467 | "Configure OSPF area as stub\n") | |
1468 | { | |
a3d826f0 | 1469 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1470 | int idx_ipv4_number = 2; |
1471 | struct in_addr area_id; | |
1472 | int format; | |
718e3744 | 1473 | |
d62a17ae | 1474 | VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id, format, |
1475 | argv[idx_ipv4_number]->arg); | |
718e3744 | 1476 | |
d62a17ae | 1477 | ospf_area_stub_unset(ospf, area_id); |
1478 | ospf_area_no_summary_unset(ospf, area_id); | |
718e3744 | 1479 | |
d62a17ae | 1480 | return CMD_SUCCESS; |
718e3744 | 1481 | } |
1482 | ||
a2c62831 | 1483 | DEFUN (no_ospf_area_stub_no_summary, |
1484 | no_ospf_area_stub_no_summary_cmd, | |
6147e2c6 | 1485 | "no area <A.B.C.D|(0-4294967295)> stub no-summary", |
718e3744 | 1486 | NO_STR |
1487 | "OSPF area parameters\n" | |
1488 | "OSPF area ID in IP address format\n" | |
1489 | "OSPF area ID as a decimal value\n" | |
1490 | "Configure OSPF area as stub\n" | |
1491 | "Do not inject inter-area routes into area\n") | |
1492 | { | |
a3d826f0 | 1493 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1494 | int idx_ipv4_number = 2; |
1495 | struct in_addr area_id; | |
1496 | int format; | |
718e3744 | 1497 | |
d62a17ae | 1498 | VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id, format, |
1499 | argv[idx_ipv4_number]->arg); | |
1500 | ospf_area_no_summary_unset(ospf, area_id); | |
718e3744 | 1501 | |
d62a17ae | 1502 | return CMD_SUCCESS; |
718e3744 | 1503 | } |
1504 | ||
d62a17ae | 1505 | static int ospf_area_nssa_cmd_handler(struct vty *vty, int argc, |
7ef56a73 CS |
1506 | struct cmd_token **argv, int cfg_nosum, |
1507 | int nosum) | |
718e3744 | 1508 | { |
a3d826f0 | 1509 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1510 | struct in_addr area_id; |
1511 | int ret, format; | |
1512 | ||
1513 | VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id, format, argv[1]->arg); | |
1514 | ||
1515 | ret = ospf_area_nssa_set(ospf, area_id); | |
1516 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
1517 | format); | |
1518 | if (ret == 0) { | |
1519 | vty_out(vty, | |
1520 | "%% Area cannot be nssa as it contains a virtual link\n"); | |
1521 | return CMD_WARNING_CONFIG_FAILED; | |
1522 | } | |
1523 | ||
1524 | if (argc > 3) { | |
1525 | if (strncmp(argv[3]->text, "translate-c", 11) == 0) | |
1526 | ospf_area_nssa_translator_role_set( | |
1527 | ospf, area_id, OSPF_NSSA_ROLE_CANDIDATE); | |
1528 | else if (strncmp(argv[3]->text, "translate-n", 11) == 0) | |
1529 | ospf_area_nssa_translator_role_set( | |
1530 | ospf, area_id, OSPF_NSSA_ROLE_NEVER); | |
1531 | else if (strncmp(argv[3]->text, "translate-a", 11) == 0) | |
1532 | ospf_area_nssa_translator_role_set( | |
1533 | ospf, area_id, OSPF_NSSA_ROLE_ALWAYS); | |
1534 | } else { | |
1535 | ospf_area_nssa_translator_role_set(ospf, area_id, | |
1536 | OSPF_NSSA_ROLE_CANDIDATE); | |
1537 | } | |
1538 | ||
7ef56a73 CS |
1539 | if (cfg_nosum) { |
1540 | if (nosum) | |
1541 | ospf_area_no_summary_set(ospf, area_id); | |
1542 | else | |
1543 | ospf_area_no_summary_unset(ospf, area_id); | |
1544 | } | |
d62a17ae | 1545 | |
44445dee S |
1546 | /* Flush the external LSA for the specified area */ |
1547 | ospf_flush_lsa_from_area(ospf, area_id, OSPF_AS_EXTERNAL_LSA); | |
d62a17ae | 1548 | ospf_schedule_abr_task(ospf); |
1549 | ||
1550 | return CMD_SUCCESS; | |
718e3744 | 1551 | } |
1552 | ||
718e3744 | 1553 | |
b0a053be | 1554 | DEFUN (ospf_area_nssa_translate, |
a2c62831 | 1555 | ospf_area_nssa_translate_cmd, |
6147e2c6 | 1556 | "area <A.B.C.D|(0-4294967295)> nssa <translate-candidate|translate-never|translate-always>", |
718e3744 | 1557 | "OSPF area parameters\n" |
1558 | "OSPF area ID in IP address format\n" | |
1559 | "OSPF area ID as a decimal value\n" | |
1560 | "Configure OSPF area as nssa\n" | |
1561 | "Configure NSSA-ABR for translate election (default)\n" | |
1562 | "Configure NSSA-ABR to never translate\n" | |
1563 | "Configure NSSA-ABR to always translate\n") | |
b0a053be | 1564 | { |
7ef56a73 | 1565 | return ospf_area_nssa_cmd_handler(vty, argc, argv, 0, 0); |
b0a053be | 1566 | } |
1567 | ||
1568 | DEFUN (ospf_area_nssa, | |
1569 | ospf_area_nssa_cmd, | |
6147e2c6 | 1570 | "area <A.B.C.D|(0-4294967295)> nssa", |
b0a053be | 1571 | "OSPF area parameters\n" |
1572 | "OSPF area ID in IP address format\n" | |
1573 | "OSPF area ID as a decimal value\n" | |
1574 | "Configure OSPF area as nssa\n") | |
1575 | { | |
2643b2bc | 1576 | return ospf_area_nssa_cmd_handler(vty, argc, argv, 0, 0); |
b0a053be | 1577 | } |
718e3744 | 1578 | |
c317eddb | 1579 | DEFUN(ospf_area_nssa_suppress_fa, ospf_area_nssa_suppress_fa_cmd, |
1580 | "area <A.B.C.D|(0-4294967295)> nssa suppress-fa", | |
1581 | "OSPF area parameters\n" | |
1582 | "OSPF area ID in IP address format\n" | |
1583 | "OSPF area ID as a decimal value\n" | |
1584 | "Configure OSPF area as nssa\n" | |
1585 | "Suppress forwarding address\n") | |
1586 | { | |
1587 | int idx_ipv4_number = 1; | |
1588 | struct in_addr area_id; | |
1589 | int format; | |
1590 | ||
1591 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
1592 | VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id, format, | |
1593 | argv[idx_ipv4_number]->arg); | |
1594 | ||
1595 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
1596 | format); | |
1597 | ospf_area_nssa_suppress_fa_set(ospf, area_id); | |
1598 | ||
1599 | ospf_schedule_abr_task(ospf); | |
1600 | ||
1601 | return CMD_SUCCESS; | |
1602 | } | |
1603 | ||
1604 | DEFUN(no_ospf_area_nssa_suppress_fa, no_ospf_area_nssa_suppress_fa_cmd, | |
1605 | "no area <A.B.C.D|(0-4294967295)> nssa suppress-fa", | |
1606 | NO_STR | |
1607 | "OSPF area parameters\n" | |
1608 | "OSPF area ID in IP address format\n" | |
1609 | "OSPF area ID as a decimal value\n" | |
1610 | "Configure OSPF area as nssa\n" | |
1611 | "Suppress forwarding address\n") | |
1612 | { | |
1613 | int idx_ipv4_number = 2; | |
1614 | struct in_addr area_id; | |
1615 | int format; | |
1616 | ||
1617 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
1618 | ||
1619 | VTY_GET_OSPF_AREA_ID_NO_BB("nssa", area_id, format, | |
1620 | argv[idx_ipv4_number]->arg); | |
1621 | ||
1622 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
1623 | format); | |
1624 | ospf_area_nssa_suppress_fa_unset(ospf, area_id); | |
1625 | ||
1626 | ospf_schedule_abr_task(ospf); | |
1627 | ||
1628 | return CMD_SUCCESS; | |
1629 | } | |
1630 | ||
a2c62831 | 1631 | DEFUN (ospf_area_nssa_no_summary, |
1632 | ospf_area_nssa_no_summary_cmd, | |
6147e2c6 | 1633 | "area <A.B.C.D|(0-4294967295)> nssa no-summary", |
718e3744 | 1634 | "OSPF area parameters\n" |
1635 | "OSPF area ID in IP address format\n" | |
1636 | "OSPF area ID as a decimal value\n" | |
1637 | "Configure OSPF area as nssa\n" | |
1638 | "Do not inject inter-area routes into nssa\n") | |
1639 | { | |
7ef56a73 CS |
1640 | int idx_ipv4_number = 1; |
1641 | struct in_addr area_id; | |
1642 | int format; | |
1643 | ||
1644 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
1645 | VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id, format, | |
1646 | argv[idx_ipv4_number]->arg); | |
1647 | ||
1648 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
1649 | format); | |
1650 | ospf_area_nssa_no_summary_set(ospf, area_id); | |
1651 | ||
1652 | ospf_schedule_abr_task(ospf); | |
1653 | ||
1654 | return CMD_SUCCESS; | |
1655 | } | |
1656 | ||
1657 | DEFUN (no_ospf_area_nssa_no_summary, | |
1658 | no_ospf_area_nssa_no_summary_cmd, | |
1659 | "no area <A.B.C.D|(0-4294967295)> nssa no-summary", | |
1660 | NO_STR | |
1661 | "OSPF area parameters\n" | |
1662 | "OSPF area ID in IP address format\n" | |
1663 | "OSPF area ID as a decimal value\n" | |
1664 | "Configure OSPF area as nssa\n" | |
1665 | "Do not inject inter-area routes into nssa\n") | |
1666 | { | |
1667 | int idx_ipv4_number = 2; | |
1668 | struct in_addr area_id; | |
1669 | int format; | |
1670 | ||
1671 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
1672 | ||
1673 | VTY_GET_OSPF_AREA_ID_NO_BB("nssa", area_id, format, | |
1674 | argv[idx_ipv4_number]->arg); | |
1675 | ||
1676 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
1677 | format); | |
1678 | ospf_area_no_summary_unset(ospf, area_id); | |
1679 | ||
1680 | ospf_schedule_abr_task(ospf); | |
1681 | ||
1682 | return CMD_SUCCESS; | |
718e3744 | 1683 | } |
1684 | ||
a2c62831 | 1685 | DEFUN (no_ospf_area_nssa, |
1686 | no_ospf_area_nssa_cmd, | |
7ef56a73 | 1687 | "no area <A.B.C.D|(0-4294967295)> nssa [<translate-candidate|translate-never|translate-always>]", |
718e3744 | 1688 | NO_STR |
1689 | "OSPF area parameters\n" | |
1690 | "OSPF area ID in IP address format\n" | |
1691 | "OSPF area ID as a decimal value\n" | |
7a7be519 | 1692 | "Configure OSPF area as nssa\n" |
1693 | "Configure NSSA-ABR for translate election (default)\n" | |
1694 | "Configure NSSA-ABR to never translate\n" | |
7ef56a73 | 1695 | "Configure NSSA-ABR to always translate\n") |
22b27e95 | 1696 | { |
a3d826f0 | 1697 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1698 | int idx_ipv4_number = 2; |
1699 | struct in_addr area_id; | |
1700 | int format; | |
718e3744 | 1701 | |
d62a17ae | 1702 | VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id, format, |
1703 | argv[idx_ipv4_number]->arg); | |
718e3744 | 1704 | |
44445dee S |
1705 | /* Flush the NSSA LSA for the specified area */ |
1706 | ospf_flush_lsa_from_area(ospf, area_id, OSPF_AS_NSSA_LSA); | |
7ef56a73 | 1707 | ospf_area_nssa_unset(ospf, area_id, argc); |
718e3744 | 1708 | |
d62a17ae | 1709 | ospf_schedule_abr_task(ospf); |
b0a053be | 1710 | |
d62a17ae | 1711 | return CMD_SUCCESS; |
718e3744 | 1712 | } |
1713 | ||
718e3744 | 1714 | |
a2c62831 | 1715 | DEFUN (ospf_area_default_cost, |
1716 | ospf_area_default_cost_cmd, | |
6147e2c6 | 1717 | "area <A.B.C.D|(0-4294967295)> default-cost (0-16777215)", |
718e3744 | 1718 | "OSPF area parameters\n" |
1719 | "OSPF area ID in IP address format\n" | |
1720 | "OSPF area ID as a decimal value\n" | |
1721 | "Set the summary-default cost of a NSSA or stub area\n" | |
1722 | "Stub's advertised default summary cost\n") | |
1723 | { | |
a3d826f0 | 1724 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1725 | int idx_ipv4_number = 1; |
1726 | int idx_number = 3; | |
1727 | struct ospf_area *area; | |
1728 | struct in_addr area_id; | |
d7c0a89a | 1729 | uint32_t cost; |
d62a17ae | 1730 | int format; |
1731 | struct prefix_ipv4 p; | |
1732 | ||
1733 | VTY_GET_OSPF_AREA_ID_NO_BB("default-cost", area_id, format, | |
1734 | argv[idx_ipv4_number]->arg); | |
1735 | cost = strtoul(argv[idx_number]->arg, NULL, 10); | |
1736 | ||
1737 | area = ospf_area_get(ospf, area_id); | |
1738 | ospf_area_display_format_set(ospf, area, format); | |
1739 | ||
1740 | if (area->external_routing == OSPF_AREA_DEFAULT) { | |
1741 | vty_out(vty, "The area is neither stub, nor NSSA\n"); | |
1742 | return CMD_WARNING_CONFIG_FAILED; | |
1743 | } | |
ba682537 | 1744 | |
d62a17ae | 1745 | area->default_cost = cost; |
1746 | ||
1747 | p.family = AF_INET; | |
1748 | p.prefix.s_addr = OSPF_DEFAULT_DESTINATION; | |
1749 | p.prefixlen = 0; | |
1750 | if (IS_DEBUG_OSPF_EVENT) | |
1751 | zlog_debug( | |
96b663a3 MS |
1752 | "ospf_abr_announce_stub_defaults(): announcing 0.0.0.0/0 to area %pI4", |
1753 | &area->area_id); | |
d62a17ae | 1754 | ospf_abr_announce_network_to_area(&p, area->default_cost, area); |
1755 | ||
1756 | return CMD_SUCCESS; | |
718e3744 | 1757 | } |
1758 | ||
a2c62831 | 1759 | DEFUN (no_ospf_area_default_cost, |
1760 | no_ospf_area_default_cost_cmd, | |
6147e2c6 | 1761 | "no area <A.B.C.D|(0-4294967295)> default-cost (0-16777215)", |
718e3744 | 1762 | NO_STR |
1763 | "OSPF area parameters\n" | |
1764 | "OSPF area ID in IP address format\n" | |
1765 | "OSPF area ID as a decimal value\n" | |
1766 | "Set the summary-default cost of a NSSA or stub area\n" | |
1767 | "Stub's advertised default summary cost\n") | |
1768 | { | |
a3d826f0 | 1769 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1770 | int idx_ipv4_number = 2; |
1771 | struct ospf_area *area; | |
1772 | struct in_addr area_id; | |
1773 | int format; | |
1774 | struct prefix_ipv4 p; | |
718e3744 | 1775 | |
d62a17ae | 1776 | VTY_GET_OSPF_AREA_ID_NO_BB("default-cost", area_id, format, |
1777 | argv[idx_ipv4_number]->arg); | |
718e3744 | 1778 | |
d62a17ae | 1779 | area = ospf_area_lookup_by_area_id(ospf, area_id); |
1780 | if (area == NULL) | |
1781 | return CMD_SUCCESS; | |
718e3744 | 1782 | |
d62a17ae | 1783 | if (area->external_routing == OSPF_AREA_DEFAULT) { |
1784 | vty_out(vty, "The area is neither stub, nor NSSA\n"); | |
1785 | return CMD_WARNING_CONFIG_FAILED; | |
1786 | } | |
718e3744 | 1787 | |
d62a17ae | 1788 | area->default_cost = 1; |
718e3744 | 1789 | |
d62a17ae | 1790 | p.family = AF_INET; |
1791 | p.prefix.s_addr = OSPF_DEFAULT_DESTINATION; | |
1792 | p.prefixlen = 0; | |
1793 | if (IS_DEBUG_OSPF_EVENT) | |
1794 | zlog_debug( | |
96b663a3 MS |
1795 | "ospf_abr_announce_stub_defaults(): announcing 0.0.0.0/0 to area %pI4", |
1796 | &area->area_id); | |
d62a17ae | 1797 | ospf_abr_announce_network_to_area(&p, area->default_cost, area); |
ba682537 | 1798 | |
1799 | ||
d62a17ae | 1800 | ospf_area_check_free(ospf, area_id); |
718e3744 | 1801 | |
d62a17ae | 1802 | return CMD_SUCCESS; |
718e3744 | 1803 | } |
1804 | ||
a2c62831 | 1805 | DEFUN (ospf_area_export_list, |
1806 | ospf_area_export_list_cmd, | |
6147e2c6 | 1807 | "area <A.B.C.D|(0-4294967295)> export-list NAME", |
718e3744 | 1808 | "OSPF area parameters\n" |
1809 | "OSPF area ID in IP address format\n" | |
1810 | "OSPF area ID as a decimal value\n" | |
1811 | "Set the filter for networks announced to other areas\n" | |
1812 | "Name of the access-list\n") | |
1813 | { | |
a3d826f0 | 1814 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1815 | int idx_ipv4_number = 1; |
1816 | struct ospf_area *area; | |
1817 | struct in_addr area_id; | |
1818 | int format; | |
718e3744 | 1819 | |
d62a17ae | 1820 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
52930766 | 1821 | |
d62a17ae | 1822 | area = ospf_area_get(ospf, area_id); |
1823 | ospf_area_display_format_set(ospf, area, format); | |
1824 | ospf_area_export_list_set(ospf, area, argv[3]->arg); | |
718e3744 | 1825 | |
d62a17ae | 1826 | return CMD_SUCCESS; |
718e3744 | 1827 | } |
1828 | ||
a2c62831 | 1829 | DEFUN (no_ospf_area_export_list, |
1830 | no_ospf_area_export_list_cmd, | |
6147e2c6 | 1831 | "no area <A.B.C.D|(0-4294967295)> export-list NAME", |
718e3744 | 1832 | NO_STR |
1833 | "OSPF area parameters\n" | |
1834 | "OSPF area ID in IP address format\n" | |
1835 | "OSPF area ID as a decimal value\n" | |
1836 | "Unset the filter for networks announced to other areas\n" | |
1837 | "Name of the access-list\n") | |
1838 | { | |
a3d826f0 | 1839 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1840 | int idx_ipv4_number = 2; |
1841 | struct ospf_area *area; | |
1842 | struct in_addr area_id; | |
1843 | int format; | |
718e3744 | 1844 | |
d62a17ae | 1845 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
52930766 | 1846 | |
d62a17ae | 1847 | area = ospf_area_lookup_by_area_id(ospf, area_id); |
1848 | if (area == NULL) | |
1849 | return CMD_SUCCESS; | |
718e3744 | 1850 | |
d62a17ae | 1851 | ospf_area_export_list_unset(ospf, area); |
718e3744 | 1852 | |
d62a17ae | 1853 | return CMD_SUCCESS; |
718e3744 | 1854 | } |
1855 | ||
1856 | ||
a2c62831 | 1857 | DEFUN (ospf_area_import_list, |
1858 | ospf_area_import_list_cmd, | |
6147e2c6 | 1859 | "area <A.B.C.D|(0-4294967295)> import-list NAME", |
718e3744 | 1860 | "OSPF area parameters\n" |
1861 | "OSPF area ID in IP address format\n" | |
1862 | "OSPF area ID as a decimal value\n" | |
1863 | "Set the filter for networks from other areas announced to the specified one\n" | |
1864 | "Name of the access-list\n") | |
1865 | { | |
a3d826f0 | 1866 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1867 | int idx_ipv4_number = 1; |
1868 | struct ospf_area *area; | |
1869 | struct in_addr area_id; | |
1870 | int format; | |
718e3744 | 1871 | |
d62a17ae | 1872 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
52930766 | 1873 | |
d62a17ae | 1874 | area = ospf_area_get(ospf, area_id); |
1875 | ospf_area_display_format_set(ospf, area, format); | |
1876 | ospf_area_import_list_set(ospf, area, argv[3]->arg); | |
718e3744 | 1877 | |
d62a17ae | 1878 | return CMD_SUCCESS; |
718e3744 | 1879 | } |
1880 | ||
a2c62831 | 1881 | DEFUN (no_ospf_area_import_list, |
1882 | no_ospf_area_import_list_cmd, | |
6147e2c6 | 1883 | "no area <A.B.C.D|(0-4294967295)> import-list NAME", |
718e3744 | 1884 | NO_STR |
1885 | "OSPF area parameters\n" | |
1886 | "OSPF area ID in IP address format\n" | |
1887 | "OSPF area ID as a decimal value\n" | |
1888 | "Unset the filter for networks announced to other areas\n" | |
1889 | "Name of the access-list\n") | |
1890 | { | |
a3d826f0 | 1891 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1892 | int idx_ipv4_number = 2; |
1893 | struct ospf_area *area; | |
1894 | struct in_addr area_id; | |
1895 | int format; | |
718e3744 | 1896 | |
d62a17ae | 1897 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
52930766 | 1898 | |
d62a17ae | 1899 | area = ospf_area_lookup_by_area_id(ospf, area_id); |
1900 | if (area == NULL) | |
1901 | return CMD_SUCCESS; | |
718e3744 | 1902 | |
d62a17ae | 1903 | ospf_area_import_list_unset(ospf, area); |
718e3744 | 1904 | |
d62a17ae | 1905 | return CMD_SUCCESS; |
718e3744 | 1906 | } |
1907 | ||
a2c62831 | 1908 | DEFUN (ospf_area_filter_list, |
1909 | ospf_area_filter_list_cmd, | |
6147e2c6 | 1910 | "area <A.B.C.D|(0-4294967295)> filter-list prefix WORD <in|out>", |
718e3744 | 1911 | "OSPF area parameters\n" |
1912 | "OSPF area ID in IP address format\n" | |
1913 | "OSPF area ID as a decimal value\n" | |
1914 | "Filter networks between OSPF areas\n" | |
1915 | "Filter prefixes between OSPF areas\n" | |
1916 | "Name of an IP prefix-list\n" | |
1917 | "Filter networks sent to this area\n" | |
1918 | "Filter networks sent from this area\n") | |
1919 | { | |
a3d826f0 | 1920 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1921 | int idx_ipv4_number = 1; |
1922 | int idx_word = 4; | |
1923 | int idx_in_out = 5; | |
1924 | struct ospf_area *area; | |
1925 | struct in_addr area_id; | |
1926 | struct prefix_list *plist; | |
1927 | int format; | |
1928 | ||
1929 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); | |
1930 | ||
1931 | area = ospf_area_get(ospf, area_id); | |
1932 | ospf_area_display_format_set(ospf, area, format); | |
1933 | plist = prefix_list_lookup(AFI_IP, argv[idx_word]->arg); | |
1934 | if (strncmp(argv[idx_in_out]->arg, "in", 2) == 0) { | |
1935 | PREFIX_LIST_IN(area) = plist; | |
1936 | if (PREFIX_NAME_IN(area)) | |
1937 | free(PREFIX_NAME_IN(area)); | |
1938 | ||
1939 | PREFIX_NAME_IN(area) = strdup(argv[idx_word]->arg); | |
1940 | ospf_schedule_abr_task(ospf); | |
1941 | } else { | |
1942 | PREFIX_LIST_OUT(area) = plist; | |
1943 | if (PREFIX_NAME_OUT(area)) | |
1944 | free(PREFIX_NAME_OUT(area)); | |
1945 | ||
1946 | PREFIX_NAME_OUT(area) = strdup(argv[idx_word]->arg); | |
1947 | ospf_schedule_abr_task(ospf); | |
1948 | } | |
718e3744 | 1949 | |
d62a17ae | 1950 | return CMD_SUCCESS; |
718e3744 | 1951 | } |
1952 | ||
a2c62831 | 1953 | DEFUN (no_ospf_area_filter_list, |
1954 | no_ospf_area_filter_list_cmd, | |
6147e2c6 | 1955 | "no area <A.B.C.D|(0-4294967295)> filter-list prefix WORD <in|out>", |
718e3744 | 1956 | NO_STR |
1957 | "OSPF area parameters\n" | |
1958 | "OSPF area ID in IP address format\n" | |
1959 | "OSPF area ID as a decimal value\n" | |
1960 | "Filter networks between OSPF areas\n" | |
1961 | "Filter prefixes between OSPF areas\n" | |
1962 | "Name of an IP prefix-list\n" | |
1963 | "Filter networks sent to this area\n" | |
1964 | "Filter networks sent from this area\n") | |
1965 | { | |
a3d826f0 | 1966 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1967 | int idx_ipv4_number = 2; |
1968 | int idx_word = 5; | |
1969 | int idx_in_out = 6; | |
1970 | struct ospf_area *area; | |
1971 | struct in_addr area_id; | |
1972 | int format; | |
718e3744 | 1973 | |
d62a17ae | 1974 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
718e3744 | 1975 | |
d62a17ae | 1976 | if ((area = ospf_area_lookup_by_area_id(ospf, area_id)) == NULL) |
1977 | return CMD_SUCCESS; | |
718e3744 | 1978 | |
d62a17ae | 1979 | if (strncmp(argv[idx_in_out]->arg, "in", 2) == 0) { |
1980 | if (PREFIX_NAME_IN(area)) | |
1981 | if (strcmp(PREFIX_NAME_IN(area), argv[idx_word]->arg) | |
1982 | != 0) | |
1983 | return CMD_SUCCESS; | |
718e3744 | 1984 | |
d62a17ae | 1985 | PREFIX_LIST_IN(area) = NULL; |
1986 | if (PREFIX_NAME_IN(area)) | |
1987 | free(PREFIX_NAME_IN(area)); | |
718e3744 | 1988 | |
d62a17ae | 1989 | PREFIX_NAME_IN(area) = NULL; |
718e3744 | 1990 | |
d62a17ae | 1991 | ospf_schedule_abr_task(ospf); |
1992 | } else { | |
1993 | if (PREFIX_NAME_OUT(area)) | |
1994 | if (strcmp(PREFIX_NAME_OUT(area), argv[idx_word]->arg) | |
1995 | != 0) | |
1996 | return CMD_SUCCESS; | |
718e3744 | 1997 | |
d62a17ae | 1998 | PREFIX_LIST_OUT(area) = NULL; |
1999 | if (PREFIX_NAME_OUT(area)) | |
2000 | free(PREFIX_NAME_OUT(area)); | |
718e3744 | 2001 | |
d62a17ae | 2002 | PREFIX_NAME_OUT(area) = NULL; |
718e3744 | 2003 | |
d62a17ae | 2004 | ospf_schedule_abr_task(ospf); |
2005 | } | |
2006 | ||
2007 | return CMD_SUCCESS; | |
718e3744 | 2008 | } |
2009 | ||
6b0655a2 | 2010 | |
a2c62831 | 2011 | DEFUN (ospf_area_authentication_message_digest, |
2012 | ospf_area_authentication_message_digest_cmd, | |
32573073 QY |
2013 | "[no] area <A.B.C.D|(0-4294967295)> authentication message-digest", |
2014 | NO_STR | |
718e3744 | 2015 | "OSPF area parameters\n" |
2b00515a CF |
2016 | "OSPF area ID in IP address format\n" |
2017 | "OSPF area ID as a decimal value\n" | |
718e3744 | 2018 | "Enable authentication\n" |
2019 | "Use message-digest authentication\n") | |
2020 | { | |
a3d826f0 | 2021 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
ca19319b | 2022 | int idx = 0; |
d62a17ae | 2023 | struct ospf_area *area; |
2024 | struct in_addr area_id; | |
2025 | int format; | |
718e3744 | 2026 | |
ca19319b | 2027 | argv_find(argv, argc, "area", &idx); |
2028 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx + 1]->arg); | |
718e3744 | 2029 | |
d62a17ae | 2030 | area = ospf_area_get(ospf, area_id); |
2031 | ospf_area_display_format_set(ospf, area, format); | |
996c9314 LB |
2032 | area->auth_type = strmatch(argv[0]->text, "no") |
2033 | ? OSPF_AUTH_NULL | |
2034 | : OSPF_AUTH_CRYPTOGRAPHIC; | |
718e3744 | 2035 | |
d62a17ae | 2036 | return CMD_SUCCESS; |
718e3744 | 2037 | } |
2038 | ||
a2c62831 | 2039 | DEFUN (ospf_area_authentication, |
2040 | ospf_area_authentication_cmd, | |
6147e2c6 | 2041 | "area <A.B.C.D|(0-4294967295)> authentication", |
718e3744 | 2042 | "OSPF area parameters\n" |
2043 | "OSPF area ID in IP address format\n" | |
2044 | "OSPF area ID as a decimal value\n" | |
2045 | "Enable authentication\n") | |
2046 | { | |
a3d826f0 | 2047 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2048 | int idx_ipv4_number = 1; |
2049 | struct ospf_area *area; | |
2050 | struct in_addr area_id; | |
2051 | int format; | |
718e3744 | 2052 | |
d62a17ae | 2053 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
718e3744 | 2054 | |
d62a17ae | 2055 | area = ospf_area_get(ospf, area_id); |
2056 | ospf_area_display_format_set(ospf, area, format); | |
2057 | area->auth_type = OSPF_AUTH_SIMPLE; | |
718e3744 | 2058 | |
d62a17ae | 2059 | return CMD_SUCCESS; |
718e3744 | 2060 | } |
2061 | ||
a2c62831 | 2062 | DEFUN (no_ospf_area_authentication, |
2063 | no_ospf_area_authentication_cmd, | |
6147e2c6 | 2064 | "no area <A.B.C.D|(0-4294967295)> authentication", |
718e3744 | 2065 | NO_STR |
2066 | "OSPF area parameters\n" | |
2067 | "OSPF area ID in IP address format\n" | |
2068 | "OSPF area ID as a decimal value\n" | |
2069 | "Enable authentication\n") | |
2070 | { | |
a3d826f0 | 2071 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2072 | int idx_ipv4_number = 2; |
2073 | struct ospf_area *area; | |
2074 | struct in_addr area_id; | |
2075 | int format; | |
718e3744 | 2076 | |
d62a17ae | 2077 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
718e3744 | 2078 | |
d62a17ae | 2079 | area = ospf_area_lookup_by_area_id(ospf, area_id); |
2080 | if (area == NULL) | |
2081 | return CMD_SUCCESS; | |
718e3744 | 2082 | |
d62a17ae | 2083 | area->auth_type = OSPF_AUTH_NULL; |
718e3744 | 2084 | |
d62a17ae | 2085 | ospf_area_check_free(ospf, area_id); |
2086 | ||
2087 | return CMD_SUCCESS; | |
718e3744 | 2088 | } |
2089 | ||
6b0655a2 | 2090 | |
718e3744 | 2091 | DEFUN (ospf_abr_type, |
2092 | ospf_abr_type_cmd, | |
6147e2c6 | 2093 | "ospf abr-type <cisco|ibm|shortcut|standard>", |
718e3744 | 2094 | "OSPF specific commands\n" |
2095 | "Set OSPF ABR type\n" | |
2096 | "Alternative ABR, cisco implementation\n" | |
2097 | "Alternative ABR, IBM implementation\n" | |
2098 | "Shortcut ABR\n" | |
2099 | "Standard behavior (RFC2328)\n") | |
2100 | { | |
a3d826f0 | 2101 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2102 | int idx_vendor = 2; |
d7c0a89a | 2103 | uint8_t abr_type = OSPF_ABR_UNKNOWN; |
d62a17ae | 2104 | |
2105 | if (strncmp(argv[idx_vendor]->arg, "c", 1) == 0) | |
2106 | abr_type = OSPF_ABR_CISCO; | |
2107 | else if (strncmp(argv[idx_vendor]->arg, "i", 1) == 0) | |
2108 | abr_type = OSPF_ABR_IBM; | |
2109 | else if (strncmp(argv[idx_vendor]->arg, "sh", 2) == 0) | |
2110 | abr_type = OSPF_ABR_SHORTCUT; | |
2111 | else if (strncmp(argv[idx_vendor]->arg, "st", 2) == 0) | |
2112 | abr_type = OSPF_ABR_STAND; | |
2113 | else | |
2114 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 2115 | |
d62a17ae | 2116 | /* If ABR type value is changed, schedule ABR task. */ |
2117 | if (ospf->abr_type != abr_type) { | |
2118 | ospf->abr_type = abr_type; | |
2119 | ospf_schedule_abr_task(ospf); | |
2120 | } | |
2121 | ||
2122 | return CMD_SUCCESS; | |
718e3744 | 2123 | } |
2124 | ||
2125 | DEFUN (no_ospf_abr_type, | |
2126 | no_ospf_abr_type_cmd, | |
6147e2c6 | 2127 | "no ospf abr-type <cisco|ibm|shortcut|standard>", |
718e3744 | 2128 | NO_STR |
2129 | "OSPF specific commands\n" | |
2130 | "Set OSPF ABR type\n" | |
2131 | "Alternative ABR, cisco implementation\n" | |
2132 | "Alternative ABR, IBM implementation\n" | |
3a2d747c QY |
2133 | "Shortcut ABR\n" |
2134 | "Standard ABR\n") | |
718e3744 | 2135 | { |
a3d826f0 | 2136 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2137 | int idx_vendor = 3; |
d7c0a89a | 2138 | uint8_t abr_type = OSPF_ABR_UNKNOWN; |
d62a17ae | 2139 | |
2140 | if (strncmp(argv[idx_vendor]->arg, "c", 1) == 0) | |
2141 | abr_type = OSPF_ABR_CISCO; | |
2142 | else if (strncmp(argv[idx_vendor]->arg, "i", 1) == 0) | |
2143 | abr_type = OSPF_ABR_IBM; | |
2144 | else if (strncmp(argv[idx_vendor]->arg, "sh", 2) == 0) | |
2145 | abr_type = OSPF_ABR_SHORTCUT; | |
2146 | else if (strncmp(argv[idx_vendor]->arg, "st", 2) == 0) | |
2147 | abr_type = OSPF_ABR_STAND; | |
2148 | else | |
2149 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 2150 | |
d62a17ae | 2151 | /* If ABR type value is changed, schedule ABR task. */ |
2152 | if (ospf->abr_type == abr_type) { | |
2153 | ospf->abr_type = OSPF_ABR_DEFAULT; | |
2154 | ospf_schedule_abr_task(ospf); | |
2155 | } | |
2156 | ||
2157 | return CMD_SUCCESS; | |
718e3744 | 2158 | } |
2159 | ||
d7e60dd7 AS |
2160 | DEFUN (ospf_log_adjacency_changes, |
2161 | ospf_log_adjacency_changes_cmd, | |
2162 | "log-adjacency-changes", | |
2163 | "Log changes in adjacency state\n") | |
2164 | { | |
a3d826f0 | 2165 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d7e60dd7 | 2166 | |
d62a17ae | 2167 | SET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES); |
2168 | UNSET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL); | |
2169 | return CMD_SUCCESS; | |
d7e60dd7 AS |
2170 | } |
2171 | ||
2172 | DEFUN (ospf_log_adjacency_changes_detail, | |
2173 | ospf_log_adjacency_changes_detail_cmd, | |
2174 | "log-adjacency-changes detail", | |
2175 | "Log changes in adjacency state\n" | |
2176 | "Log all state changes\n") | |
2177 | { | |
a3d826f0 | 2178 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d7e60dd7 | 2179 | |
d62a17ae | 2180 | SET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES); |
2181 | SET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL); | |
2182 | return CMD_SUCCESS; | |
d7e60dd7 AS |
2183 | } |
2184 | ||
2185 | DEFUN (no_ospf_log_adjacency_changes, | |
2186 | no_ospf_log_adjacency_changes_cmd, | |
2187 | "no log-adjacency-changes", | |
2188 | NO_STR | |
2189 | "Log changes in adjacency state\n") | |
2190 | { | |
a3d826f0 | 2191 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d7e60dd7 | 2192 | |
d62a17ae | 2193 | UNSET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL); |
2194 | UNSET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES); | |
2195 | return CMD_SUCCESS; | |
d7e60dd7 AS |
2196 | } |
2197 | ||
2198 | DEFUN (no_ospf_log_adjacency_changes_detail, | |
2199 | no_ospf_log_adjacency_changes_detail_cmd, | |
2200 | "no log-adjacency-changes detail", | |
2201 | NO_STR | |
2202 | "Log changes in adjacency state\n" | |
2203 | "Log all state changes\n") | |
2204 | { | |
a3d826f0 | 2205 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d7e60dd7 | 2206 | |
d62a17ae | 2207 | UNSET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL); |
2208 | return CMD_SUCCESS; | |
d7e60dd7 AS |
2209 | } |
2210 | ||
718e3744 | 2211 | DEFUN (ospf_compatible_rfc1583, |
2212 | ospf_compatible_rfc1583_cmd, | |
2213 | "compatible rfc1583", | |
2214 | "OSPF compatibility list\n" | |
2215 | "compatible with RFC 1583\n") | |
2216 | { | |
a3d826f0 | 2217 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
718e3744 | 2218 | |
d62a17ae | 2219 | if (!CHECK_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE)) { |
2220 | SET_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE); | |
2221 | ospf_spf_calculate_schedule(ospf, SPF_FLAG_CONFIG_CHANGE); | |
2222 | } | |
2223 | return CMD_SUCCESS; | |
718e3744 | 2224 | } |
2225 | ||
2226 | DEFUN (no_ospf_compatible_rfc1583, | |
2227 | no_ospf_compatible_rfc1583_cmd, | |
2228 | "no compatible rfc1583", | |
2229 | NO_STR | |
2230 | "OSPF compatibility list\n" | |
2231 | "compatible with RFC 1583\n") | |
2232 | { | |
a3d826f0 | 2233 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
718e3744 | 2234 | |
d62a17ae | 2235 | if (CHECK_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE)) { |
2236 | UNSET_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE); | |
2237 | ospf_spf_calculate_schedule(ospf, SPF_FLAG_CONFIG_CHANGE); | |
2238 | } | |
2239 | return CMD_SUCCESS; | |
718e3744 | 2240 | } |
2241 | ||
d62a17ae | 2242 | ALIAS(ospf_compatible_rfc1583, ospf_rfc1583_flag_cmd, |
2243 | "ospf rfc1583compatibility", | |
2244 | "OSPF specific commands\n" | |
2245 | "Enable the RFC1583Compatibility flag\n") | |
718e3744 | 2246 | |
d62a17ae | 2247 | ALIAS(no_ospf_compatible_rfc1583, no_ospf_rfc1583_flag_cmd, |
9d303b37 | 2248 | "no ospf rfc1583compatibility", NO_STR |
d62a17ae | 2249 | "OSPF specific commands\n" |
2250 | "Disable the RFC1583Compatibility flag\n") | |
6b0655a2 | 2251 | |
d62a17ae | 2252 | static int ospf_timers_spf_set(struct vty *vty, unsigned int delay, |
2253 | unsigned int hold, unsigned int max) | |
d24f6e2a | 2254 | { |
a3d826f0 | 2255 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
7c8ff89e | 2256 | |
d62a17ae | 2257 | ospf->spf_delay = delay; |
2258 | ospf->spf_holdtime = hold; | |
2259 | ospf->spf_max_holdtime = max; | |
2260 | ||
2261 | return CMD_SUCCESS; | |
d24f6e2a | 2262 | } |
718e3744 | 2263 | |
ac7424f9 MR |
2264 | DEFUN (ospf_timers_min_ls_interval, |
2265 | ospf_timers_min_ls_interval_cmd, | |
6147e2c6 | 2266 | "timers throttle lsa all (0-5000)", |
ac7424f9 MR |
2267 | "Adjust routing timers\n" |
2268 | "Throttling adaptive timer\n" | |
2269 | "LSA delay between transmissions\n" | |
813d4307 | 2270 | "All LSA types\n" |
ac7424f9 MR |
2271 | "Delay (msec) between sending LSAs\n") |
2272 | { | |
a3d826f0 | 2273 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2274 | int idx_number = 4; |
2275 | unsigned int interval; | |
ac7424f9 | 2276 | |
d62a17ae | 2277 | if (argc < 5) { |
2278 | vty_out(vty, "Insufficient arguments\n"); | |
2279 | return CMD_WARNING_CONFIG_FAILED; | |
2280 | } | |
ac7424f9 | 2281 | |
d62a17ae | 2282 | interval = strtoul(argv[idx_number]->arg, NULL, 10); |
ac7424f9 | 2283 | |
d62a17ae | 2284 | ospf->min_ls_interval = interval; |
ac7424f9 | 2285 | |
d62a17ae | 2286 | return CMD_SUCCESS; |
ac7424f9 MR |
2287 | } |
2288 | ||
2289 | DEFUN (no_ospf_timers_min_ls_interval, | |
2290 | no_ospf_timers_min_ls_interval_cmd, | |
7a7be519 | 2291 | "no timers throttle lsa all [(0-5000)]", |
ac7424f9 MR |
2292 | NO_STR |
2293 | "Adjust routing timers\n" | |
2294 | "Throttling adaptive timer\n" | |
813d4307 | 2295 | "LSA delay between transmissions\n" |
7a7be519 | 2296 | "All LSA types\n" |
2297 | "Delay (msec) between sending LSAs\n") | |
ac7424f9 | 2298 | { |
a3d826f0 | 2299 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2300 | ospf->min_ls_interval = OSPF_MIN_LS_INTERVAL; |
ac7424f9 | 2301 | |
d62a17ae | 2302 | return CMD_SUCCESS; |
ac7424f9 MR |
2303 | } |
2304 | ||
d24f6e2a | 2305 | DEFUN (ospf_timers_throttle_spf, |
2306 | ospf_timers_throttle_spf_cmd, | |
6147e2c6 | 2307 | "timers throttle spf (0-600000) (0-600000) (0-600000)", |
d24f6e2a | 2308 | "Adjust routing timers\n" |
2309 | "Throttling adaptive timer\n" | |
2310 | "OSPF SPF timers\n" | |
2311 | "Delay (msec) from first change received till SPF calculation\n" | |
2312 | "Initial hold time (msec) between consecutive SPF calculations\n" | |
2313 | "Maximum hold time (msec)\n") | |
2314 | { | |
d62a17ae | 2315 | int idx_number = 3; |
2316 | int idx_number_2 = 4; | |
2317 | int idx_number_3 = 5; | |
2318 | unsigned int delay, hold, max; | |
2319 | ||
2320 | if (argc < 6) { | |
2321 | vty_out(vty, "Insufficient arguments\n"); | |
2322 | return CMD_WARNING_CONFIG_FAILED; | |
2323 | } | |
2324 | ||
2325 | delay = strtoul(argv[idx_number]->arg, NULL, 10); | |
2326 | hold = strtoul(argv[idx_number_2]->arg, NULL, 10); | |
2327 | max = strtoul(argv[idx_number_3]->arg, NULL, 10); | |
2328 | ||
2329 | return ospf_timers_spf_set(vty, delay, hold, max); | |
d24f6e2a | 2330 | } |
2331 | ||
d24f6e2a | 2332 | DEFUN (no_ospf_timers_throttle_spf, |
2333 | no_ospf_timers_throttle_spf_cmd, | |
7a7be519 | 2334 | "no timers throttle spf [(0-600000)(0-600000)(0-600000)]", |
718e3744 | 2335 | NO_STR |
2336 | "Adjust routing timers\n" | |
d24f6e2a | 2337 | "Throttling adaptive timer\n" |
7a7be519 | 2338 | "OSPF SPF timers\n" |
2339 | "Delay (msec) from first change received till SPF calculation\n" | |
2340 | "Initial hold time (msec) between consecutive SPF calculations\n" | |
2341 | "Maximum hold time (msec)\n") | |
22b27e95 | 2342 | { |
d62a17ae | 2343 | return ospf_timers_spf_set(vty, OSPF_SPF_DELAY_DEFAULT, |
2344 | OSPF_SPF_HOLDTIME_DEFAULT, | |
2345 | OSPF_SPF_MAX_HOLDTIME_DEFAULT); | |
718e3744 | 2346 | } |
2347 | ||
b4a039bf | 2348 | |
0e88de35 QY |
2349 | DEFUN (ospf_timers_lsa_min_arrival, |
2350 | ospf_timers_lsa_min_arrival_cmd, | |
6147e2c6 | 2351 | "timers lsa min-arrival (0-600000)", |
b6927875 DS |
2352 | "Adjust routing timers\n" |
2353 | "OSPF LSA timers\n" | |
2354 | "Minimum delay in receiving new version of a LSA\n" | |
2355 | "Delay in milliseconds\n") | |
2356 | { | |
a3d826f0 | 2357 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
0e88de35 | 2358 | ospf->min_ls_arrival = strtoul(argv[argc - 1]->arg, NULL, 10); |
d62a17ae | 2359 | return CMD_SUCCESS; |
b6927875 DS |
2360 | } |
2361 | ||
0e88de35 QY |
2362 | DEFUN (no_ospf_timers_lsa_min_arrival, |
2363 | no_ospf_timers_lsa_min_arrival_cmd, | |
7a7be519 | 2364 | "no timers lsa min-arrival [(0-600000)]", |
b6927875 DS |
2365 | NO_STR |
2366 | "Adjust routing timers\n" | |
2367 | "OSPF LSA timers\n" | |
7a7be519 | 2368 | "Minimum delay in receiving new version of a LSA\n" |
2369 | "Delay in milliseconds\n") | |
b6927875 | 2370 | { |
a3d826f0 | 2371 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2372 | unsigned int minarrival; |
b6927875 | 2373 | |
d62a17ae | 2374 | if (argc > 4) { |
0e88de35 | 2375 | minarrival = strtoul(argv[argc - 1]->arg, NULL, 10); |
b6927875 | 2376 | |
d62a17ae | 2377 | if (ospf->min_ls_arrival != minarrival |
2378 | || minarrival == OSPF_MIN_LS_ARRIVAL) | |
2379 | return CMD_SUCCESS; | |
2380 | } | |
b6927875 | 2381 | |
d62a17ae | 2382 | ospf->min_ls_arrival = OSPF_MIN_LS_ARRIVAL; |
b6927875 | 2383 | |
d62a17ae | 2384 | return CMD_SUCCESS; |
b6927875 DS |
2385 | } |
2386 | ||
a2c62831 | 2387 | DEFUN (ospf_neighbor, |
2388 | ospf_neighbor_cmd, | |
7a7be519 | 2389 | "neighbor A.B.C.D [priority (0-255) [poll-interval (1-65535)]]", |
718e3744 | 2390 | NEIGHBOR_STR |
7a7be519 | 2391 | "Neighbor IP address\n" |
2392 | "Neighbor Priority\n" | |
2393 | "Priority\n" | |
2394 | "Dead Neighbor Polling interval\n" | |
2395 | "Seconds\n") | |
718e3744 | 2396 | { |
a3d826f0 | 2397 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2398 | int idx_ipv4 = 1; |
2399 | int idx_pri = 3; | |
2400 | int idx_poll = 5; | |
2401 | struct in_addr nbr_addr; | |
2402 | unsigned int priority = OSPF_NEIGHBOR_PRIORITY_DEFAULT; | |
2403 | unsigned int interval = OSPF_POLL_INTERVAL_DEFAULT; | |
718e3744 | 2404 | |
cc9b06ad DS |
2405 | if (!inet_aton(argv[idx_ipv4]->arg, &nbr_addr)) { |
2406 | vty_out(vty, "Please specify Neighbor ID by A.B.C.D\n"); | |
2407 | return CMD_WARNING_CONFIG_FAILED; | |
2408 | } | |
718e3744 | 2409 | |
d62a17ae | 2410 | if (argc > 2) |
2411 | priority = strtoul(argv[idx_pri]->arg, NULL, 10); | |
7a7be519 | 2412 | |
d62a17ae | 2413 | if (argc > 4) |
2414 | interval = strtoul(argv[idx_poll]->arg, NULL, 10); | |
718e3744 | 2415 | |
d62a17ae | 2416 | ospf_nbr_nbma_set(ospf, nbr_addr); |
7a7be519 | 2417 | |
d62a17ae | 2418 | if (argc > 2) |
2419 | ospf_nbr_nbma_priority_set(ospf, nbr_addr, priority); | |
7a7be519 | 2420 | |
d62a17ae | 2421 | if (argc > 4) |
2422 | ospf_nbr_nbma_poll_interval_set(ospf, nbr_addr, interval); | |
718e3744 | 2423 | |
d62a17ae | 2424 | return CMD_SUCCESS; |
718e3744 | 2425 | } |
2426 | ||
a2c62831 | 2427 | DEFUN (ospf_neighbor_poll_interval, |
2428 | ospf_neighbor_poll_interval_cmd, | |
7a7be519 | 2429 | "neighbor A.B.C.D poll-interval (1-65535) [priority (0-255)]", |
718e3744 | 2430 | NEIGHBOR_STR |
2431 | "Neighbor IP address\n" | |
2432 | "Dead Neighbor Polling interval\n" | |
7a7be519 | 2433 | "Seconds\n" |
2434 | "OSPF priority of non-broadcast neighbor\n" | |
2435 | "Priority\n") | |
22b27e95 | 2436 | { |
a3d826f0 | 2437 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2438 | int idx_ipv4 = 1; |
2439 | int idx_poll = 3; | |
2440 | int idx_pri = 5; | |
2441 | struct in_addr nbr_addr; | |
a2b6e694 | 2442 | unsigned int priority; |
2443 | unsigned int interval; | |
718e3744 | 2444 | |
cc9b06ad DS |
2445 | if (!inet_aton(argv[idx_ipv4]->arg, &nbr_addr)) { |
2446 | vty_out(vty, "Please specify Neighbor ID by A.B.C.D\n"); | |
2447 | return CMD_WARNING_CONFIG_FAILED; | |
2448 | } | |
718e3744 | 2449 | |
d62a17ae | 2450 | interval = strtoul(argv[idx_poll]->arg, NULL, 10); |
718e3744 | 2451 | |
a2b6e694 | 2452 | priority = argc > 4 ? strtoul(argv[idx_pri]->arg, NULL, 10) |
2453 | : OSPF_NEIGHBOR_PRIORITY_DEFAULT; | |
718e3744 | 2454 | |
d62a17ae | 2455 | ospf_nbr_nbma_set(ospf, nbr_addr); |
2456 | ospf_nbr_nbma_poll_interval_set(ospf, nbr_addr, interval); | |
7a7be519 | 2457 | |
d62a17ae | 2458 | if (argc > 4) |
2459 | ospf_nbr_nbma_priority_set(ospf, nbr_addr, priority); | |
718e3744 | 2460 | |
d62a17ae | 2461 | return CMD_SUCCESS; |
718e3744 | 2462 | } |
2463 | ||
a2c62831 | 2464 | DEFUN (no_ospf_neighbor, |
2465 | no_ospf_neighbor_cmd, | |
7a7be519 | 2466 | "no neighbor A.B.C.D [priority (0-255) [poll-interval (1-65525)]]", |
718e3744 | 2467 | NO_STR |
2468 | NEIGHBOR_STR | |
7a7be519 | 2469 | "Neighbor IP address\n" |
2470 | "Neighbor Priority\n" | |
2471 | "Priority\n" | |
2472 | "Dead Neighbor Polling interval\n" | |
2473 | "Seconds\n") | |
718e3744 | 2474 | { |
a3d826f0 | 2475 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2476 | int idx_ipv4 = 2; |
2477 | struct in_addr nbr_addr; | |
718e3744 | 2478 | |
cc9b06ad DS |
2479 | if (!inet_aton(argv[idx_ipv4]->arg, &nbr_addr)) { |
2480 | vty_out(vty, "Please specify Neighbor ID by A.B.C.D\n"); | |
2481 | return CMD_WARNING_CONFIG_FAILED; | |
2482 | } | |
718e3744 | 2483 | |
d62a17ae | 2484 | (void)ospf_nbr_nbma_unset(ospf, nbr_addr); |
718e3744 | 2485 | |
d62a17ae | 2486 | return CMD_SUCCESS; |
718e3744 | 2487 | } |
2488 | ||
7a7be519 | 2489 | DEFUN (no_ospf_neighbor_poll, |
2490 | no_ospf_neighbor_poll_cmd, | |
2491 | "no neighbor A.B.C.D poll-interval (1-65535) [priority (0-255)]", | |
2492 | NO_STR | |
2493 | NEIGHBOR_STR | |
2494 | "Neighbor IP address\n" | |
2495 | "Dead Neighbor Polling interval\n" | |
2496 | "Seconds\n" | |
2497 | "Neighbor Priority\n" | |
2498 | "Priority\n") | |
2499 | { | |
a3d826f0 | 2500 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2501 | int idx_ipv4 = 2; |
2502 | struct in_addr nbr_addr; | |
7a7be519 | 2503 | |
cc9b06ad DS |
2504 | if (!inet_aton(argv[idx_ipv4]->arg, &nbr_addr)) { |
2505 | vty_out(vty, "Please specify Neighbor ID by A.B.C.D\n"); | |
2506 | return CMD_WARNING_CONFIG_FAILED; | |
2507 | } | |
718e3744 | 2508 | |
d62a17ae | 2509 | (void)ospf_nbr_nbma_unset(ospf, nbr_addr); |
813d4307 | 2510 | |
d62a17ae | 2511 | return CMD_SUCCESS; |
7a7be519 | 2512 | } |
718e3744 | 2513 | |
bf2bfafd DW |
2514 | DEFUN (ospf_refresh_timer, |
2515 | ospf_refresh_timer_cmd, | |
6147e2c6 | 2516 | "refresh timer (10-1800)", |
718e3744 | 2517 | "Adjust refresh parameters\n" |
2518 | "Set refresh timer\n" | |
2519 | "Timer value in seconds\n") | |
2520 | { | |
a3d826f0 | 2521 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2522 | int idx_number = 2; |
2523 | unsigned int interval; | |
7c8ff89e | 2524 | |
d62a17ae | 2525 | interval = strtoul(argv[idx_number]->arg, NULL, 10); |
2526 | interval = (interval / OSPF_LSA_REFRESHER_GRANULARITY) | |
2527 | * OSPF_LSA_REFRESHER_GRANULARITY; | |
718e3744 | 2528 | |
d62a17ae | 2529 | ospf_timers_refresh_set(ospf, interval); |
718e3744 | 2530 | |
d62a17ae | 2531 | return CMD_SUCCESS; |
718e3744 | 2532 | } |
2533 | ||
bf2bfafd DW |
2534 | DEFUN (no_ospf_refresh_timer, |
2535 | no_ospf_refresh_timer_val_cmd, | |
7a7be519 | 2536 | "no refresh timer [(10-1800)]", |
3a2d747c | 2537 | NO_STR |
718e3744 | 2538 | "Adjust refresh parameters\n" |
2539 | "Unset refresh timer\n" | |
2540 | "Timer value in seconds\n") | |
2541 | { | |
a3d826f0 | 2542 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2543 | int idx_number = 3; |
2544 | unsigned int interval; | |
718e3744 | 2545 | |
d62a17ae | 2546 | if (argc == 1) { |
2547 | interval = strtoul(argv[idx_number]->arg, NULL, 10); | |
718e3744 | 2548 | |
d62a17ae | 2549 | if (ospf->lsa_refresh_interval != interval |
2550 | || interval == OSPF_LSA_REFRESH_INTERVAL_DEFAULT) | |
2551 | return CMD_SUCCESS; | |
2552 | } | |
2553 | ||
2554 | ospf_timers_refresh_unset(ospf); | |
2555 | ||
2556 | return CMD_SUCCESS; | |
718e3744 | 2557 | } |
2558 | ||
718e3744 | 2559 | |
a2c62831 | 2560 | DEFUN (ospf_auto_cost_reference_bandwidth, |
2561 | ospf_auto_cost_reference_bandwidth_cmd, | |
6147e2c6 | 2562 | "auto-cost reference-bandwidth (1-4294967)", |
718e3744 | 2563 | "Calculate OSPF interface cost according to bandwidth\n" |
2564 | "Use reference bandwidth method to assign OSPF cost\n" | |
2565 | "The reference bandwidth in terms of Mbits per second\n") | |
2566 | { | |
a3d826f0 | 2567 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
f4e14fdb | 2568 | struct vrf *vrf = vrf_lookup_by_id(ospf->vrf_id); |
d62a17ae | 2569 | int idx_number = 2; |
d7c0a89a | 2570 | uint32_t refbw; |
d62a17ae | 2571 | struct interface *ifp; |
2572 | ||
2573 | refbw = strtol(argv[idx_number]->arg, NULL, 10); | |
2574 | if (refbw < 1 || refbw > 4294967) { | |
2575 | vty_out(vty, "reference-bandwidth value is invalid\n"); | |
2576 | return CMD_WARNING_CONFIG_FAILED; | |
2577 | } | |
2578 | ||
2579 | /* If reference bandwidth is changed. */ | |
2580 | if ((refbw) == ospf->ref_bandwidth) | |
2581 | return CMD_SUCCESS; | |
2582 | ||
2583 | ospf->ref_bandwidth = refbw; | |
451fda4f | 2584 | FOR_ALL_INTERFACES (vrf, ifp) |
d62a17ae | 2585 | ospf_if_recalculate_output_cost(ifp); |
2586 | ||
2587 | return CMD_SUCCESS; | |
718e3744 | 2588 | } |
2589 | ||
a2c62831 | 2590 | DEFUN (no_ospf_auto_cost_reference_bandwidth, |
2591 | no_ospf_auto_cost_reference_bandwidth_cmd, | |
7a7be519 | 2592 | "no auto-cost reference-bandwidth [(1-4294967)]", |
718e3744 | 2593 | NO_STR |
2594 | "Calculate OSPF interface cost according to bandwidth\n" | |
7a7be519 | 2595 | "Use reference bandwidth method to assign OSPF cost\n" |
2596 | "The reference bandwidth in terms of Mbits per second\n") | |
718e3744 | 2597 | { |
a3d826f0 | 2598 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
f4e14fdb | 2599 | struct vrf *vrf = vrf_lookup_by_id(ospf->vrf_id); |
d62a17ae | 2600 | struct interface *ifp; |
718e3744 | 2601 | |
d62a17ae | 2602 | if (ospf->ref_bandwidth == OSPF_DEFAULT_REF_BANDWIDTH) |
2603 | return CMD_SUCCESS; | |
2604 | ||
2605 | ospf->ref_bandwidth = OSPF_DEFAULT_REF_BANDWIDTH; | |
2606 | vty_out(vty, "%% OSPF: Reference bandwidth is changed.\n"); | |
2607 | vty_out(vty, | |
2608 | " Please ensure reference bandwidth is consistent across all routers\n"); | |
2609 | ||
451fda4f | 2610 | FOR_ALL_INTERFACES (vrf, ifp) |
d62a17ae | 2611 | ospf_if_recalculate_output_cost(ifp); |
2612 | ||
2613 | return CMD_SUCCESS; | |
718e3744 | 2614 | } |
2615 | ||
2f8f370e DS |
2616 | DEFUN (ospf_write_multiplier, |
2617 | ospf_write_multiplier_cmd, | |
6147e2c6 | 2618 | "ospf write-multiplier (1-100)", |
e8f45e82 DS |
2619 | "OSPF specific commands\n" |
2620 | "Write multiplier\n" | |
2621 | "Maximum number of interface serviced per write\n") | |
2f8f370e | 2622 | { |
a3d826f0 | 2623 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2624 | int idx_number; |
d7c0a89a | 2625 | uint32_t write_oi_count; |
d62a17ae | 2626 | |
2627 | if (argc == 3) | |
2628 | idx_number = 2; | |
2629 | else | |
2630 | idx_number = 1; | |
2631 | ||
2632 | write_oi_count = strtol(argv[idx_number]->arg, NULL, 10); | |
2633 | if (write_oi_count < 1 || write_oi_count > 100) { | |
2634 | vty_out(vty, "write-multiplier value is invalid\n"); | |
2635 | return CMD_WARNING_CONFIG_FAILED; | |
2636 | } | |
2637 | ||
2638 | ospf->write_oi_count = write_oi_count; | |
2639 | return CMD_SUCCESS; | |
2f8f370e DS |
2640 | } |
2641 | ||
d62a17ae | 2642 | ALIAS(ospf_write_multiplier, write_multiplier_cmd, "write-multiplier (1-100)", |
2643 | "Write multiplier\n" | |
2644 | "Maximum number of interface serviced per write\n") | |
e8f45e82 | 2645 | |
2f8f370e DS |
2646 | DEFUN (no_ospf_write_multiplier, |
2647 | no_ospf_write_multiplier_cmd, | |
6147e2c6 | 2648 | "no ospf write-multiplier (1-100)", |
2f8f370e | 2649 | NO_STR |
e8f45e82 | 2650 | "OSPF specific commands\n" |
813d4307 DW |
2651 | "Write multiplier\n" |
2652 | "Maximum number of interface serviced per write\n") | |
2f8f370e | 2653 | { |
a3d826f0 | 2654 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
2f8f370e | 2655 | |
d62a17ae | 2656 | ospf->write_oi_count = OSPF_WRITE_INTERFACE_COUNT_DEFAULT; |
2657 | return CMD_SUCCESS; | |
2f8f370e DS |
2658 | } |
2659 | ||
d62a17ae | 2660 | ALIAS(no_ospf_write_multiplier, no_write_multiplier_cmd, |
9d303b37 | 2661 | "no write-multiplier (1-100)", NO_STR |
d62a17ae | 2662 | "Write multiplier\n" |
2663 | "Maximum number of interface serviced per write\n") | |
2664 | ||
385a1e07 | 2665 | DEFUN(ospf_ti_lfa, ospf_ti_lfa_cmd, "fast-reroute ti-lfa [node-protection]", |
7fd0729f | 2666 | "Fast Reroute for MPLS and IP resilience\n" |
385a1e07 G |
2667 | "Topology Independent LFA (Loop-Free Alternate)\n" |
2668 | "TI-LFA node protection (default is link protection)\n") | |
7fd0729f G |
2669 | { |
2670 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
2671 | ||
2672 | ospf->ti_lfa_enabled = true; | |
2673 | ||
385a1e07 G |
2674 | if (argc == 3) |
2675 | ospf->ti_lfa_protection_type = OSPF_TI_LFA_NODE_PROTECTION; | |
2676 | else | |
2677 | ospf->ti_lfa_protection_type = OSPF_TI_LFA_LINK_PROTECTION; | |
2678 | ||
7fd0729f G |
2679 | ospf_spf_calculate_schedule(ospf, SPF_FLAG_CONFIG_CHANGE); |
2680 | ||
2681 | return CMD_SUCCESS; | |
2682 | } | |
2683 | ||
385a1e07 G |
2684 | DEFUN(no_ospf_ti_lfa, no_ospf_ti_lfa_cmd, |
2685 | "no fast-reroute ti-lfa [node-protection]", | |
7fd0729f G |
2686 | NO_STR |
2687 | "Fast Reroute for MPLS and IP resilience\n" | |
385a1e07 G |
2688 | "Topology Independent LFA (Loop-Free Alternate)\n" |
2689 | "TI-LFA node protection (default is link protection)\n") | |
7fd0729f G |
2690 | { |
2691 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
2692 | ||
2693 | ospf->ti_lfa_enabled = false; | |
2694 | ||
385a1e07 G |
2695 | ospf->ti_lfa_protection_type = OSPF_TI_LFA_UNDEFINED_PROTECTION; |
2696 | ||
7fd0729f G |
2697 | ospf_spf_calculate_schedule(ospf, SPF_FLAG_CONFIG_CHANGE); |
2698 | ||
2699 | return CMD_SUCCESS; | |
2700 | } | |
2701 | ||
3d5b9855 | 2702 | static void ospf_maxpath_set(struct vty *vty, struct ospf *ospf, uint16_t paths) |
2703 | { | |
2704 | if (ospf->max_multipath == paths) | |
2705 | return; | |
2706 | ||
2707 | ospf->max_multipath = paths; | |
2708 | ||
2709 | /* Send deletion notification to zebra to delete all | |
2710 | * ospf specific routes and reinitiat SPF to reflect | |
2711 | * the new max multipath. | |
2712 | */ | |
2713 | ospf_restart_spf(ospf); | |
2714 | } | |
2715 | ||
2716 | /* Ospf Maximum multiple paths config support */ | |
2717 | DEFUN (ospf_max_multipath, | |
2718 | ospf_max_multipath_cmd, | |
2719 | "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM), | |
2720 | "Max no of multiple paths for ECMP support\n" | |
2721 | "Number of paths\n") | |
2722 | { | |
2723 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
2724 | int idx_number = 1; | |
2725 | uint16_t maxpaths; | |
2726 | ||
2727 | maxpaths = strtol(argv[idx_number]->arg, NULL, 10); | |
2728 | ||
2729 | ospf_maxpath_set(vty, ospf, maxpaths); | |
2730 | return CMD_SUCCESS; | |
2731 | } | |
2732 | ||
2733 | DEFUN (no_ospf_max_multipath, | |
2734 | no_ospf_max_multipath_cmd, | |
2735 | "no maximum-paths", | |
2736 | NO_STR | |
2737 | "Max no of multiple paths for ECMP support\n") | |
2738 | { | |
2739 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
2740 | uint16_t maxpaths = MULTIPATH_NUM; | |
2741 | ||
2742 | ospf_maxpath_set(vty, ospf, maxpaths); | |
2743 | return CMD_SUCCESS; | |
2744 | } | |
2745 | ||
2b64873d DL |
2746 | static const char *const ospf_abr_type_descr_str[] = { |
2747 | "Unknown", "Standard (RFC2328)", "Alternative IBM", | |
2748 | "Alternative Cisco", "Alternative Shortcut" | |
2749 | }; | |
d62a17ae | 2750 | |
2b64873d DL |
2751 | static const char *const ospf_shortcut_mode_descr_str[] = { |
2752 | "Default", "Enabled", "Disabled" | |
2753 | }; | |
d62a17ae | 2754 | |
2755 | static void show_ip_ospf_area(struct vty *vty, struct ospf_area *area, | |
9f049418 | 2756 | json_object *json_areas, bool use_json) |
d62a17ae | 2757 | { |
2758 | json_object *json_area = NULL; | |
96b663a3 | 2759 | char buf[PREFIX_STRLEN]; |
d62a17ae | 2760 | |
2761 | if (use_json) | |
2762 | json_area = json_object_new_object(); | |
2763 | ||
2764 | /* Show Area ID. */ | |
2765 | if (!use_json) | |
96b663a3 | 2766 | vty_out(vty, " Area ID: %pI4", &area->area_id); |
d62a17ae | 2767 | |
2768 | /* Show Area type/mode. */ | |
2769 | if (OSPF_IS_AREA_BACKBONE(area)) { | |
2770 | if (use_json) | |
2771 | json_object_boolean_true_add(json_area, "backbone"); | |
2772 | else | |
2773 | vty_out(vty, " (Backbone)\n"); | |
2774 | } else { | |
2775 | if (use_json) { | |
2776 | if (area->external_routing == OSPF_AREA_STUB) { | |
2777 | if (area->no_summary) | |
2778 | json_object_boolean_true_add( | |
2779 | json_area, "stubNoSummary"); | |
2780 | if (area->shortcut_configured) | |
2781 | json_object_boolean_true_add( | |
2782 | json_area, "stubShortcut"); | |
2783 | } else if (area->external_routing == OSPF_AREA_NSSA) { | |
2784 | if (area->no_summary) | |
2785 | json_object_boolean_true_add( | |
2786 | json_area, "nssaNoSummary"); | |
2787 | if (area->shortcut_configured) | |
2788 | json_object_boolean_true_add( | |
2789 | json_area, "nssaShortcut"); | |
2790 | } | |
813d4307 | 2791 | |
d62a17ae | 2792 | json_object_string_add( |
2793 | json_area, "shortcuttingMode", | |
2794 | ospf_shortcut_mode_descr_str | |
2795 | [area->shortcut_configured]); | |
2796 | if (area->shortcut_capability) | |
2797 | json_object_boolean_true_add(json_area, | |
2798 | "sBitConcensus"); | |
2799 | } else { | |
2800 | if (area->external_routing == OSPF_AREA_STUB) | |
2801 | vty_out(vty, " (Stub%s%s)", | |
2802 | area->no_summary ? ", no summary" : "", | |
2803 | area->shortcut_configured ? "; " : ""); | |
2804 | else if (area->external_routing == OSPF_AREA_NSSA) | |
2805 | vty_out(vty, " (NSSA%s%s)", | |
2806 | area->no_summary ? ", no summary" : "", | |
2807 | area->shortcut_configured ? "; " : ""); | |
2808 | ||
2809 | vty_out(vty, "\n"); | |
2810 | vty_out(vty, " Shortcutting mode: %s", | |
2811 | ospf_shortcut_mode_descr_str | |
2812 | [area->shortcut_configured]); | |
2813 | vty_out(vty, ", S-bit consensus: %s\n", | |
2814 | area->shortcut_capability ? "ok" : "no"); | |
2815 | } | |
2816 | } | |
718e3744 | 2817 | |
d62a17ae | 2818 | /* Show number of interfaces */ |
2819 | if (use_json) { | |
2820 | json_object_int_add(json_area, "areaIfTotalCounter", | |
2821 | listcount(area->oiflist)); | |
2822 | json_object_int_add(json_area, "areaIfActiveCounter", | |
2823 | area->act_ints); | |
2824 | } else | |
2825 | vty_out(vty, | |
3efd0893 | 2826 | " Number of interfaces in this area: Total: %d, Active: %d\n", |
d62a17ae | 2827 | listcount(area->oiflist), area->act_ints); |
2828 | ||
2829 | if (area->external_routing == OSPF_AREA_NSSA) { | |
2830 | if (use_json) { | |
2831 | json_object_boolean_true_add(json_area, "nssa"); | |
2832 | if (!IS_OSPF_ABR(area->ospf)) | |
2833 | json_object_boolean_false_add(json_area, "abr"); | |
2834 | else if (area->NSSATranslatorState) { | |
2835 | json_object_boolean_true_add(json_area, "abr"); | |
2836 | if (area->NSSATranslatorRole | |
2837 | == OSPF_NSSA_ROLE_CANDIDATE) | |
2838 | json_object_boolean_true_add( | |
2839 | json_area, | |
2840 | "nssaTranslatorElected"); | |
2841 | else if (area->NSSATranslatorRole | |
2842 | == OSPF_NSSA_ROLE_ALWAYS) | |
2843 | json_object_boolean_true_add( | |
2844 | json_area, | |
2845 | "nssaTranslatorAlways"); | |
b79c3070 | 2846 | else |
2847 | json_object_boolean_true_add( | |
2848 | json_area, | |
2849 | "nssaTranslatorNever"); | |
d62a17ae | 2850 | } else { |
2851 | json_object_boolean_true_add(json_area, "abr"); | |
2852 | if (area->NSSATranslatorRole | |
2853 | == OSPF_NSSA_ROLE_CANDIDATE) | |
2854 | json_object_boolean_false_add( | |
2855 | json_area, | |
2856 | "nssaTranslatorElected"); | |
2857 | else | |
2858 | json_object_boolean_true_add( | |
2859 | json_area, | |
2860 | "nssaTranslatorNever"); | |
2861 | } | |
2862 | } else { | |
2863 | vty_out(vty, | |
b79c3070 | 2864 | " It is an NSSA configuration.\n Elected NSSA/ABR performs type-7/type-5 LSA translation.\n"); |
d62a17ae | 2865 | if (!IS_OSPF_ABR(area->ospf)) |
2866 | vty_out(vty, | |
b79c3070 | 2867 | " It is not ABR, therefore not Translator.\n"); |
d62a17ae | 2868 | else if (area->NSSATranslatorState) { |
2869 | vty_out(vty, " We are an ABR and "); | |
2870 | if (area->NSSATranslatorRole | |
2871 | == OSPF_NSSA_ROLE_CANDIDATE) | |
2872 | vty_out(vty, | |
b79c3070 | 2873 | "the NSSA Elected Translator.\n"); |
d62a17ae | 2874 | else if (area->NSSATranslatorRole |
2875 | == OSPF_NSSA_ROLE_ALWAYS) | |
2876 | vty_out(vty, | |
b79c3070 | 2877 | "always an NSSA Translator.\n"); |
2878 | else | |
2879 | vty_out(vty, | |
2880 | "never an NSSA Translator.\n"); | |
d62a17ae | 2881 | } else { |
2882 | vty_out(vty, " We are an ABR, but "); | |
2883 | if (area->NSSATranslatorRole | |
2884 | == OSPF_NSSA_ROLE_CANDIDATE) | |
2885 | vty_out(vty, | |
b79c3070 | 2886 | "not the NSSA Elected Translator.\n"); |
d62a17ae | 2887 | else |
2888 | vty_out(vty, | |
b79c3070 | 2889 | "never an NSSA Translator.\n"); |
d62a17ae | 2890 | } |
2891 | } | |
2892 | } | |
2893 | ||
2894 | /* Stub-router state for this area */ | |
2895 | if (CHECK_FLAG(area->stub_router_state, OSPF_AREA_IS_STUB_ROUTED)) { | |
2896 | char timebuf[OSPF_TIME_DUMP_SIZE]; | |
2897 | ||
2898 | if (use_json) { | |
2899 | json_object_boolean_true_add( | |
2900 | json_area, "originStubMaxDistRouterLsa"); | |
2901 | if (CHECK_FLAG(area->stub_router_state, | |
2902 | OSPF_AREA_ADMIN_STUB_ROUTED)) | |
2903 | json_object_boolean_true_add( | |
2904 | json_area, "indefiniteActiveAdmin"); | |
2905 | if (area->t_stub_router) { | |
2906 | long time_store; | |
2907 | time_store = | |
2908 | monotime_until( | |
2909 | &area->t_stub_router->u.sands, | |
2910 | NULL) | |
2911 | / 1000LL; | |
2912 | json_object_int_add( | |
2913 | json_area, | |
2914 | "activeStartupRemainderMsecs", | |
2915 | time_store); | |
2916 | } | |
2917 | } else { | |
2918 | vty_out(vty, | |
2919 | " Originating stub / maximum-distance Router-LSA\n"); | |
2920 | if (CHECK_FLAG(area->stub_router_state, | |
2921 | OSPF_AREA_ADMIN_STUB_ROUTED)) | |
2922 | vty_out(vty, | |
2923 | " Administratively activated (indefinitely)\n"); | |
2924 | if (area->t_stub_router) | |
2925 | vty_out(vty, | |
2926 | " Active from startup, %s remaining\n", | |
2927 | ospf_timer_dump(area->t_stub_router, | |
2928 | timebuf, | |
2929 | sizeof(timebuf))); | |
2930 | } | |
2931 | } | |
2932 | ||
2933 | if (use_json) { | |
2934 | /* Show number of fully adjacent neighbors. */ | |
2935 | json_object_int_add(json_area, "nbrFullAdjacentCounter", | |
2936 | area->full_nbrs); | |
2937 | ||
2938 | /* Show authentication type. */ | |
2939 | if (area->auth_type == OSPF_AUTH_NULL) | |
2940 | json_object_string_add(json_area, "authentication", | |
2941 | "authenticationNone"); | |
2942 | else if (area->auth_type == OSPF_AUTH_SIMPLE) | |
2943 | json_object_string_add(json_area, "authentication", | |
2944 | "authenticationSimplePassword"); | |
2945 | else if (area->auth_type == OSPF_AUTH_CRYPTOGRAPHIC) | |
2946 | json_object_string_add(json_area, "authentication", | |
2947 | "authenticationMessageDigest"); | |
2948 | ||
2949 | if (!OSPF_IS_AREA_BACKBONE(area)) | |
2950 | json_object_int_add(json_area, | |
2951 | "virtualAdjacenciesPassingCounter", | |
2952 | area->full_vls); | |
2953 | ||
2954 | /* Show SPF calculation times. */ | |
2955 | json_object_int_add(json_area, "spfExecutedCounter", | |
2956 | area->spf_calculation); | |
2957 | json_object_int_add(json_area, "lsaNumber", area->lsdb->total); | |
2958 | json_object_int_add( | |
2959 | json_area, "lsaRouterNumber", | |
2960 | ospf_lsdb_count(area->lsdb, OSPF_ROUTER_LSA)); | |
2961 | json_object_int_add( | |
2962 | json_area, "lsaRouterChecksum", | |
2963 | ospf_lsdb_checksum(area->lsdb, OSPF_ROUTER_LSA)); | |
2964 | json_object_int_add( | |
2965 | json_area, "lsaNetworkNumber", | |
2966 | ospf_lsdb_count(area->lsdb, OSPF_NETWORK_LSA)); | |
2967 | json_object_int_add( | |
2968 | json_area, "lsaNetworkChecksum", | |
2969 | ospf_lsdb_checksum(area->lsdb, OSPF_NETWORK_LSA)); | |
2970 | json_object_int_add( | |
2971 | json_area, "lsaSummaryNumber", | |
2972 | ospf_lsdb_count(area->lsdb, OSPF_SUMMARY_LSA)); | |
2973 | json_object_int_add( | |
2974 | json_area, "lsaSummaryChecksum", | |
2975 | ospf_lsdb_checksum(area->lsdb, OSPF_SUMMARY_LSA)); | |
2976 | json_object_int_add( | |
2977 | json_area, "lsaAsbrNumber", | |
2978 | ospf_lsdb_count(area->lsdb, OSPF_ASBR_SUMMARY_LSA)); | |
2979 | json_object_int_add( | |
2980 | json_area, "lsaAsbrChecksum", | |
2981 | ospf_lsdb_checksum(area->lsdb, OSPF_ASBR_SUMMARY_LSA)); | |
2982 | json_object_int_add( | |
2983 | json_area, "lsaNssaNumber", | |
2984 | ospf_lsdb_count(area->lsdb, OSPF_AS_NSSA_LSA)); | |
2985 | json_object_int_add( | |
2986 | json_area, "lsaNssaChecksum", | |
2987 | ospf_lsdb_checksum(area->lsdb, OSPF_AS_NSSA_LSA)); | |
2988 | } else { | |
2989 | /* Show number of fully adjacent neighbors. */ | |
2990 | vty_out(vty, | |
3efd0893 | 2991 | " Number of fully adjacent neighbors in this area: %d\n", |
d62a17ae | 2992 | area->full_nbrs); |
2993 | ||
2994 | /* Show authentication type. */ | |
2995 | vty_out(vty, " Area has "); | |
2996 | if (area->auth_type == OSPF_AUTH_NULL) | |
2997 | vty_out(vty, "no authentication\n"); | |
2998 | else if (area->auth_type == OSPF_AUTH_SIMPLE) | |
2999 | vty_out(vty, "simple password authentication\n"); | |
3000 | else if (area->auth_type == OSPF_AUTH_CRYPTOGRAPHIC) | |
3001 | vty_out(vty, "message digest authentication\n"); | |
3002 | ||
3003 | if (!OSPF_IS_AREA_BACKBONE(area)) | |
3004 | vty_out(vty, | |
3efd0893 | 3005 | " Number of full virtual adjacencies going through this area: %d\n", |
d62a17ae | 3006 | area->full_vls); |
3007 | ||
3008 | /* Show SPF calculation times. */ | |
3009 | vty_out(vty, " SPF algorithm executed %d times\n", | |
3010 | area->spf_calculation); | |
3011 | ||
3012 | /* Show number of LSA. */ | |
3013 | vty_out(vty, " Number of LSA %ld\n", area->lsdb->total); | |
3014 | vty_out(vty, | |
3015 | " Number of router LSA %ld. Checksum Sum 0x%08x\n", | |
3016 | ospf_lsdb_count(area->lsdb, OSPF_ROUTER_LSA), | |
3017 | ospf_lsdb_checksum(area->lsdb, OSPF_ROUTER_LSA)); | |
3018 | vty_out(vty, | |
3019 | " Number of network LSA %ld. Checksum Sum 0x%08x\n", | |
3020 | ospf_lsdb_count(area->lsdb, OSPF_NETWORK_LSA), | |
3021 | ospf_lsdb_checksum(area->lsdb, OSPF_NETWORK_LSA)); | |
3022 | vty_out(vty, | |
3023 | " Number of summary LSA %ld. Checksum Sum 0x%08x\n", | |
3024 | ospf_lsdb_count(area->lsdb, OSPF_SUMMARY_LSA), | |
3025 | ospf_lsdb_checksum(area->lsdb, OSPF_SUMMARY_LSA)); | |
3026 | vty_out(vty, | |
3027 | " Number of ASBR summary LSA %ld. Checksum Sum 0x%08x\n", | |
3028 | ospf_lsdb_count(area->lsdb, OSPF_ASBR_SUMMARY_LSA), | |
3029 | ospf_lsdb_checksum(area->lsdb, OSPF_ASBR_SUMMARY_LSA)); | |
3030 | vty_out(vty, " Number of NSSA LSA %ld. Checksum Sum 0x%08x\n", | |
3031 | ospf_lsdb_count(area->lsdb, OSPF_AS_NSSA_LSA), | |
3032 | ospf_lsdb_checksum(area->lsdb, OSPF_AS_NSSA_LSA)); | |
3033 | } | |
3034 | ||
3035 | if (use_json) { | |
3036 | json_object_int_add( | |
3037 | json_area, "lsaOpaqueLinkNumber", | |
3038 | ospf_lsdb_count(area->lsdb, OSPF_OPAQUE_LINK_LSA)); | |
3039 | json_object_int_add( | |
3040 | json_area, "lsaOpaqueLinkChecksum", | |
3041 | ospf_lsdb_checksum(area->lsdb, OSPF_OPAQUE_LINK_LSA)); | |
3042 | json_object_int_add( | |
3043 | json_area, "lsaOpaqueAreaNumber", | |
3044 | ospf_lsdb_count(area->lsdb, OSPF_OPAQUE_AREA_LSA)); | |
3045 | json_object_int_add( | |
3046 | json_area, "lsaOpaqueAreaChecksum", | |
3047 | ospf_lsdb_checksum(area->lsdb, OSPF_OPAQUE_AREA_LSA)); | |
3048 | } else { | |
3049 | vty_out(vty, | |
3050 | " Number of opaque link LSA %ld. Checksum Sum 0x%08x\n", | |
3051 | ospf_lsdb_count(area->lsdb, OSPF_OPAQUE_LINK_LSA), | |
3052 | ospf_lsdb_checksum(area->lsdb, OSPF_OPAQUE_LINK_LSA)); | |
3053 | vty_out(vty, | |
3054 | " Number of opaque area LSA %ld. Checksum Sum 0x%08x\n", | |
3055 | ospf_lsdb_count(area->lsdb, OSPF_OPAQUE_AREA_LSA), | |
3056 | ospf_lsdb_checksum(area->lsdb, OSPF_OPAQUE_AREA_LSA)); | |
3057 | } | |
718e3744 | 3058 | |
d62a17ae | 3059 | if (use_json) |
96b663a3 MS |
3060 | json_object_object_add(json_areas, |
3061 | inet_ntop(AF_INET, &area->area_id, | |
3062 | buf, sizeof(buf)), | |
d62a17ae | 3063 | json_area); |
3064 | else | |
3065 | vty_out(vty, "\n"); | |
718e3744 | 3066 | } |
3067 | ||
d62a17ae | 3068 | static int show_ip_ospf_common(struct vty *vty, struct ospf *ospf, |
d7c0a89a | 3069 | json_object *json, uint8_t use_vrf) |
d62a17ae | 3070 | { |
3071 | struct listnode *node, *nnode; | |
3072 | struct ospf_area *area; | |
3073 | struct timeval result; | |
3074 | char timebuf[OSPF_TIME_DUMP_SIZE]; | |
96b663a3 | 3075 | char buf[PREFIX_STRLEN]; |
b1c3ae8c | 3076 | json_object *json_vrf = NULL; |
d62a17ae | 3077 | json_object *json_areas = NULL; |
718e3744 | 3078 | |
b1c3ae8c CS |
3079 | if (json) { |
3080 | if (use_vrf) | |
3081 | json_vrf = json_object_new_object(); | |
3082 | else | |
3083 | json_vrf = json; | |
d62a17ae | 3084 | json_areas = json_object_new_object(); |
3085 | } | |
3086 | ||
3087 | if (ospf->instance) { | |
b1c3ae8c | 3088 | if (json) { |
d62a17ae | 3089 | json_object_int_add(json, "ospfInstance", |
3090 | ospf->instance); | |
3091 | } else { | |
3092 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
3093 | } | |
3094 | } | |
3095 | ||
b1c3ae8c | 3096 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); |
87bd50e8 | 3097 | |
d62a17ae | 3098 | /* Show Router ID. */ |
b1c3ae8c CS |
3099 | if (json) { |
3100 | json_object_string_add(json_vrf, "routerId", | |
96b663a3 MS |
3101 | inet_ntop(AF_INET, &ospf->router_id, |
3102 | buf, sizeof(buf))); | |
d62a17ae | 3103 | } else { |
96b663a3 MS |
3104 | vty_out(vty, " OSPF Routing Process, Router ID: %pI4\n", |
3105 | &ospf->router_id); | |
d62a17ae | 3106 | } |
3107 | ||
3108 | /* Graceful shutdown */ | |
3109 | if (ospf->t_deferred_shutdown) { | |
b1c3ae8c | 3110 | if (json) { |
d62a17ae | 3111 | long time_store; |
3112 | time_store = | |
3113 | monotime_until( | |
3114 | &ospf->t_deferred_shutdown->u.sands, | |
3115 | NULL) | |
3116 | / 1000LL; | |
b1c3ae8c | 3117 | json_object_int_add(json_vrf, "deferredShutdownMsecs", |
d62a17ae | 3118 | time_store); |
3119 | } else { | |
3120 | vty_out(vty, | |
3121 | " Deferred shutdown in progress, %s remaining\n", | |
3122 | ospf_timer_dump(ospf->t_deferred_shutdown, | |
3123 | timebuf, sizeof(timebuf))); | |
3124 | } | |
3125 | } | |
3126 | ||
3127 | /* Show capability. */ | |
b1c3ae8c CS |
3128 | if (json) { |
3129 | json_object_boolean_true_add(json_vrf, "tosRoutesOnly"); | |
3130 | json_object_boolean_true_add(json_vrf, "rfc2328Conform"); | |
d62a17ae | 3131 | if (CHECK_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE)) { |
b1c3ae8c | 3132 | json_object_boolean_true_add(json_vrf, |
d62a17ae | 3133 | "rfc1583Compatibility"); |
3134 | } | |
3135 | } else { | |
3136 | vty_out(vty, " Supports only single TOS (TOS0) routes\n"); | |
3137 | vty_out(vty, " This implementation conforms to RFC2328\n"); | |
3138 | vty_out(vty, " RFC1583Compatibility flag is %s\n", | |
3139 | CHECK_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE) | |
3140 | ? "enabled" | |
3141 | : "disabled"); | |
3142 | } | |
3143 | ||
b1c3ae8c | 3144 | if (json) { |
d62a17ae | 3145 | if (CHECK_FLAG(ospf->config, OSPF_OPAQUE_CAPABLE)) { |
b1c3ae8c | 3146 | json_object_boolean_true_add(json_vrf, "opaqueCapable"); |
d62a17ae | 3147 | } |
3148 | } else { | |
3149 | vty_out(vty, " OpaqueCapability flag is %s\n", | |
3150 | CHECK_FLAG(ospf->config, OSPF_OPAQUE_CAPABLE) | |
3151 | ? "enabled" | |
3152 | : "disabled"); | |
3153 | } | |
3154 | ||
3155 | /* Show stub-router configuration */ | |
3156 | if (ospf->stub_router_startup_time != OSPF_STUB_ROUTER_UNCONFIGURED | |
3157 | || ospf->stub_router_shutdown_time | |
3158 | != OSPF_STUB_ROUTER_UNCONFIGURED) { | |
b1c3ae8c CS |
3159 | if (json) { |
3160 | json_object_boolean_true_add(json_vrf, | |
3161 | "stubAdvertisement"); | |
d62a17ae | 3162 | if (ospf->stub_router_startup_time |
3163 | != OSPF_STUB_ROUTER_UNCONFIGURED) | |
3164 | json_object_int_add( | |
50ad4b42 MS |
3165 | json_vrf, "postStartEnabledSecs", |
3166 | ospf->stub_router_startup_time); | |
d62a17ae | 3167 | if (ospf->stub_router_shutdown_time |
3168 | != OSPF_STUB_ROUTER_UNCONFIGURED) | |
3169 | json_object_int_add( | |
50ad4b42 MS |
3170 | json_vrf, "preShutdownEnabledSecs", |
3171 | ospf->stub_router_shutdown_time); | |
d62a17ae | 3172 | } else { |
3173 | vty_out(vty, | |
3174 | " Stub router advertisement is configured\n"); | |
3175 | if (ospf->stub_router_startup_time | |
3176 | != OSPF_STUB_ROUTER_UNCONFIGURED) | |
3177 | vty_out(vty, | |
3178 | " Enabled for %us after start-up\n", | |
3179 | ospf->stub_router_startup_time); | |
3180 | if (ospf->stub_router_shutdown_time | |
3181 | != OSPF_STUB_ROUTER_UNCONFIGURED) | |
3182 | vty_out(vty, | |
3183 | " Enabled for %us prior to full shutdown\n", | |
3184 | ospf->stub_router_shutdown_time); | |
3185 | } | |
3186 | } | |
3187 | ||
3188 | /* Show SPF timers. */ | |
b1c3ae8c CS |
3189 | if (json) { |
3190 | json_object_int_add(json_vrf, "spfScheduleDelayMsecs", | |
d62a17ae | 3191 | ospf->spf_delay); |
b1c3ae8c | 3192 | json_object_int_add(json_vrf, "holdtimeMinMsecs", |
d62a17ae | 3193 | ospf->spf_holdtime); |
b1c3ae8c | 3194 | json_object_int_add(json_vrf, "holdtimeMaxMsecs", |
d62a17ae | 3195 | ospf->spf_max_holdtime); |
b1c3ae8c | 3196 | json_object_int_add(json_vrf, "holdtimeMultplier", |
d62a17ae | 3197 | ospf->spf_hold_multiplier); |
3198 | } else { | |
3199 | vty_out(vty, | |
3200 | " Initial SPF scheduling delay %d millisec(s)\n" | |
3201 | " Minimum hold time between consecutive SPFs %d millisec(s)\n" | |
3202 | " Maximum hold time between consecutive SPFs %d millisec(s)\n" | |
3203 | " Hold time multiplier is currently %d\n", | |
3204 | ospf->spf_delay, ospf->spf_holdtime, | |
3205 | ospf->spf_max_holdtime, ospf->spf_hold_multiplier); | |
3206 | } | |
3207 | ||
b1c3ae8c | 3208 | if (json) { |
d62a17ae | 3209 | if (ospf->ts_spf.tv_sec || ospf->ts_spf.tv_usec) { |
3210 | long time_store = 0; | |
3211 | ||
3212 | time_store = | |
3213 | monotime_since(&ospf->ts_spf, NULL) / 1000LL; | |
b1c3ae8c | 3214 | json_object_int_add(json_vrf, "spfLastExecutedMsecs", |
d62a17ae | 3215 | time_store); |
3216 | ||
3217 | time_store = (1000 * ospf->ts_spf_duration.tv_sec) | |
3218 | + (ospf->ts_spf_duration.tv_usec / 1000); | |
b1c3ae8c | 3219 | json_object_int_add(json_vrf, "spfLastDurationMsecs", |
d62a17ae | 3220 | time_store); |
3221 | } else | |
b1c3ae8c | 3222 | json_object_boolean_true_add(json_vrf, "spfHasNotRun"); |
d62a17ae | 3223 | } else { |
3224 | vty_out(vty, " SPF algorithm "); | |
3225 | if (ospf->ts_spf.tv_sec || ospf->ts_spf.tv_usec) { | |
3226 | monotime_since(&ospf->ts_spf, &result); | |
3227 | vty_out(vty, "last executed %s ago\n", | |
3228 | ospf_timeval_dump(&result, timebuf, | |
3229 | sizeof(timebuf))); | |
3230 | vty_out(vty, " Last SPF duration %s\n", | |
3231 | ospf_timeval_dump(&ospf->ts_spf_duration, | |
3232 | timebuf, sizeof(timebuf))); | |
3233 | } else | |
3234 | vty_out(vty, "has not been run\n"); | |
3235 | } | |
3236 | ||
b1c3ae8c | 3237 | if (json) { |
d62a17ae | 3238 | if (ospf->t_spf_calc) { |
3239 | long time_store; | |
3240 | time_store = | |
3241 | monotime_until(&ospf->t_spf_calc->u.sands, NULL) | |
3242 | / 1000LL; | |
b1c3ae8c | 3243 | json_object_int_add(json_vrf, "spfTimerDueInMsecs", |
d62a17ae | 3244 | time_store); |
3245 | } | |
3246 | ||
b1c3ae8c | 3247 | json_object_int_add(json_vrf, "lsaMinIntervalMsecs", |
d62a17ae | 3248 | ospf->min_ls_interval); |
b1c3ae8c | 3249 | json_object_int_add(json_vrf, "lsaMinArrivalMsecs", |
d62a17ae | 3250 | ospf->min_ls_arrival); |
3251 | /* Show write multiplier values */ | |
b1c3ae8c | 3252 | json_object_int_add(json_vrf, "writeMultiplier", |
d62a17ae | 3253 | ospf->write_oi_count); |
3254 | /* Show refresh parameters. */ | |
b1c3ae8c | 3255 | json_object_int_add(json_vrf, "refreshTimerMsecs", |
d62a17ae | 3256 | ospf->lsa_refresh_interval * 1000); |
3257 | } else { | |
3258 | vty_out(vty, " SPF timer %s%s\n", | |
3259 | (ospf->t_spf_calc ? "due in " : "is "), | |
3260 | ospf_timer_dump(ospf->t_spf_calc, timebuf, | |
3261 | sizeof(timebuf))); | |
3262 | ||
3263 | vty_out(vty, " LSA minimum interval %d msecs\n", | |
3264 | ospf->min_ls_interval); | |
3265 | vty_out(vty, " LSA minimum arrival %d msecs\n", | |
3266 | ospf->min_ls_arrival); | |
3267 | ||
3268 | /* Show write multiplier values */ | |
3269 | vty_out(vty, " Write Multiplier set to %d \n", | |
3270 | ospf->write_oi_count); | |
3271 | ||
3272 | /* Show refresh parameters. */ | |
3273 | vty_out(vty, " Refresh timer %d secs\n", | |
3274 | ospf->lsa_refresh_interval); | |
3d5b9855 | 3275 | |
3276 | /* show max multipath */ | |
3277 | vty_out(vty, " Maximum multiple paths(ECMP) supported %d\n", | |
3278 | ospf->max_multipath); | |
d62a17ae | 3279 | } |
3280 | ||
3281 | /* Show ABR/ASBR flags. */ | |
3282 | if (CHECK_FLAG(ospf->flags, OSPF_FLAG_ABR)) { | |
b1c3ae8c | 3283 | if (json) |
d62a17ae | 3284 | json_object_string_add( |
b1c3ae8c | 3285 | json_vrf, "abrType", |
d62a17ae | 3286 | ospf_abr_type_descr_str[ospf->abr_type]); |
3287 | else | |
3288 | vty_out(vty, | |
3289 | " This router is an ABR, ABR type is: %s\n", | |
3290 | ospf_abr_type_descr_str[ospf->abr_type]); | |
3291 | } | |
3292 | if (CHECK_FLAG(ospf->flags, OSPF_FLAG_ASBR)) { | |
b1c3ae8c | 3293 | if (json) |
d62a17ae | 3294 | json_object_string_add( |
b1c3ae8c | 3295 | json_vrf, "asbrRouter", |
d62a17ae | 3296 | "injectingExternalRoutingInformation"); |
3297 | else | |
3298 | vty_out(vty, | |
3efd0893 | 3299 | " This router is an ASBR (injecting external routing information)\n"); |
d62a17ae | 3300 | } |
3301 | ||
3302 | /* Show Number of AS-external-LSAs. */ | |
b1c3ae8c | 3303 | if (json) { |
d62a17ae | 3304 | json_object_int_add( |
b1c3ae8c | 3305 | json_vrf, "lsaExternalCounter", |
d62a17ae | 3306 | ospf_lsdb_count(ospf->lsdb, OSPF_AS_EXTERNAL_LSA)); |
3307 | json_object_int_add( | |
b1c3ae8c | 3308 | json_vrf, "lsaExternalChecksum", |
d62a17ae | 3309 | ospf_lsdb_checksum(ospf->lsdb, OSPF_AS_EXTERNAL_LSA)); |
3310 | } else { | |
3311 | vty_out(vty, | |
3312 | " Number of external LSA %ld. Checksum Sum 0x%08x\n", | |
3313 | ospf_lsdb_count(ospf->lsdb, OSPF_AS_EXTERNAL_LSA), | |
3314 | ospf_lsdb_checksum(ospf->lsdb, OSPF_AS_EXTERNAL_LSA)); | |
3315 | } | |
3316 | ||
b1c3ae8c | 3317 | if (json) { |
d62a17ae | 3318 | json_object_int_add( |
b1c3ae8c | 3319 | json_vrf, "lsaAsopaqueCounter", |
d62a17ae | 3320 | ospf_lsdb_count(ospf->lsdb, OSPF_OPAQUE_AS_LSA)); |
3321 | json_object_int_add( | |
b1c3ae8c | 3322 | json_vrf, "lsaAsOpaqueChecksum", |
d62a17ae | 3323 | ospf_lsdb_checksum(ospf->lsdb, OSPF_OPAQUE_AS_LSA)); |
3324 | } else { | |
3325 | vty_out(vty, | |
3326 | " Number of opaque AS LSA %ld. Checksum Sum 0x%08x\n", | |
3327 | ospf_lsdb_count(ospf->lsdb, OSPF_OPAQUE_AS_LSA), | |
3328 | ospf_lsdb_checksum(ospf->lsdb, OSPF_OPAQUE_AS_LSA)); | |
3329 | } | |
3330 | ||
3331 | /* Show number of areas attached. */ | |
b1c3ae8c CS |
3332 | if (json) |
3333 | json_object_int_add(json_vrf, "attachedAreaCounter", | |
d62a17ae | 3334 | listcount(ospf->areas)); |
3335 | else | |
3336 | vty_out(vty, " Number of areas attached to this router: %d\n", | |
3337 | listcount(ospf->areas)); | |
3338 | ||
3339 | if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES)) { | |
3340 | if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL)) { | |
b1c3ae8c | 3341 | if (json) |
d62a17ae | 3342 | json_object_boolean_true_add( |
b1c3ae8c | 3343 | json_vrf, "adjacencyChangesLoggedAll"); |
d62a17ae | 3344 | else |
3345 | vty_out(vty, | |
3346 | " All adjacency changes are logged\n"); | |
3347 | } else { | |
b1c3ae8c | 3348 | if (json) |
d62a17ae | 3349 | json_object_boolean_true_add( |
b1c3ae8c | 3350 | json_vrf, "adjacencyChangesLogged"); |
d62a17ae | 3351 | else |
3352 | vty_out(vty, " Adjacency changes are logged\n"); | |
3353 | } | |
3354 | } | |
132a782e | 3355 | |
3356 | /* show LDP-Sync status */ | |
3357 | ospf_ldp_sync_show_info(vty, ospf, json_vrf, json ? 1 : 0); | |
3358 | ||
d62a17ae | 3359 | /* Show each area status. */ |
3360 | for (ALL_LIST_ELEMENTS(ospf->areas, node, nnode, area)) | |
b1c3ae8c CS |
3361 | show_ip_ospf_area(vty, area, json_areas, json ? 1 : 0); |
3362 | ||
3363 | if (json) { | |
3364 | if (use_vrf) { | |
3365 | json_object_object_add(json_vrf, "areas", json_areas); | |
3366 | if (ospf->vrf_id == VRF_DEFAULT) | |
3367 | json_object_object_add(json, "default", | |
3368 | json_vrf); | |
3369 | else | |
3370 | json_object_object_add(json, ospf->name, | |
3371 | json_vrf); | |
3372 | } else { | |
3373 | json_object_object_add(json, "areas", json_areas); | |
3374 | } | |
d62a17ae | 3375 | } else |
3376 | vty_out(vty, "\n"); | |
3377 | ||
3378 | return CMD_SUCCESS; | |
718e3744 | 3379 | } |
3380 | ||
7c8ff89e DS |
3381 | DEFUN (show_ip_ospf, |
3382 | show_ip_ospf_cmd, | |
b5a8894d | 3383 | "show ip ospf [vrf <NAME|all>] [json]", |
7c8ff89e DS |
3384 | SHOW_STR |
3385 | IP_STR | |
ca08c43d | 3386 | "OSPF information\n" |
b5a8894d CS |
3387 | VRF_CMD_HELP_STR |
3388 | "All VRFs\n" | |
9973d184 | 3389 | JSON_STR) |
7c8ff89e | 3390 | { |
d62a17ae | 3391 | struct ospf *ospf; |
9f049418 | 3392 | bool uj = use_json(argc, argv); |
b5a8894d CS |
3393 | struct listnode *node = NULL; |
3394 | char *vrf_name = NULL; | |
2951a7a4 | 3395 | bool all_vrf = false; |
b5a8894d CS |
3396 | int ret = CMD_SUCCESS; |
3397 | int inst = 0; | |
3398 | int idx_vrf = 0; | |
b1c3ae8c | 3399 | json_object *json = NULL; |
d7c0a89a | 3400 | uint8_t use_vrf = 0; |
7c8ff89e | 3401 | |
b5a8894d | 3402 | if (listcount(om->ospf) == 0) |
d62a17ae | 3403 | return CMD_SUCCESS; |
7c8ff89e | 3404 | |
43b8d1d8 | 3405 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
b5a8894d | 3406 | |
b1c3ae8c CS |
3407 | if (uj) |
3408 | json = json_object_new_object(); | |
3409 | ||
996c9314 | 3410 | /* vrf input is provided could be all or specific vrf*/ |
b5a8894d | 3411 | if (vrf_name) { |
2951a7a4 | 3412 | bool ospf_output = false; |
874f58d8 | 3413 | |
b1c3ae8c | 3414 | use_vrf = 1; |
94d4c685 | 3415 | |
b5a8894d CS |
3416 | if (all_vrf) { |
3417 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
3418 | if (!ospf->oi_running) | |
3419 | continue; | |
2951a7a4 | 3420 | ospf_output = true; |
b1c3ae8c CS |
3421 | ret = show_ip_ospf_common(vty, ospf, json, |
3422 | use_vrf); | |
3423 | } | |
3424 | if (uj) { | |
3425 | vty_out(vty, "%s\n", | |
996c9314 LB |
3426 | json_object_to_json_string_ext( |
3427 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 3428 | json_object_free(json); |
9f049418 DS |
3429 | } else if (!ospf_output) |
3430 | vty_out(vty, "%% OSPF instance not found\n"); | |
b5a8894d CS |
3431 | return ret; |
3432 | } | |
3433 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
b1c3ae8c | 3434 | if ((ospf == NULL) || !ospf->oi_running) { |
9f049418 DS |
3435 | if (uj) { |
3436 | vty_out(vty, "%s\n", | |
3437 | json_object_to_json_string_ext( | |
3438 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 3439 | json_object_free(json); |
9f049418 | 3440 | } else |
94d4c685 | 3441 | vty_out(vty, "%% OSPF instance not found\n"); |
9f049418 | 3442 | |
b5a8894d | 3443 | return CMD_SUCCESS; |
b1c3ae8c | 3444 | } |
b5a8894d CS |
3445 | } else { |
3446 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
3447 | /* Display default ospf (instance 0) info */ | |
b1c3ae8c | 3448 | if (ospf == NULL || !ospf->oi_running) { |
9f049418 DS |
3449 | if (uj) { |
3450 | vty_out(vty, "%s\n", | |
3451 | json_object_to_json_string_ext( | |
3452 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 3453 | json_object_free(json); |
9f049418 | 3454 | } else |
94d4c685 | 3455 | vty_out(vty, "%% OSPF instance not found\n"); |
9f049418 | 3456 | |
b5a8894d | 3457 | return CMD_SUCCESS; |
b1c3ae8c | 3458 | } |
b5a8894d CS |
3459 | } |
3460 | ||
996c9314 | 3461 | if (ospf) { |
b1c3ae8c CS |
3462 | show_ip_ospf_common(vty, ospf, json, use_vrf); |
3463 | if (uj) | |
996c9314 LB |
3464 | vty_out(vty, "%s\n", |
3465 | json_object_to_json_string_ext( | |
3466 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c CS |
3467 | } |
3468 | ||
3469 | if (uj) | |
3470 | json_object_free(json); | |
b5a8894d CS |
3471 | |
3472 | return ret; | |
7c8ff89e DS |
3473 | } |
3474 | ||
3475 | DEFUN (show_ip_ospf_instance, | |
3476 | show_ip_ospf_instance_cmd, | |
6147e2c6 | 3477 | "show ip ospf (1-65535) [json]", |
7c8ff89e DS |
3478 | SHOW_STR |
3479 | IP_STR | |
3480 | "OSPF information\n" | |
ca08c43d | 3481 | "Instance ID\n" |
9973d184 | 3482 | JSON_STR) |
7c8ff89e | 3483 | { |
d62a17ae | 3484 | int idx_number = 3; |
3485 | struct ospf *ospf; | |
d7c0a89a | 3486 | unsigned short instance = 0; |
9f049418 | 3487 | bool uj = use_json(argc, argv); |
b1c3ae8c CS |
3488 | int ret = CMD_SUCCESS; |
3489 | json_object *json = NULL; | |
d62a17ae | 3490 | |
3491 | instance = strtoul(argv[idx_number]->arg, NULL, 10); | |
409f98ab | 3492 | if (instance != ospf_instance) |
ac28e4ec CS |
3493 | return CMD_NOT_MY_INSTANCE; |
3494 | ||
409f98ab IR |
3495 | ospf = ospf_lookup_instance(instance); |
3496 | if (!ospf || !ospf->oi_running) | |
d62a17ae | 3497 | return CMD_SUCCESS; |
3498 | ||
b1c3ae8c CS |
3499 | if (uj) |
3500 | json = json_object_new_object(); | |
3501 | ||
3502 | ret = show_ip_ospf_common(vty, ospf, json, 0); | |
3503 | ||
3504 | if (uj) { | |
996c9314 LB |
3505 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
3506 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c CS |
3507 | json_object_free(json); |
3508 | } | |
3509 | ||
3510 | return ret; | |
d62a17ae | 3511 | } |
3512 | ||
49498934 | 3513 | static void ospf_interface_auth_show(struct vty *vty, struct ospf_interface *oi, |
3514 | json_object *json, bool use_json) | |
3515 | { | |
3516 | int auth_type; | |
3517 | ||
3518 | auth_type = OSPF_IF_PARAM(oi, auth_type); | |
3519 | ||
3520 | switch (auth_type) { | |
3521 | case OSPF_AUTH_NULL: | |
3522 | if (use_json) | |
3523 | json_object_string_add(json, "authentication", | |
3524 | "authenticationNone"); | |
3525 | else | |
3526 | vty_out(vty, " Authentication NULL is enabled\n"); | |
3527 | break; | |
3528 | case OSPF_AUTH_SIMPLE: { | |
3529 | if (use_json) | |
3530 | json_object_string_add(json, "authentication", | |
3531 | "authenticationSimplePassword"); | |
3532 | else | |
3533 | vty_out(vty, | |
3534 | " Simple password authentication enabled\n"); | |
3535 | break; | |
3536 | } | |
3537 | case OSPF_AUTH_CRYPTOGRAPHIC: { | |
3538 | struct crypt_key *ckey; | |
3539 | ||
3540 | if (list_isempty(OSPF_IF_PARAM(oi, auth_crypt))) | |
3541 | return; | |
3542 | ||
3543 | ckey = listgetdata(listtail(OSPF_IF_PARAM(oi, auth_crypt))); | |
3544 | if (ckey) { | |
3545 | if (use_json) { | |
3546 | json_object_string_add(json, "authentication", | |
3547 | "authenticationMessageDigest"); | |
3548 | } else { | |
3549 | vty_out(vty, | |
3550 | " Cryptographic authentication enabled\n"); | |
3551 | vty_out(vty, " Algorithm:MD5\n"); | |
3552 | } | |
3553 | } | |
3554 | break; | |
3555 | } | |
3556 | default: | |
3557 | break; | |
3558 | } | |
3559 | } | |
3560 | ||
d62a17ae | 3561 | static void show_ip_ospf_interface_sub(struct vty *vty, struct ospf *ospf, |
3562 | struct interface *ifp, | |
3563 | json_object *json_interface_sub, | |
9f049418 | 3564 | bool use_json) |
d62a17ae | 3565 | { |
3566 | int is_up; | |
3567 | struct ospf_neighbor *nbr; | |
3568 | struct route_node *rn; | |
96b663a3 | 3569 | char buf[PREFIX_STRLEN]; |
d62a17ae | 3570 | uint32_t bandwidth = ifp->bandwidth ? ifp->bandwidth : ifp->speed; |
3571 | ||
3572 | /* Is interface up? */ | |
3573 | if (use_json) { | |
3574 | is_up = if_is_operative(ifp); | |
3575 | if (is_up) | |
3576 | json_object_boolean_true_add(json_interface_sub, | |
3577 | "ifUp"); | |
3578 | else | |
3579 | json_object_boolean_false_add(json_interface_sub, | |
3580 | "ifDown"); | |
3581 | ||
3582 | json_object_int_add(json_interface_sub, "ifIndex", | |
3583 | ifp->ifindex); | |
3584 | json_object_int_add(json_interface_sub, "mtuBytes", ifp->mtu); | |
3585 | json_object_int_add(json_interface_sub, "bandwidthMbit", | |
3586 | bandwidth); | |
3587 | json_object_string_add(json_interface_sub, "ifFlags", | |
3588 | if_flag_dump(ifp->flags)); | |
3589 | } else { | |
3590 | vty_out(vty, "%s is %s\n", ifp->name, | |
3591 | ((is_up = if_is_operative(ifp)) ? "up" : "down")); | |
3592 | vty_out(vty, " ifindex %u, MTU %u bytes, BW %u Mbit %s\n", | |
3593 | ifp->ifindex, ifp->mtu, bandwidth, | |
3594 | if_flag_dump(ifp->flags)); | |
3595 | } | |
7c8ff89e | 3596 | |
d62a17ae | 3597 | /* Is interface OSPF enabled? */ |
3598 | if (use_json) { | |
3599 | if (ospf_oi_count(ifp) == 0) { | |
3600 | json_object_boolean_false_add(json_interface_sub, | |
3601 | "ospfEnabled"); | |
3602 | return; | |
3603 | } else if (!is_up) { | |
3604 | json_object_boolean_false_add(json_interface_sub, | |
3605 | "ospfRunning"); | |
3606 | return; | |
3607 | } else | |
3608 | json_object_boolean_true_add(json_interface_sub, | |
3609 | "ospfEnabled"); | |
3610 | } else { | |
3611 | if (ospf_oi_count(ifp) == 0) { | |
3612 | vty_out(vty, " OSPF not enabled on this interface\n"); | |
3613 | return; | |
3614 | } else if (!is_up) { | |
3615 | vty_out(vty, | |
3616 | " OSPF is enabled, but not running on this interface\n"); | |
3617 | return; | |
3618 | } | |
3619 | } | |
3620 | ||
3621 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { | |
3622 | struct ospf_interface *oi = rn->info; | |
3623 | ||
3624 | if (oi == NULL) | |
3625 | continue; | |
3626 | ||
3627 | if (CHECK_FLAG(oi->connected->flags, ZEBRA_IFA_UNNUMBERED)) { | |
3628 | if (use_json) | |
3629 | json_object_boolean_true_add(json_interface_sub, | |
3630 | "ifUnnumbered"); | |
3631 | else | |
3632 | vty_out(vty, " This interface is UNNUMBERED,"); | |
3633 | } else { | |
0f3af738 JW |
3634 | struct in_addr dest; |
3635 | const char *dstr; | |
3636 | ||
d62a17ae | 3637 | /* Show OSPF interface information. */ |
3638 | if (use_json) { | |
3639 | json_object_string_add( | |
3640 | json_interface_sub, "ipAddress", | |
96b663a3 MS |
3641 | inet_ntop(AF_INET, |
3642 | &oi->address->u.prefix4, | |
3643 | buf, sizeof(buf))); | |
d62a17ae | 3644 | json_object_int_add(json_interface_sub, |
3645 | "ipAddressPrefixlen", | |
3646 | oi->address->prefixlen); | |
3647 | } else | |
ae32e1c2 DS |
3648 | vty_out(vty, " Internet Address %pFX,", |
3649 | oi->address); | |
d62a17ae | 3650 | |
0f3af738 JW |
3651 | /* For Vlinks, showing the peer address is |
3652 | * probably more informative than the local | |
3653 | * interface that is being used */ | |
3654 | if (oi->type == OSPF_IFTYPE_VIRTUALLINK) { | |
3655 | dstr = "Peer"; | |
3656 | dest = oi->vl_data->peer_addr; | |
3657 | } else if (CONNECTED_PEER(oi->connected) | |
3658 | && oi->connected->destination) { | |
3659 | dstr = "Peer"; | |
3660 | dest = oi->connected->destination->u.prefix4; | |
3661 | } else { | |
3662 | dstr = "Broadcast"; | |
3663 | dest.s_addr = ipv4_broadcast_addr( | |
3664 | oi->connected->address->u.prefix4.s_addr, | |
3665 | oi->connected->address->prefixlen); | |
3666 | } | |
d62a17ae | 3667 | |
0f3af738 JW |
3668 | if (use_json) { |
3669 | json_object_string_add( | |
3670 | json_interface_sub, | |
3671 | "ospfIfType", dstr); | |
d62a17ae | 3672 | if (oi->type == OSPF_IFTYPE_VIRTUALLINK) |
0f3af738 JW |
3673 | json_object_string_add( |
3674 | json_interface_sub, | |
3675 | "vlinkPeer", | |
96b663a3 MS |
3676 | inet_ntop(AF_INET, &dest, |
3677 | buf, sizeof(buf))); | |
d62a17ae | 3678 | else |
d62a17ae | 3679 | json_object_string_add( |
3680 | json_interface_sub, | |
0f3af738 | 3681 | "localIfUsed", |
96b663a3 MS |
3682 | inet_ntop(AF_INET, &dest, |
3683 | buf, sizeof(buf))); | |
0f3af738 | 3684 | } else |
96b663a3 MS |
3685 | vty_out(vty, " %s %pI4,", dstr, |
3686 | &dest); | |
d62a17ae | 3687 | } |
3688 | if (use_json) { | |
3689 | json_object_string_add(json_interface_sub, "area", | |
3690 | ospf_area_desc_string(oi->area)); | |
3691 | if (OSPF_IF_PARAM(oi, mtu_ignore)) | |
3692 | json_object_boolean_true_add( | |
3693 | json_interface_sub, | |
3694 | "mtuMismatchDetect"); | |
96b663a3 MS |
3695 | json_object_string_add( |
3696 | json_interface_sub, "routerId", | |
3697 | inet_ntop(AF_INET, &ospf->router_id, | |
3698 | buf, sizeof(buf))); | |
d62a17ae | 3699 | json_object_string_add(json_interface_sub, |
3700 | "networkType", | |
3701 | ospf_network_type_str[oi->type]); | |
3702 | json_object_int_add(json_interface_sub, "cost", | |
3703 | oi->output_cost); | |
3704 | json_object_int_add( | |
50ad4b42 MS |
3705 | json_interface_sub, "transmitDelaySecs", |
3706 | OSPF_IF_PARAM(oi, transmit_delay)); | |
d62a17ae | 3707 | json_object_string_add(json_interface_sub, "state", |
3708 | lookup_msg(ospf_ism_state_msg, | |
3709 | oi->state, NULL)); | |
3710 | json_object_int_add(json_interface_sub, "priority", | |
3711 | PRIORITY(oi)); | |
3712 | } else { | |
3713 | vty_out(vty, " Area %s\n", | |
3714 | ospf_area_desc_string(oi->area)); | |
3715 | ||
3716 | vty_out(vty, " MTU mismatch detection: %s\n", | |
3717 | OSPF_IF_PARAM(oi, mtu_ignore) ? "disabled" | |
3718 | : "enabled"); | |
3719 | ||
3720 | vty_out(vty, | |
96b663a3 MS |
3721 | " Router ID %pI4, Network Type %s, Cost: %d\n", |
3722 | &ospf->router_id, | |
d62a17ae | 3723 | ospf_network_type_str[oi->type], |
3724 | oi->output_cost); | |
3725 | ||
3726 | vty_out(vty, | |
3727 | " Transmit Delay is %d sec, State %s, Priority %d\n", | |
3728 | OSPF_IF_PARAM(oi, transmit_delay), | |
3729 | lookup_msg(ospf_ism_state_msg, oi->state, NULL), | |
3730 | PRIORITY(oi)); | |
3731 | } | |
3732 | ||
3733 | /* Show DR information. */ | |
975a328e | 3734 | if (DR(oi).s_addr == INADDR_ANY) { |
d62a17ae | 3735 | if (!use_json) |
3736 | vty_out(vty, | |
3737 | " No backup designated router on this network\n"); | |
3738 | } else { | |
3739 | nbr = ospf_nbr_lookup_by_addr(oi->nbrs, &BDR(oi)); | |
3740 | if (nbr == NULL) { | |
3741 | if (!use_json) | |
3742 | vty_out(vty, | |
3743 | " No backup designated router on this network\n"); | |
3744 | } else { | |
3745 | if (use_json) { | |
3746 | json_object_string_add( | |
3747 | json_interface_sub, "bdrId", | |
96b663a3 MS |
3748 | inet_ntop(AF_INET, |
3749 | &nbr->router_id, | |
3750 | buf, sizeof(buf))); | |
d62a17ae | 3751 | json_object_string_add( |
3752 | json_interface_sub, | |
3753 | "bdrAddress", | |
96b663a3 MS |
3754 | inet_ntop(AF_INET, |
3755 | &nbr->address.u | |
3756 | .prefix4, | |
3757 | buf, sizeof(buf))); | |
d62a17ae | 3758 | } else { |
3759 | vty_out(vty, | |
96b663a3 MS |
3760 | " Backup Designated Router (ID) %pI4,", |
3761 | &nbr->router_id); | |
3762 | vty_out(vty, " Interface Address %pI4\n", | |
3763 | &nbr->address.u.prefix4); | |
d62a17ae | 3764 | } |
3765 | } | |
3766 | } | |
3767 | ||
3768 | /* Next network-LSA sequence number we'll use, if we're elected | |
3769 | * DR */ | |
3770 | if (oi->params | |
3771 | && ntohl(oi->params->network_lsa_seqnum) | |
3772 | != OSPF_INITIAL_SEQUENCE_NUMBER) { | |
3773 | if (use_json) | |
3774 | json_object_int_add( | |
3775 | json_interface_sub, | |
3776 | "networkLsaSequence", | |
3777 | ntohl(oi->params->network_lsa_seqnum)); | |
3778 | else | |
3779 | vty_out(vty, | |
3780 | " Saved Network-LSA sequence number 0x%x\n", | |
3781 | ntohl(oi->params->network_lsa_seqnum)); | |
3782 | } | |
3783 | ||
3784 | if (use_json) { | |
3785 | if (OI_MEMBER_CHECK(oi, MEMBER_ALLROUTERS) | |
3786 | || OI_MEMBER_CHECK(oi, MEMBER_DROUTERS)) { | |
3787 | if (OI_MEMBER_CHECK(oi, MEMBER_ALLROUTERS)) | |
3788 | json_object_boolean_true_add( | |
3789 | json_interface_sub, | |
3790 | "mcastMemberOspfAllRouters"); | |
3791 | if (OI_MEMBER_CHECK(oi, MEMBER_DROUTERS)) | |
3792 | json_object_boolean_true_add( | |
3793 | json_interface_sub, | |
3794 | "mcastMemberOspfDesignatedRouters"); | |
3795 | } | |
3796 | } else { | |
3797 | vty_out(vty, " Multicast group memberships:"); | |
3798 | if (OI_MEMBER_CHECK(oi, MEMBER_ALLROUTERS) | |
3799 | || OI_MEMBER_CHECK(oi, MEMBER_DROUTERS)) { | |
3800 | if (OI_MEMBER_CHECK(oi, MEMBER_ALLROUTERS)) | |
3801 | vty_out(vty, " OSPFAllRouters"); | |
3802 | if (OI_MEMBER_CHECK(oi, MEMBER_DROUTERS)) | |
3803 | vty_out(vty, " OSPFDesignatedRouters"); | |
3804 | } else | |
3805 | vty_out(vty, " <None>"); | |
3806 | vty_out(vty, "\n"); | |
3807 | } | |
3808 | ||
3809 | if (use_json) { | |
3810 | if (OSPF_IF_PARAM(oi, fast_hello) == 0) | |
3811 | json_object_int_add( | |
3812 | json_interface_sub, "timerMsecs", | |
50ad4b42 | 3813 | OSPF_IF_PARAM(oi, v_hello) * 1000); |
d62a17ae | 3814 | else |
3815 | json_object_int_add( | |
3816 | json_interface_sub, "timerMsecs", | |
50ad4b42 | 3817 | 1000 / OSPF_IF_PARAM(oi, fast_hello)); |
d62a17ae | 3818 | json_object_int_add(json_interface_sub, |
50ad4b42 MS |
3819 | "timerDeadSecs", |
3820 | OSPF_IF_PARAM(oi, v_wait)); | |
d62a17ae | 3821 | json_object_int_add(json_interface_sub, |
50ad4b42 MS |
3822 | "timerWaitSecs", |
3823 | OSPF_IF_PARAM(oi, v_wait)); | |
d62a17ae | 3824 | json_object_int_add( |
50ad4b42 MS |
3825 | json_interface_sub, "timerRetransmitSecs", |
3826 | OSPF_IF_PARAM(oi, retransmit_interval)); | |
d62a17ae | 3827 | } else { |
3828 | vty_out(vty, " Timer intervals configured,"); | |
3829 | vty_out(vty, " Hello "); | |
3830 | if (OSPF_IF_PARAM(oi, fast_hello) == 0) | |
3831 | vty_out(vty, "%ds,", | |
3832 | OSPF_IF_PARAM(oi, v_hello)); | |
3833 | else | |
3834 | vty_out(vty, "%dms,", | |
3835 | 1000 / OSPF_IF_PARAM(oi, fast_hello)); | |
3836 | vty_out(vty, " Dead %ds, Wait %ds, Retransmit %d\n", | |
3837 | OSPF_IF_PARAM(oi, v_wait), | |
3838 | OSPF_IF_PARAM(oi, v_wait), | |
3839 | OSPF_IF_PARAM(oi, retransmit_interval)); | |
3840 | } | |
3841 | ||
3842 | if (OSPF_IF_PASSIVE_STATUS(oi) == OSPF_IF_ACTIVE) { | |
3843 | char timebuf[OSPF_TIME_DUMP_SIZE]; | |
3844 | if (use_json) { | |
3845 | long time_store = 0; | |
3846 | if (oi->t_hello) | |
3847 | time_store = | |
3848 | monotime_until( | |
3849 | &oi->t_hello->u.sands, | |
3850 | NULL) | |
3851 | / 1000LL; | |
3852 | json_object_int_add(json_interface_sub, | |
3853 | "timerHelloInMsecs", | |
3854 | time_store); | |
3855 | } else | |
3856 | vty_out(vty, " Hello due in %s\n", | |
3857 | ospf_timer_dump(oi->t_hello, timebuf, | |
3858 | sizeof(timebuf))); | |
3859 | } else /* passive-interface is set */ | |
3860 | { | |
3861 | if (use_json) | |
3862 | json_object_boolean_true_add( | |
3863 | json_interface_sub, | |
3864 | "timerPassiveIface"); | |
3865 | else | |
3866 | vty_out(vty, | |
3867 | " No Hellos (Passive interface)\n"); | |
3868 | } | |
7c8ff89e | 3869 | |
d62a17ae | 3870 | if (use_json) { |
3871 | json_object_int_add(json_interface_sub, "nbrCount", | |
3872 | ospf_nbr_count(oi, 0)); | |
3873 | json_object_int_add(json_interface_sub, | |
3874 | "nbrAdjacentCount", | |
3875 | ospf_nbr_count(oi, NSM_Full)); | |
3876 | } else | |
3877 | vty_out(vty, | |
3878 | " Neighbor Count is %d, Adjacent neighbor count is %d\n", | |
3879 | ospf_nbr_count(oi, 0), | |
3880 | ospf_nbr_count(oi, NSM_Full)); | |
659f4e40 RZ |
3881 | |
3882 | ospf_interface_bfd_show(vty, ifp, json_interface_sub); | |
49498934 | 3883 | |
3884 | /* OSPF Authentication information */ | |
3885 | ospf_interface_auth_show(vty, oi, json_interface_sub, use_json); | |
d62a17ae | 3886 | } |
718e3744 | 3887 | } |
3888 | ||
d62a17ae | 3889 | static int show_ip_ospf_interface_common(struct vty *vty, struct ospf *ospf, |
d7c0a89a | 3890 | char *intf_name, uint8_t use_vrf, |
9f049418 | 3891 | json_object *json, bool use_json) |
d62a17ae | 3892 | { |
3893 | struct interface *ifp; | |
f4e14fdb | 3894 | struct vrf *vrf = vrf_lookup_by_id(ospf->vrf_id); |
6282e124 | 3895 | json_object *json_vrf = NULL; |
7dab10ce | 3896 | json_object *json_interface_sub = NULL, *json_interface = NULL; |
7c8ff89e | 3897 | |
d62a17ae | 3898 | if (use_json) { |
b1c3ae8c CS |
3899 | if (use_vrf) |
3900 | json_vrf = json_object_new_object(); | |
3901 | else | |
3902 | json_vrf = json; | |
6282e124 | 3903 | json_interface = json_object_new_object(); |
d62a17ae | 3904 | } |
3905 | ||
3906 | if (ospf->instance) { | |
3907 | if (use_json) | |
3908 | json_object_int_add(json, "ospfInstance", | |
3909 | ospf->instance); | |
3910 | else | |
3911 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
3912 | } | |
3913 | ||
b1c3ae8c CS |
3914 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); |
3915 | ||
3916 | if (intf_name == NULL) { | |
d62a17ae | 3917 | /* Show All Interfaces.*/ |
451fda4f | 3918 | FOR_ALL_INTERFACES (vrf, ifp) { |
d62a17ae | 3919 | if (ospf_oi_count(ifp)) { |
7dab10ce | 3920 | if (use_json) { |
d62a17ae | 3921 | json_interface_sub = |
3922 | json_object_new_object(); | |
7dab10ce | 3923 | } |
d62a17ae | 3924 | show_ip_ospf_interface_sub(vty, ospf, ifp, |
3925 | json_interface_sub, | |
3926 | use_json); | |
3927 | ||
7dab10ce | 3928 | if (use_json) { |
d62a17ae | 3929 | json_object_object_add( |
7dab10ce | 3930 | json_interface, ifp->name, |
d62a17ae | 3931 | json_interface_sub); |
7dab10ce | 3932 | } |
d62a17ae | 3933 | } |
3934 | } | |
6282e124 CS |
3935 | if (use_json) |
3936 | json_object_object_add(json_vrf, "interfaces", | |
996c9314 | 3937 | json_interface); |
d62a17ae | 3938 | } else { |
3939 | /* Interface name is specified. */ | |
a36898e7 | 3940 | ifp = if_lookup_by_name(intf_name, ospf->vrf_id); |
b1c3ae8c | 3941 | if (ifp == NULL) { |
d62a17ae | 3942 | if (use_json) |
b1c3ae8c | 3943 | json_object_boolean_true_add(json_vrf, |
d62a17ae | 3944 | "noSuchIface"); |
3945 | else | |
3946 | vty_out(vty, "No such interface name\n"); | |
3947 | } else { | |
7dab10ce | 3948 | if (use_json) { |
d62a17ae | 3949 | json_interface_sub = json_object_new_object(); |
7dab10ce | 3950 | json_interface = json_object_new_object(); |
7dab10ce | 3951 | } |
d62a17ae | 3952 | |
3953 | show_ip_ospf_interface_sub( | |
3954 | vty, ospf, ifp, json_interface_sub, use_json); | |
3955 | ||
7dab10ce | 3956 | if (use_json) { |
7dab10ce CS |
3957 | json_object_object_add(json_interface, |
3958 | ifp->name, | |
d62a17ae | 3959 | json_interface_sub); |
6282e124 CS |
3960 | json_object_object_add(json_vrf, "interfaces", |
3961 | json_interface); | |
7dab10ce | 3962 | } |
d62a17ae | 3963 | } |
3964 | } | |
3965 | ||
3966 | if (use_json) { | |
b1c3ae8c CS |
3967 | if (use_vrf) { |
3968 | if (ospf->vrf_id == VRF_DEFAULT) | |
3969 | json_object_object_add(json, "default", | |
3970 | json_vrf); | |
3971 | else | |
3972 | json_object_object_add(json, ospf->name, | |
3973 | json_vrf); | |
3974 | } | |
d62a17ae | 3975 | } else |
3976 | vty_out(vty, "\n"); | |
3977 | ||
3978 | return CMD_SUCCESS; | |
718e3744 | 3979 | } |
3980 | ||
c9339663 CS |
3981 | static void show_ip_ospf_interface_traffic_sub(struct vty *vty, |
3982 | struct ospf_interface *oi, | |
3983 | json_object *json_interface_sub, | |
9f049418 | 3984 | bool use_json) |
c9339663 CS |
3985 | { |
3986 | if (use_json) { | |
996c9314 LB |
3987 | json_object_int_add(json_interface_sub, "ifIndex", |
3988 | oi->ifp->ifindex); | |
3989 | json_object_int_add(json_interface_sub, "helloIn", | |
3990 | oi->hello_in); | |
3991 | json_object_int_add(json_interface_sub, "helloOut", | |
3992 | oi->hello_out); | |
3993 | json_object_int_add(json_interface_sub, "dbDescIn", | |
3994 | oi->db_desc_in); | |
3995 | json_object_int_add(json_interface_sub, "dbDescOut", | |
3996 | oi->db_desc_out); | |
3997 | json_object_int_add(json_interface_sub, "lsReqIn", | |
3998 | oi->ls_req_in); | |
3999 | json_object_int_add(json_interface_sub, "lsReqOut", | |
4000 | oi->ls_req_out); | |
4001 | json_object_int_add(json_interface_sub, "lsUpdIn", | |
4002 | oi->ls_upd_in); | |
4003 | json_object_int_add(json_interface_sub, "lsUpdOut", | |
4004 | oi->ls_upd_out); | |
4005 | json_object_int_add(json_interface_sub, "lsAckIn", | |
4006 | oi->ls_ack_in); | |
4007 | json_object_int_add(json_interface_sub, "lsAckOut", | |
4008 | oi->ls_ack_out); | |
c9339663 CS |
4009 | } else { |
4010 | vty_out(vty, | |
4011 | "%-10s %8u/%-8u %7u/%-7u %7u/%-7u %7u/%-7u %7u/%-7u\n", | |
996c9314 LB |
4012 | oi->ifp->name, oi->hello_in, oi->hello_out, |
4013 | oi->db_desc_in, oi->db_desc_out, oi->ls_req_in, | |
4014 | oi->ls_req_out, oi->ls_upd_in, oi->ls_upd_out, | |
c9339663 CS |
4015 | oi->ls_ack_in, oi->ls_ack_out); |
4016 | } | |
4017 | } | |
4018 | ||
4019 | /* OSPFv2 Packet Counters */ | |
996c9314 LB |
4020 | static int show_ip_ospf_interface_traffic_common( |
4021 | struct vty *vty, struct ospf *ospf, char *intf_name, json_object *json, | |
9f049418 | 4022 | int display_once, uint8_t use_vrf, bool use_json) |
c9339663 CS |
4023 | { |
4024 | struct vrf *vrf = NULL; | |
4025 | struct interface *ifp = NULL; | |
b1c3ae8c | 4026 | json_object *json_vrf = NULL; |
c9339663 CS |
4027 | json_object *json_interface_sub = NULL; |
4028 | ||
4029 | if (!use_json && !display_once) { | |
4030 | vty_out(vty, "\n"); | |
996c9314 LB |
4031 | vty_out(vty, "%-12s%-17s%-17s%-17s%-17s%-17s\n", "Interface", |
4032 | " HELLO", " DB-Desc", " LS-Req", " LS-Update", | |
4033 | " LS-Ack"); | |
c9339663 | 4034 | vty_out(vty, "%-10s%-18s%-18s%-17s%-17s%-17s\n", "", |
996c9314 LB |
4035 | " Rx/Tx", " Rx/Tx", " Rx/Tx", " Rx/Tx", |
4036 | " Rx/Tx"); | |
c9339663 | 4037 | vty_out(vty, |
996c9314 | 4038 | "--------------------------------------------------------------------------------------------\n"); |
c9339663 | 4039 | } else if (use_json) { |
b1c3ae8c CS |
4040 | if (use_vrf) |
4041 | json_vrf = json_object_new_object(); | |
4042 | else | |
4043 | json_vrf = json; | |
c9339663 CS |
4044 | } |
4045 | ||
b1c3ae8c CS |
4046 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); |
4047 | ||
c9339663 CS |
4048 | if (intf_name == NULL) { |
4049 | vrf = vrf_lookup_by_id(ospf->vrf_id); | |
4050 | FOR_ALL_INTERFACES (vrf, ifp) { | |
4051 | struct route_node *rn; | |
4052 | struct ospf_interface *oi; | |
4053 | ||
4054 | if (ospf_oi_count(ifp) == 0) | |
4055 | continue; | |
4056 | ||
4057 | for (rn = route_top(IF_OIFS(ifp)); rn; | |
996c9314 | 4058 | rn = route_next(rn)) { |
c9339663 CS |
4059 | oi = rn->info; |
4060 | ||
4061 | if (oi == NULL) | |
4062 | continue; | |
4063 | ||
4064 | if (use_json) { | |
4065 | json_interface_sub = | |
4066 | json_object_new_object(); | |
4067 | } | |
4068 | ||
996c9314 LB |
4069 | show_ip_ospf_interface_traffic_sub( |
4070 | vty, oi, json_interface_sub, use_json); | |
c9339663 | 4071 | if (use_json) { |
996c9314 LB |
4072 | json_object_object_add( |
4073 | json_vrf, ifp->name, | |
4074 | json_interface_sub); | |
c9339663 CS |
4075 | } |
4076 | } | |
4077 | } | |
4078 | } else { | |
4079 | /* Interface name is specified. */ | |
a36898e7 | 4080 | ifp = if_lookup_by_name(intf_name, ospf->vrf_id); |
c9339663 CS |
4081 | if (ifp != NULL) { |
4082 | struct route_node *rn; | |
4083 | struct ospf_interface *oi; | |
4084 | ||
4085 | if (ospf_oi_count(ifp) == 0) { | |
996c9314 LB |
4086 | vty_out(vty, |
4087 | " OSPF not enabled on this interface %s\n", | |
c9339663 CS |
4088 | ifp->name); |
4089 | return CMD_SUCCESS; | |
4090 | } | |
4091 | ||
4092 | for (rn = route_top(IF_OIFS(ifp)); rn; | |
4093 | rn = route_next(rn)) { | |
4094 | oi = rn->info; | |
4095 | ||
4096 | if (use_json) { | |
4097 | json_interface_sub = | |
4098 | json_object_new_object(); | |
4099 | } | |
4100 | ||
996c9314 LB |
4101 | show_ip_ospf_interface_traffic_sub( |
4102 | vty, oi, json_interface_sub, use_json); | |
c9339663 | 4103 | if (use_json) { |
996c9314 LB |
4104 | json_object_object_add( |
4105 | json_vrf, ifp->name, | |
4106 | json_interface_sub); | |
c9339663 CS |
4107 | } |
4108 | } | |
4109 | } | |
4110 | } | |
4111 | ||
4112 | if (use_json) { | |
b1c3ae8c CS |
4113 | if (use_vrf) { |
4114 | if (ospf->vrf_id == VRF_DEFAULT) | |
4115 | json_object_object_add(json, "default", | |
4116 | json_vrf); | |
4117 | else | |
4118 | json_object_object_add(json, ospf->name, | |
4119 | json_vrf); | |
4120 | } | |
4121 | } else | |
4122 | vty_out(vty, "\n"); | |
c9339663 CS |
4123 | |
4124 | return CMD_SUCCESS; | |
4125 | } | |
4126 | ||
7c8ff89e DS |
4127 | DEFUN (show_ip_ospf_interface, |
4128 | show_ip_ospf_interface_cmd, | |
43b8d1d8 | 4129 | "show ip ospf [vrf <NAME|all>] interface [INTERFACE] [json]", |
7c8ff89e DS |
4130 | SHOW_STR |
4131 | IP_STR | |
4132 | "OSPF information\n" | |
b5a8894d | 4133 | VRF_CMD_HELP_STR |
43b8d1d8 | 4134 | "All VRFs\n" |
7c8ff89e | 4135 | "Interface information\n" |
7ec4159b | 4136 | "Interface name\n" |
9973d184 | 4137 | JSON_STR) |
7c8ff89e | 4138 | { |
d62a17ae | 4139 | struct ospf *ospf; |
9f049418 | 4140 | bool uj = use_json(argc, argv); |
b5a8894d | 4141 | struct listnode *node = NULL; |
b1c3ae8c | 4142 | char *vrf_name = NULL, *intf_name = NULL; |
2951a7a4 | 4143 | bool all_vrf = false; |
b5a8894d CS |
4144 | int ret = CMD_SUCCESS; |
4145 | int inst = 0; | |
b1c3ae8c | 4146 | int idx_vrf = 0, idx_intf = 0; |
d7c0a89a | 4147 | uint8_t use_vrf = 0; |
b1c3ae8c | 4148 | json_object *json = NULL; |
7c8ff89e | 4149 | |
43b8d1d8 CS |
4150 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
4151 | ||
b1c3ae8c CS |
4152 | if (argv_find(argv, argc, "INTERFACE", &idx_intf)) |
4153 | intf_name = argv[idx_intf]->arg; | |
4154 | ||
d62a17ae | 4155 | if (uj) |
b1c3ae8c | 4156 | json = json_object_new_object(); |
6be4da3d | 4157 | |
b5a8894d CS |
4158 | /* vrf input is provided could be all or specific vrf*/ |
4159 | if (vrf_name) { | |
b1c3ae8c | 4160 | use_vrf = 1; |
b5a8894d CS |
4161 | if (all_vrf) { |
4162 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
4163 | if (!ospf->oi_running) | |
4164 | continue; | |
996c9314 LB |
4165 | ret = show_ip_ospf_interface_common( |
4166 | vty, ospf, intf_name, use_vrf, json, | |
4167 | uj); | |
b5a8894d | 4168 | } |
b1c3ae8c CS |
4169 | |
4170 | if (uj) { | |
4171 | vty_out(vty, "%s\n", | |
996c9314 LB |
4172 | json_object_to_json_string_ext( |
4173 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 4174 | json_object_free(json); |
9f049418 | 4175 | } else if (!ospf) |
94d4c685 | 4176 | vty_out(vty, "%% OSPF instance not found\n"); |
b1c3ae8c | 4177 | |
b5a8894d CS |
4178 | return ret; |
4179 | } | |
4180 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
b1c3ae8c | 4181 | if (ospf == NULL || !ospf->oi_running) { |
9f049418 DS |
4182 | if (uj) { |
4183 | vty_out(vty, "%s\n", | |
4184 | json_object_to_json_string_ext( | |
4185 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 4186 | json_object_free(json); |
9f049418 | 4187 | } else |
94d4c685 | 4188 | vty_out(vty, "%% OSPF instance not found\n"); |
9f049418 | 4189 | |
b5a8894d | 4190 | return CMD_SUCCESS; |
b1c3ae8c CS |
4191 | } |
4192 | ret = show_ip_ospf_interface_common(vty, ospf, intf_name, | |
4193 | use_vrf, json, uj); | |
b5a8894d CS |
4194 | |
4195 | } else { | |
4196 | /* Display default ospf (instance 0) info */ | |
4197 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
b1c3ae8c | 4198 | if (ospf == NULL || !ospf->oi_running) { |
9f049418 DS |
4199 | if (uj) { |
4200 | vty_out(vty, "%s\n", | |
4201 | json_object_to_json_string_ext( | |
4202 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 4203 | json_object_free(json); |
9f049418 | 4204 | } else |
94d4c685 | 4205 | vty_out(vty, "%% OSPF instance not found\n"); |
9f049418 | 4206 | |
b5a8894d | 4207 | return CMD_SUCCESS; |
b1c3ae8c CS |
4208 | } |
4209 | ret = show_ip_ospf_interface_common(vty, ospf, intf_name, | |
4210 | use_vrf, json, uj); | |
4211 | } | |
4212 | ||
4213 | if (uj) { | |
996c9314 LB |
4214 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
4215 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 4216 | json_object_free(json); |
b5a8894d CS |
4217 | } |
4218 | ||
4219 | return ret; | |
7c8ff89e DS |
4220 | } |
4221 | ||
4222 | DEFUN (show_ip_ospf_instance_interface, | |
4223 | show_ip_ospf_instance_interface_cmd, | |
6147e2c6 | 4224 | "show ip ospf (1-65535) interface [INTERFACE] [json]", |
7c8ff89e DS |
4225 | SHOW_STR |
4226 | IP_STR | |
4227 | "OSPF information\n" | |
4228 | "Instance ID\n" | |
4229 | "Interface information\n" | |
7ec4159b | 4230 | "Interface name\n" |
9973d184 | 4231 | JSON_STR) |
7c8ff89e | 4232 | { |
d62a17ae | 4233 | int idx_number = 3; |
b1c3ae8c | 4234 | int idx_intf = 0; |
d62a17ae | 4235 | struct ospf *ospf; |
d7c0a89a | 4236 | unsigned short instance = 0; |
9f049418 | 4237 | bool uj = use_json(argc, argv); |
b1c3ae8c CS |
4238 | char *intf_name = NULL; |
4239 | int ret = CMD_SUCCESS; | |
4240 | json_object *json = NULL; | |
d62a17ae | 4241 | |
4242 | instance = strtoul(argv[idx_number]->arg, NULL, 10); | |
409f98ab | 4243 | if (instance != ospf_instance) |
ac28e4ec CS |
4244 | return CMD_NOT_MY_INSTANCE; |
4245 | ||
409f98ab IR |
4246 | ospf = ospf_lookup_instance(instance); |
4247 | if (!ospf || !ospf->oi_running) | |
d62a17ae | 4248 | return CMD_SUCCESS; |
4249 | ||
4250 | if (uj) | |
b1c3ae8c CS |
4251 | json = json_object_new_object(); |
4252 | ||
4253 | if (argv_find(argv, argc, "INTERFACE", &idx_intf)) | |
4254 | intf_name = argv[idx_intf]->arg; | |
4255 | ||
4256 | ret = show_ip_ospf_interface_common(vty, ospf, intf_name, 0, json, uj); | |
4257 | ||
4258 | if (uj) { | |
996c9314 LB |
4259 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
4260 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c CS |
4261 | json_object_free(json); |
4262 | } | |
d62a17ae | 4263 | |
b1c3ae8c | 4264 | return ret; |
d62a17ae | 4265 | } |
4266 | ||
c9339663 CS |
4267 | DEFUN (show_ip_ospf_interface_traffic, |
4268 | show_ip_ospf_interface_traffic_cmd, | |
4269 | "show ip ospf [vrf <NAME|all>] interface traffic [INTERFACE] [json]", | |
4270 | SHOW_STR | |
4271 | IP_STR | |
4272 | "OSPF information\n" | |
4273 | VRF_CMD_HELP_STR | |
4274 | "All VRFs\n" | |
4275 | "Interface information\n" | |
4276 | "Protocol Packet counters\n" | |
4277 | "Interface name\n" | |
4278 | JSON_STR) | |
4279 | { | |
4280 | struct ospf *ospf = NULL; | |
4281 | struct listnode *node = NULL; | |
4282 | char *vrf_name = NULL, *intf_name = NULL; | |
2951a7a4 | 4283 | bool all_vrf = false; |
c9339663 CS |
4284 | int inst = 0; |
4285 | int idx_vrf = 0, idx_intf = 0; | |
9f049418 | 4286 | bool uj = use_json(argc, argv); |
b1c3ae8c | 4287 | json_object *json = NULL; |
c9339663 CS |
4288 | int ret = CMD_SUCCESS; |
4289 | int display_once = 0; | |
d7c0a89a | 4290 | uint8_t use_vrf = 0; |
c9339663 CS |
4291 | |
4292 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); | |
4293 | ||
4294 | if (argv_find(argv, argc, "INTERFACE", &idx_intf)) | |
4295 | intf_name = argv[idx_intf]->arg; | |
4296 | ||
b1c3ae8c CS |
4297 | if (uj) |
4298 | json = json_object_new_object(); | |
4299 | ||
c9339663 | 4300 | if (vrf_name) { |
b1c3ae8c | 4301 | use_vrf = 1; |
c9339663 CS |
4302 | if (all_vrf) { |
4303 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
4304 | if (!ospf->oi_running) | |
4305 | continue; | |
4306 | ||
996c9314 LB |
4307 | ret = show_ip_ospf_interface_traffic_common( |
4308 | vty, ospf, intf_name, json, | |
4309 | display_once, use_vrf, uj); | |
c9339663 CS |
4310 | display_once = 1; |
4311 | } | |
b1c3ae8c CS |
4312 | |
4313 | if (uj) { | |
4314 | vty_out(vty, "%s\n", | |
996c9314 LB |
4315 | json_object_to_json_string_ext( |
4316 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c CS |
4317 | json_object_free(json); |
4318 | } | |
4319 | ||
c9339663 CS |
4320 | return ret; |
4321 | } | |
4322 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
b1c3ae8c CS |
4323 | if (ospf == NULL || !ospf->oi_running) { |
4324 | if (uj) | |
4325 | json_object_free(json); | |
c9339663 | 4326 | return CMD_SUCCESS; |
b1c3ae8c CS |
4327 | } |
4328 | ||
996c9314 LB |
4329 | ret = show_ip_ospf_interface_traffic_common( |
4330 | vty, ospf, intf_name, json, display_once, use_vrf, uj); | |
c9339663 CS |
4331 | } else { |
4332 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
b1c3ae8c CS |
4333 | if (ospf == NULL || !ospf->oi_running) { |
4334 | if (uj) | |
4335 | json_object_free(json); | |
c9339663 | 4336 | return CMD_SUCCESS; |
b1c3ae8c CS |
4337 | } |
4338 | ||
996c9314 LB |
4339 | ret = show_ip_ospf_interface_traffic_common( |
4340 | vty, ospf, intf_name, json, display_once, use_vrf, uj); | |
b1c3ae8c CS |
4341 | } |
4342 | ||
4343 | if (uj) { | |
996c9314 LB |
4344 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
4345 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 4346 | json_object_free(json); |
c9339663 CS |
4347 | } |
4348 | ||
4349 | return ret; | |
4350 | } | |
4351 | ||
4352 | ||
d62a17ae | 4353 | static void show_ip_ospf_neighbour_header(struct vty *vty) |
4354 | { | |
c84355a9 | 4355 | vty_out(vty, "\n%-15s %3s %-15s %9s %-15s %-32s %5s %5s %5s\n", |
d62a17ae | 4356 | "Neighbor ID", "Pri", "State", "Dead Time", "Address", |
4357 | "Interface", "RXmtL", "RqstL", "DBsmL"); | |
4358 | } | |
4359 | ||
4360 | static void show_ip_ospf_neighbor_sub(struct vty *vty, | |
4361 | struct ospf_interface *oi, | |
9f049418 | 4362 | json_object *json, bool use_json) |
d62a17ae | 4363 | { |
4364 | struct route_node *rn; | |
cef262c3 | 4365 | struct ospf_neighbor *nbr, *prev_nbr = NULL; |
d62a17ae | 4366 | char msgbuf[16]; |
96b663a3 | 4367 | char buf[PREFIX_STRLEN]; |
d62a17ae | 4368 | char timebuf[OSPF_TIME_DUMP_SIZE]; |
cef262c3 | 4369 | json_object *json_neighbor = NULL, *json_neigh_array = NULL; |
d62a17ae | 4370 | |
4371 | for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) { | |
4372 | if ((nbr = rn->info)) { | |
4373 | /* Do not show myself. */ | |
cef262c3 CS |
4374 | if (nbr == oi->nbr_self) |
4375 | continue; | |
4376 | /* Down state is not shown. */ | |
4377 | if (nbr->state == NSM_Down) | |
4378 | continue; | |
4379 | if (use_json) { | |
4380 | char neigh_str[INET_ADDRSTRLEN]; | |
4381 | ||
996c9314 LB |
4382 | if (prev_nbr |
4383 | && !IPV4_ADDR_SAME(&prev_nbr->src, | |
4384 | &nbr->src)) { | |
cef262c3 CS |
4385 | /* Start new neigh list */ |
4386 | json_neigh_array = NULL; | |
4387 | } | |
4388 | ||
996c9314 | 4389 | if (nbr->state == NSM_Attempt |
975a328e | 4390 | && nbr->router_id.s_addr == INADDR_ANY) |
6021c6c0 CS |
4391 | strlcpy(neigh_str, "neighbor", |
4392 | sizeof(neigh_str)); | |
cef262c3 | 4393 | else |
96b663a3 MS |
4394 | inet_ntop(AF_INET, &nbr->router_id, |
4395 | neigh_str, sizeof(neigh_str)); | |
cef262c3 CS |
4396 | |
4397 | json_object_object_get_ex(json, neigh_str, | |
4398 | &json_neigh_array); | |
4399 | ||
4400 | if (!json_neigh_array) { | |
996c9314 LB |
4401 | json_neigh_array = |
4402 | json_object_new_array(); | |
4403 | json_object_object_add( | |
4404 | json, neigh_str, | |
4405 | json_neigh_array); | |
d62a17ae | 4406 | } |
cef262c3 | 4407 | |
996c9314 | 4408 | json_neighbor = json_object_new_object(); |
cef262c3 CS |
4409 | |
4410 | ospf_nbr_state_message(nbr, msgbuf, 16); | |
4411 | ||
4412 | long time_store; | |
4413 | ||
996c9314 LB |
4414 | time_store = |
4415 | monotime_until( | |
cef262c3 | 4416 | &nbr->t_inactivity->u.sands, |
996c9314 LB |
4417 | NULL) |
4418 | / 1000LL; | |
cef262c3 | 4419 | |
996c9314 | 4420 | json_object_int_add(json_neighbor, "priority", |
cef262c3 CS |
4421 | nbr->priority); |
4422 | json_object_string_add(json_neighbor, "state", | |
4423 | msgbuf); | |
4424 | json_object_int_add(json_neighbor, | |
4425 | "deadTimeMsecs", | |
4426 | time_store); | |
96b663a3 MS |
4427 | json_object_string_add( |
4428 | json_neighbor, "address", | |
4429 | inet_ntop(AF_INET, &nbr->src, | |
4430 | buf, sizeof(buf))); | |
cef262c3 CS |
4431 | json_object_string_add(json_neighbor, |
4432 | "ifaceName", | |
4433 | IF_NAME(oi)); | |
996c9314 LB |
4434 | json_object_int_add( |
4435 | json_neighbor, "retransmitCounter", | |
4436 | ospf_ls_retransmit_count(nbr)); | |
cef262c3 | 4437 | json_object_int_add(json_neighbor, |
996c9314 LB |
4438 | "requestCounter", |
4439 | ospf_ls_request_count(nbr)); | |
cef262c3 | 4440 | json_object_int_add(json_neighbor, |
996c9314 LB |
4441 | "dbSummaryCounter", |
4442 | ospf_db_summary_count(nbr)); | |
cef262c3 CS |
4443 | |
4444 | json_object_array_add(json_neigh_array, | |
4445 | json_neighbor); | |
4446 | } else { | |
4447 | ospf_nbr_state_message(nbr, msgbuf, 16); | |
4448 | ||
996c9314 | 4449 | if (nbr->state == NSM_Attempt |
975a328e | 4450 | && nbr->router_id.s_addr == INADDR_ANY) |
996c9314 LB |
4451 | vty_out(vty, "%-15s %3d %-15s ", "-", |
4452 | nbr->priority, msgbuf); | |
cef262c3 | 4453 | else |
96b663a3 MS |
4454 | vty_out(vty, "%-15pI4 %3d %-15s ", |
4455 | &nbr->router_id, | |
996c9314 | 4456 | nbr->priority, msgbuf); |
cef262c3 CS |
4457 | |
4458 | vty_out(vty, "%9s ", | |
4459 | ospf_timer_dump(nbr->t_inactivity, | |
4460 | timebuf, | |
4461 | sizeof(timebuf))); | |
96b663a3 | 4462 | vty_out(vty, "%-15pI4 ", &nbr->src); |
c84355a9 | 4463 | vty_out(vty, "%-32s %5ld %5ld %5d\n", |
cef262c3 CS |
4464 | IF_NAME(oi), |
4465 | ospf_ls_retransmit_count(nbr), | |
4466 | ospf_ls_request_count(nbr), | |
4467 | ospf_db_summary_count(nbr)); | |
d62a17ae | 4468 | } |
cef262c3 | 4469 | prev_nbr = nbr; |
d62a17ae | 4470 | } |
4471 | } | |
4472 | } | |
4473 | ||
4474 | static int show_ip_ospf_neighbor_common(struct vty *vty, struct ospf *ospf, | |
9f049418 | 4475 | json_object *json, bool use_json, |
d7c0a89a | 4476 | uint8_t use_vrf) |
d62a17ae | 4477 | { |
4478 | struct ospf_interface *oi; | |
4479 | struct listnode *node; | |
6282e124 | 4480 | json_object *json_vrf = NULL; |
2bc7673f | 4481 | json_object *json_nbr_sub = NULL; |
7c8ff89e | 4482 | |
b1c3ae8c CS |
4483 | if (use_json) { |
4484 | if (use_vrf) | |
4485 | json_vrf = json_object_new_object(); | |
4486 | else | |
4487 | json_vrf = json; | |
6282e124 | 4488 | json_nbr_sub = json_object_new_object(); |
b1c3ae8c | 4489 | } |
d62a17ae | 4490 | |
4491 | if (ospf->instance) { | |
4492 | if (use_json) | |
4493 | json_object_int_add(json, "ospfInstance", | |
4494 | ospf->instance); | |
4495 | else | |
4496 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
4497 | } | |
7c8ff89e | 4498 | |
b1c3ae8c CS |
4499 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); |
4500 | if (!use_json) | |
4501 | show_ip_ospf_neighbour_header(vty); | |
87bd50e8 | 4502 | |
2bc7673f CS |
4503 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) { |
4504 | if (ospf_interface_neighbor_count(oi) == 0) | |
4505 | continue; | |
2bc7673f CS |
4506 | show_ip_ospf_neighbor_sub(vty, oi, json_nbr_sub, use_json); |
4507 | } | |
718e3744 | 4508 | |
d62a17ae | 4509 | if (use_json) { |
996c9314 | 4510 | json_object_object_add(json_vrf, "neighbors", json_nbr_sub); |
b1c3ae8c CS |
4511 | if (use_vrf) { |
4512 | if (ospf->vrf_id == VRF_DEFAULT) | |
4513 | json_object_object_add(json, "default", | |
4514 | json_vrf); | |
4515 | else | |
4516 | json_object_object_add(json, ospf->name, | |
4517 | json_vrf); | |
4518 | } | |
d62a17ae | 4519 | } else |
4520 | vty_out(vty, "\n"); | |
7c8ff89e | 4521 | |
d62a17ae | 4522 | return CMD_SUCCESS; |
718e3744 | 4523 | } |
4524 | ||
7c8ff89e DS |
4525 | DEFUN (show_ip_ospf_neighbor, |
4526 | show_ip_ospf_neighbor_cmd, | |
b5a8894d | 4527 | "show ip ospf [vrf <NAME|all>] neighbor [json]", |
718e3744 | 4528 | SHOW_STR |
4529 | IP_STR | |
4530 | "OSPF information\n" | |
b5a8894d CS |
4531 | VRF_CMD_HELP_STR |
4532 | "All VRFs\n" | |
91756b38 | 4533 | "Neighbor list\n" |
9973d184 | 4534 | JSON_STR) |
718e3744 | 4535 | { |
d62a17ae | 4536 | struct ospf *ospf; |
9f049418 | 4537 | bool uj = use_json(argc, argv); |
b5a8894d CS |
4538 | struct listnode *node = NULL; |
4539 | char *vrf_name = NULL; | |
2951a7a4 | 4540 | bool all_vrf = false; |
b5a8894d CS |
4541 | int ret = CMD_SUCCESS; |
4542 | int inst = 0; | |
4543 | int idx_vrf = 0; | |
d7c0a89a | 4544 | uint8_t use_vrf = 0; |
b1c3ae8c | 4545 | json_object *json = NULL; |
718e3744 | 4546 | |
43b8d1d8 | 4547 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
7c8ff89e | 4548 | |
b1c3ae8c CS |
4549 | if (uj) |
4550 | json = json_object_new_object(); | |
b5a8894d CS |
4551 | |
4552 | /* vrf input is provided could be all or specific vrf*/ | |
4553 | if (vrf_name) { | |
b1c3ae8c | 4554 | use_vrf = 1; |
b5a8894d CS |
4555 | if (all_vrf) { |
4556 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
4557 | if (!ospf->oi_running) | |
4558 | continue; | |
996c9314 LB |
4559 | ret = show_ip_ospf_neighbor_common( |
4560 | vty, ospf, json, uj, use_vrf); | |
b1c3ae8c CS |
4561 | } |
4562 | ||
4563 | if (uj) { | |
4564 | vty_out(vty, "%s\n", | |
996c9314 LB |
4565 | json_object_to_json_string_ext( |
4566 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 4567 | json_object_free(json); |
9f049418 DS |
4568 | } else if (!ospf) |
4569 | vty_out(vty, "OSPF instance not found\n"); | |
b1c3ae8c | 4570 | |
b5a8894d CS |
4571 | return ret; |
4572 | } | |
b1c3ae8c | 4573 | |
b5a8894d | 4574 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); |
b1c3ae8c | 4575 | if (ospf == NULL || !ospf->oi_running) { |
9f049418 DS |
4576 | if (uj) { |
4577 | vty_out(vty, "%s\n", | |
4578 | json_object_to_json_string_ext( | |
4579 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 4580 | json_object_free(json); |
9f049418 DS |
4581 | } else |
4582 | vty_out(vty, "%% OSPF instance not found\n"); | |
4583 | ||
b5a8894d | 4584 | return CMD_SUCCESS; |
b1c3ae8c | 4585 | } |
b5a8894d CS |
4586 | } else { |
4587 | /* Display default ospf (instance 0) info */ | |
4588 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
b1c3ae8c | 4589 | if (ospf == NULL || !ospf->oi_running) { |
9f049418 DS |
4590 | if (uj) { |
4591 | vty_out(vty, "%s\n", | |
4592 | json_object_to_json_string_ext( | |
4593 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 4594 | json_object_free(json); |
9f049418 DS |
4595 | } else |
4596 | vty_out(vty, "%% OSPF instance not found\n"); | |
4597 | ||
b5a8894d | 4598 | return CMD_SUCCESS; |
b1c3ae8c | 4599 | } |
b5a8894d CS |
4600 | } |
4601 | ||
b1c3ae8c CS |
4602 | if (ospf) { |
4603 | ret = show_ip_ospf_neighbor_common(vty, ospf, json, uj, | |
4604 | use_vrf); | |
4605 | ||
4606 | if (uj) { | |
4607 | vty_out(vty, "%s\n", | |
996c9314 LB |
4608 | json_object_to_json_string_ext( |
4609 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c CS |
4610 | } |
4611 | } | |
4612 | ||
4613 | if (uj) | |
4614 | json_object_free(json); | |
b5a8894d CS |
4615 | |
4616 | return ret; | |
7c8ff89e DS |
4617 | } |
4618 | ||
4619 | ||
4620 | DEFUN (show_ip_ospf_instance_neighbor, | |
4621 | show_ip_ospf_instance_neighbor_cmd, | |
6147e2c6 | 4622 | "show ip ospf (1-65535) neighbor [json]", |
7c8ff89e DS |
4623 | SHOW_STR |
4624 | IP_STR | |
4625 | "OSPF information\n" | |
4626 | "Instance ID\n" | |
91756b38 | 4627 | "Neighbor list\n" |
9973d184 | 4628 | JSON_STR) |
7c8ff89e | 4629 | { |
d62a17ae | 4630 | int idx_number = 3; |
4631 | struct ospf *ospf; | |
d7c0a89a | 4632 | unsigned short instance = 0; |
9f049418 | 4633 | bool uj = use_json(argc, argv); |
b1c3ae8c CS |
4634 | json_object *json = NULL; |
4635 | int ret = CMD_SUCCESS; | |
7c8ff89e | 4636 | |
d62a17ae | 4637 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
409f98ab | 4638 | if (instance != ospf_instance) |
ac28e4ec CS |
4639 | return CMD_NOT_MY_INSTANCE; |
4640 | ||
409f98ab IR |
4641 | ospf = ospf_lookup_instance(instance); |
4642 | if (!ospf || !ospf->oi_running) | |
d62a17ae | 4643 | return CMD_SUCCESS; |
7c8ff89e | 4644 | |
b1c3ae8c CS |
4645 | if (uj) |
4646 | json = json_object_new_object(); | |
b5a8894d | 4647 | |
b1c3ae8c CS |
4648 | ret = show_ip_ospf_neighbor_common(vty, ospf, json, uj, 0); |
4649 | ||
4650 | if (uj) { | |
996c9314 LB |
4651 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
4652 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c CS |
4653 | json_object_free(json); |
4654 | } | |
4655 | ||
4656 | return ret; | |
7c8ff89e DS |
4657 | } |
4658 | ||
d62a17ae | 4659 | static int show_ip_ospf_neighbor_all_common(struct vty *vty, struct ospf *ospf, |
9f049418 | 4660 | json_object *json, bool use_json, |
d7c0a89a | 4661 | uint8_t use_vrf) |
d62a17ae | 4662 | { |
4663 | struct listnode *node; | |
4664 | struct ospf_interface *oi; | |
96b663a3 | 4665 | char buf[PREFIX_STRLEN]; |
b1c3ae8c | 4666 | json_object *json_vrf = NULL; |
d62a17ae | 4667 | json_object *json_neighbor_sub = NULL; |
7c8ff89e | 4668 | |
d62a17ae | 4669 | if (use_json) { |
b1c3ae8c CS |
4670 | if (use_vrf) |
4671 | json_vrf = json_object_new_object(); | |
4672 | else | |
4673 | json_vrf = json; | |
d62a17ae | 4674 | json_neighbor_sub = json_object_new_object(); |
b5a8894d | 4675 | } |
d62a17ae | 4676 | |
b1c3ae8c CS |
4677 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); |
4678 | if (!use_json) | |
4679 | show_ip_ospf_neighbour_header(vty); | |
4680 | ||
d62a17ae | 4681 | if (ospf->instance) { |
4682 | if (use_json) | |
b1c3ae8c | 4683 | json_object_int_add(json_vrf, "ospfInstance", |
d62a17ae | 4684 | ospf->instance); |
4685 | else | |
4686 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
4687 | } | |
4688 | ||
4689 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) { | |
4690 | struct listnode *nbr_node; | |
4691 | struct ospf_nbr_nbma *nbr_nbma; | |
4692 | ||
b1c3ae8c | 4693 | show_ip_ospf_neighbor_sub(vty, oi, json_vrf, use_json); |
d62a17ae | 4694 | |
4695 | /* print Down neighbor status */ | |
4696 | for (ALL_LIST_ELEMENTS_RO(oi->nbr_nbma, nbr_node, nbr_nbma)) { | |
4697 | if (nbr_nbma->nbr == NULL | |
4698 | || nbr_nbma->nbr->state == NSM_Down) { | |
4699 | if (use_json) { | |
4700 | json_object_int_add(json_neighbor_sub, | |
4701 | "nbrNbmaPriority", | |
4702 | nbr_nbma->priority); | |
4703 | json_object_boolean_true_add( | |
4704 | json_neighbor_sub, | |
4705 | "nbrNbmaDown"); | |
4706 | json_object_string_add( | |
4707 | json_neighbor_sub, | |
4708 | "nbrNbmaIfaceName", | |
4709 | IF_NAME(oi)); | |
4710 | json_object_int_add( | |
4711 | json_neighbor_sub, | |
4712 | "nbrNbmaRetransmitCounter", 0); | |
4713 | json_object_int_add( | |
4714 | json_neighbor_sub, | |
4715 | "nbrNbmaRequestCounter", 0); | |
4716 | json_object_int_add( | |
4717 | json_neighbor_sub, | |
4718 | "nbrNbmaDbSummaryCounter", 0); | |
4719 | json_object_object_add( | |
b1c3ae8c | 4720 | json_vrf, |
96b663a3 MS |
4721 | inet_ntop(AF_INET, |
4722 | &nbr_nbma->addr, buf, | |
4723 | sizeof(buf)), | |
d62a17ae | 4724 | json_neighbor_sub); |
4725 | } else { | |
4726 | vty_out(vty, "%-15s %3d %-15s %9s ", | |
4727 | "-", nbr_nbma->priority, "Down", | |
4728 | "-"); | |
4729 | vty_out(vty, | |
96b663a3 MS |
4730 | "%-32pI4 %-20s %5d %5d %5d\n", |
4731 | &nbr_nbma->addr, | |
d62a17ae | 4732 | IF_NAME(oi), 0, 0, 0); |
4733 | } | |
4734 | } | |
4735 | } | |
4736 | } | |
4737 | ||
4738 | if (use_json) { | |
b1c3ae8c CS |
4739 | if (use_vrf) { |
4740 | if (ospf->vrf_id == VRF_DEFAULT) | |
4741 | json_object_object_add(json, "default", | |
4742 | json_vrf); | |
4743 | else | |
4744 | json_object_object_add(json, ospf->name, | |
4745 | json_vrf); | |
4746 | } | |
d62a17ae | 4747 | } else |
4748 | vty_out(vty, "\n"); | |
4749 | ||
4750 | return CMD_SUCCESS; | |
718e3744 | 4751 | } |
4752 | ||
7c8ff89e DS |
4753 | DEFUN (show_ip_ospf_neighbor_all, |
4754 | show_ip_ospf_neighbor_all_cmd, | |
b5a8894d | 4755 | "show ip ospf [vrf <NAME|all>] neighbor all [json]", |
718e3744 | 4756 | SHOW_STR |
4757 | IP_STR | |
4758 | "OSPF information\n" | |
b5a8894d CS |
4759 | VRF_CMD_HELP_STR |
4760 | "All VRFs\n" | |
718e3744 | 4761 | "Neighbor list\n" |
91756b38 | 4762 | "include down status neighbor\n" |
9973d184 | 4763 | JSON_STR) |
7c8ff89e | 4764 | { |
d62a17ae | 4765 | struct ospf *ospf; |
9f049418 | 4766 | bool uj = use_json(argc, argv); |
b5a8894d CS |
4767 | struct listnode *node = NULL; |
4768 | char *vrf_name = NULL; | |
2951a7a4 | 4769 | bool all_vrf = false; |
b5a8894d CS |
4770 | int ret = CMD_SUCCESS; |
4771 | int inst = 0; | |
4772 | int idx_vrf = 0; | |
d7c0a89a | 4773 | uint8_t use_vrf = 0; |
b1c3ae8c | 4774 | json_object *json = NULL; |
7c8ff89e | 4775 | |
43b8d1d8 | 4776 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
7c8ff89e | 4777 | |
b1c3ae8c CS |
4778 | if (uj) |
4779 | json = json_object_new_object(); | |
b5a8894d CS |
4780 | |
4781 | /* vrf input is provided could be all or specific vrf*/ | |
4782 | if (vrf_name) { | |
b1c3ae8c | 4783 | use_vrf = 1; |
b5a8894d CS |
4784 | if (all_vrf) { |
4785 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
4786 | if (!ospf->oi_running) | |
4787 | continue; | |
996c9314 LB |
4788 | ret = show_ip_ospf_neighbor_all_common( |
4789 | vty, ospf, json, uj, use_vrf); | |
b1c3ae8c CS |
4790 | } |
4791 | ||
4792 | if (uj) { | |
4793 | vty_out(vty, "%s\n", | |
996c9314 LB |
4794 | json_object_to_json_string_ext( |
4795 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 4796 | json_object_free(json); |
b5a8894d | 4797 | } |
b1c3ae8c | 4798 | |
b5a8894d CS |
4799 | return ret; |
4800 | } | |
b1c3ae8c | 4801 | |
b5a8894d | 4802 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); |
b1c3ae8c CS |
4803 | if (ospf == NULL || !ospf->oi_running) { |
4804 | if (uj) | |
4805 | json_object_free(json); | |
b5a8894d | 4806 | return CMD_SUCCESS; |
b1c3ae8c | 4807 | } |
b5a8894d CS |
4808 | } else { |
4809 | /* Display default ospf (instance 0) info */ | |
4810 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
b1c3ae8c CS |
4811 | if (ospf == NULL || !ospf->oi_running) { |
4812 | if (uj) | |
4813 | json_object_free(json); | |
b5a8894d | 4814 | return CMD_SUCCESS; |
b1c3ae8c | 4815 | } |
b5a8894d CS |
4816 | } |
4817 | ||
b1c3ae8c CS |
4818 | if (ospf) { |
4819 | ret = show_ip_ospf_neighbor_all_common(vty, ospf, json, uj, | |
4820 | use_vrf); | |
4821 | if (uj) { | |
4822 | vty_out(vty, "%s\n", | |
996c9314 LB |
4823 | json_object_to_json_string_ext( |
4824 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c CS |
4825 | } |
4826 | } | |
4827 | ||
4828 | if (uj) | |
4829 | json_object_free(json); | |
b5a8894d CS |
4830 | |
4831 | return ret; | |
7c8ff89e DS |
4832 | } |
4833 | ||
4834 | DEFUN (show_ip_ospf_instance_neighbor_all, | |
4835 | show_ip_ospf_instance_neighbor_all_cmd, | |
6147e2c6 | 4836 | "show ip ospf (1-65535) neighbor all [json]", |
7c8ff89e DS |
4837 | SHOW_STR |
4838 | IP_STR | |
4839 | "OSPF information\n" | |
4840 | "Instance ID\n" | |
4841 | "Neighbor list\n" | |
91756b38 | 4842 | "include down status neighbor\n" |
9973d184 | 4843 | JSON_STR) |
718e3744 | 4844 | { |
d62a17ae | 4845 | int idx_number = 3; |
4846 | struct ospf *ospf; | |
d7c0a89a | 4847 | unsigned short instance = 0; |
9f049418 | 4848 | bool uj = use_json(argc, argv); |
b1c3ae8c CS |
4849 | json_object *json = NULL; |
4850 | int ret = CMD_SUCCESS; | |
7c8ff89e | 4851 | |
d62a17ae | 4852 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
409f98ab | 4853 | if (instance != ospf_instance) |
ac28e4ec CS |
4854 | return CMD_NOT_MY_INSTANCE; |
4855 | ||
409f98ab IR |
4856 | ospf = ospf_lookup_instance(instance); |
4857 | if (!ospf || !ospf->oi_running) | |
d62a17ae | 4858 | return CMD_SUCCESS; |
b1c3ae8c CS |
4859 | if (uj) |
4860 | json = json_object_new_object(); | |
4861 | ||
4862 | ret = show_ip_ospf_neighbor_all_common(vty, ospf, json, uj, 0); | |
4863 | ||
4864 | if (uj) { | |
4865 | vty_out(vty, "%s\n", json_object_to_json_string_ext( | |
4866 | json, JSON_C_TO_STRING_PRETTY)); | |
4867 | json_object_free(json); | |
4868 | } | |
7c8ff89e | 4869 | |
b1c3ae8c | 4870 | return ret; |
7c8ff89e DS |
4871 | } |
4872 | ||
d62a17ae | 4873 | static int show_ip_ospf_neighbor_int_common(struct vty *vty, struct ospf *ospf, |
4874 | int arg_base, | |
4875 | struct cmd_token **argv, | |
9f049418 | 4876 | bool use_json, uint8_t use_vrf) |
d62a17ae | 4877 | { |
4878 | struct interface *ifp; | |
4879 | struct route_node *rn; | |
4880 | json_object *json = NULL; | |
91756b38 | 4881 | |
d62a17ae | 4882 | if (use_json) |
4883 | json = json_object_new_object(); | |
d62a17ae | 4884 | |
4885 | if (ospf->instance) { | |
4886 | if (use_json) | |
4887 | json_object_int_add(json, "ospfInstance", | |
4888 | ospf->instance); | |
4889 | else | |
4890 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
4891 | } | |
4892 | ||
b1c3ae8c | 4893 | ospf_show_vrf_name(ospf, vty, json, use_vrf); |
87bd50e8 | 4894 | |
a36898e7 | 4895 | ifp = if_lookup_by_name(argv[arg_base]->arg, ospf->vrf_id); |
d62a17ae | 4896 | if (!ifp) { |
4897 | if (use_json) | |
4898 | json_object_boolean_true_add(json, "noSuchIface"); | |
4899 | else | |
4900 | vty_out(vty, "No such interface.\n"); | |
4901 | return CMD_WARNING; | |
4902 | } | |
4903 | ||
4904 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { | |
4905 | struct ospf_interface *oi = rn->info; | |
4906 | ||
4907 | if (oi == NULL) | |
4908 | continue; | |
4909 | ||
4910 | show_ip_ospf_neighbor_sub(vty, oi, json, use_json); | |
4911 | } | |
4912 | ||
4913 | if (use_json) { | |
9d303b37 DL |
4914 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
4915 | json, JSON_C_TO_STRING_PRETTY)); | |
d62a17ae | 4916 | json_object_free(json); |
4917 | } else | |
4918 | vty_out(vty, "\n"); | |
4919 | ||
4920 | return CMD_SUCCESS; | |
718e3744 | 4921 | } |
4922 | ||
7c8ff89e DS |
4923 | DEFUN (show_ip_ospf_neighbor_int, |
4924 | show_ip_ospf_neighbor_int_cmd, | |
03ed9f02 | 4925 | "show ip ospf [vrf <NAME>] neighbor IFNAME [json]", |
7c8ff89e DS |
4926 | SHOW_STR |
4927 | IP_STR | |
4928 | "OSPF information\n" | |
03ed9f02 | 4929 | VRF_CMD_HELP_STR |
7c8ff89e | 4930 | "Neighbor list\n" |
91756b38 | 4931 | "Interface name\n" |
9973d184 | 4932 | JSON_STR) |
7c8ff89e | 4933 | { |
d62a17ae | 4934 | struct ospf *ospf; |
03ed9f02 PG |
4935 | int idx_ifname = 0; |
4936 | int idx_vrf = 0; | |
9f049418 | 4937 | bool uj = use_json(argc, argv); |
b5a8894d CS |
4938 | int ret = CMD_SUCCESS; |
4939 | struct interface *ifp = NULL; | |
03ed9f02 PG |
4940 | char *vrf_name = NULL; |
4941 | vrf_id_t vrf_id = VRF_DEFAULT; | |
4942 | struct vrf *vrf = NULL; | |
4943 | ||
4944 | if (argv_find(argv, argc, "vrf", &idx_vrf)) | |
4945 | vrf_name = argv[idx_vrf + 1]->arg; | |
4946 | if (vrf_name && strmatch(vrf_name, VRF_DEFAULT_NAME)) | |
4947 | vrf_name = NULL; | |
4948 | if (vrf_name) { | |
4949 | vrf = vrf_lookup_by_name(vrf_name); | |
4950 | if (vrf) | |
4951 | vrf_id = vrf->vrf_id; | |
4952 | } | |
4953 | ospf = ospf_lookup_by_vrf_id(vrf_id); | |
4954 | ||
4955 | if (!ospf || !ospf->oi_running) | |
4956 | return ret; | |
7c8ff89e | 4957 | |
b5a8894d CS |
4958 | if (!uj) |
4959 | show_ip_ospf_neighbour_header(vty); | |
7c8ff89e | 4960 | |
03ed9f02 | 4961 | argv_find(argv, argc, "IFNAME", &idx_ifname); |
b5a8894d | 4962 | |
a36898e7 | 4963 | ifp = if_lookup_by_name(argv[idx_ifname]->arg, vrf_id); |
03ed9f02 PG |
4964 | if (!ifp) |
4965 | return ret; | |
4966 | ||
4967 | ret = show_ip_ospf_neighbor_int_common(vty, ospf, idx_ifname, | |
4968 | argv, uj, 0); | |
b5a8894d | 4969 | return ret; |
7c8ff89e DS |
4970 | } |
4971 | ||
4972 | DEFUN (show_ip_ospf_instance_neighbor_int, | |
4973 | show_ip_ospf_instance_neighbor_int_cmd, | |
6147e2c6 | 4974 | "show ip ospf (1-65535) neighbor IFNAME [json]", |
7c8ff89e DS |
4975 | SHOW_STR |
4976 | IP_STR | |
4977 | "OSPF information\n" | |
4978 | "Instance ID\n" | |
4979 | "Neighbor list\n" | |
91756b38 | 4980 | "Interface name\n" |
9973d184 | 4981 | JSON_STR) |
7c8ff89e | 4982 | { |
d62a17ae | 4983 | int idx_number = 3; |
b4e84315 | 4984 | int idx_ifname = 5; |
d62a17ae | 4985 | struct ospf *ospf; |
d7c0a89a | 4986 | unsigned short instance = 0; |
9f049418 | 4987 | bool uj = use_json(argc, argv); |
7c8ff89e | 4988 | |
b5a8894d CS |
4989 | if (!uj) |
4990 | show_ip_ospf_neighbour_header(vty); | |
4991 | ||
d62a17ae | 4992 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
409f98ab | 4993 | if (instance != ospf_instance) |
ac28e4ec CS |
4994 | return CMD_NOT_MY_INSTANCE; |
4995 | ||
409f98ab IR |
4996 | ospf = ospf_lookup_instance(instance); |
4997 | if (!ospf || !ospf->oi_running) | |
d62a17ae | 4998 | return CMD_SUCCESS; |
7c8ff89e | 4999 | |
b5a8894d CS |
5000 | if (!uj) |
5001 | show_ip_ospf_neighbour_header(vty); | |
5002 | ||
996c9314 LB |
5003 | return show_ip_ospf_neighbor_int_common(vty, ospf, idx_ifname, argv, uj, |
5004 | 0); | |
718e3744 | 5005 | } |
5006 | ||
d62a17ae | 5007 | static void show_ip_ospf_nbr_nbma_detail_sub(struct vty *vty, |
5008 | struct ospf_interface *oi, | |
5009 | struct ospf_nbr_nbma *nbr_nbma, | |
9f049418 | 5010 | bool use_json, json_object *json) |
d62a17ae | 5011 | { |
5012 | char timebuf[OSPF_TIME_DUMP_SIZE]; | |
96b663a3 | 5013 | char buf[PREFIX_STRLEN]; |
d62a17ae | 5014 | json_object *json_sub = NULL; |
718e3744 | 5015 | |
d62a17ae | 5016 | if (use_json) |
5017 | json_sub = json_object_new_object(); | |
5018 | else /* Show neighbor ID. */ | |
5019 | vty_out(vty, " Neighbor %s,", "-"); | |
5020 | ||
5021 | /* Show interface address. */ | |
5022 | if (use_json) | |
5023 | json_object_string_add(json_sub, "ifaceAddress", | |
96b663a3 MS |
5024 | inet_ntop(AF_INET, &nbr_nbma->addr, |
5025 | buf, sizeof(buf))); | |
d62a17ae | 5026 | else |
96b663a3 MS |
5027 | vty_out(vty, " interface address %pI4\n", |
5028 | &nbr_nbma->addr); | |
d62a17ae | 5029 | |
5030 | /* Show Area ID. */ | |
5031 | if (use_json) { | |
5032 | json_object_string_add(json_sub, "areaId", | |
5033 | ospf_area_desc_string(oi->area)); | |
5034 | json_object_string_add(json_sub, "iface", IF_NAME(oi)); | |
5035 | } else | |
5036 | vty_out(vty, " In the area %s via interface %s\n", | |
5037 | ospf_area_desc_string(oi->area), IF_NAME(oi)); | |
5038 | ||
5039 | /* Show neighbor priority and state. */ | |
5040 | if (use_json) { | |
5041 | json_object_int_add(json_sub, "nbrPriority", | |
5042 | nbr_nbma->priority); | |
5043 | json_object_string_add(json_sub, "nbrState", "down"); | |
5044 | } else | |
5045 | vty_out(vty, " Neighbor priority is %d, State is %s,", | |
5046 | nbr_nbma->priority, "Down"); | |
5047 | ||
5048 | /* Show state changes. */ | |
5049 | if (use_json) | |
5050 | json_object_int_add(json_sub, "stateChangeCounter", | |
5051 | nbr_nbma->state_change); | |
5052 | else | |
5053 | vty_out(vty, " %d state changes\n", nbr_nbma->state_change); | |
5054 | ||
5055 | /* Show PollInterval */ | |
5056 | if (use_json) | |
5057 | json_object_int_add(json_sub, "pollInterval", nbr_nbma->v_poll); | |
5058 | else | |
5059 | vty_out(vty, " Poll interval %d\n", nbr_nbma->v_poll); | |
5060 | ||
5061 | /* Show poll-interval timer. */ | |
b575a12c A |
5062 | if (nbr_nbma->t_poll) { |
5063 | if (use_json) { | |
5064 | long time_store; | |
5065 | time_store = monotime_until(&nbr_nbma->t_poll->u.sands, | |
5066 | NULL) / 1000LL; | |
5067 | json_object_int_add(json_sub, | |
5068 | "pollIntervalTimerDueMsec", | |
5069 | time_store); | |
5070 | } else | |
5071 | vty_out(vty, " Poll timer due in %s\n", | |
5072 | ospf_timer_dump(nbr_nbma->t_poll, timebuf, | |
5073 | sizeof(timebuf))); | |
5074 | } | |
d62a17ae | 5075 | |
5076 | /* Show poll-interval timer thread. */ | |
5077 | if (use_json) { | |
5078 | if (nbr_nbma->t_poll != NULL) | |
5079 | json_object_string_add(json_sub, | |
5080 | "pollIntervalTimerThread", "on"); | |
5081 | } else | |
5082 | vty_out(vty, " Thread Poll Timer %s\n", | |
5083 | nbr_nbma->t_poll != NULL ? "on" : "off"); | |
5084 | ||
5085 | if (use_json) | |
5086 | json_object_object_add(json, "noNbrId", json_sub); | |
5087 | } | |
5088 | ||
5089 | static void show_ip_ospf_neighbor_detail_sub(struct vty *vty, | |
5090 | struct ospf_interface *oi, | |
5091 | struct ospf_neighbor *nbr, | |
cb0b2ac6 | 5092 | struct ospf_neighbor *prev_nbr, |
9f049418 | 5093 | json_object *json, bool use_json) |
d62a17ae | 5094 | { |
5095 | char timebuf[OSPF_TIME_DUMP_SIZE]; | |
cb0b2ac6 CS |
5096 | json_object *json_neigh = NULL, *json_neigh_array = NULL; |
5097 | char neigh_str[INET_ADDRSTRLEN] = {0}; | |
96b663a3 | 5098 | char buf[PREFIX_STRLEN]; |
d62a17ae | 5099 | |
cb0b2ac6 CS |
5100 | if (use_json) { |
5101 | if (prev_nbr && | |
5102 | !IPV4_ADDR_SAME(&prev_nbr->src, &nbr->src)) { | |
5103 | json_neigh_array = NULL; | |
5104 | } | |
5105 | ||
975a328e DA |
5106 | if (nbr->state == NSM_Attempt |
5107 | && nbr->router_id.s_addr == INADDR_ANY) | |
cb0b2ac6 CS |
5108 | strlcpy(neigh_str, "noNbrId", sizeof(neigh_str)); |
5109 | else | |
96b663a3 MS |
5110 | inet_ntop(AF_INET, &nbr->router_id, |
5111 | neigh_str, sizeof(neigh_str)); | |
cb0b2ac6 CS |
5112 | |
5113 | json_object_object_get_ex(json, neigh_str, &json_neigh_array); | |
5114 | ||
5115 | if (!json_neigh_array) { | |
5116 | json_neigh_array = json_object_new_array(); | |
5117 | json_object_object_add(json, neigh_str, | |
5118 | json_neigh_array); | |
5119 | } | |
5120 | ||
5121 | json_neigh = json_object_new_object(); | |
5122 | ||
5123 | } else { | |
d62a17ae | 5124 | /* Show neighbor ID. */ |
975a328e DA |
5125 | if (nbr->state == NSM_Attempt |
5126 | && nbr->router_id.s_addr == INADDR_ANY) | |
d62a17ae | 5127 | vty_out(vty, " Neighbor %s,", "-"); |
5128 | else | |
96b663a3 MS |
5129 | vty_out(vty, " Neighbor %pI4,", |
5130 | &nbr->router_id); | |
d62a17ae | 5131 | } |
5132 | ||
5133 | /* Show interface address. */ | |
5134 | if (use_json) | |
cb0b2ac6 | 5135 | json_object_string_add(json_neigh, "ifaceAddress", |
96b663a3 MS |
5136 | inet_ntop(AF_INET, |
5137 | &nbr->address.u.prefix4, | |
5138 | buf, sizeof(buf))); | |
d62a17ae | 5139 | else |
96b663a3 MS |
5140 | vty_out(vty, " interface address %pI4\n", |
5141 | &nbr->address.u.prefix4); | |
d62a17ae | 5142 | |
5143 | /* Show Area ID. */ | |
5144 | if (use_json) { | |
cb0b2ac6 | 5145 | json_object_string_add(json_neigh, "areaId", |
d62a17ae | 5146 | ospf_area_desc_string(oi->area)); |
cb0b2ac6 | 5147 | json_object_string_add(json_neigh, "ifaceName", oi->ifp->name); |
d62a17ae | 5148 | } else |
5149 | vty_out(vty, " In the area %s via interface %s\n", | |
5150 | ospf_area_desc_string(oi->area), oi->ifp->name); | |
5151 | ||
5152 | /* Show neighbor priority and state. */ | |
5153 | if (use_json) { | |
cb0b2ac6 | 5154 | json_object_int_add(json_neigh, "nbrPriority", nbr->priority); |
d62a17ae | 5155 | json_object_string_add( |
cb0b2ac6 | 5156 | json_neigh, "nbrState", |
d62a17ae | 5157 | lookup_msg(ospf_nsm_state_msg, nbr->state, NULL)); |
5158 | } else | |
5159 | vty_out(vty, " Neighbor priority is %d, State is %s,", | |
5160 | nbr->priority, | |
5161 | lookup_msg(ospf_nsm_state_msg, nbr->state, NULL)); | |
5162 | ||
5163 | /* Show state changes. */ | |
5164 | if (use_json) | |
cb0b2ac6 | 5165 | json_object_int_add(json_neigh, "stateChangeCounter", |
d62a17ae | 5166 | nbr->state_change); |
5167 | else | |
5168 | vty_out(vty, " %d state changes\n", nbr->state_change); | |
5169 | ||
5170 | if (nbr->ts_last_progress.tv_sec || nbr->ts_last_progress.tv_usec) { | |
5171 | struct timeval res; | |
5172 | long time_store; | |
5173 | ||
5174 | time_store = | |
5175 | monotime_since(&nbr->ts_last_progress, &res) / 1000LL; | |
5176 | if (use_json) { | |
cb0b2ac6 | 5177 | json_object_int_add(json_neigh, "lastPrgrsvChangeMsec", |
d62a17ae | 5178 | time_store); |
5179 | } else { | |
5180 | vty_out(vty, | |
5181 | " Most recent state change statistics:\n"); | |
5182 | vty_out(vty, " Progressive change %s ago\n", | |
5183 | ospf_timeval_dump(&res, timebuf, | |
5184 | sizeof(timebuf))); | |
5185 | } | |
5186 | } | |
5187 | ||
5188 | if (nbr->ts_last_regress.tv_sec || nbr->ts_last_regress.tv_usec) { | |
5189 | struct timeval res; | |
5190 | long time_store; | |
5191 | ||
5192 | time_store = | |
5193 | monotime_since(&nbr->ts_last_regress, &res) / 1000LL; | |
5194 | if (use_json) { | |
cb0b2ac6 | 5195 | json_object_int_add(json_neigh, |
d62a17ae | 5196 | "lastRegressiveChangeMsec", |
5197 | time_store); | |
5198 | if (nbr->last_regress_str) | |
5199 | json_object_string_add( | |
cb0b2ac6 CS |
5200 | json_neigh, |
5201 | "lastRegressiveChangeReason", | |
d62a17ae | 5202 | nbr->last_regress_str); |
5203 | } else { | |
5204 | vty_out(vty, | |
5205 | " Regressive change %s ago, due to %s\n", | |
5206 | ospf_timeval_dump(&res, timebuf, | |
5207 | sizeof(timebuf)), | |
5208 | (nbr->last_regress_str ? nbr->last_regress_str | |
5209 | : "??")); | |
5210 | } | |
5211 | } | |
5212 | ||
5213 | /* Show Designated Rotuer ID. */ | |
5214 | if (use_json) | |
cb0b2ac6 | 5215 | json_object_string_add(json_neigh, "routerDesignatedId", |
96b663a3 MS |
5216 | inet_ntop(AF_INET, &nbr->d_router, |
5217 | buf, sizeof(buf))); | |
d62a17ae | 5218 | else |
96b663a3 | 5219 | vty_out(vty, " DR is %pI4,", &nbr->d_router); |
d62a17ae | 5220 | |
5221 | /* Show Backup Designated Rotuer ID. */ | |
5222 | if (use_json) | |
cb0b2ac6 | 5223 | json_object_string_add(json_neigh, "routerDesignatedBackupId", |
96b663a3 MS |
5224 | inet_ntop(AF_INET, &nbr->bd_router, |
5225 | buf, sizeof(buf))); | |
d62a17ae | 5226 | else |
96b663a3 | 5227 | vty_out(vty, " BDR is %pI4\n", &nbr->bd_router); |
d62a17ae | 5228 | |
5229 | /* Show options. */ | |
5230 | if (use_json) { | |
cb0b2ac6 CS |
5231 | json_object_int_add(json_neigh, "optionsCounter", nbr->options); |
5232 | json_object_string_add(json_neigh, "optionsList", | |
d62a17ae | 5233 | ospf_options_dump(nbr->options)); |
5234 | } else | |
5235 | vty_out(vty, " Options %d %s\n", nbr->options, | |
5236 | ospf_options_dump(nbr->options)); | |
5237 | ||
5238 | /* Show Router Dead interval timer. */ | |
5239 | if (use_json) { | |
5240 | if (nbr->t_inactivity) { | |
5241 | long time_store; | |
5242 | time_store = monotime_until(&nbr->t_inactivity->u.sands, | |
5243 | NULL) | |
5244 | / 1000LL; | |
cb0b2ac6 | 5245 | json_object_int_add(json_neigh, |
d62a17ae | 5246 | "routerDeadIntervalTimerDueMsec", |
5247 | time_store); | |
5248 | } else | |
5249 | json_object_int_add( | |
cb0b2ac6 CS |
5250 | json_neigh, |
5251 | "routerDeadIntervalTimerDueMsec", -1); | |
d62a17ae | 5252 | } else |
5253 | vty_out(vty, " Dead timer due in %s\n", | |
5254 | ospf_timer_dump(nbr->t_inactivity, timebuf, | |
5255 | sizeof(timebuf))); | |
5256 | ||
5257 | /* Show Database Summary list. */ | |
5258 | if (use_json) | |
cb0b2ac6 | 5259 | json_object_int_add(json_neigh, "databaseSummaryListCounter", |
d62a17ae | 5260 | ospf_db_summary_count(nbr)); |
5261 | else | |
5262 | vty_out(vty, " Database Summary List %d\n", | |
5263 | ospf_db_summary_count(nbr)); | |
5264 | ||
5265 | /* Show Link State Request list. */ | |
5266 | if (use_json) | |
cb0b2ac6 | 5267 | json_object_int_add(json_neigh, "linkStateRequestListCounter", |
d62a17ae | 5268 | ospf_ls_request_count(nbr)); |
5269 | else | |
5270 | vty_out(vty, " Link State Request List %ld\n", | |
5271 | ospf_ls_request_count(nbr)); | |
5272 | ||
5273 | /* Show Link State Retransmission list. */ | |
5274 | if (use_json) | |
cb0b2ac6 | 5275 | json_object_int_add(json_neigh, |
d62a17ae | 5276 | "linkStateRetransmissionListCounter", |
5277 | ospf_ls_retransmit_count(nbr)); | |
5278 | else | |
5279 | vty_out(vty, " Link State Retransmission List %ld\n", | |
5280 | ospf_ls_retransmit_count(nbr)); | |
5281 | ||
5282 | /* Show inactivity timer thread. */ | |
5283 | if (use_json) { | |
5284 | if (nbr->t_inactivity != NULL) | |
cb0b2ac6 | 5285 | json_object_string_add(json_neigh, |
d62a17ae | 5286 | "threadInactivityTimer", "on"); |
5287 | } else | |
5288 | vty_out(vty, " Thread Inactivity Timer %s\n", | |
5289 | nbr->t_inactivity != NULL ? "on" : "off"); | |
5290 | ||
5291 | /* Show Database Description retransmission thread. */ | |
5292 | if (use_json) { | |
5293 | if (nbr->t_db_desc != NULL) | |
5294 | json_object_string_add( | |
cb0b2ac6 | 5295 | json_neigh, |
d62a17ae | 5296 | "threadDatabaseDescriptionRetransmission", |
5297 | "on"); | |
5298 | } else | |
5299 | vty_out(vty, | |
5300 | " Thread Database Description Retransmision %s\n", | |
5301 | nbr->t_db_desc != NULL ? "on" : "off"); | |
5302 | ||
5303 | /* Show Link State Request Retransmission thread. */ | |
5304 | if (use_json) { | |
5305 | if (nbr->t_ls_req != NULL) | |
5306 | json_object_string_add( | |
cb0b2ac6 | 5307 | json_neigh, |
d62a17ae | 5308 | "threadLinkStateRequestRetransmission", "on"); |
5309 | } else | |
5310 | vty_out(vty, | |
5311 | " Thread Link State Request Retransmission %s\n", | |
5312 | nbr->t_ls_req != NULL ? "on" : "off"); | |
5313 | ||
5314 | /* Show Link State Update Retransmission thread. */ | |
5315 | if (use_json) { | |
5316 | if (nbr->t_ls_upd != NULL) | |
5317 | json_object_string_add( | |
cb0b2ac6 CS |
5318 | json_neigh, |
5319 | "threadLinkStateUpdateRetransmission", | |
d62a17ae | 5320 | "on"); |
5321 | } else | |
5322 | vty_out(vty, | |
5323 | " Thread Link State Update Retransmission %s\n\n", | |
5324 | nbr->t_ls_upd != NULL ? "on" : "off"); | |
5325 | ||
abd5b8c7 | 5326 | if (!use_json) { |
5327 | vty_out(vty, " Graceful restart Helper info:\n"); | |
5328 | ||
5329 | if (OSPF_GR_IS_ACTIVE_HELPER(nbr)) { | |
5330 | vty_out(vty, | |
5331 | " Graceful Restart HELPER Status : Inprogress.\n"); | |
5332 | ||
5333 | vty_out(vty, | |
5334 | " Graceful Restart grace period time: %d (seconds).\n", | |
5335 | nbr->gr_helper_info.recvd_grace_period); | |
5336 | vty_out(vty, " Graceful Restart reason: %s.\n", | |
d05d5280 MS |
5337 | ospf_restart_reason2str( |
5338 | nbr->gr_helper_info.gr_restart_reason)); | |
abd5b8c7 | 5339 | } else { |
5340 | vty_out(vty, | |
5341 | " Graceful Restart HELPER Status : None\n"); | |
5342 | } | |
5343 | ||
5344 | if (nbr->gr_helper_info.rejected_reason | |
5345 | != OSPF_HELPER_REJECTED_NONE) | |
5346 | vty_out(vty, " Helper rejected reason: %s.\n", | |
d05d5280 MS |
5347 | ospf_rejected_reason2str( |
5348 | nbr->gr_helper_info.rejected_reason)); | |
abd5b8c7 | 5349 | |
5350 | if (nbr->gr_helper_info.helper_exit_reason | |
5351 | != OSPF_GR_HELPER_EXIT_NONE) | |
5352 | vty_out(vty, " Last helper exit reason: %s.\n\n", | |
d05d5280 MS |
5353 | ospf_exit_reason2str( |
5354 | nbr->gr_helper_info.helper_exit_reason)); | |
abd5b8c7 | 5355 | else |
5356 | vty_out(vty, "\n"); | |
5357 | } else { | |
5358 | json_object_string_add(json_neigh, "grHelperStatus", | |
5359 | OSPF_GR_IS_ACTIVE_HELPER(nbr) ? | |
5360 | "Inprogress" | |
5361 | : "None"); | |
5362 | if (OSPF_GR_IS_ACTIVE_HELPER(nbr)) { | |
5363 | json_object_int_add( | |
5364 | json_neigh, "graceInterval", | |
5365 | nbr->gr_helper_info.recvd_grace_period); | |
5366 | json_object_string_add( | |
5367 | json_neigh, "grRestartReason", | |
d05d5280 MS |
5368 | ospf_restart_reason2str( |
5369 | nbr->gr_helper_info.gr_restart_reason)); | |
abd5b8c7 | 5370 | } |
5371 | ||
5372 | if (nbr->gr_helper_info.rejected_reason | |
5373 | != OSPF_HELPER_REJECTED_NONE) | |
5374 | json_object_string_add( | |
5375 | json_neigh, "helperRejectReason", | |
d05d5280 MS |
5376 | ospf_rejected_reason2str( |
5377 | nbr->gr_helper_info.rejected_reason)); | |
abd5b8c7 | 5378 | |
5379 | if (nbr->gr_helper_info.helper_exit_reason | |
5380 | != OSPF_GR_HELPER_EXIT_NONE) | |
5381 | json_object_string_add( | |
5382 | json_neigh, "helperExitReason", | |
d05d5280 MS |
5383 | ospf_exit_reason2str( |
5384 | nbr->gr_helper_info | |
5385 | .helper_exit_reason)); | |
abd5b8c7 | 5386 | } |
5387 | ||
659f4e40 | 5388 | bfd_sess_show(vty, json_neigh, nbr->bfd_session); |
cb0b2ac6 CS |
5389 | |
5390 | if (use_json) | |
5391 | json_object_array_add(json_neigh_array, json_neigh); | |
d62a17ae | 5392 | |
d62a17ae | 5393 | } |
5394 | ||
5395 | static int show_ip_ospf_neighbor_id_common(struct vty *vty, struct ospf *ospf, | |
986b87cb | 5396 | struct in_addr *router_id, |
9f049418 | 5397 | bool use_json, uint8_t use_vrf) |
d62a17ae | 5398 | { |
5399 | struct listnode *node; | |
5400 | struct ospf_neighbor *nbr; | |
5401 | struct ospf_interface *oi; | |
d62a17ae | 5402 | json_object *json = NULL; |
5403 | ||
5404 | if (use_json) | |
5405 | json = json_object_new_object(); | |
5406 | ||
5407 | if (ospf->instance) { | |
5408 | if (use_json) | |
5409 | json_object_int_add(json, "ospfInstance", | |
5410 | ospf->instance); | |
5411 | else | |
5412 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
5413 | } | |
5414 | ||
b1c3ae8c | 5415 | ospf_show_vrf_name(ospf, vty, json, use_vrf); |
87bd50e8 | 5416 | |
d62a17ae | 5417 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) { |
986b87cb | 5418 | if ((nbr = ospf_nbr_lookup_by_routerid(oi->nbrs, router_id))) { |
cb0b2ac6 CS |
5419 | show_ip_ospf_neighbor_detail_sub(vty, oi, nbr, NULL, |
5420 | json, use_json); | |
d62a17ae | 5421 | } |
5422 | } | |
5423 | ||
5424 | if (use_json) { | |
9d303b37 DL |
5425 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
5426 | json, JSON_C_TO_STRING_PRETTY)); | |
d62a17ae | 5427 | json_object_free(json); |
5428 | } else | |
5429 | vty_out(vty, "\n"); | |
5430 | ||
5431 | return CMD_SUCCESS; | |
718e3744 | 5432 | } |
5433 | ||
986b87cb | 5434 | DEFPY (show_ip_ospf_neighbor_id, |
7c8ff89e | 5435 | show_ip_ospf_neighbor_id_cmd, |
986b87cb | 5436 | "show ip ospf neighbor A.B.C.D$router_id [json$json]", |
718e3744 | 5437 | SHOW_STR |
5438 | IP_STR | |
5439 | "OSPF information\n" | |
5440 | "Neighbor list\n" | |
3ac237f8 | 5441 | "Neighbor ID\n" |
9973d184 | 5442 | JSON_STR) |
718e3744 | 5443 | { |
d62a17ae | 5444 | struct ospf *ospf; |
986b87cb | 5445 | struct listnode *node; |
b5a8894d | 5446 | int ret = CMD_SUCCESS; |
7c8ff89e | 5447 | |
b5a8894d CS |
5448 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { |
5449 | if (!ospf->oi_running) | |
5450 | continue; | |
986b87cb RW |
5451 | ret = show_ip_ospf_neighbor_id_common(vty, ospf, &router_id, |
5452 | !!json, 0); | |
b5a8894d | 5453 | } |
7c8ff89e | 5454 | |
b5a8894d | 5455 | return ret; |
7c8ff89e DS |
5456 | } |
5457 | ||
986b87cb | 5458 | DEFPY (show_ip_ospf_instance_neighbor_id, |
7c8ff89e | 5459 | show_ip_ospf_instance_neighbor_id_cmd, |
986b87cb | 5460 | "show ip ospf (1-65535)$instance neighbor A.B.C.D$router_id [json$json]", |
7c8ff89e DS |
5461 | SHOW_STR |
5462 | IP_STR | |
5463 | "OSPF information\n" | |
5464 | "Instance ID\n" | |
5465 | "Neighbor list\n" | |
3ac237f8 | 5466 | "Neighbor ID\n" |
9973d184 | 5467 | JSON_STR) |
7c8ff89e | 5468 | { |
d62a17ae | 5469 | struct ospf *ospf; |
7c8ff89e | 5470 | |
409f98ab | 5471 | if (instance != ospf_instance) |
ac28e4ec CS |
5472 | return CMD_NOT_MY_INSTANCE; |
5473 | ||
409f98ab IR |
5474 | ospf = ospf_lookup_instance(instance); |
5475 | if (!ospf || !ospf->oi_running) | |
d62a17ae | 5476 | return CMD_SUCCESS; |
7c8ff89e | 5477 | |
986b87cb RW |
5478 | return show_ip_ospf_neighbor_id_common(vty, ospf, &router_id, !!json, |
5479 | 0); | |
7c8ff89e DS |
5480 | } |
5481 | ||
d62a17ae | 5482 | static int show_ip_ospf_neighbor_detail_common(struct vty *vty, |
5483 | struct ospf *ospf, | |
9f049418 | 5484 | json_object *json, bool use_json, |
d7c0a89a | 5485 | uint8_t use_vrf) |
d62a17ae | 5486 | { |
5487 | struct ospf_interface *oi; | |
5488 | struct listnode *node; | |
b1c3ae8c | 5489 | json_object *json_vrf = NULL; |
cb0b2ac6 | 5490 | json_object *json_nbr_sub = NULL; |
d62a17ae | 5491 | |
b1c3ae8c CS |
5492 | if (use_json) { |
5493 | if (use_vrf) | |
5494 | json_vrf = json_object_new_object(); | |
5495 | else | |
5496 | json_vrf = json; | |
cb0b2ac6 CS |
5497 | |
5498 | json_nbr_sub = json_object_new_object(); | |
b1c3ae8c | 5499 | } |
cb0b2ac6 | 5500 | |
d62a17ae | 5501 | if (ospf->instance) { |
5502 | if (use_json) | |
cb0b2ac6 | 5503 | json_object_int_add(json, "ospfInstance", |
d62a17ae | 5504 | ospf->instance); |
5505 | else | |
5506 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
5507 | } | |
5508 | ||
b1c3ae8c | 5509 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); |
87bd50e8 | 5510 | |
d62a17ae | 5511 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) { |
5512 | struct route_node *rn; | |
cb0b2ac6 | 5513 | struct ospf_neighbor *nbr, *prev_nbr = NULL; |
d62a17ae | 5514 | |
5515 | for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) { | |
5516 | if ((nbr = rn->info)) { | |
5517 | if (nbr != oi->nbr_self) { | |
5518 | if (nbr->state != NSM_Down) { | |
5519 | show_ip_ospf_neighbor_detail_sub( | |
cb0b2ac6 CS |
5520 | vty, oi, nbr, prev_nbr, |
5521 | json_nbr_sub, use_json); | |
d62a17ae | 5522 | } |
5523 | } | |
cb0b2ac6 | 5524 | prev_nbr = nbr; |
d62a17ae | 5525 | } |
5526 | } | |
5527 | } | |
5528 | ||
5529 | if (use_json) { | |
cb0b2ac6 CS |
5530 | json_object_object_add(json_vrf, "neighbors", |
5531 | json_nbr_sub); | |
b1c3ae8c CS |
5532 | if (use_vrf) { |
5533 | if (ospf->vrf_id == VRF_DEFAULT) | |
5534 | json_object_object_add(json, "default", | |
5535 | json_vrf); | |
5536 | else | |
5537 | json_object_object_add(json, ospf->name, | |
5538 | json_vrf); | |
5539 | } | |
d62a17ae | 5540 | } else |
5541 | vty_out(vty, "\n"); | |
5542 | ||
5543 | return CMD_SUCCESS; | |
718e3744 | 5544 | } |
5545 | ||
7c8ff89e DS |
5546 | DEFUN (show_ip_ospf_neighbor_detail, |
5547 | show_ip_ospf_neighbor_detail_cmd, | |
b5a8894d | 5548 | "show ip ospf [vrf <NAME|all>] neighbor detail [json]", |
718e3744 | 5549 | SHOW_STR |
5550 | IP_STR | |
5551 | "OSPF information\n" | |
b5a8894d CS |
5552 | VRF_CMD_HELP_STR |
5553 | "All VRFs\n" | |
718e3744 | 5554 | "Neighbor list\n" |
3ac237f8 | 5555 | "detail of all neighbors\n" |
9973d184 | 5556 | JSON_STR) |
718e3744 | 5557 | { |
d62a17ae | 5558 | struct ospf *ospf; |
9f049418 | 5559 | bool uj = use_json(argc, argv); |
b5a8894d CS |
5560 | struct listnode *node = NULL; |
5561 | char *vrf_name = NULL; | |
2951a7a4 | 5562 | bool all_vrf = false; |
b5a8894d CS |
5563 | int ret = CMD_SUCCESS; |
5564 | int inst = 0; | |
5565 | int idx_vrf = 0; | |
d7c0a89a | 5566 | uint8_t use_vrf = 0; |
b1c3ae8c | 5567 | json_object *json = NULL; |
7c8ff89e | 5568 | |
43b8d1d8 | 5569 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
7c8ff89e | 5570 | |
b1c3ae8c CS |
5571 | if (uj) |
5572 | json = json_object_new_object(); | |
5573 | ||
b5a8894d CS |
5574 | /* vrf input is provided could be all or specific vrf*/ |
5575 | if (vrf_name) { | |
b1c3ae8c | 5576 | use_vrf = 1; |
b5a8894d CS |
5577 | if (all_vrf) { |
5578 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
5579 | if (!ospf->oi_running) | |
5580 | continue; | |
996c9314 LB |
5581 | ret = show_ip_ospf_neighbor_detail_common( |
5582 | vty, ospf, json, uj, use_vrf); | |
b1c3ae8c CS |
5583 | } |
5584 | if (uj) { | |
5585 | vty_out(vty, "%s\n", | |
996c9314 LB |
5586 | json_object_to_json_string_ext( |
5587 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 5588 | json_object_free(json); |
b5a8894d | 5589 | } |
b1c3ae8c | 5590 | |
b5a8894d CS |
5591 | return ret; |
5592 | } | |
5593 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
b1c3ae8c CS |
5594 | if (ospf == NULL || !ospf->oi_running) { |
5595 | if (uj) | |
5596 | json_object_free(json); | |
b5a8894d | 5597 | return CMD_SUCCESS; |
b1c3ae8c | 5598 | } |
b5a8894d CS |
5599 | } else { |
5600 | /* Display default ospf (instance 0) info */ | |
5601 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
b1c3ae8c CS |
5602 | if (ospf == NULL || !ospf->oi_running) { |
5603 | if (uj) | |
5604 | json_object_free(json); | |
b5a8894d | 5605 | return CMD_SUCCESS; |
b1c3ae8c | 5606 | } |
b5a8894d CS |
5607 | } |
5608 | ||
b1c3ae8c CS |
5609 | if (ospf) { |
5610 | ret = show_ip_ospf_neighbor_detail_common(vty, ospf, json, uj, | |
5611 | use_vrf); | |
5612 | if (uj) { | |
5613 | vty_out(vty, "%s\n", | |
996c9314 LB |
5614 | json_object_to_json_string_ext( |
5615 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c CS |
5616 | } |
5617 | } | |
5618 | ||
5619 | if (uj) | |
5620 | json_object_free(json); | |
b5a8894d CS |
5621 | |
5622 | return ret; | |
7c8ff89e DS |
5623 | } |
5624 | ||
5625 | DEFUN (show_ip_ospf_instance_neighbor_detail, | |
5626 | show_ip_ospf_instance_neighbor_detail_cmd, | |
6147e2c6 | 5627 | "show ip ospf (1-65535) neighbor detail [json]", |
7c8ff89e DS |
5628 | SHOW_STR |
5629 | IP_STR | |
5630 | "OSPF information\n" | |
5631 | "Instance ID\n" | |
5632 | "Neighbor list\n" | |
3ac237f8 | 5633 | "detail of all neighbors\n" |
9973d184 | 5634 | JSON_STR) |
7c8ff89e | 5635 | { |
d62a17ae | 5636 | int idx_number = 3; |
5637 | struct ospf *ospf; | |
d7c0a89a | 5638 | unsigned short instance = 0; |
9f049418 | 5639 | bool uj = use_json(argc, argv); |
b1c3ae8c CS |
5640 | json_object *json = NULL; |
5641 | int ret = CMD_SUCCESS; | |
7c8ff89e | 5642 | |
d62a17ae | 5643 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
409f98ab | 5644 | if (instance != ospf_instance) |
ac28e4ec CS |
5645 | return CMD_NOT_MY_INSTANCE; |
5646 | ||
409f98ab IR |
5647 | ospf = ospf_lookup_instance(instance); |
5648 | if (!ospf || !ospf->oi_running) | |
d62a17ae | 5649 | return CMD_SUCCESS; |
7c8ff89e | 5650 | |
b1c3ae8c CS |
5651 | if (uj) |
5652 | json = json_object_new_object(); | |
5653 | ||
5654 | ret = show_ip_ospf_neighbor_detail_common(vty, ospf, json, uj, 0); | |
5655 | ||
5656 | if (uj) { | |
5657 | vty_out(vty, "%s\n", json_object_to_json_string_ext( | |
5658 | json, JSON_C_TO_STRING_PRETTY)); | |
5659 | json_object_free(json); | |
5660 | } | |
5661 | ||
5662 | return ret; | |
7c8ff89e DS |
5663 | } |
5664 | ||
d62a17ae | 5665 | static int show_ip_ospf_neighbor_detail_all_common(struct vty *vty, |
5666 | struct ospf *ospf, | |
b1c3ae8c | 5667 | json_object *json, |
9f049418 | 5668 | bool use_json, |
d7c0a89a | 5669 | uint8_t use_vrf) |
d62a17ae | 5670 | { |
5671 | struct listnode *node; | |
5672 | struct ospf_interface *oi; | |
b1c3ae8c | 5673 | json_object *json_vrf = NULL; |
718e3744 | 5674 | |
b1c3ae8c CS |
5675 | if (use_json) { |
5676 | if (use_vrf) | |
5677 | json_vrf = json_object_new_object(); | |
5678 | else | |
5679 | json_vrf = json; | |
5680 | } | |
d62a17ae | 5681 | |
5682 | if (ospf->instance) { | |
5683 | if (use_json) | |
5684 | json_object_int_add(json, "ospfInstance", | |
5685 | ospf->instance); | |
5686 | else | |
5687 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
5688 | } | |
5689 | ||
b1c3ae8c | 5690 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); |
87bd50e8 | 5691 | |
d62a17ae | 5692 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) { |
5693 | struct route_node *rn; | |
cb0b2ac6 | 5694 | struct ospf_neighbor *nbr, *prev_nbr = NULL; |
d62a17ae | 5695 | struct ospf_nbr_nbma *nbr_nbma; |
5696 | ||
cb0b2ac6 CS |
5697 | for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) { |
5698 | if ((nbr = rn->info)) { | |
d62a17ae | 5699 | if (nbr != oi->nbr_self) |
5700 | if (nbr->state != NSM_Down) | |
5701 | show_ip_ospf_neighbor_detail_sub( | |
5702 | vty, oi, rn->info, | |
cb0b2ac6 | 5703 | prev_nbr, |
b1c3ae8c | 5704 | json_vrf, use_json); |
cb0b2ac6 CS |
5705 | prev_nbr = nbr; |
5706 | } | |
5707 | } | |
d62a17ae | 5708 | |
5709 | if (oi->type == OSPF_IFTYPE_NBMA) { | |
5710 | struct listnode *nd; | |
5711 | ||
5712 | for (ALL_LIST_ELEMENTS_RO(oi->nbr_nbma, nd, nbr_nbma)) { | |
5713 | if (nbr_nbma->nbr == NULL | |
5714 | || nbr_nbma->nbr->state == NSM_Down) | |
5715 | show_ip_ospf_nbr_nbma_detail_sub( | |
5716 | vty, oi, nbr_nbma, use_json, | |
b1c3ae8c | 5717 | json_vrf); |
d62a17ae | 5718 | } |
5719 | } | |
5720 | } | |
5721 | ||
5722 | if (use_json) { | |
b1c3ae8c CS |
5723 | if (use_vrf) { |
5724 | if (ospf->vrf_id == VRF_DEFAULT) | |
5725 | json_object_object_add(json, "default", | |
5726 | json_vrf); | |
5727 | else | |
5728 | json_object_object_add(json, ospf->name, | |
5729 | json_vrf); | |
5730 | } | |
d62a17ae | 5731 | } else { |
5732 | vty_out(vty, "\n"); | |
5733 | } | |
5734 | ||
5735 | return CMD_SUCCESS; | |
718e3744 | 5736 | } |
5737 | ||
7c8ff89e DS |
5738 | DEFUN (show_ip_ospf_neighbor_detail_all, |
5739 | show_ip_ospf_neighbor_detail_all_cmd, | |
b5a8894d | 5740 | "show ip ospf [vrf <NAME|all>] neighbor detail all [json]", |
718e3744 | 5741 | SHOW_STR |
5742 | IP_STR | |
5743 | "OSPF information\n" | |
b5a8894d CS |
5744 | VRF_CMD_HELP_STR |
5745 | "All VRFs\n" | |
718e3744 | 5746 | "Neighbor list\n" |
7c8ff89e | 5747 | "detail of all neighbors\n" |
3ac237f8 | 5748 | "include down status neighbor\n" |
9973d184 | 5749 | JSON_STR) |
718e3744 | 5750 | { |
d62a17ae | 5751 | struct ospf *ospf; |
9f049418 | 5752 | bool uj = use_json(argc, argv); |
b5a8894d CS |
5753 | struct listnode *node = NULL; |
5754 | char *vrf_name = NULL; | |
2951a7a4 | 5755 | bool all_vrf = false; |
b5a8894d CS |
5756 | int ret = CMD_SUCCESS; |
5757 | int inst = 0; | |
5758 | int idx_vrf = 0; | |
d7c0a89a | 5759 | uint8_t use_vrf = 0; |
b1c3ae8c | 5760 | json_object *json = NULL; |
7c8ff89e | 5761 | |
43b8d1d8 | 5762 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
7c8ff89e | 5763 | |
b1c3ae8c CS |
5764 | if (uj) |
5765 | json = json_object_new_object(); | |
5766 | ||
b5a8894d CS |
5767 | /* vrf input is provided could be all or specific vrf*/ |
5768 | if (vrf_name) { | |
b1c3ae8c | 5769 | use_vrf = 1; |
b5a8894d CS |
5770 | if (all_vrf) { |
5771 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
5772 | if (!ospf->oi_running) | |
5773 | continue; | |
996c9314 LB |
5774 | ret = show_ip_ospf_neighbor_detail_all_common( |
5775 | vty, ospf, json, uj, use_vrf); | |
b5a8894d | 5776 | } |
b1c3ae8c CS |
5777 | |
5778 | if (uj) { | |
5779 | vty_out(vty, "%s\n", | |
996c9314 LB |
5780 | json_object_to_json_string_ext( |
5781 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c CS |
5782 | json_object_free(json); |
5783 | } | |
5784 | ||
b5a8894d CS |
5785 | return ret; |
5786 | } | |
5787 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
b1c3ae8c CS |
5788 | if (ospf == NULL || !ospf->oi_running) { |
5789 | if (uj) | |
5790 | json_object_free(json); | |
b5a8894d | 5791 | return CMD_SUCCESS; |
b1c3ae8c | 5792 | } |
b5a8894d CS |
5793 | } else { |
5794 | /* Display default ospf (instance 0) info */ | |
5795 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
b1c3ae8c CS |
5796 | if (ospf == NULL || !ospf->oi_running) { |
5797 | if (uj) | |
5798 | json_object_free(json); | |
b5a8894d | 5799 | return CMD_SUCCESS; |
b1c3ae8c | 5800 | } |
b5a8894d CS |
5801 | } |
5802 | ||
b1c3ae8c CS |
5803 | if (ospf) { |
5804 | ret = show_ip_ospf_neighbor_detail_all_common(vty, ospf, json, | |
5805 | uj, use_vrf); | |
5806 | if (uj) { | |
5807 | vty_out(vty, "%s\n", | |
996c9314 LB |
5808 | json_object_to_json_string_ext( |
5809 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c CS |
5810 | } |
5811 | } | |
5812 | ||
5813 | if (uj) | |
5814 | json_object_free(json); | |
b5a8894d CS |
5815 | |
5816 | return ret; | |
7c8ff89e DS |
5817 | } |
5818 | ||
5819 | DEFUN (show_ip_ospf_instance_neighbor_detail_all, | |
5820 | show_ip_ospf_instance_neighbor_detail_all_cmd, | |
6147e2c6 | 5821 | "show ip ospf (1-65535) neighbor detail all [json]", |
7c8ff89e DS |
5822 | SHOW_STR |
5823 | IP_STR | |
5824 | "OSPF information\n" | |
5825 | "Instance ID\n" | |
5826 | "Neighbor list\n" | |
5827 | "detail of all neighbors\n" | |
3ac237f8 | 5828 | "include down status neighbor\n" |
9973d184 | 5829 | JSON_STR) |
7c8ff89e | 5830 | { |
d62a17ae | 5831 | int idx_number = 3; |
5832 | struct ospf *ospf; | |
d7c0a89a | 5833 | unsigned short instance = 0; |
9f049418 | 5834 | bool uj = use_json(argc, argv); |
b1c3ae8c CS |
5835 | json_object *json = NULL; |
5836 | int ret = CMD_SUCCESS; | |
7c8ff89e | 5837 | |
d62a17ae | 5838 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
409f98ab | 5839 | if (instance != ospf_instance) |
ac28e4ec CS |
5840 | return CMD_NOT_MY_INSTANCE; |
5841 | ||
409f98ab IR |
5842 | ospf = ospf_lookup_instance(instance); |
5843 | if (!ospf || !ospf->oi_running) | |
d62a17ae | 5844 | return CMD_SUCCESS; |
7c8ff89e | 5845 | |
b1c3ae8c CS |
5846 | if (uj) |
5847 | json = json_object_new_object(); | |
5848 | ||
5849 | ret = show_ip_ospf_neighbor_detail_all_common(vty, ospf, json, uj, 0); | |
5850 | ||
5851 | if (uj) { | |
996c9314 LB |
5852 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
5853 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c CS |
5854 | json_object_free(json); |
5855 | } | |
5856 | ||
5857 | return ret; | |
7c8ff89e DS |
5858 | } |
5859 | ||
d62a17ae | 5860 | static int show_ip_ospf_neighbor_int_detail_common(struct vty *vty, |
5861 | struct ospf *ospf, | |
5862 | int arg_base, | |
5863 | struct cmd_token **argv, | |
9f049418 | 5864 | bool use_json) |
d62a17ae | 5865 | { |
5866 | struct ospf_interface *oi; | |
5867 | struct interface *ifp; | |
5868 | struct route_node *rn, *nrn; | |
5869 | struct ospf_neighbor *nbr; | |
5870 | json_object *json = NULL; | |
718e3744 | 5871 | |
d62a17ae | 5872 | if (use_json) |
5873 | json = json_object_new_object(); | |
5874 | ||
5875 | if (ospf->instance) { | |
5876 | if (use_json) | |
5877 | json_object_int_add(json, "ospfInstance", | |
5878 | ospf->instance); | |
5879 | else | |
5880 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
5881 | } | |
5882 | ||
a36898e7 | 5883 | ifp = if_lookup_by_name(argv[arg_base]->arg, ospf->vrf_id); |
d62a17ae | 5884 | if (!ifp) { |
5885 | if (!use_json) | |
5886 | vty_out(vty, "No such interface.\n"); | |
16307668 RW |
5887 | else { |
5888 | vty_out(vty, "{}\n"); | |
5889 | json_object_free(json); | |
5890 | } | |
d62a17ae | 5891 | return CMD_WARNING; |
5892 | } | |
5893 | ||
5894 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { | |
5895 | if ((oi = rn->info)) { | |
5896 | for (nrn = route_top(oi->nbrs); nrn; | |
5897 | nrn = route_next(nrn)) { | |
5898 | if ((nbr = nrn->info)) { | |
5899 | if (nbr != oi->nbr_self) { | |
5900 | if (nbr->state != NSM_Down) | |
5901 | show_ip_ospf_neighbor_detail_sub( | |
5902 | vty, oi, nbr, | |
cb0b2ac6 | 5903 | NULL, |
b1c3ae8c | 5904 | json, use_json); |
d62a17ae | 5905 | } |
5906 | } | |
5907 | } | |
5908 | } | |
5909 | } | |
5910 | ||
5911 | if (use_json) { | |
9d303b37 DL |
5912 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
5913 | json, JSON_C_TO_STRING_PRETTY)); | |
d62a17ae | 5914 | json_object_free(json); |
5915 | } else | |
5916 | vty_out(vty, "\n"); | |
5917 | ||
5918 | return CMD_SUCCESS; | |
718e3744 | 5919 | } |
5920 | ||
7c8ff89e DS |
5921 | DEFUN (show_ip_ospf_neighbor_int_detail, |
5922 | show_ip_ospf_neighbor_int_detail_cmd, | |
b162fa78 | 5923 | "show ip ospf neighbor IFNAME detail [json]", |
7c8ff89e DS |
5924 | SHOW_STR |
5925 | IP_STR | |
5926 | "OSPF information\n" | |
5927 | "Neighbor list\n" | |
5928 | "Interface name\n" | |
3ac237f8 | 5929 | "detail of all neighbors\n" |
9973d184 | 5930 | JSON_STR) |
7c8ff89e | 5931 | { |
d62a17ae | 5932 | struct ospf *ospf; |
9f049418 | 5933 | bool uj = use_json(argc, argv); |
b5a8894d CS |
5934 | struct listnode *node = NULL; |
5935 | int ret = CMD_SUCCESS; | |
2951a7a4 | 5936 | bool ospf_output = false; |
7c8ff89e | 5937 | |
b5a8894d CS |
5938 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { |
5939 | if (!ospf->oi_running) | |
5940 | continue; | |
2951a7a4 | 5941 | ospf_output = true; |
cb0b2ac6 | 5942 | ret = show_ip_ospf_neighbor_int_detail_common(vty, ospf, 4, |
b5a8894d CS |
5943 | argv, uj); |
5944 | } | |
7c8ff89e | 5945 | |
9f049418 DS |
5946 | if (!ospf_output) |
5947 | vty_out(vty, "%% OSPF instance not found\n"); | |
5948 | ||
b5a8894d | 5949 | return ret; |
7c8ff89e DS |
5950 | } |
5951 | ||
5952 | DEFUN (show_ip_ospf_instance_neighbor_int_detail, | |
5953 | show_ip_ospf_instance_neighbor_int_detail_cmd, | |
6147e2c6 | 5954 | "show ip ospf (1-65535) neighbor IFNAME detail [json]", |
7c8ff89e DS |
5955 | SHOW_STR |
5956 | IP_STR | |
5957 | "OSPF information\n" | |
5958 | "Instance ID\n" | |
5959 | "Neighbor list\n" | |
5960 | "Interface name\n" | |
3ac237f8 | 5961 | "detail of all neighbors\n" |
9973d184 | 5962 | JSON_STR) |
7c8ff89e | 5963 | { |
d62a17ae | 5964 | int idx_number = 3; |
b4e84315 | 5965 | int idx_ifname = 5; |
d62a17ae | 5966 | struct ospf *ospf; |
d7c0a89a | 5967 | unsigned short instance = 0; |
9f049418 | 5968 | bool uj = use_json(argc, argv); |
7c8ff89e | 5969 | |
d62a17ae | 5970 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
409f98ab | 5971 | if (instance != ospf_instance) |
ac28e4ec CS |
5972 | return CMD_NOT_MY_INSTANCE; |
5973 | ||
409f98ab IR |
5974 | ospf = ospf_lookup_instance(instance); |
5975 | if (!ospf || !ospf->oi_running) | |
d62a17ae | 5976 | return CMD_SUCCESS; |
7c8ff89e | 5977 | |
996c9314 LB |
5978 | return show_ip_ospf_neighbor_int_detail_common(vty, ospf, idx_ifname, |
5979 | argv, uj); | |
7c8ff89e | 5980 | } |
6b0655a2 | 5981 | |
718e3744 | 5982 | /* Show functions */ |
f328dc60 | 5983 | static int show_lsa_summary(struct vty *vty, struct ospf_lsa *lsa, int self, |
5984 | json_object *json_lsa) | |
d62a17ae | 5985 | { |
5986 | struct router_lsa *rl; | |
5987 | struct summary_lsa *sl; | |
5988 | struct as_external_lsa *asel; | |
5989 | struct prefix_ipv4 p; | |
f328dc60 | 5990 | char buf[PREFIX2STR_BUFFER]; |
d62a17ae | 5991 | |
5992 | if (lsa != NULL) | |
5993 | /* If self option is set, check LSA self flag. */ | |
5994 | if (self == 0 || IS_LSA_SELF(lsa)) { | |
f328dc60 | 5995 | |
5996 | if (!json_lsa) { | |
5997 | /* LSA common part show. */ | |
5998 | vty_out(vty, "%-15pI4", | |
5999 | &lsa->data->id); | |
ce513ac6 MS |
6000 | vty_out(vty, "%-15pI4 %4d 0x%08lx 0x%04x", |
6001 | &lsa->data->adv_router, LS_AGE(lsa), | |
f328dc60 | 6002 | (unsigned long)ntohl( |
6003 | lsa->data->ls_seqnum), | |
6004 | ntohs(lsa->data->checksum)); | |
6005 | } else { | |
6006 | char seqnum[10]; | |
6007 | char checksum[10]; | |
6008 | ||
6009 | snprintf(seqnum, sizeof(seqnum), "%x", | |
6010 | ntohl(lsa->data->ls_seqnum)); | |
6011 | snprintf(checksum, sizeof(checksum), "%x", | |
6012 | ntohs(lsa->data->checksum)); | |
6013 | json_object_string_add( | |
6014 | json_lsa, "lsId", | |
ce513ac6 MS |
6015 | inet_ntop(AF_INET, &lsa->data->id, |
6016 | buf, sizeof(buf))); | |
f328dc60 | 6017 | json_object_string_add( |
6018 | json_lsa, "advertisedRouter", | |
ce513ac6 MS |
6019 | inet_ntop(AF_INET, |
6020 | &lsa->data->adv_router, | |
6021 | buf, sizeof(buf))); | |
f328dc60 | 6022 | json_object_int_add(json_lsa, "lsaAge", |
6023 | LS_AGE(lsa)); | |
6024 | json_object_string_add( | |
6025 | json_lsa, "sequenceNumber", seqnum); | |
6026 | json_object_string_add(json_lsa, "checksum", | |
6027 | checksum); | |
6028 | } | |
6029 | ||
d62a17ae | 6030 | /* LSA specific part show. */ |
6031 | switch (lsa->data->type) { | |
6032 | case OSPF_ROUTER_LSA: | |
6033 | rl = (struct router_lsa *)lsa->data; | |
f328dc60 | 6034 | |
6035 | if (!json_lsa) | |
6036 | vty_out(vty, " %-d", ntohs(rl->links)); | |
6037 | else | |
6038 | json_object_int_add(json_lsa, | |
6039 | "numOfRouterLinks", | |
6040 | ntohs(rl->links)); | |
d62a17ae | 6041 | break; |
6042 | case OSPF_SUMMARY_LSA: | |
6043 | sl = (struct summary_lsa *)lsa->data; | |
6044 | ||
6045 | p.family = AF_INET; | |
6046 | p.prefix = sl->header.id; | |
6047 | p.prefixlen = ip_masklen(sl->mask); | |
6048 | apply_mask_ipv4(&p); | |
6049 | ||
f328dc60 | 6050 | if (!json_lsa) |
6051 | vty_out(vty, " %pFX", &p); | |
6052 | else { | |
6053 | prefix2str(&p, buf, sizeof(buf)); | |
6054 | json_object_string_add(json_lsa, | |
6055 | "summaryAddress", | |
6056 | buf); | |
6057 | } | |
d62a17ae | 6058 | break; |
6059 | case OSPF_AS_EXTERNAL_LSA: | |
6060 | case OSPF_AS_NSSA_LSA: | |
6061 | asel = (struct as_external_lsa *)lsa->data; | |
6062 | ||
6063 | p.family = AF_INET; | |
6064 | p.prefix = asel->header.id; | |
6065 | p.prefixlen = ip_masklen(asel->mask); | |
6066 | apply_mask_ipv4(&p); | |
6067 | ||
f328dc60 | 6068 | if (!json_lsa) |
6069 | vty_out(vty, " %s %pFX [0x%lx]", | |
6070 | IS_EXTERNAL_METRIC( | |
6071 | asel->e[0].tos) | |
6072 | ? "E2" | |
6073 | : "E1", | |
6074 | &p, | |
6075 | (unsigned long)ntohl( | |
6076 | asel->e[0].route_tag)); | |
6077 | else { | |
6078 | prefix2str(&p, buf, sizeof(buf)); | |
6079 | json_object_string_add( | |
6080 | json_lsa, "metricType", | |
6081 | IS_EXTERNAL_METRIC( | |
6082 | asel->e[0].tos) | |
6083 | ? "E2" | |
6084 | : "E1"); | |
6085 | json_object_string_add(json_lsa, | |
6086 | "route", buf); | |
6087 | json_object_int_add( | |
6088 | json_lsa, "tag", | |
6089 | (unsigned long)ntohl( | |
6090 | asel->e[0].route_tag)); | |
6091 | } | |
d62a17ae | 6092 | break; |
6093 | case OSPF_NETWORK_LSA: | |
6094 | case OSPF_ASBR_SUMMARY_LSA: | |
6095 | case OSPF_OPAQUE_LINK_LSA: | |
6096 | case OSPF_OPAQUE_AREA_LSA: | |
6097 | case OSPF_OPAQUE_AS_LSA: | |
6098 | default: | |
6099 | break; | |
6100 | } | |
f328dc60 | 6101 | |
6102 | if (!json_lsa) | |
6103 | vty_out(vty, "\n"); | |
d62a17ae | 6104 | } |
718e3744 | 6105 | |
d62a17ae | 6106 | return 0; |
6107 | } | |
6108 | ||
2b64873d | 6109 | static const char *const show_database_desc[] = { |
d62a17ae | 6110 | "unknown", |
6111 | "Router Link States", | |
6112 | "Net Link States", | |
6113 | "Summary Link States", | |
6114 | "ASBR-Summary Link States", | |
6115 | "AS External Link States", | |
6116 | "Group Membership LSA", | |
6117 | "NSSA-external Link States", | |
6118 | "Type-8 LSA", | |
6119 | "Link-Local Opaque-LSA", | |
6120 | "Area-Local Opaque-LSA", | |
6121 | "AS-external Opaque-LSA", | |
718e3744 | 6122 | }; |
6123 | ||
f328dc60 | 6124 | static const char * const show_database_desc_json[] = { |
6125 | "unknown", | |
6126 | "routerLinkStates", | |
6127 | "networkLinkStates", | |
6128 | "summaryLinkStates", | |
6129 | "asbrSummaryLinkStates", | |
6130 | "asExternalLinkStates", | |
6131 | "groupMembershipLsa", | |
6132 | "nssaExternalLinkStates", | |
6133 | "type8Lsa", | |
6134 | "linkLocalOpaqueLsa", | |
6135 | "areaLocalOpaqueLsa", | |
6136 | "asExternalOpaqueLsa", | |
6137 | }; | |
6138 | ||
2b64873d | 6139 | static const char *const show_database_header[] = { |
d62a17ae | 6140 | "", |
6141 | "Link ID ADV Router Age Seq# CkSum Link count", | |
6142 | "Link ID ADV Router Age Seq# CkSum", | |
6143 | "Link ID ADV Router Age Seq# CkSum Route", | |
6144 | "Link ID ADV Router Age Seq# CkSum", | |
6145 | "Link ID ADV Router Age Seq# CkSum Route", | |
6146 | " --- header for Group Member ----", | |
6147 | "Link ID ADV Router Age Seq# CkSum Route", | |
6148 | " --- type-8 ---", | |
6149 | "Opaque-Type/Id ADV Router Age Seq# CkSum", | |
6150 | "Opaque-Type/Id ADV Router Age Seq# CkSum", | |
6151 | "Opaque-Type/Id ADV Router Age Seq# CkSum", | |
718e3744 | 6152 | }; |
6153 | ||
f328dc60 | 6154 | static void show_ip_ospf_database_header(struct vty *vty, struct ospf_lsa *lsa, |
6155 | json_object *json) | |
d62a17ae | 6156 | { |
ce513ac6 | 6157 | char buf[PREFIX_STRLEN]; |
d62a17ae | 6158 | struct router_lsa *rlsa = (struct router_lsa *)lsa->data; |
6159 | ||
f328dc60 | 6160 | if (!json) { |
6161 | vty_out(vty, " LS age: %d\n", LS_AGE(lsa)); | |
6162 | vty_out(vty, " Options: 0x%-2x : %s\n", lsa->data->options, | |
6163 | ospf_options_dump(lsa->data->options)); | |
6164 | vty_out(vty, " LS Flags: 0x%-2x %s\n", lsa->flags, | |
6165 | ((lsa->flags & OSPF_LSA_LOCAL_XLT) | |
6166 | ? "(Translated from Type-7)" | |
6167 | : "")); | |
6168 | ||
6169 | if (lsa->data->type == OSPF_ROUTER_LSA) { | |
6170 | vty_out(vty, " Flags: 0x%x", rlsa->flags); | |
6171 | ||
6172 | if (rlsa->flags) | |
6173 | vty_out(vty, " :%s%s%s%s", | |
6174 | IS_ROUTER_LSA_BORDER(rlsa) ? " ABR" | |
6175 | : "", | |
6176 | IS_ROUTER_LSA_EXTERNAL(rlsa) ? " ASBR" | |
6177 | : "", | |
6178 | IS_ROUTER_LSA_VIRTUAL(rlsa) | |
6179 | ? " VL-endpoint" | |
6180 | : "", | |
6181 | IS_ROUTER_LSA_SHORTCUT(rlsa) | |
6182 | ? " Shortcut" | |
6183 | : ""); | |
d62a17ae | 6184 | |
f328dc60 | 6185 | vty_out(vty, "\n"); |
6186 | } | |
6187 | vty_out(vty, " LS Type: %s\n", | |
6188 | lookup_msg(ospf_lsa_type_msg, lsa->data->type, NULL)); | |
6189 | vty_out(vty, " Link State ID: %pI4 %s\n", | |
6190 | &lsa->data->id, | |
6191 | lookup_msg(ospf_link_state_id_type_msg, lsa->data->type, | |
6192 | NULL)); | |
6193 | vty_out(vty, " Advertising Router: %pI4\n", | |
6194 | &lsa->data->adv_router); | |
6195 | vty_out(vty, " LS Seq Number: %08lx\n", | |
6196 | (unsigned long)ntohl(lsa->data->ls_seqnum)); | |
6197 | vty_out(vty, " Checksum: 0x%04x\n", | |
6198 | ntohs(lsa->data->checksum)); | |
6199 | vty_out(vty, " Length: %d\n\n", ntohs(lsa->data->length)); | |
6200 | } else { | |
6201 | char seqnum[10]; | |
6202 | char checksum[10]; | |
6203 | ||
6204 | snprintf(seqnum, 10, "%x", ntohl(lsa->data->ls_seqnum)); | |
6205 | snprintf(checksum, 10, "%x", ntohs(lsa->data->checksum)); | |
6206 | ||
6207 | json_object_int_add(json, "lsaAge", LS_AGE(lsa)); | |
6208 | json_object_string_add(json, "options", | |
6209 | ospf_options_dump(lsa->data->options)); | |
6210 | json_object_int_add(json, "lsaFlags", lsa->flags); | |
6211 | ||
6212 | if (lsa->flags & OSPF_LSA_LOCAL_XLT) | |
6213 | json_object_boolean_true_add(json, | |
6214 | "translatedFromType7"); | |
6215 | ||
6216 | if (lsa->data->type == OSPF_ROUTER_LSA) { | |
6217 | json_object_int_add(json, "flags", rlsa->flags); | |
6218 | ||
6219 | if (rlsa->flags) { | |
6220 | if (IS_ROUTER_LSA_BORDER(rlsa)) | |
6221 | json_object_boolean_true_add(json, | |
6222 | "abr"); | |
6223 | if (IS_ROUTER_LSA_EXTERNAL(rlsa)) | |
6224 | json_object_boolean_true_add(json, | |
6225 | "asbr"); | |
6226 | if (IS_ROUTER_LSA_VIRTUAL(rlsa)) | |
6227 | json_object_boolean_true_add( | |
6228 | json, "vlEndpoint"); | |
6229 | if (IS_ROUTER_LSA_SHORTCUT(rlsa)) | |
6230 | json_object_boolean_true_add( | |
6231 | json, "shortcut"); | |
6232 | } | |
6233 | } | |
6234 | ||
6235 | json_object_string_add( | |
6236 | json, "lsaType", | |
6237 | lookup_msg(ospf_lsa_type_msg, lsa->data->type, NULL)); | |
6238 | json_object_string_add(json, "linkStateId", | |
ce513ac6 MS |
6239 | inet_ntop(AF_INET, &lsa->data->id, |
6240 | buf, sizeof(buf))); | |
f328dc60 | 6241 | json_object_string_add(json, "advertisingRouter", |
ce513ac6 MS |
6242 | inet_ntop(AF_INET, |
6243 | &lsa->data->adv_router, | |
6244 | buf, sizeof(buf))); | |
f328dc60 | 6245 | json_object_string_add(json, "lsaSeqNumber", seqnum); |
6246 | json_object_string_add(json, "checksum", checksum); | |
6247 | json_object_int_add(json, "length", ntohs(lsa->data->length)); | |
d62a17ae | 6248 | } |
d62a17ae | 6249 | } |
6250 | ||
2b64873d | 6251 | static const char *const link_type_desc[] = { |
d62a17ae | 6252 | "(null)", |
6253 | "another Router (point-to-point)", | |
6254 | "a Transit Network", | |
6255 | "Stub Network", | |
6256 | "a Virtual Link", | |
718e3744 | 6257 | }; |
6258 | ||
2b64873d | 6259 | static const char *const link_id_desc[] = { |
d62a17ae | 6260 | "(null)", "Neighboring Router ID", "Designated Router address", |
6261 | "Net", "Neighboring Router ID", | |
718e3744 | 6262 | }; |
6263 | ||
2b64873d | 6264 | static const char *const link_data_desc[] = { |
d62a17ae | 6265 | "(null)", "Router Interface address", "Router Interface address", |
6266 | "Network Mask", "Router Interface address", | |
718e3744 | 6267 | }; |
6268 | ||
f328dc60 | 6269 | static const char *const link_id_desc_json[] = { |
6270 | "null", "neighborRouterId", "designatedRouterAddress", | |
6271 | "networkAddress", "neighborRouterId", | |
6272 | }; | |
6273 | ||
6274 | static const char *const link_data_desc_json[] = { | |
6275 | "null", "routerInterfaceAddress", "routerInterfaceAddress", | |
6276 | "networkMask", "routerInterfaceAddress", | |
6277 | }; | |
6278 | ||
718e3744 | 6279 | /* Show router-LSA each Link information. */ |
d62a17ae | 6280 | static void show_ip_ospf_database_router_links(struct vty *vty, |
f328dc60 | 6281 | struct router_lsa *rl, |
6282 | json_object *json) | |
d62a17ae | 6283 | { |
6284 | int len, type; | |
f328dc60 | 6285 | unsigned short i; |
6286 | json_object *json_links = NULL; | |
6287 | json_object *json_link = NULL; | |
6288 | int metric = 0; | |
ce513ac6 | 6289 | char buf[PREFIX_STRLEN]; |
f328dc60 | 6290 | |
6291 | if (json) | |
6292 | json_links = json_object_new_object(); | |
d62a17ae | 6293 | |
6294 | len = ntohs(rl->header.length) - 4; | |
6295 | for (i = 0; i < ntohs(rl->links) && len > 0; len -= 12, i++) { | |
6296 | type = rl->link[i].type; | |
6297 | ||
f328dc60 | 6298 | if (json) { |
6299 | char link[16]; | |
6300 | ||
6301 | snprintf(link, sizeof(link), "link%u", i); | |
6302 | json_link = json_object_new_object(); | |
6303 | json_object_string_add(json_link, "linkType", | |
6304 | link_type_desc[type]); | |
6305 | json_object_string_add(json_link, | |
6306 | link_id_desc_json[type], | |
ce513ac6 MS |
6307 | inet_ntop(AF_INET, |
6308 | &rl->link[i].link_id, | |
6309 | buf, sizeof(buf))); | |
f328dc60 | 6310 | json_object_string_add( |
6311 | json_link, link_data_desc_json[type], | |
ce513ac6 MS |
6312 | inet_ntop(AF_INET, &rl->link[i].link_data, |
6313 | buf, sizeof(buf))); | |
f328dc60 | 6314 | json_object_int_add(json_link, "numOfTosMetrics", |
6315 | metric); | |
6316 | json_object_int_add(json_link, "tos0Metric", | |
6317 | ntohs(rl->link[i].metric)); | |
6318 | json_object_object_add(json_links, link, json_link); | |
6319 | } else { | |
6320 | vty_out(vty, " Link connected to: %s\n", | |
6321 | link_type_desc[type]); | |
6322 | vty_out(vty, " (Link ID) %s: %pI4\n", | |
6323 | link_id_desc[type], | |
6324 | &rl->link[i].link_id); | |
6325 | vty_out(vty, " (Link Data) %s: %pI4\n", | |
6326 | link_data_desc[type], | |
6327 | &rl->link[i].link_data); | |
6328 | vty_out(vty, " Number of TOS metrics: 0\n"); | |
6329 | vty_out(vty, " TOS 0 Metric: %d\n", | |
6330 | ntohs(rl->link[i].metric)); | |
6331 | vty_out(vty, "\n"); | |
6332 | } | |
d62a17ae | 6333 | } |
f328dc60 | 6334 | if (json) |
6335 | json_object_object_add(json, "routerLinks", json_links); | |
718e3744 | 6336 | } |
6337 | ||
6338 | /* Show router-LSA detail information. */ | |
f328dc60 | 6339 | static int show_router_lsa_detail(struct vty *vty, struct ospf_lsa *lsa, |
6340 | json_object *json) | |
718e3744 | 6341 | { |
d62a17ae | 6342 | if (lsa != NULL) { |
6343 | struct router_lsa *rl = (struct router_lsa *)lsa->data; | |
718e3744 | 6344 | |
f328dc60 | 6345 | show_ip_ospf_database_header(vty, lsa, json); |
718e3744 | 6346 | |
f328dc60 | 6347 | if (!json) |
6348 | vty_out(vty, " Number of Links: %d\n\n", | |
6349 | ntohs(rl->links)); | |
6350 | else | |
6351 | json_object_int_add(json, "numOfLinks", | |
6352 | ntohs(rl->links)); | |
718e3744 | 6353 | |
f328dc60 | 6354 | show_ip_ospf_database_router_links(vty, rl, json); |
6355 | ||
6356 | if (!json) | |
6357 | vty_out(vty, "\n"); | |
d62a17ae | 6358 | } |
6359 | ||
6360 | return 0; | |
718e3744 | 6361 | } |
6362 | ||
6363 | /* Show network-LSA detail information. */ | |
f328dc60 | 6364 | static int show_network_lsa_detail(struct vty *vty, struct ospf_lsa *lsa, |
6365 | json_object *json) | |
718e3744 | 6366 | { |
d62a17ae | 6367 | int length, i; |
ce513ac6 | 6368 | char buf[PREFIX_STRLEN]; |
f328dc60 | 6369 | json_object *json_attached_rt = NULL; |
6370 | json_object *json_router = NULL; | |
6371 | ||
6372 | if (json) | |
6373 | json_attached_rt = json_object_new_object(); | |
718e3744 | 6374 | |
d62a17ae | 6375 | if (lsa != NULL) { |
6376 | struct network_lsa *nl = (struct network_lsa *)lsa->data; | |
718e3744 | 6377 | |
f328dc60 | 6378 | show_ip_ospf_database_header(vty, lsa, json); |
718e3744 | 6379 | |
f328dc60 | 6380 | if (!json) |
6381 | vty_out(vty, " Network Mask: /%d\n", | |
6382 | ip_masklen(nl->mask)); | |
6383 | else | |
6384 | json_object_int_add(json, "networkMask", | |
6385 | ip_masklen(nl->mask)); | |
718e3744 | 6386 | |
d62a17ae | 6387 | length = ntohs(lsa->data->length) - OSPF_LSA_HEADER_SIZE - 4; |
718e3744 | 6388 | |
d62a17ae | 6389 | for (i = 0; length > 0; i++, length -= 4) |
f328dc60 | 6390 | if (!json) { |
6391 | vty_out(vty, " Attached Router: %pI4\n", | |
6392 | &nl->routers[i]); | |
6393 | vty_out(vty, "\n"); | |
6394 | } else { | |
6395 | json_router = json_object_new_object(); | |
6396 | json_object_string_add( | |
6397 | json_router, "attachedRouterId", | |
ce513ac6 MS |
6398 | inet_ntop(AF_INET, &nl->routers[i], |
6399 | buf, sizeof(buf))); | |
f328dc60 | 6400 | json_object_object_add( |
6401 | json_attached_rt, | |
ce513ac6 MS |
6402 | inet_ntop(AF_INET, &(nl->routers[i]), |
6403 | buf, sizeof(buf)), | |
6404 | json_router); | |
f328dc60 | 6405 | } |
d62a17ae | 6406 | } |
718e3744 | 6407 | |
f328dc60 | 6408 | if (json) |
6409 | json_object_object_add(json, "attchedRouters", | |
6410 | json_attached_rt); | |
6411 | ||
d62a17ae | 6412 | return 0; |
718e3744 | 6413 | } |
6414 | ||
6415 | /* Show summary-LSA detail information. */ | |
f328dc60 | 6416 | static int show_summary_lsa_detail(struct vty *vty, struct ospf_lsa *lsa, |
6417 | json_object *json) | |
718e3744 | 6418 | { |
d62a17ae | 6419 | if (lsa != NULL) { |
6420 | struct summary_lsa *sl = (struct summary_lsa *)lsa->data; | |
718e3744 | 6421 | |
f328dc60 | 6422 | show_ip_ospf_database_header(vty, lsa, json); |
718e3744 | 6423 | |
f328dc60 | 6424 | if (!json) { |
6425 | vty_out(vty, " Network Mask: /%d\n", | |
6426 | ip_masklen(sl->mask)); | |
6427 | vty_out(vty, " TOS: 0 Metric: %d\n", | |
6428 | GET_METRIC(sl->metric)); | |
6429 | vty_out(vty, "\n"); | |
6430 | } else { | |
6431 | json_object_int_add(json, "networkMask", | |
6432 | ip_masklen(sl->mask)); | |
6433 | json_object_int_add(json, "tos0Metric", | |
6434 | GET_METRIC(sl->metric)); | |
6435 | } | |
d62a17ae | 6436 | } |
718e3744 | 6437 | |
d62a17ae | 6438 | return 0; |
718e3744 | 6439 | } |
6440 | ||
6441 | /* Show summary-ASBR-LSA detail information. */ | |
f328dc60 | 6442 | static int show_summary_asbr_lsa_detail(struct vty *vty, struct ospf_lsa *lsa, |
6443 | json_object *json) | |
718e3744 | 6444 | { |
d62a17ae | 6445 | if (lsa != NULL) { |
6446 | struct summary_lsa *sl = (struct summary_lsa *)lsa->data; | |
718e3744 | 6447 | |
f328dc60 | 6448 | show_ip_ospf_database_header(vty, lsa, json); |
718e3744 | 6449 | |
f328dc60 | 6450 | if (!json) { |
6451 | vty_out(vty, " Network Mask: /%d\n", | |
6452 | ip_masklen(sl->mask)); | |
6453 | vty_out(vty, " TOS: 0 Metric: %d\n", | |
6454 | GET_METRIC(sl->metric)); | |
6455 | vty_out(vty, "\n"); | |
6456 | } else { | |
6457 | json_object_int_add(json, "networkMask", | |
6458 | ip_masklen(sl->mask)); | |
6459 | json_object_int_add(json, "tos0Metric", | |
6460 | GET_METRIC(sl->metric)); | |
6461 | } | |
d62a17ae | 6462 | } |
718e3744 | 6463 | |
d62a17ae | 6464 | return 0; |
718e3744 | 6465 | } |
6466 | ||
6467 | /* Show AS-external-LSA detail information. */ | |
f328dc60 | 6468 | static int show_as_external_lsa_detail(struct vty *vty, struct ospf_lsa *lsa, |
6469 | json_object *json) | |
d62a17ae | 6470 | { |
ce513ac6 | 6471 | char buf[PREFIX_STRLEN]; |
f328dc60 | 6472 | int tos = 0; |
6473 | ||
d62a17ae | 6474 | if (lsa != NULL) { |
6475 | struct as_external_lsa *al = | |
6476 | (struct as_external_lsa *)lsa->data; | |
6477 | ||
f328dc60 | 6478 | show_ip_ospf_database_header(vty, lsa, json); |
6479 | ||
6480 | if (!json) { | |
6481 | vty_out(vty, " Network Mask: /%d\n", | |
6482 | ip_masklen(al->mask)); | |
6483 | vty_out(vty, " Metric Type: %s\n", | |
6484 | IS_EXTERNAL_METRIC(al->e[0].tos) | |
6485 | ? "2 (Larger than any link state path)" | |
6486 | : "1"); | |
6487 | vty_out(vty, " TOS: 0\n"); | |
6488 | vty_out(vty, " Metric: %d\n", | |
6489 | GET_METRIC(al->e[0].metric)); | |
6490 | vty_out(vty, " Forward Address: %pI4\n", | |
6491 | &al->e[0].fwd_addr); | |
6492 | vty_out(vty, | |
6493 | " External Route Tag: %" ROUTE_TAG_PRI "\n\n", | |
6494 | (route_tag_t)ntohl(al->e[0].route_tag)); | |
6495 | } else { | |
6496 | json_object_int_add(json, "networkMask", | |
6497 | ip_masklen(al->mask)); | |
6498 | json_object_string_add( | |
6499 | json, "metricType", | |
6500 | IS_EXTERNAL_METRIC(al->e[0].tos) | |
6501 | ? "E2 (Larger than any link state path)" | |
6502 | : "E1"); | |
6503 | json_object_int_add(json, "tos", tos); | |
6504 | json_object_int_add(json, "metric", | |
6505 | GET_METRIC(al->e[0].metric)); | |
6506 | json_object_string_add(json, "forwardAddress", | |
ce513ac6 MS |
6507 | inet_ntop(AF_INET, |
6508 | &(al->e[0].fwd_addr), | |
6509 | buf, sizeof(buf))); | |
f328dc60 | 6510 | json_object_int_add( |
6511 | json, "externalRouteTag", | |
6512 | (route_tag_t)ntohl(al->e[0].route_tag)); | |
6513 | } | |
d62a17ae | 6514 | } |
718e3744 | 6515 | |
d62a17ae | 6516 | return 0; |
718e3744 | 6517 | } |
718e3744 | 6518 | |
718e3744 | 6519 | /* Show AS-NSSA-LSA detail information. */ |
f328dc60 | 6520 | static int show_as_nssa_lsa_detail(struct vty *vty, struct ospf_lsa *lsa, |
6521 | json_object *json) | |
d62a17ae | 6522 | { |
ce513ac6 | 6523 | char buf[PREFIX_STRLEN]; |
f328dc60 | 6524 | int tos = 0; |
6525 | ||
d62a17ae | 6526 | if (lsa != NULL) { |
6527 | struct as_external_lsa *al = | |
6528 | (struct as_external_lsa *)lsa->data; | |
6529 | ||
f328dc60 | 6530 | show_ip_ospf_database_header(vty, lsa, json); |
6531 | ||
6532 | if (!json) { | |
6533 | vty_out(vty, " Network Mask: /%d\n", | |
6534 | ip_masklen(al->mask)); | |
6535 | vty_out(vty, " Metric Type: %s\n", | |
6536 | IS_EXTERNAL_METRIC(al->e[0].tos) | |
6537 | ? "2 (Larger than any link state path)" | |
6538 | : "1"); | |
6539 | vty_out(vty, " TOS: 0\n"); | |
6540 | vty_out(vty, " Metric: %d\n", | |
6541 | GET_METRIC(al->e[0].metric)); | |
6542 | vty_out(vty, " NSSA: Forward Address: %pI4\n", | |
6543 | &al->e[0].fwd_addr); | |
6544 | vty_out(vty, | |
6545 | " External Route Tag: %" ROUTE_TAG_PRI | |
6546 | "\n\n", | |
6547 | (route_tag_t)ntohl(al->e[0].route_tag)); | |
6548 | } else { | |
6549 | json_object_int_add(json, "networkMask", | |
6550 | ip_masklen(al->mask)); | |
6551 | json_object_string_add( | |
6552 | json, "metricType", | |
6553 | IS_EXTERNAL_METRIC(al->e[0].tos) | |
6554 | ? "E2 (Larger than any link state path)" | |
6555 | : "E1"); | |
6556 | json_object_int_add(json, "tos", tos); | |
6557 | json_object_int_add(json, "metric", | |
6558 | GET_METRIC(al->e[0].metric)); | |
6559 | json_object_string_add(json, "nssaForwardAddress", | |
ce513ac6 MS |
6560 | inet_ntop(AF_INET, |
6561 | &al->e[0].fwd_addr, | |
6562 | buf, sizeof(buf))); | |
f328dc60 | 6563 | json_object_int_add( |
6564 | json, "externalRouteTag", | |
6565 | (route_tag_t)ntohl(al->e[0].route_tag)); | |
6566 | } | |
d62a17ae | 6567 | } |
718e3744 | 6568 | |
d62a17ae | 6569 | return 0; |
718e3744 | 6570 | } |
6571 | ||
f328dc60 | 6572 | static int show_func_dummy(struct vty *vty, struct ospf_lsa *lsa, |
6573 | json_object *json) | |
718e3744 | 6574 | { |
d62a17ae | 6575 | return 0; |
718e3744 | 6576 | } |
6577 | ||
f328dc60 | 6578 | static int show_opaque_lsa_detail(struct vty *vty, struct ospf_lsa *lsa, |
6579 | json_object *json) | |
718e3744 | 6580 | { |
d62a17ae | 6581 | if (lsa != NULL) { |
f328dc60 | 6582 | show_ip_ospf_database_header(vty, lsa, json); |
6583 | show_opaque_info_detail(vty, lsa, json); | |
6584 | if (!json) | |
6585 | vty_out(vty, "\n"); | |
d62a17ae | 6586 | } |
6587 | return 0; | |
6588 | } | |
6589 | ||
f328dc60 | 6590 | int (*show_function[])(struct vty *, struct ospf_lsa *, json_object *) = { |
d62a17ae | 6591 | NULL, |
6592 | show_router_lsa_detail, | |
6593 | show_network_lsa_detail, | |
6594 | show_summary_lsa_detail, | |
6595 | show_summary_asbr_lsa_detail, | |
6596 | show_as_external_lsa_detail, | |
6597 | show_func_dummy, | |
6598 | show_as_nssa_lsa_detail, /* almost same as external */ | |
6599 | NULL, /* type-8 */ | |
6600 | show_opaque_lsa_detail, | |
6601 | show_opaque_lsa_detail, | |
6602 | show_opaque_lsa_detail, | |
6603 | }; | |
6604 | ||
6605 | static void show_lsa_prefix_set(struct vty *vty, struct prefix_ls *lp, | |
6606 | struct in_addr *id, struct in_addr *adv_router) | |
6607 | { | |
6608 | memset(lp, 0, sizeof(struct prefix_ls)); | |
6609 | lp->family = 0; | |
6610 | if (id == NULL) | |
6611 | lp->prefixlen = 0; | |
6612 | else if (adv_router == NULL) { | |
6613 | lp->prefixlen = 32; | |
6614 | lp->id = *id; | |
6615 | } else { | |
6616 | lp->prefixlen = 64; | |
6617 | lp->id = *id; | |
6618 | lp->adv_router = *adv_router; | |
6619 | } | |
718e3744 | 6620 | } |
718e3744 | 6621 | |
d62a17ae | 6622 | static void show_lsa_detail_proc(struct vty *vty, struct route_table *rt, |
f328dc60 | 6623 | struct in_addr *id, struct in_addr *adv_router, |
6624 | json_object *json) | |
d62a17ae | 6625 | { |
6626 | struct prefix_ls lp; | |
6627 | struct route_node *rn, *start; | |
6628 | struct ospf_lsa *lsa; | |
f328dc60 | 6629 | json_object *json_lsa = NULL; |
718e3744 | 6630 | |
d62a17ae | 6631 | show_lsa_prefix_set(vty, &lp, id, adv_router); |
6632 | start = route_node_get(rt, (struct prefix *)&lp); | |
6633 | if (start) { | |
6634 | route_lock_node(start); | |
6635 | for (rn = start; rn; rn = route_next_until(rn, start)) | |
6636 | if ((lsa = rn->info)) { | |
f328dc60 | 6637 | if (json) { |
6638 | json_lsa = json_object_new_object(); | |
6639 | json_object_array_add(json, json_lsa); | |
6640 | } | |
6641 | ||
d62a17ae | 6642 | if (show_function[lsa->data->type] != NULL) |
f328dc60 | 6643 | show_function[lsa->data->type]( |
6644 | vty, lsa, json_lsa); | |
d62a17ae | 6645 | } |
6646 | route_unlock_node(start); | |
6647 | } | |
718e3744 | 6648 | } |
6649 | ||
6650 | /* Show detail LSA information | |
6651 | -- if id is NULL then show all LSAs. */ | |
d62a17ae | 6652 | static void show_lsa_detail(struct vty *vty, struct ospf *ospf, int type, |
f328dc60 | 6653 | struct in_addr *id, struct in_addr *adv_router, |
6654 | json_object *json) | |
d62a17ae | 6655 | { |
6656 | struct listnode *node; | |
6657 | struct ospf_area *area; | |
ce513ac6 | 6658 | char buf[PREFIX_STRLEN]; |
f328dc60 | 6659 | json_object *json_lsa_type = NULL; |
6660 | json_object *json_areas = NULL; | |
6661 | json_object *json_lsa_array = NULL; | |
6662 | ||
6663 | if (json) | |
6664 | json_lsa_type = json_object_new_object(); | |
d62a17ae | 6665 | |
6666 | switch (type) { | |
6667 | case OSPF_AS_EXTERNAL_LSA: | |
6668 | case OSPF_OPAQUE_AS_LSA: | |
f328dc60 | 6669 | if (!json) |
6670 | vty_out(vty, " %s \n\n", | |
6671 | show_database_desc[type]); | |
6672 | else | |
6673 | json_lsa_array = json_object_new_array(); | |
6674 | ||
6675 | show_lsa_detail_proc(vty, AS_LSDB(ospf, type), id, adv_router, | |
6676 | json_lsa_array); | |
6677 | if (json) | |
6678 | json_object_object_add(json, | |
6679 | show_database_desc_json[type], | |
6680 | json_lsa_array); | |
6681 | ||
d62a17ae | 6682 | break; |
6683 | default: | |
f328dc60 | 6684 | if (json) |
6685 | json_areas = json_object_new_object(); | |
6686 | ||
d62a17ae | 6687 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) { |
f328dc60 | 6688 | if (!json) { |
6689 | vty_out(vty, | |
6690 | "\n %s (Area %s)\n\n", | |
6691 | show_database_desc[type], | |
6692 | ospf_area_desc_string(area)); | |
6693 | } else { | |
6694 | json_lsa_array = json_object_new_array(); | |
6695 | json_object_object_add(json_areas, | |
ce513ac6 MS |
6696 | inet_ntop(AF_INET, |
6697 | &area->area_id, | |
6698 | buf, | |
6699 | sizeof(buf)), | |
f328dc60 | 6700 | json_lsa_array); |
6701 | } | |
6702 | ||
d62a17ae | 6703 | show_lsa_detail_proc(vty, AREA_LSDB(area, type), id, |
f328dc60 | 6704 | adv_router, json_lsa_array); |
6705 | } | |
6706 | ||
6707 | if (json) { | |
6708 | json_object_object_add(json_lsa_type, "areas", | |
6709 | json_areas); | |
6710 | json_object_object_add(json, | |
6711 | show_database_desc_json[type], | |
6712 | json_lsa_type); | |
d62a17ae | 6713 | } |
6714 | break; | |
718e3744 | 6715 | } |
6716 | } | |
6717 | ||
d62a17ae | 6718 | static void show_lsa_detail_adv_router_proc(struct vty *vty, |
6719 | struct route_table *rt, | |
f328dc60 | 6720 | struct in_addr *adv_router, |
6721 | json_object *json) | |
d62a17ae | 6722 | { |
ce513ac6 | 6723 | char buf[PREFIX_STRLEN]; |
d62a17ae | 6724 | struct route_node *rn; |
6725 | struct ospf_lsa *lsa; | |
6726 | ||
6727 | for (rn = route_top(rt); rn; rn = route_next(rn)) | |
f328dc60 | 6728 | if ((lsa = rn->info)) { |
6729 | json_object *json_lsa = NULL; | |
6730 | ||
d62a17ae | 6731 | if (IPV4_ADDR_SAME(adv_router, |
6732 | &lsa->data->adv_router)) { | |
6733 | if (CHECK_FLAG(lsa->flags, OSPF_LSA_LOCAL_XLT)) | |
6734 | continue; | |
f328dc60 | 6735 | if (json) |
6736 | json_lsa = json_object_new_object(); | |
6737 | ||
d62a17ae | 6738 | if (show_function[lsa->data->type] != NULL) |
f328dc60 | 6739 | show_function[lsa->data->type]( |
6740 | vty, lsa, json_lsa); | |
6741 | if (json) | |
6742 | json_object_object_add( | |
ce513ac6 MS |
6743 | json, |
6744 | inet_ntop(AF_INET, | |
6745 | &lsa->data->id, | |
6746 | buf, sizeof(buf)), | |
f328dc60 | 6747 | json_lsa); |
d62a17ae | 6748 | } |
f328dc60 | 6749 | } |
d62a17ae | 6750 | } |
6751 | ||
718e3744 | 6752 | /* Show detail LSA information. */ |
d62a17ae | 6753 | static void show_lsa_detail_adv_router(struct vty *vty, struct ospf *ospf, |
f328dc60 | 6754 | int type, struct in_addr *adv_router, |
6755 | json_object *json) | |
d62a17ae | 6756 | { |
6757 | struct listnode *node; | |
6758 | struct ospf_area *area; | |
ce513ac6 | 6759 | char buf[PREFIX_STRLEN]; |
f328dc60 | 6760 | json_object *json_lstype = NULL; |
6761 | json_object *json_area = NULL; | |
6762 | ||
6763 | if (json) | |
6764 | json_lstype = json_object_new_object(); | |
d62a17ae | 6765 | |
6766 | switch (type) { | |
6767 | case OSPF_AS_EXTERNAL_LSA: | |
6768 | case OSPF_OPAQUE_AS_LSA: | |
f328dc60 | 6769 | if (!json) |
6770 | vty_out(vty, " %s \n\n", | |
6771 | show_database_desc[type]); | |
6772 | ||
d62a17ae | 6773 | show_lsa_detail_adv_router_proc(vty, AS_LSDB(ospf, type), |
f328dc60 | 6774 | adv_router, json_lstype); |
d62a17ae | 6775 | break; |
6776 | default: | |
f328dc60 | 6777 | |
d62a17ae | 6778 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) { |
f328dc60 | 6779 | if (json) |
6780 | json_area = json_object_new_object(); | |
6781 | else | |
6782 | vty_out(vty, | |
6783 | "\n %s (Area %s)\n\n", | |
6784 | show_database_desc[type], | |
6785 | ospf_area_desc_string(area)); | |
6786 | show_lsa_detail_adv_router_proc(vty, | |
6787 | AREA_LSDB(area, type), | |
6788 | adv_router, json_area); | |
6789 | ||
6790 | if (json) | |
6791 | json_object_object_add(json_lstype, | |
ce513ac6 MS |
6792 | inet_ntop(AF_INET, |
6793 | &area->area_id, | |
6794 | buf, | |
6795 | sizeof(buf)), | |
f328dc60 | 6796 | json_area); |
d62a17ae | 6797 | } |
6798 | break; | |
6799 | } | |
f328dc60 | 6800 | |
6801 | if (json) | |
6802 | json_object_object_add(json, show_database_desc[type], | |
6803 | json_lstype); | |
d62a17ae | 6804 | } |
6805 | ||
7fd0729f G |
6806 | void show_ip_ospf_database_summary(struct vty *vty, struct ospf *ospf, int self, |
6807 | json_object *json) | |
d62a17ae | 6808 | { |
6809 | struct ospf_lsa *lsa; | |
6810 | struct route_node *rn; | |
6811 | struct ospf_area *area; | |
6812 | struct listnode *node; | |
ce513ac6 | 6813 | char buf[PREFIX_STRLEN]; |
f328dc60 | 6814 | json_object *json_areas = NULL; |
6815 | json_object *json_area = NULL; | |
6816 | json_object *json_lsa = NULL; | |
d62a17ae | 6817 | int type; |
f328dc60 | 6818 | json_object *json_lsa_array = NULL; |
6819 | ||
6820 | if (json) | |
6821 | json_areas = json_object_new_object(); | |
d62a17ae | 6822 | |
6823 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) { | |
f328dc60 | 6824 | if (json) |
6825 | json_area = json_object_new_object(); | |
6826 | ||
d62a17ae | 6827 | for (type = OSPF_MIN_LSA; type < OSPF_MAX_LSA; type++) { |
6828 | switch (type) { | |
6829 | case OSPF_AS_EXTERNAL_LSA: | |
6830 | case OSPF_OPAQUE_AS_LSA: | |
6831 | continue; | |
6832 | default: | |
6833 | break; | |
6834 | } | |
6835 | if (ospf_lsdb_count_self(area->lsdb, type) > 0 | |
6836 | || (!self | |
6837 | && ospf_lsdb_count(area->lsdb, type) > 0)) { | |
d62a17ae | 6838 | |
f328dc60 | 6839 | if (!json) { |
6840 | vty_out(vty, | |
6841 | " %s (Area %s)\n\n", | |
6842 | show_database_desc[type], | |
6843 | ospf_area_desc_string(area)); | |
6844 | vty_out(vty, "%s\n", | |
6845 | show_database_header[type]); | |
6846 | } else { | |
6847 | json_lsa_array = | |
6848 | json_object_new_array(); | |
6849 | json_object_object_add( | |
6850 | json_area, | |
6851 | show_database_desc_json[type], | |
6852 | json_lsa_array); | |
6853 | } | |
6854 | ||
6855 | LSDB_LOOP (AREA_LSDB(area, type), rn, lsa) { | |
6856 | if (json) { | |
6857 | json_lsa = | |
6858 | json_object_new_object(); | |
6859 | json_object_array_add( | |
6860 | json_lsa_array, | |
6861 | json_lsa); | |
6862 | } | |
d62a17ae | 6863 | |
f328dc60 | 6864 | show_lsa_summary(vty, lsa, self, |
6865 | json_lsa); | |
6866 | } | |
6867 | ||
6868 | if (!json) | |
6869 | vty_out(vty, "\n"); | |
d62a17ae | 6870 | } |
6871 | } | |
f328dc60 | 6872 | if (json) |
6873 | json_object_object_add(json_areas, | |
ce513ac6 MS |
6874 | inet_ntop(AF_INET, |
6875 | &area->area_id, | |
6876 | buf, sizeof(buf)), | |
f328dc60 | 6877 | json_area); |
d62a17ae | 6878 | } |
6879 | ||
f328dc60 | 6880 | if (json) |
6881 | json_object_object_add(json, "areas", json_areas); | |
6882 | ||
d62a17ae | 6883 | for (type = OSPF_MIN_LSA; type < OSPF_MAX_LSA; type++) { |
6884 | switch (type) { | |
6885 | case OSPF_AS_EXTERNAL_LSA: | |
6886 | case OSPF_OPAQUE_AS_LSA: | |
6887 | break; | |
6888 | default: | |
6889 | continue; | |
6890 | } | |
6891 | if (ospf_lsdb_count_self(ospf->lsdb, type) | |
6892 | || (!self && ospf_lsdb_count(ospf->lsdb, type))) { | |
f328dc60 | 6893 | if (!json) { |
6894 | vty_out(vty, " %s\n\n", | |
6895 | show_database_desc[type]); | |
6896 | vty_out(vty, "%s\n", | |
6897 | show_database_header[type]); | |
6898 | } else { | |
6899 | json_lsa_array = json_object_new_array(); | |
6900 | json_object_object_add( | |
6901 | json, show_database_desc_json[type], | |
6902 | json_lsa_array); | |
6903 | } | |
d62a17ae | 6904 | |
f328dc60 | 6905 | LSDB_LOOP (AS_LSDB(ospf, type), rn, lsa) { |
6906 | if (json) { | |
6907 | json_lsa = json_object_new_object(); | |
6908 | json_object_array_add(json_lsa_array, | |
6909 | json_lsa); | |
6910 | } | |
d62a17ae | 6911 | |
f328dc60 | 6912 | show_lsa_summary(vty, lsa, self, json_lsa); |
6913 | } | |
6914 | ||
6915 | if (!json) | |
6916 | vty_out(vty, "\n"); | |
d62a17ae | 6917 | } |
6918 | } | |
6919 | ||
f328dc60 | 6920 | if (!json) |
6921 | vty_out(vty, "\n"); | |
d62a17ae | 6922 | } |
6923 | ||
f328dc60 | 6924 | static void show_ip_ospf_database_maxage(struct vty *vty, struct ospf *ospf, |
6925 | json_object *json) | |
d62a17ae | 6926 | { |
6927 | struct route_node *rn; | |
ce513ac6 | 6928 | char buf[PREFIX_STRLEN]; |
f328dc60 | 6929 | json_object *json_maxage = NULL; |
d62a17ae | 6930 | |
f328dc60 | 6931 | if (!json) |
6932 | vty_out(vty, "\n MaxAge Link States:\n\n"); | |
6933 | else | |
6934 | json_maxage = json_object_new_object(); | |
d62a17ae | 6935 | |
6936 | for (rn = route_top(ospf->maxage_lsa); rn; rn = route_next(rn)) { | |
6937 | struct ospf_lsa *lsa; | |
f328dc60 | 6938 | json_object *json_lsa = NULL; |
d62a17ae | 6939 | |
6940 | if ((lsa = rn->info) != NULL) { | |
f328dc60 | 6941 | if (!json) { |
6942 | vty_out(vty, "Link type: %d\n", | |
6943 | lsa->data->type); | |
ce513ac6 MS |
6944 | vty_out(vty, "Link State ID: %pI4\n", |
6945 | &lsa->data->id); | |
f328dc60 | 6946 | vty_out(vty, "Advertising Router: %pI4\n", |
6947 | &lsa->data->adv_router); | |
6948 | vty_out(vty, "LSA lock count: %d\n", lsa->lock); | |
6949 | vty_out(vty, "\n"); | |
6950 | } else { | |
6951 | json_lsa = json_object_new_object(); | |
6952 | json_object_int_add(json_lsa, "linkType", | |
6953 | lsa->data->type); | |
6954 | json_object_string_add( | |
6955 | json_lsa, "linkStateId", | |
ce513ac6 MS |
6956 | inet_ntop(AF_INET, &lsa->data->id, |
6957 | buf, sizeof(buf))); | |
f328dc60 | 6958 | json_object_string_add( |
6959 | json_lsa, "advertisingRouter", | |
ce513ac6 MS |
6960 | inet_ntop(AF_INET, |
6961 | &lsa->data->adv_router, | |
6962 | buf, sizeof(buf))); | |
f328dc60 | 6963 | json_object_int_add(json_lsa, "lsaLockCount", |
6964 | lsa->lock); | |
ce513ac6 MS |
6965 | json_object_object_add( |
6966 | json_maxage, | |
6967 | inet_ntop(AF_INET, | |
6968 | &lsa->data->id, | |
6969 | buf, sizeof(buf)), | |
6970 | json_lsa); | |
f328dc60 | 6971 | } |
d62a17ae | 6972 | } |
91e6a0e5 | 6973 | } |
f328dc60 | 6974 | if (json) |
6975 | json_object_object_add(json, "maxAgeLinkStates", json_maxage); | |
718e3744 | 6976 | } |
6977 | ||
718e3744 | 6978 | #define OSPF_LSA_TYPE_NSSA_DESC "NSSA external link state\n" |
6979 | #define OSPF_LSA_TYPE_NSSA_CMD_STR "|nssa-external" | |
718e3744 | 6980 | |
718e3744 | 6981 | #define OSPF_LSA_TYPE_OPAQUE_LINK_DESC "Link local Opaque-LSA\n" |
6982 | #define OSPF_LSA_TYPE_OPAQUE_AREA_DESC "Link area Opaque-LSA\n" | |
6983 | #define OSPF_LSA_TYPE_OPAQUE_AS_DESC "Link AS Opaque-LSA\n" | |
6984 | #define OSPF_LSA_TYPE_OPAQUE_CMD_STR "|opaque-link|opaque-area|opaque-as" | |
718e3744 | 6985 | |
d62a17ae | 6986 | #define OSPF_LSA_TYPES_DESC \ |
6987 | "ASBR summary link states\n" \ | |
6988 | "External link states\n" \ | |
6989 | "Network link states\n" \ | |
6990 | "Router link states\n" \ | |
6991 | "Network summary link states\n" OSPF_LSA_TYPE_NSSA_DESC \ | |
6992 | OSPF_LSA_TYPE_OPAQUE_LINK_DESC OSPF_LSA_TYPE_OPAQUE_AREA_DESC \ | |
6993 | OSPF_LSA_TYPE_OPAQUE_AS_DESC | |
6994 | ||
6995 | static int show_ip_ospf_database_common(struct vty *vty, struct ospf *ospf, | |
6996 | int arg_base, int argc, | |
d7c0a89a | 6997 | struct cmd_token **argv, |
f328dc60 | 6998 | uint8_t use_vrf, json_object *json, |
6999 | bool uj) | |
d62a17ae | 7000 | { |
7001 | int idx_type = 4; | |
7002 | int type, ret; | |
7003 | struct in_addr id, adv_router; | |
ce513ac6 | 7004 | char buf[PREFIX_STRLEN]; |
f328dc60 | 7005 | json_object *json_vrf = NULL; |
d62a17ae | 7006 | |
f328dc60 | 7007 | if (uj) { |
7008 | if (use_vrf) | |
7009 | json_vrf = json_object_new_object(); | |
7010 | else | |
7011 | json_vrf = json; | |
7012 | } | |
7013 | ||
7014 | if (ospf->instance) { | |
7015 | if (uj) | |
7016 | json_object_int_add(json_vrf, "ospfInstance", | |
7017 | ospf->instance); | |
7018 | else | |
7019 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
7020 | } | |
d62a17ae | 7021 | |
f328dc60 | 7022 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); |
87bd50e8 | 7023 | |
f328dc60 | 7024 | /* Show Router ID. */ |
7025 | if (uj) { | |
7026 | json_object_string_add(json_vrf, "routerId", | |
ce513ac6 MS |
7027 | inet_ntop(AF_INET, &ospf->router_id, |
7028 | buf, sizeof(buf))); | |
f328dc60 | 7029 | } else { |
7030 | vty_out(vty, "\n OSPF Router with ID (%pI4)\n\n", | |
7031 | &ospf->router_id); | |
7032 | } | |
d62a17ae | 7033 | |
7034 | /* Show all LSA. */ | |
f328dc60 | 7035 | if ((argc == arg_base + 4) || (uj && (argc == arg_base + 5))) { |
7036 | show_ip_ospf_database_summary(vty, ospf, 0, json_vrf); | |
7037 | if (json) { | |
7038 | if (use_vrf) { | |
7039 | if (ospf->vrf_id == VRF_DEFAULT) | |
7040 | json_object_object_add(json, "default", | |
7041 | json_vrf); | |
7042 | else | |
7043 | json_object_object_add(json, ospf->name, | |
7044 | json_vrf); | |
7045 | } | |
7046 | } | |
d62a17ae | 7047 | return CMD_SUCCESS; |
7048 | } | |
718e3744 | 7049 | |
d62a17ae | 7050 | /* Set database type to show. */ |
7051 | if (strncmp(argv[arg_base + idx_type]->text, "r", 1) == 0) | |
7052 | type = OSPF_ROUTER_LSA; | |
7053 | else if (strncmp(argv[arg_base + idx_type]->text, "ne", 2) == 0) | |
7054 | type = OSPF_NETWORK_LSA; | |
7055 | else if (strncmp(argv[arg_base + idx_type]->text, "ns", 2) == 0) | |
7056 | type = OSPF_AS_NSSA_LSA; | |
7057 | else if (strncmp(argv[arg_base + idx_type]->text, "su", 2) == 0) | |
7058 | type = OSPF_SUMMARY_LSA; | |
7059 | else if (strncmp(argv[arg_base + idx_type]->text, "a", 1) == 0) | |
7060 | type = OSPF_ASBR_SUMMARY_LSA; | |
7061 | else if (strncmp(argv[arg_base + idx_type]->text, "e", 1) == 0) | |
7062 | type = OSPF_AS_EXTERNAL_LSA; | |
7063 | else if (strncmp(argv[arg_base + idx_type]->text, "se", 2) == 0) { | |
f328dc60 | 7064 | show_ip_ospf_database_summary(vty, ospf, 1, json_vrf); |
7065 | if (json) { | |
7066 | if (use_vrf) { | |
7067 | if (ospf->vrf_id == VRF_DEFAULT) | |
7068 | json_object_object_add(json, "default", | |
7069 | json_vrf); | |
7070 | else | |
7071 | json_object_object_add(json, ospf->name, | |
7072 | json_vrf); | |
7073 | } | |
7074 | } | |
d62a17ae | 7075 | return CMD_SUCCESS; |
7076 | } else if (strncmp(argv[arg_base + idx_type]->text, "m", 1) == 0) { | |
f328dc60 | 7077 | show_ip_ospf_database_maxage(vty, ospf, json_vrf); |
7078 | if (json) { | |
7079 | if (use_vrf) { | |
7080 | if (ospf->vrf_id == VRF_DEFAULT) | |
7081 | json_object_object_add(json, "default", | |
7082 | json_vrf); | |
7083 | else | |
7084 | json_object_object_add(json, ospf->name, | |
7085 | json_vrf); | |
7086 | } | |
7087 | } | |
d62a17ae | 7088 | return CMD_SUCCESS; |
7089 | } else if (strncmp(argv[arg_base + idx_type]->text, "opaque-l", 8) == 0) | |
7090 | type = OSPF_OPAQUE_LINK_LSA; | |
7091 | else if (strncmp(argv[arg_base + idx_type]->text, "opaque-ar", 9) == 0) | |
7092 | type = OSPF_OPAQUE_AREA_LSA; | |
7093 | else if (strncmp(argv[arg_base + idx_type]->text, "opaque-as", 9) == 0) | |
7094 | type = OSPF_OPAQUE_AS_LSA; | |
7095 | else | |
718e3744 | 7096 | return CMD_WARNING; |
d62a17ae | 7097 | |
7098 | /* `show ip ospf database LSA'. */ | |
f328dc60 | 7099 | if ((argc == arg_base + 5) || (uj && (argc == arg_base + 6))) |
7100 | show_lsa_detail(vty, ospf, type, NULL, NULL, json_vrf); | |
d62a17ae | 7101 | else if (argc >= arg_base + 6) { |
7102 | ret = inet_aton(argv[arg_base + 5]->arg, &id); | |
7103 | if (!ret) | |
7104 | return CMD_WARNING; | |
7105 | ||
7106 | /* `show ip ospf database LSA ID'. */ | |
f328dc60 | 7107 | if ((argc == arg_base + 6) || (uj && (argc == arg_base + 7))) |
7108 | show_lsa_detail(vty, ospf, type, &id, NULL, json_vrf); | |
d62a17ae | 7109 | /* `show ip ospf database LSA ID adv-router ADV_ROUTER'. */ |
f328dc60 | 7110 | else if ((argc == arg_base + 7) |
7111 | || (uj && (argc == arg_base + 8))) { | |
d62a17ae | 7112 | if (strncmp(argv[arg_base + 6]->text, "s", 1) == 0) |
7113 | adv_router = ospf->router_id; | |
7114 | else { | |
7115 | ret = inet_aton(argv[arg_base + 7]->arg, | |
7116 | &adv_router); | |
7117 | if (!ret) | |
7118 | return CMD_WARNING; | |
7119 | } | |
f328dc60 | 7120 | show_lsa_detail(vty, ospf, type, &id, &adv_router, |
7121 | json_vrf); | |
7122 | } | |
7123 | } | |
7124 | ||
7125 | if (json) { | |
7126 | if (use_vrf) { | |
7127 | if (ospf->vrf_id == VRF_DEFAULT) | |
7128 | json_object_object_add(json, "default", | |
7129 | json_vrf); | |
7130 | else | |
7131 | json_object_object_add(json, ospf->name, | |
7132 | json_vrf); | |
d62a17ae | 7133 | } |
718e3744 | 7134 | } |
718e3744 | 7135 | |
d62a17ae | 7136 | return CMD_SUCCESS; |
718e3744 | 7137 | } |
7138 | ||
7a7be519 | 7139 | DEFUN (show_ip_ospf_database_max, |
7140 | show_ip_ospf_database_max_cmd, | |
f328dc60 | 7141 | "show ip ospf [vrf <NAME|all>] database <max-age|self-originate> [json]", |
7a7be519 | 7142 | SHOW_STR |
7143 | IP_STR | |
7144 | "OSPF information\n" | |
b5a8894d CS |
7145 | VRF_CMD_HELP_STR |
7146 | "All VRFs\n" | |
7a7be519 | 7147 | "Database summary\n" |
7148 | "LSAs in MaxAge list\n" | |
f328dc60 | 7149 | "Self-originated link states\n" |
7150 | JSON_STR) | |
7a7be519 | 7151 | { |
b5a8894d CS |
7152 | struct ospf *ospf = NULL; |
7153 | struct listnode *node = NULL; | |
7154 | char *vrf_name = NULL; | |
2951a7a4 | 7155 | bool all_vrf = false; |
b5a8894d CS |
7156 | int ret = CMD_SUCCESS; |
7157 | int inst = 0; | |
7158 | int idx_vrf = 0; | |
d7c0a89a | 7159 | uint8_t use_vrf = 0; |
f328dc60 | 7160 | bool uj = use_json(argc, argv); |
7161 | json_object *json = NULL; | |
7162 | ||
7163 | if (uj) | |
7164 | json = json_object_new_object(); | |
f412b39a | 7165 | |
43b8d1d8 | 7166 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
f412b39a | 7167 | |
b5a8894d | 7168 | if (vrf_name) { |
2951a7a4 | 7169 | bool ospf_output = false; |
874f58d8 | 7170 | |
b1c3ae8c | 7171 | use_vrf = 1; |
94d4c685 | 7172 | |
b5a8894d CS |
7173 | if (all_vrf) { |
7174 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
7175 | if (!ospf->oi_running) | |
7176 | continue; | |
2951a7a4 | 7177 | ospf_output = true; |
996c9314 LB |
7178 | ret = show_ip_ospf_database_common( |
7179 | vty, ospf, idx_vrf ? 2 : 0, argc, argv, | |
f328dc60 | 7180 | use_vrf, json, uj); |
b5a8894d | 7181 | } |
9f049418 DS |
7182 | |
7183 | if (!ospf_output) | |
7184 | vty_out(vty, "%% OSPF instance not found\n"); | |
b5a8894d CS |
7185 | } else { |
7186 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
9f049418 | 7187 | if (ospf == NULL || !ospf->oi_running) { |
94d4c685 | 7188 | vty_out(vty, "%% OSPF instance not found\n"); |
b5a8894d | 7189 | return CMD_SUCCESS; |
9f049418 | 7190 | } |
996c9314 | 7191 | ret = (show_ip_ospf_database_common( |
f328dc60 | 7192 | vty, ospf, idx_vrf ? 2 : 0, argc, argv, use_vrf, |
7193 | json, uj)); | |
b5a8894d CS |
7194 | } |
7195 | } else { | |
7196 | /* Display default ospf (instance 0) info */ | |
7197 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
9f049418 | 7198 | if (ospf == NULL || !ospf->oi_running) { |
94d4c685 | 7199 | vty_out(vty, "%% OSPF instance not found\n"); |
b5a8894d | 7200 | return CMD_SUCCESS; |
9f049418 DS |
7201 | } |
7202 | ||
b1c3ae8c | 7203 | ret = show_ip_ospf_database_common(vty, ospf, 0, argc, argv, |
f328dc60 | 7204 | use_vrf, json, uj); |
7205 | } | |
7206 | ||
7207 | if (uj) { | |
7208 | vty_out(vty, "%s\n", json_object_to_json_string(json)); | |
7209 | json_object_free(json); | |
b5a8894d CS |
7210 | } |
7211 | ||
7212 | return ret; | |
7a7be519 | 7213 | } |
f412b39a | 7214 | |
a11bce11 IR |
7215 | ALIAS (show_ip_ospf_database_max, |
7216 | show_ip_ospf_database_cmd, | |
7217 | "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 | 7218 | SHOW_STR |
7219 | IP_STR | |
7220 | "OSPF information\n" | |
b5a8894d | 7221 | VRF_CMD_HELP_STR |
a11bce11 | 7222 | "All VRFs\n" |
7a7be519 | 7223 | "Database summary\n" |
7224 | OSPF_LSA_TYPES_DESC | |
7225 | "Link State ID (as an IP address)\n" | |
7226 | "Self-originated link states\n" | |
7227 | "Advertising Router link states\n" | |
f328dc60 | 7228 | "Advertising Router (as an IP address)\n" |
7229 | JSON_STR) | |
7c8ff89e | 7230 | |
7a7be519 | 7231 | DEFUN (show_ip_ospf_instance_database_max, |
7232 | show_ip_ospf_instance_database_max_cmd, | |
f328dc60 | 7233 | "show ip ospf (1-65535) database <max-age|self-originate> [json]", |
7a7be519 | 7234 | SHOW_STR |
7235 | IP_STR | |
7236 | "OSPF information\n" | |
7237 | "Instance ID\n" | |
7238 | "Database summary\n" | |
7239 | "LSAs in MaxAge list\n" | |
f328dc60 | 7240 | "Self-originated link states\n" |
7241 | JSON_STR) | |
7a7be519 | 7242 | { |
d62a17ae | 7243 | int idx_number = 3; |
7244 | struct ospf *ospf; | |
d7c0a89a | 7245 | unsigned short instance = 0; |
f328dc60 | 7246 | bool uj = use_json(argc, argv); |
7247 | json_object *json = NULL; | |
7248 | ||
7249 | if (uj) | |
7250 | json = json_object_new_object(); | |
d62a17ae | 7251 | |
7252 | instance = strtoul(argv[idx_number]->arg, NULL, 10); | |
409f98ab | 7253 | if (instance != ospf_instance) |
ac28e4ec CS |
7254 | return CMD_NOT_MY_INSTANCE; |
7255 | ||
409f98ab IR |
7256 | ospf = ospf_lookup_instance(instance); |
7257 | if (!ospf || !ospf->oi_running) | |
d62a17ae | 7258 | return CMD_SUCCESS; |
7259 | ||
f328dc60 | 7260 | show_ip_ospf_database_common(vty, ospf, 1, argc, argv, 0, json, uj); |
7261 | ||
7262 | if (uj) { | |
7263 | vty_out(vty, "%s\n", | |
7264 | json_object_to_json_string_ext( | |
7265 | json, JSON_C_TO_STRING_PRETTY)); | |
7266 | json_object_free(json); | |
7267 | } | |
7268 | ||
7269 | return CMD_SUCCESS; | |
d62a17ae | 7270 | } |
7271 | ||
a11bce11 IR |
7272 | ALIAS (show_ip_ospf_instance_database_max, |
7273 | show_ip_ospf_instance_database_cmd, | |
7274 | "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]", | |
7275 | SHOW_STR | |
7276 | IP_STR | |
7277 | "OSPF information\n" | |
7278 | "Instance ID\n" | |
7279 | "Database summary\n" | |
7280 | OSPF_LSA_TYPES_DESC | |
7281 | "Link State ID (as an IP address)\n" | |
7282 | "Self-originated link states\n" | |
7283 | "Advertising Router link states\n" | |
7284 | "Advertising Router (as an IP address)\n" | |
7285 | JSON_STR) | |
d62a17ae | 7286 | |
7287 | static int show_ip_ospf_database_type_adv_router_common(struct vty *vty, | |
7288 | struct ospf *ospf, | |
7289 | int arg_base, int argc, | |
b1c3ae8c | 7290 | struct cmd_token **argv, |
f328dc60 | 7291 | uint8_t use_vrf, |
7292 | json_object *json, | |
7293 | bool uj) | |
d62a17ae | 7294 | { |
7295 | int idx_type = 4; | |
7296 | int type, ret; | |
7297 | struct in_addr adv_router; | |
ce513ac6 | 7298 | char buf[PREFIX_STRLEN]; |
f328dc60 | 7299 | json_object *json_vrf = NULL; |
d62a17ae | 7300 | |
f328dc60 | 7301 | if (uj) { |
7302 | if (use_vrf) | |
7303 | json_vrf = json_object_new_object(); | |
7304 | else | |
7305 | json_vrf = json; | |
7306 | } | |
d62a17ae | 7307 | |
f328dc60 | 7308 | if (ospf->instance) { |
7309 | if (uj) | |
7310 | json_object_int_add(json, "ospfInstance", | |
7311 | ospf->instance); | |
7312 | else | |
7313 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
7314 | } | |
87bd50e8 | 7315 | |
f328dc60 | 7316 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); |
7317 | ||
7318 | /* Show Router ID. */ | |
7319 | if (uj) { | |
7320 | json_object_string_add(json_vrf, "routerId", | |
ce513ac6 MS |
7321 | inet_ntop(AF_INET, &ospf->router_id, |
7322 | buf, sizeof(buf))); | |
f328dc60 | 7323 | } else { |
7324 | vty_out(vty, "\n OSPF Router with ID (%pI4)\n\n", | |
7325 | &ospf->router_id); | |
7326 | } | |
d62a17ae | 7327 | |
7328 | /* Set database type to show. */ | |
7329 | if (strncmp(argv[arg_base + idx_type]->text, "r", 1) == 0) | |
7330 | type = OSPF_ROUTER_LSA; | |
7331 | else if (strncmp(argv[arg_base + idx_type]->text, "ne", 2) == 0) | |
7332 | type = OSPF_NETWORK_LSA; | |
7333 | else if (strncmp(argv[arg_base + idx_type]->text, "ns", 2) == 0) | |
7334 | type = OSPF_AS_NSSA_LSA; | |
7335 | else if (strncmp(argv[arg_base + idx_type]->text, "s", 1) == 0) | |
7336 | type = OSPF_SUMMARY_LSA; | |
7337 | else if (strncmp(argv[arg_base + idx_type]->text, "a", 1) == 0) | |
7338 | type = OSPF_ASBR_SUMMARY_LSA; | |
7339 | else if (strncmp(argv[arg_base + idx_type]->text, "e", 1) == 0) | |
7340 | type = OSPF_AS_EXTERNAL_LSA; | |
7341 | else if (strncmp(argv[arg_base + idx_type]->text, "opaque-l", 8) == 0) | |
7342 | type = OSPF_OPAQUE_LINK_LSA; | |
7343 | else if (strncmp(argv[arg_base + idx_type]->text, "opaque-ar", 9) == 0) | |
7344 | type = OSPF_OPAQUE_AREA_LSA; | |
7345 | else if (strncmp(argv[arg_base + idx_type]->text, "opaque-as", 9) == 0) | |
7346 | type = OSPF_OPAQUE_AS_LSA; | |
7347 | else | |
7348 | return CMD_WARNING; | |
7c8ff89e | 7349 | |
d62a17ae | 7350 | /* `show ip ospf database LSA adv-router ADV_ROUTER'. */ |
7351 | if (strncmp(argv[arg_base + 5]->text, "s", 1) == 0) | |
7352 | adv_router = ospf->router_id; | |
7353 | else { | |
7354 | ret = inet_aton(argv[arg_base + 6]->arg, &adv_router); | |
7355 | if (!ret) | |
7356 | return CMD_WARNING; | |
7357 | } | |
7c8ff89e | 7358 | |
f328dc60 | 7359 | show_lsa_detail_adv_router(vty, ospf, type, &adv_router, json_vrf); |
7360 | ||
7361 | if (json) { | |
7362 | if (use_vrf) { | |
7363 | if (ospf->vrf_id == VRF_DEFAULT) | |
7364 | json_object_object_add(json, "default", | |
7365 | json_vrf); | |
7366 | else | |
7367 | json_object_object_add(json, ospf->name, | |
7368 | json_vrf); | |
7369 | } | |
7370 | } | |
7c8ff89e | 7371 | |
d62a17ae | 7372 | return CMD_SUCCESS; |
7c8ff89e DS |
7373 | } |
7374 | ||
a11bce11 IR |
7375 | DEFUN (show_ip_ospf_database_type_adv_router, |
7376 | show_ip_ospf_database_type_adv_router_cmd, | |
7377 | "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 |
7378 | SHOW_STR |
7379 | IP_STR | |
7380 | "OSPF information\n" | |
b5a8894d | 7381 | VRF_CMD_HELP_STR |
a11bce11 | 7382 | "All VRFs\n" |
7c8ff89e DS |
7383 | "Database summary\n" |
7384 | OSPF_LSA_TYPES_DESC | |
7385 | "Advertising Router link states\n" | |
3a2d747c | 7386 | "Advertising Router (as an IP address)\n" |
f328dc60 | 7387 | "Self-originated link states\n" |
7388 | JSON_STR) | |
7c8ff89e | 7389 | { |
b5a8894d | 7390 | struct ospf *ospf = NULL; |
b5a8894d CS |
7391 | struct listnode *node = NULL; |
7392 | char *vrf_name = NULL; | |
2951a7a4 | 7393 | bool all_vrf = false; |
b5a8894d CS |
7394 | int ret = CMD_SUCCESS; |
7395 | int inst = 0; | |
acaeb9fd | 7396 | int idx_vrf = 0; |
d7c0a89a | 7397 | uint8_t use_vrf = 0; |
f328dc60 | 7398 | bool uj = use_json(argc, argv); |
7399 | json_object *json = NULL; | |
7400 | ||
7401 | if (uj) | |
7402 | json = json_object_new_object(); | |
7c8ff89e | 7403 | |
43b8d1d8 CS |
7404 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
7405 | ||
b5a8894d | 7406 | if (vrf_name) { |
2951a7a4 | 7407 | bool ospf_output = false; |
874f58d8 | 7408 | |
b1c3ae8c | 7409 | use_vrf = 1; |
94d4c685 | 7410 | |
b5a8894d CS |
7411 | if (all_vrf) { |
7412 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
7413 | if (!ospf->oi_running) | |
7414 | continue; | |
2951a7a4 | 7415 | ospf_output = true; |
996c9314 | 7416 | ret = show_ip_ospf_database_type_adv_router_common( |
d68e47e1 LS |
7417 | vty, ospf, 2, argc, argv, use_vrf, json, |
7418 | uj); | |
b5a8894d | 7419 | } |
9f049418 DS |
7420 | if (!ospf_output) |
7421 | vty_out(vty, "%% OSPF instance not found\n"); | |
b5a8894d CS |
7422 | } else { |
7423 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
9f049418 | 7424 | if ((ospf == NULL) || !ospf->oi_running) { |
94d4c685 | 7425 | vty_out(vty, "%% OSPF instance not found\n"); |
b5a8894d | 7426 | return CMD_SUCCESS; |
9f049418 DS |
7427 | } |
7428 | ||
996c9314 | 7429 | ret = show_ip_ospf_database_type_adv_router_common( |
d68e47e1 | 7430 | vty, ospf, 2, argc, argv, use_vrf, json, uj); |
b5a8894d CS |
7431 | } |
7432 | } else { | |
7433 | /* Display default ospf (instance 0) info */ | |
7434 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
9f049418 | 7435 | if (ospf == NULL || !ospf->oi_running) { |
94d4c685 | 7436 | vty_out(vty, "%% OSPF instance not found\n"); |
b5a8894d | 7437 | return CMD_SUCCESS; |
9f049418 DS |
7438 | } |
7439 | ||
996c9314 | 7440 | ret = show_ip_ospf_database_type_adv_router_common( |
acaeb9fd | 7441 | vty, ospf, 0, argc, argv, use_vrf, json, uj); |
b5a8894d | 7442 | } |
f328dc60 | 7443 | |
7444 | if (uj) { | |
7445 | vty_out(vty, "%s\n", json_object_to_json_string(json)); | |
7446 | json_object_free(json); | |
7447 | } | |
7448 | ||
b5a8894d | 7449 | return ret; |
a11bce11 IR |
7450 | } |
7451 | ||
7452 | DEFUN (show_ip_ospf_instance_database_type_adv_router, | |
7453 | show_ip_ospf_instance_database_type_adv_router_cmd, | |
7454 | "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]", | |
7455 | SHOW_STR | |
7456 | IP_STR | |
7457 | "OSPF information\n" | |
7458 | "Instance ID\n" | |
7459 | "Database summary\n" | |
7460 | OSPF_LSA_TYPES_DESC | |
7461 | "Advertising Router link states\n" | |
7462 | "Advertising Router (as an IP address)\n" | |
7463 | "Self-originated link states\n" | |
7464 | JSON_STR) | |
7465 | { | |
7466 | int idx_number = 3; | |
7467 | struct ospf *ospf; | |
7468 | unsigned short instance = 0; | |
7469 | bool uj = use_json(argc, argv); | |
7470 | json_object *json = NULL; | |
7471 | ||
7472 | if (uj) | |
7473 | json = json_object_new_object(); | |
7474 | ||
7475 | instance = strtoul(argv[idx_number]->arg, NULL, 10); | |
7476 | if (instance != ospf_instance) | |
7477 | return CMD_NOT_MY_INSTANCE; | |
7478 | ||
7479 | ospf = ospf_lookup_instance(instance); | |
7480 | if (!ospf || !ospf->oi_running) | |
7481 | return CMD_SUCCESS; | |
7482 | ||
7483 | show_ip_ospf_database_type_adv_router_common(vty, ospf, 1, argc, argv, | |
7484 | 0, json, uj); | |
7485 | ||
7486 | if (uj) { | |
7487 | vty_out(vty, "%s\n", | |
7488 | json_object_to_json_string_ext( | |
7489 | json, JSON_C_TO_STRING_PRETTY)); | |
7490 | json_object_free(json); | |
7491 | } | |
7492 | ||
7493 | return CMD_SUCCESS; | |
718e3744 | 7494 | } |
7495 | ||
718e3744 | 7496 | DEFUN (ip_ospf_authentication_args, |
7497 | ip_ospf_authentication_args_addr_cmd, | |
7a7be519 | 7498 | "ip ospf authentication <null|message-digest> [A.B.C.D]", |
718e3744 | 7499 | "IP Information\n" |
7500 | "OSPF interface commands\n" | |
7501 | "Enable authentication on this interface\n" | |
7502 | "Use null authentication\n" | |
7503 | "Use message-digest authentication\n" | |
7a7be519 | 7504 | "Address of interface\n") |
718e3744 | 7505 | { |
d62a17ae | 7506 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7507 | int idx_encryption = 3; | |
7508 | int idx_ipv4 = 4; | |
7509 | struct in_addr addr; | |
7510 | int ret; | |
7511 | struct ospf_if_params *params; | |
7512 | ||
7513 | params = IF_DEF_PARAMS(ifp); | |
7514 | ||
7515 | if (argc == 5) { | |
7516 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
7517 | if (!ret) { | |
7518 | vty_out(vty, | |
7519 | "Please specify interface address by A.B.C.D\n"); | |
7520 | return CMD_WARNING_CONFIG_FAILED; | |
7521 | } | |
718e3744 | 7522 | |
d62a17ae | 7523 | params = ospf_get_if_params(ifp, addr); |
7524 | ospf_if_update_params(ifp, addr); | |
7525 | } | |
718e3744 | 7526 | |
d62a17ae | 7527 | /* Handle null authentication */ |
7528 | if (argv[idx_encryption]->arg[0] == 'n') { | |
7529 | SET_IF_PARAM(params, auth_type); | |
7530 | params->auth_type = OSPF_AUTH_NULL; | |
7531 | return CMD_SUCCESS; | |
7532 | } | |
718e3744 | 7533 | |
d62a17ae | 7534 | /* Handle message-digest authentication */ |
7535 | if (argv[idx_encryption]->arg[0] == 'm') { | |
7536 | SET_IF_PARAM(params, auth_type); | |
7537 | params->auth_type = OSPF_AUTH_CRYPTOGRAPHIC; | |
7538 | return CMD_SUCCESS; | |
7539 | } | |
718e3744 | 7540 | |
d62a17ae | 7541 | vty_out(vty, "You shouldn't get here!\n"); |
7542 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 7543 | } |
7544 | ||
718e3744 | 7545 | DEFUN (ip_ospf_authentication, |
7546 | ip_ospf_authentication_addr_cmd, | |
7a7be519 | 7547 | "ip ospf authentication [A.B.C.D]", |
718e3744 | 7548 | "IP Information\n" |
7549 | "OSPF interface commands\n" | |
7550 | "Enable authentication on this interface\n" | |
efd7904e | 7551 | "Address of interface\n") |
718e3744 | 7552 | { |
d62a17ae | 7553 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7554 | int idx_ipv4 = 3; | |
7555 | struct in_addr addr; | |
7556 | int ret; | |
7557 | struct ospf_if_params *params; | |
7558 | ||
7559 | params = IF_DEF_PARAMS(ifp); | |
7560 | ||
7561 | if (argc == 4) { | |
7562 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
7563 | if (!ret) { | |
7564 | vty_out(vty, | |
7565 | "Please specify interface address by A.B.C.D\n"); | |
7566 | return CMD_WARNING_CONFIG_FAILED; | |
7567 | } | |
7568 | ||
7569 | params = ospf_get_if_params(ifp, addr); | |
7570 | ospf_if_update_params(ifp, addr); | |
718e3744 | 7571 | } |
7572 | ||
d62a17ae | 7573 | SET_IF_PARAM(params, auth_type); |
7574 | params->auth_type = OSPF_AUTH_SIMPLE; | |
718e3744 | 7575 | |
d62a17ae | 7576 | return CMD_SUCCESS; |
718e3744 | 7577 | } |
7578 | ||
b4a039bf DS |
7579 | DEFUN (no_ip_ospf_authentication_args, |
7580 | no_ip_ospf_authentication_args_addr_cmd, | |
7a7be519 | 7581 | "no ip ospf authentication <null|message-digest> [A.B.C.D]", |
b4a039bf DS |
7582 | NO_STR |
7583 | "IP Information\n" | |
7584 | "OSPF interface commands\n" | |
7585 | "Enable authentication on this interface\n" | |
7586 | "Use null authentication\n" | |
7587 | "Use message-digest authentication\n" | |
efd7904e | 7588 | "Address of interface\n") |
b4a039bf | 7589 | { |
d62a17ae | 7590 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7591 | int idx_encryption = 4; | |
7592 | int idx_ipv4 = 5; | |
7593 | struct in_addr addr; | |
7594 | int ret; | |
7595 | struct ospf_if_params *params; | |
7596 | struct route_node *rn; | |
7597 | int auth_type; | |
7598 | ||
7599 | params = IF_DEF_PARAMS(ifp); | |
7600 | ||
7601 | if (argc == 6) { | |
7602 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
7603 | if (!ret) { | |
7604 | vty_out(vty, | |
7605 | "Please specify interface address by A.B.C.D\n"); | |
7606 | return CMD_WARNING_CONFIG_FAILED; | |
7607 | } | |
b4a039bf | 7608 | |
d62a17ae | 7609 | params = ospf_lookup_if_params(ifp, addr); |
7610 | if (params == NULL) { | |
7611 | vty_out(vty, "Ip Address specified is unknown\n"); | |
7612 | return CMD_WARNING_CONFIG_FAILED; | |
7613 | } | |
7614 | params->auth_type = OSPF_AUTH_NOTSET; | |
7615 | UNSET_IF_PARAM(params, auth_type); | |
7616 | if (params != IF_DEF_PARAMS(ifp)) { | |
7617 | ospf_free_if_params(ifp, addr); | |
7618 | ospf_if_update_params(ifp, addr); | |
7619 | } | |
7620 | } else { | |
7621 | if (argv[idx_encryption]->arg[0] == 'n') { | |
7622 | auth_type = OSPF_AUTH_NULL; | |
7623 | } else if (argv[idx_encryption]->arg[0] == 'm') { | |
7624 | auth_type = OSPF_AUTH_CRYPTOGRAPHIC; | |
7625 | } else { | |
7626 | vty_out(vty, "Unexpected input encountered\n"); | |
7627 | return CMD_WARNING_CONFIG_FAILED; | |
7628 | } | |
7629 | /* | |
7630 | * Here we have a case where the user has entered | |
7631 | * 'no ip ospf authentication (null | message_digest )' | |
7632 | * we need to find if we have any ip addresses underneath it | |
7633 | * that | |
7634 | * correspond to the associated type. | |
7635 | */ | |
7636 | if (params->auth_type == auth_type) { | |
7637 | params->auth_type = OSPF_AUTH_NOTSET; | |
7638 | UNSET_IF_PARAM(params, auth_type); | |
7639 | } | |
7640 | ||
7641 | for (rn = route_top(IF_OIFS_PARAMS(ifp)); rn; | |
7642 | rn = route_next(rn)) { | |
7643 | if ((params = rn->info)) { | |
7644 | if (params->auth_type == auth_type) { | |
7645 | params->auth_type = OSPF_AUTH_NOTSET; | |
7646 | UNSET_IF_PARAM(params, auth_type); | |
7647 | if (params != IF_DEF_PARAMS(ifp)) { | |
7648 | ospf_free_if_params( | |
7649 | ifp, rn->p.u.prefix4); | |
7650 | ospf_if_update_params( | |
7651 | ifp, rn->p.u.prefix4); | |
7652 | } | |
7653 | } | |
7654 | } | |
b4a039bf | 7655 | } |
b4a039bf | 7656 | } |
b4a039bf | 7657 | |
d62a17ae | 7658 | return CMD_SUCCESS; |
b4a039bf DS |
7659 | } |
7660 | ||
718e3744 | 7661 | DEFUN (no_ip_ospf_authentication, |
7662 | no_ip_ospf_authentication_addr_cmd, | |
7a7be519 | 7663 | "no ip ospf authentication [A.B.C.D]", |
718e3744 | 7664 | NO_STR |
7665 | "IP Information\n" | |
7666 | "OSPF interface commands\n" | |
7667 | "Enable authentication on this interface\n" | |
efd7904e | 7668 | "Address of interface\n") |
718e3744 | 7669 | { |
d62a17ae | 7670 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7671 | int idx_ipv4 = 4; | |
7672 | struct in_addr addr; | |
7673 | int ret; | |
7674 | struct ospf_if_params *params; | |
7675 | struct route_node *rn; | |
7676 | ||
7677 | params = IF_DEF_PARAMS(ifp); | |
7678 | ||
7679 | if (argc == 5) { | |
7680 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
7681 | if (!ret) { | |
7682 | vty_out(vty, | |
7683 | "Please specify interface address by A.B.C.D\n"); | |
7684 | return CMD_WARNING_CONFIG_FAILED; | |
7685 | } | |
718e3744 | 7686 | |
d62a17ae | 7687 | params = ospf_lookup_if_params(ifp, addr); |
7688 | if (params == NULL) { | |
7689 | vty_out(vty, "Ip Address specified is unknown\n"); | |
7690 | return CMD_WARNING_CONFIG_FAILED; | |
7691 | } | |
718e3744 | 7692 | |
d62a17ae | 7693 | params->auth_type = OSPF_AUTH_NOTSET; |
7694 | UNSET_IF_PARAM(params, auth_type); | |
7695 | if (params != IF_DEF_PARAMS(ifp)) { | |
7696 | ospf_free_if_params(ifp, addr); | |
7697 | ospf_if_update_params(ifp, addr); | |
7698 | } | |
7699 | } else { | |
7700 | /* | |
7701 | * When a user enters 'no ip ospf authentication' | |
7702 | * We should remove all authentication types from | |
7703 | * the interface. | |
7704 | */ | |
7705 | if ((params->auth_type == OSPF_AUTH_NULL) | |
7706 | || (params->auth_type == OSPF_AUTH_CRYPTOGRAPHIC) | |
7707 | || (params->auth_type == OSPF_AUTH_SIMPLE)) { | |
7708 | params->auth_type = OSPF_AUTH_NOTSET; | |
7709 | UNSET_IF_PARAM(params, auth_type); | |
7710 | } | |
813d4307 | 7711 | |
d62a17ae | 7712 | for (rn = route_top(IF_OIFS_PARAMS(ifp)); rn; |
7713 | rn = route_next(rn)) { | |
7714 | if ((params = rn->info)) { | |
7715 | ||
7716 | if ((params->auth_type == OSPF_AUTH_NULL) | |
7717 | || (params->auth_type | |
7718 | == OSPF_AUTH_CRYPTOGRAPHIC) | |
7719 | || (params->auth_type | |
7720 | == OSPF_AUTH_SIMPLE)) { | |
7721 | params->auth_type = OSPF_AUTH_NOTSET; | |
7722 | UNSET_IF_PARAM(params, auth_type); | |
7723 | if (params != IF_DEF_PARAMS(ifp)) { | |
7724 | ospf_free_if_params( | |
7725 | ifp, rn->p.u.prefix4); | |
7726 | ospf_if_update_params( | |
7727 | ifp, rn->p.u.prefix4); | |
7728 | } | |
7729 | } | |
7730 | } | |
b4a039bf | 7731 | } |
b4a039bf | 7732 | } |
d62a17ae | 7733 | |
7734 | return CMD_SUCCESS; | |
718e3744 | 7735 | } |
7736 | ||
0d829fa7 | 7737 | |
718e3744 | 7738 | DEFUN (ip_ospf_authentication_key, |
7739 | ip_ospf_authentication_key_addr_cmd, | |
7a7be519 | 7740 | "ip ospf authentication-key AUTH_KEY [A.B.C.D]", |
718e3744 | 7741 | "IP Information\n" |
7742 | "OSPF interface commands\n" | |
7743 | "Authentication password (key)\n" | |
7744 | "The OSPF password (key)\n" | |
efd7904e | 7745 | "Address of interface\n") |
718e3744 | 7746 | { |
d62a17ae | 7747 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7748 | int idx = 0; | |
7749 | struct in_addr addr; | |
7750 | struct ospf_if_params *params; | |
718e3744 | 7751 | |
d62a17ae | 7752 | params = IF_DEF_PARAMS(ifp); |
7753 | ||
7754 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
7755 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
7756 | vty_out(vty, | |
7757 | "Please specify interface address by A.B.C.D\n"); | |
7758 | return CMD_WARNING_CONFIG_FAILED; | |
7759 | } | |
718e3744 | 7760 | |
d62a17ae | 7761 | params = ospf_get_if_params(ifp, addr); |
7762 | ospf_if_update_params(ifp, addr); | |
7763 | } | |
718e3744 | 7764 | |
4d65d927 QY |
7765 | strlcpy((char *)params->auth_simple, argv[3]->arg, |
7766 | sizeof(params->auth_simple)); | |
d62a17ae | 7767 | SET_IF_PARAM(params, auth_simple); |
718e3744 | 7768 | |
d62a17ae | 7769 | return CMD_SUCCESS; |
718e3744 | 7770 | } |
7771 | ||
7a7be519 | 7772 | DEFUN_HIDDEN (ospf_authentication_key, |
747e489c | 7773 | ospf_authentication_key_cmd, |
0d829fa7 | 7774 | "ospf authentication-key AUTH_KEY [A.B.C.D]", |
747e489c | 7775 | "OSPF interface commands\n" |
baf9eaad | 7776 | VLINK_HELPSTR_AUTH_SIMPLE |
0d829fa7 | 7777 | "Address of interface\n") |
718e3744 | 7778 | { |
d62a17ae | 7779 | return ip_ospf_authentication_key(self, vty, argc, argv); |
718e3744 | 7780 | } |
7781 | ||
7a7be519 | 7782 | DEFUN (no_ip_ospf_authentication_key, |
7783 | no_ip_ospf_authentication_key_authkey_addr_cmd, | |
7784 | "no ip ospf authentication-key [AUTH_KEY [A.B.C.D]]", | |
7785 | NO_STR | |
7786 | "IP Information\n" | |
7787 | "OSPF interface commands\n" | |
baf9eaad CS |
7788 | VLINK_HELPSTR_AUTH_SIMPLE |
7789 | "Address of interface\n") | |
7a7be519 | 7790 | { |
d62a17ae | 7791 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7792 | int idx = 0; | |
7793 | struct in_addr addr; | |
7794 | struct ospf_if_params *params; | |
7795 | params = IF_DEF_PARAMS(ifp); | |
7796 | ||
7797 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
7798 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
7799 | vty_out(vty, | |
7800 | "Please specify interface address by A.B.C.D\n"); | |
7801 | return CMD_WARNING_CONFIG_FAILED; | |
7802 | } | |
7a7be519 | 7803 | |
d62a17ae | 7804 | params = ospf_lookup_if_params(ifp, addr); |
7805 | if (params == NULL) | |
7806 | return CMD_SUCCESS; | |
7a7be519 | 7807 | } |
813d4307 | 7808 | |
d62a17ae | 7809 | memset(params->auth_simple, 0, OSPF_AUTH_SIMPLE_SIZE); |
7810 | UNSET_IF_PARAM(params, auth_simple); | |
718e3744 | 7811 | |
d62a17ae | 7812 | if (params != IF_DEF_PARAMS(ifp)) { |
7813 | ospf_free_if_params(ifp, addr); | |
7814 | ospf_if_update_params(ifp, addr); | |
7815 | } | |
813d4307 | 7816 | |
d62a17ae | 7817 | return CMD_SUCCESS; |
7a7be519 | 7818 | } |
813d4307 | 7819 | |
0d829fa7 QY |
7820 | DEFUN_HIDDEN (no_ospf_authentication_key, |
7821 | no_ospf_authentication_key_authkey_addr_cmd, | |
7822 | "no ospf authentication-key [AUTH_KEY [A.B.C.D]]", | |
7823 | NO_STR | |
7824 | "OSPF interface commands\n" | |
baf9eaad CS |
7825 | VLINK_HELPSTR_AUTH_SIMPLE |
7826 | "Address of interface\n") | |
0d829fa7 | 7827 | { |
d62a17ae | 7828 | return no_ip_ospf_authentication_key(self, vty, argc, argv); |
0d829fa7 QY |
7829 | } |
7830 | ||
718e3744 | 7831 | DEFUN (ip_ospf_message_digest_key, |
537eae3f | 7832 | ip_ospf_message_digest_key_cmd, |
7a7be519 | 7833 | "ip ospf message-digest-key (1-255) md5 KEY [A.B.C.D]", |
718e3744 | 7834 | "IP Information\n" |
7835 | "OSPF interface commands\n" | |
7836 | "Message digest authentication password (key)\n" | |
7837 | "Key ID\n" | |
7838 | "Use MD5 algorithm\n" | |
fefa0d82 QY |
7839 | "The OSPF password (key)\n" |
7840 | "Address of interface\n") | |
718e3744 | 7841 | { |
d62a17ae | 7842 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7843 | struct crypt_key *ck; | |
d7c0a89a | 7844 | uint8_t key_id; |
d62a17ae | 7845 | struct in_addr addr; |
7846 | struct ospf_if_params *params; | |
7847 | ||
7848 | params = IF_DEF_PARAMS(ifp); | |
7849 | int idx = 0; | |
7850 | ||
7851 | argv_find(argv, argc, "(1-255)", &idx); | |
7852 | char *keyid = argv[idx]->arg; | |
7853 | argv_find(argv, argc, "KEY", &idx); | |
7854 | char *cryptkey = argv[idx]->arg; | |
7855 | ||
7856 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
7857 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
7858 | vty_out(vty, | |
7859 | "Please specify interface address by A.B.C.D\n"); | |
7860 | return CMD_WARNING_CONFIG_FAILED; | |
7861 | } | |
7862 | ||
7863 | params = ospf_get_if_params(ifp, addr); | |
7864 | ospf_if_update_params(ifp, addr); | |
718e3744 | 7865 | } |
7866 | ||
d62a17ae | 7867 | key_id = strtol(keyid, NULL, 10); |
519b1464 MS |
7868 | |
7869 | /* Remove existing key, if any */ | |
7870 | ospf_crypt_key_delete(params->auth_crypt, key_id); | |
718e3744 | 7871 | |
d62a17ae | 7872 | ck = ospf_crypt_key_new(); |
d7c0a89a | 7873 | ck->key_id = (uint8_t)key_id; |
4d65d927 | 7874 | strlcpy((char *)ck->auth_key, cryptkey, sizeof(ck->auth_key)); |
718e3744 | 7875 | |
d62a17ae | 7876 | ospf_crypt_key_add(params->auth_crypt, ck); |
7877 | SET_IF_PARAM(params, auth_crypt); | |
718e3744 | 7878 | |
d62a17ae | 7879 | return CMD_SUCCESS; |
718e3744 | 7880 | } |
7881 | ||
7a7be519 | 7882 | DEFUN_HIDDEN (ospf_message_digest_key, |
747e489c | 7883 | ospf_message_digest_key_cmd, |
0d829fa7 | 7884 | "ospf message-digest-key (1-255) md5 KEY [A.B.C.D]", |
747e489c DW |
7885 | "OSPF interface commands\n" |
7886 | "Message digest authentication password (key)\n" | |
7887 | "Key ID\n" | |
7888 | "Use MD5 algorithm\n" | |
0d829fa7 QY |
7889 | "The OSPF password (key)\n" |
7890 | "Address of interface\n") | |
7a7be519 | 7891 | { |
d62a17ae | 7892 | return ip_ospf_message_digest_key(self, vty, argc, argv); |
7a7be519 | 7893 | } |
718e3744 | 7894 | |
537eae3f QY |
7895 | DEFUN (no_ip_ospf_message_digest_key, |
7896 | no_ip_ospf_message_digest_key_cmd, | |
0d829fa7 | 7897 | "no ip ospf message-digest-key (1-255) [md5 KEY] [A.B.C.D]", |
813d4307 DW |
7898 | NO_STR |
7899 | "IP Information\n" | |
7900 | "OSPF interface commands\n" | |
7901 | "Message digest authentication password (key)\n" | |
7902 | "Key ID\n" | |
7903 | "Use MD5 algorithm\n" | |
0d829fa7 QY |
7904 | "The OSPF password (key)\n" |
7905 | "Address of interface\n") | |
813d4307 | 7906 | { |
d62a17ae | 7907 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7908 | int idx = 0; | |
7909 | struct crypt_key *ck; | |
7910 | int key_id; | |
7911 | struct in_addr addr; | |
7912 | struct ospf_if_params *params; | |
7913 | params = IF_DEF_PARAMS(ifp); | |
7914 | ||
7915 | argv_find(argv, argc, "(1-255)", &idx); | |
7916 | char *keyid = argv[idx]->arg; | |
7917 | ||
7918 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
7919 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
7920 | vty_out(vty, | |
7921 | "Please specify interface address by A.B.C.D\n"); | |
7922 | return CMD_WARNING_CONFIG_FAILED; | |
7923 | } | |
7a7be519 | 7924 | |
d62a17ae | 7925 | params = ospf_lookup_if_params(ifp, addr); |
7926 | if (params == NULL) | |
7927 | return CMD_SUCCESS; | |
7a7be519 | 7928 | } |
7929 | ||
d62a17ae | 7930 | key_id = strtol(keyid, NULL, 10); |
7931 | ck = ospf_crypt_key_lookup(params->auth_crypt, key_id); | |
7932 | if (ck == NULL) { | |
7933 | vty_out(vty, "OSPF: Key %d does not exist\n", key_id); | |
7934 | return CMD_WARNING_CONFIG_FAILED; | |
7935 | } | |
7a7be519 | 7936 | |
d62a17ae | 7937 | ospf_crypt_key_delete(params->auth_crypt, key_id); |
7a7be519 | 7938 | |
d62a17ae | 7939 | if (params != IF_DEF_PARAMS(ifp)) { |
7940 | ospf_free_if_params(ifp, addr); | |
7941 | ospf_if_update_params(ifp, addr); | |
7942 | } | |
7a7be519 | 7943 | |
d62a17ae | 7944 | return CMD_SUCCESS; |
7a7be519 | 7945 | } |
813d4307 | 7946 | |
0d829fa7 | 7947 | DEFUN_HIDDEN (no_ospf_message_digest_key, |
537eae3f | 7948 | no_ospf_message_digest_key_cmd, |
0d829fa7 QY |
7949 | "no ospf message-digest-key (1-255) [md5 KEY] [A.B.C.D]", |
7950 | NO_STR | |
7951 | "OSPF interface commands\n" | |
7952 | "Message digest authentication password (key)\n" | |
7953 | "Key ID\n" | |
efd7904e RW |
7954 | "Use MD5 algorithm\n" |
7955 | "The OSPF password (key)\n" | |
7956 | "Address of interface\n") | |
718e3744 | 7957 | { |
d62a17ae | 7958 | return no_ip_ospf_message_digest_key(self, vty, argc, argv); |
718e3744 | 7959 | } |
7960 | ||
718e3744 | 7961 | DEFUN (ip_ospf_cost, |
5c2fc921 | 7962 | ip_ospf_cost_cmd, |
7a7be519 | 7963 | "ip ospf cost (1-65535) [A.B.C.D]", |
718e3744 | 7964 | "IP Information\n" |
7965 | "OSPF interface commands\n" | |
7966 | "Interface cost\n" | |
7967 | "Cost\n" | |
5c2fc921 | 7968 | "Address of interface\n") |
718e3744 | 7969 | { |
d62a17ae | 7970 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7971 | int idx = 0; | |
d7c0a89a | 7972 | uint32_t cost = OSPF_OUTPUT_COST_DEFAULT; |
d62a17ae | 7973 | struct in_addr addr; |
7974 | struct ospf_if_params *params; | |
7975 | params = IF_DEF_PARAMS(ifp); | |
7976 | ||
7977 | // get arguments | |
7978 | char *coststr = NULL, *ifaddr = NULL; | |
35955c14 | 7979 | |
c31a793b VJ |
7980 | argv_find(argv, argc, "(1-65535)", &idx); |
7981 | coststr = argv[idx]->arg; | |
d62a17ae | 7982 | cost = strtol(coststr, NULL, 10); |
7983 | ||
c31a793b | 7984 | ifaddr = argv_find(argv, argc, "A.B.C.D", &idx) ? argv[idx]->arg : NULL; |
d62a17ae | 7985 | if (ifaddr) { |
7986 | if (!inet_aton(ifaddr, &addr)) { | |
7987 | vty_out(vty, | |
7988 | "Please specify interface address by A.B.C.D\n"); | |
7989 | return CMD_WARNING_CONFIG_FAILED; | |
7990 | } | |
718e3744 | 7991 | |
d62a17ae | 7992 | params = ospf_get_if_params(ifp, addr); |
7993 | ospf_if_update_params(ifp, addr); | |
718e3744 | 7994 | } |
7995 | ||
d62a17ae | 7996 | SET_IF_PARAM(params, output_cost_cmd); |
7997 | params->output_cost_cmd = cost; | |
718e3744 | 7998 | |
d62a17ae | 7999 | ospf_if_recalculate_output_cost(ifp); |
5c2fc921 | 8000 | |
d62a17ae | 8001 | return CMD_SUCCESS; |
718e3744 | 8002 | } |
8003 | ||
7a7be519 | 8004 | DEFUN_HIDDEN (ospf_cost, |
5c2fc921 QY |
8005 | ospf_cost_cmd, |
8006 | "ospf cost (1-65535) [A.B.C.D]", | |
747e489c DW |
8007 | "OSPF interface commands\n" |
8008 | "Interface cost\n" | |
8009 | "Cost\n" | |
5c2fc921 | 8010 | "Address of interface\n") |
7a7be519 | 8011 | { |
d62a17ae | 8012 | return ip_ospf_cost(self, vty, argc, argv); |
7a7be519 | 8013 | } |
9eff36b3 | 8014 | |
718e3744 | 8015 | DEFUN (no_ip_ospf_cost, |
5c2fc921 QY |
8016 | no_ip_ospf_cost_cmd, |
8017 | "no ip ospf cost [(1-65535)] [A.B.C.D]", | |
718e3744 | 8018 | NO_STR |
efd7904e | 8019 | "IP Information\n" |
718e3744 | 8020 | "OSPF interface commands\n" |
8021 | "Interface cost\n" | |
efd7904e RW |
8022 | "Cost\n" |
8023 | "Address of interface\n") | |
718e3744 | 8024 | { |
d62a17ae | 8025 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8026 | int idx = 0; | |
8027 | struct in_addr addr; | |
8028 | struct ospf_if_params *params; | |
7a7be519 | 8029 | |
d62a17ae | 8030 | params = IF_DEF_PARAMS(ifp); |
718e3744 | 8031 | |
d62a17ae | 8032 | // get arguments |
8033 | char *ifaddr = NULL; | |
8034 | ifaddr = argv_find(argv, argc, "A.B.C.D", &idx) ? argv[idx]->arg : NULL; | |
718e3744 | 8035 | |
d62a17ae | 8036 | /* According to the semantics we are mimicking "no ip ospf cost N" is |
8037 | * always treated as "no ip ospf cost" regardless of the actual value | |
8038 | * of N already configured for the interface. Thus ignore cost. */ | |
7a7be519 | 8039 | |
d62a17ae | 8040 | if (ifaddr) { |
8041 | if (!inet_aton(ifaddr, &addr)) { | |
8042 | vty_out(vty, | |
8043 | "Please specify interface address by A.B.C.D\n"); | |
8044 | return CMD_WARNING_CONFIG_FAILED; | |
8045 | } | |
7a7be519 | 8046 | |
d62a17ae | 8047 | params = ospf_lookup_if_params(ifp, addr); |
8048 | if (params == NULL) | |
8049 | return CMD_SUCCESS; | |
8050 | } | |
7a7be519 | 8051 | |
d62a17ae | 8052 | UNSET_IF_PARAM(params, output_cost_cmd); |
7a7be519 | 8053 | |
d62a17ae | 8054 | if (params != IF_DEF_PARAMS(ifp)) { |
8055 | ospf_free_if_params(ifp, addr); | |
8056 | ospf_if_update_params(ifp, addr); | |
8057 | } | |
7a7be519 | 8058 | |
d62a17ae | 8059 | ospf_if_recalculate_output_cost(ifp); |
7a7be519 | 8060 | |
d62a17ae | 8061 | return CMD_SUCCESS; |
7a7be519 | 8062 | } |
9eff36b3 | 8063 | |
5c2fc921 QY |
8064 | DEFUN_HIDDEN (no_ospf_cost, |
8065 | no_ospf_cost_cmd, | |
8066 | "no ospf cost [(1-65535)] [A.B.C.D]", | |
8067 | NO_STR | |
8068 | "OSPF interface commands\n" | |
8069 | "Interface cost\n" | |
8070 | "Cost\n" | |
8071 | "Address of interface\n") | |
827341b7 | 8072 | { |
d62a17ae | 8073 | return no_ip_ospf_cost(self, vty, argc, argv); |
827341b7 DO |
8074 | } |
8075 | ||
d62a17ae | 8076 | static void ospf_nbr_timer_update(struct ospf_interface *oi) |
718e3744 | 8077 | { |
d62a17ae | 8078 | struct route_node *rn; |
8079 | struct ospf_neighbor *nbr; | |
718e3744 | 8080 | |
d62a17ae | 8081 | for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) |
8082 | if ((nbr = rn->info)) { | |
8083 | nbr->v_inactivity = OSPF_IF_PARAM(oi, v_wait); | |
8084 | nbr->v_db_desc = OSPF_IF_PARAM(oi, retransmit_interval); | |
8085 | nbr->v_ls_req = OSPF_IF_PARAM(oi, retransmit_interval); | |
8086 | nbr->v_ls_upd = OSPF_IF_PARAM(oi, retransmit_interval); | |
8087 | } | |
718e3744 | 8088 | } |
8089 | ||
d62a17ae | 8090 | static int ospf_vty_dead_interval_set(struct vty *vty, const char *interval_str, |
8091 | const char *nbr_str, | |
8092 | const char *fast_hello_str) | |
8093 | { | |
8094 | VTY_DECLVAR_CONTEXT(interface, ifp); | |
d7c0a89a QY |
8095 | uint32_t seconds; |
8096 | uint8_t hellomult; | |
d62a17ae | 8097 | struct in_addr addr; |
8098 | int ret; | |
8099 | struct ospf_if_params *params; | |
8100 | struct ospf_interface *oi; | |
8101 | struct route_node *rn; | |
718e3744 | 8102 | |
d62a17ae | 8103 | params = IF_DEF_PARAMS(ifp); |
8104 | ||
8105 | if (nbr_str) { | |
8106 | ret = inet_aton(nbr_str, &addr); | |
8107 | if (!ret) { | |
8108 | vty_out(vty, | |
8109 | "Please specify interface address by A.B.C.D\n"); | |
8110 | return CMD_WARNING_CONFIG_FAILED; | |
8111 | } | |
8112 | ||
8113 | params = ospf_get_if_params(ifp, addr); | |
8114 | ospf_if_update_params(ifp, addr); | |
8115 | } | |
8116 | ||
8117 | if (interval_str) { | |
8118 | seconds = strtoul(interval_str, NULL, 10); | |
8119 | ||
8120 | /* reset fast_hello too, just to be sure */ | |
8121 | UNSET_IF_PARAM(params, fast_hello); | |
8122 | params->fast_hello = OSPF_FAST_HELLO_DEFAULT; | |
8123 | } else if (fast_hello_str) { | |
8124 | hellomult = strtoul(fast_hello_str, NULL, 10); | |
8125 | /* 1s dead-interval with sub-second hellos desired */ | |
8126 | seconds = OSPF_ROUTER_DEAD_INTERVAL_MINIMAL; | |
8127 | SET_IF_PARAM(params, fast_hello); | |
8128 | params->fast_hello = hellomult; | |
8129 | } else { | |
8130 | vty_out(vty, | |
8131 | "Please specify dead-interval or hello-multiplier\n"); | |
8132 | return CMD_WARNING_CONFIG_FAILED; | |
8133 | } | |
8134 | ||
8135 | SET_IF_PARAM(params, v_wait); | |
8136 | params->v_wait = seconds; | |
182d6bdc | 8137 | params->is_v_wait_set = true; |
d62a17ae | 8138 | |
8139 | /* Update timer values in neighbor structure. */ | |
8140 | if (nbr_str) { | |
b5a8894d CS |
8141 | struct ospf *ospf = NULL; |
8142 | ||
a36898e7 | 8143 | ospf = ospf_lookup_by_vrf_id(ifp->vrf_id); |
b5a8894d | 8144 | if (ospf) { |
d62a17ae | 8145 | oi = ospf_if_lookup_by_local_addr(ospf, ifp, addr); |
8146 | if (oi) | |
8147 | ospf_nbr_timer_update(oi); | |
8148 | } | |
8149 | } else { | |
8150 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) | |
8151 | if ((oi = rn->info)) | |
8152 | ospf_nbr_timer_update(oi); | |
8153 | } | |
8154 | ||
8155 | return CMD_SUCCESS; | |
718e3744 | 8156 | } |
8157 | ||
f9ad937f | 8158 | DEFUN (ip_ospf_dead_interval, |
0d829fa7 | 8159 | ip_ospf_dead_interval_cmd, |
7a7be519 | 8160 | "ip ospf dead-interval (1-65535) [A.B.C.D]", |
f9ad937f | 8161 | "IP Information\n" |
8162 | "OSPF interface commands\n" | |
99a522c7 | 8163 | "Interval time after which a neighbor is declared down\n" |
f9ad937f | 8164 | "Seconds\n" |
8165 | "Address of interface\n") | |
8166 | { | |
d62a17ae | 8167 | int idx = 0; |
8168 | char *interval = argv_find(argv, argc, "(1-65535)", &idx) | |
8169 | ? argv[idx]->arg | |
8170 | : NULL; | |
8171 | char *ifaddr = | |
8172 | argv_find(argv, argc, "A.B.C.D", &idx) ? argv[idx]->arg : NULL; | |
8173 | return ospf_vty_dead_interval_set(vty, interval, ifaddr, NULL); | |
f9ad937f | 8174 | } |
8175 | ||
718e3744 | 8176 | |
7a7be519 | 8177 | DEFUN_HIDDEN (ospf_dead_interval, |
747e489c | 8178 | ospf_dead_interval_cmd, |
0d829fa7 | 8179 | "ospf dead-interval (1-65535) [A.B.C.D]", |
747e489c | 8180 | "OSPF interface commands\n" |
99a522c7 | 8181 | "Interval time after which a neighbor is declared down\n" |
0d829fa7 QY |
8182 | "Seconds\n" |
8183 | "Address of interface\n") | |
7a7be519 | 8184 | { |
d62a17ae | 8185 | return ip_ospf_dead_interval(self, vty, argc, argv); |
7a7be519 | 8186 | } |
718e3744 | 8187 | |
f9ad937f | 8188 | DEFUN (ip_ospf_dead_interval_minimal, |
8189 | ip_ospf_dead_interval_minimal_addr_cmd, | |
7a7be519 | 8190 | "ip ospf dead-interval minimal hello-multiplier (1-10) [A.B.C.D]", |
f9ad937f | 8191 | "IP Information\n" |
8192 | "OSPF interface commands\n" | |
99a522c7 | 8193 | "Interval time after which a neighbor is declared down\n" |
f9ad937f | 8194 | "Minimal 1s dead-interval with fast sub-second hellos\n" |
8195 | "Hello multiplier factor\n" | |
8196 | "Number of Hellos to send each second\n" | |
8197 | "Address of interface\n") | |
8198 | { | |
d62a17ae | 8199 | int idx_number = 5; |
8200 | int idx_ipv4 = 6; | |
8201 | if (argc == 7) | |
8202 | return ospf_vty_dead_interval_set( | |
8203 | vty, NULL, argv[idx_ipv4]->arg, argv[idx_number]->arg); | |
8204 | else | |
8205 | return ospf_vty_dead_interval_set(vty, NULL, NULL, | |
8206 | argv[idx_number]->arg); | |
f9ad937f | 8207 | } |
8208 | ||
718e3744 | 8209 | DEFUN (no_ip_ospf_dead_interval, |
0d829fa7 | 8210 | no_ip_ospf_dead_interval_cmd, |
e83a9414 | 8211 | "no ip ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]", |
718e3744 | 8212 | NO_STR |
8213 | "IP Information\n" | |
8214 | "OSPF interface commands\n" | |
99a522c7 | 8215 | "Interval time after which a neighbor is declared down\n" |
f9dfba8d | 8216 | "Seconds\n" |
efd7904e RW |
8217 | "Minimal 1s dead-interval with fast sub-second hellos\n" |
8218 | "Hello multiplier factor\n" | |
8219 | "Number of Hellos to send each second\n" | |
8220 | "Address of interface\n") | |
718e3744 | 8221 | { |
d62a17ae | 8222 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8223 | int idx_ipv4 = argc - 1; | |
8224 | struct in_addr addr = {.s_addr = 0L}; | |
8225 | int ret; | |
8226 | struct ospf_if_params *params; | |
8227 | struct ospf_interface *oi; | |
8228 | struct route_node *rn; | |
8229 | ||
8230 | params = IF_DEF_PARAMS(ifp); | |
8231 | ||
8232 | if (argv[idx_ipv4]->type == IPV4_TKN) { | |
8233 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
8234 | if (!ret) { | |
8235 | vty_out(vty, | |
8236 | "Please specify interface address by A.B.C.D\n"); | |
8237 | return CMD_WARNING_CONFIG_FAILED; | |
8238 | } | |
020709f9 | 8239 | |
d62a17ae | 8240 | params = ospf_lookup_if_params(ifp, addr); |
8241 | if (params == NULL) | |
8242 | return CMD_SUCCESS; | |
8243 | } | |
718e3744 | 8244 | |
d62a17ae | 8245 | UNSET_IF_PARAM(params, v_wait); |
8246 | params->v_wait = OSPF_ROUTER_DEAD_INTERVAL_DEFAULT; | |
182d6bdc | 8247 | params->is_v_wait_set = false; |
d62a17ae | 8248 | |
8249 | UNSET_IF_PARAM(params, fast_hello); | |
8250 | params->fast_hello = OSPF_FAST_HELLO_DEFAULT; | |
8251 | ||
8252 | if (params != IF_DEF_PARAMS(ifp)) { | |
8253 | ospf_free_if_params(ifp, addr); | |
8254 | ospf_if_update_params(ifp, addr); | |
718e3744 | 8255 | } |
8256 | ||
d62a17ae | 8257 | /* Update timer values in neighbor structure. */ |
8258 | if (argc == 1) { | |
b5a8894d | 8259 | struct ospf *ospf = NULL; |
718e3744 | 8260 | |
a36898e7 | 8261 | ospf = ospf_lookup_by_vrf_id(ifp->vrf_id); |
b5a8894d | 8262 | if (ospf) { |
d62a17ae | 8263 | oi = ospf_if_lookup_by_local_addr(ospf, ifp, addr); |
8264 | if (oi) | |
8265 | ospf_nbr_timer_update(oi); | |
8266 | } | |
8267 | } else { | |
8268 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) | |
8269 | if ((oi = rn->info)) | |
8270 | ospf_nbr_timer_update(oi); | |
8271 | } | |
8272 | ||
8273 | return CMD_SUCCESS; | |
718e3744 | 8274 | } |
8275 | ||
0d829fa7 QY |
8276 | DEFUN_HIDDEN (no_ospf_dead_interval, |
8277 | no_ospf_dead_interval_cmd, | |
8278 | "no ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]", | |
8279 | NO_STR | |
8280 | "OSPF interface commands\n" | |
99a522c7 | 8281 | "Interval time after which a neighbor is declared down\n" |
0d829fa7 | 8282 | "Seconds\n" |
efd7904e RW |
8283 | "Minimal 1s dead-interval with fast sub-second hellos\n" |
8284 | "Hello multiplier factor\n" | |
8285 | "Number of Hellos to send each second\n" | |
8286 | "Address of interface\n") | |
0d829fa7 | 8287 | { |
d62a17ae | 8288 | return no_ip_ospf_dead_interval(self, vty, argc, argv); |
0d829fa7 QY |
8289 | } |
8290 | ||
718e3744 | 8291 | DEFUN (ip_ospf_hello_interval, |
0d829fa7 | 8292 | ip_ospf_hello_interval_cmd, |
7a7be519 | 8293 | "ip ospf hello-interval (1-65535) [A.B.C.D]", |
718e3744 | 8294 | "IP Information\n" |
8295 | "OSPF interface commands\n" | |
8296 | "Time between HELLO packets\n" | |
8297 | "Seconds\n" | |
0d829fa7 | 8298 | "Address of interface\n") |
718e3744 | 8299 | { |
d62a17ae | 8300 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8301 | int idx = 0; | |
8302 | struct in_addr addr; | |
8303 | struct ospf_if_params *params; | |
8304 | params = IF_DEF_PARAMS(ifp); | |
d7c0a89a | 8305 | uint32_t seconds = 0; |
d62a17ae | 8306 | |
8307 | argv_find(argv, argc, "(1-65535)", &idx); | |
8308 | seconds = strtol(argv[idx]->arg, NULL, 10); | |
8309 | ||
8310 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
8311 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
8312 | vty_out(vty, | |
8313 | "Please specify interface address by A.B.C.D\n"); | |
8314 | return CMD_WARNING_CONFIG_FAILED; | |
8315 | } | |
718e3744 | 8316 | |
d62a17ae | 8317 | params = ospf_get_if_params(ifp, addr); |
8318 | ospf_if_update_params(ifp, addr); | |
8319 | } | |
718e3744 | 8320 | |
d62a17ae | 8321 | SET_IF_PARAM(params, v_hello); |
8322 | params->v_hello = seconds; | |
718e3744 | 8323 | |
182d6bdc K |
8324 | if (!params->is_v_wait_set) { |
8325 | SET_IF_PARAM(params, v_wait); | |
8326 | /* As per RFC 4062 | |
8327 | * The router dead interval should | |
8328 | * be some multiple of the HelloInterval (perhaps 4 times the | |
8329 | * hello interval) and must be the same for all routers | |
8330 | * attached to a common network. | |
8331 | */ | |
8332 | params->v_wait = 4 * seconds; | |
8333 | } | |
8334 | ||
d62a17ae | 8335 | return CMD_SUCCESS; |
718e3744 | 8336 | } |
8337 | ||
7a7be519 | 8338 | DEFUN_HIDDEN (ospf_hello_interval, |
747e489c | 8339 | ospf_hello_interval_cmd, |
0d829fa7 | 8340 | "ospf hello-interval (1-65535) [A.B.C.D]", |
747e489c DW |
8341 | "OSPF interface commands\n" |
8342 | "Time between HELLO packets\n" | |
0d829fa7 QY |
8343 | "Seconds\n" |
8344 | "Address of interface\n") | |
7a7be519 | 8345 | { |
d62a17ae | 8346 | return ip_ospf_hello_interval(self, vty, argc, argv); |
7a7be519 | 8347 | } |
718e3744 | 8348 | |
8349 | DEFUN (no_ip_ospf_hello_interval, | |
0d829fa7 QY |
8350 | no_ip_ospf_hello_interval_cmd, |
8351 | "no ip ospf hello-interval [(1-65535) [A.B.C.D]]", | |
718e3744 | 8352 | NO_STR |
8353 | "IP Information\n" | |
8354 | "OSPF interface commands\n" | |
0d829fa7 | 8355 | "Time between HELLO packets\n" // ignored |
f9dfba8d | 8356 | "Seconds\n" |
0d829fa7 | 8357 | "Address of interface\n") |
718e3744 | 8358 | { |
d62a17ae | 8359 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8360 | int idx = 0; | |
8361 | struct in_addr addr; | |
8362 | struct ospf_if_params *params; | |
182d6bdc | 8363 | struct route_node *rn; |
df581cd3 | 8364 | |
d62a17ae | 8365 | params = IF_DEF_PARAMS(ifp); |
718e3744 | 8366 | |
d62a17ae | 8367 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { |
8368 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
8369 | vty_out(vty, | |
8370 | "Please specify interface address by A.B.C.D\n"); | |
8371 | return CMD_WARNING_CONFIG_FAILED; | |
8372 | } | |
718e3744 | 8373 | |
d62a17ae | 8374 | params = ospf_lookup_if_params(ifp, addr); |
8375 | if (params == NULL) | |
8376 | return CMD_SUCCESS; | |
8377 | } | |
718e3744 | 8378 | |
d62a17ae | 8379 | UNSET_IF_PARAM(params, v_hello); |
8380 | params->v_hello = OSPF_HELLO_INTERVAL_DEFAULT; | |
718e3744 | 8381 | |
182d6bdc K |
8382 | if (!params->is_v_wait_set) { |
8383 | UNSET_IF_PARAM(params, v_wait); | |
8384 | params->v_wait = OSPF_ROUTER_DEAD_INTERVAL_DEFAULT; | |
8385 | } | |
8386 | ||
8387 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { | |
8388 | struct ospf_interface *oi = rn->info; | |
8389 | ||
8390 | if (!oi) | |
8391 | continue; | |
8392 | ||
8393 | oi->type = IF_DEF_PARAMS(ifp)->type; | |
bc97889b | 8394 | oi->ptp_dmvpn = IF_DEF_PARAMS(ifp)->ptp_dmvpn; |
182d6bdc K |
8395 | |
8396 | if (oi->state > ISM_Down) { | |
8397 | OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceDown); | |
8398 | OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceUp); | |
8399 | } | |
8400 | } | |
8401 | ||
d62a17ae | 8402 | if (params != IF_DEF_PARAMS(ifp)) { |
8403 | ospf_free_if_params(ifp, addr); | |
8404 | ospf_if_update_params(ifp, addr); | |
8405 | } | |
718e3744 | 8406 | |
d62a17ae | 8407 | return CMD_SUCCESS; |
718e3744 | 8408 | } |
8409 | ||
0d829fa7 QY |
8410 | DEFUN_HIDDEN (no_ospf_hello_interval, |
8411 | no_ospf_hello_interval_cmd, | |
8412 | "no ospf hello-interval [(1-65535) [A.B.C.D]]", | |
8413 | NO_STR | |
8414 | "OSPF interface commands\n" | |
8415 | "Time between HELLO packets\n" // ignored | |
8416 | "Seconds\n" | |
8417 | "Address of interface\n") | |
8418 | { | |
d62a17ae | 8419 | return no_ip_ospf_hello_interval(self, vty, argc, argv); |
0d829fa7 | 8420 | } |
718e3744 | 8421 | |
bc97889b AL |
8422 | DEFUN(ip_ospf_network, ip_ospf_network_cmd, |
8423 | "ip ospf network <broadcast|non-broadcast|point-to-multipoint|point-to-point [dmvpn]>", | |
8424 | "IP Information\n" | |
8425 | "OSPF interface commands\n" | |
8426 | "Network type\n" | |
8427 | "Specify OSPF broadcast multi-access network\n" | |
8428 | "Specify OSPF NBMA network\n" | |
8429 | "Specify OSPF point-to-multipoint network\n" | |
8430 | "Specify OSPF point-to-point network\n" | |
8431 | "Specify OSPF point-to-point DMVPN network\n") | |
718e3744 | 8432 | { |
d62a17ae | 8433 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8434 | int idx = 0; | |
8435 | int old_type = IF_DEF_PARAMS(ifp)->type; | |
bc97889b | 8436 | uint8_t old_ptp_dmvpn = IF_DEF_PARAMS(ifp)->ptp_dmvpn; |
d62a17ae | 8437 | struct route_node *rn; |
718e3744 | 8438 | |
d62a17ae | 8439 | if (old_type == OSPF_IFTYPE_LOOPBACK) { |
8440 | vty_out(vty, | |
8441 | "This is a loopback interface. Can't set network type.\n"); | |
8442 | return CMD_WARNING_CONFIG_FAILED; | |
8443 | } | |
718e3744 | 8444 | |
bc97889b AL |
8445 | IF_DEF_PARAMS(ifp)->ptp_dmvpn = 0; |
8446 | ||
d62a17ae | 8447 | if (argv_find(argv, argc, "broadcast", &idx)) |
8448 | IF_DEF_PARAMS(ifp)->type = OSPF_IFTYPE_BROADCAST; | |
8449 | else if (argv_find(argv, argc, "non-broadcast", &idx)) | |
8450 | IF_DEF_PARAMS(ifp)->type = OSPF_IFTYPE_NBMA; | |
8451 | else if (argv_find(argv, argc, "point-to-multipoint", &idx)) | |
8452 | IF_DEF_PARAMS(ifp)->type = OSPF_IFTYPE_POINTOMULTIPOINT; | |
bc97889b | 8453 | else if (argv_find(argv, argc, "point-to-point", &idx)) { |
d62a17ae | 8454 | IF_DEF_PARAMS(ifp)->type = OSPF_IFTYPE_POINTOPOINT; |
bc97889b AL |
8455 | if (argv_find(argv, argc, "dmvpn", &idx)) |
8456 | IF_DEF_PARAMS(ifp)->ptp_dmvpn = 1; | |
8457 | } | |
718e3744 | 8458 | |
bc97889b AL |
8459 | if (IF_DEF_PARAMS(ifp)->type == old_type |
8460 | && IF_DEF_PARAMS(ifp)->ptp_dmvpn == old_ptp_dmvpn) | |
d62a17ae | 8461 | return CMD_SUCCESS; |
8462 | ||
8463 | SET_IF_PARAM(IF_DEF_PARAMS(ifp), type); | |
8464 | ||
8465 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { | |
8466 | struct ospf_interface *oi = rn->info; | |
8467 | ||
8468 | if (!oi) | |
8469 | continue; | |
8470 | ||
8471 | oi->type = IF_DEF_PARAMS(ifp)->type; | |
8472 | ||
8473 | if (oi->state > ISM_Down) { | |
8474 | OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceDown); | |
8475 | OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceUp); | |
8476 | } | |
7a7be519 | 8477 | } |
7a7be519 | 8478 | |
d62a17ae | 8479 | return CMD_SUCCESS; |
7a7be519 | 8480 | } |
8481 | ||
8482 | DEFUN_HIDDEN (ospf_network, | |
8483 | ospf_network_cmd, | |
e83a9414 | 8484 | "ospf network <broadcast|non-broadcast|point-to-multipoint|point-to-point>", |
7a7be519 | 8485 | "OSPF interface commands\n" |
8486 | "Network type\n" | |
8487 | "Specify OSPF broadcast multi-access network\n" | |
8488 | "Specify OSPF NBMA network\n" | |
8489 | "Specify OSPF point-to-multipoint network\n" | |
8490 | "Specify OSPF point-to-point network\n") | |
8491 | { | |
d62a17ae | 8492 | return ip_ospf_network(self, vty, argc, argv); |
7a7be519 | 8493 | } |
8494 | ||
8495 | DEFUN (no_ip_ospf_network, | |
8496 | no_ip_ospf_network_cmd, | |
8497 | "no ip ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]", | |
8498 | NO_STR | |
8499 | "IP Information\n" | |
8500 | "OSPF interface commands\n" | |
8501 | "Network type\n" | |
8502 | "Specify OSPF broadcast multi-access network\n" | |
8503 | "Specify OSPF NBMA network\n" | |
8504 | "Specify OSPF point-to-multipoint network\n" | |
8505 | "Specify OSPF point-to-point network\n") | |
22b27e95 | 8506 | { |
d62a17ae | 8507 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8508 | int old_type = IF_DEF_PARAMS(ifp)->type; | |
8509 | struct route_node *rn; | |
7a7be519 | 8510 | |
d62a17ae | 8511 | IF_DEF_PARAMS(ifp)->type = ospf_default_iftype(ifp); |
bc97889b | 8512 | IF_DEF_PARAMS(ifp)->ptp_dmvpn = 0; |
7a7be519 | 8513 | |
d62a17ae | 8514 | if (IF_DEF_PARAMS(ifp)->type == old_type) |
8515 | return CMD_SUCCESS; | |
7a7be519 | 8516 | |
d62a17ae | 8517 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { |
8518 | struct ospf_interface *oi = rn->info; | |
7a7be519 | 8519 | |
d62a17ae | 8520 | if (!oi) |
8521 | continue; | |
7a7be519 | 8522 | |
d62a17ae | 8523 | oi->type = IF_DEF_PARAMS(ifp)->type; |
7a7be519 | 8524 | |
d62a17ae | 8525 | if (oi->state > ISM_Down) { |
8526 | OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceDown); | |
8527 | OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceUp); | |
8528 | } | |
7a7be519 | 8529 | } |
7a7be519 | 8530 | |
d62a17ae | 8531 | return CMD_SUCCESS; |
7a7be519 | 8532 | } |
8533 | ||
0d829fa7 QY |
8534 | DEFUN_HIDDEN (no_ospf_network, |
8535 | no_ospf_network_cmd, | |
8536 | "no ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]", | |
8537 | NO_STR | |
8538 | "OSPF interface commands\n" | |
8539 | "Network type\n" | |
8540 | "Specify OSPF broadcast multi-access network\n" | |
8541 | "Specify OSPF NBMA network\n" | |
8542 | "Specify OSPF point-to-multipoint network\n" | |
8543 | "Specify OSPF point-to-point network\n") | |
8544 | { | |
d62a17ae | 8545 | return no_ip_ospf_network(self, vty, argc, argv); |
0d829fa7 QY |
8546 | } |
8547 | ||
7a7be519 | 8548 | DEFUN (ip_ospf_priority, |
537eae3f | 8549 | ip_ospf_priority_cmd, |
7a7be519 | 8550 | "ip ospf priority (0-255) [A.B.C.D]", |
8551 | "IP Information\n" | |
8552 | "OSPF interface commands\n" | |
8553 | "Router priority\n" | |
8554 | "Priority\n" | |
efd7904e | 8555 | "Address of interface\n") |
7a7be519 | 8556 | { |
d62a17ae | 8557 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8558 | int idx = 0; | |
8559 | long priority; | |
8560 | struct route_node *rn; | |
8561 | struct in_addr addr; | |
8562 | struct ospf_if_params *params; | |
8563 | params = IF_DEF_PARAMS(ifp); | |
8564 | ||
8565 | argv_find(argv, argc, "(0-255)", &idx); | |
8566 | priority = strtol(argv[idx]->arg, NULL, 10); | |
8567 | ||
8568 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
8569 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
8570 | vty_out(vty, | |
8571 | "Please specify interface address by A.B.C.D\n"); | |
8572 | return CMD_WARNING_CONFIG_FAILED; | |
8573 | } | |
7a7be519 | 8574 | |
d62a17ae | 8575 | params = ospf_get_if_params(ifp, addr); |
8576 | ospf_if_update_params(ifp, addr); | |
7a7be519 | 8577 | } |
8578 | ||
d62a17ae | 8579 | SET_IF_PARAM(params, priority); |
8580 | params->priority = priority; | |
7a7be519 | 8581 | |
d62a17ae | 8582 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { |
8583 | struct ospf_interface *oi = rn->info; | |
7a7be519 | 8584 | |
d62a17ae | 8585 | if (!oi) |
8586 | continue; | |
7a7be519 | 8587 | |
d62a17ae | 8588 | if (PRIORITY(oi) != OSPF_IF_PARAM(oi, priority)) { |
8589 | PRIORITY(oi) = OSPF_IF_PARAM(oi, priority); | |
8590 | OSPF_ISM_EVENT_SCHEDULE(oi, ISM_NeighborChange); | |
8591 | } | |
718e3744 | 8592 | } |
718e3744 | 8593 | |
d62a17ae | 8594 | return CMD_SUCCESS; |
718e3744 | 8595 | } |
8596 | ||
7a7be519 | 8597 | DEFUN_HIDDEN (ospf_priority, |
8598 | ospf_priority_cmd, | |
0d829fa7 | 8599 | "ospf priority (0-255) [A.B.C.D]", |
7a7be519 | 8600 | "OSPF interface commands\n" |
8601 | "Router priority\n" | |
3a2d747c | 8602 | "Priority\n" |
efd7904e | 8603 | "Address of interface\n") |
718e3744 | 8604 | { |
d62a17ae | 8605 | return ip_ospf_priority(self, vty, argc, argv); |
718e3744 | 8606 | } |
8607 | ||
718e3744 | 8608 | DEFUN (no_ip_ospf_priority, |
537eae3f | 8609 | no_ip_ospf_priority_cmd, |
7a7be519 | 8610 | "no ip ospf priority [(0-255) [A.B.C.D]]", |
718e3744 | 8611 | NO_STR |
8612 | "IP Information\n" | |
8613 | "OSPF interface commands\n" | |
0d829fa7 | 8614 | "Router priority\n" // ignored |
813d4307 | 8615 | "Priority\n" |
efd7904e | 8616 | "Address of interface\n") |
718e3744 | 8617 | { |
d62a17ae | 8618 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8619 | int idx = 0; | |
8620 | struct route_node *rn; | |
8621 | struct in_addr addr; | |
8622 | struct ospf_if_params *params; | |
8623 | ||
8624 | params = IF_DEF_PARAMS(ifp); | |
8625 | ||
8626 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
8627 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
8628 | vty_out(vty, | |
8629 | "Please specify interface address by A.B.C.D\n"); | |
8630 | return CMD_WARNING_CONFIG_FAILED; | |
8631 | } | |
8632 | ||
8633 | params = ospf_lookup_if_params(ifp, addr); | |
8634 | if (params == NULL) | |
8635 | return CMD_SUCCESS; | |
718e3744 | 8636 | } |
8637 | ||
d62a17ae | 8638 | UNSET_IF_PARAM(params, priority); |
8639 | params->priority = OSPF_ROUTER_PRIORITY_DEFAULT; | |
8640 | ||
8641 | if (params != IF_DEF_PARAMS(ifp)) { | |
8642 | ospf_free_if_params(ifp, addr); | |
8643 | ospf_if_update_params(ifp, addr); | |
718e3744 | 8644 | } |
d62a17ae | 8645 | |
8646 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { | |
8647 | struct ospf_interface *oi = rn->info; | |
8648 | ||
8649 | if (!oi) | |
8650 | continue; | |
8651 | ||
8652 | if (PRIORITY(oi) != OSPF_IF_PARAM(oi, priority)) { | |
8653 | PRIORITY(oi) = OSPF_IF_PARAM(oi, priority); | |
8654 | OSPF_ISM_EVENT_SCHEDULE(oi, ISM_NeighborChange); | |
8655 | } | |
8656 | } | |
8657 | ||
8658 | return CMD_SUCCESS; | |
718e3744 | 8659 | } |
8660 | ||
0d829fa7 | 8661 | DEFUN_HIDDEN (no_ospf_priority, |
537eae3f | 8662 | no_ospf_priority_cmd, |
0d829fa7 QY |
8663 | "no ospf priority [(0-255) [A.B.C.D]]", |
8664 | NO_STR | |
8665 | "OSPF interface commands\n" | |
8666 | "Router priority\n" | |
8667 | "Priority\n" | |
efd7904e | 8668 | "Address of interface\n") |
0d829fa7 | 8669 | { |
d62a17ae | 8670 | return no_ip_ospf_priority(self, vty, argc, argv); |
0d829fa7 | 8671 | } |
a1afa410 | 8672 | |
718e3744 | 8673 | DEFUN (ip_ospf_retransmit_interval, |
8674 | ip_ospf_retransmit_interval_addr_cmd, | |
d4badaf6 | 8675 | "ip ospf retransmit-interval (1-65535) [A.B.C.D]", |
718e3744 | 8676 | "IP Information\n" |
8677 | "OSPF interface commands\n" | |
8678 | "Time between retransmitting lost link state advertisements\n" | |
8679 | "Seconds\n" | |
efd7904e | 8680 | "Address of interface\n") |
718e3744 | 8681 | { |
d62a17ae | 8682 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8683 | int idx = 0; | |
d7c0a89a | 8684 | uint32_t seconds; |
d62a17ae | 8685 | struct in_addr addr; |
8686 | struct ospf_if_params *params; | |
8687 | params = IF_DEF_PARAMS(ifp); | |
8688 | ||
d4badaf6 | 8689 | argv_find(argv, argc, "(1-65535)", &idx); |
d62a17ae | 8690 | seconds = strtol(argv[idx]->arg, NULL, 10); |
8691 | ||
8692 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
8693 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
8694 | vty_out(vty, | |
8695 | "Please specify interface address by A.B.C.D\n"); | |
8696 | return CMD_WARNING_CONFIG_FAILED; | |
8697 | } | |
718e3744 | 8698 | |
d62a17ae | 8699 | params = ospf_get_if_params(ifp, addr); |
8700 | ospf_if_update_params(ifp, addr); | |
718e3744 | 8701 | } |
8702 | ||
d62a17ae | 8703 | SET_IF_PARAM(params, retransmit_interval); |
8704 | params->retransmit_interval = seconds; | |
718e3744 | 8705 | |
d62a17ae | 8706 | return CMD_SUCCESS; |
718e3744 | 8707 | } |
8708 | ||
7a7be519 | 8709 | DEFUN_HIDDEN (ospf_retransmit_interval, |
747e489c | 8710 | ospf_retransmit_interval_cmd, |
d4badaf6 | 8711 | "ospf retransmit-interval (1-65535) [A.B.C.D]", |
747e489c DW |
8712 | "OSPF interface commands\n" |
8713 | "Time between retransmitting lost link state advertisements\n" | |
3a2d747c | 8714 | "Seconds\n" |
efd7904e | 8715 | "Address of interface\n") |
7a7be519 | 8716 | { |
d62a17ae | 8717 | return ip_ospf_retransmit_interval(self, vty, argc, argv); |
7a7be519 | 8718 | } |
718e3744 | 8719 | |
8720 | DEFUN (no_ip_ospf_retransmit_interval, | |
8721 | no_ip_ospf_retransmit_interval_addr_cmd, | |
d4badaf6 | 8722 | "no ip ospf retransmit-interval [(1-65535)] [A.B.C.D]", |
718e3744 | 8723 | NO_STR |
8724 | "IP Information\n" | |
8725 | "OSPF interface commands\n" | |
3a2d747c QY |
8726 | "Time between retransmitting lost link state advertisements\n" |
8727 | "Seconds\n" | |
0d829fa7 | 8728 | "Address of interface\n") |
718e3744 | 8729 | { |
d62a17ae | 8730 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8731 | int idx = 0; | |
8732 | struct in_addr addr; | |
8733 | struct ospf_if_params *params; | |
47b91972 | 8734 | |
d62a17ae | 8735 | params = IF_DEF_PARAMS(ifp); |
718e3744 | 8736 | |
d62a17ae | 8737 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { |
8738 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
8739 | vty_out(vty, | |
8740 | "Please specify interface address by A.B.C.D\n"); | |
8741 | return CMD_WARNING_CONFIG_FAILED; | |
8742 | } | |
718e3744 | 8743 | |
d62a17ae | 8744 | params = ospf_lookup_if_params(ifp, addr); |
8745 | if (params == NULL) | |
8746 | return CMD_SUCCESS; | |
8747 | } | |
718e3744 | 8748 | |
d62a17ae | 8749 | UNSET_IF_PARAM(params, retransmit_interval); |
8750 | params->retransmit_interval = OSPF_RETRANSMIT_INTERVAL_DEFAULT; | |
718e3744 | 8751 | |
d62a17ae | 8752 | if (params != IF_DEF_PARAMS(ifp)) { |
8753 | ospf_free_if_params(ifp, addr); | |
8754 | ospf_if_update_params(ifp, addr); | |
8755 | } | |
718e3744 | 8756 | |
d62a17ae | 8757 | return CMD_SUCCESS; |
718e3744 | 8758 | } |
8759 | ||
0d829fa7 QY |
8760 | DEFUN_HIDDEN (no_ospf_retransmit_interval, |
8761 | no_ospf_retransmit_interval_cmd, | |
d4badaf6 | 8762 | "no ospf retransmit-interval [(1-65535)] [A.B.C.D]", |
0d829fa7 QY |
8763 | NO_STR |
8764 | "OSPF interface commands\n" | |
3a2d747c QY |
8765 | "Time between retransmitting lost link state advertisements\n" |
8766 | "Seconds\n" | |
8767 | "Address of interface\n") | |
0d829fa7 | 8768 | { |
d62a17ae | 8769 | return no_ip_ospf_retransmit_interval(self, vty, argc, argv); |
0d829fa7 | 8770 | } |
813d4307 | 8771 | |
718e3744 | 8772 | DEFUN (ip_ospf_transmit_delay, |
8773 | ip_ospf_transmit_delay_addr_cmd, | |
7a7be519 | 8774 | "ip ospf transmit-delay (1-65535) [A.B.C.D]", |
718e3744 | 8775 | "IP Information\n" |
8776 | "OSPF interface commands\n" | |
8777 | "Link state transmit delay\n" | |
8778 | "Seconds\n" | |
efd7904e | 8779 | "Address of interface\n") |
718e3744 | 8780 | { |
d62a17ae | 8781 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8782 | int idx = 0; | |
d7c0a89a | 8783 | uint32_t seconds; |
d62a17ae | 8784 | struct in_addr addr; |
8785 | struct ospf_if_params *params; | |
8786 | ||
8787 | params = IF_DEF_PARAMS(ifp); | |
8788 | argv_find(argv, argc, "(1-65535)", &idx); | |
8789 | seconds = strtol(argv[idx]->arg, NULL, 10); | |
8790 | ||
8791 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
8792 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
8793 | vty_out(vty, | |
8794 | "Please specify interface address by A.B.C.D\n"); | |
8795 | return CMD_WARNING_CONFIG_FAILED; | |
8796 | } | |
718e3744 | 8797 | |
d62a17ae | 8798 | params = ospf_get_if_params(ifp, addr); |
8799 | ospf_if_update_params(ifp, addr); | |
718e3744 | 8800 | } |
8801 | ||
d62a17ae | 8802 | SET_IF_PARAM(params, transmit_delay); |
8803 | params->transmit_delay = seconds; | |
718e3744 | 8804 | |
d62a17ae | 8805 | return CMD_SUCCESS; |
718e3744 | 8806 | } |
8807 | ||
7a7be519 | 8808 | DEFUN_HIDDEN (ospf_transmit_delay, |
747e489c | 8809 | ospf_transmit_delay_cmd, |
0d829fa7 | 8810 | "ospf transmit-delay (1-65535) [A.B.C.D]", |
747e489c DW |
8811 | "OSPF interface commands\n" |
8812 | "Link state transmit delay\n" | |
3a2d747c | 8813 | "Seconds\n" |
efd7904e | 8814 | "Address of interface\n") |
7a7be519 | 8815 | { |
d62a17ae | 8816 | return ip_ospf_transmit_delay(self, vty, argc, argv); |
7a7be519 | 8817 | } |
718e3744 | 8818 | |
8819 | DEFUN (no_ip_ospf_transmit_delay, | |
8820 | no_ip_ospf_transmit_delay_addr_cmd, | |
0d829fa7 | 8821 | "no ip ospf transmit-delay [(1-65535)] [A.B.C.D]", |
718e3744 | 8822 | NO_STR |
8823 | "IP Information\n" | |
8824 | "OSPF interface commands\n" | |
8825 | "Link state transmit delay\n" | |
efd7904e RW |
8826 | "Seconds\n" |
8827 | "Address of interface\n") | |
718e3744 | 8828 | { |
d62a17ae | 8829 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8830 | int idx = 0; | |
8831 | struct in_addr addr; | |
8832 | struct ospf_if_params *params; | |
718e3744 | 8833 | |
d62a17ae | 8834 | params = IF_DEF_PARAMS(ifp); |
718e3744 | 8835 | |
d62a17ae | 8836 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { |
8837 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
8838 | vty_out(vty, | |
8839 | "Please specify interface address by A.B.C.D\n"); | |
8840 | return CMD_WARNING_CONFIG_FAILED; | |
8841 | } | |
718e3744 | 8842 | |
d62a17ae | 8843 | params = ospf_lookup_if_params(ifp, addr); |
8844 | if (params == NULL) | |
8845 | return CMD_SUCCESS; | |
8846 | } | |
718e3744 | 8847 | |
d62a17ae | 8848 | UNSET_IF_PARAM(params, transmit_delay); |
8849 | params->transmit_delay = OSPF_TRANSMIT_DELAY_DEFAULT; | |
718e3744 | 8850 | |
d62a17ae | 8851 | if (params != IF_DEF_PARAMS(ifp)) { |
8852 | ospf_free_if_params(ifp, addr); | |
8853 | ospf_if_update_params(ifp, addr); | |
8854 | } | |
8855 | ||
8856 | return CMD_SUCCESS; | |
718e3744 | 8857 | } |
8858 | ||
813d4307 | 8859 | |
0d829fa7 QY |
8860 | DEFUN_HIDDEN (no_ospf_transmit_delay, |
8861 | no_ospf_transmit_delay_cmd, | |
32573073 | 8862 | "no ospf transmit-delay [(1-65535) [A.B.C.D]]", |
0d829fa7 QY |
8863 | NO_STR |
8864 | "OSPF interface commands\n" | |
32573073 QY |
8865 | "Link state transmit delay\n" |
8866 | "Seconds\n" | |
efd7904e | 8867 | "Address of interface\n") |
813d4307 | 8868 | { |
d62a17ae | 8869 | return no_ip_ospf_transmit_delay(self, vty, argc, argv); |
813d4307 DW |
8870 | } |
8871 | ||
e723861d DS |
8872 | DEFUN (ip_ospf_area, |
8873 | ip_ospf_area_cmd, | |
52c62ab8 | 8874 | "ip ospf [(1-65535)] area <A.B.C.D|(0-4294967295)> [A.B.C.D]", |
e723861d DS |
8875 | "IP Information\n" |
8876 | "OSPF interface commands\n" | |
7a7be519 | 8877 | "Instance ID\n" |
e723861d DS |
8878 | "Enable OSPF on this interface\n" |
8879 | "OSPF area ID in IP address format\n" | |
52c62ab8 JAG |
8880 | "OSPF area ID as a decimal value\n" |
8881 | "Address of interface\n") | |
e723861d | 8882 | { |
d62a17ae | 8883 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8884 | int idx = 0; | |
8885 | int format, ret; | |
8886 | struct in_addr area_id; | |
8887 | struct in_addr addr; | |
35955c14 | 8888 | struct ospf_if_params *params = NULL; |
d62a17ae | 8889 | struct route_node *rn; |
b5a8894d | 8890 | struct ospf *ospf = NULL; |
d7c0a89a | 8891 | unsigned short instance = 0; |
d62a17ae | 8892 | char *areaid; |
15bf52d3 | 8893 | uint32_t count = 0; |
d62a17ae | 8894 | |
8895 | if (argv_find(argv, argc, "(1-65535)", &idx)) | |
8896 | instance = strtol(argv[idx]->arg, NULL, 10); | |
8897 | ||
8898 | argv_find(argv, argc, "area", &idx); | |
8899 | areaid = argv[idx + 1]->arg; | |
8900 | ||
a36898e7 DS |
8901 | if (ifp->vrf_id && !instance) |
8902 | ospf = ospf_lookup_by_vrf_id(ifp->vrf_id); | |
b5a8894d CS |
8903 | else |
8904 | ospf = ospf_lookup_instance(instance); | |
8905 | ||
409f98ab | 8906 | if (instance && instance != ospf_instance) { |
2b0a32da DS |
8907 | /* |
8908 | * At this point we know we have received | |
8909 | * an instance and there is no ospf instance | |
8910 | * associated with it. This means we are | |
8911 | * in a situation where we have an | |
8912 | * ospf command that is setup for a different | |
8913 | * process(instance). We need to safely | |
8914 | * remove the command from ourselves and | |
8915 | * allow the other instance(process) handle | |
8916 | * the configuration command. | |
8917 | */ | |
15bf52d3 IR |
8918 | count = 0; |
8919 | ||
d62a17ae | 8920 | params = IF_DEF_PARAMS(ifp); |
8921 | if (OSPF_IF_PARAM_CONFIGURED(params, if_area)) { | |
8922 | UNSET_IF_PARAM(params, if_area); | |
15bf52d3 IR |
8923 | count++; |
8924 | } | |
8925 | ||
8926 | for (rn = route_top(IF_OIFS_PARAMS(ifp)); rn; rn = route_next(rn)) | |
8927 | if ((params = rn->info) && OSPF_IF_PARAM_CONFIGURED(params, if_area)) { | |
8928 | UNSET_IF_PARAM(params, if_area); | |
8929 | count++; | |
8930 | } | |
8931 | ||
8932 | if (count > 0) { | |
8933 | ospf = ospf_lookup_by_vrf_id(ifp->vrf_id); | |
cbf32f74 | 8934 | if (ospf) |
2b0a32da | 8935 | ospf_interface_area_unset(ospf, ifp); |
d62a17ae | 8936 | } |
15bf52d3 | 8937 | |
ac28e4ec | 8938 | return CMD_NOT_MY_INSTANCE; |
d62a17ae | 8939 | } |
e723861d | 8940 | |
d62a17ae | 8941 | ret = str2area_id(areaid, &area_id, &format); |
8942 | if (ret < 0) { | |
8943 | vty_out(vty, "Please specify area by A.B.C.D|<0-4294967295>\n"); | |
8944 | return CMD_WARNING_CONFIG_FAILED; | |
8945 | } | |
8946 | if (memcmp(ifp->name, "VLINK", 5) == 0) { | |
8947 | vty_out(vty, "Cannot enable OSPF on a virtual link.\n"); | |
8948 | return CMD_WARNING_CONFIG_FAILED; | |
8949 | } | |
8950 | ||
eb364867 IR |
8951 | if (ospf) { |
8952 | for (rn = route_top(ospf->networks); rn; rn = route_next(rn)) { | |
8953 | if (rn->info != NULL) { | |
8954 | vty_out(vty, | |
8955 | "Please remove all network commands first.\n"); | |
8956 | return CMD_WARNING_CONFIG_FAILED; | |
8957 | } | |
8958 | } | |
8959 | } | |
8960 | ||
d62a17ae | 8961 | params = IF_DEF_PARAMS(ifp); |
8962 | if (OSPF_IF_PARAM_CONFIGURED(params, if_area) | |
8963 | && !IPV4_ADDR_SAME(¶ms->if_area, &area_id)) { | |
8964 | vty_out(vty, | |
8965 | "Must remove previous area config before changing ospf area \n"); | |
8966 | return CMD_WARNING_CONFIG_FAILED; | |
8967 | } | |
8968 | ||
8969 | // Check if we have an address arg and proccess it | |
8970 | if (argc == idx + 3) { | |
cc9b06ad | 8971 | if (!inet_aton(argv[idx + 2]->arg, &addr)) { |
996c9314 LB |
8972 | vty_out(vty, |
8973 | "Please specify Intf Address by A.B.C.D\n"); | |
cc9b06ad DS |
8974 | return CMD_WARNING_CONFIG_FAILED; |
8975 | } | |
d62a17ae | 8976 | // update/create address-level params |
8977 | params = ospf_get_if_params((ifp), (addr)); | |
8978 | if (OSPF_IF_PARAM_CONFIGURED(params, if_area)) { | |
a900cece IR |
8979 | if (!IPV4_ADDR_SAME(¶ms->if_area, &area_id)) { |
8980 | vty_out(vty, | |
8981 | "Must remove previous area/address config before changing ospf area\n"); | |
8982 | return CMD_WARNING_CONFIG_FAILED; | |
8983 | } else | |
8984 | return CMD_SUCCESS; | |
d62a17ae | 8985 | } |
8986 | ospf_if_update_params((ifp), (addr)); | |
8987 | } | |
8988 | ||
d62a17ae | 8989 | /* enable ospf on this interface with area_id */ |
35955c14 CS |
8990 | if (params) { |
8991 | SET_IF_PARAM(params, if_area); | |
8992 | params->if_area = area_id; | |
8993 | params->if_area_id_fmt = format; | |
8994 | } | |
aed7cc62 | 8995 | |
cbf32f74 | 8996 | if (ospf) |
aed7cc62 | 8997 | ospf_interface_area_set(ospf, ifp); |
d62a17ae | 8998 | |
8999 | return CMD_SUCCESS; | |
e723861d DS |
9000 | } |
9001 | ||
9002 | DEFUN (no_ip_ospf_area, | |
9003 | no_ip_ospf_area_cmd, | |
52c62ab8 | 9004 | "no ip ospf [(1-65535)] area [<A.B.C.D|(0-4294967295)> [A.B.C.D]]", |
e723861d DS |
9005 | NO_STR |
9006 | "IP Information\n" | |
9007 | "OSPF interface commands\n" | |
3a2d747c | 9008 | "Instance ID\n" |
7a7be519 | 9009 | "Disable OSPF on this interface\n" |
9010 | "OSPF area ID in IP address format\n" | |
52c62ab8 JAG |
9011 | "OSPF area ID as a decimal value\n" |
9012 | "Address of interface\n") | |
e723861d | 9013 | { |
d62a17ae | 9014 | VTY_DECLVAR_CONTEXT(interface, ifp); |
9015 | int idx = 0; | |
9016 | struct ospf *ospf; | |
9017 | struct ospf_if_params *params; | |
d7c0a89a | 9018 | unsigned short instance = 0; |
d62a17ae | 9019 | struct in_addr addr; |
58e5d140 | 9020 | struct in_addr area_id; |
d62a17ae | 9021 | |
9022 | if (argv_find(argv, argc, "(1-65535)", &idx)) | |
9023 | instance = strtol(argv[idx]->arg, NULL, 10); | |
9024 | ||
a36898e7 DS |
9025 | if (ifp->vrf_id && !instance) |
9026 | ospf = ospf_lookup_by_vrf_id(ifp->vrf_id); | |
b5a8894d CS |
9027 | else |
9028 | ospf = ospf_lookup_instance(instance); | |
9029 | ||
409f98ab | 9030 | if (instance && instance != ospf_instance) |
ac28e4ec | 9031 | return CMD_NOT_MY_INSTANCE; |
d62a17ae | 9032 | |
9033 | argv_find(argv, argc, "area", &idx); | |
9034 | ||
9035 | // Check if we have an address arg and proccess it | |
9036 | if (argc == idx + 3) { | |
cc9b06ad | 9037 | if (!inet_aton(argv[idx + 2]->arg, &addr)) { |
996c9314 LB |
9038 | vty_out(vty, |
9039 | "Please specify Intf Address by A.B.C.D\n"); | |
cc9b06ad DS |
9040 | return CMD_WARNING_CONFIG_FAILED; |
9041 | } | |
d62a17ae | 9042 | params = ospf_lookup_if_params(ifp, addr); |
9043 | if ((params) == NULL) | |
9044 | return CMD_SUCCESS; | |
9045 | } else | |
9046 | params = IF_DEF_PARAMS(ifp); | |
9047 | ||
58e5d140 | 9048 | area_id = params->if_area; |
d62a17ae | 9049 | if (!OSPF_IF_PARAM_CONFIGURED(params, if_area)) { |
9050 | vty_out(vty, | |
9051 | "Can't find specified interface area configuration.\n"); | |
9052 | return CMD_WARNING_CONFIG_FAILED; | |
9053 | } | |
813d4307 | 9054 | |
d62a17ae | 9055 | UNSET_IF_PARAM(params, if_area); |
9056 | if (params != IF_DEF_PARAMS((ifp))) { | |
9057 | ospf_free_if_params((ifp), (addr)); | |
9058 | ospf_if_update_params((ifp), (addr)); | |
9059 | } | |
9060 | ||
e4129293 IR |
9061 | if (ospf) { |
9062 | ospf_interface_area_unset(ospf, ifp); | |
58e5d140 | 9063 | ospf_area_check_free(ospf, area_id); |
e4129293 IR |
9064 | } |
9065 | ||
d62a17ae | 9066 | return CMD_SUCCESS; |
813d4307 DW |
9067 | } |
9068 | ||
6f2a6703 CF |
9069 | DEFUN (ospf_redistribute_source, |
9070 | ospf_redistribute_source_cmd, | |
ea38ced1 | 9071 | "redistribute " FRR_REDIST_STR_OSPFD " [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]", |
d1c65c21 | 9072 | REDIST_STR |
ab0181ee | 9073 | FRR_REDIST_HELP_STR_OSPFD |
718e3744 | 9074 | "Metric for redistributed routes\n" |
9075 | "OSPF default metric\n" | |
9076 | "OSPF exterior metric type for redistributed routes\n" | |
7111c1a0 | 9077 | "Set OSPF External Type 1/2 metrics\n" |
718e3744 | 9078 | "Route map reference\n" |
9079 | "Pointer to route-map entries\n") | |
9080 | { | |
a3d826f0 | 9081 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 9082 | int idx_protocol = 1; |
9083 | int source; | |
9084 | int type = -1; | |
9085 | int metric = -1; | |
9086 | struct ospf_redist *red; | |
9087 | int idx = 0; | |
6f2a6703 | 9088 | |
d62a17ae | 9089 | /* Get distribute source. */ |
9090 | source = proto_redistnum(AFI_IP, argv[idx_protocol]->text); | |
9091 | if (source < 0) | |
9092 | return CMD_WARNING_CONFIG_FAILED; | |
9093 | ||
9094 | red = ospf_redist_add(ospf, source, 0); | |
9095 | ||
9096 | /* Get metric value. */ | |
9097 | if (argv_find(argv, argc, "(0-16777214)", &idx)) { | |
9098 | if (!str2metric(argv[idx]->arg, &metric)) | |
9099 | return CMD_WARNING_CONFIG_FAILED; | |
9100 | } | |
951da435 | 9101 | idx = 1; |
d62a17ae | 9102 | /* Get metric type. */ |
ea38ced1 | 9103 | if (argv_find(argv, argc, "(1-2)", &idx)) { |
d62a17ae | 9104 | if (!str2metric_type(argv[idx]->arg, &type)) |
9105 | return CMD_WARNING_CONFIG_FAILED; | |
9106 | } | |
951da435 | 9107 | idx = 1; |
d62a17ae | 9108 | /* Get route-map */ |
ea38ced1 | 9109 | if (argv_find(argv, argc, "WORD", &idx)) { |
d62a17ae | 9110 | ospf_routemap_set(red, argv[idx]->arg); |
9111 | } else | |
9112 | ospf_routemap_unset(red); | |
7c8ff89e | 9113 | |
d62a17ae | 9114 | return ospf_redistribute_set(ospf, source, 0, type, metric); |
718e3744 | 9115 | } |
9116 | ||
718e3744 | 9117 | DEFUN (no_ospf_redistribute_source, |
9118 | no_ospf_redistribute_source_cmd, | |
ea38ced1 | 9119 | "no redistribute " FRR_REDIST_STR_OSPFD " [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]", |
718e3744 | 9120 | NO_STR |
d1c65c21 | 9121 | REDIST_STR |
ab0181ee | 9122 | FRR_REDIST_HELP_STR_OSPFD |
813d4307 DW |
9123 | "Metric for redistributed routes\n" |
9124 | "OSPF default metric\n" | |
9125 | "OSPF exterior metric type for redistributed routes\n" | |
7111c1a0 | 9126 | "Set OSPF External Type 1/2 metrics\n" |
813d4307 DW |
9127 | "Route map reference\n" |
9128 | "Pointer to route-map entries\n") | |
718e3744 | 9129 | { |
a3d826f0 | 9130 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 9131 | int idx_protocol = 2; |
9132 | int source; | |
9133 | struct ospf_redist *red; | |
718e3744 | 9134 | |
d62a17ae | 9135 | source = proto_redistnum(AFI_IP, argv[idx_protocol]->text); |
9136 | if (source < 0) | |
9137 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 9138 | |
d62a17ae | 9139 | red = ospf_redist_lookup(ospf, source, 0); |
9140 | if (!red) | |
9141 | return CMD_SUCCESS; | |
7c8ff89e | 9142 | |
d62a17ae | 9143 | ospf_routemap_unset(red); |
766b826f DA |
9144 | ospf_redist_del(ospf, source, 0); |
9145 | ||
d62a17ae | 9146 | return ospf_redistribute_unset(ospf, source, 0); |
7c8ff89e DS |
9147 | } |
9148 | ||
9149 | DEFUN (ospf_redistribute_instance_source, | |
9150 | ospf_redistribute_instance_source_cmd, | |
1a5ce38b | 9151 | "redistribute <ospf|table> (1-65535) [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]", |
7c8ff89e DS |
9152 | REDIST_STR |
9153 | "Open Shortest Path First\n" | |
2d627ff5 DS |
9154 | "Non-main Kernel Routing Table\n" |
9155 | "Instance ID/Table ID\n" | |
7c8ff89e DS |
9156 | "Metric for redistributed routes\n" |
9157 | "OSPF default metric\n" | |
9158 | "OSPF exterior metric type for redistributed routes\n" | |
7111c1a0 | 9159 | "Set OSPF External Type 1/2 metrics\n" |
7c8ff89e DS |
9160 | "Route map reference\n" |
9161 | "Pointer to route-map entries\n") | |
9162 | { | |
a3d826f0 | 9163 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 9164 | int idx_ospf_table = 1; |
9165 | int idx_number = 2; | |
9166 | int idx = 3; | |
9167 | int source; | |
9168 | int type = -1; | |
9169 | int metric = -1; | |
d7c0a89a | 9170 | unsigned short instance; |
d62a17ae | 9171 | struct ospf_redist *red; |
7c8ff89e | 9172 | |
d62a17ae | 9173 | source = proto_redistnum(AFI_IP, argv[idx_ospf_table]->text); |
2d627ff5 | 9174 | |
13f0e434 | 9175 | if (source < 0) { |
9176 | vty_out(vty, "Unknown instance redistribution\n"); | |
9177 | return CMD_WARNING_CONFIG_FAILED; | |
9178 | } | |
9179 | ||
d62a17ae | 9180 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
7c8ff89e | 9181 | |
d62a17ae | 9182 | if ((source == ZEBRA_ROUTE_OSPF) && !ospf->instance) { |
9183 | vty_out(vty, | |
9184 | "Instance redistribution in non-instanced OSPF not allowed\n"); | |
9185 | return CMD_WARNING_CONFIG_FAILED; | |
9186 | } | |
7c8ff89e | 9187 | |
d62a17ae | 9188 | if ((source == ZEBRA_ROUTE_OSPF) && (ospf->instance == instance)) { |
9189 | vty_out(vty, "Same instance OSPF redistribution not allowed\n"); | |
9190 | return CMD_WARNING_CONFIG_FAILED; | |
9191 | } | |
7c8ff89e | 9192 | |
d62a17ae | 9193 | /* Get metric value. */ |
9194 | if (argv_find(argv, argc, "metric", &idx)) | |
9195 | if (!str2metric(argv[idx + 1]->arg, &metric)) | |
9196 | return CMD_WARNING_CONFIG_FAILED; | |
7c8ff89e | 9197 | |
d62a17ae | 9198 | idx = 3; |
9199 | /* Get metric type. */ | |
9200 | if (argv_find(argv, argc, "metric-type", &idx)) | |
9201 | if (!str2metric_type(argv[idx + 1]->arg, &type)) | |
9202 | return CMD_WARNING_CONFIG_FAILED; | |
7c8ff89e | 9203 | |
d62a17ae | 9204 | red = ospf_redist_add(ospf, source, instance); |
7a7be519 | 9205 | |
d62a17ae | 9206 | idx = 3; |
9207 | if (argv_find(argv, argc, "route-map", &idx)) | |
9208 | ospf_routemap_set(red, argv[idx + 1]->arg); | |
9209 | else | |
9210 | ospf_routemap_unset(red); | |
7c8ff89e | 9211 | |
d62a17ae | 9212 | return ospf_redistribute_set(ospf, source, instance, type, metric); |
7c8ff89e DS |
9213 | } |
9214 | ||
9215 | DEFUN (no_ospf_redistribute_instance_source, | |
9216 | no_ospf_redistribute_instance_source_cmd, | |
1a5ce38b | 9217 | "no redistribute <ospf|table> (1-65535) [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]", |
7c8ff89e DS |
9218 | NO_STR |
9219 | REDIST_STR | |
9220 | "Open Shortest Path First\n" | |
2d627ff5 DS |
9221 | "Non-main Kernel Routing Table\n" |
9222 | "Instance ID/Table Id\n" | |
7c8ff89e DS |
9223 | "Metric for redistributed routes\n" |
9224 | "OSPF default metric\n" | |
9225 | "OSPF exterior metric type for redistributed routes\n" | |
7111c1a0 | 9226 | "Set OSPF External Type 1/2 metrics\n" |
7c8ff89e DS |
9227 | "Route map reference\n" |
9228 | "Pointer to route-map entries\n") | |
9229 | { | |
a3d826f0 | 9230 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 9231 | int idx_ospf_table = 2; |
9232 | int idx_number = 3; | |
d7c0a89a | 9233 | unsigned int instance; |
d62a17ae | 9234 | struct ospf_redist *red; |
9235 | int source; | |
9236 | ||
9237 | if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0) | |
9238 | source = ZEBRA_ROUTE_OSPF; | |
9239 | else | |
9240 | source = ZEBRA_ROUTE_TABLE; | |
9241 | ||
9242 | instance = strtoul(argv[idx_number]->arg, NULL, 10); | |
7c8ff89e | 9243 | |
d62a17ae | 9244 | if ((source == ZEBRA_ROUTE_OSPF) && !ospf->instance) { |
9245 | vty_out(vty, | |
9246 | "Instance redistribution in non-instanced OSPF not allowed\n"); | |
9247 | return CMD_WARNING_CONFIG_FAILED; | |
9248 | } | |
9249 | ||
9250 | if ((source == ZEBRA_ROUTE_OSPF) && (ospf->instance == instance)) { | |
9251 | vty_out(vty, "Same instance OSPF redistribution not allowed\n"); | |
9252 | return CMD_WARNING_CONFIG_FAILED; | |
9253 | } | |
9254 | ||
9255 | red = ospf_redist_lookup(ospf, source, instance); | |
9256 | if (!red) | |
9257 | return CMD_SUCCESS; | |
9258 | ||
9259 | ospf_routemap_unset(red); | |
766b826f DA |
9260 | ospf_redist_del(ospf, source, instance); |
9261 | ||
d62a17ae | 9262 | return ospf_redistribute_unset(ospf, source, instance); |
718e3744 | 9263 | } |
9264 | ||
9265 | DEFUN (ospf_distribute_list_out, | |
9266 | ospf_distribute_list_out_cmd, | |
40d1cbfb | 9267 | "distribute-list WORD out " FRR_REDIST_STR_OSPFD, |
718e3744 | 9268 | "Filter networks in routing updates\n" |
6f2a6703 CF |
9269 | "Access-list name\n" |
9270 | OUT_STR | |
ab0181ee | 9271 | FRR_REDIST_HELP_STR_OSPFD) |
718e3744 | 9272 | { |
a3d826f0 | 9273 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 9274 | int idx_word = 1; |
9275 | int source; | |
718e3744 | 9276 | |
d62a17ae | 9277 | char *proto = argv[argc - 1]->text; |
6d681bd8 | 9278 | |
d62a17ae | 9279 | /* Get distribute source. */ |
9280 | source = proto_redistnum(AFI_IP, proto); | |
9281 | if (source < 0) | |
9282 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 9283 | |
d62a17ae | 9284 | return ospf_distribute_list_out_set(ospf, source, argv[idx_word]->arg); |
718e3744 | 9285 | } |
9286 | ||
6f2a6703 CF |
9287 | DEFUN (no_ospf_distribute_list_out, |
9288 | no_ospf_distribute_list_out_cmd, | |
40d1cbfb | 9289 | "no distribute-list WORD out " FRR_REDIST_STR_OSPFD, |
6f2a6703 CF |
9290 | NO_STR |
9291 | "Filter networks in routing updates\n" | |
9292 | "Access-list name\n" | |
9293 | OUT_STR | |
ab0181ee | 9294 | FRR_REDIST_HELP_STR_OSPFD) |
718e3744 | 9295 | { |
a3d826f0 | 9296 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 9297 | int idx_word = 2; |
9298 | int source; | |
020709f9 | 9299 | |
d62a17ae | 9300 | char *proto = argv[argc - 1]->text; |
9301 | source = proto_redistnum(AFI_IP, proto); | |
9302 | if (source < 0) | |
9303 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 9304 | |
d62a17ae | 9305 | return ospf_distribute_list_out_unset(ospf, source, |
9306 | argv[idx_word]->arg); | |
718e3744 | 9307 | } |
9308 | ||
6f2a6703 CF |
9309 | /* Default information originate. */ |
9310 | DEFUN (ospf_default_information_originate, | |
9311 | ospf_default_information_originate_cmd, | |
ea38ced1 | 9312 | "default-information originate [{always|metric (0-16777214)|metric-type (1-2)|route-map WORD}]", |
718e3744 | 9313 | "Control distribution of default information\n" |
9314 | "Distribute a default route\n" | |
9315 | "Always advertise default route\n" | |
6f2a6703 CF |
9316 | "OSPF default metric\n" |
9317 | "OSPF metric\n" | |
718e3744 | 9318 | "OSPF metric type for default routes\n" |
7111c1a0 | 9319 | "Set OSPF External Type 1/2 metrics\n" |
718e3744 | 9320 | "Route map reference\n" |
9321 | "Pointer to route-map entries\n") | |
9322 | { | |
a3d826f0 | 9323 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 9324 | int default_originate = DEFAULT_ORIGINATE_ZEBRA; |
9325 | int type = -1; | |
9326 | int metric = -1; | |
9327 | struct ospf_redist *red; | |
9328 | int idx = 0; | |
1fb93326 | 9329 | int cur_originate = ospf->default_originate; |
9330 | int sameRtmap = 0; | |
9331 | char *rtmap = NULL; | |
d62a17ae | 9332 | |
9333 | red = ospf_redist_add(ospf, DEFAULT_ROUTE, 0); | |
9334 | ||
9335 | /* Check whether "always" was specified */ | |
9336 | if (argv_find(argv, argc, "always", &idx)) | |
9337 | default_originate = DEFAULT_ORIGINATE_ALWAYS; | |
951da435 | 9338 | idx = 1; |
d62a17ae | 9339 | /* Get metric value */ |
ea38ced1 | 9340 | if (argv_find(argv, argc, "(0-16777214)", &idx)) { |
d62a17ae | 9341 | if (!str2metric(argv[idx]->arg, &metric)) |
9342 | return CMD_WARNING_CONFIG_FAILED; | |
9343 | } | |
951da435 | 9344 | idx = 1; |
d62a17ae | 9345 | /* Get metric type. */ |
ea38ced1 | 9346 | if (argv_find(argv, argc, "(1-2)", &idx)) { |
d62a17ae | 9347 | if (!str2metric_type(argv[idx]->arg, &type)) |
9348 | return CMD_WARNING_CONFIG_FAILED; | |
9349 | } | |
951da435 | 9350 | idx = 1; |
d62a17ae | 9351 | /* Get route-map */ |
ea38ced1 | 9352 | if (argv_find(argv, argc, "WORD", &idx)) |
1fb93326 | 9353 | rtmap = argv[idx]->arg; |
9354 | ||
9355 | /* To check ,if user is providing same route map */ | |
9356 | if ((rtmap == ROUTEMAP_NAME(red)) || | |
9357 | (rtmap && ROUTEMAP_NAME(red) | |
9358 | && (strcmp(rtmap, ROUTEMAP_NAME(red)) == 0))) | |
9359 | sameRtmap = 1; | |
9360 | ||
9361 | /* Don't allow if the same lsa is aleardy originated. */ | |
9362 | if ((sameRtmap) | |
9363 | && (red->dmetric.type == type) | |
9364 | && (red->dmetric.value == metric) | |
9365 | && (cur_originate == default_originate)) | |
9366 | return CMD_SUCCESS; | |
9367 | ||
9368 | /* Updating Metric details */ | |
9369 | red->dmetric.type = type; | |
9370 | red->dmetric.value = metric; | |
9371 | ||
9372 | /* updating route map details */ | |
9373 | if (rtmap) | |
9374 | ospf_routemap_set(red, rtmap); | |
d62a17ae | 9375 | else |
9376 | ospf_routemap_unset(red); | |
9377 | ||
9378 | return ospf_redistribute_default_set(ospf, default_originate, type, | |
9379 | metric); | |
718e3744 | 9380 | } |
9381 | ||
9382 | DEFUN (no_ospf_default_information_originate, | |
9383 | no_ospf_default_information_originate_cmd, | |
ea38ced1 | 9384 | "no default-information originate [{always|metric (0-16777214)|metric-type (1-2)|route-map WORD}]", |
718e3744 | 9385 | NO_STR |
9386 | "Control distribution of default information\n" | |
813d4307 DW |
9387 | "Distribute a default route\n" |
9388 | "Always advertise default route\n" | |
9389 | "OSPF default metric\n" | |
9390 | "OSPF metric\n" | |
9391 | "OSPF metric type for default routes\n" | |
7111c1a0 | 9392 | "Set OSPF External Type 1/2 metrics\n" |
813d4307 DW |
9393 | "Route map reference\n" |
9394 | "Pointer to route-map entries\n") | |
718e3744 | 9395 | { |
a3d826f0 | 9396 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 9397 | struct ospf_redist *red; |
7c8ff89e | 9398 | |
d62a17ae | 9399 | red = ospf_redist_lookup(ospf, DEFAULT_ROUTE, 0); |
9400 | if (!red) | |
9401 | return CMD_SUCCESS; | |
7c8ff89e | 9402 | |
d62a17ae | 9403 | ospf_routemap_unset(red); |
766b826f DA |
9404 | ospf_redist_del(ospf, DEFAULT_ROUTE, 0); |
9405 | ||
d5eac1e0 DL |
9406 | return ospf_redistribute_default_set(ospf, DEFAULT_ORIGINATE_NONE, |
9407 | 0, 0); | |
718e3744 | 9408 | } |
9409 | ||
9410 | DEFUN (ospf_default_metric, | |
9411 | ospf_default_metric_cmd, | |
6147e2c6 | 9412 | "default-metric (0-16777214)", |
718e3744 | 9413 | "Set metric of redistributed routes\n" |
9414 | "Default metric\n") | |
9415 | { | |
a3d826f0 | 9416 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 9417 | int idx_number = 1; |
9418 | int metric = -1; | |
718e3744 | 9419 | |
d62a17ae | 9420 | if (!str2metric(argv[idx_number]->arg, &metric)) |
9421 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 9422 | |
d62a17ae | 9423 | ospf->default_metric = metric; |
718e3744 | 9424 | |
d62a17ae | 9425 | return CMD_SUCCESS; |
718e3744 | 9426 | } |
9427 | ||
9428 | DEFUN (no_ospf_default_metric, | |
9429 | no_ospf_default_metric_cmd, | |
7a7be519 | 9430 | "no default-metric [(0-16777214)]", |
718e3744 | 9431 | NO_STR |
7a7be519 | 9432 | "Set metric of redistributed routes\n" |
9433 | "Default metric\n") | |
718e3744 | 9434 | { |
a3d826f0 | 9435 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
68980084 | 9436 | |
d62a17ae | 9437 | ospf->default_metric = -1; |
68980084 | 9438 | |
d62a17ae | 9439 | return CMD_SUCCESS; |
718e3744 | 9440 | } |
9441 | ||
718e3744 | 9442 | |
9443 | DEFUN (ospf_distance, | |
9444 | ospf_distance_cmd, | |
6147e2c6 | 9445 | "distance (1-255)", |
eaa1ae0d | 9446 | "Administrative distance\n" |
718e3744 | 9447 | "OSPF Administrative distance\n") |
9448 | { | |
a3d826f0 | 9449 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 9450 | int idx_number = 1; |
68980084 | 9451 | |
d62a17ae | 9452 | ospf->distance_all = atoi(argv[idx_number]->arg); |
68980084 | 9453 | |
d62a17ae | 9454 | return CMD_SUCCESS; |
718e3744 | 9455 | } |
9456 | ||
9457 | DEFUN (no_ospf_distance, | |
9458 | no_ospf_distance_cmd, | |
6147e2c6 | 9459 | "no distance (1-255)", |
718e3744 | 9460 | NO_STR |
eaa1ae0d | 9461 | "Administrative distance\n" |
718e3744 | 9462 | "OSPF Administrative distance\n") |
9463 | { | |
a3d826f0 | 9464 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
68980084 | 9465 | |
d62a17ae | 9466 | ospf->distance_all = 0; |
68980084 | 9467 | |
d62a17ae | 9468 | return CMD_SUCCESS; |
718e3744 | 9469 | } |
9470 | ||
9471 | DEFUN (no_ospf_distance_ospf, | |
9472 | no_ospf_distance_ospf_cmd, | |
eaa1ae0d | 9473 | "no distance ospf [{intra-area [(1-255)]|inter-area [(1-255)]|external [(1-255)]}]", |
718e3744 | 9474 | NO_STR |
eaa1ae0d QY |
9475 | "Administrative distance\n" |
9476 | "OSPF administrative distance\n" | |
718e3744 | 9477 | "Intra-area routes\n" |
813d4307 | 9478 | "Distance for intra-area routes\n" |
718e3744 | 9479 | "Inter-area routes\n" |
813d4307 DW |
9480 | "Distance for inter-area routes\n" |
9481 | "External routes\n" | |
9482 | "Distance for external routes\n") | |
718e3744 | 9483 | { |
a3d826f0 | 9484 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 9485 | int idx = 0; |
718e3744 | 9486 | |
d62a17ae | 9487 | if (argv_find(argv, argc, "intra-area", &idx) || argc == 3) |
9488 | idx = ospf->distance_intra = 0; | |
9489 | if (argv_find(argv, argc, "inter-area", &idx) || argc == 3) | |
9490 | idx = ospf->distance_inter = 0; | |
9491 | if (argv_find(argv, argc, "external", &idx) || argc == 3) | |
9492 | ospf->distance_external = 0; | |
718e3744 | 9493 | |
d62a17ae | 9494 | return CMD_SUCCESS; |
718e3744 | 9495 | } |
9496 | ||
6f2a6703 CF |
9497 | DEFUN (ospf_distance_ospf, |
9498 | ospf_distance_ospf_cmd, | |
eaa1ae0d QY |
9499 | "distance ospf {intra-area (1-255)|inter-area (1-255)|external (1-255)}", |
9500 | "Administrative distance\n" | |
9501 | "OSPF administrative distance\n" | |
718e3744 | 9502 | "Intra-area routes\n" |
9503 | "Distance for intra-area routes\n" | |
718e3744 | 9504 | "Inter-area routes\n" |
9505 | "Distance for inter-area routes\n" | |
9506 | "External routes\n" | |
718e3744 | 9507 | "Distance for external routes\n") |
9508 | { | |
a3d826f0 | 9509 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 9510 | int idx = 0; |
68980084 | 9511 | |
926b88f0 CS |
9512 | ospf->distance_intra = 0; |
9513 | ospf->distance_inter = 0; | |
9514 | ospf->distance_external = 0; | |
9515 | ||
d62a17ae | 9516 | if (argv_find(argv, argc, "intra-area", &idx)) |
9517 | ospf->distance_intra = atoi(argv[idx + 1]->arg); | |
9518 | idx = 0; | |
9519 | if (argv_find(argv, argc, "inter-area", &idx)) | |
9520 | ospf->distance_inter = atoi(argv[idx + 1]->arg); | |
9521 | idx = 0; | |
9522 | if (argv_find(argv, argc, "external", &idx)) | |
9523 | ospf->distance_external = atoi(argv[idx + 1]->arg); | |
68980084 | 9524 | |
d62a17ae | 9525 | return CMD_SUCCESS; |
718e3744 | 9526 | } |
9527 | ||
ba682537 | 9528 | DEFUN (ip_ospf_mtu_ignore, |
9529 | ip_ospf_mtu_ignore_addr_cmd, | |
7a7be519 | 9530 | "ip ospf mtu-ignore [A.B.C.D]", |
ba682537 | 9531 | "IP Information\n" |
9532 | "OSPF interface commands\n" | |
99a522c7 | 9533 | "Disable MTU mismatch detection on this interface\n" |
efd7904e | 9534 | "Address of interface\n") |
ba682537 | 9535 | { |
d62a17ae | 9536 | VTY_DECLVAR_CONTEXT(interface, ifp); |
9537 | int idx_ipv4 = 3; | |
9538 | struct in_addr addr; | |
9539 | int ret; | |
9540 | ||
9541 | struct ospf_if_params *params; | |
9542 | params = IF_DEF_PARAMS(ifp); | |
9543 | ||
9544 | if (argc == 4) { | |
9545 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
9546 | if (!ret) { | |
9547 | vty_out(vty, | |
9548 | "Please specify interface address by A.B.C.D\n"); | |
9549 | return CMD_WARNING_CONFIG_FAILED; | |
9550 | } | |
9551 | params = ospf_get_if_params(ifp, addr); | |
9552 | ospf_if_update_params(ifp, addr); | |
9553 | } | |
9554 | params->mtu_ignore = 1; | |
9555 | if (params->mtu_ignore != OSPF_MTU_IGNORE_DEFAULT) | |
9556 | SET_IF_PARAM(params, mtu_ignore); | |
9557 | else { | |
9558 | UNSET_IF_PARAM(params, mtu_ignore); | |
9559 | if (params != IF_DEF_PARAMS(ifp)) { | |
9560 | ospf_free_if_params(ifp, addr); | |
9561 | ospf_if_update_params(ifp, addr); | |
9562 | } | |
9563 | } | |
9564 | return CMD_SUCCESS; | |
ba682537 | 9565 | } |
9566 | ||
ba682537 | 9567 | DEFUN (no_ip_ospf_mtu_ignore, |
9568 | no_ip_ospf_mtu_ignore_addr_cmd, | |
7a7be519 | 9569 | "no ip ospf mtu-ignore [A.B.C.D]", |
efd7904e | 9570 | NO_STR |
ba682537 | 9571 | "IP Information\n" |
9572 | "OSPF interface commands\n" | |
99a522c7 | 9573 | "Disable MTU mismatch detection on this interface\n" |
efd7904e | 9574 | "Address of interface\n") |
ba682537 | 9575 | { |
d62a17ae | 9576 | VTY_DECLVAR_CONTEXT(interface, ifp); |
9577 | int idx_ipv4 = 4; | |
9578 | struct in_addr addr; | |
9579 | int ret; | |
9580 | ||
9581 | struct ospf_if_params *params; | |
9582 | params = IF_DEF_PARAMS(ifp); | |
9583 | ||
9584 | if (argc == 5) { | |
9585 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
9586 | if (!ret) { | |
9587 | vty_out(vty, | |
9588 | "Please specify interface address by A.B.C.D\n"); | |
9589 | return CMD_WARNING_CONFIG_FAILED; | |
9590 | } | |
9591 | params = ospf_get_if_params(ifp, addr); | |
9592 | ospf_if_update_params(ifp, addr); | |
9593 | } | |
9594 | params->mtu_ignore = 0; | |
9595 | if (params->mtu_ignore != OSPF_MTU_IGNORE_DEFAULT) | |
9596 | SET_IF_PARAM(params, mtu_ignore); | |
9597 | else { | |
9598 | UNSET_IF_PARAM(params, mtu_ignore); | |
9599 | if (params != IF_DEF_PARAMS(ifp)) { | |
9600 | ospf_free_if_params(ifp, addr); | |
9601 | ospf_if_update_params(ifp, addr); | |
9602 | } | |
9603 | } | |
9604 | return CMD_SUCCESS; | |
ba682537 | 9605 | } |
9606 | ||
6b0655a2 | 9607 | |
88d6cf37 | 9608 | DEFUN (ospf_max_metric_router_lsa_admin, |
9609 | ospf_max_metric_router_lsa_admin_cmd, | |
9610 | "max-metric router-lsa administrative", | |
9611 | "OSPF maximum / infinite-distance metric\n" | |
9612 | "Advertise own Router-LSA with infinite distance (stub router)\n" | |
9613 | "Administratively applied, for an indefinite period\n") | |
9614 | { | |
a3d826f0 | 9615 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 9616 | struct listnode *ln; |
9617 | struct ospf_area *area; | |
7c8ff89e | 9618 | |
d62a17ae | 9619 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, ln, area)) { |
9620 | SET_FLAG(area->stub_router_state, OSPF_AREA_ADMIN_STUB_ROUTED); | |
4ba4fc85 | 9621 | |
d62a17ae | 9622 | if (!CHECK_FLAG(area->stub_router_state, |
9623 | OSPF_AREA_IS_STUB_ROUTED)) | |
9624 | ospf_router_lsa_update_area(area); | |
9625 | } | |
4ba4fc85 | 9626 | |
d62a17ae | 9627 | /* Allows for areas configured later to get the property */ |
9628 | ospf->stub_router_admin_set = OSPF_STUB_ROUTER_ADMINISTRATIVE_SET; | |
9629 | ||
9630 | return CMD_SUCCESS; | |
88d6cf37 | 9631 | } |
9632 | ||
9633 | DEFUN (no_ospf_max_metric_router_lsa_admin, | |
9634 | no_ospf_max_metric_router_lsa_admin_cmd, | |
9635 | "no max-metric router-lsa administrative", | |
9636 | NO_STR | |
9637 | "OSPF maximum / infinite-distance metric\n" | |
9638 | "Advertise own Router-LSA with infinite distance (stub router)\n" | |
9639 | "Administratively applied, for an indefinite period\n") | |
9640 | { | |
a3d826f0 | 9641 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 9642 | struct listnode *ln; |
9643 | struct ospf_area *area; | |
9644 | ||
9645 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, ln, area)) { | |
9646 | UNSET_FLAG(area->stub_router_state, | |
9647 | OSPF_AREA_ADMIN_STUB_ROUTED); | |
9648 | ||
9649 | /* Don't trample on the start-up stub timer */ | |
9650 | if (CHECK_FLAG(area->stub_router_state, | |
9651 | OSPF_AREA_IS_STUB_ROUTED) | |
9652 | && !area->t_stub_router) { | |
9653 | UNSET_FLAG(area->stub_router_state, | |
9654 | OSPF_AREA_IS_STUB_ROUTED); | |
9655 | ospf_router_lsa_update_area(area); | |
9656 | } | |
9657 | } | |
9658 | ospf->stub_router_admin_set = OSPF_STUB_ROUTER_ADMINISTRATIVE_UNSET; | |
9659 | return CMD_SUCCESS; | |
88d6cf37 | 9660 | } |
9661 | ||
9662 | DEFUN (ospf_max_metric_router_lsa_startup, | |
9663 | ospf_max_metric_router_lsa_startup_cmd, | |
6147e2c6 | 9664 | "max-metric router-lsa on-startup (5-86400)", |
88d6cf37 | 9665 | "OSPF maximum / infinite-distance metric\n" |
9666 | "Advertise own Router-LSA with infinite distance (stub router)\n" | |
9667 | "Automatically advertise stub Router-LSA on startup of OSPF\n" | |
9668 | "Time (seconds) to advertise self as stub-router\n") | |
9669 | { | |
a3d826f0 | 9670 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 9671 | int idx_number = 3; |
9672 | unsigned int seconds; | |
9673 | ||
b5a8894d | 9674 | if (argc < 4) { |
d62a17ae | 9675 | vty_out(vty, "%% Must supply stub-router period"); |
9676 | return CMD_WARNING_CONFIG_FAILED; | |
9677 | } | |
9678 | ||
9679 | seconds = strtoul(argv[idx_number]->arg, NULL, 10); | |
9680 | ||
9681 | ospf->stub_router_startup_time = seconds; | |
9682 | ||
9683 | return CMD_SUCCESS; | |
88d6cf37 | 9684 | } |
9685 | ||
9686 | DEFUN (no_ospf_max_metric_router_lsa_startup, | |
9687 | no_ospf_max_metric_router_lsa_startup_cmd, | |
7a7be519 | 9688 | "no max-metric router-lsa on-startup [(5-86400)]", |
88d6cf37 | 9689 | NO_STR |
9690 | "OSPF maximum / infinite-distance metric\n" | |
9691 | "Advertise own Router-LSA with infinite distance (stub router)\n" | |
813d4307 DW |
9692 | "Automatically advertise stub Router-LSA on startup of OSPF\n" |
9693 | "Time (seconds) to advertise self as stub-router\n") | |
88d6cf37 | 9694 | { |
a3d826f0 | 9695 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 9696 | struct listnode *ln; |
9697 | struct ospf_area *area; | |
9698 | ||
9699 | ospf->stub_router_startup_time = OSPF_STUB_ROUTER_UNCONFIGURED; | |
9700 | ||
9701 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, ln, area)) { | |
9702 | SET_FLAG(area->stub_router_state, | |
9703 | OSPF_AREA_WAS_START_STUB_ROUTED); | |
9704 | OSPF_TIMER_OFF(area->t_stub_router); | |
9705 | ||
9706 | /* Don't trample on admin stub routed */ | |
9707 | if (!CHECK_FLAG(area->stub_router_state, | |
9708 | OSPF_AREA_ADMIN_STUB_ROUTED)) { | |
9709 | UNSET_FLAG(area->stub_router_state, | |
9710 | OSPF_AREA_IS_STUB_ROUTED); | |
9711 | ospf_router_lsa_update_area(area); | |
9712 | } | |
9713 | } | |
9714 | return CMD_SUCCESS; | |
88d6cf37 | 9715 | } |
9716 | ||
a1afa410 | 9717 | |
88d6cf37 | 9718 | DEFUN (ospf_max_metric_router_lsa_shutdown, |
9719 | ospf_max_metric_router_lsa_shutdown_cmd, | |
6147e2c6 | 9720 | "max-metric router-lsa on-shutdown (5-100)", |
88d6cf37 | 9721 | "OSPF maximum / infinite-distance metric\n" |
9722 | "Advertise own Router-LSA with infinite distance (stub router)\n" | |
9723 | "Advertise stub-router prior to full shutdown of OSPF\n" | |
9724 | "Time (seconds) to wait till full shutdown\n") | |
9725 | { | |
a3d826f0 | 9726 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 9727 | int idx_number = 3; |
9728 | unsigned int seconds; | |
9729 | ||
b5a8894d | 9730 | if (argc < 4) { |
d62a17ae | 9731 | vty_out(vty, "%% Must supply stub-router shutdown period"); |
9732 | return CMD_WARNING_CONFIG_FAILED; | |
9733 | } | |
9734 | ||
9735 | seconds = strtoul(argv[idx_number]->arg, NULL, 10); | |
9736 | ||
9737 | ospf->stub_router_shutdown_time = seconds; | |
9738 | ||
9739 | return CMD_SUCCESS; | |
88d6cf37 | 9740 | } |
9741 | ||
9742 | DEFUN (no_ospf_max_metric_router_lsa_shutdown, | |
9743 | no_ospf_max_metric_router_lsa_shutdown_cmd, | |
7a7be519 | 9744 | "no max-metric router-lsa on-shutdown [(5-100)]", |
88d6cf37 | 9745 | NO_STR |
9746 | "OSPF maximum / infinite-distance metric\n" | |
9747 | "Advertise own Router-LSA with infinite distance (stub router)\n" | |
813d4307 DW |
9748 | "Advertise stub-router prior to full shutdown of OSPF\n" |
9749 | "Time (seconds) to wait till full shutdown\n") | |
88d6cf37 | 9750 | { |
a3d826f0 | 9751 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
7c8ff89e | 9752 | |
d62a17ae | 9753 | ospf->stub_router_shutdown_time = OSPF_STUB_ROUTER_UNCONFIGURED; |
9754 | ||
9755 | return CMD_SUCCESS; | |
88d6cf37 | 9756 | } |
9757 | ||
a92706bb JU |
9758 | DEFUN (ospf_proactive_arp, |
9759 | ospf_proactive_arp_cmd, | |
9760 | "proactive-arp", | |
9761 | "Allow sending ARP requests proactively\n") | |
9762 | { | |
9763 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
9764 | ||
9765 | ospf->proactive_arp = true; | |
9766 | ||
9767 | return CMD_SUCCESS; | |
9768 | } | |
9769 | ||
9770 | DEFUN (no_ospf_proactive_arp, | |
9771 | no_ospf_proactive_arp_cmd, | |
9772 | "no proactive-arp", | |
9773 | NO_STR | |
9774 | "Disallow sending ARP requests proactively\n") | |
9775 | { | |
9776 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
9777 | ||
9778 | ospf->proactive_arp = false; | |
9779 | ||
9780 | return CMD_SUCCESS; | |
9781 | } | |
9782 | ||
07b33add | 9783 | /* Graceful Restart HELPER Commands */ |
9784 | DEFPY(ospf_gr_helper_enable, ospf_gr_helper_enable_cmd, | |
9785 | "graceful-restart helper-only [A.B.C.D]", | |
9786 | "OSPF Graceful Restart\n" | |
9787 | "Enable Helper support\n" | |
9788 | "Advertising router id\n") | |
9789 | { | |
9790 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
9791 | struct in_addr addr; | |
9792 | int ret; | |
9793 | ||
9794 | if (argc == 3) { | |
9795 | ret = inet_aton(argv[2]->arg, &addr); | |
9796 | if (!ret) { | |
9797 | vty_out(vty, | |
9798 | "Please specify the valid routerid address.\n"); | |
9799 | return CMD_WARNING_CONFIG_FAILED; | |
9800 | } | |
9801 | ||
9802 | ospf_gr_helper_support_set_per_routerid(ospf, &addr, OSPF_GR_TRUE); | |
9803 | return CMD_SUCCESS; | |
9804 | } | |
9805 | ||
9806 | ospf_gr_helper_support_set(ospf, OSPF_GR_TRUE); | |
9807 | ||
9808 | return CMD_SUCCESS; | |
9809 | } | |
9810 | ||
9811 | DEFPY(no_ospf_gr_helper_enable, | |
9812 | no_ospf_gr_helper_enable_cmd, | |
9813 | "no graceful-restart helper-only [A.B.C.D]", | |
9814 | NO_STR | |
9815 | "OSPF Graceful Restart\n" | |
9816 | "Disable Helper support\n" | |
9817 | "Advertising router id\n") | |
9818 | { | |
9819 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
9820 | struct in_addr addr; | |
9821 | int ret; | |
9822 | ||
9823 | if (argc == 4) { | |
9824 | ret = inet_aton(argv[3]->arg, &addr); | |
9825 | if (!ret) { | |
9826 | vty_out(vty, | |
9827 | "Please specify the valid routerid address.\n"); | |
9828 | return CMD_WARNING_CONFIG_FAILED; | |
9829 | } | |
9830 | ||
9831 | ospf_gr_helper_support_set_per_routerid(ospf, &addr, | |
9832 | OSPF_GR_FALSE); | |
9833 | return CMD_SUCCESS; | |
9834 | } | |
9835 | ||
9836 | ospf_gr_helper_support_set(ospf, OSPF_GR_FALSE); | |
9837 | return CMD_SUCCESS; | |
9838 | } | |
9839 | ||
9840 | DEFPY(ospf_gr_helper_enable_lsacheck, | |
9841 | ospf_gr_helper_enable_lsacheck_cmd, | |
9842 | "graceful-restart helper strict-lsa-checking", | |
9843 | "OSPF Graceful Restart\n" | |
9844 | "OSPF GR Helper\n" | |
9845 | "Enable strict LSA check\n") | |
9846 | { | |
9847 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
9848 | ||
9849 | ospf_gr_helper_lsa_check_set(ospf, OSPF_GR_TRUE); | |
9850 | return CMD_SUCCESS; | |
9851 | } | |
9852 | ||
9853 | DEFPY(no_ospf_gr_helper_enable_lsacheck, | |
9854 | no_ospf_gr_helper_enable_lsacheck_cmd, | |
9855 | "no graceful-restart helper strict-lsa-checking", | |
9856 | NO_STR | |
9857 | "OSPF Graceful Restart\n" | |
9858 | "OSPF GR Helper\n" | |
9859 | "Disable strict LSA check\n") | |
9860 | { | |
9861 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
9862 | ||
9863 | ospf_gr_helper_lsa_check_set(ospf, OSPF_GR_FALSE); | |
9864 | return CMD_SUCCESS; | |
9865 | } | |
9866 | ||
9867 | DEFPY(ospf_gr_helper_supported_grace_time, | |
9868 | ospf_gr_helper_supported_grace_time_cmd, | |
9869 | "graceful-restart helper supported-grace-time (10-1800)$interval", | |
9870 | "OSPF Graceful Restart\n" | |
9871 | "OSPF GR Helper\n" | |
9872 | "Supported grace timer\n" | |
9873 | "Grace interval(in seconds)\n") | |
9874 | { | |
9875 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
9876 | ||
9877 | ospf_gr_helper_supported_gracetime_set(ospf, interval); | |
9878 | return CMD_SUCCESS; | |
9879 | } | |
9880 | ||
9881 | DEFPY(no_ospf_gr_helper_supported_grace_time, | |
9882 | no_ospf_gr_helper_supported_grace_time_cmd, | |
9883 | "no graceful-restart helper supported-grace-time (10-1800)$interval", | |
9884 | NO_STR | |
9885 | "OSPF Graceful Restart\n" | |
9886 | "OSPF GR Helper\n" | |
9887 | "Supported grace timer\n" | |
9888 | "Grace interval(in seconds)\n") | |
9889 | { | |
9890 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
9891 | ||
9892 | ospf_gr_helper_supported_gracetime_set(ospf, OSPF_MAX_GRACE_INTERVAL); | |
9893 | return CMD_SUCCESS; | |
9894 | } | |
9895 | ||
9896 | DEFPY(ospf_gr_helper_planned_only, | |
9897 | ospf_gr_helper_planned_only_cmd, | |
9898 | "graceful-restart helper planned-only", | |
9899 | "OSPF Graceful Restart\n" | |
9900 | "OSPF GR Helper\n" | |
9901 | "Supported only planned restart\n") | |
9902 | { | |
9903 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
9904 | ||
9905 | ospf_gr_helper_set_supported_planned_only_restart(ospf, OSPF_GR_TRUE); | |
9906 | ||
9907 | return CMD_SUCCESS; | |
9908 | } | |
9909 | ||
423e71c4 | 9910 | /* External Route Aggregation */ |
9911 | DEFUN (ospf_external_route_aggregation, | |
9912 | ospf_external_route_aggregation_cmd, | |
9913 | "summary-address A.B.C.D/M [tag (1-4294967295)]", | |
9914 | "External summary address\n" | |
9915 | "Summary address prefix (a.b.c.d/m) \n" | |
9916 | "Router tag \n" | |
9917 | "Router tag value\n") | |
9918 | { | |
9919 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
9920 | struct prefix_ipv4 p; | |
9921 | int idx = 1; | |
9922 | route_tag_t tag = 0; | |
9923 | int ret = OSPF_SUCCESS; | |
9924 | ||
9925 | str2prefix_ipv4(argv[idx]->arg, &p); | |
9926 | ||
9927 | if (is_prefix_default(&p)) { | |
9928 | vty_out(vty, | |
9929 | "Default address shouldn't be configured as summary address.\n"); | |
9930 | return CMD_SUCCESS; | |
9931 | } | |
9932 | ||
9933 | /* Apply mask for given prefix. */ | |
9934 | apply_mask((struct prefix *)&p); | |
9935 | ||
9936 | if (!is_valid_summary_addr(&p)) { | |
9937 | vty_out(vty, "Not a valid summary address.\n"); | |
9938 | return CMD_WARNING_CONFIG_FAILED; | |
9939 | } | |
9940 | ||
9941 | if (argc > 2) | |
9942 | tag = strtoul(argv[idx + 2]->arg, NULL, 10); | |
9943 | ||
9944 | ret = ospf_asbr_external_aggregator_set(ospf, &p, tag); | |
9945 | if (ret == OSPF_INVALID) | |
9946 | vty_out(vty, "Inavlid configuration!!\n"); | |
9947 | ||
9948 | return CMD_SUCCESS; | |
9949 | } | |
9950 | ||
9951 | DEFUN (no_ospf_external_route_aggregation, | |
9952 | no_ospf_external_route_aggregation_cmd, | |
9953 | "no summary-address A.B.C.D/M [tag (1-4294967295)]", | |
9954 | NO_STR | |
9955 | "External summary address\n" | |
9956 | "Summary address prefix (a.b.c.d/m)\n" | |
9957 | "Router tag\n" | |
9958 | "Router tag value\n") | |
9959 | { | |
9960 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
9961 | struct prefix_ipv4 p; | |
9962 | int idx = 2; | |
9963 | route_tag_t tag = 0; | |
9964 | int ret = OSPF_SUCCESS; | |
9965 | ||
9966 | str2prefix_ipv4(argv[idx]->arg, &p); | |
9967 | ||
9968 | if (is_prefix_default(&p)) { | |
9969 | vty_out(vty, | |
9970 | "Default address shouldn't be configured as summary address.\n"); | |
9971 | return CMD_SUCCESS; | |
9972 | } | |
9973 | ||
9974 | /* Apply mask for given prefix. */ | |
9975 | apply_mask((struct prefix *)&p); | |
9976 | ||
9977 | if (!is_valid_summary_addr(&p)) { | |
9978 | vty_out(vty, "Not a valid summary address.\n"); | |
9979 | return CMD_WARNING_CONFIG_FAILED; | |
9980 | } | |
9981 | ||
9982 | if (argc > 3) | |
9983 | tag = strtoul(argv[idx + 2]->arg, NULL, 10); | |
9984 | ||
9985 | ret = ospf_asbr_external_aggregator_unset(ospf, &p, tag); | |
9986 | if (ret == OSPF_INVALID) | |
9987 | vty_out(vty, "Inavlid configuration!!\n"); | |
9988 | ||
9989 | return CMD_SUCCESS; | |
9990 | } | |
9991 | ||
07b33add | 9992 | DEFPY(no_ospf_gr_helper_planned_only, |
9993 | no_ospf_gr_helper_planned_only_cmd, | |
9994 | "no graceful-restart helper planned-only", | |
9995 | NO_STR | |
9996 | "OSPF Graceful Restart\n" | |
9997 | "OSPF GR Helper\n" | |
9998 | "Supported only for planned restart\n") | |
9999 | { | |
10000 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
10001 | ||
10002 | ospf_gr_helper_set_supported_planned_only_restart(ospf, OSPF_GR_FALSE); | |
10003 | ||
10004 | return CMD_SUCCESS; | |
10005 | } | |
abd5b8c7 | 10006 | |
1ac88792 | 10007 | static int ospf_print_vty_helper_dis_rtr_walkcb(struct hash_bucket *bucket, |
abd5b8c7 | 10008 | void *arg) |
10009 | { | |
1ac88792 | 10010 | struct advRtr *rtr = bucket->data; |
abd5b8c7 | 10011 | struct vty *vty = (struct vty *)arg; |
10012 | static unsigned int count; | |
10013 | ||
96b663a3 | 10014 | vty_out(vty, "%-6pI4,", &rtr->advRtrAddr); |
abd5b8c7 | 10015 | count++; |
10016 | ||
10017 | if (count % 5 == 0) | |
10018 | vty_out(vty, "\n"); | |
10019 | ||
10020 | return HASHWALK_CONTINUE; | |
10021 | } | |
10022 | ||
10023 | static int ospf_show_gr_helper_details(struct vty *vty, struct ospf *ospf, | |
10024 | uint8_t use_vrf, json_object *json, | |
10025 | bool uj, bool detail) | |
10026 | { | |
10027 | struct listnode *node; | |
10028 | struct ospf_interface *oi; | |
96b663a3 | 10029 | char buf[PREFIX_STRLEN]; |
abd5b8c7 | 10030 | json_object *json_vrf = NULL; |
10031 | ||
10032 | if (uj) { | |
10033 | if (use_vrf) | |
10034 | json_vrf = json_object_new_object(); | |
10035 | else | |
10036 | json_vrf = json; | |
10037 | } | |
10038 | ||
10039 | if (ospf->instance) { | |
10040 | if (uj) | |
10041 | json_object_int_add(json, "ospfInstance", | |
10042 | ospf->instance); | |
10043 | else | |
10044 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
10045 | } | |
10046 | ||
10047 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); | |
10048 | ||
10049 | if (uj) { | |
10050 | if (use_vrf) { | |
10051 | if (ospf->vrf_id == VRF_DEFAULT) | |
10052 | json_object_object_add(json, "default", | |
10053 | json_vrf); | |
10054 | else | |
10055 | json_object_object_add(json, ospf->name, | |
10056 | json_vrf); | |
10057 | } | |
10058 | } else | |
10059 | vty_out(vty, "\n"); | |
10060 | ||
10061 | /* Show Router ID. */ | |
10062 | if (uj) { | |
10063 | json_object_string_add(json_vrf, "routerId", | |
96b663a3 MS |
10064 | inet_ntop(AF_INET, &ospf->router_id, |
10065 | buf, sizeof(buf))); | |
abd5b8c7 | 10066 | } else { |
96b663a3 MS |
10067 | vty_out(vty, "\n OSPF Router with ID (%pI4)\n\n", |
10068 | &ospf->router_id); | |
abd5b8c7 | 10069 | } |
10070 | ||
10071 | if (!uj) { | |
10072 | ||
10073 | if (ospf->is_helper_supported) | |
10074 | vty_out(vty, | |
10075 | " Graceful restart helper support enabled.\n"); | |
10076 | else | |
10077 | vty_out(vty, | |
10078 | " Graceful restart helper support disabled.\n"); | |
10079 | ||
10080 | if (ospf->strict_lsa_check) | |
10081 | vty_out(vty, " Strict LSA check is enabled.\n"); | |
10082 | else | |
10083 | vty_out(vty, " Strict LSA check is disabled.\n"); | |
10084 | ||
10085 | if (ospf->only_planned_restart) | |
10086 | vty_out(vty, | |
10087 | " Helper supported for planned restarts only.\n"); | |
10088 | else | |
10089 | vty_out(vty, | |
10090 | " Helper supported for Planned and Unplanned Restarts.\n"); | |
10091 | ||
10092 | vty_out(vty, | |
10093 | " Supported Graceful restart interval: %d(in seconds).\n", | |
10094 | ospf->supported_grace_time); | |
10095 | ||
10096 | if (OSPF_HELPER_ENABLE_RTR_COUNT(ospf)) { | |
10097 | vty_out(vty, " Enable Router list:\n"); | |
10098 | vty_out(vty, " "); | |
10099 | hash_walk(ospf->enable_rtr_list, | |
10100 | ospf_print_vty_helper_dis_rtr_walkcb, vty); | |
10101 | vty_out(vty, "\n\n"); | |
10102 | } | |
10103 | ||
10104 | if (ospf->last_exit_reason != OSPF_GR_HELPER_EXIT_NONE) { | |
10105 | vty_out(vty, " Last Helper exit Reason :%s\n", | |
d05d5280 | 10106 | ospf_exit_reason2str(ospf->last_exit_reason)); |
abd5b8c7 | 10107 | } |
10108 | ||
10109 | if (ospf->active_restarter_cnt) | |
10110 | vty_out(vty, | |
10111 | " Number of Active neighbours in graceful restart: %d\n", | |
10112 | ospf->active_restarter_cnt); | |
10113 | else | |
10114 | vty_out(vty, "\n"); | |
10115 | ||
10116 | } else { | |
10117 | json_object_string_add( | |
10118 | json_vrf, "helperSupport", | |
10119 | (ospf->is_helper_supported) ? "Enabled" : "Disabled"); | |
10120 | json_object_string_add(json_vrf, "strictLsaCheck", | |
10121 | (ospf->strict_lsa_check) ? "Enabled" | |
10122 | : "Disabled"); | |
10123 | json_object_string_add( | |
10124 | json_vrf, "restartSupoort", | |
10125 | (ospf->only_planned_restart) | |
10126 | ? "Planned Restart only" | |
10127 | : "Planned and Unplanned Restarts"); | |
10128 | ||
10129 | json_object_int_add(json_vrf, "supportedGracePeriod", | |
10130 | ospf->supported_grace_time); | |
10131 | ||
10132 | if (ospf->last_exit_reason != OSPF_GR_HELPER_EXIT_NONE) | |
10133 | json_object_string_add( | |
10134 | json_vrf, "LastExitReason", | |
d05d5280 | 10135 | ospf_exit_reason2str(ospf->last_exit_reason)); |
abd5b8c7 | 10136 | |
10137 | if (ospf->active_restarter_cnt) | |
10138 | json_object_int_add(json_vrf, "activeRestarterCnt", | |
10139 | ospf->active_restarter_cnt); | |
10140 | } | |
10141 | ||
10142 | ||
10143 | if (detail) { | |
10144 | int cnt = 1; | |
10145 | json_object *json_neighbors = NULL; | |
10146 | ||
10147 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) { | |
10148 | struct route_node *rn; | |
10149 | struct ospf_neighbor *nbr; | |
10150 | json_object *json_neigh; | |
10151 | ||
10152 | if (ospf_interface_neighbor_count(oi) == 0) | |
10153 | continue; | |
10154 | ||
10155 | if (uj) { | |
10156 | json_object_object_get_ex(json_vrf, "Neighbors", | |
10157 | &json_neighbors); | |
10158 | if (!json_neighbors) { | |
10159 | json_neighbors = | |
10160 | json_object_new_object(); | |
10161 | json_object_object_add(json_vrf, | |
10162 | "Neighbors", | |
10163 | json_neighbors); | |
10164 | } | |
10165 | } | |
10166 | ||
10167 | for (rn = route_top(oi->nbrs); rn; | |
10168 | rn = route_next(rn)) { | |
10169 | ||
10170 | if (!rn->info) | |
10171 | continue; | |
10172 | ||
10173 | nbr = rn->info; | |
10174 | ||
10175 | if (!OSPF_GR_IS_ACTIVE_HELPER(nbr)) | |
10176 | continue; | |
10177 | ||
10178 | if (!uj) { | |
10179 | vty_out(vty, " Neighbour %d :\n", cnt); | |
96b663a3 MS |
10180 | vty_out(vty, " Address : %pI4\n", |
10181 | &nbr->address.u.prefix4); | |
10182 | vty_out(vty, " Routerid : %pI4\n", | |
10183 | &nbr->router_id); | |
abd5b8c7 | 10184 | vty_out(vty, |
10185 | " Received Grace period : %d(in seconds).\n", | |
10186 | nbr->gr_helper_info | |
10187 | .recvd_grace_period); | |
10188 | vty_out(vty, | |
10189 | " Actual Grace period : %d(in seconds)\n", | |
10190 | nbr->gr_helper_info | |
10191 | .actual_grace_period); | |
10192 | vty_out(vty, | |
10193 | " Remaining GraceTime:%ld(in seconds).\n", | |
10194 | thread_timer_remain_second( | |
10195 | nbr->gr_helper_info | |
10196 | .t_grace_timer)); | |
10197 | vty_out(vty, | |
10198 | " Graceful Restart reason: %s.\n\n", | |
d05d5280 MS |
10199 | ospf_restart_reason2str( |
10200 | nbr->gr_helper_info | |
10201 | .gr_restart_reason)); | |
abd5b8c7 | 10202 | cnt++; |
10203 | } else { | |
10204 | json_neigh = json_object_new_object(); | |
10205 | json_object_string_add( | |
10206 | json_neigh, "srcAddr", | |
96b663a3 MS |
10207 | inet_ntop(AF_INET, &nbr->src, |
10208 | buf, sizeof(buf))); | |
abd5b8c7 | 10209 | |
10210 | json_object_string_add( | |
10211 | json_neigh, "routerid", | |
96b663a3 MS |
10212 | inet_ntop(AF_INET, |
10213 | &nbr->router_id, | |
10214 | buf, sizeof(buf))); | |
abd5b8c7 | 10215 | json_object_int_add( |
10216 | json_neigh, | |
10217 | "recvdGraceInterval", | |
10218 | nbr->gr_helper_info | |
10219 | .recvd_grace_period); | |
10220 | json_object_int_add( | |
10221 | json_neigh, | |
10222 | "actualGraceInterval", | |
10223 | nbr->gr_helper_info | |
10224 | .actual_grace_period); | |
10225 | json_object_int_add( | |
10226 | json_neigh, "remainGracetime", | |
10227 | thread_timer_remain_second( | |
10228 | nbr->gr_helper_info | |
10229 | .t_grace_timer)); | |
10230 | json_object_string_add( | |
10231 | json_neigh, "restartReason", | |
d05d5280 MS |
10232 | ospf_restart_reason2str( |
10233 | nbr->gr_helper_info | |
10234 | .gr_restart_reason)); | |
abd5b8c7 | 10235 | json_object_object_add( |
10236 | json_neighbors, | |
96b663a3 MS |
10237 | inet_ntop(AF_INET, &nbr->src, |
10238 | buf, sizeof(buf)), | |
abd5b8c7 | 10239 | json_neigh); |
10240 | } | |
10241 | } | |
10242 | } | |
10243 | } | |
423e71c4 | 10244 | return CMD_SUCCESS; |
10245 | } | |
10246 | ||
10247 | DEFUN (ospf_external_route_aggregation_no_adrvertise, | |
10248 | ospf_external_route_aggregation_no_adrvertise_cmd, | |
10249 | "summary-address A.B.C.D/M no-advertise", | |
10250 | "External summary address\n" | |
10251 | "Summary address prefix (a.b.c.d/m) \n" | |
10252 | "Don't advertise summary route \n") | |
10253 | { | |
10254 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
10255 | struct prefix_ipv4 p; | |
10256 | int idx = 1; | |
10257 | int ret = OSPF_SUCCESS; | |
10258 | ||
10259 | str2prefix_ipv4(argv[idx]->arg, &p); | |
10260 | ||
10261 | if (is_prefix_default(&p)) { | |
10262 | vty_out(vty, | |
10263 | "Default address shouldn't be configured as summary address.\n"); | |
10264 | return CMD_SUCCESS; | |
10265 | } | |
10266 | ||
10267 | /* Apply mask for given prefix. */ | |
10268 | apply_mask((struct prefix *)&p); | |
10269 | ||
10270 | if (!is_valid_summary_addr(&p)) { | |
10271 | vty_out(vty, "Not a valid summary address.\n"); | |
10272 | return CMD_WARNING_CONFIG_FAILED; | |
10273 | } | |
10274 | ||
10275 | ret = ospf_asbr_external_rt_no_advertise(ospf, &p); | |
10276 | if (ret == OSPF_INVALID) | |
10277 | vty_out(vty, "Inavlid configuration!!\n"); | |
10278 | ||
10279 | return CMD_SUCCESS; | |
10280 | } | |
10281 | ||
10282 | DEFUN (no_ospf_external_route_aggregation_no_adrvertise, | |
10283 | no_ospf_external_route_aggregation_no_adrvertise_cmd, | |
10284 | "no summary-address A.B.C.D/M no-advertise", | |
10285 | NO_STR | |
10286 | "External summary address\n" | |
fbc48492 DS |
10287 | "Summary address prefix (a.b.c.d/m)\n" |
10288 | "Advertise summary route to the AS \n") | |
423e71c4 | 10289 | { |
10290 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
10291 | struct prefix_ipv4 p; | |
10292 | int idx = 2; | |
10293 | int ret = OSPF_SUCCESS; | |
10294 | ||
10295 | str2prefix_ipv4(argv[idx]->arg, &p); | |
10296 | ||
10297 | if (is_prefix_default(&p)) { | |
10298 | vty_out(vty, | |
10299 | "Default address shouldn't be configured as summary address.\n"); | |
10300 | return CMD_SUCCESS; | |
10301 | } | |
10302 | ||
10303 | /* Apply mask for given prefix. */ | |
10304 | apply_mask((struct prefix *)&p); | |
10305 | ||
10306 | if (!is_valid_summary_addr(&p)) { | |
10307 | vty_out(vty, "Not a valid summary address.\n"); | |
10308 | return CMD_WARNING_CONFIG_FAILED; | |
10309 | } | |
10310 | ||
10311 | ret = ospf_asbr_external_rt_advertise(ospf, &p); | |
10312 | if (ret == OSPF_INVALID) | |
10313 | vty_out(vty, "Inavlid configuration!!\n"); | |
10314 | ||
10315 | return CMD_SUCCESS; | |
10316 | } | |
10317 | ||
10318 | DEFUN (ospf_route_aggregation_timer, | |
10319 | ospf_route_aggregation_timer_cmd, | |
10320 | "aggregation timer (5-1800)", | |
10321 | "External route aggregation\n" | |
10322 | "Delay timer (in seconds)\n" | |
10323 | "Timer interval(in seconds)\n") | |
10324 | { | |
10325 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
10326 | unsigned int interval = 0; | |
10327 | ||
10328 | interval = strtoul(argv[2]->arg, NULL, 10); | |
10329 | ||
10330 | ospf_external_aggregator_timer_set(ospf, interval); | |
abd5b8c7 | 10331 | |
10332 | return CMD_SUCCESS; | |
10333 | } | |
10334 | ||
10335 | DEFPY (show_ip_ospf_gr_helper, | |
10336 | show_ip_ospf_gr_helper_cmd, | |
10337 | "show ip ospf [vrf <NAME|all>] graceful-restart helper [detail] [json]", | |
10338 | SHOW_STR | |
10339 | IP_STR | |
10340 | "OSPF information\n" | |
10341 | VRF_CMD_HELP_STR | |
10342 | "All VRFs\n" | |
10343 | "OSPF Graceful Restart\n" | |
10344 | "Helper details in the router\n" | |
10345 | "Detailed informtion\n" | |
10346 | JSON_STR) | |
10347 | { | |
10348 | char *vrf_name = NULL; | |
10349 | bool all_vrf = false; | |
10350 | int ret = CMD_SUCCESS; | |
10351 | int idx_vrf = 0; | |
10352 | int idx = 0; | |
10353 | uint8_t use_vrf = 0; | |
10354 | bool uj = use_json(argc, argv); | |
10355 | struct ospf *ospf = NULL; | |
10356 | json_object *json = NULL; | |
10357 | struct listnode *node = NULL; | |
10358 | int inst = 0; | |
10359 | bool detail = false; | |
10360 | ||
10361 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); | |
10362 | ||
10363 | if (argv_find(argv, argc, "detail", &idx)) | |
10364 | detail = true; | |
10365 | ||
10366 | if (uj) | |
10367 | json = json_object_new_object(); | |
10368 | ||
10369 | /* vrf input is provided */ | |
10370 | if (vrf_name) { | |
10371 | use_vrf = 1; | |
10372 | ||
10373 | if (all_vrf) { | |
10374 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
10375 | if (!ospf->oi_running) | |
10376 | continue; | |
10377 | ||
10378 | ret = ospf_show_gr_helper_details( | |
10379 | vty, ospf, use_vrf, json, uj, detail); | |
10380 | } | |
10381 | ||
10382 | if (uj) { | |
10383 | vty_out(vty, "%s\n", | |
10384 | json_object_to_json_string_ext( | |
10385 | json, JSON_C_TO_STRING_PRETTY)); | |
10386 | json_object_free(json); | |
10387 | } | |
10388 | ||
10389 | return ret; | |
10390 | } | |
10391 | ||
10392 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
10393 | ||
10394 | if (ospf == NULL || !ospf->oi_running) { | |
10395 | ||
10396 | if (uj) { | |
10397 | vty_out(vty, "%s\n", | |
10398 | json_object_to_json_string_ext( | |
10399 | json, JSON_C_TO_STRING_PRETTY)); | |
10400 | json_object_free(json); | |
10401 | } else | |
10402 | vty_out(vty, "%% OSPF instance not found\n"); | |
10403 | ||
10404 | return CMD_SUCCESS; | |
10405 | } | |
10406 | ||
10407 | } else { | |
10408 | /* Default Vrf */ | |
10409 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
10410 | ||
10411 | if (ospf == NULL || !ospf->oi_running) { | |
10412 | ||
10413 | if (uj) { | |
10414 | vty_out(vty, "%s\n", | |
10415 | json_object_to_json_string_ext( | |
10416 | json, JSON_C_TO_STRING_PRETTY)); | |
10417 | json_object_free(json); | |
10418 | } else | |
10419 | vty_out(vty, "%% OSPF instance not found\n"); | |
10420 | ||
10421 | return CMD_SUCCESS; | |
10422 | } | |
10423 | ||
10424 | ospf_show_gr_helper_details(vty, ospf, use_vrf, json, uj, | |
10425 | detail); | |
10426 | } | |
10427 | ||
10428 | if (uj) { | |
10429 | vty_out(vty, "%s\n", json_object_to_json_string_ext( | |
10430 | json, JSON_C_TO_STRING_PRETTY)); | |
10431 | json_object_free(json); | |
10432 | } | |
10433 | ||
10434 | return CMD_SUCCESS; | |
10435 | } | |
07b33add | 10436 | /* Graceful Restart HELPER commands end */ |
423e71c4 | 10437 | DEFUN (no_ospf_route_aggregation_timer, |
10438 | no_ospf_route_aggregation_timer_cmd, | |
10439 | "no aggregation timer", | |
10440 | NO_STR | |
10441 | "External route aggregation\n" | |
10442 | "Delay timer\n") | |
10443 | { | |
10444 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
10445 | ||
10446 | ospf_external_aggregator_timer_set(ospf, OSPF_EXTL_AGGR_DEFAULT_DELAY); | |
10447 | ||
10448 | return CMD_SUCCESS; | |
10449 | } | |
10450 | ||
10451 | /* External Route Aggregation End */ | |
07b33add | 10452 | |
d62a17ae | 10453 | static void config_write_stub_router(struct vty *vty, struct ospf *ospf) |
10454 | { | |
10455 | struct listnode *ln; | |
10456 | struct ospf_area *area; | |
10457 | ||
10458 | if (ospf->stub_router_startup_time != OSPF_STUB_ROUTER_UNCONFIGURED) | |
10459 | vty_out(vty, " max-metric router-lsa on-startup %u\n", | |
10460 | ospf->stub_router_startup_time); | |
10461 | if (ospf->stub_router_shutdown_time != OSPF_STUB_ROUTER_UNCONFIGURED) | |
10462 | vty_out(vty, " max-metric router-lsa on-shutdown %u\n", | |
10463 | ospf->stub_router_shutdown_time); | |
10464 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, ln, area)) { | |
10465 | if (CHECK_FLAG(area->stub_router_state, | |
10466 | OSPF_AREA_ADMIN_STUB_ROUTED)) { | |
10467 | vty_out(vty, " max-metric router-lsa administrative\n"); | |
10468 | break; | |
10469 | } | |
10470 | } | |
10471 | return; | |
10472 | } | |
10473 | ||
b5a8894d | 10474 | static void show_ip_ospf_route_network(struct vty *vty, struct ospf *ospf, |
0f478e30 CS |
10475 | struct route_table *rt, |
10476 | json_object *json) | |
d62a17ae | 10477 | { |
10478 | struct route_node *rn; | |
10479 | struct ospf_route * or ; | |
10480 | struct listnode *pnode, *pnnode; | |
10481 | struct ospf_path *path; | |
96b663a3 | 10482 | char buf[PREFIX_STRLEN]; |
0f478e30 CS |
10483 | json_object *json_route = NULL, *json_nexthop_array = NULL, |
10484 | *json_nexthop = NULL; | |
d62a17ae | 10485 | |
0f478e30 | 10486 | if (!json) |
996c9314 LB |
10487 | vty_out(vty, |
10488 | "============ OSPF network routing table ============\n"); | |
d62a17ae | 10489 | |
0f478e30 | 10490 | for (rn = route_top(rt); rn; rn = route_next(rn)) { |
96b663a3 MS |
10491 | char buf1[PREFIX2STR_BUFFER]; |
10492 | ||
0f478e30 CS |
10493 | if ((or = rn->info) == NULL) |
10494 | continue; | |
0f478e30 | 10495 | |
0f478e30 CS |
10496 | prefix2str(&rn->p, buf1, sizeof(buf1)); |
10497 | ||
10498 | json_route = json_object_new_object(); | |
10499 | if (json) { | |
996c9314 LB |
10500 | json_object_object_add(json, buf1, json_route); |
10501 | json_object_to_json_string_ext( | |
10502 | json, JSON_C_TO_STRING_NOSLASHESCAPE); | |
0f478e30 CS |
10503 | } |
10504 | ||
10505 | switch (or->path_type) { | |
10506 | case OSPF_PATH_INTER_AREA: | |
10507 | if (or->type == OSPF_DESTINATION_NETWORK) { | |
10508 | if (json) { | |
10509 | json_object_string_add(json_route, | |
996c9314 LB |
10510 | "routeType", |
10511 | "N IA"); | |
10512 | json_object_int_add(json_route, "cost", | |
0f478e30 CS |
10513 | or->cost); |
10514 | json_object_string_add( | |
996c9314 | 10515 | json_route, "area", |
96b663a3 MS |
10516 | inet_ntop(AF_INET, |
10517 | &or->u.std.area_id, | |
10518 | buf1, sizeof(buf1))); | |
0f478e30 | 10519 | } else { |
d62a17ae | 10520 | vty_out(vty, |
96b663a3 | 10521 | "N IA %-18s [%d] area: %pI4\n", |
d62a17ae | 10522 | buf1, or->cost, |
96b663a3 | 10523 | &or->u.std.area_id); |
0f478e30 | 10524 | } |
996c9314 | 10525 | } else if (or->type == OSPF_DESTINATION_DISCARD) { |
0f478e30 CS |
10526 | if (json) { |
10527 | json_object_string_add(json_route, | |
996c9314 LB |
10528 | "routeType", |
10529 | "D IA"); | |
0f478e30 | 10530 | } else { |
d62a17ae | 10531 | vty_out(vty, |
10532 | "D IA %-18s Discard entry\n", | |
10533 | buf1); | |
0f478e30 CS |
10534 | } |
10535 | } | |
10536 | break; | |
10537 | case OSPF_PATH_INTRA_AREA: | |
10538 | if (json) { | |
996c9314 LB |
10539 | json_object_string_add(json_route, "routeType", |
10540 | "N"); | |
0f478e30 | 10541 | json_object_int_add(json_route, "cost", |
996c9314 LB |
10542 | or->cost); |
10543 | json_object_string_add( | |
10544 | json_route, "area", | |
96b663a3 MS |
10545 | inet_ntop(AF_INET, &or->u.std.area_id, |
10546 | buf1, sizeof(buf1))); | |
0f478e30 | 10547 | } else { |
96b663a3 | 10548 | vty_out(vty, "N %-18s [%d] area: %pI4\n", |
d62a17ae | 10549 | buf1, or->cost, |
96b663a3 | 10550 | &or->u.std.area_id); |
0f478e30 CS |
10551 | } |
10552 | break; | |
10553 | default: | |
10554 | break; | |
10555 | } | |
10556 | ||
10557 | if (or->type == OSPF_DESTINATION_NETWORK) { | |
10558 | if (json) { | |
10559 | json_nexthop_array = json_object_new_array(); | |
10560 | json_object_object_add(json_route, "nexthops", | |
996c9314 | 10561 | json_nexthop_array); |
d62a17ae | 10562 | } |
10563 | ||
0f478e30 CS |
10564 | for (ALL_LIST_ELEMENTS(or->paths, pnode, pnnode, |
10565 | path)) { | |
10566 | if (json) { | |
996c9314 LB |
10567 | json_nexthop = json_object_new_object(); |
10568 | json_object_array_add( | |
10569 | json_nexthop_array, | |
10570 | json_nexthop); | |
0f478e30 CS |
10571 | } |
10572 | if (if_lookup_by_index(path->ifindex, | |
10573 | ospf->vrf_id)) { | |
10574 | ||
3a6290bd DA |
10575 | if (path->nexthop.s_addr |
10576 | == INADDR_ANY) { | |
0f478e30 CS |
10577 | if (json) { |
10578 | json_object_string_add( | |
10579 | json_nexthop, | |
996c9314 | 10580 | "ip", " "); |
0f478e30 CS |
10581 | json_object_string_add( |
10582 | json_nexthop, | |
10583 | "directly attached to", | |
d62a17ae | 10584 | ifindex2ifname( |
996c9314 LB |
10585 | path->ifindex, |
10586 | ospf->vrf_id)); | |
0f478e30 | 10587 | } else { |
d62a17ae | 10588 | vty_out(vty, |
996c9314 LB |
10589 | "%24s directly attached to %s\n", |
10590 | "", | |
10591 | ifindex2ifname( | |
10592 | path->ifindex, | |
10593 | ospf->vrf_id)); | |
0f478e30 CS |
10594 | } |
10595 | } else { | |
10596 | if (json) { | |
10597 | json_object_string_add( | |
10598 | json_nexthop, | |
10599 | "ip", | |
96b663a3 MS |
10600 | inet_ntop( |
10601 | AF_INET, | |
10602 | &path->nexthop, | |
10603 | buf, | |
10604 | sizeof(buf))); | |
0f478e30 CS |
10605 | json_object_string_add( |
10606 | json_nexthop, | |
10607 | "via", | |
d62a17ae | 10608 | ifindex2ifname( |
996c9314 LB |
10609 | path->ifindex, |
10610 | ospf->vrf_id)); | |
0f478e30 CS |
10611 | } else { |
10612 | vty_out(vty, | |
96b663a3 | 10613 | "%24s via %pI4, %s\n", |
996c9314 | 10614 | "", |
96b663a3 | 10615 | &path->nexthop, |
996c9314 LB |
10616 | ifindex2ifname( |
10617 | path->ifindex, | |
10618 | ospf->vrf_id)); | |
0f478e30 | 10619 | } |
d62a17ae | 10620 | } |
10621 | } | |
0f478e30 | 10622 | } |
d62a17ae | 10623 | } |
0f478e30 CS |
10624 | if (!json) |
10625 | json_object_free(json_route); | |
10626 | } | |
10627 | if (!json) | |
10628 | vty_out(vty, "\n"); | |
d62a17ae | 10629 | } |
10630 | ||
b5a8894d | 10631 | static void show_ip_ospf_route_router(struct vty *vty, struct ospf *ospf, |
0f478e30 CS |
10632 | struct route_table *rtrs, |
10633 | json_object *json) | |
d62a17ae | 10634 | { |
10635 | struct route_node *rn; | |
10636 | struct ospf_route * or ; | |
10637 | struct listnode *pnode; | |
10638 | struct listnode *node; | |
10639 | struct ospf_path *path; | |
96b663a3 | 10640 | char buf[PREFIX_STRLEN]; |
0f478e30 CS |
10641 | json_object *json_route = NULL, *json_nexthop_array = NULL, |
10642 | *json_nexthop = NULL; | |
d62a17ae | 10643 | |
0f478e30 | 10644 | if (!json) |
996c9314 LB |
10645 | vty_out(vty, |
10646 | "============ OSPF router routing table =============\n"); | |
d62a17ae | 10647 | |
0f478e30 CS |
10648 | for (rn = route_top(rtrs); rn; rn = route_next(rn)) { |
10649 | if (rn->info == NULL) | |
10650 | continue; | |
10651 | int flag = 0; | |
10652 | ||
10653 | json_route = json_object_new_object(); | |
10654 | if (json) { | |
96b663a3 MS |
10655 | json_object_object_add( |
10656 | json, inet_ntop(AF_INET, &rn->p.u.prefix4, | |
10657 | buf, sizeof(buf)), | |
10658 | json_route); | |
996c9314 | 10659 | json_object_string_add(json_route, "routeType", "R "); |
0f478e30 | 10660 | } else { |
96b663a3 MS |
10661 | vty_out(vty, "R %-15pI4 ", |
10662 | &rn->p.u.prefix4); | |
0f478e30 | 10663 | } |
d62a17ae | 10664 | |
996c9314 | 10665 | for (ALL_LIST_ELEMENTS_RO((struct list *)rn->info, node, or)) { |
0f478e30 CS |
10666 | if (flag++) { |
10667 | if (!json) | |
d62a17ae | 10668 | vty_out(vty, "%24s", ""); |
0f478e30 | 10669 | } |
d62a17ae | 10670 | |
0f478e30 CS |
10671 | /* Show path. */ |
10672 | if (json) { | |
10673 | json_object_int_add(json_route, "cost", | |
10674 | or->cost); | |
996c9314 LB |
10675 | json_object_string_add( |
10676 | json_route, "area", | |
96b663a3 MS |
10677 | inet_ntop(AF_INET, &or->u.std.area_id, |
10678 | buf, sizeof(buf))); | |
996c9314 LB |
10679 | if (or->path_type == OSPF_PATH_INTER_AREA) |
10680 | json_object_boolean_true_add(json_route, | |
10681 | "IA"); | |
0f478e30 | 10682 | if (or->u.std.flags & ROUTER_LSA_BORDER) |
996c9314 LB |
10683 | json_object_string_add(json_route, |
10684 | "routerType", | |
10685 | "abr"); | |
10686 | else if (or->u.std.flags & ROUTER_LSA_EXTERNAL) | |
10687 | json_object_string_add(json_route, | |
10688 | "routerType", | |
10689 | "asbr"); | |
0f478e30 | 10690 | } else { |
96b663a3 | 10691 | vty_out(vty, "%s [%d] area: %pI4", |
996c9314 LB |
10692 | (or->path_type == OSPF_PATH_INTER_AREA |
10693 | ? "IA" | |
10694 | : " "), | |
96b663a3 | 10695 | or->cost, &or->u.std.area_id); |
d62a17ae | 10696 | /* Show flags. */ |
10697 | vty_out(vty, "%s%s\n", | |
996c9314 LB |
10698 | (or->u.std.flags & ROUTER_LSA_BORDER |
10699 | ? ", ABR" | |
10700 | : ""), | |
10701 | (or->u.std.flags & ROUTER_LSA_EXTERNAL | |
10702 | ? ", ASBR" | |
10703 | : "")); | |
0f478e30 CS |
10704 | } |
10705 | ||
10706 | if (json) { | |
996c9314 | 10707 | json_nexthop_array = json_object_new_array(); |
0f478e30 | 10708 | json_object_object_add(json_route, "nexthops", |
996c9314 | 10709 | json_nexthop_array); |
0f478e30 CS |
10710 | } |
10711 | ||
996c9314 | 10712 | for (ALL_LIST_ELEMENTS_RO(or->paths, pnode, path)) { |
0f478e30 | 10713 | if (json) { |
996c9314 | 10714 | json_nexthop = json_object_new_object(); |
0f478e30 CS |
10715 | json_object_array_add( |
10716 | json_nexthop_array, | |
10717 | json_nexthop); | |
10718 | } | |
10719 | if (if_lookup_by_index(path->ifindex, | |
10720 | ospf->vrf_id)) { | |
3a6290bd DA |
10721 | if (path->nexthop.s_addr |
10722 | == INADDR_ANY) { | |
0f478e30 CS |
10723 | if (json) { |
10724 | json_object_string_add( | |
10725 | json_nexthop, | |
996c9314 | 10726 | "ip", " "); |
0f478e30 CS |
10727 | json_object_string_add( |
10728 | json_nexthop, | |
10729 | "directly attached to", | |
d62a17ae | 10730 | ifindex2ifname( |
10731 | path->ifindex, | |
b5a8894d | 10732 | ospf->vrf_id)); |
0f478e30 | 10733 | } else { |
d62a17ae | 10734 | vty_out(vty, |
996c9314 LB |
10735 | "%24s directly attached to %s\n", |
10736 | "", | |
10737 | ifindex2ifname( | |
10738 | path->ifindex, | |
10739 | ospf->vrf_id)); | |
0f478e30 CS |
10740 | } |
10741 | } else { | |
10742 | if (json) { | |
10743 | json_object_string_add( | |
10744 | json_nexthop, | |
10745 | "ip", | |
96b663a3 MS |
10746 | inet_ntop( |
10747 | AF_INET, | |
10748 | &path->nexthop, | |
10749 | buf, sizeof(buf))); | |
0f478e30 CS |
10750 | json_object_string_add( |
10751 | json_nexthop, | |
10752 | "via", | |
d62a17ae | 10753 | ifindex2ifname( |
10754 | path->ifindex, | |
b5a8894d | 10755 | ospf->vrf_id)); |
0f478e30 CS |
10756 | } else { |
10757 | vty_out(vty, | |
96b663a3 | 10758 | "%24s via %pI4, %s\n", |
996c9314 | 10759 | "", |
96b663a3 | 10760 | &path->nexthop, |
996c9314 LB |
10761 | ifindex2ifname( |
10762 | path->ifindex, | |
10763 | ospf->vrf_id)); | |
0f478e30 | 10764 | } |
d62a17ae | 10765 | } |
10766 | } | |
10767 | } | |
10768 | } | |
0f478e30 CS |
10769 | if (!json) |
10770 | json_object_free(json_route); | |
10771 | } | |
10772 | if (!json) | |
10773 | vty_out(vty, "\n"); | |
d62a17ae | 10774 | } |
10775 | ||
b5a8894d | 10776 | static void show_ip_ospf_route_external(struct vty *vty, struct ospf *ospf, |
0f478e30 CS |
10777 | struct route_table *rt, |
10778 | json_object *json) | |
d62a17ae | 10779 | { |
10780 | struct route_node *rn; | |
10781 | struct ospf_route *er; | |
10782 | struct listnode *pnode, *pnnode; | |
10783 | struct ospf_path *path; | |
96b663a3 | 10784 | char buf[PREFIX_STRLEN]; |
0f478e30 CS |
10785 | json_object *json_route = NULL, *json_nexthop_array = NULL, |
10786 | *json_nexthop = NULL; | |
d62a17ae | 10787 | |
0f478e30 | 10788 | if (!json) |
996c9314 LB |
10789 | vty_out(vty, |
10790 | "============ OSPF external routing table ===========\n"); | |
0f478e30 CS |
10791 | |
10792 | for (rn = route_top(rt); rn; rn = route_next(rn)) { | |
10793 | if ((er = rn->info) == NULL) | |
10794 | continue; | |
10795 | ||
10796 | char buf1[19]; | |
10797 | ||
96b663a3 | 10798 | snprintfrr(buf1, sizeof(buf1), "%pFX", &rn->p); |
0f478e30 CS |
10799 | json_route = json_object_new_object(); |
10800 | if (json) { | |
996c9314 LB |
10801 | json_object_object_add(json, buf1, json_route); |
10802 | json_object_to_json_string_ext( | |
10803 | json, JSON_C_TO_STRING_NOSLASHESCAPE); | |
0f478e30 | 10804 | } |
d62a17ae | 10805 | |
0f478e30 CS |
10806 | switch (er->path_type) { |
10807 | case OSPF_PATH_TYPE1_EXTERNAL: | |
10808 | if (json) { | |
996c9314 | 10809 | json_object_string_add(json_route, "routeType", |
0f478e30 CS |
10810 | "N E1"); |
10811 | json_object_int_add(json_route, "cost", | |
996c9314 | 10812 | er->cost); |
0f478e30 | 10813 | } else { |
d62a17ae | 10814 | vty_out(vty, |
996c9314 LB |
10815 | "N E1 %-18s [%d] tag: %" ROUTE_TAG_PRI |
10816 | "\n", | |
10817 | buf1, er->cost, er->u.ext.tag); | |
0f478e30 CS |
10818 | } |
10819 | break; | |
10820 | case OSPF_PATH_TYPE2_EXTERNAL: | |
10821 | if (json) { | |
996c9314 | 10822 | json_object_string_add(json_route, "routeType", |
0f478e30 CS |
10823 | "N E2"); |
10824 | json_object_int_add(json_route, "cost", | |
996c9314 | 10825 | er->cost); |
0f478e30 | 10826 | } else { |
d62a17ae | 10827 | vty_out(vty, |
996c9314 LB |
10828 | "N E2 %-18s [%d/%d] tag: %" ROUTE_TAG_PRI |
10829 | "\n", | |
10830 | buf1, er->cost, er->u.ext.type2_cost, | |
d62a17ae | 10831 | er->u.ext.tag); |
d62a17ae | 10832 | } |
0f478e30 CS |
10833 | break; |
10834 | } | |
d62a17ae | 10835 | |
0f478e30 CS |
10836 | if (json) { |
10837 | json_nexthop_array = json_object_new_array(); | |
10838 | json_object_object_add(json_route, "nexthops", | |
996c9314 | 10839 | json_nexthop_array); |
0f478e30 CS |
10840 | } |
10841 | ||
996c9314 | 10842 | for (ALL_LIST_ELEMENTS(er->paths, pnode, pnnode, path)) { |
0f478e30 CS |
10843 | if (json) { |
10844 | json_nexthop = json_object_new_object(); | |
996c9314 LB |
10845 | json_object_array_add(json_nexthop_array, |
10846 | json_nexthop); | |
0f478e30 CS |
10847 | } |
10848 | ||
996c9314 | 10849 | if (if_lookup_by_index(path->ifindex, ospf->vrf_id)) { |
3a6290bd | 10850 | if (path->nexthop.s_addr == INADDR_ANY) { |
0f478e30 CS |
10851 | if (json) { |
10852 | json_object_string_add( | |
996c9314 LB |
10853 | json_nexthop, "ip", |
10854 | " "); | |
0f478e30 CS |
10855 | json_object_string_add( |
10856 | json_nexthop, | |
10857 | "directly attached to", | |
d62a17ae | 10858 | ifindex2ifname( |
996c9314 LB |
10859 | path->ifindex, |
10860 | ospf->vrf_id)); | |
0f478e30 | 10861 | } else { |
d62a17ae | 10862 | vty_out(vty, |
996c9314 LB |
10863 | "%24s directly attached to %s\n", |
10864 | "", | |
10865 | ifindex2ifname( | |
10866 | path->ifindex, | |
10867 | ospf->vrf_id)); | |
0f478e30 CS |
10868 | } |
10869 | } else { | |
10870 | if (json) { | |
10871 | json_object_string_add( | |
996c9314 | 10872 | json_nexthop, "ip", |
96b663a3 MS |
10873 | inet_ntop( |
10874 | AF_INET, | |
10875 | &path->nexthop, | |
10876 | buf, | |
10877 | sizeof(buf))); | |
0f478e30 | 10878 | json_object_string_add( |
996c9314 | 10879 | json_nexthop, "via", |
d62a17ae | 10880 | ifindex2ifname( |
996c9314 LB |
10881 | path->ifindex, |
10882 | ospf->vrf_id)); | |
0f478e30 CS |
10883 | } else { |
10884 | vty_out(vty, | |
96b663a3 | 10885 | "%24s via %pI4, %s\n", |
996c9314 | 10886 | "", |
96b663a3 | 10887 | &path->nexthop, |
996c9314 LB |
10888 | ifindex2ifname( |
10889 | path->ifindex, | |
10890 | ospf->vrf_id)); | |
0f478e30 | 10891 | } |
d62a17ae | 10892 | } |
54bedb55 | 10893 | } |
d62a17ae | 10894 | } |
0f478e30 CS |
10895 | if (!json) |
10896 | json_object_free(json_route); | |
10897 | } | |
10898 | if (!json) | |
10899 | vty_out(vty, "\n"); | |
718e3744 | 10900 | } |
10901 | ||
d62a17ae | 10902 | static int show_ip_ospf_border_routers_common(struct vty *vty, |
d7c0a89a QY |
10903 | struct ospf *ospf, |
10904 | uint8_t use_vrf) | |
718e3744 | 10905 | { |
d62a17ae | 10906 | if (ospf->instance) |
10907 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
718e3744 | 10908 | |
b1c3ae8c | 10909 | ospf_show_vrf_name(ospf, vty, NULL, use_vrf); |
87bd50e8 | 10910 | |
d62a17ae | 10911 | if (ospf->new_table == NULL) { |
10912 | vty_out(vty, "No OSPF routing information exist\n"); | |
10913 | return CMD_SUCCESS; | |
10914 | } | |
718e3744 | 10915 | |
d62a17ae | 10916 | /* Show Network routes. |
10917 | show_ip_ospf_route_network (vty, ospf->new_table); */ | |
718e3744 | 10918 | |
d62a17ae | 10919 | /* Show Router routes. */ |
0f478e30 | 10920 | show_ip_ospf_route_router(vty, ospf, ospf->new_rtrs, NULL); |
718e3744 | 10921 | |
d62a17ae | 10922 | vty_out(vty, "\n"); |
7c8ff89e | 10923 | |
d62a17ae | 10924 | return CMD_SUCCESS; |
718e3744 | 10925 | } |
718e3744 | 10926 | |
7c8ff89e DS |
10927 | DEFUN (show_ip_ospf_border_routers, |
10928 | show_ip_ospf_border_routers_cmd, | |
b5a8894d | 10929 | "show ip ospf [vrf <NAME|all>] border-routers", |
718e3744 | 10930 | SHOW_STR |
10931 | IP_STR | |
10932 | "OSPF information\n" | |
b5a8894d CS |
10933 | VRF_CMD_HELP_STR |
10934 | "All VRFs\n" | |
7c8ff89e | 10935 | "Show all the ABR's and ASBR's\n") |
718e3744 | 10936 | { |
b5a8894d CS |
10937 | struct ospf *ospf = NULL; |
10938 | struct listnode *node = NULL; | |
10939 | char *vrf_name = NULL; | |
2951a7a4 | 10940 | bool all_vrf = false; |
b5a8894d CS |
10941 | int ret = CMD_SUCCESS; |
10942 | int inst = 0; | |
10943 | int idx_vrf = 0; | |
d7c0a89a | 10944 | uint8_t use_vrf = 0; |
68980084 | 10945 | |
43b8d1d8 | 10946 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
7c8ff89e | 10947 | |
b5a8894d | 10948 | if (vrf_name) { |
2951a7a4 | 10949 | bool ospf_output = false; |
874f58d8 | 10950 | |
b1c3ae8c | 10951 | use_vrf = 1; |
94d4c685 | 10952 | |
b5a8894d CS |
10953 | if (all_vrf) { |
10954 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
10955 | if (!ospf->oi_running) | |
10956 | continue; | |
b5a8894d | 10957 | |
2951a7a4 | 10958 | ospf_output = true; |
996c9314 LB |
10959 | ret = show_ip_ospf_border_routers_common( |
10960 | vty, ospf, use_vrf); | |
b5a8894d | 10961 | } |
9f049418 DS |
10962 | |
10963 | if (!ospf_output) | |
94d4c685 | 10964 | vty_out(vty, "%% OSPF instance not found\n"); |
b5a8894d CS |
10965 | } else { |
10966 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
9f049418 | 10967 | if (ospf == NULL || !ospf->oi_running) { |
94d4c685 | 10968 | vty_out(vty, "%% OSPF instance not found\n"); |
b5a8894d | 10969 | return CMD_SUCCESS; |
9f049418 | 10970 | } |
b5a8894d | 10971 | |
b1c3ae8c CS |
10972 | ret = show_ip_ospf_border_routers_common(vty, ospf, |
10973 | use_vrf); | |
b5a8894d CS |
10974 | } |
10975 | } else { | |
10976 | /* Display default ospf (instance 0) info */ | |
10977 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
9f049418 | 10978 | if (ospf == NULL || !ospf->oi_running) { |
94d4c685 | 10979 | vty_out(vty, "%% OSPF instance not found\n"); |
b5a8894d | 10980 | return CMD_SUCCESS; |
9f049418 DS |
10981 | } |
10982 | ||
b1c3ae8c | 10983 | ret = show_ip_ospf_border_routers_common(vty, ospf, use_vrf); |
b5a8894d CS |
10984 | } |
10985 | ||
10986 | return ret; | |
7c8ff89e DS |
10987 | } |
10988 | ||
10989 | DEFUN (show_ip_ospf_instance_border_routers, | |
10990 | show_ip_ospf_instance_border_routers_cmd, | |
6147e2c6 | 10991 | "show ip ospf (1-65535) border-routers", |
7c8ff89e DS |
10992 | SHOW_STR |
10993 | IP_STR | |
10994 | "OSPF information\n" | |
10995 | "Instance ID\n" | |
10996 | "Show all the ABR's and ASBR's\n") | |
10997 | { | |
d62a17ae | 10998 | int idx_number = 3; |
10999 | struct ospf *ospf; | |
d7c0a89a | 11000 | unsigned short instance = 0; |
7c8ff89e | 11001 | |
d62a17ae | 11002 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
409f98ab | 11003 | if (instance != ospf_instance) |
ac28e4ec CS |
11004 | return CMD_NOT_MY_INSTANCE; |
11005 | ||
409f98ab IR |
11006 | ospf = ospf_lookup_instance(instance); |
11007 | if (!ospf || !ospf->oi_running) | |
d62a17ae | 11008 | return CMD_SUCCESS; |
7c8ff89e | 11009 | |
b1c3ae8c | 11010 | return show_ip_ospf_border_routers_common(vty, ospf, 0); |
7c8ff89e DS |
11011 | } |
11012 | ||
b1c3ae8c | 11013 | static int show_ip_ospf_route_common(struct vty *vty, struct ospf *ospf, |
d7c0a89a | 11014 | json_object *json, uint8_t use_vrf) |
7c8ff89e | 11015 | { |
0f478e30 CS |
11016 | json_object *json_vrf = NULL; |
11017 | ||
d62a17ae | 11018 | if (ospf->instance) |
11019 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
718e3744 | 11020 | |
0f478e30 CS |
11021 | |
11022 | if (json) { | |
11023 | if (use_vrf) | |
11024 | json_vrf = json_object_new_object(); | |
11025 | else | |
11026 | json_vrf = json; | |
11027 | } | |
11028 | ||
11029 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); | |
87bd50e8 | 11030 | |
d62a17ae | 11031 | if (ospf->new_table == NULL) { |
11032 | vty_out(vty, "No OSPF routing information exist\n"); | |
11033 | return CMD_SUCCESS; | |
11034 | } | |
718e3744 | 11035 | |
d62a17ae | 11036 | /* Show Network routes. */ |
0f478e30 | 11037 | show_ip_ospf_route_network(vty, ospf, ospf->new_table, json_vrf); |
718e3744 | 11038 | |
d62a17ae | 11039 | /* Show Router routes. */ |
0f478e30 | 11040 | show_ip_ospf_route_router(vty, ospf, ospf->new_rtrs, json_vrf); |
718e3744 | 11041 | |
d62a17ae | 11042 | /* Show AS External routes. */ |
0f478e30 CS |
11043 | show_ip_ospf_route_external(vty, ospf, ospf->old_external_route, |
11044 | json_vrf); | |
718e3744 | 11045 | |
0f478e30 CS |
11046 | if (json) { |
11047 | if (use_vrf) { | |
996c9314 LB |
11048 | // json_object_object_add(json_vrf, "areas", |
11049 | // json_areas); | |
0f478e30 CS |
11050 | if (ospf->vrf_id == VRF_DEFAULT) |
11051 | json_object_object_add(json, "default", | |
11052 | json_vrf); | |
11053 | else | |
11054 | json_object_object_add(json, ospf->name, | |
11055 | json_vrf); | |
11056 | } | |
11057 | } else { | |
11058 | vty_out(vty, "\n"); | |
11059 | } | |
7c8ff89e | 11060 | |
d62a17ae | 11061 | return CMD_SUCCESS; |
718e3744 | 11062 | } |
11063 | ||
7c8ff89e DS |
11064 | DEFUN (show_ip_ospf_route, |
11065 | show_ip_ospf_route_cmd, | |
0f478e30 | 11066 | "show ip ospf [vrf <NAME|all>] route [json]", |
b5a8894d CS |
11067 | SHOW_STR |
11068 | IP_STR | |
11069 | "OSPF information\n" | |
11070 | VRF_CMD_HELP_STR | |
11071 | "All VRFs\n" | |
0f478e30 CS |
11072 | "OSPF routing table\n" |
11073 | JSON_STR) | |
b5a8894d CS |
11074 | { |
11075 | struct ospf *ospf = NULL; | |
11076 | struct listnode *node = NULL; | |
11077 | char *vrf_name = NULL; | |
2951a7a4 | 11078 | bool all_vrf = false; |
b5a8894d CS |
11079 | int ret = CMD_SUCCESS; |
11080 | int inst = 0; | |
11081 | int idx_vrf = 0; | |
d7c0a89a | 11082 | uint8_t use_vrf = 0; |
9f049418 | 11083 | bool uj = use_json(argc, argv); |
0f478e30 CS |
11084 | json_object *json = NULL; |
11085 | ||
11086 | if (uj) | |
11087 | json = json_object_new_object(); | |
7c8ff89e | 11088 | |
43b8d1d8 | 11089 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
7c8ff89e | 11090 | |
b5a8894d CS |
11091 | /* vrf input is provided could be all or specific vrf*/ |
11092 | if (vrf_name) { | |
2951a7a4 | 11093 | bool ospf_output = false; |
874f58d8 | 11094 | |
b1c3ae8c | 11095 | use_vrf = 1; |
94d4c685 | 11096 | |
b5a8894d CS |
11097 | if (all_vrf) { |
11098 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
11099 | if (!ospf->oi_running) | |
11100 | continue; | |
2951a7a4 | 11101 | ospf_output = true; |
0f478e30 | 11102 | ret = show_ip_ospf_route_common(vty, ospf, json, |
b1c3ae8c | 11103 | use_vrf); |
b5a8894d | 11104 | } |
0f478e30 CS |
11105 | |
11106 | if (uj) { | |
1406159f | 11107 | /* Keep Non-pretty format */ |
0f478e30 | 11108 | vty_out(vty, "%s\n", |
1406159f | 11109 | json_object_to_json_string(json)); |
0f478e30 | 11110 | json_object_free(json); |
9f049418 DS |
11111 | } else if (!ospf_output) |
11112 | vty_out(vty, "%% OSPF instance not found\n"); | |
0f478e30 | 11113 | |
b5a8894d CS |
11114 | return ret; |
11115 | } | |
11116 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
0f478e30 | 11117 | if (ospf == NULL || !ospf->oi_running) { |
9f049418 DS |
11118 | if (uj) { |
11119 | vty_out(vty, "%s\n", | |
11120 | json_object_to_json_string_ext( | |
11121 | json, JSON_C_TO_STRING_PRETTY)); | |
0f478e30 | 11122 | json_object_free(json); |
9f049418 | 11123 | } else |
94d4c685 | 11124 | vty_out(vty, "%% OSPF instance not found\n"); |
9f049418 | 11125 | |
b5a8894d | 11126 | return CMD_SUCCESS; |
0f478e30 | 11127 | } |
b5a8894d CS |
11128 | } else { |
11129 | /* Display default ospf (instance 0) info */ | |
11130 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
0f478e30 | 11131 | if (ospf == NULL || !ospf->oi_running) { |
9f049418 DS |
11132 | if (uj) { |
11133 | vty_out(vty, "%s\n", | |
11134 | json_object_to_json_string_ext( | |
11135 | json, JSON_C_TO_STRING_PRETTY)); | |
0f478e30 | 11136 | json_object_free(json); |
9f049418 | 11137 | } else |
94d4c685 | 11138 | vty_out(vty, "%% OSPF instance not found\n"); |
9f049418 | 11139 | |
b5a8894d | 11140 | return CMD_SUCCESS; |
0f478e30 CS |
11141 | } |
11142 | } | |
11143 | ||
11144 | if (ospf) { | |
11145 | ret = show_ip_ospf_route_common(vty, ospf, json, use_vrf); | |
1406159f | 11146 | /* Keep Non-pretty format */ |
0f478e30 | 11147 | if (uj) |
1406159f | 11148 | vty_out(vty, "%s\n", json_object_to_json_string(json)); |
b5a8894d CS |
11149 | } |
11150 | ||
0f478e30 CS |
11151 | if (uj) |
11152 | json_object_free(json); | |
b5a8894d CS |
11153 | |
11154 | return ret; | |
7c8ff89e DS |
11155 | } |
11156 | ||
11157 | DEFUN (show_ip_ospf_instance_route, | |
11158 | show_ip_ospf_instance_route_cmd, | |
6147e2c6 | 11159 | "show ip ospf (1-65535) route", |
7c8ff89e DS |
11160 | SHOW_STR |
11161 | IP_STR | |
11162 | "OSPF information\n" | |
11163 | "Instance ID\n" | |
11164 | "OSPF routing table\n") | |
11165 | { | |
d62a17ae | 11166 | int idx_number = 3; |
11167 | struct ospf *ospf; | |
d7c0a89a | 11168 | unsigned short instance = 0; |
7c8ff89e | 11169 | |
d62a17ae | 11170 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
409f98ab | 11171 | if (instance != ospf_instance) |
ac28e4ec CS |
11172 | return CMD_NOT_MY_INSTANCE; |
11173 | ||
409f98ab IR |
11174 | ospf = ospf_lookup_instance(instance); |
11175 | if (!ospf || !ospf->oi_running) | |
d62a17ae | 11176 | return CMD_SUCCESS; |
7c8ff89e | 11177 | |
0f478e30 | 11178 | return show_ip_ospf_route_common(vty, ospf, NULL, 0); |
7c8ff89e | 11179 | } |
6b0655a2 | 11180 | |
b5a8894d CS |
11181 | |
11182 | DEFUN (show_ip_ospf_vrfs, | |
11183 | show_ip_ospf_vrfs_cmd, | |
11184 | "show ip ospf vrfs [json]", | |
11185 | SHOW_STR | |
11186 | IP_STR | |
11187 | "OSPF information\n" | |
11188 | "Show OSPF VRFs \n" | |
11189 | JSON_STR) | |
11190 | { | |
9f049418 | 11191 | bool uj = use_json(argc, argv); |
b5a8894d CS |
11192 | json_object *json = NULL; |
11193 | json_object *json_vrfs = NULL; | |
11194 | struct ospf *ospf = NULL; | |
11195 | struct listnode *node = NULL; | |
11196 | int count = 0; | |
96b663a3 | 11197 | char buf[PREFIX_STRLEN]; |
2b64873d | 11198 | static const char header[] = "Name Id RouterId "; |
b5a8894d CS |
11199 | |
11200 | if (uj) { | |
11201 | json = json_object_new_object(); | |
11202 | json_vrfs = json_object_new_object(); | |
11203 | } | |
11204 | ||
11205 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
11206 | json_object *json_vrf = NULL; | |
11207 | const char *name = NULL; | |
fe3da9e7 | 11208 | int64_t vrf_id_ui = 0; |
b5a8894d CS |
11209 | |
11210 | count++; | |
11211 | ||
11212 | if (!uj && count == 1) | |
11213 | vty_out(vty, "%s\n", header); | |
11214 | if (uj) | |
11215 | json_vrf = json_object_new_object(); | |
11216 | ||
946de1b9 | 11217 | if (ospf->vrf_id == VRF_DEFAULT) |
b5a8894d CS |
11218 | name = VRF_DEFAULT_NAME; |
11219 | else | |
11220 | name = ospf->name; | |
11221 | ||
996c9314 LB |
11222 | vrf_id_ui = (ospf->vrf_id == VRF_UNKNOWN) |
11223 | ? -1 | |
11224 | : (int64_t)ospf->vrf_id; | |
b5a8894d CS |
11225 | |
11226 | if (uj) { | |
11227 | json_object_int_add(json_vrf, "vrfId", vrf_id_ui); | |
96b663a3 MS |
11228 | json_object_string_add( |
11229 | json_vrf, "routerId", | |
11230 | inet_ntop(AF_INET, &ospf->router_id, | |
11231 | buf, sizeof(buf))); | |
b5a8894d CS |
11232 | |
11233 | json_object_object_add(json_vrfs, name, json_vrf); | |
11234 | ||
11235 | } else { | |
96b663a3 MS |
11236 | vty_out(vty, "%-25s %-5d %-16pI4 \n", name, |
11237 | ospf->vrf_id, &ospf->router_id); | |
b5a8894d CS |
11238 | } |
11239 | } | |
11240 | ||
11241 | if (uj) { | |
11242 | json_object_object_add(json, "vrfs", json_vrfs); | |
11243 | json_object_int_add(json, "totalVrfs", count); | |
11244 | ||
996c9314 LB |
11245 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
11246 | json, JSON_C_TO_STRING_PRETTY)); | |
b5a8894d CS |
11247 | json_object_free(json); |
11248 | } else { | |
11249 | if (count) | |
34d6798f | 11250 | vty_out(vty, "\nTotal number of OSPF VRFs: %d\n", |
b5a8894d CS |
11251 | count); |
11252 | } | |
11253 | ||
11254 | return CMD_SUCCESS; | |
11255 | } | |
f91ce319 MR |
11256 | DEFPY (clear_ip_ospf_neighbor, |
11257 | clear_ip_ospf_neighbor_cmd, | |
11258 | "clear ip ospf [(1-65535)]$instance neighbor [A.B.C.D$nbr_id]", | |
11259 | CLEAR_STR | |
11260 | IP_STR | |
11261 | "OSPF information\n" | |
11262 | "Instance ID\n" | |
11263 | "Reset OSPF Neighbor\n" | |
11264 | "Neighbor ID\n") | |
11265 | { | |
11266 | struct listnode *node; | |
11267 | struct ospf *ospf = NULL; | |
11268 | ||
11269 | /* If user does not specify the arguments, | |
11270 | * instance = 0 and nbr_id = 0.0.0.0 | |
11271 | */ | |
11272 | if (instance != 0) { | |
11273 | /* This means clear only the particular ospf process */ | |
409f98ab | 11274 | if (instance != ospf_instance) |
f91ce319 MR |
11275 | return CMD_NOT_MY_INSTANCE; |
11276 | } | |
11277 | ||
11278 | /* Clear all the ospf processes */ | |
11279 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
11280 | if (!ospf->oi_running) | |
11281 | continue; | |
11282 | ||
11283 | ospf_neighbor_reset(ospf, nbr_id, nbr_id_str); | |
11284 | } | |
11285 | ||
11286 | return CMD_SUCCESS; | |
11287 | } | |
11288 | ||
11289 | DEFPY (clear_ip_ospf_process, | |
11290 | clear_ip_ospf_process_cmd, | |
11291 | "clear ip ospf [(1-65535)]$instance process", | |
11292 | CLEAR_STR | |
11293 | IP_STR | |
11294 | "OSPF information\n" | |
11295 | "Instance ID\n" | |
11296 | "Reset OSPF Process\n") | |
11297 | { | |
11298 | struct listnode *node; | |
11299 | struct ospf *ospf = NULL; | |
11300 | ||
11301 | /* Check if instance is not passed as an argument */ | |
11302 | if (instance != 0) { | |
11303 | /* This means clear only the particular ospf process */ | |
409f98ab | 11304 | if (instance != ospf_instance) |
f91ce319 MR |
11305 | return CMD_NOT_MY_INSTANCE; |
11306 | } | |
11307 | ||
11308 | /* Clear all the ospf processes */ | |
11309 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
11310 | if (!ospf->oi_running) | |
11311 | continue; | |
11312 | ||
11313 | ospf_process_reset(ospf); | |
11314 | } | |
11315 | ||
11316 | return CMD_SUCCESS; | |
11317 | } | |
b5a8894d | 11318 | |
2b64873d DL |
11319 | static const char *const ospf_abr_type_str[] = { |
11320 | "unknown", "standard", "ibm", "cisco", "shortcut" | |
11321 | }; | |
718e3744 | 11322 | |
2b64873d DL |
11323 | static const char *const ospf_shortcut_mode_str[] = { |
11324 | "default", "enable", "disable" | |
11325 | }; | |
1ac88792 | 11326 | static int ospf_vty_external_rt_walkcb(struct hash_bucket *bucket, |
53e44d05 | 11327 | void *arg) |
11328 | { | |
1ac88792 | 11329 | struct external_info *ei = bucket->data; |
53e44d05 | 11330 | struct vty *vty = (struct vty *)arg; |
11331 | static unsigned int count; | |
11332 | ||
11333 | vty_out(vty, "%-4pI4/%d, ", &ei->p.prefix, ei->p.prefixlen); | |
11334 | count++; | |
11335 | ||
11336 | if (count % 5 == 0) | |
11337 | vty_out(vty, "\n"); | |
11338 | ||
11339 | if (OSPF_EXTERNAL_RT_COUNT(ei->aggr_route) == count) | |
11340 | count = 0; | |
11341 | ||
11342 | return HASHWALK_CONTINUE; | |
11343 | } | |
11344 | ||
1ac88792 | 11345 | static int ospf_json_external_rt_walkcb(struct hash_bucket *bucket, |
53e44d05 | 11346 | void *arg) |
11347 | { | |
1ac88792 | 11348 | struct external_info *ei = bucket->data; |
53e44d05 | 11349 | struct json_object *json = (struct json_object *)arg; |
11350 | char buf[PREFIX2STR_BUFFER]; | |
11351 | char exnalbuf[20]; | |
11352 | static unsigned int count; | |
11353 | ||
11354 | prefix2str(&ei->p, buf, sizeof(buf)); | |
11355 | ||
11356 | snprintf(exnalbuf, 20, "Exnl Addr-%d", count); | |
11357 | ||
11358 | json_object_string_add(json, exnalbuf, buf); | |
11359 | ||
11360 | count++; | |
11361 | ||
11362 | if (OSPF_EXTERNAL_RT_COUNT(ei->aggr_route) == count) | |
11363 | count = 0; | |
11364 | ||
11365 | return HASHWALK_CONTINUE; | |
11366 | } | |
11367 | ||
11368 | static int ospf_show_summary_address(struct vty *vty, struct ospf *ospf, | |
11369 | uint8_t use_vrf, json_object *json, | |
11370 | bool uj, bool detail) | |
11371 | { | |
11372 | struct route_node *rn; | |
11373 | json_object *json_vrf = NULL; | |
11374 | int mtype = 0; | |
11375 | int mval = 0; | |
11376 | static char header[] = | |
11377 | "Summary-address Metric-type Metric Tag External_Rt_count\n"; | |
11378 | ||
11379 | mtype = metric_type(ospf, 0, ospf->instance); | |
11380 | mval = metric_value(ospf, 0, ospf->instance); | |
11381 | ||
11382 | if (!uj) | |
11383 | vty_out(vty, "%s\n", header); | |
11384 | ||
11385 | if (uj) { | |
11386 | if (use_vrf) | |
11387 | json_vrf = json_object_new_object(); | |
11388 | else | |
11389 | json_vrf = json; | |
11390 | } | |
11391 | ||
11392 | if (ospf->instance) { | |
11393 | if (uj) | |
11394 | json_object_int_add(json, "ospfInstance", | |
11395 | ospf->instance); | |
11396 | else | |
11397 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
11398 | } | |
11399 | ||
11400 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); | |
11401 | ||
11402 | if (!uj) | |
11403 | vty_out(vty, "aggregation delay interval :%d(in seconds)\n\n", | |
11404 | ospf->aggr_delay_interval); | |
11405 | else | |
11406 | json_object_int_add(json_vrf, "aggregation delay interval", | |
11407 | ospf->aggr_delay_interval); | |
11408 | ||
11409 | for (rn = route_top(ospf->rt_aggr_tbl); rn; rn = route_next(rn)) | |
11410 | if (rn->info) { | |
11411 | struct ospf_external_aggr_rt *aggr = rn->info; | |
11412 | json_object *json_aggr = NULL; | |
11413 | char buf[PREFIX2STR_BUFFER]; | |
11414 | ||
11415 | prefix2str(&aggr->p, buf, sizeof(buf)); | |
11416 | ||
11417 | if (uj) { | |
11418 | ||
11419 | json_aggr = json_object_new_object(); | |
11420 | ||
11421 | json_object_object_add(json_vrf, buf, | |
11422 | json_aggr); | |
11423 | ||
11424 | json_object_string_add(json_aggr, | |
11425 | "Summary address", buf); | |
11426 | ||
11427 | json_object_string_add( | |
11428 | json_aggr, "Metric-type", | |
11429 | (mtype == EXTERNAL_METRIC_TYPE_1) | |
11430 | ? "E1" | |
11431 | : "E2"); | |
11432 | ||
11433 | json_object_int_add(json_aggr, "Metric", mval); | |
11434 | ||
11435 | json_object_int_add(json_aggr, "Tag", | |
11436 | aggr->tag); | |
11437 | ||
11438 | json_object_int_add( | |
11439 | json_aggr, "External route count", | |
11440 | OSPF_EXTERNAL_RT_COUNT(aggr)); | |
11441 | ||
11442 | if (OSPF_EXTERNAL_RT_COUNT(aggr) && detail) { | |
11443 | hash_walk( | |
11444 | aggr->match_extnl_hash, | |
11445 | ospf_json_external_rt_walkcb, | |
11446 | json_aggr); | |
11447 | } | |
11448 | ||
11449 | } else { | |
11450 | vty_out(vty, "%-20s", buf); | |
11451 | ||
11452 | (mtype == EXTERNAL_METRIC_TYPE_1) | |
11453 | ? vty_out(vty, "%-16s", "E1") | |
11454 | : vty_out(vty, "%-16s", "E2"); | |
11455 | vty_out(vty, "%-11d", mval); | |
11456 | ||
11457 | vty_out(vty, "%-12u", aggr->tag); | |
11458 | ||
11459 | vty_out(vty, "%-5ld\n", | |
11460 | OSPF_EXTERNAL_RT_COUNT(aggr)); | |
11461 | ||
11462 | if (OSPF_EXTERNAL_RT_COUNT(aggr) && detail) { | |
11463 | vty_out(vty, | |
11464 | "Matched External routes:\n"); | |
11465 | hash_walk( | |
11466 | aggr->match_extnl_hash, | |
11467 | ospf_vty_external_rt_walkcb, | |
11468 | vty); | |
11469 | vty_out(vty, "\n"); | |
11470 | } | |
11471 | ||
11472 | vty_out(vty, "\n"); | |
11473 | } | |
11474 | } | |
11475 | ||
11476 | if (uj) { | |
11477 | if (use_vrf) { | |
11478 | if (ospf->vrf_id == VRF_DEFAULT) | |
11479 | json_object_object_add(json, "default", | |
11480 | json_vrf); | |
11481 | else | |
11482 | json_object_object_add(json, ospf->name, | |
11483 | json_vrf); | |
11484 | } | |
11485 | } else | |
11486 | vty_out(vty, "\n"); | |
11487 | ||
11488 | return CMD_SUCCESS; | |
11489 | } | |
11490 | ||
11491 | DEFUN (show_ip_ospf_external_aggregator, | |
11492 | show_ip_ospf_external_aggregator_cmd, | |
11493 | "show ip ospf [vrf <NAME|all>] summary-address [detail] [json]", | |
11494 | SHOW_STR IP_STR | |
11495 | "OSPF information\n" | |
11496 | VRF_CMD_HELP_STR | |
11497 | "All VRFs\n" | |
11498 | "Show external summary addresses\n" | |
11499 | "Detailed informtion\n" | |
11500 | JSON_STR) | |
11501 | { | |
11502 | char *vrf_name = NULL; | |
11503 | bool all_vrf = false; | |
11504 | int ret = CMD_SUCCESS; | |
11505 | int idx_vrf = 0; | |
11506 | int idx = 0; | |
11507 | uint8_t use_vrf = 0; | |
11508 | bool uj = use_json(argc, argv); | |
11509 | struct ospf *ospf = NULL; | |
11510 | json_object *json = NULL; | |
11511 | struct listnode *node = NULL; | |
11512 | int inst = 0; | |
11513 | bool detail = false; | |
11514 | ||
11515 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); | |
11516 | ||
11517 | if (argv_find(argv, argc, "detail", &idx)) | |
11518 | detail = true; | |
11519 | ||
11520 | if (uj) | |
11521 | json = json_object_new_object(); | |
11522 | ||
11523 | /* vrf input is provided */ | |
11524 | if (vrf_name) { | |
11525 | use_vrf = 1; | |
11526 | if (all_vrf) { | |
11527 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
11528 | if (!ospf->oi_running) | |
11529 | continue; | |
11530 | ret = ospf_show_summary_address( | |
11531 | vty, ospf, use_vrf, json, uj, detail); | |
11532 | } | |
11533 | ||
11534 | if (uj) { | |
11535 | vty_out(vty, "%s\n", | |
11536 | json_object_to_json_string_ext( | |
11537 | json, JSON_C_TO_STRING_PRETTY)); | |
11538 | json_object_free(json); | |
11539 | } | |
11540 | ||
11541 | return ret; | |
11542 | } | |
11543 | ||
11544 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
11545 | ||
11546 | if (ospf == NULL || !ospf->oi_running) { | |
11547 | if (uj) { | |
11548 | vty_out(vty, "%s\n", | |
11549 | json_object_to_json_string_ext( | |
11550 | json, JSON_C_TO_STRING_PRETTY)); | |
11551 | json_object_free(json); | |
11552 | } else | |
11553 | vty_out(vty, "%% OSPF instance not found\n"); | |
11554 | ||
11555 | return CMD_SUCCESS; | |
11556 | } | |
fddbafcc | 11557 | ospf_show_summary_address(vty, ospf, use_vrf, json, uj, detail); |
53e44d05 | 11558 | |
11559 | } else { | |
11560 | /* Default Vrf */ | |
11561 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
11562 | if (ospf == NULL || !ospf->oi_running) { | |
11563 | if (uj) { | |
11564 | vty_out(vty, "%s\n", | |
11565 | json_object_to_json_string_ext( | |
11566 | json, JSON_C_TO_STRING_PRETTY)); | |
11567 | json_object_free(json); | |
11568 | } else | |
11569 | vty_out(vty, "%% OSPF instance not found\n"); | |
11570 | ||
11571 | return CMD_SUCCESS; | |
11572 | } | |
11573 | ||
11574 | ospf_show_summary_address(vty, ospf, use_vrf, json, uj, detail); | |
11575 | } | |
11576 | ||
11577 | if (uj) { | |
11578 | vty_out(vty, "%s\n", json_object_to_json_string_ext( | |
11579 | json, JSON_C_TO_STRING_PRETTY)); | |
11580 | json_object_free(json); | |
11581 | } | |
11582 | return CMD_SUCCESS; | |
11583 | } | |
718e3744 | 11584 | |
2b64873d DL |
11585 | static const char *const ospf_int_type_str[] = { |
11586 | "unknown", /* should never be used. */ | |
11587 | "point-to-point", | |
11588 | "broadcast", | |
11589 | "non-broadcast", | |
11590 | "point-to-multipoint", | |
11591 | "virtual-link", /* should never be used. */ | |
11592 | "loopback" | |
11593 | }; | |
718e3744 | 11594 | |
83cc5a1f DE |
11595 | static const char *interface_config_auth_str(struct ospf_if_params *params) |
11596 | { | |
11597 | if (!OSPF_IF_PARAM_CONFIGURED(params, auth_type) | |
11598 | || params->auth_type == OSPF_AUTH_NOTSET) | |
11599 | return NULL; | |
11600 | ||
11601 | /* Translation tables are not that much help | |
11602 | * here due to syntax | |
11603 | * of the simple option */ | |
11604 | switch (params->auth_type) { | |
11605 | ||
11606 | case OSPF_AUTH_NULL: | |
11607 | return " null"; | |
11608 | ||
11609 | case OSPF_AUTH_SIMPLE: | |
11610 | return ""; | |
11611 | ||
11612 | case OSPF_AUTH_CRYPTOGRAPHIC: | |
11613 | return " message-digest"; | |
11614 | } | |
11615 | ||
11616 | return ""; | |
11617 | } | |
11618 | ||
545f0503 | 11619 | static int config_write_interface_one(struct vty *vty, struct vrf *vrf) |
d62a17ae | 11620 | { |
f4e14fdb | 11621 | struct listnode *node; |
d62a17ae | 11622 | struct interface *ifp; |
11623 | struct crypt_key *ck; | |
d62a17ae | 11624 | struct route_node *rn = NULL; |
11625 | struct ospf_if_params *params; | |
83cc5a1f | 11626 | const char *auth_str; |
43b8d1d8 | 11627 | int write = 0; |
d62a17ae | 11628 | |
545f0503 | 11629 | FOR_ALL_INTERFACES (vrf, ifp) { |
d62a17ae | 11630 | |
545f0503 CS |
11631 | if (memcmp(ifp->name, "VLINK", 5) == 0) |
11632 | continue; | |
35955c14 | 11633 | |
545f0503 | 11634 | vty_frame(vty, "!\n"); |
a36898e7 | 11635 | if (ifp->vrf_id == VRF_DEFAULT) |
545f0503 CS |
11636 | vty_frame(vty, "interface %s\n", ifp->name); |
11637 | else | |
996c9314 LB |
11638 | vty_frame(vty, "interface %s vrf %s\n", ifp->name, |
11639 | vrf->name); | |
545f0503 CS |
11640 | if (ifp->desc) |
11641 | vty_out(vty, " description %s\n", ifp->desc); | |
d62a17ae | 11642 | |
545f0503 | 11643 | write++; |
43b8d1d8 | 11644 | |
545f0503 | 11645 | params = IF_DEF_PARAMS(ifp); |
43b8d1d8 | 11646 | |
545f0503 CS |
11647 | do { |
11648 | /* Interface Network print. */ | |
11649 | if (OSPF_IF_PARAM_CONFIGURED(params, type) | |
11650 | && params->type != OSPF_IFTYPE_LOOPBACK) { | |
996c9314 | 11651 | if (params->type != ospf_default_iftype(ifp)) { |
545f0503 CS |
11652 | vty_out(vty, " ip ospf network %s", |
11653 | ospf_int_type_str | |
996c9314 | 11654 | [params->type]); |
bc97889b AL |
11655 | if (params->type |
11656 | == OSPF_IFTYPE_POINTOPOINT | |
11657 | && params->ptp_dmvpn) | |
11658 | vty_out(vty, " dmvpn"); | |
e425c019 | 11659 | if (params != IF_DEF_PARAMS(ifp) && rn) |
96b663a3 MS |
11660 | vty_out(vty, " %pI4", |
11661 | &rn->p.u.prefix4); | |
545f0503 | 11662 | vty_out(vty, "\n"); |
d62a17ae | 11663 | } |
545f0503 | 11664 | } |
d62a17ae | 11665 | |
545f0503 | 11666 | /* OSPF interface authentication print */ |
83cc5a1f DE |
11667 | auth_str = interface_config_auth_str(params); |
11668 | if (auth_str) { | |
545f0503 CS |
11669 | vty_out(vty, " ip ospf authentication%s", |
11670 | auth_str); | |
e425c019 | 11671 | if (params != IF_DEF_PARAMS(ifp) && rn) |
96b663a3 MS |
11672 | vty_out(vty, " %pI4", |
11673 | &rn->p.u.prefix4); | |
545f0503 CS |
11674 | vty_out(vty, "\n"); |
11675 | } | |
d62a17ae | 11676 | |
545f0503 CS |
11677 | /* Simple Authentication Password print. */ |
11678 | if (OSPF_IF_PARAM_CONFIGURED(params, auth_simple) | |
996c9314 | 11679 | && params->auth_simple[0] != '\0') { |
545f0503 CS |
11680 | vty_out(vty, " ip ospf authentication-key %s", |
11681 | params->auth_simple); | |
e425c019 | 11682 | if (params != IF_DEF_PARAMS(ifp) && rn) |
96b663a3 MS |
11683 | vty_out(vty, " %pI4", |
11684 | &rn->p.u.prefix4); | |
545f0503 CS |
11685 | vty_out(vty, "\n"); |
11686 | } | |
c7fd72d2 | 11687 | |
545f0503 CS |
11688 | /* Cryptographic Authentication Key print. */ |
11689 | if (params && params->auth_crypt) { | |
996c9314 LB |
11690 | for (ALL_LIST_ELEMENTS_RO(params->auth_crypt, |
11691 | node, ck)) { | |
545f0503 CS |
11692 | vty_out(vty, |
11693 | " ip ospf message-digest-key %d md5 %s", | |
996c9314 | 11694 | ck->key_id, ck->auth_key); |
e425c019 | 11695 | if (params != IF_DEF_PARAMS(ifp) && rn) |
96b663a3 MS |
11696 | vty_out(vty, " %pI4", |
11697 | &rn->p.u.prefix4); | |
c7fd72d2 CS |
11698 | vty_out(vty, "\n"); |
11699 | } | |
545f0503 | 11700 | } |
d62a17ae | 11701 | |
545f0503 | 11702 | /* Interface Output Cost print. */ |
996c9314 | 11703 | if (OSPF_IF_PARAM_CONFIGURED(params, output_cost_cmd)) { |
545f0503 CS |
11704 | vty_out(vty, " ip ospf cost %u", |
11705 | params->output_cost_cmd); | |
e425c019 | 11706 | if (params != IF_DEF_PARAMS(ifp) && rn) |
96b663a3 MS |
11707 | vty_out(vty, " %pI4", |
11708 | &rn->p.u.prefix4); | |
545f0503 CS |
11709 | vty_out(vty, "\n"); |
11710 | } | |
d62a17ae | 11711 | |
545f0503 CS |
11712 | /* Hello Interval print. */ |
11713 | if (OSPF_IF_PARAM_CONFIGURED(params, v_hello) | |
996c9314 | 11714 | && params->v_hello != OSPF_HELLO_INTERVAL_DEFAULT) { |
545f0503 CS |
11715 | vty_out(vty, " ip ospf hello-interval %u", |
11716 | params->v_hello); | |
e425c019 | 11717 | if (params != IF_DEF_PARAMS(ifp) && rn) |
96b663a3 MS |
11718 | vty_out(vty, " %pI4", |
11719 | &rn->p.u.prefix4); | |
545f0503 CS |
11720 | vty_out(vty, "\n"); |
11721 | } | |
d62a17ae | 11722 | |
d62a17ae | 11723 | |
545f0503 CS |
11724 | /* Router Dead Interval print. */ |
11725 | if (OSPF_IF_PARAM_CONFIGURED(params, v_wait) | |
6dd632c6 | 11726 | && params->is_v_wait_set |
996c9314 LB |
11727 | && params->v_wait |
11728 | != OSPF_ROUTER_DEAD_INTERVAL_DEFAULT) { | |
545f0503 | 11729 | vty_out(vty, " ip ospf dead-interval "); |
d62a17ae | 11730 | |
545f0503 CS |
11731 | /* fast hello ? */ |
11732 | if (OSPF_IF_PARAM_CONFIGURED(params, | |
996c9314 | 11733 | fast_hello)) |
545f0503 CS |
11734 | vty_out(vty, |
11735 | "minimal hello-multiplier %d", | |
11736 | params->fast_hello); | |
11737 | else | |
996c9314 | 11738 | vty_out(vty, "%u", params->v_wait); |
d62a17ae | 11739 | |
e425c019 | 11740 | if (params != IF_DEF_PARAMS(ifp) && rn) |
96b663a3 MS |
11741 | vty_out(vty, " %pI4", |
11742 | &rn->p.u.prefix4); | |
545f0503 CS |
11743 | vty_out(vty, "\n"); |
11744 | } | |
d62a17ae | 11745 | |
545f0503 CS |
11746 | /* Router Priority print. */ |
11747 | if (OSPF_IF_PARAM_CONFIGURED(params, priority) | |
996c9314 LB |
11748 | && params->priority |
11749 | != OSPF_ROUTER_PRIORITY_DEFAULT) { | |
545f0503 CS |
11750 | vty_out(vty, " ip ospf priority %u", |
11751 | params->priority); | |
e425c019 | 11752 | if (params != IF_DEF_PARAMS(ifp) && rn) |
96b663a3 MS |
11753 | vty_out(vty, " %pI4", |
11754 | &rn->p.u.prefix4); | |
545f0503 CS |
11755 | vty_out(vty, "\n"); |
11756 | } | |
d62a17ae | 11757 | |
545f0503 CS |
11758 | /* Retransmit Interval print. */ |
11759 | if (OSPF_IF_PARAM_CONFIGURED(params, | |
996c9314 LB |
11760 | retransmit_interval) |
11761 | && params->retransmit_interval | |
11762 | != OSPF_RETRANSMIT_INTERVAL_DEFAULT) { | |
545f0503 CS |
11763 | vty_out(vty, " ip ospf retransmit-interval %u", |
11764 | params->retransmit_interval); | |
e425c019 | 11765 | if (params != IF_DEF_PARAMS(ifp) && rn) |
96b663a3 MS |
11766 | vty_out(vty, " %pI4", |
11767 | &rn->p.u.prefix4); | |
545f0503 CS |
11768 | vty_out(vty, "\n"); |
11769 | } | |
d62a17ae | 11770 | |
545f0503 | 11771 | /* Transmit Delay print. */ |
996c9314 LB |
11772 | if (OSPF_IF_PARAM_CONFIGURED(params, transmit_delay) |
11773 | && params->transmit_delay | |
11774 | != OSPF_TRANSMIT_DELAY_DEFAULT) { | |
545f0503 CS |
11775 | vty_out(vty, " ip ospf transmit-delay %u", |
11776 | params->transmit_delay); | |
e425c019 | 11777 | if (params != IF_DEF_PARAMS(ifp) && rn) |
96b663a3 MS |
11778 | vty_out(vty, " %pI4", |
11779 | &rn->p.u.prefix4); | |
545f0503 CS |
11780 | vty_out(vty, "\n"); |
11781 | } | |
d62a17ae | 11782 | |
545f0503 CS |
11783 | /* Area print. */ |
11784 | if (OSPF_IF_PARAM_CONFIGURED(params, if_area)) { | |
409f98ab | 11785 | if (ospf_instance) |
545f0503 | 11786 | vty_out(vty, " ip ospf %d", |
409f98ab | 11787 | ospf_instance); |
545f0503 CS |
11788 | else |
11789 | vty_out(vty, " ip ospf"); | |
d62a17ae | 11790 | |
1f9d4e3d | 11791 | char buf[INET_ADDRSTRLEN]; |
d62a17ae | 11792 | |
996c9314 LB |
11793 | area_id2str(buf, sizeof(buf), ¶ms->if_area, |
11794 | params->if_area_id_fmt); | |
545f0503 | 11795 | vty_out(vty, " area %s", buf); |
e425c019 | 11796 | if (params != IF_DEF_PARAMS(ifp) && rn) |
96b663a3 MS |
11797 | vty_out(vty, " %pI4", |
11798 | &rn->p.u.prefix4); | |
545f0503 CS |
11799 | vty_out(vty, "\n"); |
11800 | } | |
d62a17ae | 11801 | |
545f0503 | 11802 | /* bfd print. */ |
659f4e40 | 11803 | if (params && params->bfd_config) |
545f0503 | 11804 | ospf_bfd_write_config(vty, params); |
d62a17ae | 11805 | |
545f0503 CS |
11806 | /* MTU ignore print. */ |
11807 | if (OSPF_IF_PARAM_CONFIGURED(params, mtu_ignore) | |
996c9314 | 11808 | && params->mtu_ignore != OSPF_MTU_IGNORE_DEFAULT) { |
545f0503 CS |
11809 | if (params->mtu_ignore == 0) |
11810 | vty_out(vty, " no ip ospf mtu-ignore"); | |
11811 | else | |
11812 | vty_out(vty, " ip ospf mtu-ignore"); | |
e425c019 | 11813 | if (params != IF_DEF_PARAMS(ifp) && rn) |
96b663a3 MS |
11814 | vty_out(vty, " %pI4", |
11815 | &rn->p.u.prefix4); | |
545f0503 CS |
11816 | vty_out(vty, "\n"); |
11817 | } | |
a8b828f3 | 11818 | |
132a782e | 11819 | /* LDP-Sync print */ |
11820 | if (params && params->ldp_sync_info) | |
11821 | ospf_ldp_sync_if_write_config(vty, params); | |
d62a17ae | 11822 | |
545f0503 CS |
11823 | while (1) { |
11824 | if (rn == NULL) | |
996c9314 | 11825 | rn = route_top(IF_OIFS_PARAMS(ifp)); |
545f0503 CS |
11826 | else |
11827 | rn = route_next(rn); | |
43b8d1d8 | 11828 | |
545f0503 CS |
11829 | if (rn == NULL) |
11830 | break; | |
11831 | params = rn->info; | |
11832 | if (params != NULL) | |
11833 | break; | |
11834 | } | |
11835 | } while (rn); | |
43b8d1d8 | 11836 | |
545f0503 CS |
11837 | ospf_opaque_config_write_if(vty, ifp); |
11838 | ||
11839 | vty_endframe(vty, NULL); | |
b5a8894d | 11840 | } |
545f0503 | 11841 | |
d62a17ae | 11842 | return write; |
718e3744 | 11843 | } |
11844 | ||
43b8d1d8 CS |
11845 | /* Configuration write function for ospfd. */ |
11846 | static int config_write_interface(struct vty *vty) | |
11847 | { | |
11848 | int write = 0; | |
545f0503 | 11849 | struct vrf *vrf = NULL; |
43b8d1d8 | 11850 | |
545f0503 CS |
11851 | /* Display all VRF aware OSPF interface configuration */ |
11852 | RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) { | |
11853 | write += config_write_interface_one(vty, vrf); | |
11854 | } | |
43b8d1d8 CS |
11855 | |
11856 | return write; | |
11857 | } | |
11858 | ||
d62a17ae | 11859 | static int config_write_network_area(struct vty *vty, struct ospf *ospf) |
718e3744 | 11860 | { |
d62a17ae | 11861 | struct route_node *rn; |
fc746f1c | 11862 | char buf[INET_ADDRSTRLEN]; |
718e3744 | 11863 | |
d62a17ae | 11864 | /* `network area' print. */ |
11865 | for (rn = route_top(ospf->networks); rn; rn = route_next(rn)) | |
11866 | if (rn->info) { | |
11867 | struct ospf_network *n = rn->info; | |
718e3744 | 11868 | |
d62a17ae | 11869 | /* Create Area ID string by specified Area ID format. */ |
11870 | if (n->area_id_fmt == OSPF_AREA_ID_FMT_DOTTEDQUAD) | |
fc746f1c | 11871 | inet_ntop(AF_INET, &n->area_id, buf, |
1f9d4e3d | 11872 | sizeof(buf)); |
d62a17ae | 11873 | else |
fc746f1c QY |
11874 | snprintf(buf, sizeof(buf), "%lu", |
11875 | (unsigned long int)ntohl( | |
11876 | n->area_id.s_addr)); | |
718e3744 | 11877 | |
d62a17ae | 11878 | /* Network print. */ |
96b663a3 | 11879 | vty_out(vty, " network %pFX area %s\n", &rn->p, buf); |
d62a17ae | 11880 | } |
718e3744 | 11881 | |
d62a17ae | 11882 | return 0; |
718e3744 | 11883 | } |
11884 | ||
d62a17ae | 11885 | static int config_write_ospf_area(struct vty *vty, struct ospf *ospf) |
718e3744 | 11886 | { |
d62a17ae | 11887 | struct listnode *node; |
11888 | struct ospf_area *area; | |
fc746f1c | 11889 | char buf[INET_ADDRSTRLEN]; |
718e3744 | 11890 | |
d62a17ae | 11891 | /* Area configuration print. */ |
11892 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) { | |
11893 | struct route_node *rn1; | |
718e3744 | 11894 | |
fc746f1c | 11895 | area_id2str(buf, sizeof(buf), &area->area_id, |
d62a17ae | 11896 | area->area_id_fmt); |
718e3744 | 11897 | |
d62a17ae | 11898 | if (area->auth_type != OSPF_AUTH_NULL) { |
11899 | if (area->auth_type == OSPF_AUTH_SIMPLE) | |
11900 | vty_out(vty, " area %s authentication\n", buf); | |
11901 | else | |
11902 | vty_out(vty, | |
11903 | " area %s authentication message-digest\n", | |
11904 | buf); | |
11905 | } | |
718e3744 | 11906 | |
d62a17ae | 11907 | if (area->shortcut_configured != OSPF_SHORTCUT_DEFAULT) |
11908 | vty_out(vty, " area %s shortcut %s\n", buf, | |
11909 | ospf_shortcut_mode_str | |
11910 | [area->shortcut_configured]); | |
11911 | ||
11912 | if ((area->external_routing == OSPF_AREA_STUB) | |
11913 | || (area->external_routing == OSPF_AREA_NSSA)) { | |
7ef56a73 | 11914 | if (area->external_routing == OSPF_AREA_STUB) { |
d62a17ae | 11915 | vty_out(vty, " area %s stub", buf); |
7ef56a73 CS |
11916 | if (area->no_summary) |
11917 | vty_out(vty, " no-summary\n"); | |
11918 | vty_out(vty, "\n"); | |
11919 | } else if (area->external_routing == OSPF_AREA_NSSA) { | |
d62a17ae | 11920 | switch (area->NSSATranslatorRole) { |
11921 | case OSPF_NSSA_ROLE_NEVER: | |
7ef56a73 CS |
11922 | vty_out(vty, |
11923 | " area %s nssa translate-never\n", | |
11924 | buf); | |
d62a17ae | 11925 | break; |
11926 | case OSPF_NSSA_ROLE_ALWAYS: | |
7ef56a73 CS |
11927 | vty_out(vty, |
11928 | " area %s nssa translate-always\n", | |
11929 | buf); | |
d62a17ae | 11930 | break; |
2643b2bc CS |
11931 | case OSPF_NSSA_ROLE_CANDIDATE: |
11932 | vty_out(vty, " area %s nssa \n", buf); | |
11933 | break; | |
d62a17ae | 11934 | } |
7ef56a73 CS |
11935 | if (area->no_summary) |
11936 | vty_out(vty, | |
11937 | " area %s nssa no-summary\n", | |
11938 | buf); | |
c317eddb | 11939 | if (area->suppress_fa) |
11940 | vty_out(vty, | |
11941 | " area %s nssa suppress-fa\n", | |
11942 | buf); | |
d62a17ae | 11943 | } |
718e3744 | 11944 | |
d62a17ae | 11945 | if (area->default_cost != 1) |
11946 | vty_out(vty, " area %s default-cost %d\n", buf, | |
11947 | area->default_cost); | |
11948 | } | |
718e3744 | 11949 | |
d62a17ae | 11950 | for (rn1 = route_top(area->ranges); rn1; rn1 = route_next(rn1)) |
11951 | if (rn1->info) { | |
11952 | struct ospf_area_range *range = rn1->info; | |
718e3744 | 11953 | |
96b663a3 MS |
11954 | vty_out(vty, " area %s range %pFX", buf, |
11955 | &rn1->p); | |
718e3744 | 11956 | |
d62a17ae | 11957 | if (range->cost_config |
11958 | != OSPF_AREA_RANGE_COST_UNSPEC) | |
11959 | vty_out(vty, " cost %d", | |
11960 | range->cost_config); | |
718e3744 | 11961 | |
d62a17ae | 11962 | if (!CHECK_FLAG(range->flags, |
11963 | OSPF_AREA_RANGE_ADVERTISE)) | |
11964 | vty_out(vty, " not-advertise"); | |
718e3744 | 11965 | |
d62a17ae | 11966 | if (CHECK_FLAG(range->flags, |
11967 | OSPF_AREA_RANGE_SUBSTITUTE)) | |
96b663a3 MS |
11968 | vty_out(vty, " substitute %pI4/%d", |
11969 | &range->subst_addr, | |
d62a17ae | 11970 | range->subst_masklen); |
11971 | ||
11972 | vty_out(vty, "\n"); | |
11973 | } | |
11974 | ||
11975 | if (EXPORT_NAME(area)) | |
11976 | vty_out(vty, " area %s export-list %s\n", buf, | |
11977 | EXPORT_NAME(area)); | |
11978 | ||
11979 | if (IMPORT_NAME(area)) | |
11980 | vty_out(vty, " area %s import-list %s\n", buf, | |
11981 | IMPORT_NAME(area)); | |
11982 | ||
11983 | if (PREFIX_NAME_IN(area)) | |
11984 | vty_out(vty, " area %s filter-list prefix %s in\n", buf, | |
11985 | PREFIX_NAME_IN(area)); | |
11986 | ||
11987 | if (PREFIX_NAME_OUT(area)) | |
11988 | vty_out(vty, " area %s filter-list prefix %s out\n", | |
11989 | buf, PREFIX_NAME_OUT(area)); | |
11990 | } | |
11991 | ||
11992 | return 0; | |
718e3744 | 11993 | } |
11994 | ||
d62a17ae | 11995 | static int config_write_ospf_nbr_nbma(struct vty *vty, struct ospf *ospf) |
718e3744 | 11996 | { |
d62a17ae | 11997 | struct ospf_nbr_nbma *nbr_nbma; |
11998 | struct route_node *rn; | |
718e3744 | 11999 | |
d62a17ae | 12000 | /* Static Neighbor configuration print. */ |
12001 | for (rn = route_top(ospf->nbr_nbma); rn; rn = route_next(rn)) | |
12002 | if ((nbr_nbma = rn->info)) { | |
96b663a3 | 12003 | vty_out(vty, " neighbor %pI4", &nbr_nbma->addr); |
718e3744 | 12004 | |
d62a17ae | 12005 | if (nbr_nbma->priority |
12006 | != OSPF_NEIGHBOR_PRIORITY_DEFAULT) | |
12007 | vty_out(vty, " priority %d", | |
12008 | nbr_nbma->priority); | |
718e3744 | 12009 | |
d62a17ae | 12010 | if (nbr_nbma->v_poll != OSPF_POLL_INTERVAL_DEFAULT) |
12011 | vty_out(vty, " poll-interval %d", | |
12012 | nbr_nbma->v_poll); | |
12013 | ||
12014 | vty_out(vty, "\n"); | |
12015 | } | |
12016 | ||
12017 | return 0; | |
12018 | } | |
12019 | ||
12020 | static int config_write_virtual_link(struct vty *vty, struct ospf *ospf) | |
12021 | { | |
12022 | struct listnode *node; | |
12023 | struct ospf_vl_data *vl_data; | |
83cc5a1f | 12024 | const char *auth_str; |
d62a17ae | 12025 | char buf[INET_ADDRSTRLEN]; |
12026 | ||
12027 | /* Virtual-Link print */ | |
12028 | for (ALL_LIST_ELEMENTS_RO(ospf->vlinks, node, vl_data)) { | |
12029 | struct listnode *n2; | |
12030 | struct crypt_key *ck; | |
12031 | struct ospf_interface *oi; | |
12032 | ||
12033 | if (vl_data != NULL) { | |
d62a17ae | 12034 | area_id2str(buf, sizeof(buf), &vl_data->vl_area_id, |
12035 | vl_data->vl_area_id_fmt); | |
12036 | oi = vl_data->vl_oi; | |
12037 | ||
12038 | /* timers */ | |
12039 | if (OSPF_IF_PARAM(oi, v_hello) | |
12040 | != OSPF_HELLO_INTERVAL_DEFAULT | |
12041 | || OSPF_IF_PARAM(oi, v_wait) | |
12042 | != OSPF_ROUTER_DEAD_INTERVAL_DEFAULT | |
12043 | || OSPF_IF_PARAM(oi, retransmit_interval) | |
12044 | != OSPF_RETRANSMIT_INTERVAL_DEFAULT | |
12045 | || OSPF_IF_PARAM(oi, transmit_delay) | |
12046 | != OSPF_TRANSMIT_DELAY_DEFAULT) | |
12047 | vty_out(vty, | |
96b663a3 MS |
12048 | " area %s virtual-link %pI4 hello-interval %d retransmit-interval %d transmit-delay %d dead-interval %d\n", |
12049 | buf, &vl_data->vl_peer, | |
d62a17ae | 12050 | OSPF_IF_PARAM(oi, v_hello), |
12051 | OSPF_IF_PARAM(oi, retransmit_interval), | |
12052 | OSPF_IF_PARAM(oi, transmit_delay), | |
12053 | OSPF_IF_PARAM(oi, v_wait)); | |
12054 | else | |
96b663a3 MS |
12055 | vty_out(vty, " area %s virtual-link %pI4\n", buf, |
12056 | &vl_data->vl_peer); | |
83cc5a1f DE |
12057 | /* Auth type */ |
12058 | auth_str = interface_config_auth_str( | |
12059 | IF_DEF_PARAMS(oi->ifp)); | |
12060 | if (auth_str) | |
12061 | vty_out(vty, | |
12062 | " area %s virtual-link %pI4 authentication%s\n", | |
12063 | buf, &vl_data->vl_peer, auth_str); | |
d62a17ae | 12064 | /* Auth key */ |
12065 | if (IF_DEF_PARAMS(vl_data->vl_oi->ifp)->auth_simple[0] | |
12066 | != '\0') | |
12067 | vty_out(vty, | |
96b663a3 MS |
12068 | " area %s virtual-link %pI4 authentication-key %s\n", |
12069 | buf, &vl_data->vl_peer, | |
d62a17ae | 12070 | IF_DEF_PARAMS(vl_data->vl_oi->ifp) |
12071 | ->auth_simple); | |
12072 | /* md5 keys */ | |
12073 | for (ALL_LIST_ELEMENTS_RO( | |
12074 | IF_DEF_PARAMS(vl_data->vl_oi->ifp) | |
12075 | ->auth_crypt, | |
12076 | n2, ck)) | |
12077 | vty_out(vty, | |
96b663a3 MS |
12078 | " area %s virtual-link %pI4 message-digest-key %d md5 %s\n", |
12079 | buf, &vl_data->vl_peer, | |
d62a17ae | 12080 | ck->key_id, ck->auth_key); |
12081 | } | |
12082 | } | |
12083 | ||
12084 | return 0; | |
718e3744 | 12085 | } |
12086 | ||
6b0655a2 | 12087 | |
d62a17ae | 12088 | static int config_write_ospf_redistribute(struct vty *vty, struct ospf *ospf) |
718e3744 | 12089 | { |
d62a17ae | 12090 | int type; |
718e3744 | 12091 | |
d62a17ae | 12092 | /* redistribute print. */ |
12093 | for (type = 0; type < ZEBRA_ROUTE_MAX; type++) { | |
12094 | struct list *red_list; | |
12095 | struct listnode *node; | |
12096 | struct ospf_redist *red; | |
718e3744 | 12097 | |
d62a17ae | 12098 | red_list = ospf->redist[type]; |
12099 | if (!red_list) | |
12100 | continue; | |
7c8ff89e | 12101 | |
d62a17ae | 12102 | for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) { |
12103 | vty_out(vty, " redistribute %s", | |
12104 | zebra_route_string(type)); | |
12105 | if (red->instance) | |
12106 | vty_out(vty, " %d", red->instance); | |
7c8ff89e | 12107 | |
d62a17ae | 12108 | if (red->dmetric.value >= 0) |
12109 | vty_out(vty, " metric %d", red->dmetric.value); | |
7c8ff89e | 12110 | |
d62a17ae | 12111 | if (red->dmetric.type == EXTERNAL_METRIC_TYPE_1) |
12112 | vty_out(vty, " metric-type 1"); | |
7c8ff89e | 12113 | |
d62a17ae | 12114 | if (ROUTEMAP_NAME(red)) |
12115 | vty_out(vty, " route-map %s", | |
12116 | ROUTEMAP_NAME(red)); | |
7c8ff89e | 12117 | |
d62a17ae | 12118 | vty_out(vty, "\n"); |
12119 | } | |
12120 | } | |
718e3744 | 12121 | |
d62a17ae | 12122 | return 0; |
718e3744 | 12123 | } |
12124 | ||
1ac88792 | 12125 | static int ospf_cfg_write_helper_dis_rtr_walkcb(struct hash_bucket *bucket, |
07b33add | 12126 | void *arg) |
12127 | { | |
1ac88792 | 12128 | struct advRtr *rtr = bucket->data; |
07b33add | 12129 | struct vty *vty = (struct vty *)arg; |
12130 | ||
96b663a3 MS |
12131 | vty_out(vty, " graceful-restart helper-only %pI4\n", |
12132 | &rtr->advRtrAddr); | |
07b33add | 12133 | return HASHWALK_CONTINUE; |
12134 | } | |
12135 | ||
12136 | static int config_write_ospf_gr_helper(struct vty *vty, struct ospf *ospf) | |
12137 | { | |
12138 | if (ospf->is_helper_supported) | |
12139 | vty_out(vty, " graceful-restart helper-only\n"); | |
12140 | ||
12141 | if (!ospf->strict_lsa_check) | |
96b663a3 MS |
12142 | vty_out(vty, |
12143 | " no graceful-restart helper strict-lsa-checking\n"); | |
07b33add | 12144 | |
12145 | if (ospf->only_planned_restart) | |
12146 | vty_out(vty, " graceful-restart helper planned-only\n"); | |
12147 | ||
12148 | if (ospf->supported_grace_time != OSPF_MAX_GRACE_INTERVAL) | |
12149 | vty_out(vty, | |
12150 | " graceful-restart helper supported-grace-time %d\n", | |
12151 | ospf->supported_grace_time); | |
12152 | ||
12153 | if (OSPF_HELPER_ENABLE_RTR_COUNT(ospf)) { | |
12154 | hash_walk(ospf->enable_rtr_list, | |
12155 | ospf_cfg_write_helper_dis_rtr_walkcb, vty); | |
12156 | } | |
423e71c4 | 12157 | return 0; |
12158 | } | |
12159 | ||
12160 | static int config_write_ospf_external_aggregator(struct vty *vty, | |
12161 | struct ospf *ospf) | |
12162 | { | |
12163 | struct route_node *rn; | |
12164 | ||
12165 | /* print 'summary-address A.B.C.D/M' */ | |
12166 | for (rn = route_top(ospf->rt_aggr_tbl); rn; rn = route_next(rn)) | |
12167 | if (rn->info) { | |
12168 | struct ospf_external_aggr_rt *aggr = rn->info; | |
12169 | ||
12170 | vty_out(vty, " summary-address %pI4/%d ", | |
12171 | &aggr->p.prefix, aggr->p.prefixlen); | |
12172 | if (aggr->tag) | |
12173 | vty_out(vty, " tag %u ", aggr->tag); | |
12174 | ||
12175 | if (CHECK_FLAG(aggr->flags, | |
12176 | OSPF_EXTERNAL_AGGRT_NO_ADVERTISE)) | |
12177 | vty_out(vty, " no-advertise"); | |
12178 | ||
12179 | vty_out(vty, "\n"); | |
12180 | } | |
07b33add | 12181 | |
12182 | return 0; | |
12183 | } | |
12184 | ||
d62a17ae | 12185 | static int config_write_ospf_default_metric(struct vty *vty, struct ospf *ospf) |
718e3744 | 12186 | { |
d62a17ae | 12187 | if (ospf->default_metric != -1) |
12188 | vty_out(vty, " default-metric %d\n", ospf->default_metric); | |
12189 | return 0; | |
718e3744 | 12190 | } |
12191 | ||
d62a17ae | 12192 | static int config_write_ospf_distribute(struct vty *vty, struct ospf *ospf) |
12193 | { | |
12194 | int type; | |
12195 | struct ospf_redist *red; | |
718e3744 | 12196 | |
d62a17ae | 12197 | if (ospf) { |
12198 | /* distribute-list print. */ | |
12199 | for (type = 0; type < ZEBRA_ROUTE_MAX; type++) | |
12200 | if (DISTRIBUTE_NAME(ospf, type)) | |
12201 | vty_out(vty, " distribute-list %s out %s\n", | |
12202 | DISTRIBUTE_NAME(ospf, type), | |
12203 | zebra_route_string(type)); | |
7c8ff89e | 12204 | |
d62a17ae | 12205 | /* default-information print. */ |
12206 | if (ospf->default_originate != DEFAULT_ORIGINATE_NONE) { | |
12207 | vty_out(vty, " default-information originate"); | |
12208 | if (ospf->default_originate == DEFAULT_ORIGINATE_ALWAYS) | |
12209 | vty_out(vty, " always"); | |
718e3744 | 12210 | |
d62a17ae | 12211 | red = ospf_redist_lookup(ospf, DEFAULT_ROUTE, 0); |
12212 | if (red) { | |
12213 | if (red->dmetric.value >= 0) | |
12214 | vty_out(vty, " metric %d", | |
12215 | red->dmetric.value); | |
951da435 | 12216 | |
d62a17ae | 12217 | if (red->dmetric.type == EXTERNAL_METRIC_TYPE_1) |
12218 | vty_out(vty, " metric-type 1"); | |
718e3744 | 12219 | |
d62a17ae | 12220 | if (ROUTEMAP_NAME(red)) |
12221 | vty_out(vty, " route-map %s", | |
12222 | ROUTEMAP_NAME(red)); | |
12223 | } | |
12224 | ||
12225 | vty_out(vty, "\n"); | |
12226 | } | |
12227 | } | |
12228 | ||
12229 | return 0; | |
718e3744 | 12230 | } |
12231 | ||
d62a17ae | 12232 | static int config_write_ospf_distance(struct vty *vty, struct ospf *ospf) |
12233 | { | |
12234 | struct route_node *rn; | |
12235 | struct ospf_distance *odistance; | |
12236 | ||
12237 | if (ospf->distance_all) | |
12238 | vty_out(vty, " distance %d\n", ospf->distance_all); | |
12239 | ||
12240 | if (ospf->distance_intra || ospf->distance_inter | |
12241 | || ospf->distance_external) { | |
12242 | vty_out(vty, " distance ospf"); | |
12243 | ||
12244 | if (ospf->distance_intra) | |
12245 | vty_out(vty, " intra-area %d", ospf->distance_intra); | |
12246 | if (ospf->distance_inter) | |
12247 | vty_out(vty, " inter-area %d", ospf->distance_inter); | |
12248 | if (ospf->distance_external) | |
12249 | vty_out(vty, " external %d", ospf->distance_external); | |
12250 | ||
12251 | vty_out(vty, "\n"); | |
12252 | } | |
12253 | ||
12254 | for (rn = route_top(ospf->distance_table); rn; rn = route_next(rn)) | |
12255 | if ((odistance = rn->info) != NULL) { | |
96b663a3 MS |
12256 | vty_out(vty, " distance %d %pFX %s\n", |
12257 | odistance->distance, &rn->p, | |
d62a17ae | 12258 | odistance->access_list ? odistance->access_list |
12259 | : ""); | |
12260 | } | |
12261 | return 0; | |
718e3744 | 12262 | } |
12263 | ||
43b8d1d8 | 12264 | static int ospf_config_write_one(struct vty *vty, struct ospf *ospf) |
d62a17ae | 12265 | { |
f4e14fdb | 12266 | struct vrf *vrf = vrf_lookup_by_id(ospf->vrf_id); |
d62a17ae | 12267 | struct interface *ifp; |
12268 | struct ospf_interface *oi; | |
43b8d1d8 | 12269 | struct listnode *node = NULL; |
d62a17ae | 12270 | int write = 0; |
12271 | ||
43b8d1d8 CS |
12272 | /* `router ospf' print. */ |
12273 | if (ospf->instance && ospf->name) { | |
996c9314 LB |
12274 | vty_out(vty, "router ospf %d vrf %s\n", ospf->instance, |
12275 | ospf->name); | |
43b8d1d8 | 12276 | } else if (ospf->instance) { |
996c9314 | 12277 | vty_out(vty, "router ospf %d\n", ospf->instance); |
43b8d1d8 | 12278 | } else if (ospf->name) { |
996c9314 | 12279 | vty_out(vty, "router ospf vrf %s\n", ospf->name); |
43b8d1d8 CS |
12280 | } else |
12281 | vty_out(vty, "router ospf\n"); | |
12282 | ||
12283 | if (!ospf->networks) { | |
12284 | write++; | |
b5a8894d | 12285 | return write; |
43b8d1d8 | 12286 | } |
d62a17ae | 12287 | |
43b8d1d8 | 12288 | /* Router ID print. */ |
3a6290bd | 12289 | if (ospf->router_id_static.s_addr != INADDR_ANY) |
96b663a3 MS |
12290 | vty_out(vty, " ospf router-id %pI4\n", |
12291 | &ospf->router_id_static); | |
d62a17ae | 12292 | |
43b8d1d8 CS |
12293 | /* ABR type print. */ |
12294 | if (ospf->abr_type != OSPF_ABR_DEFAULT) | |
12295 | vty_out(vty, " ospf abr-type %s\n", | |
12296 | ospf_abr_type_str[ospf->abr_type]); | |
b5a8894d | 12297 | |
43b8d1d8 CS |
12298 | /* log-adjacency-changes flag print. */ |
12299 | if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES)) { | |
12300 | if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL)) | |
12301 | vty_out(vty, " log-adjacency-changes detail\n"); | |
c572fbfe | 12302 | else if (!SAVE_OSPF_LOG_ADJACENCY_CHANGES) |
43b8d1d8 | 12303 | vty_out(vty, " log-adjacency-changes\n"); |
c572fbfe | 12304 | } else if (SAVE_OSPF_LOG_ADJACENCY_CHANGES) { |
43b8d1d8 CS |
12305 | vty_out(vty, " no log-adjacency-changes\n"); |
12306 | } | |
b5a8894d | 12307 | |
43b8d1d8 CS |
12308 | /* RFC1583 compatibility flag print -- Compatible with CISCO |
12309 | * 12.1. */ | |
12310 | if (CHECK_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE)) | |
12311 | vty_out(vty, " compatible rfc1583\n"); | |
d62a17ae | 12312 | |
43b8d1d8 CS |
12313 | /* auto-cost reference-bandwidth configuration. */ |
12314 | if (ospf->ref_bandwidth != OSPF_DEFAULT_REF_BANDWIDTH) { | |
12315 | vty_out(vty, | |
3efd0893 | 12316 | "! Important: ensure reference bandwidth is consistent across all routers\n"); |
43b8d1d8 CS |
12317 | vty_out(vty, " auto-cost reference-bandwidth %d\n", |
12318 | ospf->ref_bandwidth); | |
12319 | } | |
d62a17ae | 12320 | |
43b8d1d8 CS |
12321 | /* SPF timers print. */ |
12322 | if (ospf->spf_delay != OSPF_SPF_DELAY_DEFAULT | |
12323 | || ospf->spf_holdtime != OSPF_SPF_HOLDTIME_DEFAULT | |
12324 | || ospf->spf_max_holdtime != OSPF_SPF_MAX_HOLDTIME_DEFAULT) | |
996c9314 LB |
12325 | vty_out(vty, " timers throttle spf %d %d %d\n", ospf->spf_delay, |
12326 | ospf->spf_holdtime, ospf->spf_max_holdtime); | |
43b8d1d8 CS |
12327 | |
12328 | /* LSA timers print. */ | |
12329 | if (ospf->min_ls_interval != OSPF_MIN_LS_INTERVAL) | |
12330 | vty_out(vty, " timers throttle lsa all %d\n", | |
12331 | ospf->min_ls_interval); | |
12332 | if (ospf->min_ls_arrival != OSPF_MIN_LS_ARRIVAL) | |
12333 | vty_out(vty, " timers lsa min-arrival %d\n", | |
12334 | ospf->min_ls_arrival); | |
12335 | ||
12336 | /* Write multiplier print. */ | |
12337 | if (ospf->write_oi_count != OSPF_WRITE_INTERFACE_COUNT_DEFAULT) | |
12338 | vty_out(vty, " ospf write-multiplier %d\n", | |
12339 | ospf->write_oi_count); | |
d62a17ae | 12340 | |
3d5b9855 | 12341 | if (ospf->max_multipath != MULTIPATH_NUM) |
12342 | vty_out(vty, " maximum-paths %d\n", ospf->max_multipath); | |
12343 | ||
43b8d1d8 CS |
12344 | /* Max-metric router-lsa print */ |
12345 | config_write_stub_router(vty, ospf); | |
d62a17ae | 12346 | |
43b8d1d8 | 12347 | /* SPF refresh parameters print. */ |
996c9314 LB |
12348 | if (ospf->lsa_refresh_interval != OSPF_LSA_REFRESH_INTERVAL_DEFAULT) |
12349 | vty_out(vty, " refresh timer %d\n", ospf->lsa_refresh_interval); | |
d62a17ae | 12350 | |
43b8d1d8 CS |
12351 | /* Redistribute information print. */ |
12352 | config_write_ospf_redistribute(vty, ospf); | |
d62a17ae | 12353 | |
07b33add | 12354 | /* Print gr helper configs */ |
12355 | config_write_ospf_gr_helper(vty, ospf); | |
12356 | ||
423e71c4 | 12357 | /* Print external route aggregation. */ |
12358 | config_write_ospf_external_aggregator(vty, ospf); | |
12359 | ||
43b8d1d8 CS |
12360 | /* passive-interface print. */ |
12361 | if (ospf->passive_interface_default == OSPF_IF_PASSIVE) | |
12362 | vty_out(vty, " passive-interface default\n"); | |
d62a17ae | 12363 | |
a92706bb JU |
12364 | /* proactive-arp print. */ |
12365 | if (ospf->proactive_arp != OSPF_PROACTIVE_ARP_DEFAULT) { | |
12366 | if (ospf->proactive_arp) | |
12367 | vty_out(vty, " proactive-arp\n"); | |
12368 | else | |
12369 | vty_out(vty, " no proactive-arp\n"); | |
12370 | } | |
12371 | ||
451fda4f | 12372 | FOR_ALL_INTERFACES (vrf, ifp) |
43b8d1d8 CS |
12373 | if (OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(ifp), |
12374 | passive_interface) | |
12375 | && IF_DEF_PARAMS(ifp)->passive_interface | |
996c9314 | 12376 | != ospf->passive_interface_default) { |
43b8d1d8 | 12377 | vty_out(vty, " %spassive-interface %s\n", |
996c9314 LB |
12378 | IF_DEF_PARAMS(ifp)->passive_interface ? "" |
12379 | : "no ", | |
43b8d1d8 CS |
12380 | ifp->name); |
12381 | } | |
12382 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) { | |
996c9314 | 12383 | if (!OSPF_IF_PARAM_CONFIGURED(oi->params, passive_interface)) |
43b8d1d8 CS |
12384 | continue; |
12385 | if (OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(oi->ifp), | |
12386 | passive_interface)) { | |
12387 | if (oi->params->passive_interface | |
996c9314 | 12388 | == IF_DEF_PARAMS(oi->ifp)->passive_interface) |
43b8d1d8 CS |
12389 | continue; |
12390 | } else if (oi->params->passive_interface | |
12391 | == ospf->passive_interface_default) | |
12392 | continue; | |
d62a17ae | 12393 | |
96b663a3 | 12394 | vty_out(vty, " %spassive-interface %s %pI4\n", |
43b8d1d8 | 12395 | oi->params->passive_interface ? "" : "no ", |
96b663a3 | 12396 | oi->ifp->name, &oi->address->u.prefix4); |
43b8d1d8 | 12397 | } |
d62a17ae | 12398 | |
7fd0729f | 12399 | /* TI-LFA print. */ |
385a1e07 G |
12400 | if (ospf->ti_lfa_enabled) { |
12401 | if (ospf->ti_lfa_protection_type == OSPF_TI_LFA_NODE_PROTECTION) | |
12402 | vty_out(vty, " fast-reroute ti-lfa node-protection\n"); | |
12403 | else | |
12404 | vty_out(vty, " fast-reroute ti-lfa\n"); | |
12405 | } | |
7fd0729f | 12406 | |
43b8d1d8 CS |
12407 | /* Network area print. */ |
12408 | config_write_network_area(vty, ospf); | |
d62a17ae | 12409 | |
43b8d1d8 CS |
12410 | /* Area config print. */ |
12411 | config_write_ospf_area(vty, ospf); | |
d62a17ae | 12412 | |
43b8d1d8 CS |
12413 | /* static neighbor print. */ |
12414 | config_write_ospf_nbr_nbma(vty, ospf); | |
12415 | ||
12416 | /* Virtual-Link print. */ | |
12417 | config_write_virtual_link(vty, ospf); | |
12418 | ||
12419 | /* Default metric configuration. */ | |
12420 | config_write_ospf_default_metric(vty, ospf); | |
12421 | ||
12422 | /* Distribute-list and default-information print. */ | |
12423 | config_write_ospf_distribute(vty, ospf); | |
12424 | ||
12425 | /* Distance configuration. */ | |
12426 | config_write_ospf_distance(vty, ospf); | |
12427 | ||
12428 | ospf_opaque_config_write_router(vty, ospf); | |
12429 | ||
132a782e | 12430 | /* LDP-Sync print */ |
12431 | ospf_ldp_sync_write_config(vty, ospf); | |
12432 | ||
43b8d1d8 CS |
12433 | write++; |
12434 | return write; | |
12435 | } | |
12436 | ||
12437 | /* OSPF configuration write function. */ | |
12438 | static int ospf_config_write(struct vty *vty) | |
12439 | { | |
12440 | struct ospf *ospf; | |
12441 | struct listnode *ospf_node = NULL; | |
12442 | int write = 0; | |
12443 | ||
12444 | if (listcount(om->ospf) == 0) | |
12445 | return write; | |
12446 | ||
12447 | for (ALL_LIST_ELEMENTS_RO(om->ospf, ospf_node, ospf)) { | |
88d77109 CS |
12448 | /* VRF Default check if it is running. |
12449 | * Upon daemon start, there could be default instance | |
12450 | * in absence of 'router ospf'/oi_running is disabled. */ | |
12451 | if (ospf->vrf_id == VRF_DEFAULT && ospf->oi_running) | |
12452 | write += ospf_config_write_one(vty, ospf); | |
12453 | /* For Non-Default VRF simply display the configuration, | |
12454 | * even if it is not oi_running. */ | |
12455 | else if (ospf->vrf_id != VRF_DEFAULT) | |
43b8d1d8 | 12456 | write += ospf_config_write_one(vty, ospf); |
b5a8894d | 12457 | } |
d62a17ae | 12458 | return write; |
12459 | } | |
12460 | ||
12461 | void ospf_vty_show_init(void) | |
12462 | { | |
12463 | /* "show ip ospf" commands. */ | |
12464 | install_element(VIEW_NODE, &show_ip_ospf_cmd); | |
12465 | ||
12466 | install_element(VIEW_NODE, &show_ip_ospf_instance_cmd); | |
12467 | ||
12468 | /* "show ip ospf database" commands. */ | |
a11bce11 | 12469 | install_element(VIEW_NODE, &show_ip_ospf_database_cmd); |
d62a17ae | 12470 | install_element(VIEW_NODE, &show_ip_ospf_database_max_cmd); |
a11bce11 IR |
12471 | install_element(VIEW_NODE, |
12472 | &show_ip_ospf_database_type_adv_router_cmd); | |
d62a17ae | 12473 | install_element(VIEW_NODE, |
12474 | &show_ip_ospf_instance_database_type_adv_router_cmd); | |
12475 | install_element(VIEW_NODE, &show_ip_ospf_instance_database_cmd); | |
12476 | install_element(VIEW_NODE, &show_ip_ospf_instance_database_max_cmd); | |
12477 | ||
12478 | /* "show ip ospf interface" commands. */ | |
12479 | install_element(VIEW_NODE, &show_ip_ospf_interface_cmd); | |
12480 | ||
12481 | install_element(VIEW_NODE, &show_ip_ospf_instance_interface_cmd); | |
c9339663 CS |
12482 | /* "show ip ospf interface traffic */ |
12483 | install_element(VIEW_NODE, &show_ip_ospf_interface_traffic_cmd); | |
d62a17ae | 12484 | |
12485 | /* "show ip ospf neighbor" commands. */ | |
12486 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_int_detail_cmd); | |
12487 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_int_cmd); | |
12488 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_id_cmd); | |
12489 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_detail_all_cmd); | |
12490 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_detail_cmd); | |
12491 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_cmd); | |
12492 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_all_cmd); | |
12493 | ||
12494 | install_element(VIEW_NODE, | |
12495 | &show_ip_ospf_instance_neighbor_int_detail_cmd); | |
12496 | install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_int_cmd); | |
12497 | install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_id_cmd); | |
12498 | install_element(VIEW_NODE, | |
12499 | &show_ip_ospf_instance_neighbor_detail_all_cmd); | |
12500 | install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_detail_cmd); | |
12501 | install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_cmd); | |
12502 | install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_all_cmd); | |
12503 | ||
12504 | /* "show ip ospf route" commands. */ | |
12505 | install_element(VIEW_NODE, &show_ip_ospf_route_cmd); | |
12506 | install_element(VIEW_NODE, &show_ip_ospf_border_routers_cmd); | |
12507 | ||
12508 | install_element(VIEW_NODE, &show_ip_ospf_instance_route_cmd); | |
12509 | install_element(VIEW_NODE, &show_ip_ospf_instance_border_routers_cmd); | |
b5a8894d CS |
12510 | |
12511 | /* "show ip ospf vrfs" commands. */ | |
12512 | install_element(VIEW_NODE, &show_ip_ospf_vrfs_cmd); | |
abd5b8c7 | 12513 | |
12514 | /* "show ip ospf gr-helper details" command */ | |
12515 | install_element(VIEW_NODE, &show_ip_ospf_gr_helper_cmd); | |
718e3744 | 12516 | |
53e44d05 | 12517 | /* "show ip ospf summary-address" command */ |
12518 | install_element(VIEW_NODE, &show_ip_ospf_external_aggregator_cmd); | |
12519 | } | |
6b0655a2 | 12520 | |
612c2c15 | 12521 | static int config_write_interface(struct vty *vty); |
718e3744 | 12522 | /* ospfd's interface node. */ |
62b346ee | 12523 | static struct cmd_node interface_node = { |
f4b8291f | 12524 | .name = "interface", |
62b346ee | 12525 | .node = INTERFACE_NODE, |
24389580 | 12526 | .parent_node = CONFIG_NODE, |
62b346ee | 12527 | .prompt = "%s(config-if)# ", |
612c2c15 | 12528 | .config_write = config_write_interface, |
62b346ee | 12529 | }; |
718e3744 | 12530 | |
12531 | /* Initialization of OSPF interface. */ | |
d62a17ae | 12532 | static void ospf_vty_if_init(void) |
12533 | { | |
12534 | /* Install interface node. */ | |
612c2c15 | 12535 | install_node(&interface_node); |
d62a17ae | 12536 | if_cmd_init(); |
12537 | ||
12538 | /* "ip ospf authentication" commands. */ | |
12539 | install_element(INTERFACE_NODE, &ip_ospf_authentication_args_addr_cmd); | |
12540 | install_element(INTERFACE_NODE, &ip_ospf_authentication_addr_cmd); | |
12541 | install_element(INTERFACE_NODE, | |
12542 | &no_ip_ospf_authentication_args_addr_cmd); | |
12543 | install_element(INTERFACE_NODE, &no_ip_ospf_authentication_addr_cmd); | |
12544 | install_element(INTERFACE_NODE, &ip_ospf_authentication_key_addr_cmd); | |
12545 | install_element(INTERFACE_NODE, | |
12546 | &no_ip_ospf_authentication_key_authkey_addr_cmd); | |
12547 | install_element(INTERFACE_NODE, | |
12548 | &no_ospf_authentication_key_authkey_addr_cmd); | |
12549 | ||
12550 | /* "ip ospf message-digest-key" commands. */ | |
12551 | install_element(INTERFACE_NODE, &ip_ospf_message_digest_key_cmd); | |
12552 | install_element(INTERFACE_NODE, &no_ip_ospf_message_digest_key_cmd); | |
12553 | ||
12554 | /* "ip ospf cost" commands. */ | |
12555 | install_element(INTERFACE_NODE, &ip_ospf_cost_cmd); | |
12556 | install_element(INTERFACE_NODE, &no_ip_ospf_cost_cmd); | |
12557 | ||
12558 | /* "ip ospf mtu-ignore" commands. */ | |
12559 | install_element(INTERFACE_NODE, &ip_ospf_mtu_ignore_addr_cmd); | |
12560 | install_element(INTERFACE_NODE, &no_ip_ospf_mtu_ignore_addr_cmd); | |
12561 | ||
12562 | /* "ip ospf dead-interval" commands. */ | |
12563 | install_element(INTERFACE_NODE, &ip_ospf_dead_interval_cmd); | |
12564 | install_element(INTERFACE_NODE, | |
12565 | &ip_ospf_dead_interval_minimal_addr_cmd); | |
12566 | install_element(INTERFACE_NODE, &no_ip_ospf_dead_interval_cmd); | |
12567 | ||
12568 | /* "ip ospf hello-interval" commands. */ | |
12569 | install_element(INTERFACE_NODE, &ip_ospf_hello_interval_cmd); | |
12570 | install_element(INTERFACE_NODE, &no_ip_ospf_hello_interval_cmd); | |
12571 | ||
12572 | /* "ip ospf network" commands. */ | |
12573 | install_element(INTERFACE_NODE, &ip_ospf_network_cmd); | |
12574 | install_element(INTERFACE_NODE, &no_ip_ospf_network_cmd); | |
12575 | ||
12576 | /* "ip ospf priority" commands. */ | |
12577 | install_element(INTERFACE_NODE, &ip_ospf_priority_cmd); | |
12578 | install_element(INTERFACE_NODE, &no_ip_ospf_priority_cmd); | |
12579 | ||
12580 | /* "ip ospf retransmit-interval" commands. */ | |
12581 | install_element(INTERFACE_NODE, &ip_ospf_retransmit_interval_addr_cmd); | |
12582 | install_element(INTERFACE_NODE, | |
12583 | &no_ip_ospf_retransmit_interval_addr_cmd); | |
12584 | ||
12585 | /* "ip ospf transmit-delay" commands. */ | |
12586 | install_element(INTERFACE_NODE, &ip_ospf_transmit_delay_addr_cmd); | |
12587 | install_element(INTERFACE_NODE, &no_ip_ospf_transmit_delay_addr_cmd); | |
12588 | ||
12589 | /* "ip ospf area" commands. */ | |
12590 | install_element(INTERFACE_NODE, &ip_ospf_area_cmd); | |
12591 | install_element(INTERFACE_NODE, &no_ip_ospf_area_cmd); | |
12592 | ||
12593 | /* These commands are compatibitliy for previous version. */ | |
12594 | install_element(INTERFACE_NODE, &ospf_authentication_key_cmd); | |
12595 | install_element(INTERFACE_NODE, &ospf_message_digest_key_cmd); | |
12596 | install_element(INTERFACE_NODE, &no_ospf_message_digest_key_cmd); | |
12597 | install_element(INTERFACE_NODE, &ospf_dead_interval_cmd); | |
12598 | install_element(INTERFACE_NODE, &no_ospf_dead_interval_cmd); | |
12599 | install_element(INTERFACE_NODE, &ospf_hello_interval_cmd); | |
12600 | install_element(INTERFACE_NODE, &no_ospf_hello_interval_cmd); | |
12601 | install_element(INTERFACE_NODE, &ospf_cost_cmd); | |
12602 | install_element(INTERFACE_NODE, &no_ospf_cost_cmd); | |
12603 | install_element(INTERFACE_NODE, &ospf_network_cmd); | |
12604 | install_element(INTERFACE_NODE, &no_ospf_network_cmd); | |
12605 | install_element(INTERFACE_NODE, &ospf_priority_cmd); | |
12606 | install_element(INTERFACE_NODE, &no_ospf_priority_cmd); | |
12607 | install_element(INTERFACE_NODE, &ospf_retransmit_interval_cmd); | |
12608 | install_element(INTERFACE_NODE, &no_ospf_retransmit_interval_cmd); | |
12609 | install_element(INTERFACE_NODE, &ospf_transmit_delay_cmd); | |
12610 | install_element(INTERFACE_NODE, &no_ospf_transmit_delay_cmd); | |
12611 | } | |
12612 | ||
12613 | static void ospf_vty_zebra_init(void) | |
12614 | { | |
12615 | install_element(OSPF_NODE, &ospf_redistribute_source_cmd); | |
12616 | install_element(OSPF_NODE, &no_ospf_redistribute_source_cmd); | |
12617 | install_element(OSPF_NODE, &ospf_redistribute_instance_source_cmd); | |
12618 | install_element(OSPF_NODE, &no_ospf_redistribute_instance_source_cmd); | |
12619 | ||
12620 | install_element(OSPF_NODE, &ospf_distribute_list_out_cmd); | |
12621 | install_element(OSPF_NODE, &no_ospf_distribute_list_out_cmd); | |
12622 | ||
12623 | install_element(OSPF_NODE, &ospf_default_information_originate_cmd); | |
12624 | install_element(OSPF_NODE, &no_ospf_default_information_originate_cmd); | |
12625 | ||
12626 | install_element(OSPF_NODE, &ospf_default_metric_cmd); | |
12627 | install_element(OSPF_NODE, &no_ospf_default_metric_cmd); | |
12628 | ||
12629 | install_element(OSPF_NODE, &ospf_distance_cmd); | |
12630 | install_element(OSPF_NODE, &no_ospf_distance_cmd); | |
12631 | install_element(OSPF_NODE, &no_ospf_distance_ospf_cmd); | |
12632 | install_element(OSPF_NODE, &ospf_distance_ospf_cmd); | |
07b33add | 12633 | |
12634 | /*Ospf garcefull restart helper configurations */ | |
12635 | install_element(OSPF_NODE, &ospf_gr_helper_enable_cmd); | |
12636 | install_element(OSPF_NODE, &no_ospf_gr_helper_enable_cmd); | |
12637 | install_element(OSPF_NODE, &ospf_gr_helper_enable_lsacheck_cmd); | |
12638 | install_element(OSPF_NODE, &no_ospf_gr_helper_enable_lsacheck_cmd); | |
12639 | install_element(OSPF_NODE, &ospf_gr_helper_supported_grace_time_cmd); | |
12640 | install_element(OSPF_NODE, &no_ospf_gr_helper_supported_grace_time_cmd); | |
12641 | install_element(OSPF_NODE, &ospf_gr_helper_planned_only_cmd); | |
12642 | install_element(OSPF_NODE, &no_ospf_gr_helper_planned_only_cmd); | |
423e71c4 | 12643 | |
12644 | /* External LSA summarisation config commands.*/ | |
12645 | install_element(OSPF_NODE, &ospf_external_route_aggregation_cmd); | |
12646 | install_element(OSPF_NODE, &no_ospf_external_route_aggregation_cmd); | |
12647 | install_element(OSPF_NODE, | |
12648 | &ospf_external_route_aggregation_no_adrvertise_cmd); | |
12649 | install_element(OSPF_NODE, | |
12650 | &no_ospf_external_route_aggregation_no_adrvertise_cmd); | |
12651 | install_element(OSPF_NODE, &ospf_route_aggregation_timer_cmd); | |
12652 | install_element(OSPF_NODE, &no_ospf_route_aggregation_timer_cmd); | |
718e3744 | 12653 | } |
12654 | ||
612c2c15 | 12655 | static int ospf_config_write(struct vty *vty); |
62b346ee | 12656 | static struct cmd_node ospf_node = { |
f4b8291f | 12657 | .name = "ospf", |
62b346ee | 12658 | .node = OSPF_NODE, |
24389580 | 12659 | .parent_node = CONFIG_NODE, |
62b346ee | 12660 | .prompt = "%s(config-router)# ", |
612c2c15 | 12661 | .config_write = ospf_config_write, |
62b346ee | 12662 | }; |
718e3744 | 12663 | |
d62a17ae | 12664 | static void ospf_interface_clear(struct interface *ifp) |
09f35f8c | 12665 | { |
d62a17ae | 12666 | if (!if_is_operative(ifp)) |
12667 | return; | |
09f35f8c | 12668 | |
d62a17ae | 12669 | if (IS_DEBUG_OSPF(ism, ISM_EVENTS)) |
12670 | zlog_debug("ISM[%s]: clear by reset", ifp->name); | |
09f35f8c | 12671 | |
d62a17ae | 12672 | ospf_if_reset(ifp); |
09f35f8c DS |
12673 | } |
12674 | ||
12675 | DEFUN (clear_ip_ospf_interface, | |
12676 | clear_ip_ospf_interface_cmd, | |
1e81afc3 | 12677 | "clear ip ospf [vrf NAME] interface [IFNAME]", |
09f35f8c DS |
12678 | CLEAR_STR |
12679 | IP_STR | |
12680 | "OSPF information\n" | |
03ed9f02 | 12681 | VRF_CMD_HELP_STR |
09f35f8c DS |
12682 | "Interface information\n" |
12683 | "Interface name\n") | |
12684 | { | |
03ed9f02 PG |
12685 | int idx_ifname = 0; |
12686 | int idx_vrf = 0; | |
d62a17ae | 12687 | struct interface *ifp; |
f4e14fdb | 12688 | struct listnode *node; |
b5a8894d | 12689 | struct ospf *ospf = NULL; |
03ed9f02 PG |
12690 | char *vrf_name = NULL; |
12691 | vrf_id_t vrf_id = VRF_DEFAULT; | |
12692 | struct vrf *vrf = NULL; | |
09f35f8c | 12693 | |
03ed9f02 PG |
12694 | if (argv_find(argv, argc, "vrf", &idx_vrf)) |
12695 | vrf_name = argv[idx_vrf + 1]->arg; | |
12696 | if (vrf_name && strmatch(vrf_name, VRF_DEFAULT_NAME)) | |
12697 | vrf_name = NULL; | |
12698 | if (vrf_name) { | |
12699 | vrf = vrf_lookup_by_name(vrf_name); | |
12700 | if (vrf) | |
12701 | vrf_id = vrf->vrf_id; | |
12702 | } | |
12703 | if (!argv_find(argv, argc, "IFNAME", &idx_ifname)) { | |
12704 | /* Clear all the ospfv2 interfaces. */ | |
f4e14fdb | 12705 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { |
03ed9f02 PG |
12706 | if (vrf_id != ospf->vrf_id) |
12707 | continue; | |
12708 | if (!vrf) | |
12709 | vrf = vrf_lookup_by_id(ospf->vrf_id); | |
451fda4f | 12710 | FOR_ALL_INTERFACES (vrf, ifp) |
b5a8894d CS |
12711 | ospf_interface_clear(ifp); |
12712 | } | |
12713 | } else { | |
12714 | /* Interface name is specified. */ | |
a36898e7 | 12715 | ifp = if_lookup_by_name(argv[idx_ifname]->arg, vrf_id); |
b5a8894d | 12716 | if (ifp == NULL) |
d62a17ae | 12717 | vty_out(vty, "No such interface name\n"); |
12718 | else | |
12719 | ospf_interface_clear(ifp); | |
12720 | } | |
12721 | ||
12722 | return CMD_SUCCESS; | |
09f35f8c DS |
12723 | } |
12724 | ||
d62a17ae | 12725 | void ospf_vty_clear_init(void) |
09f35f8c | 12726 | { |
d62a17ae | 12727 | install_element(ENABLE_NODE, &clear_ip_ospf_interface_cmd); |
f91ce319 MR |
12728 | install_element(ENABLE_NODE, &clear_ip_ospf_process_cmd); |
12729 | install_element(ENABLE_NODE, &clear_ip_ospf_neighbor_cmd); | |
09f35f8c DS |
12730 | } |
12731 | ||
6b0655a2 | 12732 | |
718e3744 | 12733 | /* Install OSPF related vty commands. */ |
d62a17ae | 12734 | void ospf_vty_init(void) |
12735 | { | |
12736 | /* Install ospf top node. */ | |
612c2c15 | 12737 | install_node(&ospf_node); |
d62a17ae | 12738 | |
12739 | /* "router ospf" commands. */ | |
12740 | install_element(CONFIG_NODE, &router_ospf_cmd); | |
12741 | install_element(CONFIG_NODE, &no_router_ospf_cmd); | |
12742 | ||
12743 | ||
12744 | install_default(OSPF_NODE); | |
12745 | ||
12746 | /* "ospf router-id" commands. */ | |
12747 | install_element(OSPF_NODE, &ospf_router_id_cmd); | |
12748 | install_element(OSPF_NODE, &ospf_router_id_old_cmd); | |
12749 | install_element(OSPF_NODE, &no_ospf_router_id_cmd); | |
12750 | ||
12751 | /* "passive-interface" commands. */ | |
12752 | install_element(OSPF_NODE, &ospf_passive_interface_addr_cmd); | |
12753 | install_element(OSPF_NODE, &no_ospf_passive_interface_addr_cmd); | |
12754 | ||
12755 | /* "ospf abr-type" commands. */ | |
12756 | install_element(OSPF_NODE, &ospf_abr_type_cmd); | |
12757 | install_element(OSPF_NODE, &no_ospf_abr_type_cmd); | |
12758 | ||
12759 | /* "ospf log-adjacency-changes" commands. */ | |
12760 | install_element(OSPF_NODE, &ospf_log_adjacency_changes_cmd); | |
12761 | install_element(OSPF_NODE, &ospf_log_adjacency_changes_detail_cmd); | |
12762 | install_element(OSPF_NODE, &no_ospf_log_adjacency_changes_cmd); | |
12763 | install_element(OSPF_NODE, &no_ospf_log_adjacency_changes_detail_cmd); | |
12764 | ||
12765 | /* "ospf rfc1583-compatible" commands. */ | |
12766 | install_element(OSPF_NODE, &ospf_compatible_rfc1583_cmd); | |
12767 | install_element(OSPF_NODE, &no_ospf_compatible_rfc1583_cmd); | |
12768 | install_element(OSPF_NODE, &ospf_rfc1583_flag_cmd); | |
12769 | install_element(OSPF_NODE, &no_ospf_rfc1583_flag_cmd); | |
12770 | ||
12771 | /* "network area" commands. */ | |
12772 | install_element(OSPF_NODE, &ospf_network_area_cmd); | |
12773 | install_element(OSPF_NODE, &no_ospf_network_area_cmd); | |
12774 | ||
12775 | /* "area authentication" commands. */ | |
12776 | install_element(OSPF_NODE, | |
12777 | &ospf_area_authentication_message_digest_cmd); | |
12778 | install_element(OSPF_NODE, &ospf_area_authentication_cmd); | |
12779 | install_element(OSPF_NODE, &no_ospf_area_authentication_cmd); | |
12780 | ||
12781 | /* "area range" commands. */ | |
12782 | install_element(OSPF_NODE, &ospf_area_range_cmd); | |
12783 | install_element(OSPF_NODE, &ospf_area_range_cost_cmd); | |
12784 | install_element(OSPF_NODE, &ospf_area_range_not_advertise_cmd); | |
12785 | install_element(OSPF_NODE, &no_ospf_area_range_cmd); | |
12786 | install_element(OSPF_NODE, &ospf_area_range_substitute_cmd); | |
12787 | install_element(OSPF_NODE, &no_ospf_area_range_substitute_cmd); | |
12788 | ||
12789 | /* "area virtual-link" commands. */ | |
12790 | install_element(OSPF_NODE, &ospf_area_vlink_cmd); | |
12791 | install_element(OSPF_NODE, &ospf_area_vlink_intervals_cmd); | |
12792 | install_element(OSPF_NODE, &no_ospf_area_vlink_cmd); | |
12793 | install_element(OSPF_NODE, &no_ospf_area_vlink_intervals_cmd); | |
12794 | ||
12795 | ||
12796 | /* "area stub" commands. */ | |
12797 | install_element(OSPF_NODE, &ospf_area_stub_no_summary_cmd); | |
12798 | install_element(OSPF_NODE, &ospf_area_stub_cmd); | |
12799 | install_element(OSPF_NODE, &no_ospf_area_stub_no_summary_cmd); | |
12800 | install_element(OSPF_NODE, &no_ospf_area_stub_cmd); | |
12801 | ||
12802 | /* "area nssa" commands. */ | |
12803 | install_element(OSPF_NODE, &ospf_area_nssa_cmd); | |
d62a17ae | 12804 | install_element(OSPF_NODE, &ospf_area_nssa_translate_cmd); |
12805 | install_element(OSPF_NODE, &ospf_area_nssa_no_summary_cmd); | |
7ef56a73 | 12806 | install_element(OSPF_NODE, &no_ospf_area_nssa_no_summary_cmd); |
c317eddb | 12807 | install_element(OSPF_NODE, &ospf_area_nssa_suppress_fa_cmd); |
12808 | install_element(OSPF_NODE, &no_ospf_area_nssa_suppress_fa_cmd); | |
d62a17ae | 12809 | install_element(OSPF_NODE, &no_ospf_area_nssa_cmd); |
12810 | ||
12811 | install_element(OSPF_NODE, &ospf_area_default_cost_cmd); | |
12812 | install_element(OSPF_NODE, &no_ospf_area_default_cost_cmd); | |
12813 | ||
12814 | install_element(OSPF_NODE, &ospf_area_shortcut_cmd); | |
12815 | install_element(OSPF_NODE, &no_ospf_area_shortcut_cmd); | |
12816 | ||
12817 | install_element(OSPF_NODE, &ospf_area_export_list_cmd); | |
12818 | install_element(OSPF_NODE, &no_ospf_area_export_list_cmd); | |
12819 | ||
12820 | install_element(OSPF_NODE, &ospf_area_filter_list_cmd); | |
12821 | install_element(OSPF_NODE, &no_ospf_area_filter_list_cmd); | |
12822 | ||
12823 | install_element(OSPF_NODE, &ospf_area_import_list_cmd); | |
12824 | install_element(OSPF_NODE, &no_ospf_area_import_list_cmd); | |
12825 | ||
12826 | /* SPF timer commands */ | |
12827 | install_element(OSPF_NODE, &ospf_timers_throttle_spf_cmd); | |
12828 | install_element(OSPF_NODE, &no_ospf_timers_throttle_spf_cmd); | |
12829 | ||
12830 | /* LSA timers commands */ | |
12831 | install_element(OSPF_NODE, &ospf_timers_min_ls_interval_cmd); | |
12832 | install_element(OSPF_NODE, &no_ospf_timers_min_ls_interval_cmd); | |
0e88de35 QY |
12833 | install_element(OSPF_NODE, &ospf_timers_lsa_min_arrival_cmd); |
12834 | install_element(OSPF_NODE, &no_ospf_timers_lsa_min_arrival_cmd); | |
d62a17ae | 12835 | |
12836 | /* refresh timer commands */ | |
12837 | install_element(OSPF_NODE, &ospf_refresh_timer_cmd); | |
12838 | install_element(OSPF_NODE, &no_ospf_refresh_timer_val_cmd); | |
12839 | ||
12840 | /* max-metric commands */ | |
12841 | install_element(OSPF_NODE, &ospf_max_metric_router_lsa_admin_cmd); | |
12842 | install_element(OSPF_NODE, &no_ospf_max_metric_router_lsa_admin_cmd); | |
12843 | install_element(OSPF_NODE, &ospf_max_metric_router_lsa_startup_cmd); | |
12844 | install_element(OSPF_NODE, &no_ospf_max_metric_router_lsa_startup_cmd); | |
12845 | install_element(OSPF_NODE, &ospf_max_metric_router_lsa_shutdown_cmd); | |
12846 | install_element(OSPF_NODE, &no_ospf_max_metric_router_lsa_shutdown_cmd); | |
12847 | ||
12848 | /* reference bandwidth commands */ | |
12849 | install_element(OSPF_NODE, &ospf_auto_cost_reference_bandwidth_cmd); | |
12850 | install_element(OSPF_NODE, &no_ospf_auto_cost_reference_bandwidth_cmd); | |
12851 | ||
12852 | /* "neighbor" commands. */ | |
12853 | install_element(OSPF_NODE, &ospf_neighbor_cmd); | |
12854 | install_element(OSPF_NODE, &ospf_neighbor_poll_interval_cmd); | |
12855 | install_element(OSPF_NODE, &no_ospf_neighbor_cmd); | |
12856 | install_element(OSPF_NODE, &no_ospf_neighbor_poll_cmd); | |
12857 | ||
12858 | /* write multiplier commands */ | |
12859 | install_element(OSPF_NODE, &ospf_write_multiplier_cmd); | |
12860 | install_element(OSPF_NODE, &write_multiplier_cmd); | |
12861 | install_element(OSPF_NODE, &no_ospf_write_multiplier_cmd); | |
12862 | install_element(OSPF_NODE, &no_write_multiplier_cmd); | |
12863 | ||
a92706bb JU |
12864 | /* "proactive-arp" commands. */ |
12865 | install_element(OSPF_NODE, &ospf_proactive_arp_cmd); | |
12866 | install_element(OSPF_NODE, &no_ospf_proactive_arp_cmd); | |
12867 | ||
7fd0729f G |
12868 | /* TI-LFA commands */ |
12869 | install_element(OSPF_NODE, &ospf_ti_lfa_cmd); | |
12870 | install_element(OSPF_NODE, &no_ospf_ti_lfa_cmd); | |
12871 | ||
3d5b9855 | 12872 | /* Max path configurations */ |
12873 | install_element(OSPF_NODE, &ospf_max_multipath_cmd); | |
12874 | install_element(OSPF_NODE, &no_ospf_max_multipath_cmd); | |
12875 | ||
d62a17ae | 12876 | /* Init interface related vty commands. */ |
12877 | ospf_vty_if_init(); | |
12878 | ||
12879 | /* Init zebra related vty commands. */ | |
12880 | ospf_vty_zebra_init(); | |
718e3744 | 12881 | } |