]>
Commit | Line | Data |
---|---|---|
718e3744 | 1 | /* OSPF VTY interface. |
ba682537 | 2 | * Copyright (C) 2005 6WIND <alain.ritoux@6wind.com> |
718e3744 | 3 | * Copyright (C) 2000 Toshiaki Takada |
4 | * | |
5 | * This file is part of GNU Zebra. | |
6 | * | |
7 | * GNU Zebra is free software; you can redistribute it and/or modify it | |
8 | * under the terms of the GNU General Public License as published by the | |
9 | * Free Software Foundation; either version 2, or (at your option) any | |
10 | * later version. | |
11 | * | |
12 | * GNU Zebra is distributed in the hope that it will be useful, but | |
13 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 | * General Public License for more details. | |
16 | * | |
896014f4 DL |
17 | * You should have received a copy of the GNU General Public License along |
18 | * with this program; see the file COPYING; if not, write to the Free Software | |
19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
718e3744 | 20 | */ |
21 | ||
22 | #include <zebra.h> | |
7ec4159b | 23 | #include <string.h> |
718e3744 | 24 | |
f328dc60 | 25 | #include "printfrr.h" |
cbf3e3eb | 26 | #include "monotime.h" |
718e3744 | 27 | #include "memory.h" |
28 | #include "thread.h" | |
29 | #include "prefix.h" | |
30 | #include "table.h" | |
31 | #include "vty.h" | |
32 | #include "command.h" | |
33 | #include "plist.h" | |
34 | #include "log.h" | |
35 | #include "zclient.h" | |
bf2bfafd | 36 | #include <lib/json.h> |
8efe88ea | 37 | #include "defaults.h" |
96b663a3 | 38 | #include "lib/printfrr.h" |
718e3744 | 39 | |
40 | #include "ospfd/ospfd.h" | |
41 | #include "ospfd/ospf_asbr.h" | |
42 | #include "ospfd/ospf_lsa.h" | |
43 | #include "ospfd/ospf_lsdb.h" | |
44 | #include "ospfd/ospf_ism.h" | |
45 | #include "ospfd/ospf_interface.h" | |
46 | #include "ospfd/ospf_nsm.h" | |
47 | #include "ospfd/ospf_neighbor.h" | |
48 | #include "ospfd/ospf_flood.h" | |
49 | #include "ospfd/ospf_abr.h" | |
50 | #include "ospfd/ospf_spf.h" | |
51 | #include "ospfd/ospf_route.h" | |
52 | #include "ospfd/ospf_zebra.h" | |
53 | /*#include "ospfd/ospf_routemap.h" */ | |
54 | #include "ospfd/ospf_vty.h" | |
55 | #include "ospfd/ospf_dump.h" | |
7f342629 | 56 | #include "ospfd/ospf_bfd.h" |
132a782e | 57 | #include "ospfd/ospf_ldp_sync.h" |
718e3744 | 58 | |
f328dc60 | 59 | |
c572fbfe | 60 | FRR_CFG_DEFAULT_BOOL(OSPF_LOG_ADJACENCY_CHANGES, |
4c1458b5 DL |
61 | { .val_bool = true, .match_profile = "datacenter", }, |
62 | { .val_bool = false }, | |
67b0f40c | 63 | ); |
c572fbfe | 64 | |
2b64873d | 65 | static const char *const ospf_network_type_str[] = { |
d62a17ae | 66 | "Null", "POINTOPOINT", "BROADCAST", "NBMA", "POINTOMULTIPOINT", |
67 | "VIRTUALLINK", "LOOPBACK"}; | |
718e3744 | 68 | |
718e3744 | 69 | /* Utility functions. */ |
d62a17ae | 70 | int str2area_id(const char *str, struct in_addr *area_id, int *area_id_fmt) |
718e3744 | 71 | { |
d62a17ae | 72 | char *ep; |
718e3744 | 73 | |
d62a17ae | 74 | area_id->s_addr = htonl(strtoul(str, &ep, 10)); |
75 | if (*ep && !inet_aton(str, area_id)) | |
76 | return -1; | |
718e3744 | 77 | |
d62a17ae | 78 | *area_id_fmt = |
79 | *ep ? OSPF_AREA_ID_FMT_DOTTEDQUAD : OSPF_AREA_ID_FMT_DECIMAL; | |
718e3744 | 80 | |
d62a17ae | 81 | return 0; |
718e3744 | 82 | } |
83 | ||
1f9d4e3d | 84 | static void area_id2str(char *buf, int length, struct in_addr *area_id, |
85 | int area_id_fmt) | |
86573dcb | 86 | { |
d62a17ae | 87 | if (area_id_fmt == OSPF_AREA_ID_FMT_DOTTEDQUAD) |
1f9d4e3d | 88 | inet_ntop(AF_INET, area_id, buf, length); |
d62a17ae | 89 | else |
fc746f1c QY |
90 | snprintf(buf, length, "%lu", |
91 | (unsigned long)ntohl(area_id->s_addr)); | |
86573dcb | 92 | } |
6b0655a2 | 93 | |
d62a17ae | 94 | static int str2metric(const char *str, int *metric) |
718e3744 | 95 | { |
d62a17ae | 96 | /* Sanity check. */ |
97 | if (str == NULL) | |
98 | return 0; | |
718e3744 | 99 | |
d62a17ae | 100 | *metric = strtol(str, NULL, 10); |
1fdc969f | 101 | if (*metric < 0 || *metric > 16777214) { |
d62a17ae | 102 | /* vty_out (vty, "OSPF metric value is invalid\n"); */ |
103 | return 0; | |
104 | } | |
718e3744 | 105 | |
d62a17ae | 106 | return 1; |
718e3744 | 107 | } |
108 | ||
d62a17ae | 109 | static int str2metric_type(const char *str, int *metric_type) |
718e3744 | 110 | { |
d62a17ae | 111 | /* Sanity check. */ |
112 | if (str == NULL) | |
113 | return 0; | |
718e3744 | 114 | |
d62a17ae | 115 | if (strncmp(str, "1", 1) == 0) |
116 | *metric_type = EXTERNAL_METRIC_TYPE_1; | |
117 | else if (strncmp(str, "2", 1) == 0) | |
118 | *metric_type = EXTERNAL_METRIC_TYPE_2; | |
119 | else | |
120 | return 0; | |
718e3744 | 121 | |
d62a17ae | 122 | return 1; |
718e3744 | 123 | } |
124 | ||
d62a17ae | 125 | int ospf_oi_count(struct interface *ifp) |
718e3744 | 126 | { |
d62a17ae | 127 | struct route_node *rn; |
128 | int i = 0; | |
718e3744 | 129 | |
d62a17ae | 130 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) |
131 | if (rn->info) | |
132 | i++; | |
718e3744 | 133 | |
d62a17ae | 134 | return i; |
718e3744 | 135 | } |
136 | ||
996c9314 LB |
137 | #define OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf) \ |
138 | if (argv_find(argv, argc, "vrf", &idx_vrf)) { \ | |
139 | vrf_name = argv[idx_vrf + 1]->arg; \ | |
140 | all_vrf = strmatch(vrf_name, "all"); \ | |
43b8d1d8 CS |
141 | } |
142 | ||
409f98ab IR |
143 | static int ospf_router_cmd_parse(struct vty *vty, struct cmd_token *argv[], |
144 | const int argc, unsigned short *instance, | |
145 | const char **vrf_name) | |
718e3744 | 146 | { |
34d6798f | 147 | int idx_vrf = 0, idx_inst = 0; |
b5a8894d | 148 | |
34d6798f | 149 | *instance = 0; |
409f98ab IR |
150 | if (argv_find(argv, argc, "(1-65535)", &idx_inst)) { |
151 | if (ospf_instance == 0) { | |
152 | vty_out(vty, | |
153 | "%% OSPF is not running in instance mode\n"); | |
154 | return CMD_WARNING_CONFIG_FAILED; | |
155 | } | |
156 | ||
34d6798f | 157 | *instance = strtoul(argv[idx_inst]->arg, NULL, 10); |
409f98ab | 158 | } |
34d6798f | 159 | |
409f98ab | 160 | *vrf_name = NULL; |
b5a8894d | 161 | if (argv_find(argv, argc, "vrf", &idx_vrf)) { |
409f98ab IR |
162 | if (ospf_instance != 0) { |
163 | vty_out(vty, | |
164 | "%% VRF is not supported in instance mode\n"); | |
165 | return CMD_WARNING_CONFIG_FAILED; | |
b5a8894d | 166 | } |
34d6798f | 167 | |
409f98ab IR |
168 | *vrf_name = argv[idx_vrf + 1]->arg; |
169 | if (*vrf_name && strmatch(*vrf_name, VRF_DEFAULT_NAME)) | |
170 | *vrf_name = NULL; | |
c572fbfe DL |
171 | } |
172 | ||
409f98ab | 173 | return CMD_SUCCESS; |
43b8d1d8 CS |
174 | } |
175 | ||
52d0c099 | 176 | static void ospf_show_vrf_name(struct ospf *ospf, struct vty *vty, |
d7c0a89a | 177 | json_object *json, uint8_t use_vrf) |
52d0c099 | 178 | { |
b1c3ae8c CS |
179 | if (use_vrf) { |
180 | if (json) { | |
181 | if (ospf->vrf_id == VRF_DEFAULT) | |
182 | json_object_string_add(json, "vrfName", | |
183 | "default"); | |
184 | else | |
185 | json_object_string_add(json, "vrfName", | |
186 | ospf->name); | |
187 | json_object_int_add(json, "vrfId", ospf->vrf_id); | |
188 | } else { | |
189 | if (ospf->vrf_id == VRF_DEFAULT) | |
190 | vty_out(vty, "VRF Name: %s\n", "default"); | |
191 | else if (ospf->name) | |
192 | vty_out(vty, "VRF Name: %s\n", ospf->name); | |
193 | } | |
52d0c099 | 194 | } |
52d0c099 CS |
195 | } |
196 | ||
43b8d1d8 | 197 | #ifndef VTYSH_EXTRACT_PL |
2e4c2296 | 198 | #include "ospfd/ospf_vty_clippy.c" |
43b8d1d8 CS |
199 | #endif |
200 | ||
201 | DEFUN_NOSH (router_ospf, | |
202 | router_ospf_cmd, | |
203 | "router ospf [{(1-65535)|vrf NAME}]", | |
204 | "Enable a routing process\n" | |
205 | "Start OSPF configuration\n" | |
206 | "Instance ID\n" | |
207 | VRF_CMD_HELP_STR) | |
208 | { | |
409f98ab IR |
209 | unsigned short instance; |
210 | const char *vrf_name; | |
211 | bool created = false; | |
212 | struct ospf *ospf; | |
213 | int ret; | |
43b8d1d8 | 214 | |
409f98ab IR |
215 | ret = ospf_router_cmd_parse(vty, argv, argc, &instance, &vrf_name); |
216 | if (ret != CMD_SUCCESS) | |
217 | return ret; | |
d62a17ae | 218 | |
409f98ab | 219 | if (instance != ospf_instance) { |
d62a17ae | 220 | VTY_PUSH_CONTEXT_NULL(OSPF_NODE); |
409f98ab | 221 | return CMD_NOT_MY_INSTANCE; |
d62a17ae | 222 | } |
223 | ||
409f98ab IR |
224 | ospf = ospf_get(instance, vrf_name, &created); |
225 | ||
226 | if (created) | |
227 | if (DFLT_OSPF_LOG_ADJACENCY_CHANGES) | |
228 | SET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES); | |
229 | ||
230 | if (IS_DEBUG_OSPF_EVENT) | |
231 | zlog_debug( | |
232 | "Config command 'router ospf %d' received, vrf %s id %u oi_running %u", | |
233 | ospf->instance, ospf->name ? ospf->name : "NIL", | |
234 | ospf->vrf_id, ospf->oi_running); | |
235 | ||
236 | VTY_PUSH_CONTEXT(OSPF_NODE, ospf); | |
237 | ||
64ac44f6 | 238 | return ret; |
718e3744 | 239 | } |
240 | ||
241 | DEFUN (no_router_ospf, | |
242 | no_router_ospf_cmd, | |
43b8d1d8 | 243 | "no router ospf [{(1-65535)|vrf NAME}]", |
718e3744 | 244 | NO_STR |
245 | "Enable a routing process\n" | |
7a7be519 | 246 | "Start OSPF configuration\n" |
b5a8894d CS |
247 | "Instance ID\n" |
248 | VRF_CMD_HELP_STR) | |
718e3744 | 249 | { |
409f98ab IR |
250 | unsigned short instance; |
251 | const char *vrf_name; | |
d62a17ae | 252 | struct ospf *ospf; |
409f98ab | 253 | int ret; |
b5a8894d | 254 | |
409f98ab IR |
255 | ret = ospf_router_cmd_parse(vty, argv, argc, &instance, &vrf_name); |
256 | if (ret != CMD_SUCCESS) | |
257 | return ret; | |
718e3744 | 258 | |
409f98ab IR |
259 | if (instance != ospf_instance) |
260 | return CMD_NOT_MY_INSTANCE; | |
261 | ||
262 | ospf = ospf_lookup(instance, vrf_name); | |
263 | if (ospf) | |
264 | ospf_finish(ospf); | |
265 | else | |
266 | ret = CMD_WARNING_CONFIG_FAILED; | |
267 | ||
268 | return ret; | |
718e3744 | 269 | } |
270 | ||
7c8ff89e | 271 | |
43b8d1d8 | 272 | DEFPY (ospf_router_id, |
718e3744 | 273 | ospf_router_id_cmd, |
274 | "ospf router-id A.B.C.D", | |
275 | "OSPF specific commands\n" | |
276 | "router-id for the OSPF process\n" | |
277 | "OSPF router-id in IP address format\n") | |
278 | { | |
a3d826f0 | 279 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
43b8d1d8 | 280 | |
d62a17ae | 281 | struct listnode *node; |
282 | struct ospf_area *area; | |
d62a17ae | 283 | |
284 | ospf->router_id_static = router_id; | |
285 | ||
286 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) | |
287 | if (area->full_nbrs) { | |
288 | vty_out(vty, | |
1b8049c7 | 289 | "For this router-id change to take effect, use \"clear ip ospf process\" command\n"); |
d62a17ae | 290 | return CMD_SUCCESS; |
291 | } | |
292 | ||
293 | ospf_router_id_update(ospf); | |
294 | ||
295 | return CMD_SUCCESS; | |
718e3744 | 296 | } |
297 | ||
7a7be519 | 298 | DEFUN_HIDDEN (ospf_router_id_old, |
747e489c DW |
299 | ospf_router_id_old_cmd, |
300 | "router-id A.B.C.D", | |
301 | "router-id for the OSPF process\n" | |
302 | "OSPF router-id in IP address format\n") | |
7a7be519 | 303 | { |
a3d826f0 | 304 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 305 | int idx_ipv4 = 1; |
306 | struct listnode *node; | |
307 | struct ospf_area *area; | |
308 | struct in_addr router_id; | |
309 | int ret; | |
310 | ||
311 | ret = inet_aton(argv[idx_ipv4]->arg, &router_id); | |
312 | if (!ret) { | |
313 | vty_out(vty, "Please specify Router ID by A.B.C.D\n"); | |
314 | return CMD_WARNING_CONFIG_FAILED; | |
315 | } | |
7a7be519 | 316 | |
d62a17ae | 317 | ospf->router_id_static = router_id; |
318 | ||
319 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) | |
320 | if (area->full_nbrs) { | |
321 | vty_out(vty, | |
1b8049c7 | 322 | "For this router-id change to take effect, use \"clear ip ospf process\" command\n"); |
d62a17ae | 323 | return CMD_SUCCESS; |
324 | } | |
325 | ||
326 | ospf_router_id_update(ospf); | |
327 | ||
328 | return CMD_SUCCESS; | |
7a7be519 | 329 | } |
747e489c | 330 | |
43b8d1d8 | 331 | DEFPY (no_ospf_router_id, |
718e3744 | 332 | no_ospf_router_id_cmd, |
7a7be519 | 333 | "no ospf router-id [A.B.C.D]", |
718e3744 | 334 | NO_STR |
335 | "OSPF specific commands\n" | |
7a7be519 | 336 | "router-id for the OSPF process\n" |
337 | "OSPF router-id in IP address format\n") | |
718e3744 | 338 | { |
a3d826f0 | 339 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 340 | struct listnode *node; |
341 | struct ospf_area *area; | |
68980084 | 342 | |
43b8d1d8 CS |
343 | if (router_id_str) { |
344 | if (!IPV4_ADDR_SAME(&ospf->router_id_static, &router_id)) { | |
345 | vty_out(vty, "%% OSPF router-id doesn't match\n"); | |
346 | return CMD_WARNING_CONFIG_FAILED; | |
347 | } | |
348 | } | |
349 | ||
d62a17ae | 350 | ospf->router_id_static.s_addr = 0; |
718e3744 | 351 | |
d62a17ae | 352 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) |
353 | if (area->full_nbrs) { | |
354 | vty_out(vty, | |
1b8049c7 | 355 | "For this router-id change to take effect, use \"clear ip ospf process\" command\n"); |
d62a17ae | 356 | return CMD_SUCCESS; |
357 | } | |
2c19a6ec | 358 | |
d62a17ae | 359 | ospf_router_id_update(ospf); |
718e3744 | 360 | |
d62a17ae | 361 | return CMD_SUCCESS; |
718e3744 | 362 | } |
363 | ||
718e3744 | 364 | |
3eec4ee0 IR |
365 | static void ospf_passive_interface_default_update(struct ospf *ospf, |
366 | uint8_t newval) | |
d62a17ae | 367 | { |
368 | struct listnode *ln; | |
d62a17ae | 369 | struct ospf_interface *oi; |
370 | ||
371 | ospf->passive_interface_default = newval; | |
372 | ||
3eec4ee0 IR |
373 | /* update multicast memberships */ |
374 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, ln, oi)) | |
d62a17ae | 375 | ospf_if_set_multicast(oi); |
d62a17ae | 376 | } |
377 | ||
3eec4ee0 | 378 | static void ospf_passive_interface_update(struct interface *ifp) |
d62a17ae | 379 | { |
3eec4ee0 | 380 | struct route_node *rn; |
d62a17ae | 381 | |
3eec4ee0 IR |
382 | /* |
383 | * XXX We should call ospf_if_set_multicast on exactly those | |
384 | * interfaces for which the passive property changed. It is too much | |
385 | * work to determine this set, so we do this for every interface. | |
386 | * This is safe and reasonable because ospf_if_set_multicast uses a | |
387 | * record of joined groups to avoid systems calls if the desired | |
388 | * memberships match the current memership. | |
389 | */ | |
d62a17ae | 390 | |
3eec4ee0 IR |
391 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { |
392 | struct ospf_interface *oi = rn->info; | |
d62a17ae | 393 | |
3eec4ee0 IR |
394 | if (oi) |
395 | ospf_if_set_multicast(oi); | |
d62a17ae | 396 | } |
3eec4ee0 IR |
397 | |
398 | /* | |
399 | * XXX It is not clear what state transitions the interface needs to | |
400 | * undergo when going from active to passive and vice versa. Fixing | |
401 | * this will require precise identification of interfaces having such a | |
402 | * transition. | |
403 | */ | |
d62a17ae | 404 | } |
405 | ||
3eec4ee0 IR |
406 | DEFUN (ospf_passive_interface_default, |
407 | ospf_passive_interface_default_cmd, | |
408 | "passive-interface default", | |
409 | "Suppress routing updates on an interface\n" | |
410 | "Suppress routing updates on interfaces by default\n") | |
d62a17ae | 411 | { |
3eec4ee0 IR |
412 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
413 | ||
414 | ospf_passive_interface_default_update(ospf, OSPF_IF_PASSIVE); | |
415 | ||
416 | return CMD_SUCCESS; | |
7ffa8fa2 PJ |
417 | } |
418 | ||
3eec4ee0 | 419 | DEFUN_HIDDEN (ospf_passive_interface_addr, |
a2c62831 | 420 | ospf_passive_interface_addr_cmd, |
3eec4ee0 | 421 | "passive-interface IFNAME [A.B.C.D]", |
718e3744 | 422 | "Suppress routing updates on an interface\n" |
7a7be519 | 423 | "Interface's name\n" |
3eec4ee0 | 424 | "IPv4 address\n") |
718e3744 | 425 | { |
a3d826f0 | 426 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 427 | int idx_ipv4 = 2; |
e99734f1 | 428 | struct interface *ifp = NULL; |
d62a17ae | 429 | struct in_addr addr = {.s_addr = INADDR_ANY}; |
d62a17ae | 430 | struct ospf_if_params *params; |
3eec4ee0 IR |
431 | int ret; |
432 | ||
433 | vty_out(vty, | |
434 | "This command is deprecated, because it is not VRF-aware.\n"); | |
435 | vty_out(vty, | |
436 | "Please, use \"ip ospf passive\" on an interface instead.\n"); | |
d62a17ae | 437 | |
e99734f1 | 438 | if (ospf->vrf_id != VRF_UNKNOWN) |
a36898e7 | 439 | ifp = if_get_by_name(argv[1]->arg, ospf->vrf_id); |
d62a17ae | 440 | |
b5a8894d | 441 | if (ifp == NULL) { |
996c9314 | 442 | vty_out(vty, "interface %s not found.\n", (char *)argv[1]->arg); |
e99734f1 | 443 | return CMD_WARNING_CONFIG_FAILED; |
b5a8894d | 444 | } |
d62a17ae | 445 | |
d62a17ae | 446 | if (argc == 3) { |
447 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
448 | if (!ret) { | |
449 | vty_out(vty, | |
450 | "Please specify interface address by A.B.C.D\n"); | |
451 | return CMD_WARNING_CONFIG_FAILED; | |
452 | } | |
453 | ||
454 | params = ospf_get_if_params(ifp, addr); | |
455 | ospf_if_update_params(ifp, addr); | |
3eec4ee0 IR |
456 | } else { |
457 | params = IF_DEF_PARAMS(ifp); | |
d62a17ae | 458 | } |
459 | ||
3eec4ee0 IR |
460 | params->passive_interface = OSPF_IF_PASSIVE; |
461 | SET_IF_PARAM(params, passive_interface); | |
d62a17ae | 462 | |
3eec4ee0 | 463 | ospf_passive_interface_update(ifp); |
d62a17ae | 464 | |
3eec4ee0 IR |
465 | return CMD_SUCCESS; |
466 | } | |
d62a17ae | 467 | |
3eec4ee0 IR |
468 | DEFUN (no_ospf_passive_interface_default, |
469 | no_ospf_passive_interface_default_cmd, | |
470 | "no passive-interface default", | |
471 | NO_STR | |
472 | "Allow routing updates on an interface\n" | |
473 | "Allow routing updates on interfaces by default\n") | |
474 | { | |
475 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
476 | ||
477 | ospf_passive_interface_default_update(ospf, OSPF_IF_ACTIVE); | |
d62a17ae | 478 | |
479 | return CMD_SUCCESS; | |
718e3744 | 480 | } |
481 | ||
3eec4ee0 | 482 | DEFUN_HIDDEN (no_ospf_passive_interface, |
a2c62831 | 483 | no_ospf_passive_interface_addr_cmd, |
3eec4ee0 | 484 | "no passive-interface IFNAME [A.B.C.D]", |
718e3744 | 485 | NO_STR |
486 | "Allow routing updates on an interface\n" | |
7a7be519 | 487 | "Interface's name\n" |
3eec4ee0 | 488 | "IPv4 address\n") |
718e3744 | 489 | { |
a3d826f0 | 490 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 491 | int idx_ipv4 = 3; |
e99734f1 | 492 | struct interface *ifp = NULL; |
d62a17ae | 493 | struct in_addr addr = {.s_addr = INADDR_ANY}; |
494 | struct ospf_if_params *params; | |
495 | int ret; | |
d62a17ae | 496 | |
3eec4ee0 IR |
497 | vty_out(vty, |
498 | "This command is deprecated, because it is not VRF-aware.\n"); | |
499 | vty_out(vty, | |
500 | "Please, use \"no ip ospf passive\" on an interface instead.\n"); | |
43540886 | 501 | |
e99734f1 | 502 | if (ospf->vrf_id != VRF_UNKNOWN) |
a36898e7 | 503 | ifp = if_get_by_name(argv[2]->arg, ospf->vrf_id); |
e99734f1 | 504 | |
b5a8894d | 505 | if (ifp == NULL) { |
996c9314 | 506 | vty_out(vty, "interface %s not found.\n", (char *)argv[2]->arg); |
e99734f1 | 507 | return CMD_WARNING_CONFIG_FAILED; |
b5a8894d | 508 | } |
ba6454ec | 509 | |
d62a17ae | 510 | if (argc == 4) { |
511 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
512 | if (!ret) { | |
513 | vty_out(vty, | |
514 | "Please specify interface address by A.B.C.D\n"); | |
515 | return CMD_WARNING_CONFIG_FAILED; | |
516 | } | |
d62a17ae | 517 | params = ospf_lookup_if_params(ifp, addr); |
518 | if (params == NULL) | |
519 | return CMD_SUCCESS; | |
3eec4ee0 IR |
520 | } else { |
521 | params = IF_DEF_PARAMS(ifp); | |
d62a17ae | 522 | } |
d62a17ae | 523 | |
3eec4ee0 IR |
524 | params->passive_interface = OSPF_IF_ACTIVE; |
525 | UNSET_IF_PARAM(params, passive_interface); | |
526 | if (params != IF_DEF_PARAMS(ifp)) { | |
527 | ospf_free_if_params(ifp, addr); | |
528 | ospf_if_update_params(ifp, addr); | |
d62a17ae | 529 | } |
530 | ||
3eec4ee0 IR |
531 | ospf_passive_interface_update(ifp); |
532 | ||
d62a17ae | 533 | return CMD_SUCCESS; |
718e3744 | 534 | } |
535 | ||
718e3744 | 536 | |
a2c62831 | 537 | DEFUN (ospf_network_area, |
538 | ospf_network_area_cmd, | |
6147e2c6 | 539 | "network A.B.C.D/M area <A.B.C.D|(0-4294967295)>", |
718e3744 | 540 | "Enable routing on an IP network\n" |
541 | "OSPF network prefix\n" | |
542 | "Set the OSPF area ID\n" | |
543 | "OSPF area ID in IP address format\n" | |
544 | "OSPF area ID as a decimal value\n") | |
545 | { | |
a3d826f0 | 546 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 547 | int idx_ipv4_prefixlen = 1; |
548 | int idx_ipv4_number = 3; | |
549 | struct prefix_ipv4 p; | |
550 | struct in_addr area_id; | |
551 | int ret, format; | |
cbf32f74 | 552 | uint32_t count; |
d62a17ae | 553 | |
554 | if (ospf->instance) { | |
555 | vty_out(vty, | |
556 | "The network command is not supported in multi-instance ospf\n"); | |
557 | return CMD_WARNING_CONFIG_FAILED; | |
558 | } | |
718e3744 | 559 | |
cbf32f74 IR |
560 | count = ospf_count_area_params(ospf); |
561 | if (count > 0) { | |
d62a17ae | 562 | vty_out(vty, |
563 | "Please remove all ip ospf area x.x.x.x commands first.\n"); | |
aed7cc62 | 564 | if (IS_DEBUG_OSPF_EVENT) |
996c9314 | 565 | zlog_debug( |
d12566a1 | 566 | "%s ospf vrf %s num of %u ip ospf area x config", |
5e81f5dd | 567 | __func__, ospf->name ? ospf->name : "NIL", |
cbf32f74 | 568 | count); |
d62a17ae | 569 | return CMD_WARNING_CONFIG_FAILED; |
570 | } | |
571 | ||
572 | /* Get network prefix and Area ID. */ | |
573 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); | |
574 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); | |
575 | ||
576 | ret = ospf_network_set(ospf, &p, area_id, format); | |
577 | if (ret == 0) { | |
578 | vty_out(vty, "There is already same network statement.\n"); | |
2b0a905a | 579 | return CMD_WARNING_CONFIG_FAILED; |
d62a17ae | 580 | } |
581 | ||
582 | return CMD_SUCCESS; | |
718e3744 | 583 | } |
584 | ||
a2c62831 | 585 | DEFUN (no_ospf_network_area, |
586 | no_ospf_network_area_cmd, | |
6147e2c6 | 587 | "no network A.B.C.D/M area <A.B.C.D|(0-4294967295)>", |
718e3744 | 588 | NO_STR |
589 | "Enable routing on an IP network\n" | |
590 | "OSPF network prefix\n" | |
591 | "Set the OSPF area ID\n" | |
592 | "OSPF area ID in IP address format\n" | |
593 | "OSPF area ID as a decimal value\n") | |
594 | { | |
a3d826f0 | 595 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 596 | int idx_ipv4_prefixlen = 2; |
597 | int idx_ipv4_number = 4; | |
598 | struct prefix_ipv4 p; | |
599 | struct in_addr area_id; | |
600 | int ret, format; | |
601 | ||
602 | if (ospf->instance) { | |
603 | vty_out(vty, | |
604 | "The network command is not supported in multi-instance ospf\n"); | |
605 | return CMD_WARNING_CONFIG_FAILED; | |
606 | } | |
718e3744 | 607 | |
d62a17ae | 608 | /* Get network prefix and Area ID. */ |
609 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); | |
610 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); | |
611 | ||
612 | ret = ospf_network_unset(ospf, &p, area_id); | |
613 | if (ret == 0) { | |
614 | vty_out(vty, | |
615 | "Can't find specified network area configuration.\n"); | |
616 | return CMD_WARNING_CONFIG_FAILED; | |
617 | } | |
618 | ||
619 | return CMD_SUCCESS; | |
718e3744 | 620 | } |
621 | ||
a2c62831 | 622 | DEFUN (ospf_area_range, |
623 | ospf_area_range_cmd, | |
7a7be519 | 624 | "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M [advertise [cost (0-16777215)]]", |
718e3744 | 625 | "OSPF area parameters\n" |
626 | "OSPF area ID in IP address format\n" | |
627 | "OSPF area ID as a decimal value\n" | |
628 | "Summarize routes matching address/mask (border routers only)\n" | |
7a7be519 | 629 | "Area range prefix\n" |
630 | "Advertise this range (default)\n" | |
631 | "User specified metric for this range\n" | |
632 | "Advertised metric for this range\n") | |
718e3744 | 633 | { |
a3d826f0 | 634 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 635 | int idx_ipv4_number = 1; |
636 | int idx_ipv4_prefixlen = 3; | |
637 | int idx_cost = 6; | |
638 | struct prefix_ipv4 p; | |
639 | struct in_addr area_id; | |
640 | int format; | |
d7c0a89a | 641 | uint32_t cost; |
d62a17ae | 642 | |
643 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); | |
644 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); | |
645 | ||
646 | ospf_area_range_set(ospf, area_id, &p, OSPF_AREA_RANGE_ADVERTISE); | |
ed709ed1 GW |
647 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), |
648 | format); | |
d62a17ae | 649 | if (argc > 5) { |
650 | cost = strtoul(argv[idx_cost]->arg, NULL, 10); | |
651 | ospf_area_range_cost_set(ospf, area_id, &p, cost); | |
652 | } | |
718e3744 | 653 | |
d62a17ae | 654 | return CMD_SUCCESS; |
718e3744 | 655 | } |
656 | ||
7a7be519 | 657 | DEFUN (ospf_area_range_cost, |
658 | ospf_area_range_cost_cmd, | |
659 | "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M cost (0-16777215)", | |
660 | "OSPF area parameters\n" | |
661 | "OSPF area ID in IP address format\n" | |
662 | "OSPF area ID as a decimal value\n" | |
663 | "Summarize routes matching address/mask (border routers only)\n" | |
664 | "Area range prefix\n" | |
665 | "User specified metric for this range\n" | |
666 | "Advertised metric for this range\n") | |
667 | { | |
a3d826f0 | 668 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 669 | int idx_ipv4_number = 1; |
670 | int idx_ipv4_prefixlen = 3; | |
671 | int idx_cost = 5; | |
672 | struct prefix_ipv4 p; | |
673 | struct in_addr area_id; | |
674 | int format; | |
d7c0a89a | 675 | uint32_t cost; |
7a7be519 | 676 | |
d62a17ae | 677 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
678 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); | |
7a7be519 | 679 | |
d62a17ae | 680 | ospf_area_range_set(ospf, area_id, &p, OSPF_AREA_RANGE_ADVERTISE); |
681 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
682 | format); | |
718e3744 | 683 | |
d62a17ae | 684 | cost = strtoul(argv[idx_cost]->arg, NULL, 10); |
685 | ospf_area_range_cost_set(ospf, area_id, &p, cost); | |
718e3744 | 686 | |
d62a17ae | 687 | return CMD_SUCCESS; |
7a7be519 | 688 | } |
718e3744 | 689 | |
a2c62831 | 690 | DEFUN (ospf_area_range_not_advertise, |
691 | ospf_area_range_not_advertise_cmd, | |
6147e2c6 | 692 | "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M not-advertise", |
718e3744 | 693 | "OSPF area parameters\n" |
694 | "OSPF area ID in IP address format\n" | |
695 | "OSPF area ID as a decimal value\n" | |
696 | "Summarize routes matching address/mask (border routers only)\n" | |
697 | "Area range prefix\n" | |
698 | "DoNotAdvertise this range\n") | |
699 | { | |
a3d826f0 | 700 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 701 | int idx_ipv4_number = 1; |
702 | int idx_ipv4_prefixlen = 3; | |
703 | struct prefix_ipv4 p; | |
704 | struct in_addr area_id; | |
705 | int format; | |
718e3744 | 706 | |
d62a17ae | 707 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
708 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); | |
718e3744 | 709 | |
d62a17ae | 710 | ospf_area_range_set(ospf, area_id, &p, 0); |
711 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
712 | format); | |
990baca0 | 713 | ospf_area_range_substitute_unset(ospf, area_id, &p); |
718e3744 | 714 | |
d62a17ae | 715 | return CMD_SUCCESS; |
718e3744 | 716 | } |
717 | ||
a2c62831 | 718 | DEFUN (no_ospf_area_range, |
719 | no_ospf_area_range_cmd, | |
3a2d747c | 720 | "no area <A.B.C.D|(0-4294967295)> range A.B.C.D/M [<cost (0-16777215)|advertise [cost (0-16777215)]|not-advertise>]", |
718e3744 | 721 | NO_STR |
722 | "OSPF area parameters\n" | |
723 | "OSPF area ID in IP address format\n" | |
724 | "OSPF area ID as a decimal value\n" | |
725 | "Summarize routes matching address/mask (border routers only)\n" | |
7a7be519 | 726 | "Area range prefix\n" |
3a2d747c QY |
727 | "User specified metric for this range\n" |
728 | "Advertised metric for this range\n" | |
7a7be519 | 729 | "Advertise this range (default)\n" |
3a2d747c QY |
730 | "User specified metric for this range\n" |
731 | "Advertised metric for this range\n" | |
7a7be519 | 732 | "DoNotAdvertise this range\n") |
718e3744 | 733 | { |
a3d826f0 | 734 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 735 | int idx_ipv4_number = 2; |
736 | int idx_ipv4_prefixlen = 4; | |
737 | struct prefix_ipv4 p; | |
738 | struct in_addr area_id; | |
739 | int format; | |
718e3744 | 740 | |
d62a17ae | 741 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
742 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); | |
718e3744 | 743 | |
d62a17ae | 744 | ospf_area_range_unset(ospf, area_id, &p); |
718e3744 | 745 | |
d62a17ae | 746 | return CMD_SUCCESS; |
718e3744 | 747 | } |
748 | ||
a2c62831 | 749 | DEFUN (ospf_area_range_substitute, |
750 | ospf_area_range_substitute_cmd, | |
6147e2c6 | 751 | "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M substitute A.B.C.D/M", |
718e3744 | 752 | "OSPF area parameters\n" |
753 | "OSPF area ID in IP address format\n" | |
754 | "OSPF area ID as a decimal value\n" | |
755 | "Summarize routes matching address/mask (border routers only)\n" | |
756 | "Area range prefix\n" | |
757 | "Announce area range as another prefix\n" | |
758 | "Network prefix to be announced instead of range\n") | |
759 | { | |
a3d826f0 | 760 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 761 | int idx_ipv4_number = 1; |
762 | int idx_ipv4_prefixlen = 3; | |
763 | int idx_ipv4_prefixlen_2 = 5; | |
764 | struct prefix_ipv4 p, s; | |
765 | struct in_addr area_id; | |
766 | int format; | |
718e3744 | 767 | |
d62a17ae | 768 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
769 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); | |
770 | str2prefix_ipv4(argv[idx_ipv4_prefixlen_2]->arg, &s); | |
718e3744 | 771 | |
d62a17ae | 772 | ospf_area_range_substitute_set(ospf, area_id, &p, &s); |
773 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
774 | format); | |
718e3744 | 775 | |
d62a17ae | 776 | return CMD_SUCCESS; |
718e3744 | 777 | } |
778 | ||
a2c62831 | 779 | DEFUN (no_ospf_area_range_substitute, |
780 | no_ospf_area_range_substitute_cmd, | |
6147e2c6 | 781 | "no area <A.B.C.D|(0-4294967295)> range A.B.C.D/M substitute A.B.C.D/M", |
718e3744 | 782 | NO_STR |
783 | "OSPF area parameters\n" | |
784 | "OSPF area ID in IP address format\n" | |
785 | "OSPF area ID as a decimal value\n" | |
786 | "Summarize routes matching address/mask (border routers only)\n" | |
787 | "Area range prefix\n" | |
788 | "Announce area range as another prefix\n" | |
789 | "Network prefix to be announced instead of range\n") | |
790 | { | |
a3d826f0 | 791 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 792 | int idx_ipv4_number = 2; |
793 | int idx_ipv4_prefixlen = 4; | |
794 | int idx_ipv4_prefixlen_2 = 6; | |
795 | struct prefix_ipv4 p, s; | |
796 | struct in_addr area_id; | |
797 | int format; | |
718e3744 | 798 | |
d62a17ae | 799 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
800 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); | |
801 | str2prefix_ipv4(argv[idx_ipv4_prefixlen_2]->arg, &s); | |
718e3744 | 802 | |
d62a17ae | 803 | ospf_area_range_substitute_unset(ospf, area_id, &p); |
718e3744 | 804 | |
d62a17ae | 805 | return CMD_SUCCESS; |
718e3744 | 806 | } |
807 | ||
6b0655a2 | 808 | |
718e3744 | 809 | /* Command Handler Logic in VLink stuff is delicate!! |
810 | ||
811 | ALTER AT YOUR OWN RISK!!!! | |
812 | ||
813 | Various dummy values are used to represent 'NoChange' state for | |
814 | VLink configuration NOT being changed by a VLink command, and | |
815 | special syntax is used within the command strings so that the | |
816 | typed in command verbs can be seen in the configuration command | |
817 | bacckend handler. This is to drastically reduce the verbeage | |
818 | required to coe up with a reasonably compatible Cisco VLink command | |
819 | ||
d62a17ae | 820 | - Matthew Grant <grantma@anathoth.gen.nz> |
718e3744 | 821 | Wed, 21 Feb 2001 15:13:52 +1300 |
822 | */ | |
823 | ||
d62a17ae | 824 | /* Configuration data for virtual links |
825 | */ | |
718e3744 | 826 | struct ospf_vl_config_data { |
d62a17ae | 827 | struct vty *vty; /* vty stuff */ |
828 | struct in_addr area_id; /* area ID from command line */ | |
829 | int area_id_fmt; /* command line area ID format */ | |
830 | struct in_addr vl_peer; /* command line vl_peer */ | |
831 | int auth_type; /* Authehntication type, if given */ | |
832 | char *auth_key; /* simple password if present */ | |
833 | int crypto_key_id; /* Cryptographic key ID */ | |
834 | char *md5_key; /* MD5 authentication key */ | |
835 | int hello_interval; /* Obvious what these are... */ | |
836 | int retransmit_interval; | |
837 | int transmit_delay; | |
838 | int dead_interval; | |
718e3744 | 839 | }; |
840 | ||
d62a17ae | 841 | static void ospf_vl_config_data_init(struct ospf_vl_config_data *vl_config, |
842 | struct vty *vty) | |
718e3744 | 843 | { |
d62a17ae | 844 | memset(vl_config, 0, sizeof(struct ospf_vl_config_data)); |
845 | vl_config->auth_type = OSPF_AUTH_CMD_NOTSEEN; | |
846 | vl_config->vty = vty; | |
718e3744 | 847 | } |
848 | ||
4dadc291 | 849 | static struct ospf_vl_data * |
d62a17ae | 850 | ospf_find_vl_data(struct ospf *ospf, struct ospf_vl_config_data *vl_config) |
851 | { | |
852 | struct ospf_area *area; | |
853 | struct ospf_vl_data *vl_data; | |
854 | struct vty *vty; | |
855 | struct in_addr area_id; | |
856 | ||
857 | vty = vl_config->vty; | |
858 | area_id = vl_config->area_id; | |
859 | ||
860 | if (area_id.s_addr == OSPF_AREA_BACKBONE) { | |
861 | vty_out(vty, | |
862 | "Configuring VLs over the backbone is not allowed\n"); | |
863 | return NULL; | |
864 | } | |
865 | area = ospf_area_get(ospf, area_id); | |
866 | ospf_area_display_format_set(ospf, area, vl_config->area_id_fmt); | |
867 | ||
868 | if (area->external_routing != OSPF_AREA_DEFAULT) { | |
869 | if (vl_config->area_id_fmt == OSPF_AREA_ID_FMT_DOTTEDQUAD) | |
96b663a3 | 870 | vty_out(vty, "Area %pI4 is %s\n", &area_id, |
d62a17ae | 871 | area->external_routing == OSPF_AREA_NSSA |
872 | ? "nssa" | |
873 | : "stub"); | |
874 | else | |
875 | vty_out(vty, "Area %ld is %s\n", | |
d7c0a89a | 876 | (unsigned long)ntohl(area_id.s_addr), |
d62a17ae | 877 | area->external_routing == OSPF_AREA_NSSA |
878 | ? "nssa" | |
879 | : "stub"); | |
880 | return NULL; | |
881 | } | |
882 | ||
883 | if ((vl_data = ospf_vl_lookup(ospf, area, vl_config->vl_peer)) | |
884 | == NULL) { | |
885 | vl_data = ospf_vl_data_new(area, vl_config->vl_peer); | |
886 | if (vl_data->vl_oi == NULL) { | |
887 | vl_data->vl_oi = ospf_vl_new(ospf, vl_data); | |
888 | ospf_vl_add(ospf, vl_data); | |
889 | ospf_spf_calculate_schedule(ospf, | |
890 | SPF_FLAG_CONFIG_CHANGE); | |
891 | } | |
718e3744 | 892 | } |
d62a17ae | 893 | return vl_data; |
718e3744 | 894 | } |
895 | ||
896 | ||
d62a17ae | 897 | static int ospf_vl_set_security(struct ospf_vl_data *vl_data, |
898 | struct ospf_vl_config_data *vl_config) | |
899 | { | |
900 | struct crypt_key *ck; | |
901 | struct vty *vty; | |
902 | struct interface *ifp = vl_data->vl_oi->ifp; | |
903 | ||
904 | vty = vl_config->vty; | |
905 | ||
906 | if (vl_config->auth_type != OSPF_AUTH_CMD_NOTSEEN) { | |
907 | SET_IF_PARAM(IF_DEF_PARAMS(ifp), auth_type); | |
908 | IF_DEF_PARAMS(ifp)->auth_type = vl_config->auth_type; | |
718e3744 | 909 | } |
718e3744 | 910 | |
d62a17ae | 911 | if (vl_config->auth_key) { |
912 | memset(IF_DEF_PARAMS(ifp)->auth_simple, 0, | |
913 | OSPF_AUTH_SIMPLE_SIZE + 1); | |
4d65d927 QY |
914 | strlcpy((char *)IF_DEF_PARAMS(ifp)->auth_simple, |
915 | vl_config->auth_key, | |
916 | sizeof(IF_DEF_PARAMS(ifp)->auth_simple)); | |
d62a17ae | 917 | } else if (vl_config->md5_key) { |
918 | if (ospf_crypt_key_lookup(IF_DEF_PARAMS(ifp)->auth_crypt, | |
919 | vl_config->crypto_key_id) | |
920 | != NULL) { | |
921 | vty_out(vty, "OSPF: Key %d already exists\n", | |
922 | vl_config->crypto_key_id); | |
851fcbae | 923 | return CMD_WARNING; |
d62a17ae | 924 | } |
925 | ck = ospf_crypt_key_new(); | |
926 | ck->key_id = vl_config->crypto_key_id; | |
927 | memset(ck->auth_key, 0, OSPF_AUTH_MD5_SIZE + 1); | |
4d65d927 QY |
928 | strlcpy((char *)ck->auth_key, vl_config->md5_key, |
929 | sizeof(ck->auth_key)); | |
d62a17ae | 930 | |
931 | ospf_crypt_key_add(IF_DEF_PARAMS(ifp)->auth_crypt, ck); | |
932 | } else if (vl_config->crypto_key_id != 0) { | |
933 | /* Delete a key */ | |
934 | ||
935 | if (ospf_crypt_key_lookup(IF_DEF_PARAMS(ifp)->auth_crypt, | |
936 | vl_config->crypto_key_id) | |
937 | == NULL) { | |
938 | vty_out(vty, "OSPF: Key %d does not exist\n", | |
939 | vl_config->crypto_key_id); | |
940 | return CMD_WARNING_CONFIG_FAILED; | |
941 | } | |
942 | ||
943 | ospf_crypt_key_delete(IF_DEF_PARAMS(ifp)->auth_crypt, | |
944 | vl_config->crypto_key_id); | |
945 | } | |
946 | ||
947 | return CMD_SUCCESS; | |
718e3744 | 948 | } |
949 | ||
d62a17ae | 950 | static int ospf_vl_set_timers(struct ospf_vl_data *vl_data, |
951 | struct ospf_vl_config_data *vl_config) | |
952 | { | |
953 | struct interface *ifp = vl_data->vl_oi->ifp; | |
954 | /* Virtual Link data initialised to defaults, so only set | |
955 | if a value given */ | |
956 | if (vl_config->hello_interval) { | |
957 | SET_IF_PARAM(IF_DEF_PARAMS(ifp), v_hello); | |
958 | IF_DEF_PARAMS(ifp)->v_hello = vl_config->hello_interval; | |
959 | } | |
960 | ||
961 | if (vl_config->dead_interval) { | |
962 | SET_IF_PARAM(IF_DEF_PARAMS(ifp), v_wait); | |
963 | IF_DEF_PARAMS(ifp)->v_wait = vl_config->dead_interval; | |
964 | } | |
965 | ||
966 | if (vl_config->retransmit_interval) { | |
967 | SET_IF_PARAM(IF_DEF_PARAMS(ifp), retransmit_interval); | |
968 | IF_DEF_PARAMS(ifp)->retransmit_interval = | |
969 | vl_config->retransmit_interval; | |
970 | } | |
971 | ||
972 | if (vl_config->transmit_delay) { | |
973 | SET_IF_PARAM(IF_DEF_PARAMS(ifp), transmit_delay); | |
974 | IF_DEF_PARAMS(ifp)->transmit_delay = vl_config->transmit_delay; | |
975 | } | |
976 | ||
977 | return CMD_SUCCESS; | |
718e3744 | 978 | } |
979 | ||
980 | ||
718e3744 | 981 | /* The business end of all of the above */ |
d62a17ae | 982 | static int ospf_vl_set(struct ospf *ospf, struct ospf_vl_config_data *vl_config) |
983 | { | |
984 | struct ospf_vl_data *vl_data; | |
985 | int ret; | |
718e3744 | 986 | |
d62a17ae | 987 | vl_data = ospf_find_vl_data(ospf, vl_config); |
988 | if (!vl_data) | |
989 | return CMD_WARNING_CONFIG_FAILED; | |
990 | ||
991 | /* Process this one first as it can have a fatal result, which can | |
992 | only logically occur if the virtual link exists already | |
993 | Thus a command error does not result in a change to the | |
994 | running configuration such as unexpectedly altered timer | |
995 | values etc.*/ | |
996 | ret = ospf_vl_set_security(vl_data, vl_config); | |
997 | if (ret != CMD_SUCCESS) | |
998 | return ret; | |
999 | ||
1000 | /* Set any time based parameters, these area already range checked */ | |
1001 | ||
1002 | ret = ospf_vl_set_timers(vl_data, vl_config); | |
1003 | if (ret != CMD_SUCCESS) | |
1004 | return ret; | |
718e3744 | 1005 | |
d62a17ae | 1006 | return CMD_SUCCESS; |
718e3744 | 1007 | } |
1008 | ||
1009 | /* This stuff exists to make specifying all the alias commands A LOT simpler | |
1010 | */ | |
d62a17ae | 1011 | #define VLINK_HELPSTR_IPADDR \ |
1012 | "OSPF area parameters\n" \ | |
1013 | "OSPF area ID in IP address format\n" \ | |
1014 | "OSPF area ID as a decimal value\n" \ | |
1015 | "Configure a virtual link\n" \ | |
1016 | "Router ID of the remote ABR\n" | |
1017 | ||
1018 | #define VLINK_HELPSTR_AUTHTYPE_SIMPLE \ | |
1019 | "Enable authentication on this virtual link\n" \ | |
1020 | "dummy string \n" | |
1021 | ||
1022 | #define VLINK_HELPSTR_AUTHTYPE_ALL \ | |
1023 | VLINK_HELPSTR_AUTHTYPE_SIMPLE \ | |
1024 | "Use null authentication\n" \ | |
1025 | "Use message-digest authentication\n" | |
1026 | ||
1027 | #define VLINK_HELPSTR_TIME_PARAM \ | |
1028 | "Time between HELLO packets\n" \ | |
1029 | "Seconds\n" \ | |
1030 | "Time between retransmitting lost link state advertisements\n" \ | |
1031 | "Seconds\n" \ | |
1032 | "Link state transmit delay\n" \ | |
1033 | "Seconds\n" \ | |
1034 | "Interval time after which a neighbor is declared down\n" \ | |
1035 | "Seconds\n" | |
1036 | ||
1037 | #define VLINK_HELPSTR_AUTH_SIMPLE \ | |
1038 | "Authentication password (key)\n" \ | |
baf9eaad | 1039 | "The OSPF password (key)\n" |
d62a17ae | 1040 | |
1041 | #define VLINK_HELPSTR_AUTH_MD5 \ | |
1042 | "Message digest authentication password (key)\n" \ | |
d62a17ae | 1043 | "Key ID\n" \ |
1044 | "Use MD5 algorithm\n" \ | |
baf9eaad | 1045 | "The OSPF password (key)\n" |
718e3744 | 1046 | |
a2c62831 | 1047 | DEFUN (ospf_area_vlink, |
1048 | ospf_area_vlink_cmd, | |
3d1c6dc2 | 1049 | "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 | 1050 | VLINK_HELPSTR_IPADDR |
3d1c6dc2 | 1051 | "Enable authentication on this virtual link\n" |
7a7be519 | 1052 | "Use message-digest authentication\n" |
3d1c6dc2 | 1053 | "Use null authentication\n" |
baf9eaad CS |
1054 | VLINK_HELPSTR_AUTH_MD5 |
1055 | VLINK_HELPSTR_AUTH_SIMPLE) | |
718e3744 | 1056 | { |
a3d826f0 | 1057 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1058 | int idx_ipv4_number = 1; |
1059 | int idx_ipv4 = 3; | |
1060 | struct ospf_vl_config_data vl_config; | |
1061 | char auth_key[OSPF_AUTH_SIMPLE_SIZE + 1]; | |
1062 | char md5_key[OSPF_AUTH_MD5_SIZE + 1]; | |
d62a17ae | 1063 | int ret; |
55d1da24 | 1064 | int idx = 0; |
d62a17ae | 1065 | |
1066 | ospf_vl_config_data_init(&vl_config, vty); | |
1067 | ||
1068 | /* Read off first 2 parameters and check them */ | |
1069 | ret = str2area_id(argv[idx_ipv4_number]->arg, &vl_config.area_id, | |
1070 | &vl_config.area_id_fmt); | |
1071 | if (ret < 0) { | |
1072 | vty_out(vty, "OSPF area ID is invalid\n"); | |
1073 | return CMD_WARNING_CONFIG_FAILED; | |
1074 | } | |
718e3744 | 1075 | |
d62a17ae | 1076 | ret = inet_aton(argv[idx_ipv4]->arg, &vl_config.vl_peer); |
1077 | if (!ret) { | |
1078 | vty_out(vty, "Please specify valid Router ID as a.b.c.d\n"); | |
1079 | return CMD_WARNING_CONFIG_FAILED; | |
7a7be519 | 1080 | } |
7a7be519 | 1081 | |
d62a17ae | 1082 | if (argc <= 4) { |
1083 | /* Thats all folks! - BUGS B. strikes again!!!*/ | |
7a7be519 | 1084 | |
d62a17ae | 1085 | return ospf_vl_set(ospf, &vl_config); |
1086 | } | |
1087 | ||
3d1c6dc2 CS |
1088 | if (argv_find(argv, argc, "authentication", &idx)) { |
1089 | /* authentication - this option can only occur | |
1090 | at start of command line */ | |
1091 | vl_config.auth_type = OSPF_AUTH_SIMPLE; | |
1092 | } | |
1093 | ||
3d1c6dc2 | 1094 | if (argv_find(argv, argc, "message-digest", &idx)) { |
baf9eaad | 1095 | /* authentication message-digest */ |
3d1c6dc2 CS |
1096 | vl_config.auth_type = OSPF_AUTH_CRYPTOGRAPHIC; |
1097 | } else if (argv_find(argv, argc, "null", &idx)) { | |
1098 | /* "authentication null" */ | |
1099 | vl_config.auth_type = OSPF_AUTH_NULL; | |
d62a17ae | 1100 | } |
7a7be519 | 1101 | |
3d1c6dc2 | 1102 | if (argv_find(argv, argc, "message-digest-key", &idx)) { |
3d1c6dc2 | 1103 | vl_config.md5_key = NULL; |
cbb9b53d | 1104 | vl_config.crypto_key_id = strtol(argv[idx + 1]->arg, NULL, 10); |
3d1c6dc2 CS |
1105 | if (vl_config.crypto_key_id < 0) |
1106 | return CMD_WARNING_CONFIG_FAILED; | |
1107 | ||
4d65d927 | 1108 | strlcpy(md5_key, argv[idx + 3]->arg, sizeof(md5_key)); |
3d1c6dc2 CS |
1109 | vl_config.md5_key = md5_key; |
1110 | } | |
1111 | ||
3d1c6dc2 | 1112 | if (argv_find(argv, argc, "authentication-key", &idx)) { |
4d65d927 | 1113 | strlcpy(auth_key, argv[idx + 1]->arg, sizeof(auth_key)); |
3d1c6dc2 CS |
1114 | vl_config.auth_key = auth_key; |
1115 | } | |
7a7be519 | 1116 | |
d62a17ae | 1117 | /* Action configuration */ |
1118 | ||
1119 | return ospf_vl_set(ospf, &vl_config); | |
7a7be519 | 1120 | } |
1121 | ||
a2c62831 | 1122 | DEFUN (no_ospf_area_vlink, |
1123 | no_ospf_area_vlink_cmd, | |
3d1c6dc2 | 1124 | "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 | 1125 | NO_STR |
7a7be519 | 1126 | VLINK_HELPSTR_IPADDR |
7e5ee522 IR |
1127 | "Enable authentication on this virtual link\n" |
1128 | "Use message-digest authentication\n" | |
1129 | "Use null authentication\n" | |
baf9eaad CS |
1130 | VLINK_HELPSTR_AUTH_MD5 |
1131 | VLINK_HELPSTR_AUTH_SIMPLE) | |
718e3744 | 1132 | { |
a3d826f0 | 1133 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1134 | int idx_ipv4_number = 2; |
1135 | int idx_ipv4 = 4; | |
1136 | struct ospf_area *area; | |
1137 | struct ospf_vl_config_data vl_config; | |
1138 | struct ospf_vl_data *vl_data = NULL; | |
1139 | char auth_key[OSPF_AUTH_SIMPLE_SIZE + 1]; | |
3d1c6dc2 | 1140 | int idx = 0; |
d62a17ae | 1141 | int ret, format; |
1142 | ||
1143 | ospf_vl_config_data_init(&vl_config, vty); | |
1144 | ||
1145 | ret = str2area_id(argv[idx_ipv4_number]->arg, &vl_config.area_id, | |
1146 | &format); | |
1147 | if (ret < 0) { | |
1148 | vty_out(vty, "OSPF area ID is invalid\n"); | |
1149 | return CMD_WARNING_CONFIG_FAILED; | |
1150 | } | |
1151 | ||
1152 | area = ospf_area_lookup_by_area_id(ospf, vl_config.area_id); | |
1153 | if (!area) { | |
1154 | vty_out(vty, "Area does not exist\n"); | |
1155 | return CMD_WARNING_CONFIG_FAILED; | |
1156 | } | |
1157 | ||
1158 | ret = inet_aton(argv[idx_ipv4]->arg, &vl_config.vl_peer); | |
1159 | if (!ret) { | |
1160 | vty_out(vty, "Please specify valid Router ID as a.b.c.d\n"); | |
1161 | return CMD_WARNING_CONFIG_FAILED; | |
1162 | } | |
718e3744 | 1163 | |
188823b0 EDP |
1164 | vl_data = ospf_vl_lookup(ospf, area, vl_config.vl_peer); |
1165 | if (!vl_data) { | |
1166 | vty_out(vty, "Virtual link does not exist\n"); | |
1167 | return CMD_WARNING_CONFIG_FAILED; | |
1168 | } | |
1169 | ||
d62a17ae | 1170 | if (argc <= 5) { |
1171 | /* Basic VLink no command */ | |
1172 | /* Thats all folks! - BUGS B. strikes again!!!*/ | |
188823b0 | 1173 | ospf_vl_delete(ospf, vl_data); |
d62a17ae | 1174 | ospf_area_check_free(ospf, vl_config.area_id); |
d62a17ae | 1175 | return CMD_SUCCESS; |
1176 | } | |
1177 | ||
1178 | /* If we are down here, we are reseting parameters */ | |
d62a17ae | 1179 | /* Deal with other parameters */ |
3d1c6dc2 CS |
1180 | |
1181 | if (argv_find(argv, argc, "authentication", &idx)) { | |
1182 | /* authentication - this option can only occur | |
1183 | at start of command line */ | |
1184 | vl_config.auth_type = OSPF_AUTH_NOTSET; | |
1185 | } | |
1186 | ||
3d1c6dc2 | 1187 | if (argv_find(argv, argc, "message-digest-key", &idx)) { |
3d1c6dc2 | 1188 | vl_config.md5_key = NULL; |
cbb9b53d | 1189 | vl_config.crypto_key_id = strtol(argv[idx + 1]->arg, NULL, 10); |
3d1c6dc2 CS |
1190 | if (vl_config.crypto_key_id < 0) |
1191 | return CMD_WARNING_CONFIG_FAILED; | |
d62a17ae | 1192 | } |
1193 | ||
3d1c6dc2 | 1194 | if (argv_find(argv, argc, "authentication-key", &idx)) { |
cbb9b53d | 1195 | /* Reset authentication-key to 0 */ |
3d1c6dc2 CS |
1196 | memset(auth_key, 0, OSPF_AUTH_SIMPLE_SIZE + 1); |
1197 | vl_config.auth_key = auth_key; | |
1198 | } | |
d62a17ae | 1199 | |
1200 | /* Action configuration */ | |
1201 | ||
1202 | return ospf_vl_set(ospf, &vl_config); | |
7a7be519 | 1203 | } |
1204 | ||
b1c02cec QY |
1205 | DEFUN (ospf_area_vlink_intervals, |
1206 | ospf_area_vlink_intervals_cmd, | |
1207 | "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)}", | |
1208 | VLINK_HELPSTR_IPADDR | |
1209 | VLINK_HELPSTR_TIME_PARAM) | |
1210 | { | |
a3d826f0 | 1211 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1212 | struct ospf_vl_config_data vl_config; |
1213 | int ret = 0; | |
1214 | ||
1215 | ospf_vl_config_data_init(&vl_config, vty); | |
1216 | ||
1217 | char *area_id = argv[1]->arg; | |
1218 | char *router_id = argv[3]->arg; | |
1219 | ||
1220 | ret = str2area_id(area_id, &vl_config.area_id, &vl_config.area_id_fmt); | |
1221 | if (ret < 0) { | |
1222 | vty_out(vty, "OSPF area ID is invalid\n"); | |
1223 | return CMD_WARNING_CONFIG_FAILED; | |
1224 | } | |
1225 | ||
1226 | ret = inet_aton(router_id, &vl_config.vl_peer); | |
1227 | if (!ret) { | |
1228 | vty_out(vty, "Please specify valid Router ID as a.b.c.d\n"); | |
1229 | return CMD_WARNING_CONFIG_FAILED; | |
1230 | } | |
1231 | ||
1232 | for (int idx = 4; idx < argc; idx++) { | |
1233 | if (strmatch(argv[idx]->text, "hello-interval")) | |
1234 | vl_config.hello_interval = | |
1235 | strtol(argv[++idx]->arg, NULL, 10); | |
1236 | else if (strmatch(argv[idx]->text, "retransmit-interval")) | |
1237 | vl_config.retransmit_interval = | |
1238 | strtol(argv[++idx]->arg, NULL, 10); | |
1239 | else if (strmatch(argv[idx]->text, "transmit-delay")) | |
1240 | vl_config.transmit_delay = | |
1241 | strtol(argv[++idx]->arg, NULL, 10); | |
1242 | else if (strmatch(argv[idx]->text, "dead-interval")) | |
1243 | vl_config.dead_interval = | |
1244 | strtol(argv[++idx]->arg, NULL, 10); | |
1245 | } | |
1246 | ||
1247 | /* Action configuration */ | |
1248 | return ospf_vl_set(ospf, &vl_config); | |
b1c02cec QY |
1249 | } |
1250 | ||
7a7be519 | 1251 | DEFUN (no_ospf_area_vlink_intervals, |
1252 | no_ospf_area_vlink_intervals_cmd, | |
a663a38e | 1253 | "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 | 1254 | NO_STR |
7a7be519 | 1255 | VLINK_HELPSTR_IPADDR |
7a7be519 | 1256 | VLINK_HELPSTR_TIME_PARAM) |
1257 | { | |
a3d826f0 | 1258 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1259 | struct ospf_vl_config_data vl_config; |
1260 | int ret = 0; | |
1261 | ||
1262 | ospf_vl_config_data_init(&vl_config, vty); | |
1263 | ||
1264 | char *area_id = argv[2]->arg; | |
1265 | char *router_id = argv[4]->arg; | |
1266 | ||
1267 | ret = str2area_id(area_id, &vl_config.area_id, &vl_config.area_id_fmt); | |
1268 | if (ret < 0) { | |
1269 | vty_out(vty, "OSPF area ID is invalid\n"); | |
1270 | return CMD_WARNING_CONFIG_FAILED; | |
1271 | } | |
1272 | ||
1273 | ret = inet_aton(router_id, &vl_config.vl_peer); | |
1274 | if (!ret) { | |
1275 | vty_out(vty, "Please specify valid Router ID as a.b.c.d\n"); | |
1276 | return CMD_WARNING_CONFIG_FAILED; | |
1277 | } | |
1278 | ||
1279 | for (int idx = 5; idx < argc; idx++) { | |
1280 | if (strmatch(argv[idx]->text, "hello-interval")) | |
1281 | vl_config.hello_interval = OSPF_HELLO_INTERVAL_DEFAULT; | |
1282 | else if (strmatch(argv[idx]->text, "retransmit-interval")) | |
1283 | vl_config.retransmit_interval = | |
1284 | OSPF_RETRANSMIT_INTERVAL_DEFAULT; | |
1285 | else if (strmatch(argv[idx]->text, "transmit-delay")) | |
1286 | vl_config.transmit_delay = OSPF_TRANSMIT_DELAY_DEFAULT; | |
1287 | else if (strmatch(argv[idx]->text, "dead-interval")) | |
1288 | vl_config.dead_interval = | |
1289 | OSPF_ROUTER_DEAD_INTERVAL_DEFAULT; | |
1290 | } | |
1291 | ||
1292 | /* Action configuration */ | |
1293 | return ospf_vl_set(ospf, &vl_config); | |
718e3744 | 1294 | } |
1295 | ||
a2c62831 | 1296 | DEFUN (ospf_area_shortcut, |
1297 | ospf_area_shortcut_cmd, | |
6147e2c6 | 1298 | "area <A.B.C.D|(0-4294967295)> shortcut <default|enable|disable>", |
718e3744 | 1299 | "OSPF area parameters\n" |
1300 | "OSPF area ID in IP address format\n" | |
1301 | "OSPF area ID as a decimal value\n" | |
1302 | "Configure the area's shortcutting mode\n" | |
1303 | "Set default shortcutting behavior\n" | |
1304 | "Enable shortcutting through the area\n" | |
1305 | "Disable shortcutting through the area\n") | |
1306 | { | |
a3d826f0 | 1307 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1308 | int idx_ipv4_number = 1; |
1309 | int idx_enable_disable = 3; | |
1310 | struct ospf_area *area; | |
1311 | struct in_addr area_id; | |
1312 | int mode; | |
1313 | int format; | |
1314 | ||
1315 | VTY_GET_OSPF_AREA_ID_NO_BB("shortcut", area_id, format, | |
1316 | argv[idx_ipv4_number]->arg); | |
1317 | ||
1318 | area = ospf_area_get(ospf, area_id); | |
1319 | ospf_area_display_format_set(ospf, area, format); | |
1320 | ||
1321 | if (strncmp(argv[idx_enable_disable]->arg, "de", 2) == 0) | |
1322 | mode = OSPF_SHORTCUT_DEFAULT; | |
1323 | else if (strncmp(argv[idx_enable_disable]->arg, "di", 2) == 0) | |
1324 | mode = OSPF_SHORTCUT_DISABLE; | |
1325 | else if (strncmp(argv[idx_enable_disable]->arg, "e", 1) == 0) | |
1326 | mode = OSPF_SHORTCUT_ENABLE; | |
1327 | else | |
1328 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 1329 | |
d62a17ae | 1330 | ospf_area_shortcut_set(ospf, area, mode); |
718e3744 | 1331 | |
d62a17ae | 1332 | if (ospf->abr_type != OSPF_ABR_SHORTCUT) |
1333 | vty_out(vty, | |
3efd0893 | 1334 | "Shortcut area setting will take effect only when the router is configured as Shortcut ABR\n"); |
718e3744 | 1335 | |
d62a17ae | 1336 | return CMD_SUCCESS; |
718e3744 | 1337 | } |
1338 | ||
a2c62831 | 1339 | DEFUN (no_ospf_area_shortcut, |
1340 | no_ospf_area_shortcut_cmd, | |
6147e2c6 | 1341 | "no area <A.B.C.D|(0-4294967295)> shortcut <enable|disable>", |
718e3744 | 1342 | NO_STR |
1343 | "OSPF area parameters\n" | |
1344 | "OSPF area ID in IP address format\n" | |
1345 | "OSPF area ID as a decimal value\n" | |
1346 | "Deconfigure the area's shortcutting mode\n" | |
1347 | "Deconfigure enabled shortcutting through the area\n" | |
1348 | "Deconfigure disabled shortcutting through the area\n") | |
1349 | { | |
a3d826f0 | 1350 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1351 | int idx_ipv4_number = 2; |
1352 | struct ospf_area *area; | |
1353 | struct in_addr area_id; | |
1354 | int format; | |
718e3744 | 1355 | |
d62a17ae | 1356 | VTY_GET_OSPF_AREA_ID_NO_BB("shortcut", area_id, format, |
1357 | argv[idx_ipv4_number]->arg); | |
718e3744 | 1358 | |
d62a17ae | 1359 | area = ospf_area_lookup_by_area_id(ospf, area_id); |
1360 | if (!area) | |
1361 | return CMD_SUCCESS; | |
718e3744 | 1362 | |
d62a17ae | 1363 | ospf_area_shortcut_unset(ospf, area); |
718e3744 | 1364 | |
d62a17ae | 1365 | return CMD_SUCCESS; |
718e3744 | 1366 | } |
1367 | ||
6b0655a2 | 1368 | |
a2c62831 | 1369 | DEFUN (ospf_area_stub, |
1370 | ospf_area_stub_cmd, | |
6147e2c6 | 1371 | "area <A.B.C.D|(0-4294967295)> stub", |
718e3744 | 1372 | "OSPF area parameters\n" |
1373 | "OSPF area ID in IP address format\n" | |
1374 | "OSPF area ID as a decimal value\n" | |
1375 | "Configure OSPF area as stub\n") | |
1376 | { | |
a3d826f0 | 1377 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1378 | int idx_ipv4_number = 1; |
1379 | struct in_addr area_id; | |
1380 | int ret, format; | |
1381 | ||
1382 | VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id, format, | |
1383 | argv[idx_ipv4_number]->arg); | |
1384 | ||
1385 | ret = ospf_area_stub_set(ospf, area_id); | |
1386 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
1387 | format); | |
1388 | if (ret == 0) { | |
1389 | vty_out(vty, | |
1390 | "First deconfigure all virtual link through this area\n"); | |
1391 | return CMD_WARNING_CONFIG_FAILED; | |
1392 | } | |
718e3744 | 1393 | |
44445dee S |
1394 | /* Flush the external LSAs from the specified area */ |
1395 | ospf_flush_lsa_from_area(ospf, area_id, OSPF_AS_EXTERNAL_LSA); | |
d62a17ae | 1396 | ospf_area_no_summary_unset(ospf, area_id); |
718e3744 | 1397 | |
d62a17ae | 1398 | return CMD_SUCCESS; |
718e3744 | 1399 | } |
1400 | ||
a2c62831 | 1401 | DEFUN (ospf_area_stub_no_summary, |
1402 | ospf_area_stub_no_summary_cmd, | |
6147e2c6 | 1403 | "area <A.B.C.D|(0-4294967295)> stub no-summary", |
718e3744 | 1404 | "OSPF stub parameters\n" |
1405 | "OSPF area ID in IP address format\n" | |
1406 | "OSPF area ID as a decimal value\n" | |
1407 | "Configure OSPF area as stub\n" | |
1408 | "Do not inject inter-area routes into stub\n") | |
1409 | { | |
a3d826f0 | 1410 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1411 | int idx_ipv4_number = 1; |
1412 | struct in_addr area_id; | |
1413 | int ret, format; | |
1414 | ||
1415 | VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id, format, | |
1416 | argv[idx_ipv4_number]->arg); | |
1417 | ||
1418 | ret = ospf_area_stub_set(ospf, area_id); | |
1419 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
1420 | format); | |
1421 | if (ret == 0) { | |
1422 | vty_out(vty, | |
1423 | "%% Area cannot be stub as it contains a virtual link\n"); | |
1424 | return CMD_WARNING_CONFIG_FAILED; | |
1425 | } | |
718e3744 | 1426 | |
d62a17ae | 1427 | ospf_area_no_summary_set(ospf, area_id); |
718e3744 | 1428 | |
d62a17ae | 1429 | return CMD_SUCCESS; |
718e3744 | 1430 | } |
1431 | ||
a2c62831 | 1432 | DEFUN (no_ospf_area_stub, |
1433 | no_ospf_area_stub_cmd, | |
6147e2c6 | 1434 | "no area <A.B.C.D|(0-4294967295)> stub", |
718e3744 | 1435 | NO_STR |
1436 | "OSPF area parameters\n" | |
1437 | "OSPF area ID in IP address format\n" | |
1438 | "OSPF area ID as a decimal value\n" | |
1439 | "Configure OSPF area as stub\n") | |
1440 | { | |
a3d826f0 | 1441 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1442 | int idx_ipv4_number = 2; |
1443 | struct in_addr area_id; | |
1444 | int format; | |
718e3744 | 1445 | |
d62a17ae | 1446 | VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id, format, |
1447 | argv[idx_ipv4_number]->arg); | |
718e3744 | 1448 | |
d62a17ae | 1449 | ospf_area_stub_unset(ospf, area_id); |
1450 | ospf_area_no_summary_unset(ospf, area_id); | |
718e3744 | 1451 | |
d62a17ae | 1452 | return CMD_SUCCESS; |
718e3744 | 1453 | } |
1454 | ||
a2c62831 | 1455 | DEFUN (no_ospf_area_stub_no_summary, |
1456 | no_ospf_area_stub_no_summary_cmd, | |
6147e2c6 | 1457 | "no area <A.B.C.D|(0-4294967295)> stub no-summary", |
718e3744 | 1458 | NO_STR |
1459 | "OSPF area parameters\n" | |
1460 | "OSPF area ID in IP address format\n" | |
1461 | "OSPF area ID as a decimal value\n" | |
1462 | "Configure OSPF area as stub\n" | |
1463 | "Do not inject inter-area routes into area\n") | |
1464 | { | |
a3d826f0 | 1465 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1466 | int idx_ipv4_number = 2; |
1467 | struct in_addr area_id; | |
1468 | int format; | |
718e3744 | 1469 | |
d62a17ae | 1470 | VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id, format, |
1471 | argv[idx_ipv4_number]->arg); | |
1472 | ospf_area_no_summary_unset(ospf, area_id); | |
718e3744 | 1473 | |
d62a17ae | 1474 | return CMD_SUCCESS; |
718e3744 | 1475 | } |
1476 | ||
d62a17ae | 1477 | static int ospf_area_nssa_cmd_handler(struct vty *vty, int argc, |
7ef56a73 CS |
1478 | struct cmd_token **argv, int cfg_nosum, |
1479 | int nosum) | |
718e3744 | 1480 | { |
a3d826f0 | 1481 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1482 | struct in_addr area_id; |
1483 | int ret, format; | |
1484 | ||
1485 | VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id, format, argv[1]->arg); | |
1486 | ||
1487 | ret = ospf_area_nssa_set(ospf, area_id); | |
1488 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
1489 | format); | |
1490 | if (ret == 0) { | |
1491 | vty_out(vty, | |
1492 | "%% Area cannot be nssa as it contains a virtual link\n"); | |
1493 | return CMD_WARNING_CONFIG_FAILED; | |
1494 | } | |
1495 | ||
1496 | if (argc > 3) { | |
1497 | if (strncmp(argv[3]->text, "translate-c", 11) == 0) | |
1498 | ospf_area_nssa_translator_role_set( | |
1499 | ospf, area_id, OSPF_NSSA_ROLE_CANDIDATE); | |
1500 | else if (strncmp(argv[3]->text, "translate-n", 11) == 0) | |
1501 | ospf_area_nssa_translator_role_set( | |
1502 | ospf, area_id, OSPF_NSSA_ROLE_NEVER); | |
1503 | else if (strncmp(argv[3]->text, "translate-a", 11) == 0) | |
1504 | ospf_area_nssa_translator_role_set( | |
1505 | ospf, area_id, OSPF_NSSA_ROLE_ALWAYS); | |
1506 | } else { | |
1507 | ospf_area_nssa_translator_role_set(ospf, area_id, | |
1508 | OSPF_NSSA_ROLE_CANDIDATE); | |
1509 | } | |
1510 | ||
7ef56a73 CS |
1511 | if (cfg_nosum) { |
1512 | if (nosum) | |
1513 | ospf_area_no_summary_set(ospf, area_id); | |
1514 | else | |
1515 | ospf_area_no_summary_unset(ospf, area_id); | |
1516 | } | |
d62a17ae | 1517 | |
44445dee S |
1518 | /* Flush the external LSA for the specified area */ |
1519 | ospf_flush_lsa_from_area(ospf, area_id, OSPF_AS_EXTERNAL_LSA); | |
d62a17ae | 1520 | ospf_schedule_abr_task(ospf); |
1c1c342d | 1521 | ospf_schedule_asbr_nssa_redist_update(ospf); |
d62a17ae | 1522 | |
1523 | return CMD_SUCCESS; | |
718e3744 | 1524 | } |
1525 | ||
718e3744 | 1526 | |
b0a053be | 1527 | DEFUN (ospf_area_nssa_translate, |
a2c62831 | 1528 | ospf_area_nssa_translate_cmd, |
6147e2c6 | 1529 | "area <A.B.C.D|(0-4294967295)> nssa <translate-candidate|translate-never|translate-always>", |
718e3744 | 1530 | "OSPF area parameters\n" |
1531 | "OSPF area ID in IP address format\n" | |
1532 | "OSPF area ID as a decimal value\n" | |
1533 | "Configure OSPF area as nssa\n" | |
1534 | "Configure NSSA-ABR for translate election (default)\n" | |
1535 | "Configure NSSA-ABR to never translate\n" | |
1536 | "Configure NSSA-ABR to always translate\n") | |
b0a053be | 1537 | { |
7ef56a73 | 1538 | return ospf_area_nssa_cmd_handler(vty, argc, argv, 0, 0); |
b0a053be | 1539 | } |
1540 | ||
1541 | DEFUN (ospf_area_nssa, | |
1542 | ospf_area_nssa_cmd, | |
6147e2c6 | 1543 | "area <A.B.C.D|(0-4294967295)> nssa", |
b0a053be | 1544 | "OSPF area parameters\n" |
1545 | "OSPF area ID in IP address format\n" | |
1546 | "OSPF area ID as a decimal value\n" | |
1547 | "Configure OSPF area as nssa\n") | |
1548 | { | |
2643b2bc | 1549 | return ospf_area_nssa_cmd_handler(vty, argc, argv, 0, 0); |
b0a053be | 1550 | } |
718e3744 | 1551 | |
c317eddb | 1552 | DEFUN(ospf_area_nssa_suppress_fa, ospf_area_nssa_suppress_fa_cmd, |
1553 | "area <A.B.C.D|(0-4294967295)> nssa suppress-fa", | |
1554 | "OSPF area parameters\n" | |
1555 | "OSPF area ID in IP address format\n" | |
1556 | "OSPF area ID as a decimal value\n" | |
1557 | "Configure OSPF area as nssa\n" | |
1558 | "Suppress forwarding address\n") | |
1559 | { | |
1560 | int idx_ipv4_number = 1; | |
1561 | struct in_addr area_id; | |
1562 | int format; | |
1563 | ||
1564 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
1565 | VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id, format, | |
1566 | argv[idx_ipv4_number]->arg); | |
1567 | ||
1568 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
1569 | format); | |
1570 | ospf_area_nssa_suppress_fa_set(ospf, area_id); | |
1571 | ||
1572 | ospf_schedule_abr_task(ospf); | |
1573 | ||
1574 | return CMD_SUCCESS; | |
1575 | } | |
1576 | ||
1577 | DEFUN(no_ospf_area_nssa_suppress_fa, no_ospf_area_nssa_suppress_fa_cmd, | |
1578 | "no area <A.B.C.D|(0-4294967295)> nssa suppress-fa", | |
1579 | NO_STR | |
1580 | "OSPF area parameters\n" | |
1581 | "OSPF area ID in IP address format\n" | |
1582 | "OSPF area ID as a decimal value\n" | |
1583 | "Configure OSPF area as nssa\n" | |
1584 | "Suppress forwarding address\n") | |
1585 | { | |
1586 | int idx_ipv4_number = 2; | |
1587 | struct in_addr area_id; | |
1588 | int format; | |
1589 | ||
1590 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
1591 | ||
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_unset(ospf, area_id); | |
1598 | ||
1599 | ospf_schedule_abr_task(ospf); | |
1600 | ||
1601 | return CMD_SUCCESS; | |
1602 | } | |
1603 | ||
a2c62831 | 1604 | DEFUN (ospf_area_nssa_no_summary, |
1605 | ospf_area_nssa_no_summary_cmd, | |
6147e2c6 | 1606 | "area <A.B.C.D|(0-4294967295)> nssa no-summary", |
718e3744 | 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 | "Do not inject inter-area routes into nssa\n") | |
1612 | { | |
7ef56a73 CS |
1613 | int idx_ipv4_number = 1; |
1614 | struct in_addr area_id; | |
1615 | int format; | |
1616 | ||
1617 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
1618 | VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id, format, | |
1619 | argv[idx_ipv4_number]->arg); | |
1620 | ||
1621 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
1622 | format); | |
1623 | ospf_area_nssa_no_summary_set(ospf, area_id); | |
1624 | ||
1625 | ospf_schedule_abr_task(ospf); | |
1626 | ||
1627 | return CMD_SUCCESS; | |
1628 | } | |
1629 | ||
1630 | DEFUN (no_ospf_area_nssa_no_summary, | |
1631 | no_ospf_area_nssa_no_summary_cmd, | |
1632 | "no area <A.B.C.D|(0-4294967295)> nssa no-summary", | |
1633 | NO_STR | |
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 | { | |
1640 | int idx_ipv4_number = 2; | |
1641 | struct in_addr area_id; | |
1642 | int format; | |
1643 | ||
1644 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
1645 | ||
1646 | VTY_GET_OSPF_AREA_ID_NO_BB("nssa", area_id, format, | |
1647 | argv[idx_ipv4_number]->arg); | |
1648 | ||
1649 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
1650 | format); | |
1651 | ospf_area_no_summary_unset(ospf, area_id); | |
1652 | ||
1653 | ospf_schedule_abr_task(ospf); | |
1654 | ||
1655 | return CMD_SUCCESS; | |
718e3744 | 1656 | } |
1657 | ||
a2c62831 | 1658 | DEFUN (no_ospf_area_nssa, |
1659 | no_ospf_area_nssa_cmd, | |
7ef56a73 | 1660 | "no area <A.B.C.D|(0-4294967295)> nssa [<translate-candidate|translate-never|translate-always>]", |
718e3744 | 1661 | NO_STR |
1662 | "OSPF area parameters\n" | |
1663 | "OSPF area ID in IP address format\n" | |
1664 | "OSPF area ID as a decimal value\n" | |
7a7be519 | 1665 | "Configure OSPF area as nssa\n" |
1666 | "Configure NSSA-ABR for translate election (default)\n" | |
1667 | "Configure NSSA-ABR to never translate\n" | |
7ef56a73 | 1668 | "Configure NSSA-ABR to always translate\n") |
22b27e95 | 1669 | { |
a3d826f0 | 1670 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1671 | int idx_ipv4_number = 2; |
1672 | struct in_addr area_id; | |
1673 | int format; | |
718e3744 | 1674 | |
d62a17ae | 1675 | VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id, format, |
1676 | argv[idx_ipv4_number]->arg); | |
718e3744 | 1677 | |
44445dee S |
1678 | /* Flush the NSSA LSA for the specified area */ |
1679 | ospf_flush_lsa_from_area(ospf, area_id, OSPF_AS_NSSA_LSA); | |
7ef56a73 | 1680 | ospf_area_nssa_unset(ospf, area_id, argc); |
718e3744 | 1681 | |
d62a17ae | 1682 | ospf_schedule_abr_task(ospf); |
b0a053be | 1683 | |
d62a17ae | 1684 | return CMD_SUCCESS; |
718e3744 | 1685 | } |
1686 | ||
718e3744 | 1687 | |
a2c62831 | 1688 | DEFUN (ospf_area_default_cost, |
1689 | ospf_area_default_cost_cmd, | |
6147e2c6 | 1690 | "area <A.B.C.D|(0-4294967295)> default-cost (0-16777215)", |
718e3744 | 1691 | "OSPF area parameters\n" |
1692 | "OSPF area ID in IP address format\n" | |
1693 | "OSPF area ID as a decimal value\n" | |
1694 | "Set the summary-default cost of a NSSA or stub area\n" | |
1695 | "Stub's advertised default summary cost\n") | |
1696 | { | |
a3d826f0 | 1697 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1698 | int idx_ipv4_number = 1; |
1699 | int idx_number = 3; | |
1700 | struct ospf_area *area; | |
1701 | struct in_addr area_id; | |
d7c0a89a | 1702 | uint32_t cost; |
d62a17ae | 1703 | int format; |
1704 | struct prefix_ipv4 p; | |
1705 | ||
1706 | VTY_GET_OSPF_AREA_ID_NO_BB("default-cost", area_id, format, | |
1707 | argv[idx_ipv4_number]->arg); | |
1708 | cost = strtoul(argv[idx_number]->arg, NULL, 10); | |
1709 | ||
1710 | area = ospf_area_get(ospf, area_id); | |
1711 | ospf_area_display_format_set(ospf, area, format); | |
1712 | ||
1713 | if (area->external_routing == OSPF_AREA_DEFAULT) { | |
1714 | vty_out(vty, "The area is neither stub, nor NSSA\n"); | |
1715 | return CMD_WARNING_CONFIG_FAILED; | |
1716 | } | |
ba682537 | 1717 | |
d62a17ae | 1718 | area->default_cost = cost; |
1719 | ||
1720 | p.family = AF_INET; | |
1721 | p.prefix.s_addr = OSPF_DEFAULT_DESTINATION; | |
1722 | p.prefixlen = 0; | |
1723 | if (IS_DEBUG_OSPF_EVENT) | |
1724 | zlog_debug( | |
96b663a3 MS |
1725 | "ospf_abr_announce_stub_defaults(): announcing 0.0.0.0/0 to area %pI4", |
1726 | &area->area_id); | |
d62a17ae | 1727 | ospf_abr_announce_network_to_area(&p, area->default_cost, area); |
1728 | ||
1729 | return CMD_SUCCESS; | |
718e3744 | 1730 | } |
1731 | ||
a2c62831 | 1732 | DEFUN (no_ospf_area_default_cost, |
1733 | no_ospf_area_default_cost_cmd, | |
6147e2c6 | 1734 | "no area <A.B.C.D|(0-4294967295)> default-cost (0-16777215)", |
718e3744 | 1735 | NO_STR |
1736 | "OSPF area parameters\n" | |
1737 | "OSPF area ID in IP address format\n" | |
1738 | "OSPF area ID as a decimal value\n" | |
1739 | "Set the summary-default cost of a NSSA or stub area\n" | |
1740 | "Stub's advertised default summary cost\n") | |
1741 | { | |
a3d826f0 | 1742 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1743 | int idx_ipv4_number = 2; |
1744 | struct ospf_area *area; | |
1745 | struct in_addr area_id; | |
1746 | int format; | |
1747 | struct prefix_ipv4 p; | |
718e3744 | 1748 | |
d62a17ae | 1749 | VTY_GET_OSPF_AREA_ID_NO_BB("default-cost", area_id, format, |
1750 | argv[idx_ipv4_number]->arg); | |
718e3744 | 1751 | |
d62a17ae | 1752 | area = ospf_area_lookup_by_area_id(ospf, area_id); |
1753 | if (area == NULL) | |
1754 | return CMD_SUCCESS; | |
718e3744 | 1755 | |
d62a17ae | 1756 | if (area->external_routing == OSPF_AREA_DEFAULT) { |
1757 | vty_out(vty, "The area is neither stub, nor NSSA\n"); | |
1758 | return CMD_WARNING_CONFIG_FAILED; | |
1759 | } | |
718e3744 | 1760 | |
d62a17ae | 1761 | area->default_cost = 1; |
718e3744 | 1762 | |
d62a17ae | 1763 | p.family = AF_INET; |
1764 | p.prefix.s_addr = OSPF_DEFAULT_DESTINATION; | |
1765 | p.prefixlen = 0; | |
1766 | if (IS_DEBUG_OSPF_EVENT) | |
1767 | zlog_debug( | |
96b663a3 MS |
1768 | "ospf_abr_announce_stub_defaults(): announcing 0.0.0.0/0 to area %pI4", |
1769 | &area->area_id); | |
d62a17ae | 1770 | ospf_abr_announce_network_to_area(&p, area->default_cost, area); |
ba682537 | 1771 | |
1772 | ||
d62a17ae | 1773 | ospf_area_check_free(ospf, area_id); |
718e3744 | 1774 | |
d62a17ae | 1775 | return CMD_SUCCESS; |
718e3744 | 1776 | } |
1777 | ||
a2c62831 | 1778 | DEFUN (ospf_area_export_list, |
1779 | ospf_area_export_list_cmd, | |
6147e2c6 | 1780 | "area <A.B.C.D|(0-4294967295)> export-list NAME", |
718e3744 | 1781 | "OSPF area parameters\n" |
1782 | "OSPF area ID in IP address format\n" | |
1783 | "OSPF area ID as a decimal value\n" | |
1784 | "Set the filter for networks announced to other areas\n" | |
1785 | "Name of the access-list\n") | |
1786 | { | |
a3d826f0 | 1787 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1788 | int idx_ipv4_number = 1; |
1789 | struct ospf_area *area; | |
1790 | struct in_addr area_id; | |
1791 | int format; | |
718e3744 | 1792 | |
d62a17ae | 1793 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
52930766 | 1794 | |
d62a17ae | 1795 | area = ospf_area_get(ospf, area_id); |
1796 | ospf_area_display_format_set(ospf, area, format); | |
1797 | ospf_area_export_list_set(ospf, area, argv[3]->arg); | |
718e3744 | 1798 | |
d62a17ae | 1799 | return CMD_SUCCESS; |
718e3744 | 1800 | } |
1801 | ||
a2c62831 | 1802 | DEFUN (no_ospf_area_export_list, |
1803 | no_ospf_area_export_list_cmd, | |
6147e2c6 | 1804 | "no area <A.B.C.D|(0-4294967295)> export-list NAME", |
718e3744 | 1805 | NO_STR |
1806 | "OSPF area parameters\n" | |
1807 | "OSPF area ID in IP address format\n" | |
1808 | "OSPF area ID as a decimal value\n" | |
1809 | "Unset the filter for networks announced to other areas\n" | |
1810 | "Name of the access-list\n") | |
1811 | { | |
a3d826f0 | 1812 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1813 | int idx_ipv4_number = 2; |
1814 | struct ospf_area *area; | |
1815 | struct in_addr area_id; | |
1816 | int format; | |
718e3744 | 1817 | |
d62a17ae | 1818 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
52930766 | 1819 | |
d62a17ae | 1820 | area = ospf_area_lookup_by_area_id(ospf, area_id); |
1821 | if (area == NULL) | |
1822 | return CMD_SUCCESS; | |
718e3744 | 1823 | |
d62a17ae | 1824 | ospf_area_export_list_unset(ospf, area); |
718e3744 | 1825 | |
d62a17ae | 1826 | return CMD_SUCCESS; |
718e3744 | 1827 | } |
1828 | ||
1829 | ||
a2c62831 | 1830 | DEFUN (ospf_area_import_list, |
1831 | ospf_area_import_list_cmd, | |
6147e2c6 | 1832 | "area <A.B.C.D|(0-4294967295)> import-list NAME", |
718e3744 | 1833 | "OSPF area parameters\n" |
1834 | "OSPF area ID in IP address format\n" | |
1835 | "OSPF area ID as a decimal value\n" | |
1836 | "Set the filter for networks from other areas announced to the specified one\n" | |
1837 | "Name of the access-list\n") | |
1838 | { | |
a3d826f0 | 1839 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1840 | int idx_ipv4_number = 1; |
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_get(ospf, area_id); |
1848 | ospf_area_display_format_set(ospf, area, format); | |
1849 | ospf_area_import_list_set(ospf, area, argv[3]->arg); | |
718e3744 | 1850 | |
d62a17ae | 1851 | return CMD_SUCCESS; |
718e3744 | 1852 | } |
1853 | ||
a2c62831 | 1854 | DEFUN (no_ospf_area_import_list, |
1855 | no_ospf_area_import_list_cmd, | |
6147e2c6 | 1856 | "no area <A.B.C.D|(0-4294967295)> import-list NAME", |
718e3744 | 1857 | NO_STR |
1858 | "OSPF area parameters\n" | |
1859 | "OSPF area ID in IP address format\n" | |
1860 | "OSPF area ID as a decimal value\n" | |
1861 | "Unset the filter for networks announced to other areas\n" | |
1862 | "Name of the access-list\n") | |
1863 | { | |
a3d826f0 | 1864 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1865 | int idx_ipv4_number = 2; |
1866 | struct ospf_area *area; | |
1867 | struct in_addr area_id; | |
1868 | int format; | |
718e3744 | 1869 | |
d62a17ae | 1870 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
52930766 | 1871 | |
d62a17ae | 1872 | area = ospf_area_lookup_by_area_id(ospf, area_id); |
1873 | if (area == NULL) | |
1874 | return CMD_SUCCESS; | |
718e3744 | 1875 | |
d62a17ae | 1876 | ospf_area_import_list_unset(ospf, area); |
718e3744 | 1877 | |
d62a17ae | 1878 | return CMD_SUCCESS; |
718e3744 | 1879 | } |
1880 | ||
a2c62831 | 1881 | DEFUN (ospf_area_filter_list, |
1882 | ospf_area_filter_list_cmd, | |
6147e2c6 | 1883 | "area <A.B.C.D|(0-4294967295)> filter-list prefix WORD <in|out>", |
718e3744 | 1884 | "OSPF area parameters\n" |
1885 | "OSPF area ID in IP address format\n" | |
1886 | "OSPF area ID as a decimal value\n" | |
1887 | "Filter networks between OSPF areas\n" | |
1888 | "Filter prefixes between OSPF areas\n" | |
1889 | "Name of an IP prefix-list\n" | |
1890 | "Filter networks sent to this area\n" | |
1891 | "Filter networks sent from this area\n") | |
1892 | { | |
a3d826f0 | 1893 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1894 | int idx_ipv4_number = 1; |
1895 | int idx_word = 4; | |
1896 | int idx_in_out = 5; | |
1897 | struct ospf_area *area; | |
1898 | struct in_addr area_id; | |
1899 | struct prefix_list *plist; | |
1900 | int format; | |
1901 | ||
1902 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); | |
1903 | ||
1904 | area = ospf_area_get(ospf, area_id); | |
1905 | ospf_area_display_format_set(ospf, area, format); | |
1906 | plist = prefix_list_lookup(AFI_IP, argv[idx_word]->arg); | |
1907 | if (strncmp(argv[idx_in_out]->arg, "in", 2) == 0) { | |
1908 | PREFIX_LIST_IN(area) = plist; | |
1909 | if (PREFIX_NAME_IN(area)) | |
1910 | free(PREFIX_NAME_IN(area)); | |
1911 | ||
1912 | PREFIX_NAME_IN(area) = strdup(argv[idx_word]->arg); | |
1913 | ospf_schedule_abr_task(ospf); | |
1914 | } else { | |
1915 | PREFIX_LIST_OUT(area) = plist; | |
1916 | if (PREFIX_NAME_OUT(area)) | |
1917 | free(PREFIX_NAME_OUT(area)); | |
1918 | ||
1919 | PREFIX_NAME_OUT(area) = strdup(argv[idx_word]->arg); | |
1920 | ospf_schedule_abr_task(ospf); | |
1921 | } | |
718e3744 | 1922 | |
d62a17ae | 1923 | return CMD_SUCCESS; |
718e3744 | 1924 | } |
1925 | ||
a2c62831 | 1926 | DEFUN (no_ospf_area_filter_list, |
1927 | no_ospf_area_filter_list_cmd, | |
6147e2c6 | 1928 | "no area <A.B.C.D|(0-4294967295)> filter-list prefix WORD <in|out>", |
718e3744 | 1929 | NO_STR |
1930 | "OSPF area parameters\n" | |
1931 | "OSPF area ID in IP address format\n" | |
1932 | "OSPF area ID as a decimal value\n" | |
1933 | "Filter networks between OSPF areas\n" | |
1934 | "Filter prefixes between OSPF areas\n" | |
1935 | "Name of an IP prefix-list\n" | |
1936 | "Filter networks sent to this area\n" | |
1937 | "Filter networks sent from this area\n") | |
1938 | { | |
a3d826f0 | 1939 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1940 | int idx_ipv4_number = 2; |
1941 | int idx_word = 5; | |
1942 | int idx_in_out = 6; | |
1943 | struct ospf_area *area; | |
1944 | struct in_addr area_id; | |
1945 | int format; | |
718e3744 | 1946 | |
d62a17ae | 1947 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
718e3744 | 1948 | |
d62a17ae | 1949 | if ((area = ospf_area_lookup_by_area_id(ospf, area_id)) == NULL) |
1950 | return CMD_SUCCESS; | |
718e3744 | 1951 | |
d62a17ae | 1952 | if (strncmp(argv[idx_in_out]->arg, "in", 2) == 0) { |
1953 | if (PREFIX_NAME_IN(area)) | |
1954 | if (strcmp(PREFIX_NAME_IN(area), argv[idx_word]->arg) | |
1955 | != 0) | |
1956 | return CMD_SUCCESS; | |
718e3744 | 1957 | |
d62a17ae | 1958 | PREFIX_LIST_IN(area) = NULL; |
1959 | if (PREFIX_NAME_IN(area)) | |
1960 | free(PREFIX_NAME_IN(area)); | |
718e3744 | 1961 | |
d62a17ae | 1962 | PREFIX_NAME_IN(area) = NULL; |
718e3744 | 1963 | |
d62a17ae | 1964 | ospf_schedule_abr_task(ospf); |
1965 | } else { | |
1966 | if (PREFIX_NAME_OUT(area)) | |
1967 | if (strcmp(PREFIX_NAME_OUT(area), argv[idx_word]->arg) | |
1968 | != 0) | |
1969 | return CMD_SUCCESS; | |
718e3744 | 1970 | |
d62a17ae | 1971 | PREFIX_LIST_OUT(area) = NULL; |
1972 | if (PREFIX_NAME_OUT(area)) | |
1973 | free(PREFIX_NAME_OUT(area)); | |
718e3744 | 1974 | |
d62a17ae | 1975 | PREFIX_NAME_OUT(area) = NULL; |
718e3744 | 1976 | |
d62a17ae | 1977 | ospf_schedule_abr_task(ospf); |
1978 | } | |
1979 | ||
1980 | return CMD_SUCCESS; | |
718e3744 | 1981 | } |
1982 | ||
6b0655a2 | 1983 | |
a2c62831 | 1984 | DEFUN (ospf_area_authentication_message_digest, |
1985 | ospf_area_authentication_message_digest_cmd, | |
32573073 QY |
1986 | "[no] area <A.B.C.D|(0-4294967295)> authentication message-digest", |
1987 | NO_STR | |
718e3744 | 1988 | "OSPF area parameters\n" |
2b00515a CF |
1989 | "OSPF area ID in IP address format\n" |
1990 | "OSPF area ID as a decimal value\n" | |
718e3744 | 1991 | "Enable authentication\n" |
1992 | "Use message-digest authentication\n") | |
1993 | { | |
a3d826f0 | 1994 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
ca19319b | 1995 | int idx = 0; |
d62a17ae | 1996 | struct ospf_area *area; |
1997 | struct in_addr area_id; | |
1998 | int format; | |
718e3744 | 1999 | |
ca19319b | 2000 | argv_find(argv, argc, "area", &idx); |
2001 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx + 1]->arg); | |
718e3744 | 2002 | |
d62a17ae | 2003 | area = ospf_area_get(ospf, area_id); |
2004 | ospf_area_display_format_set(ospf, area, format); | |
996c9314 LB |
2005 | area->auth_type = strmatch(argv[0]->text, "no") |
2006 | ? OSPF_AUTH_NULL | |
2007 | : OSPF_AUTH_CRYPTOGRAPHIC; | |
718e3744 | 2008 | |
d62a17ae | 2009 | return CMD_SUCCESS; |
718e3744 | 2010 | } |
2011 | ||
a2c62831 | 2012 | DEFUN (ospf_area_authentication, |
2013 | ospf_area_authentication_cmd, | |
6147e2c6 | 2014 | "area <A.B.C.D|(0-4294967295)> authentication", |
718e3744 | 2015 | "OSPF area parameters\n" |
2016 | "OSPF area ID in IP address format\n" | |
2017 | "OSPF area ID as a decimal value\n" | |
2018 | "Enable authentication\n") | |
2019 | { | |
a3d826f0 | 2020 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2021 | int idx_ipv4_number = 1; |
2022 | struct ospf_area *area; | |
2023 | struct in_addr area_id; | |
2024 | int format; | |
718e3744 | 2025 | |
d62a17ae | 2026 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
718e3744 | 2027 | |
d62a17ae | 2028 | area = ospf_area_get(ospf, area_id); |
2029 | ospf_area_display_format_set(ospf, area, format); | |
2030 | area->auth_type = OSPF_AUTH_SIMPLE; | |
718e3744 | 2031 | |
d62a17ae | 2032 | return CMD_SUCCESS; |
718e3744 | 2033 | } |
2034 | ||
a2c62831 | 2035 | DEFUN (no_ospf_area_authentication, |
2036 | no_ospf_area_authentication_cmd, | |
6147e2c6 | 2037 | "no area <A.B.C.D|(0-4294967295)> authentication", |
718e3744 | 2038 | NO_STR |
2039 | "OSPF area parameters\n" | |
2040 | "OSPF area ID in IP address format\n" | |
2041 | "OSPF area ID as a decimal value\n" | |
2042 | "Enable authentication\n") | |
2043 | { | |
a3d826f0 | 2044 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2045 | int idx_ipv4_number = 2; |
2046 | struct ospf_area *area; | |
2047 | struct in_addr area_id; | |
2048 | int format; | |
718e3744 | 2049 | |
d62a17ae | 2050 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
718e3744 | 2051 | |
d62a17ae | 2052 | area = ospf_area_lookup_by_area_id(ospf, area_id); |
2053 | if (area == NULL) | |
2054 | return CMD_SUCCESS; | |
718e3744 | 2055 | |
d62a17ae | 2056 | area->auth_type = OSPF_AUTH_NULL; |
718e3744 | 2057 | |
d62a17ae | 2058 | ospf_area_check_free(ospf, area_id); |
2059 | ||
2060 | return CMD_SUCCESS; | |
718e3744 | 2061 | } |
2062 | ||
6b0655a2 | 2063 | |
718e3744 | 2064 | DEFUN (ospf_abr_type, |
2065 | ospf_abr_type_cmd, | |
6147e2c6 | 2066 | "ospf abr-type <cisco|ibm|shortcut|standard>", |
718e3744 | 2067 | "OSPF specific commands\n" |
2068 | "Set OSPF ABR type\n" | |
2069 | "Alternative ABR, cisco implementation\n" | |
2070 | "Alternative ABR, IBM implementation\n" | |
2071 | "Shortcut ABR\n" | |
2072 | "Standard behavior (RFC2328)\n") | |
2073 | { | |
a3d826f0 | 2074 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2075 | int idx_vendor = 2; |
d7c0a89a | 2076 | uint8_t abr_type = OSPF_ABR_UNKNOWN; |
d62a17ae | 2077 | |
2078 | if (strncmp(argv[idx_vendor]->arg, "c", 1) == 0) | |
2079 | abr_type = OSPF_ABR_CISCO; | |
2080 | else if (strncmp(argv[idx_vendor]->arg, "i", 1) == 0) | |
2081 | abr_type = OSPF_ABR_IBM; | |
2082 | else if (strncmp(argv[idx_vendor]->arg, "sh", 2) == 0) | |
2083 | abr_type = OSPF_ABR_SHORTCUT; | |
2084 | else if (strncmp(argv[idx_vendor]->arg, "st", 2) == 0) | |
2085 | abr_type = OSPF_ABR_STAND; | |
2086 | else | |
2087 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 2088 | |
d62a17ae | 2089 | /* If ABR type value is changed, schedule ABR task. */ |
2090 | if (ospf->abr_type != abr_type) { | |
2091 | ospf->abr_type = abr_type; | |
2092 | ospf_schedule_abr_task(ospf); | |
2093 | } | |
2094 | ||
2095 | return CMD_SUCCESS; | |
718e3744 | 2096 | } |
2097 | ||
2098 | DEFUN (no_ospf_abr_type, | |
2099 | no_ospf_abr_type_cmd, | |
6147e2c6 | 2100 | "no ospf abr-type <cisco|ibm|shortcut|standard>", |
718e3744 | 2101 | NO_STR |
2102 | "OSPF specific commands\n" | |
2103 | "Set OSPF ABR type\n" | |
2104 | "Alternative ABR, cisco implementation\n" | |
2105 | "Alternative ABR, IBM implementation\n" | |
3a2d747c QY |
2106 | "Shortcut ABR\n" |
2107 | "Standard ABR\n") | |
718e3744 | 2108 | { |
a3d826f0 | 2109 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2110 | int idx_vendor = 3; |
d7c0a89a | 2111 | uint8_t abr_type = OSPF_ABR_UNKNOWN; |
d62a17ae | 2112 | |
2113 | if (strncmp(argv[idx_vendor]->arg, "c", 1) == 0) | |
2114 | abr_type = OSPF_ABR_CISCO; | |
2115 | else if (strncmp(argv[idx_vendor]->arg, "i", 1) == 0) | |
2116 | abr_type = OSPF_ABR_IBM; | |
2117 | else if (strncmp(argv[idx_vendor]->arg, "sh", 2) == 0) | |
2118 | abr_type = OSPF_ABR_SHORTCUT; | |
2119 | else if (strncmp(argv[idx_vendor]->arg, "st", 2) == 0) | |
2120 | abr_type = OSPF_ABR_STAND; | |
2121 | else | |
2122 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 2123 | |
d62a17ae | 2124 | /* If ABR type value is changed, schedule ABR task. */ |
2125 | if (ospf->abr_type == abr_type) { | |
2126 | ospf->abr_type = OSPF_ABR_DEFAULT; | |
2127 | ospf_schedule_abr_task(ospf); | |
2128 | } | |
2129 | ||
2130 | return CMD_SUCCESS; | |
718e3744 | 2131 | } |
2132 | ||
d7e60dd7 AS |
2133 | DEFUN (ospf_log_adjacency_changes, |
2134 | ospf_log_adjacency_changes_cmd, | |
2135 | "log-adjacency-changes", | |
2136 | "Log changes in adjacency state\n") | |
2137 | { | |
a3d826f0 | 2138 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d7e60dd7 | 2139 | |
d62a17ae | 2140 | SET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES); |
2141 | UNSET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL); | |
2142 | return CMD_SUCCESS; | |
d7e60dd7 AS |
2143 | } |
2144 | ||
2145 | DEFUN (ospf_log_adjacency_changes_detail, | |
2146 | ospf_log_adjacency_changes_detail_cmd, | |
2147 | "log-adjacency-changes detail", | |
2148 | "Log changes in adjacency state\n" | |
2149 | "Log all state changes\n") | |
2150 | { | |
a3d826f0 | 2151 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d7e60dd7 | 2152 | |
d62a17ae | 2153 | SET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES); |
2154 | SET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL); | |
2155 | return CMD_SUCCESS; | |
d7e60dd7 AS |
2156 | } |
2157 | ||
2158 | DEFUN (no_ospf_log_adjacency_changes, | |
2159 | no_ospf_log_adjacency_changes_cmd, | |
2160 | "no log-adjacency-changes", | |
2161 | NO_STR | |
2162 | "Log changes in adjacency state\n") | |
2163 | { | |
a3d826f0 | 2164 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d7e60dd7 | 2165 | |
d62a17ae | 2166 | UNSET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL); |
2167 | UNSET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES); | |
2168 | return CMD_SUCCESS; | |
d7e60dd7 AS |
2169 | } |
2170 | ||
2171 | DEFUN (no_ospf_log_adjacency_changes_detail, | |
2172 | no_ospf_log_adjacency_changes_detail_cmd, | |
2173 | "no log-adjacency-changes detail", | |
2174 | NO_STR | |
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 | UNSET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL); |
2181 | return CMD_SUCCESS; | |
d7e60dd7 AS |
2182 | } |
2183 | ||
718e3744 | 2184 | DEFUN (ospf_compatible_rfc1583, |
2185 | ospf_compatible_rfc1583_cmd, | |
2186 | "compatible rfc1583", | |
2187 | "OSPF compatibility list\n" | |
2188 | "compatible with RFC 1583\n") | |
2189 | { | |
a3d826f0 | 2190 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
718e3744 | 2191 | |
d62a17ae | 2192 | if (!CHECK_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE)) { |
2193 | SET_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE); | |
2194 | ospf_spf_calculate_schedule(ospf, SPF_FLAG_CONFIG_CHANGE); | |
2195 | } | |
2196 | return CMD_SUCCESS; | |
718e3744 | 2197 | } |
2198 | ||
2199 | DEFUN (no_ospf_compatible_rfc1583, | |
2200 | no_ospf_compatible_rfc1583_cmd, | |
2201 | "no compatible rfc1583", | |
2202 | NO_STR | |
2203 | "OSPF compatibility list\n" | |
2204 | "compatible with RFC 1583\n") | |
2205 | { | |
a3d826f0 | 2206 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
718e3744 | 2207 | |
d62a17ae | 2208 | if (CHECK_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE)) { |
2209 | UNSET_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE); | |
2210 | ospf_spf_calculate_schedule(ospf, SPF_FLAG_CONFIG_CHANGE); | |
2211 | } | |
2212 | return CMD_SUCCESS; | |
718e3744 | 2213 | } |
2214 | ||
d62a17ae | 2215 | ALIAS(ospf_compatible_rfc1583, ospf_rfc1583_flag_cmd, |
2216 | "ospf rfc1583compatibility", | |
2217 | "OSPF specific commands\n" | |
2218 | "Enable the RFC1583Compatibility flag\n") | |
718e3744 | 2219 | |
d62a17ae | 2220 | ALIAS(no_ospf_compatible_rfc1583, no_ospf_rfc1583_flag_cmd, |
9d303b37 | 2221 | "no ospf rfc1583compatibility", NO_STR |
d62a17ae | 2222 | "OSPF specific commands\n" |
2223 | "Disable the RFC1583Compatibility flag\n") | |
6b0655a2 | 2224 | |
d62a17ae | 2225 | static int ospf_timers_spf_set(struct vty *vty, unsigned int delay, |
2226 | unsigned int hold, unsigned int max) | |
d24f6e2a | 2227 | { |
a3d826f0 | 2228 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
7c8ff89e | 2229 | |
d62a17ae | 2230 | ospf->spf_delay = delay; |
2231 | ospf->spf_holdtime = hold; | |
2232 | ospf->spf_max_holdtime = max; | |
2233 | ||
2234 | return CMD_SUCCESS; | |
d24f6e2a | 2235 | } |
718e3744 | 2236 | |
ac7424f9 MR |
2237 | DEFUN (ospf_timers_min_ls_interval, |
2238 | ospf_timers_min_ls_interval_cmd, | |
6147e2c6 | 2239 | "timers throttle lsa all (0-5000)", |
ac7424f9 MR |
2240 | "Adjust routing timers\n" |
2241 | "Throttling adaptive timer\n" | |
2242 | "LSA delay between transmissions\n" | |
813d4307 | 2243 | "All LSA types\n" |
ac7424f9 MR |
2244 | "Delay (msec) between sending LSAs\n") |
2245 | { | |
a3d826f0 | 2246 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2247 | int idx_number = 4; |
2248 | unsigned int interval; | |
ac7424f9 | 2249 | |
d62a17ae | 2250 | if (argc < 5) { |
2251 | vty_out(vty, "Insufficient arguments\n"); | |
2252 | return CMD_WARNING_CONFIG_FAILED; | |
2253 | } | |
ac7424f9 | 2254 | |
d62a17ae | 2255 | interval = strtoul(argv[idx_number]->arg, NULL, 10); |
ac7424f9 | 2256 | |
d62a17ae | 2257 | ospf->min_ls_interval = interval; |
ac7424f9 | 2258 | |
d62a17ae | 2259 | return CMD_SUCCESS; |
ac7424f9 MR |
2260 | } |
2261 | ||
2262 | DEFUN (no_ospf_timers_min_ls_interval, | |
2263 | no_ospf_timers_min_ls_interval_cmd, | |
7a7be519 | 2264 | "no timers throttle lsa all [(0-5000)]", |
ac7424f9 MR |
2265 | NO_STR |
2266 | "Adjust routing timers\n" | |
2267 | "Throttling adaptive timer\n" | |
813d4307 | 2268 | "LSA delay between transmissions\n" |
7a7be519 | 2269 | "All LSA types\n" |
2270 | "Delay (msec) between sending LSAs\n") | |
ac7424f9 | 2271 | { |
a3d826f0 | 2272 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2273 | ospf->min_ls_interval = OSPF_MIN_LS_INTERVAL; |
ac7424f9 | 2274 | |
d62a17ae | 2275 | return CMD_SUCCESS; |
ac7424f9 MR |
2276 | } |
2277 | ||
d24f6e2a | 2278 | DEFUN (ospf_timers_throttle_spf, |
2279 | ospf_timers_throttle_spf_cmd, | |
6147e2c6 | 2280 | "timers throttle spf (0-600000) (0-600000) (0-600000)", |
d24f6e2a | 2281 | "Adjust routing timers\n" |
2282 | "Throttling adaptive timer\n" | |
2283 | "OSPF SPF timers\n" | |
2284 | "Delay (msec) from first change received till SPF calculation\n" | |
2285 | "Initial hold time (msec) between consecutive SPF calculations\n" | |
2286 | "Maximum hold time (msec)\n") | |
2287 | { | |
d62a17ae | 2288 | int idx_number = 3; |
2289 | int idx_number_2 = 4; | |
2290 | int idx_number_3 = 5; | |
2291 | unsigned int delay, hold, max; | |
2292 | ||
2293 | if (argc < 6) { | |
2294 | vty_out(vty, "Insufficient arguments\n"); | |
2295 | return CMD_WARNING_CONFIG_FAILED; | |
2296 | } | |
2297 | ||
2298 | delay = strtoul(argv[idx_number]->arg, NULL, 10); | |
2299 | hold = strtoul(argv[idx_number_2]->arg, NULL, 10); | |
2300 | max = strtoul(argv[idx_number_3]->arg, NULL, 10); | |
2301 | ||
2302 | return ospf_timers_spf_set(vty, delay, hold, max); | |
d24f6e2a | 2303 | } |
2304 | ||
d24f6e2a | 2305 | DEFUN (no_ospf_timers_throttle_spf, |
2306 | no_ospf_timers_throttle_spf_cmd, | |
7a7be519 | 2307 | "no timers throttle spf [(0-600000)(0-600000)(0-600000)]", |
718e3744 | 2308 | NO_STR |
2309 | "Adjust routing timers\n" | |
d24f6e2a | 2310 | "Throttling adaptive timer\n" |
7a7be519 | 2311 | "OSPF SPF timers\n" |
2312 | "Delay (msec) from first change received till SPF calculation\n" | |
2313 | "Initial hold time (msec) between consecutive SPF calculations\n" | |
2314 | "Maximum hold time (msec)\n") | |
22b27e95 | 2315 | { |
d62a17ae | 2316 | return ospf_timers_spf_set(vty, OSPF_SPF_DELAY_DEFAULT, |
2317 | OSPF_SPF_HOLDTIME_DEFAULT, | |
2318 | OSPF_SPF_MAX_HOLDTIME_DEFAULT); | |
718e3744 | 2319 | } |
2320 | ||
b4a039bf | 2321 | |
0e88de35 QY |
2322 | DEFUN (ospf_timers_lsa_min_arrival, |
2323 | ospf_timers_lsa_min_arrival_cmd, | |
6147e2c6 | 2324 | "timers lsa min-arrival (0-600000)", |
b6927875 DS |
2325 | "Adjust routing timers\n" |
2326 | "OSPF LSA timers\n" | |
2327 | "Minimum delay in receiving new version of a LSA\n" | |
2328 | "Delay in milliseconds\n") | |
2329 | { | |
a3d826f0 | 2330 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
0e88de35 | 2331 | ospf->min_ls_arrival = strtoul(argv[argc - 1]->arg, NULL, 10); |
d62a17ae | 2332 | return CMD_SUCCESS; |
b6927875 DS |
2333 | } |
2334 | ||
0e88de35 QY |
2335 | DEFUN (no_ospf_timers_lsa_min_arrival, |
2336 | no_ospf_timers_lsa_min_arrival_cmd, | |
7a7be519 | 2337 | "no timers lsa min-arrival [(0-600000)]", |
b6927875 DS |
2338 | NO_STR |
2339 | "Adjust routing timers\n" | |
2340 | "OSPF LSA timers\n" | |
7a7be519 | 2341 | "Minimum delay in receiving new version of a LSA\n" |
2342 | "Delay in milliseconds\n") | |
b6927875 | 2343 | { |
a3d826f0 | 2344 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2345 | unsigned int minarrival; |
b6927875 | 2346 | |
d62a17ae | 2347 | if (argc > 4) { |
0e88de35 | 2348 | minarrival = strtoul(argv[argc - 1]->arg, NULL, 10); |
b6927875 | 2349 | |
d62a17ae | 2350 | if (ospf->min_ls_arrival != minarrival |
2351 | || minarrival == OSPF_MIN_LS_ARRIVAL) | |
2352 | return CMD_SUCCESS; | |
2353 | } | |
b6927875 | 2354 | |
d62a17ae | 2355 | ospf->min_ls_arrival = OSPF_MIN_LS_ARRIVAL; |
b6927875 | 2356 | |
d62a17ae | 2357 | return CMD_SUCCESS; |
b6927875 DS |
2358 | } |
2359 | ||
a2c62831 | 2360 | DEFUN (ospf_neighbor, |
2361 | ospf_neighbor_cmd, | |
7a7be519 | 2362 | "neighbor A.B.C.D [priority (0-255) [poll-interval (1-65535)]]", |
718e3744 | 2363 | NEIGHBOR_STR |
7a7be519 | 2364 | "Neighbor IP address\n" |
2365 | "Neighbor Priority\n" | |
2366 | "Priority\n" | |
2367 | "Dead Neighbor Polling interval\n" | |
2368 | "Seconds\n") | |
718e3744 | 2369 | { |
a3d826f0 | 2370 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2371 | int idx_ipv4 = 1; |
2372 | int idx_pri = 3; | |
2373 | int idx_poll = 5; | |
2374 | struct in_addr nbr_addr; | |
2375 | unsigned int priority = OSPF_NEIGHBOR_PRIORITY_DEFAULT; | |
2376 | unsigned int interval = OSPF_POLL_INTERVAL_DEFAULT; | |
718e3744 | 2377 | |
cc9b06ad DS |
2378 | if (!inet_aton(argv[idx_ipv4]->arg, &nbr_addr)) { |
2379 | vty_out(vty, "Please specify Neighbor ID by A.B.C.D\n"); | |
2380 | return CMD_WARNING_CONFIG_FAILED; | |
2381 | } | |
718e3744 | 2382 | |
d62a17ae | 2383 | if (argc > 2) |
2384 | priority = strtoul(argv[idx_pri]->arg, NULL, 10); | |
7a7be519 | 2385 | |
d62a17ae | 2386 | if (argc > 4) |
2387 | interval = strtoul(argv[idx_poll]->arg, NULL, 10); | |
718e3744 | 2388 | |
d62a17ae | 2389 | ospf_nbr_nbma_set(ospf, nbr_addr); |
7a7be519 | 2390 | |
d62a17ae | 2391 | if (argc > 2) |
2392 | ospf_nbr_nbma_priority_set(ospf, nbr_addr, priority); | |
7a7be519 | 2393 | |
d62a17ae | 2394 | if (argc > 4) |
2395 | ospf_nbr_nbma_poll_interval_set(ospf, nbr_addr, interval); | |
718e3744 | 2396 | |
d62a17ae | 2397 | return CMD_SUCCESS; |
718e3744 | 2398 | } |
2399 | ||
a2c62831 | 2400 | DEFUN (ospf_neighbor_poll_interval, |
2401 | ospf_neighbor_poll_interval_cmd, | |
7a7be519 | 2402 | "neighbor A.B.C.D poll-interval (1-65535) [priority (0-255)]", |
718e3744 | 2403 | NEIGHBOR_STR |
2404 | "Neighbor IP address\n" | |
2405 | "Dead Neighbor Polling interval\n" | |
7a7be519 | 2406 | "Seconds\n" |
2407 | "OSPF priority of non-broadcast neighbor\n" | |
2408 | "Priority\n") | |
22b27e95 | 2409 | { |
a3d826f0 | 2410 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2411 | int idx_ipv4 = 1; |
2412 | int idx_poll = 3; | |
2413 | int idx_pri = 5; | |
2414 | struct in_addr nbr_addr; | |
a2b6e694 | 2415 | unsigned int priority; |
2416 | unsigned int interval; | |
718e3744 | 2417 | |
cc9b06ad DS |
2418 | if (!inet_aton(argv[idx_ipv4]->arg, &nbr_addr)) { |
2419 | vty_out(vty, "Please specify Neighbor ID by A.B.C.D\n"); | |
2420 | return CMD_WARNING_CONFIG_FAILED; | |
2421 | } | |
718e3744 | 2422 | |
d62a17ae | 2423 | interval = strtoul(argv[idx_poll]->arg, NULL, 10); |
718e3744 | 2424 | |
a2b6e694 | 2425 | priority = argc > 4 ? strtoul(argv[idx_pri]->arg, NULL, 10) |
2426 | : OSPF_NEIGHBOR_PRIORITY_DEFAULT; | |
718e3744 | 2427 | |
d62a17ae | 2428 | ospf_nbr_nbma_set(ospf, nbr_addr); |
2429 | ospf_nbr_nbma_poll_interval_set(ospf, nbr_addr, interval); | |
7a7be519 | 2430 | |
d62a17ae | 2431 | if (argc > 4) |
2432 | ospf_nbr_nbma_priority_set(ospf, nbr_addr, priority); | |
718e3744 | 2433 | |
d62a17ae | 2434 | return CMD_SUCCESS; |
718e3744 | 2435 | } |
2436 | ||
a2c62831 | 2437 | DEFUN (no_ospf_neighbor, |
2438 | no_ospf_neighbor_cmd, | |
7a7be519 | 2439 | "no neighbor A.B.C.D [priority (0-255) [poll-interval (1-65525)]]", |
718e3744 | 2440 | NO_STR |
2441 | NEIGHBOR_STR | |
7a7be519 | 2442 | "Neighbor IP address\n" |
2443 | "Neighbor Priority\n" | |
2444 | "Priority\n" | |
2445 | "Dead Neighbor Polling interval\n" | |
2446 | "Seconds\n") | |
718e3744 | 2447 | { |
a3d826f0 | 2448 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2449 | int idx_ipv4 = 2; |
2450 | struct in_addr nbr_addr; | |
718e3744 | 2451 | |
cc9b06ad DS |
2452 | if (!inet_aton(argv[idx_ipv4]->arg, &nbr_addr)) { |
2453 | vty_out(vty, "Please specify Neighbor ID by A.B.C.D\n"); | |
2454 | return CMD_WARNING_CONFIG_FAILED; | |
2455 | } | |
718e3744 | 2456 | |
d62a17ae | 2457 | (void)ospf_nbr_nbma_unset(ospf, nbr_addr); |
718e3744 | 2458 | |
d62a17ae | 2459 | return CMD_SUCCESS; |
718e3744 | 2460 | } |
2461 | ||
7a7be519 | 2462 | DEFUN (no_ospf_neighbor_poll, |
2463 | no_ospf_neighbor_poll_cmd, | |
2464 | "no neighbor A.B.C.D poll-interval (1-65535) [priority (0-255)]", | |
2465 | NO_STR | |
2466 | NEIGHBOR_STR | |
2467 | "Neighbor IP address\n" | |
2468 | "Dead Neighbor Polling interval\n" | |
2469 | "Seconds\n" | |
2470 | "Neighbor Priority\n" | |
2471 | "Priority\n") | |
2472 | { | |
a3d826f0 | 2473 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2474 | int idx_ipv4 = 2; |
2475 | struct in_addr nbr_addr; | |
7a7be519 | 2476 | |
cc9b06ad DS |
2477 | if (!inet_aton(argv[idx_ipv4]->arg, &nbr_addr)) { |
2478 | vty_out(vty, "Please specify Neighbor ID by A.B.C.D\n"); | |
2479 | return CMD_WARNING_CONFIG_FAILED; | |
2480 | } | |
718e3744 | 2481 | |
d62a17ae | 2482 | (void)ospf_nbr_nbma_unset(ospf, nbr_addr); |
813d4307 | 2483 | |
d62a17ae | 2484 | return CMD_SUCCESS; |
7a7be519 | 2485 | } |
718e3744 | 2486 | |
bf2bfafd DW |
2487 | DEFUN (ospf_refresh_timer, |
2488 | ospf_refresh_timer_cmd, | |
6147e2c6 | 2489 | "refresh timer (10-1800)", |
718e3744 | 2490 | "Adjust refresh parameters\n" |
2491 | "Set refresh timer\n" | |
2492 | "Timer value in seconds\n") | |
2493 | { | |
a3d826f0 | 2494 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2495 | int idx_number = 2; |
2496 | unsigned int interval; | |
7c8ff89e | 2497 | |
d62a17ae | 2498 | interval = strtoul(argv[idx_number]->arg, NULL, 10); |
2499 | interval = (interval / OSPF_LSA_REFRESHER_GRANULARITY) | |
2500 | * OSPF_LSA_REFRESHER_GRANULARITY; | |
718e3744 | 2501 | |
d62a17ae | 2502 | ospf_timers_refresh_set(ospf, interval); |
718e3744 | 2503 | |
d62a17ae | 2504 | return CMD_SUCCESS; |
718e3744 | 2505 | } |
2506 | ||
bf2bfafd DW |
2507 | DEFUN (no_ospf_refresh_timer, |
2508 | no_ospf_refresh_timer_val_cmd, | |
7a7be519 | 2509 | "no refresh timer [(10-1800)]", |
3a2d747c | 2510 | NO_STR |
718e3744 | 2511 | "Adjust refresh parameters\n" |
2512 | "Unset refresh timer\n" | |
2513 | "Timer value in seconds\n") | |
2514 | { | |
a3d826f0 | 2515 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2516 | int idx_number = 3; |
2517 | unsigned int interval; | |
718e3744 | 2518 | |
d62a17ae | 2519 | if (argc == 1) { |
2520 | interval = strtoul(argv[idx_number]->arg, NULL, 10); | |
718e3744 | 2521 | |
d62a17ae | 2522 | if (ospf->lsa_refresh_interval != interval |
2523 | || interval == OSPF_LSA_REFRESH_INTERVAL_DEFAULT) | |
2524 | return CMD_SUCCESS; | |
2525 | } | |
2526 | ||
2527 | ospf_timers_refresh_unset(ospf); | |
2528 | ||
2529 | return CMD_SUCCESS; | |
718e3744 | 2530 | } |
2531 | ||
718e3744 | 2532 | |
a2c62831 | 2533 | DEFUN (ospf_auto_cost_reference_bandwidth, |
2534 | ospf_auto_cost_reference_bandwidth_cmd, | |
6147e2c6 | 2535 | "auto-cost reference-bandwidth (1-4294967)", |
718e3744 | 2536 | "Calculate OSPF interface cost according to bandwidth\n" |
2537 | "Use reference bandwidth method to assign OSPF cost\n" | |
2538 | "The reference bandwidth in terms of Mbits per second\n") | |
2539 | { | |
a3d826f0 | 2540 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
f4e14fdb | 2541 | struct vrf *vrf = vrf_lookup_by_id(ospf->vrf_id); |
d62a17ae | 2542 | int idx_number = 2; |
d7c0a89a | 2543 | uint32_t refbw; |
d62a17ae | 2544 | struct interface *ifp; |
2545 | ||
2546 | refbw = strtol(argv[idx_number]->arg, NULL, 10); | |
2547 | if (refbw < 1 || refbw > 4294967) { | |
2548 | vty_out(vty, "reference-bandwidth value is invalid\n"); | |
2549 | return CMD_WARNING_CONFIG_FAILED; | |
2550 | } | |
2551 | ||
2552 | /* If reference bandwidth is changed. */ | |
2553 | if ((refbw) == ospf->ref_bandwidth) | |
2554 | return CMD_SUCCESS; | |
2555 | ||
2556 | ospf->ref_bandwidth = refbw; | |
451fda4f | 2557 | FOR_ALL_INTERFACES (vrf, ifp) |
d62a17ae | 2558 | ospf_if_recalculate_output_cost(ifp); |
2559 | ||
2560 | return CMD_SUCCESS; | |
718e3744 | 2561 | } |
2562 | ||
a2c62831 | 2563 | DEFUN (no_ospf_auto_cost_reference_bandwidth, |
2564 | no_ospf_auto_cost_reference_bandwidth_cmd, | |
7a7be519 | 2565 | "no auto-cost reference-bandwidth [(1-4294967)]", |
718e3744 | 2566 | NO_STR |
2567 | "Calculate OSPF interface cost according to bandwidth\n" | |
7a7be519 | 2568 | "Use reference bandwidth method to assign OSPF cost\n" |
2569 | "The reference bandwidth in terms of Mbits per second\n") | |
718e3744 | 2570 | { |
a3d826f0 | 2571 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
f4e14fdb | 2572 | struct vrf *vrf = vrf_lookup_by_id(ospf->vrf_id); |
d62a17ae | 2573 | struct interface *ifp; |
718e3744 | 2574 | |
d62a17ae | 2575 | if (ospf->ref_bandwidth == OSPF_DEFAULT_REF_BANDWIDTH) |
2576 | return CMD_SUCCESS; | |
2577 | ||
2578 | ospf->ref_bandwidth = OSPF_DEFAULT_REF_BANDWIDTH; | |
2579 | vty_out(vty, "%% OSPF: Reference bandwidth is changed.\n"); | |
2580 | vty_out(vty, | |
2581 | " Please ensure reference bandwidth is consistent across all routers\n"); | |
2582 | ||
451fda4f | 2583 | FOR_ALL_INTERFACES (vrf, ifp) |
d62a17ae | 2584 | ospf_if_recalculate_output_cost(ifp); |
2585 | ||
2586 | return CMD_SUCCESS; | |
718e3744 | 2587 | } |
2588 | ||
2f8f370e DS |
2589 | DEFUN (ospf_write_multiplier, |
2590 | ospf_write_multiplier_cmd, | |
6147e2c6 | 2591 | "ospf write-multiplier (1-100)", |
e8f45e82 DS |
2592 | "OSPF specific commands\n" |
2593 | "Write multiplier\n" | |
2594 | "Maximum number of interface serviced per write\n") | |
2f8f370e | 2595 | { |
a3d826f0 | 2596 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2597 | int idx_number; |
d7c0a89a | 2598 | uint32_t write_oi_count; |
d62a17ae | 2599 | |
2600 | if (argc == 3) | |
2601 | idx_number = 2; | |
2602 | else | |
2603 | idx_number = 1; | |
2604 | ||
2605 | write_oi_count = strtol(argv[idx_number]->arg, NULL, 10); | |
2606 | if (write_oi_count < 1 || write_oi_count > 100) { | |
2607 | vty_out(vty, "write-multiplier value is invalid\n"); | |
2608 | return CMD_WARNING_CONFIG_FAILED; | |
2609 | } | |
2610 | ||
2611 | ospf->write_oi_count = write_oi_count; | |
2612 | return CMD_SUCCESS; | |
2f8f370e DS |
2613 | } |
2614 | ||
d62a17ae | 2615 | ALIAS(ospf_write_multiplier, write_multiplier_cmd, "write-multiplier (1-100)", |
2616 | "Write multiplier\n" | |
2617 | "Maximum number of interface serviced per write\n") | |
e8f45e82 | 2618 | |
2f8f370e DS |
2619 | DEFUN (no_ospf_write_multiplier, |
2620 | no_ospf_write_multiplier_cmd, | |
6147e2c6 | 2621 | "no ospf write-multiplier (1-100)", |
2f8f370e | 2622 | NO_STR |
e8f45e82 | 2623 | "OSPF specific commands\n" |
813d4307 DW |
2624 | "Write multiplier\n" |
2625 | "Maximum number of interface serviced per write\n") | |
2f8f370e | 2626 | { |
a3d826f0 | 2627 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
2f8f370e | 2628 | |
d62a17ae | 2629 | ospf->write_oi_count = OSPF_WRITE_INTERFACE_COUNT_DEFAULT; |
2630 | return CMD_SUCCESS; | |
2f8f370e DS |
2631 | } |
2632 | ||
d62a17ae | 2633 | ALIAS(no_ospf_write_multiplier, no_write_multiplier_cmd, |
9d303b37 | 2634 | "no write-multiplier (1-100)", NO_STR |
d62a17ae | 2635 | "Write multiplier\n" |
2636 | "Maximum number of interface serviced per write\n") | |
2637 | ||
385a1e07 | 2638 | DEFUN(ospf_ti_lfa, ospf_ti_lfa_cmd, "fast-reroute ti-lfa [node-protection]", |
7fd0729f | 2639 | "Fast Reroute for MPLS and IP resilience\n" |
385a1e07 G |
2640 | "Topology Independent LFA (Loop-Free Alternate)\n" |
2641 | "TI-LFA node protection (default is link protection)\n") | |
7fd0729f G |
2642 | { |
2643 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
2644 | ||
2645 | ospf->ti_lfa_enabled = true; | |
2646 | ||
385a1e07 G |
2647 | if (argc == 3) |
2648 | ospf->ti_lfa_protection_type = OSPF_TI_LFA_NODE_PROTECTION; | |
2649 | else | |
2650 | ospf->ti_lfa_protection_type = OSPF_TI_LFA_LINK_PROTECTION; | |
2651 | ||
7fd0729f G |
2652 | ospf_spf_calculate_schedule(ospf, SPF_FLAG_CONFIG_CHANGE); |
2653 | ||
2654 | return CMD_SUCCESS; | |
2655 | } | |
2656 | ||
385a1e07 G |
2657 | DEFUN(no_ospf_ti_lfa, no_ospf_ti_lfa_cmd, |
2658 | "no fast-reroute ti-lfa [node-protection]", | |
7fd0729f G |
2659 | NO_STR |
2660 | "Fast Reroute for MPLS and IP resilience\n" | |
385a1e07 G |
2661 | "Topology Independent LFA (Loop-Free Alternate)\n" |
2662 | "TI-LFA node protection (default is link protection)\n") | |
7fd0729f G |
2663 | { |
2664 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
2665 | ||
2666 | ospf->ti_lfa_enabled = false; | |
2667 | ||
385a1e07 G |
2668 | ospf->ti_lfa_protection_type = OSPF_TI_LFA_UNDEFINED_PROTECTION; |
2669 | ||
7fd0729f G |
2670 | ospf_spf_calculate_schedule(ospf, SPF_FLAG_CONFIG_CHANGE); |
2671 | ||
2672 | return CMD_SUCCESS; | |
2673 | } | |
2674 | ||
3d5b9855 | 2675 | static void ospf_maxpath_set(struct vty *vty, struct ospf *ospf, uint16_t paths) |
2676 | { | |
2677 | if (ospf->max_multipath == paths) | |
2678 | return; | |
2679 | ||
2680 | ospf->max_multipath = paths; | |
2681 | ||
2682 | /* Send deletion notification to zebra to delete all | |
2683 | * ospf specific routes and reinitiat SPF to reflect | |
2684 | * the new max multipath. | |
2685 | */ | |
2686 | ospf_restart_spf(ospf); | |
2687 | } | |
2688 | ||
2689 | /* Ospf Maximum multiple paths config support */ | |
2690 | DEFUN (ospf_max_multipath, | |
2691 | ospf_max_multipath_cmd, | |
2692 | "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM), | |
2693 | "Max no of multiple paths for ECMP support\n" | |
2694 | "Number of paths\n") | |
2695 | { | |
2696 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
2697 | int idx_number = 1; | |
2698 | uint16_t maxpaths; | |
2699 | ||
2700 | maxpaths = strtol(argv[idx_number]->arg, NULL, 10); | |
2701 | ||
2702 | ospf_maxpath_set(vty, ospf, maxpaths); | |
2703 | return CMD_SUCCESS; | |
2704 | } | |
2705 | ||
2706 | DEFUN (no_ospf_max_multipath, | |
2707 | no_ospf_max_multipath_cmd, | |
2708 | "no maximum-paths", | |
2709 | NO_STR | |
2710 | "Max no of multiple paths for ECMP support\n") | |
2711 | { | |
2712 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
2713 | uint16_t maxpaths = MULTIPATH_NUM; | |
2714 | ||
2715 | ospf_maxpath_set(vty, ospf, maxpaths); | |
2716 | return CMD_SUCCESS; | |
2717 | } | |
2718 | ||
2b64873d DL |
2719 | static const char *const ospf_abr_type_descr_str[] = { |
2720 | "Unknown", "Standard (RFC2328)", "Alternative IBM", | |
2721 | "Alternative Cisco", "Alternative Shortcut" | |
2722 | }; | |
d62a17ae | 2723 | |
2b64873d DL |
2724 | static const char *const ospf_shortcut_mode_descr_str[] = { |
2725 | "Default", "Enabled", "Disabled" | |
2726 | }; | |
d62a17ae | 2727 | |
2728 | static void show_ip_ospf_area(struct vty *vty, struct ospf_area *area, | |
9f049418 | 2729 | json_object *json_areas, bool use_json) |
d62a17ae | 2730 | { |
2731 | json_object *json_area = NULL; | |
96b663a3 | 2732 | char buf[PREFIX_STRLEN]; |
d62a17ae | 2733 | |
2734 | if (use_json) | |
2735 | json_area = json_object_new_object(); | |
2736 | ||
2737 | /* Show Area ID. */ | |
2738 | if (!use_json) | |
96b663a3 | 2739 | vty_out(vty, " Area ID: %pI4", &area->area_id); |
d62a17ae | 2740 | |
2741 | /* Show Area type/mode. */ | |
2742 | if (OSPF_IS_AREA_BACKBONE(area)) { | |
2743 | if (use_json) | |
2744 | json_object_boolean_true_add(json_area, "backbone"); | |
2745 | else | |
2746 | vty_out(vty, " (Backbone)\n"); | |
2747 | } else { | |
2748 | if (use_json) { | |
2749 | if (area->external_routing == OSPF_AREA_STUB) { | |
2750 | if (area->no_summary) | |
2751 | json_object_boolean_true_add( | |
2752 | json_area, "stubNoSummary"); | |
2753 | if (area->shortcut_configured) | |
2754 | json_object_boolean_true_add( | |
2755 | json_area, "stubShortcut"); | |
2756 | } else if (area->external_routing == OSPF_AREA_NSSA) { | |
2757 | if (area->no_summary) | |
2758 | json_object_boolean_true_add( | |
2759 | json_area, "nssaNoSummary"); | |
2760 | if (area->shortcut_configured) | |
2761 | json_object_boolean_true_add( | |
2762 | json_area, "nssaShortcut"); | |
2763 | } | |
813d4307 | 2764 | |
d62a17ae | 2765 | json_object_string_add( |
2766 | json_area, "shortcuttingMode", | |
2767 | ospf_shortcut_mode_descr_str | |
2768 | [area->shortcut_configured]); | |
2769 | if (area->shortcut_capability) | |
2770 | json_object_boolean_true_add(json_area, | |
2771 | "sBitConcensus"); | |
2772 | } else { | |
2773 | if (area->external_routing == OSPF_AREA_STUB) | |
2774 | vty_out(vty, " (Stub%s%s)", | |
2775 | area->no_summary ? ", no summary" : "", | |
2776 | area->shortcut_configured ? "; " : ""); | |
2777 | else if (area->external_routing == OSPF_AREA_NSSA) | |
2778 | vty_out(vty, " (NSSA%s%s)", | |
2779 | area->no_summary ? ", no summary" : "", | |
2780 | area->shortcut_configured ? "; " : ""); | |
2781 | ||
2782 | vty_out(vty, "\n"); | |
2783 | vty_out(vty, " Shortcutting mode: %s", | |
2784 | ospf_shortcut_mode_descr_str | |
2785 | [area->shortcut_configured]); | |
2786 | vty_out(vty, ", S-bit consensus: %s\n", | |
2787 | area->shortcut_capability ? "ok" : "no"); | |
2788 | } | |
2789 | } | |
718e3744 | 2790 | |
d62a17ae | 2791 | /* Show number of interfaces */ |
2792 | if (use_json) { | |
2793 | json_object_int_add(json_area, "areaIfTotalCounter", | |
2794 | listcount(area->oiflist)); | |
2795 | json_object_int_add(json_area, "areaIfActiveCounter", | |
2796 | area->act_ints); | |
2797 | } else | |
2798 | vty_out(vty, | |
3efd0893 | 2799 | " Number of interfaces in this area: Total: %d, Active: %d\n", |
d62a17ae | 2800 | listcount(area->oiflist), area->act_ints); |
2801 | ||
2802 | if (area->external_routing == OSPF_AREA_NSSA) { | |
2803 | if (use_json) { | |
2804 | json_object_boolean_true_add(json_area, "nssa"); | |
2805 | if (!IS_OSPF_ABR(area->ospf)) | |
2806 | json_object_boolean_false_add(json_area, "abr"); | |
2807 | else if (area->NSSATranslatorState) { | |
2808 | json_object_boolean_true_add(json_area, "abr"); | |
2809 | if (area->NSSATranslatorRole | |
2810 | == OSPF_NSSA_ROLE_CANDIDATE) | |
2811 | json_object_boolean_true_add( | |
2812 | json_area, | |
2813 | "nssaTranslatorElected"); | |
2814 | else if (area->NSSATranslatorRole | |
2815 | == OSPF_NSSA_ROLE_ALWAYS) | |
2816 | json_object_boolean_true_add( | |
2817 | json_area, | |
2818 | "nssaTranslatorAlways"); | |
b79c3070 | 2819 | else |
2820 | json_object_boolean_true_add( | |
2821 | json_area, | |
2822 | "nssaTranslatorNever"); | |
d62a17ae | 2823 | } else { |
2824 | json_object_boolean_true_add(json_area, "abr"); | |
2825 | if (area->NSSATranslatorRole | |
2826 | == OSPF_NSSA_ROLE_CANDIDATE) | |
2827 | json_object_boolean_false_add( | |
2828 | json_area, | |
2829 | "nssaTranslatorElected"); | |
2830 | else | |
2831 | json_object_boolean_true_add( | |
2832 | json_area, | |
2833 | "nssaTranslatorNever"); | |
2834 | } | |
2835 | } else { | |
2836 | vty_out(vty, | |
b79c3070 | 2837 | " It is an NSSA configuration.\n Elected NSSA/ABR performs type-7/type-5 LSA translation.\n"); |
d62a17ae | 2838 | if (!IS_OSPF_ABR(area->ospf)) |
2839 | vty_out(vty, | |
b79c3070 | 2840 | " It is not ABR, therefore not Translator.\n"); |
d62a17ae | 2841 | else if (area->NSSATranslatorState) { |
2842 | vty_out(vty, " We are an ABR and "); | |
2843 | if (area->NSSATranslatorRole | |
2844 | == OSPF_NSSA_ROLE_CANDIDATE) | |
2845 | vty_out(vty, | |
b79c3070 | 2846 | "the NSSA Elected Translator.\n"); |
d62a17ae | 2847 | else if (area->NSSATranslatorRole |
2848 | == OSPF_NSSA_ROLE_ALWAYS) | |
2849 | vty_out(vty, | |
b79c3070 | 2850 | "always an NSSA Translator.\n"); |
2851 | else | |
2852 | vty_out(vty, | |
2853 | "never an NSSA Translator.\n"); | |
d62a17ae | 2854 | } else { |
2855 | vty_out(vty, " We are an ABR, but "); | |
2856 | if (area->NSSATranslatorRole | |
2857 | == OSPF_NSSA_ROLE_CANDIDATE) | |
2858 | vty_out(vty, | |
b79c3070 | 2859 | "not the NSSA Elected Translator.\n"); |
d62a17ae | 2860 | else |
2861 | vty_out(vty, | |
b79c3070 | 2862 | "never an NSSA Translator.\n"); |
d62a17ae | 2863 | } |
2864 | } | |
2865 | } | |
2866 | ||
2867 | /* Stub-router state for this area */ | |
2868 | if (CHECK_FLAG(area->stub_router_state, OSPF_AREA_IS_STUB_ROUTED)) { | |
2869 | char timebuf[OSPF_TIME_DUMP_SIZE]; | |
2870 | ||
2871 | if (use_json) { | |
2872 | json_object_boolean_true_add( | |
2873 | json_area, "originStubMaxDistRouterLsa"); | |
2874 | if (CHECK_FLAG(area->stub_router_state, | |
2875 | OSPF_AREA_ADMIN_STUB_ROUTED)) | |
2876 | json_object_boolean_true_add( | |
2877 | json_area, "indefiniteActiveAdmin"); | |
2878 | if (area->t_stub_router) { | |
2879 | long time_store; | |
2880 | time_store = | |
2881 | monotime_until( | |
2882 | &area->t_stub_router->u.sands, | |
2883 | NULL) | |
2884 | / 1000LL; | |
2885 | json_object_int_add( | |
2886 | json_area, | |
2887 | "activeStartupRemainderMsecs", | |
2888 | time_store); | |
2889 | } | |
2890 | } else { | |
2891 | vty_out(vty, | |
2892 | " Originating stub / maximum-distance Router-LSA\n"); | |
2893 | if (CHECK_FLAG(area->stub_router_state, | |
2894 | OSPF_AREA_ADMIN_STUB_ROUTED)) | |
2895 | vty_out(vty, | |
2896 | " Administratively activated (indefinitely)\n"); | |
2897 | if (area->t_stub_router) | |
2898 | vty_out(vty, | |
2899 | " Active from startup, %s remaining\n", | |
2900 | ospf_timer_dump(area->t_stub_router, | |
2901 | timebuf, | |
2902 | sizeof(timebuf))); | |
2903 | } | |
2904 | } | |
2905 | ||
2906 | if (use_json) { | |
2907 | /* Show number of fully adjacent neighbors. */ | |
2908 | json_object_int_add(json_area, "nbrFullAdjacentCounter", | |
2909 | area->full_nbrs); | |
2910 | ||
2911 | /* Show authentication type. */ | |
2912 | if (area->auth_type == OSPF_AUTH_NULL) | |
2913 | json_object_string_add(json_area, "authentication", | |
2914 | "authenticationNone"); | |
2915 | else if (area->auth_type == OSPF_AUTH_SIMPLE) | |
2916 | json_object_string_add(json_area, "authentication", | |
2917 | "authenticationSimplePassword"); | |
2918 | else if (area->auth_type == OSPF_AUTH_CRYPTOGRAPHIC) | |
2919 | json_object_string_add(json_area, "authentication", | |
2920 | "authenticationMessageDigest"); | |
2921 | ||
2922 | if (!OSPF_IS_AREA_BACKBONE(area)) | |
2923 | json_object_int_add(json_area, | |
2924 | "virtualAdjacenciesPassingCounter", | |
2925 | area->full_vls); | |
2926 | ||
2927 | /* Show SPF calculation times. */ | |
2928 | json_object_int_add(json_area, "spfExecutedCounter", | |
2929 | area->spf_calculation); | |
2930 | json_object_int_add(json_area, "lsaNumber", area->lsdb->total); | |
2931 | json_object_int_add( | |
2932 | json_area, "lsaRouterNumber", | |
2933 | ospf_lsdb_count(area->lsdb, OSPF_ROUTER_LSA)); | |
2934 | json_object_int_add( | |
2935 | json_area, "lsaRouterChecksum", | |
2936 | ospf_lsdb_checksum(area->lsdb, OSPF_ROUTER_LSA)); | |
2937 | json_object_int_add( | |
2938 | json_area, "lsaNetworkNumber", | |
2939 | ospf_lsdb_count(area->lsdb, OSPF_NETWORK_LSA)); | |
2940 | json_object_int_add( | |
2941 | json_area, "lsaNetworkChecksum", | |
2942 | ospf_lsdb_checksum(area->lsdb, OSPF_NETWORK_LSA)); | |
2943 | json_object_int_add( | |
2944 | json_area, "lsaSummaryNumber", | |
2945 | ospf_lsdb_count(area->lsdb, OSPF_SUMMARY_LSA)); | |
2946 | json_object_int_add( | |
2947 | json_area, "lsaSummaryChecksum", | |
2948 | ospf_lsdb_checksum(area->lsdb, OSPF_SUMMARY_LSA)); | |
2949 | json_object_int_add( | |
2950 | json_area, "lsaAsbrNumber", | |
2951 | ospf_lsdb_count(area->lsdb, OSPF_ASBR_SUMMARY_LSA)); | |
2952 | json_object_int_add( | |
2953 | json_area, "lsaAsbrChecksum", | |
2954 | ospf_lsdb_checksum(area->lsdb, OSPF_ASBR_SUMMARY_LSA)); | |
2955 | json_object_int_add( | |
2956 | json_area, "lsaNssaNumber", | |
2957 | ospf_lsdb_count(area->lsdb, OSPF_AS_NSSA_LSA)); | |
2958 | json_object_int_add( | |
2959 | json_area, "lsaNssaChecksum", | |
2960 | ospf_lsdb_checksum(area->lsdb, OSPF_AS_NSSA_LSA)); | |
2961 | } else { | |
2962 | /* Show number of fully adjacent neighbors. */ | |
2963 | vty_out(vty, | |
3efd0893 | 2964 | " Number of fully adjacent neighbors in this area: %d\n", |
d62a17ae | 2965 | area->full_nbrs); |
2966 | ||
2967 | /* Show authentication type. */ | |
2968 | vty_out(vty, " Area has "); | |
2969 | if (area->auth_type == OSPF_AUTH_NULL) | |
2970 | vty_out(vty, "no authentication\n"); | |
2971 | else if (area->auth_type == OSPF_AUTH_SIMPLE) | |
2972 | vty_out(vty, "simple password authentication\n"); | |
2973 | else if (area->auth_type == OSPF_AUTH_CRYPTOGRAPHIC) | |
2974 | vty_out(vty, "message digest authentication\n"); | |
2975 | ||
2976 | if (!OSPF_IS_AREA_BACKBONE(area)) | |
2977 | vty_out(vty, | |
3efd0893 | 2978 | " Number of full virtual adjacencies going through this area: %d\n", |
d62a17ae | 2979 | area->full_vls); |
2980 | ||
2981 | /* Show SPF calculation times. */ | |
2982 | vty_out(vty, " SPF algorithm executed %d times\n", | |
2983 | area->spf_calculation); | |
2984 | ||
2985 | /* Show number of LSA. */ | |
2986 | vty_out(vty, " Number of LSA %ld\n", area->lsdb->total); | |
2987 | vty_out(vty, | |
2988 | " Number of router LSA %ld. Checksum Sum 0x%08x\n", | |
2989 | ospf_lsdb_count(area->lsdb, OSPF_ROUTER_LSA), | |
2990 | ospf_lsdb_checksum(area->lsdb, OSPF_ROUTER_LSA)); | |
2991 | vty_out(vty, | |
2992 | " Number of network LSA %ld. Checksum Sum 0x%08x\n", | |
2993 | ospf_lsdb_count(area->lsdb, OSPF_NETWORK_LSA), | |
2994 | ospf_lsdb_checksum(area->lsdb, OSPF_NETWORK_LSA)); | |
2995 | vty_out(vty, | |
2996 | " Number of summary LSA %ld. Checksum Sum 0x%08x\n", | |
2997 | ospf_lsdb_count(area->lsdb, OSPF_SUMMARY_LSA), | |
2998 | ospf_lsdb_checksum(area->lsdb, OSPF_SUMMARY_LSA)); | |
2999 | vty_out(vty, | |
3000 | " Number of ASBR summary LSA %ld. Checksum Sum 0x%08x\n", | |
3001 | ospf_lsdb_count(area->lsdb, OSPF_ASBR_SUMMARY_LSA), | |
3002 | ospf_lsdb_checksum(area->lsdb, OSPF_ASBR_SUMMARY_LSA)); | |
3003 | vty_out(vty, " Number of NSSA LSA %ld. Checksum Sum 0x%08x\n", | |
3004 | ospf_lsdb_count(area->lsdb, OSPF_AS_NSSA_LSA), | |
3005 | ospf_lsdb_checksum(area->lsdb, OSPF_AS_NSSA_LSA)); | |
3006 | } | |
3007 | ||
3008 | if (use_json) { | |
3009 | json_object_int_add( | |
3010 | json_area, "lsaOpaqueLinkNumber", | |
3011 | ospf_lsdb_count(area->lsdb, OSPF_OPAQUE_LINK_LSA)); | |
3012 | json_object_int_add( | |
3013 | json_area, "lsaOpaqueLinkChecksum", | |
3014 | ospf_lsdb_checksum(area->lsdb, OSPF_OPAQUE_LINK_LSA)); | |
3015 | json_object_int_add( | |
3016 | json_area, "lsaOpaqueAreaNumber", | |
3017 | ospf_lsdb_count(area->lsdb, OSPF_OPAQUE_AREA_LSA)); | |
3018 | json_object_int_add( | |
3019 | json_area, "lsaOpaqueAreaChecksum", | |
3020 | ospf_lsdb_checksum(area->lsdb, OSPF_OPAQUE_AREA_LSA)); | |
3021 | } else { | |
3022 | vty_out(vty, | |
3023 | " Number of opaque link LSA %ld. Checksum Sum 0x%08x\n", | |
3024 | ospf_lsdb_count(area->lsdb, OSPF_OPAQUE_LINK_LSA), | |
3025 | ospf_lsdb_checksum(area->lsdb, OSPF_OPAQUE_LINK_LSA)); | |
3026 | vty_out(vty, | |
3027 | " Number of opaque area LSA %ld. Checksum Sum 0x%08x\n", | |
3028 | ospf_lsdb_count(area->lsdb, OSPF_OPAQUE_AREA_LSA), | |
3029 | ospf_lsdb_checksum(area->lsdb, OSPF_OPAQUE_AREA_LSA)); | |
3030 | } | |
718e3744 | 3031 | |
d62a17ae | 3032 | if (use_json) |
96b663a3 MS |
3033 | json_object_object_add(json_areas, |
3034 | inet_ntop(AF_INET, &area->area_id, | |
3035 | buf, sizeof(buf)), | |
d62a17ae | 3036 | json_area); |
3037 | else | |
3038 | vty_out(vty, "\n"); | |
718e3744 | 3039 | } |
3040 | ||
d62a17ae | 3041 | static int show_ip_ospf_common(struct vty *vty, struct ospf *ospf, |
d7c0a89a | 3042 | json_object *json, uint8_t use_vrf) |
d62a17ae | 3043 | { |
3044 | struct listnode *node, *nnode; | |
3045 | struct ospf_area *area; | |
3046 | struct timeval result; | |
3047 | char timebuf[OSPF_TIME_DUMP_SIZE]; | |
96b663a3 | 3048 | char buf[PREFIX_STRLEN]; |
b1c3ae8c | 3049 | json_object *json_vrf = NULL; |
d62a17ae | 3050 | json_object *json_areas = NULL; |
718e3744 | 3051 | |
b1c3ae8c CS |
3052 | if (json) { |
3053 | if (use_vrf) | |
3054 | json_vrf = json_object_new_object(); | |
3055 | else | |
3056 | json_vrf = json; | |
d62a17ae | 3057 | json_areas = json_object_new_object(); |
3058 | } | |
3059 | ||
3060 | if (ospf->instance) { | |
b1c3ae8c | 3061 | if (json) { |
d62a17ae | 3062 | json_object_int_add(json, "ospfInstance", |
3063 | ospf->instance); | |
3064 | } else { | |
3065 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
3066 | } | |
3067 | } | |
3068 | ||
b1c3ae8c | 3069 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); |
87bd50e8 | 3070 | |
d62a17ae | 3071 | /* Show Router ID. */ |
b1c3ae8c CS |
3072 | if (json) { |
3073 | json_object_string_add(json_vrf, "routerId", | |
96b663a3 MS |
3074 | inet_ntop(AF_INET, &ospf->router_id, |
3075 | buf, sizeof(buf))); | |
d62a17ae | 3076 | } else { |
96b663a3 MS |
3077 | vty_out(vty, " OSPF Routing Process, Router ID: %pI4\n", |
3078 | &ospf->router_id); | |
d62a17ae | 3079 | } |
3080 | ||
3081 | /* Graceful shutdown */ | |
3082 | if (ospf->t_deferred_shutdown) { | |
b1c3ae8c | 3083 | if (json) { |
d62a17ae | 3084 | long time_store; |
3085 | time_store = | |
3086 | monotime_until( | |
3087 | &ospf->t_deferred_shutdown->u.sands, | |
3088 | NULL) | |
3089 | / 1000LL; | |
b1c3ae8c | 3090 | json_object_int_add(json_vrf, "deferredShutdownMsecs", |
d62a17ae | 3091 | time_store); |
3092 | } else { | |
3093 | vty_out(vty, | |
3094 | " Deferred shutdown in progress, %s remaining\n", | |
3095 | ospf_timer_dump(ospf->t_deferred_shutdown, | |
3096 | timebuf, sizeof(timebuf))); | |
3097 | } | |
3098 | } | |
3099 | ||
3100 | /* Show capability. */ | |
b1c3ae8c CS |
3101 | if (json) { |
3102 | json_object_boolean_true_add(json_vrf, "tosRoutesOnly"); | |
3103 | json_object_boolean_true_add(json_vrf, "rfc2328Conform"); | |
d62a17ae | 3104 | if (CHECK_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE)) { |
b1c3ae8c | 3105 | json_object_boolean_true_add(json_vrf, |
d62a17ae | 3106 | "rfc1583Compatibility"); |
3107 | } | |
3108 | } else { | |
3109 | vty_out(vty, " Supports only single TOS (TOS0) routes\n"); | |
3110 | vty_out(vty, " This implementation conforms to RFC2328\n"); | |
3111 | vty_out(vty, " RFC1583Compatibility flag is %s\n", | |
3112 | CHECK_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE) | |
3113 | ? "enabled" | |
3114 | : "disabled"); | |
3115 | } | |
3116 | ||
b1c3ae8c | 3117 | if (json) { |
d62a17ae | 3118 | if (CHECK_FLAG(ospf->config, OSPF_OPAQUE_CAPABLE)) { |
b1c3ae8c | 3119 | json_object_boolean_true_add(json_vrf, "opaqueCapable"); |
d62a17ae | 3120 | } |
3121 | } else { | |
3122 | vty_out(vty, " OpaqueCapability flag is %s\n", | |
3123 | CHECK_FLAG(ospf->config, OSPF_OPAQUE_CAPABLE) | |
3124 | ? "enabled" | |
3125 | : "disabled"); | |
3126 | } | |
3127 | ||
3128 | /* Show stub-router configuration */ | |
3129 | if (ospf->stub_router_startup_time != OSPF_STUB_ROUTER_UNCONFIGURED | |
3130 | || ospf->stub_router_shutdown_time | |
3131 | != OSPF_STUB_ROUTER_UNCONFIGURED) { | |
b1c3ae8c CS |
3132 | if (json) { |
3133 | json_object_boolean_true_add(json_vrf, | |
3134 | "stubAdvertisement"); | |
d62a17ae | 3135 | if (ospf->stub_router_startup_time |
3136 | != OSPF_STUB_ROUTER_UNCONFIGURED) | |
3137 | json_object_int_add( | |
50ad4b42 MS |
3138 | json_vrf, "postStartEnabledSecs", |
3139 | ospf->stub_router_startup_time); | |
d62a17ae | 3140 | if (ospf->stub_router_shutdown_time |
3141 | != OSPF_STUB_ROUTER_UNCONFIGURED) | |
3142 | json_object_int_add( | |
50ad4b42 MS |
3143 | json_vrf, "preShutdownEnabledSecs", |
3144 | ospf->stub_router_shutdown_time); | |
d62a17ae | 3145 | } else { |
3146 | vty_out(vty, | |
3147 | " Stub router advertisement is configured\n"); | |
3148 | if (ospf->stub_router_startup_time | |
3149 | != OSPF_STUB_ROUTER_UNCONFIGURED) | |
3150 | vty_out(vty, | |
3151 | " Enabled for %us after start-up\n", | |
3152 | ospf->stub_router_startup_time); | |
3153 | if (ospf->stub_router_shutdown_time | |
3154 | != OSPF_STUB_ROUTER_UNCONFIGURED) | |
3155 | vty_out(vty, | |
3156 | " Enabled for %us prior to full shutdown\n", | |
3157 | ospf->stub_router_shutdown_time); | |
3158 | } | |
3159 | } | |
3160 | ||
3161 | /* Show SPF timers. */ | |
b1c3ae8c CS |
3162 | if (json) { |
3163 | json_object_int_add(json_vrf, "spfScheduleDelayMsecs", | |
d62a17ae | 3164 | ospf->spf_delay); |
b1c3ae8c | 3165 | json_object_int_add(json_vrf, "holdtimeMinMsecs", |
d62a17ae | 3166 | ospf->spf_holdtime); |
b1c3ae8c | 3167 | json_object_int_add(json_vrf, "holdtimeMaxMsecs", |
d62a17ae | 3168 | ospf->spf_max_holdtime); |
b1c3ae8c | 3169 | json_object_int_add(json_vrf, "holdtimeMultplier", |
d62a17ae | 3170 | ospf->spf_hold_multiplier); |
3171 | } else { | |
3172 | vty_out(vty, | |
3173 | " Initial SPF scheduling delay %d millisec(s)\n" | |
3174 | " Minimum hold time between consecutive SPFs %d millisec(s)\n" | |
3175 | " Maximum hold time between consecutive SPFs %d millisec(s)\n" | |
3176 | " Hold time multiplier is currently %d\n", | |
3177 | ospf->spf_delay, ospf->spf_holdtime, | |
3178 | ospf->spf_max_holdtime, ospf->spf_hold_multiplier); | |
3179 | } | |
3180 | ||
b1c3ae8c | 3181 | if (json) { |
d62a17ae | 3182 | if (ospf->ts_spf.tv_sec || ospf->ts_spf.tv_usec) { |
3183 | long time_store = 0; | |
3184 | ||
3185 | time_store = | |
3186 | monotime_since(&ospf->ts_spf, NULL) / 1000LL; | |
b1c3ae8c | 3187 | json_object_int_add(json_vrf, "spfLastExecutedMsecs", |
d62a17ae | 3188 | time_store); |
3189 | ||
3190 | time_store = (1000 * ospf->ts_spf_duration.tv_sec) | |
3191 | + (ospf->ts_spf_duration.tv_usec / 1000); | |
b1c3ae8c | 3192 | json_object_int_add(json_vrf, "spfLastDurationMsecs", |
d62a17ae | 3193 | time_store); |
3194 | } else | |
b1c3ae8c | 3195 | json_object_boolean_true_add(json_vrf, "spfHasNotRun"); |
d62a17ae | 3196 | } else { |
3197 | vty_out(vty, " SPF algorithm "); | |
3198 | if (ospf->ts_spf.tv_sec || ospf->ts_spf.tv_usec) { | |
3199 | monotime_since(&ospf->ts_spf, &result); | |
3200 | vty_out(vty, "last executed %s ago\n", | |
3201 | ospf_timeval_dump(&result, timebuf, | |
3202 | sizeof(timebuf))); | |
3203 | vty_out(vty, " Last SPF duration %s\n", | |
3204 | ospf_timeval_dump(&ospf->ts_spf_duration, | |
3205 | timebuf, sizeof(timebuf))); | |
3206 | } else | |
3207 | vty_out(vty, "has not been run\n"); | |
3208 | } | |
3209 | ||
b1c3ae8c | 3210 | if (json) { |
d62a17ae | 3211 | if (ospf->t_spf_calc) { |
3212 | long time_store; | |
3213 | time_store = | |
3214 | monotime_until(&ospf->t_spf_calc->u.sands, NULL) | |
3215 | / 1000LL; | |
b1c3ae8c | 3216 | json_object_int_add(json_vrf, "spfTimerDueInMsecs", |
d62a17ae | 3217 | time_store); |
3218 | } | |
3219 | ||
b1c3ae8c | 3220 | json_object_int_add(json_vrf, "lsaMinIntervalMsecs", |
d62a17ae | 3221 | ospf->min_ls_interval); |
b1c3ae8c | 3222 | json_object_int_add(json_vrf, "lsaMinArrivalMsecs", |
d62a17ae | 3223 | ospf->min_ls_arrival); |
3224 | /* Show write multiplier values */ | |
b1c3ae8c | 3225 | json_object_int_add(json_vrf, "writeMultiplier", |
d62a17ae | 3226 | ospf->write_oi_count); |
3227 | /* Show refresh parameters. */ | |
b1c3ae8c | 3228 | json_object_int_add(json_vrf, "refreshTimerMsecs", |
d62a17ae | 3229 | ospf->lsa_refresh_interval * 1000); |
3230 | } else { | |
3231 | vty_out(vty, " SPF timer %s%s\n", | |
3232 | (ospf->t_spf_calc ? "due in " : "is "), | |
3233 | ospf_timer_dump(ospf->t_spf_calc, timebuf, | |
3234 | sizeof(timebuf))); | |
3235 | ||
3236 | vty_out(vty, " LSA minimum interval %d msecs\n", | |
3237 | ospf->min_ls_interval); | |
3238 | vty_out(vty, " LSA minimum arrival %d msecs\n", | |
3239 | ospf->min_ls_arrival); | |
3240 | ||
3241 | /* Show write multiplier values */ | |
3242 | vty_out(vty, " Write Multiplier set to %d \n", | |
3243 | ospf->write_oi_count); | |
3244 | ||
3245 | /* Show refresh parameters. */ | |
3246 | vty_out(vty, " Refresh timer %d secs\n", | |
3247 | ospf->lsa_refresh_interval); | |
3d5b9855 | 3248 | |
3249 | /* show max multipath */ | |
3250 | vty_out(vty, " Maximum multiple paths(ECMP) supported %d\n", | |
3251 | ospf->max_multipath); | |
d62a17ae | 3252 | } |
3253 | ||
3254 | /* Show ABR/ASBR flags. */ | |
3255 | if (CHECK_FLAG(ospf->flags, OSPF_FLAG_ABR)) { | |
b1c3ae8c | 3256 | if (json) |
d62a17ae | 3257 | json_object_string_add( |
b1c3ae8c | 3258 | json_vrf, "abrType", |
d62a17ae | 3259 | ospf_abr_type_descr_str[ospf->abr_type]); |
3260 | else | |
3261 | vty_out(vty, | |
3262 | " This router is an ABR, ABR type is: %s\n", | |
3263 | ospf_abr_type_descr_str[ospf->abr_type]); | |
3264 | } | |
3265 | if (CHECK_FLAG(ospf->flags, OSPF_FLAG_ASBR)) { | |
b1c3ae8c | 3266 | if (json) |
d62a17ae | 3267 | json_object_string_add( |
b1c3ae8c | 3268 | json_vrf, "asbrRouter", |
d62a17ae | 3269 | "injectingExternalRoutingInformation"); |
3270 | else | |
3271 | vty_out(vty, | |
3efd0893 | 3272 | " This router is an ASBR (injecting external routing information)\n"); |
d62a17ae | 3273 | } |
3274 | ||
3275 | /* Show Number of AS-external-LSAs. */ | |
b1c3ae8c | 3276 | if (json) { |
d62a17ae | 3277 | json_object_int_add( |
b1c3ae8c | 3278 | json_vrf, "lsaExternalCounter", |
d62a17ae | 3279 | ospf_lsdb_count(ospf->lsdb, OSPF_AS_EXTERNAL_LSA)); |
3280 | json_object_int_add( | |
b1c3ae8c | 3281 | json_vrf, "lsaExternalChecksum", |
d62a17ae | 3282 | ospf_lsdb_checksum(ospf->lsdb, OSPF_AS_EXTERNAL_LSA)); |
3283 | } else { | |
3284 | vty_out(vty, | |
3285 | " Number of external LSA %ld. Checksum Sum 0x%08x\n", | |
3286 | ospf_lsdb_count(ospf->lsdb, OSPF_AS_EXTERNAL_LSA), | |
3287 | ospf_lsdb_checksum(ospf->lsdb, OSPF_AS_EXTERNAL_LSA)); | |
3288 | } | |
3289 | ||
b1c3ae8c | 3290 | if (json) { |
d62a17ae | 3291 | json_object_int_add( |
b1c3ae8c | 3292 | json_vrf, "lsaAsopaqueCounter", |
d62a17ae | 3293 | ospf_lsdb_count(ospf->lsdb, OSPF_OPAQUE_AS_LSA)); |
3294 | json_object_int_add( | |
b1c3ae8c | 3295 | json_vrf, "lsaAsOpaqueChecksum", |
d62a17ae | 3296 | ospf_lsdb_checksum(ospf->lsdb, OSPF_OPAQUE_AS_LSA)); |
3297 | } else { | |
3298 | vty_out(vty, | |
3299 | " Number of opaque AS LSA %ld. Checksum Sum 0x%08x\n", | |
3300 | ospf_lsdb_count(ospf->lsdb, OSPF_OPAQUE_AS_LSA), | |
3301 | ospf_lsdb_checksum(ospf->lsdb, OSPF_OPAQUE_AS_LSA)); | |
3302 | } | |
3303 | ||
3304 | /* Show number of areas attached. */ | |
b1c3ae8c CS |
3305 | if (json) |
3306 | json_object_int_add(json_vrf, "attachedAreaCounter", | |
d62a17ae | 3307 | listcount(ospf->areas)); |
3308 | else | |
3309 | vty_out(vty, " Number of areas attached to this router: %d\n", | |
3310 | listcount(ospf->areas)); | |
3311 | ||
3312 | if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES)) { | |
3313 | if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL)) { | |
b1c3ae8c | 3314 | if (json) |
d62a17ae | 3315 | json_object_boolean_true_add( |
b1c3ae8c | 3316 | json_vrf, "adjacencyChangesLoggedAll"); |
d62a17ae | 3317 | else |
3318 | vty_out(vty, | |
3319 | " All adjacency changes are logged\n"); | |
3320 | } else { | |
b1c3ae8c | 3321 | if (json) |
d62a17ae | 3322 | json_object_boolean_true_add( |
b1c3ae8c | 3323 | json_vrf, "adjacencyChangesLogged"); |
d62a17ae | 3324 | else |
3325 | vty_out(vty, " Adjacency changes are logged\n"); | |
3326 | } | |
3327 | } | |
132a782e | 3328 | |
3329 | /* show LDP-Sync status */ | |
3330 | ospf_ldp_sync_show_info(vty, ospf, json_vrf, json ? 1 : 0); | |
3331 | ||
d62a17ae | 3332 | /* Show each area status. */ |
3333 | for (ALL_LIST_ELEMENTS(ospf->areas, node, nnode, area)) | |
b1c3ae8c CS |
3334 | show_ip_ospf_area(vty, area, json_areas, json ? 1 : 0); |
3335 | ||
3336 | if (json) { | |
3337 | if (use_vrf) { | |
3338 | json_object_object_add(json_vrf, "areas", json_areas); | |
3339 | if (ospf->vrf_id == VRF_DEFAULT) | |
3340 | json_object_object_add(json, "default", | |
3341 | json_vrf); | |
3342 | else | |
3343 | json_object_object_add(json, ospf->name, | |
3344 | json_vrf); | |
3345 | } else { | |
3346 | json_object_object_add(json, "areas", json_areas); | |
3347 | } | |
d62a17ae | 3348 | } else |
3349 | vty_out(vty, "\n"); | |
3350 | ||
3351 | return CMD_SUCCESS; | |
718e3744 | 3352 | } |
3353 | ||
7c8ff89e DS |
3354 | DEFUN (show_ip_ospf, |
3355 | show_ip_ospf_cmd, | |
b5a8894d | 3356 | "show ip ospf [vrf <NAME|all>] [json]", |
7c8ff89e DS |
3357 | SHOW_STR |
3358 | IP_STR | |
ca08c43d | 3359 | "OSPF information\n" |
b5a8894d CS |
3360 | VRF_CMD_HELP_STR |
3361 | "All VRFs\n" | |
9973d184 | 3362 | JSON_STR) |
7c8ff89e | 3363 | { |
d62a17ae | 3364 | struct ospf *ospf; |
9f049418 | 3365 | bool uj = use_json(argc, argv); |
b5a8894d CS |
3366 | struct listnode *node = NULL; |
3367 | char *vrf_name = NULL; | |
2951a7a4 | 3368 | bool all_vrf = false; |
b5a8894d CS |
3369 | int ret = CMD_SUCCESS; |
3370 | int inst = 0; | |
3371 | int idx_vrf = 0; | |
b1c3ae8c | 3372 | json_object *json = NULL; |
d7c0a89a | 3373 | uint8_t use_vrf = 0; |
7c8ff89e | 3374 | |
b5a8894d | 3375 | if (listcount(om->ospf) == 0) |
d62a17ae | 3376 | return CMD_SUCCESS; |
7c8ff89e | 3377 | |
43b8d1d8 | 3378 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
b5a8894d | 3379 | |
b1c3ae8c CS |
3380 | if (uj) |
3381 | json = json_object_new_object(); | |
3382 | ||
996c9314 | 3383 | /* vrf input is provided could be all or specific vrf*/ |
b5a8894d | 3384 | if (vrf_name) { |
2951a7a4 | 3385 | bool ospf_output = false; |
874f58d8 | 3386 | |
b1c3ae8c | 3387 | use_vrf = 1; |
94d4c685 | 3388 | |
b5a8894d CS |
3389 | if (all_vrf) { |
3390 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
3391 | if (!ospf->oi_running) | |
3392 | continue; | |
2951a7a4 | 3393 | ospf_output = true; |
b1c3ae8c CS |
3394 | ret = show_ip_ospf_common(vty, ospf, json, |
3395 | use_vrf); | |
3396 | } | |
3397 | if (uj) { | |
3398 | vty_out(vty, "%s\n", | |
996c9314 LB |
3399 | json_object_to_json_string_ext( |
3400 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 3401 | json_object_free(json); |
9f049418 DS |
3402 | } else if (!ospf_output) |
3403 | vty_out(vty, "%% OSPF instance not found\n"); | |
b5a8894d CS |
3404 | return ret; |
3405 | } | |
3406 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
b1c3ae8c | 3407 | if ((ospf == NULL) || !ospf->oi_running) { |
9f049418 DS |
3408 | if (uj) { |
3409 | vty_out(vty, "%s\n", | |
3410 | json_object_to_json_string_ext( | |
3411 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 3412 | json_object_free(json); |
9f049418 | 3413 | } else |
94d4c685 | 3414 | vty_out(vty, "%% OSPF instance not found\n"); |
9f049418 | 3415 | |
b5a8894d | 3416 | return CMD_SUCCESS; |
b1c3ae8c | 3417 | } |
b5a8894d CS |
3418 | } else { |
3419 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
3420 | /* Display default ospf (instance 0) info */ | |
b1c3ae8c | 3421 | if (ospf == NULL || !ospf->oi_running) { |
9f049418 DS |
3422 | if (uj) { |
3423 | vty_out(vty, "%s\n", | |
3424 | json_object_to_json_string_ext( | |
3425 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 3426 | json_object_free(json); |
9f049418 | 3427 | } else |
94d4c685 | 3428 | vty_out(vty, "%% OSPF instance not found\n"); |
9f049418 | 3429 | |
b5a8894d | 3430 | return CMD_SUCCESS; |
b1c3ae8c | 3431 | } |
b5a8894d CS |
3432 | } |
3433 | ||
996c9314 | 3434 | if (ospf) { |
b1c3ae8c CS |
3435 | show_ip_ospf_common(vty, ospf, json, use_vrf); |
3436 | if (uj) | |
996c9314 LB |
3437 | vty_out(vty, "%s\n", |
3438 | json_object_to_json_string_ext( | |
3439 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c CS |
3440 | } |
3441 | ||
3442 | if (uj) | |
3443 | json_object_free(json); | |
b5a8894d CS |
3444 | |
3445 | return ret; | |
7c8ff89e DS |
3446 | } |
3447 | ||
3448 | DEFUN (show_ip_ospf_instance, | |
3449 | show_ip_ospf_instance_cmd, | |
6147e2c6 | 3450 | "show ip ospf (1-65535) [json]", |
7c8ff89e DS |
3451 | SHOW_STR |
3452 | IP_STR | |
3453 | "OSPF information\n" | |
ca08c43d | 3454 | "Instance ID\n" |
9973d184 | 3455 | JSON_STR) |
7c8ff89e | 3456 | { |
d62a17ae | 3457 | int idx_number = 3; |
3458 | struct ospf *ospf; | |
d7c0a89a | 3459 | unsigned short instance = 0; |
9f049418 | 3460 | bool uj = use_json(argc, argv); |
b1c3ae8c CS |
3461 | int ret = CMD_SUCCESS; |
3462 | json_object *json = NULL; | |
d62a17ae | 3463 | |
3464 | instance = strtoul(argv[idx_number]->arg, NULL, 10); | |
409f98ab | 3465 | if (instance != ospf_instance) |
ac28e4ec CS |
3466 | return CMD_NOT_MY_INSTANCE; |
3467 | ||
409f98ab IR |
3468 | ospf = ospf_lookup_instance(instance); |
3469 | if (!ospf || !ospf->oi_running) | |
d62a17ae | 3470 | return CMD_SUCCESS; |
3471 | ||
b1c3ae8c CS |
3472 | if (uj) |
3473 | json = json_object_new_object(); | |
3474 | ||
3475 | ret = show_ip_ospf_common(vty, ospf, json, 0); | |
3476 | ||
3477 | if (uj) { | |
996c9314 LB |
3478 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
3479 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c CS |
3480 | json_object_free(json); |
3481 | } | |
3482 | ||
3483 | return ret; | |
d62a17ae | 3484 | } |
3485 | ||
49498934 | 3486 | static void ospf_interface_auth_show(struct vty *vty, struct ospf_interface *oi, |
3487 | json_object *json, bool use_json) | |
3488 | { | |
3489 | int auth_type; | |
3490 | ||
3491 | auth_type = OSPF_IF_PARAM(oi, auth_type); | |
3492 | ||
3493 | switch (auth_type) { | |
3494 | case OSPF_AUTH_NULL: | |
3495 | if (use_json) | |
3496 | json_object_string_add(json, "authentication", | |
3497 | "authenticationNone"); | |
3498 | else | |
3499 | vty_out(vty, " Authentication NULL is enabled\n"); | |
3500 | break; | |
3501 | case OSPF_AUTH_SIMPLE: { | |
3502 | if (use_json) | |
3503 | json_object_string_add(json, "authentication", | |
3504 | "authenticationSimplePassword"); | |
3505 | else | |
3506 | vty_out(vty, | |
3507 | " Simple password authentication enabled\n"); | |
3508 | break; | |
3509 | } | |
3510 | case OSPF_AUTH_CRYPTOGRAPHIC: { | |
3511 | struct crypt_key *ckey; | |
3512 | ||
3513 | if (list_isempty(OSPF_IF_PARAM(oi, auth_crypt))) | |
3514 | return; | |
3515 | ||
3516 | ckey = listgetdata(listtail(OSPF_IF_PARAM(oi, auth_crypt))); | |
3517 | if (ckey) { | |
3518 | if (use_json) { | |
3519 | json_object_string_add(json, "authentication", | |
3520 | "authenticationMessageDigest"); | |
3521 | } else { | |
3522 | vty_out(vty, | |
3523 | " Cryptographic authentication enabled\n"); | |
3524 | vty_out(vty, " Algorithm:MD5\n"); | |
3525 | } | |
3526 | } | |
3527 | break; | |
3528 | } | |
3529 | default: | |
3530 | break; | |
3531 | } | |
3532 | } | |
3533 | ||
d62a17ae | 3534 | static void show_ip_ospf_interface_sub(struct vty *vty, struct ospf *ospf, |
3535 | struct interface *ifp, | |
3536 | json_object *json_interface_sub, | |
9f049418 | 3537 | bool use_json) |
d62a17ae | 3538 | { |
3539 | int is_up; | |
3540 | struct ospf_neighbor *nbr; | |
3541 | struct route_node *rn; | |
96b663a3 | 3542 | char buf[PREFIX_STRLEN]; |
d62a17ae | 3543 | uint32_t bandwidth = ifp->bandwidth ? ifp->bandwidth : ifp->speed; |
3544 | ||
3545 | /* Is interface up? */ | |
3546 | if (use_json) { | |
3547 | is_up = if_is_operative(ifp); | |
3548 | if (is_up) | |
3549 | json_object_boolean_true_add(json_interface_sub, | |
3550 | "ifUp"); | |
3551 | else | |
3552 | json_object_boolean_false_add(json_interface_sub, | |
3553 | "ifDown"); | |
3554 | ||
3555 | json_object_int_add(json_interface_sub, "ifIndex", | |
3556 | ifp->ifindex); | |
3557 | json_object_int_add(json_interface_sub, "mtuBytes", ifp->mtu); | |
3558 | json_object_int_add(json_interface_sub, "bandwidthMbit", | |
3559 | bandwidth); | |
3560 | json_object_string_add(json_interface_sub, "ifFlags", | |
3561 | if_flag_dump(ifp->flags)); | |
3562 | } else { | |
3563 | vty_out(vty, "%s is %s\n", ifp->name, | |
3564 | ((is_up = if_is_operative(ifp)) ? "up" : "down")); | |
3565 | vty_out(vty, " ifindex %u, MTU %u bytes, BW %u Mbit %s\n", | |
3566 | ifp->ifindex, ifp->mtu, bandwidth, | |
3567 | if_flag_dump(ifp->flags)); | |
3568 | } | |
7c8ff89e | 3569 | |
d62a17ae | 3570 | /* Is interface OSPF enabled? */ |
3571 | if (use_json) { | |
3572 | if (ospf_oi_count(ifp) == 0) { | |
3573 | json_object_boolean_false_add(json_interface_sub, | |
3574 | "ospfEnabled"); | |
3575 | return; | |
3576 | } else if (!is_up) { | |
3577 | json_object_boolean_false_add(json_interface_sub, | |
3578 | "ospfRunning"); | |
3579 | return; | |
3580 | } else | |
3581 | json_object_boolean_true_add(json_interface_sub, | |
3582 | "ospfEnabled"); | |
3583 | } else { | |
3584 | if (ospf_oi_count(ifp) == 0) { | |
3585 | vty_out(vty, " OSPF not enabled on this interface\n"); | |
3586 | return; | |
3587 | } else if (!is_up) { | |
3588 | vty_out(vty, | |
3589 | " OSPF is enabled, but not running on this interface\n"); | |
3590 | return; | |
3591 | } | |
3592 | } | |
3593 | ||
3594 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { | |
3595 | struct ospf_interface *oi = rn->info; | |
3596 | ||
3597 | if (oi == NULL) | |
3598 | continue; | |
3599 | ||
3600 | if (CHECK_FLAG(oi->connected->flags, ZEBRA_IFA_UNNUMBERED)) { | |
3601 | if (use_json) | |
3602 | json_object_boolean_true_add(json_interface_sub, | |
3603 | "ifUnnumbered"); | |
3604 | else | |
3605 | vty_out(vty, " This interface is UNNUMBERED,"); | |
3606 | } else { | |
0f3af738 JW |
3607 | struct in_addr dest; |
3608 | const char *dstr; | |
3609 | ||
d62a17ae | 3610 | /* Show OSPF interface information. */ |
3611 | if (use_json) { | |
3612 | json_object_string_add( | |
3613 | json_interface_sub, "ipAddress", | |
96b663a3 MS |
3614 | inet_ntop(AF_INET, |
3615 | &oi->address->u.prefix4, | |
3616 | buf, sizeof(buf))); | |
d62a17ae | 3617 | json_object_int_add(json_interface_sub, |
3618 | "ipAddressPrefixlen", | |
3619 | oi->address->prefixlen); | |
3620 | } else | |
ae32e1c2 DS |
3621 | vty_out(vty, " Internet Address %pFX,", |
3622 | oi->address); | |
d62a17ae | 3623 | |
0f3af738 JW |
3624 | /* For Vlinks, showing the peer address is |
3625 | * probably more informative than the local | |
3626 | * interface that is being used */ | |
3627 | if (oi->type == OSPF_IFTYPE_VIRTUALLINK) { | |
3628 | dstr = "Peer"; | |
3629 | dest = oi->vl_data->peer_addr; | |
3630 | } else if (CONNECTED_PEER(oi->connected) | |
3631 | && oi->connected->destination) { | |
3632 | dstr = "Peer"; | |
3633 | dest = oi->connected->destination->u.prefix4; | |
3634 | } else { | |
3635 | dstr = "Broadcast"; | |
3636 | dest.s_addr = ipv4_broadcast_addr( | |
3637 | oi->connected->address->u.prefix4.s_addr, | |
3638 | oi->connected->address->prefixlen); | |
3639 | } | |
d62a17ae | 3640 | |
0f3af738 JW |
3641 | if (use_json) { |
3642 | json_object_string_add( | |
3643 | json_interface_sub, | |
3644 | "ospfIfType", dstr); | |
d62a17ae | 3645 | if (oi->type == OSPF_IFTYPE_VIRTUALLINK) |
0f3af738 JW |
3646 | json_object_string_add( |
3647 | json_interface_sub, | |
3648 | "vlinkPeer", | |
96b663a3 MS |
3649 | inet_ntop(AF_INET, &dest, |
3650 | buf, sizeof(buf))); | |
d62a17ae | 3651 | else |
d62a17ae | 3652 | json_object_string_add( |
3653 | json_interface_sub, | |
0f3af738 | 3654 | "localIfUsed", |
96b663a3 MS |
3655 | inet_ntop(AF_INET, &dest, |
3656 | buf, sizeof(buf))); | |
0f3af738 | 3657 | } else |
96b663a3 MS |
3658 | vty_out(vty, " %s %pI4,", dstr, |
3659 | &dest); | |
d62a17ae | 3660 | } |
3661 | if (use_json) { | |
3662 | json_object_string_add(json_interface_sub, "area", | |
3663 | ospf_area_desc_string(oi->area)); | |
3664 | if (OSPF_IF_PARAM(oi, mtu_ignore)) | |
3665 | json_object_boolean_true_add( | |
3666 | json_interface_sub, | |
3667 | "mtuMismatchDetect"); | |
96b663a3 MS |
3668 | json_object_string_add( |
3669 | json_interface_sub, "routerId", | |
3670 | inet_ntop(AF_INET, &ospf->router_id, | |
3671 | buf, sizeof(buf))); | |
d62a17ae | 3672 | json_object_string_add(json_interface_sub, |
3673 | "networkType", | |
3674 | ospf_network_type_str[oi->type]); | |
3675 | json_object_int_add(json_interface_sub, "cost", | |
3676 | oi->output_cost); | |
3677 | json_object_int_add( | |
50ad4b42 MS |
3678 | json_interface_sub, "transmitDelaySecs", |
3679 | OSPF_IF_PARAM(oi, transmit_delay)); | |
d62a17ae | 3680 | json_object_string_add(json_interface_sub, "state", |
3681 | lookup_msg(ospf_ism_state_msg, | |
3682 | oi->state, NULL)); | |
3683 | json_object_int_add(json_interface_sub, "priority", | |
3684 | PRIORITY(oi)); | |
3685 | } else { | |
3686 | vty_out(vty, " Area %s\n", | |
3687 | ospf_area_desc_string(oi->area)); | |
3688 | ||
3689 | vty_out(vty, " MTU mismatch detection: %s\n", | |
3690 | OSPF_IF_PARAM(oi, mtu_ignore) ? "disabled" | |
3691 | : "enabled"); | |
3692 | ||
3693 | vty_out(vty, | |
96b663a3 MS |
3694 | " Router ID %pI4, Network Type %s, Cost: %d\n", |
3695 | &ospf->router_id, | |
d62a17ae | 3696 | ospf_network_type_str[oi->type], |
3697 | oi->output_cost); | |
3698 | ||
3699 | vty_out(vty, | |
3700 | " Transmit Delay is %d sec, State %s, Priority %d\n", | |
3701 | OSPF_IF_PARAM(oi, transmit_delay), | |
3702 | lookup_msg(ospf_ism_state_msg, oi->state, NULL), | |
3703 | PRIORITY(oi)); | |
3704 | } | |
3705 | ||
3706 | /* Show DR information. */ | |
975a328e | 3707 | if (DR(oi).s_addr == INADDR_ANY) { |
d62a17ae | 3708 | if (!use_json) |
3709 | vty_out(vty, | |
3710 | " No backup designated router on this network\n"); | |
3711 | } else { | |
2fbb8f45 | 3712 | nbr = ospf_nbr_lookup_by_addr(oi->nbrs, &DR(oi)); |
3713 | if (nbr) { | |
3714 | if (use_json) { | |
3715 | json_object_string_add( | |
3716 | json_interface_sub, "drId", | |
3717 | inet_ntop(AF_INET, | |
3718 | &nbr->router_id, buf, | |
3719 | sizeof(buf))); | |
3720 | json_object_string_add( | |
3721 | json_interface_sub, "drAddress", | |
3722 | inet_ntop( | |
3723 | AF_INET, | |
3724 | &nbr->address.u.prefix4, | |
3725 | buf, sizeof(buf))); | |
3726 | } else { | |
3727 | vty_out(vty, | |
3728 | " Designated Router (ID) %pI4", | |
3729 | &nbr->router_id); | |
3730 | vty_out(vty, | |
3731 | " Interface Address %pFX\n", | |
3732 | &nbr->address); | |
3733 | } | |
3734 | } | |
3735 | nbr = NULL; | |
3736 | ||
d62a17ae | 3737 | nbr = ospf_nbr_lookup_by_addr(oi->nbrs, &BDR(oi)); |
3738 | if (nbr == NULL) { | |
3739 | if (!use_json) | |
3740 | vty_out(vty, | |
3741 | " No backup designated router on this network\n"); | |
3742 | } else { | |
3743 | if (use_json) { | |
3744 | json_object_string_add( | |
3745 | json_interface_sub, "bdrId", | |
96b663a3 MS |
3746 | inet_ntop(AF_INET, |
3747 | &nbr->router_id, | |
3748 | buf, sizeof(buf))); | |
d62a17ae | 3749 | json_object_string_add( |
3750 | json_interface_sub, | |
3751 | "bdrAddress", | |
96b663a3 MS |
3752 | inet_ntop(AF_INET, |
3753 | &nbr->address.u | |
3754 | .prefix4, | |
3755 | buf, sizeof(buf))); | |
d62a17ae | 3756 | } else { |
3757 | vty_out(vty, | |
96b663a3 MS |
3758 | " Backup Designated Router (ID) %pI4,", |
3759 | &nbr->router_id); | |
3760 | vty_out(vty, " Interface Address %pI4\n", | |
3761 | &nbr->address.u.prefix4); | |
d62a17ae | 3762 | } |
3763 | } | |
3764 | } | |
3765 | ||
3766 | /* Next network-LSA sequence number we'll use, if we're elected | |
3767 | * DR */ | |
3768 | if (oi->params | |
3769 | && ntohl(oi->params->network_lsa_seqnum) | |
3770 | != OSPF_INITIAL_SEQUENCE_NUMBER) { | |
3771 | if (use_json) | |
3772 | json_object_int_add( | |
3773 | json_interface_sub, | |
3774 | "networkLsaSequence", | |
3775 | ntohl(oi->params->network_lsa_seqnum)); | |
3776 | else | |
3777 | vty_out(vty, | |
3778 | " Saved Network-LSA sequence number 0x%x\n", | |
3779 | ntohl(oi->params->network_lsa_seqnum)); | |
3780 | } | |
3781 | ||
3782 | if (use_json) { | |
3783 | if (OI_MEMBER_CHECK(oi, MEMBER_ALLROUTERS) | |
3784 | || OI_MEMBER_CHECK(oi, MEMBER_DROUTERS)) { | |
3785 | if (OI_MEMBER_CHECK(oi, MEMBER_ALLROUTERS)) | |
3786 | json_object_boolean_true_add( | |
3787 | json_interface_sub, | |
3788 | "mcastMemberOspfAllRouters"); | |
3789 | if (OI_MEMBER_CHECK(oi, MEMBER_DROUTERS)) | |
3790 | json_object_boolean_true_add( | |
3791 | json_interface_sub, | |
3792 | "mcastMemberOspfDesignatedRouters"); | |
3793 | } | |
3794 | } else { | |
3795 | vty_out(vty, " Multicast group memberships:"); | |
3796 | if (OI_MEMBER_CHECK(oi, MEMBER_ALLROUTERS) | |
3797 | || OI_MEMBER_CHECK(oi, MEMBER_DROUTERS)) { | |
3798 | if (OI_MEMBER_CHECK(oi, MEMBER_ALLROUTERS)) | |
3799 | vty_out(vty, " OSPFAllRouters"); | |
3800 | if (OI_MEMBER_CHECK(oi, MEMBER_DROUTERS)) | |
3801 | vty_out(vty, " OSPFDesignatedRouters"); | |
3802 | } else | |
3803 | vty_out(vty, " <None>"); | |
3804 | vty_out(vty, "\n"); | |
3805 | } | |
3806 | ||
3807 | if (use_json) { | |
3808 | if (OSPF_IF_PARAM(oi, fast_hello) == 0) | |
3809 | json_object_int_add( | |
3810 | json_interface_sub, "timerMsecs", | |
50ad4b42 | 3811 | OSPF_IF_PARAM(oi, v_hello) * 1000); |
d62a17ae | 3812 | else |
3813 | json_object_int_add( | |
3814 | json_interface_sub, "timerMsecs", | |
50ad4b42 | 3815 | 1000 / OSPF_IF_PARAM(oi, fast_hello)); |
d62a17ae | 3816 | json_object_int_add(json_interface_sub, |
50ad4b42 MS |
3817 | "timerDeadSecs", |
3818 | OSPF_IF_PARAM(oi, v_wait)); | |
d62a17ae | 3819 | json_object_int_add(json_interface_sub, |
50ad4b42 MS |
3820 | "timerWaitSecs", |
3821 | OSPF_IF_PARAM(oi, v_wait)); | |
d62a17ae | 3822 | json_object_int_add( |
50ad4b42 MS |
3823 | json_interface_sub, "timerRetransmitSecs", |
3824 | OSPF_IF_PARAM(oi, retransmit_interval)); | |
d62a17ae | 3825 | } else { |
3826 | vty_out(vty, " Timer intervals configured,"); | |
3827 | vty_out(vty, " Hello "); | |
3828 | if (OSPF_IF_PARAM(oi, fast_hello) == 0) | |
3829 | vty_out(vty, "%ds,", | |
3830 | OSPF_IF_PARAM(oi, v_hello)); | |
3831 | else | |
3832 | vty_out(vty, "%dms,", | |
3833 | 1000 / OSPF_IF_PARAM(oi, fast_hello)); | |
3834 | vty_out(vty, " Dead %ds, Wait %ds, Retransmit %d\n", | |
3835 | OSPF_IF_PARAM(oi, v_wait), | |
3836 | OSPF_IF_PARAM(oi, v_wait), | |
3837 | OSPF_IF_PARAM(oi, retransmit_interval)); | |
3838 | } | |
3839 | ||
3840 | if (OSPF_IF_PASSIVE_STATUS(oi) == OSPF_IF_ACTIVE) { | |
3841 | char timebuf[OSPF_TIME_DUMP_SIZE]; | |
3842 | if (use_json) { | |
3843 | long time_store = 0; | |
3844 | if (oi->t_hello) | |
3845 | time_store = | |
3846 | monotime_until( | |
3847 | &oi->t_hello->u.sands, | |
3848 | NULL) | |
3849 | / 1000LL; | |
3850 | json_object_int_add(json_interface_sub, | |
3851 | "timerHelloInMsecs", | |
3852 | time_store); | |
3853 | } else | |
3854 | vty_out(vty, " Hello due in %s\n", | |
3855 | ospf_timer_dump(oi->t_hello, timebuf, | |
3856 | sizeof(timebuf))); | |
3857 | } else /* passive-interface is set */ | |
3858 | { | |
3859 | if (use_json) | |
3860 | json_object_boolean_true_add( | |
3861 | json_interface_sub, | |
3862 | "timerPassiveIface"); | |
3863 | else | |
3864 | vty_out(vty, | |
3865 | " No Hellos (Passive interface)\n"); | |
3866 | } | |
7c8ff89e | 3867 | |
d62a17ae | 3868 | if (use_json) { |
3869 | json_object_int_add(json_interface_sub, "nbrCount", | |
3870 | ospf_nbr_count(oi, 0)); | |
3871 | json_object_int_add(json_interface_sub, | |
3872 | "nbrAdjacentCount", | |
3873 | ospf_nbr_count(oi, NSM_Full)); | |
3874 | } else | |
3875 | vty_out(vty, | |
3876 | " Neighbor Count is %d, Adjacent neighbor count is %d\n", | |
3877 | ospf_nbr_count(oi, 0), | |
3878 | ospf_nbr_count(oi, NSM_Full)); | |
659f4e40 RZ |
3879 | |
3880 | ospf_interface_bfd_show(vty, ifp, json_interface_sub); | |
49498934 | 3881 | |
3882 | /* OSPF Authentication information */ | |
3883 | ospf_interface_auth_show(vty, oi, json_interface_sub, use_json); | |
d62a17ae | 3884 | } |
718e3744 | 3885 | } |
3886 | ||
d62a17ae | 3887 | static int show_ip_ospf_interface_common(struct vty *vty, struct ospf *ospf, |
d7c0a89a | 3888 | char *intf_name, uint8_t use_vrf, |
9f049418 | 3889 | json_object *json, bool use_json) |
d62a17ae | 3890 | { |
3891 | struct interface *ifp; | |
f4e14fdb | 3892 | struct vrf *vrf = vrf_lookup_by_id(ospf->vrf_id); |
6282e124 | 3893 | json_object *json_vrf = NULL; |
7dab10ce | 3894 | json_object *json_interface_sub = NULL, *json_interface = NULL; |
7c8ff89e | 3895 | |
d62a17ae | 3896 | if (use_json) { |
b1c3ae8c CS |
3897 | if (use_vrf) |
3898 | json_vrf = json_object_new_object(); | |
3899 | else | |
3900 | json_vrf = json; | |
6282e124 | 3901 | json_interface = json_object_new_object(); |
d62a17ae | 3902 | } |
3903 | ||
3904 | if (ospf->instance) { | |
3905 | if (use_json) | |
3906 | json_object_int_add(json, "ospfInstance", | |
3907 | ospf->instance); | |
3908 | else | |
3909 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
3910 | } | |
3911 | ||
b1c3ae8c CS |
3912 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); |
3913 | ||
3914 | if (intf_name == NULL) { | |
d62a17ae | 3915 | /* Show All Interfaces.*/ |
451fda4f | 3916 | FOR_ALL_INTERFACES (vrf, ifp) { |
d62a17ae | 3917 | if (ospf_oi_count(ifp)) { |
7dab10ce | 3918 | if (use_json) { |
d62a17ae | 3919 | json_interface_sub = |
3920 | json_object_new_object(); | |
7dab10ce | 3921 | } |
d62a17ae | 3922 | show_ip_ospf_interface_sub(vty, ospf, ifp, |
3923 | json_interface_sub, | |
3924 | use_json); | |
3925 | ||
7dab10ce | 3926 | if (use_json) { |
d62a17ae | 3927 | json_object_object_add( |
7dab10ce | 3928 | json_interface, ifp->name, |
d62a17ae | 3929 | json_interface_sub); |
7dab10ce | 3930 | } |
d62a17ae | 3931 | } |
3932 | } | |
6282e124 CS |
3933 | if (use_json) |
3934 | json_object_object_add(json_vrf, "interfaces", | |
996c9314 | 3935 | json_interface); |
d62a17ae | 3936 | } else { |
3937 | /* Interface name is specified. */ | |
a36898e7 | 3938 | ifp = if_lookup_by_name(intf_name, ospf->vrf_id); |
b1c3ae8c | 3939 | if (ifp == NULL) { |
d62a17ae | 3940 | if (use_json) |
b1c3ae8c | 3941 | json_object_boolean_true_add(json_vrf, |
d62a17ae | 3942 | "noSuchIface"); |
3943 | else | |
3944 | vty_out(vty, "No such interface name\n"); | |
3945 | } else { | |
7dab10ce | 3946 | if (use_json) { |
d62a17ae | 3947 | json_interface_sub = json_object_new_object(); |
7dab10ce | 3948 | json_interface = json_object_new_object(); |
7dab10ce | 3949 | } |
d62a17ae | 3950 | |
3951 | show_ip_ospf_interface_sub( | |
3952 | vty, ospf, ifp, json_interface_sub, use_json); | |
3953 | ||
7dab10ce | 3954 | if (use_json) { |
7dab10ce CS |
3955 | json_object_object_add(json_interface, |
3956 | ifp->name, | |
d62a17ae | 3957 | json_interface_sub); |
6282e124 CS |
3958 | json_object_object_add(json_vrf, "interfaces", |
3959 | json_interface); | |
7dab10ce | 3960 | } |
d62a17ae | 3961 | } |
3962 | } | |
3963 | ||
3964 | if (use_json) { | |
b1c3ae8c CS |
3965 | if (use_vrf) { |
3966 | if (ospf->vrf_id == VRF_DEFAULT) | |
3967 | json_object_object_add(json, "default", | |
3968 | json_vrf); | |
3969 | else | |
3970 | json_object_object_add(json, ospf->name, | |
3971 | json_vrf); | |
3972 | } | |
d62a17ae | 3973 | } else |
3974 | vty_out(vty, "\n"); | |
3975 | ||
3976 | return CMD_SUCCESS; | |
718e3744 | 3977 | } |
3978 | ||
c9339663 CS |
3979 | static void show_ip_ospf_interface_traffic_sub(struct vty *vty, |
3980 | struct ospf_interface *oi, | |
3981 | json_object *json_interface_sub, | |
9f049418 | 3982 | bool use_json) |
c9339663 CS |
3983 | { |
3984 | if (use_json) { | |
996c9314 LB |
3985 | json_object_int_add(json_interface_sub, "ifIndex", |
3986 | oi->ifp->ifindex); | |
3987 | json_object_int_add(json_interface_sub, "helloIn", | |
3988 | oi->hello_in); | |
3989 | json_object_int_add(json_interface_sub, "helloOut", | |
3990 | oi->hello_out); | |
3991 | json_object_int_add(json_interface_sub, "dbDescIn", | |
3992 | oi->db_desc_in); | |
3993 | json_object_int_add(json_interface_sub, "dbDescOut", | |
3994 | oi->db_desc_out); | |
3995 | json_object_int_add(json_interface_sub, "lsReqIn", | |
3996 | oi->ls_req_in); | |
3997 | json_object_int_add(json_interface_sub, "lsReqOut", | |
3998 | oi->ls_req_out); | |
3999 | json_object_int_add(json_interface_sub, "lsUpdIn", | |
4000 | oi->ls_upd_in); | |
4001 | json_object_int_add(json_interface_sub, "lsUpdOut", | |
4002 | oi->ls_upd_out); | |
4003 | json_object_int_add(json_interface_sub, "lsAckIn", | |
4004 | oi->ls_ack_in); | |
4005 | json_object_int_add(json_interface_sub, "lsAckOut", | |
4006 | oi->ls_ack_out); | |
c9339663 CS |
4007 | } else { |
4008 | vty_out(vty, | |
4009 | "%-10s %8u/%-8u %7u/%-7u %7u/%-7u %7u/%-7u %7u/%-7u\n", | |
996c9314 LB |
4010 | oi->ifp->name, oi->hello_in, oi->hello_out, |
4011 | oi->db_desc_in, oi->db_desc_out, oi->ls_req_in, | |
4012 | oi->ls_req_out, oi->ls_upd_in, oi->ls_upd_out, | |
c9339663 CS |
4013 | oi->ls_ack_in, oi->ls_ack_out); |
4014 | } | |
4015 | } | |
4016 | ||
4017 | /* OSPFv2 Packet Counters */ | |
996c9314 LB |
4018 | static int show_ip_ospf_interface_traffic_common( |
4019 | struct vty *vty, struct ospf *ospf, char *intf_name, json_object *json, | |
9f049418 | 4020 | int display_once, uint8_t use_vrf, bool use_json) |
c9339663 CS |
4021 | { |
4022 | struct vrf *vrf = NULL; | |
4023 | struct interface *ifp = NULL; | |
b1c3ae8c | 4024 | json_object *json_vrf = NULL; |
c9339663 CS |
4025 | json_object *json_interface_sub = NULL; |
4026 | ||
4027 | if (!use_json && !display_once) { | |
4028 | vty_out(vty, "\n"); | |
996c9314 LB |
4029 | vty_out(vty, "%-12s%-17s%-17s%-17s%-17s%-17s\n", "Interface", |
4030 | " HELLO", " DB-Desc", " LS-Req", " LS-Update", | |
4031 | " LS-Ack"); | |
c9339663 | 4032 | vty_out(vty, "%-10s%-18s%-18s%-17s%-17s%-17s\n", "", |
996c9314 LB |
4033 | " Rx/Tx", " Rx/Tx", " Rx/Tx", " Rx/Tx", |
4034 | " Rx/Tx"); | |
c9339663 | 4035 | vty_out(vty, |
996c9314 | 4036 | "--------------------------------------------------------------------------------------------\n"); |
c9339663 | 4037 | } else if (use_json) { |
b1c3ae8c CS |
4038 | if (use_vrf) |
4039 | json_vrf = json_object_new_object(); | |
4040 | else | |
4041 | json_vrf = json; | |
c9339663 CS |
4042 | } |
4043 | ||
b1c3ae8c CS |
4044 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); |
4045 | ||
c9339663 CS |
4046 | if (intf_name == NULL) { |
4047 | vrf = vrf_lookup_by_id(ospf->vrf_id); | |
4048 | FOR_ALL_INTERFACES (vrf, ifp) { | |
4049 | struct route_node *rn; | |
4050 | struct ospf_interface *oi; | |
4051 | ||
4052 | if (ospf_oi_count(ifp) == 0) | |
4053 | continue; | |
4054 | ||
4055 | for (rn = route_top(IF_OIFS(ifp)); rn; | |
996c9314 | 4056 | rn = route_next(rn)) { |
c9339663 CS |
4057 | oi = rn->info; |
4058 | ||
4059 | if (oi == NULL) | |
4060 | continue; | |
4061 | ||
4062 | if (use_json) { | |
4063 | json_interface_sub = | |
4064 | json_object_new_object(); | |
4065 | } | |
4066 | ||
996c9314 LB |
4067 | show_ip_ospf_interface_traffic_sub( |
4068 | vty, oi, json_interface_sub, use_json); | |
c9339663 | 4069 | if (use_json) { |
996c9314 LB |
4070 | json_object_object_add( |
4071 | json_vrf, ifp->name, | |
4072 | json_interface_sub); | |
c9339663 CS |
4073 | } |
4074 | } | |
4075 | } | |
4076 | } else { | |
4077 | /* Interface name is specified. */ | |
a36898e7 | 4078 | ifp = if_lookup_by_name(intf_name, ospf->vrf_id); |
c9339663 CS |
4079 | if (ifp != NULL) { |
4080 | struct route_node *rn; | |
4081 | struct ospf_interface *oi; | |
4082 | ||
4083 | if (ospf_oi_count(ifp) == 0) { | |
996c9314 LB |
4084 | vty_out(vty, |
4085 | " OSPF not enabled on this interface %s\n", | |
c9339663 CS |
4086 | ifp->name); |
4087 | return CMD_SUCCESS; | |
4088 | } | |
4089 | ||
4090 | for (rn = route_top(IF_OIFS(ifp)); rn; | |
4091 | rn = route_next(rn)) { | |
4092 | oi = rn->info; | |
4093 | ||
4094 | if (use_json) { | |
4095 | json_interface_sub = | |
4096 | json_object_new_object(); | |
4097 | } | |
4098 | ||
996c9314 LB |
4099 | show_ip_ospf_interface_traffic_sub( |
4100 | vty, oi, json_interface_sub, use_json); | |
c9339663 | 4101 | if (use_json) { |
996c9314 LB |
4102 | json_object_object_add( |
4103 | json_vrf, ifp->name, | |
4104 | json_interface_sub); | |
c9339663 CS |
4105 | } |
4106 | } | |
4107 | } | |
4108 | } | |
4109 | ||
4110 | if (use_json) { | |
b1c3ae8c CS |
4111 | if (use_vrf) { |
4112 | if (ospf->vrf_id == VRF_DEFAULT) | |
4113 | json_object_object_add(json, "default", | |
4114 | json_vrf); | |
4115 | else | |
4116 | json_object_object_add(json, ospf->name, | |
4117 | json_vrf); | |
4118 | } | |
4119 | } else | |
4120 | vty_out(vty, "\n"); | |
c9339663 CS |
4121 | |
4122 | return CMD_SUCCESS; | |
4123 | } | |
4124 | ||
7c8ff89e DS |
4125 | DEFUN (show_ip_ospf_interface, |
4126 | show_ip_ospf_interface_cmd, | |
43b8d1d8 | 4127 | "show ip ospf [vrf <NAME|all>] interface [INTERFACE] [json]", |
7c8ff89e DS |
4128 | SHOW_STR |
4129 | IP_STR | |
4130 | "OSPF information\n" | |
b5a8894d | 4131 | VRF_CMD_HELP_STR |
43b8d1d8 | 4132 | "All VRFs\n" |
7c8ff89e | 4133 | "Interface information\n" |
7ec4159b | 4134 | "Interface name\n" |
9973d184 | 4135 | JSON_STR) |
7c8ff89e | 4136 | { |
d62a17ae | 4137 | struct ospf *ospf; |
9f049418 | 4138 | bool uj = use_json(argc, argv); |
b5a8894d | 4139 | struct listnode *node = NULL; |
b1c3ae8c | 4140 | char *vrf_name = NULL, *intf_name = NULL; |
2951a7a4 | 4141 | bool all_vrf = false; |
b5a8894d CS |
4142 | int ret = CMD_SUCCESS; |
4143 | int inst = 0; | |
b1c3ae8c | 4144 | int idx_vrf = 0, idx_intf = 0; |
d7c0a89a | 4145 | uint8_t use_vrf = 0; |
b1c3ae8c | 4146 | json_object *json = NULL; |
7c8ff89e | 4147 | |
43b8d1d8 CS |
4148 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
4149 | ||
b1c3ae8c CS |
4150 | if (argv_find(argv, argc, "INTERFACE", &idx_intf)) |
4151 | intf_name = argv[idx_intf]->arg; | |
4152 | ||
d62a17ae | 4153 | if (uj) |
b1c3ae8c | 4154 | json = json_object_new_object(); |
6be4da3d | 4155 | |
b5a8894d CS |
4156 | /* vrf input is provided could be all or specific vrf*/ |
4157 | if (vrf_name) { | |
b1c3ae8c | 4158 | use_vrf = 1; |
b5a8894d CS |
4159 | if (all_vrf) { |
4160 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
4161 | if (!ospf->oi_running) | |
4162 | continue; | |
996c9314 LB |
4163 | ret = show_ip_ospf_interface_common( |
4164 | vty, ospf, intf_name, use_vrf, json, | |
4165 | uj); | |
b5a8894d | 4166 | } |
b1c3ae8c CS |
4167 | |
4168 | if (uj) { | |
4169 | vty_out(vty, "%s\n", | |
996c9314 LB |
4170 | json_object_to_json_string_ext( |
4171 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 4172 | json_object_free(json); |
9f049418 | 4173 | } else if (!ospf) |
94d4c685 | 4174 | vty_out(vty, "%% OSPF instance not found\n"); |
b1c3ae8c | 4175 | |
b5a8894d CS |
4176 | return ret; |
4177 | } | |
4178 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
b1c3ae8c | 4179 | if (ospf == NULL || !ospf->oi_running) { |
9f049418 DS |
4180 | if (uj) { |
4181 | vty_out(vty, "%s\n", | |
4182 | json_object_to_json_string_ext( | |
4183 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 4184 | json_object_free(json); |
9f049418 | 4185 | } else |
94d4c685 | 4186 | vty_out(vty, "%% OSPF instance not found\n"); |
9f049418 | 4187 | |
b5a8894d | 4188 | return CMD_SUCCESS; |
b1c3ae8c CS |
4189 | } |
4190 | ret = show_ip_ospf_interface_common(vty, ospf, intf_name, | |
4191 | use_vrf, json, uj); | |
b5a8894d CS |
4192 | |
4193 | } else { | |
4194 | /* Display default ospf (instance 0) info */ | |
4195 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
b1c3ae8c | 4196 | if (ospf == NULL || !ospf->oi_running) { |
9f049418 DS |
4197 | if (uj) { |
4198 | vty_out(vty, "%s\n", | |
4199 | json_object_to_json_string_ext( | |
4200 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 4201 | json_object_free(json); |
9f049418 | 4202 | } else |
94d4c685 | 4203 | vty_out(vty, "%% OSPF instance not found\n"); |
9f049418 | 4204 | |
b5a8894d | 4205 | return CMD_SUCCESS; |
b1c3ae8c CS |
4206 | } |
4207 | ret = show_ip_ospf_interface_common(vty, ospf, intf_name, | |
4208 | use_vrf, json, uj); | |
4209 | } | |
4210 | ||
4211 | if (uj) { | |
996c9314 LB |
4212 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
4213 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 4214 | json_object_free(json); |
b5a8894d CS |
4215 | } |
4216 | ||
4217 | return ret; | |
7c8ff89e DS |
4218 | } |
4219 | ||
4220 | DEFUN (show_ip_ospf_instance_interface, | |
4221 | show_ip_ospf_instance_interface_cmd, | |
6147e2c6 | 4222 | "show ip ospf (1-65535) interface [INTERFACE] [json]", |
7c8ff89e DS |
4223 | SHOW_STR |
4224 | IP_STR | |
4225 | "OSPF information\n" | |
4226 | "Instance ID\n" | |
4227 | "Interface information\n" | |
7ec4159b | 4228 | "Interface name\n" |
9973d184 | 4229 | JSON_STR) |
7c8ff89e | 4230 | { |
d62a17ae | 4231 | int idx_number = 3; |
b1c3ae8c | 4232 | int idx_intf = 0; |
d62a17ae | 4233 | struct ospf *ospf; |
d7c0a89a | 4234 | unsigned short instance = 0; |
9f049418 | 4235 | bool uj = use_json(argc, argv); |
b1c3ae8c CS |
4236 | char *intf_name = NULL; |
4237 | int ret = CMD_SUCCESS; | |
4238 | json_object *json = NULL; | |
d62a17ae | 4239 | |
4240 | instance = strtoul(argv[idx_number]->arg, NULL, 10); | |
409f98ab | 4241 | if (instance != ospf_instance) |
ac28e4ec CS |
4242 | return CMD_NOT_MY_INSTANCE; |
4243 | ||
409f98ab IR |
4244 | ospf = ospf_lookup_instance(instance); |
4245 | if (!ospf || !ospf->oi_running) | |
d62a17ae | 4246 | return CMD_SUCCESS; |
4247 | ||
4248 | if (uj) | |
b1c3ae8c CS |
4249 | json = json_object_new_object(); |
4250 | ||
4251 | if (argv_find(argv, argc, "INTERFACE", &idx_intf)) | |
4252 | intf_name = argv[idx_intf]->arg; | |
4253 | ||
4254 | ret = show_ip_ospf_interface_common(vty, ospf, intf_name, 0, json, uj); | |
4255 | ||
4256 | if (uj) { | |
996c9314 LB |
4257 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
4258 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c CS |
4259 | json_object_free(json); |
4260 | } | |
d62a17ae | 4261 | |
b1c3ae8c | 4262 | return ret; |
d62a17ae | 4263 | } |
4264 | ||
c9339663 CS |
4265 | DEFUN (show_ip_ospf_interface_traffic, |
4266 | show_ip_ospf_interface_traffic_cmd, | |
4267 | "show ip ospf [vrf <NAME|all>] interface traffic [INTERFACE] [json]", | |
4268 | SHOW_STR | |
4269 | IP_STR | |
4270 | "OSPF information\n" | |
4271 | VRF_CMD_HELP_STR | |
4272 | "All VRFs\n" | |
4273 | "Interface information\n" | |
4274 | "Protocol Packet counters\n" | |
4275 | "Interface name\n" | |
4276 | JSON_STR) | |
4277 | { | |
4278 | struct ospf *ospf = NULL; | |
4279 | struct listnode *node = NULL; | |
4280 | char *vrf_name = NULL, *intf_name = NULL; | |
2951a7a4 | 4281 | bool all_vrf = false; |
c9339663 CS |
4282 | int inst = 0; |
4283 | int idx_vrf = 0, idx_intf = 0; | |
9f049418 | 4284 | bool uj = use_json(argc, argv); |
b1c3ae8c | 4285 | json_object *json = NULL; |
c9339663 CS |
4286 | int ret = CMD_SUCCESS; |
4287 | int display_once = 0; | |
d7c0a89a | 4288 | uint8_t use_vrf = 0; |
c9339663 CS |
4289 | |
4290 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); | |
4291 | ||
4292 | if (argv_find(argv, argc, "INTERFACE", &idx_intf)) | |
4293 | intf_name = argv[idx_intf]->arg; | |
4294 | ||
b1c3ae8c CS |
4295 | if (uj) |
4296 | json = json_object_new_object(); | |
4297 | ||
c9339663 | 4298 | if (vrf_name) { |
b1c3ae8c | 4299 | use_vrf = 1; |
c9339663 CS |
4300 | if (all_vrf) { |
4301 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
4302 | if (!ospf->oi_running) | |
4303 | continue; | |
4304 | ||
996c9314 LB |
4305 | ret = show_ip_ospf_interface_traffic_common( |
4306 | vty, ospf, intf_name, json, | |
4307 | display_once, use_vrf, uj); | |
c9339663 CS |
4308 | display_once = 1; |
4309 | } | |
b1c3ae8c CS |
4310 | |
4311 | if (uj) { | |
4312 | vty_out(vty, "%s\n", | |
996c9314 LB |
4313 | json_object_to_json_string_ext( |
4314 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c CS |
4315 | json_object_free(json); |
4316 | } | |
4317 | ||
c9339663 CS |
4318 | return ret; |
4319 | } | |
4320 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
b1c3ae8c CS |
4321 | if (ospf == NULL || !ospf->oi_running) { |
4322 | if (uj) | |
4323 | json_object_free(json); | |
c9339663 | 4324 | return CMD_SUCCESS; |
b1c3ae8c CS |
4325 | } |
4326 | ||
996c9314 LB |
4327 | ret = show_ip_ospf_interface_traffic_common( |
4328 | vty, ospf, intf_name, json, display_once, use_vrf, uj); | |
c9339663 CS |
4329 | } else { |
4330 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
b1c3ae8c CS |
4331 | if (ospf == NULL || !ospf->oi_running) { |
4332 | if (uj) | |
4333 | json_object_free(json); | |
c9339663 | 4334 | return CMD_SUCCESS; |
b1c3ae8c CS |
4335 | } |
4336 | ||
996c9314 LB |
4337 | ret = show_ip_ospf_interface_traffic_common( |
4338 | vty, ospf, intf_name, json, display_once, use_vrf, uj); | |
b1c3ae8c CS |
4339 | } |
4340 | ||
4341 | if (uj) { | |
996c9314 LB |
4342 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
4343 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 4344 | json_object_free(json); |
c9339663 CS |
4345 | } |
4346 | ||
4347 | return ret; | |
4348 | } | |
4349 | ||
4350 | ||
d62a17ae | 4351 | static void show_ip_ospf_neighbour_header(struct vty *vty) |
4352 | { | |
c84355a9 | 4353 | vty_out(vty, "\n%-15s %3s %-15s %9s %-15s %-32s %5s %5s %5s\n", |
d62a17ae | 4354 | "Neighbor ID", "Pri", "State", "Dead Time", "Address", |
4355 | "Interface", "RXmtL", "RqstL", "DBsmL"); | |
4356 | } | |
4357 | ||
4358 | static void show_ip_ospf_neighbor_sub(struct vty *vty, | |
4359 | struct ospf_interface *oi, | |
9f049418 | 4360 | json_object *json, bool use_json) |
d62a17ae | 4361 | { |
4362 | struct route_node *rn; | |
cef262c3 | 4363 | struct ospf_neighbor *nbr, *prev_nbr = NULL; |
d62a17ae | 4364 | char msgbuf[16]; |
96b663a3 | 4365 | char buf[PREFIX_STRLEN]; |
d62a17ae | 4366 | char timebuf[OSPF_TIME_DUMP_SIZE]; |
cef262c3 | 4367 | json_object *json_neighbor = NULL, *json_neigh_array = NULL; |
d62a17ae | 4368 | |
4369 | for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) { | |
4370 | if ((nbr = rn->info)) { | |
4371 | /* Do not show myself. */ | |
cef262c3 CS |
4372 | if (nbr == oi->nbr_self) |
4373 | continue; | |
4374 | /* Down state is not shown. */ | |
4375 | if (nbr->state == NSM_Down) | |
4376 | continue; | |
4377 | if (use_json) { | |
4378 | char neigh_str[INET_ADDRSTRLEN]; | |
4379 | ||
996c9314 LB |
4380 | if (prev_nbr |
4381 | && !IPV4_ADDR_SAME(&prev_nbr->src, | |
4382 | &nbr->src)) { | |
cef262c3 CS |
4383 | /* Start new neigh list */ |
4384 | json_neigh_array = NULL; | |
4385 | } | |
4386 | ||
996c9314 | 4387 | if (nbr->state == NSM_Attempt |
975a328e | 4388 | && nbr->router_id.s_addr == INADDR_ANY) |
6021c6c0 CS |
4389 | strlcpy(neigh_str, "neighbor", |
4390 | sizeof(neigh_str)); | |
cef262c3 | 4391 | else |
96b663a3 MS |
4392 | inet_ntop(AF_INET, &nbr->router_id, |
4393 | neigh_str, sizeof(neigh_str)); | |
cef262c3 CS |
4394 | |
4395 | json_object_object_get_ex(json, neigh_str, | |
4396 | &json_neigh_array); | |
4397 | ||
4398 | if (!json_neigh_array) { | |
996c9314 LB |
4399 | json_neigh_array = |
4400 | json_object_new_array(); | |
4401 | json_object_object_add( | |
4402 | json, neigh_str, | |
4403 | json_neigh_array); | |
d62a17ae | 4404 | } |
cef262c3 | 4405 | |
996c9314 | 4406 | json_neighbor = json_object_new_object(); |
cef262c3 CS |
4407 | |
4408 | ospf_nbr_state_message(nbr, msgbuf, 16); | |
4409 | ||
996c9314 | 4410 | json_object_int_add(json_neighbor, "priority", |
cef262c3 CS |
4411 | nbr->priority); |
4412 | json_object_string_add(json_neighbor, "state", | |
4413 | msgbuf); | |
b3d498f8 RW |
4414 | |
4415 | if (nbr->t_inactivity) { | |
4416 | long time_store; | |
4417 | ||
4418 | time_store = monotime_until( | |
4419 | &nbr->t_inactivity | |
4420 | ->u.sands, | |
4421 | NULL) | |
4422 | / 1000LL; | |
4423 | json_object_int_add(json_neighbor, | |
4424 | "deadTimeMsecs", | |
4425 | time_store); | |
4426 | } else { | |
4427 | json_object_string_add(json_neighbor, | |
4428 | "deadTimeMsecs", | |
4429 | "inactive"); | |
4430 | } | |
96b663a3 MS |
4431 | json_object_string_add( |
4432 | json_neighbor, "address", | |
4433 | inet_ntop(AF_INET, &nbr->src, | |
4434 | buf, sizeof(buf))); | |
cef262c3 CS |
4435 | json_object_string_add(json_neighbor, |
4436 | "ifaceName", | |
4437 | IF_NAME(oi)); | |
996c9314 LB |
4438 | json_object_int_add( |
4439 | json_neighbor, "retransmitCounter", | |
4440 | ospf_ls_retransmit_count(nbr)); | |
cef262c3 | 4441 | json_object_int_add(json_neighbor, |
996c9314 LB |
4442 | "requestCounter", |
4443 | ospf_ls_request_count(nbr)); | |
cef262c3 | 4444 | json_object_int_add(json_neighbor, |
996c9314 LB |
4445 | "dbSummaryCounter", |
4446 | ospf_db_summary_count(nbr)); | |
cef262c3 CS |
4447 | |
4448 | json_object_array_add(json_neigh_array, | |
4449 | json_neighbor); | |
4450 | } else { | |
4451 | ospf_nbr_state_message(nbr, msgbuf, 16); | |
4452 | ||
996c9314 | 4453 | if (nbr->state == NSM_Attempt |
975a328e | 4454 | && nbr->router_id.s_addr == INADDR_ANY) |
996c9314 LB |
4455 | vty_out(vty, "%-15s %3d %-15s ", "-", |
4456 | nbr->priority, msgbuf); | |
cef262c3 | 4457 | else |
96b663a3 MS |
4458 | vty_out(vty, "%-15pI4 %3d %-15s ", |
4459 | &nbr->router_id, | |
996c9314 | 4460 | nbr->priority, msgbuf); |
cef262c3 CS |
4461 | |
4462 | vty_out(vty, "%9s ", | |
4463 | ospf_timer_dump(nbr->t_inactivity, | |
4464 | timebuf, | |
4465 | sizeof(timebuf))); | |
96b663a3 | 4466 | vty_out(vty, "%-15pI4 ", &nbr->src); |
c84355a9 | 4467 | vty_out(vty, "%-32s %5ld %5ld %5d\n", |
cef262c3 CS |
4468 | IF_NAME(oi), |
4469 | ospf_ls_retransmit_count(nbr), | |
4470 | ospf_ls_request_count(nbr), | |
4471 | ospf_db_summary_count(nbr)); | |
d62a17ae | 4472 | } |
cef262c3 | 4473 | prev_nbr = nbr; |
d62a17ae | 4474 | } |
4475 | } | |
4476 | } | |
4477 | ||
4478 | static int show_ip_ospf_neighbor_common(struct vty *vty, struct ospf *ospf, | |
9f049418 | 4479 | json_object *json, bool use_json, |
d7c0a89a | 4480 | uint8_t use_vrf) |
d62a17ae | 4481 | { |
4482 | struct ospf_interface *oi; | |
4483 | struct listnode *node; | |
6282e124 | 4484 | json_object *json_vrf = NULL; |
2bc7673f | 4485 | json_object *json_nbr_sub = NULL; |
7c8ff89e | 4486 | |
b1c3ae8c CS |
4487 | if (use_json) { |
4488 | if (use_vrf) | |
4489 | json_vrf = json_object_new_object(); | |
4490 | else | |
4491 | json_vrf = json; | |
6282e124 | 4492 | json_nbr_sub = json_object_new_object(); |
b1c3ae8c | 4493 | } |
d62a17ae | 4494 | |
4495 | if (ospf->instance) { | |
4496 | if (use_json) | |
4497 | json_object_int_add(json, "ospfInstance", | |
4498 | ospf->instance); | |
4499 | else | |
4500 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
4501 | } | |
7c8ff89e | 4502 | |
b1c3ae8c CS |
4503 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); |
4504 | if (!use_json) | |
4505 | show_ip_ospf_neighbour_header(vty); | |
87bd50e8 | 4506 | |
2bc7673f CS |
4507 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) { |
4508 | if (ospf_interface_neighbor_count(oi) == 0) | |
4509 | continue; | |
2bc7673f CS |
4510 | show_ip_ospf_neighbor_sub(vty, oi, json_nbr_sub, use_json); |
4511 | } | |
718e3744 | 4512 | |
d62a17ae | 4513 | if (use_json) { |
996c9314 | 4514 | json_object_object_add(json_vrf, "neighbors", json_nbr_sub); |
b1c3ae8c CS |
4515 | if (use_vrf) { |
4516 | if (ospf->vrf_id == VRF_DEFAULT) | |
4517 | json_object_object_add(json, "default", | |
4518 | json_vrf); | |
4519 | else | |
4520 | json_object_object_add(json, ospf->name, | |
4521 | json_vrf); | |
4522 | } | |
d62a17ae | 4523 | } else |
4524 | vty_out(vty, "\n"); | |
7c8ff89e | 4525 | |
d62a17ae | 4526 | return CMD_SUCCESS; |
718e3744 | 4527 | } |
4528 | ||
7c8ff89e DS |
4529 | DEFUN (show_ip_ospf_neighbor, |
4530 | show_ip_ospf_neighbor_cmd, | |
b5a8894d | 4531 | "show ip ospf [vrf <NAME|all>] neighbor [json]", |
718e3744 | 4532 | SHOW_STR |
4533 | IP_STR | |
4534 | "OSPF information\n" | |
b5a8894d CS |
4535 | VRF_CMD_HELP_STR |
4536 | "All VRFs\n" | |
91756b38 | 4537 | "Neighbor list\n" |
9973d184 | 4538 | JSON_STR) |
718e3744 | 4539 | { |
d62a17ae | 4540 | struct ospf *ospf; |
9f049418 | 4541 | bool uj = use_json(argc, argv); |
b5a8894d CS |
4542 | struct listnode *node = NULL; |
4543 | char *vrf_name = NULL; | |
2951a7a4 | 4544 | bool all_vrf = false; |
b5a8894d CS |
4545 | int ret = CMD_SUCCESS; |
4546 | int inst = 0; | |
4547 | int idx_vrf = 0; | |
d7c0a89a | 4548 | uint8_t use_vrf = 0; |
b1c3ae8c | 4549 | json_object *json = NULL; |
718e3744 | 4550 | |
43b8d1d8 | 4551 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
7c8ff89e | 4552 | |
b1c3ae8c CS |
4553 | if (uj) |
4554 | json = json_object_new_object(); | |
b5a8894d CS |
4555 | |
4556 | /* vrf input is provided could be all or specific vrf*/ | |
4557 | if (vrf_name) { | |
b1c3ae8c | 4558 | use_vrf = 1; |
b5a8894d CS |
4559 | if (all_vrf) { |
4560 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
4561 | if (!ospf->oi_running) | |
4562 | continue; | |
996c9314 LB |
4563 | ret = show_ip_ospf_neighbor_common( |
4564 | vty, ospf, json, uj, use_vrf); | |
b1c3ae8c CS |
4565 | } |
4566 | ||
4567 | if (uj) { | |
4568 | vty_out(vty, "%s\n", | |
996c9314 LB |
4569 | json_object_to_json_string_ext( |
4570 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 4571 | json_object_free(json); |
9f049418 DS |
4572 | } else if (!ospf) |
4573 | vty_out(vty, "OSPF instance not found\n"); | |
b1c3ae8c | 4574 | |
b5a8894d CS |
4575 | return ret; |
4576 | } | |
b1c3ae8c | 4577 | |
b5a8894d | 4578 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); |
b1c3ae8c | 4579 | if (ospf == NULL || !ospf->oi_running) { |
9f049418 DS |
4580 | if (uj) { |
4581 | vty_out(vty, "%s\n", | |
4582 | json_object_to_json_string_ext( | |
4583 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 4584 | json_object_free(json); |
9f049418 DS |
4585 | } else |
4586 | vty_out(vty, "%% OSPF instance not found\n"); | |
4587 | ||
b5a8894d | 4588 | return CMD_SUCCESS; |
b1c3ae8c | 4589 | } |
b5a8894d CS |
4590 | } else { |
4591 | /* Display default ospf (instance 0) info */ | |
4592 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
b1c3ae8c | 4593 | if (ospf == NULL || !ospf->oi_running) { |
9f049418 DS |
4594 | if (uj) { |
4595 | vty_out(vty, "%s\n", | |
4596 | json_object_to_json_string_ext( | |
4597 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 4598 | json_object_free(json); |
9f049418 DS |
4599 | } else |
4600 | vty_out(vty, "%% OSPF instance not found\n"); | |
4601 | ||
b5a8894d | 4602 | return CMD_SUCCESS; |
b1c3ae8c | 4603 | } |
b5a8894d CS |
4604 | } |
4605 | ||
b1c3ae8c CS |
4606 | if (ospf) { |
4607 | ret = show_ip_ospf_neighbor_common(vty, ospf, json, uj, | |
4608 | use_vrf); | |
4609 | ||
4610 | if (uj) { | |
4611 | vty_out(vty, "%s\n", | |
996c9314 LB |
4612 | json_object_to_json_string_ext( |
4613 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c CS |
4614 | } |
4615 | } | |
4616 | ||
4617 | if (uj) | |
4618 | json_object_free(json); | |
b5a8894d CS |
4619 | |
4620 | return ret; | |
7c8ff89e DS |
4621 | } |
4622 | ||
4623 | ||
4624 | DEFUN (show_ip_ospf_instance_neighbor, | |
4625 | show_ip_ospf_instance_neighbor_cmd, | |
6147e2c6 | 4626 | "show ip ospf (1-65535) neighbor [json]", |
7c8ff89e DS |
4627 | SHOW_STR |
4628 | IP_STR | |
4629 | "OSPF information\n" | |
4630 | "Instance ID\n" | |
91756b38 | 4631 | "Neighbor list\n" |
9973d184 | 4632 | JSON_STR) |
7c8ff89e | 4633 | { |
d62a17ae | 4634 | int idx_number = 3; |
4635 | struct ospf *ospf; | |
d7c0a89a | 4636 | unsigned short instance = 0; |
9f049418 | 4637 | bool uj = use_json(argc, argv); |
b1c3ae8c CS |
4638 | json_object *json = NULL; |
4639 | int ret = CMD_SUCCESS; | |
7c8ff89e | 4640 | |
d62a17ae | 4641 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
409f98ab | 4642 | if (instance != ospf_instance) |
ac28e4ec CS |
4643 | return CMD_NOT_MY_INSTANCE; |
4644 | ||
409f98ab IR |
4645 | ospf = ospf_lookup_instance(instance); |
4646 | if (!ospf || !ospf->oi_running) | |
d62a17ae | 4647 | return CMD_SUCCESS; |
7c8ff89e | 4648 | |
b1c3ae8c CS |
4649 | if (uj) |
4650 | json = json_object_new_object(); | |
b5a8894d | 4651 | |
b1c3ae8c CS |
4652 | ret = show_ip_ospf_neighbor_common(vty, ospf, json, uj, 0); |
4653 | ||
4654 | if (uj) { | |
996c9314 LB |
4655 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
4656 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c CS |
4657 | json_object_free(json); |
4658 | } | |
4659 | ||
4660 | return ret; | |
7c8ff89e DS |
4661 | } |
4662 | ||
d62a17ae | 4663 | static int show_ip_ospf_neighbor_all_common(struct vty *vty, struct ospf *ospf, |
9f049418 | 4664 | json_object *json, bool use_json, |
d7c0a89a | 4665 | uint8_t use_vrf) |
d62a17ae | 4666 | { |
4667 | struct listnode *node; | |
4668 | struct ospf_interface *oi; | |
96b663a3 | 4669 | char buf[PREFIX_STRLEN]; |
b1c3ae8c | 4670 | json_object *json_vrf = NULL; |
d62a17ae | 4671 | json_object *json_neighbor_sub = NULL; |
7c8ff89e | 4672 | |
d62a17ae | 4673 | if (use_json) { |
b1c3ae8c CS |
4674 | if (use_vrf) |
4675 | json_vrf = json_object_new_object(); | |
4676 | else | |
4677 | json_vrf = json; | |
d62a17ae | 4678 | json_neighbor_sub = json_object_new_object(); |
b5a8894d | 4679 | } |
d62a17ae | 4680 | |
b1c3ae8c CS |
4681 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); |
4682 | if (!use_json) | |
4683 | show_ip_ospf_neighbour_header(vty); | |
4684 | ||
d62a17ae | 4685 | if (ospf->instance) { |
4686 | if (use_json) | |
b1c3ae8c | 4687 | json_object_int_add(json_vrf, "ospfInstance", |
d62a17ae | 4688 | ospf->instance); |
4689 | else | |
4690 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
4691 | } | |
4692 | ||
4693 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) { | |
4694 | struct listnode *nbr_node; | |
4695 | struct ospf_nbr_nbma *nbr_nbma; | |
4696 | ||
b1c3ae8c | 4697 | show_ip_ospf_neighbor_sub(vty, oi, json_vrf, use_json); |
d62a17ae | 4698 | |
4699 | /* print Down neighbor status */ | |
4700 | for (ALL_LIST_ELEMENTS_RO(oi->nbr_nbma, nbr_node, nbr_nbma)) { | |
4701 | if (nbr_nbma->nbr == NULL | |
4702 | || nbr_nbma->nbr->state == NSM_Down) { | |
4703 | if (use_json) { | |
4704 | json_object_int_add(json_neighbor_sub, | |
4705 | "nbrNbmaPriority", | |
4706 | nbr_nbma->priority); | |
4707 | json_object_boolean_true_add( | |
4708 | json_neighbor_sub, | |
4709 | "nbrNbmaDown"); | |
4710 | json_object_string_add( | |
4711 | json_neighbor_sub, | |
4712 | "nbrNbmaIfaceName", | |
4713 | IF_NAME(oi)); | |
4714 | json_object_int_add( | |
4715 | json_neighbor_sub, | |
4716 | "nbrNbmaRetransmitCounter", 0); | |
4717 | json_object_int_add( | |
4718 | json_neighbor_sub, | |
4719 | "nbrNbmaRequestCounter", 0); | |
4720 | json_object_int_add( | |
4721 | json_neighbor_sub, | |
4722 | "nbrNbmaDbSummaryCounter", 0); | |
4723 | json_object_object_add( | |
b1c3ae8c | 4724 | json_vrf, |
96b663a3 MS |
4725 | inet_ntop(AF_INET, |
4726 | &nbr_nbma->addr, buf, | |
4727 | sizeof(buf)), | |
d62a17ae | 4728 | json_neighbor_sub); |
4729 | } else { | |
4730 | vty_out(vty, "%-15s %3d %-15s %9s ", | |
4731 | "-", nbr_nbma->priority, "Down", | |
4732 | "-"); | |
4733 | vty_out(vty, | |
96b663a3 MS |
4734 | "%-32pI4 %-20s %5d %5d %5d\n", |
4735 | &nbr_nbma->addr, | |
d62a17ae | 4736 | IF_NAME(oi), 0, 0, 0); |
4737 | } | |
4738 | } | |
4739 | } | |
4740 | } | |
4741 | ||
4742 | if (use_json) { | |
b1c3ae8c CS |
4743 | if (use_vrf) { |
4744 | if (ospf->vrf_id == VRF_DEFAULT) | |
4745 | json_object_object_add(json, "default", | |
4746 | json_vrf); | |
4747 | else | |
4748 | json_object_object_add(json, ospf->name, | |
4749 | json_vrf); | |
4750 | } | |
d62a17ae | 4751 | } else |
4752 | vty_out(vty, "\n"); | |
4753 | ||
4754 | return CMD_SUCCESS; | |
718e3744 | 4755 | } |
4756 | ||
7c8ff89e DS |
4757 | DEFUN (show_ip_ospf_neighbor_all, |
4758 | show_ip_ospf_neighbor_all_cmd, | |
b5a8894d | 4759 | "show ip ospf [vrf <NAME|all>] neighbor all [json]", |
718e3744 | 4760 | SHOW_STR |
4761 | IP_STR | |
4762 | "OSPF information\n" | |
b5a8894d CS |
4763 | VRF_CMD_HELP_STR |
4764 | "All VRFs\n" | |
718e3744 | 4765 | "Neighbor list\n" |
91756b38 | 4766 | "include down status neighbor\n" |
9973d184 | 4767 | JSON_STR) |
7c8ff89e | 4768 | { |
d62a17ae | 4769 | struct ospf *ospf; |
9f049418 | 4770 | bool uj = use_json(argc, argv); |
b5a8894d CS |
4771 | struct listnode *node = NULL; |
4772 | char *vrf_name = NULL; | |
2951a7a4 | 4773 | bool all_vrf = false; |
b5a8894d CS |
4774 | int ret = CMD_SUCCESS; |
4775 | int inst = 0; | |
4776 | int idx_vrf = 0; | |
d7c0a89a | 4777 | uint8_t use_vrf = 0; |
b1c3ae8c | 4778 | json_object *json = NULL; |
7c8ff89e | 4779 | |
43b8d1d8 | 4780 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
7c8ff89e | 4781 | |
b1c3ae8c CS |
4782 | if (uj) |
4783 | json = json_object_new_object(); | |
b5a8894d CS |
4784 | |
4785 | /* vrf input is provided could be all or specific vrf*/ | |
4786 | if (vrf_name) { | |
b1c3ae8c | 4787 | use_vrf = 1; |
b5a8894d CS |
4788 | if (all_vrf) { |
4789 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
4790 | if (!ospf->oi_running) | |
4791 | continue; | |
996c9314 LB |
4792 | ret = show_ip_ospf_neighbor_all_common( |
4793 | vty, ospf, json, uj, use_vrf); | |
b1c3ae8c CS |
4794 | } |
4795 | ||
4796 | if (uj) { | |
4797 | vty_out(vty, "%s\n", | |
996c9314 LB |
4798 | json_object_to_json_string_ext( |
4799 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 4800 | json_object_free(json); |
b5a8894d | 4801 | } |
b1c3ae8c | 4802 | |
b5a8894d CS |
4803 | return ret; |
4804 | } | |
b1c3ae8c | 4805 | |
b5a8894d | 4806 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); |
b1c3ae8c CS |
4807 | if (ospf == NULL || !ospf->oi_running) { |
4808 | if (uj) | |
4809 | json_object_free(json); | |
b5a8894d | 4810 | return CMD_SUCCESS; |
b1c3ae8c | 4811 | } |
b5a8894d CS |
4812 | } else { |
4813 | /* Display default ospf (instance 0) info */ | |
4814 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
b1c3ae8c CS |
4815 | if (ospf == NULL || !ospf->oi_running) { |
4816 | if (uj) | |
4817 | json_object_free(json); | |
b5a8894d | 4818 | return CMD_SUCCESS; |
b1c3ae8c | 4819 | } |
b5a8894d CS |
4820 | } |
4821 | ||
b1c3ae8c CS |
4822 | if (ospf) { |
4823 | ret = show_ip_ospf_neighbor_all_common(vty, ospf, json, uj, | |
4824 | use_vrf); | |
4825 | if (uj) { | |
4826 | vty_out(vty, "%s\n", | |
996c9314 LB |
4827 | json_object_to_json_string_ext( |
4828 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c CS |
4829 | } |
4830 | } | |
4831 | ||
4832 | if (uj) | |
4833 | json_object_free(json); | |
b5a8894d CS |
4834 | |
4835 | return ret; | |
7c8ff89e DS |
4836 | } |
4837 | ||
4838 | DEFUN (show_ip_ospf_instance_neighbor_all, | |
4839 | show_ip_ospf_instance_neighbor_all_cmd, | |
6147e2c6 | 4840 | "show ip ospf (1-65535) neighbor all [json]", |
7c8ff89e DS |
4841 | SHOW_STR |
4842 | IP_STR | |
4843 | "OSPF information\n" | |
4844 | "Instance ID\n" | |
4845 | "Neighbor list\n" | |
91756b38 | 4846 | "include down status neighbor\n" |
9973d184 | 4847 | JSON_STR) |
718e3744 | 4848 | { |
d62a17ae | 4849 | int idx_number = 3; |
4850 | struct ospf *ospf; | |
d7c0a89a | 4851 | unsigned short instance = 0; |
9f049418 | 4852 | bool uj = use_json(argc, argv); |
b1c3ae8c CS |
4853 | json_object *json = NULL; |
4854 | int ret = CMD_SUCCESS; | |
7c8ff89e | 4855 | |
d62a17ae | 4856 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
409f98ab | 4857 | if (instance != ospf_instance) |
ac28e4ec CS |
4858 | return CMD_NOT_MY_INSTANCE; |
4859 | ||
409f98ab IR |
4860 | ospf = ospf_lookup_instance(instance); |
4861 | if (!ospf || !ospf->oi_running) | |
d62a17ae | 4862 | return CMD_SUCCESS; |
b1c3ae8c CS |
4863 | if (uj) |
4864 | json = json_object_new_object(); | |
4865 | ||
4866 | ret = show_ip_ospf_neighbor_all_common(vty, ospf, json, uj, 0); | |
4867 | ||
4868 | if (uj) { | |
4869 | vty_out(vty, "%s\n", json_object_to_json_string_ext( | |
4870 | json, JSON_C_TO_STRING_PRETTY)); | |
4871 | json_object_free(json); | |
4872 | } | |
7c8ff89e | 4873 | |
b1c3ae8c | 4874 | return ret; |
7c8ff89e DS |
4875 | } |
4876 | ||
d62a17ae | 4877 | static int show_ip_ospf_neighbor_int_common(struct vty *vty, struct ospf *ospf, |
4878 | int arg_base, | |
4879 | struct cmd_token **argv, | |
9f049418 | 4880 | bool use_json, uint8_t use_vrf) |
d62a17ae | 4881 | { |
4882 | struct interface *ifp; | |
4883 | struct route_node *rn; | |
4884 | json_object *json = NULL; | |
91756b38 | 4885 | |
d62a17ae | 4886 | if (use_json) |
4887 | json = json_object_new_object(); | |
d62a17ae | 4888 | |
4889 | if (ospf->instance) { | |
4890 | if (use_json) | |
4891 | json_object_int_add(json, "ospfInstance", | |
4892 | ospf->instance); | |
4893 | else | |
4894 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
4895 | } | |
4896 | ||
b1c3ae8c | 4897 | ospf_show_vrf_name(ospf, vty, json, use_vrf); |
87bd50e8 | 4898 | |
a36898e7 | 4899 | ifp = if_lookup_by_name(argv[arg_base]->arg, ospf->vrf_id); |
d62a17ae | 4900 | if (!ifp) { |
4901 | if (use_json) | |
4902 | json_object_boolean_true_add(json, "noSuchIface"); | |
4903 | else | |
4904 | vty_out(vty, "No such interface.\n"); | |
4905 | return CMD_WARNING; | |
4906 | } | |
4907 | ||
4908 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { | |
4909 | struct ospf_interface *oi = rn->info; | |
4910 | ||
4911 | if (oi == NULL) | |
4912 | continue; | |
4913 | ||
4914 | show_ip_ospf_neighbor_sub(vty, oi, json, use_json); | |
4915 | } | |
4916 | ||
4917 | if (use_json) { | |
9d303b37 DL |
4918 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
4919 | json, JSON_C_TO_STRING_PRETTY)); | |
d62a17ae | 4920 | json_object_free(json); |
4921 | } else | |
4922 | vty_out(vty, "\n"); | |
4923 | ||
4924 | return CMD_SUCCESS; | |
718e3744 | 4925 | } |
4926 | ||
7c8ff89e DS |
4927 | DEFUN (show_ip_ospf_neighbor_int, |
4928 | show_ip_ospf_neighbor_int_cmd, | |
03ed9f02 | 4929 | "show ip ospf [vrf <NAME>] neighbor IFNAME [json]", |
7c8ff89e DS |
4930 | SHOW_STR |
4931 | IP_STR | |
4932 | "OSPF information\n" | |
03ed9f02 | 4933 | VRF_CMD_HELP_STR |
7c8ff89e | 4934 | "Neighbor list\n" |
91756b38 | 4935 | "Interface name\n" |
9973d184 | 4936 | JSON_STR) |
7c8ff89e | 4937 | { |
d62a17ae | 4938 | struct ospf *ospf; |
03ed9f02 PG |
4939 | int idx_ifname = 0; |
4940 | int idx_vrf = 0; | |
9f049418 | 4941 | bool uj = use_json(argc, argv); |
b5a8894d CS |
4942 | int ret = CMD_SUCCESS; |
4943 | struct interface *ifp = NULL; | |
03ed9f02 PG |
4944 | char *vrf_name = NULL; |
4945 | vrf_id_t vrf_id = VRF_DEFAULT; | |
4946 | struct vrf *vrf = NULL; | |
4947 | ||
4948 | if (argv_find(argv, argc, "vrf", &idx_vrf)) | |
4949 | vrf_name = argv[idx_vrf + 1]->arg; | |
4950 | if (vrf_name && strmatch(vrf_name, VRF_DEFAULT_NAME)) | |
4951 | vrf_name = NULL; | |
4952 | if (vrf_name) { | |
4953 | vrf = vrf_lookup_by_name(vrf_name); | |
4954 | if (vrf) | |
4955 | vrf_id = vrf->vrf_id; | |
4956 | } | |
4957 | ospf = ospf_lookup_by_vrf_id(vrf_id); | |
4958 | ||
4959 | if (!ospf || !ospf->oi_running) | |
4960 | return ret; | |
7c8ff89e | 4961 | |
b5a8894d CS |
4962 | if (!uj) |
4963 | show_ip_ospf_neighbour_header(vty); | |
7c8ff89e | 4964 | |
03ed9f02 | 4965 | argv_find(argv, argc, "IFNAME", &idx_ifname); |
b5a8894d | 4966 | |
a36898e7 | 4967 | ifp = if_lookup_by_name(argv[idx_ifname]->arg, vrf_id); |
03ed9f02 PG |
4968 | if (!ifp) |
4969 | return ret; | |
4970 | ||
4971 | ret = show_ip_ospf_neighbor_int_common(vty, ospf, idx_ifname, | |
4972 | argv, uj, 0); | |
b5a8894d | 4973 | return ret; |
7c8ff89e DS |
4974 | } |
4975 | ||
4976 | DEFUN (show_ip_ospf_instance_neighbor_int, | |
4977 | show_ip_ospf_instance_neighbor_int_cmd, | |
6147e2c6 | 4978 | "show ip ospf (1-65535) neighbor IFNAME [json]", |
7c8ff89e DS |
4979 | SHOW_STR |
4980 | IP_STR | |
4981 | "OSPF information\n" | |
4982 | "Instance ID\n" | |
4983 | "Neighbor list\n" | |
91756b38 | 4984 | "Interface name\n" |
9973d184 | 4985 | JSON_STR) |
7c8ff89e | 4986 | { |
d62a17ae | 4987 | int idx_number = 3; |
b4e84315 | 4988 | int idx_ifname = 5; |
d62a17ae | 4989 | struct ospf *ospf; |
d7c0a89a | 4990 | unsigned short instance = 0; |
9f049418 | 4991 | bool uj = use_json(argc, argv); |
7c8ff89e | 4992 | |
b5a8894d CS |
4993 | if (!uj) |
4994 | show_ip_ospf_neighbour_header(vty); | |
4995 | ||
d62a17ae | 4996 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
409f98ab | 4997 | if (instance != ospf_instance) |
ac28e4ec CS |
4998 | return CMD_NOT_MY_INSTANCE; |
4999 | ||
409f98ab IR |
5000 | ospf = ospf_lookup_instance(instance); |
5001 | if (!ospf || !ospf->oi_running) | |
d62a17ae | 5002 | return CMD_SUCCESS; |
7c8ff89e | 5003 | |
b5a8894d CS |
5004 | if (!uj) |
5005 | show_ip_ospf_neighbour_header(vty); | |
5006 | ||
996c9314 LB |
5007 | return show_ip_ospf_neighbor_int_common(vty, ospf, idx_ifname, argv, uj, |
5008 | 0); | |
718e3744 | 5009 | } |
5010 | ||
d62a17ae | 5011 | static void show_ip_ospf_nbr_nbma_detail_sub(struct vty *vty, |
5012 | struct ospf_interface *oi, | |
5013 | struct ospf_nbr_nbma *nbr_nbma, | |
9f049418 | 5014 | bool use_json, json_object *json) |
d62a17ae | 5015 | { |
5016 | char timebuf[OSPF_TIME_DUMP_SIZE]; | |
96b663a3 | 5017 | char buf[PREFIX_STRLEN]; |
d62a17ae | 5018 | json_object *json_sub = NULL; |
718e3744 | 5019 | |
d62a17ae | 5020 | if (use_json) |
5021 | json_sub = json_object_new_object(); | |
5022 | else /* Show neighbor ID. */ | |
5023 | vty_out(vty, " Neighbor %s,", "-"); | |
5024 | ||
5025 | /* Show interface address. */ | |
5026 | if (use_json) | |
5027 | json_object_string_add(json_sub, "ifaceAddress", | |
96b663a3 MS |
5028 | inet_ntop(AF_INET, &nbr_nbma->addr, |
5029 | buf, sizeof(buf))); | |
d62a17ae | 5030 | else |
96b663a3 MS |
5031 | vty_out(vty, " interface address %pI4\n", |
5032 | &nbr_nbma->addr); | |
d62a17ae | 5033 | |
5034 | /* Show Area ID. */ | |
5035 | if (use_json) { | |
5036 | json_object_string_add(json_sub, "areaId", | |
5037 | ospf_area_desc_string(oi->area)); | |
5038 | json_object_string_add(json_sub, "iface", IF_NAME(oi)); | |
5039 | } else | |
5040 | vty_out(vty, " In the area %s via interface %s\n", | |
5041 | ospf_area_desc_string(oi->area), IF_NAME(oi)); | |
5042 | ||
5043 | /* Show neighbor priority and state. */ | |
5044 | if (use_json) { | |
5045 | json_object_int_add(json_sub, "nbrPriority", | |
5046 | nbr_nbma->priority); | |
5047 | json_object_string_add(json_sub, "nbrState", "down"); | |
5048 | } else | |
5049 | vty_out(vty, " Neighbor priority is %d, State is %s,", | |
5050 | nbr_nbma->priority, "Down"); | |
5051 | ||
5052 | /* Show state changes. */ | |
5053 | if (use_json) | |
5054 | json_object_int_add(json_sub, "stateChangeCounter", | |
5055 | nbr_nbma->state_change); | |
5056 | else | |
5057 | vty_out(vty, " %d state changes\n", nbr_nbma->state_change); | |
5058 | ||
5059 | /* Show PollInterval */ | |
5060 | if (use_json) | |
5061 | json_object_int_add(json_sub, "pollInterval", nbr_nbma->v_poll); | |
5062 | else | |
5063 | vty_out(vty, " Poll interval %d\n", nbr_nbma->v_poll); | |
5064 | ||
5065 | /* Show poll-interval timer. */ | |
b575a12c A |
5066 | if (nbr_nbma->t_poll) { |
5067 | if (use_json) { | |
5068 | long time_store; | |
5069 | time_store = monotime_until(&nbr_nbma->t_poll->u.sands, | |
5070 | NULL) / 1000LL; | |
5071 | json_object_int_add(json_sub, | |
5072 | "pollIntervalTimerDueMsec", | |
5073 | time_store); | |
5074 | } else | |
5075 | vty_out(vty, " Poll timer due in %s\n", | |
5076 | ospf_timer_dump(nbr_nbma->t_poll, timebuf, | |
5077 | sizeof(timebuf))); | |
5078 | } | |
d62a17ae | 5079 | |
5080 | /* Show poll-interval timer thread. */ | |
5081 | if (use_json) { | |
5082 | if (nbr_nbma->t_poll != NULL) | |
5083 | json_object_string_add(json_sub, | |
5084 | "pollIntervalTimerThread", "on"); | |
5085 | } else | |
5086 | vty_out(vty, " Thread Poll Timer %s\n", | |
5087 | nbr_nbma->t_poll != NULL ? "on" : "off"); | |
5088 | ||
5089 | if (use_json) | |
5090 | json_object_object_add(json, "noNbrId", json_sub); | |
5091 | } | |
5092 | ||
5093 | static void show_ip_ospf_neighbor_detail_sub(struct vty *vty, | |
5094 | struct ospf_interface *oi, | |
5095 | struct ospf_neighbor *nbr, | |
cb0b2ac6 | 5096 | struct ospf_neighbor *prev_nbr, |
9f049418 | 5097 | json_object *json, bool use_json) |
d62a17ae | 5098 | { |
5099 | char timebuf[OSPF_TIME_DUMP_SIZE]; | |
cb0b2ac6 CS |
5100 | json_object *json_neigh = NULL, *json_neigh_array = NULL; |
5101 | char neigh_str[INET_ADDRSTRLEN] = {0}; | |
96b663a3 | 5102 | char buf[PREFIX_STRLEN]; |
d62a17ae | 5103 | |
cb0b2ac6 CS |
5104 | if (use_json) { |
5105 | if (prev_nbr && | |
5106 | !IPV4_ADDR_SAME(&prev_nbr->src, &nbr->src)) { | |
5107 | json_neigh_array = NULL; | |
5108 | } | |
5109 | ||
975a328e DA |
5110 | if (nbr->state == NSM_Attempt |
5111 | && nbr->router_id.s_addr == INADDR_ANY) | |
cb0b2ac6 CS |
5112 | strlcpy(neigh_str, "noNbrId", sizeof(neigh_str)); |
5113 | else | |
96b663a3 MS |
5114 | inet_ntop(AF_INET, &nbr->router_id, |
5115 | neigh_str, sizeof(neigh_str)); | |
cb0b2ac6 CS |
5116 | |
5117 | json_object_object_get_ex(json, neigh_str, &json_neigh_array); | |
5118 | ||
5119 | if (!json_neigh_array) { | |
5120 | json_neigh_array = json_object_new_array(); | |
5121 | json_object_object_add(json, neigh_str, | |
5122 | json_neigh_array); | |
5123 | } | |
5124 | ||
5125 | json_neigh = json_object_new_object(); | |
5126 | ||
5127 | } else { | |
d62a17ae | 5128 | /* Show neighbor ID. */ |
975a328e DA |
5129 | if (nbr->state == NSM_Attempt |
5130 | && nbr->router_id.s_addr == INADDR_ANY) | |
d62a17ae | 5131 | vty_out(vty, " Neighbor %s,", "-"); |
5132 | else | |
96b663a3 MS |
5133 | vty_out(vty, " Neighbor %pI4,", |
5134 | &nbr->router_id); | |
d62a17ae | 5135 | } |
5136 | ||
5137 | /* Show interface address. */ | |
5138 | if (use_json) | |
cb0b2ac6 | 5139 | json_object_string_add(json_neigh, "ifaceAddress", |
96b663a3 MS |
5140 | inet_ntop(AF_INET, |
5141 | &nbr->address.u.prefix4, | |
5142 | buf, sizeof(buf))); | |
d62a17ae | 5143 | else |
96b663a3 MS |
5144 | vty_out(vty, " interface address %pI4\n", |
5145 | &nbr->address.u.prefix4); | |
d62a17ae | 5146 | |
5147 | /* Show Area ID. */ | |
5148 | if (use_json) { | |
cb0b2ac6 | 5149 | json_object_string_add(json_neigh, "areaId", |
d62a17ae | 5150 | ospf_area_desc_string(oi->area)); |
cb0b2ac6 | 5151 | json_object_string_add(json_neigh, "ifaceName", oi->ifp->name); |
d62a17ae | 5152 | } else |
5153 | vty_out(vty, " In the area %s via interface %s\n", | |
5154 | ospf_area_desc_string(oi->area), oi->ifp->name); | |
5155 | ||
5156 | /* Show neighbor priority and state. */ | |
5157 | if (use_json) { | |
cb0b2ac6 | 5158 | json_object_int_add(json_neigh, "nbrPriority", nbr->priority); |
d62a17ae | 5159 | json_object_string_add( |
cb0b2ac6 | 5160 | json_neigh, "nbrState", |
d62a17ae | 5161 | lookup_msg(ospf_nsm_state_msg, nbr->state, NULL)); |
5162 | } else | |
5163 | vty_out(vty, " Neighbor priority is %d, State is %s,", | |
5164 | nbr->priority, | |
5165 | lookup_msg(ospf_nsm_state_msg, nbr->state, NULL)); | |
5166 | ||
5167 | /* Show state changes. */ | |
5168 | if (use_json) | |
cb0b2ac6 | 5169 | json_object_int_add(json_neigh, "stateChangeCounter", |
d62a17ae | 5170 | nbr->state_change); |
5171 | else | |
5172 | vty_out(vty, " %d state changes\n", nbr->state_change); | |
5173 | ||
5174 | if (nbr->ts_last_progress.tv_sec || nbr->ts_last_progress.tv_usec) { | |
5175 | struct timeval res; | |
5176 | long time_store; | |
5177 | ||
5178 | time_store = | |
5179 | monotime_since(&nbr->ts_last_progress, &res) / 1000LL; | |
5180 | if (use_json) { | |
cb0b2ac6 | 5181 | json_object_int_add(json_neigh, "lastPrgrsvChangeMsec", |
d62a17ae | 5182 | time_store); |
5183 | } else { | |
5184 | vty_out(vty, | |
5185 | " Most recent state change statistics:\n"); | |
5186 | vty_out(vty, " Progressive change %s ago\n", | |
5187 | ospf_timeval_dump(&res, timebuf, | |
5188 | sizeof(timebuf))); | |
5189 | } | |
5190 | } | |
5191 | ||
5192 | if (nbr->ts_last_regress.tv_sec || nbr->ts_last_regress.tv_usec) { | |
5193 | struct timeval res; | |
5194 | long time_store; | |
5195 | ||
5196 | time_store = | |
5197 | monotime_since(&nbr->ts_last_regress, &res) / 1000LL; | |
5198 | if (use_json) { | |
cb0b2ac6 | 5199 | json_object_int_add(json_neigh, |
d62a17ae | 5200 | "lastRegressiveChangeMsec", |
5201 | time_store); | |
5202 | if (nbr->last_regress_str) | |
5203 | json_object_string_add( | |
cb0b2ac6 CS |
5204 | json_neigh, |
5205 | "lastRegressiveChangeReason", | |
d62a17ae | 5206 | nbr->last_regress_str); |
5207 | } else { | |
5208 | vty_out(vty, | |
5209 | " Regressive change %s ago, due to %s\n", | |
5210 | ospf_timeval_dump(&res, timebuf, | |
5211 | sizeof(timebuf)), | |
5212 | (nbr->last_regress_str ? nbr->last_regress_str | |
5213 | : "??")); | |
5214 | } | |
5215 | } | |
5216 | ||
5217 | /* Show Designated Rotuer ID. */ | |
5218 | if (use_json) | |
cb0b2ac6 | 5219 | json_object_string_add(json_neigh, "routerDesignatedId", |
96b663a3 MS |
5220 | inet_ntop(AF_INET, &nbr->d_router, |
5221 | buf, sizeof(buf))); | |
d62a17ae | 5222 | else |
96b663a3 | 5223 | vty_out(vty, " DR is %pI4,", &nbr->d_router); |
d62a17ae | 5224 | |
5225 | /* Show Backup Designated Rotuer ID. */ | |
5226 | if (use_json) | |
cb0b2ac6 | 5227 | json_object_string_add(json_neigh, "routerDesignatedBackupId", |
96b663a3 MS |
5228 | inet_ntop(AF_INET, &nbr->bd_router, |
5229 | buf, sizeof(buf))); | |
d62a17ae | 5230 | else |
96b663a3 | 5231 | vty_out(vty, " BDR is %pI4\n", &nbr->bd_router); |
d62a17ae | 5232 | |
5233 | /* Show options. */ | |
5234 | if (use_json) { | |
cb0b2ac6 CS |
5235 | json_object_int_add(json_neigh, "optionsCounter", nbr->options); |
5236 | json_object_string_add(json_neigh, "optionsList", | |
d62a17ae | 5237 | ospf_options_dump(nbr->options)); |
5238 | } else | |
5239 | vty_out(vty, " Options %d %s\n", nbr->options, | |
5240 | ospf_options_dump(nbr->options)); | |
5241 | ||
5242 | /* Show Router Dead interval timer. */ | |
5243 | if (use_json) { | |
5244 | if (nbr->t_inactivity) { | |
5245 | long time_store; | |
5246 | time_store = monotime_until(&nbr->t_inactivity->u.sands, | |
5247 | NULL) | |
5248 | / 1000LL; | |
cb0b2ac6 | 5249 | json_object_int_add(json_neigh, |
d62a17ae | 5250 | "routerDeadIntervalTimerDueMsec", |
5251 | time_store); | |
5252 | } else | |
5253 | json_object_int_add( | |
cb0b2ac6 CS |
5254 | json_neigh, |
5255 | "routerDeadIntervalTimerDueMsec", -1); | |
d62a17ae | 5256 | } else |
5257 | vty_out(vty, " Dead timer due in %s\n", | |
5258 | ospf_timer_dump(nbr->t_inactivity, timebuf, | |
5259 | sizeof(timebuf))); | |
5260 | ||
5261 | /* Show Database Summary list. */ | |
5262 | if (use_json) | |
cb0b2ac6 | 5263 | json_object_int_add(json_neigh, "databaseSummaryListCounter", |
d62a17ae | 5264 | ospf_db_summary_count(nbr)); |
5265 | else | |
5266 | vty_out(vty, " Database Summary List %d\n", | |
5267 | ospf_db_summary_count(nbr)); | |
5268 | ||
5269 | /* Show Link State Request list. */ | |
5270 | if (use_json) | |
cb0b2ac6 | 5271 | json_object_int_add(json_neigh, "linkStateRequestListCounter", |
d62a17ae | 5272 | ospf_ls_request_count(nbr)); |
5273 | else | |
5274 | vty_out(vty, " Link State Request List %ld\n", | |
5275 | ospf_ls_request_count(nbr)); | |
5276 | ||
5277 | /* Show Link State Retransmission list. */ | |
5278 | if (use_json) | |
cb0b2ac6 | 5279 | json_object_int_add(json_neigh, |
d62a17ae | 5280 | "linkStateRetransmissionListCounter", |
5281 | ospf_ls_retransmit_count(nbr)); | |
5282 | else | |
5283 | vty_out(vty, " Link State Retransmission List %ld\n", | |
5284 | ospf_ls_retransmit_count(nbr)); | |
5285 | ||
5286 | /* Show inactivity timer thread. */ | |
5287 | if (use_json) { | |
5288 | if (nbr->t_inactivity != NULL) | |
cb0b2ac6 | 5289 | json_object_string_add(json_neigh, |
d62a17ae | 5290 | "threadInactivityTimer", "on"); |
5291 | } else | |
5292 | vty_out(vty, " Thread Inactivity Timer %s\n", | |
5293 | nbr->t_inactivity != NULL ? "on" : "off"); | |
5294 | ||
5295 | /* Show Database Description retransmission thread. */ | |
5296 | if (use_json) { | |
5297 | if (nbr->t_db_desc != NULL) | |
5298 | json_object_string_add( | |
cb0b2ac6 | 5299 | json_neigh, |
d62a17ae | 5300 | "threadDatabaseDescriptionRetransmission", |
5301 | "on"); | |
5302 | } else | |
5303 | vty_out(vty, | |
5304 | " Thread Database Description Retransmision %s\n", | |
5305 | nbr->t_db_desc != NULL ? "on" : "off"); | |
5306 | ||
5307 | /* Show Link State Request Retransmission thread. */ | |
5308 | if (use_json) { | |
5309 | if (nbr->t_ls_req != NULL) | |
5310 | json_object_string_add( | |
cb0b2ac6 | 5311 | json_neigh, |
d62a17ae | 5312 | "threadLinkStateRequestRetransmission", "on"); |
5313 | } else | |
5314 | vty_out(vty, | |
5315 | " Thread Link State Request Retransmission %s\n", | |
5316 | nbr->t_ls_req != NULL ? "on" : "off"); | |
5317 | ||
5318 | /* Show Link State Update Retransmission thread. */ | |
5319 | if (use_json) { | |
5320 | if (nbr->t_ls_upd != NULL) | |
5321 | json_object_string_add( | |
cb0b2ac6 CS |
5322 | json_neigh, |
5323 | "threadLinkStateUpdateRetransmission", | |
d62a17ae | 5324 | "on"); |
5325 | } else | |
5326 | vty_out(vty, | |
5327 | " Thread Link State Update Retransmission %s\n\n", | |
5328 | nbr->t_ls_upd != NULL ? "on" : "off"); | |
5329 | ||
abd5b8c7 | 5330 | if (!use_json) { |
5331 | vty_out(vty, " Graceful restart Helper info:\n"); | |
5332 | ||
5333 | if (OSPF_GR_IS_ACTIVE_HELPER(nbr)) { | |
5334 | vty_out(vty, | |
5335 | " Graceful Restart HELPER Status : Inprogress.\n"); | |
5336 | ||
5337 | vty_out(vty, | |
5338 | " Graceful Restart grace period time: %d (seconds).\n", | |
5339 | nbr->gr_helper_info.recvd_grace_period); | |
5340 | vty_out(vty, " Graceful Restart reason: %s.\n", | |
d05d5280 MS |
5341 | ospf_restart_reason2str( |
5342 | nbr->gr_helper_info.gr_restart_reason)); | |
abd5b8c7 | 5343 | } else { |
5344 | vty_out(vty, | |
5345 | " Graceful Restart HELPER Status : None\n"); | |
5346 | } | |
5347 | ||
5348 | if (nbr->gr_helper_info.rejected_reason | |
5349 | != OSPF_HELPER_REJECTED_NONE) | |
5350 | vty_out(vty, " Helper rejected reason: %s.\n", | |
d05d5280 MS |
5351 | ospf_rejected_reason2str( |
5352 | nbr->gr_helper_info.rejected_reason)); | |
abd5b8c7 | 5353 | |
5354 | if (nbr->gr_helper_info.helper_exit_reason | |
5355 | != OSPF_GR_HELPER_EXIT_NONE) | |
5356 | vty_out(vty, " Last helper exit reason: %s.\n\n", | |
d05d5280 MS |
5357 | ospf_exit_reason2str( |
5358 | nbr->gr_helper_info.helper_exit_reason)); | |
abd5b8c7 | 5359 | else |
5360 | vty_out(vty, "\n"); | |
5361 | } else { | |
5362 | json_object_string_add(json_neigh, "grHelperStatus", | |
5363 | OSPF_GR_IS_ACTIVE_HELPER(nbr) ? | |
5364 | "Inprogress" | |
5365 | : "None"); | |
5366 | if (OSPF_GR_IS_ACTIVE_HELPER(nbr)) { | |
5367 | json_object_int_add( | |
5368 | json_neigh, "graceInterval", | |
5369 | nbr->gr_helper_info.recvd_grace_period); | |
5370 | json_object_string_add( | |
5371 | json_neigh, "grRestartReason", | |
d05d5280 MS |
5372 | ospf_restart_reason2str( |
5373 | nbr->gr_helper_info.gr_restart_reason)); | |
abd5b8c7 | 5374 | } |
5375 | ||
5376 | if (nbr->gr_helper_info.rejected_reason | |
5377 | != OSPF_HELPER_REJECTED_NONE) | |
5378 | json_object_string_add( | |
5379 | json_neigh, "helperRejectReason", | |
d05d5280 MS |
5380 | ospf_rejected_reason2str( |
5381 | nbr->gr_helper_info.rejected_reason)); | |
abd5b8c7 | 5382 | |
5383 | if (nbr->gr_helper_info.helper_exit_reason | |
5384 | != OSPF_GR_HELPER_EXIT_NONE) | |
5385 | json_object_string_add( | |
5386 | json_neigh, "helperExitReason", | |
d05d5280 MS |
5387 | ospf_exit_reason2str( |
5388 | nbr->gr_helper_info | |
5389 | .helper_exit_reason)); | |
abd5b8c7 | 5390 | } |
5391 | ||
659f4e40 | 5392 | bfd_sess_show(vty, json_neigh, nbr->bfd_session); |
cb0b2ac6 CS |
5393 | |
5394 | if (use_json) | |
5395 | json_object_array_add(json_neigh_array, json_neigh); | |
d62a17ae | 5396 | |
d62a17ae | 5397 | } |
5398 | ||
5399 | static int show_ip_ospf_neighbor_id_common(struct vty *vty, struct ospf *ospf, | |
986b87cb | 5400 | struct in_addr *router_id, |
9f049418 | 5401 | bool use_json, uint8_t use_vrf) |
d62a17ae | 5402 | { |
5403 | struct listnode *node; | |
5404 | struct ospf_neighbor *nbr; | |
5405 | struct ospf_interface *oi; | |
d62a17ae | 5406 | json_object *json = NULL; |
5407 | ||
5408 | if (use_json) | |
5409 | json = json_object_new_object(); | |
5410 | ||
5411 | if (ospf->instance) { | |
5412 | if (use_json) | |
5413 | json_object_int_add(json, "ospfInstance", | |
5414 | ospf->instance); | |
5415 | else | |
5416 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
5417 | } | |
5418 | ||
b1c3ae8c | 5419 | ospf_show_vrf_name(ospf, vty, json, use_vrf); |
87bd50e8 | 5420 | |
d62a17ae | 5421 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) { |
986b87cb | 5422 | if ((nbr = ospf_nbr_lookup_by_routerid(oi->nbrs, router_id))) { |
cb0b2ac6 CS |
5423 | show_ip_ospf_neighbor_detail_sub(vty, oi, nbr, NULL, |
5424 | json, use_json); | |
d62a17ae | 5425 | } |
5426 | } | |
5427 | ||
5428 | if (use_json) { | |
9d303b37 DL |
5429 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
5430 | json, JSON_C_TO_STRING_PRETTY)); | |
d62a17ae | 5431 | json_object_free(json); |
5432 | } else | |
5433 | vty_out(vty, "\n"); | |
5434 | ||
5435 | return CMD_SUCCESS; | |
718e3744 | 5436 | } |
5437 | ||
986b87cb | 5438 | DEFPY (show_ip_ospf_neighbor_id, |
7c8ff89e | 5439 | show_ip_ospf_neighbor_id_cmd, |
986b87cb | 5440 | "show ip ospf neighbor A.B.C.D$router_id [json$json]", |
718e3744 | 5441 | SHOW_STR |
5442 | IP_STR | |
5443 | "OSPF information\n" | |
5444 | "Neighbor list\n" | |
3ac237f8 | 5445 | "Neighbor ID\n" |
9973d184 | 5446 | JSON_STR) |
718e3744 | 5447 | { |
d62a17ae | 5448 | struct ospf *ospf; |
986b87cb | 5449 | struct listnode *node; |
b5a8894d | 5450 | int ret = CMD_SUCCESS; |
7c8ff89e | 5451 | |
b5a8894d CS |
5452 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { |
5453 | if (!ospf->oi_running) | |
5454 | continue; | |
986b87cb RW |
5455 | ret = show_ip_ospf_neighbor_id_common(vty, ospf, &router_id, |
5456 | !!json, 0); | |
b5a8894d | 5457 | } |
7c8ff89e | 5458 | |
b5a8894d | 5459 | return ret; |
7c8ff89e DS |
5460 | } |
5461 | ||
986b87cb | 5462 | DEFPY (show_ip_ospf_instance_neighbor_id, |
7c8ff89e | 5463 | show_ip_ospf_instance_neighbor_id_cmd, |
986b87cb | 5464 | "show ip ospf (1-65535)$instance neighbor A.B.C.D$router_id [json$json]", |
7c8ff89e DS |
5465 | SHOW_STR |
5466 | IP_STR | |
5467 | "OSPF information\n" | |
5468 | "Instance ID\n" | |
5469 | "Neighbor list\n" | |
3ac237f8 | 5470 | "Neighbor ID\n" |
9973d184 | 5471 | JSON_STR) |
7c8ff89e | 5472 | { |
d62a17ae | 5473 | struct ospf *ospf; |
7c8ff89e | 5474 | |
409f98ab | 5475 | if (instance != ospf_instance) |
ac28e4ec CS |
5476 | return CMD_NOT_MY_INSTANCE; |
5477 | ||
409f98ab IR |
5478 | ospf = ospf_lookup_instance(instance); |
5479 | if (!ospf || !ospf->oi_running) | |
d62a17ae | 5480 | return CMD_SUCCESS; |
7c8ff89e | 5481 | |
986b87cb RW |
5482 | return show_ip_ospf_neighbor_id_common(vty, ospf, &router_id, !!json, |
5483 | 0); | |
7c8ff89e DS |
5484 | } |
5485 | ||
d62a17ae | 5486 | static int show_ip_ospf_neighbor_detail_common(struct vty *vty, |
5487 | struct ospf *ospf, | |
9f049418 | 5488 | json_object *json, bool use_json, |
d7c0a89a | 5489 | uint8_t use_vrf) |
d62a17ae | 5490 | { |
5491 | struct ospf_interface *oi; | |
5492 | struct listnode *node; | |
b1c3ae8c | 5493 | json_object *json_vrf = NULL; |
cb0b2ac6 | 5494 | json_object *json_nbr_sub = NULL; |
d62a17ae | 5495 | |
b1c3ae8c CS |
5496 | if (use_json) { |
5497 | if (use_vrf) | |
5498 | json_vrf = json_object_new_object(); | |
5499 | else | |
5500 | json_vrf = json; | |
cb0b2ac6 CS |
5501 | |
5502 | json_nbr_sub = json_object_new_object(); | |
b1c3ae8c | 5503 | } |
cb0b2ac6 | 5504 | |
d62a17ae | 5505 | if (ospf->instance) { |
5506 | if (use_json) | |
cb0b2ac6 | 5507 | json_object_int_add(json, "ospfInstance", |
d62a17ae | 5508 | ospf->instance); |
5509 | else | |
5510 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
5511 | } | |
5512 | ||
b1c3ae8c | 5513 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); |
87bd50e8 | 5514 | |
d62a17ae | 5515 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) { |
5516 | struct route_node *rn; | |
cb0b2ac6 | 5517 | struct ospf_neighbor *nbr, *prev_nbr = NULL; |
d62a17ae | 5518 | |
5519 | for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) { | |
5520 | if ((nbr = rn->info)) { | |
5521 | if (nbr != oi->nbr_self) { | |
5522 | if (nbr->state != NSM_Down) { | |
5523 | show_ip_ospf_neighbor_detail_sub( | |
cb0b2ac6 CS |
5524 | vty, oi, nbr, prev_nbr, |
5525 | json_nbr_sub, use_json); | |
d62a17ae | 5526 | } |
5527 | } | |
cb0b2ac6 | 5528 | prev_nbr = nbr; |
d62a17ae | 5529 | } |
5530 | } | |
5531 | } | |
5532 | ||
5533 | if (use_json) { | |
cb0b2ac6 CS |
5534 | json_object_object_add(json_vrf, "neighbors", |
5535 | json_nbr_sub); | |
b1c3ae8c CS |
5536 | if (use_vrf) { |
5537 | if (ospf->vrf_id == VRF_DEFAULT) | |
5538 | json_object_object_add(json, "default", | |
5539 | json_vrf); | |
5540 | else | |
5541 | json_object_object_add(json, ospf->name, | |
5542 | json_vrf); | |
5543 | } | |
d62a17ae | 5544 | } else |
5545 | vty_out(vty, "\n"); | |
5546 | ||
5547 | return CMD_SUCCESS; | |
718e3744 | 5548 | } |
5549 | ||
7c8ff89e DS |
5550 | DEFUN (show_ip_ospf_neighbor_detail, |
5551 | show_ip_ospf_neighbor_detail_cmd, | |
b5a8894d | 5552 | "show ip ospf [vrf <NAME|all>] neighbor detail [json]", |
718e3744 | 5553 | SHOW_STR |
5554 | IP_STR | |
5555 | "OSPF information\n" | |
b5a8894d CS |
5556 | VRF_CMD_HELP_STR |
5557 | "All VRFs\n" | |
718e3744 | 5558 | "Neighbor list\n" |
3ac237f8 | 5559 | "detail of all neighbors\n" |
9973d184 | 5560 | JSON_STR) |
718e3744 | 5561 | { |
d62a17ae | 5562 | struct ospf *ospf; |
9f049418 | 5563 | bool uj = use_json(argc, argv); |
b5a8894d CS |
5564 | struct listnode *node = NULL; |
5565 | char *vrf_name = NULL; | |
2951a7a4 | 5566 | bool all_vrf = false; |
b5a8894d CS |
5567 | int ret = CMD_SUCCESS; |
5568 | int inst = 0; | |
5569 | int idx_vrf = 0; | |
d7c0a89a | 5570 | uint8_t use_vrf = 0; |
b1c3ae8c | 5571 | json_object *json = NULL; |
7c8ff89e | 5572 | |
43b8d1d8 | 5573 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
7c8ff89e | 5574 | |
b1c3ae8c CS |
5575 | if (uj) |
5576 | json = json_object_new_object(); | |
5577 | ||
b5a8894d CS |
5578 | /* vrf input is provided could be all or specific vrf*/ |
5579 | if (vrf_name) { | |
b1c3ae8c | 5580 | use_vrf = 1; |
b5a8894d CS |
5581 | if (all_vrf) { |
5582 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
5583 | if (!ospf->oi_running) | |
5584 | continue; | |
996c9314 LB |
5585 | ret = show_ip_ospf_neighbor_detail_common( |
5586 | vty, ospf, json, uj, use_vrf); | |
b1c3ae8c CS |
5587 | } |
5588 | if (uj) { | |
5589 | vty_out(vty, "%s\n", | |
996c9314 LB |
5590 | json_object_to_json_string_ext( |
5591 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 5592 | json_object_free(json); |
b5a8894d | 5593 | } |
b1c3ae8c | 5594 | |
b5a8894d CS |
5595 | return ret; |
5596 | } | |
5597 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
b1c3ae8c CS |
5598 | if (ospf == NULL || !ospf->oi_running) { |
5599 | if (uj) | |
5600 | json_object_free(json); | |
b5a8894d | 5601 | return CMD_SUCCESS; |
b1c3ae8c | 5602 | } |
b5a8894d CS |
5603 | } else { |
5604 | /* Display default ospf (instance 0) info */ | |
5605 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
b1c3ae8c CS |
5606 | if (ospf == NULL || !ospf->oi_running) { |
5607 | if (uj) | |
5608 | json_object_free(json); | |
b5a8894d | 5609 | return CMD_SUCCESS; |
b1c3ae8c | 5610 | } |
b5a8894d CS |
5611 | } |
5612 | ||
b1c3ae8c CS |
5613 | if (ospf) { |
5614 | ret = show_ip_ospf_neighbor_detail_common(vty, ospf, json, uj, | |
5615 | use_vrf); | |
5616 | if (uj) { | |
5617 | vty_out(vty, "%s\n", | |
996c9314 LB |
5618 | json_object_to_json_string_ext( |
5619 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c CS |
5620 | } |
5621 | } | |
5622 | ||
5623 | if (uj) | |
5624 | json_object_free(json); | |
b5a8894d CS |
5625 | |
5626 | return ret; | |
7c8ff89e DS |
5627 | } |
5628 | ||
5629 | DEFUN (show_ip_ospf_instance_neighbor_detail, | |
5630 | show_ip_ospf_instance_neighbor_detail_cmd, | |
6147e2c6 | 5631 | "show ip ospf (1-65535) neighbor detail [json]", |
7c8ff89e DS |
5632 | SHOW_STR |
5633 | IP_STR | |
5634 | "OSPF information\n" | |
5635 | "Instance ID\n" | |
5636 | "Neighbor list\n" | |
3ac237f8 | 5637 | "detail of all neighbors\n" |
9973d184 | 5638 | JSON_STR) |
7c8ff89e | 5639 | { |
d62a17ae | 5640 | int idx_number = 3; |
5641 | struct ospf *ospf; | |
d7c0a89a | 5642 | unsigned short instance = 0; |
9f049418 | 5643 | bool uj = use_json(argc, argv); |
b1c3ae8c CS |
5644 | json_object *json = NULL; |
5645 | int ret = CMD_SUCCESS; | |
7c8ff89e | 5646 | |
d62a17ae | 5647 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
409f98ab | 5648 | if (instance != ospf_instance) |
ac28e4ec CS |
5649 | return CMD_NOT_MY_INSTANCE; |
5650 | ||
409f98ab IR |
5651 | ospf = ospf_lookup_instance(instance); |
5652 | if (!ospf || !ospf->oi_running) | |
d62a17ae | 5653 | return CMD_SUCCESS; |
7c8ff89e | 5654 | |
b1c3ae8c CS |
5655 | if (uj) |
5656 | json = json_object_new_object(); | |
5657 | ||
5658 | ret = show_ip_ospf_neighbor_detail_common(vty, ospf, json, uj, 0); | |
5659 | ||
5660 | if (uj) { | |
5661 | vty_out(vty, "%s\n", json_object_to_json_string_ext( | |
5662 | json, JSON_C_TO_STRING_PRETTY)); | |
5663 | json_object_free(json); | |
5664 | } | |
5665 | ||
5666 | return ret; | |
7c8ff89e DS |
5667 | } |
5668 | ||
d62a17ae | 5669 | static int show_ip_ospf_neighbor_detail_all_common(struct vty *vty, |
5670 | struct ospf *ospf, | |
b1c3ae8c | 5671 | json_object *json, |
9f049418 | 5672 | bool use_json, |
d7c0a89a | 5673 | uint8_t use_vrf) |
d62a17ae | 5674 | { |
5675 | struct listnode *node; | |
5676 | struct ospf_interface *oi; | |
b1c3ae8c | 5677 | json_object *json_vrf = NULL; |
718e3744 | 5678 | |
b1c3ae8c CS |
5679 | if (use_json) { |
5680 | if (use_vrf) | |
5681 | json_vrf = json_object_new_object(); | |
5682 | else | |
5683 | json_vrf = json; | |
5684 | } | |
d62a17ae | 5685 | |
5686 | if (ospf->instance) { | |
5687 | if (use_json) | |
5688 | json_object_int_add(json, "ospfInstance", | |
5689 | ospf->instance); | |
5690 | else | |
5691 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
5692 | } | |
5693 | ||
b1c3ae8c | 5694 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); |
87bd50e8 | 5695 | |
d62a17ae | 5696 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) { |
5697 | struct route_node *rn; | |
cb0b2ac6 | 5698 | struct ospf_neighbor *nbr, *prev_nbr = NULL; |
d62a17ae | 5699 | struct ospf_nbr_nbma *nbr_nbma; |
5700 | ||
cb0b2ac6 CS |
5701 | for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) { |
5702 | if ((nbr = rn->info)) { | |
d62a17ae | 5703 | if (nbr != oi->nbr_self) |
5704 | if (nbr->state != NSM_Down) | |
5705 | show_ip_ospf_neighbor_detail_sub( | |
5706 | vty, oi, rn->info, | |
cb0b2ac6 | 5707 | prev_nbr, |
b1c3ae8c | 5708 | json_vrf, use_json); |
cb0b2ac6 CS |
5709 | prev_nbr = nbr; |
5710 | } | |
5711 | } | |
d62a17ae | 5712 | |
5713 | if (oi->type == OSPF_IFTYPE_NBMA) { | |
5714 | struct listnode *nd; | |
5715 | ||
5716 | for (ALL_LIST_ELEMENTS_RO(oi->nbr_nbma, nd, nbr_nbma)) { | |
5717 | if (nbr_nbma->nbr == NULL | |
5718 | || nbr_nbma->nbr->state == NSM_Down) | |
5719 | show_ip_ospf_nbr_nbma_detail_sub( | |
5720 | vty, oi, nbr_nbma, use_json, | |
b1c3ae8c | 5721 | json_vrf); |
d62a17ae | 5722 | } |
5723 | } | |
5724 | } | |
5725 | ||
5726 | if (use_json) { | |
b1c3ae8c CS |
5727 | if (use_vrf) { |
5728 | if (ospf->vrf_id == VRF_DEFAULT) | |
5729 | json_object_object_add(json, "default", | |
5730 | json_vrf); | |
5731 | else | |
5732 | json_object_object_add(json, ospf->name, | |
5733 | json_vrf); | |
5734 | } | |
d62a17ae | 5735 | } else { |
5736 | vty_out(vty, "\n"); | |
5737 | } | |
5738 | ||
5739 | return CMD_SUCCESS; | |
718e3744 | 5740 | } |
5741 | ||
7c8ff89e DS |
5742 | DEFUN (show_ip_ospf_neighbor_detail_all, |
5743 | show_ip_ospf_neighbor_detail_all_cmd, | |
b5a8894d | 5744 | "show ip ospf [vrf <NAME|all>] neighbor detail all [json]", |
718e3744 | 5745 | SHOW_STR |
5746 | IP_STR | |
5747 | "OSPF information\n" | |
b5a8894d CS |
5748 | VRF_CMD_HELP_STR |
5749 | "All VRFs\n" | |
718e3744 | 5750 | "Neighbor list\n" |
7c8ff89e | 5751 | "detail of all neighbors\n" |
3ac237f8 | 5752 | "include down status neighbor\n" |
9973d184 | 5753 | JSON_STR) |
718e3744 | 5754 | { |
d62a17ae | 5755 | struct ospf *ospf; |
9f049418 | 5756 | bool uj = use_json(argc, argv); |
b5a8894d CS |
5757 | struct listnode *node = NULL; |
5758 | char *vrf_name = NULL; | |
2951a7a4 | 5759 | bool all_vrf = false; |
b5a8894d CS |
5760 | int ret = CMD_SUCCESS; |
5761 | int inst = 0; | |
5762 | int idx_vrf = 0; | |
d7c0a89a | 5763 | uint8_t use_vrf = 0; |
b1c3ae8c | 5764 | json_object *json = NULL; |
7c8ff89e | 5765 | |
43b8d1d8 | 5766 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
7c8ff89e | 5767 | |
b1c3ae8c CS |
5768 | if (uj) |
5769 | json = json_object_new_object(); | |
5770 | ||
b5a8894d CS |
5771 | /* vrf input is provided could be all or specific vrf*/ |
5772 | if (vrf_name) { | |
b1c3ae8c | 5773 | use_vrf = 1; |
b5a8894d CS |
5774 | if (all_vrf) { |
5775 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
5776 | if (!ospf->oi_running) | |
5777 | continue; | |
996c9314 LB |
5778 | ret = show_ip_ospf_neighbor_detail_all_common( |
5779 | vty, ospf, json, uj, use_vrf); | |
b5a8894d | 5780 | } |
b1c3ae8c CS |
5781 | |
5782 | if (uj) { | |
5783 | vty_out(vty, "%s\n", | |
996c9314 LB |
5784 | json_object_to_json_string_ext( |
5785 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c CS |
5786 | json_object_free(json); |
5787 | } | |
5788 | ||
b5a8894d CS |
5789 | return ret; |
5790 | } | |
5791 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
b1c3ae8c CS |
5792 | if (ospf == NULL || !ospf->oi_running) { |
5793 | if (uj) | |
5794 | json_object_free(json); | |
b5a8894d | 5795 | return CMD_SUCCESS; |
b1c3ae8c | 5796 | } |
b5a8894d CS |
5797 | } else { |
5798 | /* Display default ospf (instance 0) info */ | |
5799 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
b1c3ae8c CS |
5800 | if (ospf == NULL || !ospf->oi_running) { |
5801 | if (uj) | |
5802 | json_object_free(json); | |
b5a8894d | 5803 | return CMD_SUCCESS; |
b1c3ae8c | 5804 | } |
b5a8894d CS |
5805 | } |
5806 | ||
b1c3ae8c CS |
5807 | if (ospf) { |
5808 | ret = show_ip_ospf_neighbor_detail_all_common(vty, ospf, json, | |
5809 | uj, use_vrf); | |
5810 | if (uj) { | |
5811 | vty_out(vty, "%s\n", | |
996c9314 LB |
5812 | json_object_to_json_string_ext( |
5813 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c CS |
5814 | } |
5815 | } | |
5816 | ||
5817 | if (uj) | |
5818 | json_object_free(json); | |
b5a8894d CS |
5819 | |
5820 | return ret; | |
7c8ff89e DS |
5821 | } |
5822 | ||
5823 | DEFUN (show_ip_ospf_instance_neighbor_detail_all, | |
5824 | show_ip_ospf_instance_neighbor_detail_all_cmd, | |
6147e2c6 | 5825 | "show ip ospf (1-65535) neighbor detail all [json]", |
7c8ff89e DS |
5826 | SHOW_STR |
5827 | IP_STR | |
5828 | "OSPF information\n" | |
5829 | "Instance ID\n" | |
5830 | "Neighbor list\n" | |
5831 | "detail of all neighbors\n" | |
3ac237f8 | 5832 | "include down status neighbor\n" |
9973d184 | 5833 | JSON_STR) |
7c8ff89e | 5834 | { |
d62a17ae | 5835 | int idx_number = 3; |
5836 | struct ospf *ospf; | |
d7c0a89a | 5837 | unsigned short instance = 0; |
9f049418 | 5838 | bool uj = use_json(argc, argv); |
b1c3ae8c CS |
5839 | json_object *json = NULL; |
5840 | int ret = CMD_SUCCESS; | |
7c8ff89e | 5841 | |
d62a17ae | 5842 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
409f98ab | 5843 | if (instance != ospf_instance) |
ac28e4ec CS |
5844 | return CMD_NOT_MY_INSTANCE; |
5845 | ||
409f98ab IR |
5846 | ospf = ospf_lookup_instance(instance); |
5847 | if (!ospf || !ospf->oi_running) | |
d62a17ae | 5848 | return CMD_SUCCESS; |
7c8ff89e | 5849 | |
b1c3ae8c CS |
5850 | if (uj) |
5851 | json = json_object_new_object(); | |
5852 | ||
5853 | ret = show_ip_ospf_neighbor_detail_all_common(vty, ospf, json, uj, 0); | |
5854 | ||
5855 | if (uj) { | |
996c9314 LB |
5856 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
5857 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c CS |
5858 | json_object_free(json); |
5859 | } | |
5860 | ||
5861 | return ret; | |
7c8ff89e DS |
5862 | } |
5863 | ||
d62a17ae | 5864 | static int show_ip_ospf_neighbor_int_detail_common(struct vty *vty, |
5865 | struct ospf *ospf, | |
5866 | int arg_base, | |
5867 | struct cmd_token **argv, | |
9f049418 | 5868 | bool use_json) |
d62a17ae | 5869 | { |
5870 | struct ospf_interface *oi; | |
5871 | struct interface *ifp; | |
5872 | struct route_node *rn, *nrn; | |
5873 | struct ospf_neighbor *nbr; | |
5874 | json_object *json = NULL; | |
718e3744 | 5875 | |
d62a17ae | 5876 | if (use_json) |
5877 | json = json_object_new_object(); | |
5878 | ||
5879 | if (ospf->instance) { | |
5880 | if (use_json) | |
5881 | json_object_int_add(json, "ospfInstance", | |
5882 | ospf->instance); | |
5883 | else | |
5884 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
5885 | } | |
5886 | ||
a36898e7 | 5887 | ifp = if_lookup_by_name(argv[arg_base]->arg, ospf->vrf_id); |
d62a17ae | 5888 | if (!ifp) { |
5889 | if (!use_json) | |
5890 | vty_out(vty, "No such interface.\n"); | |
16307668 RW |
5891 | else { |
5892 | vty_out(vty, "{}\n"); | |
5893 | json_object_free(json); | |
5894 | } | |
d62a17ae | 5895 | return CMD_WARNING; |
5896 | } | |
5897 | ||
5898 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { | |
5899 | if ((oi = rn->info)) { | |
5900 | for (nrn = route_top(oi->nbrs); nrn; | |
5901 | nrn = route_next(nrn)) { | |
5902 | if ((nbr = nrn->info)) { | |
5903 | if (nbr != oi->nbr_self) { | |
5904 | if (nbr->state != NSM_Down) | |
5905 | show_ip_ospf_neighbor_detail_sub( | |
5906 | vty, oi, nbr, | |
cb0b2ac6 | 5907 | NULL, |
b1c3ae8c | 5908 | json, use_json); |
d62a17ae | 5909 | } |
5910 | } | |
5911 | } | |
5912 | } | |
5913 | } | |
5914 | ||
5915 | if (use_json) { | |
9d303b37 DL |
5916 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
5917 | json, JSON_C_TO_STRING_PRETTY)); | |
d62a17ae | 5918 | json_object_free(json); |
5919 | } else | |
5920 | vty_out(vty, "\n"); | |
5921 | ||
5922 | return CMD_SUCCESS; | |
718e3744 | 5923 | } |
5924 | ||
7c8ff89e DS |
5925 | DEFUN (show_ip_ospf_neighbor_int_detail, |
5926 | show_ip_ospf_neighbor_int_detail_cmd, | |
b162fa78 | 5927 | "show ip ospf neighbor IFNAME detail [json]", |
7c8ff89e DS |
5928 | SHOW_STR |
5929 | IP_STR | |
5930 | "OSPF information\n" | |
5931 | "Neighbor list\n" | |
5932 | "Interface name\n" | |
3ac237f8 | 5933 | "detail of all neighbors\n" |
9973d184 | 5934 | JSON_STR) |
7c8ff89e | 5935 | { |
d62a17ae | 5936 | struct ospf *ospf; |
9f049418 | 5937 | bool uj = use_json(argc, argv); |
b5a8894d CS |
5938 | struct listnode *node = NULL; |
5939 | int ret = CMD_SUCCESS; | |
2951a7a4 | 5940 | bool ospf_output = false; |
7c8ff89e | 5941 | |
b5a8894d CS |
5942 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { |
5943 | if (!ospf->oi_running) | |
5944 | continue; | |
2951a7a4 | 5945 | ospf_output = true; |
cb0b2ac6 | 5946 | ret = show_ip_ospf_neighbor_int_detail_common(vty, ospf, 4, |
b5a8894d CS |
5947 | argv, uj); |
5948 | } | |
7c8ff89e | 5949 | |
9f049418 DS |
5950 | if (!ospf_output) |
5951 | vty_out(vty, "%% OSPF instance not found\n"); | |
5952 | ||
b5a8894d | 5953 | return ret; |
7c8ff89e DS |
5954 | } |
5955 | ||
5956 | DEFUN (show_ip_ospf_instance_neighbor_int_detail, | |
5957 | show_ip_ospf_instance_neighbor_int_detail_cmd, | |
6147e2c6 | 5958 | "show ip ospf (1-65535) neighbor IFNAME detail [json]", |
7c8ff89e DS |
5959 | SHOW_STR |
5960 | IP_STR | |
5961 | "OSPF information\n" | |
5962 | "Instance ID\n" | |
5963 | "Neighbor list\n" | |
5964 | "Interface name\n" | |
3ac237f8 | 5965 | "detail of all neighbors\n" |
9973d184 | 5966 | JSON_STR) |
7c8ff89e | 5967 | { |
d62a17ae | 5968 | int idx_number = 3; |
b4e84315 | 5969 | int idx_ifname = 5; |
d62a17ae | 5970 | struct ospf *ospf; |
d7c0a89a | 5971 | unsigned short instance = 0; |
9f049418 | 5972 | bool uj = use_json(argc, argv); |
7c8ff89e | 5973 | |
d62a17ae | 5974 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
409f98ab | 5975 | if (instance != ospf_instance) |
ac28e4ec CS |
5976 | return CMD_NOT_MY_INSTANCE; |
5977 | ||
409f98ab IR |
5978 | ospf = ospf_lookup_instance(instance); |
5979 | if (!ospf || !ospf->oi_running) | |
d62a17ae | 5980 | return CMD_SUCCESS; |
7c8ff89e | 5981 | |
996c9314 LB |
5982 | return show_ip_ospf_neighbor_int_detail_common(vty, ospf, idx_ifname, |
5983 | argv, uj); | |
7c8ff89e | 5984 | } |
6b0655a2 | 5985 | |
718e3744 | 5986 | /* Show functions */ |
f328dc60 | 5987 | static int show_lsa_summary(struct vty *vty, struct ospf_lsa *lsa, int self, |
5988 | json_object *json_lsa) | |
d62a17ae | 5989 | { |
5990 | struct router_lsa *rl; | |
5991 | struct summary_lsa *sl; | |
5992 | struct as_external_lsa *asel; | |
5993 | struct prefix_ipv4 p; | |
f328dc60 | 5994 | char buf[PREFIX2STR_BUFFER]; |
d62a17ae | 5995 | |
5996 | if (lsa != NULL) | |
5997 | /* If self option is set, check LSA self flag. */ | |
5998 | if (self == 0 || IS_LSA_SELF(lsa)) { | |
f328dc60 | 5999 | |
6000 | if (!json_lsa) { | |
6001 | /* LSA common part show. */ | |
6002 | vty_out(vty, "%-15pI4", | |
6003 | &lsa->data->id); | |
ce513ac6 MS |
6004 | vty_out(vty, "%-15pI4 %4d 0x%08lx 0x%04x", |
6005 | &lsa->data->adv_router, LS_AGE(lsa), | |
f328dc60 | 6006 | (unsigned long)ntohl( |
6007 | lsa->data->ls_seqnum), | |
6008 | ntohs(lsa->data->checksum)); | |
6009 | } else { | |
6010 | char seqnum[10]; | |
6011 | char checksum[10]; | |
6012 | ||
6013 | snprintf(seqnum, sizeof(seqnum), "%x", | |
6014 | ntohl(lsa->data->ls_seqnum)); | |
6015 | snprintf(checksum, sizeof(checksum), "%x", | |
6016 | ntohs(lsa->data->checksum)); | |
6017 | json_object_string_add( | |
6018 | json_lsa, "lsId", | |
ce513ac6 MS |
6019 | inet_ntop(AF_INET, &lsa->data->id, |
6020 | buf, sizeof(buf))); | |
f328dc60 | 6021 | json_object_string_add( |
6022 | json_lsa, "advertisedRouter", | |
ce513ac6 MS |
6023 | inet_ntop(AF_INET, |
6024 | &lsa->data->adv_router, | |
6025 | buf, sizeof(buf))); | |
f328dc60 | 6026 | json_object_int_add(json_lsa, "lsaAge", |
6027 | LS_AGE(lsa)); | |
6028 | json_object_string_add( | |
6029 | json_lsa, "sequenceNumber", seqnum); | |
6030 | json_object_string_add(json_lsa, "checksum", | |
6031 | checksum); | |
6032 | } | |
6033 | ||
d62a17ae | 6034 | /* LSA specific part show. */ |
6035 | switch (lsa->data->type) { | |
6036 | case OSPF_ROUTER_LSA: | |
6037 | rl = (struct router_lsa *)lsa->data; | |
f328dc60 | 6038 | |
6039 | if (!json_lsa) | |
6040 | vty_out(vty, " %-d", ntohs(rl->links)); | |
6041 | else | |
6042 | json_object_int_add(json_lsa, | |
6043 | "numOfRouterLinks", | |
6044 | ntohs(rl->links)); | |
d62a17ae | 6045 | break; |
6046 | case OSPF_SUMMARY_LSA: | |
6047 | sl = (struct summary_lsa *)lsa->data; | |
6048 | ||
6049 | p.family = AF_INET; | |
6050 | p.prefix = sl->header.id; | |
6051 | p.prefixlen = ip_masklen(sl->mask); | |
6052 | apply_mask_ipv4(&p); | |
6053 | ||
f328dc60 | 6054 | if (!json_lsa) |
6055 | vty_out(vty, " %pFX", &p); | |
6056 | else { | |
6057 | prefix2str(&p, buf, sizeof(buf)); | |
6058 | json_object_string_add(json_lsa, | |
6059 | "summaryAddress", | |
6060 | buf); | |
6061 | } | |
d62a17ae | 6062 | break; |
6063 | case OSPF_AS_EXTERNAL_LSA: | |
6064 | case OSPF_AS_NSSA_LSA: | |
6065 | asel = (struct as_external_lsa *)lsa->data; | |
6066 | ||
6067 | p.family = AF_INET; | |
6068 | p.prefix = asel->header.id; | |
6069 | p.prefixlen = ip_masklen(asel->mask); | |
6070 | apply_mask_ipv4(&p); | |
6071 | ||
f328dc60 | 6072 | if (!json_lsa) |
6073 | vty_out(vty, " %s %pFX [0x%lx]", | |
6074 | IS_EXTERNAL_METRIC( | |
6075 | asel->e[0].tos) | |
6076 | ? "E2" | |
6077 | : "E1", | |
6078 | &p, | |
6079 | (unsigned long)ntohl( | |
6080 | asel->e[0].route_tag)); | |
6081 | else { | |
6082 | prefix2str(&p, buf, sizeof(buf)); | |
6083 | json_object_string_add( | |
6084 | json_lsa, "metricType", | |
6085 | IS_EXTERNAL_METRIC( | |
6086 | asel->e[0].tos) | |
6087 | ? "E2" | |
6088 | : "E1"); | |
6089 | json_object_string_add(json_lsa, | |
6090 | "route", buf); | |
6091 | json_object_int_add( | |
6092 | json_lsa, "tag", | |
6093 | (unsigned long)ntohl( | |
6094 | asel->e[0].route_tag)); | |
6095 | } | |
d62a17ae | 6096 | break; |
6097 | case OSPF_NETWORK_LSA: | |
6098 | case OSPF_ASBR_SUMMARY_LSA: | |
6099 | case OSPF_OPAQUE_LINK_LSA: | |
6100 | case OSPF_OPAQUE_AREA_LSA: | |
6101 | case OSPF_OPAQUE_AS_LSA: | |
6102 | default: | |
6103 | break; | |
6104 | } | |
f328dc60 | 6105 | |
6106 | if (!json_lsa) | |
6107 | vty_out(vty, "\n"); | |
d62a17ae | 6108 | } |
718e3744 | 6109 | |
d62a17ae | 6110 | return 0; |
6111 | } | |
6112 | ||
2b64873d | 6113 | static const char *const show_database_desc[] = { |
d62a17ae | 6114 | "unknown", |
6115 | "Router Link States", | |
6116 | "Net Link States", | |
6117 | "Summary Link States", | |
6118 | "ASBR-Summary Link States", | |
6119 | "AS External Link States", | |
6120 | "Group Membership LSA", | |
6121 | "NSSA-external Link States", | |
6122 | "Type-8 LSA", | |
6123 | "Link-Local Opaque-LSA", | |
6124 | "Area-Local Opaque-LSA", | |
6125 | "AS-external Opaque-LSA", | |
718e3744 | 6126 | }; |
6127 | ||
f328dc60 | 6128 | static const char * const show_database_desc_json[] = { |
6129 | "unknown", | |
6130 | "routerLinkStates", | |
6131 | "networkLinkStates", | |
6132 | "summaryLinkStates", | |
6133 | "asbrSummaryLinkStates", | |
6134 | "asExternalLinkStates", | |
6135 | "groupMembershipLsa", | |
6136 | "nssaExternalLinkStates", | |
6137 | "type8Lsa", | |
6138 | "linkLocalOpaqueLsa", | |
6139 | "areaLocalOpaqueLsa", | |
6140 | "asExternalOpaqueLsa", | |
6141 | }; | |
6142 | ||
2b64873d | 6143 | static const char *const show_database_header[] = { |
d62a17ae | 6144 | "", |
6145 | "Link ID ADV Router Age Seq# CkSum Link count", | |
6146 | "Link ID ADV Router Age Seq# CkSum", | |
6147 | "Link ID ADV Router Age Seq# CkSum Route", | |
6148 | "Link ID ADV Router Age Seq# CkSum", | |
6149 | "Link ID ADV Router Age Seq# CkSum Route", | |
6150 | " --- header for Group Member ----", | |
6151 | "Link ID ADV Router Age Seq# CkSum Route", | |
6152 | " --- type-8 ---", | |
6153 | "Opaque-Type/Id ADV Router Age Seq# CkSum", | |
6154 | "Opaque-Type/Id ADV Router Age Seq# CkSum", | |
6155 | "Opaque-Type/Id ADV Router Age Seq# CkSum", | |
718e3744 | 6156 | }; |
6157 | ||
f328dc60 | 6158 | static void show_ip_ospf_database_header(struct vty *vty, struct ospf_lsa *lsa, |
6159 | json_object *json) | |
d62a17ae | 6160 | { |
ce513ac6 | 6161 | char buf[PREFIX_STRLEN]; |
d62a17ae | 6162 | struct router_lsa *rlsa = (struct router_lsa *)lsa->data; |
6163 | ||
f328dc60 | 6164 | if (!json) { |
6165 | vty_out(vty, " LS age: %d\n", LS_AGE(lsa)); | |
6166 | vty_out(vty, " Options: 0x%-2x : %s\n", lsa->data->options, | |
6167 | ospf_options_dump(lsa->data->options)); | |
6168 | vty_out(vty, " LS Flags: 0x%-2x %s\n", lsa->flags, | |
6169 | ((lsa->flags & OSPF_LSA_LOCAL_XLT) | |
6170 | ? "(Translated from Type-7)" | |
6171 | : "")); | |
6172 | ||
6173 | if (lsa->data->type == OSPF_ROUTER_LSA) { | |
6174 | vty_out(vty, " Flags: 0x%x", rlsa->flags); | |
6175 | ||
6176 | if (rlsa->flags) | |
6177 | vty_out(vty, " :%s%s%s%s", | |
6178 | IS_ROUTER_LSA_BORDER(rlsa) ? " ABR" | |
6179 | : "", | |
6180 | IS_ROUTER_LSA_EXTERNAL(rlsa) ? " ASBR" | |
6181 | : "", | |
6182 | IS_ROUTER_LSA_VIRTUAL(rlsa) | |
6183 | ? " VL-endpoint" | |
6184 | : "", | |
6185 | IS_ROUTER_LSA_SHORTCUT(rlsa) | |
6186 | ? " Shortcut" | |
6187 | : ""); | |
d62a17ae | 6188 | |
f328dc60 | 6189 | vty_out(vty, "\n"); |
6190 | } | |
6191 | vty_out(vty, " LS Type: %s\n", | |
6192 | lookup_msg(ospf_lsa_type_msg, lsa->data->type, NULL)); | |
6193 | vty_out(vty, " Link State ID: %pI4 %s\n", | |
6194 | &lsa->data->id, | |
6195 | lookup_msg(ospf_link_state_id_type_msg, lsa->data->type, | |
6196 | NULL)); | |
6197 | vty_out(vty, " Advertising Router: %pI4\n", | |
6198 | &lsa->data->adv_router); | |
6199 | vty_out(vty, " LS Seq Number: %08lx\n", | |
6200 | (unsigned long)ntohl(lsa->data->ls_seqnum)); | |
6201 | vty_out(vty, " Checksum: 0x%04x\n", | |
6202 | ntohs(lsa->data->checksum)); | |
6203 | vty_out(vty, " Length: %d\n\n", ntohs(lsa->data->length)); | |
6204 | } else { | |
6205 | char seqnum[10]; | |
6206 | char checksum[10]; | |
6207 | ||
6208 | snprintf(seqnum, 10, "%x", ntohl(lsa->data->ls_seqnum)); | |
6209 | snprintf(checksum, 10, "%x", ntohs(lsa->data->checksum)); | |
6210 | ||
6211 | json_object_int_add(json, "lsaAge", LS_AGE(lsa)); | |
6212 | json_object_string_add(json, "options", | |
6213 | ospf_options_dump(lsa->data->options)); | |
6214 | json_object_int_add(json, "lsaFlags", lsa->flags); | |
6215 | ||
6216 | if (lsa->flags & OSPF_LSA_LOCAL_XLT) | |
6217 | json_object_boolean_true_add(json, | |
6218 | "translatedFromType7"); | |
6219 | ||
6220 | if (lsa->data->type == OSPF_ROUTER_LSA) { | |
6221 | json_object_int_add(json, "flags", rlsa->flags); | |
6222 | ||
6223 | if (rlsa->flags) { | |
6224 | if (IS_ROUTER_LSA_BORDER(rlsa)) | |
6225 | json_object_boolean_true_add(json, | |
6226 | "abr"); | |
6227 | if (IS_ROUTER_LSA_EXTERNAL(rlsa)) | |
6228 | json_object_boolean_true_add(json, | |
6229 | "asbr"); | |
6230 | if (IS_ROUTER_LSA_VIRTUAL(rlsa)) | |
6231 | json_object_boolean_true_add( | |
6232 | json, "vlEndpoint"); | |
6233 | if (IS_ROUTER_LSA_SHORTCUT(rlsa)) | |
6234 | json_object_boolean_true_add( | |
6235 | json, "shortcut"); | |
6236 | } | |
6237 | } | |
6238 | ||
6239 | json_object_string_add( | |
6240 | json, "lsaType", | |
6241 | lookup_msg(ospf_lsa_type_msg, lsa->data->type, NULL)); | |
6242 | json_object_string_add(json, "linkStateId", | |
ce513ac6 MS |
6243 | inet_ntop(AF_INET, &lsa->data->id, |
6244 | buf, sizeof(buf))); | |
f328dc60 | 6245 | json_object_string_add(json, "advertisingRouter", |
ce513ac6 MS |
6246 | inet_ntop(AF_INET, |
6247 | &lsa->data->adv_router, | |
6248 | buf, sizeof(buf))); | |
f328dc60 | 6249 | json_object_string_add(json, "lsaSeqNumber", seqnum); |
6250 | json_object_string_add(json, "checksum", checksum); | |
6251 | json_object_int_add(json, "length", ntohs(lsa->data->length)); | |
d62a17ae | 6252 | } |
d62a17ae | 6253 | } |
6254 | ||
2b64873d | 6255 | static const char *const link_type_desc[] = { |
d62a17ae | 6256 | "(null)", |
6257 | "another Router (point-to-point)", | |
6258 | "a Transit Network", | |
6259 | "Stub Network", | |
6260 | "a Virtual Link", | |
718e3744 | 6261 | }; |
6262 | ||
2b64873d | 6263 | static const char *const link_id_desc[] = { |
d62a17ae | 6264 | "(null)", "Neighboring Router ID", "Designated Router address", |
6265 | "Net", "Neighboring Router ID", | |
718e3744 | 6266 | }; |
6267 | ||
2b64873d | 6268 | static const char *const link_data_desc[] = { |
d62a17ae | 6269 | "(null)", "Router Interface address", "Router Interface address", |
6270 | "Network Mask", "Router Interface address", | |
718e3744 | 6271 | }; |
6272 | ||
f328dc60 | 6273 | static const char *const link_id_desc_json[] = { |
6274 | "null", "neighborRouterId", "designatedRouterAddress", | |
6275 | "networkAddress", "neighborRouterId", | |
6276 | }; | |
6277 | ||
6278 | static const char *const link_data_desc_json[] = { | |
6279 | "null", "routerInterfaceAddress", "routerInterfaceAddress", | |
6280 | "networkMask", "routerInterfaceAddress", | |
6281 | }; | |
6282 | ||
718e3744 | 6283 | /* Show router-LSA each Link information. */ |
d62a17ae | 6284 | static void show_ip_ospf_database_router_links(struct vty *vty, |
f328dc60 | 6285 | struct router_lsa *rl, |
6286 | json_object *json) | |
d62a17ae | 6287 | { |
6288 | int len, type; | |
f328dc60 | 6289 | unsigned short i; |
6290 | json_object *json_links = NULL; | |
6291 | json_object *json_link = NULL; | |
6292 | int metric = 0; | |
ce513ac6 | 6293 | char buf[PREFIX_STRLEN]; |
f328dc60 | 6294 | |
6295 | if (json) | |
6296 | json_links = json_object_new_object(); | |
d62a17ae | 6297 | |
6298 | len = ntohs(rl->header.length) - 4; | |
6299 | for (i = 0; i < ntohs(rl->links) && len > 0; len -= 12, i++) { | |
6300 | type = rl->link[i].type; | |
6301 | ||
f328dc60 | 6302 | if (json) { |
6303 | char link[16]; | |
6304 | ||
6305 | snprintf(link, sizeof(link), "link%u", i); | |
6306 | json_link = json_object_new_object(); | |
6307 | json_object_string_add(json_link, "linkType", | |
6308 | link_type_desc[type]); | |
6309 | json_object_string_add(json_link, | |
6310 | link_id_desc_json[type], | |
ce513ac6 MS |
6311 | inet_ntop(AF_INET, |
6312 | &rl->link[i].link_id, | |
6313 | buf, sizeof(buf))); | |
f328dc60 | 6314 | json_object_string_add( |
6315 | json_link, link_data_desc_json[type], | |
ce513ac6 MS |
6316 | inet_ntop(AF_INET, &rl->link[i].link_data, |
6317 | buf, sizeof(buf))); | |
f328dc60 | 6318 | json_object_int_add(json_link, "numOfTosMetrics", |
6319 | metric); | |
6320 | json_object_int_add(json_link, "tos0Metric", | |
6321 | ntohs(rl->link[i].metric)); | |
6322 | json_object_object_add(json_links, link, json_link); | |
6323 | } else { | |
6324 | vty_out(vty, " Link connected to: %s\n", | |
6325 | link_type_desc[type]); | |
6326 | vty_out(vty, " (Link ID) %s: %pI4\n", | |
6327 | link_id_desc[type], | |
6328 | &rl->link[i].link_id); | |
6329 | vty_out(vty, " (Link Data) %s: %pI4\n", | |
6330 | link_data_desc[type], | |
6331 | &rl->link[i].link_data); | |
6332 | vty_out(vty, " Number of TOS metrics: 0\n"); | |
6333 | vty_out(vty, " TOS 0 Metric: %d\n", | |
6334 | ntohs(rl->link[i].metric)); | |
6335 | vty_out(vty, "\n"); | |
6336 | } | |
d62a17ae | 6337 | } |
f328dc60 | 6338 | if (json) |
6339 | json_object_object_add(json, "routerLinks", json_links); | |
718e3744 | 6340 | } |
6341 | ||
6342 | /* Show router-LSA detail information. */ | |
f328dc60 | 6343 | static int show_router_lsa_detail(struct vty *vty, struct ospf_lsa *lsa, |
6344 | json_object *json) | |
718e3744 | 6345 | { |
d62a17ae | 6346 | if (lsa != NULL) { |
6347 | struct router_lsa *rl = (struct router_lsa *)lsa->data; | |
718e3744 | 6348 | |
f328dc60 | 6349 | show_ip_ospf_database_header(vty, lsa, json); |
718e3744 | 6350 | |
f328dc60 | 6351 | if (!json) |
6352 | vty_out(vty, " Number of Links: %d\n\n", | |
6353 | ntohs(rl->links)); | |
6354 | else | |
6355 | json_object_int_add(json, "numOfLinks", | |
6356 | ntohs(rl->links)); | |
718e3744 | 6357 | |
f328dc60 | 6358 | show_ip_ospf_database_router_links(vty, rl, json); |
6359 | ||
6360 | if (!json) | |
6361 | vty_out(vty, "\n"); | |
d62a17ae | 6362 | } |
6363 | ||
6364 | return 0; | |
718e3744 | 6365 | } |
6366 | ||
6367 | /* Show network-LSA detail information. */ | |
f328dc60 | 6368 | static int show_network_lsa_detail(struct vty *vty, struct ospf_lsa *lsa, |
6369 | json_object *json) | |
718e3744 | 6370 | { |
d62a17ae | 6371 | int length, i; |
ce513ac6 | 6372 | char buf[PREFIX_STRLEN]; |
f328dc60 | 6373 | json_object *json_attached_rt = NULL; |
6374 | json_object *json_router = NULL; | |
6375 | ||
6376 | if (json) | |
6377 | json_attached_rt = json_object_new_object(); | |
718e3744 | 6378 | |
d62a17ae | 6379 | if (lsa != NULL) { |
6380 | struct network_lsa *nl = (struct network_lsa *)lsa->data; | |
8db278b5 | 6381 | struct in_addr *addr; |
718e3744 | 6382 | |
f328dc60 | 6383 | show_ip_ospf_database_header(vty, lsa, json); |
718e3744 | 6384 | |
f328dc60 | 6385 | if (!json) |
6386 | vty_out(vty, " Network Mask: /%d\n", | |
6387 | ip_masklen(nl->mask)); | |
6388 | else | |
6389 | json_object_int_add(json, "networkMask", | |
6390 | ip_masklen(nl->mask)); | |
718e3744 | 6391 | |
8db278b5 OD |
6392 | length = lsa->size - OSPF_LSA_HEADER_SIZE - 4; |
6393 | addr = &nl->routers[0]; | |
6394 | for (i = 0; length > 0 && addr; | |
6395 | length -= 4, addr = &nl->routers[++i]) | |
f328dc60 | 6396 | if (!json) { |
6397 | vty_out(vty, " Attached Router: %pI4\n", | |
8db278b5 | 6398 | addr); |
f328dc60 | 6399 | vty_out(vty, "\n"); |
6400 | } else { | |
6401 | json_router = json_object_new_object(); | |
6402 | json_object_string_add( | |
6403 | json_router, "attachedRouterId", | |
8db278b5 OD |
6404 | inet_ntop(AF_INET, addr, buf, |
6405 | sizeof(buf))); | |
6406 | json_object_object_add(json_attached_rt, | |
6407 | inet_ntop(AF_INET, addr, | |
6408 | buf, | |
6409 | sizeof(buf)), | |
6410 | json_router); | |
f328dc60 | 6411 | } |
d62a17ae | 6412 | } |
718e3744 | 6413 | |
f328dc60 | 6414 | if (json) |
6415 | json_object_object_add(json, "attchedRouters", | |
6416 | json_attached_rt); | |
6417 | ||
d62a17ae | 6418 | return 0; |
718e3744 | 6419 | } |
6420 | ||
6421 | /* Show summary-LSA detail information. */ | |
f328dc60 | 6422 | static int show_summary_lsa_detail(struct vty *vty, struct ospf_lsa *lsa, |
6423 | json_object *json) | |
718e3744 | 6424 | { |
d62a17ae | 6425 | if (lsa != NULL) { |
6426 | struct summary_lsa *sl = (struct summary_lsa *)lsa->data; | |
718e3744 | 6427 | |
f328dc60 | 6428 | show_ip_ospf_database_header(vty, lsa, json); |
718e3744 | 6429 | |
f328dc60 | 6430 | if (!json) { |
6431 | vty_out(vty, " Network Mask: /%d\n", | |
6432 | ip_masklen(sl->mask)); | |
6433 | vty_out(vty, " TOS: 0 Metric: %d\n", | |
6434 | GET_METRIC(sl->metric)); | |
6435 | vty_out(vty, "\n"); | |
6436 | } else { | |
6437 | json_object_int_add(json, "networkMask", | |
6438 | ip_masklen(sl->mask)); | |
6439 | json_object_int_add(json, "tos0Metric", | |
6440 | GET_METRIC(sl->metric)); | |
6441 | } | |
d62a17ae | 6442 | } |
718e3744 | 6443 | |
d62a17ae | 6444 | return 0; |
718e3744 | 6445 | } |
6446 | ||
6447 | /* Show summary-ASBR-LSA detail information. */ | |
f328dc60 | 6448 | static int show_summary_asbr_lsa_detail(struct vty *vty, struct ospf_lsa *lsa, |
6449 | json_object *json) | |
718e3744 | 6450 | { |
d62a17ae | 6451 | if (lsa != NULL) { |
6452 | struct summary_lsa *sl = (struct summary_lsa *)lsa->data; | |
718e3744 | 6453 | |
f328dc60 | 6454 | show_ip_ospf_database_header(vty, lsa, json); |
718e3744 | 6455 | |
f328dc60 | 6456 | if (!json) { |
6457 | vty_out(vty, " Network Mask: /%d\n", | |
6458 | ip_masklen(sl->mask)); | |
6459 | vty_out(vty, " TOS: 0 Metric: %d\n", | |
6460 | GET_METRIC(sl->metric)); | |
6461 | vty_out(vty, "\n"); | |
6462 | } else { | |
6463 | json_object_int_add(json, "networkMask", | |
6464 | ip_masklen(sl->mask)); | |
6465 | json_object_int_add(json, "tos0Metric", | |
6466 | GET_METRIC(sl->metric)); | |
6467 | } | |
d62a17ae | 6468 | } |
718e3744 | 6469 | |
d62a17ae | 6470 | return 0; |
718e3744 | 6471 | } |
6472 | ||
6473 | /* Show AS-external-LSA detail information. */ | |
f328dc60 | 6474 | static int show_as_external_lsa_detail(struct vty *vty, struct ospf_lsa *lsa, |
6475 | json_object *json) | |
d62a17ae | 6476 | { |
ce513ac6 | 6477 | char buf[PREFIX_STRLEN]; |
f328dc60 | 6478 | int tos = 0; |
6479 | ||
d62a17ae | 6480 | if (lsa != NULL) { |
6481 | struct as_external_lsa *al = | |
6482 | (struct as_external_lsa *)lsa->data; | |
6483 | ||
f328dc60 | 6484 | show_ip_ospf_database_header(vty, lsa, json); |
6485 | ||
6486 | if (!json) { | |
6487 | vty_out(vty, " Network Mask: /%d\n", | |
6488 | ip_masklen(al->mask)); | |
6489 | vty_out(vty, " Metric Type: %s\n", | |
6490 | IS_EXTERNAL_METRIC(al->e[0].tos) | |
6491 | ? "2 (Larger than any link state path)" | |
6492 | : "1"); | |
6493 | vty_out(vty, " TOS: 0\n"); | |
6494 | vty_out(vty, " Metric: %d\n", | |
6495 | GET_METRIC(al->e[0].metric)); | |
6496 | vty_out(vty, " Forward Address: %pI4\n", | |
6497 | &al->e[0].fwd_addr); | |
6498 | vty_out(vty, | |
6499 | " External Route Tag: %" ROUTE_TAG_PRI "\n\n", | |
6500 | (route_tag_t)ntohl(al->e[0].route_tag)); | |
6501 | } else { | |
6502 | json_object_int_add(json, "networkMask", | |
6503 | ip_masklen(al->mask)); | |
6504 | json_object_string_add( | |
6505 | json, "metricType", | |
6506 | IS_EXTERNAL_METRIC(al->e[0].tos) | |
6507 | ? "E2 (Larger than any link state path)" | |
6508 | : "E1"); | |
6509 | json_object_int_add(json, "tos", tos); | |
6510 | json_object_int_add(json, "metric", | |
6511 | GET_METRIC(al->e[0].metric)); | |
6512 | json_object_string_add(json, "forwardAddress", | |
ce513ac6 MS |
6513 | inet_ntop(AF_INET, |
6514 | &(al->e[0].fwd_addr), | |
6515 | buf, sizeof(buf))); | |
f328dc60 | 6516 | json_object_int_add( |
6517 | json, "externalRouteTag", | |
6518 | (route_tag_t)ntohl(al->e[0].route_tag)); | |
6519 | } | |
d62a17ae | 6520 | } |
718e3744 | 6521 | |
d62a17ae | 6522 | return 0; |
718e3744 | 6523 | } |
718e3744 | 6524 | |
718e3744 | 6525 | /* Show AS-NSSA-LSA detail information. */ |
f328dc60 | 6526 | static int show_as_nssa_lsa_detail(struct vty *vty, struct ospf_lsa *lsa, |
6527 | json_object *json) | |
d62a17ae | 6528 | { |
ce513ac6 | 6529 | char buf[PREFIX_STRLEN]; |
f328dc60 | 6530 | int tos = 0; |
6531 | ||
d62a17ae | 6532 | if (lsa != NULL) { |
6533 | struct as_external_lsa *al = | |
6534 | (struct as_external_lsa *)lsa->data; | |
6535 | ||
f328dc60 | 6536 | show_ip_ospf_database_header(vty, lsa, json); |
6537 | ||
6538 | if (!json) { | |
6539 | vty_out(vty, " Network Mask: /%d\n", | |
6540 | ip_masklen(al->mask)); | |
6541 | vty_out(vty, " Metric Type: %s\n", | |
6542 | IS_EXTERNAL_METRIC(al->e[0].tos) | |
6543 | ? "2 (Larger than any link state path)" | |
6544 | : "1"); | |
6545 | vty_out(vty, " TOS: 0\n"); | |
6546 | vty_out(vty, " Metric: %d\n", | |
6547 | GET_METRIC(al->e[0].metric)); | |
6548 | vty_out(vty, " NSSA: Forward Address: %pI4\n", | |
6549 | &al->e[0].fwd_addr); | |
6550 | vty_out(vty, | |
6551 | " External Route Tag: %" ROUTE_TAG_PRI | |
6552 | "\n\n", | |
6553 | (route_tag_t)ntohl(al->e[0].route_tag)); | |
6554 | } else { | |
6555 | json_object_int_add(json, "networkMask", | |
6556 | ip_masklen(al->mask)); | |
6557 | json_object_string_add( | |
6558 | json, "metricType", | |
6559 | IS_EXTERNAL_METRIC(al->e[0].tos) | |
6560 | ? "E2 (Larger than any link state path)" | |
6561 | : "E1"); | |
6562 | json_object_int_add(json, "tos", tos); | |
6563 | json_object_int_add(json, "metric", | |
6564 | GET_METRIC(al->e[0].metric)); | |
6565 | json_object_string_add(json, "nssaForwardAddress", | |
ce513ac6 MS |
6566 | inet_ntop(AF_INET, |
6567 | &al->e[0].fwd_addr, | |
6568 | buf, sizeof(buf))); | |
f328dc60 | 6569 | json_object_int_add( |
6570 | json, "externalRouteTag", | |
6571 | (route_tag_t)ntohl(al->e[0].route_tag)); | |
6572 | } | |
d62a17ae | 6573 | } |
718e3744 | 6574 | |
d62a17ae | 6575 | return 0; |
718e3744 | 6576 | } |
6577 | ||
f328dc60 | 6578 | static int show_func_dummy(struct vty *vty, struct ospf_lsa *lsa, |
6579 | json_object *json) | |
718e3744 | 6580 | { |
d62a17ae | 6581 | return 0; |
718e3744 | 6582 | } |
6583 | ||
f328dc60 | 6584 | static int show_opaque_lsa_detail(struct vty *vty, struct ospf_lsa *lsa, |
6585 | json_object *json) | |
718e3744 | 6586 | { |
d62a17ae | 6587 | if (lsa != NULL) { |
f328dc60 | 6588 | show_ip_ospf_database_header(vty, lsa, json); |
6589 | show_opaque_info_detail(vty, lsa, json); | |
6590 | if (!json) | |
6591 | vty_out(vty, "\n"); | |
d62a17ae | 6592 | } |
6593 | return 0; | |
6594 | } | |
6595 | ||
f328dc60 | 6596 | int (*show_function[])(struct vty *, struct ospf_lsa *, json_object *) = { |
d62a17ae | 6597 | NULL, |
6598 | show_router_lsa_detail, | |
6599 | show_network_lsa_detail, | |
6600 | show_summary_lsa_detail, | |
6601 | show_summary_asbr_lsa_detail, | |
6602 | show_as_external_lsa_detail, | |
6603 | show_func_dummy, | |
6604 | show_as_nssa_lsa_detail, /* almost same as external */ | |
6605 | NULL, /* type-8 */ | |
6606 | show_opaque_lsa_detail, | |
6607 | show_opaque_lsa_detail, | |
6608 | show_opaque_lsa_detail, | |
6609 | }; | |
6610 | ||
6611 | static void show_lsa_prefix_set(struct vty *vty, struct prefix_ls *lp, | |
6612 | struct in_addr *id, struct in_addr *adv_router) | |
6613 | { | |
6614 | memset(lp, 0, sizeof(struct prefix_ls)); | |
6615 | lp->family = 0; | |
6616 | if (id == NULL) | |
6617 | lp->prefixlen = 0; | |
6618 | else if (adv_router == NULL) { | |
12256b84 | 6619 | lp->prefixlen = IPV4_MAX_BITLEN; |
d62a17ae | 6620 | lp->id = *id; |
6621 | } else { | |
6622 | lp->prefixlen = 64; | |
6623 | lp->id = *id; | |
6624 | lp->adv_router = *adv_router; | |
6625 | } | |
718e3744 | 6626 | } |
718e3744 | 6627 | |
d62a17ae | 6628 | static void show_lsa_detail_proc(struct vty *vty, struct route_table *rt, |
f328dc60 | 6629 | struct in_addr *id, struct in_addr *adv_router, |
6630 | json_object *json) | |
d62a17ae | 6631 | { |
6632 | struct prefix_ls lp; | |
6633 | struct route_node *rn, *start; | |
6634 | struct ospf_lsa *lsa; | |
f328dc60 | 6635 | json_object *json_lsa = NULL; |
718e3744 | 6636 | |
d62a17ae | 6637 | show_lsa_prefix_set(vty, &lp, id, adv_router); |
6638 | start = route_node_get(rt, (struct prefix *)&lp); | |
6639 | if (start) { | |
6640 | route_lock_node(start); | |
6641 | for (rn = start; rn; rn = route_next_until(rn, start)) | |
6642 | if ((lsa = rn->info)) { | |
f328dc60 | 6643 | if (json) { |
6644 | json_lsa = json_object_new_object(); | |
6645 | json_object_array_add(json, json_lsa); | |
6646 | } | |
6647 | ||
d62a17ae | 6648 | if (show_function[lsa->data->type] != NULL) |
f328dc60 | 6649 | show_function[lsa->data->type]( |
6650 | vty, lsa, json_lsa); | |
d62a17ae | 6651 | } |
6652 | route_unlock_node(start); | |
6653 | } | |
718e3744 | 6654 | } |
6655 | ||
6656 | /* Show detail LSA information | |
6657 | -- if id is NULL then show all LSAs. */ | |
d62a17ae | 6658 | static void show_lsa_detail(struct vty *vty, struct ospf *ospf, int type, |
f328dc60 | 6659 | struct in_addr *id, struct in_addr *adv_router, |
6660 | json_object *json) | |
d62a17ae | 6661 | { |
6662 | struct listnode *node; | |
6663 | struct ospf_area *area; | |
ce513ac6 | 6664 | char buf[PREFIX_STRLEN]; |
f328dc60 | 6665 | json_object *json_lsa_type = NULL; |
6666 | json_object *json_areas = NULL; | |
6667 | json_object *json_lsa_array = NULL; | |
6668 | ||
6669 | if (json) | |
6670 | json_lsa_type = json_object_new_object(); | |
d62a17ae | 6671 | |
6672 | switch (type) { | |
6673 | case OSPF_AS_EXTERNAL_LSA: | |
6674 | case OSPF_OPAQUE_AS_LSA: | |
f328dc60 | 6675 | if (!json) |
6676 | vty_out(vty, " %s \n\n", | |
6677 | show_database_desc[type]); | |
6678 | else | |
6679 | json_lsa_array = json_object_new_array(); | |
6680 | ||
6681 | show_lsa_detail_proc(vty, AS_LSDB(ospf, type), id, adv_router, | |
6682 | json_lsa_array); | |
6683 | if (json) | |
6684 | json_object_object_add(json, | |
6685 | show_database_desc_json[type], | |
6686 | json_lsa_array); | |
6687 | ||
d62a17ae | 6688 | break; |
6689 | default: | |
f328dc60 | 6690 | if (json) |
6691 | json_areas = json_object_new_object(); | |
6692 | ||
d62a17ae | 6693 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) { |
f328dc60 | 6694 | if (!json) { |
6695 | vty_out(vty, | |
6696 | "\n %s (Area %s)\n\n", | |
6697 | show_database_desc[type], | |
6698 | ospf_area_desc_string(area)); | |
6699 | } else { | |
6700 | json_lsa_array = json_object_new_array(); | |
6701 | json_object_object_add(json_areas, | |
ce513ac6 MS |
6702 | inet_ntop(AF_INET, |
6703 | &area->area_id, | |
6704 | buf, | |
6705 | sizeof(buf)), | |
f328dc60 | 6706 | json_lsa_array); |
6707 | } | |
6708 | ||
d62a17ae | 6709 | show_lsa_detail_proc(vty, AREA_LSDB(area, type), id, |
f328dc60 | 6710 | adv_router, json_lsa_array); |
6711 | } | |
6712 | ||
6713 | if (json) { | |
6714 | json_object_object_add(json_lsa_type, "areas", | |
6715 | json_areas); | |
6716 | json_object_object_add(json, | |
6717 | show_database_desc_json[type], | |
6718 | json_lsa_type); | |
d62a17ae | 6719 | } |
6720 | break; | |
718e3744 | 6721 | } |
6722 | } | |
6723 | ||
d62a17ae | 6724 | static void show_lsa_detail_adv_router_proc(struct vty *vty, |
6725 | struct route_table *rt, | |
f328dc60 | 6726 | struct in_addr *adv_router, |
6727 | json_object *json) | |
d62a17ae | 6728 | { |
ce513ac6 | 6729 | char buf[PREFIX_STRLEN]; |
d62a17ae | 6730 | struct route_node *rn; |
6731 | struct ospf_lsa *lsa; | |
6732 | ||
6733 | for (rn = route_top(rt); rn; rn = route_next(rn)) | |
f328dc60 | 6734 | if ((lsa = rn->info)) { |
6735 | json_object *json_lsa = NULL; | |
6736 | ||
d62a17ae | 6737 | if (IPV4_ADDR_SAME(adv_router, |
6738 | &lsa->data->adv_router)) { | |
6739 | if (CHECK_FLAG(lsa->flags, OSPF_LSA_LOCAL_XLT)) | |
6740 | continue; | |
f328dc60 | 6741 | if (json) |
6742 | json_lsa = json_object_new_object(); | |
6743 | ||
d62a17ae | 6744 | if (show_function[lsa->data->type] != NULL) |
f328dc60 | 6745 | show_function[lsa->data->type]( |
6746 | vty, lsa, json_lsa); | |
6747 | if (json) | |
6748 | json_object_object_add( | |
ce513ac6 MS |
6749 | json, |
6750 | inet_ntop(AF_INET, | |
6751 | &lsa->data->id, | |
6752 | buf, sizeof(buf)), | |
f328dc60 | 6753 | json_lsa); |
d62a17ae | 6754 | } |
f328dc60 | 6755 | } |
d62a17ae | 6756 | } |
6757 | ||
718e3744 | 6758 | /* Show detail LSA information. */ |
d62a17ae | 6759 | static void show_lsa_detail_adv_router(struct vty *vty, struct ospf *ospf, |
f328dc60 | 6760 | int type, struct in_addr *adv_router, |
6761 | json_object *json) | |
d62a17ae | 6762 | { |
6763 | struct listnode *node; | |
6764 | struct ospf_area *area; | |
ce513ac6 | 6765 | char buf[PREFIX_STRLEN]; |
f328dc60 | 6766 | json_object *json_lstype = NULL; |
6767 | json_object *json_area = NULL; | |
6768 | ||
6769 | if (json) | |
6770 | json_lstype = json_object_new_object(); | |
d62a17ae | 6771 | |
6772 | switch (type) { | |
6773 | case OSPF_AS_EXTERNAL_LSA: | |
6774 | case OSPF_OPAQUE_AS_LSA: | |
f328dc60 | 6775 | if (!json) |
6776 | vty_out(vty, " %s \n\n", | |
6777 | show_database_desc[type]); | |
6778 | ||
d62a17ae | 6779 | show_lsa_detail_adv_router_proc(vty, AS_LSDB(ospf, type), |
f328dc60 | 6780 | adv_router, json_lstype); |
d62a17ae | 6781 | break; |
6782 | default: | |
f328dc60 | 6783 | |
d62a17ae | 6784 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) { |
f328dc60 | 6785 | if (json) |
6786 | json_area = json_object_new_object(); | |
6787 | else | |
6788 | vty_out(vty, | |
6789 | "\n %s (Area %s)\n\n", | |
6790 | show_database_desc[type], | |
6791 | ospf_area_desc_string(area)); | |
6792 | show_lsa_detail_adv_router_proc(vty, | |
6793 | AREA_LSDB(area, type), | |
6794 | adv_router, json_area); | |
6795 | ||
6796 | if (json) | |
6797 | json_object_object_add(json_lstype, | |
ce513ac6 MS |
6798 | inet_ntop(AF_INET, |
6799 | &area->area_id, | |
6800 | buf, | |
6801 | sizeof(buf)), | |
f328dc60 | 6802 | json_area); |
d62a17ae | 6803 | } |
6804 | break; | |
6805 | } | |
f328dc60 | 6806 | |
6807 | if (json) | |
6808 | json_object_object_add(json, show_database_desc[type], | |
6809 | json_lstype); | |
d62a17ae | 6810 | } |
6811 | ||
7fd0729f G |
6812 | void show_ip_ospf_database_summary(struct vty *vty, struct ospf *ospf, int self, |
6813 | json_object *json) | |
d62a17ae | 6814 | { |
6815 | struct ospf_lsa *lsa; | |
6816 | struct route_node *rn; | |
6817 | struct ospf_area *area; | |
6818 | struct listnode *node; | |
ce513ac6 | 6819 | char buf[PREFIX_STRLEN]; |
f328dc60 | 6820 | json_object *json_areas = NULL; |
6821 | json_object *json_area = NULL; | |
6822 | json_object *json_lsa = NULL; | |
d62a17ae | 6823 | int type; |
f328dc60 | 6824 | json_object *json_lsa_array = NULL; |
6825 | ||
6826 | if (json) | |
6827 | json_areas = json_object_new_object(); | |
d62a17ae | 6828 | |
6829 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) { | |
f328dc60 | 6830 | if (json) |
6831 | json_area = json_object_new_object(); | |
6832 | ||
d62a17ae | 6833 | for (type = OSPF_MIN_LSA; type < OSPF_MAX_LSA; type++) { |
6834 | switch (type) { | |
6835 | case OSPF_AS_EXTERNAL_LSA: | |
6836 | case OSPF_OPAQUE_AS_LSA: | |
6837 | continue; | |
6838 | default: | |
6839 | break; | |
6840 | } | |
6841 | if (ospf_lsdb_count_self(area->lsdb, type) > 0 | |
6842 | || (!self | |
6843 | && ospf_lsdb_count(area->lsdb, type) > 0)) { | |
d62a17ae | 6844 | |
f328dc60 | 6845 | if (!json) { |
6846 | vty_out(vty, | |
6847 | " %s (Area %s)\n\n", | |
6848 | show_database_desc[type], | |
6849 | ospf_area_desc_string(area)); | |
6850 | vty_out(vty, "%s\n", | |
6851 | show_database_header[type]); | |
6852 | } else { | |
6853 | json_lsa_array = | |
6854 | json_object_new_array(); | |
6855 | json_object_object_add( | |
6856 | json_area, | |
6857 | show_database_desc_json[type], | |
6858 | json_lsa_array); | |
6859 | } | |
6860 | ||
6861 | LSDB_LOOP (AREA_LSDB(area, type), rn, lsa) { | |
6862 | if (json) { | |
6863 | json_lsa = | |
6864 | json_object_new_object(); | |
6865 | json_object_array_add( | |
6866 | json_lsa_array, | |
6867 | json_lsa); | |
6868 | } | |
d62a17ae | 6869 | |
f328dc60 | 6870 | show_lsa_summary(vty, lsa, self, |
6871 | json_lsa); | |
6872 | } | |
6873 | ||
6874 | if (!json) | |
6875 | vty_out(vty, "\n"); | |
d62a17ae | 6876 | } |
6877 | } | |
f328dc60 | 6878 | if (json) |
6879 | json_object_object_add(json_areas, | |
ce513ac6 MS |
6880 | inet_ntop(AF_INET, |
6881 | &area->area_id, | |
6882 | buf, sizeof(buf)), | |
f328dc60 | 6883 | json_area); |
d62a17ae | 6884 | } |
6885 | ||
f328dc60 | 6886 | if (json) |
6887 | json_object_object_add(json, "areas", json_areas); | |
6888 | ||
d62a17ae | 6889 | for (type = OSPF_MIN_LSA; type < OSPF_MAX_LSA; type++) { |
6890 | switch (type) { | |
6891 | case OSPF_AS_EXTERNAL_LSA: | |
6892 | case OSPF_OPAQUE_AS_LSA: | |
6893 | break; | |
6894 | default: | |
6895 | continue; | |
6896 | } | |
6897 | if (ospf_lsdb_count_self(ospf->lsdb, type) | |
6898 | || (!self && ospf_lsdb_count(ospf->lsdb, type))) { | |
f328dc60 | 6899 | if (!json) { |
6900 | vty_out(vty, " %s\n\n", | |
6901 | show_database_desc[type]); | |
6902 | vty_out(vty, "%s\n", | |
6903 | show_database_header[type]); | |
6904 | } else { | |
6905 | json_lsa_array = json_object_new_array(); | |
6906 | json_object_object_add( | |
6907 | json, show_database_desc_json[type], | |
6908 | json_lsa_array); | |
6909 | } | |
d62a17ae | 6910 | |
f328dc60 | 6911 | LSDB_LOOP (AS_LSDB(ospf, type), rn, lsa) { |
6912 | if (json) { | |
6913 | json_lsa = json_object_new_object(); | |
6914 | json_object_array_add(json_lsa_array, | |
6915 | json_lsa); | |
6916 | } | |
d62a17ae | 6917 | |
f328dc60 | 6918 | show_lsa_summary(vty, lsa, self, json_lsa); |
6919 | } | |
6920 | ||
6921 | if (!json) | |
6922 | vty_out(vty, "\n"); | |
d62a17ae | 6923 | } |
6924 | } | |
6925 | ||
f328dc60 | 6926 | if (!json) |
6927 | vty_out(vty, "\n"); | |
d62a17ae | 6928 | } |
6929 | ||
f328dc60 | 6930 | static void show_ip_ospf_database_maxage(struct vty *vty, struct ospf *ospf, |
6931 | json_object *json) | |
d62a17ae | 6932 | { |
6933 | struct route_node *rn; | |
ce513ac6 | 6934 | char buf[PREFIX_STRLEN]; |
f328dc60 | 6935 | json_object *json_maxage = NULL; |
d62a17ae | 6936 | |
f328dc60 | 6937 | if (!json) |
6938 | vty_out(vty, "\n MaxAge Link States:\n\n"); | |
6939 | else | |
6940 | json_maxage = json_object_new_object(); | |
d62a17ae | 6941 | |
6942 | for (rn = route_top(ospf->maxage_lsa); rn; rn = route_next(rn)) { | |
6943 | struct ospf_lsa *lsa; | |
f328dc60 | 6944 | json_object *json_lsa = NULL; |
d62a17ae | 6945 | |
6946 | if ((lsa = rn->info) != NULL) { | |
f328dc60 | 6947 | if (!json) { |
6948 | vty_out(vty, "Link type: %d\n", | |
6949 | lsa->data->type); | |
ce513ac6 MS |
6950 | vty_out(vty, "Link State ID: %pI4\n", |
6951 | &lsa->data->id); | |
f328dc60 | 6952 | vty_out(vty, "Advertising Router: %pI4\n", |
6953 | &lsa->data->adv_router); | |
6954 | vty_out(vty, "LSA lock count: %d\n", lsa->lock); | |
6955 | vty_out(vty, "\n"); | |
6956 | } else { | |
6957 | json_lsa = json_object_new_object(); | |
6958 | json_object_int_add(json_lsa, "linkType", | |
6959 | lsa->data->type); | |
6960 | json_object_string_add( | |
6961 | json_lsa, "linkStateId", | |
ce513ac6 MS |
6962 | inet_ntop(AF_INET, &lsa->data->id, |
6963 | buf, sizeof(buf))); | |
f328dc60 | 6964 | json_object_string_add( |
6965 | json_lsa, "advertisingRouter", | |
ce513ac6 MS |
6966 | inet_ntop(AF_INET, |
6967 | &lsa->data->adv_router, | |
6968 | buf, sizeof(buf))); | |
f328dc60 | 6969 | json_object_int_add(json_lsa, "lsaLockCount", |
6970 | lsa->lock); | |
ce513ac6 MS |
6971 | json_object_object_add( |
6972 | json_maxage, | |
6973 | inet_ntop(AF_INET, | |
6974 | &lsa->data->id, | |
6975 | buf, sizeof(buf)), | |
6976 | json_lsa); | |
f328dc60 | 6977 | } |
d62a17ae | 6978 | } |
91e6a0e5 | 6979 | } |
f328dc60 | 6980 | if (json) |
6981 | json_object_object_add(json, "maxAgeLinkStates", json_maxage); | |
718e3744 | 6982 | } |
6983 | ||
718e3744 | 6984 | #define OSPF_LSA_TYPE_NSSA_DESC "NSSA external link state\n" |
6985 | #define OSPF_LSA_TYPE_NSSA_CMD_STR "|nssa-external" | |
718e3744 | 6986 | |
718e3744 | 6987 | #define OSPF_LSA_TYPE_OPAQUE_LINK_DESC "Link local Opaque-LSA\n" |
6988 | #define OSPF_LSA_TYPE_OPAQUE_AREA_DESC "Link area Opaque-LSA\n" | |
6989 | #define OSPF_LSA_TYPE_OPAQUE_AS_DESC "Link AS Opaque-LSA\n" | |
6990 | #define OSPF_LSA_TYPE_OPAQUE_CMD_STR "|opaque-link|opaque-area|opaque-as" | |
718e3744 | 6991 | |
d62a17ae | 6992 | #define OSPF_LSA_TYPES_DESC \ |
6993 | "ASBR summary link states\n" \ | |
6994 | "External link states\n" \ | |
6995 | "Network link states\n" \ | |
6996 | "Router link states\n" \ | |
6997 | "Network summary link states\n" OSPF_LSA_TYPE_NSSA_DESC \ | |
6998 | OSPF_LSA_TYPE_OPAQUE_LINK_DESC OSPF_LSA_TYPE_OPAQUE_AREA_DESC \ | |
6999 | OSPF_LSA_TYPE_OPAQUE_AS_DESC | |
7000 | ||
7001 | static int show_ip_ospf_database_common(struct vty *vty, struct ospf *ospf, | |
7002 | int arg_base, int argc, | |
d7c0a89a | 7003 | struct cmd_token **argv, |
f328dc60 | 7004 | uint8_t use_vrf, json_object *json, |
7005 | bool uj) | |
d62a17ae | 7006 | { |
7007 | int idx_type = 4; | |
7008 | int type, ret; | |
7009 | struct in_addr id, adv_router; | |
ce513ac6 | 7010 | char buf[PREFIX_STRLEN]; |
f328dc60 | 7011 | json_object *json_vrf = NULL; |
d62a17ae | 7012 | |
f328dc60 | 7013 | if (uj) { |
7014 | if (use_vrf) | |
7015 | json_vrf = json_object_new_object(); | |
7016 | else | |
7017 | json_vrf = json; | |
7018 | } | |
7019 | ||
7020 | if (ospf->instance) { | |
7021 | if (uj) | |
7022 | json_object_int_add(json_vrf, "ospfInstance", | |
7023 | ospf->instance); | |
7024 | else | |
7025 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
7026 | } | |
d62a17ae | 7027 | |
f328dc60 | 7028 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); |
87bd50e8 | 7029 | |
f328dc60 | 7030 | /* Show Router ID. */ |
7031 | if (uj) { | |
7032 | json_object_string_add(json_vrf, "routerId", | |
ce513ac6 MS |
7033 | inet_ntop(AF_INET, &ospf->router_id, |
7034 | buf, sizeof(buf))); | |
f328dc60 | 7035 | } else { |
7036 | vty_out(vty, "\n OSPF Router with ID (%pI4)\n\n", | |
7037 | &ospf->router_id); | |
7038 | } | |
d62a17ae | 7039 | |
7040 | /* Show all LSA. */ | |
f328dc60 | 7041 | if ((argc == arg_base + 4) || (uj && (argc == arg_base + 5))) { |
7042 | show_ip_ospf_database_summary(vty, ospf, 0, json_vrf); | |
7043 | if (json) { | |
7044 | if (use_vrf) { | |
7045 | if (ospf->vrf_id == VRF_DEFAULT) | |
7046 | json_object_object_add(json, "default", | |
7047 | json_vrf); | |
7048 | else | |
7049 | json_object_object_add(json, ospf->name, | |
7050 | json_vrf); | |
7051 | } | |
7052 | } | |
d62a17ae | 7053 | return CMD_SUCCESS; |
7054 | } | |
718e3744 | 7055 | |
d62a17ae | 7056 | /* Set database type to show. */ |
7057 | if (strncmp(argv[arg_base + idx_type]->text, "r", 1) == 0) | |
7058 | type = OSPF_ROUTER_LSA; | |
7059 | else if (strncmp(argv[arg_base + idx_type]->text, "ne", 2) == 0) | |
7060 | type = OSPF_NETWORK_LSA; | |
7061 | else if (strncmp(argv[arg_base + idx_type]->text, "ns", 2) == 0) | |
7062 | type = OSPF_AS_NSSA_LSA; | |
7063 | else if (strncmp(argv[arg_base + idx_type]->text, "su", 2) == 0) | |
7064 | type = OSPF_SUMMARY_LSA; | |
7065 | else if (strncmp(argv[arg_base + idx_type]->text, "a", 1) == 0) | |
7066 | type = OSPF_ASBR_SUMMARY_LSA; | |
7067 | else if (strncmp(argv[arg_base + idx_type]->text, "e", 1) == 0) | |
7068 | type = OSPF_AS_EXTERNAL_LSA; | |
7069 | else if (strncmp(argv[arg_base + idx_type]->text, "se", 2) == 0) { | |
f328dc60 | 7070 | show_ip_ospf_database_summary(vty, ospf, 1, json_vrf); |
7071 | if (json) { | |
7072 | if (use_vrf) { | |
7073 | if (ospf->vrf_id == VRF_DEFAULT) | |
7074 | json_object_object_add(json, "default", | |
7075 | json_vrf); | |
7076 | else | |
7077 | json_object_object_add(json, ospf->name, | |
7078 | json_vrf); | |
7079 | } | |
7080 | } | |
d62a17ae | 7081 | return CMD_SUCCESS; |
7082 | } else if (strncmp(argv[arg_base + idx_type]->text, "m", 1) == 0) { | |
f328dc60 | 7083 | show_ip_ospf_database_maxage(vty, ospf, json_vrf); |
7084 | if (json) { | |
7085 | if (use_vrf) { | |
7086 | if (ospf->vrf_id == VRF_DEFAULT) | |
7087 | json_object_object_add(json, "default", | |
7088 | json_vrf); | |
7089 | else | |
7090 | json_object_object_add(json, ospf->name, | |
7091 | json_vrf); | |
7092 | } | |
7093 | } | |
d62a17ae | 7094 | return CMD_SUCCESS; |
7095 | } else if (strncmp(argv[arg_base + idx_type]->text, "opaque-l", 8) == 0) | |
7096 | type = OSPF_OPAQUE_LINK_LSA; | |
7097 | else if (strncmp(argv[arg_base + idx_type]->text, "opaque-ar", 9) == 0) | |
7098 | type = OSPF_OPAQUE_AREA_LSA; | |
7099 | else if (strncmp(argv[arg_base + idx_type]->text, "opaque-as", 9) == 0) | |
7100 | type = OSPF_OPAQUE_AS_LSA; | |
7101 | else | |
718e3744 | 7102 | return CMD_WARNING; |
d62a17ae | 7103 | |
7104 | /* `show ip ospf database LSA'. */ | |
f328dc60 | 7105 | if ((argc == arg_base + 5) || (uj && (argc == arg_base + 6))) |
7106 | show_lsa_detail(vty, ospf, type, NULL, NULL, json_vrf); | |
d62a17ae | 7107 | else if (argc >= arg_base + 6) { |
7108 | ret = inet_aton(argv[arg_base + 5]->arg, &id); | |
7109 | if (!ret) | |
7110 | return CMD_WARNING; | |
7111 | ||
7112 | /* `show ip ospf database LSA ID'. */ | |
f328dc60 | 7113 | if ((argc == arg_base + 6) || (uj && (argc == arg_base + 7))) |
7114 | show_lsa_detail(vty, ospf, type, &id, NULL, json_vrf); | |
d62a17ae | 7115 | /* `show ip ospf database LSA ID adv-router ADV_ROUTER'. */ |
f328dc60 | 7116 | else if ((argc == arg_base + 7) |
7117 | || (uj && (argc == arg_base + 8))) { | |
d62a17ae | 7118 | if (strncmp(argv[arg_base + 6]->text, "s", 1) == 0) |
7119 | adv_router = ospf->router_id; | |
7120 | else { | |
7121 | ret = inet_aton(argv[arg_base + 7]->arg, | |
7122 | &adv_router); | |
7123 | if (!ret) | |
7124 | return CMD_WARNING; | |
7125 | } | |
f328dc60 | 7126 | show_lsa_detail(vty, ospf, type, &id, &adv_router, |
7127 | json_vrf); | |
7128 | } | |
7129 | } | |
7130 | ||
7131 | if (json) { | |
7132 | if (use_vrf) { | |
7133 | if (ospf->vrf_id == VRF_DEFAULT) | |
7134 | json_object_object_add(json, "default", | |
7135 | json_vrf); | |
7136 | else | |
7137 | json_object_object_add(json, ospf->name, | |
7138 | json_vrf); | |
d62a17ae | 7139 | } |
718e3744 | 7140 | } |
718e3744 | 7141 | |
d62a17ae | 7142 | return CMD_SUCCESS; |
718e3744 | 7143 | } |
7144 | ||
7a7be519 | 7145 | DEFUN (show_ip_ospf_database_max, |
7146 | show_ip_ospf_database_max_cmd, | |
f328dc60 | 7147 | "show ip ospf [vrf <NAME|all>] database <max-age|self-originate> [json]", |
7a7be519 | 7148 | SHOW_STR |
7149 | IP_STR | |
7150 | "OSPF information\n" | |
b5a8894d CS |
7151 | VRF_CMD_HELP_STR |
7152 | "All VRFs\n" | |
7a7be519 | 7153 | "Database summary\n" |
7154 | "LSAs in MaxAge list\n" | |
f328dc60 | 7155 | "Self-originated link states\n" |
7156 | JSON_STR) | |
7a7be519 | 7157 | { |
b5a8894d CS |
7158 | struct ospf *ospf = NULL; |
7159 | struct listnode *node = NULL; | |
7160 | char *vrf_name = NULL; | |
2951a7a4 | 7161 | bool all_vrf = false; |
b5a8894d CS |
7162 | int ret = CMD_SUCCESS; |
7163 | int inst = 0; | |
7164 | int idx_vrf = 0; | |
d7c0a89a | 7165 | uint8_t use_vrf = 0; |
f328dc60 | 7166 | bool uj = use_json(argc, argv); |
7167 | json_object *json = NULL; | |
7168 | ||
7169 | if (uj) | |
7170 | json = json_object_new_object(); | |
f412b39a | 7171 | |
43b8d1d8 | 7172 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
f412b39a | 7173 | |
b5a8894d | 7174 | if (vrf_name) { |
2951a7a4 | 7175 | bool ospf_output = false; |
874f58d8 | 7176 | |
b1c3ae8c | 7177 | use_vrf = 1; |
94d4c685 | 7178 | |
b5a8894d CS |
7179 | if (all_vrf) { |
7180 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
7181 | if (!ospf->oi_running) | |
7182 | continue; | |
2951a7a4 | 7183 | ospf_output = true; |
996c9314 LB |
7184 | ret = show_ip_ospf_database_common( |
7185 | vty, ospf, idx_vrf ? 2 : 0, argc, argv, | |
f328dc60 | 7186 | use_vrf, json, uj); |
b5a8894d | 7187 | } |
9f049418 DS |
7188 | |
7189 | if (!ospf_output) | |
7190 | vty_out(vty, "%% OSPF instance not found\n"); | |
b5a8894d CS |
7191 | } else { |
7192 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
9f049418 | 7193 | if (ospf == NULL || !ospf->oi_running) { |
94d4c685 | 7194 | vty_out(vty, "%% OSPF instance not found\n"); |
b5a8894d | 7195 | return CMD_SUCCESS; |
9f049418 | 7196 | } |
996c9314 | 7197 | ret = (show_ip_ospf_database_common( |
f328dc60 | 7198 | vty, ospf, idx_vrf ? 2 : 0, argc, argv, use_vrf, |
7199 | json, uj)); | |
b5a8894d CS |
7200 | } |
7201 | } else { | |
7202 | /* Display default ospf (instance 0) info */ | |
7203 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
9f049418 | 7204 | if (ospf == NULL || !ospf->oi_running) { |
94d4c685 | 7205 | vty_out(vty, "%% OSPF instance not found\n"); |
b5a8894d | 7206 | return CMD_SUCCESS; |
9f049418 DS |
7207 | } |
7208 | ||
b1c3ae8c | 7209 | ret = show_ip_ospf_database_common(vty, ospf, 0, argc, argv, |
f328dc60 | 7210 | use_vrf, json, uj); |
7211 | } | |
7212 | ||
7213 | if (uj) { | |
7214 | vty_out(vty, "%s\n", json_object_to_json_string(json)); | |
7215 | json_object_free(json); | |
b5a8894d CS |
7216 | } |
7217 | ||
7218 | return ret; | |
7a7be519 | 7219 | } |
f412b39a | 7220 | |
a11bce11 IR |
7221 | ALIAS (show_ip_ospf_database_max, |
7222 | show_ip_ospf_database_cmd, | |
7223 | "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 | 7224 | SHOW_STR |
7225 | IP_STR | |
7226 | "OSPF information\n" | |
b5a8894d | 7227 | VRF_CMD_HELP_STR |
a11bce11 | 7228 | "All VRFs\n" |
7a7be519 | 7229 | "Database summary\n" |
7230 | OSPF_LSA_TYPES_DESC | |
7231 | "Link State ID (as an IP address)\n" | |
7232 | "Self-originated link states\n" | |
7233 | "Advertising Router link states\n" | |
f328dc60 | 7234 | "Advertising Router (as an IP address)\n" |
7235 | JSON_STR) | |
7c8ff89e | 7236 | |
7a7be519 | 7237 | DEFUN (show_ip_ospf_instance_database_max, |
7238 | show_ip_ospf_instance_database_max_cmd, | |
f328dc60 | 7239 | "show ip ospf (1-65535) database <max-age|self-originate> [json]", |
7a7be519 | 7240 | SHOW_STR |
7241 | IP_STR | |
7242 | "OSPF information\n" | |
7243 | "Instance ID\n" | |
7244 | "Database summary\n" | |
7245 | "LSAs in MaxAge list\n" | |
f328dc60 | 7246 | "Self-originated link states\n" |
7247 | JSON_STR) | |
7a7be519 | 7248 | { |
d62a17ae | 7249 | int idx_number = 3; |
7250 | struct ospf *ospf; | |
d7c0a89a | 7251 | unsigned short instance = 0; |
f328dc60 | 7252 | bool uj = use_json(argc, argv); |
7253 | json_object *json = NULL; | |
7254 | ||
7255 | if (uj) | |
7256 | json = json_object_new_object(); | |
d62a17ae | 7257 | |
7258 | instance = strtoul(argv[idx_number]->arg, NULL, 10); | |
409f98ab | 7259 | if (instance != ospf_instance) |
ac28e4ec CS |
7260 | return CMD_NOT_MY_INSTANCE; |
7261 | ||
409f98ab IR |
7262 | ospf = ospf_lookup_instance(instance); |
7263 | if (!ospf || !ospf->oi_running) | |
d62a17ae | 7264 | return CMD_SUCCESS; |
7265 | ||
f328dc60 | 7266 | show_ip_ospf_database_common(vty, ospf, 1, argc, argv, 0, json, uj); |
7267 | ||
7268 | if (uj) { | |
7269 | vty_out(vty, "%s\n", | |
7270 | json_object_to_json_string_ext( | |
7271 | json, JSON_C_TO_STRING_PRETTY)); | |
7272 | json_object_free(json); | |
7273 | } | |
7274 | ||
7275 | return CMD_SUCCESS; | |
d62a17ae | 7276 | } |
7277 | ||
a11bce11 IR |
7278 | ALIAS (show_ip_ospf_instance_database_max, |
7279 | show_ip_ospf_instance_database_cmd, | |
7280 | "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]", | |
7281 | SHOW_STR | |
7282 | IP_STR | |
7283 | "OSPF information\n" | |
7284 | "Instance ID\n" | |
7285 | "Database summary\n" | |
7286 | OSPF_LSA_TYPES_DESC | |
7287 | "Link State ID (as an IP address)\n" | |
7288 | "Self-originated link states\n" | |
7289 | "Advertising Router link states\n" | |
7290 | "Advertising Router (as an IP address)\n" | |
7291 | JSON_STR) | |
d62a17ae | 7292 | |
7293 | static int show_ip_ospf_database_type_adv_router_common(struct vty *vty, | |
7294 | struct ospf *ospf, | |
7295 | int arg_base, int argc, | |
b1c3ae8c | 7296 | struct cmd_token **argv, |
f328dc60 | 7297 | uint8_t use_vrf, |
7298 | json_object *json, | |
7299 | bool uj) | |
d62a17ae | 7300 | { |
7301 | int idx_type = 4; | |
7302 | int type, ret; | |
7303 | struct in_addr adv_router; | |
ce513ac6 | 7304 | char buf[PREFIX_STRLEN]; |
f328dc60 | 7305 | json_object *json_vrf = NULL; |
d62a17ae | 7306 | |
f328dc60 | 7307 | if (uj) { |
7308 | if (use_vrf) | |
7309 | json_vrf = json_object_new_object(); | |
7310 | else | |
7311 | json_vrf = json; | |
7312 | } | |
d62a17ae | 7313 | |
f328dc60 | 7314 | if (ospf->instance) { |
7315 | if (uj) | |
7316 | json_object_int_add(json, "ospfInstance", | |
7317 | ospf->instance); | |
7318 | else | |
7319 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
7320 | } | |
87bd50e8 | 7321 | |
f328dc60 | 7322 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); |
7323 | ||
7324 | /* Show Router ID. */ | |
7325 | if (uj) { | |
7326 | json_object_string_add(json_vrf, "routerId", | |
ce513ac6 MS |
7327 | inet_ntop(AF_INET, &ospf->router_id, |
7328 | buf, sizeof(buf))); | |
f328dc60 | 7329 | } else { |
7330 | vty_out(vty, "\n OSPF Router with ID (%pI4)\n\n", | |
7331 | &ospf->router_id); | |
7332 | } | |
d62a17ae | 7333 | |
7334 | /* Set database type to show. */ | |
7335 | if (strncmp(argv[arg_base + idx_type]->text, "r", 1) == 0) | |
7336 | type = OSPF_ROUTER_LSA; | |
7337 | else if (strncmp(argv[arg_base + idx_type]->text, "ne", 2) == 0) | |
7338 | type = OSPF_NETWORK_LSA; | |
7339 | else if (strncmp(argv[arg_base + idx_type]->text, "ns", 2) == 0) | |
7340 | type = OSPF_AS_NSSA_LSA; | |
7341 | else if (strncmp(argv[arg_base + idx_type]->text, "s", 1) == 0) | |
7342 | type = OSPF_SUMMARY_LSA; | |
7343 | else if (strncmp(argv[arg_base + idx_type]->text, "a", 1) == 0) | |
7344 | type = OSPF_ASBR_SUMMARY_LSA; | |
7345 | else if (strncmp(argv[arg_base + idx_type]->text, "e", 1) == 0) | |
7346 | type = OSPF_AS_EXTERNAL_LSA; | |
7347 | else if (strncmp(argv[arg_base + idx_type]->text, "opaque-l", 8) == 0) | |
7348 | type = OSPF_OPAQUE_LINK_LSA; | |
7349 | else if (strncmp(argv[arg_base + idx_type]->text, "opaque-ar", 9) == 0) | |
7350 | type = OSPF_OPAQUE_AREA_LSA; | |
7351 | else if (strncmp(argv[arg_base + idx_type]->text, "opaque-as", 9) == 0) | |
7352 | type = OSPF_OPAQUE_AS_LSA; | |
7353 | else | |
7354 | return CMD_WARNING; | |
7c8ff89e | 7355 | |
d62a17ae | 7356 | /* `show ip ospf database LSA adv-router ADV_ROUTER'. */ |
7357 | if (strncmp(argv[arg_base + 5]->text, "s", 1) == 0) | |
7358 | adv_router = ospf->router_id; | |
7359 | else { | |
7360 | ret = inet_aton(argv[arg_base + 6]->arg, &adv_router); | |
7361 | if (!ret) | |
7362 | return CMD_WARNING; | |
7363 | } | |
7c8ff89e | 7364 | |
f328dc60 | 7365 | show_lsa_detail_adv_router(vty, ospf, type, &adv_router, json_vrf); |
7366 | ||
7367 | if (json) { | |
7368 | if (use_vrf) { | |
7369 | if (ospf->vrf_id == VRF_DEFAULT) | |
7370 | json_object_object_add(json, "default", | |
7371 | json_vrf); | |
7372 | else | |
7373 | json_object_object_add(json, ospf->name, | |
7374 | json_vrf); | |
7375 | } | |
7376 | } | |
7c8ff89e | 7377 | |
d62a17ae | 7378 | return CMD_SUCCESS; |
7c8ff89e DS |
7379 | } |
7380 | ||
a11bce11 IR |
7381 | DEFUN (show_ip_ospf_database_type_adv_router, |
7382 | show_ip_ospf_database_type_adv_router_cmd, | |
7383 | "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 |
7384 | SHOW_STR |
7385 | IP_STR | |
7386 | "OSPF information\n" | |
b5a8894d | 7387 | VRF_CMD_HELP_STR |
a11bce11 | 7388 | "All VRFs\n" |
7c8ff89e DS |
7389 | "Database summary\n" |
7390 | OSPF_LSA_TYPES_DESC | |
7391 | "Advertising Router link states\n" | |
3a2d747c | 7392 | "Advertising Router (as an IP address)\n" |
f328dc60 | 7393 | "Self-originated link states\n" |
7394 | JSON_STR) | |
7c8ff89e | 7395 | { |
b5a8894d | 7396 | struct ospf *ospf = NULL; |
b5a8894d CS |
7397 | struct listnode *node = NULL; |
7398 | char *vrf_name = NULL; | |
2951a7a4 | 7399 | bool all_vrf = false; |
b5a8894d CS |
7400 | int ret = CMD_SUCCESS; |
7401 | int inst = 0; | |
acaeb9fd | 7402 | int idx_vrf = 0; |
d7c0a89a | 7403 | uint8_t use_vrf = 0; |
f328dc60 | 7404 | bool uj = use_json(argc, argv); |
7405 | json_object *json = NULL; | |
7406 | ||
7407 | if (uj) | |
7408 | json = json_object_new_object(); | |
7c8ff89e | 7409 | |
43b8d1d8 CS |
7410 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
7411 | ||
b5a8894d | 7412 | if (vrf_name) { |
2951a7a4 | 7413 | bool ospf_output = false; |
874f58d8 | 7414 | |
b1c3ae8c | 7415 | use_vrf = 1; |
94d4c685 | 7416 | |
b5a8894d CS |
7417 | if (all_vrf) { |
7418 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
7419 | if (!ospf->oi_running) | |
7420 | continue; | |
2951a7a4 | 7421 | ospf_output = true; |
996c9314 | 7422 | ret = show_ip_ospf_database_type_adv_router_common( |
d68e47e1 LS |
7423 | vty, ospf, 2, argc, argv, use_vrf, json, |
7424 | uj); | |
b5a8894d | 7425 | } |
9f049418 DS |
7426 | if (!ospf_output) |
7427 | vty_out(vty, "%% OSPF instance not found\n"); | |
b5a8894d CS |
7428 | } else { |
7429 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
9f049418 | 7430 | if ((ospf == NULL) || !ospf->oi_running) { |
94d4c685 | 7431 | vty_out(vty, "%% OSPF instance not found\n"); |
b5a8894d | 7432 | return CMD_SUCCESS; |
9f049418 DS |
7433 | } |
7434 | ||
996c9314 | 7435 | ret = show_ip_ospf_database_type_adv_router_common( |
d68e47e1 | 7436 | vty, ospf, 2, argc, argv, use_vrf, json, uj); |
b5a8894d CS |
7437 | } |
7438 | } else { | |
7439 | /* Display default ospf (instance 0) info */ | |
7440 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
9f049418 | 7441 | if (ospf == NULL || !ospf->oi_running) { |
94d4c685 | 7442 | vty_out(vty, "%% OSPF instance not found\n"); |
b5a8894d | 7443 | return CMD_SUCCESS; |
9f049418 DS |
7444 | } |
7445 | ||
996c9314 | 7446 | ret = show_ip_ospf_database_type_adv_router_common( |
acaeb9fd | 7447 | vty, ospf, 0, argc, argv, use_vrf, json, uj); |
b5a8894d | 7448 | } |
f328dc60 | 7449 | |
7450 | if (uj) { | |
7451 | vty_out(vty, "%s\n", json_object_to_json_string(json)); | |
7452 | json_object_free(json); | |
7453 | } | |
7454 | ||
b5a8894d | 7455 | return ret; |
a11bce11 IR |
7456 | } |
7457 | ||
7458 | DEFUN (show_ip_ospf_instance_database_type_adv_router, | |
7459 | show_ip_ospf_instance_database_type_adv_router_cmd, | |
7460 | "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]", | |
7461 | SHOW_STR | |
7462 | IP_STR | |
7463 | "OSPF information\n" | |
7464 | "Instance ID\n" | |
7465 | "Database summary\n" | |
7466 | OSPF_LSA_TYPES_DESC | |
7467 | "Advertising Router link states\n" | |
7468 | "Advertising Router (as an IP address)\n" | |
7469 | "Self-originated link states\n" | |
7470 | JSON_STR) | |
7471 | { | |
7472 | int idx_number = 3; | |
7473 | struct ospf *ospf; | |
7474 | unsigned short instance = 0; | |
7475 | bool uj = use_json(argc, argv); | |
7476 | json_object *json = NULL; | |
7477 | ||
7478 | if (uj) | |
7479 | json = json_object_new_object(); | |
7480 | ||
7481 | instance = strtoul(argv[idx_number]->arg, NULL, 10); | |
7482 | if (instance != ospf_instance) | |
7483 | return CMD_NOT_MY_INSTANCE; | |
7484 | ||
7485 | ospf = ospf_lookup_instance(instance); | |
7486 | if (!ospf || !ospf->oi_running) | |
7487 | return CMD_SUCCESS; | |
7488 | ||
7489 | show_ip_ospf_database_type_adv_router_common(vty, ospf, 1, argc, argv, | |
7490 | 0, json, uj); | |
7491 | ||
7492 | if (uj) { | |
7493 | vty_out(vty, "%s\n", | |
7494 | json_object_to_json_string_ext( | |
7495 | json, JSON_C_TO_STRING_PRETTY)); | |
7496 | json_object_free(json); | |
7497 | } | |
7498 | ||
7499 | return CMD_SUCCESS; | |
718e3744 | 7500 | } |
7501 | ||
718e3744 | 7502 | DEFUN (ip_ospf_authentication_args, |
7503 | ip_ospf_authentication_args_addr_cmd, | |
7a7be519 | 7504 | "ip ospf authentication <null|message-digest> [A.B.C.D]", |
718e3744 | 7505 | "IP Information\n" |
7506 | "OSPF interface commands\n" | |
7507 | "Enable authentication on this interface\n" | |
7508 | "Use null authentication\n" | |
7509 | "Use message-digest authentication\n" | |
7a7be519 | 7510 | "Address of interface\n") |
718e3744 | 7511 | { |
d62a17ae | 7512 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7513 | int idx_encryption = 3; | |
7514 | int idx_ipv4 = 4; | |
7515 | struct in_addr addr; | |
7516 | int ret; | |
7517 | struct ospf_if_params *params; | |
7518 | ||
7519 | params = IF_DEF_PARAMS(ifp); | |
7520 | ||
7521 | if (argc == 5) { | |
7522 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
7523 | if (!ret) { | |
7524 | vty_out(vty, | |
7525 | "Please specify interface address by A.B.C.D\n"); | |
7526 | return CMD_WARNING_CONFIG_FAILED; | |
7527 | } | |
718e3744 | 7528 | |
d62a17ae | 7529 | params = ospf_get_if_params(ifp, addr); |
7530 | ospf_if_update_params(ifp, addr); | |
7531 | } | |
718e3744 | 7532 | |
d62a17ae | 7533 | /* Handle null authentication */ |
7534 | if (argv[idx_encryption]->arg[0] == 'n') { | |
7535 | SET_IF_PARAM(params, auth_type); | |
7536 | params->auth_type = OSPF_AUTH_NULL; | |
7537 | return CMD_SUCCESS; | |
7538 | } | |
718e3744 | 7539 | |
d62a17ae | 7540 | /* Handle message-digest authentication */ |
7541 | if (argv[idx_encryption]->arg[0] == 'm') { | |
7542 | SET_IF_PARAM(params, auth_type); | |
7543 | params->auth_type = OSPF_AUTH_CRYPTOGRAPHIC; | |
7544 | return CMD_SUCCESS; | |
7545 | } | |
718e3744 | 7546 | |
d62a17ae | 7547 | vty_out(vty, "You shouldn't get here!\n"); |
7548 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 7549 | } |
7550 | ||
718e3744 | 7551 | DEFUN (ip_ospf_authentication, |
7552 | ip_ospf_authentication_addr_cmd, | |
7a7be519 | 7553 | "ip ospf authentication [A.B.C.D]", |
718e3744 | 7554 | "IP Information\n" |
7555 | "OSPF interface commands\n" | |
7556 | "Enable authentication on this interface\n" | |
efd7904e | 7557 | "Address of interface\n") |
718e3744 | 7558 | { |
d62a17ae | 7559 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7560 | int idx_ipv4 = 3; | |
7561 | struct in_addr addr; | |
7562 | int ret; | |
7563 | struct ospf_if_params *params; | |
7564 | ||
7565 | params = IF_DEF_PARAMS(ifp); | |
7566 | ||
7567 | if (argc == 4) { | |
7568 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
7569 | if (!ret) { | |
7570 | vty_out(vty, | |
7571 | "Please specify interface address by A.B.C.D\n"); | |
7572 | return CMD_WARNING_CONFIG_FAILED; | |
7573 | } | |
7574 | ||
7575 | params = ospf_get_if_params(ifp, addr); | |
7576 | ospf_if_update_params(ifp, addr); | |
718e3744 | 7577 | } |
7578 | ||
d62a17ae | 7579 | SET_IF_PARAM(params, auth_type); |
7580 | params->auth_type = OSPF_AUTH_SIMPLE; | |
718e3744 | 7581 | |
d62a17ae | 7582 | return CMD_SUCCESS; |
718e3744 | 7583 | } |
7584 | ||
b4a039bf DS |
7585 | DEFUN (no_ip_ospf_authentication_args, |
7586 | no_ip_ospf_authentication_args_addr_cmd, | |
7a7be519 | 7587 | "no ip ospf authentication <null|message-digest> [A.B.C.D]", |
b4a039bf DS |
7588 | NO_STR |
7589 | "IP Information\n" | |
7590 | "OSPF interface commands\n" | |
7591 | "Enable authentication on this interface\n" | |
7592 | "Use null authentication\n" | |
7593 | "Use message-digest authentication\n" | |
efd7904e | 7594 | "Address of interface\n") |
b4a039bf | 7595 | { |
d62a17ae | 7596 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7597 | int idx_encryption = 4; | |
7598 | int idx_ipv4 = 5; | |
7599 | struct in_addr addr; | |
7600 | int ret; | |
7601 | struct ospf_if_params *params; | |
7602 | struct route_node *rn; | |
7603 | int auth_type; | |
7604 | ||
7605 | params = IF_DEF_PARAMS(ifp); | |
7606 | ||
7607 | if (argc == 6) { | |
7608 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
7609 | if (!ret) { | |
7610 | vty_out(vty, | |
7611 | "Please specify interface address by A.B.C.D\n"); | |
7612 | return CMD_WARNING_CONFIG_FAILED; | |
7613 | } | |
b4a039bf | 7614 | |
d62a17ae | 7615 | params = ospf_lookup_if_params(ifp, addr); |
7616 | if (params == NULL) { | |
7617 | vty_out(vty, "Ip Address specified is unknown\n"); | |
7618 | return CMD_WARNING_CONFIG_FAILED; | |
7619 | } | |
7620 | params->auth_type = OSPF_AUTH_NOTSET; | |
7621 | UNSET_IF_PARAM(params, auth_type); | |
7622 | if (params != IF_DEF_PARAMS(ifp)) { | |
7623 | ospf_free_if_params(ifp, addr); | |
7624 | ospf_if_update_params(ifp, addr); | |
7625 | } | |
7626 | } else { | |
7627 | if (argv[idx_encryption]->arg[0] == 'n') { | |
7628 | auth_type = OSPF_AUTH_NULL; | |
7629 | } else if (argv[idx_encryption]->arg[0] == 'm') { | |
7630 | auth_type = OSPF_AUTH_CRYPTOGRAPHIC; | |
7631 | } else { | |
7632 | vty_out(vty, "Unexpected input encountered\n"); | |
7633 | return CMD_WARNING_CONFIG_FAILED; | |
7634 | } | |
7635 | /* | |
7636 | * Here we have a case where the user has entered | |
7637 | * 'no ip ospf authentication (null | message_digest )' | |
7638 | * we need to find if we have any ip addresses underneath it | |
7639 | * that | |
7640 | * correspond to the associated type. | |
7641 | */ | |
7642 | if (params->auth_type == auth_type) { | |
7643 | params->auth_type = OSPF_AUTH_NOTSET; | |
7644 | UNSET_IF_PARAM(params, auth_type); | |
7645 | } | |
7646 | ||
7647 | for (rn = route_top(IF_OIFS_PARAMS(ifp)); rn; | |
7648 | rn = route_next(rn)) { | |
7649 | if ((params = rn->info)) { | |
7650 | if (params->auth_type == auth_type) { | |
7651 | params->auth_type = OSPF_AUTH_NOTSET; | |
7652 | UNSET_IF_PARAM(params, auth_type); | |
7653 | if (params != IF_DEF_PARAMS(ifp)) { | |
7654 | ospf_free_if_params( | |
7655 | ifp, rn->p.u.prefix4); | |
7656 | ospf_if_update_params( | |
7657 | ifp, rn->p.u.prefix4); | |
7658 | } | |
7659 | } | |
7660 | } | |
b4a039bf | 7661 | } |
b4a039bf | 7662 | } |
b4a039bf | 7663 | |
d62a17ae | 7664 | return CMD_SUCCESS; |
b4a039bf DS |
7665 | } |
7666 | ||
718e3744 | 7667 | DEFUN (no_ip_ospf_authentication, |
7668 | no_ip_ospf_authentication_addr_cmd, | |
7a7be519 | 7669 | "no ip ospf authentication [A.B.C.D]", |
718e3744 | 7670 | NO_STR |
7671 | "IP Information\n" | |
7672 | "OSPF interface commands\n" | |
7673 | "Enable authentication on this interface\n" | |
efd7904e | 7674 | "Address of interface\n") |
718e3744 | 7675 | { |
d62a17ae | 7676 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7677 | int idx_ipv4 = 4; | |
7678 | struct in_addr addr; | |
7679 | int ret; | |
7680 | struct ospf_if_params *params; | |
7681 | struct route_node *rn; | |
7682 | ||
7683 | params = IF_DEF_PARAMS(ifp); | |
7684 | ||
7685 | if (argc == 5) { | |
7686 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
7687 | if (!ret) { | |
7688 | vty_out(vty, | |
7689 | "Please specify interface address by A.B.C.D\n"); | |
7690 | return CMD_WARNING_CONFIG_FAILED; | |
7691 | } | |
718e3744 | 7692 | |
d62a17ae | 7693 | params = ospf_lookup_if_params(ifp, addr); |
7694 | if (params == NULL) { | |
7695 | vty_out(vty, "Ip Address specified is unknown\n"); | |
7696 | return CMD_WARNING_CONFIG_FAILED; | |
7697 | } | |
718e3744 | 7698 | |
d62a17ae | 7699 | params->auth_type = OSPF_AUTH_NOTSET; |
7700 | UNSET_IF_PARAM(params, auth_type); | |
7701 | if (params != IF_DEF_PARAMS(ifp)) { | |
7702 | ospf_free_if_params(ifp, addr); | |
7703 | ospf_if_update_params(ifp, addr); | |
7704 | } | |
7705 | } else { | |
7706 | /* | |
7707 | * When a user enters 'no ip ospf authentication' | |
7708 | * We should remove all authentication types from | |
7709 | * the interface. | |
7710 | */ | |
7711 | if ((params->auth_type == OSPF_AUTH_NULL) | |
7712 | || (params->auth_type == OSPF_AUTH_CRYPTOGRAPHIC) | |
7713 | || (params->auth_type == OSPF_AUTH_SIMPLE)) { | |
7714 | params->auth_type = OSPF_AUTH_NOTSET; | |
7715 | UNSET_IF_PARAM(params, auth_type); | |
7716 | } | |
813d4307 | 7717 | |
d62a17ae | 7718 | for (rn = route_top(IF_OIFS_PARAMS(ifp)); rn; |
7719 | rn = route_next(rn)) { | |
7720 | if ((params = rn->info)) { | |
7721 | ||
7722 | if ((params->auth_type == OSPF_AUTH_NULL) | |
7723 | || (params->auth_type | |
7724 | == OSPF_AUTH_CRYPTOGRAPHIC) | |
7725 | || (params->auth_type | |
7726 | == OSPF_AUTH_SIMPLE)) { | |
7727 | params->auth_type = OSPF_AUTH_NOTSET; | |
7728 | UNSET_IF_PARAM(params, auth_type); | |
7729 | if (params != IF_DEF_PARAMS(ifp)) { | |
7730 | ospf_free_if_params( | |
7731 | ifp, rn->p.u.prefix4); | |
7732 | ospf_if_update_params( | |
7733 | ifp, rn->p.u.prefix4); | |
7734 | } | |
7735 | } | |
7736 | } | |
b4a039bf | 7737 | } |
b4a039bf | 7738 | } |
d62a17ae | 7739 | |
7740 | return CMD_SUCCESS; | |
718e3744 | 7741 | } |
7742 | ||
0d829fa7 | 7743 | |
718e3744 | 7744 | DEFUN (ip_ospf_authentication_key, |
7745 | ip_ospf_authentication_key_addr_cmd, | |
7a7be519 | 7746 | "ip ospf authentication-key AUTH_KEY [A.B.C.D]", |
718e3744 | 7747 | "IP Information\n" |
7748 | "OSPF interface commands\n" | |
7749 | "Authentication password (key)\n" | |
7750 | "The OSPF password (key)\n" | |
efd7904e | 7751 | "Address of interface\n") |
718e3744 | 7752 | { |
d62a17ae | 7753 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7754 | int idx = 0; | |
7755 | struct in_addr addr; | |
7756 | struct ospf_if_params *params; | |
718e3744 | 7757 | |
d62a17ae | 7758 | params = IF_DEF_PARAMS(ifp); |
7759 | ||
7760 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
7761 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
7762 | vty_out(vty, | |
7763 | "Please specify interface address by A.B.C.D\n"); | |
7764 | return CMD_WARNING_CONFIG_FAILED; | |
7765 | } | |
718e3744 | 7766 | |
d62a17ae | 7767 | params = ospf_get_if_params(ifp, addr); |
7768 | ospf_if_update_params(ifp, addr); | |
7769 | } | |
718e3744 | 7770 | |
4d65d927 QY |
7771 | strlcpy((char *)params->auth_simple, argv[3]->arg, |
7772 | sizeof(params->auth_simple)); | |
d62a17ae | 7773 | SET_IF_PARAM(params, auth_simple); |
718e3744 | 7774 | |
d62a17ae | 7775 | return CMD_SUCCESS; |
718e3744 | 7776 | } |
7777 | ||
7a7be519 | 7778 | DEFUN_HIDDEN (ospf_authentication_key, |
747e489c | 7779 | ospf_authentication_key_cmd, |
0d829fa7 | 7780 | "ospf authentication-key AUTH_KEY [A.B.C.D]", |
747e489c | 7781 | "OSPF interface commands\n" |
baf9eaad | 7782 | VLINK_HELPSTR_AUTH_SIMPLE |
0d829fa7 | 7783 | "Address of interface\n") |
718e3744 | 7784 | { |
d62a17ae | 7785 | return ip_ospf_authentication_key(self, vty, argc, argv); |
718e3744 | 7786 | } |
7787 | ||
7a7be519 | 7788 | DEFUN (no_ip_ospf_authentication_key, |
7789 | no_ip_ospf_authentication_key_authkey_addr_cmd, | |
7790 | "no ip ospf authentication-key [AUTH_KEY [A.B.C.D]]", | |
7791 | NO_STR | |
7792 | "IP Information\n" | |
7793 | "OSPF interface commands\n" | |
baf9eaad CS |
7794 | VLINK_HELPSTR_AUTH_SIMPLE |
7795 | "Address of interface\n") | |
7a7be519 | 7796 | { |
d62a17ae | 7797 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7798 | int idx = 0; | |
7799 | struct in_addr addr; | |
7800 | struct ospf_if_params *params; | |
7801 | params = IF_DEF_PARAMS(ifp); | |
7802 | ||
7803 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
7804 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
7805 | vty_out(vty, | |
7806 | "Please specify interface address by A.B.C.D\n"); | |
7807 | return CMD_WARNING_CONFIG_FAILED; | |
7808 | } | |
7a7be519 | 7809 | |
d62a17ae | 7810 | params = ospf_lookup_if_params(ifp, addr); |
7811 | if (params == NULL) | |
7812 | return CMD_SUCCESS; | |
7a7be519 | 7813 | } |
813d4307 | 7814 | |
d62a17ae | 7815 | memset(params->auth_simple, 0, OSPF_AUTH_SIMPLE_SIZE); |
7816 | UNSET_IF_PARAM(params, auth_simple); | |
718e3744 | 7817 | |
d62a17ae | 7818 | if (params != IF_DEF_PARAMS(ifp)) { |
7819 | ospf_free_if_params(ifp, addr); | |
7820 | ospf_if_update_params(ifp, addr); | |
7821 | } | |
813d4307 | 7822 | |
d62a17ae | 7823 | return CMD_SUCCESS; |
7a7be519 | 7824 | } |
813d4307 | 7825 | |
0d829fa7 QY |
7826 | DEFUN_HIDDEN (no_ospf_authentication_key, |
7827 | no_ospf_authentication_key_authkey_addr_cmd, | |
7828 | "no ospf authentication-key [AUTH_KEY [A.B.C.D]]", | |
7829 | NO_STR | |
7830 | "OSPF interface commands\n" | |
baf9eaad CS |
7831 | VLINK_HELPSTR_AUTH_SIMPLE |
7832 | "Address of interface\n") | |
0d829fa7 | 7833 | { |
d62a17ae | 7834 | return no_ip_ospf_authentication_key(self, vty, argc, argv); |
0d829fa7 QY |
7835 | } |
7836 | ||
718e3744 | 7837 | DEFUN (ip_ospf_message_digest_key, |
537eae3f | 7838 | ip_ospf_message_digest_key_cmd, |
7a7be519 | 7839 | "ip ospf message-digest-key (1-255) md5 KEY [A.B.C.D]", |
718e3744 | 7840 | "IP Information\n" |
7841 | "OSPF interface commands\n" | |
7842 | "Message digest authentication password (key)\n" | |
7843 | "Key ID\n" | |
7844 | "Use MD5 algorithm\n" | |
fefa0d82 QY |
7845 | "The OSPF password (key)\n" |
7846 | "Address of interface\n") | |
718e3744 | 7847 | { |
d62a17ae | 7848 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7849 | struct crypt_key *ck; | |
d7c0a89a | 7850 | uint8_t key_id; |
d62a17ae | 7851 | struct in_addr addr; |
7852 | struct ospf_if_params *params; | |
7853 | ||
7854 | params = IF_DEF_PARAMS(ifp); | |
7855 | int idx = 0; | |
7856 | ||
7857 | argv_find(argv, argc, "(1-255)", &idx); | |
7858 | char *keyid = argv[idx]->arg; | |
7859 | argv_find(argv, argc, "KEY", &idx); | |
7860 | char *cryptkey = argv[idx]->arg; | |
7861 | ||
7862 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
7863 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
7864 | vty_out(vty, | |
7865 | "Please specify interface address by A.B.C.D\n"); | |
7866 | return CMD_WARNING_CONFIG_FAILED; | |
7867 | } | |
7868 | ||
7869 | params = ospf_get_if_params(ifp, addr); | |
7870 | ospf_if_update_params(ifp, addr); | |
718e3744 | 7871 | } |
7872 | ||
d62a17ae | 7873 | key_id = strtol(keyid, NULL, 10); |
519b1464 MS |
7874 | |
7875 | /* Remove existing key, if any */ | |
7876 | ospf_crypt_key_delete(params->auth_crypt, key_id); | |
718e3744 | 7877 | |
d62a17ae | 7878 | ck = ospf_crypt_key_new(); |
d7c0a89a | 7879 | ck->key_id = (uint8_t)key_id; |
4d65d927 | 7880 | strlcpy((char *)ck->auth_key, cryptkey, sizeof(ck->auth_key)); |
718e3744 | 7881 | |
d62a17ae | 7882 | ospf_crypt_key_add(params->auth_crypt, ck); |
7883 | SET_IF_PARAM(params, auth_crypt); | |
718e3744 | 7884 | |
d62a17ae | 7885 | return CMD_SUCCESS; |
718e3744 | 7886 | } |
7887 | ||
7a7be519 | 7888 | DEFUN_HIDDEN (ospf_message_digest_key, |
747e489c | 7889 | ospf_message_digest_key_cmd, |
0d829fa7 | 7890 | "ospf message-digest-key (1-255) md5 KEY [A.B.C.D]", |
747e489c DW |
7891 | "OSPF interface commands\n" |
7892 | "Message digest authentication password (key)\n" | |
7893 | "Key ID\n" | |
7894 | "Use MD5 algorithm\n" | |
0d829fa7 QY |
7895 | "The OSPF password (key)\n" |
7896 | "Address of interface\n") | |
7a7be519 | 7897 | { |
d62a17ae | 7898 | return ip_ospf_message_digest_key(self, vty, argc, argv); |
7a7be519 | 7899 | } |
718e3744 | 7900 | |
537eae3f QY |
7901 | DEFUN (no_ip_ospf_message_digest_key, |
7902 | no_ip_ospf_message_digest_key_cmd, | |
0d829fa7 | 7903 | "no ip ospf message-digest-key (1-255) [md5 KEY] [A.B.C.D]", |
813d4307 DW |
7904 | NO_STR |
7905 | "IP Information\n" | |
7906 | "OSPF interface commands\n" | |
7907 | "Message digest authentication password (key)\n" | |
7908 | "Key ID\n" | |
7909 | "Use MD5 algorithm\n" | |
0d829fa7 QY |
7910 | "The OSPF password (key)\n" |
7911 | "Address of interface\n") | |
813d4307 | 7912 | { |
d62a17ae | 7913 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7914 | int idx = 0; | |
7915 | struct crypt_key *ck; | |
7916 | int key_id; | |
7917 | struct in_addr addr; | |
7918 | struct ospf_if_params *params; | |
7919 | params = IF_DEF_PARAMS(ifp); | |
7920 | ||
7921 | argv_find(argv, argc, "(1-255)", &idx); | |
7922 | char *keyid = argv[idx]->arg; | |
7923 | ||
7924 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
7925 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
7926 | vty_out(vty, | |
7927 | "Please specify interface address by A.B.C.D\n"); | |
7928 | return CMD_WARNING_CONFIG_FAILED; | |
7929 | } | |
7a7be519 | 7930 | |
d62a17ae | 7931 | params = ospf_lookup_if_params(ifp, addr); |
7932 | if (params == NULL) | |
7933 | return CMD_SUCCESS; | |
7a7be519 | 7934 | } |
7935 | ||
d62a17ae | 7936 | key_id = strtol(keyid, NULL, 10); |
7937 | ck = ospf_crypt_key_lookup(params->auth_crypt, key_id); | |
7938 | if (ck == NULL) { | |
7939 | vty_out(vty, "OSPF: Key %d does not exist\n", key_id); | |
7940 | return CMD_WARNING_CONFIG_FAILED; | |
7941 | } | |
7a7be519 | 7942 | |
d62a17ae | 7943 | ospf_crypt_key_delete(params->auth_crypt, key_id); |
7a7be519 | 7944 | |
d62a17ae | 7945 | if (params != IF_DEF_PARAMS(ifp)) { |
7946 | ospf_free_if_params(ifp, addr); | |
7947 | ospf_if_update_params(ifp, addr); | |
7948 | } | |
7a7be519 | 7949 | |
d62a17ae | 7950 | return CMD_SUCCESS; |
7a7be519 | 7951 | } |
813d4307 | 7952 | |
0d829fa7 | 7953 | DEFUN_HIDDEN (no_ospf_message_digest_key, |
537eae3f | 7954 | no_ospf_message_digest_key_cmd, |
0d829fa7 QY |
7955 | "no ospf message-digest-key (1-255) [md5 KEY] [A.B.C.D]", |
7956 | NO_STR | |
7957 | "OSPF interface commands\n" | |
7958 | "Message digest authentication password (key)\n" | |
7959 | "Key ID\n" | |
efd7904e RW |
7960 | "Use MD5 algorithm\n" |
7961 | "The OSPF password (key)\n" | |
7962 | "Address of interface\n") | |
718e3744 | 7963 | { |
d62a17ae | 7964 | return no_ip_ospf_message_digest_key(self, vty, argc, argv); |
718e3744 | 7965 | } |
7966 | ||
718e3744 | 7967 | DEFUN (ip_ospf_cost, |
5c2fc921 | 7968 | ip_ospf_cost_cmd, |
7a7be519 | 7969 | "ip ospf cost (1-65535) [A.B.C.D]", |
718e3744 | 7970 | "IP Information\n" |
7971 | "OSPF interface commands\n" | |
7972 | "Interface cost\n" | |
7973 | "Cost\n" | |
5c2fc921 | 7974 | "Address of interface\n") |
718e3744 | 7975 | { |
d62a17ae | 7976 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7977 | int idx = 0; | |
d7c0a89a | 7978 | uint32_t cost = OSPF_OUTPUT_COST_DEFAULT; |
d62a17ae | 7979 | struct in_addr addr; |
7980 | struct ospf_if_params *params; | |
7981 | params = IF_DEF_PARAMS(ifp); | |
7982 | ||
7983 | // get arguments | |
7984 | char *coststr = NULL, *ifaddr = NULL; | |
35955c14 | 7985 | |
c31a793b VJ |
7986 | argv_find(argv, argc, "(1-65535)", &idx); |
7987 | coststr = argv[idx]->arg; | |
d62a17ae | 7988 | cost = strtol(coststr, NULL, 10); |
7989 | ||
c31a793b | 7990 | ifaddr = argv_find(argv, argc, "A.B.C.D", &idx) ? argv[idx]->arg : NULL; |
d62a17ae | 7991 | if (ifaddr) { |
7992 | if (!inet_aton(ifaddr, &addr)) { | |
7993 | vty_out(vty, | |
7994 | "Please specify interface address by A.B.C.D\n"); | |
7995 | return CMD_WARNING_CONFIG_FAILED; | |
7996 | } | |
718e3744 | 7997 | |
d62a17ae | 7998 | params = ospf_get_if_params(ifp, addr); |
7999 | ospf_if_update_params(ifp, addr); | |
718e3744 | 8000 | } |
8001 | ||
d62a17ae | 8002 | SET_IF_PARAM(params, output_cost_cmd); |
8003 | params->output_cost_cmd = cost; | |
718e3744 | 8004 | |
d62a17ae | 8005 | ospf_if_recalculate_output_cost(ifp); |
5c2fc921 | 8006 | |
d62a17ae | 8007 | return CMD_SUCCESS; |
718e3744 | 8008 | } |
8009 | ||
7a7be519 | 8010 | DEFUN_HIDDEN (ospf_cost, |
5c2fc921 QY |
8011 | ospf_cost_cmd, |
8012 | "ospf cost (1-65535) [A.B.C.D]", | |
747e489c DW |
8013 | "OSPF interface commands\n" |
8014 | "Interface cost\n" | |
8015 | "Cost\n" | |
5c2fc921 | 8016 | "Address of interface\n") |
7a7be519 | 8017 | { |
d62a17ae | 8018 | return ip_ospf_cost(self, vty, argc, argv); |
7a7be519 | 8019 | } |
9eff36b3 | 8020 | |
718e3744 | 8021 | DEFUN (no_ip_ospf_cost, |
5c2fc921 QY |
8022 | no_ip_ospf_cost_cmd, |
8023 | "no ip ospf cost [(1-65535)] [A.B.C.D]", | |
718e3744 | 8024 | NO_STR |
efd7904e | 8025 | "IP Information\n" |
718e3744 | 8026 | "OSPF interface commands\n" |
8027 | "Interface cost\n" | |
efd7904e RW |
8028 | "Cost\n" |
8029 | "Address of interface\n") | |
718e3744 | 8030 | { |
d62a17ae | 8031 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8032 | int idx = 0; | |
8033 | struct in_addr addr; | |
8034 | struct ospf_if_params *params; | |
7a7be519 | 8035 | |
d62a17ae | 8036 | params = IF_DEF_PARAMS(ifp); |
718e3744 | 8037 | |
d62a17ae | 8038 | // get arguments |
8039 | char *ifaddr = NULL; | |
8040 | ifaddr = argv_find(argv, argc, "A.B.C.D", &idx) ? argv[idx]->arg : NULL; | |
718e3744 | 8041 | |
d62a17ae | 8042 | /* According to the semantics we are mimicking "no ip ospf cost N" is |
8043 | * always treated as "no ip ospf cost" regardless of the actual value | |
8044 | * of N already configured for the interface. Thus ignore cost. */ | |
7a7be519 | 8045 | |
d62a17ae | 8046 | if (ifaddr) { |
8047 | if (!inet_aton(ifaddr, &addr)) { | |
8048 | vty_out(vty, | |
8049 | "Please specify interface address by A.B.C.D\n"); | |
8050 | return CMD_WARNING_CONFIG_FAILED; | |
8051 | } | |
7a7be519 | 8052 | |
d62a17ae | 8053 | params = ospf_lookup_if_params(ifp, addr); |
8054 | if (params == NULL) | |
8055 | return CMD_SUCCESS; | |
8056 | } | |
7a7be519 | 8057 | |
d62a17ae | 8058 | UNSET_IF_PARAM(params, output_cost_cmd); |
7a7be519 | 8059 | |
d62a17ae | 8060 | if (params != IF_DEF_PARAMS(ifp)) { |
8061 | ospf_free_if_params(ifp, addr); | |
8062 | ospf_if_update_params(ifp, addr); | |
8063 | } | |
7a7be519 | 8064 | |
d62a17ae | 8065 | ospf_if_recalculate_output_cost(ifp); |
7a7be519 | 8066 | |
d62a17ae | 8067 | return CMD_SUCCESS; |
7a7be519 | 8068 | } |
9eff36b3 | 8069 | |
5c2fc921 QY |
8070 | DEFUN_HIDDEN (no_ospf_cost, |
8071 | no_ospf_cost_cmd, | |
8072 | "no ospf cost [(1-65535)] [A.B.C.D]", | |
8073 | NO_STR | |
8074 | "OSPF interface commands\n" | |
8075 | "Interface cost\n" | |
8076 | "Cost\n" | |
8077 | "Address of interface\n") | |
827341b7 | 8078 | { |
d62a17ae | 8079 | return no_ip_ospf_cost(self, vty, argc, argv); |
827341b7 DO |
8080 | } |
8081 | ||
d62a17ae | 8082 | static void ospf_nbr_timer_update(struct ospf_interface *oi) |
718e3744 | 8083 | { |
d62a17ae | 8084 | struct route_node *rn; |
8085 | struct ospf_neighbor *nbr; | |
718e3744 | 8086 | |
d62a17ae | 8087 | for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) |
8088 | if ((nbr = rn->info)) { | |
8089 | nbr->v_inactivity = OSPF_IF_PARAM(oi, v_wait); | |
8090 | nbr->v_db_desc = OSPF_IF_PARAM(oi, retransmit_interval); | |
8091 | nbr->v_ls_req = OSPF_IF_PARAM(oi, retransmit_interval); | |
8092 | nbr->v_ls_upd = OSPF_IF_PARAM(oi, retransmit_interval); | |
8093 | } | |
718e3744 | 8094 | } |
8095 | ||
d62a17ae | 8096 | static int ospf_vty_dead_interval_set(struct vty *vty, const char *interval_str, |
8097 | const char *nbr_str, | |
8098 | const char *fast_hello_str) | |
8099 | { | |
8100 | VTY_DECLVAR_CONTEXT(interface, ifp); | |
d7c0a89a QY |
8101 | uint32_t seconds; |
8102 | uint8_t hellomult; | |
d62a17ae | 8103 | struct in_addr addr; |
8104 | int ret; | |
8105 | struct ospf_if_params *params; | |
8106 | struct ospf_interface *oi; | |
8107 | struct route_node *rn; | |
718e3744 | 8108 | |
d62a17ae | 8109 | params = IF_DEF_PARAMS(ifp); |
8110 | ||
8111 | if (nbr_str) { | |
8112 | ret = inet_aton(nbr_str, &addr); | |
8113 | if (!ret) { | |
8114 | vty_out(vty, | |
8115 | "Please specify interface address by A.B.C.D\n"); | |
8116 | return CMD_WARNING_CONFIG_FAILED; | |
8117 | } | |
8118 | ||
8119 | params = ospf_get_if_params(ifp, addr); | |
8120 | ospf_if_update_params(ifp, addr); | |
8121 | } | |
8122 | ||
8123 | if (interval_str) { | |
8124 | seconds = strtoul(interval_str, NULL, 10); | |
8125 | ||
8126 | /* reset fast_hello too, just to be sure */ | |
8127 | UNSET_IF_PARAM(params, fast_hello); | |
8128 | params->fast_hello = OSPF_FAST_HELLO_DEFAULT; | |
8129 | } else if (fast_hello_str) { | |
8130 | hellomult = strtoul(fast_hello_str, NULL, 10); | |
8131 | /* 1s dead-interval with sub-second hellos desired */ | |
8132 | seconds = OSPF_ROUTER_DEAD_INTERVAL_MINIMAL; | |
8133 | SET_IF_PARAM(params, fast_hello); | |
8134 | params->fast_hello = hellomult; | |
8135 | } else { | |
8136 | vty_out(vty, | |
8137 | "Please specify dead-interval or hello-multiplier\n"); | |
8138 | return CMD_WARNING_CONFIG_FAILED; | |
8139 | } | |
8140 | ||
8141 | SET_IF_PARAM(params, v_wait); | |
8142 | params->v_wait = seconds; | |
182d6bdc | 8143 | params->is_v_wait_set = true; |
d62a17ae | 8144 | |
8145 | /* Update timer values in neighbor structure. */ | |
8146 | if (nbr_str) { | |
b5a8894d CS |
8147 | struct ospf *ospf = NULL; |
8148 | ||
a36898e7 | 8149 | ospf = ospf_lookup_by_vrf_id(ifp->vrf_id); |
b5a8894d | 8150 | if (ospf) { |
d62a17ae | 8151 | oi = ospf_if_lookup_by_local_addr(ospf, ifp, addr); |
8152 | if (oi) | |
8153 | ospf_nbr_timer_update(oi); | |
8154 | } | |
8155 | } else { | |
8156 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) | |
8157 | if ((oi = rn->info)) | |
8158 | ospf_nbr_timer_update(oi); | |
8159 | } | |
8160 | ||
8161 | return CMD_SUCCESS; | |
718e3744 | 8162 | } |
8163 | ||
f9ad937f | 8164 | DEFUN (ip_ospf_dead_interval, |
0d829fa7 | 8165 | ip_ospf_dead_interval_cmd, |
7a7be519 | 8166 | "ip ospf dead-interval (1-65535) [A.B.C.D]", |
f9ad937f | 8167 | "IP Information\n" |
8168 | "OSPF interface commands\n" | |
99a522c7 | 8169 | "Interval time after which a neighbor is declared down\n" |
f9ad937f | 8170 | "Seconds\n" |
8171 | "Address of interface\n") | |
8172 | { | |
d62a17ae | 8173 | int idx = 0; |
8174 | char *interval = argv_find(argv, argc, "(1-65535)", &idx) | |
8175 | ? argv[idx]->arg | |
8176 | : NULL; | |
8177 | char *ifaddr = | |
8178 | argv_find(argv, argc, "A.B.C.D", &idx) ? argv[idx]->arg : NULL; | |
8179 | return ospf_vty_dead_interval_set(vty, interval, ifaddr, NULL); | |
f9ad937f | 8180 | } |
8181 | ||
718e3744 | 8182 | |
7a7be519 | 8183 | DEFUN_HIDDEN (ospf_dead_interval, |
747e489c | 8184 | ospf_dead_interval_cmd, |
0d829fa7 | 8185 | "ospf dead-interval (1-65535) [A.B.C.D]", |
747e489c | 8186 | "OSPF interface commands\n" |
99a522c7 | 8187 | "Interval time after which a neighbor is declared down\n" |
0d829fa7 QY |
8188 | "Seconds\n" |
8189 | "Address of interface\n") | |
7a7be519 | 8190 | { |
d62a17ae | 8191 | return ip_ospf_dead_interval(self, vty, argc, argv); |
7a7be519 | 8192 | } |
718e3744 | 8193 | |
f9ad937f | 8194 | DEFUN (ip_ospf_dead_interval_minimal, |
8195 | ip_ospf_dead_interval_minimal_addr_cmd, | |
7a7be519 | 8196 | "ip ospf dead-interval minimal hello-multiplier (1-10) [A.B.C.D]", |
f9ad937f | 8197 | "IP Information\n" |
8198 | "OSPF interface commands\n" | |
99a522c7 | 8199 | "Interval time after which a neighbor is declared down\n" |
f9ad937f | 8200 | "Minimal 1s dead-interval with fast sub-second hellos\n" |
8201 | "Hello multiplier factor\n" | |
8202 | "Number of Hellos to send each second\n" | |
8203 | "Address of interface\n") | |
8204 | { | |
d62a17ae | 8205 | int idx_number = 5; |
8206 | int idx_ipv4 = 6; | |
8207 | if (argc == 7) | |
8208 | return ospf_vty_dead_interval_set( | |
8209 | vty, NULL, argv[idx_ipv4]->arg, argv[idx_number]->arg); | |
8210 | else | |
8211 | return ospf_vty_dead_interval_set(vty, NULL, NULL, | |
8212 | argv[idx_number]->arg); | |
f9ad937f | 8213 | } |
8214 | ||
718e3744 | 8215 | DEFUN (no_ip_ospf_dead_interval, |
0d829fa7 | 8216 | no_ip_ospf_dead_interval_cmd, |
e83a9414 | 8217 | "no ip ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]", |
718e3744 | 8218 | NO_STR |
8219 | "IP Information\n" | |
8220 | "OSPF interface commands\n" | |
99a522c7 | 8221 | "Interval time after which a neighbor is declared down\n" |
f9dfba8d | 8222 | "Seconds\n" |
efd7904e RW |
8223 | "Minimal 1s dead-interval with fast sub-second hellos\n" |
8224 | "Hello multiplier factor\n" | |
8225 | "Number of Hellos to send each second\n" | |
8226 | "Address of interface\n") | |
718e3744 | 8227 | { |
d62a17ae | 8228 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8229 | int idx_ipv4 = argc - 1; | |
8230 | struct in_addr addr = {.s_addr = 0L}; | |
8231 | int ret; | |
8232 | struct ospf_if_params *params; | |
8233 | struct ospf_interface *oi; | |
8234 | struct route_node *rn; | |
8235 | ||
8236 | params = IF_DEF_PARAMS(ifp); | |
8237 | ||
8238 | if (argv[idx_ipv4]->type == IPV4_TKN) { | |
8239 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
8240 | if (!ret) { | |
8241 | vty_out(vty, | |
8242 | "Please specify interface address by A.B.C.D\n"); | |
8243 | return CMD_WARNING_CONFIG_FAILED; | |
8244 | } | |
020709f9 | 8245 | |
d62a17ae | 8246 | params = ospf_lookup_if_params(ifp, addr); |
8247 | if (params == NULL) | |
8248 | return CMD_SUCCESS; | |
8249 | } | |
718e3744 | 8250 | |
d62a17ae | 8251 | UNSET_IF_PARAM(params, v_wait); |
8252 | params->v_wait = OSPF_ROUTER_DEAD_INTERVAL_DEFAULT; | |
182d6bdc | 8253 | params->is_v_wait_set = false; |
d62a17ae | 8254 | |
8255 | UNSET_IF_PARAM(params, fast_hello); | |
8256 | params->fast_hello = OSPF_FAST_HELLO_DEFAULT; | |
8257 | ||
8258 | if (params != IF_DEF_PARAMS(ifp)) { | |
8259 | ospf_free_if_params(ifp, addr); | |
8260 | ospf_if_update_params(ifp, addr); | |
718e3744 | 8261 | } |
8262 | ||
d62a17ae | 8263 | /* Update timer values in neighbor structure. */ |
8264 | if (argc == 1) { | |
b5a8894d | 8265 | struct ospf *ospf = NULL; |
718e3744 | 8266 | |
a36898e7 | 8267 | ospf = ospf_lookup_by_vrf_id(ifp->vrf_id); |
b5a8894d | 8268 | if (ospf) { |
d62a17ae | 8269 | oi = ospf_if_lookup_by_local_addr(ospf, ifp, addr); |
8270 | if (oi) | |
8271 | ospf_nbr_timer_update(oi); | |
8272 | } | |
8273 | } else { | |
8274 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) | |
8275 | if ((oi = rn->info)) | |
8276 | ospf_nbr_timer_update(oi); | |
8277 | } | |
8278 | ||
8279 | return CMD_SUCCESS; | |
718e3744 | 8280 | } |
8281 | ||
0d829fa7 QY |
8282 | DEFUN_HIDDEN (no_ospf_dead_interval, |
8283 | no_ospf_dead_interval_cmd, | |
8284 | "no ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]", | |
8285 | NO_STR | |
8286 | "OSPF interface commands\n" | |
99a522c7 | 8287 | "Interval time after which a neighbor is declared down\n" |
0d829fa7 | 8288 | "Seconds\n" |
efd7904e RW |
8289 | "Minimal 1s dead-interval with fast sub-second hellos\n" |
8290 | "Hello multiplier factor\n" | |
8291 | "Number of Hellos to send each second\n" | |
8292 | "Address of interface\n") | |
0d829fa7 | 8293 | { |
d62a17ae | 8294 | return no_ip_ospf_dead_interval(self, vty, argc, argv); |
0d829fa7 QY |
8295 | } |
8296 | ||
718e3744 | 8297 | DEFUN (ip_ospf_hello_interval, |
0d829fa7 | 8298 | ip_ospf_hello_interval_cmd, |
7a7be519 | 8299 | "ip ospf hello-interval (1-65535) [A.B.C.D]", |
718e3744 | 8300 | "IP Information\n" |
8301 | "OSPF interface commands\n" | |
8302 | "Time between HELLO packets\n" | |
8303 | "Seconds\n" | |
0d829fa7 | 8304 | "Address of interface\n") |
718e3744 | 8305 | { |
d62a17ae | 8306 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8307 | int idx = 0; | |
8308 | struct in_addr addr; | |
8309 | struct ospf_if_params *params; | |
8310 | params = IF_DEF_PARAMS(ifp); | |
d7c0a89a | 8311 | uint32_t seconds = 0; |
d62a17ae | 8312 | |
8313 | argv_find(argv, argc, "(1-65535)", &idx); | |
8314 | seconds = strtol(argv[idx]->arg, NULL, 10); | |
8315 | ||
8316 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
8317 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
8318 | vty_out(vty, | |
8319 | "Please specify interface address by A.B.C.D\n"); | |
8320 | return CMD_WARNING_CONFIG_FAILED; | |
8321 | } | |
718e3744 | 8322 | |
d62a17ae | 8323 | params = ospf_get_if_params(ifp, addr); |
8324 | ospf_if_update_params(ifp, addr); | |
8325 | } | |
718e3744 | 8326 | |
d62a17ae | 8327 | SET_IF_PARAM(params, v_hello); |
8328 | params->v_hello = seconds; | |
718e3744 | 8329 | |
182d6bdc K |
8330 | if (!params->is_v_wait_set) { |
8331 | SET_IF_PARAM(params, v_wait); | |
8332 | /* As per RFC 4062 | |
8333 | * The router dead interval should | |
8334 | * be some multiple of the HelloInterval (perhaps 4 times the | |
8335 | * hello interval) and must be the same for all routers | |
8336 | * attached to a common network. | |
8337 | */ | |
8338 | params->v_wait = 4 * seconds; | |
8339 | } | |
8340 | ||
d62a17ae | 8341 | return CMD_SUCCESS; |
718e3744 | 8342 | } |
8343 | ||
7a7be519 | 8344 | DEFUN_HIDDEN (ospf_hello_interval, |
747e489c | 8345 | ospf_hello_interval_cmd, |
0d829fa7 | 8346 | "ospf hello-interval (1-65535) [A.B.C.D]", |
747e489c DW |
8347 | "OSPF interface commands\n" |
8348 | "Time between HELLO packets\n" | |
0d829fa7 QY |
8349 | "Seconds\n" |
8350 | "Address of interface\n") | |
7a7be519 | 8351 | { |
d62a17ae | 8352 | return ip_ospf_hello_interval(self, vty, argc, argv); |
7a7be519 | 8353 | } |
718e3744 | 8354 | |
8355 | DEFUN (no_ip_ospf_hello_interval, | |
0d829fa7 QY |
8356 | no_ip_ospf_hello_interval_cmd, |
8357 | "no ip ospf hello-interval [(1-65535) [A.B.C.D]]", | |
718e3744 | 8358 | NO_STR |
8359 | "IP Information\n" | |
8360 | "OSPF interface commands\n" | |
0d829fa7 | 8361 | "Time between HELLO packets\n" // ignored |
f9dfba8d | 8362 | "Seconds\n" |
0d829fa7 | 8363 | "Address of interface\n") |
718e3744 | 8364 | { |
d62a17ae | 8365 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8366 | int idx = 0; | |
8367 | struct in_addr addr; | |
8368 | struct ospf_if_params *params; | |
182d6bdc | 8369 | struct route_node *rn; |
df581cd3 | 8370 | |
d62a17ae | 8371 | params = IF_DEF_PARAMS(ifp); |
718e3744 | 8372 | |
d62a17ae | 8373 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { |
8374 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
8375 | vty_out(vty, | |
8376 | "Please specify interface address by A.B.C.D\n"); | |
8377 | return CMD_WARNING_CONFIG_FAILED; | |
8378 | } | |
718e3744 | 8379 | |
d62a17ae | 8380 | params = ospf_lookup_if_params(ifp, addr); |
8381 | if (params == NULL) | |
8382 | return CMD_SUCCESS; | |
8383 | } | |
718e3744 | 8384 | |
d62a17ae | 8385 | UNSET_IF_PARAM(params, v_hello); |
8386 | params->v_hello = OSPF_HELLO_INTERVAL_DEFAULT; | |
718e3744 | 8387 | |
182d6bdc K |
8388 | if (!params->is_v_wait_set) { |
8389 | UNSET_IF_PARAM(params, v_wait); | |
8390 | params->v_wait = OSPF_ROUTER_DEAD_INTERVAL_DEFAULT; | |
8391 | } | |
8392 | ||
8393 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { | |
8394 | struct ospf_interface *oi = rn->info; | |
8395 | ||
8396 | if (!oi) | |
8397 | continue; | |
8398 | ||
8399 | oi->type = IF_DEF_PARAMS(ifp)->type; | |
bc97889b | 8400 | oi->ptp_dmvpn = IF_DEF_PARAMS(ifp)->ptp_dmvpn; |
182d6bdc K |
8401 | |
8402 | if (oi->state > ISM_Down) { | |
8403 | OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceDown); | |
8404 | OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceUp); | |
8405 | } | |
8406 | } | |
8407 | ||
d62a17ae | 8408 | if (params != IF_DEF_PARAMS(ifp)) { |
8409 | ospf_free_if_params(ifp, addr); | |
8410 | ospf_if_update_params(ifp, addr); | |
8411 | } | |
718e3744 | 8412 | |
d62a17ae | 8413 | return CMD_SUCCESS; |
718e3744 | 8414 | } |
8415 | ||
0d829fa7 QY |
8416 | DEFUN_HIDDEN (no_ospf_hello_interval, |
8417 | no_ospf_hello_interval_cmd, | |
8418 | "no ospf hello-interval [(1-65535) [A.B.C.D]]", | |
8419 | NO_STR | |
8420 | "OSPF interface commands\n" | |
8421 | "Time between HELLO packets\n" // ignored | |
8422 | "Seconds\n" | |
8423 | "Address of interface\n") | |
8424 | { | |
d62a17ae | 8425 | return no_ip_ospf_hello_interval(self, vty, argc, argv); |
0d829fa7 | 8426 | } |
718e3744 | 8427 | |
bc97889b AL |
8428 | DEFUN(ip_ospf_network, ip_ospf_network_cmd, |
8429 | "ip ospf network <broadcast|non-broadcast|point-to-multipoint|point-to-point [dmvpn]>", | |
8430 | "IP Information\n" | |
8431 | "OSPF interface commands\n" | |
8432 | "Network type\n" | |
8433 | "Specify OSPF broadcast multi-access network\n" | |
8434 | "Specify OSPF NBMA network\n" | |
8435 | "Specify OSPF point-to-multipoint network\n" | |
8436 | "Specify OSPF point-to-point network\n" | |
8437 | "Specify OSPF point-to-point DMVPN network\n") | |
718e3744 | 8438 | { |
d62a17ae | 8439 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8440 | int idx = 0; | |
8441 | int old_type = IF_DEF_PARAMS(ifp)->type; | |
bc97889b | 8442 | uint8_t old_ptp_dmvpn = IF_DEF_PARAMS(ifp)->ptp_dmvpn; |
d62a17ae | 8443 | struct route_node *rn; |
718e3744 | 8444 | |
d62a17ae | 8445 | if (old_type == OSPF_IFTYPE_LOOPBACK) { |
8446 | vty_out(vty, | |
8447 | "This is a loopback interface. Can't set network type.\n"); | |
8448 | return CMD_WARNING_CONFIG_FAILED; | |
8449 | } | |
718e3744 | 8450 | |
bc97889b AL |
8451 | IF_DEF_PARAMS(ifp)->ptp_dmvpn = 0; |
8452 | ||
d62a17ae | 8453 | if (argv_find(argv, argc, "broadcast", &idx)) |
8454 | IF_DEF_PARAMS(ifp)->type = OSPF_IFTYPE_BROADCAST; | |
8455 | else if (argv_find(argv, argc, "non-broadcast", &idx)) | |
8456 | IF_DEF_PARAMS(ifp)->type = OSPF_IFTYPE_NBMA; | |
8457 | else if (argv_find(argv, argc, "point-to-multipoint", &idx)) | |
8458 | IF_DEF_PARAMS(ifp)->type = OSPF_IFTYPE_POINTOMULTIPOINT; | |
bc97889b | 8459 | else if (argv_find(argv, argc, "point-to-point", &idx)) { |
d62a17ae | 8460 | IF_DEF_PARAMS(ifp)->type = OSPF_IFTYPE_POINTOPOINT; |
bc97889b AL |
8461 | if (argv_find(argv, argc, "dmvpn", &idx)) |
8462 | IF_DEF_PARAMS(ifp)->ptp_dmvpn = 1; | |
8463 | } | |
718e3744 | 8464 | |
bc97889b AL |
8465 | if (IF_DEF_PARAMS(ifp)->type == old_type |
8466 | && IF_DEF_PARAMS(ifp)->ptp_dmvpn == old_ptp_dmvpn) | |
d62a17ae | 8467 | return CMD_SUCCESS; |
8468 | ||
8469 | SET_IF_PARAM(IF_DEF_PARAMS(ifp), type); | |
8470 | ||
8471 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { | |
8472 | struct ospf_interface *oi = rn->info; | |
8473 | ||
8474 | if (!oi) | |
8475 | continue; | |
8476 | ||
8477 | oi->type = IF_DEF_PARAMS(ifp)->type; | |
8478 | ||
8479 | if (oi->state > ISM_Down) { | |
8480 | OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceDown); | |
8481 | OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceUp); | |
8482 | } | |
7a7be519 | 8483 | } |
7a7be519 | 8484 | |
d62a17ae | 8485 | return CMD_SUCCESS; |
7a7be519 | 8486 | } |
8487 | ||
8488 | DEFUN_HIDDEN (ospf_network, | |
8489 | ospf_network_cmd, | |
e83a9414 | 8490 | "ospf network <broadcast|non-broadcast|point-to-multipoint|point-to-point>", |
7a7be519 | 8491 | "OSPF interface commands\n" |
8492 | "Network type\n" | |
8493 | "Specify OSPF broadcast multi-access network\n" | |
8494 | "Specify OSPF NBMA network\n" | |
8495 | "Specify OSPF point-to-multipoint network\n" | |
8496 | "Specify OSPF point-to-point network\n") | |
8497 | { | |
d62a17ae | 8498 | return ip_ospf_network(self, vty, argc, argv); |
7a7be519 | 8499 | } |
8500 | ||
8501 | DEFUN (no_ip_ospf_network, | |
8502 | no_ip_ospf_network_cmd, | |
8503 | "no ip ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]", | |
8504 | NO_STR | |
8505 | "IP Information\n" | |
8506 | "OSPF interface commands\n" | |
8507 | "Network type\n" | |
8508 | "Specify OSPF broadcast multi-access network\n" | |
8509 | "Specify OSPF NBMA network\n" | |
8510 | "Specify OSPF point-to-multipoint network\n" | |
8511 | "Specify OSPF point-to-point network\n") | |
22b27e95 | 8512 | { |
d62a17ae | 8513 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8514 | int old_type = IF_DEF_PARAMS(ifp)->type; | |
8515 | struct route_node *rn; | |
7a7be519 | 8516 | |
d62a17ae | 8517 | IF_DEF_PARAMS(ifp)->type = ospf_default_iftype(ifp); |
bc97889b | 8518 | IF_DEF_PARAMS(ifp)->ptp_dmvpn = 0; |
7a7be519 | 8519 | |
d62a17ae | 8520 | if (IF_DEF_PARAMS(ifp)->type == old_type) |
8521 | return CMD_SUCCESS; | |
7a7be519 | 8522 | |
d62a17ae | 8523 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { |
8524 | struct ospf_interface *oi = rn->info; | |
7a7be519 | 8525 | |
d62a17ae | 8526 | if (!oi) |
8527 | continue; | |
7a7be519 | 8528 | |
d62a17ae | 8529 | oi->type = IF_DEF_PARAMS(ifp)->type; |
7a7be519 | 8530 | |
d62a17ae | 8531 | if (oi->state > ISM_Down) { |
8532 | OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceDown); | |
8533 | OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceUp); | |
8534 | } | |
7a7be519 | 8535 | } |
7a7be519 | 8536 | |
d62a17ae | 8537 | return CMD_SUCCESS; |
7a7be519 | 8538 | } |
8539 | ||
0d829fa7 QY |
8540 | DEFUN_HIDDEN (no_ospf_network, |
8541 | no_ospf_network_cmd, | |
8542 | "no ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]", | |
8543 | NO_STR | |
8544 | "OSPF interface commands\n" | |
8545 | "Network type\n" | |
8546 | "Specify OSPF broadcast multi-access network\n" | |
8547 | "Specify OSPF NBMA network\n" | |
8548 | "Specify OSPF point-to-multipoint network\n" | |
8549 | "Specify OSPF point-to-point network\n") | |
8550 | { | |
d62a17ae | 8551 | return no_ip_ospf_network(self, vty, argc, argv); |
0d829fa7 QY |
8552 | } |
8553 | ||
7a7be519 | 8554 | DEFUN (ip_ospf_priority, |
537eae3f | 8555 | ip_ospf_priority_cmd, |
7a7be519 | 8556 | "ip ospf priority (0-255) [A.B.C.D]", |
8557 | "IP Information\n" | |
8558 | "OSPF interface commands\n" | |
8559 | "Router priority\n" | |
8560 | "Priority\n" | |
efd7904e | 8561 | "Address of interface\n") |
7a7be519 | 8562 | { |
d62a17ae | 8563 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8564 | int idx = 0; | |
8565 | long priority; | |
8566 | struct route_node *rn; | |
8567 | struct in_addr addr; | |
8568 | struct ospf_if_params *params; | |
8569 | params = IF_DEF_PARAMS(ifp); | |
8570 | ||
8571 | argv_find(argv, argc, "(0-255)", &idx); | |
8572 | priority = strtol(argv[idx]->arg, NULL, 10); | |
8573 | ||
8574 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
8575 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
8576 | vty_out(vty, | |
8577 | "Please specify interface address by A.B.C.D\n"); | |
8578 | return CMD_WARNING_CONFIG_FAILED; | |
8579 | } | |
7a7be519 | 8580 | |
d62a17ae | 8581 | params = ospf_get_if_params(ifp, addr); |
8582 | ospf_if_update_params(ifp, addr); | |
7a7be519 | 8583 | } |
8584 | ||
d62a17ae | 8585 | SET_IF_PARAM(params, priority); |
8586 | params->priority = priority; | |
7a7be519 | 8587 | |
d62a17ae | 8588 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { |
8589 | struct ospf_interface *oi = rn->info; | |
7a7be519 | 8590 | |
d62a17ae | 8591 | if (!oi) |
8592 | continue; | |
7a7be519 | 8593 | |
d62a17ae | 8594 | if (PRIORITY(oi) != OSPF_IF_PARAM(oi, priority)) { |
8595 | PRIORITY(oi) = OSPF_IF_PARAM(oi, priority); | |
8596 | OSPF_ISM_EVENT_SCHEDULE(oi, ISM_NeighborChange); | |
8597 | } | |
718e3744 | 8598 | } |
718e3744 | 8599 | |
d62a17ae | 8600 | return CMD_SUCCESS; |
718e3744 | 8601 | } |
8602 | ||
7a7be519 | 8603 | DEFUN_HIDDEN (ospf_priority, |
8604 | ospf_priority_cmd, | |
0d829fa7 | 8605 | "ospf priority (0-255) [A.B.C.D]", |
7a7be519 | 8606 | "OSPF interface commands\n" |
8607 | "Router priority\n" | |
3a2d747c | 8608 | "Priority\n" |
efd7904e | 8609 | "Address of interface\n") |
718e3744 | 8610 | { |
d62a17ae | 8611 | return ip_ospf_priority(self, vty, argc, argv); |
718e3744 | 8612 | } |
8613 | ||
718e3744 | 8614 | DEFUN (no_ip_ospf_priority, |
537eae3f | 8615 | no_ip_ospf_priority_cmd, |
7a7be519 | 8616 | "no ip ospf priority [(0-255) [A.B.C.D]]", |
718e3744 | 8617 | NO_STR |
8618 | "IP Information\n" | |
8619 | "OSPF interface commands\n" | |
0d829fa7 | 8620 | "Router priority\n" // ignored |
813d4307 | 8621 | "Priority\n" |
efd7904e | 8622 | "Address of interface\n") |
718e3744 | 8623 | { |
d62a17ae | 8624 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8625 | int idx = 0; | |
8626 | struct route_node *rn; | |
8627 | struct in_addr addr; | |
8628 | struct ospf_if_params *params; | |
8629 | ||
8630 | params = IF_DEF_PARAMS(ifp); | |
8631 | ||
8632 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
8633 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
8634 | vty_out(vty, | |
8635 | "Please specify interface address by A.B.C.D\n"); | |
8636 | return CMD_WARNING_CONFIG_FAILED; | |
8637 | } | |
8638 | ||
8639 | params = ospf_lookup_if_params(ifp, addr); | |
8640 | if (params == NULL) | |
8641 | return CMD_SUCCESS; | |
718e3744 | 8642 | } |
8643 | ||
d62a17ae | 8644 | UNSET_IF_PARAM(params, priority); |
8645 | params->priority = OSPF_ROUTER_PRIORITY_DEFAULT; | |
8646 | ||
8647 | if (params != IF_DEF_PARAMS(ifp)) { | |
8648 | ospf_free_if_params(ifp, addr); | |
8649 | ospf_if_update_params(ifp, addr); | |
718e3744 | 8650 | } |
d62a17ae | 8651 | |
8652 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { | |
8653 | struct ospf_interface *oi = rn->info; | |
8654 | ||
8655 | if (!oi) | |
8656 | continue; | |
8657 | ||
8658 | if (PRIORITY(oi) != OSPF_IF_PARAM(oi, priority)) { | |
8659 | PRIORITY(oi) = OSPF_IF_PARAM(oi, priority); | |
8660 | OSPF_ISM_EVENT_SCHEDULE(oi, ISM_NeighborChange); | |
8661 | } | |
8662 | } | |
8663 | ||
8664 | return CMD_SUCCESS; | |
718e3744 | 8665 | } |
8666 | ||
0d829fa7 | 8667 | DEFUN_HIDDEN (no_ospf_priority, |
537eae3f | 8668 | no_ospf_priority_cmd, |
0d829fa7 QY |
8669 | "no ospf priority [(0-255) [A.B.C.D]]", |
8670 | NO_STR | |
8671 | "OSPF interface commands\n" | |
8672 | "Router priority\n" | |
8673 | "Priority\n" | |
efd7904e | 8674 | "Address of interface\n") |
0d829fa7 | 8675 | { |
d62a17ae | 8676 | return no_ip_ospf_priority(self, vty, argc, argv); |
0d829fa7 | 8677 | } |
a1afa410 | 8678 | |
718e3744 | 8679 | DEFUN (ip_ospf_retransmit_interval, |
8680 | ip_ospf_retransmit_interval_addr_cmd, | |
d4badaf6 | 8681 | "ip ospf retransmit-interval (1-65535) [A.B.C.D]", |
718e3744 | 8682 | "IP Information\n" |
8683 | "OSPF interface commands\n" | |
8684 | "Time between retransmitting lost link state advertisements\n" | |
8685 | "Seconds\n" | |
efd7904e | 8686 | "Address of interface\n") |
718e3744 | 8687 | { |
d62a17ae | 8688 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8689 | int idx = 0; | |
d7c0a89a | 8690 | uint32_t seconds; |
d62a17ae | 8691 | struct in_addr addr; |
8692 | struct ospf_if_params *params; | |
8693 | params = IF_DEF_PARAMS(ifp); | |
8694 | ||
d4badaf6 | 8695 | argv_find(argv, argc, "(1-65535)", &idx); |
d62a17ae | 8696 | seconds = strtol(argv[idx]->arg, NULL, 10); |
8697 | ||
8698 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
8699 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
8700 | vty_out(vty, | |
8701 | "Please specify interface address by A.B.C.D\n"); | |
8702 | return CMD_WARNING_CONFIG_FAILED; | |
8703 | } | |
718e3744 | 8704 | |
d62a17ae | 8705 | params = ospf_get_if_params(ifp, addr); |
8706 | ospf_if_update_params(ifp, addr); | |
718e3744 | 8707 | } |
8708 | ||
d62a17ae | 8709 | SET_IF_PARAM(params, retransmit_interval); |
8710 | params->retransmit_interval = seconds; | |
718e3744 | 8711 | |
d62a17ae | 8712 | return CMD_SUCCESS; |
718e3744 | 8713 | } |
8714 | ||
7a7be519 | 8715 | DEFUN_HIDDEN (ospf_retransmit_interval, |
747e489c | 8716 | ospf_retransmit_interval_cmd, |
d4badaf6 | 8717 | "ospf retransmit-interval (1-65535) [A.B.C.D]", |
747e489c DW |
8718 | "OSPF interface commands\n" |
8719 | "Time between retransmitting lost link state advertisements\n" | |
3a2d747c | 8720 | "Seconds\n" |
efd7904e | 8721 | "Address of interface\n") |
7a7be519 | 8722 | { |
d62a17ae | 8723 | return ip_ospf_retransmit_interval(self, vty, argc, argv); |
7a7be519 | 8724 | } |
718e3744 | 8725 | |
8726 | DEFUN (no_ip_ospf_retransmit_interval, | |
8727 | no_ip_ospf_retransmit_interval_addr_cmd, | |
d4badaf6 | 8728 | "no ip ospf retransmit-interval [(1-65535)] [A.B.C.D]", |
718e3744 | 8729 | NO_STR |
8730 | "IP Information\n" | |
8731 | "OSPF interface commands\n" | |
3a2d747c QY |
8732 | "Time between retransmitting lost link state advertisements\n" |
8733 | "Seconds\n" | |
0d829fa7 | 8734 | "Address of interface\n") |
718e3744 | 8735 | { |
d62a17ae | 8736 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8737 | int idx = 0; | |
8738 | struct in_addr addr; | |
8739 | struct ospf_if_params *params; | |
47b91972 | 8740 | |
d62a17ae | 8741 | params = IF_DEF_PARAMS(ifp); |
718e3744 | 8742 | |
d62a17ae | 8743 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { |
8744 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
8745 | vty_out(vty, | |
8746 | "Please specify interface address by A.B.C.D\n"); | |
8747 | return CMD_WARNING_CONFIG_FAILED; | |
8748 | } | |
718e3744 | 8749 | |
d62a17ae | 8750 | params = ospf_lookup_if_params(ifp, addr); |
8751 | if (params == NULL) | |
8752 | return CMD_SUCCESS; | |
8753 | } | |
718e3744 | 8754 | |
d62a17ae | 8755 | UNSET_IF_PARAM(params, retransmit_interval); |
8756 | params->retransmit_interval = OSPF_RETRANSMIT_INTERVAL_DEFAULT; | |
718e3744 | 8757 | |
d62a17ae | 8758 | if (params != IF_DEF_PARAMS(ifp)) { |
8759 | ospf_free_if_params(ifp, addr); | |
8760 | ospf_if_update_params(ifp, addr); | |
8761 | } | |
718e3744 | 8762 | |
d62a17ae | 8763 | return CMD_SUCCESS; |
718e3744 | 8764 | } |
8765 | ||
0d829fa7 QY |
8766 | DEFUN_HIDDEN (no_ospf_retransmit_interval, |
8767 | no_ospf_retransmit_interval_cmd, | |
d4badaf6 | 8768 | "no ospf retransmit-interval [(1-65535)] [A.B.C.D]", |
0d829fa7 QY |
8769 | NO_STR |
8770 | "OSPF interface commands\n" | |
3a2d747c QY |
8771 | "Time between retransmitting lost link state advertisements\n" |
8772 | "Seconds\n" | |
8773 | "Address of interface\n") | |
0d829fa7 | 8774 | { |
d62a17ae | 8775 | return no_ip_ospf_retransmit_interval(self, vty, argc, argv); |
0d829fa7 | 8776 | } |
813d4307 | 8777 | |
718e3744 | 8778 | DEFUN (ip_ospf_transmit_delay, |
8779 | ip_ospf_transmit_delay_addr_cmd, | |
7a7be519 | 8780 | "ip ospf transmit-delay (1-65535) [A.B.C.D]", |
718e3744 | 8781 | "IP Information\n" |
8782 | "OSPF interface commands\n" | |
8783 | "Link state transmit delay\n" | |
8784 | "Seconds\n" | |
efd7904e | 8785 | "Address of interface\n") |
718e3744 | 8786 | { |
d62a17ae | 8787 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8788 | int idx = 0; | |
d7c0a89a | 8789 | uint32_t seconds; |
d62a17ae | 8790 | struct in_addr addr; |
8791 | struct ospf_if_params *params; | |
8792 | ||
8793 | params = IF_DEF_PARAMS(ifp); | |
8794 | argv_find(argv, argc, "(1-65535)", &idx); | |
8795 | seconds = strtol(argv[idx]->arg, NULL, 10); | |
8796 | ||
8797 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
8798 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
8799 | vty_out(vty, | |
8800 | "Please specify interface address by A.B.C.D\n"); | |
8801 | return CMD_WARNING_CONFIG_FAILED; | |
8802 | } | |
718e3744 | 8803 | |
d62a17ae | 8804 | params = ospf_get_if_params(ifp, addr); |
8805 | ospf_if_update_params(ifp, addr); | |
718e3744 | 8806 | } |
8807 | ||
d62a17ae | 8808 | SET_IF_PARAM(params, transmit_delay); |
8809 | params->transmit_delay = seconds; | |
718e3744 | 8810 | |
d62a17ae | 8811 | return CMD_SUCCESS; |
718e3744 | 8812 | } |
8813 | ||
7a7be519 | 8814 | DEFUN_HIDDEN (ospf_transmit_delay, |
747e489c | 8815 | ospf_transmit_delay_cmd, |
0d829fa7 | 8816 | "ospf transmit-delay (1-65535) [A.B.C.D]", |
747e489c DW |
8817 | "OSPF interface commands\n" |
8818 | "Link state transmit delay\n" | |
3a2d747c | 8819 | "Seconds\n" |
efd7904e | 8820 | "Address of interface\n") |
7a7be519 | 8821 | { |
d62a17ae | 8822 | return ip_ospf_transmit_delay(self, vty, argc, argv); |
7a7be519 | 8823 | } |
718e3744 | 8824 | |
8825 | DEFUN (no_ip_ospf_transmit_delay, | |
8826 | no_ip_ospf_transmit_delay_addr_cmd, | |
0d829fa7 | 8827 | "no ip ospf transmit-delay [(1-65535)] [A.B.C.D]", |
718e3744 | 8828 | NO_STR |
8829 | "IP Information\n" | |
8830 | "OSPF interface commands\n" | |
8831 | "Link state transmit delay\n" | |
efd7904e RW |
8832 | "Seconds\n" |
8833 | "Address of interface\n") | |
718e3744 | 8834 | { |
d62a17ae | 8835 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8836 | int idx = 0; | |
8837 | struct in_addr addr; | |
8838 | struct ospf_if_params *params; | |
718e3744 | 8839 | |
d62a17ae | 8840 | params = IF_DEF_PARAMS(ifp); |
718e3744 | 8841 | |
d62a17ae | 8842 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { |
8843 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
8844 | vty_out(vty, | |
8845 | "Please specify interface address by A.B.C.D\n"); | |
8846 | return CMD_WARNING_CONFIG_FAILED; | |
8847 | } | |
718e3744 | 8848 | |
d62a17ae | 8849 | params = ospf_lookup_if_params(ifp, addr); |
8850 | if (params == NULL) | |
8851 | return CMD_SUCCESS; | |
8852 | } | |
718e3744 | 8853 | |
d62a17ae | 8854 | UNSET_IF_PARAM(params, transmit_delay); |
8855 | params->transmit_delay = OSPF_TRANSMIT_DELAY_DEFAULT; | |
718e3744 | 8856 | |
d62a17ae | 8857 | if (params != IF_DEF_PARAMS(ifp)) { |
8858 | ospf_free_if_params(ifp, addr); | |
8859 | ospf_if_update_params(ifp, addr); | |
8860 | } | |
8861 | ||
8862 | return CMD_SUCCESS; | |
718e3744 | 8863 | } |
8864 | ||
813d4307 | 8865 | |
0d829fa7 QY |
8866 | DEFUN_HIDDEN (no_ospf_transmit_delay, |
8867 | no_ospf_transmit_delay_cmd, | |
32573073 | 8868 | "no ospf transmit-delay [(1-65535) [A.B.C.D]]", |
0d829fa7 QY |
8869 | NO_STR |
8870 | "OSPF interface commands\n" | |
32573073 QY |
8871 | "Link state transmit delay\n" |
8872 | "Seconds\n" | |
efd7904e | 8873 | "Address of interface\n") |
813d4307 | 8874 | { |
d62a17ae | 8875 | return no_ip_ospf_transmit_delay(self, vty, argc, argv); |
813d4307 DW |
8876 | } |
8877 | ||
e723861d DS |
8878 | DEFUN (ip_ospf_area, |
8879 | ip_ospf_area_cmd, | |
52c62ab8 | 8880 | "ip ospf [(1-65535)] area <A.B.C.D|(0-4294967295)> [A.B.C.D]", |
e723861d DS |
8881 | "IP Information\n" |
8882 | "OSPF interface commands\n" | |
7a7be519 | 8883 | "Instance ID\n" |
e723861d DS |
8884 | "Enable OSPF on this interface\n" |
8885 | "OSPF area ID in IP address format\n" | |
52c62ab8 JAG |
8886 | "OSPF area ID as a decimal value\n" |
8887 | "Address of interface\n") | |
e723861d | 8888 | { |
d62a17ae | 8889 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8890 | int idx = 0; | |
8891 | int format, ret; | |
8892 | struct in_addr area_id; | |
8893 | struct in_addr addr; | |
35955c14 | 8894 | struct ospf_if_params *params = NULL; |
d62a17ae | 8895 | struct route_node *rn; |
b5a8894d | 8896 | struct ospf *ospf = NULL; |
d7c0a89a | 8897 | unsigned short instance = 0; |
d62a17ae | 8898 | char *areaid; |
15bf52d3 | 8899 | uint32_t count = 0; |
d62a17ae | 8900 | |
8901 | if (argv_find(argv, argc, "(1-65535)", &idx)) | |
8902 | instance = strtol(argv[idx]->arg, NULL, 10); | |
8903 | ||
8904 | argv_find(argv, argc, "area", &idx); | |
8905 | areaid = argv[idx + 1]->arg; | |
8906 | ||
b56114aa | 8907 | if (!instance) |
a36898e7 | 8908 | ospf = ospf_lookup_by_vrf_id(ifp->vrf_id); |
b5a8894d CS |
8909 | else |
8910 | ospf = ospf_lookup_instance(instance); | |
8911 | ||
409f98ab | 8912 | if (instance && instance != ospf_instance) { |
2b0a32da DS |
8913 | /* |
8914 | * At this point we know we have received | |
8915 | * an instance and there is no ospf instance | |
8916 | * associated with it. This means we are | |
8917 | * in a situation where we have an | |
8918 | * ospf command that is setup for a different | |
8919 | * process(instance). We need to safely | |
8920 | * remove the command from ourselves and | |
8921 | * allow the other instance(process) handle | |
8922 | * the configuration command. | |
8923 | */ | |
15bf52d3 IR |
8924 | count = 0; |
8925 | ||
d62a17ae | 8926 | params = IF_DEF_PARAMS(ifp); |
8927 | if (OSPF_IF_PARAM_CONFIGURED(params, if_area)) { | |
8928 | UNSET_IF_PARAM(params, if_area); | |
15bf52d3 IR |
8929 | count++; |
8930 | } | |
8931 | ||
8932 | for (rn = route_top(IF_OIFS_PARAMS(ifp)); rn; rn = route_next(rn)) | |
8933 | if ((params = rn->info) && OSPF_IF_PARAM_CONFIGURED(params, if_area)) { | |
8934 | UNSET_IF_PARAM(params, if_area); | |
8935 | count++; | |
8936 | } | |
8937 | ||
8938 | if (count > 0) { | |
8939 | ospf = ospf_lookup_by_vrf_id(ifp->vrf_id); | |
cbf32f74 | 8940 | if (ospf) |
2b0a32da | 8941 | ospf_interface_area_unset(ospf, ifp); |
d62a17ae | 8942 | } |
15bf52d3 | 8943 | |
ac28e4ec | 8944 | return CMD_NOT_MY_INSTANCE; |
d62a17ae | 8945 | } |
e723861d | 8946 | |
d62a17ae | 8947 | ret = str2area_id(areaid, &area_id, &format); |
8948 | if (ret < 0) { | |
8949 | vty_out(vty, "Please specify area by A.B.C.D|<0-4294967295>\n"); | |
8950 | return CMD_WARNING_CONFIG_FAILED; | |
8951 | } | |
8952 | if (memcmp(ifp->name, "VLINK", 5) == 0) { | |
8953 | vty_out(vty, "Cannot enable OSPF on a virtual link.\n"); | |
8954 | return CMD_WARNING_CONFIG_FAILED; | |
8955 | } | |
8956 | ||
eb364867 IR |
8957 | if (ospf) { |
8958 | for (rn = route_top(ospf->networks); rn; rn = route_next(rn)) { | |
8959 | if (rn->info != NULL) { | |
8960 | vty_out(vty, | |
8961 | "Please remove all network commands first.\n"); | |
8962 | return CMD_WARNING_CONFIG_FAILED; | |
8963 | } | |
8964 | } | |
8965 | } | |
8966 | ||
d62a17ae | 8967 | params = IF_DEF_PARAMS(ifp); |
8968 | if (OSPF_IF_PARAM_CONFIGURED(params, if_area) | |
8969 | && !IPV4_ADDR_SAME(¶ms->if_area, &area_id)) { | |
8970 | vty_out(vty, | |
8971 | "Must remove previous area config before changing ospf area \n"); | |
8972 | return CMD_WARNING_CONFIG_FAILED; | |
8973 | } | |
8974 | ||
8975 | // Check if we have an address arg and proccess it | |
8976 | if (argc == idx + 3) { | |
cc9b06ad | 8977 | if (!inet_aton(argv[idx + 2]->arg, &addr)) { |
996c9314 LB |
8978 | vty_out(vty, |
8979 | "Please specify Intf Address by A.B.C.D\n"); | |
cc9b06ad DS |
8980 | return CMD_WARNING_CONFIG_FAILED; |
8981 | } | |
d62a17ae | 8982 | // update/create address-level params |
8983 | params = ospf_get_if_params((ifp), (addr)); | |
8984 | if (OSPF_IF_PARAM_CONFIGURED(params, if_area)) { | |
a900cece IR |
8985 | if (!IPV4_ADDR_SAME(¶ms->if_area, &area_id)) { |
8986 | vty_out(vty, | |
8987 | "Must remove previous area/address config before changing ospf area\n"); | |
8988 | return CMD_WARNING_CONFIG_FAILED; | |
8989 | } else | |
8990 | return CMD_SUCCESS; | |
d62a17ae | 8991 | } |
8992 | ospf_if_update_params((ifp), (addr)); | |
8993 | } | |
8994 | ||
d62a17ae | 8995 | /* enable ospf on this interface with area_id */ |
35955c14 CS |
8996 | if (params) { |
8997 | SET_IF_PARAM(params, if_area); | |
8998 | params->if_area = area_id; | |
8999 | params->if_area_id_fmt = format; | |
9000 | } | |
aed7cc62 | 9001 | |
cbf32f74 | 9002 | if (ospf) |
aed7cc62 | 9003 | ospf_interface_area_set(ospf, ifp); |
d62a17ae | 9004 | |
9005 | return CMD_SUCCESS; | |
e723861d DS |
9006 | } |
9007 | ||
9008 | DEFUN (no_ip_ospf_area, | |
9009 | no_ip_ospf_area_cmd, | |
52c62ab8 | 9010 | "no ip ospf [(1-65535)] area [<A.B.C.D|(0-4294967295)> [A.B.C.D]]", |
e723861d DS |
9011 | NO_STR |
9012 | "IP Information\n" | |
9013 | "OSPF interface commands\n" | |
3a2d747c | 9014 | "Instance ID\n" |
7a7be519 | 9015 | "Disable OSPF on this interface\n" |
9016 | "OSPF area ID in IP address format\n" | |
52c62ab8 JAG |
9017 | "OSPF area ID as a decimal value\n" |
9018 | "Address of interface\n") | |
e723861d | 9019 | { |
d62a17ae | 9020 | VTY_DECLVAR_CONTEXT(interface, ifp); |
9021 | int idx = 0; | |
9022 | struct ospf *ospf; | |
9023 | struct ospf_if_params *params; | |
d7c0a89a | 9024 | unsigned short instance = 0; |
d62a17ae | 9025 | struct in_addr addr; |
58e5d140 | 9026 | struct in_addr area_id; |
d62a17ae | 9027 | |
9028 | if (argv_find(argv, argc, "(1-65535)", &idx)) | |
9029 | instance = strtol(argv[idx]->arg, NULL, 10); | |
9030 | ||
b56114aa | 9031 | if (!instance) |
a36898e7 | 9032 | ospf = ospf_lookup_by_vrf_id(ifp->vrf_id); |
b5a8894d CS |
9033 | else |
9034 | ospf = ospf_lookup_instance(instance); | |
9035 | ||
409f98ab | 9036 | if (instance && instance != ospf_instance) |
ac28e4ec | 9037 | return CMD_NOT_MY_INSTANCE; |
d62a17ae | 9038 | |
9039 | argv_find(argv, argc, "area", &idx); | |
9040 | ||
9041 | // Check if we have an address arg and proccess it | |
9042 | if (argc == idx + 3) { | |
cc9b06ad | 9043 | if (!inet_aton(argv[idx + 2]->arg, &addr)) { |
996c9314 LB |
9044 | vty_out(vty, |
9045 | "Please specify Intf Address by A.B.C.D\n"); | |
cc9b06ad DS |
9046 | return CMD_WARNING_CONFIG_FAILED; |
9047 | } | |
d62a17ae | 9048 | params = ospf_lookup_if_params(ifp, addr); |
9049 | if ((params) == NULL) | |
9050 | return CMD_SUCCESS; | |
9051 | } else | |
9052 | params = IF_DEF_PARAMS(ifp); | |
9053 | ||
58e5d140 | 9054 | area_id = params->if_area; |
d62a17ae | 9055 | if (!OSPF_IF_PARAM_CONFIGURED(params, if_area)) { |
9056 | vty_out(vty, | |
9057 | "Can't find specified interface area configuration.\n"); | |
9058 | return CMD_WARNING_CONFIG_FAILED; | |
9059 | } | |
813d4307 | 9060 | |
d62a17ae | 9061 | UNSET_IF_PARAM(params, if_area); |
9062 | if (params != IF_DEF_PARAMS((ifp))) { | |
9063 | ospf_free_if_params((ifp), (addr)); | |
9064 | ospf_if_update_params((ifp), (addr)); | |
9065 | } | |
9066 | ||
e4129293 IR |
9067 | if (ospf) { |
9068 | ospf_interface_area_unset(ospf, ifp); | |
58e5d140 | 9069 | ospf_area_check_free(ospf, area_id); |
e4129293 IR |
9070 | } |
9071 | ||
d62a17ae | 9072 | return CMD_SUCCESS; |
813d4307 DW |
9073 | } |
9074 | ||
3eec4ee0 IR |
9075 | DEFUN (ip_ospf_passive, |
9076 | ip_ospf_passive_cmd, | |
9077 | "ip ospf passive [A.B.C.D]", | |
9078 | "IP Information\n" | |
9079 | "OSPF interface commands\n" | |
9080 | "Suppress routing updates on an interface\n" | |
9081 | "Address of interface\n") | |
9082 | { | |
9083 | VTY_DECLVAR_CONTEXT(interface, ifp); | |
9084 | int idx_ipv4 = 3; | |
9085 | struct in_addr addr; | |
9086 | struct ospf_if_params *params; | |
9087 | int ret; | |
9088 | ||
9089 | if (argc == 4) { | |
9090 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
9091 | if (!ret) { | |
9092 | vty_out(vty, | |
9093 | "Please specify interface address by A.B.C.D\n"); | |
9094 | return CMD_WARNING_CONFIG_FAILED; | |
9095 | } | |
9096 | params = ospf_get_if_params(ifp, addr); | |
9097 | ospf_if_update_params(ifp, addr); | |
9098 | } else { | |
9099 | params = IF_DEF_PARAMS(ifp); | |
9100 | } | |
9101 | ||
9102 | params->passive_interface = OSPF_IF_PASSIVE; | |
9103 | SET_IF_PARAM(params, passive_interface); | |
9104 | ||
9105 | ospf_passive_interface_update(ifp); | |
9106 | ||
9107 | return CMD_SUCCESS; | |
9108 | } | |
9109 | ||
9110 | DEFUN (no_ip_ospf_passive, | |
9111 | no_ip_ospf_passive_cmd, | |
9112 | "no ip ospf passive [A.B.C.D]", | |
9113 | NO_STR | |
9114 | "IP Information\n" | |
9115 | "OSPF interface commands\n" | |
9116 | "Enable routing updates on an interface\n" | |
9117 | "Address of interface\n") | |
9118 | { | |
9119 | VTY_DECLVAR_CONTEXT(interface, ifp); | |
9120 | int idx_ipv4 = 4; | |
9121 | struct in_addr addr; | |
9122 | struct ospf_if_params *params; | |
9123 | int ret; | |
9124 | ||
9125 | if (argc == 5) { | |
9126 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
9127 | if (!ret) { | |
9128 | vty_out(vty, | |
9129 | "Please specify interface address by A.B.C.D\n"); | |
9130 | return CMD_WARNING_CONFIG_FAILED; | |
9131 | } | |
9132 | params = ospf_lookup_if_params(ifp, addr); | |
9133 | if (params == NULL) | |
9134 | return CMD_SUCCESS; | |
9135 | } else { | |
9136 | params = IF_DEF_PARAMS(ifp); | |
9137 | } | |
9138 | ||
9139 | params->passive_interface = OSPF_IF_ACTIVE; | |
9140 | UNSET_IF_PARAM(params, passive_interface); | |
9141 | if (params != IF_DEF_PARAMS(ifp)) { | |
9142 | ospf_free_if_params(ifp, addr); | |
9143 | ospf_if_update_params(ifp, addr); | |
9144 | } | |
9145 | ||
9146 | ospf_passive_interface_update(ifp); | |
9147 | ||
9148 | return CMD_SUCCESS; | |
9149 | } | |
9150 | ||
6f2a6703 CF |
9151 | DEFUN (ospf_redistribute_source, |
9152 | ospf_redistribute_source_cmd, | |
ea38ced1 | 9153 | "redistribute " FRR_REDIST_STR_OSPFD " [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]", |
d1c65c21 | 9154 | REDIST_STR |
ab0181ee | 9155 | FRR_REDIST_HELP_STR_OSPFD |
718e3744 | 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" |
718e3744 | 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_protocol = 1; |
9165 | int source; | |
9166 | int type = -1; | |
9167 | int metric = -1; | |
9168 | struct ospf_redist *red; | |
9169 | int idx = 0; | |
7bced643 | 9170 | bool update = false; |
6f2a6703 | 9171 | |
d62a17ae | 9172 | /* Get distribute source. */ |
9173 | source = proto_redistnum(AFI_IP, argv[idx_protocol]->text); | |
9174 | if (source < 0) | |
9175 | return CMD_WARNING_CONFIG_FAILED; | |
9176 | ||
d62a17ae | 9177 | /* Get metric value. */ |
9178 | if (argv_find(argv, argc, "(0-16777214)", &idx)) { | |
9179 | if (!str2metric(argv[idx]->arg, &metric)) | |
9180 | return CMD_WARNING_CONFIG_FAILED; | |
9181 | } | |
951da435 | 9182 | idx = 1; |
d62a17ae | 9183 | /* Get metric type. */ |
ea38ced1 | 9184 | if (argv_find(argv, argc, "(1-2)", &idx)) { |
d62a17ae | 9185 | if (!str2metric_type(argv[idx]->arg, &type)) |
9186 | return CMD_WARNING_CONFIG_FAILED; | |
9187 | } | |
951da435 | 9188 | idx = 1; |
7bced643 IR |
9189 | |
9190 | red = ospf_redist_lookup(ospf, source, 0); | |
9191 | if (!red) | |
9192 | red = ospf_redist_add(ospf, source, 0); | |
9193 | else | |
9194 | update = true; | |
9195 | ||
d62a17ae | 9196 | /* Get route-map */ |
ea38ced1 | 9197 | if (argv_find(argv, argc, "WORD", &idx)) { |
d62a17ae | 9198 | ospf_routemap_set(red, argv[idx]->arg); |
9199 | } else | |
9200 | ospf_routemap_unset(red); | |
7c8ff89e | 9201 | |
7bced643 IR |
9202 | if (update) |
9203 | return ospf_redistribute_update(ospf, red, source, 0, type, | |
9204 | metric); | |
9205 | else | |
9206 | return ospf_redistribute_set(ospf, red, source, 0, type, | |
9207 | metric); | |
718e3744 | 9208 | } |
9209 | ||
718e3744 | 9210 | DEFUN (no_ospf_redistribute_source, |
9211 | no_ospf_redistribute_source_cmd, | |
ea38ced1 | 9212 | "no redistribute " FRR_REDIST_STR_OSPFD " [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]", |
718e3744 | 9213 | NO_STR |
d1c65c21 | 9214 | REDIST_STR |
ab0181ee | 9215 | FRR_REDIST_HELP_STR_OSPFD |
813d4307 DW |
9216 | "Metric for redistributed routes\n" |
9217 | "OSPF default metric\n" | |
9218 | "OSPF exterior metric type for redistributed routes\n" | |
7111c1a0 | 9219 | "Set OSPF External Type 1/2 metrics\n" |
813d4307 DW |
9220 | "Route map reference\n" |
9221 | "Pointer to route-map entries\n") | |
718e3744 | 9222 | { |
a3d826f0 | 9223 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 9224 | int idx_protocol = 2; |
9225 | int source; | |
9226 | struct ospf_redist *red; | |
718e3744 | 9227 | |
d62a17ae | 9228 | source = proto_redistnum(AFI_IP, argv[idx_protocol]->text); |
9229 | if (source < 0) | |
9230 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 9231 | |
d62a17ae | 9232 | red = ospf_redist_lookup(ospf, source, 0); |
9233 | if (!red) | |
9234 | return CMD_SUCCESS; | |
7c8ff89e | 9235 | |
d62a17ae | 9236 | ospf_routemap_unset(red); |
766b826f DA |
9237 | ospf_redist_del(ospf, source, 0); |
9238 | ||
d62a17ae | 9239 | return ospf_redistribute_unset(ospf, source, 0); |
7c8ff89e DS |
9240 | } |
9241 | ||
9242 | DEFUN (ospf_redistribute_instance_source, | |
9243 | ospf_redistribute_instance_source_cmd, | |
1a5ce38b | 9244 | "redistribute <ospf|table> (1-65535) [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]", |
7c8ff89e DS |
9245 | REDIST_STR |
9246 | "Open Shortest Path First\n" | |
2d627ff5 DS |
9247 | "Non-main Kernel Routing Table\n" |
9248 | "Instance ID/Table ID\n" | |
7c8ff89e DS |
9249 | "Metric for redistributed routes\n" |
9250 | "OSPF default metric\n" | |
9251 | "OSPF exterior metric type for redistributed routes\n" | |
7111c1a0 | 9252 | "Set OSPF External Type 1/2 metrics\n" |
7c8ff89e DS |
9253 | "Route map reference\n" |
9254 | "Pointer to route-map entries\n") | |
9255 | { | |
a3d826f0 | 9256 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 9257 | int idx_ospf_table = 1; |
9258 | int idx_number = 2; | |
9259 | int idx = 3; | |
9260 | int source; | |
9261 | int type = -1; | |
9262 | int metric = -1; | |
d7c0a89a | 9263 | unsigned short instance; |
d62a17ae | 9264 | struct ospf_redist *red; |
7bced643 | 9265 | bool update = false; |
7c8ff89e | 9266 | |
d62a17ae | 9267 | source = proto_redistnum(AFI_IP, argv[idx_ospf_table]->text); |
2d627ff5 | 9268 | |
13f0e434 | 9269 | if (source < 0) { |
9270 | vty_out(vty, "Unknown instance redistribution\n"); | |
9271 | return CMD_WARNING_CONFIG_FAILED; | |
9272 | } | |
9273 | ||
d62a17ae | 9274 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
7c8ff89e | 9275 | |
d62a17ae | 9276 | if ((source == ZEBRA_ROUTE_OSPF) && !ospf->instance) { |
9277 | vty_out(vty, | |
9278 | "Instance redistribution in non-instanced OSPF not allowed\n"); | |
9279 | return CMD_WARNING_CONFIG_FAILED; | |
9280 | } | |
7c8ff89e | 9281 | |
d62a17ae | 9282 | if ((source == ZEBRA_ROUTE_OSPF) && (ospf->instance == instance)) { |
9283 | vty_out(vty, "Same instance OSPF redistribution not allowed\n"); | |
9284 | return CMD_WARNING_CONFIG_FAILED; | |
9285 | } | |
7c8ff89e | 9286 | |
d62a17ae | 9287 | /* Get metric value. */ |
9288 | if (argv_find(argv, argc, "metric", &idx)) | |
9289 | if (!str2metric(argv[idx + 1]->arg, &metric)) | |
9290 | return CMD_WARNING_CONFIG_FAILED; | |
7c8ff89e | 9291 | |
d62a17ae | 9292 | idx = 3; |
9293 | /* Get metric type. */ | |
9294 | if (argv_find(argv, argc, "metric-type", &idx)) | |
9295 | if (!str2metric_type(argv[idx + 1]->arg, &type)) | |
9296 | return CMD_WARNING_CONFIG_FAILED; | |
7c8ff89e | 9297 | |
7bced643 IR |
9298 | red = ospf_redist_lookup(ospf, source, instance); |
9299 | if (!red) | |
9300 | red = ospf_redist_add(ospf, source, instance); | |
9301 | else | |
9302 | update = true; | |
7a7be519 | 9303 | |
d62a17ae | 9304 | idx = 3; |
9305 | if (argv_find(argv, argc, "route-map", &idx)) | |
9306 | ospf_routemap_set(red, argv[idx + 1]->arg); | |
9307 | else | |
9308 | ospf_routemap_unset(red); | |
7c8ff89e | 9309 | |
7bced643 IR |
9310 | if (update) |
9311 | return ospf_redistribute_update(ospf, red, source, instance, | |
9312 | type, metric); | |
9313 | else | |
9314 | return ospf_redistribute_set(ospf, red, source, instance, type, | |
9315 | metric); | |
7c8ff89e DS |
9316 | } |
9317 | ||
9318 | DEFUN (no_ospf_redistribute_instance_source, | |
9319 | no_ospf_redistribute_instance_source_cmd, | |
1a5ce38b | 9320 | "no redistribute <ospf|table> (1-65535) [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]", |
7c8ff89e DS |
9321 | NO_STR |
9322 | REDIST_STR | |
9323 | "Open Shortest Path First\n" | |
2d627ff5 DS |
9324 | "Non-main Kernel Routing Table\n" |
9325 | "Instance ID/Table Id\n" | |
7c8ff89e DS |
9326 | "Metric for redistributed routes\n" |
9327 | "OSPF default metric\n" | |
9328 | "OSPF exterior metric type for redistributed routes\n" | |
7111c1a0 | 9329 | "Set OSPF External Type 1/2 metrics\n" |
7c8ff89e DS |
9330 | "Route map reference\n" |
9331 | "Pointer to route-map entries\n") | |
9332 | { | |
a3d826f0 | 9333 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 9334 | int idx_ospf_table = 2; |
9335 | int idx_number = 3; | |
d7c0a89a | 9336 | unsigned int instance; |
d62a17ae | 9337 | struct ospf_redist *red; |
9338 | int source; | |
9339 | ||
9340 | if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0) | |
9341 | source = ZEBRA_ROUTE_OSPF; | |
9342 | else | |
9343 | source = ZEBRA_ROUTE_TABLE; | |
9344 | ||
9345 | instance = strtoul(argv[idx_number]->arg, NULL, 10); | |
7c8ff89e | 9346 | |
d62a17ae | 9347 | if ((source == ZEBRA_ROUTE_OSPF) && !ospf->instance) { |
9348 | vty_out(vty, | |
9349 | "Instance redistribution in non-instanced OSPF not allowed\n"); | |
9350 | return CMD_WARNING_CONFIG_FAILED; | |
9351 | } | |
9352 | ||
9353 | if ((source == ZEBRA_ROUTE_OSPF) && (ospf->instance == instance)) { | |
9354 | vty_out(vty, "Same instance OSPF redistribution not allowed\n"); | |
9355 | return CMD_WARNING_CONFIG_FAILED; | |
9356 | } | |
9357 | ||
9358 | red = ospf_redist_lookup(ospf, source, instance); | |
9359 | if (!red) | |
9360 | return CMD_SUCCESS; | |
9361 | ||
9362 | ospf_routemap_unset(red); | |
766b826f DA |
9363 | ospf_redist_del(ospf, source, instance); |
9364 | ||
d62a17ae | 9365 | return ospf_redistribute_unset(ospf, source, instance); |
718e3744 | 9366 | } |
9367 | ||
9368 | DEFUN (ospf_distribute_list_out, | |
9369 | ospf_distribute_list_out_cmd, | |
40d1cbfb | 9370 | "distribute-list WORD out " FRR_REDIST_STR_OSPFD, |
718e3744 | 9371 | "Filter networks in routing updates\n" |
6f2a6703 CF |
9372 | "Access-list name\n" |
9373 | OUT_STR | |
ab0181ee | 9374 | FRR_REDIST_HELP_STR_OSPFD) |
718e3744 | 9375 | { |
a3d826f0 | 9376 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 9377 | int idx_word = 1; |
9378 | int source; | |
718e3744 | 9379 | |
d62a17ae | 9380 | char *proto = argv[argc - 1]->text; |
6d681bd8 | 9381 | |
d62a17ae | 9382 | /* Get distribute source. */ |
9383 | source = proto_redistnum(AFI_IP, proto); | |
9384 | if (source < 0) | |
9385 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 9386 | |
d62a17ae | 9387 | return ospf_distribute_list_out_set(ospf, source, argv[idx_word]->arg); |
718e3744 | 9388 | } |
9389 | ||
6f2a6703 CF |
9390 | DEFUN (no_ospf_distribute_list_out, |
9391 | no_ospf_distribute_list_out_cmd, | |
40d1cbfb | 9392 | "no distribute-list WORD out " FRR_REDIST_STR_OSPFD, |
6f2a6703 CF |
9393 | NO_STR |
9394 | "Filter networks in routing updates\n" | |
9395 | "Access-list name\n" | |
9396 | OUT_STR | |
ab0181ee | 9397 | FRR_REDIST_HELP_STR_OSPFD) |
718e3744 | 9398 | { |
a3d826f0 | 9399 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 9400 | int idx_word = 2; |
9401 | int source; | |
020709f9 | 9402 | |
d62a17ae | 9403 | char *proto = argv[argc - 1]->text; |
9404 | source = proto_redistnum(AFI_IP, proto); | |
9405 | if (source < 0) | |
9406 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 9407 | |
d62a17ae | 9408 | return ospf_distribute_list_out_unset(ospf, source, |
9409 | argv[idx_word]->arg); | |
718e3744 | 9410 | } |
9411 | ||
6f2a6703 CF |
9412 | /* Default information originate. */ |
9413 | DEFUN (ospf_default_information_originate, | |
9414 | ospf_default_information_originate_cmd, | |
ea38ced1 | 9415 | "default-information originate [{always|metric (0-16777214)|metric-type (1-2)|route-map WORD}]", |
718e3744 | 9416 | "Control distribution of default information\n" |
9417 | "Distribute a default route\n" | |
9418 | "Always advertise default route\n" | |
6f2a6703 CF |
9419 | "OSPF default metric\n" |
9420 | "OSPF metric\n" | |
718e3744 | 9421 | "OSPF metric type for default routes\n" |
7111c1a0 | 9422 | "Set OSPF External Type 1/2 metrics\n" |
718e3744 | 9423 | "Route map reference\n" |
9424 | "Pointer to route-map entries\n") | |
9425 | { | |
a3d826f0 | 9426 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 9427 | int default_originate = DEFAULT_ORIGINATE_ZEBRA; |
9428 | int type = -1; | |
9429 | int metric = -1; | |
9430 | struct ospf_redist *red; | |
9431 | int idx = 0; | |
1fb93326 | 9432 | int cur_originate = ospf->default_originate; |
9433 | int sameRtmap = 0; | |
9434 | char *rtmap = NULL; | |
d62a17ae | 9435 | |
9436 | red = ospf_redist_add(ospf, DEFAULT_ROUTE, 0); | |
9437 | ||
9438 | /* Check whether "always" was specified */ | |
9439 | if (argv_find(argv, argc, "always", &idx)) | |
9440 | default_originate = DEFAULT_ORIGINATE_ALWAYS; | |
951da435 | 9441 | idx = 1; |
d62a17ae | 9442 | /* Get metric value */ |
ea38ced1 | 9443 | if (argv_find(argv, argc, "(0-16777214)", &idx)) { |
d62a17ae | 9444 | if (!str2metric(argv[idx]->arg, &metric)) |
9445 | return CMD_WARNING_CONFIG_FAILED; | |
9446 | } | |
951da435 | 9447 | idx = 1; |
d62a17ae | 9448 | /* Get metric type. */ |
ea38ced1 | 9449 | if (argv_find(argv, argc, "(1-2)", &idx)) { |
d62a17ae | 9450 | if (!str2metric_type(argv[idx]->arg, &type)) |
9451 | return CMD_WARNING_CONFIG_FAILED; | |
9452 | } | |
951da435 | 9453 | idx = 1; |
d62a17ae | 9454 | /* Get route-map */ |
ea38ced1 | 9455 | if (argv_find(argv, argc, "WORD", &idx)) |
1fb93326 | 9456 | rtmap = argv[idx]->arg; |
9457 | ||
9458 | /* To check ,if user is providing same route map */ | |
9459 | if ((rtmap == ROUTEMAP_NAME(red)) || | |
9460 | (rtmap && ROUTEMAP_NAME(red) | |
9461 | && (strcmp(rtmap, ROUTEMAP_NAME(red)) == 0))) | |
9462 | sameRtmap = 1; | |
9463 | ||
9464 | /* Don't allow if the same lsa is aleardy originated. */ | |
9465 | if ((sameRtmap) | |
9466 | && (red->dmetric.type == type) | |
9467 | && (red->dmetric.value == metric) | |
9468 | && (cur_originate == default_originate)) | |
9469 | return CMD_SUCCESS; | |
9470 | ||
9471 | /* Updating Metric details */ | |
9472 | red->dmetric.type = type; | |
9473 | red->dmetric.value = metric; | |
9474 | ||
9475 | /* updating route map details */ | |
9476 | if (rtmap) | |
9477 | ospf_routemap_set(red, rtmap); | |
d62a17ae | 9478 | else |
9479 | ospf_routemap_unset(red); | |
9480 | ||
9481 | return ospf_redistribute_default_set(ospf, default_originate, type, | |
9482 | metric); | |
718e3744 | 9483 | } |
9484 | ||
9485 | DEFUN (no_ospf_default_information_originate, | |
9486 | no_ospf_default_information_originate_cmd, | |
ea38ced1 | 9487 | "no default-information originate [{always|metric (0-16777214)|metric-type (1-2)|route-map WORD}]", |
718e3744 | 9488 | NO_STR |
9489 | "Control distribution of default information\n" | |
813d4307 DW |
9490 | "Distribute a default route\n" |
9491 | "Always advertise default route\n" | |
9492 | "OSPF default metric\n" | |
9493 | "OSPF metric\n" | |
9494 | "OSPF metric type for default routes\n" | |
7111c1a0 | 9495 | "Set OSPF External Type 1/2 metrics\n" |
813d4307 DW |
9496 | "Route map reference\n" |
9497 | "Pointer to route-map entries\n") | |
718e3744 | 9498 | { |
a3d826f0 | 9499 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 9500 | struct ospf_redist *red; |
7c8ff89e | 9501 | |
d62a17ae | 9502 | red = ospf_redist_lookup(ospf, DEFAULT_ROUTE, 0); |
9503 | if (!red) | |
9504 | return CMD_SUCCESS; | |
7c8ff89e | 9505 | |
d62a17ae | 9506 | ospf_routemap_unset(red); |
766b826f DA |
9507 | ospf_redist_del(ospf, DEFAULT_ROUTE, 0); |
9508 | ||
d5eac1e0 DL |
9509 | return ospf_redistribute_default_set(ospf, DEFAULT_ORIGINATE_NONE, |
9510 | 0, 0); | |
718e3744 | 9511 | } |
9512 | ||
9513 | DEFUN (ospf_default_metric, | |
9514 | ospf_default_metric_cmd, | |
6147e2c6 | 9515 | "default-metric (0-16777214)", |
718e3744 | 9516 | "Set metric of redistributed routes\n" |
9517 | "Default metric\n") | |
9518 | { | |
a3d826f0 | 9519 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 9520 | int idx_number = 1; |
9521 | int metric = -1; | |
718e3744 | 9522 | |
d62a17ae | 9523 | if (!str2metric(argv[idx_number]->arg, &metric)) |
9524 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 9525 | |
d62a17ae | 9526 | ospf->default_metric = metric; |
718e3744 | 9527 | |
d62a17ae | 9528 | return CMD_SUCCESS; |
718e3744 | 9529 | } |
9530 | ||
9531 | DEFUN (no_ospf_default_metric, | |
9532 | no_ospf_default_metric_cmd, | |
7a7be519 | 9533 | "no default-metric [(0-16777214)]", |
718e3744 | 9534 | NO_STR |
7a7be519 | 9535 | "Set metric of redistributed routes\n" |
9536 | "Default metric\n") | |
718e3744 | 9537 | { |
a3d826f0 | 9538 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
68980084 | 9539 | |
d62a17ae | 9540 | ospf->default_metric = -1; |
68980084 | 9541 | |
d62a17ae | 9542 | return CMD_SUCCESS; |
718e3744 | 9543 | } |
9544 | ||
718e3744 | 9545 | |
9546 | DEFUN (ospf_distance, | |
9547 | ospf_distance_cmd, | |
6147e2c6 | 9548 | "distance (1-255)", |
eaa1ae0d | 9549 | "Administrative distance\n" |
718e3744 | 9550 | "OSPF Administrative distance\n") |
9551 | { | |
a3d826f0 | 9552 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 9553 | int idx_number = 1; |
68980084 | 9554 | |
d62a17ae | 9555 | ospf->distance_all = atoi(argv[idx_number]->arg); |
68980084 | 9556 | |
d62a17ae | 9557 | return CMD_SUCCESS; |
718e3744 | 9558 | } |
9559 | ||
9560 | DEFUN (no_ospf_distance, | |
9561 | no_ospf_distance_cmd, | |
6147e2c6 | 9562 | "no distance (1-255)", |
718e3744 | 9563 | NO_STR |
eaa1ae0d | 9564 | "Administrative distance\n" |
718e3744 | 9565 | "OSPF Administrative distance\n") |
9566 | { | |
a3d826f0 | 9567 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
68980084 | 9568 | |
d62a17ae | 9569 | ospf->distance_all = 0; |
68980084 | 9570 | |
d62a17ae | 9571 | return CMD_SUCCESS; |
718e3744 | 9572 | } |
9573 | ||
9574 | DEFUN (no_ospf_distance_ospf, | |
9575 | no_ospf_distance_ospf_cmd, | |
eaa1ae0d | 9576 | "no distance ospf [{intra-area [(1-255)]|inter-area [(1-255)]|external [(1-255)]}]", |
718e3744 | 9577 | NO_STR |
eaa1ae0d QY |
9578 | "Administrative distance\n" |
9579 | "OSPF administrative distance\n" | |
718e3744 | 9580 | "Intra-area routes\n" |
813d4307 | 9581 | "Distance for intra-area routes\n" |
718e3744 | 9582 | "Inter-area routes\n" |
813d4307 DW |
9583 | "Distance for inter-area routes\n" |
9584 | "External routes\n" | |
9585 | "Distance for external routes\n") | |
718e3744 | 9586 | { |
a3d826f0 | 9587 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 9588 | int idx = 0; |
718e3744 | 9589 | |
d62a17ae | 9590 | if (argv_find(argv, argc, "intra-area", &idx) || argc == 3) |
9591 | idx = ospf->distance_intra = 0; | |
9592 | if (argv_find(argv, argc, "inter-area", &idx) || argc == 3) | |
9593 | idx = ospf->distance_inter = 0; | |
9594 | if (argv_find(argv, argc, "external", &idx) || argc == 3) | |
9595 | ospf->distance_external = 0; | |
718e3744 | 9596 | |
d62a17ae | 9597 | return CMD_SUCCESS; |
718e3744 | 9598 | } |
9599 | ||
6f2a6703 CF |
9600 | DEFUN (ospf_distance_ospf, |
9601 | ospf_distance_ospf_cmd, | |
eaa1ae0d QY |
9602 | "distance ospf {intra-area (1-255)|inter-area (1-255)|external (1-255)}", |
9603 | "Administrative distance\n" | |
9604 | "OSPF administrative distance\n" | |
718e3744 | 9605 | "Intra-area routes\n" |
9606 | "Distance for intra-area routes\n" | |
718e3744 | 9607 | "Inter-area routes\n" |
9608 | "Distance for inter-area routes\n" | |
9609 | "External routes\n" | |
718e3744 | 9610 | "Distance for external routes\n") |
9611 | { | |
a3d826f0 | 9612 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 9613 | int idx = 0; |
68980084 | 9614 | |
926b88f0 CS |
9615 | ospf->distance_intra = 0; |
9616 | ospf->distance_inter = 0; | |
9617 | ospf->distance_external = 0; | |
9618 | ||
d62a17ae | 9619 | if (argv_find(argv, argc, "intra-area", &idx)) |
9620 | ospf->distance_intra = atoi(argv[idx + 1]->arg); | |
9621 | idx = 0; | |
9622 | if (argv_find(argv, argc, "inter-area", &idx)) | |
9623 | ospf->distance_inter = atoi(argv[idx + 1]->arg); | |
9624 | idx = 0; | |
9625 | if (argv_find(argv, argc, "external", &idx)) | |
9626 | ospf->distance_external = atoi(argv[idx + 1]->arg); | |
68980084 | 9627 | |
d62a17ae | 9628 | return CMD_SUCCESS; |
718e3744 | 9629 | } |
9630 | ||
ba682537 | 9631 | DEFUN (ip_ospf_mtu_ignore, |
9632 | ip_ospf_mtu_ignore_addr_cmd, | |
7a7be519 | 9633 | "ip ospf mtu-ignore [A.B.C.D]", |
ba682537 | 9634 | "IP Information\n" |
9635 | "OSPF interface commands\n" | |
99a522c7 | 9636 | "Disable MTU mismatch detection on this interface\n" |
efd7904e | 9637 | "Address of interface\n") |
ba682537 | 9638 | { |
d62a17ae | 9639 | VTY_DECLVAR_CONTEXT(interface, ifp); |
9640 | int idx_ipv4 = 3; | |
9641 | struct in_addr addr; | |
9642 | int ret; | |
9643 | ||
9644 | struct ospf_if_params *params; | |
9645 | params = IF_DEF_PARAMS(ifp); | |
9646 | ||
9647 | if (argc == 4) { | |
9648 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
9649 | if (!ret) { | |
9650 | vty_out(vty, | |
9651 | "Please specify interface address by A.B.C.D\n"); | |
9652 | return CMD_WARNING_CONFIG_FAILED; | |
9653 | } | |
9654 | params = ospf_get_if_params(ifp, addr); | |
9655 | ospf_if_update_params(ifp, addr); | |
9656 | } | |
9657 | params->mtu_ignore = 1; | |
9658 | if (params->mtu_ignore != OSPF_MTU_IGNORE_DEFAULT) | |
9659 | SET_IF_PARAM(params, mtu_ignore); | |
9660 | else { | |
9661 | UNSET_IF_PARAM(params, mtu_ignore); | |
9662 | if (params != IF_DEF_PARAMS(ifp)) { | |
9663 | ospf_free_if_params(ifp, addr); | |
9664 | ospf_if_update_params(ifp, addr); | |
9665 | } | |
9666 | } | |
9667 | return CMD_SUCCESS; | |
ba682537 | 9668 | } |
9669 | ||
ba682537 | 9670 | DEFUN (no_ip_ospf_mtu_ignore, |
9671 | no_ip_ospf_mtu_ignore_addr_cmd, | |
7a7be519 | 9672 | "no ip ospf mtu-ignore [A.B.C.D]", |
efd7904e | 9673 | NO_STR |
ba682537 | 9674 | "IP Information\n" |
9675 | "OSPF interface commands\n" | |
99a522c7 | 9676 | "Disable MTU mismatch detection on this interface\n" |
efd7904e | 9677 | "Address of interface\n") |
ba682537 | 9678 | { |
d62a17ae | 9679 | VTY_DECLVAR_CONTEXT(interface, ifp); |
9680 | int idx_ipv4 = 4; | |
9681 | struct in_addr addr; | |
9682 | int ret; | |
9683 | ||
9684 | struct ospf_if_params *params; | |
9685 | params = IF_DEF_PARAMS(ifp); | |
9686 | ||
9687 | if (argc == 5) { | |
9688 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
9689 | if (!ret) { | |
9690 | vty_out(vty, | |
9691 | "Please specify interface address by A.B.C.D\n"); | |
9692 | return CMD_WARNING_CONFIG_FAILED; | |
9693 | } | |
9694 | params = ospf_get_if_params(ifp, addr); | |
9695 | ospf_if_update_params(ifp, addr); | |
9696 | } | |
9697 | params->mtu_ignore = 0; | |
9698 | if (params->mtu_ignore != OSPF_MTU_IGNORE_DEFAULT) | |
9699 | SET_IF_PARAM(params, mtu_ignore); | |
9700 | else { | |
9701 | UNSET_IF_PARAM(params, mtu_ignore); | |
9702 | if (params != IF_DEF_PARAMS(ifp)) { | |
9703 | ospf_free_if_params(ifp, addr); | |
9704 | ospf_if_update_params(ifp, addr); | |
9705 | } | |
9706 | } | |
9707 | return CMD_SUCCESS; | |
ba682537 | 9708 | } |
9709 | ||
6b0655a2 | 9710 | |
88d6cf37 | 9711 | DEFUN (ospf_max_metric_router_lsa_admin, |
9712 | ospf_max_metric_router_lsa_admin_cmd, | |
9713 | "max-metric router-lsa administrative", | |
9714 | "OSPF maximum / infinite-distance metric\n" | |
9715 | "Advertise own Router-LSA with infinite distance (stub router)\n" | |
9716 | "Administratively applied, for an indefinite period\n") | |
9717 | { | |
a3d826f0 | 9718 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 9719 | struct listnode *ln; |
9720 | struct ospf_area *area; | |
7c8ff89e | 9721 | |
d62a17ae | 9722 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, ln, area)) { |
9723 | SET_FLAG(area->stub_router_state, OSPF_AREA_ADMIN_STUB_ROUTED); | |
4ba4fc85 | 9724 | |
d62a17ae | 9725 | if (!CHECK_FLAG(area->stub_router_state, |
9726 | OSPF_AREA_IS_STUB_ROUTED)) | |
9727 | ospf_router_lsa_update_area(area); | |
9728 | } | |
4ba4fc85 | 9729 | |
d62a17ae | 9730 | /* Allows for areas configured later to get the property */ |
9731 | ospf->stub_router_admin_set = OSPF_STUB_ROUTER_ADMINISTRATIVE_SET; | |
9732 | ||
9733 | return CMD_SUCCESS; | |
88d6cf37 | 9734 | } |
9735 | ||
9736 | DEFUN (no_ospf_max_metric_router_lsa_admin, | |
9737 | no_ospf_max_metric_router_lsa_admin_cmd, | |
9738 | "no max-metric router-lsa administrative", | |
9739 | NO_STR | |
9740 | "OSPF maximum / infinite-distance metric\n" | |
9741 | "Advertise own Router-LSA with infinite distance (stub router)\n" | |
9742 | "Administratively applied, for an indefinite period\n") | |
9743 | { | |
a3d826f0 | 9744 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 9745 | struct listnode *ln; |
9746 | struct ospf_area *area; | |
9747 | ||
9748 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, ln, area)) { | |
9749 | UNSET_FLAG(area->stub_router_state, | |
9750 | OSPF_AREA_ADMIN_STUB_ROUTED); | |
9751 | ||
9752 | /* Don't trample on the start-up stub timer */ | |
9753 | if (CHECK_FLAG(area->stub_router_state, | |
9754 | OSPF_AREA_IS_STUB_ROUTED) | |
9755 | && !area->t_stub_router) { | |
9756 | UNSET_FLAG(area->stub_router_state, | |
9757 | OSPF_AREA_IS_STUB_ROUTED); | |
9758 | ospf_router_lsa_update_area(area); | |
9759 | } | |
9760 | } | |
9761 | ospf->stub_router_admin_set = OSPF_STUB_ROUTER_ADMINISTRATIVE_UNSET; | |
9762 | return CMD_SUCCESS; | |
88d6cf37 | 9763 | } |
9764 | ||
9765 | DEFUN (ospf_max_metric_router_lsa_startup, | |
9766 | ospf_max_metric_router_lsa_startup_cmd, | |
6147e2c6 | 9767 | "max-metric router-lsa on-startup (5-86400)", |
88d6cf37 | 9768 | "OSPF maximum / infinite-distance metric\n" |
9769 | "Advertise own Router-LSA with infinite distance (stub router)\n" | |
9770 | "Automatically advertise stub Router-LSA on startup of OSPF\n" | |
9771 | "Time (seconds) to advertise self as stub-router\n") | |
9772 | { | |
a3d826f0 | 9773 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 9774 | int idx_number = 3; |
9775 | unsigned int seconds; | |
9776 | ||
b5a8894d | 9777 | if (argc < 4) { |
d62a17ae | 9778 | vty_out(vty, "%% Must supply stub-router period"); |
9779 | return CMD_WARNING_CONFIG_FAILED; | |
9780 | } | |
9781 | ||
9782 | seconds = strtoul(argv[idx_number]->arg, NULL, 10); | |
9783 | ||
9784 | ospf->stub_router_startup_time = seconds; | |
9785 | ||
9786 | return CMD_SUCCESS; | |
88d6cf37 | 9787 | } |
9788 | ||
9789 | DEFUN (no_ospf_max_metric_router_lsa_startup, | |
9790 | no_ospf_max_metric_router_lsa_startup_cmd, | |
7a7be519 | 9791 | "no max-metric router-lsa on-startup [(5-86400)]", |
88d6cf37 | 9792 | NO_STR |
9793 | "OSPF maximum / infinite-distance metric\n" | |
9794 | "Advertise own Router-LSA with infinite distance (stub router)\n" | |
813d4307 DW |
9795 | "Automatically advertise stub Router-LSA on startup of OSPF\n" |
9796 | "Time (seconds) to advertise self as stub-router\n") | |
88d6cf37 | 9797 | { |
a3d826f0 | 9798 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 9799 | struct listnode *ln; |
9800 | struct ospf_area *area; | |
9801 | ||
9802 | ospf->stub_router_startup_time = OSPF_STUB_ROUTER_UNCONFIGURED; | |
9803 | ||
9804 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, ln, area)) { | |
9805 | SET_FLAG(area->stub_router_state, | |
9806 | OSPF_AREA_WAS_START_STUB_ROUTED); | |
9807 | OSPF_TIMER_OFF(area->t_stub_router); | |
9808 | ||
9809 | /* Don't trample on admin stub routed */ | |
9810 | if (!CHECK_FLAG(area->stub_router_state, | |
9811 | OSPF_AREA_ADMIN_STUB_ROUTED)) { | |
9812 | UNSET_FLAG(area->stub_router_state, | |
9813 | OSPF_AREA_IS_STUB_ROUTED); | |
9814 | ospf_router_lsa_update_area(area); | |
9815 | } | |
9816 | } | |
9817 | return CMD_SUCCESS; | |
88d6cf37 | 9818 | } |
9819 | ||
a1afa410 | 9820 | |
88d6cf37 | 9821 | DEFUN (ospf_max_metric_router_lsa_shutdown, |
9822 | ospf_max_metric_router_lsa_shutdown_cmd, | |
6147e2c6 | 9823 | "max-metric router-lsa on-shutdown (5-100)", |
88d6cf37 | 9824 | "OSPF maximum / infinite-distance metric\n" |
9825 | "Advertise own Router-LSA with infinite distance (stub router)\n" | |
9826 | "Advertise stub-router prior to full shutdown of OSPF\n" | |
9827 | "Time (seconds) to wait till full shutdown\n") | |
9828 | { | |
a3d826f0 | 9829 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 9830 | int idx_number = 3; |
9831 | unsigned int seconds; | |
9832 | ||
b5a8894d | 9833 | if (argc < 4) { |
d62a17ae | 9834 | vty_out(vty, "%% Must supply stub-router shutdown period"); |
9835 | return CMD_WARNING_CONFIG_FAILED; | |
9836 | } | |
9837 | ||
9838 | seconds = strtoul(argv[idx_number]->arg, NULL, 10); | |
9839 | ||
9840 | ospf->stub_router_shutdown_time = seconds; | |
9841 | ||
9842 | return CMD_SUCCESS; | |
88d6cf37 | 9843 | } |
9844 | ||
9845 | DEFUN (no_ospf_max_metric_router_lsa_shutdown, | |
9846 | no_ospf_max_metric_router_lsa_shutdown_cmd, | |
7a7be519 | 9847 | "no max-metric router-lsa on-shutdown [(5-100)]", |
88d6cf37 | 9848 | NO_STR |
9849 | "OSPF maximum / infinite-distance metric\n" | |
9850 | "Advertise own Router-LSA with infinite distance (stub router)\n" | |
813d4307 DW |
9851 | "Advertise stub-router prior to full shutdown of OSPF\n" |
9852 | "Time (seconds) to wait till full shutdown\n") | |
88d6cf37 | 9853 | { |
a3d826f0 | 9854 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
7c8ff89e | 9855 | |
d62a17ae | 9856 | ospf->stub_router_shutdown_time = OSPF_STUB_ROUTER_UNCONFIGURED; |
9857 | ||
9858 | return CMD_SUCCESS; | |
88d6cf37 | 9859 | } |
9860 | ||
a92706bb JU |
9861 | DEFUN (ospf_proactive_arp, |
9862 | ospf_proactive_arp_cmd, | |
9863 | "proactive-arp", | |
9864 | "Allow sending ARP requests proactively\n") | |
9865 | { | |
9866 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
9867 | ||
9868 | ospf->proactive_arp = true; | |
9869 | ||
9870 | return CMD_SUCCESS; | |
9871 | } | |
9872 | ||
9873 | DEFUN (no_ospf_proactive_arp, | |
9874 | no_ospf_proactive_arp_cmd, | |
9875 | "no proactive-arp", | |
9876 | NO_STR | |
9877 | "Disallow sending ARP requests proactively\n") | |
9878 | { | |
9879 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
9880 | ||
9881 | ospf->proactive_arp = false; | |
9882 | ||
9883 | return CMD_SUCCESS; | |
9884 | } | |
9885 | ||
07b33add | 9886 | /* Graceful Restart HELPER Commands */ |
9887 | DEFPY(ospf_gr_helper_enable, ospf_gr_helper_enable_cmd, | |
9888 | "graceful-restart helper-only [A.B.C.D]", | |
9889 | "OSPF Graceful Restart\n" | |
9890 | "Enable Helper support\n" | |
9891 | "Advertising router id\n") | |
9892 | { | |
9893 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
9894 | struct in_addr addr; | |
9895 | int ret; | |
9896 | ||
9897 | if (argc == 3) { | |
9898 | ret = inet_aton(argv[2]->arg, &addr); | |
9899 | if (!ret) { | |
9900 | vty_out(vty, | |
9901 | "Please specify the valid routerid address.\n"); | |
9902 | return CMD_WARNING_CONFIG_FAILED; | |
9903 | } | |
9904 | ||
9905 | ospf_gr_helper_support_set_per_routerid(ospf, &addr, OSPF_GR_TRUE); | |
9906 | return CMD_SUCCESS; | |
9907 | } | |
9908 | ||
9909 | ospf_gr_helper_support_set(ospf, OSPF_GR_TRUE); | |
9910 | ||
9911 | return CMD_SUCCESS; | |
9912 | } | |
9913 | ||
9914 | DEFPY(no_ospf_gr_helper_enable, | |
9915 | no_ospf_gr_helper_enable_cmd, | |
9916 | "no graceful-restart helper-only [A.B.C.D]", | |
9917 | NO_STR | |
9918 | "OSPF Graceful Restart\n" | |
9919 | "Disable Helper support\n" | |
9920 | "Advertising router id\n") | |
9921 | { | |
9922 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
9923 | struct in_addr addr; | |
9924 | int ret; | |
9925 | ||
9926 | if (argc == 4) { | |
9927 | ret = inet_aton(argv[3]->arg, &addr); | |
9928 | if (!ret) { | |
9929 | vty_out(vty, | |
9930 | "Please specify the valid routerid address.\n"); | |
9931 | return CMD_WARNING_CONFIG_FAILED; | |
9932 | } | |
9933 | ||
9934 | ospf_gr_helper_support_set_per_routerid(ospf, &addr, | |
9935 | OSPF_GR_FALSE); | |
9936 | return CMD_SUCCESS; | |
9937 | } | |
9938 | ||
9939 | ospf_gr_helper_support_set(ospf, OSPF_GR_FALSE); | |
9940 | return CMD_SUCCESS; | |
9941 | } | |
9942 | ||
9943 | DEFPY(ospf_gr_helper_enable_lsacheck, | |
9944 | ospf_gr_helper_enable_lsacheck_cmd, | |
9945 | "graceful-restart helper strict-lsa-checking", | |
9946 | "OSPF Graceful Restart\n" | |
9947 | "OSPF GR Helper\n" | |
9948 | "Enable strict LSA check\n") | |
9949 | { | |
9950 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
9951 | ||
9952 | ospf_gr_helper_lsa_check_set(ospf, OSPF_GR_TRUE); | |
9953 | return CMD_SUCCESS; | |
9954 | } | |
9955 | ||
9956 | DEFPY(no_ospf_gr_helper_enable_lsacheck, | |
9957 | no_ospf_gr_helper_enable_lsacheck_cmd, | |
9958 | "no graceful-restart helper strict-lsa-checking", | |
9959 | NO_STR | |
9960 | "OSPF Graceful Restart\n" | |
9961 | "OSPF GR Helper\n" | |
9962 | "Disable strict LSA check\n") | |
9963 | { | |
9964 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
9965 | ||
9966 | ospf_gr_helper_lsa_check_set(ospf, OSPF_GR_FALSE); | |
9967 | return CMD_SUCCESS; | |
9968 | } | |
9969 | ||
9970 | DEFPY(ospf_gr_helper_supported_grace_time, | |
9971 | ospf_gr_helper_supported_grace_time_cmd, | |
9972 | "graceful-restart helper supported-grace-time (10-1800)$interval", | |
9973 | "OSPF Graceful Restart\n" | |
9974 | "OSPF GR Helper\n" | |
9975 | "Supported grace timer\n" | |
9976 | "Grace interval(in seconds)\n") | |
9977 | { | |
9978 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
9979 | ||
9980 | ospf_gr_helper_supported_gracetime_set(ospf, interval); | |
9981 | return CMD_SUCCESS; | |
9982 | } | |
9983 | ||
9984 | DEFPY(no_ospf_gr_helper_supported_grace_time, | |
9985 | no_ospf_gr_helper_supported_grace_time_cmd, | |
9986 | "no graceful-restart helper supported-grace-time (10-1800)$interval", | |
9987 | NO_STR | |
9988 | "OSPF Graceful Restart\n" | |
9989 | "OSPF GR Helper\n" | |
9990 | "Supported grace timer\n" | |
9991 | "Grace interval(in seconds)\n") | |
9992 | { | |
9993 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
9994 | ||
9995 | ospf_gr_helper_supported_gracetime_set(ospf, OSPF_MAX_GRACE_INTERVAL); | |
9996 | return CMD_SUCCESS; | |
9997 | } | |
9998 | ||
9999 | DEFPY(ospf_gr_helper_planned_only, | |
10000 | ospf_gr_helper_planned_only_cmd, | |
10001 | "graceful-restart helper planned-only", | |
10002 | "OSPF Graceful Restart\n" | |
10003 | "OSPF GR Helper\n" | |
10004 | "Supported only planned restart\n") | |
10005 | { | |
10006 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
10007 | ||
10008 | ospf_gr_helper_set_supported_planned_only_restart(ospf, OSPF_GR_TRUE); | |
10009 | ||
10010 | return CMD_SUCCESS; | |
10011 | } | |
10012 | ||
423e71c4 | 10013 | /* External Route Aggregation */ |
10014 | DEFUN (ospf_external_route_aggregation, | |
10015 | ospf_external_route_aggregation_cmd, | |
10016 | "summary-address A.B.C.D/M [tag (1-4294967295)]", | |
10017 | "External summary address\n" | |
10018 | "Summary address prefix (a.b.c.d/m) \n" | |
10019 | "Router tag \n" | |
10020 | "Router tag value\n") | |
10021 | { | |
10022 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
10023 | struct prefix_ipv4 p; | |
10024 | int idx = 1; | |
10025 | route_tag_t tag = 0; | |
10026 | int ret = OSPF_SUCCESS; | |
10027 | ||
10028 | str2prefix_ipv4(argv[idx]->arg, &p); | |
10029 | ||
1fe59b44 | 10030 | if (is_default_prefix4(&p)) { |
423e71c4 | 10031 | vty_out(vty, |
10032 | "Default address shouldn't be configured as summary address.\n"); | |
10033 | return CMD_SUCCESS; | |
10034 | } | |
10035 | ||
10036 | /* Apply mask for given prefix. */ | |
10037 | apply_mask((struct prefix *)&p); | |
10038 | ||
10039 | if (!is_valid_summary_addr(&p)) { | |
10040 | vty_out(vty, "Not a valid summary address.\n"); | |
10041 | return CMD_WARNING_CONFIG_FAILED; | |
10042 | } | |
10043 | ||
10044 | if (argc > 2) | |
10045 | tag = strtoul(argv[idx + 2]->arg, NULL, 10); | |
10046 | ||
10047 | ret = ospf_asbr_external_aggregator_set(ospf, &p, tag); | |
10048 | if (ret == OSPF_INVALID) | |
10049 | vty_out(vty, "Inavlid configuration!!\n"); | |
10050 | ||
10051 | return CMD_SUCCESS; | |
10052 | } | |
10053 | ||
10054 | DEFUN (no_ospf_external_route_aggregation, | |
10055 | no_ospf_external_route_aggregation_cmd, | |
10056 | "no summary-address A.B.C.D/M [tag (1-4294967295)]", | |
10057 | NO_STR | |
10058 | "External summary address\n" | |
10059 | "Summary address prefix (a.b.c.d/m)\n" | |
10060 | "Router tag\n" | |
10061 | "Router tag value\n") | |
10062 | { | |
10063 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
10064 | struct prefix_ipv4 p; | |
10065 | int idx = 2; | |
10066 | route_tag_t tag = 0; | |
10067 | int ret = OSPF_SUCCESS; | |
10068 | ||
10069 | str2prefix_ipv4(argv[idx]->arg, &p); | |
10070 | ||
1fe59b44 | 10071 | if (is_default_prefix4(&p)) { |
423e71c4 | 10072 | vty_out(vty, |
10073 | "Default address shouldn't be configured as summary address.\n"); | |
10074 | return CMD_SUCCESS; | |
10075 | } | |
10076 | ||
10077 | /* Apply mask for given prefix. */ | |
10078 | apply_mask((struct prefix *)&p); | |
10079 | ||
10080 | if (!is_valid_summary_addr(&p)) { | |
10081 | vty_out(vty, "Not a valid summary address.\n"); | |
10082 | return CMD_WARNING_CONFIG_FAILED; | |
10083 | } | |
10084 | ||
10085 | if (argc > 3) | |
10086 | tag = strtoul(argv[idx + 2]->arg, NULL, 10); | |
10087 | ||
10088 | ret = ospf_asbr_external_aggregator_unset(ospf, &p, tag); | |
10089 | if (ret == OSPF_INVALID) | |
10090 | vty_out(vty, "Inavlid configuration!!\n"); | |
10091 | ||
10092 | return CMD_SUCCESS; | |
10093 | } | |
10094 | ||
07b33add | 10095 | DEFPY(no_ospf_gr_helper_planned_only, |
10096 | no_ospf_gr_helper_planned_only_cmd, | |
10097 | "no graceful-restart helper planned-only", | |
10098 | NO_STR | |
10099 | "OSPF Graceful Restart\n" | |
10100 | "OSPF GR Helper\n" | |
10101 | "Supported only for planned restart\n") | |
10102 | { | |
10103 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
10104 | ||
10105 | ospf_gr_helper_set_supported_planned_only_restart(ospf, OSPF_GR_FALSE); | |
10106 | ||
10107 | return CMD_SUCCESS; | |
10108 | } | |
abd5b8c7 | 10109 | |
1ac88792 | 10110 | static int ospf_print_vty_helper_dis_rtr_walkcb(struct hash_bucket *bucket, |
abd5b8c7 | 10111 | void *arg) |
10112 | { | |
1ac88792 | 10113 | struct advRtr *rtr = bucket->data; |
abd5b8c7 | 10114 | struct vty *vty = (struct vty *)arg; |
10115 | static unsigned int count; | |
10116 | ||
96b663a3 | 10117 | vty_out(vty, "%-6pI4,", &rtr->advRtrAddr); |
abd5b8c7 | 10118 | count++; |
10119 | ||
10120 | if (count % 5 == 0) | |
10121 | vty_out(vty, "\n"); | |
10122 | ||
10123 | return HASHWALK_CONTINUE; | |
10124 | } | |
10125 | ||
10126 | static int ospf_show_gr_helper_details(struct vty *vty, struct ospf *ospf, | |
10127 | uint8_t use_vrf, json_object *json, | |
10128 | bool uj, bool detail) | |
10129 | { | |
10130 | struct listnode *node; | |
10131 | struct ospf_interface *oi; | |
96b663a3 | 10132 | char buf[PREFIX_STRLEN]; |
abd5b8c7 | 10133 | json_object *json_vrf = NULL; |
10134 | ||
10135 | if (uj) { | |
10136 | if (use_vrf) | |
10137 | json_vrf = json_object_new_object(); | |
10138 | else | |
10139 | json_vrf = json; | |
10140 | } | |
10141 | ||
10142 | if (ospf->instance) { | |
10143 | if (uj) | |
10144 | json_object_int_add(json, "ospfInstance", | |
10145 | ospf->instance); | |
10146 | else | |
10147 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
10148 | } | |
10149 | ||
10150 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); | |
10151 | ||
10152 | if (uj) { | |
10153 | if (use_vrf) { | |
10154 | if (ospf->vrf_id == VRF_DEFAULT) | |
10155 | json_object_object_add(json, "default", | |
10156 | json_vrf); | |
10157 | else | |
10158 | json_object_object_add(json, ospf->name, | |
10159 | json_vrf); | |
10160 | } | |
10161 | } else | |
10162 | vty_out(vty, "\n"); | |
10163 | ||
10164 | /* Show Router ID. */ | |
10165 | if (uj) { | |
10166 | json_object_string_add(json_vrf, "routerId", | |
96b663a3 MS |
10167 | inet_ntop(AF_INET, &ospf->router_id, |
10168 | buf, sizeof(buf))); | |
abd5b8c7 | 10169 | } else { |
96b663a3 MS |
10170 | vty_out(vty, "\n OSPF Router with ID (%pI4)\n\n", |
10171 | &ospf->router_id); | |
abd5b8c7 | 10172 | } |
10173 | ||
10174 | if (!uj) { | |
10175 | ||
10176 | if (ospf->is_helper_supported) | |
10177 | vty_out(vty, | |
10178 | " Graceful restart helper support enabled.\n"); | |
10179 | else | |
10180 | vty_out(vty, | |
10181 | " Graceful restart helper support disabled.\n"); | |
10182 | ||
10183 | if (ospf->strict_lsa_check) | |
10184 | vty_out(vty, " Strict LSA check is enabled.\n"); | |
10185 | else | |
10186 | vty_out(vty, " Strict LSA check is disabled.\n"); | |
10187 | ||
10188 | if (ospf->only_planned_restart) | |
10189 | vty_out(vty, | |
10190 | " Helper supported for planned restarts only.\n"); | |
10191 | else | |
10192 | vty_out(vty, | |
10193 | " Helper supported for Planned and Unplanned Restarts.\n"); | |
10194 | ||
10195 | vty_out(vty, | |
10196 | " Supported Graceful restart interval: %d(in seconds).\n", | |
10197 | ospf->supported_grace_time); | |
10198 | ||
10199 | if (OSPF_HELPER_ENABLE_RTR_COUNT(ospf)) { | |
10200 | vty_out(vty, " Enable Router list:\n"); | |
10201 | vty_out(vty, " "); | |
10202 | hash_walk(ospf->enable_rtr_list, | |
10203 | ospf_print_vty_helper_dis_rtr_walkcb, vty); | |
10204 | vty_out(vty, "\n\n"); | |
10205 | } | |
10206 | ||
10207 | if (ospf->last_exit_reason != OSPF_GR_HELPER_EXIT_NONE) { | |
10208 | vty_out(vty, " Last Helper exit Reason :%s\n", | |
d05d5280 | 10209 | ospf_exit_reason2str(ospf->last_exit_reason)); |
abd5b8c7 | 10210 | } |
10211 | ||
10212 | if (ospf->active_restarter_cnt) | |
10213 | vty_out(vty, | |
10214 | " Number of Active neighbours in graceful restart: %d\n", | |
10215 | ospf->active_restarter_cnt); | |
10216 | else | |
10217 | vty_out(vty, "\n"); | |
10218 | ||
10219 | } else { | |
10220 | json_object_string_add( | |
10221 | json_vrf, "helperSupport", | |
10222 | (ospf->is_helper_supported) ? "Enabled" : "Disabled"); | |
10223 | json_object_string_add(json_vrf, "strictLsaCheck", | |
10224 | (ospf->strict_lsa_check) ? "Enabled" | |
10225 | : "Disabled"); | |
10226 | json_object_string_add( | |
10227 | json_vrf, "restartSupoort", | |
10228 | (ospf->only_planned_restart) | |
10229 | ? "Planned Restart only" | |
10230 | : "Planned and Unplanned Restarts"); | |
10231 | ||
10232 | json_object_int_add(json_vrf, "supportedGracePeriod", | |
10233 | ospf->supported_grace_time); | |
10234 | ||
10235 | if (ospf->last_exit_reason != OSPF_GR_HELPER_EXIT_NONE) | |
10236 | json_object_string_add( | |
10237 | json_vrf, "LastExitReason", | |
d05d5280 | 10238 | ospf_exit_reason2str(ospf->last_exit_reason)); |
abd5b8c7 | 10239 | |
10240 | if (ospf->active_restarter_cnt) | |
10241 | json_object_int_add(json_vrf, "activeRestarterCnt", | |
10242 | ospf->active_restarter_cnt); | |
10243 | } | |
10244 | ||
10245 | ||
10246 | if (detail) { | |
10247 | int cnt = 1; | |
10248 | json_object *json_neighbors = NULL; | |
10249 | ||
10250 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) { | |
10251 | struct route_node *rn; | |
10252 | struct ospf_neighbor *nbr; | |
10253 | json_object *json_neigh; | |
10254 | ||
10255 | if (ospf_interface_neighbor_count(oi) == 0) | |
10256 | continue; | |
10257 | ||
10258 | if (uj) { | |
10259 | json_object_object_get_ex(json_vrf, "Neighbors", | |
10260 | &json_neighbors); | |
10261 | if (!json_neighbors) { | |
10262 | json_neighbors = | |
10263 | json_object_new_object(); | |
10264 | json_object_object_add(json_vrf, | |
10265 | "Neighbors", | |
10266 | json_neighbors); | |
10267 | } | |
10268 | } | |
10269 | ||
10270 | for (rn = route_top(oi->nbrs); rn; | |
10271 | rn = route_next(rn)) { | |
10272 | ||
10273 | if (!rn->info) | |
10274 | continue; | |
10275 | ||
10276 | nbr = rn->info; | |
10277 | ||
10278 | if (!OSPF_GR_IS_ACTIVE_HELPER(nbr)) | |
10279 | continue; | |
10280 | ||
10281 | if (!uj) { | |
10282 | vty_out(vty, " Neighbour %d :\n", cnt); | |
96b663a3 MS |
10283 | vty_out(vty, " Address : %pI4\n", |
10284 | &nbr->address.u.prefix4); | |
10285 | vty_out(vty, " Routerid : %pI4\n", | |
10286 | &nbr->router_id); | |
abd5b8c7 | 10287 | vty_out(vty, |
10288 | " Received Grace period : %d(in seconds).\n", | |
10289 | nbr->gr_helper_info | |
10290 | .recvd_grace_period); | |
10291 | vty_out(vty, | |
10292 | " Actual Grace period : %d(in seconds)\n", | |
10293 | nbr->gr_helper_info | |
10294 | .actual_grace_period); | |
10295 | vty_out(vty, | |
10296 | " Remaining GraceTime:%ld(in seconds).\n", | |
10297 | thread_timer_remain_second( | |
10298 | nbr->gr_helper_info | |
10299 | .t_grace_timer)); | |
10300 | vty_out(vty, | |
10301 | " Graceful Restart reason: %s.\n\n", | |
d05d5280 MS |
10302 | ospf_restart_reason2str( |
10303 | nbr->gr_helper_info | |
10304 | .gr_restart_reason)); | |
abd5b8c7 | 10305 | cnt++; |
10306 | } else { | |
10307 | json_neigh = json_object_new_object(); | |
10308 | json_object_string_add( | |
10309 | json_neigh, "srcAddr", | |
96b663a3 MS |
10310 | inet_ntop(AF_INET, &nbr->src, |
10311 | buf, sizeof(buf))); | |
abd5b8c7 | 10312 | |
10313 | json_object_string_add( | |
10314 | json_neigh, "routerid", | |
96b663a3 MS |
10315 | inet_ntop(AF_INET, |
10316 | &nbr->router_id, | |
10317 | buf, sizeof(buf))); | |
abd5b8c7 | 10318 | json_object_int_add( |
10319 | json_neigh, | |
10320 | "recvdGraceInterval", | |
10321 | nbr->gr_helper_info | |
10322 | .recvd_grace_period); | |
10323 | json_object_int_add( | |
10324 | json_neigh, | |
10325 | "actualGraceInterval", | |
10326 | nbr->gr_helper_info | |
10327 | .actual_grace_period); | |
10328 | json_object_int_add( | |
10329 | json_neigh, "remainGracetime", | |
10330 | thread_timer_remain_second( | |
10331 | nbr->gr_helper_info | |
10332 | .t_grace_timer)); | |
10333 | json_object_string_add( | |
10334 | json_neigh, "restartReason", | |
d05d5280 MS |
10335 | ospf_restart_reason2str( |
10336 | nbr->gr_helper_info | |
10337 | .gr_restart_reason)); | |
abd5b8c7 | 10338 | json_object_object_add( |
10339 | json_neighbors, | |
96b663a3 MS |
10340 | inet_ntop(AF_INET, &nbr->src, |
10341 | buf, sizeof(buf)), | |
abd5b8c7 | 10342 | json_neigh); |
10343 | } | |
10344 | } | |
10345 | } | |
10346 | } | |
423e71c4 | 10347 | return CMD_SUCCESS; |
10348 | } | |
10349 | ||
10350 | DEFUN (ospf_external_route_aggregation_no_adrvertise, | |
10351 | ospf_external_route_aggregation_no_adrvertise_cmd, | |
10352 | "summary-address A.B.C.D/M no-advertise", | |
10353 | "External summary address\n" | |
10354 | "Summary address prefix (a.b.c.d/m) \n" | |
10355 | "Don't advertise summary route \n") | |
10356 | { | |
10357 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
10358 | struct prefix_ipv4 p; | |
10359 | int idx = 1; | |
10360 | int ret = OSPF_SUCCESS; | |
10361 | ||
10362 | str2prefix_ipv4(argv[idx]->arg, &p); | |
10363 | ||
1fe59b44 | 10364 | if (is_default_prefix4(&p)) { |
423e71c4 | 10365 | vty_out(vty, |
10366 | "Default address shouldn't be configured as summary address.\n"); | |
10367 | return CMD_SUCCESS; | |
10368 | } | |
10369 | ||
10370 | /* Apply mask for given prefix. */ | |
10371 | apply_mask((struct prefix *)&p); | |
10372 | ||
10373 | if (!is_valid_summary_addr(&p)) { | |
10374 | vty_out(vty, "Not a valid summary address.\n"); | |
10375 | return CMD_WARNING_CONFIG_FAILED; | |
10376 | } | |
10377 | ||
10378 | ret = ospf_asbr_external_rt_no_advertise(ospf, &p); | |
10379 | if (ret == OSPF_INVALID) | |
10380 | vty_out(vty, "Inavlid configuration!!\n"); | |
10381 | ||
10382 | return CMD_SUCCESS; | |
10383 | } | |
10384 | ||
10385 | DEFUN (no_ospf_external_route_aggregation_no_adrvertise, | |
10386 | no_ospf_external_route_aggregation_no_adrvertise_cmd, | |
10387 | "no summary-address A.B.C.D/M no-advertise", | |
10388 | NO_STR | |
10389 | "External summary address\n" | |
fbc48492 DS |
10390 | "Summary address prefix (a.b.c.d/m)\n" |
10391 | "Advertise summary route to the AS \n") | |
423e71c4 | 10392 | { |
10393 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
10394 | struct prefix_ipv4 p; | |
10395 | int idx = 2; | |
10396 | int ret = OSPF_SUCCESS; | |
10397 | ||
10398 | str2prefix_ipv4(argv[idx]->arg, &p); | |
10399 | ||
1fe59b44 | 10400 | if (is_default_prefix4(&p)) { |
423e71c4 | 10401 | vty_out(vty, |
10402 | "Default address shouldn't be configured as summary address.\n"); | |
10403 | return CMD_SUCCESS; | |
10404 | } | |
10405 | ||
10406 | /* Apply mask for given prefix. */ | |
10407 | apply_mask((struct prefix *)&p); | |
10408 | ||
10409 | if (!is_valid_summary_addr(&p)) { | |
10410 | vty_out(vty, "Not a valid summary address.\n"); | |
10411 | return CMD_WARNING_CONFIG_FAILED; | |
10412 | } | |
10413 | ||
10414 | ret = ospf_asbr_external_rt_advertise(ospf, &p); | |
10415 | if (ret == OSPF_INVALID) | |
10416 | vty_out(vty, "Inavlid configuration!!\n"); | |
10417 | ||
10418 | return CMD_SUCCESS; | |
10419 | } | |
10420 | ||
10421 | DEFUN (ospf_route_aggregation_timer, | |
10422 | ospf_route_aggregation_timer_cmd, | |
10423 | "aggregation timer (5-1800)", | |
10424 | "External route aggregation\n" | |
10425 | "Delay timer (in seconds)\n" | |
10426 | "Timer interval(in seconds)\n") | |
10427 | { | |
10428 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
10429 | unsigned int interval = 0; | |
10430 | ||
10431 | interval = strtoul(argv[2]->arg, NULL, 10); | |
10432 | ||
10433 | ospf_external_aggregator_timer_set(ospf, interval); | |
abd5b8c7 | 10434 | |
10435 | return CMD_SUCCESS; | |
10436 | } | |
10437 | ||
10438 | DEFPY (show_ip_ospf_gr_helper, | |
10439 | show_ip_ospf_gr_helper_cmd, | |
10440 | "show ip ospf [vrf <NAME|all>] graceful-restart helper [detail] [json]", | |
10441 | SHOW_STR | |
10442 | IP_STR | |
10443 | "OSPF information\n" | |
10444 | VRF_CMD_HELP_STR | |
10445 | "All VRFs\n" | |
10446 | "OSPF Graceful Restart\n" | |
10447 | "Helper details in the router\n" | |
10448 | "Detailed informtion\n" | |
10449 | JSON_STR) | |
10450 | { | |
10451 | char *vrf_name = NULL; | |
10452 | bool all_vrf = false; | |
10453 | int ret = CMD_SUCCESS; | |
10454 | int idx_vrf = 0; | |
10455 | int idx = 0; | |
10456 | uint8_t use_vrf = 0; | |
10457 | bool uj = use_json(argc, argv); | |
10458 | struct ospf *ospf = NULL; | |
10459 | json_object *json = NULL; | |
10460 | struct listnode *node = NULL; | |
10461 | int inst = 0; | |
10462 | bool detail = false; | |
10463 | ||
10464 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); | |
10465 | ||
10466 | if (argv_find(argv, argc, "detail", &idx)) | |
10467 | detail = true; | |
10468 | ||
10469 | if (uj) | |
10470 | json = json_object_new_object(); | |
10471 | ||
10472 | /* vrf input is provided */ | |
10473 | if (vrf_name) { | |
10474 | use_vrf = 1; | |
10475 | ||
10476 | if (all_vrf) { | |
10477 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
10478 | if (!ospf->oi_running) | |
10479 | continue; | |
10480 | ||
10481 | ret = ospf_show_gr_helper_details( | |
10482 | vty, ospf, use_vrf, json, uj, detail); | |
10483 | } | |
10484 | ||
10485 | if (uj) { | |
10486 | vty_out(vty, "%s\n", | |
10487 | json_object_to_json_string_ext( | |
10488 | json, JSON_C_TO_STRING_PRETTY)); | |
10489 | json_object_free(json); | |
10490 | } | |
10491 | ||
10492 | return ret; | |
10493 | } | |
10494 | ||
10495 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
10496 | ||
10497 | if (ospf == NULL || !ospf->oi_running) { | |
10498 | ||
10499 | if (uj) { | |
10500 | vty_out(vty, "%s\n", | |
10501 | json_object_to_json_string_ext( | |
10502 | json, JSON_C_TO_STRING_PRETTY)); | |
10503 | json_object_free(json); | |
10504 | } else | |
10505 | vty_out(vty, "%% OSPF instance not found\n"); | |
10506 | ||
10507 | return CMD_SUCCESS; | |
10508 | } | |
10509 | ||
10510 | } else { | |
10511 | /* Default Vrf */ | |
10512 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
10513 | ||
10514 | if (ospf == NULL || !ospf->oi_running) { | |
10515 | ||
10516 | if (uj) { | |
10517 | vty_out(vty, "%s\n", | |
10518 | json_object_to_json_string_ext( | |
10519 | json, JSON_C_TO_STRING_PRETTY)); | |
10520 | json_object_free(json); | |
10521 | } else | |
10522 | vty_out(vty, "%% OSPF instance not found\n"); | |
10523 | ||
10524 | return CMD_SUCCESS; | |
10525 | } | |
10526 | ||
10527 | ospf_show_gr_helper_details(vty, ospf, use_vrf, json, uj, | |
10528 | detail); | |
10529 | } | |
10530 | ||
10531 | if (uj) { | |
10532 | vty_out(vty, "%s\n", json_object_to_json_string_ext( | |
10533 | json, JSON_C_TO_STRING_PRETTY)); | |
10534 | json_object_free(json); | |
10535 | } | |
10536 | ||
10537 | return CMD_SUCCESS; | |
10538 | } | |
07b33add | 10539 | /* Graceful Restart HELPER commands end */ |
423e71c4 | 10540 | DEFUN (no_ospf_route_aggregation_timer, |
10541 | no_ospf_route_aggregation_timer_cmd, | |
10542 | "no aggregation timer", | |
10543 | NO_STR | |
10544 | "External route aggregation\n" | |
10545 | "Delay timer\n") | |
10546 | { | |
10547 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
10548 | ||
10549 | ospf_external_aggregator_timer_set(ospf, OSPF_EXTL_AGGR_DEFAULT_DELAY); | |
10550 | ||
10551 | return CMD_SUCCESS; | |
10552 | } | |
10553 | ||
10554 | /* External Route Aggregation End */ | |
07b33add | 10555 | |
d62a17ae | 10556 | static void config_write_stub_router(struct vty *vty, struct ospf *ospf) |
10557 | { | |
10558 | struct listnode *ln; | |
10559 | struct ospf_area *area; | |
10560 | ||
10561 | if (ospf->stub_router_startup_time != OSPF_STUB_ROUTER_UNCONFIGURED) | |
10562 | vty_out(vty, " max-metric router-lsa on-startup %u\n", | |
10563 | ospf->stub_router_startup_time); | |
10564 | if (ospf->stub_router_shutdown_time != OSPF_STUB_ROUTER_UNCONFIGURED) | |
10565 | vty_out(vty, " max-metric router-lsa on-shutdown %u\n", | |
10566 | ospf->stub_router_shutdown_time); | |
10567 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, ln, area)) { | |
10568 | if (CHECK_FLAG(area->stub_router_state, | |
10569 | OSPF_AREA_ADMIN_STUB_ROUTED)) { | |
10570 | vty_out(vty, " max-metric router-lsa administrative\n"); | |
10571 | break; | |
10572 | } | |
10573 | } | |
10574 | return; | |
10575 | } | |
10576 | ||
b5a8894d | 10577 | static void show_ip_ospf_route_network(struct vty *vty, struct ospf *ospf, |
0f478e30 CS |
10578 | struct route_table *rt, |
10579 | json_object *json) | |
d62a17ae | 10580 | { |
10581 | struct route_node *rn; | |
10582 | struct ospf_route * or ; | |
10583 | struct listnode *pnode, *pnnode; | |
10584 | struct ospf_path *path; | |
96b663a3 | 10585 | char buf[PREFIX_STRLEN]; |
0f478e30 CS |
10586 | json_object *json_route = NULL, *json_nexthop_array = NULL, |
10587 | *json_nexthop = NULL; | |
d62a17ae | 10588 | |
0f478e30 | 10589 | if (!json) |
996c9314 LB |
10590 | vty_out(vty, |
10591 | "============ OSPF network routing table ============\n"); | |
d62a17ae | 10592 | |
0f478e30 | 10593 | for (rn = route_top(rt); rn; rn = route_next(rn)) { |
96b663a3 MS |
10594 | char buf1[PREFIX2STR_BUFFER]; |
10595 | ||
0f478e30 CS |
10596 | if ((or = rn->info) == NULL) |
10597 | continue; | |
0f478e30 | 10598 | |
0f478e30 CS |
10599 | prefix2str(&rn->p, buf1, sizeof(buf1)); |
10600 | ||
10601 | json_route = json_object_new_object(); | |
10602 | if (json) { | |
996c9314 LB |
10603 | json_object_object_add(json, buf1, json_route); |
10604 | json_object_to_json_string_ext( | |
10605 | json, JSON_C_TO_STRING_NOSLASHESCAPE); | |
0f478e30 CS |
10606 | } |
10607 | ||
10608 | switch (or->path_type) { | |
10609 | case OSPF_PATH_INTER_AREA: | |
10610 | if (or->type == OSPF_DESTINATION_NETWORK) { | |
10611 | if (json) { | |
10612 | json_object_string_add(json_route, | |
996c9314 LB |
10613 | "routeType", |
10614 | "N IA"); | |
10615 | json_object_int_add(json_route, "cost", | |
0f478e30 CS |
10616 | or->cost); |
10617 | json_object_string_add( | |
996c9314 | 10618 | json_route, "area", |
96b663a3 MS |
10619 | inet_ntop(AF_INET, |
10620 | &or->u.std.area_id, | |
10621 | buf1, sizeof(buf1))); | |
0f478e30 | 10622 | } else { |
d62a17ae | 10623 | vty_out(vty, |
96b663a3 | 10624 | "N IA %-18s [%d] area: %pI4\n", |
d62a17ae | 10625 | buf1, or->cost, |
96b663a3 | 10626 | &or->u.std.area_id); |
0f478e30 | 10627 | } |
996c9314 | 10628 | } else if (or->type == OSPF_DESTINATION_DISCARD) { |
0f478e30 CS |
10629 | if (json) { |
10630 | json_object_string_add(json_route, | |
996c9314 LB |
10631 | "routeType", |
10632 | "D IA"); | |
0f478e30 | 10633 | } else { |
d62a17ae | 10634 | vty_out(vty, |
10635 | "D IA %-18s Discard entry\n", | |
10636 | buf1); | |
0f478e30 CS |
10637 | } |
10638 | } | |
10639 | break; | |
10640 | case OSPF_PATH_INTRA_AREA: | |
10641 | if (json) { | |
996c9314 LB |
10642 | json_object_string_add(json_route, "routeType", |
10643 | "N"); | |
0f478e30 | 10644 | json_object_int_add(json_route, "cost", |
996c9314 LB |
10645 | or->cost); |
10646 | json_object_string_add( | |
10647 | json_route, "area", | |
96b663a3 MS |
10648 | inet_ntop(AF_INET, &or->u.std.area_id, |
10649 | buf1, sizeof(buf1))); | |
0f478e30 | 10650 | } else { |
96b663a3 | 10651 | vty_out(vty, "N %-18s [%d] area: %pI4\n", |
d62a17ae | 10652 | buf1, or->cost, |
96b663a3 | 10653 | &or->u.std.area_id); |
0f478e30 CS |
10654 | } |
10655 | break; | |
10656 | default: | |
10657 | break; | |
10658 | } | |
10659 | ||
10660 | if (or->type == OSPF_DESTINATION_NETWORK) { | |
10661 | if (json) { | |
10662 | json_nexthop_array = json_object_new_array(); | |
10663 | json_object_object_add(json_route, "nexthops", | |
996c9314 | 10664 | json_nexthop_array); |
d62a17ae | 10665 | } |
10666 | ||
0f478e30 CS |
10667 | for (ALL_LIST_ELEMENTS(or->paths, pnode, pnnode, |
10668 | path)) { | |
10669 | if (json) { | |
996c9314 LB |
10670 | json_nexthop = json_object_new_object(); |
10671 | json_object_array_add( | |
10672 | json_nexthop_array, | |
10673 | json_nexthop); | |
0f478e30 CS |
10674 | } |
10675 | if (if_lookup_by_index(path->ifindex, | |
10676 | ospf->vrf_id)) { | |
10677 | ||
3a6290bd DA |
10678 | if (path->nexthop.s_addr |
10679 | == INADDR_ANY) { | |
0f478e30 CS |
10680 | if (json) { |
10681 | json_object_string_add( | |
10682 | json_nexthop, | |
996c9314 | 10683 | "ip", " "); |
0f478e30 CS |
10684 | json_object_string_add( |
10685 | json_nexthop, | |
10686 | "directly attached to", | |
d62a17ae | 10687 | ifindex2ifname( |
996c9314 LB |
10688 | path->ifindex, |
10689 | ospf->vrf_id)); | |
0f478e30 | 10690 | } else { |
d62a17ae | 10691 | vty_out(vty, |
996c9314 LB |
10692 | "%24s directly attached to %s\n", |
10693 | "", | |
10694 | ifindex2ifname( | |
10695 | path->ifindex, | |
10696 | ospf->vrf_id)); | |
0f478e30 CS |
10697 | } |
10698 | } else { | |
10699 | if (json) { | |
10700 | json_object_string_add( | |
10701 | json_nexthop, | |
10702 | "ip", | |
96b663a3 MS |
10703 | inet_ntop( |
10704 | AF_INET, | |
10705 | &path->nexthop, | |
10706 | buf, | |
10707 | sizeof(buf))); | |
0f478e30 CS |
10708 | json_object_string_add( |
10709 | json_nexthop, | |
10710 | "via", | |
d62a17ae | 10711 | ifindex2ifname( |
996c9314 LB |
10712 | path->ifindex, |
10713 | ospf->vrf_id)); | |
0f478e30 CS |
10714 | } else { |
10715 | vty_out(vty, | |
96b663a3 | 10716 | "%24s via %pI4, %s\n", |
996c9314 | 10717 | "", |
96b663a3 | 10718 | &path->nexthop, |
996c9314 LB |
10719 | ifindex2ifname( |
10720 | path->ifindex, | |
10721 | ospf->vrf_id)); | |
0f478e30 | 10722 | } |
d62a17ae | 10723 | } |
10724 | } | |
0f478e30 | 10725 | } |
d62a17ae | 10726 | } |
0f478e30 CS |
10727 | if (!json) |
10728 | json_object_free(json_route); | |
10729 | } | |
10730 | if (!json) | |
10731 | vty_out(vty, "\n"); | |
d62a17ae | 10732 | } |
10733 | ||
b5a8894d | 10734 | static void show_ip_ospf_route_router(struct vty *vty, struct ospf *ospf, |
0f478e30 CS |
10735 | struct route_table *rtrs, |
10736 | json_object *json) | |
d62a17ae | 10737 | { |
10738 | struct route_node *rn; | |
10739 | struct ospf_route * or ; | |
10740 | struct listnode *pnode; | |
10741 | struct listnode *node; | |
10742 | struct ospf_path *path; | |
96b663a3 | 10743 | char buf[PREFIX_STRLEN]; |
0f478e30 CS |
10744 | json_object *json_route = NULL, *json_nexthop_array = NULL, |
10745 | *json_nexthop = NULL; | |
d62a17ae | 10746 | |
0f478e30 | 10747 | if (!json) |
996c9314 LB |
10748 | vty_out(vty, |
10749 | "============ OSPF router routing table =============\n"); | |
d62a17ae | 10750 | |
0f478e30 CS |
10751 | for (rn = route_top(rtrs); rn; rn = route_next(rn)) { |
10752 | if (rn->info == NULL) | |
10753 | continue; | |
10754 | int flag = 0; | |
10755 | ||
10756 | json_route = json_object_new_object(); | |
10757 | if (json) { | |
96b663a3 MS |
10758 | json_object_object_add( |
10759 | json, inet_ntop(AF_INET, &rn->p.u.prefix4, | |
10760 | buf, sizeof(buf)), | |
10761 | json_route); | |
996c9314 | 10762 | json_object_string_add(json_route, "routeType", "R "); |
0f478e30 | 10763 | } else { |
96b663a3 MS |
10764 | vty_out(vty, "R %-15pI4 ", |
10765 | &rn->p.u.prefix4); | |
0f478e30 | 10766 | } |
d62a17ae | 10767 | |
996c9314 | 10768 | for (ALL_LIST_ELEMENTS_RO((struct list *)rn->info, node, or)) { |
0f478e30 CS |
10769 | if (flag++) { |
10770 | if (!json) | |
d62a17ae | 10771 | vty_out(vty, "%24s", ""); |
0f478e30 | 10772 | } |
d62a17ae | 10773 | |
0f478e30 CS |
10774 | /* Show path. */ |
10775 | if (json) { | |
10776 | json_object_int_add(json_route, "cost", | |
10777 | or->cost); | |
996c9314 LB |
10778 | json_object_string_add( |
10779 | json_route, "area", | |
96b663a3 MS |
10780 | inet_ntop(AF_INET, &or->u.std.area_id, |
10781 | buf, sizeof(buf))); | |
996c9314 LB |
10782 | if (or->path_type == OSPF_PATH_INTER_AREA) |
10783 | json_object_boolean_true_add(json_route, | |
10784 | "IA"); | |
0f478e30 | 10785 | if (or->u.std.flags & ROUTER_LSA_BORDER) |
996c9314 LB |
10786 | json_object_string_add(json_route, |
10787 | "routerType", | |
10788 | "abr"); | |
10789 | else if (or->u.std.flags & ROUTER_LSA_EXTERNAL) | |
10790 | json_object_string_add(json_route, | |
10791 | "routerType", | |
10792 | "asbr"); | |
0f478e30 | 10793 | } else { |
96b663a3 | 10794 | vty_out(vty, "%s [%d] area: %pI4", |
996c9314 LB |
10795 | (or->path_type == OSPF_PATH_INTER_AREA |
10796 | ? "IA" | |
10797 | : " "), | |
96b663a3 | 10798 | or->cost, &or->u.std.area_id); |
d62a17ae | 10799 | /* Show flags. */ |
10800 | vty_out(vty, "%s%s\n", | |
996c9314 LB |
10801 | (or->u.std.flags & ROUTER_LSA_BORDER |
10802 | ? ", ABR" | |
10803 | : ""), | |
10804 | (or->u.std.flags & ROUTER_LSA_EXTERNAL | |
10805 | ? ", ASBR" | |
10806 | : "")); | |
0f478e30 CS |
10807 | } |
10808 | ||
10809 | if (json) { | |
996c9314 | 10810 | json_nexthop_array = json_object_new_array(); |
0f478e30 | 10811 | json_object_object_add(json_route, "nexthops", |
996c9314 | 10812 | json_nexthop_array); |
0f478e30 CS |
10813 | } |
10814 | ||
996c9314 | 10815 | for (ALL_LIST_ELEMENTS_RO(or->paths, pnode, path)) { |
0f478e30 | 10816 | if (json) { |
996c9314 | 10817 | json_nexthop = json_object_new_object(); |
0f478e30 CS |
10818 | json_object_array_add( |
10819 | json_nexthop_array, | |
10820 | json_nexthop); | |
10821 | } | |
10822 | if (if_lookup_by_index(path->ifindex, | |
10823 | ospf->vrf_id)) { | |
3a6290bd DA |
10824 | if (path->nexthop.s_addr |
10825 | == INADDR_ANY) { | |
0f478e30 CS |
10826 | if (json) { |
10827 | json_object_string_add( | |
10828 | json_nexthop, | |
996c9314 | 10829 | "ip", " "); |
0f478e30 CS |
10830 | json_object_string_add( |
10831 | json_nexthop, | |
10832 | "directly attached to", | |
d62a17ae | 10833 | ifindex2ifname( |
10834 | path->ifindex, | |
b5a8894d | 10835 | ospf->vrf_id)); |
0f478e30 | 10836 | } else { |
d62a17ae | 10837 | vty_out(vty, |
996c9314 LB |
10838 | "%24s directly attached to %s\n", |
10839 | "", | |
10840 | ifindex2ifname( | |
10841 | path->ifindex, | |
10842 | ospf->vrf_id)); | |
0f478e30 CS |
10843 | } |
10844 | } else { | |
10845 | if (json) { | |
10846 | json_object_string_add( | |
10847 | json_nexthop, | |
10848 | "ip", | |
96b663a3 MS |
10849 | inet_ntop( |
10850 | AF_INET, | |
10851 | &path->nexthop, | |
10852 | buf, sizeof(buf))); | |
0f478e30 CS |
10853 | json_object_string_add( |
10854 | json_nexthop, | |
10855 | "via", | |
d62a17ae | 10856 | ifindex2ifname( |
10857 | path->ifindex, | |
b5a8894d | 10858 | ospf->vrf_id)); |
0f478e30 CS |
10859 | } else { |
10860 | vty_out(vty, | |
96b663a3 | 10861 | "%24s via %pI4, %s\n", |
996c9314 | 10862 | "", |
96b663a3 | 10863 | &path->nexthop, |
996c9314 LB |
10864 | ifindex2ifname( |
10865 | path->ifindex, | |
10866 | ospf->vrf_id)); | |
0f478e30 | 10867 | } |
d62a17ae | 10868 | } |
10869 | } | |
10870 | } | |
10871 | } | |
0f478e30 CS |
10872 | if (!json) |
10873 | json_object_free(json_route); | |
10874 | } | |
10875 | if (!json) | |
10876 | vty_out(vty, "\n"); | |
d62a17ae | 10877 | } |
10878 | ||
b5a8894d | 10879 | static void show_ip_ospf_route_external(struct vty *vty, struct ospf *ospf, |
0f478e30 CS |
10880 | struct route_table *rt, |
10881 | json_object *json) | |
d62a17ae | 10882 | { |
10883 | struct route_node *rn; | |
10884 | struct ospf_route *er; | |
10885 | struct listnode *pnode, *pnnode; | |
10886 | struct ospf_path *path; | |
96b663a3 | 10887 | char buf[PREFIX_STRLEN]; |
0f478e30 CS |
10888 | json_object *json_route = NULL, *json_nexthop_array = NULL, |
10889 | *json_nexthop = NULL; | |
d62a17ae | 10890 | |
0f478e30 | 10891 | if (!json) |
996c9314 LB |
10892 | vty_out(vty, |
10893 | "============ OSPF external routing table ===========\n"); | |
0f478e30 CS |
10894 | |
10895 | for (rn = route_top(rt); rn; rn = route_next(rn)) { | |
10896 | if ((er = rn->info) == NULL) | |
10897 | continue; | |
10898 | ||
10899 | char buf1[19]; | |
10900 | ||
96b663a3 | 10901 | snprintfrr(buf1, sizeof(buf1), "%pFX", &rn->p); |
0f478e30 CS |
10902 | json_route = json_object_new_object(); |
10903 | if (json) { | |
996c9314 LB |
10904 | json_object_object_add(json, buf1, json_route); |
10905 | json_object_to_json_string_ext( | |
10906 | json, JSON_C_TO_STRING_NOSLASHESCAPE); | |
0f478e30 | 10907 | } |
d62a17ae | 10908 | |
0f478e30 CS |
10909 | switch (er->path_type) { |
10910 | case OSPF_PATH_TYPE1_EXTERNAL: | |
10911 | if (json) { | |
996c9314 | 10912 | json_object_string_add(json_route, "routeType", |
0f478e30 CS |
10913 | "N E1"); |
10914 | json_object_int_add(json_route, "cost", | |
996c9314 | 10915 | er->cost); |
67df3649 MR |
10916 | json_object_int_add(json_route, "tag", |
10917 | er->u.ext.tag); | |
0f478e30 | 10918 | } else { |
d62a17ae | 10919 | vty_out(vty, |
996c9314 LB |
10920 | "N E1 %-18s [%d] tag: %" ROUTE_TAG_PRI |
10921 | "\n", | |
10922 | buf1, er->cost, er->u.ext.tag); | |
0f478e30 CS |
10923 | } |
10924 | break; | |
10925 | case OSPF_PATH_TYPE2_EXTERNAL: | |
10926 | if (json) { | |
996c9314 | 10927 | json_object_string_add(json_route, "routeType", |
0f478e30 CS |
10928 | "N E2"); |
10929 | json_object_int_add(json_route, "cost", | |
996c9314 | 10930 | er->cost); |
67df3649 MR |
10931 | json_object_int_add(json_route, "type2cost", |
10932 | er->u.ext.type2_cost); | |
10933 | json_object_int_add(json_route, "tag", | |
10934 | er->u.ext.tag); | |
0f478e30 | 10935 | } else { |
d62a17ae | 10936 | vty_out(vty, |
996c9314 LB |
10937 | "N E2 %-18s [%d/%d] tag: %" ROUTE_TAG_PRI |
10938 | "\n", | |
10939 | buf1, er->cost, er->u.ext.type2_cost, | |
d62a17ae | 10940 | er->u.ext.tag); |
d62a17ae | 10941 | } |
0f478e30 CS |
10942 | break; |
10943 | } | |
d62a17ae | 10944 | |
0f478e30 CS |
10945 | if (json) { |
10946 | json_nexthop_array = json_object_new_array(); | |
10947 | json_object_object_add(json_route, "nexthops", | |
996c9314 | 10948 | json_nexthop_array); |
0f478e30 CS |
10949 | } |
10950 | ||
996c9314 | 10951 | for (ALL_LIST_ELEMENTS(er->paths, pnode, pnnode, path)) { |
0f478e30 CS |
10952 | if (json) { |
10953 | json_nexthop = json_object_new_object(); | |
996c9314 LB |
10954 | json_object_array_add(json_nexthop_array, |
10955 | json_nexthop); | |
0f478e30 CS |
10956 | } |
10957 | ||
996c9314 | 10958 | if (if_lookup_by_index(path->ifindex, ospf->vrf_id)) { |
3a6290bd | 10959 | if (path->nexthop.s_addr == INADDR_ANY) { |
0f478e30 CS |
10960 | if (json) { |
10961 | json_object_string_add( | |
996c9314 LB |
10962 | json_nexthop, "ip", |
10963 | " "); | |
0f478e30 CS |
10964 | json_object_string_add( |
10965 | json_nexthop, | |
10966 | "directly attached to", | |
d62a17ae | 10967 | ifindex2ifname( |
996c9314 LB |
10968 | path->ifindex, |
10969 | ospf->vrf_id)); | |
0f478e30 | 10970 | } else { |
d62a17ae | 10971 | vty_out(vty, |
996c9314 LB |
10972 | "%24s directly attached to %s\n", |
10973 | "", | |
10974 | ifindex2ifname( | |
10975 | path->ifindex, | |
10976 | ospf->vrf_id)); | |
0f478e30 CS |
10977 | } |
10978 | } else { | |
10979 | if (json) { | |
10980 | json_object_string_add( | |
996c9314 | 10981 | json_nexthop, "ip", |
96b663a3 MS |
10982 | inet_ntop( |
10983 | AF_INET, | |
10984 | &path->nexthop, | |
10985 | buf, | |
10986 | sizeof(buf))); | |
0f478e30 | 10987 | json_object_string_add( |
996c9314 | 10988 | json_nexthop, "via", |
d62a17ae | 10989 | ifindex2ifname( |
996c9314 LB |
10990 | path->ifindex, |
10991 | ospf->vrf_id)); | |
0f478e30 CS |
10992 | } else { |
10993 | vty_out(vty, | |
96b663a3 | 10994 | "%24s via %pI4, %s\n", |
996c9314 | 10995 | "", |
96b663a3 | 10996 | &path->nexthop, |
996c9314 LB |
10997 | ifindex2ifname( |
10998 | path->ifindex, | |
10999 | ospf->vrf_id)); | |
0f478e30 | 11000 | } |
d62a17ae | 11001 | } |
54bedb55 | 11002 | } |
d62a17ae | 11003 | } |
0f478e30 CS |
11004 | if (!json) |
11005 | json_object_free(json_route); | |
11006 | } | |
11007 | if (!json) | |
11008 | vty_out(vty, "\n"); | |
718e3744 | 11009 | } |
11010 | ||
d62a17ae | 11011 | static int show_ip_ospf_border_routers_common(struct vty *vty, |
d7c0a89a QY |
11012 | struct ospf *ospf, |
11013 | uint8_t use_vrf) | |
718e3744 | 11014 | { |
d62a17ae | 11015 | if (ospf->instance) |
11016 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
718e3744 | 11017 | |
b1c3ae8c | 11018 | ospf_show_vrf_name(ospf, vty, NULL, use_vrf); |
87bd50e8 | 11019 | |
d62a17ae | 11020 | if (ospf->new_table == NULL) { |
11021 | vty_out(vty, "No OSPF routing information exist\n"); | |
11022 | return CMD_SUCCESS; | |
11023 | } | |
718e3744 | 11024 | |
d62a17ae | 11025 | /* Show Network routes. |
11026 | show_ip_ospf_route_network (vty, ospf->new_table); */ | |
718e3744 | 11027 | |
d62a17ae | 11028 | /* Show Router routes. */ |
0f478e30 | 11029 | show_ip_ospf_route_router(vty, ospf, ospf->new_rtrs, NULL); |
718e3744 | 11030 | |
d62a17ae | 11031 | vty_out(vty, "\n"); |
7c8ff89e | 11032 | |
d62a17ae | 11033 | return CMD_SUCCESS; |
718e3744 | 11034 | } |
718e3744 | 11035 | |
7c8ff89e DS |
11036 | DEFUN (show_ip_ospf_border_routers, |
11037 | show_ip_ospf_border_routers_cmd, | |
b5a8894d | 11038 | "show ip ospf [vrf <NAME|all>] border-routers", |
718e3744 | 11039 | SHOW_STR |
11040 | IP_STR | |
11041 | "OSPF information\n" | |
b5a8894d CS |
11042 | VRF_CMD_HELP_STR |
11043 | "All VRFs\n" | |
7c8ff89e | 11044 | "Show all the ABR's and ASBR's\n") |
718e3744 | 11045 | { |
b5a8894d CS |
11046 | struct ospf *ospf = NULL; |
11047 | struct listnode *node = NULL; | |
11048 | char *vrf_name = NULL; | |
2951a7a4 | 11049 | bool all_vrf = false; |
b5a8894d CS |
11050 | int ret = CMD_SUCCESS; |
11051 | int inst = 0; | |
11052 | int idx_vrf = 0; | |
d7c0a89a | 11053 | uint8_t use_vrf = 0; |
68980084 | 11054 | |
43b8d1d8 | 11055 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
7c8ff89e | 11056 | |
b5a8894d | 11057 | if (vrf_name) { |
2951a7a4 | 11058 | bool ospf_output = false; |
874f58d8 | 11059 | |
b1c3ae8c | 11060 | use_vrf = 1; |
94d4c685 | 11061 | |
b5a8894d CS |
11062 | if (all_vrf) { |
11063 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
11064 | if (!ospf->oi_running) | |
11065 | continue; | |
b5a8894d | 11066 | |
2951a7a4 | 11067 | ospf_output = true; |
996c9314 LB |
11068 | ret = show_ip_ospf_border_routers_common( |
11069 | vty, ospf, use_vrf); | |
b5a8894d | 11070 | } |
9f049418 DS |
11071 | |
11072 | if (!ospf_output) | |
94d4c685 | 11073 | vty_out(vty, "%% OSPF instance not found\n"); |
b5a8894d CS |
11074 | } else { |
11075 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
9f049418 | 11076 | if (ospf == NULL || !ospf->oi_running) { |
94d4c685 | 11077 | vty_out(vty, "%% OSPF instance not found\n"); |
b5a8894d | 11078 | return CMD_SUCCESS; |
9f049418 | 11079 | } |
b5a8894d | 11080 | |
b1c3ae8c CS |
11081 | ret = show_ip_ospf_border_routers_common(vty, ospf, |
11082 | use_vrf); | |
b5a8894d CS |
11083 | } |
11084 | } else { | |
11085 | /* Display default ospf (instance 0) info */ | |
11086 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
9f049418 | 11087 | if (ospf == NULL || !ospf->oi_running) { |
94d4c685 | 11088 | vty_out(vty, "%% OSPF instance not found\n"); |
b5a8894d | 11089 | return CMD_SUCCESS; |
9f049418 DS |
11090 | } |
11091 | ||
b1c3ae8c | 11092 | ret = show_ip_ospf_border_routers_common(vty, ospf, use_vrf); |
b5a8894d CS |
11093 | } |
11094 | ||
11095 | return ret; | |
7c8ff89e DS |
11096 | } |
11097 | ||
11098 | DEFUN (show_ip_ospf_instance_border_routers, | |
11099 | show_ip_ospf_instance_border_routers_cmd, | |
6147e2c6 | 11100 | "show ip ospf (1-65535) border-routers", |
7c8ff89e DS |
11101 | SHOW_STR |
11102 | IP_STR | |
11103 | "OSPF information\n" | |
11104 | "Instance ID\n" | |
11105 | "Show all the ABR's and ASBR's\n") | |
11106 | { | |
d62a17ae | 11107 | int idx_number = 3; |
11108 | struct ospf *ospf; | |
d7c0a89a | 11109 | unsigned short instance = 0; |
7c8ff89e | 11110 | |
d62a17ae | 11111 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
409f98ab | 11112 | if (instance != ospf_instance) |
ac28e4ec CS |
11113 | return CMD_NOT_MY_INSTANCE; |
11114 | ||
409f98ab IR |
11115 | ospf = ospf_lookup_instance(instance); |
11116 | if (!ospf || !ospf->oi_running) | |
d62a17ae | 11117 | return CMD_SUCCESS; |
7c8ff89e | 11118 | |
b1c3ae8c | 11119 | return show_ip_ospf_border_routers_common(vty, ospf, 0); |
7c8ff89e DS |
11120 | } |
11121 | ||
b1c3ae8c | 11122 | static int show_ip_ospf_route_common(struct vty *vty, struct ospf *ospf, |
d7c0a89a | 11123 | json_object *json, uint8_t use_vrf) |
7c8ff89e | 11124 | { |
0f478e30 CS |
11125 | json_object *json_vrf = NULL; |
11126 | ||
d62a17ae | 11127 | if (ospf->instance) |
11128 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
718e3744 | 11129 | |
0f478e30 CS |
11130 | |
11131 | if (json) { | |
11132 | if (use_vrf) | |
11133 | json_vrf = json_object_new_object(); | |
11134 | else | |
11135 | json_vrf = json; | |
11136 | } | |
11137 | ||
11138 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); | |
87bd50e8 | 11139 | |
d62a17ae | 11140 | if (ospf->new_table == NULL) { |
11141 | vty_out(vty, "No OSPF routing information exist\n"); | |
11142 | return CMD_SUCCESS; | |
11143 | } | |
718e3744 | 11144 | |
d62a17ae | 11145 | /* Show Network routes. */ |
0f478e30 | 11146 | show_ip_ospf_route_network(vty, ospf, ospf->new_table, json_vrf); |
718e3744 | 11147 | |
d62a17ae | 11148 | /* Show Router routes. */ |
0f478e30 | 11149 | show_ip_ospf_route_router(vty, ospf, ospf->new_rtrs, json_vrf); |
718e3744 | 11150 | |
d62a17ae | 11151 | /* Show AS External routes. */ |
0f478e30 CS |
11152 | show_ip_ospf_route_external(vty, ospf, ospf->old_external_route, |
11153 | json_vrf); | |
718e3744 | 11154 | |
0f478e30 CS |
11155 | if (json) { |
11156 | if (use_vrf) { | |
996c9314 LB |
11157 | // json_object_object_add(json_vrf, "areas", |
11158 | // json_areas); | |
0f478e30 CS |
11159 | if (ospf->vrf_id == VRF_DEFAULT) |
11160 | json_object_object_add(json, "default", | |
11161 | json_vrf); | |
11162 | else | |
11163 | json_object_object_add(json, ospf->name, | |
11164 | json_vrf); | |
11165 | } | |
11166 | } else { | |
11167 | vty_out(vty, "\n"); | |
11168 | } | |
7c8ff89e | 11169 | |
d62a17ae | 11170 | return CMD_SUCCESS; |
718e3744 | 11171 | } |
11172 | ||
7c8ff89e DS |
11173 | DEFUN (show_ip_ospf_route, |
11174 | show_ip_ospf_route_cmd, | |
0f478e30 | 11175 | "show ip ospf [vrf <NAME|all>] route [json]", |
b5a8894d CS |
11176 | SHOW_STR |
11177 | IP_STR | |
11178 | "OSPF information\n" | |
11179 | VRF_CMD_HELP_STR | |
11180 | "All VRFs\n" | |
0f478e30 CS |
11181 | "OSPF routing table\n" |
11182 | JSON_STR) | |
b5a8894d CS |
11183 | { |
11184 | struct ospf *ospf = NULL; | |
11185 | struct listnode *node = NULL; | |
11186 | char *vrf_name = NULL; | |
2951a7a4 | 11187 | bool all_vrf = false; |
b5a8894d CS |
11188 | int ret = CMD_SUCCESS; |
11189 | int inst = 0; | |
11190 | int idx_vrf = 0; | |
d7c0a89a | 11191 | uint8_t use_vrf = 0; |
9f049418 | 11192 | bool uj = use_json(argc, argv); |
0f478e30 CS |
11193 | json_object *json = NULL; |
11194 | ||
11195 | if (uj) | |
11196 | json = json_object_new_object(); | |
7c8ff89e | 11197 | |
43b8d1d8 | 11198 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
7c8ff89e | 11199 | |
b5a8894d CS |
11200 | /* vrf input is provided could be all or specific vrf*/ |
11201 | if (vrf_name) { | |
2951a7a4 | 11202 | bool ospf_output = false; |
874f58d8 | 11203 | |
b1c3ae8c | 11204 | use_vrf = 1; |
94d4c685 | 11205 | |
b5a8894d CS |
11206 | if (all_vrf) { |
11207 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
11208 | if (!ospf->oi_running) | |
11209 | continue; | |
2951a7a4 | 11210 | ospf_output = true; |
0f478e30 | 11211 | ret = show_ip_ospf_route_common(vty, ospf, json, |
b1c3ae8c | 11212 | use_vrf); |
b5a8894d | 11213 | } |
0f478e30 CS |
11214 | |
11215 | if (uj) { | |
1406159f | 11216 | /* Keep Non-pretty format */ |
0f478e30 | 11217 | vty_out(vty, "%s\n", |
1406159f | 11218 | json_object_to_json_string(json)); |
0f478e30 | 11219 | json_object_free(json); |
9f049418 DS |
11220 | } else if (!ospf_output) |
11221 | vty_out(vty, "%% OSPF instance not found\n"); | |
0f478e30 | 11222 | |
b5a8894d CS |
11223 | return ret; |
11224 | } | |
11225 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
0f478e30 | 11226 | if (ospf == NULL || !ospf->oi_running) { |
9f049418 DS |
11227 | if (uj) { |
11228 | vty_out(vty, "%s\n", | |
11229 | json_object_to_json_string_ext( | |
11230 | json, JSON_C_TO_STRING_PRETTY)); | |
0f478e30 | 11231 | json_object_free(json); |
9f049418 | 11232 | } else |
94d4c685 | 11233 | vty_out(vty, "%% OSPF instance not found\n"); |
9f049418 | 11234 | |
b5a8894d | 11235 | return CMD_SUCCESS; |
0f478e30 | 11236 | } |
b5a8894d CS |
11237 | } else { |
11238 | /* Display default ospf (instance 0) info */ | |
11239 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
0f478e30 | 11240 | if (ospf == NULL || !ospf->oi_running) { |
9f049418 DS |
11241 | if (uj) { |
11242 | vty_out(vty, "%s\n", | |
11243 | json_object_to_json_string_ext( | |
11244 | json, JSON_C_TO_STRING_PRETTY)); | |
0f478e30 | 11245 | json_object_free(json); |
9f049418 | 11246 | } else |
94d4c685 | 11247 | vty_out(vty, "%% OSPF instance not found\n"); |
9f049418 | 11248 | |
b5a8894d | 11249 | return CMD_SUCCESS; |
0f478e30 CS |
11250 | } |
11251 | } | |
11252 | ||
11253 | if (ospf) { | |
11254 | ret = show_ip_ospf_route_common(vty, ospf, json, use_vrf); | |
1406159f | 11255 | /* Keep Non-pretty format */ |
0f478e30 | 11256 | if (uj) |
1406159f | 11257 | vty_out(vty, "%s\n", json_object_to_json_string(json)); |
b5a8894d CS |
11258 | } |
11259 | ||
0f478e30 CS |
11260 | if (uj) |
11261 | json_object_free(json); | |
b5a8894d CS |
11262 | |
11263 | return ret; | |
7c8ff89e DS |
11264 | } |
11265 | ||
11266 | DEFUN (show_ip_ospf_instance_route, | |
11267 | show_ip_ospf_instance_route_cmd, | |
6147e2c6 | 11268 | "show ip ospf (1-65535) route", |
7c8ff89e DS |
11269 | SHOW_STR |
11270 | IP_STR | |
11271 | "OSPF information\n" | |
11272 | "Instance ID\n" | |
11273 | "OSPF routing table\n") | |
11274 | { | |
d62a17ae | 11275 | int idx_number = 3; |
11276 | struct ospf *ospf; | |
d7c0a89a | 11277 | unsigned short instance = 0; |
7c8ff89e | 11278 | |
d62a17ae | 11279 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
409f98ab | 11280 | if (instance != ospf_instance) |
ac28e4ec CS |
11281 | return CMD_NOT_MY_INSTANCE; |
11282 | ||
409f98ab IR |
11283 | ospf = ospf_lookup_instance(instance); |
11284 | if (!ospf || !ospf->oi_running) | |
d62a17ae | 11285 | return CMD_SUCCESS; |
7c8ff89e | 11286 | |
0f478e30 | 11287 | return show_ip_ospf_route_common(vty, ospf, NULL, 0); |
7c8ff89e | 11288 | } |
6b0655a2 | 11289 | |
b5a8894d CS |
11290 | |
11291 | DEFUN (show_ip_ospf_vrfs, | |
11292 | show_ip_ospf_vrfs_cmd, | |
11293 | "show ip ospf vrfs [json]", | |
11294 | SHOW_STR | |
11295 | IP_STR | |
11296 | "OSPF information\n" | |
11297 | "Show OSPF VRFs \n" | |
11298 | JSON_STR) | |
11299 | { | |
9f049418 | 11300 | bool uj = use_json(argc, argv); |
b5a8894d CS |
11301 | json_object *json = NULL; |
11302 | json_object *json_vrfs = NULL; | |
11303 | struct ospf *ospf = NULL; | |
11304 | struct listnode *node = NULL; | |
11305 | int count = 0; | |
96b663a3 | 11306 | char buf[PREFIX_STRLEN]; |
2b64873d | 11307 | static const char header[] = "Name Id RouterId "; |
b5a8894d CS |
11308 | |
11309 | if (uj) { | |
11310 | json = json_object_new_object(); | |
11311 | json_vrfs = json_object_new_object(); | |
11312 | } | |
11313 | ||
11314 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
11315 | json_object *json_vrf = NULL; | |
11316 | const char *name = NULL; | |
fe3da9e7 | 11317 | int64_t vrf_id_ui = 0; |
b5a8894d CS |
11318 | |
11319 | count++; | |
11320 | ||
11321 | if (!uj && count == 1) | |
11322 | vty_out(vty, "%s\n", header); | |
11323 | if (uj) | |
11324 | json_vrf = json_object_new_object(); | |
11325 | ||
946de1b9 | 11326 | if (ospf->vrf_id == VRF_DEFAULT) |
b5a8894d CS |
11327 | name = VRF_DEFAULT_NAME; |
11328 | else | |
11329 | name = ospf->name; | |
11330 | ||
996c9314 LB |
11331 | vrf_id_ui = (ospf->vrf_id == VRF_UNKNOWN) |
11332 | ? -1 | |
11333 | : (int64_t)ospf->vrf_id; | |
b5a8894d CS |
11334 | |
11335 | if (uj) { | |
11336 | json_object_int_add(json_vrf, "vrfId", vrf_id_ui); | |
96b663a3 MS |
11337 | json_object_string_add( |
11338 | json_vrf, "routerId", | |
11339 | inet_ntop(AF_INET, &ospf->router_id, | |
11340 | buf, sizeof(buf))); | |
b5a8894d CS |
11341 | |
11342 | json_object_object_add(json_vrfs, name, json_vrf); | |
11343 | ||
11344 | } else { | |
96b663a3 MS |
11345 | vty_out(vty, "%-25s %-5d %-16pI4 \n", name, |
11346 | ospf->vrf_id, &ospf->router_id); | |
b5a8894d CS |
11347 | } |
11348 | } | |
11349 | ||
11350 | if (uj) { | |
11351 | json_object_object_add(json, "vrfs", json_vrfs); | |
11352 | json_object_int_add(json, "totalVrfs", count); | |
11353 | ||
996c9314 LB |
11354 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
11355 | json, JSON_C_TO_STRING_PRETTY)); | |
b5a8894d CS |
11356 | json_object_free(json); |
11357 | } else { | |
11358 | if (count) | |
34d6798f | 11359 | vty_out(vty, "\nTotal number of OSPF VRFs: %d\n", |
b5a8894d CS |
11360 | count); |
11361 | } | |
11362 | ||
11363 | return CMD_SUCCESS; | |
11364 | } | |
f91ce319 MR |
11365 | DEFPY (clear_ip_ospf_neighbor, |
11366 | clear_ip_ospf_neighbor_cmd, | |
11367 | "clear ip ospf [(1-65535)]$instance neighbor [A.B.C.D$nbr_id]", | |
11368 | CLEAR_STR | |
11369 | IP_STR | |
11370 | "OSPF information\n" | |
11371 | "Instance ID\n" | |
11372 | "Reset OSPF Neighbor\n" | |
11373 | "Neighbor ID\n") | |
11374 | { | |
11375 | struct listnode *node; | |
11376 | struct ospf *ospf = NULL; | |
11377 | ||
11378 | /* If user does not specify the arguments, | |
11379 | * instance = 0 and nbr_id = 0.0.0.0 | |
11380 | */ | |
11381 | if (instance != 0) { | |
11382 | /* This means clear only the particular ospf process */ | |
409f98ab | 11383 | if (instance != ospf_instance) |
f91ce319 MR |
11384 | return CMD_NOT_MY_INSTANCE; |
11385 | } | |
11386 | ||
11387 | /* Clear all the ospf processes */ | |
11388 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
11389 | if (!ospf->oi_running) | |
11390 | continue; | |
11391 | ||
c88ad8ec | 11392 | if (nbr_id_str && IPV4_ADDR_SAME(&ospf->router_id, &nbr_id)) { |
11393 | vty_out(vty, "Self router-id is not allowed.\r\n "); | |
11394 | return CMD_SUCCESS; | |
11395 | } | |
11396 | ||
f91ce319 MR |
11397 | ospf_neighbor_reset(ospf, nbr_id, nbr_id_str); |
11398 | } | |
11399 | ||
11400 | return CMD_SUCCESS; | |
11401 | } | |
11402 | ||
11403 | DEFPY (clear_ip_ospf_process, | |
11404 | clear_ip_ospf_process_cmd, | |
11405 | "clear ip ospf [(1-65535)]$instance process", | |
11406 | CLEAR_STR | |
11407 | IP_STR | |
11408 | "OSPF information\n" | |
11409 | "Instance ID\n" | |
11410 | "Reset OSPF Process\n") | |
11411 | { | |
11412 | struct listnode *node; | |
11413 | struct ospf *ospf = NULL; | |
11414 | ||
11415 | /* Check if instance is not passed as an argument */ | |
11416 | if (instance != 0) { | |
11417 | /* This means clear only the particular ospf process */ | |
409f98ab | 11418 | if (instance != ospf_instance) |
f91ce319 MR |
11419 | return CMD_NOT_MY_INSTANCE; |
11420 | } | |
11421 | ||
11422 | /* Clear all the ospf processes */ | |
11423 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
11424 | if (!ospf->oi_running) | |
11425 | continue; | |
11426 | ||
11427 | ospf_process_reset(ospf); | |
11428 | } | |
11429 | ||
11430 | return CMD_SUCCESS; | |
11431 | } | |
b5a8894d | 11432 | |
2b64873d DL |
11433 | static const char *const ospf_abr_type_str[] = { |
11434 | "unknown", "standard", "ibm", "cisco", "shortcut" | |
11435 | }; | |
718e3744 | 11436 | |
2b64873d DL |
11437 | static const char *const ospf_shortcut_mode_str[] = { |
11438 | "default", "enable", "disable" | |
11439 | }; | |
1ac88792 | 11440 | static int ospf_vty_external_rt_walkcb(struct hash_bucket *bucket, |
53e44d05 | 11441 | void *arg) |
11442 | { | |
1ac88792 | 11443 | struct external_info *ei = bucket->data; |
53e44d05 | 11444 | struct vty *vty = (struct vty *)arg; |
11445 | static unsigned int count; | |
11446 | ||
11447 | vty_out(vty, "%-4pI4/%d, ", &ei->p.prefix, ei->p.prefixlen); | |
11448 | count++; | |
11449 | ||
11450 | if (count % 5 == 0) | |
11451 | vty_out(vty, "\n"); | |
11452 | ||
11453 | if (OSPF_EXTERNAL_RT_COUNT(ei->aggr_route) == count) | |
11454 | count = 0; | |
11455 | ||
11456 | return HASHWALK_CONTINUE; | |
11457 | } | |
11458 | ||
1ac88792 | 11459 | static int ospf_json_external_rt_walkcb(struct hash_bucket *bucket, |
53e44d05 | 11460 | void *arg) |
11461 | { | |
1ac88792 | 11462 | struct external_info *ei = bucket->data; |
53e44d05 | 11463 | struct json_object *json = (struct json_object *)arg; |
11464 | char buf[PREFIX2STR_BUFFER]; | |
11465 | char exnalbuf[20]; | |
11466 | static unsigned int count; | |
11467 | ||
11468 | prefix2str(&ei->p, buf, sizeof(buf)); | |
11469 | ||
11470 | snprintf(exnalbuf, 20, "Exnl Addr-%d", count); | |
11471 | ||
11472 | json_object_string_add(json, exnalbuf, buf); | |
11473 | ||
11474 | count++; | |
11475 | ||
11476 | if (OSPF_EXTERNAL_RT_COUNT(ei->aggr_route) == count) | |
11477 | count = 0; | |
11478 | ||
11479 | return HASHWALK_CONTINUE; | |
11480 | } | |
11481 | ||
11482 | static int ospf_show_summary_address(struct vty *vty, struct ospf *ospf, | |
11483 | uint8_t use_vrf, json_object *json, | |
11484 | bool uj, bool detail) | |
11485 | { | |
11486 | struct route_node *rn; | |
11487 | json_object *json_vrf = NULL; | |
11488 | int mtype = 0; | |
11489 | int mval = 0; | |
11490 | static char header[] = | |
11491 | "Summary-address Metric-type Metric Tag External_Rt_count\n"; | |
11492 | ||
11493 | mtype = metric_type(ospf, 0, ospf->instance); | |
11494 | mval = metric_value(ospf, 0, ospf->instance); | |
11495 | ||
11496 | if (!uj) | |
11497 | vty_out(vty, "%s\n", header); | |
11498 | ||
11499 | if (uj) { | |
11500 | if (use_vrf) | |
11501 | json_vrf = json_object_new_object(); | |
11502 | else | |
11503 | json_vrf = json; | |
11504 | } | |
11505 | ||
11506 | if (ospf->instance) { | |
11507 | if (uj) | |
11508 | json_object_int_add(json, "ospfInstance", | |
11509 | ospf->instance); | |
11510 | else | |
11511 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
11512 | } | |
11513 | ||
11514 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); | |
11515 | ||
11516 | if (!uj) | |
11517 | vty_out(vty, "aggregation delay interval :%d(in seconds)\n\n", | |
11518 | ospf->aggr_delay_interval); | |
11519 | else | |
11520 | json_object_int_add(json_vrf, "aggregation delay interval", | |
11521 | ospf->aggr_delay_interval); | |
11522 | ||
11523 | for (rn = route_top(ospf->rt_aggr_tbl); rn; rn = route_next(rn)) | |
11524 | if (rn->info) { | |
11525 | struct ospf_external_aggr_rt *aggr = rn->info; | |
11526 | json_object *json_aggr = NULL; | |
11527 | char buf[PREFIX2STR_BUFFER]; | |
11528 | ||
11529 | prefix2str(&aggr->p, buf, sizeof(buf)); | |
11530 | ||
11531 | if (uj) { | |
11532 | ||
11533 | json_aggr = json_object_new_object(); | |
11534 | ||
11535 | json_object_object_add(json_vrf, buf, | |
11536 | json_aggr); | |
11537 | ||
11538 | json_object_string_add(json_aggr, | |
11539 | "Summary address", buf); | |
11540 | ||
11541 | json_object_string_add( | |
11542 | json_aggr, "Metric-type", | |
11543 | (mtype == EXTERNAL_METRIC_TYPE_1) | |
11544 | ? "E1" | |
11545 | : "E2"); | |
11546 | ||
11547 | json_object_int_add(json_aggr, "Metric", mval); | |
11548 | ||
11549 | json_object_int_add(json_aggr, "Tag", | |
11550 | aggr->tag); | |
11551 | ||
11552 | json_object_int_add( | |
11553 | json_aggr, "External route count", | |
11554 | OSPF_EXTERNAL_RT_COUNT(aggr)); | |
11555 | ||
11556 | if (OSPF_EXTERNAL_RT_COUNT(aggr) && detail) { | |
11557 | hash_walk( | |
11558 | aggr->match_extnl_hash, | |
11559 | ospf_json_external_rt_walkcb, | |
11560 | json_aggr); | |
11561 | } | |
11562 | ||
11563 | } else { | |
11564 | vty_out(vty, "%-20s", buf); | |
11565 | ||
11566 | (mtype == EXTERNAL_METRIC_TYPE_1) | |
11567 | ? vty_out(vty, "%-16s", "E1") | |
11568 | : vty_out(vty, "%-16s", "E2"); | |
11569 | vty_out(vty, "%-11d", mval); | |
11570 | ||
11571 | vty_out(vty, "%-12u", aggr->tag); | |
11572 | ||
11573 | vty_out(vty, "%-5ld\n", | |
11574 | OSPF_EXTERNAL_RT_COUNT(aggr)); | |
11575 | ||
11576 | if (OSPF_EXTERNAL_RT_COUNT(aggr) && detail) { | |
11577 | vty_out(vty, | |
11578 | "Matched External routes:\n"); | |
11579 | hash_walk( | |
11580 | aggr->match_extnl_hash, | |
11581 | ospf_vty_external_rt_walkcb, | |
11582 | vty); | |
11583 | vty_out(vty, "\n"); | |
11584 | } | |
11585 | ||
11586 | vty_out(vty, "\n"); | |
11587 | } | |
11588 | } | |
11589 | ||
11590 | if (uj) { | |
11591 | if (use_vrf) { | |
11592 | if (ospf->vrf_id == VRF_DEFAULT) | |
11593 | json_object_object_add(json, "default", | |
11594 | json_vrf); | |
11595 | else | |
11596 | json_object_object_add(json, ospf->name, | |
11597 | json_vrf); | |
11598 | } | |
11599 | } else | |
11600 | vty_out(vty, "\n"); | |
11601 | ||
11602 | return CMD_SUCCESS; | |
11603 | } | |
11604 | ||
11605 | DEFUN (show_ip_ospf_external_aggregator, | |
11606 | show_ip_ospf_external_aggregator_cmd, | |
11607 | "show ip ospf [vrf <NAME|all>] summary-address [detail] [json]", | |
11608 | SHOW_STR IP_STR | |
11609 | "OSPF information\n" | |
11610 | VRF_CMD_HELP_STR | |
11611 | "All VRFs\n" | |
11612 | "Show external summary addresses\n" | |
11613 | "Detailed informtion\n" | |
11614 | JSON_STR) | |
11615 | { | |
11616 | char *vrf_name = NULL; | |
11617 | bool all_vrf = false; | |
11618 | int ret = CMD_SUCCESS; | |
11619 | int idx_vrf = 0; | |
11620 | int idx = 0; | |
11621 | uint8_t use_vrf = 0; | |
11622 | bool uj = use_json(argc, argv); | |
11623 | struct ospf *ospf = NULL; | |
11624 | json_object *json = NULL; | |
11625 | struct listnode *node = NULL; | |
11626 | int inst = 0; | |
11627 | bool detail = false; | |
11628 | ||
11629 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); | |
11630 | ||
11631 | if (argv_find(argv, argc, "detail", &idx)) | |
11632 | detail = true; | |
11633 | ||
11634 | if (uj) | |
11635 | json = json_object_new_object(); | |
11636 | ||
11637 | /* vrf input is provided */ | |
11638 | if (vrf_name) { | |
11639 | use_vrf = 1; | |
11640 | if (all_vrf) { | |
11641 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
11642 | if (!ospf->oi_running) | |
11643 | continue; | |
11644 | ret = ospf_show_summary_address( | |
11645 | vty, ospf, use_vrf, json, uj, detail); | |
11646 | } | |
11647 | ||
11648 | if (uj) { | |
11649 | vty_out(vty, "%s\n", | |
11650 | json_object_to_json_string_ext( | |
11651 | json, JSON_C_TO_STRING_PRETTY)); | |
11652 | json_object_free(json); | |
11653 | } | |
11654 | ||
11655 | return ret; | |
11656 | } | |
11657 | ||
11658 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
11659 | ||
11660 | if (ospf == NULL || !ospf->oi_running) { | |
11661 | if (uj) { | |
11662 | vty_out(vty, "%s\n", | |
11663 | json_object_to_json_string_ext( | |
11664 | json, JSON_C_TO_STRING_PRETTY)); | |
11665 | json_object_free(json); | |
11666 | } else | |
11667 | vty_out(vty, "%% OSPF instance not found\n"); | |
11668 | ||
11669 | return CMD_SUCCESS; | |
11670 | } | |
fddbafcc | 11671 | ospf_show_summary_address(vty, ospf, use_vrf, json, uj, detail); |
53e44d05 | 11672 | |
11673 | } else { | |
11674 | /* Default Vrf */ | |
11675 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
11676 | if (ospf == NULL || !ospf->oi_running) { | |
11677 | if (uj) { | |
11678 | vty_out(vty, "%s\n", | |
11679 | json_object_to_json_string_ext( | |
11680 | json, JSON_C_TO_STRING_PRETTY)); | |
11681 | json_object_free(json); | |
11682 | } else | |
11683 | vty_out(vty, "%% OSPF instance not found\n"); | |
11684 | ||
11685 | return CMD_SUCCESS; | |
11686 | } | |
11687 | ||
11688 | ospf_show_summary_address(vty, ospf, use_vrf, json, uj, detail); | |
11689 | } | |
11690 | ||
11691 | if (uj) { | |
11692 | vty_out(vty, "%s\n", json_object_to_json_string_ext( | |
11693 | json, JSON_C_TO_STRING_PRETTY)); | |
11694 | json_object_free(json); | |
11695 | } | |
11696 | return CMD_SUCCESS; | |
11697 | } | |
718e3744 | 11698 | |
2b64873d DL |
11699 | static const char *const ospf_int_type_str[] = { |
11700 | "unknown", /* should never be used. */ | |
11701 | "point-to-point", | |
11702 | "broadcast", | |
11703 | "non-broadcast", | |
11704 | "point-to-multipoint", | |
11705 | "virtual-link", /* should never be used. */ | |
11706 | "loopback" | |
11707 | }; | |
718e3744 | 11708 | |
83cc5a1f DE |
11709 | static const char *interface_config_auth_str(struct ospf_if_params *params) |
11710 | { | |
11711 | if (!OSPF_IF_PARAM_CONFIGURED(params, auth_type) | |
11712 | || params->auth_type == OSPF_AUTH_NOTSET) | |
11713 | return NULL; | |
11714 | ||
11715 | /* Translation tables are not that much help | |
11716 | * here due to syntax | |
11717 | * of the simple option */ | |
11718 | switch (params->auth_type) { | |
11719 | ||
11720 | case OSPF_AUTH_NULL: | |
11721 | return " null"; | |
11722 | ||
11723 | case OSPF_AUTH_SIMPLE: | |
11724 | return ""; | |
11725 | ||
11726 | case OSPF_AUTH_CRYPTOGRAPHIC: | |
11727 | return " message-digest"; | |
11728 | } | |
11729 | ||
11730 | return ""; | |
11731 | } | |
11732 | ||
545f0503 | 11733 | static int config_write_interface_one(struct vty *vty, struct vrf *vrf) |
d62a17ae | 11734 | { |
f4e14fdb | 11735 | struct listnode *node; |
d62a17ae | 11736 | struct interface *ifp; |
11737 | struct crypt_key *ck; | |
d62a17ae | 11738 | struct route_node *rn = NULL; |
11739 | struct ospf_if_params *params; | |
83cc5a1f | 11740 | const char *auth_str; |
43b8d1d8 | 11741 | int write = 0; |
d62a17ae | 11742 | |
545f0503 | 11743 | FOR_ALL_INTERFACES (vrf, ifp) { |
d62a17ae | 11744 | |
545f0503 CS |
11745 | if (memcmp(ifp->name, "VLINK", 5) == 0) |
11746 | continue; | |
35955c14 | 11747 | |
545f0503 | 11748 | vty_frame(vty, "!\n"); |
a36898e7 | 11749 | if (ifp->vrf_id == VRF_DEFAULT) |
545f0503 CS |
11750 | vty_frame(vty, "interface %s\n", ifp->name); |
11751 | else | |
996c9314 LB |
11752 | vty_frame(vty, "interface %s vrf %s\n", ifp->name, |
11753 | vrf->name); | |
545f0503 CS |
11754 | if (ifp->desc) |
11755 | vty_out(vty, " description %s\n", ifp->desc); | |
d62a17ae | 11756 | |
545f0503 | 11757 | write++; |
43b8d1d8 | 11758 | |
545f0503 | 11759 | params = IF_DEF_PARAMS(ifp); |
43b8d1d8 | 11760 | |
545f0503 CS |
11761 | do { |
11762 | /* Interface Network print. */ | |
11763 | if (OSPF_IF_PARAM_CONFIGURED(params, type) | |
11764 | && params->type != OSPF_IFTYPE_LOOPBACK) { | |
996c9314 | 11765 | if (params->type != ospf_default_iftype(ifp)) { |
545f0503 CS |
11766 | vty_out(vty, " ip ospf network %s", |
11767 | ospf_int_type_str | |
996c9314 | 11768 | [params->type]); |
bc97889b AL |
11769 | if (params->type |
11770 | == OSPF_IFTYPE_POINTOPOINT | |
11771 | && params->ptp_dmvpn) | |
11772 | vty_out(vty, " dmvpn"); | |
e425c019 | 11773 | if (params != IF_DEF_PARAMS(ifp) && rn) |
96b663a3 MS |
11774 | vty_out(vty, " %pI4", |
11775 | &rn->p.u.prefix4); | |
545f0503 | 11776 | vty_out(vty, "\n"); |
d62a17ae | 11777 | } |
545f0503 | 11778 | } |
d62a17ae | 11779 | |
545f0503 | 11780 | /* OSPF interface authentication print */ |
83cc5a1f DE |
11781 | auth_str = interface_config_auth_str(params); |
11782 | if (auth_str) { | |
545f0503 CS |
11783 | vty_out(vty, " ip ospf authentication%s", |
11784 | auth_str); | |
e425c019 | 11785 | if (params != IF_DEF_PARAMS(ifp) && rn) |
96b663a3 MS |
11786 | vty_out(vty, " %pI4", |
11787 | &rn->p.u.prefix4); | |
545f0503 CS |
11788 | vty_out(vty, "\n"); |
11789 | } | |
d62a17ae | 11790 | |
545f0503 CS |
11791 | /* Simple Authentication Password print. */ |
11792 | if (OSPF_IF_PARAM_CONFIGURED(params, auth_simple) | |
996c9314 | 11793 | && params->auth_simple[0] != '\0') { |
545f0503 CS |
11794 | vty_out(vty, " ip ospf authentication-key %s", |
11795 | params->auth_simple); | |
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 | } | |
c7fd72d2 | 11801 | |
545f0503 CS |
11802 | /* Cryptographic Authentication Key print. */ |
11803 | if (params && params->auth_crypt) { | |
996c9314 LB |
11804 | for (ALL_LIST_ELEMENTS_RO(params->auth_crypt, |
11805 | node, ck)) { | |
545f0503 CS |
11806 | vty_out(vty, |
11807 | " ip ospf message-digest-key %d md5 %s", | |
996c9314 | 11808 | ck->key_id, ck->auth_key); |
e425c019 | 11809 | if (params != IF_DEF_PARAMS(ifp) && rn) |
96b663a3 MS |
11810 | vty_out(vty, " %pI4", |
11811 | &rn->p.u.prefix4); | |
c7fd72d2 CS |
11812 | vty_out(vty, "\n"); |
11813 | } | |
545f0503 | 11814 | } |
d62a17ae | 11815 | |
545f0503 | 11816 | /* Interface Output Cost print. */ |
996c9314 | 11817 | if (OSPF_IF_PARAM_CONFIGURED(params, output_cost_cmd)) { |
545f0503 CS |
11818 | vty_out(vty, " ip ospf cost %u", |
11819 | params->output_cost_cmd); | |
e425c019 | 11820 | if (params != IF_DEF_PARAMS(ifp) && rn) |
96b663a3 MS |
11821 | vty_out(vty, " %pI4", |
11822 | &rn->p.u.prefix4); | |
545f0503 CS |
11823 | vty_out(vty, "\n"); |
11824 | } | |
d62a17ae | 11825 | |
545f0503 CS |
11826 | /* Hello Interval print. */ |
11827 | if (OSPF_IF_PARAM_CONFIGURED(params, v_hello) | |
996c9314 | 11828 | && params->v_hello != OSPF_HELLO_INTERVAL_DEFAULT) { |
545f0503 CS |
11829 | vty_out(vty, " ip ospf hello-interval %u", |
11830 | params->v_hello); | |
e425c019 | 11831 | if (params != IF_DEF_PARAMS(ifp) && rn) |
96b663a3 MS |
11832 | vty_out(vty, " %pI4", |
11833 | &rn->p.u.prefix4); | |
545f0503 CS |
11834 | vty_out(vty, "\n"); |
11835 | } | |
d62a17ae | 11836 | |
d62a17ae | 11837 | |
545f0503 CS |
11838 | /* Router Dead Interval print. */ |
11839 | if (OSPF_IF_PARAM_CONFIGURED(params, v_wait) | |
6dd632c6 | 11840 | && params->is_v_wait_set |
996c9314 LB |
11841 | && params->v_wait |
11842 | != OSPF_ROUTER_DEAD_INTERVAL_DEFAULT) { | |
545f0503 | 11843 | vty_out(vty, " ip ospf dead-interval "); |
d62a17ae | 11844 | |
545f0503 CS |
11845 | /* fast hello ? */ |
11846 | if (OSPF_IF_PARAM_CONFIGURED(params, | |
996c9314 | 11847 | fast_hello)) |
545f0503 CS |
11848 | vty_out(vty, |
11849 | "minimal hello-multiplier %d", | |
11850 | params->fast_hello); | |
11851 | else | |
996c9314 | 11852 | vty_out(vty, "%u", params->v_wait); |
d62a17ae | 11853 | |
e425c019 | 11854 | if (params != IF_DEF_PARAMS(ifp) && rn) |
96b663a3 MS |
11855 | vty_out(vty, " %pI4", |
11856 | &rn->p.u.prefix4); | |
545f0503 CS |
11857 | vty_out(vty, "\n"); |
11858 | } | |
d62a17ae | 11859 | |
545f0503 CS |
11860 | /* Router Priority print. */ |
11861 | if (OSPF_IF_PARAM_CONFIGURED(params, priority) | |
996c9314 LB |
11862 | && params->priority |
11863 | != OSPF_ROUTER_PRIORITY_DEFAULT) { | |
545f0503 CS |
11864 | vty_out(vty, " ip ospf priority %u", |
11865 | params->priority); | |
e425c019 | 11866 | if (params != IF_DEF_PARAMS(ifp) && rn) |
96b663a3 MS |
11867 | vty_out(vty, " %pI4", |
11868 | &rn->p.u.prefix4); | |
545f0503 CS |
11869 | vty_out(vty, "\n"); |
11870 | } | |
d62a17ae | 11871 | |
545f0503 CS |
11872 | /* Retransmit Interval print. */ |
11873 | if (OSPF_IF_PARAM_CONFIGURED(params, | |
996c9314 LB |
11874 | retransmit_interval) |
11875 | && params->retransmit_interval | |
11876 | != OSPF_RETRANSMIT_INTERVAL_DEFAULT) { | |
545f0503 CS |
11877 | vty_out(vty, " ip ospf retransmit-interval %u", |
11878 | params->retransmit_interval); | |
e425c019 | 11879 | if (params != IF_DEF_PARAMS(ifp) && rn) |
96b663a3 MS |
11880 | vty_out(vty, " %pI4", |
11881 | &rn->p.u.prefix4); | |
545f0503 CS |
11882 | vty_out(vty, "\n"); |
11883 | } | |
d62a17ae | 11884 | |
545f0503 | 11885 | /* Transmit Delay print. */ |
996c9314 LB |
11886 | if (OSPF_IF_PARAM_CONFIGURED(params, transmit_delay) |
11887 | && params->transmit_delay | |
11888 | != OSPF_TRANSMIT_DELAY_DEFAULT) { | |
545f0503 CS |
11889 | vty_out(vty, " ip ospf transmit-delay %u", |
11890 | params->transmit_delay); | |
e425c019 | 11891 | if (params != IF_DEF_PARAMS(ifp) && rn) |
96b663a3 MS |
11892 | vty_out(vty, " %pI4", |
11893 | &rn->p.u.prefix4); | |
545f0503 CS |
11894 | vty_out(vty, "\n"); |
11895 | } | |
d62a17ae | 11896 | |
545f0503 CS |
11897 | /* Area print. */ |
11898 | if (OSPF_IF_PARAM_CONFIGURED(params, if_area)) { | |
409f98ab | 11899 | if (ospf_instance) |
545f0503 | 11900 | vty_out(vty, " ip ospf %d", |
409f98ab | 11901 | ospf_instance); |
545f0503 CS |
11902 | else |
11903 | vty_out(vty, " ip ospf"); | |
d62a17ae | 11904 | |
1f9d4e3d | 11905 | char buf[INET_ADDRSTRLEN]; |
d62a17ae | 11906 | |
996c9314 LB |
11907 | area_id2str(buf, sizeof(buf), ¶ms->if_area, |
11908 | params->if_area_id_fmt); | |
545f0503 | 11909 | vty_out(vty, " area %s", buf); |
e425c019 | 11910 | if (params != IF_DEF_PARAMS(ifp) && rn) |
96b663a3 MS |
11911 | vty_out(vty, " %pI4", |
11912 | &rn->p.u.prefix4); | |
545f0503 CS |
11913 | vty_out(vty, "\n"); |
11914 | } | |
d62a17ae | 11915 | |
545f0503 | 11916 | /* bfd print. */ |
659f4e40 | 11917 | if (params && params->bfd_config) |
545f0503 | 11918 | ospf_bfd_write_config(vty, params); |
d62a17ae | 11919 | |
545f0503 CS |
11920 | /* MTU ignore print. */ |
11921 | if (OSPF_IF_PARAM_CONFIGURED(params, mtu_ignore) | |
996c9314 | 11922 | && params->mtu_ignore != OSPF_MTU_IGNORE_DEFAULT) { |
545f0503 CS |
11923 | if (params->mtu_ignore == 0) |
11924 | vty_out(vty, " no ip ospf mtu-ignore"); | |
11925 | else | |
11926 | vty_out(vty, " ip ospf mtu-ignore"); | |
e425c019 | 11927 | if (params != IF_DEF_PARAMS(ifp) && rn) |
96b663a3 MS |
11928 | vty_out(vty, " %pI4", |
11929 | &rn->p.u.prefix4); | |
545f0503 CS |
11930 | vty_out(vty, "\n"); |
11931 | } | |
a8b828f3 | 11932 | |
3eec4ee0 IR |
11933 | if (OSPF_IF_PARAM_CONFIGURED(params, |
11934 | passive_interface)) { | |
11935 | vty_out(vty, " ip ospf passive"); | |
11936 | if (params != IF_DEF_PARAMS(ifp) && rn) | |
11937 | vty_out(vty, " %pI4", &rn->p.u.prefix4); | |
11938 | vty_out(vty, "\n"); | |
11939 | } | |
11940 | ||
132a782e | 11941 | /* LDP-Sync print */ |
11942 | if (params && params->ldp_sync_info) | |
11943 | ospf_ldp_sync_if_write_config(vty, params); | |
d62a17ae | 11944 | |
545f0503 CS |
11945 | while (1) { |
11946 | if (rn == NULL) | |
996c9314 | 11947 | rn = route_top(IF_OIFS_PARAMS(ifp)); |
545f0503 CS |
11948 | else |
11949 | rn = route_next(rn); | |
43b8d1d8 | 11950 | |
545f0503 CS |
11951 | if (rn == NULL) |
11952 | break; | |
11953 | params = rn->info; | |
11954 | if (params != NULL) | |
11955 | break; | |
11956 | } | |
11957 | } while (rn); | |
43b8d1d8 | 11958 | |
545f0503 CS |
11959 | ospf_opaque_config_write_if(vty, ifp); |
11960 | ||
11961 | vty_endframe(vty, NULL); | |
b5a8894d | 11962 | } |
545f0503 | 11963 | |
d62a17ae | 11964 | return write; |
718e3744 | 11965 | } |
11966 | ||
43b8d1d8 CS |
11967 | /* Configuration write function for ospfd. */ |
11968 | static int config_write_interface(struct vty *vty) | |
11969 | { | |
11970 | int write = 0; | |
545f0503 | 11971 | struct vrf *vrf = NULL; |
43b8d1d8 | 11972 | |
545f0503 CS |
11973 | /* Display all VRF aware OSPF interface configuration */ |
11974 | RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) { | |
11975 | write += config_write_interface_one(vty, vrf); | |
11976 | } | |
43b8d1d8 CS |
11977 | |
11978 | return write; | |
11979 | } | |
11980 | ||
d62a17ae | 11981 | static int config_write_network_area(struct vty *vty, struct ospf *ospf) |
718e3744 | 11982 | { |
d62a17ae | 11983 | struct route_node *rn; |
fc746f1c | 11984 | char buf[INET_ADDRSTRLEN]; |
718e3744 | 11985 | |
d62a17ae | 11986 | /* `network area' print. */ |
11987 | for (rn = route_top(ospf->networks); rn; rn = route_next(rn)) | |
11988 | if (rn->info) { | |
11989 | struct ospf_network *n = rn->info; | |
718e3744 | 11990 | |
d62a17ae | 11991 | /* Create Area ID string by specified Area ID format. */ |
11992 | if (n->area_id_fmt == OSPF_AREA_ID_FMT_DOTTEDQUAD) | |
fc746f1c | 11993 | inet_ntop(AF_INET, &n->area_id, buf, |
1f9d4e3d | 11994 | sizeof(buf)); |
d62a17ae | 11995 | else |
fc746f1c QY |
11996 | snprintf(buf, sizeof(buf), "%lu", |
11997 | (unsigned long int)ntohl( | |
11998 | n->area_id.s_addr)); | |
718e3744 | 11999 | |
d62a17ae | 12000 | /* Network print. */ |
96b663a3 | 12001 | vty_out(vty, " network %pFX area %s\n", &rn->p, buf); |
d62a17ae | 12002 | } |
718e3744 | 12003 | |
d62a17ae | 12004 | return 0; |
718e3744 | 12005 | } |
12006 | ||
d62a17ae | 12007 | static int config_write_ospf_area(struct vty *vty, struct ospf *ospf) |
718e3744 | 12008 | { |
d62a17ae | 12009 | struct listnode *node; |
12010 | struct ospf_area *area; | |
fc746f1c | 12011 | char buf[INET_ADDRSTRLEN]; |
718e3744 | 12012 | |
d62a17ae | 12013 | /* Area configuration print. */ |
12014 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) { | |
12015 | struct route_node *rn1; | |
718e3744 | 12016 | |
fc746f1c | 12017 | area_id2str(buf, sizeof(buf), &area->area_id, |
d62a17ae | 12018 | area->area_id_fmt); |
718e3744 | 12019 | |
d62a17ae | 12020 | if (area->auth_type != OSPF_AUTH_NULL) { |
12021 | if (area->auth_type == OSPF_AUTH_SIMPLE) | |
12022 | vty_out(vty, " area %s authentication\n", buf); | |
12023 | else | |
12024 | vty_out(vty, | |
12025 | " area %s authentication message-digest\n", | |
12026 | buf); | |
12027 | } | |
718e3744 | 12028 | |
d62a17ae | 12029 | if (area->shortcut_configured != OSPF_SHORTCUT_DEFAULT) |
12030 | vty_out(vty, " area %s shortcut %s\n", buf, | |
12031 | ospf_shortcut_mode_str | |
12032 | [area->shortcut_configured]); | |
12033 | ||
12034 | if ((area->external_routing == OSPF_AREA_STUB) | |
12035 | || (area->external_routing == OSPF_AREA_NSSA)) { | |
7ef56a73 | 12036 | if (area->external_routing == OSPF_AREA_STUB) { |
d62a17ae | 12037 | vty_out(vty, " area %s stub", buf); |
7ef56a73 CS |
12038 | if (area->no_summary) |
12039 | vty_out(vty, " no-summary\n"); | |
12040 | vty_out(vty, "\n"); | |
12041 | } else if (area->external_routing == OSPF_AREA_NSSA) { | |
d62a17ae | 12042 | switch (area->NSSATranslatorRole) { |
12043 | case OSPF_NSSA_ROLE_NEVER: | |
7ef56a73 CS |
12044 | vty_out(vty, |
12045 | " area %s nssa translate-never\n", | |
12046 | buf); | |
d62a17ae | 12047 | break; |
12048 | case OSPF_NSSA_ROLE_ALWAYS: | |
7ef56a73 CS |
12049 | vty_out(vty, |
12050 | " area %s nssa translate-always\n", | |
12051 | buf); | |
d62a17ae | 12052 | break; |
2643b2bc CS |
12053 | case OSPF_NSSA_ROLE_CANDIDATE: |
12054 | vty_out(vty, " area %s nssa \n", buf); | |
12055 | break; | |
d62a17ae | 12056 | } |
7ef56a73 CS |
12057 | if (area->no_summary) |
12058 | vty_out(vty, | |
12059 | " area %s nssa no-summary\n", | |
12060 | buf); | |
c317eddb | 12061 | if (area->suppress_fa) |
12062 | vty_out(vty, | |
12063 | " area %s nssa suppress-fa\n", | |
12064 | buf); | |
d62a17ae | 12065 | } |
718e3744 | 12066 | |
d62a17ae | 12067 | if (area->default_cost != 1) |
12068 | vty_out(vty, " area %s default-cost %d\n", buf, | |
12069 | area->default_cost); | |
12070 | } | |
718e3744 | 12071 | |
d62a17ae | 12072 | for (rn1 = route_top(area->ranges); rn1; rn1 = route_next(rn1)) |
12073 | if (rn1->info) { | |
12074 | struct ospf_area_range *range = rn1->info; | |
718e3744 | 12075 | |
96b663a3 MS |
12076 | vty_out(vty, " area %s range %pFX", buf, |
12077 | &rn1->p); | |
718e3744 | 12078 | |
d62a17ae | 12079 | if (range->cost_config |
12080 | != OSPF_AREA_RANGE_COST_UNSPEC) | |
12081 | vty_out(vty, " cost %d", | |
12082 | range->cost_config); | |
718e3744 | 12083 | |
d62a17ae | 12084 | if (!CHECK_FLAG(range->flags, |
12085 | OSPF_AREA_RANGE_ADVERTISE)) | |
12086 | vty_out(vty, " not-advertise"); | |
718e3744 | 12087 | |
d62a17ae | 12088 | if (CHECK_FLAG(range->flags, |
12089 | OSPF_AREA_RANGE_SUBSTITUTE)) | |
96b663a3 MS |
12090 | vty_out(vty, " substitute %pI4/%d", |
12091 | &range->subst_addr, | |
d62a17ae | 12092 | range->subst_masklen); |
12093 | ||
12094 | vty_out(vty, "\n"); | |
12095 | } | |
12096 | ||
12097 | if (EXPORT_NAME(area)) | |
12098 | vty_out(vty, " area %s export-list %s\n", buf, | |
12099 | EXPORT_NAME(area)); | |
12100 | ||
12101 | if (IMPORT_NAME(area)) | |
12102 | vty_out(vty, " area %s import-list %s\n", buf, | |
12103 | IMPORT_NAME(area)); | |
12104 | ||
12105 | if (PREFIX_NAME_IN(area)) | |
12106 | vty_out(vty, " area %s filter-list prefix %s in\n", buf, | |
12107 | PREFIX_NAME_IN(area)); | |
12108 | ||
12109 | if (PREFIX_NAME_OUT(area)) | |
12110 | vty_out(vty, " area %s filter-list prefix %s out\n", | |
12111 | buf, PREFIX_NAME_OUT(area)); | |
12112 | } | |
12113 | ||
12114 | return 0; | |
718e3744 | 12115 | } |
12116 | ||
d62a17ae | 12117 | static int config_write_ospf_nbr_nbma(struct vty *vty, struct ospf *ospf) |
718e3744 | 12118 | { |
d62a17ae | 12119 | struct ospf_nbr_nbma *nbr_nbma; |
12120 | struct route_node *rn; | |
718e3744 | 12121 | |
d62a17ae | 12122 | /* Static Neighbor configuration print. */ |
12123 | for (rn = route_top(ospf->nbr_nbma); rn; rn = route_next(rn)) | |
12124 | if ((nbr_nbma = rn->info)) { | |
96b663a3 | 12125 | vty_out(vty, " neighbor %pI4", &nbr_nbma->addr); |
718e3744 | 12126 | |
d62a17ae | 12127 | if (nbr_nbma->priority |
12128 | != OSPF_NEIGHBOR_PRIORITY_DEFAULT) | |
12129 | vty_out(vty, " priority %d", | |
12130 | nbr_nbma->priority); | |
718e3744 | 12131 | |
d62a17ae | 12132 | if (nbr_nbma->v_poll != OSPF_POLL_INTERVAL_DEFAULT) |
12133 | vty_out(vty, " poll-interval %d", | |
12134 | nbr_nbma->v_poll); | |
12135 | ||
12136 | vty_out(vty, "\n"); | |
12137 | } | |
12138 | ||
12139 | return 0; | |
12140 | } | |
12141 | ||
12142 | static int config_write_virtual_link(struct vty *vty, struct ospf *ospf) | |
12143 | { | |
12144 | struct listnode *node; | |
12145 | struct ospf_vl_data *vl_data; | |
83cc5a1f | 12146 | const char *auth_str; |
d62a17ae | 12147 | char buf[INET_ADDRSTRLEN]; |
12148 | ||
12149 | /* Virtual-Link print */ | |
12150 | for (ALL_LIST_ELEMENTS_RO(ospf->vlinks, node, vl_data)) { | |
12151 | struct listnode *n2; | |
12152 | struct crypt_key *ck; | |
12153 | struct ospf_interface *oi; | |
12154 | ||
12155 | if (vl_data != NULL) { | |
d62a17ae | 12156 | area_id2str(buf, sizeof(buf), &vl_data->vl_area_id, |
12157 | vl_data->vl_area_id_fmt); | |
12158 | oi = vl_data->vl_oi; | |
12159 | ||
12160 | /* timers */ | |
12161 | if (OSPF_IF_PARAM(oi, v_hello) | |
12162 | != OSPF_HELLO_INTERVAL_DEFAULT | |
12163 | || OSPF_IF_PARAM(oi, v_wait) | |
12164 | != OSPF_ROUTER_DEAD_INTERVAL_DEFAULT | |
12165 | || OSPF_IF_PARAM(oi, retransmit_interval) | |
12166 | != OSPF_RETRANSMIT_INTERVAL_DEFAULT | |
12167 | || OSPF_IF_PARAM(oi, transmit_delay) | |
12168 | != OSPF_TRANSMIT_DELAY_DEFAULT) | |
12169 | vty_out(vty, | |
96b663a3 MS |
12170 | " area %s virtual-link %pI4 hello-interval %d retransmit-interval %d transmit-delay %d dead-interval %d\n", |
12171 | buf, &vl_data->vl_peer, | |
d62a17ae | 12172 | OSPF_IF_PARAM(oi, v_hello), |
12173 | OSPF_IF_PARAM(oi, retransmit_interval), | |
12174 | OSPF_IF_PARAM(oi, transmit_delay), | |
12175 | OSPF_IF_PARAM(oi, v_wait)); | |
12176 | else | |
96b663a3 MS |
12177 | vty_out(vty, " area %s virtual-link %pI4\n", buf, |
12178 | &vl_data->vl_peer); | |
83cc5a1f DE |
12179 | /* Auth type */ |
12180 | auth_str = interface_config_auth_str( | |
12181 | IF_DEF_PARAMS(oi->ifp)); | |
12182 | if (auth_str) | |
12183 | vty_out(vty, | |
12184 | " area %s virtual-link %pI4 authentication%s\n", | |
12185 | buf, &vl_data->vl_peer, auth_str); | |
d62a17ae | 12186 | /* Auth key */ |
12187 | if (IF_DEF_PARAMS(vl_data->vl_oi->ifp)->auth_simple[0] | |
12188 | != '\0') | |
12189 | vty_out(vty, | |
96b663a3 MS |
12190 | " area %s virtual-link %pI4 authentication-key %s\n", |
12191 | buf, &vl_data->vl_peer, | |
d62a17ae | 12192 | IF_DEF_PARAMS(vl_data->vl_oi->ifp) |
12193 | ->auth_simple); | |
12194 | /* md5 keys */ | |
12195 | for (ALL_LIST_ELEMENTS_RO( | |
12196 | IF_DEF_PARAMS(vl_data->vl_oi->ifp) | |
12197 | ->auth_crypt, | |
12198 | n2, ck)) | |
12199 | vty_out(vty, | |
96b663a3 MS |
12200 | " area %s virtual-link %pI4 message-digest-key %d md5 %s\n", |
12201 | buf, &vl_data->vl_peer, | |
d62a17ae | 12202 | ck->key_id, ck->auth_key); |
12203 | } | |
12204 | } | |
12205 | ||
12206 | return 0; | |
718e3744 | 12207 | } |
12208 | ||
6b0655a2 | 12209 | |
d62a17ae | 12210 | static int config_write_ospf_redistribute(struct vty *vty, struct ospf *ospf) |
718e3744 | 12211 | { |
d62a17ae | 12212 | int type; |
718e3744 | 12213 | |
d62a17ae | 12214 | /* redistribute print. */ |
12215 | for (type = 0; type < ZEBRA_ROUTE_MAX; type++) { | |
12216 | struct list *red_list; | |
12217 | struct listnode *node; | |
12218 | struct ospf_redist *red; | |
718e3744 | 12219 | |
d62a17ae | 12220 | red_list = ospf->redist[type]; |
12221 | if (!red_list) | |
12222 | continue; | |
7c8ff89e | 12223 | |
d62a17ae | 12224 | for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) { |
12225 | vty_out(vty, " redistribute %s", | |
12226 | zebra_route_string(type)); | |
12227 | if (red->instance) | |
12228 | vty_out(vty, " %d", red->instance); | |
7c8ff89e | 12229 | |
d62a17ae | 12230 | if (red->dmetric.value >= 0) |
12231 | vty_out(vty, " metric %d", red->dmetric.value); | |
7c8ff89e | 12232 | |
d62a17ae | 12233 | if (red->dmetric.type == EXTERNAL_METRIC_TYPE_1) |
12234 | vty_out(vty, " metric-type 1"); | |
7c8ff89e | 12235 | |
d62a17ae | 12236 | if (ROUTEMAP_NAME(red)) |
12237 | vty_out(vty, " route-map %s", | |
12238 | ROUTEMAP_NAME(red)); | |
7c8ff89e | 12239 | |
d62a17ae | 12240 | vty_out(vty, "\n"); |
12241 | } | |
12242 | } | |
718e3744 | 12243 | |
d62a17ae | 12244 | return 0; |
718e3744 | 12245 | } |
12246 | ||
1ac88792 | 12247 | static int ospf_cfg_write_helper_dis_rtr_walkcb(struct hash_bucket *bucket, |
07b33add | 12248 | void *arg) |
12249 | { | |
1ac88792 | 12250 | struct advRtr *rtr = bucket->data; |
07b33add | 12251 | struct vty *vty = (struct vty *)arg; |
12252 | ||
96b663a3 MS |
12253 | vty_out(vty, " graceful-restart helper-only %pI4\n", |
12254 | &rtr->advRtrAddr); | |
07b33add | 12255 | return HASHWALK_CONTINUE; |
12256 | } | |
12257 | ||
10514170 RW |
12258 | static void config_write_ospf_gr(struct vty *vty, struct ospf *ospf) |
12259 | { | |
12260 | if (!ospf->gr_info.restart_support) | |
12261 | return; | |
12262 | ||
12263 | if (ospf->gr_info.grace_period == OSPF_DFLT_GRACE_INTERVAL) | |
12264 | vty_out(vty, " graceful-restart\n"); | |
12265 | else | |
12266 | vty_out(vty, " graceful-restart grace-period %u\n", | |
12267 | ospf->gr_info.grace_period); | |
12268 | } | |
12269 | ||
07b33add | 12270 | static int config_write_ospf_gr_helper(struct vty *vty, struct ospf *ospf) |
12271 | { | |
12272 | if (ospf->is_helper_supported) | |
12273 | vty_out(vty, " graceful-restart helper-only\n"); | |
12274 | ||
12275 | if (!ospf->strict_lsa_check) | |
96b663a3 MS |
12276 | vty_out(vty, |
12277 | " no graceful-restart helper strict-lsa-checking\n"); | |
07b33add | 12278 | |
12279 | if (ospf->only_planned_restart) | |
12280 | vty_out(vty, " graceful-restart helper planned-only\n"); | |
12281 | ||
12282 | if (ospf->supported_grace_time != OSPF_MAX_GRACE_INTERVAL) | |
12283 | vty_out(vty, | |
12284 | " graceful-restart helper supported-grace-time %d\n", | |
12285 | ospf->supported_grace_time); | |
12286 | ||
12287 | if (OSPF_HELPER_ENABLE_RTR_COUNT(ospf)) { | |
12288 | hash_walk(ospf->enable_rtr_list, | |
12289 | ospf_cfg_write_helper_dis_rtr_walkcb, vty); | |
12290 | } | |
423e71c4 | 12291 | return 0; |
12292 | } | |
12293 | ||
12294 | static int config_write_ospf_external_aggregator(struct vty *vty, | |
12295 | struct ospf *ospf) | |
12296 | { | |
12297 | struct route_node *rn; | |
12298 | ||
12299 | /* print 'summary-address A.B.C.D/M' */ | |
12300 | for (rn = route_top(ospf->rt_aggr_tbl); rn; rn = route_next(rn)) | |
12301 | if (rn->info) { | |
12302 | struct ospf_external_aggr_rt *aggr = rn->info; | |
12303 | ||
12304 | vty_out(vty, " summary-address %pI4/%d ", | |
12305 | &aggr->p.prefix, aggr->p.prefixlen); | |
12306 | if (aggr->tag) | |
12307 | vty_out(vty, " tag %u ", aggr->tag); | |
12308 | ||
12309 | if (CHECK_FLAG(aggr->flags, | |
12310 | OSPF_EXTERNAL_AGGRT_NO_ADVERTISE)) | |
12311 | vty_out(vty, " no-advertise"); | |
12312 | ||
12313 | vty_out(vty, "\n"); | |
12314 | } | |
07b33add | 12315 | |
12316 | return 0; | |
12317 | } | |
12318 | ||
d62a17ae | 12319 | static int config_write_ospf_default_metric(struct vty *vty, struct ospf *ospf) |
718e3744 | 12320 | { |
d62a17ae | 12321 | if (ospf->default_metric != -1) |
12322 | vty_out(vty, " default-metric %d\n", ospf->default_metric); | |
12323 | return 0; | |
718e3744 | 12324 | } |
12325 | ||
d62a17ae | 12326 | static int config_write_ospf_distribute(struct vty *vty, struct ospf *ospf) |
12327 | { | |
12328 | int type; | |
12329 | struct ospf_redist *red; | |
718e3744 | 12330 | |
d62a17ae | 12331 | if (ospf) { |
12332 | /* distribute-list print. */ | |
12333 | for (type = 0; type < ZEBRA_ROUTE_MAX; type++) | |
12334 | if (DISTRIBUTE_NAME(ospf, type)) | |
12335 | vty_out(vty, " distribute-list %s out %s\n", | |
12336 | DISTRIBUTE_NAME(ospf, type), | |
12337 | zebra_route_string(type)); | |
7c8ff89e | 12338 | |
d62a17ae | 12339 | /* default-information print. */ |
12340 | if (ospf->default_originate != DEFAULT_ORIGINATE_NONE) { | |
12341 | vty_out(vty, " default-information originate"); | |
12342 | if (ospf->default_originate == DEFAULT_ORIGINATE_ALWAYS) | |
12343 | vty_out(vty, " always"); | |
718e3744 | 12344 | |
d62a17ae | 12345 | red = ospf_redist_lookup(ospf, DEFAULT_ROUTE, 0); |
12346 | if (red) { | |
12347 | if (red->dmetric.value >= 0) | |
12348 | vty_out(vty, " metric %d", | |
12349 | red->dmetric.value); | |
951da435 | 12350 | |
d62a17ae | 12351 | if (red->dmetric.type == EXTERNAL_METRIC_TYPE_1) |
12352 | vty_out(vty, " metric-type 1"); | |
718e3744 | 12353 | |
d62a17ae | 12354 | if (ROUTEMAP_NAME(red)) |
12355 | vty_out(vty, " route-map %s", | |
12356 | ROUTEMAP_NAME(red)); | |
12357 | } | |
12358 | ||
12359 | vty_out(vty, "\n"); | |
12360 | } | |
12361 | } | |
12362 | ||
12363 | return 0; | |
718e3744 | 12364 | } |
12365 | ||
d62a17ae | 12366 | static int config_write_ospf_distance(struct vty *vty, struct ospf *ospf) |
12367 | { | |
12368 | struct route_node *rn; | |
12369 | struct ospf_distance *odistance; | |
12370 | ||
12371 | if (ospf->distance_all) | |
12372 | vty_out(vty, " distance %d\n", ospf->distance_all); | |
12373 | ||
12374 | if (ospf->distance_intra || ospf->distance_inter | |
12375 | || ospf->distance_external) { | |
12376 | vty_out(vty, " distance ospf"); | |
12377 | ||
12378 | if (ospf->distance_intra) | |
12379 | vty_out(vty, " intra-area %d", ospf->distance_intra); | |
12380 | if (ospf->distance_inter) | |
12381 | vty_out(vty, " inter-area %d", ospf->distance_inter); | |
12382 | if (ospf->distance_external) | |
12383 | vty_out(vty, " external %d", ospf->distance_external); | |
12384 | ||
12385 | vty_out(vty, "\n"); | |
12386 | } | |
12387 | ||
12388 | for (rn = route_top(ospf->distance_table); rn; rn = route_next(rn)) | |
12389 | if ((odistance = rn->info) != NULL) { | |
96b663a3 MS |
12390 | vty_out(vty, " distance %d %pFX %s\n", |
12391 | odistance->distance, &rn->p, | |
d62a17ae | 12392 | odistance->access_list ? odistance->access_list |
12393 | : ""); | |
12394 | } | |
12395 | return 0; | |
718e3744 | 12396 | } |
12397 | ||
43b8d1d8 | 12398 | static int ospf_config_write_one(struct vty *vty, struct ospf *ospf) |
d62a17ae | 12399 | { |
d62a17ae | 12400 | int write = 0; |
12401 | ||
43b8d1d8 CS |
12402 | /* `router ospf' print. */ |
12403 | if (ospf->instance && ospf->name) { | |
996c9314 LB |
12404 | vty_out(vty, "router ospf %d vrf %s\n", ospf->instance, |
12405 | ospf->name); | |
43b8d1d8 | 12406 | } else if (ospf->instance) { |
996c9314 | 12407 | vty_out(vty, "router ospf %d\n", ospf->instance); |
43b8d1d8 | 12408 | } else if (ospf->name) { |
996c9314 | 12409 | vty_out(vty, "router ospf vrf %s\n", ospf->name); |
43b8d1d8 CS |
12410 | } else |
12411 | vty_out(vty, "router ospf\n"); | |
12412 | ||
12413 | if (!ospf->networks) { | |
12414 | write++; | |
b5a8894d | 12415 | return write; |
43b8d1d8 | 12416 | } |
d62a17ae | 12417 | |
43b8d1d8 | 12418 | /* Router ID print. */ |
3a6290bd | 12419 | if (ospf->router_id_static.s_addr != INADDR_ANY) |
96b663a3 MS |
12420 | vty_out(vty, " ospf router-id %pI4\n", |
12421 | &ospf->router_id_static); | |
d62a17ae | 12422 | |
43b8d1d8 CS |
12423 | /* ABR type print. */ |
12424 | if (ospf->abr_type != OSPF_ABR_DEFAULT) | |
12425 | vty_out(vty, " ospf abr-type %s\n", | |
12426 | ospf_abr_type_str[ospf->abr_type]); | |
b5a8894d | 12427 | |
43b8d1d8 CS |
12428 | /* log-adjacency-changes flag print. */ |
12429 | if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES)) { | |
12430 | if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL)) | |
12431 | vty_out(vty, " log-adjacency-changes detail\n"); | |
c572fbfe | 12432 | else if (!SAVE_OSPF_LOG_ADJACENCY_CHANGES) |
43b8d1d8 | 12433 | vty_out(vty, " log-adjacency-changes\n"); |
c572fbfe | 12434 | } else if (SAVE_OSPF_LOG_ADJACENCY_CHANGES) { |
43b8d1d8 CS |
12435 | vty_out(vty, " no log-adjacency-changes\n"); |
12436 | } | |
b5a8894d | 12437 | |
43b8d1d8 CS |
12438 | /* RFC1583 compatibility flag print -- Compatible with CISCO |
12439 | * 12.1. */ | |
12440 | if (CHECK_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE)) | |
12441 | vty_out(vty, " compatible rfc1583\n"); | |
d62a17ae | 12442 | |
43b8d1d8 CS |
12443 | /* auto-cost reference-bandwidth configuration. */ |
12444 | if (ospf->ref_bandwidth != OSPF_DEFAULT_REF_BANDWIDTH) { | |
12445 | vty_out(vty, | |
3efd0893 | 12446 | "! Important: ensure reference bandwidth is consistent across all routers\n"); |
43b8d1d8 CS |
12447 | vty_out(vty, " auto-cost reference-bandwidth %d\n", |
12448 | ospf->ref_bandwidth); | |
12449 | } | |
d62a17ae | 12450 | |
43b8d1d8 CS |
12451 | /* SPF timers print. */ |
12452 | if (ospf->spf_delay != OSPF_SPF_DELAY_DEFAULT | |
12453 | || ospf->spf_holdtime != OSPF_SPF_HOLDTIME_DEFAULT | |
12454 | || ospf->spf_max_holdtime != OSPF_SPF_MAX_HOLDTIME_DEFAULT) | |
996c9314 LB |
12455 | vty_out(vty, " timers throttle spf %d %d %d\n", ospf->spf_delay, |
12456 | ospf->spf_holdtime, ospf->spf_max_holdtime); | |
43b8d1d8 CS |
12457 | |
12458 | /* LSA timers print. */ | |
12459 | if (ospf->min_ls_interval != OSPF_MIN_LS_INTERVAL) | |
12460 | vty_out(vty, " timers throttle lsa all %d\n", | |
12461 | ospf->min_ls_interval); | |
12462 | if (ospf->min_ls_arrival != OSPF_MIN_LS_ARRIVAL) | |
12463 | vty_out(vty, " timers lsa min-arrival %d\n", | |
12464 | ospf->min_ls_arrival); | |
12465 | ||
12466 | /* Write multiplier print. */ | |
12467 | if (ospf->write_oi_count != OSPF_WRITE_INTERFACE_COUNT_DEFAULT) | |
12468 | vty_out(vty, " ospf write-multiplier %d\n", | |
12469 | ospf->write_oi_count); | |
d62a17ae | 12470 | |
3d5b9855 | 12471 | if (ospf->max_multipath != MULTIPATH_NUM) |
12472 | vty_out(vty, " maximum-paths %d\n", ospf->max_multipath); | |
12473 | ||
43b8d1d8 CS |
12474 | /* Max-metric router-lsa print */ |
12475 | config_write_stub_router(vty, ospf); | |
d62a17ae | 12476 | |
43b8d1d8 | 12477 | /* SPF refresh parameters print. */ |
996c9314 LB |
12478 | if (ospf->lsa_refresh_interval != OSPF_LSA_REFRESH_INTERVAL_DEFAULT) |
12479 | vty_out(vty, " refresh timer %d\n", ospf->lsa_refresh_interval); | |
d62a17ae | 12480 | |
43b8d1d8 CS |
12481 | /* Redistribute information print. */ |
12482 | config_write_ospf_redistribute(vty, ospf); | |
d62a17ae | 12483 | |
10514170 RW |
12484 | /* Graceful Restart print */ |
12485 | config_write_ospf_gr(vty, ospf); | |
07b33add | 12486 | config_write_ospf_gr_helper(vty, ospf); |
12487 | ||
423e71c4 | 12488 | /* Print external route aggregation. */ |
12489 | config_write_ospf_external_aggregator(vty, ospf); | |
12490 | ||
43b8d1d8 CS |
12491 | /* passive-interface print. */ |
12492 | if (ospf->passive_interface_default == OSPF_IF_PASSIVE) | |
12493 | vty_out(vty, " passive-interface default\n"); | |
d62a17ae | 12494 | |
a92706bb JU |
12495 | /* proactive-arp print. */ |
12496 | if (ospf->proactive_arp != OSPF_PROACTIVE_ARP_DEFAULT) { | |
12497 | if (ospf->proactive_arp) | |
12498 | vty_out(vty, " proactive-arp\n"); | |
12499 | else | |
12500 | vty_out(vty, " no proactive-arp\n"); | |
12501 | } | |
12502 | ||
7fd0729f | 12503 | /* TI-LFA print. */ |
385a1e07 G |
12504 | if (ospf->ti_lfa_enabled) { |
12505 | if (ospf->ti_lfa_protection_type == OSPF_TI_LFA_NODE_PROTECTION) | |
12506 | vty_out(vty, " fast-reroute ti-lfa node-protection\n"); | |
12507 | else | |
12508 | vty_out(vty, " fast-reroute ti-lfa\n"); | |
12509 | } | |
7fd0729f | 12510 | |
43b8d1d8 CS |
12511 | /* Network area print. */ |
12512 | config_write_network_area(vty, ospf); | |
d62a17ae | 12513 | |
43b8d1d8 CS |
12514 | /* Area config print. */ |
12515 | config_write_ospf_area(vty, ospf); | |
d62a17ae | 12516 | |
43b8d1d8 CS |
12517 | /* static neighbor print. */ |
12518 | config_write_ospf_nbr_nbma(vty, ospf); | |
12519 | ||
12520 | /* Virtual-Link print. */ | |
12521 | config_write_virtual_link(vty, ospf); | |
12522 | ||
12523 | /* Default metric configuration. */ | |
12524 | config_write_ospf_default_metric(vty, ospf); | |
12525 | ||
12526 | /* Distribute-list and default-information print. */ | |
12527 | config_write_ospf_distribute(vty, ospf); | |
12528 | ||
12529 | /* Distance configuration. */ | |
12530 | config_write_ospf_distance(vty, ospf); | |
12531 | ||
12532 | ospf_opaque_config_write_router(vty, ospf); | |
12533 | ||
132a782e | 12534 | /* LDP-Sync print */ |
12535 | ospf_ldp_sync_write_config(vty, ospf); | |
12536 | ||
43b8d1d8 CS |
12537 | write++; |
12538 | return write; | |
12539 | } | |
12540 | ||
12541 | /* OSPF configuration write function. */ | |
12542 | static int ospf_config_write(struct vty *vty) | |
12543 | { | |
12544 | struct ospf *ospf; | |
12545 | struct listnode *ospf_node = NULL; | |
12546 | int write = 0; | |
12547 | ||
12548 | if (listcount(om->ospf) == 0) | |
12549 | return write; | |
12550 | ||
12551 | for (ALL_LIST_ELEMENTS_RO(om->ospf, ospf_node, ospf)) { | |
88d77109 CS |
12552 | /* VRF Default check if it is running. |
12553 | * Upon daemon start, there could be default instance | |
12554 | * in absence of 'router ospf'/oi_running is disabled. */ | |
12555 | if (ospf->vrf_id == VRF_DEFAULT && ospf->oi_running) | |
12556 | write += ospf_config_write_one(vty, ospf); | |
12557 | /* For Non-Default VRF simply display the configuration, | |
12558 | * even if it is not oi_running. */ | |
12559 | else if (ospf->vrf_id != VRF_DEFAULT) | |
43b8d1d8 | 12560 | write += ospf_config_write_one(vty, ospf); |
b5a8894d | 12561 | } |
d62a17ae | 12562 | return write; |
12563 | } | |
12564 | ||
12565 | void ospf_vty_show_init(void) | |
12566 | { | |
12567 | /* "show ip ospf" commands. */ | |
12568 | install_element(VIEW_NODE, &show_ip_ospf_cmd); | |
12569 | ||
12570 | install_element(VIEW_NODE, &show_ip_ospf_instance_cmd); | |
12571 | ||
12572 | /* "show ip ospf database" commands. */ | |
a11bce11 | 12573 | install_element(VIEW_NODE, &show_ip_ospf_database_cmd); |
d62a17ae | 12574 | install_element(VIEW_NODE, &show_ip_ospf_database_max_cmd); |
a11bce11 IR |
12575 | install_element(VIEW_NODE, |
12576 | &show_ip_ospf_database_type_adv_router_cmd); | |
d62a17ae | 12577 | install_element(VIEW_NODE, |
12578 | &show_ip_ospf_instance_database_type_adv_router_cmd); | |
12579 | install_element(VIEW_NODE, &show_ip_ospf_instance_database_cmd); | |
12580 | install_element(VIEW_NODE, &show_ip_ospf_instance_database_max_cmd); | |
12581 | ||
12582 | /* "show ip ospf interface" commands. */ | |
12583 | install_element(VIEW_NODE, &show_ip_ospf_interface_cmd); | |
12584 | ||
12585 | install_element(VIEW_NODE, &show_ip_ospf_instance_interface_cmd); | |
c9339663 CS |
12586 | /* "show ip ospf interface traffic */ |
12587 | install_element(VIEW_NODE, &show_ip_ospf_interface_traffic_cmd); | |
d62a17ae | 12588 | |
12589 | /* "show ip ospf neighbor" commands. */ | |
12590 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_int_detail_cmd); | |
12591 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_int_cmd); | |
12592 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_id_cmd); | |
12593 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_detail_all_cmd); | |
12594 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_detail_cmd); | |
12595 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_cmd); | |
12596 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_all_cmd); | |
12597 | ||
12598 | install_element(VIEW_NODE, | |
12599 | &show_ip_ospf_instance_neighbor_int_detail_cmd); | |
12600 | install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_int_cmd); | |
12601 | install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_id_cmd); | |
12602 | install_element(VIEW_NODE, | |
12603 | &show_ip_ospf_instance_neighbor_detail_all_cmd); | |
12604 | install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_detail_cmd); | |
12605 | install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_cmd); | |
12606 | install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_all_cmd); | |
12607 | ||
12608 | /* "show ip ospf route" commands. */ | |
12609 | install_element(VIEW_NODE, &show_ip_ospf_route_cmd); | |
12610 | install_element(VIEW_NODE, &show_ip_ospf_border_routers_cmd); | |
12611 | ||
12612 | install_element(VIEW_NODE, &show_ip_ospf_instance_route_cmd); | |
12613 | install_element(VIEW_NODE, &show_ip_ospf_instance_border_routers_cmd); | |
b5a8894d CS |
12614 | |
12615 | /* "show ip ospf vrfs" commands. */ | |
12616 | install_element(VIEW_NODE, &show_ip_ospf_vrfs_cmd); | |
abd5b8c7 | 12617 | |
12618 | /* "show ip ospf gr-helper details" command */ | |
12619 | install_element(VIEW_NODE, &show_ip_ospf_gr_helper_cmd); | |
718e3744 | 12620 | |
53e44d05 | 12621 | /* "show ip ospf summary-address" command */ |
12622 | install_element(VIEW_NODE, &show_ip_ospf_external_aggregator_cmd); | |
12623 | } | |
6b0655a2 | 12624 | |
612c2c15 | 12625 | static int config_write_interface(struct vty *vty); |
718e3744 | 12626 | /* ospfd's interface node. */ |
62b346ee | 12627 | static struct cmd_node interface_node = { |
f4b8291f | 12628 | .name = "interface", |
62b346ee | 12629 | .node = INTERFACE_NODE, |
24389580 | 12630 | .parent_node = CONFIG_NODE, |
62b346ee | 12631 | .prompt = "%s(config-if)# ", |
612c2c15 | 12632 | .config_write = config_write_interface, |
62b346ee | 12633 | }; |
718e3744 | 12634 | |
12635 | /* Initialization of OSPF interface. */ | |
d62a17ae | 12636 | static void ospf_vty_if_init(void) |
12637 | { | |
12638 | /* Install interface node. */ | |
612c2c15 | 12639 | install_node(&interface_node); |
d62a17ae | 12640 | if_cmd_init(); |
12641 | ||
12642 | /* "ip ospf authentication" commands. */ | |
12643 | install_element(INTERFACE_NODE, &ip_ospf_authentication_args_addr_cmd); | |
12644 | install_element(INTERFACE_NODE, &ip_ospf_authentication_addr_cmd); | |
12645 | install_element(INTERFACE_NODE, | |
12646 | &no_ip_ospf_authentication_args_addr_cmd); | |
12647 | install_element(INTERFACE_NODE, &no_ip_ospf_authentication_addr_cmd); | |
12648 | install_element(INTERFACE_NODE, &ip_ospf_authentication_key_addr_cmd); | |
12649 | install_element(INTERFACE_NODE, | |
12650 | &no_ip_ospf_authentication_key_authkey_addr_cmd); | |
12651 | install_element(INTERFACE_NODE, | |
12652 | &no_ospf_authentication_key_authkey_addr_cmd); | |
12653 | ||
12654 | /* "ip ospf message-digest-key" commands. */ | |
12655 | install_element(INTERFACE_NODE, &ip_ospf_message_digest_key_cmd); | |
12656 | install_element(INTERFACE_NODE, &no_ip_ospf_message_digest_key_cmd); | |
12657 | ||
12658 | /* "ip ospf cost" commands. */ | |
12659 | install_element(INTERFACE_NODE, &ip_ospf_cost_cmd); | |
12660 | install_element(INTERFACE_NODE, &no_ip_ospf_cost_cmd); | |
12661 | ||
12662 | /* "ip ospf mtu-ignore" commands. */ | |
12663 | install_element(INTERFACE_NODE, &ip_ospf_mtu_ignore_addr_cmd); | |
12664 | install_element(INTERFACE_NODE, &no_ip_ospf_mtu_ignore_addr_cmd); | |
12665 | ||
12666 | /* "ip ospf dead-interval" commands. */ | |
12667 | install_element(INTERFACE_NODE, &ip_ospf_dead_interval_cmd); | |
12668 | install_element(INTERFACE_NODE, | |
12669 | &ip_ospf_dead_interval_minimal_addr_cmd); | |
12670 | install_element(INTERFACE_NODE, &no_ip_ospf_dead_interval_cmd); | |
12671 | ||
12672 | /* "ip ospf hello-interval" commands. */ | |
12673 | install_element(INTERFACE_NODE, &ip_ospf_hello_interval_cmd); | |
12674 | install_element(INTERFACE_NODE, &no_ip_ospf_hello_interval_cmd); | |
12675 | ||
12676 | /* "ip ospf network" commands. */ | |
12677 | install_element(INTERFACE_NODE, &ip_ospf_network_cmd); | |
12678 | install_element(INTERFACE_NODE, &no_ip_ospf_network_cmd); | |
12679 | ||
12680 | /* "ip ospf priority" commands. */ | |
12681 | install_element(INTERFACE_NODE, &ip_ospf_priority_cmd); | |
12682 | install_element(INTERFACE_NODE, &no_ip_ospf_priority_cmd); | |
12683 | ||
12684 | /* "ip ospf retransmit-interval" commands. */ | |
12685 | install_element(INTERFACE_NODE, &ip_ospf_retransmit_interval_addr_cmd); | |
12686 | install_element(INTERFACE_NODE, | |
12687 | &no_ip_ospf_retransmit_interval_addr_cmd); | |
12688 | ||
12689 | /* "ip ospf transmit-delay" commands. */ | |
12690 | install_element(INTERFACE_NODE, &ip_ospf_transmit_delay_addr_cmd); | |
12691 | install_element(INTERFACE_NODE, &no_ip_ospf_transmit_delay_addr_cmd); | |
12692 | ||
12693 | /* "ip ospf area" commands. */ | |
12694 | install_element(INTERFACE_NODE, &ip_ospf_area_cmd); | |
12695 | install_element(INTERFACE_NODE, &no_ip_ospf_area_cmd); | |
12696 | ||
3eec4ee0 IR |
12697 | /* "ip ospf passive" commands. */ |
12698 | install_element(INTERFACE_NODE, &ip_ospf_passive_cmd); | |
12699 | install_element(INTERFACE_NODE, &no_ip_ospf_passive_cmd); | |
12700 | ||
d62a17ae | 12701 | /* These commands are compatibitliy for previous version. */ |
12702 | install_element(INTERFACE_NODE, &ospf_authentication_key_cmd); | |
12703 | install_element(INTERFACE_NODE, &ospf_message_digest_key_cmd); | |
12704 | install_element(INTERFACE_NODE, &no_ospf_message_digest_key_cmd); | |
12705 | install_element(INTERFACE_NODE, &ospf_dead_interval_cmd); | |
12706 | install_element(INTERFACE_NODE, &no_ospf_dead_interval_cmd); | |
12707 | install_element(INTERFACE_NODE, &ospf_hello_interval_cmd); | |
12708 | install_element(INTERFACE_NODE, &no_ospf_hello_interval_cmd); | |
12709 | install_element(INTERFACE_NODE, &ospf_cost_cmd); | |
12710 | install_element(INTERFACE_NODE, &no_ospf_cost_cmd); | |
12711 | install_element(INTERFACE_NODE, &ospf_network_cmd); | |
12712 | install_element(INTERFACE_NODE, &no_ospf_network_cmd); | |
12713 | install_element(INTERFACE_NODE, &ospf_priority_cmd); | |
12714 | install_element(INTERFACE_NODE, &no_ospf_priority_cmd); | |
12715 | install_element(INTERFACE_NODE, &ospf_retransmit_interval_cmd); | |
12716 | install_element(INTERFACE_NODE, &no_ospf_retransmit_interval_cmd); | |
12717 | install_element(INTERFACE_NODE, &ospf_transmit_delay_cmd); | |
12718 | install_element(INTERFACE_NODE, &no_ospf_transmit_delay_cmd); | |
12719 | } | |
12720 | ||
12721 | static void ospf_vty_zebra_init(void) | |
12722 | { | |
12723 | install_element(OSPF_NODE, &ospf_redistribute_source_cmd); | |
12724 | install_element(OSPF_NODE, &no_ospf_redistribute_source_cmd); | |
12725 | install_element(OSPF_NODE, &ospf_redistribute_instance_source_cmd); | |
12726 | install_element(OSPF_NODE, &no_ospf_redistribute_instance_source_cmd); | |
12727 | ||
12728 | install_element(OSPF_NODE, &ospf_distribute_list_out_cmd); | |
12729 | install_element(OSPF_NODE, &no_ospf_distribute_list_out_cmd); | |
12730 | ||
12731 | install_element(OSPF_NODE, &ospf_default_information_originate_cmd); | |
12732 | install_element(OSPF_NODE, &no_ospf_default_information_originate_cmd); | |
12733 | ||
12734 | install_element(OSPF_NODE, &ospf_default_metric_cmd); | |
12735 | install_element(OSPF_NODE, &no_ospf_default_metric_cmd); | |
12736 | ||
12737 | install_element(OSPF_NODE, &ospf_distance_cmd); | |
12738 | install_element(OSPF_NODE, &no_ospf_distance_cmd); | |
12739 | install_element(OSPF_NODE, &no_ospf_distance_ospf_cmd); | |
12740 | install_element(OSPF_NODE, &ospf_distance_ospf_cmd); | |
07b33add | 12741 | |
12742 | /*Ospf garcefull restart helper configurations */ | |
12743 | install_element(OSPF_NODE, &ospf_gr_helper_enable_cmd); | |
12744 | install_element(OSPF_NODE, &no_ospf_gr_helper_enable_cmd); | |
12745 | install_element(OSPF_NODE, &ospf_gr_helper_enable_lsacheck_cmd); | |
12746 | install_element(OSPF_NODE, &no_ospf_gr_helper_enable_lsacheck_cmd); | |
12747 | install_element(OSPF_NODE, &ospf_gr_helper_supported_grace_time_cmd); | |
12748 | install_element(OSPF_NODE, &no_ospf_gr_helper_supported_grace_time_cmd); | |
12749 | install_element(OSPF_NODE, &ospf_gr_helper_planned_only_cmd); | |
12750 | install_element(OSPF_NODE, &no_ospf_gr_helper_planned_only_cmd); | |
423e71c4 | 12751 | |
12752 | /* External LSA summarisation config commands.*/ | |
12753 | install_element(OSPF_NODE, &ospf_external_route_aggregation_cmd); | |
12754 | install_element(OSPF_NODE, &no_ospf_external_route_aggregation_cmd); | |
12755 | install_element(OSPF_NODE, | |
12756 | &ospf_external_route_aggregation_no_adrvertise_cmd); | |
12757 | install_element(OSPF_NODE, | |
12758 | &no_ospf_external_route_aggregation_no_adrvertise_cmd); | |
12759 | install_element(OSPF_NODE, &ospf_route_aggregation_timer_cmd); | |
12760 | install_element(OSPF_NODE, &no_ospf_route_aggregation_timer_cmd); | |
718e3744 | 12761 | } |
12762 | ||
612c2c15 | 12763 | static int ospf_config_write(struct vty *vty); |
62b346ee | 12764 | static struct cmd_node ospf_node = { |
f4b8291f | 12765 | .name = "ospf", |
62b346ee | 12766 | .node = OSPF_NODE, |
24389580 | 12767 | .parent_node = CONFIG_NODE, |
62b346ee | 12768 | .prompt = "%s(config-router)# ", |
612c2c15 | 12769 | .config_write = ospf_config_write, |
62b346ee | 12770 | }; |
718e3744 | 12771 | |
d62a17ae | 12772 | static void ospf_interface_clear(struct interface *ifp) |
09f35f8c | 12773 | { |
d62a17ae | 12774 | if (!if_is_operative(ifp)) |
12775 | return; | |
09f35f8c | 12776 | |
d62a17ae | 12777 | if (IS_DEBUG_OSPF(ism, ISM_EVENTS)) |
12778 | zlog_debug("ISM[%s]: clear by reset", ifp->name); | |
09f35f8c | 12779 | |
d62a17ae | 12780 | ospf_if_reset(ifp); |
09f35f8c DS |
12781 | } |
12782 | ||
12783 | DEFUN (clear_ip_ospf_interface, | |
12784 | clear_ip_ospf_interface_cmd, | |
1e81afc3 | 12785 | "clear ip ospf [vrf NAME] interface [IFNAME]", |
09f35f8c DS |
12786 | CLEAR_STR |
12787 | IP_STR | |
12788 | "OSPF information\n" | |
03ed9f02 | 12789 | VRF_CMD_HELP_STR |
09f35f8c DS |
12790 | "Interface information\n" |
12791 | "Interface name\n") | |
12792 | { | |
03ed9f02 PG |
12793 | int idx_ifname = 0; |
12794 | int idx_vrf = 0; | |
d62a17ae | 12795 | struct interface *ifp; |
f4e14fdb | 12796 | struct listnode *node; |
b5a8894d | 12797 | struct ospf *ospf = NULL; |
03ed9f02 PG |
12798 | char *vrf_name = NULL; |
12799 | vrf_id_t vrf_id = VRF_DEFAULT; | |
12800 | struct vrf *vrf = NULL; | |
09f35f8c | 12801 | |
03ed9f02 PG |
12802 | if (argv_find(argv, argc, "vrf", &idx_vrf)) |
12803 | vrf_name = argv[idx_vrf + 1]->arg; | |
12804 | if (vrf_name && strmatch(vrf_name, VRF_DEFAULT_NAME)) | |
12805 | vrf_name = NULL; | |
12806 | if (vrf_name) { | |
12807 | vrf = vrf_lookup_by_name(vrf_name); | |
12808 | if (vrf) | |
12809 | vrf_id = vrf->vrf_id; | |
12810 | } | |
12811 | if (!argv_find(argv, argc, "IFNAME", &idx_ifname)) { | |
12812 | /* Clear all the ospfv2 interfaces. */ | |
f4e14fdb | 12813 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { |
03ed9f02 PG |
12814 | if (vrf_id != ospf->vrf_id) |
12815 | continue; | |
12816 | if (!vrf) | |
12817 | vrf = vrf_lookup_by_id(ospf->vrf_id); | |
451fda4f | 12818 | FOR_ALL_INTERFACES (vrf, ifp) |
b5a8894d CS |
12819 | ospf_interface_clear(ifp); |
12820 | } | |
12821 | } else { | |
12822 | /* Interface name is specified. */ | |
a36898e7 | 12823 | ifp = if_lookup_by_name(argv[idx_ifname]->arg, vrf_id); |
b5a8894d | 12824 | if (ifp == NULL) |
d62a17ae | 12825 | vty_out(vty, "No such interface name\n"); |
12826 | else | |
12827 | ospf_interface_clear(ifp); | |
12828 | } | |
12829 | ||
12830 | return CMD_SUCCESS; | |
09f35f8c DS |
12831 | } |
12832 | ||
d62a17ae | 12833 | void ospf_vty_clear_init(void) |
09f35f8c | 12834 | { |
d62a17ae | 12835 | install_element(ENABLE_NODE, &clear_ip_ospf_interface_cmd); |
f91ce319 MR |
12836 | install_element(ENABLE_NODE, &clear_ip_ospf_process_cmd); |
12837 | install_element(ENABLE_NODE, &clear_ip_ospf_neighbor_cmd); | |
09f35f8c DS |
12838 | } |
12839 | ||
6b0655a2 | 12840 | |
718e3744 | 12841 | /* Install OSPF related vty commands. */ |
d62a17ae | 12842 | void ospf_vty_init(void) |
12843 | { | |
12844 | /* Install ospf top node. */ | |
612c2c15 | 12845 | install_node(&ospf_node); |
d62a17ae | 12846 | |
12847 | /* "router ospf" commands. */ | |
12848 | install_element(CONFIG_NODE, &router_ospf_cmd); | |
12849 | install_element(CONFIG_NODE, &no_router_ospf_cmd); | |
12850 | ||
12851 | ||
12852 | install_default(OSPF_NODE); | |
12853 | ||
12854 | /* "ospf router-id" commands. */ | |
12855 | install_element(OSPF_NODE, &ospf_router_id_cmd); | |
12856 | install_element(OSPF_NODE, &ospf_router_id_old_cmd); | |
12857 | install_element(OSPF_NODE, &no_ospf_router_id_cmd); | |
12858 | ||
12859 | /* "passive-interface" commands. */ | |
3eec4ee0 | 12860 | install_element(OSPF_NODE, &ospf_passive_interface_default_cmd); |
d62a17ae | 12861 | install_element(OSPF_NODE, &ospf_passive_interface_addr_cmd); |
3eec4ee0 | 12862 | install_element(OSPF_NODE, &no_ospf_passive_interface_default_cmd); |
d62a17ae | 12863 | install_element(OSPF_NODE, &no_ospf_passive_interface_addr_cmd); |
12864 | ||
12865 | /* "ospf abr-type" commands. */ | |
12866 | install_element(OSPF_NODE, &ospf_abr_type_cmd); | |
12867 | install_element(OSPF_NODE, &no_ospf_abr_type_cmd); | |
12868 | ||
12869 | /* "ospf log-adjacency-changes" commands. */ | |
12870 | install_element(OSPF_NODE, &ospf_log_adjacency_changes_cmd); | |
12871 | install_element(OSPF_NODE, &ospf_log_adjacency_changes_detail_cmd); | |
12872 | install_element(OSPF_NODE, &no_ospf_log_adjacency_changes_cmd); | |
12873 | install_element(OSPF_NODE, &no_ospf_log_adjacency_changes_detail_cmd); | |
12874 | ||
12875 | /* "ospf rfc1583-compatible" commands. */ | |
12876 | install_element(OSPF_NODE, &ospf_compatible_rfc1583_cmd); | |
12877 | install_element(OSPF_NODE, &no_ospf_compatible_rfc1583_cmd); | |
12878 | install_element(OSPF_NODE, &ospf_rfc1583_flag_cmd); | |
12879 | install_element(OSPF_NODE, &no_ospf_rfc1583_flag_cmd); | |
12880 | ||
12881 | /* "network area" commands. */ | |
12882 | install_element(OSPF_NODE, &ospf_network_area_cmd); | |
12883 | install_element(OSPF_NODE, &no_ospf_network_area_cmd); | |
12884 | ||
12885 | /* "area authentication" commands. */ | |
12886 | install_element(OSPF_NODE, | |
12887 | &ospf_area_authentication_message_digest_cmd); | |
12888 | install_element(OSPF_NODE, &ospf_area_authentication_cmd); | |
12889 | install_element(OSPF_NODE, &no_ospf_area_authentication_cmd); | |
12890 | ||
12891 | /* "area range" commands. */ | |
12892 | install_element(OSPF_NODE, &ospf_area_range_cmd); | |
12893 | install_element(OSPF_NODE, &ospf_area_range_cost_cmd); | |
12894 | install_element(OSPF_NODE, &ospf_area_range_not_advertise_cmd); | |
12895 | install_element(OSPF_NODE, &no_ospf_area_range_cmd); | |
12896 | install_element(OSPF_NODE, &ospf_area_range_substitute_cmd); | |
12897 | install_element(OSPF_NODE, &no_ospf_area_range_substitute_cmd); | |
12898 | ||
12899 | /* "area virtual-link" commands. */ | |
12900 | install_element(OSPF_NODE, &ospf_area_vlink_cmd); | |
12901 | install_element(OSPF_NODE, &ospf_area_vlink_intervals_cmd); | |
12902 | install_element(OSPF_NODE, &no_ospf_area_vlink_cmd); | |
12903 | install_element(OSPF_NODE, &no_ospf_area_vlink_intervals_cmd); | |
12904 | ||
12905 | ||
12906 | /* "area stub" commands. */ | |
12907 | install_element(OSPF_NODE, &ospf_area_stub_no_summary_cmd); | |
12908 | install_element(OSPF_NODE, &ospf_area_stub_cmd); | |
12909 | install_element(OSPF_NODE, &no_ospf_area_stub_no_summary_cmd); | |
12910 | install_element(OSPF_NODE, &no_ospf_area_stub_cmd); | |
12911 | ||
12912 | /* "area nssa" commands. */ | |
12913 | install_element(OSPF_NODE, &ospf_area_nssa_cmd); | |
d62a17ae | 12914 | install_element(OSPF_NODE, &ospf_area_nssa_translate_cmd); |
12915 | install_element(OSPF_NODE, &ospf_area_nssa_no_summary_cmd); | |
7ef56a73 | 12916 | install_element(OSPF_NODE, &no_ospf_area_nssa_no_summary_cmd); |
c317eddb | 12917 | install_element(OSPF_NODE, &ospf_area_nssa_suppress_fa_cmd); |
12918 | install_element(OSPF_NODE, &no_ospf_area_nssa_suppress_fa_cmd); | |
d62a17ae | 12919 | install_element(OSPF_NODE, &no_ospf_area_nssa_cmd); |
12920 | ||
12921 | install_element(OSPF_NODE, &ospf_area_default_cost_cmd); | |
12922 | install_element(OSPF_NODE, &no_ospf_area_default_cost_cmd); | |
12923 | ||
12924 | install_element(OSPF_NODE, &ospf_area_shortcut_cmd); | |
12925 | install_element(OSPF_NODE, &no_ospf_area_shortcut_cmd); | |
12926 | ||
12927 | install_element(OSPF_NODE, &ospf_area_export_list_cmd); | |
12928 | install_element(OSPF_NODE, &no_ospf_area_export_list_cmd); | |
12929 | ||
12930 | install_element(OSPF_NODE, &ospf_area_filter_list_cmd); | |
12931 | install_element(OSPF_NODE, &no_ospf_area_filter_list_cmd); | |
12932 | ||
12933 | install_element(OSPF_NODE, &ospf_area_import_list_cmd); | |
12934 | install_element(OSPF_NODE, &no_ospf_area_import_list_cmd); | |
12935 | ||
12936 | /* SPF timer commands */ | |
12937 | install_element(OSPF_NODE, &ospf_timers_throttle_spf_cmd); | |
12938 | install_element(OSPF_NODE, &no_ospf_timers_throttle_spf_cmd); | |
12939 | ||
12940 | /* LSA timers commands */ | |
12941 | install_element(OSPF_NODE, &ospf_timers_min_ls_interval_cmd); | |
12942 | install_element(OSPF_NODE, &no_ospf_timers_min_ls_interval_cmd); | |
0e88de35 QY |
12943 | install_element(OSPF_NODE, &ospf_timers_lsa_min_arrival_cmd); |
12944 | install_element(OSPF_NODE, &no_ospf_timers_lsa_min_arrival_cmd); | |
d62a17ae | 12945 | |
12946 | /* refresh timer commands */ | |
12947 | install_element(OSPF_NODE, &ospf_refresh_timer_cmd); | |
12948 | install_element(OSPF_NODE, &no_ospf_refresh_timer_val_cmd); | |
12949 | ||
12950 | /* max-metric commands */ | |
12951 | install_element(OSPF_NODE, &ospf_max_metric_router_lsa_admin_cmd); | |
12952 | install_element(OSPF_NODE, &no_ospf_max_metric_router_lsa_admin_cmd); | |
12953 | install_element(OSPF_NODE, &ospf_max_metric_router_lsa_startup_cmd); | |
12954 | install_element(OSPF_NODE, &no_ospf_max_metric_router_lsa_startup_cmd); | |
12955 | install_element(OSPF_NODE, &ospf_max_metric_router_lsa_shutdown_cmd); | |
12956 | install_element(OSPF_NODE, &no_ospf_max_metric_router_lsa_shutdown_cmd); | |
12957 | ||
12958 | /* reference bandwidth commands */ | |
12959 | install_element(OSPF_NODE, &ospf_auto_cost_reference_bandwidth_cmd); | |
12960 | install_element(OSPF_NODE, &no_ospf_auto_cost_reference_bandwidth_cmd); | |
12961 | ||
12962 | /* "neighbor" commands. */ | |
12963 | install_element(OSPF_NODE, &ospf_neighbor_cmd); | |
12964 | install_element(OSPF_NODE, &ospf_neighbor_poll_interval_cmd); | |
12965 | install_element(OSPF_NODE, &no_ospf_neighbor_cmd); | |
12966 | install_element(OSPF_NODE, &no_ospf_neighbor_poll_cmd); | |
12967 | ||
12968 | /* write multiplier commands */ | |
12969 | install_element(OSPF_NODE, &ospf_write_multiplier_cmd); | |
12970 | install_element(OSPF_NODE, &write_multiplier_cmd); | |
12971 | install_element(OSPF_NODE, &no_ospf_write_multiplier_cmd); | |
12972 | install_element(OSPF_NODE, &no_write_multiplier_cmd); | |
12973 | ||
a92706bb JU |
12974 | /* "proactive-arp" commands. */ |
12975 | install_element(OSPF_NODE, &ospf_proactive_arp_cmd); | |
12976 | install_element(OSPF_NODE, &no_ospf_proactive_arp_cmd); | |
12977 | ||
7fd0729f G |
12978 | /* TI-LFA commands */ |
12979 | install_element(OSPF_NODE, &ospf_ti_lfa_cmd); | |
12980 | install_element(OSPF_NODE, &no_ospf_ti_lfa_cmd); | |
12981 | ||
3d5b9855 | 12982 | /* Max path configurations */ |
12983 | install_element(OSPF_NODE, &ospf_max_multipath_cmd); | |
12984 | install_element(OSPF_NODE, &no_ospf_max_multipath_cmd); | |
12985 | ||
f5eef2d5 IR |
12986 | vrf_cmd_init(NULL, &ospfd_privs); |
12987 | ||
d62a17ae | 12988 | /* Init interface related vty commands. */ |
12989 | ospf_vty_if_init(); | |
12990 | ||
12991 | /* Init zebra related vty commands. */ | |
12992 | ospf_vty_zebra_init(); | |
718e3744 | 12993 | } |