]>
Commit | Line | Data |
---|---|---|
718e3744 | 1 | /* OSPF VTY interface. |
ba682537 | 2 | * Copyright (C) 2005 6WIND <alain.ritoux@6wind.com> |
718e3744 | 3 | * Copyright (C) 2000 Toshiaki Takada |
4 | * | |
5 | * This file is part of GNU Zebra. | |
6 | * | |
7 | * GNU Zebra is free software; you can redistribute it and/or modify it | |
8 | * under the terms of the GNU General Public License as published by the | |
9 | * Free Software Foundation; either version 2, or (at your option) any | |
10 | * later version. | |
11 | * | |
12 | * GNU Zebra is distributed in the hope that it will be useful, but | |
13 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 | * General Public License for more details. | |
16 | * | |
896014f4 DL |
17 | * You should have received a copy of the GNU General Public License along |
18 | * with this program; see the file COPYING; if not, write to the Free Software | |
19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
718e3744 | 20 | */ |
21 | ||
22 | #include <zebra.h> | |
7ec4159b | 23 | #include <string.h> |
718e3744 | 24 | |
f328dc60 | 25 | #include "printfrr.h" |
cbf3e3eb | 26 | #include "monotime.h" |
718e3744 | 27 | #include "memory.h" |
28 | #include "thread.h" | |
29 | #include "prefix.h" | |
30 | #include "table.h" | |
31 | #include "vty.h" | |
32 | #include "command.h" | |
33 | #include "plist.h" | |
34 | #include "log.h" | |
35 | #include "zclient.h" | |
bf2bfafd | 36 | #include <lib/json.h> |
8efe88ea | 37 | #include "defaults.h" |
96b663a3 | 38 | #include "lib/printfrr.h" |
718e3744 | 39 | |
40 | #include "ospfd/ospfd.h" | |
41 | #include "ospfd/ospf_asbr.h" | |
42 | #include "ospfd/ospf_lsa.h" | |
43 | #include "ospfd/ospf_lsdb.h" | |
44 | #include "ospfd/ospf_ism.h" | |
45 | #include "ospfd/ospf_interface.h" | |
46 | #include "ospfd/ospf_nsm.h" | |
47 | #include "ospfd/ospf_neighbor.h" | |
48 | #include "ospfd/ospf_flood.h" | |
49 | #include "ospfd/ospf_abr.h" | |
50 | #include "ospfd/ospf_spf.h" | |
51 | #include "ospfd/ospf_route.h" | |
52 | #include "ospfd/ospf_zebra.h" | |
53 | /*#include "ospfd/ospf_routemap.h" */ | |
54 | #include "ospfd/ospf_vty.h" | |
55 | #include "ospfd/ospf_dump.h" | |
7f342629 | 56 | #include "ospfd/ospf_bfd.h" |
132a782e | 57 | #include "ospfd/ospf_ldp_sync.h" |
718e3744 | 58 | |
f328dc60 | 59 | |
c572fbfe | 60 | FRR_CFG_DEFAULT_BOOL(OSPF_LOG_ADJACENCY_CHANGES, |
4c1458b5 DL |
61 | { .val_bool = true, .match_profile = "datacenter", }, |
62 | { .val_bool = false }, | |
67b0f40c | 63 | ); |
c572fbfe | 64 | |
2b64873d | 65 | static const char *const ospf_network_type_str[] = { |
d62a17ae | 66 | "Null", "POINTOPOINT", "BROADCAST", "NBMA", "POINTOMULTIPOINT", |
67 | "VIRTUALLINK", "LOOPBACK"}; | |
718e3744 | 68 | |
718e3744 | 69 | /* Utility functions. */ |
d62a17ae | 70 | int str2area_id(const char *str, struct in_addr *area_id, int *area_id_fmt) |
718e3744 | 71 | { |
d62a17ae | 72 | char *ep; |
718e3744 | 73 | |
d62a17ae | 74 | area_id->s_addr = htonl(strtoul(str, &ep, 10)); |
75 | if (*ep && !inet_aton(str, area_id)) | |
76 | return -1; | |
718e3744 | 77 | |
d62a17ae | 78 | *area_id_fmt = |
79 | *ep ? OSPF_AREA_ID_FMT_DOTTEDQUAD : OSPF_AREA_ID_FMT_DECIMAL; | |
718e3744 | 80 | |
d62a17ae | 81 | return 0; |
718e3744 | 82 | } |
83 | ||
1f9d4e3d | 84 | static void area_id2str(char *buf, int length, struct in_addr *area_id, |
85 | int area_id_fmt) | |
86573dcb | 86 | { |
d62a17ae | 87 | if (area_id_fmt == OSPF_AREA_ID_FMT_DOTTEDQUAD) |
1f9d4e3d | 88 | inet_ntop(AF_INET, area_id, buf, length); |
d62a17ae | 89 | else |
fc746f1c QY |
90 | snprintf(buf, length, "%lu", |
91 | (unsigned long)ntohl(area_id->s_addr)); | |
86573dcb | 92 | } |
6b0655a2 | 93 | |
d62a17ae | 94 | static int str2metric(const char *str, int *metric) |
718e3744 | 95 | { |
d62a17ae | 96 | /* Sanity check. */ |
97 | if (str == NULL) | |
98 | return 0; | |
718e3744 | 99 | |
d62a17ae | 100 | *metric = strtol(str, NULL, 10); |
1fdc969f | 101 | if (*metric < 0 || *metric > 16777214) { |
d62a17ae | 102 | /* vty_out (vty, "OSPF metric value is invalid\n"); */ |
103 | return 0; | |
104 | } | |
718e3744 | 105 | |
d62a17ae | 106 | return 1; |
718e3744 | 107 | } |
108 | ||
d62a17ae | 109 | static int str2metric_type(const char *str, int *metric_type) |
718e3744 | 110 | { |
d62a17ae | 111 | /* Sanity check. */ |
112 | if (str == NULL) | |
113 | return 0; | |
718e3744 | 114 | |
d62a17ae | 115 | if (strncmp(str, "1", 1) == 0) |
116 | *metric_type = EXTERNAL_METRIC_TYPE_1; | |
117 | else if (strncmp(str, "2", 1) == 0) | |
118 | *metric_type = EXTERNAL_METRIC_TYPE_2; | |
119 | else | |
120 | return 0; | |
718e3744 | 121 | |
d62a17ae | 122 | return 1; |
718e3744 | 123 | } |
124 | ||
d62a17ae | 125 | int ospf_oi_count(struct interface *ifp) |
718e3744 | 126 | { |
d62a17ae | 127 | struct route_node *rn; |
128 | int i = 0; | |
718e3744 | 129 | |
d62a17ae | 130 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) |
131 | if (rn->info) | |
132 | i++; | |
718e3744 | 133 | |
d62a17ae | 134 | return i; |
718e3744 | 135 | } |
136 | ||
996c9314 LB |
137 | #define OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf) \ |
138 | if (argv_find(argv, argc, "vrf", &idx_vrf)) { \ | |
139 | vrf_name = argv[idx_vrf + 1]->arg; \ | |
140 | all_vrf = strmatch(vrf_name, "all"); \ | |
43b8d1d8 CS |
141 | } |
142 | ||
409f98ab IR |
143 | static int ospf_router_cmd_parse(struct vty *vty, struct cmd_token *argv[], |
144 | const int argc, unsigned short *instance, | |
145 | const char **vrf_name) | |
718e3744 | 146 | { |
34d6798f | 147 | int idx_vrf = 0, idx_inst = 0; |
b5a8894d | 148 | |
34d6798f | 149 | *instance = 0; |
409f98ab IR |
150 | if (argv_find(argv, argc, "(1-65535)", &idx_inst)) { |
151 | if (ospf_instance == 0) { | |
152 | vty_out(vty, | |
153 | "%% OSPF is not running in instance mode\n"); | |
154 | return CMD_WARNING_CONFIG_FAILED; | |
155 | } | |
156 | ||
34d6798f | 157 | *instance = strtoul(argv[idx_inst]->arg, NULL, 10); |
409f98ab | 158 | } |
34d6798f | 159 | |
409f98ab | 160 | *vrf_name = NULL; |
b5a8894d | 161 | if (argv_find(argv, argc, "vrf", &idx_vrf)) { |
409f98ab IR |
162 | if (ospf_instance != 0) { |
163 | vty_out(vty, | |
164 | "%% VRF is not supported in instance mode\n"); | |
165 | return CMD_WARNING_CONFIG_FAILED; | |
b5a8894d | 166 | } |
34d6798f | 167 | |
409f98ab IR |
168 | *vrf_name = argv[idx_vrf + 1]->arg; |
169 | if (*vrf_name && strmatch(*vrf_name, VRF_DEFAULT_NAME)) | |
170 | *vrf_name = NULL; | |
c572fbfe DL |
171 | } |
172 | ||
409f98ab | 173 | return CMD_SUCCESS; |
43b8d1d8 CS |
174 | } |
175 | ||
52d0c099 | 176 | static void ospf_show_vrf_name(struct ospf *ospf, struct vty *vty, |
d7c0a89a | 177 | json_object *json, uint8_t use_vrf) |
52d0c099 | 178 | { |
b1c3ae8c CS |
179 | if (use_vrf) { |
180 | if (json) { | |
44076f4d RW |
181 | json_object_string_add(json, "vrfName", |
182 | ospf_get_name(ospf)); | |
b1c3ae8c | 183 | json_object_int_add(json, "vrfId", ospf->vrf_id); |
44076f4d RW |
184 | } else |
185 | vty_out(vty, "VRF Name: %s\n", ospf_get_name(ospf)); | |
52d0c099 | 186 | } |
52d0c099 CS |
187 | } |
188 | ||
43b8d1d8 | 189 | #ifndef VTYSH_EXTRACT_PL |
2e4c2296 | 190 | #include "ospfd/ospf_vty_clippy.c" |
43b8d1d8 CS |
191 | #endif |
192 | ||
193 | DEFUN_NOSH (router_ospf, | |
194 | router_ospf_cmd, | |
195 | "router ospf [{(1-65535)|vrf NAME}]", | |
196 | "Enable a routing process\n" | |
197 | "Start OSPF configuration\n" | |
198 | "Instance ID\n" | |
199 | VRF_CMD_HELP_STR) | |
200 | { | |
409f98ab IR |
201 | unsigned short instance; |
202 | const char *vrf_name; | |
203 | bool created = false; | |
204 | struct ospf *ospf; | |
205 | int ret; | |
43b8d1d8 | 206 | |
409f98ab IR |
207 | ret = ospf_router_cmd_parse(vty, argv, argc, &instance, &vrf_name); |
208 | if (ret != CMD_SUCCESS) | |
209 | return ret; | |
d62a17ae | 210 | |
409f98ab | 211 | if (instance != ospf_instance) { |
d62a17ae | 212 | VTY_PUSH_CONTEXT_NULL(OSPF_NODE); |
409f98ab | 213 | return CMD_NOT_MY_INSTANCE; |
d62a17ae | 214 | } |
215 | ||
409f98ab IR |
216 | ospf = ospf_get(instance, vrf_name, &created); |
217 | ||
218 | if (created) | |
219 | if (DFLT_OSPF_LOG_ADJACENCY_CHANGES) | |
220 | SET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES); | |
221 | ||
222 | if (IS_DEBUG_OSPF_EVENT) | |
223 | zlog_debug( | |
224 | "Config command 'router ospf %d' received, vrf %s id %u oi_running %u", | |
44076f4d RW |
225 | ospf->instance, ospf_get_name(ospf), ospf->vrf_id, |
226 | ospf->oi_running); | |
409f98ab IR |
227 | |
228 | VTY_PUSH_CONTEXT(OSPF_NODE, ospf); | |
229 | ||
64ac44f6 | 230 | return ret; |
718e3744 | 231 | } |
232 | ||
233 | DEFUN (no_router_ospf, | |
234 | no_router_ospf_cmd, | |
43b8d1d8 | 235 | "no router ospf [{(1-65535)|vrf NAME}]", |
718e3744 | 236 | NO_STR |
237 | "Enable a routing process\n" | |
7a7be519 | 238 | "Start OSPF configuration\n" |
b5a8894d CS |
239 | "Instance ID\n" |
240 | VRF_CMD_HELP_STR) | |
718e3744 | 241 | { |
409f98ab IR |
242 | unsigned short instance; |
243 | const char *vrf_name; | |
d62a17ae | 244 | struct ospf *ospf; |
409f98ab | 245 | int ret; |
b5a8894d | 246 | |
409f98ab IR |
247 | ret = ospf_router_cmd_parse(vty, argv, argc, &instance, &vrf_name); |
248 | if (ret != CMD_SUCCESS) | |
249 | return ret; | |
718e3744 | 250 | |
409f98ab IR |
251 | if (instance != ospf_instance) |
252 | return CMD_NOT_MY_INSTANCE; | |
253 | ||
254 | ospf = ospf_lookup(instance, vrf_name); | |
255 | if (ospf) | |
256 | ospf_finish(ospf); | |
257 | else | |
258 | ret = CMD_WARNING_CONFIG_FAILED; | |
259 | ||
260 | return ret; | |
718e3744 | 261 | } |
262 | ||
7c8ff89e | 263 | |
43b8d1d8 | 264 | DEFPY (ospf_router_id, |
718e3744 | 265 | ospf_router_id_cmd, |
266 | "ospf router-id A.B.C.D", | |
267 | "OSPF specific commands\n" | |
268 | "router-id for the OSPF process\n" | |
269 | "OSPF router-id in IP address format\n") | |
270 | { | |
a3d826f0 | 271 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
43b8d1d8 | 272 | |
d62a17ae | 273 | struct listnode *node; |
274 | struct ospf_area *area; | |
d62a17ae | 275 | |
276 | ospf->router_id_static = router_id; | |
277 | ||
278 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) | |
279 | if (area->full_nbrs) { | |
280 | vty_out(vty, | |
1b8049c7 | 281 | "For this router-id change to take effect, use \"clear ip ospf process\" command\n"); |
d62a17ae | 282 | return CMD_SUCCESS; |
283 | } | |
284 | ||
285 | ospf_router_id_update(ospf); | |
286 | ||
287 | return CMD_SUCCESS; | |
718e3744 | 288 | } |
289 | ||
7a7be519 | 290 | DEFUN_HIDDEN (ospf_router_id_old, |
747e489c DW |
291 | ospf_router_id_old_cmd, |
292 | "router-id A.B.C.D", | |
293 | "router-id for the OSPF process\n" | |
294 | "OSPF router-id in IP address format\n") | |
7a7be519 | 295 | { |
a3d826f0 | 296 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 297 | int idx_ipv4 = 1; |
298 | struct listnode *node; | |
299 | struct ospf_area *area; | |
300 | struct in_addr router_id; | |
301 | int ret; | |
302 | ||
303 | ret = inet_aton(argv[idx_ipv4]->arg, &router_id); | |
304 | if (!ret) { | |
305 | vty_out(vty, "Please specify Router ID by A.B.C.D\n"); | |
306 | return CMD_WARNING_CONFIG_FAILED; | |
307 | } | |
7a7be519 | 308 | |
d62a17ae | 309 | ospf->router_id_static = router_id; |
310 | ||
311 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) | |
312 | if (area->full_nbrs) { | |
313 | vty_out(vty, | |
1b8049c7 | 314 | "For this router-id change to take effect, use \"clear ip ospf process\" command\n"); |
d62a17ae | 315 | return CMD_SUCCESS; |
316 | } | |
317 | ||
318 | ospf_router_id_update(ospf); | |
319 | ||
320 | return CMD_SUCCESS; | |
7a7be519 | 321 | } |
747e489c | 322 | |
43b8d1d8 | 323 | DEFPY (no_ospf_router_id, |
718e3744 | 324 | no_ospf_router_id_cmd, |
7a7be519 | 325 | "no ospf router-id [A.B.C.D]", |
718e3744 | 326 | NO_STR |
327 | "OSPF specific commands\n" | |
7a7be519 | 328 | "router-id for the OSPF process\n" |
329 | "OSPF router-id in IP address format\n") | |
718e3744 | 330 | { |
a3d826f0 | 331 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 332 | struct listnode *node; |
333 | struct ospf_area *area; | |
68980084 | 334 | |
43b8d1d8 CS |
335 | if (router_id_str) { |
336 | if (!IPV4_ADDR_SAME(&ospf->router_id_static, &router_id)) { | |
337 | vty_out(vty, "%% OSPF router-id doesn't match\n"); | |
338 | return CMD_WARNING_CONFIG_FAILED; | |
339 | } | |
340 | } | |
341 | ||
d62a17ae | 342 | ospf->router_id_static.s_addr = 0; |
718e3744 | 343 | |
d62a17ae | 344 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) |
345 | if (area->full_nbrs) { | |
346 | vty_out(vty, | |
1b8049c7 | 347 | "For this router-id change to take effect, use \"clear ip ospf process\" command\n"); |
d62a17ae | 348 | return CMD_SUCCESS; |
349 | } | |
2c19a6ec | 350 | |
d62a17ae | 351 | ospf_router_id_update(ospf); |
718e3744 | 352 | |
d62a17ae | 353 | return CMD_SUCCESS; |
718e3744 | 354 | } |
355 | ||
718e3744 | 356 | |
3eec4ee0 IR |
357 | static void ospf_passive_interface_default_update(struct ospf *ospf, |
358 | uint8_t newval) | |
d62a17ae | 359 | { |
360 | struct listnode *ln; | |
d62a17ae | 361 | struct ospf_interface *oi; |
362 | ||
363 | ospf->passive_interface_default = newval; | |
364 | ||
3eec4ee0 IR |
365 | /* update multicast memberships */ |
366 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, ln, oi)) | |
d62a17ae | 367 | ospf_if_set_multicast(oi); |
d62a17ae | 368 | } |
369 | ||
82f0277b IR |
370 | static void ospf_passive_interface_update(struct interface *ifp, |
371 | struct ospf_if_params *params, | |
372 | struct in_addr addr, uint8_t newval) | |
d62a17ae | 373 | { |
3eec4ee0 | 374 | struct route_node *rn; |
d62a17ae | 375 | |
82f0277b IR |
376 | if (OSPF_IF_PARAM_CONFIGURED(params, passive_interface)) { |
377 | if (params->passive_interface == newval) | |
378 | return; | |
379 | ||
380 | params->passive_interface = newval; | |
381 | UNSET_IF_PARAM(params, passive_interface); | |
382 | if (params != IF_DEF_PARAMS(ifp)) { | |
383 | ospf_free_if_params(ifp, addr); | |
384 | ospf_if_update_params(ifp, addr); | |
385 | } | |
386 | } else { | |
387 | params->passive_interface = newval; | |
388 | SET_IF_PARAM(params, passive_interface); | |
389 | } | |
390 | ||
3eec4ee0 IR |
391 | /* |
392 | * XXX We should call ospf_if_set_multicast on exactly those | |
393 | * interfaces for which the passive property changed. It is too much | |
394 | * work to determine this set, so we do this for every interface. | |
395 | * This is safe and reasonable because ospf_if_set_multicast uses a | |
396 | * record of joined groups to avoid systems calls if the desired | |
397 | * memberships match the current memership. | |
398 | */ | |
d62a17ae | 399 | |
3eec4ee0 IR |
400 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { |
401 | struct ospf_interface *oi = rn->info; | |
d62a17ae | 402 | |
3eec4ee0 IR |
403 | if (oi) |
404 | ospf_if_set_multicast(oi); | |
d62a17ae | 405 | } |
3eec4ee0 IR |
406 | |
407 | /* | |
408 | * XXX It is not clear what state transitions the interface needs to | |
409 | * undergo when going from active to passive and vice versa. Fixing | |
410 | * this will require precise identification of interfaces having such a | |
411 | * transition. | |
412 | */ | |
d62a17ae | 413 | } |
414 | ||
3eec4ee0 IR |
415 | DEFUN (ospf_passive_interface_default, |
416 | ospf_passive_interface_default_cmd, | |
417 | "passive-interface default", | |
418 | "Suppress routing updates on an interface\n" | |
419 | "Suppress routing updates on interfaces by default\n") | |
d62a17ae | 420 | { |
3eec4ee0 IR |
421 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
422 | ||
423 | ospf_passive_interface_default_update(ospf, OSPF_IF_PASSIVE); | |
424 | ||
425 | return CMD_SUCCESS; | |
7ffa8fa2 PJ |
426 | } |
427 | ||
3eec4ee0 | 428 | DEFUN_HIDDEN (ospf_passive_interface_addr, |
a2c62831 | 429 | ospf_passive_interface_addr_cmd, |
3eec4ee0 | 430 | "passive-interface IFNAME [A.B.C.D]", |
718e3744 | 431 | "Suppress routing updates on an interface\n" |
7a7be519 | 432 | "Interface's name\n" |
3eec4ee0 | 433 | "IPv4 address\n") |
718e3744 | 434 | { |
a3d826f0 | 435 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 436 | int idx_ipv4 = 2; |
e99734f1 | 437 | struct interface *ifp = NULL; |
d62a17ae | 438 | struct in_addr addr = {.s_addr = INADDR_ANY}; |
d62a17ae | 439 | struct ospf_if_params *params; |
3eec4ee0 IR |
440 | int ret; |
441 | ||
442 | vty_out(vty, | |
443 | "This command is deprecated, because it is not VRF-aware.\n"); | |
444 | vty_out(vty, | |
445 | "Please, use \"ip ospf passive\" on an interface instead.\n"); | |
d62a17ae | 446 | |
e99734f1 | 447 | if (ospf->vrf_id != VRF_UNKNOWN) |
a36898e7 | 448 | ifp = if_get_by_name(argv[1]->arg, ospf->vrf_id); |
d62a17ae | 449 | |
b5a8894d | 450 | if (ifp == NULL) { |
996c9314 | 451 | vty_out(vty, "interface %s not found.\n", (char *)argv[1]->arg); |
e99734f1 | 452 | return CMD_WARNING_CONFIG_FAILED; |
b5a8894d | 453 | } |
d62a17ae | 454 | |
d62a17ae | 455 | if (argc == 3) { |
456 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
457 | if (!ret) { | |
458 | vty_out(vty, | |
459 | "Please specify interface address by A.B.C.D\n"); | |
460 | return CMD_WARNING_CONFIG_FAILED; | |
461 | } | |
462 | ||
463 | params = ospf_get_if_params(ifp, addr); | |
464 | ospf_if_update_params(ifp, addr); | |
3eec4ee0 IR |
465 | } else { |
466 | params = IF_DEF_PARAMS(ifp); | |
d62a17ae | 467 | } |
468 | ||
82f0277b | 469 | ospf_passive_interface_update(ifp, params, addr, OSPF_IF_PASSIVE); |
d62a17ae | 470 | |
3eec4ee0 IR |
471 | return CMD_SUCCESS; |
472 | } | |
d62a17ae | 473 | |
3eec4ee0 IR |
474 | DEFUN (no_ospf_passive_interface_default, |
475 | no_ospf_passive_interface_default_cmd, | |
476 | "no passive-interface default", | |
477 | NO_STR | |
478 | "Allow routing updates on an interface\n" | |
479 | "Allow routing updates on interfaces by default\n") | |
480 | { | |
481 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
482 | ||
483 | ospf_passive_interface_default_update(ospf, OSPF_IF_ACTIVE); | |
d62a17ae | 484 | |
485 | return CMD_SUCCESS; | |
718e3744 | 486 | } |
487 | ||
3eec4ee0 | 488 | DEFUN_HIDDEN (no_ospf_passive_interface, |
a2c62831 | 489 | no_ospf_passive_interface_addr_cmd, |
3eec4ee0 | 490 | "no passive-interface IFNAME [A.B.C.D]", |
718e3744 | 491 | NO_STR |
492 | "Allow routing updates on an interface\n" | |
7a7be519 | 493 | "Interface's name\n" |
3eec4ee0 | 494 | "IPv4 address\n") |
718e3744 | 495 | { |
a3d826f0 | 496 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 497 | int idx_ipv4 = 3; |
e99734f1 | 498 | struct interface *ifp = NULL; |
d62a17ae | 499 | struct in_addr addr = {.s_addr = INADDR_ANY}; |
500 | struct ospf_if_params *params; | |
501 | int ret; | |
d62a17ae | 502 | |
3eec4ee0 IR |
503 | vty_out(vty, |
504 | "This command is deprecated, because it is not VRF-aware.\n"); | |
505 | vty_out(vty, | |
506 | "Please, use \"no ip ospf passive\" on an interface instead.\n"); | |
43540886 | 507 | |
e99734f1 | 508 | if (ospf->vrf_id != VRF_UNKNOWN) |
a36898e7 | 509 | ifp = if_get_by_name(argv[2]->arg, ospf->vrf_id); |
e99734f1 | 510 | |
b5a8894d | 511 | if (ifp == NULL) { |
996c9314 | 512 | vty_out(vty, "interface %s not found.\n", (char *)argv[2]->arg); |
e99734f1 | 513 | return CMD_WARNING_CONFIG_FAILED; |
b5a8894d | 514 | } |
ba6454ec | 515 | |
d62a17ae | 516 | if (argc == 4) { |
517 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
518 | if (!ret) { | |
519 | vty_out(vty, | |
520 | "Please specify interface address by A.B.C.D\n"); | |
521 | return CMD_WARNING_CONFIG_FAILED; | |
522 | } | |
d62a17ae | 523 | params = ospf_lookup_if_params(ifp, addr); |
524 | if (params == NULL) | |
525 | return CMD_SUCCESS; | |
3eec4ee0 IR |
526 | } else { |
527 | params = IF_DEF_PARAMS(ifp); | |
d62a17ae | 528 | } |
d62a17ae | 529 | |
82f0277b | 530 | ospf_passive_interface_update(ifp, params, addr, OSPF_IF_ACTIVE); |
3eec4ee0 | 531 | |
d62a17ae | 532 | return CMD_SUCCESS; |
718e3744 | 533 | } |
534 | ||
718e3744 | 535 | |
a2c62831 | 536 | DEFUN (ospf_network_area, |
537 | ospf_network_area_cmd, | |
6147e2c6 | 538 | "network A.B.C.D/M area <A.B.C.D|(0-4294967295)>", |
718e3744 | 539 | "Enable routing on an IP network\n" |
540 | "OSPF network prefix\n" | |
541 | "Set the OSPF area ID\n" | |
542 | "OSPF area ID in IP address format\n" | |
543 | "OSPF area ID as a decimal value\n") | |
544 | { | |
a3d826f0 | 545 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 546 | int idx_ipv4_prefixlen = 1; |
547 | int idx_ipv4_number = 3; | |
548 | struct prefix_ipv4 p; | |
549 | struct in_addr area_id; | |
550 | int ret, format; | |
cbf32f74 | 551 | uint32_t count; |
d62a17ae | 552 | |
553 | if (ospf->instance) { | |
554 | vty_out(vty, | |
555 | "The network command is not supported in multi-instance ospf\n"); | |
556 | return CMD_WARNING_CONFIG_FAILED; | |
557 | } | |
718e3744 | 558 | |
cbf32f74 IR |
559 | count = ospf_count_area_params(ospf); |
560 | if (count > 0) { | |
d62a17ae | 561 | vty_out(vty, |
562 | "Please remove all ip ospf area x.x.x.x commands first.\n"); | |
aed7cc62 | 563 | if (IS_DEBUG_OSPF_EVENT) |
996c9314 | 564 | zlog_debug( |
d12566a1 | 565 | "%s ospf vrf %s num of %u ip ospf area x config", |
44076f4d | 566 | __func__, ospf_get_name(ospf), count); |
d62a17ae | 567 | return CMD_WARNING_CONFIG_FAILED; |
568 | } | |
569 | ||
570 | /* Get network prefix and Area ID. */ | |
571 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); | |
572 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); | |
573 | ||
574 | ret = ospf_network_set(ospf, &p, area_id, format); | |
575 | if (ret == 0) { | |
576 | vty_out(vty, "There is already same network statement.\n"); | |
2b0a905a | 577 | return CMD_WARNING_CONFIG_FAILED; |
d62a17ae | 578 | } |
579 | ||
580 | return CMD_SUCCESS; | |
718e3744 | 581 | } |
582 | ||
a2c62831 | 583 | DEFUN (no_ospf_network_area, |
584 | no_ospf_network_area_cmd, | |
6147e2c6 | 585 | "no network A.B.C.D/M area <A.B.C.D|(0-4294967295)>", |
718e3744 | 586 | NO_STR |
587 | "Enable routing on an IP network\n" | |
588 | "OSPF network prefix\n" | |
589 | "Set the OSPF area ID\n" | |
590 | "OSPF area ID in IP address format\n" | |
591 | "OSPF area ID as a decimal value\n") | |
592 | { | |
a3d826f0 | 593 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 594 | int idx_ipv4_prefixlen = 2; |
595 | int idx_ipv4_number = 4; | |
596 | struct prefix_ipv4 p; | |
597 | struct in_addr area_id; | |
598 | int ret, format; | |
599 | ||
600 | if (ospf->instance) { | |
601 | vty_out(vty, | |
602 | "The network command is not supported in multi-instance ospf\n"); | |
603 | return CMD_WARNING_CONFIG_FAILED; | |
604 | } | |
718e3744 | 605 | |
d62a17ae | 606 | /* Get network prefix and Area ID. */ |
607 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); | |
608 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); | |
609 | ||
610 | ret = ospf_network_unset(ospf, &p, area_id); | |
611 | if (ret == 0) { | |
612 | vty_out(vty, | |
613 | "Can't find specified network area configuration.\n"); | |
614 | return CMD_WARNING_CONFIG_FAILED; | |
615 | } | |
616 | ||
617 | return CMD_SUCCESS; | |
718e3744 | 618 | } |
619 | ||
a2c62831 | 620 | DEFUN (ospf_area_range, |
621 | ospf_area_range_cmd, | |
7a7be519 | 622 | "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M [advertise [cost (0-16777215)]]", |
718e3744 | 623 | "OSPF area parameters\n" |
624 | "OSPF area ID in IP address format\n" | |
625 | "OSPF area ID as a decimal value\n" | |
626 | "Summarize routes matching address/mask (border routers only)\n" | |
7a7be519 | 627 | "Area range prefix\n" |
628 | "Advertise this range (default)\n" | |
629 | "User specified metric for this range\n" | |
630 | "Advertised metric for this range\n") | |
718e3744 | 631 | { |
a3d826f0 | 632 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 633 | int idx_ipv4_number = 1; |
634 | int idx_ipv4_prefixlen = 3; | |
635 | int idx_cost = 6; | |
636 | struct prefix_ipv4 p; | |
637 | struct in_addr area_id; | |
638 | int format; | |
d7c0a89a | 639 | uint32_t cost; |
d62a17ae | 640 | |
641 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); | |
642 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); | |
643 | ||
644 | ospf_area_range_set(ospf, area_id, &p, OSPF_AREA_RANGE_ADVERTISE); | |
ed709ed1 GW |
645 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), |
646 | format); | |
d62a17ae | 647 | if (argc > 5) { |
648 | cost = strtoul(argv[idx_cost]->arg, NULL, 10); | |
649 | ospf_area_range_cost_set(ospf, area_id, &p, cost); | |
650 | } | |
718e3744 | 651 | |
d62a17ae | 652 | return CMD_SUCCESS; |
718e3744 | 653 | } |
654 | ||
7a7be519 | 655 | DEFUN (ospf_area_range_cost, |
656 | ospf_area_range_cost_cmd, | |
657 | "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M cost (0-16777215)", | |
658 | "OSPF area parameters\n" | |
659 | "OSPF area ID in IP address format\n" | |
660 | "OSPF area ID as a decimal value\n" | |
661 | "Summarize routes matching address/mask (border routers only)\n" | |
662 | "Area range prefix\n" | |
663 | "User specified metric for this range\n" | |
664 | "Advertised metric for this range\n") | |
665 | { | |
a3d826f0 | 666 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 667 | int idx_ipv4_number = 1; |
668 | int idx_ipv4_prefixlen = 3; | |
669 | int idx_cost = 5; | |
670 | struct prefix_ipv4 p; | |
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 | |
d62a17ae | 682 | cost = strtoul(argv[idx_cost]->arg, NULL, 10); |
683 | ospf_area_range_cost_set(ospf, area_id, &p, cost); | |
718e3744 | 684 | |
d62a17ae | 685 | return CMD_SUCCESS; |
7a7be519 | 686 | } |
718e3744 | 687 | |
a2c62831 | 688 | DEFUN (ospf_area_range_not_advertise, |
689 | ospf_area_range_not_advertise_cmd, | |
6147e2c6 | 690 | "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M not-advertise", |
718e3744 | 691 | "OSPF area parameters\n" |
692 | "OSPF area ID in IP address format\n" | |
693 | "OSPF area ID as a decimal value\n" | |
694 | "Summarize routes matching address/mask (border routers only)\n" | |
695 | "Area range prefix\n" | |
696 | "DoNotAdvertise this range\n") | |
697 | { | |
a3d826f0 | 698 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 699 | int idx_ipv4_number = 1; |
700 | int idx_ipv4_prefixlen = 3; | |
701 | struct prefix_ipv4 p; | |
702 | struct in_addr area_id; | |
703 | int format; | |
718e3744 | 704 | |
d62a17ae | 705 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
706 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); | |
718e3744 | 707 | |
d62a17ae | 708 | ospf_area_range_set(ospf, area_id, &p, 0); |
709 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
710 | format); | |
990baca0 | 711 | ospf_area_range_substitute_unset(ospf, area_id, &p); |
718e3744 | 712 | |
d62a17ae | 713 | return CMD_SUCCESS; |
718e3744 | 714 | } |
715 | ||
a2c62831 | 716 | DEFUN (no_ospf_area_range, |
717 | no_ospf_area_range_cmd, | |
3a2d747c | 718 | "no area <A.B.C.D|(0-4294967295)> range A.B.C.D/M [<cost (0-16777215)|advertise [cost (0-16777215)]|not-advertise>]", |
718e3744 | 719 | NO_STR |
720 | "OSPF area parameters\n" | |
721 | "OSPF area ID in IP address format\n" | |
722 | "OSPF area ID as a decimal value\n" | |
723 | "Summarize routes matching address/mask (border routers only)\n" | |
7a7be519 | 724 | "Area range prefix\n" |
3a2d747c QY |
725 | "User specified metric for this range\n" |
726 | "Advertised metric for this range\n" | |
7a7be519 | 727 | "Advertise this range (default)\n" |
3a2d747c QY |
728 | "User specified metric for this range\n" |
729 | "Advertised metric for this range\n" | |
7a7be519 | 730 | "DoNotAdvertise this range\n") |
718e3744 | 731 | { |
a3d826f0 | 732 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 733 | int idx_ipv4_number = 2; |
734 | int idx_ipv4_prefixlen = 4; | |
735 | struct prefix_ipv4 p; | |
736 | struct in_addr area_id; | |
737 | int format; | |
718e3744 | 738 | |
d62a17ae | 739 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
740 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); | |
718e3744 | 741 | |
d62a17ae | 742 | ospf_area_range_unset(ospf, area_id, &p); |
718e3744 | 743 | |
d62a17ae | 744 | return CMD_SUCCESS; |
718e3744 | 745 | } |
746 | ||
a2c62831 | 747 | DEFUN (ospf_area_range_substitute, |
748 | ospf_area_range_substitute_cmd, | |
6147e2c6 | 749 | "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M substitute A.B.C.D/M", |
718e3744 | 750 | "OSPF area parameters\n" |
751 | "OSPF area ID in IP address format\n" | |
752 | "OSPF area ID as a decimal value\n" | |
753 | "Summarize routes matching address/mask (border routers only)\n" | |
754 | "Area range prefix\n" | |
755 | "Announce area range as another prefix\n" | |
756 | "Network prefix to be announced instead of range\n") | |
757 | { | |
a3d826f0 | 758 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 759 | int idx_ipv4_number = 1; |
760 | int idx_ipv4_prefixlen = 3; | |
761 | int idx_ipv4_prefixlen_2 = 5; | |
762 | struct prefix_ipv4 p, s; | |
763 | struct in_addr area_id; | |
764 | int format; | |
718e3744 | 765 | |
d62a17ae | 766 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
767 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); | |
768 | str2prefix_ipv4(argv[idx_ipv4_prefixlen_2]->arg, &s); | |
718e3744 | 769 | |
d62a17ae | 770 | ospf_area_range_substitute_set(ospf, area_id, &p, &s); |
771 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
772 | format); | |
718e3744 | 773 | |
d62a17ae | 774 | return CMD_SUCCESS; |
718e3744 | 775 | } |
776 | ||
a2c62831 | 777 | DEFUN (no_ospf_area_range_substitute, |
778 | no_ospf_area_range_substitute_cmd, | |
6147e2c6 | 779 | "no area <A.B.C.D|(0-4294967295)> range A.B.C.D/M substitute A.B.C.D/M", |
718e3744 | 780 | NO_STR |
781 | "OSPF area parameters\n" | |
782 | "OSPF area ID in IP address format\n" | |
783 | "OSPF area ID as a decimal value\n" | |
784 | "Summarize routes matching address/mask (border routers only)\n" | |
785 | "Area range prefix\n" | |
786 | "Announce area range as another prefix\n" | |
787 | "Network prefix to be announced instead of range\n") | |
788 | { | |
a3d826f0 | 789 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 790 | int idx_ipv4_number = 2; |
791 | int idx_ipv4_prefixlen = 4; | |
792 | int idx_ipv4_prefixlen_2 = 6; | |
793 | struct prefix_ipv4 p, s; | |
794 | struct in_addr area_id; | |
795 | int format; | |
718e3744 | 796 | |
d62a17ae | 797 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
798 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); | |
799 | str2prefix_ipv4(argv[idx_ipv4_prefixlen_2]->arg, &s); | |
718e3744 | 800 | |
d62a17ae | 801 | ospf_area_range_substitute_unset(ospf, area_id, &p); |
718e3744 | 802 | |
d62a17ae | 803 | return CMD_SUCCESS; |
718e3744 | 804 | } |
805 | ||
6b0655a2 | 806 | |
718e3744 | 807 | /* Command Handler Logic in VLink stuff is delicate!! |
808 | ||
809 | ALTER AT YOUR OWN RISK!!!! | |
810 | ||
811 | Various dummy values are used to represent 'NoChange' state for | |
812 | VLink configuration NOT being changed by a VLink command, and | |
813 | special syntax is used within the command strings so that the | |
814 | typed in command verbs can be seen in the configuration command | |
815 | bacckend handler. This is to drastically reduce the verbeage | |
816 | required to coe up with a reasonably compatible Cisco VLink command | |
817 | ||
d62a17ae | 818 | - Matthew Grant <grantma@anathoth.gen.nz> |
718e3744 | 819 | Wed, 21 Feb 2001 15:13:52 +1300 |
820 | */ | |
821 | ||
d62a17ae | 822 | /* Configuration data for virtual links |
823 | */ | |
718e3744 | 824 | struct ospf_vl_config_data { |
d62a17ae | 825 | struct vty *vty; /* vty stuff */ |
826 | struct in_addr area_id; /* area ID from command line */ | |
827 | int area_id_fmt; /* command line area ID format */ | |
828 | struct in_addr vl_peer; /* command line vl_peer */ | |
829 | int auth_type; /* Authehntication type, if given */ | |
830 | char *auth_key; /* simple password if present */ | |
831 | int crypto_key_id; /* Cryptographic key ID */ | |
832 | char *md5_key; /* MD5 authentication key */ | |
833 | int hello_interval; /* Obvious what these are... */ | |
834 | int retransmit_interval; | |
835 | int transmit_delay; | |
836 | int dead_interval; | |
718e3744 | 837 | }; |
838 | ||
d62a17ae | 839 | static void ospf_vl_config_data_init(struct ospf_vl_config_data *vl_config, |
840 | struct vty *vty) | |
718e3744 | 841 | { |
d62a17ae | 842 | memset(vl_config, 0, sizeof(struct ospf_vl_config_data)); |
843 | vl_config->auth_type = OSPF_AUTH_CMD_NOTSEEN; | |
844 | vl_config->vty = vty; | |
718e3744 | 845 | } |
846 | ||
4dadc291 | 847 | static struct ospf_vl_data * |
d62a17ae | 848 | ospf_find_vl_data(struct ospf *ospf, struct ospf_vl_config_data *vl_config) |
849 | { | |
850 | struct ospf_area *area; | |
851 | struct ospf_vl_data *vl_data; | |
852 | struct vty *vty; | |
853 | struct in_addr area_id; | |
854 | ||
855 | vty = vl_config->vty; | |
856 | area_id = vl_config->area_id; | |
857 | ||
858 | if (area_id.s_addr == OSPF_AREA_BACKBONE) { | |
859 | vty_out(vty, | |
860 | "Configuring VLs over the backbone is not allowed\n"); | |
861 | return NULL; | |
862 | } | |
863 | area = ospf_area_get(ospf, area_id); | |
864 | ospf_area_display_format_set(ospf, area, vl_config->area_id_fmt); | |
865 | ||
866 | if (area->external_routing != OSPF_AREA_DEFAULT) { | |
867 | if (vl_config->area_id_fmt == OSPF_AREA_ID_FMT_DOTTEDQUAD) | |
96b663a3 | 868 | vty_out(vty, "Area %pI4 is %s\n", &area_id, |
d62a17ae | 869 | area->external_routing == OSPF_AREA_NSSA |
870 | ? "nssa" | |
871 | : "stub"); | |
872 | else | |
873 | vty_out(vty, "Area %ld is %s\n", | |
d7c0a89a | 874 | (unsigned long)ntohl(area_id.s_addr), |
d62a17ae | 875 | area->external_routing == OSPF_AREA_NSSA |
876 | ? "nssa" | |
877 | : "stub"); | |
878 | return NULL; | |
879 | } | |
880 | ||
881 | if ((vl_data = ospf_vl_lookup(ospf, area, vl_config->vl_peer)) | |
882 | == NULL) { | |
883 | vl_data = ospf_vl_data_new(area, vl_config->vl_peer); | |
884 | if (vl_data->vl_oi == NULL) { | |
885 | vl_data->vl_oi = ospf_vl_new(ospf, vl_data); | |
886 | ospf_vl_add(ospf, vl_data); | |
887 | ospf_spf_calculate_schedule(ospf, | |
888 | SPF_FLAG_CONFIG_CHANGE); | |
889 | } | |
718e3744 | 890 | } |
d62a17ae | 891 | return vl_data; |
718e3744 | 892 | } |
893 | ||
894 | ||
d62a17ae | 895 | static int ospf_vl_set_security(struct ospf_vl_data *vl_data, |
896 | struct ospf_vl_config_data *vl_config) | |
897 | { | |
898 | struct crypt_key *ck; | |
899 | struct vty *vty; | |
900 | struct interface *ifp = vl_data->vl_oi->ifp; | |
901 | ||
902 | vty = vl_config->vty; | |
903 | ||
904 | if (vl_config->auth_type != OSPF_AUTH_CMD_NOTSEEN) { | |
905 | SET_IF_PARAM(IF_DEF_PARAMS(ifp), auth_type); | |
906 | IF_DEF_PARAMS(ifp)->auth_type = vl_config->auth_type; | |
718e3744 | 907 | } |
718e3744 | 908 | |
d62a17ae | 909 | if (vl_config->auth_key) { |
910 | memset(IF_DEF_PARAMS(ifp)->auth_simple, 0, | |
911 | OSPF_AUTH_SIMPLE_SIZE + 1); | |
4d65d927 QY |
912 | strlcpy((char *)IF_DEF_PARAMS(ifp)->auth_simple, |
913 | vl_config->auth_key, | |
914 | sizeof(IF_DEF_PARAMS(ifp)->auth_simple)); | |
d62a17ae | 915 | } else if (vl_config->md5_key) { |
916 | if (ospf_crypt_key_lookup(IF_DEF_PARAMS(ifp)->auth_crypt, | |
917 | vl_config->crypto_key_id) | |
918 | != NULL) { | |
919 | vty_out(vty, "OSPF: Key %d already exists\n", | |
920 | vl_config->crypto_key_id); | |
851fcbae | 921 | return CMD_WARNING; |
d62a17ae | 922 | } |
923 | ck = ospf_crypt_key_new(); | |
924 | ck->key_id = vl_config->crypto_key_id; | |
925 | memset(ck->auth_key, 0, OSPF_AUTH_MD5_SIZE + 1); | |
4d65d927 QY |
926 | strlcpy((char *)ck->auth_key, vl_config->md5_key, |
927 | sizeof(ck->auth_key)); | |
d62a17ae | 928 | |
929 | ospf_crypt_key_add(IF_DEF_PARAMS(ifp)->auth_crypt, ck); | |
930 | } else if (vl_config->crypto_key_id != 0) { | |
931 | /* Delete a key */ | |
932 | ||
933 | if (ospf_crypt_key_lookup(IF_DEF_PARAMS(ifp)->auth_crypt, | |
934 | vl_config->crypto_key_id) | |
935 | == NULL) { | |
936 | vty_out(vty, "OSPF: Key %d does not exist\n", | |
937 | vl_config->crypto_key_id); | |
938 | return CMD_WARNING_CONFIG_FAILED; | |
939 | } | |
940 | ||
941 | ospf_crypt_key_delete(IF_DEF_PARAMS(ifp)->auth_crypt, | |
942 | vl_config->crypto_key_id); | |
943 | } | |
944 | ||
945 | return CMD_SUCCESS; | |
718e3744 | 946 | } |
947 | ||
d62a17ae | 948 | static int ospf_vl_set_timers(struct ospf_vl_data *vl_data, |
949 | struct ospf_vl_config_data *vl_config) | |
950 | { | |
951 | struct interface *ifp = vl_data->vl_oi->ifp; | |
952 | /* Virtual Link data initialised to defaults, so only set | |
953 | if a value given */ | |
954 | if (vl_config->hello_interval) { | |
955 | SET_IF_PARAM(IF_DEF_PARAMS(ifp), v_hello); | |
956 | IF_DEF_PARAMS(ifp)->v_hello = vl_config->hello_interval; | |
957 | } | |
958 | ||
959 | if (vl_config->dead_interval) { | |
960 | SET_IF_PARAM(IF_DEF_PARAMS(ifp), v_wait); | |
961 | IF_DEF_PARAMS(ifp)->v_wait = vl_config->dead_interval; | |
962 | } | |
963 | ||
964 | if (vl_config->retransmit_interval) { | |
965 | SET_IF_PARAM(IF_DEF_PARAMS(ifp), retransmit_interval); | |
966 | IF_DEF_PARAMS(ifp)->retransmit_interval = | |
967 | vl_config->retransmit_interval; | |
968 | } | |
969 | ||
970 | if (vl_config->transmit_delay) { | |
971 | SET_IF_PARAM(IF_DEF_PARAMS(ifp), transmit_delay); | |
972 | IF_DEF_PARAMS(ifp)->transmit_delay = vl_config->transmit_delay; | |
973 | } | |
974 | ||
975 | return CMD_SUCCESS; | |
718e3744 | 976 | } |
977 | ||
978 | ||
718e3744 | 979 | /* The business end of all of the above */ |
d62a17ae | 980 | static int ospf_vl_set(struct ospf *ospf, struct ospf_vl_config_data *vl_config) |
981 | { | |
982 | struct ospf_vl_data *vl_data; | |
983 | int ret; | |
718e3744 | 984 | |
d62a17ae | 985 | vl_data = ospf_find_vl_data(ospf, vl_config); |
986 | if (!vl_data) | |
987 | return CMD_WARNING_CONFIG_FAILED; | |
988 | ||
989 | /* Process this one first as it can have a fatal result, which can | |
990 | only logically occur if the virtual link exists already | |
991 | Thus a command error does not result in a change to the | |
992 | running configuration such as unexpectedly altered timer | |
993 | values etc.*/ | |
994 | ret = ospf_vl_set_security(vl_data, vl_config); | |
995 | if (ret != CMD_SUCCESS) | |
996 | return ret; | |
997 | ||
998 | /* Set any time based parameters, these area already range checked */ | |
999 | ||
1000 | ret = ospf_vl_set_timers(vl_data, vl_config); | |
1001 | if (ret != CMD_SUCCESS) | |
1002 | return ret; | |
718e3744 | 1003 | |
d62a17ae | 1004 | return CMD_SUCCESS; |
718e3744 | 1005 | } |
1006 | ||
1007 | /* This stuff exists to make specifying all the alias commands A LOT simpler | |
1008 | */ | |
d62a17ae | 1009 | #define VLINK_HELPSTR_IPADDR \ |
1010 | "OSPF area parameters\n" \ | |
1011 | "OSPF area ID in IP address format\n" \ | |
1012 | "OSPF area ID as a decimal value\n" \ | |
1013 | "Configure a virtual link\n" \ | |
1014 | "Router ID of the remote ABR\n" | |
1015 | ||
1016 | #define VLINK_HELPSTR_AUTHTYPE_SIMPLE \ | |
1017 | "Enable authentication on this virtual link\n" \ | |
1018 | "dummy string \n" | |
1019 | ||
1020 | #define VLINK_HELPSTR_AUTHTYPE_ALL \ | |
1021 | VLINK_HELPSTR_AUTHTYPE_SIMPLE \ | |
1022 | "Use null authentication\n" \ | |
1023 | "Use message-digest authentication\n" | |
1024 | ||
1025 | #define VLINK_HELPSTR_TIME_PARAM \ | |
1026 | "Time between HELLO packets\n" \ | |
1027 | "Seconds\n" \ | |
1028 | "Time between retransmitting lost link state advertisements\n" \ | |
1029 | "Seconds\n" \ | |
1030 | "Link state transmit delay\n" \ | |
1031 | "Seconds\n" \ | |
1032 | "Interval time after which a neighbor is declared down\n" \ | |
1033 | "Seconds\n" | |
1034 | ||
1035 | #define VLINK_HELPSTR_AUTH_SIMPLE \ | |
1036 | "Authentication password (key)\n" \ | |
baf9eaad | 1037 | "The OSPF password (key)\n" |
d62a17ae | 1038 | |
1039 | #define VLINK_HELPSTR_AUTH_MD5 \ | |
1040 | "Message digest authentication password (key)\n" \ | |
d62a17ae | 1041 | "Key ID\n" \ |
1042 | "Use MD5 algorithm\n" \ | |
baf9eaad | 1043 | "The OSPF password (key)\n" |
718e3744 | 1044 | |
a2c62831 | 1045 | DEFUN (ospf_area_vlink, |
1046 | ospf_area_vlink_cmd, | |
3d1c6dc2 | 1047 | "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 | 1048 | VLINK_HELPSTR_IPADDR |
3d1c6dc2 | 1049 | "Enable authentication on this virtual link\n" |
7a7be519 | 1050 | "Use message-digest authentication\n" |
3d1c6dc2 | 1051 | "Use null authentication\n" |
baf9eaad CS |
1052 | VLINK_HELPSTR_AUTH_MD5 |
1053 | VLINK_HELPSTR_AUTH_SIMPLE) | |
718e3744 | 1054 | { |
a3d826f0 | 1055 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1056 | int idx_ipv4_number = 1; |
1057 | int idx_ipv4 = 3; | |
1058 | struct ospf_vl_config_data vl_config; | |
1059 | char auth_key[OSPF_AUTH_SIMPLE_SIZE + 1]; | |
1060 | char md5_key[OSPF_AUTH_MD5_SIZE + 1]; | |
d62a17ae | 1061 | int ret; |
55d1da24 | 1062 | int idx = 0; |
d62a17ae | 1063 | |
1064 | ospf_vl_config_data_init(&vl_config, vty); | |
1065 | ||
1066 | /* Read off first 2 parameters and check them */ | |
1067 | ret = str2area_id(argv[idx_ipv4_number]->arg, &vl_config.area_id, | |
1068 | &vl_config.area_id_fmt); | |
1069 | if (ret < 0) { | |
1070 | vty_out(vty, "OSPF area ID is invalid\n"); | |
1071 | return CMD_WARNING_CONFIG_FAILED; | |
1072 | } | |
718e3744 | 1073 | |
d62a17ae | 1074 | ret = inet_aton(argv[idx_ipv4]->arg, &vl_config.vl_peer); |
1075 | if (!ret) { | |
1076 | vty_out(vty, "Please specify valid Router ID as a.b.c.d\n"); | |
1077 | return CMD_WARNING_CONFIG_FAILED; | |
7a7be519 | 1078 | } |
7a7be519 | 1079 | |
d62a17ae | 1080 | if (argc <= 4) { |
1081 | /* Thats all folks! - BUGS B. strikes again!!!*/ | |
7a7be519 | 1082 | |
d62a17ae | 1083 | return ospf_vl_set(ospf, &vl_config); |
1084 | } | |
1085 | ||
3d1c6dc2 CS |
1086 | if (argv_find(argv, argc, "authentication", &idx)) { |
1087 | /* authentication - this option can only occur | |
1088 | at start of command line */ | |
1089 | vl_config.auth_type = OSPF_AUTH_SIMPLE; | |
1090 | } | |
1091 | ||
3d1c6dc2 | 1092 | if (argv_find(argv, argc, "message-digest", &idx)) { |
baf9eaad | 1093 | /* authentication message-digest */ |
3d1c6dc2 CS |
1094 | vl_config.auth_type = OSPF_AUTH_CRYPTOGRAPHIC; |
1095 | } else if (argv_find(argv, argc, "null", &idx)) { | |
1096 | /* "authentication null" */ | |
1097 | vl_config.auth_type = OSPF_AUTH_NULL; | |
d62a17ae | 1098 | } |
7a7be519 | 1099 | |
3d1c6dc2 | 1100 | if (argv_find(argv, argc, "message-digest-key", &idx)) { |
3d1c6dc2 | 1101 | vl_config.md5_key = NULL; |
cbb9b53d | 1102 | vl_config.crypto_key_id = strtol(argv[idx + 1]->arg, NULL, 10); |
3d1c6dc2 CS |
1103 | if (vl_config.crypto_key_id < 0) |
1104 | return CMD_WARNING_CONFIG_FAILED; | |
1105 | ||
4d65d927 | 1106 | strlcpy(md5_key, argv[idx + 3]->arg, sizeof(md5_key)); |
3d1c6dc2 CS |
1107 | vl_config.md5_key = md5_key; |
1108 | } | |
1109 | ||
3d1c6dc2 | 1110 | if (argv_find(argv, argc, "authentication-key", &idx)) { |
4d65d927 | 1111 | strlcpy(auth_key, argv[idx + 1]->arg, sizeof(auth_key)); |
3d1c6dc2 CS |
1112 | vl_config.auth_key = auth_key; |
1113 | } | |
7a7be519 | 1114 | |
d62a17ae | 1115 | /* Action configuration */ |
1116 | ||
1117 | return ospf_vl_set(ospf, &vl_config); | |
7a7be519 | 1118 | } |
1119 | ||
a2c62831 | 1120 | DEFUN (no_ospf_area_vlink, |
1121 | no_ospf_area_vlink_cmd, | |
3d1c6dc2 | 1122 | "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 | 1123 | NO_STR |
7a7be519 | 1124 | VLINK_HELPSTR_IPADDR |
7e5ee522 IR |
1125 | "Enable authentication on this virtual link\n" |
1126 | "Use message-digest authentication\n" | |
1127 | "Use null authentication\n" | |
baf9eaad CS |
1128 | VLINK_HELPSTR_AUTH_MD5 |
1129 | VLINK_HELPSTR_AUTH_SIMPLE) | |
718e3744 | 1130 | { |
a3d826f0 | 1131 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1132 | int idx_ipv4_number = 2; |
1133 | int idx_ipv4 = 4; | |
1134 | struct ospf_area *area; | |
1135 | struct ospf_vl_config_data vl_config; | |
1136 | struct ospf_vl_data *vl_data = NULL; | |
1137 | char auth_key[OSPF_AUTH_SIMPLE_SIZE + 1]; | |
3d1c6dc2 | 1138 | int idx = 0; |
d62a17ae | 1139 | int ret, format; |
1140 | ||
1141 | ospf_vl_config_data_init(&vl_config, vty); | |
1142 | ||
1143 | ret = str2area_id(argv[idx_ipv4_number]->arg, &vl_config.area_id, | |
1144 | &format); | |
1145 | if (ret < 0) { | |
1146 | vty_out(vty, "OSPF area ID is invalid\n"); | |
1147 | return CMD_WARNING_CONFIG_FAILED; | |
1148 | } | |
1149 | ||
1150 | area = ospf_area_lookup_by_area_id(ospf, vl_config.area_id); | |
1151 | if (!area) { | |
1152 | vty_out(vty, "Area does not exist\n"); | |
1153 | return CMD_WARNING_CONFIG_FAILED; | |
1154 | } | |
1155 | ||
1156 | ret = inet_aton(argv[idx_ipv4]->arg, &vl_config.vl_peer); | |
1157 | if (!ret) { | |
1158 | vty_out(vty, "Please specify valid Router ID as a.b.c.d\n"); | |
1159 | return CMD_WARNING_CONFIG_FAILED; | |
1160 | } | |
718e3744 | 1161 | |
188823b0 EDP |
1162 | vl_data = ospf_vl_lookup(ospf, area, vl_config.vl_peer); |
1163 | if (!vl_data) { | |
1164 | vty_out(vty, "Virtual link does not exist\n"); | |
1165 | return CMD_WARNING_CONFIG_FAILED; | |
1166 | } | |
1167 | ||
d62a17ae | 1168 | if (argc <= 5) { |
1169 | /* Basic VLink no command */ | |
1170 | /* Thats all folks! - BUGS B. strikes again!!!*/ | |
188823b0 | 1171 | ospf_vl_delete(ospf, vl_data); |
d62a17ae | 1172 | ospf_area_check_free(ospf, vl_config.area_id); |
d62a17ae | 1173 | return CMD_SUCCESS; |
1174 | } | |
1175 | ||
1176 | /* If we are down here, we are reseting parameters */ | |
d62a17ae | 1177 | /* Deal with other parameters */ |
3d1c6dc2 CS |
1178 | |
1179 | if (argv_find(argv, argc, "authentication", &idx)) { | |
1180 | /* authentication - this option can only occur | |
1181 | at start of command line */ | |
1182 | vl_config.auth_type = OSPF_AUTH_NOTSET; | |
1183 | } | |
1184 | ||
3d1c6dc2 | 1185 | if (argv_find(argv, argc, "message-digest-key", &idx)) { |
3d1c6dc2 | 1186 | vl_config.md5_key = NULL; |
cbb9b53d | 1187 | vl_config.crypto_key_id = strtol(argv[idx + 1]->arg, NULL, 10); |
3d1c6dc2 CS |
1188 | if (vl_config.crypto_key_id < 0) |
1189 | return CMD_WARNING_CONFIG_FAILED; | |
d62a17ae | 1190 | } |
1191 | ||
3d1c6dc2 | 1192 | if (argv_find(argv, argc, "authentication-key", &idx)) { |
cbb9b53d | 1193 | /* Reset authentication-key to 0 */ |
3d1c6dc2 CS |
1194 | memset(auth_key, 0, OSPF_AUTH_SIMPLE_SIZE + 1); |
1195 | vl_config.auth_key = auth_key; | |
1196 | } | |
d62a17ae | 1197 | |
1198 | /* Action configuration */ | |
1199 | ||
1200 | return ospf_vl_set(ospf, &vl_config); | |
7a7be519 | 1201 | } |
1202 | ||
b1c02cec QY |
1203 | DEFUN (ospf_area_vlink_intervals, |
1204 | ospf_area_vlink_intervals_cmd, | |
1205 | "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)}", | |
1206 | VLINK_HELPSTR_IPADDR | |
1207 | VLINK_HELPSTR_TIME_PARAM) | |
1208 | { | |
a3d826f0 | 1209 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1210 | struct ospf_vl_config_data vl_config; |
1211 | int ret = 0; | |
1212 | ||
1213 | ospf_vl_config_data_init(&vl_config, vty); | |
1214 | ||
1215 | char *area_id = argv[1]->arg; | |
1216 | char *router_id = argv[3]->arg; | |
1217 | ||
1218 | ret = str2area_id(area_id, &vl_config.area_id, &vl_config.area_id_fmt); | |
1219 | if (ret < 0) { | |
1220 | vty_out(vty, "OSPF area ID is invalid\n"); | |
1221 | return CMD_WARNING_CONFIG_FAILED; | |
1222 | } | |
1223 | ||
1224 | ret = inet_aton(router_id, &vl_config.vl_peer); | |
1225 | if (!ret) { | |
1226 | vty_out(vty, "Please specify valid Router ID as a.b.c.d\n"); | |
1227 | return CMD_WARNING_CONFIG_FAILED; | |
1228 | } | |
1229 | ||
1230 | for (int idx = 4; idx < argc; idx++) { | |
1231 | if (strmatch(argv[idx]->text, "hello-interval")) | |
1232 | vl_config.hello_interval = | |
1233 | strtol(argv[++idx]->arg, NULL, 10); | |
1234 | else if (strmatch(argv[idx]->text, "retransmit-interval")) | |
1235 | vl_config.retransmit_interval = | |
1236 | strtol(argv[++idx]->arg, NULL, 10); | |
1237 | else if (strmatch(argv[idx]->text, "transmit-delay")) | |
1238 | vl_config.transmit_delay = | |
1239 | strtol(argv[++idx]->arg, NULL, 10); | |
1240 | else if (strmatch(argv[idx]->text, "dead-interval")) | |
1241 | vl_config.dead_interval = | |
1242 | strtol(argv[++idx]->arg, NULL, 10); | |
1243 | } | |
1244 | ||
1245 | /* Action configuration */ | |
1246 | return ospf_vl_set(ospf, &vl_config); | |
b1c02cec QY |
1247 | } |
1248 | ||
7a7be519 | 1249 | DEFUN (no_ospf_area_vlink_intervals, |
1250 | no_ospf_area_vlink_intervals_cmd, | |
a663a38e | 1251 | "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 | 1252 | NO_STR |
7a7be519 | 1253 | VLINK_HELPSTR_IPADDR |
7a7be519 | 1254 | VLINK_HELPSTR_TIME_PARAM) |
1255 | { | |
a3d826f0 | 1256 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1257 | struct ospf_vl_config_data vl_config; |
1258 | int ret = 0; | |
1259 | ||
1260 | ospf_vl_config_data_init(&vl_config, vty); | |
1261 | ||
1262 | char *area_id = argv[2]->arg; | |
1263 | char *router_id = argv[4]->arg; | |
1264 | ||
1265 | ret = str2area_id(area_id, &vl_config.area_id, &vl_config.area_id_fmt); | |
1266 | if (ret < 0) { | |
1267 | vty_out(vty, "OSPF area ID is invalid\n"); | |
1268 | return CMD_WARNING_CONFIG_FAILED; | |
1269 | } | |
1270 | ||
1271 | ret = inet_aton(router_id, &vl_config.vl_peer); | |
1272 | if (!ret) { | |
1273 | vty_out(vty, "Please specify valid Router ID as a.b.c.d\n"); | |
1274 | return CMD_WARNING_CONFIG_FAILED; | |
1275 | } | |
1276 | ||
1277 | for (int idx = 5; idx < argc; idx++) { | |
1278 | if (strmatch(argv[idx]->text, "hello-interval")) | |
1279 | vl_config.hello_interval = OSPF_HELLO_INTERVAL_DEFAULT; | |
1280 | else if (strmatch(argv[idx]->text, "retransmit-interval")) | |
1281 | vl_config.retransmit_interval = | |
1282 | OSPF_RETRANSMIT_INTERVAL_DEFAULT; | |
1283 | else if (strmatch(argv[idx]->text, "transmit-delay")) | |
1284 | vl_config.transmit_delay = OSPF_TRANSMIT_DELAY_DEFAULT; | |
1285 | else if (strmatch(argv[idx]->text, "dead-interval")) | |
1286 | vl_config.dead_interval = | |
1287 | OSPF_ROUTER_DEAD_INTERVAL_DEFAULT; | |
1288 | } | |
1289 | ||
1290 | /* Action configuration */ | |
1291 | return ospf_vl_set(ospf, &vl_config); | |
718e3744 | 1292 | } |
1293 | ||
a2c62831 | 1294 | DEFUN (ospf_area_shortcut, |
1295 | ospf_area_shortcut_cmd, | |
6147e2c6 | 1296 | "area <A.B.C.D|(0-4294967295)> shortcut <default|enable|disable>", |
718e3744 | 1297 | "OSPF area parameters\n" |
1298 | "OSPF area ID in IP address format\n" | |
1299 | "OSPF area ID as a decimal value\n" | |
1300 | "Configure the area's shortcutting mode\n" | |
1301 | "Set default shortcutting behavior\n" | |
1302 | "Enable shortcutting through the area\n" | |
1303 | "Disable shortcutting through the area\n") | |
1304 | { | |
a3d826f0 | 1305 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1306 | int idx_ipv4_number = 1; |
1307 | int idx_enable_disable = 3; | |
1308 | struct ospf_area *area; | |
1309 | struct in_addr area_id; | |
1310 | int mode; | |
1311 | int format; | |
1312 | ||
1313 | VTY_GET_OSPF_AREA_ID_NO_BB("shortcut", area_id, format, | |
1314 | argv[idx_ipv4_number]->arg); | |
1315 | ||
1316 | area = ospf_area_get(ospf, area_id); | |
1317 | ospf_area_display_format_set(ospf, area, format); | |
1318 | ||
1319 | if (strncmp(argv[idx_enable_disable]->arg, "de", 2) == 0) | |
1320 | mode = OSPF_SHORTCUT_DEFAULT; | |
1321 | else if (strncmp(argv[idx_enable_disable]->arg, "di", 2) == 0) | |
1322 | mode = OSPF_SHORTCUT_DISABLE; | |
1323 | else if (strncmp(argv[idx_enable_disable]->arg, "e", 1) == 0) | |
1324 | mode = OSPF_SHORTCUT_ENABLE; | |
1325 | else | |
1326 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 1327 | |
d62a17ae | 1328 | ospf_area_shortcut_set(ospf, area, mode); |
718e3744 | 1329 | |
d62a17ae | 1330 | if (ospf->abr_type != OSPF_ABR_SHORTCUT) |
1331 | vty_out(vty, | |
3efd0893 | 1332 | "Shortcut area setting will take effect only when the router is configured as Shortcut ABR\n"); |
718e3744 | 1333 | |
d62a17ae | 1334 | return CMD_SUCCESS; |
718e3744 | 1335 | } |
1336 | ||
a2c62831 | 1337 | DEFUN (no_ospf_area_shortcut, |
1338 | no_ospf_area_shortcut_cmd, | |
6147e2c6 | 1339 | "no area <A.B.C.D|(0-4294967295)> shortcut <enable|disable>", |
718e3744 | 1340 | NO_STR |
1341 | "OSPF area parameters\n" | |
1342 | "OSPF area ID in IP address format\n" | |
1343 | "OSPF area ID as a decimal value\n" | |
1344 | "Deconfigure the area's shortcutting mode\n" | |
1345 | "Deconfigure enabled shortcutting through the area\n" | |
1346 | "Deconfigure disabled shortcutting through the area\n") | |
1347 | { | |
a3d826f0 | 1348 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1349 | int idx_ipv4_number = 2; |
1350 | struct ospf_area *area; | |
1351 | struct in_addr area_id; | |
1352 | int format; | |
718e3744 | 1353 | |
d62a17ae | 1354 | VTY_GET_OSPF_AREA_ID_NO_BB("shortcut", area_id, format, |
1355 | argv[idx_ipv4_number]->arg); | |
718e3744 | 1356 | |
d62a17ae | 1357 | area = ospf_area_lookup_by_area_id(ospf, area_id); |
1358 | if (!area) | |
1359 | return CMD_SUCCESS; | |
718e3744 | 1360 | |
d62a17ae | 1361 | ospf_area_shortcut_unset(ospf, area); |
718e3744 | 1362 | |
d62a17ae | 1363 | return CMD_SUCCESS; |
718e3744 | 1364 | } |
1365 | ||
6b0655a2 | 1366 | |
a2c62831 | 1367 | DEFUN (ospf_area_stub, |
1368 | ospf_area_stub_cmd, | |
6147e2c6 | 1369 | "area <A.B.C.D|(0-4294967295)> stub", |
718e3744 | 1370 | "OSPF area parameters\n" |
1371 | "OSPF area ID in IP address format\n" | |
1372 | "OSPF area ID as a decimal value\n" | |
1373 | "Configure OSPF area as stub\n") | |
1374 | { | |
a3d826f0 | 1375 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1376 | int idx_ipv4_number = 1; |
1377 | struct in_addr area_id; | |
1378 | int ret, format; | |
1379 | ||
1380 | VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id, format, | |
1381 | argv[idx_ipv4_number]->arg); | |
1382 | ||
1383 | ret = ospf_area_stub_set(ospf, area_id); | |
1384 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
1385 | format); | |
1386 | if (ret == 0) { | |
1387 | vty_out(vty, | |
1388 | "First deconfigure all virtual link through this area\n"); | |
1389 | return CMD_WARNING_CONFIG_FAILED; | |
1390 | } | |
718e3744 | 1391 | |
44445dee S |
1392 | /* Flush the external LSAs from the specified area */ |
1393 | ospf_flush_lsa_from_area(ospf, area_id, OSPF_AS_EXTERNAL_LSA); | |
d62a17ae | 1394 | ospf_area_no_summary_unset(ospf, area_id); |
718e3744 | 1395 | |
d62a17ae | 1396 | return CMD_SUCCESS; |
718e3744 | 1397 | } |
1398 | ||
a2c62831 | 1399 | DEFUN (ospf_area_stub_no_summary, |
1400 | ospf_area_stub_no_summary_cmd, | |
6147e2c6 | 1401 | "area <A.B.C.D|(0-4294967295)> stub no-summary", |
718e3744 | 1402 | "OSPF stub parameters\n" |
1403 | "OSPF area ID in IP address format\n" | |
1404 | "OSPF area ID as a decimal value\n" | |
1405 | "Configure OSPF area as stub\n" | |
1406 | "Do not inject inter-area routes into stub\n") | |
1407 | { | |
a3d826f0 | 1408 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1409 | int idx_ipv4_number = 1; |
1410 | struct in_addr area_id; | |
1411 | int ret, format; | |
1412 | ||
1413 | VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id, format, | |
1414 | argv[idx_ipv4_number]->arg); | |
1415 | ||
1416 | ret = ospf_area_stub_set(ospf, area_id); | |
1417 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
1418 | format); | |
1419 | if (ret == 0) { | |
1420 | vty_out(vty, | |
1421 | "%% Area cannot be stub as it contains a virtual link\n"); | |
1422 | return CMD_WARNING_CONFIG_FAILED; | |
1423 | } | |
718e3744 | 1424 | |
d62a17ae | 1425 | ospf_area_no_summary_set(ospf, area_id); |
718e3744 | 1426 | |
d62a17ae | 1427 | return CMD_SUCCESS; |
718e3744 | 1428 | } |
1429 | ||
a2c62831 | 1430 | DEFUN (no_ospf_area_stub, |
1431 | no_ospf_area_stub_cmd, | |
6147e2c6 | 1432 | "no area <A.B.C.D|(0-4294967295)> stub", |
718e3744 | 1433 | NO_STR |
1434 | "OSPF area parameters\n" | |
1435 | "OSPF area ID in IP address format\n" | |
1436 | "OSPF area ID as a decimal value\n" | |
1437 | "Configure OSPF area as stub\n") | |
1438 | { | |
a3d826f0 | 1439 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1440 | int idx_ipv4_number = 2; |
1441 | struct in_addr area_id; | |
1442 | int format; | |
718e3744 | 1443 | |
d62a17ae | 1444 | VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id, format, |
1445 | argv[idx_ipv4_number]->arg); | |
718e3744 | 1446 | |
d62a17ae | 1447 | ospf_area_stub_unset(ospf, area_id); |
1448 | ospf_area_no_summary_unset(ospf, area_id); | |
718e3744 | 1449 | |
d62a17ae | 1450 | return CMD_SUCCESS; |
718e3744 | 1451 | } |
1452 | ||
a2c62831 | 1453 | DEFUN (no_ospf_area_stub_no_summary, |
1454 | no_ospf_area_stub_no_summary_cmd, | |
6147e2c6 | 1455 | "no area <A.B.C.D|(0-4294967295)> stub no-summary", |
718e3744 | 1456 | NO_STR |
1457 | "OSPF area parameters\n" | |
1458 | "OSPF area ID in IP address format\n" | |
1459 | "OSPF area ID as a decimal value\n" | |
1460 | "Configure OSPF area as stub\n" | |
1461 | "Do not inject inter-area routes into area\n") | |
1462 | { | |
a3d826f0 | 1463 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1464 | int idx_ipv4_number = 2; |
1465 | struct in_addr area_id; | |
1466 | int format; | |
718e3744 | 1467 | |
d62a17ae | 1468 | VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id, format, |
1469 | argv[idx_ipv4_number]->arg); | |
1470 | ospf_area_no_summary_unset(ospf, area_id); | |
718e3744 | 1471 | |
d62a17ae | 1472 | return CMD_SUCCESS; |
718e3744 | 1473 | } |
1474 | ||
d62a17ae | 1475 | static int ospf_area_nssa_cmd_handler(struct vty *vty, int argc, |
7ef56a73 CS |
1476 | struct cmd_token **argv, int cfg_nosum, |
1477 | int nosum) | |
718e3744 | 1478 | { |
a3d826f0 | 1479 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1480 | struct in_addr area_id; |
1481 | int ret, format; | |
1482 | ||
1483 | VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id, format, argv[1]->arg); | |
1484 | ||
1485 | ret = ospf_area_nssa_set(ospf, area_id); | |
1486 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
1487 | format); | |
1488 | if (ret == 0) { | |
1489 | vty_out(vty, | |
1490 | "%% Area cannot be nssa as it contains a virtual link\n"); | |
1491 | return CMD_WARNING_CONFIG_FAILED; | |
1492 | } | |
1493 | ||
1494 | if (argc > 3) { | |
1495 | if (strncmp(argv[3]->text, "translate-c", 11) == 0) | |
1496 | ospf_area_nssa_translator_role_set( | |
1497 | ospf, area_id, OSPF_NSSA_ROLE_CANDIDATE); | |
1498 | else if (strncmp(argv[3]->text, "translate-n", 11) == 0) | |
1499 | ospf_area_nssa_translator_role_set( | |
1500 | ospf, area_id, OSPF_NSSA_ROLE_NEVER); | |
1501 | else if (strncmp(argv[3]->text, "translate-a", 11) == 0) | |
1502 | ospf_area_nssa_translator_role_set( | |
1503 | ospf, area_id, OSPF_NSSA_ROLE_ALWAYS); | |
1504 | } else { | |
1505 | ospf_area_nssa_translator_role_set(ospf, area_id, | |
1506 | OSPF_NSSA_ROLE_CANDIDATE); | |
1507 | } | |
1508 | ||
7ef56a73 CS |
1509 | if (cfg_nosum) { |
1510 | if (nosum) | |
1511 | ospf_area_no_summary_set(ospf, area_id); | |
1512 | else | |
1513 | ospf_area_no_summary_unset(ospf, area_id); | |
1514 | } | |
d62a17ae | 1515 | |
44445dee S |
1516 | /* Flush the external LSA for the specified area */ |
1517 | ospf_flush_lsa_from_area(ospf, area_id, OSPF_AS_EXTERNAL_LSA); | |
d62a17ae | 1518 | ospf_schedule_abr_task(ospf); |
1c1c342d | 1519 | ospf_schedule_asbr_nssa_redist_update(ospf); |
d62a17ae | 1520 | |
1521 | return CMD_SUCCESS; | |
718e3744 | 1522 | } |
1523 | ||
718e3744 | 1524 | |
b0a053be | 1525 | DEFUN (ospf_area_nssa_translate, |
a2c62831 | 1526 | ospf_area_nssa_translate_cmd, |
6147e2c6 | 1527 | "area <A.B.C.D|(0-4294967295)> nssa <translate-candidate|translate-never|translate-always>", |
718e3744 | 1528 | "OSPF area parameters\n" |
1529 | "OSPF area ID in IP address format\n" | |
1530 | "OSPF area ID as a decimal value\n" | |
1531 | "Configure OSPF area as nssa\n" | |
1532 | "Configure NSSA-ABR for translate election (default)\n" | |
1533 | "Configure NSSA-ABR to never translate\n" | |
1534 | "Configure NSSA-ABR to always translate\n") | |
b0a053be | 1535 | { |
7ef56a73 | 1536 | return ospf_area_nssa_cmd_handler(vty, argc, argv, 0, 0); |
b0a053be | 1537 | } |
1538 | ||
1539 | DEFUN (ospf_area_nssa, | |
1540 | ospf_area_nssa_cmd, | |
6147e2c6 | 1541 | "area <A.B.C.D|(0-4294967295)> nssa", |
b0a053be | 1542 | "OSPF area parameters\n" |
1543 | "OSPF area ID in IP address format\n" | |
1544 | "OSPF area ID as a decimal value\n" | |
1545 | "Configure OSPF area as nssa\n") | |
1546 | { | |
2643b2bc | 1547 | return ospf_area_nssa_cmd_handler(vty, argc, argv, 0, 0); |
b0a053be | 1548 | } |
718e3744 | 1549 | |
c317eddb | 1550 | DEFUN(ospf_area_nssa_suppress_fa, ospf_area_nssa_suppress_fa_cmd, |
1551 | "area <A.B.C.D|(0-4294967295)> nssa suppress-fa", | |
1552 | "OSPF area parameters\n" | |
1553 | "OSPF area ID in IP address format\n" | |
1554 | "OSPF area ID as a decimal value\n" | |
1555 | "Configure OSPF area as nssa\n" | |
1556 | "Suppress forwarding address\n") | |
1557 | { | |
1558 | int idx_ipv4_number = 1; | |
1559 | struct in_addr area_id; | |
1560 | int format; | |
1561 | ||
1562 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
1563 | VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id, format, | |
1564 | argv[idx_ipv4_number]->arg); | |
1565 | ||
1566 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
1567 | format); | |
1568 | ospf_area_nssa_suppress_fa_set(ospf, area_id); | |
1569 | ||
1570 | ospf_schedule_abr_task(ospf); | |
1571 | ||
1572 | return CMD_SUCCESS; | |
1573 | } | |
1574 | ||
1575 | DEFUN(no_ospf_area_nssa_suppress_fa, no_ospf_area_nssa_suppress_fa_cmd, | |
1576 | "no area <A.B.C.D|(0-4294967295)> nssa suppress-fa", | |
1577 | NO_STR | |
1578 | "OSPF area parameters\n" | |
1579 | "OSPF area ID in IP address format\n" | |
1580 | "OSPF area ID as a decimal value\n" | |
1581 | "Configure OSPF area as nssa\n" | |
1582 | "Suppress forwarding address\n") | |
1583 | { | |
1584 | int idx_ipv4_number = 2; | |
1585 | struct in_addr area_id; | |
1586 | int format; | |
1587 | ||
1588 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
1589 | ||
1590 | VTY_GET_OSPF_AREA_ID_NO_BB("nssa", area_id, format, | |
1591 | argv[idx_ipv4_number]->arg); | |
1592 | ||
1593 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
1594 | format); | |
1595 | ospf_area_nssa_suppress_fa_unset(ospf, area_id); | |
1596 | ||
1597 | ospf_schedule_abr_task(ospf); | |
1598 | ||
1599 | return CMD_SUCCESS; | |
1600 | } | |
1601 | ||
a2c62831 | 1602 | DEFUN (ospf_area_nssa_no_summary, |
1603 | ospf_area_nssa_no_summary_cmd, | |
6147e2c6 | 1604 | "area <A.B.C.D|(0-4294967295)> nssa no-summary", |
718e3744 | 1605 | "OSPF area parameters\n" |
1606 | "OSPF area ID in IP address format\n" | |
1607 | "OSPF area ID as a decimal value\n" | |
1608 | "Configure OSPF area as nssa\n" | |
1609 | "Do not inject inter-area routes into nssa\n") | |
1610 | { | |
7ef56a73 CS |
1611 | int idx_ipv4_number = 1; |
1612 | struct in_addr area_id; | |
1613 | int format; | |
1614 | ||
1615 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
1616 | VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id, format, | |
1617 | argv[idx_ipv4_number]->arg); | |
1618 | ||
1619 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
1620 | format); | |
1621 | ospf_area_nssa_no_summary_set(ospf, area_id); | |
1622 | ||
1623 | ospf_schedule_abr_task(ospf); | |
1624 | ||
1625 | return CMD_SUCCESS; | |
1626 | } | |
1627 | ||
1628 | DEFUN (no_ospf_area_nssa_no_summary, | |
1629 | no_ospf_area_nssa_no_summary_cmd, | |
1630 | "no area <A.B.C.D|(0-4294967295)> nssa no-summary", | |
1631 | NO_STR | |
1632 | "OSPF area parameters\n" | |
1633 | "OSPF area ID in IP address format\n" | |
1634 | "OSPF area ID as a decimal value\n" | |
1635 | "Configure OSPF area as nssa\n" | |
1636 | "Do not inject inter-area routes into nssa\n") | |
1637 | { | |
1638 | int idx_ipv4_number = 2; | |
1639 | struct in_addr area_id; | |
1640 | int format; | |
1641 | ||
1642 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
1643 | ||
1644 | VTY_GET_OSPF_AREA_ID_NO_BB("nssa", area_id, format, | |
1645 | argv[idx_ipv4_number]->arg); | |
1646 | ||
1647 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
1648 | format); | |
1649 | ospf_area_no_summary_unset(ospf, area_id); | |
1650 | ||
1651 | ospf_schedule_abr_task(ospf); | |
1652 | ||
1653 | return CMD_SUCCESS; | |
718e3744 | 1654 | } |
1655 | ||
a2c62831 | 1656 | DEFUN (no_ospf_area_nssa, |
1657 | no_ospf_area_nssa_cmd, | |
7ef56a73 | 1658 | "no area <A.B.C.D|(0-4294967295)> nssa [<translate-candidate|translate-never|translate-always>]", |
718e3744 | 1659 | NO_STR |
1660 | "OSPF area parameters\n" | |
1661 | "OSPF area ID in IP address format\n" | |
1662 | "OSPF area ID as a decimal value\n" | |
7a7be519 | 1663 | "Configure OSPF area as nssa\n" |
1664 | "Configure NSSA-ABR for translate election (default)\n" | |
1665 | "Configure NSSA-ABR to never translate\n" | |
7ef56a73 | 1666 | "Configure NSSA-ABR to always translate\n") |
22b27e95 | 1667 | { |
a3d826f0 | 1668 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1669 | int idx_ipv4_number = 2; |
1670 | struct in_addr area_id; | |
1671 | int format; | |
718e3744 | 1672 | |
d62a17ae | 1673 | VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id, format, |
1674 | argv[idx_ipv4_number]->arg); | |
718e3744 | 1675 | |
44445dee S |
1676 | /* Flush the NSSA LSA for the specified area */ |
1677 | ospf_flush_lsa_from_area(ospf, area_id, OSPF_AS_NSSA_LSA); | |
7ef56a73 | 1678 | ospf_area_nssa_unset(ospf, area_id, argc); |
718e3744 | 1679 | |
d62a17ae | 1680 | ospf_schedule_abr_task(ospf); |
b0a053be | 1681 | |
d62a17ae | 1682 | return CMD_SUCCESS; |
718e3744 | 1683 | } |
1684 | ||
718e3744 | 1685 | |
a2c62831 | 1686 | DEFUN (ospf_area_default_cost, |
1687 | ospf_area_default_cost_cmd, | |
6147e2c6 | 1688 | "area <A.B.C.D|(0-4294967295)> default-cost (0-16777215)", |
718e3744 | 1689 | "OSPF area parameters\n" |
1690 | "OSPF area ID in IP address format\n" | |
1691 | "OSPF area ID as a decimal value\n" | |
1692 | "Set the summary-default cost of a NSSA or stub area\n" | |
1693 | "Stub's advertised default summary cost\n") | |
1694 | { | |
a3d826f0 | 1695 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1696 | int idx_ipv4_number = 1; |
1697 | int idx_number = 3; | |
1698 | struct ospf_area *area; | |
1699 | struct in_addr area_id; | |
d7c0a89a | 1700 | uint32_t cost; |
d62a17ae | 1701 | int format; |
1702 | struct prefix_ipv4 p; | |
1703 | ||
1704 | VTY_GET_OSPF_AREA_ID_NO_BB("default-cost", area_id, format, | |
1705 | argv[idx_ipv4_number]->arg); | |
1706 | cost = strtoul(argv[idx_number]->arg, NULL, 10); | |
1707 | ||
1708 | area = ospf_area_get(ospf, area_id); | |
1709 | ospf_area_display_format_set(ospf, area, format); | |
1710 | ||
1711 | if (area->external_routing == OSPF_AREA_DEFAULT) { | |
1712 | vty_out(vty, "The area is neither stub, nor NSSA\n"); | |
1713 | return CMD_WARNING_CONFIG_FAILED; | |
1714 | } | |
ba682537 | 1715 | |
d62a17ae | 1716 | area->default_cost = cost; |
1717 | ||
1718 | p.family = AF_INET; | |
1719 | p.prefix.s_addr = OSPF_DEFAULT_DESTINATION; | |
1720 | p.prefixlen = 0; | |
1721 | if (IS_DEBUG_OSPF_EVENT) | |
1722 | zlog_debug( | |
96b663a3 MS |
1723 | "ospf_abr_announce_stub_defaults(): announcing 0.0.0.0/0 to area %pI4", |
1724 | &area->area_id); | |
d62a17ae | 1725 | ospf_abr_announce_network_to_area(&p, area->default_cost, area); |
1726 | ||
1727 | return CMD_SUCCESS; | |
718e3744 | 1728 | } |
1729 | ||
a2c62831 | 1730 | DEFUN (no_ospf_area_default_cost, |
1731 | no_ospf_area_default_cost_cmd, | |
6147e2c6 | 1732 | "no area <A.B.C.D|(0-4294967295)> default-cost (0-16777215)", |
718e3744 | 1733 | NO_STR |
1734 | "OSPF area parameters\n" | |
1735 | "OSPF area ID in IP address format\n" | |
1736 | "OSPF area ID as a decimal value\n" | |
1737 | "Set the summary-default cost of a NSSA or stub area\n" | |
1738 | "Stub's advertised default summary cost\n") | |
1739 | { | |
a3d826f0 | 1740 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1741 | int idx_ipv4_number = 2; |
1742 | struct ospf_area *area; | |
1743 | struct in_addr area_id; | |
1744 | int format; | |
1745 | struct prefix_ipv4 p; | |
718e3744 | 1746 | |
d62a17ae | 1747 | VTY_GET_OSPF_AREA_ID_NO_BB("default-cost", area_id, format, |
1748 | argv[idx_ipv4_number]->arg); | |
718e3744 | 1749 | |
d62a17ae | 1750 | area = ospf_area_lookup_by_area_id(ospf, area_id); |
1751 | if (area == NULL) | |
1752 | return CMD_SUCCESS; | |
718e3744 | 1753 | |
d62a17ae | 1754 | if (area->external_routing == OSPF_AREA_DEFAULT) { |
1755 | vty_out(vty, "The area is neither stub, nor NSSA\n"); | |
1756 | return CMD_WARNING_CONFIG_FAILED; | |
1757 | } | |
718e3744 | 1758 | |
d62a17ae | 1759 | area->default_cost = 1; |
718e3744 | 1760 | |
d62a17ae | 1761 | p.family = AF_INET; |
1762 | p.prefix.s_addr = OSPF_DEFAULT_DESTINATION; | |
1763 | p.prefixlen = 0; | |
1764 | if (IS_DEBUG_OSPF_EVENT) | |
1765 | zlog_debug( | |
96b663a3 MS |
1766 | "ospf_abr_announce_stub_defaults(): announcing 0.0.0.0/0 to area %pI4", |
1767 | &area->area_id); | |
d62a17ae | 1768 | ospf_abr_announce_network_to_area(&p, area->default_cost, area); |
ba682537 | 1769 | |
1770 | ||
d62a17ae | 1771 | ospf_area_check_free(ospf, area_id); |
718e3744 | 1772 | |
d62a17ae | 1773 | return CMD_SUCCESS; |
718e3744 | 1774 | } |
1775 | ||
a2c62831 | 1776 | DEFUN (ospf_area_export_list, |
1777 | ospf_area_export_list_cmd, | |
6147e2c6 | 1778 | "area <A.B.C.D|(0-4294967295)> export-list NAME", |
718e3744 | 1779 | "OSPF area parameters\n" |
1780 | "OSPF area ID in IP address format\n" | |
1781 | "OSPF area ID as a decimal value\n" | |
1782 | "Set the filter for networks announced to other areas\n" | |
1783 | "Name of the access-list\n") | |
1784 | { | |
a3d826f0 | 1785 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1786 | int idx_ipv4_number = 1; |
1787 | struct ospf_area *area; | |
1788 | struct in_addr area_id; | |
1789 | int format; | |
718e3744 | 1790 | |
d62a17ae | 1791 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
52930766 | 1792 | |
d62a17ae | 1793 | area = ospf_area_get(ospf, area_id); |
1794 | ospf_area_display_format_set(ospf, area, format); | |
1795 | ospf_area_export_list_set(ospf, area, argv[3]->arg); | |
718e3744 | 1796 | |
d62a17ae | 1797 | return CMD_SUCCESS; |
718e3744 | 1798 | } |
1799 | ||
a2c62831 | 1800 | DEFUN (no_ospf_area_export_list, |
1801 | no_ospf_area_export_list_cmd, | |
6147e2c6 | 1802 | "no area <A.B.C.D|(0-4294967295)> export-list NAME", |
718e3744 | 1803 | NO_STR |
1804 | "OSPF area parameters\n" | |
1805 | "OSPF area ID in IP address format\n" | |
1806 | "OSPF area ID as a decimal value\n" | |
1807 | "Unset the filter for networks announced to other areas\n" | |
1808 | "Name of the access-list\n") | |
1809 | { | |
a3d826f0 | 1810 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1811 | int idx_ipv4_number = 2; |
1812 | struct ospf_area *area; | |
1813 | struct in_addr area_id; | |
1814 | int format; | |
718e3744 | 1815 | |
d62a17ae | 1816 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
52930766 | 1817 | |
d62a17ae | 1818 | area = ospf_area_lookup_by_area_id(ospf, area_id); |
1819 | if (area == NULL) | |
1820 | return CMD_SUCCESS; | |
718e3744 | 1821 | |
d62a17ae | 1822 | ospf_area_export_list_unset(ospf, area); |
718e3744 | 1823 | |
d62a17ae | 1824 | return CMD_SUCCESS; |
718e3744 | 1825 | } |
1826 | ||
1827 | ||
a2c62831 | 1828 | DEFUN (ospf_area_import_list, |
1829 | ospf_area_import_list_cmd, | |
6147e2c6 | 1830 | "area <A.B.C.D|(0-4294967295)> import-list NAME", |
718e3744 | 1831 | "OSPF area parameters\n" |
1832 | "OSPF area ID in IP address format\n" | |
1833 | "OSPF area ID as a decimal value\n" | |
1834 | "Set the filter for networks from other areas announced to the specified one\n" | |
1835 | "Name of the access-list\n") | |
1836 | { | |
a3d826f0 | 1837 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1838 | int idx_ipv4_number = 1; |
1839 | struct ospf_area *area; | |
1840 | struct in_addr area_id; | |
1841 | int format; | |
718e3744 | 1842 | |
d62a17ae | 1843 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
52930766 | 1844 | |
d62a17ae | 1845 | area = ospf_area_get(ospf, area_id); |
1846 | ospf_area_display_format_set(ospf, area, format); | |
1847 | ospf_area_import_list_set(ospf, area, argv[3]->arg); | |
718e3744 | 1848 | |
d62a17ae | 1849 | return CMD_SUCCESS; |
718e3744 | 1850 | } |
1851 | ||
a2c62831 | 1852 | DEFUN (no_ospf_area_import_list, |
1853 | no_ospf_area_import_list_cmd, | |
6147e2c6 | 1854 | "no area <A.B.C.D|(0-4294967295)> import-list NAME", |
718e3744 | 1855 | NO_STR |
1856 | "OSPF area parameters\n" | |
1857 | "OSPF area ID in IP address format\n" | |
1858 | "OSPF area ID as a decimal value\n" | |
1859 | "Unset the filter for networks announced to other areas\n" | |
1860 | "Name of the access-list\n") | |
1861 | { | |
a3d826f0 | 1862 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1863 | int idx_ipv4_number = 2; |
1864 | struct ospf_area *area; | |
1865 | struct in_addr area_id; | |
1866 | int format; | |
718e3744 | 1867 | |
d62a17ae | 1868 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
52930766 | 1869 | |
d62a17ae | 1870 | area = ospf_area_lookup_by_area_id(ospf, area_id); |
1871 | if (area == NULL) | |
1872 | return CMD_SUCCESS; | |
718e3744 | 1873 | |
d62a17ae | 1874 | ospf_area_import_list_unset(ospf, area); |
718e3744 | 1875 | |
d62a17ae | 1876 | return CMD_SUCCESS; |
718e3744 | 1877 | } |
1878 | ||
a2c62831 | 1879 | DEFUN (ospf_area_filter_list, |
1880 | ospf_area_filter_list_cmd, | |
6147e2c6 | 1881 | "area <A.B.C.D|(0-4294967295)> filter-list prefix WORD <in|out>", |
718e3744 | 1882 | "OSPF area parameters\n" |
1883 | "OSPF area ID in IP address format\n" | |
1884 | "OSPF area ID as a decimal value\n" | |
1885 | "Filter networks between OSPF areas\n" | |
1886 | "Filter prefixes between OSPF areas\n" | |
1887 | "Name of an IP prefix-list\n" | |
1888 | "Filter networks sent to this area\n" | |
1889 | "Filter networks sent from this area\n") | |
1890 | { | |
a3d826f0 | 1891 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1892 | int idx_ipv4_number = 1; |
1893 | int idx_word = 4; | |
1894 | int idx_in_out = 5; | |
1895 | struct ospf_area *area; | |
1896 | struct in_addr area_id; | |
1897 | struct prefix_list *plist; | |
1898 | int format; | |
1899 | ||
1900 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); | |
1901 | ||
1902 | area = ospf_area_get(ospf, area_id); | |
1903 | ospf_area_display_format_set(ospf, area, format); | |
1904 | plist = prefix_list_lookup(AFI_IP, argv[idx_word]->arg); | |
1905 | if (strncmp(argv[idx_in_out]->arg, "in", 2) == 0) { | |
1906 | PREFIX_LIST_IN(area) = plist; | |
1907 | if (PREFIX_NAME_IN(area)) | |
1908 | free(PREFIX_NAME_IN(area)); | |
1909 | ||
1910 | PREFIX_NAME_IN(area) = strdup(argv[idx_word]->arg); | |
1911 | ospf_schedule_abr_task(ospf); | |
1912 | } else { | |
1913 | PREFIX_LIST_OUT(area) = plist; | |
1914 | if (PREFIX_NAME_OUT(area)) | |
1915 | free(PREFIX_NAME_OUT(area)); | |
1916 | ||
1917 | PREFIX_NAME_OUT(area) = strdup(argv[idx_word]->arg); | |
1918 | ospf_schedule_abr_task(ospf); | |
1919 | } | |
718e3744 | 1920 | |
d62a17ae | 1921 | return CMD_SUCCESS; |
718e3744 | 1922 | } |
1923 | ||
a2c62831 | 1924 | DEFUN (no_ospf_area_filter_list, |
1925 | no_ospf_area_filter_list_cmd, | |
6147e2c6 | 1926 | "no area <A.B.C.D|(0-4294967295)> filter-list prefix WORD <in|out>", |
718e3744 | 1927 | NO_STR |
1928 | "OSPF area parameters\n" | |
1929 | "OSPF area ID in IP address format\n" | |
1930 | "OSPF area ID as a decimal value\n" | |
1931 | "Filter networks between OSPF areas\n" | |
1932 | "Filter prefixes between OSPF areas\n" | |
1933 | "Name of an IP prefix-list\n" | |
1934 | "Filter networks sent to this area\n" | |
1935 | "Filter networks sent from this area\n") | |
1936 | { | |
a3d826f0 | 1937 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1938 | int idx_ipv4_number = 2; |
1939 | int idx_word = 5; | |
1940 | int idx_in_out = 6; | |
1941 | struct ospf_area *area; | |
1942 | struct in_addr area_id; | |
1943 | int format; | |
718e3744 | 1944 | |
d62a17ae | 1945 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
718e3744 | 1946 | |
d62a17ae | 1947 | if ((area = ospf_area_lookup_by_area_id(ospf, area_id)) == NULL) |
1948 | return CMD_SUCCESS; | |
718e3744 | 1949 | |
d62a17ae | 1950 | if (strncmp(argv[idx_in_out]->arg, "in", 2) == 0) { |
1951 | if (PREFIX_NAME_IN(area)) | |
1952 | if (strcmp(PREFIX_NAME_IN(area), argv[idx_word]->arg) | |
1953 | != 0) | |
1954 | return CMD_SUCCESS; | |
718e3744 | 1955 | |
d62a17ae | 1956 | PREFIX_LIST_IN(area) = NULL; |
1957 | if (PREFIX_NAME_IN(area)) | |
1958 | free(PREFIX_NAME_IN(area)); | |
718e3744 | 1959 | |
d62a17ae | 1960 | PREFIX_NAME_IN(area) = NULL; |
718e3744 | 1961 | |
d62a17ae | 1962 | ospf_schedule_abr_task(ospf); |
1963 | } else { | |
1964 | if (PREFIX_NAME_OUT(area)) | |
1965 | if (strcmp(PREFIX_NAME_OUT(area), argv[idx_word]->arg) | |
1966 | != 0) | |
1967 | return CMD_SUCCESS; | |
718e3744 | 1968 | |
d62a17ae | 1969 | PREFIX_LIST_OUT(area) = NULL; |
1970 | if (PREFIX_NAME_OUT(area)) | |
1971 | free(PREFIX_NAME_OUT(area)); | |
718e3744 | 1972 | |
d62a17ae | 1973 | PREFIX_NAME_OUT(area) = NULL; |
718e3744 | 1974 | |
d62a17ae | 1975 | ospf_schedule_abr_task(ospf); |
1976 | } | |
1977 | ||
1978 | return CMD_SUCCESS; | |
718e3744 | 1979 | } |
1980 | ||
6b0655a2 | 1981 | |
a2c62831 | 1982 | DEFUN (ospf_area_authentication_message_digest, |
1983 | ospf_area_authentication_message_digest_cmd, | |
32573073 QY |
1984 | "[no] area <A.B.C.D|(0-4294967295)> authentication message-digest", |
1985 | NO_STR | |
718e3744 | 1986 | "OSPF area parameters\n" |
2b00515a CF |
1987 | "OSPF area ID in IP address format\n" |
1988 | "OSPF area ID as a decimal value\n" | |
718e3744 | 1989 | "Enable authentication\n" |
1990 | "Use message-digest authentication\n") | |
1991 | { | |
a3d826f0 | 1992 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
ca19319b | 1993 | int idx = 0; |
d62a17ae | 1994 | struct ospf_area *area; |
1995 | struct in_addr area_id; | |
1996 | int format; | |
718e3744 | 1997 | |
ca19319b | 1998 | argv_find(argv, argc, "area", &idx); |
1999 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx + 1]->arg); | |
718e3744 | 2000 | |
d62a17ae | 2001 | area = ospf_area_get(ospf, area_id); |
2002 | ospf_area_display_format_set(ospf, area, format); | |
996c9314 LB |
2003 | area->auth_type = strmatch(argv[0]->text, "no") |
2004 | ? OSPF_AUTH_NULL | |
2005 | : OSPF_AUTH_CRYPTOGRAPHIC; | |
718e3744 | 2006 | |
d62a17ae | 2007 | return CMD_SUCCESS; |
718e3744 | 2008 | } |
2009 | ||
a2c62831 | 2010 | DEFUN (ospf_area_authentication, |
2011 | ospf_area_authentication_cmd, | |
6147e2c6 | 2012 | "area <A.B.C.D|(0-4294967295)> authentication", |
718e3744 | 2013 | "OSPF area parameters\n" |
2014 | "OSPF area ID in IP address format\n" | |
2015 | "OSPF area ID as a decimal value\n" | |
2016 | "Enable authentication\n") | |
2017 | { | |
a3d826f0 | 2018 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2019 | int idx_ipv4_number = 1; |
2020 | struct ospf_area *area; | |
2021 | struct in_addr area_id; | |
2022 | int format; | |
718e3744 | 2023 | |
d62a17ae | 2024 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
718e3744 | 2025 | |
d62a17ae | 2026 | area = ospf_area_get(ospf, area_id); |
2027 | ospf_area_display_format_set(ospf, area, format); | |
2028 | area->auth_type = OSPF_AUTH_SIMPLE; | |
718e3744 | 2029 | |
d62a17ae | 2030 | return CMD_SUCCESS; |
718e3744 | 2031 | } |
2032 | ||
a2c62831 | 2033 | DEFUN (no_ospf_area_authentication, |
2034 | no_ospf_area_authentication_cmd, | |
6147e2c6 | 2035 | "no area <A.B.C.D|(0-4294967295)> authentication", |
718e3744 | 2036 | NO_STR |
2037 | "OSPF area parameters\n" | |
2038 | "OSPF area ID in IP address format\n" | |
2039 | "OSPF area ID as a decimal value\n" | |
2040 | "Enable authentication\n") | |
2041 | { | |
a3d826f0 | 2042 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2043 | int idx_ipv4_number = 2; |
2044 | struct ospf_area *area; | |
2045 | struct in_addr area_id; | |
2046 | int format; | |
718e3744 | 2047 | |
d62a17ae | 2048 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
718e3744 | 2049 | |
d62a17ae | 2050 | area = ospf_area_lookup_by_area_id(ospf, area_id); |
2051 | if (area == NULL) | |
2052 | return CMD_SUCCESS; | |
718e3744 | 2053 | |
d62a17ae | 2054 | area->auth_type = OSPF_AUTH_NULL; |
718e3744 | 2055 | |
d62a17ae | 2056 | ospf_area_check_free(ospf, area_id); |
2057 | ||
2058 | return CMD_SUCCESS; | |
718e3744 | 2059 | } |
2060 | ||
6b0655a2 | 2061 | |
718e3744 | 2062 | DEFUN (ospf_abr_type, |
2063 | ospf_abr_type_cmd, | |
6147e2c6 | 2064 | "ospf abr-type <cisco|ibm|shortcut|standard>", |
718e3744 | 2065 | "OSPF specific commands\n" |
2066 | "Set OSPF ABR type\n" | |
2067 | "Alternative ABR, cisco implementation\n" | |
2068 | "Alternative ABR, IBM implementation\n" | |
2069 | "Shortcut ABR\n" | |
2070 | "Standard behavior (RFC2328)\n") | |
2071 | { | |
a3d826f0 | 2072 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2073 | int idx_vendor = 2; |
d7c0a89a | 2074 | uint8_t abr_type = OSPF_ABR_UNKNOWN; |
d62a17ae | 2075 | |
2076 | if (strncmp(argv[idx_vendor]->arg, "c", 1) == 0) | |
2077 | abr_type = OSPF_ABR_CISCO; | |
2078 | else if (strncmp(argv[idx_vendor]->arg, "i", 1) == 0) | |
2079 | abr_type = OSPF_ABR_IBM; | |
2080 | else if (strncmp(argv[idx_vendor]->arg, "sh", 2) == 0) | |
2081 | abr_type = OSPF_ABR_SHORTCUT; | |
2082 | else if (strncmp(argv[idx_vendor]->arg, "st", 2) == 0) | |
2083 | abr_type = OSPF_ABR_STAND; | |
2084 | else | |
2085 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 2086 | |
d62a17ae | 2087 | /* If ABR type value is changed, schedule ABR task. */ |
2088 | if (ospf->abr_type != abr_type) { | |
2089 | ospf->abr_type = abr_type; | |
2090 | ospf_schedule_abr_task(ospf); | |
2091 | } | |
2092 | ||
2093 | return CMD_SUCCESS; | |
718e3744 | 2094 | } |
2095 | ||
2096 | DEFUN (no_ospf_abr_type, | |
2097 | no_ospf_abr_type_cmd, | |
6147e2c6 | 2098 | "no ospf abr-type <cisco|ibm|shortcut|standard>", |
718e3744 | 2099 | NO_STR |
2100 | "OSPF specific commands\n" | |
2101 | "Set OSPF ABR type\n" | |
2102 | "Alternative ABR, cisco implementation\n" | |
2103 | "Alternative ABR, IBM implementation\n" | |
3a2d747c QY |
2104 | "Shortcut ABR\n" |
2105 | "Standard ABR\n") | |
718e3744 | 2106 | { |
a3d826f0 | 2107 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2108 | int idx_vendor = 3; |
d7c0a89a | 2109 | uint8_t abr_type = OSPF_ABR_UNKNOWN; |
d62a17ae | 2110 | |
2111 | if (strncmp(argv[idx_vendor]->arg, "c", 1) == 0) | |
2112 | abr_type = OSPF_ABR_CISCO; | |
2113 | else if (strncmp(argv[idx_vendor]->arg, "i", 1) == 0) | |
2114 | abr_type = OSPF_ABR_IBM; | |
2115 | else if (strncmp(argv[idx_vendor]->arg, "sh", 2) == 0) | |
2116 | abr_type = OSPF_ABR_SHORTCUT; | |
2117 | else if (strncmp(argv[idx_vendor]->arg, "st", 2) == 0) | |
2118 | abr_type = OSPF_ABR_STAND; | |
2119 | else | |
2120 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 2121 | |
d62a17ae | 2122 | /* If ABR type value is changed, schedule ABR task. */ |
2123 | if (ospf->abr_type == abr_type) { | |
2124 | ospf->abr_type = OSPF_ABR_DEFAULT; | |
2125 | ospf_schedule_abr_task(ospf); | |
2126 | } | |
2127 | ||
2128 | return CMD_SUCCESS; | |
718e3744 | 2129 | } |
2130 | ||
d7e60dd7 AS |
2131 | DEFUN (ospf_log_adjacency_changes, |
2132 | ospf_log_adjacency_changes_cmd, | |
2133 | "log-adjacency-changes", | |
2134 | "Log changes in adjacency state\n") | |
2135 | { | |
a3d826f0 | 2136 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d7e60dd7 | 2137 | |
d62a17ae | 2138 | SET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES); |
2139 | UNSET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL); | |
2140 | return CMD_SUCCESS; | |
d7e60dd7 AS |
2141 | } |
2142 | ||
2143 | DEFUN (ospf_log_adjacency_changes_detail, | |
2144 | ospf_log_adjacency_changes_detail_cmd, | |
2145 | "log-adjacency-changes detail", | |
2146 | "Log changes in adjacency state\n" | |
2147 | "Log all state changes\n") | |
2148 | { | |
a3d826f0 | 2149 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d7e60dd7 | 2150 | |
d62a17ae | 2151 | SET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES); |
2152 | SET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL); | |
2153 | return CMD_SUCCESS; | |
d7e60dd7 AS |
2154 | } |
2155 | ||
2156 | DEFUN (no_ospf_log_adjacency_changes, | |
2157 | no_ospf_log_adjacency_changes_cmd, | |
2158 | "no log-adjacency-changes", | |
2159 | NO_STR | |
2160 | "Log changes in adjacency state\n") | |
2161 | { | |
a3d826f0 | 2162 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d7e60dd7 | 2163 | |
d62a17ae | 2164 | UNSET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL); |
2165 | UNSET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES); | |
2166 | return CMD_SUCCESS; | |
d7e60dd7 AS |
2167 | } |
2168 | ||
2169 | DEFUN (no_ospf_log_adjacency_changes_detail, | |
2170 | no_ospf_log_adjacency_changes_detail_cmd, | |
2171 | "no log-adjacency-changes detail", | |
2172 | NO_STR | |
2173 | "Log changes in adjacency state\n" | |
2174 | "Log all state changes\n") | |
2175 | { | |
a3d826f0 | 2176 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d7e60dd7 | 2177 | |
d62a17ae | 2178 | UNSET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL); |
2179 | return CMD_SUCCESS; | |
d7e60dd7 AS |
2180 | } |
2181 | ||
718e3744 | 2182 | DEFUN (ospf_compatible_rfc1583, |
2183 | ospf_compatible_rfc1583_cmd, | |
2184 | "compatible rfc1583", | |
2185 | "OSPF compatibility list\n" | |
2186 | "compatible with RFC 1583\n") | |
2187 | { | |
a3d826f0 | 2188 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
718e3744 | 2189 | |
d62a17ae | 2190 | if (!CHECK_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE)) { |
2191 | SET_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE); | |
2192 | ospf_spf_calculate_schedule(ospf, SPF_FLAG_CONFIG_CHANGE); | |
2193 | } | |
2194 | return CMD_SUCCESS; | |
718e3744 | 2195 | } |
2196 | ||
2197 | DEFUN (no_ospf_compatible_rfc1583, | |
2198 | no_ospf_compatible_rfc1583_cmd, | |
2199 | "no compatible rfc1583", | |
2200 | NO_STR | |
2201 | "OSPF compatibility list\n" | |
2202 | "compatible with RFC 1583\n") | |
2203 | { | |
a3d826f0 | 2204 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
718e3744 | 2205 | |
d62a17ae | 2206 | if (CHECK_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE)) { |
2207 | UNSET_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE); | |
2208 | ospf_spf_calculate_schedule(ospf, SPF_FLAG_CONFIG_CHANGE); | |
2209 | } | |
2210 | return CMD_SUCCESS; | |
718e3744 | 2211 | } |
2212 | ||
d62a17ae | 2213 | ALIAS(ospf_compatible_rfc1583, ospf_rfc1583_flag_cmd, |
2214 | "ospf rfc1583compatibility", | |
2215 | "OSPF specific commands\n" | |
2216 | "Enable the RFC1583Compatibility flag\n") | |
718e3744 | 2217 | |
d62a17ae | 2218 | ALIAS(no_ospf_compatible_rfc1583, no_ospf_rfc1583_flag_cmd, |
9d303b37 | 2219 | "no ospf rfc1583compatibility", NO_STR |
d62a17ae | 2220 | "OSPF specific commands\n" |
2221 | "Disable the RFC1583Compatibility flag\n") | |
6b0655a2 | 2222 | |
d62a17ae | 2223 | static int ospf_timers_spf_set(struct vty *vty, unsigned int delay, |
2224 | unsigned int hold, unsigned int max) | |
d24f6e2a | 2225 | { |
a3d826f0 | 2226 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
7c8ff89e | 2227 | |
d62a17ae | 2228 | ospf->spf_delay = delay; |
2229 | ospf->spf_holdtime = hold; | |
2230 | ospf->spf_max_holdtime = max; | |
2231 | ||
2232 | return CMD_SUCCESS; | |
d24f6e2a | 2233 | } |
718e3744 | 2234 | |
ac7424f9 MR |
2235 | DEFUN (ospf_timers_min_ls_interval, |
2236 | ospf_timers_min_ls_interval_cmd, | |
6147e2c6 | 2237 | "timers throttle lsa all (0-5000)", |
ac7424f9 MR |
2238 | "Adjust routing timers\n" |
2239 | "Throttling adaptive timer\n" | |
2240 | "LSA delay between transmissions\n" | |
813d4307 | 2241 | "All LSA types\n" |
ac7424f9 MR |
2242 | "Delay (msec) between sending LSAs\n") |
2243 | { | |
a3d826f0 | 2244 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2245 | int idx_number = 4; |
2246 | unsigned int interval; | |
ac7424f9 | 2247 | |
d62a17ae | 2248 | if (argc < 5) { |
2249 | vty_out(vty, "Insufficient arguments\n"); | |
2250 | return CMD_WARNING_CONFIG_FAILED; | |
2251 | } | |
ac7424f9 | 2252 | |
d62a17ae | 2253 | interval = strtoul(argv[idx_number]->arg, NULL, 10); |
ac7424f9 | 2254 | |
d62a17ae | 2255 | ospf->min_ls_interval = interval; |
ac7424f9 | 2256 | |
d62a17ae | 2257 | return CMD_SUCCESS; |
ac7424f9 MR |
2258 | } |
2259 | ||
2260 | DEFUN (no_ospf_timers_min_ls_interval, | |
2261 | no_ospf_timers_min_ls_interval_cmd, | |
7a7be519 | 2262 | "no timers throttle lsa all [(0-5000)]", |
ac7424f9 MR |
2263 | NO_STR |
2264 | "Adjust routing timers\n" | |
2265 | "Throttling adaptive timer\n" | |
813d4307 | 2266 | "LSA delay between transmissions\n" |
7a7be519 | 2267 | "All LSA types\n" |
2268 | "Delay (msec) between sending LSAs\n") | |
ac7424f9 | 2269 | { |
a3d826f0 | 2270 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2271 | ospf->min_ls_interval = OSPF_MIN_LS_INTERVAL; |
ac7424f9 | 2272 | |
d62a17ae | 2273 | return CMD_SUCCESS; |
ac7424f9 MR |
2274 | } |
2275 | ||
d24f6e2a | 2276 | DEFUN (ospf_timers_throttle_spf, |
2277 | ospf_timers_throttle_spf_cmd, | |
6147e2c6 | 2278 | "timers throttle spf (0-600000) (0-600000) (0-600000)", |
d24f6e2a | 2279 | "Adjust routing timers\n" |
2280 | "Throttling adaptive timer\n" | |
2281 | "OSPF SPF timers\n" | |
2282 | "Delay (msec) from first change received till SPF calculation\n" | |
2283 | "Initial hold time (msec) between consecutive SPF calculations\n" | |
2284 | "Maximum hold time (msec)\n") | |
2285 | { | |
d62a17ae | 2286 | int idx_number = 3; |
2287 | int idx_number_2 = 4; | |
2288 | int idx_number_3 = 5; | |
2289 | unsigned int delay, hold, max; | |
2290 | ||
2291 | if (argc < 6) { | |
2292 | vty_out(vty, "Insufficient arguments\n"); | |
2293 | return CMD_WARNING_CONFIG_FAILED; | |
2294 | } | |
2295 | ||
2296 | delay = strtoul(argv[idx_number]->arg, NULL, 10); | |
2297 | hold = strtoul(argv[idx_number_2]->arg, NULL, 10); | |
2298 | max = strtoul(argv[idx_number_3]->arg, NULL, 10); | |
2299 | ||
2300 | return ospf_timers_spf_set(vty, delay, hold, max); | |
d24f6e2a | 2301 | } |
2302 | ||
d24f6e2a | 2303 | DEFUN (no_ospf_timers_throttle_spf, |
2304 | no_ospf_timers_throttle_spf_cmd, | |
7a7be519 | 2305 | "no timers throttle spf [(0-600000)(0-600000)(0-600000)]", |
718e3744 | 2306 | NO_STR |
2307 | "Adjust routing timers\n" | |
d24f6e2a | 2308 | "Throttling adaptive timer\n" |
7a7be519 | 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") | |
22b27e95 | 2313 | { |
d62a17ae | 2314 | return ospf_timers_spf_set(vty, OSPF_SPF_DELAY_DEFAULT, |
2315 | OSPF_SPF_HOLDTIME_DEFAULT, | |
2316 | OSPF_SPF_MAX_HOLDTIME_DEFAULT); | |
718e3744 | 2317 | } |
2318 | ||
b4a039bf | 2319 | |
0e88de35 QY |
2320 | DEFUN (ospf_timers_lsa_min_arrival, |
2321 | ospf_timers_lsa_min_arrival_cmd, | |
6147e2c6 | 2322 | "timers lsa min-arrival (0-600000)", |
b6927875 DS |
2323 | "Adjust routing timers\n" |
2324 | "OSPF LSA timers\n" | |
2325 | "Minimum delay in receiving new version of a LSA\n" | |
2326 | "Delay in milliseconds\n") | |
2327 | { | |
a3d826f0 | 2328 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
0e88de35 | 2329 | ospf->min_ls_arrival = strtoul(argv[argc - 1]->arg, NULL, 10); |
d62a17ae | 2330 | return CMD_SUCCESS; |
b6927875 DS |
2331 | } |
2332 | ||
0e88de35 QY |
2333 | DEFUN (no_ospf_timers_lsa_min_arrival, |
2334 | no_ospf_timers_lsa_min_arrival_cmd, | |
7a7be519 | 2335 | "no timers lsa min-arrival [(0-600000)]", |
b6927875 DS |
2336 | NO_STR |
2337 | "Adjust routing timers\n" | |
2338 | "OSPF LSA timers\n" | |
7a7be519 | 2339 | "Minimum delay in receiving new version of a LSA\n" |
2340 | "Delay in milliseconds\n") | |
b6927875 | 2341 | { |
a3d826f0 | 2342 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2343 | unsigned int minarrival; |
b6927875 | 2344 | |
d62a17ae | 2345 | if (argc > 4) { |
0e88de35 | 2346 | minarrival = strtoul(argv[argc - 1]->arg, NULL, 10); |
b6927875 | 2347 | |
d62a17ae | 2348 | if (ospf->min_ls_arrival != minarrival |
2349 | || minarrival == OSPF_MIN_LS_ARRIVAL) | |
2350 | return CMD_SUCCESS; | |
2351 | } | |
b6927875 | 2352 | |
d62a17ae | 2353 | ospf->min_ls_arrival = OSPF_MIN_LS_ARRIVAL; |
b6927875 | 2354 | |
d62a17ae | 2355 | return CMD_SUCCESS; |
b6927875 DS |
2356 | } |
2357 | ||
a2c62831 | 2358 | DEFUN (ospf_neighbor, |
2359 | ospf_neighbor_cmd, | |
7a7be519 | 2360 | "neighbor A.B.C.D [priority (0-255) [poll-interval (1-65535)]]", |
718e3744 | 2361 | NEIGHBOR_STR |
7a7be519 | 2362 | "Neighbor IP address\n" |
2363 | "Neighbor Priority\n" | |
2364 | "Priority\n" | |
2365 | "Dead Neighbor Polling interval\n" | |
2366 | "Seconds\n") | |
718e3744 | 2367 | { |
a3d826f0 | 2368 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2369 | int idx_ipv4 = 1; |
2370 | int idx_pri = 3; | |
2371 | int idx_poll = 5; | |
2372 | struct in_addr nbr_addr; | |
2373 | unsigned int priority = OSPF_NEIGHBOR_PRIORITY_DEFAULT; | |
2374 | unsigned int interval = OSPF_POLL_INTERVAL_DEFAULT; | |
718e3744 | 2375 | |
cc9b06ad DS |
2376 | if (!inet_aton(argv[idx_ipv4]->arg, &nbr_addr)) { |
2377 | vty_out(vty, "Please specify Neighbor ID by A.B.C.D\n"); | |
2378 | return CMD_WARNING_CONFIG_FAILED; | |
2379 | } | |
718e3744 | 2380 | |
d62a17ae | 2381 | if (argc > 2) |
2382 | priority = strtoul(argv[idx_pri]->arg, NULL, 10); | |
7a7be519 | 2383 | |
d62a17ae | 2384 | if (argc > 4) |
2385 | interval = strtoul(argv[idx_poll]->arg, NULL, 10); | |
718e3744 | 2386 | |
d62a17ae | 2387 | ospf_nbr_nbma_set(ospf, nbr_addr); |
7a7be519 | 2388 | |
d62a17ae | 2389 | if (argc > 2) |
2390 | ospf_nbr_nbma_priority_set(ospf, nbr_addr, priority); | |
7a7be519 | 2391 | |
d62a17ae | 2392 | if (argc > 4) |
2393 | ospf_nbr_nbma_poll_interval_set(ospf, nbr_addr, interval); | |
718e3744 | 2394 | |
d62a17ae | 2395 | return CMD_SUCCESS; |
718e3744 | 2396 | } |
2397 | ||
a2c62831 | 2398 | DEFUN (ospf_neighbor_poll_interval, |
2399 | ospf_neighbor_poll_interval_cmd, | |
7a7be519 | 2400 | "neighbor A.B.C.D poll-interval (1-65535) [priority (0-255)]", |
718e3744 | 2401 | NEIGHBOR_STR |
2402 | "Neighbor IP address\n" | |
2403 | "Dead Neighbor Polling interval\n" | |
7a7be519 | 2404 | "Seconds\n" |
2405 | "OSPF priority of non-broadcast neighbor\n" | |
2406 | "Priority\n") | |
22b27e95 | 2407 | { |
a3d826f0 | 2408 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2409 | int idx_ipv4 = 1; |
2410 | int idx_poll = 3; | |
2411 | int idx_pri = 5; | |
2412 | struct in_addr nbr_addr; | |
a2b6e694 | 2413 | unsigned int priority; |
2414 | unsigned int interval; | |
718e3744 | 2415 | |
cc9b06ad DS |
2416 | if (!inet_aton(argv[idx_ipv4]->arg, &nbr_addr)) { |
2417 | vty_out(vty, "Please specify Neighbor ID by A.B.C.D\n"); | |
2418 | return CMD_WARNING_CONFIG_FAILED; | |
2419 | } | |
718e3744 | 2420 | |
d62a17ae | 2421 | interval = strtoul(argv[idx_poll]->arg, NULL, 10); |
718e3744 | 2422 | |
a2b6e694 | 2423 | priority = argc > 4 ? strtoul(argv[idx_pri]->arg, NULL, 10) |
2424 | : OSPF_NEIGHBOR_PRIORITY_DEFAULT; | |
718e3744 | 2425 | |
d62a17ae | 2426 | ospf_nbr_nbma_set(ospf, nbr_addr); |
2427 | ospf_nbr_nbma_poll_interval_set(ospf, nbr_addr, interval); | |
7a7be519 | 2428 | |
d62a17ae | 2429 | if (argc > 4) |
2430 | ospf_nbr_nbma_priority_set(ospf, nbr_addr, priority); | |
718e3744 | 2431 | |
d62a17ae | 2432 | return CMD_SUCCESS; |
718e3744 | 2433 | } |
2434 | ||
a2c62831 | 2435 | DEFUN (no_ospf_neighbor, |
2436 | no_ospf_neighbor_cmd, | |
7a7be519 | 2437 | "no neighbor A.B.C.D [priority (0-255) [poll-interval (1-65525)]]", |
718e3744 | 2438 | NO_STR |
2439 | NEIGHBOR_STR | |
7a7be519 | 2440 | "Neighbor IP address\n" |
2441 | "Neighbor Priority\n" | |
2442 | "Priority\n" | |
2443 | "Dead Neighbor Polling interval\n" | |
2444 | "Seconds\n") | |
718e3744 | 2445 | { |
a3d826f0 | 2446 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2447 | int idx_ipv4 = 2; |
2448 | struct in_addr nbr_addr; | |
718e3744 | 2449 | |
cc9b06ad DS |
2450 | if (!inet_aton(argv[idx_ipv4]->arg, &nbr_addr)) { |
2451 | vty_out(vty, "Please specify Neighbor ID by A.B.C.D\n"); | |
2452 | return CMD_WARNING_CONFIG_FAILED; | |
2453 | } | |
718e3744 | 2454 | |
d62a17ae | 2455 | (void)ospf_nbr_nbma_unset(ospf, nbr_addr); |
718e3744 | 2456 | |
d62a17ae | 2457 | return CMD_SUCCESS; |
718e3744 | 2458 | } |
2459 | ||
7a7be519 | 2460 | DEFUN (no_ospf_neighbor_poll, |
2461 | no_ospf_neighbor_poll_cmd, | |
2462 | "no neighbor A.B.C.D poll-interval (1-65535) [priority (0-255)]", | |
2463 | NO_STR | |
2464 | NEIGHBOR_STR | |
2465 | "Neighbor IP address\n" | |
2466 | "Dead Neighbor Polling interval\n" | |
2467 | "Seconds\n" | |
2468 | "Neighbor Priority\n" | |
2469 | "Priority\n") | |
2470 | { | |
a3d826f0 | 2471 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2472 | int idx_ipv4 = 2; |
2473 | struct in_addr nbr_addr; | |
7a7be519 | 2474 | |
cc9b06ad DS |
2475 | if (!inet_aton(argv[idx_ipv4]->arg, &nbr_addr)) { |
2476 | vty_out(vty, "Please specify Neighbor ID by A.B.C.D\n"); | |
2477 | return CMD_WARNING_CONFIG_FAILED; | |
2478 | } | |
718e3744 | 2479 | |
d62a17ae | 2480 | (void)ospf_nbr_nbma_unset(ospf, nbr_addr); |
813d4307 | 2481 | |
d62a17ae | 2482 | return CMD_SUCCESS; |
7a7be519 | 2483 | } |
718e3744 | 2484 | |
bf2bfafd DW |
2485 | DEFUN (ospf_refresh_timer, |
2486 | ospf_refresh_timer_cmd, | |
6147e2c6 | 2487 | "refresh timer (10-1800)", |
718e3744 | 2488 | "Adjust refresh parameters\n" |
2489 | "Set refresh timer\n" | |
2490 | "Timer value in seconds\n") | |
2491 | { | |
a3d826f0 | 2492 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2493 | int idx_number = 2; |
2494 | unsigned int interval; | |
7c8ff89e | 2495 | |
d62a17ae | 2496 | interval = strtoul(argv[idx_number]->arg, NULL, 10); |
2497 | interval = (interval / OSPF_LSA_REFRESHER_GRANULARITY) | |
2498 | * OSPF_LSA_REFRESHER_GRANULARITY; | |
718e3744 | 2499 | |
d62a17ae | 2500 | ospf_timers_refresh_set(ospf, interval); |
718e3744 | 2501 | |
d62a17ae | 2502 | return CMD_SUCCESS; |
718e3744 | 2503 | } |
2504 | ||
bf2bfafd DW |
2505 | DEFUN (no_ospf_refresh_timer, |
2506 | no_ospf_refresh_timer_val_cmd, | |
7a7be519 | 2507 | "no refresh timer [(10-1800)]", |
3a2d747c | 2508 | NO_STR |
718e3744 | 2509 | "Adjust refresh parameters\n" |
2510 | "Unset refresh timer\n" | |
2511 | "Timer value in seconds\n") | |
2512 | { | |
a3d826f0 | 2513 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2514 | int idx_number = 3; |
2515 | unsigned int interval; | |
718e3744 | 2516 | |
d62a17ae | 2517 | if (argc == 1) { |
2518 | interval = strtoul(argv[idx_number]->arg, NULL, 10); | |
718e3744 | 2519 | |
d62a17ae | 2520 | if (ospf->lsa_refresh_interval != interval |
2521 | || interval == OSPF_LSA_REFRESH_INTERVAL_DEFAULT) | |
2522 | return CMD_SUCCESS; | |
2523 | } | |
2524 | ||
2525 | ospf_timers_refresh_unset(ospf); | |
2526 | ||
2527 | return CMD_SUCCESS; | |
718e3744 | 2528 | } |
2529 | ||
718e3744 | 2530 | |
a2c62831 | 2531 | DEFUN (ospf_auto_cost_reference_bandwidth, |
2532 | ospf_auto_cost_reference_bandwidth_cmd, | |
6147e2c6 | 2533 | "auto-cost reference-bandwidth (1-4294967)", |
718e3744 | 2534 | "Calculate OSPF interface cost according to bandwidth\n" |
2535 | "Use reference bandwidth method to assign OSPF cost\n" | |
2536 | "The reference bandwidth in terms of Mbits per second\n") | |
2537 | { | |
a3d826f0 | 2538 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
f4e14fdb | 2539 | struct vrf *vrf = vrf_lookup_by_id(ospf->vrf_id); |
d62a17ae | 2540 | int idx_number = 2; |
d7c0a89a | 2541 | uint32_t refbw; |
d62a17ae | 2542 | struct interface *ifp; |
2543 | ||
2544 | refbw = strtol(argv[idx_number]->arg, NULL, 10); | |
2545 | if (refbw < 1 || refbw > 4294967) { | |
2546 | vty_out(vty, "reference-bandwidth value is invalid\n"); | |
2547 | return CMD_WARNING_CONFIG_FAILED; | |
2548 | } | |
2549 | ||
2550 | /* If reference bandwidth is changed. */ | |
2551 | if ((refbw) == ospf->ref_bandwidth) | |
2552 | return CMD_SUCCESS; | |
2553 | ||
2554 | ospf->ref_bandwidth = refbw; | |
451fda4f | 2555 | FOR_ALL_INTERFACES (vrf, ifp) |
d62a17ae | 2556 | ospf_if_recalculate_output_cost(ifp); |
2557 | ||
2558 | return CMD_SUCCESS; | |
718e3744 | 2559 | } |
2560 | ||
a2c62831 | 2561 | DEFUN (no_ospf_auto_cost_reference_bandwidth, |
2562 | no_ospf_auto_cost_reference_bandwidth_cmd, | |
7a7be519 | 2563 | "no auto-cost reference-bandwidth [(1-4294967)]", |
718e3744 | 2564 | NO_STR |
2565 | "Calculate OSPF interface cost according to bandwidth\n" | |
7a7be519 | 2566 | "Use reference bandwidth method to assign OSPF cost\n" |
2567 | "The reference bandwidth in terms of Mbits per second\n") | |
718e3744 | 2568 | { |
a3d826f0 | 2569 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
f4e14fdb | 2570 | struct vrf *vrf = vrf_lookup_by_id(ospf->vrf_id); |
d62a17ae | 2571 | struct interface *ifp; |
718e3744 | 2572 | |
d62a17ae | 2573 | if (ospf->ref_bandwidth == OSPF_DEFAULT_REF_BANDWIDTH) |
2574 | return CMD_SUCCESS; | |
2575 | ||
2576 | ospf->ref_bandwidth = OSPF_DEFAULT_REF_BANDWIDTH; | |
2577 | vty_out(vty, "%% OSPF: Reference bandwidth is changed.\n"); | |
2578 | vty_out(vty, | |
2579 | " Please ensure reference bandwidth is consistent across all routers\n"); | |
2580 | ||
451fda4f | 2581 | FOR_ALL_INTERFACES (vrf, ifp) |
d62a17ae | 2582 | ospf_if_recalculate_output_cost(ifp); |
2583 | ||
2584 | return CMD_SUCCESS; | |
718e3744 | 2585 | } |
2586 | ||
2f8f370e DS |
2587 | DEFUN (ospf_write_multiplier, |
2588 | ospf_write_multiplier_cmd, | |
6147e2c6 | 2589 | "ospf write-multiplier (1-100)", |
e8f45e82 DS |
2590 | "OSPF specific commands\n" |
2591 | "Write multiplier\n" | |
2592 | "Maximum number of interface serviced per write\n") | |
2f8f370e | 2593 | { |
a3d826f0 | 2594 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2595 | int idx_number; |
d7c0a89a | 2596 | uint32_t write_oi_count; |
d62a17ae | 2597 | |
2598 | if (argc == 3) | |
2599 | idx_number = 2; | |
2600 | else | |
2601 | idx_number = 1; | |
2602 | ||
2603 | write_oi_count = strtol(argv[idx_number]->arg, NULL, 10); | |
2604 | if (write_oi_count < 1 || write_oi_count > 100) { | |
2605 | vty_out(vty, "write-multiplier value is invalid\n"); | |
2606 | return CMD_WARNING_CONFIG_FAILED; | |
2607 | } | |
2608 | ||
2609 | ospf->write_oi_count = write_oi_count; | |
2610 | return CMD_SUCCESS; | |
2f8f370e DS |
2611 | } |
2612 | ||
d62a17ae | 2613 | ALIAS(ospf_write_multiplier, write_multiplier_cmd, "write-multiplier (1-100)", |
2614 | "Write multiplier\n" | |
2615 | "Maximum number of interface serviced per write\n") | |
e8f45e82 | 2616 | |
2f8f370e DS |
2617 | DEFUN (no_ospf_write_multiplier, |
2618 | no_ospf_write_multiplier_cmd, | |
6147e2c6 | 2619 | "no ospf write-multiplier (1-100)", |
2f8f370e | 2620 | NO_STR |
e8f45e82 | 2621 | "OSPF specific commands\n" |
813d4307 DW |
2622 | "Write multiplier\n" |
2623 | "Maximum number of interface serviced per write\n") | |
2f8f370e | 2624 | { |
a3d826f0 | 2625 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
2f8f370e | 2626 | |
d62a17ae | 2627 | ospf->write_oi_count = OSPF_WRITE_INTERFACE_COUNT_DEFAULT; |
2628 | return CMD_SUCCESS; | |
2f8f370e DS |
2629 | } |
2630 | ||
d62a17ae | 2631 | ALIAS(no_ospf_write_multiplier, no_write_multiplier_cmd, |
9d303b37 | 2632 | "no write-multiplier (1-100)", NO_STR |
d62a17ae | 2633 | "Write multiplier\n" |
2634 | "Maximum number of interface serviced per write\n") | |
2635 | ||
385a1e07 | 2636 | DEFUN(ospf_ti_lfa, ospf_ti_lfa_cmd, "fast-reroute ti-lfa [node-protection]", |
7fd0729f | 2637 | "Fast Reroute for MPLS and IP resilience\n" |
385a1e07 G |
2638 | "Topology Independent LFA (Loop-Free Alternate)\n" |
2639 | "TI-LFA node protection (default is link protection)\n") | |
7fd0729f G |
2640 | { |
2641 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
2642 | ||
2643 | ospf->ti_lfa_enabled = true; | |
2644 | ||
385a1e07 G |
2645 | if (argc == 3) |
2646 | ospf->ti_lfa_protection_type = OSPF_TI_LFA_NODE_PROTECTION; | |
2647 | else | |
2648 | ospf->ti_lfa_protection_type = OSPF_TI_LFA_LINK_PROTECTION; | |
2649 | ||
7fd0729f G |
2650 | ospf_spf_calculate_schedule(ospf, SPF_FLAG_CONFIG_CHANGE); |
2651 | ||
2652 | return CMD_SUCCESS; | |
2653 | } | |
2654 | ||
385a1e07 G |
2655 | DEFUN(no_ospf_ti_lfa, no_ospf_ti_lfa_cmd, |
2656 | "no fast-reroute ti-lfa [node-protection]", | |
7fd0729f G |
2657 | NO_STR |
2658 | "Fast Reroute for MPLS and IP resilience\n" | |
385a1e07 G |
2659 | "Topology Independent LFA (Loop-Free Alternate)\n" |
2660 | "TI-LFA node protection (default is link protection)\n") | |
7fd0729f G |
2661 | { |
2662 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
2663 | ||
2664 | ospf->ti_lfa_enabled = false; | |
2665 | ||
385a1e07 G |
2666 | ospf->ti_lfa_protection_type = OSPF_TI_LFA_UNDEFINED_PROTECTION; |
2667 | ||
7fd0729f G |
2668 | ospf_spf_calculate_schedule(ospf, SPF_FLAG_CONFIG_CHANGE); |
2669 | ||
2670 | return CMD_SUCCESS; | |
2671 | } | |
2672 | ||
3d5b9855 | 2673 | static void ospf_maxpath_set(struct vty *vty, struct ospf *ospf, uint16_t paths) |
2674 | { | |
2675 | if (ospf->max_multipath == paths) | |
2676 | return; | |
2677 | ||
2678 | ospf->max_multipath = paths; | |
2679 | ||
2680 | /* Send deletion notification to zebra to delete all | |
2681 | * ospf specific routes and reinitiat SPF to reflect | |
2682 | * the new max multipath. | |
2683 | */ | |
2684 | ospf_restart_spf(ospf); | |
2685 | } | |
2686 | ||
2687 | /* Ospf Maximum multiple paths config support */ | |
2688 | DEFUN (ospf_max_multipath, | |
2689 | ospf_max_multipath_cmd, | |
2690 | "maximum-paths " CMD_RANGE_STR(1, MULTIPATH_NUM), | |
2691 | "Max no of multiple paths for ECMP support\n" | |
2692 | "Number of paths\n") | |
2693 | { | |
2694 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
2695 | int idx_number = 1; | |
2696 | uint16_t maxpaths; | |
2697 | ||
2698 | maxpaths = strtol(argv[idx_number]->arg, NULL, 10); | |
2699 | ||
2700 | ospf_maxpath_set(vty, ospf, maxpaths); | |
2701 | return CMD_SUCCESS; | |
2702 | } | |
2703 | ||
2704 | DEFUN (no_ospf_max_multipath, | |
2705 | no_ospf_max_multipath_cmd, | |
2706 | "no maximum-paths", | |
2707 | NO_STR | |
2708 | "Max no of multiple paths for ECMP support\n") | |
2709 | { | |
2710 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
2711 | uint16_t maxpaths = MULTIPATH_NUM; | |
2712 | ||
2713 | ospf_maxpath_set(vty, ospf, maxpaths); | |
2714 | return CMD_SUCCESS; | |
2715 | } | |
2716 | ||
2b64873d DL |
2717 | static const char *const ospf_abr_type_descr_str[] = { |
2718 | "Unknown", "Standard (RFC2328)", "Alternative IBM", | |
2719 | "Alternative Cisco", "Alternative Shortcut" | |
2720 | }; | |
d62a17ae | 2721 | |
2b64873d DL |
2722 | static const char *const ospf_shortcut_mode_descr_str[] = { |
2723 | "Default", "Enabled", "Disabled" | |
2724 | }; | |
d62a17ae | 2725 | |
2726 | static void show_ip_ospf_area(struct vty *vty, struct ospf_area *area, | |
9f049418 | 2727 | json_object *json_areas, bool use_json) |
d62a17ae | 2728 | { |
2729 | json_object *json_area = NULL; | |
96b663a3 | 2730 | char buf[PREFIX_STRLEN]; |
d62a17ae | 2731 | |
2732 | if (use_json) | |
2733 | json_area = json_object_new_object(); | |
2734 | ||
2735 | /* Show Area ID. */ | |
2736 | if (!use_json) | |
96b663a3 | 2737 | vty_out(vty, " Area ID: %pI4", &area->area_id); |
d62a17ae | 2738 | |
2739 | /* Show Area type/mode. */ | |
2740 | if (OSPF_IS_AREA_BACKBONE(area)) { | |
2741 | if (use_json) | |
2742 | json_object_boolean_true_add(json_area, "backbone"); | |
2743 | else | |
2744 | vty_out(vty, " (Backbone)\n"); | |
2745 | } else { | |
2746 | if (use_json) { | |
2747 | if (area->external_routing == OSPF_AREA_STUB) { | |
2748 | if (area->no_summary) | |
2749 | json_object_boolean_true_add( | |
2750 | json_area, "stubNoSummary"); | |
2751 | if (area->shortcut_configured) | |
2752 | json_object_boolean_true_add( | |
2753 | json_area, "stubShortcut"); | |
2754 | } else if (area->external_routing == OSPF_AREA_NSSA) { | |
2755 | if (area->no_summary) | |
2756 | json_object_boolean_true_add( | |
2757 | json_area, "nssaNoSummary"); | |
2758 | if (area->shortcut_configured) | |
2759 | json_object_boolean_true_add( | |
2760 | json_area, "nssaShortcut"); | |
2761 | } | |
813d4307 | 2762 | |
d62a17ae | 2763 | json_object_string_add( |
2764 | json_area, "shortcuttingMode", | |
2765 | ospf_shortcut_mode_descr_str | |
2766 | [area->shortcut_configured]); | |
2767 | if (area->shortcut_capability) | |
2768 | json_object_boolean_true_add(json_area, | |
2769 | "sBitConcensus"); | |
2770 | } else { | |
2771 | if (area->external_routing == OSPF_AREA_STUB) | |
2772 | vty_out(vty, " (Stub%s%s)", | |
2773 | area->no_summary ? ", no summary" : "", | |
2774 | area->shortcut_configured ? "; " : ""); | |
2775 | else if (area->external_routing == OSPF_AREA_NSSA) | |
2776 | vty_out(vty, " (NSSA%s%s)", | |
2777 | area->no_summary ? ", no summary" : "", | |
2778 | area->shortcut_configured ? "; " : ""); | |
2779 | ||
2780 | vty_out(vty, "\n"); | |
2781 | vty_out(vty, " Shortcutting mode: %s", | |
2782 | ospf_shortcut_mode_descr_str | |
2783 | [area->shortcut_configured]); | |
2784 | vty_out(vty, ", S-bit consensus: %s\n", | |
2785 | area->shortcut_capability ? "ok" : "no"); | |
2786 | } | |
2787 | } | |
718e3744 | 2788 | |
d62a17ae | 2789 | /* Show number of interfaces */ |
2790 | if (use_json) { | |
2791 | json_object_int_add(json_area, "areaIfTotalCounter", | |
2792 | listcount(area->oiflist)); | |
2793 | json_object_int_add(json_area, "areaIfActiveCounter", | |
2794 | area->act_ints); | |
2795 | } else | |
2796 | vty_out(vty, | |
3efd0893 | 2797 | " Number of interfaces in this area: Total: %d, Active: %d\n", |
d62a17ae | 2798 | listcount(area->oiflist), area->act_ints); |
2799 | ||
2800 | if (area->external_routing == OSPF_AREA_NSSA) { | |
2801 | if (use_json) { | |
2802 | json_object_boolean_true_add(json_area, "nssa"); | |
2803 | if (!IS_OSPF_ABR(area->ospf)) | |
2804 | json_object_boolean_false_add(json_area, "abr"); | |
2805 | else if (area->NSSATranslatorState) { | |
2806 | json_object_boolean_true_add(json_area, "abr"); | |
2807 | if (area->NSSATranslatorRole | |
2808 | == OSPF_NSSA_ROLE_CANDIDATE) | |
2809 | json_object_boolean_true_add( | |
2810 | json_area, | |
2811 | "nssaTranslatorElected"); | |
2812 | else if (area->NSSATranslatorRole | |
2813 | == OSPF_NSSA_ROLE_ALWAYS) | |
2814 | json_object_boolean_true_add( | |
2815 | json_area, | |
2816 | "nssaTranslatorAlways"); | |
b79c3070 | 2817 | else |
2818 | json_object_boolean_true_add( | |
2819 | json_area, | |
2820 | "nssaTranslatorNever"); | |
d62a17ae | 2821 | } else { |
2822 | json_object_boolean_true_add(json_area, "abr"); | |
2823 | if (area->NSSATranslatorRole | |
2824 | == OSPF_NSSA_ROLE_CANDIDATE) | |
2825 | json_object_boolean_false_add( | |
2826 | json_area, | |
2827 | "nssaTranslatorElected"); | |
2828 | else | |
2829 | json_object_boolean_true_add( | |
2830 | json_area, | |
2831 | "nssaTranslatorNever"); | |
2832 | } | |
2833 | } else { | |
2834 | vty_out(vty, | |
b79c3070 | 2835 | " It is an NSSA configuration.\n Elected NSSA/ABR performs type-7/type-5 LSA translation.\n"); |
d62a17ae | 2836 | if (!IS_OSPF_ABR(area->ospf)) |
2837 | vty_out(vty, | |
b79c3070 | 2838 | " It is not ABR, therefore not Translator.\n"); |
d62a17ae | 2839 | else if (area->NSSATranslatorState) { |
2840 | vty_out(vty, " We are an ABR and "); | |
2841 | if (area->NSSATranslatorRole | |
2842 | == OSPF_NSSA_ROLE_CANDIDATE) | |
2843 | vty_out(vty, | |
b79c3070 | 2844 | "the NSSA Elected Translator.\n"); |
d62a17ae | 2845 | else if (area->NSSATranslatorRole |
2846 | == OSPF_NSSA_ROLE_ALWAYS) | |
2847 | vty_out(vty, | |
b79c3070 | 2848 | "always an NSSA Translator.\n"); |
2849 | else | |
2850 | vty_out(vty, | |
2851 | "never an NSSA Translator.\n"); | |
d62a17ae | 2852 | } else { |
2853 | vty_out(vty, " We are an ABR, but "); | |
2854 | if (area->NSSATranslatorRole | |
2855 | == OSPF_NSSA_ROLE_CANDIDATE) | |
2856 | vty_out(vty, | |
b79c3070 | 2857 | "not the NSSA Elected Translator.\n"); |
d62a17ae | 2858 | else |
2859 | vty_out(vty, | |
b79c3070 | 2860 | "never an NSSA Translator.\n"); |
d62a17ae | 2861 | } |
2862 | } | |
2863 | } | |
2864 | ||
2865 | /* Stub-router state for this area */ | |
2866 | if (CHECK_FLAG(area->stub_router_state, OSPF_AREA_IS_STUB_ROUTED)) { | |
2867 | char timebuf[OSPF_TIME_DUMP_SIZE]; | |
2868 | ||
2869 | if (use_json) { | |
2870 | json_object_boolean_true_add( | |
2871 | json_area, "originStubMaxDistRouterLsa"); | |
2872 | if (CHECK_FLAG(area->stub_router_state, | |
2873 | OSPF_AREA_ADMIN_STUB_ROUTED)) | |
2874 | json_object_boolean_true_add( | |
2875 | json_area, "indefiniteActiveAdmin"); | |
2876 | if (area->t_stub_router) { | |
2877 | long time_store; | |
2878 | time_store = | |
2879 | monotime_until( | |
2880 | &area->t_stub_router->u.sands, | |
2881 | NULL) | |
2882 | / 1000LL; | |
2883 | json_object_int_add( | |
2884 | json_area, | |
2885 | "activeStartupRemainderMsecs", | |
2886 | time_store); | |
2887 | } | |
2888 | } else { | |
2889 | vty_out(vty, | |
2890 | " Originating stub / maximum-distance Router-LSA\n"); | |
2891 | if (CHECK_FLAG(area->stub_router_state, | |
2892 | OSPF_AREA_ADMIN_STUB_ROUTED)) | |
2893 | vty_out(vty, | |
2894 | " Administratively activated (indefinitely)\n"); | |
2895 | if (area->t_stub_router) | |
2896 | vty_out(vty, | |
2897 | " Active from startup, %s remaining\n", | |
2898 | ospf_timer_dump(area->t_stub_router, | |
2899 | timebuf, | |
2900 | sizeof(timebuf))); | |
2901 | } | |
2902 | } | |
2903 | ||
2904 | if (use_json) { | |
2905 | /* Show number of fully adjacent neighbors. */ | |
2906 | json_object_int_add(json_area, "nbrFullAdjacentCounter", | |
2907 | area->full_nbrs); | |
2908 | ||
2909 | /* Show authentication type. */ | |
2910 | if (area->auth_type == OSPF_AUTH_NULL) | |
2911 | json_object_string_add(json_area, "authentication", | |
2912 | "authenticationNone"); | |
2913 | else if (area->auth_type == OSPF_AUTH_SIMPLE) | |
2914 | json_object_string_add(json_area, "authentication", | |
2915 | "authenticationSimplePassword"); | |
2916 | else if (area->auth_type == OSPF_AUTH_CRYPTOGRAPHIC) | |
2917 | json_object_string_add(json_area, "authentication", | |
2918 | "authenticationMessageDigest"); | |
2919 | ||
2920 | if (!OSPF_IS_AREA_BACKBONE(area)) | |
2921 | json_object_int_add(json_area, | |
2922 | "virtualAdjacenciesPassingCounter", | |
2923 | area->full_vls); | |
2924 | ||
2925 | /* Show SPF calculation times. */ | |
2926 | json_object_int_add(json_area, "spfExecutedCounter", | |
2927 | area->spf_calculation); | |
2928 | json_object_int_add(json_area, "lsaNumber", area->lsdb->total); | |
2929 | json_object_int_add( | |
2930 | json_area, "lsaRouterNumber", | |
2931 | ospf_lsdb_count(area->lsdb, OSPF_ROUTER_LSA)); | |
2932 | json_object_int_add( | |
2933 | json_area, "lsaRouterChecksum", | |
2934 | ospf_lsdb_checksum(area->lsdb, OSPF_ROUTER_LSA)); | |
2935 | json_object_int_add( | |
2936 | json_area, "lsaNetworkNumber", | |
2937 | ospf_lsdb_count(area->lsdb, OSPF_NETWORK_LSA)); | |
2938 | json_object_int_add( | |
2939 | json_area, "lsaNetworkChecksum", | |
2940 | ospf_lsdb_checksum(area->lsdb, OSPF_NETWORK_LSA)); | |
2941 | json_object_int_add( | |
2942 | json_area, "lsaSummaryNumber", | |
2943 | ospf_lsdb_count(area->lsdb, OSPF_SUMMARY_LSA)); | |
2944 | json_object_int_add( | |
2945 | json_area, "lsaSummaryChecksum", | |
2946 | ospf_lsdb_checksum(area->lsdb, OSPF_SUMMARY_LSA)); | |
2947 | json_object_int_add( | |
2948 | json_area, "lsaAsbrNumber", | |
2949 | ospf_lsdb_count(area->lsdb, OSPF_ASBR_SUMMARY_LSA)); | |
2950 | json_object_int_add( | |
2951 | json_area, "lsaAsbrChecksum", | |
2952 | ospf_lsdb_checksum(area->lsdb, OSPF_ASBR_SUMMARY_LSA)); | |
2953 | json_object_int_add( | |
2954 | json_area, "lsaNssaNumber", | |
2955 | ospf_lsdb_count(area->lsdb, OSPF_AS_NSSA_LSA)); | |
2956 | json_object_int_add( | |
2957 | json_area, "lsaNssaChecksum", | |
2958 | ospf_lsdb_checksum(area->lsdb, OSPF_AS_NSSA_LSA)); | |
2959 | } else { | |
2960 | /* Show number of fully adjacent neighbors. */ | |
2961 | vty_out(vty, | |
3efd0893 | 2962 | " Number of fully adjacent neighbors in this area: %d\n", |
d62a17ae | 2963 | area->full_nbrs); |
2964 | ||
2965 | /* Show authentication type. */ | |
2966 | vty_out(vty, " Area has "); | |
2967 | if (area->auth_type == OSPF_AUTH_NULL) | |
2968 | vty_out(vty, "no authentication\n"); | |
2969 | else if (area->auth_type == OSPF_AUTH_SIMPLE) | |
2970 | vty_out(vty, "simple password authentication\n"); | |
2971 | else if (area->auth_type == OSPF_AUTH_CRYPTOGRAPHIC) | |
2972 | vty_out(vty, "message digest authentication\n"); | |
2973 | ||
2974 | if (!OSPF_IS_AREA_BACKBONE(area)) | |
2975 | vty_out(vty, | |
3efd0893 | 2976 | " Number of full virtual adjacencies going through this area: %d\n", |
d62a17ae | 2977 | area->full_vls); |
2978 | ||
2979 | /* Show SPF calculation times. */ | |
2980 | vty_out(vty, " SPF algorithm executed %d times\n", | |
2981 | area->spf_calculation); | |
2982 | ||
2983 | /* Show number of LSA. */ | |
2984 | vty_out(vty, " Number of LSA %ld\n", area->lsdb->total); | |
2985 | vty_out(vty, | |
2986 | " Number of router LSA %ld. Checksum Sum 0x%08x\n", | |
2987 | ospf_lsdb_count(area->lsdb, OSPF_ROUTER_LSA), | |
2988 | ospf_lsdb_checksum(area->lsdb, OSPF_ROUTER_LSA)); | |
2989 | vty_out(vty, | |
2990 | " Number of network LSA %ld. Checksum Sum 0x%08x\n", | |
2991 | ospf_lsdb_count(area->lsdb, OSPF_NETWORK_LSA), | |
2992 | ospf_lsdb_checksum(area->lsdb, OSPF_NETWORK_LSA)); | |
2993 | vty_out(vty, | |
2994 | " Number of summary LSA %ld. Checksum Sum 0x%08x\n", | |
2995 | ospf_lsdb_count(area->lsdb, OSPF_SUMMARY_LSA), | |
2996 | ospf_lsdb_checksum(area->lsdb, OSPF_SUMMARY_LSA)); | |
2997 | vty_out(vty, | |
2998 | " Number of ASBR summary LSA %ld. Checksum Sum 0x%08x\n", | |
2999 | ospf_lsdb_count(area->lsdb, OSPF_ASBR_SUMMARY_LSA), | |
3000 | ospf_lsdb_checksum(area->lsdb, OSPF_ASBR_SUMMARY_LSA)); | |
3001 | vty_out(vty, " Number of NSSA LSA %ld. Checksum Sum 0x%08x\n", | |
3002 | ospf_lsdb_count(area->lsdb, OSPF_AS_NSSA_LSA), | |
3003 | ospf_lsdb_checksum(area->lsdb, OSPF_AS_NSSA_LSA)); | |
3004 | } | |
3005 | ||
3006 | if (use_json) { | |
3007 | json_object_int_add( | |
3008 | json_area, "lsaOpaqueLinkNumber", | |
3009 | ospf_lsdb_count(area->lsdb, OSPF_OPAQUE_LINK_LSA)); | |
3010 | json_object_int_add( | |
3011 | json_area, "lsaOpaqueLinkChecksum", | |
3012 | ospf_lsdb_checksum(area->lsdb, OSPF_OPAQUE_LINK_LSA)); | |
3013 | json_object_int_add( | |
3014 | json_area, "lsaOpaqueAreaNumber", | |
3015 | ospf_lsdb_count(area->lsdb, OSPF_OPAQUE_AREA_LSA)); | |
3016 | json_object_int_add( | |
3017 | json_area, "lsaOpaqueAreaChecksum", | |
3018 | ospf_lsdb_checksum(area->lsdb, OSPF_OPAQUE_AREA_LSA)); | |
3019 | } else { | |
3020 | vty_out(vty, | |
3021 | " Number of opaque link LSA %ld. Checksum Sum 0x%08x\n", | |
3022 | ospf_lsdb_count(area->lsdb, OSPF_OPAQUE_LINK_LSA), | |
3023 | ospf_lsdb_checksum(area->lsdb, OSPF_OPAQUE_LINK_LSA)); | |
3024 | vty_out(vty, | |
3025 | " Number of opaque area LSA %ld. Checksum Sum 0x%08x\n", | |
3026 | ospf_lsdb_count(area->lsdb, OSPF_OPAQUE_AREA_LSA), | |
3027 | ospf_lsdb_checksum(area->lsdb, OSPF_OPAQUE_AREA_LSA)); | |
3028 | } | |
718e3744 | 3029 | |
d62a17ae | 3030 | if (use_json) |
96b663a3 MS |
3031 | json_object_object_add(json_areas, |
3032 | inet_ntop(AF_INET, &area->area_id, | |
3033 | buf, sizeof(buf)), | |
d62a17ae | 3034 | json_area); |
3035 | else | |
3036 | vty_out(vty, "\n"); | |
718e3744 | 3037 | } |
3038 | ||
d62a17ae | 3039 | static int show_ip_ospf_common(struct vty *vty, struct ospf *ospf, |
d7c0a89a | 3040 | json_object *json, uint8_t use_vrf) |
d62a17ae | 3041 | { |
3042 | struct listnode *node, *nnode; | |
3043 | struct ospf_area *area; | |
3044 | struct timeval result; | |
3045 | char timebuf[OSPF_TIME_DUMP_SIZE]; | |
96b663a3 | 3046 | char buf[PREFIX_STRLEN]; |
b1c3ae8c | 3047 | json_object *json_vrf = NULL; |
d62a17ae | 3048 | json_object *json_areas = NULL; |
718e3744 | 3049 | |
b1c3ae8c CS |
3050 | if (json) { |
3051 | if (use_vrf) | |
3052 | json_vrf = json_object_new_object(); | |
3053 | else | |
3054 | json_vrf = json; | |
d62a17ae | 3055 | json_areas = json_object_new_object(); |
3056 | } | |
3057 | ||
3058 | if (ospf->instance) { | |
b1c3ae8c | 3059 | if (json) { |
d62a17ae | 3060 | json_object_int_add(json, "ospfInstance", |
3061 | ospf->instance); | |
3062 | } else { | |
3063 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
3064 | } | |
3065 | } | |
3066 | ||
b1c3ae8c | 3067 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); |
87bd50e8 | 3068 | |
d62a17ae | 3069 | /* Show Router ID. */ |
b1c3ae8c CS |
3070 | if (json) { |
3071 | json_object_string_add(json_vrf, "routerId", | |
96b663a3 MS |
3072 | inet_ntop(AF_INET, &ospf->router_id, |
3073 | buf, sizeof(buf))); | |
d62a17ae | 3074 | } else { |
96b663a3 MS |
3075 | vty_out(vty, " OSPF Routing Process, Router ID: %pI4\n", |
3076 | &ospf->router_id); | |
d62a17ae | 3077 | } |
3078 | ||
3079 | /* Graceful shutdown */ | |
3080 | if (ospf->t_deferred_shutdown) { | |
b1c3ae8c | 3081 | if (json) { |
d62a17ae | 3082 | long time_store; |
3083 | time_store = | |
3084 | monotime_until( | |
3085 | &ospf->t_deferred_shutdown->u.sands, | |
3086 | NULL) | |
3087 | / 1000LL; | |
b1c3ae8c | 3088 | json_object_int_add(json_vrf, "deferredShutdownMsecs", |
d62a17ae | 3089 | time_store); |
3090 | } else { | |
3091 | vty_out(vty, | |
3092 | " Deferred shutdown in progress, %s remaining\n", | |
3093 | ospf_timer_dump(ospf->t_deferred_shutdown, | |
3094 | timebuf, sizeof(timebuf))); | |
3095 | } | |
3096 | } | |
3097 | ||
3098 | /* Show capability. */ | |
b1c3ae8c CS |
3099 | if (json) { |
3100 | json_object_boolean_true_add(json_vrf, "tosRoutesOnly"); | |
3101 | json_object_boolean_true_add(json_vrf, "rfc2328Conform"); | |
d62a17ae | 3102 | if (CHECK_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE)) { |
b1c3ae8c | 3103 | json_object_boolean_true_add(json_vrf, |
d62a17ae | 3104 | "rfc1583Compatibility"); |
3105 | } | |
3106 | } else { | |
3107 | vty_out(vty, " Supports only single TOS (TOS0) routes\n"); | |
3108 | vty_out(vty, " This implementation conforms to RFC2328\n"); | |
3109 | vty_out(vty, " RFC1583Compatibility flag is %s\n", | |
3110 | CHECK_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE) | |
3111 | ? "enabled" | |
3112 | : "disabled"); | |
3113 | } | |
3114 | ||
b1c3ae8c | 3115 | if (json) { |
d62a17ae | 3116 | if (CHECK_FLAG(ospf->config, OSPF_OPAQUE_CAPABLE)) { |
b1c3ae8c | 3117 | json_object_boolean_true_add(json_vrf, "opaqueCapable"); |
d62a17ae | 3118 | } |
3119 | } else { | |
3120 | vty_out(vty, " OpaqueCapability flag is %s\n", | |
3121 | CHECK_FLAG(ospf->config, OSPF_OPAQUE_CAPABLE) | |
3122 | ? "enabled" | |
3123 | : "disabled"); | |
3124 | } | |
3125 | ||
3126 | /* Show stub-router configuration */ | |
3127 | if (ospf->stub_router_startup_time != OSPF_STUB_ROUTER_UNCONFIGURED | |
3128 | || ospf->stub_router_shutdown_time | |
3129 | != OSPF_STUB_ROUTER_UNCONFIGURED) { | |
b1c3ae8c CS |
3130 | if (json) { |
3131 | json_object_boolean_true_add(json_vrf, | |
3132 | "stubAdvertisement"); | |
d62a17ae | 3133 | if (ospf->stub_router_startup_time |
3134 | != OSPF_STUB_ROUTER_UNCONFIGURED) | |
3135 | json_object_int_add( | |
50ad4b42 MS |
3136 | json_vrf, "postStartEnabledSecs", |
3137 | ospf->stub_router_startup_time); | |
d62a17ae | 3138 | if (ospf->stub_router_shutdown_time |
3139 | != OSPF_STUB_ROUTER_UNCONFIGURED) | |
3140 | json_object_int_add( | |
50ad4b42 MS |
3141 | json_vrf, "preShutdownEnabledSecs", |
3142 | ospf->stub_router_shutdown_time); | |
d62a17ae | 3143 | } else { |
3144 | vty_out(vty, | |
3145 | " Stub router advertisement is configured\n"); | |
3146 | if (ospf->stub_router_startup_time | |
3147 | != OSPF_STUB_ROUTER_UNCONFIGURED) | |
3148 | vty_out(vty, | |
3149 | " Enabled for %us after start-up\n", | |
3150 | ospf->stub_router_startup_time); | |
3151 | if (ospf->stub_router_shutdown_time | |
3152 | != OSPF_STUB_ROUTER_UNCONFIGURED) | |
3153 | vty_out(vty, | |
3154 | " Enabled for %us prior to full shutdown\n", | |
3155 | ospf->stub_router_shutdown_time); | |
3156 | } | |
3157 | } | |
3158 | ||
3159 | /* Show SPF timers. */ | |
b1c3ae8c CS |
3160 | if (json) { |
3161 | json_object_int_add(json_vrf, "spfScheduleDelayMsecs", | |
d62a17ae | 3162 | ospf->spf_delay); |
b1c3ae8c | 3163 | json_object_int_add(json_vrf, "holdtimeMinMsecs", |
d62a17ae | 3164 | ospf->spf_holdtime); |
b1c3ae8c | 3165 | json_object_int_add(json_vrf, "holdtimeMaxMsecs", |
d62a17ae | 3166 | ospf->spf_max_holdtime); |
b1c3ae8c | 3167 | json_object_int_add(json_vrf, "holdtimeMultplier", |
d62a17ae | 3168 | ospf->spf_hold_multiplier); |
3169 | } else { | |
3170 | vty_out(vty, | |
3171 | " Initial SPF scheduling delay %d millisec(s)\n" | |
3172 | " Minimum hold time between consecutive SPFs %d millisec(s)\n" | |
3173 | " Maximum hold time between consecutive SPFs %d millisec(s)\n" | |
3174 | " Hold time multiplier is currently %d\n", | |
3175 | ospf->spf_delay, ospf->spf_holdtime, | |
3176 | ospf->spf_max_holdtime, ospf->spf_hold_multiplier); | |
3177 | } | |
3178 | ||
b1c3ae8c | 3179 | if (json) { |
d62a17ae | 3180 | if (ospf->ts_spf.tv_sec || ospf->ts_spf.tv_usec) { |
3181 | long time_store = 0; | |
3182 | ||
3183 | time_store = | |
3184 | monotime_since(&ospf->ts_spf, NULL) / 1000LL; | |
b1c3ae8c | 3185 | json_object_int_add(json_vrf, "spfLastExecutedMsecs", |
d62a17ae | 3186 | time_store); |
3187 | ||
3188 | time_store = (1000 * ospf->ts_spf_duration.tv_sec) | |
3189 | + (ospf->ts_spf_duration.tv_usec / 1000); | |
b1c3ae8c | 3190 | json_object_int_add(json_vrf, "spfLastDurationMsecs", |
d62a17ae | 3191 | time_store); |
3192 | } else | |
b1c3ae8c | 3193 | json_object_boolean_true_add(json_vrf, "spfHasNotRun"); |
d62a17ae | 3194 | } else { |
3195 | vty_out(vty, " SPF algorithm "); | |
3196 | if (ospf->ts_spf.tv_sec || ospf->ts_spf.tv_usec) { | |
3197 | monotime_since(&ospf->ts_spf, &result); | |
3198 | vty_out(vty, "last executed %s ago\n", | |
3199 | ospf_timeval_dump(&result, timebuf, | |
3200 | sizeof(timebuf))); | |
3201 | vty_out(vty, " Last SPF duration %s\n", | |
3202 | ospf_timeval_dump(&ospf->ts_spf_duration, | |
3203 | timebuf, sizeof(timebuf))); | |
3204 | } else | |
3205 | vty_out(vty, "has not been run\n"); | |
3206 | } | |
3207 | ||
b1c3ae8c | 3208 | if (json) { |
d62a17ae | 3209 | if (ospf->t_spf_calc) { |
3210 | long time_store; | |
3211 | time_store = | |
3212 | monotime_until(&ospf->t_spf_calc->u.sands, NULL) | |
3213 | / 1000LL; | |
b1c3ae8c | 3214 | json_object_int_add(json_vrf, "spfTimerDueInMsecs", |
d62a17ae | 3215 | time_store); |
3216 | } | |
3217 | ||
b1c3ae8c | 3218 | json_object_int_add(json_vrf, "lsaMinIntervalMsecs", |
d62a17ae | 3219 | ospf->min_ls_interval); |
b1c3ae8c | 3220 | json_object_int_add(json_vrf, "lsaMinArrivalMsecs", |
d62a17ae | 3221 | ospf->min_ls_arrival); |
3222 | /* Show write multiplier values */ | |
b1c3ae8c | 3223 | json_object_int_add(json_vrf, "writeMultiplier", |
d62a17ae | 3224 | ospf->write_oi_count); |
3225 | /* Show refresh parameters. */ | |
b1c3ae8c | 3226 | json_object_int_add(json_vrf, "refreshTimerMsecs", |
d62a17ae | 3227 | ospf->lsa_refresh_interval * 1000); |
3228 | } else { | |
3229 | vty_out(vty, " SPF timer %s%s\n", | |
3230 | (ospf->t_spf_calc ? "due in " : "is "), | |
3231 | ospf_timer_dump(ospf->t_spf_calc, timebuf, | |
3232 | sizeof(timebuf))); | |
3233 | ||
3234 | vty_out(vty, " LSA minimum interval %d msecs\n", | |
3235 | ospf->min_ls_interval); | |
3236 | vty_out(vty, " LSA minimum arrival %d msecs\n", | |
3237 | ospf->min_ls_arrival); | |
3238 | ||
3239 | /* Show write multiplier values */ | |
3240 | vty_out(vty, " Write Multiplier set to %d \n", | |
3241 | ospf->write_oi_count); | |
3242 | ||
3243 | /* Show refresh parameters. */ | |
3244 | vty_out(vty, " Refresh timer %d secs\n", | |
3245 | ospf->lsa_refresh_interval); | |
3d5b9855 | 3246 | |
3247 | /* show max multipath */ | |
3248 | vty_out(vty, " Maximum multiple paths(ECMP) supported %d\n", | |
3249 | ospf->max_multipath); | |
d62a17ae | 3250 | } |
3251 | ||
3252 | /* Show ABR/ASBR flags. */ | |
3253 | if (CHECK_FLAG(ospf->flags, OSPF_FLAG_ABR)) { | |
b1c3ae8c | 3254 | if (json) |
d62a17ae | 3255 | json_object_string_add( |
b1c3ae8c | 3256 | json_vrf, "abrType", |
d62a17ae | 3257 | ospf_abr_type_descr_str[ospf->abr_type]); |
3258 | else | |
3259 | vty_out(vty, | |
3260 | " This router is an ABR, ABR type is: %s\n", | |
3261 | ospf_abr_type_descr_str[ospf->abr_type]); | |
3262 | } | |
3263 | if (CHECK_FLAG(ospf->flags, OSPF_FLAG_ASBR)) { | |
b1c3ae8c | 3264 | if (json) |
d62a17ae | 3265 | json_object_string_add( |
b1c3ae8c | 3266 | json_vrf, "asbrRouter", |
d62a17ae | 3267 | "injectingExternalRoutingInformation"); |
3268 | else | |
3269 | vty_out(vty, | |
3efd0893 | 3270 | " This router is an ASBR (injecting external routing information)\n"); |
d62a17ae | 3271 | } |
3272 | ||
3273 | /* Show Number of AS-external-LSAs. */ | |
b1c3ae8c | 3274 | if (json) { |
d62a17ae | 3275 | json_object_int_add( |
b1c3ae8c | 3276 | json_vrf, "lsaExternalCounter", |
d62a17ae | 3277 | ospf_lsdb_count(ospf->lsdb, OSPF_AS_EXTERNAL_LSA)); |
3278 | json_object_int_add( | |
b1c3ae8c | 3279 | json_vrf, "lsaExternalChecksum", |
d62a17ae | 3280 | ospf_lsdb_checksum(ospf->lsdb, OSPF_AS_EXTERNAL_LSA)); |
3281 | } else { | |
3282 | vty_out(vty, | |
3283 | " Number of external LSA %ld. Checksum Sum 0x%08x\n", | |
3284 | ospf_lsdb_count(ospf->lsdb, OSPF_AS_EXTERNAL_LSA), | |
3285 | ospf_lsdb_checksum(ospf->lsdb, OSPF_AS_EXTERNAL_LSA)); | |
3286 | } | |
3287 | ||
b1c3ae8c | 3288 | if (json) { |
d62a17ae | 3289 | json_object_int_add( |
b1c3ae8c | 3290 | json_vrf, "lsaAsopaqueCounter", |
d62a17ae | 3291 | ospf_lsdb_count(ospf->lsdb, OSPF_OPAQUE_AS_LSA)); |
3292 | json_object_int_add( | |
b1c3ae8c | 3293 | json_vrf, "lsaAsOpaqueChecksum", |
d62a17ae | 3294 | ospf_lsdb_checksum(ospf->lsdb, OSPF_OPAQUE_AS_LSA)); |
3295 | } else { | |
3296 | vty_out(vty, | |
3297 | " Number of opaque AS LSA %ld. Checksum Sum 0x%08x\n", | |
3298 | ospf_lsdb_count(ospf->lsdb, OSPF_OPAQUE_AS_LSA), | |
3299 | ospf_lsdb_checksum(ospf->lsdb, OSPF_OPAQUE_AS_LSA)); | |
3300 | } | |
3301 | ||
3302 | /* Show number of areas attached. */ | |
b1c3ae8c CS |
3303 | if (json) |
3304 | json_object_int_add(json_vrf, "attachedAreaCounter", | |
d62a17ae | 3305 | listcount(ospf->areas)); |
3306 | else | |
3307 | vty_out(vty, " Number of areas attached to this router: %d\n", | |
3308 | listcount(ospf->areas)); | |
3309 | ||
3310 | if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES)) { | |
3311 | if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL)) { | |
b1c3ae8c | 3312 | if (json) |
d62a17ae | 3313 | json_object_boolean_true_add( |
b1c3ae8c | 3314 | json_vrf, "adjacencyChangesLoggedAll"); |
d62a17ae | 3315 | else |
3316 | vty_out(vty, | |
3317 | " All adjacency changes are logged\n"); | |
3318 | } else { | |
b1c3ae8c | 3319 | if (json) |
d62a17ae | 3320 | json_object_boolean_true_add( |
b1c3ae8c | 3321 | json_vrf, "adjacencyChangesLogged"); |
d62a17ae | 3322 | else |
3323 | vty_out(vty, " Adjacency changes are logged\n"); | |
3324 | } | |
3325 | } | |
132a782e | 3326 | |
3327 | /* show LDP-Sync status */ | |
3328 | ospf_ldp_sync_show_info(vty, ospf, json_vrf, json ? 1 : 0); | |
3329 | ||
d62a17ae | 3330 | /* Show each area status. */ |
3331 | for (ALL_LIST_ELEMENTS(ospf->areas, node, nnode, area)) | |
b1c3ae8c CS |
3332 | show_ip_ospf_area(vty, area, json_areas, json ? 1 : 0); |
3333 | ||
3334 | if (json) { | |
3335 | if (use_vrf) { | |
3336 | json_object_object_add(json_vrf, "areas", json_areas); | |
44076f4d RW |
3337 | json_object_object_add(json, ospf_get_name(ospf), |
3338 | json_vrf); | |
b1c3ae8c CS |
3339 | } else { |
3340 | json_object_object_add(json, "areas", json_areas); | |
3341 | } | |
d62a17ae | 3342 | } else |
3343 | vty_out(vty, "\n"); | |
3344 | ||
3345 | return CMD_SUCCESS; | |
718e3744 | 3346 | } |
3347 | ||
7c8ff89e DS |
3348 | DEFUN (show_ip_ospf, |
3349 | show_ip_ospf_cmd, | |
b5a8894d | 3350 | "show ip ospf [vrf <NAME|all>] [json]", |
7c8ff89e DS |
3351 | SHOW_STR |
3352 | IP_STR | |
ca08c43d | 3353 | "OSPF information\n" |
b5a8894d CS |
3354 | VRF_CMD_HELP_STR |
3355 | "All VRFs\n" | |
9973d184 | 3356 | JSON_STR) |
7c8ff89e | 3357 | { |
d62a17ae | 3358 | struct ospf *ospf; |
9f049418 | 3359 | bool uj = use_json(argc, argv); |
b5a8894d CS |
3360 | struct listnode *node = NULL; |
3361 | char *vrf_name = NULL; | |
2951a7a4 | 3362 | bool all_vrf = false; |
b5a8894d CS |
3363 | int ret = CMD_SUCCESS; |
3364 | int inst = 0; | |
3365 | int idx_vrf = 0; | |
b1c3ae8c | 3366 | json_object *json = NULL; |
d7c0a89a | 3367 | uint8_t use_vrf = 0; |
7c8ff89e | 3368 | |
b5a8894d | 3369 | if (listcount(om->ospf) == 0) |
d62a17ae | 3370 | return CMD_SUCCESS; |
7c8ff89e | 3371 | |
43b8d1d8 | 3372 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
b5a8894d | 3373 | |
b1c3ae8c CS |
3374 | if (uj) |
3375 | json = json_object_new_object(); | |
3376 | ||
996c9314 | 3377 | /* vrf input is provided could be all or specific vrf*/ |
b5a8894d | 3378 | if (vrf_name) { |
2951a7a4 | 3379 | bool ospf_output = false; |
874f58d8 | 3380 | |
b1c3ae8c | 3381 | use_vrf = 1; |
94d4c685 | 3382 | |
b5a8894d CS |
3383 | if (all_vrf) { |
3384 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
3385 | if (!ospf->oi_running) | |
3386 | continue; | |
2951a7a4 | 3387 | ospf_output = true; |
b1c3ae8c CS |
3388 | ret = show_ip_ospf_common(vty, ospf, json, |
3389 | use_vrf); | |
3390 | } | |
3391 | if (uj) { | |
3392 | vty_out(vty, "%s\n", | |
996c9314 LB |
3393 | json_object_to_json_string_ext( |
3394 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 3395 | json_object_free(json); |
9f049418 DS |
3396 | } else if (!ospf_output) |
3397 | vty_out(vty, "%% OSPF instance not found\n"); | |
b5a8894d CS |
3398 | return ret; |
3399 | } | |
3400 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
b1c3ae8c | 3401 | if ((ospf == NULL) || !ospf->oi_running) { |
9f049418 DS |
3402 | if (uj) { |
3403 | vty_out(vty, "%s\n", | |
3404 | json_object_to_json_string_ext( | |
3405 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 3406 | json_object_free(json); |
9f049418 | 3407 | } else |
94d4c685 | 3408 | vty_out(vty, "%% OSPF instance not found\n"); |
9f049418 | 3409 | |
b5a8894d | 3410 | return CMD_SUCCESS; |
b1c3ae8c | 3411 | } |
b5a8894d CS |
3412 | } else { |
3413 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
3414 | /* Display default ospf (instance 0) info */ | |
b1c3ae8c | 3415 | if (ospf == NULL || !ospf->oi_running) { |
9f049418 DS |
3416 | if (uj) { |
3417 | vty_out(vty, "%s\n", | |
3418 | json_object_to_json_string_ext( | |
3419 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 3420 | json_object_free(json); |
9f049418 | 3421 | } else |
94d4c685 | 3422 | vty_out(vty, "%% OSPF instance not found\n"); |
9f049418 | 3423 | |
b5a8894d | 3424 | return CMD_SUCCESS; |
b1c3ae8c | 3425 | } |
b5a8894d CS |
3426 | } |
3427 | ||
996c9314 | 3428 | if (ospf) { |
b1c3ae8c CS |
3429 | show_ip_ospf_common(vty, ospf, json, use_vrf); |
3430 | if (uj) | |
996c9314 LB |
3431 | vty_out(vty, "%s\n", |
3432 | json_object_to_json_string_ext( | |
3433 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c CS |
3434 | } |
3435 | ||
3436 | if (uj) | |
3437 | json_object_free(json); | |
b5a8894d CS |
3438 | |
3439 | return ret; | |
7c8ff89e DS |
3440 | } |
3441 | ||
3442 | DEFUN (show_ip_ospf_instance, | |
3443 | show_ip_ospf_instance_cmd, | |
6147e2c6 | 3444 | "show ip ospf (1-65535) [json]", |
7c8ff89e DS |
3445 | SHOW_STR |
3446 | IP_STR | |
3447 | "OSPF information\n" | |
ca08c43d | 3448 | "Instance ID\n" |
9973d184 | 3449 | JSON_STR) |
7c8ff89e | 3450 | { |
d62a17ae | 3451 | int idx_number = 3; |
3452 | struct ospf *ospf; | |
d7c0a89a | 3453 | unsigned short instance = 0; |
9f049418 | 3454 | bool uj = use_json(argc, argv); |
b1c3ae8c CS |
3455 | int ret = CMD_SUCCESS; |
3456 | json_object *json = NULL; | |
d62a17ae | 3457 | |
3458 | instance = strtoul(argv[idx_number]->arg, NULL, 10); | |
409f98ab | 3459 | if (instance != ospf_instance) |
ac28e4ec CS |
3460 | return CMD_NOT_MY_INSTANCE; |
3461 | ||
409f98ab IR |
3462 | ospf = ospf_lookup_instance(instance); |
3463 | if (!ospf || !ospf->oi_running) | |
d62a17ae | 3464 | return CMD_SUCCESS; |
3465 | ||
b1c3ae8c CS |
3466 | if (uj) |
3467 | json = json_object_new_object(); | |
3468 | ||
3469 | ret = show_ip_ospf_common(vty, ospf, json, 0); | |
3470 | ||
3471 | if (uj) { | |
996c9314 LB |
3472 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
3473 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c CS |
3474 | json_object_free(json); |
3475 | } | |
3476 | ||
3477 | return ret; | |
d62a17ae | 3478 | } |
3479 | ||
49498934 | 3480 | static void ospf_interface_auth_show(struct vty *vty, struct ospf_interface *oi, |
3481 | json_object *json, bool use_json) | |
3482 | { | |
3483 | int auth_type; | |
3484 | ||
3485 | auth_type = OSPF_IF_PARAM(oi, auth_type); | |
3486 | ||
3487 | switch (auth_type) { | |
3488 | case OSPF_AUTH_NULL: | |
3489 | if (use_json) | |
3490 | json_object_string_add(json, "authentication", | |
3491 | "authenticationNone"); | |
3492 | else | |
3493 | vty_out(vty, " Authentication NULL is enabled\n"); | |
3494 | break; | |
3495 | case OSPF_AUTH_SIMPLE: { | |
3496 | if (use_json) | |
3497 | json_object_string_add(json, "authentication", | |
3498 | "authenticationSimplePassword"); | |
3499 | else | |
3500 | vty_out(vty, | |
3501 | " Simple password authentication enabled\n"); | |
3502 | break; | |
3503 | } | |
3504 | case OSPF_AUTH_CRYPTOGRAPHIC: { | |
3505 | struct crypt_key *ckey; | |
3506 | ||
3507 | if (list_isempty(OSPF_IF_PARAM(oi, auth_crypt))) | |
3508 | return; | |
3509 | ||
3510 | ckey = listgetdata(listtail(OSPF_IF_PARAM(oi, auth_crypt))); | |
3511 | if (ckey) { | |
3512 | if (use_json) { | |
3513 | json_object_string_add(json, "authentication", | |
3514 | "authenticationMessageDigest"); | |
3515 | } else { | |
3516 | vty_out(vty, | |
3517 | " Cryptographic authentication enabled\n"); | |
3518 | vty_out(vty, " Algorithm:MD5\n"); | |
3519 | } | |
3520 | } | |
3521 | break; | |
3522 | } | |
3523 | default: | |
3524 | break; | |
3525 | } | |
3526 | } | |
3527 | ||
d62a17ae | 3528 | static void show_ip_ospf_interface_sub(struct vty *vty, struct ospf *ospf, |
3529 | struct interface *ifp, | |
3530 | json_object *json_interface_sub, | |
9f049418 | 3531 | bool use_json) |
d62a17ae | 3532 | { |
3533 | int is_up; | |
3534 | struct ospf_neighbor *nbr; | |
3535 | struct route_node *rn; | |
96b663a3 | 3536 | char buf[PREFIX_STRLEN]; |
d62a17ae | 3537 | uint32_t bandwidth = ifp->bandwidth ? ifp->bandwidth : ifp->speed; |
3538 | ||
3539 | /* Is interface up? */ | |
3540 | if (use_json) { | |
3541 | is_up = if_is_operative(ifp); | |
3542 | if (is_up) | |
3543 | json_object_boolean_true_add(json_interface_sub, | |
3544 | "ifUp"); | |
3545 | else | |
3546 | json_object_boolean_false_add(json_interface_sub, | |
3547 | "ifDown"); | |
3548 | ||
3549 | json_object_int_add(json_interface_sub, "ifIndex", | |
3550 | ifp->ifindex); | |
3551 | json_object_int_add(json_interface_sub, "mtuBytes", ifp->mtu); | |
3552 | json_object_int_add(json_interface_sub, "bandwidthMbit", | |
3553 | bandwidth); | |
3554 | json_object_string_add(json_interface_sub, "ifFlags", | |
3555 | if_flag_dump(ifp->flags)); | |
3556 | } else { | |
3557 | vty_out(vty, "%s is %s\n", ifp->name, | |
3558 | ((is_up = if_is_operative(ifp)) ? "up" : "down")); | |
3559 | vty_out(vty, " ifindex %u, MTU %u bytes, BW %u Mbit %s\n", | |
3560 | ifp->ifindex, ifp->mtu, bandwidth, | |
3561 | if_flag_dump(ifp->flags)); | |
3562 | } | |
7c8ff89e | 3563 | |
d62a17ae | 3564 | /* Is interface OSPF enabled? */ |
3565 | if (use_json) { | |
3566 | if (ospf_oi_count(ifp) == 0) { | |
3567 | json_object_boolean_false_add(json_interface_sub, | |
3568 | "ospfEnabled"); | |
3569 | return; | |
3570 | } else if (!is_up) { | |
3571 | json_object_boolean_false_add(json_interface_sub, | |
3572 | "ospfRunning"); | |
3573 | return; | |
3574 | } else | |
3575 | json_object_boolean_true_add(json_interface_sub, | |
3576 | "ospfEnabled"); | |
3577 | } else { | |
3578 | if (ospf_oi_count(ifp) == 0) { | |
3579 | vty_out(vty, " OSPF not enabled on this interface\n"); | |
3580 | return; | |
3581 | } else if (!is_up) { | |
3582 | vty_out(vty, | |
3583 | " OSPF is enabled, but not running on this interface\n"); | |
3584 | return; | |
3585 | } | |
3586 | } | |
3587 | ||
3588 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { | |
3589 | struct ospf_interface *oi = rn->info; | |
3590 | ||
3591 | if (oi == NULL) | |
3592 | continue; | |
3593 | ||
3594 | if (CHECK_FLAG(oi->connected->flags, ZEBRA_IFA_UNNUMBERED)) { | |
3595 | if (use_json) | |
3596 | json_object_boolean_true_add(json_interface_sub, | |
3597 | "ifUnnumbered"); | |
3598 | else | |
3599 | vty_out(vty, " This interface is UNNUMBERED,"); | |
3600 | } else { | |
0f3af738 JW |
3601 | struct in_addr dest; |
3602 | const char *dstr; | |
3603 | ||
d62a17ae | 3604 | /* Show OSPF interface information. */ |
3605 | if (use_json) { | |
3606 | json_object_string_add( | |
3607 | json_interface_sub, "ipAddress", | |
96b663a3 MS |
3608 | inet_ntop(AF_INET, |
3609 | &oi->address->u.prefix4, | |
3610 | buf, sizeof(buf))); | |
d62a17ae | 3611 | json_object_int_add(json_interface_sub, |
3612 | "ipAddressPrefixlen", | |
3613 | oi->address->prefixlen); | |
3614 | } else | |
ae32e1c2 DS |
3615 | vty_out(vty, " Internet Address %pFX,", |
3616 | oi->address); | |
d62a17ae | 3617 | |
0f3af738 JW |
3618 | /* For Vlinks, showing the peer address is |
3619 | * probably more informative than the local | |
3620 | * interface that is being used */ | |
3621 | if (oi->type == OSPF_IFTYPE_VIRTUALLINK) { | |
3622 | dstr = "Peer"; | |
3623 | dest = oi->vl_data->peer_addr; | |
3624 | } else if (CONNECTED_PEER(oi->connected) | |
3625 | && oi->connected->destination) { | |
3626 | dstr = "Peer"; | |
3627 | dest = oi->connected->destination->u.prefix4; | |
3628 | } else { | |
3629 | dstr = "Broadcast"; | |
3630 | dest.s_addr = ipv4_broadcast_addr( | |
3631 | oi->connected->address->u.prefix4.s_addr, | |
3632 | oi->connected->address->prefixlen); | |
3633 | } | |
d62a17ae | 3634 | |
0f3af738 JW |
3635 | if (use_json) { |
3636 | json_object_string_add( | |
3637 | json_interface_sub, | |
3638 | "ospfIfType", dstr); | |
d62a17ae | 3639 | if (oi->type == OSPF_IFTYPE_VIRTUALLINK) |
0f3af738 JW |
3640 | json_object_string_add( |
3641 | json_interface_sub, | |
3642 | "vlinkPeer", | |
96b663a3 MS |
3643 | inet_ntop(AF_INET, &dest, |
3644 | buf, sizeof(buf))); | |
d62a17ae | 3645 | else |
d62a17ae | 3646 | json_object_string_add( |
3647 | json_interface_sub, | |
0f3af738 | 3648 | "localIfUsed", |
96b663a3 MS |
3649 | inet_ntop(AF_INET, &dest, |
3650 | buf, sizeof(buf))); | |
0f3af738 | 3651 | } else |
96b663a3 MS |
3652 | vty_out(vty, " %s %pI4,", dstr, |
3653 | &dest); | |
d62a17ae | 3654 | } |
3655 | if (use_json) { | |
3656 | json_object_string_add(json_interface_sub, "area", | |
3657 | ospf_area_desc_string(oi->area)); | |
3658 | if (OSPF_IF_PARAM(oi, mtu_ignore)) | |
3659 | json_object_boolean_true_add( | |
3660 | json_interface_sub, | |
3661 | "mtuMismatchDetect"); | |
96b663a3 MS |
3662 | json_object_string_add( |
3663 | json_interface_sub, "routerId", | |
3664 | inet_ntop(AF_INET, &ospf->router_id, | |
3665 | buf, sizeof(buf))); | |
d62a17ae | 3666 | json_object_string_add(json_interface_sub, |
3667 | "networkType", | |
3668 | ospf_network_type_str[oi->type]); | |
3669 | json_object_int_add(json_interface_sub, "cost", | |
3670 | oi->output_cost); | |
3671 | json_object_int_add( | |
50ad4b42 MS |
3672 | json_interface_sub, "transmitDelaySecs", |
3673 | OSPF_IF_PARAM(oi, transmit_delay)); | |
d62a17ae | 3674 | json_object_string_add(json_interface_sub, "state", |
3675 | lookup_msg(ospf_ism_state_msg, | |
3676 | oi->state, NULL)); | |
3677 | json_object_int_add(json_interface_sub, "priority", | |
3678 | PRIORITY(oi)); | |
3679 | } else { | |
3680 | vty_out(vty, " Area %s\n", | |
3681 | ospf_area_desc_string(oi->area)); | |
3682 | ||
3683 | vty_out(vty, " MTU mismatch detection: %s\n", | |
3684 | OSPF_IF_PARAM(oi, mtu_ignore) ? "disabled" | |
3685 | : "enabled"); | |
3686 | ||
3687 | vty_out(vty, | |
96b663a3 MS |
3688 | " Router ID %pI4, Network Type %s, Cost: %d\n", |
3689 | &ospf->router_id, | |
d62a17ae | 3690 | ospf_network_type_str[oi->type], |
3691 | oi->output_cost); | |
3692 | ||
3693 | vty_out(vty, | |
3694 | " Transmit Delay is %d sec, State %s, Priority %d\n", | |
3695 | OSPF_IF_PARAM(oi, transmit_delay), | |
3696 | lookup_msg(ospf_ism_state_msg, oi->state, NULL), | |
3697 | PRIORITY(oi)); | |
3698 | } | |
3699 | ||
3700 | /* Show DR information. */ | |
975a328e | 3701 | if (DR(oi).s_addr == INADDR_ANY) { |
d62a17ae | 3702 | if (!use_json) |
3703 | vty_out(vty, | |
3704 | " No backup designated router on this network\n"); | |
3705 | } else { | |
2fbb8f45 | 3706 | nbr = ospf_nbr_lookup_by_addr(oi->nbrs, &DR(oi)); |
3707 | if (nbr) { | |
3708 | if (use_json) { | |
3709 | json_object_string_add( | |
3710 | json_interface_sub, "drId", | |
3711 | inet_ntop(AF_INET, | |
3712 | &nbr->router_id, buf, | |
3713 | sizeof(buf))); | |
3714 | json_object_string_add( | |
3715 | json_interface_sub, "drAddress", | |
3716 | inet_ntop( | |
3717 | AF_INET, | |
3718 | &nbr->address.u.prefix4, | |
3719 | buf, sizeof(buf))); | |
3720 | } else { | |
3721 | vty_out(vty, | |
3722 | " Designated Router (ID) %pI4", | |
3723 | &nbr->router_id); | |
3724 | vty_out(vty, | |
3725 | " Interface Address %pFX\n", | |
3726 | &nbr->address); | |
3727 | } | |
3728 | } | |
3729 | nbr = NULL; | |
3730 | ||
d62a17ae | 3731 | nbr = ospf_nbr_lookup_by_addr(oi->nbrs, &BDR(oi)); |
3732 | if (nbr == NULL) { | |
3733 | if (!use_json) | |
3734 | vty_out(vty, | |
3735 | " No backup designated router on this network\n"); | |
3736 | } else { | |
3737 | if (use_json) { | |
3738 | json_object_string_add( | |
3739 | json_interface_sub, "bdrId", | |
96b663a3 MS |
3740 | inet_ntop(AF_INET, |
3741 | &nbr->router_id, | |
3742 | buf, sizeof(buf))); | |
d62a17ae | 3743 | json_object_string_add( |
3744 | json_interface_sub, | |
3745 | "bdrAddress", | |
96b663a3 MS |
3746 | inet_ntop(AF_INET, |
3747 | &nbr->address.u | |
3748 | .prefix4, | |
3749 | buf, sizeof(buf))); | |
d62a17ae | 3750 | } else { |
3751 | vty_out(vty, | |
96b663a3 MS |
3752 | " Backup Designated Router (ID) %pI4,", |
3753 | &nbr->router_id); | |
3754 | vty_out(vty, " Interface Address %pI4\n", | |
3755 | &nbr->address.u.prefix4); | |
d62a17ae | 3756 | } |
3757 | } | |
3758 | } | |
3759 | ||
3760 | /* Next network-LSA sequence number we'll use, if we're elected | |
3761 | * DR */ | |
3762 | if (oi->params | |
3763 | && ntohl(oi->params->network_lsa_seqnum) | |
3764 | != OSPF_INITIAL_SEQUENCE_NUMBER) { | |
3765 | if (use_json) | |
3766 | json_object_int_add( | |
3767 | json_interface_sub, | |
3768 | "networkLsaSequence", | |
3769 | ntohl(oi->params->network_lsa_seqnum)); | |
3770 | else | |
3771 | vty_out(vty, | |
3772 | " Saved Network-LSA sequence number 0x%x\n", | |
3773 | ntohl(oi->params->network_lsa_seqnum)); | |
3774 | } | |
3775 | ||
3776 | if (use_json) { | |
3777 | if (OI_MEMBER_CHECK(oi, MEMBER_ALLROUTERS) | |
3778 | || OI_MEMBER_CHECK(oi, MEMBER_DROUTERS)) { | |
3779 | if (OI_MEMBER_CHECK(oi, MEMBER_ALLROUTERS)) | |
3780 | json_object_boolean_true_add( | |
3781 | json_interface_sub, | |
3782 | "mcastMemberOspfAllRouters"); | |
3783 | if (OI_MEMBER_CHECK(oi, MEMBER_DROUTERS)) | |
3784 | json_object_boolean_true_add( | |
3785 | json_interface_sub, | |
3786 | "mcastMemberOspfDesignatedRouters"); | |
3787 | } | |
3788 | } else { | |
3789 | vty_out(vty, " Multicast group memberships:"); | |
3790 | if (OI_MEMBER_CHECK(oi, MEMBER_ALLROUTERS) | |
3791 | || OI_MEMBER_CHECK(oi, MEMBER_DROUTERS)) { | |
3792 | if (OI_MEMBER_CHECK(oi, MEMBER_ALLROUTERS)) | |
3793 | vty_out(vty, " OSPFAllRouters"); | |
3794 | if (OI_MEMBER_CHECK(oi, MEMBER_DROUTERS)) | |
3795 | vty_out(vty, " OSPFDesignatedRouters"); | |
3796 | } else | |
3797 | vty_out(vty, " <None>"); | |
3798 | vty_out(vty, "\n"); | |
3799 | } | |
3800 | ||
3801 | if (use_json) { | |
3802 | if (OSPF_IF_PARAM(oi, fast_hello) == 0) | |
3803 | json_object_int_add( | |
3804 | json_interface_sub, "timerMsecs", | |
50ad4b42 | 3805 | OSPF_IF_PARAM(oi, v_hello) * 1000); |
d62a17ae | 3806 | else |
3807 | json_object_int_add( | |
3808 | json_interface_sub, "timerMsecs", | |
50ad4b42 | 3809 | 1000 / OSPF_IF_PARAM(oi, fast_hello)); |
d62a17ae | 3810 | json_object_int_add(json_interface_sub, |
50ad4b42 MS |
3811 | "timerDeadSecs", |
3812 | OSPF_IF_PARAM(oi, v_wait)); | |
d62a17ae | 3813 | json_object_int_add(json_interface_sub, |
50ad4b42 MS |
3814 | "timerWaitSecs", |
3815 | OSPF_IF_PARAM(oi, v_wait)); | |
d62a17ae | 3816 | json_object_int_add( |
50ad4b42 MS |
3817 | json_interface_sub, "timerRetransmitSecs", |
3818 | OSPF_IF_PARAM(oi, retransmit_interval)); | |
d62a17ae | 3819 | } else { |
3820 | vty_out(vty, " Timer intervals configured,"); | |
3821 | vty_out(vty, " Hello "); | |
3822 | if (OSPF_IF_PARAM(oi, fast_hello) == 0) | |
3823 | vty_out(vty, "%ds,", | |
3824 | OSPF_IF_PARAM(oi, v_hello)); | |
3825 | else | |
3826 | vty_out(vty, "%dms,", | |
3827 | 1000 / OSPF_IF_PARAM(oi, fast_hello)); | |
3828 | vty_out(vty, " Dead %ds, Wait %ds, Retransmit %d\n", | |
3829 | OSPF_IF_PARAM(oi, v_wait), | |
3830 | OSPF_IF_PARAM(oi, v_wait), | |
3831 | OSPF_IF_PARAM(oi, retransmit_interval)); | |
3832 | } | |
3833 | ||
3834 | if (OSPF_IF_PASSIVE_STATUS(oi) == OSPF_IF_ACTIVE) { | |
3835 | char timebuf[OSPF_TIME_DUMP_SIZE]; | |
3836 | if (use_json) { | |
3837 | long time_store = 0; | |
3838 | if (oi->t_hello) | |
3839 | time_store = | |
3840 | monotime_until( | |
3841 | &oi->t_hello->u.sands, | |
3842 | NULL) | |
3843 | / 1000LL; | |
3844 | json_object_int_add(json_interface_sub, | |
3845 | "timerHelloInMsecs", | |
3846 | time_store); | |
3847 | } else | |
3848 | vty_out(vty, " Hello due in %s\n", | |
3849 | ospf_timer_dump(oi->t_hello, timebuf, | |
3850 | sizeof(timebuf))); | |
3851 | } else /* passive-interface is set */ | |
3852 | { | |
3853 | if (use_json) | |
3854 | json_object_boolean_true_add( | |
3855 | json_interface_sub, | |
3856 | "timerPassiveIface"); | |
3857 | else | |
3858 | vty_out(vty, | |
3859 | " No Hellos (Passive interface)\n"); | |
3860 | } | |
7c8ff89e | 3861 | |
d62a17ae | 3862 | if (use_json) { |
3863 | json_object_int_add(json_interface_sub, "nbrCount", | |
3864 | ospf_nbr_count(oi, 0)); | |
3865 | json_object_int_add(json_interface_sub, | |
3866 | "nbrAdjacentCount", | |
3867 | ospf_nbr_count(oi, NSM_Full)); | |
3868 | } else | |
3869 | vty_out(vty, | |
3870 | " Neighbor Count is %d, Adjacent neighbor count is %d\n", | |
3871 | ospf_nbr_count(oi, 0), | |
3872 | ospf_nbr_count(oi, NSM_Full)); | |
659f4e40 RZ |
3873 | |
3874 | ospf_interface_bfd_show(vty, ifp, json_interface_sub); | |
49498934 | 3875 | |
3876 | /* OSPF Authentication information */ | |
3877 | ospf_interface_auth_show(vty, oi, json_interface_sub, use_json); | |
d62a17ae | 3878 | } |
718e3744 | 3879 | } |
3880 | ||
d62a17ae | 3881 | static int show_ip_ospf_interface_common(struct vty *vty, struct ospf *ospf, |
d7c0a89a | 3882 | char *intf_name, uint8_t use_vrf, |
9f049418 | 3883 | json_object *json, bool use_json) |
d62a17ae | 3884 | { |
3885 | struct interface *ifp; | |
f4e14fdb | 3886 | struct vrf *vrf = vrf_lookup_by_id(ospf->vrf_id); |
6282e124 | 3887 | json_object *json_vrf = NULL; |
7dab10ce | 3888 | json_object *json_interface_sub = NULL, *json_interface = NULL; |
7c8ff89e | 3889 | |
d62a17ae | 3890 | if (use_json) { |
b1c3ae8c CS |
3891 | if (use_vrf) |
3892 | json_vrf = json_object_new_object(); | |
3893 | else | |
3894 | json_vrf = json; | |
6282e124 | 3895 | json_interface = json_object_new_object(); |
d62a17ae | 3896 | } |
3897 | ||
3898 | if (ospf->instance) { | |
3899 | if (use_json) | |
3900 | json_object_int_add(json, "ospfInstance", | |
3901 | ospf->instance); | |
3902 | else | |
3903 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
3904 | } | |
3905 | ||
b1c3ae8c CS |
3906 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); |
3907 | ||
3908 | if (intf_name == NULL) { | |
d62a17ae | 3909 | /* Show All Interfaces.*/ |
451fda4f | 3910 | FOR_ALL_INTERFACES (vrf, ifp) { |
d62a17ae | 3911 | if (ospf_oi_count(ifp)) { |
7dab10ce | 3912 | if (use_json) { |
d62a17ae | 3913 | json_interface_sub = |
3914 | json_object_new_object(); | |
7dab10ce | 3915 | } |
d62a17ae | 3916 | show_ip_ospf_interface_sub(vty, ospf, ifp, |
3917 | json_interface_sub, | |
3918 | use_json); | |
3919 | ||
7dab10ce | 3920 | if (use_json) { |
d62a17ae | 3921 | json_object_object_add( |
7dab10ce | 3922 | json_interface, ifp->name, |
d62a17ae | 3923 | json_interface_sub); |
7dab10ce | 3924 | } |
d62a17ae | 3925 | } |
3926 | } | |
6282e124 CS |
3927 | if (use_json) |
3928 | json_object_object_add(json_vrf, "interfaces", | |
996c9314 | 3929 | json_interface); |
d62a17ae | 3930 | } else { |
3931 | /* Interface name is specified. */ | |
a36898e7 | 3932 | ifp = if_lookup_by_name(intf_name, ospf->vrf_id); |
b1c3ae8c | 3933 | if (ifp == NULL) { |
d62a17ae | 3934 | if (use_json) |
b1c3ae8c | 3935 | json_object_boolean_true_add(json_vrf, |
d62a17ae | 3936 | "noSuchIface"); |
3937 | else | |
3938 | vty_out(vty, "No such interface name\n"); | |
3939 | } else { | |
7dab10ce | 3940 | if (use_json) { |
d62a17ae | 3941 | json_interface_sub = json_object_new_object(); |
7dab10ce | 3942 | json_interface = json_object_new_object(); |
7dab10ce | 3943 | } |
d62a17ae | 3944 | |
3945 | show_ip_ospf_interface_sub( | |
3946 | vty, ospf, ifp, json_interface_sub, use_json); | |
3947 | ||
7dab10ce | 3948 | if (use_json) { |
7dab10ce CS |
3949 | json_object_object_add(json_interface, |
3950 | ifp->name, | |
d62a17ae | 3951 | json_interface_sub); |
6282e124 CS |
3952 | json_object_object_add(json_vrf, "interfaces", |
3953 | json_interface); | |
7dab10ce | 3954 | } |
d62a17ae | 3955 | } |
3956 | } | |
3957 | ||
3958 | if (use_json) { | |
b1c3ae8c | 3959 | if (use_vrf) { |
44076f4d RW |
3960 | json_object_object_add(json, ospf_get_name(ospf), |
3961 | json_vrf); | |
b1c3ae8c | 3962 | } |
d62a17ae | 3963 | } else |
3964 | vty_out(vty, "\n"); | |
3965 | ||
3966 | return CMD_SUCCESS; | |
718e3744 | 3967 | } |
3968 | ||
c9339663 CS |
3969 | static void show_ip_ospf_interface_traffic_sub(struct vty *vty, |
3970 | struct ospf_interface *oi, | |
3971 | json_object *json_interface_sub, | |
9f049418 | 3972 | bool use_json) |
c9339663 CS |
3973 | { |
3974 | if (use_json) { | |
996c9314 LB |
3975 | json_object_int_add(json_interface_sub, "ifIndex", |
3976 | oi->ifp->ifindex); | |
3977 | json_object_int_add(json_interface_sub, "helloIn", | |
3978 | oi->hello_in); | |
3979 | json_object_int_add(json_interface_sub, "helloOut", | |
3980 | oi->hello_out); | |
3981 | json_object_int_add(json_interface_sub, "dbDescIn", | |
3982 | oi->db_desc_in); | |
3983 | json_object_int_add(json_interface_sub, "dbDescOut", | |
3984 | oi->db_desc_out); | |
3985 | json_object_int_add(json_interface_sub, "lsReqIn", | |
3986 | oi->ls_req_in); | |
3987 | json_object_int_add(json_interface_sub, "lsReqOut", | |
3988 | oi->ls_req_out); | |
3989 | json_object_int_add(json_interface_sub, "lsUpdIn", | |
3990 | oi->ls_upd_in); | |
3991 | json_object_int_add(json_interface_sub, "lsUpdOut", | |
3992 | oi->ls_upd_out); | |
3993 | json_object_int_add(json_interface_sub, "lsAckIn", | |
3994 | oi->ls_ack_in); | |
3995 | json_object_int_add(json_interface_sub, "lsAckOut", | |
3996 | oi->ls_ack_out); | |
c9339663 CS |
3997 | } else { |
3998 | vty_out(vty, | |
3999 | "%-10s %8u/%-8u %7u/%-7u %7u/%-7u %7u/%-7u %7u/%-7u\n", | |
996c9314 LB |
4000 | oi->ifp->name, oi->hello_in, oi->hello_out, |
4001 | oi->db_desc_in, oi->db_desc_out, oi->ls_req_in, | |
4002 | oi->ls_req_out, oi->ls_upd_in, oi->ls_upd_out, | |
c9339663 CS |
4003 | oi->ls_ack_in, oi->ls_ack_out); |
4004 | } | |
4005 | } | |
4006 | ||
4007 | /* OSPFv2 Packet Counters */ | |
996c9314 LB |
4008 | static int show_ip_ospf_interface_traffic_common( |
4009 | struct vty *vty, struct ospf *ospf, char *intf_name, json_object *json, | |
9f049418 | 4010 | int display_once, uint8_t use_vrf, bool use_json) |
c9339663 CS |
4011 | { |
4012 | struct vrf *vrf = NULL; | |
4013 | struct interface *ifp = NULL; | |
b1c3ae8c | 4014 | json_object *json_vrf = NULL; |
c9339663 CS |
4015 | json_object *json_interface_sub = NULL; |
4016 | ||
4017 | if (!use_json && !display_once) { | |
4018 | vty_out(vty, "\n"); | |
996c9314 LB |
4019 | vty_out(vty, "%-12s%-17s%-17s%-17s%-17s%-17s\n", "Interface", |
4020 | " HELLO", " DB-Desc", " LS-Req", " LS-Update", | |
4021 | " LS-Ack"); | |
c9339663 | 4022 | vty_out(vty, "%-10s%-18s%-18s%-17s%-17s%-17s\n", "", |
996c9314 LB |
4023 | " Rx/Tx", " Rx/Tx", " Rx/Tx", " Rx/Tx", |
4024 | " Rx/Tx"); | |
c9339663 | 4025 | vty_out(vty, |
996c9314 | 4026 | "--------------------------------------------------------------------------------------------\n"); |
c9339663 | 4027 | } else if (use_json) { |
b1c3ae8c CS |
4028 | if (use_vrf) |
4029 | json_vrf = json_object_new_object(); | |
4030 | else | |
4031 | json_vrf = json; | |
c9339663 CS |
4032 | } |
4033 | ||
b1c3ae8c CS |
4034 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); |
4035 | ||
c9339663 CS |
4036 | if (intf_name == NULL) { |
4037 | vrf = vrf_lookup_by_id(ospf->vrf_id); | |
4038 | FOR_ALL_INTERFACES (vrf, ifp) { | |
4039 | struct route_node *rn; | |
4040 | struct ospf_interface *oi; | |
4041 | ||
4042 | if (ospf_oi_count(ifp) == 0) | |
4043 | continue; | |
4044 | ||
4045 | for (rn = route_top(IF_OIFS(ifp)); rn; | |
996c9314 | 4046 | rn = route_next(rn)) { |
c9339663 CS |
4047 | oi = rn->info; |
4048 | ||
4049 | if (oi == NULL) | |
4050 | continue; | |
4051 | ||
4052 | if (use_json) { | |
4053 | json_interface_sub = | |
4054 | json_object_new_object(); | |
4055 | } | |
4056 | ||
996c9314 LB |
4057 | show_ip_ospf_interface_traffic_sub( |
4058 | vty, oi, json_interface_sub, use_json); | |
c9339663 | 4059 | if (use_json) { |
996c9314 LB |
4060 | json_object_object_add( |
4061 | json_vrf, ifp->name, | |
4062 | json_interface_sub); | |
c9339663 CS |
4063 | } |
4064 | } | |
4065 | } | |
4066 | } else { | |
4067 | /* Interface name is specified. */ | |
a36898e7 | 4068 | ifp = if_lookup_by_name(intf_name, ospf->vrf_id); |
c9339663 CS |
4069 | if (ifp != NULL) { |
4070 | struct route_node *rn; | |
4071 | struct ospf_interface *oi; | |
4072 | ||
4073 | if (ospf_oi_count(ifp) == 0) { | |
996c9314 LB |
4074 | vty_out(vty, |
4075 | " OSPF not enabled on this interface %s\n", | |
c9339663 CS |
4076 | ifp->name); |
4077 | return CMD_SUCCESS; | |
4078 | } | |
4079 | ||
4080 | for (rn = route_top(IF_OIFS(ifp)); rn; | |
4081 | rn = route_next(rn)) { | |
4082 | oi = rn->info; | |
4083 | ||
4084 | if (use_json) { | |
4085 | json_interface_sub = | |
4086 | json_object_new_object(); | |
4087 | } | |
4088 | ||
996c9314 LB |
4089 | show_ip_ospf_interface_traffic_sub( |
4090 | vty, oi, json_interface_sub, use_json); | |
c9339663 | 4091 | if (use_json) { |
996c9314 LB |
4092 | json_object_object_add( |
4093 | json_vrf, ifp->name, | |
4094 | json_interface_sub); | |
c9339663 CS |
4095 | } |
4096 | } | |
4097 | } | |
4098 | } | |
4099 | ||
4100 | if (use_json) { | |
44076f4d RW |
4101 | if (use_vrf) |
4102 | json_object_object_add(json, ospf_get_name(ospf), | |
4103 | json_vrf); | |
b1c3ae8c CS |
4104 | } else |
4105 | vty_out(vty, "\n"); | |
c9339663 CS |
4106 | |
4107 | return CMD_SUCCESS; | |
4108 | } | |
4109 | ||
7c8ff89e DS |
4110 | DEFUN (show_ip_ospf_interface, |
4111 | show_ip_ospf_interface_cmd, | |
43b8d1d8 | 4112 | "show ip ospf [vrf <NAME|all>] interface [INTERFACE] [json]", |
7c8ff89e DS |
4113 | SHOW_STR |
4114 | IP_STR | |
4115 | "OSPF information\n" | |
b5a8894d | 4116 | VRF_CMD_HELP_STR |
43b8d1d8 | 4117 | "All VRFs\n" |
7c8ff89e | 4118 | "Interface information\n" |
7ec4159b | 4119 | "Interface name\n" |
9973d184 | 4120 | JSON_STR) |
7c8ff89e | 4121 | { |
d62a17ae | 4122 | struct ospf *ospf; |
9f049418 | 4123 | bool uj = use_json(argc, argv); |
b5a8894d | 4124 | struct listnode *node = NULL; |
b1c3ae8c | 4125 | char *vrf_name = NULL, *intf_name = NULL; |
2951a7a4 | 4126 | bool all_vrf = false; |
b5a8894d CS |
4127 | int ret = CMD_SUCCESS; |
4128 | int inst = 0; | |
b1c3ae8c | 4129 | int idx_vrf = 0, idx_intf = 0; |
d7c0a89a | 4130 | uint8_t use_vrf = 0; |
b1c3ae8c | 4131 | json_object *json = NULL; |
7c8ff89e | 4132 | |
43b8d1d8 CS |
4133 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
4134 | ||
b1c3ae8c CS |
4135 | if (argv_find(argv, argc, "INTERFACE", &idx_intf)) |
4136 | intf_name = argv[idx_intf]->arg; | |
4137 | ||
d62a17ae | 4138 | if (uj) |
b1c3ae8c | 4139 | json = json_object_new_object(); |
6be4da3d | 4140 | |
b5a8894d CS |
4141 | /* vrf input is provided could be all or specific vrf*/ |
4142 | if (vrf_name) { | |
b1c3ae8c | 4143 | use_vrf = 1; |
b5a8894d CS |
4144 | if (all_vrf) { |
4145 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
4146 | if (!ospf->oi_running) | |
4147 | continue; | |
996c9314 LB |
4148 | ret = show_ip_ospf_interface_common( |
4149 | vty, ospf, intf_name, use_vrf, json, | |
4150 | uj); | |
b5a8894d | 4151 | } |
b1c3ae8c CS |
4152 | |
4153 | if (uj) { | |
4154 | vty_out(vty, "%s\n", | |
996c9314 LB |
4155 | json_object_to_json_string_ext( |
4156 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 4157 | json_object_free(json); |
9f049418 | 4158 | } else if (!ospf) |
94d4c685 | 4159 | vty_out(vty, "%% OSPF instance not found\n"); |
b1c3ae8c | 4160 | |
b5a8894d CS |
4161 | return ret; |
4162 | } | |
4163 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
b1c3ae8c | 4164 | if (ospf == NULL || !ospf->oi_running) { |
9f049418 DS |
4165 | if (uj) { |
4166 | vty_out(vty, "%s\n", | |
4167 | json_object_to_json_string_ext( | |
4168 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 4169 | json_object_free(json); |
9f049418 | 4170 | } else |
94d4c685 | 4171 | vty_out(vty, "%% OSPF instance not found\n"); |
9f049418 | 4172 | |
b5a8894d | 4173 | return CMD_SUCCESS; |
b1c3ae8c CS |
4174 | } |
4175 | ret = show_ip_ospf_interface_common(vty, ospf, intf_name, | |
4176 | use_vrf, json, uj); | |
b5a8894d CS |
4177 | |
4178 | } else { | |
4179 | /* Display default ospf (instance 0) info */ | |
4180 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
b1c3ae8c | 4181 | if (ospf == NULL || !ospf->oi_running) { |
9f049418 DS |
4182 | if (uj) { |
4183 | vty_out(vty, "%s\n", | |
4184 | json_object_to_json_string_ext( | |
4185 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 4186 | json_object_free(json); |
9f049418 | 4187 | } else |
94d4c685 | 4188 | vty_out(vty, "%% OSPF instance not found\n"); |
9f049418 | 4189 | |
b5a8894d | 4190 | return CMD_SUCCESS; |
b1c3ae8c CS |
4191 | } |
4192 | ret = show_ip_ospf_interface_common(vty, ospf, intf_name, | |
4193 | use_vrf, json, uj); | |
4194 | } | |
4195 | ||
4196 | if (uj) { | |
996c9314 LB |
4197 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
4198 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 4199 | json_object_free(json); |
b5a8894d CS |
4200 | } |
4201 | ||
4202 | return ret; | |
7c8ff89e DS |
4203 | } |
4204 | ||
4205 | DEFUN (show_ip_ospf_instance_interface, | |
4206 | show_ip_ospf_instance_interface_cmd, | |
6147e2c6 | 4207 | "show ip ospf (1-65535) interface [INTERFACE] [json]", |
7c8ff89e DS |
4208 | SHOW_STR |
4209 | IP_STR | |
4210 | "OSPF information\n" | |
4211 | "Instance ID\n" | |
4212 | "Interface information\n" | |
7ec4159b | 4213 | "Interface name\n" |
9973d184 | 4214 | JSON_STR) |
7c8ff89e | 4215 | { |
d62a17ae | 4216 | int idx_number = 3; |
b1c3ae8c | 4217 | int idx_intf = 0; |
d62a17ae | 4218 | struct ospf *ospf; |
d7c0a89a | 4219 | unsigned short instance = 0; |
9f049418 | 4220 | bool uj = use_json(argc, argv); |
b1c3ae8c CS |
4221 | char *intf_name = NULL; |
4222 | int ret = CMD_SUCCESS; | |
4223 | json_object *json = NULL; | |
d62a17ae | 4224 | |
4225 | instance = strtoul(argv[idx_number]->arg, NULL, 10); | |
409f98ab | 4226 | if (instance != ospf_instance) |
ac28e4ec CS |
4227 | return CMD_NOT_MY_INSTANCE; |
4228 | ||
409f98ab IR |
4229 | ospf = ospf_lookup_instance(instance); |
4230 | if (!ospf || !ospf->oi_running) | |
d62a17ae | 4231 | return CMD_SUCCESS; |
4232 | ||
4233 | if (uj) | |
b1c3ae8c CS |
4234 | json = json_object_new_object(); |
4235 | ||
4236 | if (argv_find(argv, argc, "INTERFACE", &idx_intf)) | |
4237 | intf_name = argv[idx_intf]->arg; | |
4238 | ||
4239 | ret = show_ip_ospf_interface_common(vty, ospf, intf_name, 0, json, uj); | |
4240 | ||
4241 | if (uj) { | |
996c9314 LB |
4242 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
4243 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c CS |
4244 | json_object_free(json); |
4245 | } | |
d62a17ae | 4246 | |
b1c3ae8c | 4247 | return ret; |
d62a17ae | 4248 | } |
4249 | ||
c9339663 CS |
4250 | DEFUN (show_ip_ospf_interface_traffic, |
4251 | show_ip_ospf_interface_traffic_cmd, | |
4252 | "show ip ospf [vrf <NAME|all>] interface traffic [INTERFACE] [json]", | |
4253 | SHOW_STR | |
4254 | IP_STR | |
4255 | "OSPF information\n" | |
4256 | VRF_CMD_HELP_STR | |
4257 | "All VRFs\n" | |
4258 | "Interface information\n" | |
4259 | "Protocol Packet counters\n" | |
4260 | "Interface name\n" | |
4261 | JSON_STR) | |
4262 | { | |
4263 | struct ospf *ospf = NULL; | |
4264 | struct listnode *node = NULL; | |
4265 | char *vrf_name = NULL, *intf_name = NULL; | |
2951a7a4 | 4266 | bool all_vrf = false; |
c9339663 CS |
4267 | int inst = 0; |
4268 | int idx_vrf = 0, idx_intf = 0; | |
9f049418 | 4269 | bool uj = use_json(argc, argv); |
b1c3ae8c | 4270 | json_object *json = NULL; |
c9339663 CS |
4271 | int ret = CMD_SUCCESS; |
4272 | int display_once = 0; | |
d7c0a89a | 4273 | uint8_t use_vrf = 0; |
c9339663 CS |
4274 | |
4275 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); | |
4276 | ||
4277 | if (argv_find(argv, argc, "INTERFACE", &idx_intf)) | |
4278 | intf_name = argv[idx_intf]->arg; | |
4279 | ||
b1c3ae8c CS |
4280 | if (uj) |
4281 | json = json_object_new_object(); | |
4282 | ||
c9339663 | 4283 | if (vrf_name) { |
b1c3ae8c | 4284 | use_vrf = 1; |
c9339663 CS |
4285 | if (all_vrf) { |
4286 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
4287 | if (!ospf->oi_running) | |
4288 | continue; | |
4289 | ||
996c9314 LB |
4290 | ret = show_ip_ospf_interface_traffic_common( |
4291 | vty, ospf, intf_name, json, | |
4292 | display_once, use_vrf, uj); | |
c9339663 CS |
4293 | display_once = 1; |
4294 | } | |
b1c3ae8c CS |
4295 | |
4296 | if (uj) { | |
4297 | vty_out(vty, "%s\n", | |
996c9314 LB |
4298 | json_object_to_json_string_ext( |
4299 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c CS |
4300 | json_object_free(json); |
4301 | } | |
4302 | ||
c9339663 CS |
4303 | return ret; |
4304 | } | |
4305 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
b1c3ae8c CS |
4306 | if (ospf == NULL || !ospf->oi_running) { |
4307 | if (uj) | |
4308 | json_object_free(json); | |
c9339663 | 4309 | return CMD_SUCCESS; |
b1c3ae8c CS |
4310 | } |
4311 | ||
996c9314 LB |
4312 | ret = show_ip_ospf_interface_traffic_common( |
4313 | vty, ospf, intf_name, json, display_once, use_vrf, uj); | |
c9339663 CS |
4314 | } else { |
4315 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
b1c3ae8c CS |
4316 | if (ospf == NULL || !ospf->oi_running) { |
4317 | if (uj) | |
4318 | json_object_free(json); | |
c9339663 | 4319 | return CMD_SUCCESS; |
b1c3ae8c CS |
4320 | } |
4321 | ||
996c9314 LB |
4322 | ret = show_ip_ospf_interface_traffic_common( |
4323 | vty, ospf, intf_name, json, display_once, use_vrf, uj); | |
b1c3ae8c CS |
4324 | } |
4325 | ||
4326 | if (uj) { | |
996c9314 LB |
4327 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
4328 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 4329 | json_object_free(json); |
c9339663 CS |
4330 | } |
4331 | ||
4332 | return ret; | |
4333 | } | |
4334 | ||
4335 | ||
d62a17ae | 4336 | static void show_ip_ospf_neighbour_header(struct vty *vty) |
4337 | { | |
c84355a9 | 4338 | vty_out(vty, "\n%-15s %3s %-15s %9s %-15s %-32s %5s %5s %5s\n", |
d62a17ae | 4339 | "Neighbor ID", "Pri", "State", "Dead Time", "Address", |
4340 | "Interface", "RXmtL", "RqstL", "DBsmL"); | |
4341 | } | |
4342 | ||
4343 | static void show_ip_ospf_neighbor_sub(struct vty *vty, | |
4344 | struct ospf_interface *oi, | |
9f049418 | 4345 | json_object *json, bool use_json) |
d62a17ae | 4346 | { |
4347 | struct route_node *rn; | |
cef262c3 | 4348 | struct ospf_neighbor *nbr, *prev_nbr = NULL; |
d62a17ae | 4349 | char msgbuf[16]; |
96b663a3 | 4350 | char buf[PREFIX_STRLEN]; |
d62a17ae | 4351 | char timebuf[OSPF_TIME_DUMP_SIZE]; |
cef262c3 | 4352 | json_object *json_neighbor = NULL, *json_neigh_array = NULL; |
d62a17ae | 4353 | |
4354 | for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) { | |
4355 | if ((nbr = rn->info)) { | |
4356 | /* Do not show myself. */ | |
cef262c3 CS |
4357 | if (nbr == oi->nbr_self) |
4358 | continue; | |
4359 | /* Down state is not shown. */ | |
4360 | if (nbr->state == NSM_Down) | |
4361 | continue; | |
4362 | if (use_json) { | |
4363 | char neigh_str[INET_ADDRSTRLEN]; | |
4364 | ||
996c9314 LB |
4365 | if (prev_nbr |
4366 | && !IPV4_ADDR_SAME(&prev_nbr->src, | |
4367 | &nbr->src)) { | |
cef262c3 CS |
4368 | /* Start new neigh list */ |
4369 | json_neigh_array = NULL; | |
4370 | } | |
4371 | ||
996c9314 | 4372 | if (nbr->state == NSM_Attempt |
975a328e | 4373 | && nbr->router_id.s_addr == INADDR_ANY) |
6021c6c0 CS |
4374 | strlcpy(neigh_str, "neighbor", |
4375 | sizeof(neigh_str)); | |
cef262c3 | 4376 | else |
96b663a3 MS |
4377 | inet_ntop(AF_INET, &nbr->router_id, |
4378 | neigh_str, sizeof(neigh_str)); | |
cef262c3 CS |
4379 | |
4380 | json_object_object_get_ex(json, neigh_str, | |
4381 | &json_neigh_array); | |
4382 | ||
4383 | if (!json_neigh_array) { | |
996c9314 LB |
4384 | json_neigh_array = |
4385 | json_object_new_array(); | |
4386 | json_object_object_add( | |
4387 | json, neigh_str, | |
4388 | json_neigh_array); | |
d62a17ae | 4389 | } |
cef262c3 | 4390 | |
996c9314 | 4391 | json_neighbor = json_object_new_object(); |
cef262c3 CS |
4392 | |
4393 | ospf_nbr_state_message(nbr, msgbuf, 16); | |
4394 | ||
996c9314 | 4395 | json_object_int_add(json_neighbor, "priority", |
cef262c3 CS |
4396 | nbr->priority); |
4397 | json_object_string_add(json_neighbor, "state", | |
4398 | msgbuf); | |
b3d498f8 RW |
4399 | |
4400 | if (nbr->t_inactivity) { | |
4401 | long time_store; | |
4402 | ||
4403 | time_store = monotime_until( | |
4404 | &nbr->t_inactivity | |
4405 | ->u.sands, | |
4406 | NULL) | |
4407 | / 1000LL; | |
4408 | json_object_int_add(json_neighbor, | |
4409 | "deadTimeMsecs", | |
4410 | time_store); | |
4411 | } else { | |
4412 | json_object_string_add(json_neighbor, | |
4413 | "deadTimeMsecs", | |
4414 | "inactive"); | |
4415 | } | |
96b663a3 MS |
4416 | json_object_string_add( |
4417 | json_neighbor, "address", | |
4418 | inet_ntop(AF_INET, &nbr->src, | |
4419 | buf, sizeof(buf))); | |
cef262c3 CS |
4420 | json_object_string_add(json_neighbor, |
4421 | "ifaceName", | |
4422 | IF_NAME(oi)); | |
996c9314 LB |
4423 | json_object_int_add( |
4424 | json_neighbor, "retransmitCounter", | |
4425 | ospf_ls_retransmit_count(nbr)); | |
cef262c3 | 4426 | json_object_int_add(json_neighbor, |
996c9314 LB |
4427 | "requestCounter", |
4428 | ospf_ls_request_count(nbr)); | |
cef262c3 | 4429 | json_object_int_add(json_neighbor, |
996c9314 LB |
4430 | "dbSummaryCounter", |
4431 | ospf_db_summary_count(nbr)); | |
cef262c3 CS |
4432 | |
4433 | json_object_array_add(json_neigh_array, | |
4434 | json_neighbor); | |
4435 | } else { | |
4436 | ospf_nbr_state_message(nbr, msgbuf, 16); | |
4437 | ||
996c9314 | 4438 | if (nbr->state == NSM_Attempt |
975a328e | 4439 | && nbr->router_id.s_addr == INADDR_ANY) |
996c9314 LB |
4440 | vty_out(vty, "%-15s %3d %-15s ", "-", |
4441 | nbr->priority, msgbuf); | |
cef262c3 | 4442 | else |
96b663a3 MS |
4443 | vty_out(vty, "%-15pI4 %3d %-15s ", |
4444 | &nbr->router_id, | |
996c9314 | 4445 | nbr->priority, msgbuf); |
cef262c3 CS |
4446 | |
4447 | vty_out(vty, "%9s ", | |
4448 | ospf_timer_dump(nbr->t_inactivity, | |
4449 | timebuf, | |
4450 | sizeof(timebuf))); | |
96b663a3 | 4451 | vty_out(vty, "%-15pI4 ", &nbr->src); |
c84355a9 | 4452 | vty_out(vty, "%-32s %5ld %5ld %5d\n", |
cef262c3 CS |
4453 | IF_NAME(oi), |
4454 | ospf_ls_retransmit_count(nbr), | |
4455 | ospf_ls_request_count(nbr), | |
4456 | ospf_db_summary_count(nbr)); | |
d62a17ae | 4457 | } |
cef262c3 | 4458 | prev_nbr = nbr; |
d62a17ae | 4459 | } |
4460 | } | |
4461 | } | |
4462 | ||
4463 | static int show_ip_ospf_neighbor_common(struct vty *vty, struct ospf *ospf, | |
9f049418 | 4464 | json_object *json, bool use_json, |
d7c0a89a | 4465 | uint8_t use_vrf) |
d62a17ae | 4466 | { |
4467 | struct ospf_interface *oi; | |
4468 | struct listnode *node; | |
6282e124 | 4469 | json_object *json_vrf = NULL; |
2bc7673f | 4470 | json_object *json_nbr_sub = NULL; |
7c8ff89e | 4471 | |
b1c3ae8c CS |
4472 | if (use_json) { |
4473 | if (use_vrf) | |
4474 | json_vrf = json_object_new_object(); | |
4475 | else | |
4476 | json_vrf = json; | |
6282e124 | 4477 | json_nbr_sub = json_object_new_object(); |
b1c3ae8c | 4478 | } |
d62a17ae | 4479 | |
4480 | if (ospf->instance) { | |
4481 | if (use_json) | |
4482 | json_object_int_add(json, "ospfInstance", | |
4483 | ospf->instance); | |
4484 | else | |
4485 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
4486 | } | |
7c8ff89e | 4487 | |
b1c3ae8c CS |
4488 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); |
4489 | if (!use_json) | |
4490 | show_ip_ospf_neighbour_header(vty); | |
87bd50e8 | 4491 | |
2bc7673f CS |
4492 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) { |
4493 | if (ospf_interface_neighbor_count(oi) == 0) | |
4494 | continue; | |
2bc7673f CS |
4495 | show_ip_ospf_neighbor_sub(vty, oi, json_nbr_sub, use_json); |
4496 | } | |
718e3744 | 4497 | |
d62a17ae | 4498 | if (use_json) { |
996c9314 | 4499 | json_object_object_add(json_vrf, "neighbors", json_nbr_sub); |
44076f4d RW |
4500 | if (use_vrf) |
4501 | json_object_object_add(json, ospf_get_name(ospf), | |
4502 | json_vrf); | |
d62a17ae | 4503 | } else |
4504 | vty_out(vty, "\n"); | |
7c8ff89e | 4505 | |
d62a17ae | 4506 | return CMD_SUCCESS; |
718e3744 | 4507 | } |
4508 | ||
7c8ff89e DS |
4509 | DEFUN (show_ip_ospf_neighbor, |
4510 | show_ip_ospf_neighbor_cmd, | |
b5a8894d | 4511 | "show ip ospf [vrf <NAME|all>] neighbor [json]", |
718e3744 | 4512 | SHOW_STR |
4513 | IP_STR | |
4514 | "OSPF information\n" | |
b5a8894d CS |
4515 | VRF_CMD_HELP_STR |
4516 | "All VRFs\n" | |
91756b38 | 4517 | "Neighbor list\n" |
9973d184 | 4518 | JSON_STR) |
718e3744 | 4519 | { |
d62a17ae | 4520 | struct ospf *ospf; |
9f049418 | 4521 | bool uj = use_json(argc, argv); |
b5a8894d CS |
4522 | struct listnode *node = NULL; |
4523 | char *vrf_name = NULL; | |
2951a7a4 | 4524 | bool all_vrf = false; |
b5a8894d CS |
4525 | int ret = CMD_SUCCESS; |
4526 | int inst = 0; | |
4527 | int idx_vrf = 0; | |
d7c0a89a | 4528 | uint8_t use_vrf = 0; |
b1c3ae8c | 4529 | json_object *json = NULL; |
718e3744 | 4530 | |
43b8d1d8 | 4531 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
7c8ff89e | 4532 | |
b1c3ae8c CS |
4533 | if (uj) |
4534 | json = json_object_new_object(); | |
b5a8894d CS |
4535 | |
4536 | /* vrf input is provided could be all or specific vrf*/ | |
4537 | if (vrf_name) { | |
b1c3ae8c | 4538 | use_vrf = 1; |
b5a8894d CS |
4539 | if (all_vrf) { |
4540 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
4541 | if (!ospf->oi_running) | |
4542 | continue; | |
996c9314 LB |
4543 | ret = show_ip_ospf_neighbor_common( |
4544 | vty, ospf, json, uj, use_vrf); | |
b1c3ae8c CS |
4545 | } |
4546 | ||
4547 | if (uj) { | |
4548 | vty_out(vty, "%s\n", | |
996c9314 LB |
4549 | json_object_to_json_string_ext( |
4550 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 4551 | json_object_free(json); |
9f049418 DS |
4552 | } else if (!ospf) |
4553 | vty_out(vty, "OSPF instance not found\n"); | |
b1c3ae8c | 4554 | |
b5a8894d CS |
4555 | return ret; |
4556 | } | |
b1c3ae8c | 4557 | |
b5a8894d | 4558 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); |
b1c3ae8c | 4559 | if (ospf == NULL || !ospf->oi_running) { |
9f049418 DS |
4560 | if (uj) { |
4561 | vty_out(vty, "%s\n", | |
4562 | json_object_to_json_string_ext( | |
4563 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 4564 | json_object_free(json); |
9f049418 DS |
4565 | } else |
4566 | vty_out(vty, "%% OSPF instance not found\n"); | |
4567 | ||
b5a8894d | 4568 | return CMD_SUCCESS; |
b1c3ae8c | 4569 | } |
b5a8894d CS |
4570 | } else { |
4571 | /* Display default ospf (instance 0) info */ | |
4572 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
b1c3ae8c | 4573 | if (ospf == NULL || !ospf->oi_running) { |
9f049418 DS |
4574 | if (uj) { |
4575 | vty_out(vty, "%s\n", | |
4576 | json_object_to_json_string_ext( | |
4577 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 4578 | json_object_free(json); |
9f049418 DS |
4579 | } else |
4580 | vty_out(vty, "%% OSPF instance not found\n"); | |
4581 | ||
b5a8894d | 4582 | return CMD_SUCCESS; |
b1c3ae8c | 4583 | } |
b5a8894d CS |
4584 | } |
4585 | ||
b1c3ae8c CS |
4586 | if (ospf) { |
4587 | ret = show_ip_ospf_neighbor_common(vty, ospf, json, uj, | |
4588 | use_vrf); | |
4589 | ||
4590 | if (uj) { | |
4591 | vty_out(vty, "%s\n", | |
996c9314 LB |
4592 | json_object_to_json_string_ext( |
4593 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c CS |
4594 | } |
4595 | } | |
4596 | ||
4597 | if (uj) | |
4598 | json_object_free(json); | |
b5a8894d CS |
4599 | |
4600 | return ret; | |
7c8ff89e DS |
4601 | } |
4602 | ||
4603 | ||
4604 | DEFUN (show_ip_ospf_instance_neighbor, | |
4605 | show_ip_ospf_instance_neighbor_cmd, | |
6147e2c6 | 4606 | "show ip ospf (1-65535) neighbor [json]", |
7c8ff89e DS |
4607 | SHOW_STR |
4608 | IP_STR | |
4609 | "OSPF information\n" | |
4610 | "Instance ID\n" | |
91756b38 | 4611 | "Neighbor list\n" |
9973d184 | 4612 | JSON_STR) |
7c8ff89e | 4613 | { |
d62a17ae | 4614 | int idx_number = 3; |
4615 | struct ospf *ospf; | |
d7c0a89a | 4616 | unsigned short instance = 0; |
9f049418 | 4617 | bool uj = use_json(argc, argv); |
b1c3ae8c CS |
4618 | json_object *json = NULL; |
4619 | int ret = CMD_SUCCESS; | |
7c8ff89e | 4620 | |
d62a17ae | 4621 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
409f98ab | 4622 | if (instance != ospf_instance) |
ac28e4ec CS |
4623 | return CMD_NOT_MY_INSTANCE; |
4624 | ||
409f98ab IR |
4625 | ospf = ospf_lookup_instance(instance); |
4626 | if (!ospf || !ospf->oi_running) | |
d62a17ae | 4627 | return CMD_SUCCESS; |
7c8ff89e | 4628 | |
b1c3ae8c CS |
4629 | if (uj) |
4630 | json = json_object_new_object(); | |
b5a8894d | 4631 | |
b1c3ae8c CS |
4632 | ret = show_ip_ospf_neighbor_common(vty, ospf, json, uj, 0); |
4633 | ||
4634 | if (uj) { | |
996c9314 LB |
4635 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
4636 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c CS |
4637 | json_object_free(json); |
4638 | } | |
4639 | ||
4640 | return ret; | |
7c8ff89e DS |
4641 | } |
4642 | ||
d62a17ae | 4643 | static int show_ip_ospf_neighbor_all_common(struct vty *vty, struct ospf *ospf, |
9f049418 | 4644 | json_object *json, bool use_json, |
d7c0a89a | 4645 | uint8_t use_vrf) |
d62a17ae | 4646 | { |
4647 | struct listnode *node; | |
4648 | struct ospf_interface *oi; | |
96b663a3 | 4649 | char buf[PREFIX_STRLEN]; |
b1c3ae8c | 4650 | json_object *json_vrf = NULL; |
d62a17ae | 4651 | json_object *json_neighbor_sub = NULL; |
7c8ff89e | 4652 | |
d62a17ae | 4653 | if (use_json) { |
b1c3ae8c CS |
4654 | if (use_vrf) |
4655 | json_vrf = json_object_new_object(); | |
4656 | else | |
4657 | json_vrf = json; | |
b5a8894d | 4658 | } |
d62a17ae | 4659 | |
b1c3ae8c CS |
4660 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); |
4661 | if (!use_json) | |
4662 | show_ip_ospf_neighbour_header(vty); | |
4663 | ||
d62a17ae | 4664 | if (ospf->instance) { |
4665 | if (use_json) | |
b1c3ae8c | 4666 | json_object_int_add(json_vrf, "ospfInstance", |
d62a17ae | 4667 | ospf->instance); |
4668 | else | |
4669 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
4670 | } | |
4671 | ||
4672 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) { | |
4673 | struct listnode *nbr_node; | |
4674 | struct ospf_nbr_nbma *nbr_nbma; | |
4675 | ||
b1c3ae8c | 4676 | show_ip_ospf_neighbor_sub(vty, oi, json_vrf, use_json); |
d62a17ae | 4677 | |
4678 | /* print Down neighbor status */ | |
4679 | for (ALL_LIST_ELEMENTS_RO(oi->nbr_nbma, nbr_node, nbr_nbma)) { | |
4680 | if (nbr_nbma->nbr == NULL | |
4681 | || nbr_nbma->nbr->state == NSM_Down) { | |
4682 | if (use_json) { | |
6f3e19b7 MR |
4683 | json_neighbor_sub = |
4684 | json_object_new_object(); | |
d62a17ae | 4685 | json_object_int_add(json_neighbor_sub, |
4686 | "nbrNbmaPriority", | |
4687 | nbr_nbma->priority); | |
4688 | json_object_boolean_true_add( | |
4689 | json_neighbor_sub, | |
4690 | "nbrNbmaDown"); | |
4691 | json_object_string_add( | |
4692 | json_neighbor_sub, | |
4693 | "nbrNbmaIfaceName", | |
4694 | IF_NAME(oi)); | |
4695 | json_object_int_add( | |
4696 | json_neighbor_sub, | |
4697 | "nbrNbmaRetransmitCounter", 0); | |
4698 | json_object_int_add( | |
4699 | json_neighbor_sub, | |
4700 | "nbrNbmaRequestCounter", 0); | |
4701 | json_object_int_add( | |
4702 | json_neighbor_sub, | |
4703 | "nbrNbmaDbSummaryCounter", 0); | |
4704 | json_object_object_add( | |
b1c3ae8c | 4705 | json_vrf, |
96b663a3 MS |
4706 | inet_ntop(AF_INET, |
4707 | &nbr_nbma->addr, buf, | |
4708 | sizeof(buf)), | |
d62a17ae | 4709 | json_neighbor_sub); |
4710 | } else { | |
4711 | vty_out(vty, "%-15s %3d %-15s %9s ", | |
4712 | "-", nbr_nbma->priority, "Down", | |
4713 | "-"); | |
4714 | vty_out(vty, | |
96b663a3 MS |
4715 | "%-32pI4 %-20s %5d %5d %5d\n", |
4716 | &nbr_nbma->addr, | |
d62a17ae | 4717 | IF_NAME(oi), 0, 0, 0); |
4718 | } | |
4719 | } | |
4720 | } | |
4721 | } | |
4722 | ||
4723 | if (use_json) { | |
44076f4d RW |
4724 | if (use_vrf) |
4725 | json_object_object_add(json, ospf_get_name(ospf), | |
4726 | json_vrf); | |
d62a17ae | 4727 | } else |
4728 | vty_out(vty, "\n"); | |
4729 | ||
4730 | return CMD_SUCCESS; | |
718e3744 | 4731 | } |
4732 | ||
7c8ff89e DS |
4733 | DEFUN (show_ip_ospf_neighbor_all, |
4734 | show_ip_ospf_neighbor_all_cmd, | |
b5a8894d | 4735 | "show ip ospf [vrf <NAME|all>] neighbor all [json]", |
718e3744 | 4736 | SHOW_STR |
4737 | IP_STR | |
4738 | "OSPF information\n" | |
b5a8894d CS |
4739 | VRF_CMD_HELP_STR |
4740 | "All VRFs\n" | |
718e3744 | 4741 | "Neighbor list\n" |
91756b38 | 4742 | "include down status neighbor\n" |
9973d184 | 4743 | JSON_STR) |
7c8ff89e | 4744 | { |
d62a17ae | 4745 | struct ospf *ospf; |
9f049418 | 4746 | bool uj = use_json(argc, argv); |
b5a8894d CS |
4747 | struct listnode *node = NULL; |
4748 | char *vrf_name = NULL; | |
2951a7a4 | 4749 | bool all_vrf = false; |
b5a8894d CS |
4750 | int ret = CMD_SUCCESS; |
4751 | int inst = 0; | |
4752 | int idx_vrf = 0; | |
d7c0a89a | 4753 | uint8_t use_vrf = 0; |
b1c3ae8c | 4754 | json_object *json = NULL; |
7c8ff89e | 4755 | |
43b8d1d8 | 4756 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
7c8ff89e | 4757 | |
b1c3ae8c CS |
4758 | if (uj) |
4759 | json = json_object_new_object(); | |
b5a8894d CS |
4760 | |
4761 | /* vrf input is provided could be all or specific vrf*/ | |
4762 | if (vrf_name) { | |
b1c3ae8c | 4763 | use_vrf = 1; |
b5a8894d CS |
4764 | if (all_vrf) { |
4765 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
4766 | if (!ospf->oi_running) | |
4767 | continue; | |
996c9314 LB |
4768 | ret = show_ip_ospf_neighbor_all_common( |
4769 | vty, ospf, json, uj, use_vrf); | |
b1c3ae8c CS |
4770 | } |
4771 | ||
4772 | if (uj) { | |
4773 | vty_out(vty, "%s\n", | |
996c9314 LB |
4774 | json_object_to_json_string_ext( |
4775 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 4776 | json_object_free(json); |
b5a8894d | 4777 | } |
b1c3ae8c | 4778 | |
b5a8894d CS |
4779 | return ret; |
4780 | } | |
b1c3ae8c | 4781 | |
b5a8894d | 4782 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); |
b1c3ae8c CS |
4783 | if (ospf == NULL || !ospf->oi_running) { |
4784 | if (uj) | |
4785 | json_object_free(json); | |
b5a8894d | 4786 | return CMD_SUCCESS; |
b1c3ae8c | 4787 | } |
b5a8894d CS |
4788 | } else { |
4789 | /* Display default ospf (instance 0) info */ | |
4790 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
b1c3ae8c CS |
4791 | if (ospf == NULL || !ospf->oi_running) { |
4792 | if (uj) | |
4793 | json_object_free(json); | |
b5a8894d | 4794 | return CMD_SUCCESS; |
b1c3ae8c | 4795 | } |
b5a8894d CS |
4796 | } |
4797 | ||
b1c3ae8c CS |
4798 | if (ospf) { |
4799 | ret = show_ip_ospf_neighbor_all_common(vty, ospf, json, uj, | |
4800 | use_vrf); | |
4801 | if (uj) { | |
4802 | vty_out(vty, "%s\n", | |
996c9314 LB |
4803 | json_object_to_json_string_ext( |
4804 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c CS |
4805 | } |
4806 | } | |
4807 | ||
4808 | if (uj) | |
4809 | json_object_free(json); | |
b5a8894d CS |
4810 | |
4811 | return ret; | |
7c8ff89e DS |
4812 | } |
4813 | ||
4814 | DEFUN (show_ip_ospf_instance_neighbor_all, | |
4815 | show_ip_ospf_instance_neighbor_all_cmd, | |
6147e2c6 | 4816 | "show ip ospf (1-65535) neighbor all [json]", |
7c8ff89e DS |
4817 | SHOW_STR |
4818 | IP_STR | |
4819 | "OSPF information\n" | |
4820 | "Instance ID\n" | |
4821 | "Neighbor list\n" | |
91756b38 | 4822 | "include down status neighbor\n" |
9973d184 | 4823 | JSON_STR) |
718e3744 | 4824 | { |
d62a17ae | 4825 | int idx_number = 3; |
4826 | struct ospf *ospf; | |
d7c0a89a | 4827 | unsigned short instance = 0; |
9f049418 | 4828 | bool uj = use_json(argc, argv); |
b1c3ae8c CS |
4829 | json_object *json = NULL; |
4830 | int ret = CMD_SUCCESS; | |
7c8ff89e | 4831 | |
d62a17ae | 4832 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
409f98ab | 4833 | if (instance != ospf_instance) |
ac28e4ec CS |
4834 | return CMD_NOT_MY_INSTANCE; |
4835 | ||
409f98ab IR |
4836 | ospf = ospf_lookup_instance(instance); |
4837 | if (!ospf || !ospf->oi_running) | |
d62a17ae | 4838 | return CMD_SUCCESS; |
b1c3ae8c CS |
4839 | if (uj) |
4840 | json = json_object_new_object(); | |
4841 | ||
4842 | ret = show_ip_ospf_neighbor_all_common(vty, ospf, json, uj, 0); | |
4843 | ||
4844 | if (uj) { | |
4845 | vty_out(vty, "%s\n", json_object_to_json_string_ext( | |
4846 | json, JSON_C_TO_STRING_PRETTY)); | |
4847 | json_object_free(json); | |
4848 | } | |
7c8ff89e | 4849 | |
b1c3ae8c | 4850 | return ret; |
7c8ff89e DS |
4851 | } |
4852 | ||
d62a17ae | 4853 | static int show_ip_ospf_neighbor_int_common(struct vty *vty, struct ospf *ospf, |
4854 | int arg_base, | |
4855 | struct cmd_token **argv, | |
9f049418 | 4856 | bool use_json, uint8_t use_vrf) |
d62a17ae | 4857 | { |
4858 | struct interface *ifp; | |
4859 | struct route_node *rn; | |
4860 | json_object *json = NULL; | |
91756b38 | 4861 | |
d62a17ae | 4862 | if (use_json) |
4863 | json = json_object_new_object(); | |
d62a17ae | 4864 | |
4865 | if (ospf->instance) { | |
4866 | if (use_json) | |
4867 | json_object_int_add(json, "ospfInstance", | |
4868 | ospf->instance); | |
4869 | else | |
4870 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
4871 | } | |
4872 | ||
b1c3ae8c | 4873 | ospf_show_vrf_name(ospf, vty, json, use_vrf); |
87bd50e8 | 4874 | |
a36898e7 | 4875 | ifp = if_lookup_by_name(argv[arg_base]->arg, ospf->vrf_id); |
d62a17ae | 4876 | if (!ifp) { |
4877 | if (use_json) | |
4878 | json_object_boolean_true_add(json, "noSuchIface"); | |
4879 | else | |
4880 | vty_out(vty, "No such interface.\n"); | |
4881 | return CMD_WARNING; | |
4882 | } | |
4883 | ||
4884 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { | |
4885 | struct ospf_interface *oi = rn->info; | |
4886 | ||
4887 | if (oi == NULL) | |
4888 | continue; | |
4889 | ||
4890 | show_ip_ospf_neighbor_sub(vty, oi, json, use_json); | |
4891 | } | |
4892 | ||
4893 | if (use_json) { | |
9d303b37 DL |
4894 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
4895 | json, JSON_C_TO_STRING_PRETTY)); | |
d62a17ae | 4896 | json_object_free(json); |
4897 | } else | |
4898 | vty_out(vty, "\n"); | |
4899 | ||
4900 | return CMD_SUCCESS; | |
718e3744 | 4901 | } |
4902 | ||
7c8ff89e DS |
4903 | DEFUN (show_ip_ospf_neighbor_int, |
4904 | show_ip_ospf_neighbor_int_cmd, | |
03ed9f02 | 4905 | "show ip ospf [vrf <NAME>] neighbor IFNAME [json]", |
7c8ff89e DS |
4906 | SHOW_STR |
4907 | IP_STR | |
4908 | "OSPF information\n" | |
03ed9f02 | 4909 | VRF_CMD_HELP_STR |
7c8ff89e | 4910 | "Neighbor list\n" |
91756b38 | 4911 | "Interface name\n" |
9973d184 | 4912 | JSON_STR) |
7c8ff89e | 4913 | { |
d62a17ae | 4914 | struct ospf *ospf; |
03ed9f02 PG |
4915 | int idx_ifname = 0; |
4916 | int idx_vrf = 0; | |
9f049418 | 4917 | bool uj = use_json(argc, argv); |
b5a8894d CS |
4918 | int ret = CMD_SUCCESS; |
4919 | struct interface *ifp = NULL; | |
03ed9f02 PG |
4920 | char *vrf_name = NULL; |
4921 | vrf_id_t vrf_id = VRF_DEFAULT; | |
4922 | struct vrf *vrf = NULL; | |
4923 | ||
4924 | if (argv_find(argv, argc, "vrf", &idx_vrf)) | |
4925 | vrf_name = argv[idx_vrf + 1]->arg; | |
4926 | if (vrf_name && strmatch(vrf_name, VRF_DEFAULT_NAME)) | |
4927 | vrf_name = NULL; | |
4928 | if (vrf_name) { | |
4929 | vrf = vrf_lookup_by_name(vrf_name); | |
4930 | if (vrf) | |
4931 | vrf_id = vrf->vrf_id; | |
4932 | } | |
4933 | ospf = ospf_lookup_by_vrf_id(vrf_id); | |
4934 | ||
4935 | if (!ospf || !ospf->oi_running) | |
4936 | return ret; | |
7c8ff89e | 4937 | |
b5a8894d CS |
4938 | if (!uj) |
4939 | show_ip_ospf_neighbour_header(vty); | |
7c8ff89e | 4940 | |
03ed9f02 | 4941 | argv_find(argv, argc, "IFNAME", &idx_ifname); |
b5a8894d | 4942 | |
a36898e7 | 4943 | ifp = if_lookup_by_name(argv[idx_ifname]->arg, vrf_id); |
03ed9f02 PG |
4944 | if (!ifp) |
4945 | return ret; | |
4946 | ||
4947 | ret = show_ip_ospf_neighbor_int_common(vty, ospf, idx_ifname, | |
4948 | argv, uj, 0); | |
b5a8894d | 4949 | return ret; |
7c8ff89e DS |
4950 | } |
4951 | ||
4952 | DEFUN (show_ip_ospf_instance_neighbor_int, | |
4953 | show_ip_ospf_instance_neighbor_int_cmd, | |
6147e2c6 | 4954 | "show ip ospf (1-65535) neighbor IFNAME [json]", |
7c8ff89e DS |
4955 | SHOW_STR |
4956 | IP_STR | |
4957 | "OSPF information\n" | |
4958 | "Instance ID\n" | |
4959 | "Neighbor list\n" | |
91756b38 | 4960 | "Interface name\n" |
9973d184 | 4961 | JSON_STR) |
7c8ff89e | 4962 | { |
d62a17ae | 4963 | int idx_number = 3; |
b4e84315 | 4964 | int idx_ifname = 5; |
d62a17ae | 4965 | struct ospf *ospf; |
d7c0a89a | 4966 | unsigned short instance = 0; |
9f049418 | 4967 | bool uj = use_json(argc, argv); |
7c8ff89e | 4968 | |
b5a8894d CS |
4969 | if (!uj) |
4970 | show_ip_ospf_neighbour_header(vty); | |
4971 | ||
d62a17ae | 4972 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
409f98ab | 4973 | if (instance != ospf_instance) |
ac28e4ec CS |
4974 | return CMD_NOT_MY_INSTANCE; |
4975 | ||
409f98ab IR |
4976 | ospf = ospf_lookup_instance(instance); |
4977 | if (!ospf || !ospf->oi_running) | |
d62a17ae | 4978 | return CMD_SUCCESS; |
7c8ff89e | 4979 | |
b5a8894d CS |
4980 | if (!uj) |
4981 | show_ip_ospf_neighbour_header(vty); | |
4982 | ||
996c9314 LB |
4983 | return show_ip_ospf_neighbor_int_common(vty, ospf, idx_ifname, argv, uj, |
4984 | 0); | |
718e3744 | 4985 | } |
4986 | ||
d62a17ae | 4987 | static void show_ip_ospf_nbr_nbma_detail_sub(struct vty *vty, |
4988 | struct ospf_interface *oi, | |
4989 | struct ospf_nbr_nbma *nbr_nbma, | |
9f049418 | 4990 | bool use_json, json_object *json) |
d62a17ae | 4991 | { |
4992 | char timebuf[OSPF_TIME_DUMP_SIZE]; | |
96b663a3 | 4993 | char buf[PREFIX_STRLEN]; |
d62a17ae | 4994 | json_object *json_sub = NULL; |
718e3744 | 4995 | |
d62a17ae | 4996 | if (use_json) |
4997 | json_sub = json_object_new_object(); | |
4998 | else /* Show neighbor ID. */ | |
4999 | vty_out(vty, " Neighbor %s,", "-"); | |
5000 | ||
5001 | /* Show interface address. */ | |
5002 | if (use_json) | |
5003 | json_object_string_add(json_sub, "ifaceAddress", | |
96b663a3 MS |
5004 | inet_ntop(AF_INET, &nbr_nbma->addr, |
5005 | buf, sizeof(buf))); | |
d62a17ae | 5006 | else |
96b663a3 MS |
5007 | vty_out(vty, " interface address %pI4\n", |
5008 | &nbr_nbma->addr); | |
d62a17ae | 5009 | |
5010 | /* Show Area ID. */ | |
5011 | if (use_json) { | |
5012 | json_object_string_add(json_sub, "areaId", | |
5013 | ospf_area_desc_string(oi->area)); | |
5014 | json_object_string_add(json_sub, "iface", IF_NAME(oi)); | |
5015 | } else | |
5016 | vty_out(vty, " In the area %s via interface %s\n", | |
5017 | ospf_area_desc_string(oi->area), IF_NAME(oi)); | |
5018 | ||
5019 | /* Show neighbor priority and state. */ | |
5020 | if (use_json) { | |
5021 | json_object_int_add(json_sub, "nbrPriority", | |
5022 | nbr_nbma->priority); | |
5023 | json_object_string_add(json_sub, "nbrState", "down"); | |
5024 | } else | |
5025 | vty_out(vty, " Neighbor priority is %d, State is %s,", | |
5026 | nbr_nbma->priority, "Down"); | |
5027 | ||
5028 | /* Show state changes. */ | |
5029 | if (use_json) | |
5030 | json_object_int_add(json_sub, "stateChangeCounter", | |
5031 | nbr_nbma->state_change); | |
5032 | else | |
5033 | vty_out(vty, " %d state changes\n", nbr_nbma->state_change); | |
5034 | ||
5035 | /* Show PollInterval */ | |
5036 | if (use_json) | |
5037 | json_object_int_add(json_sub, "pollInterval", nbr_nbma->v_poll); | |
5038 | else | |
5039 | vty_out(vty, " Poll interval %d\n", nbr_nbma->v_poll); | |
5040 | ||
5041 | /* Show poll-interval timer. */ | |
b575a12c A |
5042 | if (nbr_nbma->t_poll) { |
5043 | if (use_json) { | |
5044 | long time_store; | |
5045 | time_store = monotime_until(&nbr_nbma->t_poll->u.sands, | |
5046 | NULL) / 1000LL; | |
5047 | json_object_int_add(json_sub, | |
5048 | "pollIntervalTimerDueMsec", | |
5049 | time_store); | |
5050 | } else | |
5051 | vty_out(vty, " Poll timer due in %s\n", | |
5052 | ospf_timer_dump(nbr_nbma->t_poll, timebuf, | |
5053 | sizeof(timebuf))); | |
5054 | } | |
d62a17ae | 5055 | |
5056 | /* Show poll-interval timer thread. */ | |
5057 | if (use_json) { | |
5058 | if (nbr_nbma->t_poll != NULL) | |
5059 | json_object_string_add(json_sub, | |
5060 | "pollIntervalTimerThread", "on"); | |
5061 | } else | |
5062 | vty_out(vty, " Thread Poll Timer %s\n", | |
5063 | nbr_nbma->t_poll != NULL ? "on" : "off"); | |
5064 | ||
5065 | if (use_json) | |
5066 | json_object_object_add(json, "noNbrId", json_sub); | |
5067 | } | |
5068 | ||
5069 | static void show_ip_ospf_neighbor_detail_sub(struct vty *vty, | |
5070 | struct ospf_interface *oi, | |
5071 | struct ospf_neighbor *nbr, | |
cb0b2ac6 | 5072 | struct ospf_neighbor *prev_nbr, |
9f049418 | 5073 | json_object *json, bool use_json) |
d62a17ae | 5074 | { |
5075 | char timebuf[OSPF_TIME_DUMP_SIZE]; | |
cb0b2ac6 CS |
5076 | json_object *json_neigh = NULL, *json_neigh_array = NULL; |
5077 | char neigh_str[INET_ADDRSTRLEN] = {0}; | |
96b663a3 | 5078 | char buf[PREFIX_STRLEN]; |
d62a17ae | 5079 | |
cb0b2ac6 CS |
5080 | if (use_json) { |
5081 | if (prev_nbr && | |
5082 | !IPV4_ADDR_SAME(&prev_nbr->src, &nbr->src)) { | |
5083 | json_neigh_array = NULL; | |
5084 | } | |
5085 | ||
975a328e DA |
5086 | if (nbr->state == NSM_Attempt |
5087 | && nbr->router_id.s_addr == INADDR_ANY) | |
cb0b2ac6 CS |
5088 | strlcpy(neigh_str, "noNbrId", sizeof(neigh_str)); |
5089 | else | |
96b663a3 MS |
5090 | inet_ntop(AF_INET, &nbr->router_id, |
5091 | neigh_str, sizeof(neigh_str)); | |
cb0b2ac6 CS |
5092 | |
5093 | json_object_object_get_ex(json, neigh_str, &json_neigh_array); | |
5094 | ||
5095 | if (!json_neigh_array) { | |
5096 | json_neigh_array = json_object_new_array(); | |
5097 | json_object_object_add(json, neigh_str, | |
5098 | json_neigh_array); | |
5099 | } | |
5100 | ||
5101 | json_neigh = json_object_new_object(); | |
5102 | ||
5103 | } else { | |
d62a17ae | 5104 | /* Show neighbor ID. */ |
975a328e DA |
5105 | if (nbr->state == NSM_Attempt |
5106 | && nbr->router_id.s_addr == INADDR_ANY) | |
d62a17ae | 5107 | vty_out(vty, " Neighbor %s,", "-"); |
5108 | else | |
96b663a3 MS |
5109 | vty_out(vty, " Neighbor %pI4,", |
5110 | &nbr->router_id); | |
d62a17ae | 5111 | } |
5112 | ||
5113 | /* Show interface address. */ | |
5114 | if (use_json) | |
cb0b2ac6 | 5115 | json_object_string_add(json_neigh, "ifaceAddress", |
96b663a3 MS |
5116 | inet_ntop(AF_INET, |
5117 | &nbr->address.u.prefix4, | |
5118 | buf, sizeof(buf))); | |
d62a17ae | 5119 | else |
96b663a3 MS |
5120 | vty_out(vty, " interface address %pI4\n", |
5121 | &nbr->address.u.prefix4); | |
d62a17ae | 5122 | |
5123 | /* Show Area ID. */ | |
5124 | if (use_json) { | |
cb0b2ac6 | 5125 | json_object_string_add(json_neigh, "areaId", |
d62a17ae | 5126 | ospf_area_desc_string(oi->area)); |
cb0b2ac6 | 5127 | json_object_string_add(json_neigh, "ifaceName", oi->ifp->name); |
d62a17ae | 5128 | } else |
5129 | vty_out(vty, " In the area %s via interface %s\n", | |
5130 | ospf_area_desc_string(oi->area), oi->ifp->name); | |
5131 | ||
5132 | /* Show neighbor priority and state. */ | |
5133 | if (use_json) { | |
cb0b2ac6 | 5134 | json_object_int_add(json_neigh, "nbrPriority", nbr->priority); |
d62a17ae | 5135 | json_object_string_add( |
cb0b2ac6 | 5136 | json_neigh, "nbrState", |
d62a17ae | 5137 | lookup_msg(ospf_nsm_state_msg, nbr->state, NULL)); |
5138 | } else | |
5139 | vty_out(vty, " Neighbor priority is %d, State is %s,", | |
5140 | nbr->priority, | |
5141 | lookup_msg(ospf_nsm_state_msg, nbr->state, NULL)); | |
5142 | ||
5143 | /* Show state changes. */ | |
5144 | if (use_json) | |
cb0b2ac6 | 5145 | json_object_int_add(json_neigh, "stateChangeCounter", |
d62a17ae | 5146 | nbr->state_change); |
5147 | else | |
5148 | vty_out(vty, " %d state changes\n", nbr->state_change); | |
5149 | ||
5150 | if (nbr->ts_last_progress.tv_sec || nbr->ts_last_progress.tv_usec) { | |
5151 | struct timeval res; | |
5152 | long time_store; | |
5153 | ||
5154 | time_store = | |
5155 | monotime_since(&nbr->ts_last_progress, &res) / 1000LL; | |
5156 | if (use_json) { | |
cb0b2ac6 | 5157 | json_object_int_add(json_neigh, "lastPrgrsvChangeMsec", |
d62a17ae | 5158 | time_store); |
5159 | } else { | |
5160 | vty_out(vty, | |
5161 | " Most recent state change statistics:\n"); | |
5162 | vty_out(vty, " Progressive change %s ago\n", | |
5163 | ospf_timeval_dump(&res, timebuf, | |
5164 | sizeof(timebuf))); | |
5165 | } | |
5166 | } | |
5167 | ||
5168 | if (nbr->ts_last_regress.tv_sec || nbr->ts_last_regress.tv_usec) { | |
5169 | struct timeval res; | |
5170 | long time_store; | |
5171 | ||
5172 | time_store = | |
5173 | monotime_since(&nbr->ts_last_regress, &res) / 1000LL; | |
5174 | if (use_json) { | |
cb0b2ac6 | 5175 | json_object_int_add(json_neigh, |
d62a17ae | 5176 | "lastRegressiveChangeMsec", |
5177 | time_store); | |
5178 | if (nbr->last_regress_str) | |
5179 | json_object_string_add( | |
cb0b2ac6 CS |
5180 | json_neigh, |
5181 | "lastRegressiveChangeReason", | |
d62a17ae | 5182 | nbr->last_regress_str); |
5183 | } else { | |
5184 | vty_out(vty, | |
5185 | " Regressive change %s ago, due to %s\n", | |
5186 | ospf_timeval_dump(&res, timebuf, | |
5187 | sizeof(timebuf)), | |
5188 | (nbr->last_regress_str ? nbr->last_regress_str | |
5189 | : "??")); | |
5190 | } | |
5191 | } | |
5192 | ||
5193 | /* Show Designated Rotuer ID. */ | |
5194 | if (use_json) | |
cb0b2ac6 | 5195 | json_object_string_add(json_neigh, "routerDesignatedId", |
96b663a3 MS |
5196 | inet_ntop(AF_INET, &nbr->d_router, |
5197 | buf, sizeof(buf))); | |
d62a17ae | 5198 | else |
96b663a3 | 5199 | vty_out(vty, " DR is %pI4,", &nbr->d_router); |
d62a17ae | 5200 | |
5201 | /* Show Backup Designated Rotuer ID. */ | |
5202 | if (use_json) | |
cb0b2ac6 | 5203 | json_object_string_add(json_neigh, "routerDesignatedBackupId", |
96b663a3 MS |
5204 | inet_ntop(AF_INET, &nbr->bd_router, |
5205 | buf, sizeof(buf))); | |
d62a17ae | 5206 | else |
96b663a3 | 5207 | vty_out(vty, " BDR is %pI4\n", &nbr->bd_router); |
d62a17ae | 5208 | |
5209 | /* Show options. */ | |
5210 | if (use_json) { | |
cb0b2ac6 CS |
5211 | json_object_int_add(json_neigh, "optionsCounter", nbr->options); |
5212 | json_object_string_add(json_neigh, "optionsList", | |
d62a17ae | 5213 | ospf_options_dump(nbr->options)); |
5214 | } else | |
5215 | vty_out(vty, " Options %d %s\n", nbr->options, | |
5216 | ospf_options_dump(nbr->options)); | |
5217 | ||
5218 | /* Show Router Dead interval timer. */ | |
5219 | if (use_json) { | |
5220 | if (nbr->t_inactivity) { | |
5221 | long time_store; | |
5222 | time_store = monotime_until(&nbr->t_inactivity->u.sands, | |
5223 | NULL) | |
5224 | / 1000LL; | |
cb0b2ac6 | 5225 | json_object_int_add(json_neigh, |
d62a17ae | 5226 | "routerDeadIntervalTimerDueMsec", |
5227 | time_store); | |
5228 | } else | |
5229 | json_object_int_add( | |
cb0b2ac6 CS |
5230 | json_neigh, |
5231 | "routerDeadIntervalTimerDueMsec", -1); | |
d62a17ae | 5232 | } else |
5233 | vty_out(vty, " Dead timer due in %s\n", | |
5234 | ospf_timer_dump(nbr->t_inactivity, timebuf, | |
5235 | sizeof(timebuf))); | |
5236 | ||
5237 | /* Show Database Summary list. */ | |
5238 | if (use_json) | |
cb0b2ac6 | 5239 | json_object_int_add(json_neigh, "databaseSummaryListCounter", |
d62a17ae | 5240 | ospf_db_summary_count(nbr)); |
5241 | else | |
5242 | vty_out(vty, " Database Summary List %d\n", | |
5243 | ospf_db_summary_count(nbr)); | |
5244 | ||
5245 | /* Show Link State Request list. */ | |
5246 | if (use_json) | |
cb0b2ac6 | 5247 | json_object_int_add(json_neigh, "linkStateRequestListCounter", |
d62a17ae | 5248 | ospf_ls_request_count(nbr)); |
5249 | else | |
5250 | vty_out(vty, " Link State Request List %ld\n", | |
5251 | ospf_ls_request_count(nbr)); | |
5252 | ||
5253 | /* Show Link State Retransmission list. */ | |
5254 | if (use_json) | |
cb0b2ac6 | 5255 | json_object_int_add(json_neigh, |
d62a17ae | 5256 | "linkStateRetransmissionListCounter", |
5257 | ospf_ls_retransmit_count(nbr)); | |
5258 | else | |
5259 | vty_out(vty, " Link State Retransmission List %ld\n", | |
5260 | ospf_ls_retransmit_count(nbr)); | |
5261 | ||
5262 | /* Show inactivity timer thread. */ | |
5263 | if (use_json) { | |
5264 | if (nbr->t_inactivity != NULL) | |
cb0b2ac6 | 5265 | json_object_string_add(json_neigh, |
d62a17ae | 5266 | "threadInactivityTimer", "on"); |
5267 | } else | |
5268 | vty_out(vty, " Thread Inactivity Timer %s\n", | |
5269 | nbr->t_inactivity != NULL ? "on" : "off"); | |
5270 | ||
5271 | /* Show Database Description retransmission thread. */ | |
5272 | if (use_json) { | |
5273 | if (nbr->t_db_desc != NULL) | |
5274 | json_object_string_add( | |
cb0b2ac6 | 5275 | json_neigh, |
d62a17ae | 5276 | "threadDatabaseDescriptionRetransmission", |
5277 | "on"); | |
5278 | } else | |
5279 | vty_out(vty, | |
5280 | " Thread Database Description Retransmision %s\n", | |
5281 | nbr->t_db_desc != NULL ? "on" : "off"); | |
5282 | ||
5283 | /* Show Link State Request Retransmission thread. */ | |
5284 | if (use_json) { | |
5285 | if (nbr->t_ls_req != NULL) | |
5286 | json_object_string_add( | |
cb0b2ac6 | 5287 | json_neigh, |
d62a17ae | 5288 | "threadLinkStateRequestRetransmission", "on"); |
5289 | } else | |
5290 | vty_out(vty, | |
5291 | " Thread Link State Request Retransmission %s\n", | |
5292 | nbr->t_ls_req != NULL ? "on" : "off"); | |
5293 | ||
5294 | /* Show Link State Update Retransmission thread. */ | |
5295 | if (use_json) { | |
5296 | if (nbr->t_ls_upd != NULL) | |
5297 | json_object_string_add( | |
cb0b2ac6 CS |
5298 | json_neigh, |
5299 | "threadLinkStateUpdateRetransmission", | |
d62a17ae | 5300 | "on"); |
5301 | } else | |
5302 | vty_out(vty, | |
5303 | " Thread Link State Update Retransmission %s\n\n", | |
5304 | nbr->t_ls_upd != NULL ? "on" : "off"); | |
5305 | ||
abd5b8c7 | 5306 | if (!use_json) { |
5307 | vty_out(vty, " Graceful restart Helper info:\n"); | |
5308 | ||
5309 | if (OSPF_GR_IS_ACTIVE_HELPER(nbr)) { | |
5310 | vty_out(vty, | |
5311 | " Graceful Restart HELPER Status : Inprogress.\n"); | |
5312 | ||
5313 | vty_out(vty, | |
5314 | " Graceful Restart grace period time: %d (seconds).\n", | |
5315 | nbr->gr_helper_info.recvd_grace_period); | |
5316 | vty_out(vty, " Graceful Restart reason: %s.\n", | |
d05d5280 MS |
5317 | ospf_restart_reason2str( |
5318 | nbr->gr_helper_info.gr_restart_reason)); | |
abd5b8c7 | 5319 | } else { |
5320 | vty_out(vty, | |
5321 | " Graceful Restart HELPER Status : None\n"); | |
5322 | } | |
5323 | ||
5324 | if (nbr->gr_helper_info.rejected_reason | |
5325 | != OSPF_HELPER_REJECTED_NONE) | |
5326 | vty_out(vty, " Helper rejected reason: %s.\n", | |
d05d5280 MS |
5327 | ospf_rejected_reason2str( |
5328 | nbr->gr_helper_info.rejected_reason)); | |
abd5b8c7 | 5329 | |
5330 | if (nbr->gr_helper_info.helper_exit_reason | |
5331 | != OSPF_GR_HELPER_EXIT_NONE) | |
5332 | vty_out(vty, " Last helper exit reason: %s.\n\n", | |
d05d5280 MS |
5333 | ospf_exit_reason2str( |
5334 | nbr->gr_helper_info.helper_exit_reason)); | |
abd5b8c7 | 5335 | else |
5336 | vty_out(vty, "\n"); | |
5337 | } else { | |
5338 | json_object_string_add(json_neigh, "grHelperStatus", | |
5339 | OSPF_GR_IS_ACTIVE_HELPER(nbr) ? | |
5340 | "Inprogress" | |
5341 | : "None"); | |
5342 | if (OSPF_GR_IS_ACTIVE_HELPER(nbr)) { | |
5343 | json_object_int_add( | |
5344 | json_neigh, "graceInterval", | |
5345 | nbr->gr_helper_info.recvd_grace_period); | |
5346 | json_object_string_add( | |
5347 | json_neigh, "grRestartReason", | |
d05d5280 MS |
5348 | ospf_restart_reason2str( |
5349 | nbr->gr_helper_info.gr_restart_reason)); | |
abd5b8c7 | 5350 | } |
5351 | ||
5352 | if (nbr->gr_helper_info.rejected_reason | |
5353 | != OSPF_HELPER_REJECTED_NONE) | |
5354 | json_object_string_add( | |
5355 | json_neigh, "helperRejectReason", | |
d05d5280 MS |
5356 | ospf_rejected_reason2str( |
5357 | nbr->gr_helper_info.rejected_reason)); | |
abd5b8c7 | 5358 | |
5359 | if (nbr->gr_helper_info.helper_exit_reason | |
5360 | != OSPF_GR_HELPER_EXIT_NONE) | |
5361 | json_object_string_add( | |
5362 | json_neigh, "helperExitReason", | |
d05d5280 MS |
5363 | ospf_exit_reason2str( |
5364 | nbr->gr_helper_info | |
5365 | .helper_exit_reason)); | |
abd5b8c7 | 5366 | } |
5367 | ||
659f4e40 | 5368 | bfd_sess_show(vty, json_neigh, nbr->bfd_session); |
cb0b2ac6 CS |
5369 | |
5370 | if (use_json) | |
5371 | json_object_array_add(json_neigh_array, json_neigh); | |
d62a17ae | 5372 | |
d62a17ae | 5373 | } |
5374 | ||
5375 | static int show_ip_ospf_neighbor_id_common(struct vty *vty, struct ospf *ospf, | |
986b87cb | 5376 | struct in_addr *router_id, |
9f049418 | 5377 | bool use_json, uint8_t use_vrf) |
d62a17ae | 5378 | { |
5379 | struct listnode *node; | |
5380 | struct ospf_neighbor *nbr; | |
5381 | struct ospf_interface *oi; | |
d62a17ae | 5382 | json_object *json = NULL; |
5383 | ||
5384 | if (use_json) | |
5385 | json = json_object_new_object(); | |
5386 | ||
5387 | if (ospf->instance) { | |
5388 | if (use_json) | |
5389 | json_object_int_add(json, "ospfInstance", | |
5390 | ospf->instance); | |
5391 | else | |
5392 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
5393 | } | |
5394 | ||
b1c3ae8c | 5395 | ospf_show_vrf_name(ospf, vty, json, use_vrf); |
87bd50e8 | 5396 | |
d62a17ae | 5397 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) { |
986b87cb | 5398 | if ((nbr = ospf_nbr_lookup_by_routerid(oi->nbrs, router_id))) { |
cb0b2ac6 CS |
5399 | show_ip_ospf_neighbor_detail_sub(vty, oi, nbr, NULL, |
5400 | json, use_json); | |
d62a17ae | 5401 | } |
5402 | } | |
5403 | ||
5404 | if (use_json) { | |
9d303b37 DL |
5405 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
5406 | json, JSON_C_TO_STRING_PRETTY)); | |
d62a17ae | 5407 | json_object_free(json); |
5408 | } else | |
5409 | vty_out(vty, "\n"); | |
5410 | ||
5411 | return CMD_SUCCESS; | |
718e3744 | 5412 | } |
5413 | ||
986b87cb | 5414 | DEFPY (show_ip_ospf_neighbor_id, |
7c8ff89e | 5415 | show_ip_ospf_neighbor_id_cmd, |
986b87cb | 5416 | "show ip ospf neighbor A.B.C.D$router_id [json$json]", |
718e3744 | 5417 | SHOW_STR |
5418 | IP_STR | |
5419 | "OSPF information\n" | |
5420 | "Neighbor list\n" | |
3ac237f8 | 5421 | "Neighbor ID\n" |
9973d184 | 5422 | JSON_STR) |
718e3744 | 5423 | { |
d62a17ae | 5424 | struct ospf *ospf; |
986b87cb | 5425 | struct listnode *node; |
b5a8894d | 5426 | int ret = CMD_SUCCESS; |
7c8ff89e | 5427 | |
b5a8894d CS |
5428 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { |
5429 | if (!ospf->oi_running) | |
5430 | continue; | |
986b87cb RW |
5431 | ret = show_ip_ospf_neighbor_id_common(vty, ospf, &router_id, |
5432 | !!json, 0); | |
b5a8894d | 5433 | } |
7c8ff89e | 5434 | |
b5a8894d | 5435 | return ret; |
7c8ff89e DS |
5436 | } |
5437 | ||
986b87cb | 5438 | DEFPY (show_ip_ospf_instance_neighbor_id, |
7c8ff89e | 5439 | show_ip_ospf_instance_neighbor_id_cmd, |
986b87cb | 5440 | "show ip ospf (1-65535)$instance neighbor A.B.C.D$router_id [json$json]", |
7c8ff89e DS |
5441 | SHOW_STR |
5442 | IP_STR | |
5443 | "OSPF information\n" | |
5444 | "Instance ID\n" | |
5445 | "Neighbor list\n" | |
3ac237f8 | 5446 | "Neighbor ID\n" |
9973d184 | 5447 | JSON_STR) |
7c8ff89e | 5448 | { |
d62a17ae | 5449 | struct ospf *ospf; |
7c8ff89e | 5450 | |
409f98ab | 5451 | if (instance != ospf_instance) |
ac28e4ec CS |
5452 | return CMD_NOT_MY_INSTANCE; |
5453 | ||
409f98ab IR |
5454 | ospf = ospf_lookup_instance(instance); |
5455 | if (!ospf || !ospf->oi_running) | |
d62a17ae | 5456 | return CMD_SUCCESS; |
7c8ff89e | 5457 | |
986b87cb RW |
5458 | return show_ip_ospf_neighbor_id_common(vty, ospf, &router_id, !!json, |
5459 | 0); | |
7c8ff89e DS |
5460 | } |
5461 | ||
d62a17ae | 5462 | static int show_ip_ospf_neighbor_detail_common(struct vty *vty, |
5463 | struct ospf *ospf, | |
9f049418 | 5464 | json_object *json, bool use_json, |
d7c0a89a | 5465 | uint8_t use_vrf) |
d62a17ae | 5466 | { |
5467 | struct ospf_interface *oi; | |
5468 | struct listnode *node; | |
b1c3ae8c | 5469 | json_object *json_vrf = NULL; |
cb0b2ac6 | 5470 | json_object *json_nbr_sub = NULL; |
d62a17ae | 5471 | |
b1c3ae8c CS |
5472 | if (use_json) { |
5473 | if (use_vrf) | |
5474 | json_vrf = json_object_new_object(); | |
5475 | else | |
5476 | json_vrf = json; | |
cb0b2ac6 CS |
5477 | |
5478 | json_nbr_sub = json_object_new_object(); | |
b1c3ae8c | 5479 | } |
cb0b2ac6 | 5480 | |
d62a17ae | 5481 | if (ospf->instance) { |
5482 | if (use_json) | |
cb0b2ac6 | 5483 | json_object_int_add(json, "ospfInstance", |
d62a17ae | 5484 | ospf->instance); |
5485 | else | |
5486 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
5487 | } | |
5488 | ||
b1c3ae8c | 5489 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); |
87bd50e8 | 5490 | |
d62a17ae | 5491 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) { |
5492 | struct route_node *rn; | |
cb0b2ac6 | 5493 | struct ospf_neighbor *nbr, *prev_nbr = NULL; |
d62a17ae | 5494 | |
5495 | for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) { | |
5496 | if ((nbr = rn->info)) { | |
5497 | if (nbr != oi->nbr_self) { | |
5498 | if (nbr->state != NSM_Down) { | |
5499 | show_ip_ospf_neighbor_detail_sub( | |
cb0b2ac6 CS |
5500 | vty, oi, nbr, prev_nbr, |
5501 | json_nbr_sub, use_json); | |
d62a17ae | 5502 | } |
5503 | } | |
cb0b2ac6 | 5504 | prev_nbr = nbr; |
d62a17ae | 5505 | } |
5506 | } | |
5507 | } | |
5508 | ||
5509 | if (use_json) { | |
cb0b2ac6 CS |
5510 | json_object_object_add(json_vrf, "neighbors", |
5511 | json_nbr_sub); | |
44076f4d RW |
5512 | if (use_vrf) |
5513 | json_object_object_add(json, ospf_get_name(ospf), | |
5514 | json_vrf); | |
d62a17ae | 5515 | } else |
5516 | vty_out(vty, "\n"); | |
5517 | ||
5518 | return CMD_SUCCESS; | |
718e3744 | 5519 | } |
5520 | ||
7c8ff89e DS |
5521 | DEFUN (show_ip_ospf_neighbor_detail, |
5522 | show_ip_ospf_neighbor_detail_cmd, | |
b5a8894d | 5523 | "show ip ospf [vrf <NAME|all>] neighbor detail [json]", |
718e3744 | 5524 | SHOW_STR |
5525 | IP_STR | |
5526 | "OSPF information\n" | |
b5a8894d CS |
5527 | VRF_CMD_HELP_STR |
5528 | "All VRFs\n" | |
718e3744 | 5529 | "Neighbor list\n" |
3ac237f8 | 5530 | "detail of all neighbors\n" |
9973d184 | 5531 | JSON_STR) |
718e3744 | 5532 | { |
d62a17ae | 5533 | struct ospf *ospf; |
9f049418 | 5534 | bool uj = use_json(argc, argv); |
b5a8894d CS |
5535 | struct listnode *node = NULL; |
5536 | char *vrf_name = NULL; | |
2951a7a4 | 5537 | bool all_vrf = false; |
b5a8894d CS |
5538 | int ret = CMD_SUCCESS; |
5539 | int inst = 0; | |
5540 | int idx_vrf = 0; | |
d7c0a89a | 5541 | uint8_t use_vrf = 0; |
b1c3ae8c | 5542 | json_object *json = NULL; |
7c8ff89e | 5543 | |
43b8d1d8 | 5544 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
7c8ff89e | 5545 | |
b1c3ae8c CS |
5546 | if (uj) |
5547 | json = json_object_new_object(); | |
5548 | ||
b5a8894d CS |
5549 | /* vrf input is provided could be all or specific vrf*/ |
5550 | if (vrf_name) { | |
b1c3ae8c | 5551 | use_vrf = 1; |
b5a8894d CS |
5552 | if (all_vrf) { |
5553 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
5554 | if (!ospf->oi_running) | |
5555 | continue; | |
996c9314 LB |
5556 | ret = show_ip_ospf_neighbor_detail_common( |
5557 | vty, ospf, json, uj, use_vrf); | |
b1c3ae8c CS |
5558 | } |
5559 | if (uj) { | |
5560 | vty_out(vty, "%s\n", | |
996c9314 LB |
5561 | json_object_to_json_string_ext( |
5562 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 5563 | json_object_free(json); |
b5a8894d | 5564 | } |
b1c3ae8c | 5565 | |
b5a8894d CS |
5566 | return ret; |
5567 | } | |
5568 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
b1c3ae8c CS |
5569 | if (ospf == NULL || !ospf->oi_running) { |
5570 | if (uj) | |
5571 | json_object_free(json); | |
b5a8894d | 5572 | return CMD_SUCCESS; |
b1c3ae8c | 5573 | } |
b5a8894d CS |
5574 | } else { |
5575 | /* Display default ospf (instance 0) info */ | |
5576 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
b1c3ae8c CS |
5577 | if (ospf == NULL || !ospf->oi_running) { |
5578 | if (uj) | |
5579 | json_object_free(json); | |
b5a8894d | 5580 | return CMD_SUCCESS; |
b1c3ae8c | 5581 | } |
b5a8894d CS |
5582 | } |
5583 | ||
b1c3ae8c CS |
5584 | if (ospf) { |
5585 | ret = show_ip_ospf_neighbor_detail_common(vty, ospf, json, uj, | |
5586 | use_vrf); | |
5587 | if (uj) { | |
5588 | vty_out(vty, "%s\n", | |
996c9314 LB |
5589 | json_object_to_json_string_ext( |
5590 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c CS |
5591 | } |
5592 | } | |
5593 | ||
5594 | if (uj) | |
5595 | json_object_free(json); | |
b5a8894d CS |
5596 | |
5597 | return ret; | |
7c8ff89e DS |
5598 | } |
5599 | ||
5600 | DEFUN (show_ip_ospf_instance_neighbor_detail, | |
5601 | show_ip_ospf_instance_neighbor_detail_cmd, | |
6147e2c6 | 5602 | "show ip ospf (1-65535) neighbor detail [json]", |
7c8ff89e DS |
5603 | SHOW_STR |
5604 | IP_STR | |
5605 | "OSPF information\n" | |
5606 | "Instance ID\n" | |
5607 | "Neighbor list\n" | |
3ac237f8 | 5608 | "detail of all neighbors\n" |
9973d184 | 5609 | JSON_STR) |
7c8ff89e | 5610 | { |
d62a17ae | 5611 | int idx_number = 3; |
5612 | struct ospf *ospf; | |
d7c0a89a | 5613 | unsigned short instance = 0; |
9f049418 | 5614 | bool uj = use_json(argc, argv); |
b1c3ae8c CS |
5615 | json_object *json = NULL; |
5616 | int ret = CMD_SUCCESS; | |
7c8ff89e | 5617 | |
d62a17ae | 5618 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
409f98ab | 5619 | if (instance != ospf_instance) |
ac28e4ec CS |
5620 | return CMD_NOT_MY_INSTANCE; |
5621 | ||
409f98ab IR |
5622 | ospf = ospf_lookup_instance(instance); |
5623 | if (!ospf || !ospf->oi_running) | |
d62a17ae | 5624 | return CMD_SUCCESS; |
7c8ff89e | 5625 | |
b1c3ae8c CS |
5626 | if (uj) |
5627 | json = json_object_new_object(); | |
5628 | ||
5629 | ret = show_ip_ospf_neighbor_detail_common(vty, ospf, json, uj, 0); | |
5630 | ||
5631 | if (uj) { | |
5632 | vty_out(vty, "%s\n", json_object_to_json_string_ext( | |
5633 | json, JSON_C_TO_STRING_PRETTY)); | |
5634 | json_object_free(json); | |
5635 | } | |
5636 | ||
5637 | return ret; | |
7c8ff89e DS |
5638 | } |
5639 | ||
d62a17ae | 5640 | static int show_ip_ospf_neighbor_detail_all_common(struct vty *vty, |
5641 | struct ospf *ospf, | |
b1c3ae8c | 5642 | json_object *json, |
9f049418 | 5643 | bool use_json, |
d7c0a89a | 5644 | uint8_t use_vrf) |
d62a17ae | 5645 | { |
5646 | struct listnode *node; | |
5647 | struct ospf_interface *oi; | |
b1c3ae8c | 5648 | json_object *json_vrf = NULL; |
718e3744 | 5649 | |
b1c3ae8c CS |
5650 | if (use_json) { |
5651 | if (use_vrf) | |
5652 | json_vrf = json_object_new_object(); | |
5653 | else | |
5654 | json_vrf = json; | |
5655 | } | |
d62a17ae | 5656 | |
5657 | if (ospf->instance) { | |
5658 | if (use_json) | |
5659 | json_object_int_add(json, "ospfInstance", | |
5660 | ospf->instance); | |
5661 | else | |
5662 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
5663 | } | |
5664 | ||
b1c3ae8c | 5665 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); |
87bd50e8 | 5666 | |
d62a17ae | 5667 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) { |
5668 | struct route_node *rn; | |
cb0b2ac6 | 5669 | struct ospf_neighbor *nbr, *prev_nbr = NULL; |
d62a17ae | 5670 | struct ospf_nbr_nbma *nbr_nbma; |
5671 | ||
cb0b2ac6 CS |
5672 | for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) { |
5673 | if ((nbr = rn->info)) { | |
d62a17ae | 5674 | if (nbr != oi->nbr_self) |
5675 | if (nbr->state != NSM_Down) | |
5676 | show_ip_ospf_neighbor_detail_sub( | |
5677 | vty, oi, rn->info, | |
cb0b2ac6 | 5678 | prev_nbr, |
b1c3ae8c | 5679 | json_vrf, use_json); |
cb0b2ac6 CS |
5680 | prev_nbr = nbr; |
5681 | } | |
5682 | } | |
d62a17ae | 5683 | |
5684 | if (oi->type == OSPF_IFTYPE_NBMA) { | |
5685 | struct listnode *nd; | |
5686 | ||
5687 | for (ALL_LIST_ELEMENTS_RO(oi->nbr_nbma, nd, nbr_nbma)) { | |
5688 | if (nbr_nbma->nbr == NULL | |
5689 | || nbr_nbma->nbr->state == NSM_Down) | |
5690 | show_ip_ospf_nbr_nbma_detail_sub( | |
5691 | vty, oi, nbr_nbma, use_json, | |
b1c3ae8c | 5692 | json_vrf); |
d62a17ae | 5693 | } |
5694 | } | |
5695 | } | |
5696 | ||
5697 | if (use_json) { | |
44076f4d RW |
5698 | if (use_vrf) |
5699 | json_object_object_add(json, ospf_get_name(ospf), | |
5700 | json_vrf); | |
d62a17ae | 5701 | } else { |
5702 | vty_out(vty, "\n"); | |
5703 | } | |
5704 | ||
5705 | return CMD_SUCCESS; | |
718e3744 | 5706 | } |
5707 | ||
7c8ff89e DS |
5708 | DEFUN (show_ip_ospf_neighbor_detail_all, |
5709 | show_ip_ospf_neighbor_detail_all_cmd, | |
b5a8894d | 5710 | "show ip ospf [vrf <NAME|all>] neighbor detail all [json]", |
718e3744 | 5711 | SHOW_STR |
5712 | IP_STR | |
5713 | "OSPF information\n" | |
b5a8894d CS |
5714 | VRF_CMD_HELP_STR |
5715 | "All VRFs\n" | |
718e3744 | 5716 | "Neighbor list\n" |
7c8ff89e | 5717 | "detail of all neighbors\n" |
3ac237f8 | 5718 | "include down status neighbor\n" |
9973d184 | 5719 | JSON_STR) |
718e3744 | 5720 | { |
d62a17ae | 5721 | struct ospf *ospf; |
9f049418 | 5722 | bool uj = use_json(argc, argv); |
b5a8894d CS |
5723 | struct listnode *node = NULL; |
5724 | char *vrf_name = NULL; | |
2951a7a4 | 5725 | bool all_vrf = false; |
b5a8894d CS |
5726 | int ret = CMD_SUCCESS; |
5727 | int inst = 0; | |
5728 | int idx_vrf = 0; | |
d7c0a89a | 5729 | uint8_t use_vrf = 0; |
b1c3ae8c | 5730 | json_object *json = NULL; |
7c8ff89e | 5731 | |
43b8d1d8 | 5732 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
7c8ff89e | 5733 | |
b1c3ae8c CS |
5734 | if (uj) |
5735 | json = json_object_new_object(); | |
5736 | ||
b5a8894d CS |
5737 | /* vrf input is provided could be all or specific vrf*/ |
5738 | if (vrf_name) { | |
b1c3ae8c | 5739 | use_vrf = 1; |
b5a8894d CS |
5740 | if (all_vrf) { |
5741 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
5742 | if (!ospf->oi_running) | |
5743 | continue; | |
996c9314 LB |
5744 | ret = show_ip_ospf_neighbor_detail_all_common( |
5745 | vty, ospf, json, uj, use_vrf); | |
b5a8894d | 5746 | } |
b1c3ae8c CS |
5747 | |
5748 | if (uj) { | |
5749 | vty_out(vty, "%s\n", | |
996c9314 LB |
5750 | json_object_to_json_string_ext( |
5751 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c CS |
5752 | json_object_free(json); |
5753 | } | |
5754 | ||
b5a8894d CS |
5755 | return ret; |
5756 | } | |
5757 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
b1c3ae8c CS |
5758 | if (ospf == NULL || !ospf->oi_running) { |
5759 | if (uj) | |
5760 | json_object_free(json); | |
b5a8894d | 5761 | return CMD_SUCCESS; |
b1c3ae8c | 5762 | } |
b5a8894d CS |
5763 | } else { |
5764 | /* Display default ospf (instance 0) info */ | |
5765 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
b1c3ae8c CS |
5766 | if (ospf == NULL || !ospf->oi_running) { |
5767 | if (uj) | |
5768 | json_object_free(json); | |
b5a8894d | 5769 | return CMD_SUCCESS; |
b1c3ae8c | 5770 | } |
b5a8894d CS |
5771 | } |
5772 | ||
b1c3ae8c CS |
5773 | if (ospf) { |
5774 | ret = show_ip_ospf_neighbor_detail_all_common(vty, ospf, json, | |
5775 | uj, use_vrf); | |
5776 | if (uj) { | |
5777 | vty_out(vty, "%s\n", | |
996c9314 LB |
5778 | json_object_to_json_string_ext( |
5779 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c CS |
5780 | } |
5781 | } | |
5782 | ||
5783 | if (uj) | |
5784 | json_object_free(json); | |
b5a8894d CS |
5785 | |
5786 | return ret; | |
7c8ff89e DS |
5787 | } |
5788 | ||
5789 | DEFUN (show_ip_ospf_instance_neighbor_detail_all, | |
5790 | show_ip_ospf_instance_neighbor_detail_all_cmd, | |
6147e2c6 | 5791 | "show ip ospf (1-65535) neighbor detail all [json]", |
7c8ff89e DS |
5792 | SHOW_STR |
5793 | IP_STR | |
5794 | "OSPF information\n" | |
5795 | "Instance ID\n" | |
5796 | "Neighbor list\n" | |
5797 | "detail of all neighbors\n" | |
3ac237f8 | 5798 | "include down status neighbor\n" |
9973d184 | 5799 | JSON_STR) |
7c8ff89e | 5800 | { |
d62a17ae | 5801 | int idx_number = 3; |
5802 | struct ospf *ospf; | |
d7c0a89a | 5803 | unsigned short instance = 0; |
9f049418 | 5804 | bool uj = use_json(argc, argv); |
b1c3ae8c CS |
5805 | json_object *json = NULL; |
5806 | int ret = CMD_SUCCESS; | |
7c8ff89e | 5807 | |
d62a17ae | 5808 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
409f98ab | 5809 | if (instance != ospf_instance) |
ac28e4ec CS |
5810 | return CMD_NOT_MY_INSTANCE; |
5811 | ||
409f98ab IR |
5812 | ospf = ospf_lookup_instance(instance); |
5813 | if (!ospf || !ospf->oi_running) | |
d62a17ae | 5814 | return CMD_SUCCESS; |
7c8ff89e | 5815 | |
b1c3ae8c CS |
5816 | if (uj) |
5817 | json = json_object_new_object(); | |
5818 | ||
5819 | ret = show_ip_ospf_neighbor_detail_all_common(vty, ospf, json, uj, 0); | |
5820 | ||
5821 | if (uj) { | |
996c9314 LB |
5822 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
5823 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c CS |
5824 | json_object_free(json); |
5825 | } | |
5826 | ||
5827 | return ret; | |
7c8ff89e DS |
5828 | } |
5829 | ||
d62a17ae | 5830 | static int show_ip_ospf_neighbor_int_detail_common(struct vty *vty, |
5831 | struct ospf *ospf, | |
5832 | int arg_base, | |
5833 | struct cmd_token **argv, | |
9f049418 | 5834 | bool use_json) |
d62a17ae | 5835 | { |
5836 | struct ospf_interface *oi; | |
5837 | struct interface *ifp; | |
5838 | struct route_node *rn, *nrn; | |
5839 | struct ospf_neighbor *nbr; | |
5840 | json_object *json = NULL; | |
718e3744 | 5841 | |
d62a17ae | 5842 | if (use_json) |
5843 | json = json_object_new_object(); | |
5844 | ||
5845 | if (ospf->instance) { | |
5846 | if (use_json) | |
5847 | json_object_int_add(json, "ospfInstance", | |
5848 | ospf->instance); | |
5849 | else | |
5850 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
5851 | } | |
5852 | ||
a36898e7 | 5853 | ifp = if_lookup_by_name(argv[arg_base]->arg, ospf->vrf_id); |
d62a17ae | 5854 | if (!ifp) { |
5855 | if (!use_json) | |
5856 | vty_out(vty, "No such interface.\n"); | |
16307668 RW |
5857 | else { |
5858 | vty_out(vty, "{}\n"); | |
5859 | json_object_free(json); | |
5860 | } | |
d62a17ae | 5861 | return CMD_WARNING; |
5862 | } | |
5863 | ||
5864 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { | |
5865 | if ((oi = rn->info)) { | |
5866 | for (nrn = route_top(oi->nbrs); nrn; | |
5867 | nrn = route_next(nrn)) { | |
5868 | if ((nbr = nrn->info)) { | |
5869 | if (nbr != oi->nbr_self) { | |
5870 | if (nbr->state != NSM_Down) | |
5871 | show_ip_ospf_neighbor_detail_sub( | |
5872 | vty, oi, nbr, | |
cb0b2ac6 | 5873 | NULL, |
b1c3ae8c | 5874 | json, use_json); |
d62a17ae | 5875 | } |
5876 | } | |
5877 | } | |
5878 | } | |
5879 | } | |
5880 | ||
5881 | if (use_json) { | |
9d303b37 DL |
5882 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
5883 | json, JSON_C_TO_STRING_PRETTY)); | |
d62a17ae | 5884 | json_object_free(json); |
5885 | } else | |
5886 | vty_out(vty, "\n"); | |
5887 | ||
5888 | return CMD_SUCCESS; | |
718e3744 | 5889 | } |
5890 | ||
7c8ff89e DS |
5891 | DEFUN (show_ip_ospf_neighbor_int_detail, |
5892 | show_ip_ospf_neighbor_int_detail_cmd, | |
b162fa78 | 5893 | "show ip ospf neighbor IFNAME detail [json]", |
7c8ff89e DS |
5894 | SHOW_STR |
5895 | IP_STR | |
5896 | "OSPF information\n" | |
5897 | "Neighbor list\n" | |
5898 | "Interface name\n" | |
3ac237f8 | 5899 | "detail of all neighbors\n" |
9973d184 | 5900 | JSON_STR) |
7c8ff89e | 5901 | { |
d62a17ae | 5902 | struct ospf *ospf; |
9f049418 | 5903 | bool uj = use_json(argc, argv); |
b5a8894d CS |
5904 | struct listnode *node = NULL; |
5905 | int ret = CMD_SUCCESS; | |
2951a7a4 | 5906 | bool ospf_output = false; |
7c8ff89e | 5907 | |
b5a8894d CS |
5908 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { |
5909 | if (!ospf->oi_running) | |
5910 | continue; | |
2951a7a4 | 5911 | ospf_output = true; |
cb0b2ac6 | 5912 | ret = show_ip_ospf_neighbor_int_detail_common(vty, ospf, 4, |
b5a8894d CS |
5913 | argv, uj); |
5914 | } | |
7c8ff89e | 5915 | |
9f049418 DS |
5916 | if (!ospf_output) |
5917 | vty_out(vty, "%% OSPF instance not found\n"); | |
5918 | ||
b5a8894d | 5919 | return ret; |
7c8ff89e DS |
5920 | } |
5921 | ||
5922 | DEFUN (show_ip_ospf_instance_neighbor_int_detail, | |
5923 | show_ip_ospf_instance_neighbor_int_detail_cmd, | |
6147e2c6 | 5924 | "show ip ospf (1-65535) neighbor IFNAME detail [json]", |
7c8ff89e DS |
5925 | SHOW_STR |
5926 | IP_STR | |
5927 | "OSPF information\n" | |
5928 | "Instance ID\n" | |
5929 | "Neighbor list\n" | |
5930 | "Interface name\n" | |
3ac237f8 | 5931 | "detail of all neighbors\n" |
9973d184 | 5932 | JSON_STR) |
7c8ff89e | 5933 | { |
d62a17ae | 5934 | int idx_number = 3; |
b4e84315 | 5935 | int idx_ifname = 5; |
d62a17ae | 5936 | struct ospf *ospf; |
d7c0a89a | 5937 | unsigned short instance = 0; |
9f049418 | 5938 | bool uj = use_json(argc, argv); |
7c8ff89e | 5939 | |
d62a17ae | 5940 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
409f98ab | 5941 | if (instance != ospf_instance) |
ac28e4ec CS |
5942 | return CMD_NOT_MY_INSTANCE; |
5943 | ||
409f98ab IR |
5944 | ospf = ospf_lookup_instance(instance); |
5945 | if (!ospf || !ospf->oi_running) | |
d62a17ae | 5946 | return CMD_SUCCESS; |
7c8ff89e | 5947 | |
996c9314 LB |
5948 | return show_ip_ospf_neighbor_int_detail_common(vty, ospf, idx_ifname, |
5949 | argv, uj); | |
7c8ff89e | 5950 | } |
6b0655a2 | 5951 | |
718e3744 | 5952 | /* Show functions */ |
f328dc60 | 5953 | static int show_lsa_summary(struct vty *vty, struct ospf_lsa *lsa, int self, |
5954 | json_object *json_lsa) | |
d62a17ae | 5955 | { |
5956 | struct router_lsa *rl; | |
5957 | struct summary_lsa *sl; | |
5958 | struct as_external_lsa *asel; | |
5959 | struct prefix_ipv4 p; | |
f328dc60 | 5960 | char buf[PREFIX2STR_BUFFER]; |
d62a17ae | 5961 | |
5962 | if (lsa != NULL) | |
5963 | /* If self option is set, check LSA self flag. */ | |
5964 | if (self == 0 || IS_LSA_SELF(lsa)) { | |
f328dc60 | 5965 | |
5966 | if (!json_lsa) { | |
5967 | /* LSA common part show. */ | |
5968 | vty_out(vty, "%-15pI4", | |
5969 | &lsa->data->id); | |
ce513ac6 MS |
5970 | vty_out(vty, "%-15pI4 %4d 0x%08lx 0x%04x", |
5971 | &lsa->data->adv_router, LS_AGE(lsa), | |
f328dc60 | 5972 | (unsigned long)ntohl( |
5973 | lsa->data->ls_seqnum), | |
5974 | ntohs(lsa->data->checksum)); | |
5975 | } else { | |
5976 | char seqnum[10]; | |
5977 | char checksum[10]; | |
5978 | ||
5979 | snprintf(seqnum, sizeof(seqnum), "%x", | |
5980 | ntohl(lsa->data->ls_seqnum)); | |
5981 | snprintf(checksum, sizeof(checksum), "%x", | |
5982 | ntohs(lsa->data->checksum)); | |
5983 | json_object_string_add( | |
5984 | json_lsa, "lsId", | |
ce513ac6 MS |
5985 | inet_ntop(AF_INET, &lsa->data->id, |
5986 | buf, sizeof(buf))); | |
f328dc60 | 5987 | json_object_string_add( |
5988 | json_lsa, "advertisedRouter", | |
ce513ac6 MS |
5989 | inet_ntop(AF_INET, |
5990 | &lsa->data->adv_router, | |
5991 | buf, sizeof(buf))); | |
f328dc60 | 5992 | json_object_int_add(json_lsa, "lsaAge", |
5993 | LS_AGE(lsa)); | |
5994 | json_object_string_add( | |
5995 | json_lsa, "sequenceNumber", seqnum); | |
5996 | json_object_string_add(json_lsa, "checksum", | |
5997 | checksum); | |
5998 | } | |
5999 | ||
d62a17ae | 6000 | /* LSA specific part show. */ |
6001 | switch (lsa->data->type) { | |
6002 | case OSPF_ROUTER_LSA: | |
6003 | rl = (struct router_lsa *)lsa->data; | |
f328dc60 | 6004 | |
6005 | if (!json_lsa) | |
6006 | vty_out(vty, " %-d", ntohs(rl->links)); | |
6007 | else | |
6008 | json_object_int_add(json_lsa, | |
6009 | "numOfRouterLinks", | |
6010 | ntohs(rl->links)); | |
d62a17ae | 6011 | break; |
6012 | case OSPF_SUMMARY_LSA: | |
6013 | sl = (struct summary_lsa *)lsa->data; | |
6014 | ||
6015 | p.family = AF_INET; | |
6016 | p.prefix = sl->header.id; | |
6017 | p.prefixlen = ip_masklen(sl->mask); | |
6018 | apply_mask_ipv4(&p); | |
6019 | ||
f328dc60 | 6020 | if (!json_lsa) |
6021 | vty_out(vty, " %pFX", &p); | |
6022 | else { | |
6023 | prefix2str(&p, buf, sizeof(buf)); | |
6024 | json_object_string_add(json_lsa, | |
6025 | "summaryAddress", | |
6026 | buf); | |
6027 | } | |
d62a17ae | 6028 | break; |
6029 | case OSPF_AS_EXTERNAL_LSA: | |
6030 | case OSPF_AS_NSSA_LSA: | |
6031 | asel = (struct as_external_lsa *)lsa->data; | |
6032 | ||
6033 | p.family = AF_INET; | |
6034 | p.prefix = asel->header.id; | |
6035 | p.prefixlen = ip_masklen(asel->mask); | |
6036 | apply_mask_ipv4(&p); | |
6037 | ||
f328dc60 | 6038 | if (!json_lsa) |
6039 | vty_out(vty, " %s %pFX [0x%lx]", | |
6040 | IS_EXTERNAL_METRIC( | |
6041 | asel->e[0].tos) | |
6042 | ? "E2" | |
6043 | : "E1", | |
6044 | &p, | |
6045 | (unsigned long)ntohl( | |
6046 | asel->e[0].route_tag)); | |
6047 | else { | |
6048 | prefix2str(&p, buf, sizeof(buf)); | |
6049 | json_object_string_add( | |
6050 | json_lsa, "metricType", | |
6051 | IS_EXTERNAL_METRIC( | |
6052 | asel->e[0].tos) | |
6053 | ? "E2" | |
6054 | : "E1"); | |
6055 | json_object_string_add(json_lsa, | |
6056 | "route", buf); | |
6057 | json_object_int_add( | |
6058 | json_lsa, "tag", | |
6059 | (unsigned long)ntohl( | |
6060 | asel->e[0].route_tag)); | |
6061 | } | |
d62a17ae | 6062 | break; |
6063 | case OSPF_NETWORK_LSA: | |
6064 | case OSPF_ASBR_SUMMARY_LSA: | |
6065 | case OSPF_OPAQUE_LINK_LSA: | |
6066 | case OSPF_OPAQUE_AREA_LSA: | |
6067 | case OSPF_OPAQUE_AS_LSA: | |
6068 | default: | |
6069 | break; | |
6070 | } | |
f328dc60 | 6071 | |
6072 | if (!json_lsa) | |
6073 | vty_out(vty, "\n"); | |
d62a17ae | 6074 | } |
718e3744 | 6075 | |
d62a17ae | 6076 | return 0; |
6077 | } | |
6078 | ||
2b64873d | 6079 | static const char *const show_database_desc[] = { |
d62a17ae | 6080 | "unknown", |
6081 | "Router Link States", | |
6082 | "Net Link States", | |
6083 | "Summary Link States", | |
6084 | "ASBR-Summary Link States", | |
6085 | "AS External Link States", | |
6086 | "Group Membership LSA", | |
6087 | "NSSA-external Link States", | |
6088 | "Type-8 LSA", | |
6089 | "Link-Local Opaque-LSA", | |
6090 | "Area-Local Opaque-LSA", | |
6091 | "AS-external Opaque-LSA", | |
718e3744 | 6092 | }; |
6093 | ||
f328dc60 | 6094 | static const char * const show_database_desc_json[] = { |
6095 | "unknown", | |
6096 | "routerLinkStates", | |
6097 | "networkLinkStates", | |
6098 | "summaryLinkStates", | |
6099 | "asbrSummaryLinkStates", | |
6100 | "asExternalLinkStates", | |
6101 | "groupMembershipLsa", | |
6102 | "nssaExternalLinkStates", | |
6103 | "type8Lsa", | |
6104 | "linkLocalOpaqueLsa", | |
6105 | "areaLocalOpaqueLsa", | |
6106 | "asExternalOpaqueLsa", | |
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 | { |
ce513ac6 | 6127 | char buf[PREFIX_STRLEN]; |
d62a17ae | 6128 | struct router_lsa *rlsa = (struct router_lsa *)lsa->data; |
6129 | ||
f328dc60 | 6130 | if (!json) { |
6131 | vty_out(vty, " LS age: %d\n", LS_AGE(lsa)); | |
6132 | vty_out(vty, " Options: 0x%-2x : %s\n", lsa->data->options, | |
6133 | ospf_options_dump(lsa->data->options)); | |
6134 | vty_out(vty, " LS Flags: 0x%-2x %s\n", lsa->flags, | |
6135 | ((lsa->flags & OSPF_LSA_LOCAL_XLT) | |
6136 | ? "(Translated from Type-7)" | |
6137 | : "")); | |
6138 | ||
6139 | if (lsa->data->type == OSPF_ROUTER_LSA) { | |
6140 | vty_out(vty, " Flags: 0x%x", rlsa->flags); | |
6141 | ||
6142 | if (rlsa->flags) | |
6143 | vty_out(vty, " :%s%s%s%s", | |
6144 | IS_ROUTER_LSA_BORDER(rlsa) ? " ABR" | |
6145 | : "", | |
6146 | IS_ROUTER_LSA_EXTERNAL(rlsa) ? " ASBR" | |
6147 | : "", | |
6148 | IS_ROUTER_LSA_VIRTUAL(rlsa) | |
6149 | ? " VL-endpoint" | |
6150 | : "", | |
6151 | IS_ROUTER_LSA_SHORTCUT(rlsa) | |
6152 | ? " Shortcut" | |
6153 | : ""); | |
d62a17ae | 6154 | |
f328dc60 | 6155 | vty_out(vty, "\n"); |
6156 | } | |
6157 | vty_out(vty, " LS Type: %s\n", | |
6158 | lookup_msg(ospf_lsa_type_msg, lsa->data->type, NULL)); | |
6159 | vty_out(vty, " Link State ID: %pI4 %s\n", | |
6160 | &lsa->data->id, | |
6161 | lookup_msg(ospf_link_state_id_type_msg, lsa->data->type, | |
6162 | NULL)); | |
6163 | vty_out(vty, " Advertising Router: %pI4\n", | |
6164 | &lsa->data->adv_router); | |
6165 | vty_out(vty, " LS Seq Number: %08lx\n", | |
6166 | (unsigned long)ntohl(lsa->data->ls_seqnum)); | |
6167 | vty_out(vty, " Checksum: 0x%04x\n", | |
6168 | ntohs(lsa->data->checksum)); | |
6169 | vty_out(vty, " Length: %d\n\n", ntohs(lsa->data->length)); | |
6170 | } else { | |
6171 | char seqnum[10]; | |
6172 | char checksum[10]; | |
6173 | ||
6174 | snprintf(seqnum, 10, "%x", ntohl(lsa->data->ls_seqnum)); | |
6175 | snprintf(checksum, 10, "%x", ntohs(lsa->data->checksum)); | |
6176 | ||
6177 | json_object_int_add(json, "lsaAge", LS_AGE(lsa)); | |
6178 | json_object_string_add(json, "options", | |
6179 | ospf_options_dump(lsa->data->options)); | |
6180 | json_object_int_add(json, "lsaFlags", lsa->flags); | |
6181 | ||
6182 | if (lsa->flags & OSPF_LSA_LOCAL_XLT) | |
6183 | json_object_boolean_true_add(json, | |
6184 | "translatedFromType7"); | |
6185 | ||
6186 | if (lsa->data->type == OSPF_ROUTER_LSA) { | |
6187 | json_object_int_add(json, "flags", rlsa->flags); | |
6188 | ||
6189 | if (rlsa->flags) { | |
6190 | if (IS_ROUTER_LSA_BORDER(rlsa)) | |
6191 | json_object_boolean_true_add(json, | |
6192 | "abr"); | |
6193 | if (IS_ROUTER_LSA_EXTERNAL(rlsa)) | |
6194 | json_object_boolean_true_add(json, | |
6195 | "asbr"); | |
6196 | if (IS_ROUTER_LSA_VIRTUAL(rlsa)) | |
6197 | json_object_boolean_true_add( | |
6198 | json, "vlEndpoint"); | |
6199 | if (IS_ROUTER_LSA_SHORTCUT(rlsa)) | |
6200 | json_object_boolean_true_add( | |
6201 | json, "shortcut"); | |
6202 | } | |
6203 | } | |
6204 | ||
6205 | json_object_string_add( | |
6206 | json, "lsaType", | |
6207 | lookup_msg(ospf_lsa_type_msg, lsa->data->type, NULL)); | |
6208 | json_object_string_add(json, "linkStateId", | |
ce513ac6 MS |
6209 | inet_ntop(AF_INET, &lsa->data->id, |
6210 | buf, sizeof(buf))); | |
f328dc60 | 6211 | json_object_string_add(json, "advertisingRouter", |
ce513ac6 MS |
6212 | inet_ntop(AF_INET, |
6213 | &lsa->data->adv_router, | |
6214 | buf, sizeof(buf))); | |
f328dc60 | 6215 | json_object_string_add(json, "lsaSeqNumber", seqnum); |
6216 | json_object_string_add(json, "checksum", checksum); | |
6217 | json_object_int_add(json, "length", ntohs(lsa->data->length)); | |
d62a17ae | 6218 | } |
d62a17ae | 6219 | } |
6220 | ||
2b64873d | 6221 | static const char *const link_type_desc[] = { |
d62a17ae | 6222 | "(null)", |
6223 | "another Router (point-to-point)", | |
6224 | "a Transit Network", | |
6225 | "Stub Network", | |
6226 | "a Virtual Link", | |
718e3744 | 6227 | }; |
6228 | ||
2b64873d | 6229 | static const char *const link_id_desc[] = { |
d62a17ae | 6230 | "(null)", "Neighboring Router ID", "Designated Router address", |
6231 | "Net", "Neighboring Router ID", | |
718e3744 | 6232 | }; |
6233 | ||
2b64873d | 6234 | static const char *const link_data_desc[] = { |
d62a17ae | 6235 | "(null)", "Router Interface address", "Router Interface address", |
6236 | "Network Mask", "Router Interface address", | |
718e3744 | 6237 | }; |
6238 | ||
f328dc60 | 6239 | static const char *const link_id_desc_json[] = { |
6240 | "null", "neighborRouterId", "designatedRouterAddress", | |
6241 | "networkAddress", "neighborRouterId", | |
6242 | }; | |
6243 | ||
6244 | static const char *const link_data_desc_json[] = { | |
6245 | "null", "routerInterfaceAddress", "routerInterfaceAddress", | |
6246 | "networkMask", "routerInterfaceAddress", | |
6247 | }; | |
6248 | ||
718e3744 | 6249 | /* Show router-LSA each Link information. */ |
d62a17ae | 6250 | static void show_ip_ospf_database_router_links(struct vty *vty, |
f328dc60 | 6251 | struct router_lsa *rl, |
6252 | json_object *json) | |
d62a17ae | 6253 | { |
6254 | int len, type; | |
f328dc60 | 6255 | unsigned short i; |
6256 | json_object *json_links = NULL; | |
6257 | json_object *json_link = NULL; | |
6258 | int metric = 0; | |
ce513ac6 | 6259 | char buf[PREFIX_STRLEN]; |
f328dc60 | 6260 | |
6261 | if (json) | |
6262 | json_links = json_object_new_object(); | |
d62a17ae | 6263 | |
6264 | len = ntohs(rl->header.length) - 4; | |
6265 | for (i = 0; i < ntohs(rl->links) && len > 0; len -= 12, i++) { | |
6266 | type = rl->link[i].type; | |
6267 | ||
f328dc60 | 6268 | if (json) { |
6269 | char link[16]; | |
6270 | ||
6271 | snprintf(link, sizeof(link), "link%u", i); | |
6272 | json_link = json_object_new_object(); | |
6273 | json_object_string_add(json_link, "linkType", | |
6274 | link_type_desc[type]); | |
6275 | json_object_string_add(json_link, | |
6276 | link_id_desc_json[type], | |
ce513ac6 MS |
6277 | inet_ntop(AF_INET, |
6278 | &rl->link[i].link_id, | |
6279 | buf, sizeof(buf))); | |
f328dc60 | 6280 | json_object_string_add( |
6281 | json_link, link_data_desc_json[type], | |
ce513ac6 MS |
6282 | inet_ntop(AF_INET, &rl->link[i].link_data, |
6283 | buf, sizeof(buf))); | |
f328dc60 | 6284 | json_object_int_add(json_link, "numOfTosMetrics", |
6285 | metric); | |
6286 | json_object_int_add(json_link, "tos0Metric", | |
6287 | ntohs(rl->link[i].metric)); | |
6288 | json_object_object_add(json_links, link, json_link); | |
6289 | } else { | |
6290 | vty_out(vty, " Link connected to: %s\n", | |
6291 | link_type_desc[type]); | |
6292 | vty_out(vty, " (Link ID) %s: %pI4\n", | |
6293 | link_id_desc[type], | |
6294 | &rl->link[i].link_id); | |
6295 | vty_out(vty, " (Link Data) %s: %pI4\n", | |
6296 | link_data_desc[type], | |
6297 | &rl->link[i].link_data); | |
6298 | vty_out(vty, " Number of TOS metrics: 0\n"); | |
6299 | vty_out(vty, " TOS 0 Metric: %d\n", | |
6300 | ntohs(rl->link[i].metric)); | |
6301 | vty_out(vty, "\n"); | |
6302 | } | |
d62a17ae | 6303 | } |
f328dc60 | 6304 | if (json) |
6305 | json_object_object_add(json, "routerLinks", json_links); | |
718e3744 | 6306 | } |
6307 | ||
6308 | /* Show router-LSA detail information. */ | |
f328dc60 | 6309 | static int show_router_lsa_detail(struct vty *vty, struct ospf_lsa *lsa, |
6310 | json_object *json) | |
718e3744 | 6311 | { |
d62a17ae | 6312 | if (lsa != NULL) { |
6313 | struct router_lsa *rl = (struct router_lsa *)lsa->data; | |
718e3744 | 6314 | |
f328dc60 | 6315 | show_ip_ospf_database_header(vty, lsa, json); |
718e3744 | 6316 | |
f328dc60 | 6317 | if (!json) |
6318 | vty_out(vty, " Number of Links: %d\n\n", | |
6319 | ntohs(rl->links)); | |
6320 | else | |
6321 | json_object_int_add(json, "numOfLinks", | |
6322 | ntohs(rl->links)); | |
718e3744 | 6323 | |
f328dc60 | 6324 | show_ip_ospf_database_router_links(vty, rl, json); |
6325 | ||
6326 | if (!json) | |
6327 | vty_out(vty, "\n"); | |
d62a17ae | 6328 | } |
6329 | ||
6330 | return 0; | |
718e3744 | 6331 | } |
6332 | ||
6333 | /* Show network-LSA detail information. */ | |
f328dc60 | 6334 | static int show_network_lsa_detail(struct vty *vty, struct ospf_lsa *lsa, |
6335 | json_object *json) | |
718e3744 | 6336 | { |
d62a17ae | 6337 | int length, i; |
ce513ac6 | 6338 | char buf[PREFIX_STRLEN]; |
f328dc60 | 6339 | json_object *json_attached_rt = NULL; |
6340 | json_object *json_router = NULL; | |
6341 | ||
6342 | if (json) | |
6343 | json_attached_rt = json_object_new_object(); | |
718e3744 | 6344 | |
d62a17ae | 6345 | if (lsa != NULL) { |
6346 | struct network_lsa *nl = (struct network_lsa *)lsa->data; | |
8db278b5 | 6347 | struct in_addr *addr; |
718e3744 | 6348 | |
f328dc60 | 6349 | show_ip_ospf_database_header(vty, lsa, json); |
718e3744 | 6350 | |
f328dc60 | 6351 | if (!json) |
6352 | vty_out(vty, " Network Mask: /%d\n", | |
6353 | ip_masklen(nl->mask)); | |
6354 | else | |
6355 | json_object_int_add(json, "networkMask", | |
6356 | ip_masklen(nl->mask)); | |
718e3744 | 6357 | |
8db278b5 OD |
6358 | length = lsa->size - OSPF_LSA_HEADER_SIZE - 4; |
6359 | addr = &nl->routers[0]; | |
6360 | for (i = 0; length > 0 && addr; | |
6361 | length -= 4, addr = &nl->routers[++i]) | |
f328dc60 | 6362 | if (!json) { |
6363 | vty_out(vty, " Attached Router: %pI4\n", | |
8db278b5 | 6364 | addr); |
f328dc60 | 6365 | vty_out(vty, "\n"); |
6366 | } else { | |
6367 | json_router = json_object_new_object(); | |
6368 | json_object_string_add( | |
6369 | json_router, "attachedRouterId", | |
8db278b5 OD |
6370 | inet_ntop(AF_INET, addr, buf, |
6371 | sizeof(buf))); | |
6372 | json_object_object_add(json_attached_rt, | |
6373 | inet_ntop(AF_INET, addr, | |
6374 | buf, | |
6375 | sizeof(buf)), | |
6376 | json_router); | |
f328dc60 | 6377 | } |
d62a17ae | 6378 | } |
718e3744 | 6379 | |
f328dc60 | 6380 | if (json) |
6381 | json_object_object_add(json, "attchedRouters", | |
6382 | json_attached_rt); | |
6383 | ||
d62a17ae | 6384 | return 0; |
718e3744 | 6385 | } |
6386 | ||
6387 | /* Show summary-LSA detail information. */ | |
f328dc60 | 6388 | static int show_summary_lsa_detail(struct vty *vty, struct ospf_lsa *lsa, |
6389 | json_object *json) | |
718e3744 | 6390 | { |
d62a17ae | 6391 | if (lsa != NULL) { |
6392 | struct summary_lsa *sl = (struct summary_lsa *)lsa->data; | |
718e3744 | 6393 | |
f328dc60 | 6394 | show_ip_ospf_database_header(vty, lsa, json); |
718e3744 | 6395 | |
f328dc60 | 6396 | if (!json) { |
6397 | vty_out(vty, " Network Mask: /%d\n", | |
6398 | ip_masklen(sl->mask)); | |
6399 | vty_out(vty, " TOS: 0 Metric: %d\n", | |
6400 | GET_METRIC(sl->metric)); | |
6401 | vty_out(vty, "\n"); | |
6402 | } else { | |
6403 | json_object_int_add(json, "networkMask", | |
6404 | ip_masklen(sl->mask)); | |
6405 | json_object_int_add(json, "tos0Metric", | |
6406 | GET_METRIC(sl->metric)); | |
6407 | } | |
d62a17ae | 6408 | } |
718e3744 | 6409 | |
d62a17ae | 6410 | return 0; |
718e3744 | 6411 | } |
6412 | ||
6413 | /* Show summary-ASBR-LSA detail information. */ | |
f328dc60 | 6414 | static int show_summary_asbr_lsa_detail(struct vty *vty, struct ospf_lsa *lsa, |
6415 | json_object *json) | |
718e3744 | 6416 | { |
d62a17ae | 6417 | if (lsa != NULL) { |
6418 | struct summary_lsa *sl = (struct summary_lsa *)lsa->data; | |
718e3744 | 6419 | |
f328dc60 | 6420 | show_ip_ospf_database_header(vty, lsa, json); |
718e3744 | 6421 | |
f328dc60 | 6422 | if (!json) { |
6423 | vty_out(vty, " Network Mask: /%d\n", | |
6424 | ip_masklen(sl->mask)); | |
6425 | vty_out(vty, " TOS: 0 Metric: %d\n", | |
6426 | GET_METRIC(sl->metric)); | |
6427 | vty_out(vty, "\n"); | |
6428 | } else { | |
6429 | json_object_int_add(json, "networkMask", | |
6430 | ip_masklen(sl->mask)); | |
6431 | json_object_int_add(json, "tos0Metric", | |
6432 | GET_METRIC(sl->metric)); | |
6433 | } | |
d62a17ae | 6434 | } |
718e3744 | 6435 | |
d62a17ae | 6436 | return 0; |
718e3744 | 6437 | } |
6438 | ||
6439 | /* Show AS-external-LSA detail information. */ | |
f328dc60 | 6440 | static int show_as_external_lsa_detail(struct vty *vty, struct ospf_lsa *lsa, |
6441 | json_object *json) | |
d62a17ae | 6442 | { |
ce513ac6 | 6443 | char buf[PREFIX_STRLEN]; |
f328dc60 | 6444 | int tos = 0; |
6445 | ||
d62a17ae | 6446 | if (lsa != NULL) { |
6447 | struct as_external_lsa *al = | |
6448 | (struct as_external_lsa *)lsa->data; | |
6449 | ||
f328dc60 | 6450 | show_ip_ospf_database_header(vty, lsa, json); |
6451 | ||
6452 | if (!json) { | |
6453 | vty_out(vty, " Network Mask: /%d\n", | |
6454 | ip_masklen(al->mask)); | |
6455 | vty_out(vty, " Metric Type: %s\n", | |
6456 | IS_EXTERNAL_METRIC(al->e[0].tos) | |
6457 | ? "2 (Larger than any link state path)" | |
6458 | : "1"); | |
6459 | vty_out(vty, " TOS: 0\n"); | |
6460 | vty_out(vty, " Metric: %d\n", | |
6461 | GET_METRIC(al->e[0].metric)); | |
6462 | vty_out(vty, " Forward Address: %pI4\n", | |
6463 | &al->e[0].fwd_addr); | |
6464 | vty_out(vty, | |
6465 | " External Route Tag: %" ROUTE_TAG_PRI "\n\n", | |
6466 | (route_tag_t)ntohl(al->e[0].route_tag)); | |
6467 | } else { | |
6468 | json_object_int_add(json, "networkMask", | |
6469 | ip_masklen(al->mask)); | |
6470 | json_object_string_add( | |
6471 | json, "metricType", | |
6472 | IS_EXTERNAL_METRIC(al->e[0].tos) | |
6473 | ? "E2 (Larger than any link state path)" | |
6474 | : "E1"); | |
6475 | json_object_int_add(json, "tos", tos); | |
6476 | json_object_int_add(json, "metric", | |
6477 | GET_METRIC(al->e[0].metric)); | |
6478 | json_object_string_add(json, "forwardAddress", | |
ce513ac6 MS |
6479 | inet_ntop(AF_INET, |
6480 | &(al->e[0].fwd_addr), | |
6481 | buf, sizeof(buf))); | |
f328dc60 | 6482 | json_object_int_add( |
6483 | json, "externalRouteTag", | |
6484 | (route_tag_t)ntohl(al->e[0].route_tag)); | |
6485 | } | |
d62a17ae | 6486 | } |
718e3744 | 6487 | |
d62a17ae | 6488 | return 0; |
718e3744 | 6489 | } |
718e3744 | 6490 | |
718e3744 | 6491 | /* Show AS-NSSA-LSA detail information. */ |
f328dc60 | 6492 | static int show_as_nssa_lsa_detail(struct vty *vty, struct ospf_lsa *lsa, |
6493 | json_object *json) | |
d62a17ae | 6494 | { |
ce513ac6 | 6495 | char buf[PREFIX_STRLEN]; |
f328dc60 | 6496 | int tos = 0; |
6497 | ||
d62a17ae | 6498 | if (lsa != NULL) { |
6499 | struct as_external_lsa *al = | |
6500 | (struct as_external_lsa *)lsa->data; | |
6501 | ||
f328dc60 | 6502 | show_ip_ospf_database_header(vty, lsa, json); |
6503 | ||
6504 | if (!json) { | |
6505 | vty_out(vty, " Network Mask: /%d\n", | |
6506 | ip_masklen(al->mask)); | |
6507 | vty_out(vty, " Metric Type: %s\n", | |
6508 | IS_EXTERNAL_METRIC(al->e[0].tos) | |
6509 | ? "2 (Larger than any link state path)" | |
6510 | : "1"); | |
6511 | vty_out(vty, " TOS: 0\n"); | |
6512 | vty_out(vty, " Metric: %d\n", | |
6513 | GET_METRIC(al->e[0].metric)); | |
6514 | vty_out(vty, " NSSA: Forward Address: %pI4\n", | |
6515 | &al->e[0].fwd_addr); | |
6516 | vty_out(vty, | |
6517 | " External Route Tag: %" ROUTE_TAG_PRI | |
6518 | "\n\n", | |
6519 | (route_tag_t)ntohl(al->e[0].route_tag)); | |
6520 | } else { | |
6521 | json_object_int_add(json, "networkMask", | |
6522 | ip_masklen(al->mask)); | |
6523 | json_object_string_add( | |
6524 | json, "metricType", | |
6525 | IS_EXTERNAL_METRIC(al->e[0].tos) | |
6526 | ? "E2 (Larger than any link state path)" | |
6527 | : "E1"); | |
6528 | json_object_int_add(json, "tos", tos); | |
6529 | json_object_int_add(json, "metric", | |
6530 | GET_METRIC(al->e[0].metric)); | |
6531 | json_object_string_add(json, "nssaForwardAddress", | |
ce513ac6 MS |
6532 | inet_ntop(AF_INET, |
6533 | &al->e[0].fwd_addr, | |
6534 | buf, sizeof(buf))); | |
f328dc60 | 6535 | json_object_int_add( |
6536 | json, "externalRouteTag", | |
6537 | (route_tag_t)ntohl(al->e[0].route_tag)); | |
6538 | } | |
d62a17ae | 6539 | } |
718e3744 | 6540 | |
d62a17ae | 6541 | return 0; |
718e3744 | 6542 | } |
6543 | ||
f328dc60 | 6544 | static int show_func_dummy(struct vty *vty, struct ospf_lsa *lsa, |
6545 | json_object *json) | |
718e3744 | 6546 | { |
d62a17ae | 6547 | return 0; |
718e3744 | 6548 | } |
6549 | ||
f328dc60 | 6550 | static int show_opaque_lsa_detail(struct vty *vty, struct ospf_lsa *lsa, |
6551 | json_object *json) | |
718e3744 | 6552 | { |
d62a17ae | 6553 | if (lsa != NULL) { |
f328dc60 | 6554 | show_ip_ospf_database_header(vty, lsa, json); |
6555 | show_opaque_info_detail(vty, lsa, json); | |
6556 | if (!json) | |
6557 | vty_out(vty, "\n"); | |
d62a17ae | 6558 | } |
6559 | return 0; | |
6560 | } | |
6561 | ||
f328dc60 | 6562 | int (*show_function[])(struct vty *, struct ospf_lsa *, json_object *) = { |
d62a17ae | 6563 | NULL, |
6564 | show_router_lsa_detail, | |
6565 | show_network_lsa_detail, | |
6566 | show_summary_lsa_detail, | |
6567 | show_summary_asbr_lsa_detail, | |
6568 | show_as_external_lsa_detail, | |
6569 | show_func_dummy, | |
6570 | show_as_nssa_lsa_detail, /* almost same as external */ | |
6571 | NULL, /* type-8 */ | |
6572 | show_opaque_lsa_detail, | |
6573 | show_opaque_lsa_detail, | |
6574 | show_opaque_lsa_detail, | |
6575 | }; | |
6576 | ||
6577 | static void show_lsa_prefix_set(struct vty *vty, struct prefix_ls *lp, | |
6578 | struct in_addr *id, struct in_addr *adv_router) | |
6579 | { | |
6580 | memset(lp, 0, sizeof(struct prefix_ls)); | |
6581 | lp->family = 0; | |
6582 | if (id == NULL) | |
6583 | lp->prefixlen = 0; | |
6584 | else if (adv_router == NULL) { | |
12256b84 | 6585 | lp->prefixlen = IPV4_MAX_BITLEN; |
d62a17ae | 6586 | lp->id = *id; |
6587 | } else { | |
6588 | lp->prefixlen = 64; | |
6589 | lp->id = *id; | |
6590 | lp->adv_router = *adv_router; | |
6591 | } | |
718e3744 | 6592 | } |
718e3744 | 6593 | |
d62a17ae | 6594 | static void show_lsa_detail_proc(struct vty *vty, struct route_table *rt, |
f328dc60 | 6595 | struct in_addr *id, struct in_addr *adv_router, |
6596 | json_object *json) | |
d62a17ae | 6597 | { |
6598 | struct prefix_ls lp; | |
6599 | struct route_node *rn, *start; | |
6600 | struct ospf_lsa *lsa; | |
f328dc60 | 6601 | json_object *json_lsa = NULL; |
718e3744 | 6602 | |
d62a17ae | 6603 | show_lsa_prefix_set(vty, &lp, id, adv_router); |
6604 | start = route_node_get(rt, (struct prefix *)&lp); | |
6605 | if (start) { | |
6606 | route_lock_node(start); | |
6607 | for (rn = start; rn; rn = route_next_until(rn, start)) | |
6608 | if ((lsa = rn->info)) { | |
f328dc60 | 6609 | if (json) { |
6610 | json_lsa = json_object_new_object(); | |
6611 | json_object_array_add(json, json_lsa); | |
6612 | } | |
6613 | ||
d62a17ae | 6614 | if (show_function[lsa->data->type] != NULL) |
f328dc60 | 6615 | show_function[lsa->data->type]( |
6616 | vty, lsa, json_lsa); | |
d62a17ae | 6617 | } |
6618 | route_unlock_node(start); | |
6619 | } | |
718e3744 | 6620 | } |
6621 | ||
6622 | /* Show detail LSA information | |
6623 | -- if id is NULL then show all LSAs. */ | |
d62a17ae | 6624 | static void show_lsa_detail(struct vty *vty, struct ospf *ospf, int type, |
f328dc60 | 6625 | struct in_addr *id, struct in_addr *adv_router, |
6626 | json_object *json) | |
d62a17ae | 6627 | { |
6628 | struct listnode *node; | |
6629 | struct ospf_area *area; | |
ce513ac6 | 6630 | char buf[PREFIX_STRLEN]; |
f328dc60 | 6631 | json_object *json_lsa_type = NULL; |
6632 | json_object *json_areas = NULL; | |
6633 | json_object *json_lsa_array = NULL; | |
6634 | ||
6635 | if (json) | |
6636 | json_lsa_type = json_object_new_object(); | |
d62a17ae | 6637 | |
6638 | switch (type) { | |
6639 | case OSPF_AS_EXTERNAL_LSA: | |
6640 | case OSPF_OPAQUE_AS_LSA: | |
f328dc60 | 6641 | if (!json) |
6642 | vty_out(vty, " %s \n\n", | |
6643 | show_database_desc[type]); | |
6644 | else | |
6645 | json_lsa_array = json_object_new_array(); | |
6646 | ||
6647 | show_lsa_detail_proc(vty, AS_LSDB(ospf, type), id, adv_router, | |
6648 | json_lsa_array); | |
6649 | if (json) | |
6650 | json_object_object_add(json, | |
6651 | show_database_desc_json[type], | |
6652 | json_lsa_array); | |
6653 | ||
d62a17ae | 6654 | break; |
6655 | default: | |
f328dc60 | 6656 | if (json) |
6657 | json_areas = json_object_new_object(); | |
6658 | ||
d62a17ae | 6659 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) { |
f328dc60 | 6660 | if (!json) { |
6661 | vty_out(vty, | |
6662 | "\n %s (Area %s)\n\n", | |
6663 | show_database_desc[type], | |
6664 | ospf_area_desc_string(area)); | |
6665 | } else { | |
6666 | json_lsa_array = json_object_new_array(); | |
6667 | json_object_object_add(json_areas, | |
ce513ac6 MS |
6668 | inet_ntop(AF_INET, |
6669 | &area->area_id, | |
6670 | buf, | |
6671 | sizeof(buf)), | |
f328dc60 | 6672 | json_lsa_array); |
6673 | } | |
6674 | ||
d62a17ae | 6675 | show_lsa_detail_proc(vty, AREA_LSDB(area, type), id, |
f328dc60 | 6676 | adv_router, json_lsa_array); |
6677 | } | |
6678 | ||
6679 | if (json) { | |
6680 | json_object_object_add(json_lsa_type, "areas", | |
6681 | json_areas); | |
6682 | json_object_object_add(json, | |
6683 | show_database_desc_json[type], | |
6684 | json_lsa_type); | |
d62a17ae | 6685 | } |
6686 | break; | |
718e3744 | 6687 | } |
6688 | } | |
6689 | ||
d62a17ae | 6690 | static void show_lsa_detail_adv_router_proc(struct vty *vty, |
6691 | struct route_table *rt, | |
f328dc60 | 6692 | struct in_addr *adv_router, |
6693 | json_object *json) | |
d62a17ae | 6694 | { |
ce513ac6 | 6695 | char buf[PREFIX_STRLEN]; |
d62a17ae | 6696 | struct route_node *rn; |
6697 | struct ospf_lsa *lsa; | |
6698 | ||
6699 | for (rn = route_top(rt); rn; rn = route_next(rn)) | |
f328dc60 | 6700 | if ((lsa = rn->info)) { |
6701 | json_object *json_lsa = NULL; | |
6702 | ||
d62a17ae | 6703 | if (IPV4_ADDR_SAME(adv_router, |
6704 | &lsa->data->adv_router)) { | |
6705 | if (CHECK_FLAG(lsa->flags, OSPF_LSA_LOCAL_XLT)) | |
6706 | continue; | |
f328dc60 | 6707 | if (json) |
6708 | json_lsa = json_object_new_object(); | |
6709 | ||
d62a17ae | 6710 | if (show_function[lsa->data->type] != NULL) |
f328dc60 | 6711 | show_function[lsa->data->type]( |
6712 | vty, lsa, json_lsa); | |
6713 | if (json) | |
6714 | json_object_object_add( | |
ce513ac6 MS |
6715 | json, |
6716 | inet_ntop(AF_INET, | |
6717 | &lsa->data->id, | |
6718 | buf, sizeof(buf)), | |
f328dc60 | 6719 | json_lsa); |
d62a17ae | 6720 | } |
f328dc60 | 6721 | } |
d62a17ae | 6722 | } |
6723 | ||
718e3744 | 6724 | /* Show detail LSA information. */ |
d62a17ae | 6725 | static void show_lsa_detail_adv_router(struct vty *vty, struct ospf *ospf, |
f328dc60 | 6726 | int type, struct in_addr *adv_router, |
6727 | json_object *json) | |
d62a17ae | 6728 | { |
6729 | struct listnode *node; | |
6730 | struct ospf_area *area; | |
ce513ac6 | 6731 | char buf[PREFIX_STRLEN]; |
f328dc60 | 6732 | json_object *json_lstype = NULL; |
6733 | json_object *json_area = NULL; | |
6734 | ||
6735 | if (json) | |
6736 | json_lstype = json_object_new_object(); | |
d62a17ae | 6737 | |
6738 | switch (type) { | |
6739 | case OSPF_AS_EXTERNAL_LSA: | |
6740 | case OSPF_OPAQUE_AS_LSA: | |
f328dc60 | 6741 | if (!json) |
6742 | vty_out(vty, " %s \n\n", | |
6743 | show_database_desc[type]); | |
6744 | ||
d62a17ae | 6745 | show_lsa_detail_adv_router_proc(vty, AS_LSDB(ospf, type), |
f328dc60 | 6746 | adv_router, json_lstype); |
d62a17ae | 6747 | break; |
6748 | default: | |
f328dc60 | 6749 | |
d62a17ae | 6750 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) { |
f328dc60 | 6751 | if (json) |
6752 | json_area = json_object_new_object(); | |
6753 | else | |
6754 | vty_out(vty, | |
6755 | "\n %s (Area %s)\n\n", | |
6756 | show_database_desc[type], | |
6757 | ospf_area_desc_string(area)); | |
6758 | show_lsa_detail_adv_router_proc(vty, | |
6759 | AREA_LSDB(area, type), | |
6760 | adv_router, json_area); | |
6761 | ||
6762 | if (json) | |
6763 | json_object_object_add(json_lstype, | |
ce513ac6 MS |
6764 | inet_ntop(AF_INET, |
6765 | &area->area_id, | |
6766 | buf, | |
6767 | sizeof(buf)), | |
f328dc60 | 6768 | json_area); |
d62a17ae | 6769 | } |
6770 | break; | |
6771 | } | |
f328dc60 | 6772 | |
6773 | if (json) | |
6774 | json_object_object_add(json, show_database_desc[type], | |
6775 | json_lstype); | |
d62a17ae | 6776 | } |
6777 | ||
7fd0729f G |
6778 | void show_ip_ospf_database_summary(struct vty *vty, struct ospf *ospf, int self, |
6779 | json_object *json) | |
d62a17ae | 6780 | { |
6781 | struct ospf_lsa *lsa; | |
6782 | struct route_node *rn; | |
6783 | struct ospf_area *area; | |
6784 | struct listnode *node; | |
ce513ac6 | 6785 | char buf[PREFIX_STRLEN]; |
f328dc60 | 6786 | json_object *json_areas = NULL; |
6787 | json_object *json_area = NULL; | |
6788 | json_object *json_lsa = NULL; | |
d62a17ae | 6789 | int type; |
f328dc60 | 6790 | json_object *json_lsa_array = NULL; |
6791 | ||
6792 | if (json) | |
6793 | json_areas = json_object_new_object(); | |
d62a17ae | 6794 | |
6795 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) { | |
f328dc60 | 6796 | if (json) |
6797 | json_area = json_object_new_object(); | |
6798 | ||
d62a17ae | 6799 | for (type = OSPF_MIN_LSA; type < OSPF_MAX_LSA; type++) { |
6800 | switch (type) { | |
6801 | case OSPF_AS_EXTERNAL_LSA: | |
6802 | case OSPF_OPAQUE_AS_LSA: | |
6803 | continue; | |
6804 | default: | |
6805 | break; | |
6806 | } | |
6807 | if (ospf_lsdb_count_self(area->lsdb, type) > 0 | |
6808 | || (!self | |
6809 | && ospf_lsdb_count(area->lsdb, type) > 0)) { | |
d62a17ae | 6810 | |
f328dc60 | 6811 | if (!json) { |
6812 | vty_out(vty, | |
6813 | " %s (Area %s)\n\n", | |
6814 | show_database_desc[type], | |
6815 | ospf_area_desc_string(area)); | |
6816 | vty_out(vty, "%s\n", | |
6817 | show_database_header[type]); | |
6818 | } else { | |
6819 | json_lsa_array = | |
6820 | json_object_new_array(); | |
6821 | json_object_object_add( | |
6822 | json_area, | |
6823 | show_database_desc_json[type], | |
6824 | json_lsa_array); | |
6825 | } | |
6826 | ||
6827 | LSDB_LOOP (AREA_LSDB(area, type), rn, lsa) { | |
6828 | if (json) { | |
6829 | json_lsa = | |
6830 | json_object_new_object(); | |
6831 | json_object_array_add( | |
6832 | json_lsa_array, | |
6833 | json_lsa); | |
6834 | } | |
d62a17ae | 6835 | |
f328dc60 | 6836 | show_lsa_summary(vty, lsa, self, |
6837 | json_lsa); | |
6838 | } | |
6839 | ||
6840 | if (!json) | |
6841 | vty_out(vty, "\n"); | |
d62a17ae | 6842 | } |
6843 | } | |
f328dc60 | 6844 | if (json) |
6845 | json_object_object_add(json_areas, | |
ce513ac6 MS |
6846 | inet_ntop(AF_INET, |
6847 | &area->area_id, | |
6848 | buf, sizeof(buf)), | |
f328dc60 | 6849 | json_area); |
d62a17ae | 6850 | } |
6851 | ||
f328dc60 | 6852 | if (json) |
6853 | json_object_object_add(json, "areas", json_areas); | |
6854 | ||
d62a17ae | 6855 | for (type = OSPF_MIN_LSA; type < OSPF_MAX_LSA; type++) { |
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 | |
f328dc60 | 6884 | show_lsa_summary(vty, lsa, self, json_lsa); |
6885 | } | |
6886 | ||
6887 | if (!json) | |
6888 | vty_out(vty, "\n"); | |
d62a17ae | 6889 | } |
6890 | } | |
6891 | ||
f328dc60 | 6892 | if (!json) |
6893 | vty_out(vty, "\n"); | |
d62a17ae | 6894 | } |
6895 | ||
f328dc60 | 6896 | static void show_ip_ospf_database_maxage(struct vty *vty, struct ospf *ospf, |
6897 | json_object *json) | |
d62a17ae | 6898 | { |
6899 | struct route_node *rn; | |
ce513ac6 | 6900 | char buf[PREFIX_STRLEN]; |
f328dc60 | 6901 | json_object *json_maxage = NULL; |
d62a17ae | 6902 | |
f328dc60 | 6903 | if (!json) |
6904 | vty_out(vty, "\n MaxAge Link States:\n\n"); | |
6905 | else | |
6906 | json_maxage = json_object_new_object(); | |
d62a17ae | 6907 | |
6908 | for (rn = route_top(ospf->maxage_lsa); rn; rn = route_next(rn)) { | |
6909 | struct ospf_lsa *lsa; | |
f328dc60 | 6910 | json_object *json_lsa = NULL; |
d62a17ae | 6911 | |
6912 | if ((lsa = rn->info) != NULL) { | |
f328dc60 | 6913 | if (!json) { |
6914 | vty_out(vty, "Link type: %d\n", | |
6915 | lsa->data->type); | |
ce513ac6 MS |
6916 | vty_out(vty, "Link State ID: %pI4\n", |
6917 | &lsa->data->id); | |
f328dc60 | 6918 | vty_out(vty, "Advertising Router: %pI4\n", |
6919 | &lsa->data->adv_router); | |
6920 | vty_out(vty, "LSA lock count: %d\n", lsa->lock); | |
6921 | vty_out(vty, "\n"); | |
6922 | } else { | |
6923 | json_lsa = json_object_new_object(); | |
6924 | json_object_int_add(json_lsa, "linkType", | |
6925 | lsa->data->type); | |
6926 | json_object_string_add( | |
6927 | json_lsa, "linkStateId", | |
ce513ac6 MS |
6928 | inet_ntop(AF_INET, &lsa->data->id, |
6929 | buf, sizeof(buf))); | |
f328dc60 | 6930 | json_object_string_add( |
6931 | json_lsa, "advertisingRouter", | |
ce513ac6 MS |
6932 | inet_ntop(AF_INET, |
6933 | &lsa->data->adv_router, | |
6934 | buf, sizeof(buf))); | |
f328dc60 | 6935 | json_object_int_add(json_lsa, "lsaLockCount", |
6936 | lsa->lock); | |
ce513ac6 MS |
6937 | json_object_object_add( |
6938 | json_maxage, | |
6939 | inet_ntop(AF_INET, | |
6940 | &lsa->data->id, | |
6941 | buf, sizeof(buf)), | |
6942 | json_lsa); | |
f328dc60 | 6943 | } |
d62a17ae | 6944 | } |
91e6a0e5 | 6945 | } |
f328dc60 | 6946 | if (json) |
6947 | json_object_object_add(json, "maxAgeLinkStates", json_maxage); | |
718e3744 | 6948 | } |
6949 | ||
718e3744 | 6950 | #define OSPF_LSA_TYPE_NSSA_DESC "NSSA external link state\n" |
6951 | #define OSPF_LSA_TYPE_NSSA_CMD_STR "|nssa-external" | |
718e3744 | 6952 | |
718e3744 | 6953 | #define OSPF_LSA_TYPE_OPAQUE_LINK_DESC "Link local Opaque-LSA\n" |
6954 | #define OSPF_LSA_TYPE_OPAQUE_AREA_DESC "Link area Opaque-LSA\n" | |
6955 | #define OSPF_LSA_TYPE_OPAQUE_AS_DESC "Link AS Opaque-LSA\n" | |
6956 | #define OSPF_LSA_TYPE_OPAQUE_CMD_STR "|opaque-link|opaque-area|opaque-as" | |
718e3744 | 6957 | |
d62a17ae | 6958 | #define OSPF_LSA_TYPES_DESC \ |
6959 | "ASBR summary link states\n" \ | |
6960 | "External link states\n" \ | |
6961 | "Network link states\n" \ | |
6962 | "Router link states\n" \ | |
6963 | "Network summary link states\n" OSPF_LSA_TYPE_NSSA_DESC \ | |
6964 | OSPF_LSA_TYPE_OPAQUE_LINK_DESC OSPF_LSA_TYPE_OPAQUE_AREA_DESC \ | |
6965 | OSPF_LSA_TYPE_OPAQUE_AS_DESC | |
6966 | ||
6967 | static int show_ip_ospf_database_common(struct vty *vty, struct ospf *ospf, | |
6968 | int arg_base, int argc, | |
d7c0a89a | 6969 | struct cmd_token **argv, |
f328dc60 | 6970 | uint8_t use_vrf, json_object *json, |
6971 | bool uj) | |
d62a17ae | 6972 | { |
6973 | int idx_type = 4; | |
6974 | int type, ret; | |
6975 | struct in_addr id, adv_router; | |
ce513ac6 | 6976 | char buf[PREFIX_STRLEN]; |
f328dc60 | 6977 | json_object *json_vrf = NULL; |
d62a17ae | 6978 | |
f328dc60 | 6979 | if (uj) { |
6980 | if (use_vrf) | |
6981 | json_vrf = json_object_new_object(); | |
6982 | else | |
6983 | json_vrf = json; | |
6984 | } | |
6985 | ||
6986 | if (ospf->instance) { | |
6987 | if (uj) | |
6988 | json_object_int_add(json_vrf, "ospfInstance", | |
6989 | ospf->instance); | |
6990 | else | |
6991 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
6992 | } | |
d62a17ae | 6993 | |
f328dc60 | 6994 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); |
87bd50e8 | 6995 | |
f328dc60 | 6996 | /* Show Router ID. */ |
6997 | if (uj) { | |
6998 | json_object_string_add(json_vrf, "routerId", | |
ce513ac6 MS |
6999 | inet_ntop(AF_INET, &ospf->router_id, |
7000 | buf, sizeof(buf))); | |
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) | |
7136 | vty_out(vty, "%% OSPF instance not found\n"); | |
b5a8894d CS |
7137 | } else { |
7138 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
9f049418 | 7139 | if (ospf == NULL || !ospf->oi_running) { |
94d4c685 | 7140 | vty_out(vty, "%% OSPF instance not found\n"); |
b5a8894d | 7141 | return CMD_SUCCESS; |
9f049418 | 7142 | } |
996c9314 | 7143 | ret = (show_ip_ospf_database_common( |
f328dc60 | 7144 | vty, ospf, idx_vrf ? 2 : 0, argc, argv, use_vrf, |
7145 | json, uj)); | |
b5a8894d CS |
7146 | } |
7147 | } else { | |
7148 | /* Display default ospf (instance 0) info */ | |
7149 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
9f049418 | 7150 | if (ospf == NULL || !ospf->oi_running) { |
94d4c685 | 7151 | vty_out(vty, "%% OSPF instance not found\n"); |
b5a8894d | 7152 | return CMD_SUCCESS; |
9f049418 DS |
7153 | } |
7154 | ||
b1c3ae8c | 7155 | ret = show_ip_ospf_database_common(vty, ospf, 0, argc, argv, |
f328dc60 | 7156 | use_vrf, json, uj); |
7157 | } | |
7158 | ||
7159 | if (uj) { | |
7160 | vty_out(vty, "%s\n", json_object_to_json_string(json)); | |
7161 | json_object_free(json); | |
b5a8894d CS |
7162 | } |
7163 | ||
7164 | return ret; | |
7a7be519 | 7165 | } |
f412b39a | 7166 | |
a11bce11 IR |
7167 | ALIAS (show_ip_ospf_database_max, |
7168 | show_ip_ospf_database_cmd, | |
7169 | "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 | 7170 | SHOW_STR |
7171 | IP_STR | |
7172 | "OSPF information\n" | |
b5a8894d | 7173 | VRF_CMD_HELP_STR |
a11bce11 | 7174 | "All VRFs\n" |
7a7be519 | 7175 | "Database summary\n" |
7176 | OSPF_LSA_TYPES_DESC | |
7177 | "Link State ID (as an IP address)\n" | |
7178 | "Self-originated link states\n" | |
7179 | "Advertising Router link states\n" | |
f328dc60 | 7180 | "Advertising Router (as an IP address)\n" |
7181 | JSON_STR) | |
7c8ff89e | 7182 | |
7a7be519 | 7183 | DEFUN (show_ip_ospf_instance_database_max, |
7184 | show_ip_ospf_instance_database_max_cmd, | |
f328dc60 | 7185 | "show ip ospf (1-65535) database <max-age|self-originate> [json]", |
7a7be519 | 7186 | SHOW_STR |
7187 | IP_STR | |
7188 | "OSPF information\n" | |
7189 | "Instance ID\n" | |
7190 | "Database summary\n" | |
7191 | "LSAs in MaxAge list\n" | |
f328dc60 | 7192 | "Self-originated link states\n" |
7193 | JSON_STR) | |
7a7be519 | 7194 | { |
d62a17ae | 7195 | int idx_number = 3; |
7196 | struct ospf *ospf; | |
d7c0a89a | 7197 | unsigned short instance = 0; |
f328dc60 | 7198 | bool uj = use_json(argc, argv); |
7199 | json_object *json = NULL; | |
7200 | ||
7201 | if (uj) | |
7202 | json = json_object_new_object(); | |
d62a17ae | 7203 | |
7204 | instance = strtoul(argv[idx_number]->arg, NULL, 10); | |
409f98ab | 7205 | if (instance != ospf_instance) |
ac28e4ec CS |
7206 | return CMD_NOT_MY_INSTANCE; |
7207 | ||
409f98ab IR |
7208 | ospf = ospf_lookup_instance(instance); |
7209 | if (!ospf || !ospf->oi_running) | |
d62a17ae | 7210 | return CMD_SUCCESS; |
7211 | ||
f328dc60 | 7212 | show_ip_ospf_database_common(vty, ospf, 1, argc, argv, 0, json, uj); |
7213 | ||
7214 | if (uj) { | |
7215 | vty_out(vty, "%s\n", | |
7216 | json_object_to_json_string_ext( | |
7217 | json, JSON_C_TO_STRING_PRETTY)); | |
7218 | json_object_free(json); | |
7219 | } | |
7220 | ||
7221 | return CMD_SUCCESS; | |
d62a17ae | 7222 | } |
7223 | ||
a11bce11 IR |
7224 | ALIAS (show_ip_ospf_instance_database_max, |
7225 | show_ip_ospf_instance_database_cmd, | |
7226 | "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]", | |
7227 | SHOW_STR | |
7228 | IP_STR | |
7229 | "OSPF information\n" | |
7230 | "Instance ID\n" | |
7231 | "Database summary\n" | |
7232 | OSPF_LSA_TYPES_DESC | |
7233 | "Link State ID (as an IP address)\n" | |
7234 | "Self-originated link states\n" | |
7235 | "Advertising Router link states\n" | |
7236 | "Advertising Router (as an IP address)\n" | |
7237 | JSON_STR) | |
d62a17ae | 7238 | |
7239 | static int show_ip_ospf_database_type_adv_router_common(struct vty *vty, | |
7240 | struct ospf *ospf, | |
7241 | int arg_base, int argc, | |
b1c3ae8c | 7242 | struct cmd_token **argv, |
f328dc60 | 7243 | uint8_t use_vrf, |
7244 | json_object *json, | |
7245 | bool uj) | |
d62a17ae | 7246 | { |
7247 | int idx_type = 4; | |
7248 | int type, ret; | |
7249 | struct in_addr adv_router; | |
ce513ac6 | 7250 | char buf[PREFIX_STRLEN]; |
f328dc60 | 7251 | json_object *json_vrf = NULL; |
d62a17ae | 7252 | |
f328dc60 | 7253 | if (uj) { |
7254 | if (use_vrf) | |
7255 | json_vrf = json_object_new_object(); | |
7256 | else | |
7257 | json_vrf = json; | |
7258 | } | |
d62a17ae | 7259 | |
f328dc60 | 7260 | if (ospf->instance) { |
7261 | if (uj) | |
7262 | json_object_int_add(json, "ospfInstance", | |
7263 | ospf->instance); | |
7264 | else | |
7265 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
7266 | } | |
87bd50e8 | 7267 | |
f328dc60 | 7268 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); |
7269 | ||
7270 | /* Show Router ID. */ | |
7271 | if (uj) { | |
7272 | json_object_string_add(json_vrf, "routerId", | |
ce513ac6 MS |
7273 | inet_ntop(AF_INET, &ospf->router_id, |
7274 | buf, sizeof(buf))); | |
f328dc60 | 7275 | } else { |
7276 | vty_out(vty, "\n OSPF Router with ID (%pI4)\n\n", | |
7277 | &ospf->router_id); | |
7278 | } | |
d62a17ae | 7279 | |
7280 | /* Set database type to show. */ | |
7281 | if (strncmp(argv[arg_base + idx_type]->text, "r", 1) == 0) | |
7282 | type = OSPF_ROUTER_LSA; | |
7283 | else if (strncmp(argv[arg_base + idx_type]->text, "ne", 2) == 0) | |
7284 | type = OSPF_NETWORK_LSA; | |
7285 | else if (strncmp(argv[arg_base + idx_type]->text, "ns", 2) == 0) | |
7286 | type = OSPF_AS_NSSA_LSA; | |
7287 | else if (strncmp(argv[arg_base + idx_type]->text, "s", 1) == 0) | |
7288 | type = OSPF_SUMMARY_LSA; | |
7289 | else if (strncmp(argv[arg_base + idx_type]->text, "a", 1) == 0) | |
7290 | type = OSPF_ASBR_SUMMARY_LSA; | |
7291 | else if (strncmp(argv[arg_base + idx_type]->text, "e", 1) == 0) | |
7292 | type = OSPF_AS_EXTERNAL_LSA; | |
7293 | else if (strncmp(argv[arg_base + idx_type]->text, "opaque-l", 8) == 0) | |
7294 | type = OSPF_OPAQUE_LINK_LSA; | |
7295 | else if (strncmp(argv[arg_base + idx_type]->text, "opaque-ar", 9) == 0) | |
7296 | type = OSPF_OPAQUE_AREA_LSA; | |
7297 | else if (strncmp(argv[arg_base + idx_type]->text, "opaque-as", 9) == 0) | |
7298 | type = OSPF_OPAQUE_AS_LSA; | |
7299 | else | |
7300 | return CMD_WARNING; | |
7c8ff89e | 7301 | |
d62a17ae | 7302 | /* `show ip ospf database LSA adv-router ADV_ROUTER'. */ |
7303 | if (strncmp(argv[arg_base + 5]->text, "s", 1) == 0) | |
7304 | adv_router = ospf->router_id; | |
7305 | else { | |
7306 | ret = inet_aton(argv[arg_base + 6]->arg, &adv_router); | |
7307 | if (!ret) | |
7308 | return CMD_WARNING; | |
7309 | } | |
7c8ff89e | 7310 | |
f328dc60 | 7311 | show_lsa_detail_adv_router(vty, ospf, type, &adv_router, json_vrf); |
7312 | ||
7313 | if (json) { | |
44076f4d RW |
7314 | if (use_vrf) |
7315 | json_object_object_add(json, ospf_get_name(ospf), | |
7316 | json_vrf); | |
f328dc60 | 7317 | } |
7c8ff89e | 7318 | |
d62a17ae | 7319 | return CMD_SUCCESS; |
7c8ff89e DS |
7320 | } |
7321 | ||
a11bce11 IR |
7322 | DEFUN (show_ip_ospf_database_type_adv_router, |
7323 | show_ip_ospf_database_type_adv_router_cmd, | |
7324 | "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 |
7325 | SHOW_STR |
7326 | IP_STR | |
7327 | "OSPF information\n" | |
b5a8894d | 7328 | VRF_CMD_HELP_STR |
a11bce11 | 7329 | "All VRFs\n" |
7c8ff89e DS |
7330 | "Database summary\n" |
7331 | OSPF_LSA_TYPES_DESC | |
7332 | "Advertising Router link states\n" | |
3a2d747c | 7333 | "Advertising Router (as an IP address)\n" |
f328dc60 | 7334 | "Self-originated link states\n" |
7335 | JSON_STR) | |
7c8ff89e | 7336 | { |
b5a8894d | 7337 | struct ospf *ospf = NULL; |
b5a8894d CS |
7338 | struct listnode *node = NULL; |
7339 | char *vrf_name = NULL; | |
2951a7a4 | 7340 | bool all_vrf = false; |
b5a8894d CS |
7341 | int ret = CMD_SUCCESS; |
7342 | int inst = 0; | |
acaeb9fd | 7343 | int idx_vrf = 0; |
d7c0a89a | 7344 | uint8_t use_vrf = 0; |
f328dc60 | 7345 | bool uj = use_json(argc, argv); |
7346 | json_object *json = NULL; | |
7347 | ||
7348 | if (uj) | |
7349 | json = json_object_new_object(); | |
7c8ff89e | 7350 | |
43b8d1d8 CS |
7351 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
7352 | ||
b5a8894d | 7353 | if (vrf_name) { |
2951a7a4 | 7354 | bool ospf_output = false; |
874f58d8 | 7355 | |
b1c3ae8c | 7356 | use_vrf = 1; |
94d4c685 | 7357 | |
b5a8894d CS |
7358 | if (all_vrf) { |
7359 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
7360 | if (!ospf->oi_running) | |
7361 | continue; | |
2951a7a4 | 7362 | ospf_output = true; |
996c9314 | 7363 | ret = show_ip_ospf_database_type_adv_router_common( |
d68e47e1 LS |
7364 | vty, ospf, 2, argc, argv, use_vrf, json, |
7365 | uj); | |
b5a8894d | 7366 | } |
9f049418 DS |
7367 | if (!ospf_output) |
7368 | vty_out(vty, "%% OSPF instance not found\n"); | |
b5a8894d CS |
7369 | } else { |
7370 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
9f049418 | 7371 | if ((ospf == NULL) || !ospf->oi_running) { |
94d4c685 | 7372 | vty_out(vty, "%% OSPF instance not found\n"); |
b5a8894d | 7373 | return CMD_SUCCESS; |
9f049418 DS |
7374 | } |
7375 | ||
996c9314 | 7376 | ret = show_ip_ospf_database_type_adv_router_common( |
d68e47e1 | 7377 | vty, ospf, 2, argc, argv, use_vrf, json, uj); |
b5a8894d CS |
7378 | } |
7379 | } else { | |
7380 | /* Display default ospf (instance 0) info */ | |
7381 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
9f049418 | 7382 | if (ospf == NULL || !ospf->oi_running) { |
94d4c685 | 7383 | vty_out(vty, "%% OSPF instance not found\n"); |
b5a8894d | 7384 | return CMD_SUCCESS; |
9f049418 DS |
7385 | } |
7386 | ||
996c9314 | 7387 | ret = show_ip_ospf_database_type_adv_router_common( |
acaeb9fd | 7388 | vty, ospf, 0, argc, argv, use_vrf, json, uj); |
b5a8894d | 7389 | } |
f328dc60 | 7390 | |
7391 | if (uj) { | |
7392 | vty_out(vty, "%s\n", json_object_to_json_string(json)); | |
7393 | json_object_free(json); | |
7394 | } | |
7395 | ||
b5a8894d | 7396 | return ret; |
a11bce11 IR |
7397 | } |
7398 | ||
7399 | DEFUN (show_ip_ospf_instance_database_type_adv_router, | |
7400 | show_ip_ospf_instance_database_type_adv_router_cmd, | |
7401 | "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]", | |
7402 | SHOW_STR | |
7403 | IP_STR | |
7404 | "OSPF information\n" | |
7405 | "Instance ID\n" | |
7406 | "Database summary\n" | |
7407 | OSPF_LSA_TYPES_DESC | |
7408 | "Advertising Router link states\n" | |
7409 | "Advertising Router (as an IP address)\n" | |
7410 | "Self-originated link states\n" | |
7411 | JSON_STR) | |
7412 | { | |
7413 | int idx_number = 3; | |
7414 | struct ospf *ospf; | |
7415 | unsigned short instance = 0; | |
7416 | bool uj = use_json(argc, argv); | |
7417 | json_object *json = NULL; | |
7418 | ||
7419 | if (uj) | |
7420 | json = json_object_new_object(); | |
7421 | ||
7422 | instance = strtoul(argv[idx_number]->arg, NULL, 10); | |
7423 | if (instance != ospf_instance) | |
7424 | return CMD_NOT_MY_INSTANCE; | |
7425 | ||
7426 | ospf = ospf_lookup_instance(instance); | |
7427 | if (!ospf || !ospf->oi_running) | |
7428 | return CMD_SUCCESS; | |
7429 | ||
7430 | show_ip_ospf_database_type_adv_router_common(vty, ospf, 1, argc, argv, | |
7431 | 0, json, uj); | |
7432 | ||
7433 | if (uj) { | |
7434 | vty_out(vty, "%s\n", | |
7435 | json_object_to_json_string_ext( | |
7436 | json, JSON_C_TO_STRING_PRETTY)); | |
7437 | json_object_free(json); | |
7438 | } | |
7439 | ||
7440 | return CMD_SUCCESS; | |
718e3744 | 7441 | } |
7442 | ||
718e3744 | 7443 | DEFUN (ip_ospf_authentication_args, |
7444 | ip_ospf_authentication_args_addr_cmd, | |
7a7be519 | 7445 | "ip ospf authentication <null|message-digest> [A.B.C.D]", |
718e3744 | 7446 | "IP Information\n" |
7447 | "OSPF interface commands\n" | |
7448 | "Enable authentication on this interface\n" | |
7449 | "Use null authentication\n" | |
7450 | "Use message-digest authentication\n" | |
7a7be519 | 7451 | "Address of interface\n") |
718e3744 | 7452 | { |
d62a17ae | 7453 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7454 | int idx_encryption = 3; | |
7455 | int idx_ipv4 = 4; | |
7456 | struct in_addr addr; | |
7457 | int ret; | |
7458 | struct ospf_if_params *params; | |
7459 | ||
7460 | params = IF_DEF_PARAMS(ifp); | |
7461 | ||
7462 | if (argc == 5) { | |
7463 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
7464 | if (!ret) { | |
7465 | vty_out(vty, | |
7466 | "Please specify interface address by A.B.C.D\n"); | |
7467 | return CMD_WARNING_CONFIG_FAILED; | |
7468 | } | |
718e3744 | 7469 | |
d62a17ae | 7470 | params = ospf_get_if_params(ifp, addr); |
7471 | ospf_if_update_params(ifp, addr); | |
7472 | } | |
718e3744 | 7473 | |
d62a17ae | 7474 | /* Handle null authentication */ |
7475 | if (argv[idx_encryption]->arg[0] == 'n') { | |
7476 | SET_IF_PARAM(params, auth_type); | |
7477 | params->auth_type = OSPF_AUTH_NULL; | |
7478 | return CMD_SUCCESS; | |
7479 | } | |
718e3744 | 7480 | |
d62a17ae | 7481 | /* Handle message-digest authentication */ |
7482 | if (argv[idx_encryption]->arg[0] == 'm') { | |
7483 | SET_IF_PARAM(params, auth_type); | |
7484 | params->auth_type = OSPF_AUTH_CRYPTOGRAPHIC; | |
7485 | return CMD_SUCCESS; | |
7486 | } | |
718e3744 | 7487 | |
d62a17ae | 7488 | vty_out(vty, "You shouldn't get here!\n"); |
7489 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 7490 | } |
7491 | ||
718e3744 | 7492 | DEFUN (ip_ospf_authentication, |
7493 | ip_ospf_authentication_addr_cmd, | |
7a7be519 | 7494 | "ip ospf authentication [A.B.C.D]", |
718e3744 | 7495 | "IP Information\n" |
7496 | "OSPF interface commands\n" | |
7497 | "Enable authentication on this interface\n" | |
efd7904e | 7498 | "Address of interface\n") |
718e3744 | 7499 | { |
d62a17ae | 7500 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7501 | int idx_ipv4 = 3; | |
7502 | struct in_addr addr; | |
7503 | int ret; | |
7504 | struct ospf_if_params *params; | |
7505 | ||
7506 | params = IF_DEF_PARAMS(ifp); | |
7507 | ||
7508 | if (argc == 4) { | |
7509 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
7510 | if (!ret) { | |
7511 | vty_out(vty, | |
7512 | "Please specify interface address by A.B.C.D\n"); | |
7513 | return CMD_WARNING_CONFIG_FAILED; | |
7514 | } | |
7515 | ||
7516 | params = ospf_get_if_params(ifp, addr); | |
7517 | ospf_if_update_params(ifp, addr); | |
718e3744 | 7518 | } |
7519 | ||
d62a17ae | 7520 | SET_IF_PARAM(params, auth_type); |
7521 | params->auth_type = OSPF_AUTH_SIMPLE; | |
718e3744 | 7522 | |
d62a17ae | 7523 | return CMD_SUCCESS; |
718e3744 | 7524 | } |
7525 | ||
b4a039bf DS |
7526 | DEFUN (no_ip_ospf_authentication_args, |
7527 | no_ip_ospf_authentication_args_addr_cmd, | |
7a7be519 | 7528 | "no ip ospf authentication <null|message-digest> [A.B.C.D]", |
b4a039bf DS |
7529 | NO_STR |
7530 | "IP Information\n" | |
7531 | "OSPF interface commands\n" | |
7532 | "Enable authentication on this interface\n" | |
7533 | "Use null authentication\n" | |
7534 | "Use message-digest authentication\n" | |
efd7904e | 7535 | "Address of interface\n") |
b4a039bf | 7536 | { |
d62a17ae | 7537 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7538 | int idx_encryption = 4; | |
7539 | int idx_ipv4 = 5; | |
7540 | struct in_addr addr; | |
7541 | int ret; | |
7542 | struct ospf_if_params *params; | |
7543 | struct route_node *rn; | |
7544 | int auth_type; | |
7545 | ||
7546 | params = IF_DEF_PARAMS(ifp); | |
7547 | ||
7548 | if (argc == 6) { | |
7549 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
7550 | if (!ret) { | |
7551 | vty_out(vty, | |
7552 | "Please specify interface address by A.B.C.D\n"); | |
7553 | return CMD_WARNING_CONFIG_FAILED; | |
7554 | } | |
b4a039bf | 7555 | |
d62a17ae | 7556 | params = ospf_lookup_if_params(ifp, addr); |
7557 | if (params == NULL) { | |
7558 | vty_out(vty, "Ip Address specified is unknown\n"); | |
7559 | return CMD_WARNING_CONFIG_FAILED; | |
7560 | } | |
7561 | params->auth_type = OSPF_AUTH_NOTSET; | |
7562 | UNSET_IF_PARAM(params, auth_type); | |
7563 | if (params != IF_DEF_PARAMS(ifp)) { | |
7564 | ospf_free_if_params(ifp, addr); | |
7565 | ospf_if_update_params(ifp, addr); | |
7566 | } | |
7567 | } else { | |
7568 | if (argv[idx_encryption]->arg[0] == 'n') { | |
7569 | auth_type = OSPF_AUTH_NULL; | |
7570 | } else if (argv[idx_encryption]->arg[0] == 'm') { | |
7571 | auth_type = OSPF_AUTH_CRYPTOGRAPHIC; | |
7572 | } else { | |
7573 | vty_out(vty, "Unexpected input encountered\n"); | |
7574 | return CMD_WARNING_CONFIG_FAILED; | |
7575 | } | |
7576 | /* | |
7577 | * Here we have a case where the user has entered | |
7578 | * 'no ip ospf authentication (null | message_digest )' | |
7579 | * we need to find if we have any ip addresses underneath it | |
7580 | * that | |
7581 | * correspond to the associated type. | |
7582 | */ | |
7583 | if (params->auth_type == auth_type) { | |
7584 | params->auth_type = OSPF_AUTH_NOTSET; | |
7585 | UNSET_IF_PARAM(params, auth_type); | |
7586 | } | |
7587 | ||
7588 | for (rn = route_top(IF_OIFS_PARAMS(ifp)); rn; | |
7589 | rn = route_next(rn)) { | |
7590 | if ((params = rn->info)) { | |
7591 | if (params->auth_type == auth_type) { | |
7592 | params->auth_type = OSPF_AUTH_NOTSET; | |
7593 | UNSET_IF_PARAM(params, auth_type); | |
7594 | if (params != IF_DEF_PARAMS(ifp)) { | |
7595 | ospf_free_if_params( | |
7596 | ifp, rn->p.u.prefix4); | |
7597 | ospf_if_update_params( | |
7598 | ifp, rn->p.u.prefix4); | |
7599 | } | |
7600 | } | |
7601 | } | |
b4a039bf | 7602 | } |
b4a039bf | 7603 | } |
b4a039bf | 7604 | |
d62a17ae | 7605 | return CMD_SUCCESS; |
b4a039bf DS |
7606 | } |
7607 | ||
718e3744 | 7608 | DEFUN (no_ip_ospf_authentication, |
7609 | no_ip_ospf_authentication_addr_cmd, | |
7a7be519 | 7610 | "no ip ospf authentication [A.B.C.D]", |
718e3744 | 7611 | NO_STR |
7612 | "IP Information\n" | |
7613 | "OSPF interface commands\n" | |
7614 | "Enable authentication on this interface\n" | |
efd7904e | 7615 | "Address of interface\n") |
718e3744 | 7616 | { |
d62a17ae | 7617 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7618 | int idx_ipv4 = 4; | |
7619 | struct in_addr addr; | |
7620 | int ret; | |
7621 | struct ospf_if_params *params; | |
7622 | struct route_node *rn; | |
7623 | ||
7624 | params = IF_DEF_PARAMS(ifp); | |
7625 | ||
7626 | if (argc == 5) { | |
7627 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
7628 | if (!ret) { | |
7629 | vty_out(vty, | |
7630 | "Please specify interface address by A.B.C.D\n"); | |
7631 | return CMD_WARNING_CONFIG_FAILED; | |
7632 | } | |
718e3744 | 7633 | |
d62a17ae | 7634 | params = ospf_lookup_if_params(ifp, addr); |
7635 | if (params == NULL) { | |
7636 | vty_out(vty, "Ip Address specified is unknown\n"); | |
7637 | return CMD_WARNING_CONFIG_FAILED; | |
7638 | } | |
718e3744 | 7639 | |
d62a17ae | 7640 | params->auth_type = OSPF_AUTH_NOTSET; |
7641 | UNSET_IF_PARAM(params, auth_type); | |
7642 | if (params != IF_DEF_PARAMS(ifp)) { | |
7643 | ospf_free_if_params(ifp, addr); | |
7644 | ospf_if_update_params(ifp, addr); | |
7645 | } | |
7646 | } else { | |
7647 | /* | |
7648 | * When a user enters 'no ip ospf authentication' | |
7649 | * We should remove all authentication types from | |
7650 | * the interface. | |
7651 | */ | |
7652 | if ((params->auth_type == OSPF_AUTH_NULL) | |
7653 | || (params->auth_type == OSPF_AUTH_CRYPTOGRAPHIC) | |
7654 | || (params->auth_type == OSPF_AUTH_SIMPLE)) { | |
7655 | params->auth_type = OSPF_AUTH_NOTSET; | |
7656 | UNSET_IF_PARAM(params, auth_type); | |
7657 | } | |
813d4307 | 7658 | |
d62a17ae | 7659 | for (rn = route_top(IF_OIFS_PARAMS(ifp)); rn; |
7660 | rn = route_next(rn)) { | |
7661 | if ((params = rn->info)) { | |
7662 | ||
7663 | if ((params->auth_type == OSPF_AUTH_NULL) | |
7664 | || (params->auth_type | |
7665 | == OSPF_AUTH_CRYPTOGRAPHIC) | |
7666 | || (params->auth_type | |
7667 | == OSPF_AUTH_SIMPLE)) { | |
7668 | params->auth_type = OSPF_AUTH_NOTSET; | |
7669 | UNSET_IF_PARAM(params, auth_type); | |
7670 | if (params != IF_DEF_PARAMS(ifp)) { | |
7671 | ospf_free_if_params( | |
7672 | ifp, rn->p.u.prefix4); | |
7673 | ospf_if_update_params( | |
7674 | ifp, rn->p.u.prefix4); | |
7675 | } | |
7676 | } | |
7677 | } | |
b4a039bf | 7678 | } |
b4a039bf | 7679 | } |
d62a17ae | 7680 | |
7681 | return CMD_SUCCESS; | |
718e3744 | 7682 | } |
7683 | ||
0d829fa7 | 7684 | |
718e3744 | 7685 | DEFUN (ip_ospf_authentication_key, |
7686 | ip_ospf_authentication_key_addr_cmd, | |
7a7be519 | 7687 | "ip ospf authentication-key AUTH_KEY [A.B.C.D]", |
718e3744 | 7688 | "IP Information\n" |
7689 | "OSPF interface commands\n" | |
7690 | "Authentication password (key)\n" | |
7691 | "The OSPF password (key)\n" | |
efd7904e | 7692 | "Address of interface\n") |
718e3744 | 7693 | { |
d62a17ae | 7694 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7695 | int idx = 0; | |
7696 | struct in_addr addr; | |
7697 | struct ospf_if_params *params; | |
718e3744 | 7698 | |
d62a17ae | 7699 | params = IF_DEF_PARAMS(ifp); |
7700 | ||
7701 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
7702 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
7703 | vty_out(vty, | |
7704 | "Please specify interface address by A.B.C.D\n"); | |
7705 | return CMD_WARNING_CONFIG_FAILED; | |
7706 | } | |
718e3744 | 7707 | |
d62a17ae | 7708 | params = ospf_get_if_params(ifp, addr); |
7709 | ospf_if_update_params(ifp, addr); | |
7710 | } | |
718e3744 | 7711 | |
4d65d927 QY |
7712 | strlcpy((char *)params->auth_simple, argv[3]->arg, |
7713 | sizeof(params->auth_simple)); | |
d62a17ae | 7714 | SET_IF_PARAM(params, auth_simple); |
718e3744 | 7715 | |
d62a17ae | 7716 | return CMD_SUCCESS; |
718e3744 | 7717 | } |
7718 | ||
7a7be519 | 7719 | DEFUN_HIDDEN (ospf_authentication_key, |
747e489c | 7720 | ospf_authentication_key_cmd, |
0d829fa7 | 7721 | "ospf authentication-key AUTH_KEY [A.B.C.D]", |
747e489c | 7722 | "OSPF interface commands\n" |
baf9eaad | 7723 | VLINK_HELPSTR_AUTH_SIMPLE |
0d829fa7 | 7724 | "Address of interface\n") |
718e3744 | 7725 | { |
d62a17ae | 7726 | return ip_ospf_authentication_key(self, vty, argc, argv); |
718e3744 | 7727 | } |
7728 | ||
7a7be519 | 7729 | DEFUN (no_ip_ospf_authentication_key, |
7730 | no_ip_ospf_authentication_key_authkey_addr_cmd, | |
7731 | "no ip ospf authentication-key [AUTH_KEY [A.B.C.D]]", | |
7732 | NO_STR | |
7733 | "IP Information\n" | |
7734 | "OSPF interface commands\n" | |
baf9eaad CS |
7735 | VLINK_HELPSTR_AUTH_SIMPLE |
7736 | "Address of interface\n") | |
7a7be519 | 7737 | { |
d62a17ae | 7738 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7739 | int idx = 0; | |
7740 | struct in_addr addr; | |
7741 | struct ospf_if_params *params; | |
7742 | params = IF_DEF_PARAMS(ifp); | |
7743 | ||
7744 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
7745 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
7746 | vty_out(vty, | |
7747 | "Please specify interface address by A.B.C.D\n"); | |
7748 | return CMD_WARNING_CONFIG_FAILED; | |
7749 | } | |
7a7be519 | 7750 | |
d62a17ae | 7751 | params = ospf_lookup_if_params(ifp, addr); |
7752 | if (params == NULL) | |
7753 | return CMD_SUCCESS; | |
7a7be519 | 7754 | } |
813d4307 | 7755 | |
d62a17ae | 7756 | memset(params->auth_simple, 0, OSPF_AUTH_SIMPLE_SIZE); |
7757 | UNSET_IF_PARAM(params, auth_simple); | |
718e3744 | 7758 | |
d62a17ae | 7759 | if (params != IF_DEF_PARAMS(ifp)) { |
7760 | ospf_free_if_params(ifp, addr); | |
7761 | ospf_if_update_params(ifp, addr); | |
7762 | } | |
813d4307 | 7763 | |
d62a17ae | 7764 | return CMD_SUCCESS; |
7a7be519 | 7765 | } |
813d4307 | 7766 | |
0d829fa7 QY |
7767 | DEFUN_HIDDEN (no_ospf_authentication_key, |
7768 | no_ospf_authentication_key_authkey_addr_cmd, | |
7769 | "no ospf authentication-key [AUTH_KEY [A.B.C.D]]", | |
7770 | NO_STR | |
7771 | "OSPF interface commands\n" | |
baf9eaad CS |
7772 | VLINK_HELPSTR_AUTH_SIMPLE |
7773 | "Address of interface\n") | |
0d829fa7 | 7774 | { |
d62a17ae | 7775 | return no_ip_ospf_authentication_key(self, vty, argc, argv); |
0d829fa7 QY |
7776 | } |
7777 | ||
718e3744 | 7778 | DEFUN (ip_ospf_message_digest_key, |
537eae3f | 7779 | ip_ospf_message_digest_key_cmd, |
7a7be519 | 7780 | "ip ospf message-digest-key (1-255) md5 KEY [A.B.C.D]", |
718e3744 | 7781 | "IP Information\n" |
7782 | "OSPF interface commands\n" | |
7783 | "Message digest authentication password (key)\n" | |
7784 | "Key ID\n" | |
7785 | "Use MD5 algorithm\n" | |
fefa0d82 QY |
7786 | "The OSPF password (key)\n" |
7787 | "Address of interface\n") | |
718e3744 | 7788 | { |
d62a17ae | 7789 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7790 | struct crypt_key *ck; | |
d7c0a89a | 7791 | uint8_t key_id; |
d62a17ae | 7792 | struct in_addr addr; |
7793 | struct ospf_if_params *params; | |
7794 | ||
7795 | params = IF_DEF_PARAMS(ifp); | |
7796 | int idx = 0; | |
7797 | ||
7798 | argv_find(argv, argc, "(1-255)", &idx); | |
7799 | char *keyid = argv[idx]->arg; | |
7800 | argv_find(argv, argc, "KEY", &idx); | |
7801 | char *cryptkey = argv[idx]->arg; | |
7802 | ||
7803 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
7804 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
7805 | vty_out(vty, | |
7806 | "Please specify interface address by A.B.C.D\n"); | |
7807 | return CMD_WARNING_CONFIG_FAILED; | |
7808 | } | |
7809 | ||
7810 | params = ospf_get_if_params(ifp, addr); | |
7811 | ospf_if_update_params(ifp, addr); | |
718e3744 | 7812 | } |
7813 | ||
d62a17ae | 7814 | key_id = strtol(keyid, NULL, 10); |
519b1464 MS |
7815 | |
7816 | /* Remove existing key, if any */ | |
7817 | ospf_crypt_key_delete(params->auth_crypt, key_id); | |
718e3744 | 7818 | |
d62a17ae | 7819 | ck = ospf_crypt_key_new(); |
d7c0a89a | 7820 | ck->key_id = (uint8_t)key_id; |
4d65d927 | 7821 | strlcpy((char *)ck->auth_key, cryptkey, sizeof(ck->auth_key)); |
718e3744 | 7822 | |
d62a17ae | 7823 | ospf_crypt_key_add(params->auth_crypt, ck); |
7824 | SET_IF_PARAM(params, auth_crypt); | |
718e3744 | 7825 | |
d62a17ae | 7826 | return CMD_SUCCESS; |
718e3744 | 7827 | } |
7828 | ||
7a7be519 | 7829 | DEFUN_HIDDEN (ospf_message_digest_key, |
747e489c | 7830 | ospf_message_digest_key_cmd, |
0d829fa7 | 7831 | "ospf message-digest-key (1-255) md5 KEY [A.B.C.D]", |
747e489c DW |
7832 | "OSPF interface commands\n" |
7833 | "Message digest authentication password (key)\n" | |
7834 | "Key ID\n" | |
7835 | "Use MD5 algorithm\n" | |
0d829fa7 QY |
7836 | "The OSPF password (key)\n" |
7837 | "Address of interface\n") | |
7a7be519 | 7838 | { |
d62a17ae | 7839 | return ip_ospf_message_digest_key(self, vty, argc, argv); |
7a7be519 | 7840 | } |
718e3744 | 7841 | |
537eae3f QY |
7842 | DEFUN (no_ip_ospf_message_digest_key, |
7843 | no_ip_ospf_message_digest_key_cmd, | |
0d829fa7 | 7844 | "no ip ospf message-digest-key (1-255) [md5 KEY] [A.B.C.D]", |
813d4307 DW |
7845 | NO_STR |
7846 | "IP Information\n" | |
7847 | "OSPF interface commands\n" | |
7848 | "Message digest authentication password (key)\n" | |
7849 | "Key ID\n" | |
7850 | "Use MD5 algorithm\n" | |
0d829fa7 QY |
7851 | "The OSPF password (key)\n" |
7852 | "Address of interface\n") | |
813d4307 | 7853 | { |
d62a17ae | 7854 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7855 | int idx = 0; | |
7856 | struct crypt_key *ck; | |
7857 | int key_id; | |
7858 | struct in_addr addr; | |
7859 | struct ospf_if_params *params; | |
7860 | params = IF_DEF_PARAMS(ifp); | |
7861 | ||
7862 | argv_find(argv, argc, "(1-255)", &idx); | |
7863 | char *keyid = argv[idx]->arg; | |
7864 | ||
7865 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
7866 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
7867 | vty_out(vty, | |
7868 | "Please specify interface address by A.B.C.D\n"); | |
7869 | return CMD_WARNING_CONFIG_FAILED; | |
7870 | } | |
7a7be519 | 7871 | |
d62a17ae | 7872 | params = ospf_lookup_if_params(ifp, addr); |
7873 | if (params == NULL) | |
7874 | return CMD_SUCCESS; | |
7a7be519 | 7875 | } |
7876 | ||
d62a17ae | 7877 | key_id = strtol(keyid, NULL, 10); |
7878 | ck = ospf_crypt_key_lookup(params->auth_crypt, key_id); | |
7879 | if (ck == NULL) { | |
7880 | vty_out(vty, "OSPF: Key %d does not exist\n", key_id); | |
7881 | return CMD_WARNING_CONFIG_FAILED; | |
7882 | } | |
7a7be519 | 7883 | |
d62a17ae | 7884 | ospf_crypt_key_delete(params->auth_crypt, key_id); |
7a7be519 | 7885 | |
d62a17ae | 7886 | if (params != IF_DEF_PARAMS(ifp)) { |
7887 | ospf_free_if_params(ifp, addr); | |
7888 | ospf_if_update_params(ifp, addr); | |
7889 | } | |
7a7be519 | 7890 | |
d62a17ae | 7891 | return CMD_SUCCESS; |
7a7be519 | 7892 | } |
813d4307 | 7893 | |
0d829fa7 | 7894 | DEFUN_HIDDEN (no_ospf_message_digest_key, |
537eae3f | 7895 | no_ospf_message_digest_key_cmd, |
0d829fa7 QY |
7896 | "no ospf message-digest-key (1-255) [md5 KEY] [A.B.C.D]", |
7897 | NO_STR | |
7898 | "OSPF interface commands\n" | |
7899 | "Message digest authentication password (key)\n" | |
7900 | "Key ID\n" | |
efd7904e RW |
7901 | "Use MD5 algorithm\n" |
7902 | "The OSPF password (key)\n" | |
7903 | "Address of interface\n") | |
718e3744 | 7904 | { |
d62a17ae | 7905 | return no_ip_ospf_message_digest_key(self, vty, argc, argv); |
718e3744 | 7906 | } |
7907 | ||
718e3744 | 7908 | DEFUN (ip_ospf_cost, |
5c2fc921 | 7909 | ip_ospf_cost_cmd, |
7a7be519 | 7910 | "ip ospf cost (1-65535) [A.B.C.D]", |
718e3744 | 7911 | "IP Information\n" |
7912 | "OSPF interface commands\n" | |
7913 | "Interface cost\n" | |
7914 | "Cost\n" | |
5c2fc921 | 7915 | "Address of interface\n") |
718e3744 | 7916 | { |
d62a17ae | 7917 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7918 | int idx = 0; | |
d7c0a89a | 7919 | uint32_t cost = OSPF_OUTPUT_COST_DEFAULT; |
d62a17ae | 7920 | struct in_addr addr; |
7921 | struct ospf_if_params *params; | |
7922 | params = IF_DEF_PARAMS(ifp); | |
7923 | ||
7924 | // get arguments | |
7925 | char *coststr = NULL, *ifaddr = NULL; | |
35955c14 | 7926 | |
c31a793b VJ |
7927 | argv_find(argv, argc, "(1-65535)", &idx); |
7928 | coststr = argv[idx]->arg; | |
d62a17ae | 7929 | cost = strtol(coststr, NULL, 10); |
7930 | ||
c31a793b | 7931 | ifaddr = argv_find(argv, argc, "A.B.C.D", &idx) ? argv[idx]->arg : NULL; |
d62a17ae | 7932 | if (ifaddr) { |
7933 | if (!inet_aton(ifaddr, &addr)) { | |
7934 | vty_out(vty, | |
7935 | "Please specify interface address by A.B.C.D\n"); | |
7936 | return CMD_WARNING_CONFIG_FAILED; | |
7937 | } | |
718e3744 | 7938 | |
d62a17ae | 7939 | params = ospf_get_if_params(ifp, addr); |
7940 | ospf_if_update_params(ifp, addr); | |
718e3744 | 7941 | } |
7942 | ||
d62a17ae | 7943 | SET_IF_PARAM(params, output_cost_cmd); |
7944 | params->output_cost_cmd = cost; | |
718e3744 | 7945 | |
d62a17ae | 7946 | ospf_if_recalculate_output_cost(ifp); |
5c2fc921 | 7947 | |
d62a17ae | 7948 | return CMD_SUCCESS; |
718e3744 | 7949 | } |
7950 | ||
7a7be519 | 7951 | DEFUN_HIDDEN (ospf_cost, |
5c2fc921 QY |
7952 | ospf_cost_cmd, |
7953 | "ospf cost (1-65535) [A.B.C.D]", | |
747e489c DW |
7954 | "OSPF interface commands\n" |
7955 | "Interface cost\n" | |
7956 | "Cost\n" | |
5c2fc921 | 7957 | "Address of interface\n") |
7a7be519 | 7958 | { |
d62a17ae | 7959 | return ip_ospf_cost(self, vty, argc, argv); |
7a7be519 | 7960 | } |
9eff36b3 | 7961 | |
718e3744 | 7962 | DEFUN (no_ip_ospf_cost, |
5c2fc921 QY |
7963 | no_ip_ospf_cost_cmd, |
7964 | "no ip ospf cost [(1-65535)] [A.B.C.D]", | |
718e3744 | 7965 | NO_STR |
efd7904e | 7966 | "IP Information\n" |
718e3744 | 7967 | "OSPF interface commands\n" |
7968 | "Interface cost\n" | |
efd7904e RW |
7969 | "Cost\n" |
7970 | "Address of interface\n") | |
718e3744 | 7971 | { |
d62a17ae | 7972 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7973 | int idx = 0; | |
7974 | struct in_addr addr; | |
7975 | struct ospf_if_params *params; | |
7a7be519 | 7976 | |
d62a17ae | 7977 | params = IF_DEF_PARAMS(ifp); |
718e3744 | 7978 | |
d62a17ae | 7979 | // get arguments |
7980 | char *ifaddr = NULL; | |
7981 | ifaddr = argv_find(argv, argc, "A.B.C.D", &idx) ? argv[idx]->arg : NULL; | |
718e3744 | 7982 | |
d62a17ae | 7983 | /* According to the semantics we are mimicking "no ip ospf cost N" is |
7984 | * always treated as "no ip ospf cost" regardless of the actual value | |
7985 | * of N already configured for the interface. Thus ignore cost. */ | |
7a7be519 | 7986 | |
d62a17ae | 7987 | if (ifaddr) { |
7988 | if (!inet_aton(ifaddr, &addr)) { | |
7989 | vty_out(vty, | |
7990 | "Please specify interface address by A.B.C.D\n"); | |
7991 | return CMD_WARNING_CONFIG_FAILED; | |
7992 | } | |
7a7be519 | 7993 | |
d62a17ae | 7994 | params = ospf_lookup_if_params(ifp, addr); |
7995 | if (params == NULL) | |
7996 | return CMD_SUCCESS; | |
7997 | } | |
7a7be519 | 7998 | |
d62a17ae | 7999 | UNSET_IF_PARAM(params, output_cost_cmd); |
7a7be519 | 8000 | |
d62a17ae | 8001 | if (params != IF_DEF_PARAMS(ifp)) { |
8002 | ospf_free_if_params(ifp, addr); | |
8003 | ospf_if_update_params(ifp, addr); | |
8004 | } | |
7a7be519 | 8005 | |
d62a17ae | 8006 | ospf_if_recalculate_output_cost(ifp); |
7a7be519 | 8007 | |
d62a17ae | 8008 | return CMD_SUCCESS; |
7a7be519 | 8009 | } |
9eff36b3 | 8010 | |
5c2fc921 QY |
8011 | DEFUN_HIDDEN (no_ospf_cost, |
8012 | no_ospf_cost_cmd, | |
8013 | "no ospf cost [(1-65535)] [A.B.C.D]", | |
8014 | NO_STR | |
8015 | "OSPF interface commands\n" | |
8016 | "Interface cost\n" | |
8017 | "Cost\n" | |
8018 | "Address of interface\n") | |
827341b7 | 8019 | { |
d62a17ae | 8020 | return no_ip_ospf_cost(self, vty, argc, argv); |
827341b7 DO |
8021 | } |
8022 | ||
d62a17ae | 8023 | static void ospf_nbr_timer_update(struct ospf_interface *oi) |
718e3744 | 8024 | { |
d62a17ae | 8025 | struct route_node *rn; |
8026 | struct ospf_neighbor *nbr; | |
718e3744 | 8027 | |
d62a17ae | 8028 | for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) |
8029 | if ((nbr = rn->info)) { | |
8030 | nbr->v_inactivity = OSPF_IF_PARAM(oi, v_wait); | |
8031 | nbr->v_db_desc = OSPF_IF_PARAM(oi, retransmit_interval); | |
8032 | nbr->v_ls_req = OSPF_IF_PARAM(oi, retransmit_interval); | |
8033 | nbr->v_ls_upd = OSPF_IF_PARAM(oi, retransmit_interval); | |
8034 | } | |
718e3744 | 8035 | } |
8036 | ||
d62a17ae | 8037 | static int ospf_vty_dead_interval_set(struct vty *vty, const char *interval_str, |
8038 | const char *nbr_str, | |
8039 | const char *fast_hello_str) | |
8040 | { | |
8041 | VTY_DECLVAR_CONTEXT(interface, ifp); | |
d7c0a89a QY |
8042 | uint32_t seconds; |
8043 | uint8_t hellomult; | |
d62a17ae | 8044 | struct in_addr addr; |
8045 | int ret; | |
8046 | struct ospf_if_params *params; | |
8047 | struct ospf_interface *oi; | |
8048 | struct route_node *rn; | |
718e3744 | 8049 | |
d62a17ae | 8050 | params = IF_DEF_PARAMS(ifp); |
8051 | ||
8052 | if (nbr_str) { | |
8053 | ret = inet_aton(nbr_str, &addr); | |
8054 | if (!ret) { | |
8055 | vty_out(vty, | |
8056 | "Please specify interface address by A.B.C.D\n"); | |
8057 | return CMD_WARNING_CONFIG_FAILED; | |
8058 | } | |
8059 | ||
8060 | params = ospf_get_if_params(ifp, addr); | |
8061 | ospf_if_update_params(ifp, addr); | |
8062 | } | |
8063 | ||
8064 | if (interval_str) { | |
8065 | seconds = strtoul(interval_str, NULL, 10); | |
8066 | ||
8067 | /* reset fast_hello too, just to be sure */ | |
8068 | UNSET_IF_PARAM(params, fast_hello); | |
8069 | params->fast_hello = OSPF_FAST_HELLO_DEFAULT; | |
8070 | } else if (fast_hello_str) { | |
8071 | hellomult = strtoul(fast_hello_str, NULL, 10); | |
8072 | /* 1s dead-interval with sub-second hellos desired */ | |
8073 | seconds = OSPF_ROUTER_DEAD_INTERVAL_MINIMAL; | |
8074 | SET_IF_PARAM(params, fast_hello); | |
8075 | params->fast_hello = hellomult; | |
8076 | } else { | |
8077 | vty_out(vty, | |
8078 | "Please specify dead-interval or hello-multiplier\n"); | |
8079 | return CMD_WARNING_CONFIG_FAILED; | |
8080 | } | |
8081 | ||
8082 | SET_IF_PARAM(params, v_wait); | |
8083 | params->v_wait = seconds; | |
182d6bdc | 8084 | params->is_v_wait_set = true; |
d62a17ae | 8085 | |
8086 | /* Update timer values in neighbor structure. */ | |
8087 | if (nbr_str) { | |
b5a8894d CS |
8088 | struct ospf *ospf = NULL; |
8089 | ||
a36898e7 | 8090 | ospf = ospf_lookup_by_vrf_id(ifp->vrf_id); |
b5a8894d | 8091 | if (ospf) { |
d62a17ae | 8092 | oi = ospf_if_lookup_by_local_addr(ospf, ifp, addr); |
8093 | if (oi) | |
8094 | ospf_nbr_timer_update(oi); | |
8095 | } | |
8096 | } else { | |
8097 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) | |
8098 | if ((oi = rn->info)) | |
8099 | ospf_nbr_timer_update(oi); | |
8100 | } | |
8101 | ||
8102 | return CMD_SUCCESS; | |
718e3744 | 8103 | } |
8104 | ||
f9ad937f | 8105 | DEFUN (ip_ospf_dead_interval, |
0d829fa7 | 8106 | ip_ospf_dead_interval_cmd, |
7a7be519 | 8107 | "ip ospf dead-interval (1-65535) [A.B.C.D]", |
f9ad937f | 8108 | "IP Information\n" |
8109 | "OSPF interface commands\n" | |
99a522c7 | 8110 | "Interval time after which a neighbor is declared down\n" |
f9ad937f | 8111 | "Seconds\n" |
8112 | "Address of interface\n") | |
8113 | { | |
d62a17ae | 8114 | int idx = 0; |
8115 | char *interval = argv_find(argv, argc, "(1-65535)", &idx) | |
8116 | ? argv[idx]->arg | |
8117 | : NULL; | |
8118 | char *ifaddr = | |
8119 | argv_find(argv, argc, "A.B.C.D", &idx) ? argv[idx]->arg : NULL; | |
8120 | return ospf_vty_dead_interval_set(vty, interval, ifaddr, NULL); | |
f9ad937f | 8121 | } |
8122 | ||
718e3744 | 8123 | |
7a7be519 | 8124 | DEFUN_HIDDEN (ospf_dead_interval, |
747e489c | 8125 | ospf_dead_interval_cmd, |
0d829fa7 | 8126 | "ospf dead-interval (1-65535) [A.B.C.D]", |
747e489c | 8127 | "OSPF interface commands\n" |
99a522c7 | 8128 | "Interval time after which a neighbor is declared down\n" |
0d829fa7 QY |
8129 | "Seconds\n" |
8130 | "Address of interface\n") | |
7a7be519 | 8131 | { |
d62a17ae | 8132 | return ip_ospf_dead_interval(self, vty, argc, argv); |
7a7be519 | 8133 | } |
718e3744 | 8134 | |
f9ad937f | 8135 | DEFUN (ip_ospf_dead_interval_minimal, |
8136 | ip_ospf_dead_interval_minimal_addr_cmd, | |
7a7be519 | 8137 | "ip ospf dead-interval minimal hello-multiplier (1-10) [A.B.C.D]", |
f9ad937f | 8138 | "IP Information\n" |
8139 | "OSPF interface commands\n" | |
99a522c7 | 8140 | "Interval time after which a neighbor is declared down\n" |
f9ad937f | 8141 | "Minimal 1s dead-interval with fast sub-second hellos\n" |
8142 | "Hello multiplier factor\n" | |
8143 | "Number of Hellos to send each second\n" | |
8144 | "Address of interface\n") | |
8145 | { | |
d62a17ae | 8146 | int idx_number = 5; |
8147 | int idx_ipv4 = 6; | |
8148 | if (argc == 7) | |
8149 | return ospf_vty_dead_interval_set( | |
8150 | vty, NULL, argv[idx_ipv4]->arg, argv[idx_number]->arg); | |
8151 | else | |
8152 | return ospf_vty_dead_interval_set(vty, NULL, NULL, | |
8153 | argv[idx_number]->arg); | |
f9ad937f | 8154 | } |
8155 | ||
718e3744 | 8156 | DEFUN (no_ip_ospf_dead_interval, |
0d829fa7 | 8157 | no_ip_ospf_dead_interval_cmd, |
e83a9414 | 8158 | "no ip ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]", |
718e3744 | 8159 | NO_STR |
8160 | "IP Information\n" | |
8161 | "OSPF interface commands\n" | |
99a522c7 | 8162 | "Interval time after which a neighbor is declared down\n" |
f9dfba8d | 8163 | "Seconds\n" |
efd7904e RW |
8164 | "Minimal 1s dead-interval with fast sub-second hellos\n" |
8165 | "Hello multiplier factor\n" | |
8166 | "Number of Hellos to send each second\n" | |
8167 | "Address of interface\n") | |
718e3744 | 8168 | { |
d62a17ae | 8169 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8170 | int idx_ipv4 = argc - 1; | |
8171 | struct in_addr addr = {.s_addr = 0L}; | |
8172 | int ret; | |
8173 | struct ospf_if_params *params; | |
8174 | struct ospf_interface *oi; | |
8175 | struct route_node *rn; | |
8176 | ||
8177 | params = IF_DEF_PARAMS(ifp); | |
8178 | ||
8179 | if (argv[idx_ipv4]->type == IPV4_TKN) { | |
8180 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
8181 | if (!ret) { | |
8182 | vty_out(vty, | |
8183 | "Please specify interface address by A.B.C.D\n"); | |
8184 | return CMD_WARNING_CONFIG_FAILED; | |
8185 | } | |
020709f9 | 8186 | |
d62a17ae | 8187 | params = ospf_lookup_if_params(ifp, addr); |
8188 | if (params == NULL) | |
8189 | return CMD_SUCCESS; | |
8190 | } | |
718e3744 | 8191 | |
d62a17ae | 8192 | UNSET_IF_PARAM(params, v_wait); |
8193 | params->v_wait = OSPF_ROUTER_DEAD_INTERVAL_DEFAULT; | |
182d6bdc | 8194 | params->is_v_wait_set = false; |
d62a17ae | 8195 | |
8196 | UNSET_IF_PARAM(params, fast_hello); | |
8197 | params->fast_hello = OSPF_FAST_HELLO_DEFAULT; | |
8198 | ||
8199 | if (params != IF_DEF_PARAMS(ifp)) { | |
8200 | ospf_free_if_params(ifp, addr); | |
8201 | ospf_if_update_params(ifp, addr); | |
718e3744 | 8202 | } |
8203 | ||
d62a17ae | 8204 | /* Update timer values in neighbor structure. */ |
8205 | if (argc == 1) { | |
b5a8894d | 8206 | struct ospf *ospf = NULL; |
718e3744 | 8207 | |
a36898e7 | 8208 | ospf = ospf_lookup_by_vrf_id(ifp->vrf_id); |
b5a8894d | 8209 | if (ospf) { |
d62a17ae | 8210 | oi = ospf_if_lookup_by_local_addr(ospf, ifp, addr); |
8211 | if (oi) | |
8212 | ospf_nbr_timer_update(oi); | |
8213 | } | |
8214 | } else { | |
8215 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) | |
8216 | if ((oi = rn->info)) | |
8217 | ospf_nbr_timer_update(oi); | |
8218 | } | |
8219 | ||
8220 | return CMD_SUCCESS; | |
718e3744 | 8221 | } |
8222 | ||
0d829fa7 QY |
8223 | DEFUN_HIDDEN (no_ospf_dead_interval, |
8224 | no_ospf_dead_interval_cmd, | |
8225 | "no ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]", | |
8226 | NO_STR | |
8227 | "OSPF interface commands\n" | |
99a522c7 | 8228 | "Interval time after which a neighbor is declared down\n" |
0d829fa7 | 8229 | "Seconds\n" |
efd7904e RW |
8230 | "Minimal 1s dead-interval with fast sub-second hellos\n" |
8231 | "Hello multiplier factor\n" | |
8232 | "Number of Hellos to send each second\n" | |
8233 | "Address of interface\n") | |
0d829fa7 | 8234 | { |
d62a17ae | 8235 | return no_ip_ospf_dead_interval(self, vty, argc, argv); |
0d829fa7 QY |
8236 | } |
8237 | ||
718e3744 | 8238 | DEFUN (ip_ospf_hello_interval, |
0d829fa7 | 8239 | ip_ospf_hello_interval_cmd, |
7a7be519 | 8240 | "ip ospf hello-interval (1-65535) [A.B.C.D]", |
718e3744 | 8241 | "IP Information\n" |
8242 | "OSPF interface commands\n" | |
8243 | "Time between HELLO packets\n" | |
8244 | "Seconds\n" | |
0d829fa7 | 8245 | "Address of interface\n") |
718e3744 | 8246 | { |
d62a17ae | 8247 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8248 | int idx = 0; | |
be418160 | 8249 | struct in_addr addr = {.s_addr = 0L}; |
d62a17ae | 8250 | struct ospf_if_params *params; |
8251 | params = IF_DEF_PARAMS(ifp); | |
d7c0a89a | 8252 | uint32_t seconds = 0; |
be418160 | 8253 | bool is_addr = false; |
8254 | uint32_t old_interval = 0; | |
d62a17ae | 8255 | |
8256 | argv_find(argv, argc, "(1-65535)", &idx); | |
8257 | seconds = strtol(argv[idx]->arg, NULL, 10); | |
8258 | ||
8259 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
8260 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
8261 | vty_out(vty, | |
8262 | "Please specify interface address by A.B.C.D\n"); | |
8263 | return CMD_WARNING_CONFIG_FAILED; | |
8264 | } | |
718e3744 | 8265 | |
d62a17ae | 8266 | params = ospf_get_if_params(ifp, addr); |
8267 | ospf_if_update_params(ifp, addr); | |
be418160 | 8268 | is_addr = true; |
d62a17ae | 8269 | } |
718e3744 | 8270 | |
be418160 | 8271 | old_interval = params->v_hello; |
8272 | ||
8273 | /* Return, if same interval is configured. */ | |
8274 | if (old_interval == seconds) | |
8275 | return CMD_SUCCESS; | |
8276 | ||
d62a17ae | 8277 | SET_IF_PARAM(params, v_hello); |
8278 | params->v_hello = seconds; | |
718e3744 | 8279 | |
182d6bdc K |
8280 | if (!params->is_v_wait_set) { |
8281 | SET_IF_PARAM(params, v_wait); | |
8282 | /* As per RFC 4062 | |
8283 | * The router dead interval should | |
8284 | * be some multiple of the HelloInterval (perhaps 4 times the | |
8285 | * hello interval) and must be the same for all routers | |
8286 | * attached to a common network. | |
8287 | */ | |
8288 | params->v_wait = 4 * seconds; | |
8289 | } | |
8290 | ||
be418160 | 8291 | ospf_reset_hello_timer(ifp, addr, is_addr); |
8292 | ||
d62a17ae | 8293 | return CMD_SUCCESS; |
718e3744 | 8294 | } |
8295 | ||
7a7be519 | 8296 | DEFUN_HIDDEN (ospf_hello_interval, |
747e489c | 8297 | ospf_hello_interval_cmd, |
0d829fa7 | 8298 | "ospf hello-interval (1-65535) [A.B.C.D]", |
747e489c DW |
8299 | "OSPF interface commands\n" |
8300 | "Time between HELLO packets\n" | |
0d829fa7 QY |
8301 | "Seconds\n" |
8302 | "Address of interface\n") | |
7a7be519 | 8303 | { |
d62a17ae | 8304 | return ip_ospf_hello_interval(self, vty, argc, argv); |
7a7be519 | 8305 | } |
718e3744 | 8306 | |
8307 | DEFUN (no_ip_ospf_hello_interval, | |
0d829fa7 QY |
8308 | no_ip_ospf_hello_interval_cmd, |
8309 | "no ip ospf hello-interval [(1-65535) [A.B.C.D]]", | |
718e3744 | 8310 | NO_STR |
8311 | "IP Information\n" | |
8312 | "OSPF interface commands\n" | |
0d829fa7 | 8313 | "Time between HELLO packets\n" // ignored |
f9dfba8d | 8314 | "Seconds\n" |
0d829fa7 | 8315 | "Address of interface\n") |
718e3744 | 8316 | { |
d62a17ae | 8317 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8318 | int idx = 0; | |
be418160 | 8319 | struct in_addr addr = {.s_addr = 0L}; |
d62a17ae | 8320 | struct ospf_if_params *params; |
182d6bdc | 8321 | struct route_node *rn; |
df581cd3 | 8322 | |
d62a17ae | 8323 | params = IF_DEF_PARAMS(ifp); |
718e3744 | 8324 | |
d62a17ae | 8325 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { |
8326 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
8327 | vty_out(vty, | |
8328 | "Please specify interface address by A.B.C.D\n"); | |
8329 | return CMD_WARNING_CONFIG_FAILED; | |
8330 | } | |
718e3744 | 8331 | |
d62a17ae | 8332 | params = ospf_lookup_if_params(ifp, addr); |
8333 | if (params == NULL) | |
8334 | return CMD_SUCCESS; | |
8335 | } | |
718e3744 | 8336 | |
d62a17ae | 8337 | UNSET_IF_PARAM(params, v_hello); |
8338 | params->v_hello = OSPF_HELLO_INTERVAL_DEFAULT; | |
718e3744 | 8339 | |
182d6bdc K |
8340 | if (!params->is_v_wait_set) { |
8341 | UNSET_IF_PARAM(params, v_wait); | |
8342 | params->v_wait = OSPF_ROUTER_DEAD_INTERVAL_DEFAULT; | |
8343 | } | |
8344 | ||
8345 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { | |
8346 | struct ospf_interface *oi = rn->info; | |
8347 | ||
8348 | if (!oi) | |
8349 | continue; | |
8350 | ||
8351 | oi->type = IF_DEF_PARAMS(ifp)->type; | |
bc97889b | 8352 | oi->ptp_dmvpn = IF_DEF_PARAMS(ifp)->ptp_dmvpn; |
182d6bdc K |
8353 | |
8354 | if (oi->state > ISM_Down) { | |
8355 | OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceDown); | |
8356 | OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceUp); | |
8357 | } | |
8358 | } | |
8359 | ||
d62a17ae | 8360 | if (params != IF_DEF_PARAMS(ifp)) { |
8361 | ospf_free_if_params(ifp, addr); | |
8362 | ospf_if_update_params(ifp, addr); | |
8363 | } | |
718e3744 | 8364 | |
d62a17ae | 8365 | return CMD_SUCCESS; |
718e3744 | 8366 | } |
8367 | ||
0d829fa7 QY |
8368 | DEFUN_HIDDEN (no_ospf_hello_interval, |
8369 | no_ospf_hello_interval_cmd, | |
8370 | "no ospf hello-interval [(1-65535) [A.B.C.D]]", | |
8371 | NO_STR | |
8372 | "OSPF interface commands\n" | |
8373 | "Time between HELLO packets\n" // ignored | |
8374 | "Seconds\n" | |
8375 | "Address of interface\n") | |
8376 | { | |
d62a17ae | 8377 | return no_ip_ospf_hello_interval(self, vty, argc, argv); |
0d829fa7 | 8378 | } |
718e3744 | 8379 | |
bc97889b AL |
8380 | DEFUN(ip_ospf_network, ip_ospf_network_cmd, |
8381 | "ip ospf network <broadcast|non-broadcast|point-to-multipoint|point-to-point [dmvpn]>", | |
8382 | "IP Information\n" | |
8383 | "OSPF interface commands\n" | |
8384 | "Network type\n" | |
8385 | "Specify OSPF broadcast multi-access network\n" | |
8386 | "Specify OSPF NBMA network\n" | |
8387 | "Specify OSPF point-to-multipoint network\n" | |
8388 | "Specify OSPF point-to-point network\n" | |
8389 | "Specify OSPF point-to-point DMVPN network\n") | |
718e3744 | 8390 | { |
d62a17ae | 8391 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8392 | int idx = 0; | |
8393 | int old_type = IF_DEF_PARAMS(ifp)->type; | |
bc97889b | 8394 | uint8_t old_ptp_dmvpn = IF_DEF_PARAMS(ifp)->ptp_dmvpn; |
d62a17ae | 8395 | struct route_node *rn; |
718e3744 | 8396 | |
d62a17ae | 8397 | if (old_type == OSPF_IFTYPE_LOOPBACK) { |
8398 | vty_out(vty, | |
8399 | "This is a loopback interface. Can't set network type.\n"); | |
8400 | return CMD_WARNING_CONFIG_FAILED; | |
8401 | } | |
718e3744 | 8402 | |
bc97889b AL |
8403 | IF_DEF_PARAMS(ifp)->ptp_dmvpn = 0; |
8404 | ||
d62a17ae | 8405 | if (argv_find(argv, argc, "broadcast", &idx)) |
8406 | IF_DEF_PARAMS(ifp)->type = OSPF_IFTYPE_BROADCAST; | |
8407 | else if (argv_find(argv, argc, "non-broadcast", &idx)) | |
8408 | IF_DEF_PARAMS(ifp)->type = OSPF_IFTYPE_NBMA; | |
8409 | else if (argv_find(argv, argc, "point-to-multipoint", &idx)) | |
8410 | IF_DEF_PARAMS(ifp)->type = OSPF_IFTYPE_POINTOMULTIPOINT; | |
bc97889b | 8411 | else if (argv_find(argv, argc, "point-to-point", &idx)) { |
d62a17ae | 8412 | IF_DEF_PARAMS(ifp)->type = OSPF_IFTYPE_POINTOPOINT; |
bc97889b AL |
8413 | if (argv_find(argv, argc, "dmvpn", &idx)) |
8414 | IF_DEF_PARAMS(ifp)->ptp_dmvpn = 1; | |
8415 | } | |
718e3744 | 8416 | |
bc97889b AL |
8417 | if (IF_DEF_PARAMS(ifp)->type == old_type |
8418 | && IF_DEF_PARAMS(ifp)->ptp_dmvpn == old_ptp_dmvpn) | |
d62a17ae | 8419 | return CMD_SUCCESS; |
8420 | ||
8421 | SET_IF_PARAM(IF_DEF_PARAMS(ifp), type); | |
8422 | ||
8423 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { | |
8424 | struct ospf_interface *oi = rn->info; | |
8425 | ||
8426 | if (!oi) | |
8427 | continue; | |
8428 | ||
8429 | oi->type = IF_DEF_PARAMS(ifp)->type; | |
8430 | ||
8431 | if (oi->state > ISM_Down) { | |
8432 | OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceDown); | |
8433 | OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceUp); | |
8434 | } | |
7a7be519 | 8435 | } |
7a7be519 | 8436 | |
d62a17ae | 8437 | return CMD_SUCCESS; |
7a7be519 | 8438 | } |
8439 | ||
8440 | DEFUN_HIDDEN (ospf_network, | |
8441 | ospf_network_cmd, | |
e83a9414 | 8442 | "ospf network <broadcast|non-broadcast|point-to-multipoint|point-to-point>", |
7a7be519 | 8443 | "OSPF interface commands\n" |
8444 | "Network type\n" | |
8445 | "Specify OSPF broadcast multi-access network\n" | |
8446 | "Specify OSPF NBMA network\n" | |
8447 | "Specify OSPF point-to-multipoint network\n" | |
8448 | "Specify OSPF point-to-point network\n") | |
8449 | { | |
d62a17ae | 8450 | return ip_ospf_network(self, vty, argc, argv); |
7a7be519 | 8451 | } |
8452 | ||
8453 | DEFUN (no_ip_ospf_network, | |
8454 | no_ip_ospf_network_cmd, | |
8455 | "no ip ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]", | |
8456 | NO_STR | |
8457 | "IP Information\n" | |
8458 | "OSPF interface commands\n" | |
8459 | "Network type\n" | |
8460 | "Specify OSPF broadcast multi-access network\n" | |
8461 | "Specify OSPF NBMA network\n" | |
8462 | "Specify OSPF point-to-multipoint network\n" | |
8463 | "Specify OSPF point-to-point network\n") | |
22b27e95 | 8464 | { |
d62a17ae | 8465 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8466 | int old_type = IF_DEF_PARAMS(ifp)->type; | |
8467 | struct route_node *rn; | |
7a7be519 | 8468 | |
d62a17ae | 8469 | IF_DEF_PARAMS(ifp)->type = ospf_default_iftype(ifp); |
bc97889b | 8470 | IF_DEF_PARAMS(ifp)->ptp_dmvpn = 0; |
7a7be519 | 8471 | |
d62a17ae | 8472 | if (IF_DEF_PARAMS(ifp)->type == old_type) |
8473 | return CMD_SUCCESS; | |
7a7be519 | 8474 | |
d62a17ae | 8475 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { |
8476 | struct ospf_interface *oi = rn->info; | |
7a7be519 | 8477 | |
d62a17ae | 8478 | if (!oi) |
8479 | continue; | |
7a7be519 | 8480 | |
d62a17ae | 8481 | oi->type = IF_DEF_PARAMS(ifp)->type; |
7a7be519 | 8482 | |
d62a17ae | 8483 | if (oi->state > ISM_Down) { |
8484 | OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceDown); | |
8485 | OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceUp); | |
8486 | } | |
7a7be519 | 8487 | } |
7a7be519 | 8488 | |
d62a17ae | 8489 | return CMD_SUCCESS; |
7a7be519 | 8490 | } |
8491 | ||
0d829fa7 QY |
8492 | DEFUN_HIDDEN (no_ospf_network, |
8493 | no_ospf_network_cmd, | |
8494 | "no ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]", | |
8495 | NO_STR | |
8496 | "OSPF interface commands\n" | |
8497 | "Network type\n" | |
8498 | "Specify OSPF broadcast multi-access network\n" | |
8499 | "Specify OSPF NBMA network\n" | |
8500 | "Specify OSPF point-to-multipoint network\n" | |
8501 | "Specify OSPF point-to-point network\n") | |
8502 | { | |
d62a17ae | 8503 | return no_ip_ospf_network(self, vty, argc, argv); |
0d829fa7 QY |
8504 | } |
8505 | ||
7a7be519 | 8506 | DEFUN (ip_ospf_priority, |
537eae3f | 8507 | ip_ospf_priority_cmd, |
7a7be519 | 8508 | "ip ospf priority (0-255) [A.B.C.D]", |
8509 | "IP Information\n" | |
8510 | "OSPF interface commands\n" | |
8511 | "Router priority\n" | |
8512 | "Priority\n" | |
efd7904e | 8513 | "Address of interface\n") |
7a7be519 | 8514 | { |
d62a17ae | 8515 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8516 | int idx = 0; | |
8517 | long priority; | |
8518 | struct route_node *rn; | |
8519 | struct in_addr addr; | |
8520 | struct ospf_if_params *params; | |
8521 | params = IF_DEF_PARAMS(ifp); | |
8522 | ||
8523 | argv_find(argv, argc, "(0-255)", &idx); | |
8524 | priority = strtol(argv[idx]->arg, NULL, 10); | |
8525 | ||
8526 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
8527 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
8528 | vty_out(vty, | |
8529 | "Please specify interface address by A.B.C.D\n"); | |
8530 | return CMD_WARNING_CONFIG_FAILED; | |
8531 | } | |
7a7be519 | 8532 | |
d62a17ae | 8533 | params = ospf_get_if_params(ifp, addr); |
8534 | ospf_if_update_params(ifp, addr); | |
7a7be519 | 8535 | } |
8536 | ||
d62a17ae | 8537 | SET_IF_PARAM(params, priority); |
8538 | params->priority = priority; | |
7a7be519 | 8539 | |
d62a17ae | 8540 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { |
8541 | struct ospf_interface *oi = rn->info; | |
7a7be519 | 8542 | |
d62a17ae | 8543 | if (!oi) |
8544 | continue; | |
7a7be519 | 8545 | |
d62a17ae | 8546 | if (PRIORITY(oi) != OSPF_IF_PARAM(oi, priority)) { |
8547 | PRIORITY(oi) = OSPF_IF_PARAM(oi, priority); | |
8548 | OSPF_ISM_EVENT_SCHEDULE(oi, ISM_NeighborChange); | |
8549 | } | |
718e3744 | 8550 | } |
718e3744 | 8551 | |
d62a17ae | 8552 | return CMD_SUCCESS; |
718e3744 | 8553 | } |
8554 | ||
7a7be519 | 8555 | DEFUN_HIDDEN (ospf_priority, |
8556 | ospf_priority_cmd, | |
0d829fa7 | 8557 | "ospf priority (0-255) [A.B.C.D]", |
7a7be519 | 8558 | "OSPF interface commands\n" |
8559 | "Router priority\n" | |
3a2d747c | 8560 | "Priority\n" |
efd7904e | 8561 | "Address of interface\n") |
718e3744 | 8562 | { |
d62a17ae | 8563 | return ip_ospf_priority(self, vty, argc, argv); |
718e3744 | 8564 | } |
8565 | ||
718e3744 | 8566 | DEFUN (no_ip_ospf_priority, |
537eae3f | 8567 | no_ip_ospf_priority_cmd, |
7a7be519 | 8568 | "no ip ospf priority [(0-255) [A.B.C.D]]", |
718e3744 | 8569 | NO_STR |
8570 | "IP Information\n" | |
8571 | "OSPF interface commands\n" | |
0d829fa7 | 8572 | "Router priority\n" // ignored |
813d4307 | 8573 | "Priority\n" |
efd7904e | 8574 | "Address of interface\n") |
718e3744 | 8575 | { |
d62a17ae | 8576 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8577 | int idx = 0; | |
8578 | struct route_node *rn; | |
8579 | struct in_addr addr; | |
8580 | struct ospf_if_params *params; | |
8581 | ||
8582 | params = IF_DEF_PARAMS(ifp); | |
8583 | ||
8584 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
8585 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
8586 | vty_out(vty, | |
8587 | "Please specify interface address by A.B.C.D\n"); | |
8588 | return CMD_WARNING_CONFIG_FAILED; | |
8589 | } | |
8590 | ||
8591 | params = ospf_lookup_if_params(ifp, addr); | |
8592 | if (params == NULL) | |
8593 | return CMD_SUCCESS; | |
718e3744 | 8594 | } |
8595 | ||
d62a17ae | 8596 | UNSET_IF_PARAM(params, priority); |
8597 | params->priority = OSPF_ROUTER_PRIORITY_DEFAULT; | |
8598 | ||
8599 | if (params != IF_DEF_PARAMS(ifp)) { | |
8600 | ospf_free_if_params(ifp, addr); | |
8601 | ospf_if_update_params(ifp, addr); | |
718e3744 | 8602 | } |
d62a17ae | 8603 | |
8604 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { | |
8605 | struct ospf_interface *oi = rn->info; | |
8606 | ||
8607 | if (!oi) | |
8608 | continue; | |
8609 | ||
8610 | if (PRIORITY(oi) != OSPF_IF_PARAM(oi, priority)) { | |
8611 | PRIORITY(oi) = OSPF_IF_PARAM(oi, priority); | |
8612 | OSPF_ISM_EVENT_SCHEDULE(oi, ISM_NeighborChange); | |
8613 | } | |
8614 | } | |
8615 | ||
8616 | return CMD_SUCCESS; | |
718e3744 | 8617 | } |
8618 | ||
0d829fa7 | 8619 | DEFUN_HIDDEN (no_ospf_priority, |
537eae3f | 8620 | no_ospf_priority_cmd, |
0d829fa7 QY |
8621 | "no ospf priority [(0-255) [A.B.C.D]]", |
8622 | NO_STR | |
8623 | "OSPF interface commands\n" | |
8624 | "Router priority\n" | |
8625 | "Priority\n" | |
efd7904e | 8626 | "Address of interface\n") |
0d829fa7 | 8627 | { |
d62a17ae | 8628 | return no_ip_ospf_priority(self, vty, argc, argv); |
0d829fa7 | 8629 | } |
a1afa410 | 8630 | |
718e3744 | 8631 | DEFUN (ip_ospf_retransmit_interval, |
8632 | ip_ospf_retransmit_interval_addr_cmd, | |
d4badaf6 | 8633 | "ip ospf retransmit-interval (1-65535) [A.B.C.D]", |
718e3744 | 8634 | "IP Information\n" |
8635 | "OSPF interface commands\n" | |
8636 | "Time between retransmitting lost link state advertisements\n" | |
8637 | "Seconds\n" | |
efd7904e | 8638 | "Address of interface\n") |
718e3744 | 8639 | { |
d62a17ae | 8640 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8641 | int idx = 0; | |
d7c0a89a | 8642 | uint32_t seconds; |
d62a17ae | 8643 | struct in_addr addr; |
8644 | struct ospf_if_params *params; | |
8645 | params = IF_DEF_PARAMS(ifp); | |
8646 | ||
d4badaf6 | 8647 | argv_find(argv, argc, "(1-65535)", &idx); |
d62a17ae | 8648 | seconds = strtol(argv[idx]->arg, NULL, 10); |
8649 | ||
8650 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
8651 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
8652 | vty_out(vty, | |
8653 | "Please specify interface address by A.B.C.D\n"); | |
8654 | return CMD_WARNING_CONFIG_FAILED; | |
8655 | } | |
718e3744 | 8656 | |
d62a17ae | 8657 | params = ospf_get_if_params(ifp, addr); |
8658 | ospf_if_update_params(ifp, addr); | |
718e3744 | 8659 | } |
8660 | ||
d62a17ae | 8661 | SET_IF_PARAM(params, retransmit_interval); |
8662 | params->retransmit_interval = seconds; | |
718e3744 | 8663 | |
d62a17ae | 8664 | return CMD_SUCCESS; |
718e3744 | 8665 | } |
8666 | ||
7a7be519 | 8667 | DEFUN_HIDDEN (ospf_retransmit_interval, |
747e489c | 8668 | ospf_retransmit_interval_cmd, |
d4badaf6 | 8669 | "ospf retransmit-interval (1-65535) [A.B.C.D]", |
747e489c DW |
8670 | "OSPF interface commands\n" |
8671 | "Time between retransmitting lost link state advertisements\n" | |
3a2d747c | 8672 | "Seconds\n" |
efd7904e | 8673 | "Address of interface\n") |
7a7be519 | 8674 | { |
d62a17ae | 8675 | return ip_ospf_retransmit_interval(self, vty, argc, argv); |
7a7be519 | 8676 | } |
718e3744 | 8677 | |
8678 | DEFUN (no_ip_ospf_retransmit_interval, | |
8679 | no_ip_ospf_retransmit_interval_addr_cmd, | |
d4badaf6 | 8680 | "no ip ospf retransmit-interval [(1-65535)] [A.B.C.D]", |
718e3744 | 8681 | NO_STR |
8682 | "IP Information\n" | |
8683 | "OSPF interface commands\n" | |
3a2d747c QY |
8684 | "Time between retransmitting lost link state advertisements\n" |
8685 | "Seconds\n" | |
0d829fa7 | 8686 | "Address of interface\n") |
718e3744 | 8687 | { |
d62a17ae | 8688 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8689 | int idx = 0; | |
8690 | struct in_addr addr; | |
8691 | struct ospf_if_params *params; | |
47b91972 | 8692 | |
d62a17ae | 8693 | params = IF_DEF_PARAMS(ifp); |
718e3744 | 8694 | |
d62a17ae | 8695 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { |
8696 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
8697 | vty_out(vty, | |
8698 | "Please specify interface address by A.B.C.D\n"); | |
8699 | return CMD_WARNING_CONFIG_FAILED; | |
8700 | } | |
718e3744 | 8701 | |
d62a17ae | 8702 | params = ospf_lookup_if_params(ifp, addr); |
8703 | if (params == NULL) | |
8704 | return CMD_SUCCESS; | |
8705 | } | |
718e3744 | 8706 | |
d62a17ae | 8707 | UNSET_IF_PARAM(params, retransmit_interval); |
8708 | params->retransmit_interval = OSPF_RETRANSMIT_INTERVAL_DEFAULT; | |
718e3744 | 8709 | |
d62a17ae | 8710 | if (params != IF_DEF_PARAMS(ifp)) { |
8711 | ospf_free_if_params(ifp, addr); | |
8712 | ospf_if_update_params(ifp, addr); | |
8713 | } | |
718e3744 | 8714 | |
d62a17ae | 8715 | return CMD_SUCCESS; |
718e3744 | 8716 | } |
8717 | ||
0d829fa7 QY |
8718 | DEFUN_HIDDEN (no_ospf_retransmit_interval, |
8719 | no_ospf_retransmit_interval_cmd, | |
d4badaf6 | 8720 | "no ospf retransmit-interval [(1-65535)] [A.B.C.D]", |
0d829fa7 QY |
8721 | NO_STR |
8722 | "OSPF interface commands\n" | |
3a2d747c QY |
8723 | "Time between retransmitting lost link state advertisements\n" |
8724 | "Seconds\n" | |
8725 | "Address of interface\n") | |
0d829fa7 | 8726 | { |
d62a17ae | 8727 | return no_ip_ospf_retransmit_interval(self, vty, argc, argv); |
0d829fa7 | 8728 | } |
813d4307 | 8729 | |
718e3744 | 8730 | DEFUN (ip_ospf_transmit_delay, |
8731 | ip_ospf_transmit_delay_addr_cmd, | |
7a7be519 | 8732 | "ip ospf transmit-delay (1-65535) [A.B.C.D]", |
718e3744 | 8733 | "IP Information\n" |
8734 | "OSPF interface commands\n" | |
8735 | "Link state transmit delay\n" | |
8736 | "Seconds\n" | |
efd7904e | 8737 | "Address of interface\n") |
718e3744 | 8738 | { |
d62a17ae | 8739 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8740 | int idx = 0; | |
d7c0a89a | 8741 | uint32_t seconds; |
d62a17ae | 8742 | struct in_addr addr; |
8743 | struct ospf_if_params *params; | |
8744 | ||
8745 | params = IF_DEF_PARAMS(ifp); | |
8746 | argv_find(argv, argc, "(1-65535)", &idx); | |
8747 | seconds = strtol(argv[idx]->arg, NULL, 10); | |
8748 | ||
8749 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
8750 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
8751 | vty_out(vty, | |
8752 | "Please specify interface address by A.B.C.D\n"); | |
8753 | return CMD_WARNING_CONFIG_FAILED; | |
8754 | } | |
718e3744 | 8755 | |
d62a17ae | 8756 | params = ospf_get_if_params(ifp, addr); |
8757 | ospf_if_update_params(ifp, addr); | |
718e3744 | 8758 | } |
8759 | ||
d62a17ae | 8760 | SET_IF_PARAM(params, transmit_delay); |
8761 | params->transmit_delay = seconds; | |
718e3744 | 8762 | |
d62a17ae | 8763 | return CMD_SUCCESS; |
718e3744 | 8764 | } |
8765 | ||
7a7be519 | 8766 | DEFUN_HIDDEN (ospf_transmit_delay, |
747e489c | 8767 | ospf_transmit_delay_cmd, |
0d829fa7 | 8768 | "ospf transmit-delay (1-65535) [A.B.C.D]", |
747e489c DW |
8769 | "OSPF interface commands\n" |
8770 | "Link state transmit delay\n" | |
3a2d747c | 8771 | "Seconds\n" |
efd7904e | 8772 | "Address of interface\n") |
7a7be519 | 8773 | { |
d62a17ae | 8774 | return ip_ospf_transmit_delay(self, vty, argc, argv); |
7a7be519 | 8775 | } |
718e3744 | 8776 | |
8777 | DEFUN (no_ip_ospf_transmit_delay, | |
8778 | no_ip_ospf_transmit_delay_addr_cmd, | |
0d829fa7 | 8779 | "no ip ospf transmit-delay [(1-65535)] [A.B.C.D]", |
718e3744 | 8780 | NO_STR |
8781 | "IP Information\n" | |
8782 | "OSPF interface commands\n" | |
8783 | "Link state transmit delay\n" | |
efd7904e RW |
8784 | "Seconds\n" |
8785 | "Address of interface\n") | |
718e3744 | 8786 | { |
d62a17ae | 8787 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8788 | int idx = 0; | |
8789 | struct in_addr addr; | |
8790 | struct ospf_if_params *params; | |
718e3744 | 8791 | |
d62a17ae | 8792 | params = IF_DEF_PARAMS(ifp); |
718e3744 | 8793 | |
d62a17ae | 8794 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { |
8795 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
8796 | vty_out(vty, | |
8797 | "Please specify interface address by A.B.C.D\n"); | |
8798 | return CMD_WARNING_CONFIG_FAILED; | |
8799 | } | |
718e3744 | 8800 | |
d62a17ae | 8801 | params = ospf_lookup_if_params(ifp, addr); |
8802 | if (params == NULL) | |
8803 | return CMD_SUCCESS; | |
8804 | } | |
718e3744 | 8805 | |
d62a17ae | 8806 | UNSET_IF_PARAM(params, transmit_delay); |
8807 | params->transmit_delay = OSPF_TRANSMIT_DELAY_DEFAULT; | |
718e3744 | 8808 | |
d62a17ae | 8809 | if (params != IF_DEF_PARAMS(ifp)) { |
8810 | ospf_free_if_params(ifp, addr); | |
8811 | ospf_if_update_params(ifp, addr); | |
8812 | } | |
8813 | ||
8814 | return CMD_SUCCESS; | |
718e3744 | 8815 | } |
8816 | ||
813d4307 | 8817 | |
0d829fa7 QY |
8818 | DEFUN_HIDDEN (no_ospf_transmit_delay, |
8819 | no_ospf_transmit_delay_cmd, | |
32573073 | 8820 | "no ospf transmit-delay [(1-65535) [A.B.C.D]]", |
0d829fa7 QY |
8821 | NO_STR |
8822 | "OSPF interface commands\n" | |
32573073 QY |
8823 | "Link state transmit delay\n" |
8824 | "Seconds\n" | |
efd7904e | 8825 | "Address of interface\n") |
813d4307 | 8826 | { |
d62a17ae | 8827 | return no_ip_ospf_transmit_delay(self, vty, argc, argv); |
813d4307 DW |
8828 | } |
8829 | ||
e723861d DS |
8830 | DEFUN (ip_ospf_area, |
8831 | ip_ospf_area_cmd, | |
52c62ab8 | 8832 | "ip ospf [(1-65535)] area <A.B.C.D|(0-4294967295)> [A.B.C.D]", |
e723861d DS |
8833 | "IP Information\n" |
8834 | "OSPF interface commands\n" | |
7a7be519 | 8835 | "Instance ID\n" |
e723861d DS |
8836 | "Enable OSPF on this interface\n" |
8837 | "OSPF area ID in IP address format\n" | |
52c62ab8 JAG |
8838 | "OSPF area ID as a decimal value\n" |
8839 | "Address of interface\n") | |
e723861d | 8840 | { |
d62a17ae | 8841 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8842 | int idx = 0; | |
8843 | int format, ret; | |
8844 | struct in_addr area_id; | |
8845 | struct in_addr addr; | |
35955c14 | 8846 | struct ospf_if_params *params = NULL; |
d62a17ae | 8847 | struct route_node *rn; |
b5a8894d | 8848 | struct ospf *ospf = NULL; |
d7c0a89a | 8849 | unsigned short instance = 0; |
d62a17ae | 8850 | char *areaid; |
15bf52d3 | 8851 | uint32_t count = 0; |
d62a17ae | 8852 | |
8853 | if (argv_find(argv, argc, "(1-65535)", &idx)) | |
8854 | instance = strtol(argv[idx]->arg, NULL, 10); | |
8855 | ||
8856 | argv_find(argv, argc, "area", &idx); | |
8857 | areaid = argv[idx + 1]->arg; | |
8858 | ||
b56114aa | 8859 | if (!instance) |
a36898e7 | 8860 | ospf = ospf_lookup_by_vrf_id(ifp->vrf_id); |
b5a8894d CS |
8861 | else |
8862 | ospf = ospf_lookup_instance(instance); | |
8863 | ||
409f98ab | 8864 | if (instance && instance != ospf_instance) { |
2b0a32da DS |
8865 | /* |
8866 | * At this point we know we have received | |
8867 | * an instance and there is no ospf instance | |
8868 | * associated with it. This means we are | |
8869 | * in a situation where we have an | |
8870 | * ospf command that is setup for a different | |
8871 | * process(instance). We need to safely | |
8872 | * remove the command from ourselves and | |
8873 | * allow the other instance(process) handle | |
8874 | * the configuration command. | |
8875 | */ | |
15bf52d3 IR |
8876 | count = 0; |
8877 | ||
d62a17ae | 8878 | params = IF_DEF_PARAMS(ifp); |
8879 | if (OSPF_IF_PARAM_CONFIGURED(params, if_area)) { | |
8880 | UNSET_IF_PARAM(params, if_area); | |
15bf52d3 IR |
8881 | count++; |
8882 | } | |
8883 | ||
8884 | for (rn = route_top(IF_OIFS_PARAMS(ifp)); rn; rn = route_next(rn)) | |
8885 | if ((params = rn->info) && OSPF_IF_PARAM_CONFIGURED(params, if_area)) { | |
8886 | UNSET_IF_PARAM(params, if_area); | |
8887 | count++; | |
8888 | } | |
8889 | ||
8890 | if (count > 0) { | |
8891 | ospf = ospf_lookup_by_vrf_id(ifp->vrf_id); | |
cbf32f74 | 8892 | if (ospf) |
2b0a32da | 8893 | ospf_interface_area_unset(ospf, ifp); |
d62a17ae | 8894 | } |
15bf52d3 | 8895 | |
ac28e4ec | 8896 | return CMD_NOT_MY_INSTANCE; |
d62a17ae | 8897 | } |
e723861d | 8898 | |
d62a17ae | 8899 | ret = str2area_id(areaid, &area_id, &format); |
8900 | if (ret < 0) { | |
8901 | vty_out(vty, "Please specify area by A.B.C.D|<0-4294967295>\n"); | |
8902 | return CMD_WARNING_CONFIG_FAILED; | |
8903 | } | |
8904 | if (memcmp(ifp->name, "VLINK", 5) == 0) { | |
8905 | vty_out(vty, "Cannot enable OSPF on a virtual link.\n"); | |
8906 | return CMD_WARNING_CONFIG_FAILED; | |
8907 | } | |
8908 | ||
eb364867 IR |
8909 | if (ospf) { |
8910 | for (rn = route_top(ospf->networks); rn; rn = route_next(rn)) { | |
8911 | if (rn->info != NULL) { | |
8912 | vty_out(vty, | |
8913 | "Please remove all network commands first.\n"); | |
8914 | return CMD_WARNING_CONFIG_FAILED; | |
8915 | } | |
8916 | } | |
8917 | } | |
8918 | ||
d62a17ae | 8919 | params = IF_DEF_PARAMS(ifp); |
8920 | if (OSPF_IF_PARAM_CONFIGURED(params, if_area) | |
8921 | && !IPV4_ADDR_SAME(¶ms->if_area, &area_id)) { | |
8922 | vty_out(vty, | |
8923 | "Must remove previous area config before changing ospf area \n"); | |
8924 | return CMD_WARNING_CONFIG_FAILED; | |
8925 | } | |
8926 | ||
8927 | // Check if we have an address arg and proccess it | |
8928 | if (argc == idx + 3) { | |
cc9b06ad | 8929 | if (!inet_aton(argv[idx + 2]->arg, &addr)) { |
996c9314 LB |
8930 | vty_out(vty, |
8931 | "Please specify Intf Address by A.B.C.D\n"); | |
cc9b06ad DS |
8932 | return CMD_WARNING_CONFIG_FAILED; |
8933 | } | |
d62a17ae | 8934 | // update/create address-level params |
8935 | params = ospf_get_if_params((ifp), (addr)); | |
8936 | if (OSPF_IF_PARAM_CONFIGURED(params, if_area)) { | |
a900cece IR |
8937 | if (!IPV4_ADDR_SAME(¶ms->if_area, &area_id)) { |
8938 | vty_out(vty, | |
8939 | "Must remove previous area/address config before changing ospf area\n"); | |
8940 | return CMD_WARNING_CONFIG_FAILED; | |
8941 | } else | |
8942 | return CMD_SUCCESS; | |
d62a17ae | 8943 | } |
8944 | ospf_if_update_params((ifp), (addr)); | |
8945 | } | |
8946 | ||
d62a17ae | 8947 | /* enable ospf on this interface with area_id */ |
35955c14 CS |
8948 | if (params) { |
8949 | SET_IF_PARAM(params, if_area); | |
8950 | params->if_area = area_id; | |
8951 | params->if_area_id_fmt = format; | |
8952 | } | |
aed7cc62 | 8953 | |
cbf32f74 | 8954 | if (ospf) |
aed7cc62 | 8955 | ospf_interface_area_set(ospf, ifp); |
d62a17ae | 8956 | |
8957 | return CMD_SUCCESS; | |
e723861d DS |
8958 | } |
8959 | ||
8960 | DEFUN (no_ip_ospf_area, | |
8961 | no_ip_ospf_area_cmd, | |
52c62ab8 | 8962 | "no ip ospf [(1-65535)] area [<A.B.C.D|(0-4294967295)> [A.B.C.D]]", |
e723861d DS |
8963 | NO_STR |
8964 | "IP Information\n" | |
8965 | "OSPF interface commands\n" | |
3a2d747c | 8966 | "Instance ID\n" |
7a7be519 | 8967 | "Disable OSPF on this interface\n" |
8968 | "OSPF area ID in IP address format\n" | |
52c62ab8 JAG |
8969 | "OSPF area ID as a decimal value\n" |
8970 | "Address of interface\n") | |
e723861d | 8971 | { |
d62a17ae | 8972 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8973 | int idx = 0; | |
8974 | struct ospf *ospf; | |
8975 | struct ospf_if_params *params; | |
d7c0a89a | 8976 | unsigned short instance = 0; |
d62a17ae | 8977 | struct in_addr addr; |
58e5d140 | 8978 | struct in_addr area_id; |
d62a17ae | 8979 | |
8980 | if (argv_find(argv, argc, "(1-65535)", &idx)) | |
8981 | instance = strtol(argv[idx]->arg, NULL, 10); | |
8982 | ||
b56114aa | 8983 | if (!instance) |
a36898e7 | 8984 | ospf = ospf_lookup_by_vrf_id(ifp->vrf_id); |
b5a8894d CS |
8985 | else |
8986 | ospf = ospf_lookup_instance(instance); | |
8987 | ||
409f98ab | 8988 | if (instance && instance != ospf_instance) |
ac28e4ec | 8989 | return CMD_NOT_MY_INSTANCE; |
d62a17ae | 8990 | |
8991 | argv_find(argv, argc, "area", &idx); | |
8992 | ||
8993 | // Check if we have an address arg and proccess it | |
8994 | if (argc == idx + 3) { | |
cc9b06ad | 8995 | if (!inet_aton(argv[idx + 2]->arg, &addr)) { |
996c9314 LB |
8996 | vty_out(vty, |
8997 | "Please specify Intf Address by A.B.C.D\n"); | |
cc9b06ad DS |
8998 | return CMD_WARNING_CONFIG_FAILED; |
8999 | } | |
d62a17ae | 9000 | params = ospf_lookup_if_params(ifp, addr); |
9001 | if ((params) == NULL) | |
9002 | return CMD_SUCCESS; | |
9003 | } else | |
9004 | params = IF_DEF_PARAMS(ifp); | |
9005 | ||
58e5d140 | 9006 | area_id = params->if_area; |
d62a17ae | 9007 | if (!OSPF_IF_PARAM_CONFIGURED(params, if_area)) { |
9008 | vty_out(vty, | |
9009 | "Can't find specified interface area configuration.\n"); | |
9010 | return CMD_WARNING_CONFIG_FAILED; | |
9011 | } | |
813d4307 | 9012 | |
d62a17ae | 9013 | UNSET_IF_PARAM(params, if_area); |
9014 | if (params != IF_DEF_PARAMS((ifp))) { | |
9015 | ospf_free_if_params((ifp), (addr)); | |
9016 | ospf_if_update_params((ifp), (addr)); | |
9017 | } | |
9018 | ||
e4129293 IR |
9019 | if (ospf) { |
9020 | ospf_interface_area_unset(ospf, ifp); | |
58e5d140 | 9021 | ospf_area_check_free(ospf, area_id); |
e4129293 IR |
9022 | } |
9023 | ||
d62a17ae | 9024 | return CMD_SUCCESS; |
813d4307 DW |
9025 | } |
9026 | ||
3eec4ee0 IR |
9027 | DEFUN (ip_ospf_passive, |
9028 | ip_ospf_passive_cmd, | |
9029 | "ip ospf passive [A.B.C.D]", | |
9030 | "IP Information\n" | |
9031 | "OSPF interface commands\n" | |
9032 | "Suppress routing updates on an interface\n" | |
9033 | "Address of interface\n") | |
9034 | { | |
9035 | VTY_DECLVAR_CONTEXT(interface, ifp); | |
9036 | int idx_ipv4 = 3; | |
82f0277b | 9037 | struct in_addr addr = {.s_addr = INADDR_ANY}; |
3eec4ee0 IR |
9038 | struct ospf_if_params *params; |
9039 | int ret; | |
9040 | ||
9041 | if (argc == 4) { | |
9042 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
9043 | if (!ret) { | |
9044 | vty_out(vty, | |
9045 | "Please specify interface address by A.B.C.D\n"); | |
9046 | return CMD_WARNING_CONFIG_FAILED; | |
9047 | } | |
9048 | params = ospf_get_if_params(ifp, addr); | |
9049 | ospf_if_update_params(ifp, addr); | |
9050 | } else { | |
9051 | params = IF_DEF_PARAMS(ifp); | |
9052 | } | |
9053 | ||
82f0277b | 9054 | ospf_passive_interface_update(ifp, params, addr, OSPF_IF_PASSIVE); |
3eec4ee0 IR |
9055 | |
9056 | return CMD_SUCCESS; | |
9057 | } | |
9058 | ||
9059 | DEFUN (no_ip_ospf_passive, | |
9060 | no_ip_ospf_passive_cmd, | |
9061 | "no ip ospf passive [A.B.C.D]", | |
9062 | NO_STR | |
9063 | "IP Information\n" | |
9064 | "OSPF interface commands\n" | |
9065 | "Enable routing updates on an interface\n" | |
9066 | "Address of interface\n") | |
9067 | { | |
9068 | VTY_DECLVAR_CONTEXT(interface, ifp); | |
9069 | int idx_ipv4 = 4; | |
82f0277b | 9070 | struct in_addr addr = {.s_addr = INADDR_ANY}; |
3eec4ee0 IR |
9071 | struct ospf_if_params *params; |
9072 | int ret; | |
9073 | ||
9074 | if (argc == 5) { | |
9075 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
9076 | if (!ret) { | |
9077 | vty_out(vty, | |
9078 | "Please specify interface address by A.B.C.D\n"); | |
9079 | return CMD_WARNING_CONFIG_FAILED; | |
9080 | } | |
9081 | params = ospf_lookup_if_params(ifp, addr); | |
9082 | if (params == NULL) | |
9083 | return CMD_SUCCESS; | |
9084 | } else { | |
9085 | params = IF_DEF_PARAMS(ifp); | |
9086 | } | |
9087 | ||
82f0277b | 9088 | ospf_passive_interface_update(ifp, params, addr, OSPF_IF_ACTIVE); |
3eec4ee0 IR |
9089 | |
9090 | return CMD_SUCCESS; | |
9091 | } | |
9092 | ||
6f2a6703 CF |
9093 | DEFUN (ospf_redistribute_source, |
9094 | ospf_redistribute_source_cmd, | |
ea38ced1 | 9095 | "redistribute " FRR_REDIST_STR_OSPFD " [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]", |
d1c65c21 | 9096 | REDIST_STR |
ab0181ee | 9097 | FRR_REDIST_HELP_STR_OSPFD |
718e3744 | 9098 | "Metric for redistributed routes\n" |
9099 | "OSPF default metric\n" | |
9100 | "OSPF exterior metric type for redistributed routes\n" | |
7111c1a0 | 9101 | "Set OSPF External Type 1/2 metrics\n" |
718e3744 | 9102 | "Route map reference\n" |
9103 | "Pointer to route-map entries\n") | |
9104 | { | |
a3d826f0 | 9105 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 9106 | int idx_protocol = 1; |
9107 | int source; | |
9108 | int type = -1; | |
9109 | int metric = -1; | |
9110 | struct ospf_redist *red; | |
9111 | int idx = 0; | |
7bced643 | 9112 | bool update = false; |
6f2a6703 | 9113 | |
d62a17ae | 9114 | /* Get distribute source. */ |
9115 | source = proto_redistnum(AFI_IP, argv[idx_protocol]->text); | |
9116 | if (source < 0) | |
9117 | return CMD_WARNING_CONFIG_FAILED; | |
9118 | ||
d62a17ae | 9119 | /* Get metric value. */ |
9120 | if (argv_find(argv, argc, "(0-16777214)", &idx)) { | |
9121 | if (!str2metric(argv[idx]->arg, &metric)) | |
9122 | return CMD_WARNING_CONFIG_FAILED; | |
9123 | } | |
951da435 | 9124 | idx = 1; |
d62a17ae | 9125 | /* Get metric type. */ |
ea38ced1 | 9126 | if (argv_find(argv, argc, "(1-2)", &idx)) { |
d62a17ae | 9127 | if (!str2metric_type(argv[idx]->arg, &type)) |
9128 | return CMD_WARNING_CONFIG_FAILED; | |
9129 | } | |
951da435 | 9130 | idx = 1; |
7bced643 IR |
9131 | |
9132 | red = ospf_redist_lookup(ospf, source, 0); | |
9133 | if (!red) | |
9134 | red = ospf_redist_add(ospf, source, 0); | |
9135 | else | |
9136 | update = true; | |
9137 | ||
d62a17ae | 9138 | /* Get route-map */ |
ea38ced1 | 9139 | if (argv_find(argv, argc, "WORD", &idx)) { |
d62a17ae | 9140 | ospf_routemap_set(red, argv[idx]->arg); |
9141 | } else | |
9142 | ospf_routemap_unset(red); | |
7c8ff89e | 9143 | |
7bced643 IR |
9144 | if (update) |
9145 | return ospf_redistribute_update(ospf, red, source, 0, type, | |
9146 | metric); | |
9147 | else | |
9148 | return ospf_redistribute_set(ospf, red, source, 0, type, | |
9149 | metric); | |
718e3744 | 9150 | } |
9151 | ||
718e3744 | 9152 | DEFUN (no_ospf_redistribute_source, |
9153 | no_ospf_redistribute_source_cmd, | |
ea38ced1 | 9154 | "no redistribute " FRR_REDIST_STR_OSPFD " [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]", |
718e3744 | 9155 | NO_STR |
d1c65c21 | 9156 | REDIST_STR |
ab0181ee | 9157 | FRR_REDIST_HELP_STR_OSPFD |
813d4307 DW |
9158 | "Metric for redistributed routes\n" |
9159 | "OSPF default metric\n" | |
9160 | "OSPF exterior metric type for redistributed routes\n" | |
7111c1a0 | 9161 | "Set OSPF External Type 1/2 metrics\n" |
813d4307 DW |
9162 | "Route map reference\n" |
9163 | "Pointer to route-map entries\n") | |
718e3744 | 9164 | { |
a3d826f0 | 9165 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 9166 | int idx_protocol = 2; |
9167 | int source; | |
9168 | struct ospf_redist *red; | |
718e3744 | 9169 | |
d62a17ae | 9170 | source = proto_redistnum(AFI_IP, argv[idx_protocol]->text); |
9171 | if (source < 0) | |
9172 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 9173 | |
d62a17ae | 9174 | red = ospf_redist_lookup(ospf, source, 0); |
9175 | if (!red) | |
9176 | return CMD_SUCCESS; | |
7c8ff89e | 9177 | |
d62a17ae | 9178 | ospf_routemap_unset(red); |
766b826f DA |
9179 | ospf_redist_del(ospf, source, 0); |
9180 | ||
d62a17ae | 9181 | return ospf_redistribute_unset(ospf, source, 0); |
7c8ff89e DS |
9182 | } |
9183 | ||
9184 | DEFUN (ospf_redistribute_instance_source, | |
9185 | ospf_redistribute_instance_source_cmd, | |
1a5ce38b | 9186 | "redistribute <ospf|table> (1-65535) [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]", |
7c8ff89e DS |
9187 | REDIST_STR |
9188 | "Open Shortest Path First\n" | |
2d627ff5 DS |
9189 | "Non-main Kernel Routing Table\n" |
9190 | "Instance ID/Table ID\n" | |
7c8ff89e DS |
9191 | "Metric for redistributed routes\n" |
9192 | "OSPF default metric\n" | |
9193 | "OSPF exterior metric type for redistributed routes\n" | |
7111c1a0 | 9194 | "Set OSPF External Type 1/2 metrics\n" |
7c8ff89e DS |
9195 | "Route map reference\n" |
9196 | "Pointer to route-map entries\n") | |
9197 | { | |
a3d826f0 | 9198 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 9199 | int idx_ospf_table = 1; |
9200 | int idx_number = 2; | |
9201 | int idx = 3; | |
9202 | int source; | |
9203 | int type = -1; | |
9204 | int metric = -1; | |
d7c0a89a | 9205 | unsigned short instance; |
d62a17ae | 9206 | struct ospf_redist *red; |
7bced643 | 9207 | bool update = false; |
7c8ff89e | 9208 | |
d62a17ae | 9209 | source = proto_redistnum(AFI_IP, argv[idx_ospf_table]->text); |
2d627ff5 | 9210 | |
13f0e434 | 9211 | if (source < 0) { |
9212 | vty_out(vty, "Unknown instance redistribution\n"); | |
9213 | return CMD_WARNING_CONFIG_FAILED; | |
9214 | } | |
9215 | ||
d62a17ae | 9216 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
7c8ff89e | 9217 | |
d62a17ae | 9218 | if ((source == ZEBRA_ROUTE_OSPF) && !ospf->instance) { |
9219 | vty_out(vty, | |
9220 | "Instance redistribution in non-instanced OSPF not allowed\n"); | |
9221 | return CMD_WARNING_CONFIG_FAILED; | |
9222 | } | |
7c8ff89e | 9223 | |
d62a17ae | 9224 | if ((source == ZEBRA_ROUTE_OSPF) && (ospf->instance == instance)) { |
9225 | vty_out(vty, "Same instance OSPF redistribution not allowed\n"); | |
9226 | return CMD_WARNING_CONFIG_FAILED; | |
9227 | } | |
7c8ff89e | 9228 | |
d62a17ae | 9229 | /* Get metric value. */ |
9230 | if (argv_find(argv, argc, "metric", &idx)) | |
9231 | if (!str2metric(argv[idx + 1]->arg, &metric)) | |
9232 | return CMD_WARNING_CONFIG_FAILED; | |
7c8ff89e | 9233 | |
d62a17ae | 9234 | idx = 3; |
9235 | /* Get metric type. */ | |
9236 | if (argv_find(argv, argc, "metric-type", &idx)) | |
9237 | if (!str2metric_type(argv[idx + 1]->arg, &type)) | |
9238 | return CMD_WARNING_CONFIG_FAILED; | |
7c8ff89e | 9239 | |
7bced643 IR |
9240 | red = ospf_redist_lookup(ospf, source, instance); |
9241 | if (!red) | |
9242 | red = ospf_redist_add(ospf, source, instance); | |
9243 | else | |
9244 | update = true; | |
7a7be519 | 9245 | |
d62a17ae | 9246 | idx = 3; |
9247 | if (argv_find(argv, argc, "route-map", &idx)) | |
9248 | ospf_routemap_set(red, argv[idx + 1]->arg); | |
9249 | else | |
9250 | ospf_routemap_unset(red); | |
7c8ff89e | 9251 | |
7bced643 IR |
9252 | if (update) |
9253 | return ospf_redistribute_update(ospf, red, source, instance, | |
9254 | type, metric); | |
9255 | else | |
9256 | return ospf_redistribute_set(ospf, red, source, instance, type, | |
9257 | metric); | |
7c8ff89e DS |
9258 | } |
9259 | ||
9260 | DEFUN (no_ospf_redistribute_instance_source, | |
9261 | no_ospf_redistribute_instance_source_cmd, | |
1a5ce38b | 9262 | "no redistribute <ospf|table> (1-65535) [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]", |
7c8ff89e DS |
9263 | NO_STR |
9264 | REDIST_STR | |
9265 | "Open Shortest Path First\n" | |
2d627ff5 DS |
9266 | "Non-main Kernel Routing Table\n" |
9267 | "Instance ID/Table Id\n" | |
7c8ff89e DS |
9268 | "Metric for redistributed routes\n" |
9269 | "OSPF default metric\n" | |
9270 | "OSPF exterior metric type for redistributed routes\n" | |
7111c1a0 | 9271 | "Set OSPF External Type 1/2 metrics\n" |
7c8ff89e DS |
9272 | "Route map reference\n" |
9273 | "Pointer to route-map entries\n") | |
9274 | { | |
a3d826f0 | 9275 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 9276 | int idx_ospf_table = 2; |
9277 | int idx_number = 3; | |
d7c0a89a | 9278 | unsigned int instance; |
d62a17ae | 9279 | struct ospf_redist *red; |
9280 | int source; | |
9281 | ||
9282 | if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0) | |
9283 | source = ZEBRA_ROUTE_OSPF; | |
9284 | else | |
9285 | source = ZEBRA_ROUTE_TABLE; | |
9286 | ||
9287 | instance = strtoul(argv[idx_number]->arg, NULL, 10); | |
7c8ff89e | 9288 | |
d62a17ae | 9289 | if ((source == ZEBRA_ROUTE_OSPF) && !ospf->instance) { |
9290 | vty_out(vty, | |
9291 | "Instance redistribution in non-instanced OSPF not allowed\n"); | |
9292 | return CMD_WARNING_CONFIG_FAILED; | |
9293 | } | |
9294 | ||
9295 | if ((source == ZEBRA_ROUTE_OSPF) && (ospf->instance == instance)) { | |
9296 | vty_out(vty, "Same instance OSPF redistribution not allowed\n"); | |
9297 | return CMD_WARNING_CONFIG_FAILED; | |
9298 | } | |
9299 | ||
9300 | red = ospf_redist_lookup(ospf, source, instance); | |
9301 | if (!red) | |
9302 | return CMD_SUCCESS; | |
9303 | ||
9304 | ospf_routemap_unset(red); | |
766b826f DA |
9305 | ospf_redist_del(ospf, source, instance); |
9306 | ||
d62a17ae | 9307 | return ospf_redistribute_unset(ospf, source, instance); |
718e3744 | 9308 | } |
9309 | ||
9310 | DEFUN (ospf_distribute_list_out, | |
9311 | ospf_distribute_list_out_cmd, | |
40d1cbfb | 9312 | "distribute-list WORD out " FRR_REDIST_STR_OSPFD, |
718e3744 | 9313 | "Filter networks in routing updates\n" |
6f2a6703 CF |
9314 | "Access-list name\n" |
9315 | OUT_STR | |
ab0181ee | 9316 | FRR_REDIST_HELP_STR_OSPFD) |
718e3744 | 9317 | { |
a3d826f0 | 9318 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 9319 | int idx_word = 1; |
9320 | int source; | |
718e3744 | 9321 | |
d62a17ae | 9322 | char *proto = argv[argc - 1]->text; |
6d681bd8 | 9323 | |
d62a17ae | 9324 | /* Get distribute source. */ |
9325 | source = proto_redistnum(AFI_IP, proto); | |
9326 | if (source < 0) | |
9327 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 9328 | |
d62a17ae | 9329 | return ospf_distribute_list_out_set(ospf, source, argv[idx_word]->arg); |
718e3744 | 9330 | } |
9331 | ||
6f2a6703 CF |
9332 | DEFUN (no_ospf_distribute_list_out, |
9333 | no_ospf_distribute_list_out_cmd, | |
40d1cbfb | 9334 | "no distribute-list WORD out " FRR_REDIST_STR_OSPFD, |
6f2a6703 CF |
9335 | NO_STR |
9336 | "Filter networks in routing updates\n" | |
9337 | "Access-list name\n" | |
9338 | OUT_STR | |
ab0181ee | 9339 | FRR_REDIST_HELP_STR_OSPFD) |
718e3744 | 9340 | { |
a3d826f0 | 9341 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 9342 | int idx_word = 2; |
9343 | int source; | |
020709f9 | 9344 | |
d62a17ae | 9345 | char *proto = argv[argc - 1]->text; |
9346 | source = proto_redistnum(AFI_IP, proto); | |
9347 | if (source < 0) | |
9348 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 9349 | |
d62a17ae | 9350 | return ospf_distribute_list_out_unset(ospf, source, |
9351 | argv[idx_word]->arg); | |
718e3744 | 9352 | } |
9353 | ||
6f2a6703 CF |
9354 | /* Default information originate. */ |
9355 | DEFUN (ospf_default_information_originate, | |
9356 | ospf_default_information_originate_cmd, | |
ea38ced1 | 9357 | "default-information originate [{always|metric (0-16777214)|metric-type (1-2)|route-map WORD}]", |
718e3744 | 9358 | "Control distribution of default information\n" |
9359 | "Distribute a default route\n" | |
9360 | "Always advertise default route\n" | |
6f2a6703 CF |
9361 | "OSPF default metric\n" |
9362 | "OSPF metric\n" | |
718e3744 | 9363 | "OSPF metric type for default routes\n" |
7111c1a0 | 9364 | "Set OSPF External Type 1/2 metrics\n" |
718e3744 | 9365 | "Route map reference\n" |
9366 | "Pointer to route-map entries\n") | |
9367 | { | |
a3d826f0 | 9368 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 9369 | int default_originate = DEFAULT_ORIGINATE_ZEBRA; |
9370 | int type = -1; | |
9371 | int metric = -1; | |
9372 | struct ospf_redist *red; | |
9373 | int idx = 0; | |
1fb93326 | 9374 | int cur_originate = ospf->default_originate; |
9375 | int sameRtmap = 0; | |
9376 | char *rtmap = NULL; | |
d62a17ae | 9377 | |
9378 | red = ospf_redist_add(ospf, DEFAULT_ROUTE, 0); | |
9379 | ||
9380 | /* Check whether "always" was specified */ | |
9381 | if (argv_find(argv, argc, "always", &idx)) | |
9382 | default_originate = DEFAULT_ORIGINATE_ALWAYS; | |
951da435 | 9383 | idx = 1; |
d62a17ae | 9384 | /* Get metric value */ |
ea38ced1 | 9385 | if (argv_find(argv, argc, "(0-16777214)", &idx)) { |
d62a17ae | 9386 | if (!str2metric(argv[idx]->arg, &metric)) |
9387 | return CMD_WARNING_CONFIG_FAILED; | |
9388 | } | |
951da435 | 9389 | idx = 1; |
d62a17ae | 9390 | /* Get metric type. */ |
ea38ced1 | 9391 | if (argv_find(argv, argc, "(1-2)", &idx)) { |
d62a17ae | 9392 | if (!str2metric_type(argv[idx]->arg, &type)) |
9393 | return CMD_WARNING_CONFIG_FAILED; | |
9394 | } | |
951da435 | 9395 | idx = 1; |
d62a17ae | 9396 | /* Get route-map */ |
ea38ced1 | 9397 | if (argv_find(argv, argc, "WORD", &idx)) |
1fb93326 | 9398 | rtmap = argv[idx]->arg; |
9399 | ||
9400 | /* To check ,if user is providing same route map */ | |
9401 | if ((rtmap == ROUTEMAP_NAME(red)) || | |
9402 | (rtmap && ROUTEMAP_NAME(red) | |
9403 | && (strcmp(rtmap, ROUTEMAP_NAME(red)) == 0))) | |
9404 | sameRtmap = 1; | |
9405 | ||
9406 | /* Don't allow if the same lsa is aleardy originated. */ | |
9407 | if ((sameRtmap) | |
9408 | && (red->dmetric.type == type) | |
9409 | && (red->dmetric.value == metric) | |
9410 | && (cur_originate == default_originate)) | |
9411 | return CMD_SUCCESS; | |
9412 | ||
9413 | /* Updating Metric details */ | |
9414 | red->dmetric.type = type; | |
9415 | red->dmetric.value = metric; | |
9416 | ||
9417 | /* updating route map details */ | |
9418 | if (rtmap) | |
9419 | ospf_routemap_set(red, rtmap); | |
d62a17ae | 9420 | else |
9421 | ospf_routemap_unset(red); | |
9422 | ||
9423 | return ospf_redistribute_default_set(ospf, default_originate, type, | |
9424 | metric); | |
718e3744 | 9425 | } |
9426 | ||
9427 | DEFUN (no_ospf_default_information_originate, | |
9428 | no_ospf_default_information_originate_cmd, | |
ea38ced1 | 9429 | "no default-information originate [{always|metric (0-16777214)|metric-type (1-2)|route-map WORD}]", |
718e3744 | 9430 | NO_STR |
9431 | "Control distribution of default information\n" | |
813d4307 DW |
9432 | "Distribute a default route\n" |
9433 | "Always advertise default route\n" | |
9434 | "OSPF default metric\n" | |
9435 | "OSPF metric\n" | |
9436 | "OSPF metric type for default routes\n" | |
7111c1a0 | 9437 | "Set OSPF External Type 1/2 metrics\n" |
813d4307 DW |
9438 | "Route map reference\n" |
9439 | "Pointer to route-map entries\n") | |
718e3744 | 9440 | { |
a3d826f0 | 9441 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 9442 | struct ospf_redist *red; |
7c8ff89e | 9443 | |
d62a17ae | 9444 | red = ospf_redist_lookup(ospf, DEFAULT_ROUTE, 0); |
9445 | if (!red) | |
9446 | return CMD_SUCCESS; | |
7c8ff89e | 9447 | |
d62a17ae | 9448 | ospf_routemap_unset(red); |
766b826f DA |
9449 | ospf_redist_del(ospf, DEFAULT_ROUTE, 0); |
9450 | ||
d5eac1e0 DL |
9451 | return ospf_redistribute_default_set(ospf, DEFAULT_ORIGINATE_NONE, |
9452 | 0, 0); | |
718e3744 | 9453 | } |
9454 | ||
9455 | DEFUN (ospf_default_metric, | |
9456 | ospf_default_metric_cmd, | |
6147e2c6 | 9457 | "default-metric (0-16777214)", |
718e3744 | 9458 | "Set metric of redistributed routes\n" |
9459 | "Default metric\n") | |
9460 | { | |
a3d826f0 | 9461 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 9462 | int idx_number = 1; |
9463 | int metric = -1; | |
718e3744 | 9464 | |
d62a17ae | 9465 | if (!str2metric(argv[idx_number]->arg, &metric)) |
9466 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 9467 | |
d62a17ae | 9468 | ospf->default_metric = metric; |
718e3744 | 9469 | |
d62a17ae | 9470 | return CMD_SUCCESS; |
718e3744 | 9471 | } |
9472 | ||
9473 | DEFUN (no_ospf_default_metric, | |
9474 | no_ospf_default_metric_cmd, | |
7a7be519 | 9475 | "no default-metric [(0-16777214)]", |
718e3744 | 9476 | NO_STR |
7a7be519 | 9477 | "Set metric of redistributed routes\n" |
9478 | "Default metric\n") | |
718e3744 | 9479 | { |
a3d826f0 | 9480 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
68980084 | 9481 | |
d62a17ae | 9482 | ospf->default_metric = -1; |
68980084 | 9483 | |
d62a17ae | 9484 | return CMD_SUCCESS; |
718e3744 | 9485 | } |
9486 | ||
718e3744 | 9487 | |
9488 | DEFUN (ospf_distance, | |
9489 | ospf_distance_cmd, | |
6147e2c6 | 9490 | "distance (1-255)", |
eaa1ae0d | 9491 | "Administrative distance\n" |
718e3744 | 9492 | "OSPF Administrative distance\n") |
9493 | { | |
a3d826f0 | 9494 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 9495 | int idx_number = 1; |
68980084 | 9496 | |
d62a17ae | 9497 | ospf->distance_all = atoi(argv[idx_number]->arg); |
68980084 | 9498 | |
d62a17ae | 9499 | return CMD_SUCCESS; |
718e3744 | 9500 | } |
9501 | ||
9502 | DEFUN (no_ospf_distance, | |
9503 | no_ospf_distance_cmd, | |
6147e2c6 | 9504 | "no distance (1-255)", |
718e3744 | 9505 | NO_STR |
eaa1ae0d | 9506 | "Administrative distance\n" |
718e3744 | 9507 | "OSPF Administrative distance\n") |
9508 | { | |
a3d826f0 | 9509 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
68980084 | 9510 | |
d62a17ae | 9511 | ospf->distance_all = 0; |
68980084 | 9512 | |
d62a17ae | 9513 | return CMD_SUCCESS; |
718e3744 | 9514 | } |
9515 | ||
9516 | DEFUN (no_ospf_distance_ospf, | |
9517 | no_ospf_distance_ospf_cmd, | |
eaa1ae0d | 9518 | "no distance ospf [{intra-area [(1-255)]|inter-area [(1-255)]|external [(1-255)]}]", |
718e3744 | 9519 | NO_STR |
eaa1ae0d QY |
9520 | "Administrative distance\n" |
9521 | "OSPF administrative distance\n" | |
718e3744 | 9522 | "Intra-area routes\n" |
813d4307 | 9523 | "Distance for intra-area routes\n" |
718e3744 | 9524 | "Inter-area routes\n" |
813d4307 DW |
9525 | "Distance for inter-area routes\n" |
9526 | "External routes\n" | |
9527 | "Distance for external routes\n") | |
718e3744 | 9528 | { |
a3d826f0 | 9529 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 9530 | int idx = 0; |
718e3744 | 9531 | |
d62a17ae | 9532 | if (argv_find(argv, argc, "intra-area", &idx) || argc == 3) |
9533 | idx = ospf->distance_intra = 0; | |
9534 | if (argv_find(argv, argc, "inter-area", &idx) || argc == 3) | |
9535 | idx = ospf->distance_inter = 0; | |
9536 | if (argv_find(argv, argc, "external", &idx) || argc == 3) | |
9537 | ospf->distance_external = 0; | |
718e3744 | 9538 | |
d62a17ae | 9539 | return CMD_SUCCESS; |
718e3744 | 9540 | } |
9541 | ||
6f2a6703 CF |
9542 | DEFUN (ospf_distance_ospf, |
9543 | ospf_distance_ospf_cmd, | |
eaa1ae0d QY |
9544 | "distance ospf {intra-area (1-255)|inter-area (1-255)|external (1-255)}", |
9545 | "Administrative distance\n" | |
9546 | "OSPF administrative distance\n" | |
718e3744 | 9547 | "Intra-area routes\n" |
9548 | "Distance for intra-area routes\n" | |
718e3744 | 9549 | "Inter-area routes\n" |
9550 | "Distance for inter-area routes\n" | |
9551 | "External routes\n" | |
718e3744 | 9552 | "Distance for external routes\n") |
9553 | { | |
a3d826f0 | 9554 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 9555 | int idx = 0; |
68980084 | 9556 | |
926b88f0 CS |
9557 | ospf->distance_intra = 0; |
9558 | ospf->distance_inter = 0; | |
9559 | ospf->distance_external = 0; | |
9560 | ||
d62a17ae | 9561 | if (argv_find(argv, argc, "intra-area", &idx)) |
9562 | ospf->distance_intra = atoi(argv[idx + 1]->arg); | |
9563 | idx = 0; | |
9564 | if (argv_find(argv, argc, "inter-area", &idx)) | |
9565 | ospf->distance_inter = atoi(argv[idx + 1]->arg); | |
9566 | idx = 0; | |
9567 | if (argv_find(argv, argc, "external", &idx)) | |
9568 | ospf->distance_external = atoi(argv[idx + 1]->arg); | |
68980084 | 9569 | |
d62a17ae | 9570 | return CMD_SUCCESS; |
718e3744 | 9571 | } |
9572 | ||
ba682537 | 9573 | DEFUN (ip_ospf_mtu_ignore, |
9574 | ip_ospf_mtu_ignore_addr_cmd, | |
7a7be519 | 9575 | "ip ospf mtu-ignore [A.B.C.D]", |
ba682537 | 9576 | "IP Information\n" |
9577 | "OSPF interface commands\n" | |
99a522c7 | 9578 | "Disable MTU mismatch detection on this interface\n" |
efd7904e | 9579 | "Address of interface\n") |
ba682537 | 9580 | { |
d62a17ae | 9581 | VTY_DECLVAR_CONTEXT(interface, ifp); |
9582 | int idx_ipv4 = 3; | |
9583 | struct in_addr addr; | |
9584 | int ret; | |
9585 | ||
9586 | struct ospf_if_params *params; | |
9587 | params = IF_DEF_PARAMS(ifp); | |
9588 | ||
9589 | if (argc == 4) { | |
9590 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
9591 | if (!ret) { | |
9592 | vty_out(vty, | |
9593 | "Please specify interface address by A.B.C.D\n"); | |
9594 | return CMD_WARNING_CONFIG_FAILED; | |
9595 | } | |
9596 | params = ospf_get_if_params(ifp, addr); | |
9597 | ospf_if_update_params(ifp, addr); | |
9598 | } | |
9599 | params->mtu_ignore = 1; | |
9600 | if (params->mtu_ignore != OSPF_MTU_IGNORE_DEFAULT) | |
9601 | SET_IF_PARAM(params, mtu_ignore); | |
9602 | else { | |
9603 | UNSET_IF_PARAM(params, mtu_ignore); | |
9604 | if (params != IF_DEF_PARAMS(ifp)) { | |
9605 | ospf_free_if_params(ifp, addr); | |
9606 | ospf_if_update_params(ifp, addr); | |
9607 | } | |
9608 | } | |
9609 | return CMD_SUCCESS; | |
ba682537 | 9610 | } |
9611 | ||
ba682537 | 9612 | DEFUN (no_ip_ospf_mtu_ignore, |
9613 | no_ip_ospf_mtu_ignore_addr_cmd, | |
7a7be519 | 9614 | "no ip ospf mtu-ignore [A.B.C.D]", |
efd7904e | 9615 | NO_STR |
ba682537 | 9616 | "IP Information\n" |
9617 | "OSPF interface commands\n" | |
99a522c7 | 9618 | "Disable MTU mismatch detection on this interface\n" |
efd7904e | 9619 | "Address of interface\n") |
ba682537 | 9620 | { |
d62a17ae | 9621 | VTY_DECLVAR_CONTEXT(interface, ifp); |
9622 | int idx_ipv4 = 4; | |
9623 | struct in_addr addr; | |
9624 | int ret; | |
9625 | ||
9626 | struct ospf_if_params *params; | |
9627 | params = IF_DEF_PARAMS(ifp); | |
9628 | ||
9629 | if (argc == 5) { | |
9630 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
9631 | if (!ret) { | |
9632 | vty_out(vty, | |
9633 | "Please specify interface address by A.B.C.D\n"); | |
9634 | return CMD_WARNING_CONFIG_FAILED; | |
9635 | } | |
9636 | params = ospf_get_if_params(ifp, addr); | |
9637 | ospf_if_update_params(ifp, addr); | |
9638 | } | |
9639 | params->mtu_ignore = 0; | |
9640 | if (params->mtu_ignore != OSPF_MTU_IGNORE_DEFAULT) | |
9641 | SET_IF_PARAM(params, mtu_ignore); | |
9642 | else { | |
9643 | UNSET_IF_PARAM(params, mtu_ignore); | |
9644 | if (params != IF_DEF_PARAMS(ifp)) { | |
9645 | ospf_free_if_params(ifp, addr); | |
9646 | ospf_if_update_params(ifp, addr); | |
9647 | } | |
9648 | } | |
9649 | return CMD_SUCCESS; | |
ba682537 | 9650 | } |
9651 | ||
6b0655a2 | 9652 | |
88d6cf37 | 9653 | DEFUN (ospf_max_metric_router_lsa_admin, |
9654 | ospf_max_metric_router_lsa_admin_cmd, | |
9655 | "max-metric router-lsa administrative", | |
9656 | "OSPF maximum / infinite-distance metric\n" | |
9657 | "Advertise own Router-LSA with infinite distance (stub router)\n" | |
9658 | "Administratively applied, for an indefinite period\n") | |
9659 | { | |
a3d826f0 | 9660 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 9661 | struct listnode *ln; |
9662 | struct ospf_area *area; | |
7c8ff89e | 9663 | |
d62a17ae | 9664 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, ln, area)) { |
9665 | SET_FLAG(area->stub_router_state, OSPF_AREA_ADMIN_STUB_ROUTED); | |
4ba4fc85 | 9666 | |
d62a17ae | 9667 | if (!CHECK_FLAG(area->stub_router_state, |
9668 | OSPF_AREA_IS_STUB_ROUTED)) | |
9669 | ospf_router_lsa_update_area(area); | |
9670 | } | |
4ba4fc85 | 9671 | |
d62a17ae | 9672 | /* Allows for areas configured later to get the property */ |
9673 | ospf->stub_router_admin_set = OSPF_STUB_ROUTER_ADMINISTRATIVE_SET; | |
9674 | ||
9675 | return CMD_SUCCESS; | |
88d6cf37 | 9676 | } |
9677 | ||
9678 | DEFUN (no_ospf_max_metric_router_lsa_admin, | |
9679 | no_ospf_max_metric_router_lsa_admin_cmd, | |
9680 | "no max-metric router-lsa administrative", | |
9681 | NO_STR | |
9682 | "OSPF maximum / infinite-distance metric\n" | |
9683 | "Advertise own Router-LSA with infinite distance (stub router)\n" | |
9684 | "Administratively applied, for an indefinite period\n") | |
9685 | { | |
a3d826f0 | 9686 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 9687 | struct listnode *ln; |
9688 | struct ospf_area *area; | |
9689 | ||
9690 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, ln, area)) { | |
9691 | UNSET_FLAG(area->stub_router_state, | |
9692 | OSPF_AREA_ADMIN_STUB_ROUTED); | |
9693 | ||
9694 | /* Don't trample on the start-up stub timer */ | |
9695 | if (CHECK_FLAG(area->stub_router_state, | |
9696 | OSPF_AREA_IS_STUB_ROUTED) | |
9697 | && !area->t_stub_router) { | |
9698 | UNSET_FLAG(area->stub_router_state, | |
9699 | OSPF_AREA_IS_STUB_ROUTED); | |
9700 | ospf_router_lsa_update_area(area); | |
9701 | } | |
9702 | } | |
9703 | ospf->stub_router_admin_set = OSPF_STUB_ROUTER_ADMINISTRATIVE_UNSET; | |
9704 | return CMD_SUCCESS; | |
88d6cf37 | 9705 | } |
9706 | ||
9707 | DEFUN (ospf_max_metric_router_lsa_startup, | |
9708 | ospf_max_metric_router_lsa_startup_cmd, | |
6147e2c6 | 9709 | "max-metric router-lsa on-startup (5-86400)", |
88d6cf37 | 9710 | "OSPF maximum / infinite-distance metric\n" |
9711 | "Advertise own Router-LSA with infinite distance (stub router)\n" | |
9712 | "Automatically advertise stub Router-LSA on startup of OSPF\n" | |
9713 | "Time (seconds) to advertise self as stub-router\n") | |
9714 | { | |
a3d826f0 | 9715 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 9716 | int idx_number = 3; |
9717 | unsigned int seconds; | |
9718 | ||
b5a8894d | 9719 | if (argc < 4) { |
d62a17ae | 9720 | vty_out(vty, "%% Must supply stub-router period"); |
9721 | return CMD_WARNING_CONFIG_FAILED; | |
9722 | } | |
9723 | ||
9724 | seconds = strtoul(argv[idx_number]->arg, NULL, 10); | |
9725 | ||
9726 | ospf->stub_router_startup_time = seconds; | |
9727 | ||
9728 | return CMD_SUCCESS; | |
88d6cf37 | 9729 | } |
9730 | ||
9731 | DEFUN (no_ospf_max_metric_router_lsa_startup, | |
9732 | no_ospf_max_metric_router_lsa_startup_cmd, | |
7a7be519 | 9733 | "no max-metric router-lsa on-startup [(5-86400)]", |
88d6cf37 | 9734 | NO_STR |
9735 | "OSPF maximum / infinite-distance metric\n" | |
9736 | "Advertise own Router-LSA with infinite distance (stub router)\n" | |
813d4307 DW |
9737 | "Automatically advertise stub Router-LSA on startup of OSPF\n" |
9738 | "Time (seconds) to advertise self as stub-router\n") | |
88d6cf37 | 9739 | { |
a3d826f0 | 9740 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 9741 | struct listnode *ln; |
9742 | struct ospf_area *area; | |
9743 | ||
9744 | ospf->stub_router_startup_time = OSPF_STUB_ROUTER_UNCONFIGURED; | |
9745 | ||
9746 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, ln, area)) { | |
9747 | SET_FLAG(area->stub_router_state, | |
9748 | OSPF_AREA_WAS_START_STUB_ROUTED); | |
9749 | OSPF_TIMER_OFF(area->t_stub_router); | |
9750 | ||
9751 | /* Don't trample on admin stub routed */ | |
9752 | if (!CHECK_FLAG(area->stub_router_state, | |
9753 | OSPF_AREA_ADMIN_STUB_ROUTED)) { | |
9754 | UNSET_FLAG(area->stub_router_state, | |
9755 | OSPF_AREA_IS_STUB_ROUTED); | |
9756 | ospf_router_lsa_update_area(area); | |
9757 | } | |
9758 | } | |
9759 | return CMD_SUCCESS; | |
88d6cf37 | 9760 | } |
9761 | ||
a1afa410 | 9762 | |
88d6cf37 | 9763 | DEFUN (ospf_max_metric_router_lsa_shutdown, |
9764 | ospf_max_metric_router_lsa_shutdown_cmd, | |
6147e2c6 | 9765 | "max-metric router-lsa on-shutdown (5-100)", |
88d6cf37 | 9766 | "OSPF maximum / infinite-distance metric\n" |
9767 | "Advertise own Router-LSA with infinite distance (stub router)\n" | |
9768 | "Advertise stub-router prior to full shutdown of OSPF\n" | |
9769 | "Time (seconds) to wait till full shutdown\n") | |
9770 | { | |
a3d826f0 | 9771 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 9772 | int idx_number = 3; |
9773 | unsigned int seconds; | |
9774 | ||
b5a8894d | 9775 | if (argc < 4) { |
d62a17ae | 9776 | vty_out(vty, "%% Must supply stub-router shutdown period"); |
9777 | return CMD_WARNING_CONFIG_FAILED; | |
9778 | } | |
9779 | ||
9780 | seconds = strtoul(argv[idx_number]->arg, NULL, 10); | |
9781 | ||
9782 | ospf->stub_router_shutdown_time = seconds; | |
9783 | ||
9784 | return CMD_SUCCESS; | |
88d6cf37 | 9785 | } |
9786 | ||
9787 | DEFUN (no_ospf_max_metric_router_lsa_shutdown, | |
9788 | no_ospf_max_metric_router_lsa_shutdown_cmd, | |
7a7be519 | 9789 | "no max-metric router-lsa on-shutdown [(5-100)]", |
88d6cf37 | 9790 | NO_STR |
9791 | "OSPF maximum / infinite-distance metric\n" | |
9792 | "Advertise own Router-LSA with infinite distance (stub router)\n" | |
813d4307 DW |
9793 | "Advertise stub-router prior to full shutdown of OSPF\n" |
9794 | "Time (seconds) to wait till full shutdown\n") | |
88d6cf37 | 9795 | { |
a3d826f0 | 9796 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
7c8ff89e | 9797 | |
d62a17ae | 9798 | ospf->stub_router_shutdown_time = OSPF_STUB_ROUTER_UNCONFIGURED; |
9799 | ||
9800 | return CMD_SUCCESS; | |
88d6cf37 | 9801 | } |
9802 | ||
a92706bb JU |
9803 | DEFUN (ospf_proactive_arp, |
9804 | ospf_proactive_arp_cmd, | |
9805 | "proactive-arp", | |
9806 | "Allow sending ARP requests proactively\n") | |
9807 | { | |
9808 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
9809 | ||
9810 | ospf->proactive_arp = true; | |
9811 | ||
9812 | return CMD_SUCCESS; | |
9813 | } | |
9814 | ||
9815 | DEFUN (no_ospf_proactive_arp, | |
9816 | no_ospf_proactive_arp_cmd, | |
9817 | "no proactive-arp", | |
9818 | NO_STR | |
9819 | "Disallow sending ARP requests proactively\n") | |
9820 | { | |
9821 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
9822 | ||
9823 | ospf->proactive_arp = false; | |
9824 | ||
9825 | return CMD_SUCCESS; | |
9826 | } | |
9827 | ||
07b33add | 9828 | /* Graceful Restart HELPER Commands */ |
9829 | DEFPY(ospf_gr_helper_enable, ospf_gr_helper_enable_cmd, | |
859bce81 | 9830 | "graceful-restart helper enable [A.B.C.D$address]", |
07b33add | 9831 | "OSPF Graceful Restart\n" |
859bce81 | 9832 | "OSPF GR Helper\n" |
07b33add | 9833 | "Enable Helper support\n" |
859bce81 | 9834 | "Advertising Router-ID\n") |
07b33add | 9835 | { |
9836 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
07b33add | 9837 | |
859bce81 RW |
9838 | if (address_str) { |
9839 | ospf_gr_helper_support_set_per_routerid(ospf, &address, | |
9840 | OSPF_GR_TRUE); | |
07b33add | 9841 | return CMD_SUCCESS; |
9842 | } | |
9843 | ||
9844 | ospf_gr_helper_support_set(ospf, OSPF_GR_TRUE); | |
9845 | ||
9846 | return CMD_SUCCESS; | |
9847 | } | |
9848 | ||
9849 | DEFPY(no_ospf_gr_helper_enable, | |
9850 | no_ospf_gr_helper_enable_cmd, | |
859bce81 | 9851 | "no graceful-restart helper enable [A.B.C.D$address]", |
07b33add | 9852 | NO_STR |
9853 | "OSPF Graceful Restart\n" | |
859bce81 RW |
9854 | "OSPF GR Helper\n" |
9855 | "Enable Helper support\n" | |
9856 | "Advertising Router-ID\n") | |
9857 | { | |
9858 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
9859 | ||
9860 | if (address_str) { | |
9861 | ospf_gr_helper_support_set_per_routerid(ospf, &address, | |
9862 | OSPF_GR_FALSE); | |
9863 | return CMD_SUCCESS; | |
9864 | } | |
9865 | ||
9866 | ospf_gr_helper_support_set(ospf, OSPF_GR_FALSE); | |
9867 | return CMD_SUCCESS; | |
9868 | } | |
9869 | ||
9870 | #if CONFDATE > 20220921 | |
9871 | CPP_NOTICE( | |
9872 | "Time to remove the deprecated \"[no] graceful-restart helper-only\" commands") | |
9873 | #endif | |
9874 | ||
9875 | DEFPY_HIDDEN(ospf_gr_helper_only, ospf_gr_helper_only_cmd, | |
9876 | "graceful-restart helper-only [A.B.C.D]", | |
9877 | "OSPF Graceful Restart\n" | |
9878 | "Enable Helper support\n" | |
07b33add | 9879 | "Advertising router id\n") |
9880 | { | |
9881 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
9882 | struct in_addr addr; | |
9883 | int ret; | |
9884 | ||
859bce81 RW |
9885 | vty_out(vty, |
9886 | "%% This command is deprecated. Please, use `graceful-restart helper enable` instead.\n"); | |
9887 | ||
9888 | if (argc == 3) { | |
9889 | ret = inet_aton(argv[2]->arg, &addr); | |
07b33add | 9890 | if (!ret) { |
9891 | vty_out(vty, | |
9892 | "Please specify the valid routerid address.\n"); | |
9893 | return CMD_WARNING_CONFIG_FAILED; | |
9894 | } | |
9895 | ||
859bce81 | 9896 | ospf_gr_helper_support_set_per_routerid(ospf, &addr, OSPF_GR_TRUE); |
07b33add | 9897 | return CMD_SUCCESS; |
9898 | } | |
9899 | ||
859bce81 RW |
9900 | ospf_gr_helper_support_set(ospf, OSPF_GR_TRUE); |
9901 | ||
07b33add | 9902 | return CMD_SUCCESS; |
9903 | } | |
9904 | ||
859bce81 RW |
9905 | ALIAS_HIDDEN(no_ospf_gr_helper_enable, |
9906 | no_ospf_gr_helper_only_cmd, | |
9907 | "no graceful-restart helper-only [A.B.C.D]", | |
9908 | NO_STR | |
9909 | "OSPF Graceful Restart\n" | |
9910 | "Disable Helper support\n" | |
9911 | "Advertising router id\n") | |
9912 | ||
07b33add | 9913 | DEFPY(ospf_gr_helper_enable_lsacheck, |
9914 | ospf_gr_helper_enable_lsacheck_cmd, | |
9915 | "graceful-restart helper strict-lsa-checking", | |
9916 | "OSPF Graceful Restart\n" | |
9917 | "OSPF GR Helper\n" | |
9918 | "Enable strict LSA check\n") | |
9919 | { | |
9920 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
9921 | ||
9922 | ospf_gr_helper_lsa_check_set(ospf, OSPF_GR_TRUE); | |
9923 | return CMD_SUCCESS; | |
9924 | } | |
9925 | ||
9926 | DEFPY(no_ospf_gr_helper_enable_lsacheck, | |
9927 | no_ospf_gr_helper_enable_lsacheck_cmd, | |
9928 | "no graceful-restart helper strict-lsa-checking", | |
9929 | NO_STR | |
9930 | "OSPF Graceful Restart\n" | |
9931 | "OSPF GR Helper\n" | |
9932 | "Disable strict LSA check\n") | |
9933 | { | |
9934 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
9935 | ||
9936 | ospf_gr_helper_lsa_check_set(ospf, OSPF_GR_FALSE); | |
9937 | return CMD_SUCCESS; | |
9938 | } | |
9939 | ||
9940 | DEFPY(ospf_gr_helper_supported_grace_time, | |
9941 | ospf_gr_helper_supported_grace_time_cmd, | |
9942 | "graceful-restart helper supported-grace-time (10-1800)$interval", | |
9943 | "OSPF Graceful Restart\n" | |
9944 | "OSPF GR Helper\n" | |
9945 | "Supported grace timer\n" | |
9946 | "Grace interval(in seconds)\n") | |
9947 | { | |
9948 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
9949 | ||
9950 | ospf_gr_helper_supported_gracetime_set(ospf, interval); | |
9951 | return CMD_SUCCESS; | |
9952 | } | |
9953 | ||
9954 | DEFPY(no_ospf_gr_helper_supported_grace_time, | |
9955 | no_ospf_gr_helper_supported_grace_time_cmd, | |
9956 | "no graceful-restart helper supported-grace-time (10-1800)$interval", | |
9957 | NO_STR | |
9958 | "OSPF Graceful Restart\n" | |
9959 | "OSPF GR Helper\n" | |
9960 | "Supported grace timer\n" | |
9961 | "Grace interval(in seconds)\n") | |
9962 | { | |
9963 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
9964 | ||
9965 | ospf_gr_helper_supported_gracetime_set(ospf, OSPF_MAX_GRACE_INTERVAL); | |
9966 | return CMD_SUCCESS; | |
9967 | } | |
9968 | ||
9969 | DEFPY(ospf_gr_helper_planned_only, | |
9970 | ospf_gr_helper_planned_only_cmd, | |
9971 | "graceful-restart helper planned-only", | |
9972 | "OSPF Graceful Restart\n" | |
9973 | "OSPF GR Helper\n" | |
9974 | "Supported only planned restart\n") | |
9975 | { | |
9976 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
9977 | ||
9978 | ospf_gr_helper_set_supported_planned_only_restart(ospf, OSPF_GR_TRUE); | |
9979 | ||
9980 | return CMD_SUCCESS; | |
9981 | } | |
9982 | ||
423e71c4 | 9983 | /* External Route Aggregation */ |
9984 | DEFUN (ospf_external_route_aggregation, | |
9985 | ospf_external_route_aggregation_cmd, | |
9986 | "summary-address A.B.C.D/M [tag (1-4294967295)]", | |
9987 | "External summary address\n" | |
9988 | "Summary address prefix (a.b.c.d/m) \n" | |
9989 | "Router tag \n" | |
9990 | "Router tag value\n") | |
9991 | { | |
9992 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
9993 | struct prefix_ipv4 p; | |
9994 | int idx = 1; | |
9995 | route_tag_t tag = 0; | |
9996 | int ret = OSPF_SUCCESS; | |
9997 | ||
9998 | str2prefix_ipv4(argv[idx]->arg, &p); | |
9999 | ||
1fe59b44 | 10000 | if (is_default_prefix4(&p)) { |
423e71c4 | 10001 | vty_out(vty, |
10002 | "Default address shouldn't be configured as summary address.\n"); | |
10003 | return CMD_SUCCESS; | |
10004 | } | |
10005 | ||
10006 | /* Apply mask for given prefix. */ | |
10007 | apply_mask((struct prefix *)&p); | |
10008 | ||
10009 | if (!is_valid_summary_addr(&p)) { | |
10010 | vty_out(vty, "Not a valid summary address.\n"); | |
10011 | return CMD_WARNING_CONFIG_FAILED; | |
10012 | } | |
10013 | ||
10014 | if (argc > 2) | |
10015 | tag = strtoul(argv[idx + 2]->arg, NULL, 10); | |
10016 | ||
10017 | ret = ospf_asbr_external_aggregator_set(ospf, &p, tag); | |
10018 | if (ret == OSPF_INVALID) | |
10019 | vty_out(vty, "Inavlid configuration!!\n"); | |
10020 | ||
10021 | return CMD_SUCCESS; | |
10022 | } | |
10023 | ||
10024 | DEFUN (no_ospf_external_route_aggregation, | |
10025 | no_ospf_external_route_aggregation_cmd, | |
10026 | "no summary-address A.B.C.D/M [tag (1-4294967295)]", | |
10027 | NO_STR | |
10028 | "External summary address\n" | |
10029 | "Summary address prefix (a.b.c.d/m)\n" | |
10030 | "Router tag\n" | |
10031 | "Router tag value\n") | |
10032 | { | |
10033 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
10034 | struct prefix_ipv4 p; | |
10035 | int idx = 2; | |
10036 | route_tag_t tag = 0; | |
10037 | int ret = OSPF_SUCCESS; | |
10038 | ||
10039 | str2prefix_ipv4(argv[idx]->arg, &p); | |
10040 | ||
1fe59b44 | 10041 | if (is_default_prefix4(&p)) { |
423e71c4 | 10042 | vty_out(vty, |
10043 | "Default address shouldn't be configured as summary address.\n"); | |
10044 | return CMD_SUCCESS; | |
10045 | } | |
10046 | ||
10047 | /* Apply mask for given prefix. */ | |
10048 | apply_mask((struct prefix *)&p); | |
10049 | ||
10050 | if (!is_valid_summary_addr(&p)) { | |
10051 | vty_out(vty, "Not a valid summary address.\n"); | |
10052 | return CMD_WARNING_CONFIG_FAILED; | |
10053 | } | |
10054 | ||
10055 | if (argc > 3) | |
10056 | tag = strtoul(argv[idx + 2]->arg, NULL, 10); | |
10057 | ||
10058 | ret = ospf_asbr_external_aggregator_unset(ospf, &p, tag); | |
10059 | if (ret == OSPF_INVALID) | |
10060 | vty_out(vty, "Inavlid configuration!!\n"); | |
10061 | ||
10062 | return CMD_SUCCESS; | |
10063 | } | |
10064 | ||
07b33add | 10065 | DEFPY(no_ospf_gr_helper_planned_only, |
10066 | no_ospf_gr_helper_planned_only_cmd, | |
10067 | "no graceful-restart helper planned-only", | |
10068 | NO_STR | |
10069 | "OSPF Graceful Restart\n" | |
10070 | "OSPF GR Helper\n" | |
10071 | "Supported only for planned restart\n") | |
10072 | { | |
10073 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
10074 | ||
10075 | ospf_gr_helper_set_supported_planned_only_restart(ospf, OSPF_GR_FALSE); | |
10076 | ||
10077 | return CMD_SUCCESS; | |
10078 | } | |
abd5b8c7 | 10079 | |
1ac88792 | 10080 | static int ospf_print_vty_helper_dis_rtr_walkcb(struct hash_bucket *bucket, |
abd5b8c7 | 10081 | void *arg) |
10082 | { | |
1ac88792 | 10083 | struct advRtr *rtr = bucket->data; |
abd5b8c7 | 10084 | struct vty *vty = (struct vty *)arg; |
10085 | static unsigned int count; | |
10086 | ||
96b663a3 | 10087 | vty_out(vty, "%-6pI4,", &rtr->advRtrAddr); |
abd5b8c7 | 10088 | count++; |
10089 | ||
10090 | if (count % 5 == 0) | |
10091 | vty_out(vty, "\n"); | |
10092 | ||
10093 | return HASHWALK_CONTINUE; | |
10094 | } | |
10095 | ||
10096 | static int ospf_show_gr_helper_details(struct vty *vty, struct ospf *ospf, | |
10097 | uint8_t use_vrf, json_object *json, | |
10098 | bool uj, bool detail) | |
10099 | { | |
10100 | struct listnode *node; | |
10101 | struct ospf_interface *oi; | |
96b663a3 | 10102 | char buf[PREFIX_STRLEN]; |
abd5b8c7 | 10103 | json_object *json_vrf = NULL; |
10104 | ||
10105 | if (uj) { | |
10106 | if (use_vrf) | |
10107 | json_vrf = json_object_new_object(); | |
10108 | else | |
10109 | json_vrf = json; | |
10110 | } | |
10111 | ||
10112 | if (ospf->instance) { | |
10113 | if (uj) | |
10114 | json_object_int_add(json, "ospfInstance", | |
10115 | ospf->instance); | |
10116 | else | |
10117 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
10118 | } | |
10119 | ||
10120 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); | |
10121 | ||
10122 | if (uj) { | |
44076f4d RW |
10123 | if (use_vrf) |
10124 | json_object_object_add(json, ospf_get_name(ospf), | |
10125 | json_vrf); | |
abd5b8c7 | 10126 | } else |
10127 | vty_out(vty, "\n"); | |
10128 | ||
10129 | /* Show Router ID. */ | |
10130 | if (uj) { | |
10131 | json_object_string_add(json_vrf, "routerId", | |
96b663a3 MS |
10132 | inet_ntop(AF_INET, &ospf->router_id, |
10133 | buf, sizeof(buf))); | |
abd5b8c7 | 10134 | } else { |
96b663a3 MS |
10135 | vty_out(vty, "\n OSPF Router with ID (%pI4)\n\n", |
10136 | &ospf->router_id); | |
abd5b8c7 | 10137 | } |
10138 | ||
10139 | if (!uj) { | |
10140 | ||
10141 | if (ospf->is_helper_supported) | |
10142 | vty_out(vty, | |
10143 | " Graceful restart helper support enabled.\n"); | |
10144 | else | |
10145 | vty_out(vty, | |
10146 | " Graceful restart helper support disabled.\n"); | |
10147 | ||
10148 | if (ospf->strict_lsa_check) | |
10149 | vty_out(vty, " Strict LSA check is enabled.\n"); | |
10150 | else | |
10151 | vty_out(vty, " Strict LSA check is disabled.\n"); | |
10152 | ||
10153 | if (ospf->only_planned_restart) | |
10154 | vty_out(vty, | |
10155 | " Helper supported for planned restarts only.\n"); | |
10156 | else | |
10157 | vty_out(vty, | |
10158 | " Helper supported for Planned and Unplanned Restarts.\n"); | |
10159 | ||
10160 | vty_out(vty, | |
10161 | " Supported Graceful restart interval: %d(in seconds).\n", | |
10162 | ospf->supported_grace_time); | |
10163 | ||
10164 | if (OSPF_HELPER_ENABLE_RTR_COUNT(ospf)) { | |
10165 | vty_out(vty, " Enable Router list:\n"); | |
10166 | vty_out(vty, " "); | |
10167 | hash_walk(ospf->enable_rtr_list, | |
10168 | ospf_print_vty_helper_dis_rtr_walkcb, vty); | |
10169 | vty_out(vty, "\n\n"); | |
10170 | } | |
10171 | ||
10172 | if (ospf->last_exit_reason != OSPF_GR_HELPER_EXIT_NONE) { | |
10173 | vty_out(vty, " Last Helper exit Reason :%s\n", | |
d05d5280 | 10174 | ospf_exit_reason2str(ospf->last_exit_reason)); |
abd5b8c7 | 10175 | } |
10176 | ||
10177 | if (ospf->active_restarter_cnt) | |
10178 | vty_out(vty, | |
10179 | " Number of Active neighbours in graceful restart: %d\n", | |
10180 | ospf->active_restarter_cnt); | |
10181 | else | |
10182 | vty_out(vty, "\n"); | |
10183 | ||
10184 | } else { | |
10185 | json_object_string_add( | |
10186 | json_vrf, "helperSupport", | |
10187 | (ospf->is_helper_supported) ? "Enabled" : "Disabled"); | |
10188 | json_object_string_add(json_vrf, "strictLsaCheck", | |
10189 | (ospf->strict_lsa_check) ? "Enabled" | |
10190 | : "Disabled"); | |
10191 | json_object_string_add( | |
10192 | json_vrf, "restartSupoort", | |
10193 | (ospf->only_planned_restart) | |
10194 | ? "Planned Restart only" | |
10195 | : "Planned and Unplanned Restarts"); | |
10196 | ||
10197 | json_object_int_add(json_vrf, "supportedGracePeriod", | |
10198 | ospf->supported_grace_time); | |
10199 | ||
10200 | if (ospf->last_exit_reason != OSPF_GR_HELPER_EXIT_NONE) | |
10201 | json_object_string_add( | |
10202 | json_vrf, "LastExitReason", | |
d05d5280 | 10203 | ospf_exit_reason2str(ospf->last_exit_reason)); |
abd5b8c7 | 10204 | |
10205 | if (ospf->active_restarter_cnt) | |
10206 | json_object_int_add(json_vrf, "activeRestarterCnt", | |
10207 | ospf->active_restarter_cnt); | |
10208 | } | |
10209 | ||
10210 | ||
10211 | if (detail) { | |
10212 | int cnt = 1; | |
10213 | json_object *json_neighbors = NULL; | |
10214 | ||
10215 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) { | |
10216 | struct route_node *rn; | |
10217 | struct ospf_neighbor *nbr; | |
10218 | json_object *json_neigh; | |
10219 | ||
10220 | if (ospf_interface_neighbor_count(oi) == 0) | |
10221 | continue; | |
10222 | ||
10223 | if (uj) { | |
10224 | json_object_object_get_ex(json_vrf, "Neighbors", | |
10225 | &json_neighbors); | |
10226 | if (!json_neighbors) { | |
10227 | json_neighbors = | |
10228 | json_object_new_object(); | |
10229 | json_object_object_add(json_vrf, | |
10230 | "Neighbors", | |
10231 | json_neighbors); | |
10232 | } | |
10233 | } | |
10234 | ||
10235 | for (rn = route_top(oi->nbrs); rn; | |
10236 | rn = route_next(rn)) { | |
10237 | ||
10238 | if (!rn->info) | |
10239 | continue; | |
10240 | ||
10241 | nbr = rn->info; | |
10242 | ||
10243 | if (!OSPF_GR_IS_ACTIVE_HELPER(nbr)) | |
10244 | continue; | |
10245 | ||
10246 | if (!uj) { | |
10247 | vty_out(vty, " Neighbour %d :\n", cnt); | |
96b663a3 MS |
10248 | vty_out(vty, " Address : %pI4\n", |
10249 | &nbr->address.u.prefix4); | |
10250 | vty_out(vty, " Routerid : %pI4\n", | |
10251 | &nbr->router_id); | |
abd5b8c7 | 10252 | vty_out(vty, |
10253 | " Received Grace period : %d(in seconds).\n", | |
10254 | nbr->gr_helper_info | |
10255 | .recvd_grace_period); | |
10256 | vty_out(vty, | |
10257 | " Actual Grace period : %d(in seconds)\n", | |
10258 | nbr->gr_helper_info | |
10259 | .actual_grace_period); | |
10260 | vty_out(vty, | |
10261 | " Remaining GraceTime:%ld(in seconds).\n", | |
10262 | thread_timer_remain_second( | |
10263 | nbr->gr_helper_info | |
10264 | .t_grace_timer)); | |
10265 | vty_out(vty, | |
10266 | " Graceful Restart reason: %s.\n\n", | |
d05d5280 MS |
10267 | ospf_restart_reason2str( |
10268 | nbr->gr_helper_info | |
10269 | .gr_restart_reason)); | |
abd5b8c7 | 10270 | cnt++; |
10271 | } else { | |
10272 | json_neigh = json_object_new_object(); | |
10273 | json_object_string_add( | |
10274 | json_neigh, "srcAddr", | |
96b663a3 MS |
10275 | inet_ntop(AF_INET, &nbr->src, |
10276 | buf, sizeof(buf))); | |
abd5b8c7 | 10277 | |
10278 | json_object_string_add( | |
10279 | json_neigh, "routerid", | |
96b663a3 MS |
10280 | inet_ntop(AF_INET, |
10281 | &nbr->router_id, | |
10282 | buf, sizeof(buf))); | |
abd5b8c7 | 10283 | json_object_int_add( |
10284 | json_neigh, | |
10285 | "recvdGraceInterval", | |
10286 | nbr->gr_helper_info | |
10287 | .recvd_grace_period); | |
10288 | json_object_int_add( | |
10289 | json_neigh, | |
10290 | "actualGraceInterval", | |
10291 | nbr->gr_helper_info | |
10292 | .actual_grace_period); | |
10293 | json_object_int_add( | |
10294 | json_neigh, "remainGracetime", | |
10295 | thread_timer_remain_second( | |
10296 | nbr->gr_helper_info | |
10297 | .t_grace_timer)); | |
10298 | json_object_string_add( | |
10299 | json_neigh, "restartReason", | |
d05d5280 MS |
10300 | ospf_restart_reason2str( |
10301 | nbr->gr_helper_info | |
10302 | .gr_restart_reason)); | |
abd5b8c7 | 10303 | json_object_object_add( |
10304 | json_neighbors, | |
96b663a3 MS |
10305 | inet_ntop(AF_INET, &nbr->src, |
10306 | buf, sizeof(buf)), | |
abd5b8c7 | 10307 | json_neigh); |
10308 | } | |
10309 | } | |
10310 | } | |
10311 | } | |
423e71c4 | 10312 | return CMD_SUCCESS; |
10313 | } | |
10314 | ||
10315 | DEFUN (ospf_external_route_aggregation_no_adrvertise, | |
10316 | ospf_external_route_aggregation_no_adrvertise_cmd, | |
10317 | "summary-address A.B.C.D/M no-advertise", | |
10318 | "External summary address\n" | |
10319 | "Summary address prefix (a.b.c.d/m) \n" | |
10320 | "Don't advertise summary route \n") | |
10321 | { | |
10322 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
10323 | struct prefix_ipv4 p; | |
10324 | int idx = 1; | |
10325 | int ret = OSPF_SUCCESS; | |
10326 | ||
10327 | str2prefix_ipv4(argv[idx]->arg, &p); | |
10328 | ||
1fe59b44 | 10329 | if (is_default_prefix4(&p)) { |
423e71c4 | 10330 | vty_out(vty, |
10331 | "Default address shouldn't be configured as summary address.\n"); | |
10332 | return CMD_SUCCESS; | |
10333 | } | |
10334 | ||
10335 | /* Apply mask for given prefix. */ | |
10336 | apply_mask((struct prefix *)&p); | |
10337 | ||
10338 | if (!is_valid_summary_addr(&p)) { | |
10339 | vty_out(vty, "Not a valid summary address.\n"); | |
10340 | return CMD_WARNING_CONFIG_FAILED; | |
10341 | } | |
10342 | ||
10343 | ret = ospf_asbr_external_rt_no_advertise(ospf, &p); | |
10344 | if (ret == OSPF_INVALID) | |
10345 | vty_out(vty, "Inavlid configuration!!\n"); | |
10346 | ||
10347 | return CMD_SUCCESS; | |
10348 | } | |
10349 | ||
10350 | DEFUN (no_ospf_external_route_aggregation_no_adrvertise, | |
10351 | no_ospf_external_route_aggregation_no_adrvertise_cmd, | |
10352 | "no summary-address A.B.C.D/M no-advertise", | |
10353 | NO_STR | |
10354 | "External summary address\n" | |
fbc48492 DS |
10355 | "Summary address prefix (a.b.c.d/m)\n" |
10356 | "Advertise summary route to the AS \n") | |
423e71c4 | 10357 | { |
10358 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
10359 | struct prefix_ipv4 p; | |
10360 | int idx = 2; | |
10361 | int ret = OSPF_SUCCESS; | |
10362 | ||
10363 | str2prefix_ipv4(argv[idx]->arg, &p); | |
10364 | ||
1fe59b44 | 10365 | if (is_default_prefix4(&p)) { |
423e71c4 | 10366 | vty_out(vty, |
10367 | "Default address shouldn't be configured as summary address.\n"); | |
10368 | return CMD_SUCCESS; | |
10369 | } | |
10370 | ||
10371 | /* Apply mask for given prefix. */ | |
10372 | apply_mask((struct prefix *)&p); | |
10373 | ||
10374 | if (!is_valid_summary_addr(&p)) { | |
10375 | vty_out(vty, "Not a valid summary address.\n"); | |
10376 | return CMD_WARNING_CONFIG_FAILED; | |
10377 | } | |
10378 | ||
10379 | ret = ospf_asbr_external_rt_advertise(ospf, &p); | |
10380 | if (ret == OSPF_INVALID) | |
10381 | vty_out(vty, "Inavlid configuration!!\n"); | |
10382 | ||
10383 | return CMD_SUCCESS; | |
10384 | } | |
10385 | ||
10386 | DEFUN (ospf_route_aggregation_timer, | |
10387 | ospf_route_aggregation_timer_cmd, | |
10388 | "aggregation timer (5-1800)", | |
10389 | "External route aggregation\n" | |
10390 | "Delay timer (in seconds)\n" | |
10391 | "Timer interval(in seconds)\n") | |
10392 | { | |
10393 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
10394 | unsigned int interval = 0; | |
10395 | ||
10396 | interval = strtoul(argv[2]->arg, NULL, 10); | |
10397 | ||
10398 | ospf_external_aggregator_timer_set(ospf, interval); | |
abd5b8c7 | 10399 | |
10400 | return CMD_SUCCESS; | |
10401 | } | |
10402 | ||
10403 | DEFPY (show_ip_ospf_gr_helper, | |
10404 | show_ip_ospf_gr_helper_cmd, | |
10405 | "show ip ospf [vrf <NAME|all>] graceful-restart helper [detail] [json]", | |
10406 | SHOW_STR | |
10407 | IP_STR | |
10408 | "OSPF information\n" | |
10409 | VRF_CMD_HELP_STR | |
10410 | "All VRFs\n" | |
10411 | "OSPF Graceful Restart\n" | |
10412 | "Helper details in the router\n" | |
10413 | "Detailed informtion\n" | |
10414 | JSON_STR) | |
10415 | { | |
10416 | char *vrf_name = NULL; | |
10417 | bool all_vrf = false; | |
10418 | int ret = CMD_SUCCESS; | |
10419 | int idx_vrf = 0; | |
10420 | int idx = 0; | |
10421 | uint8_t use_vrf = 0; | |
10422 | bool uj = use_json(argc, argv); | |
10423 | struct ospf *ospf = NULL; | |
10424 | json_object *json = NULL; | |
10425 | struct listnode *node = NULL; | |
10426 | int inst = 0; | |
10427 | bool detail = false; | |
10428 | ||
10429 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); | |
10430 | ||
10431 | if (argv_find(argv, argc, "detail", &idx)) | |
10432 | detail = true; | |
10433 | ||
10434 | if (uj) | |
10435 | json = json_object_new_object(); | |
10436 | ||
10437 | /* vrf input is provided */ | |
10438 | if (vrf_name) { | |
10439 | use_vrf = 1; | |
10440 | ||
10441 | if (all_vrf) { | |
10442 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
10443 | if (!ospf->oi_running) | |
10444 | continue; | |
10445 | ||
10446 | ret = ospf_show_gr_helper_details( | |
10447 | vty, ospf, use_vrf, json, uj, detail); | |
10448 | } | |
10449 | ||
10450 | if (uj) { | |
10451 | vty_out(vty, "%s\n", | |
10452 | json_object_to_json_string_ext( | |
10453 | json, JSON_C_TO_STRING_PRETTY)); | |
10454 | json_object_free(json); | |
10455 | } | |
10456 | ||
10457 | return ret; | |
10458 | } | |
10459 | ||
10460 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
10461 | ||
10462 | if (ospf == NULL || !ospf->oi_running) { | |
10463 | ||
10464 | if (uj) { | |
10465 | vty_out(vty, "%s\n", | |
10466 | json_object_to_json_string_ext( | |
10467 | json, JSON_C_TO_STRING_PRETTY)); | |
10468 | json_object_free(json); | |
10469 | } else | |
10470 | vty_out(vty, "%% OSPF instance not found\n"); | |
10471 | ||
10472 | return CMD_SUCCESS; | |
10473 | } | |
10474 | ||
10475 | } else { | |
10476 | /* Default Vrf */ | |
10477 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
10478 | ||
10479 | if (ospf == NULL || !ospf->oi_running) { | |
10480 | ||
10481 | if (uj) { | |
10482 | vty_out(vty, "%s\n", | |
10483 | json_object_to_json_string_ext( | |
10484 | json, JSON_C_TO_STRING_PRETTY)); | |
10485 | json_object_free(json); | |
10486 | } else | |
10487 | vty_out(vty, "%% OSPF instance not found\n"); | |
10488 | ||
10489 | return CMD_SUCCESS; | |
10490 | } | |
10491 | ||
10492 | ospf_show_gr_helper_details(vty, ospf, use_vrf, json, uj, | |
10493 | detail); | |
10494 | } | |
10495 | ||
10496 | if (uj) { | |
10497 | vty_out(vty, "%s\n", json_object_to_json_string_ext( | |
10498 | json, JSON_C_TO_STRING_PRETTY)); | |
10499 | json_object_free(json); | |
10500 | } | |
10501 | ||
10502 | return CMD_SUCCESS; | |
10503 | } | |
07b33add | 10504 | /* Graceful Restart HELPER commands end */ |
423e71c4 | 10505 | DEFUN (no_ospf_route_aggregation_timer, |
10506 | no_ospf_route_aggregation_timer_cmd, | |
10507 | "no aggregation timer", | |
10508 | NO_STR | |
10509 | "External route aggregation\n" | |
10510 | "Delay timer\n") | |
10511 | { | |
10512 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
10513 | ||
10514 | ospf_external_aggregator_timer_set(ospf, OSPF_EXTL_AGGR_DEFAULT_DELAY); | |
10515 | ||
10516 | return CMD_SUCCESS; | |
10517 | } | |
10518 | ||
10519 | /* External Route Aggregation End */ | |
07b33add | 10520 | |
d62a17ae | 10521 | static void config_write_stub_router(struct vty *vty, struct ospf *ospf) |
10522 | { | |
10523 | struct listnode *ln; | |
10524 | struct ospf_area *area; | |
10525 | ||
10526 | if (ospf->stub_router_startup_time != OSPF_STUB_ROUTER_UNCONFIGURED) | |
10527 | vty_out(vty, " max-metric router-lsa on-startup %u\n", | |
10528 | ospf->stub_router_startup_time); | |
10529 | if (ospf->stub_router_shutdown_time != OSPF_STUB_ROUTER_UNCONFIGURED) | |
10530 | vty_out(vty, " max-metric router-lsa on-shutdown %u\n", | |
10531 | ospf->stub_router_shutdown_time); | |
10532 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, ln, area)) { | |
10533 | if (CHECK_FLAG(area->stub_router_state, | |
10534 | OSPF_AREA_ADMIN_STUB_ROUTED)) { | |
10535 | vty_out(vty, " max-metric router-lsa administrative\n"); | |
10536 | break; | |
10537 | } | |
10538 | } | |
10539 | return; | |
10540 | } | |
10541 | ||
b5a8894d | 10542 | static void show_ip_ospf_route_network(struct vty *vty, struct ospf *ospf, |
0f478e30 CS |
10543 | struct route_table *rt, |
10544 | json_object *json) | |
d62a17ae | 10545 | { |
10546 | struct route_node *rn; | |
10547 | struct ospf_route * or ; | |
10548 | struct listnode *pnode, *pnnode; | |
10549 | struct ospf_path *path; | |
96b663a3 | 10550 | char buf[PREFIX_STRLEN]; |
0f478e30 CS |
10551 | json_object *json_route = NULL, *json_nexthop_array = NULL, |
10552 | *json_nexthop = NULL; | |
d62a17ae | 10553 | |
0f478e30 | 10554 | if (!json) |
996c9314 LB |
10555 | vty_out(vty, |
10556 | "============ OSPF network routing table ============\n"); | |
d62a17ae | 10557 | |
0f478e30 | 10558 | for (rn = route_top(rt); rn; rn = route_next(rn)) { |
96b663a3 MS |
10559 | char buf1[PREFIX2STR_BUFFER]; |
10560 | ||
0f478e30 CS |
10561 | if ((or = rn->info) == NULL) |
10562 | continue; | |
0f478e30 | 10563 | |
0f478e30 CS |
10564 | prefix2str(&rn->p, buf1, sizeof(buf1)); |
10565 | ||
19d37e54 DS |
10566 | if (json) { |
10567 | json_route = json_object_new_object(); | |
996c9314 | 10568 | json_object_object_add(json, buf1, json_route); |
19d37e54 | 10569 | } |
0f478e30 CS |
10570 | |
10571 | switch (or->path_type) { | |
10572 | case OSPF_PATH_INTER_AREA: | |
10573 | if (or->type == OSPF_DESTINATION_NETWORK) { | |
10574 | if (json) { | |
10575 | json_object_string_add(json_route, | |
996c9314 LB |
10576 | "routeType", |
10577 | "N IA"); | |
10578 | json_object_int_add(json_route, "cost", | |
0f478e30 CS |
10579 | or->cost); |
10580 | json_object_string_add( | |
996c9314 | 10581 | json_route, "area", |
96b663a3 MS |
10582 | inet_ntop(AF_INET, |
10583 | &or->u.std.area_id, | |
10584 | buf1, sizeof(buf1))); | |
0f478e30 | 10585 | } else { |
d62a17ae | 10586 | vty_out(vty, |
96b663a3 | 10587 | "N IA %-18s [%d] area: %pI4\n", |
d62a17ae | 10588 | buf1, or->cost, |
96b663a3 | 10589 | &or->u.std.area_id); |
0f478e30 | 10590 | } |
996c9314 | 10591 | } else if (or->type == OSPF_DESTINATION_DISCARD) { |
0f478e30 CS |
10592 | if (json) { |
10593 | json_object_string_add(json_route, | |
996c9314 LB |
10594 | "routeType", |
10595 | "D IA"); | |
0f478e30 | 10596 | } else { |
d62a17ae | 10597 | vty_out(vty, |
10598 | "D IA %-18s Discard entry\n", | |
10599 | buf1); | |
0f478e30 CS |
10600 | } |
10601 | } | |
10602 | break; | |
10603 | case OSPF_PATH_INTRA_AREA: | |
10604 | if (json) { | |
996c9314 LB |
10605 | json_object_string_add(json_route, "routeType", |
10606 | "N"); | |
0f478e30 | 10607 | json_object_int_add(json_route, "cost", |
996c9314 LB |
10608 | or->cost); |
10609 | json_object_string_add( | |
10610 | json_route, "area", | |
96b663a3 MS |
10611 | inet_ntop(AF_INET, &or->u.std.area_id, |
10612 | buf1, sizeof(buf1))); | |
0f478e30 | 10613 | } else { |
96b663a3 | 10614 | vty_out(vty, "N %-18s [%d] area: %pI4\n", |
d62a17ae | 10615 | buf1, or->cost, |
96b663a3 | 10616 | &or->u.std.area_id); |
0f478e30 CS |
10617 | } |
10618 | break; | |
10619 | default: | |
10620 | break; | |
10621 | } | |
10622 | ||
10623 | if (or->type == OSPF_DESTINATION_NETWORK) { | |
10624 | if (json) { | |
10625 | json_nexthop_array = json_object_new_array(); | |
10626 | json_object_object_add(json_route, "nexthops", | |
996c9314 | 10627 | json_nexthop_array); |
d62a17ae | 10628 | } |
10629 | ||
0f478e30 CS |
10630 | for (ALL_LIST_ELEMENTS(or->paths, pnode, pnnode, |
10631 | path)) { | |
10632 | if (json) { | |
996c9314 LB |
10633 | json_nexthop = json_object_new_object(); |
10634 | json_object_array_add( | |
10635 | json_nexthop_array, | |
10636 | json_nexthop); | |
0f478e30 CS |
10637 | } |
10638 | if (if_lookup_by_index(path->ifindex, | |
10639 | ospf->vrf_id)) { | |
10640 | ||
3a6290bd DA |
10641 | if (path->nexthop.s_addr |
10642 | == INADDR_ANY) { | |
0f478e30 CS |
10643 | if (json) { |
10644 | json_object_string_add( | |
10645 | json_nexthop, | |
996c9314 | 10646 | "ip", " "); |
0f478e30 CS |
10647 | json_object_string_add( |
10648 | json_nexthop, | |
10649 | "directly attached to", | |
d62a17ae | 10650 | ifindex2ifname( |
996c9314 LB |
10651 | path->ifindex, |
10652 | ospf->vrf_id)); | |
0f478e30 | 10653 | } else { |
d62a17ae | 10654 | vty_out(vty, |
996c9314 LB |
10655 | "%24s directly attached to %s\n", |
10656 | "", | |
10657 | ifindex2ifname( | |
10658 | path->ifindex, | |
10659 | ospf->vrf_id)); | |
0f478e30 CS |
10660 | } |
10661 | } else { | |
10662 | if (json) { | |
10663 | json_object_string_add( | |
10664 | json_nexthop, | |
10665 | "ip", | |
96b663a3 MS |
10666 | inet_ntop( |
10667 | AF_INET, | |
10668 | &path->nexthop, | |
10669 | buf, | |
10670 | sizeof(buf))); | |
0f478e30 CS |
10671 | json_object_string_add( |
10672 | json_nexthop, | |
10673 | "via", | |
d62a17ae | 10674 | ifindex2ifname( |
996c9314 LB |
10675 | path->ifindex, |
10676 | ospf->vrf_id)); | |
0f478e30 CS |
10677 | } else { |
10678 | vty_out(vty, | |
96b663a3 | 10679 | "%24s via %pI4, %s\n", |
996c9314 | 10680 | "", |
96b663a3 | 10681 | &path->nexthop, |
996c9314 LB |
10682 | ifindex2ifname( |
10683 | path->ifindex, | |
10684 | ospf->vrf_id)); | |
0f478e30 | 10685 | } |
d62a17ae | 10686 | } |
10687 | } | |
0f478e30 | 10688 | } |
d62a17ae | 10689 | } |
0f478e30 CS |
10690 | } |
10691 | if (!json) | |
10692 | vty_out(vty, "\n"); | |
d62a17ae | 10693 | } |
10694 | ||
b5a8894d | 10695 | static void show_ip_ospf_route_router(struct vty *vty, struct ospf *ospf, |
0f478e30 CS |
10696 | struct route_table *rtrs, |
10697 | json_object *json) | |
d62a17ae | 10698 | { |
10699 | struct route_node *rn; | |
10700 | struct ospf_route * or ; | |
10701 | struct listnode *pnode; | |
10702 | struct listnode *node; | |
10703 | struct ospf_path *path; | |
96b663a3 | 10704 | char buf[PREFIX_STRLEN]; |
0f478e30 CS |
10705 | json_object *json_route = NULL, *json_nexthop_array = NULL, |
10706 | *json_nexthop = NULL; | |
d62a17ae | 10707 | |
0f478e30 | 10708 | if (!json) |
996c9314 LB |
10709 | vty_out(vty, |
10710 | "============ OSPF router routing table =============\n"); | |
d62a17ae | 10711 | |
0f478e30 CS |
10712 | for (rn = route_top(rtrs); rn; rn = route_next(rn)) { |
10713 | if (rn->info == NULL) | |
10714 | continue; | |
10715 | int flag = 0; | |
10716 | ||
0f478e30 | 10717 | if (json) { |
19d37e54 | 10718 | json_route = json_object_new_object(); |
96b663a3 MS |
10719 | json_object_object_add( |
10720 | json, inet_ntop(AF_INET, &rn->p.u.prefix4, | |
10721 | buf, sizeof(buf)), | |
10722 | json_route); | |
996c9314 | 10723 | json_object_string_add(json_route, "routeType", "R "); |
0f478e30 | 10724 | } else { |
96b663a3 MS |
10725 | vty_out(vty, "R %-15pI4 ", |
10726 | &rn->p.u.prefix4); | |
0f478e30 | 10727 | } |
d62a17ae | 10728 | |
996c9314 | 10729 | for (ALL_LIST_ELEMENTS_RO((struct list *)rn->info, node, or)) { |
0f478e30 CS |
10730 | if (flag++) { |
10731 | if (!json) | |
d62a17ae | 10732 | vty_out(vty, "%24s", ""); |
0f478e30 | 10733 | } |
d62a17ae | 10734 | |
0f478e30 CS |
10735 | /* Show path. */ |
10736 | if (json) { | |
10737 | json_object_int_add(json_route, "cost", | |
10738 | or->cost); | |
996c9314 LB |
10739 | json_object_string_add( |
10740 | json_route, "area", | |
96b663a3 MS |
10741 | inet_ntop(AF_INET, &or->u.std.area_id, |
10742 | buf, sizeof(buf))); | |
996c9314 LB |
10743 | if (or->path_type == OSPF_PATH_INTER_AREA) |
10744 | json_object_boolean_true_add(json_route, | |
10745 | "IA"); | |
0f478e30 | 10746 | if (or->u.std.flags & ROUTER_LSA_BORDER) |
996c9314 LB |
10747 | json_object_string_add(json_route, |
10748 | "routerType", | |
10749 | "abr"); | |
10750 | else if (or->u.std.flags & ROUTER_LSA_EXTERNAL) | |
10751 | json_object_string_add(json_route, | |
10752 | "routerType", | |
10753 | "asbr"); | |
0f478e30 | 10754 | } else { |
96b663a3 | 10755 | vty_out(vty, "%s [%d] area: %pI4", |
996c9314 LB |
10756 | (or->path_type == OSPF_PATH_INTER_AREA |
10757 | ? "IA" | |
10758 | : " "), | |
96b663a3 | 10759 | or->cost, &or->u.std.area_id); |
d62a17ae | 10760 | /* Show flags. */ |
10761 | vty_out(vty, "%s%s\n", | |
996c9314 LB |
10762 | (or->u.std.flags & ROUTER_LSA_BORDER |
10763 | ? ", ABR" | |
10764 | : ""), | |
10765 | (or->u.std.flags & ROUTER_LSA_EXTERNAL | |
10766 | ? ", ASBR" | |
10767 | : "")); | |
0f478e30 CS |
10768 | } |
10769 | ||
10770 | if (json) { | |
996c9314 | 10771 | json_nexthop_array = json_object_new_array(); |
0f478e30 | 10772 | json_object_object_add(json_route, "nexthops", |
996c9314 | 10773 | json_nexthop_array); |
0f478e30 CS |
10774 | } |
10775 | ||
996c9314 | 10776 | for (ALL_LIST_ELEMENTS_RO(or->paths, pnode, path)) { |
0f478e30 | 10777 | if (json) { |
996c9314 | 10778 | json_nexthop = json_object_new_object(); |
0f478e30 CS |
10779 | json_object_array_add( |
10780 | json_nexthop_array, | |
10781 | json_nexthop); | |
10782 | } | |
10783 | if (if_lookup_by_index(path->ifindex, | |
10784 | ospf->vrf_id)) { | |
3a6290bd DA |
10785 | if (path->nexthop.s_addr |
10786 | == INADDR_ANY) { | |
0f478e30 CS |
10787 | if (json) { |
10788 | json_object_string_add( | |
10789 | json_nexthop, | |
996c9314 | 10790 | "ip", " "); |
0f478e30 CS |
10791 | json_object_string_add( |
10792 | json_nexthop, | |
10793 | "directly attached to", | |
d62a17ae | 10794 | ifindex2ifname( |
10795 | path->ifindex, | |
b5a8894d | 10796 | ospf->vrf_id)); |
0f478e30 | 10797 | } else { |
d62a17ae | 10798 | vty_out(vty, |
996c9314 LB |
10799 | "%24s directly attached to %s\n", |
10800 | "", | |
10801 | ifindex2ifname( | |
10802 | path->ifindex, | |
10803 | ospf->vrf_id)); | |
0f478e30 CS |
10804 | } |
10805 | } else { | |
10806 | if (json) { | |
10807 | json_object_string_add( | |
10808 | json_nexthop, | |
10809 | "ip", | |
96b663a3 MS |
10810 | inet_ntop( |
10811 | AF_INET, | |
10812 | &path->nexthop, | |
10813 | buf, sizeof(buf))); | |
0f478e30 CS |
10814 | json_object_string_add( |
10815 | json_nexthop, | |
10816 | "via", | |
d62a17ae | 10817 | ifindex2ifname( |
10818 | path->ifindex, | |
b5a8894d | 10819 | ospf->vrf_id)); |
0f478e30 CS |
10820 | } else { |
10821 | vty_out(vty, | |
96b663a3 | 10822 | "%24s via %pI4, %s\n", |
996c9314 | 10823 | "", |
96b663a3 | 10824 | &path->nexthop, |
996c9314 LB |
10825 | ifindex2ifname( |
10826 | path->ifindex, | |
10827 | ospf->vrf_id)); | |
0f478e30 | 10828 | } |
d62a17ae | 10829 | } |
10830 | } | |
10831 | } | |
10832 | } | |
0f478e30 CS |
10833 | } |
10834 | if (!json) | |
10835 | vty_out(vty, "\n"); | |
d62a17ae | 10836 | } |
10837 | ||
b5a8894d | 10838 | static void show_ip_ospf_route_external(struct vty *vty, struct ospf *ospf, |
0f478e30 CS |
10839 | struct route_table *rt, |
10840 | json_object *json) | |
d62a17ae | 10841 | { |
10842 | struct route_node *rn; | |
10843 | struct ospf_route *er; | |
10844 | struct listnode *pnode, *pnnode; | |
10845 | struct ospf_path *path; | |
96b663a3 | 10846 | char buf[PREFIX_STRLEN]; |
0f478e30 CS |
10847 | json_object *json_route = NULL, *json_nexthop_array = NULL, |
10848 | *json_nexthop = NULL; | |
d62a17ae | 10849 | |
0f478e30 | 10850 | if (!json) |
996c9314 LB |
10851 | vty_out(vty, |
10852 | "============ OSPF external routing table ===========\n"); | |
0f478e30 CS |
10853 | |
10854 | for (rn = route_top(rt); rn; rn = route_next(rn)) { | |
10855 | if ((er = rn->info) == NULL) | |
10856 | continue; | |
10857 | ||
10858 | char buf1[19]; | |
10859 | ||
96b663a3 | 10860 | snprintfrr(buf1, sizeof(buf1), "%pFX", &rn->p); |
19d37e54 DS |
10861 | if (json) { |
10862 | json_route = json_object_new_object(); | |
996c9314 | 10863 | json_object_object_add(json, buf1, json_route); |
19d37e54 | 10864 | } |
d62a17ae | 10865 | |
0f478e30 CS |
10866 | switch (er->path_type) { |
10867 | case OSPF_PATH_TYPE1_EXTERNAL: | |
10868 | if (json) { | |
996c9314 | 10869 | json_object_string_add(json_route, "routeType", |
0f478e30 CS |
10870 | "N E1"); |
10871 | json_object_int_add(json_route, "cost", | |
996c9314 | 10872 | er->cost); |
67df3649 MR |
10873 | json_object_int_add(json_route, "tag", |
10874 | er->u.ext.tag); | |
0f478e30 | 10875 | } else { |
d62a17ae | 10876 | vty_out(vty, |
996c9314 LB |
10877 | "N E1 %-18s [%d] tag: %" ROUTE_TAG_PRI |
10878 | "\n", | |
10879 | buf1, er->cost, er->u.ext.tag); | |
0f478e30 CS |
10880 | } |
10881 | break; | |
10882 | case OSPF_PATH_TYPE2_EXTERNAL: | |
10883 | if (json) { | |
996c9314 | 10884 | json_object_string_add(json_route, "routeType", |
0f478e30 CS |
10885 | "N E2"); |
10886 | json_object_int_add(json_route, "cost", | |
996c9314 | 10887 | er->cost); |
67df3649 MR |
10888 | json_object_int_add(json_route, "type2cost", |
10889 | er->u.ext.type2_cost); | |
10890 | json_object_int_add(json_route, "tag", | |
10891 | er->u.ext.tag); | |
0f478e30 | 10892 | } else { |
d62a17ae | 10893 | vty_out(vty, |
996c9314 LB |
10894 | "N E2 %-18s [%d/%d] tag: %" ROUTE_TAG_PRI |
10895 | "\n", | |
10896 | buf1, er->cost, er->u.ext.type2_cost, | |
d62a17ae | 10897 | er->u.ext.tag); |
d62a17ae | 10898 | } |
0f478e30 CS |
10899 | break; |
10900 | } | |
d62a17ae | 10901 | |
0f478e30 CS |
10902 | if (json) { |
10903 | json_nexthop_array = json_object_new_array(); | |
10904 | json_object_object_add(json_route, "nexthops", | |
996c9314 | 10905 | json_nexthop_array); |
0f478e30 CS |
10906 | } |
10907 | ||
996c9314 | 10908 | for (ALL_LIST_ELEMENTS(er->paths, pnode, pnnode, path)) { |
0f478e30 CS |
10909 | if (json) { |
10910 | json_nexthop = json_object_new_object(); | |
996c9314 LB |
10911 | json_object_array_add(json_nexthop_array, |
10912 | json_nexthop); | |
0f478e30 CS |
10913 | } |
10914 | ||
996c9314 | 10915 | if (if_lookup_by_index(path->ifindex, ospf->vrf_id)) { |
3a6290bd | 10916 | if (path->nexthop.s_addr == INADDR_ANY) { |
0f478e30 CS |
10917 | if (json) { |
10918 | json_object_string_add( | |
996c9314 LB |
10919 | json_nexthop, "ip", |
10920 | " "); | |
0f478e30 CS |
10921 | json_object_string_add( |
10922 | json_nexthop, | |
10923 | "directly attached to", | |
d62a17ae | 10924 | ifindex2ifname( |
996c9314 LB |
10925 | path->ifindex, |
10926 | ospf->vrf_id)); | |
0f478e30 | 10927 | } else { |
d62a17ae | 10928 | vty_out(vty, |
996c9314 LB |
10929 | "%24s directly attached to %s\n", |
10930 | "", | |
10931 | ifindex2ifname( | |
10932 | path->ifindex, | |
10933 | ospf->vrf_id)); | |
0f478e30 CS |
10934 | } |
10935 | } else { | |
10936 | if (json) { | |
10937 | json_object_string_add( | |
996c9314 | 10938 | json_nexthop, "ip", |
96b663a3 MS |
10939 | inet_ntop( |
10940 | AF_INET, | |
10941 | &path->nexthop, | |
10942 | buf, | |
10943 | sizeof(buf))); | |
0f478e30 | 10944 | json_object_string_add( |
996c9314 | 10945 | json_nexthop, "via", |
d62a17ae | 10946 | ifindex2ifname( |
996c9314 LB |
10947 | path->ifindex, |
10948 | ospf->vrf_id)); | |
0f478e30 CS |
10949 | } else { |
10950 | vty_out(vty, | |
96b663a3 | 10951 | "%24s via %pI4, %s\n", |
996c9314 | 10952 | "", |
96b663a3 | 10953 | &path->nexthop, |
996c9314 LB |
10954 | ifindex2ifname( |
10955 | path->ifindex, | |
10956 | ospf->vrf_id)); | |
0f478e30 | 10957 | } |
d62a17ae | 10958 | } |
54bedb55 | 10959 | } |
d62a17ae | 10960 | } |
0f478e30 CS |
10961 | } |
10962 | if (!json) | |
10963 | vty_out(vty, "\n"); | |
718e3744 | 10964 | } |
10965 | ||
d62a17ae | 10966 | static int show_ip_ospf_border_routers_common(struct vty *vty, |
d7c0a89a QY |
10967 | struct ospf *ospf, |
10968 | uint8_t use_vrf) | |
718e3744 | 10969 | { |
d62a17ae | 10970 | if (ospf->instance) |
10971 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
718e3744 | 10972 | |
b1c3ae8c | 10973 | ospf_show_vrf_name(ospf, vty, NULL, use_vrf); |
87bd50e8 | 10974 | |
d62a17ae | 10975 | if (ospf->new_table == NULL) { |
10976 | vty_out(vty, "No OSPF routing information exist\n"); | |
10977 | return CMD_SUCCESS; | |
10978 | } | |
718e3744 | 10979 | |
d62a17ae | 10980 | /* Show Network routes. |
10981 | show_ip_ospf_route_network (vty, ospf->new_table); */ | |
718e3744 | 10982 | |
d62a17ae | 10983 | /* Show Router routes. */ |
0f478e30 | 10984 | show_ip_ospf_route_router(vty, ospf, ospf->new_rtrs, NULL); |
718e3744 | 10985 | |
d62a17ae | 10986 | vty_out(vty, "\n"); |
7c8ff89e | 10987 | |
d62a17ae | 10988 | return CMD_SUCCESS; |
718e3744 | 10989 | } |
718e3744 | 10990 | |
7c8ff89e DS |
10991 | DEFUN (show_ip_ospf_border_routers, |
10992 | show_ip_ospf_border_routers_cmd, | |
b5a8894d | 10993 | "show ip ospf [vrf <NAME|all>] border-routers", |
718e3744 | 10994 | SHOW_STR |
10995 | IP_STR | |
10996 | "OSPF information\n" | |
b5a8894d CS |
10997 | VRF_CMD_HELP_STR |
10998 | "All VRFs\n" | |
7c8ff89e | 10999 | "Show all the ABR's and ASBR's\n") |
718e3744 | 11000 | { |
b5a8894d CS |
11001 | struct ospf *ospf = NULL; |
11002 | struct listnode *node = NULL; | |
11003 | char *vrf_name = NULL; | |
2951a7a4 | 11004 | bool all_vrf = false; |
b5a8894d CS |
11005 | int ret = CMD_SUCCESS; |
11006 | int inst = 0; | |
11007 | int idx_vrf = 0; | |
d7c0a89a | 11008 | uint8_t use_vrf = 0; |
68980084 | 11009 | |
43b8d1d8 | 11010 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
7c8ff89e | 11011 | |
b5a8894d | 11012 | if (vrf_name) { |
2951a7a4 | 11013 | bool ospf_output = false; |
874f58d8 | 11014 | |
b1c3ae8c | 11015 | use_vrf = 1; |
94d4c685 | 11016 | |
b5a8894d CS |
11017 | if (all_vrf) { |
11018 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
11019 | if (!ospf->oi_running) | |
11020 | continue; | |
b5a8894d | 11021 | |
2951a7a4 | 11022 | ospf_output = true; |
996c9314 LB |
11023 | ret = show_ip_ospf_border_routers_common( |
11024 | vty, ospf, use_vrf); | |
b5a8894d | 11025 | } |
9f049418 DS |
11026 | |
11027 | if (!ospf_output) | |
94d4c685 | 11028 | vty_out(vty, "%% OSPF instance not found\n"); |
b5a8894d CS |
11029 | } else { |
11030 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
9f049418 | 11031 | if (ospf == NULL || !ospf->oi_running) { |
94d4c685 | 11032 | vty_out(vty, "%% OSPF instance not found\n"); |
b5a8894d | 11033 | return CMD_SUCCESS; |
9f049418 | 11034 | } |
b5a8894d | 11035 | |
b1c3ae8c CS |
11036 | ret = show_ip_ospf_border_routers_common(vty, ospf, |
11037 | use_vrf); | |
b5a8894d CS |
11038 | } |
11039 | } else { | |
11040 | /* Display default ospf (instance 0) info */ | |
11041 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
9f049418 | 11042 | if (ospf == NULL || !ospf->oi_running) { |
94d4c685 | 11043 | vty_out(vty, "%% OSPF instance not found\n"); |
b5a8894d | 11044 | return CMD_SUCCESS; |
9f049418 DS |
11045 | } |
11046 | ||
b1c3ae8c | 11047 | ret = show_ip_ospf_border_routers_common(vty, ospf, use_vrf); |
b5a8894d CS |
11048 | } |
11049 | ||
11050 | return ret; | |
7c8ff89e DS |
11051 | } |
11052 | ||
11053 | DEFUN (show_ip_ospf_instance_border_routers, | |
11054 | show_ip_ospf_instance_border_routers_cmd, | |
6147e2c6 | 11055 | "show ip ospf (1-65535) border-routers", |
7c8ff89e DS |
11056 | SHOW_STR |
11057 | IP_STR | |
11058 | "OSPF information\n" | |
11059 | "Instance ID\n" | |
11060 | "Show all the ABR's and ASBR's\n") | |
11061 | { | |
d62a17ae | 11062 | int idx_number = 3; |
11063 | struct ospf *ospf; | |
d7c0a89a | 11064 | unsigned short instance = 0; |
7c8ff89e | 11065 | |
d62a17ae | 11066 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
409f98ab | 11067 | if (instance != ospf_instance) |
ac28e4ec CS |
11068 | return CMD_NOT_MY_INSTANCE; |
11069 | ||
409f98ab IR |
11070 | ospf = ospf_lookup_instance(instance); |
11071 | if (!ospf || !ospf->oi_running) | |
d62a17ae | 11072 | return CMD_SUCCESS; |
7c8ff89e | 11073 | |
b1c3ae8c | 11074 | return show_ip_ospf_border_routers_common(vty, ospf, 0); |
7c8ff89e DS |
11075 | } |
11076 | ||
b1c3ae8c | 11077 | static int show_ip_ospf_route_common(struct vty *vty, struct ospf *ospf, |
d7c0a89a | 11078 | json_object *json, uint8_t use_vrf) |
7c8ff89e | 11079 | { |
0f478e30 CS |
11080 | json_object *json_vrf = NULL; |
11081 | ||
d62a17ae | 11082 | if (ospf->instance) |
11083 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
718e3744 | 11084 | |
0f478e30 CS |
11085 | |
11086 | if (json) { | |
11087 | if (use_vrf) | |
11088 | json_vrf = json_object_new_object(); | |
11089 | else | |
11090 | json_vrf = json; | |
11091 | } | |
11092 | ||
11093 | ospf_show_vrf_name(ospf, vty, json_vrf, 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. */ |
0f478e30 | 11101 | show_ip_ospf_route_network(vty, ospf, ospf->new_table, json_vrf); |
718e3744 | 11102 | |
d62a17ae | 11103 | /* Show Router routes. */ |
0f478e30 | 11104 | show_ip_ospf_route_router(vty, ospf, ospf->new_rtrs, json_vrf); |
718e3744 | 11105 | |
d62a17ae | 11106 | /* Show AS External routes. */ |
0f478e30 CS |
11107 | show_ip_ospf_route_external(vty, ospf, ospf->old_external_route, |
11108 | json_vrf); | |
718e3744 | 11109 | |
0f478e30 CS |
11110 | if (json) { |
11111 | if (use_vrf) { | |
996c9314 LB |
11112 | // json_object_object_add(json_vrf, "areas", |
11113 | // json_areas); | |
44076f4d RW |
11114 | json_object_object_add(json, ospf_get_name(ospf), |
11115 | json_vrf); | |
0f478e30 CS |
11116 | } |
11117 | } else { | |
11118 | vty_out(vty, "\n"); | |
11119 | } | |
7c8ff89e | 11120 | |
d62a17ae | 11121 | return CMD_SUCCESS; |
718e3744 | 11122 | } |
11123 | ||
7c8ff89e DS |
11124 | DEFUN (show_ip_ospf_route, |
11125 | show_ip_ospf_route_cmd, | |
0f478e30 | 11126 | "show ip ospf [vrf <NAME|all>] route [json]", |
b5a8894d CS |
11127 | SHOW_STR |
11128 | IP_STR | |
11129 | "OSPF information\n" | |
11130 | VRF_CMD_HELP_STR | |
11131 | "All VRFs\n" | |
0f478e30 CS |
11132 | "OSPF routing table\n" |
11133 | JSON_STR) | |
b5a8894d CS |
11134 | { |
11135 | struct ospf *ospf = NULL; | |
11136 | struct listnode *node = NULL; | |
11137 | char *vrf_name = NULL; | |
2951a7a4 | 11138 | bool all_vrf = false; |
b5a8894d CS |
11139 | int ret = CMD_SUCCESS; |
11140 | int inst = 0; | |
11141 | int idx_vrf = 0; | |
d7c0a89a | 11142 | uint8_t use_vrf = 0; |
9f049418 | 11143 | bool uj = use_json(argc, argv); |
0f478e30 CS |
11144 | json_object *json = NULL; |
11145 | ||
11146 | if (uj) | |
11147 | json = json_object_new_object(); | |
7c8ff89e | 11148 | |
43b8d1d8 | 11149 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
7c8ff89e | 11150 | |
b5a8894d CS |
11151 | /* vrf input is provided could be all or specific vrf*/ |
11152 | if (vrf_name) { | |
2951a7a4 | 11153 | bool ospf_output = false; |
874f58d8 | 11154 | |
b1c3ae8c | 11155 | use_vrf = 1; |
94d4c685 | 11156 | |
b5a8894d CS |
11157 | if (all_vrf) { |
11158 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
11159 | if (!ospf->oi_running) | |
11160 | continue; | |
2951a7a4 | 11161 | ospf_output = true; |
0f478e30 | 11162 | ret = show_ip_ospf_route_common(vty, ospf, json, |
b1c3ae8c | 11163 | use_vrf); |
b5a8894d | 11164 | } |
0f478e30 CS |
11165 | |
11166 | if (uj) { | |
1406159f | 11167 | /* Keep Non-pretty format */ |
0f478e30 | 11168 | vty_out(vty, "%s\n", |
e77564cc DS |
11169 | json_object_to_json_string_ext( |
11170 | json, | |
11171 | JSON_C_TO_STRING_NOSLASHESCAPE)); | |
0f478e30 | 11172 | json_object_free(json); |
9f049418 DS |
11173 | } else if (!ospf_output) |
11174 | vty_out(vty, "%% OSPF instance not found\n"); | |
0f478e30 | 11175 | |
b5a8894d CS |
11176 | return ret; |
11177 | } | |
11178 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
0f478e30 | 11179 | if (ospf == NULL || !ospf->oi_running) { |
9f049418 DS |
11180 | if (uj) { |
11181 | vty_out(vty, "%s\n", | |
11182 | json_object_to_json_string_ext( | |
e77564cc DS |
11183 | json, |
11184 | JSON_C_TO_STRING_PRETTY | |
11185 | | JSON_C_TO_STRING_NOSLASHESCAPE)); | |
0f478e30 | 11186 | json_object_free(json); |
9f049418 | 11187 | } else |
94d4c685 | 11188 | vty_out(vty, "%% OSPF instance not found\n"); |
9f049418 | 11189 | |
b5a8894d | 11190 | return CMD_SUCCESS; |
0f478e30 | 11191 | } |
b5a8894d CS |
11192 | } else { |
11193 | /* Display default ospf (instance 0) info */ | |
11194 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
0f478e30 | 11195 | if (ospf == NULL || !ospf->oi_running) { |
9f049418 DS |
11196 | if (uj) { |
11197 | vty_out(vty, "%s\n", | |
11198 | json_object_to_json_string_ext( | |
e77564cc DS |
11199 | json, |
11200 | JSON_C_TO_STRING_PRETTY | |
11201 | | JSON_C_TO_STRING_NOSLASHESCAPE)); | |
0f478e30 | 11202 | json_object_free(json); |
9f049418 | 11203 | } else |
94d4c685 | 11204 | vty_out(vty, "%% OSPF instance not found\n"); |
9f049418 | 11205 | |
b5a8894d | 11206 | return CMD_SUCCESS; |
0f478e30 CS |
11207 | } |
11208 | } | |
11209 | ||
11210 | if (ospf) { | |
11211 | ret = show_ip_ospf_route_common(vty, ospf, json, use_vrf); | |
1406159f | 11212 | /* Keep Non-pretty format */ |
0f478e30 | 11213 | if (uj) |
e77564cc DS |
11214 | vty_out(vty, "%s\n", |
11215 | json_object_to_json_string_ext( | |
11216 | json, JSON_C_TO_STRING_NOSLASHESCAPE)); | |
b5a8894d CS |
11217 | } |
11218 | ||
0f478e30 CS |
11219 | if (uj) |
11220 | json_object_free(json); | |
b5a8894d CS |
11221 | |
11222 | return ret; | |
7c8ff89e DS |
11223 | } |
11224 | ||
11225 | DEFUN (show_ip_ospf_instance_route, | |
11226 | show_ip_ospf_instance_route_cmd, | |
6147e2c6 | 11227 | "show ip ospf (1-65535) route", |
7c8ff89e DS |
11228 | SHOW_STR |
11229 | IP_STR | |
11230 | "OSPF information\n" | |
11231 | "Instance ID\n" | |
11232 | "OSPF routing table\n") | |
11233 | { | |
d62a17ae | 11234 | int idx_number = 3; |
11235 | struct ospf *ospf; | |
d7c0a89a | 11236 | unsigned short instance = 0; |
7c8ff89e | 11237 | |
d62a17ae | 11238 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
409f98ab | 11239 | if (instance != ospf_instance) |
ac28e4ec CS |
11240 | return CMD_NOT_MY_INSTANCE; |
11241 | ||
409f98ab IR |
11242 | ospf = ospf_lookup_instance(instance); |
11243 | if (!ospf || !ospf->oi_running) | |
d62a17ae | 11244 | return CMD_SUCCESS; |
7c8ff89e | 11245 | |
0f478e30 | 11246 | return show_ip_ospf_route_common(vty, ospf, NULL, 0); |
7c8ff89e | 11247 | } |
6b0655a2 | 11248 | |
b5a8894d CS |
11249 | |
11250 | DEFUN (show_ip_ospf_vrfs, | |
11251 | show_ip_ospf_vrfs_cmd, | |
11252 | "show ip ospf vrfs [json]", | |
11253 | SHOW_STR | |
11254 | IP_STR | |
11255 | "OSPF information\n" | |
11256 | "Show OSPF VRFs \n" | |
11257 | JSON_STR) | |
11258 | { | |
9f049418 | 11259 | bool uj = use_json(argc, argv); |
b5a8894d CS |
11260 | json_object *json = NULL; |
11261 | json_object *json_vrfs = NULL; | |
11262 | struct ospf *ospf = NULL; | |
11263 | struct listnode *node = NULL; | |
11264 | int count = 0; | |
96b663a3 | 11265 | char buf[PREFIX_STRLEN]; |
2b64873d | 11266 | static const char header[] = "Name Id RouterId "; |
b5a8894d CS |
11267 | |
11268 | if (uj) { | |
11269 | json = json_object_new_object(); | |
11270 | json_vrfs = json_object_new_object(); | |
11271 | } | |
11272 | ||
11273 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
11274 | json_object *json_vrf = NULL; | |
11275 | const char *name = NULL; | |
fe3da9e7 | 11276 | int64_t vrf_id_ui = 0; |
b5a8894d CS |
11277 | |
11278 | count++; | |
11279 | ||
11280 | if (!uj && count == 1) | |
11281 | vty_out(vty, "%s\n", header); | |
11282 | if (uj) | |
11283 | json_vrf = json_object_new_object(); | |
11284 | ||
44076f4d | 11285 | name = ospf_get_name(ospf); |
b5a8894d | 11286 | |
996c9314 LB |
11287 | vrf_id_ui = (ospf->vrf_id == VRF_UNKNOWN) |
11288 | ? -1 | |
11289 | : (int64_t)ospf->vrf_id; | |
b5a8894d CS |
11290 | |
11291 | if (uj) { | |
11292 | json_object_int_add(json_vrf, "vrfId", vrf_id_ui); | |
96b663a3 MS |
11293 | json_object_string_add( |
11294 | json_vrf, "routerId", | |
11295 | inet_ntop(AF_INET, &ospf->router_id, | |
11296 | buf, sizeof(buf))); | |
b5a8894d CS |
11297 | |
11298 | json_object_object_add(json_vrfs, name, json_vrf); | |
11299 | ||
11300 | } else { | |
96b663a3 MS |
11301 | vty_out(vty, "%-25s %-5d %-16pI4 \n", name, |
11302 | ospf->vrf_id, &ospf->router_id); | |
b5a8894d CS |
11303 | } |
11304 | } | |
11305 | ||
11306 | if (uj) { | |
11307 | json_object_object_add(json, "vrfs", json_vrfs); | |
11308 | json_object_int_add(json, "totalVrfs", count); | |
11309 | ||
996c9314 LB |
11310 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
11311 | json, JSON_C_TO_STRING_PRETTY)); | |
b5a8894d CS |
11312 | json_object_free(json); |
11313 | } else { | |
11314 | if (count) | |
34d6798f | 11315 | vty_out(vty, "\nTotal number of OSPF VRFs: %d\n", |
b5a8894d CS |
11316 | count); |
11317 | } | |
11318 | ||
11319 | return CMD_SUCCESS; | |
11320 | } | |
f91ce319 MR |
11321 | DEFPY (clear_ip_ospf_neighbor, |
11322 | clear_ip_ospf_neighbor_cmd, | |
11323 | "clear ip ospf [(1-65535)]$instance neighbor [A.B.C.D$nbr_id]", | |
11324 | CLEAR_STR | |
11325 | IP_STR | |
11326 | "OSPF information\n" | |
11327 | "Instance ID\n" | |
11328 | "Reset OSPF Neighbor\n" | |
11329 | "Neighbor ID\n") | |
11330 | { | |
11331 | struct listnode *node; | |
11332 | struct ospf *ospf = NULL; | |
11333 | ||
11334 | /* If user does not specify the arguments, | |
11335 | * instance = 0 and nbr_id = 0.0.0.0 | |
11336 | */ | |
11337 | if (instance != 0) { | |
11338 | /* This means clear only the particular ospf process */ | |
409f98ab | 11339 | if (instance != ospf_instance) |
f91ce319 MR |
11340 | return CMD_NOT_MY_INSTANCE; |
11341 | } | |
11342 | ||
11343 | /* Clear all the ospf processes */ | |
11344 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
11345 | if (!ospf->oi_running) | |
11346 | continue; | |
11347 | ||
c88ad8ec | 11348 | if (nbr_id_str && IPV4_ADDR_SAME(&ospf->router_id, &nbr_id)) { |
11349 | vty_out(vty, "Self router-id is not allowed.\r\n "); | |
11350 | return CMD_SUCCESS; | |
11351 | } | |
11352 | ||
f91ce319 MR |
11353 | ospf_neighbor_reset(ospf, nbr_id, nbr_id_str); |
11354 | } | |
11355 | ||
11356 | return CMD_SUCCESS; | |
11357 | } | |
11358 | ||
11359 | DEFPY (clear_ip_ospf_process, | |
11360 | clear_ip_ospf_process_cmd, | |
11361 | "clear ip ospf [(1-65535)]$instance process", | |
11362 | CLEAR_STR | |
11363 | IP_STR | |
11364 | "OSPF information\n" | |
11365 | "Instance ID\n" | |
11366 | "Reset OSPF Process\n") | |
11367 | { | |
11368 | struct listnode *node; | |
11369 | struct ospf *ospf = NULL; | |
11370 | ||
11371 | /* Check if instance is not passed as an argument */ | |
11372 | if (instance != 0) { | |
11373 | /* This means clear only the particular ospf process */ | |
409f98ab | 11374 | if (instance != ospf_instance) |
f91ce319 MR |
11375 | return CMD_NOT_MY_INSTANCE; |
11376 | } | |
11377 | ||
11378 | /* Clear all the ospf processes */ | |
11379 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
11380 | if (!ospf->oi_running) | |
11381 | continue; | |
11382 | ||
11383 | ospf_process_reset(ospf); | |
11384 | } | |
11385 | ||
11386 | return CMD_SUCCESS; | |
11387 | } | |
b5a8894d | 11388 | |
2b64873d DL |
11389 | static const char *const ospf_abr_type_str[] = { |
11390 | "unknown", "standard", "ibm", "cisco", "shortcut" | |
11391 | }; | |
718e3744 | 11392 | |
2b64873d DL |
11393 | static const char *const ospf_shortcut_mode_str[] = { |
11394 | "default", "enable", "disable" | |
11395 | }; | |
1ac88792 | 11396 | static int ospf_vty_external_rt_walkcb(struct hash_bucket *bucket, |
53e44d05 | 11397 | void *arg) |
11398 | { | |
1ac88792 | 11399 | struct external_info *ei = bucket->data; |
53e44d05 | 11400 | struct vty *vty = (struct vty *)arg; |
11401 | static unsigned int count; | |
11402 | ||
11403 | vty_out(vty, "%-4pI4/%d, ", &ei->p.prefix, ei->p.prefixlen); | |
11404 | count++; | |
11405 | ||
11406 | if (count % 5 == 0) | |
11407 | vty_out(vty, "\n"); | |
11408 | ||
11409 | if (OSPF_EXTERNAL_RT_COUNT(ei->aggr_route) == count) | |
11410 | count = 0; | |
11411 | ||
11412 | return HASHWALK_CONTINUE; | |
11413 | } | |
11414 | ||
1ac88792 | 11415 | static int ospf_json_external_rt_walkcb(struct hash_bucket *bucket, |
53e44d05 | 11416 | void *arg) |
11417 | { | |
1ac88792 | 11418 | struct external_info *ei = bucket->data; |
53e44d05 | 11419 | struct json_object *json = (struct json_object *)arg; |
11420 | char buf[PREFIX2STR_BUFFER]; | |
11421 | char exnalbuf[20]; | |
11422 | static unsigned int count; | |
11423 | ||
11424 | prefix2str(&ei->p, buf, sizeof(buf)); | |
11425 | ||
11426 | snprintf(exnalbuf, 20, "Exnl Addr-%d", count); | |
11427 | ||
11428 | json_object_string_add(json, exnalbuf, buf); | |
11429 | ||
11430 | count++; | |
11431 | ||
11432 | if (OSPF_EXTERNAL_RT_COUNT(ei->aggr_route) == count) | |
11433 | count = 0; | |
11434 | ||
11435 | return HASHWALK_CONTINUE; | |
11436 | } | |
11437 | ||
11438 | static int ospf_show_summary_address(struct vty *vty, struct ospf *ospf, | |
11439 | uint8_t use_vrf, json_object *json, | |
11440 | bool uj, bool detail) | |
11441 | { | |
11442 | struct route_node *rn; | |
11443 | json_object *json_vrf = NULL; | |
11444 | int mtype = 0; | |
11445 | int mval = 0; | |
11446 | static char header[] = | |
11447 | "Summary-address Metric-type Metric Tag External_Rt_count\n"; | |
11448 | ||
11449 | mtype = metric_type(ospf, 0, ospf->instance); | |
11450 | mval = metric_value(ospf, 0, ospf->instance); | |
11451 | ||
11452 | if (!uj) | |
11453 | vty_out(vty, "%s\n", header); | |
11454 | ||
11455 | if (uj) { | |
11456 | if (use_vrf) | |
11457 | json_vrf = json_object_new_object(); | |
11458 | else | |
11459 | json_vrf = json; | |
11460 | } | |
11461 | ||
11462 | if (ospf->instance) { | |
11463 | if (uj) | |
11464 | json_object_int_add(json, "ospfInstance", | |
11465 | ospf->instance); | |
11466 | else | |
11467 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
11468 | } | |
11469 | ||
11470 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); | |
11471 | ||
11472 | if (!uj) | |
11473 | vty_out(vty, "aggregation delay interval :%d(in seconds)\n\n", | |
11474 | ospf->aggr_delay_interval); | |
11475 | else | |
11476 | json_object_int_add(json_vrf, "aggregation delay interval", | |
11477 | ospf->aggr_delay_interval); | |
11478 | ||
11479 | for (rn = route_top(ospf->rt_aggr_tbl); rn; rn = route_next(rn)) | |
11480 | if (rn->info) { | |
11481 | struct ospf_external_aggr_rt *aggr = rn->info; | |
11482 | json_object *json_aggr = NULL; | |
11483 | char buf[PREFIX2STR_BUFFER]; | |
11484 | ||
11485 | prefix2str(&aggr->p, buf, sizeof(buf)); | |
11486 | ||
11487 | if (uj) { | |
11488 | ||
11489 | json_aggr = json_object_new_object(); | |
11490 | ||
11491 | json_object_object_add(json_vrf, buf, | |
11492 | json_aggr); | |
11493 | ||
11494 | json_object_string_add(json_aggr, | |
11495 | "Summary address", buf); | |
11496 | ||
11497 | json_object_string_add( | |
11498 | json_aggr, "Metric-type", | |
11499 | (mtype == EXTERNAL_METRIC_TYPE_1) | |
11500 | ? "E1" | |
11501 | : "E2"); | |
11502 | ||
11503 | json_object_int_add(json_aggr, "Metric", mval); | |
11504 | ||
11505 | json_object_int_add(json_aggr, "Tag", | |
11506 | aggr->tag); | |
11507 | ||
11508 | json_object_int_add( | |
11509 | json_aggr, "External route count", | |
11510 | OSPF_EXTERNAL_RT_COUNT(aggr)); | |
11511 | ||
11512 | if (OSPF_EXTERNAL_RT_COUNT(aggr) && detail) { | |
11513 | hash_walk( | |
11514 | aggr->match_extnl_hash, | |
11515 | ospf_json_external_rt_walkcb, | |
11516 | json_aggr); | |
11517 | } | |
11518 | ||
11519 | } else { | |
11520 | vty_out(vty, "%-20s", buf); | |
11521 | ||
11522 | (mtype == EXTERNAL_METRIC_TYPE_1) | |
11523 | ? vty_out(vty, "%-16s", "E1") | |
11524 | : vty_out(vty, "%-16s", "E2"); | |
11525 | vty_out(vty, "%-11d", mval); | |
11526 | ||
11527 | vty_out(vty, "%-12u", aggr->tag); | |
11528 | ||
11529 | vty_out(vty, "%-5ld\n", | |
11530 | OSPF_EXTERNAL_RT_COUNT(aggr)); | |
11531 | ||
11532 | if (OSPF_EXTERNAL_RT_COUNT(aggr) && detail) { | |
11533 | vty_out(vty, | |
11534 | "Matched External routes:\n"); | |
11535 | hash_walk( | |
11536 | aggr->match_extnl_hash, | |
11537 | ospf_vty_external_rt_walkcb, | |
11538 | vty); | |
11539 | vty_out(vty, "\n"); | |
11540 | } | |
11541 | ||
11542 | vty_out(vty, "\n"); | |
11543 | } | |
11544 | } | |
11545 | ||
11546 | if (uj) { | |
44076f4d RW |
11547 | if (use_vrf) |
11548 | json_object_object_add(json, ospf_get_name(ospf), | |
11549 | json_vrf); | |
53e44d05 | 11550 | } else |
11551 | vty_out(vty, "\n"); | |
11552 | ||
11553 | return CMD_SUCCESS; | |
11554 | } | |
11555 | ||
11556 | DEFUN (show_ip_ospf_external_aggregator, | |
11557 | show_ip_ospf_external_aggregator_cmd, | |
11558 | "show ip ospf [vrf <NAME|all>] summary-address [detail] [json]", | |
11559 | SHOW_STR IP_STR | |
11560 | "OSPF information\n" | |
11561 | VRF_CMD_HELP_STR | |
11562 | "All VRFs\n" | |
11563 | "Show external summary addresses\n" | |
11564 | "Detailed informtion\n" | |
11565 | JSON_STR) | |
11566 | { | |
11567 | char *vrf_name = NULL; | |
11568 | bool all_vrf = false; | |
11569 | int ret = CMD_SUCCESS; | |
11570 | int idx_vrf = 0; | |
11571 | int idx = 0; | |
11572 | uint8_t use_vrf = 0; | |
11573 | bool uj = use_json(argc, argv); | |
11574 | struct ospf *ospf = NULL; | |
11575 | json_object *json = NULL; | |
11576 | struct listnode *node = NULL; | |
11577 | int inst = 0; | |
11578 | bool detail = false; | |
11579 | ||
11580 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); | |
11581 | ||
11582 | if (argv_find(argv, argc, "detail", &idx)) | |
11583 | detail = true; | |
11584 | ||
11585 | if (uj) | |
11586 | json = json_object_new_object(); | |
11587 | ||
11588 | /* vrf input is provided */ | |
11589 | if (vrf_name) { | |
11590 | use_vrf = 1; | |
11591 | if (all_vrf) { | |
11592 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
11593 | if (!ospf->oi_running) | |
11594 | continue; | |
11595 | ret = ospf_show_summary_address( | |
11596 | vty, ospf, use_vrf, json, uj, detail); | |
11597 | } | |
11598 | ||
11599 | if (uj) { | |
11600 | vty_out(vty, "%s\n", | |
11601 | json_object_to_json_string_ext( | |
11602 | json, JSON_C_TO_STRING_PRETTY)); | |
11603 | json_object_free(json); | |
11604 | } | |
11605 | ||
11606 | return ret; | |
11607 | } | |
11608 | ||
11609 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
11610 | ||
11611 | if (ospf == NULL || !ospf->oi_running) { | |
11612 | if (uj) { | |
11613 | vty_out(vty, "%s\n", | |
11614 | json_object_to_json_string_ext( | |
11615 | json, JSON_C_TO_STRING_PRETTY)); | |
11616 | json_object_free(json); | |
11617 | } else | |
11618 | vty_out(vty, "%% OSPF instance not found\n"); | |
11619 | ||
11620 | return CMD_SUCCESS; | |
11621 | } | |
fddbafcc | 11622 | ospf_show_summary_address(vty, ospf, use_vrf, json, uj, detail); |
53e44d05 | 11623 | |
11624 | } else { | |
11625 | /* Default Vrf */ | |
11626 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
11627 | if (ospf == NULL || !ospf->oi_running) { | |
11628 | if (uj) { | |
11629 | vty_out(vty, "%s\n", | |
11630 | json_object_to_json_string_ext( | |
11631 | json, JSON_C_TO_STRING_PRETTY)); | |
11632 | json_object_free(json); | |
11633 | } else | |
11634 | vty_out(vty, "%% OSPF instance not found\n"); | |
11635 | ||
11636 | return CMD_SUCCESS; | |
11637 | } | |
11638 | ||
11639 | ospf_show_summary_address(vty, ospf, use_vrf, json, uj, detail); | |
11640 | } | |
11641 | ||
11642 | if (uj) { | |
11643 | vty_out(vty, "%s\n", json_object_to_json_string_ext( | |
11644 | json, JSON_C_TO_STRING_PRETTY)); | |
11645 | json_object_free(json); | |
11646 | } | |
11647 | return CMD_SUCCESS; | |
11648 | } | |
718e3744 | 11649 | |
2b64873d DL |
11650 | static const char *const ospf_int_type_str[] = { |
11651 | "unknown", /* should never be used. */ | |
11652 | "point-to-point", | |
11653 | "broadcast", | |
11654 | "non-broadcast", | |
11655 | "point-to-multipoint", | |
11656 | "virtual-link", /* should never be used. */ | |
11657 | "loopback" | |
11658 | }; | |
718e3744 | 11659 | |
83cc5a1f DE |
11660 | static const char *interface_config_auth_str(struct ospf_if_params *params) |
11661 | { | |
11662 | if (!OSPF_IF_PARAM_CONFIGURED(params, auth_type) | |
11663 | || params->auth_type == OSPF_AUTH_NOTSET) | |
11664 | return NULL; | |
11665 | ||
11666 | /* Translation tables are not that much help | |
11667 | * here due to syntax | |
11668 | * of the simple option */ | |
11669 | switch (params->auth_type) { | |
11670 | ||
11671 | case OSPF_AUTH_NULL: | |
11672 | return " null"; | |
11673 | ||
11674 | case OSPF_AUTH_SIMPLE: | |
11675 | return ""; | |
11676 | ||
11677 | case OSPF_AUTH_CRYPTOGRAPHIC: | |
11678 | return " message-digest"; | |
11679 | } | |
11680 | ||
11681 | return ""; | |
11682 | } | |
11683 | ||
545f0503 | 11684 | static int config_write_interface_one(struct vty *vty, struct vrf *vrf) |
d62a17ae | 11685 | { |
f4e14fdb | 11686 | struct listnode *node; |
d62a17ae | 11687 | struct interface *ifp; |
11688 | struct crypt_key *ck; | |
d62a17ae | 11689 | struct route_node *rn = NULL; |
11690 | struct ospf_if_params *params; | |
83cc5a1f | 11691 | const char *auth_str; |
43b8d1d8 | 11692 | int write = 0; |
d62a17ae | 11693 | |
545f0503 | 11694 | FOR_ALL_INTERFACES (vrf, ifp) { |
d62a17ae | 11695 | |
545f0503 CS |
11696 | if (memcmp(ifp->name, "VLINK", 5) == 0) |
11697 | continue; | |
35955c14 | 11698 | |
545f0503 | 11699 | vty_frame(vty, "!\n"); |
a36898e7 | 11700 | if (ifp->vrf_id == VRF_DEFAULT) |
545f0503 CS |
11701 | vty_frame(vty, "interface %s\n", ifp->name); |
11702 | else | |
996c9314 LB |
11703 | vty_frame(vty, "interface %s vrf %s\n", ifp->name, |
11704 | vrf->name); | |
545f0503 CS |
11705 | if (ifp->desc) |
11706 | vty_out(vty, " description %s\n", ifp->desc); | |
d62a17ae | 11707 | |
545f0503 | 11708 | write++; |
43b8d1d8 | 11709 | |
545f0503 | 11710 | params = IF_DEF_PARAMS(ifp); |
43b8d1d8 | 11711 | |
545f0503 CS |
11712 | do { |
11713 | /* Interface Network print. */ | |
11714 | if (OSPF_IF_PARAM_CONFIGURED(params, type) | |
11715 | && params->type != OSPF_IFTYPE_LOOPBACK) { | |
996c9314 | 11716 | if (params->type != ospf_default_iftype(ifp)) { |
545f0503 CS |
11717 | vty_out(vty, " ip ospf network %s", |
11718 | ospf_int_type_str | |
996c9314 | 11719 | [params->type]); |
bc97889b AL |
11720 | if (params->type |
11721 | == OSPF_IFTYPE_POINTOPOINT | |
11722 | && params->ptp_dmvpn) | |
11723 | vty_out(vty, " dmvpn"); | |
e425c019 | 11724 | if (params != IF_DEF_PARAMS(ifp) && rn) |
96b663a3 MS |
11725 | vty_out(vty, " %pI4", |
11726 | &rn->p.u.prefix4); | |
545f0503 | 11727 | vty_out(vty, "\n"); |
d62a17ae | 11728 | } |
545f0503 | 11729 | } |
d62a17ae | 11730 | |
545f0503 | 11731 | /* OSPF interface authentication print */ |
83cc5a1f DE |
11732 | auth_str = interface_config_auth_str(params); |
11733 | if (auth_str) { | |
545f0503 CS |
11734 | vty_out(vty, " ip ospf authentication%s", |
11735 | auth_str); | |
e425c019 | 11736 | if (params != IF_DEF_PARAMS(ifp) && rn) |
96b663a3 MS |
11737 | vty_out(vty, " %pI4", |
11738 | &rn->p.u.prefix4); | |
545f0503 CS |
11739 | vty_out(vty, "\n"); |
11740 | } | |
d62a17ae | 11741 | |
545f0503 CS |
11742 | /* Simple Authentication Password print. */ |
11743 | if (OSPF_IF_PARAM_CONFIGURED(params, auth_simple) | |
996c9314 | 11744 | && params->auth_simple[0] != '\0') { |
545f0503 CS |
11745 | vty_out(vty, " ip ospf authentication-key %s", |
11746 | params->auth_simple); | |
e425c019 | 11747 | if (params != IF_DEF_PARAMS(ifp) && rn) |
96b663a3 MS |
11748 | vty_out(vty, " %pI4", |
11749 | &rn->p.u.prefix4); | |
545f0503 CS |
11750 | vty_out(vty, "\n"); |
11751 | } | |
c7fd72d2 | 11752 | |
545f0503 CS |
11753 | /* Cryptographic Authentication Key print. */ |
11754 | if (params && params->auth_crypt) { | |
996c9314 LB |
11755 | for (ALL_LIST_ELEMENTS_RO(params->auth_crypt, |
11756 | node, ck)) { | |
545f0503 CS |
11757 | vty_out(vty, |
11758 | " ip ospf message-digest-key %d md5 %s", | |
996c9314 | 11759 | ck->key_id, ck->auth_key); |
e425c019 | 11760 | if (params != IF_DEF_PARAMS(ifp) && rn) |
96b663a3 MS |
11761 | vty_out(vty, " %pI4", |
11762 | &rn->p.u.prefix4); | |
c7fd72d2 CS |
11763 | vty_out(vty, "\n"); |
11764 | } | |
545f0503 | 11765 | } |
d62a17ae | 11766 | |
545f0503 | 11767 | /* Interface Output Cost print. */ |
996c9314 | 11768 | if (OSPF_IF_PARAM_CONFIGURED(params, output_cost_cmd)) { |
545f0503 CS |
11769 | vty_out(vty, " ip ospf cost %u", |
11770 | params->output_cost_cmd); | |
e425c019 | 11771 | if (params != IF_DEF_PARAMS(ifp) && rn) |
96b663a3 MS |
11772 | vty_out(vty, " %pI4", |
11773 | &rn->p.u.prefix4); | |
545f0503 CS |
11774 | vty_out(vty, "\n"); |
11775 | } | |
d62a17ae | 11776 | |
545f0503 CS |
11777 | /* Hello Interval print. */ |
11778 | if (OSPF_IF_PARAM_CONFIGURED(params, v_hello) | |
996c9314 | 11779 | && params->v_hello != OSPF_HELLO_INTERVAL_DEFAULT) { |
545f0503 CS |
11780 | vty_out(vty, " ip ospf hello-interval %u", |
11781 | params->v_hello); | |
e425c019 | 11782 | if (params != IF_DEF_PARAMS(ifp) && rn) |
96b663a3 MS |
11783 | vty_out(vty, " %pI4", |
11784 | &rn->p.u.prefix4); | |
545f0503 CS |
11785 | vty_out(vty, "\n"); |
11786 | } | |
d62a17ae | 11787 | |
d62a17ae | 11788 | |
545f0503 CS |
11789 | /* Router Dead Interval print. */ |
11790 | if (OSPF_IF_PARAM_CONFIGURED(params, v_wait) | |
2c1f2d2a | 11791 | && params->is_v_wait_set) { |
545f0503 | 11792 | vty_out(vty, " ip ospf dead-interval "); |
d62a17ae | 11793 | |
545f0503 CS |
11794 | /* fast hello ? */ |
11795 | if (OSPF_IF_PARAM_CONFIGURED(params, | |
996c9314 | 11796 | fast_hello)) |
545f0503 CS |
11797 | vty_out(vty, |
11798 | "minimal hello-multiplier %d", | |
11799 | params->fast_hello); | |
11800 | else | |
996c9314 | 11801 | vty_out(vty, "%u", params->v_wait); |
d62a17ae | 11802 | |
e425c019 | 11803 | if (params != IF_DEF_PARAMS(ifp) && rn) |
96b663a3 MS |
11804 | vty_out(vty, " %pI4", |
11805 | &rn->p.u.prefix4); | |
545f0503 CS |
11806 | vty_out(vty, "\n"); |
11807 | } | |
d62a17ae | 11808 | |
545f0503 CS |
11809 | /* Router Priority print. */ |
11810 | if (OSPF_IF_PARAM_CONFIGURED(params, priority) | |
996c9314 LB |
11811 | && params->priority |
11812 | != OSPF_ROUTER_PRIORITY_DEFAULT) { | |
545f0503 CS |
11813 | vty_out(vty, " ip ospf priority %u", |
11814 | params->priority); | |
e425c019 | 11815 | if (params != IF_DEF_PARAMS(ifp) && rn) |
96b663a3 MS |
11816 | vty_out(vty, " %pI4", |
11817 | &rn->p.u.prefix4); | |
545f0503 CS |
11818 | vty_out(vty, "\n"); |
11819 | } | |
d62a17ae | 11820 | |
545f0503 CS |
11821 | /* Retransmit Interval print. */ |
11822 | if (OSPF_IF_PARAM_CONFIGURED(params, | |
996c9314 LB |
11823 | retransmit_interval) |
11824 | && params->retransmit_interval | |
11825 | != OSPF_RETRANSMIT_INTERVAL_DEFAULT) { | |
545f0503 CS |
11826 | vty_out(vty, " ip ospf retransmit-interval %u", |
11827 | params->retransmit_interval); | |
e425c019 | 11828 | if (params != IF_DEF_PARAMS(ifp) && rn) |
96b663a3 MS |
11829 | vty_out(vty, " %pI4", |
11830 | &rn->p.u.prefix4); | |
545f0503 CS |
11831 | vty_out(vty, "\n"); |
11832 | } | |
d62a17ae | 11833 | |
545f0503 | 11834 | /* Transmit Delay print. */ |
996c9314 LB |
11835 | if (OSPF_IF_PARAM_CONFIGURED(params, transmit_delay) |
11836 | && params->transmit_delay | |
11837 | != OSPF_TRANSMIT_DELAY_DEFAULT) { | |
545f0503 CS |
11838 | vty_out(vty, " ip ospf transmit-delay %u", |
11839 | params->transmit_delay); | |
e425c019 | 11840 | if (params != IF_DEF_PARAMS(ifp) && rn) |
96b663a3 MS |
11841 | vty_out(vty, " %pI4", |
11842 | &rn->p.u.prefix4); | |
545f0503 CS |
11843 | vty_out(vty, "\n"); |
11844 | } | |
d62a17ae | 11845 | |
545f0503 CS |
11846 | /* Area print. */ |
11847 | if (OSPF_IF_PARAM_CONFIGURED(params, if_area)) { | |
409f98ab | 11848 | if (ospf_instance) |
545f0503 | 11849 | vty_out(vty, " ip ospf %d", |
409f98ab | 11850 | ospf_instance); |
545f0503 CS |
11851 | else |
11852 | vty_out(vty, " ip ospf"); | |
d62a17ae | 11853 | |
1f9d4e3d | 11854 | char buf[INET_ADDRSTRLEN]; |
d62a17ae | 11855 | |
996c9314 LB |
11856 | area_id2str(buf, sizeof(buf), ¶ms->if_area, |
11857 | params->if_area_id_fmt); | |
545f0503 | 11858 | vty_out(vty, " area %s", buf); |
e425c019 | 11859 | if (params != IF_DEF_PARAMS(ifp) && rn) |
96b663a3 MS |
11860 | vty_out(vty, " %pI4", |
11861 | &rn->p.u.prefix4); | |
545f0503 CS |
11862 | vty_out(vty, "\n"); |
11863 | } | |
d62a17ae | 11864 | |
545f0503 | 11865 | /* bfd print. */ |
659f4e40 | 11866 | if (params && params->bfd_config) |
545f0503 | 11867 | ospf_bfd_write_config(vty, params); |
d62a17ae | 11868 | |
545f0503 CS |
11869 | /* MTU ignore print. */ |
11870 | if (OSPF_IF_PARAM_CONFIGURED(params, mtu_ignore) | |
996c9314 | 11871 | && params->mtu_ignore != OSPF_MTU_IGNORE_DEFAULT) { |
545f0503 CS |
11872 | if (params->mtu_ignore == 0) |
11873 | vty_out(vty, " no ip ospf mtu-ignore"); | |
11874 | else | |
11875 | vty_out(vty, " ip ospf mtu-ignore"); | |
e425c019 | 11876 | if (params != IF_DEF_PARAMS(ifp) && rn) |
96b663a3 MS |
11877 | vty_out(vty, " %pI4", |
11878 | &rn->p.u.prefix4); | |
545f0503 CS |
11879 | vty_out(vty, "\n"); |
11880 | } | |
a8b828f3 | 11881 | |
3eec4ee0 IR |
11882 | if (OSPF_IF_PARAM_CONFIGURED(params, |
11883 | passive_interface)) { | |
82f0277b IR |
11884 | vty_out(vty, " %sip ospf passive", |
11885 | params->passive_interface | |
11886 | == OSPF_IF_ACTIVE | |
11887 | ? "no " | |
11888 | : ""); | |
3eec4ee0 IR |
11889 | if (params != IF_DEF_PARAMS(ifp) && rn) |
11890 | vty_out(vty, " %pI4", &rn->p.u.prefix4); | |
11891 | vty_out(vty, "\n"); | |
11892 | } | |
11893 | ||
132a782e | 11894 | /* LDP-Sync print */ |
11895 | if (params && params->ldp_sync_info) | |
11896 | ospf_ldp_sync_if_write_config(vty, params); | |
d62a17ae | 11897 | |
545f0503 CS |
11898 | while (1) { |
11899 | if (rn == NULL) | |
996c9314 | 11900 | rn = route_top(IF_OIFS_PARAMS(ifp)); |
545f0503 CS |
11901 | else |
11902 | rn = route_next(rn); | |
43b8d1d8 | 11903 | |
545f0503 CS |
11904 | if (rn == NULL) |
11905 | break; | |
11906 | params = rn->info; | |
11907 | if (params != NULL) | |
11908 | break; | |
11909 | } | |
11910 | } while (rn); | |
43b8d1d8 | 11911 | |
545f0503 CS |
11912 | ospf_opaque_config_write_if(vty, ifp); |
11913 | ||
07679ad9 | 11914 | vty_endframe(vty, "exit\n!\n"); |
b5a8894d | 11915 | } |
545f0503 | 11916 | |
d62a17ae | 11917 | return write; |
718e3744 | 11918 | } |
11919 | ||
43b8d1d8 CS |
11920 | /* Configuration write function for ospfd. */ |
11921 | static int config_write_interface(struct vty *vty) | |
11922 | { | |
11923 | int write = 0; | |
545f0503 | 11924 | struct vrf *vrf = NULL; |
43b8d1d8 | 11925 | |
545f0503 CS |
11926 | /* Display all VRF aware OSPF interface configuration */ |
11927 | RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) { | |
11928 | write += config_write_interface_one(vty, vrf); | |
11929 | } | |
43b8d1d8 CS |
11930 | |
11931 | return write; | |
11932 | } | |
11933 | ||
d62a17ae | 11934 | static int config_write_network_area(struct vty *vty, struct ospf *ospf) |
718e3744 | 11935 | { |
d62a17ae | 11936 | struct route_node *rn; |
fc746f1c | 11937 | char buf[INET_ADDRSTRLEN]; |
718e3744 | 11938 | |
d62a17ae | 11939 | /* `network area' print. */ |
11940 | for (rn = route_top(ospf->networks); rn; rn = route_next(rn)) | |
11941 | if (rn->info) { | |
11942 | struct ospf_network *n = rn->info; | |
718e3744 | 11943 | |
d62a17ae | 11944 | /* Create Area ID string by specified Area ID format. */ |
11945 | if (n->area_id_fmt == OSPF_AREA_ID_FMT_DOTTEDQUAD) | |
fc746f1c | 11946 | inet_ntop(AF_INET, &n->area_id, buf, |
1f9d4e3d | 11947 | sizeof(buf)); |
d62a17ae | 11948 | else |
fc746f1c QY |
11949 | snprintf(buf, sizeof(buf), "%lu", |
11950 | (unsigned long int)ntohl( | |
11951 | n->area_id.s_addr)); | |
718e3744 | 11952 | |
d62a17ae | 11953 | /* Network print. */ |
96b663a3 | 11954 | vty_out(vty, " network %pFX area %s\n", &rn->p, buf); |
d62a17ae | 11955 | } |
718e3744 | 11956 | |
d62a17ae | 11957 | return 0; |
718e3744 | 11958 | } |
11959 | ||
d62a17ae | 11960 | static int config_write_ospf_area(struct vty *vty, struct ospf *ospf) |
718e3744 | 11961 | { |
d62a17ae | 11962 | struct listnode *node; |
11963 | struct ospf_area *area; | |
fc746f1c | 11964 | char buf[INET_ADDRSTRLEN]; |
718e3744 | 11965 | |
d62a17ae | 11966 | /* Area configuration print. */ |
11967 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) { | |
11968 | struct route_node *rn1; | |
718e3744 | 11969 | |
fc746f1c | 11970 | area_id2str(buf, sizeof(buf), &area->area_id, |
d62a17ae | 11971 | area->area_id_fmt); |
718e3744 | 11972 | |
d62a17ae | 11973 | if (area->auth_type != OSPF_AUTH_NULL) { |
11974 | if (area->auth_type == OSPF_AUTH_SIMPLE) | |
11975 | vty_out(vty, " area %s authentication\n", buf); | |
11976 | else | |
11977 | vty_out(vty, | |
11978 | " area %s authentication message-digest\n", | |
11979 | buf); | |
11980 | } | |
718e3744 | 11981 | |
d62a17ae | 11982 | if (area->shortcut_configured != OSPF_SHORTCUT_DEFAULT) |
11983 | vty_out(vty, " area %s shortcut %s\n", buf, | |
11984 | ospf_shortcut_mode_str | |
11985 | [area->shortcut_configured]); | |
11986 | ||
11987 | if ((area->external_routing == OSPF_AREA_STUB) | |
11988 | || (area->external_routing == OSPF_AREA_NSSA)) { | |
7ef56a73 | 11989 | if (area->external_routing == OSPF_AREA_STUB) { |
d62a17ae | 11990 | vty_out(vty, " area %s stub", buf); |
7ef56a73 CS |
11991 | if (area->no_summary) |
11992 | vty_out(vty, " no-summary\n"); | |
11993 | vty_out(vty, "\n"); | |
11994 | } else if (area->external_routing == OSPF_AREA_NSSA) { | |
d62a17ae | 11995 | switch (area->NSSATranslatorRole) { |
11996 | case OSPF_NSSA_ROLE_NEVER: | |
7ef56a73 CS |
11997 | vty_out(vty, |
11998 | " area %s nssa translate-never\n", | |
11999 | buf); | |
d62a17ae | 12000 | break; |
12001 | case OSPF_NSSA_ROLE_ALWAYS: | |
7ef56a73 CS |
12002 | vty_out(vty, |
12003 | " area %s nssa translate-always\n", | |
12004 | buf); | |
d62a17ae | 12005 | break; |
2643b2bc CS |
12006 | case OSPF_NSSA_ROLE_CANDIDATE: |
12007 | vty_out(vty, " area %s nssa \n", buf); | |
12008 | break; | |
d62a17ae | 12009 | } |
7ef56a73 CS |
12010 | if (area->no_summary) |
12011 | vty_out(vty, | |
12012 | " area %s nssa no-summary\n", | |
12013 | buf); | |
c317eddb | 12014 | if (area->suppress_fa) |
12015 | vty_out(vty, | |
12016 | " area %s nssa suppress-fa\n", | |
12017 | buf); | |
d62a17ae | 12018 | } |
718e3744 | 12019 | |
d62a17ae | 12020 | if (area->default_cost != 1) |
12021 | vty_out(vty, " area %s default-cost %d\n", buf, | |
12022 | area->default_cost); | |
12023 | } | |
718e3744 | 12024 | |
d62a17ae | 12025 | for (rn1 = route_top(area->ranges); rn1; rn1 = route_next(rn1)) |
12026 | if (rn1->info) { | |
12027 | struct ospf_area_range *range = rn1->info; | |
718e3744 | 12028 | |
96b663a3 MS |
12029 | vty_out(vty, " area %s range %pFX", buf, |
12030 | &rn1->p); | |
718e3744 | 12031 | |
d62a17ae | 12032 | if (range->cost_config |
12033 | != OSPF_AREA_RANGE_COST_UNSPEC) | |
12034 | vty_out(vty, " cost %d", | |
12035 | range->cost_config); | |
718e3744 | 12036 | |
d62a17ae | 12037 | if (!CHECK_FLAG(range->flags, |
12038 | OSPF_AREA_RANGE_ADVERTISE)) | |
12039 | vty_out(vty, " not-advertise"); | |
718e3744 | 12040 | |
d62a17ae | 12041 | if (CHECK_FLAG(range->flags, |
12042 | OSPF_AREA_RANGE_SUBSTITUTE)) | |
96b663a3 MS |
12043 | vty_out(vty, " substitute %pI4/%d", |
12044 | &range->subst_addr, | |
d62a17ae | 12045 | range->subst_masklen); |
12046 | ||
12047 | vty_out(vty, "\n"); | |
12048 | } | |
12049 | ||
12050 | if (EXPORT_NAME(area)) | |
12051 | vty_out(vty, " area %s export-list %s\n", buf, | |
12052 | EXPORT_NAME(area)); | |
12053 | ||
12054 | if (IMPORT_NAME(area)) | |
12055 | vty_out(vty, " area %s import-list %s\n", buf, | |
12056 | IMPORT_NAME(area)); | |
12057 | ||
12058 | if (PREFIX_NAME_IN(area)) | |
12059 | vty_out(vty, " area %s filter-list prefix %s in\n", buf, | |
12060 | PREFIX_NAME_IN(area)); | |
12061 | ||
12062 | if (PREFIX_NAME_OUT(area)) | |
12063 | vty_out(vty, " area %s filter-list prefix %s out\n", | |
12064 | buf, PREFIX_NAME_OUT(area)); | |
12065 | } | |
12066 | ||
12067 | return 0; | |
718e3744 | 12068 | } |
12069 | ||
d62a17ae | 12070 | static int config_write_ospf_nbr_nbma(struct vty *vty, struct ospf *ospf) |
718e3744 | 12071 | { |
d62a17ae | 12072 | struct ospf_nbr_nbma *nbr_nbma; |
12073 | struct route_node *rn; | |
718e3744 | 12074 | |
d62a17ae | 12075 | /* Static Neighbor configuration print. */ |
12076 | for (rn = route_top(ospf->nbr_nbma); rn; rn = route_next(rn)) | |
12077 | if ((nbr_nbma = rn->info)) { | |
96b663a3 | 12078 | vty_out(vty, " neighbor %pI4", &nbr_nbma->addr); |
718e3744 | 12079 | |
d62a17ae | 12080 | if (nbr_nbma->priority |
12081 | != OSPF_NEIGHBOR_PRIORITY_DEFAULT) | |
12082 | vty_out(vty, " priority %d", | |
12083 | nbr_nbma->priority); | |
718e3744 | 12084 | |
d62a17ae | 12085 | if (nbr_nbma->v_poll != OSPF_POLL_INTERVAL_DEFAULT) |
12086 | vty_out(vty, " poll-interval %d", | |
12087 | nbr_nbma->v_poll); | |
12088 | ||
12089 | vty_out(vty, "\n"); | |
12090 | } | |
12091 | ||
12092 | return 0; | |
12093 | } | |
12094 | ||
12095 | static int config_write_virtual_link(struct vty *vty, struct ospf *ospf) | |
12096 | { | |
12097 | struct listnode *node; | |
12098 | struct ospf_vl_data *vl_data; | |
83cc5a1f | 12099 | const char *auth_str; |
d62a17ae | 12100 | char buf[INET_ADDRSTRLEN]; |
12101 | ||
12102 | /* Virtual-Link print */ | |
12103 | for (ALL_LIST_ELEMENTS_RO(ospf->vlinks, node, vl_data)) { | |
12104 | struct listnode *n2; | |
12105 | struct crypt_key *ck; | |
12106 | struct ospf_interface *oi; | |
12107 | ||
12108 | if (vl_data != NULL) { | |
d62a17ae | 12109 | area_id2str(buf, sizeof(buf), &vl_data->vl_area_id, |
12110 | vl_data->vl_area_id_fmt); | |
12111 | oi = vl_data->vl_oi; | |
12112 | ||
12113 | /* timers */ | |
12114 | if (OSPF_IF_PARAM(oi, v_hello) | |
12115 | != OSPF_HELLO_INTERVAL_DEFAULT | |
12116 | || OSPF_IF_PARAM(oi, v_wait) | |
12117 | != OSPF_ROUTER_DEAD_INTERVAL_DEFAULT | |
12118 | || OSPF_IF_PARAM(oi, retransmit_interval) | |
12119 | != OSPF_RETRANSMIT_INTERVAL_DEFAULT | |
12120 | || OSPF_IF_PARAM(oi, transmit_delay) | |
12121 | != OSPF_TRANSMIT_DELAY_DEFAULT) | |
12122 | vty_out(vty, | |
96b663a3 MS |
12123 | " area %s virtual-link %pI4 hello-interval %d retransmit-interval %d transmit-delay %d dead-interval %d\n", |
12124 | buf, &vl_data->vl_peer, | |
d62a17ae | 12125 | OSPF_IF_PARAM(oi, v_hello), |
12126 | OSPF_IF_PARAM(oi, retransmit_interval), | |
12127 | OSPF_IF_PARAM(oi, transmit_delay), | |
12128 | OSPF_IF_PARAM(oi, v_wait)); | |
12129 | else | |
96b663a3 MS |
12130 | vty_out(vty, " area %s virtual-link %pI4\n", buf, |
12131 | &vl_data->vl_peer); | |
83cc5a1f DE |
12132 | /* Auth type */ |
12133 | auth_str = interface_config_auth_str( | |
12134 | IF_DEF_PARAMS(oi->ifp)); | |
12135 | if (auth_str) | |
12136 | vty_out(vty, | |
12137 | " area %s virtual-link %pI4 authentication%s\n", | |
12138 | buf, &vl_data->vl_peer, auth_str); | |
d62a17ae | 12139 | /* Auth key */ |
12140 | if (IF_DEF_PARAMS(vl_data->vl_oi->ifp)->auth_simple[0] | |
12141 | != '\0') | |
12142 | vty_out(vty, | |
96b663a3 MS |
12143 | " area %s virtual-link %pI4 authentication-key %s\n", |
12144 | buf, &vl_data->vl_peer, | |
d62a17ae | 12145 | IF_DEF_PARAMS(vl_data->vl_oi->ifp) |
12146 | ->auth_simple); | |
12147 | /* md5 keys */ | |
12148 | for (ALL_LIST_ELEMENTS_RO( | |
12149 | IF_DEF_PARAMS(vl_data->vl_oi->ifp) | |
12150 | ->auth_crypt, | |
12151 | n2, ck)) | |
12152 | vty_out(vty, | |
96b663a3 MS |
12153 | " area %s virtual-link %pI4 message-digest-key %d md5 %s\n", |
12154 | buf, &vl_data->vl_peer, | |
d62a17ae | 12155 | ck->key_id, ck->auth_key); |
12156 | } | |
12157 | } | |
12158 | ||
12159 | return 0; | |
718e3744 | 12160 | } |
12161 | ||
6b0655a2 | 12162 | |
d62a17ae | 12163 | static int config_write_ospf_redistribute(struct vty *vty, struct ospf *ospf) |
718e3744 | 12164 | { |
d62a17ae | 12165 | int type; |
718e3744 | 12166 | |
d62a17ae | 12167 | /* redistribute print. */ |
12168 | for (type = 0; type < ZEBRA_ROUTE_MAX; type++) { | |
12169 | struct list *red_list; | |
12170 | struct listnode *node; | |
12171 | struct ospf_redist *red; | |
718e3744 | 12172 | |
d62a17ae | 12173 | red_list = ospf->redist[type]; |
12174 | if (!red_list) | |
12175 | continue; | |
7c8ff89e | 12176 | |
d62a17ae | 12177 | for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) { |
12178 | vty_out(vty, " redistribute %s", | |
12179 | zebra_route_string(type)); | |
12180 | if (red->instance) | |
12181 | vty_out(vty, " %d", red->instance); | |
7c8ff89e | 12182 | |
d62a17ae | 12183 | if (red->dmetric.value >= 0) |
12184 | vty_out(vty, " metric %d", red->dmetric.value); | |
7c8ff89e | 12185 | |
d62a17ae | 12186 | if (red->dmetric.type == EXTERNAL_METRIC_TYPE_1) |
12187 | vty_out(vty, " metric-type 1"); | |
7c8ff89e | 12188 | |
d62a17ae | 12189 | if (ROUTEMAP_NAME(red)) |
12190 | vty_out(vty, " route-map %s", | |
12191 | ROUTEMAP_NAME(red)); | |
7c8ff89e | 12192 | |
d62a17ae | 12193 | vty_out(vty, "\n"); |
12194 | } | |
12195 | } | |
718e3744 | 12196 | |
d62a17ae | 12197 | return 0; |
718e3744 | 12198 | } |
12199 | ||
1ac88792 | 12200 | static int ospf_cfg_write_helper_dis_rtr_walkcb(struct hash_bucket *bucket, |
07b33add | 12201 | void *arg) |
12202 | { | |
1ac88792 | 12203 | struct advRtr *rtr = bucket->data; |
07b33add | 12204 | struct vty *vty = (struct vty *)arg; |
12205 | ||
859bce81 | 12206 | vty_out(vty, " graceful-restart helper enable %pI4\n", |
96b663a3 | 12207 | &rtr->advRtrAddr); |
07b33add | 12208 | return HASHWALK_CONTINUE; |
12209 | } | |
12210 | ||
10514170 RW |
12211 | static void config_write_ospf_gr(struct vty *vty, struct ospf *ospf) |
12212 | { | |
12213 | if (!ospf->gr_info.restart_support) | |
12214 | return; | |
12215 | ||
12216 | if (ospf->gr_info.grace_period == OSPF_DFLT_GRACE_INTERVAL) | |
12217 | vty_out(vty, " graceful-restart\n"); | |
12218 | else | |
12219 | vty_out(vty, " graceful-restart grace-period %u\n", | |
12220 | ospf->gr_info.grace_period); | |
12221 | } | |
12222 | ||
07b33add | 12223 | static int config_write_ospf_gr_helper(struct vty *vty, struct ospf *ospf) |
12224 | { | |
12225 | if (ospf->is_helper_supported) | |
859bce81 | 12226 | vty_out(vty, " graceful-restart helper enable\n"); |
07b33add | 12227 | |
12228 | if (!ospf->strict_lsa_check) | |
96b663a3 MS |
12229 | vty_out(vty, |
12230 | " no graceful-restart helper strict-lsa-checking\n"); | |
07b33add | 12231 | |
12232 | if (ospf->only_planned_restart) | |
12233 | vty_out(vty, " graceful-restart helper planned-only\n"); | |
12234 | ||
12235 | if (ospf->supported_grace_time != OSPF_MAX_GRACE_INTERVAL) | |
12236 | vty_out(vty, | |
12237 | " graceful-restart helper supported-grace-time %d\n", | |
12238 | ospf->supported_grace_time); | |
12239 | ||
12240 | if (OSPF_HELPER_ENABLE_RTR_COUNT(ospf)) { | |
12241 | hash_walk(ospf->enable_rtr_list, | |
12242 | ospf_cfg_write_helper_dis_rtr_walkcb, vty); | |
12243 | } | |
423e71c4 | 12244 | return 0; |
12245 | } | |
12246 | ||
12247 | static int config_write_ospf_external_aggregator(struct vty *vty, | |
12248 | struct ospf *ospf) | |
12249 | { | |
12250 | struct route_node *rn; | |
12251 | ||
12252 | /* print 'summary-address A.B.C.D/M' */ | |
12253 | for (rn = route_top(ospf->rt_aggr_tbl); rn; rn = route_next(rn)) | |
12254 | if (rn->info) { | |
12255 | struct ospf_external_aggr_rt *aggr = rn->info; | |
12256 | ||
12257 | vty_out(vty, " summary-address %pI4/%d ", | |
12258 | &aggr->p.prefix, aggr->p.prefixlen); | |
12259 | if (aggr->tag) | |
12260 | vty_out(vty, " tag %u ", aggr->tag); | |
12261 | ||
12262 | if (CHECK_FLAG(aggr->flags, | |
12263 | OSPF_EXTERNAL_AGGRT_NO_ADVERTISE)) | |
12264 | vty_out(vty, " no-advertise"); | |
12265 | ||
12266 | vty_out(vty, "\n"); | |
12267 | } | |
07b33add | 12268 | |
12269 | return 0; | |
12270 | } | |
12271 | ||
d62a17ae | 12272 | static int config_write_ospf_default_metric(struct vty *vty, struct ospf *ospf) |
718e3744 | 12273 | { |
d62a17ae | 12274 | if (ospf->default_metric != -1) |
12275 | vty_out(vty, " default-metric %d\n", ospf->default_metric); | |
12276 | return 0; | |
718e3744 | 12277 | } |
12278 | ||
d62a17ae | 12279 | static int config_write_ospf_distribute(struct vty *vty, struct ospf *ospf) |
12280 | { | |
12281 | int type; | |
12282 | struct ospf_redist *red; | |
718e3744 | 12283 | |
d62a17ae | 12284 | if (ospf) { |
12285 | /* distribute-list print. */ | |
12286 | for (type = 0; type < ZEBRA_ROUTE_MAX; type++) | |
12287 | if (DISTRIBUTE_NAME(ospf, type)) | |
12288 | vty_out(vty, " distribute-list %s out %s\n", | |
12289 | DISTRIBUTE_NAME(ospf, type), | |
12290 | zebra_route_string(type)); | |
7c8ff89e | 12291 | |
d62a17ae | 12292 | /* default-information print. */ |
12293 | if (ospf->default_originate != DEFAULT_ORIGINATE_NONE) { | |
12294 | vty_out(vty, " default-information originate"); | |
12295 | if (ospf->default_originate == DEFAULT_ORIGINATE_ALWAYS) | |
12296 | vty_out(vty, " always"); | |
718e3744 | 12297 | |
d62a17ae | 12298 | red = ospf_redist_lookup(ospf, DEFAULT_ROUTE, 0); |
12299 | if (red) { | |
12300 | if (red->dmetric.value >= 0) | |
12301 | vty_out(vty, " metric %d", | |
12302 | red->dmetric.value); | |
951da435 | 12303 | |
d62a17ae | 12304 | if (red->dmetric.type == EXTERNAL_METRIC_TYPE_1) |
12305 | vty_out(vty, " metric-type 1"); | |
718e3744 | 12306 | |
d62a17ae | 12307 | if (ROUTEMAP_NAME(red)) |
12308 | vty_out(vty, " route-map %s", | |
12309 | ROUTEMAP_NAME(red)); | |
12310 | } | |
12311 | ||
12312 | vty_out(vty, "\n"); | |
12313 | } | |
12314 | } | |
12315 | ||
12316 | return 0; | |
718e3744 | 12317 | } |
12318 | ||
d62a17ae | 12319 | static int config_write_ospf_distance(struct vty *vty, struct ospf *ospf) |
12320 | { | |
12321 | struct route_node *rn; | |
12322 | struct ospf_distance *odistance; | |
12323 | ||
12324 | if (ospf->distance_all) | |
12325 | vty_out(vty, " distance %d\n", ospf->distance_all); | |
12326 | ||
12327 | if (ospf->distance_intra || ospf->distance_inter | |
12328 | || ospf->distance_external) { | |
12329 | vty_out(vty, " distance ospf"); | |
12330 | ||
12331 | if (ospf->distance_intra) | |
12332 | vty_out(vty, " intra-area %d", ospf->distance_intra); | |
12333 | if (ospf->distance_inter) | |
12334 | vty_out(vty, " inter-area %d", ospf->distance_inter); | |
12335 | if (ospf->distance_external) | |
12336 | vty_out(vty, " external %d", ospf->distance_external); | |
12337 | ||
12338 | vty_out(vty, "\n"); | |
12339 | } | |
12340 | ||
12341 | for (rn = route_top(ospf->distance_table); rn; rn = route_next(rn)) | |
12342 | if ((odistance = rn->info) != NULL) { | |
96b663a3 MS |
12343 | vty_out(vty, " distance %d %pFX %s\n", |
12344 | odistance->distance, &rn->p, | |
d62a17ae | 12345 | odistance->access_list ? odistance->access_list |
12346 | : ""); | |
12347 | } | |
12348 | return 0; | |
718e3744 | 12349 | } |
12350 | ||
43b8d1d8 | 12351 | static int ospf_config_write_one(struct vty *vty, struct ospf *ospf) |
d62a17ae | 12352 | { |
d62a17ae | 12353 | int write = 0; |
12354 | ||
43b8d1d8 CS |
12355 | /* `router ospf' print. */ |
12356 | if (ospf->instance && ospf->name) { | |
996c9314 LB |
12357 | vty_out(vty, "router ospf %d vrf %s\n", ospf->instance, |
12358 | ospf->name); | |
43b8d1d8 | 12359 | } else if (ospf->instance) { |
996c9314 | 12360 | vty_out(vty, "router ospf %d\n", ospf->instance); |
43b8d1d8 | 12361 | } else if (ospf->name) { |
996c9314 | 12362 | vty_out(vty, "router ospf vrf %s\n", ospf->name); |
43b8d1d8 CS |
12363 | } else |
12364 | vty_out(vty, "router ospf\n"); | |
12365 | ||
12366 | if (!ospf->networks) { | |
12367 | write++; | |
b5a8894d | 12368 | return write; |
43b8d1d8 | 12369 | } |
d62a17ae | 12370 | |
43b8d1d8 | 12371 | /* Router ID print. */ |
3a6290bd | 12372 | if (ospf->router_id_static.s_addr != INADDR_ANY) |
96b663a3 MS |
12373 | vty_out(vty, " ospf router-id %pI4\n", |
12374 | &ospf->router_id_static); | |
d62a17ae | 12375 | |
43b8d1d8 CS |
12376 | /* ABR type print. */ |
12377 | if (ospf->abr_type != OSPF_ABR_DEFAULT) | |
12378 | vty_out(vty, " ospf abr-type %s\n", | |
12379 | ospf_abr_type_str[ospf->abr_type]); | |
b5a8894d | 12380 | |
43b8d1d8 CS |
12381 | /* log-adjacency-changes flag print. */ |
12382 | if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES)) { | |
12383 | if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL)) | |
12384 | vty_out(vty, " log-adjacency-changes detail\n"); | |
c572fbfe | 12385 | else if (!SAVE_OSPF_LOG_ADJACENCY_CHANGES) |
43b8d1d8 | 12386 | vty_out(vty, " log-adjacency-changes\n"); |
c572fbfe | 12387 | } else if (SAVE_OSPF_LOG_ADJACENCY_CHANGES) { |
43b8d1d8 CS |
12388 | vty_out(vty, " no log-adjacency-changes\n"); |
12389 | } | |
b5a8894d | 12390 | |
43b8d1d8 CS |
12391 | /* RFC1583 compatibility flag print -- Compatible with CISCO |
12392 | * 12.1. */ | |
12393 | if (CHECK_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE)) | |
12394 | vty_out(vty, " compatible rfc1583\n"); | |
d62a17ae | 12395 | |
43b8d1d8 CS |
12396 | /* auto-cost reference-bandwidth configuration. */ |
12397 | if (ospf->ref_bandwidth != OSPF_DEFAULT_REF_BANDWIDTH) { | |
12398 | vty_out(vty, | |
3efd0893 | 12399 | "! Important: ensure reference bandwidth is consistent across all routers\n"); |
43b8d1d8 CS |
12400 | vty_out(vty, " auto-cost reference-bandwidth %d\n", |
12401 | ospf->ref_bandwidth); | |
12402 | } | |
d62a17ae | 12403 | |
43b8d1d8 CS |
12404 | /* SPF timers print. */ |
12405 | if (ospf->spf_delay != OSPF_SPF_DELAY_DEFAULT | |
12406 | || ospf->spf_holdtime != OSPF_SPF_HOLDTIME_DEFAULT | |
12407 | || ospf->spf_max_holdtime != OSPF_SPF_MAX_HOLDTIME_DEFAULT) | |
996c9314 LB |
12408 | vty_out(vty, " timers throttle spf %d %d %d\n", ospf->spf_delay, |
12409 | ospf->spf_holdtime, ospf->spf_max_holdtime); | |
43b8d1d8 CS |
12410 | |
12411 | /* LSA timers print. */ | |
12412 | if (ospf->min_ls_interval != OSPF_MIN_LS_INTERVAL) | |
12413 | vty_out(vty, " timers throttle lsa all %d\n", | |
12414 | ospf->min_ls_interval); | |
12415 | if (ospf->min_ls_arrival != OSPF_MIN_LS_ARRIVAL) | |
12416 | vty_out(vty, " timers lsa min-arrival %d\n", | |
12417 | ospf->min_ls_arrival); | |
12418 | ||
12419 | /* Write multiplier print. */ | |
12420 | if (ospf->write_oi_count != OSPF_WRITE_INTERFACE_COUNT_DEFAULT) | |
12421 | vty_out(vty, " ospf write-multiplier %d\n", | |
12422 | ospf->write_oi_count); | |
d62a17ae | 12423 | |
3d5b9855 | 12424 | if (ospf->max_multipath != MULTIPATH_NUM) |
12425 | vty_out(vty, " maximum-paths %d\n", ospf->max_multipath); | |
12426 | ||
43b8d1d8 CS |
12427 | /* Max-metric router-lsa print */ |
12428 | config_write_stub_router(vty, ospf); | |
d62a17ae | 12429 | |
43b8d1d8 | 12430 | /* SPF refresh parameters print. */ |
996c9314 LB |
12431 | if (ospf->lsa_refresh_interval != OSPF_LSA_REFRESH_INTERVAL_DEFAULT) |
12432 | vty_out(vty, " refresh timer %d\n", ospf->lsa_refresh_interval); | |
d62a17ae | 12433 | |
43b8d1d8 CS |
12434 | /* Redistribute information print. */ |
12435 | config_write_ospf_redistribute(vty, ospf); | |
d62a17ae | 12436 | |
10514170 RW |
12437 | /* Graceful Restart print */ |
12438 | config_write_ospf_gr(vty, ospf); | |
07b33add | 12439 | config_write_ospf_gr_helper(vty, ospf); |
12440 | ||
423e71c4 | 12441 | /* Print external route aggregation. */ |
12442 | config_write_ospf_external_aggregator(vty, ospf); | |
12443 | ||
43b8d1d8 CS |
12444 | /* passive-interface print. */ |
12445 | if (ospf->passive_interface_default == OSPF_IF_PASSIVE) | |
12446 | vty_out(vty, " passive-interface default\n"); | |
d62a17ae | 12447 | |
a92706bb JU |
12448 | /* proactive-arp print. */ |
12449 | if (ospf->proactive_arp != OSPF_PROACTIVE_ARP_DEFAULT) { | |
12450 | if (ospf->proactive_arp) | |
12451 | vty_out(vty, " proactive-arp\n"); | |
12452 | else | |
12453 | vty_out(vty, " no proactive-arp\n"); | |
12454 | } | |
12455 | ||
7fd0729f | 12456 | /* TI-LFA print. */ |
385a1e07 G |
12457 | if (ospf->ti_lfa_enabled) { |
12458 | if (ospf->ti_lfa_protection_type == OSPF_TI_LFA_NODE_PROTECTION) | |
12459 | vty_out(vty, " fast-reroute ti-lfa node-protection\n"); | |
12460 | else | |
12461 | vty_out(vty, " fast-reroute ti-lfa\n"); | |
12462 | } | |
7fd0729f | 12463 | |
43b8d1d8 CS |
12464 | /* Network area print. */ |
12465 | config_write_network_area(vty, ospf); | |
d62a17ae | 12466 | |
43b8d1d8 CS |
12467 | /* Area config print. */ |
12468 | config_write_ospf_area(vty, ospf); | |
d62a17ae | 12469 | |
43b8d1d8 CS |
12470 | /* static neighbor print. */ |
12471 | config_write_ospf_nbr_nbma(vty, ospf); | |
12472 | ||
12473 | /* Virtual-Link print. */ | |
12474 | config_write_virtual_link(vty, ospf); | |
12475 | ||
12476 | /* Default metric configuration. */ | |
12477 | config_write_ospf_default_metric(vty, ospf); | |
12478 | ||
12479 | /* Distribute-list and default-information print. */ | |
12480 | config_write_ospf_distribute(vty, ospf); | |
12481 | ||
12482 | /* Distance configuration. */ | |
12483 | config_write_ospf_distance(vty, ospf); | |
12484 | ||
12485 | ospf_opaque_config_write_router(vty, ospf); | |
12486 | ||
132a782e | 12487 | /* LDP-Sync print */ |
12488 | ospf_ldp_sync_write_config(vty, ospf); | |
12489 | ||
07679ad9 IR |
12490 | vty_out(vty, "exit\n"); |
12491 | ||
43b8d1d8 CS |
12492 | write++; |
12493 | return write; | |
12494 | } | |
12495 | ||
12496 | /* OSPF configuration write function. */ | |
12497 | static int ospf_config_write(struct vty *vty) | |
12498 | { | |
12499 | struct ospf *ospf; | |
12500 | struct listnode *ospf_node = NULL; | |
12501 | int write = 0; | |
12502 | ||
12503 | if (listcount(om->ospf) == 0) | |
12504 | return write; | |
12505 | ||
12506 | for (ALL_LIST_ELEMENTS_RO(om->ospf, ospf_node, ospf)) { | |
88d77109 CS |
12507 | /* VRF Default check if it is running. |
12508 | * Upon daemon start, there could be default instance | |
12509 | * in absence of 'router ospf'/oi_running is disabled. */ | |
12510 | if (ospf->vrf_id == VRF_DEFAULT && ospf->oi_running) | |
12511 | write += ospf_config_write_one(vty, ospf); | |
12512 | /* For Non-Default VRF simply display the configuration, | |
12513 | * even if it is not oi_running. */ | |
12514 | else if (ospf->vrf_id != VRF_DEFAULT) | |
43b8d1d8 | 12515 | write += ospf_config_write_one(vty, ospf); |
b5a8894d | 12516 | } |
d62a17ae | 12517 | return write; |
12518 | } | |
12519 | ||
12520 | void ospf_vty_show_init(void) | |
12521 | { | |
12522 | /* "show ip ospf" commands. */ | |
12523 | install_element(VIEW_NODE, &show_ip_ospf_cmd); | |
12524 | ||
12525 | install_element(VIEW_NODE, &show_ip_ospf_instance_cmd); | |
12526 | ||
12527 | /* "show ip ospf database" commands. */ | |
a11bce11 | 12528 | install_element(VIEW_NODE, &show_ip_ospf_database_cmd); |
d62a17ae | 12529 | install_element(VIEW_NODE, &show_ip_ospf_database_max_cmd); |
a11bce11 IR |
12530 | install_element(VIEW_NODE, |
12531 | &show_ip_ospf_database_type_adv_router_cmd); | |
d62a17ae | 12532 | install_element(VIEW_NODE, |
12533 | &show_ip_ospf_instance_database_type_adv_router_cmd); | |
12534 | install_element(VIEW_NODE, &show_ip_ospf_instance_database_cmd); | |
12535 | install_element(VIEW_NODE, &show_ip_ospf_instance_database_max_cmd); | |
12536 | ||
12537 | /* "show ip ospf interface" commands. */ | |
12538 | install_element(VIEW_NODE, &show_ip_ospf_interface_cmd); | |
12539 | ||
12540 | install_element(VIEW_NODE, &show_ip_ospf_instance_interface_cmd); | |
c9339663 CS |
12541 | /* "show ip ospf interface traffic */ |
12542 | install_element(VIEW_NODE, &show_ip_ospf_interface_traffic_cmd); | |
d62a17ae | 12543 | |
12544 | /* "show ip ospf neighbor" commands. */ | |
12545 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_int_detail_cmd); | |
12546 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_int_cmd); | |
12547 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_id_cmd); | |
12548 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_detail_all_cmd); | |
12549 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_detail_cmd); | |
12550 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_cmd); | |
12551 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_all_cmd); | |
12552 | ||
12553 | install_element(VIEW_NODE, | |
12554 | &show_ip_ospf_instance_neighbor_int_detail_cmd); | |
12555 | install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_int_cmd); | |
12556 | install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_id_cmd); | |
12557 | install_element(VIEW_NODE, | |
12558 | &show_ip_ospf_instance_neighbor_detail_all_cmd); | |
12559 | install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_detail_cmd); | |
12560 | install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_cmd); | |
12561 | install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_all_cmd); | |
12562 | ||
12563 | /* "show ip ospf route" commands. */ | |
12564 | install_element(VIEW_NODE, &show_ip_ospf_route_cmd); | |
12565 | install_element(VIEW_NODE, &show_ip_ospf_border_routers_cmd); | |
12566 | ||
12567 | install_element(VIEW_NODE, &show_ip_ospf_instance_route_cmd); | |
12568 | install_element(VIEW_NODE, &show_ip_ospf_instance_border_routers_cmd); | |
b5a8894d CS |
12569 | |
12570 | /* "show ip ospf vrfs" commands. */ | |
12571 | install_element(VIEW_NODE, &show_ip_ospf_vrfs_cmd); | |
abd5b8c7 | 12572 | |
12573 | /* "show ip ospf gr-helper details" command */ | |
12574 | install_element(VIEW_NODE, &show_ip_ospf_gr_helper_cmd); | |
718e3744 | 12575 | |
53e44d05 | 12576 | /* "show ip ospf summary-address" command */ |
12577 | install_element(VIEW_NODE, &show_ip_ospf_external_aggregator_cmd); | |
12578 | } | |
6b0655a2 | 12579 | |
718e3744 | 12580 | /* Initialization of OSPF interface. */ |
d62a17ae | 12581 | static void ospf_vty_if_init(void) |
12582 | { | |
12583 | /* Install interface node. */ | |
9da01b0b | 12584 | if_cmd_init(config_write_interface); |
d62a17ae | 12585 | |
12586 | /* "ip ospf authentication" commands. */ | |
12587 | install_element(INTERFACE_NODE, &ip_ospf_authentication_args_addr_cmd); | |
12588 | install_element(INTERFACE_NODE, &ip_ospf_authentication_addr_cmd); | |
12589 | install_element(INTERFACE_NODE, | |
12590 | &no_ip_ospf_authentication_args_addr_cmd); | |
12591 | install_element(INTERFACE_NODE, &no_ip_ospf_authentication_addr_cmd); | |
12592 | install_element(INTERFACE_NODE, &ip_ospf_authentication_key_addr_cmd); | |
12593 | install_element(INTERFACE_NODE, | |
12594 | &no_ip_ospf_authentication_key_authkey_addr_cmd); | |
12595 | install_element(INTERFACE_NODE, | |
12596 | &no_ospf_authentication_key_authkey_addr_cmd); | |
12597 | ||
12598 | /* "ip ospf message-digest-key" commands. */ | |
12599 | install_element(INTERFACE_NODE, &ip_ospf_message_digest_key_cmd); | |
12600 | install_element(INTERFACE_NODE, &no_ip_ospf_message_digest_key_cmd); | |
12601 | ||
12602 | /* "ip ospf cost" commands. */ | |
12603 | install_element(INTERFACE_NODE, &ip_ospf_cost_cmd); | |
12604 | install_element(INTERFACE_NODE, &no_ip_ospf_cost_cmd); | |
12605 | ||
12606 | /* "ip ospf mtu-ignore" commands. */ | |
12607 | install_element(INTERFACE_NODE, &ip_ospf_mtu_ignore_addr_cmd); | |
12608 | install_element(INTERFACE_NODE, &no_ip_ospf_mtu_ignore_addr_cmd); | |
12609 | ||
12610 | /* "ip ospf dead-interval" commands. */ | |
12611 | install_element(INTERFACE_NODE, &ip_ospf_dead_interval_cmd); | |
12612 | install_element(INTERFACE_NODE, | |
12613 | &ip_ospf_dead_interval_minimal_addr_cmd); | |
12614 | install_element(INTERFACE_NODE, &no_ip_ospf_dead_interval_cmd); | |
12615 | ||
12616 | /* "ip ospf hello-interval" commands. */ | |
12617 | install_element(INTERFACE_NODE, &ip_ospf_hello_interval_cmd); | |
12618 | install_element(INTERFACE_NODE, &no_ip_ospf_hello_interval_cmd); | |
12619 | ||
12620 | /* "ip ospf network" commands. */ | |
12621 | install_element(INTERFACE_NODE, &ip_ospf_network_cmd); | |
12622 | install_element(INTERFACE_NODE, &no_ip_ospf_network_cmd); | |
12623 | ||
12624 | /* "ip ospf priority" commands. */ | |
12625 | install_element(INTERFACE_NODE, &ip_ospf_priority_cmd); | |
12626 | install_element(INTERFACE_NODE, &no_ip_ospf_priority_cmd); | |
12627 | ||
12628 | /* "ip ospf retransmit-interval" commands. */ | |
12629 | install_element(INTERFACE_NODE, &ip_ospf_retransmit_interval_addr_cmd); | |
12630 | install_element(INTERFACE_NODE, | |
12631 | &no_ip_ospf_retransmit_interval_addr_cmd); | |
12632 | ||
12633 | /* "ip ospf transmit-delay" commands. */ | |
12634 | install_element(INTERFACE_NODE, &ip_ospf_transmit_delay_addr_cmd); | |
12635 | install_element(INTERFACE_NODE, &no_ip_ospf_transmit_delay_addr_cmd); | |
12636 | ||
12637 | /* "ip ospf area" commands. */ | |
12638 | install_element(INTERFACE_NODE, &ip_ospf_area_cmd); | |
12639 | install_element(INTERFACE_NODE, &no_ip_ospf_area_cmd); | |
12640 | ||
3eec4ee0 IR |
12641 | /* "ip ospf passive" commands. */ |
12642 | install_element(INTERFACE_NODE, &ip_ospf_passive_cmd); | |
12643 | install_element(INTERFACE_NODE, &no_ip_ospf_passive_cmd); | |
12644 | ||
d62a17ae | 12645 | /* These commands are compatibitliy for previous version. */ |
12646 | install_element(INTERFACE_NODE, &ospf_authentication_key_cmd); | |
12647 | install_element(INTERFACE_NODE, &ospf_message_digest_key_cmd); | |
12648 | install_element(INTERFACE_NODE, &no_ospf_message_digest_key_cmd); | |
12649 | install_element(INTERFACE_NODE, &ospf_dead_interval_cmd); | |
12650 | install_element(INTERFACE_NODE, &no_ospf_dead_interval_cmd); | |
12651 | install_element(INTERFACE_NODE, &ospf_hello_interval_cmd); | |
12652 | install_element(INTERFACE_NODE, &no_ospf_hello_interval_cmd); | |
12653 | install_element(INTERFACE_NODE, &ospf_cost_cmd); | |
12654 | install_element(INTERFACE_NODE, &no_ospf_cost_cmd); | |
12655 | install_element(INTERFACE_NODE, &ospf_network_cmd); | |
12656 | install_element(INTERFACE_NODE, &no_ospf_network_cmd); | |
12657 | install_element(INTERFACE_NODE, &ospf_priority_cmd); | |
12658 | install_element(INTERFACE_NODE, &no_ospf_priority_cmd); | |
12659 | install_element(INTERFACE_NODE, &ospf_retransmit_interval_cmd); | |
12660 | install_element(INTERFACE_NODE, &no_ospf_retransmit_interval_cmd); | |
12661 | install_element(INTERFACE_NODE, &ospf_transmit_delay_cmd); | |
12662 | install_element(INTERFACE_NODE, &no_ospf_transmit_delay_cmd); | |
12663 | } | |
12664 | ||
12665 | static void ospf_vty_zebra_init(void) | |
12666 | { | |
12667 | install_element(OSPF_NODE, &ospf_redistribute_source_cmd); | |
12668 | install_element(OSPF_NODE, &no_ospf_redistribute_source_cmd); | |
12669 | install_element(OSPF_NODE, &ospf_redistribute_instance_source_cmd); | |
12670 | install_element(OSPF_NODE, &no_ospf_redistribute_instance_source_cmd); | |
12671 | ||
12672 | install_element(OSPF_NODE, &ospf_distribute_list_out_cmd); | |
12673 | install_element(OSPF_NODE, &no_ospf_distribute_list_out_cmd); | |
12674 | ||
12675 | install_element(OSPF_NODE, &ospf_default_information_originate_cmd); | |
12676 | install_element(OSPF_NODE, &no_ospf_default_information_originate_cmd); | |
12677 | ||
12678 | install_element(OSPF_NODE, &ospf_default_metric_cmd); | |
12679 | install_element(OSPF_NODE, &no_ospf_default_metric_cmd); | |
12680 | ||
12681 | install_element(OSPF_NODE, &ospf_distance_cmd); | |
12682 | install_element(OSPF_NODE, &no_ospf_distance_cmd); | |
12683 | install_element(OSPF_NODE, &no_ospf_distance_ospf_cmd); | |
12684 | install_element(OSPF_NODE, &ospf_distance_ospf_cmd); | |
07b33add | 12685 | |
12686 | /*Ospf garcefull restart helper configurations */ | |
12687 | install_element(OSPF_NODE, &ospf_gr_helper_enable_cmd); | |
12688 | install_element(OSPF_NODE, &no_ospf_gr_helper_enable_cmd); | |
859bce81 RW |
12689 | install_element(OSPF_NODE, &ospf_gr_helper_only_cmd); |
12690 | install_element(OSPF_NODE, &no_ospf_gr_helper_only_cmd); | |
07b33add | 12691 | install_element(OSPF_NODE, &ospf_gr_helper_enable_lsacheck_cmd); |
12692 | install_element(OSPF_NODE, &no_ospf_gr_helper_enable_lsacheck_cmd); | |
12693 | install_element(OSPF_NODE, &ospf_gr_helper_supported_grace_time_cmd); | |
12694 | install_element(OSPF_NODE, &no_ospf_gr_helper_supported_grace_time_cmd); | |
12695 | install_element(OSPF_NODE, &ospf_gr_helper_planned_only_cmd); | |
12696 | install_element(OSPF_NODE, &no_ospf_gr_helper_planned_only_cmd); | |
423e71c4 | 12697 | |
12698 | /* External LSA summarisation config commands.*/ | |
12699 | install_element(OSPF_NODE, &ospf_external_route_aggregation_cmd); | |
12700 | install_element(OSPF_NODE, &no_ospf_external_route_aggregation_cmd); | |
12701 | install_element(OSPF_NODE, | |
12702 | &ospf_external_route_aggregation_no_adrvertise_cmd); | |
12703 | install_element(OSPF_NODE, | |
12704 | &no_ospf_external_route_aggregation_no_adrvertise_cmd); | |
12705 | install_element(OSPF_NODE, &ospf_route_aggregation_timer_cmd); | |
12706 | install_element(OSPF_NODE, &no_ospf_route_aggregation_timer_cmd); | |
718e3744 | 12707 | } |
12708 | ||
612c2c15 | 12709 | static int ospf_config_write(struct vty *vty); |
62b346ee | 12710 | static struct cmd_node ospf_node = { |
f4b8291f | 12711 | .name = "ospf", |
62b346ee | 12712 | .node = OSPF_NODE, |
24389580 | 12713 | .parent_node = CONFIG_NODE, |
62b346ee | 12714 | .prompt = "%s(config-router)# ", |
612c2c15 | 12715 | .config_write = ospf_config_write, |
62b346ee | 12716 | }; |
718e3744 | 12717 | |
d62a17ae | 12718 | static void ospf_interface_clear(struct interface *ifp) |
09f35f8c | 12719 | { |
d62a17ae | 12720 | if (!if_is_operative(ifp)) |
12721 | return; | |
09f35f8c | 12722 | |
d62a17ae | 12723 | if (IS_DEBUG_OSPF(ism, ISM_EVENTS)) |
12724 | zlog_debug("ISM[%s]: clear by reset", ifp->name); | |
09f35f8c | 12725 | |
d62a17ae | 12726 | ospf_if_reset(ifp); |
09f35f8c DS |
12727 | } |
12728 | ||
12729 | DEFUN (clear_ip_ospf_interface, | |
12730 | clear_ip_ospf_interface_cmd, | |
1e81afc3 | 12731 | "clear ip ospf [vrf NAME] interface [IFNAME]", |
09f35f8c DS |
12732 | CLEAR_STR |
12733 | IP_STR | |
12734 | "OSPF information\n" | |
03ed9f02 | 12735 | VRF_CMD_HELP_STR |
09f35f8c DS |
12736 | "Interface information\n" |
12737 | "Interface name\n") | |
12738 | { | |
03ed9f02 PG |
12739 | int idx_ifname = 0; |
12740 | int idx_vrf = 0; | |
d62a17ae | 12741 | struct interface *ifp; |
f4e14fdb | 12742 | struct listnode *node; |
b5a8894d | 12743 | struct ospf *ospf = NULL; |
03ed9f02 PG |
12744 | char *vrf_name = NULL; |
12745 | vrf_id_t vrf_id = VRF_DEFAULT; | |
12746 | struct vrf *vrf = NULL; | |
09f35f8c | 12747 | |
03ed9f02 PG |
12748 | if (argv_find(argv, argc, "vrf", &idx_vrf)) |
12749 | vrf_name = argv[idx_vrf + 1]->arg; | |
12750 | if (vrf_name && strmatch(vrf_name, VRF_DEFAULT_NAME)) | |
12751 | vrf_name = NULL; | |
12752 | if (vrf_name) { | |
12753 | vrf = vrf_lookup_by_name(vrf_name); | |
12754 | if (vrf) | |
12755 | vrf_id = vrf->vrf_id; | |
12756 | } | |
12757 | if (!argv_find(argv, argc, "IFNAME", &idx_ifname)) { | |
12758 | /* Clear all the ospfv2 interfaces. */ | |
f4e14fdb | 12759 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { |
03ed9f02 PG |
12760 | if (vrf_id != ospf->vrf_id) |
12761 | continue; | |
12762 | if (!vrf) | |
12763 | vrf = vrf_lookup_by_id(ospf->vrf_id); | |
451fda4f | 12764 | FOR_ALL_INTERFACES (vrf, ifp) |
b5a8894d CS |
12765 | ospf_interface_clear(ifp); |
12766 | } | |
12767 | } else { | |
12768 | /* Interface name is specified. */ | |
a36898e7 | 12769 | ifp = if_lookup_by_name(argv[idx_ifname]->arg, vrf_id); |
b5a8894d | 12770 | if (ifp == NULL) |
d62a17ae | 12771 | vty_out(vty, "No such interface name\n"); |
12772 | else | |
12773 | ospf_interface_clear(ifp); | |
12774 | } | |
12775 | ||
12776 | return CMD_SUCCESS; | |
09f35f8c DS |
12777 | } |
12778 | ||
d62a17ae | 12779 | void ospf_vty_clear_init(void) |
09f35f8c | 12780 | { |
d62a17ae | 12781 | install_element(ENABLE_NODE, &clear_ip_ospf_interface_cmd); |
f91ce319 MR |
12782 | install_element(ENABLE_NODE, &clear_ip_ospf_process_cmd); |
12783 | install_element(ENABLE_NODE, &clear_ip_ospf_neighbor_cmd); | |
09f35f8c DS |
12784 | } |
12785 | ||
6b0655a2 | 12786 | |
718e3744 | 12787 | /* Install OSPF related vty commands. */ |
d62a17ae | 12788 | void ospf_vty_init(void) |
12789 | { | |
12790 | /* Install ospf top node. */ | |
612c2c15 | 12791 | install_node(&ospf_node); |
d62a17ae | 12792 | |
12793 | /* "router ospf" commands. */ | |
12794 | install_element(CONFIG_NODE, &router_ospf_cmd); | |
12795 | install_element(CONFIG_NODE, &no_router_ospf_cmd); | |
12796 | ||
12797 | ||
12798 | install_default(OSPF_NODE); | |
12799 | ||
12800 | /* "ospf router-id" commands. */ | |
12801 | install_element(OSPF_NODE, &ospf_router_id_cmd); | |
12802 | install_element(OSPF_NODE, &ospf_router_id_old_cmd); | |
12803 | install_element(OSPF_NODE, &no_ospf_router_id_cmd); | |
12804 | ||
12805 | /* "passive-interface" commands. */ | |
3eec4ee0 | 12806 | install_element(OSPF_NODE, &ospf_passive_interface_default_cmd); |
d62a17ae | 12807 | install_element(OSPF_NODE, &ospf_passive_interface_addr_cmd); |
3eec4ee0 | 12808 | install_element(OSPF_NODE, &no_ospf_passive_interface_default_cmd); |
d62a17ae | 12809 | install_element(OSPF_NODE, &no_ospf_passive_interface_addr_cmd); |
12810 | ||
12811 | /* "ospf abr-type" commands. */ | |
12812 | install_element(OSPF_NODE, &ospf_abr_type_cmd); | |
12813 | install_element(OSPF_NODE, &no_ospf_abr_type_cmd); | |
12814 | ||
12815 | /* "ospf log-adjacency-changes" commands. */ | |
12816 | install_element(OSPF_NODE, &ospf_log_adjacency_changes_cmd); | |
12817 | install_element(OSPF_NODE, &ospf_log_adjacency_changes_detail_cmd); | |
12818 | install_element(OSPF_NODE, &no_ospf_log_adjacency_changes_cmd); | |
12819 | install_element(OSPF_NODE, &no_ospf_log_adjacency_changes_detail_cmd); | |
12820 | ||
12821 | /* "ospf rfc1583-compatible" commands. */ | |
12822 | install_element(OSPF_NODE, &ospf_compatible_rfc1583_cmd); | |
12823 | install_element(OSPF_NODE, &no_ospf_compatible_rfc1583_cmd); | |
12824 | install_element(OSPF_NODE, &ospf_rfc1583_flag_cmd); | |
12825 | install_element(OSPF_NODE, &no_ospf_rfc1583_flag_cmd); | |
12826 | ||
12827 | /* "network area" commands. */ | |
12828 | install_element(OSPF_NODE, &ospf_network_area_cmd); | |
12829 | install_element(OSPF_NODE, &no_ospf_network_area_cmd); | |
12830 | ||
12831 | /* "area authentication" commands. */ | |
12832 | install_element(OSPF_NODE, | |
12833 | &ospf_area_authentication_message_digest_cmd); | |
12834 | install_element(OSPF_NODE, &ospf_area_authentication_cmd); | |
12835 | install_element(OSPF_NODE, &no_ospf_area_authentication_cmd); | |
12836 | ||
12837 | /* "area range" commands. */ | |
12838 | install_element(OSPF_NODE, &ospf_area_range_cmd); | |
12839 | install_element(OSPF_NODE, &ospf_area_range_cost_cmd); | |
12840 | install_element(OSPF_NODE, &ospf_area_range_not_advertise_cmd); | |
12841 | install_element(OSPF_NODE, &no_ospf_area_range_cmd); | |
12842 | install_element(OSPF_NODE, &ospf_area_range_substitute_cmd); | |
12843 | install_element(OSPF_NODE, &no_ospf_area_range_substitute_cmd); | |
12844 | ||
12845 | /* "area virtual-link" commands. */ | |
12846 | install_element(OSPF_NODE, &ospf_area_vlink_cmd); | |
12847 | install_element(OSPF_NODE, &ospf_area_vlink_intervals_cmd); | |
12848 | install_element(OSPF_NODE, &no_ospf_area_vlink_cmd); | |
12849 | install_element(OSPF_NODE, &no_ospf_area_vlink_intervals_cmd); | |
12850 | ||
12851 | ||
12852 | /* "area stub" commands. */ | |
12853 | install_element(OSPF_NODE, &ospf_area_stub_no_summary_cmd); | |
12854 | install_element(OSPF_NODE, &ospf_area_stub_cmd); | |
12855 | install_element(OSPF_NODE, &no_ospf_area_stub_no_summary_cmd); | |
12856 | install_element(OSPF_NODE, &no_ospf_area_stub_cmd); | |
12857 | ||
12858 | /* "area nssa" commands. */ | |
12859 | install_element(OSPF_NODE, &ospf_area_nssa_cmd); | |
d62a17ae | 12860 | install_element(OSPF_NODE, &ospf_area_nssa_translate_cmd); |
12861 | install_element(OSPF_NODE, &ospf_area_nssa_no_summary_cmd); | |
7ef56a73 | 12862 | install_element(OSPF_NODE, &no_ospf_area_nssa_no_summary_cmd); |
c317eddb | 12863 | install_element(OSPF_NODE, &ospf_area_nssa_suppress_fa_cmd); |
12864 | install_element(OSPF_NODE, &no_ospf_area_nssa_suppress_fa_cmd); | |
d62a17ae | 12865 | install_element(OSPF_NODE, &no_ospf_area_nssa_cmd); |
12866 | ||
12867 | install_element(OSPF_NODE, &ospf_area_default_cost_cmd); | |
12868 | install_element(OSPF_NODE, &no_ospf_area_default_cost_cmd); | |
12869 | ||
12870 | install_element(OSPF_NODE, &ospf_area_shortcut_cmd); | |
12871 | install_element(OSPF_NODE, &no_ospf_area_shortcut_cmd); | |
12872 | ||
12873 | install_element(OSPF_NODE, &ospf_area_export_list_cmd); | |
12874 | install_element(OSPF_NODE, &no_ospf_area_export_list_cmd); | |
12875 | ||
12876 | install_element(OSPF_NODE, &ospf_area_filter_list_cmd); | |
12877 | install_element(OSPF_NODE, &no_ospf_area_filter_list_cmd); | |
12878 | ||
12879 | install_element(OSPF_NODE, &ospf_area_import_list_cmd); | |
12880 | install_element(OSPF_NODE, &no_ospf_area_import_list_cmd); | |
12881 | ||
12882 | /* SPF timer commands */ | |
12883 | install_element(OSPF_NODE, &ospf_timers_throttle_spf_cmd); | |
12884 | install_element(OSPF_NODE, &no_ospf_timers_throttle_spf_cmd); | |
12885 | ||
12886 | /* LSA timers commands */ | |
12887 | install_element(OSPF_NODE, &ospf_timers_min_ls_interval_cmd); | |
12888 | install_element(OSPF_NODE, &no_ospf_timers_min_ls_interval_cmd); | |
0e88de35 QY |
12889 | install_element(OSPF_NODE, &ospf_timers_lsa_min_arrival_cmd); |
12890 | install_element(OSPF_NODE, &no_ospf_timers_lsa_min_arrival_cmd); | |
d62a17ae | 12891 | |
12892 | /* refresh timer commands */ | |
12893 | install_element(OSPF_NODE, &ospf_refresh_timer_cmd); | |
12894 | install_element(OSPF_NODE, &no_ospf_refresh_timer_val_cmd); | |
12895 | ||
12896 | /* max-metric commands */ | |
12897 | install_element(OSPF_NODE, &ospf_max_metric_router_lsa_admin_cmd); | |
12898 | install_element(OSPF_NODE, &no_ospf_max_metric_router_lsa_admin_cmd); | |
12899 | install_element(OSPF_NODE, &ospf_max_metric_router_lsa_startup_cmd); | |
12900 | install_element(OSPF_NODE, &no_ospf_max_metric_router_lsa_startup_cmd); | |
12901 | install_element(OSPF_NODE, &ospf_max_metric_router_lsa_shutdown_cmd); | |
12902 | install_element(OSPF_NODE, &no_ospf_max_metric_router_lsa_shutdown_cmd); | |
12903 | ||
12904 | /* reference bandwidth commands */ | |
12905 | install_element(OSPF_NODE, &ospf_auto_cost_reference_bandwidth_cmd); | |
12906 | install_element(OSPF_NODE, &no_ospf_auto_cost_reference_bandwidth_cmd); | |
12907 | ||
12908 | /* "neighbor" commands. */ | |
12909 | install_element(OSPF_NODE, &ospf_neighbor_cmd); | |
12910 | install_element(OSPF_NODE, &ospf_neighbor_poll_interval_cmd); | |
12911 | install_element(OSPF_NODE, &no_ospf_neighbor_cmd); | |
12912 | install_element(OSPF_NODE, &no_ospf_neighbor_poll_cmd); | |
12913 | ||
12914 | /* write multiplier commands */ | |
12915 | install_element(OSPF_NODE, &ospf_write_multiplier_cmd); | |
12916 | install_element(OSPF_NODE, &write_multiplier_cmd); | |
12917 | install_element(OSPF_NODE, &no_ospf_write_multiplier_cmd); | |
12918 | install_element(OSPF_NODE, &no_write_multiplier_cmd); | |
12919 | ||
a92706bb JU |
12920 | /* "proactive-arp" commands. */ |
12921 | install_element(OSPF_NODE, &ospf_proactive_arp_cmd); | |
12922 | install_element(OSPF_NODE, &no_ospf_proactive_arp_cmd); | |
12923 | ||
7fd0729f G |
12924 | /* TI-LFA commands */ |
12925 | install_element(OSPF_NODE, &ospf_ti_lfa_cmd); | |
12926 | install_element(OSPF_NODE, &no_ospf_ti_lfa_cmd); | |
12927 | ||
3d5b9855 | 12928 | /* Max path configurations */ |
12929 | install_element(OSPF_NODE, &ospf_max_multipath_cmd); | |
12930 | install_element(OSPF_NODE, &no_ospf_max_multipath_cmd); | |
12931 | ||
cfc369c4 | 12932 | vrf_cmd_init(NULL); |
f5eef2d5 | 12933 | |
d62a17ae | 12934 | /* Init interface related vty commands. */ |
12935 | ospf_vty_if_init(); | |
12936 | ||
12937 | /* Init zebra related vty commands. */ | |
12938 | ospf_vty_zebra_init(); | |
718e3744 | 12939 | } |