]>
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 | |
ac2cb9bf | 160 | *vrf_name = VRF_DEFAULT_NAME; |
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 | 168 | *vrf_name = argv[idx_vrf + 1]->arg; |
c572fbfe DL |
169 | } |
170 | ||
409f98ab | 171 | return CMD_SUCCESS; |
43b8d1d8 CS |
172 | } |
173 | ||
52d0c099 | 174 | static void ospf_show_vrf_name(struct ospf *ospf, struct vty *vty, |
d7c0a89a | 175 | json_object *json, uint8_t use_vrf) |
52d0c099 | 176 | { |
b1c3ae8c CS |
177 | if (use_vrf) { |
178 | if (json) { | |
44076f4d RW |
179 | json_object_string_add(json, "vrfName", |
180 | ospf_get_name(ospf)); | |
b1c3ae8c | 181 | json_object_int_add(json, "vrfId", ospf->vrf_id); |
44076f4d RW |
182 | } else |
183 | vty_out(vty, "VRF Name: %s\n", ospf_get_name(ospf)); | |
52d0c099 | 184 | } |
52d0c099 CS |
185 | } |
186 | ||
43b8d1d8 | 187 | #ifndef VTYSH_EXTRACT_PL |
2e4c2296 | 188 | #include "ospfd/ospf_vty_clippy.c" |
43b8d1d8 CS |
189 | #endif |
190 | ||
191 | DEFUN_NOSH (router_ospf, | |
192 | router_ospf_cmd, | |
193 | "router ospf [{(1-65535)|vrf NAME}]", | |
194 | "Enable a routing process\n" | |
195 | "Start OSPF configuration\n" | |
196 | "Instance ID\n" | |
197 | VRF_CMD_HELP_STR) | |
198 | { | |
409f98ab IR |
199 | unsigned short instance; |
200 | const char *vrf_name; | |
201 | bool created = false; | |
202 | struct ospf *ospf; | |
203 | int ret; | |
43b8d1d8 | 204 | |
409f98ab IR |
205 | ret = ospf_router_cmd_parse(vty, argv, argc, &instance, &vrf_name); |
206 | if (ret != CMD_SUCCESS) | |
207 | return ret; | |
d62a17ae | 208 | |
409f98ab | 209 | if (instance != ospf_instance) { |
d62a17ae | 210 | VTY_PUSH_CONTEXT_NULL(OSPF_NODE); |
409f98ab | 211 | return CMD_NOT_MY_INSTANCE; |
d62a17ae | 212 | } |
213 | ||
409f98ab IR |
214 | ospf = ospf_get(instance, vrf_name, &created); |
215 | ||
216 | if (created) | |
217 | if (DFLT_OSPF_LOG_ADJACENCY_CHANGES) | |
218 | SET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES); | |
219 | ||
220 | if (IS_DEBUG_OSPF_EVENT) | |
221 | zlog_debug( | |
222 | "Config command 'router ospf %d' received, vrf %s id %u oi_running %u", | |
44076f4d RW |
223 | ospf->instance, ospf_get_name(ospf), ospf->vrf_id, |
224 | ospf->oi_running); | |
409f98ab IR |
225 | |
226 | VTY_PUSH_CONTEXT(OSPF_NODE, ospf); | |
227 | ||
64ac44f6 | 228 | return ret; |
718e3744 | 229 | } |
230 | ||
231 | DEFUN (no_router_ospf, | |
232 | no_router_ospf_cmd, | |
43b8d1d8 | 233 | "no router ospf [{(1-65535)|vrf NAME}]", |
718e3744 | 234 | NO_STR |
235 | "Enable a routing process\n" | |
7a7be519 | 236 | "Start OSPF configuration\n" |
b5a8894d CS |
237 | "Instance ID\n" |
238 | VRF_CMD_HELP_STR) | |
718e3744 | 239 | { |
409f98ab IR |
240 | unsigned short instance; |
241 | const char *vrf_name; | |
d62a17ae | 242 | struct ospf *ospf; |
409f98ab | 243 | int ret; |
b5a8894d | 244 | |
409f98ab IR |
245 | ret = ospf_router_cmd_parse(vty, argv, argc, &instance, &vrf_name); |
246 | if (ret != CMD_SUCCESS) | |
247 | return ret; | |
718e3744 | 248 | |
409f98ab IR |
249 | if (instance != ospf_instance) |
250 | return CMD_NOT_MY_INSTANCE; | |
251 | ||
252 | ospf = ospf_lookup(instance, vrf_name); | |
253 | if (ospf) | |
254 | ospf_finish(ospf); | |
255 | else | |
256 | ret = CMD_WARNING_CONFIG_FAILED; | |
257 | ||
258 | return ret; | |
718e3744 | 259 | } |
260 | ||
7c8ff89e | 261 | |
43b8d1d8 | 262 | DEFPY (ospf_router_id, |
718e3744 | 263 | ospf_router_id_cmd, |
264 | "ospf router-id A.B.C.D", | |
265 | "OSPF specific commands\n" | |
266 | "router-id for the OSPF process\n" | |
267 | "OSPF router-id in IP address format\n") | |
268 | { | |
a3d826f0 | 269 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
43b8d1d8 | 270 | |
d62a17ae | 271 | struct listnode *node; |
272 | struct ospf_area *area; | |
d62a17ae | 273 | |
274 | ospf->router_id_static = router_id; | |
275 | ||
276 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) | |
277 | if (area->full_nbrs) { | |
278 | vty_out(vty, | |
1b8049c7 | 279 | "For this router-id change to take effect, use \"clear ip ospf process\" command\n"); |
d62a17ae | 280 | return CMD_SUCCESS; |
281 | } | |
282 | ||
283 | ospf_router_id_update(ospf); | |
284 | ||
285 | return CMD_SUCCESS; | |
718e3744 | 286 | } |
287 | ||
7a7be519 | 288 | DEFUN_HIDDEN (ospf_router_id_old, |
747e489c DW |
289 | ospf_router_id_old_cmd, |
290 | "router-id A.B.C.D", | |
291 | "router-id for the OSPF process\n" | |
292 | "OSPF router-id in IP address format\n") | |
7a7be519 | 293 | { |
a3d826f0 | 294 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 295 | int idx_ipv4 = 1; |
296 | struct listnode *node; | |
297 | struct ospf_area *area; | |
298 | struct in_addr router_id; | |
299 | int ret; | |
300 | ||
301 | ret = inet_aton(argv[idx_ipv4]->arg, &router_id); | |
302 | if (!ret) { | |
303 | vty_out(vty, "Please specify Router ID by A.B.C.D\n"); | |
304 | return CMD_WARNING_CONFIG_FAILED; | |
305 | } | |
7a7be519 | 306 | |
d62a17ae | 307 | ospf->router_id_static = router_id; |
308 | ||
309 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) | |
310 | if (area->full_nbrs) { | |
311 | vty_out(vty, | |
1b8049c7 | 312 | "For this router-id change to take effect, use \"clear ip ospf process\" command\n"); |
d62a17ae | 313 | return CMD_SUCCESS; |
314 | } | |
315 | ||
316 | ospf_router_id_update(ospf); | |
317 | ||
318 | return CMD_SUCCESS; | |
7a7be519 | 319 | } |
747e489c | 320 | |
43b8d1d8 | 321 | DEFPY (no_ospf_router_id, |
718e3744 | 322 | no_ospf_router_id_cmd, |
7a7be519 | 323 | "no ospf router-id [A.B.C.D]", |
718e3744 | 324 | NO_STR |
325 | "OSPF specific commands\n" | |
7a7be519 | 326 | "router-id for the OSPF process\n" |
327 | "OSPF router-id in IP address format\n") | |
718e3744 | 328 | { |
a3d826f0 | 329 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 330 | struct listnode *node; |
331 | struct ospf_area *area; | |
68980084 | 332 | |
43b8d1d8 CS |
333 | if (router_id_str) { |
334 | if (!IPV4_ADDR_SAME(&ospf->router_id_static, &router_id)) { | |
335 | vty_out(vty, "%% OSPF router-id doesn't match\n"); | |
336 | return CMD_WARNING_CONFIG_FAILED; | |
337 | } | |
338 | } | |
339 | ||
d62a17ae | 340 | ospf->router_id_static.s_addr = 0; |
718e3744 | 341 | |
d62a17ae | 342 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) |
343 | if (area->full_nbrs) { | |
344 | vty_out(vty, | |
1b8049c7 | 345 | "For this router-id change to take effect, use \"clear ip ospf process\" command\n"); |
d62a17ae | 346 | return CMD_SUCCESS; |
347 | } | |
2c19a6ec | 348 | |
d62a17ae | 349 | ospf_router_id_update(ospf); |
718e3744 | 350 | |
d62a17ae | 351 | return CMD_SUCCESS; |
718e3744 | 352 | } |
353 | ||
718e3744 | 354 | |
3eec4ee0 IR |
355 | static void ospf_passive_interface_default_update(struct ospf *ospf, |
356 | uint8_t newval) | |
d62a17ae | 357 | { |
358 | struct listnode *ln; | |
d62a17ae | 359 | struct ospf_interface *oi; |
360 | ||
361 | ospf->passive_interface_default = newval; | |
362 | ||
3eec4ee0 IR |
363 | /* update multicast memberships */ |
364 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, ln, oi)) | |
d62a17ae | 365 | ospf_if_set_multicast(oi); |
d62a17ae | 366 | } |
367 | ||
82f0277b IR |
368 | static void ospf_passive_interface_update(struct interface *ifp, |
369 | struct ospf_if_params *params, | |
370 | struct in_addr addr, uint8_t newval) | |
d62a17ae | 371 | { |
3eec4ee0 | 372 | struct route_node *rn; |
d62a17ae | 373 | |
82f0277b IR |
374 | if (OSPF_IF_PARAM_CONFIGURED(params, passive_interface)) { |
375 | if (params->passive_interface == newval) | |
376 | return; | |
377 | ||
378 | params->passive_interface = newval; | |
379 | UNSET_IF_PARAM(params, passive_interface); | |
380 | if (params != IF_DEF_PARAMS(ifp)) { | |
381 | ospf_free_if_params(ifp, addr); | |
382 | ospf_if_update_params(ifp, addr); | |
383 | } | |
384 | } else { | |
385 | params->passive_interface = newval; | |
386 | SET_IF_PARAM(params, passive_interface); | |
387 | } | |
388 | ||
3eec4ee0 IR |
389 | /* |
390 | * XXX We should call ospf_if_set_multicast on exactly those | |
391 | * interfaces for which the passive property changed. It is too much | |
392 | * work to determine this set, so we do this for every interface. | |
393 | * This is safe and reasonable because ospf_if_set_multicast uses a | |
394 | * record of joined groups to avoid systems calls if the desired | |
395 | * memberships match the current memership. | |
396 | */ | |
d62a17ae | 397 | |
3eec4ee0 IR |
398 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { |
399 | struct ospf_interface *oi = rn->info; | |
d62a17ae | 400 | |
3eec4ee0 IR |
401 | if (oi) |
402 | ospf_if_set_multicast(oi); | |
d62a17ae | 403 | } |
3eec4ee0 IR |
404 | |
405 | /* | |
406 | * XXX It is not clear what state transitions the interface needs to | |
407 | * undergo when going from active to passive and vice versa. Fixing | |
408 | * this will require precise identification of interfaces having such a | |
409 | * transition. | |
410 | */ | |
d62a17ae | 411 | } |
412 | ||
3eec4ee0 IR |
413 | DEFUN (ospf_passive_interface_default, |
414 | ospf_passive_interface_default_cmd, | |
415 | "passive-interface default", | |
416 | "Suppress routing updates on an interface\n" | |
417 | "Suppress routing updates on interfaces by default\n") | |
d62a17ae | 418 | { |
3eec4ee0 IR |
419 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
420 | ||
421 | ospf_passive_interface_default_update(ospf, OSPF_IF_PASSIVE); | |
422 | ||
423 | return CMD_SUCCESS; | |
7ffa8fa2 PJ |
424 | } |
425 | ||
3eec4ee0 | 426 | DEFUN_HIDDEN (ospf_passive_interface_addr, |
a2c62831 | 427 | ospf_passive_interface_addr_cmd, |
3eec4ee0 | 428 | "passive-interface IFNAME [A.B.C.D]", |
718e3744 | 429 | "Suppress routing updates on an interface\n" |
7a7be519 | 430 | "Interface's name\n" |
3eec4ee0 | 431 | "IPv4 address\n") |
718e3744 | 432 | { |
a3d826f0 | 433 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 434 | int idx_ipv4 = 2; |
e99734f1 | 435 | struct interface *ifp = NULL; |
d62a17ae | 436 | struct in_addr addr = {.s_addr = INADDR_ANY}; |
d62a17ae | 437 | struct ospf_if_params *params; |
3eec4ee0 IR |
438 | int ret; |
439 | ||
440 | vty_out(vty, | |
441 | "This command is deprecated, because it is not VRF-aware.\n"); | |
442 | vty_out(vty, | |
443 | "Please, use \"ip ospf passive\" on an interface instead.\n"); | |
d62a17ae | 444 | |
e99734f1 | 445 | if (ospf->vrf_id != VRF_UNKNOWN) |
f60a1188 | 446 | ifp = if_get_by_name(argv[1]->arg, ospf->vrf_id, ospf->name); |
d62a17ae | 447 | |
b5a8894d | 448 | if (ifp == NULL) { |
996c9314 | 449 | vty_out(vty, "interface %s not found.\n", (char *)argv[1]->arg); |
e99734f1 | 450 | return CMD_WARNING_CONFIG_FAILED; |
b5a8894d | 451 | } |
d62a17ae | 452 | |
d62a17ae | 453 | if (argc == 3) { |
454 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
455 | if (!ret) { | |
456 | vty_out(vty, | |
457 | "Please specify interface address by A.B.C.D\n"); | |
458 | return CMD_WARNING_CONFIG_FAILED; | |
459 | } | |
460 | ||
461 | params = ospf_get_if_params(ifp, addr); | |
462 | ospf_if_update_params(ifp, addr); | |
3eec4ee0 IR |
463 | } else { |
464 | params = IF_DEF_PARAMS(ifp); | |
d62a17ae | 465 | } |
466 | ||
82f0277b | 467 | ospf_passive_interface_update(ifp, params, addr, OSPF_IF_PASSIVE); |
d62a17ae | 468 | |
3eec4ee0 IR |
469 | return CMD_SUCCESS; |
470 | } | |
d62a17ae | 471 | |
3eec4ee0 IR |
472 | DEFUN (no_ospf_passive_interface_default, |
473 | no_ospf_passive_interface_default_cmd, | |
474 | "no passive-interface default", | |
475 | NO_STR | |
476 | "Allow routing updates on an interface\n" | |
477 | "Allow routing updates on interfaces by default\n") | |
478 | { | |
479 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
480 | ||
481 | ospf_passive_interface_default_update(ospf, OSPF_IF_ACTIVE); | |
d62a17ae | 482 | |
483 | return CMD_SUCCESS; | |
718e3744 | 484 | } |
485 | ||
3eec4ee0 | 486 | DEFUN_HIDDEN (no_ospf_passive_interface, |
a2c62831 | 487 | no_ospf_passive_interface_addr_cmd, |
3eec4ee0 | 488 | "no passive-interface IFNAME [A.B.C.D]", |
718e3744 | 489 | NO_STR |
490 | "Allow routing updates on an interface\n" | |
7a7be519 | 491 | "Interface's name\n" |
3eec4ee0 | 492 | "IPv4 address\n") |
718e3744 | 493 | { |
a3d826f0 | 494 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 495 | int idx_ipv4 = 3; |
e99734f1 | 496 | struct interface *ifp = NULL; |
d62a17ae | 497 | struct in_addr addr = {.s_addr = INADDR_ANY}; |
498 | struct ospf_if_params *params; | |
499 | int ret; | |
d62a17ae | 500 | |
3eec4ee0 IR |
501 | vty_out(vty, |
502 | "This command is deprecated, because it is not VRF-aware.\n"); | |
503 | vty_out(vty, | |
504 | "Please, use \"no ip ospf passive\" on an interface instead.\n"); | |
43540886 | 505 | |
e99734f1 | 506 | if (ospf->vrf_id != VRF_UNKNOWN) |
f60a1188 | 507 | ifp = if_get_by_name(argv[2]->arg, ospf->vrf_id, ospf->name); |
e99734f1 | 508 | |
b5a8894d | 509 | if (ifp == NULL) { |
996c9314 | 510 | vty_out(vty, "interface %s not found.\n", (char *)argv[2]->arg); |
e99734f1 | 511 | return CMD_WARNING_CONFIG_FAILED; |
b5a8894d | 512 | } |
ba6454ec | 513 | |
d62a17ae | 514 | if (argc == 4) { |
515 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
516 | if (!ret) { | |
517 | vty_out(vty, | |
518 | "Please specify interface address by A.B.C.D\n"); | |
519 | return CMD_WARNING_CONFIG_FAILED; | |
520 | } | |
d62a17ae | 521 | params = ospf_lookup_if_params(ifp, addr); |
522 | if (params == NULL) | |
523 | return CMD_SUCCESS; | |
3eec4ee0 IR |
524 | } else { |
525 | params = IF_DEF_PARAMS(ifp); | |
d62a17ae | 526 | } |
d62a17ae | 527 | |
82f0277b | 528 | ospf_passive_interface_update(ifp, params, addr, OSPF_IF_ACTIVE); |
3eec4ee0 | 529 | |
d62a17ae | 530 | return CMD_SUCCESS; |
718e3744 | 531 | } |
532 | ||
718e3744 | 533 | |
a2c62831 | 534 | DEFUN (ospf_network_area, |
535 | ospf_network_area_cmd, | |
6147e2c6 | 536 | "network A.B.C.D/M area <A.B.C.D|(0-4294967295)>", |
718e3744 | 537 | "Enable routing on an IP network\n" |
538 | "OSPF network prefix\n" | |
539 | "Set the OSPF area ID\n" | |
540 | "OSPF area ID in IP address format\n" | |
541 | "OSPF area ID as a decimal value\n") | |
542 | { | |
a3d826f0 | 543 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 544 | int idx_ipv4_prefixlen = 1; |
545 | int idx_ipv4_number = 3; | |
546 | struct prefix_ipv4 p; | |
547 | struct in_addr area_id; | |
548 | int ret, format; | |
cbf32f74 | 549 | uint32_t count; |
d62a17ae | 550 | |
551 | if (ospf->instance) { | |
552 | vty_out(vty, | |
553 | "The network command is not supported in multi-instance ospf\n"); | |
554 | return CMD_WARNING_CONFIG_FAILED; | |
555 | } | |
718e3744 | 556 | |
cbf32f74 IR |
557 | count = ospf_count_area_params(ospf); |
558 | if (count > 0) { | |
d62a17ae | 559 | vty_out(vty, |
560 | "Please remove all ip ospf area x.x.x.x commands first.\n"); | |
aed7cc62 | 561 | if (IS_DEBUG_OSPF_EVENT) |
996c9314 | 562 | zlog_debug( |
d12566a1 | 563 | "%s ospf vrf %s num of %u ip ospf area x config", |
44076f4d | 564 | __func__, ospf_get_name(ospf), count); |
d62a17ae | 565 | return CMD_WARNING_CONFIG_FAILED; |
566 | } | |
567 | ||
568 | /* Get network prefix and Area ID. */ | |
569 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); | |
570 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); | |
571 | ||
572 | ret = ospf_network_set(ospf, &p, area_id, format); | |
573 | if (ret == 0) { | |
574 | vty_out(vty, "There is already same network statement.\n"); | |
2b0a905a | 575 | return CMD_WARNING_CONFIG_FAILED; |
d62a17ae | 576 | } |
577 | ||
578 | return CMD_SUCCESS; | |
718e3744 | 579 | } |
580 | ||
a2c62831 | 581 | DEFUN (no_ospf_network_area, |
582 | no_ospf_network_area_cmd, | |
6147e2c6 | 583 | "no network A.B.C.D/M area <A.B.C.D|(0-4294967295)>", |
718e3744 | 584 | NO_STR |
585 | "Enable routing on an IP network\n" | |
586 | "OSPF network prefix\n" | |
587 | "Set the OSPF area ID\n" | |
588 | "OSPF area ID in IP address format\n" | |
589 | "OSPF area ID as a decimal value\n") | |
590 | { | |
a3d826f0 | 591 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 592 | int idx_ipv4_prefixlen = 2; |
593 | int idx_ipv4_number = 4; | |
594 | struct prefix_ipv4 p; | |
595 | struct in_addr area_id; | |
596 | int ret, format; | |
597 | ||
598 | if (ospf->instance) { | |
599 | vty_out(vty, | |
600 | "The network command is not supported in multi-instance ospf\n"); | |
601 | return CMD_WARNING_CONFIG_FAILED; | |
602 | } | |
718e3744 | 603 | |
d62a17ae | 604 | /* Get network prefix and Area ID. */ |
605 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); | |
606 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); | |
607 | ||
608 | ret = ospf_network_unset(ospf, &p, area_id); | |
609 | if (ret == 0) { | |
610 | vty_out(vty, | |
611 | "Can't find specified network area configuration.\n"); | |
612 | return CMD_WARNING_CONFIG_FAILED; | |
613 | } | |
614 | ||
615 | return CMD_SUCCESS; | |
718e3744 | 616 | } |
617 | ||
a2c62831 | 618 | DEFUN (ospf_area_range, |
619 | ospf_area_range_cmd, | |
7a7be519 | 620 | "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M [advertise [cost (0-16777215)]]", |
718e3744 | 621 | "OSPF area parameters\n" |
622 | "OSPF area ID in IP address format\n" | |
623 | "OSPF area ID as a decimal value\n" | |
624 | "Summarize routes matching address/mask (border routers only)\n" | |
7a7be519 | 625 | "Area range prefix\n" |
626 | "Advertise this range (default)\n" | |
627 | "User specified metric for this range\n" | |
628 | "Advertised metric for this range\n") | |
718e3744 | 629 | { |
a3d826f0 | 630 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 631 | int idx_ipv4_number = 1; |
632 | int idx_ipv4_prefixlen = 3; | |
633 | int idx_cost = 6; | |
634 | struct prefix_ipv4 p; | |
635 | struct in_addr area_id; | |
636 | int format; | |
d7c0a89a | 637 | uint32_t cost; |
d62a17ae | 638 | |
639 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); | |
640 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); | |
641 | ||
642 | ospf_area_range_set(ospf, area_id, &p, OSPF_AREA_RANGE_ADVERTISE); | |
ed709ed1 GW |
643 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), |
644 | format); | |
d62a17ae | 645 | if (argc > 5) { |
646 | cost = strtoul(argv[idx_cost]->arg, NULL, 10); | |
647 | ospf_area_range_cost_set(ospf, area_id, &p, cost); | |
648 | } | |
718e3744 | 649 | |
d62a17ae | 650 | return CMD_SUCCESS; |
718e3744 | 651 | } |
652 | ||
7a7be519 | 653 | DEFUN (ospf_area_range_cost, |
654 | ospf_area_range_cost_cmd, | |
ec88a72a | 655 | "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M {cost (0-16777215)|substitute A.B.C.D/M}", |
7a7be519 | 656 | "OSPF area parameters\n" |
657 | "OSPF area ID in IP address format\n" | |
658 | "OSPF area ID as a decimal value\n" | |
659 | "Summarize routes matching address/mask (border routers only)\n" | |
660 | "Area range prefix\n" | |
661 | "User specified metric for this range\n" | |
ec88a72a | 662 | "Advertised metric for this range\n" |
663 | "Announce area range as another prefix\n" | |
664 | "Network prefix to be announced instead of range\n") | |
7a7be519 | 665 | { |
a3d826f0 | 666 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 667 | int idx_ipv4_number = 1; |
668 | int idx_ipv4_prefixlen = 3; | |
ec88a72a | 669 | int idx = 4; |
670 | struct prefix_ipv4 p, s; | |
d62a17ae | 671 | struct in_addr area_id; |
672 | int format; | |
d7c0a89a | 673 | uint32_t cost; |
7a7be519 | 674 | |
d62a17ae | 675 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
676 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); | |
7a7be519 | 677 | |
d62a17ae | 678 | ospf_area_range_set(ospf, area_id, &p, OSPF_AREA_RANGE_ADVERTISE); |
679 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
680 | format); | |
718e3744 | 681 | |
ec88a72a | 682 | if (argv_find(argv, argc, "cost", &idx)) { |
683 | cost = strtoul(argv[idx + 1]->arg, NULL, 10); | |
684 | ospf_area_range_cost_set(ospf, area_id, &p, cost); | |
685 | } | |
686 | ||
687 | idx = 4; | |
688 | if (argv_find(argv, argc, "substitute", &idx)) { | |
689 | str2prefix_ipv4(argv[idx + 1]->arg, &s); | |
690 | ospf_area_range_substitute_set(ospf, area_id, &p, &s); | |
691 | } | |
718e3744 | 692 | |
d62a17ae | 693 | return CMD_SUCCESS; |
7a7be519 | 694 | } |
718e3744 | 695 | |
a2c62831 | 696 | DEFUN (ospf_area_range_not_advertise, |
697 | ospf_area_range_not_advertise_cmd, | |
6147e2c6 | 698 | "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M not-advertise", |
718e3744 | 699 | "OSPF area parameters\n" |
700 | "OSPF area ID in IP address format\n" | |
701 | "OSPF area ID as a decimal value\n" | |
702 | "Summarize routes matching address/mask (border routers only)\n" | |
703 | "Area range prefix\n" | |
704 | "DoNotAdvertise this range\n") | |
705 | { | |
a3d826f0 | 706 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 707 | int idx_ipv4_number = 1; |
708 | int idx_ipv4_prefixlen = 3; | |
709 | struct prefix_ipv4 p; | |
710 | struct in_addr area_id; | |
711 | int format; | |
718e3744 | 712 | |
d62a17ae | 713 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
714 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); | |
718e3744 | 715 | |
d62a17ae | 716 | ospf_area_range_set(ospf, area_id, &p, 0); |
717 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
718 | format); | |
990baca0 | 719 | ospf_area_range_substitute_unset(ospf, area_id, &p); |
718e3744 | 720 | |
d62a17ae | 721 | return CMD_SUCCESS; |
718e3744 | 722 | } |
723 | ||
a2c62831 | 724 | DEFUN (no_ospf_area_range, |
725 | no_ospf_area_range_cmd, | |
3a2d747c | 726 | "no area <A.B.C.D|(0-4294967295)> range A.B.C.D/M [<cost (0-16777215)|advertise [cost (0-16777215)]|not-advertise>]", |
718e3744 | 727 | NO_STR |
728 | "OSPF area parameters\n" | |
729 | "OSPF area ID in IP address format\n" | |
730 | "OSPF area ID as a decimal value\n" | |
731 | "Summarize routes matching address/mask (border routers only)\n" | |
7a7be519 | 732 | "Area range prefix\n" |
3a2d747c QY |
733 | "User specified metric for this range\n" |
734 | "Advertised metric for this range\n" | |
7a7be519 | 735 | "Advertise this range (default)\n" |
3a2d747c QY |
736 | "User specified metric for this range\n" |
737 | "Advertised metric for this range\n" | |
7a7be519 | 738 | "DoNotAdvertise this range\n") |
718e3744 | 739 | { |
a3d826f0 | 740 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 741 | int idx_ipv4_number = 2; |
742 | int idx_ipv4_prefixlen = 4; | |
743 | struct prefix_ipv4 p; | |
744 | struct in_addr area_id; | |
745 | int format; | |
718e3744 | 746 | |
d62a17ae | 747 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
748 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); | |
718e3744 | 749 | |
d62a17ae | 750 | ospf_area_range_unset(ospf, area_id, &p); |
718e3744 | 751 | |
d62a17ae | 752 | return CMD_SUCCESS; |
718e3744 | 753 | } |
754 | ||
a2c62831 | 755 | DEFUN (no_ospf_area_range_substitute, |
756 | no_ospf_area_range_substitute_cmd, | |
6147e2c6 | 757 | "no area <A.B.C.D|(0-4294967295)> range A.B.C.D/M substitute A.B.C.D/M", |
718e3744 | 758 | NO_STR |
759 | "OSPF area parameters\n" | |
760 | "OSPF area ID in IP address format\n" | |
761 | "OSPF area ID as a decimal value\n" | |
762 | "Summarize routes matching address/mask (border routers only)\n" | |
763 | "Area range prefix\n" | |
764 | "Announce area range as another prefix\n" | |
765 | "Network prefix to be announced instead of range\n") | |
766 | { | |
a3d826f0 | 767 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 768 | int idx_ipv4_number = 2; |
769 | int idx_ipv4_prefixlen = 4; | |
770 | int idx_ipv4_prefixlen_2 = 6; | |
771 | struct prefix_ipv4 p, s; | |
772 | struct in_addr area_id; | |
773 | int format; | |
718e3744 | 774 | |
d62a17ae | 775 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
776 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); | |
777 | str2prefix_ipv4(argv[idx_ipv4_prefixlen_2]->arg, &s); | |
718e3744 | 778 | |
d62a17ae | 779 | ospf_area_range_substitute_unset(ospf, area_id, &p); |
718e3744 | 780 | |
d62a17ae | 781 | return CMD_SUCCESS; |
718e3744 | 782 | } |
783 | ||
6b0655a2 | 784 | |
718e3744 | 785 | /* Command Handler Logic in VLink stuff is delicate!! |
786 | ||
787 | ALTER AT YOUR OWN RISK!!!! | |
788 | ||
789 | Various dummy values are used to represent 'NoChange' state for | |
790 | VLink configuration NOT being changed by a VLink command, and | |
791 | special syntax is used within the command strings so that the | |
792 | typed in command verbs can be seen in the configuration command | |
793 | bacckend handler. This is to drastically reduce the verbeage | |
794 | required to coe up with a reasonably compatible Cisco VLink command | |
795 | ||
d62a17ae | 796 | - Matthew Grant <grantma@anathoth.gen.nz> |
718e3744 | 797 | Wed, 21 Feb 2001 15:13:52 +1300 |
798 | */ | |
799 | ||
d62a17ae | 800 | /* Configuration data for virtual links |
801 | */ | |
718e3744 | 802 | struct ospf_vl_config_data { |
d62a17ae | 803 | struct vty *vty; /* vty stuff */ |
804 | struct in_addr area_id; /* area ID from command line */ | |
805 | int area_id_fmt; /* command line area ID format */ | |
806 | struct in_addr vl_peer; /* command line vl_peer */ | |
807 | int auth_type; /* Authehntication type, if given */ | |
808 | char *auth_key; /* simple password if present */ | |
809 | int crypto_key_id; /* Cryptographic key ID */ | |
810 | char *md5_key; /* MD5 authentication key */ | |
811 | int hello_interval; /* Obvious what these are... */ | |
812 | int retransmit_interval; | |
813 | int transmit_delay; | |
814 | int dead_interval; | |
718e3744 | 815 | }; |
816 | ||
d62a17ae | 817 | static void ospf_vl_config_data_init(struct ospf_vl_config_data *vl_config, |
818 | struct vty *vty) | |
718e3744 | 819 | { |
d62a17ae | 820 | memset(vl_config, 0, sizeof(struct ospf_vl_config_data)); |
821 | vl_config->auth_type = OSPF_AUTH_CMD_NOTSEEN; | |
822 | vl_config->vty = vty; | |
718e3744 | 823 | } |
824 | ||
4dadc291 | 825 | static struct ospf_vl_data * |
d62a17ae | 826 | ospf_find_vl_data(struct ospf *ospf, struct ospf_vl_config_data *vl_config) |
827 | { | |
828 | struct ospf_area *area; | |
829 | struct ospf_vl_data *vl_data; | |
830 | struct vty *vty; | |
831 | struct in_addr area_id; | |
832 | ||
833 | vty = vl_config->vty; | |
834 | area_id = vl_config->area_id; | |
835 | ||
836 | if (area_id.s_addr == OSPF_AREA_BACKBONE) { | |
837 | vty_out(vty, | |
838 | "Configuring VLs over the backbone is not allowed\n"); | |
839 | return NULL; | |
840 | } | |
841 | area = ospf_area_get(ospf, area_id); | |
842 | ospf_area_display_format_set(ospf, area, vl_config->area_id_fmt); | |
843 | ||
844 | if (area->external_routing != OSPF_AREA_DEFAULT) { | |
845 | if (vl_config->area_id_fmt == OSPF_AREA_ID_FMT_DOTTEDQUAD) | |
96b663a3 | 846 | vty_out(vty, "Area %pI4 is %s\n", &area_id, |
d62a17ae | 847 | area->external_routing == OSPF_AREA_NSSA |
848 | ? "nssa" | |
849 | : "stub"); | |
850 | else | |
851 | vty_out(vty, "Area %ld is %s\n", | |
d7c0a89a | 852 | (unsigned long)ntohl(area_id.s_addr), |
d62a17ae | 853 | area->external_routing == OSPF_AREA_NSSA |
854 | ? "nssa" | |
855 | : "stub"); | |
856 | return NULL; | |
857 | } | |
858 | ||
859 | if ((vl_data = ospf_vl_lookup(ospf, area, vl_config->vl_peer)) | |
860 | == NULL) { | |
861 | vl_data = ospf_vl_data_new(area, vl_config->vl_peer); | |
862 | if (vl_data->vl_oi == NULL) { | |
863 | vl_data->vl_oi = ospf_vl_new(ospf, vl_data); | |
864 | ospf_vl_add(ospf, vl_data); | |
865 | ospf_spf_calculate_schedule(ospf, | |
866 | SPF_FLAG_CONFIG_CHANGE); | |
867 | } | |
718e3744 | 868 | } |
d62a17ae | 869 | return vl_data; |
718e3744 | 870 | } |
871 | ||
872 | ||
d62a17ae | 873 | static int ospf_vl_set_security(struct ospf_vl_data *vl_data, |
874 | struct ospf_vl_config_data *vl_config) | |
875 | { | |
876 | struct crypt_key *ck; | |
877 | struct vty *vty; | |
878 | struct interface *ifp = vl_data->vl_oi->ifp; | |
879 | ||
880 | vty = vl_config->vty; | |
881 | ||
882 | if (vl_config->auth_type != OSPF_AUTH_CMD_NOTSEEN) { | |
883 | SET_IF_PARAM(IF_DEF_PARAMS(ifp), auth_type); | |
884 | IF_DEF_PARAMS(ifp)->auth_type = vl_config->auth_type; | |
718e3744 | 885 | } |
718e3744 | 886 | |
d62a17ae | 887 | if (vl_config->auth_key) { |
888 | memset(IF_DEF_PARAMS(ifp)->auth_simple, 0, | |
889 | OSPF_AUTH_SIMPLE_SIZE + 1); | |
4d65d927 QY |
890 | strlcpy((char *)IF_DEF_PARAMS(ifp)->auth_simple, |
891 | vl_config->auth_key, | |
892 | sizeof(IF_DEF_PARAMS(ifp)->auth_simple)); | |
d62a17ae | 893 | } else if (vl_config->md5_key) { |
894 | if (ospf_crypt_key_lookup(IF_DEF_PARAMS(ifp)->auth_crypt, | |
895 | vl_config->crypto_key_id) | |
896 | != NULL) { | |
897 | vty_out(vty, "OSPF: Key %d already exists\n", | |
898 | vl_config->crypto_key_id); | |
851fcbae | 899 | return CMD_WARNING; |
d62a17ae | 900 | } |
901 | ck = ospf_crypt_key_new(); | |
902 | ck->key_id = vl_config->crypto_key_id; | |
903 | memset(ck->auth_key, 0, OSPF_AUTH_MD5_SIZE + 1); | |
4d65d927 QY |
904 | strlcpy((char *)ck->auth_key, vl_config->md5_key, |
905 | sizeof(ck->auth_key)); | |
d62a17ae | 906 | |
907 | ospf_crypt_key_add(IF_DEF_PARAMS(ifp)->auth_crypt, ck); | |
908 | } else if (vl_config->crypto_key_id != 0) { | |
909 | /* Delete a key */ | |
910 | ||
911 | if (ospf_crypt_key_lookup(IF_DEF_PARAMS(ifp)->auth_crypt, | |
912 | vl_config->crypto_key_id) | |
913 | == NULL) { | |
914 | vty_out(vty, "OSPF: Key %d does not exist\n", | |
915 | vl_config->crypto_key_id); | |
916 | return CMD_WARNING_CONFIG_FAILED; | |
917 | } | |
918 | ||
919 | ospf_crypt_key_delete(IF_DEF_PARAMS(ifp)->auth_crypt, | |
920 | vl_config->crypto_key_id); | |
921 | } | |
922 | ||
923 | return CMD_SUCCESS; | |
718e3744 | 924 | } |
925 | ||
d62a17ae | 926 | static int ospf_vl_set_timers(struct ospf_vl_data *vl_data, |
927 | struct ospf_vl_config_data *vl_config) | |
928 | { | |
929 | struct interface *ifp = vl_data->vl_oi->ifp; | |
930 | /* Virtual Link data initialised to defaults, so only set | |
931 | if a value given */ | |
932 | if (vl_config->hello_interval) { | |
933 | SET_IF_PARAM(IF_DEF_PARAMS(ifp), v_hello); | |
934 | IF_DEF_PARAMS(ifp)->v_hello = vl_config->hello_interval; | |
935 | } | |
936 | ||
937 | if (vl_config->dead_interval) { | |
938 | SET_IF_PARAM(IF_DEF_PARAMS(ifp), v_wait); | |
939 | IF_DEF_PARAMS(ifp)->v_wait = vl_config->dead_interval; | |
940 | } | |
941 | ||
942 | if (vl_config->retransmit_interval) { | |
943 | SET_IF_PARAM(IF_DEF_PARAMS(ifp), retransmit_interval); | |
944 | IF_DEF_PARAMS(ifp)->retransmit_interval = | |
945 | vl_config->retransmit_interval; | |
946 | } | |
947 | ||
948 | if (vl_config->transmit_delay) { | |
949 | SET_IF_PARAM(IF_DEF_PARAMS(ifp), transmit_delay); | |
950 | IF_DEF_PARAMS(ifp)->transmit_delay = vl_config->transmit_delay; | |
951 | } | |
952 | ||
953 | return CMD_SUCCESS; | |
718e3744 | 954 | } |
955 | ||
956 | ||
718e3744 | 957 | /* The business end of all of the above */ |
d62a17ae | 958 | static int ospf_vl_set(struct ospf *ospf, struct ospf_vl_config_data *vl_config) |
959 | { | |
960 | struct ospf_vl_data *vl_data; | |
961 | int ret; | |
718e3744 | 962 | |
d62a17ae | 963 | vl_data = ospf_find_vl_data(ospf, vl_config); |
964 | if (!vl_data) | |
965 | return CMD_WARNING_CONFIG_FAILED; | |
966 | ||
967 | /* Process this one first as it can have a fatal result, which can | |
968 | only logically occur if the virtual link exists already | |
969 | Thus a command error does not result in a change to the | |
970 | running configuration such as unexpectedly altered timer | |
971 | values etc.*/ | |
972 | ret = ospf_vl_set_security(vl_data, vl_config); | |
973 | if (ret != CMD_SUCCESS) | |
974 | return ret; | |
975 | ||
976 | /* Set any time based parameters, these area already range checked */ | |
977 | ||
978 | ret = ospf_vl_set_timers(vl_data, vl_config); | |
979 | if (ret != CMD_SUCCESS) | |
980 | return ret; | |
718e3744 | 981 | |
d62a17ae | 982 | return CMD_SUCCESS; |
718e3744 | 983 | } |
984 | ||
985 | /* This stuff exists to make specifying all the alias commands A LOT simpler | |
986 | */ | |
d62a17ae | 987 | #define VLINK_HELPSTR_IPADDR \ |
988 | "OSPF area parameters\n" \ | |
989 | "OSPF area ID in IP address format\n" \ | |
990 | "OSPF area ID as a decimal value\n" \ | |
991 | "Configure a virtual link\n" \ | |
992 | "Router ID of the remote ABR\n" | |
993 | ||
994 | #define VLINK_HELPSTR_AUTHTYPE_SIMPLE \ | |
995 | "Enable authentication on this virtual link\n" \ | |
996 | "dummy string \n" | |
997 | ||
998 | #define VLINK_HELPSTR_AUTHTYPE_ALL \ | |
999 | VLINK_HELPSTR_AUTHTYPE_SIMPLE \ | |
1000 | "Use null authentication\n" \ | |
1001 | "Use message-digest authentication\n" | |
1002 | ||
1003 | #define VLINK_HELPSTR_TIME_PARAM \ | |
1004 | "Time between HELLO packets\n" \ | |
1005 | "Seconds\n" \ | |
1006 | "Time between retransmitting lost link state advertisements\n" \ | |
1007 | "Seconds\n" \ | |
1008 | "Link state transmit delay\n" \ | |
1009 | "Seconds\n" \ | |
1010 | "Interval time after which a neighbor is declared down\n" \ | |
1011 | "Seconds\n" | |
1012 | ||
1013 | #define VLINK_HELPSTR_AUTH_SIMPLE \ | |
1014 | "Authentication password (key)\n" \ | |
baf9eaad | 1015 | "The OSPF password (key)\n" |
d62a17ae | 1016 | |
1017 | #define VLINK_HELPSTR_AUTH_MD5 \ | |
1018 | "Message digest authentication password (key)\n" \ | |
d62a17ae | 1019 | "Key ID\n" \ |
1020 | "Use MD5 algorithm\n" \ | |
baf9eaad | 1021 | "The OSPF password (key)\n" |
718e3744 | 1022 | |
a2c62831 | 1023 | DEFUN (ospf_area_vlink, |
1024 | ospf_area_vlink_cmd, | |
3d1c6dc2 | 1025 | "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 | 1026 | VLINK_HELPSTR_IPADDR |
3d1c6dc2 | 1027 | "Enable authentication on this virtual link\n" |
7a7be519 | 1028 | "Use message-digest authentication\n" |
3d1c6dc2 | 1029 | "Use null authentication\n" |
baf9eaad CS |
1030 | VLINK_HELPSTR_AUTH_MD5 |
1031 | VLINK_HELPSTR_AUTH_SIMPLE) | |
718e3744 | 1032 | { |
a3d826f0 | 1033 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1034 | int idx_ipv4_number = 1; |
1035 | int idx_ipv4 = 3; | |
1036 | struct ospf_vl_config_data vl_config; | |
1037 | char auth_key[OSPF_AUTH_SIMPLE_SIZE + 1]; | |
1038 | char md5_key[OSPF_AUTH_MD5_SIZE + 1]; | |
d62a17ae | 1039 | int ret; |
55d1da24 | 1040 | int idx = 0; |
d62a17ae | 1041 | |
1042 | ospf_vl_config_data_init(&vl_config, vty); | |
1043 | ||
1044 | /* Read off first 2 parameters and check them */ | |
1045 | ret = str2area_id(argv[idx_ipv4_number]->arg, &vl_config.area_id, | |
1046 | &vl_config.area_id_fmt); | |
1047 | if (ret < 0) { | |
1048 | vty_out(vty, "OSPF area ID is invalid\n"); | |
1049 | return CMD_WARNING_CONFIG_FAILED; | |
1050 | } | |
718e3744 | 1051 | |
d62a17ae | 1052 | ret = inet_aton(argv[idx_ipv4]->arg, &vl_config.vl_peer); |
1053 | if (!ret) { | |
1054 | vty_out(vty, "Please specify valid Router ID as a.b.c.d\n"); | |
1055 | return CMD_WARNING_CONFIG_FAILED; | |
7a7be519 | 1056 | } |
7a7be519 | 1057 | |
d62a17ae | 1058 | if (argc <= 4) { |
1059 | /* Thats all folks! - BUGS B. strikes again!!!*/ | |
7a7be519 | 1060 | |
d62a17ae | 1061 | return ospf_vl_set(ospf, &vl_config); |
1062 | } | |
1063 | ||
3d1c6dc2 CS |
1064 | if (argv_find(argv, argc, "authentication", &idx)) { |
1065 | /* authentication - this option can only occur | |
1066 | at start of command line */ | |
1067 | vl_config.auth_type = OSPF_AUTH_SIMPLE; | |
1068 | } | |
1069 | ||
3d1c6dc2 | 1070 | if (argv_find(argv, argc, "message-digest", &idx)) { |
baf9eaad | 1071 | /* authentication message-digest */ |
3d1c6dc2 CS |
1072 | vl_config.auth_type = OSPF_AUTH_CRYPTOGRAPHIC; |
1073 | } else if (argv_find(argv, argc, "null", &idx)) { | |
1074 | /* "authentication null" */ | |
1075 | vl_config.auth_type = OSPF_AUTH_NULL; | |
d62a17ae | 1076 | } |
7a7be519 | 1077 | |
3d1c6dc2 | 1078 | if (argv_find(argv, argc, "message-digest-key", &idx)) { |
3d1c6dc2 | 1079 | vl_config.md5_key = NULL; |
cbb9b53d | 1080 | vl_config.crypto_key_id = strtol(argv[idx + 1]->arg, NULL, 10); |
3d1c6dc2 CS |
1081 | if (vl_config.crypto_key_id < 0) |
1082 | return CMD_WARNING_CONFIG_FAILED; | |
1083 | ||
4d65d927 | 1084 | strlcpy(md5_key, argv[idx + 3]->arg, sizeof(md5_key)); |
3d1c6dc2 CS |
1085 | vl_config.md5_key = md5_key; |
1086 | } | |
1087 | ||
3d1c6dc2 | 1088 | if (argv_find(argv, argc, "authentication-key", &idx)) { |
4d65d927 | 1089 | strlcpy(auth_key, argv[idx + 1]->arg, sizeof(auth_key)); |
3d1c6dc2 CS |
1090 | vl_config.auth_key = auth_key; |
1091 | } | |
7a7be519 | 1092 | |
d62a17ae | 1093 | /* Action configuration */ |
1094 | ||
1095 | return ospf_vl_set(ospf, &vl_config); | |
7a7be519 | 1096 | } |
1097 | ||
a2c62831 | 1098 | DEFUN (no_ospf_area_vlink, |
1099 | no_ospf_area_vlink_cmd, | |
3d1c6dc2 | 1100 | "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 | 1101 | NO_STR |
7a7be519 | 1102 | VLINK_HELPSTR_IPADDR |
7e5ee522 IR |
1103 | "Enable authentication on this virtual link\n" |
1104 | "Use message-digest authentication\n" | |
1105 | "Use null authentication\n" | |
baf9eaad CS |
1106 | VLINK_HELPSTR_AUTH_MD5 |
1107 | VLINK_HELPSTR_AUTH_SIMPLE) | |
718e3744 | 1108 | { |
a3d826f0 | 1109 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1110 | int idx_ipv4_number = 2; |
1111 | int idx_ipv4 = 4; | |
1112 | struct ospf_area *area; | |
1113 | struct ospf_vl_config_data vl_config; | |
1114 | struct ospf_vl_data *vl_data = NULL; | |
1115 | char auth_key[OSPF_AUTH_SIMPLE_SIZE + 1]; | |
3d1c6dc2 | 1116 | int idx = 0; |
d62a17ae | 1117 | int ret, format; |
1118 | ||
1119 | ospf_vl_config_data_init(&vl_config, vty); | |
1120 | ||
1121 | ret = str2area_id(argv[idx_ipv4_number]->arg, &vl_config.area_id, | |
1122 | &format); | |
1123 | if (ret < 0) { | |
1124 | vty_out(vty, "OSPF area ID is invalid\n"); | |
1125 | return CMD_WARNING_CONFIG_FAILED; | |
1126 | } | |
1127 | ||
1128 | area = ospf_area_lookup_by_area_id(ospf, vl_config.area_id); | |
1129 | if (!area) { | |
1130 | vty_out(vty, "Area does not exist\n"); | |
1131 | return CMD_WARNING_CONFIG_FAILED; | |
1132 | } | |
1133 | ||
1134 | ret = inet_aton(argv[idx_ipv4]->arg, &vl_config.vl_peer); | |
1135 | if (!ret) { | |
1136 | vty_out(vty, "Please specify valid Router ID as a.b.c.d\n"); | |
1137 | return CMD_WARNING_CONFIG_FAILED; | |
1138 | } | |
718e3744 | 1139 | |
188823b0 EDP |
1140 | vl_data = ospf_vl_lookup(ospf, area, vl_config.vl_peer); |
1141 | if (!vl_data) { | |
1142 | vty_out(vty, "Virtual link does not exist\n"); | |
1143 | return CMD_WARNING_CONFIG_FAILED; | |
1144 | } | |
1145 | ||
d62a17ae | 1146 | if (argc <= 5) { |
1147 | /* Basic VLink no command */ | |
1148 | /* Thats all folks! - BUGS B. strikes again!!!*/ | |
188823b0 | 1149 | ospf_vl_delete(ospf, vl_data); |
d62a17ae | 1150 | ospf_area_check_free(ospf, vl_config.area_id); |
d62a17ae | 1151 | return CMD_SUCCESS; |
1152 | } | |
1153 | ||
1154 | /* If we are down here, we are reseting parameters */ | |
d62a17ae | 1155 | /* Deal with other parameters */ |
3d1c6dc2 CS |
1156 | |
1157 | if (argv_find(argv, argc, "authentication", &idx)) { | |
1158 | /* authentication - this option can only occur | |
1159 | at start of command line */ | |
1160 | vl_config.auth_type = OSPF_AUTH_NOTSET; | |
1161 | } | |
1162 | ||
3d1c6dc2 | 1163 | if (argv_find(argv, argc, "message-digest-key", &idx)) { |
3d1c6dc2 | 1164 | vl_config.md5_key = NULL; |
cbb9b53d | 1165 | vl_config.crypto_key_id = strtol(argv[idx + 1]->arg, NULL, 10); |
3d1c6dc2 CS |
1166 | if (vl_config.crypto_key_id < 0) |
1167 | return CMD_WARNING_CONFIG_FAILED; | |
d62a17ae | 1168 | } |
1169 | ||
3d1c6dc2 | 1170 | if (argv_find(argv, argc, "authentication-key", &idx)) { |
cbb9b53d | 1171 | /* Reset authentication-key to 0 */ |
3d1c6dc2 CS |
1172 | memset(auth_key, 0, OSPF_AUTH_SIMPLE_SIZE + 1); |
1173 | vl_config.auth_key = auth_key; | |
1174 | } | |
d62a17ae | 1175 | |
1176 | /* Action configuration */ | |
1177 | ||
1178 | return ospf_vl_set(ospf, &vl_config); | |
7a7be519 | 1179 | } |
1180 | ||
b1c02cec QY |
1181 | DEFUN (ospf_area_vlink_intervals, |
1182 | ospf_area_vlink_intervals_cmd, | |
1183 | "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)}", | |
1184 | VLINK_HELPSTR_IPADDR | |
1185 | VLINK_HELPSTR_TIME_PARAM) | |
1186 | { | |
a3d826f0 | 1187 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1188 | struct ospf_vl_config_data vl_config; |
1189 | int ret = 0; | |
1190 | ||
1191 | ospf_vl_config_data_init(&vl_config, vty); | |
1192 | ||
1193 | char *area_id = argv[1]->arg; | |
1194 | char *router_id = argv[3]->arg; | |
1195 | ||
1196 | ret = str2area_id(area_id, &vl_config.area_id, &vl_config.area_id_fmt); | |
1197 | if (ret < 0) { | |
1198 | vty_out(vty, "OSPF area ID is invalid\n"); | |
1199 | return CMD_WARNING_CONFIG_FAILED; | |
1200 | } | |
1201 | ||
1202 | ret = inet_aton(router_id, &vl_config.vl_peer); | |
1203 | if (!ret) { | |
1204 | vty_out(vty, "Please specify valid Router ID as a.b.c.d\n"); | |
1205 | return CMD_WARNING_CONFIG_FAILED; | |
1206 | } | |
1207 | ||
1208 | for (int idx = 4; idx < argc; idx++) { | |
1209 | if (strmatch(argv[idx]->text, "hello-interval")) | |
1210 | vl_config.hello_interval = | |
1211 | strtol(argv[++idx]->arg, NULL, 10); | |
1212 | else if (strmatch(argv[idx]->text, "retransmit-interval")) | |
1213 | vl_config.retransmit_interval = | |
1214 | strtol(argv[++idx]->arg, NULL, 10); | |
1215 | else if (strmatch(argv[idx]->text, "transmit-delay")) | |
1216 | vl_config.transmit_delay = | |
1217 | strtol(argv[++idx]->arg, NULL, 10); | |
1218 | else if (strmatch(argv[idx]->text, "dead-interval")) | |
1219 | vl_config.dead_interval = | |
1220 | strtol(argv[++idx]->arg, NULL, 10); | |
1221 | } | |
1222 | ||
1223 | /* Action configuration */ | |
1224 | return ospf_vl_set(ospf, &vl_config); | |
b1c02cec QY |
1225 | } |
1226 | ||
7a7be519 | 1227 | DEFUN (no_ospf_area_vlink_intervals, |
1228 | no_ospf_area_vlink_intervals_cmd, | |
a663a38e | 1229 | "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 | 1230 | NO_STR |
7a7be519 | 1231 | VLINK_HELPSTR_IPADDR |
7a7be519 | 1232 | VLINK_HELPSTR_TIME_PARAM) |
1233 | { | |
a3d826f0 | 1234 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1235 | struct ospf_vl_config_data vl_config; |
1236 | int ret = 0; | |
1237 | ||
1238 | ospf_vl_config_data_init(&vl_config, vty); | |
1239 | ||
1240 | char *area_id = argv[2]->arg; | |
1241 | char *router_id = argv[4]->arg; | |
1242 | ||
1243 | ret = str2area_id(area_id, &vl_config.area_id, &vl_config.area_id_fmt); | |
1244 | if (ret < 0) { | |
1245 | vty_out(vty, "OSPF area ID is invalid\n"); | |
1246 | return CMD_WARNING_CONFIG_FAILED; | |
1247 | } | |
1248 | ||
1249 | ret = inet_aton(router_id, &vl_config.vl_peer); | |
1250 | if (!ret) { | |
1251 | vty_out(vty, "Please specify valid Router ID as a.b.c.d\n"); | |
1252 | return CMD_WARNING_CONFIG_FAILED; | |
1253 | } | |
1254 | ||
1255 | for (int idx = 5; idx < argc; idx++) { | |
1256 | if (strmatch(argv[idx]->text, "hello-interval")) | |
1257 | vl_config.hello_interval = OSPF_HELLO_INTERVAL_DEFAULT; | |
1258 | else if (strmatch(argv[idx]->text, "retransmit-interval")) | |
1259 | vl_config.retransmit_interval = | |
1260 | OSPF_RETRANSMIT_INTERVAL_DEFAULT; | |
1261 | else if (strmatch(argv[idx]->text, "transmit-delay")) | |
1262 | vl_config.transmit_delay = OSPF_TRANSMIT_DELAY_DEFAULT; | |
1263 | else if (strmatch(argv[idx]->text, "dead-interval")) | |
1264 | vl_config.dead_interval = | |
1265 | OSPF_ROUTER_DEAD_INTERVAL_DEFAULT; | |
1266 | } | |
1267 | ||
1268 | /* Action configuration */ | |
1269 | return ospf_vl_set(ospf, &vl_config); | |
718e3744 | 1270 | } |
1271 | ||
a2c62831 | 1272 | DEFUN (ospf_area_shortcut, |
1273 | ospf_area_shortcut_cmd, | |
6147e2c6 | 1274 | "area <A.B.C.D|(0-4294967295)> shortcut <default|enable|disable>", |
718e3744 | 1275 | "OSPF area parameters\n" |
1276 | "OSPF area ID in IP address format\n" | |
1277 | "OSPF area ID as a decimal value\n" | |
1278 | "Configure the area's shortcutting mode\n" | |
1279 | "Set default shortcutting behavior\n" | |
1280 | "Enable shortcutting through the area\n" | |
1281 | "Disable shortcutting through the area\n") | |
1282 | { | |
a3d826f0 | 1283 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1284 | int idx_ipv4_number = 1; |
1285 | int idx_enable_disable = 3; | |
1286 | struct ospf_area *area; | |
1287 | struct in_addr area_id; | |
1288 | int mode; | |
1289 | int format; | |
1290 | ||
1291 | VTY_GET_OSPF_AREA_ID_NO_BB("shortcut", area_id, format, | |
1292 | argv[idx_ipv4_number]->arg); | |
1293 | ||
1294 | area = ospf_area_get(ospf, area_id); | |
1295 | ospf_area_display_format_set(ospf, area, format); | |
1296 | ||
1297 | if (strncmp(argv[idx_enable_disable]->arg, "de", 2) == 0) | |
1298 | mode = OSPF_SHORTCUT_DEFAULT; | |
1299 | else if (strncmp(argv[idx_enable_disable]->arg, "di", 2) == 0) | |
1300 | mode = OSPF_SHORTCUT_DISABLE; | |
1301 | else if (strncmp(argv[idx_enable_disable]->arg, "e", 1) == 0) | |
1302 | mode = OSPF_SHORTCUT_ENABLE; | |
1303 | else | |
1304 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 1305 | |
d62a17ae | 1306 | ospf_area_shortcut_set(ospf, area, mode); |
718e3744 | 1307 | |
d62a17ae | 1308 | if (ospf->abr_type != OSPF_ABR_SHORTCUT) |
1309 | vty_out(vty, | |
3efd0893 | 1310 | "Shortcut area setting will take effect only when the router is configured as Shortcut ABR\n"); |
718e3744 | 1311 | |
d62a17ae | 1312 | return CMD_SUCCESS; |
718e3744 | 1313 | } |
1314 | ||
a2c62831 | 1315 | DEFUN (no_ospf_area_shortcut, |
1316 | no_ospf_area_shortcut_cmd, | |
6147e2c6 | 1317 | "no area <A.B.C.D|(0-4294967295)> shortcut <enable|disable>", |
718e3744 | 1318 | NO_STR |
1319 | "OSPF area parameters\n" | |
1320 | "OSPF area ID in IP address format\n" | |
1321 | "OSPF area ID as a decimal value\n" | |
1322 | "Deconfigure the area's shortcutting mode\n" | |
1323 | "Deconfigure enabled shortcutting through the area\n" | |
1324 | "Deconfigure disabled shortcutting through the area\n") | |
1325 | { | |
a3d826f0 | 1326 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1327 | int idx_ipv4_number = 2; |
1328 | struct ospf_area *area; | |
1329 | struct in_addr area_id; | |
1330 | int format; | |
718e3744 | 1331 | |
d62a17ae | 1332 | VTY_GET_OSPF_AREA_ID_NO_BB("shortcut", area_id, format, |
1333 | argv[idx_ipv4_number]->arg); | |
718e3744 | 1334 | |
d62a17ae | 1335 | area = ospf_area_lookup_by_area_id(ospf, area_id); |
1336 | if (!area) | |
1337 | return CMD_SUCCESS; | |
718e3744 | 1338 | |
d62a17ae | 1339 | ospf_area_shortcut_unset(ospf, area); |
718e3744 | 1340 | |
d62a17ae | 1341 | return CMD_SUCCESS; |
718e3744 | 1342 | } |
1343 | ||
6b0655a2 | 1344 | |
a2c62831 | 1345 | DEFUN (ospf_area_stub, |
1346 | ospf_area_stub_cmd, | |
6147e2c6 | 1347 | "area <A.B.C.D|(0-4294967295)> stub", |
718e3744 | 1348 | "OSPF area parameters\n" |
1349 | "OSPF area ID in IP address format\n" | |
1350 | "OSPF area ID as a decimal value\n" | |
1351 | "Configure OSPF area as stub\n") | |
1352 | { | |
a3d826f0 | 1353 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1354 | int idx_ipv4_number = 1; |
1355 | struct in_addr area_id; | |
1356 | int ret, format; | |
1357 | ||
1358 | VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id, format, | |
1359 | argv[idx_ipv4_number]->arg); | |
1360 | ||
1361 | ret = ospf_area_stub_set(ospf, area_id); | |
1362 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
1363 | format); | |
1364 | if (ret == 0) { | |
1365 | vty_out(vty, | |
1366 | "First deconfigure all virtual link through this area\n"); | |
1367 | return CMD_WARNING_CONFIG_FAILED; | |
1368 | } | |
718e3744 | 1369 | |
44445dee S |
1370 | /* Flush the external LSAs from the specified area */ |
1371 | ospf_flush_lsa_from_area(ospf, area_id, OSPF_AS_EXTERNAL_LSA); | |
d62a17ae | 1372 | ospf_area_no_summary_unset(ospf, area_id); |
718e3744 | 1373 | |
d62a17ae | 1374 | return CMD_SUCCESS; |
718e3744 | 1375 | } |
1376 | ||
a2c62831 | 1377 | DEFUN (ospf_area_stub_no_summary, |
1378 | ospf_area_stub_no_summary_cmd, | |
6147e2c6 | 1379 | "area <A.B.C.D|(0-4294967295)> stub no-summary", |
718e3744 | 1380 | "OSPF stub parameters\n" |
1381 | "OSPF area ID in IP address format\n" | |
1382 | "OSPF area ID as a decimal value\n" | |
1383 | "Configure OSPF area as stub\n" | |
1384 | "Do not inject inter-area routes into stub\n") | |
1385 | { | |
a3d826f0 | 1386 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1387 | int idx_ipv4_number = 1; |
1388 | struct in_addr area_id; | |
1389 | int ret, format; | |
1390 | ||
1391 | VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id, format, | |
1392 | argv[idx_ipv4_number]->arg); | |
1393 | ||
1394 | ret = ospf_area_stub_set(ospf, area_id); | |
1395 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
1396 | format); | |
1397 | if (ret == 0) { | |
1398 | vty_out(vty, | |
1399 | "%% Area cannot be stub as it contains a virtual link\n"); | |
1400 | return CMD_WARNING_CONFIG_FAILED; | |
1401 | } | |
718e3744 | 1402 | |
d62a17ae | 1403 | ospf_area_no_summary_set(ospf, area_id); |
718e3744 | 1404 | |
d62a17ae | 1405 | return CMD_SUCCESS; |
718e3744 | 1406 | } |
1407 | ||
a2c62831 | 1408 | DEFUN (no_ospf_area_stub, |
1409 | no_ospf_area_stub_cmd, | |
6147e2c6 | 1410 | "no area <A.B.C.D|(0-4294967295)> stub", |
718e3744 | 1411 | NO_STR |
1412 | "OSPF area parameters\n" | |
1413 | "OSPF area ID in IP address format\n" | |
1414 | "OSPF area ID as a decimal value\n" | |
1415 | "Configure OSPF area as stub\n") | |
1416 | { | |
a3d826f0 | 1417 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1418 | int idx_ipv4_number = 2; |
1419 | struct in_addr area_id; | |
1420 | int format; | |
718e3744 | 1421 | |
d62a17ae | 1422 | VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id, format, |
1423 | argv[idx_ipv4_number]->arg); | |
718e3744 | 1424 | |
d62a17ae | 1425 | ospf_area_stub_unset(ospf, area_id); |
1426 | ospf_area_no_summary_unset(ospf, area_id); | |
718e3744 | 1427 | |
d62a17ae | 1428 | return CMD_SUCCESS; |
718e3744 | 1429 | } |
1430 | ||
a2c62831 | 1431 | DEFUN (no_ospf_area_stub_no_summary, |
1432 | no_ospf_area_stub_no_summary_cmd, | |
6147e2c6 | 1433 | "no area <A.B.C.D|(0-4294967295)> stub no-summary", |
718e3744 | 1434 | NO_STR |
1435 | "OSPF area parameters\n" | |
1436 | "OSPF area ID in IP address format\n" | |
1437 | "OSPF area ID as a decimal value\n" | |
1438 | "Configure OSPF area as stub\n" | |
1439 | "Do not inject inter-area routes into area\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); | |
1448 | ospf_area_no_summary_unset(ospf, area_id); | |
718e3744 | 1449 | |
d62a17ae | 1450 | return CMD_SUCCESS; |
718e3744 | 1451 | } |
1452 | ||
d62a17ae | 1453 | static int ospf_area_nssa_cmd_handler(struct vty *vty, int argc, |
7ef56a73 CS |
1454 | struct cmd_token **argv, int cfg_nosum, |
1455 | int nosum) | |
718e3744 | 1456 | { |
a3d826f0 | 1457 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1458 | struct in_addr area_id; |
1459 | int ret, format; | |
1460 | ||
1461 | VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id, format, argv[1]->arg); | |
1462 | ||
1463 | ret = ospf_area_nssa_set(ospf, area_id); | |
1464 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
1465 | format); | |
1466 | if (ret == 0) { | |
1467 | vty_out(vty, | |
1468 | "%% Area cannot be nssa as it contains a virtual link\n"); | |
1469 | return CMD_WARNING_CONFIG_FAILED; | |
1470 | } | |
1471 | ||
1472 | if (argc > 3) { | |
1473 | if (strncmp(argv[3]->text, "translate-c", 11) == 0) | |
1474 | ospf_area_nssa_translator_role_set( | |
1475 | ospf, area_id, OSPF_NSSA_ROLE_CANDIDATE); | |
1476 | else if (strncmp(argv[3]->text, "translate-n", 11) == 0) | |
1477 | ospf_area_nssa_translator_role_set( | |
1478 | ospf, area_id, OSPF_NSSA_ROLE_NEVER); | |
1479 | else if (strncmp(argv[3]->text, "translate-a", 11) == 0) | |
1480 | ospf_area_nssa_translator_role_set( | |
1481 | ospf, area_id, OSPF_NSSA_ROLE_ALWAYS); | |
1482 | } else { | |
1483 | ospf_area_nssa_translator_role_set(ospf, area_id, | |
1484 | OSPF_NSSA_ROLE_CANDIDATE); | |
1485 | } | |
1486 | ||
7ef56a73 CS |
1487 | if (cfg_nosum) { |
1488 | if (nosum) | |
1489 | ospf_area_no_summary_set(ospf, area_id); | |
1490 | else | |
1491 | ospf_area_no_summary_unset(ospf, area_id); | |
1492 | } | |
d62a17ae | 1493 | |
44445dee S |
1494 | /* Flush the external LSA for the specified area */ |
1495 | ospf_flush_lsa_from_area(ospf, area_id, OSPF_AS_EXTERNAL_LSA); | |
d62a17ae | 1496 | ospf_schedule_abr_task(ospf); |
1c1c342d | 1497 | ospf_schedule_asbr_nssa_redist_update(ospf); |
d62a17ae | 1498 | |
1499 | return CMD_SUCCESS; | |
718e3744 | 1500 | } |
1501 | ||
718e3744 | 1502 | |
b0a053be | 1503 | DEFUN (ospf_area_nssa_translate, |
a2c62831 | 1504 | ospf_area_nssa_translate_cmd, |
6147e2c6 | 1505 | "area <A.B.C.D|(0-4294967295)> nssa <translate-candidate|translate-never|translate-always>", |
718e3744 | 1506 | "OSPF area parameters\n" |
1507 | "OSPF area ID in IP address format\n" | |
1508 | "OSPF area ID as a decimal value\n" | |
1509 | "Configure OSPF area as nssa\n" | |
1510 | "Configure NSSA-ABR for translate election (default)\n" | |
1511 | "Configure NSSA-ABR to never translate\n" | |
1512 | "Configure NSSA-ABR to always translate\n") | |
b0a053be | 1513 | { |
7ef56a73 | 1514 | return ospf_area_nssa_cmd_handler(vty, argc, argv, 0, 0); |
b0a053be | 1515 | } |
1516 | ||
1517 | DEFUN (ospf_area_nssa, | |
1518 | ospf_area_nssa_cmd, | |
6147e2c6 | 1519 | "area <A.B.C.D|(0-4294967295)> nssa", |
b0a053be | 1520 | "OSPF area parameters\n" |
1521 | "OSPF area ID in IP address format\n" | |
1522 | "OSPF area ID as a decimal value\n" | |
1523 | "Configure OSPF area as nssa\n") | |
1524 | { | |
2643b2bc | 1525 | return ospf_area_nssa_cmd_handler(vty, argc, argv, 0, 0); |
b0a053be | 1526 | } |
718e3744 | 1527 | |
c317eddb | 1528 | DEFUN(ospf_area_nssa_suppress_fa, ospf_area_nssa_suppress_fa_cmd, |
1529 | "area <A.B.C.D|(0-4294967295)> nssa suppress-fa", | |
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 | "Suppress forwarding address\n") | |
1535 | { | |
1536 | int idx_ipv4_number = 1; | |
1537 | struct in_addr area_id; | |
1538 | int format; | |
1539 | ||
1540 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
1541 | VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id, format, | |
1542 | argv[idx_ipv4_number]->arg); | |
1543 | ||
1544 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
1545 | format); | |
1546 | ospf_area_nssa_suppress_fa_set(ospf, area_id); | |
1547 | ||
1548 | ospf_schedule_abr_task(ospf); | |
1549 | ||
1550 | return CMD_SUCCESS; | |
1551 | } | |
1552 | ||
1553 | DEFUN(no_ospf_area_nssa_suppress_fa, no_ospf_area_nssa_suppress_fa_cmd, | |
1554 | "no area <A.B.C.D|(0-4294967295)> nssa suppress-fa", | |
1555 | NO_STR | |
1556 | "OSPF area parameters\n" | |
1557 | "OSPF area ID in IP address format\n" | |
1558 | "OSPF area ID as a decimal value\n" | |
1559 | "Configure OSPF area as nssa\n" | |
1560 | "Suppress forwarding address\n") | |
1561 | { | |
1562 | int idx_ipv4_number = 2; | |
1563 | struct in_addr area_id; | |
1564 | int format; | |
1565 | ||
1566 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
1567 | ||
1568 | VTY_GET_OSPF_AREA_ID_NO_BB("nssa", area_id, format, | |
1569 | argv[idx_ipv4_number]->arg); | |
1570 | ||
1571 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
1572 | format); | |
1573 | ospf_area_nssa_suppress_fa_unset(ospf, area_id); | |
1574 | ||
1575 | ospf_schedule_abr_task(ospf); | |
1576 | ||
1577 | return CMD_SUCCESS; | |
1578 | } | |
1579 | ||
a2c62831 | 1580 | DEFUN (ospf_area_nssa_no_summary, |
1581 | ospf_area_nssa_no_summary_cmd, | |
6147e2c6 | 1582 | "area <A.B.C.D|(0-4294967295)> nssa no-summary", |
718e3744 | 1583 | "OSPF area parameters\n" |
1584 | "OSPF area ID in IP address format\n" | |
1585 | "OSPF area ID as a decimal value\n" | |
1586 | "Configure OSPF area as nssa\n" | |
1587 | "Do not inject inter-area routes into nssa\n") | |
1588 | { | |
7ef56a73 CS |
1589 | int idx_ipv4_number = 1; |
1590 | struct in_addr area_id; | |
1591 | int format; | |
1592 | ||
1593 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
1594 | VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id, format, | |
1595 | argv[idx_ipv4_number]->arg); | |
1596 | ||
1597 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
1598 | format); | |
1599 | ospf_area_nssa_no_summary_set(ospf, area_id); | |
1600 | ||
1601 | ospf_schedule_abr_task(ospf); | |
1602 | ||
1603 | return CMD_SUCCESS; | |
1604 | } | |
1605 | ||
1606 | DEFUN (no_ospf_area_nssa_no_summary, | |
1607 | no_ospf_area_nssa_no_summary_cmd, | |
1608 | "no area <A.B.C.D|(0-4294967295)> nssa no-summary", | |
1609 | NO_STR | |
1610 | "OSPF area parameters\n" | |
1611 | "OSPF area ID in IP address format\n" | |
1612 | "OSPF area ID as a decimal value\n" | |
1613 | "Configure OSPF area as nssa\n" | |
1614 | "Do not inject inter-area routes into nssa\n") | |
1615 | { | |
1616 | int idx_ipv4_number = 2; | |
1617 | struct in_addr area_id; | |
1618 | int format; | |
1619 | ||
1620 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
1621 | ||
1622 | VTY_GET_OSPF_AREA_ID_NO_BB("nssa", area_id, format, | |
1623 | argv[idx_ipv4_number]->arg); | |
1624 | ||
1625 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
1626 | format); | |
1627 | ospf_area_no_summary_unset(ospf, area_id); | |
1628 | ||
1629 | ospf_schedule_abr_task(ospf); | |
1630 | ||
1631 | return CMD_SUCCESS; | |
718e3744 | 1632 | } |
1633 | ||
a2c62831 | 1634 | DEFUN (no_ospf_area_nssa, |
1635 | no_ospf_area_nssa_cmd, | |
7ef56a73 | 1636 | "no area <A.B.C.D|(0-4294967295)> nssa [<translate-candidate|translate-never|translate-always>]", |
718e3744 | 1637 | NO_STR |
1638 | "OSPF area parameters\n" | |
1639 | "OSPF area ID in IP address format\n" | |
1640 | "OSPF area ID as a decimal value\n" | |
7a7be519 | 1641 | "Configure OSPF area as nssa\n" |
1642 | "Configure NSSA-ABR for translate election (default)\n" | |
1643 | "Configure NSSA-ABR to never translate\n" | |
7ef56a73 | 1644 | "Configure NSSA-ABR to always translate\n") |
22b27e95 | 1645 | { |
a3d826f0 | 1646 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1647 | int idx_ipv4_number = 2; |
1648 | struct in_addr area_id; | |
1649 | int format; | |
718e3744 | 1650 | |
d62a17ae | 1651 | VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id, format, |
1652 | argv[idx_ipv4_number]->arg); | |
718e3744 | 1653 | |
44445dee S |
1654 | /* Flush the NSSA LSA for the specified area */ |
1655 | ospf_flush_lsa_from_area(ospf, area_id, OSPF_AS_NSSA_LSA); | |
7ef56a73 | 1656 | ospf_area_nssa_unset(ospf, area_id, argc); |
718e3744 | 1657 | |
d62a17ae | 1658 | ospf_schedule_abr_task(ospf); |
b0a053be | 1659 | |
d62a17ae | 1660 | return CMD_SUCCESS; |
718e3744 | 1661 | } |
1662 | ||
718e3744 | 1663 | |
a2c62831 | 1664 | DEFUN (ospf_area_default_cost, |
1665 | ospf_area_default_cost_cmd, | |
6147e2c6 | 1666 | "area <A.B.C.D|(0-4294967295)> default-cost (0-16777215)", |
718e3744 | 1667 | "OSPF area parameters\n" |
1668 | "OSPF area ID in IP address format\n" | |
1669 | "OSPF area ID as a decimal value\n" | |
1670 | "Set the summary-default cost of a NSSA or stub area\n" | |
1671 | "Stub's advertised default summary cost\n") | |
1672 | { | |
a3d826f0 | 1673 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1674 | int idx_ipv4_number = 1; |
1675 | int idx_number = 3; | |
1676 | struct ospf_area *area; | |
1677 | struct in_addr area_id; | |
d7c0a89a | 1678 | uint32_t cost; |
d62a17ae | 1679 | int format; |
1680 | struct prefix_ipv4 p; | |
1681 | ||
1682 | VTY_GET_OSPF_AREA_ID_NO_BB("default-cost", area_id, format, | |
1683 | argv[idx_ipv4_number]->arg); | |
1684 | cost = strtoul(argv[idx_number]->arg, NULL, 10); | |
1685 | ||
1686 | area = ospf_area_get(ospf, area_id); | |
1687 | ospf_area_display_format_set(ospf, area, format); | |
1688 | ||
1689 | if (area->external_routing == OSPF_AREA_DEFAULT) { | |
1690 | vty_out(vty, "The area is neither stub, nor NSSA\n"); | |
1691 | return CMD_WARNING_CONFIG_FAILED; | |
1692 | } | |
ba682537 | 1693 | |
d62a17ae | 1694 | area->default_cost = cost; |
1695 | ||
1696 | p.family = AF_INET; | |
1697 | p.prefix.s_addr = OSPF_DEFAULT_DESTINATION; | |
1698 | p.prefixlen = 0; | |
1699 | if (IS_DEBUG_OSPF_EVENT) | |
1700 | zlog_debug( | |
96b663a3 MS |
1701 | "ospf_abr_announce_stub_defaults(): announcing 0.0.0.0/0 to area %pI4", |
1702 | &area->area_id); | |
d62a17ae | 1703 | ospf_abr_announce_network_to_area(&p, area->default_cost, area); |
1704 | ||
1705 | return CMD_SUCCESS; | |
718e3744 | 1706 | } |
1707 | ||
a2c62831 | 1708 | DEFUN (no_ospf_area_default_cost, |
1709 | no_ospf_area_default_cost_cmd, | |
6147e2c6 | 1710 | "no area <A.B.C.D|(0-4294967295)> default-cost (0-16777215)", |
718e3744 | 1711 | NO_STR |
1712 | "OSPF area parameters\n" | |
1713 | "OSPF area ID in IP address format\n" | |
1714 | "OSPF area ID as a decimal value\n" | |
1715 | "Set the summary-default cost of a NSSA or stub area\n" | |
1716 | "Stub's advertised default summary cost\n") | |
1717 | { | |
a3d826f0 | 1718 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1719 | int idx_ipv4_number = 2; |
1720 | struct ospf_area *area; | |
1721 | struct in_addr area_id; | |
1722 | int format; | |
1723 | struct prefix_ipv4 p; | |
718e3744 | 1724 | |
d62a17ae | 1725 | VTY_GET_OSPF_AREA_ID_NO_BB("default-cost", area_id, format, |
1726 | argv[idx_ipv4_number]->arg); | |
718e3744 | 1727 | |
d62a17ae | 1728 | area = ospf_area_lookup_by_area_id(ospf, area_id); |
1729 | if (area == NULL) | |
1730 | return CMD_SUCCESS; | |
718e3744 | 1731 | |
d62a17ae | 1732 | if (area->external_routing == OSPF_AREA_DEFAULT) { |
1733 | vty_out(vty, "The area is neither stub, nor NSSA\n"); | |
1734 | return CMD_WARNING_CONFIG_FAILED; | |
1735 | } | |
718e3744 | 1736 | |
d62a17ae | 1737 | area->default_cost = 1; |
718e3744 | 1738 | |
d62a17ae | 1739 | p.family = AF_INET; |
1740 | p.prefix.s_addr = OSPF_DEFAULT_DESTINATION; | |
1741 | p.prefixlen = 0; | |
1742 | if (IS_DEBUG_OSPF_EVENT) | |
1743 | zlog_debug( | |
96b663a3 MS |
1744 | "ospf_abr_announce_stub_defaults(): announcing 0.0.0.0/0 to area %pI4", |
1745 | &area->area_id); | |
d62a17ae | 1746 | ospf_abr_announce_network_to_area(&p, area->default_cost, area); |
ba682537 | 1747 | |
1748 | ||
d62a17ae | 1749 | ospf_area_check_free(ospf, area_id); |
718e3744 | 1750 | |
d62a17ae | 1751 | return CMD_SUCCESS; |
718e3744 | 1752 | } |
1753 | ||
a2c62831 | 1754 | DEFUN (ospf_area_export_list, |
1755 | ospf_area_export_list_cmd, | |
c60dec36 | 1756 | "area <A.B.C.D|(0-4294967295)> export-list ACCESSLIST4_NAME", |
718e3744 | 1757 | "OSPF area parameters\n" |
1758 | "OSPF area ID in IP address format\n" | |
1759 | "OSPF area ID as a decimal value\n" | |
1760 | "Set the filter for networks announced to other areas\n" | |
1761 | "Name of the access-list\n") | |
1762 | { | |
a3d826f0 | 1763 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1764 | int idx_ipv4_number = 1; |
1765 | struct ospf_area *area; | |
1766 | struct in_addr area_id; | |
1767 | int format; | |
718e3744 | 1768 | |
d62a17ae | 1769 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
52930766 | 1770 | |
d62a17ae | 1771 | area = ospf_area_get(ospf, area_id); |
1772 | ospf_area_display_format_set(ospf, area, format); | |
1773 | ospf_area_export_list_set(ospf, area, argv[3]->arg); | |
718e3744 | 1774 | |
d62a17ae | 1775 | return CMD_SUCCESS; |
718e3744 | 1776 | } |
1777 | ||
a2c62831 | 1778 | DEFUN (no_ospf_area_export_list, |
1779 | no_ospf_area_export_list_cmd, | |
c60dec36 | 1780 | "no area <A.B.C.D|(0-4294967295)> export-list ACCESSLIST4_NAME", |
718e3744 | 1781 | NO_STR |
1782 | "OSPF area parameters\n" | |
1783 | "OSPF area ID in IP address format\n" | |
1784 | "OSPF area ID as a decimal value\n" | |
1785 | "Unset the filter for networks announced to other areas\n" | |
1786 | "Name of the access-list\n") | |
1787 | { | |
a3d826f0 | 1788 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1789 | int idx_ipv4_number = 2; |
1790 | struct ospf_area *area; | |
1791 | struct in_addr area_id; | |
1792 | int format; | |
718e3744 | 1793 | |
d62a17ae | 1794 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
52930766 | 1795 | |
d62a17ae | 1796 | area = ospf_area_lookup_by_area_id(ospf, area_id); |
1797 | if (area == NULL) | |
1798 | return CMD_SUCCESS; | |
718e3744 | 1799 | |
d62a17ae | 1800 | ospf_area_export_list_unset(ospf, area); |
718e3744 | 1801 | |
d62a17ae | 1802 | return CMD_SUCCESS; |
718e3744 | 1803 | } |
1804 | ||
1805 | ||
a2c62831 | 1806 | DEFUN (ospf_area_import_list, |
1807 | ospf_area_import_list_cmd, | |
c60dec36 | 1808 | "area <A.B.C.D|(0-4294967295)> import-list ACCESSLIST4_NAME", |
718e3744 | 1809 | "OSPF area parameters\n" |
1810 | "OSPF area ID in IP address format\n" | |
1811 | "OSPF area ID as a decimal value\n" | |
1812 | "Set the filter for networks from other areas announced to the specified one\n" | |
1813 | "Name of the access-list\n") | |
1814 | { | |
a3d826f0 | 1815 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1816 | int idx_ipv4_number = 1; |
1817 | struct ospf_area *area; | |
1818 | struct in_addr area_id; | |
1819 | int format; | |
718e3744 | 1820 | |
d62a17ae | 1821 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
52930766 | 1822 | |
d62a17ae | 1823 | area = ospf_area_get(ospf, area_id); |
1824 | ospf_area_display_format_set(ospf, area, format); | |
1825 | ospf_area_import_list_set(ospf, area, argv[3]->arg); | |
718e3744 | 1826 | |
d62a17ae | 1827 | return CMD_SUCCESS; |
718e3744 | 1828 | } |
1829 | ||
a2c62831 | 1830 | DEFUN (no_ospf_area_import_list, |
1831 | no_ospf_area_import_list_cmd, | |
c60dec36 | 1832 | "no area <A.B.C.D|(0-4294967295)> import-list ACCESSLIST4_NAME", |
718e3744 | 1833 | NO_STR |
1834 | "OSPF area parameters\n" | |
1835 | "OSPF area ID in IP address format\n" | |
1836 | "OSPF area ID as a decimal value\n" | |
1837 | "Unset the filter for networks announced to other areas\n" | |
1838 | "Name of the access-list\n") | |
1839 | { | |
a3d826f0 | 1840 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1841 | int idx_ipv4_number = 2; |
1842 | struct ospf_area *area; | |
1843 | struct in_addr area_id; | |
1844 | int format; | |
718e3744 | 1845 | |
d62a17ae | 1846 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
52930766 | 1847 | |
d62a17ae | 1848 | area = ospf_area_lookup_by_area_id(ospf, area_id); |
1849 | if (area == NULL) | |
1850 | return CMD_SUCCESS; | |
718e3744 | 1851 | |
d62a17ae | 1852 | ospf_area_import_list_unset(ospf, area); |
718e3744 | 1853 | |
d62a17ae | 1854 | return CMD_SUCCESS; |
718e3744 | 1855 | } |
1856 | ||
a2c62831 | 1857 | DEFUN (ospf_area_filter_list, |
1858 | ospf_area_filter_list_cmd, | |
1c3f03f7 | 1859 | "area <A.B.C.D|(0-4294967295)> filter-list prefix PREFIXLIST_NAME <in|out>", |
718e3744 | 1860 | "OSPF area parameters\n" |
1861 | "OSPF area ID in IP address format\n" | |
1862 | "OSPF area ID as a decimal value\n" | |
1863 | "Filter networks between OSPF areas\n" | |
1864 | "Filter prefixes between OSPF areas\n" | |
1865 | "Name of an IP prefix-list\n" | |
1866 | "Filter networks sent to this area\n" | |
1867 | "Filter networks sent from this area\n") | |
1868 | { | |
a3d826f0 | 1869 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1870 | int idx_ipv4_number = 1; |
1871 | int idx_word = 4; | |
1872 | int idx_in_out = 5; | |
1873 | struct ospf_area *area; | |
1874 | struct in_addr area_id; | |
1875 | struct prefix_list *plist; | |
1876 | int format; | |
1877 | ||
1878 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); | |
1879 | ||
1880 | area = ospf_area_get(ospf, area_id); | |
1881 | ospf_area_display_format_set(ospf, area, format); | |
1882 | plist = prefix_list_lookup(AFI_IP, argv[idx_word]->arg); | |
1883 | if (strncmp(argv[idx_in_out]->arg, "in", 2) == 0) { | |
1884 | PREFIX_LIST_IN(area) = plist; | |
1885 | if (PREFIX_NAME_IN(area)) | |
1886 | free(PREFIX_NAME_IN(area)); | |
1887 | ||
1888 | PREFIX_NAME_IN(area) = strdup(argv[idx_word]->arg); | |
1889 | ospf_schedule_abr_task(ospf); | |
1890 | } else { | |
1891 | PREFIX_LIST_OUT(area) = plist; | |
1892 | if (PREFIX_NAME_OUT(area)) | |
1893 | free(PREFIX_NAME_OUT(area)); | |
1894 | ||
1895 | PREFIX_NAME_OUT(area) = strdup(argv[idx_word]->arg); | |
1896 | ospf_schedule_abr_task(ospf); | |
1897 | } | |
718e3744 | 1898 | |
d62a17ae | 1899 | return CMD_SUCCESS; |
718e3744 | 1900 | } |
1901 | ||
a2c62831 | 1902 | DEFUN (no_ospf_area_filter_list, |
1903 | no_ospf_area_filter_list_cmd, | |
1c3f03f7 | 1904 | "no area <A.B.C.D|(0-4294967295)> filter-list prefix PREFIXLIST_NAME <in|out>", |
718e3744 | 1905 | NO_STR |
1906 | "OSPF area parameters\n" | |
1907 | "OSPF area ID in IP address format\n" | |
1908 | "OSPF area ID as a decimal value\n" | |
1909 | "Filter networks between OSPF areas\n" | |
1910 | "Filter prefixes between OSPF areas\n" | |
1911 | "Name of an IP prefix-list\n" | |
1912 | "Filter networks sent to this area\n" | |
1913 | "Filter networks sent from this area\n") | |
1914 | { | |
a3d826f0 | 1915 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1916 | int idx_ipv4_number = 2; |
1917 | int idx_word = 5; | |
1918 | int idx_in_out = 6; | |
1919 | struct ospf_area *area; | |
1920 | struct in_addr area_id; | |
1921 | int format; | |
718e3744 | 1922 | |
d62a17ae | 1923 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
718e3744 | 1924 | |
d62a17ae | 1925 | if ((area = ospf_area_lookup_by_area_id(ospf, area_id)) == NULL) |
1926 | return CMD_SUCCESS; | |
718e3744 | 1927 | |
d62a17ae | 1928 | if (strncmp(argv[idx_in_out]->arg, "in", 2) == 0) { |
1929 | if (PREFIX_NAME_IN(area)) | |
1930 | if (strcmp(PREFIX_NAME_IN(area), argv[idx_word]->arg) | |
1931 | != 0) | |
1932 | return CMD_SUCCESS; | |
718e3744 | 1933 | |
d62a17ae | 1934 | PREFIX_LIST_IN(area) = NULL; |
1935 | if (PREFIX_NAME_IN(area)) | |
1936 | free(PREFIX_NAME_IN(area)); | |
718e3744 | 1937 | |
d62a17ae | 1938 | PREFIX_NAME_IN(area) = NULL; |
718e3744 | 1939 | |
d62a17ae | 1940 | ospf_schedule_abr_task(ospf); |
1941 | } else { | |
1942 | if (PREFIX_NAME_OUT(area)) | |
1943 | if (strcmp(PREFIX_NAME_OUT(area), argv[idx_word]->arg) | |
1944 | != 0) | |
1945 | return CMD_SUCCESS; | |
718e3744 | 1946 | |
d62a17ae | 1947 | PREFIX_LIST_OUT(area) = NULL; |
1948 | if (PREFIX_NAME_OUT(area)) | |
1949 | free(PREFIX_NAME_OUT(area)); | |
718e3744 | 1950 | |
d62a17ae | 1951 | PREFIX_NAME_OUT(area) = NULL; |
718e3744 | 1952 | |
d62a17ae | 1953 | ospf_schedule_abr_task(ospf); |
1954 | } | |
1955 | ||
1956 | return CMD_SUCCESS; | |
718e3744 | 1957 | } |
1958 | ||
6b0655a2 | 1959 | |
a2c62831 | 1960 | DEFUN (ospf_area_authentication_message_digest, |
1961 | ospf_area_authentication_message_digest_cmd, | |
32573073 QY |
1962 | "[no] area <A.B.C.D|(0-4294967295)> authentication message-digest", |
1963 | NO_STR | |
718e3744 | 1964 | "OSPF area parameters\n" |
2b00515a CF |
1965 | "OSPF area ID in IP address format\n" |
1966 | "OSPF area ID as a decimal value\n" | |
718e3744 | 1967 | "Enable authentication\n" |
1968 | "Use message-digest authentication\n") | |
1969 | { | |
a3d826f0 | 1970 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
ca19319b | 1971 | int idx = 0; |
d62a17ae | 1972 | struct ospf_area *area; |
1973 | struct in_addr area_id; | |
1974 | int format; | |
718e3744 | 1975 | |
ca19319b | 1976 | argv_find(argv, argc, "area", &idx); |
1977 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx + 1]->arg); | |
718e3744 | 1978 | |
d62a17ae | 1979 | area = ospf_area_get(ospf, area_id); |
1980 | ospf_area_display_format_set(ospf, area, format); | |
996c9314 LB |
1981 | area->auth_type = strmatch(argv[0]->text, "no") |
1982 | ? OSPF_AUTH_NULL | |
1983 | : OSPF_AUTH_CRYPTOGRAPHIC; | |
718e3744 | 1984 | |
d62a17ae | 1985 | return CMD_SUCCESS; |
718e3744 | 1986 | } |
1987 | ||
a2c62831 | 1988 | DEFUN (ospf_area_authentication, |
1989 | ospf_area_authentication_cmd, | |
6147e2c6 | 1990 | "area <A.B.C.D|(0-4294967295)> authentication", |
718e3744 | 1991 | "OSPF area parameters\n" |
1992 | "OSPF area ID in IP address format\n" | |
1993 | "OSPF area ID as a decimal value\n" | |
1994 | "Enable authentication\n") | |
1995 | { | |
a3d826f0 | 1996 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1997 | int idx_ipv4_number = 1; |
1998 | struct ospf_area *area; | |
1999 | struct in_addr area_id; | |
2000 | int format; | |
718e3744 | 2001 | |
d62a17ae | 2002 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
718e3744 | 2003 | |
d62a17ae | 2004 | area = ospf_area_get(ospf, area_id); |
2005 | ospf_area_display_format_set(ospf, area, format); | |
2006 | area->auth_type = OSPF_AUTH_SIMPLE; | |
718e3744 | 2007 | |
d62a17ae | 2008 | return CMD_SUCCESS; |
718e3744 | 2009 | } |
2010 | ||
a2c62831 | 2011 | DEFUN (no_ospf_area_authentication, |
2012 | no_ospf_area_authentication_cmd, | |
6147e2c6 | 2013 | "no area <A.B.C.D|(0-4294967295)> authentication", |
718e3744 | 2014 | NO_STR |
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 = 2; |
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_lookup_by_area_id(ospf, area_id); |
2029 | if (area == NULL) | |
2030 | return CMD_SUCCESS; | |
718e3744 | 2031 | |
d62a17ae | 2032 | area->auth_type = OSPF_AUTH_NULL; |
718e3744 | 2033 | |
d62a17ae | 2034 | ospf_area_check_free(ospf, area_id); |
2035 | ||
2036 | return CMD_SUCCESS; | |
718e3744 | 2037 | } |
2038 | ||
6b0655a2 | 2039 | |
718e3744 | 2040 | DEFUN (ospf_abr_type, |
2041 | ospf_abr_type_cmd, | |
6147e2c6 | 2042 | "ospf abr-type <cisco|ibm|shortcut|standard>", |
718e3744 | 2043 | "OSPF specific commands\n" |
2044 | "Set OSPF ABR type\n" | |
2045 | "Alternative ABR, cisco implementation\n" | |
2046 | "Alternative ABR, IBM implementation\n" | |
2047 | "Shortcut ABR\n" | |
2048 | "Standard behavior (RFC2328)\n") | |
2049 | { | |
a3d826f0 | 2050 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2051 | int idx_vendor = 2; |
d7c0a89a | 2052 | uint8_t abr_type = OSPF_ABR_UNKNOWN; |
d62a17ae | 2053 | |
2054 | if (strncmp(argv[idx_vendor]->arg, "c", 1) == 0) | |
2055 | abr_type = OSPF_ABR_CISCO; | |
2056 | else if (strncmp(argv[idx_vendor]->arg, "i", 1) == 0) | |
2057 | abr_type = OSPF_ABR_IBM; | |
2058 | else if (strncmp(argv[idx_vendor]->arg, "sh", 2) == 0) | |
2059 | abr_type = OSPF_ABR_SHORTCUT; | |
2060 | else if (strncmp(argv[idx_vendor]->arg, "st", 2) == 0) | |
2061 | abr_type = OSPF_ABR_STAND; | |
2062 | else | |
2063 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 2064 | |
d62a17ae | 2065 | /* If ABR type value is changed, schedule ABR task. */ |
2066 | if (ospf->abr_type != abr_type) { | |
2067 | ospf->abr_type = abr_type; | |
2068 | ospf_schedule_abr_task(ospf); | |
2069 | } | |
2070 | ||
2071 | return CMD_SUCCESS; | |
718e3744 | 2072 | } |
2073 | ||
2074 | DEFUN (no_ospf_abr_type, | |
2075 | no_ospf_abr_type_cmd, | |
6147e2c6 | 2076 | "no ospf abr-type <cisco|ibm|shortcut|standard>", |
718e3744 | 2077 | NO_STR |
2078 | "OSPF specific commands\n" | |
2079 | "Set OSPF ABR type\n" | |
2080 | "Alternative ABR, cisco implementation\n" | |
2081 | "Alternative ABR, IBM implementation\n" | |
3a2d747c QY |
2082 | "Shortcut ABR\n" |
2083 | "Standard ABR\n") | |
718e3744 | 2084 | { |
a3d826f0 | 2085 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2086 | int idx_vendor = 3; |
d7c0a89a | 2087 | uint8_t abr_type = OSPF_ABR_UNKNOWN; |
d62a17ae | 2088 | |
2089 | if (strncmp(argv[idx_vendor]->arg, "c", 1) == 0) | |
2090 | abr_type = OSPF_ABR_CISCO; | |
2091 | else if (strncmp(argv[idx_vendor]->arg, "i", 1) == 0) | |
2092 | abr_type = OSPF_ABR_IBM; | |
2093 | else if (strncmp(argv[idx_vendor]->arg, "sh", 2) == 0) | |
2094 | abr_type = OSPF_ABR_SHORTCUT; | |
2095 | else if (strncmp(argv[idx_vendor]->arg, "st", 2) == 0) | |
2096 | abr_type = OSPF_ABR_STAND; | |
2097 | else | |
2098 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 2099 | |
d62a17ae | 2100 | /* If ABR type value is changed, schedule ABR task. */ |
2101 | if (ospf->abr_type == abr_type) { | |
2102 | ospf->abr_type = OSPF_ABR_DEFAULT; | |
2103 | ospf_schedule_abr_task(ospf); | |
2104 | } | |
2105 | ||
2106 | return CMD_SUCCESS; | |
718e3744 | 2107 | } |
2108 | ||
d7e60dd7 AS |
2109 | DEFUN (ospf_log_adjacency_changes, |
2110 | ospf_log_adjacency_changes_cmd, | |
2111 | "log-adjacency-changes", | |
2112 | "Log changes in adjacency state\n") | |
2113 | { | |
a3d826f0 | 2114 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d7e60dd7 | 2115 | |
d62a17ae | 2116 | SET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES); |
2117 | UNSET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL); | |
2118 | return CMD_SUCCESS; | |
d7e60dd7 AS |
2119 | } |
2120 | ||
2121 | DEFUN (ospf_log_adjacency_changes_detail, | |
2122 | ospf_log_adjacency_changes_detail_cmd, | |
2123 | "log-adjacency-changes detail", | |
2124 | "Log changes in adjacency state\n" | |
2125 | "Log all state changes\n") | |
2126 | { | |
a3d826f0 | 2127 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d7e60dd7 | 2128 | |
d62a17ae | 2129 | SET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES); |
2130 | SET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL); | |
2131 | return CMD_SUCCESS; | |
d7e60dd7 AS |
2132 | } |
2133 | ||
2134 | DEFUN (no_ospf_log_adjacency_changes, | |
2135 | no_ospf_log_adjacency_changes_cmd, | |
2136 | "no log-adjacency-changes", | |
2137 | NO_STR | |
2138 | "Log changes in adjacency state\n") | |
2139 | { | |
a3d826f0 | 2140 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d7e60dd7 | 2141 | |
d62a17ae | 2142 | UNSET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL); |
2143 | UNSET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES); | |
2144 | return CMD_SUCCESS; | |
d7e60dd7 AS |
2145 | } |
2146 | ||
2147 | DEFUN (no_ospf_log_adjacency_changes_detail, | |
2148 | no_ospf_log_adjacency_changes_detail_cmd, | |
2149 | "no log-adjacency-changes detail", | |
2150 | NO_STR | |
2151 | "Log changes in adjacency state\n" | |
2152 | "Log all state changes\n") | |
2153 | { | |
a3d826f0 | 2154 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d7e60dd7 | 2155 | |
d62a17ae | 2156 | UNSET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL); |
2157 | return CMD_SUCCESS; | |
d7e60dd7 AS |
2158 | } |
2159 | ||
718e3744 | 2160 | DEFUN (ospf_compatible_rfc1583, |
2161 | ospf_compatible_rfc1583_cmd, | |
2162 | "compatible rfc1583", | |
2163 | "OSPF compatibility list\n" | |
2164 | "compatible with RFC 1583\n") | |
2165 | { | |
a3d826f0 | 2166 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
718e3744 | 2167 | |
d62a17ae | 2168 | if (!CHECK_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE)) { |
2169 | SET_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE); | |
2170 | ospf_spf_calculate_schedule(ospf, SPF_FLAG_CONFIG_CHANGE); | |
2171 | } | |
2172 | return CMD_SUCCESS; | |
718e3744 | 2173 | } |
2174 | ||
2175 | DEFUN (no_ospf_compatible_rfc1583, | |
2176 | no_ospf_compatible_rfc1583_cmd, | |
2177 | "no compatible rfc1583", | |
2178 | NO_STR | |
2179 | "OSPF compatibility list\n" | |
2180 | "compatible with RFC 1583\n") | |
2181 | { | |
a3d826f0 | 2182 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
718e3744 | 2183 | |
d62a17ae | 2184 | if (CHECK_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE)) { |
2185 | UNSET_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE); | |
2186 | ospf_spf_calculate_schedule(ospf, SPF_FLAG_CONFIG_CHANGE); | |
2187 | } | |
2188 | return CMD_SUCCESS; | |
718e3744 | 2189 | } |
2190 | ||
d62a17ae | 2191 | ALIAS(ospf_compatible_rfc1583, ospf_rfc1583_flag_cmd, |
2192 | "ospf rfc1583compatibility", | |
2193 | "OSPF specific commands\n" | |
2194 | "Enable the RFC1583Compatibility flag\n") | |
718e3744 | 2195 | |
d62a17ae | 2196 | ALIAS(no_ospf_compatible_rfc1583, no_ospf_rfc1583_flag_cmd, |
9d303b37 | 2197 | "no ospf rfc1583compatibility", NO_STR |
d62a17ae | 2198 | "OSPF specific commands\n" |
2199 | "Disable the RFC1583Compatibility flag\n") | |
6b0655a2 | 2200 | |
5b5d66c4 RW |
2201 | static void ospf_table_reinstall_routes(struct ospf *ospf, |
2202 | struct route_table *rt) | |
2203 | { | |
2204 | struct route_node *rn; | |
2205 | ||
6ae27a4b IR |
2206 | if (!rt) |
2207 | return; | |
2208 | ||
5b5d66c4 RW |
2209 | for (rn = route_top(rt); rn; rn = route_next(rn)) { |
2210 | struct ospf_route *or; | |
2211 | ||
2212 | or = rn->info; | |
2213 | if (!or) | |
2214 | continue; | |
2215 | ||
2216 | if (or->type == OSPF_DESTINATION_NETWORK) | |
2217 | ospf_zebra_add(ospf, (struct prefix_ipv4 *)&rn->p, or); | |
2218 | else if (or->type == OSPF_DESTINATION_DISCARD) | |
2219 | ospf_zebra_add_discard(ospf, | |
2220 | (struct prefix_ipv4 *)&rn->p); | |
2221 | } | |
2222 | } | |
2223 | ||
2224 | static void ospf_reinstall_routes(struct ospf *ospf) | |
2225 | { | |
2226 | ospf_table_reinstall_routes(ospf, ospf->new_table); | |
2227 | ospf_table_reinstall_routes(ospf, ospf->new_external_route); | |
2228 | } | |
2229 | ||
2230 | DEFPY (ospf_send_extra_data, | |
2231 | ospf_send_extra_data_cmd, | |
2232 | "[no] ospf send-extra-data zebra", | |
2233 | NO_STR | |
2234 | OSPF_STR | |
2235 | "Extra data to Zebra for display/use\n" | |
2236 | "To zebra\n") | |
2237 | { | |
2238 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
2239 | ||
2240 | if (no && CHECK_FLAG(ospf->config, OSPF_SEND_EXTRA_DATA_TO_ZEBRA)) { | |
2241 | UNSET_FLAG(ospf->config, OSPF_SEND_EXTRA_DATA_TO_ZEBRA); | |
2242 | ospf_reinstall_routes(ospf); | |
2243 | } else if (!CHECK_FLAG(ospf->config, OSPF_SEND_EXTRA_DATA_TO_ZEBRA)) { | |
2244 | SET_FLAG(ospf->config, OSPF_SEND_EXTRA_DATA_TO_ZEBRA); | |
2245 | ospf_reinstall_routes(ospf); | |
2246 | } | |
2247 | ||
2248 | return CMD_SUCCESS; | |
2249 | } | |
2250 | ||
d62a17ae | 2251 | static int ospf_timers_spf_set(struct vty *vty, unsigned int delay, |
2252 | unsigned int hold, unsigned int max) | |
d24f6e2a | 2253 | { |
a3d826f0 | 2254 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
7c8ff89e | 2255 | |
d62a17ae | 2256 | ospf->spf_delay = delay; |
2257 | ospf->spf_holdtime = hold; | |
2258 | ospf->spf_max_holdtime = max; | |
2259 | ||
2260 | return CMD_SUCCESS; | |
d24f6e2a | 2261 | } |
718e3744 | 2262 | |
ac7424f9 MR |
2263 | DEFUN (ospf_timers_min_ls_interval, |
2264 | ospf_timers_min_ls_interval_cmd, | |
6147e2c6 | 2265 | "timers throttle lsa all (0-5000)", |
ac7424f9 MR |
2266 | "Adjust routing timers\n" |
2267 | "Throttling adaptive timer\n" | |
2268 | "LSA delay between transmissions\n" | |
813d4307 | 2269 | "All LSA types\n" |
ac7424f9 MR |
2270 | "Delay (msec) between sending LSAs\n") |
2271 | { | |
a3d826f0 | 2272 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2273 | int idx_number = 4; |
2274 | unsigned int interval; | |
ac7424f9 | 2275 | |
d62a17ae | 2276 | if (argc < 5) { |
2277 | vty_out(vty, "Insufficient arguments\n"); | |
2278 | return CMD_WARNING_CONFIG_FAILED; | |
2279 | } | |
ac7424f9 | 2280 | |
d62a17ae | 2281 | interval = strtoul(argv[idx_number]->arg, NULL, 10); |
ac7424f9 | 2282 | |
d62a17ae | 2283 | ospf->min_ls_interval = interval; |
ac7424f9 | 2284 | |
d62a17ae | 2285 | return CMD_SUCCESS; |
ac7424f9 MR |
2286 | } |
2287 | ||
2288 | DEFUN (no_ospf_timers_min_ls_interval, | |
2289 | no_ospf_timers_min_ls_interval_cmd, | |
7a7be519 | 2290 | "no timers throttle lsa all [(0-5000)]", |
ac7424f9 MR |
2291 | NO_STR |
2292 | "Adjust routing timers\n" | |
2293 | "Throttling adaptive timer\n" | |
813d4307 | 2294 | "LSA delay between transmissions\n" |
7a7be519 | 2295 | "All LSA types\n" |
2296 | "Delay (msec) between sending LSAs\n") | |
ac7424f9 | 2297 | { |
a3d826f0 | 2298 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2299 | ospf->min_ls_interval = OSPF_MIN_LS_INTERVAL; |
ac7424f9 | 2300 | |
d62a17ae | 2301 | return CMD_SUCCESS; |
ac7424f9 MR |
2302 | } |
2303 | ||
d24f6e2a | 2304 | DEFUN (ospf_timers_throttle_spf, |
2305 | ospf_timers_throttle_spf_cmd, | |
6147e2c6 | 2306 | "timers throttle spf (0-600000) (0-600000) (0-600000)", |
d24f6e2a | 2307 | "Adjust routing timers\n" |
2308 | "Throttling adaptive timer\n" | |
2309 | "OSPF SPF timers\n" | |
2310 | "Delay (msec) from first change received till SPF calculation\n" | |
2311 | "Initial hold time (msec) between consecutive SPF calculations\n" | |
2312 | "Maximum hold time (msec)\n") | |
2313 | { | |
d62a17ae | 2314 | int idx_number = 3; |
2315 | int idx_number_2 = 4; | |
2316 | int idx_number_3 = 5; | |
2317 | unsigned int delay, hold, max; | |
2318 | ||
2319 | if (argc < 6) { | |
2320 | vty_out(vty, "Insufficient arguments\n"); | |
2321 | return CMD_WARNING_CONFIG_FAILED; | |
2322 | } | |
2323 | ||
2324 | delay = strtoul(argv[idx_number]->arg, NULL, 10); | |
2325 | hold = strtoul(argv[idx_number_2]->arg, NULL, 10); | |
2326 | max = strtoul(argv[idx_number_3]->arg, NULL, 10); | |
2327 | ||
2328 | return ospf_timers_spf_set(vty, delay, hold, max); | |
d24f6e2a | 2329 | } |
2330 | ||
d24f6e2a | 2331 | DEFUN (no_ospf_timers_throttle_spf, |
2332 | no_ospf_timers_throttle_spf_cmd, | |
7a7be519 | 2333 | "no timers throttle spf [(0-600000)(0-600000)(0-600000)]", |
718e3744 | 2334 | NO_STR |
2335 | "Adjust routing timers\n" | |
d24f6e2a | 2336 | "Throttling adaptive timer\n" |
7a7be519 | 2337 | "OSPF SPF timers\n" |
2338 | "Delay (msec) from first change received till SPF calculation\n" | |
2339 | "Initial hold time (msec) between consecutive SPF calculations\n" | |
2340 | "Maximum hold time (msec)\n") | |
22b27e95 | 2341 | { |
d62a17ae | 2342 | return ospf_timers_spf_set(vty, OSPF_SPF_DELAY_DEFAULT, |
2343 | OSPF_SPF_HOLDTIME_DEFAULT, | |
2344 | OSPF_SPF_MAX_HOLDTIME_DEFAULT); | |
718e3744 | 2345 | } |
2346 | ||
b4a039bf | 2347 | |
0e88de35 QY |
2348 | DEFUN (ospf_timers_lsa_min_arrival, |
2349 | ospf_timers_lsa_min_arrival_cmd, | |
6147e2c6 | 2350 | "timers lsa min-arrival (0-600000)", |
b6927875 DS |
2351 | "Adjust routing timers\n" |
2352 | "OSPF LSA timers\n" | |
2353 | "Minimum delay in receiving new version of a LSA\n" | |
2354 | "Delay in milliseconds\n") | |
2355 | { | |
a3d826f0 | 2356 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
0e88de35 | 2357 | ospf->min_ls_arrival = strtoul(argv[argc - 1]->arg, NULL, 10); |
d62a17ae | 2358 | return CMD_SUCCESS; |
b6927875 DS |
2359 | } |
2360 | ||
0e88de35 QY |
2361 | DEFUN (no_ospf_timers_lsa_min_arrival, |
2362 | no_ospf_timers_lsa_min_arrival_cmd, | |
7a7be519 | 2363 | "no timers lsa min-arrival [(0-600000)]", |
b6927875 DS |
2364 | NO_STR |
2365 | "Adjust routing timers\n" | |
2366 | "OSPF LSA timers\n" | |
7a7be519 | 2367 | "Minimum delay in receiving new version of a LSA\n" |
2368 | "Delay in milliseconds\n") | |
b6927875 | 2369 | { |
a3d826f0 | 2370 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2371 | unsigned int minarrival; |
b6927875 | 2372 | |
d62a17ae | 2373 | if (argc > 4) { |
0e88de35 | 2374 | minarrival = strtoul(argv[argc - 1]->arg, NULL, 10); |
b6927875 | 2375 | |
d62a17ae | 2376 | if (ospf->min_ls_arrival != minarrival |
2377 | || minarrival == OSPF_MIN_LS_ARRIVAL) | |
2378 | return CMD_SUCCESS; | |
2379 | } | |
b6927875 | 2380 | |
d62a17ae | 2381 | ospf->min_ls_arrival = OSPF_MIN_LS_ARRIVAL; |
b6927875 | 2382 | |
d62a17ae | 2383 | return CMD_SUCCESS; |
b6927875 DS |
2384 | } |
2385 | ||
a2c62831 | 2386 | DEFUN (ospf_neighbor, |
2387 | ospf_neighbor_cmd, | |
7a7be519 | 2388 | "neighbor A.B.C.D [priority (0-255) [poll-interval (1-65535)]]", |
718e3744 | 2389 | NEIGHBOR_STR |
7a7be519 | 2390 | "Neighbor IP address\n" |
2391 | "Neighbor Priority\n" | |
2392 | "Priority\n" | |
2393 | "Dead Neighbor Polling interval\n" | |
2394 | "Seconds\n") | |
718e3744 | 2395 | { |
a3d826f0 | 2396 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2397 | int idx_ipv4 = 1; |
2398 | int idx_pri = 3; | |
2399 | int idx_poll = 5; | |
2400 | struct in_addr nbr_addr; | |
2401 | unsigned int priority = OSPF_NEIGHBOR_PRIORITY_DEFAULT; | |
2402 | unsigned int interval = OSPF_POLL_INTERVAL_DEFAULT; | |
718e3744 | 2403 | |
cc9b06ad DS |
2404 | if (!inet_aton(argv[idx_ipv4]->arg, &nbr_addr)) { |
2405 | vty_out(vty, "Please specify Neighbor ID by A.B.C.D\n"); | |
2406 | return CMD_WARNING_CONFIG_FAILED; | |
2407 | } | |
718e3744 | 2408 | |
d62a17ae | 2409 | if (argc > 2) |
2410 | priority = strtoul(argv[idx_pri]->arg, NULL, 10); | |
7a7be519 | 2411 | |
d62a17ae | 2412 | if (argc > 4) |
2413 | interval = strtoul(argv[idx_poll]->arg, NULL, 10); | |
718e3744 | 2414 | |
d62a17ae | 2415 | ospf_nbr_nbma_set(ospf, nbr_addr); |
7a7be519 | 2416 | |
d62a17ae | 2417 | if (argc > 2) |
2418 | ospf_nbr_nbma_priority_set(ospf, nbr_addr, priority); | |
7a7be519 | 2419 | |
d62a17ae | 2420 | if (argc > 4) |
2421 | ospf_nbr_nbma_poll_interval_set(ospf, nbr_addr, interval); | |
718e3744 | 2422 | |
d62a17ae | 2423 | return CMD_SUCCESS; |
718e3744 | 2424 | } |
2425 | ||
a2c62831 | 2426 | DEFUN (ospf_neighbor_poll_interval, |
2427 | ospf_neighbor_poll_interval_cmd, | |
7a7be519 | 2428 | "neighbor A.B.C.D poll-interval (1-65535) [priority (0-255)]", |
718e3744 | 2429 | NEIGHBOR_STR |
2430 | "Neighbor IP address\n" | |
2431 | "Dead Neighbor Polling interval\n" | |
7a7be519 | 2432 | "Seconds\n" |
2433 | "OSPF priority of non-broadcast neighbor\n" | |
2434 | "Priority\n") | |
22b27e95 | 2435 | { |
a3d826f0 | 2436 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2437 | int idx_ipv4 = 1; |
2438 | int idx_poll = 3; | |
2439 | int idx_pri = 5; | |
2440 | struct in_addr nbr_addr; | |
a2b6e694 | 2441 | unsigned int priority; |
2442 | unsigned int interval; | |
718e3744 | 2443 | |
cc9b06ad DS |
2444 | if (!inet_aton(argv[idx_ipv4]->arg, &nbr_addr)) { |
2445 | vty_out(vty, "Please specify Neighbor ID by A.B.C.D\n"); | |
2446 | return CMD_WARNING_CONFIG_FAILED; | |
2447 | } | |
718e3744 | 2448 | |
d62a17ae | 2449 | interval = strtoul(argv[idx_poll]->arg, NULL, 10); |
718e3744 | 2450 | |
a2b6e694 | 2451 | priority = argc > 4 ? strtoul(argv[idx_pri]->arg, NULL, 10) |
2452 | : OSPF_NEIGHBOR_PRIORITY_DEFAULT; | |
718e3744 | 2453 | |
d62a17ae | 2454 | ospf_nbr_nbma_set(ospf, nbr_addr); |
2455 | ospf_nbr_nbma_poll_interval_set(ospf, nbr_addr, interval); | |
7a7be519 | 2456 | |
d62a17ae | 2457 | if (argc > 4) |
2458 | ospf_nbr_nbma_priority_set(ospf, nbr_addr, priority); | |
718e3744 | 2459 | |
d62a17ae | 2460 | return CMD_SUCCESS; |
718e3744 | 2461 | } |
2462 | ||
a2c62831 | 2463 | DEFUN (no_ospf_neighbor, |
2464 | no_ospf_neighbor_cmd, | |
7a7be519 | 2465 | "no neighbor A.B.C.D [priority (0-255) [poll-interval (1-65525)]]", |
718e3744 | 2466 | NO_STR |
2467 | NEIGHBOR_STR | |
7a7be519 | 2468 | "Neighbor IP address\n" |
2469 | "Neighbor Priority\n" | |
2470 | "Priority\n" | |
2471 | "Dead Neighbor Polling interval\n" | |
2472 | "Seconds\n") | |
718e3744 | 2473 | { |
a3d826f0 | 2474 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2475 | int idx_ipv4 = 2; |
2476 | struct in_addr nbr_addr; | |
718e3744 | 2477 | |
cc9b06ad DS |
2478 | if (!inet_aton(argv[idx_ipv4]->arg, &nbr_addr)) { |
2479 | vty_out(vty, "Please specify Neighbor ID by A.B.C.D\n"); | |
2480 | return CMD_WARNING_CONFIG_FAILED; | |
2481 | } | |
718e3744 | 2482 | |
d62a17ae | 2483 | (void)ospf_nbr_nbma_unset(ospf, nbr_addr); |
718e3744 | 2484 | |
d62a17ae | 2485 | return CMD_SUCCESS; |
718e3744 | 2486 | } |
2487 | ||
7a7be519 | 2488 | DEFUN (no_ospf_neighbor_poll, |
2489 | no_ospf_neighbor_poll_cmd, | |
2490 | "no neighbor A.B.C.D poll-interval (1-65535) [priority (0-255)]", | |
2491 | NO_STR | |
2492 | NEIGHBOR_STR | |
2493 | "Neighbor IP address\n" | |
2494 | "Dead Neighbor Polling interval\n" | |
2495 | "Seconds\n" | |
2496 | "Neighbor Priority\n" | |
2497 | "Priority\n") | |
2498 | { | |
a3d826f0 | 2499 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2500 | int idx_ipv4 = 2; |
2501 | struct in_addr nbr_addr; | |
7a7be519 | 2502 | |
cc9b06ad DS |
2503 | if (!inet_aton(argv[idx_ipv4]->arg, &nbr_addr)) { |
2504 | vty_out(vty, "Please specify Neighbor ID by A.B.C.D\n"); | |
2505 | return CMD_WARNING_CONFIG_FAILED; | |
2506 | } | |
718e3744 | 2507 | |
d62a17ae | 2508 | (void)ospf_nbr_nbma_unset(ospf, nbr_addr); |
813d4307 | 2509 | |
d62a17ae | 2510 | return CMD_SUCCESS; |
7a7be519 | 2511 | } |
718e3744 | 2512 | |
bf2bfafd DW |
2513 | DEFUN (ospf_refresh_timer, |
2514 | ospf_refresh_timer_cmd, | |
6147e2c6 | 2515 | "refresh timer (10-1800)", |
718e3744 | 2516 | "Adjust refresh parameters\n" |
2517 | "Set refresh timer\n" | |
2518 | "Timer value in seconds\n") | |
2519 | { | |
a3d826f0 | 2520 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2521 | int idx_number = 2; |
2522 | unsigned int interval; | |
7c8ff89e | 2523 | |
d62a17ae | 2524 | interval = strtoul(argv[idx_number]->arg, NULL, 10); |
2525 | interval = (interval / OSPF_LSA_REFRESHER_GRANULARITY) | |
2526 | * OSPF_LSA_REFRESHER_GRANULARITY; | |
718e3744 | 2527 | |
d62a17ae | 2528 | ospf_timers_refresh_set(ospf, interval); |
718e3744 | 2529 | |
d62a17ae | 2530 | return CMD_SUCCESS; |
718e3744 | 2531 | } |
2532 | ||
bf2bfafd DW |
2533 | DEFUN (no_ospf_refresh_timer, |
2534 | no_ospf_refresh_timer_val_cmd, | |
7a7be519 | 2535 | "no refresh timer [(10-1800)]", |
3a2d747c | 2536 | NO_STR |
718e3744 | 2537 | "Adjust refresh parameters\n" |
2538 | "Unset refresh timer\n" | |
2539 | "Timer value in seconds\n") | |
2540 | { | |
a3d826f0 | 2541 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2542 | int idx_number = 3; |
2543 | unsigned int interval; | |
718e3744 | 2544 | |
d62a17ae | 2545 | if (argc == 1) { |
2546 | interval = strtoul(argv[idx_number]->arg, NULL, 10); | |
718e3744 | 2547 | |
d62a17ae | 2548 | if (ospf->lsa_refresh_interval != interval |
2549 | || interval == OSPF_LSA_REFRESH_INTERVAL_DEFAULT) | |
2550 | return CMD_SUCCESS; | |
2551 | } | |
2552 | ||
2553 | ospf_timers_refresh_unset(ospf); | |
2554 | ||
2555 | return CMD_SUCCESS; | |
718e3744 | 2556 | } |
2557 | ||
718e3744 | 2558 | |
a2c62831 | 2559 | DEFUN (ospf_auto_cost_reference_bandwidth, |
2560 | ospf_auto_cost_reference_bandwidth_cmd, | |
6147e2c6 | 2561 | "auto-cost reference-bandwidth (1-4294967)", |
718e3744 | 2562 | "Calculate OSPF interface cost according to bandwidth\n" |
2563 | "Use reference bandwidth method to assign OSPF cost\n" | |
2564 | "The reference bandwidth in terms of Mbits per second\n") | |
2565 | { | |
a3d826f0 | 2566 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
f4e14fdb | 2567 | struct vrf *vrf = vrf_lookup_by_id(ospf->vrf_id); |
d62a17ae | 2568 | int idx_number = 2; |
d7c0a89a | 2569 | uint32_t refbw; |
d62a17ae | 2570 | struct interface *ifp; |
2571 | ||
2572 | refbw = strtol(argv[idx_number]->arg, NULL, 10); | |
2573 | if (refbw < 1 || refbw > 4294967) { | |
2574 | vty_out(vty, "reference-bandwidth value is invalid\n"); | |
2575 | return CMD_WARNING_CONFIG_FAILED; | |
2576 | } | |
2577 | ||
2578 | /* If reference bandwidth is changed. */ | |
2579 | if ((refbw) == ospf->ref_bandwidth) | |
2580 | return CMD_SUCCESS; | |
2581 | ||
2582 | ospf->ref_bandwidth = refbw; | |
451fda4f | 2583 | FOR_ALL_INTERFACES (vrf, ifp) |
d62a17ae | 2584 | ospf_if_recalculate_output_cost(ifp); |
2585 | ||
2586 | return CMD_SUCCESS; | |
718e3744 | 2587 | } |
2588 | ||
a2c62831 | 2589 | DEFUN (no_ospf_auto_cost_reference_bandwidth, |
2590 | no_ospf_auto_cost_reference_bandwidth_cmd, | |
7a7be519 | 2591 | "no auto-cost reference-bandwidth [(1-4294967)]", |
718e3744 | 2592 | NO_STR |
2593 | "Calculate OSPF interface cost according to bandwidth\n" | |
7a7be519 | 2594 | "Use reference bandwidth method to assign OSPF cost\n" |
2595 | "The reference bandwidth in terms of Mbits per second\n") | |
718e3744 | 2596 | { |
a3d826f0 | 2597 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
f4e14fdb | 2598 | struct vrf *vrf = vrf_lookup_by_id(ospf->vrf_id); |
d62a17ae | 2599 | struct interface *ifp; |
718e3744 | 2600 | |
d62a17ae | 2601 | if (ospf->ref_bandwidth == OSPF_DEFAULT_REF_BANDWIDTH) |
2602 | return CMD_SUCCESS; | |
2603 | ||
2604 | ospf->ref_bandwidth = OSPF_DEFAULT_REF_BANDWIDTH; | |
2605 | vty_out(vty, "%% OSPF: Reference bandwidth is changed.\n"); | |
2606 | vty_out(vty, | |
2607 | " Please ensure reference bandwidth is consistent across all routers\n"); | |
2608 | ||
451fda4f | 2609 | FOR_ALL_INTERFACES (vrf, ifp) |
d62a17ae | 2610 | ospf_if_recalculate_output_cost(ifp); |
2611 | ||
2612 | return CMD_SUCCESS; | |
718e3744 | 2613 | } |
2614 | ||
2f8f370e DS |
2615 | DEFUN (ospf_write_multiplier, |
2616 | ospf_write_multiplier_cmd, | |
6147e2c6 | 2617 | "ospf write-multiplier (1-100)", |
e8f45e82 DS |
2618 | "OSPF specific commands\n" |
2619 | "Write multiplier\n" | |
2620 | "Maximum number of interface serviced per write\n") | |
2f8f370e | 2621 | { |
a3d826f0 | 2622 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2623 | int idx_number; |
d7c0a89a | 2624 | uint32_t write_oi_count; |
d62a17ae | 2625 | |
2626 | if (argc == 3) | |
2627 | idx_number = 2; | |
2628 | else | |
2629 | idx_number = 1; | |
2630 | ||
2631 | write_oi_count = strtol(argv[idx_number]->arg, NULL, 10); | |
2632 | if (write_oi_count < 1 || write_oi_count > 100) { | |
2633 | vty_out(vty, "write-multiplier value is invalid\n"); | |
2634 | return CMD_WARNING_CONFIG_FAILED; | |
2635 | } | |
2636 | ||
2637 | ospf->write_oi_count = write_oi_count; | |
2638 | return CMD_SUCCESS; | |
2f8f370e DS |
2639 | } |
2640 | ||
d62a17ae | 2641 | ALIAS(ospf_write_multiplier, write_multiplier_cmd, "write-multiplier (1-100)", |
2642 | "Write multiplier\n" | |
2643 | "Maximum number of interface serviced per write\n") | |
e8f45e82 | 2644 | |
2f8f370e DS |
2645 | DEFUN (no_ospf_write_multiplier, |
2646 | no_ospf_write_multiplier_cmd, | |
6147e2c6 | 2647 | "no ospf write-multiplier (1-100)", |
2f8f370e | 2648 | NO_STR |
e8f45e82 | 2649 | "OSPF specific commands\n" |
813d4307 DW |
2650 | "Write multiplier\n" |
2651 | "Maximum number of interface serviced per write\n") | |
2f8f370e | 2652 | { |
a3d826f0 | 2653 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
2f8f370e | 2654 | |
d62a17ae | 2655 | ospf->write_oi_count = OSPF_WRITE_INTERFACE_COUNT_DEFAULT; |
2656 | return CMD_SUCCESS; | |
2f8f370e DS |
2657 | } |
2658 | ||
d62a17ae | 2659 | ALIAS(no_ospf_write_multiplier, no_write_multiplier_cmd, |
9d303b37 | 2660 | "no write-multiplier (1-100)", NO_STR |
d62a17ae | 2661 | "Write multiplier\n" |
2662 | "Maximum number of interface serviced per write\n") | |
2663 | ||
385a1e07 | 2664 | DEFUN(ospf_ti_lfa, ospf_ti_lfa_cmd, "fast-reroute ti-lfa [node-protection]", |
7fd0729f | 2665 | "Fast Reroute for MPLS and IP resilience\n" |
385a1e07 G |
2666 | "Topology Independent LFA (Loop-Free Alternate)\n" |
2667 | "TI-LFA node protection (default is link protection)\n") | |
7fd0729f G |
2668 | { |
2669 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
2670 | ||
2671 | ospf->ti_lfa_enabled = true; | |
2672 | ||
385a1e07 G |
2673 | if (argc == 3) |
2674 | ospf->ti_lfa_protection_type = OSPF_TI_LFA_NODE_PROTECTION; | |
2675 | else | |
2676 | ospf->ti_lfa_protection_type = OSPF_TI_LFA_LINK_PROTECTION; | |
2677 | ||
7fd0729f G |
2678 | ospf_spf_calculate_schedule(ospf, SPF_FLAG_CONFIG_CHANGE); |
2679 | ||
2680 | return CMD_SUCCESS; | |
2681 | } | |
2682 | ||
385a1e07 G |
2683 | DEFUN(no_ospf_ti_lfa, no_ospf_ti_lfa_cmd, |
2684 | "no fast-reroute ti-lfa [node-protection]", | |
7fd0729f G |
2685 | NO_STR |
2686 | "Fast Reroute for MPLS and IP resilience\n" | |
385a1e07 G |
2687 | "Topology Independent LFA (Loop-Free Alternate)\n" |
2688 | "TI-LFA node protection (default is link protection)\n") | |
7fd0729f G |
2689 | { |
2690 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
2691 | ||
2692 | ospf->ti_lfa_enabled = false; | |
2693 | ||
385a1e07 G |
2694 | ospf->ti_lfa_protection_type = OSPF_TI_LFA_UNDEFINED_PROTECTION; |
2695 | ||
7fd0729f G |
2696 | ospf_spf_calculate_schedule(ospf, SPF_FLAG_CONFIG_CHANGE); |
2697 | ||
2698 | return CMD_SUCCESS; | |
2699 | } | |
2700 | ||
3d5b9855 | 2701 | static void ospf_maxpath_set(struct vty *vty, struct ospf *ospf, uint16_t paths) |
2702 | { | |
2703 | if (ospf->max_multipath == paths) | |
2704 | return; | |
2705 | ||
2706 | ospf->max_multipath = paths; | |
2707 | ||
2708 | /* Send deletion notification to zebra to delete all | |
2709 | * ospf specific routes and reinitiat SPF to reflect | |
2710 | * the new max multipath. | |
2711 | */ | |
2712 | ospf_restart_spf(ospf); | |
2713 | } | |
2714 | ||
2715 | /* Ospf Maximum multiple paths config support */ | |
2716 | DEFUN (ospf_max_multipath, | |
2717 | ospf_max_multipath_cmd, | |
2718 | "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM), | |
2719 | "Max no of multiple paths for ECMP support\n" | |
2720 | "Number of paths\n") | |
2721 | { | |
2722 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
2723 | int idx_number = 1; | |
2724 | uint16_t maxpaths; | |
2725 | ||
2726 | maxpaths = strtol(argv[idx_number]->arg, NULL, 10); | |
2727 | ||
2728 | ospf_maxpath_set(vty, ospf, maxpaths); | |
2729 | return CMD_SUCCESS; | |
2730 | } | |
2731 | ||
2732 | DEFUN (no_ospf_max_multipath, | |
2733 | no_ospf_max_multipath_cmd, | |
2734 | "no maximum-paths", | |
2735 | NO_STR | |
2736 | "Max no of multiple paths for ECMP support\n") | |
2737 | { | |
2738 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
2739 | uint16_t maxpaths = MULTIPATH_NUM; | |
2740 | ||
2741 | ospf_maxpath_set(vty, ospf, maxpaths); | |
2742 | return CMD_SUCCESS; | |
2743 | } | |
2744 | ||
2b64873d DL |
2745 | static const char *const ospf_abr_type_descr_str[] = { |
2746 | "Unknown", "Standard (RFC2328)", "Alternative IBM", | |
2747 | "Alternative Cisco", "Alternative Shortcut" | |
2748 | }; | |
d62a17ae | 2749 | |
2b64873d DL |
2750 | static const char *const ospf_shortcut_mode_descr_str[] = { |
2751 | "Default", "Enabled", "Disabled" | |
2752 | }; | |
d62a17ae | 2753 | |
2754 | static void show_ip_ospf_area(struct vty *vty, struct ospf_area *area, | |
9f049418 | 2755 | json_object *json_areas, bool use_json) |
d62a17ae | 2756 | { |
2757 | json_object *json_area = NULL; | |
96b663a3 | 2758 | char buf[PREFIX_STRLEN]; |
d62a17ae | 2759 | |
2760 | if (use_json) | |
2761 | json_area = json_object_new_object(); | |
2762 | ||
2763 | /* Show Area ID. */ | |
2764 | if (!use_json) | |
96b663a3 | 2765 | vty_out(vty, " Area ID: %pI4", &area->area_id); |
d62a17ae | 2766 | |
2767 | /* Show Area type/mode. */ | |
2768 | if (OSPF_IS_AREA_BACKBONE(area)) { | |
2769 | if (use_json) | |
2770 | json_object_boolean_true_add(json_area, "backbone"); | |
2771 | else | |
2772 | vty_out(vty, " (Backbone)\n"); | |
2773 | } else { | |
2774 | if (use_json) { | |
2775 | if (area->external_routing == OSPF_AREA_STUB) { | |
2776 | if (area->no_summary) | |
2777 | json_object_boolean_true_add( | |
2778 | json_area, "stubNoSummary"); | |
2779 | if (area->shortcut_configured) | |
2780 | json_object_boolean_true_add( | |
2781 | json_area, "stubShortcut"); | |
2782 | } else if (area->external_routing == OSPF_AREA_NSSA) { | |
2783 | if (area->no_summary) | |
2784 | json_object_boolean_true_add( | |
2785 | json_area, "nssaNoSummary"); | |
2786 | if (area->shortcut_configured) | |
2787 | json_object_boolean_true_add( | |
2788 | json_area, "nssaShortcut"); | |
2789 | } | |
813d4307 | 2790 | |
d62a17ae | 2791 | json_object_string_add( |
2792 | json_area, "shortcuttingMode", | |
2793 | ospf_shortcut_mode_descr_str | |
2794 | [area->shortcut_configured]); | |
2795 | if (area->shortcut_capability) | |
2796 | json_object_boolean_true_add(json_area, | |
2797 | "sBitConcensus"); | |
2798 | } else { | |
2799 | if (area->external_routing == OSPF_AREA_STUB) | |
2800 | vty_out(vty, " (Stub%s%s)", | |
2801 | area->no_summary ? ", no summary" : "", | |
2802 | area->shortcut_configured ? "; " : ""); | |
2803 | else if (area->external_routing == OSPF_AREA_NSSA) | |
2804 | vty_out(vty, " (NSSA%s%s)", | |
2805 | area->no_summary ? ", no summary" : "", | |
2806 | area->shortcut_configured ? "; " : ""); | |
2807 | ||
2808 | vty_out(vty, "\n"); | |
2809 | vty_out(vty, " Shortcutting mode: %s", | |
2810 | ospf_shortcut_mode_descr_str | |
2811 | [area->shortcut_configured]); | |
2812 | vty_out(vty, ", S-bit consensus: %s\n", | |
2813 | area->shortcut_capability ? "ok" : "no"); | |
2814 | } | |
2815 | } | |
718e3744 | 2816 | |
d62a17ae | 2817 | /* Show number of interfaces */ |
2818 | if (use_json) { | |
2819 | json_object_int_add(json_area, "areaIfTotalCounter", | |
2820 | listcount(area->oiflist)); | |
2821 | json_object_int_add(json_area, "areaIfActiveCounter", | |
2822 | area->act_ints); | |
2823 | } else | |
2824 | vty_out(vty, | |
3efd0893 | 2825 | " Number of interfaces in this area: Total: %d, Active: %d\n", |
d62a17ae | 2826 | listcount(area->oiflist), area->act_ints); |
2827 | ||
2828 | if (area->external_routing == OSPF_AREA_NSSA) { | |
2829 | if (use_json) { | |
2830 | json_object_boolean_true_add(json_area, "nssa"); | |
2831 | if (!IS_OSPF_ABR(area->ospf)) | |
2832 | json_object_boolean_false_add(json_area, "abr"); | |
2833 | else if (area->NSSATranslatorState) { | |
2834 | json_object_boolean_true_add(json_area, "abr"); | |
2835 | if (area->NSSATranslatorRole | |
2836 | == OSPF_NSSA_ROLE_CANDIDATE) | |
2837 | json_object_boolean_true_add( | |
2838 | json_area, | |
2839 | "nssaTranslatorElected"); | |
2840 | else if (area->NSSATranslatorRole | |
2841 | == OSPF_NSSA_ROLE_ALWAYS) | |
2842 | json_object_boolean_true_add( | |
2843 | json_area, | |
2844 | "nssaTranslatorAlways"); | |
b79c3070 | 2845 | else |
2846 | json_object_boolean_true_add( | |
2847 | json_area, | |
2848 | "nssaTranslatorNever"); | |
d62a17ae | 2849 | } else { |
2850 | json_object_boolean_true_add(json_area, "abr"); | |
2851 | if (area->NSSATranslatorRole | |
2852 | == OSPF_NSSA_ROLE_CANDIDATE) | |
2853 | json_object_boolean_false_add( | |
2854 | json_area, | |
2855 | "nssaTranslatorElected"); | |
2856 | else | |
2857 | json_object_boolean_true_add( | |
2858 | json_area, | |
2859 | "nssaTranslatorNever"); | |
2860 | } | |
2861 | } else { | |
2862 | vty_out(vty, | |
b79c3070 | 2863 | " It is an NSSA configuration.\n Elected NSSA/ABR performs type-7/type-5 LSA translation.\n"); |
d62a17ae | 2864 | if (!IS_OSPF_ABR(area->ospf)) |
2865 | vty_out(vty, | |
b79c3070 | 2866 | " It is not ABR, therefore not Translator.\n"); |
d62a17ae | 2867 | else if (area->NSSATranslatorState) { |
2868 | vty_out(vty, " We are an ABR and "); | |
2869 | if (area->NSSATranslatorRole | |
2870 | == OSPF_NSSA_ROLE_CANDIDATE) | |
2871 | vty_out(vty, | |
b79c3070 | 2872 | "the NSSA Elected Translator.\n"); |
d62a17ae | 2873 | else if (area->NSSATranslatorRole |
2874 | == OSPF_NSSA_ROLE_ALWAYS) | |
2875 | vty_out(vty, | |
b79c3070 | 2876 | "always an NSSA Translator.\n"); |
2877 | else | |
2878 | vty_out(vty, | |
2879 | "never an NSSA Translator.\n"); | |
d62a17ae | 2880 | } else { |
2881 | vty_out(vty, " We are an ABR, but "); | |
2882 | if (area->NSSATranslatorRole | |
2883 | == OSPF_NSSA_ROLE_CANDIDATE) | |
2884 | vty_out(vty, | |
b79c3070 | 2885 | "not the NSSA Elected Translator.\n"); |
d62a17ae | 2886 | else |
2887 | vty_out(vty, | |
b79c3070 | 2888 | "never an NSSA Translator.\n"); |
d62a17ae | 2889 | } |
2890 | } | |
2891 | } | |
2892 | ||
2893 | /* Stub-router state for this area */ | |
2894 | if (CHECK_FLAG(area->stub_router_state, OSPF_AREA_IS_STUB_ROUTED)) { | |
2895 | char timebuf[OSPF_TIME_DUMP_SIZE]; | |
2896 | ||
2897 | if (use_json) { | |
2898 | json_object_boolean_true_add( | |
2899 | json_area, "originStubMaxDistRouterLsa"); | |
2900 | if (CHECK_FLAG(area->stub_router_state, | |
2901 | OSPF_AREA_ADMIN_STUB_ROUTED)) | |
2902 | json_object_boolean_true_add( | |
2903 | json_area, "indefiniteActiveAdmin"); | |
2904 | if (area->t_stub_router) { | |
2905 | long time_store; | |
2906 | time_store = | |
2907 | monotime_until( | |
2908 | &area->t_stub_router->u.sands, | |
2909 | NULL) | |
2910 | / 1000LL; | |
2911 | json_object_int_add( | |
2912 | json_area, | |
2913 | "activeStartupRemainderMsecs", | |
2914 | time_store); | |
2915 | } | |
2916 | } else { | |
2917 | vty_out(vty, | |
2918 | " Originating stub / maximum-distance Router-LSA\n"); | |
2919 | if (CHECK_FLAG(area->stub_router_state, | |
2920 | OSPF_AREA_ADMIN_STUB_ROUTED)) | |
2921 | vty_out(vty, | |
2922 | " Administratively activated (indefinitely)\n"); | |
2923 | if (area->t_stub_router) | |
2924 | vty_out(vty, | |
2925 | " Active from startup, %s remaining\n", | |
2926 | ospf_timer_dump(area->t_stub_router, | |
2927 | timebuf, | |
2928 | sizeof(timebuf))); | |
2929 | } | |
2930 | } | |
2931 | ||
2932 | if (use_json) { | |
2933 | /* Show number of fully adjacent neighbors. */ | |
2934 | json_object_int_add(json_area, "nbrFullAdjacentCounter", | |
2935 | area->full_nbrs); | |
2936 | ||
2937 | /* Show authentication type. */ | |
2938 | if (area->auth_type == OSPF_AUTH_NULL) | |
2939 | json_object_string_add(json_area, "authentication", | |
2940 | "authenticationNone"); | |
2941 | else if (area->auth_type == OSPF_AUTH_SIMPLE) | |
2942 | json_object_string_add(json_area, "authentication", | |
2943 | "authenticationSimplePassword"); | |
2944 | else if (area->auth_type == OSPF_AUTH_CRYPTOGRAPHIC) | |
2945 | json_object_string_add(json_area, "authentication", | |
2946 | "authenticationMessageDigest"); | |
2947 | ||
2948 | if (!OSPF_IS_AREA_BACKBONE(area)) | |
2949 | json_object_int_add(json_area, | |
2950 | "virtualAdjacenciesPassingCounter", | |
2951 | area->full_vls); | |
2952 | ||
2953 | /* Show SPF calculation times. */ | |
2954 | json_object_int_add(json_area, "spfExecutedCounter", | |
2955 | area->spf_calculation); | |
2956 | json_object_int_add(json_area, "lsaNumber", area->lsdb->total); | |
2957 | json_object_int_add( | |
2958 | json_area, "lsaRouterNumber", | |
2959 | ospf_lsdb_count(area->lsdb, OSPF_ROUTER_LSA)); | |
2960 | json_object_int_add( | |
2961 | json_area, "lsaRouterChecksum", | |
2962 | ospf_lsdb_checksum(area->lsdb, OSPF_ROUTER_LSA)); | |
2963 | json_object_int_add( | |
2964 | json_area, "lsaNetworkNumber", | |
2965 | ospf_lsdb_count(area->lsdb, OSPF_NETWORK_LSA)); | |
2966 | json_object_int_add( | |
2967 | json_area, "lsaNetworkChecksum", | |
2968 | ospf_lsdb_checksum(area->lsdb, OSPF_NETWORK_LSA)); | |
2969 | json_object_int_add( | |
2970 | json_area, "lsaSummaryNumber", | |
2971 | ospf_lsdb_count(area->lsdb, OSPF_SUMMARY_LSA)); | |
2972 | json_object_int_add( | |
2973 | json_area, "lsaSummaryChecksum", | |
2974 | ospf_lsdb_checksum(area->lsdb, OSPF_SUMMARY_LSA)); | |
2975 | json_object_int_add( | |
2976 | json_area, "lsaAsbrNumber", | |
2977 | ospf_lsdb_count(area->lsdb, OSPF_ASBR_SUMMARY_LSA)); | |
2978 | json_object_int_add( | |
2979 | json_area, "lsaAsbrChecksum", | |
2980 | ospf_lsdb_checksum(area->lsdb, OSPF_ASBR_SUMMARY_LSA)); | |
2981 | json_object_int_add( | |
2982 | json_area, "lsaNssaNumber", | |
2983 | ospf_lsdb_count(area->lsdb, OSPF_AS_NSSA_LSA)); | |
2984 | json_object_int_add( | |
2985 | json_area, "lsaNssaChecksum", | |
2986 | ospf_lsdb_checksum(area->lsdb, OSPF_AS_NSSA_LSA)); | |
2987 | } else { | |
2988 | /* Show number of fully adjacent neighbors. */ | |
2989 | vty_out(vty, | |
3efd0893 | 2990 | " Number of fully adjacent neighbors in this area: %d\n", |
d62a17ae | 2991 | area->full_nbrs); |
2992 | ||
2993 | /* Show authentication type. */ | |
2994 | vty_out(vty, " Area has "); | |
2995 | if (area->auth_type == OSPF_AUTH_NULL) | |
2996 | vty_out(vty, "no authentication\n"); | |
2997 | else if (area->auth_type == OSPF_AUTH_SIMPLE) | |
2998 | vty_out(vty, "simple password authentication\n"); | |
2999 | else if (area->auth_type == OSPF_AUTH_CRYPTOGRAPHIC) | |
3000 | vty_out(vty, "message digest authentication\n"); | |
3001 | ||
3002 | if (!OSPF_IS_AREA_BACKBONE(area)) | |
3003 | vty_out(vty, | |
3efd0893 | 3004 | " Number of full virtual adjacencies going through this area: %d\n", |
d62a17ae | 3005 | area->full_vls); |
3006 | ||
3007 | /* Show SPF calculation times. */ | |
3008 | vty_out(vty, " SPF algorithm executed %d times\n", | |
3009 | area->spf_calculation); | |
3010 | ||
3011 | /* Show number of LSA. */ | |
3012 | vty_out(vty, " Number of LSA %ld\n", area->lsdb->total); | |
3013 | vty_out(vty, | |
3014 | " Number of router LSA %ld. Checksum Sum 0x%08x\n", | |
3015 | ospf_lsdb_count(area->lsdb, OSPF_ROUTER_LSA), | |
3016 | ospf_lsdb_checksum(area->lsdb, OSPF_ROUTER_LSA)); | |
3017 | vty_out(vty, | |
3018 | " Number of network LSA %ld. Checksum Sum 0x%08x\n", | |
3019 | ospf_lsdb_count(area->lsdb, OSPF_NETWORK_LSA), | |
3020 | ospf_lsdb_checksum(area->lsdb, OSPF_NETWORK_LSA)); | |
3021 | vty_out(vty, | |
3022 | " Number of summary LSA %ld. Checksum Sum 0x%08x\n", | |
3023 | ospf_lsdb_count(area->lsdb, OSPF_SUMMARY_LSA), | |
3024 | ospf_lsdb_checksum(area->lsdb, OSPF_SUMMARY_LSA)); | |
3025 | vty_out(vty, | |
3026 | " Number of ASBR summary LSA %ld. Checksum Sum 0x%08x\n", | |
3027 | ospf_lsdb_count(area->lsdb, OSPF_ASBR_SUMMARY_LSA), | |
3028 | ospf_lsdb_checksum(area->lsdb, OSPF_ASBR_SUMMARY_LSA)); | |
3029 | vty_out(vty, " Number of NSSA LSA %ld. Checksum Sum 0x%08x\n", | |
3030 | ospf_lsdb_count(area->lsdb, OSPF_AS_NSSA_LSA), | |
3031 | ospf_lsdb_checksum(area->lsdb, OSPF_AS_NSSA_LSA)); | |
3032 | } | |
3033 | ||
3034 | if (use_json) { | |
3035 | json_object_int_add( | |
3036 | json_area, "lsaOpaqueLinkNumber", | |
3037 | ospf_lsdb_count(area->lsdb, OSPF_OPAQUE_LINK_LSA)); | |
3038 | json_object_int_add( | |
3039 | json_area, "lsaOpaqueLinkChecksum", | |
3040 | ospf_lsdb_checksum(area->lsdb, OSPF_OPAQUE_LINK_LSA)); | |
3041 | json_object_int_add( | |
3042 | json_area, "lsaOpaqueAreaNumber", | |
3043 | ospf_lsdb_count(area->lsdb, OSPF_OPAQUE_AREA_LSA)); | |
3044 | json_object_int_add( | |
3045 | json_area, "lsaOpaqueAreaChecksum", | |
3046 | ospf_lsdb_checksum(area->lsdb, OSPF_OPAQUE_AREA_LSA)); | |
3047 | } else { | |
3048 | vty_out(vty, | |
3049 | " Number of opaque link LSA %ld. Checksum Sum 0x%08x\n", | |
3050 | ospf_lsdb_count(area->lsdb, OSPF_OPAQUE_LINK_LSA), | |
3051 | ospf_lsdb_checksum(area->lsdb, OSPF_OPAQUE_LINK_LSA)); | |
3052 | vty_out(vty, | |
3053 | " Number of opaque area LSA %ld. Checksum Sum 0x%08x\n", | |
3054 | ospf_lsdb_count(area->lsdb, OSPF_OPAQUE_AREA_LSA), | |
3055 | ospf_lsdb_checksum(area->lsdb, OSPF_OPAQUE_AREA_LSA)); | |
3056 | } | |
718e3744 | 3057 | |
d62a17ae | 3058 | if (use_json) |
96b663a3 MS |
3059 | json_object_object_add(json_areas, |
3060 | inet_ntop(AF_INET, &area->area_id, | |
3061 | buf, sizeof(buf)), | |
d62a17ae | 3062 | json_area); |
3063 | else | |
3064 | vty_out(vty, "\n"); | |
718e3744 | 3065 | } |
3066 | ||
d62a17ae | 3067 | static int show_ip_ospf_common(struct vty *vty, struct ospf *ospf, |
d7c0a89a | 3068 | json_object *json, uint8_t use_vrf) |
d62a17ae | 3069 | { |
3070 | struct listnode *node, *nnode; | |
3071 | struct ospf_area *area; | |
3072 | struct timeval result; | |
3073 | char timebuf[OSPF_TIME_DUMP_SIZE]; | |
b1c3ae8c | 3074 | json_object *json_vrf = NULL; |
d62a17ae | 3075 | json_object *json_areas = NULL; |
718e3744 | 3076 | |
b1c3ae8c CS |
3077 | if (json) { |
3078 | if (use_vrf) | |
3079 | json_vrf = json_object_new_object(); | |
3080 | else | |
3081 | json_vrf = json; | |
d62a17ae | 3082 | json_areas = json_object_new_object(); |
3083 | } | |
3084 | ||
3085 | if (ospf->instance) { | |
b1c3ae8c | 3086 | if (json) { |
d62a17ae | 3087 | json_object_int_add(json, "ospfInstance", |
3088 | ospf->instance); | |
3089 | } else { | |
3090 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
3091 | } | |
3092 | } | |
3093 | ||
b1c3ae8c | 3094 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); |
87bd50e8 | 3095 | |
d62a17ae | 3096 | /* Show Router ID. */ |
b1c3ae8c | 3097 | if (json) { |
20308be3 DA |
3098 | json_object_string_addf(json_vrf, "routerId", "%pI4", |
3099 | &ospf->router_id); | |
d62a17ae | 3100 | } else { |
96b663a3 MS |
3101 | vty_out(vty, " OSPF Routing Process, Router ID: %pI4\n", |
3102 | &ospf->router_id); | |
d62a17ae | 3103 | } |
3104 | ||
3105 | /* Graceful shutdown */ | |
3106 | if (ospf->t_deferred_shutdown) { | |
b1c3ae8c | 3107 | if (json) { |
d62a17ae | 3108 | long time_store; |
3109 | time_store = | |
3110 | monotime_until( | |
3111 | &ospf->t_deferred_shutdown->u.sands, | |
3112 | NULL) | |
3113 | / 1000LL; | |
b1c3ae8c | 3114 | json_object_int_add(json_vrf, "deferredShutdownMsecs", |
d62a17ae | 3115 | time_store); |
3116 | } else { | |
3117 | vty_out(vty, | |
3118 | " Deferred shutdown in progress, %s remaining\n", | |
3119 | ospf_timer_dump(ospf->t_deferred_shutdown, | |
3120 | timebuf, sizeof(timebuf))); | |
3121 | } | |
3122 | } | |
3123 | ||
3124 | /* Show capability. */ | |
b1c3ae8c CS |
3125 | if (json) { |
3126 | json_object_boolean_true_add(json_vrf, "tosRoutesOnly"); | |
3127 | json_object_boolean_true_add(json_vrf, "rfc2328Conform"); | |
d62a17ae | 3128 | if (CHECK_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE)) { |
b1c3ae8c | 3129 | json_object_boolean_true_add(json_vrf, |
d62a17ae | 3130 | "rfc1583Compatibility"); |
3131 | } | |
3132 | } else { | |
3133 | vty_out(vty, " Supports only single TOS (TOS0) routes\n"); | |
3134 | vty_out(vty, " This implementation conforms to RFC2328\n"); | |
3135 | vty_out(vty, " RFC1583Compatibility flag is %s\n", | |
3136 | CHECK_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE) | |
3137 | ? "enabled" | |
3138 | : "disabled"); | |
3139 | } | |
3140 | ||
b1c3ae8c | 3141 | if (json) { |
d62a17ae | 3142 | if (CHECK_FLAG(ospf->config, OSPF_OPAQUE_CAPABLE)) { |
b1c3ae8c | 3143 | json_object_boolean_true_add(json_vrf, "opaqueCapable"); |
d62a17ae | 3144 | } |
3145 | } else { | |
3146 | vty_out(vty, " OpaqueCapability flag is %s\n", | |
3147 | CHECK_FLAG(ospf->config, OSPF_OPAQUE_CAPABLE) | |
3148 | ? "enabled" | |
3149 | : "disabled"); | |
3150 | } | |
3151 | ||
3152 | /* Show stub-router configuration */ | |
3153 | if (ospf->stub_router_startup_time != OSPF_STUB_ROUTER_UNCONFIGURED | |
3154 | || ospf->stub_router_shutdown_time | |
3155 | != OSPF_STUB_ROUTER_UNCONFIGURED) { | |
b1c3ae8c CS |
3156 | if (json) { |
3157 | json_object_boolean_true_add(json_vrf, | |
3158 | "stubAdvertisement"); | |
d62a17ae | 3159 | if (ospf->stub_router_startup_time |
3160 | != OSPF_STUB_ROUTER_UNCONFIGURED) | |
3161 | json_object_int_add( | |
50ad4b42 MS |
3162 | json_vrf, "postStartEnabledSecs", |
3163 | ospf->stub_router_startup_time); | |
d62a17ae | 3164 | if (ospf->stub_router_shutdown_time |
3165 | != OSPF_STUB_ROUTER_UNCONFIGURED) | |
3166 | json_object_int_add( | |
50ad4b42 MS |
3167 | json_vrf, "preShutdownEnabledSecs", |
3168 | ospf->stub_router_shutdown_time); | |
d62a17ae | 3169 | } else { |
3170 | vty_out(vty, | |
3171 | " Stub router advertisement is configured\n"); | |
3172 | if (ospf->stub_router_startup_time | |
3173 | != OSPF_STUB_ROUTER_UNCONFIGURED) | |
3174 | vty_out(vty, | |
3175 | " Enabled for %us after start-up\n", | |
3176 | ospf->stub_router_startup_time); | |
3177 | if (ospf->stub_router_shutdown_time | |
3178 | != OSPF_STUB_ROUTER_UNCONFIGURED) | |
3179 | vty_out(vty, | |
3180 | " Enabled for %us prior to full shutdown\n", | |
3181 | ospf->stub_router_shutdown_time); | |
3182 | } | |
3183 | } | |
3184 | ||
3185 | /* Show SPF timers. */ | |
b1c3ae8c CS |
3186 | if (json) { |
3187 | json_object_int_add(json_vrf, "spfScheduleDelayMsecs", | |
d62a17ae | 3188 | ospf->spf_delay); |
b1c3ae8c | 3189 | json_object_int_add(json_vrf, "holdtimeMinMsecs", |
d62a17ae | 3190 | ospf->spf_holdtime); |
b1c3ae8c | 3191 | json_object_int_add(json_vrf, "holdtimeMaxMsecs", |
d62a17ae | 3192 | ospf->spf_max_holdtime); |
b1c3ae8c | 3193 | json_object_int_add(json_vrf, "holdtimeMultplier", |
d62a17ae | 3194 | ospf->spf_hold_multiplier); |
3195 | } else { | |
3196 | vty_out(vty, | |
3197 | " Initial SPF scheduling delay %d millisec(s)\n" | |
3198 | " Minimum hold time between consecutive SPFs %d millisec(s)\n" | |
3199 | " Maximum hold time between consecutive SPFs %d millisec(s)\n" | |
3200 | " Hold time multiplier is currently %d\n", | |
3201 | ospf->spf_delay, ospf->spf_holdtime, | |
3202 | ospf->spf_max_holdtime, ospf->spf_hold_multiplier); | |
3203 | } | |
3204 | ||
b1c3ae8c | 3205 | if (json) { |
d62a17ae | 3206 | if (ospf->ts_spf.tv_sec || ospf->ts_spf.tv_usec) { |
3207 | long time_store = 0; | |
3208 | ||
3209 | time_store = | |
3210 | monotime_since(&ospf->ts_spf, NULL) / 1000LL; | |
b1c3ae8c | 3211 | json_object_int_add(json_vrf, "spfLastExecutedMsecs", |
d62a17ae | 3212 | time_store); |
3213 | ||
3214 | time_store = (1000 * ospf->ts_spf_duration.tv_sec) | |
3215 | + (ospf->ts_spf_duration.tv_usec / 1000); | |
b1c3ae8c | 3216 | json_object_int_add(json_vrf, "spfLastDurationMsecs", |
d62a17ae | 3217 | time_store); |
3218 | } else | |
b1c3ae8c | 3219 | json_object_boolean_true_add(json_vrf, "spfHasNotRun"); |
d62a17ae | 3220 | } else { |
3221 | vty_out(vty, " SPF algorithm "); | |
3222 | if (ospf->ts_spf.tv_sec || ospf->ts_spf.tv_usec) { | |
3223 | monotime_since(&ospf->ts_spf, &result); | |
3224 | vty_out(vty, "last executed %s ago\n", | |
3225 | ospf_timeval_dump(&result, timebuf, | |
3226 | sizeof(timebuf))); | |
3227 | vty_out(vty, " Last SPF duration %s\n", | |
3228 | ospf_timeval_dump(&ospf->ts_spf_duration, | |
3229 | timebuf, sizeof(timebuf))); | |
3230 | } else | |
3231 | vty_out(vty, "has not been run\n"); | |
3232 | } | |
3233 | ||
b1c3ae8c | 3234 | if (json) { |
d62a17ae | 3235 | if (ospf->t_spf_calc) { |
3236 | long time_store; | |
3237 | time_store = | |
3238 | monotime_until(&ospf->t_spf_calc->u.sands, NULL) | |
3239 | / 1000LL; | |
b1c3ae8c | 3240 | json_object_int_add(json_vrf, "spfTimerDueInMsecs", |
d62a17ae | 3241 | time_store); |
3242 | } | |
3243 | ||
b1c3ae8c | 3244 | json_object_int_add(json_vrf, "lsaMinIntervalMsecs", |
d62a17ae | 3245 | ospf->min_ls_interval); |
b1c3ae8c | 3246 | json_object_int_add(json_vrf, "lsaMinArrivalMsecs", |
d62a17ae | 3247 | ospf->min_ls_arrival); |
3248 | /* Show write multiplier values */ | |
b1c3ae8c | 3249 | json_object_int_add(json_vrf, "writeMultiplier", |
d62a17ae | 3250 | ospf->write_oi_count); |
3251 | /* Show refresh parameters. */ | |
b1c3ae8c | 3252 | json_object_int_add(json_vrf, "refreshTimerMsecs", |
d62a17ae | 3253 | ospf->lsa_refresh_interval * 1000); |
f61b005a | 3254 | |
0b177538 | 3255 | /* show max multipath */ |
3256 | json_object_int_add(json_vrf, "maximumPaths", | |
3257 | ospf->max_multipath); | |
3258 | ||
f61b005a | 3259 | /* show administrative distance */ |
3260 | json_object_int_add(json_vrf, "preference", | |
3261 | ospf->distance_all | |
3262 | ? ospf->distance_all | |
3263 | : ZEBRA_OSPF_DISTANCE_DEFAULT); | |
d62a17ae | 3264 | } else { |
3265 | vty_out(vty, " SPF timer %s%s\n", | |
3266 | (ospf->t_spf_calc ? "due in " : "is "), | |
3267 | ospf_timer_dump(ospf->t_spf_calc, timebuf, | |
3268 | sizeof(timebuf))); | |
3269 | ||
3270 | vty_out(vty, " LSA minimum interval %d msecs\n", | |
3271 | ospf->min_ls_interval); | |
3272 | vty_out(vty, " LSA minimum arrival %d msecs\n", | |
3273 | ospf->min_ls_arrival); | |
3274 | ||
3275 | /* Show write multiplier values */ | |
3276 | vty_out(vty, " Write Multiplier set to %d \n", | |
3277 | ospf->write_oi_count); | |
3278 | ||
3279 | /* Show refresh parameters. */ | |
3280 | vty_out(vty, " Refresh timer %d secs\n", | |
3281 | ospf->lsa_refresh_interval); | |
3d5b9855 | 3282 | |
3283 | /* show max multipath */ | |
e9b0752f | 3284 | vty_out(vty, " Maximum multiple paths(ECMP) supported %d\n", |
3d5b9855 | 3285 | ospf->max_multipath); |
f61b005a | 3286 | |
3287 | /* show administrative distance */ | |
3288 | vty_out(vty, " Administrative distance %u\n", | |
3289 | ospf->distance_all ? ospf->distance_all | |
3290 | : ZEBRA_OSPF_DISTANCE_DEFAULT); | |
d62a17ae | 3291 | } |
3292 | ||
3293 | /* Show ABR/ASBR flags. */ | |
3294 | if (CHECK_FLAG(ospf->flags, OSPF_FLAG_ABR)) { | |
b1c3ae8c | 3295 | if (json) |
d62a17ae | 3296 | json_object_string_add( |
b1c3ae8c | 3297 | json_vrf, "abrType", |
d62a17ae | 3298 | ospf_abr_type_descr_str[ospf->abr_type]); |
3299 | else | |
3300 | vty_out(vty, | |
3301 | " This router is an ABR, ABR type is: %s\n", | |
3302 | ospf_abr_type_descr_str[ospf->abr_type]); | |
3303 | } | |
3304 | if (CHECK_FLAG(ospf->flags, OSPF_FLAG_ASBR)) { | |
b1c3ae8c | 3305 | if (json) |
d62a17ae | 3306 | json_object_string_add( |
b1c3ae8c | 3307 | json_vrf, "asbrRouter", |
d62a17ae | 3308 | "injectingExternalRoutingInformation"); |
3309 | else | |
3310 | vty_out(vty, | |
3efd0893 | 3311 | " This router is an ASBR (injecting external routing information)\n"); |
d62a17ae | 3312 | } |
3313 | ||
3314 | /* Show Number of AS-external-LSAs. */ | |
b1c3ae8c | 3315 | if (json) { |
d62a17ae | 3316 | json_object_int_add( |
b1c3ae8c | 3317 | json_vrf, "lsaExternalCounter", |
d62a17ae | 3318 | ospf_lsdb_count(ospf->lsdb, OSPF_AS_EXTERNAL_LSA)); |
3319 | json_object_int_add( | |
b1c3ae8c | 3320 | json_vrf, "lsaExternalChecksum", |
d62a17ae | 3321 | ospf_lsdb_checksum(ospf->lsdb, OSPF_AS_EXTERNAL_LSA)); |
3322 | } else { | |
3323 | vty_out(vty, | |
3324 | " Number of external LSA %ld. Checksum Sum 0x%08x\n", | |
3325 | ospf_lsdb_count(ospf->lsdb, OSPF_AS_EXTERNAL_LSA), | |
3326 | ospf_lsdb_checksum(ospf->lsdb, OSPF_AS_EXTERNAL_LSA)); | |
3327 | } | |
3328 | ||
b1c3ae8c | 3329 | if (json) { |
d62a17ae | 3330 | json_object_int_add( |
b1c3ae8c | 3331 | json_vrf, "lsaAsopaqueCounter", |
d62a17ae | 3332 | ospf_lsdb_count(ospf->lsdb, OSPF_OPAQUE_AS_LSA)); |
3333 | json_object_int_add( | |
b1c3ae8c | 3334 | json_vrf, "lsaAsOpaqueChecksum", |
d62a17ae | 3335 | ospf_lsdb_checksum(ospf->lsdb, OSPF_OPAQUE_AS_LSA)); |
3336 | } else { | |
3337 | vty_out(vty, | |
3338 | " Number of opaque AS LSA %ld. Checksum Sum 0x%08x\n", | |
3339 | ospf_lsdb_count(ospf->lsdb, OSPF_OPAQUE_AS_LSA), | |
3340 | ospf_lsdb_checksum(ospf->lsdb, OSPF_OPAQUE_AS_LSA)); | |
3341 | } | |
3342 | ||
3343 | /* Show number of areas attached. */ | |
b1c3ae8c CS |
3344 | if (json) |
3345 | json_object_int_add(json_vrf, "attachedAreaCounter", | |
d62a17ae | 3346 | listcount(ospf->areas)); |
3347 | else | |
3348 | vty_out(vty, " Number of areas attached to this router: %d\n", | |
3349 | listcount(ospf->areas)); | |
3350 | ||
3351 | if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES)) { | |
3352 | if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL)) { | |
b1c3ae8c | 3353 | if (json) |
d62a17ae | 3354 | json_object_boolean_true_add( |
b1c3ae8c | 3355 | json_vrf, "adjacencyChangesLoggedAll"); |
d62a17ae | 3356 | else |
3357 | vty_out(vty, | |
3358 | " All adjacency changes are logged\n"); | |
3359 | } else { | |
b1c3ae8c | 3360 | if (json) |
d62a17ae | 3361 | json_object_boolean_true_add( |
b1c3ae8c | 3362 | json_vrf, "adjacencyChangesLogged"); |
d62a17ae | 3363 | else |
3364 | vty_out(vty, " Adjacency changes are logged\n"); | |
3365 | } | |
3366 | } | |
132a782e | 3367 | |
3368 | /* show LDP-Sync status */ | |
3369 | ospf_ldp_sync_show_info(vty, ospf, json_vrf, json ? 1 : 0); | |
3370 | ||
d62a17ae | 3371 | /* Show each area status. */ |
3372 | for (ALL_LIST_ELEMENTS(ospf->areas, node, nnode, area)) | |
b1c3ae8c CS |
3373 | show_ip_ospf_area(vty, area, json_areas, json ? 1 : 0); |
3374 | ||
3375 | if (json) { | |
3376 | if (use_vrf) { | |
3377 | json_object_object_add(json_vrf, "areas", json_areas); | |
44076f4d RW |
3378 | json_object_object_add(json, ospf_get_name(ospf), |
3379 | json_vrf); | |
b1c3ae8c CS |
3380 | } else { |
3381 | json_object_object_add(json, "areas", json_areas); | |
3382 | } | |
d62a17ae | 3383 | } else |
3384 | vty_out(vty, "\n"); | |
3385 | ||
3386 | return CMD_SUCCESS; | |
718e3744 | 3387 | } |
3388 | ||
7c8ff89e DS |
3389 | DEFUN (show_ip_ospf, |
3390 | show_ip_ospf_cmd, | |
b5a8894d | 3391 | "show ip ospf [vrf <NAME|all>] [json]", |
7c8ff89e DS |
3392 | SHOW_STR |
3393 | IP_STR | |
ca08c43d | 3394 | "OSPF information\n" |
b5a8894d CS |
3395 | VRF_CMD_HELP_STR |
3396 | "All VRFs\n" | |
9973d184 | 3397 | JSON_STR) |
7c8ff89e | 3398 | { |
d62a17ae | 3399 | struct ospf *ospf; |
9f049418 | 3400 | bool uj = use_json(argc, argv); |
b5a8894d CS |
3401 | struct listnode *node = NULL; |
3402 | char *vrf_name = NULL; | |
2951a7a4 | 3403 | bool all_vrf = false; |
b5a8894d CS |
3404 | int ret = CMD_SUCCESS; |
3405 | int inst = 0; | |
3406 | int idx_vrf = 0; | |
b1c3ae8c | 3407 | json_object *json = NULL; |
d7c0a89a | 3408 | uint8_t use_vrf = 0; |
7c8ff89e | 3409 | |
b5a8894d | 3410 | if (listcount(om->ospf) == 0) |
d62a17ae | 3411 | return CMD_SUCCESS; |
7c8ff89e | 3412 | |
43b8d1d8 | 3413 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
b5a8894d | 3414 | |
b1c3ae8c CS |
3415 | if (uj) |
3416 | json = json_object_new_object(); | |
3417 | ||
996c9314 | 3418 | /* vrf input is provided could be all or specific vrf*/ |
b5a8894d | 3419 | if (vrf_name) { |
2951a7a4 | 3420 | bool ospf_output = false; |
874f58d8 | 3421 | |
b1c3ae8c | 3422 | use_vrf = 1; |
94d4c685 | 3423 | |
b5a8894d CS |
3424 | if (all_vrf) { |
3425 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
3426 | if (!ospf->oi_running) | |
3427 | continue; | |
2951a7a4 | 3428 | ospf_output = true; |
b1c3ae8c CS |
3429 | ret = show_ip_ospf_common(vty, ospf, json, |
3430 | use_vrf); | |
3431 | } | |
c48349e3 | 3432 | if (uj) |
92ef0078 | 3433 | vty_json(vty, json); |
c48349e3 | 3434 | else if (!ospf_output) |
fbaafa00 | 3435 | vty_out(vty, "%% OSPF is not enabled\n"); |
b5a8894d CS |
3436 | return ret; |
3437 | } | |
3438 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
b1c3ae8c | 3439 | if ((ospf == NULL) || !ospf->oi_running) { |
c48349e3 | 3440 | if (uj) |
92ef0078 | 3441 | vty_json(vty, json); |
c48349e3 | 3442 | else |
fbaafa00 JAG |
3443 | vty_out(vty, |
3444 | "%% OSPF is not enabled in vrf %s\n", | |
3445 | vrf_name); | |
9f049418 | 3446 | |
b5a8894d | 3447 | return CMD_SUCCESS; |
b1c3ae8c | 3448 | } |
b5a8894d CS |
3449 | } else { |
3450 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
3451 | /* Display default ospf (instance 0) info */ | |
b1c3ae8c | 3452 | if (ospf == NULL || !ospf->oi_running) { |
c48349e3 | 3453 | if (uj) |
92ef0078 | 3454 | vty_json(vty, json); |
c48349e3 | 3455 | else |
fbaafa00 JAG |
3456 | vty_out(vty, |
3457 | "%% OSPF is not enabled in vrf default\n"); | |
9f049418 | 3458 | |
b5a8894d | 3459 | return CMD_SUCCESS; |
b1c3ae8c | 3460 | } |
b5a8894d CS |
3461 | } |
3462 | ||
996c9314 | 3463 | if (ospf) { |
b1c3ae8c CS |
3464 | show_ip_ospf_common(vty, ospf, json, use_vrf); |
3465 | if (uj) | |
996c9314 LB |
3466 | vty_out(vty, "%s\n", |
3467 | json_object_to_json_string_ext( | |
3468 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c CS |
3469 | } |
3470 | ||
3471 | if (uj) | |
3472 | json_object_free(json); | |
b5a8894d CS |
3473 | |
3474 | return ret; | |
7c8ff89e DS |
3475 | } |
3476 | ||
3477 | DEFUN (show_ip_ospf_instance, | |
3478 | show_ip_ospf_instance_cmd, | |
6147e2c6 | 3479 | "show ip ospf (1-65535) [json]", |
7c8ff89e DS |
3480 | SHOW_STR |
3481 | IP_STR | |
3482 | "OSPF information\n" | |
ca08c43d | 3483 | "Instance ID\n" |
9973d184 | 3484 | JSON_STR) |
7c8ff89e | 3485 | { |
d62a17ae | 3486 | int idx_number = 3; |
3487 | struct ospf *ospf; | |
d7c0a89a | 3488 | unsigned short instance = 0; |
9f049418 | 3489 | bool uj = use_json(argc, argv); |
b1c3ae8c CS |
3490 | int ret = CMD_SUCCESS; |
3491 | json_object *json = NULL; | |
d62a17ae | 3492 | |
3493 | instance = strtoul(argv[idx_number]->arg, NULL, 10); | |
409f98ab | 3494 | if (instance != ospf_instance) |
ac28e4ec CS |
3495 | return CMD_NOT_MY_INSTANCE; |
3496 | ||
409f98ab IR |
3497 | ospf = ospf_lookup_instance(instance); |
3498 | if (!ospf || !ospf->oi_running) | |
d62a17ae | 3499 | return CMD_SUCCESS; |
3500 | ||
b1c3ae8c CS |
3501 | if (uj) |
3502 | json = json_object_new_object(); | |
3503 | ||
3504 | ret = show_ip_ospf_common(vty, ospf, json, 0); | |
3505 | ||
c48349e3 | 3506 | if (uj) |
92ef0078 | 3507 | vty_json(vty, json); |
b1c3ae8c CS |
3508 | |
3509 | return ret; | |
d62a17ae | 3510 | } |
3511 | ||
49498934 | 3512 | static void ospf_interface_auth_show(struct vty *vty, struct ospf_interface *oi, |
3513 | json_object *json, bool use_json) | |
3514 | { | |
3515 | int auth_type; | |
3516 | ||
3517 | auth_type = OSPF_IF_PARAM(oi, auth_type); | |
3518 | ||
3519 | switch (auth_type) { | |
3520 | case OSPF_AUTH_NULL: | |
3521 | if (use_json) | |
3522 | json_object_string_add(json, "authentication", | |
3523 | "authenticationNone"); | |
3524 | else | |
3525 | vty_out(vty, " Authentication NULL is enabled\n"); | |
3526 | break; | |
3527 | case OSPF_AUTH_SIMPLE: { | |
3528 | if (use_json) | |
3529 | json_object_string_add(json, "authentication", | |
3530 | "authenticationSimplePassword"); | |
3531 | else | |
3532 | vty_out(vty, | |
3533 | " Simple password authentication enabled\n"); | |
3534 | break; | |
3535 | } | |
3536 | case OSPF_AUTH_CRYPTOGRAPHIC: { | |
3537 | struct crypt_key *ckey; | |
3538 | ||
3539 | if (list_isempty(OSPF_IF_PARAM(oi, auth_crypt))) | |
3540 | return; | |
3541 | ||
3542 | ckey = listgetdata(listtail(OSPF_IF_PARAM(oi, auth_crypt))); | |
3543 | if (ckey) { | |
3544 | if (use_json) { | |
3545 | json_object_string_add(json, "authentication", | |
3546 | "authenticationMessageDigest"); | |
3547 | } else { | |
3548 | vty_out(vty, | |
3549 | " Cryptographic authentication enabled\n"); | |
3550 | vty_out(vty, " Algorithm:MD5\n"); | |
3551 | } | |
3552 | } | |
3553 | break; | |
3554 | } | |
3555 | default: | |
3556 | break; | |
3557 | } | |
3558 | } | |
3559 | ||
d62a17ae | 3560 | static void show_ip_ospf_interface_sub(struct vty *vty, struct ospf *ospf, |
3561 | struct interface *ifp, | |
3562 | json_object *json_interface_sub, | |
9f049418 | 3563 | bool use_json) |
d62a17ae | 3564 | { |
3565 | int is_up; | |
3566 | struct ospf_neighbor *nbr; | |
3567 | struct route_node *rn; | |
3568 | uint32_t bandwidth = ifp->bandwidth ? ifp->bandwidth : ifp->speed; | |
3569 | ||
3570 | /* Is interface up? */ | |
3571 | if (use_json) { | |
3572 | is_up = if_is_operative(ifp); | |
3573 | if (is_up) | |
3574 | json_object_boolean_true_add(json_interface_sub, | |
3575 | "ifUp"); | |
3576 | else | |
3577 | json_object_boolean_false_add(json_interface_sub, | |
3578 | "ifDown"); | |
3579 | ||
3580 | json_object_int_add(json_interface_sub, "ifIndex", | |
3581 | ifp->ifindex); | |
3582 | json_object_int_add(json_interface_sub, "mtuBytes", ifp->mtu); | |
3583 | json_object_int_add(json_interface_sub, "bandwidthMbit", | |
3584 | bandwidth); | |
3585 | json_object_string_add(json_interface_sub, "ifFlags", | |
3586 | if_flag_dump(ifp->flags)); | |
3587 | } else { | |
3588 | vty_out(vty, "%s is %s\n", ifp->name, | |
3589 | ((is_up = if_is_operative(ifp)) ? "up" : "down")); | |
3590 | vty_out(vty, " ifindex %u, MTU %u bytes, BW %u Mbit %s\n", | |
3591 | ifp->ifindex, ifp->mtu, bandwidth, | |
3592 | if_flag_dump(ifp->flags)); | |
3593 | } | |
7c8ff89e | 3594 | |
d62a17ae | 3595 | /* Is interface OSPF enabled? */ |
3596 | if (use_json) { | |
3597 | if (ospf_oi_count(ifp) == 0) { | |
3598 | json_object_boolean_false_add(json_interface_sub, | |
3599 | "ospfEnabled"); | |
3600 | return; | |
3601 | } else if (!is_up) { | |
3602 | json_object_boolean_false_add(json_interface_sub, | |
3603 | "ospfRunning"); | |
3604 | return; | |
3605 | } else | |
3606 | json_object_boolean_true_add(json_interface_sub, | |
3607 | "ospfEnabled"); | |
3608 | } else { | |
3609 | if (ospf_oi_count(ifp) == 0) { | |
3610 | vty_out(vty, " OSPF not enabled on this interface\n"); | |
3611 | return; | |
3612 | } else if (!is_up) { | |
3613 | vty_out(vty, | |
3614 | " OSPF is enabled, but not running on this interface\n"); | |
3615 | return; | |
3616 | } | |
3617 | } | |
3618 | ||
3619 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { | |
3620 | struct ospf_interface *oi = rn->info; | |
3621 | ||
3622 | if (oi == NULL) | |
3623 | continue; | |
3624 | ||
3625 | if (CHECK_FLAG(oi->connected->flags, ZEBRA_IFA_UNNUMBERED)) { | |
3626 | if (use_json) | |
3627 | json_object_boolean_true_add(json_interface_sub, | |
3628 | "ifUnnumbered"); | |
3629 | else | |
3630 | vty_out(vty, " This interface is UNNUMBERED,"); | |
3631 | } else { | |
0f3af738 JW |
3632 | struct in_addr dest; |
3633 | const char *dstr; | |
3634 | ||
d62a17ae | 3635 | /* Show OSPF interface information. */ |
3636 | if (use_json) { | |
20308be3 DA |
3637 | json_object_string_addf( |
3638 | json_interface_sub, "ipAddress", "%pI4", | |
3639 | &oi->address->u.prefix4); | |
d62a17ae | 3640 | json_object_int_add(json_interface_sub, |
3641 | "ipAddressPrefixlen", | |
3642 | oi->address->prefixlen); | |
3643 | } else | |
ae32e1c2 DS |
3644 | vty_out(vty, " Internet Address %pFX,", |
3645 | oi->address); | |
d62a17ae | 3646 | |
0f3af738 JW |
3647 | /* For Vlinks, showing the peer address is |
3648 | * probably more informative than the local | |
3649 | * interface that is being used */ | |
3650 | if (oi->type == OSPF_IFTYPE_VIRTUALLINK) { | |
3651 | dstr = "Peer"; | |
3652 | dest = oi->vl_data->peer_addr; | |
3653 | } else if (CONNECTED_PEER(oi->connected) | |
3654 | && oi->connected->destination) { | |
3655 | dstr = "Peer"; | |
3656 | dest = oi->connected->destination->u.prefix4; | |
3657 | } else { | |
3658 | dstr = "Broadcast"; | |
3659 | dest.s_addr = ipv4_broadcast_addr( | |
3660 | oi->connected->address->u.prefix4.s_addr, | |
3661 | oi->connected->address->prefixlen); | |
3662 | } | |
d62a17ae | 3663 | |
0f3af738 JW |
3664 | if (use_json) { |
3665 | json_object_string_add( | |
3666 | json_interface_sub, | |
3667 | "ospfIfType", dstr); | |
d62a17ae | 3668 | if (oi->type == OSPF_IFTYPE_VIRTUALLINK) |
20308be3 DA |
3669 | json_object_string_addf( |
3670 | json_interface_sub, "vlinkPeer", | |
3671 | "%pI4", &dest); | |
d62a17ae | 3672 | else |
20308be3 | 3673 | json_object_string_addf( |
d62a17ae | 3674 | json_interface_sub, |
20308be3 | 3675 | "localIfUsed", "%pI4", &dest); |
0f3af738 | 3676 | } else |
96b663a3 MS |
3677 | vty_out(vty, " %s %pI4,", dstr, |
3678 | &dest); | |
d62a17ae | 3679 | } |
3680 | if (use_json) { | |
3681 | json_object_string_add(json_interface_sub, "area", | |
3682 | ospf_area_desc_string(oi->area)); | |
3683 | if (OSPF_IF_PARAM(oi, mtu_ignore)) | |
3684 | json_object_boolean_true_add( | |
3685 | json_interface_sub, | |
3686 | "mtuMismatchDetect"); | |
20308be3 DA |
3687 | json_object_string_addf(json_interface_sub, "routerId", |
3688 | "%pI4", &ospf->router_id); | |
d62a17ae | 3689 | json_object_string_add(json_interface_sub, |
3690 | "networkType", | |
3691 | ospf_network_type_str[oi->type]); | |
3692 | json_object_int_add(json_interface_sub, "cost", | |
3693 | oi->output_cost); | |
3694 | json_object_int_add( | |
50ad4b42 MS |
3695 | json_interface_sub, "transmitDelaySecs", |
3696 | OSPF_IF_PARAM(oi, transmit_delay)); | |
d62a17ae | 3697 | json_object_string_add(json_interface_sub, "state", |
3698 | lookup_msg(ospf_ism_state_msg, | |
3699 | oi->state, NULL)); | |
3700 | json_object_int_add(json_interface_sub, "priority", | |
3701 | PRIORITY(oi)); | |
3702 | } else { | |
3703 | vty_out(vty, " Area %s\n", | |
3704 | ospf_area_desc_string(oi->area)); | |
3705 | ||
3706 | vty_out(vty, " MTU mismatch detection: %s\n", | |
3707 | OSPF_IF_PARAM(oi, mtu_ignore) ? "disabled" | |
3708 | : "enabled"); | |
3709 | ||
3710 | vty_out(vty, | |
96b663a3 MS |
3711 | " Router ID %pI4, Network Type %s, Cost: %d\n", |
3712 | &ospf->router_id, | |
d62a17ae | 3713 | ospf_network_type_str[oi->type], |
3714 | oi->output_cost); | |
3715 | ||
3716 | vty_out(vty, | |
3717 | " Transmit Delay is %d sec, State %s, Priority %d\n", | |
3718 | OSPF_IF_PARAM(oi, transmit_delay), | |
3719 | lookup_msg(ospf_ism_state_msg, oi->state, NULL), | |
3720 | PRIORITY(oi)); | |
3721 | } | |
3722 | ||
3723 | /* Show DR information. */ | |
975a328e | 3724 | if (DR(oi).s_addr == INADDR_ANY) { |
d62a17ae | 3725 | if (!use_json) |
3726 | vty_out(vty, | |
3727 | " No backup designated router on this network\n"); | |
3728 | } else { | |
2fbb8f45 | 3729 | nbr = ospf_nbr_lookup_by_addr(oi->nbrs, &DR(oi)); |
3730 | if (nbr) { | |
3731 | if (use_json) { | |
20308be3 | 3732 | json_object_string_addf( |
2fbb8f45 | 3733 | json_interface_sub, "drId", |
20308be3 DA |
3734 | "%pI4", &nbr->router_id); |
3735 | json_object_string_addf( | |
2fbb8f45 | 3736 | json_interface_sub, "drAddress", |
20308be3 DA |
3737 | "%pI4", |
3738 | &nbr->address.u.prefix4); | |
2fbb8f45 | 3739 | } else { |
3740 | vty_out(vty, | |
3741 | " Designated Router (ID) %pI4", | |
3742 | &nbr->router_id); | |
3743 | vty_out(vty, | |
3744 | " Interface Address %pFX\n", | |
3745 | &nbr->address); | |
3746 | } | |
3747 | } | |
3748 | nbr = NULL; | |
3749 | ||
d62a17ae | 3750 | nbr = ospf_nbr_lookup_by_addr(oi->nbrs, &BDR(oi)); |
3751 | if (nbr == NULL) { | |
3752 | if (!use_json) | |
3753 | vty_out(vty, | |
3754 | " No backup designated router on this network\n"); | |
3755 | } else { | |
3756 | if (use_json) { | |
20308be3 | 3757 | json_object_string_addf( |
d62a17ae | 3758 | json_interface_sub, "bdrId", |
20308be3 DA |
3759 | "%pI4", &nbr->router_id); |
3760 | json_object_string_addf( | |
d62a17ae | 3761 | json_interface_sub, |
20308be3 DA |
3762 | "bdrAddress", "%pI4", |
3763 | &nbr->address.u.prefix4); | |
d62a17ae | 3764 | } else { |
3765 | vty_out(vty, | |
96b663a3 MS |
3766 | " Backup Designated Router (ID) %pI4,", |
3767 | &nbr->router_id); | |
3768 | vty_out(vty, " Interface Address %pI4\n", | |
3769 | &nbr->address.u.prefix4); | |
d62a17ae | 3770 | } |
3771 | } | |
3772 | } | |
3773 | ||
3774 | /* Next network-LSA sequence number we'll use, if we're elected | |
3775 | * DR */ | |
3776 | if (oi->params | |
3777 | && ntohl(oi->params->network_lsa_seqnum) | |
3778 | != OSPF_INITIAL_SEQUENCE_NUMBER) { | |
3779 | if (use_json) | |
3780 | json_object_int_add( | |
3781 | json_interface_sub, | |
3782 | "networkLsaSequence", | |
3783 | ntohl(oi->params->network_lsa_seqnum)); | |
3784 | else | |
3785 | vty_out(vty, | |
3786 | " Saved Network-LSA sequence number 0x%x\n", | |
3787 | ntohl(oi->params->network_lsa_seqnum)); | |
3788 | } | |
3789 | ||
3790 | if (use_json) { | |
3791 | if (OI_MEMBER_CHECK(oi, MEMBER_ALLROUTERS) | |
3792 | || OI_MEMBER_CHECK(oi, MEMBER_DROUTERS)) { | |
3793 | if (OI_MEMBER_CHECK(oi, MEMBER_ALLROUTERS)) | |
3794 | json_object_boolean_true_add( | |
3795 | json_interface_sub, | |
3796 | "mcastMemberOspfAllRouters"); | |
3797 | if (OI_MEMBER_CHECK(oi, MEMBER_DROUTERS)) | |
3798 | json_object_boolean_true_add( | |
3799 | json_interface_sub, | |
3800 | "mcastMemberOspfDesignatedRouters"); | |
3801 | } | |
3802 | } else { | |
3803 | vty_out(vty, " Multicast group memberships:"); | |
3804 | if (OI_MEMBER_CHECK(oi, MEMBER_ALLROUTERS) | |
3805 | || OI_MEMBER_CHECK(oi, MEMBER_DROUTERS)) { | |
3806 | if (OI_MEMBER_CHECK(oi, MEMBER_ALLROUTERS)) | |
3807 | vty_out(vty, " OSPFAllRouters"); | |
3808 | if (OI_MEMBER_CHECK(oi, MEMBER_DROUTERS)) | |
3809 | vty_out(vty, " OSPFDesignatedRouters"); | |
3810 | } else | |
3811 | vty_out(vty, " <None>"); | |
3812 | vty_out(vty, "\n"); | |
3813 | } | |
3814 | ||
3815 | if (use_json) { | |
3816 | if (OSPF_IF_PARAM(oi, fast_hello) == 0) | |
3817 | json_object_int_add( | |
3818 | json_interface_sub, "timerMsecs", | |
50ad4b42 | 3819 | OSPF_IF_PARAM(oi, v_hello) * 1000); |
d62a17ae | 3820 | else |
3821 | json_object_int_add( | |
3822 | json_interface_sub, "timerMsecs", | |
50ad4b42 | 3823 | 1000 / OSPF_IF_PARAM(oi, fast_hello)); |
d62a17ae | 3824 | json_object_int_add(json_interface_sub, |
50ad4b42 MS |
3825 | "timerDeadSecs", |
3826 | OSPF_IF_PARAM(oi, v_wait)); | |
d62a17ae | 3827 | json_object_int_add(json_interface_sub, |
50ad4b42 MS |
3828 | "timerWaitSecs", |
3829 | OSPF_IF_PARAM(oi, v_wait)); | |
d62a17ae | 3830 | json_object_int_add( |
50ad4b42 MS |
3831 | json_interface_sub, "timerRetransmitSecs", |
3832 | OSPF_IF_PARAM(oi, retransmit_interval)); | |
d62a17ae | 3833 | } else { |
3834 | vty_out(vty, " Timer intervals configured,"); | |
3835 | vty_out(vty, " Hello "); | |
3836 | if (OSPF_IF_PARAM(oi, fast_hello) == 0) | |
3837 | vty_out(vty, "%ds,", | |
3838 | OSPF_IF_PARAM(oi, v_hello)); | |
3839 | else | |
3840 | vty_out(vty, "%dms,", | |
3841 | 1000 / OSPF_IF_PARAM(oi, fast_hello)); | |
3842 | vty_out(vty, " Dead %ds, Wait %ds, Retransmit %d\n", | |
3843 | OSPF_IF_PARAM(oi, v_wait), | |
3844 | OSPF_IF_PARAM(oi, v_wait), | |
3845 | OSPF_IF_PARAM(oi, retransmit_interval)); | |
3846 | } | |
3847 | ||
3848 | if (OSPF_IF_PASSIVE_STATUS(oi) == OSPF_IF_ACTIVE) { | |
3849 | char timebuf[OSPF_TIME_DUMP_SIZE]; | |
3850 | if (use_json) { | |
3851 | long time_store = 0; | |
3852 | if (oi->t_hello) | |
3853 | time_store = | |
3854 | monotime_until( | |
3855 | &oi->t_hello->u.sands, | |
3856 | NULL) | |
3857 | / 1000LL; | |
3858 | json_object_int_add(json_interface_sub, | |
3859 | "timerHelloInMsecs", | |
3860 | time_store); | |
3861 | } else | |
3862 | vty_out(vty, " Hello due in %s\n", | |
3863 | ospf_timer_dump(oi->t_hello, timebuf, | |
3864 | sizeof(timebuf))); | |
3865 | } else /* passive-interface is set */ | |
3866 | { | |
3867 | if (use_json) | |
3868 | json_object_boolean_true_add( | |
3869 | json_interface_sub, | |
3870 | "timerPassiveIface"); | |
3871 | else | |
3872 | vty_out(vty, | |
3873 | " No Hellos (Passive interface)\n"); | |
3874 | } | |
7c8ff89e | 3875 | |
d62a17ae | 3876 | if (use_json) { |
3877 | json_object_int_add(json_interface_sub, "nbrCount", | |
3878 | ospf_nbr_count(oi, 0)); | |
3879 | json_object_int_add(json_interface_sub, | |
3880 | "nbrAdjacentCount", | |
3881 | ospf_nbr_count(oi, NSM_Full)); | |
3882 | } else | |
3883 | vty_out(vty, | |
3884 | " Neighbor Count is %d, Adjacent neighbor count is %d\n", | |
3885 | ospf_nbr_count(oi, 0), | |
3886 | ospf_nbr_count(oi, NSM_Full)); | |
659f4e40 RZ |
3887 | |
3888 | ospf_interface_bfd_show(vty, ifp, json_interface_sub); | |
49498934 | 3889 | |
3890 | /* OSPF Authentication information */ | |
3891 | ospf_interface_auth_show(vty, oi, json_interface_sub, use_json); | |
d62a17ae | 3892 | } |
718e3744 | 3893 | } |
3894 | ||
d62a17ae | 3895 | static int show_ip_ospf_interface_common(struct vty *vty, struct ospf *ospf, |
d7c0a89a | 3896 | char *intf_name, uint8_t use_vrf, |
9f049418 | 3897 | json_object *json, bool use_json) |
d62a17ae | 3898 | { |
3899 | struct interface *ifp; | |
f4e14fdb | 3900 | struct vrf *vrf = vrf_lookup_by_id(ospf->vrf_id); |
6282e124 | 3901 | json_object *json_vrf = NULL; |
7dab10ce | 3902 | json_object *json_interface_sub = NULL, *json_interface = NULL; |
7c8ff89e | 3903 | |
d62a17ae | 3904 | if (use_json) { |
b1c3ae8c CS |
3905 | if (use_vrf) |
3906 | json_vrf = json_object_new_object(); | |
3907 | else | |
3908 | json_vrf = json; | |
6282e124 | 3909 | json_interface = json_object_new_object(); |
d62a17ae | 3910 | } |
3911 | ||
3912 | if (ospf->instance) { | |
3913 | if (use_json) | |
3914 | json_object_int_add(json, "ospfInstance", | |
3915 | ospf->instance); | |
3916 | else | |
3917 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
3918 | } | |
3919 | ||
b1c3ae8c CS |
3920 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); |
3921 | ||
3922 | if (intf_name == NULL) { | |
d62a17ae | 3923 | /* Show All Interfaces.*/ |
451fda4f | 3924 | FOR_ALL_INTERFACES (vrf, ifp) { |
d62a17ae | 3925 | if (ospf_oi_count(ifp)) { |
7dab10ce | 3926 | if (use_json) { |
d62a17ae | 3927 | json_interface_sub = |
3928 | json_object_new_object(); | |
7dab10ce | 3929 | } |
d62a17ae | 3930 | show_ip_ospf_interface_sub(vty, ospf, ifp, |
3931 | json_interface_sub, | |
3932 | use_json); | |
3933 | ||
7dab10ce | 3934 | if (use_json) { |
d62a17ae | 3935 | json_object_object_add( |
7dab10ce | 3936 | json_interface, ifp->name, |
d62a17ae | 3937 | json_interface_sub); |
7dab10ce | 3938 | } |
d62a17ae | 3939 | } |
3940 | } | |
6282e124 CS |
3941 | if (use_json) |
3942 | json_object_object_add(json_vrf, "interfaces", | |
996c9314 | 3943 | json_interface); |
d62a17ae | 3944 | } else { |
3945 | /* Interface name is specified. */ | |
a36898e7 | 3946 | ifp = if_lookup_by_name(intf_name, ospf->vrf_id); |
b1c3ae8c | 3947 | if (ifp == NULL) { |
d62a17ae | 3948 | if (use_json) |
b1c3ae8c | 3949 | json_object_boolean_true_add(json_vrf, |
d62a17ae | 3950 | "noSuchIface"); |
3951 | else | |
3952 | vty_out(vty, "No such interface name\n"); | |
3953 | } else { | |
7dab10ce | 3954 | if (use_json) { |
d62a17ae | 3955 | json_interface_sub = json_object_new_object(); |
7dab10ce | 3956 | json_interface = json_object_new_object(); |
7dab10ce | 3957 | } |
d62a17ae | 3958 | |
3959 | show_ip_ospf_interface_sub( | |
3960 | vty, ospf, ifp, json_interface_sub, use_json); | |
3961 | ||
7dab10ce | 3962 | if (use_json) { |
7dab10ce CS |
3963 | json_object_object_add(json_interface, |
3964 | ifp->name, | |
d62a17ae | 3965 | json_interface_sub); |
6282e124 CS |
3966 | json_object_object_add(json_vrf, "interfaces", |
3967 | json_interface); | |
7dab10ce | 3968 | } |
d62a17ae | 3969 | } |
3970 | } | |
3971 | ||
3972 | if (use_json) { | |
b1c3ae8c | 3973 | if (use_vrf) { |
44076f4d RW |
3974 | json_object_object_add(json, ospf_get_name(ospf), |
3975 | json_vrf); | |
b1c3ae8c | 3976 | } |
d62a17ae | 3977 | } else |
3978 | vty_out(vty, "\n"); | |
3979 | ||
3980 | return CMD_SUCCESS; | |
718e3744 | 3981 | } |
3982 | ||
c9339663 CS |
3983 | static void show_ip_ospf_interface_traffic_sub(struct vty *vty, |
3984 | struct ospf_interface *oi, | |
3985 | json_object *json_interface_sub, | |
9f049418 | 3986 | bool use_json) |
c9339663 CS |
3987 | { |
3988 | if (use_json) { | |
996c9314 LB |
3989 | json_object_int_add(json_interface_sub, "ifIndex", |
3990 | oi->ifp->ifindex); | |
3991 | json_object_int_add(json_interface_sub, "helloIn", | |
3992 | oi->hello_in); | |
3993 | json_object_int_add(json_interface_sub, "helloOut", | |
3994 | oi->hello_out); | |
3995 | json_object_int_add(json_interface_sub, "dbDescIn", | |
3996 | oi->db_desc_in); | |
3997 | json_object_int_add(json_interface_sub, "dbDescOut", | |
3998 | oi->db_desc_out); | |
3999 | json_object_int_add(json_interface_sub, "lsReqIn", | |
4000 | oi->ls_req_in); | |
4001 | json_object_int_add(json_interface_sub, "lsReqOut", | |
4002 | oi->ls_req_out); | |
4003 | json_object_int_add(json_interface_sub, "lsUpdIn", | |
4004 | oi->ls_upd_in); | |
4005 | json_object_int_add(json_interface_sub, "lsUpdOut", | |
4006 | oi->ls_upd_out); | |
4007 | json_object_int_add(json_interface_sub, "lsAckIn", | |
4008 | oi->ls_ack_in); | |
4009 | json_object_int_add(json_interface_sub, "lsAckOut", | |
4010 | oi->ls_ack_out); | |
c9339663 CS |
4011 | } else { |
4012 | vty_out(vty, | |
4013 | "%-10s %8u/%-8u %7u/%-7u %7u/%-7u %7u/%-7u %7u/%-7u\n", | |
996c9314 LB |
4014 | oi->ifp->name, oi->hello_in, oi->hello_out, |
4015 | oi->db_desc_in, oi->db_desc_out, oi->ls_req_in, | |
4016 | oi->ls_req_out, oi->ls_upd_in, oi->ls_upd_out, | |
c9339663 CS |
4017 | oi->ls_ack_in, oi->ls_ack_out); |
4018 | } | |
4019 | } | |
4020 | ||
4021 | /* OSPFv2 Packet Counters */ | |
996c9314 LB |
4022 | static int show_ip_ospf_interface_traffic_common( |
4023 | struct vty *vty, struct ospf *ospf, char *intf_name, json_object *json, | |
9f049418 | 4024 | int display_once, uint8_t use_vrf, bool use_json) |
c9339663 CS |
4025 | { |
4026 | struct vrf *vrf = NULL; | |
4027 | struct interface *ifp = NULL; | |
b1c3ae8c | 4028 | json_object *json_vrf = NULL; |
c9339663 CS |
4029 | json_object *json_interface_sub = NULL; |
4030 | ||
4031 | if (!use_json && !display_once) { | |
4032 | vty_out(vty, "\n"); | |
996c9314 LB |
4033 | vty_out(vty, "%-12s%-17s%-17s%-17s%-17s%-17s\n", "Interface", |
4034 | " HELLO", " DB-Desc", " LS-Req", " LS-Update", | |
4035 | " LS-Ack"); | |
c9339663 | 4036 | vty_out(vty, "%-10s%-18s%-18s%-17s%-17s%-17s\n", "", |
996c9314 LB |
4037 | " Rx/Tx", " Rx/Tx", " Rx/Tx", " Rx/Tx", |
4038 | " Rx/Tx"); | |
c9339663 | 4039 | vty_out(vty, |
996c9314 | 4040 | "--------------------------------------------------------------------------------------------\n"); |
c9339663 | 4041 | } else if (use_json) { |
b1c3ae8c CS |
4042 | if (use_vrf) |
4043 | json_vrf = json_object_new_object(); | |
4044 | else | |
4045 | json_vrf = json; | |
c9339663 CS |
4046 | } |
4047 | ||
b1c3ae8c CS |
4048 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); |
4049 | ||
c9339663 CS |
4050 | if (intf_name == NULL) { |
4051 | vrf = vrf_lookup_by_id(ospf->vrf_id); | |
4052 | FOR_ALL_INTERFACES (vrf, ifp) { | |
4053 | struct route_node *rn; | |
4054 | struct ospf_interface *oi; | |
4055 | ||
4056 | if (ospf_oi_count(ifp) == 0) | |
4057 | continue; | |
4058 | ||
4059 | for (rn = route_top(IF_OIFS(ifp)); rn; | |
996c9314 | 4060 | rn = route_next(rn)) { |
c9339663 CS |
4061 | oi = rn->info; |
4062 | ||
4063 | if (oi == NULL) | |
4064 | continue; | |
4065 | ||
4066 | if (use_json) { | |
4067 | json_interface_sub = | |
4068 | json_object_new_object(); | |
4069 | } | |
4070 | ||
996c9314 LB |
4071 | show_ip_ospf_interface_traffic_sub( |
4072 | vty, oi, json_interface_sub, use_json); | |
c9339663 | 4073 | if (use_json) { |
996c9314 LB |
4074 | json_object_object_add( |
4075 | json_vrf, ifp->name, | |
4076 | json_interface_sub); | |
c9339663 CS |
4077 | } |
4078 | } | |
4079 | } | |
4080 | } else { | |
4081 | /* Interface name is specified. */ | |
a36898e7 | 4082 | ifp = if_lookup_by_name(intf_name, ospf->vrf_id); |
c9339663 CS |
4083 | if (ifp != NULL) { |
4084 | struct route_node *rn; | |
4085 | struct ospf_interface *oi; | |
4086 | ||
4087 | if (ospf_oi_count(ifp) == 0) { | |
996c9314 LB |
4088 | vty_out(vty, |
4089 | " OSPF not enabled on this interface %s\n", | |
c9339663 CS |
4090 | ifp->name); |
4091 | return CMD_SUCCESS; | |
4092 | } | |
4093 | ||
4094 | for (rn = route_top(IF_OIFS(ifp)); rn; | |
4095 | rn = route_next(rn)) { | |
4096 | oi = rn->info; | |
4097 | ||
4098 | if (use_json) { | |
4099 | json_interface_sub = | |
4100 | json_object_new_object(); | |
4101 | } | |
4102 | ||
996c9314 LB |
4103 | show_ip_ospf_interface_traffic_sub( |
4104 | vty, oi, json_interface_sub, use_json); | |
c9339663 | 4105 | if (use_json) { |
996c9314 LB |
4106 | json_object_object_add( |
4107 | json_vrf, ifp->name, | |
4108 | json_interface_sub); | |
c9339663 CS |
4109 | } |
4110 | } | |
4111 | } | |
4112 | } | |
4113 | ||
4114 | if (use_json) { | |
44076f4d RW |
4115 | if (use_vrf) |
4116 | json_object_object_add(json, ospf_get_name(ospf), | |
4117 | json_vrf); | |
b1c3ae8c CS |
4118 | } else |
4119 | vty_out(vty, "\n"); | |
c9339663 CS |
4120 | |
4121 | return CMD_SUCCESS; | |
4122 | } | |
4123 | ||
7c8ff89e DS |
4124 | DEFUN (show_ip_ospf_interface, |
4125 | show_ip_ospf_interface_cmd, | |
43b8d1d8 | 4126 | "show ip ospf [vrf <NAME|all>] interface [INTERFACE] [json]", |
7c8ff89e DS |
4127 | SHOW_STR |
4128 | IP_STR | |
4129 | "OSPF information\n" | |
b5a8894d | 4130 | VRF_CMD_HELP_STR |
43b8d1d8 | 4131 | "All VRFs\n" |
7c8ff89e | 4132 | "Interface information\n" |
7ec4159b | 4133 | "Interface name\n" |
9973d184 | 4134 | JSON_STR) |
7c8ff89e | 4135 | { |
d62a17ae | 4136 | struct ospf *ospf; |
9f049418 | 4137 | bool uj = use_json(argc, argv); |
b5a8894d | 4138 | struct listnode *node = NULL; |
b1c3ae8c | 4139 | char *vrf_name = NULL, *intf_name = NULL; |
2951a7a4 | 4140 | bool all_vrf = false; |
b5a8894d CS |
4141 | int ret = CMD_SUCCESS; |
4142 | int inst = 0; | |
b1c3ae8c | 4143 | int idx_vrf = 0, idx_intf = 0; |
d7c0a89a | 4144 | uint8_t use_vrf = 0; |
b1c3ae8c | 4145 | json_object *json = NULL; |
7c8ff89e | 4146 | |
43b8d1d8 CS |
4147 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
4148 | ||
b1c3ae8c CS |
4149 | if (argv_find(argv, argc, "INTERFACE", &idx_intf)) |
4150 | intf_name = argv[idx_intf]->arg; | |
4151 | ||
d62a17ae | 4152 | if (uj) |
b1c3ae8c | 4153 | json = json_object_new_object(); |
6be4da3d | 4154 | |
b5a8894d CS |
4155 | /* vrf input is provided could be all or specific vrf*/ |
4156 | if (vrf_name) { | |
b1c3ae8c | 4157 | use_vrf = 1; |
b5a8894d CS |
4158 | if (all_vrf) { |
4159 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
4160 | if (!ospf->oi_running) | |
4161 | continue; | |
996c9314 LB |
4162 | ret = show_ip_ospf_interface_common( |
4163 | vty, ospf, intf_name, use_vrf, json, | |
4164 | uj); | |
b5a8894d | 4165 | } |
b1c3ae8c | 4166 | |
c48349e3 | 4167 | if (uj) |
92ef0078 | 4168 | vty_json(vty, json); |
c48349e3 | 4169 | else if (!ospf) |
fbaafa00 | 4170 | vty_out(vty, "%% OSPF is not enabled\n"); |
b1c3ae8c | 4171 | |
b5a8894d CS |
4172 | return ret; |
4173 | } | |
4174 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
b1c3ae8c | 4175 | if (ospf == NULL || !ospf->oi_running) { |
c48349e3 | 4176 | if (uj) |
92ef0078 | 4177 | vty_json(vty, json); |
c48349e3 | 4178 | else |
fbaafa00 JAG |
4179 | vty_out(vty, |
4180 | "%% OSPF is not enabled in vrf %s\n", | |
4181 | vrf_name); | |
9f049418 | 4182 | |
b5a8894d | 4183 | return CMD_SUCCESS; |
b1c3ae8c CS |
4184 | } |
4185 | ret = show_ip_ospf_interface_common(vty, ospf, intf_name, | |
4186 | use_vrf, json, uj); | |
b5a8894d CS |
4187 | |
4188 | } else { | |
4189 | /* Display default ospf (instance 0) info */ | |
4190 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
b1c3ae8c | 4191 | if (ospf == NULL || !ospf->oi_running) { |
c48349e3 | 4192 | if (uj) |
92ef0078 | 4193 | vty_json(vty, json); |
c48349e3 | 4194 | else |
fbaafa00 JAG |
4195 | vty_out(vty, |
4196 | "%% OSPF is not enabled in vrf default\n"); | |
9f049418 | 4197 | |
b5a8894d | 4198 | return CMD_SUCCESS; |
b1c3ae8c CS |
4199 | } |
4200 | ret = show_ip_ospf_interface_common(vty, ospf, intf_name, | |
4201 | use_vrf, json, uj); | |
4202 | } | |
4203 | ||
c48349e3 | 4204 | if (uj) |
92ef0078 | 4205 | vty_json(vty, json); |
b5a8894d CS |
4206 | |
4207 | return ret; | |
7c8ff89e DS |
4208 | } |
4209 | ||
4210 | DEFUN (show_ip_ospf_instance_interface, | |
4211 | show_ip_ospf_instance_interface_cmd, | |
6147e2c6 | 4212 | "show ip ospf (1-65535) interface [INTERFACE] [json]", |
7c8ff89e DS |
4213 | SHOW_STR |
4214 | IP_STR | |
4215 | "OSPF information\n" | |
4216 | "Instance ID\n" | |
4217 | "Interface information\n" | |
7ec4159b | 4218 | "Interface name\n" |
9973d184 | 4219 | JSON_STR) |
7c8ff89e | 4220 | { |
d62a17ae | 4221 | int idx_number = 3; |
b1c3ae8c | 4222 | int idx_intf = 0; |
d62a17ae | 4223 | struct ospf *ospf; |
d7c0a89a | 4224 | unsigned short instance = 0; |
9f049418 | 4225 | bool uj = use_json(argc, argv); |
b1c3ae8c CS |
4226 | char *intf_name = NULL; |
4227 | int ret = CMD_SUCCESS; | |
4228 | json_object *json = NULL; | |
d62a17ae | 4229 | |
4230 | instance = strtoul(argv[idx_number]->arg, NULL, 10); | |
409f98ab | 4231 | if (instance != ospf_instance) |
ac28e4ec CS |
4232 | return CMD_NOT_MY_INSTANCE; |
4233 | ||
409f98ab IR |
4234 | ospf = ospf_lookup_instance(instance); |
4235 | if (!ospf || !ospf->oi_running) | |
d62a17ae | 4236 | return CMD_SUCCESS; |
4237 | ||
4238 | if (uj) | |
b1c3ae8c CS |
4239 | json = json_object_new_object(); |
4240 | ||
4241 | if (argv_find(argv, argc, "INTERFACE", &idx_intf)) | |
4242 | intf_name = argv[idx_intf]->arg; | |
4243 | ||
4244 | ret = show_ip_ospf_interface_common(vty, ospf, intf_name, 0, json, uj); | |
4245 | ||
c48349e3 | 4246 | if (uj) |
92ef0078 | 4247 | vty_json(vty, json); |
d62a17ae | 4248 | |
b1c3ae8c | 4249 | return ret; |
d62a17ae | 4250 | } |
4251 | ||
c9339663 CS |
4252 | DEFUN (show_ip_ospf_interface_traffic, |
4253 | show_ip_ospf_interface_traffic_cmd, | |
4254 | "show ip ospf [vrf <NAME|all>] interface traffic [INTERFACE] [json]", | |
4255 | SHOW_STR | |
4256 | IP_STR | |
4257 | "OSPF information\n" | |
4258 | VRF_CMD_HELP_STR | |
4259 | "All VRFs\n" | |
4260 | "Interface information\n" | |
4261 | "Protocol Packet counters\n" | |
4262 | "Interface name\n" | |
4263 | JSON_STR) | |
4264 | { | |
4265 | struct ospf *ospf = NULL; | |
4266 | struct listnode *node = NULL; | |
4267 | char *vrf_name = NULL, *intf_name = NULL; | |
2951a7a4 | 4268 | bool all_vrf = false; |
c9339663 CS |
4269 | int inst = 0; |
4270 | int idx_vrf = 0, idx_intf = 0; | |
9f049418 | 4271 | bool uj = use_json(argc, argv); |
b1c3ae8c | 4272 | json_object *json = NULL; |
c9339663 CS |
4273 | int ret = CMD_SUCCESS; |
4274 | int display_once = 0; | |
d7c0a89a | 4275 | uint8_t use_vrf = 0; |
c9339663 CS |
4276 | |
4277 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); | |
4278 | ||
4279 | if (argv_find(argv, argc, "INTERFACE", &idx_intf)) | |
4280 | intf_name = argv[idx_intf]->arg; | |
4281 | ||
b1c3ae8c CS |
4282 | if (uj) |
4283 | json = json_object_new_object(); | |
4284 | ||
c9339663 | 4285 | if (vrf_name) { |
b1c3ae8c | 4286 | use_vrf = 1; |
c9339663 CS |
4287 | if (all_vrf) { |
4288 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
4289 | if (!ospf->oi_running) | |
4290 | continue; | |
4291 | ||
996c9314 LB |
4292 | ret = show_ip_ospf_interface_traffic_common( |
4293 | vty, ospf, intf_name, json, | |
4294 | display_once, use_vrf, uj); | |
c9339663 CS |
4295 | display_once = 1; |
4296 | } | |
b1c3ae8c | 4297 | |
c48349e3 | 4298 | if (uj) |
92ef0078 | 4299 | vty_json(vty, json); |
b1c3ae8c | 4300 | |
c9339663 CS |
4301 | return ret; |
4302 | } | |
4303 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
b1c3ae8c CS |
4304 | if (ospf == NULL || !ospf->oi_running) { |
4305 | if (uj) | |
4306 | json_object_free(json); | |
c9339663 | 4307 | return CMD_SUCCESS; |
b1c3ae8c CS |
4308 | } |
4309 | ||
996c9314 LB |
4310 | ret = show_ip_ospf_interface_traffic_common( |
4311 | vty, ospf, intf_name, json, display_once, use_vrf, uj); | |
c9339663 CS |
4312 | } else { |
4313 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
b1c3ae8c CS |
4314 | if (ospf == NULL || !ospf->oi_running) { |
4315 | if (uj) | |
4316 | json_object_free(json); | |
c9339663 | 4317 | return CMD_SUCCESS; |
b1c3ae8c CS |
4318 | } |
4319 | ||
996c9314 LB |
4320 | ret = show_ip_ospf_interface_traffic_common( |
4321 | vty, ospf, intf_name, json, display_once, use_vrf, uj); | |
b1c3ae8c CS |
4322 | } |
4323 | ||
c48349e3 | 4324 | if (uj) |
92ef0078 | 4325 | vty_json(vty, json); |
c9339663 CS |
4326 | |
4327 | return ret; | |
4328 | } | |
4329 | ||
4330 | ||
d62a17ae | 4331 | static void show_ip_ospf_neighbour_header(struct vty *vty) |
4332 | { | |
eb4ed6e8 | 4333 | vty_out(vty, "\n%-15s %-3s %-15s %-15s %-9s %-15s %-32s %5s %5s %5s\n", |
4334 | "Neighbor ID", "Pri", "State", "Up Time", "Dead Time", | |
4335 | "Address", "Interface", "RXmtL", "RqstL", "DBsmL"); | |
d62a17ae | 4336 | } |
4337 | ||
e8a8b116 | 4338 | static void show_ip_ospf_neighbour_brief(struct vty *vty, |
4339 | struct ospf_neighbor *nbr, | |
4340 | struct ospf_neighbor *prev_nbr, | |
4341 | json_object *json, bool use_json) | |
d62a17ae | 4342 | { |
d62a17ae | 4343 | char msgbuf[16]; |
4344 | char timebuf[OSPF_TIME_DUMP_SIZE]; | |
cef262c3 | 4345 | json_object *json_neighbor = NULL, *json_neigh_array = NULL; |
25804ce5 | 4346 | struct timeval res = {.tv_sec = 0, .tv_usec = 0}; |
eb4ed6e8 | 4347 | long time_val = 0; |
4348 | char uptime[OSPF_TIME_DUMP_SIZE]; | |
d62a17ae | 4349 | |
e8a8b116 | 4350 | if (nbr->ts_last_progress.tv_sec || nbr->ts_last_progress.tv_usec) |
4351 | time_val = | |
4352 | monotime_since(&nbr->ts_last_progress, &res) / 1000LL; | |
eb4ed6e8 | 4353 | |
e8a8b116 | 4354 | if (use_json) { |
4355 | char neigh_str[INET_ADDRSTRLEN]; | |
cef262c3 | 4356 | |
e8a8b116 | 4357 | if (prev_nbr && !IPV4_ADDR_SAME(&prev_nbr->src, &nbr->src)) { |
4358 | /* Start new neigh list */ | |
4359 | json_neigh_array = NULL; | |
4360 | } | |
cef262c3 | 4361 | |
e8a8b116 | 4362 | if (nbr->state == NSM_Attempt && |
4363 | nbr->router_id.s_addr == INADDR_ANY) | |
4364 | strlcpy(neigh_str, "neighbor", sizeof(neigh_str)); | |
4365 | else | |
4366 | inet_ntop(AF_INET, &nbr->router_id, neigh_str, | |
4367 | sizeof(neigh_str)); | |
cef262c3 | 4368 | |
e8a8b116 | 4369 | json_object_object_get_ex(json, neigh_str, &json_neigh_array); |
cef262c3 | 4370 | |
e8a8b116 | 4371 | if (!json_neigh_array) { |
4372 | json_neigh_array = json_object_new_array(); | |
4373 | json_object_object_add(json, neigh_str, | |
4374 | json_neigh_array); | |
4375 | } | |
cef262c3 | 4376 | |
e8a8b116 | 4377 | json_neighbor = json_object_new_object(); |
cef262c3 | 4378 | |
e8a8b116 | 4379 | ospf_nbr_ism_state_message(nbr, msgbuf, sizeof(msgbuf)); |
1c18b0d6 | 4380 | #if CONFDATE > 20230321 |
e8a8b116 | 4381 | CPP_NOTICE( |
4382 | "Remove show_ip_ospf_neighbor_sub() JSON keys: priority, state, deadTimeMsecs, address, retransmitCounter, requestCounter, dbSummaryCounter") | |
1c18b0d6 | 4383 | #endif |
e8a8b116 | 4384 | json_object_int_add(json_neighbor, "priority", nbr->priority); |
4385 | json_object_string_add(json_neighbor, "state", msgbuf); | |
4386 | json_object_int_add(json_neighbor, "nbrPriority", | |
4387 | nbr->priority); | |
4388 | json_object_string_add(json_neighbor, "nbrState", msgbuf); | |
4389 | ||
4390 | json_object_string_add( | |
4391 | json_neighbor, "converged", | |
4392 | lookup_msg(ospf_nsm_state_msg, nbr->state, NULL)); | |
4393 | json_object_string_add(json_neighbor, "role", | |
4394 | lookup_msg(ospf_ism_state_msg, | |
4395 | ospf_nbr_ism_state(nbr), | |
4396 | NULL)); | |
4397 | if (nbr->t_inactivity) { | |
4398 | long time_store; | |
b3d498f8 | 4399 | |
e8a8b116 | 4400 | time_store = monotime_until(&nbr->t_inactivity->u.sands, |
4401 | NULL) / | |
4402 | 1000LL; | |
4403 | json_object_int_add(json_neighbor, "upTimeInMsec", | |
4404 | time_val); | |
4405 | json_object_int_add(json_neighbor, "deadTimeMsecs", | |
4406 | time_store); | |
4407 | json_object_int_add(json_neighbor, | |
4408 | "routerDeadIntervalTimerDueMsec", | |
4409 | time_store); | |
4410 | json_object_string_add( | |
4411 | json_neighbor, "upTime", | |
4412 | ospf_timeval_dump(&res, uptime, | |
4413 | sizeof(uptime))); | |
4414 | json_object_string_add( | |
4415 | json_neighbor, "deadTime", | |
4416 | ospf_timer_dump(nbr->t_inactivity, timebuf, | |
4417 | sizeof(timebuf))); | |
4418 | } else { | |
4419 | json_object_string_add(json_neighbor, "deadTimeMsecs", | |
4420 | "inactive"); | |
4421 | json_object_string_add(json_neighbor, | |
4422 | "routerDeadIntervalTimerDueMsec", | |
4423 | "inactive"); | |
4424 | } | |
4425 | json_object_string_addf(json_neighbor, "address", "%pI4", | |
4426 | &nbr->src); | |
4427 | json_object_string_addf(json_neighbor, "ifaceAddress", "%pI4", | |
4428 | &nbr->src); | |
4429 | json_object_string_add(json_neighbor, "ifaceName", | |
4430 | IF_NAME(nbr->oi)); | |
4431 | json_object_int_add(json_neighbor, "retransmitCounter", | |
4432 | ospf_ls_retransmit_count(nbr)); | |
4433 | json_object_int_add(json_neighbor, | |
4434 | "linkStateRetransmissionListCounter", | |
4435 | ospf_ls_retransmit_count(nbr)); | |
4436 | json_object_int_add(json_neighbor, "requestCounter", | |
4437 | ospf_ls_request_count(nbr)); | |
4438 | json_object_int_add(json_neighbor, | |
4439 | "linkStateRequestListCounter", | |
4440 | ospf_ls_request_count(nbr)); | |
4441 | json_object_int_add(json_neighbor, "dbSummaryCounter", | |
4442 | ospf_db_summary_count(nbr)); | |
4443 | json_object_int_add(json_neighbor, "databaseSummaryListCounter", | |
4444 | ospf_db_summary_count(nbr)); | |
cef262c3 | 4445 | |
e8a8b116 | 4446 | json_object_array_add(json_neigh_array, json_neighbor); |
4447 | } else { | |
4448 | ospf_nbr_ism_state_message(nbr, msgbuf, sizeof(msgbuf)); | |
cef262c3 | 4449 | |
e8a8b116 | 4450 | if (nbr->state == NSM_Attempt && |
4451 | nbr->router_id.s_addr == INADDR_ANY) | |
4452 | vty_out(vty, "%-15s %3d %-15s ", "-", nbr->priority, | |
4453 | msgbuf); | |
4454 | else | |
4455 | vty_out(vty, "%-15pI4 %3d %-15s ", &nbr->router_id, | |
4456 | nbr->priority, msgbuf); | |
eb4ed6e8 | 4457 | |
e8a8b116 | 4458 | vty_out(vty, "%-15s ", |
4459 | ospf_timeval_dump(&res, uptime, sizeof(uptime))); | |
4460 | ||
4461 | vty_out(vty, "%9s ", | |
4462 | ospf_timer_dump(nbr->t_inactivity, timebuf, | |
4463 | sizeof(timebuf))); | |
4464 | vty_out(vty, "%-15pI4 ", &nbr->src); | |
4465 | vty_out(vty, "%-32s %5ld %5ld %5d\n", IF_NAME(nbr->oi), | |
4466 | ospf_ls_retransmit_count(nbr), | |
4467 | ospf_ls_request_count(nbr), ospf_db_summary_count(nbr)); | |
4468 | } | |
4469 | } | |
4470 | ||
4471 | static void show_ip_ospf_neighbor_sub(struct vty *vty, | |
4472 | struct ospf_interface *oi, | |
4473 | json_object *json, bool use_json) | |
4474 | { | |
4475 | struct route_node *rn; | |
4476 | struct ospf_neighbor *nbr, *prev_nbr = NULL; | |
4477 | ||
4478 | for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) { | |
4479 | if ((nbr = rn->info)) { | |
4480 | /* Do not show myself. */ | |
4481 | if (nbr == oi->nbr_self) | |
4482 | continue; | |
4483 | /* Down state is not shown. */ | |
4484 | if (nbr->state == NSM_Down) | |
4485 | continue; | |
cef262c3 | 4486 | |
cef262c3 | 4487 | prev_nbr = nbr; |
e8a8b116 | 4488 | |
4489 | show_ip_ospf_neighbour_brief(vty, nbr, prev_nbr, json, | |
4490 | use_json); | |
d62a17ae | 4491 | } |
4492 | } | |
4493 | } | |
4494 | ||
4495 | static int show_ip_ospf_neighbor_common(struct vty *vty, struct ospf *ospf, | |
9f049418 | 4496 | json_object *json, bool use_json, |
d7c0a89a | 4497 | uint8_t use_vrf) |
d62a17ae | 4498 | { |
4499 | struct ospf_interface *oi; | |
4500 | struct listnode *node; | |
6282e124 | 4501 | json_object *json_vrf = NULL; |
2bc7673f | 4502 | json_object *json_nbr_sub = NULL; |
7c8ff89e | 4503 | |
b1c3ae8c CS |
4504 | if (use_json) { |
4505 | if (use_vrf) | |
4506 | json_vrf = json_object_new_object(); | |
4507 | else | |
4508 | json_vrf = json; | |
6282e124 | 4509 | json_nbr_sub = json_object_new_object(); |
b1c3ae8c | 4510 | } |
d62a17ae | 4511 | |
4512 | if (ospf->instance) { | |
4513 | if (use_json) | |
4514 | json_object_int_add(json, "ospfInstance", | |
4515 | ospf->instance); | |
4516 | else | |
4517 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
4518 | } | |
7c8ff89e | 4519 | |
b1c3ae8c CS |
4520 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); |
4521 | if (!use_json) | |
4522 | show_ip_ospf_neighbour_header(vty); | |
87bd50e8 | 4523 | |
2bc7673f CS |
4524 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) { |
4525 | if (ospf_interface_neighbor_count(oi) == 0) | |
4526 | continue; | |
2bc7673f CS |
4527 | show_ip_ospf_neighbor_sub(vty, oi, json_nbr_sub, use_json); |
4528 | } | |
718e3744 | 4529 | |
d62a17ae | 4530 | if (use_json) { |
996c9314 | 4531 | json_object_object_add(json_vrf, "neighbors", json_nbr_sub); |
44076f4d RW |
4532 | if (use_vrf) |
4533 | json_object_object_add(json, ospf_get_name(ospf), | |
4534 | json_vrf); | |
d62a17ae | 4535 | } else |
4536 | vty_out(vty, "\n"); | |
7c8ff89e | 4537 | |
d62a17ae | 4538 | return CMD_SUCCESS; |
718e3744 | 4539 | } |
4540 | ||
7c8ff89e DS |
4541 | DEFUN (show_ip_ospf_neighbor, |
4542 | show_ip_ospf_neighbor_cmd, | |
b5a8894d | 4543 | "show ip ospf [vrf <NAME|all>] neighbor [json]", |
718e3744 | 4544 | SHOW_STR |
4545 | IP_STR | |
4546 | "OSPF information\n" | |
b5a8894d CS |
4547 | VRF_CMD_HELP_STR |
4548 | "All VRFs\n" | |
91756b38 | 4549 | "Neighbor list\n" |
9973d184 | 4550 | JSON_STR) |
718e3744 | 4551 | { |
d62a17ae | 4552 | struct ospf *ospf; |
9f049418 | 4553 | bool uj = use_json(argc, argv); |
b5a8894d CS |
4554 | struct listnode *node = NULL; |
4555 | char *vrf_name = NULL; | |
2951a7a4 | 4556 | bool all_vrf = false; |
b5a8894d CS |
4557 | int ret = CMD_SUCCESS; |
4558 | int inst = 0; | |
4559 | int idx_vrf = 0; | |
d7c0a89a | 4560 | uint8_t use_vrf = 0; |
b1c3ae8c | 4561 | json_object *json = NULL; |
718e3744 | 4562 | |
43b8d1d8 | 4563 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
7c8ff89e | 4564 | |
b1c3ae8c CS |
4565 | if (uj) |
4566 | json = json_object_new_object(); | |
b5a8894d CS |
4567 | |
4568 | /* vrf input is provided could be all or specific vrf*/ | |
4569 | if (vrf_name) { | |
b1c3ae8c | 4570 | use_vrf = 1; |
b5a8894d CS |
4571 | if (all_vrf) { |
4572 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
4573 | if (!ospf->oi_running) | |
4574 | continue; | |
996c9314 LB |
4575 | ret = show_ip_ospf_neighbor_common( |
4576 | vty, ospf, json, uj, use_vrf); | |
b1c3ae8c CS |
4577 | } |
4578 | ||
c48349e3 | 4579 | if (uj) |
92ef0078 | 4580 | vty_json(vty, json); |
c48349e3 | 4581 | else if (!ospf) |
fbaafa00 | 4582 | vty_out(vty, "OSPF is not enabled\n"); |
b1c3ae8c | 4583 | |
b5a8894d CS |
4584 | return ret; |
4585 | } | |
b1c3ae8c | 4586 | |
b5a8894d | 4587 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); |
b1c3ae8c | 4588 | if (ospf == NULL || !ospf->oi_running) { |
c48349e3 | 4589 | if (uj) |
92ef0078 | 4590 | vty_json(vty, json); |
c48349e3 | 4591 | else |
fbaafa00 JAG |
4592 | vty_out(vty, |
4593 | "%% OSPF is not enabled in vrf %s\n", | |
4594 | vrf_name); | |
9f049418 | 4595 | |
b5a8894d | 4596 | return CMD_SUCCESS; |
b1c3ae8c | 4597 | } |
b5a8894d CS |
4598 | } else { |
4599 | /* Display default ospf (instance 0) info */ | |
4600 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
b1c3ae8c | 4601 | if (ospf == NULL || !ospf->oi_running) { |
c48349e3 | 4602 | if (uj) |
92ef0078 | 4603 | vty_json(vty, json); |
c48349e3 | 4604 | else |
fbaafa00 JAG |
4605 | vty_out(vty, |
4606 | "%% OSPF is not enabled in vrf default\n"); | |
9f049418 | 4607 | |
b5a8894d | 4608 | return CMD_SUCCESS; |
b1c3ae8c | 4609 | } |
b5a8894d CS |
4610 | } |
4611 | ||
b1c3ae8c CS |
4612 | if (ospf) { |
4613 | ret = show_ip_ospf_neighbor_common(vty, ospf, json, uj, | |
4614 | use_vrf); | |
4615 | ||
4616 | if (uj) { | |
4617 | vty_out(vty, "%s\n", | |
996c9314 LB |
4618 | json_object_to_json_string_ext( |
4619 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c CS |
4620 | } |
4621 | } | |
4622 | ||
4623 | if (uj) | |
4624 | json_object_free(json); | |
b5a8894d CS |
4625 | |
4626 | return ret; | |
7c8ff89e DS |
4627 | } |
4628 | ||
4629 | ||
4630 | DEFUN (show_ip_ospf_instance_neighbor, | |
4631 | show_ip_ospf_instance_neighbor_cmd, | |
6147e2c6 | 4632 | "show ip ospf (1-65535) neighbor [json]", |
7c8ff89e DS |
4633 | SHOW_STR |
4634 | IP_STR | |
4635 | "OSPF information\n" | |
4636 | "Instance ID\n" | |
91756b38 | 4637 | "Neighbor list\n" |
9973d184 | 4638 | JSON_STR) |
7c8ff89e | 4639 | { |
d62a17ae | 4640 | int idx_number = 3; |
4641 | struct ospf *ospf; | |
d7c0a89a | 4642 | unsigned short instance = 0; |
9f049418 | 4643 | bool uj = use_json(argc, argv); |
b1c3ae8c CS |
4644 | json_object *json = NULL; |
4645 | int ret = CMD_SUCCESS; | |
7c8ff89e | 4646 | |
d62a17ae | 4647 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
409f98ab | 4648 | if (instance != ospf_instance) |
ac28e4ec CS |
4649 | return CMD_NOT_MY_INSTANCE; |
4650 | ||
409f98ab IR |
4651 | ospf = ospf_lookup_instance(instance); |
4652 | if (!ospf || !ospf->oi_running) | |
d62a17ae | 4653 | return CMD_SUCCESS; |
7c8ff89e | 4654 | |
b1c3ae8c CS |
4655 | if (uj) |
4656 | json = json_object_new_object(); | |
b5a8894d | 4657 | |
b1c3ae8c CS |
4658 | ret = show_ip_ospf_neighbor_common(vty, ospf, json, uj, 0); |
4659 | ||
c48349e3 | 4660 | if (uj) |
92ef0078 | 4661 | vty_json(vty, json); |
b1c3ae8c CS |
4662 | |
4663 | return ret; | |
7c8ff89e DS |
4664 | } |
4665 | ||
d62a17ae | 4666 | static int show_ip_ospf_neighbor_all_common(struct vty *vty, struct ospf *ospf, |
9f049418 | 4667 | json_object *json, bool use_json, |
d7c0a89a | 4668 | uint8_t use_vrf) |
d62a17ae | 4669 | { |
4670 | struct listnode *node; | |
4671 | struct ospf_interface *oi; | |
96b663a3 | 4672 | char buf[PREFIX_STRLEN]; |
b1c3ae8c | 4673 | json_object *json_vrf = NULL; |
d62a17ae | 4674 | json_object *json_neighbor_sub = NULL; |
7c8ff89e | 4675 | |
d62a17ae | 4676 | if (use_json) { |
b1c3ae8c CS |
4677 | if (use_vrf) |
4678 | json_vrf = json_object_new_object(); | |
4679 | else | |
4680 | json_vrf = json; | |
b5a8894d | 4681 | } |
d62a17ae | 4682 | |
b1c3ae8c CS |
4683 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); |
4684 | if (!use_json) | |
4685 | show_ip_ospf_neighbour_header(vty); | |
4686 | ||
d62a17ae | 4687 | if (ospf->instance) { |
4688 | if (use_json) | |
b1c3ae8c | 4689 | json_object_int_add(json_vrf, "ospfInstance", |
d62a17ae | 4690 | ospf->instance); |
4691 | else | |
4692 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
4693 | } | |
4694 | ||
4695 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) { | |
4696 | struct listnode *nbr_node; | |
4697 | struct ospf_nbr_nbma *nbr_nbma; | |
4698 | ||
b1c3ae8c | 4699 | show_ip_ospf_neighbor_sub(vty, oi, json_vrf, use_json); |
d62a17ae | 4700 | |
4701 | /* print Down neighbor status */ | |
4702 | for (ALL_LIST_ELEMENTS_RO(oi->nbr_nbma, nbr_node, nbr_nbma)) { | |
4703 | if (nbr_nbma->nbr == NULL | |
4704 | || nbr_nbma->nbr->state == NSM_Down) { | |
4705 | if (use_json) { | |
6f3e19b7 MR |
4706 | json_neighbor_sub = |
4707 | json_object_new_object(); | |
d62a17ae | 4708 | json_object_int_add(json_neighbor_sub, |
4709 | "nbrNbmaPriority", | |
4710 | nbr_nbma->priority); | |
4711 | json_object_boolean_true_add( | |
4712 | json_neighbor_sub, | |
4713 | "nbrNbmaDown"); | |
4714 | json_object_string_add( | |
4715 | json_neighbor_sub, | |
4716 | "nbrNbmaIfaceName", | |
4717 | IF_NAME(oi)); | |
4718 | json_object_int_add( | |
4719 | json_neighbor_sub, | |
4720 | "nbrNbmaRetransmitCounter", 0); | |
4721 | json_object_int_add( | |
4722 | json_neighbor_sub, | |
4723 | "nbrNbmaRequestCounter", 0); | |
4724 | json_object_int_add( | |
4725 | json_neighbor_sub, | |
4726 | "nbrNbmaDbSummaryCounter", 0); | |
4727 | json_object_object_add( | |
b1c3ae8c | 4728 | json_vrf, |
96b663a3 MS |
4729 | inet_ntop(AF_INET, |
4730 | &nbr_nbma->addr, buf, | |
4731 | sizeof(buf)), | |
d62a17ae | 4732 | json_neighbor_sub); |
4733 | } else { | |
4734 | vty_out(vty, "%-15s %3d %-15s %9s ", | |
4735 | "-", nbr_nbma->priority, "Down", | |
4736 | "-"); | |
4737 | vty_out(vty, | |
96b663a3 MS |
4738 | "%-32pI4 %-20s %5d %5d %5d\n", |
4739 | &nbr_nbma->addr, | |
d62a17ae | 4740 | IF_NAME(oi), 0, 0, 0); |
4741 | } | |
4742 | } | |
4743 | } | |
4744 | } | |
4745 | ||
4746 | if (use_json) { | |
44076f4d RW |
4747 | if (use_vrf) |
4748 | json_object_object_add(json, ospf_get_name(ospf), | |
4749 | json_vrf); | |
d62a17ae | 4750 | } else |
4751 | vty_out(vty, "\n"); | |
4752 | ||
4753 | return CMD_SUCCESS; | |
718e3744 | 4754 | } |
4755 | ||
7c8ff89e DS |
4756 | DEFUN (show_ip_ospf_neighbor_all, |
4757 | show_ip_ospf_neighbor_all_cmd, | |
b5a8894d | 4758 | "show ip ospf [vrf <NAME|all>] neighbor all [json]", |
718e3744 | 4759 | SHOW_STR |
4760 | IP_STR | |
4761 | "OSPF information\n" | |
b5a8894d CS |
4762 | VRF_CMD_HELP_STR |
4763 | "All VRFs\n" | |
718e3744 | 4764 | "Neighbor list\n" |
91756b38 | 4765 | "include down status neighbor\n" |
9973d184 | 4766 | JSON_STR) |
7c8ff89e | 4767 | { |
d62a17ae | 4768 | struct ospf *ospf; |
9f049418 | 4769 | bool uj = use_json(argc, argv); |
b5a8894d CS |
4770 | struct listnode *node = NULL; |
4771 | char *vrf_name = NULL; | |
2951a7a4 | 4772 | bool all_vrf = false; |
b5a8894d CS |
4773 | int ret = CMD_SUCCESS; |
4774 | int inst = 0; | |
4775 | int idx_vrf = 0; | |
d7c0a89a | 4776 | uint8_t use_vrf = 0; |
b1c3ae8c | 4777 | json_object *json = NULL; |
7c8ff89e | 4778 | |
43b8d1d8 | 4779 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
7c8ff89e | 4780 | |
b1c3ae8c CS |
4781 | if (uj) |
4782 | json = json_object_new_object(); | |
b5a8894d CS |
4783 | |
4784 | /* vrf input is provided could be all or specific vrf*/ | |
4785 | if (vrf_name) { | |
b1c3ae8c | 4786 | use_vrf = 1; |
b5a8894d CS |
4787 | if (all_vrf) { |
4788 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
4789 | if (!ospf->oi_running) | |
4790 | continue; | |
996c9314 LB |
4791 | ret = show_ip_ospf_neighbor_all_common( |
4792 | vty, ospf, json, uj, use_vrf); | |
b1c3ae8c CS |
4793 | } |
4794 | ||
c48349e3 | 4795 | if (uj) |
92ef0078 | 4796 | vty_json(vty, json); |
b1c3ae8c | 4797 | |
b5a8894d CS |
4798 | return ret; |
4799 | } | |
b1c3ae8c | 4800 | |
b5a8894d | 4801 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); |
b1c3ae8c CS |
4802 | if (ospf == NULL || !ospf->oi_running) { |
4803 | if (uj) | |
4804 | json_object_free(json); | |
b5a8894d | 4805 | return CMD_SUCCESS; |
b1c3ae8c | 4806 | } |
b5a8894d CS |
4807 | } else { |
4808 | /* Display default ospf (instance 0) info */ | |
4809 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
b1c3ae8c CS |
4810 | if (ospf == NULL || !ospf->oi_running) { |
4811 | if (uj) | |
4812 | json_object_free(json); | |
b5a8894d | 4813 | return CMD_SUCCESS; |
b1c3ae8c | 4814 | } |
b5a8894d CS |
4815 | } |
4816 | ||
b1c3ae8c CS |
4817 | if (ospf) { |
4818 | ret = show_ip_ospf_neighbor_all_common(vty, ospf, json, uj, | |
4819 | use_vrf); | |
4820 | if (uj) { | |
4821 | vty_out(vty, "%s\n", | |
996c9314 LB |
4822 | json_object_to_json_string_ext( |
4823 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c CS |
4824 | } |
4825 | } | |
4826 | ||
4827 | if (uj) | |
4828 | json_object_free(json); | |
b5a8894d CS |
4829 | |
4830 | return ret; | |
7c8ff89e DS |
4831 | } |
4832 | ||
4833 | DEFUN (show_ip_ospf_instance_neighbor_all, | |
4834 | show_ip_ospf_instance_neighbor_all_cmd, | |
6147e2c6 | 4835 | "show ip ospf (1-65535) neighbor all [json]", |
7c8ff89e DS |
4836 | SHOW_STR |
4837 | IP_STR | |
4838 | "OSPF information\n" | |
4839 | "Instance ID\n" | |
4840 | "Neighbor list\n" | |
91756b38 | 4841 | "include down status neighbor\n" |
9973d184 | 4842 | JSON_STR) |
718e3744 | 4843 | { |
d62a17ae | 4844 | int idx_number = 3; |
4845 | struct ospf *ospf; | |
d7c0a89a | 4846 | unsigned short instance = 0; |
9f049418 | 4847 | bool uj = use_json(argc, argv); |
b1c3ae8c CS |
4848 | json_object *json = NULL; |
4849 | int ret = CMD_SUCCESS; | |
7c8ff89e | 4850 | |
d62a17ae | 4851 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
409f98ab | 4852 | if (instance != ospf_instance) |
ac28e4ec CS |
4853 | return CMD_NOT_MY_INSTANCE; |
4854 | ||
409f98ab IR |
4855 | ospf = ospf_lookup_instance(instance); |
4856 | if (!ospf || !ospf->oi_running) | |
d62a17ae | 4857 | return CMD_SUCCESS; |
b1c3ae8c CS |
4858 | if (uj) |
4859 | json = json_object_new_object(); | |
4860 | ||
4861 | ret = show_ip_ospf_neighbor_all_common(vty, ospf, json, uj, 0); | |
4862 | ||
c48349e3 | 4863 | if (uj) |
92ef0078 | 4864 | vty_json(vty, json); |
7c8ff89e | 4865 | |
b1c3ae8c | 4866 | return ret; |
7c8ff89e DS |
4867 | } |
4868 | ||
d62a17ae | 4869 | static int show_ip_ospf_neighbor_int_common(struct vty *vty, struct ospf *ospf, |
4870 | int arg_base, | |
4871 | struct cmd_token **argv, | |
9f049418 | 4872 | bool use_json, uint8_t use_vrf) |
d62a17ae | 4873 | { |
4874 | struct interface *ifp; | |
4875 | struct route_node *rn; | |
4876 | json_object *json = NULL; | |
91756b38 | 4877 | |
d62a17ae | 4878 | if (use_json) |
4879 | json = json_object_new_object(); | |
d62a17ae | 4880 | |
4881 | if (ospf->instance) { | |
4882 | if (use_json) | |
4883 | json_object_int_add(json, "ospfInstance", | |
4884 | ospf->instance); | |
4885 | else | |
4886 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
4887 | } | |
4888 | ||
b1c3ae8c | 4889 | ospf_show_vrf_name(ospf, vty, json, use_vrf); |
87bd50e8 | 4890 | |
a36898e7 | 4891 | ifp = if_lookup_by_name(argv[arg_base]->arg, ospf->vrf_id); |
d62a17ae | 4892 | if (!ifp) { |
4893 | if (use_json) | |
4894 | json_object_boolean_true_add(json, "noSuchIface"); | |
4895 | else | |
4896 | vty_out(vty, "No such interface.\n"); | |
4897 | return CMD_WARNING; | |
4898 | } | |
4899 | ||
4900 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { | |
4901 | struct ospf_interface *oi = rn->info; | |
4902 | ||
4903 | if (oi == NULL) | |
4904 | continue; | |
4905 | ||
4906 | show_ip_ospf_neighbor_sub(vty, oi, json, use_json); | |
4907 | } | |
4908 | ||
c48349e3 | 4909 | if (use_json) |
92ef0078 | 4910 | vty_json(vty, json); |
c48349e3 | 4911 | else |
d62a17ae | 4912 | vty_out(vty, "\n"); |
4913 | ||
4914 | return CMD_SUCCESS; | |
718e3744 | 4915 | } |
4916 | ||
7c8ff89e DS |
4917 | DEFUN (show_ip_ospf_neighbor_int, |
4918 | show_ip_ospf_neighbor_int_cmd, | |
03ed9f02 | 4919 | "show ip ospf [vrf <NAME>] neighbor IFNAME [json]", |
7c8ff89e DS |
4920 | SHOW_STR |
4921 | IP_STR | |
4922 | "OSPF information\n" | |
03ed9f02 | 4923 | VRF_CMD_HELP_STR |
7c8ff89e | 4924 | "Neighbor list\n" |
91756b38 | 4925 | "Interface name\n" |
9973d184 | 4926 | JSON_STR) |
7c8ff89e | 4927 | { |
d62a17ae | 4928 | struct ospf *ospf; |
03ed9f02 PG |
4929 | int idx_ifname = 0; |
4930 | int idx_vrf = 0; | |
9f049418 | 4931 | bool uj = use_json(argc, argv); |
b5a8894d CS |
4932 | int ret = CMD_SUCCESS; |
4933 | struct interface *ifp = NULL; | |
03ed9f02 PG |
4934 | char *vrf_name = NULL; |
4935 | vrf_id_t vrf_id = VRF_DEFAULT; | |
4936 | struct vrf *vrf = NULL; | |
4937 | ||
4938 | if (argv_find(argv, argc, "vrf", &idx_vrf)) | |
4939 | vrf_name = argv[idx_vrf + 1]->arg; | |
4940 | if (vrf_name && strmatch(vrf_name, VRF_DEFAULT_NAME)) | |
4941 | vrf_name = NULL; | |
4942 | if (vrf_name) { | |
4943 | vrf = vrf_lookup_by_name(vrf_name); | |
4944 | if (vrf) | |
4945 | vrf_id = vrf->vrf_id; | |
4946 | } | |
4947 | ospf = ospf_lookup_by_vrf_id(vrf_id); | |
4948 | ||
4949 | if (!ospf || !ospf->oi_running) | |
4950 | return ret; | |
7c8ff89e | 4951 | |
b5a8894d CS |
4952 | if (!uj) |
4953 | show_ip_ospf_neighbour_header(vty); | |
7c8ff89e | 4954 | |
03ed9f02 | 4955 | argv_find(argv, argc, "IFNAME", &idx_ifname); |
b5a8894d | 4956 | |
a36898e7 | 4957 | ifp = if_lookup_by_name(argv[idx_ifname]->arg, vrf_id); |
03ed9f02 PG |
4958 | if (!ifp) |
4959 | return ret; | |
4960 | ||
4961 | ret = show_ip_ospf_neighbor_int_common(vty, ospf, idx_ifname, | |
4962 | argv, uj, 0); | |
b5a8894d | 4963 | return ret; |
7c8ff89e DS |
4964 | } |
4965 | ||
4966 | DEFUN (show_ip_ospf_instance_neighbor_int, | |
4967 | show_ip_ospf_instance_neighbor_int_cmd, | |
6147e2c6 | 4968 | "show ip ospf (1-65535) neighbor IFNAME [json]", |
7c8ff89e DS |
4969 | SHOW_STR |
4970 | IP_STR | |
4971 | "OSPF information\n" | |
4972 | "Instance ID\n" | |
4973 | "Neighbor list\n" | |
91756b38 | 4974 | "Interface name\n" |
9973d184 | 4975 | JSON_STR) |
7c8ff89e | 4976 | { |
d62a17ae | 4977 | int idx_number = 3; |
b4e84315 | 4978 | int idx_ifname = 5; |
d62a17ae | 4979 | struct ospf *ospf; |
d7c0a89a | 4980 | unsigned short instance = 0; |
9f049418 | 4981 | bool uj = use_json(argc, argv); |
7c8ff89e | 4982 | |
b5a8894d CS |
4983 | if (!uj) |
4984 | show_ip_ospf_neighbour_header(vty); | |
4985 | ||
d62a17ae | 4986 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
409f98ab | 4987 | if (instance != ospf_instance) |
ac28e4ec CS |
4988 | return CMD_NOT_MY_INSTANCE; |
4989 | ||
409f98ab IR |
4990 | ospf = ospf_lookup_instance(instance); |
4991 | if (!ospf || !ospf->oi_running) | |
d62a17ae | 4992 | return CMD_SUCCESS; |
7c8ff89e | 4993 | |
b5a8894d CS |
4994 | if (!uj) |
4995 | show_ip_ospf_neighbour_header(vty); | |
4996 | ||
996c9314 LB |
4997 | return show_ip_ospf_neighbor_int_common(vty, ospf, idx_ifname, argv, uj, |
4998 | 0); | |
718e3744 | 4999 | } |
5000 | ||
d62a17ae | 5001 | static void show_ip_ospf_nbr_nbma_detail_sub(struct vty *vty, |
5002 | struct ospf_interface *oi, | |
5003 | struct ospf_nbr_nbma *nbr_nbma, | |
9f049418 | 5004 | bool use_json, json_object *json) |
d62a17ae | 5005 | { |
5006 | char timebuf[OSPF_TIME_DUMP_SIZE]; | |
5007 | json_object *json_sub = NULL; | |
718e3744 | 5008 | |
d62a17ae | 5009 | if (use_json) |
5010 | json_sub = json_object_new_object(); | |
5011 | else /* Show neighbor ID. */ | |
5012 | vty_out(vty, " Neighbor %s,", "-"); | |
5013 | ||
5014 | /* Show interface address. */ | |
5015 | if (use_json) | |
20308be3 DA |
5016 | json_object_string_addf(json_sub, "ifaceAddress", "%pI4", |
5017 | &nbr_nbma->addr); | |
d62a17ae | 5018 | else |
96b663a3 MS |
5019 | vty_out(vty, " interface address %pI4\n", |
5020 | &nbr_nbma->addr); | |
d62a17ae | 5021 | |
5022 | /* Show Area ID. */ | |
5023 | if (use_json) { | |
5024 | json_object_string_add(json_sub, "areaId", | |
5025 | ospf_area_desc_string(oi->area)); | |
5026 | json_object_string_add(json_sub, "iface", IF_NAME(oi)); | |
5027 | } else | |
5028 | vty_out(vty, " In the area %s via interface %s\n", | |
5029 | ospf_area_desc_string(oi->area), IF_NAME(oi)); | |
5030 | ||
5031 | /* Show neighbor priority and state. */ | |
5032 | if (use_json) { | |
5033 | json_object_int_add(json_sub, "nbrPriority", | |
5034 | nbr_nbma->priority); | |
5035 | json_object_string_add(json_sub, "nbrState", "down"); | |
5036 | } else | |
5037 | vty_out(vty, " Neighbor priority is %d, State is %s,", | |
5038 | nbr_nbma->priority, "Down"); | |
5039 | ||
5040 | /* Show state changes. */ | |
5041 | if (use_json) | |
5042 | json_object_int_add(json_sub, "stateChangeCounter", | |
5043 | nbr_nbma->state_change); | |
5044 | else | |
5045 | vty_out(vty, " %d state changes\n", nbr_nbma->state_change); | |
5046 | ||
5047 | /* Show PollInterval */ | |
5048 | if (use_json) | |
5049 | json_object_int_add(json_sub, "pollInterval", nbr_nbma->v_poll); | |
5050 | else | |
5051 | vty_out(vty, " Poll interval %d\n", nbr_nbma->v_poll); | |
5052 | ||
5053 | /* Show poll-interval timer. */ | |
b575a12c A |
5054 | if (nbr_nbma->t_poll) { |
5055 | if (use_json) { | |
5056 | long time_store; | |
5057 | time_store = monotime_until(&nbr_nbma->t_poll->u.sands, | |
5058 | NULL) / 1000LL; | |
5059 | json_object_int_add(json_sub, | |
5060 | "pollIntervalTimerDueMsec", | |
5061 | time_store); | |
5062 | } else | |
5063 | vty_out(vty, " Poll timer due in %s\n", | |
5064 | ospf_timer_dump(nbr_nbma->t_poll, timebuf, | |
5065 | sizeof(timebuf))); | |
5066 | } | |
d62a17ae | 5067 | |
5068 | /* Show poll-interval timer thread. */ | |
5069 | if (use_json) { | |
5070 | if (nbr_nbma->t_poll != NULL) | |
5071 | json_object_string_add(json_sub, | |
5072 | "pollIntervalTimerThread", "on"); | |
5073 | } else | |
5074 | vty_out(vty, " Thread Poll Timer %s\n", | |
5075 | nbr_nbma->t_poll != NULL ? "on" : "off"); | |
5076 | ||
5077 | if (use_json) | |
5078 | json_object_object_add(json, "noNbrId", json_sub); | |
5079 | } | |
5080 | ||
5081 | static void show_ip_ospf_neighbor_detail_sub(struct vty *vty, | |
5082 | struct ospf_interface *oi, | |
5083 | struct ospf_neighbor *nbr, | |
cb0b2ac6 | 5084 | struct ospf_neighbor *prev_nbr, |
9f049418 | 5085 | json_object *json, bool use_json) |
d62a17ae | 5086 | { |
5087 | char timebuf[OSPF_TIME_DUMP_SIZE]; | |
cb0b2ac6 CS |
5088 | json_object *json_neigh = NULL, *json_neigh_array = NULL; |
5089 | char neigh_str[INET_ADDRSTRLEN] = {0}; | |
41710ed1 | 5090 | char neigh_state[16] = {0}; |
d62a17ae | 5091 | |
cb0b2ac6 CS |
5092 | if (use_json) { |
5093 | if (prev_nbr && | |
5094 | !IPV4_ADDR_SAME(&prev_nbr->src, &nbr->src)) { | |
5095 | json_neigh_array = NULL; | |
5096 | } | |
5097 | ||
975a328e DA |
5098 | if (nbr->state == NSM_Attempt |
5099 | && nbr->router_id.s_addr == INADDR_ANY) | |
cb0b2ac6 CS |
5100 | strlcpy(neigh_str, "noNbrId", sizeof(neigh_str)); |
5101 | else | |
96b663a3 MS |
5102 | inet_ntop(AF_INET, &nbr->router_id, |
5103 | neigh_str, sizeof(neigh_str)); | |
cb0b2ac6 CS |
5104 | |
5105 | json_object_object_get_ex(json, neigh_str, &json_neigh_array); | |
5106 | ||
5107 | if (!json_neigh_array) { | |
5108 | json_neigh_array = json_object_new_array(); | |
5109 | json_object_object_add(json, neigh_str, | |
5110 | json_neigh_array); | |
5111 | } | |
5112 | ||
5113 | json_neigh = json_object_new_object(); | |
5114 | ||
5115 | } else { | |
d62a17ae | 5116 | /* Show neighbor ID. */ |
975a328e DA |
5117 | if (nbr->state == NSM_Attempt |
5118 | && nbr->router_id.s_addr == INADDR_ANY) | |
d62a17ae | 5119 | vty_out(vty, " Neighbor %s,", "-"); |
5120 | else | |
96b663a3 MS |
5121 | vty_out(vty, " Neighbor %pI4,", |
5122 | &nbr->router_id); | |
d62a17ae | 5123 | } |
5124 | ||
5125 | /* Show interface address. */ | |
5126 | if (use_json) | |
20308be3 DA |
5127 | json_object_string_addf(json_neigh, "ifaceAddress", "%pI4", |
5128 | &nbr->address.u.prefix4); | |
d62a17ae | 5129 | else |
96b663a3 MS |
5130 | vty_out(vty, " interface address %pI4\n", |
5131 | &nbr->address.u.prefix4); | |
d62a17ae | 5132 | |
5133 | /* Show Area ID. */ | |
5134 | if (use_json) { | |
cb0b2ac6 | 5135 | json_object_string_add(json_neigh, "areaId", |
d62a17ae | 5136 | ospf_area_desc_string(oi->area)); |
cb0b2ac6 | 5137 | json_object_string_add(json_neigh, "ifaceName", oi->ifp->name); |
d62a17ae | 5138 | } else |
5139 | vty_out(vty, " In the area %s via interface %s\n", | |
5140 | ospf_area_desc_string(oi->area), oi->ifp->name); | |
5141 | ||
5142 | /* Show neighbor priority and state. */ | |
41710ed1 | 5143 | ospf_nbr_ism_state_message(nbr, neigh_state, sizeof(neigh_state)); |
d62a17ae | 5144 | if (use_json) { |
cb0b2ac6 | 5145 | json_object_int_add(json_neigh, "nbrPriority", nbr->priority); |
41710ed1 | 5146 | json_object_string_add(json_neigh, "nbrState", neigh_state); |
d62a17ae | 5147 | } else |
5148 | vty_out(vty, " Neighbor priority is %d, State is %s,", | |
41710ed1 | 5149 | nbr->priority, neigh_state); |
d62a17ae | 5150 | |
5151 | /* Show state changes. */ | |
5152 | if (use_json) | |
cb0b2ac6 | 5153 | json_object_int_add(json_neigh, "stateChangeCounter", |
d62a17ae | 5154 | nbr->state_change); |
5155 | else | |
5156 | vty_out(vty, " %d state changes\n", nbr->state_change); | |
5157 | ||
5158 | if (nbr->ts_last_progress.tv_sec || nbr->ts_last_progress.tv_usec) { | |
5159 | struct timeval res; | |
5160 | long time_store; | |
5161 | ||
5162 | time_store = | |
5163 | monotime_since(&nbr->ts_last_progress, &res) / 1000LL; | |
5164 | if (use_json) { | |
cb0b2ac6 | 5165 | json_object_int_add(json_neigh, "lastPrgrsvChangeMsec", |
d62a17ae | 5166 | time_store); |
5167 | } else { | |
5168 | vty_out(vty, | |
5169 | " Most recent state change statistics:\n"); | |
5170 | vty_out(vty, " Progressive change %s ago\n", | |
5171 | ospf_timeval_dump(&res, timebuf, | |
5172 | sizeof(timebuf))); | |
5173 | } | |
5174 | } | |
5175 | ||
5176 | if (nbr->ts_last_regress.tv_sec || nbr->ts_last_regress.tv_usec) { | |
5177 | struct timeval res; | |
5178 | long time_store; | |
5179 | ||
5180 | time_store = | |
5181 | monotime_since(&nbr->ts_last_regress, &res) / 1000LL; | |
5182 | if (use_json) { | |
cb0b2ac6 | 5183 | json_object_int_add(json_neigh, |
d62a17ae | 5184 | "lastRegressiveChangeMsec", |
5185 | time_store); | |
5186 | if (nbr->last_regress_str) | |
5187 | json_object_string_add( | |
cb0b2ac6 CS |
5188 | json_neigh, |
5189 | "lastRegressiveChangeReason", | |
d62a17ae | 5190 | nbr->last_regress_str); |
5191 | } else { | |
5192 | vty_out(vty, | |
5193 | " Regressive change %s ago, due to %s\n", | |
5194 | ospf_timeval_dump(&res, timebuf, | |
5195 | sizeof(timebuf)), | |
5196 | (nbr->last_regress_str ? nbr->last_regress_str | |
5197 | : "??")); | |
5198 | } | |
5199 | } | |
5200 | ||
5201 | /* Show Designated Rotuer ID. */ | |
5202 | if (use_json) | |
20308be3 DA |
5203 | json_object_string_addf(json_neigh, "routerDesignatedId", |
5204 | "%pI4", &nbr->d_router); | |
d62a17ae | 5205 | else |
96b663a3 | 5206 | vty_out(vty, " DR is %pI4,", &nbr->d_router); |
d62a17ae | 5207 | |
5208 | /* Show Backup Designated Rotuer ID. */ | |
5209 | if (use_json) | |
20308be3 DA |
5210 | json_object_string_addf(json_neigh, "routerDesignatedBackupId", |
5211 | "%pI4", &nbr->bd_router); | |
d62a17ae | 5212 | else |
96b663a3 | 5213 | vty_out(vty, " BDR is %pI4\n", &nbr->bd_router); |
d62a17ae | 5214 | |
5215 | /* Show options. */ | |
5216 | if (use_json) { | |
cb0b2ac6 CS |
5217 | json_object_int_add(json_neigh, "optionsCounter", nbr->options); |
5218 | json_object_string_add(json_neigh, "optionsList", | |
d62a17ae | 5219 | ospf_options_dump(nbr->options)); |
5220 | } else | |
5221 | vty_out(vty, " Options %d %s\n", nbr->options, | |
5222 | ospf_options_dump(nbr->options)); | |
5223 | ||
5224 | /* Show Router Dead interval timer. */ | |
5225 | if (use_json) { | |
5226 | if (nbr->t_inactivity) { | |
5227 | long time_store; | |
5228 | time_store = monotime_until(&nbr->t_inactivity->u.sands, | |
5229 | NULL) | |
5230 | / 1000LL; | |
cb0b2ac6 | 5231 | json_object_int_add(json_neigh, |
d62a17ae | 5232 | "routerDeadIntervalTimerDueMsec", |
5233 | time_store); | |
5234 | } else | |
5235 | json_object_int_add( | |
cb0b2ac6 CS |
5236 | json_neigh, |
5237 | "routerDeadIntervalTimerDueMsec", -1); | |
d62a17ae | 5238 | } else |
5239 | vty_out(vty, " Dead timer due in %s\n", | |
5240 | ospf_timer_dump(nbr->t_inactivity, timebuf, | |
5241 | sizeof(timebuf))); | |
5242 | ||
5243 | /* Show Database Summary list. */ | |
5244 | if (use_json) | |
cb0b2ac6 | 5245 | json_object_int_add(json_neigh, "databaseSummaryListCounter", |
d62a17ae | 5246 | ospf_db_summary_count(nbr)); |
5247 | else | |
5248 | vty_out(vty, " Database Summary List %d\n", | |
5249 | ospf_db_summary_count(nbr)); | |
5250 | ||
5251 | /* Show Link State Request list. */ | |
5252 | if (use_json) | |
cb0b2ac6 | 5253 | json_object_int_add(json_neigh, "linkStateRequestListCounter", |
d62a17ae | 5254 | ospf_ls_request_count(nbr)); |
5255 | else | |
5256 | vty_out(vty, " Link State Request List %ld\n", | |
5257 | ospf_ls_request_count(nbr)); | |
5258 | ||
5259 | /* Show Link State Retransmission list. */ | |
5260 | if (use_json) | |
cb0b2ac6 | 5261 | json_object_int_add(json_neigh, |
d62a17ae | 5262 | "linkStateRetransmissionListCounter", |
5263 | ospf_ls_retransmit_count(nbr)); | |
5264 | else | |
5265 | vty_out(vty, " Link State Retransmission List %ld\n", | |
5266 | ospf_ls_retransmit_count(nbr)); | |
5267 | ||
5268 | /* Show inactivity timer thread. */ | |
5269 | if (use_json) { | |
5270 | if (nbr->t_inactivity != NULL) | |
cb0b2ac6 | 5271 | json_object_string_add(json_neigh, |
d62a17ae | 5272 | "threadInactivityTimer", "on"); |
5273 | } else | |
5274 | vty_out(vty, " Thread Inactivity Timer %s\n", | |
5275 | nbr->t_inactivity != NULL ? "on" : "off"); | |
5276 | ||
5277 | /* Show Database Description retransmission thread. */ | |
5278 | if (use_json) { | |
5279 | if (nbr->t_db_desc != NULL) | |
5280 | json_object_string_add( | |
cb0b2ac6 | 5281 | json_neigh, |
d62a17ae | 5282 | "threadDatabaseDescriptionRetransmission", |
5283 | "on"); | |
5284 | } else | |
5285 | vty_out(vty, | |
5286 | " Thread Database Description Retransmision %s\n", | |
5287 | nbr->t_db_desc != NULL ? "on" : "off"); | |
5288 | ||
5289 | /* Show Link State Request Retransmission thread. */ | |
5290 | if (use_json) { | |
5291 | if (nbr->t_ls_req != NULL) | |
5292 | json_object_string_add( | |
cb0b2ac6 | 5293 | json_neigh, |
d62a17ae | 5294 | "threadLinkStateRequestRetransmission", "on"); |
5295 | } else | |
5296 | vty_out(vty, | |
5297 | " Thread Link State Request Retransmission %s\n", | |
5298 | nbr->t_ls_req != NULL ? "on" : "off"); | |
5299 | ||
5300 | /* Show Link State Update Retransmission thread. */ | |
5301 | if (use_json) { | |
5302 | if (nbr->t_ls_upd != NULL) | |
5303 | json_object_string_add( | |
cb0b2ac6 CS |
5304 | json_neigh, |
5305 | "threadLinkStateUpdateRetransmission", | |
d62a17ae | 5306 | "on"); |
5307 | } else | |
5308 | vty_out(vty, | |
5309 | " Thread Link State Update Retransmission %s\n\n", | |
5310 | nbr->t_ls_upd != NULL ? "on" : "off"); | |
5311 | ||
abd5b8c7 | 5312 | if (!use_json) { |
5313 | vty_out(vty, " Graceful restart Helper info:\n"); | |
5314 | ||
5315 | if (OSPF_GR_IS_ACTIVE_HELPER(nbr)) { | |
5316 | vty_out(vty, | |
5317 | " Graceful Restart HELPER Status : Inprogress.\n"); | |
5318 | ||
5319 | vty_out(vty, | |
5320 | " Graceful Restart grace period time: %d (seconds).\n", | |
5321 | nbr->gr_helper_info.recvd_grace_period); | |
5322 | vty_out(vty, " Graceful Restart reason: %s.\n", | |
d05d5280 MS |
5323 | ospf_restart_reason2str( |
5324 | nbr->gr_helper_info.gr_restart_reason)); | |
abd5b8c7 | 5325 | } else { |
5326 | vty_out(vty, | |
5327 | " Graceful Restart HELPER Status : None\n"); | |
5328 | } | |
5329 | ||
5330 | if (nbr->gr_helper_info.rejected_reason | |
5331 | != OSPF_HELPER_REJECTED_NONE) | |
5332 | vty_out(vty, " Helper rejected reason: %s.\n", | |
d05d5280 MS |
5333 | ospf_rejected_reason2str( |
5334 | nbr->gr_helper_info.rejected_reason)); | |
abd5b8c7 | 5335 | |
5336 | if (nbr->gr_helper_info.helper_exit_reason | |
5337 | != OSPF_GR_HELPER_EXIT_NONE) | |
5338 | vty_out(vty, " Last helper exit reason: %s.\n\n", | |
d05d5280 MS |
5339 | ospf_exit_reason2str( |
5340 | nbr->gr_helper_info.helper_exit_reason)); | |
abd5b8c7 | 5341 | else |
5342 | vty_out(vty, "\n"); | |
5343 | } else { | |
5344 | json_object_string_add(json_neigh, "grHelperStatus", | |
5345 | OSPF_GR_IS_ACTIVE_HELPER(nbr) ? | |
5346 | "Inprogress" | |
5347 | : "None"); | |
5348 | if (OSPF_GR_IS_ACTIVE_HELPER(nbr)) { | |
5349 | json_object_int_add( | |
5350 | json_neigh, "graceInterval", | |
5351 | nbr->gr_helper_info.recvd_grace_period); | |
5352 | json_object_string_add( | |
5353 | json_neigh, "grRestartReason", | |
d05d5280 MS |
5354 | ospf_restart_reason2str( |
5355 | nbr->gr_helper_info.gr_restart_reason)); | |
abd5b8c7 | 5356 | } |
5357 | ||
5358 | if (nbr->gr_helper_info.rejected_reason | |
5359 | != OSPF_HELPER_REJECTED_NONE) | |
5360 | json_object_string_add( | |
5361 | json_neigh, "helperRejectReason", | |
d05d5280 MS |
5362 | ospf_rejected_reason2str( |
5363 | nbr->gr_helper_info.rejected_reason)); | |
abd5b8c7 | 5364 | |
5365 | if (nbr->gr_helper_info.helper_exit_reason | |
5366 | != OSPF_GR_HELPER_EXIT_NONE) | |
5367 | json_object_string_add( | |
5368 | json_neigh, "helperExitReason", | |
d05d5280 MS |
5369 | ospf_exit_reason2str( |
5370 | nbr->gr_helper_info | |
5371 | .helper_exit_reason)); | |
abd5b8c7 | 5372 | } |
5373 | ||
659f4e40 | 5374 | bfd_sess_show(vty, json_neigh, nbr->bfd_session); |
cb0b2ac6 CS |
5375 | |
5376 | if (use_json) | |
5377 | json_object_array_add(json_neigh_array, json_neigh); | |
d62a17ae | 5378 | |
d62a17ae | 5379 | } |
5380 | ||
5381 | static int show_ip_ospf_neighbor_id_common(struct vty *vty, struct ospf *ospf, | |
986b87cb | 5382 | struct in_addr *router_id, |
e8a8b116 | 5383 | bool use_json, uint8_t use_vrf, |
5384 | bool is_detail) | |
d62a17ae | 5385 | { |
5386 | struct listnode *node; | |
5387 | struct ospf_neighbor *nbr; | |
5388 | struct ospf_interface *oi; | |
d62a17ae | 5389 | json_object *json = NULL; |
5390 | ||
5391 | if (use_json) | |
5392 | json = json_object_new_object(); | |
5393 | ||
5394 | if (ospf->instance) { | |
5395 | if (use_json) | |
5396 | json_object_int_add(json, "ospfInstance", | |
5397 | ospf->instance); | |
5398 | else | |
5399 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
5400 | } | |
5401 | ||
b1c3ae8c | 5402 | ospf_show_vrf_name(ospf, vty, json, use_vrf); |
87bd50e8 | 5403 | |
d62a17ae | 5404 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) { |
986b87cb | 5405 | if ((nbr = ospf_nbr_lookup_by_routerid(oi->nbrs, router_id))) { |
e8a8b116 | 5406 | if (is_detail) |
5407 | show_ip_ospf_neighbor_detail_sub( | |
5408 | vty, oi, nbr, NULL, json, use_json); | |
5409 | else | |
5410 | show_ip_ospf_neighbour_brief(vty, nbr, NULL, | |
5411 | json, use_json); | |
d62a17ae | 5412 | } |
5413 | } | |
5414 | ||
c48349e3 | 5415 | if (use_json) |
92ef0078 | 5416 | vty_json(vty, json); |
c48349e3 | 5417 | else |
d62a17ae | 5418 | vty_out(vty, "\n"); |
5419 | ||
5420 | return CMD_SUCCESS; | |
718e3744 | 5421 | } |
5422 | ||
e8a8b116 | 5423 | DEFPY(show_ip_ospf_neighbor_id, show_ip_ospf_neighbor_id_cmd, |
5424 | "show ip ospf neighbor A.B.C.D$router_id [detail$detail] [json$json]", | |
5425 | SHOW_STR IP_STR | |
5426 | "OSPF information\n" | |
5427 | "Neighbor list\n" | |
5428 | "Neighbor ID\n" | |
5429 | "Detailed output\n" JSON_STR) | |
718e3744 | 5430 | { |
d62a17ae | 5431 | struct ospf *ospf; |
986b87cb | 5432 | struct listnode *node; |
b5a8894d | 5433 | int ret = CMD_SUCCESS; |
7c8ff89e | 5434 | |
b5a8894d CS |
5435 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { |
5436 | if (!ospf->oi_running) | |
5437 | continue; | |
986b87cb | 5438 | ret = show_ip_ospf_neighbor_id_common(vty, ospf, &router_id, |
e8a8b116 | 5439 | !!json, 0, !!detail); |
b5a8894d | 5440 | } |
7c8ff89e | 5441 | |
b5a8894d | 5442 | return ret; |
7c8ff89e DS |
5443 | } |
5444 | ||
e8a8b116 | 5445 | DEFPY(show_ip_ospf_instance_neighbor_id, show_ip_ospf_instance_neighbor_id_cmd, |
5446 | "show ip ospf (1-65535)$instance neighbor A.B.C.D$router_id [detail$detail] [json$json]", | |
5447 | SHOW_STR IP_STR | |
5448 | "OSPF information\n" | |
5449 | "Instance ID\n" | |
5450 | "Neighbor list\n" | |
5451 | "Neighbor ID\n" | |
5452 | "Detailed output\n" JSON_STR) | |
7c8ff89e | 5453 | { |
d62a17ae | 5454 | struct ospf *ospf; |
7c8ff89e | 5455 | |
409f98ab | 5456 | if (instance != ospf_instance) |
ac28e4ec CS |
5457 | return CMD_NOT_MY_INSTANCE; |
5458 | ||
409f98ab IR |
5459 | ospf = ospf_lookup_instance(instance); |
5460 | if (!ospf || !ospf->oi_running) | |
d62a17ae | 5461 | return CMD_SUCCESS; |
7c8ff89e | 5462 | |
e8a8b116 | 5463 | return show_ip_ospf_neighbor_id_common(vty, ospf, &router_id, !!json, 0, |
5464 | !!detail); | |
7c8ff89e DS |
5465 | } |
5466 | ||
d62a17ae | 5467 | static int show_ip_ospf_neighbor_detail_common(struct vty *vty, |
5468 | struct ospf *ospf, | |
9f049418 | 5469 | json_object *json, bool use_json, |
d7c0a89a | 5470 | uint8_t use_vrf) |
d62a17ae | 5471 | { |
5472 | struct ospf_interface *oi; | |
5473 | struct listnode *node; | |
b1c3ae8c | 5474 | json_object *json_vrf = NULL; |
cb0b2ac6 | 5475 | json_object *json_nbr_sub = NULL; |
d62a17ae | 5476 | |
b1c3ae8c CS |
5477 | if (use_json) { |
5478 | if (use_vrf) | |
5479 | json_vrf = json_object_new_object(); | |
5480 | else | |
5481 | json_vrf = json; | |
cb0b2ac6 CS |
5482 | |
5483 | json_nbr_sub = json_object_new_object(); | |
b1c3ae8c | 5484 | } |
cb0b2ac6 | 5485 | |
d62a17ae | 5486 | if (ospf->instance) { |
5487 | if (use_json) | |
cb0b2ac6 | 5488 | json_object_int_add(json, "ospfInstance", |
d62a17ae | 5489 | ospf->instance); |
5490 | else | |
5491 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
5492 | } | |
5493 | ||
b1c3ae8c | 5494 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); |
87bd50e8 | 5495 | |
d62a17ae | 5496 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) { |
5497 | struct route_node *rn; | |
cb0b2ac6 | 5498 | struct ospf_neighbor *nbr, *prev_nbr = NULL; |
d62a17ae | 5499 | |
5500 | for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) { | |
5501 | if ((nbr = rn->info)) { | |
5502 | if (nbr != oi->nbr_self) { | |
5503 | if (nbr->state != NSM_Down) { | |
5504 | show_ip_ospf_neighbor_detail_sub( | |
cb0b2ac6 CS |
5505 | vty, oi, nbr, prev_nbr, |
5506 | json_nbr_sub, use_json); | |
d62a17ae | 5507 | } |
5508 | } | |
cb0b2ac6 | 5509 | prev_nbr = nbr; |
d62a17ae | 5510 | } |
5511 | } | |
5512 | } | |
5513 | ||
5514 | if (use_json) { | |
cb0b2ac6 CS |
5515 | json_object_object_add(json_vrf, "neighbors", |
5516 | json_nbr_sub); | |
44076f4d RW |
5517 | if (use_vrf) |
5518 | json_object_object_add(json, ospf_get_name(ospf), | |
5519 | json_vrf); | |
d62a17ae | 5520 | } else |
5521 | vty_out(vty, "\n"); | |
5522 | ||
5523 | return CMD_SUCCESS; | |
718e3744 | 5524 | } |
5525 | ||
7c8ff89e DS |
5526 | DEFUN (show_ip_ospf_neighbor_detail, |
5527 | show_ip_ospf_neighbor_detail_cmd, | |
b5a8894d | 5528 | "show ip ospf [vrf <NAME|all>] neighbor detail [json]", |
718e3744 | 5529 | SHOW_STR |
5530 | IP_STR | |
5531 | "OSPF information\n" | |
b5a8894d CS |
5532 | VRF_CMD_HELP_STR |
5533 | "All VRFs\n" | |
718e3744 | 5534 | "Neighbor list\n" |
3ac237f8 | 5535 | "detail of all neighbors\n" |
9973d184 | 5536 | JSON_STR) |
718e3744 | 5537 | { |
d62a17ae | 5538 | struct ospf *ospf; |
9f049418 | 5539 | bool uj = use_json(argc, argv); |
b5a8894d CS |
5540 | struct listnode *node = NULL; |
5541 | char *vrf_name = NULL; | |
2951a7a4 | 5542 | bool all_vrf = false; |
b5a8894d CS |
5543 | int ret = CMD_SUCCESS; |
5544 | int inst = 0; | |
5545 | int idx_vrf = 0; | |
d7c0a89a | 5546 | uint8_t use_vrf = 0; |
b1c3ae8c | 5547 | json_object *json = NULL; |
7c8ff89e | 5548 | |
43b8d1d8 | 5549 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
7c8ff89e | 5550 | |
b1c3ae8c CS |
5551 | if (uj) |
5552 | json = json_object_new_object(); | |
5553 | ||
b5a8894d CS |
5554 | /* vrf input is provided could be all or specific vrf*/ |
5555 | if (vrf_name) { | |
b1c3ae8c | 5556 | use_vrf = 1; |
b5a8894d CS |
5557 | if (all_vrf) { |
5558 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
5559 | if (!ospf->oi_running) | |
5560 | continue; | |
996c9314 LB |
5561 | ret = show_ip_ospf_neighbor_detail_common( |
5562 | vty, ospf, json, uj, use_vrf); | |
b1c3ae8c | 5563 | } |
c48349e3 | 5564 | if (uj) |
92ef0078 | 5565 | vty_json(vty, json); |
b1c3ae8c | 5566 | |
b5a8894d CS |
5567 | return ret; |
5568 | } | |
5569 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
b1c3ae8c CS |
5570 | if (ospf == NULL || !ospf->oi_running) { |
5571 | if (uj) | |
5572 | json_object_free(json); | |
b5a8894d | 5573 | return CMD_SUCCESS; |
b1c3ae8c | 5574 | } |
b5a8894d CS |
5575 | } else { |
5576 | /* Display default ospf (instance 0) info */ | |
5577 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
b1c3ae8c CS |
5578 | if (ospf == NULL || !ospf->oi_running) { |
5579 | if (uj) | |
5580 | json_object_free(json); | |
b5a8894d | 5581 | return CMD_SUCCESS; |
b1c3ae8c | 5582 | } |
b5a8894d CS |
5583 | } |
5584 | ||
b1c3ae8c CS |
5585 | if (ospf) { |
5586 | ret = show_ip_ospf_neighbor_detail_common(vty, ospf, json, uj, | |
5587 | use_vrf); | |
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 CS |
5592 | } |
5593 | } | |
5594 | ||
5595 | if (uj) | |
5596 | json_object_free(json); | |
b5a8894d CS |
5597 | |
5598 | return ret; | |
7c8ff89e DS |
5599 | } |
5600 | ||
5601 | DEFUN (show_ip_ospf_instance_neighbor_detail, | |
5602 | show_ip_ospf_instance_neighbor_detail_cmd, | |
6147e2c6 | 5603 | "show ip ospf (1-65535) neighbor detail [json]", |
7c8ff89e DS |
5604 | SHOW_STR |
5605 | IP_STR | |
5606 | "OSPF information\n" | |
5607 | "Instance ID\n" | |
5608 | "Neighbor list\n" | |
3ac237f8 | 5609 | "detail of all neighbors\n" |
9973d184 | 5610 | JSON_STR) |
7c8ff89e | 5611 | { |
d62a17ae | 5612 | int idx_number = 3; |
5613 | struct ospf *ospf; | |
d7c0a89a | 5614 | unsigned short instance = 0; |
9f049418 | 5615 | bool uj = use_json(argc, argv); |
b1c3ae8c CS |
5616 | json_object *json = NULL; |
5617 | int ret = CMD_SUCCESS; | |
7c8ff89e | 5618 | |
d62a17ae | 5619 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
409f98ab | 5620 | if (instance != ospf_instance) |
ac28e4ec CS |
5621 | return CMD_NOT_MY_INSTANCE; |
5622 | ||
409f98ab IR |
5623 | ospf = ospf_lookup_instance(instance); |
5624 | if (!ospf || !ospf->oi_running) | |
d62a17ae | 5625 | return CMD_SUCCESS; |
7c8ff89e | 5626 | |
b1c3ae8c CS |
5627 | if (uj) |
5628 | json = json_object_new_object(); | |
5629 | ||
5630 | ret = show_ip_ospf_neighbor_detail_common(vty, ospf, json, uj, 0); | |
5631 | ||
c48349e3 | 5632 | if (uj) |
92ef0078 | 5633 | vty_json(vty, json); |
b1c3ae8c CS |
5634 | |
5635 | return ret; | |
7c8ff89e DS |
5636 | } |
5637 | ||
d62a17ae | 5638 | static int show_ip_ospf_neighbor_detail_all_common(struct vty *vty, |
5639 | struct ospf *ospf, | |
b1c3ae8c | 5640 | json_object *json, |
9f049418 | 5641 | bool use_json, |
d7c0a89a | 5642 | uint8_t use_vrf) |
d62a17ae | 5643 | { |
5644 | struct listnode *node; | |
5645 | struct ospf_interface *oi; | |
b1c3ae8c | 5646 | json_object *json_vrf = NULL; |
718e3744 | 5647 | |
b1c3ae8c CS |
5648 | if (use_json) { |
5649 | if (use_vrf) | |
5650 | json_vrf = json_object_new_object(); | |
5651 | else | |
5652 | json_vrf = json; | |
5653 | } | |
d62a17ae | 5654 | |
5655 | if (ospf->instance) { | |
5656 | if (use_json) | |
5657 | json_object_int_add(json, "ospfInstance", | |
5658 | ospf->instance); | |
5659 | else | |
5660 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
5661 | } | |
5662 | ||
b1c3ae8c | 5663 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); |
87bd50e8 | 5664 | |
d62a17ae | 5665 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) { |
5666 | struct route_node *rn; | |
cb0b2ac6 | 5667 | struct ospf_neighbor *nbr, *prev_nbr = NULL; |
d62a17ae | 5668 | struct ospf_nbr_nbma *nbr_nbma; |
5669 | ||
cb0b2ac6 CS |
5670 | for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) { |
5671 | if ((nbr = rn->info)) { | |
d62a17ae | 5672 | if (nbr != oi->nbr_self) |
5673 | if (nbr->state != NSM_Down) | |
5674 | show_ip_ospf_neighbor_detail_sub( | |
5675 | vty, oi, rn->info, | |
cb0b2ac6 | 5676 | prev_nbr, |
b1c3ae8c | 5677 | json_vrf, use_json); |
cb0b2ac6 CS |
5678 | prev_nbr = nbr; |
5679 | } | |
5680 | } | |
d62a17ae | 5681 | |
5682 | if (oi->type == OSPF_IFTYPE_NBMA) { | |
5683 | struct listnode *nd; | |
5684 | ||
5685 | for (ALL_LIST_ELEMENTS_RO(oi->nbr_nbma, nd, nbr_nbma)) { | |
5686 | if (nbr_nbma->nbr == NULL | |
5687 | || nbr_nbma->nbr->state == NSM_Down) | |
5688 | show_ip_ospf_nbr_nbma_detail_sub( | |
5689 | vty, oi, nbr_nbma, use_json, | |
b1c3ae8c | 5690 | json_vrf); |
d62a17ae | 5691 | } |
5692 | } | |
5693 | } | |
5694 | ||
5695 | if (use_json) { | |
44076f4d RW |
5696 | if (use_vrf) |
5697 | json_object_object_add(json, ospf_get_name(ospf), | |
5698 | json_vrf); | |
d62a17ae | 5699 | } else { |
5700 | vty_out(vty, "\n"); | |
5701 | } | |
5702 | ||
5703 | return CMD_SUCCESS; | |
718e3744 | 5704 | } |
5705 | ||
7c8ff89e DS |
5706 | DEFUN (show_ip_ospf_neighbor_detail_all, |
5707 | show_ip_ospf_neighbor_detail_all_cmd, | |
b5a8894d | 5708 | "show ip ospf [vrf <NAME|all>] neighbor detail all [json]", |
718e3744 | 5709 | SHOW_STR |
5710 | IP_STR | |
5711 | "OSPF information\n" | |
b5a8894d CS |
5712 | VRF_CMD_HELP_STR |
5713 | "All VRFs\n" | |
718e3744 | 5714 | "Neighbor list\n" |
7c8ff89e | 5715 | "detail of all neighbors\n" |
3ac237f8 | 5716 | "include down status neighbor\n" |
9973d184 | 5717 | JSON_STR) |
718e3744 | 5718 | { |
d62a17ae | 5719 | struct ospf *ospf; |
9f049418 | 5720 | bool uj = use_json(argc, argv); |
b5a8894d CS |
5721 | struct listnode *node = NULL; |
5722 | char *vrf_name = NULL; | |
2951a7a4 | 5723 | bool all_vrf = false; |
b5a8894d CS |
5724 | int ret = CMD_SUCCESS; |
5725 | int inst = 0; | |
5726 | int idx_vrf = 0; | |
d7c0a89a | 5727 | uint8_t use_vrf = 0; |
b1c3ae8c | 5728 | json_object *json = NULL; |
7c8ff89e | 5729 | |
43b8d1d8 | 5730 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
7c8ff89e | 5731 | |
b1c3ae8c CS |
5732 | if (uj) |
5733 | json = json_object_new_object(); | |
5734 | ||
b5a8894d CS |
5735 | /* vrf input is provided could be all or specific vrf*/ |
5736 | if (vrf_name) { | |
b1c3ae8c | 5737 | use_vrf = 1; |
b5a8894d CS |
5738 | if (all_vrf) { |
5739 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
5740 | if (!ospf->oi_running) | |
5741 | continue; | |
996c9314 LB |
5742 | ret = show_ip_ospf_neighbor_detail_all_common( |
5743 | vty, ospf, json, uj, use_vrf); | |
b5a8894d | 5744 | } |
b1c3ae8c | 5745 | |
c48349e3 | 5746 | if (uj) |
92ef0078 | 5747 | vty_json(vty, json); |
b1c3ae8c | 5748 | |
b5a8894d CS |
5749 | return ret; |
5750 | } | |
5751 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
b1c3ae8c CS |
5752 | if (ospf == NULL || !ospf->oi_running) { |
5753 | if (uj) | |
5754 | json_object_free(json); | |
b5a8894d | 5755 | return CMD_SUCCESS; |
b1c3ae8c | 5756 | } |
b5a8894d CS |
5757 | } else { |
5758 | /* Display default ospf (instance 0) info */ | |
5759 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
b1c3ae8c CS |
5760 | if (ospf == NULL || !ospf->oi_running) { |
5761 | if (uj) | |
5762 | json_object_free(json); | |
b5a8894d | 5763 | return CMD_SUCCESS; |
b1c3ae8c | 5764 | } |
b5a8894d CS |
5765 | } |
5766 | ||
b1c3ae8c CS |
5767 | if (ospf) { |
5768 | ret = show_ip_ospf_neighbor_detail_all_common(vty, ospf, json, | |
5769 | uj, use_vrf); | |
5770 | if (uj) { | |
5771 | vty_out(vty, "%s\n", | |
996c9314 LB |
5772 | json_object_to_json_string_ext( |
5773 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c CS |
5774 | } |
5775 | } | |
5776 | ||
5777 | if (uj) | |
5778 | json_object_free(json); | |
b5a8894d CS |
5779 | |
5780 | return ret; | |
7c8ff89e DS |
5781 | } |
5782 | ||
5783 | DEFUN (show_ip_ospf_instance_neighbor_detail_all, | |
5784 | show_ip_ospf_instance_neighbor_detail_all_cmd, | |
6147e2c6 | 5785 | "show ip ospf (1-65535) neighbor detail all [json]", |
7c8ff89e DS |
5786 | SHOW_STR |
5787 | IP_STR | |
5788 | "OSPF information\n" | |
5789 | "Instance ID\n" | |
5790 | "Neighbor list\n" | |
5791 | "detail of all neighbors\n" | |
3ac237f8 | 5792 | "include down status neighbor\n" |
9973d184 | 5793 | JSON_STR) |
7c8ff89e | 5794 | { |
d62a17ae | 5795 | int idx_number = 3; |
5796 | struct ospf *ospf; | |
d7c0a89a | 5797 | unsigned short instance = 0; |
9f049418 | 5798 | bool uj = use_json(argc, argv); |
b1c3ae8c CS |
5799 | json_object *json = NULL; |
5800 | int ret = CMD_SUCCESS; | |
7c8ff89e | 5801 | |
d62a17ae | 5802 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
409f98ab | 5803 | if (instance != ospf_instance) |
ac28e4ec CS |
5804 | return CMD_NOT_MY_INSTANCE; |
5805 | ||
409f98ab IR |
5806 | ospf = ospf_lookup_instance(instance); |
5807 | if (!ospf || !ospf->oi_running) | |
d62a17ae | 5808 | return CMD_SUCCESS; |
7c8ff89e | 5809 | |
b1c3ae8c CS |
5810 | if (uj) |
5811 | json = json_object_new_object(); | |
5812 | ||
5813 | ret = show_ip_ospf_neighbor_detail_all_common(vty, ospf, json, uj, 0); | |
5814 | ||
c48349e3 | 5815 | if (uj) |
92ef0078 | 5816 | vty_json(vty, json); |
b1c3ae8c CS |
5817 | |
5818 | return ret; | |
7c8ff89e DS |
5819 | } |
5820 | ||
d62a17ae | 5821 | static int show_ip_ospf_neighbor_int_detail_common(struct vty *vty, |
5822 | struct ospf *ospf, | |
5823 | int arg_base, | |
5824 | struct cmd_token **argv, | |
9f049418 | 5825 | bool use_json) |
d62a17ae | 5826 | { |
5827 | struct ospf_interface *oi; | |
5828 | struct interface *ifp; | |
5829 | struct route_node *rn, *nrn; | |
5830 | struct ospf_neighbor *nbr; | |
5831 | json_object *json = NULL; | |
718e3744 | 5832 | |
d62a17ae | 5833 | if (use_json) |
5834 | json = json_object_new_object(); | |
5835 | ||
5836 | if (ospf->instance) { | |
5837 | if (use_json) | |
5838 | json_object_int_add(json, "ospfInstance", | |
5839 | ospf->instance); | |
5840 | else | |
5841 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
5842 | } | |
5843 | ||
a36898e7 | 5844 | ifp = if_lookup_by_name(argv[arg_base]->arg, ospf->vrf_id); |
d62a17ae | 5845 | if (!ifp) { |
5846 | if (!use_json) | |
5847 | vty_out(vty, "No such interface.\n"); | |
16307668 RW |
5848 | else { |
5849 | vty_out(vty, "{}\n"); | |
5850 | json_object_free(json); | |
5851 | } | |
d62a17ae | 5852 | return CMD_WARNING; |
5853 | } | |
5854 | ||
5855 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { | |
5856 | if ((oi = rn->info)) { | |
5857 | for (nrn = route_top(oi->nbrs); nrn; | |
5858 | nrn = route_next(nrn)) { | |
5859 | if ((nbr = nrn->info)) { | |
5860 | if (nbr != oi->nbr_self) { | |
5861 | if (nbr->state != NSM_Down) | |
5862 | show_ip_ospf_neighbor_detail_sub( | |
5863 | vty, oi, nbr, | |
cb0b2ac6 | 5864 | NULL, |
b1c3ae8c | 5865 | json, use_json); |
d62a17ae | 5866 | } |
5867 | } | |
5868 | } | |
5869 | } | |
5870 | } | |
5871 | ||
c48349e3 | 5872 | if (use_json) |
92ef0078 | 5873 | vty_json(vty, json); |
c48349e3 | 5874 | else |
d62a17ae | 5875 | vty_out(vty, "\n"); |
5876 | ||
5877 | return CMD_SUCCESS; | |
718e3744 | 5878 | } |
5879 | ||
7c8ff89e DS |
5880 | DEFUN (show_ip_ospf_neighbor_int_detail, |
5881 | show_ip_ospf_neighbor_int_detail_cmd, | |
b162fa78 | 5882 | "show ip ospf neighbor IFNAME detail [json]", |
7c8ff89e DS |
5883 | SHOW_STR |
5884 | IP_STR | |
5885 | "OSPF information\n" | |
5886 | "Neighbor list\n" | |
5887 | "Interface name\n" | |
3ac237f8 | 5888 | "detail of all neighbors\n" |
9973d184 | 5889 | JSON_STR) |
7c8ff89e | 5890 | { |
d62a17ae | 5891 | struct ospf *ospf; |
9f049418 | 5892 | bool uj = use_json(argc, argv); |
b5a8894d CS |
5893 | struct listnode *node = NULL; |
5894 | int ret = CMD_SUCCESS; | |
2951a7a4 | 5895 | bool ospf_output = false; |
7c8ff89e | 5896 | |
b5a8894d CS |
5897 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { |
5898 | if (!ospf->oi_running) | |
5899 | continue; | |
2951a7a4 | 5900 | ospf_output = true; |
cb0b2ac6 | 5901 | ret = show_ip_ospf_neighbor_int_detail_common(vty, ospf, 4, |
b5a8894d CS |
5902 | argv, uj); |
5903 | } | |
7c8ff89e | 5904 | |
9f049418 DS |
5905 | if (!ospf_output) |
5906 | vty_out(vty, "%% OSPF instance not found\n"); | |
5907 | ||
b5a8894d | 5908 | return ret; |
7c8ff89e DS |
5909 | } |
5910 | ||
5911 | DEFUN (show_ip_ospf_instance_neighbor_int_detail, | |
5912 | show_ip_ospf_instance_neighbor_int_detail_cmd, | |
6147e2c6 | 5913 | "show ip ospf (1-65535) neighbor IFNAME detail [json]", |
7c8ff89e DS |
5914 | SHOW_STR |
5915 | IP_STR | |
5916 | "OSPF information\n" | |
5917 | "Instance ID\n" | |
5918 | "Neighbor list\n" | |
5919 | "Interface name\n" | |
3ac237f8 | 5920 | "detail of all neighbors\n" |
9973d184 | 5921 | JSON_STR) |
7c8ff89e | 5922 | { |
d62a17ae | 5923 | int idx_number = 3; |
b4e84315 | 5924 | int idx_ifname = 5; |
d62a17ae | 5925 | struct ospf *ospf; |
d7c0a89a | 5926 | unsigned short instance = 0; |
9f049418 | 5927 | bool uj = use_json(argc, argv); |
7c8ff89e | 5928 | |
d62a17ae | 5929 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
409f98ab | 5930 | if (instance != ospf_instance) |
ac28e4ec CS |
5931 | return CMD_NOT_MY_INSTANCE; |
5932 | ||
409f98ab IR |
5933 | ospf = ospf_lookup_instance(instance); |
5934 | if (!ospf || !ospf->oi_running) | |
d62a17ae | 5935 | return CMD_SUCCESS; |
7c8ff89e | 5936 | |
996c9314 LB |
5937 | return show_ip_ospf_neighbor_int_detail_common(vty, ospf, idx_ifname, |
5938 | argv, uj); | |
7c8ff89e | 5939 | } |
6b0655a2 | 5940 | |
718e3744 | 5941 | /* Show functions */ |
f328dc60 | 5942 | static int show_lsa_summary(struct vty *vty, struct ospf_lsa *lsa, int self, |
5943 | json_object *json_lsa) | |
d62a17ae | 5944 | { |
5945 | struct router_lsa *rl; | |
5946 | struct summary_lsa *sl; | |
5947 | struct as_external_lsa *asel; | |
5948 | struct prefix_ipv4 p; | |
5949 | ||
0fa6d92b | 5950 | if (lsa != NULL) { |
d62a17ae | 5951 | /* If self option is set, check LSA self flag. */ |
5952 | if (self == 0 || IS_LSA_SELF(lsa)) { | |
f328dc60 | 5953 | |
5954 | if (!json_lsa) { | |
5955 | /* LSA common part show. */ | |
5956 | vty_out(vty, "%-15pI4", | |
5957 | &lsa->data->id); | |
ce513ac6 MS |
5958 | vty_out(vty, "%-15pI4 %4d 0x%08lx 0x%04x", |
5959 | &lsa->data->adv_router, LS_AGE(lsa), | |
f328dc60 | 5960 | (unsigned long)ntohl( |
5961 | lsa->data->ls_seqnum), | |
5962 | ntohs(lsa->data->checksum)); | |
5963 | } else { | |
5964 | char seqnum[10]; | |
5965 | char checksum[10]; | |
5966 | ||
5967 | snprintf(seqnum, sizeof(seqnum), "%x", | |
5968 | ntohl(lsa->data->ls_seqnum)); | |
5969 | snprintf(checksum, sizeof(checksum), "%x", | |
5970 | ntohs(lsa->data->checksum)); | |
20308be3 DA |
5971 | json_object_string_addf(json_lsa, "lsId", |
5972 | "%pI4", &lsa->data->id); | |
5973 | json_object_string_addf( | |
5974 | json_lsa, "advertisedRouter", "%pI4", | |
5975 | &lsa->data->adv_router); | |
f328dc60 | 5976 | json_object_int_add(json_lsa, "lsaAge", |
5977 | LS_AGE(lsa)); | |
5978 | json_object_string_add( | |
5979 | json_lsa, "sequenceNumber", seqnum); | |
5980 | json_object_string_add(json_lsa, "checksum", | |
5981 | checksum); | |
5982 | } | |
5983 | ||
d62a17ae | 5984 | /* LSA specific part show. */ |
5985 | switch (lsa->data->type) { | |
5986 | case OSPF_ROUTER_LSA: | |
5987 | rl = (struct router_lsa *)lsa->data; | |
f328dc60 | 5988 | |
5989 | if (!json_lsa) | |
5990 | vty_out(vty, " %-d", ntohs(rl->links)); | |
5991 | else | |
5992 | json_object_int_add(json_lsa, | |
5993 | "numOfRouterLinks", | |
5994 | ntohs(rl->links)); | |
d62a17ae | 5995 | break; |
5996 | case OSPF_SUMMARY_LSA: | |
5997 | sl = (struct summary_lsa *)lsa->data; | |
5998 | ||
5999 | p.family = AF_INET; | |
6000 | p.prefix = sl->header.id; | |
6001 | p.prefixlen = ip_masklen(sl->mask); | |
6002 | apply_mask_ipv4(&p); | |
6003 | ||
f328dc60 | 6004 | if (!json_lsa) |
6005 | vty_out(vty, " %pFX", &p); | |
6006 | else { | |
d63f3ff7 DA |
6007 | json_object_string_addf( |
6008 | json_lsa, "summaryAddress", | |
6009 | "%pFX", &p); | |
f328dc60 | 6010 | } |
d62a17ae | 6011 | break; |
6012 | case OSPF_AS_EXTERNAL_LSA: | |
6013 | case OSPF_AS_NSSA_LSA: | |
6014 | asel = (struct as_external_lsa *)lsa->data; | |
6015 | ||
6016 | p.family = AF_INET; | |
6017 | p.prefix = asel->header.id; | |
6018 | p.prefixlen = ip_masklen(asel->mask); | |
6019 | apply_mask_ipv4(&p); | |
6020 | ||
f328dc60 | 6021 | if (!json_lsa) |
6022 | vty_out(vty, " %s %pFX [0x%lx]", | |
6023 | IS_EXTERNAL_METRIC( | |
6024 | asel->e[0].tos) | |
6025 | ? "E2" | |
6026 | : "E1", | |
6027 | &p, | |
6028 | (unsigned long)ntohl( | |
6029 | asel->e[0].route_tag)); | |
6030 | else { | |
f328dc60 | 6031 | json_object_string_add( |
6032 | json_lsa, "metricType", | |
6033 | IS_EXTERNAL_METRIC( | |
6034 | asel->e[0].tos) | |
6035 | ? "E2" | |
6036 | : "E1"); | |
d63f3ff7 DA |
6037 | json_object_string_addf( |
6038 | json_lsa, "route", "%pFX", &p); | |
f328dc60 | 6039 | json_object_int_add( |
6040 | json_lsa, "tag", | |
6041 | (unsigned long)ntohl( | |
6042 | asel->e[0].route_tag)); | |
6043 | } | |
d62a17ae | 6044 | break; |
6045 | case OSPF_NETWORK_LSA: | |
6046 | case OSPF_ASBR_SUMMARY_LSA: | |
6047 | case OSPF_OPAQUE_LINK_LSA: | |
6048 | case OSPF_OPAQUE_AREA_LSA: | |
6049 | case OSPF_OPAQUE_AS_LSA: | |
6050 | default: | |
6051 | break; | |
6052 | } | |
f328dc60 | 6053 | |
6054 | if (!json_lsa) | |
6055 | vty_out(vty, "\n"); | |
d62a17ae | 6056 | } |
718e3744 | 6057 | |
0fa6d92b DS |
6058 | return 1; |
6059 | } | |
6060 | ||
d62a17ae | 6061 | return 0; |
6062 | } | |
6063 | ||
2b64873d | 6064 | static const char *const show_database_desc[] = { |
d62a17ae | 6065 | "unknown", |
6066 | "Router Link States", | |
6067 | "Net Link States", | |
6068 | "Summary Link States", | |
6069 | "ASBR-Summary Link States", | |
6070 | "AS External Link States", | |
6071 | "Group Membership LSA", | |
6072 | "NSSA-external Link States", | |
6073 | "Type-8 LSA", | |
6074 | "Link-Local Opaque-LSA", | |
6075 | "Area-Local Opaque-LSA", | |
6076 | "AS-external Opaque-LSA", | |
718e3744 | 6077 | }; |
6078 | ||
f328dc60 | 6079 | static const char * const show_database_desc_json[] = { |
6080 | "unknown", | |
6081 | "routerLinkStates", | |
6082 | "networkLinkStates", | |
6083 | "summaryLinkStates", | |
6084 | "asbrSummaryLinkStates", | |
6085 | "asExternalLinkStates", | |
6086 | "groupMembershipLsa", | |
6087 | "nssaExternalLinkStates", | |
6088 | "type8Lsa", | |
6089 | "linkLocalOpaqueLsa", | |
6090 | "areaLocalOpaqueLsa", | |
6091 | "asExternalOpaqueLsa", | |
6092 | }; | |
6093 | ||
0fa6d92b DS |
6094 | static const char *const show_database_desc_count_json[] = { |
6095 | "unknownCount", | |
6096 | "routerLinkStatesCount", | |
6097 | "networkLinkStatesCount", | |
6098 | "summaryLinkStatesCount", | |
6099 | "asbrSummaryLinkStatesCount", | |
6100 | "asExternalLinkStatesCount", | |
6101 | "groupMembershipLsaCount", | |
6102 | "nssaExternalLinkStatesCount", | |
6103 | "type8LsaCount", | |
6104 | "linkLocalOpaqueLsaCount", | |
6105 | "areaLocalOpaqueLsaCount", | |
6106 | "asExternalOpaqueLsaCount", | |
6107 | }; | |
6108 | ||
2b64873d | 6109 | static const char *const show_database_header[] = { |
d62a17ae | 6110 | "", |
6111 | "Link ID ADV Router Age Seq# CkSum Link count", | |
6112 | "Link ID ADV Router Age Seq# CkSum", | |
6113 | "Link ID ADV Router Age Seq# CkSum Route", | |
6114 | "Link ID ADV Router Age Seq# CkSum", | |
6115 | "Link ID ADV Router Age Seq# CkSum Route", | |
6116 | " --- header for Group Member ----", | |
6117 | "Link ID ADV Router Age Seq# CkSum Route", | |
6118 | " --- type-8 ---", | |
6119 | "Opaque-Type/Id ADV Router Age Seq# CkSum", | |
6120 | "Opaque-Type/Id ADV Router Age Seq# CkSum", | |
6121 | "Opaque-Type/Id ADV Router Age Seq# CkSum", | |
718e3744 | 6122 | }; |
6123 | ||
f328dc60 | 6124 | static void show_ip_ospf_database_header(struct vty *vty, struct ospf_lsa *lsa, |
6125 | json_object *json) | |
d62a17ae | 6126 | { |
6127 | struct router_lsa *rlsa = (struct router_lsa *)lsa->data; | |
6128 | ||
f328dc60 | 6129 | if (!json) { |
6130 | vty_out(vty, " LS age: %d\n", LS_AGE(lsa)); | |
6131 | vty_out(vty, " Options: 0x%-2x : %s\n", lsa->data->options, | |
6132 | ospf_options_dump(lsa->data->options)); | |
6133 | vty_out(vty, " LS Flags: 0x%-2x %s\n", lsa->flags, | |
6134 | ((lsa->flags & OSPF_LSA_LOCAL_XLT) | |
6135 | ? "(Translated from Type-7)" | |
6136 | : "")); | |
6137 | ||
6138 | if (lsa->data->type == OSPF_ROUTER_LSA) { | |
6139 | vty_out(vty, " Flags: 0x%x", rlsa->flags); | |
6140 | ||
6141 | if (rlsa->flags) | |
6142 | vty_out(vty, " :%s%s%s%s", | |
6143 | IS_ROUTER_LSA_BORDER(rlsa) ? " ABR" | |
6144 | : "", | |
6145 | IS_ROUTER_LSA_EXTERNAL(rlsa) ? " ASBR" | |
6146 | : "", | |
6147 | IS_ROUTER_LSA_VIRTUAL(rlsa) | |
6148 | ? " VL-endpoint" | |
6149 | : "", | |
6150 | IS_ROUTER_LSA_SHORTCUT(rlsa) | |
6151 | ? " Shortcut" | |
6152 | : ""); | |
d62a17ae | 6153 | |
f328dc60 | 6154 | vty_out(vty, "\n"); |
6155 | } | |
6156 | vty_out(vty, " LS Type: %s\n", | |
6157 | lookup_msg(ospf_lsa_type_msg, lsa->data->type, NULL)); | |
6158 | vty_out(vty, " Link State ID: %pI4 %s\n", | |
6159 | &lsa->data->id, | |
6160 | lookup_msg(ospf_link_state_id_type_msg, lsa->data->type, | |
6161 | NULL)); | |
6162 | vty_out(vty, " Advertising Router: %pI4\n", | |
6163 | &lsa->data->adv_router); | |
6164 | vty_out(vty, " LS Seq Number: %08lx\n", | |
6165 | (unsigned long)ntohl(lsa->data->ls_seqnum)); | |
6166 | vty_out(vty, " Checksum: 0x%04x\n", | |
6167 | ntohs(lsa->data->checksum)); | |
6168 | vty_out(vty, " Length: %d\n\n", ntohs(lsa->data->length)); | |
6169 | } else { | |
6170 | char seqnum[10]; | |
6171 | char checksum[10]; | |
6172 | ||
6173 | snprintf(seqnum, 10, "%x", ntohl(lsa->data->ls_seqnum)); | |
6174 | snprintf(checksum, 10, "%x", ntohs(lsa->data->checksum)); | |
6175 | ||
6176 | json_object_int_add(json, "lsaAge", LS_AGE(lsa)); | |
6177 | json_object_string_add(json, "options", | |
6178 | ospf_options_dump(lsa->data->options)); | |
6179 | json_object_int_add(json, "lsaFlags", lsa->flags); | |
6180 | ||
6181 | if (lsa->flags & OSPF_LSA_LOCAL_XLT) | |
6182 | json_object_boolean_true_add(json, | |
6183 | "translatedFromType7"); | |
6184 | ||
6185 | if (lsa->data->type == OSPF_ROUTER_LSA) { | |
6186 | json_object_int_add(json, "flags", rlsa->flags); | |
6187 | ||
6188 | if (rlsa->flags) { | |
6189 | if (IS_ROUTER_LSA_BORDER(rlsa)) | |
6190 | json_object_boolean_true_add(json, | |
6191 | "abr"); | |
6192 | if (IS_ROUTER_LSA_EXTERNAL(rlsa)) | |
6193 | json_object_boolean_true_add(json, | |
6194 | "asbr"); | |
6195 | if (IS_ROUTER_LSA_VIRTUAL(rlsa)) | |
6196 | json_object_boolean_true_add( | |
6197 | json, "vlEndpoint"); | |
6198 | if (IS_ROUTER_LSA_SHORTCUT(rlsa)) | |
6199 | json_object_boolean_true_add( | |
6200 | json, "shortcut"); | |
6201 | } | |
6202 | } | |
6203 | ||
6204 | json_object_string_add( | |
6205 | json, "lsaType", | |
6206 | lookup_msg(ospf_lsa_type_msg, lsa->data->type, NULL)); | |
20308be3 DA |
6207 | json_object_string_addf(json, "linkStateId", "%pI4", |
6208 | &lsa->data->id); | |
6209 | json_object_string_addf(json, "advertisingRouter", "%pI4", | |
6210 | &lsa->data->adv_router); | |
f328dc60 | 6211 | json_object_string_add(json, "lsaSeqNumber", seqnum); |
6212 | json_object_string_add(json, "checksum", checksum); | |
6213 | json_object_int_add(json, "length", ntohs(lsa->data->length)); | |
d62a17ae | 6214 | } |
d62a17ae | 6215 | } |
6216 | ||
2b64873d | 6217 | static const char *const link_type_desc[] = { |
d62a17ae | 6218 | "(null)", |
6219 | "another Router (point-to-point)", | |
6220 | "a Transit Network", | |
6221 | "Stub Network", | |
6222 | "a Virtual Link", | |
718e3744 | 6223 | }; |
6224 | ||
2b64873d | 6225 | static const char *const link_id_desc[] = { |
d62a17ae | 6226 | "(null)", "Neighboring Router ID", "Designated Router address", |
6227 | "Net", "Neighboring Router ID", | |
718e3744 | 6228 | }; |
6229 | ||
2b64873d | 6230 | static const char *const link_data_desc[] = { |
d62a17ae | 6231 | "(null)", "Router Interface address", "Router Interface address", |
6232 | "Network Mask", "Router Interface address", | |
718e3744 | 6233 | }; |
6234 | ||
f328dc60 | 6235 | static const char *const link_id_desc_json[] = { |
6236 | "null", "neighborRouterId", "designatedRouterAddress", | |
6237 | "networkAddress", "neighborRouterId", | |
6238 | }; | |
6239 | ||
6240 | static const char *const link_data_desc_json[] = { | |
6241 | "null", "routerInterfaceAddress", "routerInterfaceAddress", | |
6242 | "networkMask", "routerInterfaceAddress", | |
6243 | }; | |
6244 | ||
718e3744 | 6245 | /* Show router-LSA each Link information. */ |
d62a17ae | 6246 | static void show_ip_ospf_database_router_links(struct vty *vty, |
f328dc60 | 6247 | struct router_lsa *rl, |
6248 | json_object *json) | |
d62a17ae | 6249 | { |
6250 | int len, type; | |
f328dc60 | 6251 | unsigned short i; |
6252 | json_object *json_links = NULL; | |
6253 | json_object *json_link = NULL; | |
6254 | int metric = 0; | |
ce513ac6 | 6255 | char buf[PREFIX_STRLEN]; |
f328dc60 | 6256 | |
6257 | if (json) | |
6258 | json_links = json_object_new_object(); | |
d62a17ae | 6259 | |
6260 | len = ntohs(rl->header.length) - 4; | |
6261 | for (i = 0; i < ntohs(rl->links) && len > 0; len -= 12, i++) { | |
6262 | type = rl->link[i].type; | |
6263 | ||
f328dc60 | 6264 | if (json) { |
6265 | char link[16]; | |
6266 | ||
6267 | snprintf(link, sizeof(link), "link%u", i); | |
6268 | json_link = json_object_new_object(); | |
6269 | json_object_string_add(json_link, "linkType", | |
6270 | link_type_desc[type]); | |
6271 | json_object_string_add(json_link, | |
6272 | link_id_desc_json[type], | |
ce513ac6 MS |
6273 | inet_ntop(AF_INET, |
6274 | &rl->link[i].link_id, | |
6275 | buf, sizeof(buf))); | |
f328dc60 | 6276 | json_object_string_add( |
6277 | json_link, link_data_desc_json[type], | |
ce513ac6 MS |
6278 | inet_ntop(AF_INET, &rl->link[i].link_data, |
6279 | buf, sizeof(buf))); | |
f328dc60 | 6280 | json_object_int_add(json_link, "numOfTosMetrics", |
6281 | metric); | |
6282 | json_object_int_add(json_link, "tos0Metric", | |
6283 | ntohs(rl->link[i].metric)); | |
6284 | json_object_object_add(json_links, link, json_link); | |
6285 | } else { | |
6286 | vty_out(vty, " Link connected to: %s\n", | |
6287 | link_type_desc[type]); | |
6288 | vty_out(vty, " (Link ID) %s: %pI4\n", | |
6289 | link_id_desc[type], | |
6290 | &rl->link[i].link_id); | |
6291 | vty_out(vty, " (Link Data) %s: %pI4\n", | |
6292 | link_data_desc[type], | |
6293 | &rl->link[i].link_data); | |
6294 | vty_out(vty, " Number of TOS metrics: 0\n"); | |
6295 | vty_out(vty, " TOS 0 Metric: %d\n", | |
6296 | ntohs(rl->link[i].metric)); | |
6297 | vty_out(vty, "\n"); | |
6298 | } | |
d62a17ae | 6299 | } |
f328dc60 | 6300 | if (json) |
6301 | json_object_object_add(json, "routerLinks", json_links); | |
718e3744 | 6302 | } |
6303 | ||
6304 | /* Show router-LSA detail information. */ | |
f328dc60 | 6305 | static int show_router_lsa_detail(struct vty *vty, struct ospf_lsa *lsa, |
6306 | json_object *json) | |
718e3744 | 6307 | { |
d62a17ae | 6308 | if (lsa != NULL) { |
6309 | struct router_lsa *rl = (struct router_lsa *)lsa->data; | |
718e3744 | 6310 | |
f328dc60 | 6311 | show_ip_ospf_database_header(vty, lsa, json); |
718e3744 | 6312 | |
f328dc60 | 6313 | if (!json) |
6314 | vty_out(vty, " Number of Links: %d\n\n", | |
6315 | ntohs(rl->links)); | |
6316 | else | |
6317 | json_object_int_add(json, "numOfLinks", | |
6318 | ntohs(rl->links)); | |
718e3744 | 6319 | |
f328dc60 | 6320 | show_ip_ospf_database_router_links(vty, rl, json); |
6321 | ||
6322 | if (!json) | |
6323 | vty_out(vty, "\n"); | |
d62a17ae | 6324 | } |
6325 | ||
6326 | return 0; | |
718e3744 | 6327 | } |
6328 | ||
6329 | /* Show network-LSA detail information. */ | |
f328dc60 | 6330 | static int show_network_lsa_detail(struct vty *vty, struct ospf_lsa *lsa, |
6331 | json_object *json) | |
718e3744 | 6332 | { |
d62a17ae | 6333 | int length, i; |
ce513ac6 | 6334 | char buf[PREFIX_STRLEN]; |
f328dc60 | 6335 | json_object *json_attached_rt = NULL; |
6336 | json_object *json_router = NULL; | |
6337 | ||
6338 | if (json) | |
6339 | json_attached_rt = json_object_new_object(); | |
718e3744 | 6340 | |
d62a17ae | 6341 | if (lsa != NULL) { |
6342 | struct network_lsa *nl = (struct network_lsa *)lsa->data; | |
8db278b5 | 6343 | struct in_addr *addr; |
718e3744 | 6344 | |
f328dc60 | 6345 | show_ip_ospf_database_header(vty, lsa, json); |
718e3744 | 6346 | |
f328dc60 | 6347 | if (!json) |
6348 | vty_out(vty, " Network Mask: /%d\n", | |
6349 | ip_masklen(nl->mask)); | |
6350 | else | |
6351 | json_object_int_add(json, "networkMask", | |
6352 | ip_masklen(nl->mask)); | |
718e3744 | 6353 | |
8db278b5 OD |
6354 | length = lsa->size - OSPF_LSA_HEADER_SIZE - 4; |
6355 | addr = &nl->routers[0]; | |
6356 | for (i = 0; length > 0 && addr; | |
6357 | length -= 4, addr = &nl->routers[++i]) | |
f328dc60 | 6358 | if (!json) { |
6359 | vty_out(vty, " Attached Router: %pI4\n", | |
8db278b5 | 6360 | addr); |
f328dc60 | 6361 | vty_out(vty, "\n"); |
6362 | } else { | |
6363 | json_router = json_object_new_object(); | |
6364 | json_object_string_add( | |
6365 | json_router, "attachedRouterId", | |
8db278b5 OD |
6366 | inet_ntop(AF_INET, addr, buf, |
6367 | sizeof(buf))); | |
6368 | json_object_object_add(json_attached_rt, | |
6369 | inet_ntop(AF_INET, addr, | |
6370 | buf, | |
6371 | sizeof(buf)), | |
6372 | json_router); | |
f328dc60 | 6373 | } |
d62a17ae | 6374 | } |
718e3744 | 6375 | |
f328dc60 | 6376 | if (json) |
6377 | json_object_object_add(json, "attchedRouters", | |
6378 | json_attached_rt); | |
6379 | ||
d62a17ae | 6380 | return 0; |
718e3744 | 6381 | } |
6382 | ||
6383 | /* Show summary-LSA detail information. */ | |
f328dc60 | 6384 | static int show_summary_lsa_detail(struct vty *vty, struct ospf_lsa *lsa, |
6385 | json_object *json) | |
718e3744 | 6386 | { |
d62a17ae | 6387 | if (lsa != NULL) { |
6388 | struct summary_lsa *sl = (struct summary_lsa *)lsa->data; | |
718e3744 | 6389 | |
f328dc60 | 6390 | show_ip_ospf_database_header(vty, lsa, json); |
718e3744 | 6391 | |
f328dc60 | 6392 | if (!json) { |
6393 | vty_out(vty, " Network Mask: /%d\n", | |
6394 | ip_masklen(sl->mask)); | |
6395 | vty_out(vty, " TOS: 0 Metric: %d\n", | |
6396 | GET_METRIC(sl->metric)); | |
6397 | vty_out(vty, "\n"); | |
6398 | } else { | |
6399 | json_object_int_add(json, "networkMask", | |
6400 | ip_masklen(sl->mask)); | |
6401 | json_object_int_add(json, "tos0Metric", | |
6402 | GET_METRIC(sl->metric)); | |
6403 | } | |
d62a17ae | 6404 | } |
718e3744 | 6405 | |
d62a17ae | 6406 | return 0; |
718e3744 | 6407 | } |
6408 | ||
6409 | /* Show summary-ASBR-LSA detail information. */ | |
f328dc60 | 6410 | static int show_summary_asbr_lsa_detail(struct vty *vty, struct ospf_lsa *lsa, |
6411 | json_object *json) | |
718e3744 | 6412 | { |
d62a17ae | 6413 | if (lsa != NULL) { |
6414 | struct summary_lsa *sl = (struct summary_lsa *)lsa->data; | |
718e3744 | 6415 | |
f328dc60 | 6416 | show_ip_ospf_database_header(vty, lsa, json); |
718e3744 | 6417 | |
f328dc60 | 6418 | if (!json) { |
6419 | vty_out(vty, " Network Mask: /%d\n", | |
6420 | ip_masklen(sl->mask)); | |
6421 | vty_out(vty, " TOS: 0 Metric: %d\n", | |
6422 | GET_METRIC(sl->metric)); | |
6423 | vty_out(vty, "\n"); | |
6424 | } else { | |
6425 | json_object_int_add(json, "networkMask", | |
6426 | ip_masklen(sl->mask)); | |
6427 | json_object_int_add(json, "tos0Metric", | |
6428 | GET_METRIC(sl->metric)); | |
6429 | } | |
d62a17ae | 6430 | } |
718e3744 | 6431 | |
d62a17ae | 6432 | return 0; |
718e3744 | 6433 | } |
6434 | ||
6435 | /* Show AS-external-LSA detail information. */ | |
f328dc60 | 6436 | static int show_as_external_lsa_detail(struct vty *vty, struct ospf_lsa *lsa, |
6437 | json_object *json) | |
d62a17ae | 6438 | { |
f328dc60 | 6439 | int tos = 0; |
6440 | ||
d62a17ae | 6441 | if (lsa != NULL) { |
6442 | struct as_external_lsa *al = | |
6443 | (struct as_external_lsa *)lsa->data; | |
6444 | ||
f328dc60 | 6445 | show_ip_ospf_database_header(vty, lsa, json); |
6446 | ||
6447 | if (!json) { | |
6448 | vty_out(vty, " Network Mask: /%d\n", | |
6449 | ip_masklen(al->mask)); | |
6450 | vty_out(vty, " Metric Type: %s\n", | |
6451 | IS_EXTERNAL_METRIC(al->e[0].tos) | |
6452 | ? "2 (Larger than any link state path)" | |
6453 | : "1"); | |
6454 | vty_out(vty, " TOS: 0\n"); | |
6455 | vty_out(vty, " Metric: %d\n", | |
6456 | GET_METRIC(al->e[0].metric)); | |
6457 | vty_out(vty, " Forward Address: %pI4\n", | |
6458 | &al->e[0].fwd_addr); | |
6459 | vty_out(vty, | |
6460 | " External Route Tag: %" ROUTE_TAG_PRI "\n\n", | |
6461 | (route_tag_t)ntohl(al->e[0].route_tag)); | |
6462 | } else { | |
6463 | json_object_int_add(json, "networkMask", | |
6464 | ip_masklen(al->mask)); | |
6465 | json_object_string_add( | |
6466 | json, "metricType", | |
6467 | IS_EXTERNAL_METRIC(al->e[0].tos) | |
6468 | ? "E2 (Larger than any link state path)" | |
6469 | : "E1"); | |
6470 | json_object_int_add(json, "tos", tos); | |
6471 | json_object_int_add(json, "metric", | |
6472 | GET_METRIC(al->e[0].metric)); | |
20308be3 DA |
6473 | json_object_string_addf(json, "forwardAddress", "%pI4", |
6474 | &(al->e[0].fwd_addr)); | |
f328dc60 | 6475 | json_object_int_add( |
6476 | json, "externalRouteTag", | |
6477 | (route_tag_t)ntohl(al->e[0].route_tag)); | |
6478 | } | |
d62a17ae | 6479 | } |
718e3744 | 6480 | |
d62a17ae | 6481 | return 0; |
718e3744 | 6482 | } |
718e3744 | 6483 | |
718e3744 | 6484 | /* Show AS-NSSA-LSA detail information. */ |
f328dc60 | 6485 | static int show_as_nssa_lsa_detail(struct vty *vty, struct ospf_lsa *lsa, |
6486 | json_object *json) | |
d62a17ae | 6487 | { |
f328dc60 | 6488 | int tos = 0; |
6489 | ||
d62a17ae | 6490 | if (lsa != NULL) { |
6491 | struct as_external_lsa *al = | |
6492 | (struct as_external_lsa *)lsa->data; | |
6493 | ||
f328dc60 | 6494 | show_ip_ospf_database_header(vty, lsa, json); |
6495 | ||
6496 | if (!json) { | |
6497 | vty_out(vty, " Network Mask: /%d\n", | |
6498 | ip_masklen(al->mask)); | |
6499 | vty_out(vty, " Metric Type: %s\n", | |
6500 | IS_EXTERNAL_METRIC(al->e[0].tos) | |
6501 | ? "2 (Larger than any link state path)" | |
6502 | : "1"); | |
6503 | vty_out(vty, " TOS: 0\n"); | |
6504 | vty_out(vty, " Metric: %d\n", | |
6505 | GET_METRIC(al->e[0].metric)); | |
6506 | vty_out(vty, " NSSA: Forward Address: %pI4\n", | |
6507 | &al->e[0].fwd_addr); | |
6508 | vty_out(vty, | |
6509 | " External Route Tag: %" ROUTE_TAG_PRI | |
6510 | "\n\n", | |
6511 | (route_tag_t)ntohl(al->e[0].route_tag)); | |
6512 | } else { | |
6513 | json_object_int_add(json, "networkMask", | |
6514 | ip_masklen(al->mask)); | |
6515 | json_object_string_add( | |
6516 | json, "metricType", | |
6517 | IS_EXTERNAL_METRIC(al->e[0].tos) | |
6518 | ? "E2 (Larger than any link state path)" | |
6519 | : "E1"); | |
6520 | json_object_int_add(json, "tos", tos); | |
6521 | json_object_int_add(json, "metric", | |
6522 | GET_METRIC(al->e[0].metric)); | |
20308be3 DA |
6523 | json_object_string_addf(json, "nssaForwardAddress", |
6524 | "%pI4", &al->e[0].fwd_addr); | |
f328dc60 | 6525 | json_object_int_add( |
6526 | json, "externalRouteTag", | |
6527 | (route_tag_t)ntohl(al->e[0].route_tag)); | |
6528 | } | |
d62a17ae | 6529 | } |
718e3744 | 6530 | |
d62a17ae | 6531 | return 0; |
718e3744 | 6532 | } |
6533 | ||
f328dc60 | 6534 | static int show_func_dummy(struct vty *vty, struct ospf_lsa *lsa, |
6535 | json_object *json) | |
718e3744 | 6536 | { |
d62a17ae | 6537 | return 0; |
718e3744 | 6538 | } |
6539 | ||
f328dc60 | 6540 | static int show_opaque_lsa_detail(struct vty *vty, struct ospf_lsa *lsa, |
6541 | json_object *json) | |
718e3744 | 6542 | { |
d62a17ae | 6543 | if (lsa != NULL) { |
f328dc60 | 6544 | show_ip_ospf_database_header(vty, lsa, json); |
6545 | show_opaque_info_detail(vty, lsa, json); | |
6546 | if (!json) | |
6547 | vty_out(vty, "\n"); | |
d62a17ae | 6548 | } |
6549 | return 0; | |
6550 | } | |
6551 | ||
f328dc60 | 6552 | int (*show_function[])(struct vty *, struct ospf_lsa *, json_object *) = { |
d62a17ae | 6553 | NULL, |
6554 | show_router_lsa_detail, | |
6555 | show_network_lsa_detail, | |
6556 | show_summary_lsa_detail, | |
6557 | show_summary_asbr_lsa_detail, | |
6558 | show_as_external_lsa_detail, | |
6559 | show_func_dummy, | |
6560 | show_as_nssa_lsa_detail, /* almost same as external */ | |
6561 | NULL, /* type-8 */ | |
6562 | show_opaque_lsa_detail, | |
6563 | show_opaque_lsa_detail, | |
6564 | show_opaque_lsa_detail, | |
6565 | }; | |
6566 | ||
6567 | static void show_lsa_prefix_set(struct vty *vty, struct prefix_ls *lp, | |
6568 | struct in_addr *id, struct in_addr *adv_router) | |
6569 | { | |
6570 | memset(lp, 0, sizeof(struct prefix_ls)); | |
abb1bf8d | 6571 | lp->family = AF_UNSPEC; |
d62a17ae | 6572 | if (id == NULL) |
6573 | lp->prefixlen = 0; | |
6574 | else if (adv_router == NULL) { | |
12256b84 | 6575 | lp->prefixlen = IPV4_MAX_BITLEN; |
d62a17ae | 6576 | lp->id = *id; |
6577 | } else { | |
6578 | lp->prefixlen = 64; | |
6579 | lp->id = *id; | |
6580 | lp->adv_router = *adv_router; | |
6581 | } | |
718e3744 | 6582 | } |
718e3744 | 6583 | |
d62a17ae | 6584 | static void show_lsa_detail_proc(struct vty *vty, struct route_table *rt, |
f328dc60 | 6585 | struct in_addr *id, struct in_addr *adv_router, |
6586 | json_object *json) | |
d62a17ae | 6587 | { |
6588 | struct prefix_ls lp; | |
6589 | struct route_node *rn, *start; | |
6590 | struct ospf_lsa *lsa; | |
f328dc60 | 6591 | json_object *json_lsa = NULL; |
718e3744 | 6592 | |
d62a17ae | 6593 | show_lsa_prefix_set(vty, &lp, id, adv_router); |
6594 | start = route_node_get(rt, (struct prefix *)&lp); | |
6595 | if (start) { | |
6596 | route_lock_node(start); | |
6597 | for (rn = start; rn; rn = route_next_until(rn, start)) | |
6598 | if ((lsa = rn->info)) { | |
f328dc60 | 6599 | if (json) { |
6600 | json_lsa = json_object_new_object(); | |
6601 | json_object_array_add(json, json_lsa); | |
6602 | } | |
6603 | ||
d62a17ae | 6604 | if (show_function[lsa->data->type] != NULL) |
f328dc60 | 6605 | show_function[lsa->data->type]( |
6606 | vty, lsa, json_lsa); | |
d62a17ae | 6607 | } |
6608 | route_unlock_node(start); | |
6609 | } | |
718e3744 | 6610 | } |
6611 | ||
6612 | /* Show detail LSA information | |
6613 | -- if id is NULL then show all LSAs. */ | |
d62a17ae | 6614 | static void show_lsa_detail(struct vty *vty, struct ospf *ospf, int type, |
f328dc60 | 6615 | struct in_addr *id, struct in_addr *adv_router, |
6616 | json_object *json) | |
d62a17ae | 6617 | { |
6618 | struct listnode *node; | |
6619 | struct ospf_area *area; | |
ce513ac6 | 6620 | char buf[PREFIX_STRLEN]; |
f328dc60 | 6621 | json_object *json_lsa_type = NULL; |
6622 | json_object *json_areas = NULL; | |
6623 | json_object *json_lsa_array = NULL; | |
6624 | ||
6625 | if (json) | |
6626 | json_lsa_type = json_object_new_object(); | |
d62a17ae | 6627 | |
6628 | switch (type) { | |
6629 | case OSPF_AS_EXTERNAL_LSA: | |
6630 | case OSPF_OPAQUE_AS_LSA: | |
f328dc60 | 6631 | if (!json) |
6632 | vty_out(vty, " %s \n\n", | |
6633 | show_database_desc[type]); | |
6634 | else | |
6635 | json_lsa_array = json_object_new_array(); | |
6636 | ||
6637 | show_lsa_detail_proc(vty, AS_LSDB(ospf, type), id, adv_router, | |
6638 | json_lsa_array); | |
6639 | if (json) | |
6640 | json_object_object_add(json, | |
6641 | show_database_desc_json[type], | |
6642 | json_lsa_array); | |
6643 | ||
d62a17ae | 6644 | break; |
6645 | default: | |
f328dc60 | 6646 | if (json) |
6647 | json_areas = json_object_new_object(); | |
6648 | ||
d62a17ae | 6649 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) { |
f328dc60 | 6650 | if (!json) { |
6651 | vty_out(vty, | |
6652 | "\n %s (Area %s)\n\n", | |
6653 | show_database_desc[type], | |
6654 | ospf_area_desc_string(area)); | |
6655 | } else { | |
6656 | json_lsa_array = json_object_new_array(); | |
6657 | json_object_object_add(json_areas, | |
ce513ac6 MS |
6658 | inet_ntop(AF_INET, |
6659 | &area->area_id, | |
6660 | buf, | |
6661 | sizeof(buf)), | |
f328dc60 | 6662 | json_lsa_array); |
6663 | } | |
6664 | ||
d62a17ae | 6665 | show_lsa_detail_proc(vty, AREA_LSDB(area, type), id, |
f328dc60 | 6666 | adv_router, json_lsa_array); |
6667 | } | |
6668 | ||
6669 | if (json) { | |
6670 | json_object_object_add(json_lsa_type, "areas", | |
6671 | json_areas); | |
6672 | json_object_object_add(json, | |
6673 | show_database_desc_json[type], | |
6674 | json_lsa_type); | |
d62a17ae | 6675 | } |
6676 | break; | |
718e3744 | 6677 | } |
6678 | } | |
6679 | ||
d62a17ae | 6680 | static void show_lsa_detail_adv_router_proc(struct vty *vty, |
6681 | struct route_table *rt, | |
f328dc60 | 6682 | struct in_addr *adv_router, |
6683 | json_object *json) | |
d62a17ae | 6684 | { |
ce513ac6 | 6685 | char buf[PREFIX_STRLEN]; |
d62a17ae | 6686 | struct route_node *rn; |
6687 | struct ospf_lsa *lsa; | |
6688 | ||
6689 | for (rn = route_top(rt); rn; rn = route_next(rn)) | |
f328dc60 | 6690 | if ((lsa = rn->info)) { |
6691 | json_object *json_lsa = NULL; | |
6692 | ||
d62a17ae | 6693 | if (IPV4_ADDR_SAME(adv_router, |
6694 | &lsa->data->adv_router)) { | |
6695 | if (CHECK_FLAG(lsa->flags, OSPF_LSA_LOCAL_XLT)) | |
6696 | continue; | |
f328dc60 | 6697 | if (json) |
6698 | json_lsa = json_object_new_object(); | |
6699 | ||
d62a17ae | 6700 | if (show_function[lsa->data->type] != NULL) |
f328dc60 | 6701 | show_function[lsa->data->type]( |
6702 | vty, lsa, json_lsa); | |
6703 | if (json) | |
6704 | json_object_object_add( | |
ce513ac6 MS |
6705 | json, |
6706 | inet_ntop(AF_INET, | |
6707 | &lsa->data->id, | |
6708 | buf, sizeof(buf)), | |
f328dc60 | 6709 | json_lsa); |
d62a17ae | 6710 | } |
f328dc60 | 6711 | } |
d62a17ae | 6712 | } |
6713 | ||
718e3744 | 6714 | /* Show detail LSA information. */ |
d62a17ae | 6715 | static void show_lsa_detail_adv_router(struct vty *vty, struct ospf *ospf, |
f328dc60 | 6716 | int type, struct in_addr *adv_router, |
6717 | json_object *json) | |
d62a17ae | 6718 | { |
6719 | struct listnode *node; | |
6720 | struct ospf_area *area; | |
ce513ac6 | 6721 | char buf[PREFIX_STRLEN]; |
f328dc60 | 6722 | json_object *json_lstype = NULL; |
6723 | json_object *json_area = NULL; | |
6724 | ||
6725 | if (json) | |
6726 | json_lstype = json_object_new_object(); | |
d62a17ae | 6727 | |
6728 | switch (type) { | |
6729 | case OSPF_AS_EXTERNAL_LSA: | |
6730 | case OSPF_OPAQUE_AS_LSA: | |
f328dc60 | 6731 | if (!json) |
6732 | vty_out(vty, " %s \n\n", | |
6733 | show_database_desc[type]); | |
6734 | ||
d62a17ae | 6735 | show_lsa_detail_adv_router_proc(vty, AS_LSDB(ospf, type), |
f328dc60 | 6736 | adv_router, json_lstype); |
d62a17ae | 6737 | break; |
6738 | default: | |
f328dc60 | 6739 | |
d62a17ae | 6740 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) { |
f328dc60 | 6741 | if (json) |
6742 | json_area = json_object_new_object(); | |
6743 | else | |
6744 | vty_out(vty, | |
6745 | "\n %s (Area %s)\n\n", | |
6746 | show_database_desc[type], | |
6747 | ospf_area_desc_string(area)); | |
6748 | show_lsa_detail_adv_router_proc(vty, | |
6749 | AREA_LSDB(area, type), | |
6750 | adv_router, json_area); | |
6751 | ||
6752 | if (json) | |
6753 | json_object_object_add(json_lstype, | |
ce513ac6 MS |
6754 | inet_ntop(AF_INET, |
6755 | &area->area_id, | |
6756 | buf, | |
6757 | sizeof(buf)), | |
f328dc60 | 6758 | json_area); |
d62a17ae | 6759 | } |
6760 | break; | |
6761 | } | |
f328dc60 | 6762 | |
6763 | if (json) | |
6764 | json_object_object_add(json, show_database_desc[type], | |
6765 | json_lstype); | |
d62a17ae | 6766 | } |
6767 | ||
7fd0729f G |
6768 | void show_ip_ospf_database_summary(struct vty *vty, struct ospf *ospf, int self, |
6769 | json_object *json) | |
d62a17ae | 6770 | { |
6771 | struct ospf_lsa *lsa; | |
6772 | struct route_node *rn; | |
6773 | struct ospf_area *area; | |
6774 | struct listnode *node; | |
ce513ac6 | 6775 | char buf[PREFIX_STRLEN]; |
f328dc60 | 6776 | json_object *json_areas = NULL; |
6777 | json_object *json_area = NULL; | |
6778 | json_object *json_lsa = NULL; | |
d62a17ae | 6779 | int type; |
f328dc60 | 6780 | json_object *json_lsa_array = NULL; |
0fa6d92b | 6781 | uint32_t count; |
f328dc60 | 6782 | |
6783 | if (json) | |
6784 | json_areas = json_object_new_object(); | |
d62a17ae | 6785 | |
6786 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) { | |
f328dc60 | 6787 | if (json) |
6788 | json_area = json_object_new_object(); | |
6789 | ||
d62a17ae | 6790 | for (type = OSPF_MIN_LSA; type < OSPF_MAX_LSA; type++) { |
0fa6d92b | 6791 | count = 0; |
d62a17ae | 6792 | switch (type) { |
6793 | case OSPF_AS_EXTERNAL_LSA: | |
6794 | case OSPF_OPAQUE_AS_LSA: | |
6795 | continue; | |
6796 | default: | |
6797 | break; | |
6798 | } | |
6799 | if (ospf_lsdb_count_self(area->lsdb, type) > 0 | |
6800 | || (!self | |
6801 | && ospf_lsdb_count(area->lsdb, type) > 0)) { | |
d62a17ae | 6802 | |
f328dc60 | 6803 | if (!json) { |
6804 | vty_out(vty, | |
6805 | " %s (Area %s)\n\n", | |
6806 | show_database_desc[type], | |
6807 | ospf_area_desc_string(area)); | |
6808 | vty_out(vty, "%s\n", | |
6809 | show_database_header[type]); | |
6810 | } else { | |
6811 | json_lsa_array = | |
6812 | json_object_new_array(); | |
6813 | json_object_object_add( | |
6814 | json_area, | |
6815 | show_database_desc_json[type], | |
6816 | json_lsa_array); | |
6817 | } | |
6818 | ||
6819 | LSDB_LOOP (AREA_LSDB(area, type), rn, lsa) { | |
6820 | if (json) { | |
6821 | json_lsa = | |
6822 | json_object_new_object(); | |
6823 | json_object_array_add( | |
6824 | json_lsa_array, | |
6825 | json_lsa); | |
6826 | } | |
d62a17ae | 6827 | |
0fa6d92b DS |
6828 | count += show_lsa_summary( |
6829 | vty, lsa, self, json_lsa); | |
f328dc60 | 6830 | } |
6831 | ||
6832 | if (!json) | |
6833 | vty_out(vty, "\n"); | |
0fa6d92b DS |
6834 | else |
6835 | json_object_int_add( | |
6836 | json_area, | |
6837 | ||
6838 | show_database_desc_count_json | |
6839 | [type], | |
6840 | count); | |
d62a17ae | 6841 | } |
6842 | } | |
f328dc60 | 6843 | if (json) |
6844 | json_object_object_add(json_areas, | |
ce513ac6 MS |
6845 | inet_ntop(AF_INET, |
6846 | &area->area_id, | |
6847 | buf, sizeof(buf)), | |
f328dc60 | 6848 | json_area); |
d62a17ae | 6849 | } |
6850 | ||
f328dc60 | 6851 | if (json) |
6852 | json_object_object_add(json, "areas", json_areas); | |
6853 | ||
d62a17ae | 6854 | for (type = OSPF_MIN_LSA; type < OSPF_MAX_LSA; type++) { |
0fa6d92b | 6855 | count = 0; |
d62a17ae | 6856 | switch (type) { |
6857 | case OSPF_AS_EXTERNAL_LSA: | |
6858 | case OSPF_OPAQUE_AS_LSA: | |
6859 | break; | |
6860 | default: | |
6861 | continue; | |
6862 | } | |
6863 | if (ospf_lsdb_count_self(ospf->lsdb, type) | |
6864 | || (!self && ospf_lsdb_count(ospf->lsdb, type))) { | |
f328dc60 | 6865 | if (!json) { |
6866 | vty_out(vty, " %s\n\n", | |
6867 | show_database_desc[type]); | |
6868 | vty_out(vty, "%s\n", | |
6869 | show_database_header[type]); | |
6870 | } else { | |
6871 | json_lsa_array = json_object_new_array(); | |
6872 | json_object_object_add( | |
6873 | json, show_database_desc_json[type], | |
6874 | json_lsa_array); | |
6875 | } | |
d62a17ae | 6876 | |
f328dc60 | 6877 | LSDB_LOOP (AS_LSDB(ospf, type), rn, lsa) { |
6878 | if (json) { | |
6879 | json_lsa = json_object_new_object(); | |
6880 | json_object_array_add(json_lsa_array, | |
6881 | json_lsa); | |
6882 | } | |
d62a17ae | 6883 | |
0fa6d92b DS |
6884 | count += show_lsa_summary(vty, lsa, self, |
6885 | json_lsa); | |
f328dc60 | 6886 | } |
6887 | ||
6888 | if (!json) | |
6889 | vty_out(vty, "\n"); | |
0fa6d92b DS |
6890 | else |
6891 | json_object_int_add( | |
6892 | json, | |
6893 | show_database_desc_count_json[type], | |
6894 | count); | |
d62a17ae | 6895 | } |
6896 | } | |
6897 | ||
f328dc60 | 6898 | if (!json) |
6899 | vty_out(vty, "\n"); | |
d62a17ae | 6900 | } |
6901 | ||
f328dc60 | 6902 | static void show_ip_ospf_database_maxage(struct vty *vty, struct ospf *ospf, |
6903 | json_object *json) | |
d62a17ae | 6904 | { |
6905 | struct route_node *rn; | |
ce513ac6 | 6906 | char buf[PREFIX_STRLEN]; |
f328dc60 | 6907 | json_object *json_maxage = NULL; |
d62a17ae | 6908 | |
f328dc60 | 6909 | if (!json) |
6910 | vty_out(vty, "\n MaxAge Link States:\n\n"); | |
6911 | else | |
6912 | json_maxage = json_object_new_object(); | |
d62a17ae | 6913 | |
6914 | for (rn = route_top(ospf->maxage_lsa); rn; rn = route_next(rn)) { | |
6915 | struct ospf_lsa *lsa; | |
f328dc60 | 6916 | json_object *json_lsa = NULL; |
d62a17ae | 6917 | |
6918 | if ((lsa = rn->info) != NULL) { | |
f328dc60 | 6919 | if (!json) { |
6920 | vty_out(vty, "Link type: %d\n", | |
6921 | lsa->data->type); | |
ce513ac6 MS |
6922 | vty_out(vty, "Link State ID: %pI4\n", |
6923 | &lsa->data->id); | |
f328dc60 | 6924 | vty_out(vty, "Advertising Router: %pI4\n", |
6925 | &lsa->data->adv_router); | |
6926 | vty_out(vty, "LSA lock count: %d\n", lsa->lock); | |
6927 | vty_out(vty, "\n"); | |
6928 | } else { | |
6929 | json_lsa = json_object_new_object(); | |
6930 | json_object_int_add(json_lsa, "linkType", | |
6931 | lsa->data->type); | |
20308be3 DA |
6932 | json_object_string_addf(json_lsa, "linkStateId", |
6933 | "%pI4", &lsa->data->id); | |
6934 | json_object_string_addf( | |
6935 | json_lsa, "advertisingRouter", "%pI4", | |
6936 | &lsa->data->adv_router); | |
f328dc60 | 6937 | json_object_int_add(json_lsa, "lsaLockCount", |
6938 | lsa->lock); | |
ce513ac6 MS |
6939 | json_object_object_add( |
6940 | json_maxage, | |
6941 | inet_ntop(AF_INET, | |
6942 | &lsa->data->id, | |
6943 | buf, sizeof(buf)), | |
6944 | json_lsa); | |
f328dc60 | 6945 | } |
d62a17ae | 6946 | } |
91e6a0e5 | 6947 | } |
f328dc60 | 6948 | if (json) |
6949 | json_object_object_add(json, "maxAgeLinkStates", json_maxage); | |
718e3744 | 6950 | } |
6951 | ||
718e3744 | 6952 | #define OSPF_LSA_TYPE_NSSA_DESC "NSSA external link state\n" |
6953 | #define OSPF_LSA_TYPE_NSSA_CMD_STR "|nssa-external" | |
718e3744 | 6954 | |
718e3744 | 6955 | #define OSPF_LSA_TYPE_OPAQUE_LINK_DESC "Link local Opaque-LSA\n" |
6956 | #define OSPF_LSA_TYPE_OPAQUE_AREA_DESC "Link area Opaque-LSA\n" | |
6957 | #define OSPF_LSA_TYPE_OPAQUE_AS_DESC "Link AS Opaque-LSA\n" | |
6958 | #define OSPF_LSA_TYPE_OPAQUE_CMD_STR "|opaque-link|opaque-area|opaque-as" | |
718e3744 | 6959 | |
d62a17ae | 6960 | #define OSPF_LSA_TYPES_DESC \ |
6961 | "ASBR summary link states\n" \ | |
6962 | "External link states\n" \ | |
6963 | "Network link states\n" \ | |
6964 | "Router link states\n" \ | |
6965 | "Network summary link states\n" OSPF_LSA_TYPE_NSSA_DESC \ | |
6966 | OSPF_LSA_TYPE_OPAQUE_LINK_DESC OSPF_LSA_TYPE_OPAQUE_AREA_DESC \ | |
6967 | OSPF_LSA_TYPE_OPAQUE_AS_DESC | |
6968 | ||
6969 | static int show_ip_ospf_database_common(struct vty *vty, struct ospf *ospf, | |
6970 | int arg_base, int argc, | |
d7c0a89a | 6971 | struct cmd_token **argv, |
f328dc60 | 6972 | uint8_t use_vrf, json_object *json, |
6973 | bool uj) | |
d62a17ae | 6974 | { |
6975 | int idx_type = 4; | |
6976 | int type, ret; | |
6977 | struct in_addr id, adv_router; | |
f328dc60 | 6978 | json_object *json_vrf = NULL; |
d62a17ae | 6979 | |
f328dc60 | 6980 | if (uj) { |
6981 | if (use_vrf) | |
6982 | json_vrf = json_object_new_object(); | |
6983 | else | |
6984 | json_vrf = json; | |
6985 | } | |
6986 | ||
6987 | if (ospf->instance) { | |
6988 | if (uj) | |
6989 | json_object_int_add(json_vrf, "ospfInstance", | |
6990 | ospf->instance); | |
6991 | else | |
6992 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
6993 | } | |
d62a17ae | 6994 | |
f328dc60 | 6995 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); |
87bd50e8 | 6996 | |
f328dc60 | 6997 | /* Show Router ID. */ |
6998 | if (uj) { | |
20308be3 DA |
6999 | json_object_string_addf(json_vrf, "routerId", "%pI4", |
7000 | &ospf->router_id); | |
f328dc60 | 7001 | } else { |
7002 | vty_out(vty, "\n OSPF Router with ID (%pI4)\n\n", | |
7003 | &ospf->router_id); | |
7004 | } | |
d62a17ae | 7005 | |
7006 | /* Show all LSA. */ | |
f328dc60 | 7007 | if ((argc == arg_base + 4) || (uj && (argc == arg_base + 5))) { |
7008 | show_ip_ospf_database_summary(vty, ospf, 0, json_vrf); | |
7009 | if (json) { | |
44076f4d RW |
7010 | if (use_vrf) |
7011 | json_object_object_add( | |
7012 | json, ospf_get_name(ospf), json_vrf); | |
f328dc60 | 7013 | } |
d62a17ae | 7014 | return CMD_SUCCESS; |
7015 | } | |
718e3744 | 7016 | |
d62a17ae | 7017 | /* Set database type to show. */ |
7018 | if (strncmp(argv[arg_base + idx_type]->text, "r", 1) == 0) | |
7019 | type = OSPF_ROUTER_LSA; | |
7020 | else if (strncmp(argv[arg_base + idx_type]->text, "ne", 2) == 0) | |
7021 | type = OSPF_NETWORK_LSA; | |
7022 | else if (strncmp(argv[arg_base + idx_type]->text, "ns", 2) == 0) | |
7023 | type = OSPF_AS_NSSA_LSA; | |
7024 | else if (strncmp(argv[arg_base + idx_type]->text, "su", 2) == 0) | |
7025 | type = OSPF_SUMMARY_LSA; | |
7026 | else if (strncmp(argv[arg_base + idx_type]->text, "a", 1) == 0) | |
7027 | type = OSPF_ASBR_SUMMARY_LSA; | |
7028 | else if (strncmp(argv[arg_base + idx_type]->text, "e", 1) == 0) | |
7029 | type = OSPF_AS_EXTERNAL_LSA; | |
7030 | else if (strncmp(argv[arg_base + idx_type]->text, "se", 2) == 0) { | |
f328dc60 | 7031 | show_ip_ospf_database_summary(vty, ospf, 1, json_vrf); |
7032 | if (json) { | |
44076f4d RW |
7033 | if (use_vrf) |
7034 | json_object_object_add( | |
7035 | json, ospf_get_name(ospf), json_vrf); | |
f328dc60 | 7036 | } |
d62a17ae | 7037 | return CMD_SUCCESS; |
7038 | } else if (strncmp(argv[arg_base + idx_type]->text, "m", 1) == 0) { | |
f328dc60 | 7039 | show_ip_ospf_database_maxage(vty, ospf, json_vrf); |
7040 | if (json) { | |
44076f4d RW |
7041 | if (use_vrf) |
7042 | json_object_object_add( | |
7043 | json, ospf_get_name(ospf), json_vrf); | |
f328dc60 | 7044 | } |
d62a17ae | 7045 | return CMD_SUCCESS; |
7046 | } else if (strncmp(argv[arg_base + idx_type]->text, "opaque-l", 8) == 0) | |
7047 | type = OSPF_OPAQUE_LINK_LSA; | |
7048 | else if (strncmp(argv[arg_base + idx_type]->text, "opaque-ar", 9) == 0) | |
7049 | type = OSPF_OPAQUE_AREA_LSA; | |
7050 | else if (strncmp(argv[arg_base + idx_type]->text, "opaque-as", 9) == 0) | |
7051 | type = OSPF_OPAQUE_AS_LSA; | |
7052 | else | |
718e3744 | 7053 | return CMD_WARNING; |
d62a17ae | 7054 | |
7055 | /* `show ip ospf database LSA'. */ | |
f328dc60 | 7056 | if ((argc == arg_base + 5) || (uj && (argc == arg_base + 6))) |
7057 | show_lsa_detail(vty, ospf, type, NULL, NULL, json_vrf); | |
d62a17ae | 7058 | else if (argc >= arg_base + 6) { |
7059 | ret = inet_aton(argv[arg_base + 5]->arg, &id); | |
7060 | if (!ret) | |
7061 | return CMD_WARNING; | |
7062 | ||
7063 | /* `show ip ospf database LSA ID'. */ | |
f328dc60 | 7064 | if ((argc == arg_base + 6) || (uj && (argc == arg_base + 7))) |
7065 | show_lsa_detail(vty, ospf, type, &id, NULL, json_vrf); | |
d62a17ae | 7066 | /* `show ip ospf database LSA ID adv-router ADV_ROUTER'. */ |
f328dc60 | 7067 | else if ((argc == arg_base + 7) |
7068 | || (uj && (argc == arg_base + 8))) { | |
d62a17ae | 7069 | if (strncmp(argv[arg_base + 6]->text, "s", 1) == 0) |
7070 | adv_router = ospf->router_id; | |
7071 | else { | |
7072 | ret = inet_aton(argv[arg_base + 7]->arg, | |
7073 | &adv_router); | |
7074 | if (!ret) | |
7075 | return CMD_WARNING; | |
7076 | } | |
f328dc60 | 7077 | show_lsa_detail(vty, ospf, type, &id, &adv_router, |
7078 | json_vrf); | |
7079 | } | |
7080 | } | |
7081 | ||
7082 | if (json) { | |
44076f4d RW |
7083 | if (use_vrf) |
7084 | json_object_object_add(json, ospf_get_name(ospf), | |
7085 | json_vrf); | |
718e3744 | 7086 | } |
718e3744 | 7087 | |
d62a17ae | 7088 | return CMD_SUCCESS; |
718e3744 | 7089 | } |
7090 | ||
7a7be519 | 7091 | DEFUN (show_ip_ospf_database_max, |
7092 | show_ip_ospf_database_max_cmd, | |
f328dc60 | 7093 | "show ip ospf [vrf <NAME|all>] database <max-age|self-originate> [json]", |
7a7be519 | 7094 | SHOW_STR |
7095 | IP_STR | |
7096 | "OSPF information\n" | |
b5a8894d CS |
7097 | VRF_CMD_HELP_STR |
7098 | "All VRFs\n" | |
7a7be519 | 7099 | "Database summary\n" |
7100 | "LSAs in MaxAge list\n" | |
f328dc60 | 7101 | "Self-originated link states\n" |
7102 | JSON_STR) | |
7a7be519 | 7103 | { |
b5a8894d CS |
7104 | struct ospf *ospf = NULL; |
7105 | struct listnode *node = NULL; | |
7106 | char *vrf_name = NULL; | |
2951a7a4 | 7107 | bool all_vrf = false; |
b5a8894d CS |
7108 | int ret = CMD_SUCCESS; |
7109 | int inst = 0; | |
7110 | int idx_vrf = 0; | |
d7c0a89a | 7111 | uint8_t use_vrf = 0; |
f328dc60 | 7112 | bool uj = use_json(argc, argv); |
7113 | json_object *json = NULL; | |
7114 | ||
7115 | if (uj) | |
7116 | json = json_object_new_object(); | |
f412b39a | 7117 | |
43b8d1d8 | 7118 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
f412b39a | 7119 | |
b5a8894d | 7120 | if (vrf_name) { |
2951a7a4 | 7121 | bool ospf_output = false; |
874f58d8 | 7122 | |
b1c3ae8c | 7123 | use_vrf = 1; |
94d4c685 | 7124 | |
b5a8894d CS |
7125 | if (all_vrf) { |
7126 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
7127 | if (!ospf->oi_running) | |
7128 | continue; | |
2951a7a4 | 7129 | ospf_output = true; |
996c9314 LB |
7130 | ret = show_ip_ospf_database_common( |
7131 | vty, ospf, idx_vrf ? 2 : 0, argc, argv, | |
f328dc60 | 7132 | use_vrf, json, uj); |
b5a8894d | 7133 | } |
9f049418 DS |
7134 | |
7135 | if (!ospf_output) | |
fbaafa00 | 7136 | vty_out(vty, "%% OSPF is not enabled\n"); |
b5a8894d CS |
7137 | } else { |
7138 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
9f049418 | 7139 | if (ospf == NULL || !ospf->oi_running) { |
fbaafa00 JAG |
7140 | vty_out(vty, |
7141 | "%% OSPF is not enabled in vrf %s\n", | |
7142 | vrf_name); | |
b5a8894d | 7143 | return CMD_SUCCESS; |
9f049418 | 7144 | } |
996c9314 | 7145 | ret = (show_ip_ospf_database_common( |
f328dc60 | 7146 | vty, ospf, idx_vrf ? 2 : 0, argc, argv, use_vrf, |
7147 | json, uj)); | |
b5a8894d CS |
7148 | } |
7149 | } else { | |
7150 | /* Display default ospf (instance 0) info */ | |
7151 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
9f049418 | 7152 | if (ospf == NULL || !ospf->oi_running) { |
fbaafa00 | 7153 | vty_out(vty, "%% OSPF is not enabled in vrf default\n"); |
b5a8894d | 7154 | return CMD_SUCCESS; |
9f049418 DS |
7155 | } |
7156 | ||
b1c3ae8c | 7157 | ret = show_ip_ospf_database_common(vty, ospf, 0, argc, argv, |
f328dc60 | 7158 | use_vrf, json, uj); |
7159 | } | |
7160 | ||
7161 | if (uj) { | |
7162 | vty_out(vty, "%s\n", json_object_to_json_string(json)); | |
7163 | json_object_free(json); | |
b5a8894d CS |
7164 | } |
7165 | ||
7166 | return ret; | |
7a7be519 | 7167 | } |
f412b39a | 7168 | |
a11bce11 IR |
7169 | ALIAS (show_ip_ospf_database_max, |
7170 | show_ip_ospf_database_cmd, | |
7171 | "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 | 7172 | SHOW_STR |
7173 | IP_STR | |
7174 | "OSPF information\n" | |
b5a8894d | 7175 | VRF_CMD_HELP_STR |
a11bce11 | 7176 | "All VRFs\n" |
7a7be519 | 7177 | "Database summary\n" |
7178 | OSPF_LSA_TYPES_DESC | |
7179 | "Link State ID (as an IP address)\n" | |
7180 | "Self-originated link states\n" | |
7181 | "Advertising Router link states\n" | |
f328dc60 | 7182 | "Advertising Router (as an IP address)\n" |
7183 | JSON_STR) | |
7c8ff89e | 7184 | |
7a7be519 | 7185 | DEFUN (show_ip_ospf_instance_database_max, |
7186 | show_ip_ospf_instance_database_max_cmd, | |
f328dc60 | 7187 | "show ip ospf (1-65535) database <max-age|self-originate> [json]", |
7a7be519 | 7188 | SHOW_STR |
7189 | IP_STR | |
7190 | "OSPF information\n" | |
7191 | "Instance ID\n" | |
7192 | "Database summary\n" | |
7193 | "LSAs in MaxAge list\n" | |
f328dc60 | 7194 | "Self-originated link states\n" |
7195 | JSON_STR) | |
7a7be519 | 7196 | { |
d62a17ae | 7197 | int idx_number = 3; |
7198 | struct ospf *ospf; | |
d7c0a89a | 7199 | unsigned short instance = 0; |
f328dc60 | 7200 | bool uj = use_json(argc, argv); |
7201 | json_object *json = NULL; | |
7202 | ||
7203 | if (uj) | |
7204 | json = json_object_new_object(); | |
d62a17ae | 7205 | |
7206 | instance = strtoul(argv[idx_number]->arg, NULL, 10); | |
409f98ab | 7207 | if (instance != ospf_instance) |
ac28e4ec CS |
7208 | return CMD_NOT_MY_INSTANCE; |
7209 | ||
409f98ab IR |
7210 | ospf = ospf_lookup_instance(instance); |
7211 | if (!ospf || !ospf->oi_running) | |
d62a17ae | 7212 | return CMD_SUCCESS; |
7213 | ||
f328dc60 | 7214 | show_ip_ospf_database_common(vty, ospf, 1, argc, argv, 0, json, uj); |
7215 | ||
c48349e3 | 7216 | if (uj) |
92ef0078 | 7217 | vty_json(vty, json); |
f328dc60 | 7218 | |
7219 | return CMD_SUCCESS; | |
d62a17ae | 7220 | } |
7221 | ||
a11bce11 IR |
7222 | ALIAS (show_ip_ospf_instance_database_max, |
7223 | show_ip_ospf_instance_database_cmd, | |
7224 | "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]", | |
7225 | SHOW_STR | |
7226 | IP_STR | |
7227 | "OSPF information\n" | |
7228 | "Instance ID\n" | |
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" | |
7234 | "Advertising Router (as an IP address)\n" | |
7235 | JSON_STR) | |
d62a17ae | 7236 | |
7237 | static int show_ip_ospf_database_type_adv_router_common(struct vty *vty, | |
7238 | struct ospf *ospf, | |
7239 | int arg_base, int argc, | |
b1c3ae8c | 7240 | struct cmd_token **argv, |
f328dc60 | 7241 | uint8_t use_vrf, |
7242 | json_object *json, | |
7243 | bool uj) | |
d62a17ae | 7244 | { |
7245 | int idx_type = 4; | |
7246 | int type, ret; | |
7247 | struct in_addr adv_router; | |
f328dc60 | 7248 | json_object *json_vrf = NULL; |
d62a17ae | 7249 | |
f328dc60 | 7250 | if (uj) { |
7251 | if (use_vrf) | |
7252 | json_vrf = json_object_new_object(); | |
7253 | else | |
7254 | json_vrf = json; | |
7255 | } | |
d62a17ae | 7256 | |
f328dc60 | 7257 | if (ospf->instance) { |
7258 | if (uj) | |
7259 | json_object_int_add(json, "ospfInstance", | |
7260 | ospf->instance); | |
7261 | else | |
7262 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
7263 | } | |
87bd50e8 | 7264 | |
f328dc60 | 7265 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); |
7266 | ||
7267 | /* Show Router ID. */ | |
7268 | if (uj) { | |
20308be3 DA |
7269 | json_object_string_addf(json_vrf, "routerId", "%pI4", |
7270 | &ospf->router_id); | |
f328dc60 | 7271 | } else { |
7272 | vty_out(vty, "\n OSPF Router with ID (%pI4)\n\n", | |
7273 | &ospf->router_id); | |
7274 | } | |
d62a17ae | 7275 | |
7276 | /* Set database type to show. */ | |
7277 | if (strncmp(argv[arg_base + idx_type]->text, "r", 1) == 0) | |
7278 | type = OSPF_ROUTER_LSA; | |
7279 | else if (strncmp(argv[arg_base + idx_type]->text, "ne", 2) == 0) | |
7280 | type = OSPF_NETWORK_LSA; | |
7281 | else if (strncmp(argv[arg_base + idx_type]->text, "ns", 2) == 0) | |
7282 | type = OSPF_AS_NSSA_LSA; | |
7283 | else if (strncmp(argv[arg_base + idx_type]->text, "s", 1) == 0) | |
7284 | type = OSPF_SUMMARY_LSA; | |
7285 | else if (strncmp(argv[arg_base + idx_type]->text, "a", 1) == 0) | |
7286 | type = OSPF_ASBR_SUMMARY_LSA; | |
7287 | else if (strncmp(argv[arg_base + idx_type]->text, "e", 1) == 0) | |
7288 | type = OSPF_AS_EXTERNAL_LSA; | |
7289 | else if (strncmp(argv[arg_base + idx_type]->text, "opaque-l", 8) == 0) | |
7290 | type = OSPF_OPAQUE_LINK_LSA; | |
7291 | else if (strncmp(argv[arg_base + idx_type]->text, "opaque-ar", 9) == 0) | |
7292 | type = OSPF_OPAQUE_AREA_LSA; | |
7293 | else if (strncmp(argv[arg_base + idx_type]->text, "opaque-as", 9) == 0) | |
7294 | type = OSPF_OPAQUE_AS_LSA; | |
7295 | else | |
7296 | return CMD_WARNING; | |
7c8ff89e | 7297 | |
d62a17ae | 7298 | /* `show ip ospf database LSA adv-router ADV_ROUTER'. */ |
7299 | if (strncmp(argv[arg_base + 5]->text, "s", 1) == 0) | |
7300 | adv_router = ospf->router_id; | |
7301 | else { | |
7302 | ret = inet_aton(argv[arg_base + 6]->arg, &adv_router); | |
7303 | if (!ret) | |
7304 | return CMD_WARNING; | |
7305 | } | |
7c8ff89e | 7306 | |
f328dc60 | 7307 | show_lsa_detail_adv_router(vty, ospf, type, &adv_router, json_vrf); |
7308 | ||
7309 | if (json) { | |
44076f4d RW |
7310 | if (use_vrf) |
7311 | json_object_object_add(json, ospf_get_name(ospf), | |
7312 | json_vrf); | |
f328dc60 | 7313 | } |
7c8ff89e | 7314 | |
d62a17ae | 7315 | return CMD_SUCCESS; |
7c8ff89e DS |
7316 | } |
7317 | ||
a11bce11 IR |
7318 | DEFUN (show_ip_ospf_database_type_adv_router, |
7319 | show_ip_ospf_database_type_adv_router_cmd, | |
7320 | "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 |
7321 | SHOW_STR |
7322 | IP_STR | |
7323 | "OSPF information\n" | |
b5a8894d | 7324 | VRF_CMD_HELP_STR |
a11bce11 | 7325 | "All VRFs\n" |
7c8ff89e DS |
7326 | "Database summary\n" |
7327 | OSPF_LSA_TYPES_DESC | |
7328 | "Advertising Router link states\n" | |
3a2d747c | 7329 | "Advertising Router (as an IP address)\n" |
f328dc60 | 7330 | "Self-originated link states\n" |
7331 | JSON_STR) | |
7c8ff89e | 7332 | { |
b5a8894d | 7333 | struct ospf *ospf = NULL; |
b5a8894d CS |
7334 | struct listnode *node = NULL; |
7335 | char *vrf_name = NULL; | |
2951a7a4 | 7336 | bool all_vrf = false; |
b5a8894d CS |
7337 | int ret = CMD_SUCCESS; |
7338 | int inst = 0; | |
acaeb9fd | 7339 | int idx_vrf = 0; |
d7c0a89a | 7340 | uint8_t use_vrf = 0; |
f328dc60 | 7341 | bool uj = use_json(argc, argv); |
7342 | json_object *json = NULL; | |
7343 | ||
7344 | if (uj) | |
7345 | json = json_object_new_object(); | |
7c8ff89e | 7346 | |
43b8d1d8 CS |
7347 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
7348 | ||
b5a8894d | 7349 | if (vrf_name) { |
2951a7a4 | 7350 | bool ospf_output = false; |
874f58d8 | 7351 | |
b1c3ae8c | 7352 | use_vrf = 1; |
94d4c685 | 7353 | |
b5a8894d CS |
7354 | if (all_vrf) { |
7355 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
7356 | if (!ospf->oi_running) | |
7357 | continue; | |
2951a7a4 | 7358 | ospf_output = true; |
996c9314 | 7359 | ret = show_ip_ospf_database_type_adv_router_common( |
d68e47e1 LS |
7360 | vty, ospf, 2, argc, argv, use_vrf, json, |
7361 | uj); | |
b5a8894d | 7362 | } |
9f049418 | 7363 | if (!ospf_output) |
fbaafa00 | 7364 | vty_out(vty, "%% OSPF is not enabled\n"); |
b5a8894d CS |
7365 | } else { |
7366 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
9f049418 | 7367 | if ((ospf == NULL) || !ospf->oi_running) { |
fbaafa00 JAG |
7368 | vty_out(vty, |
7369 | "%% OSPF is not enabled in vrf %s\n", | |
7370 | vrf_name); | |
b5a8894d | 7371 | return CMD_SUCCESS; |
9f049418 DS |
7372 | } |
7373 | ||
996c9314 | 7374 | ret = show_ip_ospf_database_type_adv_router_common( |
d68e47e1 | 7375 | vty, ospf, 2, argc, argv, use_vrf, json, uj); |
b5a8894d CS |
7376 | } |
7377 | } else { | |
7378 | /* Display default ospf (instance 0) info */ | |
7379 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
9f049418 | 7380 | if (ospf == NULL || !ospf->oi_running) { |
fbaafa00 | 7381 | vty_out(vty, "%% OSPF is not enabled on vrf default\n"); |
b5a8894d | 7382 | return CMD_SUCCESS; |
9f049418 DS |
7383 | } |
7384 | ||
996c9314 | 7385 | ret = show_ip_ospf_database_type_adv_router_common( |
acaeb9fd | 7386 | vty, ospf, 0, argc, argv, use_vrf, json, uj); |
b5a8894d | 7387 | } |
f328dc60 | 7388 | |
7389 | if (uj) { | |
7390 | vty_out(vty, "%s\n", json_object_to_json_string(json)); | |
7391 | json_object_free(json); | |
7392 | } | |
7393 | ||
b5a8894d | 7394 | return ret; |
a11bce11 IR |
7395 | } |
7396 | ||
7397 | DEFUN (show_ip_ospf_instance_database_type_adv_router, | |
7398 | show_ip_ospf_instance_database_type_adv_router_cmd, | |
7399 | "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]", | |
7400 | SHOW_STR | |
7401 | IP_STR | |
7402 | "OSPF information\n" | |
7403 | "Instance ID\n" | |
7404 | "Database summary\n" | |
7405 | OSPF_LSA_TYPES_DESC | |
7406 | "Advertising Router link states\n" | |
7407 | "Advertising Router (as an IP address)\n" | |
7408 | "Self-originated link states\n" | |
7409 | JSON_STR) | |
7410 | { | |
7411 | int idx_number = 3; | |
7412 | struct ospf *ospf; | |
7413 | unsigned short instance = 0; | |
7414 | bool uj = use_json(argc, argv); | |
7415 | json_object *json = NULL; | |
7416 | ||
7417 | if (uj) | |
7418 | json = json_object_new_object(); | |
7419 | ||
7420 | instance = strtoul(argv[idx_number]->arg, NULL, 10); | |
7421 | if (instance != ospf_instance) | |
7422 | return CMD_NOT_MY_INSTANCE; | |
7423 | ||
7424 | ospf = ospf_lookup_instance(instance); | |
7425 | if (!ospf || !ospf->oi_running) | |
7426 | return CMD_SUCCESS; | |
7427 | ||
7428 | show_ip_ospf_database_type_adv_router_common(vty, ospf, 1, argc, argv, | |
7429 | 0, json, uj); | |
7430 | ||
c48349e3 | 7431 | if (uj) |
92ef0078 | 7432 | vty_json(vty, json); |
a11bce11 IR |
7433 | |
7434 | return CMD_SUCCESS; | |
718e3744 | 7435 | } |
7436 | ||
718e3744 | 7437 | DEFUN (ip_ospf_authentication_args, |
7438 | ip_ospf_authentication_args_addr_cmd, | |
7a7be519 | 7439 | "ip ospf authentication <null|message-digest> [A.B.C.D]", |
718e3744 | 7440 | "IP Information\n" |
7441 | "OSPF interface commands\n" | |
7442 | "Enable authentication on this interface\n" | |
7443 | "Use null authentication\n" | |
7444 | "Use message-digest authentication\n" | |
7a7be519 | 7445 | "Address of interface\n") |
718e3744 | 7446 | { |
d62a17ae | 7447 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7448 | int idx_encryption = 3; | |
7449 | int idx_ipv4 = 4; | |
7450 | struct in_addr addr; | |
7451 | int ret; | |
7452 | struct ospf_if_params *params; | |
7453 | ||
7454 | params = IF_DEF_PARAMS(ifp); | |
7455 | ||
7456 | if (argc == 5) { | |
7457 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
7458 | if (!ret) { | |
7459 | vty_out(vty, | |
7460 | "Please specify interface address by A.B.C.D\n"); | |
7461 | return CMD_WARNING_CONFIG_FAILED; | |
7462 | } | |
718e3744 | 7463 | |
d62a17ae | 7464 | params = ospf_get_if_params(ifp, addr); |
7465 | ospf_if_update_params(ifp, addr); | |
7466 | } | |
718e3744 | 7467 | |
d62a17ae | 7468 | /* Handle null authentication */ |
7469 | if (argv[idx_encryption]->arg[0] == 'n') { | |
7470 | SET_IF_PARAM(params, auth_type); | |
7471 | params->auth_type = OSPF_AUTH_NULL; | |
7472 | return CMD_SUCCESS; | |
7473 | } | |
718e3744 | 7474 | |
d62a17ae | 7475 | /* Handle message-digest authentication */ |
7476 | if (argv[idx_encryption]->arg[0] == 'm') { | |
7477 | SET_IF_PARAM(params, auth_type); | |
7478 | params->auth_type = OSPF_AUTH_CRYPTOGRAPHIC; | |
7479 | return CMD_SUCCESS; | |
7480 | } | |
718e3744 | 7481 | |
d62a17ae | 7482 | vty_out(vty, "You shouldn't get here!\n"); |
7483 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 7484 | } |
7485 | ||
718e3744 | 7486 | DEFUN (ip_ospf_authentication, |
7487 | ip_ospf_authentication_addr_cmd, | |
7a7be519 | 7488 | "ip ospf authentication [A.B.C.D]", |
718e3744 | 7489 | "IP Information\n" |
7490 | "OSPF interface commands\n" | |
7491 | "Enable authentication on this interface\n" | |
efd7904e | 7492 | "Address of interface\n") |
718e3744 | 7493 | { |
d62a17ae | 7494 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7495 | int idx_ipv4 = 3; | |
7496 | struct in_addr addr; | |
7497 | int ret; | |
7498 | struct ospf_if_params *params; | |
7499 | ||
7500 | params = IF_DEF_PARAMS(ifp); | |
7501 | ||
7502 | if (argc == 4) { | |
7503 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
7504 | if (!ret) { | |
7505 | vty_out(vty, | |
7506 | "Please specify interface address by A.B.C.D\n"); | |
7507 | return CMD_WARNING_CONFIG_FAILED; | |
7508 | } | |
7509 | ||
7510 | params = ospf_get_if_params(ifp, addr); | |
7511 | ospf_if_update_params(ifp, addr); | |
718e3744 | 7512 | } |
7513 | ||
d62a17ae | 7514 | SET_IF_PARAM(params, auth_type); |
7515 | params->auth_type = OSPF_AUTH_SIMPLE; | |
718e3744 | 7516 | |
d62a17ae | 7517 | return CMD_SUCCESS; |
718e3744 | 7518 | } |
7519 | ||
b4a039bf DS |
7520 | DEFUN (no_ip_ospf_authentication_args, |
7521 | no_ip_ospf_authentication_args_addr_cmd, | |
7a7be519 | 7522 | "no ip ospf authentication <null|message-digest> [A.B.C.D]", |
b4a039bf DS |
7523 | NO_STR |
7524 | "IP Information\n" | |
7525 | "OSPF interface commands\n" | |
7526 | "Enable authentication on this interface\n" | |
7527 | "Use null authentication\n" | |
7528 | "Use message-digest authentication\n" | |
efd7904e | 7529 | "Address of interface\n") |
b4a039bf | 7530 | { |
d62a17ae | 7531 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7532 | int idx_encryption = 4; | |
7533 | int idx_ipv4 = 5; | |
7534 | struct in_addr addr; | |
7535 | int ret; | |
7536 | struct ospf_if_params *params; | |
7537 | struct route_node *rn; | |
7538 | int auth_type; | |
7539 | ||
7540 | params = IF_DEF_PARAMS(ifp); | |
7541 | ||
7542 | if (argc == 6) { | |
7543 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
7544 | if (!ret) { | |
7545 | vty_out(vty, | |
7546 | "Please specify interface address by A.B.C.D\n"); | |
7547 | return CMD_WARNING_CONFIG_FAILED; | |
7548 | } | |
b4a039bf | 7549 | |
d62a17ae | 7550 | params = ospf_lookup_if_params(ifp, addr); |
7551 | if (params == NULL) { | |
7552 | vty_out(vty, "Ip Address specified is unknown\n"); | |
7553 | return CMD_WARNING_CONFIG_FAILED; | |
7554 | } | |
7555 | params->auth_type = OSPF_AUTH_NOTSET; | |
7556 | UNSET_IF_PARAM(params, auth_type); | |
7557 | if (params != IF_DEF_PARAMS(ifp)) { | |
7558 | ospf_free_if_params(ifp, addr); | |
7559 | ospf_if_update_params(ifp, addr); | |
7560 | } | |
7561 | } else { | |
7562 | if (argv[idx_encryption]->arg[0] == 'n') { | |
7563 | auth_type = OSPF_AUTH_NULL; | |
7564 | } else if (argv[idx_encryption]->arg[0] == 'm') { | |
7565 | auth_type = OSPF_AUTH_CRYPTOGRAPHIC; | |
7566 | } else { | |
7567 | vty_out(vty, "Unexpected input encountered\n"); | |
7568 | return CMD_WARNING_CONFIG_FAILED; | |
7569 | } | |
7570 | /* | |
7571 | * Here we have a case where the user has entered | |
7572 | * 'no ip ospf authentication (null | message_digest )' | |
7573 | * we need to find if we have any ip addresses underneath it | |
7574 | * that | |
7575 | * correspond to the associated type. | |
7576 | */ | |
7577 | if (params->auth_type == auth_type) { | |
7578 | params->auth_type = OSPF_AUTH_NOTSET; | |
7579 | UNSET_IF_PARAM(params, auth_type); | |
7580 | } | |
7581 | ||
7582 | for (rn = route_top(IF_OIFS_PARAMS(ifp)); rn; | |
7583 | rn = route_next(rn)) { | |
7584 | if ((params = rn->info)) { | |
7585 | if (params->auth_type == auth_type) { | |
7586 | params->auth_type = OSPF_AUTH_NOTSET; | |
7587 | UNSET_IF_PARAM(params, auth_type); | |
7588 | if (params != IF_DEF_PARAMS(ifp)) { | |
7589 | ospf_free_if_params( | |
7590 | ifp, rn->p.u.prefix4); | |
7591 | ospf_if_update_params( | |
7592 | ifp, rn->p.u.prefix4); | |
7593 | } | |
7594 | } | |
7595 | } | |
b4a039bf | 7596 | } |
b4a039bf | 7597 | } |
b4a039bf | 7598 | |
d62a17ae | 7599 | return CMD_SUCCESS; |
b4a039bf DS |
7600 | } |
7601 | ||
718e3744 | 7602 | DEFUN (no_ip_ospf_authentication, |
7603 | no_ip_ospf_authentication_addr_cmd, | |
7a7be519 | 7604 | "no ip ospf authentication [A.B.C.D]", |
718e3744 | 7605 | NO_STR |
7606 | "IP Information\n" | |
7607 | "OSPF interface commands\n" | |
7608 | "Enable authentication on this interface\n" | |
efd7904e | 7609 | "Address of interface\n") |
718e3744 | 7610 | { |
d62a17ae | 7611 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7612 | int idx_ipv4 = 4; | |
7613 | struct in_addr addr; | |
7614 | int ret; | |
7615 | struct ospf_if_params *params; | |
7616 | struct route_node *rn; | |
7617 | ||
7618 | params = IF_DEF_PARAMS(ifp); | |
7619 | ||
7620 | if (argc == 5) { | |
7621 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
7622 | if (!ret) { | |
7623 | vty_out(vty, | |
7624 | "Please specify interface address by A.B.C.D\n"); | |
7625 | return CMD_WARNING_CONFIG_FAILED; | |
7626 | } | |
718e3744 | 7627 | |
d62a17ae | 7628 | params = ospf_lookup_if_params(ifp, addr); |
7629 | if (params == NULL) { | |
7630 | vty_out(vty, "Ip Address specified is unknown\n"); | |
7631 | return CMD_WARNING_CONFIG_FAILED; | |
7632 | } | |
718e3744 | 7633 | |
d62a17ae | 7634 | params->auth_type = OSPF_AUTH_NOTSET; |
7635 | UNSET_IF_PARAM(params, auth_type); | |
7636 | if (params != IF_DEF_PARAMS(ifp)) { | |
7637 | ospf_free_if_params(ifp, addr); | |
7638 | ospf_if_update_params(ifp, addr); | |
7639 | } | |
7640 | } else { | |
7641 | /* | |
7642 | * When a user enters 'no ip ospf authentication' | |
7643 | * We should remove all authentication types from | |
7644 | * the interface. | |
7645 | */ | |
7646 | if ((params->auth_type == OSPF_AUTH_NULL) | |
7647 | || (params->auth_type == OSPF_AUTH_CRYPTOGRAPHIC) | |
7648 | || (params->auth_type == OSPF_AUTH_SIMPLE)) { | |
7649 | params->auth_type = OSPF_AUTH_NOTSET; | |
7650 | UNSET_IF_PARAM(params, auth_type); | |
7651 | } | |
813d4307 | 7652 | |
d62a17ae | 7653 | for (rn = route_top(IF_OIFS_PARAMS(ifp)); rn; |
7654 | rn = route_next(rn)) { | |
7655 | if ((params = rn->info)) { | |
7656 | ||
7657 | if ((params->auth_type == OSPF_AUTH_NULL) | |
7658 | || (params->auth_type | |
7659 | == OSPF_AUTH_CRYPTOGRAPHIC) | |
7660 | || (params->auth_type | |
7661 | == OSPF_AUTH_SIMPLE)) { | |
7662 | params->auth_type = OSPF_AUTH_NOTSET; | |
7663 | UNSET_IF_PARAM(params, auth_type); | |
7664 | if (params != IF_DEF_PARAMS(ifp)) { | |
7665 | ospf_free_if_params( | |
7666 | ifp, rn->p.u.prefix4); | |
7667 | ospf_if_update_params( | |
7668 | ifp, rn->p.u.prefix4); | |
7669 | } | |
7670 | } | |
7671 | } | |
b4a039bf | 7672 | } |
b4a039bf | 7673 | } |
d62a17ae | 7674 | |
7675 | return CMD_SUCCESS; | |
718e3744 | 7676 | } |
7677 | ||
0d829fa7 | 7678 | |
718e3744 | 7679 | DEFUN (ip_ospf_authentication_key, |
7680 | ip_ospf_authentication_key_addr_cmd, | |
7a7be519 | 7681 | "ip ospf authentication-key AUTH_KEY [A.B.C.D]", |
718e3744 | 7682 | "IP Information\n" |
7683 | "OSPF interface commands\n" | |
7684 | "Authentication password (key)\n" | |
7685 | "The OSPF password (key)\n" | |
efd7904e | 7686 | "Address of interface\n") |
718e3744 | 7687 | { |
d62a17ae | 7688 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7689 | int idx = 0; | |
7690 | struct in_addr addr; | |
7691 | struct ospf_if_params *params; | |
718e3744 | 7692 | |
d62a17ae | 7693 | params = IF_DEF_PARAMS(ifp); |
7694 | ||
7695 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
7696 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
7697 | vty_out(vty, | |
7698 | "Please specify interface address by A.B.C.D\n"); | |
7699 | return CMD_WARNING_CONFIG_FAILED; | |
7700 | } | |
718e3744 | 7701 | |
d62a17ae | 7702 | params = ospf_get_if_params(ifp, addr); |
7703 | ospf_if_update_params(ifp, addr); | |
7704 | } | |
718e3744 | 7705 | |
4d65d927 QY |
7706 | strlcpy((char *)params->auth_simple, argv[3]->arg, |
7707 | sizeof(params->auth_simple)); | |
d62a17ae | 7708 | SET_IF_PARAM(params, auth_simple); |
718e3744 | 7709 | |
d62a17ae | 7710 | return CMD_SUCCESS; |
718e3744 | 7711 | } |
7712 | ||
7a7be519 | 7713 | DEFUN_HIDDEN (ospf_authentication_key, |
747e489c | 7714 | ospf_authentication_key_cmd, |
0d829fa7 | 7715 | "ospf authentication-key AUTH_KEY [A.B.C.D]", |
747e489c | 7716 | "OSPF interface commands\n" |
baf9eaad | 7717 | VLINK_HELPSTR_AUTH_SIMPLE |
0d829fa7 | 7718 | "Address of interface\n") |
718e3744 | 7719 | { |
d62a17ae | 7720 | return ip_ospf_authentication_key(self, vty, argc, argv); |
718e3744 | 7721 | } |
7722 | ||
7a7be519 | 7723 | DEFUN (no_ip_ospf_authentication_key, |
7724 | no_ip_ospf_authentication_key_authkey_addr_cmd, | |
7725 | "no ip ospf authentication-key [AUTH_KEY [A.B.C.D]]", | |
7726 | NO_STR | |
7727 | "IP Information\n" | |
7728 | "OSPF interface commands\n" | |
baf9eaad CS |
7729 | VLINK_HELPSTR_AUTH_SIMPLE |
7730 | "Address of interface\n") | |
7a7be519 | 7731 | { |
d62a17ae | 7732 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7733 | int idx = 0; | |
7734 | struct in_addr addr; | |
7735 | struct ospf_if_params *params; | |
7736 | params = IF_DEF_PARAMS(ifp); | |
7737 | ||
7738 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
7739 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
7740 | vty_out(vty, | |
7741 | "Please specify interface address by A.B.C.D\n"); | |
7742 | return CMD_WARNING_CONFIG_FAILED; | |
7743 | } | |
7a7be519 | 7744 | |
d62a17ae | 7745 | params = ospf_lookup_if_params(ifp, addr); |
7746 | if (params == NULL) | |
7747 | return CMD_SUCCESS; | |
7a7be519 | 7748 | } |
813d4307 | 7749 | |
d62a17ae | 7750 | memset(params->auth_simple, 0, OSPF_AUTH_SIMPLE_SIZE); |
7751 | UNSET_IF_PARAM(params, auth_simple); | |
718e3744 | 7752 | |
d62a17ae | 7753 | if (params != IF_DEF_PARAMS(ifp)) { |
7754 | ospf_free_if_params(ifp, addr); | |
7755 | ospf_if_update_params(ifp, addr); | |
7756 | } | |
813d4307 | 7757 | |
d62a17ae | 7758 | return CMD_SUCCESS; |
7a7be519 | 7759 | } |
813d4307 | 7760 | |
0d829fa7 QY |
7761 | DEFUN_HIDDEN (no_ospf_authentication_key, |
7762 | no_ospf_authentication_key_authkey_addr_cmd, | |
7763 | "no ospf authentication-key [AUTH_KEY [A.B.C.D]]", | |
7764 | NO_STR | |
7765 | "OSPF interface commands\n" | |
baf9eaad CS |
7766 | VLINK_HELPSTR_AUTH_SIMPLE |
7767 | "Address of interface\n") | |
0d829fa7 | 7768 | { |
d62a17ae | 7769 | return no_ip_ospf_authentication_key(self, vty, argc, argv); |
0d829fa7 QY |
7770 | } |
7771 | ||
718e3744 | 7772 | DEFUN (ip_ospf_message_digest_key, |
537eae3f | 7773 | ip_ospf_message_digest_key_cmd, |
7a7be519 | 7774 | "ip ospf message-digest-key (1-255) md5 KEY [A.B.C.D]", |
718e3744 | 7775 | "IP Information\n" |
7776 | "OSPF interface commands\n" | |
7777 | "Message digest authentication password (key)\n" | |
7778 | "Key ID\n" | |
7779 | "Use MD5 algorithm\n" | |
fefa0d82 QY |
7780 | "The OSPF password (key)\n" |
7781 | "Address of interface\n") | |
718e3744 | 7782 | { |
d62a17ae | 7783 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7784 | struct crypt_key *ck; | |
d7c0a89a | 7785 | uint8_t key_id; |
d62a17ae | 7786 | struct in_addr addr; |
7787 | struct ospf_if_params *params; | |
7788 | ||
7789 | params = IF_DEF_PARAMS(ifp); | |
7790 | int idx = 0; | |
7791 | ||
7792 | argv_find(argv, argc, "(1-255)", &idx); | |
7793 | char *keyid = argv[idx]->arg; | |
7794 | argv_find(argv, argc, "KEY", &idx); | |
7795 | char *cryptkey = argv[idx]->arg; | |
7796 | ||
7797 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
7798 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
7799 | vty_out(vty, | |
7800 | "Please specify interface address by A.B.C.D\n"); | |
7801 | return CMD_WARNING_CONFIG_FAILED; | |
7802 | } | |
7803 | ||
7804 | params = ospf_get_if_params(ifp, addr); | |
7805 | ospf_if_update_params(ifp, addr); | |
718e3744 | 7806 | } |
7807 | ||
d62a17ae | 7808 | key_id = strtol(keyid, NULL, 10); |
519b1464 MS |
7809 | |
7810 | /* Remove existing key, if any */ | |
7811 | ospf_crypt_key_delete(params->auth_crypt, key_id); | |
718e3744 | 7812 | |
d62a17ae | 7813 | ck = ospf_crypt_key_new(); |
d7c0a89a | 7814 | ck->key_id = (uint8_t)key_id; |
4d65d927 | 7815 | strlcpy((char *)ck->auth_key, cryptkey, sizeof(ck->auth_key)); |
718e3744 | 7816 | |
d62a17ae | 7817 | ospf_crypt_key_add(params->auth_crypt, ck); |
7818 | SET_IF_PARAM(params, auth_crypt); | |
718e3744 | 7819 | |
d62a17ae | 7820 | return CMD_SUCCESS; |
718e3744 | 7821 | } |
7822 | ||
7a7be519 | 7823 | DEFUN_HIDDEN (ospf_message_digest_key, |
747e489c | 7824 | ospf_message_digest_key_cmd, |
0d829fa7 | 7825 | "ospf message-digest-key (1-255) md5 KEY [A.B.C.D]", |
747e489c DW |
7826 | "OSPF interface commands\n" |
7827 | "Message digest authentication password (key)\n" | |
7828 | "Key ID\n" | |
7829 | "Use MD5 algorithm\n" | |
0d829fa7 QY |
7830 | "The OSPF password (key)\n" |
7831 | "Address of interface\n") | |
7a7be519 | 7832 | { |
d62a17ae | 7833 | return ip_ospf_message_digest_key(self, vty, argc, argv); |
7a7be519 | 7834 | } |
718e3744 | 7835 | |
537eae3f QY |
7836 | DEFUN (no_ip_ospf_message_digest_key, |
7837 | no_ip_ospf_message_digest_key_cmd, | |
0d829fa7 | 7838 | "no ip ospf message-digest-key (1-255) [md5 KEY] [A.B.C.D]", |
813d4307 DW |
7839 | NO_STR |
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" | |
0d829fa7 QY |
7845 | "The OSPF password (key)\n" |
7846 | "Address of interface\n") | |
813d4307 | 7847 | { |
d62a17ae | 7848 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7849 | int idx = 0; | |
7850 | struct crypt_key *ck; | |
7851 | int key_id; | |
7852 | struct in_addr addr; | |
7853 | struct ospf_if_params *params; | |
7854 | params = IF_DEF_PARAMS(ifp); | |
7855 | ||
7856 | argv_find(argv, argc, "(1-255)", &idx); | |
7857 | char *keyid = argv[idx]->arg; | |
7858 | ||
7859 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
7860 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
7861 | vty_out(vty, | |
7862 | "Please specify interface address by A.B.C.D\n"); | |
7863 | return CMD_WARNING_CONFIG_FAILED; | |
7864 | } | |
7a7be519 | 7865 | |
d62a17ae | 7866 | params = ospf_lookup_if_params(ifp, addr); |
7867 | if (params == NULL) | |
7868 | return CMD_SUCCESS; | |
7a7be519 | 7869 | } |
7870 | ||
d62a17ae | 7871 | key_id = strtol(keyid, NULL, 10); |
7872 | ck = ospf_crypt_key_lookup(params->auth_crypt, key_id); | |
7873 | if (ck == NULL) { | |
7874 | vty_out(vty, "OSPF: Key %d does not exist\n", key_id); | |
7875 | return CMD_WARNING_CONFIG_FAILED; | |
7876 | } | |
7a7be519 | 7877 | |
d62a17ae | 7878 | ospf_crypt_key_delete(params->auth_crypt, key_id); |
7a7be519 | 7879 | |
d62a17ae | 7880 | if (params != IF_DEF_PARAMS(ifp)) { |
7881 | ospf_free_if_params(ifp, addr); | |
7882 | ospf_if_update_params(ifp, addr); | |
7883 | } | |
7a7be519 | 7884 | |
d62a17ae | 7885 | return CMD_SUCCESS; |
7a7be519 | 7886 | } |
813d4307 | 7887 | |
0d829fa7 | 7888 | DEFUN_HIDDEN (no_ospf_message_digest_key, |
537eae3f | 7889 | no_ospf_message_digest_key_cmd, |
0d829fa7 QY |
7890 | "no ospf message-digest-key (1-255) [md5 KEY] [A.B.C.D]", |
7891 | NO_STR | |
7892 | "OSPF interface commands\n" | |
7893 | "Message digest authentication password (key)\n" | |
7894 | "Key ID\n" | |
efd7904e RW |
7895 | "Use MD5 algorithm\n" |
7896 | "The OSPF password (key)\n" | |
7897 | "Address of interface\n") | |
718e3744 | 7898 | { |
d62a17ae | 7899 | return no_ip_ospf_message_digest_key(self, vty, argc, argv); |
718e3744 | 7900 | } |
7901 | ||
718e3744 | 7902 | DEFUN (ip_ospf_cost, |
5c2fc921 | 7903 | ip_ospf_cost_cmd, |
7a7be519 | 7904 | "ip ospf cost (1-65535) [A.B.C.D]", |
718e3744 | 7905 | "IP Information\n" |
7906 | "OSPF interface commands\n" | |
7907 | "Interface cost\n" | |
7908 | "Cost\n" | |
5c2fc921 | 7909 | "Address of interface\n") |
718e3744 | 7910 | { |
d62a17ae | 7911 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7912 | int idx = 0; | |
d7c0a89a | 7913 | uint32_t cost = OSPF_OUTPUT_COST_DEFAULT; |
d62a17ae | 7914 | struct in_addr addr; |
7915 | struct ospf_if_params *params; | |
7916 | params = IF_DEF_PARAMS(ifp); | |
7917 | ||
7918 | // get arguments | |
7919 | char *coststr = NULL, *ifaddr = NULL; | |
35955c14 | 7920 | |
c31a793b VJ |
7921 | argv_find(argv, argc, "(1-65535)", &idx); |
7922 | coststr = argv[idx]->arg; | |
d62a17ae | 7923 | cost = strtol(coststr, NULL, 10); |
7924 | ||
c31a793b | 7925 | ifaddr = argv_find(argv, argc, "A.B.C.D", &idx) ? argv[idx]->arg : NULL; |
d62a17ae | 7926 | if (ifaddr) { |
7927 | if (!inet_aton(ifaddr, &addr)) { | |
7928 | vty_out(vty, | |
7929 | "Please specify interface address by A.B.C.D\n"); | |
7930 | return CMD_WARNING_CONFIG_FAILED; | |
7931 | } | |
718e3744 | 7932 | |
d62a17ae | 7933 | params = ospf_get_if_params(ifp, addr); |
7934 | ospf_if_update_params(ifp, addr); | |
718e3744 | 7935 | } |
7936 | ||
d62a17ae | 7937 | SET_IF_PARAM(params, output_cost_cmd); |
7938 | params->output_cost_cmd = cost; | |
718e3744 | 7939 | |
d62a17ae | 7940 | ospf_if_recalculate_output_cost(ifp); |
5c2fc921 | 7941 | |
d62a17ae | 7942 | return CMD_SUCCESS; |
718e3744 | 7943 | } |
7944 | ||
7a7be519 | 7945 | DEFUN_HIDDEN (ospf_cost, |
5c2fc921 QY |
7946 | ospf_cost_cmd, |
7947 | "ospf cost (1-65535) [A.B.C.D]", | |
747e489c DW |
7948 | "OSPF interface commands\n" |
7949 | "Interface cost\n" | |
7950 | "Cost\n" | |
5c2fc921 | 7951 | "Address of interface\n") |
7a7be519 | 7952 | { |
d62a17ae | 7953 | return ip_ospf_cost(self, vty, argc, argv); |
7a7be519 | 7954 | } |
9eff36b3 | 7955 | |
718e3744 | 7956 | DEFUN (no_ip_ospf_cost, |
5c2fc921 QY |
7957 | no_ip_ospf_cost_cmd, |
7958 | "no ip ospf cost [(1-65535)] [A.B.C.D]", | |
718e3744 | 7959 | NO_STR |
efd7904e | 7960 | "IP Information\n" |
718e3744 | 7961 | "OSPF interface commands\n" |
7962 | "Interface cost\n" | |
efd7904e RW |
7963 | "Cost\n" |
7964 | "Address of interface\n") | |
718e3744 | 7965 | { |
d62a17ae | 7966 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7967 | int idx = 0; | |
7968 | struct in_addr addr; | |
7969 | struct ospf_if_params *params; | |
7a7be519 | 7970 | |
d62a17ae | 7971 | params = IF_DEF_PARAMS(ifp); |
718e3744 | 7972 | |
d62a17ae | 7973 | // get arguments |
7974 | char *ifaddr = NULL; | |
7975 | ifaddr = argv_find(argv, argc, "A.B.C.D", &idx) ? argv[idx]->arg : NULL; | |
718e3744 | 7976 | |
d62a17ae | 7977 | /* According to the semantics we are mimicking "no ip ospf cost N" is |
7978 | * always treated as "no ip ospf cost" regardless of the actual value | |
7979 | * of N already configured for the interface. Thus ignore cost. */ | |
7a7be519 | 7980 | |
d62a17ae | 7981 | if (ifaddr) { |
7982 | if (!inet_aton(ifaddr, &addr)) { | |
7983 | vty_out(vty, | |
7984 | "Please specify interface address by A.B.C.D\n"); | |
7985 | return CMD_WARNING_CONFIG_FAILED; | |
7986 | } | |
7a7be519 | 7987 | |
d62a17ae | 7988 | params = ospf_lookup_if_params(ifp, addr); |
7989 | if (params == NULL) | |
7990 | return CMD_SUCCESS; | |
7991 | } | |
7a7be519 | 7992 | |
d62a17ae | 7993 | UNSET_IF_PARAM(params, output_cost_cmd); |
7a7be519 | 7994 | |
d62a17ae | 7995 | if (params != IF_DEF_PARAMS(ifp)) { |
7996 | ospf_free_if_params(ifp, addr); | |
7997 | ospf_if_update_params(ifp, addr); | |
7998 | } | |
7a7be519 | 7999 | |
d62a17ae | 8000 | ospf_if_recalculate_output_cost(ifp); |
7a7be519 | 8001 | |
d62a17ae | 8002 | return CMD_SUCCESS; |
7a7be519 | 8003 | } |
9eff36b3 | 8004 | |
5c2fc921 QY |
8005 | DEFUN_HIDDEN (no_ospf_cost, |
8006 | no_ospf_cost_cmd, | |
8007 | "no ospf cost [(1-65535)] [A.B.C.D]", | |
8008 | NO_STR | |
8009 | "OSPF interface commands\n" | |
8010 | "Interface cost\n" | |
8011 | "Cost\n" | |
8012 | "Address of interface\n") | |
827341b7 | 8013 | { |
d62a17ae | 8014 | return no_ip_ospf_cost(self, vty, argc, argv); |
827341b7 DO |
8015 | } |
8016 | ||
d62a17ae | 8017 | static void ospf_nbr_timer_update(struct ospf_interface *oi) |
718e3744 | 8018 | { |
d62a17ae | 8019 | struct route_node *rn; |
8020 | struct ospf_neighbor *nbr; | |
718e3744 | 8021 | |
d62a17ae | 8022 | for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) |
8023 | if ((nbr = rn->info)) { | |
8024 | nbr->v_inactivity = OSPF_IF_PARAM(oi, v_wait); | |
8025 | nbr->v_db_desc = OSPF_IF_PARAM(oi, retransmit_interval); | |
8026 | nbr->v_ls_req = OSPF_IF_PARAM(oi, retransmit_interval); | |
8027 | nbr->v_ls_upd = OSPF_IF_PARAM(oi, retransmit_interval); | |
8028 | } | |
718e3744 | 8029 | } |
8030 | ||
d62a17ae | 8031 | static int ospf_vty_dead_interval_set(struct vty *vty, const char *interval_str, |
8032 | const char *nbr_str, | |
8033 | const char *fast_hello_str) | |
8034 | { | |
8035 | VTY_DECLVAR_CONTEXT(interface, ifp); | |
d7c0a89a QY |
8036 | uint32_t seconds; |
8037 | uint8_t hellomult; | |
d62a17ae | 8038 | struct in_addr addr; |
8039 | int ret; | |
8040 | struct ospf_if_params *params; | |
8041 | struct ospf_interface *oi; | |
8042 | struct route_node *rn; | |
718e3744 | 8043 | |
d62a17ae | 8044 | params = IF_DEF_PARAMS(ifp); |
8045 | ||
8046 | if (nbr_str) { | |
8047 | ret = inet_aton(nbr_str, &addr); | |
8048 | if (!ret) { | |
8049 | vty_out(vty, | |
8050 | "Please specify interface address by A.B.C.D\n"); | |
8051 | return CMD_WARNING_CONFIG_FAILED; | |
8052 | } | |
8053 | ||
8054 | params = ospf_get_if_params(ifp, addr); | |
8055 | ospf_if_update_params(ifp, addr); | |
8056 | } | |
8057 | ||
8058 | if (interval_str) { | |
8059 | seconds = strtoul(interval_str, NULL, 10); | |
8060 | ||
8061 | /* reset fast_hello too, just to be sure */ | |
8062 | UNSET_IF_PARAM(params, fast_hello); | |
8063 | params->fast_hello = OSPF_FAST_HELLO_DEFAULT; | |
8064 | } else if (fast_hello_str) { | |
8065 | hellomult = strtoul(fast_hello_str, NULL, 10); | |
8066 | /* 1s dead-interval with sub-second hellos desired */ | |
8067 | seconds = OSPF_ROUTER_DEAD_INTERVAL_MINIMAL; | |
8068 | SET_IF_PARAM(params, fast_hello); | |
8069 | params->fast_hello = hellomult; | |
8070 | } else { | |
8071 | vty_out(vty, | |
8072 | "Please specify dead-interval or hello-multiplier\n"); | |
8073 | return CMD_WARNING_CONFIG_FAILED; | |
8074 | } | |
8075 | ||
8076 | SET_IF_PARAM(params, v_wait); | |
8077 | params->v_wait = seconds; | |
182d6bdc | 8078 | params->is_v_wait_set = true; |
d62a17ae | 8079 | |
8080 | /* Update timer values in neighbor structure. */ | |
8081 | if (nbr_str) { | |
b5a8894d CS |
8082 | struct ospf *ospf = NULL; |
8083 | ||
096f7609 | 8084 | ospf = ifp->vrf->info; |
b5a8894d | 8085 | if (ospf) { |
d62a17ae | 8086 | oi = ospf_if_lookup_by_local_addr(ospf, ifp, addr); |
8087 | if (oi) | |
8088 | ospf_nbr_timer_update(oi); | |
8089 | } | |
8090 | } else { | |
8091 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) | |
8092 | if ((oi = rn->info)) | |
8093 | ospf_nbr_timer_update(oi); | |
8094 | } | |
8095 | ||
8096 | return CMD_SUCCESS; | |
718e3744 | 8097 | } |
8098 | ||
f9ad937f | 8099 | DEFUN (ip_ospf_dead_interval, |
0d829fa7 | 8100 | ip_ospf_dead_interval_cmd, |
7a7be519 | 8101 | "ip ospf dead-interval (1-65535) [A.B.C.D]", |
f9ad937f | 8102 | "IP Information\n" |
8103 | "OSPF interface commands\n" | |
99a522c7 | 8104 | "Interval time after which a neighbor is declared down\n" |
f9ad937f | 8105 | "Seconds\n" |
8106 | "Address of interface\n") | |
8107 | { | |
d62a17ae | 8108 | int idx = 0; |
8109 | char *interval = argv_find(argv, argc, "(1-65535)", &idx) | |
8110 | ? argv[idx]->arg | |
8111 | : NULL; | |
8112 | char *ifaddr = | |
8113 | argv_find(argv, argc, "A.B.C.D", &idx) ? argv[idx]->arg : NULL; | |
8114 | return ospf_vty_dead_interval_set(vty, interval, ifaddr, NULL); | |
f9ad937f | 8115 | } |
8116 | ||
718e3744 | 8117 | |
7a7be519 | 8118 | DEFUN_HIDDEN (ospf_dead_interval, |
747e489c | 8119 | ospf_dead_interval_cmd, |
0d829fa7 | 8120 | "ospf dead-interval (1-65535) [A.B.C.D]", |
747e489c | 8121 | "OSPF interface commands\n" |
99a522c7 | 8122 | "Interval time after which a neighbor is declared down\n" |
0d829fa7 QY |
8123 | "Seconds\n" |
8124 | "Address of interface\n") | |
7a7be519 | 8125 | { |
d62a17ae | 8126 | return ip_ospf_dead_interval(self, vty, argc, argv); |
7a7be519 | 8127 | } |
718e3744 | 8128 | |
f9ad937f | 8129 | DEFUN (ip_ospf_dead_interval_minimal, |
8130 | ip_ospf_dead_interval_minimal_addr_cmd, | |
7a7be519 | 8131 | "ip ospf dead-interval minimal hello-multiplier (1-10) [A.B.C.D]", |
f9ad937f | 8132 | "IP Information\n" |
8133 | "OSPF interface commands\n" | |
99a522c7 | 8134 | "Interval time after which a neighbor is declared down\n" |
f9ad937f | 8135 | "Minimal 1s dead-interval with fast sub-second hellos\n" |
8136 | "Hello multiplier factor\n" | |
8137 | "Number of Hellos to send each second\n" | |
8138 | "Address of interface\n") | |
8139 | { | |
d62a17ae | 8140 | int idx_number = 5; |
8141 | int idx_ipv4 = 6; | |
8142 | if (argc == 7) | |
8143 | return ospf_vty_dead_interval_set( | |
8144 | vty, NULL, argv[idx_ipv4]->arg, argv[idx_number]->arg); | |
8145 | else | |
8146 | return ospf_vty_dead_interval_set(vty, NULL, NULL, | |
8147 | argv[idx_number]->arg); | |
f9ad937f | 8148 | } |
8149 | ||
718e3744 | 8150 | DEFUN (no_ip_ospf_dead_interval, |
0d829fa7 | 8151 | no_ip_ospf_dead_interval_cmd, |
e83a9414 | 8152 | "no ip ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]", |
718e3744 | 8153 | NO_STR |
8154 | "IP Information\n" | |
8155 | "OSPF interface commands\n" | |
99a522c7 | 8156 | "Interval time after which a neighbor is declared down\n" |
f9dfba8d | 8157 | "Seconds\n" |
efd7904e RW |
8158 | "Minimal 1s dead-interval with fast sub-second hellos\n" |
8159 | "Hello multiplier factor\n" | |
8160 | "Number of Hellos to send each second\n" | |
8161 | "Address of interface\n") | |
718e3744 | 8162 | { |
d62a17ae | 8163 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8164 | int idx_ipv4 = argc - 1; | |
8165 | struct in_addr addr = {.s_addr = 0L}; | |
8166 | int ret; | |
8167 | struct ospf_if_params *params; | |
8168 | struct ospf_interface *oi; | |
8169 | struct route_node *rn; | |
8170 | ||
8171 | params = IF_DEF_PARAMS(ifp); | |
8172 | ||
8173 | if (argv[idx_ipv4]->type == IPV4_TKN) { | |
8174 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
8175 | if (!ret) { | |
8176 | vty_out(vty, | |
8177 | "Please specify interface address by A.B.C.D\n"); | |
8178 | return CMD_WARNING_CONFIG_FAILED; | |
8179 | } | |
020709f9 | 8180 | |
d62a17ae | 8181 | params = ospf_lookup_if_params(ifp, addr); |
8182 | if (params == NULL) | |
8183 | return CMD_SUCCESS; | |
8184 | } | |
718e3744 | 8185 | |
d62a17ae | 8186 | UNSET_IF_PARAM(params, v_wait); |
8187 | params->v_wait = OSPF_ROUTER_DEAD_INTERVAL_DEFAULT; | |
182d6bdc | 8188 | params->is_v_wait_set = false; |
d62a17ae | 8189 | |
8190 | UNSET_IF_PARAM(params, fast_hello); | |
8191 | params->fast_hello = OSPF_FAST_HELLO_DEFAULT; | |
8192 | ||
8193 | if (params != IF_DEF_PARAMS(ifp)) { | |
8194 | ospf_free_if_params(ifp, addr); | |
8195 | ospf_if_update_params(ifp, addr); | |
718e3744 | 8196 | } |
8197 | ||
d62a17ae | 8198 | /* Update timer values in neighbor structure. */ |
8199 | if (argc == 1) { | |
b5a8894d | 8200 | struct ospf *ospf = NULL; |
718e3744 | 8201 | |
096f7609 | 8202 | ospf = ifp->vrf->info; |
b5a8894d | 8203 | if (ospf) { |
d62a17ae | 8204 | oi = ospf_if_lookup_by_local_addr(ospf, ifp, addr); |
8205 | if (oi) | |
8206 | ospf_nbr_timer_update(oi); | |
8207 | } | |
8208 | } else { | |
8209 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) | |
8210 | if ((oi = rn->info)) | |
8211 | ospf_nbr_timer_update(oi); | |
8212 | } | |
8213 | ||
8214 | return CMD_SUCCESS; | |
718e3744 | 8215 | } |
8216 | ||
0d829fa7 QY |
8217 | DEFUN_HIDDEN (no_ospf_dead_interval, |
8218 | no_ospf_dead_interval_cmd, | |
8219 | "no ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]", | |
8220 | NO_STR | |
8221 | "OSPF interface commands\n" | |
99a522c7 | 8222 | "Interval time after which a neighbor is declared down\n" |
0d829fa7 | 8223 | "Seconds\n" |
efd7904e RW |
8224 | "Minimal 1s dead-interval with fast sub-second hellos\n" |
8225 | "Hello multiplier factor\n" | |
8226 | "Number of Hellos to send each second\n" | |
8227 | "Address of interface\n") | |
0d829fa7 | 8228 | { |
d62a17ae | 8229 | return no_ip_ospf_dead_interval(self, vty, argc, argv); |
0d829fa7 QY |
8230 | } |
8231 | ||
718e3744 | 8232 | DEFUN (ip_ospf_hello_interval, |
0d829fa7 | 8233 | ip_ospf_hello_interval_cmd, |
7a7be519 | 8234 | "ip ospf hello-interval (1-65535) [A.B.C.D]", |
718e3744 | 8235 | "IP Information\n" |
8236 | "OSPF interface commands\n" | |
8237 | "Time between HELLO packets\n" | |
8238 | "Seconds\n" | |
0d829fa7 | 8239 | "Address of interface\n") |
718e3744 | 8240 | { |
d62a17ae | 8241 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8242 | int idx = 0; | |
be418160 | 8243 | struct in_addr addr = {.s_addr = 0L}; |
d62a17ae | 8244 | struct ospf_if_params *params; |
8245 | params = IF_DEF_PARAMS(ifp); | |
d7c0a89a | 8246 | uint32_t seconds = 0; |
be418160 | 8247 | bool is_addr = false; |
8248 | uint32_t old_interval = 0; | |
d62a17ae | 8249 | |
8250 | argv_find(argv, argc, "(1-65535)", &idx); | |
8251 | seconds = strtol(argv[idx]->arg, NULL, 10); | |
8252 | ||
8253 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
8254 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
8255 | vty_out(vty, | |
8256 | "Please specify interface address by A.B.C.D\n"); | |
8257 | return CMD_WARNING_CONFIG_FAILED; | |
8258 | } | |
718e3744 | 8259 | |
d62a17ae | 8260 | params = ospf_get_if_params(ifp, addr); |
8261 | ospf_if_update_params(ifp, addr); | |
be418160 | 8262 | is_addr = true; |
d62a17ae | 8263 | } |
718e3744 | 8264 | |
be418160 | 8265 | old_interval = params->v_hello; |
8266 | ||
8267 | /* Return, if same interval is configured. */ | |
8268 | if (old_interval == seconds) | |
8269 | return CMD_SUCCESS; | |
8270 | ||
d62a17ae | 8271 | SET_IF_PARAM(params, v_hello); |
8272 | params->v_hello = seconds; | |
718e3744 | 8273 | |
182d6bdc K |
8274 | if (!params->is_v_wait_set) { |
8275 | SET_IF_PARAM(params, v_wait); | |
8276 | /* As per RFC 4062 | |
8277 | * The router dead interval should | |
8278 | * be some multiple of the HelloInterval (perhaps 4 times the | |
8279 | * hello interval) and must be the same for all routers | |
8280 | * attached to a common network. | |
8281 | */ | |
8282 | params->v_wait = 4 * seconds; | |
8283 | } | |
8284 | ||
be418160 | 8285 | ospf_reset_hello_timer(ifp, addr, is_addr); |
8286 | ||
d62a17ae | 8287 | return CMD_SUCCESS; |
718e3744 | 8288 | } |
8289 | ||
7a7be519 | 8290 | DEFUN_HIDDEN (ospf_hello_interval, |
747e489c | 8291 | ospf_hello_interval_cmd, |
0d829fa7 | 8292 | "ospf hello-interval (1-65535) [A.B.C.D]", |
747e489c DW |
8293 | "OSPF interface commands\n" |
8294 | "Time between HELLO packets\n" | |
0d829fa7 QY |
8295 | "Seconds\n" |
8296 | "Address of interface\n") | |
7a7be519 | 8297 | { |
d62a17ae | 8298 | return ip_ospf_hello_interval(self, vty, argc, argv); |
7a7be519 | 8299 | } |
718e3744 | 8300 | |
8301 | DEFUN (no_ip_ospf_hello_interval, | |
0d829fa7 QY |
8302 | no_ip_ospf_hello_interval_cmd, |
8303 | "no ip ospf hello-interval [(1-65535) [A.B.C.D]]", | |
718e3744 | 8304 | NO_STR |
8305 | "IP Information\n" | |
8306 | "OSPF interface commands\n" | |
0d829fa7 | 8307 | "Time between HELLO packets\n" // ignored |
f9dfba8d | 8308 | "Seconds\n" |
0d829fa7 | 8309 | "Address of interface\n") |
718e3744 | 8310 | { |
d62a17ae | 8311 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8312 | int idx = 0; | |
be418160 | 8313 | struct in_addr addr = {.s_addr = 0L}; |
d62a17ae | 8314 | struct ospf_if_params *params; |
182d6bdc | 8315 | struct route_node *rn; |
df581cd3 | 8316 | |
d62a17ae | 8317 | params = IF_DEF_PARAMS(ifp); |
718e3744 | 8318 | |
d62a17ae | 8319 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { |
8320 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
8321 | vty_out(vty, | |
8322 | "Please specify interface address by A.B.C.D\n"); | |
8323 | return CMD_WARNING_CONFIG_FAILED; | |
8324 | } | |
718e3744 | 8325 | |
d62a17ae | 8326 | params = ospf_lookup_if_params(ifp, addr); |
8327 | if (params == NULL) | |
8328 | return CMD_SUCCESS; | |
8329 | } | |
718e3744 | 8330 | |
d62a17ae | 8331 | UNSET_IF_PARAM(params, v_hello); |
8332 | params->v_hello = OSPF_HELLO_INTERVAL_DEFAULT; | |
718e3744 | 8333 | |
182d6bdc K |
8334 | if (!params->is_v_wait_set) { |
8335 | UNSET_IF_PARAM(params, v_wait); | |
8336 | params->v_wait = OSPF_ROUTER_DEAD_INTERVAL_DEFAULT; | |
8337 | } | |
8338 | ||
8339 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { | |
8340 | struct ospf_interface *oi = rn->info; | |
8341 | ||
8342 | if (!oi) | |
8343 | continue; | |
8344 | ||
8345 | oi->type = IF_DEF_PARAMS(ifp)->type; | |
bc97889b | 8346 | oi->ptp_dmvpn = IF_DEF_PARAMS(ifp)->ptp_dmvpn; |
182d6bdc K |
8347 | |
8348 | if (oi->state > ISM_Down) { | |
8349 | OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceDown); | |
8350 | OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceUp); | |
8351 | } | |
8352 | } | |
8353 | ||
d62a17ae | 8354 | if (params != IF_DEF_PARAMS(ifp)) { |
8355 | ospf_free_if_params(ifp, addr); | |
8356 | ospf_if_update_params(ifp, addr); | |
8357 | } | |
718e3744 | 8358 | |
d62a17ae | 8359 | return CMD_SUCCESS; |
718e3744 | 8360 | } |
8361 | ||
0d829fa7 QY |
8362 | DEFUN_HIDDEN (no_ospf_hello_interval, |
8363 | no_ospf_hello_interval_cmd, | |
8364 | "no ospf hello-interval [(1-65535) [A.B.C.D]]", | |
8365 | NO_STR | |
8366 | "OSPF interface commands\n" | |
8367 | "Time between HELLO packets\n" // ignored | |
8368 | "Seconds\n" | |
8369 | "Address of interface\n") | |
8370 | { | |
d62a17ae | 8371 | return no_ip_ospf_hello_interval(self, vty, argc, argv); |
0d829fa7 | 8372 | } |
718e3744 | 8373 | |
bc97889b AL |
8374 | DEFUN(ip_ospf_network, ip_ospf_network_cmd, |
8375 | "ip ospf network <broadcast|non-broadcast|point-to-multipoint|point-to-point [dmvpn]>", | |
8376 | "IP Information\n" | |
8377 | "OSPF interface commands\n" | |
8378 | "Network type\n" | |
8379 | "Specify OSPF broadcast multi-access network\n" | |
8380 | "Specify OSPF NBMA network\n" | |
8381 | "Specify OSPF point-to-multipoint network\n" | |
8382 | "Specify OSPF point-to-point network\n" | |
8383 | "Specify OSPF point-to-point DMVPN network\n") | |
718e3744 | 8384 | { |
d62a17ae | 8385 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8386 | int idx = 0; | |
8387 | int old_type = IF_DEF_PARAMS(ifp)->type; | |
bc97889b | 8388 | uint8_t old_ptp_dmvpn = IF_DEF_PARAMS(ifp)->ptp_dmvpn; |
d62a17ae | 8389 | struct route_node *rn; |
718e3744 | 8390 | |
d62a17ae | 8391 | if (old_type == OSPF_IFTYPE_LOOPBACK) { |
8392 | vty_out(vty, | |
8393 | "This is a loopback interface. Can't set network type.\n"); | |
8394 | return CMD_WARNING_CONFIG_FAILED; | |
8395 | } | |
718e3744 | 8396 | |
bc97889b AL |
8397 | IF_DEF_PARAMS(ifp)->ptp_dmvpn = 0; |
8398 | ||
d62a17ae | 8399 | if (argv_find(argv, argc, "broadcast", &idx)) |
8400 | IF_DEF_PARAMS(ifp)->type = OSPF_IFTYPE_BROADCAST; | |
8401 | else if (argv_find(argv, argc, "non-broadcast", &idx)) | |
8402 | IF_DEF_PARAMS(ifp)->type = OSPF_IFTYPE_NBMA; | |
8403 | else if (argv_find(argv, argc, "point-to-multipoint", &idx)) | |
8404 | IF_DEF_PARAMS(ifp)->type = OSPF_IFTYPE_POINTOMULTIPOINT; | |
bc97889b | 8405 | else if (argv_find(argv, argc, "point-to-point", &idx)) { |
d62a17ae | 8406 | IF_DEF_PARAMS(ifp)->type = OSPF_IFTYPE_POINTOPOINT; |
bc97889b AL |
8407 | if (argv_find(argv, argc, "dmvpn", &idx)) |
8408 | IF_DEF_PARAMS(ifp)->ptp_dmvpn = 1; | |
8409 | } | |
718e3744 | 8410 | |
bc97889b AL |
8411 | if (IF_DEF_PARAMS(ifp)->type == old_type |
8412 | && IF_DEF_PARAMS(ifp)->ptp_dmvpn == old_ptp_dmvpn) | |
d62a17ae | 8413 | return CMD_SUCCESS; |
8414 | ||
8415 | SET_IF_PARAM(IF_DEF_PARAMS(ifp), type); | |
8416 | ||
8417 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { | |
8418 | struct ospf_interface *oi = rn->info; | |
8419 | ||
8420 | if (!oi) | |
8421 | continue; | |
8422 | ||
8423 | oi->type = IF_DEF_PARAMS(ifp)->type; | |
8424 | ||
8425 | if (oi->state > ISM_Down) { | |
8426 | OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceDown); | |
8427 | OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceUp); | |
8428 | } | |
7a7be519 | 8429 | } |
7a7be519 | 8430 | |
d62a17ae | 8431 | return CMD_SUCCESS; |
7a7be519 | 8432 | } |
8433 | ||
8434 | DEFUN_HIDDEN (ospf_network, | |
8435 | ospf_network_cmd, | |
e83a9414 | 8436 | "ospf network <broadcast|non-broadcast|point-to-multipoint|point-to-point>", |
7a7be519 | 8437 | "OSPF interface commands\n" |
8438 | "Network type\n" | |
8439 | "Specify OSPF broadcast multi-access network\n" | |
8440 | "Specify OSPF NBMA network\n" | |
8441 | "Specify OSPF point-to-multipoint network\n" | |
8442 | "Specify OSPF point-to-point network\n") | |
8443 | { | |
d62a17ae | 8444 | return ip_ospf_network(self, vty, argc, argv); |
7a7be519 | 8445 | } |
8446 | ||
8447 | DEFUN (no_ip_ospf_network, | |
8448 | no_ip_ospf_network_cmd, | |
8449 | "no ip ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]", | |
8450 | NO_STR | |
8451 | "IP Information\n" | |
8452 | "OSPF interface commands\n" | |
8453 | "Network type\n" | |
8454 | "Specify OSPF broadcast multi-access network\n" | |
8455 | "Specify OSPF NBMA network\n" | |
8456 | "Specify OSPF point-to-multipoint network\n" | |
8457 | "Specify OSPF point-to-point network\n") | |
22b27e95 | 8458 | { |
d62a17ae | 8459 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8460 | int old_type = IF_DEF_PARAMS(ifp)->type; | |
8461 | struct route_node *rn; | |
7a7be519 | 8462 | |
d62a17ae | 8463 | IF_DEF_PARAMS(ifp)->type = ospf_default_iftype(ifp); |
bc97889b | 8464 | IF_DEF_PARAMS(ifp)->ptp_dmvpn = 0; |
7a7be519 | 8465 | |
d62a17ae | 8466 | if (IF_DEF_PARAMS(ifp)->type == old_type) |
8467 | return CMD_SUCCESS; | |
7a7be519 | 8468 | |
d62a17ae | 8469 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { |
8470 | struct ospf_interface *oi = rn->info; | |
7a7be519 | 8471 | |
d62a17ae | 8472 | if (!oi) |
8473 | continue; | |
7a7be519 | 8474 | |
d62a17ae | 8475 | oi->type = IF_DEF_PARAMS(ifp)->type; |
7a7be519 | 8476 | |
d62a17ae | 8477 | if (oi->state > ISM_Down) { |
8478 | OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceDown); | |
8479 | OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceUp); | |
8480 | } | |
7a7be519 | 8481 | } |
7a7be519 | 8482 | |
d62a17ae | 8483 | return CMD_SUCCESS; |
7a7be519 | 8484 | } |
8485 | ||
0d829fa7 QY |
8486 | DEFUN_HIDDEN (no_ospf_network, |
8487 | no_ospf_network_cmd, | |
8488 | "no ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]", | |
8489 | NO_STR | |
8490 | "OSPF interface commands\n" | |
8491 | "Network type\n" | |
8492 | "Specify OSPF broadcast multi-access network\n" | |
8493 | "Specify OSPF NBMA network\n" | |
8494 | "Specify OSPF point-to-multipoint network\n" | |
8495 | "Specify OSPF point-to-point network\n") | |
8496 | { | |
d62a17ae | 8497 | return no_ip_ospf_network(self, vty, argc, argv); |
0d829fa7 QY |
8498 | } |
8499 | ||
7a7be519 | 8500 | DEFUN (ip_ospf_priority, |
537eae3f | 8501 | ip_ospf_priority_cmd, |
7a7be519 | 8502 | "ip ospf priority (0-255) [A.B.C.D]", |
8503 | "IP Information\n" | |
8504 | "OSPF interface commands\n" | |
8505 | "Router priority\n" | |
8506 | "Priority\n" | |
efd7904e | 8507 | "Address of interface\n") |
7a7be519 | 8508 | { |
d62a17ae | 8509 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8510 | int idx = 0; | |
8511 | long priority; | |
8512 | struct route_node *rn; | |
8513 | struct in_addr addr; | |
8514 | struct ospf_if_params *params; | |
8515 | params = IF_DEF_PARAMS(ifp); | |
8516 | ||
8517 | argv_find(argv, argc, "(0-255)", &idx); | |
8518 | priority = strtol(argv[idx]->arg, NULL, 10); | |
8519 | ||
8520 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
8521 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
8522 | vty_out(vty, | |
8523 | "Please specify interface address by A.B.C.D\n"); | |
8524 | return CMD_WARNING_CONFIG_FAILED; | |
8525 | } | |
7a7be519 | 8526 | |
d62a17ae | 8527 | params = ospf_get_if_params(ifp, addr); |
8528 | ospf_if_update_params(ifp, addr); | |
7a7be519 | 8529 | } |
8530 | ||
d62a17ae | 8531 | SET_IF_PARAM(params, priority); |
8532 | params->priority = priority; | |
7a7be519 | 8533 | |
d62a17ae | 8534 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { |
8535 | struct ospf_interface *oi = rn->info; | |
7a7be519 | 8536 | |
d62a17ae | 8537 | if (!oi) |
8538 | continue; | |
7a7be519 | 8539 | |
d62a17ae | 8540 | if (PRIORITY(oi) != OSPF_IF_PARAM(oi, priority)) { |
8541 | PRIORITY(oi) = OSPF_IF_PARAM(oi, priority); | |
8542 | OSPF_ISM_EVENT_SCHEDULE(oi, ISM_NeighborChange); | |
8543 | } | |
718e3744 | 8544 | } |
718e3744 | 8545 | |
d62a17ae | 8546 | return CMD_SUCCESS; |
718e3744 | 8547 | } |
8548 | ||
7a7be519 | 8549 | DEFUN_HIDDEN (ospf_priority, |
8550 | ospf_priority_cmd, | |
0d829fa7 | 8551 | "ospf priority (0-255) [A.B.C.D]", |
7a7be519 | 8552 | "OSPF interface commands\n" |
8553 | "Router priority\n" | |
3a2d747c | 8554 | "Priority\n" |
efd7904e | 8555 | "Address of interface\n") |
718e3744 | 8556 | { |
d62a17ae | 8557 | return ip_ospf_priority(self, vty, argc, argv); |
718e3744 | 8558 | } |
8559 | ||
718e3744 | 8560 | DEFUN (no_ip_ospf_priority, |
537eae3f | 8561 | no_ip_ospf_priority_cmd, |
7a7be519 | 8562 | "no ip ospf priority [(0-255) [A.B.C.D]]", |
718e3744 | 8563 | NO_STR |
8564 | "IP Information\n" | |
8565 | "OSPF interface commands\n" | |
0d829fa7 | 8566 | "Router priority\n" // ignored |
813d4307 | 8567 | "Priority\n" |
efd7904e | 8568 | "Address of interface\n") |
718e3744 | 8569 | { |
d62a17ae | 8570 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8571 | int idx = 0; | |
8572 | struct route_node *rn; | |
8573 | struct in_addr addr; | |
8574 | struct ospf_if_params *params; | |
8575 | ||
8576 | params = IF_DEF_PARAMS(ifp); | |
8577 | ||
8578 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
8579 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
8580 | vty_out(vty, | |
8581 | "Please specify interface address by A.B.C.D\n"); | |
8582 | return CMD_WARNING_CONFIG_FAILED; | |
8583 | } | |
8584 | ||
8585 | params = ospf_lookup_if_params(ifp, addr); | |
8586 | if (params == NULL) | |
8587 | return CMD_SUCCESS; | |
718e3744 | 8588 | } |
8589 | ||
d62a17ae | 8590 | UNSET_IF_PARAM(params, priority); |
8591 | params->priority = OSPF_ROUTER_PRIORITY_DEFAULT; | |
8592 | ||
8593 | if (params != IF_DEF_PARAMS(ifp)) { | |
8594 | ospf_free_if_params(ifp, addr); | |
8595 | ospf_if_update_params(ifp, addr); | |
718e3744 | 8596 | } |
d62a17ae | 8597 | |
8598 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { | |
8599 | struct ospf_interface *oi = rn->info; | |
8600 | ||
8601 | if (!oi) | |
8602 | continue; | |
8603 | ||
8604 | if (PRIORITY(oi) != OSPF_IF_PARAM(oi, priority)) { | |
8605 | PRIORITY(oi) = OSPF_IF_PARAM(oi, priority); | |
8606 | OSPF_ISM_EVENT_SCHEDULE(oi, ISM_NeighborChange); | |
8607 | } | |
8608 | } | |
8609 | ||
8610 | return CMD_SUCCESS; | |
718e3744 | 8611 | } |
8612 | ||
0d829fa7 | 8613 | DEFUN_HIDDEN (no_ospf_priority, |
537eae3f | 8614 | no_ospf_priority_cmd, |
0d829fa7 QY |
8615 | "no ospf priority [(0-255) [A.B.C.D]]", |
8616 | NO_STR | |
8617 | "OSPF interface commands\n" | |
8618 | "Router priority\n" | |
8619 | "Priority\n" | |
efd7904e | 8620 | "Address of interface\n") |
0d829fa7 | 8621 | { |
d62a17ae | 8622 | return no_ip_ospf_priority(self, vty, argc, argv); |
0d829fa7 | 8623 | } |
a1afa410 | 8624 | |
718e3744 | 8625 | DEFUN (ip_ospf_retransmit_interval, |
8626 | ip_ospf_retransmit_interval_addr_cmd, | |
d4badaf6 | 8627 | "ip ospf retransmit-interval (1-65535) [A.B.C.D]", |
718e3744 | 8628 | "IP Information\n" |
8629 | "OSPF interface commands\n" | |
8630 | "Time between retransmitting lost link state advertisements\n" | |
8631 | "Seconds\n" | |
efd7904e | 8632 | "Address of interface\n") |
718e3744 | 8633 | { |
d62a17ae | 8634 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8635 | int idx = 0; | |
d7c0a89a | 8636 | uint32_t seconds; |
d62a17ae | 8637 | struct in_addr addr; |
8638 | struct ospf_if_params *params; | |
8639 | params = IF_DEF_PARAMS(ifp); | |
8640 | ||
d4badaf6 | 8641 | argv_find(argv, argc, "(1-65535)", &idx); |
d62a17ae | 8642 | seconds = strtol(argv[idx]->arg, NULL, 10); |
8643 | ||
8644 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
8645 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
8646 | vty_out(vty, | |
8647 | "Please specify interface address by A.B.C.D\n"); | |
8648 | return CMD_WARNING_CONFIG_FAILED; | |
8649 | } | |
718e3744 | 8650 | |
d62a17ae | 8651 | params = ospf_get_if_params(ifp, addr); |
8652 | ospf_if_update_params(ifp, addr); | |
718e3744 | 8653 | } |
8654 | ||
d62a17ae | 8655 | SET_IF_PARAM(params, retransmit_interval); |
8656 | params->retransmit_interval = seconds; | |
718e3744 | 8657 | |
d62a17ae | 8658 | return CMD_SUCCESS; |
718e3744 | 8659 | } |
8660 | ||
7a7be519 | 8661 | DEFUN_HIDDEN (ospf_retransmit_interval, |
747e489c | 8662 | ospf_retransmit_interval_cmd, |
d4badaf6 | 8663 | "ospf retransmit-interval (1-65535) [A.B.C.D]", |
747e489c DW |
8664 | "OSPF interface commands\n" |
8665 | "Time between retransmitting lost link state advertisements\n" | |
3a2d747c | 8666 | "Seconds\n" |
efd7904e | 8667 | "Address of interface\n") |
7a7be519 | 8668 | { |
d62a17ae | 8669 | return ip_ospf_retransmit_interval(self, vty, argc, argv); |
7a7be519 | 8670 | } |
718e3744 | 8671 | |
8672 | DEFUN (no_ip_ospf_retransmit_interval, | |
8673 | no_ip_ospf_retransmit_interval_addr_cmd, | |
d4badaf6 | 8674 | "no ip ospf retransmit-interval [(1-65535)] [A.B.C.D]", |
718e3744 | 8675 | NO_STR |
8676 | "IP Information\n" | |
8677 | "OSPF interface commands\n" | |
3a2d747c QY |
8678 | "Time between retransmitting lost link state advertisements\n" |
8679 | "Seconds\n" | |
0d829fa7 | 8680 | "Address of interface\n") |
718e3744 | 8681 | { |
d62a17ae | 8682 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8683 | int idx = 0; | |
8684 | struct in_addr addr; | |
8685 | struct ospf_if_params *params; | |
47b91972 | 8686 | |
d62a17ae | 8687 | params = IF_DEF_PARAMS(ifp); |
718e3744 | 8688 | |
d62a17ae | 8689 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { |
8690 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
8691 | vty_out(vty, | |
8692 | "Please specify interface address by A.B.C.D\n"); | |
8693 | return CMD_WARNING_CONFIG_FAILED; | |
8694 | } | |
718e3744 | 8695 | |
d62a17ae | 8696 | params = ospf_lookup_if_params(ifp, addr); |
8697 | if (params == NULL) | |
8698 | return CMD_SUCCESS; | |
8699 | } | |
718e3744 | 8700 | |
d62a17ae | 8701 | UNSET_IF_PARAM(params, retransmit_interval); |
8702 | params->retransmit_interval = OSPF_RETRANSMIT_INTERVAL_DEFAULT; | |
718e3744 | 8703 | |
d62a17ae | 8704 | if (params != IF_DEF_PARAMS(ifp)) { |
8705 | ospf_free_if_params(ifp, addr); | |
8706 | ospf_if_update_params(ifp, addr); | |
8707 | } | |
718e3744 | 8708 | |
d62a17ae | 8709 | return CMD_SUCCESS; |
718e3744 | 8710 | } |
8711 | ||
0d829fa7 QY |
8712 | DEFUN_HIDDEN (no_ospf_retransmit_interval, |
8713 | no_ospf_retransmit_interval_cmd, | |
d4badaf6 | 8714 | "no ospf retransmit-interval [(1-65535)] [A.B.C.D]", |
0d829fa7 QY |
8715 | NO_STR |
8716 | "OSPF interface commands\n" | |
3a2d747c QY |
8717 | "Time between retransmitting lost link state advertisements\n" |
8718 | "Seconds\n" | |
8719 | "Address of interface\n") | |
0d829fa7 | 8720 | { |
d62a17ae | 8721 | return no_ip_ospf_retransmit_interval(self, vty, argc, argv); |
0d829fa7 | 8722 | } |
813d4307 | 8723 | |
718e3744 | 8724 | DEFUN (ip_ospf_transmit_delay, |
8725 | ip_ospf_transmit_delay_addr_cmd, | |
7a7be519 | 8726 | "ip ospf transmit-delay (1-65535) [A.B.C.D]", |
718e3744 | 8727 | "IP Information\n" |
8728 | "OSPF interface commands\n" | |
8729 | "Link state transmit delay\n" | |
8730 | "Seconds\n" | |
efd7904e | 8731 | "Address of interface\n") |
718e3744 | 8732 | { |
d62a17ae | 8733 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8734 | int idx = 0; | |
d7c0a89a | 8735 | uint32_t seconds; |
d62a17ae | 8736 | struct in_addr addr; |
8737 | struct ospf_if_params *params; | |
8738 | ||
8739 | params = IF_DEF_PARAMS(ifp); | |
8740 | argv_find(argv, argc, "(1-65535)", &idx); | |
8741 | seconds = strtol(argv[idx]->arg, NULL, 10); | |
8742 | ||
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_get_if_params(ifp, addr); |
8751 | ospf_if_update_params(ifp, addr); | |
718e3744 | 8752 | } |
8753 | ||
d62a17ae | 8754 | SET_IF_PARAM(params, transmit_delay); |
8755 | params->transmit_delay = seconds; | |
718e3744 | 8756 | |
d62a17ae | 8757 | return CMD_SUCCESS; |
718e3744 | 8758 | } |
8759 | ||
7a7be519 | 8760 | DEFUN_HIDDEN (ospf_transmit_delay, |
747e489c | 8761 | ospf_transmit_delay_cmd, |
0d829fa7 | 8762 | "ospf transmit-delay (1-65535) [A.B.C.D]", |
747e489c DW |
8763 | "OSPF interface commands\n" |
8764 | "Link state transmit delay\n" | |
3a2d747c | 8765 | "Seconds\n" |
efd7904e | 8766 | "Address of interface\n") |
7a7be519 | 8767 | { |
d62a17ae | 8768 | return ip_ospf_transmit_delay(self, vty, argc, argv); |
7a7be519 | 8769 | } |
718e3744 | 8770 | |
8771 | DEFUN (no_ip_ospf_transmit_delay, | |
8772 | no_ip_ospf_transmit_delay_addr_cmd, | |
0d829fa7 | 8773 | "no ip ospf transmit-delay [(1-65535)] [A.B.C.D]", |
718e3744 | 8774 | NO_STR |
8775 | "IP Information\n" | |
8776 | "OSPF interface commands\n" | |
8777 | "Link state transmit delay\n" | |
efd7904e RW |
8778 | "Seconds\n" |
8779 | "Address of interface\n") | |
718e3744 | 8780 | { |
d62a17ae | 8781 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8782 | int idx = 0; | |
8783 | struct in_addr addr; | |
8784 | struct ospf_if_params *params; | |
718e3744 | 8785 | |
d62a17ae | 8786 | params = IF_DEF_PARAMS(ifp); |
718e3744 | 8787 | |
d62a17ae | 8788 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { |
8789 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
8790 | vty_out(vty, | |
8791 | "Please specify interface address by A.B.C.D\n"); | |
8792 | return CMD_WARNING_CONFIG_FAILED; | |
8793 | } | |
718e3744 | 8794 | |
d62a17ae | 8795 | params = ospf_lookup_if_params(ifp, addr); |
8796 | if (params == NULL) | |
8797 | return CMD_SUCCESS; | |
8798 | } | |
718e3744 | 8799 | |
d62a17ae | 8800 | UNSET_IF_PARAM(params, transmit_delay); |
8801 | params->transmit_delay = OSPF_TRANSMIT_DELAY_DEFAULT; | |
718e3744 | 8802 | |
d62a17ae | 8803 | if (params != IF_DEF_PARAMS(ifp)) { |
8804 | ospf_free_if_params(ifp, addr); | |
8805 | ospf_if_update_params(ifp, addr); | |
8806 | } | |
8807 | ||
8808 | return CMD_SUCCESS; | |
718e3744 | 8809 | } |
8810 | ||
813d4307 | 8811 | |
0d829fa7 QY |
8812 | DEFUN_HIDDEN (no_ospf_transmit_delay, |
8813 | no_ospf_transmit_delay_cmd, | |
32573073 | 8814 | "no ospf transmit-delay [(1-65535) [A.B.C.D]]", |
0d829fa7 QY |
8815 | NO_STR |
8816 | "OSPF interface commands\n" | |
32573073 QY |
8817 | "Link state transmit delay\n" |
8818 | "Seconds\n" | |
efd7904e | 8819 | "Address of interface\n") |
813d4307 | 8820 | { |
d62a17ae | 8821 | return no_ip_ospf_transmit_delay(self, vty, argc, argv); |
813d4307 DW |
8822 | } |
8823 | ||
e723861d DS |
8824 | DEFUN (ip_ospf_area, |
8825 | ip_ospf_area_cmd, | |
52c62ab8 | 8826 | "ip ospf [(1-65535)] area <A.B.C.D|(0-4294967295)> [A.B.C.D]", |
e723861d DS |
8827 | "IP Information\n" |
8828 | "OSPF interface commands\n" | |
7a7be519 | 8829 | "Instance ID\n" |
e723861d DS |
8830 | "Enable OSPF on this interface\n" |
8831 | "OSPF area ID in IP address format\n" | |
52c62ab8 JAG |
8832 | "OSPF area ID as a decimal value\n" |
8833 | "Address of interface\n") | |
e723861d | 8834 | { |
d62a17ae | 8835 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8836 | int idx = 0; | |
8837 | int format, ret; | |
8838 | struct in_addr area_id; | |
8839 | struct in_addr addr; | |
35955c14 | 8840 | struct ospf_if_params *params = NULL; |
d62a17ae | 8841 | struct route_node *rn; |
b5a8894d | 8842 | struct ospf *ospf = NULL; |
d7c0a89a | 8843 | unsigned short instance = 0; |
d62a17ae | 8844 | char *areaid; |
15bf52d3 | 8845 | uint32_t count = 0; |
d62a17ae | 8846 | |
8847 | if (argv_find(argv, argc, "(1-65535)", &idx)) | |
8848 | instance = strtol(argv[idx]->arg, NULL, 10); | |
8849 | ||
8850 | argv_find(argv, argc, "area", &idx); | |
8851 | areaid = argv[idx + 1]->arg; | |
8852 | ||
b56114aa | 8853 | if (!instance) |
096f7609 | 8854 | ospf = ifp->vrf->info; |
b5a8894d CS |
8855 | else |
8856 | ospf = ospf_lookup_instance(instance); | |
8857 | ||
409f98ab | 8858 | if (instance && instance != ospf_instance) { |
2b0a32da DS |
8859 | /* |
8860 | * At this point we know we have received | |
8861 | * an instance and there is no ospf instance | |
8862 | * associated with it. This means we are | |
8863 | * in a situation where we have an | |
8864 | * ospf command that is setup for a different | |
8865 | * process(instance). We need to safely | |
8866 | * remove the command from ourselves and | |
8867 | * allow the other instance(process) handle | |
8868 | * the configuration command. | |
8869 | */ | |
15bf52d3 IR |
8870 | count = 0; |
8871 | ||
d62a17ae | 8872 | params = IF_DEF_PARAMS(ifp); |
8873 | if (OSPF_IF_PARAM_CONFIGURED(params, if_area)) { | |
8874 | UNSET_IF_PARAM(params, if_area); | |
15bf52d3 IR |
8875 | count++; |
8876 | } | |
8877 | ||
8878 | for (rn = route_top(IF_OIFS_PARAMS(ifp)); rn; rn = route_next(rn)) | |
8879 | if ((params = rn->info) && OSPF_IF_PARAM_CONFIGURED(params, if_area)) { | |
8880 | UNSET_IF_PARAM(params, if_area); | |
8881 | count++; | |
8882 | } | |
8883 | ||
8884 | if (count > 0) { | |
096f7609 | 8885 | ospf = ifp->vrf->info; |
cbf32f74 | 8886 | if (ospf) |
2b0a32da | 8887 | ospf_interface_area_unset(ospf, ifp); |
d62a17ae | 8888 | } |
15bf52d3 | 8889 | |
ac28e4ec | 8890 | return CMD_NOT_MY_INSTANCE; |
d62a17ae | 8891 | } |
e723861d | 8892 | |
d62a17ae | 8893 | ret = str2area_id(areaid, &area_id, &format); |
8894 | if (ret < 0) { | |
8895 | vty_out(vty, "Please specify area by A.B.C.D|<0-4294967295>\n"); | |
8896 | return CMD_WARNING_CONFIG_FAILED; | |
8897 | } | |
8898 | if (memcmp(ifp->name, "VLINK", 5) == 0) { | |
8899 | vty_out(vty, "Cannot enable OSPF on a virtual link.\n"); | |
8900 | return CMD_WARNING_CONFIG_FAILED; | |
8901 | } | |
8902 | ||
eb364867 IR |
8903 | if (ospf) { |
8904 | for (rn = route_top(ospf->networks); rn; rn = route_next(rn)) { | |
8905 | if (rn->info != NULL) { | |
8906 | vty_out(vty, | |
8907 | "Please remove all network commands first.\n"); | |
8908 | return CMD_WARNING_CONFIG_FAILED; | |
8909 | } | |
8910 | } | |
8911 | } | |
8912 | ||
d62a17ae | 8913 | params = IF_DEF_PARAMS(ifp); |
8914 | if (OSPF_IF_PARAM_CONFIGURED(params, if_area) | |
8915 | && !IPV4_ADDR_SAME(¶ms->if_area, &area_id)) { | |
8916 | vty_out(vty, | |
8917 | "Must remove previous area config before changing ospf area \n"); | |
8918 | return CMD_WARNING_CONFIG_FAILED; | |
8919 | } | |
8920 | ||
8921 | // Check if we have an address arg and proccess it | |
8922 | if (argc == idx + 3) { | |
cc9b06ad | 8923 | if (!inet_aton(argv[idx + 2]->arg, &addr)) { |
996c9314 LB |
8924 | vty_out(vty, |
8925 | "Please specify Intf Address by A.B.C.D\n"); | |
cc9b06ad DS |
8926 | return CMD_WARNING_CONFIG_FAILED; |
8927 | } | |
d62a17ae | 8928 | // update/create address-level params |
8929 | params = ospf_get_if_params((ifp), (addr)); | |
8930 | if (OSPF_IF_PARAM_CONFIGURED(params, if_area)) { | |
a900cece IR |
8931 | if (!IPV4_ADDR_SAME(¶ms->if_area, &area_id)) { |
8932 | vty_out(vty, | |
8933 | "Must remove previous area/address config before changing ospf area\n"); | |
8934 | return CMD_WARNING_CONFIG_FAILED; | |
8935 | } else | |
8936 | return CMD_SUCCESS; | |
d62a17ae | 8937 | } |
8938 | ospf_if_update_params((ifp), (addr)); | |
8939 | } | |
8940 | ||
d62a17ae | 8941 | /* enable ospf on this interface with area_id */ |
35955c14 CS |
8942 | if (params) { |
8943 | SET_IF_PARAM(params, if_area); | |
8944 | params->if_area = area_id; | |
8945 | params->if_area_id_fmt = format; | |
8946 | } | |
aed7cc62 | 8947 | |
cbf32f74 | 8948 | if (ospf) |
aed7cc62 | 8949 | ospf_interface_area_set(ospf, ifp); |
d62a17ae | 8950 | |
8951 | return CMD_SUCCESS; | |
e723861d DS |
8952 | } |
8953 | ||
8954 | DEFUN (no_ip_ospf_area, | |
8955 | no_ip_ospf_area_cmd, | |
52c62ab8 | 8956 | "no ip ospf [(1-65535)] area [<A.B.C.D|(0-4294967295)> [A.B.C.D]]", |
e723861d DS |
8957 | NO_STR |
8958 | "IP Information\n" | |
8959 | "OSPF interface commands\n" | |
3a2d747c | 8960 | "Instance ID\n" |
7a7be519 | 8961 | "Disable OSPF on this interface\n" |
8962 | "OSPF area ID in IP address format\n" | |
52c62ab8 JAG |
8963 | "OSPF area ID as a decimal value\n" |
8964 | "Address of interface\n") | |
e723861d | 8965 | { |
d62a17ae | 8966 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8967 | int idx = 0; | |
8968 | struct ospf *ospf; | |
8969 | struct ospf_if_params *params; | |
d7c0a89a | 8970 | unsigned short instance = 0; |
d62a17ae | 8971 | struct in_addr addr; |
58e5d140 | 8972 | struct in_addr area_id; |
d62a17ae | 8973 | |
8974 | if (argv_find(argv, argc, "(1-65535)", &idx)) | |
8975 | instance = strtol(argv[idx]->arg, NULL, 10); | |
8976 | ||
b56114aa | 8977 | if (!instance) |
096f7609 | 8978 | ospf = ifp->vrf->info; |
b5a8894d CS |
8979 | else |
8980 | ospf = ospf_lookup_instance(instance); | |
8981 | ||
409f98ab | 8982 | if (instance && instance != ospf_instance) |
ac28e4ec | 8983 | return CMD_NOT_MY_INSTANCE; |
d62a17ae | 8984 | |
8985 | argv_find(argv, argc, "area", &idx); | |
8986 | ||
8987 | // Check if we have an address arg and proccess it | |
8988 | if (argc == idx + 3) { | |
cc9b06ad | 8989 | if (!inet_aton(argv[idx + 2]->arg, &addr)) { |
996c9314 LB |
8990 | vty_out(vty, |
8991 | "Please specify Intf Address by A.B.C.D\n"); | |
cc9b06ad DS |
8992 | return CMD_WARNING_CONFIG_FAILED; |
8993 | } | |
d62a17ae | 8994 | params = ospf_lookup_if_params(ifp, addr); |
8995 | if ((params) == NULL) | |
8996 | return CMD_SUCCESS; | |
8997 | } else | |
8998 | params = IF_DEF_PARAMS(ifp); | |
8999 | ||
58e5d140 | 9000 | area_id = params->if_area; |
d62a17ae | 9001 | if (!OSPF_IF_PARAM_CONFIGURED(params, if_area)) { |
9002 | vty_out(vty, | |
9003 | "Can't find specified interface area configuration.\n"); | |
9004 | return CMD_WARNING_CONFIG_FAILED; | |
9005 | } | |
813d4307 | 9006 | |
d62a17ae | 9007 | UNSET_IF_PARAM(params, if_area); |
9008 | if (params != IF_DEF_PARAMS((ifp))) { | |
9009 | ospf_free_if_params((ifp), (addr)); | |
9010 | ospf_if_update_params((ifp), (addr)); | |
9011 | } | |
9012 | ||
e4129293 IR |
9013 | if (ospf) { |
9014 | ospf_interface_area_unset(ospf, ifp); | |
58e5d140 | 9015 | ospf_area_check_free(ospf, area_id); |
e4129293 IR |
9016 | } |
9017 | ||
d62a17ae | 9018 | return CMD_SUCCESS; |
813d4307 DW |
9019 | } |
9020 | ||
3eec4ee0 IR |
9021 | DEFUN (ip_ospf_passive, |
9022 | ip_ospf_passive_cmd, | |
9023 | "ip ospf passive [A.B.C.D]", | |
9024 | "IP Information\n" | |
9025 | "OSPF interface commands\n" | |
9026 | "Suppress routing updates on an interface\n" | |
9027 | "Address of interface\n") | |
9028 | { | |
9029 | VTY_DECLVAR_CONTEXT(interface, ifp); | |
9030 | int idx_ipv4 = 3; | |
82f0277b | 9031 | struct in_addr addr = {.s_addr = INADDR_ANY}; |
3eec4ee0 IR |
9032 | struct ospf_if_params *params; |
9033 | int ret; | |
9034 | ||
9035 | if (argc == 4) { | |
9036 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
9037 | if (!ret) { | |
9038 | vty_out(vty, | |
9039 | "Please specify interface address by A.B.C.D\n"); | |
9040 | return CMD_WARNING_CONFIG_FAILED; | |
9041 | } | |
9042 | params = ospf_get_if_params(ifp, addr); | |
9043 | ospf_if_update_params(ifp, addr); | |
9044 | } else { | |
9045 | params = IF_DEF_PARAMS(ifp); | |
9046 | } | |
9047 | ||
82f0277b | 9048 | ospf_passive_interface_update(ifp, params, addr, OSPF_IF_PASSIVE); |
3eec4ee0 IR |
9049 | |
9050 | return CMD_SUCCESS; | |
9051 | } | |
9052 | ||
9053 | DEFUN (no_ip_ospf_passive, | |
9054 | no_ip_ospf_passive_cmd, | |
9055 | "no ip ospf passive [A.B.C.D]", | |
9056 | NO_STR | |
9057 | "IP Information\n" | |
9058 | "OSPF interface commands\n" | |
9059 | "Enable routing updates on an interface\n" | |
9060 | "Address of interface\n") | |
9061 | { | |
9062 | VTY_DECLVAR_CONTEXT(interface, ifp); | |
9063 | int idx_ipv4 = 4; | |
82f0277b | 9064 | struct in_addr addr = {.s_addr = INADDR_ANY}; |
3eec4ee0 IR |
9065 | struct ospf_if_params *params; |
9066 | int ret; | |
9067 | ||
9068 | if (argc == 5) { | |
9069 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
9070 | if (!ret) { | |
9071 | vty_out(vty, | |
9072 | "Please specify interface address by A.B.C.D\n"); | |
9073 | return CMD_WARNING_CONFIG_FAILED; | |
9074 | } | |
9075 | params = ospf_lookup_if_params(ifp, addr); | |
9076 | if (params == NULL) | |
9077 | return CMD_SUCCESS; | |
9078 | } else { | |
9079 | params = IF_DEF_PARAMS(ifp); | |
9080 | } | |
9081 | ||
82f0277b | 9082 | ospf_passive_interface_update(ifp, params, addr, OSPF_IF_ACTIVE); |
3eec4ee0 IR |
9083 | |
9084 | return CMD_SUCCESS; | |
9085 | } | |
9086 | ||
6f2a6703 CF |
9087 | DEFUN (ospf_redistribute_source, |
9088 | ospf_redistribute_source_cmd, | |
70dd370f | 9089 | "redistribute " FRR_REDIST_STR_OSPFD " [{metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]", |
d1c65c21 | 9090 | REDIST_STR |
ab0181ee | 9091 | FRR_REDIST_HELP_STR_OSPFD |
718e3744 | 9092 | "Metric for redistributed routes\n" |
9093 | "OSPF default metric\n" | |
9094 | "OSPF exterior metric type for redistributed routes\n" | |
7111c1a0 | 9095 | "Set OSPF External Type 1/2 metrics\n" |
718e3744 | 9096 | "Route map reference\n" |
9097 | "Pointer to route-map entries\n") | |
9098 | { | |
a3d826f0 | 9099 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 9100 | int idx_protocol = 1; |
9101 | int source; | |
9102 | int type = -1; | |
9103 | int metric = -1; | |
9104 | struct ospf_redist *red; | |
9105 | int idx = 0; | |
7bced643 | 9106 | bool update = false; |
6f2a6703 | 9107 | |
d62a17ae | 9108 | /* Get distribute source. */ |
9109 | source = proto_redistnum(AFI_IP, argv[idx_protocol]->text); | |
9110 | if (source < 0) | |
9111 | return CMD_WARNING_CONFIG_FAILED; | |
9112 | ||
d62a17ae | 9113 | /* Get metric value. */ |
9114 | if (argv_find(argv, argc, "(0-16777214)", &idx)) { | |
9115 | if (!str2metric(argv[idx]->arg, &metric)) | |
9116 | return CMD_WARNING_CONFIG_FAILED; | |
9117 | } | |
951da435 | 9118 | idx = 1; |
d62a17ae | 9119 | /* Get metric type. */ |
ea38ced1 | 9120 | if (argv_find(argv, argc, "(1-2)", &idx)) { |
d62a17ae | 9121 | if (!str2metric_type(argv[idx]->arg, &type)) |
9122 | return CMD_WARNING_CONFIG_FAILED; | |
9123 | } | |
951da435 | 9124 | idx = 1; |
7bced643 IR |
9125 | |
9126 | red = ospf_redist_lookup(ospf, source, 0); | |
9127 | if (!red) | |
9128 | red = ospf_redist_add(ospf, source, 0); | |
9129 | else | |
9130 | update = true; | |
9131 | ||
d62a17ae | 9132 | /* Get route-map */ |
70dd370f DA |
9133 | if (argv_find(argv, argc, "route-map", &idx)) { |
9134 | ospf_routemap_set(red, argv[idx + 1]->arg); | |
d62a17ae | 9135 | } else |
9136 | ospf_routemap_unset(red); | |
7c8ff89e | 9137 | |
7bced643 IR |
9138 | if (update) |
9139 | return ospf_redistribute_update(ospf, red, source, 0, type, | |
9140 | metric); | |
9141 | else | |
9142 | return ospf_redistribute_set(ospf, red, source, 0, type, | |
9143 | metric); | |
718e3744 | 9144 | } |
9145 | ||
718e3744 | 9146 | DEFUN (no_ospf_redistribute_source, |
9147 | no_ospf_redistribute_source_cmd, | |
70dd370f | 9148 | "no redistribute " FRR_REDIST_STR_OSPFD " [{metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]", |
718e3744 | 9149 | NO_STR |
d1c65c21 | 9150 | REDIST_STR |
ab0181ee | 9151 | FRR_REDIST_HELP_STR_OSPFD |
813d4307 DW |
9152 | "Metric for redistributed routes\n" |
9153 | "OSPF default metric\n" | |
9154 | "OSPF exterior metric type for redistributed routes\n" | |
7111c1a0 | 9155 | "Set OSPF External Type 1/2 metrics\n" |
813d4307 DW |
9156 | "Route map reference\n" |
9157 | "Pointer to route-map entries\n") | |
718e3744 | 9158 | { |
a3d826f0 | 9159 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 9160 | int idx_protocol = 2; |
9161 | int source; | |
9162 | struct ospf_redist *red; | |
718e3744 | 9163 | |
d62a17ae | 9164 | source = proto_redistnum(AFI_IP, argv[idx_protocol]->text); |
9165 | if (source < 0) | |
9166 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 9167 | |
d62a17ae | 9168 | red = ospf_redist_lookup(ospf, source, 0); |
9169 | if (!red) | |
9170 | return CMD_SUCCESS; | |
7c8ff89e | 9171 | |
d62a17ae | 9172 | ospf_routemap_unset(red); |
766b826f DA |
9173 | ospf_redist_del(ospf, source, 0); |
9174 | ||
d62a17ae | 9175 | return ospf_redistribute_unset(ospf, source, 0); |
7c8ff89e DS |
9176 | } |
9177 | ||
9178 | DEFUN (ospf_redistribute_instance_source, | |
9179 | ospf_redistribute_instance_source_cmd, | |
70dd370f | 9180 | "redistribute <ospf|table> (1-65535) [{metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]", |
7c8ff89e DS |
9181 | REDIST_STR |
9182 | "Open Shortest Path First\n" | |
2d627ff5 DS |
9183 | "Non-main Kernel Routing Table\n" |
9184 | "Instance ID/Table ID\n" | |
7c8ff89e DS |
9185 | "Metric for redistributed routes\n" |
9186 | "OSPF default metric\n" | |
9187 | "OSPF exterior metric type for redistributed routes\n" | |
7111c1a0 | 9188 | "Set OSPF External Type 1/2 metrics\n" |
7c8ff89e DS |
9189 | "Route map reference\n" |
9190 | "Pointer to route-map entries\n") | |
9191 | { | |
a3d826f0 | 9192 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 9193 | int idx_ospf_table = 1; |
9194 | int idx_number = 2; | |
9195 | int idx = 3; | |
9196 | int source; | |
9197 | int type = -1; | |
9198 | int metric = -1; | |
d7c0a89a | 9199 | unsigned short instance; |
d62a17ae | 9200 | struct ospf_redist *red; |
7bced643 | 9201 | bool update = false; |
7c8ff89e | 9202 | |
d62a17ae | 9203 | source = proto_redistnum(AFI_IP, argv[idx_ospf_table]->text); |
2d627ff5 | 9204 | |
13f0e434 | 9205 | if (source < 0) { |
9206 | vty_out(vty, "Unknown instance redistribution\n"); | |
9207 | return CMD_WARNING_CONFIG_FAILED; | |
9208 | } | |
9209 | ||
d62a17ae | 9210 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
7c8ff89e | 9211 | |
d62a17ae | 9212 | if ((source == ZEBRA_ROUTE_OSPF) && !ospf->instance) { |
9213 | vty_out(vty, | |
9214 | "Instance redistribution in non-instanced OSPF not allowed\n"); | |
9215 | return CMD_WARNING_CONFIG_FAILED; | |
9216 | } | |
7c8ff89e | 9217 | |
d62a17ae | 9218 | if ((source == ZEBRA_ROUTE_OSPF) && (ospf->instance == instance)) { |
9219 | vty_out(vty, "Same instance OSPF redistribution not allowed\n"); | |
9220 | return CMD_WARNING_CONFIG_FAILED; | |
9221 | } | |
7c8ff89e | 9222 | |
d62a17ae | 9223 | /* Get metric value. */ |
9224 | if (argv_find(argv, argc, "metric", &idx)) | |
9225 | if (!str2metric(argv[idx + 1]->arg, &metric)) | |
9226 | return CMD_WARNING_CONFIG_FAILED; | |
7c8ff89e | 9227 | |
d62a17ae | 9228 | idx = 3; |
9229 | /* Get metric type. */ | |
9230 | if (argv_find(argv, argc, "metric-type", &idx)) | |
9231 | if (!str2metric_type(argv[idx + 1]->arg, &type)) | |
9232 | return CMD_WARNING_CONFIG_FAILED; | |
7c8ff89e | 9233 | |
7bced643 IR |
9234 | red = ospf_redist_lookup(ospf, source, instance); |
9235 | if (!red) | |
9236 | red = ospf_redist_add(ospf, source, instance); | |
9237 | else | |
9238 | update = true; | |
7a7be519 | 9239 | |
d62a17ae | 9240 | idx = 3; |
9241 | if (argv_find(argv, argc, "route-map", &idx)) | |
9242 | ospf_routemap_set(red, argv[idx + 1]->arg); | |
9243 | else | |
9244 | ospf_routemap_unset(red); | |
7c8ff89e | 9245 | |
7bced643 IR |
9246 | if (update) |
9247 | return ospf_redistribute_update(ospf, red, source, instance, | |
9248 | type, metric); | |
9249 | else | |
9250 | return ospf_redistribute_set(ospf, red, source, instance, type, | |
9251 | metric); | |
7c8ff89e DS |
9252 | } |
9253 | ||
9254 | DEFUN (no_ospf_redistribute_instance_source, | |
9255 | no_ospf_redistribute_instance_source_cmd, | |
70dd370f | 9256 | "no redistribute <ospf|table> (1-65535) [{metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]", |
7c8ff89e DS |
9257 | NO_STR |
9258 | REDIST_STR | |
9259 | "Open Shortest Path First\n" | |
2d627ff5 DS |
9260 | "Non-main Kernel Routing Table\n" |
9261 | "Instance ID/Table Id\n" | |
7c8ff89e DS |
9262 | "Metric for redistributed routes\n" |
9263 | "OSPF default metric\n" | |
9264 | "OSPF exterior metric type for redistributed routes\n" | |
7111c1a0 | 9265 | "Set OSPF External Type 1/2 metrics\n" |
7c8ff89e DS |
9266 | "Route map reference\n" |
9267 | "Pointer to route-map entries\n") | |
9268 | { | |
a3d826f0 | 9269 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 9270 | int idx_ospf_table = 2; |
9271 | int idx_number = 3; | |
d7c0a89a | 9272 | unsigned int instance; |
d62a17ae | 9273 | struct ospf_redist *red; |
9274 | int source; | |
9275 | ||
9276 | if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0) | |
9277 | source = ZEBRA_ROUTE_OSPF; | |
9278 | else | |
9279 | source = ZEBRA_ROUTE_TABLE; | |
9280 | ||
9281 | instance = strtoul(argv[idx_number]->arg, NULL, 10); | |
7c8ff89e | 9282 | |
d62a17ae | 9283 | if ((source == ZEBRA_ROUTE_OSPF) && !ospf->instance) { |
9284 | vty_out(vty, | |
9285 | "Instance redistribution in non-instanced OSPF not allowed\n"); | |
9286 | return CMD_WARNING_CONFIG_FAILED; | |
9287 | } | |
9288 | ||
9289 | if ((source == ZEBRA_ROUTE_OSPF) && (ospf->instance == instance)) { | |
9290 | vty_out(vty, "Same instance OSPF redistribution not allowed\n"); | |
9291 | return CMD_WARNING_CONFIG_FAILED; | |
9292 | } | |
9293 | ||
9294 | red = ospf_redist_lookup(ospf, source, instance); | |
9295 | if (!red) | |
9296 | return CMD_SUCCESS; | |
9297 | ||
9298 | ospf_routemap_unset(red); | |
766b826f DA |
9299 | ospf_redist_del(ospf, source, instance); |
9300 | ||
d62a17ae | 9301 | return ospf_redistribute_unset(ospf, source, instance); |
718e3744 | 9302 | } |
9303 | ||
9304 | DEFUN (ospf_distribute_list_out, | |
9305 | ospf_distribute_list_out_cmd, | |
c60dec36 | 9306 | "distribute-list ACCESSLIST4_NAME out " FRR_REDIST_STR_OSPFD, |
718e3744 | 9307 | "Filter networks in routing updates\n" |
6f2a6703 CF |
9308 | "Access-list name\n" |
9309 | OUT_STR | |
ab0181ee | 9310 | FRR_REDIST_HELP_STR_OSPFD) |
718e3744 | 9311 | { |
a3d826f0 | 9312 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 9313 | int idx_word = 1; |
9314 | int source; | |
718e3744 | 9315 | |
d62a17ae | 9316 | char *proto = argv[argc - 1]->text; |
6d681bd8 | 9317 | |
d62a17ae | 9318 | /* Get distribute source. */ |
9319 | source = proto_redistnum(AFI_IP, proto); | |
9320 | if (source < 0) | |
9321 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 9322 | |
d62a17ae | 9323 | return ospf_distribute_list_out_set(ospf, source, argv[idx_word]->arg); |
718e3744 | 9324 | } |
9325 | ||
6f2a6703 CF |
9326 | DEFUN (no_ospf_distribute_list_out, |
9327 | no_ospf_distribute_list_out_cmd, | |
c60dec36 | 9328 | "no distribute-list ACCESSLIST4_NAME out " FRR_REDIST_STR_OSPFD, |
6f2a6703 CF |
9329 | NO_STR |
9330 | "Filter networks in routing updates\n" | |
9331 | "Access-list name\n" | |
9332 | OUT_STR | |
ab0181ee | 9333 | FRR_REDIST_HELP_STR_OSPFD) |
718e3744 | 9334 | { |
a3d826f0 | 9335 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 9336 | int idx_word = 2; |
9337 | int source; | |
020709f9 | 9338 | |
d62a17ae | 9339 | char *proto = argv[argc - 1]->text; |
9340 | source = proto_redistnum(AFI_IP, proto); | |
9341 | if (source < 0) | |
9342 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 9343 | |
d62a17ae | 9344 | return ospf_distribute_list_out_unset(ospf, source, |
9345 | argv[idx_word]->arg); | |
718e3744 | 9346 | } |
9347 | ||
6f2a6703 CF |
9348 | /* Default information originate. */ |
9349 | DEFUN (ospf_default_information_originate, | |
9350 | ospf_default_information_originate_cmd, | |
70dd370f | 9351 | "default-information originate [{always|metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]", |
718e3744 | 9352 | "Control distribution of default information\n" |
9353 | "Distribute a default route\n" | |
9354 | "Always advertise default route\n" | |
6f2a6703 CF |
9355 | "OSPF default metric\n" |
9356 | "OSPF metric\n" | |
718e3744 | 9357 | "OSPF metric type for default routes\n" |
7111c1a0 | 9358 | "Set OSPF External Type 1/2 metrics\n" |
718e3744 | 9359 | "Route map reference\n" |
9360 | "Pointer to route-map entries\n") | |
9361 | { | |
a3d826f0 | 9362 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 9363 | int default_originate = DEFAULT_ORIGINATE_ZEBRA; |
9364 | int type = -1; | |
9365 | int metric = -1; | |
9366 | struct ospf_redist *red; | |
9367 | int idx = 0; | |
1fb93326 | 9368 | int cur_originate = ospf->default_originate; |
ff5c476d | 9369 | bool sameRtmap = false; |
1fb93326 | 9370 | char *rtmap = NULL; |
d62a17ae | 9371 | |
9372 | red = ospf_redist_add(ospf, DEFAULT_ROUTE, 0); | |
9373 | ||
9374 | /* Check whether "always" was specified */ | |
9375 | if (argv_find(argv, argc, "always", &idx)) | |
9376 | default_originate = DEFAULT_ORIGINATE_ALWAYS; | |
951da435 | 9377 | idx = 1; |
d62a17ae | 9378 | /* Get metric value */ |
ea38ced1 | 9379 | if (argv_find(argv, argc, "(0-16777214)", &idx)) { |
d62a17ae | 9380 | if (!str2metric(argv[idx]->arg, &metric)) |
9381 | return CMD_WARNING_CONFIG_FAILED; | |
9382 | } | |
951da435 | 9383 | idx = 1; |
d62a17ae | 9384 | /* Get metric type. */ |
ea38ced1 | 9385 | if (argv_find(argv, argc, "(1-2)", &idx)) { |
d62a17ae | 9386 | if (!str2metric_type(argv[idx]->arg, &type)) |
9387 | return CMD_WARNING_CONFIG_FAILED; | |
9388 | } | |
951da435 | 9389 | idx = 1; |
d62a17ae | 9390 | /* Get route-map */ |
70dd370f DA |
9391 | if (argv_find(argv, argc, "route-map", &idx)) |
9392 | rtmap = argv[idx]->arg + 1; | |
1fb93326 | 9393 | |
ff5c476d | 9394 | /* To check if user is providing same route map */ |
9395 | if ((!rtmap && !ROUTEMAP_NAME(red)) || | |
9396 | (rtmap && ROUTEMAP_NAME(red) && | |
9397 | (strcmp(rtmap, ROUTEMAP_NAME(red)) == 0))) | |
9398 | sameRtmap = true; | |
1fb93326 | 9399 | |
ff5c476d | 9400 | /* Don't allow if the same lsa is already originated. */ |
1fb93326 | 9401 | if ((sameRtmap) |
9402 | && (red->dmetric.type == type) | |
9403 | && (red->dmetric.value == metric) | |
9404 | && (cur_originate == default_originate)) | |
9405 | return CMD_SUCCESS; | |
9406 | ||
9407 | /* Updating Metric details */ | |
9408 | red->dmetric.type = type; | |
9409 | red->dmetric.value = metric; | |
9410 | ||
9411 | /* updating route map details */ | |
9412 | if (rtmap) | |
9413 | ospf_routemap_set(red, rtmap); | |
d62a17ae | 9414 | else |
9415 | ospf_routemap_unset(red); | |
9416 | ||
9417 | return ospf_redistribute_default_set(ospf, default_originate, type, | |
9418 | metric); | |
718e3744 | 9419 | } |
9420 | ||
9421 | DEFUN (no_ospf_default_information_originate, | |
9422 | no_ospf_default_information_originate_cmd, | |
70dd370f | 9423 | "no default-information originate [{always|metric (0-16777214)|metric-type (1-2)|route-map RMAP_NAME}]", |
718e3744 | 9424 | NO_STR |
9425 | "Control distribution of default information\n" | |
813d4307 DW |
9426 | "Distribute a default route\n" |
9427 | "Always advertise default route\n" | |
9428 | "OSPF default metric\n" | |
9429 | "OSPF metric\n" | |
9430 | "OSPF metric type for default routes\n" | |
7111c1a0 | 9431 | "Set OSPF External Type 1/2 metrics\n" |
813d4307 DW |
9432 | "Route map reference\n" |
9433 | "Pointer to route-map entries\n") | |
718e3744 | 9434 | { |
a3d826f0 | 9435 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 9436 | struct ospf_redist *red; |
7c8ff89e | 9437 | |
d62a17ae | 9438 | red = ospf_redist_lookup(ospf, DEFAULT_ROUTE, 0); |
9439 | if (!red) | |
9440 | return CMD_SUCCESS; | |
7c8ff89e | 9441 | |
d62a17ae | 9442 | ospf_routemap_unset(red); |
766b826f DA |
9443 | ospf_redist_del(ospf, DEFAULT_ROUTE, 0); |
9444 | ||
d5eac1e0 DL |
9445 | return ospf_redistribute_default_set(ospf, DEFAULT_ORIGINATE_NONE, |
9446 | 0, 0); | |
718e3744 | 9447 | } |
9448 | ||
9449 | DEFUN (ospf_default_metric, | |
9450 | ospf_default_metric_cmd, | |
6147e2c6 | 9451 | "default-metric (0-16777214)", |
718e3744 | 9452 | "Set metric of redistributed routes\n" |
9453 | "Default metric\n") | |
9454 | { | |
a3d826f0 | 9455 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 9456 | int idx_number = 1; |
9457 | int metric = -1; | |
718e3744 | 9458 | |
d62a17ae | 9459 | if (!str2metric(argv[idx_number]->arg, &metric)) |
9460 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 9461 | |
d62a17ae | 9462 | ospf->default_metric = metric; |
718e3744 | 9463 | |
d62a17ae | 9464 | return CMD_SUCCESS; |
718e3744 | 9465 | } |
9466 | ||
9467 | DEFUN (no_ospf_default_metric, | |
9468 | no_ospf_default_metric_cmd, | |
7a7be519 | 9469 | "no default-metric [(0-16777214)]", |
718e3744 | 9470 | NO_STR |
7a7be519 | 9471 | "Set metric of redistributed routes\n" |
9472 | "Default metric\n") | |
718e3744 | 9473 | { |
a3d826f0 | 9474 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
68980084 | 9475 | |
d62a17ae | 9476 | ospf->default_metric = -1; |
68980084 | 9477 | |
d62a17ae | 9478 | return CMD_SUCCESS; |
718e3744 | 9479 | } |
9480 | ||
718e3744 | 9481 | |
9482 | DEFUN (ospf_distance, | |
9483 | ospf_distance_cmd, | |
6147e2c6 | 9484 | "distance (1-255)", |
eaa1ae0d | 9485 | "Administrative distance\n" |
718e3744 | 9486 | "OSPF Administrative distance\n") |
9487 | { | |
a3d826f0 | 9488 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 9489 | int idx_number = 1; |
9fdb4735 | 9490 | uint8_t distance; |
68980084 | 9491 | |
9fdb4735 | 9492 | distance = atoi(argv[idx_number]->arg); |
9493 | if (ospf->distance_all != distance) { | |
9494 | ospf->distance_all = distance; | |
9495 | ospf_restart_spf(ospf); | |
9496 | } | |
68980084 | 9497 | |
d62a17ae | 9498 | return CMD_SUCCESS; |
718e3744 | 9499 | } |
9500 | ||
9501 | DEFUN (no_ospf_distance, | |
9502 | no_ospf_distance_cmd, | |
6147e2c6 | 9503 | "no distance (1-255)", |
718e3744 | 9504 | NO_STR |
eaa1ae0d | 9505 | "Administrative distance\n" |
718e3744 | 9506 | "OSPF Administrative distance\n") |
9507 | { | |
a3d826f0 | 9508 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
68980084 | 9509 | |
9fdb4735 | 9510 | if (ospf->distance_all) { |
9511 | ospf->distance_all = 0; | |
9512 | ospf_restart_spf(ospf); | |
9513 | } | |
68980084 | 9514 | |
d62a17ae | 9515 | return CMD_SUCCESS; |
718e3744 | 9516 | } |
9517 | ||
9518 | DEFUN (no_ospf_distance_ospf, | |
9519 | no_ospf_distance_ospf_cmd, | |
eaa1ae0d | 9520 | "no distance ospf [{intra-area [(1-255)]|inter-area [(1-255)]|external [(1-255)]}]", |
718e3744 | 9521 | NO_STR |
eaa1ae0d QY |
9522 | "Administrative distance\n" |
9523 | "OSPF administrative distance\n" | |
718e3744 | 9524 | "Intra-area routes\n" |
813d4307 | 9525 | "Distance for intra-area routes\n" |
718e3744 | 9526 | "Inter-area routes\n" |
813d4307 DW |
9527 | "Distance for inter-area routes\n" |
9528 | "External routes\n" | |
9529 | "Distance for external routes\n") | |
718e3744 | 9530 | { |
a3d826f0 | 9531 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 9532 | int idx = 0; |
718e3744 | 9533 | |
d62a17ae | 9534 | if (argv_find(argv, argc, "intra-area", &idx) || argc == 3) |
9535 | idx = ospf->distance_intra = 0; | |
9536 | if (argv_find(argv, argc, "inter-area", &idx) || argc == 3) | |
9537 | idx = ospf->distance_inter = 0; | |
9538 | if (argv_find(argv, argc, "external", &idx) || argc == 3) | |
9539 | ospf->distance_external = 0; | |
718e3744 | 9540 | |
d62a17ae | 9541 | return CMD_SUCCESS; |
718e3744 | 9542 | } |
9543 | ||
6f2a6703 CF |
9544 | DEFUN (ospf_distance_ospf, |
9545 | ospf_distance_ospf_cmd, | |
eaa1ae0d QY |
9546 | "distance ospf {intra-area (1-255)|inter-area (1-255)|external (1-255)}", |
9547 | "Administrative distance\n" | |
9548 | "OSPF administrative distance\n" | |
718e3744 | 9549 | "Intra-area routes\n" |
9550 | "Distance for intra-area routes\n" | |
718e3744 | 9551 | "Inter-area routes\n" |
9552 | "Distance for inter-area routes\n" | |
9553 | "External routes\n" | |
718e3744 | 9554 | "Distance for external routes\n") |
9555 | { | |
a3d826f0 | 9556 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 9557 | int idx = 0; |
68980084 | 9558 | |
926b88f0 CS |
9559 | ospf->distance_intra = 0; |
9560 | ospf->distance_inter = 0; | |
9561 | ospf->distance_external = 0; | |
9562 | ||
d62a17ae | 9563 | if (argv_find(argv, argc, "intra-area", &idx)) |
9564 | ospf->distance_intra = atoi(argv[idx + 1]->arg); | |
9565 | idx = 0; | |
9566 | if (argv_find(argv, argc, "inter-area", &idx)) | |
9567 | ospf->distance_inter = atoi(argv[idx + 1]->arg); | |
9568 | idx = 0; | |
9569 | if (argv_find(argv, argc, "external", &idx)) | |
9570 | ospf->distance_external = atoi(argv[idx + 1]->arg); | |
68980084 | 9571 | |
d62a17ae | 9572 | return CMD_SUCCESS; |
718e3744 | 9573 | } |
9574 | ||
ba682537 | 9575 | DEFUN (ip_ospf_mtu_ignore, |
9576 | ip_ospf_mtu_ignore_addr_cmd, | |
7a7be519 | 9577 | "ip ospf mtu-ignore [A.B.C.D]", |
ba682537 | 9578 | "IP Information\n" |
9579 | "OSPF interface commands\n" | |
99a522c7 | 9580 | "Disable MTU mismatch detection on this interface\n" |
efd7904e | 9581 | "Address of interface\n") |
ba682537 | 9582 | { |
d62a17ae | 9583 | VTY_DECLVAR_CONTEXT(interface, ifp); |
9584 | int idx_ipv4 = 3; | |
9585 | struct in_addr addr; | |
9586 | int ret; | |
9587 | ||
9588 | struct ospf_if_params *params; | |
9589 | params = IF_DEF_PARAMS(ifp); | |
9590 | ||
9591 | if (argc == 4) { | |
9592 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
9593 | if (!ret) { | |
9594 | vty_out(vty, | |
9595 | "Please specify interface address by A.B.C.D\n"); | |
9596 | return CMD_WARNING_CONFIG_FAILED; | |
9597 | } | |
9598 | params = ospf_get_if_params(ifp, addr); | |
9599 | ospf_if_update_params(ifp, addr); | |
9600 | } | |
9601 | params->mtu_ignore = 1; | |
9602 | if (params->mtu_ignore != OSPF_MTU_IGNORE_DEFAULT) | |
9603 | SET_IF_PARAM(params, mtu_ignore); | |
9604 | else { | |
9605 | UNSET_IF_PARAM(params, mtu_ignore); | |
9606 | if (params != IF_DEF_PARAMS(ifp)) { | |
9607 | ospf_free_if_params(ifp, addr); | |
9608 | ospf_if_update_params(ifp, addr); | |
9609 | } | |
9610 | } | |
9611 | return CMD_SUCCESS; | |
ba682537 | 9612 | } |
9613 | ||
ba682537 | 9614 | DEFUN (no_ip_ospf_mtu_ignore, |
9615 | no_ip_ospf_mtu_ignore_addr_cmd, | |
7a7be519 | 9616 | "no ip ospf mtu-ignore [A.B.C.D]", |
efd7904e | 9617 | NO_STR |
ba682537 | 9618 | "IP Information\n" |
9619 | "OSPF interface commands\n" | |
99a522c7 | 9620 | "Disable MTU mismatch detection on this interface\n" |
efd7904e | 9621 | "Address of interface\n") |
ba682537 | 9622 | { |
d62a17ae | 9623 | VTY_DECLVAR_CONTEXT(interface, ifp); |
9624 | int idx_ipv4 = 4; | |
9625 | struct in_addr addr; | |
9626 | int ret; | |
9627 | ||
9628 | struct ospf_if_params *params; | |
9629 | params = IF_DEF_PARAMS(ifp); | |
9630 | ||
9631 | if (argc == 5) { | |
9632 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
9633 | if (!ret) { | |
9634 | vty_out(vty, | |
9635 | "Please specify interface address by A.B.C.D\n"); | |
9636 | return CMD_WARNING_CONFIG_FAILED; | |
9637 | } | |
9638 | params = ospf_get_if_params(ifp, addr); | |
9639 | ospf_if_update_params(ifp, addr); | |
9640 | } | |
9641 | params->mtu_ignore = 0; | |
9642 | if (params->mtu_ignore != OSPF_MTU_IGNORE_DEFAULT) | |
9643 | SET_IF_PARAM(params, mtu_ignore); | |
9644 | else { | |
9645 | UNSET_IF_PARAM(params, mtu_ignore); | |
9646 | if (params != IF_DEF_PARAMS(ifp)) { | |
9647 | ospf_free_if_params(ifp, addr); | |
9648 | ospf_if_update_params(ifp, addr); | |
9649 | } | |
9650 | } | |
9651 | return CMD_SUCCESS; | |
ba682537 | 9652 | } |
9653 | ||
6b0655a2 | 9654 | |
88d6cf37 | 9655 | DEFUN (ospf_max_metric_router_lsa_admin, |
9656 | ospf_max_metric_router_lsa_admin_cmd, | |
9657 | "max-metric router-lsa administrative", | |
9658 | "OSPF maximum / infinite-distance metric\n" | |
9659 | "Advertise own Router-LSA with infinite distance (stub router)\n" | |
9660 | "Administratively applied, for an indefinite period\n") | |
9661 | { | |
a3d826f0 | 9662 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 9663 | struct listnode *ln; |
9664 | struct ospf_area *area; | |
7c8ff89e | 9665 | |
d62a17ae | 9666 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, ln, area)) { |
9667 | SET_FLAG(area->stub_router_state, OSPF_AREA_ADMIN_STUB_ROUTED); | |
4ba4fc85 | 9668 | |
d62a17ae | 9669 | if (!CHECK_FLAG(area->stub_router_state, |
9670 | OSPF_AREA_IS_STUB_ROUTED)) | |
9671 | ospf_router_lsa_update_area(area); | |
9672 | } | |
4ba4fc85 | 9673 | |
d62a17ae | 9674 | /* Allows for areas configured later to get the property */ |
9675 | ospf->stub_router_admin_set = OSPF_STUB_ROUTER_ADMINISTRATIVE_SET; | |
9676 | ||
9677 | return CMD_SUCCESS; | |
88d6cf37 | 9678 | } |
9679 | ||
9680 | DEFUN (no_ospf_max_metric_router_lsa_admin, | |
9681 | no_ospf_max_metric_router_lsa_admin_cmd, | |
9682 | "no max-metric router-lsa administrative", | |
9683 | NO_STR | |
9684 | "OSPF maximum / infinite-distance metric\n" | |
9685 | "Advertise own Router-LSA with infinite distance (stub router)\n" | |
9686 | "Administratively applied, for an indefinite period\n") | |
9687 | { | |
a3d826f0 | 9688 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 9689 | struct listnode *ln; |
9690 | struct ospf_area *area; | |
9691 | ||
9692 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, ln, area)) { | |
9693 | UNSET_FLAG(area->stub_router_state, | |
9694 | OSPF_AREA_ADMIN_STUB_ROUTED); | |
9695 | ||
9696 | /* Don't trample on the start-up stub timer */ | |
9697 | if (CHECK_FLAG(area->stub_router_state, | |
9698 | OSPF_AREA_IS_STUB_ROUTED) | |
9699 | && !area->t_stub_router) { | |
9700 | UNSET_FLAG(area->stub_router_state, | |
9701 | OSPF_AREA_IS_STUB_ROUTED); | |
9702 | ospf_router_lsa_update_area(area); | |
9703 | } | |
9704 | } | |
9705 | ospf->stub_router_admin_set = OSPF_STUB_ROUTER_ADMINISTRATIVE_UNSET; | |
9706 | return CMD_SUCCESS; | |
88d6cf37 | 9707 | } |
9708 | ||
9709 | DEFUN (ospf_max_metric_router_lsa_startup, | |
9710 | ospf_max_metric_router_lsa_startup_cmd, | |
6147e2c6 | 9711 | "max-metric router-lsa on-startup (5-86400)", |
88d6cf37 | 9712 | "OSPF maximum / infinite-distance metric\n" |
9713 | "Advertise own Router-LSA with infinite distance (stub router)\n" | |
9714 | "Automatically advertise stub Router-LSA on startup of OSPF\n" | |
9715 | "Time (seconds) to advertise self as stub-router\n") | |
9716 | { | |
a3d826f0 | 9717 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 9718 | int idx_number = 3; |
9719 | unsigned int seconds; | |
9720 | ||
b5a8894d | 9721 | if (argc < 4) { |
4d4c404b | 9722 | vty_out(vty, "%% Must supply stub-router period\n"); |
d62a17ae | 9723 | return CMD_WARNING_CONFIG_FAILED; |
9724 | } | |
9725 | ||
9726 | seconds = strtoul(argv[idx_number]->arg, NULL, 10); | |
9727 | ||
9728 | ospf->stub_router_startup_time = seconds; | |
9729 | ||
9730 | return CMD_SUCCESS; | |
88d6cf37 | 9731 | } |
9732 | ||
9733 | DEFUN (no_ospf_max_metric_router_lsa_startup, | |
9734 | no_ospf_max_metric_router_lsa_startup_cmd, | |
7a7be519 | 9735 | "no max-metric router-lsa on-startup [(5-86400)]", |
88d6cf37 | 9736 | NO_STR |
9737 | "OSPF maximum / infinite-distance metric\n" | |
9738 | "Advertise own Router-LSA with infinite distance (stub router)\n" | |
813d4307 DW |
9739 | "Automatically advertise stub Router-LSA on startup of OSPF\n" |
9740 | "Time (seconds) to advertise self as stub-router\n") | |
88d6cf37 | 9741 | { |
a3d826f0 | 9742 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 9743 | struct listnode *ln; |
9744 | struct ospf_area *area; | |
9745 | ||
9746 | ospf->stub_router_startup_time = OSPF_STUB_ROUTER_UNCONFIGURED; | |
9747 | ||
9748 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, ln, area)) { | |
9749 | SET_FLAG(area->stub_router_state, | |
9750 | OSPF_AREA_WAS_START_STUB_ROUTED); | |
cccd44f3 | 9751 | THREAD_OFF(area->t_stub_router); |
d62a17ae | 9752 | |
9753 | /* Don't trample on admin stub routed */ | |
9754 | if (!CHECK_FLAG(area->stub_router_state, | |
9755 | OSPF_AREA_ADMIN_STUB_ROUTED)) { | |
9756 | UNSET_FLAG(area->stub_router_state, | |
9757 | OSPF_AREA_IS_STUB_ROUTED); | |
9758 | ospf_router_lsa_update_area(area); | |
9759 | } | |
9760 | } | |
9761 | return CMD_SUCCESS; | |
88d6cf37 | 9762 | } |
9763 | ||
a1afa410 | 9764 | |
88d6cf37 | 9765 | DEFUN (ospf_max_metric_router_lsa_shutdown, |
9766 | ospf_max_metric_router_lsa_shutdown_cmd, | |
6147e2c6 | 9767 | "max-metric router-lsa on-shutdown (5-100)", |
88d6cf37 | 9768 | "OSPF maximum / infinite-distance metric\n" |
9769 | "Advertise own Router-LSA with infinite distance (stub router)\n" | |
9770 | "Advertise stub-router prior to full shutdown of OSPF\n" | |
9771 | "Time (seconds) to wait till full shutdown\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) { |
4d4c404b | 9778 | vty_out(vty, "%% Must supply stub-router shutdown period\n"); |
d62a17ae | 9779 | return CMD_WARNING_CONFIG_FAILED; |
9780 | } | |
9781 | ||
9782 | seconds = strtoul(argv[idx_number]->arg, NULL, 10); | |
9783 | ||
9784 | ospf->stub_router_shutdown_time = seconds; | |
9785 | ||
9786 | return CMD_SUCCESS; | |
88d6cf37 | 9787 | } |
9788 | ||
9789 | DEFUN (no_ospf_max_metric_router_lsa_shutdown, | |
9790 | no_ospf_max_metric_router_lsa_shutdown_cmd, | |
7a7be519 | 9791 | "no max-metric router-lsa on-shutdown [(5-100)]", |
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 | "Advertise stub-router prior to full shutdown of OSPF\n" |
9796 | "Time (seconds) to wait till full shutdown\n") | |
88d6cf37 | 9797 | { |
a3d826f0 | 9798 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
7c8ff89e | 9799 | |
d62a17ae | 9800 | ospf->stub_router_shutdown_time = OSPF_STUB_ROUTER_UNCONFIGURED; |
9801 | ||
9802 | return CMD_SUCCESS; | |
88d6cf37 | 9803 | } |
9804 | ||
a92706bb JU |
9805 | DEFUN (ospf_proactive_arp, |
9806 | ospf_proactive_arp_cmd, | |
9807 | "proactive-arp", | |
9808 | "Allow sending ARP requests proactively\n") | |
9809 | { | |
9810 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
9811 | ||
9812 | ospf->proactive_arp = true; | |
9813 | ||
9814 | return CMD_SUCCESS; | |
9815 | } | |
9816 | ||
9817 | DEFUN (no_ospf_proactive_arp, | |
9818 | no_ospf_proactive_arp_cmd, | |
9819 | "no proactive-arp", | |
9820 | NO_STR | |
9821 | "Disallow sending ARP requests proactively\n") | |
9822 | { | |
9823 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
9824 | ||
9825 | ospf->proactive_arp = false; | |
9826 | ||
9827 | return CMD_SUCCESS; | |
9828 | } | |
9829 | ||
003d3dbe RW |
9830 | /* Graceful Restart HELPER Commands */ |
9831 | DEFPY(ospf_gr_helper_enable, ospf_gr_helper_enable_cmd, | |
9832 | "graceful-restart helper enable [A.B.C.D$address]", | |
9833 | "OSPF Graceful Restart\n" | |
9834 | "OSPF GR Helper\n" | |
9835 | "Enable Helper support\n" | |
9836 | "Advertising Router-ID\n") | |
9837 | { | |
9838 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
9839 | ||
9840 | if (address_str) { | |
9841 | ospf_gr_helper_support_set_per_routerid(ospf, &address, | |
9842 | OSPF_GR_TRUE); | |
9843 | return CMD_SUCCESS; | |
9844 | } | |
9845 | ||
9846 | ospf_gr_helper_support_set(ospf, OSPF_GR_TRUE); | |
9847 | ||
9848 | return CMD_SUCCESS; | |
9849 | } | |
9850 | ||
9851 | DEFPY(no_ospf_gr_helper_enable, | |
9852 | no_ospf_gr_helper_enable_cmd, | |
9853 | "no graceful-restart helper enable [A.B.C.D$address]", | |
9854 | NO_STR | |
9855 | "OSPF Graceful Restart\n" | |
9856 | "OSPF GR Helper\n" | |
9857 | "Enable Helper support\n" | |
9858 | "Advertising Router-ID\n") | |
9859 | { | |
9860 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
9861 | ||
9862 | if (address_str) { | |
9863 | ospf_gr_helper_support_set_per_routerid(ospf, &address, | |
9864 | OSPF_GR_FALSE); | |
9865 | return CMD_SUCCESS; | |
9866 | } | |
9867 | ||
9868 | ospf_gr_helper_support_set(ospf, OSPF_GR_FALSE); | |
9869 | return CMD_SUCCESS; | |
9870 | } | |
9871 | ||
9872 | #if CONFDATE > 20220921 | |
9873 | CPP_NOTICE( | |
9874 | "Time to remove the deprecated \"[no] graceful-restart helper-only\" commands") | |
859bce81 RW |
9875 | #endif |
9876 | ||
003d3dbe RW |
9877 | DEFPY_HIDDEN(ospf_gr_helper_only, ospf_gr_helper_only_cmd, |
9878 | "graceful-restart helper-only [A.B.C.D]", | |
9879 | "OSPF Graceful Restart\n" | |
9880 | "Enable Helper support\n" | |
9881 | "Advertising router id\n") | |
9882 | { | |
9883 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
9884 | struct in_addr addr; | |
9885 | int ret; | |
9886 | ||
9887 | vty_out(vty, | |
9888 | "%% This command is deprecated. Please, use `graceful-restart helper enable` instead.\n"); | |
9889 | ||
9890 | if (argc == 3) { | |
9891 | ret = inet_aton(argv[2]->arg, &addr); | |
9892 | if (!ret) { | |
9893 | vty_out(vty, | |
9894 | "Please specify the valid routerid address.\n"); | |
9895 | return CMD_WARNING_CONFIG_FAILED; | |
9896 | } | |
9897 | ||
9898 | ospf_gr_helper_support_set_per_routerid(ospf, &addr, OSPF_GR_TRUE); | |
9899 | return CMD_SUCCESS; | |
9900 | } | |
9901 | ||
9902 | ospf_gr_helper_support_set(ospf, OSPF_GR_TRUE); | |
9903 | ||
9904 | return CMD_SUCCESS; | |
9905 | } | |
9906 | ||
9907 | ALIAS_HIDDEN(no_ospf_gr_helper_enable, | |
9908 | no_ospf_gr_helper_only_cmd, | |
9909 | "no graceful-restart helper-only [A.B.C.D]", | |
9910 | NO_STR | |
9911 | "OSPF Graceful Restart\n" | |
9912 | "Disable Helper support\n" | |
9913 | "Advertising router id\n") | |
9914 | ||
9915 | DEFPY(ospf_gr_helper_enable_lsacheck, | |
9916 | ospf_gr_helper_enable_lsacheck_cmd, | |
9917 | "graceful-restart helper strict-lsa-checking", | |
9918 | "OSPF Graceful Restart\n" | |
9919 | "OSPF GR Helper\n" | |
9920 | "Enable strict LSA check\n") | |
9921 | { | |
9922 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
9923 | ||
9924 | ospf_gr_helper_lsa_check_set(ospf, OSPF_GR_TRUE); | |
9925 | return CMD_SUCCESS; | |
9926 | } | |
9927 | ||
9928 | DEFPY(no_ospf_gr_helper_enable_lsacheck, | |
9929 | no_ospf_gr_helper_enable_lsacheck_cmd, | |
9930 | "no graceful-restart helper strict-lsa-checking", | |
9931 | NO_STR | |
9932 | "OSPF Graceful Restart\n" | |
9933 | "OSPF GR Helper\n" | |
9934 | "Disable strict LSA check\n") | |
9935 | { | |
9936 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
9937 | ||
9938 | ospf_gr_helper_lsa_check_set(ospf, OSPF_GR_FALSE); | |
9939 | return CMD_SUCCESS; | |
9940 | } | |
9941 | ||
9942 | DEFPY(ospf_gr_helper_supported_grace_time, | |
9943 | ospf_gr_helper_supported_grace_time_cmd, | |
9944 | "graceful-restart helper supported-grace-time (10-1800)$interval", | |
9945 | "OSPF Graceful Restart\n" | |
9946 | "OSPF GR Helper\n" | |
9947 | "Supported grace timer\n" | |
9948 | "Grace interval(in seconds)\n") | |
9949 | { | |
9950 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
9951 | ||
9952 | ospf_gr_helper_supported_gracetime_set(ospf, interval); | |
9953 | return CMD_SUCCESS; | |
9954 | } | |
9955 | ||
9956 | DEFPY(no_ospf_gr_helper_supported_grace_time, | |
9957 | no_ospf_gr_helper_supported_grace_time_cmd, | |
9958 | "no graceful-restart helper supported-grace-time (10-1800)$interval", | |
9959 | NO_STR | |
9960 | "OSPF Graceful Restart\n" | |
9961 | "OSPF GR Helper\n" | |
9962 | "Supported grace timer\n" | |
9963 | "Grace interval(in seconds)\n") | |
9964 | { | |
9965 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
9966 | ||
9967 | ospf_gr_helper_supported_gracetime_set(ospf, OSPF_MAX_GRACE_INTERVAL); | |
9968 | return CMD_SUCCESS; | |
9969 | } | |
9970 | ||
9971 | DEFPY(ospf_gr_helper_planned_only, | |
9972 | ospf_gr_helper_planned_only_cmd, | |
9973 | "graceful-restart helper planned-only", | |
9974 | "OSPF Graceful Restart\n" | |
9975 | "OSPF GR Helper\n" | |
9976 | "Supported only planned restart\n") | |
9977 | { | |
9978 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
9979 | ||
9980 | ospf_gr_helper_set_supported_planned_only_restart(ospf, OSPF_GR_TRUE); | |
9981 | ||
9982 | return CMD_SUCCESS; | |
9983 | } | |
9984 | ||
423e71c4 | 9985 | /* External Route Aggregation */ |
9986 | DEFUN (ospf_external_route_aggregation, | |
9987 | ospf_external_route_aggregation_cmd, | |
9988 | "summary-address A.B.C.D/M [tag (1-4294967295)]", | |
9989 | "External summary address\n" | |
78cf8877 | 9990 | "Summary address prefix\n" |
423e71c4 | 9991 | "Router tag \n" |
9992 | "Router tag value\n") | |
9993 | { | |
9994 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
9995 | struct prefix_ipv4 p; | |
9996 | int idx = 1; | |
9997 | route_tag_t tag = 0; | |
9998 | int ret = OSPF_SUCCESS; | |
9999 | ||
10000 | str2prefix_ipv4(argv[idx]->arg, &p); | |
10001 | ||
1fe59b44 | 10002 | if (is_default_prefix4(&p)) { |
423e71c4 | 10003 | vty_out(vty, |
10004 | "Default address shouldn't be configured as summary address.\n"); | |
10005 | return CMD_SUCCESS; | |
10006 | } | |
10007 | ||
10008 | /* Apply mask for given prefix. */ | |
8998807f | 10009 | apply_mask(&p); |
423e71c4 | 10010 | |
10011 | if (!is_valid_summary_addr(&p)) { | |
10012 | vty_out(vty, "Not a valid summary address.\n"); | |
10013 | return CMD_WARNING_CONFIG_FAILED; | |
10014 | } | |
10015 | ||
10016 | if (argc > 2) | |
10017 | tag = strtoul(argv[idx + 2]->arg, NULL, 10); | |
10018 | ||
10019 | ret = ospf_asbr_external_aggregator_set(ospf, &p, tag); | |
10020 | if (ret == OSPF_INVALID) | |
ea3f3df5 | 10021 | vty_out(vty, "Invalid configuration!!\n"); |
423e71c4 | 10022 | |
10023 | return CMD_SUCCESS; | |
10024 | } | |
10025 | ||
10026 | DEFUN (no_ospf_external_route_aggregation, | |
10027 | no_ospf_external_route_aggregation_cmd, | |
10028 | "no summary-address A.B.C.D/M [tag (1-4294967295)]", | |
10029 | NO_STR | |
10030 | "External summary address\n" | |
78cf8877 | 10031 | "Summary address prefix\n" |
423e71c4 | 10032 | "Router tag\n" |
10033 | "Router tag value\n") | |
10034 | { | |
10035 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
10036 | struct prefix_ipv4 p; | |
10037 | int idx = 2; | |
10038 | route_tag_t tag = 0; | |
10039 | int ret = OSPF_SUCCESS; | |
10040 | ||
10041 | str2prefix_ipv4(argv[idx]->arg, &p); | |
10042 | ||
1fe59b44 | 10043 | if (is_default_prefix4(&p)) { |
423e71c4 | 10044 | vty_out(vty, |
10045 | "Default address shouldn't be configured as summary address.\n"); | |
10046 | return CMD_SUCCESS; | |
10047 | } | |
10048 | ||
10049 | /* Apply mask for given prefix. */ | |
8998807f | 10050 | apply_mask(&p); |
423e71c4 | 10051 | |
10052 | if (!is_valid_summary_addr(&p)) { | |
10053 | vty_out(vty, "Not a valid summary address.\n"); | |
10054 | return CMD_WARNING_CONFIG_FAILED; | |
10055 | } | |
10056 | ||
10057 | if (argc > 3) | |
10058 | tag = strtoul(argv[idx + 2]->arg, NULL, 10); | |
10059 | ||
10060 | ret = ospf_asbr_external_aggregator_unset(ospf, &p, tag); | |
10061 | if (ret == OSPF_INVALID) | |
ea3f3df5 | 10062 | vty_out(vty, "Invalid configuration!!\n"); |
423e71c4 | 10063 | |
10064 | return CMD_SUCCESS; | |
10065 | } | |
10066 | ||
003d3dbe RW |
10067 | DEFPY(no_ospf_gr_helper_planned_only, |
10068 | no_ospf_gr_helper_planned_only_cmd, | |
10069 | "no graceful-restart helper planned-only", | |
10070 | NO_STR | |
10071 | "OSPF Graceful Restart\n" | |
10072 | "OSPF GR Helper\n" | |
10073 | "Supported only for planned restart\n") | |
10074 | { | |
10075 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
10076 | ||
10077 | ospf_gr_helper_set_supported_planned_only_restart(ospf, OSPF_GR_FALSE); | |
10078 | ||
10079 | return CMD_SUCCESS; | |
10080 | } | |
10081 | ||
10082 | static int ospf_print_vty_helper_dis_rtr_walkcb(struct hash_bucket *bucket, | |
10083 | void *arg) | |
10084 | { | |
10085 | struct advRtr *rtr = bucket->data; | |
10086 | struct vty *vty = (struct vty *)arg; | |
10087 | static unsigned int count; | |
10088 | ||
10089 | vty_out(vty, "%-6pI4,", &rtr->advRtrAddr); | |
10090 | count++; | |
10091 | ||
10092 | if (count % 5 == 0) | |
10093 | vty_out(vty, "\n"); | |
10094 | ||
10095 | return HASHWALK_CONTINUE; | |
10096 | } | |
10097 | ||
10098 | static int ospf_show_gr_helper_details(struct vty *vty, struct ospf *ospf, | |
10099 | uint8_t use_vrf, json_object *json, | |
10100 | bool uj, bool detail) | |
10101 | { | |
10102 | struct listnode *node; | |
10103 | struct ospf_interface *oi; | |
10104 | char buf[PREFIX_STRLEN]; | |
10105 | json_object *json_vrf = NULL; | |
10106 | ||
10107 | if (uj) { | |
10108 | if (use_vrf) | |
10109 | json_vrf = json_object_new_object(); | |
10110 | else | |
10111 | json_vrf = json; | |
10112 | } | |
10113 | ||
10114 | if (ospf->instance) { | |
10115 | if (uj) | |
10116 | json_object_int_add(json, "ospfInstance", | |
10117 | ospf->instance); | |
10118 | else | |
10119 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
10120 | } | |
10121 | ||
10122 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); | |
10123 | ||
10124 | if (uj) { | |
10125 | if (use_vrf) | |
10126 | json_object_object_add(json, ospf_get_name(ospf), | |
10127 | json_vrf); | |
10128 | } else | |
10129 | vty_out(vty, "\n"); | |
10130 | ||
10131 | /* Show Router ID. */ | |
10132 | if (uj) { | |
10133 | json_object_string_add(json_vrf, "routerId", | |
10134 | inet_ntop(AF_INET, &ospf->router_id, | |
10135 | buf, sizeof(buf))); | |
10136 | } else { | |
10137 | vty_out(vty, "\n OSPF Router with ID (%pI4)\n\n", | |
10138 | &ospf->router_id); | |
10139 | } | |
10140 | ||
10141 | if (!uj) { | |
10142 | ||
10143 | if (ospf->is_helper_supported) | |
10144 | vty_out(vty, | |
10145 | " Graceful restart helper support enabled.\n"); | |
10146 | else | |
10147 | vty_out(vty, | |
10148 | " Graceful restart helper support disabled.\n"); | |
10149 | ||
10150 | if (ospf->strict_lsa_check) | |
10151 | vty_out(vty, " Strict LSA check is enabled.\n"); | |
10152 | else | |
10153 | vty_out(vty, " Strict LSA check is disabled.\n"); | |
10154 | ||
10155 | if (ospf->only_planned_restart) | |
10156 | vty_out(vty, | |
10157 | " Helper supported for planned restarts only.\n"); | |
10158 | else | |
10159 | vty_out(vty, | |
10160 | " Helper supported for Planned and Unplanned Restarts.\n"); | |
10161 | ||
10162 | vty_out(vty, | |
10163 | " Supported Graceful restart interval: %d(in seconds).\n", | |
10164 | ospf->supported_grace_time); | |
10165 | ||
10166 | if (OSPF_HELPER_ENABLE_RTR_COUNT(ospf)) { | |
10167 | vty_out(vty, " Enable Router list:\n"); | |
10168 | vty_out(vty, " "); | |
10169 | hash_walk(ospf->enable_rtr_list, | |
10170 | ospf_print_vty_helper_dis_rtr_walkcb, vty); | |
10171 | vty_out(vty, "\n\n"); | |
10172 | } | |
10173 | ||
10174 | if (ospf->last_exit_reason != OSPF_GR_HELPER_EXIT_NONE) { | |
10175 | vty_out(vty, " Last Helper exit Reason :%s\n", | |
10176 | ospf_exit_reason2str(ospf->last_exit_reason)); | |
10177 | } | |
10178 | ||
10179 | if (ospf->active_restarter_cnt) | |
10180 | vty_out(vty, | |
10181 | " Number of Active neighbours in graceful restart: %d\n", | |
10182 | ospf->active_restarter_cnt); | |
10183 | else | |
10184 | vty_out(vty, "\n"); | |
10185 | ||
10186 | } else { | |
10187 | json_object_string_add( | |
10188 | json_vrf, "helperSupport", | |
10189 | (ospf->is_helper_supported) ? "Enabled" : "Disabled"); | |
10190 | json_object_string_add(json_vrf, "strictLsaCheck", | |
10191 | (ospf->strict_lsa_check) ? "Enabled" | |
10192 | : "Disabled"); | |
10193 | json_object_string_add( | |
10194 | json_vrf, "restartSupoort", | |
10195 | (ospf->only_planned_restart) | |
10196 | ? "Planned Restart only" | |
10197 | : "Planned and Unplanned Restarts"); | |
10198 | ||
10199 | json_object_int_add(json_vrf, "supportedGracePeriod", | |
10200 | ospf->supported_grace_time); | |
10201 | ||
77a2f8e5 DA |
10202 | #if CONFDATE > 20230131 |
10203 | CPP_NOTICE("Remove JSON object commands with keys starting with capital") | |
10204 | #endif | |
10205 | if (ospf->last_exit_reason != OSPF_GR_HELPER_EXIT_NONE) { | |
003d3dbe RW |
10206 | json_object_string_add( |
10207 | json_vrf, "LastExitReason", | |
10208 | ospf_exit_reason2str(ospf->last_exit_reason)); | |
77a2f8e5 DA |
10209 | json_object_string_add( |
10210 | json_vrf, "lastExitReason", | |
10211 | ospf_exit_reason2str(ospf->last_exit_reason)); | |
10212 | } | |
003d3dbe RW |
10213 | |
10214 | if (ospf->active_restarter_cnt) | |
10215 | json_object_int_add(json_vrf, "activeRestarterCnt", | |
10216 | ospf->active_restarter_cnt); | |
10217 | } | |
10218 | ||
10219 | ||
10220 | if (detail) { | |
10221 | int cnt = 1; | |
10222 | json_object *json_neighbors = NULL; | |
10223 | ||
10224 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) { | |
10225 | struct route_node *rn; | |
10226 | struct ospf_neighbor *nbr; | |
10227 | json_object *json_neigh; | |
10228 | ||
10229 | if (ospf_interface_neighbor_count(oi) == 0) | |
10230 | continue; | |
10231 | ||
10232 | if (uj) { | |
10233 | json_object_object_get_ex(json_vrf, "Neighbors", | |
10234 | &json_neighbors); | |
77a2f8e5 DA |
10235 | json_object_object_get_ex(json_vrf, "neighbors", |
10236 | &json_neighbors); | |
003d3dbe RW |
10237 | if (!json_neighbors) { |
10238 | json_neighbors = | |
10239 | json_object_new_object(); | |
10240 | json_object_object_add(json_vrf, | |
10241 | "Neighbors", | |
10242 | json_neighbors); | |
77a2f8e5 DA |
10243 | json_object_object_add(json_vrf, |
10244 | "neighbors", | |
10245 | json_neighbors); | |
003d3dbe RW |
10246 | } |
10247 | } | |
10248 | ||
10249 | for (rn = route_top(oi->nbrs); rn; | |
10250 | rn = route_next(rn)) { | |
10251 | ||
10252 | if (!rn->info) | |
10253 | continue; | |
10254 | ||
10255 | nbr = rn->info; | |
10256 | ||
10257 | if (!OSPF_GR_IS_ACTIVE_HELPER(nbr)) | |
10258 | continue; | |
10259 | ||
10260 | if (!uj) { | |
10261 | vty_out(vty, " Neighbour %d :\n", cnt); | |
10262 | vty_out(vty, " Address : %pI4\n", | |
10263 | &nbr->address.u.prefix4); | |
10264 | vty_out(vty, " Routerid : %pI4\n", | |
10265 | &nbr->router_id); | |
10266 | vty_out(vty, | |
10267 | " Received Grace period : %d(in seconds).\n", | |
10268 | nbr->gr_helper_info | |
10269 | .recvd_grace_period); | |
10270 | vty_out(vty, | |
10271 | " Actual Grace period : %d(in seconds)\n", | |
10272 | nbr->gr_helper_info | |
10273 | .actual_grace_period); | |
10274 | vty_out(vty, | |
10275 | " Remaining GraceTime:%ld(in seconds).\n", | |
10276 | thread_timer_remain_second( | |
10277 | nbr->gr_helper_info | |
10278 | .t_grace_timer)); | |
10279 | vty_out(vty, | |
10280 | " Graceful Restart reason: %s.\n\n", | |
10281 | ospf_restart_reason2str( | |
10282 | nbr->gr_helper_info | |
10283 | .gr_restart_reason)); | |
10284 | cnt++; | |
10285 | } else { | |
10286 | json_neigh = json_object_new_object(); | |
10287 | json_object_string_add( | |
10288 | json_neigh, "srcAddr", | |
10289 | inet_ntop(AF_INET, &nbr->src, | |
10290 | buf, sizeof(buf))); | |
10291 | ||
10292 | json_object_string_add( | |
10293 | json_neigh, "routerid", | |
10294 | inet_ntop(AF_INET, | |
10295 | &nbr->router_id, | |
10296 | buf, sizeof(buf))); | |
10297 | json_object_int_add( | |
10298 | json_neigh, | |
10299 | "recvdGraceInterval", | |
10300 | nbr->gr_helper_info | |
10301 | .recvd_grace_period); | |
10302 | json_object_int_add( | |
10303 | json_neigh, | |
10304 | "actualGraceInterval", | |
10305 | nbr->gr_helper_info | |
10306 | .actual_grace_period); | |
10307 | json_object_int_add( | |
10308 | json_neigh, "remainGracetime", | |
10309 | thread_timer_remain_second( | |
10310 | nbr->gr_helper_info | |
10311 | .t_grace_timer)); | |
10312 | json_object_string_add( | |
10313 | json_neigh, "restartReason", | |
10314 | ospf_restart_reason2str( | |
10315 | nbr->gr_helper_info | |
10316 | .gr_restart_reason)); | |
10317 | json_object_object_add( | |
10318 | json_neighbors, | |
10319 | inet_ntop(AF_INET, &nbr->src, | |
10320 | buf, sizeof(buf)), | |
10321 | json_neigh); | |
10322 | } | |
10323 | } | |
10324 | } | |
10325 | } | |
10326 | return CMD_SUCCESS; | |
10327 | } | |
10328 | ||
423e71c4 | 10329 | DEFUN (ospf_external_route_aggregation_no_adrvertise, |
10330 | ospf_external_route_aggregation_no_adrvertise_cmd, | |
10331 | "summary-address A.B.C.D/M no-advertise", | |
10332 | "External summary address\n" | |
78cf8877 | 10333 | "Summary address prefix\n" |
423e71c4 | 10334 | "Don't advertise summary route \n") |
10335 | { | |
10336 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
10337 | struct prefix_ipv4 p; | |
10338 | int idx = 1; | |
10339 | int ret = OSPF_SUCCESS; | |
10340 | ||
10341 | str2prefix_ipv4(argv[idx]->arg, &p); | |
10342 | ||
1fe59b44 | 10343 | if (is_default_prefix4(&p)) { |
423e71c4 | 10344 | vty_out(vty, |
10345 | "Default address shouldn't be configured as summary address.\n"); | |
10346 | return CMD_SUCCESS; | |
10347 | } | |
10348 | ||
10349 | /* Apply mask for given prefix. */ | |
8998807f | 10350 | apply_mask(&p); |
423e71c4 | 10351 | |
10352 | if (!is_valid_summary_addr(&p)) { | |
10353 | vty_out(vty, "Not a valid summary address.\n"); | |
10354 | return CMD_WARNING_CONFIG_FAILED; | |
10355 | } | |
10356 | ||
10357 | ret = ospf_asbr_external_rt_no_advertise(ospf, &p); | |
10358 | if (ret == OSPF_INVALID) | |
ea3f3df5 | 10359 | vty_out(vty, "Invalid configuration!!\n"); |
423e71c4 | 10360 | |
10361 | return CMD_SUCCESS; | |
10362 | } | |
10363 | ||
10364 | DEFUN (no_ospf_external_route_aggregation_no_adrvertise, | |
10365 | no_ospf_external_route_aggregation_no_adrvertise_cmd, | |
10366 | "no summary-address A.B.C.D/M no-advertise", | |
10367 | NO_STR | |
10368 | "External summary address\n" | |
78cf8877 | 10369 | "Summary address prefix\n" |
fbc48492 | 10370 | "Advertise summary route to the AS \n") |
423e71c4 | 10371 | { |
10372 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
10373 | struct prefix_ipv4 p; | |
10374 | int idx = 2; | |
10375 | int ret = OSPF_SUCCESS; | |
10376 | ||
10377 | str2prefix_ipv4(argv[idx]->arg, &p); | |
10378 | ||
1fe59b44 | 10379 | if (is_default_prefix4(&p)) { |
423e71c4 | 10380 | vty_out(vty, |
10381 | "Default address shouldn't be configured as summary address.\n"); | |
10382 | return CMD_SUCCESS; | |
10383 | } | |
10384 | ||
10385 | /* Apply mask for given prefix. */ | |
8998807f | 10386 | apply_mask(&p); |
423e71c4 | 10387 | |
10388 | if (!is_valid_summary_addr(&p)) { | |
10389 | vty_out(vty, "Not a valid summary address.\n"); | |
10390 | return CMD_WARNING_CONFIG_FAILED; | |
10391 | } | |
10392 | ||
10393 | ret = ospf_asbr_external_rt_advertise(ospf, &p); | |
10394 | if (ret == OSPF_INVALID) | |
ea3f3df5 | 10395 | vty_out(vty, "Invalid configuration!!\n"); |
423e71c4 | 10396 | |
10397 | return CMD_SUCCESS; | |
10398 | } | |
10399 | ||
10400 | DEFUN (ospf_route_aggregation_timer, | |
10401 | ospf_route_aggregation_timer_cmd, | |
10402 | "aggregation timer (5-1800)", | |
10403 | "External route aggregation\n" | |
10404 | "Delay timer (in seconds)\n" | |
10405 | "Timer interval(in seconds)\n") | |
10406 | { | |
10407 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
4b939ad2 | 10408 | uint16_t interval = 0; |
423e71c4 | 10409 | |
10410 | interval = strtoul(argv[2]->arg, NULL, 10); | |
10411 | ||
10412 | ospf_external_aggregator_timer_set(ospf, interval); | |
abd5b8c7 | 10413 | |
10414 | return CMD_SUCCESS; | |
10415 | } | |
10416 | ||
003d3dbe RW |
10417 | DEFPY (show_ip_ospf_gr_helper, |
10418 | show_ip_ospf_gr_helper_cmd, | |
10419 | "show ip ospf [vrf <NAME|all>] graceful-restart helper [detail] [json]", | |
10420 | SHOW_STR | |
10421 | IP_STR | |
10422 | "OSPF information\n" | |
10423 | VRF_CMD_HELP_STR | |
10424 | "All VRFs\n" | |
10425 | "OSPF Graceful Restart\n" | |
10426 | "Helper details in the router\n" | |
1461559c | 10427 | "Detailed information\n" |
003d3dbe RW |
10428 | JSON_STR) |
10429 | { | |
10430 | char *vrf_name = NULL; | |
10431 | bool all_vrf = false; | |
10432 | int ret = CMD_SUCCESS; | |
10433 | int idx_vrf = 0; | |
10434 | int idx = 0; | |
10435 | uint8_t use_vrf = 0; | |
10436 | bool uj = use_json(argc, argv); | |
10437 | struct ospf *ospf = NULL; | |
10438 | json_object *json = NULL; | |
10439 | struct listnode *node = NULL; | |
10440 | int inst = 0; | |
10441 | bool detail = false; | |
10442 | ||
10443 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); | |
10444 | ||
10445 | if (argv_find(argv, argc, "detail", &idx)) | |
10446 | detail = true; | |
10447 | ||
10448 | if (uj) | |
10449 | json = json_object_new_object(); | |
10450 | ||
10451 | /* vrf input is provided */ | |
10452 | if (vrf_name) { | |
10453 | use_vrf = 1; | |
10454 | ||
10455 | if (all_vrf) { | |
10456 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
10457 | if (!ospf->oi_running) | |
10458 | continue; | |
10459 | ||
10460 | ret = ospf_show_gr_helper_details( | |
10461 | vty, ospf, use_vrf, json, uj, detail); | |
10462 | } | |
10463 | ||
a38db2fa DA |
10464 | if (uj) |
10465 | vty_json(vty, json); | |
003d3dbe RW |
10466 | |
10467 | return ret; | |
10468 | } | |
10469 | ||
10470 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
10471 | ||
10472 | if (ospf == NULL || !ospf->oi_running) { | |
10473 | ||
a38db2fa DA |
10474 | if (uj) |
10475 | vty_json(vty, json); | |
10476 | else | |
fbaafa00 JAG |
10477 | vty_out(vty, |
10478 | "%% OSPF is not enabled in vrf %s\n", | |
10479 | vrf_name); | |
003d3dbe RW |
10480 | |
10481 | return CMD_SUCCESS; | |
10482 | } | |
10483 | ||
10484 | } else { | |
10485 | /* Default Vrf */ | |
10486 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
10487 | ||
10488 | if (ospf == NULL || !ospf->oi_running) { | |
10489 | ||
a38db2fa DA |
10490 | if (uj) |
10491 | vty_json(vty, json); | |
10492 | else | |
fbaafa00 JAG |
10493 | vty_out(vty, |
10494 | "%% OSPF is not enabled in vrf default\n"); | |
003d3dbe RW |
10495 | |
10496 | return CMD_SUCCESS; | |
10497 | } | |
10498 | ||
10499 | ospf_show_gr_helper_details(vty, ospf, use_vrf, json, uj, | |
10500 | detail); | |
10501 | } | |
10502 | ||
a38db2fa DA |
10503 | if (uj) |
10504 | vty_json(vty, json); | |
003d3dbe RW |
10505 | |
10506 | return CMD_SUCCESS; | |
10507 | } | |
10508 | /* Graceful Restart HELPER commands end */ | |
423e71c4 | 10509 | DEFUN (no_ospf_route_aggregation_timer, |
10510 | no_ospf_route_aggregation_timer_cmd, | |
10511 | "no aggregation timer", | |
10512 | NO_STR | |
10513 | "External route aggregation\n" | |
10514 | "Delay timer\n") | |
10515 | { | |
10516 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
10517 | ||
10518 | ospf_external_aggregator_timer_set(ospf, OSPF_EXTL_AGGR_DEFAULT_DELAY); | |
10519 | ||
10520 | return CMD_SUCCESS; | |
10521 | } | |
10522 | ||
10523 | /* External Route Aggregation End */ | |
07b33add | 10524 | |
d62a17ae | 10525 | static void config_write_stub_router(struct vty *vty, struct ospf *ospf) |
10526 | { | |
10527 | struct listnode *ln; | |
10528 | struct ospf_area *area; | |
10529 | ||
10530 | if (ospf->stub_router_startup_time != OSPF_STUB_ROUTER_UNCONFIGURED) | |
10531 | vty_out(vty, " max-metric router-lsa on-startup %u\n", | |
10532 | ospf->stub_router_startup_time); | |
10533 | if (ospf->stub_router_shutdown_time != OSPF_STUB_ROUTER_UNCONFIGURED) | |
10534 | vty_out(vty, " max-metric router-lsa on-shutdown %u\n", | |
10535 | ospf->stub_router_shutdown_time); | |
10536 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, ln, area)) { | |
10537 | if (CHECK_FLAG(area->stub_router_state, | |
10538 | OSPF_AREA_ADMIN_STUB_ROUTED)) { | |
10539 | vty_out(vty, " max-metric router-lsa administrative\n"); | |
10540 | break; | |
10541 | } | |
10542 | } | |
10543 | return; | |
10544 | } | |
10545 | ||
08d79bce DA |
10546 | #if CONFDATE > 20230131 |
10547 | CPP_NOTICE("Remove JSON object commands with keys containing whitespaces") | |
10548 | #endif | |
b5a8894d | 10549 | static void show_ip_ospf_route_network(struct vty *vty, struct ospf *ospf, |
0f478e30 CS |
10550 | struct route_table *rt, |
10551 | json_object *json) | |
d62a17ae | 10552 | { |
10553 | struct route_node *rn; | |
10554 | struct ospf_route * or ; | |
10555 | struct listnode *pnode, *pnnode; | |
10556 | struct ospf_path *path; | |
0f478e30 CS |
10557 | json_object *json_route = NULL, *json_nexthop_array = NULL, |
10558 | *json_nexthop = NULL; | |
d62a17ae | 10559 | |
0f478e30 | 10560 | if (!json) |
996c9314 LB |
10561 | vty_out(vty, |
10562 | "============ OSPF network routing table ============\n"); | |
d62a17ae | 10563 | |
0f478e30 | 10564 | for (rn = route_top(rt); rn; rn = route_next(rn)) { |
96b663a3 MS |
10565 | char buf1[PREFIX2STR_BUFFER]; |
10566 | ||
0f478e30 CS |
10567 | if ((or = rn->info) == NULL) |
10568 | continue; | |
0f478e30 | 10569 | |
0f478e30 CS |
10570 | prefix2str(&rn->p, buf1, sizeof(buf1)); |
10571 | ||
19d37e54 DS |
10572 | if (json) { |
10573 | json_route = json_object_new_object(); | |
996c9314 | 10574 | json_object_object_add(json, buf1, json_route); |
19d37e54 | 10575 | } |
0f478e30 CS |
10576 | |
10577 | switch (or->path_type) { | |
10578 | case OSPF_PATH_INTER_AREA: | |
10579 | if (or->type == OSPF_DESTINATION_NETWORK) { | |
10580 | if (json) { | |
10581 | json_object_string_add(json_route, | |
996c9314 LB |
10582 | "routeType", |
10583 | "N IA"); | |
10584 | json_object_int_add(json_route, "cost", | |
0f478e30 | 10585 | or->cost); |
20308be3 DA |
10586 | json_object_string_addf( |
10587 | json_route, "area", "%pI4", | |
10588 | &or->u.std.area_id); | |
0f478e30 | 10589 | } else { |
d62a17ae | 10590 | vty_out(vty, |
96b663a3 | 10591 | "N IA %-18s [%d] area: %pI4\n", |
d62a17ae | 10592 | buf1, or->cost, |
96b663a3 | 10593 | &or->u.std.area_id); |
0f478e30 | 10594 | } |
996c9314 | 10595 | } else if (or->type == OSPF_DESTINATION_DISCARD) { |
0f478e30 CS |
10596 | if (json) { |
10597 | json_object_string_add(json_route, | |
996c9314 LB |
10598 | "routeType", |
10599 | "D IA"); | |
0f478e30 | 10600 | } else { |
d62a17ae | 10601 | vty_out(vty, |
10602 | "D IA %-18s Discard entry\n", | |
10603 | buf1); | |
0f478e30 CS |
10604 | } |
10605 | } | |
10606 | break; | |
10607 | case OSPF_PATH_INTRA_AREA: | |
10608 | if (json) { | |
996c9314 LB |
10609 | json_object_string_add(json_route, "routeType", |
10610 | "N"); | |
0f478e30 | 10611 | json_object_int_add(json_route, "cost", |
996c9314 | 10612 | or->cost); |
20308be3 DA |
10613 | json_object_string_addf(json_route, "area", |
10614 | "%pI4", | |
10615 | &or->u.std.area_id); | |
0f478e30 | 10616 | } else { |
96b663a3 | 10617 | vty_out(vty, "N %-18s [%d] area: %pI4\n", |
d62a17ae | 10618 | buf1, or->cost, |
96b663a3 | 10619 | &or->u.std.area_id); |
0f478e30 CS |
10620 | } |
10621 | break; | |
10622 | default: | |
10623 | break; | |
10624 | } | |
10625 | ||
10626 | if (or->type == OSPF_DESTINATION_NETWORK) { | |
10627 | if (json) { | |
10628 | json_nexthop_array = json_object_new_array(); | |
10629 | json_object_object_add(json_route, "nexthops", | |
996c9314 | 10630 | json_nexthop_array); |
d62a17ae | 10631 | } |
10632 | ||
0f478e30 CS |
10633 | for (ALL_LIST_ELEMENTS(or->paths, pnode, pnnode, |
10634 | path)) { | |
10635 | if (json) { | |
996c9314 LB |
10636 | json_nexthop = json_object_new_object(); |
10637 | json_object_array_add( | |
10638 | json_nexthop_array, | |
10639 | json_nexthop); | |
0f478e30 CS |
10640 | } |
10641 | if (if_lookup_by_index(path->ifindex, | |
10642 | ospf->vrf_id)) { | |
10643 | ||
3a6290bd DA |
10644 | if (path->nexthop.s_addr |
10645 | == INADDR_ANY) { | |
0f478e30 CS |
10646 | if (json) { |
10647 | json_object_string_add( | |
10648 | json_nexthop, | |
996c9314 | 10649 | "ip", " "); |
0f478e30 CS |
10650 | json_object_string_add( |
10651 | json_nexthop, | |
10652 | "directly attached to", | |
d62a17ae | 10653 | ifindex2ifname( |
996c9314 LB |
10654 | path->ifindex, |
10655 | ospf->vrf_id)); | |
08d79bce DA |
10656 | json_object_string_add( |
10657 | json_nexthop, | |
10658 | "directlyAttachedTo", | |
10659 | ifindex2ifname( | |
10660 | path->ifindex, | |
10661 | ospf->vrf_id)); | |
0f478e30 | 10662 | } else { |
d62a17ae | 10663 | vty_out(vty, |
996c9314 LB |
10664 | "%24s directly attached to %s\n", |
10665 | "", | |
10666 | ifindex2ifname( | |
10667 | path->ifindex, | |
10668 | ospf->vrf_id)); | |
0f478e30 CS |
10669 | } |
10670 | } else { | |
10671 | if (json) { | |
20308be3 | 10672 | json_object_string_addf( |
0f478e30 | 10673 | json_nexthop, |
20308be3 DA |
10674 | "ip", "%pI4", |
10675 | &path->nexthop); | |
0f478e30 CS |
10676 | json_object_string_add( |
10677 | json_nexthop, | |
10678 | "via", | |
d62a17ae | 10679 | ifindex2ifname( |
996c9314 LB |
10680 | path->ifindex, |
10681 | ospf->vrf_id)); | |
0f478e30 CS |
10682 | } else { |
10683 | vty_out(vty, | |
96b663a3 | 10684 | "%24s via %pI4, %s\n", |
996c9314 | 10685 | "", |
96b663a3 | 10686 | &path->nexthop, |
996c9314 LB |
10687 | ifindex2ifname( |
10688 | path->ifindex, | |
10689 | ospf->vrf_id)); | |
0f478e30 | 10690 | } |
d62a17ae | 10691 | } |
10692 | } | |
0f478e30 | 10693 | } |
d62a17ae | 10694 | } |
0f478e30 CS |
10695 | } |
10696 | if (!json) | |
10697 | vty_out(vty, "\n"); | |
d62a17ae | 10698 | } |
10699 | ||
b5a8894d | 10700 | static void show_ip_ospf_route_router(struct vty *vty, struct ospf *ospf, |
0f478e30 CS |
10701 | struct route_table *rtrs, |
10702 | json_object *json) | |
d62a17ae | 10703 | { |
10704 | struct route_node *rn; | |
10705 | struct ospf_route * or ; | |
10706 | struct listnode *pnode; | |
10707 | struct listnode *node; | |
10708 | struct ospf_path *path; | |
96b663a3 | 10709 | char buf[PREFIX_STRLEN]; |
0f478e30 CS |
10710 | json_object *json_route = NULL, *json_nexthop_array = NULL, |
10711 | *json_nexthop = NULL; | |
d62a17ae | 10712 | |
0f478e30 | 10713 | if (!json) |
d86760ac CH |
10714 | vty_out(vty, "============ OSPF %s table =============\n", |
10715 | ospf->all_rtrs == rtrs ? "reachable routers" | |
10716 | : "router routing"); | |
d62a17ae | 10717 | |
0f478e30 CS |
10718 | for (rn = route_top(rtrs); rn; rn = route_next(rn)) { |
10719 | if (rn->info == NULL) | |
10720 | continue; | |
10721 | int flag = 0; | |
10722 | ||
0f478e30 | 10723 | if (json) { |
19d37e54 | 10724 | json_route = json_object_new_object(); |
96b663a3 MS |
10725 | json_object_object_add( |
10726 | json, inet_ntop(AF_INET, &rn->p.u.prefix4, | |
10727 | buf, sizeof(buf)), | |
10728 | json_route); | |
996c9314 | 10729 | json_object_string_add(json_route, "routeType", "R "); |
0f478e30 | 10730 | } else { |
96b663a3 MS |
10731 | vty_out(vty, "R %-15pI4 ", |
10732 | &rn->p.u.prefix4); | |
0f478e30 | 10733 | } |
d62a17ae | 10734 | |
996c9314 | 10735 | for (ALL_LIST_ELEMENTS_RO((struct list *)rn->info, node, or)) { |
0f478e30 CS |
10736 | if (flag++) { |
10737 | if (!json) | |
d62a17ae | 10738 | vty_out(vty, "%24s", ""); |
0f478e30 | 10739 | } |
d62a17ae | 10740 | |
0f478e30 CS |
10741 | /* Show path. */ |
10742 | if (json) { | |
10743 | json_object_int_add(json_route, "cost", | |
10744 | or->cost); | |
20308be3 DA |
10745 | json_object_string_addf(json_route, "area", |
10746 | "%pI4", | |
10747 | &or->u.std.area_id); | |
77a2f8e5 | 10748 | if (or->path_type == OSPF_PATH_INTER_AREA) { |
996c9314 LB |
10749 | json_object_boolean_true_add(json_route, |
10750 | "IA"); | |
77a2f8e5 DA |
10751 | json_object_boolean_true_add(json_route, |
10752 | "ia"); | |
10753 | } | |
0f478e30 | 10754 | if (or->u.std.flags & ROUTER_LSA_BORDER) |
996c9314 LB |
10755 | json_object_string_add(json_route, |
10756 | "routerType", | |
10757 | "abr"); | |
10758 | else if (or->u.std.flags & ROUTER_LSA_EXTERNAL) | |
10759 | json_object_string_add(json_route, | |
10760 | "routerType", | |
10761 | "asbr"); | |
0f478e30 | 10762 | } else { |
96b663a3 | 10763 | vty_out(vty, "%s [%d] area: %pI4", |
996c9314 LB |
10764 | (or->path_type == OSPF_PATH_INTER_AREA |
10765 | ? "IA" | |
10766 | : " "), | |
96b663a3 | 10767 | or->cost, &or->u.std.area_id); |
d62a17ae | 10768 | /* Show flags. */ |
10769 | vty_out(vty, "%s%s\n", | |
996c9314 LB |
10770 | (or->u.std.flags & ROUTER_LSA_BORDER |
10771 | ? ", ABR" | |
10772 | : ""), | |
10773 | (or->u.std.flags & ROUTER_LSA_EXTERNAL | |
10774 | ? ", ASBR" | |
10775 | : "")); | |
0f478e30 CS |
10776 | } |
10777 | ||
10778 | if (json) { | |
996c9314 | 10779 | json_nexthop_array = json_object_new_array(); |
0f478e30 | 10780 | json_object_object_add(json_route, "nexthops", |
996c9314 | 10781 | json_nexthop_array); |
0f478e30 CS |
10782 | } |
10783 | ||
996c9314 | 10784 | for (ALL_LIST_ELEMENTS_RO(or->paths, pnode, path)) { |
0f478e30 | 10785 | if (json) { |
996c9314 | 10786 | json_nexthop = json_object_new_object(); |
0f478e30 CS |
10787 | json_object_array_add( |
10788 | json_nexthop_array, | |
10789 | json_nexthop); | |
10790 | } | |
10791 | if (if_lookup_by_index(path->ifindex, | |
10792 | ospf->vrf_id)) { | |
3a6290bd DA |
10793 | if (path->nexthop.s_addr |
10794 | == INADDR_ANY) { | |
0f478e30 CS |
10795 | if (json) { |
10796 | json_object_string_add( | |
10797 | json_nexthop, | |
996c9314 | 10798 | "ip", " "); |
0f478e30 CS |
10799 | json_object_string_add( |
10800 | json_nexthop, | |
10801 | "directly attached to", | |
d62a17ae | 10802 | ifindex2ifname( |
10803 | path->ifindex, | |
b5a8894d | 10804 | ospf->vrf_id)); |
08d79bce DA |
10805 | json_object_string_add( |
10806 | json_nexthop, | |
10807 | "directlyAttachedTo", | |
10808 | ifindex2ifname( | |
10809 | path->ifindex, | |
10810 | ospf->vrf_id)); | |
0f478e30 | 10811 | } else { |
d62a17ae | 10812 | vty_out(vty, |
996c9314 LB |
10813 | "%24s directly attached to %s\n", |
10814 | "", | |
10815 | ifindex2ifname( | |
10816 | path->ifindex, | |
10817 | ospf->vrf_id)); | |
0f478e30 CS |
10818 | } |
10819 | } else { | |
10820 | if (json) { | |
20308be3 | 10821 | json_object_string_addf( |
0f478e30 | 10822 | json_nexthop, |
20308be3 DA |
10823 | "ip", "%pI4", |
10824 | &path->nexthop); | |
0f478e30 CS |
10825 | json_object_string_add( |
10826 | json_nexthop, | |
10827 | "via", | |
d62a17ae | 10828 | ifindex2ifname( |
10829 | path->ifindex, | |
b5a8894d | 10830 | ospf->vrf_id)); |
0f478e30 CS |
10831 | } else { |
10832 | vty_out(vty, | |
96b663a3 | 10833 | "%24s via %pI4, %s\n", |
996c9314 | 10834 | "", |
96b663a3 | 10835 | &path->nexthop, |
996c9314 LB |
10836 | ifindex2ifname( |
10837 | path->ifindex, | |
10838 | ospf->vrf_id)); | |
0f478e30 | 10839 | } |
d62a17ae | 10840 | } |
10841 | } | |
10842 | } | |
10843 | } | |
0f478e30 CS |
10844 | } |
10845 | if (!json) | |
10846 | vty_out(vty, "\n"); | |
d62a17ae | 10847 | } |
10848 | ||
b5a8894d | 10849 | static void show_ip_ospf_route_external(struct vty *vty, struct ospf *ospf, |
0f478e30 CS |
10850 | struct route_table *rt, |
10851 | json_object *json) | |
d62a17ae | 10852 | { |
10853 | struct route_node *rn; | |
10854 | struct ospf_route *er; | |
10855 | struct listnode *pnode, *pnnode; | |
10856 | struct ospf_path *path; | |
0f478e30 CS |
10857 | json_object *json_route = NULL, *json_nexthop_array = NULL, |
10858 | *json_nexthop = NULL; | |
d62a17ae | 10859 | |
0f478e30 | 10860 | if (!json) |
996c9314 LB |
10861 | vty_out(vty, |
10862 | "============ OSPF external routing table ===========\n"); | |
0f478e30 CS |
10863 | |
10864 | for (rn = route_top(rt); rn; rn = route_next(rn)) { | |
10865 | if ((er = rn->info) == NULL) | |
10866 | continue; | |
10867 | ||
10868 | char buf1[19]; | |
10869 | ||
96b663a3 | 10870 | snprintfrr(buf1, sizeof(buf1), "%pFX", &rn->p); |
19d37e54 DS |
10871 | if (json) { |
10872 | json_route = json_object_new_object(); | |
996c9314 | 10873 | json_object_object_add(json, buf1, json_route); |
19d37e54 | 10874 | } |
d62a17ae | 10875 | |
0f478e30 CS |
10876 | switch (er->path_type) { |
10877 | case OSPF_PATH_TYPE1_EXTERNAL: | |
10878 | if (json) { | |
996c9314 | 10879 | json_object_string_add(json_route, "routeType", |
0f478e30 CS |
10880 | "N E1"); |
10881 | json_object_int_add(json_route, "cost", | |
996c9314 | 10882 | er->cost); |
67df3649 MR |
10883 | json_object_int_add(json_route, "tag", |
10884 | er->u.ext.tag); | |
0f478e30 | 10885 | } else { |
d62a17ae | 10886 | vty_out(vty, |
996c9314 LB |
10887 | "N E1 %-18s [%d] tag: %" ROUTE_TAG_PRI |
10888 | "\n", | |
10889 | buf1, er->cost, er->u.ext.tag); | |
0f478e30 CS |
10890 | } |
10891 | break; | |
10892 | case OSPF_PATH_TYPE2_EXTERNAL: | |
10893 | if (json) { | |
996c9314 | 10894 | json_object_string_add(json_route, "routeType", |
0f478e30 CS |
10895 | "N E2"); |
10896 | json_object_int_add(json_route, "cost", | |
996c9314 | 10897 | er->cost); |
67df3649 MR |
10898 | json_object_int_add(json_route, "type2cost", |
10899 | er->u.ext.type2_cost); | |
10900 | json_object_int_add(json_route, "tag", | |
10901 | er->u.ext.tag); | |
0f478e30 | 10902 | } else { |
d62a17ae | 10903 | vty_out(vty, |
996c9314 LB |
10904 | "N E2 %-18s [%d/%d] tag: %" ROUTE_TAG_PRI |
10905 | "\n", | |
10906 | buf1, er->cost, er->u.ext.type2_cost, | |
d62a17ae | 10907 | er->u.ext.tag); |
d62a17ae | 10908 | } |
0f478e30 CS |
10909 | break; |
10910 | } | |
d62a17ae | 10911 | |
0f478e30 CS |
10912 | if (json) { |
10913 | json_nexthop_array = json_object_new_array(); | |
10914 | json_object_object_add(json_route, "nexthops", | |
996c9314 | 10915 | json_nexthop_array); |
0f478e30 CS |
10916 | } |
10917 | ||
996c9314 | 10918 | for (ALL_LIST_ELEMENTS(er->paths, pnode, pnnode, path)) { |
0f478e30 CS |
10919 | if (json) { |
10920 | json_nexthop = json_object_new_object(); | |
996c9314 LB |
10921 | json_object_array_add(json_nexthop_array, |
10922 | json_nexthop); | |
0f478e30 CS |
10923 | } |
10924 | ||
996c9314 | 10925 | if (if_lookup_by_index(path->ifindex, ospf->vrf_id)) { |
3a6290bd | 10926 | if (path->nexthop.s_addr == INADDR_ANY) { |
0f478e30 CS |
10927 | if (json) { |
10928 | json_object_string_add( | |
996c9314 LB |
10929 | json_nexthop, "ip", |
10930 | " "); | |
0f478e30 CS |
10931 | json_object_string_add( |
10932 | json_nexthop, | |
10933 | "directly attached to", | |
d62a17ae | 10934 | ifindex2ifname( |
996c9314 LB |
10935 | path->ifindex, |
10936 | ospf->vrf_id)); | |
08d79bce DA |
10937 | json_object_string_add( |
10938 | json_nexthop, | |
10939 | "directlyAttachedTo", | |
10940 | ifindex2ifname( | |
10941 | path->ifindex, | |
10942 | ospf->vrf_id)); | |
0f478e30 | 10943 | } else { |
d62a17ae | 10944 | vty_out(vty, |
996c9314 LB |
10945 | "%24s directly attached to %s\n", |
10946 | "", | |
10947 | ifindex2ifname( | |
10948 | path->ifindex, | |
10949 | ospf->vrf_id)); | |
0f478e30 CS |
10950 | } |
10951 | } else { | |
10952 | if (json) { | |
20308be3 | 10953 | json_object_string_addf( |
996c9314 | 10954 | json_nexthop, "ip", |
20308be3 | 10955 | "%pI4", &path->nexthop); |
0f478e30 | 10956 | json_object_string_add( |
996c9314 | 10957 | json_nexthop, "via", |
d62a17ae | 10958 | ifindex2ifname( |
996c9314 LB |
10959 | path->ifindex, |
10960 | ospf->vrf_id)); | |
0f478e30 CS |
10961 | } else { |
10962 | vty_out(vty, | |
96b663a3 | 10963 | "%24s via %pI4, %s\n", |
996c9314 | 10964 | "", |
96b663a3 | 10965 | &path->nexthop, |
996c9314 LB |
10966 | ifindex2ifname( |
10967 | path->ifindex, | |
10968 | ospf->vrf_id)); | |
0f478e30 | 10969 | } |
d62a17ae | 10970 | } |
54bedb55 | 10971 | } |
d62a17ae | 10972 | } |
0f478e30 CS |
10973 | } |
10974 | if (!json) | |
10975 | vty_out(vty, "\n"); | |
718e3744 | 10976 | } |
10977 | ||
d86760ac CH |
10978 | static int show_ip_ospf_reachable_routers_common(struct vty *vty, |
10979 | struct ospf *ospf, | |
10980 | uint8_t use_vrf) | |
10981 | { | |
10982 | if (ospf->instance) | |
10983 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
10984 | ||
10985 | ospf_show_vrf_name(ospf, vty, NULL, use_vrf); | |
10986 | ||
10987 | if (ospf->all_rtrs == NULL) { | |
10988 | vty_out(vty, "No OSPF reachable router information exist\n"); | |
10989 | return CMD_SUCCESS; | |
10990 | } | |
10991 | ||
10992 | /* Show Router routes. */ | |
10993 | show_ip_ospf_route_router(vty, ospf, ospf->all_rtrs, NULL); | |
10994 | ||
10995 | vty_out(vty, "\n"); | |
10996 | ||
10997 | return CMD_SUCCESS; | |
10998 | } | |
10999 | ||
11000 | DEFUN (show_ip_ospf_reachable_routers, | |
11001 | show_ip_ospf_reachable_routers_cmd, | |
11002 | "show ip ospf [vrf <NAME|all>] reachable-routers", | |
11003 | SHOW_STR | |
11004 | IP_STR | |
11005 | "OSPF information\n" | |
11006 | VRF_CMD_HELP_STR | |
11007 | "All VRFs\n" | |
11008 | "Show all the reachable OSPF routers\n") | |
11009 | { | |
11010 | struct ospf *ospf = NULL; | |
11011 | struct listnode *node = NULL; | |
11012 | char *vrf_name = NULL; | |
11013 | bool all_vrf = false; | |
11014 | int ret = CMD_SUCCESS; | |
11015 | int inst = 0; | |
11016 | int idx_vrf = 0; | |
11017 | uint8_t use_vrf = 0; | |
11018 | ||
11019 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); | |
11020 | ||
11021 | if (vrf_name) { | |
11022 | bool ospf_output = false; | |
11023 | ||
11024 | use_vrf = 1; | |
11025 | ||
11026 | if (all_vrf) { | |
11027 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
11028 | if (!ospf->oi_running) | |
11029 | continue; | |
11030 | ||
11031 | ospf_output = true; | |
11032 | ret = show_ip_ospf_reachable_routers_common( | |
11033 | vty, ospf, use_vrf); | |
11034 | } | |
11035 | ||
11036 | if (!ospf_output) | |
11037 | vty_out(vty, "%% OSPF instance not found\n"); | |
11038 | } else { | |
11039 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
11040 | if (ospf == NULL || !ospf->oi_running) { | |
11041 | vty_out(vty, "%% OSPF instance not found\n"); | |
11042 | return CMD_SUCCESS; | |
11043 | } | |
11044 | ||
11045 | ret = show_ip_ospf_reachable_routers_common(vty, ospf, | |
11046 | use_vrf); | |
11047 | } | |
11048 | } else { | |
11049 | /* Display default ospf (instance 0) info */ | |
11050 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
11051 | if (ospf == NULL || !ospf->oi_running) { | |
11052 | vty_out(vty, "%% OSPF instance not found\n"); | |
11053 | return CMD_SUCCESS; | |
11054 | } | |
11055 | ||
11056 | ret = show_ip_ospf_reachable_routers_common(vty, ospf, use_vrf); | |
11057 | } | |
11058 | ||
11059 | return ret; | |
11060 | } | |
11061 | ||
11062 | DEFUN (show_ip_ospf_instance_reachable_routers, | |
11063 | show_ip_ospf_instance_reachable_routers_cmd, | |
11064 | "show ip ospf (1-65535) reachable-routers", | |
11065 | SHOW_STR | |
11066 | IP_STR | |
11067 | "OSPF information\n" | |
11068 | "Instance ID\n" | |
11069 | "Show all the reachable OSPF routers\n") | |
11070 | { | |
11071 | int idx_number = 3; | |
11072 | struct ospf *ospf; | |
11073 | unsigned short instance = 0; | |
11074 | ||
11075 | instance = strtoul(argv[idx_number]->arg, NULL, 10); | |
11076 | if (instance != ospf_instance) | |
11077 | return CMD_NOT_MY_INSTANCE; | |
11078 | ||
11079 | ospf = ospf_lookup_instance(instance); | |
11080 | if (!ospf || !ospf->oi_running) | |
11081 | return CMD_SUCCESS; | |
11082 | ||
11083 | return show_ip_ospf_reachable_routers_common(vty, ospf, 0); | |
11084 | } | |
11085 | ||
d62a17ae | 11086 | static int show_ip_ospf_border_routers_common(struct vty *vty, |
d7c0a89a QY |
11087 | struct ospf *ospf, |
11088 | uint8_t use_vrf) | |
718e3744 | 11089 | { |
d62a17ae | 11090 | if (ospf->instance) |
11091 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
718e3744 | 11092 | |
b1c3ae8c | 11093 | ospf_show_vrf_name(ospf, vty, NULL, use_vrf); |
87bd50e8 | 11094 | |
d62a17ae | 11095 | if (ospf->new_table == NULL) { |
11096 | vty_out(vty, "No OSPF routing information exist\n"); | |
11097 | return CMD_SUCCESS; | |
11098 | } | |
718e3744 | 11099 | |
d62a17ae | 11100 | /* Show Network routes. |
11101 | show_ip_ospf_route_network (vty, ospf->new_table); */ | |
718e3744 | 11102 | |
d62a17ae | 11103 | /* Show Router routes. */ |
0f478e30 | 11104 | show_ip_ospf_route_router(vty, ospf, ospf->new_rtrs, NULL); |
718e3744 | 11105 | |
d62a17ae | 11106 | vty_out(vty, "\n"); |
7c8ff89e | 11107 | |
d62a17ae | 11108 | return CMD_SUCCESS; |
718e3744 | 11109 | } |
718e3744 | 11110 | |
7c8ff89e DS |
11111 | DEFUN (show_ip_ospf_border_routers, |
11112 | show_ip_ospf_border_routers_cmd, | |
b5a8894d | 11113 | "show ip ospf [vrf <NAME|all>] border-routers", |
718e3744 | 11114 | SHOW_STR |
11115 | IP_STR | |
11116 | "OSPF information\n" | |
b5a8894d CS |
11117 | VRF_CMD_HELP_STR |
11118 | "All VRFs\n" | |
7c8ff89e | 11119 | "Show all the ABR's and ASBR's\n") |
718e3744 | 11120 | { |
b5a8894d CS |
11121 | struct ospf *ospf = NULL; |
11122 | struct listnode *node = NULL; | |
11123 | char *vrf_name = NULL; | |
2951a7a4 | 11124 | bool all_vrf = false; |
b5a8894d CS |
11125 | int ret = CMD_SUCCESS; |
11126 | int inst = 0; | |
11127 | int idx_vrf = 0; | |
d7c0a89a | 11128 | uint8_t use_vrf = 0; |
68980084 | 11129 | |
43b8d1d8 | 11130 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
7c8ff89e | 11131 | |
b5a8894d | 11132 | if (vrf_name) { |
2951a7a4 | 11133 | bool ospf_output = false; |
874f58d8 | 11134 | |
b1c3ae8c | 11135 | use_vrf = 1; |
94d4c685 | 11136 | |
b5a8894d CS |
11137 | if (all_vrf) { |
11138 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
11139 | if (!ospf->oi_running) | |
11140 | continue; | |
b5a8894d | 11141 | |
2951a7a4 | 11142 | ospf_output = true; |
996c9314 LB |
11143 | ret = show_ip_ospf_border_routers_common( |
11144 | vty, ospf, use_vrf); | |
b5a8894d | 11145 | } |
9f049418 DS |
11146 | |
11147 | if (!ospf_output) | |
fbaafa00 | 11148 | vty_out(vty, "%% OSPF is not enabled\n"); |
b5a8894d CS |
11149 | } else { |
11150 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
9f049418 | 11151 | if (ospf == NULL || !ospf->oi_running) { |
fbaafa00 JAG |
11152 | vty_out(vty, |
11153 | "%% OSPF is not enabled in vrf %s\n", | |
11154 | vrf_name); | |
b5a8894d | 11155 | return CMD_SUCCESS; |
9f049418 | 11156 | } |
b5a8894d | 11157 | |
b1c3ae8c CS |
11158 | ret = show_ip_ospf_border_routers_common(vty, ospf, |
11159 | use_vrf); | |
b5a8894d CS |
11160 | } |
11161 | } else { | |
11162 | /* Display default ospf (instance 0) info */ | |
11163 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
9f049418 | 11164 | if (ospf == NULL || !ospf->oi_running) { |
fbaafa00 | 11165 | vty_out(vty, "%% OSPF is not enabled in vrf default\n"); |
b5a8894d | 11166 | return CMD_SUCCESS; |
9f049418 DS |
11167 | } |
11168 | ||
b1c3ae8c | 11169 | ret = show_ip_ospf_border_routers_common(vty, ospf, use_vrf); |
b5a8894d CS |
11170 | } |
11171 | ||
11172 | return ret; | |
7c8ff89e DS |
11173 | } |
11174 | ||
11175 | DEFUN (show_ip_ospf_instance_border_routers, | |
11176 | show_ip_ospf_instance_border_routers_cmd, | |
6147e2c6 | 11177 | "show ip ospf (1-65535) border-routers", |
7c8ff89e DS |
11178 | SHOW_STR |
11179 | IP_STR | |
11180 | "OSPF information\n" | |
11181 | "Instance ID\n" | |
11182 | "Show all the ABR's and ASBR's\n") | |
11183 | { | |
d62a17ae | 11184 | int idx_number = 3; |
11185 | struct ospf *ospf; | |
d7c0a89a | 11186 | unsigned short instance = 0; |
7c8ff89e | 11187 | |
d62a17ae | 11188 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
409f98ab | 11189 | if (instance != ospf_instance) |
ac28e4ec CS |
11190 | return CMD_NOT_MY_INSTANCE; |
11191 | ||
409f98ab IR |
11192 | ospf = ospf_lookup_instance(instance); |
11193 | if (!ospf || !ospf->oi_running) | |
d62a17ae | 11194 | return CMD_SUCCESS; |
7c8ff89e | 11195 | |
b1c3ae8c | 11196 | return show_ip_ospf_border_routers_common(vty, ospf, 0); |
7c8ff89e DS |
11197 | } |
11198 | ||
b1c3ae8c | 11199 | static int show_ip_ospf_route_common(struct vty *vty, struct ospf *ospf, |
d7c0a89a | 11200 | json_object *json, uint8_t use_vrf) |
7c8ff89e | 11201 | { |
0f478e30 CS |
11202 | json_object *json_vrf = NULL; |
11203 | ||
d62a17ae | 11204 | if (ospf->instance) |
11205 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
718e3744 | 11206 | |
0f478e30 CS |
11207 | |
11208 | if (json) { | |
11209 | if (use_vrf) | |
11210 | json_vrf = json_object_new_object(); | |
11211 | else | |
11212 | json_vrf = json; | |
11213 | } | |
11214 | ||
11215 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); | |
87bd50e8 | 11216 | |
d62a17ae | 11217 | if (ospf->new_table == NULL) { |
11218 | vty_out(vty, "No OSPF routing information exist\n"); | |
11219 | return CMD_SUCCESS; | |
11220 | } | |
718e3744 | 11221 | |
d62a17ae | 11222 | /* Show Network routes. */ |
0f478e30 | 11223 | show_ip_ospf_route_network(vty, ospf, ospf->new_table, json_vrf); |
718e3744 | 11224 | |
d62a17ae | 11225 | /* Show Router routes. */ |
0f478e30 | 11226 | show_ip_ospf_route_router(vty, ospf, ospf->new_rtrs, json_vrf); |
718e3744 | 11227 | |
d86760ac CH |
11228 | /* Show Router routes. */ |
11229 | if (ospf->all_rtrs) | |
11230 | show_ip_ospf_route_router(vty, ospf, ospf->all_rtrs, json_vrf); | |
11231 | ||
d62a17ae | 11232 | /* Show AS External routes. */ |
0f478e30 CS |
11233 | show_ip_ospf_route_external(vty, ospf, ospf->old_external_route, |
11234 | json_vrf); | |
718e3744 | 11235 | |
0f478e30 CS |
11236 | if (json) { |
11237 | if (use_vrf) { | |
996c9314 LB |
11238 | // json_object_object_add(json_vrf, "areas", |
11239 | // json_areas); | |
44076f4d RW |
11240 | json_object_object_add(json, ospf_get_name(ospf), |
11241 | json_vrf); | |
0f478e30 CS |
11242 | } |
11243 | } else { | |
11244 | vty_out(vty, "\n"); | |
11245 | } | |
7c8ff89e | 11246 | |
d62a17ae | 11247 | return CMD_SUCCESS; |
718e3744 | 11248 | } |
11249 | ||
7c8ff89e DS |
11250 | DEFUN (show_ip_ospf_route, |
11251 | show_ip_ospf_route_cmd, | |
0f478e30 | 11252 | "show ip ospf [vrf <NAME|all>] route [json]", |
b5a8894d CS |
11253 | SHOW_STR |
11254 | IP_STR | |
11255 | "OSPF information\n" | |
11256 | VRF_CMD_HELP_STR | |
11257 | "All VRFs\n" | |
0f478e30 CS |
11258 | "OSPF routing table\n" |
11259 | JSON_STR) | |
b5a8894d CS |
11260 | { |
11261 | struct ospf *ospf = NULL; | |
11262 | struct listnode *node = NULL; | |
11263 | char *vrf_name = NULL; | |
2951a7a4 | 11264 | bool all_vrf = false; |
b5a8894d CS |
11265 | int ret = CMD_SUCCESS; |
11266 | int inst = 0; | |
11267 | int idx_vrf = 0; | |
d7c0a89a | 11268 | uint8_t use_vrf = 0; |
9f049418 | 11269 | bool uj = use_json(argc, argv); |
0f478e30 CS |
11270 | json_object *json = NULL; |
11271 | ||
11272 | if (uj) | |
11273 | json = json_object_new_object(); | |
7c8ff89e | 11274 | |
43b8d1d8 | 11275 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
7c8ff89e | 11276 | |
b5a8894d CS |
11277 | /* vrf input is provided could be all or specific vrf*/ |
11278 | if (vrf_name) { | |
2951a7a4 | 11279 | bool ospf_output = false; |
874f58d8 | 11280 | |
b1c3ae8c | 11281 | use_vrf = 1; |
94d4c685 | 11282 | |
b5a8894d CS |
11283 | if (all_vrf) { |
11284 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
11285 | if (!ospf->oi_running) | |
11286 | continue; | |
2951a7a4 | 11287 | ospf_output = true; |
0f478e30 | 11288 | ret = show_ip_ospf_route_common(vty, ospf, json, |
b1c3ae8c | 11289 | use_vrf); |
b5a8894d | 11290 | } |
0f478e30 CS |
11291 | |
11292 | if (uj) { | |
1406159f | 11293 | /* Keep Non-pretty format */ |
92ef0078 | 11294 | vty_json(vty, json); |
9f049418 | 11295 | } else if (!ospf_output) |
fbaafa00 | 11296 | vty_out(vty, "%% OSPF is not enabled\n"); |
0f478e30 | 11297 | |
b5a8894d CS |
11298 | return ret; |
11299 | } | |
11300 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
0f478e30 | 11301 | if (ospf == NULL || !ospf->oi_running) { |
c48349e3 | 11302 | if (uj) |
92ef0078 | 11303 | vty_json(vty, json); |
c48349e3 | 11304 | else |
fbaafa00 JAG |
11305 | vty_out(vty, |
11306 | "%% OSPF is not enabled in vrf %s\n", | |
11307 | vrf_name); | |
9f049418 | 11308 | |
b5a8894d | 11309 | return CMD_SUCCESS; |
0f478e30 | 11310 | } |
b5a8894d CS |
11311 | } else { |
11312 | /* Display default ospf (instance 0) info */ | |
11313 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
0f478e30 | 11314 | if (ospf == NULL || !ospf->oi_running) { |
c48349e3 | 11315 | if (uj) |
92ef0078 | 11316 | vty_json(vty, json); |
c48349e3 | 11317 | else |
fbaafa00 JAG |
11318 | vty_out(vty, |
11319 | "%% OSPF is not enabled in vrf default\n"); | |
9f049418 | 11320 | |
b5a8894d | 11321 | return CMD_SUCCESS; |
0f478e30 CS |
11322 | } |
11323 | } | |
11324 | ||
11325 | if (ospf) { | |
11326 | ret = show_ip_ospf_route_common(vty, ospf, json, use_vrf); | |
1406159f | 11327 | /* Keep Non-pretty format */ |
0f478e30 | 11328 | if (uj) |
e77564cc DS |
11329 | vty_out(vty, "%s\n", |
11330 | json_object_to_json_string_ext( | |
11331 | json, JSON_C_TO_STRING_NOSLASHESCAPE)); | |
b5a8894d CS |
11332 | } |
11333 | ||
0f478e30 CS |
11334 | if (uj) |
11335 | json_object_free(json); | |
b5a8894d CS |
11336 | |
11337 | return ret; | |
7c8ff89e DS |
11338 | } |
11339 | ||
11340 | DEFUN (show_ip_ospf_instance_route, | |
11341 | show_ip_ospf_instance_route_cmd, | |
6147e2c6 | 11342 | "show ip ospf (1-65535) route", |
7c8ff89e DS |
11343 | SHOW_STR |
11344 | IP_STR | |
11345 | "OSPF information\n" | |
11346 | "Instance ID\n" | |
11347 | "OSPF routing table\n") | |
11348 | { | |
d62a17ae | 11349 | int idx_number = 3; |
11350 | struct ospf *ospf; | |
d7c0a89a | 11351 | unsigned short instance = 0; |
7c8ff89e | 11352 | |
d62a17ae | 11353 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
409f98ab | 11354 | if (instance != ospf_instance) |
ac28e4ec CS |
11355 | return CMD_NOT_MY_INSTANCE; |
11356 | ||
409f98ab IR |
11357 | ospf = ospf_lookup_instance(instance); |
11358 | if (!ospf || !ospf->oi_running) | |
d62a17ae | 11359 | return CMD_SUCCESS; |
7c8ff89e | 11360 | |
0f478e30 | 11361 | return show_ip_ospf_route_common(vty, ospf, NULL, 0); |
7c8ff89e | 11362 | } |
6b0655a2 | 11363 | |
b5a8894d CS |
11364 | |
11365 | DEFUN (show_ip_ospf_vrfs, | |
11366 | show_ip_ospf_vrfs_cmd, | |
11367 | "show ip ospf vrfs [json]", | |
11368 | SHOW_STR | |
11369 | IP_STR | |
11370 | "OSPF information\n" | |
11371 | "Show OSPF VRFs \n" | |
11372 | JSON_STR) | |
11373 | { | |
9f049418 | 11374 | bool uj = use_json(argc, argv); |
b5a8894d CS |
11375 | json_object *json = NULL; |
11376 | json_object *json_vrfs = NULL; | |
11377 | struct ospf *ospf = NULL; | |
11378 | struct listnode *node = NULL; | |
11379 | int count = 0; | |
2b64873d | 11380 | static const char header[] = "Name Id RouterId "; |
b5a8894d CS |
11381 | |
11382 | if (uj) { | |
11383 | json = json_object_new_object(); | |
11384 | json_vrfs = json_object_new_object(); | |
11385 | } | |
11386 | ||
11387 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
11388 | json_object *json_vrf = NULL; | |
11389 | const char *name = NULL; | |
fe3da9e7 | 11390 | int64_t vrf_id_ui = 0; |
b5a8894d CS |
11391 | |
11392 | count++; | |
11393 | ||
11394 | if (!uj && count == 1) | |
11395 | vty_out(vty, "%s\n", header); | |
11396 | if (uj) | |
11397 | json_vrf = json_object_new_object(); | |
11398 | ||
44076f4d | 11399 | name = ospf_get_name(ospf); |
b5a8894d | 11400 | |
996c9314 LB |
11401 | vrf_id_ui = (ospf->vrf_id == VRF_UNKNOWN) |
11402 | ? -1 | |
11403 | : (int64_t)ospf->vrf_id; | |
b5a8894d CS |
11404 | |
11405 | if (uj) { | |
11406 | json_object_int_add(json_vrf, "vrfId", vrf_id_ui); | |
20308be3 DA |
11407 | json_object_string_addf(json_vrf, "routerId", "%pI4", |
11408 | &ospf->router_id); | |
b5a8894d CS |
11409 | |
11410 | json_object_object_add(json_vrfs, name, json_vrf); | |
11411 | ||
11412 | } else { | |
96b663a3 MS |
11413 | vty_out(vty, "%-25s %-5d %-16pI4 \n", name, |
11414 | ospf->vrf_id, &ospf->router_id); | |
b5a8894d CS |
11415 | } |
11416 | } | |
11417 | ||
11418 | if (uj) { | |
11419 | json_object_object_add(json, "vrfs", json_vrfs); | |
11420 | json_object_int_add(json, "totalVrfs", count); | |
11421 | ||
92ef0078 | 11422 | vty_json(vty, json); |
b5a8894d CS |
11423 | } else { |
11424 | if (count) | |
34d6798f | 11425 | vty_out(vty, "\nTotal number of OSPF VRFs: %d\n", |
b5a8894d CS |
11426 | count); |
11427 | } | |
11428 | ||
11429 | return CMD_SUCCESS; | |
11430 | } | |
f91ce319 MR |
11431 | DEFPY (clear_ip_ospf_neighbor, |
11432 | clear_ip_ospf_neighbor_cmd, | |
11433 | "clear ip ospf [(1-65535)]$instance neighbor [A.B.C.D$nbr_id]", | |
11434 | CLEAR_STR | |
11435 | IP_STR | |
11436 | "OSPF information\n" | |
11437 | "Instance ID\n" | |
11438 | "Reset OSPF Neighbor\n" | |
11439 | "Neighbor ID\n") | |
11440 | { | |
11441 | struct listnode *node; | |
11442 | struct ospf *ospf = NULL; | |
11443 | ||
11444 | /* If user does not specify the arguments, | |
11445 | * instance = 0 and nbr_id = 0.0.0.0 | |
11446 | */ | |
11447 | if (instance != 0) { | |
11448 | /* This means clear only the particular ospf process */ | |
409f98ab | 11449 | if (instance != ospf_instance) |
f91ce319 MR |
11450 | return CMD_NOT_MY_INSTANCE; |
11451 | } | |
11452 | ||
11453 | /* Clear all the ospf processes */ | |
11454 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
11455 | if (!ospf->oi_running) | |
11456 | continue; | |
11457 | ||
c88ad8ec | 11458 | if (nbr_id_str && IPV4_ADDR_SAME(&ospf->router_id, &nbr_id)) { |
11459 | vty_out(vty, "Self router-id is not allowed.\r\n "); | |
11460 | return CMD_SUCCESS; | |
11461 | } | |
11462 | ||
f91ce319 MR |
11463 | ospf_neighbor_reset(ospf, nbr_id, nbr_id_str); |
11464 | } | |
11465 | ||
11466 | return CMD_SUCCESS; | |
11467 | } | |
11468 | ||
11469 | DEFPY (clear_ip_ospf_process, | |
11470 | clear_ip_ospf_process_cmd, | |
11471 | "clear ip ospf [(1-65535)]$instance process", | |
11472 | CLEAR_STR | |
11473 | IP_STR | |
11474 | "OSPF information\n" | |
11475 | "Instance ID\n" | |
11476 | "Reset OSPF Process\n") | |
11477 | { | |
11478 | struct listnode *node; | |
11479 | struct ospf *ospf = NULL; | |
11480 | ||
11481 | /* Check if instance is not passed as an argument */ | |
11482 | if (instance != 0) { | |
11483 | /* This means clear only the particular ospf process */ | |
409f98ab | 11484 | if (instance != ospf_instance) |
f91ce319 MR |
11485 | return CMD_NOT_MY_INSTANCE; |
11486 | } | |
11487 | ||
11488 | /* Clear all the ospf processes */ | |
11489 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
11490 | if (!ospf->oi_running) | |
11491 | continue; | |
11492 | ||
11493 | ospf_process_reset(ospf); | |
11494 | } | |
11495 | ||
11496 | return CMD_SUCCESS; | |
11497 | } | |
b5a8894d | 11498 | |
2b64873d DL |
11499 | static const char *const ospf_abr_type_str[] = { |
11500 | "unknown", "standard", "ibm", "cisco", "shortcut" | |
11501 | }; | |
718e3744 | 11502 | |
2b64873d DL |
11503 | static const char *const ospf_shortcut_mode_str[] = { |
11504 | "default", "enable", "disable" | |
11505 | }; | |
1ac88792 | 11506 | static int ospf_vty_external_rt_walkcb(struct hash_bucket *bucket, |
53e44d05 | 11507 | void *arg) |
11508 | { | |
1ac88792 | 11509 | struct external_info *ei = bucket->data; |
53e44d05 | 11510 | struct vty *vty = (struct vty *)arg; |
11511 | static unsigned int count; | |
11512 | ||
11513 | vty_out(vty, "%-4pI4/%d, ", &ei->p.prefix, ei->p.prefixlen); | |
11514 | count++; | |
11515 | ||
11516 | if (count % 5 == 0) | |
11517 | vty_out(vty, "\n"); | |
11518 | ||
11519 | if (OSPF_EXTERNAL_RT_COUNT(ei->aggr_route) == count) | |
11520 | count = 0; | |
11521 | ||
11522 | return HASHWALK_CONTINUE; | |
11523 | } | |
11524 | ||
1ac88792 | 11525 | static int ospf_json_external_rt_walkcb(struct hash_bucket *bucket, |
53e44d05 | 11526 | void *arg) |
11527 | { | |
1ac88792 | 11528 | struct external_info *ei = bucket->data; |
53e44d05 | 11529 | struct json_object *json = (struct json_object *)arg; |
11530 | char buf[PREFIX2STR_BUFFER]; | |
11531 | char exnalbuf[20]; | |
11532 | static unsigned int count; | |
11533 | ||
11534 | prefix2str(&ei->p, buf, sizeof(buf)); | |
11535 | ||
11536 | snprintf(exnalbuf, 20, "Exnl Addr-%d", count); | |
11537 | ||
11538 | json_object_string_add(json, exnalbuf, buf); | |
11539 | ||
11540 | count++; | |
11541 | ||
11542 | if (OSPF_EXTERNAL_RT_COUNT(ei->aggr_route) == count) | |
11543 | count = 0; | |
11544 | ||
11545 | return HASHWALK_CONTINUE; | |
11546 | } | |
11547 | ||
11548 | static int ospf_show_summary_address(struct vty *vty, struct ospf *ospf, | |
11549 | uint8_t use_vrf, json_object *json, | |
11550 | bool uj, bool detail) | |
11551 | { | |
11552 | struct route_node *rn; | |
11553 | json_object *json_vrf = NULL; | |
11554 | int mtype = 0; | |
11555 | int mval = 0; | |
11556 | static char header[] = | |
11557 | "Summary-address Metric-type Metric Tag External_Rt_count\n"; | |
11558 | ||
11559 | mtype = metric_type(ospf, 0, ospf->instance); | |
11560 | mval = metric_value(ospf, 0, ospf->instance); | |
11561 | ||
11562 | if (!uj) | |
11563 | vty_out(vty, "%s\n", header); | |
11564 | ||
11565 | if (uj) { | |
11566 | if (use_vrf) | |
11567 | json_vrf = json_object_new_object(); | |
11568 | else | |
11569 | json_vrf = json; | |
11570 | } | |
11571 | ||
11572 | if (ospf->instance) { | |
11573 | if (uj) | |
11574 | json_object_int_add(json, "ospfInstance", | |
11575 | ospf->instance); | |
11576 | else | |
11577 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
11578 | } | |
11579 | ||
11580 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); | |
11581 | ||
08d79bce | 11582 | if (!uj) { |
4b939ad2 | 11583 | vty_out(vty, "aggregation delay interval :%u(in seconds)\n\n", |
53e44d05 | 11584 | ospf->aggr_delay_interval); |
08d79bce | 11585 | } else { |
53e44d05 | 11586 | json_object_int_add(json_vrf, "aggregation delay interval", |
11587 | ospf->aggr_delay_interval); | |
08d79bce DA |
11588 | json_object_int_add(json_vrf, "aggregationDelayInterval", |
11589 | ospf->aggr_delay_interval); | |
11590 | } | |
53e44d05 | 11591 | |
11592 | for (rn = route_top(ospf->rt_aggr_tbl); rn; rn = route_next(rn)) | |
11593 | if (rn->info) { | |
11594 | struct ospf_external_aggr_rt *aggr = rn->info; | |
11595 | json_object *json_aggr = NULL; | |
11596 | char buf[PREFIX2STR_BUFFER]; | |
11597 | ||
11598 | prefix2str(&aggr->p, buf, sizeof(buf)); | |
11599 | ||
11600 | if (uj) { | |
11601 | ||
11602 | json_aggr = json_object_new_object(); | |
11603 | ||
11604 | json_object_object_add(json_vrf, buf, | |
11605 | json_aggr); | |
11606 | ||
11607 | json_object_string_add(json_aggr, | |
11608 | "Summary address", buf); | |
08d79bce DA |
11609 | json_object_string_add(json_aggr, |
11610 | "summaryAddress", buf); | |
53e44d05 | 11611 | |
11612 | json_object_string_add( | |
11613 | json_aggr, "Metric-type", | |
11614 | (mtype == EXTERNAL_METRIC_TYPE_1) | |
11615 | ? "E1" | |
11616 | : "E2"); | |
08d79bce DA |
11617 | json_object_string_add( |
11618 | json_aggr, "metricType", | |
11619 | (mtype == EXTERNAL_METRIC_TYPE_1) | |
11620 | ? "E1" | |
11621 | : "E2"); | |
53e44d05 | 11622 | |
77a2f8e5 DA |
11623 | #if CONFDATE > 20230131 |
11624 | CPP_NOTICE("Remove JSON object commands with keys starting with capital") | |
11625 | #endif | |
53e44d05 | 11626 | json_object_int_add(json_aggr, "Metric", mval); |
77a2f8e5 | 11627 | json_object_int_add(json_aggr, "metric", mval); |
53e44d05 | 11628 | |
11629 | json_object_int_add(json_aggr, "Tag", | |
11630 | aggr->tag); | |
77a2f8e5 DA |
11631 | json_object_int_add(json_aggr, "tag", |
11632 | aggr->tag); | |
53e44d05 | 11633 | |
11634 | json_object_int_add( | |
11635 | json_aggr, "External route count", | |
11636 | OSPF_EXTERNAL_RT_COUNT(aggr)); | |
08d79bce DA |
11637 | json_object_int_add( |
11638 | json_aggr, "externalRouteCount", | |
11639 | OSPF_EXTERNAL_RT_COUNT(aggr)); | |
53e44d05 | 11640 | |
11641 | if (OSPF_EXTERNAL_RT_COUNT(aggr) && detail) { | |
11642 | hash_walk( | |
11643 | aggr->match_extnl_hash, | |
11644 | ospf_json_external_rt_walkcb, | |
11645 | json_aggr); | |
11646 | } | |
11647 | ||
11648 | } else { | |
11649 | vty_out(vty, "%-20s", buf); | |
11650 | ||
11651 | (mtype == EXTERNAL_METRIC_TYPE_1) | |
11652 | ? vty_out(vty, "%-16s", "E1") | |
11653 | : vty_out(vty, "%-16s", "E2"); | |
11654 | vty_out(vty, "%-11d", mval); | |
11655 | ||
11656 | vty_out(vty, "%-12u", aggr->tag); | |
11657 | ||
11658 | vty_out(vty, "%-5ld\n", | |
11659 | OSPF_EXTERNAL_RT_COUNT(aggr)); | |
11660 | ||
11661 | if (OSPF_EXTERNAL_RT_COUNT(aggr) && detail) { | |
11662 | vty_out(vty, | |
11663 | "Matched External routes:\n"); | |
11664 | hash_walk( | |
11665 | aggr->match_extnl_hash, | |
11666 | ospf_vty_external_rt_walkcb, | |
11667 | vty); | |
11668 | vty_out(vty, "\n"); | |
11669 | } | |
11670 | ||
11671 | vty_out(vty, "\n"); | |
11672 | } | |
11673 | } | |
11674 | ||
11675 | if (uj) { | |
44076f4d RW |
11676 | if (use_vrf) |
11677 | json_object_object_add(json, ospf_get_name(ospf), | |
11678 | json_vrf); | |
53e44d05 | 11679 | } else |
11680 | vty_out(vty, "\n"); | |
11681 | ||
11682 | return CMD_SUCCESS; | |
11683 | } | |
11684 | ||
11685 | DEFUN (show_ip_ospf_external_aggregator, | |
11686 | show_ip_ospf_external_aggregator_cmd, | |
11687 | "show ip ospf [vrf <NAME|all>] summary-address [detail] [json]", | |
11688 | SHOW_STR IP_STR | |
11689 | "OSPF information\n" | |
11690 | VRF_CMD_HELP_STR | |
11691 | "All VRFs\n" | |
11692 | "Show external summary addresses\n" | |
1461559c | 11693 | "Detailed information\n" |
53e44d05 | 11694 | JSON_STR) |
11695 | { | |
11696 | char *vrf_name = NULL; | |
11697 | bool all_vrf = false; | |
11698 | int ret = CMD_SUCCESS; | |
11699 | int idx_vrf = 0; | |
11700 | int idx = 0; | |
11701 | uint8_t use_vrf = 0; | |
11702 | bool uj = use_json(argc, argv); | |
11703 | struct ospf *ospf = NULL; | |
11704 | json_object *json = NULL; | |
11705 | struct listnode *node = NULL; | |
11706 | int inst = 0; | |
11707 | bool detail = false; | |
11708 | ||
11709 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); | |
11710 | ||
11711 | if (argv_find(argv, argc, "detail", &idx)) | |
11712 | detail = true; | |
11713 | ||
11714 | if (uj) | |
11715 | json = json_object_new_object(); | |
11716 | ||
11717 | /* vrf input is provided */ | |
11718 | if (vrf_name) { | |
11719 | use_vrf = 1; | |
11720 | if (all_vrf) { | |
11721 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
11722 | if (!ospf->oi_running) | |
11723 | continue; | |
11724 | ret = ospf_show_summary_address( | |
11725 | vty, ospf, use_vrf, json, uj, detail); | |
11726 | } | |
11727 | ||
c48349e3 | 11728 | if (uj) |
92ef0078 | 11729 | vty_json(vty, json); |
53e44d05 | 11730 | |
11731 | return ret; | |
11732 | } | |
11733 | ||
11734 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
11735 | ||
11736 | if (ospf == NULL || !ospf->oi_running) { | |
c48349e3 | 11737 | if (uj) |
92ef0078 | 11738 | vty_json(vty, json); |
c48349e3 | 11739 | else |
fbaafa00 JAG |
11740 | vty_out(vty, |
11741 | "%% OSPF is not enabled in vrf %s\n", | |
11742 | vrf_name); | |
53e44d05 | 11743 | |
11744 | return CMD_SUCCESS; | |
11745 | } | |
fddbafcc | 11746 | ospf_show_summary_address(vty, ospf, use_vrf, json, uj, detail); |
53e44d05 | 11747 | |
11748 | } else { | |
11749 | /* Default Vrf */ | |
11750 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
11751 | if (ospf == NULL || !ospf->oi_running) { | |
c48349e3 | 11752 | if (uj) |
92ef0078 | 11753 | vty_json(vty, json); |
c48349e3 | 11754 | else |
fbaafa00 JAG |
11755 | vty_out(vty, |
11756 | "%% OSPF is not enabled in vrf default\n"); | |
53e44d05 | 11757 | |
11758 | return CMD_SUCCESS; | |
11759 | } | |
11760 | ||
11761 | ospf_show_summary_address(vty, ospf, use_vrf, json, uj, detail); | |
11762 | } | |
11763 | ||
c48349e3 | 11764 | if (uj) |
92ef0078 | 11765 | vty_json(vty, json); |
53e44d05 | 11766 | return CMD_SUCCESS; |
11767 | } | |
718e3744 | 11768 | |
2b64873d DL |
11769 | static const char *const ospf_int_type_str[] = { |
11770 | "unknown", /* should never be used. */ | |
11771 | "point-to-point", | |
11772 | "broadcast", | |
11773 | "non-broadcast", | |
11774 | "point-to-multipoint", | |
11775 | "virtual-link", /* should never be used. */ | |
11776 | "loopback" | |
11777 | }; | |
718e3744 | 11778 | |
83cc5a1f DE |
11779 | static const char *interface_config_auth_str(struct ospf_if_params *params) |
11780 | { | |
11781 | if (!OSPF_IF_PARAM_CONFIGURED(params, auth_type) | |
11782 | || params->auth_type == OSPF_AUTH_NOTSET) | |
11783 | return NULL; | |
11784 | ||
11785 | /* Translation tables are not that much help | |
11786 | * here due to syntax | |
11787 | * of the simple option */ | |
11788 | switch (params->auth_type) { | |
11789 | ||
11790 | case OSPF_AUTH_NULL: | |
11791 | return " null"; | |
11792 | ||
11793 | case OSPF_AUTH_SIMPLE: | |
11794 | return ""; | |
11795 | ||
11796 | case OSPF_AUTH_CRYPTOGRAPHIC: | |
11797 | return " message-digest"; | |
11798 | } | |
11799 | ||
11800 | return ""; | |
11801 | } | |
11802 | ||
545f0503 | 11803 | static int config_write_interface_one(struct vty *vty, struct vrf *vrf) |
d62a17ae | 11804 | { |
f4e14fdb | 11805 | struct listnode *node; |
d62a17ae | 11806 | struct interface *ifp; |
11807 | struct crypt_key *ck; | |
d62a17ae | 11808 | struct route_node *rn = NULL; |
11809 | struct ospf_if_params *params; | |
83cc5a1f | 11810 | const char *auth_str; |
43b8d1d8 | 11811 | int write = 0; |
d62a17ae | 11812 | |
545f0503 | 11813 | FOR_ALL_INTERFACES (vrf, ifp) { |
d62a17ae | 11814 | |
545f0503 CS |
11815 | if (memcmp(ifp->name, "VLINK", 5) == 0) |
11816 | continue; | |
35955c14 | 11817 | |
788a036f IR |
11818 | if_vty_config_start(vty, ifp); |
11819 | ||
545f0503 CS |
11820 | if (ifp->desc) |
11821 | vty_out(vty, " description %s\n", ifp->desc); | |
d62a17ae | 11822 | |
545f0503 | 11823 | write++; |
43b8d1d8 | 11824 | |
545f0503 | 11825 | params = IF_DEF_PARAMS(ifp); |
43b8d1d8 | 11826 | |
545f0503 CS |
11827 | do { |
11828 | /* Interface Network print. */ | |
11829 | if (OSPF_IF_PARAM_CONFIGURED(params, type) | |
11830 | && params->type != OSPF_IFTYPE_LOOPBACK) { | |
996c9314 | 11831 | if (params->type != ospf_default_iftype(ifp)) { |
545f0503 CS |
11832 | vty_out(vty, " ip ospf network %s", |
11833 | ospf_int_type_str | |
996c9314 | 11834 | [params->type]); |
bc97889b AL |
11835 | if (params->type |
11836 | == OSPF_IFTYPE_POINTOPOINT | |
11837 | && params->ptp_dmvpn) | |
11838 | vty_out(vty, " dmvpn"); | |
e425c019 | 11839 | if (params != IF_DEF_PARAMS(ifp) && rn) |
96b663a3 MS |
11840 | vty_out(vty, " %pI4", |
11841 | &rn->p.u.prefix4); | |
545f0503 | 11842 | vty_out(vty, "\n"); |
d62a17ae | 11843 | } |
545f0503 | 11844 | } |
d62a17ae | 11845 | |
545f0503 | 11846 | /* OSPF interface authentication print */ |
83cc5a1f DE |
11847 | auth_str = interface_config_auth_str(params); |
11848 | if (auth_str) { | |
545f0503 CS |
11849 | vty_out(vty, " ip ospf authentication%s", |
11850 | auth_str); | |
e425c019 | 11851 | if (params != IF_DEF_PARAMS(ifp) && rn) |
96b663a3 MS |
11852 | vty_out(vty, " %pI4", |
11853 | &rn->p.u.prefix4); | |
545f0503 CS |
11854 | vty_out(vty, "\n"); |
11855 | } | |
d62a17ae | 11856 | |
545f0503 CS |
11857 | /* Simple Authentication Password print. */ |
11858 | if (OSPF_IF_PARAM_CONFIGURED(params, auth_simple) | |
996c9314 | 11859 | && params->auth_simple[0] != '\0') { |
545f0503 CS |
11860 | vty_out(vty, " ip ospf authentication-key %s", |
11861 | params->auth_simple); | |
e425c019 | 11862 | if (params != IF_DEF_PARAMS(ifp) && rn) |
96b663a3 MS |
11863 | vty_out(vty, " %pI4", |
11864 | &rn->p.u.prefix4); | |
545f0503 CS |
11865 | vty_out(vty, "\n"); |
11866 | } | |
c7fd72d2 | 11867 | |
545f0503 CS |
11868 | /* Cryptographic Authentication Key print. */ |
11869 | if (params && params->auth_crypt) { | |
996c9314 LB |
11870 | for (ALL_LIST_ELEMENTS_RO(params->auth_crypt, |
11871 | node, ck)) { | |
545f0503 CS |
11872 | vty_out(vty, |
11873 | " ip ospf message-digest-key %d md5 %s", | |
996c9314 | 11874 | ck->key_id, ck->auth_key); |
e425c019 | 11875 | if (params != IF_DEF_PARAMS(ifp) && rn) |
96b663a3 MS |
11876 | vty_out(vty, " %pI4", |
11877 | &rn->p.u.prefix4); | |
c7fd72d2 CS |
11878 | vty_out(vty, "\n"); |
11879 | } | |
545f0503 | 11880 | } |
d62a17ae | 11881 | |
545f0503 | 11882 | /* Interface Output Cost print. */ |
996c9314 | 11883 | if (OSPF_IF_PARAM_CONFIGURED(params, output_cost_cmd)) { |
545f0503 CS |
11884 | vty_out(vty, " ip ospf cost %u", |
11885 | params->output_cost_cmd); | |
e425c019 | 11886 | if (params != IF_DEF_PARAMS(ifp) && rn) |
96b663a3 MS |
11887 | vty_out(vty, " %pI4", |
11888 | &rn->p.u.prefix4); | |
545f0503 CS |
11889 | vty_out(vty, "\n"); |
11890 | } | |
d62a17ae | 11891 | |
545f0503 CS |
11892 | /* Hello Interval print. */ |
11893 | if (OSPF_IF_PARAM_CONFIGURED(params, v_hello) | |
996c9314 | 11894 | && params->v_hello != OSPF_HELLO_INTERVAL_DEFAULT) { |
545f0503 CS |
11895 | vty_out(vty, " ip ospf hello-interval %u", |
11896 | params->v_hello); | |
e425c019 | 11897 | if (params != IF_DEF_PARAMS(ifp) && rn) |
96b663a3 MS |
11898 | vty_out(vty, " %pI4", |
11899 | &rn->p.u.prefix4); | |
545f0503 CS |
11900 | vty_out(vty, "\n"); |
11901 | } | |
d62a17ae | 11902 | |
d62a17ae | 11903 | |
545f0503 CS |
11904 | /* Router Dead Interval print. */ |
11905 | if (OSPF_IF_PARAM_CONFIGURED(params, v_wait) | |
2c1f2d2a | 11906 | && params->is_v_wait_set) { |
545f0503 | 11907 | vty_out(vty, " ip ospf dead-interval "); |
d62a17ae | 11908 | |
545f0503 CS |
11909 | /* fast hello ? */ |
11910 | if (OSPF_IF_PARAM_CONFIGURED(params, | |
996c9314 | 11911 | fast_hello)) |
545f0503 CS |
11912 | vty_out(vty, |
11913 | "minimal hello-multiplier %d", | |
11914 | params->fast_hello); | |
11915 | else | |
996c9314 | 11916 | vty_out(vty, "%u", params->v_wait); |
d62a17ae | 11917 | |
e425c019 | 11918 | if (params != IF_DEF_PARAMS(ifp) && rn) |
96b663a3 MS |
11919 | vty_out(vty, " %pI4", |
11920 | &rn->p.u.prefix4); | |
545f0503 CS |
11921 | vty_out(vty, "\n"); |
11922 | } | |
d62a17ae | 11923 | |
545f0503 CS |
11924 | /* Router Priority print. */ |
11925 | if (OSPF_IF_PARAM_CONFIGURED(params, priority) | |
996c9314 LB |
11926 | && params->priority |
11927 | != OSPF_ROUTER_PRIORITY_DEFAULT) { | |
545f0503 CS |
11928 | vty_out(vty, " ip ospf priority %u", |
11929 | params->priority); | |
e425c019 | 11930 | if (params != IF_DEF_PARAMS(ifp) && rn) |
96b663a3 MS |
11931 | vty_out(vty, " %pI4", |
11932 | &rn->p.u.prefix4); | |
545f0503 CS |
11933 | vty_out(vty, "\n"); |
11934 | } | |
d62a17ae | 11935 | |
545f0503 CS |
11936 | /* Retransmit Interval print. */ |
11937 | if (OSPF_IF_PARAM_CONFIGURED(params, | |
996c9314 LB |
11938 | retransmit_interval) |
11939 | && params->retransmit_interval | |
11940 | != OSPF_RETRANSMIT_INTERVAL_DEFAULT) { | |
545f0503 CS |
11941 | vty_out(vty, " ip ospf retransmit-interval %u", |
11942 | params->retransmit_interval); | |
e425c019 | 11943 | if (params != IF_DEF_PARAMS(ifp) && rn) |
96b663a3 MS |
11944 | vty_out(vty, " %pI4", |
11945 | &rn->p.u.prefix4); | |
545f0503 CS |
11946 | vty_out(vty, "\n"); |
11947 | } | |
d62a17ae | 11948 | |
545f0503 | 11949 | /* Transmit Delay print. */ |
996c9314 LB |
11950 | if (OSPF_IF_PARAM_CONFIGURED(params, transmit_delay) |
11951 | && params->transmit_delay | |
11952 | != OSPF_TRANSMIT_DELAY_DEFAULT) { | |
545f0503 CS |
11953 | vty_out(vty, " ip ospf transmit-delay %u", |
11954 | params->transmit_delay); | |
e425c019 | 11955 | if (params != IF_DEF_PARAMS(ifp) && rn) |
96b663a3 MS |
11956 | vty_out(vty, " %pI4", |
11957 | &rn->p.u.prefix4); | |
545f0503 CS |
11958 | vty_out(vty, "\n"); |
11959 | } | |
d62a17ae | 11960 | |
545f0503 CS |
11961 | /* Area print. */ |
11962 | if (OSPF_IF_PARAM_CONFIGURED(params, if_area)) { | |
409f98ab | 11963 | if (ospf_instance) |
545f0503 | 11964 | vty_out(vty, " ip ospf %d", |
409f98ab | 11965 | ospf_instance); |
545f0503 CS |
11966 | else |
11967 | vty_out(vty, " ip ospf"); | |
d62a17ae | 11968 | |
1f9d4e3d | 11969 | char buf[INET_ADDRSTRLEN]; |
d62a17ae | 11970 | |
996c9314 LB |
11971 | area_id2str(buf, sizeof(buf), ¶ms->if_area, |
11972 | params->if_area_id_fmt); | |
545f0503 | 11973 | vty_out(vty, " area %s", buf); |
e425c019 | 11974 | if (params != IF_DEF_PARAMS(ifp) && rn) |
96b663a3 MS |
11975 | vty_out(vty, " %pI4", |
11976 | &rn->p.u.prefix4); | |
545f0503 CS |
11977 | vty_out(vty, "\n"); |
11978 | } | |
d62a17ae | 11979 | |
545f0503 | 11980 | /* bfd print. */ |
659f4e40 | 11981 | if (params && params->bfd_config) |
545f0503 | 11982 | ospf_bfd_write_config(vty, params); |
d62a17ae | 11983 | |
545f0503 CS |
11984 | /* MTU ignore print. */ |
11985 | if (OSPF_IF_PARAM_CONFIGURED(params, mtu_ignore) | |
996c9314 | 11986 | && params->mtu_ignore != OSPF_MTU_IGNORE_DEFAULT) { |
545f0503 CS |
11987 | if (params->mtu_ignore == 0) |
11988 | vty_out(vty, " no ip ospf mtu-ignore"); | |
11989 | else | |
11990 | vty_out(vty, " ip ospf mtu-ignore"); | |
e425c019 | 11991 | if (params != IF_DEF_PARAMS(ifp) && rn) |
96b663a3 MS |
11992 | vty_out(vty, " %pI4", |
11993 | &rn->p.u.prefix4); | |
545f0503 CS |
11994 | vty_out(vty, "\n"); |
11995 | } | |
a8b828f3 | 11996 | |
3eec4ee0 IR |
11997 | if (OSPF_IF_PARAM_CONFIGURED(params, |
11998 | passive_interface)) { | |
82f0277b IR |
11999 | vty_out(vty, " %sip ospf passive", |
12000 | params->passive_interface | |
12001 | == OSPF_IF_ACTIVE | |
12002 | ? "no " | |
12003 | : ""); | |
3eec4ee0 IR |
12004 | if (params != IF_DEF_PARAMS(ifp) && rn) |
12005 | vty_out(vty, " %pI4", &rn->p.u.prefix4); | |
12006 | vty_out(vty, "\n"); | |
12007 | } | |
12008 | ||
132a782e | 12009 | /* LDP-Sync print */ |
12010 | if (params && params->ldp_sync_info) | |
12011 | ospf_ldp_sync_if_write_config(vty, params); | |
d62a17ae | 12012 | |
545f0503 CS |
12013 | while (1) { |
12014 | if (rn == NULL) | |
996c9314 | 12015 | rn = route_top(IF_OIFS_PARAMS(ifp)); |
545f0503 CS |
12016 | else |
12017 | rn = route_next(rn); | |
43b8d1d8 | 12018 | |
545f0503 CS |
12019 | if (rn == NULL) |
12020 | break; | |
12021 | params = rn->info; | |
12022 | if (params != NULL) | |
12023 | break; | |
12024 | } | |
12025 | } while (rn); | |
43b8d1d8 | 12026 | |
545f0503 CS |
12027 | ospf_opaque_config_write_if(vty, ifp); |
12028 | ||
788a036f | 12029 | if_vty_config_end(vty); |
b5a8894d | 12030 | } |
545f0503 | 12031 | |
d62a17ae | 12032 | return write; |
718e3744 | 12033 | } |
12034 | ||
43b8d1d8 CS |
12035 | /* Configuration write function for ospfd. */ |
12036 | static int config_write_interface(struct vty *vty) | |
12037 | { | |
12038 | int write = 0; | |
545f0503 | 12039 | struct vrf *vrf = NULL; |
43b8d1d8 | 12040 | |
545f0503 CS |
12041 | /* Display all VRF aware OSPF interface configuration */ |
12042 | RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) { | |
12043 | write += config_write_interface_one(vty, vrf); | |
12044 | } | |
43b8d1d8 CS |
12045 | |
12046 | return write; | |
12047 | } | |
12048 | ||
d62a17ae | 12049 | static int config_write_network_area(struct vty *vty, struct ospf *ospf) |
718e3744 | 12050 | { |
d62a17ae | 12051 | struct route_node *rn; |
fc746f1c | 12052 | char buf[INET_ADDRSTRLEN]; |
718e3744 | 12053 | |
d62a17ae | 12054 | /* `network area' print. */ |
12055 | for (rn = route_top(ospf->networks); rn; rn = route_next(rn)) | |
12056 | if (rn->info) { | |
12057 | struct ospf_network *n = rn->info; | |
718e3744 | 12058 | |
d62a17ae | 12059 | /* Create Area ID string by specified Area ID format. */ |
12060 | if (n->area_id_fmt == OSPF_AREA_ID_FMT_DOTTEDQUAD) | |
fc746f1c | 12061 | inet_ntop(AF_INET, &n->area_id, buf, |
1f9d4e3d | 12062 | sizeof(buf)); |
d62a17ae | 12063 | else |
fc746f1c QY |
12064 | snprintf(buf, sizeof(buf), "%lu", |
12065 | (unsigned long int)ntohl( | |
12066 | n->area_id.s_addr)); | |
718e3744 | 12067 | |
d62a17ae | 12068 | /* Network print. */ |
96b663a3 | 12069 | vty_out(vty, " network %pFX area %s\n", &rn->p, buf); |
d62a17ae | 12070 | } |
718e3744 | 12071 | |
d62a17ae | 12072 | return 0; |
718e3744 | 12073 | } |
12074 | ||
d62a17ae | 12075 | static int config_write_ospf_area(struct vty *vty, struct ospf *ospf) |
718e3744 | 12076 | { |
d62a17ae | 12077 | struct listnode *node; |
12078 | struct ospf_area *area; | |
fc746f1c | 12079 | char buf[INET_ADDRSTRLEN]; |
718e3744 | 12080 | |
d62a17ae | 12081 | /* Area configuration print. */ |
12082 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) { | |
12083 | struct route_node *rn1; | |
718e3744 | 12084 | |
fc746f1c | 12085 | area_id2str(buf, sizeof(buf), &area->area_id, |
d62a17ae | 12086 | area->area_id_fmt); |
718e3744 | 12087 | |
d62a17ae | 12088 | if (area->auth_type != OSPF_AUTH_NULL) { |
12089 | if (area->auth_type == OSPF_AUTH_SIMPLE) | |
12090 | vty_out(vty, " area %s authentication\n", buf); | |
12091 | else | |
12092 | vty_out(vty, | |
12093 | " area %s authentication message-digest\n", | |
12094 | buf); | |
12095 | } | |
718e3744 | 12096 | |
d62a17ae | 12097 | if (area->shortcut_configured != OSPF_SHORTCUT_DEFAULT) |
12098 | vty_out(vty, " area %s shortcut %s\n", buf, | |
12099 | ospf_shortcut_mode_str | |
12100 | [area->shortcut_configured]); | |
12101 | ||
12102 | if ((area->external_routing == OSPF_AREA_STUB) | |
12103 | || (area->external_routing == OSPF_AREA_NSSA)) { | |
7ef56a73 | 12104 | if (area->external_routing == OSPF_AREA_STUB) { |
d62a17ae | 12105 | vty_out(vty, " area %s stub", buf); |
7ef56a73 CS |
12106 | if (area->no_summary) |
12107 | vty_out(vty, " no-summary\n"); | |
12108 | vty_out(vty, "\n"); | |
12109 | } else if (area->external_routing == OSPF_AREA_NSSA) { | |
d62a17ae | 12110 | switch (area->NSSATranslatorRole) { |
12111 | case OSPF_NSSA_ROLE_NEVER: | |
7ef56a73 CS |
12112 | vty_out(vty, |
12113 | " area %s nssa translate-never\n", | |
12114 | buf); | |
d62a17ae | 12115 | break; |
12116 | case OSPF_NSSA_ROLE_ALWAYS: | |
7ef56a73 CS |
12117 | vty_out(vty, |
12118 | " area %s nssa translate-always\n", | |
12119 | buf); | |
d62a17ae | 12120 | break; |
2643b2bc CS |
12121 | case OSPF_NSSA_ROLE_CANDIDATE: |
12122 | vty_out(vty, " area %s nssa \n", buf); | |
12123 | break; | |
d62a17ae | 12124 | } |
7ef56a73 CS |
12125 | if (area->no_summary) |
12126 | vty_out(vty, | |
12127 | " area %s nssa no-summary\n", | |
12128 | buf); | |
c317eddb | 12129 | if (area->suppress_fa) |
12130 | vty_out(vty, | |
12131 | " area %s nssa suppress-fa\n", | |
12132 | buf); | |
d62a17ae | 12133 | } |
718e3744 | 12134 | |
d62a17ae | 12135 | if (area->default_cost != 1) |
12136 | vty_out(vty, " area %s default-cost %d\n", buf, | |
12137 | area->default_cost); | |
12138 | } | |
718e3744 | 12139 | |
d62a17ae | 12140 | for (rn1 = route_top(area->ranges); rn1; rn1 = route_next(rn1)) |
12141 | if (rn1->info) { | |
12142 | struct ospf_area_range *range = rn1->info; | |
718e3744 | 12143 | |
96b663a3 MS |
12144 | vty_out(vty, " area %s range %pFX", buf, |
12145 | &rn1->p); | |
718e3744 | 12146 | |
d62a17ae | 12147 | if (range->cost_config |
12148 | != OSPF_AREA_RANGE_COST_UNSPEC) | |
12149 | vty_out(vty, " cost %d", | |
12150 | range->cost_config); | |
718e3744 | 12151 | |
d62a17ae | 12152 | if (!CHECK_FLAG(range->flags, |
12153 | OSPF_AREA_RANGE_ADVERTISE)) | |
12154 | vty_out(vty, " not-advertise"); | |
718e3744 | 12155 | |
d62a17ae | 12156 | if (CHECK_FLAG(range->flags, |
12157 | OSPF_AREA_RANGE_SUBSTITUTE)) | |
96b663a3 MS |
12158 | vty_out(vty, " substitute %pI4/%d", |
12159 | &range->subst_addr, | |
d62a17ae | 12160 | range->subst_masklen); |
12161 | ||
12162 | vty_out(vty, "\n"); | |
12163 | } | |
12164 | ||
12165 | if (EXPORT_NAME(area)) | |
12166 | vty_out(vty, " area %s export-list %s\n", buf, | |
12167 | EXPORT_NAME(area)); | |
12168 | ||
12169 | if (IMPORT_NAME(area)) | |
12170 | vty_out(vty, " area %s import-list %s\n", buf, | |
12171 | IMPORT_NAME(area)); | |
12172 | ||
12173 | if (PREFIX_NAME_IN(area)) | |
12174 | vty_out(vty, " area %s filter-list prefix %s in\n", buf, | |
12175 | PREFIX_NAME_IN(area)); | |
12176 | ||
12177 | if (PREFIX_NAME_OUT(area)) | |
12178 | vty_out(vty, " area %s filter-list prefix %s out\n", | |
12179 | buf, PREFIX_NAME_OUT(area)); | |
12180 | } | |
12181 | ||
12182 | return 0; | |
718e3744 | 12183 | } |
12184 | ||
d62a17ae | 12185 | static int config_write_ospf_nbr_nbma(struct vty *vty, struct ospf *ospf) |
718e3744 | 12186 | { |
d62a17ae | 12187 | struct ospf_nbr_nbma *nbr_nbma; |
12188 | struct route_node *rn; | |
718e3744 | 12189 | |
d62a17ae | 12190 | /* Static Neighbor configuration print. */ |
12191 | for (rn = route_top(ospf->nbr_nbma); rn; rn = route_next(rn)) | |
12192 | if ((nbr_nbma = rn->info)) { | |
96b663a3 | 12193 | vty_out(vty, " neighbor %pI4", &nbr_nbma->addr); |
718e3744 | 12194 | |
d62a17ae | 12195 | if (nbr_nbma->priority |
12196 | != OSPF_NEIGHBOR_PRIORITY_DEFAULT) | |
12197 | vty_out(vty, " priority %d", | |
12198 | nbr_nbma->priority); | |
718e3744 | 12199 | |
d62a17ae | 12200 | if (nbr_nbma->v_poll != OSPF_POLL_INTERVAL_DEFAULT) |
12201 | vty_out(vty, " poll-interval %d", | |
12202 | nbr_nbma->v_poll); | |
12203 | ||
12204 | vty_out(vty, "\n"); | |
12205 | } | |
12206 | ||
12207 | return 0; | |
12208 | } | |
12209 | ||
12210 | static int config_write_virtual_link(struct vty *vty, struct ospf *ospf) | |
12211 | { | |
12212 | struct listnode *node; | |
12213 | struct ospf_vl_data *vl_data; | |
83cc5a1f | 12214 | const char *auth_str; |
d62a17ae | 12215 | char buf[INET_ADDRSTRLEN]; |
12216 | ||
12217 | /* Virtual-Link print */ | |
12218 | for (ALL_LIST_ELEMENTS_RO(ospf->vlinks, node, vl_data)) { | |
12219 | struct listnode *n2; | |
12220 | struct crypt_key *ck; | |
12221 | struct ospf_interface *oi; | |
12222 | ||
12223 | if (vl_data != NULL) { | |
d62a17ae | 12224 | area_id2str(buf, sizeof(buf), &vl_data->vl_area_id, |
12225 | vl_data->vl_area_id_fmt); | |
12226 | oi = vl_data->vl_oi; | |
12227 | ||
12228 | /* timers */ | |
12229 | if (OSPF_IF_PARAM(oi, v_hello) | |
12230 | != OSPF_HELLO_INTERVAL_DEFAULT | |
12231 | || OSPF_IF_PARAM(oi, v_wait) | |
12232 | != OSPF_ROUTER_DEAD_INTERVAL_DEFAULT | |
12233 | || OSPF_IF_PARAM(oi, retransmit_interval) | |
12234 | != OSPF_RETRANSMIT_INTERVAL_DEFAULT | |
12235 | || OSPF_IF_PARAM(oi, transmit_delay) | |
12236 | != OSPF_TRANSMIT_DELAY_DEFAULT) | |
12237 | vty_out(vty, | |
96b663a3 MS |
12238 | " area %s virtual-link %pI4 hello-interval %d retransmit-interval %d transmit-delay %d dead-interval %d\n", |
12239 | buf, &vl_data->vl_peer, | |
d62a17ae | 12240 | OSPF_IF_PARAM(oi, v_hello), |
12241 | OSPF_IF_PARAM(oi, retransmit_interval), | |
12242 | OSPF_IF_PARAM(oi, transmit_delay), | |
12243 | OSPF_IF_PARAM(oi, v_wait)); | |
12244 | else | |
96b663a3 MS |
12245 | vty_out(vty, " area %s virtual-link %pI4\n", buf, |
12246 | &vl_data->vl_peer); | |
83cc5a1f DE |
12247 | /* Auth type */ |
12248 | auth_str = interface_config_auth_str( | |
12249 | IF_DEF_PARAMS(oi->ifp)); | |
12250 | if (auth_str) | |
12251 | vty_out(vty, | |
12252 | " area %s virtual-link %pI4 authentication%s\n", | |
12253 | buf, &vl_data->vl_peer, auth_str); | |
d62a17ae | 12254 | /* Auth key */ |
12255 | if (IF_DEF_PARAMS(vl_data->vl_oi->ifp)->auth_simple[0] | |
12256 | != '\0') | |
12257 | vty_out(vty, | |
96b663a3 MS |
12258 | " area %s virtual-link %pI4 authentication-key %s\n", |
12259 | buf, &vl_data->vl_peer, | |
d62a17ae | 12260 | IF_DEF_PARAMS(vl_data->vl_oi->ifp) |
12261 | ->auth_simple); | |
12262 | /* md5 keys */ | |
12263 | for (ALL_LIST_ELEMENTS_RO( | |
12264 | IF_DEF_PARAMS(vl_data->vl_oi->ifp) | |
12265 | ->auth_crypt, | |
12266 | n2, ck)) | |
12267 | vty_out(vty, | |
96b663a3 MS |
12268 | " area %s virtual-link %pI4 message-digest-key %d md5 %s\n", |
12269 | buf, &vl_data->vl_peer, | |
d62a17ae | 12270 | ck->key_id, ck->auth_key); |
12271 | } | |
12272 | } | |
12273 | ||
12274 | return 0; | |
718e3744 | 12275 | } |
12276 | ||
6b0655a2 | 12277 | |
d62a17ae | 12278 | static int config_write_ospf_redistribute(struct vty *vty, struct ospf *ospf) |
718e3744 | 12279 | { |
d62a17ae | 12280 | int type; |
718e3744 | 12281 | |
d62a17ae | 12282 | /* redistribute print. */ |
12283 | for (type = 0; type < ZEBRA_ROUTE_MAX; type++) { | |
12284 | struct list *red_list; | |
12285 | struct listnode *node; | |
12286 | struct ospf_redist *red; | |
718e3744 | 12287 | |
d62a17ae | 12288 | red_list = ospf->redist[type]; |
12289 | if (!red_list) | |
12290 | continue; | |
7c8ff89e | 12291 | |
d62a17ae | 12292 | for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) { |
12293 | vty_out(vty, " redistribute %s", | |
12294 | zebra_route_string(type)); | |
12295 | if (red->instance) | |
12296 | vty_out(vty, " %d", red->instance); | |
7c8ff89e | 12297 | |
d62a17ae | 12298 | if (red->dmetric.value >= 0) |
12299 | vty_out(vty, " metric %d", red->dmetric.value); | |
7c8ff89e | 12300 | |
d62a17ae | 12301 | if (red->dmetric.type == EXTERNAL_METRIC_TYPE_1) |
12302 | vty_out(vty, " metric-type 1"); | |
7c8ff89e | 12303 | |
d62a17ae | 12304 | if (ROUTEMAP_NAME(red)) |
12305 | vty_out(vty, " route-map %s", | |
12306 | ROUTEMAP_NAME(red)); | |
7c8ff89e | 12307 | |
d62a17ae | 12308 | vty_out(vty, "\n"); |
12309 | } | |
12310 | } | |
718e3744 | 12311 | |
d62a17ae | 12312 | return 0; |
718e3744 | 12313 | } |
12314 | ||
1ac88792 | 12315 | static int ospf_cfg_write_helper_dis_rtr_walkcb(struct hash_bucket *bucket, |
07b33add | 12316 | void *arg) |
12317 | { | |
1ac88792 | 12318 | struct advRtr *rtr = bucket->data; |
07b33add | 12319 | struct vty *vty = (struct vty *)arg; |
12320 | ||
859bce81 | 12321 | vty_out(vty, " graceful-restart helper enable %pI4\n", |
96b663a3 | 12322 | &rtr->advRtrAddr); |
07b33add | 12323 | return HASHWALK_CONTINUE; |
12324 | } | |
12325 | ||
10514170 RW |
12326 | static void config_write_ospf_gr(struct vty *vty, struct ospf *ospf) |
12327 | { | |
12328 | if (!ospf->gr_info.restart_support) | |
12329 | return; | |
12330 | ||
12331 | if (ospf->gr_info.grace_period == OSPF_DFLT_GRACE_INTERVAL) | |
12332 | vty_out(vty, " graceful-restart\n"); | |
12333 | else | |
12334 | vty_out(vty, " graceful-restart grace-period %u\n", | |
12335 | ospf->gr_info.grace_period); | |
12336 | } | |
12337 | ||
07b33add | 12338 | static int config_write_ospf_gr_helper(struct vty *vty, struct ospf *ospf) |
12339 | { | |
12340 | if (ospf->is_helper_supported) | |
859bce81 | 12341 | vty_out(vty, " graceful-restart helper enable\n"); |
07b33add | 12342 | |
12343 | if (!ospf->strict_lsa_check) | |
96b663a3 MS |
12344 | vty_out(vty, |
12345 | " no graceful-restart helper strict-lsa-checking\n"); | |
07b33add | 12346 | |
12347 | if (ospf->only_planned_restart) | |
12348 | vty_out(vty, " graceful-restart helper planned-only\n"); | |
12349 | ||
12350 | if (ospf->supported_grace_time != OSPF_MAX_GRACE_INTERVAL) | |
12351 | vty_out(vty, | |
12352 | " graceful-restart helper supported-grace-time %d\n", | |
12353 | ospf->supported_grace_time); | |
12354 | ||
12355 | if (OSPF_HELPER_ENABLE_RTR_COUNT(ospf)) { | |
12356 | hash_walk(ospf->enable_rtr_list, | |
12357 | ospf_cfg_write_helper_dis_rtr_walkcb, vty); | |
12358 | } | |
423e71c4 | 12359 | return 0; |
12360 | } | |
12361 | ||
12362 | static int config_write_ospf_external_aggregator(struct vty *vty, | |
12363 | struct ospf *ospf) | |
12364 | { | |
12365 | struct route_node *rn; | |
12366 | ||
d1b1eae1 | 12367 | if (ospf->aggr_delay_interval != OSPF_EXTL_AGGR_DEFAULT_DELAY) |
12368 | vty_out(vty, " aggregation timer %u\n", | |
12369 | ospf->aggr_delay_interval); | |
12370 | ||
423e71c4 | 12371 | /* print 'summary-address A.B.C.D/M' */ |
12372 | for (rn = route_top(ospf->rt_aggr_tbl); rn; rn = route_next(rn)) | |
12373 | if (rn->info) { | |
12374 | struct ospf_external_aggr_rt *aggr = rn->info; | |
12375 | ||
78cf8877 | 12376 | vty_out(vty, " summary-address %pI4/%d", |
423e71c4 | 12377 | &aggr->p.prefix, aggr->p.prefixlen); |
12378 | if (aggr->tag) | |
78cf8877 | 12379 | vty_out(vty, " tag %u", aggr->tag); |
423e71c4 | 12380 | |
12381 | if (CHECK_FLAG(aggr->flags, | |
12382 | OSPF_EXTERNAL_AGGRT_NO_ADVERTISE)) | |
12383 | vty_out(vty, " no-advertise"); | |
12384 | ||
12385 | vty_out(vty, "\n"); | |
12386 | } | |
07b33add | 12387 | |
12388 | return 0; | |
12389 | } | |
12390 | ||
d62a17ae | 12391 | static int config_write_ospf_default_metric(struct vty *vty, struct ospf *ospf) |
718e3744 | 12392 | { |
d62a17ae | 12393 | if (ospf->default_metric != -1) |
12394 | vty_out(vty, " default-metric %d\n", ospf->default_metric); | |
12395 | return 0; | |
718e3744 | 12396 | } |
12397 | ||
d62a17ae | 12398 | static int config_write_ospf_distribute(struct vty *vty, struct ospf *ospf) |
12399 | { | |
12400 | int type; | |
12401 | struct ospf_redist *red; | |
718e3744 | 12402 | |
d62a17ae | 12403 | if (ospf) { |
12404 | /* distribute-list print. */ | |
12405 | for (type = 0; type < ZEBRA_ROUTE_MAX; type++) | |
12406 | if (DISTRIBUTE_NAME(ospf, type)) | |
12407 | vty_out(vty, " distribute-list %s out %s\n", | |
12408 | DISTRIBUTE_NAME(ospf, type), | |
12409 | zebra_route_string(type)); | |
7c8ff89e | 12410 | |
d62a17ae | 12411 | /* default-information print. */ |
12412 | if (ospf->default_originate != DEFAULT_ORIGINATE_NONE) { | |
12413 | vty_out(vty, " default-information originate"); | |
12414 | if (ospf->default_originate == DEFAULT_ORIGINATE_ALWAYS) | |
12415 | vty_out(vty, " always"); | |
718e3744 | 12416 | |
d62a17ae | 12417 | red = ospf_redist_lookup(ospf, DEFAULT_ROUTE, 0); |
12418 | if (red) { | |
12419 | if (red->dmetric.value >= 0) | |
12420 | vty_out(vty, " metric %d", | |
12421 | red->dmetric.value); | |
951da435 | 12422 | |
d62a17ae | 12423 | if (red->dmetric.type == EXTERNAL_METRIC_TYPE_1) |
12424 | vty_out(vty, " metric-type 1"); | |
718e3744 | 12425 | |
d62a17ae | 12426 | if (ROUTEMAP_NAME(red)) |
12427 | vty_out(vty, " route-map %s", | |
12428 | ROUTEMAP_NAME(red)); | |
12429 | } | |
12430 | ||
12431 | vty_out(vty, "\n"); | |
12432 | } | |
12433 | } | |
12434 | ||
12435 | return 0; | |
718e3744 | 12436 | } |
12437 | ||
d62a17ae | 12438 | static int config_write_ospf_distance(struct vty *vty, struct ospf *ospf) |
12439 | { | |
12440 | struct route_node *rn; | |
12441 | struct ospf_distance *odistance; | |
12442 | ||
12443 | if (ospf->distance_all) | |
12444 | vty_out(vty, " distance %d\n", ospf->distance_all); | |
12445 | ||
12446 | if (ospf->distance_intra || ospf->distance_inter | |
12447 | || ospf->distance_external) { | |
12448 | vty_out(vty, " distance ospf"); | |
12449 | ||
12450 | if (ospf->distance_intra) | |
12451 | vty_out(vty, " intra-area %d", ospf->distance_intra); | |
12452 | if (ospf->distance_inter) | |
12453 | vty_out(vty, " inter-area %d", ospf->distance_inter); | |
12454 | if (ospf->distance_external) | |
12455 | vty_out(vty, " external %d", ospf->distance_external); | |
12456 | ||
12457 | vty_out(vty, "\n"); | |
12458 | } | |
12459 | ||
12460 | for (rn = route_top(ospf->distance_table); rn; rn = route_next(rn)) | |
12461 | if ((odistance = rn->info) != NULL) { | |
96b663a3 MS |
12462 | vty_out(vty, " distance %d %pFX %s\n", |
12463 | odistance->distance, &rn->p, | |
d62a17ae | 12464 | odistance->access_list ? odistance->access_list |
12465 | : ""); | |
12466 | } | |
12467 | return 0; | |
718e3744 | 12468 | } |
12469 | ||
43b8d1d8 | 12470 | static int ospf_config_write_one(struct vty *vty, struct ospf *ospf) |
d62a17ae | 12471 | { |
d62a17ae | 12472 | int write = 0; |
12473 | ||
43b8d1d8 | 12474 | /* `router ospf' print. */ |
ac2cb9bf | 12475 | if (ospf->instance && strcmp(ospf->name, VRF_DEFAULT_NAME)) { |
996c9314 LB |
12476 | vty_out(vty, "router ospf %d vrf %s\n", ospf->instance, |
12477 | ospf->name); | |
43b8d1d8 | 12478 | } else if (ospf->instance) { |
996c9314 | 12479 | vty_out(vty, "router ospf %d\n", ospf->instance); |
ac2cb9bf | 12480 | } else if (strcmp(ospf->name, VRF_DEFAULT_NAME)) { |
996c9314 | 12481 | vty_out(vty, "router ospf vrf %s\n", ospf->name); |
43b8d1d8 CS |
12482 | } else |
12483 | vty_out(vty, "router ospf\n"); | |
12484 | ||
12485 | if (!ospf->networks) { | |
12486 | write++; | |
b5a8894d | 12487 | return write; |
43b8d1d8 | 12488 | } |
d62a17ae | 12489 | |
43b8d1d8 | 12490 | /* Router ID print. */ |
3a6290bd | 12491 | if (ospf->router_id_static.s_addr != INADDR_ANY) |
96b663a3 MS |
12492 | vty_out(vty, " ospf router-id %pI4\n", |
12493 | &ospf->router_id_static); | |
d62a17ae | 12494 | |
5b5d66c4 | 12495 | /* zebra opaque attributes configuration. */ |
870791a3 IR |
12496 | if (CHECK_FLAG(ospf->config, OSPF_SEND_EXTRA_DATA_TO_ZEBRA)) |
12497 | vty_out(vty, " ospf send-extra-data zebra\n"); | |
5b5d66c4 | 12498 | |
43b8d1d8 CS |
12499 | /* ABR type print. */ |
12500 | if (ospf->abr_type != OSPF_ABR_DEFAULT) | |
12501 | vty_out(vty, " ospf abr-type %s\n", | |
12502 | ospf_abr_type_str[ospf->abr_type]); | |
b5a8894d | 12503 | |
43b8d1d8 CS |
12504 | /* log-adjacency-changes flag print. */ |
12505 | if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES)) { | |
12506 | if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL)) | |
12507 | vty_out(vty, " log-adjacency-changes detail\n"); | |
c572fbfe | 12508 | else if (!SAVE_OSPF_LOG_ADJACENCY_CHANGES) |
43b8d1d8 | 12509 | vty_out(vty, " log-adjacency-changes\n"); |
c572fbfe | 12510 | } else if (SAVE_OSPF_LOG_ADJACENCY_CHANGES) { |
43b8d1d8 CS |
12511 | vty_out(vty, " no log-adjacency-changes\n"); |
12512 | } | |
b5a8894d | 12513 | |
43b8d1d8 CS |
12514 | /* RFC1583 compatibility flag print -- Compatible with CISCO |
12515 | * 12.1. */ | |
12516 | if (CHECK_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE)) | |
12517 | vty_out(vty, " compatible rfc1583\n"); | |
d62a17ae | 12518 | |
43b8d1d8 CS |
12519 | /* auto-cost reference-bandwidth configuration. */ |
12520 | if (ospf->ref_bandwidth != OSPF_DEFAULT_REF_BANDWIDTH) { | |
12521 | vty_out(vty, | |
3efd0893 | 12522 | "! Important: ensure reference bandwidth is consistent across all routers\n"); |
43b8d1d8 CS |
12523 | vty_out(vty, " auto-cost reference-bandwidth %d\n", |
12524 | ospf->ref_bandwidth); | |
12525 | } | |
d62a17ae | 12526 | |
43b8d1d8 CS |
12527 | /* SPF timers print. */ |
12528 | if (ospf->spf_delay != OSPF_SPF_DELAY_DEFAULT | |
12529 | || ospf->spf_holdtime != OSPF_SPF_HOLDTIME_DEFAULT | |
12530 | || ospf->spf_max_holdtime != OSPF_SPF_MAX_HOLDTIME_DEFAULT) | |
996c9314 LB |
12531 | vty_out(vty, " timers throttle spf %d %d %d\n", ospf->spf_delay, |
12532 | ospf->spf_holdtime, ospf->spf_max_holdtime); | |
43b8d1d8 CS |
12533 | |
12534 | /* LSA timers print. */ | |
12535 | if (ospf->min_ls_interval != OSPF_MIN_LS_INTERVAL) | |
12536 | vty_out(vty, " timers throttle lsa all %d\n", | |
12537 | ospf->min_ls_interval); | |
12538 | if (ospf->min_ls_arrival != OSPF_MIN_LS_ARRIVAL) | |
12539 | vty_out(vty, " timers lsa min-arrival %d\n", | |
12540 | ospf->min_ls_arrival); | |
12541 | ||
12542 | /* Write multiplier print. */ | |
12543 | if (ospf->write_oi_count != OSPF_WRITE_INTERFACE_COUNT_DEFAULT) | |
12544 | vty_out(vty, " ospf write-multiplier %d\n", | |
12545 | ospf->write_oi_count); | |
d62a17ae | 12546 | |
3d5b9855 | 12547 | if (ospf->max_multipath != MULTIPATH_NUM) |
12548 | vty_out(vty, " maximum-paths %d\n", ospf->max_multipath); | |
12549 | ||
43b8d1d8 CS |
12550 | /* Max-metric router-lsa print */ |
12551 | config_write_stub_router(vty, ospf); | |
d62a17ae | 12552 | |
43b8d1d8 | 12553 | /* SPF refresh parameters print. */ |
996c9314 LB |
12554 | if (ospf->lsa_refresh_interval != OSPF_LSA_REFRESH_INTERVAL_DEFAULT) |
12555 | vty_out(vty, " refresh timer %d\n", ospf->lsa_refresh_interval); | |
d62a17ae | 12556 | |
43b8d1d8 CS |
12557 | /* Redistribute information print. */ |
12558 | config_write_ospf_redistribute(vty, ospf); | |
d62a17ae | 12559 | |
10514170 RW |
12560 | /* Graceful Restart print */ |
12561 | config_write_ospf_gr(vty, ospf); | |
07b33add | 12562 | config_write_ospf_gr_helper(vty, ospf); |
12563 | ||
423e71c4 | 12564 | /* Print external route aggregation. */ |
12565 | config_write_ospf_external_aggregator(vty, ospf); | |
12566 | ||
43b8d1d8 CS |
12567 | /* passive-interface print. */ |
12568 | if (ospf->passive_interface_default == OSPF_IF_PASSIVE) | |
12569 | vty_out(vty, " passive-interface default\n"); | |
d62a17ae | 12570 | |
a92706bb JU |
12571 | /* proactive-arp print. */ |
12572 | if (ospf->proactive_arp != OSPF_PROACTIVE_ARP_DEFAULT) { | |
12573 | if (ospf->proactive_arp) | |
12574 | vty_out(vty, " proactive-arp\n"); | |
12575 | else | |
12576 | vty_out(vty, " no proactive-arp\n"); | |
12577 | } | |
12578 | ||
7fd0729f | 12579 | /* TI-LFA print. */ |
385a1e07 G |
12580 | if (ospf->ti_lfa_enabled) { |
12581 | if (ospf->ti_lfa_protection_type == OSPF_TI_LFA_NODE_PROTECTION) | |
12582 | vty_out(vty, " fast-reroute ti-lfa node-protection\n"); | |
12583 | else | |
12584 | vty_out(vty, " fast-reroute ti-lfa\n"); | |
12585 | } | |
7fd0729f | 12586 | |
43b8d1d8 CS |
12587 | /* Network area print. */ |
12588 | config_write_network_area(vty, ospf); | |
d62a17ae | 12589 | |
43b8d1d8 CS |
12590 | /* Area config print. */ |
12591 | config_write_ospf_area(vty, ospf); | |
d62a17ae | 12592 | |
43b8d1d8 CS |
12593 | /* static neighbor print. */ |
12594 | config_write_ospf_nbr_nbma(vty, ospf); | |
12595 | ||
12596 | /* Virtual-Link print. */ | |
12597 | config_write_virtual_link(vty, ospf); | |
12598 | ||
12599 | /* Default metric configuration. */ | |
12600 | config_write_ospf_default_metric(vty, ospf); | |
12601 | ||
12602 | /* Distribute-list and default-information print. */ | |
12603 | config_write_ospf_distribute(vty, ospf); | |
12604 | ||
12605 | /* Distance configuration. */ | |
12606 | config_write_ospf_distance(vty, ospf); | |
12607 | ||
12608 | ospf_opaque_config_write_router(vty, ospf); | |
12609 | ||
132a782e | 12610 | /* LDP-Sync print */ |
12611 | ospf_ldp_sync_write_config(vty, ospf); | |
12612 | ||
07679ad9 IR |
12613 | vty_out(vty, "exit\n"); |
12614 | ||
43b8d1d8 CS |
12615 | write++; |
12616 | return write; | |
12617 | } | |
12618 | ||
12619 | /* OSPF configuration write function. */ | |
12620 | static int ospf_config_write(struct vty *vty) | |
12621 | { | |
12622 | struct ospf *ospf; | |
12623 | struct listnode *ospf_node = NULL; | |
12624 | int write = 0; | |
12625 | ||
12626 | if (listcount(om->ospf) == 0) | |
12627 | return write; | |
12628 | ||
12629 | for (ALL_LIST_ELEMENTS_RO(om->ospf, ospf_node, ospf)) { | |
88d77109 CS |
12630 | /* VRF Default check if it is running. |
12631 | * Upon daemon start, there could be default instance | |
12632 | * in absence of 'router ospf'/oi_running is disabled. */ | |
12633 | if (ospf->vrf_id == VRF_DEFAULT && ospf->oi_running) | |
12634 | write += ospf_config_write_one(vty, ospf); | |
12635 | /* For Non-Default VRF simply display the configuration, | |
12636 | * even if it is not oi_running. */ | |
12637 | else if (ospf->vrf_id != VRF_DEFAULT) | |
43b8d1d8 | 12638 | write += ospf_config_write_one(vty, ospf); |
b5a8894d | 12639 | } |
d62a17ae | 12640 | return write; |
12641 | } | |
12642 | ||
12643 | void ospf_vty_show_init(void) | |
12644 | { | |
12645 | /* "show ip ospf" commands. */ | |
12646 | install_element(VIEW_NODE, &show_ip_ospf_cmd); | |
12647 | ||
12648 | install_element(VIEW_NODE, &show_ip_ospf_instance_cmd); | |
12649 | ||
12650 | /* "show ip ospf database" commands. */ | |
a11bce11 | 12651 | install_element(VIEW_NODE, &show_ip_ospf_database_cmd); |
d62a17ae | 12652 | install_element(VIEW_NODE, &show_ip_ospf_database_max_cmd); |
a11bce11 IR |
12653 | install_element(VIEW_NODE, |
12654 | &show_ip_ospf_database_type_adv_router_cmd); | |
d62a17ae | 12655 | install_element(VIEW_NODE, |
12656 | &show_ip_ospf_instance_database_type_adv_router_cmd); | |
12657 | install_element(VIEW_NODE, &show_ip_ospf_instance_database_cmd); | |
12658 | install_element(VIEW_NODE, &show_ip_ospf_instance_database_max_cmd); | |
12659 | ||
12660 | /* "show ip ospf interface" commands. */ | |
12661 | install_element(VIEW_NODE, &show_ip_ospf_interface_cmd); | |
12662 | ||
12663 | install_element(VIEW_NODE, &show_ip_ospf_instance_interface_cmd); | |
c9339663 CS |
12664 | /* "show ip ospf interface traffic */ |
12665 | install_element(VIEW_NODE, &show_ip_ospf_interface_traffic_cmd); | |
d62a17ae | 12666 | |
12667 | /* "show ip ospf neighbor" commands. */ | |
12668 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_int_detail_cmd); | |
12669 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_int_cmd); | |
12670 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_id_cmd); | |
12671 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_detail_all_cmd); | |
12672 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_detail_cmd); | |
12673 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_cmd); | |
12674 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_all_cmd); | |
12675 | ||
12676 | install_element(VIEW_NODE, | |
12677 | &show_ip_ospf_instance_neighbor_int_detail_cmd); | |
12678 | install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_int_cmd); | |
12679 | install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_id_cmd); | |
12680 | install_element(VIEW_NODE, | |
12681 | &show_ip_ospf_instance_neighbor_detail_all_cmd); | |
12682 | install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_detail_cmd); | |
12683 | install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_cmd); | |
12684 | install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_all_cmd); | |
12685 | ||
12686 | /* "show ip ospf route" commands. */ | |
12687 | install_element(VIEW_NODE, &show_ip_ospf_route_cmd); | |
12688 | install_element(VIEW_NODE, &show_ip_ospf_border_routers_cmd); | |
d86760ac | 12689 | install_element(VIEW_NODE, &show_ip_ospf_reachable_routers_cmd); |
d62a17ae | 12690 | |
12691 | install_element(VIEW_NODE, &show_ip_ospf_instance_route_cmd); | |
12692 | install_element(VIEW_NODE, &show_ip_ospf_instance_border_routers_cmd); | |
d86760ac CH |
12693 | install_element(VIEW_NODE, |
12694 | &show_ip_ospf_instance_reachable_routers_cmd); | |
b5a8894d CS |
12695 | |
12696 | /* "show ip ospf vrfs" commands. */ | |
12697 | install_element(VIEW_NODE, &show_ip_ospf_vrfs_cmd); | |
abd5b8c7 | 12698 | |
003d3dbe RW |
12699 | /* "show ip ospf gr-helper details" command */ |
12700 | install_element(VIEW_NODE, &show_ip_ospf_gr_helper_cmd); | |
12701 | ||
53e44d05 | 12702 | /* "show ip ospf summary-address" command */ |
12703 | install_element(VIEW_NODE, &show_ip_ospf_external_aggregator_cmd); | |
12704 | } | |
6b0655a2 | 12705 | |
718e3744 | 12706 | /* Initialization of OSPF interface. */ |
d62a17ae | 12707 | static void ospf_vty_if_init(void) |
12708 | { | |
12709 | /* Install interface node. */ | |
9da01b0b | 12710 | if_cmd_init(config_write_interface); |
d62a17ae | 12711 | |
12712 | /* "ip ospf authentication" commands. */ | |
12713 | install_element(INTERFACE_NODE, &ip_ospf_authentication_args_addr_cmd); | |
12714 | install_element(INTERFACE_NODE, &ip_ospf_authentication_addr_cmd); | |
12715 | install_element(INTERFACE_NODE, | |
12716 | &no_ip_ospf_authentication_args_addr_cmd); | |
12717 | install_element(INTERFACE_NODE, &no_ip_ospf_authentication_addr_cmd); | |
12718 | install_element(INTERFACE_NODE, &ip_ospf_authentication_key_addr_cmd); | |
12719 | install_element(INTERFACE_NODE, | |
12720 | &no_ip_ospf_authentication_key_authkey_addr_cmd); | |
12721 | install_element(INTERFACE_NODE, | |
12722 | &no_ospf_authentication_key_authkey_addr_cmd); | |
12723 | ||
12724 | /* "ip ospf message-digest-key" commands. */ | |
12725 | install_element(INTERFACE_NODE, &ip_ospf_message_digest_key_cmd); | |
12726 | install_element(INTERFACE_NODE, &no_ip_ospf_message_digest_key_cmd); | |
12727 | ||
12728 | /* "ip ospf cost" commands. */ | |
12729 | install_element(INTERFACE_NODE, &ip_ospf_cost_cmd); | |
12730 | install_element(INTERFACE_NODE, &no_ip_ospf_cost_cmd); | |
12731 | ||
12732 | /* "ip ospf mtu-ignore" commands. */ | |
12733 | install_element(INTERFACE_NODE, &ip_ospf_mtu_ignore_addr_cmd); | |
12734 | install_element(INTERFACE_NODE, &no_ip_ospf_mtu_ignore_addr_cmd); | |
12735 | ||
12736 | /* "ip ospf dead-interval" commands. */ | |
12737 | install_element(INTERFACE_NODE, &ip_ospf_dead_interval_cmd); | |
12738 | install_element(INTERFACE_NODE, | |
12739 | &ip_ospf_dead_interval_minimal_addr_cmd); | |
12740 | install_element(INTERFACE_NODE, &no_ip_ospf_dead_interval_cmd); | |
12741 | ||
12742 | /* "ip ospf hello-interval" commands. */ | |
12743 | install_element(INTERFACE_NODE, &ip_ospf_hello_interval_cmd); | |
12744 | install_element(INTERFACE_NODE, &no_ip_ospf_hello_interval_cmd); | |
12745 | ||
12746 | /* "ip ospf network" commands. */ | |
12747 | install_element(INTERFACE_NODE, &ip_ospf_network_cmd); | |
12748 | install_element(INTERFACE_NODE, &no_ip_ospf_network_cmd); | |
12749 | ||
12750 | /* "ip ospf priority" commands. */ | |
12751 | install_element(INTERFACE_NODE, &ip_ospf_priority_cmd); | |
12752 | install_element(INTERFACE_NODE, &no_ip_ospf_priority_cmd); | |
12753 | ||
12754 | /* "ip ospf retransmit-interval" commands. */ | |
12755 | install_element(INTERFACE_NODE, &ip_ospf_retransmit_interval_addr_cmd); | |
12756 | install_element(INTERFACE_NODE, | |
12757 | &no_ip_ospf_retransmit_interval_addr_cmd); | |
12758 | ||
12759 | /* "ip ospf transmit-delay" commands. */ | |
12760 | install_element(INTERFACE_NODE, &ip_ospf_transmit_delay_addr_cmd); | |
12761 | install_element(INTERFACE_NODE, &no_ip_ospf_transmit_delay_addr_cmd); | |
12762 | ||
12763 | /* "ip ospf area" commands. */ | |
12764 | install_element(INTERFACE_NODE, &ip_ospf_area_cmd); | |
12765 | install_element(INTERFACE_NODE, &no_ip_ospf_area_cmd); | |
12766 | ||
3eec4ee0 IR |
12767 | /* "ip ospf passive" commands. */ |
12768 | install_element(INTERFACE_NODE, &ip_ospf_passive_cmd); | |
12769 | install_element(INTERFACE_NODE, &no_ip_ospf_passive_cmd); | |
12770 | ||
d62a17ae | 12771 | /* These commands are compatibitliy for previous version. */ |
12772 | install_element(INTERFACE_NODE, &ospf_authentication_key_cmd); | |
12773 | install_element(INTERFACE_NODE, &ospf_message_digest_key_cmd); | |
12774 | install_element(INTERFACE_NODE, &no_ospf_message_digest_key_cmd); | |
12775 | install_element(INTERFACE_NODE, &ospf_dead_interval_cmd); | |
12776 | install_element(INTERFACE_NODE, &no_ospf_dead_interval_cmd); | |
12777 | install_element(INTERFACE_NODE, &ospf_hello_interval_cmd); | |
12778 | install_element(INTERFACE_NODE, &no_ospf_hello_interval_cmd); | |
12779 | install_element(INTERFACE_NODE, &ospf_cost_cmd); | |
12780 | install_element(INTERFACE_NODE, &no_ospf_cost_cmd); | |
12781 | install_element(INTERFACE_NODE, &ospf_network_cmd); | |
12782 | install_element(INTERFACE_NODE, &no_ospf_network_cmd); | |
12783 | install_element(INTERFACE_NODE, &ospf_priority_cmd); | |
12784 | install_element(INTERFACE_NODE, &no_ospf_priority_cmd); | |
12785 | install_element(INTERFACE_NODE, &ospf_retransmit_interval_cmd); | |
12786 | install_element(INTERFACE_NODE, &no_ospf_retransmit_interval_cmd); | |
12787 | install_element(INTERFACE_NODE, &ospf_transmit_delay_cmd); | |
12788 | install_element(INTERFACE_NODE, &no_ospf_transmit_delay_cmd); | |
12789 | } | |
12790 | ||
12791 | static void ospf_vty_zebra_init(void) | |
12792 | { | |
12793 | install_element(OSPF_NODE, &ospf_redistribute_source_cmd); | |
12794 | install_element(OSPF_NODE, &no_ospf_redistribute_source_cmd); | |
12795 | install_element(OSPF_NODE, &ospf_redistribute_instance_source_cmd); | |
12796 | install_element(OSPF_NODE, &no_ospf_redistribute_instance_source_cmd); | |
12797 | ||
12798 | install_element(OSPF_NODE, &ospf_distribute_list_out_cmd); | |
12799 | install_element(OSPF_NODE, &no_ospf_distribute_list_out_cmd); | |
12800 | ||
12801 | install_element(OSPF_NODE, &ospf_default_information_originate_cmd); | |
12802 | install_element(OSPF_NODE, &no_ospf_default_information_originate_cmd); | |
12803 | ||
12804 | install_element(OSPF_NODE, &ospf_default_metric_cmd); | |
12805 | install_element(OSPF_NODE, &no_ospf_default_metric_cmd); | |
12806 | ||
12807 | install_element(OSPF_NODE, &ospf_distance_cmd); | |
12808 | install_element(OSPF_NODE, &no_ospf_distance_cmd); | |
12809 | install_element(OSPF_NODE, &no_ospf_distance_ospf_cmd); | |
12810 | install_element(OSPF_NODE, &ospf_distance_ospf_cmd); | |
07b33add | 12811 | |
003d3dbe RW |
12812 | /*Ospf garcefull restart helper configurations */ |
12813 | install_element(OSPF_NODE, &ospf_gr_helper_enable_cmd); | |
12814 | install_element(OSPF_NODE, &no_ospf_gr_helper_enable_cmd); | |
12815 | install_element(OSPF_NODE, &ospf_gr_helper_only_cmd); | |
12816 | install_element(OSPF_NODE, &no_ospf_gr_helper_only_cmd); | |
12817 | install_element(OSPF_NODE, &ospf_gr_helper_enable_lsacheck_cmd); | |
12818 | install_element(OSPF_NODE, &no_ospf_gr_helper_enable_lsacheck_cmd); | |
12819 | install_element(OSPF_NODE, &ospf_gr_helper_supported_grace_time_cmd); | |
12820 | install_element(OSPF_NODE, &no_ospf_gr_helper_supported_grace_time_cmd); | |
12821 | install_element(OSPF_NODE, &ospf_gr_helper_planned_only_cmd); | |
12822 | install_element(OSPF_NODE, &no_ospf_gr_helper_planned_only_cmd); | |
12823 | ||
423e71c4 | 12824 | /* External LSA summarisation config commands.*/ |
12825 | install_element(OSPF_NODE, &ospf_external_route_aggregation_cmd); | |
12826 | install_element(OSPF_NODE, &no_ospf_external_route_aggregation_cmd); | |
12827 | install_element(OSPF_NODE, | |
12828 | &ospf_external_route_aggregation_no_adrvertise_cmd); | |
12829 | install_element(OSPF_NODE, | |
12830 | &no_ospf_external_route_aggregation_no_adrvertise_cmd); | |
12831 | install_element(OSPF_NODE, &ospf_route_aggregation_timer_cmd); | |
12832 | install_element(OSPF_NODE, &no_ospf_route_aggregation_timer_cmd); | |
718e3744 | 12833 | } |
12834 | ||
612c2c15 | 12835 | static int ospf_config_write(struct vty *vty); |
62b346ee | 12836 | static struct cmd_node ospf_node = { |
f4b8291f | 12837 | .name = "ospf", |
62b346ee | 12838 | .node = OSPF_NODE, |
24389580 | 12839 | .parent_node = CONFIG_NODE, |
62b346ee | 12840 | .prompt = "%s(config-router)# ", |
612c2c15 | 12841 | .config_write = ospf_config_write, |
62b346ee | 12842 | }; |
718e3744 | 12843 | |
d62a17ae | 12844 | static void ospf_interface_clear(struct interface *ifp) |
09f35f8c | 12845 | { |
d62a17ae | 12846 | if (!if_is_operative(ifp)) |
12847 | return; | |
09f35f8c | 12848 | |
d62a17ae | 12849 | if (IS_DEBUG_OSPF(ism, ISM_EVENTS)) |
12850 | zlog_debug("ISM[%s]: clear by reset", ifp->name); | |
09f35f8c | 12851 | |
d62a17ae | 12852 | ospf_if_reset(ifp); |
09f35f8c DS |
12853 | } |
12854 | ||
12855 | DEFUN (clear_ip_ospf_interface, | |
12856 | clear_ip_ospf_interface_cmd, | |
1e81afc3 | 12857 | "clear ip ospf [vrf NAME] interface [IFNAME]", |
09f35f8c DS |
12858 | CLEAR_STR |
12859 | IP_STR | |
12860 | "OSPF information\n" | |
03ed9f02 | 12861 | VRF_CMD_HELP_STR |
09f35f8c DS |
12862 | "Interface information\n" |
12863 | "Interface name\n") | |
12864 | { | |
03ed9f02 PG |
12865 | int idx_ifname = 0; |
12866 | int idx_vrf = 0; | |
d62a17ae | 12867 | struct interface *ifp; |
f4e14fdb | 12868 | struct listnode *node; |
b5a8894d | 12869 | struct ospf *ospf = NULL; |
03ed9f02 PG |
12870 | char *vrf_name = NULL; |
12871 | vrf_id_t vrf_id = VRF_DEFAULT; | |
12872 | struct vrf *vrf = NULL; | |
09f35f8c | 12873 | |
03ed9f02 PG |
12874 | if (argv_find(argv, argc, "vrf", &idx_vrf)) |
12875 | vrf_name = argv[idx_vrf + 1]->arg; | |
12876 | if (vrf_name && strmatch(vrf_name, VRF_DEFAULT_NAME)) | |
12877 | vrf_name = NULL; | |
12878 | if (vrf_name) { | |
12879 | vrf = vrf_lookup_by_name(vrf_name); | |
12880 | if (vrf) | |
12881 | vrf_id = vrf->vrf_id; | |
12882 | } | |
12883 | if (!argv_find(argv, argc, "IFNAME", &idx_ifname)) { | |
12884 | /* Clear all the ospfv2 interfaces. */ | |
f4e14fdb | 12885 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { |
03ed9f02 PG |
12886 | if (vrf_id != ospf->vrf_id) |
12887 | continue; | |
12888 | if (!vrf) | |
12889 | vrf = vrf_lookup_by_id(ospf->vrf_id); | |
451fda4f | 12890 | FOR_ALL_INTERFACES (vrf, ifp) |
b5a8894d CS |
12891 | ospf_interface_clear(ifp); |
12892 | } | |
12893 | } else { | |
12894 | /* Interface name is specified. */ | |
a36898e7 | 12895 | ifp = if_lookup_by_name(argv[idx_ifname]->arg, vrf_id); |
b5a8894d | 12896 | if (ifp == NULL) |
d62a17ae | 12897 | vty_out(vty, "No such interface name\n"); |
12898 | else | |
12899 | ospf_interface_clear(ifp); | |
12900 | } | |
12901 | ||
12902 | return CMD_SUCCESS; | |
09f35f8c DS |
12903 | } |
12904 | ||
d62a17ae | 12905 | void ospf_vty_clear_init(void) |
09f35f8c | 12906 | { |
d62a17ae | 12907 | install_element(ENABLE_NODE, &clear_ip_ospf_interface_cmd); |
f91ce319 MR |
12908 | install_element(ENABLE_NODE, &clear_ip_ospf_process_cmd); |
12909 | install_element(ENABLE_NODE, &clear_ip_ospf_neighbor_cmd); | |
09f35f8c DS |
12910 | } |
12911 | ||
6b0655a2 | 12912 | |
718e3744 | 12913 | /* Install OSPF related vty commands. */ |
d62a17ae | 12914 | void ospf_vty_init(void) |
12915 | { | |
12916 | /* Install ospf top node. */ | |
612c2c15 | 12917 | install_node(&ospf_node); |
d62a17ae | 12918 | |
12919 | /* "router ospf" commands. */ | |
12920 | install_element(CONFIG_NODE, &router_ospf_cmd); | |
12921 | install_element(CONFIG_NODE, &no_router_ospf_cmd); | |
12922 | ||
12923 | ||
12924 | install_default(OSPF_NODE); | |
12925 | ||
12926 | /* "ospf router-id" commands. */ | |
12927 | install_element(OSPF_NODE, &ospf_router_id_cmd); | |
12928 | install_element(OSPF_NODE, &ospf_router_id_old_cmd); | |
12929 | install_element(OSPF_NODE, &no_ospf_router_id_cmd); | |
12930 | ||
12931 | /* "passive-interface" commands. */ | |
3eec4ee0 | 12932 | install_element(OSPF_NODE, &ospf_passive_interface_default_cmd); |
d62a17ae | 12933 | install_element(OSPF_NODE, &ospf_passive_interface_addr_cmd); |
3eec4ee0 | 12934 | install_element(OSPF_NODE, &no_ospf_passive_interface_default_cmd); |
d62a17ae | 12935 | install_element(OSPF_NODE, &no_ospf_passive_interface_addr_cmd); |
12936 | ||
12937 | /* "ospf abr-type" commands. */ | |
12938 | install_element(OSPF_NODE, &ospf_abr_type_cmd); | |
12939 | install_element(OSPF_NODE, &no_ospf_abr_type_cmd); | |
12940 | ||
12941 | /* "ospf log-adjacency-changes" commands. */ | |
12942 | install_element(OSPF_NODE, &ospf_log_adjacency_changes_cmd); | |
12943 | install_element(OSPF_NODE, &ospf_log_adjacency_changes_detail_cmd); | |
12944 | install_element(OSPF_NODE, &no_ospf_log_adjacency_changes_cmd); | |
12945 | install_element(OSPF_NODE, &no_ospf_log_adjacency_changes_detail_cmd); | |
12946 | ||
12947 | /* "ospf rfc1583-compatible" commands. */ | |
12948 | install_element(OSPF_NODE, &ospf_compatible_rfc1583_cmd); | |
12949 | install_element(OSPF_NODE, &no_ospf_compatible_rfc1583_cmd); | |
12950 | install_element(OSPF_NODE, &ospf_rfc1583_flag_cmd); | |
12951 | install_element(OSPF_NODE, &no_ospf_rfc1583_flag_cmd); | |
12952 | ||
5b5d66c4 RW |
12953 | /* "ospf send-extra-data zebra" commands. */ |
12954 | install_element(OSPF_NODE, &ospf_send_extra_data_cmd); | |
12955 | ||
d62a17ae | 12956 | /* "network area" commands. */ |
12957 | install_element(OSPF_NODE, &ospf_network_area_cmd); | |
12958 | install_element(OSPF_NODE, &no_ospf_network_area_cmd); | |
12959 | ||
12960 | /* "area authentication" commands. */ | |
12961 | install_element(OSPF_NODE, | |
12962 | &ospf_area_authentication_message_digest_cmd); | |
12963 | install_element(OSPF_NODE, &ospf_area_authentication_cmd); | |
12964 | install_element(OSPF_NODE, &no_ospf_area_authentication_cmd); | |
12965 | ||
12966 | /* "area range" commands. */ | |
12967 | install_element(OSPF_NODE, &ospf_area_range_cmd); | |
12968 | install_element(OSPF_NODE, &ospf_area_range_cost_cmd); | |
12969 | install_element(OSPF_NODE, &ospf_area_range_not_advertise_cmd); | |
12970 | install_element(OSPF_NODE, &no_ospf_area_range_cmd); | |
d62a17ae | 12971 | install_element(OSPF_NODE, &no_ospf_area_range_substitute_cmd); |
12972 | ||
12973 | /* "area virtual-link" commands. */ | |
12974 | install_element(OSPF_NODE, &ospf_area_vlink_cmd); | |
12975 | install_element(OSPF_NODE, &ospf_area_vlink_intervals_cmd); | |
12976 | install_element(OSPF_NODE, &no_ospf_area_vlink_cmd); | |
12977 | install_element(OSPF_NODE, &no_ospf_area_vlink_intervals_cmd); | |
12978 | ||
12979 | ||
12980 | /* "area stub" commands. */ | |
12981 | install_element(OSPF_NODE, &ospf_area_stub_no_summary_cmd); | |
12982 | install_element(OSPF_NODE, &ospf_area_stub_cmd); | |
12983 | install_element(OSPF_NODE, &no_ospf_area_stub_no_summary_cmd); | |
12984 | install_element(OSPF_NODE, &no_ospf_area_stub_cmd); | |
12985 | ||
12986 | /* "area nssa" commands. */ | |
12987 | install_element(OSPF_NODE, &ospf_area_nssa_cmd); | |
d62a17ae | 12988 | install_element(OSPF_NODE, &ospf_area_nssa_translate_cmd); |
12989 | install_element(OSPF_NODE, &ospf_area_nssa_no_summary_cmd); | |
7ef56a73 | 12990 | install_element(OSPF_NODE, &no_ospf_area_nssa_no_summary_cmd); |
c317eddb | 12991 | install_element(OSPF_NODE, &ospf_area_nssa_suppress_fa_cmd); |
12992 | install_element(OSPF_NODE, &no_ospf_area_nssa_suppress_fa_cmd); | |
d62a17ae | 12993 | install_element(OSPF_NODE, &no_ospf_area_nssa_cmd); |
12994 | ||
12995 | install_element(OSPF_NODE, &ospf_area_default_cost_cmd); | |
12996 | install_element(OSPF_NODE, &no_ospf_area_default_cost_cmd); | |
12997 | ||
12998 | install_element(OSPF_NODE, &ospf_area_shortcut_cmd); | |
12999 | install_element(OSPF_NODE, &no_ospf_area_shortcut_cmd); | |
13000 | ||
13001 | install_element(OSPF_NODE, &ospf_area_export_list_cmd); | |
13002 | install_element(OSPF_NODE, &no_ospf_area_export_list_cmd); | |
13003 | ||
13004 | install_element(OSPF_NODE, &ospf_area_filter_list_cmd); | |
13005 | install_element(OSPF_NODE, &no_ospf_area_filter_list_cmd); | |
13006 | ||
13007 | install_element(OSPF_NODE, &ospf_area_import_list_cmd); | |
13008 | install_element(OSPF_NODE, &no_ospf_area_import_list_cmd); | |
13009 | ||
13010 | /* SPF timer commands */ | |
13011 | install_element(OSPF_NODE, &ospf_timers_throttle_spf_cmd); | |
13012 | install_element(OSPF_NODE, &no_ospf_timers_throttle_spf_cmd); | |
13013 | ||
13014 | /* LSA timers commands */ | |
13015 | install_element(OSPF_NODE, &ospf_timers_min_ls_interval_cmd); | |
13016 | install_element(OSPF_NODE, &no_ospf_timers_min_ls_interval_cmd); | |
0e88de35 QY |
13017 | install_element(OSPF_NODE, &ospf_timers_lsa_min_arrival_cmd); |
13018 | install_element(OSPF_NODE, &no_ospf_timers_lsa_min_arrival_cmd); | |
d62a17ae | 13019 | |
13020 | /* refresh timer commands */ | |
13021 | install_element(OSPF_NODE, &ospf_refresh_timer_cmd); | |
13022 | install_element(OSPF_NODE, &no_ospf_refresh_timer_val_cmd); | |
13023 | ||
13024 | /* max-metric commands */ | |
13025 | install_element(OSPF_NODE, &ospf_max_metric_router_lsa_admin_cmd); | |
13026 | install_element(OSPF_NODE, &no_ospf_max_metric_router_lsa_admin_cmd); | |
13027 | install_element(OSPF_NODE, &ospf_max_metric_router_lsa_startup_cmd); | |
13028 | install_element(OSPF_NODE, &no_ospf_max_metric_router_lsa_startup_cmd); | |
13029 | install_element(OSPF_NODE, &ospf_max_metric_router_lsa_shutdown_cmd); | |
13030 | install_element(OSPF_NODE, &no_ospf_max_metric_router_lsa_shutdown_cmd); | |
13031 | ||
13032 | /* reference bandwidth commands */ | |
13033 | install_element(OSPF_NODE, &ospf_auto_cost_reference_bandwidth_cmd); | |
13034 | install_element(OSPF_NODE, &no_ospf_auto_cost_reference_bandwidth_cmd); | |
13035 | ||
13036 | /* "neighbor" commands. */ | |
13037 | install_element(OSPF_NODE, &ospf_neighbor_cmd); | |
13038 | install_element(OSPF_NODE, &ospf_neighbor_poll_interval_cmd); | |
13039 | install_element(OSPF_NODE, &no_ospf_neighbor_cmd); | |
13040 | install_element(OSPF_NODE, &no_ospf_neighbor_poll_cmd); | |
13041 | ||
13042 | /* write multiplier commands */ | |
13043 | install_element(OSPF_NODE, &ospf_write_multiplier_cmd); | |
13044 | install_element(OSPF_NODE, &write_multiplier_cmd); | |
13045 | install_element(OSPF_NODE, &no_ospf_write_multiplier_cmd); | |
13046 | install_element(OSPF_NODE, &no_write_multiplier_cmd); | |
13047 | ||
a92706bb JU |
13048 | /* "proactive-arp" commands. */ |
13049 | install_element(OSPF_NODE, &ospf_proactive_arp_cmd); | |
13050 | install_element(OSPF_NODE, &no_ospf_proactive_arp_cmd); | |
13051 | ||
7fd0729f G |
13052 | /* TI-LFA commands */ |
13053 | install_element(OSPF_NODE, &ospf_ti_lfa_cmd); | |
13054 | install_element(OSPF_NODE, &no_ospf_ti_lfa_cmd); | |
13055 | ||
3d5b9855 | 13056 | /* Max path configurations */ |
13057 | install_element(OSPF_NODE, &ospf_max_multipath_cmd); | |
13058 | install_element(OSPF_NODE, &no_ospf_max_multipath_cmd); | |
13059 | ||
cfc369c4 | 13060 | vrf_cmd_init(NULL); |
f5eef2d5 | 13061 | |
d62a17ae | 13062 | /* Init interface related vty commands. */ |
13063 | ospf_vty_if_init(); | |
13064 | ||
13065 | /* Init zebra related vty commands. */ | |
13066 | ospf_vty_zebra_init(); | |
718e3744 | 13067 | } |