]>
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 | |
cbf3e3eb | 25 | #include "monotime.h" |
718e3744 | 26 | #include "memory.h" |
27 | #include "thread.h" | |
28 | #include "prefix.h" | |
29 | #include "table.h" | |
30 | #include "vty.h" | |
31 | #include "command.h" | |
32 | #include "plist.h" | |
33 | #include "log.h" | |
34 | #include "zclient.h" | |
bf2bfafd | 35 | #include <lib/json.h> |
8efe88ea | 36 | #include "defaults.h" |
718e3744 | 37 | |
38 | #include "ospfd/ospfd.h" | |
39 | #include "ospfd/ospf_asbr.h" | |
40 | #include "ospfd/ospf_lsa.h" | |
41 | #include "ospfd/ospf_lsdb.h" | |
42 | #include "ospfd/ospf_ism.h" | |
43 | #include "ospfd/ospf_interface.h" | |
44 | #include "ospfd/ospf_nsm.h" | |
45 | #include "ospfd/ospf_neighbor.h" | |
46 | #include "ospfd/ospf_flood.h" | |
47 | #include "ospfd/ospf_abr.h" | |
48 | #include "ospfd/ospf_spf.h" | |
49 | #include "ospfd/ospf_route.h" | |
50 | #include "ospfd/ospf_zebra.h" | |
51 | /*#include "ospfd/ospf_routemap.h" */ | |
52 | #include "ospfd/ospf_vty.h" | |
53 | #include "ospfd/ospf_dump.h" | |
7f342629 | 54 | #include "ospfd/ospf_bfd.h" |
718e3744 | 55 | |
d62a17ae | 56 | static const char *ospf_network_type_str[] = { |
57 | "Null", "POINTOPOINT", "BROADCAST", "NBMA", "POINTOMULTIPOINT", | |
58 | "VIRTUALLINK", "LOOPBACK"}; | |
718e3744 | 59 | |
718e3744 | 60 | /* Utility functions. */ |
d62a17ae | 61 | int str2area_id(const char *str, struct in_addr *area_id, int *area_id_fmt) |
718e3744 | 62 | { |
d62a17ae | 63 | char *ep; |
718e3744 | 64 | |
d62a17ae | 65 | area_id->s_addr = htonl(strtoul(str, &ep, 10)); |
66 | if (*ep && !inet_aton(str, area_id)) | |
67 | return -1; | |
718e3744 | 68 | |
d62a17ae | 69 | *area_id_fmt = |
70 | *ep ? OSPF_AREA_ID_FMT_DOTTEDQUAD : OSPF_AREA_ID_FMT_DECIMAL; | |
718e3744 | 71 | |
d62a17ae | 72 | return 0; |
718e3744 | 73 | } |
74 | ||
1f9d4e3d | 75 | static void area_id2str(char *buf, int length, struct in_addr *area_id, |
76 | int area_id_fmt) | |
86573dcb | 77 | { |
d62a17ae | 78 | if (area_id_fmt == OSPF_AREA_ID_FMT_DOTTEDQUAD) |
1f9d4e3d | 79 | inet_ntop(AF_INET, area_id, buf, length); |
d62a17ae | 80 | else |
81 | sprintf(buf, "%lu", (unsigned long)ntohl(area_id->s_addr)); | |
86573dcb | 82 | } |
6b0655a2 | 83 | |
d62a17ae | 84 | static int str2metric(const char *str, int *metric) |
718e3744 | 85 | { |
d62a17ae | 86 | /* Sanity check. */ |
87 | if (str == NULL) | |
88 | return 0; | |
718e3744 | 89 | |
d62a17ae | 90 | *metric = strtol(str, NULL, 10); |
91 | if (*metric < 0 && *metric > 16777214) { | |
92 | /* vty_out (vty, "OSPF metric value is invalid\n"); */ | |
93 | return 0; | |
94 | } | |
718e3744 | 95 | |
d62a17ae | 96 | return 1; |
718e3744 | 97 | } |
98 | ||
d62a17ae | 99 | static int str2metric_type(const char *str, int *metric_type) |
718e3744 | 100 | { |
d62a17ae | 101 | /* Sanity check. */ |
102 | if (str == NULL) | |
103 | return 0; | |
718e3744 | 104 | |
d62a17ae | 105 | if (strncmp(str, "1", 1) == 0) |
106 | *metric_type = EXTERNAL_METRIC_TYPE_1; | |
107 | else if (strncmp(str, "2", 1) == 0) | |
108 | *metric_type = EXTERNAL_METRIC_TYPE_2; | |
109 | else | |
110 | return 0; | |
718e3744 | 111 | |
d62a17ae | 112 | return 1; |
718e3744 | 113 | } |
114 | ||
d62a17ae | 115 | int ospf_oi_count(struct interface *ifp) |
718e3744 | 116 | { |
d62a17ae | 117 | struct route_node *rn; |
118 | int i = 0; | |
718e3744 | 119 | |
d62a17ae | 120 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) |
121 | if (rn->info) | |
122 | i++; | |
718e3744 | 123 | |
d62a17ae | 124 | return i; |
718e3744 | 125 | } |
126 | ||
996c9314 LB |
127 | #define OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf) \ |
128 | if (argv_find(argv, argc, "vrf", &idx_vrf)) { \ | |
129 | vrf_name = argv[idx_vrf + 1]->arg; \ | |
130 | all_vrf = strmatch(vrf_name, "all"); \ | |
43b8d1d8 CS |
131 | } |
132 | ||
133 | static struct ospf *ospf_cmd_lookup_ospf(struct vty *vty, | |
134 | struct cmd_token *argv[], | |
996c9314 | 135 | const int argc, uint32_t enable, |
d7c0a89a | 136 | unsigned short *instance) |
718e3744 | 137 | { |
b5a8894d | 138 | struct ospf *ospf = NULL; |
34d6798f | 139 | int idx_vrf = 0, idx_inst = 0; |
b5a8894d CS |
140 | const char *vrf_name = NULL; |
141 | ||
34d6798f CS |
142 | *instance = 0; |
143 | if (argv_find(argv, argc, "(1-65535)", &idx_inst)) | |
144 | *instance = strtoul(argv[idx_inst]->arg, NULL, 10); | |
145 | ||
b5a8894d | 146 | if (argv_find(argv, argc, "vrf", &idx_vrf)) { |
b5a8894d | 147 | vrf_name = argv[idx_vrf + 1]->arg; |
6895b354 PG |
148 | if (vrf_name == NULL || strmatch(vrf_name, VRF_DEFAULT_NAME)) |
149 | vrf_name = NULL; | |
43b8d1d8 | 150 | if (enable) { |
43b8d1d8 CS |
151 | /* Allocate VRF aware instance */ |
152 | ospf = ospf_get(*instance, vrf_name); | |
153 | } else { | |
43b8d1d8 CS |
154 | ospf = ospf_lookup_by_inst_name(*instance, vrf_name); |
155 | } | |
b5a8894d | 156 | } else { |
43b8d1d8 | 157 | if (enable) { |
34d6798f | 158 | ospf = ospf_get(*instance, NULL); |
43b8d1d8 | 159 | } else { |
43b8d1d8 | 160 | ospf = ospf_lookup_instance(*instance); |
b5a8894d | 161 | } |
d62a17ae | 162 | } |
34d6798f | 163 | |
43b8d1d8 CS |
164 | return ospf; |
165 | } | |
166 | ||
52d0c099 | 167 | static void ospf_show_vrf_name(struct ospf *ospf, struct vty *vty, |
d7c0a89a | 168 | json_object *json, uint8_t use_vrf) |
52d0c099 | 169 | { |
b1c3ae8c CS |
170 | if (use_vrf) { |
171 | if (json) { | |
172 | if (ospf->vrf_id == VRF_DEFAULT) | |
173 | json_object_string_add(json, "vrfName", | |
174 | "default"); | |
175 | else | |
176 | json_object_string_add(json, "vrfName", | |
177 | ospf->name); | |
178 | json_object_int_add(json, "vrfId", ospf->vrf_id); | |
179 | } else { | |
180 | if (ospf->vrf_id == VRF_DEFAULT) | |
181 | vty_out(vty, "VRF Name: %s\n", "default"); | |
182 | else if (ospf->name) | |
183 | vty_out(vty, "VRF Name: %s\n", ospf->name); | |
184 | } | |
52d0c099 | 185 | } |
52d0c099 CS |
186 | } |
187 | ||
43b8d1d8 | 188 | #ifndef VTYSH_EXTRACT_PL |
2e4c2296 | 189 | #include "ospfd/ospf_vty_clippy.c" |
43b8d1d8 CS |
190 | #endif |
191 | ||
192 | DEFUN_NOSH (router_ospf, | |
193 | router_ospf_cmd, | |
194 | "router ospf [{(1-65535)|vrf NAME}]", | |
195 | "Enable a routing process\n" | |
196 | "Start OSPF configuration\n" | |
197 | "Instance ID\n" | |
198 | VRF_CMD_HELP_STR) | |
199 | { | |
200 | struct ospf *ospf = NULL; | |
201 | int ret = CMD_SUCCESS; | |
d7c0a89a | 202 | unsigned short instance = 0; |
aed7cc62 CS |
203 | struct vrf *vrf = NULL; |
204 | struct route_node *rn; | |
205 | struct interface *ifp; | |
43b8d1d8 CS |
206 | |
207 | ospf = ospf_cmd_lookup_ospf(vty, argv, argc, 1, &instance); | |
208 | if (!ospf) | |
209 | return CMD_WARNING_CONFIG_FAILED; | |
d62a17ae | 210 | |
d62a17ae | 211 | /* The following logic to set the vty qobj index is in place to be able |
212 | to ignore the commands which dont belong to this instance. */ | |
64ac44f6 | 213 | if (ospf->instance != instance) { |
d62a17ae | 214 | VTY_PUSH_CONTEXT_NULL(OSPF_NODE); |
64ac44f6 CS |
215 | ret = CMD_NOT_MY_INSTANCE; |
216 | } else { | |
b5a8894d CS |
217 | if (ospf->vrf_id != VRF_UNKNOWN) |
218 | ospf->oi_running = 1; | |
d62a17ae | 219 | if (IS_DEBUG_OSPF_EVENT) |
996c9314 LB |
220 | zlog_debug( |
221 | "Config command 'router ospf %d' received, vrf %s id %u oi_running %u", | |
222 | instance, ospf->name ? ospf->name : "NIL", | |
223 | ospf->vrf_id, ospf->oi_running); | |
d62a17ae | 224 | VTY_PUSH_CONTEXT(OSPF_NODE, ospf); |
aed7cc62 CS |
225 | |
226 | /* Activate 'ip ospf area x' configured interfaces for given | |
227 | * vrf. Activate area on vrf x aware interfaces. | |
228 | * vrf_enable callback calls router_id_update which | |
229 | * internally will call ospf_if_update to trigger | |
230 | * network_run_state | |
231 | */ | |
232 | vrf = vrf_lookup_by_id(ospf->vrf_id); | |
233 | ||
234 | FOR_ALL_INTERFACES (vrf, ifp) { | |
235 | struct ospf_if_params *params; | |
236 | ||
237 | params = IF_DEF_PARAMS(ifp); | |
238 | if (OSPF_IF_PARAM_CONFIGURED(params, if_area)) { | |
239 | for (rn = route_top(ospf->networks); rn; | |
240 | rn = route_next(rn)) { | |
241 | if (rn->info != NULL) { | |
242 | vty_out(vty, | |
996c9314 LB |
243 | "Interface %s has area config but please remove all network commands first.\n", |
244 | ifp->name); | |
aed7cc62 CS |
245 | return ret; |
246 | } | |
247 | } | |
e9f07a30 PG |
248 | if (!ospf_interface_area_is_already_set(ospf, |
249 | ifp)) { | |
250 | ospf_interface_area_set(ospf, ifp); | |
251 | ospf->if_ospf_cli_count++; | |
252 | } | |
aed7cc62 CS |
253 | } |
254 | } | |
255 | ||
d62a17ae | 256 | ospf_router_id_update(ospf); |
257 | } | |
258 | ||
64ac44f6 | 259 | return ret; |
718e3744 | 260 | } |
261 | ||
262 | DEFUN (no_router_ospf, | |
263 | no_router_ospf_cmd, | |
43b8d1d8 | 264 | "no router ospf [{(1-65535)|vrf NAME}]", |
718e3744 | 265 | NO_STR |
266 | "Enable a routing process\n" | |
7a7be519 | 267 | "Start OSPF configuration\n" |
b5a8894d CS |
268 | "Instance ID\n" |
269 | VRF_CMD_HELP_STR) | |
718e3744 | 270 | { |
d62a17ae | 271 | struct ospf *ospf; |
d7c0a89a | 272 | unsigned short instance = 0; |
b5a8894d | 273 | |
43b8d1d8 CS |
274 | ospf = ospf_cmd_lookup_ospf(vty, argv, argc, 0, &instance); |
275 | if (ospf == NULL) { | |
276 | if (instance) | |
b5a8894d | 277 | return CMD_NOT_MY_INSTANCE; |
43b8d1d8 CS |
278 | else |
279 | return CMD_WARNING; | |
b5a8894d | 280 | } |
d62a17ae | 281 | ospf_finish(ospf); |
718e3744 | 282 | |
d62a17ae | 283 | return CMD_SUCCESS; |
718e3744 | 284 | } |
285 | ||
7c8ff89e | 286 | |
43b8d1d8 | 287 | DEFPY (ospf_router_id, |
718e3744 | 288 | ospf_router_id_cmd, |
289 | "ospf router-id A.B.C.D", | |
290 | "OSPF specific commands\n" | |
291 | "router-id for the OSPF process\n" | |
292 | "OSPF router-id in IP address format\n") | |
293 | { | |
a3d826f0 | 294 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
43b8d1d8 | 295 | |
d62a17ae | 296 | struct listnode *node; |
297 | struct ospf_area *area; | |
d62a17ae | 298 | |
299 | ospf->router_id_static = router_id; | |
300 | ||
301 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) | |
302 | if (area->full_nbrs) { | |
303 | vty_out(vty, | |
304 | "For this router-id change to take effect," | |
305 | " save config and restart ospfd\n"); | |
306 | return CMD_SUCCESS; | |
307 | } | |
308 | ||
309 | ospf_router_id_update(ospf); | |
310 | ||
311 | return CMD_SUCCESS; | |
718e3744 | 312 | } |
313 | ||
7a7be519 | 314 | DEFUN_HIDDEN (ospf_router_id_old, |
747e489c DW |
315 | ospf_router_id_old_cmd, |
316 | "router-id A.B.C.D", | |
317 | "router-id for the OSPF process\n" | |
318 | "OSPF router-id in IP address format\n") | |
7a7be519 | 319 | { |
a3d826f0 | 320 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 321 | int idx_ipv4 = 1; |
322 | struct listnode *node; | |
323 | struct ospf_area *area; | |
324 | struct in_addr router_id; | |
325 | int ret; | |
326 | ||
327 | ret = inet_aton(argv[idx_ipv4]->arg, &router_id); | |
328 | if (!ret) { | |
329 | vty_out(vty, "Please specify Router ID by A.B.C.D\n"); | |
330 | return CMD_WARNING_CONFIG_FAILED; | |
331 | } | |
7a7be519 | 332 | |
d62a17ae | 333 | ospf->router_id_static = router_id; |
334 | ||
335 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) | |
336 | if (area->full_nbrs) { | |
337 | vty_out(vty, | |
338 | "For this router-id change to take effect," | |
339 | " save config and restart ospfd\n"); | |
340 | return CMD_SUCCESS; | |
341 | } | |
342 | ||
343 | ospf_router_id_update(ospf); | |
344 | ||
345 | return CMD_SUCCESS; | |
7a7be519 | 346 | } |
747e489c | 347 | |
43b8d1d8 | 348 | DEFPY (no_ospf_router_id, |
718e3744 | 349 | no_ospf_router_id_cmd, |
7a7be519 | 350 | "no ospf router-id [A.B.C.D]", |
718e3744 | 351 | NO_STR |
352 | "OSPF specific commands\n" | |
7a7be519 | 353 | "router-id for the OSPF process\n" |
354 | "OSPF router-id in IP address format\n") | |
718e3744 | 355 | { |
a3d826f0 | 356 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 357 | struct listnode *node; |
358 | struct ospf_area *area; | |
68980084 | 359 | |
43b8d1d8 CS |
360 | if (router_id_str) { |
361 | if (!IPV4_ADDR_SAME(&ospf->router_id_static, &router_id)) { | |
362 | vty_out(vty, "%% OSPF router-id doesn't match\n"); | |
363 | return CMD_WARNING_CONFIG_FAILED; | |
364 | } | |
365 | } | |
366 | ||
d62a17ae | 367 | ospf->router_id_static.s_addr = 0; |
718e3744 | 368 | |
d62a17ae | 369 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) |
370 | if (area->full_nbrs) { | |
371 | vty_out(vty, | |
372 | "For this router-id change to take effect," | |
373 | " save config and restart ospfd\n"); | |
374 | return CMD_SUCCESS; | |
375 | } | |
2c19a6ec | 376 | |
d62a17ae | 377 | ospf_router_id_update(ospf); |
718e3744 | 378 | |
d62a17ae | 379 | return CMD_SUCCESS; |
718e3744 | 380 | } |
381 | ||
718e3744 | 382 | |
d7c0a89a | 383 | static void ospf_passive_interface_default(struct ospf *ospf, uint8_t newval) |
d62a17ae | 384 | { |
f4e14fdb | 385 | struct vrf *vrf = vrf_lookup_by_id(ospf->vrf_id); |
d62a17ae | 386 | struct listnode *ln; |
387 | struct interface *ifp; | |
388 | struct ospf_interface *oi; | |
389 | ||
390 | ospf->passive_interface_default = newval; | |
391 | ||
451fda4f | 392 | FOR_ALL_INTERFACES (vrf, ifp) { |
9d303b37 DL |
393 | if (ifp && OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(ifp), |
394 | passive_interface)) | |
d62a17ae | 395 | UNSET_IF_PARAM(IF_DEF_PARAMS(ifp), passive_interface); |
396 | } | |
397 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, ln, oi)) { | |
398 | if (OSPF_IF_PARAM_CONFIGURED(oi->params, passive_interface)) | |
399 | UNSET_IF_PARAM(oi->params, passive_interface); | |
400 | /* update multicast memberships */ | |
401 | ospf_if_set_multicast(oi); | |
402 | } | |
403 | } | |
404 | ||
405 | static void ospf_passive_interface_update_addr(struct ospf *ospf, | |
406 | struct interface *ifp, | |
407 | struct ospf_if_params *params, | |
d7c0a89a | 408 | uint8_t value, |
d62a17ae | 409 | struct in_addr addr) |
410 | { | |
d7c0a89a | 411 | uint8_t dflt; |
d62a17ae | 412 | |
413 | params->passive_interface = value; | |
414 | if (params != IF_DEF_PARAMS(ifp)) { | |
415 | if (OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(ifp), | |
416 | passive_interface)) | |
417 | dflt = IF_DEF_PARAMS(ifp)->passive_interface; | |
418 | else | |
419 | dflt = ospf->passive_interface_default; | |
420 | ||
421 | if (value != dflt) | |
422 | SET_IF_PARAM(params, passive_interface); | |
423 | else | |
424 | UNSET_IF_PARAM(params, passive_interface); | |
425 | ||
426 | ospf_free_if_params(ifp, addr); | |
427 | ospf_if_update_params(ifp, addr); | |
428 | } | |
429 | } | |
430 | ||
431 | static void ospf_passive_interface_update(struct ospf *ospf, | |
432 | struct interface *ifp, | |
433 | struct ospf_if_params *params, | |
d7c0a89a | 434 | uint8_t value) |
d62a17ae | 435 | { |
436 | params->passive_interface = value; | |
437 | if (params == IF_DEF_PARAMS(ifp)) { | |
438 | if (value != ospf->passive_interface_default) | |
439 | SET_IF_PARAM(params, passive_interface); | |
440 | else | |
441 | UNSET_IF_PARAM(params, passive_interface); | |
442 | } | |
7ffa8fa2 PJ |
443 | } |
444 | ||
a2c62831 | 445 | DEFUN (ospf_passive_interface, |
446 | ospf_passive_interface_addr_cmd, | |
7a7be519 | 447 | "passive-interface <IFNAME [A.B.C.D]|default>", |
718e3744 | 448 | "Suppress routing updates on an interface\n" |
7a7be519 | 449 | "Interface's name\n" |
3a2d747c | 450 | "IPv4 address\n" |
7a7be519 | 451 | "Suppress routing updates on interfaces by default\n") |
718e3744 | 452 | { |
a3d826f0 | 453 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 454 | int idx_ipv4 = 2; |
e99734f1 | 455 | struct interface *ifp = NULL; |
d62a17ae | 456 | struct in_addr addr = {.s_addr = INADDR_ANY}; |
457 | int ret; | |
458 | struct ospf_if_params *params; | |
459 | struct route_node *rn; | |
460 | ||
461 | if (strmatch(argv[1]->text, "default")) { | |
462 | ospf_passive_interface_default(ospf, OSPF_IF_PASSIVE); | |
463 | return CMD_SUCCESS; | |
464 | } | |
e99734f1 | 465 | if (ospf->vrf_id != VRF_UNKNOWN) |
a36898e7 | 466 | ifp = if_get_by_name(argv[1]->arg, ospf->vrf_id); |
d62a17ae | 467 | |
b5a8894d | 468 | if (ifp == NULL) { |
996c9314 | 469 | vty_out(vty, "interface %s not found.\n", (char *)argv[1]->arg); |
e99734f1 | 470 | return CMD_WARNING_CONFIG_FAILED; |
b5a8894d | 471 | } |
d62a17ae | 472 | |
473 | params = IF_DEF_PARAMS(ifp); | |
474 | ||
475 | if (argc == 3) { | |
476 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
477 | if (!ret) { | |
478 | vty_out(vty, | |
479 | "Please specify interface address by A.B.C.D\n"); | |
480 | return CMD_WARNING_CONFIG_FAILED; | |
481 | } | |
482 | ||
483 | params = ospf_get_if_params(ifp, addr); | |
484 | ospf_if_update_params(ifp, addr); | |
485 | ospf_passive_interface_update_addr(ospf, ifp, params, | |
486 | OSPF_IF_PASSIVE, addr); | |
487 | } | |
488 | ||
489 | ospf_passive_interface_update(ospf, ifp, params, OSPF_IF_PASSIVE); | |
490 | ||
491 | /* XXX We should call ospf_if_set_multicast on exactly those | |
492 | * interfaces for which the passive property changed. It is too much | |
493 | * work to determine this set, so we do this for every interface. | |
494 | * This is safe and reasonable because ospf_if_set_multicast uses a | |
495 | * record of joined groups to avoid systems calls if the desired | |
496 | * memberships match the current memership. | |
497 | */ | |
498 | ||
499 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { | |
500 | struct ospf_interface *oi = rn->info; | |
501 | ||
9d303b37 DL |
502 | if (oi && (OSPF_IF_PARAM(oi, passive_interface) |
503 | == OSPF_IF_PASSIVE)) | |
d62a17ae | 504 | ospf_if_set_multicast(oi); |
505 | } | |
506 | /* | |
507 | * XXX It is not clear what state transitions the interface needs to | |
508 | * undergo when going from active to passive. Fixing this will | |
509 | * require precise identification of interfaces having such a | |
510 | * transition. | |
511 | */ | |
512 | ||
513 | return CMD_SUCCESS; | |
718e3744 | 514 | } |
515 | ||
a2c62831 | 516 | DEFUN (no_ospf_passive_interface, |
517 | no_ospf_passive_interface_addr_cmd, | |
7a7be519 | 518 | "no passive-interface <IFNAME [A.B.C.D]|default>", |
718e3744 | 519 | NO_STR |
520 | "Allow routing updates on an interface\n" | |
7a7be519 | 521 | "Interface's name\n" |
3a2d747c | 522 | "IPv4 address\n" |
7a7be519 | 523 | "Allow routing updates on interfaces by default\n") |
718e3744 | 524 | { |
a3d826f0 | 525 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 526 | int idx_ipv4 = 3; |
e99734f1 | 527 | struct interface *ifp = NULL; |
d62a17ae | 528 | struct in_addr addr = {.s_addr = INADDR_ANY}; |
529 | struct ospf_if_params *params; | |
530 | int ret; | |
531 | struct route_node *rn; | |
532 | ||
533 | if (strmatch(argv[2]->text, "default")) { | |
534 | ospf_passive_interface_default(ospf, OSPF_IF_ACTIVE); | |
535 | return CMD_SUCCESS; | |
43540886 AS |
536 | } |
537 | ||
e99734f1 | 538 | if (ospf->vrf_id != VRF_UNKNOWN) |
a36898e7 | 539 | ifp = if_get_by_name(argv[2]->arg, ospf->vrf_id); |
e99734f1 | 540 | |
b5a8894d | 541 | if (ifp == NULL) { |
996c9314 | 542 | vty_out(vty, "interface %s not found.\n", (char *)argv[2]->arg); |
e99734f1 | 543 | return CMD_WARNING_CONFIG_FAILED; |
b5a8894d | 544 | } |
ba6454ec | 545 | |
d62a17ae | 546 | params = IF_DEF_PARAMS(ifp); |
547 | ||
548 | if (argc == 4) { | |
549 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
550 | if (!ret) { | |
551 | vty_out(vty, | |
552 | "Please specify interface address by A.B.C.D\n"); | |
553 | return CMD_WARNING_CONFIG_FAILED; | |
554 | } | |
555 | ||
556 | params = ospf_lookup_if_params(ifp, addr); | |
557 | if (params == NULL) | |
558 | return CMD_SUCCESS; | |
559 | ospf_passive_interface_update_addr(ospf, ifp, params, | |
560 | OSPF_IF_ACTIVE, addr); | |
561 | } | |
562 | ospf_passive_interface_update(ospf, ifp, params, OSPF_IF_ACTIVE); | |
563 | ||
564 | /* XXX We should call ospf_if_set_multicast on exactly those | |
565 | * interfaces for which the passive property changed. It is too much | |
566 | * work to determine this set, so we do this for every interface. | |
567 | * This is safe and reasonable because ospf_if_set_multicast uses a | |
568 | * record of joined groups to avoid systems calls if the desired | |
569 | * memberships match the current memership. | |
570 | */ | |
571 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { | |
572 | struct ospf_interface *oi = rn->info; | |
573 | ||
574 | if (oi | |
575 | && (OSPF_IF_PARAM(oi, passive_interface) == OSPF_IF_ACTIVE)) | |
576 | ospf_if_set_multicast(oi); | |
577 | } | |
578 | ||
579 | return CMD_SUCCESS; | |
718e3744 | 580 | } |
581 | ||
718e3744 | 582 | |
a2c62831 | 583 | DEFUN (ospf_network_area, |
584 | ospf_network_area_cmd, | |
6147e2c6 | 585 | "network A.B.C.D/M area <A.B.C.D|(0-4294967295)>", |
718e3744 | 586 | "Enable routing on an IP network\n" |
587 | "OSPF network prefix\n" | |
588 | "Set the OSPF area ID\n" | |
589 | "OSPF area ID in IP address format\n" | |
590 | "OSPF area ID as a decimal value\n") | |
591 | { | |
a3d826f0 | 592 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 593 | int idx_ipv4_prefixlen = 1; |
594 | int idx_ipv4_number = 3; | |
595 | struct prefix_ipv4 p; | |
596 | struct in_addr area_id; | |
597 | int ret, format; | |
598 | ||
599 | if (ospf->instance) { | |
600 | vty_out(vty, | |
601 | "The network command is not supported in multi-instance ospf\n"); | |
602 | return CMD_WARNING_CONFIG_FAILED; | |
603 | } | |
718e3744 | 604 | |
d62a17ae | 605 | if (ospf->if_ospf_cli_count > 0) { |
606 | vty_out(vty, | |
607 | "Please remove all ip ospf area x.x.x.x commands first.\n"); | |
aed7cc62 | 608 | if (IS_DEBUG_OSPF_EVENT) |
996c9314 LB |
609 | zlog_debug( |
610 | "%s ospf vrf %s num of %u ip osp area x config", | |
611 | __PRETTY_FUNCTION__, | |
612 | ospf->name ? ospf->name : "NIL", | |
613 | ospf->if_ospf_cli_count); | |
d62a17ae | 614 | return CMD_WARNING_CONFIG_FAILED; |
615 | } | |
616 | ||
617 | /* Get network prefix and Area ID. */ | |
618 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); | |
619 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); | |
620 | ||
621 | ret = ospf_network_set(ospf, &p, area_id, format); | |
622 | if (ret == 0) { | |
623 | vty_out(vty, "There is already same network statement.\n"); | |
2b0a905a | 624 | return CMD_WARNING_CONFIG_FAILED; |
d62a17ae | 625 | } |
626 | ||
627 | return CMD_SUCCESS; | |
718e3744 | 628 | } |
629 | ||
a2c62831 | 630 | DEFUN (no_ospf_network_area, |
631 | no_ospf_network_area_cmd, | |
6147e2c6 | 632 | "no network A.B.C.D/M area <A.B.C.D|(0-4294967295)>", |
718e3744 | 633 | NO_STR |
634 | "Enable routing on an IP network\n" | |
635 | "OSPF network prefix\n" | |
636 | "Set the OSPF area ID\n" | |
637 | "OSPF area ID in IP address format\n" | |
638 | "OSPF area ID as a decimal value\n") | |
639 | { | |
a3d826f0 | 640 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 641 | int idx_ipv4_prefixlen = 2; |
642 | int idx_ipv4_number = 4; | |
643 | struct prefix_ipv4 p; | |
644 | struct in_addr area_id; | |
645 | int ret, format; | |
646 | ||
647 | if (ospf->instance) { | |
648 | vty_out(vty, | |
649 | "The network command is not supported in multi-instance ospf\n"); | |
650 | return CMD_WARNING_CONFIG_FAILED; | |
651 | } | |
718e3744 | 652 | |
d62a17ae | 653 | /* Get network prefix and Area ID. */ |
654 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); | |
655 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); | |
656 | ||
657 | ret = ospf_network_unset(ospf, &p, area_id); | |
658 | if (ret == 0) { | |
659 | vty_out(vty, | |
660 | "Can't find specified network area configuration.\n"); | |
661 | return CMD_WARNING_CONFIG_FAILED; | |
662 | } | |
663 | ||
664 | return CMD_SUCCESS; | |
718e3744 | 665 | } |
666 | ||
a2c62831 | 667 | DEFUN (ospf_area_range, |
668 | ospf_area_range_cmd, | |
7a7be519 | 669 | "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M [advertise [cost (0-16777215)]]", |
718e3744 | 670 | "OSPF area parameters\n" |
671 | "OSPF area ID in IP address format\n" | |
672 | "OSPF area ID as a decimal value\n" | |
673 | "Summarize routes matching address/mask (border routers only)\n" | |
7a7be519 | 674 | "Area range prefix\n" |
675 | "Advertise this range (default)\n" | |
676 | "User specified metric for this range\n" | |
677 | "Advertised metric for this range\n") | |
718e3744 | 678 | { |
a3d826f0 | 679 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 680 | int idx_ipv4_number = 1; |
681 | int idx_ipv4_prefixlen = 3; | |
682 | int idx_cost = 6; | |
683 | struct prefix_ipv4 p; | |
684 | struct in_addr area_id; | |
685 | int format; | |
d7c0a89a | 686 | uint32_t cost; |
d62a17ae | 687 | |
688 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); | |
689 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); | |
690 | ||
691 | ospf_area_range_set(ospf, area_id, &p, OSPF_AREA_RANGE_ADVERTISE); | |
692 | if (argc > 5) { | |
693 | cost = strtoul(argv[idx_cost]->arg, NULL, 10); | |
694 | ospf_area_range_cost_set(ospf, area_id, &p, cost); | |
695 | } | |
718e3744 | 696 | |
d62a17ae | 697 | return CMD_SUCCESS; |
718e3744 | 698 | } |
699 | ||
7a7be519 | 700 | DEFUN (ospf_area_range_cost, |
701 | ospf_area_range_cost_cmd, | |
702 | "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M cost (0-16777215)", | |
703 | "OSPF area parameters\n" | |
704 | "OSPF area ID in IP address format\n" | |
705 | "OSPF area ID as a decimal value\n" | |
706 | "Summarize routes matching address/mask (border routers only)\n" | |
707 | "Area range prefix\n" | |
708 | "User specified metric for this range\n" | |
709 | "Advertised metric for this range\n") | |
710 | { | |
a3d826f0 | 711 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 712 | int idx_ipv4_number = 1; |
713 | int idx_ipv4_prefixlen = 3; | |
714 | int idx_cost = 5; | |
715 | struct prefix_ipv4 p; | |
716 | struct in_addr area_id; | |
717 | int format; | |
d7c0a89a | 718 | uint32_t cost; |
7a7be519 | 719 | |
d62a17ae | 720 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
721 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); | |
7a7be519 | 722 | |
d62a17ae | 723 | ospf_area_range_set(ospf, area_id, &p, OSPF_AREA_RANGE_ADVERTISE); |
724 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
725 | format); | |
718e3744 | 726 | |
d62a17ae | 727 | cost = strtoul(argv[idx_cost]->arg, NULL, 10); |
728 | ospf_area_range_cost_set(ospf, area_id, &p, cost); | |
718e3744 | 729 | |
d62a17ae | 730 | return CMD_SUCCESS; |
7a7be519 | 731 | } |
718e3744 | 732 | |
a2c62831 | 733 | DEFUN (ospf_area_range_not_advertise, |
734 | ospf_area_range_not_advertise_cmd, | |
6147e2c6 | 735 | "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M not-advertise", |
718e3744 | 736 | "OSPF area parameters\n" |
737 | "OSPF area ID in IP address format\n" | |
738 | "OSPF area ID as a decimal value\n" | |
739 | "Summarize routes matching address/mask (border routers only)\n" | |
740 | "Area range prefix\n" | |
741 | "DoNotAdvertise this range\n") | |
742 | { | |
a3d826f0 | 743 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 744 | int idx_ipv4_number = 1; |
745 | int idx_ipv4_prefixlen = 3; | |
746 | struct prefix_ipv4 p; | |
747 | struct in_addr area_id; | |
748 | int format; | |
718e3744 | 749 | |
d62a17ae | 750 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
751 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); | |
718e3744 | 752 | |
d62a17ae | 753 | ospf_area_range_set(ospf, area_id, &p, 0); |
754 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
755 | format); | |
990baca0 | 756 | ospf_area_range_substitute_unset(ospf, area_id, &p); |
718e3744 | 757 | |
d62a17ae | 758 | return CMD_SUCCESS; |
718e3744 | 759 | } |
760 | ||
a2c62831 | 761 | DEFUN (no_ospf_area_range, |
762 | no_ospf_area_range_cmd, | |
3a2d747c | 763 | "no area <A.B.C.D|(0-4294967295)> range A.B.C.D/M [<cost (0-16777215)|advertise [cost (0-16777215)]|not-advertise>]", |
718e3744 | 764 | NO_STR |
765 | "OSPF area parameters\n" | |
766 | "OSPF area ID in IP address format\n" | |
767 | "OSPF area ID as a decimal value\n" | |
768 | "Summarize routes matching address/mask (border routers only)\n" | |
7a7be519 | 769 | "Area range prefix\n" |
3a2d747c QY |
770 | "User specified metric for this range\n" |
771 | "Advertised metric for this range\n" | |
7a7be519 | 772 | "Advertise this range (default)\n" |
3a2d747c QY |
773 | "User specified metric for this range\n" |
774 | "Advertised metric for this range\n" | |
7a7be519 | 775 | "DoNotAdvertise this range\n") |
718e3744 | 776 | { |
a3d826f0 | 777 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 778 | int idx_ipv4_number = 2; |
779 | int idx_ipv4_prefixlen = 4; | |
780 | struct prefix_ipv4 p; | |
781 | struct in_addr area_id; | |
782 | int format; | |
718e3744 | 783 | |
d62a17ae | 784 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
785 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); | |
718e3744 | 786 | |
d62a17ae | 787 | ospf_area_range_unset(ospf, area_id, &p); |
718e3744 | 788 | |
d62a17ae | 789 | return CMD_SUCCESS; |
718e3744 | 790 | } |
791 | ||
a2c62831 | 792 | DEFUN (ospf_area_range_substitute, |
793 | ospf_area_range_substitute_cmd, | |
6147e2c6 | 794 | "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M substitute A.B.C.D/M", |
718e3744 | 795 | "OSPF area parameters\n" |
796 | "OSPF area ID in IP address format\n" | |
797 | "OSPF area ID as a decimal value\n" | |
798 | "Summarize routes matching address/mask (border routers only)\n" | |
799 | "Area range prefix\n" | |
800 | "Announce area range as another prefix\n" | |
801 | "Network prefix to be announced instead of range\n") | |
802 | { | |
a3d826f0 | 803 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 804 | int idx_ipv4_number = 1; |
805 | int idx_ipv4_prefixlen = 3; | |
806 | int idx_ipv4_prefixlen_2 = 5; | |
807 | struct prefix_ipv4 p, s; | |
808 | struct in_addr area_id; | |
809 | int format; | |
718e3744 | 810 | |
d62a17ae | 811 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
812 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); | |
813 | str2prefix_ipv4(argv[idx_ipv4_prefixlen_2]->arg, &s); | |
718e3744 | 814 | |
d62a17ae | 815 | ospf_area_range_substitute_set(ospf, area_id, &p, &s); |
816 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
817 | format); | |
718e3744 | 818 | |
d62a17ae | 819 | return CMD_SUCCESS; |
718e3744 | 820 | } |
821 | ||
a2c62831 | 822 | DEFUN (no_ospf_area_range_substitute, |
823 | no_ospf_area_range_substitute_cmd, | |
6147e2c6 | 824 | "no area <A.B.C.D|(0-4294967295)> range A.B.C.D/M substitute A.B.C.D/M", |
718e3744 | 825 | NO_STR |
826 | "OSPF area parameters\n" | |
827 | "OSPF area ID in IP address format\n" | |
828 | "OSPF area ID as a decimal value\n" | |
829 | "Summarize routes matching address/mask (border routers only)\n" | |
830 | "Area range prefix\n" | |
831 | "Announce area range as another prefix\n" | |
832 | "Network prefix to be announced instead of range\n") | |
833 | { | |
a3d826f0 | 834 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 835 | int idx_ipv4_number = 2; |
836 | int idx_ipv4_prefixlen = 4; | |
837 | int idx_ipv4_prefixlen_2 = 6; | |
838 | struct prefix_ipv4 p, s; | |
839 | struct in_addr area_id; | |
840 | int format; | |
718e3744 | 841 | |
d62a17ae | 842 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
843 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); | |
844 | str2prefix_ipv4(argv[idx_ipv4_prefixlen_2]->arg, &s); | |
718e3744 | 845 | |
d62a17ae | 846 | ospf_area_range_substitute_unset(ospf, area_id, &p); |
718e3744 | 847 | |
d62a17ae | 848 | return CMD_SUCCESS; |
718e3744 | 849 | } |
850 | ||
6b0655a2 | 851 | |
718e3744 | 852 | /* Command Handler Logic in VLink stuff is delicate!! |
853 | ||
854 | ALTER AT YOUR OWN RISK!!!! | |
855 | ||
856 | Various dummy values are used to represent 'NoChange' state for | |
857 | VLink configuration NOT being changed by a VLink command, and | |
858 | special syntax is used within the command strings so that the | |
859 | typed in command verbs can be seen in the configuration command | |
860 | bacckend handler. This is to drastically reduce the verbeage | |
861 | required to coe up with a reasonably compatible Cisco VLink command | |
862 | ||
d62a17ae | 863 | - Matthew Grant <grantma@anathoth.gen.nz> |
718e3744 | 864 | Wed, 21 Feb 2001 15:13:52 +1300 |
865 | */ | |
866 | ||
d62a17ae | 867 | /* Configuration data for virtual links |
868 | */ | |
718e3744 | 869 | struct ospf_vl_config_data { |
d62a17ae | 870 | struct vty *vty; /* vty stuff */ |
871 | struct in_addr area_id; /* area ID from command line */ | |
872 | int area_id_fmt; /* command line area ID format */ | |
873 | struct in_addr vl_peer; /* command line vl_peer */ | |
874 | int auth_type; /* Authehntication type, if given */ | |
875 | char *auth_key; /* simple password if present */ | |
876 | int crypto_key_id; /* Cryptographic key ID */ | |
877 | char *md5_key; /* MD5 authentication key */ | |
878 | int hello_interval; /* Obvious what these are... */ | |
879 | int retransmit_interval; | |
880 | int transmit_delay; | |
881 | int dead_interval; | |
718e3744 | 882 | }; |
883 | ||
d62a17ae | 884 | static void ospf_vl_config_data_init(struct ospf_vl_config_data *vl_config, |
885 | struct vty *vty) | |
718e3744 | 886 | { |
d62a17ae | 887 | memset(vl_config, 0, sizeof(struct ospf_vl_config_data)); |
888 | vl_config->auth_type = OSPF_AUTH_CMD_NOTSEEN; | |
889 | vl_config->vty = vty; | |
718e3744 | 890 | } |
891 | ||
4dadc291 | 892 | static struct ospf_vl_data * |
d62a17ae | 893 | ospf_find_vl_data(struct ospf *ospf, struct ospf_vl_config_data *vl_config) |
894 | { | |
895 | struct ospf_area *area; | |
896 | struct ospf_vl_data *vl_data; | |
897 | struct vty *vty; | |
898 | struct in_addr area_id; | |
899 | ||
900 | vty = vl_config->vty; | |
901 | area_id = vl_config->area_id; | |
902 | ||
903 | if (area_id.s_addr == OSPF_AREA_BACKBONE) { | |
904 | vty_out(vty, | |
905 | "Configuring VLs over the backbone is not allowed\n"); | |
906 | return NULL; | |
907 | } | |
908 | area = ospf_area_get(ospf, area_id); | |
909 | ospf_area_display_format_set(ospf, area, vl_config->area_id_fmt); | |
910 | ||
911 | if (area->external_routing != OSPF_AREA_DEFAULT) { | |
912 | if (vl_config->area_id_fmt == OSPF_AREA_ID_FMT_DOTTEDQUAD) | |
913 | vty_out(vty, "Area %s is %s\n", inet_ntoa(area_id), | |
914 | area->external_routing == OSPF_AREA_NSSA | |
915 | ? "nssa" | |
916 | : "stub"); | |
917 | else | |
918 | vty_out(vty, "Area %ld is %s\n", | |
d7c0a89a | 919 | (unsigned long)ntohl(area_id.s_addr), |
d62a17ae | 920 | area->external_routing == OSPF_AREA_NSSA |
921 | ? "nssa" | |
922 | : "stub"); | |
923 | return NULL; | |
924 | } | |
925 | ||
926 | if ((vl_data = ospf_vl_lookup(ospf, area, vl_config->vl_peer)) | |
927 | == NULL) { | |
928 | vl_data = ospf_vl_data_new(area, vl_config->vl_peer); | |
929 | if (vl_data->vl_oi == NULL) { | |
930 | vl_data->vl_oi = ospf_vl_new(ospf, vl_data); | |
931 | ospf_vl_add(ospf, vl_data); | |
932 | ospf_spf_calculate_schedule(ospf, | |
933 | SPF_FLAG_CONFIG_CHANGE); | |
934 | } | |
718e3744 | 935 | } |
d62a17ae | 936 | return vl_data; |
718e3744 | 937 | } |
938 | ||
939 | ||
d62a17ae | 940 | static int ospf_vl_set_security(struct ospf_vl_data *vl_data, |
941 | struct ospf_vl_config_data *vl_config) | |
942 | { | |
943 | struct crypt_key *ck; | |
944 | struct vty *vty; | |
945 | struct interface *ifp = vl_data->vl_oi->ifp; | |
946 | ||
947 | vty = vl_config->vty; | |
948 | ||
949 | if (vl_config->auth_type != OSPF_AUTH_CMD_NOTSEEN) { | |
950 | SET_IF_PARAM(IF_DEF_PARAMS(ifp), auth_type); | |
951 | IF_DEF_PARAMS(ifp)->auth_type = vl_config->auth_type; | |
718e3744 | 952 | } |
718e3744 | 953 | |
d62a17ae | 954 | if (vl_config->auth_key) { |
955 | memset(IF_DEF_PARAMS(ifp)->auth_simple, 0, | |
956 | OSPF_AUTH_SIMPLE_SIZE + 1); | |
4d65d927 QY |
957 | strlcpy((char *)IF_DEF_PARAMS(ifp)->auth_simple, |
958 | vl_config->auth_key, | |
959 | sizeof(IF_DEF_PARAMS(ifp)->auth_simple)); | |
d62a17ae | 960 | } else if (vl_config->md5_key) { |
961 | if (ospf_crypt_key_lookup(IF_DEF_PARAMS(ifp)->auth_crypt, | |
962 | vl_config->crypto_key_id) | |
963 | != NULL) { | |
964 | vty_out(vty, "OSPF: Key %d already exists\n", | |
965 | vl_config->crypto_key_id); | |
851fcbae | 966 | return CMD_WARNING; |
d62a17ae | 967 | } |
968 | ck = ospf_crypt_key_new(); | |
969 | ck->key_id = vl_config->crypto_key_id; | |
970 | memset(ck->auth_key, 0, OSPF_AUTH_MD5_SIZE + 1); | |
4d65d927 QY |
971 | strlcpy((char *)ck->auth_key, vl_config->md5_key, |
972 | sizeof(ck->auth_key)); | |
d62a17ae | 973 | |
974 | ospf_crypt_key_add(IF_DEF_PARAMS(ifp)->auth_crypt, ck); | |
975 | } else if (vl_config->crypto_key_id != 0) { | |
976 | /* Delete a key */ | |
977 | ||
978 | if (ospf_crypt_key_lookup(IF_DEF_PARAMS(ifp)->auth_crypt, | |
979 | vl_config->crypto_key_id) | |
980 | == NULL) { | |
981 | vty_out(vty, "OSPF: Key %d does not exist\n", | |
982 | vl_config->crypto_key_id); | |
983 | return CMD_WARNING_CONFIG_FAILED; | |
984 | } | |
985 | ||
986 | ospf_crypt_key_delete(IF_DEF_PARAMS(ifp)->auth_crypt, | |
987 | vl_config->crypto_key_id); | |
988 | } | |
989 | ||
990 | return CMD_SUCCESS; | |
718e3744 | 991 | } |
992 | ||
d62a17ae | 993 | static int ospf_vl_set_timers(struct ospf_vl_data *vl_data, |
994 | struct ospf_vl_config_data *vl_config) | |
995 | { | |
996 | struct interface *ifp = vl_data->vl_oi->ifp; | |
997 | /* Virtual Link data initialised to defaults, so only set | |
998 | if a value given */ | |
999 | if (vl_config->hello_interval) { | |
1000 | SET_IF_PARAM(IF_DEF_PARAMS(ifp), v_hello); | |
1001 | IF_DEF_PARAMS(ifp)->v_hello = vl_config->hello_interval; | |
1002 | } | |
1003 | ||
1004 | if (vl_config->dead_interval) { | |
1005 | SET_IF_PARAM(IF_DEF_PARAMS(ifp), v_wait); | |
1006 | IF_DEF_PARAMS(ifp)->v_wait = vl_config->dead_interval; | |
1007 | } | |
1008 | ||
1009 | if (vl_config->retransmit_interval) { | |
1010 | SET_IF_PARAM(IF_DEF_PARAMS(ifp), retransmit_interval); | |
1011 | IF_DEF_PARAMS(ifp)->retransmit_interval = | |
1012 | vl_config->retransmit_interval; | |
1013 | } | |
1014 | ||
1015 | if (vl_config->transmit_delay) { | |
1016 | SET_IF_PARAM(IF_DEF_PARAMS(ifp), transmit_delay); | |
1017 | IF_DEF_PARAMS(ifp)->transmit_delay = vl_config->transmit_delay; | |
1018 | } | |
1019 | ||
1020 | return CMD_SUCCESS; | |
718e3744 | 1021 | } |
1022 | ||
1023 | ||
718e3744 | 1024 | /* The business end of all of the above */ |
d62a17ae | 1025 | static int ospf_vl_set(struct ospf *ospf, struct ospf_vl_config_data *vl_config) |
1026 | { | |
1027 | struct ospf_vl_data *vl_data; | |
1028 | int ret; | |
718e3744 | 1029 | |
d62a17ae | 1030 | vl_data = ospf_find_vl_data(ospf, vl_config); |
1031 | if (!vl_data) | |
1032 | return CMD_WARNING_CONFIG_FAILED; | |
1033 | ||
1034 | /* Process this one first as it can have a fatal result, which can | |
1035 | only logically occur if the virtual link exists already | |
1036 | Thus a command error does not result in a change to the | |
1037 | running configuration such as unexpectedly altered timer | |
1038 | values etc.*/ | |
1039 | ret = ospf_vl_set_security(vl_data, vl_config); | |
1040 | if (ret != CMD_SUCCESS) | |
1041 | return ret; | |
1042 | ||
1043 | /* Set any time based parameters, these area already range checked */ | |
1044 | ||
1045 | ret = ospf_vl_set_timers(vl_data, vl_config); | |
1046 | if (ret != CMD_SUCCESS) | |
1047 | return ret; | |
718e3744 | 1048 | |
d62a17ae | 1049 | return CMD_SUCCESS; |
718e3744 | 1050 | } |
1051 | ||
1052 | /* This stuff exists to make specifying all the alias commands A LOT simpler | |
1053 | */ | |
d62a17ae | 1054 | #define VLINK_HELPSTR_IPADDR \ |
1055 | "OSPF area parameters\n" \ | |
1056 | "OSPF area ID in IP address format\n" \ | |
1057 | "OSPF area ID as a decimal value\n" \ | |
1058 | "Configure a virtual link\n" \ | |
1059 | "Router ID of the remote ABR\n" | |
1060 | ||
1061 | #define VLINK_HELPSTR_AUTHTYPE_SIMPLE \ | |
1062 | "Enable authentication on this virtual link\n" \ | |
1063 | "dummy string \n" | |
1064 | ||
1065 | #define VLINK_HELPSTR_AUTHTYPE_ALL \ | |
1066 | VLINK_HELPSTR_AUTHTYPE_SIMPLE \ | |
1067 | "Use null authentication\n" \ | |
1068 | "Use message-digest authentication\n" | |
1069 | ||
1070 | #define VLINK_HELPSTR_TIME_PARAM \ | |
1071 | "Time between HELLO packets\n" \ | |
1072 | "Seconds\n" \ | |
1073 | "Time between retransmitting lost link state advertisements\n" \ | |
1074 | "Seconds\n" \ | |
1075 | "Link state transmit delay\n" \ | |
1076 | "Seconds\n" \ | |
1077 | "Interval time after which a neighbor is declared down\n" \ | |
1078 | "Seconds\n" | |
1079 | ||
1080 | #define VLINK_HELPSTR_AUTH_SIMPLE \ | |
1081 | "Authentication password (key)\n" \ | |
baf9eaad | 1082 | "The OSPF password (key)\n" |
d62a17ae | 1083 | |
1084 | #define VLINK_HELPSTR_AUTH_MD5 \ | |
1085 | "Message digest authentication password (key)\n" \ | |
d62a17ae | 1086 | "Key ID\n" \ |
1087 | "Use MD5 algorithm\n" \ | |
baf9eaad | 1088 | "The OSPF password (key)\n" |
718e3744 | 1089 | |
a2c62831 | 1090 | DEFUN (ospf_area_vlink, |
1091 | ospf_area_vlink_cmd, | |
3d1c6dc2 | 1092 | "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 | 1093 | VLINK_HELPSTR_IPADDR |
3d1c6dc2 | 1094 | "Enable authentication on this virtual link\n" |
7a7be519 | 1095 | "Use message-digest authentication\n" |
3d1c6dc2 | 1096 | "Use null authentication\n" |
baf9eaad CS |
1097 | VLINK_HELPSTR_AUTH_MD5 |
1098 | VLINK_HELPSTR_AUTH_SIMPLE) | |
718e3744 | 1099 | { |
a3d826f0 | 1100 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1101 | int idx_ipv4_number = 1; |
1102 | int idx_ipv4 = 3; | |
1103 | struct ospf_vl_config_data vl_config; | |
1104 | char auth_key[OSPF_AUTH_SIMPLE_SIZE + 1]; | |
1105 | char md5_key[OSPF_AUTH_MD5_SIZE + 1]; | |
d62a17ae | 1106 | int ret; |
55d1da24 | 1107 | int idx = 0; |
d62a17ae | 1108 | |
1109 | ospf_vl_config_data_init(&vl_config, vty); | |
1110 | ||
1111 | /* Read off first 2 parameters and check them */ | |
1112 | ret = str2area_id(argv[idx_ipv4_number]->arg, &vl_config.area_id, | |
1113 | &vl_config.area_id_fmt); | |
1114 | if (ret < 0) { | |
1115 | vty_out(vty, "OSPF area ID is invalid\n"); | |
1116 | return CMD_WARNING_CONFIG_FAILED; | |
1117 | } | |
718e3744 | 1118 | |
d62a17ae | 1119 | ret = inet_aton(argv[idx_ipv4]->arg, &vl_config.vl_peer); |
1120 | if (!ret) { | |
1121 | vty_out(vty, "Please specify valid Router ID as a.b.c.d\n"); | |
1122 | return CMD_WARNING_CONFIG_FAILED; | |
7a7be519 | 1123 | } |
7a7be519 | 1124 | |
d62a17ae | 1125 | if (argc <= 4) { |
1126 | /* Thats all folks! - BUGS B. strikes again!!!*/ | |
7a7be519 | 1127 | |
d62a17ae | 1128 | return ospf_vl_set(ospf, &vl_config); |
1129 | } | |
1130 | ||
3d1c6dc2 CS |
1131 | if (argv_find(argv, argc, "authentication", &idx)) { |
1132 | /* authentication - this option can only occur | |
1133 | at start of command line */ | |
1134 | vl_config.auth_type = OSPF_AUTH_SIMPLE; | |
1135 | } | |
1136 | ||
3d1c6dc2 | 1137 | if (argv_find(argv, argc, "message-digest", &idx)) { |
baf9eaad | 1138 | /* authentication message-digest */ |
3d1c6dc2 CS |
1139 | vl_config.auth_type = OSPF_AUTH_CRYPTOGRAPHIC; |
1140 | } else if (argv_find(argv, argc, "null", &idx)) { | |
1141 | /* "authentication null" */ | |
1142 | vl_config.auth_type = OSPF_AUTH_NULL; | |
d62a17ae | 1143 | } |
7a7be519 | 1144 | |
3d1c6dc2 | 1145 | if (argv_find(argv, argc, "message-digest-key", &idx)) { |
3d1c6dc2 | 1146 | vl_config.md5_key = NULL; |
cbb9b53d | 1147 | vl_config.crypto_key_id = strtol(argv[idx + 1]->arg, NULL, 10); |
3d1c6dc2 CS |
1148 | if (vl_config.crypto_key_id < 0) |
1149 | return CMD_WARNING_CONFIG_FAILED; | |
1150 | ||
4d65d927 | 1151 | strlcpy(md5_key, argv[idx + 3]->arg, sizeof(md5_key)); |
3d1c6dc2 CS |
1152 | vl_config.md5_key = md5_key; |
1153 | } | |
1154 | ||
3d1c6dc2 | 1155 | if (argv_find(argv, argc, "authentication-key", &idx)) { |
4d65d927 | 1156 | strlcpy(auth_key, argv[idx + 1]->arg, sizeof(auth_key)); |
3d1c6dc2 CS |
1157 | vl_config.auth_key = auth_key; |
1158 | } | |
7a7be519 | 1159 | |
d62a17ae | 1160 | /* Action configuration */ |
1161 | ||
1162 | return ospf_vl_set(ospf, &vl_config); | |
7a7be519 | 1163 | } |
1164 | ||
a2c62831 | 1165 | DEFUN (no_ospf_area_vlink, |
1166 | no_ospf_area_vlink_cmd, | |
3d1c6dc2 | 1167 | "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 | 1168 | NO_STR |
7a7be519 | 1169 | VLINK_HELPSTR_IPADDR |
1170 | "Enable authentication on this virtual link\n" \ | |
3d1c6dc2 | 1171 | "Use message-digest authentication\n" \ |
7a7be519 | 1172 | "Use null authentication\n" \ |
baf9eaad CS |
1173 | VLINK_HELPSTR_AUTH_MD5 |
1174 | VLINK_HELPSTR_AUTH_SIMPLE) | |
718e3744 | 1175 | { |
a3d826f0 | 1176 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1177 | int idx_ipv4_number = 2; |
1178 | int idx_ipv4 = 4; | |
1179 | struct ospf_area *area; | |
1180 | struct ospf_vl_config_data vl_config; | |
1181 | struct ospf_vl_data *vl_data = NULL; | |
1182 | char auth_key[OSPF_AUTH_SIMPLE_SIZE + 1]; | |
3d1c6dc2 | 1183 | int idx = 0; |
d62a17ae | 1184 | int ret, format; |
1185 | ||
1186 | ospf_vl_config_data_init(&vl_config, vty); | |
1187 | ||
1188 | ret = str2area_id(argv[idx_ipv4_number]->arg, &vl_config.area_id, | |
1189 | &format); | |
1190 | if (ret < 0) { | |
1191 | vty_out(vty, "OSPF area ID is invalid\n"); | |
1192 | return CMD_WARNING_CONFIG_FAILED; | |
1193 | } | |
1194 | ||
1195 | area = ospf_area_lookup_by_area_id(ospf, vl_config.area_id); | |
1196 | if (!area) { | |
1197 | vty_out(vty, "Area does not exist\n"); | |
1198 | return CMD_WARNING_CONFIG_FAILED; | |
1199 | } | |
1200 | ||
1201 | ret = inet_aton(argv[idx_ipv4]->arg, &vl_config.vl_peer); | |
1202 | if (!ret) { | |
1203 | vty_out(vty, "Please specify valid Router ID as a.b.c.d\n"); | |
1204 | return CMD_WARNING_CONFIG_FAILED; | |
1205 | } | |
718e3744 | 1206 | |
188823b0 EDP |
1207 | vl_data = ospf_vl_lookup(ospf, area, vl_config.vl_peer); |
1208 | if (!vl_data) { | |
1209 | vty_out(vty, "Virtual link does not exist\n"); | |
1210 | return CMD_WARNING_CONFIG_FAILED; | |
1211 | } | |
1212 | ||
d62a17ae | 1213 | if (argc <= 5) { |
1214 | /* Basic VLink no command */ | |
1215 | /* Thats all folks! - BUGS B. strikes again!!!*/ | |
188823b0 | 1216 | ospf_vl_delete(ospf, vl_data); |
d62a17ae | 1217 | ospf_area_check_free(ospf, vl_config.area_id); |
d62a17ae | 1218 | return CMD_SUCCESS; |
1219 | } | |
1220 | ||
1221 | /* If we are down here, we are reseting parameters */ | |
d62a17ae | 1222 | /* Deal with other parameters */ |
3d1c6dc2 CS |
1223 | |
1224 | if (argv_find(argv, argc, "authentication", &idx)) { | |
1225 | /* authentication - this option can only occur | |
1226 | at start of command line */ | |
1227 | vl_config.auth_type = OSPF_AUTH_NOTSET; | |
1228 | } | |
1229 | ||
3d1c6dc2 | 1230 | if (argv_find(argv, argc, "message-digest-key", &idx)) { |
3d1c6dc2 | 1231 | vl_config.md5_key = NULL; |
cbb9b53d | 1232 | vl_config.crypto_key_id = strtol(argv[idx + 1]->arg, NULL, 10); |
3d1c6dc2 CS |
1233 | if (vl_config.crypto_key_id < 0) |
1234 | return CMD_WARNING_CONFIG_FAILED; | |
d62a17ae | 1235 | } |
1236 | ||
3d1c6dc2 | 1237 | if (argv_find(argv, argc, "authentication-key", &idx)) { |
cbb9b53d | 1238 | /* Reset authentication-key to 0 */ |
3d1c6dc2 CS |
1239 | memset(auth_key, 0, OSPF_AUTH_SIMPLE_SIZE + 1); |
1240 | vl_config.auth_key = auth_key; | |
1241 | } | |
d62a17ae | 1242 | |
1243 | /* Action configuration */ | |
1244 | ||
1245 | return ospf_vl_set(ospf, &vl_config); | |
7a7be519 | 1246 | } |
1247 | ||
b1c02cec QY |
1248 | DEFUN (ospf_area_vlink_intervals, |
1249 | ospf_area_vlink_intervals_cmd, | |
1250 | "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)}", | |
1251 | VLINK_HELPSTR_IPADDR | |
1252 | VLINK_HELPSTR_TIME_PARAM) | |
1253 | { | |
a3d826f0 | 1254 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1255 | struct ospf_vl_config_data vl_config; |
1256 | int ret = 0; | |
1257 | ||
1258 | ospf_vl_config_data_init(&vl_config, vty); | |
1259 | ||
1260 | char *area_id = argv[1]->arg; | |
1261 | char *router_id = argv[3]->arg; | |
1262 | ||
1263 | ret = str2area_id(area_id, &vl_config.area_id, &vl_config.area_id_fmt); | |
1264 | if (ret < 0) { | |
1265 | vty_out(vty, "OSPF area ID is invalid\n"); | |
1266 | return CMD_WARNING_CONFIG_FAILED; | |
1267 | } | |
1268 | ||
1269 | ret = inet_aton(router_id, &vl_config.vl_peer); | |
1270 | if (!ret) { | |
1271 | vty_out(vty, "Please specify valid Router ID as a.b.c.d\n"); | |
1272 | return CMD_WARNING_CONFIG_FAILED; | |
1273 | } | |
1274 | ||
1275 | for (int idx = 4; idx < argc; idx++) { | |
1276 | if (strmatch(argv[idx]->text, "hello-interval")) | |
1277 | vl_config.hello_interval = | |
1278 | strtol(argv[++idx]->arg, NULL, 10); | |
1279 | else if (strmatch(argv[idx]->text, "retransmit-interval")) | |
1280 | vl_config.retransmit_interval = | |
1281 | strtol(argv[++idx]->arg, NULL, 10); | |
1282 | else if (strmatch(argv[idx]->text, "transmit-delay")) | |
1283 | vl_config.transmit_delay = | |
1284 | strtol(argv[++idx]->arg, NULL, 10); | |
1285 | else if (strmatch(argv[idx]->text, "dead-interval")) | |
1286 | vl_config.dead_interval = | |
1287 | strtol(argv[++idx]->arg, NULL, 10); | |
1288 | } | |
1289 | ||
1290 | /* Action configuration */ | |
1291 | return ospf_vl_set(ospf, &vl_config); | |
b1c02cec QY |
1292 | } |
1293 | ||
7a7be519 | 1294 | DEFUN (no_ospf_area_vlink_intervals, |
1295 | no_ospf_area_vlink_intervals_cmd, | |
a663a38e | 1296 | "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 | 1297 | NO_STR |
7a7be519 | 1298 | VLINK_HELPSTR_IPADDR |
7a7be519 | 1299 | VLINK_HELPSTR_TIME_PARAM) |
1300 | { | |
a3d826f0 | 1301 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1302 | struct ospf_vl_config_data vl_config; |
1303 | int ret = 0; | |
1304 | ||
1305 | ospf_vl_config_data_init(&vl_config, vty); | |
1306 | ||
1307 | char *area_id = argv[2]->arg; | |
1308 | char *router_id = argv[4]->arg; | |
1309 | ||
1310 | ret = str2area_id(area_id, &vl_config.area_id, &vl_config.area_id_fmt); | |
1311 | if (ret < 0) { | |
1312 | vty_out(vty, "OSPF area ID is invalid\n"); | |
1313 | return CMD_WARNING_CONFIG_FAILED; | |
1314 | } | |
1315 | ||
1316 | ret = inet_aton(router_id, &vl_config.vl_peer); | |
1317 | if (!ret) { | |
1318 | vty_out(vty, "Please specify valid Router ID as a.b.c.d\n"); | |
1319 | return CMD_WARNING_CONFIG_FAILED; | |
1320 | } | |
1321 | ||
1322 | for (int idx = 5; idx < argc; idx++) { | |
1323 | if (strmatch(argv[idx]->text, "hello-interval")) | |
1324 | vl_config.hello_interval = OSPF_HELLO_INTERVAL_DEFAULT; | |
1325 | else if (strmatch(argv[idx]->text, "retransmit-interval")) | |
1326 | vl_config.retransmit_interval = | |
1327 | OSPF_RETRANSMIT_INTERVAL_DEFAULT; | |
1328 | else if (strmatch(argv[idx]->text, "transmit-delay")) | |
1329 | vl_config.transmit_delay = OSPF_TRANSMIT_DELAY_DEFAULT; | |
1330 | else if (strmatch(argv[idx]->text, "dead-interval")) | |
1331 | vl_config.dead_interval = | |
1332 | OSPF_ROUTER_DEAD_INTERVAL_DEFAULT; | |
1333 | } | |
1334 | ||
1335 | /* Action configuration */ | |
1336 | return ospf_vl_set(ospf, &vl_config); | |
718e3744 | 1337 | } |
1338 | ||
a2c62831 | 1339 | DEFUN (ospf_area_shortcut, |
1340 | ospf_area_shortcut_cmd, | |
6147e2c6 | 1341 | "area <A.B.C.D|(0-4294967295)> shortcut <default|enable|disable>", |
718e3744 | 1342 | "OSPF area parameters\n" |
1343 | "OSPF area ID in IP address format\n" | |
1344 | "OSPF area ID as a decimal value\n" | |
1345 | "Configure the area's shortcutting mode\n" | |
1346 | "Set default shortcutting behavior\n" | |
1347 | "Enable shortcutting through the area\n" | |
1348 | "Disable shortcutting through the area\n") | |
1349 | { | |
a3d826f0 | 1350 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1351 | int idx_ipv4_number = 1; |
1352 | int idx_enable_disable = 3; | |
1353 | struct ospf_area *area; | |
1354 | struct in_addr area_id; | |
1355 | int mode; | |
1356 | int format; | |
1357 | ||
1358 | VTY_GET_OSPF_AREA_ID_NO_BB("shortcut", area_id, format, | |
1359 | argv[idx_ipv4_number]->arg); | |
1360 | ||
1361 | area = ospf_area_get(ospf, area_id); | |
1362 | ospf_area_display_format_set(ospf, area, format); | |
1363 | ||
1364 | if (strncmp(argv[idx_enable_disable]->arg, "de", 2) == 0) | |
1365 | mode = OSPF_SHORTCUT_DEFAULT; | |
1366 | else if (strncmp(argv[idx_enable_disable]->arg, "di", 2) == 0) | |
1367 | mode = OSPF_SHORTCUT_DISABLE; | |
1368 | else if (strncmp(argv[idx_enable_disable]->arg, "e", 1) == 0) | |
1369 | mode = OSPF_SHORTCUT_ENABLE; | |
1370 | else | |
1371 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 1372 | |
d62a17ae | 1373 | ospf_area_shortcut_set(ospf, area, mode); |
718e3744 | 1374 | |
d62a17ae | 1375 | if (ospf->abr_type != OSPF_ABR_SHORTCUT) |
1376 | vty_out(vty, | |
1377 | "Shortcut area setting will take effect " | |
1378 | "only when the router is configured as Shortcut ABR\n"); | |
718e3744 | 1379 | |
d62a17ae | 1380 | return CMD_SUCCESS; |
718e3744 | 1381 | } |
1382 | ||
a2c62831 | 1383 | DEFUN (no_ospf_area_shortcut, |
1384 | no_ospf_area_shortcut_cmd, | |
6147e2c6 | 1385 | "no area <A.B.C.D|(0-4294967295)> shortcut <enable|disable>", |
718e3744 | 1386 | NO_STR |
1387 | "OSPF area parameters\n" | |
1388 | "OSPF area ID in IP address format\n" | |
1389 | "OSPF area ID as a decimal value\n" | |
1390 | "Deconfigure the area's shortcutting mode\n" | |
1391 | "Deconfigure enabled shortcutting through the area\n" | |
1392 | "Deconfigure disabled shortcutting through the area\n") | |
1393 | { | |
a3d826f0 | 1394 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1395 | int idx_ipv4_number = 2; |
1396 | struct ospf_area *area; | |
1397 | struct in_addr area_id; | |
1398 | int format; | |
718e3744 | 1399 | |
d62a17ae | 1400 | VTY_GET_OSPF_AREA_ID_NO_BB("shortcut", area_id, format, |
1401 | argv[idx_ipv4_number]->arg); | |
718e3744 | 1402 | |
d62a17ae | 1403 | area = ospf_area_lookup_by_area_id(ospf, area_id); |
1404 | if (!area) | |
1405 | return CMD_SUCCESS; | |
718e3744 | 1406 | |
d62a17ae | 1407 | ospf_area_shortcut_unset(ospf, area); |
718e3744 | 1408 | |
d62a17ae | 1409 | return CMD_SUCCESS; |
718e3744 | 1410 | } |
1411 | ||
6b0655a2 | 1412 | |
a2c62831 | 1413 | DEFUN (ospf_area_stub, |
1414 | ospf_area_stub_cmd, | |
6147e2c6 | 1415 | "area <A.B.C.D|(0-4294967295)> stub", |
718e3744 | 1416 | "OSPF area parameters\n" |
1417 | "OSPF area ID in IP address format\n" | |
1418 | "OSPF area ID as a decimal value\n" | |
1419 | "Configure OSPF area as stub\n") | |
1420 | { | |
a3d826f0 | 1421 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1422 | int idx_ipv4_number = 1; |
1423 | struct in_addr area_id; | |
1424 | int ret, format; | |
1425 | ||
1426 | VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id, format, | |
1427 | argv[idx_ipv4_number]->arg); | |
1428 | ||
1429 | ret = ospf_area_stub_set(ospf, area_id); | |
1430 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
1431 | format); | |
1432 | if (ret == 0) { | |
1433 | vty_out(vty, | |
1434 | "First deconfigure all virtual link through this area\n"); | |
1435 | return CMD_WARNING_CONFIG_FAILED; | |
1436 | } | |
718e3744 | 1437 | |
d62a17ae | 1438 | ospf_area_no_summary_unset(ospf, area_id); |
718e3744 | 1439 | |
d62a17ae | 1440 | return CMD_SUCCESS; |
718e3744 | 1441 | } |
1442 | ||
a2c62831 | 1443 | DEFUN (ospf_area_stub_no_summary, |
1444 | ospf_area_stub_no_summary_cmd, | |
6147e2c6 | 1445 | "area <A.B.C.D|(0-4294967295)> stub no-summary", |
718e3744 | 1446 | "OSPF stub parameters\n" |
1447 | "OSPF area ID in IP address format\n" | |
1448 | "OSPF area ID as a decimal value\n" | |
1449 | "Configure OSPF area as stub\n" | |
1450 | "Do not inject inter-area routes into stub\n") | |
1451 | { | |
a3d826f0 | 1452 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1453 | int idx_ipv4_number = 1; |
1454 | struct in_addr area_id; | |
1455 | int ret, format; | |
1456 | ||
1457 | VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id, format, | |
1458 | argv[idx_ipv4_number]->arg); | |
1459 | ||
1460 | ret = ospf_area_stub_set(ospf, area_id); | |
1461 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
1462 | format); | |
1463 | if (ret == 0) { | |
1464 | vty_out(vty, | |
1465 | "%% Area cannot be stub as it contains a virtual link\n"); | |
1466 | return CMD_WARNING_CONFIG_FAILED; | |
1467 | } | |
718e3744 | 1468 | |
d62a17ae | 1469 | ospf_area_no_summary_set(ospf, area_id); |
718e3744 | 1470 | |
d62a17ae | 1471 | return CMD_SUCCESS; |
718e3744 | 1472 | } |
1473 | ||
a2c62831 | 1474 | DEFUN (no_ospf_area_stub, |
1475 | no_ospf_area_stub_cmd, | |
6147e2c6 | 1476 | "no area <A.B.C.D|(0-4294967295)> stub", |
718e3744 | 1477 | NO_STR |
1478 | "OSPF area parameters\n" | |
1479 | "OSPF area ID in IP address format\n" | |
1480 | "OSPF area ID as a decimal value\n" | |
1481 | "Configure OSPF area as stub\n") | |
1482 | { | |
a3d826f0 | 1483 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1484 | int idx_ipv4_number = 2; |
1485 | struct in_addr area_id; | |
1486 | int format; | |
718e3744 | 1487 | |
d62a17ae | 1488 | VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id, format, |
1489 | argv[idx_ipv4_number]->arg); | |
718e3744 | 1490 | |
d62a17ae | 1491 | ospf_area_stub_unset(ospf, area_id); |
1492 | ospf_area_no_summary_unset(ospf, area_id); | |
718e3744 | 1493 | |
d62a17ae | 1494 | return CMD_SUCCESS; |
718e3744 | 1495 | } |
1496 | ||
a2c62831 | 1497 | DEFUN (no_ospf_area_stub_no_summary, |
1498 | no_ospf_area_stub_no_summary_cmd, | |
6147e2c6 | 1499 | "no area <A.B.C.D|(0-4294967295)> stub no-summary", |
718e3744 | 1500 | NO_STR |
1501 | "OSPF area parameters\n" | |
1502 | "OSPF area ID in IP address format\n" | |
1503 | "OSPF area ID as a decimal value\n" | |
1504 | "Configure OSPF area as stub\n" | |
1505 | "Do not inject inter-area routes into area\n") | |
1506 | { | |
a3d826f0 | 1507 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1508 | int idx_ipv4_number = 2; |
1509 | struct in_addr area_id; | |
1510 | int format; | |
718e3744 | 1511 | |
d62a17ae | 1512 | VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id, format, |
1513 | argv[idx_ipv4_number]->arg); | |
1514 | ospf_area_no_summary_unset(ospf, area_id); | |
718e3744 | 1515 | |
d62a17ae | 1516 | return CMD_SUCCESS; |
718e3744 | 1517 | } |
1518 | ||
d62a17ae | 1519 | static int ospf_area_nssa_cmd_handler(struct vty *vty, int argc, |
7ef56a73 CS |
1520 | struct cmd_token **argv, int cfg_nosum, |
1521 | int nosum) | |
718e3744 | 1522 | { |
a3d826f0 | 1523 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1524 | struct in_addr area_id; |
1525 | int ret, format; | |
1526 | ||
1527 | VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id, format, argv[1]->arg); | |
1528 | ||
1529 | ret = ospf_area_nssa_set(ospf, area_id); | |
1530 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
1531 | format); | |
1532 | if (ret == 0) { | |
1533 | vty_out(vty, | |
1534 | "%% Area cannot be nssa as it contains a virtual link\n"); | |
1535 | return CMD_WARNING_CONFIG_FAILED; | |
1536 | } | |
1537 | ||
1538 | if (argc > 3) { | |
1539 | if (strncmp(argv[3]->text, "translate-c", 11) == 0) | |
1540 | ospf_area_nssa_translator_role_set( | |
1541 | ospf, area_id, OSPF_NSSA_ROLE_CANDIDATE); | |
1542 | else if (strncmp(argv[3]->text, "translate-n", 11) == 0) | |
1543 | ospf_area_nssa_translator_role_set( | |
1544 | ospf, area_id, OSPF_NSSA_ROLE_NEVER); | |
1545 | else if (strncmp(argv[3]->text, "translate-a", 11) == 0) | |
1546 | ospf_area_nssa_translator_role_set( | |
1547 | ospf, area_id, OSPF_NSSA_ROLE_ALWAYS); | |
1548 | } else { | |
1549 | ospf_area_nssa_translator_role_set(ospf, area_id, | |
1550 | OSPF_NSSA_ROLE_CANDIDATE); | |
1551 | } | |
1552 | ||
7ef56a73 CS |
1553 | if (cfg_nosum) { |
1554 | if (nosum) | |
1555 | ospf_area_no_summary_set(ospf, area_id); | |
1556 | else | |
1557 | ospf_area_no_summary_unset(ospf, area_id); | |
1558 | } | |
d62a17ae | 1559 | |
1560 | ospf_schedule_abr_task(ospf); | |
1561 | ||
1562 | return CMD_SUCCESS; | |
718e3744 | 1563 | } |
1564 | ||
718e3744 | 1565 | |
b0a053be | 1566 | DEFUN (ospf_area_nssa_translate, |
a2c62831 | 1567 | ospf_area_nssa_translate_cmd, |
6147e2c6 | 1568 | "area <A.B.C.D|(0-4294967295)> nssa <translate-candidate|translate-never|translate-always>", |
718e3744 | 1569 | "OSPF area parameters\n" |
1570 | "OSPF area ID in IP address format\n" | |
1571 | "OSPF area ID as a decimal value\n" | |
1572 | "Configure OSPF area as nssa\n" | |
1573 | "Configure NSSA-ABR for translate election (default)\n" | |
1574 | "Configure NSSA-ABR to never translate\n" | |
1575 | "Configure NSSA-ABR to always translate\n") | |
b0a053be | 1576 | { |
7ef56a73 | 1577 | return ospf_area_nssa_cmd_handler(vty, argc, argv, 0, 0); |
b0a053be | 1578 | } |
1579 | ||
1580 | DEFUN (ospf_area_nssa, | |
1581 | ospf_area_nssa_cmd, | |
6147e2c6 | 1582 | "area <A.B.C.D|(0-4294967295)> nssa", |
b0a053be | 1583 | "OSPF area parameters\n" |
1584 | "OSPF area ID in IP address format\n" | |
1585 | "OSPF area ID as a decimal value\n" | |
1586 | "Configure OSPF area as nssa\n") | |
1587 | { | |
2643b2bc | 1588 | return ospf_area_nssa_cmd_handler(vty, argc, argv, 0, 0); |
b0a053be | 1589 | } |
718e3744 | 1590 | |
a2c62831 | 1591 | DEFUN (ospf_area_nssa_no_summary, |
1592 | ospf_area_nssa_no_summary_cmd, | |
6147e2c6 | 1593 | "area <A.B.C.D|(0-4294967295)> nssa no-summary", |
718e3744 | 1594 | "OSPF area parameters\n" |
1595 | "OSPF area ID in IP address format\n" | |
1596 | "OSPF area ID as a decimal value\n" | |
1597 | "Configure OSPF area as nssa\n" | |
1598 | "Do not inject inter-area routes into nssa\n") | |
1599 | { | |
7ef56a73 CS |
1600 | int idx_ipv4_number = 1; |
1601 | struct in_addr area_id; | |
1602 | int format; | |
1603 | ||
1604 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
1605 | VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id, format, | |
1606 | argv[idx_ipv4_number]->arg); | |
1607 | ||
1608 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
1609 | format); | |
1610 | ospf_area_nssa_no_summary_set(ospf, area_id); | |
1611 | ||
1612 | ospf_schedule_abr_task(ospf); | |
1613 | ||
1614 | return CMD_SUCCESS; | |
1615 | } | |
1616 | ||
1617 | DEFUN (no_ospf_area_nssa_no_summary, | |
1618 | no_ospf_area_nssa_no_summary_cmd, | |
1619 | "no area <A.B.C.D|(0-4294967295)> nssa no-summary", | |
1620 | NO_STR | |
1621 | "OSPF area parameters\n" | |
1622 | "OSPF area ID in IP address format\n" | |
1623 | "OSPF area ID as a decimal value\n" | |
1624 | "Configure OSPF area as nssa\n" | |
1625 | "Do not inject inter-area routes into nssa\n") | |
1626 | { | |
1627 | int idx_ipv4_number = 2; | |
1628 | struct in_addr area_id; | |
1629 | int format; | |
1630 | ||
1631 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
1632 | ||
1633 | VTY_GET_OSPF_AREA_ID_NO_BB("nssa", area_id, format, | |
1634 | argv[idx_ipv4_number]->arg); | |
1635 | ||
1636 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
1637 | format); | |
1638 | ospf_area_no_summary_unset(ospf, area_id); | |
1639 | ||
1640 | ospf_schedule_abr_task(ospf); | |
1641 | ||
1642 | return CMD_SUCCESS; | |
718e3744 | 1643 | } |
1644 | ||
a2c62831 | 1645 | DEFUN (no_ospf_area_nssa, |
1646 | no_ospf_area_nssa_cmd, | |
7ef56a73 | 1647 | "no area <A.B.C.D|(0-4294967295)> nssa [<translate-candidate|translate-never|translate-always>]", |
718e3744 | 1648 | NO_STR |
1649 | "OSPF area parameters\n" | |
1650 | "OSPF area ID in IP address format\n" | |
1651 | "OSPF area ID as a decimal value\n" | |
7a7be519 | 1652 | "Configure OSPF area as nssa\n" |
1653 | "Configure NSSA-ABR for translate election (default)\n" | |
1654 | "Configure NSSA-ABR to never translate\n" | |
7ef56a73 | 1655 | "Configure NSSA-ABR to always translate\n") |
22b27e95 | 1656 | { |
a3d826f0 | 1657 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1658 | int idx_ipv4_number = 2; |
1659 | struct in_addr area_id; | |
1660 | int format; | |
718e3744 | 1661 | |
d62a17ae | 1662 | VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id, format, |
1663 | argv[idx_ipv4_number]->arg); | |
718e3744 | 1664 | |
7ef56a73 | 1665 | ospf_area_nssa_unset(ospf, area_id, argc); |
718e3744 | 1666 | |
d62a17ae | 1667 | ospf_schedule_abr_task(ospf); |
b0a053be | 1668 | |
d62a17ae | 1669 | return CMD_SUCCESS; |
718e3744 | 1670 | } |
1671 | ||
718e3744 | 1672 | |
a2c62831 | 1673 | DEFUN (ospf_area_default_cost, |
1674 | ospf_area_default_cost_cmd, | |
6147e2c6 | 1675 | "area <A.B.C.D|(0-4294967295)> default-cost (0-16777215)", |
718e3744 | 1676 | "OSPF area parameters\n" |
1677 | "OSPF area ID in IP address format\n" | |
1678 | "OSPF area ID as a decimal value\n" | |
1679 | "Set the summary-default cost of a NSSA or stub area\n" | |
1680 | "Stub's advertised default summary cost\n") | |
1681 | { | |
a3d826f0 | 1682 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1683 | int idx_ipv4_number = 1; |
1684 | int idx_number = 3; | |
1685 | struct ospf_area *area; | |
1686 | struct in_addr area_id; | |
d7c0a89a | 1687 | uint32_t cost; |
d62a17ae | 1688 | int format; |
1689 | struct prefix_ipv4 p; | |
1690 | ||
1691 | VTY_GET_OSPF_AREA_ID_NO_BB("default-cost", area_id, format, | |
1692 | argv[idx_ipv4_number]->arg); | |
1693 | cost = strtoul(argv[idx_number]->arg, NULL, 10); | |
1694 | ||
1695 | area = ospf_area_get(ospf, area_id); | |
1696 | ospf_area_display_format_set(ospf, area, format); | |
1697 | ||
1698 | if (area->external_routing == OSPF_AREA_DEFAULT) { | |
1699 | vty_out(vty, "The area is neither stub, nor NSSA\n"); | |
1700 | return CMD_WARNING_CONFIG_FAILED; | |
1701 | } | |
ba682537 | 1702 | |
d62a17ae | 1703 | area->default_cost = cost; |
1704 | ||
1705 | p.family = AF_INET; | |
1706 | p.prefix.s_addr = OSPF_DEFAULT_DESTINATION; | |
1707 | p.prefixlen = 0; | |
1708 | if (IS_DEBUG_OSPF_EVENT) | |
1709 | zlog_debug( | |
1710 | "ospf_abr_announce_stub_defaults(): " | |
1711 | "announcing 0.0.0.0/0 to area %s", | |
1712 | inet_ntoa(area->area_id)); | |
1713 | ospf_abr_announce_network_to_area(&p, area->default_cost, area); | |
1714 | ||
1715 | return CMD_SUCCESS; | |
718e3744 | 1716 | } |
1717 | ||
a2c62831 | 1718 | DEFUN (no_ospf_area_default_cost, |
1719 | no_ospf_area_default_cost_cmd, | |
6147e2c6 | 1720 | "no area <A.B.C.D|(0-4294967295)> default-cost (0-16777215)", |
718e3744 | 1721 | NO_STR |
1722 | "OSPF area parameters\n" | |
1723 | "OSPF area ID in IP address format\n" | |
1724 | "OSPF area ID as a decimal value\n" | |
1725 | "Set the summary-default cost of a NSSA or stub area\n" | |
1726 | "Stub's advertised default summary cost\n") | |
1727 | { | |
a3d826f0 | 1728 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1729 | int idx_ipv4_number = 2; |
1730 | struct ospf_area *area; | |
1731 | struct in_addr area_id; | |
1732 | int format; | |
1733 | struct prefix_ipv4 p; | |
718e3744 | 1734 | |
d62a17ae | 1735 | VTY_GET_OSPF_AREA_ID_NO_BB("default-cost", area_id, format, |
1736 | argv[idx_ipv4_number]->arg); | |
718e3744 | 1737 | |
d62a17ae | 1738 | area = ospf_area_lookup_by_area_id(ospf, area_id); |
1739 | if (area == NULL) | |
1740 | return CMD_SUCCESS; | |
718e3744 | 1741 | |
d62a17ae | 1742 | if (area->external_routing == OSPF_AREA_DEFAULT) { |
1743 | vty_out(vty, "The area is neither stub, nor NSSA\n"); | |
1744 | return CMD_WARNING_CONFIG_FAILED; | |
1745 | } | |
718e3744 | 1746 | |
d62a17ae | 1747 | area->default_cost = 1; |
718e3744 | 1748 | |
d62a17ae | 1749 | p.family = AF_INET; |
1750 | p.prefix.s_addr = OSPF_DEFAULT_DESTINATION; | |
1751 | p.prefixlen = 0; | |
1752 | if (IS_DEBUG_OSPF_EVENT) | |
1753 | zlog_debug( | |
1754 | "ospf_abr_announce_stub_defaults(): " | |
1755 | "announcing 0.0.0.0/0 to area %s", | |
1756 | inet_ntoa(area->area_id)); | |
1757 | ospf_abr_announce_network_to_area(&p, area->default_cost, area); | |
ba682537 | 1758 | |
1759 | ||
d62a17ae | 1760 | ospf_area_check_free(ospf, area_id); |
718e3744 | 1761 | |
d62a17ae | 1762 | return CMD_SUCCESS; |
718e3744 | 1763 | } |
1764 | ||
a2c62831 | 1765 | DEFUN (ospf_area_export_list, |
1766 | ospf_area_export_list_cmd, | |
6147e2c6 | 1767 | "area <A.B.C.D|(0-4294967295)> export-list NAME", |
718e3744 | 1768 | "OSPF area parameters\n" |
1769 | "OSPF area ID in IP address format\n" | |
1770 | "OSPF area ID as a decimal value\n" | |
1771 | "Set the filter for networks announced to other areas\n" | |
1772 | "Name of the access-list\n") | |
1773 | { | |
a3d826f0 | 1774 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1775 | int idx_ipv4_number = 1; |
1776 | struct ospf_area *area; | |
1777 | struct in_addr area_id; | |
1778 | int format; | |
718e3744 | 1779 | |
d62a17ae | 1780 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
52930766 | 1781 | |
d62a17ae | 1782 | area = ospf_area_get(ospf, area_id); |
1783 | ospf_area_display_format_set(ospf, area, format); | |
1784 | ospf_area_export_list_set(ospf, area, argv[3]->arg); | |
718e3744 | 1785 | |
d62a17ae | 1786 | return CMD_SUCCESS; |
718e3744 | 1787 | } |
1788 | ||
a2c62831 | 1789 | DEFUN (no_ospf_area_export_list, |
1790 | no_ospf_area_export_list_cmd, | |
6147e2c6 | 1791 | "no area <A.B.C.D|(0-4294967295)> export-list NAME", |
718e3744 | 1792 | NO_STR |
1793 | "OSPF area parameters\n" | |
1794 | "OSPF area ID in IP address format\n" | |
1795 | "OSPF area ID as a decimal value\n" | |
1796 | "Unset the filter for networks announced to other areas\n" | |
1797 | "Name of the access-list\n") | |
1798 | { | |
a3d826f0 | 1799 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1800 | int idx_ipv4_number = 2; |
1801 | struct ospf_area *area; | |
1802 | struct in_addr area_id; | |
1803 | int format; | |
718e3744 | 1804 | |
d62a17ae | 1805 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
52930766 | 1806 | |
d62a17ae | 1807 | area = ospf_area_lookup_by_area_id(ospf, area_id); |
1808 | if (area == NULL) | |
1809 | return CMD_SUCCESS; | |
718e3744 | 1810 | |
d62a17ae | 1811 | ospf_area_export_list_unset(ospf, area); |
718e3744 | 1812 | |
d62a17ae | 1813 | return CMD_SUCCESS; |
718e3744 | 1814 | } |
1815 | ||
1816 | ||
a2c62831 | 1817 | DEFUN (ospf_area_import_list, |
1818 | ospf_area_import_list_cmd, | |
6147e2c6 | 1819 | "area <A.B.C.D|(0-4294967295)> import-list NAME", |
718e3744 | 1820 | "OSPF area parameters\n" |
1821 | "OSPF area ID in IP address format\n" | |
1822 | "OSPF area ID as a decimal value\n" | |
1823 | "Set the filter for networks from other areas announced to the specified one\n" | |
1824 | "Name of the access-list\n") | |
1825 | { | |
a3d826f0 | 1826 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1827 | int idx_ipv4_number = 1; |
1828 | struct ospf_area *area; | |
1829 | struct in_addr area_id; | |
1830 | int format; | |
718e3744 | 1831 | |
d62a17ae | 1832 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
52930766 | 1833 | |
d62a17ae | 1834 | area = ospf_area_get(ospf, area_id); |
1835 | ospf_area_display_format_set(ospf, area, format); | |
1836 | ospf_area_import_list_set(ospf, area, argv[3]->arg); | |
718e3744 | 1837 | |
d62a17ae | 1838 | return CMD_SUCCESS; |
718e3744 | 1839 | } |
1840 | ||
a2c62831 | 1841 | DEFUN (no_ospf_area_import_list, |
1842 | no_ospf_area_import_list_cmd, | |
6147e2c6 | 1843 | "no area <A.B.C.D|(0-4294967295)> import-list NAME", |
718e3744 | 1844 | NO_STR |
1845 | "OSPF area parameters\n" | |
1846 | "OSPF area ID in IP address format\n" | |
1847 | "OSPF area ID as a decimal value\n" | |
1848 | "Unset the filter for networks announced to other areas\n" | |
1849 | "Name of the access-list\n") | |
1850 | { | |
a3d826f0 | 1851 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1852 | int idx_ipv4_number = 2; |
1853 | struct ospf_area *area; | |
1854 | struct in_addr area_id; | |
1855 | int format; | |
718e3744 | 1856 | |
d62a17ae | 1857 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
52930766 | 1858 | |
d62a17ae | 1859 | area = ospf_area_lookup_by_area_id(ospf, area_id); |
1860 | if (area == NULL) | |
1861 | return CMD_SUCCESS; | |
718e3744 | 1862 | |
d62a17ae | 1863 | ospf_area_import_list_unset(ospf, area); |
718e3744 | 1864 | |
d62a17ae | 1865 | return CMD_SUCCESS; |
718e3744 | 1866 | } |
1867 | ||
a2c62831 | 1868 | DEFUN (ospf_area_filter_list, |
1869 | ospf_area_filter_list_cmd, | |
6147e2c6 | 1870 | "area <A.B.C.D|(0-4294967295)> filter-list prefix WORD <in|out>", |
718e3744 | 1871 | "OSPF area parameters\n" |
1872 | "OSPF area ID in IP address format\n" | |
1873 | "OSPF area ID as a decimal value\n" | |
1874 | "Filter networks between OSPF areas\n" | |
1875 | "Filter prefixes between OSPF areas\n" | |
1876 | "Name of an IP prefix-list\n" | |
1877 | "Filter networks sent to this area\n" | |
1878 | "Filter networks sent from this area\n") | |
1879 | { | |
a3d826f0 | 1880 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1881 | int idx_ipv4_number = 1; |
1882 | int idx_word = 4; | |
1883 | int idx_in_out = 5; | |
1884 | struct ospf_area *area; | |
1885 | struct in_addr area_id; | |
1886 | struct prefix_list *plist; | |
1887 | int format; | |
1888 | ||
1889 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); | |
1890 | ||
1891 | area = ospf_area_get(ospf, area_id); | |
1892 | ospf_area_display_format_set(ospf, area, format); | |
1893 | plist = prefix_list_lookup(AFI_IP, argv[idx_word]->arg); | |
1894 | if (strncmp(argv[idx_in_out]->arg, "in", 2) == 0) { | |
1895 | PREFIX_LIST_IN(area) = plist; | |
1896 | if (PREFIX_NAME_IN(area)) | |
1897 | free(PREFIX_NAME_IN(area)); | |
1898 | ||
1899 | PREFIX_NAME_IN(area) = strdup(argv[idx_word]->arg); | |
1900 | ospf_schedule_abr_task(ospf); | |
1901 | } else { | |
1902 | PREFIX_LIST_OUT(area) = plist; | |
1903 | if (PREFIX_NAME_OUT(area)) | |
1904 | free(PREFIX_NAME_OUT(area)); | |
1905 | ||
1906 | PREFIX_NAME_OUT(area) = strdup(argv[idx_word]->arg); | |
1907 | ospf_schedule_abr_task(ospf); | |
1908 | } | |
718e3744 | 1909 | |
d62a17ae | 1910 | return CMD_SUCCESS; |
718e3744 | 1911 | } |
1912 | ||
a2c62831 | 1913 | DEFUN (no_ospf_area_filter_list, |
1914 | no_ospf_area_filter_list_cmd, | |
6147e2c6 | 1915 | "no area <A.B.C.D|(0-4294967295)> filter-list prefix WORD <in|out>", |
718e3744 | 1916 | NO_STR |
1917 | "OSPF area parameters\n" | |
1918 | "OSPF area ID in IP address format\n" | |
1919 | "OSPF area ID as a decimal value\n" | |
1920 | "Filter networks between OSPF areas\n" | |
1921 | "Filter prefixes between OSPF areas\n" | |
1922 | "Name of an IP prefix-list\n" | |
1923 | "Filter networks sent to this area\n" | |
1924 | "Filter networks sent from this area\n") | |
1925 | { | |
a3d826f0 | 1926 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1927 | int idx_ipv4_number = 2; |
1928 | int idx_word = 5; | |
1929 | int idx_in_out = 6; | |
1930 | struct ospf_area *area; | |
1931 | struct in_addr area_id; | |
1932 | int format; | |
718e3744 | 1933 | |
d62a17ae | 1934 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
718e3744 | 1935 | |
d62a17ae | 1936 | if ((area = ospf_area_lookup_by_area_id(ospf, area_id)) == NULL) |
1937 | return CMD_SUCCESS; | |
718e3744 | 1938 | |
d62a17ae | 1939 | if (strncmp(argv[idx_in_out]->arg, "in", 2) == 0) { |
1940 | if (PREFIX_NAME_IN(area)) | |
1941 | if (strcmp(PREFIX_NAME_IN(area), argv[idx_word]->arg) | |
1942 | != 0) | |
1943 | return CMD_SUCCESS; | |
718e3744 | 1944 | |
d62a17ae | 1945 | PREFIX_LIST_IN(area) = NULL; |
1946 | if (PREFIX_NAME_IN(area)) | |
1947 | free(PREFIX_NAME_IN(area)); | |
718e3744 | 1948 | |
d62a17ae | 1949 | PREFIX_NAME_IN(area) = NULL; |
718e3744 | 1950 | |
d62a17ae | 1951 | ospf_schedule_abr_task(ospf); |
1952 | } else { | |
1953 | if (PREFIX_NAME_OUT(area)) | |
1954 | if (strcmp(PREFIX_NAME_OUT(area), argv[idx_word]->arg) | |
1955 | != 0) | |
1956 | return CMD_SUCCESS; | |
718e3744 | 1957 | |
d62a17ae | 1958 | PREFIX_LIST_OUT(area) = NULL; |
1959 | if (PREFIX_NAME_OUT(area)) | |
1960 | free(PREFIX_NAME_OUT(area)); | |
718e3744 | 1961 | |
d62a17ae | 1962 | PREFIX_NAME_OUT(area) = NULL; |
718e3744 | 1963 | |
d62a17ae | 1964 | ospf_schedule_abr_task(ospf); |
1965 | } | |
1966 | ||
1967 | return CMD_SUCCESS; | |
718e3744 | 1968 | } |
1969 | ||
6b0655a2 | 1970 | |
a2c62831 | 1971 | DEFUN (ospf_area_authentication_message_digest, |
1972 | ospf_area_authentication_message_digest_cmd, | |
32573073 QY |
1973 | "[no] area <A.B.C.D|(0-4294967295)> authentication message-digest", |
1974 | NO_STR | |
718e3744 | 1975 | "OSPF area parameters\n" |
2b00515a CF |
1976 | "OSPF area ID in IP address format\n" |
1977 | "OSPF area ID as a decimal value\n" | |
718e3744 | 1978 | "Enable authentication\n" |
1979 | "Use message-digest authentication\n") | |
1980 | { | |
a3d826f0 | 1981 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
ca19319b | 1982 | int idx = 0; |
d62a17ae | 1983 | struct ospf_area *area; |
1984 | struct in_addr area_id; | |
1985 | int format; | |
718e3744 | 1986 | |
ca19319b | 1987 | argv_find(argv, argc, "area", &idx); |
1988 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx + 1]->arg); | |
718e3744 | 1989 | |
d62a17ae | 1990 | area = ospf_area_get(ospf, area_id); |
1991 | ospf_area_display_format_set(ospf, area, format); | |
996c9314 LB |
1992 | area->auth_type = strmatch(argv[0]->text, "no") |
1993 | ? OSPF_AUTH_NULL | |
1994 | : OSPF_AUTH_CRYPTOGRAPHIC; | |
718e3744 | 1995 | |
d62a17ae | 1996 | return CMD_SUCCESS; |
718e3744 | 1997 | } |
1998 | ||
a2c62831 | 1999 | DEFUN (ospf_area_authentication, |
2000 | ospf_area_authentication_cmd, | |
6147e2c6 | 2001 | "area <A.B.C.D|(0-4294967295)> authentication", |
718e3744 | 2002 | "OSPF area parameters\n" |
2003 | "OSPF area ID in IP address format\n" | |
2004 | "OSPF area ID as a decimal value\n" | |
2005 | "Enable authentication\n") | |
2006 | { | |
a3d826f0 | 2007 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2008 | int idx_ipv4_number = 1; |
2009 | struct ospf_area *area; | |
2010 | struct in_addr area_id; | |
2011 | int format; | |
718e3744 | 2012 | |
d62a17ae | 2013 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
718e3744 | 2014 | |
d62a17ae | 2015 | area = ospf_area_get(ospf, area_id); |
2016 | ospf_area_display_format_set(ospf, area, format); | |
2017 | area->auth_type = OSPF_AUTH_SIMPLE; | |
718e3744 | 2018 | |
d62a17ae | 2019 | return CMD_SUCCESS; |
718e3744 | 2020 | } |
2021 | ||
a2c62831 | 2022 | DEFUN (no_ospf_area_authentication, |
2023 | no_ospf_area_authentication_cmd, | |
6147e2c6 | 2024 | "no area <A.B.C.D|(0-4294967295)> authentication", |
718e3744 | 2025 | NO_STR |
2026 | "OSPF area parameters\n" | |
2027 | "OSPF area ID in IP address format\n" | |
2028 | "OSPF area ID as a decimal value\n" | |
2029 | "Enable authentication\n") | |
2030 | { | |
a3d826f0 | 2031 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2032 | int idx_ipv4_number = 2; |
2033 | struct ospf_area *area; | |
2034 | struct in_addr area_id; | |
2035 | int format; | |
718e3744 | 2036 | |
d62a17ae | 2037 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
718e3744 | 2038 | |
d62a17ae | 2039 | area = ospf_area_lookup_by_area_id(ospf, area_id); |
2040 | if (area == NULL) | |
2041 | return CMD_SUCCESS; | |
718e3744 | 2042 | |
d62a17ae | 2043 | area->auth_type = OSPF_AUTH_NULL; |
718e3744 | 2044 | |
d62a17ae | 2045 | ospf_area_check_free(ospf, area_id); |
2046 | ||
2047 | return CMD_SUCCESS; | |
718e3744 | 2048 | } |
2049 | ||
6b0655a2 | 2050 | |
718e3744 | 2051 | DEFUN (ospf_abr_type, |
2052 | ospf_abr_type_cmd, | |
6147e2c6 | 2053 | "ospf abr-type <cisco|ibm|shortcut|standard>", |
718e3744 | 2054 | "OSPF specific commands\n" |
2055 | "Set OSPF ABR type\n" | |
2056 | "Alternative ABR, cisco implementation\n" | |
2057 | "Alternative ABR, IBM implementation\n" | |
2058 | "Shortcut ABR\n" | |
2059 | "Standard behavior (RFC2328)\n") | |
2060 | { | |
a3d826f0 | 2061 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2062 | int idx_vendor = 2; |
d7c0a89a | 2063 | uint8_t abr_type = OSPF_ABR_UNKNOWN; |
d62a17ae | 2064 | |
2065 | if (strncmp(argv[idx_vendor]->arg, "c", 1) == 0) | |
2066 | abr_type = OSPF_ABR_CISCO; | |
2067 | else if (strncmp(argv[idx_vendor]->arg, "i", 1) == 0) | |
2068 | abr_type = OSPF_ABR_IBM; | |
2069 | else if (strncmp(argv[idx_vendor]->arg, "sh", 2) == 0) | |
2070 | abr_type = OSPF_ABR_SHORTCUT; | |
2071 | else if (strncmp(argv[idx_vendor]->arg, "st", 2) == 0) | |
2072 | abr_type = OSPF_ABR_STAND; | |
2073 | else | |
2074 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 2075 | |
d62a17ae | 2076 | /* If ABR type value is changed, schedule ABR task. */ |
2077 | if (ospf->abr_type != abr_type) { | |
2078 | ospf->abr_type = abr_type; | |
2079 | ospf_schedule_abr_task(ospf); | |
2080 | } | |
2081 | ||
2082 | return CMD_SUCCESS; | |
718e3744 | 2083 | } |
2084 | ||
2085 | DEFUN (no_ospf_abr_type, | |
2086 | no_ospf_abr_type_cmd, | |
6147e2c6 | 2087 | "no ospf abr-type <cisco|ibm|shortcut|standard>", |
718e3744 | 2088 | NO_STR |
2089 | "OSPF specific commands\n" | |
2090 | "Set OSPF ABR type\n" | |
2091 | "Alternative ABR, cisco implementation\n" | |
2092 | "Alternative ABR, IBM implementation\n" | |
3a2d747c QY |
2093 | "Shortcut ABR\n" |
2094 | "Standard ABR\n") | |
718e3744 | 2095 | { |
a3d826f0 | 2096 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2097 | int idx_vendor = 3; |
d7c0a89a | 2098 | uint8_t abr_type = OSPF_ABR_UNKNOWN; |
d62a17ae | 2099 | |
2100 | if (strncmp(argv[idx_vendor]->arg, "c", 1) == 0) | |
2101 | abr_type = OSPF_ABR_CISCO; | |
2102 | else if (strncmp(argv[idx_vendor]->arg, "i", 1) == 0) | |
2103 | abr_type = OSPF_ABR_IBM; | |
2104 | else if (strncmp(argv[idx_vendor]->arg, "sh", 2) == 0) | |
2105 | abr_type = OSPF_ABR_SHORTCUT; | |
2106 | else if (strncmp(argv[idx_vendor]->arg, "st", 2) == 0) | |
2107 | abr_type = OSPF_ABR_STAND; | |
2108 | else | |
2109 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 2110 | |
d62a17ae | 2111 | /* If ABR type value is changed, schedule ABR task. */ |
2112 | if (ospf->abr_type == abr_type) { | |
2113 | ospf->abr_type = OSPF_ABR_DEFAULT; | |
2114 | ospf_schedule_abr_task(ospf); | |
2115 | } | |
2116 | ||
2117 | return CMD_SUCCESS; | |
718e3744 | 2118 | } |
2119 | ||
d7e60dd7 AS |
2120 | DEFUN (ospf_log_adjacency_changes, |
2121 | ospf_log_adjacency_changes_cmd, | |
2122 | "log-adjacency-changes", | |
2123 | "Log changes in adjacency state\n") | |
2124 | { | |
a3d826f0 | 2125 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d7e60dd7 | 2126 | |
d62a17ae | 2127 | SET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES); |
2128 | UNSET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL); | |
2129 | return CMD_SUCCESS; | |
d7e60dd7 AS |
2130 | } |
2131 | ||
2132 | DEFUN (ospf_log_adjacency_changes_detail, | |
2133 | ospf_log_adjacency_changes_detail_cmd, | |
2134 | "log-adjacency-changes detail", | |
2135 | "Log changes in adjacency state\n" | |
2136 | "Log all state changes\n") | |
2137 | { | |
a3d826f0 | 2138 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d7e60dd7 | 2139 | |
d62a17ae | 2140 | SET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES); |
2141 | SET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL); | |
2142 | return CMD_SUCCESS; | |
d7e60dd7 AS |
2143 | } |
2144 | ||
2145 | DEFUN (no_ospf_log_adjacency_changes, | |
2146 | no_ospf_log_adjacency_changes_cmd, | |
2147 | "no log-adjacency-changes", | |
2148 | NO_STR | |
2149 | "Log changes in adjacency state\n") | |
2150 | { | |
a3d826f0 | 2151 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d7e60dd7 | 2152 | |
d62a17ae | 2153 | UNSET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL); |
2154 | UNSET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES); | |
2155 | return CMD_SUCCESS; | |
d7e60dd7 AS |
2156 | } |
2157 | ||
2158 | DEFUN (no_ospf_log_adjacency_changes_detail, | |
2159 | no_ospf_log_adjacency_changes_detail_cmd, | |
2160 | "no log-adjacency-changes detail", | |
2161 | NO_STR | |
2162 | "Log changes in adjacency state\n" | |
2163 | "Log all state changes\n") | |
2164 | { | |
a3d826f0 | 2165 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d7e60dd7 | 2166 | |
d62a17ae | 2167 | UNSET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL); |
2168 | return CMD_SUCCESS; | |
d7e60dd7 AS |
2169 | } |
2170 | ||
718e3744 | 2171 | DEFUN (ospf_compatible_rfc1583, |
2172 | ospf_compatible_rfc1583_cmd, | |
2173 | "compatible rfc1583", | |
2174 | "OSPF compatibility list\n" | |
2175 | "compatible with RFC 1583\n") | |
2176 | { | |
a3d826f0 | 2177 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
718e3744 | 2178 | |
d62a17ae | 2179 | if (!CHECK_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE)) { |
2180 | SET_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE); | |
2181 | ospf_spf_calculate_schedule(ospf, SPF_FLAG_CONFIG_CHANGE); | |
2182 | } | |
2183 | return CMD_SUCCESS; | |
718e3744 | 2184 | } |
2185 | ||
2186 | DEFUN (no_ospf_compatible_rfc1583, | |
2187 | no_ospf_compatible_rfc1583_cmd, | |
2188 | "no compatible rfc1583", | |
2189 | NO_STR | |
2190 | "OSPF compatibility list\n" | |
2191 | "compatible with RFC 1583\n") | |
2192 | { | |
a3d826f0 | 2193 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
718e3744 | 2194 | |
d62a17ae | 2195 | if (CHECK_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE)) { |
2196 | UNSET_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE); | |
2197 | ospf_spf_calculate_schedule(ospf, SPF_FLAG_CONFIG_CHANGE); | |
2198 | } | |
2199 | return CMD_SUCCESS; | |
718e3744 | 2200 | } |
2201 | ||
d62a17ae | 2202 | ALIAS(ospf_compatible_rfc1583, ospf_rfc1583_flag_cmd, |
2203 | "ospf rfc1583compatibility", | |
2204 | "OSPF specific commands\n" | |
2205 | "Enable the RFC1583Compatibility flag\n") | |
718e3744 | 2206 | |
d62a17ae | 2207 | ALIAS(no_ospf_compatible_rfc1583, no_ospf_rfc1583_flag_cmd, |
9d303b37 | 2208 | "no ospf rfc1583compatibility", NO_STR |
d62a17ae | 2209 | "OSPF specific commands\n" |
2210 | "Disable the RFC1583Compatibility flag\n") | |
6b0655a2 | 2211 | |
d62a17ae | 2212 | static int ospf_timers_spf_set(struct vty *vty, unsigned int delay, |
2213 | unsigned int hold, unsigned int max) | |
d24f6e2a | 2214 | { |
a3d826f0 | 2215 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
7c8ff89e | 2216 | |
d62a17ae | 2217 | ospf->spf_delay = delay; |
2218 | ospf->spf_holdtime = hold; | |
2219 | ospf->spf_max_holdtime = max; | |
2220 | ||
2221 | return CMD_SUCCESS; | |
d24f6e2a | 2222 | } |
718e3744 | 2223 | |
ac7424f9 MR |
2224 | DEFUN (ospf_timers_min_ls_interval, |
2225 | ospf_timers_min_ls_interval_cmd, | |
6147e2c6 | 2226 | "timers throttle lsa all (0-5000)", |
ac7424f9 MR |
2227 | "Adjust routing timers\n" |
2228 | "Throttling adaptive timer\n" | |
2229 | "LSA delay between transmissions\n" | |
813d4307 | 2230 | "All LSA types\n" |
ac7424f9 MR |
2231 | "Delay (msec) between sending LSAs\n") |
2232 | { | |
a3d826f0 | 2233 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2234 | int idx_number = 4; |
2235 | unsigned int interval; | |
ac7424f9 | 2236 | |
d62a17ae | 2237 | if (argc < 5) { |
2238 | vty_out(vty, "Insufficient arguments\n"); | |
2239 | return CMD_WARNING_CONFIG_FAILED; | |
2240 | } | |
ac7424f9 | 2241 | |
d62a17ae | 2242 | interval = strtoul(argv[idx_number]->arg, NULL, 10); |
ac7424f9 | 2243 | |
d62a17ae | 2244 | ospf->min_ls_interval = interval; |
ac7424f9 | 2245 | |
d62a17ae | 2246 | return CMD_SUCCESS; |
ac7424f9 MR |
2247 | } |
2248 | ||
2249 | DEFUN (no_ospf_timers_min_ls_interval, | |
2250 | no_ospf_timers_min_ls_interval_cmd, | |
7a7be519 | 2251 | "no timers throttle lsa all [(0-5000)]", |
ac7424f9 MR |
2252 | NO_STR |
2253 | "Adjust routing timers\n" | |
2254 | "Throttling adaptive timer\n" | |
813d4307 | 2255 | "LSA delay between transmissions\n" |
7a7be519 | 2256 | "All LSA types\n" |
2257 | "Delay (msec) between sending LSAs\n") | |
ac7424f9 | 2258 | { |
a3d826f0 | 2259 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2260 | ospf->min_ls_interval = OSPF_MIN_LS_INTERVAL; |
ac7424f9 | 2261 | |
d62a17ae | 2262 | return CMD_SUCCESS; |
ac7424f9 MR |
2263 | } |
2264 | ||
d24f6e2a | 2265 | DEFUN (ospf_timers_throttle_spf, |
2266 | ospf_timers_throttle_spf_cmd, | |
6147e2c6 | 2267 | "timers throttle spf (0-600000) (0-600000) (0-600000)", |
d24f6e2a | 2268 | "Adjust routing timers\n" |
2269 | "Throttling adaptive timer\n" | |
2270 | "OSPF SPF timers\n" | |
2271 | "Delay (msec) from first change received till SPF calculation\n" | |
2272 | "Initial hold time (msec) between consecutive SPF calculations\n" | |
2273 | "Maximum hold time (msec)\n") | |
2274 | { | |
d62a17ae | 2275 | int idx_number = 3; |
2276 | int idx_number_2 = 4; | |
2277 | int idx_number_3 = 5; | |
2278 | unsigned int delay, hold, max; | |
2279 | ||
2280 | if (argc < 6) { | |
2281 | vty_out(vty, "Insufficient arguments\n"); | |
2282 | return CMD_WARNING_CONFIG_FAILED; | |
2283 | } | |
2284 | ||
2285 | delay = strtoul(argv[idx_number]->arg, NULL, 10); | |
2286 | hold = strtoul(argv[idx_number_2]->arg, NULL, 10); | |
2287 | max = strtoul(argv[idx_number_3]->arg, NULL, 10); | |
2288 | ||
2289 | return ospf_timers_spf_set(vty, delay, hold, max); | |
d24f6e2a | 2290 | } |
2291 | ||
d24f6e2a | 2292 | DEFUN (no_ospf_timers_throttle_spf, |
2293 | no_ospf_timers_throttle_spf_cmd, | |
7a7be519 | 2294 | "no timers throttle spf [(0-600000)(0-600000)(0-600000)]", |
718e3744 | 2295 | NO_STR |
2296 | "Adjust routing timers\n" | |
d24f6e2a | 2297 | "Throttling adaptive timer\n" |
7a7be519 | 2298 | "OSPF SPF timers\n" |
2299 | "Delay (msec) from first change received till SPF calculation\n" | |
2300 | "Initial hold time (msec) between consecutive SPF calculations\n" | |
2301 | "Maximum hold time (msec)\n") | |
22b27e95 | 2302 | { |
d62a17ae | 2303 | return ospf_timers_spf_set(vty, OSPF_SPF_DELAY_DEFAULT, |
2304 | OSPF_SPF_HOLDTIME_DEFAULT, | |
2305 | OSPF_SPF_MAX_HOLDTIME_DEFAULT); | |
718e3744 | 2306 | } |
2307 | ||
b4a039bf | 2308 | |
0e88de35 QY |
2309 | DEFUN (ospf_timers_lsa_min_arrival, |
2310 | ospf_timers_lsa_min_arrival_cmd, | |
6147e2c6 | 2311 | "timers lsa min-arrival (0-600000)", |
b6927875 DS |
2312 | "Adjust routing timers\n" |
2313 | "OSPF LSA timers\n" | |
2314 | "Minimum delay in receiving new version of a LSA\n" | |
2315 | "Delay in milliseconds\n") | |
2316 | { | |
a3d826f0 | 2317 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
0e88de35 | 2318 | ospf->min_ls_arrival = strtoul(argv[argc - 1]->arg, NULL, 10); |
d62a17ae | 2319 | return CMD_SUCCESS; |
b6927875 DS |
2320 | } |
2321 | ||
0e88de35 QY |
2322 | DEFUN (no_ospf_timers_lsa_min_arrival, |
2323 | no_ospf_timers_lsa_min_arrival_cmd, | |
7a7be519 | 2324 | "no timers lsa min-arrival [(0-600000)]", |
b6927875 DS |
2325 | NO_STR |
2326 | "Adjust routing timers\n" | |
2327 | "OSPF LSA timers\n" | |
7a7be519 | 2328 | "Minimum delay in receiving new version of a LSA\n" |
2329 | "Delay in milliseconds\n") | |
b6927875 | 2330 | { |
a3d826f0 | 2331 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2332 | unsigned int minarrival; |
b6927875 | 2333 | |
d62a17ae | 2334 | if (argc > 4) { |
0e88de35 | 2335 | minarrival = strtoul(argv[argc - 1]->arg, NULL, 10); |
b6927875 | 2336 | |
d62a17ae | 2337 | if (ospf->min_ls_arrival != minarrival |
2338 | || minarrival == OSPF_MIN_LS_ARRIVAL) | |
2339 | return CMD_SUCCESS; | |
2340 | } | |
b6927875 | 2341 | |
d62a17ae | 2342 | ospf->min_ls_arrival = OSPF_MIN_LS_ARRIVAL; |
b6927875 | 2343 | |
d62a17ae | 2344 | return CMD_SUCCESS; |
b6927875 DS |
2345 | } |
2346 | ||
a2c62831 | 2347 | DEFUN (ospf_neighbor, |
2348 | ospf_neighbor_cmd, | |
7a7be519 | 2349 | "neighbor A.B.C.D [priority (0-255) [poll-interval (1-65535)]]", |
718e3744 | 2350 | NEIGHBOR_STR |
7a7be519 | 2351 | "Neighbor IP address\n" |
2352 | "Neighbor Priority\n" | |
2353 | "Priority\n" | |
2354 | "Dead Neighbor Polling interval\n" | |
2355 | "Seconds\n") | |
718e3744 | 2356 | { |
a3d826f0 | 2357 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2358 | int idx_ipv4 = 1; |
2359 | int idx_pri = 3; | |
2360 | int idx_poll = 5; | |
2361 | struct in_addr nbr_addr; | |
2362 | unsigned int priority = OSPF_NEIGHBOR_PRIORITY_DEFAULT; | |
2363 | unsigned int interval = OSPF_POLL_INTERVAL_DEFAULT; | |
718e3744 | 2364 | |
cc9b06ad DS |
2365 | if (!inet_aton(argv[idx_ipv4]->arg, &nbr_addr)) { |
2366 | vty_out(vty, "Please specify Neighbor ID by A.B.C.D\n"); | |
2367 | return CMD_WARNING_CONFIG_FAILED; | |
2368 | } | |
718e3744 | 2369 | |
d62a17ae | 2370 | if (argc > 2) |
2371 | priority = strtoul(argv[idx_pri]->arg, NULL, 10); | |
7a7be519 | 2372 | |
d62a17ae | 2373 | if (argc > 4) |
2374 | interval = strtoul(argv[idx_poll]->arg, NULL, 10); | |
718e3744 | 2375 | |
d62a17ae | 2376 | ospf_nbr_nbma_set(ospf, nbr_addr); |
7a7be519 | 2377 | |
d62a17ae | 2378 | if (argc > 2) |
2379 | ospf_nbr_nbma_priority_set(ospf, nbr_addr, priority); | |
7a7be519 | 2380 | |
d62a17ae | 2381 | if (argc > 4) |
2382 | ospf_nbr_nbma_poll_interval_set(ospf, nbr_addr, interval); | |
718e3744 | 2383 | |
d62a17ae | 2384 | return CMD_SUCCESS; |
718e3744 | 2385 | } |
2386 | ||
a2c62831 | 2387 | DEFUN (ospf_neighbor_poll_interval, |
2388 | ospf_neighbor_poll_interval_cmd, | |
7a7be519 | 2389 | "neighbor A.B.C.D poll-interval (1-65535) [priority (0-255)]", |
718e3744 | 2390 | NEIGHBOR_STR |
2391 | "Neighbor IP address\n" | |
2392 | "Dead Neighbor Polling interval\n" | |
7a7be519 | 2393 | "Seconds\n" |
2394 | "OSPF priority of non-broadcast neighbor\n" | |
2395 | "Priority\n") | |
22b27e95 | 2396 | { |
a3d826f0 | 2397 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2398 | int idx_ipv4 = 1; |
2399 | int idx_poll = 3; | |
2400 | int idx_pri = 5; | |
2401 | struct in_addr nbr_addr; | |
a2b6e694 | 2402 | unsigned int priority; |
2403 | unsigned int interval; | |
718e3744 | 2404 | |
cc9b06ad DS |
2405 | if (!inet_aton(argv[idx_ipv4]->arg, &nbr_addr)) { |
2406 | vty_out(vty, "Please specify Neighbor ID by A.B.C.D\n"); | |
2407 | return CMD_WARNING_CONFIG_FAILED; | |
2408 | } | |
718e3744 | 2409 | |
d62a17ae | 2410 | interval = strtoul(argv[idx_poll]->arg, NULL, 10); |
718e3744 | 2411 | |
a2b6e694 | 2412 | priority = argc > 4 ? strtoul(argv[idx_pri]->arg, NULL, 10) |
2413 | : OSPF_NEIGHBOR_PRIORITY_DEFAULT; | |
718e3744 | 2414 | |
d62a17ae | 2415 | ospf_nbr_nbma_set(ospf, nbr_addr); |
2416 | ospf_nbr_nbma_poll_interval_set(ospf, nbr_addr, interval); | |
7a7be519 | 2417 | |
d62a17ae | 2418 | if (argc > 4) |
2419 | ospf_nbr_nbma_priority_set(ospf, nbr_addr, priority); | |
718e3744 | 2420 | |
d62a17ae | 2421 | return CMD_SUCCESS; |
718e3744 | 2422 | } |
2423 | ||
a2c62831 | 2424 | DEFUN (no_ospf_neighbor, |
2425 | no_ospf_neighbor_cmd, | |
7a7be519 | 2426 | "no neighbor A.B.C.D [priority (0-255) [poll-interval (1-65525)]]", |
718e3744 | 2427 | NO_STR |
2428 | NEIGHBOR_STR | |
7a7be519 | 2429 | "Neighbor IP address\n" |
2430 | "Neighbor Priority\n" | |
2431 | "Priority\n" | |
2432 | "Dead Neighbor Polling interval\n" | |
2433 | "Seconds\n") | |
718e3744 | 2434 | { |
a3d826f0 | 2435 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2436 | int idx_ipv4 = 2; |
2437 | struct in_addr nbr_addr; | |
718e3744 | 2438 | |
cc9b06ad DS |
2439 | if (!inet_aton(argv[idx_ipv4]->arg, &nbr_addr)) { |
2440 | vty_out(vty, "Please specify Neighbor ID by A.B.C.D\n"); | |
2441 | return CMD_WARNING_CONFIG_FAILED; | |
2442 | } | |
718e3744 | 2443 | |
d62a17ae | 2444 | (void)ospf_nbr_nbma_unset(ospf, nbr_addr); |
718e3744 | 2445 | |
d62a17ae | 2446 | return CMD_SUCCESS; |
718e3744 | 2447 | } |
2448 | ||
7a7be519 | 2449 | DEFUN (no_ospf_neighbor_poll, |
2450 | no_ospf_neighbor_poll_cmd, | |
2451 | "no neighbor A.B.C.D poll-interval (1-65535) [priority (0-255)]", | |
2452 | NO_STR | |
2453 | NEIGHBOR_STR | |
2454 | "Neighbor IP address\n" | |
2455 | "Dead Neighbor Polling interval\n" | |
2456 | "Seconds\n" | |
2457 | "Neighbor Priority\n" | |
2458 | "Priority\n") | |
2459 | { | |
a3d826f0 | 2460 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2461 | int idx_ipv4 = 2; |
2462 | struct in_addr nbr_addr; | |
7a7be519 | 2463 | |
cc9b06ad DS |
2464 | if (!inet_aton(argv[idx_ipv4]->arg, &nbr_addr)) { |
2465 | vty_out(vty, "Please specify Neighbor ID by A.B.C.D\n"); | |
2466 | return CMD_WARNING_CONFIG_FAILED; | |
2467 | } | |
718e3744 | 2468 | |
d62a17ae | 2469 | (void)ospf_nbr_nbma_unset(ospf, nbr_addr); |
813d4307 | 2470 | |
d62a17ae | 2471 | return CMD_SUCCESS; |
7a7be519 | 2472 | } |
718e3744 | 2473 | |
bf2bfafd DW |
2474 | DEFUN (ospf_refresh_timer, |
2475 | ospf_refresh_timer_cmd, | |
6147e2c6 | 2476 | "refresh timer (10-1800)", |
718e3744 | 2477 | "Adjust refresh parameters\n" |
2478 | "Set refresh timer\n" | |
2479 | "Timer value in seconds\n") | |
2480 | { | |
a3d826f0 | 2481 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2482 | int idx_number = 2; |
2483 | unsigned int interval; | |
7c8ff89e | 2484 | |
d62a17ae | 2485 | interval = strtoul(argv[idx_number]->arg, NULL, 10); |
2486 | interval = (interval / OSPF_LSA_REFRESHER_GRANULARITY) | |
2487 | * OSPF_LSA_REFRESHER_GRANULARITY; | |
718e3744 | 2488 | |
d62a17ae | 2489 | ospf_timers_refresh_set(ospf, interval); |
718e3744 | 2490 | |
d62a17ae | 2491 | return CMD_SUCCESS; |
718e3744 | 2492 | } |
2493 | ||
bf2bfafd DW |
2494 | DEFUN (no_ospf_refresh_timer, |
2495 | no_ospf_refresh_timer_val_cmd, | |
7a7be519 | 2496 | "no refresh timer [(10-1800)]", |
3a2d747c | 2497 | NO_STR |
718e3744 | 2498 | "Adjust refresh parameters\n" |
2499 | "Unset refresh timer\n" | |
2500 | "Timer value in seconds\n") | |
2501 | { | |
a3d826f0 | 2502 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2503 | int idx_number = 3; |
2504 | unsigned int interval; | |
718e3744 | 2505 | |
d62a17ae | 2506 | if (argc == 1) { |
2507 | interval = strtoul(argv[idx_number]->arg, NULL, 10); | |
718e3744 | 2508 | |
d62a17ae | 2509 | if (ospf->lsa_refresh_interval != interval |
2510 | || interval == OSPF_LSA_REFRESH_INTERVAL_DEFAULT) | |
2511 | return CMD_SUCCESS; | |
2512 | } | |
2513 | ||
2514 | ospf_timers_refresh_unset(ospf); | |
2515 | ||
2516 | return CMD_SUCCESS; | |
718e3744 | 2517 | } |
2518 | ||
718e3744 | 2519 | |
a2c62831 | 2520 | DEFUN (ospf_auto_cost_reference_bandwidth, |
2521 | ospf_auto_cost_reference_bandwidth_cmd, | |
6147e2c6 | 2522 | "auto-cost reference-bandwidth (1-4294967)", |
718e3744 | 2523 | "Calculate OSPF interface cost according to bandwidth\n" |
2524 | "Use reference bandwidth method to assign OSPF cost\n" | |
2525 | "The reference bandwidth in terms of Mbits per second\n") | |
2526 | { | |
a3d826f0 | 2527 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
f4e14fdb | 2528 | struct vrf *vrf = vrf_lookup_by_id(ospf->vrf_id); |
d62a17ae | 2529 | int idx_number = 2; |
d7c0a89a | 2530 | uint32_t refbw; |
d62a17ae | 2531 | struct interface *ifp; |
2532 | ||
2533 | refbw = strtol(argv[idx_number]->arg, NULL, 10); | |
2534 | if (refbw < 1 || refbw > 4294967) { | |
2535 | vty_out(vty, "reference-bandwidth value is invalid\n"); | |
2536 | return CMD_WARNING_CONFIG_FAILED; | |
2537 | } | |
2538 | ||
2539 | /* If reference bandwidth is changed. */ | |
2540 | if ((refbw) == ospf->ref_bandwidth) | |
2541 | return CMD_SUCCESS; | |
2542 | ||
2543 | ospf->ref_bandwidth = refbw; | |
451fda4f | 2544 | FOR_ALL_INTERFACES (vrf, ifp) |
d62a17ae | 2545 | ospf_if_recalculate_output_cost(ifp); |
2546 | ||
2547 | return CMD_SUCCESS; | |
718e3744 | 2548 | } |
2549 | ||
a2c62831 | 2550 | DEFUN (no_ospf_auto_cost_reference_bandwidth, |
2551 | no_ospf_auto_cost_reference_bandwidth_cmd, | |
7a7be519 | 2552 | "no auto-cost reference-bandwidth [(1-4294967)]", |
718e3744 | 2553 | NO_STR |
2554 | "Calculate OSPF interface cost according to bandwidth\n" | |
7a7be519 | 2555 | "Use reference bandwidth method to assign OSPF cost\n" |
2556 | "The reference bandwidth in terms of Mbits per second\n") | |
718e3744 | 2557 | { |
a3d826f0 | 2558 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
f4e14fdb | 2559 | struct vrf *vrf = vrf_lookup_by_id(ospf->vrf_id); |
d62a17ae | 2560 | struct interface *ifp; |
718e3744 | 2561 | |
d62a17ae | 2562 | if (ospf->ref_bandwidth == OSPF_DEFAULT_REF_BANDWIDTH) |
2563 | return CMD_SUCCESS; | |
2564 | ||
2565 | ospf->ref_bandwidth = OSPF_DEFAULT_REF_BANDWIDTH; | |
2566 | vty_out(vty, "%% OSPF: Reference bandwidth is changed.\n"); | |
2567 | vty_out(vty, | |
2568 | " Please ensure reference bandwidth is consistent across all routers\n"); | |
2569 | ||
451fda4f | 2570 | FOR_ALL_INTERFACES (vrf, ifp) |
d62a17ae | 2571 | ospf_if_recalculate_output_cost(ifp); |
2572 | ||
2573 | return CMD_SUCCESS; | |
718e3744 | 2574 | } |
2575 | ||
2f8f370e DS |
2576 | DEFUN (ospf_write_multiplier, |
2577 | ospf_write_multiplier_cmd, | |
6147e2c6 | 2578 | "ospf write-multiplier (1-100)", |
e8f45e82 DS |
2579 | "OSPF specific commands\n" |
2580 | "Write multiplier\n" | |
2581 | "Maximum number of interface serviced per write\n") | |
2f8f370e | 2582 | { |
a3d826f0 | 2583 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2584 | int idx_number; |
d7c0a89a | 2585 | uint32_t write_oi_count; |
d62a17ae | 2586 | |
2587 | if (argc == 3) | |
2588 | idx_number = 2; | |
2589 | else | |
2590 | idx_number = 1; | |
2591 | ||
2592 | write_oi_count = strtol(argv[idx_number]->arg, NULL, 10); | |
2593 | if (write_oi_count < 1 || write_oi_count > 100) { | |
2594 | vty_out(vty, "write-multiplier value is invalid\n"); | |
2595 | return CMD_WARNING_CONFIG_FAILED; | |
2596 | } | |
2597 | ||
2598 | ospf->write_oi_count = write_oi_count; | |
2599 | return CMD_SUCCESS; | |
2f8f370e DS |
2600 | } |
2601 | ||
d62a17ae | 2602 | ALIAS(ospf_write_multiplier, write_multiplier_cmd, "write-multiplier (1-100)", |
2603 | "Write multiplier\n" | |
2604 | "Maximum number of interface serviced per write\n") | |
e8f45e82 | 2605 | |
2f8f370e DS |
2606 | DEFUN (no_ospf_write_multiplier, |
2607 | no_ospf_write_multiplier_cmd, | |
6147e2c6 | 2608 | "no ospf write-multiplier (1-100)", |
2f8f370e | 2609 | NO_STR |
e8f45e82 | 2610 | "OSPF specific commands\n" |
813d4307 DW |
2611 | "Write multiplier\n" |
2612 | "Maximum number of interface serviced per write\n") | |
2f8f370e | 2613 | { |
a3d826f0 | 2614 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
2f8f370e | 2615 | |
d62a17ae | 2616 | ospf->write_oi_count = OSPF_WRITE_INTERFACE_COUNT_DEFAULT; |
2617 | return CMD_SUCCESS; | |
2f8f370e DS |
2618 | } |
2619 | ||
d62a17ae | 2620 | ALIAS(no_ospf_write_multiplier, no_write_multiplier_cmd, |
9d303b37 | 2621 | "no write-multiplier (1-100)", NO_STR |
d62a17ae | 2622 | "Write multiplier\n" |
2623 | "Maximum number of interface serviced per write\n") | |
2624 | ||
2625 | const char *ospf_abr_type_descr_str[] = {"Unknown", "Standard (RFC2328)", | |
2626 | "Alternative IBM", "Alternative Cisco", | |
2627 | "Alternative Shortcut"}; | |
2628 | ||
2629 | const char *ospf_shortcut_mode_descr_str[] = {"Default", "Enabled", "Disabled"}; | |
2630 | ||
2631 | static void show_ip_ospf_area(struct vty *vty, struct ospf_area *area, | |
9f049418 | 2632 | json_object *json_areas, bool use_json) |
d62a17ae | 2633 | { |
2634 | json_object *json_area = NULL; | |
2635 | ||
2636 | if (use_json) | |
2637 | json_area = json_object_new_object(); | |
2638 | ||
2639 | /* Show Area ID. */ | |
2640 | if (!use_json) | |
2641 | vty_out(vty, " Area ID: %s", inet_ntoa(area->area_id)); | |
2642 | ||
2643 | /* Show Area type/mode. */ | |
2644 | if (OSPF_IS_AREA_BACKBONE(area)) { | |
2645 | if (use_json) | |
2646 | json_object_boolean_true_add(json_area, "backbone"); | |
2647 | else | |
2648 | vty_out(vty, " (Backbone)\n"); | |
2649 | } else { | |
2650 | if (use_json) { | |
2651 | if (area->external_routing == OSPF_AREA_STUB) { | |
2652 | if (area->no_summary) | |
2653 | json_object_boolean_true_add( | |
2654 | json_area, "stubNoSummary"); | |
2655 | if (area->shortcut_configured) | |
2656 | json_object_boolean_true_add( | |
2657 | json_area, "stubShortcut"); | |
2658 | } else if (area->external_routing == OSPF_AREA_NSSA) { | |
2659 | if (area->no_summary) | |
2660 | json_object_boolean_true_add( | |
2661 | json_area, "nssaNoSummary"); | |
2662 | if (area->shortcut_configured) | |
2663 | json_object_boolean_true_add( | |
2664 | json_area, "nssaShortcut"); | |
2665 | } | |
813d4307 | 2666 | |
d62a17ae | 2667 | json_object_string_add( |
2668 | json_area, "shortcuttingMode", | |
2669 | ospf_shortcut_mode_descr_str | |
2670 | [area->shortcut_configured]); | |
2671 | if (area->shortcut_capability) | |
2672 | json_object_boolean_true_add(json_area, | |
2673 | "sBitConcensus"); | |
2674 | } else { | |
2675 | if (area->external_routing == OSPF_AREA_STUB) | |
2676 | vty_out(vty, " (Stub%s%s)", | |
2677 | area->no_summary ? ", no summary" : "", | |
2678 | area->shortcut_configured ? "; " : ""); | |
2679 | else if (area->external_routing == OSPF_AREA_NSSA) | |
2680 | vty_out(vty, " (NSSA%s%s)", | |
2681 | area->no_summary ? ", no summary" : "", | |
2682 | area->shortcut_configured ? "; " : ""); | |
2683 | ||
2684 | vty_out(vty, "\n"); | |
2685 | vty_out(vty, " Shortcutting mode: %s", | |
2686 | ospf_shortcut_mode_descr_str | |
2687 | [area->shortcut_configured]); | |
2688 | vty_out(vty, ", S-bit consensus: %s\n", | |
2689 | area->shortcut_capability ? "ok" : "no"); | |
2690 | } | |
2691 | } | |
718e3744 | 2692 | |
d62a17ae | 2693 | /* Show number of interfaces */ |
2694 | if (use_json) { | |
2695 | json_object_int_add(json_area, "areaIfTotalCounter", | |
2696 | listcount(area->oiflist)); | |
2697 | json_object_int_add(json_area, "areaIfActiveCounter", | |
2698 | area->act_ints); | |
2699 | } else | |
2700 | vty_out(vty, | |
2701 | " Number of interfaces in this area: Total: %d, " | |
2702 | "Active: %d\n", | |
2703 | listcount(area->oiflist), area->act_ints); | |
2704 | ||
2705 | if (area->external_routing == OSPF_AREA_NSSA) { | |
2706 | if (use_json) { | |
2707 | json_object_boolean_true_add(json_area, "nssa"); | |
2708 | if (!IS_OSPF_ABR(area->ospf)) | |
2709 | json_object_boolean_false_add(json_area, "abr"); | |
2710 | else if (area->NSSATranslatorState) { | |
2711 | json_object_boolean_true_add(json_area, "abr"); | |
2712 | if (area->NSSATranslatorRole | |
2713 | == OSPF_NSSA_ROLE_CANDIDATE) | |
2714 | json_object_boolean_true_add( | |
2715 | json_area, | |
2716 | "nssaTranslatorElected"); | |
2717 | else if (area->NSSATranslatorRole | |
2718 | == OSPF_NSSA_ROLE_ALWAYS) | |
2719 | json_object_boolean_true_add( | |
2720 | json_area, | |
2721 | "nssaTranslatorAlways"); | |
2722 | } else { | |
2723 | json_object_boolean_true_add(json_area, "abr"); | |
2724 | if (area->NSSATranslatorRole | |
2725 | == OSPF_NSSA_ROLE_CANDIDATE) | |
2726 | json_object_boolean_false_add( | |
2727 | json_area, | |
2728 | "nssaTranslatorElected"); | |
2729 | else | |
2730 | json_object_boolean_true_add( | |
2731 | json_area, | |
2732 | "nssaTranslatorNever"); | |
2733 | } | |
2734 | } else { | |
2735 | vty_out(vty, | |
2736 | " It is an NSSA configuration. \n Elected NSSA/ABR performs type-7/type-5 LSA translation. \n"); | |
2737 | if (!IS_OSPF_ABR(area->ospf)) | |
2738 | vty_out(vty, | |
2739 | " It is not ABR, therefore not Translator. \n"); | |
2740 | else if (area->NSSATranslatorState) { | |
2741 | vty_out(vty, " We are an ABR and "); | |
2742 | if (area->NSSATranslatorRole | |
2743 | == OSPF_NSSA_ROLE_CANDIDATE) | |
2744 | vty_out(vty, | |
2745 | "the NSSA Elected Translator. \n"); | |
2746 | else if (area->NSSATranslatorRole | |
2747 | == OSPF_NSSA_ROLE_ALWAYS) | |
2748 | vty_out(vty, | |
2749 | "always an NSSA Translator. \n"); | |
2750 | } else { | |
2751 | vty_out(vty, " We are an ABR, but "); | |
2752 | if (area->NSSATranslatorRole | |
2753 | == OSPF_NSSA_ROLE_CANDIDATE) | |
2754 | vty_out(vty, | |
2755 | "not the NSSA Elected Translator. \n"); | |
2756 | else | |
2757 | vty_out(vty, | |
2758 | "never an NSSA Translator. \n"); | |
2759 | } | |
2760 | } | |
2761 | } | |
2762 | ||
2763 | /* Stub-router state for this area */ | |
2764 | if (CHECK_FLAG(area->stub_router_state, OSPF_AREA_IS_STUB_ROUTED)) { | |
2765 | char timebuf[OSPF_TIME_DUMP_SIZE]; | |
2766 | ||
2767 | if (use_json) { | |
2768 | json_object_boolean_true_add( | |
2769 | json_area, "originStubMaxDistRouterLsa"); | |
2770 | if (CHECK_FLAG(area->stub_router_state, | |
2771 | OSPF_AREA_ADMIN_STUB_ROUTED)) | |
2772 | json_object_boolean_true_add( | |
2773 | json_area, "indefiniteActiveAdmin"); | |
2774 | if (area->t_stub_router) { | |
2775 | long time_store; | |
2776 | time_store = | |
2777 | monotime_until( | |
2778 | &area->t_stub_router->u.sands, | |
2779 | NULL) | |
2780 | / 1000LL; | |
2781 | json_object_int_add( | |
2782 | json_area, | |
2783 | "activeStartupRemainderMsecs", | |
2784 | time_store); | |
2785 | } | |
2786 | } else { | |
2787 | vty_out(vty, | |
2788 | " Originating stub / maximum-distance Router-LSA\n"); | |
2789 | if (CHECK_FLAG(area->stub_router_state, | |
2790 | OSPF_AREA_ADMIN_STUB_ROUTED)) | |
2791 | vty_out(vty, | |
2792 | " Administratively activated (indefinitely)\n"); | |
2793 | if (area->t_stub_router) | |
2794 | vty_out(vty, | |
2795 | " Active from startup, %s remaining\n", | |
2796 | ospf_timer_dump(area->t_stub_router, | |
2797 | timebuf, | |
2798 | sizeof(timebuf))); | |
2799 | } | |
2800 | } | |
2801 | ||
2802 | if (use_json) { | |
2803 | /* Show number of fully adjacent neighbors. */ | |
2804 | json_object_int_add(json_area, "nbrFullAdjacentCounter", | |
2805 | area->full_nbrs); | |
2806 | ||
2807 | /* Show authentication type. */ | |
2808 | if (area->auth_type == OSPF_AUTH_NULL) | |
2809 | json_object_string_add(json_area, "authentication", | |
2810 | "authenticationNone"); | |
2811 | else if (area->auth_type == OSPF_AUTH_SIMPLE) | |
2812 | json_object_string_add(json_area, "authentication", | |
2813 | "authenticationSimplePassword"); | |
2814 | else if (area->auth_type == OSPF_AUTH_CRYPTOGRAPHIC) | |
2815 | json_object_string_add(json_area, "authentication", | |
2816 | "authenticationMessageDigest"); | |
2817 | ||
2818 | if (!OSPF_IS_AREA_BACKBONE(area)) | |
2819 | json_object_int_add(json_area, | |
2820 | "virtualAdjacenciesPassingCounter", | |
2821 | area->full_vls); | |
2822 | ||
2823 | /* Show SPF calculation times. */ | |
2824 | json_object_int_add(json_area, "spfExecutedCounter", | |
2825 | area->spf_calculation); | |
2826 | json_object_int_add(json_area, "lsaNumber", area->lsdb->total); | |
2827 | json_object_int_add( | |
2828 | json_area, "lsaRouterNumber", | |
2829 | ospf_lsdb_count(area->lsdb, OSPF_ROUTER_LSA)); | |
2830 | json_object_int_add( | |
2831 | json_area, "lsaRouterChecksum", | |
2832 | ospf_lsdb_checksum(area->lsdb, OSPF_ROUTER_LSA)); | |
2833 | json_object_int_add( | |
2834 | json_area, "lsaNetworkNumber", | |
2835 | ospf_lsdb_count(area->lsdb, OSPF_NETWORK_LSA)); | |
2836 | json_object_int_add( | |
2837 | json_area, "lsaNetworkChecksum", | |
2838 | ospf_lsdb_checksum(area->lsdb, OSPF_NETWORK_LSA)); | |
2839 | json_object_int_add( | |
2840 | json_area, "lsaSummaryNumber", | |
2841 | ospf_lsdb_count(area->lsdb, OSPF_SUMMARY_LSA)); | |
2842 | json_object_int_add( | |
2843 | json_area, "lsaSummaryChecksum", | |
2844 | ospf_lsdb_checksum(area->lsdb, OSPF_SUMMARY_LSA)); | |
2845 | json_object_int_add( | |
2846 | json_area, "lsaAsbrNumber", | |
2847 | ospf_lsdb_count(area->lsdb, OSPF_ASBR_SUMMARY_LSA)); | |
2848 | json_object_int_add( | |
2849 | json_area, "lsaAsbrChecksum", | |
2850 | ospf_lsdb_checksum(area->lsdb, OSPF_ASBR_SUMMARY_LSA)); | |
2851 | json_object_int_add( | |
2852 | json_area, "lsaNssaNumber", | |
2853 | ospf_lsdb_count(area->lsdb, OSPF_AS_NSSA_LSA)); | |
2854 | json_object_int_add( | |
2855 | json_area, "lsaNssaChecksum", | |
2856 | ospf_lsdb_checksum(area->lsdb, OSPF_AS_NSSA_LSA)); | |
2857 | } else { | |
2858 | /* Show number of fully adjacent neighbors. */ | |
2859 | vty_out(vty, | |
2860 | " Number of fully adjacent neighbors in this area:" | |
2861 | " %d\n", | |
2862 | area->full_nbrs); | |
2863 | ||
2864 | /* Show authentication type. */ | |
2865 | vty_out(vty, " Area has "); | |
2866 | if (area->auth_type == OSPF_AUTH_NULL) | |
2867 | vty_out(vty, "no authentication\n"); | |
2868 | else if (area->auth_type == OSPF_AUTH_SIMPLE) | |
2869 | vty_out(vty, "simple password authentication\n"); | |
2870 | else if (area->auth_type == OSPF_AUTH_CRYPTOGRAPHIC) | |
2871 | vty_out(vty, "message digest authentication\n"); | |
2872 | ||
2873 | if (!OSPF_IS_AREA_BACKBONE(area)) | |
2874 | vty_out(vty, | |
2875 | " Number of full virtual adjacencies going through" | |
2876 | " this area: %d\n", | |
2877 | area->full_vls); | |
2878 | ||
2879 | /* Show SPF calculation times. */ | |
2880 | vty_out(vty, " SPF algorithm executed %d times\n", | |
2881 | area->spf_calculation); | |
2882 | ||
2883 | /* Show number of LSA. */ | |
2884 | vty_out(vty, " Number of LSA %ld\n", area->lsdb->total); | |
2885 | vty_out(vty, | |
2886 | " Number of router LSA %ld. Checksum Sum 0x%08x\n", | |
2887 | ospf_lsdb_count(area->lsdb, OSPF_ROUTER_LSA), | |
2888 | ospf_lsdb_checksum(area->lsdb, OSPF_ROUTER_LSA)); | |
2889 | vty_out(vty, | |
2890 | " Number of network LSA %ld. Checksum Sum 0x%08x\n", | |
2891 | ospf_lsdb_count(area->lsdb, OSPF_NETWORK_LSA), | |
2892 | ospf_lsdb_checksum(area->lsdb, OSPF_NETWORK_LSA)); | |
2893 | vty_out(vty, | |
2894 | " Number of summary LSA %ld. Checksum Sum 0x%08x\n", | |
2895 | ospf_lsdb_count(area->lsdb, OSPF_SUMMARY_LSA), | |
2896 | ospf_lsdb_checksum(area->lsdb, OSPF_SUMMARY_LSA)); | |
2897 | vty_out(vty, | |
2898 | " Number of ASBR summary LSA %ld. Checksum Sum 0x%08x\n", | |
2899 | ospf_lsdb_count(area->lsdb, OSPF_ASBR_SUMMARY_LSA), | |
2900 | ospf_lsdb_checksum(area->lsdb, OSPF_ASBR_SUMMARY_LSA)); | |
2901 | vty_out(vty, " Number of NSSA LSA %ld. Checksum Sum 0x%08x\n", | |
2902 | ospf_lsdb_count(area->lsdb, OSPF_AS_NSSA_LSA), | |
2903 | ospf_lsdb_checksum(area->lsdb, OSPF_AS_NSSA_LSA)); | |
2904 | } | |
2905 | ||
2906 | if (use_json) { | |
2907 | json_object_int_add( | |
2908 | json_area, "lsaOpaqueLinkNumber", | |
2909 | ospf_lsdb_count(area->lsdb, OSPF_OPAQUE_LINK_LSA)); | |
2910 | json_object_int_add( | |
2911 | json_area, "lsaOpaqueLinkChecksum", | |
2912 | ospf_lsdb_checksum(area->lsdb, OSPF_OPAQUE_LINK_LSA)); | |
2913 | json_object_int_add( | |
2914 | json_area, "lsaOpaqueAreaNumber", | |
2915 | ospf_lsdb_count(area->lsdb, OSPF_OPAQUE_AREA_LSA)); | |
2916 | json_object_int_add( | |
2917 | json_area, "lsaOpaqueAreaChecksum", | |
2918 | ospf_lsdb_checksum(area->lsdb, OSPF_OPAQUE_AREA_LSA)); | |
2919 | } else { | |
2920 | vty_out(vty, | |
2921 | " Number of opaque link LSA %ld. Checksum Sum 0x%08x\n", | |
2922 | ospf_lsdb_count(area->lsdb, OSPF_OPAQUE_LINK_LSA), | |
2923 | ospf_lsdb_checksum(area->lsdb, OSPF_OPAQUE_LINK_LSA)); | |
2924 | vty_out(vty, | |
2925 | " Number of opaque area LSA %ld. Checksum Sum 0x%08x\n", | |
2926 | ospf_lsdb_count(area->lsdb, OSPF_OPAQUE_AREA_LSA), | |
2927 | ospf_lsdb_checksum(area->lsdb, OSPF_OPAQUE_AREA_LSA)); | |
2928 | } | |
718e3744 | 2929 | |
d62a17ae | 2930 | if (use_json) |
2931 | json_object_object_add(json_areas, inet_ntoa(area->area_id), | |
2932 | json_area); | |
2933 | else | |
2934 | vty_out(vty, "\n"); | |
718e3744 | 2935 | } |
2936 | ||
d62a17ae | 2937 | static int show_ip_ospf_common(struct vty *vty, struct ospf *ospf, |
d7c0a89a | 2938 | json_object *json, uint8_t use_vrf) |
d62a17ae | 2939 | { |
2940 | struct listnode *node, *nnode; | |
2941 | struct ospf_area *area; | |
2942 | struct timeval result; | |
2943 | char timebuf[OSPF_TIME_DUMP_SIZE]; | |
b1c3ae8c | 2944 | json_object *json_vrf = NULL; |
d62a17ae | 2945 | json_object *json_areas = NULL; |
718e3744 | 2946 | |
b1c3ae8c CS |
2947 | if (json) { |
2948 | if (use_vrf) | |
2949 | json_vrf = json_object_new_object(); | |
2950 | else | |
2951 | json_vrf = json; | |
d62a17ae | 2952 | json_areas = json_object_new_object(); |
2953 | } | |
2954 | ||
2955 | if (ospf->instance) { | |
b1c3ae8c | 2956 | if (json) { |
d62a17ae | 2957 | json_object_int_add(json, "ospfInstance", |
2958 | ospf->instance); | |
2959 | } else { | |
2960 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
2961 | } | |
2962 | } | |
2963 | ||
b1c3ae8c | 2964 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); |
87bd50e8 | 2965 | |
d62a17ae | 2966 | /* Show Router ID. */ |
b1c3ae8c CS |
2967 | if (json) { |
2968 | json_object_string_add(json_vrf, "routerId", | |
d62a17ae | 2969 | inet_ntoa(ospf->router_id)); |
2970 | } else { | |
2971 | vty_out(vty, " OSPF Routing Process, Router ID: %s\n", | |
2972 | inet_ntoa(ospf->router_id)); | |
2973 | } | |
2974 | ||
2975 | /* Graceful shutdown */ | |
2976 | if (ospf->t_deferred_shutdown) { | |
b1c3ae8c | 2977 | if (json) { |
d62a17ae | 2978 | long time_store; |
2979 | time_store = | |
2980 | monotime_until( | |
2981 | &ospf->t_deferred_shutdown->u.sands, | |
2982 | NULL) | |
2983 | / 1000LL; | |
b1c3ae8c | 2984 | json_object_int_add(json_vrf, "deferredShutdownMsecs", |
d62a17ae | 2985 | time_store); |
2986 | } else { | |
2987 | vty_out(vty, | |
2988 | " Deferred shutdown in progress, %s remaining\n", | |
2989 | ospf_timer_dump(ospf->t_deferred_shutdown, | |
2990 | timebuf, sizeof(timebuf))); | |
2991 | } | |
2992 | } | |
2993 | ||
2994 | /* Show capability. */ | |
b1c3ae8c CS |
2995 | if (json) { |
2996 | json_object_boolean_true_add(json_vrf, "tosRoutesOnly"); | |
2997 | json_object_boolean_true_add(json_vrf, "rfc2328Conform"); | |
d62a17ae | 2998 | if (CHECK_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE)) { |
b1c3ae8c | 2999 | json_object_boolean_true_add(json_vrf, |
d62a17ae | 3000 | "rfc1583Compatibility"); |
3001 | } | |
3002 | } else { | |
3003 | vty_out(vty, " Supports only single TOS (TOS0) routes\n"); | |
3004 | vty_out(vty, " This implementation conforms to RFC2328\n"); | |
3005 | vty_out(vty, " RFC1583Compatibility flag is %s\n", | |
3006 | CHECK_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE) | |
3007 | ? "enabled" | |
3008 | : "disabled"); | |
3009 | } | |
3010 | ||
b1c3ae8c | 3011 | if (json) { |
d62a17ae | 3012 | if (CHECK_FLAG(ospf->config, OSPF_OPAQUE_CAPABLE)) { |
b1c3ae8c | 3013 | json_object_boolean_true_add(json_vrf, "opaqueCapable"); |
d62a17ae | 3014 | } |
3015 | } else { | |
3016 | vty_out(vty, " OpaqueCapability flag is %s\n", | |
3017 | CHECK_FLAG(ospf->config, OSPF_OPAQUE_CAPABLE) | |
3018 | ? "enabled" | |
3019 | : "disabled"); | |
3020 | } | |
3021 | ||
3022 | /* Show stub-router configuration */ | |
3023 | if (ospf->stub_router_startup_time != OSPF_STUB_ROUTER_UNCONFIGURED | |
3024 | || ospf->stub_router_shutdown_time | |
3025 | != OSPF_STUB_ROUTER_UNCONFIGURED) { | |
b1c3ae8c CS |
3026 | if (json) { |
3027 | json_object_boolean_true_add(json_vrf, | |
3028 | "stubAdvertisement"); | |
d62a17ae | 3029 | if (ospf->stub_router_startup_time |
3030 | != OSPF_STUB_ROUTER_UNCONFIGURED) | |
3031 | json_object_int_add( | |
50ad4b42 MS |
3032 | json_vrf, "postStartEnabledSecs", |
3033 | ospf->stub_router_startup_time); | |
d62a17ae | 3034 | if (ospf->stub_router_shutdown_time |
3035 | != OSPF_STUB_ROUTER_UNCONFIGURED) | |
3036 | json_object_int_add( | |
50ad4b42 MS |
3037 | json_vrf, "preShutdownEnabledSecs", |
3038 | ospf->stub_router_shutdown_time); | |
d62a17ae | 3039 | } else { |
3040 | vty_out(vty, | |
3041 | " Stub router advertisement is configured\n"); | |
3042 | if (ospf->stub_router_startup_time | |
3043 | != OSPF_STUB_ROUTER_UNCONFIGURED) | |
3044 | vty_out(vty, | |
3045 | " Enabled for %us after start-up\n", | |
3046 | ospf->stub_router_startup_time); | |
3047 | if (ospf->stub_router_shutdown_time | |
3048 | != OSPF_STUB_ROUTER_UNCONFIGURED) | |
3049 | vty_out(vty, | |
3050 | " Enabled for %us prior to full shutdown\n", | |
3051 | ospf->stub_router_shutdown_time); | |
3052 | } | |
3053 | } | |
3054 | ||
3055 | /* Show SPF timers. */ | |
b1c3ae8c CS |
3056 | if (json) { |
3057 | json_object_int_add(json_vrf, "spfScheduleDelayMsecs", | |
d62a17ae | 3058 | ospf->spf_delay); |
b1c3ae8c | 3059 | json_object_int_add(json_vrf, "holdtimeMinMsecs", |
d62a17ae | 3060 | ospf->spf_holdtime); |
b1c3ae8c | 3061 | json_object_int_add(json_vrf, "holdtimeMaxMsecs", |
d62a17ae | 3062 | ospf->spf_max_holdtime); |
b1c3ae8c | 3063 | json_object_int_add(json_vrf, "holdtimeMultplier", |
d62a17ae | 3064 | ospf->spf_hold_multiplier); |
3065 | } else { | |
3066 | vty_out(vty, | |
3067 | " Initial SPF scheduling delay %d millisec(s)\n" | |
3068 | " Minimum hold time between consecutive SPFs %d millisec(s)\n" | |
3069 | " Maximum hold time between consecutive SPFs %d millisec(s)\n" | |
3070 | " Hold time multiplier is currently %d\n", | |
3071 | ospf->spf_delay, ospf->spf_holdtime, | |
3072 | ospf->spf_max_holdtime, ospf->spf_hold_multiplier); | |
3073 | } | |
3074 | ||
b1c3ae8c | 3075 | if (json) { |
d62a17ae | 3076 | if (ospf->ts_spf.tv_sec || ospf->ts_spf.tv_usec) { |
3077 | long time_store = 0; | |
3078 | ||
3079 | time_store = | |
3080 | monotime_since(&ospf->ts_spf, NULL) / 1000LL; | |
b1c3ae8c | 3081 | json_object_int_add(json_vrf, "spfLastExecutedMsecs", |
d62a17ae | 3082 | time_store); |
3083 | ||
3084 | time_store = (1000 * ospf->ts_spf_duration.tv_sec) | |
3085 | + (ospf->ts_spf_duration.tv_usec / 1000); | |
b1c3ae8c | 3086 | json_object_int_add(json_vrf, "spfLastDurationMsecs", |
d62a17ae | 3087 | time_store); |
3088 | } else | |
b1c3ae8c | 3089 | json_object_boolean_true_add(json_vrf, "spfHasNotRun"); |
d62a17ae | 3090 | } else { |
3091 | vty_out(vty, " SPF algorithm "); | |
3092 | if (ospf->ts_spf.tv_sec || ospf->ts_spf.tv_usec) { | |
3093 | monotime_since(&ospf->ts_spf, &result); | |
3094 | vty_out(vty, "last executed %s ago\n", | |
3095 | ospf_timeval_dump(&result, timebuf, | |
3096 | sizeof(timebuf))); | |
3097 | vty_out(vty, " Last SPF duration %s\n", | |
3098 | ospf_timeval_dump(&ospf->ts_spf_duration, | |
3099 | timebuf, sizeof(timebuf))); | |
3100 | } else | |
3101 | vty_out(vty, "has not been run\n"); | |
3102 | } | |
3103 | ||
b1c3ae8c | 3104 | if (json) { |
d62a17ae | 3105 | if (ospf->t_spf_calc) { |
3106 | long time_store; | |
3107 | time_store = | |
3108 | monotime_until(&ospf->t_spf_calc->u.sands, NULL) | |
3109 | / 1000LL; | |
b1c3ae8c | 3110 | json_object_int_add(json_vrf, "spfTimerDueInMsecs", |
d62a17ae | 3111 | time_store); |
3112 | } | |
3113 | ||
b1c3ae8c | 3114 | json_object_int_add(json_vrf, "lsaMinIntervalMsecs", |
d62a17ae | 3115 | ospf->min_ls_interval); |
b1c3ae8c | 3116 | json_object_int_add(json_vrf, "lsaMinArrivalMsecs", |
d62a17ae | 3117 | ospf->min_ls_arrival); |
3118 | /* Show write multiplier values */ | |
b1c3ae8c | 3119 | json_object_int_add(json_vrf, "writeMultiplier", |
d62a17ae | 3120 | ospf->write_oi_count); |
3121 | /* Show refresh parameters. */ | |
b1c3ae8c | 3122 | json_object_int_add(json_vrf, "refreshTimerMsecs", |
d62a17ae | 3123 | ospf->lsa_refresh_interval * 1000); |
3124 | } else { | |
3125 | vty_out(vty, " SPF timer %s%s\n", | |
3126 | (ospf->t_spf_calc ? "due in " : "is "), | |
3127 | ospf_timer_dump(ospf->t_spf_calc, timebuf, | |
3128 | sizeof(timebuf))); | |
3129 | ||
3130 | vty_out(vty, " LSA minimum interval %d msecs\n", | |
3131 | ospf->min_ls_interval); | |
3132 | vty_out(vty, " LSA minimum arrival %d msecs\n", | |
3133 | ospf->min_ls_arrival); | |
3134 | ||
3135 | /* Show write multiplier values */ | |
3136 | vty_out(vty, " Write Multiplier set to %d \n", | |
3137 | ospf->write_oi_count); | |
3138 | ||
3139 | /* Show refresh parameters. */ | |
3140 | vty_out(vty, " Refresh timer %d secs\n", | |
3141 | ospf->lsa_refresh_interval); | |
3142 | } | |
3143 | ||
3144 | /* Show ABR/ASBR flags. */ | |
3145 | if (CHECK_FLAG(ospf->flags, OSPF_FLAG_ABR)) { | |
b1c3ae8c | 3146 | if (json) |
d62a17ae | 3147 | json_object_string_add( |
b1c3ae8c | 3148 | json_vrf, "abrType", |
d62a17ae | 3149 | ospf_abr_type_descr_str[ospf->abr_type]); |
3150 | else | |
3151 | vty_out(vty, | |
3152 | " This router is an ABR, ABR type is: %s\n", | |
3153 | ospf_abr_type_descr_str[ospf->abr_type]); | |
3154 | } | |
3155 | if (CHECK_FLAG(ospf->flags, OSPF_FLAG_ASBR)) { | |
b1c3ae8c | 3156 | if (json) |
d62a17ae | 3157 | json_object_string_add( |
b1c3ae8c | 3158 | json_vrf, "asbrRouter", |
d62a17ae | 3159 | "injectingExternalRoutingInformation"); |
3160 | else | |
3161 | vty_out(vty, | |
3162 | " This router is an ASBR " | |
3163 | "(injecting external routing information)\n"); | |
3164 | } | |
3165 | ||
3166 | /* Show Number of AS-external-LSAs. */ | |
b1c3ae8c | 3167 | if (json) { |
d62a17ae | 3168 | json_object_int_add( |
b1c3ae8c | 3169 | json_vrf, "lsaExternalCounter", |
d62a17ae | 3170 | ospf_lsdb_count(ospf->lsdb, OSPF_AS_EXTERNAL_LSA)); |
3171 | json_object_int_add( | |
b1c3ae8c | 3172 | json_vrf, "lsaExternalChecksum", |
d62a17ae | 3173 | ospf_lsdb_checksum(ospf->lsdb, OSPF_AS_EXTERNAL_LSA)); |
3174 | } else { | |
3175 | vty_out(vty, | |
3176 | " Number of external LSA %ld. Checksum Sum 0x%08x\n", | |
3177 | ospf_lsdb_count(ospf->lsdb, OSPF_AS_EXTERNAL_LSA), | |
3178 | ospf_lsdb_checksum(ospf->lsdb, OSPF_AS_EXTERNAL_LSA)); | |
3179 | } | |
3180 | ||
b1c3ae8c | 3181 | if (json) { |
d62a17ae | 3182 | json_object_int_add( |
b1c3ae8c | 3183 | json_vrf, "lsaAsopaqueCounter", |
d62a17ae | 3184 | ospf_lsdb_count(ospf->lsdb, OSPF_OPAQUE_AS_LSA)); |
3185 | json_object_int_add( | |
b1c3ae8c | 3186 | json_vrf, "lsaAsOpaqueChecksum", |
d62a17ae | 3187 | ospf_lsdb_checksum(ospf->lsdb, OSPF_OPAQUE_AS_LSA)); |
3188 | } else { | |
3189 | vty_out(vty, | |
3190 | " Number of opaque AS LSA %ld. Checksum Sum 0x%08x\n", | |
3191 | ospf_lsdb_count(ospf->lsdb, OSPF_OPAQUE_AS_LSA), | |
3192 | ospf_lsdb_checksum(ospf->lsdb, OSPF_OPAQUE_AS_LSA)); | |
3193 | } | |
3194 | ||
3195 | /* Show number of areas attached. */ | |
b1c3ae8c CS |
3196 | if (json) |
3197 | json_object_int_add(json_vrf, "attachedAreaCounter", | |
d62a17ae | 3198 | listcount(ospf->areas)); |
3199 | else | |
3200 | vty_out(vty, " Number of areas attached to this router: %d\n", | |
3201 | listcount(ospf->areas)); | |
3202 | ||
3203 | if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES)) { | |
3204 | if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL)) { | |
b1c3ae8c | 3205 | if (json) |
d62a17ae | 3206 | json_object_boolean_true_add( |
b1c3ae8c | 3207 | json_vrf, "adjacencyChangesLoggedAll"); |
d62a17ae | 3208 | else |
3209 | vty_out(vty, | |
3210 | " All adjacency changes are logged\n"); | |
3211 | } else { | |
b1c3ae8c | 3212 | if (json) |
d62a17ae | 3213 | json_object_boolean_true_add( |
b1c3ae8c | 3214 | json_vrf, "adjacencyChangesLogged"); |
d62a17ae | 3215 | else |
3216 | vty_out(vty, " Adjacency changes are logged\n"); | |
3217 | } | |
3218 | } | |
3219 | /* Show each area status. */ | |
3220 | for (ALL_LIST_ELEMENTS(ospf->areas, node, nnode, area)) | |
b1c3ae8c CS |
3221 | show_ip_ospf_area(vty, area, json_areas, json ? 1 : 0); |
3222 | ||
3223 | if (json) { | |
3224 | if (use_vrf) { | |
3225 | json_object_object_add(json_vrf, "areas", json_areas); | |
3226 | if (ospf->vrf_id == VRF_DEFAULT) | |
3227 | json_object_object_add(json, "default", | |
3228 | json_vrf); | |
3229 | else | |
3230 | json_object_object_add(json, ospf->name, | |
3231 | json_vrf); | |
3232 | } else { | |
3233 | json_object_object_add(json, "areas", json_areas); | |
3234 | } | |
d62a17ae | 3235 | } else |
3236 | vty_out(vty, "\n"); | |
3237 | ||
3238 | return CMD_SUCCESS; | |
718e3744 | 3239 | } |
3240 | ||
7c8ff89e DS |
3241 | DEFUN (show_ip_ospf, |
3242 | show_ip_ospf_cmd, | |
b5a8894d | 3243 | "show ip ospf [vrf <NAME|all>] [json]", |
7c8ff89e DS |
3244 | SHOW_STR |
3245 | IP_STR | |
ca08c43d | 3246 | "OSPF information\n" |
b5a8894d CS |
3247 | VRF_CMD_HELP_STR |
3248 | "All VRFs\n" | |
9973d184 | 3249 | JSON_STR) |
7c8ff89e | 3250 | { |
d62a17ae | 3251 | struct ospf *ospf; |
9f049418 | 3252 | bool uj = use_json(argc, argv); |
b5a8894d CS |
3253 | struct listnode *node = NULL; |
3254 | char *vrf_name = NULL; | |
2951a7a4 | 3255 | bool all_vrf = false; |
b5a8894d CS |
3256 | int ret = CMD_SUCCESS; |
3257 | int inst = 0; | |
3258 | int idx_vrf = 0; | |
b1c3ae8c | 3259 | json_object *json = NULL; |
d7c0a89a | 3260 | uint8_t use_vrf = 0; |
7c8ff89e | 3261 | |
b5a8894d | 3262 | if (listcount(om->ospf) == 0) |
d62a17ae | 3263 | return CMD_SUCCESS; |
7c8ff89e | 3264 | |
43b8d1d8 | 3265 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
b5a8894d | 3266 | |
b1c3ae8c CS |
3267 | if (uj) |
3268 | json = json_object_new_object(); | |
3269 | ||
996c9314 | 3270 | /* vrf input is provided could be all or specific vrf*/ |
b5a8894d | 3271 | if (vrf_name) { |
2951a7a4 | 3272 | bool ospf_output = false; |
874f58d8 | 3273 | |
b1c3ae8c | 3274 | use_vrf = 1; |
94d4c685 | 3275 | |
b5a8894d CS |
3276 | if (all_vrf) { |
3277 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
3278 | if (!ospf->oi_running) | |
3279 | continue; | |
2951a7a4 | 3280 | ospf_output = true; |
b1c3ae8c CS |
3281 | ret = show_ip_ospf_common(vty, ospf, json, |
3282 | use_vrf); | |
3283 | } | |
3284 | if (uj) { | |
3285 | vty_out(vty, "%s\n", | |
996c9314 LB |
3286 | json_object_to_json_string_ext( |
3287 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 3288 | json_object_free(json); |
9f049418 DS |
3289 | } else if (!ospf_output) |
3290 | vty_out(vty, "%% OSPF instance not found\n"); | |
b5a8894d CS |
3291 | return ret; |
3292 | } | |
3293 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
b1c3ae8c | 3294 | if ((ospf == NULL) || !ospf->oi_running) { |
9f049418 DS |
3295 | if (uj) { |
3296 | vty_out(vty, "%s\n", | |
3297 | json_object_to_json_string_ext( | |
3298 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 3299 | json_object_free(json); |
9f049418 | 3300 | } else |
94d4c685 | 3301 | vty_out(vty, "%% OSPF instance not found\n"); |
9f049418 | 3302 | |
b5a8894d | 3303 | return CMD_SUCCESS; |
b1c3ae8c | 3304 | } |
b5a8894d CS |
3305 | } else { |
3306 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
3307 | /* Display default ospf (instance 0) info */ | |
b1c3ae8c | 3308 | if (ospf == NULL || !ospf->oi_running) { |
9f049418 DS |
3309 | if (uj) { |
3310 | vty_out(vty, "%s\n", | |
3311 | json_object_to_json_string_ext( | |
3312 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 3313 | json_object_free(json); |
9f049418 | 3314 | } else |
94d4c685 | 3315 | vty_out(vty, "%% OSPF instance not found\n"); |
9f049418 | 3316 | |
b5a8894d | 3317 | return CMD_SUCCESS; |
b1c3ae8c | 3318 | } |
b5a8894d CS |
3319 | } |
3320 | ||
996c9314 | 3321 | if (ospf) { |
b1c3ae8c CS |
3322 | show_ip_ospf_common(vty, ospf, json, use_vrf); |
3323 | if (uj) | |
996c9314 LB |
3324 | vty_out(vty, "%s\n", |
3325 | json_object_to_json_string_ext( | |
3326 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c CS |
3327 | } |
3328 | ||
3329 | if (uj) | |
3330 | json_object_free(json); | |
b5a8894d CS |
3331 | |
3332 | return ret; | |
7c8ff89e DS |
3333 | } |
3334 | ||
3335 | DEFUN (show_ip_ospf_instance, | |
3336 | show_ip_ospf_instance_cmd, | |
6147e2c6 | 3337 | "show ip ospf (1-65535) [json]", |
7c8ff89e DS |
3338 | SHOW_STR |
3339 | IP_STR | |
3340 | "OSPF information\n" | |
ca08c43d | 3341 | "Instance ID\n" |
9973d184 | 3342 | JSON_STR) |
7c8ff89e | 3343 | { |
d62a17ae | 3344 | int idx_number = 3; |
3345 | struct ospf *ospf; | |
d7c0a89a | 3346 | unsigned short instance = 0; |
9f049418 | 3347 | bool uj = use_json(argc, argv); |
b1c3ae8c CS |
3348 | int ret = CMD_SUCCESS; |
3349 | json_object *json = NULL; | |
d62a17ae | 3350 | |
3351 | instance = strtoul(argv[idx_number]->arg, NULL, 10); | |
ac28e4ec CS |
3352 | ospf = ospf_lookup_instance(instance); |
3353 | if (ospf == NULL) | |
3354 | return CMD_NOT_MY_INSTANCE; | |
3355 | ||
3356 | if (!ospf->oi_running) | |
d62a17ae | 3357 | return CMD_SUCCESS; |
3358 | ||
b1c3ae8c CS |
3359 | if (uj) |
3360 | json = json_object_new_object(); | |
3361 | ||
3362 | ret = show_ip_ospf_common(vty, ospf, json, 0); | |
3363 | ||
3364 | if (uj) { | |
996c9314 LB |
3365 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
3366 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c CS |
3367 | json_object_free(json); |
3368 | } | |
3369 | ||
3370 | return ret; | |
d62a17ae | 3371 | } |
3372 | ||
3373 | static void show_ip_ospf_interface_sub(struct vty *vty, struct ospf *ospf, | |
3374 | struct interface *ifp, | |
3375 | json_object *json_interface_sub, | |
9f049418 | 3376 | bool use_json) |
d62a17ae | 3377 | { |
3378 | int is_up; | |
3379 | struct ospf_neighbor *nbr; | |
3380 | struct route_node *rn; | |
3381 | uint32_t bandwidth = ifp->bandwidth ? ifp->bandwidth : ifp->speed; | |
3382 | ||
3383 | /* Is interface up? */ | |
3384 | if (use_json) { | |
3385 | is_up = if_is_operative(ifp); | |
3386 | if (is_up) | |
3387 | json_object_boolean_true_add(json_interface_sub, | |
3388 | "ifUp"); | |
3389 | else | |
3390 | json_object_boolean_false_add(json_interface_sub, | |
3391 | "ifDown"); | |
3392 | ||
3393 | json_object_int_add(json_interface_sub, "ifIndex", | |
3394 | ifp->ifindex); | |
3395 | json_object_int_add(json_interface_sub, "mtuBytes", ifp->mtu); | |
3396 | json_object_int_add(json_interface_sub, "bandwidthMbit", | |
3397 | bandwidth); | |
3398 | json_object_string_add(json_interface_sub, "ifFlags", | |
3399 | if_flag_dump(ifp->flags)); | |
3400 | } else { | |
3401 | vty_out(vty, "%s is %s\n", ifp->name, | |
3402 | ((is_up = if_is_operative(ifp)) ? "up" : "down")); | |
3403 | vty_out(vty, " ifindex %u, MTU %u bytes, BW %u Mbit %s\n", | |
3404 | ifp->ifindex, ifp->mtu, bandwidth, | |
3405 | if_flag_dump(ifp->flags)); | |
3406 | } | |
7c8ff89e | 3407 | |
d62a17ae | 3408 | /* Is interface OSPF enabled? */ |
3409 | if (use_json) { | |
3410 | if (ospf_oi_count(ifp) == 0) { | |
3411 | json_object_boolean_false_add(json_interface_sub, | |
3412 | "ospfEnabled"); | |
3413 | return; | |
3414 | } else if (!is_up) { | |
3415 | json_object_boolean_false_add(json_interface_sub, | |
3416 | "ospfRunning"); | |
3417 | return; | |
3418 | } else | |
3419 | json_object_boolean_true_add(json_interface_sub, | |
3420 | "ospfEnabled"); | |
3421 | } else { | |
3422 | if (ospf_oi_count(ifp) == 0) { | |
3423 | vty_out(vty, " OSPF not enabled on this interface\n"); | |
3424 | return; | |
3425 | } else if (!is_up) { | |
3426 | vty_out(vty, | |
3427 | " OSPF is enabled, but not running on this interface\n"); | |
3428 | return; | |
3429 | } | |
3430 | } | |
3431 | ||
3432 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { | |
3433 | struct ospf_interface *oi = rn->info; | |
3434 | ||
3435 | if (oi == NULL) | |
3436 | continue; | |
3437 | ||
3438 | if (CHECK_FLAG(oi->connected->flags, ZEBRA_IFA_UNNUMBERED)) { | |
3439 | if (use_json) | |
3440 | json_object_boolean_true_add(json_interface_sub, | |
3441 | "ifUnnumbered"); | |
3442 | else | |
3443 | vty_out(vty, " This interface is UNNUMBERED,"); | |
3444 | } else { | |
3445 | /* Show OSPF interface information. */ | |
3446 | if (use_json) { | |
3447 | json_object_string_add( | |
3448 | json_interface_sub, "ipAddress", | |
3449 | inet_ntoa(oi->address->u.prefix4)); | |
3450 | json_object_int_add(json_interface_sub, | |
3451 | "ipAddressPrefixlen", | |
3452 | oi->address->prefixlen); | |
3453 | } else | |
3454 | vty_out(vty, " Internet Address %s/%d,", | |
3455 | inet_ntoa(oi->address->u.prefix4), | |
3456 | oi->address->prefixlen); | |
3457 | ||
3458 | if (oi->connected->destination | |
3459 | || oi->type == OSPF_IFTYPE_VIRTUALLINK) { | |
3460 | struct in_addr *dest; | |
3461 | const char *dstr; | |
3462 | ||
3463 | if (CONNECTED_PEER(oi->connected) | |
3464 | || oi->type == OSPF_IFTYPE_VIRTUALLINK) | |
3465 | dstr = "Peer"; | |
3466 | else | |
3467 | dstr = "Broadcast"; | |
3468 | ||
3469 | /* For Vlinks, showing the peer address is | |
9d303b37 DL |
3470 | * probably more |
3471 | * * * * * informative than the local | |
3472 | * interface that is being used | |
3473 | * * * * */ | |
d62a17ae | 3474 | if (oi->type == OSPF_IFTYPE_VIRTUALLINK) |
3475 | dest = &oi->vl_data->peer_addr; | |
3476 | else | |
3477 | dest = &oi->connected->destination->u | |
3478 | .prefix4; | |
3479 | ||
3480 | if (use_json) { | |
3481 | json_object_string_add( | |
3482 | json_interface_sub, | |
3483 | "ospfIfType", dstr); | |
3484 | if (oi->type == OSPF_IFTYPE_VIRTUALLINK) | |
3485 | json_object_string_add( | |
3486 | json_interface_sub, | |
3487 | "vlinkPeer", | |
3488 | inet_ntoa(*dest)); | |
3489 | else | |
3490 | json_object_string_add( | |
3491 | json_interface_sub, | |
3492 | "localIfUsed", | |
3493 | inet_ntoa(*dest)); | |
3494 | } else | |
3495 | vty_out(vty, " %s %s,", dstr, | |
3496 | inet_ntoa(*dest)); | |
3497 | } | |
3498 | } | |
3499 | if (use_json) { | |
3500 | json_object_string_add(json_interface_sub, "area", | |
3501 | ospf_area_desc_string(oi->area)); | |
3502 | if (OSPF_IF_PARAM(oi, mtu_ignore)) | |
3503 | json_object_boolean_true_add( | |
3504 | json_interface_sub, | |
3505 | "mtuMismatchDetect"); | |
3506 | json_object_string_add(json_interface_sub, "routerId", | |
3507 | inet_ntoa(ospf->router_id)); | |
3508 | json_object_string_add(json_interface_sub, | |
3509 | "networkType", | |
3510 | ospf_network_type_str[oi->type]); | |
3511 | json_object_int_add(json_interface_sub, "cost", | |
3512 | oi->output_cost); | |
3513 | json_object_int_add( | |
50ad4b42 MS |
3514 | json_interface_sub, "transmitDelaySecs", |
3515 | OSPF_IF_PARAM(oi, transmit_delay)); | |
d62a17ae | 3516 | json_object_string_add(json_interface_sub, "state", |
3517 | lookup_msg(ospf_ism_state_msg, | |
3518 | oi->state, NULL)); | |
3519 | json_object_int_add(json_interface_sub, "priority", | |
3520 | PRIORITY(oi)); | |
3521 | } else { | |
3522 | vty_out(vty, " Area %s\n", | |
3523 | ospf_area_desc_string(oi->area)); | |
3524 | ||
3525 | vty_out(vty, " MTU mismatch detection: %s\n", | |
3526 | OSPF_IF_PARAM(oi, mtu_ignore) ? "disabled" | |
3527 | : "enabled"); | |
3528 | ||
3529 | vty_out(vty, | |
3530 | " Router ID %s, Network Type %s, Cost: %d\n", | |
3531 | inet_ntoa(ospf->router_id), | |
3532 | ospf_network_type_str[oi->type], | |
3533 | oi->output_cost); | |
3534 | ||
3535 | vty_out(vty, | |
3536 | " Transmit Delay is %d sec, State %s, Priority %d\n", | |
3537 | OSPF_IF_PARAM(oi, transmit_delay), | |
3538 | lookup_msg(ospf_ism_state_msg, oi->state, NULL), | |
3539 | PRIORITY(oi)); | |
3540 | } | |
3541 | ||
3542 | /* Show DR information. */ | |
3543 | if (DR(oi).s_addr == 0) { | |
3544 | if (!use_json) | |
3545 | vty_out(vty, | |
3546 | " No backup designated router on this network\n"); | |
3547 | } else { | |
3548 | nbr = ospf_nbr_lookup_by_addr(oi->nbrs, &BDR(oi)); | |
3549 | if (nbr == NULL) { | |
3550 | if (!use_json) | |
3551 | vty_out(vty, | |
3552 | " No backup designated router on this network\n"); | |
3553 | } else { | |
3554 | if (use_json) { | |
3555 | json_object_string_add( | |
3556 | json_interface_sub, "bdrId", | |
3557 | inet_ntoa(nbr->router_id)); | |
3558 | json_object_string_add( | |
3559 | json_interface_sub, | |
3560 | "bdrAddress", | |
3561 | inet_ntoa(nbr->address.u | |
3562 | .prefix4)); | |
3563 | } else { | |
3564 | vty_out(vty, | |
3565 | " Backup Designated Router (ID) %s,", | |
3566 | inet_ntoa(nbr->router_id)); | |
3567 | vty_out(vty, " Interface Address %s\n", | |
3568 | inet_ntoa(nbr->address.u | |
3569 | .prefix4)); | |
3570 | } | |
3571 | } | |
3572 | } | |
3573 | ||
3574 | /* Next network-LSA sequence number we'll use, if we're elected | |
3575 | * DR */ | |
3576 | if (oi->params | |
3577 | && ntohl(oi->params->network_lsa_seqnum) | |
3578 | != OSPF_INITIAL_SEQUENCE_NUMBER) { | |
3579 | if (use_json) | |
3580 | json_object_int_add( | |
3581 | json_interface_sub, | |
3582 | "networkLsaSequence", | |
3583 | ntohl(oi->params->network_lsa_seqnum)); | |
3584 | else | |
3585 | vty_out(vty, | |
3586 | " Saved Network-LSA sequence number 0x%x\n", | |
3587 | ntohl(oi->params->network_lsa_seqnum)); | |
3588 | } | |
3589 | ||
3590 | if (use_json) { | |
3591 | if (OI_MEMBER_CHECK(oi, MEMBER_ALLROUTERS) | |
3592 | || OI_MEMBER_CHECK(oi, MEMBER_DROUTERS)) { | |
3593 | if (OI_MEMBER_CHECK(oi, MEMBER_ALLROUTERS)) | |
3594 | json_object_boolean_true_add( | |
3595 | json_interface_sub, | |
3596 | "mcastMemberOspfAllRouters"); | |
3597 | if (OI_MEMBER_CHECK(oi, MEMBER_DROUTERS)) | |
3598 | json_object_boolean_true_add( | |
3599 | json_interface_sub, | |
3600 | "mcastMemberOspfDesignatedRouters"); | |
3601 | } | |
3602 | } else { | |
3603 | vty_out(vty, " Multicast group memberships:"); | |
3604 | if (OI_MEMBER_CHECK(oi, MEMBER_ALLROUTERS) | |
3605 | || OI_MEMBER_CHECK(oi, MEMBER_DROUTERS)) { | |
3606 | if (OI_MEMBER_CHECK(oi, MEMBER_ALLROUTERS)) | |
3607 | vty_out(vty, " OSPFAllRouters"); | |
3608 | if (OI_MEMBER_CHECK(oi, MEMBER_DROUTERS)) | |
3609 | vty_out(vty, " OSPFDesignatedRouters"); | |
3610 | } else | |
3611 | vty_out(vty, " <None>"); | |
3612 | vty_out(vty, "\n"); | |
3613 | } | |
3614 | ||
3615 | if (use_json) { | |
3616 | if (OSPF_IF_PARAM(oi, fast_hello) == 0) | |
3617 | json_object_int_add( | |
3618 | json_interface_sub, "timerMsecs", | |
50ad4b42 | 3619 | OSPF_IF_PARAM(oi, v_hello) * 1000); |
d62a17ae | 3620 | else |
3621 | json_object_int_add( | |
3622 | json_interface_sub, "timerMsecs", | |
50ad4b42 | 3623 | 1000 / OSPF_IF_PARAM(oi, fast_hello)); |
d62a17ae | 3624 | json_object_int_add(json_interface_sub, |
50ad4b42 MS |
3625 | "timerDeadSecs", |
3626 | OSPF_IF_PARAM(oi, v_wait)); | |
d62a17ae | 3627 | json_object_int_add(json_interface_sub, |
50ad4b42 MS |
3628 | "timerWaitSecs", |
3629 | OSPF_IF_PARAM(oi, v_wait)); | |
d62a17ae | 3630 | json_object_int_add( |
50ad4b42 MS |
3631 | json_interface_sub, "timerRetransmitSecs", |
3632 | OSPF_IF_PARAM(oi, retransmit_interval)); | |
d62a17ae | 3633 | } else { |
3634 | vty_out(vty, " Timer intervals configured,"); | |
3635 | vty_out(vty, " Hello "); | |
3636 | if (OSPF_IF_PARAM(oi, fast_hello) == 0) | |
3637 | vty_out(vty, "%ds,", | |
3638 | OSPF_IF_PARAM(oi, v_hello)); | |
3639 | else | |
3640 | vty_out(vty, "%dms,", | |
3641 | 1000 / OSPF_IF_PARAM(oi, fast_hello)); | |
3642 | vty_out(vty, " Dead %ds, Wait %ds, Retransmit %d\n", | |
3643 | OSPF_IF_PARAM(oi, v_wait), | |
3644 | OSPF_IF_PARAM(oi, v_wait), | |
3645 | OSPF_IF_PARAM(oi, retransmit_interval)); | |
3646 | } | |
3647 | ||
3648 | if (OSPF_IF_PASSIVE_STATUS(oi) == OSPF_IF_ACTIVE) { | |
3649 | char timebuf[OSPF_TIME_DUMP_SIZE]; | |
3650 | if (use_json) { | |
3651 | long time_store = 0; | |
3652 | if (oi->t_hello) | |
3653 | time_store = | |
3654 | monotime_until( | |
3655 | &oi->t_hello->u.sands, | |
3656 | NULL) | |
3657 | / 1000LL; | |
3658 | json_object_int_add(json_interface_sub, | |
3659 | "timerHelloInMsecs", | |
3660 | time_store); | |
3661 | } else | |
3662 | vty_out(vty, " Hello due in %s\n", | |
3663 | ospf_timer_dump(oi->t_hello, timebuf, | |
3664 | sizeof(timebuf))); | |
3665 | } else /* passive-interface is set */ | |
3666 | { | |
3667 | if (use_json) | |
3668 | json_object_boolean_true_add( | |
3669 | json_interface_sub, | |
3670 | "timerPassiveIface"); | |
3671 | else | |
3672 | vty_out(vty, | |
3673 | " No Hellos (Passive interface)\n"); | |
3674 | } | |
7c8ff89e | 3675 | |
d62a17ae | 3676 | if (use_json) { |
3677 | json_object_int_add(json_interface_sub, "nbrCount", | |
3678 | ospf_nbr_count(oi, 0)); | |
3679 | json_object_int_add(json_interface_sub, | |
3680 | "nbrAdjacentCount", | |
3681 | ospf_nbr_count(oi, NSM_Full)); | |
3682 | } else | |
3683 | vty_out(vty, | |
3684 | " Neighbor Count is %d, Adjacent neighbor count is %d\n", | |
3685 | ospf_nbr_count(oi, 0), | |
3686 | ospf_nbr_count(oi, NSM_Full)); | |
3687 | ospf_bfd_interface_show(vty, ifp, json_interface_sub, use_json); | |
3688 | } | |
718e3744 | 3689 | } |
3690 | ||
d62a17ae | 3691 | static int show_ip_ospf_interface_common(struct vty *vty, struct ospf *ospf, |
d7c0a89a | 3692 | char *intf_name, uint8_t use_vrf, |
9f049418 | 3693 | json_object *json, bool use_json) |
d62a17ae | 3694 | { |
3695 | struct interface *ifp; | |
f4e14fdb | 3696 | struct vrf *vrf = vrf_lookup_by_id(ospf->vrf_id); |
6282e124 | 3697 | json_object *json_vrf = NULL; |
7dab10ce | 3698 | json_object *json_interface_sub = NULL, *json_interface = NULL; |
7c8ff89e | 3699 | |
d62a17ae | 3700 | if (use_json) { |
b1c3ae8c CS |
3701 | if (use_vrf) |
3702 | json_vrf = json_object_new_object(); | |
3703 | else | |
3704 | json_vrf = json; | |
6282e124 | 3705 | json_interface = json_object_new_object(); |
d62a17ae | 3706 | } |
3707 | ||
3708 | if (ospf->instance) { | |
3709 | if (use_json) | |
3710 | json_object_int_add(json, "ospfInstance", | |
3711 | ospf->instance); | |
3712 | else | |
3713 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
3714 | } | |
3715 | ||
b1c3ae8c CS |
3716 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); |
3717 | ||
3718 | if (intf_name == NULL) { | |
d62a17ae | 3719 | /* Show All Interfaces.*/ |
451fda4f | 3720 | FOR_ALL_INTERFACES (vrf, ifp) { |
d62a17ae | 3721 | if (ospf_oi_count(ifp)) { |
7dab10ce | 3722 | if (use_json) { |
d62a17ae | 3723 | json_interface_sub = |
3724 | json_object_new_object(); | |
7dab10ce | 3725 | } |
d62a17ae | 3726 | show_ip_ospf_interface_sub(vty, ospf, ifp, |
3727 | json_interface_sub, | |
3728 | use_json); | |
3729 | ||
7dab10ce | 3730 | if (use_json) { |
d62a17ae | 3731 | json_object_object_add( |
7dab10ce | 3732 | json_interface, ifp->name, |
d62a17ae | 3733 | json_interface_sub); |
7dab10ce | 3734 | } |
d62a17ae | 3735 | } |
3736 | } | |
6282e124 CS |
3737 | if (use_json) |
3738 | json_object_object_add(json_vrf, "interfaces", | |
996c9314 | 3739 | json_interface); |
d62a17ae | 3740 | } else { |
3741 | /* Interface name is specified. */ | |
a36898e7 | 3742 | ifp = if_lookup_by_name(intf_name, ospf->vrf_id); |
b1c3ae8c | 3743 | if (ifp == NULL) { |
d62a17ae | 3744 | if (use_json) |
b1c3ae8c | 3745 | json_object_boolean_true_add(json_vrf, |
d62a17ae | 3746 | "noSuchIface"); |
3747 | else | |
3748 | vty_out(vty, "No such interface name\n"); | |
3749 | } else { | |
7dab10ce | 3750 | if (use_json) { |
d62a17ae | 3751 | json_interface_sub = json_object_new_object(); |
7dab10ce | 3752 | json_interface = json_object_new_object(); |
7dab10ce | 3753 | } |
d62a17ae | 3754 | |
3755 | show_ip_ospf_interface_sub( | |
3756 | vty, ospf, ifp, json_interface_sub, use_json); | |
3757 | ||
7dab10ce | 3758 | if (use_json) { |
7dab10ce CS |
3759 | json_object_object_add(json_interface, |
3760 | ifp->name, | |
d62a17ae | 3761 | json_interface_sub); |
6282e124 CS |
3762 | json_object_object_add(json_vrf, "interfaces", |
3763 | json_interface); | |
7dab10ce | 3764 | } |
d62a17ae | 3765 | } |
3766 | } | |
3767 | ||
3768 | if (use_json) { | |
b1c3ae8c CS |
3769 | if (use_vrf) { |
3770 | if (ospf->vrf_id == VRF_DEFAULT) | |
3771 | json_object_object_add(json, "default", | |
3772 | json_vrf); | |
3773 | else | |
3774 | json_object_object_add(json, ospf->name, | |
3775 | json_vrf); | |
3776 | } | |
d62a17ae | 3777 | } else |
3778 | vty_out(vty, "\n"); | |
3779 | ||
3780 | return CMD_SUCCESS; | |
718e3744 | 3781 | } |
3782 | ||
c9339663 CS |
3783 | static void show_ip_ospf_interface_traffic_sub(struct vty *vty, |
3784 | struct ospf_interface *oi, | |
3785 | json_object *json_interface_sub, | |
9f049418 | 3786 | bool use_json) |
c9339663 CS |
3787 | { |
3788 | if (use_json) { | |
996c9314 LB |
3789 | json_object_int_add(json_interface_sub, "ifIndex", |
3790 | oi->ifp->ifindex); | |
3791 | json_object_int_add(json_interface_sub, "helloIn", | |
3792 | oi->hello_in); | |
3793 | json_object_int_add(json_interface_sub, "helloOut", | |
3794 | oi->hello_out); | |
3795 | json_object_int_add(json_interface_sub, "dbDescIn", | |
3796 | oi->db_desc_in); | |
3797 | json_object_int_add(json_interface_sub, "dbDescOut", | |
3798 | oi->db_desc_out); | |
3799 | json_object_int_add(json_interface_sub, "lsReqIn", | |
3800 | oi->ls_req_in); | |
3801 | json_object_int_add(json_interface_sub, "lsReqOut", | |
3802 | oi->ls_req_out); | |
3803 | json_object_int_add(json_interface_sub, "lsUpdIn", | |
3804 | oi->ls_upd_in); | |
3805 | json_object_int_add(json_interface_sub, "lsUpdOut", | |
3806 | oi->ls_upd_out); | |
3807 | json_object_int_add(json_interface_sub, "lsAckIn", | |
3808 | oi->ls_ack_in); | |
3809 | json_object_int_add(json_interface_sub, "lsAckOut", | |
3810 | oi->ls_ack_out); | |
c9339663 CS |
3811 | } else { |
3812 | vty_out(vty, | |
3813 | "%-10s %8u/%-8u %7u/%-7u %7u/%-7u %7u/%-7u %7u/%-7u\n", | |
996c9314 LB |
3814 | oi->ifp->name, oi->hello_in, oi->hello_out, |
3815 | oi->db_desc_in, oi->db_desc_out, oi->ls_req_in, | |
3816 | oi->ls_req_out, oi->ls_upd_in, oi->ls_upd_out, | |
c9339663 CS |
3817 | oi->ls_ack_in, oi->ls_ack_out); |
3818 | } | |
3819 | } | |
3820 | ||
3821 | /* OSPFv2 Packet Counters */ | |
996c9314 LB |
3822 | static int show_ip_ospf_interface_traffic_common( |
3823 | struct vty *vty, struct ospf *ospf, char *intf_name, json_object *json, | |
9f049418 | 3824 | int display_once, uint8_t use_vrf, bool use_json) |
c9339663 CS |
3825 | { |
3826 | struct vrf *vrf = NULL; | |
3827 | struct interface *ifp = NULL; | |
b1c3ae8c | 3828 | json_object *json_vrf = NULL; |
c9339663 CS |
3829 | json_object *json_interface_sub = NULL; |
3830 | ||
3831 | if (!use_json && !display_once) { | |
3832 | vty_out(vty, "\n"); | |
996c9314 LB |
3833 | vty_out(vty, "%-12s%-17s%-17s%-17s%-17s%-17s\n", "Interface", |
3834 | " HELLO", " DB-Desc", " LS-Req", " LS-Update", | |
3835 | " LS-Ack"); | |
c9339663 | 3836 | vty_out(vty, "%-10s%-18s%-18s%-17s%-17s%-17s\n", "", |
996c9314 LB |
3837 | " Rx/Tx", " Rx/Tx", " Rx/Tx", " Rx/Tx", |
3838 | " Rx/Tx"); | |
c9339663 | 3839 | vty_out(vty, |
996c9314 | 3840 | "--------------------------------------------------------------------------------------------\n"); |
c9339663 | 3841 | } else if (use_json) { |
b1c3ae8c CS |
3842 | if (use_vrf) |
3843 | json_vrf = json_object_new_object(); | |
3844 | else | |
3845 | json_vrf = json; | |
c9339663 CS |
3846 | } |
3847 | ||
b1c3ae8c CS |
3848 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); |
3849 | ||
c9339663 CS |
3850 | if (intf_name == NULL) { |
3851 | vrf = vrf_lookup_by_id(ospf->vrf_id); | |
3852 | FOR_ALL_INTERFACES (vrf, ifp) { | |
3853 | struct route_node *rn; | |
3854 | struct ospf_interface *oi; | |
3855 | ||
3856 | if (ospf_oi_count(ifp) == 0) | |
3857 | continue; | |
3858 | ||
3859 | for (rn = route_top(IF_OIFS(ifp)); rn; | |
996c9314 | 3860 | rn = route_next(rn)) { |
c9339663 CS |
3861 | oi = rn->info; |
3862 | ||
3863 | if (oi == NULL) | |
3864 | continue; | |
3865 | ||
3866 | if (use_json) { | |
3867 | json_interface_sub = | |
3868 | json_object_new_object(); | |
3869 | } | |
3870 | ||
996c9314 LB |
3871 | show_ip_ospf_interface_traffic_sub( |
3872 | vty, oi, json_interface_sub, use_json); | |
c9339663 | 3873 | if (use_json) { |
996c9314 LB |
3874 | json_object_object_add( |
3875 | json_vrf, ifp->name, | |
3876 | json_interface_sub); | |
c9339663 CS |
3877 | } |
3878 | } | |
3879 | } | |
3880 | } else { | |
3881 | /* Interface name is specified. */ | |
a36898e7 | 3882 | ifp = if_lookup_by_name(intf_name, ospf->vrf_id); |
c9339663 CS |
3883 | if (ifp != NULL) { |
3884 | struct route_node *rn; | |
3885 | struct ospf_interface *oi; | |
3886 | ||
3887 | if (ospf_oi_count(ifp) == 0) { | |
996c9314 LB |
3888 | vty_out(vty, |
3889 | " OSPF not enabled on this interface %s\n", | |
c9339663 CS |
3890 | ifp->name); |
3891 | return CMD_SUCCESS; | |
3892 | } | |
3893 | ||
3894 | for (rn = route_top(IF_OIFS(ifp)); rn; | |
3895 | rn = route_next(rn)) { | |
3896 | oi = rn->info; | |
3897 | ||
3898 | if (use_json) { | |
3899 | json_interface_sub = | |
3900 | json_object_new_object(); | |
3901 | } | |
3902 | ||
996c9314 LB |
3903 | show_ip_ospf_interface_traffic_sub( |
3904 | vty, oi, json_interface_sub, use_json); | |
c9339663 | 3905 | if (use_json) { |
996c9314 LB |
3906 | json_object_object_add( |
3907 | json_vrf, ifp->name, | |
3908 | json_interface_sub); | |
c9339663 CS |
3909 | } |
3910 | } | |
3911 | } | |
3912 | } | |
3913 | ||
3914 | if (use_json) { | |
b1c3ae8c CS |
3915 | if (use_vrf) { |
3916 | if (ospf->vrf_id == VRF_DEFAULT) | |
3917 | json_object_object_add(json, "default", | |
3918 | json_vrf); | |
3919 | else | |
3920 | json_object_object_add(json, ospf->name, | |
3921 | json_vrf); | |
3922 | } | |
3923 | } else | |
3924 | vty_out(vty, "\n"); | |
c9339663 CS |
3925 | |
3926 | return CMD_SUCCESS; | |
3927 | } | |
3928 | ||
7c8ff89e DS |
3929 | DEFUN (show_ip_ospf_interface, |
3930 | show_ip_ospf_interface_cmd, | |
43b8d1d8 | 3931 | "show ip ospf [vrf <NAME|all>] interface [INTERFACE] [json]", |
7c8ff89e DS |
3932 | SHOW_STR |
3933 | IP_STR | |
3934 | "OSPF information\n" | |
b5a8894d | 3935 | VRF_CMD_HELP_STR |
43b8d1d8 | 3936 | "All VRFs\n" |
7c8ff89e | 3937 | "Interface information\n" |
7ec4159b | 3938 | "Interface name\n" |
9973d184 | 3939 | JSON_STR) |
7c8ff89e | 3940 | { |
d62a17ae | 3941 | struct ospf *ospf; |
9f049418 | 3942 | bool uj = use_json(argc, argv); |
b5a8894d | 3943 | struct listnode *node = NULL; |
b1c3ae8c | 3944 | char *vrf_name = NULL, *intf_name = NULL; |
2951a7a4 | 3945 | bool all_vrf = false; |
b5a8894d CS |
3946 | int ret = CMD_SUCCESS; |
3947 | int inst = 0; | |
b1c3ae8c | 3948 | int idx_vrf = 0, idx_intf = 0; |
d7c0a89a | 3949 | uint8_t use_vrf = 0; |
b1c3ae8c | 3950 | json_object *json = NULL; |
7c8ff89e | 3951 | |
43b8d1d8 CS |
3952 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
3953 | ||
b1c3ae8c CS |
3954 | if (argv_find(argv, argc, "INTERFACE", &idx_intf)) |
3955 | intf_name = argv[idx_intf]->arg; | |
3956 | ||
d62a17ae | 3957 | if (uj) |
b1c3ae8c | 3958 | json = json_object_new_object(); |
6be4da3d | 3959 | |
b5a8894d CS |
3960 | /* vrf input is provided could be all or specific vrf*/ |
3961 | if (vrf_name) { | |
b1c3ae8c | 3962 | use_vrf = 1; |
b5a8894d CS |
3963 | if (all_vrf) { |
3964 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
3965 | if (!ospf->oi_running) | |
3966 | continue; | |
996c9314 LB |
3967 | ret = show_ip_ospf_interface_common( |
3968 | vty, ospf, intf_name, use_vrf, json, | |
3969 | uj); | |
b5a8894d | 3970 | } |
b1c3ae8c CS |
3971 | |
3972 | if (uj) { | |
3973 | vty_out(vty, "%s\n", | |
996c9314 LB |
3974 | json_object_to_json_string_ext( |
3975 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 3976 | json_object_free(json); |
9f049418 | 3977 | } else if (!ospf) |
94d4c685 | 3978 | vty_out(vty, "%% OSPF instance not found\n"); |
b1c3ae8c | 3979 | |
b5a8894d CS |
3980 | return ret; |
3981 | } | |
3982 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
b1c3ae8c | 3983 | if (ospf == NULL || !ospf->oi_running) { |
9f049418 DS |
3984 | if (uj) { |
3985 | vty_out(vty, "%s\n", | |
3986 | json_object_to_json_string_ext( | |
3987 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 3988 | json_object_free(json); |
9f049418 | 3989 | } else |
94d4c685 | 3990 | vty_out(vty, "%% OSPF instance not found\n"); |
9f049418 | 3991 | |
b5a8894d | 3992 | return CMD_SUCCESS; |
b1c3ae8c CS |
3993 | } |
3994 | ret = show_ip_ospf_interface_common(vty, ospf, intf_name, | |
3995 | use_vrf, json, uj); | |
b5a8894d CS |
3996 | |
3997 | } else { | |
3998 | /* Display default ospf (instance 0) info */ | |
3999 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
b1c3ae8c | 4000 | if (ospf == NULL || !ospf->oi_running) { |
9f049418 DS |
4001 | if (uj) { |
4002 | vty_out(vty, "%s\n", | |
4003 | json_object_to_json_string_ext( | |
4004 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 4005 | json_object_free(json); |
9f049418 | 4006 | } else |
94d4c685 | 4007 | vty_out(vty, "%% OSPF instance not found\n"); |
9f049418 | 4008 | |
b5a8894d | 4009 | return CMD_SUCCESS; |
b1c3ae8c CS |
4010 | } |
4011 | ret = show_ip_ospf_interface_common(vty, ospf, intf_name, | |
4012 | use_vrf, json, uj); | |
4013 | } | |
4014 | ||
4015 | if (uj) { | |
996c9314 LB |
4016 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
4017 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 4018 | json_object_free(json); |
b5a8894d CS |
4019 | } |
4020 | ||
4021 | return ret; | |
7c8ff89e DS |
4022 | } |
4023 | ||
4024 | DEFUN (show_ip_ospf_instance_interface, | |
4025 | show_ip_ospf_instance_interface_cmd, | |
6147e2c6 | 4026 | "show ip ospf (1-65535) interface [INTERFACE] [json]", |
7c8ff89e DS |
4027 | SHOW_STR |
4028 | IP_STR | |
4029 | "OSPF information\n" | |
4030 | "Instance ID\n" | |
4031 | "Interface information\n" | |
7ec4159b | 4032 | "Interface name\n" |
9973d184 | 4033 | JSON_STR) |
7c8ff89e | 4034 | { |
d62a17ae | 4035 | int idx_number = 3; |
b1c3ae8c | 4036 | int idx_intf = 0; |
d62a17ae | 4037 | struct ospf *ospf; |
d7c0a89a | 4038 | unsigned short instance = 0; |
9f049418 | 4039 | bool uj = use_json(argc, argv); |
b1c3ae8c CS |
4040 | char *intf_name = NULL; |
4041 | int ret = CMD_SUCCESS; | |
4042 | json_object *json = NULL; | |
d62a17ae | 4043 | |
4044 | instance = strtoul(argv[idx_number]->arg, NULL, 10); | |
ac28e4ec CS |
4045 | ospf = ospf_lookup_instance(instance); |
4046 | if (ospf == NULL) | |
4047 | return CMD_NOT_MY_INSTANCE; | |
4048 | ||
4049 | if (!ospf->oi_running) | |
d62a17ae | 4050 | return CMD_SUCCESS; |
4051 | ||
4052 | if (uj) | |
b1c3ae8c CS |
4053 | json = json_object_new_object(); |
4054 | ||
4055 | if (argv_find(argv, argc, "INTERFACE", &idx_intf)) | |
4056 | intf_name = argv[idx_intf]->arg; | |
4057 | ||
4058 | ret = show_ip_ospf_interface_common(vty, ospf, intf_name, 0, json, uj); | |
4059 | ||
4060 | if (uj) { | |
996c9314 LB |
4061 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
4062 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c CS |
4063 | json_object_free(json); |
4064 | } | |
d62a17ae | 4065 | |
b1c3ae8c | 4066 | return ret; |
d62a17ae | 4067 | } |
4068 | ||
c9339663 CS |
4069 | DEFUN (show_ip_ospf_interface_traffic, |
4070 | show_ip_ospf_interface_traffic_cmd, | |
4071 | "show ip ospf [vrf <NAME|all>] interface traffic [INTERFACE] [json]", | |
4072 | SHOW_STR | |
4073 | IP_STR | |
4074 | "OSPF information\n" | |
4075 | VRF_CMD_HELP_STR | |
4076 | "All VRFs\n" | |
4077 | "Interface information\n" | |
4078 | "Protocol Packet counters\n" | |
4079 | "Interface name\n" | |
4080 | JSON_STR) | |
4081 | { | |
4082 | struct ospf *ospf = NULL; | |
4083 | struct listnode *node = NULL; | |
4084 | char *vrf_name = NULL, *intf_name = NULL; | |
2951a7a4 | 4085 | bool all_vrf = false; |
c9339663 CS |
4086 | int inst = 0; |
4087 | int idx_vrf = 0, idx_intf = 0; | |
9f049418 | 4088 | bool uj = use_json(argc, argv); |
b1c3ae8c | 4089 | json_object *json = NULL; |
c9339663 CS |
4090 | int ret = CMD_SUCCESS; |
4091 | int display_once = 0; | |
d7c0a89a | 4092 | uint8_t use_vrf = 0; |
c9339663 CS |
4093 | |
4094 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); | |
4095 | ||
4096 | if (argv_find(argv, argc, "INTERFACE", &idx_intf)) | |
4097 | intf_name = argv[idx_intf]->arg; | |
4098 | ||
b1c3ae8c CS |
4099 | if (uj) |
4100 | json = json_object_new_object(); | |
4101 | ||
c9339663 | 4102 | if (vrf_name) { |
b1c3ae8c | 4103 | use_vrf = 1; |
c9339663 CS |
4104 | if (all_vrf) { |
4105 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
4106 | if (!ospf->oi_running) | |
4107 | continue; | |
4108 | ||
996c9314 LB |
4109 | ret = show_ip_ospf_interface_traffic_common( |
4110 | vty, ospf, intf_name, json, | |
4111 | display_once, use_vrf, uj); | |
c9339663 CS |
4112 | display_once = 1; |
4113 | } | |
b1c3ae8c CS |
4114 | |
4115 | if (uj) { | |
4116 | vty_out(vty, "%s\n", | |
996c9314 LB |
4117 | json_object_to_json_string_ext( |
4118 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c CS |
4119 | json_object_free(json); |
4120 | } | |
4121 | ||
c9339663 CS |
4122 | return ret; |
4123 | } | |
4124 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
b1c3ae8c CS |
4125 | if (ospf == NULL || !ospf->oi_running) { |
4126 | if (uj) | |
4127 | json_object_free(json); | |
c9339663 | 4128 | return CMD_SUCCESS; |
b1c3ae8c CS |
4129 | } |
4130 | ||
996c9314 LB |
4131 | ret = show_ip_ospf_interface_traffic_common( |
4132 | vty, ospf, intf_name, json, display_once, use_vrf, uj); | |
c9339663 CS |
4133 | } else { |
4134 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
b1c3ae8c CS |
4135 | if (ospf == NULL || !ospf->oi_running) { |
4136 | if (uj) | |
4137 | json_object_free(json); | |
c9339663 | 4138 | return CMD_SUCCESS; |
b1c3ae8c CS |
4139 | } |
4140 | ||
996c9314 LB |
4141 | ret = show_ip_ospf_interface_traffic_common( |
4142 | vty, ospf, intf_name, json, display_once, use_vrf, uj); | |
b1c3ae8c CS |
4143 | } |
4144 | ||
4145 | if (uj) { | |
996c9314 LB |
4146 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
4147 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 4148 | json_object_free(json); |
c9339663 CS |
4149 | } |
4150 | ||
4151 | return ret; | |
4152 | } | |
4153 | ||
4154 | ||
d62a17ae | 4155 | static void show_ip_ospf_neighbour_header(struct vty *vty) |
4156 | { | |
4157 | vty_out(vty, "\n%-15s %3s %-15s %9s %-15s %-20s %5s %5s %5s\n", | |
4158 | "Neighbor ID", "Pri", "State", "Dead Time", "Address", | |
4159 | "Interface", "RXmtL", "RqstL", "DBsmL"); | |
4160 | } | |
4161 | ||
4162 | static void show_ip_ospf_neighbor_sub(struct vty *vty, | |
4163 | struct ospf_interface *oi, | |
9f049418 | 4164 | json_object *json, bool use_json) |
d62a17ae | 4165 | { |
4166 | struct route_node *rn; | |
cef262c3 | 4167 | struct ospf_neighbor *nbr, *prev_nbr = NULL; |
d62a17ae | 4168 | char msgbuf[16]; |
4169 | char timebuf[OSPF_TIME_DUMP_SIZE]; | |
cef262c3 | 4170 | json_object *json_neighbor = NULL, *json_neigh_array = NULL; |
d62a17ae | 4171 | |
4172 | for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) { | |
4173 | if ((nbr = rn->info)) { | |
4174 | /* Do not show myself. */ | |
cef262c3 CS |
4175 | if (nbr == oi->nbr_self) |
4176 | continue; | |
4177 | /* Down state is not shown. */ | |
4178 | if (nbr->state == NSM_Down) | |
4179 | continue; | |
4180 | if (use_json) { | |
4181 | char neigh_str[INET_ADDRSTRLEN]; | |
4182 | ||
996c9314 LB |
4183 | if (prev_nbr |
4184 | && !IPV4_ADDR_SAME(&prev_nbr->src, | |
4185 | &nbr->src)) { | |
cef262c3 CS |
4186 | /* Start new neigh list */ |
4187 | json_neigh_array = NULL; | |
4188 | } | |
4189 | ||
996c9314 LB |
4190 | if (nbr->state == NSM_Attempt |
4191 | && nbr->router_id.s_addr == 0) | |
6021c6c0 CS |
4192 | strlcpy(neigh_str, "neighbor", |
4193 | sizeof(neigh_str)); | |
cef262c3 | 4194 | else |
6021c6c0 | 4195 | strlcpy(neigh_str, |
cef262c3 | 4196 | inet_ntoa(nbr->router_id), |
6021c6c0 | 4197 | sizeof(neigh_str)); |
cef262c3 CS |
4198 | |
4199 | json_object_object_get_ex(json, neigh_str, | |
4200 | &json_neigh_array); | |
4201 | ||
4202 | if (!json_neigh_array) { | |
996c9314 LB |
4203 | json_neigh_array = |
4204 | json_object_new_array(); | |
4205 | json_object_object_add( | |
4206 | json, neigh_str, | |
4207 | json_neigh_array); | |
d62a17ae | 4208 | } |
cef262c3 | 4209 | |
996c9314 | 4210 | json_neighbor = json_object_new_object(); |
cef262c3 CS |
4211 | |
4212 | ospf_nbr_state_message(nbr, msgbuf, 16); | |
4213 | ||
4214 | long time_store; | |
4215 | ||
996c9314 LB |
4216 | time_store = |
4217 | monotime_until( | |
cef262c3 | 4218 | &nbr->t_inactivity->u.sands, |
996c9314 LB |
4219 | NULL) |
4220 | / 1000LL; | |
cef262c3 | 4221 | |
996c9314 | 4222 | json_object_int_add(json_neighbor, "priority", |
cef262c3 CS |
4223 | nbr->priority); |
4224 | json_object_string_add(json_neighbor, "state", | |
4225 | msgbuf); | |
4226 | json_object_int_add(json_neighbor, | |
4227 | "deadTimeMsecs", | |
4228 | time_store); | |
996c9314 | 4229 | json_object_string_add(json_neighbor, "address", |
cef262c3 CS |
4230 | inet_ntoa(nbr->src)); |
4231 | json_object_string_add(json_neighbor, | |
4232 | "ifaceName", | |
4233 | IF_NAME(oi)); | |
996c9314 LB |
4234 | json_object_int_add( |
4235 | json_neighbor, "retransmitCounter", | |
4236 | ospf_ls_retransmit_count(nbr)); | |
cef262c3 | 4237 | json_object_int_add(json_neighbor, |
996c9314 LB |
4238 | "requestCounter", |
4239 | ospf_ls_request_count(nbr)); | |
cef262c3 | 4240 | json_object_int_add(json_neighbor, |
996c9314 LB |
4241 | "dbSummaryCounter", |
4242 | ospf_db_summary_count(nbr)); | |
cef262c3 CS |
4243 | |
4244 | json_object_array_add(json_neigh_array, | |
4245 | json_neighbor); | |
4246 | } else { | |
4247 | ospf_nbr_state_message(nbr, msgbuf, 16); | |
4248 | ||
996c9314 LB |
4249 | if (nbr->state == NSM_Attempt |
4250 | && nbr->router_id.s_addr == 0) | |
4251 | vty_out(vty, "%-15s %3d %-15s ", "-", | |
4252 | nbr->priority, msgbuf); | |
cef262c3 | 4253 | else |
996c9314 | 4254 | vty_out(vty, "%-15s %3d %-15s ", |
cef262c3 | 4255 | inet_ntoa(nbr->router_id), |
996c9314 | 4256 | nbr->priority, msgbuf); |
cef262c3 CS |
4257 | |
4258 | vty_out(vty, "%9s ", | |
4259 | ospf_timer_dump(nbr->t_inactivity, | |
4260 | timebuf, | |
4261 | sizeof(timebuf))); | |
4262 | vty_out(vty, "%-15s ", inet_ntoa(nbr->src)); | |
996c9314 | 4263 | vty_out(vty, "%-20s %5ld %5ld %5d\n", |
cef262c3 CS |
4264 | IF_NAME(oi), |
4265 | ospf_ls_retransmit_count(nbr), | |
4266 | ospf_ls_request_count(nbr), | |
4267 | ospf_db_summary_count(nbr)); | |
d62a17ae | 4268 | } |
cef262c3 | 4269 | prev_nbr = nbr; |
d62a17ae | 4270 | } |
4271 | } | |
4272 | } | |
4273 | ||
4274 | static int show_ip_ospf_neighbor_common(struct vty *vty, struct ospf *ospf, | |
9f049418 | 4275 | json_object *json, bool use_json, |
d7c0a89a | 4276 | uint8_t use_vrf) |
d62a17ae | 4277 | { |
4278 | struct ospf_interface *oi; | |
4279 | struct listnode *node; | |
6282e124 | 4280 | json_object *json_vrf = NULL; |
2bc7673f | 4281 | json_object *json_nbr_sub = NULL; |
7c8ff89e | 4282 | |
b1c3ae8c CS |
4283 | if (use_json) { |
4284 | if (use_vrf) | |
4285 | json_vrf = json_object_new_object(); | |
4286 | else | |
4287 | json_vrf = json; | |
6282e124 | 4288 | json_nbr_sub = json_object_new_object(); |
b1c3ae8c | 4289 | } |
d62a17ae | 4290 | |
4291 | if (ospf->instance) { | |
4292 | if (use_json) | |
4293 | json_object_int_add(json, "ospfInstance", | |
4294 | ospf->instance); | |
4295 | else | |
4296 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
4297 | } | |
7c8ff89e | 4298 | |
b1c3ae8c CS |
4299 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); |
4300 | if (!use_json) | |
4301 | show_ip_ospf_neighbour_header(vty); | |
87bd50e8 | 4302 | |
2bc7673f CS |
4303 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) { |
4304 | if (ospf_interface_neighbor_count(oi) == 0) | |
4305 | continue; | |
2bc7673f CS |
4306 | show_ip_ospf_neighbor_sub(vty, oi, json_nbr_sub, use_json); |
4307 | } | |
718e3744 | 4308 | |
d62a17ae | 4309 | if (use_json) { |
996c9314 | 4310 | json_object_object_add(json_vrf, "neighbors", json_nbr_sub); |
b1c3ae8c CS |
4311 | if (use_vrf) { |
4312 | if (ospf->vrf_id == VRF_DEFAULT) | |
4313 | json_object_object_add(json, "default", | |
4314 | json_vrf); | |
4315 | else | |
4316 | json_object_object_add(json, ospf->name, | |
4317 | json_vrf); | |
4318 | } | |
d62a17ae | 4319 | } else |
4320 | vty_out(vty, "\n"); | |
7c8ff89e | 4321 | |
d62a17ae | 4322 | return CMD_SUCCESS; |
718e3744 | 4323 | } |
4324 | ||
7c8ff89e DS |
4325 | DEFUN (show_ip_ospf_neighbor, |
4326 | show_ip_ospf_neighbor_cmd, | |
b5a8894d | 4327 | "show ip ospf [vrf <NAME|all>] neighbor [json]", |
718e3744 | 4328 | SHOW_STR |
4329 | IP_STR | |
4330 | "OSPF information\n" | |
b5a8894d CS |
4331 | VRF_CMD_HELP_STR |
4332 | "All VRFs\n" | |
91756b38 | 4333 | "Neighbor list\n" |
9973d184 | 4334 | JSON_STR) |
718e3744 | 4335 | { |
d62a17ae | 4336 | struct ospf *ospf; |
9f049418 | 4337 | bool uj = use_json(argc, argv); |
b5a8894d CS |
4338 | struct listnode *node = NULL; |
4339 | char *vrf_name = NULL; | |
2951a7a4 | 4340 | bool all_vrf = false; |
b5a8894d CS |
4341 | int ret = CMD_SUCCESS; |
4342 | int inst = 0; | |
4343 | int idx_vrf = 0; | |
d7c0a89a | 4344 | uint8_t use_vrf = 0; |
b1c3ae8c | 4345 | json_object *json = NULL; |
718e3744 | 4346 | |
43b8d1d8 | 4347 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
7c8ff89e | 4348 | |
b1c3ae8c CS |
4349 | if (uj) |
4350 | json = json_object_new_object(); | |
b5a8894d CS |
4351 | |
4352 | /* vrf input is provided could be all or specific vrf*/ | |
4353 | if (vrf_name) { | |
b1c3ae8c | 4354 | use_vrf = 1; |
b5a8894d CS |
4355 | if (all_vrf) { |
4356 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
4357 | if (!ospf->oi_running) | |
4358 | continue; | |
996c9314 LB |
4359 | ret = show_ip_ospf_neighbor_common( |
4360 | vty, ospf, json, uj, use_vrf); | |
b1c3ae8c CS |
4361 | } |
4362 | ||
4363 | if (uj) { | |
4364 | vty_out(vty, "%s\n", | |
996c9314 LB |
4365 | json_object_to_json_string_ext( |
4366 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 4367 | json_object_free(json); |
9f049418 DS |
4368 | } else if (!ospf) |
4369 | vty_out(vty, "OSPF instance not found\n"); | |
b1c3ae8c | 4370 | |
b5a8894d CS |
4371 | return ret; |
4372 | } | |
b1c3ae8c | 4373 | |
b5a8894d | 4374 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); |
b1c3ae8c | 4375 | if (ospf == NULL || !ospf->oi_running) { |
9f049418 DS |
4376 | if (uj) { |
4377 | vty_out(vty, "%s\n", | |
4378 | json_object_to_json_string_ext( | |
4379 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 4380 | json_object_free(json); |
9f049418 DS |
4381 | } else |
4382 | vty_out(vty, "%% OSPF instance not found\n"); | |
4383 | ||
b5a8894d | 4384 | return CMD_SUCCESS; |
b1c3ae8c | 4385 | } |
b5a8894d CS |
4386 | } else { |
4387 | /* Display default ospf (instance 0) info */ | |
4388 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
b1c3ae8c | 4389 | if (ospf == NULL || !ospf->oi_running) { |
9f049418 DS |
4390 | if (uj) { |
4391 | vty_out(vty, "%s\n", | |
4392 | json_object_to_json_string_ext( | |
4393 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 4394 | json_object_free(json); |
9f049418 DS |
4395 | } else |
4396 | vty_out(vty, "%% OSPF instance not found\n"); | |
4397 | ||
b5a8894d | 4398 | return CMD_SUCCESS; |
b1c3ae8c | 4399 | } |
b5a8894d CS |
4400 | } |
4401 | ||
b1c3ae8c CS |
4402 | if (ospf) { |
4403 | ret = show_ip_ospf_neighbor_common(vty, ospf, json, uj, | |
4404 | use_vrf); | |
4405 | ||
4406 | if (uj) { | |
4407 | vty_out(vty, "%s\n", | |
996c9314 LB |
4408 | json_object_to_json_string_ext( |
4409 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c CS |
4410 | } |
4411 | } | |
4412 | ||
4413 | if (uj) | |
4414 | json_object_free(json); | |
b5a8894d CS |
4415 | |
4416 | return ret; | |
7c8ff89e DS |
4417 | } |
4418 | ||
4419 | ||
4420 | DEFUN (show_ip_ospf_instance_neighbor, | |
4421 | show_ip_ospf_instance_neighbor_cmd, | |
6147e2c6 | 4422 | "show ip ospf (1-65535) neighbor [json]", |
7c8ff89e DS |
4423 | SHOW_STR |
4424 | IP_STR | |
4425 | "OSPF information\n" | |
4426 | "Instance ID\n" | |
91756b38 | 4427 | "Neighbor list\n" |
9973d184 | 4428 | JSON_STR) |
7c8ff89e | 4429 | { |
d62a17ae | 4430 | int idx_number = 3; |
4431 | struct ospf *ospf; | |
d7c0a89a | 4432 | unsigned short instance = 0; |
9f049418 | 4433 | bool uj = use_json(argc, argv); |
b1c3ae8c CS |
4434 | json_object *json = NULL; |
4435 | int ret = CMD_SUCCESS; | |
7c8ff89e | 4436 | |
d62a17ae | 4437 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
ac28e4ec CS |
4438 | ospf = ospf_lookup_instance(instance); |
4439 | if (ospf == NULL) | |
4440 | return CMD_NOT_MY_INSTANCE; | |
4441 | ||
4442 | if (!ospf->oi_running) | |
d62a17ae | 4443 | return CMD_SUCCESS; |
7c8ff89e | 4444 | |
b1c3ae8c CS |
4445 | if (uj) |
4446 | json = json_object_new_object(); | |
b5a8894d | 4447 | |
b1c3ae8c CS |
4448 | ret = show_ip_ospf_neighbor_common(vty, ospf, json, uj, 0); |
4449 | ||
4450 | if (uj) { | |
996c9314 LB |
4451 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
4452 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c CS |
4453 | json_object_free(json); |
4454 | } | |
4455 | ||
4456 | return ret; | |
7c8ff89e DS |
4457 | } |
4458 | ||
d62a17ae | 4459 | static int show_ip_ospf_neighbor_all_common(struct vty *vty, struct ospf *ospf, |
9f049418 | 4460 | json_object *json, bool use_json, |
d7c0a89a | 4461 | uint8_t use_vrf) |
d62a17ae | 4462 | { |
4463 | struct listnode *node; | |
4464 | struct ospf_interface *oi; | |
b1c3ae8c | 4465 | json_object *json_vrf = NULL; |
d62a17ae | 4466 | json_object *json_neighbor_sub = NULL; |
7c8ff89e | 4467 | |
d62a17ae | 4468 | if (use_json) { |
b1c3ae8c CS |
4469 | if (use_vrf) |
4470 | json_vrf = json_object_new_object(); | |
4471 | else | |
4472 | json_vrf = json; | |
d62a17ae | 4473 | json_neighbor_sub = json_object_new_object(); |
b5a8894d | 4474 | } |
d62a17ae | 4475 | |
b1c3ae8c CS |
4476 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); |
4477 | if (!use_json) | |
4478 | show_ip_ospf_neighbour_header(vty); | |
4479 | ||
d62a17ae | 4480 | if (ospf->instance) { |
4481 | if (use_json) | |
b1c3ae8c | 4482 | json_object_int_add(json_vrf, "ospfInstance", |
d62a17ae | 4483 | ospf->instance); |
4484 | else | |
4485 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
4486 | } | |
4487 | ||
4488 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) { | |
4489 | struct listnode *nbr_node; | |
4490 | struct ospf_nbr_nbma *nbr_nbma; | |
4491 | ||
b1c3ae8c | 4492 | show_ip_ospf_neighbor_sub(vty, oi, json_vrf, use_json); |
d62a17ae | 4493 | |
4494 | /* print Down neighbor status */ | |
4495 | for (ALL_LIST_ELEMENTS_RO(oi->nbr_nbma, nbr_node, nbr_nbma)) { | |
4496 | if (nbr_nbma->nbr == NULL | |
4497 | || nbr_nbma->nbr->state == NSM_Down) { | |
4498 | if (use_json) { | |
4499 | json_object_int_add(json_neighbor_sub, | |
4500 | "nbrNbmaPriority", | |
4501 | nbr_nbma->priority); | |
4502 | json_object_boolean_true_add( | |
4503 | json_neighbor_sub, | |
4504 | "nbrNbmaDown"); | |
4505 | json_object_string_add( | |
4506 | json_neighbor_sub, | |
4507 | "nbrNbmaIfaceName", | |
4508 | IF_NAME(oi)); | |
4509 | json_object_int_add( | |
4510 | json_neighbor_sub, | |
4511 | "nbrNbmaRetransmitCounter", 0); | |
4512 | json_object_int_add( | |
4513 | json_neighbor_sub, | |
4514 | "nbrNbmaRequestCounter", 0); | |
4515 | json_object_int_add( | |
4516 | json_neighbor_sub, | |
4517 | "nbrNbmaDbSummaryCounter", 0); | |
4518 | json_object_object_add( | |
b1c3ae8c CS |
4519 | json_vrf, |
4520 | inet_ntoa(nbr_nbma->addr), | |
d62a17ae | 4521 | json_neighbor_sub); |
4522 | } else { | |
4523 | vty_out(vty, "%-15s %3d %-15s %9s ", | |
4524 | "-", nbr_nbma->priority, "Down", | |
4525 | "-"); | |
4526 | vty_out(vty, | |
4527 | "%-15s %-20s %5d %5d %5d\n", | |
4528 | inet_ntoa(nbr_nbma->addr), | |
4529 | IF_NAME(oi), 0, 0, 0); | |
4530 | } | |
4531 | } | |
4532 | } | |
4533 | } | |
4534 | ||
4535 | if (use_json) { | |
b1c3ae8c CS |
4536 | if (use_vrf) { |
4537 | if (ospf->vrf_id == VRF_DEFAULT) | |
4538 | json_object_object_add(json, "default", | |
4539 | json_vrf); | |
4540 | else | |
4541 | json_object_object_add(json, ospf->name, | |
4542 | json_vrf); | |
4543 | } | |
d62a17ae | 4544 | } else |
4545 | vty_out(vty, "\n"); | |
4546 | ||
4547 | return CMD_SUCCESS; | |
718e3744 | 4548 | } |
4549 | ||
7c8ff89e DS |
4550 | DEFUN (show_ip_ospf_neighbor_all, |
4551 | show_ip_ospf_neighbor_all_cmd, | |
b5a8894d | 4552 | "show ip ospf [vrf <NAME|all>] neighbor all [json]", |
718e3744 | 4553 | SHOW_STR |
4554 | IP_STR | |
4555 | "OSPF information\n" | |
b5a8894d CS |
4556 | VRF_CMD_HELP_STR |
4557 | "All VRFs\n" | |
718e3744 | 4558 | "Neighbor list\n" |
91756b38 | 4559 | "include down status neighbor\n" |
9973d184 | 4560 | JSON_STR) |
7c8ff89e | 4561 | { |
d62a17ae | 4562 | struct ospf *ospf; |
9f049418 | 4563 | bool uj = use_json(argc, argv); |
b5a8894d CS |
4564 | struct listnode *node = NULL; |
4565 | char *vrf_name = NULL; | |
2951a7a4 | 4566 | bool all_vrf = false; |
b5a8894d CS |
4567 | int ret = CMD_SUCCESS; |
4568 | int inst = 0; | |
4569 | int idx_vrf = 0; | |
d7c0a89a | 4570 | uint8_t use_vrf = 0; |
b1c3ae8c | 4571 | json_object *json = NULL; |
7c8ff89e | 4572 | |
43b8d1d8 | 4573 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
7c8ff89e | 4574 | |
b1c3ae8c CS |
4575 | if (uj) |
4576 | json = json_object_new_object(); | |
b5a8894d CS |
4577 | |
4578 | /* vrf input is provided could be all or specific vrf*/ | |
4579 | if (vrf_name) { | |
b1c3ae8c | 4580 | use_vrf = 1; |
b5a8894d CS |
4581 | if (all_vrf) { |
4582 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
4583 | if (!ospf->oi_running) | |
4584 | continue; | |
996c9314 LB |
4585 | ret = show_ip_ospf_neighbor_all_common( |
4586 | vty, ospf, json, uj, use_vrf); | |
b1c3ae8c CS |
4587 | } |
4588 | ||
4589 | if (uj) { | |
4590 | vty_out(vty, "%s\n", | |
996c9314 LB |
4591 | json_object_to_json_string_ext( |
4592 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 4593 | json_object_free(json); |
b5a8894d | 4594 | } |
b1c3ae8c | 4595 | |
b5a8894d CS |
4596 | return ret; |
4597 | } | |
b1c3ae8c | 4598 | |
b5a8894d | 4599 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); |
b1c3ae8c CS |
4600 | if (ospf == NULL || !ospf->oi_running) { |
4601 | if (uj) | |
4602 | json_object_free(json); | |
b5a8894d | 4603 | return CMD_SUCCESS; |
b1c3ae8c | 4604 | } |
b5a8894d CS |
4605 | } else { |
4606 | /* Display default ospf (instance 0) info */ | |
4607 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
b1c3ae8c CS |
4608 | if (ospf == NULL || !ospf->oi_running) { |
4609 | if (uj) | |
4610 | json_object_free(json); | |
b5a8894d | 4611 | return CMD_SUCCESS; |
b1c3ae8c | 4612 | } |
b5a8894d CS |
4613 | } |
4614 | ||
b1c3ae8c CS |
4615 | if (ospf) { |
4616 | ret = show_ip_ospf_neighbor_all_common(vty, ospf, json, uj, | |
4617 | use_vrf); | |
4618 | if (uj) { | |
4619 | vty_out(vty, "%s\n", | |
996c9314 LB |
4620 | json_object_to_json_string_ext( |
4621 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c CS |
4622 | } |
4623 | } | |
4624 | ||
4625 | if (uj) | |
4626 | json_object_free(json); | |
b5a8894d CS |
4627 | |
4628 | return ret; | |
7c8ff89e DS |
4629 | } |
4630 | ||
4631 | DEFUN (show_ip_ospf_instance_neighbor_all, | |
4632 | show_ip_ospf_instance_neighbor_all_cmd, | |
6147e2c6 | 4633 | "show ip ospf (1-65535) neighbor all [json]", |
7c8ff89e DS |
4634 | SHOW_STR |
4635 | IP_STR | |
4636 | "OSPF information\n" | |
4637 | "Instance ID\n" | |
4638 | "Neighbor list\n" | |
91756b38 | 4639 | "include down status neighbor\n" |
9973d184 | 4640 | JSON_STR) |
718e3744 | 4641 | { |
d62a17ae | 4642 | int idx_number = 3; |
4643 | struct ospf *ospf; | |
d7c0a89a | 4644 | unsigned short instance = 0; |
9f049418 | 4645 | bool uj = use_json(argc, argv); |
b1c3ae8c CS |
4646 | json_object *json = NULL; |
4647 | int ret = CMD_SUCCESS; | |
7c8ff89e | 4648 | |
d62a17ae | 4649 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
ac28e4ec CS |
4650 | ospf = ospf_lookup_instance(instance); |
4651 | if (ospf == NULL) | |
4652 | return CMD_NOT_MY_INSTANCE; | |
4653 | ||
4654 | if (!ospf->oi_running) | |
d62a17ae | 4655 | return CMD_SUCCESS; |
b1c3ae8c CS |
4656 | if (uj) |
4657 | json = json_object_new_object(); | |
4658 | ||
4659 | ret = show_ip_ospf_neighbor_all_common(vty, ospf, json, uj, 0); | |
4660 | ||
4661 | if (uj) { | |
4662 | vty_out(vty, "%s\n", json_object_to_json_string_ext( | |
4663 | json, JSON_C_TO_STRING_PRETTY)); | |
4664 | json_object_free(json); | |
4665 | } | |
7c8ff89e | 4666 | |
b1c3ae8c | 4667 | return ret; |
7c8ff89e DS |
4668 | } |
4669 | ||
d62a17ae | 4670 | static int show_ip_ospf_neighbor_int_common(struct vty *vty, struct ospf *ospf, |
4671 | int arg_base, | |
4672 | struct cmd_token **argv, | |
9f049418 | 4673 | bool use_json, uint8_t use_vrf) |
d62a17ae | 4674 | { |
4675 | struct interface *ifp; | |
4676 | struct route_node *rn; | |
4677 | json_object *json = NULL; | |
91756b38 | 4678 | |
d62a17ae | 4679 | if (use_json) |
4680 | json = json_object_new_object(); | |
d62a17ae | 4681 | |
4682 | if (ospf->instance) { | |
4683 | if (use_json) | |
4684 | json_object_int_add(json, "ospfInstance", | |
4685 | ospf->instance); | |
4686 | else | |
4687 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
4688 | } | |
4689 | ||
b1c3ae8c | 4690 | ospf_show_vrf_name(ospf, vty, json, use_vrf); |
87bd50e8 | 4691 | |
a36898e7 | 4692 | ifp = if_lookup_by_name(argv[arg_base]->arg, ospf->vrf_id); |
d62a17ae | 4693 | if (!ifp) { |
4694 | if (use_json) | |
4695 | json_object_boolean_true_add(json, "noSuchIface"); | |
4696 | else | |
4697 | vty_out(vty, "No such interface.\n"); | |
4698 | return CMD_WARNING; | |
4699 | } | |
4700 | ||
4701 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { | |
4702 | struct ospf_interface *oi = rn->info; | |
4703 | ||
4704 | if (oi == NULL) | |
4705 | continue; | |
4706 | ||
4707 | show_ip_ospf_neighbor_sub(vty, oi, json, use_json); | |
4708 | } | |
4709 | ||
4710 | if (use_json) { | |
9d303b37 DL |
4711 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
4712 | json, JSON_C_TO_STRING_PRETTY)); | |
d62a17ae | 4713 | json_object_free(json); |
4714 | } else | |
4715 | vty_out(vty, "\n"); | |
4716 | ||
4717 | return CMD_SUCCESS; | |
718e3744 | 4718 | } |
4719 | ||
7c8ff89e DS |
4720 | DEFUN (show_ip_ospf_neighbor_int, |
4721 | show_ip_ospf_neighbor_int_cmd, | |
03ed9f02 | 4722 | "show ip ospf [vrf <NAME>] neighbor IFNAME [json]", |
7c8ff89e DS |
4723 | SHOW_STR |
4724 | IP_STR | |
4725 | "OSPF information\n" | |
03ed9f02 | 4726 | VRF_CMD_HELP_STR |
7c8ff89e | 4727 | "Neighbor list\n" |
91756b38 | 4728 | "Interface name\n" |
9973d184 | 4729 | JSON_STR) |
7c8ff89e | 4730 | { |
d62a17ae | 4731 | struct ospf *ospf; |
03ed9f02 PG |
4732 | int idx_ifname = 0; |
4733 | int idx_vrf = 0; | |
9f049418 | 4734 | bool uj = use_json(argc, argv); |
b5a8894d CS |
4735 | int ret = CMD_SUCCESS; |
4736 | struct interface *ifp = NULL; | |
03ed9f02 PG |
4737 | char *vrf_name = NULL; |
4738 | vrf_id_t vrf_id = VRF_DEFAULT; | |
4739 | struct vrf *vrf = NULL; | |
4740 | ||
4741 | if (argv_find(argv, argc, "vrf", &idx_vrf)) | |
4742 | vrf_name = argv[idx_vrf + 1]->arg; | |
4743 | if (vrf_name && strmatch(vrf_name, VRF_DEFAULT_NAME)) | |
4744 | vrf_name = NULL; | |
4745 | if (vrf_name) { | |
4746 | vrf = vrf_lookup_by_name(vrf_name); | |
4747 | if (vrf) | |
4748 | vrf_id = vrf->vrf_id; | |
4749 | } | |
4750 | ospf = ospf_lookup_by_vrf_id(vrf_id); | |
4751 | ||
4752 | if (!ospf || !ospf->oi_running) | |
4753 | return ret; | |
7c8ff89e | 4754 | |
b5a8894d CS |
4755 | if (!uj) |
4756 | show_ip_ospf_neighbour_header(vty); | |
7c8ff89e | 4757 | |
03ed9f02 | 4758 | argv_find(argv, argc, "IFNAME", &idx_ifname); |
b5a8894d | 4759 | |
a36898e7 | 4760 | ifp = if_lookup_by_name(argv[idx_ifname]->arg, vrf_id); |
03ed9f02 PG |
4761 | if (!ifp) |
4762 | return ret; | |
4763 | ||
4764 | ret = show_ip_ospf_neighbor_int_common(vty, ospf, idx_ifname, | |
4765 | argv, uj, 0); | |
b5a8894d | 4766 | return ret; |
7c8ff89e DS |
4767 | } |
4768 | ||
4769 | DEFUN (show_ip_ospf_instance_neighbor_int, | |
4770 | show_ip_ospf_instance_neighbor_int_cmd, | |
6147e2c6 | 4771 | "show ip ospf (1-65535) neighbor IFNAME [json]", |
7c8ff89e DS |
4772 | SHOW_STR |
4773 | IP_STR | |
4774 | "OSPF information\n" | |
4775 | "Instance ID\n" | |
4776 | "Neighbor list\n" | |
91756b38 | 4777 | "Interface name\n" |
9973d184 | 4778 | JSON_STR) |
7c8ff89e | 4779 | { |
d62a17ae | 4780 | int idx_number = 3; |
b4e84315 | 4781 | int idx_ifname = 5; |
d62a17ae | 4782 | struct ospf *ospf; |
d7c0a89a | 4783 | unsigned short instance = 0; |
9f049418 | 4784 | bool uj = use_json(argc, argv); |
7c8ff89e | 4785 | |
b5a8894d CS |
4786 | if (!uj) |
4787 | show_ip_ospf_neighbour_header(vty); | |
4788 | ||
d62a17ae | 4789 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
ac28e4ec CS |
4790 | ospf = ospf_lookup_instance(instance); |
4791 | if (ospf == NULL) | |
4792 | return CMD_NOT_MY_INSTANCE; | |
4793 | ||
4794 | if (!ospf->oi_running) | |
d62a17ae | 4795 | return CMD_SUCCESS; |
7c8ff89e | 4796 | |
b5a8894d CS |
4797 | if (!uj) |
4798 | show_ip_ospf_neighbour_header(vty); | |
4799 | ||
996c9314 LB |
4800 | return show_ip_ospf_neighbor_int_common(vty, ospf, idx_ifname, argv, uj, |
4801 | 0); | |
718e3744 | 4802 | } |
4803 | ||
d62a17ae | 4804 | static void show_ip_ospf_nbr_nbma_detail_sub(struct vty *vty, |
4805 | struct ospf_interface *oi, | |
4806 | struct ospf_nbr_nbma *nbr_nbma, | |
9f049418 | 4807 | bool use_json, json_object *json) |
d62a17ae | 4808 | { |
4809 | char timebuf[OSPF_TIME_DUMP_SIZE]; | |
4810 | json_object *json_sub = NULL; | |
718e3744 | 4811 | |
d62a17ae | 4812 | if (use_json) |
4813 | json_sub = json_object_new_object(); | |
4814 | else /* Show neighbor ID. */ | |
4815 | vty_out(vty, " Neighbor %s,", "-"); | |
4816 | ||
4817 | /* Show interface address. */ | |
4818 | if (use_json) | |
4819 | json_object_string_add(json_sub, "ifaceAddress", | |
4820 | inet_ntoa(nbr_nbma->addr)); | |
4821 | else | |
4822 | vty_out(vty, " interface address %s\n", | |
4823 | inet_ntoa(nbr_nbma->addr)); | |
4824 | ||
4825 | /* Show Area ID. */ | |
4826 | if (use_json) { | |
4827 | json_object_string_add(json_sub, "areaId", | |
4828 | ospf_area_desc_string(oi->area)); | |
4829 | json_object_string_add(json_sub, "iface", IF_NAME(oi)); | |
4830 | } else | |
4831 | vty_out(vty, " In the area %s via interface %s\n", | |
4832 | ospf_area_desc_string(oi->area), IF_NAME(oi)); | |
4833 | ||
4834 | /* Show neighbor priority and state. */ | |
4835 | if (use_json) { | |
4836 | json_object_int_add(json_sub, "nbrPriority", | |
4837 | nbr_nbma->priority); | |
4838 | json_object_string_add(json_sub, "nbrState", "down"); | |
4839 | } else | |
4840 | vty_out(vty, " Neighbor priority is %d, State is %s,", | |
4841 | nbr_nbma->priority, "Down"); | |
4842 | ||
4843 | /* Show state changes. */ | |
4844 | if (use_json) | |
4845 | json_object_int_add(json_sub, "stateChangeCounter", | |
4846 | nbr_nbma->state_change); | |
4847 | else | |
4848 | vty_out(vty, " %d state changes\n", nbr_nbma->state_change); | |
4849 | ||
4850 | /* Show PollInterval */ | |
4851 | if (use_json) | |
4852 | json_object_int_add(json_sub, "pollInterval", nbr_nbma->v_poll); | |
4853 | else | |
4854 | vty_out(vty, " Poll interval %d\n", nbr_nbma->v_poll); | |
4855 | ||
4856 | /* Show poll-interval timer. */ | |
b575a12c A |
4857 | if (nbr_nbma->t_poll) { |
4858 | if (use_json) { | |
4859 | long time_store; | |
4860 | time_store = monotime_until(&nbr_nbma->t_poll->u.sands, | |
4861 | NULL) / 1000LL; | |
4862 | json_object_int_add(json_sub, | |
4863 | "pollIntervalTimerDueMsec", | |
4864 | time_store); | |
4865 | } else | |
4866 | vty_out(vty, " Poll timer due in %s\n", | |
4867 | ospf_timer_dump(nbr_nbma->t_poll, timebuf, | |
4868 | sizeof(timebuf))); | |
4869 | } | |
d62a17ae | 4870 | |
4871 | /* Show poll-interval timer thread. */ | |
4872 | if (use_json) { | |
4873 | if (nbr_nbma->t_poll != NULL) | |
4874 | json_object_string_add(json_sub, | |
4875 | "pollIntervalTimerThread", "on"); | |
4876 | } else | |
4877 | vty_out(vty, " Thread Poll Timer %s\n", | |
4878 | nbr_nbma->t_poll != NULL ? "on" : "off"); | |
4879 | ||
4880 | if (use_json) | |
4881 | json_object_object_add(json, "noNbrId", json_sub); | |
4882 | } | |
4883 | ||
4884 | static void show_ip_ospf_neighbor_detail_sub(struct vty *vty, | |
4885 | struct ospf_interface *oi, | |
4886 | struct ospf_neighbor *nbr, | |
9f049418 | 4887 | json_object *json, bool use_json) |
d62a17ae | 4888 | { |
4889 | char timebuf[OSPF_TIME_DUMP_SIZE]; | |
4890 | json_object *json_sub = NULL; | |
4891 | ||
4892 | if (use_json) | |
4893 | json_sub = json_object_new_object(); | |
4894 | else { | |
4895 | /* Show neighbor ID. */ | |
4896 | if (nbr->state == NSM_Attempt && nbr->router_id.s_addr == 0) | |
4897 | vty_out(vty, " Neighbor %s,", "-"); | |
4898 | else | |
4899 | vty_out(vty, " Neighbor %s,", | |
4900 | inet_ntoa(nbr->router_id)); | |
4901 | } | |
4902 | ||
4903 | /* Show interface address. */ | |
4904 | if (use_json) | |
4905 | json_object_string_add(json_sub, "ifaceAddress", | |
4906 | inet_ntoa(nbr->address.u.prefix4)); | |
4907 | else | |
4908 | vty_out(vty, " interface address %s\n", | |
4909 | inet_ntoa(nbr->address.u.prefix4)); | |
4910 | ||
4911 | /* Show Area ID. */ | |
4912 | if (use_json) { | |
4913 | json_object_string_add(json_sub, "areaId", | |
4914 | ospf_area_desc_string(oi->area)); | |
4915 | json_object_string_add(json_sub, "ifaceName", oi->ifp->name); | |
4916 | } else | |
4917 | vty_out(vty, " In the area %s via interface %s\n", | |
4918 | ospf_area_desc_string(oi->area), oi->ifp->name); | |
4919 | ||
4920 | /* Show neighbor priority and state. */ | |
4921 | if (use_json) { | |
4922 | json_object_int_add(json_sub, "nbrPriority", nbr->priority); | |
4923 | json_object_string_add( | |
4924 | json_sub, "nbrState", | |
4925 | lookup_msg(ospf_nsm_state_msg, nbr->state, NULL)); | |
4926 | } else | |
4927 | vty_out(vty, " Neighbor priority is %d, State is %s,", | |
4928 | nbr->priority, | |
4929 | lookup_msg(ospf_nsm_state_msg, nbr->state, NULL)); | |
4930 | ||
4931 | /* Show state changes. */ | |
4932 | if (use_json) | |
4933 | json_object_int_add(json_sub, "stateChangeCounter", | |
4934 | nbr->state_change); | |
4935 | else | |
4936 | vty_out(vty, " %d state changes\n", nbr->state_change); | |
4937 | ||
4938 | if (nbr->ts_last_progress.tv_sec || nbr->ts_last_progress.tv_usec) { | |
4939 | struct timeval res; | |
4940 | long time_store; | |
4941 | ||
4942 | time_store = | |
4943 | monotime_since(&nbr->ts_last_progress, &res) / 1000LL; | |
4944 | if (use_json) { | |
4945 | json_object_int_add(json_sub, "lastPrgrsvChangeMsec", | |
4946 | time_store); | |
4947 | } else { | |
4948 | vty_out(vty, | |
4949 | " Most recent state change statistics:\n"); | |
4950 | vty_out(vty, " Progressive change %s ago\n", | |
4951 | ospf_timeval_dump(&res, timebuf, | |
4952 | sizeof(timebuf))); | |
4953 | } | |
4954 | } | |
4955 | ||
4956 | if (nbr->ts_last_regress.tv_sec || nbr->ts_last_regress.tv_usec) { | |
4957 | struct timeval res; | |
4958 | long time_store; | |
4959 | ||
4960 | time_store = | |
4961 | monotime_since(&nbr->ts_last_regress, &res) / 1000LL; | |
4962 | if (use_json) { | |
4963 | json_object_int_add(json_sub, | |
4964 | "lastRegressiveChangeMsec", | |
4965 | time_store); | |
4966 | if (nbr->last_regress_str) | |
4967 | json_object_string_add( | |
4968 | json_sub, "lastRegressiveChangeReason", | |
4969 | nbr->last_regress_str); | |
4970 | } else { | |
4971 | vty_out(vty, | |
4972 | " Regressive change %s ago, due to %s\n", | |
4973 | ospf_timeval_dump(&res, timebuf, | |
4974 | sizeof(timebuf)), | |
4975 | (nbr->last_regress_str ? nbr->last_regress_str | |
4976 | : "??")); | |
4977 | } | |
4978 | } | |
4979 | ||
4980 | /* Show Designated Rotuer ID. */ | |
4981 | if (use_json) | |
4982 | json_object_string_add(json_sub, "routerDesignatedId", | |
4983 | inet_ntoa(nbr->d_router)); | |
4984 | else | |
4985 | vty_out(vty, " DR is %s,", inet_ntoa(nbr->d_router)); | |
4986 | ||
4987 | /* Show Backup Designated Rotuer ID. */ | |
4988 | if (use_json) | |
4989 | json_object_string_add(json_sub, "routerDesignatedBackupId", | |
4990 | inet_ntoa(nbr->bd_router)); | |
4991 | else | |
4992 | vty_out(vty, " BDR is %s\n", inet_ntoa(nbr->bd_router)); | |
4993 | ||
4994 | /* Show options. */ | |
4995 | if (use_json) { | |
4996 | json_object_int_add(json_sub, "optionsCounter", nbr->options); | |
4997 | json_object_string_add(json_sub, "optionsList", | |
4998 | ospf_options_dump(nbr->options)); | |
4999 | } else | |
5000 | vty_out(vty, " Options %d %s\n", nbr->options, | |
5001 | ospf_options_dump(nbr->options)); | |
5002 | ||
5003 | /* Show Router Dead interval timer. */ | |
5004 | if (use_json) { | |
5005 | if (nbr->t_inactivity) { | |
5006 | long time_store; | |
5007 | time_store = monotime_until(&nbr->t_inactivity->u.sands, | |
5008 | NULL) | |
5009 | / 1000LL; | |
5010 | json_object_int_add(json_sub, | |
5011 | "routerDeadIntervalTimerDueMsec", | |
5012 | time_store); | |
5013 | } else | |
5014 | json_object_int_add( | |
5015 | json_sub, "routerDeadIntervalTimerDueMsec", -1); | |
5016 | } else | |
5017 | vty_out(vty, " Dead timer due in %s\n", | |
5018 | ospf_timer_dump(nbr->t_inactivity, timebuf, | |
5019 | sizeof(timebuf))); | |
5020 | ||
5021 | /* Show Database Summary list. */ | |
5022 | if (use_json) | |
5023 | json_object_int_add(json_sub, "databaseSummaryListCounter", | |
5024 | ospf_db_summary_count(nbr)); | |
5025 | else | |
5026 | vty_out(vty, " Database Summary List %d\n", | |
5027 | ospf_db_summary_count(nbr)); | |
5028 | ||
5029 | /* Show Link State Request list. */ | |
5030 | if (use_json) | |
5031 | json_object_int_add(json_sub, "linkStateRequestListCounter", | |
5032 | ospf_ls_request_count(nbr)); | |
5033 | else | |
5034 | vty_out(vty, " Link State Request List %ld\n", | |
5035 | ospf_ls_request_count(nbr)); | |
5036 | ||
5037 | /* Show Link State Retransmission list. */ | |
5038 | if (use_json) | |
5039 | json_object_int_add(json_sub, | |
5040 | "linkStateRetransmissionListCounter", | |
5041 | ospf_ls_retransmit_count(nbr)); | |
5042 | else | |
5043 | vty_out(vty, " Link State Retransmission List %ld\n", | |
5044 | ospf_ls_retransmit_count(nbr)); | |
5045 | ||
5046 | /* Show inactivity timer thread. */ | |
5047 | if (use_json) { | |
5048 | if (nbr->t_inactivity != NULL) | |
5049 | json_object_string_add(json_sub, | |
5050 | "threadInactivityTimer", "on"); | |
5051 | } else | |
5052 | vty_out(vty, " Thread Inactivity Timer %s\n", | |
5053 | nbr->t_inactivity != NULL ? "on" : "off"); | |
5054 | ||
5055 | /* Show Database Description retransmission thread. */ | |
5056 | if (use_json) { | |
5057 | if (nbr->t_db_desc != NULL) | |
5058 | json_object_string_add( | |
5059 | json_sub, | |
5060 | "threadDatabaseDescriptionRetransmission", | |
5061 | "on"); | |
5062 | } else | |
5063 | vty_out(vty, | |
5064 | " Thread Database Description Retransmision %s\n", | |
5065 | nbr->t_db_desc != NULL ? "on" : "off"); | |
5066 | ||
5067 | /* Show Link State Request Retransmission thread. */ | |
5068 | if (use_json) { | |
5069 | if (nbr->t_ls_req != NULL) | |
5070 | json_object_string_add( | |
5071 | json_sub, | |
5072 | "threadLinkStateRequestRetransmission", "on"); | |
5073 | } else | |
5074 | vty_out(vty, | |
5075 | " Thread Link State Request Retransmission %s\n", | |
5076 | nbr->t_ls_req != NULL ? "on" : "off"); | |
5077 | ||
5078 | /* Show Link State Update Retransmission thread. */ | |
5079 | if (use_json) { | |
5080 | if (nbr->t_ls_upd != NULL) | |
5081 | json_object_string_add( | |
5082 | json_sub, "threadLinkStateUpdateRetransmission", | |
5083 | "on"); | |
5084 | } else | |
5085 | vty_out(vty, | |
5086 | " Thread Link State Update Retransmission %s\n\n", | |
5087 | nbr->t_ls_upd != NULL ? "on" : "off"); | |
5088 | ||
5089 | if (use_json) { | |
5090 | if (nbr->state == NSM_Attempt && nbr->router_id.s_addr == 0) | |
5091 | json_object_object_add(json, "noNbrId", json_sub); | |
5092 | else | |
5093 | json_object_object_add(json, inet_ntoa(nbr->router_id), | |
5094 | json_sub); | |
5095 | } | |
5096 | ||
5097 | ospf_bfd_show_info(vty, nbr->bfd_info, json, use_json, 0); | |
5098 | } | |
5099 | ||
5100 | static int show_ip_ospf_neighbor_id_common(struct vty *vty, struct ospf *ospf, | |
986b87cb | 5101 | struct in_addr *router_id, |
9f049418 | 5102 | bool use_json, uint8_t use_vrf) |
d62a17ae | 5103 | { |
5104 | struct listnode *node; | |
5105 | struct ospf_neighbor *nbr; | |
5106 | struct ospf_interface *oi; | |
d62a17ae | 5107 | json_object *json = NULL; |
5108 | ||
5109 | if (use_json) | |
5110 | json = json_object_new_object(); | |
5111 | ||
5112 | if (ospf->instance) { | |
5113 | if (use_json) | |
5114 | json_object_int_add(json, "ospfInstance", | |
5115 | ospf->instance); | |
5116 | else | |
5117 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
5118 | } | |
5119 | ||
b1c3ae8c | 5120 | ospf_show_vrf_name(ospf, vty, json, use_vrf); |
87bd50e8 | 5121 | |
d62a17ae | 5122 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) { |
986b87cb | 5123 | if ((nbr = ospf_nbr_lookup_by_routerid(oi->nbrs, router_id))) { |
b1c3ae8c CS |
5124 | show_ip_ospf_neighbor_detail_sub(vty, oi, nbr, json, |
5125 | use_json); | |
d62a17ae | 5126 | } |
5127 | } | |
5128 | ||
5129 | if (use_json) { | |
9d303b37 DL |
5130 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
5131 | json, JSON_C_TO_STRING_PRETTY)); | |
d62a17ae | 5132 | json_object_free(json); |
5133 | } else | |
5134 | vty_out(vty, "\n"); | |
5135 | ||
5136 | return CMD_SUCCESS; | |
718e3744 | 5137 | } |
5138 | ||
986b87cb | 5139 | DEFPY (show_ip_ospf_neighbor_id, |
7c8ff89e | 5140 | show_ip_ospf_neighbor_id_cmd, |
986b87cb | 5141 | "show ip ospf neighbor A.B.C.D$router_id [json$json]", |
718e3744 | 5142 | SHOW_STR |
5143 | IP_STR | |
5144 | "OSPF information\n" | |
5145 | "Neighbor list\n" | |
3ac237f8 | 5146 | "Neighbor ID\n" |
9973d184 | 5147 | JSON_STR) |
718e3744 | 5148 | { |
d62a17ae | 5149 | struct ospf *ospf; |
986b87cb | 5150 | struct listnode *node; |
b5a8894d | 5151 | int ret = CMD_SUCCESS; |
7c8ff89e | 5152 | |
b5a8894d CS |
5153 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { |
5154 | if (!ospf->oi_running) | |
5155 | continue; | |
986b87cb RW |
5156 | ret = show_ip_ospf_neighbor_id_common(vty, ospf, &router_id, |
5157 | !!json, 0); | |
b5a8894d | 5158 | } |
7c8ff89e | 5159 | |
b5a8894d | 5160 | return ret; |
7c8ff89e DS |
5161 | } |
5162 | ||
986b87cb | 5163 | DEFPY (show_ip_ospf_instance_neighbor_id, |
7c8ff89e | 5164 | show_ip_ospf_instance_neighbor_id_cmd, |
986b87cb | 5165 | "show ip ospf (1-65535)$instance neighbor A.B.C.D$router_id [json$json]", |
7c8ff89e DS |
5166 | SHOW_STR |
5167 | IP_STR | |
5168 | "OSPF information\n" | |
5169 | "Instance ID\n" | |
5170 | "Neighbor list\n" | |
3ac237f8 | 5171 | "Neighbor ID\n" |
9973d184 | 5172 | JSON_STR) |
7c8ff89e | 5173 | { |
d62a17ae | 5174 | struct ospf *ospf; |
7c8ff89e | 5175 | |
ac28e4ec CS |
5176 | ospf = ospf_lookup_instance(instance); |
5177 | if (ospf == NULL) | |
5178 | return CMD_NOT_MY_INSTANCE; | |
5179 | ||
5180 | if (!ospf->oi_running) | |
d62a17ae | 5181 | return CMD_SUCCESS; |
7c8ff89e | 5182 | |
986b87cb RW |
5183 | return show_ip_ospf_neighbor_id_common(vty, ospf, &router_id, !!json, |
5184 | 0); | |
7c8ff89e DS |
5185 | } |
5186 | ||
d62a17ae | 5187 | static int show_ip_ospf_neighbor_detail_common(struct vty *vty, |
5188 | struct ospf *ospf, | |
9f049418 | 5189 | json_object *json, bool use_json, |
d7c0a89a | 5190 | uint8_t use_vrf) |
d62a17ae | 5191 | { |
5192 | struct ospf_interface *oi; | |
5193 | struct listnode *node; | |
b1c3ae8c | 5194 | json_object *json_vrf = NULL; |
d62a17ae | 5195 | |
b1c3ae8c CS |
5196 | if (use_json) { |
5197 | if (use_vrf) | |
5198 | json_vrf = json_object_new_object(); | |
5199 | else | |
5200 | json_vrf = json; | |
5201 | } | |
d62a17ae | 5202 | if (ospf->instance) { |
5203 | if (use_json) | |
b1c3ae8c | 5204 | json_object_int_add(json_vrf, "ospfInstance", |
d62a17ae | 5205 | ospf->instance); |
5206 | else | |
5207 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
5208 | } | |
5209 | ||
b1c3ae8c | 5210 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); |
87bd50e8 | 5211 | |
d62a17ae | 5212 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) { |
5213 | struct route_node *rn; | |
5214 | struct ospf_neighbor *nbr; | |
5215 | ||
5216 | for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) { | |
5217 | if ((nbr = rn->info)) { | |
5218 | if (nbr != oi->nbr_self) { | |
5219 | if (nbr->state != NSM_Down) { | |
5220 | show_ip_ospf_neighbor_detail_sub( | |
b1c3ae8c CS |
5221 | vty, oi, nbr, json_vrf, |
5222 | use_json); | |
d62a17ae | 5223 | } |
5224 | } | |
5225 | } | |
5226 | } | |
5227 | } | |
5228 | ||
5229 | if (use_json) { | |
b1c3ae8c CS |
5230 | if (use_vrf) { |
5231 | if (ospf->vrf_id == VRF_DEFAULT) | |
5232 | json_object_object_add(json, "default", | |
5233 | json_vrf); | |
5234 | else | |
5235 | json_object_object_add(json, ospf->name, | |
5236 | json_vrf); | |
5237 | } | |
d62a17ae | 5238 | } else |
5239 | vty_out(vty, "\n"); | |
5240 | ||
5241 | return CMD_SUCCESS; | |
718e3744 | 5242 | } |
5243 | ||
7c8ff89e DS |
5244 | DEFUN (show_ip_ospf_neighbor_detail, |
5245 | show_ip_ospf_neighbor_detail_cmd, | |
b5a8894d | 5246 | "show ip ospf [vrf <NAME|all>] neighbor detail [json]", |
718e3744 | 5247 | SHOW_STR |
5248 | IP_STR | |
5249 | "OSPF information\n" | |
b5a8894d CS |
5250 | VRF_CMD_HELP_STR |
5251 | "All VRFs\n" | |
718e3744 | 5252 | "Neighbor list\n" |
3ac237f8 | 5253 | "detail of all neighbors\n" |
9973d184 | 5254 | JSON_STR) |
718e3744 | 5255 | { |
d62a17ae | 5256 | struct ospf *ospf; |
9f049418 | 5257 | bool uj = use_json(argc, argv); |
b5a8894d CS |
5258 | struct listnode *node = NULL; |
5259 | char *vrf_name = NULL; | |
2951a7a4 | 5260 | bool all_vrf = false; |
b5a8894d CS |
5261 | int ret = CMD_SUCCESS; |
5262 | int inst = 0; | |
5263 | int idx_vrf = 0; | |
d7c0a89a | 5264 | uint8_t use_vrf = 0; |
b1c3ae8c | 5265 | json_object *json = NULL; |
7c8ff89e | 5266 | |
43b8d1d8 | 5267 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
7c8ff89e | 5268 | |
b1c3ae8c CS |
5269 | if (uj) |
5270 | json = json_object_new_object(); | |
5271 | ||
b5a8894d CS |
5272 | /* vrf input is provided could be all or specific vrf*/ |
5273 | if (vrf_name) { | |
b1c3ae8c | 5274 | use_vrf = 1; |
b5a8894d CS |
5275 | if (all_vrf) { |
5276 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
5277 | if (!ospf->oi_running) | |
5278 | continue; | |
996c9314 LB |
5279 | ret = show_ip_ospf_neighbor_detail_common( |
5280 | vty, ospf, json, uj, use_vrf); | |
b1c3ae8c CS |
5281 | } |
5282 | if (uj) { | |
5283 | vty_out(vty, "%s\n", | |
996c9314 LB |
5284 | json_object_to_json_string_ext( |
5285 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c | 5286 | json_object_free(json); |
b5a8894d | 5287 | } |
b1c3ae8c | 5288 | |
b5a8894d CS |
5289 | return ret; |
5290 | } | |
5291 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
b1c3ae8c CS |
5292 | if (ospf == NULL || !ospf->oi_running) { |
5293 | if (uj) | |
5294 | json_object_free(json); | |
b5a8894d | 5295 | return CMD_SUCCESS; |
b1c3ae8c | 5296 | } |
b5a8894d CS |
5297 | } else { |
5298 | /* Display default ospf (instance 0) info */ | |
5299 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
b1c3ae8c CS |
5300 | if (ospf == NULL || !ospf->oi_running) { |
5301 | if (uj) | |
5302 | json_object_free(json); | |
b5a8894d | 5303 | return CMD_SUCCESS; |
b1c3ae8c | 5304 | } |
b5a8894d CS |
5305 | } |
5306 | ||
b1c3ae8c CS |
5307 | if (ospf) { |
5308 | ret = show_ip_ospf_neighbor_detail_common(vty, ospf, json, uj, | |
5309 | use_vrf); | |
5310 | if (uj) { | |
5311 | vty_out(vty, "%s\n", | |
996c9314 LB |
5312 | json_object_to_json_string_ext( |
5313 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c CS |
5314 | } |
5315 | } | |
5316 | ||
5317 | if (uj) | |
5318 | json_object_free(json); | |
b5a8894d CS |
5319 | |
5320 | return ret; | |
7c8ff89e DS |
5321 | } |
5322 | ||
5323 | DEFUN (show_ip_ospf_instance_neighbor_detail, | |
5324 | show_ip_ospf_instance_neighbor_detail_cmd, | |
6147e2c6 | 5325 | "show ip ospf (1-65535) neighbor detail [json]", |
7c8ff89e DS |
5326 | SHOW_STR |
5327 | IP_STR | |
5328 | "OSPF information\n" | |
5329 | "Instance ID\n" | |
5330 | "Neighbor list\n" | |
3ac237f8 | 5331 | "detail of all neighbors\n" |
9973d184 | 5332 | JSON_STR) |
7c8ff89e | 5333 | { |
d62a17ae | 5334 | int idx_number = 3; |
5335 | struct ospf *ospf; | |
d7c0a89a | 5336 | unsigned short instance = 0; |
9f049418 | 5337 | bool uj = use_json(argc, argv); |
b1c3ae8c CS |
5338 | json_object *json = NULL; |
5339 | int ret = CMD_SUCCESS; | |
7c8ff89e | 5340 | |
d62a17ae | 5341 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
ac28e4ec CS |
5342 | ospf = ospf_lookup_instance(instance); |
5343 | if (ospf == NULL) | |
5344 | return CMD_NOT_MY_INSTANCE; | |
5345 | ||
5346 | if (!ospf->oi_running) | |
d62a17ae | 5347 | return CMD_SUCCESS; |
7c8ff89e | 5348 | |
b1c3ae8c CS |
5349 | if (uj) |
5350 | json = json_object_new_object(); | |
5351 | ||
5352 | ret = show_ip_ospf_neighbor_detail_common(vty, ospf, json, uj, 0); | |
5353 | ||
5354 | if (uj) { | |
5355 | vty_out(vty, "%s\n", json_object_to_json_string_ext( | |
5356 | json, JSON_C_TO_STRING_PRETTY)); | |
5357 | json_object_free(json); | |
5358 | } | |
5359 | ||
5360 | return ret; | |
7c8ff89e DS |
5361 | } |
5362 | ||
d62a17ae | 5363 | static int show_ip_ospf_neighbor_detail_all_common(struct vty *vty, |
5364 | struct ospf *ospf, | |
b1c3ae8c | 5365 | json_object *json, |
9f049418 | 5366 | bool use_json, |
d7c0a89a | 5367 | uint8_t use_vrf) |
d62a17ae | 5368 | { |
5369 | struct listnode *node; | |
5370 | struct ospf_interface *oi; | |
b1c3ae8c | 5371 | json_object *json_vrf = NULL; |
718e3744 | 5372 | |
b1c3ae8c CS |
5373 | if (use_json) { |
5374 | if (use_vrf) | |
5375 | json_vrf = json_object_new_object(); | |
5376 | else | |
5377 | json_vrf = json; | |
5378 | } | |
d62a17ae | 5379 | |
5380 | if (ospf->instance) { | |
5381 | if (use_json) | |
5382 | json_object_int_add(json, "ospfInstance", | |
5383 | ospf->instance); | |
5384 | else | |
5385 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
5386 | } | |
5387 | ||
b1c3ae8c | 5388 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); |
87bd50e8 | 5389 | |
d62a17ae | 5390 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) { |
5391 | struct route_node *rn; | |
5392 | struct ospf_neighbor *nbr; | |
5393 | struct ospf_nbr_nbma *nbr_nbma; | |
5394 | ||
5395 | for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) | |
5396 | if ((nbr = rn->info)) | |
5397 | if (nbr != oi->nbr_self) | |
5398 | if (nbr->state != NSM_Down) | |
5399 | show_ip_ospf_neighbor_detail_sub( | |
5400 | vty, oi, rn->info, | |
b1c3ae8c | 5401 | json_vrf, use_json); |
d62a17ae | 5402 | |
5403 | if (oi->type == OSPF_IFTYPE_NBMA) { | |
5404 | struct listnode *nd; | |
5405 | ||
5406 | for (ALL_LIST_ELEMENTS_RO(oi->nbr_nbma, nd, nbr_nbma)) { | |
5407 | if (nbr_nbma->nbr == NULL | |
5408 | || nbr_nbma->nbr->state == NSM_Down) | |
5409 | show_ip_ospf_nbr_nbma_detail_sub( | |
5410 | vty, oi, nbr_nbma, use_json, | |
b1c3ae8c | 5411 | json_vrf); |
d62a17ae | 5412 | } |
5413 | } | |
5414 | } | |
5415 | ||
5416 | if (use_json) { | |
b1c3ae8c CS |
5417 | if (use_vrf) { |
5418 | if (ospf->vrf_id == VRF_DEFAULT) | |
5419 | json_object_object_add(json, "default", | |
5420 | json_vrf); | |
5421 | else | |
5422 | json_object_object_add(json, ospf->name, | |
5423 | json_vrf); | |
5424 | } | |
d62a17ae | 5425 | } else { |
5426 | vty_out(vty, "\n"); | |
5427 | } | |
5428 | ||
5429 | return CMD_SUCCESS; | |
718e3744 | 5430 | } |
5431 | ||
7c8ff89e DS |
5432 | DEFUN (show_ip_ospf_neighbor_detail_all, |
5433 | show_ip_ospf_neighbor_detail_all_cmd, | |
b5a8894d | 5434 | "show ip ospf [vrf <NAME|all>] neighbor detail all [json]", |
718e3744 | 5435 | SHOW_STR |
5436 | IP_STR | |
5437 | "OSPF information\n" | |
b5a8894d CS |
5438 | VRF_CMD_HELP_STR |
5439 | "All VRFs\n" | |
718e3744 | 5440 | "Neighbor list\n" |
7c8ff89e | 5441 | "detail of all neighbors\n" |
3ac237f8 | 5442 | "include down status neighbor\n" |
9973d184 | 5443 | JSON_STR) |
718e3744 | 5444 | { |
d62a17ae | 5445 | struct ospf *ospf; |
9f049418 | 5446 | bool uj = use_json(argc, argv); |
b5a8894d CS |
5447 | struct listnode *node = NULL; |
5448 | char *vrf_name = NULL; | |
2951a7a4 | 5449 | bool all_vrf = false; |
b5a8894d CS |
5450 | int ret = CMD_SUCCESS; |
5451 | int inst = 0; | |
5452 | int idx_vrf = 0; | |
d7c0a89a | 5453 | uint8_t use_vrf = 0; |
b1c3ae8c | 5454 | json_object *json = NULL; |
7c8ff89e | 5455 | |
43b8d1d8 | 5456 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
7c8ff89e | 5457 | |
b1c3ae8c CS |
5458 | if (uj) |
5459 | json = json_object_new_object(); | |
5460 | ||
b5a8894d CS |
5461 | /* vrf input is provided could be all or specific vrf*/ |
5462 | if (vrf_name) { | |
b1c3ae8c | 5463 | use_vrf = 1; |
b5a8894d CS |
5464 | if (all_vrf) { |
5465 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
5466 | if (!ospf->oi_running) | |
5467 | continue; | |
996c9314 LB |
5468 | ret = show_ip_ospf_neighbor_detail_all_common( |
5469 | vty, ospf, json, uj, use_vrf); | |
b5a8894d | 5470 | } |
b1c3ae8c CS |
5471 | |
5472 | if (uj) { | |
5473 | vty_out(vty, "%s\n", | |
996c9314 LB |
5474 | json_object_to_json_string_ext( |
5475 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c CS |
5476 | json_object_free(json); |
5477 | } | |
5478 | ||
b5a8894d CS |
5479 | return ret; |
5480 | } | |
5481 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
b1c3ae8c CS |
5482 | if (ospf == NULL || !ospf->oi_running) { |
5483 | if (uj) | |
5484 | json_object_free(json); | |
b5a8894d | 5485 | return CMD_SUCCESS; |
b1c3ae8c | 5486 | } |
b5a8894d CS |
5487 | } else { |
5488 | /* Display default ospf (instance 0) info */ | |
5489 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
b1c3ae8c CS |
5490 | if (ospf == NULL || !ospf->oi_running) { |
5491 | if (uj) | |
5492 | json_object_free(json); | |
b5a8894d | 5493 | return CMD_SUCCESS; |
b1c3ae8c | 5494 | } |
b5a8894d CS |
5495 | } |
5496 | ||
b1c3ae8c CS |
5497 | if (ospf) { |
5498 | ret = show_ip_ospf_neighbor_detail_all_common(vty, ospf, json, | |
5499 | uj, use_vrf); | |
5500 | if (uj) { | |
5501 | vty_out(vty, "%s\n", | |
996c9314 LB |
5502 | json_object_to_json_string_ext( |
5503 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c CS |
5504 | } |
5505 | } | |
5506 | ||
5507 | if (uj) | |
5508 | json_object_free(json); | |
b5a8894d CS |
5509 | |
5510 | return ret; | |
7c8ff89e DS |
5511 | } |
5512 | ||
5513 | DEFUN (show_ip_ospf_instance_neighbor_detail_all, | |
5514 | show_ip_ospf_instance_neighbor_detail_all_cmd, | |
6147e2c6 | 5515 | "show ip ospf (1-65535) neighbor detail all [json]", |
7c8ff89e DS |
5516 | SHOW_STR |
5517 | IP_STR | |
5518 | "OSPF information\n" | |
5519 | "Instance ID\n" | |
5520 | "Neighbor list\n" | |
5521 | "detail of all neighbors\n" | |
3ac237f8 | 5522 | "include down status neighbor\n" |
9973d184 | 5523 | JSON_STR) |
7c8ff89e | 5524 | { |
d62a17ae | 5525 | int idx_number = 3; |
5526 | struct ospf *ospf; | |
d7c0a89a | 5527 | unsigned short instance = 0; |
9f049418 | 5528 | bool uj = use_json(argc, argv); |
b1c3ae8c CS |
5529 | json_object *json = NULL; |
5530 | int ret = CMD_SUCCESS; | |
7c8ff89e | 5531 | |
d62a17ae | 5532 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
ac28e4ec CS |
5533 | ospf = ospf_lookup_instance(instance); |
5534 | if (ospf == NULL) | |
5535 | return CMD_NOT_MY_INSTANCE; | |
5536 | ||
5537 | if (!ospf->oi_running) | |
d62a17ae | 5538 | return CMD_SUCCESS; |
7c8ff89e | 5539 | |
b1c3ae8c CS |
5540 | if (uj) |
5541 | json = json_object_new_object(); | |
5542 | ||
5543 | ret = show_ip_ospf_neighbor_detail_all_common(vty, ospf, json, uj, 0); | |
5544 | ||
5545 | if (uj) { | |
996c9314 LB |
5546 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
5547 | json, JSON_C_TO_STRING_PRETTY)); | |
b1c3ae8c CS |
5548 | json_object_free(json); |
5549 | } | |
5550 | ||
5551 | return ret; | |
7c8ff89e DS |
5552 | } |
5553 | ||
d62a17ae | 5554 | static int show_ip_ospf_neighbor_int_detail_common(struct vty *vty, |
5555 | struct ospf *ospf, | |
5556 | int arg_base, | |
5557 | struct cmd_token **argv, | |
9f049418 | 5558 | bool use_json) |
d62a17ae | 5559 | { |
5560 | struct ospf_interface *oi; | |
5561 | struct interface *ifp; | |
5562 | struct route_node *rn, *nrn; | |
5563 | struct ospf_neighbor *nbr; | |
5564 | json_object *json = NULL; | |
718e3744 | 5565 | |
d62a17ae | 5566 | if (use_json) |
5567 | json = json_object_new_object(); | |
5568 | ||
5569 | if (ospf->instance) { | |
5570 | if (use_json) | |
5571 | json_object_int_add(json, "ospfInstance", | |
5572 | ospf->instance); | |
5573 | else | |
5574 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
5575 | } | |
5576 | ||
a36898e7 | 5577 | ifp = if_lookup_by_name(argv[arg_base]->arg, ospf->vrf_id); |
d62a17ae | 5578 | if (!ifp) { |
5579 | if (!use_json) | |
5580 | vty_out(vty, "No such interface.\n"); | |
16307668 RW |
5581 | else { |
5582 | vty_out(vty, "{}\n"); | |
5583 | json_object_free(json); | |
5584 | } | |
d62a17ae | 5585 | return CMD_WARNING; |
5586 | } | |
5587 | ||
5588 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { | |
5589 | if ((oi = rn->info)) { | |
5590 | for (nrn = route_top(oi->nbrs); nrn; | |
5591 | nrn = route_next(nrn)) { | |
5592 | if ((nbr = nrn->info)) { | |
5593 | if (nbr != oi->nbr_self) { | |
5594 | if (nbr->state != NSM_Down) | |
5595 | show_ip_ospf_neighbor_detail_sub( | |
5596 | vty, oi, nbr, | |
b1c3ae8c | 5597 | json, use_json); |
d62a17ae | 5598 | } |
5599 | } | |
5600 | } | |
5601 | } | |
5602 | } | |
5603 | ||
5604 | if (use_json) { | |
9d303b37 DL |
5605 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
5606 | json, JSON_C_TO_STRING_PRETTY)); | |
d62a17ae | 5607 | json_object_free(json); |
5608 | } else | |
5609 | vty_out(vty, "\n"); | |
5610 | ||
5611 | return CMD_SUCCESS; | |
718e3744 | 5612 | } |
5613 | ||
7c8ff89e DS |
5614 | DEFUN (show_ip_ospf_neighbor_int_detail, |
5615 | show_ip_ospf_neighbor_int_detail_cmd, | |
b162fa78 | 5616 | "show ip ospf neighbor IFNAME detail [json]", |
7c8ff89e DS |
5617 | SHOW_STR |
5618 | IP_STR | |
5619 | "OSPF information\n" | |
5620 | "Neighbor list\n" | |
5621 | "Interface name\n" | |
3ac237f8 | 5622 | "detail of all neighbors\n" |
9973d184 | 5623 | JSON_STR) |
7c8ff89e | 5624 | { |
d62a17ae | 5625 | struct ospf *ospf; |
9f049418 | 5626 | bool uj = use_json(argc, argv); |
b5a8894d CS |
5627 | struct listnode *node = NULL; |
5628 | int ret = CMD_SUCCESS; | |
2951a7a4 | 5629 | bool ospf_output = false; |
7c8ff89e | 5630 | |
b5a8894d CS |
5631 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { |
5632 | if (!ospf->oi_running) | |
5633 | continue; | |
2951a7a4 | 5634 | ospf_output = true; |
b5a8894d CS |
5635 | ret = show_ip_ospf_neighbor_int_detail_common(vty, ospf, 0, |
5636 | argv, uj); | |
5637 | } | |
7c8ff89e | 5638 | |
9f049418 DS |
5639 | if (!ospf_output) |
5640 | vty_out(vty, "%% OSPF instance not found\n"); | |
5641 | ||
b5a8894d | 5642 | return ret; |
7c8ff89e DS |
5643 | } |
5644 | ||
5645 | DEFUN (show_ip_ospf_instance_neighbor_int_detail, | |
5646 | show_ip_ospf_instance_neighbor_int_detail_cmd, | |
6147e2c6 | 5647 | "show ip ospf (1-65535) neighbor IFNAME detail [json]", |
7c8ff89e DS |
5648 | SHOW_STR |
5649 | IP_STR | |
5650 | "OSPF information\n" | |
5651 | "Instance ID\n" | |
5652 | "Neighbor list\n" | |
5653 | "Interface name\n" | |
3ac237f8 | 5654 | "detail of all neighbors\n" |
9973d184 | 5655 | JSON_STR) |
7c8ff89e | 5656 | { |
d62a17ae | 5657 | int idx_number = 3; |
b4e84315 | 5658 | int idx_ifname = 5; |
d62a17ae | 5659 | struct ospf *ospf; |
d7c0a89a | 5660 | unsigned short instance = 0; |
9f049418 | 5661 | bool uj = use_json(argc, argv); |
7c8ff89e | 5662 | |
d62a17ae | 5663 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
ac28e4ec CS |
5664 | ospf = ospf_lookup_instance(instance); |
5665 | if (ospf == NULL) | |
5666 | return CMD_NOT_MY_INSTANCE; | |
5667 | ||
5668 | if (!ospf->oi_running) | |
d62a17ae | 5669 | return CMD_SUCCESS; |
7c8ff89e | 5670 | |
996c9314 LB |
5671 | return show_ip_ospf_neighbor_int_detail_common(vty, ospf, idx_ifname, |
5672 | argv, uj); | |
7c8ff89e | 5673 | } |
6b0655a2 | 5674 | |
718e3744 | 5675 | /* Show functions */ |
d62a17ae | 5676 | static int show_lsa_summary(struct vty *vty, struct ospf_lsa *lsa, int self) |
5677 | { | |
5678 | struct router_lsa *rl; | |
5679 | struct summary_lsa *sl; | |
5680 | struct as_external_lsa *asel; | |
5681 | struct prefix_ipv4 p; | |
5682 | ||
5683 | if (lsa != NULL) | |
5684 | /* If self option is set, check LSA self flag. */ | |
5685 | if (self == 0 || IS_LSA_SELF(lsa)) { | |
5686 | /* LSA common part show. */ | |
5687 | vty_out(vty, "%-15s ", inet_ntoa(lsa->data->id)); | |
5688 | vty_out(vty, "%-15s %4d 0x%08lx 0x%04x", | |
5689 | inet_ntoa(lsa->data->adv_router), LS_AGE(lsa), | |
d7c0a89a | 5690 | (unsigned long)ntohl(lsa->data->ls_seqnum), |
d62a17ae | 5691 | ntohs(lsa->data->checksum)); |
5692 | /* LSA specific part show. */ | |
5693 | switch (lsa->data->type) { | |
5694 | case OSPF_ROUTER_LSA: | |
5695 | rl = (struct router_lsa *)lsa->data; | |
5696 | vty_out(vty, " %-d", ntohs(rl->links)); | |
5697 | break; | |
5698 | case OSPF_SUMMARY_LSA: | |
5699 | sl = (struct summary_lsa *)lsa->data; | |
5700 | ||
5701 | p.family = AF_INET; | |
5702 | p.prefix = sl->header.id; | |
5703 | p.prefixlen = ip_masklen(sl->mask); | |
5704 | apply_mask_ipv4(&p); | |
5705 | ||
5706 | vty_out(vty, " %s/%d", inet_ntoa(p.prefix), | |
5707 | p.prefixlen); | |
5708 | break; | |
5709 | case OSPF_AS_EXTERNAL_LSA: | |
5710 | case OSPF_AS_NSSA_LSA: | |
5711 | asel = (struct as_external_lsa *)lsa->data; | |
5712 | ||
5713 | p.family = AF_INET; | |
5714 | p.prefix = asel->header.id; | |
5715 | p.prefixlen = ip_masklen(asel->mask); | |
5716 | apply_mask_ipv4(&p); | |
5717 | ||
5718 | vty_out(vty, " %s %s/%d [0x%lx]", | |
5719 | IS_EXTERNAL_METRIC(asel->e[0].tos) | |
5720 | ? "E2" | |
5721 | : "E1", | |
5722 | inet_ntoa(p.prefix), p.prefixlen, | |
d7c0a89a QY |
5723 | (unsigned long)ntohl( |
5724 | asel->e[0].route_tag)); | |
d62a17ae | 5725 | break; |
5726 | case OSPF_NETWORK_LSA: | |
5727 | case OSPF_ASBR_SUMMARY_LSA: | |
5728 | case OSPF_OPAQUE_LINK_LSA: | |
5729 | case OSPF_OPAQUE_AREA_LSA: | |
5730 | case OSPF_OPAQUE_AS_LSA: | |
5731 | default: | |
5732 | break; | |
5733 | } | |
5734 | vty_out(vty, "\n"); | |
5735 | } | |
718e3744 | 5736 | |
d62a17ae | 5737 | return 0; |
5738 | } | |
5739 | ||
5740 | static const char *show_database_desc[] = { | |
5741 | "unknown", | |
5742 | "Router Link States", | |
5743 | "Net Link States", | |
5744 | "Summary Link States", | |
5745 | "ASBR-Summary Link States", | |
5746 | "AS External Link States", | |
5747 | "Group Membership LSA", | |
5748 | "NSSA-external Link States", | |
5749 | "Type-8 LSA", | |
5750 | "Link-Local Opaque-LSA", | |
5751 | "Area-Local Opaque-LSA", | |
5752 | "AS-external Opaque-LSA", | |
718e3744 | 5753 | }; |
5754 | ||
d62a17ae | 5755 | static const char *show_database_header[] = { |
5756 | "", | |
5757 | "Link ID ADV Router Age Seq# CkSum Link count", | |
5758 | "Link ID ADV Router Age Seq# CkSum", | |
5759 | "Link ID ADV Router Age Seq# CkSum Route", | |
5760 | "Link ID ADV Router Age Seq# CkSum", | |
5761 | "Link ID ADV Router Age Seq# CkSum Route", | |
5762 | " --- header for Group Member ----", | |
5763 | "Link ID ADV Router Age Seq# CkSum Route", | |
5764 | " --- type-8 ---", | |
5765 | "Opaque-Type/Id ADV Router Age Seq# CkSum", | |
5766 | "Opaque-Type/Id ADV Router Age Seq# CkSum", | |
5767 | "Opaque-Type/Id ADV Router Age Seq# CkSum", | |
718e3744 | 5768 | }; |
5769 | ||
d62a17ae | 5770 | static void show_ip_ospf_database_header(struct vty *vty, struct ospf_lsa *lsa) |
5771 | { | |
5772 | struct router_lsa *rlsa = (struct router_lsa *)lsa->data; | |
5773 | ||
5774 | vty_out(vty, " LS age: %d\n", LS_AGE(lsa)); | |
5775 | vty_out(vty, " Options: 0x%-2x : %s\n", lsa->data->options, | |
5776 | ospf_options_dump(lsa->data->options)); | |
5777 | vty_out(vty, " LS Flags: 0x%-2x %s\n", lsa->flags, | |
5778 | ((lsa->flags & OSPF_LSA_LOCAL_XLT) ? "(Translated from Type-7)" | |
5779 | : "")); | |
5780 | ||
5781 | if (lsa->data->type == OSPF_ROUTER_LSA) { | |
5782 | vty_out(vty, " Flags: 0x%x", rlsa->flags); | |
5783 | ||
5784 | if (rlsa->flags) | |
5785 | vty_out(vty, " :%s%s%s%s", | |
5786 | IS_ROUTER_LSA_BORDER(rlsa) ? " ABR" : "", | |
5787 | IS_ROUTER_LSA_EXTERNAL(rlsa) ? " ASBR" : "", | |
5788 | IS_ROUTER_LSA_VIRTUAL(rlsa) ? " VL-endpoint" | |
5789 | : "", | |
5790 | IS_ROUTER_LSA_SHORTCUT(rlsa) ? " Shortcut" | |
5791 | : ""); | |
5792 | ||
5793 | vty_out(vty, "\n"); | |
5794 | } | |
5795 | vty_out(vty, " LS Type: %s\n", | |
5796 | lookup_msg(ospf_lsa_type_msg, lsa->data->type, NULL)); | |
5797 | vty_out(vty, " Link State ID: %s %s\n", inet_ntoa(lsa->data->id), | |
5798 | lookup_msg(ospf_link_state_id_type_msg, lsa->data->type, NULL)); | |
5799 | vty_out(vty, " Advertising Router: %s\n", | |
5800 | inet_ntoa(lsa->data->adv_router)); | |
5801 | vty_out(vty, " LS Seq Number: %08lx\n", | |
d7c0a89a | 5802 | (unsigned long)ntohl(lsa->data->ls_seqnum)); |
d62a17ae | 5803 | vty_out(vty, " Checksum: 0x%04x\n", ntohs(lsa->data->checksum)); |
5804 | vty_out(vty, " Length: %d\n\n", ntohs(lsa->data->length)); | |
5805 | } | |
5806 | ||
5807 | const char *link_type_desc[] = { | |
5808 | "(null)", | |
5809 | "another Router (point-to-point)", | |
5810 | "a Transit Network", | |
5811 | "Stub Network", | |
5812 | "a Virtual Link", | |
718e3744 | 5813 | }; |
5814 | ||
d62a17ae | 5815 | const char *link_id_desc[] = { |
5816 | "(null)", "Neighboring Router ID", "Designated Router address", | |
5817 | "Net", "Neighboring Router ID", | |
718e3744 | 5818 | }; |
5819 | ||
d62a17ae | 5820 | const char *link_data_desc[] = { |
5821 | "(null)", "Router Interface address", "Router Interface address", | |
5822 | "Network Mask", "Router Interface address", | |
718e3744 | 5823 | }; |
5824 | ||
5825 | /* Show router-LSA each Link information. */ | |
d62a17ae | 5826 | static void show_ip_ospf_database_router_links(struct vty *vty, |
5827 | struct router_lsa *rl) | |
5828 | { | |
5829 | int len, type; | |
5830 | unsigned int i; | |
5831 | ||
5832 | len = ntohs(rl->header.length) - 4; | |
5833 | for (i = 0; i < ntohs(rl->links) && len > 0; len -= 12, i++) { | |
5834 | type = rl->link[i].type; | |
5835 | ||
5836 | vty_out(vty, " Link connected to: %s\n", | |
5837 | link_type_desc[type]); | |
5838 | vty_out(vty, " (Link ID) %s: %s\n", link_id_desc[type], | |
5839 | inet_ntoa(rl->link[i].link_id)); | |
5840 | vty_out(vty, " (Link Data) %s: %s\n", link_data_desc[type], | |
5841 | inet_ntoa(rl->link[i].link_data)); | |
5842 | vty_out(vty, " Number of TOS metrics: 0\n"); | |
5843 | vty_out(vty, " TOS 0 Metric: %d\n", | |
5844 | ntohs(rl->link[i].metric)); | |
5845 | vty_out(vty, "\n"); | |
5846 | } | |
718e3744 | 5847 | } |
5848 | ||
5849 | /* Show router-LSA detail information. */ | |
d62a17ae | 5850 | static int show_router_lsa_detail(struct vty *vty, struct ospf_lsa *lsa) |
718e3744 | 5851 | { |
d62a17ae | 5852 | if (lsa != NULL) { |
5853 | struct router_lsa *rl = (struct router_lsa *)lsa->data; | |
718e3744 | 5854 | |
d62a17ae | 5855 | show_ip_ospf_database_header(vty, lsa); |
718e3744 | 5856 | |
d62a17ae | 5857 | vty_out(vty, " Number of Links: %d\n\n", ntohs(rl->links)); |
718e3744 | 5858 | |
d62a17ae | 5859 | show_ip_ospf_database_router_links(vty, rl); |
5860 | vty_out(vty, "\n"); | |
5861 | } | |
5862 | ||
5863 | return 0; | |
718e3744 | 5864 | } |
5865 | ||
5866 | /* Show network-LSA detail information. */ | |
d62a17ae | 5867 | static int show_network_lsa_detail(struct vty *vty, struct ospf_lsa *lsa) |
718e3744 | 5868 | { |
d62a17ae | 5869 | int length, i; |
718e3744 | 5870 | |
d62a17ae | 5871 | if (lsa != NULL) { |
5872 | struct network_lsa *nl = (struct network_lsa *)lsa->data; | |
718e3744 | 5873 | |
d62a17ae | 5874 | show_ip_ospf_database_header(vty, lsa); |
718e3744 | 5875 | |
d62a17ae | 5876 | vty_out(vty, " Network Mask: /%d\n", ip_masklen(nl->mask)); |
718e3744 | 5877 | |
d62a17ae | 5878 | length = ntohs(lsa->data->length) - OSPF_LSA_HEADER_SIZE - 4; |
718e3744 | 5879 | |
d62a17ae | 5880 | for (i = 0; length > 0; i++, length -= 4) |
5881 | vty_out(vty, " Attached Router: %s\n", | |
5882 | inet_ntoa(nl->routers[i])); | |
718e3744 | 5883 | |
d62a17ae | 5884 | vty_out(vty, "\n"); |
5885 | } | |
718e3744 | 5886 | |
d62a17ae | 5887 | return 0; |
718e3744 | 5888 | } |
5889 | ||
5890 | /* Show summary-LSA detail information. */ | |
d62a17ae | 5891 | static int show_summary_lsa_detail(struct vty *vty, struct ospf_lsa *lsa) |
718e3744 | 5892 | { |
d62a17ae | 5893 | if (lsa != NULL) { |
5894 | struct summary_lsa *sl = (struct summary_lsa *)lsa->data; | |
718e3744 | 5895 | |
d62a17ae | 5896 | show_ip_ospf_database_header(vty, lsa); |
718e3744 | 5897 | |
d62a17ae | 5898 | vty_out(vty, " Network Mask: /%d\n", ip_masklen(sl->mask)); |
5899 | vty_out(vty, " TOS: 0 Metric: %d\n", | |
5900 | GET_METRIC(sl->metric)); | |
5901 | vty_out(vty, "\n"); | |
5902 | } | |
718e3744 | 5903 | |
d62a17ae | 5904 | return 0; |
718e3744 | 5905 | } |
5906 | ||
5907 | /* Show summary-ASBR-LSA detail information. */ | |
d62a17ae | 5908 | static int show_summary_asbr_lsa_detail(struct vty *vty, struct ospf_lsa *lsa) |
718e3744 | 5909 | { |
d62a17ae | 5910 | if (lsa != NULL) { |
5911 | struct summary_lsa *sl = (struct summary_lsa *)lsa->data; | |
718e3744 | 5912 | |
d62a17ae | 5913 | show_ip_ospf_database_header(vty, lsa); |
718e3744 | 5914 | |
d62a17ae | 5915 | vty_out(vty, " Network Mask: /%d\n", ip_masklen(sl->mask)); |
5916 | vty_out(vty, " TOS: 0 Metric: %d\n", | |
5917 | GET_METRIC(sl->metric)); | |
5918 | vty_out(vty, "\n"); | |
5919 | } | |
718e3744 | 5920 | |
d62a17ae | 5921 | return 0; |
718e3744 | 5922 | } |
5923 | ||
5924 | /* Show AS-external-LSA detail information. */ | |
d62a17ae | 5925 | static int show_as_external_lsa_detail(struct vty *vty, struct ospf_lsa *lsa) |
5926 | { | |
5927 | if (lsa != NULL) { | |
5928 | struct as_external_lsa *al = | |
5929 | (struct as_external_lsa *)lsa->data; | |
5930 | ||
5931 | show_ip_ospf_database_header(vty, lsa); | |
5932 | ||
5933 | vty_out(vty, " Network Mask: /%d\n", ip_masklen(al->mask)); | |
5934 | vty_out(vty, " Metric Type: %s\n", | |
5935 | IS_EXTERNAL_METRIC(al->e[0].tos) | |
5936 | ? "2 (Larger than any link state path)" | |
5937 | : "1"); | |
5938 | vty_out(vty, " TOS: 0\n"); | |
5939 | vty_out(vty, " Metric: %d\n", | |
5940 | GET_METRIC(al->e[0].metric)); | |
5941 | vty_out(vty, " Forward Address: %s\n", | |
5942 | inet_ntoa(al->e[0].fwd_addr)); | |
5943 | ||
5944 | vty_out(vty, | |
5945 | " External Route Tag: %" ROUTE_TAG_PRI "\n\n", | |
5946 | (route_tag_t)ntohl(al->e[0].route_tag)); | |
5947 | } | |
718e3744 | 5948 | |
d62a17ae | 5949 | return 0; |
718e3744 | 5950 | } |
075e12f5 | 5951 | #if 0 |
4dadc291 | 5952 | static int |
718e3744 | 5953 | show_as_external_lsa_stdvty (struct ospf_lsa *lsa) |
5954 | { | |
5955 | struct as_external_lsa *al = (struct as_external_lsa *) lsa->data; | |
5956 | ||
5957 | /* show_ip_ospf_database_header (vty, lsa); */ | |
5958 | ||
2a42e285 | 5959 | zlog_debug( " Network Mask: /%d%s", |
718e3744 | 5960 | ip_masklen (al->mask), "\n"); |
2a42e285 | 5961 | zlog_debug( " Metric Type: %s%s", |
718e3744 | 5962 | IS_EXTERNAL_METRIC (al->e[0].tos) ? |
5963 | "2 (Larger than any link state path)" : "1", "\n"); | |
2a42e285 | 5964 | zlog_debug( " TOS: 0%s", "\n"); |
5965 | zlog_debug( " Metric: %d%s", | |
718e3744 | 5966 | GET_METRIC (al->e[0].metric), "\n"); |
2a42e285 | 5967 | zlog_debug( " Forward Address: %s%s", |
718e3744 | 5968 | inet_ntoa (al->e[0].fwd_addr), "\n"); |
5969 | ||
dc9ffce8 CF |
5970 | zlog_debug( " External Route Tag: %"ROUTE_TAG_PRI"%s%s", |
5971 | (route_tag_t)ntohl (al->e[0].route_tag), "\n", "\n"); | |
718e3744 | 5972 | |
5973 | return 0; | |
5974 | } | |
075e12f5 | 5975 | #endif |
718e3744 | 5976 | /* Show AS-NSSA-LSA detail information. */ |
d62a17ae | 5977 | static int show_as_nssa_lsa_detail(struct vty *vty, struct ospf_lsa *lsa) |
5978 | { | |
5979 | if (lsa != NULL) { | |
5980 | struct as_external_lsa *al = | |
5981 | (struct as_external_lsa *)lsa->data; | |
5982 | ||
5983 | show_ip_ospf_database_header(vty, lsa); | |
5984 | ||
5985 | vty_out(vty, " Network Mask: /%d\n", ip_masklen(al->mask)); | |
5986 | vty_out(vty, " Metric Type: %s\n", | |
5987 | IS_EXTERNAL_METRIC(al->e[0].tos) | |
5988 | ? "2 (Larger than any link state path)" | |
5989 | : "1"); | |
5990 | vty_out(vty, " TOS: 0\n"); | |
5991 | vty_out(vty, " Metric: %d\n", | |
5992 | GET_METRIC(al->e[0].metric)); | |
5993 | vty_out(vty, " NSSA: Forward Address: %s\n", | |
5994 | inet_ntoa(al->e[0].fwd_addr)); | |
5995 | ||
5996 | vty_out(vty, | |
5997 | " External Route Tag: %" ROUTE_TAG_PRI "\n\n", | |
5998 | (route_tag_t)ntohl(al->e[0].route_tag)); | |
5999 | } | |
718e3744 | 6000 | |
d62a17ae | 6001 | return 0; |
718e3744 | 6002 | } |
6003 | ||
d62a17ae | 6004 | static int show_func_dummy(struct vty *vty, struct ospf_lsa *lsa) |
718e3744 | 6005 | { |
d62a17ae | 6006 | return 0; |
718e3744 | 6007 | } |
6008 | ||
d62a17ae | 6009 | static int show_opaque_lsa_detail(struct vty *vty, struct ospf_lsa *lsa) |
718e3744 | 6010 | { |
d62a17ae | 6011 | if (lsa != NULL) { |
6012 | show_ip_ospf_database_header(vty, lsa); | |
6013 | show_opaque_info_detail(vty, lsa); | |
718e3744 | 6014 | |
d62a17ae | 6015 | vty_out(vty, "\n"); |
6016 | } | |
6017 | return 0; | |
6018 | } | |
6019 | ||
6020 | int (*show_function[])(struct vty *, struct ospf_lsa *) = { | |
6021 | NULL, | |
6022 | show_router_lsa_detail, | |
6023 | show_network_lsa_detail, | |
6024 | show_summary_lsa_detail, | |
6025 | show_summary_asbr_lsa_detail, | |
6026 | show_as_external_lsa_detail, | |
6027 | show_func_dummy, | |
6028 | show_as_nssa_lsa_detail, /* almost same as external */ | |
6029 | NULL, /* type-8 */ | |
6030 | show_opaque_lsa_detail, | |
6031 | show_opaque_lsa_detail, | |
6032 | show_opaque_lsa_detail, | |
6033 | }; | |
6034 | ||
6035 | static void show_lsa_prefix_set(struct vty *vty, struct prefix_ls *lp, | |
6036 | struct in_addr *id, struct in_addr *adv_router) | |
6037 | { | |
6038 | memset(lp, 0, sizeof(struct prefix_ls)); | |
6039 | lp->family = 0; | |
6040 | if (id == NULL) | |
6041 | lp->prefixlen = 0; | |
6042 | else if (adv_router == NULL) { | |
6043 | lp->prefixlen = 32; | |
6044 | lp->id = *id; | |
6045 | } else { | |
6046 | lp->prefixlen = 64; | |
6047 | lp->id = *id; | |
6048 | lp->adv_router = *adv_router; | |
6049 | } | |
718e3744 | 6050 | } |
718e3744 | 6051 | |
d62a17ae | 6052 | static void show_lsa_detail_proc(struct vty *vty, struct route_table *rt, |
6053 | struct in_addr *id, struct in_addr *adv_router) | |
6054 | { | |
6055 | struct prefix_ls lp; | |
6056 | struct route_node *rn, *start; | |
6057 | struct ospf_lsa *lsa; | |
718e3744 | 6058 | |
d62a17ae | 6059 | show_lsa_prefix_set(vty, &lp, id, adv_router); |
6060 | start = route_node_get(rt, (struct prefix *)&lp); | |
6061 | if (start) { | |
6062 | route_lock_node(start); | |
6063 | for (rn = start; rn; rn = route_next_until(rn, start)) | |
6064 | if ((lsa = rn->info)) { | |
6065 | if (show_function[lsa->data->type] != NULL) | |
6066 | show_function[lsa->data->type](vty, | |
6067 | lsa); | |
6068 | } | |
6069 | route_unlock_node(start); | |
6070 | } | |
718e3744 | 6071 | } |
6072 | ||
6073 | /* Show detail LSA information | |
6074 | -- if id is NULL then show all LSAs. */ | |
d62a17ae | 6075 | static void show_lsa_detail(struct vty *vty, struct ospf *ospf, int type, |
6076 | struct in_addr *id, struct in_addr *adv_router) | |
6077 | { | |
6078 | struct listnode *node; | |
6079 | struct ospf_area *area; | |
6080 | ||
6081 | switch (type) { | |
6082 | case OSPF_AS_EXTERNAL_LSA: | |
6083 | case OSPF_OPAQUE_AS_LSA: | |
6084 | vty_out(vty, " %s \n\n", | |
6085 | show_database_desc[type]); | |
6086 | show_lsa_detail_proc(vty, AS_LSDB(ospf, type), id, adv_router); | |
6087 | break; | |
6088 | default: | |
6089 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) { | |
6090 | vty_out(vty, "\n %s (Area %s)\n\n", | |
6091 | show_database_desc[type], | |
6092 | ospf_area_desc_string(area)); | |
6093 | show_lsa_detail_proc(vty, AREA_LSDB(area, type), id, | |
6094 | adv_router); | |
6095 | } | |
6096 | break; | |
718e3744 | 6097 | } |
6098 | } | |
6099 | ||
d62a17ae | 6100 | static void show_lsa_detail_adv_router_proc(struct vty *vty, |
6101 | struct route_table *rt, | |
6102 | struct in_addr *adv_router) | |
6103 | { | |
6104 | struct route_node *rn; | |
6105 | struct ospf_lsa *lsa; | |
6106 | ||
6107 | for (rn = route_top(rt); rn; rn = route_next(rn)) | |
6108 | if ((lsa = rn->info)) | |
6109 | if (IPV4_ADDR_SAME(adv_router, | |
6110 | &lsa->data->adv_router)) { | |
6111 | if (CHECK_FLAG(lsa->flags, OSPF_LSA_LOCAL_XLT)) | |
6112 | continue; | |
6113 | if (show_function[lsa->data->type] != NULL) | |
6114 | show_function[lsa->data->type](vty, | |
6115 | lsa); | |
6116 | } | |
6117 | } | |
6118 | ||
718e3744 | 6119 | /* Show detail LSA information. */ |
d62a17ae | 6120 | static void show_lsa_detail_adv_router(struct vty *vty, struct ospf *ospf, |
6121 | int type, struct in_addr *adv_router) | |
6122 | { | |
6123 | struct listnode *node; | |
6124 | struct ospf_area *area; | |
6125 | ||
6126 | switch (type) { | |
6127 | case OSPF_AS_EXTERNAL_LSA: | |
6128 | case OSPF_OPAQUE_AS_LSA: | |
6129 | vty_out(vty, " %s \n\n", | |
6130 | show_database_desc[type]); | |
6131 | show_lsa_detail_adv_router_proc(vty, AS_LSDB(ospf, type), | |
6132 | adv_router); | |
6133 | break; | |
6134 | default: | |
6135 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) { | |
6136 | vty_out(vty, "\n %s (Area %s)\n\n", | |
6137 | show_database_desc[type], | |
6138 | ospf_area_desc_string(area)); | |
6139 | show_lsa_detail_adv_router_proc( | |
6140 | vty, AREA_LSDB(area, type), adv_router); | |
6141 | } | |
6142 | break; | |
6143 | } | |
6144 | } | |
6145 | ||
6146 | static void show_ip_ospf_database_summary(struct vty *vty, struct ospf *ospf, | |
6147 | int self) | |
6148 | { | |
6149 | struct ospf_lsa *lsa; | |
6150 | struct route_node *rn; | |
6151 | struct ospf_area *area; | |
6152 | struct listnode *node; | |
6153 | int type; | |
6154 | ||
6155 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) { | |
6156 | for (type = OSPF_MIN_LSA; type < OSPF_MAX_LSA; type++) { | |
6157 | switch (type) { | |
6158 | case OSPF_AS_EXTERNAL_LSA: | |
6159 | case OSPF_OPAQUE_AS_LSA: | |
6160 | continue; | |
6161 | default: | |
6162 | break; | |
6163 | } | |
6164 | if (ospf_lsdb_count_self(area->lsdb, type) > 0 | |
6165 | || (!self | |
6166 | && ospf_lsdb_count(area->lsdb, type) > 0)) { | |
6167 | vty_out(vty, " %s (Area %s)\n\n", | |
6168 | show_database_desc[type], | |
6169 | ospf_area_desc_string(area)); | |
6170 | vty_out(vty, "%s\n", | |
6171 | show_database_header[type]); | |
6172 | ||
996c9314 | 6173 | LSDB_LOOP (AREA_LSDB(area, type), rn, lsa) |
044506e7 | 6174 | show_lsa_summary(vty, lsa, self); |
d62a17ae | 6175 | |
6176 | vty_out(vty, "\n"); | |
6177 | } | |
6178 | } | |
6179 | } | |
6180 | ||
6181 | for (type = OSPF_MIN_LSA; type < OSPF_MAX_LSA; type++) { | |
6182 | switch (type) { | |
6183 | case OSPF_AS_EXTERNAL_LSA: | |
6184 | case OSPF_OPAQUE_AS_LSA: | |
6185 | break; | |
6186 | default: | |
6187 | continue; | |
6188 | } | |
6189 | if (ospf_lsdb_count_self(ospf->lsdb, type) | |
6190 | || (!self && ospf_lsdb_count(ospf->lsdb, type))) { | |
6191 | vty_out(vty, " %s\n\n", | |
6192 | show_database_desc[type]); | |
6193 | vty_out(vty, "%s\n", show_database_header[type]); | |
6194 | ||
996c9314 | 6195 | LSDB_LOOP (AS_LSDB(ospf, type), rn, lsa) |
044506e7 | 6196 | show_lsa_summary(vty, lsa, self); |
d62a17ae | 6197 | |
6198 | vty_out(vty, "\n"); | |
6199 | } | |
6200 | } | |
6201 | ||
6202 | vty_out(vty, "\n"); | |
6203 | } | |
6204 | ||
6205 | static void show_ip_ospf_database_maxage(struct vty *vty, struct ospf *ospf) | |
6206 | { | |
6207 | struct route_node *rn; | |
6208 | ||
6209 | vty_out(vty, "\n MaxAge Link States:\n\n"); | |
6210 | ||
6211 | for (rn = route_top(ospf->maxage_lsa); rn; rn = route_next(rn)) { | |
6212 | struct ospf_lsa *lsa; | |
6213 | ||
6214 | if ((lsa = rn->info) != NULL) { | |
6215 | vty_out(vty, "Link type: %d\n", lsa->data->type); | |
6216 | vty_out(vty, "Link State ID: %s\n", | |
6217 | inet_ntoa(lsa->data->id)); | |
6218 | vty_out(vty, "Advertising Router: %s\n", | |
6219 | inet_ntoa(lsa->data->adv_router)); | |
6220 | vty_out(vty, "LSA lock count: %d\n", lsa->lock); | |
6221 | vty_out(vty, "\n"); | |
6222 | } | |
91e6a0e5 | 6223 | } |
718e3744 | 6224 | } |
6225 | ||
718e3744 | 6226 | #define OSPF_LSA_TYPE_NSSA_DESC "NSSA external link state\n" |
6227 | #define OSPF_LSA_TYPE_NSSA_CMD_STR "|nssa-external" | |
718e3744 | 6228 | |
718e3744 | 6229 | #define OSPF_LSA_TYPE_OPAQUE_LINK_DESC "Link local Opaque-LSA\n" |
6230 | #define OSPF_LSA_TYPE_OPAQUE_AREA_DESC "Link area Opaque-LSA\n" | |
6231 | #define OSPF_LSA_TYPE_OPAQUE_AS_DESC "Link AS Opaque-LSA\n" | |
6232 | #define OSPF_LSA_TYPE_OPAQUE_CMD_STR "|opaque-link|opaque-area|opaque-as" | |
718e3744 | 6233 | |
d62a17ae | 6234 | #define OSPF_LSA_TYPES_DESC \ |
6235 | "ASBR summary link states\n" \ | |
6236 | "External link states\n" \ | |
6237 | "Network link states\n" \ | |
6238 | "Router link states\n" \ | |
6239 | "Network summary link states\n" OSPF_LSA_TYPE_NSSA_DESC \ | |
6240 | OSPF_LSA_TYPE_OPAQUE_LINK_DESC OSPF_LSA_TYPE_OPAQUE_AREA_DESC \ | |
6241 | OSPF_LSA_TYPE_OPAQUE_AS_DESC | |
6242 | ||
6243 | static int show_ip_ospf_database_common(struct vty *vty, struct ospf *ospf, | |
6244 | int arg_base, int argc, | |
d7c0a89a QY |
6245 | struct cmd_token **argv, |
6246 | uint8_t use_vrf) | |
d62a17ae | 6247 | { |
6248 | int idx_type = 4; | |
6249 | int type, ret; | |
6250 | struct in_addr id, adv_router; | |
6251 | ||
6252 | if (ospf->instance) | |
6253 | vty_out(vty, "\nOSPF Instance: %d\n", ospf->instance); | |
6254 | ||
b1c3ae8c | 6255 | ospf_show_vrf_name(ospf, vty, NULL, use_vrf); |
87bd50e8 | 6256 | |
d62a17ae | 6257 | vty_out(vty, "\n OSPF Router with ID (%s)\n\n", |
6258 | inet_ntoa(ospf->router_id)); | |
6259 | ||
6260 | /* Show all LSA. */ | |
6261 | if (argc == arg_base + 4) { | |
6262 | show_ip_ospf_database_summary(vty, ospf, 0); | |
6263 | return CMD_SUCCESS; | |
6264 | } | |
718e3744 | 6265 | |
d62a17ae | 6266 | /* Set database type to show. */ |
6267 | if (strncmp(argv[arg_base + idx_type]->text, "r", 1) == 0) | |
6268 | type = OSPF_ROUTER_LSA; | |
6269 | else if (strncmp(argv[arg_base + idx_type]->text, "ne", 2) == 0) | |
6270 | type = OSPF_NETWORK_LSA; | |
6271 | else if (strncmp(argv[arg_base + idx_type]->text, "ns", 2) == 0) | |
6272 | type = OSPF_AS_NSSA_LSA; | |
6273 | else if (strncmp(argv[arg_base + idx_type]->text, "su", 2) == 0) | |
6274 | type = OSPF_SUMMARY_LSA; | |
6275 | else if (strncmp(argv[arg_base + idx_type]->text, "a", 1) == 0) | |
6276 | type = OSPF_ASBR_SUMMARY_LSA; | |
6277 | else if (strncmp(argv[arg_base + idx_type]->text, "e", 1) == 0) | |
6278 | type = OSPF_AS_EXTERNAL_LSA; | |
6279 | else if (strncmp(argv[arg_base + idx_type]->text, "se", 2) == 0) { | |
6280 | show_ip_ospf_database_summary(vty, ospf, 1); | |
6281 | return CMD_SUCCESS; | |
6282 | } else if (strncmp(argv[arg_base + idx_type]->text, "m", 1) == 0) { | |
6283 | show_ip_ospf_database_maxage(vty, ospf); | |
6284 | return CMD_SUCCESS; | |
6285 | } else if (strncmp(argv[arg_base + idx_type]->text, "opaque-l", 8) == 0) | |
6286 | type = OSPF_OPAQUE_LINK_LSA; | |
6287 | else if (strncmp(argv[arg_base + idx_type]->text, "opaque-ar", 9) == 0) | |
6288 | type = OSPF_OPAQUE_AREA_LSA; | |
6289 | else if (strncmp(argv[arg_base + idx_type]->text, "opaque-as", 9) == 0) | |
6290 | type = OSPF_OPAQUE_AS_LSA; | |
6291 | else | |
718e3744 | 6292 | return CMD_WARNING; |
d62a17ae | 6293 | |
6294 | /* `show ip ospf database LSA'. */ | |
6295 | if (argc == arg_base + 5) | |
6296 | show_lsa_detail(vty, ospf, type, NULL, NULL); | |
6297 | else if (argc >= arg_base + 6) { | |
6298 | ret = inet_aton(argv[arg_base + 5]->arg, &id); | |
6299 | if (!ret) | |
6300 | return CMD_WARNING; | |
6301 | ||
6302 | /* `show ip ospf database LSA ID'. */ | |
6303 | if (argc == arg_base + 6) | |
6304 | show_lsa_detail(vty, ospf, type, &id, NULL); | |
6305 | /* `show ip ospf database LSA ID adv-router ADV_ROUTER'. */ | |
6306 | else if (argc == arg_base + 7) { | |
6307 | if (strncmp(argv[arg_base + 6]->text, "s", 1) == 0) | |
6308 | adv_router = ospf->router_id; | |
6309 | else { | |
6310 | ret = inet_aton(argv[arg_base + 7]->arg, | |
6311 | &adv_router); | |
6312 | if (!ret) | |
6313 | return CMD_WARNING; | |
6314 | } | |
6315 | show_lsa_detail(vty, ospf, type, &id, &adv_router); | |
6316 | } | |
718e3744 | 6317 | } |
718e3744 | 6318 | |
d62a17ae | 6319 | return CMD_SUCCESS; |
718e3744 | 6320 | } |
6321 | ||
7a7be519 | 6322 | DEFUN (show_ip_ospf_database_max, |
6323 | show_ip_ospf_database_max_cmd, | |
b5a8894d | 6324 | "show ip ospf [vrf <NAME|all>] database <max-age|self-originate>", |
7a7be519 | 6325 | SHOW_STR |
6326 | IP_STR | |
6327 | "OSPF information\n" | |
b5a8894d CS |
6328 | VRF_CMD_HELP_STR |
6329 | "All VRFs\n" | |
7a7be519 | 6330 | "Database summary\n" |
6331 | "LSAs in MaxAge list\n" | |
6332 | "Self-originated link states\n") | |
6333 | { | |
b5a8894d CS |
6334 | struct ospf *ospf = NULL; |
6335 | struct listnode *node = NULL; | |
6336 | char *vrf_name = NULL; | |
2951a7a4 | 6337 | bool all_vrf = false; |
b5a8894d CS |
6338 | int ret = CMD_SUCCESS; |
6339 | int inst = 0; | |
6340 | int idx_vrf = 0; | |
d7c0a89a | 6341 | uint8_t use_vrf = 0; |
f412b39a | 6342 | |
43b8d1d8 | 6343 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
f412b39a | 6344 | |
b5a8894d | 6345 | if (vrf_name) { |
2951a7a4 | 6346 | bool ospf_output = false; |
874f58d8 | 6347 | |
b1c3ae8c | 6348 | use_vrf = 1; |
94d4c685 | 6349 | |
b5a8894d CS |
6350 | if (all_vrf) { |
6351 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
6352 | if (!ospf->oi_running) | |
6353 | continue; | |
2951a7a4 | 6354 | ospf_output = true; |
996c9314 LB |
6355 | ret = show_ip_ospf_database_common( |
6356 | vty, ospf, idx_vrf ? 2 : 0, argc, argv, | |
6357 | use_vrf); | |
b5a8894d | 6358 | } |
9f049418 DS |
6359 | |
6360 | if (!ospf_output) | |
6361 | vty_out(vty, "%% OSPF instance not found\n"); | |
b5a8894d CS |
6362 | } else { |
6363 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
9f049418 | 6364 | if (ospf == NULL || !ospf->oi_running) { |
94d4c685 | 6365 | vty_out(vty, "%% OSPF instance not found\n"); |
b5a8894d | 6366 | return CMD_SUCCESS; |
9f049418 | 6367 | } |
996c9314 LB |
6368 | ret = (show_ip_ospf_database_common( |
6369 | vty, ospf, idx_vrf ? 2 : 0, argc, argv, | |
6370 | use_vrf)); | |
b5a8894d CS |
6371 | } |
6372 | } else { | |
6373 | /* Display default ospf (instance 0) info */ | |
6374 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
9f049418 | 6375 | if (ospf == NULL || !ospf->oi_running) { |
94d4c685 | 6376 | vty_out(vty, "%% OSPF instance not found\n"); |
b5a8894d | 6377 | return CMD_SUCCESS; |
9f049418 DS |
6378 | } |
6379 | ||
b1c3ae8c CS |
6380 | ret = show_ip_ospf_database_common(vty, ospf, 0, argc, argv, |
6381 | use_vrf); | |
b5a8894d CS |
6382 | } |
6383 | ||
6384 | return ret; | |
7a7be519 | 6385 | } |
f412b39a | 6386 | |
f412b39a DW |
6387 | DEFUN (show_ip_ospf_instance_database, |
6388 | show_ip_ospf_instance_database_cmd, | |
43b8d1d8 | 6389 | "show ip ospf [{(1-65535)|vrf NAME}] 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>]]]", |
718e3744 | 6390 | SHOW_STR |
6391 | IP_STR | |
6392 | "OSPF information\n" | |
7c8ff89e | 6393 | "Instance ID\n" |
b5a8894d | 6394 | VRF_CMD_HELP_STR |
7a7be519 | 6395 | "Database summary\n" |
6396 | OSPF_LSA_TYPES_DESC | |
6397 | "Link State ID (as an IP address)\n" | |
6398 | "Self-originated link states\n" | |
6399 | "Advertising Router link states\n" | |
6400 | "Advertising Router (as an IP address)\n") | |
7c8ff89e | 6401 | { |
d62a17ae | 6402 | struct ospf *ospf; |
d7c0a89a | 6403 | unsigned short instance = 0; |
b5a8894d CS |
6404 | struct listnode *node = NULL; |
6405 | char *vrf_name = NULL; | |
2951a7a4 | 6406 | bool all_vrf = false; |
b5a8894d CS |
6407 | int ret = CMD_SUCCESS; |
6408 | int inst = 0; | |
d62a17ae | 6409 | int idx = 0; |
d7c0a89a | 6410 | uint8_t use_vrf = 0; |
b5a8894d | 6411 | |
d62a17ae | 6412 | if (argv_find(argv, argc, "(1-65535)", &idx)) { |
6413 | instance = strtoul(argv[idx]->arg, NULL, 10); | |
6414 | ospf = ospf_lookup_instance(instance); | |
ac28e4ec CS |
6415 | if (ospf == NULL) |
6416 | return CMD_NOT_MY_INSTANCE; | |
b5a8894d CS |
6417 | if (!ospf->oi_running) |
6418 | return CMD_SUCCESS; | |
6419 | ||
6420 | return (show_ip_ospf_database_common(vty, ospf, idx ? 1 : 0, | |
b1c3ae8c | 6421 | argc, argv, use_vrf)); |
b5a8894d CS |
6422 | } else if (argv_find(argv, argc, "vrf", &idx)) { |
6423 | vrf_name = argv[++idx]->arg; | |
6424 | all_vrf = strmatch(vrf_name, "all"); | |
d62a17ae | 6425 | } |
7c8ff89e | 6426 | |
b5a8894d | 6427 | if (vrf_name) { |
b1c3ae8c | 6428 | use_vrf = 1; |
b5a8894d CS |
6429 | if (all_vrf) { |
6430 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
6431 | if (!ospf->oi_running) | |
6432 | continue; | |
996c9314 LB |
6433 | ret = (show_ip_ospf_database_common( |
6434 | vty, ospf, idx ? 2 : 0, argc, argv, | |
6435 | use_vrf)); | |
b5a8894d CS |
6436 | } |
6437 | } else { | |
6438 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
9f049418 | 6439 | if ((ospf == NULL) || !ospf->oi_running) { |
94d4c685 | 6440 | vty_out(vty, "%% OSPF instance not found\n"); |
b5a8894d | 6441 | return CMD_SUCCESS; |
9f049418 DS |
6442 | } |
6443 | ||
996c9314 LB |
6444 | ret = (show_ip_ospf_database_common( |
6445 | vty, ospf, idx ? 2 : 0, argc, argv, use_vrf)); | |
b5a8894d CS |
6446 | } |
6447 | } else { | |
6448 | /* Display default ospf (instance 0) info */ | |
6449 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
9f049418 | 6450 | if (ospf == NULL || !ospf->oi_running) { |
94d4c685 | 6451 | vty_out(vty, "%% OSPF instance not found\n"); |
b5a8894d | 6452 | return CMD_SUCCESS; |
9f049418 DS |
6453 | } |
6454 | ||
b1c3ae8c CS |
6455 | ret = (show_ip_ospf_database_common(vty, ospf, 0, argc, argv, |
6456 | use_vrf)); | |
b5a8894d | 6457 | } |
7c8ff89e | 6458 | |
b5a8894d | 6459 | return ret; |
7c8ff89e DS |
6460 | } |
6461 | ||
7a7be519 | 6462 | DEFUN (show_ip_ospf_instance_database_max, |
6463 | show_ip_ospf_instance_database_max_cmd, | |
6464 | "show ip ospf (1-65535) database <max-age|self-originate>", | |
6465 | SHOW_STR | |
6466 | IP_STR | |
6467 | "OSPF information\n" | |
6468 | "Instance ID\n" | |
6469 | "Database summary\n" | |
6470 | "LSAs in MaxAge list\n" | |
6471 | "Self-originated link states\n") | |
6472 | { | |
d62a17ae | 6473 | int idx_number = 3; |
6474 | struct ospf *ospf; | |
d7c0a89a | 6475 | unsigned short instance = 0; |
d62a17ae | 6476 | |
6477 | instance = strtoul(argv[idx_number]->arg, NULL, 10); | |
6478 | ||
ac28e4ec CS |
6479 | ospf = ospf_lookup_instance(instance); |
6480 | if (ospf == NULL) | |
6481 | return CMD_NOT_MY_INSTANCE; | |
6482 | ||
9f049418 | 6483 | if (!ospf->oi_running) { |
94d4c685 | 6484 | vty_out(vty, "%% OSPF instance not found\n"); |
d62a17ae | 6485 | return CMD_SUCCESS; |
9f049418 | 6486 | } |
d62a17ae | 6487 | |
b1c3ae8c | 6488 | return show_ip_ospf_database_common(vty, ospf, 1, argc, argv, 0); |
d62a17ae | 6489 | } |
6490 | ||
6491 | ||
6492 | static int show_ip_ospf_database_type_adv_router_common(struct vty *vty, | |
6493 | struct ospf *ospf, | |
6494 | int arg_base, int argc, | |
b1c3ae8c | 6495 | struct cmd_token **argv, |
d7c0a89a | 6496 | uint8_t use_vrf) |
d62a17ae | 6497 | { |
6498 | int idx_type = 4; | |
6499 | int type, ret; | |
6500 | struct in_addr adv_router; | |
6501 | ||
6502 | if (ospf->instance) | |
6503 | vty_out(vty, "\nOSPF Instance: %d\n", ospf->instance); | |
6504 | ||
b1c3ae8c | 6505 | ospf_show_vrf_name(ospf, vty, NULL, use_vrf); |
87bd50e8 | 6506 | |
d62a17ae | 6507 | vty_out(vty, "\n OSPF Router with ID (%s)\n\n", |
6508 | inet_ntoa(ospf->router_id)); | |
6509 | ||
6510 | /* Set database type to show. */ | |
6511 | if (strncmp(argv[arg_base + idx_type]->text, "r", 1) == 0) | |
6512 | type = OSPF_ROUTER_LSA; | |
6513 | else if (strncmp(argv[arg_base + idx_type]->text, "ne", 2) == 0) | |
6514 | type = OSPF_NETWORK_LSA; | |
6515 | else if (strncmp(argv[arg_base + idx_type]->text, "ns", 2) == 0) | |
6516 | type = OSPF_AS_NSSA_LSA; | |
6517 | else if (strncmp(argv[arg_base + idx_type]->text, "s", 1) == 0) | |
6518 | type = OSPF_SUMMARY_LSA; | |
6519 | else if (strncmp(argv[arg_base + idx_type]->text, "a", 1) == 0) | |
6520 | type = OSPF_ASBR_SUMMARY_LSA; | |
6521 | else if (strncmp(argv[arg_base + idx_type]->text, "e", 1) == 0) | |
6522 | type = OSPF_AS_EXTERNAL_LSA; | |
6523 | else if (strncmp(argv[arg_base + idx_type]->text, "opaque-l", 8) == 0) | |
6524 | type = OSPF_OPAQUE_LINK_LSA; | |
6525 | else if (strncmp(argv[arg_base + idx_type]->text, "opaque-ar", 9) == 0) | |
6526 | type = OSPF_OPAQUE_AREA_LSA; | |
6527 | else if (strncmp(argv[arg_base + idx_type]->text, "opaque-as", 9) == 0) | |
6528 | type = OSPF_OPAQUE_AS_LSA; | |
6529 | else | |
6530 | return CMD_WARNING; | |
7c8ff89e | 6531 | |
d62a17ae | 6532 | /* `show ip ospf database LSA adv-router ADV_ROUTER'. */ |
6533 | if (strncmp(argv[arg_base + 5]->text, "s", 1) == 0) | |
6534 | adv_router = ospf->router_id; | |
6535 | else { | |
6536 | ret = inet_aton(argv[arg_base + 6]->arg, &adv_router); | |
6537 | if (!ret) | |
6538 | return CMD_WARNING; | |
6539 | } | |
7c8ff89e | 6540 | |
d62a17ae | 6541 | show_lsa_detail_adv_router(vty, ospf, type, &adv_router); |
7c8ff89e | 6542 | |
d62a17ae | 6543 | return CMD_SUCCESS; |
7c8ff89e DS |
6544 | } |
6545 | ||
7c8ff89e DS |
6546 | DEFUN (show_ip_ospf_instance_database_type_adv_router, |
6547 | show_ip_ospf_instance_database_type_adv_router_cmd, | |
43b8d1d8 | 6548 | "show ip ospf [{(1-65535)|vrf NAME}] database <asbr-summary|external|network|router|summary|nssa-external|opaque-link|opaque-area|opaque-as> <adv-router A.B.C.D|self-originate>", |
7c8ff89e DS |
6549 | SHOW_STR |
6550 | IP_STR | |
6551 | "OSPF information\n" | |
6552 | "Instance ID\n" | |
b5a8894d | 6553 | VRF_CMD_HELP_STR |
7c8ff89e DS |
6554 | "Database summary\n" |
6555 | OSPF_LSA_TYPES_DESC | |
6556 | "Advertising Router link states\n" | |
3a2d747c QY |
6557 | "Advertising Router (as an IP address)\n" |
6558 | "Self-originated link states\n") | |
7c8ff89e | 6559 | { |
b5a8894d | 6560 | struct ospf *ospf = NULL; |
d7c0a89a | 6561 | unsigned short instance = 0; |
b5a8894d CS |
6562 | struct listnode *node = NULL; |
6563 | char *vrf_name = NULL; | |
2951a7a4 | 6564 | bool all_vrf = false; |
b5a8894d CS |
6565 | int ret = CMD_SUCCESS; |
6566 | int inst = 0; | |
43b8d1d8 | 6567 | int idx = 0, idx_vrf = 0; |
d7c0a89a | 6568 | uint8_t use_vrf = 0; |
7c8ff89e | 6569 | |
d62a17ae | 6570 | if (argv_find(argv, argc, "(1-65535)", &idx)) { |
6571 | instance = strtoul(argv[idx]->arg, NULL, 10); | |
6572 | ospf = ospf_lookup_instance(instance); | |
ac28e4ec CS |
6573 | if (ospf == NULL) |
6574 | return CMD_NOT_MY_INSTANCE; | |
9f049418 | 6575 | if (!ospf->oi_running) { |
94d4c685 | 6576 | vty_out(vty, "%% OSPF instance not found\n"); |
b5a8894d | 6577 | return CMD_SUCCESS; |
9f049418 DS |
6578 | } |
6579 | ||
996c9314 LB |
6580 | return (show_ip_ospf_database_type_adv_router_common( |
6581 | vty, ospf, idx ? 1 : 0, argc, argv, use_vrf)); | |
b5a8894d | 6582 | } |
43b8d1d8 CS |
6583 | |
6584 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); | |
6585 | ||
b5a8894d | 6586 | if (vrf_name) { |
2951a7a4 | 6587 | bool ospf_output = false; |
874f58d8 | 6588 | |
b1c3ae8c | 6589 | use_vrf = 1; |
94d4c685 | 6590 | |
b5a8894d CS |
6591 | if (all_vrf) { |
6592 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
6593 | if (!ospf->oi_running) | |
6594 | continue; | |
2951a7a4 | 6595 | ospf_output = true; |
996c9314 LB |
6596 | ret = show_ip_ospf_database_type_adv_router_common( |
6597 | vty, ospf, idx ? 1 : 0, argc, argv, | |
6598 | use_vrf); | |
b5a8894d | 6599 | } |
9f049418 DS |
6600 | if (!ospf_output) |
6601 | vty_out(vty, "%% OSPF instance not found\n"); | |
b5a8894d CS |
6602 | } else { |
6603 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
9f049418 | 6604 | if ((ospf == NULL) || !ospf->oi_running) { |
94d4c685 | 6605 | vty_out(vty, "%% OSPF instance not found\n"); |
b5a8894d | 6606 | return CMD_SUCCESS; |
9f049418 DS |
6607 | } |
6608 | ||
996c9314 LB |
6609 | ret = show_ip_ospf_database_type_adv_router_common( |
6610 | vty, ospf, idx ? 1 : 0, argc, argv, use_vrf); | |
b5a8894d CS |
6611 | } |
6612 | } else { | |
6613 | /* Display default ospf (instance 0) info */ | |
6614 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
9f049418 | 6615 | if (ospf == NULL || !ospf->oi_running) { |
94d4c685 | 6616 | vty_out(vty, "%% OSPF instance not found\n"); |
b5a8894d | 6617 | return CMD_SUCCESS; |
9f049418 DS |
6618 | } |
6619 | ||
996c9314 LB |
6620 | ret = show_ip_ospf_database_type_adv_router_common( |
6621 | vty, ospf, idx ? 1 : 0, argc, argv, use_vrf); | |
b5a8894d CS |
6622 | } |
6623 | return ret; | |
6624 | /*return (show_ip_ospf_database_type_adv_router_common( | |
6625 | vty, ospf, idx ? 1 : 0, argc, argv));*/ | |
718e3744 | 6626 | } |
6627 | ||
718e3744 | 6628 | DEFUN (ip_ospf_authentication_args, |
6629 | ip_ospf_authentication_args_addr_cmd, | |
7a7be519 | 6630 | "ip ospf authentication <null|message-digest> [A.B.C.D]", |
718e3744 | 6631 | "IP Information\n" |
6632 | "OSPF interface commands\n" | |
6633 | "Enable authentication on this interface\n" | |
6634 | "Use null authentication\n" | |
6635 | "Use message-digest authentication\n" | |
7a7be519 | 6636 | "Address of interface\n") |
718e3744 | 6637 | { |
d62a17ae | 6638 | VTY_DECLVAR_CONTEXT(interface, ifp); |
6639 | int idx_encryption = 3; | |
6640 | int idx_ipv4 = 4; | |
6641 | struct in_addr addr; | |
6642 | int ret; | |
6643 | struct ospf_if_params *params; | |
6644 | ||
6645 | params = IF_DEF_PARAMS(ifp); | |
6646 | ||
6647 | if (argc == 5) { | |
6648 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
6649 | if (!ret) { | |
6650 | vty_out(vty, | |
6651 | "Please specify interface address by A.B.C.D\n"); | |
6652 | return CMD_WARNING_CONFIG_FAILED; | |
6653 | } | |
718e3744 | 6654 | |
d62a17ae | 6655 | params = ospf_get_if_params(ifp, addr); |
6656 | ospf_if_update_params(ifp, addr); | |
6657 | } | |
718e3744 | 6658 | |
d62a17ae | 6659 | /* Handle null authentication */ |
6660 | if (argv[idx_encryption]->arg[0] == 'n') { | |
6661 | SET_IF_PARAM(params, auth_type); | |
6662 | params->auth_type = OSPF_AUTH_NULL; | |
6663 | return CMD_SUCCESS; | |
6664 | } | |
718e3744 | 6665 | |
d62a17ae | 6666 | /* Handle message-digest authentication */ |
6667 | if (argv[idx_encryption]->arg[0] == 'm') { | |
6668 | SET_IF_PARAM(params, auth_type); | |
6669 | params->auth_type = OSPF_AUTH_CRYPTOGRAPHIC; | |
6670 | return CMD_SUCCESS; | |
6671 | } | |
718e3744 | 6672 | |
d62a17ae | 6673 | vty_out(vty, "You shouldn't get here!\n"); |
6674 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 6675 | } |
6676 | ||
718e3744 | 6677 | DEFUN (ip_ospf_authentication, |
6678 | ip_ospf_authentication_addr_cmd, | |
7a7be519 | 6679 | "ip ospf authentication [A.B.C.D]", |
718e3744 | 6680 | "IP Information\n" |
6681 | "OSPF interface commands\n" | |
6682 | "Enable authentication on this interface\n" | |
efd7904e | 6683 | "Address of interface\n") |
718e3744 | 6684 | { |
d62a17ae | 6685 | VTY_DECLVAR_CONTEXT(interface, ifp); |
6686 | int idx_ipv4 = 3; | |
6687 | struct in_addr addr; | |
6688 | int ret; | |
6689 | struct ospf_if_params *params; | |
6690 | ||
6691 | params = IF_DEF_PARAMS(ifp); | |
6692 | ||
6693 | if (argc == 4) { | |
6694 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
6695 | if (!ret) { | |
6696 | vty_out(vty, | |
6697 | "Please specify interface address by A.B.C.D\n"); | |
6698 | return CMD_WARNING_CONFIG_FAILED; | |
6699 | } | |
6700 | ||
6701 | params = ospf_get_if_params(ifp, addr); | |
6702 | ospf_if_update_params(ifp, addr); | |
718e3744 | 6703 | } |
6704 | ||
d62a17ae | 6705 | SET_IF_PARAM(params, auth_type); |
6706 | params->auth_type = OSPF_AUTH_SIMPLE; | |
718e3744 | 6707 | |
d62a17ae | 6708 | return CMD_SUCCESS; |
718e3744 | 6709 | } |
6710 | ||
b4a039bf DS |
6711 | DEFUN (no_ip_ospf_authentication_args, |
6712 | no_ip_ospf_authentication_args_addr_cmd, | |
7a7be519 | 6713 | "no ip ospf authentication <null|message-digest> [A.B.C.D]", |
b4a039bf DS |
6714 | NO_STR |
6715 | "IP Information\n" | |
6716 | "OSPF interface commands\n" | |
6717 | "Enable authentication on this interface\n" | |
6718 | "Use null authentication\n" | |
6719 | "Use message-digest authentication\n" | |
efd7904e | 6720 | "Address of interface\n") |
b4a039bf | 6721 | { |
d62a17ae | 6722 | VTY_DECLVAR_CONTEXT(interface, ifp); |
6723 | int idx_encryption = 4; | |
6724 | int idx_ipv4 = 5; | |
6725 | struct in_addr addr; | |
6726 | int ret; | |
6727 | struct ospf_if_params *params; | |
6728 | struct route_node *rn; | |
6729 | int auth_type; | |
6730 | ||
6731 | params = IF_DEF_PARAMS(ifp); | |
6732 | ||
6733 | if (argc == 6) { | |
6734 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
6735 | if (!ret) { | |
6736 | vty_out(vty, | |
6737 | "Please specify interface address by A.B.C.D\n"); | |
6738 | return CMD_WARNING_CONFIG_FAILED; | |
6739 | } | |
b4a039bf | 6740 | |
d62a17ae | 6741 | params = ospf_lookup_if_params(ifp, addr); |
6742 | if (params == NULL) { | |
6743 | vty_out(vty, "Ip Address specified is unknown\n"); | |
6744 | return CMD_WARNING_CONFIG_FAILED; | |
6745 | } | |
6746 | params->auth_type = OSPF_AUTH_NOTSET; | |
6747 | UNSET_IF_PARAM(params, auth_type); | |
6748 | if (params != IF_DEF_PARAMS(ifp)) { | |
6749 | ospf_free_if_params(ifp, addr); | |
6750 | ospf_if_update_params(ifp, addr); | |
6751 | } | |
6752 | } else { | |
6753 | if (argv[idx_encryption]->arg[0] == 'n') { | |
6754 | auth_type = OSPF_AUTH_NULL; | |
6755 | } else if (argv[idx_encryption]->arg[0] == 'm') { | |
6756 | auth_type = OSPF_AUTH_CRYPTOGRAPHIC; | |
6757 | } else { | |
6758 | vty_out(vty, "Unexpected input encountered\n"); | |
6759 | return CMD_WARNING_CONFIG_FAILED; | |
6760 | } | |
6761 | /* | |
6762 | * Here we have a case where the user has entered | |
6763 | * 'no ip ospf authentication (null | message_digest )' | |
6764 | * we need to find if we have any ip addresses underneath it | |
6765 | * that | |
6766 | * correspond to the associated type. | |
6767 | */ | |
6768 | if (params->auth_type == auth_type) { | |
6769 | params->auth_type = OSPF_AUTH_NOTSET; | |
6770 | UNSET_IF_PARAM(params, auth_type); | |
6771 | } | |
6772 | ||
6773 | for (rn = route_top(IF_OIFS_PARAMS(ifp)); rn; | |
6774 | rn = route_next(rn)) { | |
6775 | if ((params = rn->info)) { | |
6776 | if (params->auth_type == auth_type) { | |
6777 | params->auth_type = OSPF_AUTH_NOTSET; | |
6778 | UNSET_IF_PARAM(params, auth_type); | |
6779 | if (params != IF_DEF_PARAMS(ifp)) { | |
6780 | ospf_free_if_params( | |
6781 | ifp, rn->p.u.prefix4); | |
6782 | ospf_if_update_params( | |
6783 | ifp, rn->p.u.prefix4); | |
6784 | } | |
6785 | } | |
6786 | } | |
b4a039bf | 6787 | } |
b4a039bf | 6788 | } |
b4a039bf | 6789 | |
d62a17ae | 6790 | return CMD_SUCCESS; |
b4a039bf DS |
6791 | } |
6792 | ||
718e3744 | 6793 | DEFUN (no_ip_ospf_authentication, |
6794 | no_ip_ospf_authentication_addr_cmd, | |
7a7be519 | 6795 | "no ip ospf authentication [A.B.C.D]", |
718e3744 | 6796 | NO_STR |
6797 | "IP Information\n" | |
6798 | "OSPF interface commands\n" | |
6799 | "Enable authentication on this interface\n" | |
efd7904e | 6800 | "Address of interface\n") |
718e3744 | 6801 | { |
d62a17ae | 6802 | VTY_DECLVAR_CONTEXT(interface, ifp); |
6803 | int idx_ipv4 = 4; | |
6804 | struct in_addr addr; | |
6805 | int ret; | |
6806 | struct ospf_if_params *params; | |
6807 | struct route_node *rn; | |
6808 | ||
6809 | params = IF_DEF_PARAMS(ifp); | |
6810 | ||
6811 | if (argc == 5) { | |
6812 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
6813 | if (!ret) { | |
6814 | vty_out(vty, | |
6815 | "Please specify interface address by A.B.C.D\n"); | |
6816 | return CMD_WARNING_CONFIG_FAILED; | |
6817 | } | |
718e3744 | 6818 | |
d62a17ae | 6819 | params = ospf_lookup_if_params(ifp, addr); |
6820 | if (params == NULL) { | |
6821 | vty_out(vty, "Ip Address specified is unknown\n"); | |
6822 | return CMD_WARNING_CONFIG_FAILED; | |
6823 | } | |
718e3744 | 6824 | |
d62a17ae | 6825 | params->auth_type = OSPF_AUTH_NOTSET; |
6826 | UNSET_IF_PARAM(params, auth_type); | |
6827 | if (params != IF_DEF_PARAMS(ifp)) { | |
6828 | ospf_free_if_params(ifp, addr); | |
6829 | ospf_if_update_params(ifp, addr); | |
6830 | } | |
6831 | } else { | |
6832 | /* | |
6833 | * When a user enters 'no ip ospf authentication' | |
6834 | * We should remove all authentication types from | |
6835 | * the interface. | |
6836 | */ | |
6837 | if ((params->auth_type == OSPF_AUTH_NULL) | |
6838 | || (params->auth_type == OSPF_AUTH_CRYPTOGRAPHIC) | |
6839 | || (params->auth_type == OSPF_AUTH_SIMPLE)) { | |
6840 | params->auth_type = OSPF_AUTH_NOTSET; | |
6841 | UNSET_IF_PARAM(params, auth_type); | |
6842 | } | |
813d4307 | 6843 | |
d62a17ae | 6844 | for (rn = route_top(IF_OIFS_PARAMS(ifp)); rn; |
6845 | rn = route_next(rn)) { | |
6846 | if ((params = rn->info)) { | |
6847 | ||
6848 | if ((params->auth_type == OSPF_AUTH_NULL) | |
6849 | || (params->auth_type | |
6850 | == OSPF_AUTH_CRYPTOGRAPHIC) | |
6851 | || (params->auth_type | |
6852 | == OSPF_AUTH_SIMPLE)) { | |
6853 | params->auth_type = OSPF_AUTH_NOTSET; | |
6854 | UNSET_IF_PARAM(params, auth_type); | |
6855 | if (params != IF_DEF_PARAMS(ifp)) { | |
6856 | ospf_free_if_params( | |
6857 | ifp, rn->p.u.prefix4); | |
6858 | ospf_if_update_params( | |
6859 | ifp, rn->p.u.prefix4); | |
6860 | } | |
6861 | } | |
6862 | } | |
b4a039bf | 6863 | } |
b4a039bf | 6864 | } |
d62a17ae | 6865 | |
6866 | return CMD_SUCCESS; | |
718e3744 | 6867 | } |
6868 | ||
0d829fa7 | 6869 | |
718e3744 | 6870 | DEFUN (ip_ospf_authentication_key, |
6871 | ip_ospf_authentication_key_addr_cmd, | |
7a7be519 | 6872 | "ip ospf authentication-key AUTH_KEY [A.B.C.D]", |
718e3744 | 6873 | "IP Information\n" |
6874 | "OSPF interface commands\n" | |
6875 | "Authentication password (key)\n" | |
6876 | "The OSPF password (key)\n" | |
efd7904e | 6877 | "Address of interface\n") |
718e3744 | 6878 | { |
d62a17ae | 6879 | VTY_DECLVAR_CONTEXT(interface, ifp); |
6880 | int idx = 0; | |
6881 | struct in_addr addr; | |
6882 | struct ospf_if_params *params; | |
718e3744 | 6883 | |
d62a17ae | 6884 | params = IF_DEF_PARAMS(ifp); |
6885 | ||
6886 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
6887 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
6888 | vty_out(vty, | |
6889 | "Please specify interface address by A.B.C.D\n"); | |
6890 | return CMD_WARNING_CONFIG_FAILED; | |
6891 | } | |
718e3744 | 6892 | |
d62a17ae | 6893 | params = ospf_get_if_params(ifp, addr); |
6894 | ospf_if_update_params(ifp, addr); | |
6895 | } | |
718e3744 | 6896 | |
4d65d927 QY |
6897 | strlcpy((char *)params->auth_simple, argv[3]->arg, |
6898 | sizeof(params->auth_simple)); | |
d62a17ae | 6899 | SET_IF_PARAM(params, auth_simple); |
718e3744 | 6900 | |
d62a17ae | 6901 | return CMD_SUCCESS; |
718e3744 | 6902 | } |
6903 | ||
7a7be519 | 6904 | DEFUN_HIDDEN (ospf_authentication_key, |
747e489c | 6905 | ospf_authentication_key_cmd, |
0d829fa7 | 6906 | "ospf authentication-key AUTH_KEY [A.B.C.D]", |
747e489c | 6907 | "OSPF interface commands\n" |
baf9eaad | 6908 | VLINK_HELPSTR_AUTH_SIMPLE |
0d829fa7 | 6909 | "Address of interface\n") |
718e3744 | 6910 | { |
d62a17ae | 6911 | return ip_ospf_authentication_key(self, vty, argc, argv); |
718e3744 | 6912 | } |
6913 | ||
7a7be519 | 6914 | DEFUN (no_ip_ospf_authentication_key, |
6915 | no_ip_ospf_authentication_key_authkey_addr_cmd, | |
6916 | "no ip ospf authentication-key [AUTH_KEY [A.B.C.D]]", | |
6917 | NO_STR | |
6918 | "IP Information\n" | |
6919 | "OSPF interface commands\n" | |
baf9eaad CS |
6920 | VLINK_HELPSTR_AUTH_SIMPLE |
6921 | "Address of interface\n") | |
7a7be519 | 6922 | { |
d62a17ae | 6923 | VTY_DECLVAR_CONTEXT(interface, ifp); |
6924 | int idx = 0; | |
6925 | struct in_addr addr; | |
6926 | struct ospf_if_params *params; | |
6927 | params = IF_DEF_PARAMS(ifp); | |
6928 | ||
6929 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
6930 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
6931 | vty_out(vty, | |
6932 | "Please specify interface address by A.B.C.D\n"); | |
6933 | return CMD_WARNING_CONFIG_FAILED; | |
6934 | } | |
7a7be519 | 6935 | |
d62a17ae | 6936 | params = ospf_lookup_if_params(ifp, addr); |
6937 | if (params == NULL) | |
6938 | return CMD_SUCCESS; | |
7a7be519 | 6939 | } |
813d4307 | 6940 | |
d62a17ae | 6941 | memset(params->auth_simple, 0, OSPF_AUTH_SIMPLE_SIZE); |
6942 | UNSET_IF_PARAM(params, auth_simple); | |
718e3744 | 6943 | |
d62a17ae | 6944 | if (params != IF_DEF_PARAMS(ifp)) { |
6945 | ospf_free_if_params(ifp, addr); | |
6946 | ospf_if_update_params(ifp, addr); | |
6947 | } | |
813d4307 | 6948 | |
d62a17ae | 6949 | return CMD_SUCCESS; |
7a7be519 | 6950 | } |
813d4307 | 6951 | |
0d829fa7 QY |
6952 | DEFUN_HIDDEN (no_ospf_authentication_key, |
6953 | no_ospf_authentication_key_authkey_addr_cmd, | |
6954 | "no ospf authentication-key [AUTH_KEY [A.B.C.D]]", | |
6955 | NO_STR | |
6956 | "OSPF interface commands\n" | |
baf9eaad CS |
6957 | VLINK_HELPSTR_AUTH_SIMPLE |
6958 | "Address of interface\n") | |
0d829fa7 | 6959 | { |
d62a17ae | 6960 | return no_ip_ospf_authentication_key(self, vty, argc, argv); |
0d829fa7 QY |
6961 | } |
6962 | ||
718e3744 | 6963 | DEFUN (ip_ospf_message_digest_key, |
537eae3f | 6964 | ip_ospf_message_digest_key_cmd, |
7a7be519 | 6965 | "ip ospf message-digest-key (1-255) md5 KEY [A.B.C.D]", |
718e3744 | 6966 | "IP Information\n" |
6967 | "OSPF interface commands\n" | |
6968 | "Message digest authentication password (key)\n" | |
6969 | "Key ID\n" | |
6970 | "Use MD5 algorithm\n" | |
fefa0d82 QY |
6971 | "The OSPF password (key)\n" |
6972 | "Address of interface\n") | |
718e3744 | 6973 | { |
d62a17ae | 6974 | VTY_DECLVAR_CONTEXT(interface, ifp); |
6975 | struct crypt_key *ck; | |
d7c0a89a | 6976 | uint8_t key_id; |
d62a17ae | 6977 | struct in_addr addr; |
6978 | struct ospf_if_params *params; | |
6979 | ||
6980 | params = IF_DEF_PARAMS(ifp); | |
6981 | int idx = 0; | |
6982 | ||
6983 | argv_find(argv, argc, "(1-255)", &idx); | |
6984 | char *keyid = argv[idx]->arg; | |
6985 | argv_find(argv, argc, "KEY", &idx); | |
6986 | char *cryptkey = argv[idx]->arg; | |
6987 | ||
6988 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
6989 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
6990 | vty_out(vty, | |
6991 | "Please specify interface address by A.B.C.D\n"); | |
6992 | return CMD_WARNING_CONFIG_FAILED; | |
6993 | } | |
6994 | ||
6995 | params = ospf_get_if_params(ifp, addr); | |
6996 | ospf_if_update_params(ifp, addr); | |
718e3744 | 6997 | } |
6998 | ||
d62a17ae | 6999 | key_id = strtol(keyid, NULL, 10); |
7000 | if (ospf_crypt_key_lookup(params->auth_crypt, key_id) != NULL) { | |
7001 | vty_out(vty, "OSPF: Key %d already exists\n", key_id); | |
851fcbae | 7002 | return CMD_WARNING; |
d62a17ae | 7003 | } |
718e3744 | 7004 | |
d62a17ae | 7005 | ck = ospf_crypt_key_new(); |
d7c0a89a | 7006 | ck->key_id = (uint8_t)key_id; |
4d65d927 | 7007 | strlcpy((char *)ck->auth_key, cryptkey, sizeof(ck->auth_key)); |
718e3744 | 7008 | |
d62a17ae | 7009 | ospf_crypt_key_add(params->auth_crypt, ck); |
7010 | SET_IF_PARAM(params, auth_crypt); | |
718e3744 | 7011 | |
d62a17ae | 7012 | return CMD_SUCCESS; |
718e3744 | 7013 | } |
7014 | ||
7a7be519 | 7015 | DEFUN_HIDDEN (ospf_message_digest_key, |
747e489c | 7016 | ospf_message_digest_key_cmd, |
0d829fa7 | 7017 | "ospf message-digest-key (1-255) md5 KEY [A.B.C.D]", |
747e489c DW |
7018 | "OSPF interface commands\n" |
7019 | "Message digest authentication password (key)\n" | |
7020 | "Key ID\n" | |
7021 | "Use MD5 algorithm\n" | |
0d829fa7 QY |
7022 | "The OSPF password (key)\n" |
7023 | "Address of interface\n") | |
7a7be519 | 7024 | { |
d62a17ae | 7025 | return ip_ospf_message_digest_key(self, vty, argc, argv); |
7a7be519 | 7026 | } |
718e3744 | 7027 | |
537eae3f QY |
7028 | DEFUN (no_ip_ospf_message_digest_key, |
7029 | no_ip_ospf_message_digest_key_cmd, | |
0d829fa7 | 7030 | "no ip ospf message-digest-key (1-255) [md5 KEY] [A.B.C.D]", |
813d4307 DW |
7031 | NO_STR |
7032 | "IP Information\n" | |
7033 | "OSPF interface commands\n" | |
7034 | "Message digest authentication password (key)\n" | |
7035 | "Key ID\n" | |
7036 | "Use MD5 algorithm\n" | |
0d829fa7 QY |
7037 | "The OSPF password (key)\n" |
7038 | "Address of interface\n") | |
813d4307 | 7039 | { |
d62a17ae | 7040 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7041 | int idx = 0; | |
7042 | struct crypt_key *ck; | |
7043 | int key_id; | |
7044 | struct in_addr addr; | |
7045 | struct ospf_if_params *params; | |
7046 | params = IF_DEF_PARAMS(ifp); | |
7047 | ||
7048 | argv_find(argv, argc, "(1-255)", &idx); | |
7049 | char *keyid = argv[idx]->arg; | |
7050 | ||
7051 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
7052 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
7053 | vty_out(vty, | |
7054 | "Please specify interface address by A.B.C.D\n"); | |
7055 | return CMD_WARNING_CONFIG_FAILED; | |
7056 | } | |
7a7be519 | 7057 | |
d62a17ae | 7058 | params = ospf_lookup_if_params(ifp, addr); |
7059 | if (params == NULL) | |
7060 | return CMD_SUCCESS; | |
7a7be519 | 7061 | } |
7062 | ||
d62a17ae | 7063 | key_id = strtol(keyid, NULL, 10); |
7064 | ck = ospf_crypt_key_lookup(params->auth_crypt, key_id); | |
7065 | if (ck == NULL) { | |
7066 | vty_out(vty, "OSPF: Key %d does not exist\n", key_id); | |
7067 | return CMD_WARNING_CONFIG_FAILED; | |
7068 | } | |
7a7be519 | 7069 | |
d62a17ae | 7070 | ospf_crypt_key_delete(params->auth_crypt, key_id); |
7a7be519 | 7071 | |
d62a17ae | 7072 | if (params != IF_DEF_PARAMS(ifp)) { |
7073 | ospf_free_if_params(ifp, addr); | |
7074 | ospf_if_update_params(ifp, addr); | |
7075 | } | |
7a7be519 | 7076 | |
d62a17ae | 7077 | return CMD_SUCCESS; |
7a7be519 | 7078 | } |
813d4307 | 7079 | |
0d829fa7 | 7080 | DEFUN_HIDDEN (no_ospf_message_digest_key, |
537eae3f | 7081 | no_ospf_message_digest_key_cmd, |
0d829fa7 QY |
7082 | "no ospf message-digest-key (1-255) [md5 KEY] [A.B.C.D]", |
7083 | NO_STR | |
7084 | "OSPF interface commands\n" | |
7085 | "Message digest authentication password (key)\n" | |
7086 | "Key ID\n" | |
efd7904e RW |
7087 | "Use MD5 algorithm\n" |
7088 | "The OSPF password (key)\n" | |
7089 | "Address of interface\n") | |
718e3744 | 7090 | { |
d62a17ae | 7091 | return no_ip_ospf_message_digest_key(self, vty, argc, argv); |
718e3744 | 7092 | } |
7093 | ||
718e3744 | 7094 | DEFUN (ip_ospf_cost, |
5c2fc921 | 7095 | ip_ospf_cost_cmd, |
7a7be519 | 7096 | "ip ospf cost (1-65535) [A.B.C.D]", |
718e3744 | 7097 | "IP Information\n" |
7098 | "OSPF interface commands\n" | |
7099 | "Interface cost\n" | |
7100 | "Cost\n" | |
5c2fc921 | 7101 | "Address of interface\n") |
718e3744 | 7102 | { |
d62a17ae | 7103 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7104 | int idx = 0; | |
d7c0a89a | 7105 | uint32_t cost = OSPF_OUTPUT_COST_DEFAULT; |
d62a17ae | 7106 | struct in_addr addr; |
7107 | struct ospf_if_params *params; | |
7108 | params = IF_DEF_PARAMS(ifp); | |
7109 | ||
7110 | // get arguments | |
7111 | char *coststr = NULL, *ifaddr = NULL; | |
35955c14 | 7112 | |
c31a793b VJ |
7113 | argv_find(argv, argc, "(1-65535)", &idx); |
7114 | coststr = argv[idx]->arg; | |
d62a17ae | 7115 | cost = strtol(coststr, NULL, 10); |
7116 | ||
c31a793b | 7117 | ifaddr = argv_find(argv, argc, "A.B.C.D", &idx) ? argv[idx]->arg : NULL; |
d62a17ae | 7118 | if (ifaddr) { |
7119 | if (!inet_aton(ifaddr, &addr)) { | |
7120 | vty_out(vty, | |
7121 | "Please specify interface address by A.B.C.D\n"); | |
7122 | return CMD_WARNING_CONFIG_FAILED; | |
7123 | } | |
718e3744 | 7124 | |
d62a17ae | 7125 | params = ospf_get_if_params(ifp, addr); |
7126 | ospf_if_update_params(ifp, addr); | |
718e3744 | 7127 | } |
7128 | ||
d62a17ae | 7129 | SET_IF_PARAM(params, output_cost_cmd); |
7130 | params->output_cost_cmd = cost; | |
718e3744 | 7131 | |
d62a17ae | 7132 | ospf_if_recalculate_output_cost(ifp); |
5c2fc921 | 7133 | |
d62a17ae | 7134 | return CMD_SUCCESS; |
718e3744 | 7135 | } |
7136 | ||
7a7be519 | 7137 | DEFUN_HIDDEN (ospf_cost, |
5c2fc921 QY |
7138 | ospf_cost_cmd, |
7139 | "ospf cost (1-65535) [A.B.C.D]", | |
747e489c DW |
7140 | "OSPF interface commands\n" |
7141 | "Interface cost\n" | |
7142 | "Cost\n" | |
5c2fc921 | 7143 | "Address of interface\n") |
7a7be519 | 7144 | { |
d62a17ae | 7145 | return ip_ospf_cost(self, vty, argc, argv); |
7a7be519 | 7146 | } |
9eff36b3 | 7147 | |
718e3744 | 7148 | DEFUN (no_ip_ospf_cost, |
5c2fc921 QY |
7149 | no_ip_ospf_cost_cmd, |
7150 | "no ip ospf cost [(1-65535)] [A.B.C.D]", | |
718e3744 | 7151 | NO_STR |
efd7904e | 7152 | "IP Information\n" |
718e3744 | 7153 | "OSPF interface commands\n" |
7154 | "Interface cost\n" | |
efd7904e RW |
7155 | "Cost\n" |
7156 | "Address of interface\n") | |
718e3744 | 7157 | { |
d62a17ae | 7158 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7159 | int idx = 0; | |
7160 | struct in_addr addr; | |
7161 | struct ospf_if_params *params; | |
7a7be519 | 7162 | |
d62a17ae | 7163 | params = IF_DEF_PARAMS(ifp); |
718e3744 | 7164 | |
d62a17ae | 7165 | // get arguments |
7166 | char *ifaddr = NULL; | |
7167 | ifaddr = argv_find(argv, argc, "A.B.C.D", &idx) ? argv[idx]->arg : NULL; | |
718e3744 | 7168 | |
d62a17ae | 7169 | /* According to the semantics we are mimicking "no ip ospf cost N" is |
7170 | * always treated as "no ip ospf cost" regardless of the actual value | |
7171 | * of N already configured for the interface. Thus ignore cost. */ | |
7a7be519 | 7172 | |
d62a17ae | 7173 | if (ifaddr) { |
7174 | if (!inet_aton(ifaddr, &addr)) { | |
7175 | vty_out(vty, | |
7176 | "Please specify interface address by A.B.C.D\n"); | |
7177 | return CMD_WARNING_CONFIG_FAILED; | |
7178 | } | |
7a7be519 | 7179 | |
d62a17ae | 7180 | params = ospf_lookup_if_params(ifp, addr); |
7181 | if (params == NULL) | |
7182 | return CMD_SUCCESS; | |
7183 | } | |
7a7be519 | 7184 | |
d62a17ae | 7185 | UNSET_IF_PARAM(params, output_cost_cmd); |
7a7be519 | 7186 | |
d62a17ae | 7187 | if (params != IF_DEF_PARAMS(ifp)) { |
7188 | ospf_free_if_params(ifp, addr); | |
7189 | ospf_if_update_params(ifp, addr); | |
7190 | } | |
7a7be519 | 7191 | |
d62a17ae | 7192 | ospf_if_recalculate_output_cost(ifp); |
7a7be519 | 7193 | |
d62a17ae | 7194 | return CMD_SUCCESS; |
7a7be519 | 7195 | } |
9eff36b3 | 7196 | |
5c2fc921 QY |
7197 | DEFUN_HIDDEN (no_ospf_cost, |
7198 | no_ospf_cost_cmd, | |
7199 | "no ospf cost [(1-65535)] [A.B.C.D]", | |
7200 | NO_STR | |
7201 | "OSPF interface commands\n" | |
7202 | "Interface cost\n" | |
7203 | "Cost\n" | |
7204 | "Address of interface\n") | |
827341b7 | 7205 | { |
d62a17ae | 7206 | return no_ip_ospf_cost(self, vty, argc, argv); |
827341b7 DO |
7207 | } |
7208 | ||
d62a17ae | 7209 | static void ospf_nbr_timer_update(struct ospf_interface *oi) |
718e3744 | 7210 | { |
d62a17ae | 7211 | struct route_node *rn; |
7212 | struct ospf_neighbor *nbr; | |
718e3744 | 7213 | |
d62a17ae | 7214 | for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) |
7215 | if ((nbr = rn->info)) { | |
7216 | nbr->v_inactivity = OSPF_IF_PARAM(oi, v_wait); | |
7217 | nbr->v_db_desc = OSPF_IF_PARAM(oi, retransmit_interval); | |
7218 | nbr->v_ls_req = OSPF_IF_PARAM(oi, retransmit_interval); | |
7219 | nbr->v_ls_upd = OSPF_IF_PARAM(oi, retransmit_interval); | |
7220 | } | |
718e3744 | 7221 | } |
7222 | ||
d62a17ae | 7223 | static int ospf_vty_dead_interval_set(struct vty *vty, const char *interval_str, |
7224 | const char *nbr_str, | |
7225 | const char *fast_hello_str) | |
7226 | { | |
7227 | VTY_DECLVAR_CONTEXT(interface, ifp); | |
d7c0a89a QY |
7228 | uint32_t seconds; |
7229 | uint8_t hellomult; | |
d62a17ae | 7230 | struct in_addr addr; |
7231 | int ret; | |
7232 | struct ospf_if_params *params; | |
7233 | struct ospf_interface *oi; | |
7234 | struct route_node *rn; | |
718e3744 | 7235 | |
d62a17ae | 7236 | params = IF_DEF_PARAMS(ifp); |
7237 | ||
7238 | if (nbr_str) { | |
7239 | ret = inet_aton(nbr_str, &addr); | |
7240 | if (!ret) { | |
7241 | vty_out(vty, | |
7242 | "Please specify interface address by A.B.C.D\n"); | |
7243 | return CMD_WARNING_CONFIG_FAILED; | |
7244 | } | |
7245 | ||
7246 | params = ospf_get_if_params(ifp, addr); | |
7247 | ospf_if_update_params(ifp, addr); | |
7248 | } | |
7249 | ||
7250 | if (interval_str) { | |
7251 | seconds = strtoul(interval_str, NULL, 10); | |
7252 | ||
7253 | /* reset fast_hello too, just to be sure */ | |
7254 | UNSET_IF_PARAM(params, fast_hello); | |
7255 | params->fast_hello = OSPF_FAST_HELLO_DEFAULT; | |
7256 | } else if (fast_hello_str) { | |
7257 | hellomult = strtoul(fast_hello_str, NULL, 10); | |
7258 | /* 1s dead-interval with sub-second hellos desired */ | |
7259 | seconds = OSPF_ROUTER_DEAD_INTERVAL_MINIMAL; | |
7260 | SET_IF_PARAM(params, fast_hello); | |
7261 | params->fast_hello = hellomult; | |
7262 | } else { | |
7263 | vty_out(vty, | |
7264 | "Please specify dead-interval or hello-multiplier\n"); | |
7265 | return CMD_WARNING_CONFIG_FAILED; | |
7266 | } | |
7267 | ||
7268 | SET_IF_PARAM(params, v_wait); | |
7269 | params->v_wait = seconds; | |
7270 | ||
7271 | /* Update timer values in neighbor structure. */ | |
7272 | if (nbr_str) { | |
b5a8894d CS |
7273 | struct ospf *ospf = NULL; |
7274 | ||
a36898e7 | 7275 | ospf = ospf_lookup_by_vrf_id(ifp->vrf_id); |
b5a8894d | 7276 | if (ospf) { |
d62a17ae | 7277 | oi = ospf_if_lookup_by_local_addr(ospf, ifp, addr); |
7278 | if (oi) | |
7279 | ospf_nbr_timer_update(oi); | |
7280 | } | |
7281 | } else { | |
7282 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) | |
7283 | if ((oi = rn->info)) | |
7284 | ospf_nbr_timer_update(oi); | |
7285 | } | |
7286 | ||
7287 | return CMD_SUCCESS; | |
718e3744 | 7288 | } |
7289 | ||
f9ad937f | 7290 | DEFUN (ip_ospf_dead_interval, |
0d829fa7 | 7291 | ip_ospf_dead_interval_cmd, |
7a7be519 | 7292 | "ip ospf dead-interval (1-65535) [A.B.C.D]", |
f9ad937f | 7293 | "IP Information\n" |
7294 | "OSPF interface commands\n" | |
99a522c7 | 7295 | "Interval time after which a neighbor is declared down\n" |
f9ad937f | 7296 | "Seconds\n" |
7297 | "Address of interface\n") | |
7298 | { | |
d62a17ae | 7299 | int idx = 0; |
7300 | char *interval = argv_find(argv, argc, "(1-65535)", &idx) | |
7301 | ? argv[idx]->arg | |
7302 | : NULL; | |
7303 | char *ifaddr = | |
7304 | argv_find(argv, argc, "A.B.C.D", &idx) ? argv[idx]->arg : NULL; | |
7305 | return ospf_vty_dead_interval_set(vty, interval, ifaddr, NULL); | |
f9ad937f | 7306 | } |
7307 | ||
718e3744 | 7308 | |
7a7be519 | 7309 | DEFUN_HIDDEN (ospf_dead_interval, |
747e489c | 7310 | ospf_dead_interval_cmd, |
0d829fa7 | 7311 | "ospf dead-interval (1-65535) [A.B.C.D]", |
747e489c | 7312 | "OSPF interface commands\n" |
99a522c7 | 7313 | "Interval time after which a neighbor is declared down\n" |
0d829fa7 QY |
7314 | "Seconds\n" |
7315 | "Address of interface\n") | |
7a7be519 | 7316 | { |
d62a17ae | 7317 | return ip_ospf_dead_interval(self, vty, argc, argv); |
7a7be519 | 7318 | } |
718e3744 | 7319 | |
f9ad937f | 7320 | DEFUN (ip_ospf_dead_interval_minimal, |
7321 | ip_ospf_dead_interval_minimal_addr_cmd, | |
7a7be519 | 7322 | "ip ospf dead-interval minimal hello-multiplier (1-10) [A.B.C.D]", |
f9ad937f | 7323 | "IP Information\n" |
7324 | "OSPF interface commands\n" | |
99a522c7 | 7325 | "Interval time after which a neighbor is declared down\n" |
f9ad937f | 7326 | "Minimal 1s dead-interval with fast sub-second hellos\n" |
7327 | "Hello multiplier factor\n" | |
7328 | "Number of Hellos to send each second\n" | |
7329 | "Address of interface\n") | |
7330 | { | |
d62a17ae | 7331 | int idx_number = 5; |
7332 | int idx_ipv4 = 6; | |
7333 | if (argc == 7) | |
7334 | return ospf_vty_dead_interval_set( | |
7335 | vty, NULL, argv[idx_ipv4]->arg, argv[idx_number]->arg); | |
7336 | else | |
7337 | return ospf_vty_dead_interval_set(vty, NULL, NULL, | |
7338 | argv[idx_number]->arg); | |
f9ad937f | 7339 | } |
7340 | ||
718e3744 | 7341 | DEFUN (no_ip_ospf_dead_interval, |
0d829fa7 | 7342 | no_ip_ospf_dead_interval_cmd, |
e83a9414 | 7343 | "no ip ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]", |
718e3744 | 7344 | NO_STR |
7345 | "IP Information\n" | |
7346 | "OSPF interface commands\n" | |
99a522c7 | 7347 | "Interval time after which a neighbor is declared down\n" |
f9dfba8d | 7348 | "Seconds\n" |
efd7904e RW |
7349 | "Minimal 1s dead-interval with fast sub-second hellos\n" |
7350 | "Hello multiplier factor\n" | |
7351 | "Number of Hellos to send each second\n" | |
7352 | "Address of interface\n") | |
718e3744 | 7353 | { |
d62a17ae | 7354 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7355 | int idx_ipv4 = argc - 1; | |
7356 | struct in_addr addr = {.s_addr = 0L}; | |
7357 | int ret; | |
7358 | struct ospf_if_params *params; | |
7359 | struct ospf_interface *oi; | |
7360 | struct route_node *rn; | |
7361 | ||
7362 | params = IF_DEF_PARAMS(ifp); | |
7363 | ||
7364 | if (argv[idx_ipv4]->type == IPV4_TKN) { | |
7365 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
7366 | if (!ret) { | |
7367 | vty_out(vty, | |
7368 | "Please specify interface address by A.B.C.D\n"); | |
7369 | return CMD_WARNING_CONFIG_FAILED; | |
7370 | } | |
020709f9 | 7371 | |
d62a17ae | 7372 | params = ospf_lookup_if_params(ifp, addr); |
7373 | if (params == NULL) | |
7374 | return CMD_SUCCESS; | |
7375 | } | |
718e3744 | 7376 | |
d62a17ae | 7377 | UNSET_IF_PARAM(params, v_wait); |
7378 | params->v_wait = OSPF_ROUTER_DEAD_INTERVAL_DEFAULT; | |
7379 | ||
7380 | UNSET_IF_PARAM(params, fast_hello); | |
7381 | params->fast_hello = OSPF_FAST_HELLO_DEFAULT; | |
7382 | ||
7383 | if (params != IF_DEF_PARAMS(ifp)) { | |
7384 | ospf_free_if_params(ifp, addr); | |
7385 | ospf_if_update_params(ifp, addr); | |
718e3744 | 7386 | } |
7387 | ||
d62a17ae | 7388 | /* Update timer values in neighbor structure. */ |
7389 | if (argc == 1) { | |
b5a8894d | 7390 | struct ospf *ospf = NULL; |
718e3744 | 7391 | |
a36898e7 | 7392 | ospf = ospf_lookup_by_vrf_id(ifp->vrf_id); |
b5a8894d | 7393 | if (ospf) { |
d62a17ae | 7394 | oi = ospf_if_lookup_by_local_addr(ospf, ifp, addr); |
7395 | if (oi) | |
7396 | ospf_nbr_timer_update(oi); | |
7397 | } | |
7398 | } else { | |
7399 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) | |
7400 | if ((oi = rn->info)) | |
7401 | ospf_nbr_timer_update(oi); | |
7402 | } | |
7403 | ||
7404 | return CMD_SUCCESS; | |
718e3744 | 7405 | } |
7406 | ||
0d829fa7 QY |
7407 | DEFUN_HIDDEN (no_ospf_dead_interval, |
7408 | no_ospf_dead_interval_cmd, | |
7409 | "no ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]", | |
7410 | NO_STR | |
7411 | "OSPF interface commands\n" | |
99a522c7 | 7412 | "Interval time after which a neighbor is declared down\n" |
0d829fa7 | 7413 | "Seconds\n" |
efd7904e RW |
7414 | "Minimal 1s dead-interval with fast sub-second hellos\n" |
7415 | "Hello multiplier factor\n" | |
7416 | "Number of Hellos to send each second\n" | |
7417 | "Address of interface\n") | |
0d829fa7 | 7418 | { |
d62a17ae | 7419 | return no_ip_ospf_dead_interval(self, vty, argc, argv); |
0d829fa7 QY |
7420 | } |
7421 | ||
718e3744 | 7422 | DEFUN (ip_ospf_hello_interval, |
0d829fa7 | 7423 | ip_ospf_hello_interval_cmd, |
7a7be519 | 7424 | "ip ospf hello-interval (1-65535) [A.B.C.D]", |
718e3744 | 7425 | "IP Information\n" |
7426 | "OSPF interface commands\n" | |
7427 | "Time between HELLO packets\n" | |
7428 | "Seconds\n" | |
0d829fa7 | 7429 | "Address of interface\n") |
718e3744 | 7430 | { |
d62a17ae | 7431 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7432 | int idx = 0; | |
7433 | struct in_addr addr; | |
7434 | struct ospf_if_params *params; | |
7435 | params = IF_DEF_PARAMS(ifp); | |
d7c0a89a | 7436 | uint32_t seconds = 0; |
d62a17ae | 7437 | |
7438 | argv_find(argv, argc, "(1-65535)", &idx); | |
7439 | seconds = strtol(argv[idx]->arg, NULL, 10); | |
7440 | ||
7441 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
7442 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
7443 | vty_out(vty, | |
7444 | "Please specify interface address by A.B.C.D\n"); | |
7445 | return CMD_WARNING_CONFIG_FAILED; | |
7446 | } | |
718e3744 | 7447 | |
d62a17ae | 7448 | params = ospf_get_if_params(ifp, addr); |
7449 | ospf_if_update_params(ifp, addr); | |
7450 | } | |
718e3744 | 7451 | |
d62a17ae | 7452 | SET_IF_PARAM(params, v_hello); |
7453 | params->v_hello = seconds; | |
718e3744 | 7454 | |
d62a17ae | 7455 | return CMD_SUCCESS; |
718e3744 | 7456 | } |
7457 | ||
7a7be519 | 7458 | DEFUN_HIDDEN (ospf_hello_interval, |
747e489c | 7459 | ospf_hello_interval_cmd, |
0d829fa7 | 7460 | "ospf hello-interval (1-65535) [A.B.C.D]", |
747e489c DW |
7461 | "OSPF interface commands\n" |
7462 | "Time between HELLO packets\n" | |
0d829fa7 QY |
7463 | "Seconds\n" |
7464 | "Address of interface\n") | |
7a7be519 | 7465 | { |
d62a17ae | 7466 | return ip_ospf_hello_interval(self, vty, argc, argv); |
7a7be519 | 7467 | } |
718e3744 | 7468 | |
7469 | DEFUN (no_ip_ospf_hello_interval, | |
0d829fa7 QY |
7470 | no_ip_ospf_hello_interval_cmd, |
7471 | "no ip ospf hello-interval [(1-65535) [A.B.C.D]]", | |
718e3744 | 7472 | NO_STR |
7473 | "IP Information\n" | |
7474 | "OSPF interface commands\n" | |
0d829fa7 | 7475 | "Time between HELLO packets\n" // ignored |
f9dfba8d | 7476 | "Seconds\n" |
0d829fa7 | 7477 | "Address of interface\n") |
718e3744 | 7478 | { |
d62a17ae | 7479 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7480 | int idx = 0; | |
7481 | struct in_addr addr; | |
7482 | struct ospf_if_params *params; | |
df581cd3 | 7483 | |
d62a17ae | 7484 | params = IF_DEF_PARAMS(ifp); |
718e3744 | 7485 | |
d62a17ae | 7486 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { |
7487 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
7488 | vty_out(vty, | |
7489 | "Please specify interface address by A.B.C.D\n"); | |
7490 | return CMD_WARNING_CONFIG_FAILED; | |
7491 | } | |
718e3744 | 7492 | |
d62a17ae | 7493 | params = ospf_lookup_if_params(ifp, addr); |
7494 | if (params == NULL) | |
7495 | return CMD_SUCCESS; | |
7496 | } | |
718e3744 | 7497 | |
d62a17ae | 7498 | UNSET_IF_PARAM(params, v_hello); |
7499 | params->v_hello = OSPF_HELLO_INTERVAL_DEFAULT; | |
718e3744 | 7500 | |
d62a17ae | 7501 | if (params != IF_DEF_PARAMS(ifp)) { |
7502 | ospf_free_if_params(ifp, addr); | |
7503 | ospf_if_update_params(ifp, addr); | |
7504 | } | |
718e3744 | 7505 | |
d62a17ae | 7506 | return CMD_SUCCESS; |
718e3744 | 7507 | } |
7508 | ||
0d829fa7 QY |
7509 | DEFUN_HIDDEN (no_ospf_hello_interval, |
7510 | no_ospf_hello_interval_cmd, | |
7511 | "no ospf hello-interval [(1-65535) [A.B.C.D]]", | |
7512 | NO_STR | |
7513 | "OSPF interface commands\n" | |
7514 | "Time between HELLO packets\n" // ignored | |
7515 | "Seconds\n" | |
7516 | "Address of interface\n") | |
7517 | { | |
d62a17ae | 7518 | return no_ip_ospf_hello_interval(self, vty, argc, argv); |
0d829fa7 | 7519 | } |
718e3744 | 7520 | |
7521 | DEFUN (ip_ospf_network, | |
7522 | ip_ospf_network_cmd, | |
6147e2c6 | 7523 | "ip ospf network <broadcast|non-broadcast|point-to-multipoint|point-to-point>", |
718e3744 | 7524 | "IP Information\n" |
7525 | "OSPF interface commands\n" | |
7526 | "Network type\n" | |
7527 | "Specify OSPF broadcast multi-access network\n" | |
7528 | "Specify OSPF NBMA network\n" | |
7529 | "Specify OSPF point-to-multipoint network\n" | |
7530 | "Specify OSPF point-to-point network\n") | |
7531 | { | |
d62a17ae | 7532 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7533 | int idx = 0; | |
7534 | int old_type = IF_DEF_PARAMS(ifp)->type; | |
7535 | struct route_node *rn; | |
718e3744 | 7536 | |
d62a17ae | 7537 | if (old_type == OSPF_IFTYPE_LOOPBACK) { |
7538 | vty_out(vty, | |
7539 | "This is a loopback interface. Can't set network type.\n"); | |
7540 | return CMD_WARNING_CONFIG_FAILED; | |
7541 | } | |
718e3744 | 7542 | |
d62a17ae | 7543 | if (argv_find(argv, argc, "broadcast", &idx)) |
7544 | IF_DEF_PARAMS(ifp)->type = OSPF_IFTYPE_BROADCAST; | |
7545 | else if (argv_find(argv, argc, "non-broadcast", &idx)) | |
7546 | IF_DEF_PARAMS(ifp)->type = OSPF_IFTYPE_NBMA; | |
7547 | else if (argv_find(argv, argc, "point-to-multipoint", &idx)) | |
7548 | IF_DEF_PARAMS(ifp)->type = OSPF_IFTYPE_POINTOMULTIPOINT; | |
7549 | else if (argv_find(argv, argc, "point-to-point", &idx)) | |
7550 | IF_DEF_PARAMS(ifp)->type = OSPF_IFTYPE_POINTOPOINT; | |
718e3744 | 7551 | |
d62a17ae | 7552 | if (IF_DEF_PARAMS(ifp)->type == old_type) |
7553 | return CMD_SUCCESS; | |
7554 | ||
7555 | SET_IF_PARAM(IF_DEF_PARAMS(ifp), type); | |
7556 | ||
7557 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { | |
7558 | struct ospf_interface *oi = rn->info; | |
7559 | ||
7560 | if (!oi) | |
7561 | continue; | |
7562 | ||
7563 | oi->type = IF_DEF_PARAMS(ifp)->type; | |
7564 | ||
7565 | if (oi->state > ISM_Down) { | |
7566 | OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceDown); | |
7567 | OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceUp); | |
7568 | } | |
7a7be519 | 7569 | } |
7a7be519 | 7570 | |
d62a17ae | 7571 | return CMD_SUCCESS; |
7a7be519 | 7572 | } |
7573 | ||
7574 | DEFUN_HIDDEN (ospf_network, | |
7575 | ospf_network_cmd, | |
e83a9414 | 7576 | "ospf network <broadcast|non-broadcast|point-to-multipoint|point-to-point>", |
7a7be519 | 7577 | "OSPF interface commands\n" |
7578 | "Network type\n" | |
7579 | "Specify OSPF broadcast multi-access network\n" | |
7580 | "Specify OSPF NBMA network\n" | |
7581 | "Specify OSPF point-to-multipoint network\n" | |
7582 | "Specify OSPF point-to-point network\n") | |
7583 | { | |
d62a17ae | 7584 | return ip_ospf_network(self, vty, argc, argv); |
7a7be519 | 7585 | } |
7586 | ||
7587 | DEFUN (no_ip_ospf_network, | |
7588 | no_ip_ospf_network_cmd, | |
7589 | "no ip ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]", | |
7590 | NO_STR | |
7591 | "IP Information\n" | |
7592 | "OSPF interface commands\n" | |
7593 | "Network type\n" | |
7594 | "Specify OSPF broadcast multi-access network\n" | |
7595 | "Specify OSPF NBMA network\n" | |
7596 | "Specify OSPF point-to-multipoint network\n" | |
7597 | "Specify OSPF point-to-point network\n") | |
22b27e95 | 7598 | { |
d62a17ae | 7599 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7600 | int old_type = IF_DEF_PARAMS(ifp)->type; | |
7601 | struct route_node *rn; | |
7a7be519 | 7602 | |
d62a17ae | 7603 | IF_DEF_PARAMS(ifp)->type = ospf_default_iftype(ifp); |
7a7be519 | 7604 | |
d62a17ae | 7605 | if (IF_DEF_PARAMS(ifp)->type == old_type) |
7606 | return CMD_SUCCESS; | |
7a7be519 | 7607 | |
d62a17ae | 7608 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { |
7609 | struct ospf_interface *oi = rn->info; | |
7a7be519 | 7610 | |
d62a17ae | 7611 | if (!oi) |
7612 | continue; | |
7a7be519 | 7613 | |
d62a17ae | 7614 | oi->type = IF_DEF_PARAMS(ifp)->type; |
7a7be519 | 7615 | |
d62a17ae | 7616 | if (oi->state > ISM_Down) { |
7617 | OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceDown); | |
7618 | OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceUp); | |
7619 | } | |
7a7be519 | 7620 | } |
7a7be519 | 7621 | |
d62a17ae | 7622 | return CMD_SUCCESS; |
7a7be519 | 7623 | } |
7624 | ||
0d829fa7 QY |
7625 | DEFUN_HIDDEN (no_ospf_network, |
7626 | no_ospf_network_cmd, | |
7627 | "no ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]", | |
7628 | NO_STR | |
7629 | "OSPF interface commands\n" | |
7630 | "Network type\n" | |
7631 | "Specify OSPF broadcast multi-access network\n" | |
7632 | "Specify OSPF NBMA network\n" | |
7633 | "Specify OSPF point-to-multipoint network\n" | |
7634 | "Specify OSPF point-to-point network\n") | |
7635 | { | |
d62a17ae | 7636 | return no_ip_ospf_network(self, vty, argc, argv); |
0d829fa7 QY |
7637 | } |
7638 | ||
7a7be519 | 7639 | DEFUN (ip_ospf_priority, |
537eae3f | 7640 | ip_ospf_priority_cmd, |
7a7be519 | 7641 | "ip ospf priority (0-255) [A.B.C.D]", |
7642 | "IP Information\n" | |
7643 | "OSPF interface commands\n" | |
7644 | "Router priority\n" | |
7645 | "Priority\n" | |
efd7904e | 7646 | "Address of interface\n") |
7a7be519 | 7647 | { |
d62a17ae | 7648 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7649 | int idx = 0; | |
7650 | long priority; | |
7651 | struct route_node *rn; | |
7652 | struct in_addr addr; | |
7653 | struct ospf_if_params *params; | |
7654 | params = IF_DEF_PARAMS(ifp); | |
7655 | ||
7656 | argv_find(argv, argc, "(0-255)", &idx); | |
7657 | priority = strtol(argv[idx]->arg, NULL, 10); | |
7658 | ||
7659 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
7660 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
7661 | vty_out(vty, | |
7662 | "Please specify interface address by A.B.C.D\n"); | |
7663 | return CMD_WARNING_CONFIG_FAILED; | |
7664 | } | |
7a7be519 | 7665 | |
d62a17ae | 7666 | params = ospf_get_if_params(ifp, addr); |
7667 | ospf_if_update_params(ifp, addr); | |
7a7be519 | 7668 | } |
7669 | ||
d62a17ae | 7670 | SET_IF_PARAM(params, priority); |
7671 | params->priority = priority; | |
7a7be519 | 7672 | |
d62a17ae | 7673 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { |
7674 | struct ospf_interface *oi = rn->info; | |
7a7be519 | 7675 | |
d62a17ae | 7676 | if (!oi) |
7677 | continue; | |
7a7be519 | 7678 | |
d62a17ae | 7679 | if (PRIORITY(oi) != OSPF_IF_PARAM(oi, priority)) { |
7680 | PRIORITY(oi) = OSPF_IF_PARAM(oi, priority); | |
7681 | OSPF_ISM_EVENT_SCHEDULE(oi, ISM_NeighborChange); | |
7682 | } | |
718e3744 | 7683 | } |
718e3744 | 7684 | |
d62a17ae | 7685 | return CMD_SUCCESS; |
718e3744 | 7686 | } |
7687 | ||
7a7be519 | 7688 | DEFUN_HIDDEN (ospf_priority, |
7689 | ospf_priority_cmd, | |
0d829fa7 | 7690 | "ospf priority (0-255) [A.B.C.D]", |
7a7be519 | 7691 | "OSPF interface commands\n" |
7692 | "Router priority\n" | |
3a2d747c | 7693 | "Priority\n" |
efd7904e | 7694 | "Address of interface\n") |
718e3744 | 7695 | { |
d62a17ae | 7696 | return ip_ospf_priority(self, vty, argc, argv); |
718e3744 | 7697 | } |
7698 | ||
718e3744 | 7699 | DEFUN (no_ip_ospf_priority, |
537eae3f | 7700 | no_ip_ospf_priority_cmd, |
7a7be519 | 7701 | "no ip ospf priority [(0-255) [A.B.C.D]]", |
718e3744 | 7702 | NO_STR |
7703 | "IP Information\n" | |
7704 | "OSPF interface commands\n" | |
0d829fa7 | 7705 | "Router priority\n" // ignored |
813d4307 | 7706 | "Priority\n" |
efd7904e | 7707 | "Address of interface\n") |
718e3744 | 7708 | { |
d62a17ae | 7709 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7710 | int idx = 0; | |
7711 | struct route_node *rn; | |
7712 | struct in_addr addr; | |
7713 | struct ospf_if_params *params; | |
7714 | ||
7715 | params = IF_DEF_PARAMS(ifp); | |
7716 | ||
7717 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
7718 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
7719 | vty_out(vty, | |
7720 | "Please specify interface address by A.B.C.D\n"); | |
7721 | return CMD_WARNING_CONFIG_FAILED; | |
7722 | } | |
7723 | ||
7724 | params = ospf_lookup_if_params(ifp, addr); | |
7725 | if (params == NULL) | |
7726 | return CMD_SUCCESS; | |
718e3744 | 7727 | } |
7728 | ||
d62a17ae | 7729 | UNSET_IF_PARAM(params, priority); |
7730 | params->priority = OSPF_ROUTER_PRIORITY_DEFAULT; | |
7731 | ||
7732 | if (params != IF_DEF_PARAMS(ifp)) { | |
7733 | ospf_free_if_params(ifp, addr); | |
7734 | ospf_if_update_params(ifp, addr); | |
718e3744 | 7735 | } |
d62a17ae | 7736 | |
7737 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { | |
7738 | struct ospf_interface *oi = rn->info; | |
7739 | ||
7740 | if (!oi) | |
7741 | continue; | |
7742 | ||
7743 | if (PRIORITY(oi) != OSPF_IF_PARAM(oi, priority)) { | |
7744 | PRIORITY(oi) = OSPF_IF_PARAM(oi, priority); | |
7745 | OSPF_ISM_EVENT_SCHEDULE(oi, ISM_NeighborChange); | |
7746 | } | |
7747 | } | |
7748 | ||
7749 | return CMD_SUCCESS; | |
718e3744 | 7750 | } |
7751 | ||
0d829fa7 | 7752 | DEFUN_HIDDEN (no_ospf_priority, |
537eae3f | 7753 | no_ospf_priority_cmd, |
0d829fa7 QY |
7754 | "no ospf priority [(0-255) [A.B.C.D]]", |
7755 | NO_STR | |
7756 | "OSPF interface commands\n" | |
7757 | "Router priority\n" | |
7758 | "Priority\n" | |
efd7904e | 7759 | "Address of interface\n") |
0d829fa7 | 7760 | { |
d62a17ae | 7761 | return no_ip_ospf_priority(self, vty, argc, argv); |
0d829fa7 | 7762 | } |
a1afa410 | 7763 | |
718e3744 | 7764 | DEFUN (ip_ospf_retransmit_interval, |
7765 | ip_ospf_retransmit_interval_addr_cmd, | |
7a7be519 | 7766 | "ip ospf retransmit-interval (3-65535) [A.B.C.D]", |
718e3744 | 7767 | "IP Information\n" |
7768 | "OSPF interface commands\n" | |
7769 | "Time between retransmitting lost link state advertisements\n" | |
7770 | "Seconds\n" | |
efd7904e | 7771 | "Address of interface\n") |
718e3744 | 7772 | { |
d62a17ae | 7773 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7774 | int idx = 0; | |
d7c0a89a | 7775 | uint32_t seconds; |
d62a17ae | 7776 | struct in_addr addr; |
7777 | struct ospf_if_params *params; | |
7778 | params = IF_DEF_PARAMS(ifp); | |
7779 | ||
7780 | argv_find(argv, argc, "(3-65535)", &idx); | |
7781 | seconds = strtol(argv[idx]->arg, NULL, 10); | |
7782 | ||
7783 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
7784 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
7785 | vty_out(vty, | |
7786 | "Please specify interface address by A.B.C.D\n"); | |
7787 | return CMD_WARNING_CONFIG_FAILED; | |
7788 | } | |
718e3744 | 7789 | |
d62a17ae | 7790 | params = ospf_get_if_params(ifp, addr); |
7791 | ospf_if_update_params(ifp, addr); | |
718e3744 | 7792 | } |
7793 | ||
d62a17ae | 7794 | SET_IF_PARAM(params, retransmit_interval); |
7795 | params->retransmit_interval = seconds; | |
718e3744 | 7796 | |
d62a17ae | 7797 | return CMD_SUCCESS; |
718e3744 | 7798 | } |
7799 | ||
7a7be519 | 7800 | DEFUN_HIDDEN (ospf_retransmit_interval, |
747e489c | 7801 | ospf_retransmit_interval_cmd, |
0d829fa7 | 7802 | "ospf retransmit-interval (3-65535) [A.B.C.D]", |
747e489c DW |
7803 | "OSPF interface commands\n" |
7804 | "Time between retransmitting lost link state advertisements\n" | |
3a2d747c | 7805 | "Seconds\n" |
efd7904e | 7806 | "Address of interface\n") |
7a7be519 | 7807 | { |
d62a17ae | 7808 | return ip_ospf_retransmit_interval(self, vty, argc, argv); |
7a7be519 | 7809 | } |
718e3744 | 7810 | |
7811 | DEFUN (no_ip_ospf_retransmit_interval, | |
7812 | no_ip_ospf_retransmit_interval_addr_cmd, | |
0d829fa7 | 7813 | "no ip ospf retransmit-interval [(3-65535)] [A.B.C.D]", |
718e3744 | 7814 | NO_STR |
7815 | "IP Information\n" | |
7816 | "OSPF interface commands\n" | |
3a2d747c QY |
7817 | "Time between retransmitting lost link state advertisements\n" |
7818 | "Seconds\n" | |
0d829fa7 | 7819 | "Address of interface\n") |
718e3744 | 7820 | { |
d62a17ae | 7821 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7822 | int idx = 0; | |
7823 | struct in_addr addr; | |
7824 | struct ospf_if_params *params; | |
47b91972 | 7825 | |
d62a17ae | 7826 | params = IF_DEF_PARAMS(ifp); |
718e3744 | 7827 | |
d62a17ae | 7828 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { |
7829 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
7830 | vty_out(vty, | |
7831 | "Please specify interface address by A.B.C.D\n"); | |
7832 | return CMD_WARNING_CONFIG_FAILED; | |
7833 | } | |
718e3744 | 7834 | |
d62a17ae | 7835 | params = ospf_lookup_if_params(ifp, addr); |
7836 | if (params == NULL) | |
7837 | return CMD_SUCCESS; | |
7838 | } | |
718e3744 | 7839 | |
d62a17ae | 7840 | UNSET_IF_PARAM(params, retransmit_interval); |
7841 | params->retransmit_interval = OSPF_RETRANSMIT_INTERVAL_DEFAULT; | |
718e3744 | 7842 | |
d62a17ae | 7843 | if (params != IF_DEF_PARAMS(ifp)) { |
7844 | ospf_free_if_params(ifp, addr); | |
7845 | ospf_if_update_params(ifp, addr); | |
7846 | } | |
718e3744 | 7847 | |
d62a17ae | 7848 | return CMD_SUCCESS; |
718e3744 | 7849 | } |
7850 | ||
0d829fa7 QY |
7851 | DEFUN_HIDDEN (no_ospf_retransmit_interval, |
7852 | no_ospf_retransmit_interval_cmd, | |
7853 | "no ospf retransmit-interval [(3-65535)] [A.B.C.D]", | |
7854 | NO_STR | |
7855 | "OSPF interface commands\n" | |
3a2d747c QY |
7856 | "Time between retransmitting lost link state advertisements\n" |
7857 | "Seconds\n" | |
7858 | "Address of interface\n") | |
0d829fa7 | 7859 | { |
d62a17ae | 7860 | return no_ip_ospf_retransmit_interval(self, vty, argc, argv); |
0d829fa7 | 7861 | } |
813d4307 | 7862 | |
718e3744 | 7863 | DEFUN (ip_ospf_transmit_delay, |
7864 | ip_ospf_transmit_delay_addr_cmd, | |
7a7be519 | 7865 | "ip ospf transmit-delay (1-65535) [A.B.C.D]", |
718e3744 | 7866 | "IP Information\n" |
7867 | "OSPF interface commands\n" | |
7868 | "Link state transmit delay\n" | |
7869 | "Seconds\n" | |
efd7904e | 7870 | "Address of interface\n") |
718e3744 | 7871 | { |
d62a17ae | 7872 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7873 | int idx = 0; | |
d7c0a89a | 7874 | uint32_t seconds; |
d62a17ae | 7875 | struct in_addr addr; |
7876 | struct ospf_if_params *params; | |
7877 | ||
7878 | params = IF_DEF_PARAMS(ifp); | |
7879 | argv_find(argv, argc, "(1-65535)", &idx); | |
7880 | seconds = strtol(argv[idx]->arg, NULL, 10); | |
7881 | ||
7882 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
7883 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
7884 | vty_out(vty, | |
7885 | "Please specify interface address by A.B.C.D\n"); | |
7886 | return CMD_WARNING_CONFIG_FAILED; | |
7887 | } | |
718e3744 | 7888 | |
d62a17ae | 7889 | params = ospf_get_if_params(ifp, addr); |
7890 | ospf_if_update_params(ifp, addr); | |
718e3744 | 7891 | } |
7892 | ||
d62a17ae | 7893 | SET_IF_PARAM(params, transmit_delay); |
7894 | params->transmit_delay = seconds; | |
718e3744 | 7895 | |
d62a17ae | 7896 | return CMD_SUCCESS; |
718e3744 | 7897 | } |
7898 | ||
7a7be519 | 7899 | DEFUN_HIDDEN (ospf_transmit_delay, |
747e489c | 7900 | ospf_transmit_delay_cmd, |
0d829fa7 | 7901 | "ospf transmit-delay (1-65535) [A.B.C.D]", |
747e489c DW |
7902 | "OSPF interface commands\n" |
7903 | "Link state transmit delay\n" | |
3a2d747c | 7904 | "Seconds\n" |
efd7904e | 7905 | "Address of interface\n") |
7a7be519 | 7906 | { |
d62a17ae | 7907 | return ip_ospf_transmit_delay(self, vty, argc, argv); |
7a7be519 | 7908 | } |
718e3744 | 7909 | |
7910 | DEFUN (no_ip_ospf_transmit_delay, | |
7911 | no_ip_ospf_transmit_delay_addr_cmd, | |
0d829fa7 | 7912 | "no ip ospf transmit-delay [(1-65535)] [A.B.C.D]", |
718e3744 | 7913 | NO_STR |
7914 | "IP Information\n" | |
7915 | "OSPF interface commands\n" | |
7916 | "Link state transmit delay\n" | |
efd7904e RW |
7917 | "Seconds\n" |
7918 | "Address of interface\n") | |
718e3744 | 7919 | { |
d62a17ae | 7920 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7921 | int idx = 0; | |
7922 | struct in_addr addr; | |
7923 | struct ospf_if_params *params; | |
718e3744 | 7924 | |
d62a17ae | 7925 | params = IF_DEF_PARAMS(ifp); |
718e3744 | 7926 | |
d62a17ae | 7927 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { |
7928 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
7929 | vty_out(vty, | |
7930 | "Please specify interface address by A.B.C.D\n"); | |
7931 | return CMD_WARNING_CONFIG_FAILED; | |
7932 | } | |
718e3744 | 7933 | |
d62a17ae | 7934 | params = ospf_lookup_if_params(ifp, addr); |
7935 | if (params == NULL) | |
7936 | return CMD_SUCCESS; | |
7937 | } | |
718e3744 | 7938 | |
d62a17ae | 7939 | UNSET_IF_PARAM(params, transmit_delay); |
7940 | params->transmit_delay = OSPF_TRANSMIT_DELAY_DEFAULT; | |
718e3744 | 7941 | |
d62a17ae | 7942 | if (params != IF_DEF_PARAMS(ifp)) { |
7943 | ospf_free_if_params(ifp, addr); | |
7944 | ospf_if_update_params(ifp, addr); | |
7945 | } | |
7946 | ||
7947 | return CMD_SUCCESS; | |
718e3744 | 7948 | } |
7949 | ||
813d4307 | 7950 | |
0d829fa7 QY |
7951 | DEFUN_HIDDEN (no_ospf_transmit_delay, |
7952 | no_ospf_transmit_delay_cmd, | |
32573073 | 7953 | "no ospf transmit-delay [(1-65535) [A.B.C.D]]", |
0d829fa7 QY |
7954 | NO_STR |
7955 | "OSPF interface commands\n" | |
32573073 QY |
7956 | "Link state transmit delay\n" |
7957 | "Seconds\n" | |
efd7904e | 7958 | "Address of interface\n") |
813d4307 | 7959 | { |
d62a17ae | 7960 | return no_ip_ospf_transmit_delay(self, vty, argc, argv); |
813d4307 DW |
7961 | } |
7962 | ||
e723861d DS |
7963 | DEFUN (ip_ospf_area, |
7964 | ip_ospf_area_cmd, | |
52c62ab8 | 7965 | "ip ospf [(1-65535)] area <A.B.C.D|(0-4294967295)> [A.B.C.D]", |
e723861d DS |
7966 | "IP Information\n" |
7967 | "OSPF interface commands\n" | |
7a7be519 | 7968 | "Instance ID\n" |
e723861d DS |
7969 | "Enable OSPF on this interface\n" |
7970 | "OSPF area ID in IP address format\n" | |
52c62ab8 JAG |
7971 | "OSPF area ID as a decimal value\n" |
7972 | "Address of interface\n") | |
e723861d | 7973 | { |
d62a17ae | 7974 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7975 | int idx = 0; | |
7976 | int format, ret; | |
7977 | struct in_addr area_id; | |
7978 | struct in_addr addr; | |
35955c14 | 7979 | struct ospf_if_params *params = NULL; |
d62a17ae | 7980 | struct route_node *rn; |
b5a8894d | 7981 | struct ospf *ospf = NULL; |
d7c0a89a | 7982 | unsigned short instance = 0; |
d62a17ae | 7983 | char *areaid; |
7984 | ||
7985 | if (argv_find(argv, argc, "(1-65535)", &idx)) | |
7986 | instance = strtol(argv[idx]->arg, NULL, 10); | |
7987 | ||
7988 | argv_find(argv, argc, "area", &idx); | |
7989 | areaid = argv[idx + 1]->arg; | |
7990 | ||
a36898e7 DS |
7991 | if (ifp->vrf_id && !instance) |
7992 | ospf = ospf_lookup_by_vrf_id(ifp->vrf_id); | |
b5a8894d CS |
7993 | else |
7994 | ospf = ospf_lookup_instance(instance); | |
7995 | ||
aed7cc62 | 7996 | if (instance && ospf == NULL) { |
d62a17ae | 7997 | params = IF_DEF_PARAMS(ifp); |
7998 | if (OSPF_IF_PARAM_CONFIGURED(params, if_area)) { | |
7999 | UNSET_IF_PARAM(params, if_area); | |
b5a8894d CS |
8000 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); |
8001 | ospf_interface_area_unset(ospf, ifp); | |
d62a17ae | 8002 | ospf->if_ospf_cli_count--; |
8003 | } | |
ac28e4ec | 8004 | return CMD_NOT_MY_INSTANCE; |
d62a17ae | 8005 | } |
e723861d | 8006 | |
d62a17ae | 8007 | ret = str2area_id(areaid, &area_id, &format); |
8008 | if (ret < 0) { | |
8009 | vty_out(vty, "Please specify area by A.B.C.D|<0-4294967295>\n"); | |
8010 | return CMD_WARNING_CONFIG_FAILED; | |
8011 | } | |
8012 | if (memcmp(ifp->name, "VLINK", 5) == 0) { | |
8013 | vty_out(vty, "Cannot enable OSPF on a virtual link.\n"); | |
8014 | return CMD_WARNING_CONFIG_FAILED; | |
8015 | } | |
8016 | ||
8017 | params = IF_DEF_PARAMS(ifp); | |
8018 | if (OSPF_IF_PARAM_CONFIGURED(params, if_area) | |
8019 | && !IPV4_ADDR_SAME(¶ms->if_area, &area_id)) { | |
8020 | vty_out(vty, | |
8021 | "Must remove previous area config before changing ospf area \n"); | |
8022 | return CMD_WARNING_CONFIG_FAILED; | |
8023 | } | |
8024 | ||
8025 | // Check if we have an address arg and proccess it | |
8026 | if (argc == idx + 3) { | |
cc9b06ad | 8027 | if (!inet_aton(argv[idx + 2]->arg, &addr)) { |
996c9314 LB |
8028 | vty_out(vty, |
8029 | "Please specify Intf Address by A.B.C.D\n"); | |
cc9b06ad DS |
8030 | return CMD_WARNING_CONFIG_FAILED; |
8031 | } | |
d62a17ae | 8032 | // update/create address-level params |
8033 | params = ospf_get_if_params((ifp), (addr)); | |
8034 | if (OSPF_IF_PARAM_CONFIGURED(params, if_area)) { | |
8035 | vty_out(vty, | |
8036 | "Must remove previous area/address config before changing ospf area"); | |
8037 | return CMD_WARNING_CONFIG_FAILED; | |
8038 | } | |
8039 | ospf_if_update_params((ifp), (addr)); | |
8040 | } | |
8041 | ||
aed7cc62 CS |
8042 | if (ospf) { |
8043 | for (rn = route_top(ospf->networks); rn; rn = route_next(rn)) { | |
8044 | if (rn->info != NULL) { | |
8045 | vty_out(vty, | |
8046 | "Please remove all network commands first.\n"); | |
8047 | return CMD_WARNING_CONFIG_FAILED; | |
8048 | } | |
d62a17ae | 8049 | } |
8050 | } | |
8051 | ||
8052 | /* enable ospf on this interface with area_id */ | |
35955c14 CS |
8053 | if (params) { |
8054 | SET_IF_PARAM(params, if_area); | |
8055 | params->if_area = area_id; | |
8056 | params->if_area_id_fmt = format; | |
8057 | } | |
aed7cc62 CS |
8058 | |
8059 | if (ospf) { | |
8060 | ospf_interface_area_set(ospf, ifp); | |
8061 | ospf->if_ospf_cli_count++; | |
8062 | } | |
d62a17ae | 8063 | |
8064 | return CMD_SUCCESS; | |
e723861d DS |
8065 | } |
8066 | ||
8067 | DEFUN (no_ip_ospf_area, | |
8068 | no_ip_ospf_area_cmd, | |
52c62ab8 | 8069 | "no ip ospf [(1-65535)] area [<A.B.C.D|(0-4294967295)> [A.B.C.D]]", |
e723861d DS |
8070 | NO_STR |
8071 | "IP Information\n" | |
8072 | "OSPF interface commands\n" | |
3a2d747c | 8073 | "Instance ID\n" |
7a7be519 | 8074 | "Disable OSPF on this interface\n" |
8075 | "OSPF area ID in IP address format\n" | |
52c62ab8 JAG |
8076 | "OSPF area ID as a decimal value\n" |
8077 | "Address of interface\n") | |
e723861d | 8078 | { |
d62a17ae | 8079 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8080 | int idx = 0; | |
8081 | struct ospf *ospf; | |
8082 | struct ospf_if_params *params; | |
d7c0a89a | 8083 | unsigned short instance = 0; |
d62a17ae | 8084 | struct in_addr addr; |
8085 | ||
8086 | if (argv_find(argv, argc, "(1-65535)", &idx)) | |
8087 | instance = strtol(argv[idx]->arg, NULL, 10); | |
8088 | ||
a36898e7 DS |
8089 | if (ifp->vrf_id && !instance) |
8090 | ospf = ospf_lookup_by_vrf_id(ifp->vrf_id); | |
b5a8894d CS |
8091 | else |
8092 | ospf = ospf_lookup_instance(instance); | |
8093 | ||
ac28e4ec CS |
8094 | if (ospf == NULL) |
8095 | return CMD_NOT_MY_INSTANCE; | |
d62a17ae | 8096 | |
8097 | argv_find(argv, argc, "area", &idx); | |
8098 | ||
8099 | // Check if we have an address arg and proccess it | |
8100 | if (argc == idx + 3) { | |
cc9b06ad | 8101 | if (!inet_aton(argv[idx + 2]->arg, &addr)) { |
996c9314 LB |
8102 | vty_out(vty, |
8103 | "Please specify Intf Address by A.B.C.D\n"); | |
cc9b06ad DS |
8104 | return CMD_WARNING_CONFIG_FAILED; |
8105 | } | |
d62a17ae | 8106 | params = ospf_lookup_if_params(ifp, addr); |
8107 | if ((params) == NULL) | |
8108 | return CMD_SUCCESS; | |
8109 | } else | |
8110 | params = IF_DEF_PARAMS(ifp); | |
8111 | ||
8112 | if (!OSPF_IF_PARAM_CONFIGURED(params, if_area)) { | |
8113 | vty_out(vty, | |
8114 | "Can't find specified interface area configuration.\n"); | |
8115 | return CMD_WARNING_CONFIG_FAILED; | |
8116 | } | |
813d4307 | 8117 | |
d62a17ae | 8118 | UNSET_IF_PARAM(params, if_area); |
8119 | if (params != IF_DEF_PARAMS((ifp))) { | |
8120 | ospf_free_if_params((ifp), (addr)); | |
8121 | ospf_if_update_params((ifp), (addr)); | |
8122 | } | |
8123 | ||
b5a8894d | 8124 | ospf_interface_area_unset(ospf, ifp); |
d62a17ae | 8125 | ospf->if_ospf_cli_count--; |
8126 | return CMD_SUCCESS; | |
813d4307 DW |
8127 | } |
8128 | ||
6f2a6703 CF |
8129 | DEFUN (ospf_redistribute_source, |
8130 | ospf_redistribute_source_cmd, | |
ea38ced1 | 8131 | "redistribute " FRR_REDIST_STR_OSPFD " [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]", |
d1c65c21 | 8132 | REDIST_STR |
ab0181ee | 8133 | FRR_REDIST_HELP_STR_OSPFD |
718e3744 | 8134 | "Metric for redistributed routes\n" |
8135 | "OSPF default metric\n" | |
8136 | "OSPF exterior metric type for redistributed routes\n" | |
7111c1a0 | 8137 | "Set OSPF External Type 1/2 metrics\n" |
718e3744 | 8138 | "Route map reference\n" |
8139 | "Pointer to route-map entries\n") | |
8140 | { | |
a3d826f0 | 8141 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 8142 | int idx_protocol = 1; |
8143 | int source; | |
8144 | int type = -1; | |
8145 | int metric = -1; | |
8146 | struct ospf_redist *red; | |
8147 | int idx = 0; | |
6f2a6703 | 8148 | |
d62a17ae | 8149 | /* Get distribute source. */ |
8150 | source = proto_redistnum(AFI_IP, argv[idx_protocol]->text); | |
8151 | if (source < 0) | |
8152 | return CMD_WARNING_CONFIG_FAILED; | |
8153 | ||
8154 | red = ospf_redist_add(ospf, source, 0); | |
8155 | ||
8156 | /* Get metric value. */ | |
8157 | if (argv_find(argv, argc, "(0-16777214)", &idx)) { | |
8158 | if (!str2metric(argv[idx]->arg, &metric)) | |
8159 | return CMD_WARNING_CONFIG_FAILED; | |
8160 | } | |
951da435 | 8161 | idx = 1; |
d62a17ae | 8162 | /* Get metric type. */ |
ea38ced1 | 8163 | if (argv_find(argv, argc, "(1-2)", &idx)) { |
d62a17ae | 8164 | if (!str2metric_type(argv[idx]->arg, &type)) |
8165 | return CMD_WARNING_CONFIG_FAILED; | |
8166 | } | |
951da435 | 8167 | idx = 1; |
d62a17ae | 8168 | /* Get route-map */ |
ea38ced1 | 8169 | if (argv_find(argv, argc, "WORD", &idx)) { |
d62a17ae | 8170 | ospf_routemap_set(red, argv[idx]->arg); |
8171 | } else | |
8172 | ospf_routemap_unset(red); | |
7c8ff89e | 8173 | |
d62a17ae | 8174 | return ospf_redistribute_set(ospf, source, 0, type, metric); |
718e3744 | 8175 | } |
8176 | ||
718e3744 | 8177 | DEFUN (no_ospf_redistribute_source, |
8178 | no_ospf_redistribute_source_cmd, | |
ea38ced1 | 8179 | "no redistribute " FRR_REDIST_STR_OSPFD " [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]", |
718e3744 | 8180 | NO_STR |
d1c65c21 | 8181 | REDIST_STR |
ab0181ee | 8182 | FRR_REDIST_HELP_STR_OSPFD |
813d4307 DW |
8183 | "Metric for redistributed routes\n" |
8184 | "OSPF default metric\n" | |
8185 | "OSPF exterior metric type for redistributed routes\n" | |
7111c1a0 | 8186 | "Set OSPF External Type 1/2 metrics\n" |
813d4307 DW |
8187 | "Route map reference\n" |
8188 | "Pointer to route-map entries\n") | |
718e3744 | 8189 | { |
a3d826f0 | 8190 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 8191 | int idx_protocol = 2; |
8192 | int source; | |
8193 | struct ospf_redist *red; | |
718e3744 | 8194 | |
d62a17ae | 8195 | source = proto_redistnum(AFI_IP, argv[idx_protocol]->text); |
8196 | if (source < 0) | |
8197 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 8198 | |
d62a17ae | 8199 | red = ospf_redist_lookup(ospf, source, 0); |
8200 | if (!red) | |
8201 | return CMD_SUCCESS; | |
7c8ff89e | 8202 | |
d62a17ae | 8203 | ospf_routemap_unset(red); |
766b826f DA |
8204 | ospf_redist_del(ospf, source, 0); |
8205 | ||
d62a17ae | 8206 | return ospf_redistribute_unset(ospf, source, 0); |
7c8ff89e DS |
8207 | } |
8208 | ||
8209 | DEFUN (ospf_redistribute_instance_source, | |
8210 | ospf_redistribute_instance_source_cmd, | |
1a5ce38b | 8211 | "redistribute <ospf|table> (1-65535) [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]", |
7c8ff89e DS |
8212 | REDIST_STR |
8213 | "Open Shortest Path First\n" | |
2d627ff5 DS |
8214 | "Non-main Kernel Routing Table\n" |
8215 | "Instance ID/Table ID\n" | |
7c8ff89e DS |
8216 | "Metric for redistributed routes\n" |
8217 | "OSPF default metric\n" | |
8218 | "OSPF exterior metric type for redistributed routes\n" | |
7111c1a0 | 8219 | "Set OSPF External Type 1/2 metrics\n" |
7c8ff89e DS |
8220 | "Route map reference\n" |
8221 | "Pointer to route-map entries\n") | |
8222 | { | |
a3d826f0 | 8223 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 8224 | int idx_ospf_table = 1; |
8225 | int idx_number = 2; | |
8226 | int idx = 3; | |
8227 | int source; | |
8228 | int type = -1; | |
8229 | int metric = -1; | |
d7c0a89a | 8230 | unsigned short instance; |
d62a17ae | 8231 | struct ospf_redist *red; |
7c8ff89e | 8232 | |
d62a17ae | 8233 | source = proto_redistnum(AFI_IP, argv[idx_ospf_table]->text); |
2d627ff5 | 8234 | |
13f0e434 | 8235 | if (source < 0) { |
8236 | vty_out(vty, "Unknown instance redistribution\n"); | |
8237 | return CMD_WARNING_CONFIG_FAILED; | |
8238 | } | |
8239 | ||
d62a17ae | 8240 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
7c8ff89e | 8241 | |
d62a17ae | 8242 | if ((source == ZEBRA_ROUTE_OSPF) && !ospf->instance) { |
8243 | vty_out(vty, | |
8244 | "Instance redistribution in non-instanced OSPF not allowed\n"); | |
8245 | return CMD_WARNING_CONFIG_FAILED; | |
8246 | } | |
7c8ff89e | 8247 | |
d62a17ae | 8248 | if ((source == ZEBRA_ROUTE_OSPF) && (ospf->instance == instance)) { |
8249 | vty_out(vty, "Same instance OSPF redistribution not allowed\n"); | |
8250 | return CMD_WARNING_CONFIG_FAILED; | |
8251 | } | |
7c8ff89e | 8252 | |
d62a17ae | 8253 | /* Get metric value. */ |
8254 | if (argv_find(argv, argc, "metric", &idx)) | |
8255 | if (!str2metric(argv[idx + 1]->arg, &metric)) | |
8256 | return CMD_WARNING_CONFIG_FAILED; | |
7c8ff89e | 8257 | |
d62a17ae | 8258 | idx = 3; |
8259 | /* Get metric type. */ | |
8260 | if (argv_find(argv, argc, "metric-type", &idx)) | |
8261 | if (!str2metric_type(argv[idx + 1]->arg, &type)) | |
8262 | return CMD_WARNING_CONFIG_FAILED; | |
7c8ff89e | 8263 | |
d62a17ae | 8264 | red = ospf_redist_add(ospf, source, instance); |
7a7be519 | 8265 | |
d62a17ae | 8266 | idx = 3; |
8267 | if (argv_find(argv, argc, "route-map", &idx)) | |
8268 | ospf_routemap_set(red, argv[idx + 1]->arg); | |
8269 | else | |
8270 | ospf_routemap_unset(red); | |
7c8ff89e | 8271 | |
d62a17ae | 8272 | return ospf_redistribute_set(ospf, source, instance, type, metric); |
7c8ff89e DS |
8273 | } |
8274 | ||
8275 | DEFUN (no_ospf_redistribute_instance_source, | |
8276 | no_ospf_redistribute_instance_source_cmd, | |
1a5ce38b | 8277 | "no redistribute <ospf|table> (1-65535) [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]", |
7c8ff89e DS |
8278 | NO_STR |
8279 | REDIST_STR | |
8280 | "Open Shortest Path First\n" | |
2d627ff5 DS |
8281 | "Non-main Kernel Routing Table\n" |
8282 | "Instance ID/Table Id\n" | |
7c8ff89e DS |
8283 | "Metric for redistributed routes\n" |
8284 | "OSPF default metric\n" | |
8285 | "OSPF exterior metric type for redistributed routes\n" | |
7111c1a0 | 8286 | "Set OSPF External Type 1/2 metrics\n" |
7c8ff89e DS |
8287 | "Route map reference\n" |
8288 | "Pointer to route-map entries\n") | |
8289 | { | |
a3d826f0 | 8290 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 8291 | int idx_ospf_table = 2; |
8292 | int idx_number = 3; | |
d7c0a89a | 8293 | unsigned int instance; |
d62a17ae | 8294 | struct ospf_redist *red; |
8295 | int source; | |
8296 | ||
8297 | if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0) | |
8298 | source = ZEBRA_ROUTE_OSPF; | |
8299 | else | |
8300 | source = ZEBRA_ROUTE_TABLE; | |
8301 | ||
8302 | instance = strtoul(argv[idx_number]->arg, NULL, 10); | |
7c8ff89e | 8303 | |
d62a17ae | 8304 | if ((source == ZEBRA_ROUTE_OSPF) && !ospf->instance) { |
8305 | vty_out(vty, | |
8306 | "Instance redistribution in non-instanced OSPF not allowed\n"); | |
8307 | return CMD_WARNING_CONFIG_FAILED; | |
8308 | } | |
8309 | ||
8310 | if ((source == ZEBRA_ROUTE_OSPF) && (ospf->instance == instance)) { | |
8311 | vty_out(vty, "Same instance OSPF redistribution not allowed\n"); | |
8312 | return CMD_WARNING_CONFIG_FAILED; | |
8313 | } | |
8314 | ||
8315 | red = ospf_redist_lookup(ospf, source, instance); | |
8316 | if (!red) | |
8317 | return CMD_SUCCESS; | |
8318 | ||
8319 | ospf_routemap_unset(red); | |
766b826f DA |
8320 | ospf_redist_del(ospf, source, instance); |
8321 | ||
d62a17ae | 8322 | return ospf_redistribute_unset(ospf, source, instance); |
718e3744 | 8323 | } |
8324 | ||
8325 | DEFUN (ospf_distribute_list_out, | |
8326 | ospf_distribute_list_out_cmd, | |
40d1cbfb | 8327 | "distribute-list WORD out " FRR_REDIST_STR_OSPFD, |
718e3744 | 8328 | "Filter networks in routing updates\n" |
6f2a6703 CF |
8329 | "Access-list name\n" |
8330 | OUT_STR | |
ab0181ee | 8331 | FRR_REDIST_HELP_STR_OSPFD) |
718e3744 | 8332 | { |
a3d826f0 | 8333 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 8334 | int idx_word = 1; |
8335 | int source; | |
718e3744 | 8336 | |
d62a17ae | 8337 | char *proto = argv[argc - 1]->text; |
6d681bd8 | 8338 | |
d62a17ae | 8339 | /* Get distribute source. */ |
8340 | source = proto_redistnum(AFI_IP, proto); | |
8341 | if (source < 0) | |
8342 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 8343 | |
d62a17ae | 8344 | return ospf_distribute_list_out_set(ospf, source, argv[idx_word]->arg); |
718e3744 | 8345 | } |
8346 | ||
6f2a6703 CF |
8347 | DEFUN (no_ospf_distribute_list_out, |
8348 | no_ospf_distribute_list_out_cmd, | |
40d1cbfb | 8349 | "no distribute-list WORD out " FRR_REDIST_STR_OSPFD, |
6f2a6703 CF |
8350 | NO_STR |
8351 | "Filter networks in routing updates\n" | |
8352 | "Access-list name\n" | |
8353 | OUT_STR | |
ab0181ee | 8354 | FRR_REDIST_HELP_STR_OSPFD) |
718e3744 | 8355 | { |
a3d826f0 | 8356 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 8357 | int idx_word = 2; |
8358 | int source; | |
020709f9 | 8359 | |
d62a17ae | 8360 | char *proto = argv[argc - 1]->text; |
8361 | source = proto_redistnum(AFI_IP, proto); | |
8362 | if (source < 0) | |
8363 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 8364 | |
d62a17ae | 8365 | return ospf_distribute_list_out_unset(ospf, source, |
8366 | argv[idx_word]->arg); | |
718e3744 | 8367 | } |
8368 | ||
6f2a6703 CF |
8369 | /* Default information originate. */ |
8370 | DEFUN (ospf_default_information_originate, | |
8371 | ospf_default_information_originate_cmd, | |
ea38ced1 | 8372 | "default-information originate [{always|metric (0-16777214)|metric-type (1-2)|route-map WORD}]", |
718e3744 | 8373 | "Control distribution of default information\n" |
8374 | "Distribute a default route\n" | |
8375 | "Always advertise default route\n" | |
6f2a6703 CF |
8376 | "OSPF default metric\n" |
8377 | "OSPF metric\n" | |
718e3744 | 8378 | "OSPF metric type for default routes\n" |
7111c1a0 | 8379 | "Set OSPF External Type 1/2 metrics\n" |
718e3744 | 8380 | "Route map reference\n" |
8381 | "Pointer to route-map entries\n") | |
8382 | { | |
a3d826f0 | 8383 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 8384 | int default_originate = DEFAULT_ORIGINATE_ZEBRA; |
8385 | int type = -1; | |
8386 | int metric = -1; | |
8387 | struct ospf_redist *red; | |
8388 | int idx = 0; | |
1fb93326 | 8389 | int cur_originate = ospf->default_originate; |
8390 | int sameRtmap = 0; | |
8391 | char *rtmap = NULL; | |
d62a17ae | 8392 | |
8393 | red = ospf_redist_add(ospf, DEFAULT_ROUTE, 0); | |
8394 | ||
8395 | /* Check whether "always" was specified */ | |
8396 | if (argv_find(argv, argc, "always", &idx)) | |
8397 | default_originate = DEFAULT_ORIGINATE_ALWAYS; | |
951da435 | 8398 | idx = 1; |
d62a17ae | 8399 | /* Get metric value */ |
ea38ced1 | 8400 | if (argv_find(argv, argc, "(0-16777214)", &idx)) { |
d62a17ae | 8401 | if (!str2metric(argv[idx]->arg, &metric)) |
8402 | return CMD_WARNING_CONFIG_FAILED; | |
8403 | } | |
951da435 | 8404 | idx = 1; |
d62a17ae | 8405 | /* Get metric type. */ |
ea38ced1 | 8406 | if (argv_find(argv, argc, "(1-2)", &idx)) { |
d62a17ae | 8407 | if (!str2metric_type(argv[idx]->arg, &type)) |
8408 | return CMD_WARNING_CONFIG_FAILED; | |
8409 | } | |
951da435 | 8410 | idx = 1; |
d62a17ae | 8411 | /* Get route-map */ |
ea38ced1 | 8412 | if (argv_find(argv, argc, "WORD", &idx)) |
1fb93326 | 8413 | rtmap = argv[idx]->arg; |
8414 | ||
8415 | /* To check ,if user is providing same route map */ | |
8416 | if ((rtmap == ROUTEMAP_NAME(red)) || | |
8417 | (rtmap && ROUTEMAP_NAME(red) | |
8418 | && (strcmp(rtmap, ROUTEMAP_NAME(red)) == 0))) | |
8419 | sameRtmap = 1; | |
8420 | ||
8421 | /* Don't allow if the same lsa is aleardy originated. */ | |
8422 | if ((sameRtmap) | |
8423 | && (red->dmetric.type == type) | |
8424 | && (red->dmetric.value == metric) | |
8425 | && (cur_originate == default_originate)) | |
8426 | return CMD_SUCCESS; | |
8427 | ||
8428 | /* Updating Metric details */ | |
8429 | red->dmetric.type = type; | |
8430 | red->dmetric.value = metric; | |
8431 | ||
8432 | /* updating route map details */ | |
8433 | if (rtmap) | |
8434 | ospf_routemap_set(red, rtmap); | |
d62a17ae | 8435 | else |
8436 | ospf_routemap_unset(red); | |
8437 | ||
8438 | return ospf_redistribute_default_set(ospf, default_originate, type, | |
8439 | metric); | |
718e3744 | 8440 | } |
8441 | ||
8442 | DEFUN (no_ospf_default_information_originate, | |
8443 | no_ospf_default_information_originate_cmd, | |
ea38ced1 | 8444 | "no default-information originate [{always|metric (0-16777214)|metric-type (1-2)|route-map WORD}]", |
718e3744 | 8445 | NO_STR |
8446 | "Control distribution of default information\n" | |
813d4307 DW |
8447 | "Distribute a default route\n" |
8448 | "Always advertise default route\n" | |
8449 | "OSPF default metric\n" | |
8450 | "OSPF metric\n" | |
8451 | "OSPF metric type for default routes\n" | |
7111c1a0 | 8452 | "Set OSPF External Type 1/2 metrics\n" |
813d4307 DW |
8453 | "Route map reference\n" |
8454 | "Pointer to route-map entries\n") | |
718e3744 | 8455 | { |
a3d826f0 | 8456 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 8457 | struct prefix_ipv4 p; |
8458 | struct ospf_external *ext; | |
8459 | struct ospf_redist *red; | |
7c8ff89e | 8460 | |
d62a17ae | 8461 | p.family = AF_INET; |
8462 | p.prefix.s_addr = 0; | |
8463 | p.prefixlen = 0; | |
718e3744 | 8464 | |
d62a17ae | 8465 | ospf_external_lsa_flush(ospf, DEFAULT_ROUTE, &p, 0); |
718e3744 | 8466 | |
de1ac5fd CS |
8467 | ext = ospf_external_lookup(ospf, DEFAULT_ROUTE, 0); |
8468 | if (ext && EXTERNAL_INFO(ext)) { | |
8469 | ospf_external_info_delete(ospf, DEFAULT_ROUTE, 0, p); | |
8470 | ospf_external_del(ospf, DEFAULT_ROUTE, 0); | |
d62a17ae | 8471 | } |
718e3744 | 8472 | |
d62a17ae | 8473 | red = ospf_redist_lookup(ospf, DEFAULT_ROUTE, 0); |
8474 | if (!red) | |
8475 | return CMD_SUCCESS; | |
7c8ff89e | 8476 | |
d62a17ae | 8477 | ospf_routemap_unset(red); |
766b826f DA |
8478 | ospf_redist_del(ospf, DEFAULT_ROUTE, 0); |
8479 | ||
d62a17ae | 8480 | return ospf_redistribute_default_unset(ospf); |
718e3744 | 8481 | } |
8482 | ||
8483 | DEFUN (ospf_default_metric, | |
8484 | ospf_default_metric_cmd, | |
6147e2c6 | 8485 | "default-metric (0-16777214)", |
718e3744 | 8486 | "Set metric of redistributed routes\n" |
8487 | "Default metric\n") | |
8488 | { | |
a3d826f0 | 8489 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 8490 | int idx_number = 1; |
8491 | int metric = -1; | |
718e3744 | 8492 | |
d62a17ae | 8493 | if (!str2metric(argv[idx_number]->arg, &metric)) |
8494 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 8495 | |
d62a17ae | 8496 | ospf->default_metric = metric; |
718e3744 | 8497 | |
d62a17ae | 8498 | return CMD_SUCCESS; |
718e3744 | 8499 | } |
8500 | ||
8501 | DEFUN (no_ospf_default_metric, | |
8502 | no_ospf_default_metric_cmd, | |
7a7be519 | 8503 | "no default-metric [(0-16777214)]", |
718e3744 | 8504 | NO_STR |
7a7be519 | 8505 | "Set metric of redistributed routes\n" |
8506 | "Default metric\n") | |
718e3744 | 8507 | { |
a3d826f0 | 8508 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
68980084 | 8509 | |
d62a17ae | 8510 | ospf->default_metric = -1; |
68980084 | 8511 | |
d62a17ae | 8512 | return CMD_SUCCESS; |
718e3744 | 8513 | } |
8514 | ||
718e3744 | 8515 | |
8516 | DEFUN (ospf_distance, | |
8517 | ospf_distance_cmd, | |
6147e2c6 | 8518 | "distance (1-255)", |
eaa1ae0d | 8519 | "Administrative distance\n" |
718e3744 | 8520 | "OSPF Administrative distance\n") |
8521 | { | |
a3d826f0 | 8522 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 8523 | int idx_number = 1; |
68980084 | 8524 | |
d62a17ae | 8525 | ospf->distance_all = atoi(argv[idx_number]->arg); |
68980084 | 8526 | |
d62a17ae | 8527 | return CMD_SUCCESS; |
718e3744 | 8528 | } |
8529 | ||
8530 | DEFUN (no_ospf_distance, | |
8531 | no_ospf_distance_cmd, | |
6147e2c6 | 8532 | "no distance (1-255)", |
718e3744 | 8533 | NO_STR |
eaa1ae0d | 8534 | "Administrative distance\n" |
718e3744 | 8535 | "OSPF Administrative distance\n") |
8536 | { | |
a3d826f0 | 8537 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
68980084 | 8538 | |
d62a17ae | 8539 | ospf->distance_all = 0; |
68980084 | 8540 | |
d62a17ae | 8541 | return CMD_SUCCESS; |
718e3744 | 8542 | } |
8543 | ||
8544 | DEFUN (no_ospf_distance_ospf, | |
8545 | no_ospf_distance_ospf_cmd, | |
eaa1ae0d | 8546 | "no distance ospf [{intra-area [(1-255)]|inter-area [(1-255)]|external [(1-255)]}]", |
718e3744 | 8547 | NO_STR |
eaa1ae0d QY |
8548 | "Administrative distance\n" |
8549 | "OSPF administrative distance\n" | |
718e3744 | 8550 | "Intra-area routes\n" |
813d4307 | 8551 | "Distance for intra-area routes\n" |
718e3744 | 8552 | "Inter-area routes\n" |
813d4307 DW |
8553 | "Distance for inter-area routes\n" |
8554 | "External routes\n" | |
8555 | "Distance for external routes\n") | |
718e3744 | 8556 | { |
a3d826f0 | 8557 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 8558 | int idx = 0; |
718e3744 | 8559 | |
d62a17ae | 8560 | if (argv_find(argv, argc, "intra-area", &idx) || argc == 3) |
8561 | idx = ospf->distance_intra = 0; | |
8562 | if (argv_find(argv, argc, "inter-area", &idx) || argc == 3) | |
8563 | idx = ospf->distance_inter = 0; | |
8564 | if (argv_find(argv, argc, "external", &idx) || argc == 3) | |
8565 | ospf->distance_external = 0; | |
718e3744 | 8566 | |
d62a17ae | 8567 | return CMD_SUCCESS; |
718e3744 | 8568 | } |
8569 | ||
6f2a6703 CF |
8570 | DEFUN (ospf_distance_ospf, |
8571 | ospf_distance_ospf_cmd, | |
eaa1ae0d QY |
8572 | "distance ospf {intra-area (1-255)|inter-area (1-255)|external (1-255)}", |
8573 | "Administrative distance\n" | |
8574 | "OSPF administrative distance\n" | |
718e3744 | 8575 | "Intra-area routes\n" |
8576 | "Distance for intra-area routes\n" | |
718e3744 | 8577 | "Inter-area routes\n" |
8578 | "Distance for inter-area routes\n" | |
8579 | "External routes\n" | |
718e3744 | 8580 | "Distance for external routes\n") |
8581 | { | |
a3d826f0 | 8582 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 8583 | int idx = 0; |
68980084 | 8584 | |
926b88f0 CS |
8585 | ospf->distance_intra = 0; |
8586 | ospf->distance_inter = 0; | |
8587 | ospf->distance_external = 0; | |
8588 | ||
d62a17ae | 8589 | if (argv_find(argv, argc, "intra-area", &idx)) |
8590 | ospf->distance_intra = atoi(argv[idx + 1]->arg); | |
8591 | idx = 0; | |
8592 | if (argv_find(argv, argc, "inter-area", &idx)) | |
8593 | ospf->distance_inter = atoi(argv[idx + 1]->arg); | |
8594 | idx = 0; | |
8595 | if (argv_find(argv, argc, "external", &idx)) | |
8596 | ospf->distance_external = atoi(argv[idx + 1]->arg); | |
68980084 | 8597 | |
d62a17ae | 8598 | return CMD_SUCCESS; |
718e3744 | 8599 | } |
8600 | ||
d7d73ffc | 8601 | #if 0 |
718e3744 | 8602 | DEFUN (ospf_distance_source, |
8603 | ospf_distance_source_cmd, | |
6147e2c6 | 8604 | "distance (1-255) A.B.C.D/M", |
718e3744 | 8605 | "Administrative distance\n" |
8606 | "Distance value\n" | |
8607 | "IP source prefix\n") | |
8608 | { | |
cdc2d765 | 8609 | VTY_DECLVAR_CONTEXT(ospf, ospf); |
8d769265 DW |
8610 | int idx_number = 1; |
8611 | int idx_ipv4_prefixlen = 2; | |
020709f9 | 8612 | |
8d769265 | 8613 | ospf_distance_set (vty, ospf, argv[idx_number]->arg, argv[idx_ipv4_prefixlen]->arg, NULL); |
68980084 | 8614 | |
718e3744 | 8615 | return CMD_SUCCESS; |
8616 | } | |
8617 | ||
8618 | DEFUN (no_ospf_distance_source, | |
8619 | no_ospf_distance_source_cmd, | |
6147e2c6 | 8620 | "no distance (1-255) A.B.C.D/M", |
718e3744 | 8621 | NO_STR |
8622 | "Administrative distance\n" | |
8623 | "Distance value\n" | |
8624 | "IP source prefix\n") | |
8625 | { | |
cdc2d765 | 8626 | VTY_DECLVAR_CONTEXT(ospf, ospf); |
8d769265 DW |
8627 | int idx_number = 2; |
8628 | int idx_ipv4_prefixlen = 3; | |
020709f9 | 8629 | |
8d769265 | 8630 | ospf_distance_unset (vty, ospf, argv[idx_number]->arg, argv[idx_ipv4_prefixlen]->arg, NULL); |
020709f9 | 8631 | |
718e3744 | 8632 | return CMD_SUCCESS; |
8633 | } | |
8634 | ||
8635 | DEFUN (ospf_distance_source_access_list, | |
8636 | ospf_distance_source_access_list_cmd, | |
6147e2c6 | 8637 | "distance (1-255) A.B.C.D/M WORD", |
718e3744 | 8638 | "Administrative distance\n" |
8639 | "Distance value\n" | |
8640 | "IP source prefix\n" | |
8641 | "Access list name\n") | |
8642 | { | |
cdc2d765 | 8643 | VTY_DECLVAR_CONTEXT(ospf, ospf); |
8d769265 DW |
8644 | int idx_number = 1; |
8645 | int idx_ipv4_prefixlen = 2; | |
8646 | int idx_word = 3; | |
020709f9 | 8647 | |
8d769265 | 8648 | ospf_distance_set (vty, ospf, argv[idx_number]->arg, argv[idx_ipv4_prefixlen]->arg, argv[idx_word]->arg); |
020709f9 | 8649 | |
718e3744 | 8650 | return CMD_SUCCESS; |
8651 | } | |
8652 | ||
8653 | DEFUN (no_ospf_distance_source_access_list, | |
8654 | no_ospf_distance_source_access_list_cmd, | |
6147e2c6 | 8655 | "no distance (1-255) A.B.C.D/M WORD", |
718e3744 | 8656 | NO_STR |
8657 | "Administrative distance\n" | |
8658 | "Distance value\n" | |
8659 | "IP source prefix\n" | |
8660 | "Access list name\n") | |
8661 | { | |
cdc2d765 | 8662 | VTY_DECLVAR_CONTEXT(ospf, ospf); |
8d769265 DW |
8663 | int idx_number = 2; |
8664 | int idx_ipv4_prefixlen = 3; | |
8665 | int idx_word = 4; | |
020709f9 | 8666 | |
8d769265 | 8667 | ospf_distance_unset (vty, ospf, argv[idx_number]->arg, argv[idx_ipv4_prefixlen]->arg, argv[idx_word]->arg); |
020709f9 | 8668 | |
718e3744 | 8669 | return CMD_SUCCESS; |
8670 | } | |
d7d73ffc | 8671 | #endif |
718e3744 | 8672 | |
ba682537 | 8673 | DEFUN (ip_ospf_mtu_ignore, |
8674 | ip_ospf_mtu_ignore_addr_cmd, | |
7a7be519 | 8675 | "ip ospf mtu-ignore [A.B.C.D]", |
ba682537 | 8676 | "IP Information\n" |
8677 | "OSPF interface commands\n" | |
99a522c7 | 8678 | "Disable MTU mismatch detection on this interface\n" |
efd7904e | 8679 | "Address of interface\n") |
ba682537 | 8680 | { |
d62a17ae | 8681 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8682 | int idx_ipv4 = 3; | |
8683 | struct in_addr addr; | |
8684 | int ret; | |
8685 | ||
8686 | struct ospf_if_params *params; | |
8687 | params = IF_DEF_PARAMS(ifp); | |
8688 | ||
8689 | if (argc == 4) { | |
8690 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
8691 | if (!ret) { | |
8692 | vty_out(vty, | |
8693 | "Please specify interface address by A.B.C.D\n"); | |
8694 | return CMD_WARNING_CONFIG_FAILED; | |
8695 | } | |
8696 | params = ospf_get_if_params(ifp, addr); | |
8697 | ospf_if_update_params(ifp, addr); | |
8698 | } | |
8699 | params->mtu_ignore = 1; | |
8700 | if (params->mtu_ignore != OSPF_MTU_IGNORE_DEFAULT) | |
8701 | SET_IF_PARAM(params, mtu_ignore); | |
8702 | else { | |
8703 | UNSET_IF_PARAM(params, mtu_ignore); | |
8704 | if (params != IF_DEF_PARAMS(ifp)) { | |
8705 | ospf_free_if_params(ifp, addr); | |
8706 | ospf_if_update_params(ifp, addr); | |
8707 | } | |
8708 | } | |
8709 | return CMD_SUCCESS; | |
ba682537 | 8710 | } |
8711 | ||
ba682537 | 8712 | DEFUN (no_ip_ospf_mtu_ignore, |
8713 | no_ip_ospf_mtu_ignore_addr_cmd, | |
7a7be519 | 8714 | "no ip ospf mtu-ignore [A.B.C.D]", |
efd7904e | 8715 | NO_STR |
ba682537 | 8716 | "IP Information\n" |
8717 | "OSPF interface commands\n" | |
99a522c7 | 8718 | "Disable MTU mismatch detection on this interface\n" |
efd7904e | 8719 | "Address of interface\n") |
ba682537 | 8720 | { |
d62a17ae | 8721 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8722 | int idx_ipv4 = 4; | |
8723 | struct in_addr addr; | |
8724 | int ret; | |
8725 | ||
8726 | struct ospf_if_params *params; | |
8727 | params = IF_DEF_PARAMS(ifp); | |
8728 | ||
8729 | if (argc == 5) { | |
8730 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
8731 | if (!ret) { | |
8732 | vty_out(vty, | |
8733 | "Please specify interface address by A.B.C.D\n"); | |
8734 | return CMD_WARNING_CONFIG_FAILED; | |
8735 | } | |
8736 | params = ospf_get_if_params(ifp, addr); | |
8737 | ospf_if_update_params(ifp, addr); | |
8738 | } | |
8739 | params->mtu_ignore = 0; | |
8740 | if (params->mtu_ignore != OSPF_MTU_IGNORE_DEFAULT) | |
8741 | SET_IF_PARAM(params, mtu_ignore); | |
8742 | else { | |
8743 | UNSET_IF_PARAM(params, mtu_ignore); | |
8744 | if (params != IF_DEF_PARAMS(ifp)) { | |
8745 | ospf_free_if_params(ifp, addr); | |
8746 | ospf_if_update_params(ifp, addr); | |
8747 | } | |
8748 | } | |
8749 | return CMD_SUCCESS; | |
ba682537 | 8750 | } |
8751 | ||
6b0655a2 | 8752 | |
88d6cf37 | 8753 | DEFUN (ospf_max_metric_router_lsa_admin, |
8754 | ospf_max_metric_router_lsa_admin_cmd, | |
8755 | "max-metric router-lsa administrative", | |
8756 | "OSPF maximum / infinite-distance metric\n" | |
8757 | "Advertise own Router-LSA with infinite distance (stub router)\n" | |
8758 | "Administratively applied, for an indefinite period\n") | |
8759 | { | |
a3d826f0 | 8760 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 8761 | struct listnode *ln; |
8762 | struct ospf_area *area; | |
7c8ff89e | 8763 | |
d62a17ae | 8764 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, ln, area)) { |
8765 | SET_FLAG(area->stub_router_state, OSPF_AREA_ADMIN_STUB_ROUTED); | |
4ba4fc85 | 8766 | |
d62a17ae | 8767 | if (!CHECK_FLAG(area->stub_router_state, |
8768 | OSPF_AREA_IS_STUB_ROUTED)) | |
8769 | ospf_router_lsa_update_area(area); | |
8770 | } | |
4ba4fc85 | 8771 | |
d62a17ae | 8772 | /* Allows for areas configured later to get the property */ |
8773 | ospf->stub_router_admin_set = OSPF_STUB_ROUTER_ADMINISTRATIVE_SET; | |
8774 | ||
8775 | return CMD_SUCCESS; | |
88d6cf37 | 8776 | } |
8777 | ||
8778 | DEFUN (no_ospf_max_metric_router_lsa_admin, | |
8779 | no_ospf_max_metric_router_lsa_admin_cmd, | |
8780 | "no max-metric router-lsa administrative", | |
8781 | NO_STR | |
8782 | "OSPF maximum / infinite-distance metric\n" | |
8783 | "Advertise own Router-LSA with infinite distance (stub router)\n" | |
8784 | "Administratively applied, for an indefinite period\n") | |
8785 | { | |
a3d826f0 | 8786 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 8787 | struct listnode *ln; |
8788 | struct ospf_area *area; | |
8789 | ||
8790 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, ln, area)) { | |
8791 | UNSET_FLAG(area->stub_router_state, | |
8792 | OSPF_AREA_ADMIN_STUB_ROUTED); | |
8793 | ||
8794 | /* Don't trample on the start-up stub timer */ | |
8795 | if (CHECK_FLAG(area->stub_router_state, | |
8796 | OSPF_AREA_IS_STUB_ROUTED) | |
8797 | && !area->t_stub_router) { | |
8798 | UNSET_FLAG(area->stub_router_state, | |
8799 | OSPF_AREA_IS_STUB_ROUTED); | |
8800 | ospf_router_lsa_update_area(area); | |
8801 | } | |
8802 | } | |
8803 | ospf->stub_router_admin_set = OSPF_STUB_ROUTER_ADMINISTRATIVE_UNSET; | |
8804 | return CMD_SUCCESS; | |
88d6cf37 | 8805 | } |
8806 | ||
8807 | DEFUN (ospf_max_metric_router_lsa_startup, | |
8808 | ospf_max_metric_router_lsa_startup_cmd, | |
6147e2c6 | 8809 | "max-metric router-lsa on-startup (5-86400)", |
88d6cf37 | 8810 | "OSPF maximum / infinite-distance metric\n" |
8811 | "Advertise own Router-LSA with infinite distance (stub router)\n" | |
8812 | "Automatically advertise stub Router-LSA on startup of OSPF\n" | |
8813 | "Time (seconds) to advertise self as stub-router\n") | |
8814 | { | |
a3d826f0 | 8815 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 8816 | int idx_number = 3; |
8817 | unsigned int seconds; | |
8818 | ||
b5a8894d | 8819 | if (argc < 4) { |
d62a17ae | 8820 | vty_out(vty, "%% Must supply stub-router period"); |
8821 | return CMD_WARNING_CONFIG_FAILED; | |
8822 | } | |
8823 | ||
8824 | seconds = strtoul(argv[idx_number]->arg, NULL, 10); | |
8825 | ||
8826 | ospf->stub_router_startup_time = seconds; | |
8827 | ||
8828 | return CMD_SUCCESS; | |
88d6cf37 | 8829 | } |
8830 | ||
8831 | DEFUN (no_ospf_max_metric_router_lsa_startup, | |
8832 | no_ospf_max_metric_router_lsa_startup_cmd, | |
7a7be519 | 8833 | "no max-metric router-lsa on-startup [(5-86400)]", |
88d6cf37 | 8834 | NO_STR |
8835 | "OSPF maximum / infinite-distance metric\n" | |
8836 | "Advertise own Router-LSA with infinite distance (stub router)\n" | |
813d4307 DW |
8837 | "Automatically advertise stub Router-LSA on startup of OSPF\n" |
8838 | "Time (seconds) to advertise self as stub-router\n") | |
88d6cf37 | 8839 | { |
a3d826f0 | 8840 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 8841 | struct listnode *ln; |
8842 | struct ospf_area *area; | |
8843 | ||
8844 | ospf->stub_router_startup_time = OSPF_STUB_ROUTER_UNCONFIGURED; | |
8845 | ||
8846 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, ln, area)) { | |
8847 | SET_FLAG(area->stub_router_state, | |
8848 | OSPF_AREA_WAS_START_STUB_ROUTED); | |
8849 | OSPF_TIMER_OFF(area->t_stub_router); | |
8850 | ||
8851 | /* Don't trample on admin stub routed */ | |
8852 | if (!CHECK_FLAG(area->stub_router_state, | |
8853 | OSPF_AREA_ADMIN_STUB_ROUTED)) { | |
8854 | UNSET_FLAG(area->stub_router_state, | |
8855 | OSPF_AREA_IS_STUB_ROUTED); | |
8856 | ospf_router_lsa_update_area(area); | |
8857 | } | |
8858 | } | |
8859 | return CMD_SUCCESS; | |
88d6cf37 | 8860 | } |
8861 | ||
a1afa410 | 8862 | |
88d6cf37 | 8863 | DEFUN (ospf_max_metric_router_lsa_shutdown, |
8864 | ospf_max_metric_router_lsa_shutdown_cmd, | |
6147e2c6 | 8865 | "max-metric router-lsa on-shutdown (5-100)", |
88d6cf37 | 8866 | "OSPF maximum / infinite-distance metric\n" |
8867 | "Advertise own Router-LSA with infinite distance (stub router)\n" | |
8868 | "Advertise stub-router prior to full shutdown of OSPF\n" | |
8869 | "Time (seconds) to wait till full shutdown\n") | |
8870 | { | |
a3d826f0 | 8871 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 8872 | int idx_number = 3; |
8873 | unsigned int seconds; | |
8874 | ||
b5a8894d | 8875 | if (argc < 4) { |
d62a17ae | 8876 | vty_out(vty, "%% Must supply stub-router shutdown period"); |
8877 | return CMD_WARNING_CONFIG_FAILED; | |
8878 | } | |
8879 | ||
8880 | seconds = strtoul(argv[idx_number]->arg, NULL, 10); | |
8881 | ||
8882 | ospf->stub_router_shutdown_time = seconds; | |
8883 | ||
8884 | return CMD_SUCCESS; | |
88d6cf37 | 8885 | } |
8886 | ||
8887 | DEFUN (no_ospf_max_metric_router_lsa_shutdown, | |
8888 | no_ospf_max_metric_router_lsa_shutdown_cmd, | |
7a7be519 | 8889 | "no max-metric router-lsa on-shutdown [(5-100)]", |
88d6cf37 | 8890 | NO_STR |
8891 | "OSPF maximum / infinite-distance metric\n" | |
8892 | "Advertise own Router-LSA with infinite distance (stub router)\n" | |
813d4307 DW |
8893 | "Advertise stub-router prior to full shutdown of OSPF\n" |
8894 | "Time (seconds) to wait till full shutdown\n") | |
88d6cf37 | 8895 | { |
a3d826f0 | 8896 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
7c8ff89e | 8897 | |
d62a17ae | 8898 | ospf->stub_router_shutdown_time = OSPF_STUB_ROUTER_UNCONFIGURED; |
8899 | ||
8900 | return CMD_SUCCESS; | |
88d6cf37 | 8901 | } |
8902 | ||
d62a17ae | 8903 | static void config_write_stub_router(struct vty *vty, struct ospf *ospf) |
8904 | { | |
8905 | struct listnode *ln; | |
8906 | struct ospf_area *area; | |
8907 | ||
8908 | if (ospf->stub_router_startup_time != OSPF_STUB_ROUTER_UNCONFIGURED) | |
8909 | vty_out(vty, " max-metric router-lsa on-startup %u\n", | |
8910 | ospf->stub_router_startup_time); | |
8911 | if (ospf->stub_router_shutdown_time != OSPF_STUB_ROUTER_UNCONFIGURED) | |
8912 | vty_out(vty, " max-metric router-lsa on-shutdown %u\n", | |
8913 | ospf->stub_router_shutdown_time); | |
8914 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, ln, area)) { | |
8915 | if (CHECK_FLAG(area->stub_router_state, | |
8916 | OSPF_AREA_ADMIN_STUB_ROUTED)) { | |
8917 | vty_out(vty, " max-metric router-lsa administrative\n"); | |
8918 | break; | |
8919 | } | |
8920 | } | |
8921 | return; | |
8922 | } | |
8923 | ||
b5a8894d | 8924 | static void show_ip_ospf_route_network(struct vty *vty, struct ospf *ospf, |
0f478e30 CS |
8925 | struct route_table *rt, |
8926 | json_object *json) | |
d62a17ae | 8927 | { |
8928 | struct route_node *rn; | |
8929 | struct ospf_route * or ; | |
8930 | struct listnode *pnode, *pnnode; | |
8931 | struct ospf_path *path; | |
0f478e30 CS |
8932 | json_object *json_route = NULL, *json_nexthop_array = NULL, |
8933 | *json_nexthop = NULL; | |
d62a17ae | 8934 | |
0f478e30 | 8935 | if (!json) |
996c9314 LB |
8936 | vty_out(vty, |
8937 | "============ OSPF network routing table ============\n"); | |
d62a17ae | 8938 | |
0f478e30 CS |
8939 | for (rn = route_top(rt); rn; rn = route_next(rn)) { |
8940 | if ((or = rn->info) == NULL) | |
8941 | continue; | |
8942 | char buf1[PREFIX2STR_BUFFER]; | |
8943 | ||
8944 | memset(buf1, 0, sizeof(buf1)); | |
8945 | prefix2str(&rn->p, buf1, sizeof(buf1)); | |
8946 | ||
8947 | json_route = json_object_new_object(); | |
8948 | if (json) { | |
996c9314 LB |
8949 | json_object_object_add(json, buf1, json_route); |
8950 | json_object_to_json_string_ext( | |
8951 | json, JSON_C_TO_STRING_NOSLASHESCAPE); | |
0f478e30 CS |
8952 | } |
8953 | ||
8954 | switch (or->path_type) { | |
8955 | case OSPF_PATH_INTER_AREA: | |
8956 | if (or->type == OSPF_DESTINATION_NETWORK) { | |
8957 | if (json) { | |
8958 | json_object_string_add(json_route, | |
996c9314 LB |
8959 | "routeType", |
8960 | "N IA"); | |
8961 | json_object_int_add(json_route, "cost", | |
0f478e30 CS |
8962 | or->cost); |
8963 | json_object_string_add( | |
996c9314 LB |
8964 | json_route, "area", |
8965 | inet_ntoa(or->u.std.area_id)); | |
0f478e30 | 8966 | } else { |
d62a17ae | 8967 | vty_out(vty, |
996c9314 | 8968 | "N IA %-18s [%d] area: %s\n", |
d62a17ae | 8969 | buf1, or->cost, |
996c9314 | 8970 | inet_ntoa(or->u.std.area_id)); |
0f478e30 | 8971 | } |
996c9314 | 8972 | } else if (or->type == OSPF_DESTINATION_DISCARD) { |
0f478e30 CS |
8973 | if (json) { |
8974 | json_object_string_add(json_route, | |
996c9314 LB |
8975 | "routeType", |
8976 | "D IA"); | |
0f478e30 | 8977 | } else { |
d62a17ae | 8978 | vty_out(vty, |
8979 | "D IA %-18s Discard entry\n", | |
8980 | buf1); | |
0f478e30 CS |
8981 | } |
8982 | } | |
8983 | break; | |
8984 | case OSPF_PATH_INTRA_AREA: | |
8985 | if (json) { | |
996c9314 LB |
8986 | json_object_string_add(json_route, "routeType", |
8987 | "N"); | |
0f478e30 | 8988 | json_object_int_add(json_route, "cost", |
996c9314 LB |
8989 | or->cost); |
8990 | json_object_string_add( | |
8991 | json_route, "area", | |
8992 | inet_ntoa(or->u.std.area_id)); | |
0f478e30 | 8993 | } else { |
d62a17ae | 8994 | vty_out(vty, "N %-18s [%d] area: %s\n", |
8995 | buf1, or->cost, | |
8996 | inet_ntoa(or->u.std.area_id)); | |
0f478e30 CS |
8997 | } |
8998 | break; | |
8999 | default: | |
9000 | break; | |
9001 | } | |
9002 | ||
9003 | if (or->type == OSPF_DESTINATION_NETWORK) { | |
9004 | if (json) { | |
9005 | json_nexthop_array = json_object_new_array(); | |
9006 | json_object_object_add(json_route, "nexthops", | |
996c9314 | 9007 | json_nexthop_array); |
d62a17ae | 9008 | } |
9009 | ||
0f478e30 CS |
9010 | for (ALL_LIST_ELEMENTS(or->paths, pnode, pnnode, |
9011 | path)) { | |
9012 | if (json) { | |
996c9314 LB |
9013 | json_nexthop = json_object_new_object(); |
9014 | json_object_array_add( | |
9015 | json_nexthop_array, | |
9016 | json_nexthop); | |
0f478e30 CS |
9017 | } |
9018 | if (if_lookup_by_index(path->ifindex, | |
9019 | ospf->vrf_id)) { | |
9020 | ||
9021 | if (path->nexthop.s_addr == 0) { | |
9022 | if (json) { | |
9023 | json_object_string_add( | |
9024 | json_nexthop, | |
996c9314 | 9025 | "ip", " "); |
0f478e30 CS |
9026 | json_object_string_add( |
9027 | json_nexthop, | |
9028 | "directly attached to", | |
d62a17ae | 9029 | ifindex2ifname( |
996c9314 LB |
9030 | path->ifindex, |
9031 | ospf->vrf_id)); | |
0f478e30 | 9032 | } else { |
d62a17ae | 9033 | vty_out(vty, |
996c9314 LB |
9034 | "%24s directly attached to %s\n", |
9035 | "", | |
9036 | ifindex2ifname( | |
9037 | path->ifindex, | |
9038 | ospf->vrf_id)); | |
0f478e30 CS |
9039 | } |
9040 | } else { | |
9041 | if (json) { | |
9042 | json_object_string_add( | |
9043 | json_nexthop, | |
9044 | "ip", | |
d62a17ae | 9045 | inet_ntoa( |
996c9314 | 9046 | path->nexthop)); |
0f478e30 CS |
9047 | json_object_string_add( |
9048 | json_nexthop, | |
9049 | "via", | |
d62a17ae | 9050 | ifindex2ifname( |
996c9314 LB |
9051 | path->ifindex, |
9052 | ospf->vrf_id)); | |
0f478e30 CS |
9053 | } else { |
9054 | vty_out(vty, | |
996c9314 LB |
9055 | "%24s via %s, %s\n", |
9056 | "", | |
9057 | inet_ntoa( | |
9058 | path->nexthop), | |
9059 | ifindex2ifname( | |
9060 | path->ifindex, | |
9061 | ospf->vrf_id)); | |
0f478e30 | 9062 | } |
d62a17ae | 9063 | } |
9064 | } | |
0f478e30 | 9065 | } |
d62a17ae | 9066 | } |
0f478e30 CS |
9067 | if (!json) |
9068 | json_object_free(json_route); | |
9069 | } | |
9070 | if (!json) | |
9071 | vty_out(vty, "\n"); | |
d62a17ae | 9072 | } |
9073 | ||
b5a8894d | 9074 | static void show_ip_ospf_route_router(struct vty *vty, struct ospf *ospf, |
0f478e30 CS |
9075 | struct route_table *rtrs, |
9076 | json_object *json) | |
d62a17ae | 9077 | { |
9078 | struct route_node *rn; | |
9079 | struct ospf_route * or ; | |
9080 | struct listnode *pnode; | |
9081 | struct listnode *node; | |
9082 | struct ospf_path *path; | |
0f478e30 CS |
9083 | json_object *json_route = NULL, *json_nexthop_array = NULL, |
9084 | *json_nexthop = NULL; | |
d62a17ae | 9085 | |
0f478e30 | 9086 | if (!json) |
996c9314 LB |
9087 | vty_out(vty, |
9088 | "============ OSPF router routing table =============\n"); | |
d62a17ae | 9089 | |
0f478e30 CS |
9090 | for (rn = route_top(rtrs); rn; rn = route_next(rn)) { |
9091 | if (rn->info == NULL) | |
9092 | continue; | |
9093 | int flag = 0; | |
9094 | ||
9095 | json_route = json_object_new_object(); | |
9096 | if (json) { | |
996c9314 LB |
9097 | json_object_object_add(json, inet_ntoa(rn->p.u.prefix4), |
9098 | json_route); | |
9099 | json_object_string_add(json_route, "routeType", "R "); | |
0f478e30 | 9100 | } else { |
d62a17ae | 9101 | vty_out(vty, "R %-15s ", |
9102 | inet_ntoa(rn->p.u.prefix4)); | |
0f478e30 | 9103 | } |
d62a17ae | 9104 | |
996c9314 | 9105 | for (ALL_LIST_ELEMENTS_RO((struct list *)rn->info, node, or)) { |
0f478e30 CS |
9106 | if (flag++) { |
9107 | if (!json) | |
d62a17ae | 9108 | vty_out(vty, "%24s", ""); |
0f478e30 | 9109 | } |
d62a17ae | 9110 | |
0f478e30 CS |
9111 | /* Show path. */ |
9112 | if (json) { | |
9113 | json_object_int_add(json_route, "cost", | |
9114 | or->cost); | |
996c9314 LB |
9115 | json_object_string_add( |
9116 | json_route, "area", | |
0f478e30 | 9117 | inet_ntoa(or->u.std.area_id)); |
996c9314 LB |
9118 | if (or->path_type == OSPF_PATH_INTER_AREA) |
9119 | json_object_boolean_true_add(json_route, | |
9120 | "IA"); | |
0f478e30 | 9121 | if (or->u.std.flags & ROUTER_LSA_BORDER) |
996c9314 LB |
9122 | json_object_string_add(json_route, |
9123 | "routerType", | |
9124 | "abr"); | |
9125 | else if (or->u.std.flags & ROUTER_LSA_EXTERNAL) | |
9126 | json_object_string_add(json_route, | |
9127 | "routerType", | |
9128 | "asbr"); | |
0f478e30 | 9129 | } else { |
d62a17ae | 9130 | vty_out(vty, "%s [%d] area: %s", |
996c9314 LB |
9131 | (or->path_type == OSPF_PATH_INTER_AREA |
9132 | ? "IA" | |
9133 | : " "), | |
9134 | or->cost, inet_ntoa(or->u.std.area_id)); | |
d62a17ae | 9135 | /* Show flags. */ |
9136 | vty_out(vty, "%s%s\n", | |
996c9314 LB |
9137 | (or->u.std.flags & ROUTER_LSA_BORDER |
9138 | ? ", ABR" | |
9139 | : ""), | |
9140 | (or->u.std.flags & ROUTER_LSA_EXTERNAL | |
9141 | ? ", ASBR" | |
9142 | : "")); | |
0f478e30 CS |
9143 | } |
9144 | ||
9145 | if (json) { | |
996c9314 | 9146 | json_nexthop_array = json_object_new_array(); |
0f478e30 | 9147 | json_object_object_add(json_route, "nexthops", |
996c9314 | 9148 | json_nexthop_array); |
0f478e30 CS |
9149 | } |
9150 | ||
996c9314 | 9151 | for (ALL_LIST_ELEMENTS_RO(or->paths, pnode, path)) { |
0f478e30 | 9152 | if (json) { |
996c9314 | 9153 | json_nexthop = json_object_new_object(); |
0f478e30 CS |
9154 | json_object_array_add( |
9155 | json_nexthop_array, | |
9156 | json_nexthop); | |
9157 | } | |
9158 | if (if_lookup_by_index(path->ifindex, | |
9159 | ospf->vrf_id)) { | |
9160 | if (path->nexthop.s_addr == 0) { | |
9161 | if (json) { | |
9162 | json_object_string_add( | |
9163 | json_nexthop, | |
996c9314 | 9164 | "ip", " "); |
0f478e30 CS |
9165 | json_object_string_add( |
9166 | json_nexthop, | |
9167 | "directly attached to", | |
d62a17ae | 9168 | ifindex2ifname( |
9169 | path->ifindex, | |
b5a8894d | 9170 | ospf->vrf_id)); |
0f478e30 | 9171 | } else { |
d62a17ae | 9172 | vty_out(vty, |
996c9314 LB |
9173 | "%24s directly attached to %s\n", |
9174 | "", | |
9175 | ifindex2ifname( | |
9176 | path->ifindex, | |
9177 | ospf->vrf_id)); | |
0f478e30 CS |
9178 | } |
9179 | } else { | |
9180 | if (json) { | |
9181 | json_object_string_add( | |
9182 | json_nexthop, | |
9183 | "ip", | |
996c9314 LB |
9184 | inet_ntoa( |
9185 | path->nexthop)); | |
0f478e30 CS |
9186 | json_object_string_add( |
9187 | json_nexthop, | |
9188 | "via", | |
d62a17ae | 9189 | ifindex2ifname( |
9190 | path->ifindex, | |
b5a8894d | 9191 | ospf->vrf_id)); |
0f478e30 CS |
9192 | } else { |
9193 | vty_out(vty, | |
996c9314 LB |
9194 | "%24s via %s, %s\n", |
9195 | "", | |
9196 | inet_ntoa( | |
9197 | path->nexthop), | |
9198 | ifindex2ifname( | |
9199 | path->ifindex, | |
9200 | ospf->vrf_id)); | |
0f478e30 | 9201 | } |
d62a17ae | 9202 | } |
9203 | } | |
9204 | } | |
9205 | } | |
0f478e30 CS |
9206 | if (!json) |
9207 | json_object_free(json_route); | |
9208 | } | |
9209 | if (!json) | |
9210 | vty_out(vty, "\n"); | |
d62a17ae | 9211 | } |
9212 | ||
b5a8894d | 9213 | static void show_ip_ospf_route_external(struct vty *vty, struct ospf *ospf, |
0f478e30 CS |
9214 | struct route_table *rt, |
9215 | json_object *json) | |
d62a17ae | 9216 | { |
9217 | struct route_node *rn; | |
9218 | struct ospf_route *er; | |
9219 | struct listnode *pnode, *pnnode; | |
9220 | struct ospf_path *path; | |
0f478e30 CS |
9221 | json_object *json_route = NULL, *json_nexthop_array = NULL, |
9222 | *json_nexthop = NULL; | |
d62a17ae | 9223 | |
0f478e30 | 9224 | if (!json) |
996c9314 LB |
9225 | vty_out(vty, |
9226 | "============ OSPF external routing table ===========\n"); | |
0f478e30 CS |
9227 | |
9228 | for (rn = route_top(rt); rn; rn = route_next(rn)) { | |
9229 | if ((er = rn->info) == NULL) | |
9230 | continue; | |
9231 | ||
9232 | char buf1[19]; | |
9233 | ||
9234 | snprintf(buf1, 19, "%s/%d", inet_ntoa(rn->p.u.prefix4), | |
9235 | rn->p.prefixlen); | |
9236 | json_route = json_object_new_object(); | |
9237 | if (json) { | |
996c9314 LB |
9238 | json_object_object_add(json, buf1, json_route); |
9239 | json_object_to_json_string_ext( | |
9240 | json, JSON_C_TO_STRING_NOSLASHESCAPE); | |
0f478e30 | 9241 | } |
d62a17ae | 9242 | |
0f478e30 CS |
9243 | switch (er->path_type) { |
9244 | case OSPF_PATH_TYPE1_EXTERNAL: | |
9245 | if (json) { | |
996c9314 | 9246 | json_object_string_add(json_route, "routeType", |
0f478e30 CS |
9247 | "N E1"); |
9248 | json_object_int_add(json_route, "cost", | |
996c9314 | 9249 | er->cost); |
0f478e30 | 9250 | } else { |
d62a17ae | 9251 | vty_out(vty, |
996c9314 LB |
9252 | "N E1 %-18s [%d] tag: %" ROUTE_TAG_PRI |
9253 | "\n", | |
9254 | buf1, er->cost, er->u.ext.tag); | |
0f478e30 CS |
9255 | } |
9256 | break; | |
9257 | case OSPF_PATH_TYPE2_EXTERNAL: | |
9258 | if (json) { | |
996c9314 | 9259 | json_object_string_add(json_route, "routeType", |
0f478e30 CS |
9260 | "N E2"); |
9261 | json_object_int_add(json_route, "cost", | |
996c9314 | 9262 | er->cost); |
0f478e30 | 9263 | } else { |
d62a17ae | 9264 | vty_out(vty, |
996c9314 LB |
9265 | "N E2 %-18s [%d/%d] tag: %" ROUTE_TAG_PRI |
9266 | "\n", | |
9267 | buf1, er->cost, er->u.ext.type2_cost, | |
d62a17ae | 9268 | er->u.ext.tag); |
d62a17ae | 9269 | } |
0f478e30 CS |
9270 | break; |
9271 | } | |
d62a17ae | 9272 | |
0f478e30 CS |
9273 | if (json) { |
9274 | json_nexthop_array = json_object_new_array(); | |
9275 | json_object_object_add(json_route, "nexthops", | |
996c9314 | 9276 | json_nexthop_array); |
0f478e30 CS |
9277 | } |
9278 | ||
996c9314 | 9279 | for (ALL_LIST_ELEMENTS(er->paths, pnode, pnnode, path)) { |
0f478e30 CS |
9280 | if (json) { |
9281 | json_nexthop = json_object_new_object(); | |
996c9314 LB |
9282 | json_object_array_add(json_nexthop_array, |
9283 | json_nexthop); | |
0f478e30 CS |
9284 | } |
9285 | ||
996c9314 | 9286 | if (if_lookup_by_index(path->ifindex, ospf->vrf_id)) { |
0f478e30 CS |
9287 | if (path->nexthop.s_addr == 0) { |
9288 | if (json) { | |
9289 | json_object_string_add( | |
996c9314 LB |
9290 | json_nexthop, "ip", |
9291 | " "); | |
0f478e30 CS |
9292 | json_object_string_add( |
9293 | json_nexthop, | |
9294 | "directly attached to", | |
d62a17ae | 9295 | ifindex2ifname( |
996c9314 LB |
9296 | path->ifindex, |
9297 | ospf->vrf_id)); | |
0f478e30 | 9298 | } else { |
d62a17ae | 9299 | vty_out(vty, |
996c9314 LB |
9300 | "%24s directly attached to %s\n", |
9301 | "", | |
9302 | ifindex2ifname( | |
9303 | path->ifindex, | |
9304 | ospf->vrf_id)); | |
0f478e30 CS |
9305 | } |
9306 | } else { | |
9307 | if (json) { | |
9308 | json_object_string_add( | |
996c9314 | 9309 | json_nexthop, "ip", |
d62a17ae | 9310 | inet_ntoa( |
996c9314 | 9311 | path->nexthop)); |
0f478e30 | 9312 | json_object_string_add( |
996c9314 | 9313 | json_nexthop, "via", |
d62a17ae | 9314 | ifindex2ifname( |
996c9314 LB |
9315 | path->ifindex, |
9316 | ospf->vrf_id)); | |
0f478e30 CS |
9317 | } else { |
9318 | vty_out(vty, | |
996c9314 LB |
9319 | "%24s via %s, %s\n", |
9320 | "", | |
9321 | inet_ntoa( | |
9322 | path->nexthop), | |
9323 | ifindex2ifname( | |
9324 | path->ifindex, | |
9325 | ospf->vrf_id)); | |
0f478e30 | 9326 | } |
d62a17ae | 9327 | } |
54bedb55 | 9328 | } |
d62a17ae | 9329 | } |
0f478e30 CS |
9330 | if (!json) |
9331 | json_object_free(json_route); | |
9332 | } | |
9333 | if (!json) | |
9334 | vty_out(vty, "\n"); | |
718e3744 | 9335 | } |
9336 | ||
d62a17ae | 9337 | static int show_ip_ospf_border_routers_common(struct vty *vty, |
d7c0a89a QY |
9338 | struct ospf *ospf, |
9339 | uint8_t use_vrf) | |
718e3744 | 9340 | { |
d62a17ae | 9341 | if (ospf->instance) |
9342 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
718e3744 | 9343 | |
b1c3ae8c | 9344 | ospf_show_vrf_name(ospf, vty, NULL, use_vrf); |
87bd50e8 | 9345 | |
d62a17ae | 9346 | if (ospf->new_table == NULL) { |
9347 | vty_out(vty, "No OSPF routing information exist\n"); | |
9348 | return CMD_SUCCESS; | |
9349 | } | |
718e3744 | 9350 | |
d62a17ae | 9351 | /* Show Network routes. |
9352 | show_ip_ospf_route_network (vty, ospf->new_table); */ | |
718e3744 | 9353 | |
d62a17ae | 9354 | /* Show Router routes. */ |
0f478e30 | 9355 | show_ip_ospf_route_router(vty, ospf, ospf->new_rtrs, NULL); |
718e3744 | 9356 | |
d62a17ae | 9357 | vty_out(vty, "\n"); |
7c8ff89e | 9358 | |
d62a17ae | 9359 | return CMD_SUCCESS; |
718e3744 | 9360 | } |
718e3744 | 9361 | |
7c8ff89e DS |
9362 | DEFUN (show_ip_ospf_border_routers, |
9363 | show_ip_ospf_border_routers_cmd, | |
b5a8894d | 9364 | "show ip ospf [vrf <NAME|all>] border-routers", |
718e3744 | 9365 | SHOW_STR |
9366 | IP_STR | |
9367 | "OSPF information\n" | |
b5a8894d CS |
9368 | VRF_CMD_HELP_STR |
9369 | "All VRFs\n" | |
7c8ff89e | 9370 | "Show all the ABR's and ASBR's\n") |
718e3744 | 9371 | { |
b5a8894d CS |
9372 | struct ospf *ospf = NULL; |
9373 | struct listnode *node = NULL; | |
9374 | char *vrf_name = NULL; | |
2951a7a4 | 9375 | bool all_vrf = false; |
b5a8894d CS |
9376 | int ret = CMD_SUCCESS; |
9377 | int inst = 0; | |
9378 | int idx_vrf = 0; | |
d7c0a89a | 9379 | uint8_t use_vrf = 0; |
68980084 | 9380 | |
43b8d1d8 | 9381 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
7c8ff89e | 9382 | |
b5a8894d | 9383 | if (vrf_name) { |
2951a7a4 | 9384 | bool ospf_output = false; |
874f58d8 | 9385 | |
b1c3ae8c | 9386 | use_vrf = 1; |
94d4c685 | 9387 | |
b5a8894d CS |
9388 | if (all_vrf) { |
9389 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
9390 | if (!ospf->oi_running) | |
9391 | continue; | |
b5a8894d | 9392 | |
2951a7a4 | 9393 | ospf_output = true; |
996c9314 LB |
9394 | ret = show_ip_ospf_border_routers_common( |
9395 | vty, ospf, use_vrf); | |
b5a8894d | 9396 | } |
9f049418 DS |
9397 | |
9398 | if (!ospf_output) | |
94d4c685 | 9399 | vty_out(vty, "%% OSPF instance not found\n"); |
b5a8894d CS |
9400 | } else { |
9401 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
9f049418 | 9402 | if (ospf == NULL || !ospf->oi_running) { |
94d4c685 | 9403 | vty_out(vty, "%% OSPF instance not found\n"); |
b5a8894d | 9404 | return CMD_SUCCESS; |
9f049418 | 9405 | } |
b5a8894d | 9406 | |
b1c3ae8c CS |
9407 | ret = show_ip_ospf_border_routers_common(vty, ospf, |
9408 | use_vrf); | |
b5a8894d CS |
9409 | } |
9410 | } else { | |
9411 | /* Display default ospf (instance 0) info */ | |
9412 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
9f049418 | 9413 | if (ospf == NULL || !ospf->oi_running) { |
94d4c685 | 9414 | vty_out(vty, "%% OSPF instance not found\n"); |
b5a8894d | 9415 | return CMD_SUCCESS; |
9f049418 DS |
9416 | } |
9417 | ||
b1c3ae8c | 9418 | ret = show_ip_ospf_border_routers_common(vty, ospf, use_vrf); |
b5a8894d CS |
9419 | } |
9420 | ||
9421 | return ret; | |
7c8ff89e DS |
9422 | } |
9423 | ||
9424 | DEFUN (show_ip_ospf_instance_border_routers, | |
9425 | show_ip_ospf_instance_border_routers_cmd, | |
6147e2c6 | 9426 | "show ip ospf (1-65535) border-routers", |
7c8ff89e DS |
9427 | SHOW_STR |
9428 | IP_STR | |
9429 | "OSPF information\n" | |
9430 | "Instance ID\n" | |
9431 | "Show all the ABR's and ASBR's\n") | |
9432 | { | |
d62a17ae | 9433 | int idx_number = 3; |
9434 | struct ospf *ospf; | |
d7c0a89a | 9435 | unsigned short instance = 0; |
7c8ff89e | 9436 | |
d62a17ae | 9437 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
ac28e4ec CS |
9438 | ospf = ospf_lookup_instance(instance); |
9439 | if (ospf == NULL) | |
9440 | return CMD_NOT_MY_INSTANCE; | |
9441 | ||
9442 | if (!ospf->oi_running) | |
d62a17ae | 9443 | return CMD_SUCCESS; |
7c8ff89e | 9444 | |
b1c3ae8c | 9445 | return show_ip_ospf_border_routers_common(vty, ospf, 0); |
7c8ff89e DS |
9446 | } |
9447 | ||
b1c3ae8c | 9448 | static int show_ip_ospf_route_common(struct vty *vty, struct ospf *ospf, |
d7c0a89a | 9449 | json_object *json, uint8_t use_vrf) |
7c8ff89e | 9450 | { |
0f478e30 CS |
9451 | json_object *json_vrf = NULL; |
9452 | ||
d62a17ae | 9453 | if (ospf->instance) |
9454 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
718e3744 | 9455 | |
0f478e30 CS |
9456 | |
9457 | if (json) { | |
9458 | if (use_vrf) | |
9459 | json_vrf = json_object_new_object(); | |
9460 | else | |
9461 | json_vrf = json; | |
9462 | } | |
9463 | ||
9464 | ospf_show_vrf_name(ospf, vty, json_vrf, use_vrf); | |
87bd50e8 | 9465 | |
d62a17ae | 9466 | if (ospf->new_table == NULL) { |
9467 | vty_out(vty, "No OSPF routing information exist\n"); | |
9468 | return CMD_SUCCESS; | |
9469 | } | |
718e3744 | 9470 | |
d62a17ae | 9471 | /* Show Network routes. */ |
0f478e30 | 9472 | show_ip_ospf_route_network(vty, ospf, ospf->new_table, json_vrf); |
718e3744 | 9473 | |
d62a17ae | 9474 | /* Show Router routes. */ |
0f478e30 | 9475 | show_ip_ospf_route_router(vty, ospf, ospf->new_rtrs, json_vrf); |
718e3744 | 9476 | |
d62a17ae | 9477 | /* Show AS External routes. */ |
0f478e30 CS |
9478 | show_ip_ospf_route_external(vty, ospf, ospf->old_external_route, |
9479 | json_vrf); | |
718e3744 | 9480 | |
0f478e30 CS |
9481 | if (json) { |
9482 | if (use_vrf) { | |
996c9314 LB |
9483 | // json_object_object_add(json_vrf, "areas", |
9484 | // json_areas); | |
0f478e30 CS |
9485 | if (ospf->vrf_id == VRF_DEFAULT) |
9486 | json_object_object_add(json, "default", | |
9487 | json_vrf); | |
9488 | else | |
9489 | json_object_object_add(json, ospf->name, | |
9490 | json_vrf); | |
9491 | } | |
9492 | } else { | |
9493 | vty_out(vty, "\n"); | |
9494 | } | |
7c8ff89e | 9495 | |
d62a17ae | 9496 | return CMD_SUCCESS; |
718e3744 | 9497 | } |
9498 | ||
7c8ff89e DS |
9499 | DEFUN (show_ip_ospf_route, |
9500 | show_ip_ospf_route_cmd, | |
0f478e30 | 9501 | "show ip ospf [vrf <NAME|all>] route [json]", |
b5a8894d CS |
9502 | SHOW_STR |
9503 | IP_STR | |
9504 | "OSPF information\n" | |
9505 | VRF_CMD_HELP_STR | |
9506 | "All VRFs\n" | |
0f478e30 CS |
9507 | "OSPF routing table\n" |
9508 | JSON_STR) | |
b5a8894d CS |
9509 | { |
9510 | struct ospf *ospf = NULL; | |
9511 | struct listnode *node = NULL; | |
9512 | char *vrf_name = NULL; | |
2951a7a4 | 9513 | bool all_vrf = false; |
b5a8894d CS |
9514 | int ret = CMD_SUCCESS; |
9515 | int inst = 0; | |
9516 | int idx_vrf = 0; | |
d7c0a89a | 9517 | uint8_t use_vrf = 0; |
9f049418 | 9518 | bool uj = use_json(argc, argv); |
0f478e30 CS |
9519 | json_object *json = NULL; |
9520 | ||
9521 | if (uj) | |
9522 | json = json_object_new_object(); | |
7c8ff89e | 9523 | |
43b8d1d8 | 9524 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
7c8ff89e | 9525 | |
b5a8894d CS |
9526 | /* vrf input is provided could be all or specific vrf*/ |
9527 | if (vrf_name) { | |
2951a7a4 | 9528 | bool ospf_output = false; |
874f58d8 | 9529 | |
b1c3ae8c | 9530 | use_vrf = 1; |
94d4c685 | 9531 | |
b5a8894d CS |
9532 | if (all_vrf) { |
9533 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
9534 | if (!ospf->oi_running) | |
9535 | continue; | |
2951a7a4 | 9536 | ospf_output = true; |
0f478e30 | 9537 | ret = show_ip_ospf_route_common(vty, ospf, json, |
b1c3ae8c | 9538 | use_vrf); |
b5a8894d | 9539 | } |
0f478e30 CS |
9540 | |
9541 | if (uj) { | |
1406159f | 9542 | /* Keep Non-pretty format */ |
0f478e30 | 9543 | vty_out(vty, "%s\n", |
1406159f | 9544 | json_object_to_json_string(json)); |
0f478e30 | 9545 | json_object_free(json); |
9f049418 DS |
9546 | } else if (!ospf_output) |
9547 | vty_out(vty, "%% OSPF instance not found\n"); | |
0f478e30 | 9548 | |
b5a8894d CS |
9549 | return ret; |
9550 | } | |
9551 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
0f478e30 | 9552 | if (ospf == NULL || !ospf->oi_running) { |
9f049418 DS |
9553 | if (uj) { |
9554 | vty_out(vty, "%s\n", | |
9555 | json_object_to_json_string_ext( | |
9556 | json, JSON_C_TO_STRING_PRETTY)); | |
0f478e30 | 9557 | json_object_free(json); |
9f049418 | 9558 | } else |
94d4c685 | 9559 | vty_out(vty, "%% OSPF instance not found\n"); |
9f049418 | 9560 | |
b5a8894d | 9561 | return CMD_SUCCESS; |
0f478e30 | 9562 | } |
b5a8894d CS |
9563 | } else { |
9564 | /* Display default ospf (instance 0) info */ | |
9565 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
0f478e30 | 9566 | if (ospf == NULL || !ospf->oi_running) { |
9f049418 DS |
9567 | if (uj) { |
9568 | vty_out(vty, "%s\n", | |
9569 | json_object_to_json_string_ext( | |
9570 | json, JSON_C_TO_STRING_PRETTY)); | |
0f478e30 | 9571 | json_object_free(json); |
9f049418 | 9572 | } else |
94d4c685 | 9573 | vty_out(vty, "%% OSPF instance not found\n"); |
9f049418 | 9574 | |
b5a8894d | 9575 | return CMD_SUCCESS; |
0f478e30 CS |
9576 | } |
9577 | } | |
9578 | ||
9579 | if (ospf) { | |
9580 | ret = show_ip_ospf_route_common(vty, ospf, json, use_vrf); | |
1406159f | 9581 | /* Keep Non-pretty format */ |
0f478e30 | 9582 | if (uj) |
1406159f | 9583 | vty_out(vty, "%s\n", json_object_to_json_string(json)); |
b5a8894d CS |
9584 | } |
9585 | ||
0f478e30 CS |
9586 | if (uj) |
9587 | json_object_free(json); | |
b5a8894d CS |
9588 | |
9589 | return ret; | |
7c8ff89e DS |
9590 | } |
9591 | ||
9592 | DEFUN (show_ip_ospf_instance_route, | |
9593 | show_ip_ospf_instance_route_cmd, | |
6147e2c6 | 9594 | "show ip ospf (1-65535) route", |
7c8ff89e DS |
9595 | SHOW_STR |
9596 | IP_STR | |
9597 | "OSPF information\n" | |
9598 | "Instance ID\n" | |
9599 | "OSPF routing table\n") | |
9600 | { | |
d62a17ae | 9601 | int idx_number = 3; |
9602 | struct ospf *ospf; | |
d7c0a89a | 9603 | unsigned short instance = 0; |
7c8ff89e | 9604 | |
d62a17ae | 9605 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
ac28e4ec CS |
9606 | ospf = ospf_lookup_instance(instance); |
9607 | if (ospf == NULL) | |
9608 | return CMD_NOT_MY_INSTANCE; | |
9609 | ||
9610 | if (!ospf->oi_running) | |
d62a17ae | 9611 | return CMD_SUCCESS; |
7c8ff89e | 9612 | |
0f478e30 | 9613 | return show_ip_ospf_route_common(vty, ospf, NULL, 0); |
7c8ff89e | 9614 | } |
6b0655a2 | 9615 | |
b5a8894d CS |
9616 | |
9617 | DEFUN (show_ip_ospf_vrfs, | |
9618 | show_ip_ospf_vrfs_cmd, | |
9619 | "show ip ospf vrfs [json]", | |
9620 | SHOW_STR | |
9621 | IP_STR | |
9622 | "OSPF information\n" | |
9623 | "Show OSPF VRFs \n" | |
9624 | JSON_STR) | |
9625 | { | |
9f049418 | 9626 | bool uj = use_json(argc, argv); |
b5a8894d CS |
9627 | json_object *json = NULL; |
9628 | json_object *json_vrfs = NULL; | |
9629 | struct ospf *ospf = NULL; | |
9630 | struct listnode *node = NULL; | |
9631 | int count = 0; | |
9632 | static char header[] = "Name Id RouterId "; | |
9633 | ||
9634 | if (uj) { | |
9635 | json = json_object_new_object(); | |
9636 | json_vrfs = json_object_new_object(); | |
9637 | } | |
9638 | ||
9639 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
9640 | json_object *json_vrf = NULL; | |
9641 | const char *name = NULL; | |
fe3da9e7 | 9642 | int64_t vrf_id_ui = 0; |
b5a8894d CS |
9643 | |
9644 | count++; | |
9645 | ||
9646 | if (!uj && count == 1) | |
9647 | vty_out(vty, "%s\n", header); | |
9648 | if (uj) | |
9649 | json_vrf = json_object_new_object(); | |
9650 | ||
9651 | if (ospf->vrf_id == 0) | |
9652 | name = VRF_DEFAULT_NAME; | |
9653 | else | |
9654 | name = ospf->name; | |
9655 | ||
996c9314 LB |
9656 | vrf_id_ui = (ospf->vrf_id == VRF_UNKNOWN) |
9657 | ? -1 | |
9658 | : (int64_t)ospf->vrf_id; | |
b5a8894d CS |
9659 | |
9660 | if (uj) { | |
9661 | json_object_int_add(json_vrf, "vrfId", vrf_id_ui); | |
9662 | json_object_string_add(json_vrf, "routerId", | |
9663 | inet_ntoa(ospf->router_id)); | |
9664 | ||
9665 | json_object_object_add(json_vrfs, name, json_vrf); | |
9666 | ||
9667 | } else { | |
996c9314 LB |
9668 | vty_out(vty, "%-25s %-5d %-16s \n", name, |
9669 | ospf->vrf_id, inet_ntoa(ospf->router_id)); | |
b5a8894d CS |
9670 | } |
9671 | } | |
9672 | ||
9673 | if (uj) { | |
9674 | json_object_object_add(json, "vrfs", json_vrfs); | |
9675 | json_object_int_add(json, "totalVrfs", count); | |
9676 | ||
996c9314 LB |
9677 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
9678 | json, JSON_C_TO_STRING_PRETTY)); | |
b5a8894d CS |
9679 | json_object_free(json); |
9680 | } else { | |
9681 | if (count) | |
34d6798f | 9682 | vty_out(vty, "\nTotal number of OSPF VRFs: %d\n", |
b5a8894d CS |
9683 | count); |
9684 | } | |
9685 | ||
9686 | return CMD_SUCCESS; | |
9687 | } | |
9688 | ||
d62a17ae | 9689 | const char *ospf_abr_type_str[] = {"unknown", "standard", "ibm", "cisco", |
9690 | "shortcut"}; | |
718e3744 | 9691 | |
d62a17ae | 9692 | const char *ospf_shortcut_mode_str[] = {"default", "enable", "disable"}; |
718e3744 | 9693 | |
d62a17ae | 9694 | const char *ospf_int_type_str[] = {"unknown", /* should never be used. */ |
9695 | "point-to-point", "broadcast", | |
9696 | "non-broadcast", "point-to-multipoint", | |
9697 | "virtual-link", /* should never be used. */ | |
9698 | "loopback"}; | |
718e3744 | 9699 | |
545f0503 | 9700 | static int config_write_interface_one(struct vty *vty, struct vrf *vrf) |
d62a17ae | 9701 | { |
f4e14fdb | 9702 | struct listnode *node; |
d62a17ae | 9703 | struct interface *ifp; |
9704 | struct crypt_key *ck; | |
d62a17ae | 9705 | struct route_node *rn = NULL; |
9706 | struct ospf_if_params *params; | |
43b8d1d8 | 9707 | int write = 0; |
545f0503 | 9708 | struct ospf *ospf = vrf->info; |
d62a17ae | 9709 | |
545f0503 | 9710 | FOR_ALL_INTERFACES (vrf, ifp) { |
d62a17ae | 9711 | |
545f0503 CS |
9712 | if (memcmp(ifp->name, "VLINK", 5) == 0) |
9713 | continue; | |
35955c14 | 9714 | |
545f0503 | 9715 | vty_frame(vty, "!\n"); |
a36898e7 | 9716 | if (ifp->vrf_id == VRF_DEFAULT) |
545f0503 CS |
9717 | vty_frame(vty, "interface %s\n", ifp->name); |
9718 | else | |
996c9314 LB |
9719 | vty_frame(vty, "interface %s vrf %s\n", ifp->name, |
9720 | vrf->name); | |
545f0503 CS |
9721 | if (ifp->desc) |
9722 | vty_out(vty, " description %s\n", ifp->desc); | |
d62a17ae | 9723 | |
545f0503 | 9724 | write++; |
43b8d1d8 | 9725 | |
545f0503 | 9726 | params = IF_DEF_PARAMS(ifp); |
43b8d1d8 | 9727 | |
545f0503 CS |
9728 | do { |
9729 | /* Interface Network print. */ | |
9730 | if (OSPF_IF_PARAM_CONFIGURED(params, type) | |
9731 | && params->type != OSPF_IFTYPE_LOOPBACK) { | |
996c9314 | 9732 | if (params->type != ospf_default_iftype(ifp)) { |
545f0503 CS |
9733 | vty_out(vty, " ip ospf network %s", |
9734 | ospf_int_type_str | |
996c9314 | 9735 | [params->type]); |
e425c019 | 9736 | if (params != IF_DEF_PARAMS(ifp) && rn) |
545f0503 CS |
9737 | vty_out(vty, " %s", |
9738 | inet_ntoa( | |
996c9314 | 9739 | rn->p.u.prefix4)); |
545f0503 | 9740 | vty_out(vty, "\n"); |
d62a17ae | 9741 | } |
545f0503 | 9742 | } |
d62a17ae | 9743 | |
545f0503 CS |
9744 | /* OSPF interface authentication print */ |
9745 | if (OSPF_IF_PARAM_CONFIGURED(params, auth_type) | |
996c9314 | 9746 | && params->auth_type != OSPF_AUTH_NOTSET) { |
545f0503 | 9747 | const char *auth_str; |
d62a17ae | 9748 | |
545f0503 CS |
9749 | /* Translation tables are not that much help |
9750 | * here due to syntax | |
9751 | * of the simple option */ | |
9752 | switch (params->auth_type) { | |
d62a17ae | 9753 | |
545f0503 CS |
9754 | case OSPF_AUTH_NULL: |
9755 | auth_str = " null"; | |
9756 | break; | |
d62a17ae | 9757 | |
545f0503 CS |
9758 | case OSPF_AUTH_SIMPLE: |
9759 | auth_str = ""; | |
9760 | break; | |
b5a8894d | 9761 | |
545f0503 CS |
9762 | case OSPF_AUTH_CRYPTOGRAPHIC: |
9763 | auth_str = " message-digest"; | |
9764 | break; | |
d62a17ae | 9765 | |
545f0503 CS |
9766 | default: |
9767 | auth_str = ""; | |
9768 | break; | |
c7fd72d2 | 9769 | } |
d62a17ae | 9770 | |
545f0503 CS |
9771 | vty_out(vty, " ip ospf authentication%s", |
9772 | auth_str); | |
e425c019 | 9773 | if (params != IF_DEF_PARAMS(ifp) && rn) |
545f0503 | 9774 | vty_out(vty, " %s", |
c7fd72d2 | 9775 | inet_ntoa(rn->p.u.prefix4)); |
545f0503 CS |
9776 | vty_out(vty, "\n"); |
9777 | } | |
d62a17ae | 9778 | |
545f0503 CS |
9779 | /* Simple Authentication Password print. */ |
9780 | if (OSPF_IF_PARAM_CONFIGURED(params, auth_simple) | |
996c9314 | 9781 | && params->auth_simple[0] != '\0') { |
545f0503 CS |
9782 | vty_out(vty, " ip ospf authentication-key %s", |
9783 | params->auth_simple); | |
e425c019 | 9784 | if (params != IF_DEF_PARAMS(ifp) && rn) |
545f0503 CS |
9785 | vty_out(vty, " %s", |
9786 | inet_ntoa(rn->p.u.prefix4)); | |
9787 | vty_out(vty, "\n"); | |
9788 | } | |
c7fd72d2 | 9789 | |
545f0503 CS |
9790 | /* Cryptographic Authentication Key print. */ |
9791 | if (params && params->auth_crypt) { | |
996c9314 LB |
9792 | for (ALL_LIST_ELEMENTS_RO(params->auth_crypt, |
9793 | node, ck)) { | |
545f0503 CS |
9794 | vty_out(vty, |
9795 | " ip ospf message-digest-key %d md5 %s", | |
996c9314 | 9796 | ck->key_id, ck->auth_key); |
e425c019 | 9797 | if (params != IF_DEF_PARAMS(ifp) && rn) |
c7fd72d2 | 9798 | vty_out(vty, " %s", |
996c9314 LB |
9799 | inet_ntoa( |
9800 | rn->p.u.prefix4)); | |
c7fd72d2 CS |
9801 | vty_out(vty, "\n"); |
9802 | } | |
545f0503 | 9803 | } |
d62a17ae | 9804 | |
545f0503 | 9805 | /* Interface Output Cost print. */ |
996c9314 | 9806 | if (OSPF_IF_PARAM_CONFIGURED(params, output_cost_cmd)) { |
545f0503 CS |
9807 | vty_out(vty, " ip ospf cost %u", |
9808 | params->output_cost_cmd); | |
e425c019 | 9809 | if (params != IF_DEF_PARAMS(ifp) && rn) |
545f0503 | 9810 | vty_out(vty, " %s", |
43b8d1d8 | 9811 | inet_ntoa(rn->p.u.prefix4)); |
545f0503 CS |
9812 | vty_out(vty, "\n"); |
9813 | } | |
d62a17ae | 9814 | |
545f0503 CS |
9815 | /* Hello Interval print. */ |
9816 | if (OSPF_IF_PARAM_CONFIGURED(params, v_hello) | |
996c9314 | 9817 | && params->v_hello != OSPF_HELLO_INTERVAL_DEFAULT) { |
545f0503 CS |
9818 | vty_out(vty, " ip ospf hello-interval %u", |
9819 | params->v_hello); | |
e425c019 | 9820 | if (params != IF_DEF_PARAMS(ifp) && rn) |
545f0503 CS |
9821 | vty_out(vty, " %s", |
9822 | inet_ntoa(rn->p.u.prefix4)); | |
9823 | vty_out(vty, "\n"); | |
9824 | } | |
d62a17ae | 9825 | |
d62a17ae | 9826 | |
545f0503 CS |
9827 | /* Router Dead Interval print. */ |
9828 | if (OSPF_IF_PARAM_CONFIGURED(params, v_wait) | |
996c9314 LB |
9829 | && params->v_wait |
9830 | != OSPF_ROUTER_DEAD_INTERVAL_DEFAULT) { | |
545f0503 | 9831 | vty_out(vty, " ip ospf dead-interval "); |
d62a17ae | 9832 | |
545f0503 CS |
9833 | /* fast hello ? */ |
9834 | if (OSPF_IF_PARAM_CONFIGURED(params, | |
996c9314 | 9835 | fast_hello)) |
545f0503 CS |
9836 | vty_out(vty, |
9837 | "minimal hello-multiplier %d", | |
9838 | params->fast_hello); | |
9839 | else | |
996c9314 | 9840 | vty_out(vty, "%u", params->v_wait); |
d62a17ae | 9841 | |
e425c019 | 9842 | if (params != IF_DEF_PARAMS(ifp) && rn) |
545f0503 | 9843 | vty_out(vty, " %s", |
43b8d1d8 | 9844 | inet_ntoa(rn->p.u.prefix4)); |
545f0503 CS |
9845 | vty_out(vty, "\n"); |
9846 | } | |
d62a17ae | 9847 | |
545f0503 CS |
9848 | /* Router Priority print. */ |
9849 | if (OSPF_IF_PARAM_CONFIGURED(params, priority) | |
996c9314 LB |
9850 | && params->priority |
9851 | != OSPF_ROUTER_PRIORITY_DEFAULT) { | |
545f0503 CS |
9852 | vty_out(vty, " ip ospf priority %u", |
9853 | params->priority); | |
e425c019 | 9854 | if (params != IF_DEF_PARAMS(ifp) && rn) |
545f0503 | 9855 | vty_out(vty, " %s", |
43b8d1d8 | 9856 | inet_ntoa(rn->p.u.prefix4)); |
545f0503 CS |
9857 | vty_out(vty, "\n"); |
9858 | } | |
d62a17ae | 9859 | |
545f0503 CS |
9860 | /* Retransmit Interval print. */ |
9861 | if (OSPF_IF_PARAM_CONFIGURED(params, | |
996c9314 LB |
9862 | retransmit_interval) |
9863 | && params->retransmit_interval | |
9864 | != OSPF_RETRANSMIT_INTERVAL_DEFAULT) { | |
545f0503 CS |
9865 | vty_out(vty, " ip ospf retransmit-interval %u", |
9866 | params->retransmit_interval); | |
e425c019 | 9867 | if (params != IF_DEF_PARAMS(ifp) && rn) |
545f0503 | 9868 | vty_out(vty, " %s", |
43b8d1d8 | 9869 | inet_ntoa(rn->p.u.prefix4)); |
545f0503 CS |
9870 | vty_out(vty, "\n"); |
9871 | } | |
d62a17ae | 9872 | |
545f0503 | 9873 | /* Transmit Delay print. */ |
996c9314 LB |
9874 | if (OSPF_IF_PARAM_CONFIGURED(params, transmit_delay) |
9875 | && params->transmit_delay | |
9876 | != OSPF_TRANSMIT_DELAY_DEFAULT) { | |
545f0503 CS |
9877 | vty_out(vty, " ip ospf transmit-delay %u", |
9878 | params->transmit_delay); | |
e425c019 | 9879 | if (params != IF_DEF_PARAMS(ifp) && rn) |
545f0503 | 9880 | vty_out(vty, " %s", |
996c9314 | 9881 | inet_ntoa(rn->p.u.prefix4)); |
545f0503 CS |
9882 | vty_out(vty, "\n"); |
9883 | } | |
d62a17ae | 9884 | |
545f0503 CS |
9885 | /* Area print. */ |
9886 | if (OSPF_IF_PARAM_CONFIGURED(params, if_area)) { | |
9887 | if (ospf && ospf->instance) | |
9888 | vty_out(vty, " ip ospf %d", | |
9889 | ospf->instance); | |
9890 | else | |
9891 | vty_out(vty, " ip ospf"); | |
d62a17ae | 9892 | |
1f9d4e3d | 9893 | char buf[INET_ADDRSTRLEN]; |
d62a17ae | 9894 | |
996c9314 LB |
9895 | area_id2str(buf, sizeof(buf), ¶ms->if_area, |
9896 | params->if_area_id_fmt); | |
545f0503 | 9897 | vty_out(vty, " area %s", buf); |
e425c019 | 9898 | if (params != IF_DEF_PARAMS(ifp) && rn) |
545f0503 | 9899 | vty_out(vty, " %s", |
996c9314 | 9900 | inet_ntoa(rn->p.u.prefix4)); |
545f0503 CS |
9901 | vty_out(vty, "\n"); |
9902 | } | |
d62a17ae | 9903 | |
545f0503 | 9904 | /* bfd print. */ |
e89ffeee | 9905 | if (params && params->bfd_info) |
545f0503 | 9906 | ospf_bfd_write_config(vty, params); |
d62a17ae | 9907 | |
545f0503 CS |
9908 | /* MTU ignore print. */ |
9909 | if (OSPF_IF_PARAM_CONFIGURED(params, mtu_ignore) | |
996c9314 | 9910 | && params->mtu_ignore != OSPF_MTU_IGNORE_DEFAULT) { |
545f0503 CS |
9911 | if (params->mtu_ignore == 0) |
9912 | vty_out(vty, " no ip ospf mtu-ignore"); | |
9913 | else | |
9914 | vty_out(vty, " ip ospf mtu-ignore"); | |
e425c019 | 9915 | if (params != IF_DEF_PARAMS(ifp) && rn) |
545f0503 | 9916 | vty_out(vty, " %s", |
996c9314 | 9917 | inet_ntoa(rn->p.u.prefix4)); |
545f0503 CS |
9918 | vty_out(vty, "\n"); |
9919 | } | |
a8b828f3 | 9920 | |
d62a17ae | 9921 | |
545f0503 CS |
9922 | while (1) { |
9923 | if (rn == NULL) | |
996c9314 | 9924 | rn = route_top(IF_OIFS_PARAMS(ifp)); |
545f0503 CS |
9925 | else |
9926 | rn = route_next(rn); | |
43b8d1d8 | 9927 | |
545f0503 CS |
9928 | if (rn == NULL) |
9929 | break; | |
9930 | params = rn->info; | |
9931 | if (params != NULL) | |
9932 | break; | |
9933 | } | |
9934 | } while (rn); | |
43b8d1d8 | 9935 | |
545f0503 CS |
9936 | ospf_opaque_config_write_if(vty, ifp); |
9937 | ||
9938 | vty_endframe(vty, NULL); | |
b5a8894d | 9939 | } |
545f0503 | 9940 | |
d62a17ae | 9941 | return write; |
718e3744 | 9942 | } |
9943 | ||
43b8d1d8 CS |
9944 | /* Configuration write function for ospfd. */ |
9945 | static int config_write_interface(struct vty *vty) | |
9946 | { | |
9947 | int write = 0; | |
545f0503 | 9948 | struct vrf *vrf = NULL; |
43b8d1d8 | 9949 | |
545f0503 CS |
9950 | /* Display all VRF aware OSPF interface configuration */ |
9951 | RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) { | |
9952 | write += config_write_interface_one(vty, vrf); | |
9953 | } | |
43b8d1d8 CS |
9954 | |
9955 | return write; | |
9956 | } | |
9957 | ||
d62a17ae | 9958 | static int config_write_network_area(struct vty *vty, struct ospf *ospf) |
718e3744 | 9959 | { |
d62a17ae | 9960 | struct route_node *rn; |
d7c0a89a | 9961 | uint8_t buf[INET_ADDRSTRLEN]; |
718e3744 | 9962 | |
d62a17ae | 9963 | /* `network area' print. */ |
9964 | for (rn = route_top(ospf->networks); rn; rn = route_next(rn)) | |
9965 | if (rn->info) { | |
9966 | struct ospf_network *n = rn->info; | |
718e3744 | 9967 | |
d62a17ae | 9968 | /* Create Area ID string by specified Area ID format. */ |
9969 | if (n->area_id_fmt == OSPF_AREA_ID_FMT_DOTTEDQUAD) | |
1f9d4e3d | 9970 | inet_ntop(AF_INET, &n->area_id, (char *)buf, |
9971 | sizeof(buf)); | |
d62a17ae | 9972 | else |
9973 | sprintf((char *)buf, "%lu", | |
9974 | (unsigned long int)ntohl( | |
9975 | n->area_id.s_addr)); | |
718e3744 | 9976 | |
d62a17ae | 9977 | /* Network print. */ |
9978 | vty_out(vty, " network %s/%d area %s\n", | |
9979 | inet_ntoa(rn->p.u.prefix4), rn->p.prefixlen, | |
9980 | buf); | |
9981 | } | |
718e3744 | 9982 | |
d62a17ae | 9983 | return 0; |
718e3744 | 9984 | } |
9985 | ||
d62a17ae | 9986 | static int config_write_ospf_area(struct vty *vty, struct ospf *ospf) |
718e3744 | 9987 | { |
d62a17ae | 9988 | struct listnode *node; |
9989 | struct ospf_area *area; | |
d7c0a89a | 9990 | uint8_t buf[INET_ADDRSTRLEN]; |
718e3744 | 9991 | |
d62a17ae | 9992 | /* Area configuration print. */ |
9993 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) { | |
9994 | struct route_node *rn1; | |
718e3744 | 9995 | |
1f9d4e3d | 9996 | area_id2str((char *)buf, sizeof(buf), &area->area_id, |
d62a17ae | 9997 | area->area_id_fmt); |
718e3744 | 9998 | |
d62a17ae | 9999 | if (area->auth_type != OSPF_AUTH_NULL) { |
10000 | if (area->auth_type == OSPF_AUTH_SIMPLE) | |
10001 | vty_out(vty, " area %s authentication\n", buf); | |
10002 | else | |
10003 | vty_out(vty, | |
10004 | " area %s authentication message-digest\n", | |
10005 | buf); | |
10006 | } | |
718e3744 | 10007 | |
d62a17ae | 10008 | if (area->shortcut_configured != OSPF_SHORTCUT_DEFAULT) |
10009 | vty_out(vty, " area %s shortcut %s\n", buf, | |
10010 | ospf_shortcut_mode_str | |
10011 | [area->shortcut_configured]); | |
10012 | ||
10013 | if ((area->external_routing == OSPF_AREA_STUB) | |
10014 | || (area->external_routing == OSPF_AREA_NSSA)) { | |
7ef56a73 | 10015 | if (area->external_routing == OSPF_AREA_STUB) { |
d62a17ae | 10016 | vty_out(vty, " area %s stub", buf); |
7ef56a73 CS |
10017 | if (area->no_summary) |
10018 | vty_out(vty, " no-summary\n"); | |
10019 | vty_out(vty, "\n"); | |
10020 | } else if (area->external_routing == OSPF_AREA_NSSA) { | |
d62a17ae | 10021 | switch (area->NSSATranslatorRole) { |
10022 | case OSPF_NSSA_ROLE_NEVER: | |
7ef56a73 CS |
10023 | vty_out(vty, |
10024 | " area %s nssa translate-never\n", | |
10025 | buf); | |
d62a17ae | 10026 | break; |
10027 | case OSPF_NSSA_ROLE_ALWAYS: | |
7ef56a73 CS |
10028 | vty_out(vty, |
10029 | " area %s nssa translate-always\n", | |
10030 | buf); | |
d62a17ae | 10031 | break; |
2643b2bc CS |
10032 | case OSPF_NSSA_ROLE_CANDIDATE: |
10033 | vty_out(vty, " area %s nssa \n", buf); | |
10034 | break; | |
d62a17ae | 10035 | } |
7ef56a73 CS |
10036 | if (area->no_summary) |
10037 | vty_out(vty, | |
10038 | " area %s nssa no-summary\n", | |
10039 | buf); | |
d62a17ae | 10040 | } |
718e3744 | 10041 | |
d62a17ae | 10042 | if (area->default_cost != 1) |
10043 | vty_out(vty, " area %s default-cost %d\n", buf, | |
10044 | area->default_cost); | |
10045 | } | |
718e3744 | 10046 | |
d62a17ae | 10047 | for (rn1 = route_top(area->ranges); rn1; rn1 = route_next(rn1)) |
10048 | if (rn1->info) { | |
10049 | struct ospf_area_range *range = rn1->info; | |
718e3744 | 10050 | |
d62a17ae | 10051 | vty_out(vty, " area %s range %s/%d", buf, |
10052 | inet_ntoa(rn1->p.u.prefix4), | |
10053 | rn1->p.prefixlen); | |
718e3744 | 10054 | |
d62a17ae | 10055 | if (range->cost_config |
10056 | != OSPF_AREA_RANGE_COST_UNSPEC) | |
10057 | vty_out(vty, " cost %d", | |
10058 | range->cost_config); | |
718e3744 | 10059 | |
d62a17ae | 10060 | if (!CHECK_FLAG(range->flags, |
10061 | OSPF_AREA_RANGE_ADVERTISE)) | |
10062 | vty_out(vty, " not-advertise"); | |
718e3744 | 10063 | |
d62a17ae | 10064 | if (CHECK_FLAG(range->flags, |
10065 | OSPF_AREA_RANGE_SUBSTITUTE)) | |
10066 | vty_out(vty, " substitute %s/%d", | |
10067 | inet_ntoa(range->subst_addr), | |
10068 | range->subst_masklen); | |
10069 | ||
10070 | vty_out(vty, "\n"); | |
10071 | } | |
10072 | ||
10073 | if (EXPORT_NAME(area)) | |
10074 | vty_out(vty, " area %s export-list %s\n", buf, | |
10075 | EXPORT_NAME(area)); | |
10076 | ||
10077 | if (IMPORT_NAME(area)) | |
10078 | vty_out(vty, " area %s import-list %s\n", buf, | |
10079 | IMPORT_NAME(area)); | |
10080 | ||
10081 | if (PREFIX_NAME_IN(area)) | |
10082 | vty_out(vty, " area %s filter-list prefix %s in\n", buf, | |
10083 | PREFIX_NAME_IN(area)); | |
10084 | ||
10085 | if (PREFIX_NAME_OUT(area)) | |
10086 | vty_out(vty, " area %s filter-list prefix %s out\n", | |
10087 | buf, PREFIX_NAME_OUT(area)); | |
10088 | } | |
10089 | ||
10090 | return 0; | |
718e3744 | 10091 | } |
10092 | ||
d62a17ae | 10093 | static int config_write_ospf_nbr_nbma(struct vty *vty, struct ospf *ospf) |
718e3744 | 10094 | { |
d62a17ae | 10095 | struct ospf_nbr_nbma *nbr_nbma; |
10096 | struct route_node *rn; | |
718e3744 | 10097 | |
d62a17ae | 10098 | /* Static Neighbor configuration print. */ |
10099 | for (rn = route_top(ospf->nbr_nbma); rn; rn = route_next(rn)) | |
10100 | if ((nbr_nbma = rn->info)) { | |
10101 | vty_out(vty, " neighbor %s", inet_ntoa(nbr_nbma->addr)); | |
718e3744 | 10102 | |
d62a17ae | 10103 | if (nbr_nbma->priority |
10104 | != OSPF_NEIGHBOR_PRIORITY_DEFAULT) | |
10105 | vty_out(vty, " priority %d", | |
10106 | nbr_nbma->priority); | |
718e3744 | 10107 | |
d62a17ae | 10108 | if (nbr_nbma->v_poll != OSPF_POLL_INTERVAL_DEFAULT) |
10109 | vty_out(vty, " poll-interval %d", | |
10110 | nbr_nbma->v_poll); | |
10111 | ||
10112 | vty_out(vty, "\n"); | |
10113 | } | |
10114 | ||
10115 | return 0; | |
10116 | } | |
10117 | ||
10118 | static int config_write_virtual_link(struct vty *vty, struct ospf *ospf) | |
10119 | { | |
10120 | struct listnode *node; | |
10121 | struct ospf_vl_data *vl_data; | |
10122 | char buf[INET_ADDRSTRLEN]; | |
10123 | ||
10124 | /* Virtual-Link print */ | |
10125 | for (ALL_LIST_ELEMENTS_RO(ospf->vlinks, node, vl_data)) { | |
10126 | struct listnode *n2; | |
10127 | struct crypt_key *ck; | |
10128 | struct ospf_interface *oi; | |
10129 | ||
10130 | if (vl_data != NULL) { | |
d62a17ae | 10131 | area_id2str(buf, sizeof(buf), &vl_data->vl_area_id, |
10132 | vl_data->vl_area_id_fmt); | |
10133 | oi = vl_data->vl_oi; | |
10134 | ||
10135 | /* timers */ | |
10136 | if (OSPF_IF_PARAM(oi, v_hello) | |
10137 | != OSPF_HELLO_INTERVAL_DEFAULT | |
10138 | || OSPF_IF_PARAM(oi, v_wait) | |
10139 | != OSPF_ROUTER_DEAD_INTERVAL_DEFAULT | |
10140 | || OSPF_IF_PARAM(oi, retransmit_interval) | |
10141 | != OSPF_RETRANSMIT_INTERVAL_DEFAULT | |
10142 | || OSPF_IF_PARAM(oi, transmit_delay) | |
10143 | != OSPF_TRANSMIT_DELAY_DEFAULT) | |
10144 | vty_out(vty, | |
10145 | " area %s virtual-link %s hello-interval %d retransmit-interval %d transmit-delay %d dead-interval %d\n", | |
10146 | buf, inet_ntoa(vl_data->vl_peer), | |
10147 | OSPF_IF_PARAM(oi, v_hello), | |
10148 | OSPF_IF_PARAM(oi, retransmit_interval), | |
10149 | OSPF_IF_PARAM(oi, transmit_delay), | |
10150 | OSPF_IF_PARAM(oi, v_wait)); | |
10151 | else | |
10152 | vty_out(vty, " area %s virtual-link %s\n", buf, | |
10153 | inet_ntoa(vl_data->vl_peer)); | |
10154 | /* Auth key */ | |
10155 | if (IF_DEF_PARAMS(vl_data->vl_oi->ifp)->auth_simple[0] | |
10156 | != '\0') | |
10157 | vty_out(vty, | |
10158 | " area %s virtual-link %s authentication-key %s\n", | |
10159 | buf, inet_ntoa(vl_data->vl_peer), | |
10160 | IF_DEF_PARAMS(vl_data->vl_oi->ifp) | |
10161 | ->auth_simple); | |
10162 | /* md5 keys */ | |
10163 | for (ALL_LIST_ELEMENTS_RO( | |
10164 | IF_DEF_PARAMS(vl_data->vl_oi->ifp) | |
10165 | ->auth_crypt, | |
10166 | n2, ck)) | |
10167 | vty_out(vty, | |
10168 | " area %s virtual-link %s" | |
10169 | " message-digest-key %d md5 %s\n", | |
10170 | buf, inet_ntoa(vl_data->vl_peer), | |
10171 | ck->key_id, ck->auth_key); | |
10172 | } | |
10173 | } | |
10174 | ||
10175 | return 0; | |
718e3744 | 10176 | } |
10177 | ||
6b0655a2 | 10178 | |
d62a17ae | 10179 | static int config_write_ospf_redistribute(struct vty *vty, struct ospf *ospf) |
718e3744 | 10180 | { |
d62a17ae | 10181 | int type; |
718e3744 | 10182 | |
d62a17ae | 10183 | /* redistribute print. */ |
10184 | for (type = 0; type < ZEBRA_ROUTE_MAX; type++) { | |
10185 | struct list *red_list; | |
10186 | struct listnode *node; | |
10187 | struct ospf_redist *red; | |
718e3744 | 10188 | |
d62a17ae | 10189 | red_list = ospf->redist[type]; |
10190 | if (!red_list) | |
10191 | continue; | |
7c8ff89e | 10192 | |
d62a17ae | 10193 | for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) { |
10194 | vty_out(vty, " redistribute %s", | |
10195 | zebra_route_string(type)); | |
10196 | if (red->instance) | |
10197 | vty_out(vty, " %d", red->instance); | |
7c8ff89e | 10198 | |
d62a17ae | 10199 | if (red->dmetric.value >= 0) |
10200 | vty_out(vty, " metric %d", red->dmetric.value); | |
7c8ff89e | 10201 | |
d62a17ae | 10202 | if (red->dmetric.type == EXTERNAL_METRIC_TYPE_1) |
10203 | vty_out(vty, " metric-type 1"); | |
7c8ff89e | 10204 | |
d62a17ae | 10205 | if (ROUTEMAP_NAME(red)) |
10206 | vty_out(vty, " route-map %s", | |
10207 | ROUTEMAP_NAME(red)); | |
7c8ff89e | 10208 | |
d62a17ae | 10209 | vty_out(vty, "\n"); |
10210 | } | |
10211 | } | |
718e3744 | 10212 | |
d62a17ae | 10213 | return 0; |
718e3744 | 10214 | } |
10215 | ||
d62a17ae | 10216 | static int config_write_ospf_default_metric(struct vty *vty, struct ospf *ospf) |
718e3744 | 10217 | { |
d62a17ae | 10218 | if (ospf->default_metric != -1) |
10219 | vty_out(vty, " default-metric %d\n", ospf->default_metric); | |
10220 | return 0; | |
718e3744 | 10221 | } |
10222 | ||
d62a17ae | 10223 | static int config_write_ospf_distribute(struct vty *vty, struct ospf *ospf) |
10224 | { | |
10225 | int type; | |
10226 | struct ospf_redist *red; | |
718e3744 | 10227 | |
d62a17ae | 10228 | if (ospf) { |
10229 | /* distribute-list print. */ | |
10230 | for (type = 0; type < ZEBRA_ROUTE_MAX; type++) | |
10231 | if (DISTRIBUTE_NAME(ospf, type)) | |
10232 | vty_out(vty, " distribute-list %s out %s\n", | |
10233 | DISTRIBUTE_NAME(ospf, type), | |
10234 | zebra_route_string(type)); | |
7c8ff89e | 10235 | |
d62a17ae | 10236 | /* default-information print. */ |
10237 | if (ospf->default_originate != DEFAULT_ORIGINATE_NONE) { | |
10238 | vty_out(vty, " default-information originate"); | |
10239 | if (ospf->default_originate == DEFAULT_ORIGINATE_ALWAYS) | |
10240 | vty_out(vty, " always"); | |
718e3744 | 10241 | |
d62a17ae | 10242 | red = ospf_redist_lookup(ospf, DEFAULT_ROUTE, 0); |
10243 | if (red) { | |
10244 | if (red->dmetric.value >= 0) | |
10245 | vty_out(vty, " metric %d", | |
10246 | red->dmetric.value); | |
951da435 | 10247 | |
d62a17ae | 10248 | if (red->dmetric.type == EXTERNAL_METRIC_TYPE_1) |
10249 | vty_out(vty, " metric-type 1"); | |
718e3744 | 10250 | |
d62a17ae | 10251 | if (ROUTEMAP_NAME(red)) |
10252 | vty_out(vty, " route-map %s", | |
10253 | ROUTEMAP_NAME(red)); | |
10254 | } | |
10255 | ||
10256 | vty_out(vty, "\n"); | |
10257 | } | |
10258 | } | |
10259 | ||
10260 | return 0; | |
718e3744 | 10261 | } |
10262 | ||
d62a17ae | 10263 | static int config_write_ospf_distance(struct vty *vty, struct ospf *ospf) |
10264 | { | |
10265 | struct route_node *rn; | |
10266 | struct ospf_distance *odistance; | |
10267 | ||
10268 | if (ospf->distance_all) | |
10269 | vty_out(vty, " distance %d\n", ospf->distance_all); | |
10270 | ||
10271 | if (ospf->distance_intra || ospf->distance_inter | |
10272 | || ospf->distance_external) { | |
10273 | vty_out(vty, " distance ospf"); | |
10274 | ||
10275 | if (ospf->distance_intra) | |
10276 | vty_out(vty, " intra-area %d", ospf->distance_intra); | |
10277 | if (ospf->distance_inter) | |
10278 | vty_out(vty, " inter-area %d", ospf->distance_inter); | |
10279 | if (ospf->distance_external) | |
10280 | vty_out(vty, " external %d", ospf->distance_external); | |
10281 | ||
10282 | vty_out(vty, "\n"); | |
10283 | } | |
10284 | ||
10285 | for (rn = route_top(ospf->distance_table); rn; rn = route_next(rn)) | |
10286 | if ((odistance = rn->info) != NULL) { | |
10287 | vty_out(vty, " distance %d %s/%d %s\n", | |
10288 | odistance->distance, inet_ntoa(rn->p.u.prefix4), | |
10289 | rn->p.prefixlen, | |
10290 | odistance->access_list ? odistance->access_list | |
10291 | : ""); | |
10292 | } | |
10293 | return 0; | |
718e3744 | 10294 | } |
10295 | ||
43b8d1d8 | 10296 | static int ospf_config_write_one(struct vty *vty, struct ospf *ospf) |
d62a17ae | 10297 | { |
f4e14fdb | 10298 | struct vrf *vrf = vrf_lookup_by_id(ospf->vrf_id); |
d62a17ae | 10299 | struct interface *ifp; |
10300 | struct ospf_interface *oi; | |
43b8d1d8 | 10301 | struct listnode *node = NULL; |
d62a17ae | 10302 | int write = 0; |
10303 | ||
43b8d1d8 CS |
10304 | /* `router ospf' print. */ |
10305 | if (ospf->instance && ospf->name) { | |
996c9314 LB |
10306 | vty_out(vty, "router ospf %d vrf %s\n", ospf->instance, |
10307 | ospf->name); | |
43b8d1d8 | 10308 | } else if (ospf->instance) { |
996c9314 | 10309 | vty_out(vty, "router ospf %d\n", ospf->instance); |
43b8d1d8 | 10310 | } else if (ospf->name) { |
996c9314 | 10311 | vty_out(vty, "router ospf vrf %s\n", ospf->name); |
43b8d1d8 CS |
10312 | } else |
10313 | vty_out(vty, "router ospf\n"); | |
10314 | ||
10315 | if (!ospf->networks) { | |
10316 | write++; | |
b5a8894d | 10317 | return write; |
43b8d1d8 | 10318 | } |
d62a17ae | 10319 | |
43b8d1d8 CS |
10320 | /* Router ID print. */ |
10321 | if (ospf->router_id_static.s_addr != 0) | |
10322 | vty_out(vty, " ospf router-id %s\n", | |
10323 | inet_ntoa(ospf->router_id_static)); | |
d62a17ae | 10324 | |
43b8d1d8 CS |
10325 | /* ABR type print. */ |
10326 | if (ospf->abr_type != OSPF_ABR_DEFAULT) | |
10327 | vty_out(vty, " ospf abr-type %s\n", | |
10328 | ospf_abr_type_str[ospf->abr_type]); | |
b5a8894d | 10329 | |
43b8d1d8 CS |
10330 | /* log-adjacency-changes flag print. */ |
10331 | if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES)) { | |
10332 | if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL)) | |
10333 | vty_out(vty, " log-adjacency-changes detail\n"); | |
10334 | else if (!DFLT_OSPF_LOG_ADJACENCY_CHANGES) | |
10335 | vty_out(vty, " log-adjacency-changes\n"); | |
10336 | } else if (DFLT_OSPF_LOG_ADJACENCY_CHANGES) { | |
10337 | vty_out(vty, " no log-adjacency-changes\n"); | |
10338 | } | |
b5a8894d | 10339 | |
43b8d1d8 CS |
10340 | /* RFC1583 compatibility flag print -- Compatible with CISCO |
10341 | * 12.1. */ | |
10342 | if (CHECK_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE)) | |
10343 | vty_out(vty, " compatible rfc1583\n"); | |
d62a17ae | 10344 | |
43b8d1d8 CS |
10345 | /* auto-cost reference-bandwidth configuration. */ |
10346 | if (ospf->ref_bandwidth != OSPF_DEFAULT_REF_BANDWIDTH) { | |
10347 | vty_out(vty, | |
10348 | "! Important: ensure reference bandwidth " | |
10349 | "is consistent across all routers\n"); | |
10350 | vty_out(vty, " auto-cost reference-bandwidth %d\n", | |
10351 | ospf->ref_bandwidth); | |
10352 | } | |
d62a17ae | 10353 | |
43b8d1d8 CS |
10354 | /* SPF timers print. */ |
10355 | if (ospf->spf_delay != OSPF_SPF_DELAY_DEFAULT | |
10356 | || ospf->spf_holdtime != OSPF_SPF_HOLDTIME_DEFAULT | |
10357 | || ospf->spf_max_holdtime != OSPF_SPF_MAX_HOLDTIME_DEFAULT) | |
996c9314 LB |
10358 | vty_out(vty, " timers throttle spf %d %d %d\n", ospf->spf_delay, |
10359 | ospf->spf_holdtime, ospf->spf_max_holdtime); | |
43b8d1d8 CS |
10360 | |
10361 | /* LSA timers print. */ | |
10362 | if (ospf->min_ls_interval != OSPF_MIN_LS_INTERVAL) | |
10363 | vty_out(vty, " timers throttle lsa all %d\n", | |
10364 | ospf->min_ls_interval); | |
10365 | if (ospf->min_ls_arrival != OSPF_MIN_LS_ARRIVAL) | |
10366 | vty_out(vty, " timers lsa min-arrival %d\n", | |
10367 | ospf->min_ls_arrival); | |
10368 | ||
10369 | /* Write multiplier print. */ | |
10370 | if (ospf->write_oi_count != OSPF_WRITE_INTERFACE_COUNT_DEFAULT) | |
10371 | vty_out(vty, " ospf write-multiplier %d\n", | |
10372 | ospf->write_oi_count); | |
d62a17ae | 10373 | |
43b8d1d8 CS |
10374 | /* Max-metric router-lsa print */ |
10375 | config_write_stub_router(vty, ospf); | |
d62a17ae | 10376 | |
43b8d1d8 | 10377 | /* SPF refresh parameters print. */ |
996c9314 LB |
10378 | if (ospf->lsa_refresh_interval != OSPF_LSA_REFRESH_INTERVAL_DEFAULT) |
10379 | vty_out(vty, " refresh timer %d\n", ospf->lsa_refresh_interval); | |
d62a17ae | 10380 | |
43b8d1d8 CS |
10381 | /* Redistribute information print. */ |
10382 | config_write_ospf_redistribute(vty, ospf); | |
d62a17ae | 10383 | |
43b8d1d8 CS |
10384 | /* passive-interface print. */ |
10385 | if (ospf->passive_interface_default == OSPF_IF_PASSIVE) | |
10386 | vty_out(vty, " passive-interface default\n"); | |
d62a17ae | 10387 | |
451fda4f | 10388 | FOR_ALL_INTERFACES (vrf, ifp) |
43b8d1d8 CS |
10389 | if (OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(ifp), |
10390 | passive_interface) | |
10391 | && IF_DEF_PARAMS(ifp)->passive_interface | |
996c9314 | 10392 | != ospf->passive_interface_default) { |
43b8d1d8 | 10393 | vty_out(vty, " %spassive-interface %s\n", |
996c9314 LB |
10394 | IF_DEF_PARAMS(ifp)->passive_interface ? "" |
10395 | : "no ", | |
43b8d1d8 CS |
10396 | ifp->name); |
10397 | } | |
10398 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) { | |
996c9314 | 10399 | if (!OSPF_IF_PARAM_CONFIGURED(oi->params, passive_interface)) |
43b8d1d8 CS |
10400 | continue; |
10401 | if (OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(oi->ifp), | |
10402 | passive_interface)) { | |
10403 | if (oi->params->passive_interface | |
996c9314 | 10404 | == IF_DEF_PARAMS(oi->ifp)->passive_interface) |
43b8d1d8 CS |
10405 | continue; |
10406 | } else if (oi->params->passive_interface | |
10407 | == ospf->passive_interface_default) | |
10408 | continue; | |
d62a17ae | 10409 | |
43b8d1d8 CS |
10410 | vty_out(vty, " %spassive-interface %s %s\n", |
10411 | oi->params->passive_interface ? "" : "no ", | |
996c9314 | 10412 | oi->ifp->name, inet_ntoa(oi->address->u.prefix4)); |
43b8d1d8 | 10413 | } |
d62a17ae | 10414 | |
43b8d1d8 CS |
10415 | /* Network area print. */ |
10416 | config_write_network_area(vty, ospf); | |
d62a17ae | 10417 | |
43b8d1d8 CS |
10418 | /* Area config print. */ |
10419 | config_write_ospf_area(vty, ospf); | |
d62a17ae | 10420 | |
43b8d1d8 CS |
10421 | /* static neighbor print. */ |
10422 | config_write_ospf_nbr_nbma(vty, ospf); | |
10423 | ||
10424 | /* Virtual-Link print. */ | |
10425 | config_write_virtual_link(vty, ospf); | |
10426 | ||
10427 | /* Default metric configuration. */ | |
10428 | config_write_ospf_default_metric(vty, ospf); | |
10429 | ||
10430 | /* Distribute-list and default-information print. */ | |
10431 | config_write_ospf_distribute(vty, ospf); | |
10432 | ||
10433 | /* Distance configuration. */ | |
10434 | config_write_ospf_distance(vty, ospf); | |
10435 | ||
10436 | ospf_opaque_config_write_router(vty, ospf); | |
10437 | ||
10438 | write++; | |
10439 | return write; | |
10440 | } | |
10441 | ||
10442 | /* OSPF configuration write function. */ | |
10443 | static int ospf_config_write(struct vty *vty) | |
10444 | { | |
10445 | struct ospf *ospf; | |
10446 | struct listnode *ospf_node = NULL; | |
10447 | int write = 0; | |
10448 | ||
10449 | if (listcount(om->ospf) == 0) | |
10450 | return write; | |
10451 | ||
10452 | for (ALL_LIST_ELEMENTS_RO(om->ospf, ospf_node, ospf)) { | |
88d77109 CS |
10453 | /* VRF Default check if it is running. |
10454 | * Upon daemon start, there could be default instance | |
10455 | * in absence of 'router ospf'/oi_running is disabled. */ | |
10456 | if (ospf->vrf_id == VRF_DEFAULT && ospf->oi_running) | |
10457 | write += ospf_config_write_one(vty, ospf); | |
10458 | /* For Non-Default VRF simply display the configuration, | |
10459 | * even if it is not oi_running. */ | |
10460 | else if (ospf->vrf_id != VRF_DEFAULT) | |
43b8d1d8 | 10461 | write += ospf_config_write_one(vty, ospf); |
b5a8894d | 10462 | } |
d62a17ae | 10463 | return write; |
10464 | } | |
10465 | ||
10466 | void ospf_vty_show_init(void) | |
10467 | { | |
10468 | /* "show ip ospf" commands. */ | |
10469 | install_element(VIEW_NODE, &show_ip_ospf_cmd); | |
10470 | ||
10471 | install_element(VIEW_NODE, &show_ip_ospf_instance_cmd); | |
10472 | ||
10473 | /* "show ip ospf database" commands. */ | |
10474 | install_element(VIEW_NODE, &show_ip_ospf_database_max_cmd); | |
10475 | ||
10476 | install_element(VIEW_NODE, | |
10477 | &show_ip_ospf_instance_database_type_adv_router_cmd); | |
10478 | install_element(VIEW_NODE, &show_ip_ospf_instance_database_cmd); | |
10479 | install_element(VIEW_NODE, &show_ip_ospf_instance_database_max_cmd); | |
10480 | ||
10481 | /* "show ip ospf interface" commands. */ | |
10482 | install_element(VIEW_NODE, &show_ip_ospf_interface_cmd); | |
10483 | ||
10484 | install_element(VIEW_NODE, &show_ip_ospf_instance_interface_cmd); | |
c9339663 CS |
10485 | /* "show ip ospf interface traffic */ |
10486 | install_element(VIEW_NODE, &show_ip_ospf_interface_traffic_cmd); | |
d62a17ae | 10487 | |
10488 | /* "show ip ospf neighbor" commands. */ | |
10489 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_int_detail_cmd); | |
10490 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_int_cmd); | |
10491 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_id_cmd); | |
10492 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_detail_all_cmd); | |
10493 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_detail_cmd); | |
10494 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_cmd); | |
10495 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_all_cmd); | |
10496 | ||
10497 | install_element(VIEW_NODE, | |
10498 | &show_ip_ospf_instance_neighbor_int_detail_cmd); | |
10499 | install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_int_cmd); | |
10500 | install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_id_cmd); | |
10501 | install_element(VIEW_NODE, | |
10502 | &show_ip_ospf_instance_neighbor_detail_all_cmd); | |
10503 | install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_detail_cmd); | |
10504 | install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_cmd); | |
10505 | install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_all_cmd); | |
10506 | ||
10507 | /* "show ip ospf route" commands. */ | |
10508 | install_element(VIEW_NODE, &show_ip_ospf_route_cmd); | |
10509 | install_element(VIEW_NODE, &show_ip_ospf_border_routers_cmd); | |
10510 | ||
10511 | install_element(VIEW_NODE, &show_ip_ospf_instance_route_cmd); | |
10512 | install_element(VIEW_NODE, &show_ip_ospf_instance_border_routers_cmd); | |
b5a8894d CS |
10513 | |
10514 | /* "show ip ospf vrfs" commands. */ | |
10515 | install_element(VIEW_NODE, &show_ip_ospf_vrfs_cmd); | |
718e3744 | 10516 | } |
10517 | ||
6b0655a2 | 10518 | |
718e3744 | 10519 | /* ospfd's interface node. */ |
d62a17ae | 10520 | static struct cmd_node interface_node = {INTERFACE_NODE, "%s(config-if)# ", 1}; |
718e3744 | 10521 | |
10522 | /* Initialization of OSPF interface. */ | |
d62a17ae | 10523 | static void ospf_vty_if_init(void) |
10524 | { | |
10525 | /* Install interface node. */ | |
10526 | install_node(&interface_node, config_write_interface); | |
10527 | if_cmd_init(); | |
10528 | ||
10529 | /* "ip ospf authentication" commands. */ | |
10530 | install_element(INTERFACE_NODE, &ip_ospf_authentication_args_addr_cmd); | |
10531 | install_element(INTERFACE_NODE, &ip_ospf_authentication_addr_cmd); | |
10532 | install_element(INTERFACE_NODE, | |
10533 | &no_ip_ospf_authentication_args_addr_cmd); | |
10534 | install_element(INTERFACE_NODE, &no_ip_ospf_authentication_addr_cmd); | |
10535 | install_element(INTERFACE_NODE, &ip_ospf_authentication_key_addr_cmd); | |
10536 | install_element(INTERFACE_NODE, | |
10537 | &no_ip_ospf_authentication_key_authkey_addr_cmd); | |
10538 | install_element(INTERFACE_NODE, | |
10539 | &no_ospf_authentication_key_authkey_addr_cmd); | |
10540 | ||
10541 | /* "ip ospf message-digest-key" commands. */ | |
10542 | install_element(INTERFACE_NODE, &ip_ospf_message_digest_key_cmd); | |
10543 | install_element(INTERFACE_NODE, &no_ip_ospf_message_digest_key_cmd); | |
10544 | ||
10545 | /* "ip ospf cost" commands. */ | |
10546 | install_element(INTERFACE_NODE, &ip_ospf_cost_cmd); | |
10547 | install_element(INTERFACE_NODE, &no_ip_ospf_cost_cmd); | |
10548 | ||
10549 | /* "ip ospf mtu-ignore" commands. */ | |
10550 | install_element(INTERFACE_NODE, &ip_ospf_mtu_ignore_addr_cmd); | |
10551 | install_element(INTERFACE_NODE, &no_ip_ospf_mtu_ignore_addr_cmd); | |
10552 | ||
10553 | /* "ip ospf dead-interval" commands. */ | |
10554 | install_element(INTERFACE_NODE, &ip_ospf_dead_interval_cmd); | |
10555 | install_element(INTERFACE_NODE, | |
10556 | &ip_ospf_dead_interval_minimal_addr_cmd); | |
10557 | install_element(INTERFACE_NODE, &no_ip_ospf_dead_interval_cmd); | |
10558 | ||
10559 | /* "ip ospf hello-interval" commands. */ | |
10560 | install_element(INTERFACE_NODE, &ip_ospf_hello_interval_cmd); | |
10561 | install_element(INTERFACE_NODE, &no_ip_ospf_hello_interval_cmd); | |
10562 | ||
10563 | /* "ip ospf network" commands. */ | |
10564 | install_element(INTERFACE_NODE, &ip_ospf_network_cmd); | |
10565 | install_element(INTERFACE_NODE, &no_ip_ospf_network_cmd); | |
10566 | ||
10567 | /* "ip ospf priority" commands. */ | |
10568 | install_element(INTERFACE_NODE, &ip_ospf_priority_cmd); | |
10569 | install_element(INTERFACE_NODE, &no_ip_ospf_priority_cmd); | |
10570 | ||
10571 | /* "ip ospf retransmit-interval" commands. */ | |
10572 | install_element(INTERFACE_NODE, &ip_ospf_retransmit_interval_addr_cmd); | |
10573 | install_element(INTERFACE_NODE, | |
10574 | &no_ip_ospf_retransmit_interval_addr_cmd); | |
10575 | ||
10576 | /* "ip ospf transmit-delay" commands. */ | |
10577 | install_element(INTERFACE_NODE, &ip_ospf_transmit_delay_addr_cmd); | |
10578 | install_element(INTERFACE_NODE, &no_ip_ospf_transmit_delay_addr_cmd); | |
10579 | ||
10580 | /* "ip ospf area" commands. */ | |
10581 | install_element(INTERFACE_NODE, &ip_ospf_area_cmd); | |
10582 | install_element(INTERFACE_NODE, &no_ip_ospf_area_cmd); | |
10583 | ||
10584 | /* These commands are compatibitliy for previous version. */ | |
10585 | install_element(INTERFACE_NODE, &ospf_authentication_key_cmd); | |
10586 | install_element(INTERFACE_NODE, &ospf_message_digest_key_cmd); | |
10587 | install_element(INTERFACE_NODE, &no_ospf_message_digest_key_cmd); | |
10588 | install_element(INTERFACE_NODE, &ospf_dead_interval_cmd); | |
10589 | install_element(INTERFACE_NODE, &no_ospf_dead_interval_cmd); | |
10590 | install_element(INTERFACE_NODE, &ospf_hello_interval_cmd); | |
10591 | install_element(INTERFACE_NODE, &no_ospf_hello_interval_cmd); | |
10592 | install_element(INTERFACE_NODE, &ospf_cost_cmd); | |
10593 | install_element(INTERFACE_NODE, &no_ospf_cost_cmd); | |
10594 | install_element(INTERFACE_NODE, &ospf_network_cmd); | |
10595 | install_element(INTERFACE_NODE, &no_ospf_network_cmd); | |
10596 | install_element(INTERFACE_NODE, &ospf_priority_cmd); | |
10597 | install_element(INTERFACE_NODE, &no_ospf_priority_cmd); | |
10598 | install_element(INTERFACE_NODE, &ospf_retransmit_interval_cmd); | |
10599 | install_element(INTERFACE_NODE, &no_ospf_retransmit_interval_cmd); | |
10600 | install_element(INTERFACE_NODE, &ospf_transmit_delay_cmd); | |
10601 | install_element(INTERFACE_NODE, &no_ospf_transmit_delay_cmd); | |
10602 | } | |
10603 | ||
10604 | static void ospf_vty_zebra_init(void) | |
10605 | { | |
10606 | install_element(OSPF_NODE, &ospf_redistribute_source_cmd); | |
10607 | install_element(OSPF_NODE, &no_ospf_redistribute_source_cmd); | |
10608 | install_element(OSPF_NODE, &ospf_redistribute_instance_source_cmd); | |
10609 | install_element(OSPF_NODE, &no_ospf_redistribute_instance_source_cmd); | |
10610 | ||
10611 | install_element(OSPF_NODE, &ospf_distribute_list_out_cmd); | |
10612 | install_element(OSPF_NODE, &no_ospf_distribute_list_out_cmd); | |
10613 | ||
10614 | install_element(OSPF_NODE, &ospf_default_information_originate_cmd); | |
10615 | install_element(OSPF_NODE, &no_ospf_default_information_originate_cmd); | |
10616 | ||
10617 | install_element(OSPF_NODE, &ospf_default_metric_cmd); | |
10618 | install_element(OSPF_NODE, &no_ospf_default_metric_cmd); | |
10619 | ||
10620 | install_element(OSPF_NODE, &ospf_distance_cmd); | |
10621 | install_element(OSPF_NODE, &no_ospf_distance_cmd); | |
10622 | install_element(OSPF_NODE, &no_ospf_distance_ospf_cmd); | |
10623 | install_element(OSPF_NODE, &ospf_distance_ospf_cmd); | |
718e3744 | 10624 | #if 0 |
10625 | install_element (OSPF_NODE, &ospf_distance_source_cmd); | |
10626 | install_element (OSPF_NODE, &no_ospf_distance_source_cmd); | |
10627 | install_element (OSPF_NODE, &ospf_distance_source_access_list_cmd); | |
10628 | install_element (OSPF_NODE, &no_ospf_distance_source_access_list_cmd); | |
10629 | #endif /* 0 */ | |
10630 | } | |
10631 | ||
d62a17ae | 10632 | static struct cmd_node ospf_node = {OSPF_NODE, "%s(config-router)# ", 1}; |
718e3744 | 10633 | |
d62a17ae | 10634 | static void ospf_interface_clear(struct interface *ifp) |
09f35f8c | 10635 | { |
d62a17ae | 10636 | if (!if_is_operative(ifp)) |
10637 | return; | |
09f35f8c | 10638 | |
d62a17ae | 10639 | if (IS_DEBUG_OSPF(ism, ISM_EVENTS)) |
10640 | zlog_debug("ISM[%s]: clear by reset", ifp->name); | |
09f35f8c | 10641 | |
d62a17ae | 10642 | ospf_if_reset(ifp); |
09f35f8c DS |
10643 | } |
10644 | ||
10645 | DEFUN (clear_ip_ospf_interface, | |
10646 | clear_ip_ospf_interface_cmd, | |
03ed9f02 | 10647 | "clear ip ospf [vrf <NAME>] interface [IFNAME]", |
09f35f8c DS |
10648 | CLEAR_STR |
10649 | IP_STR | |
10650 | "OSPF information\n" | |
03ed9f02 | 10651 | VRF_CMD_HELP_STR |
09f35f8c DS |
10652 | "Interface information\n" |
10653 | "Interface name\n") | |
10654 | { | |
03ed9f02 PG |
10655 | int idx_ifname = 0; |
10656 | int idx_vrf = 0; | |
d62a17ae | 10657 | struct interface *ifp; |
f4e14fdb | 10658 | struct listnode *node; |
b5a8894d | 10659 | struct ospf *ospf = NULL; |
03ed9f02 PG |
10660 | char *vrf_name = NULL; |
10661 | vrf_id_t vrf_id = VRF_DEFAULT; | |
10662 | struct vrf *vrf = NULL; | |
09f35f8c | 10663 | |
03ed9f02 PG |
10664 | if (argv_find(argv, argc, "vrf", &idx_vrf)) |
10665 | vrf_name = argv[idx_vrf + 1]->arg; | |
10666 | if (vrf_name && strmatch(vrf_name, VRF_DEFAULT_NAME)) | |
10667 | vrf_name = NULL; | |
10668 | if (vrf_name) { | |
10669 | vrf = vrf_lookup_by_name(vrf_name); | |
10670 | if (vrf) | |
10671 | vrf_id = vrf->vrf_id; | |
10672 | } | |
10673 | if (!argv_find(argv, argc, "IFNAME", &idx_ifname)) { | |
10674 | /* Clear all the ospfv2 interfaces. */ | |
f4e14fdb | 10675 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { |
03ed9f02 PG |
10676 | if (vrf_id != ospf->vrf_id) |
10677 | continue; | |
10678 | if (!vrf) | |
10679 | vrf = vrf_lookup_by_id(ospf->vrf_id); | |
451fda4f | 10680 | FOR_ALL_INTERFACES (vrf, ifp) |
b5a8894d CS |
10681 | ospf_interface_clear(ifp); |
10682 | } | |
10683 | } else { | |
10684 | /* Interface name is specified. */ | |
a36898e7 | 10685 | ifp = if_lookup_by_name(argv[idx_ifname]->arg, vrf_id); |
b5a8894d | 10686 | if (ifp == NULL) |
d62a17ae | 10687 | vty_out(vty, "No such interface name\n"); |
10688 | else | |
10689 | ospf_interface_clear(ifp); | |
10690 | } | |
10691 | ||
10692 | return CMD_SUCCESS; | |
09f35f8c DS |
10693 | } |
10694 | ||
d62a17ae | 10695 | void ospf_vty_clear_init(void) |
09f35f8c | 10696 | { |
d62a17ae | 10697 | install_element(ENABLE_NODE, &clear_ip_ospf_interface_cmd); |
09f35f8c DS |
10698 | } |
10699 | ||
6b0655a2 | 10700 | |
718e3744 | 10701 | /* Install OSPF related vty commands. */ |
d62a17ae | 10702 | void ospf_vty_init(void) |
10703 | { | |
10704 | /* Install ospf top node. */ | |
10705 | install_node(&ospf_node, ospf_config_write); | |
10706 | ||
10707 | /* "router ospf" commands. */ | |
10708 | install_element(CONFIG_NODE, &router_ospf_cmd); | |
10709 | install_element(CONFIG_NODE, &no_router_ospf_cmd); | |
10710 | ||
10711 | ||
10712 | install_default(OSPF_NODE); | |
10713 | ||
10714 | /* "ospf router-id" commands. */ | |
10715 | install_element(OSPF_NODE, &ospf_router_id_cmd); | |
10716 | install_element(OSPF_NODE, &ospf_router_id_old_cmd); | |
10717 | install_element(OSPF_NODE, &no_ospf_router_id_cmd); | |
10718 | ||
10719 | /* "passive-interface" commands. */ | |
10720 | install_element(OSPF_NODE, &ospf_passive_interface_addr_cmd); | |
10721 | install_element(OSPF_NODE, &no_ospf_passive_interface_addr_cmd); | |
10722 | ||
10723 | /* "ospf abr-type" commands. */ | |
10724 | install_element(OSPF_NODE, &ospf_abr_type_cmd); | |
10725 | install_element(OSPF_NODE, &no_ospf_abr_type_cmd); | |
10726 | ||
10727 | /* "ospf log-adjacency-changes" commands. */ | |
10728 | install_element(OSPF_NODE, &ospf_log_adjacency_changes_cmd); | |
10729 | install_element(OSPF_NODE, &ospf_log_adjacency_changes_detail_cmd); | |
10730 | install_element(OSPF_NODE, &no_ospf_log_adjacency_changes_cmd); | |
10731 | install_element(OSPF_NODE, &no_ospf_log_adjacency_changes_detail_cmd); | |
10732 | ||
10733 | /* "ospf rfc1583-compatible" commands. */ | |
10734 | install_element(OSPF_NODE, &ospf_compatible_rfc1583_cmd); | |
10735 | install_element(OSPF_NODE, &no_ospf_compatible_rfc1583_cmd); | |
10736 | install_element(OSPF_NODE, &ospf_rfc1583_flag_cmd); | |
10737 | install_element(OSPF_NODE, &no_ospf_rfc1583_flag_cmd); | |
10738 | ||
10739 | /* "network area" commands. */ | |
10740 | install_element(OSPF_NODE, &ospf_network_area_cmd); | |
10741 | install_element(OSPF_NODE, &no_ospf_network_area_cmd); | |
10742 | ||
10743 | /* "area authentication" commands. */ | |
10744 | install_element(OSPF_NODE, | |
10745 | &ospf_area_authentication_message_digest_cmd); | |
10746 | install_element(OSPF_NODE, &ospf_area_authentication_cmd); | |
10747 | install_element(OSPF_NODE, &no_ospf_area_authentication_cmd); | |
10748 | ||
10749 | /* "area range" commands. */ | |
10750 | install_element(OSPF_NODE, &ospf_area_range_cmd); | |
10751 | install_element(OSPF_NODE, &ospf_area_range_cost_cmd); | |
10752 | install_element(OSPF_NODE, &ospf_area_range_not_advertise_cmd); | |
10753 | install_element(OSPF_NODE, &no_ospf_area_range_cmd); | |
10754 | install_element(OSPF_NODE, &ospf_area_range_substitute_cmd); | |
10755 | install_element(OSPF_NODE, &no_ospf_area_range_substitute_cmd); | |
10756 | ||
10757 | /* "area virtual-link" commands. */ | |
10758 | install_element(OSPF_NODE, &ospf_area_vlink_cmd); | |
10759 | install_element(OSPF_NODE, &ospf_area_vlink_intervals_cmd); | |
10760 | install_element(OSPF_NODE, &no_ospf_area_vlink_cmd); | |
10761 | install_element(OSPF_NODE, &no_ospf_area_vlink_intervals_cmd); | |
10762 | ||
10763 | ||
10764 | /* "area stub" commands. */ | |
10765 | install_element(OSPF_NODE, &ospf_area_stub_no_summary_cmd); | |
10766 | install_element(OSPF_NODE, &ospf_area_stub_cmd); | |
10767 | install_element(OSPF_NODE, &no_ospf_area_stub_no_summary_cmd); | |
10768 | install_element(OSPF_NODE, &no_ospf_area_stub_cmd); | |
10769 | ||
10770 | /* "area nssa" commands. */ | |
10771 | install_element(OSPF_NODE, &ospf_area_nssa_cmd); | |
d62a17ae | 10772 | install_element(OSPF_NODE, &ospf_area_nssa_translate_cmd); |
10773 | install_element(OSPF_NODE, &ospf_area_nssa_no_summary_cmd); | |
7ef56a73 | 10774 | install_element(OSPF_NODE, &no_ospf_area_nssa_no_summary_cmd); |
d62a17ae | 10775 | install_element(OSPF_NODE, &no_ospf_area_nssa_cmd); |
10776 | ||
10777 | install_element(OSPF_NODE, &ospf_area_default_cost_cmd); | |
10778 | install_element(OSPF_NODE, &no_ospf_area_default_cost_cmd); | |
10779 | ||
10780 | install_element(OSPF_NODE, &ospf_area_shortcut_cmd); | |
10781 | install_element(OSPF_NODE, &no_ospf_area_shortcut_cmd); | |
10782 | ||
10783 | install_element(OSPF_NODE, &ospf_area_export_list_cmd); | |
10784 | install_element(OSPF_NODE, &no_ospf_area_export_list_cmd); | |
10785 | ||
10786 | install_element(OSPF_NODE, &ospf_area_filter_list_cmd); | |
10787 | install_element(OSPF_NODE, &no_ospf_area_filter_list_cmd); | |
10788 | ||
10789 | install_element(OSPF_NODE, &ospf_area_import_list_cmd); | |
10790 | install_element(OSPF_NODE, &no_ospf_area_import_list_cmd); | |
10791 | ||
10792 | /* SPF timer commands */ | |
10793 | install_element(OSPF_NODE, &ospf_timers_throttle_spf_cmd); | |
10794 | install_element(OSPF_NODE, &no_ospf_timers_throttle_spf_cmd); | |
10795 | ||
10796 | /* LSA timers commands */ | |
10797 | install_element(OSPF_NODE, &ospf_timers_min_ls_interval_cmd); | |
10798 | install_element(OSPF_NODE, &no_ospf_timers_min_ls_interval_cmd); | |
0e88de35 QY |
10799 | install_element(OSPF_NODE, &ospf_timers_lsa_min_arrival_cmd); |
10800 | install_element(OSPF_NODE, &no_ospf_timers_lsa_min_arrival_cmd); | |
d62a17ae | 10801 | |
10802 | /* refresh timer commands */ | |
10803 | install_element(OSPF_NODE, &ospf_refresh_timer_cmd); | |
10804 | install_element(OSPF_NODE, &no_ospf_refresh_timer_val_cmd); | |
10805 | ||
10806 | /* max-metric commands */ | |
10807 | install_element(OSPF_NODE, &ospf_max_metric_router_lsa_admin_cmd); | |
10808 | install_element(OSPF_NODE, &no_ospf_max_metric_router_lsa_admin_cmd); | |
10809 | install_element(OSPF_NODE, &ospf_max_metric_router_lsa_startup_cmd); | |
10810 | install_element(OSPF_NODE, &no_ospf_max_metric_router_lsa_startup_cmd); | |
10811 | install_element(OSPF_NODE, &ospf_max_metric_router_lsa_shutdown_cmd); | |
10812 | install_element(OSPF_NODE, &no_ospf_max_metric_router_lsa_shutdown_cmd); | |
10813 | ||
10814 | /* reference bandwidth commands */ | |
10815 | install_element(OSPF_NODE, &ospf_auto_cost_reference_bandwidth_cmd); | |
10816 | install_element(OSPF_NODE, &no_ospf_auto_cost_reference_bandwidth_cmd); | |
10817 | ||
10818 | /* "neighbor" commands. */ | |
10819 | install_element(OSPF_NODE, &ospf_neighbor_cmd); | |
10820 | install_element(OSPF_NODE, &ospf_neighbor_poll_interval_cmd); | |
10821 | install_element(OSPF_NODE, &no_ospf_neighbor_cmd); | |
10822 | install_element(OSPF_NODE, &no_ospf_neighbor_poll_cmd); | |
10823 | ||
10824 | /* write multiplier commands */ | |
10825 | install_element(OSPF_NODE, &ospf_write_multiplier_cmd); | |
10826 | install_element(OSPF_NODE, &write_multiplier_cmd); | |
10827 | install_element(OSPF_NODE, &no_ospf_write_multiplier_cmd); | |
10828 | install_element(OSPF_NODE, &no_write_multiplier_cmd); | |
10829 | ||
10830 | /* Init interface related vty commands. */ | |
10831 | ospf_vty_if_init(); | |
10832 | ||
10833 | /* Init zebra related vty commands. */ | |
10834 | ospf_vty_zebra_init(); | |
718e3744 | 10835 | } |