]>
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 | ||
d62a17ae | 75 | void area_id2str(char *buf, int length, struct in_addr *area_id, |
76 | int area_id_fmt) | |
86573dcb | 77 | { |
d62a17ae | 78 | memset(buf, 0, length); |
86573dcb | 79 | |
d62a17ae | 80 | if (area_id_fmt == OSPF_AREA_ID_FMT_DOTTEDQUAD) |
81 | strncpy(buf, inet_ntoa(*area_id), length); | |
82 | else | |
83 | sprintf(buf, "%lu", (unsigned long)ntohl(area_id->s_addr)); | |
86573dcb | 84 | } |
6b0655a2 | 85 | |
d62a17ae | 86 | static int str2metric(const char *str, int *metric) |
718e3744 | 87 | { |
d62a17ae | 88 | /* Sanity check. */ |
89 | if (str == NULL) | |
90 | return 0; | |
718e3744 | 91 | |
d62a17ae | 92 | *metric = strtol(str, NULL, 10); |
93 | if (*metric < 0 && *metric > 16777214) { | |
94 | /* vty_out (vty, "OSPF metric value is invalid\n"); */ | |
95 | return 0; | |
96 | } | |
718e3744 | 97 | |
d62a17ae | 98 | return 1; |
718e3744 | 99 | } |
100 | ||
d62a17ae | 101 | static int str2metric_type(const char *str, int *metric_type) |
718e3744 | 102 | { |
d62a17ae | 103 | /* Sanity check. */ |
104 | if (str == NULL) | |
105 | return 0; | |
718e3744 | 106 | |
d62a17ae | 107 | if (strncmp(str, "1", 1) == 0) |
108 | *metric_type = EXTERNAL_METRIC_TYPE_1; | |
109 | else if (strncmp(str, "2", 1) == 0) | |
110 | *metric_type = EXTERNAL_METRIC_TYPE_2; | |
111 | else | |
112 | return 0; | |
718e3744 | 113 | |
d62a17ae | 114 | return 1; |
718e3744 | 115 | } |
116 | ||
d62a17ae | 117 | int ospf_oi_count(struct interface *ifp) |
718e3744 | 118 | { |
d62a17ae | 119 | struct route_node *rn; |
120 | int i = 0; | |
718e3744 | 121 | |
d62a17ae | 122 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) |
123 | if (rn->info) | |
124 | i++; | |
718e3744 | 125 | |
d62a17ae | 126 | return i; |
718e3744 | 127 | } |
128 | ||
43b8d1d8 CS |
129 | #define OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf) \ |
130 | if (argv_find(argv, argc, "vrf", &idx_vrf)) { \ | |
131 | vrf_name = argv[idx_vrf + 1]->arg; \ | |
132 | all_vrf = strmatch(vrf_name, "all"); \ | |
133 | } | |
134 | ||
135 | static struct ospf *ospf_cmd_lookup_ospf(struct vty *vty, | |
136 | struct cmd_token *argv[], | |
137 | const int argc, | |
138 | uint32_t enable, | |
139 | u_short *instance) | |
718e3744 | 140 | { |
b5a8894d | 141 | struct ospf *ospf = NULL; |
b5a8894d CS |
142 | int idx_vrf = 0; |
143 | const char *vrf_name = NULL; | |
144 | ||
145 | if (argv_find(argv, argc, "vrf", &idx_vrf)) { | |
b5a8894d | 146 | vrf_name = argv[idx_vrf + 1]->arg; |
43b8d1d8 CS |
147 | if (enable) { |
148 | if (argc > 4) | |
149 | *instance = strtoul(argv[2]->arg, NULL, 10); | |
150 | /* Allocate VRF aware instance */ | |
151 | ospf = ospf_get(*instance, vrf_name); | |
152 | } else { | |
153 | if (argc > 5) | |
154 | *instance = strtoul(argv[3]->arg, NULL, 10); | |
155 | ospf = ospf_lookup_by_inst_name(*instance, vrf_name); | |
156 | } | |
b5a8894d | 157 | } else { |
43b8d1d8 CS |
158 | if (enable) { |
159 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
160 | if (!ospf) | |
161 | vty_out(vty, | |
162 | "There isn't active ospf instance\n"); | |
163 | if (argc > 2) | |
164 | *instance = strtoul(argv[2]->arg, NULL, 10); | |
165 | } else { | |
166 | if (argc > 3) | |
167 | *instance = strtoul(argv[3]->arg, NULL, 10); | |
168 | ospf = ospf_lookup_instance(*instance); | |
b5a8894d | 169 | } |
d62a17ae | 170 | } |
43b8d1d8 CS |
171 | return ospf; |
172 | } | |
173 | ||
174 | #ifndef VTYSH_EXTRACT_PL | |
175 | #include "ospf_vty_clippy.c" | |
176 | #endif | |
177 | ||
178 | DEFUN_NOSH (router_ospf, | |
179 | router_ospf_cmd, | |
180 | "router ospf [{(1-65535)|vrf NAME}]", | |
181 | "Enable a routing process\n" | |
182 | "Start OSPF configuration\n" | |
183 | "Instance ID\n" | |
184 | VRF_CMD_HELP_STR) | |
185 | { | |
186 | struct ospf *ospf = NULL; | |
187 | int ret = CMD_SUCCESS; | |
188 | u_short instance = 0; | |
189 | ||
190 | ospf = ospf_cmd_lookup_ospf(vty, argv, argc, 1, &instance); | |
191 | if (!ospf) | |
192 | return CMD_WARNING_CONFIG_FAILED; | |
d62a17ae | 193 | |
d62a17ae | 194 | /* The following logic to set the vty qobj index is in place to be able |
195 | to ignore the commands which dont belong to this instance. */ | |
64ac44f6 | 196 | if (ospf->instance != instance) { |
d62a17ae | 197 | VTY_PUSH_CONTEXT_NULL(OSPF_NODE); |
64ac44f6 CS |
198 | ret = CMD_NOT_MY_INSTANCE; |
199 | } else { | |
b5a8894d CS |
200 | if (ospf->vrf_id != VRF_UNKNOWN) |
201 | ospf->oi_running = 1; | |
d62a17ae | 202 | if (IS_DEBUG_OSPF_EVENT) |
b5a8894d CS |
203 | zlog_debug("Config command 'router ospf %d' received, vrf %s id %d oi_running %u", |
204 | instance, ospf->name ? ospf->name : "NIL", | |
205 | ospf->vrf_id, ospf->oi_running); | |
d62a17ae | 206 | VTY_PUSH_CONTEXT(OSPF_NODE, ospf); |
207 | ospf_router_id_update(ospf); | |
208 | } | |
209 | ||
64ac44f6 | 210 | return ret; |
718e3744 | 211 | } |
212 | ||
213 | DEFUN (no_router_ospf, | |
214 | no_router_ospf_cmd, | |
43b8d1d8 | 215 | "no router ospf [{(1-65535)|vrf NAME}]", |
718e3744 | 216 | NO_STR |
217 | "Enable a routing process\n" | |
7a7be519 | 218 | "Start OSPF configuration\n" |
b5a8894d CS |
219 | "Instance ID\n" |
220 | VRF_CMD_HELP_STR) | |
718e3744 | 221 | { |
d62a17ae | 222 | struct ospf *ospf; |
223 | u_short instance = 0; | |
b5a8894d | 224 | |
43b8d1d8 CS |
225 | ospf = ospf_cmd_lookup_ospf(vty, argv, argc, 0, &instance); |
226 | if (ospf == NULL) { | |
227 | if (instance) | |
b5a8894d | 228 | return CMD_NOT_MY_INSTANCE; |
43b8d1d8 CS |
229 | else |
230 | return CMD_WARNING; | |
b5a8894d | 231 | } |
d62a17ae | 232 | ospf_finish(ospf); |
718e3744 | 233 | |
d62a17ae | 234 | return CMD_SUCCESS; |
718e3744 | 235 | } |
236 | ||
7c8ff89e | 237 | |
43b8d1d8 | 238 | DEFPY (ospf_router_id, |
718e3744 | 239 | ospf_router_id_cmd, |
240 | "ospf router-id A.B.C.D", | |
241 | "OSPF specific commands\n" | |
242 | "router-id for the OSPF process\n" | |
243 | "OSPF router-id in IP address format\n") | |
244 | { | |
a3d826f0 | 245 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
43b8d1d8 | 246 | |
d62a17ae | 247 | struct listnode *node; |
248 | struct ospf_area *area; | |
d62a17ae | 249 | |
250 | ospf->router_id_static = router_id; | |
251 | ||
252 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) | |
253 | if (area->full_nbrs) { | |
254 | vty_out(vty, | |
255 | "For this router-id change to take effect," | |
256 | " save config and restart ospfd\n"); | |
257 | return CMD_SUCCESS; | |
258 | } | |
259 | ||
260 | ospf_router_id_update(ospf); | |
261 | ||
262 | return CMD_SUCCESS; | |
718e3744 | 263 | } |
264 | ||
7a7be519 | 265 | DEFUN_HIDDEN (ospf_router_id_old, |
747e489c DW |
266 | ospf_router_id_old_cmd, |
267 | "router-id A.B.C.D", | |
268 | "router-id for the OSPF process\n" | |
269 | "OSPF router-id in IP address format\n") | |
7a7be519 | 270 | { |
a3d826f0 | 271 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 272 | int idx_ipv4 = 1; |
273 | struct listnode *node; | |
274 | struct ospf_area *area; | |
275 | struct in_addr router_id; | |
276 | int ret; | |
277 | ||
278 | ret = inet_aton(argv[idx_ipv4]->arg, &router_id); | |
279 | if (!ret) { | |
280 | vty_out(vty, "Please specify Router ID by A.B.C.D\n"); | |
281 | return CMD_WARNING_CONFIG_FAILED; | |
282 | } | |
7a7be519 | 283 | |
d62a17ae | 284 | ospf->router_id_static = router_id; |
285 | ||
286 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) | |
287 | if (area->full_nbrs) { | |
288 | vty_out(vty, | |
289 | "For this router-id change to take effect," | |
290 | " save config and restart ospfd\n"); | |
291 | return CMD_SUCCESS; | |
292 | } | |
293 | ||
294 | ospf_router_id_update(ospf); | |
295 | ||
296 | return CMD_SUCCESS; | |
7a7be519 | 297 | } |
747e489c | 298 | |
43b8d1d8 | 299 | DEFPY (no_ospf_router_id, |
718e3744 | 300 | no_ospf_router_id_cmd, |
7a7be519 | 301 | "no ospf router-id [A.B.C.D]", |
718e3744 | 302 | NO_STR |
303 | "OSPF specific commands\n" | |
7a7be519 | 304 | "router-id for the OSPF process\n" |
305 | "OSPF router-id in IP address format\n") | |
718e3744 | 306 | { |
a3d826f0 | 307 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 308 | struct listnode *node; |
309 | struct ospf_area *area; | |
68980084 | 310 | |
43b8d1d8 CS |
311 | if (router_id_str) { |
312 | if (!IPV4_ADDR_SAME(&ospf->router_id_static, &router_id)) { | |
313 | vty_out(vty, "%% OSPF router-id doesn't match\n"); | |
314 | return CMD_WARNING_CONFIG_FAILED; | |
315 | } | |
316 | } | |
317 | ||
d62a17ae | 318 | ospf->router_id_static.s_addr = 0; |
718e3744 | 319 | |
d62a17ae | 320 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) |
321 | if (area->full_nbrs) { | |
322 | vty_out(vty, | |
323 | "For this router-id change to take effect," | |
324 | " save config and restart ospfd\n"); | |
325 | return CMD_SUCCESS; | |
326 | } | |
2c19a6ec | 327 | |
d62a17ae | 328 | ospf_router_id_update(ospf); |
718e3744 | 329 | |
d62a17ae | 330 | return CMD_SUCCESS; |
718e3744 | 331 | } |
332 | ||
718e3744 | 333 | |
d62a17ae | 334 | static void ospf_passive_interface_default(struct ospf *ospf, u_char newval) |
335 | { | |
336 | struct listnode *ln; | |
337 | struct interface *ifp; | |
338 | struct ospf_interface *oi; | |
339 | ||
340 | ospf->passive_interface_default = newval; | |
341 | ||
b5a8894d | 342 | for (ALL_LIST_ELEMENTS_RO(vrf_iflist(ospf->vrf_id), ln, ifp)) { |
9d303b37 DL |
343 | if (ifp && OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(ifp), |
344 | passive_interface)) | |
d62a17ae | 345 | UNSET_IF_PARAM(IF_DEF_PARAMS(ifp), passive_interface); |
346 | } | |
347 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, ln, oi)) { | |
348 | if (OSPF_IF_PARAM_CONFIGURED(oi->params, passive_interface)) | |
349 | UNSET_IF_PARAM(oi->params, passive_interface); | |
350 | /* update multicast memberships */ | |
351 | ospf_if_set_multicast(oi); | |
352 | } | |
353 | } | |
354 | ||
355 | static void ospf_passive_interface_update_addr(struct ospf *ospf, | |
356 | struct interface *ifp, | |
357 | struct ospf_if_params *params, | |
358 | u_char value, | |
359 | struct in_addr addr) | |
360 | { | |
361 | u_char dflt; | |
362 | ||
363 | params->passive_interface = value; | |
364 | if (params != IF_DEF_PARAMS(ifp)) { | |
365 | if (OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(ifp), | |
366 | passive_interface)) | |
367 | dflt = IF_DEF_PARAMS(ifp)->passive_interface; | |
368 | else | |
369 | dflt = ospf->passive_interface_default; | |
370 | ||
371 | if (value != dflt) | |
372 | SET_IF_PARAM(params, passive_interface); | |
373 | else | |
374 | UNSET_IF_PARAM(params, passive_interface); | |
375 | ||
376 | ospf_free_if_params(ifp, addr); | |
377 | ospf_if_update_params(ifp, addr); | |
378 | } | |
379 | } | |
380 | ||
381 | static void ospf_passive_interface_update(struct ospf *ospf, | |
382 | struct interface *ifp, | |
383 | struct ospf_if_params *params, | |
384 | u_char value) | |
385 | { | |
386 | params->passive_interface = value; | |
387 | if (params == IF_DEF_PARAMS(ifp)) { | |
388 | if (value != ospf->passive_interface_default) | |
389 | SET_IF_PARAM(params, passive_interface); | |
390 | else | |
391 | UNSET_IF_PARAM(params, passive_interface); | |
392 | } | |
7ffa8fa2 PJ |
393 | } |
394 | ||
a2c62831 | 395 | DEFUN (ospf_passive_interface, |
396 | ospf_passive_interface_addr_cmd, | |
7a7be519 | 397 | "passive-interface <IFNAME [A.B.C.D]|default>", |
718e3744 | 398 | "Suppress routing updates on an interface\n" |
7a7be519 | 399 | "Interface's name\n" |
3a2d747c | 400 | "IPv4 address\n" |
7a7be519 | 401 | "Suppress routing updates on interfaces by default\n") |
718e3744 | 402 | { |
a3d826f0 | 403 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 404 | int idx_ipv4 = 2; |
405 | struct interface *ifp; | |
406 | struct in_addr addr = {.s_addr = INADDR_ANY}; | |
407 | int ret; | |
408 | struct ospf_if_params *params; | |
409 | struct route_node *rn; | |
410 | ||
411 | if (strmatch(argv[1]->text, "default")) { | |
412 | ospf_passive_interface_default(ospf, OSPF_IF_PASSIVE); | |
413 | return CMD_SUCCESS; | |
414 | } | |
415 | ||
bcc24579 | 416 | ifp = if_get_by_name(argv[1]->arg, ospf->vrf_id, 0); |
b5a8894d CS |
417 | if (ifp == NULL) { |
418 | vty_out(vty, "interface %s not found.\n", | |
419 | (char *)argv[1]->arg); | |
420 | return CMD_WARNING; | |
421 | } | |
d62a17ae | 422 | |
423 | params = IF_DEF_PARAMS(ifp); | |
424 | ||
425 | if (argc == 3) { | |
426 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
427 | if (!ret) { | |
428 | vty_out(vty, | |
429 | "Please specify interface address by A.B.C.D\n"); | |
430 | return CMD_WARNING_CONFIG_FAILED; | |
431 | } | |
432 | ||
433 | params = ospf_get_if_params(ifp, addr); | |
434 | ospf_if_update_params(ifp, addr); | |
435 | ospf_passive_interface_update_addr(ospf, ifp, params, | |
436 | OSPF_IF_PASSIVE, addr); | |
437 | } | |
438 | ||
439 | ospf_passive_interface_update(ospf, ifp, params, OSPF_IF_PASSIVE); | |
440 | ||
441 | /* XXX We should call ospf_if_set_multicast on exactly those | |
442 | * interfaces for which the passive property changed. It is too much | |
443 | * work to determine this set, so we do this for every interface. | |
444 | * This is safe and reasonable because ospf_if_set_multicast uses a | |
445 | * record of joined groups to avoid systems calls if the desired | |
446 | * memberships match the current memership. | |
447 | */ | |
448 | ||
449 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { | |
450 | struct ospf_interface *oi = rn->info; | |
451 | ||
9d303b37 DL |
452 | if (oi && (OSPF_IF_PARAM(oi, passive_interface) |
453 | == OSPF_IF_PASSIVE)) | |
d62a17ae | 454 | ospf_if_set_multicast(oi); |
455 | } | |
456 | /* | |
457 | * XXX It is not clear what state transitions the interface needs to | |
458 | * undergo when going from active to passive. Fixing this will | |
459 | * require precise identification of interfaces having such a | |
460 | * transition. | |
461 | */ | |
462 | ||
463 | return CMD_SUCCESS; | |
718e3744 | 464 | } |
465 | ||
a2c62831 | 466 | DEFUN (no_ospf_passive_interface, |
467 | no_ospf_passive_interface_addr_cmd, | |
7a7be519 | 468 | "no passive-interface <IFNAME [A.B.C.D]|default>", |
718e3744 | 469 | NO_STR |
470 | "Allow routing updates on an interface\n" | |
7a7be519 | 471 | "Interface's name\n" |
3a2d747c | 472 | "IPv4 address\n" |
7a7be519 | 473 | "Allow routing updates on interfaces by default\n") |
718e3744 | 474 | { |
a3d826f0 | 475 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 476 | int idx_ipv4 = 3; |
477 | struct interface *ifp; | |
478 | struct in_addr addr = {.s_addr = INADDR_ANY}; | |
479 | struct ospf_if_params *params; | |
480 | int ret; | |
481 | struct route_node *rn; | |
482 | ||
483 | if (strmatch(argv[2]->text, "default")) { | |
484 | ospf_passive_interface_default(ospf, OSPF_IF_ACTIVE); | |
485 | return CMD_SUCCESS; | |
43540886 AS |
486 | } |
487 | ||
bcc24579 | 488 | ifp = if_get_by_name(argv[2]->arg, ospf->vrf_id, 0); |
b5a8894d CS |
489 | if (ifp == NULL) { |
490 | vty_out(vty, "interface %s not found.\n", | |
491 | (char *)argv[1]->arg); | |
492 | return CMD_WARNING; | |
493 | } | |
ba6454ec | 494 | |
d62a17ae | 495 | params = IF_DEF_PARAMS(ifp); |
496 | ||
497 | if (argc == 4) { | |
498 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
499 | if (!ret) { | |
500 | vty_out(vty, | |
501 | "Please specify interface address by A.B.C.D\n"); | |
502 | return CMD_WARNING_CONFIG_FAILED; | |
503 | } | |
504 | ||
505 | params = ospf_lookup_if_params(ifp, addr); | |
506 | if (params == NULL) | |
507 | return CMD_SUCCESS; | |
508 | ospf_passive_interface_update_addr(ospf, ifp, params, | |
509 | OSPF_IF_ACTIVE, addr); | |
510 | } | |
511 | ospf_passive_interface_update(ospf, ifp, params, OSPF_IF_ACTIVE); | |
512 | ||
513 | /* XXX We should call ospf_if_set_multicast on exactly those | |
514 | * interfaces for which the passive property changed. It is too much | |
515 | * work to determine this set, so we do this for every interface. | |
516 | * This is safe and reasonable because ospf_if_set_multicast uses a | |
517 | * record of joined groups to avoid systems calls if the desired | |
518 | * memberships match the current memership. | |
519 | */ | |
520 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { | |
521 | struct ospf_interface *oi = rn->info; | |
522 | ||
523 | if (oi | |
524 | && (OSPF_IF_PARAM(oi, passive_interface) == OSPF_IF_ACTIVE)) | |
525 | ospf_if_set_multicast(oi); | |
526 | } | |
527 | ||
528 | return CMD_SUCCESS; | |
718e3744 | 529 | } |
530 | ||
718e3744 | 531 | |
a2c62831 | 532 | DEFUN (ospf_network_area, |
533 | ospf_network_area_cmd, | |
6147e2c6 | 534 | "network A.B.C.D/M area <A.B.C.D|(0-4294967295)>", |
718e3744 | 535 | "Enable routing on an IP network\n" |
536 | "OSPF network prefix\n" | |
537 | "Set the OSPF area ID\n" | |
538 | "OSPF area ID in IP address format\n" | |
539 | "OSPF area ID as a decimal value\n") | |
540 | { | |
a3d826f0 | 541 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 542 | int idx_ipv4_prefixlen = 1; |
543 | int idx_ipv4_number = 3; | |
544 | struct prefix_ipv4 p; | |
545 | struct in_addr area_id; | |
546 | int ret, format; | |
547 | ||
548 | if (ospf->instance) { | |
549 | vty_out(vty, | |
550 | "The network command is not supported in multi-instance ospf\n"); | |
551 | return CMD_WARNING_CONFIG_FAILED; | |
552 | } | |
718e3744 | 553 | |
d62a17ae | 554 | if (ospf->if_ospf_cli_count > 0) { |
555 | vty_out(vty, | |
556 | "Please remove all ip ospf area x.x.x.x commands first.\n"); | |
557 | return CMD_WARNING_CONFIG_FAILED; | |
558 | } | |
559 | ||
560 | /* Get network prefix and Area ID. */ | |
561 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); | |
562 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); | |
563 | ||
564 | ret = ospf_network_set(ospf, &p, area_id, format); | |
565 | if (ret == 0) { | |
566 | vty_out(vty, "There is already same network statement.\n"); | |
851fcbae | 567 | return CMD_WARNING; |
d62a17ae | 568 | } |
569 | ||
570 | return CMD_SUCCESS; | |
718e3744 | 571 | } |
572 | ||
a2c62831 | 573 | DEFUN (no_ospf_network_area, |
574 | no_ospf_network_area_cmd, | |
6147e2c6 | 575 | "no network A.B.C.D/M area <A.B.C.D|(0-4294967295)>", |
718e3744 | 576 | NO_STR |
577 | "Enable routing on an IP network\n" | |
578 | "OSPF network prefix\n" | |
579 | "Set the OSPF area ID\n" | |
580 | "OSPF area ID in IP address format\n" | |
581 | "OSPF area ID as a decimal value\n") | |
582 | { | |
a3d826f0 | 583 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 584 | int idx_ipv4_prefixlen = 2; |
585 | int idx_ipv4_number = 4; | |
586 | struct prefix_ipv4 p; | |
587 | struct in_addr area_id; | |
588 | int ret, format; | |
589 | ||
590 | if (ospf->instance) { | |
591 | vty_out(vty, | |
592 | "The network command is not supported in multi-instance ospf\n"); | |
593 | return CMD_WARNING_CONFIG_FAILED; | |
594 | } | |
718e3744 | 595 | |
d62a17ae | 596 | /* Get network prefix and Area ID. */ |
597 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); | |
598 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); | |
599 | ||
600 | ret = ospf_network_unset(ospf, &p, area_id); | |
601 | if (ret == 0) { | |
602 | vty_out(vty, | |
603 | "Can't find specified network area configuration.\n"); | |
604 | return CMD_WARNING_CONFIG_FAILED; | |
605 | } | |
606 | ||
607 | return CMD_SUCCESS; | |
718e3744 | 608 | } |
609 | ||
a2c62831 | 610 | DEFUN (ospf_area_range, |
611 | ospf_area_range_cmd, | |
7a7be519 | 612 | "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M [advertise [cost (0-16777215)]]", |
718e3744 | 613 | "OSPF area parameters\n" |
614 | "OSPF area ID in IP address format\n" | |
615 | "OSPF area ID as a decimal value\n" | |
616 | "Summarize routes matching address/mask (border routers only)\n" | |
7a7be519 | 617 | "Area range prefix\n" |
618 | "Advertise this range (default)\n" | |
619 | "User specified metric for this range\n" | |
620 | "Advertised metric for this range\n") | |
718e3744 | 621 | { |
a3d826f0 | 622 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 623 | int idx_ipv4_number = 1; |
624 | int idx_ipv4_prefixlen = 3; | |
625 | int idx_cost = 6; | |
626 | struct prefix_ipv4 p; | |
627 | struct in_addr area_id; | |
628 | int format; | |
629 | u_int32_t cost; | |
630 | ||
631 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); | |
632 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); | |
633 | ||
634 | ospf_area_range_set(ospf, area_id, &p, OSPF_AREA_RANGE_ADVERTISE); | |
635 | if (argc > 5) { | |
636 | cost = strtoul(argv[idx_cost]->arg, NULL, 10); | |
637 | ospf_area_range_cost_set(ospf, area_id, &p, cost); | |
638 | } | |
718e3744 | 639 | |
d62a17ae | 640 | return CMD_SUCCESS; |
718e3744 | 641 | } |
642 | ||
7a7be519 | 643 | DEFUN (ospf_area_range_cost, |
644 | ospf_area_range_cost_cmd, | |
645 | "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M cost (0-16777215)", | |
646 | "OSPF area parameters\n" | |
647 | "OSPF area ID in IP address format\n" | |
648 | "OSPF area ID as a decimal value\n" | |
649 | "Summarize routes matching address/mask (border routers only)\n" | |
650 | "Area range prefix\n" | |
651 | "User specified metric for this range\n" | |
652 | "Advertised metric for this range\n") | |
653 | { | |
a3d826f0 | 654 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 655 | int idx_ipv4_number = 1; |
656 | int idx_ipv4_prefixlen = 3; | |
657 | int idx_cost = 5; | |
658 | struct prefix_ipv4 p; | |
659 | struct in_addr area_id; | |
660 | int format; | |
661 | u_int32_t cost; | |
7a7be519 | 662 | |
d62a17ae | 663 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
664 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); | |
7a7be519 | 665 | |
d62a17ae | 666 | ospf_area_range_set(ospf, area_id, &p, OSPF_AREA_RANGE_ADVERTISE); |
667 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
668 | format); | |
718e3744 | 669 | |
d62a17ae | 670 | cost = strtoul(argv[idx_cost]->arg, NULL, 10); |
671 | ospf_area_range_cost_set(ospf, area_id, &p, cost); | |
718e3744 | 672 | |
d62a17ae | 673 | return CMD_SUCCESS; |
7a7be519 | 674 | } |
718e3744 | 675 | |
a2c62831 | 676 | DEFUN (ospf_area_range_not_advertise, |
677 | ospf_area_range_not_advertise_cmd, | |
6147e2c6 | 678 | "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M not-advertise", |
718e3744 | 679 | "OSPF area parameters\n" |
680 | "OSPF area ID in IP address format\n" | |
681 | "OSPF area ID as a decimal value\n" | |
682 | "Summarize routes matching address/mask (border routers only)\n" | |
683 | "Area range prefix\n" | |
684 | "DoNotAdvertise this range\n") | |
685 | { | |
a3d826f0 | 686 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 687 | int idx_ipv4_number = 1; |
688 | int idx_ipv4_prefixlen = 3; | |
689 | struct prefix_ipv4 p; | |
690 | struct in_addr area_id; | |
691 | int format; | |
718e3744 | 692 | |
d62a17ae | 693 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
694 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); | |
718e3744 | 695 | |
d62a17ae | 696 | ospf_area_range_set(ospf, area_id, &p, 0); |
697 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
698 | format); | |
718e3744 | 699 | |
d62a17ae | 700 | return CMD_SUCCESS; |
718e3744 | 701 | } |
702 | ||
a2c62831 | 703 | DEFUN (no_ospf_area_range, |
704 | no_ospf_area_range_cmd, | |
3a2d747c | 705 | "no area <A.B.C.D|(0-4294967295)> range A.B.C.D/M [<cost (0-16777215)|advertise [cost (0-16777215)]|not-advertise>]", |
718e3744 | 706 | NO_STR |
707 | "OSPF area parameters\n" | |
708 | "OSPF area ID in IP address format\n" | |
709 | "OSPF area ID as a decimal value\n" | |
710 | "Summarize routes matching address/mask (border routers only)\n" | |
7a7be519 | 711 | "Area range prefix\n" |
3a2d747c QY |
712 | "User specified metric for this range\n" |
713 | "Advertised metric for this range\n" | |
7a7be519 | 714 | "Advertise this range (default)\n" |
3a2d747c QY |
715 | "User specified metric for this range\n" |
716 | "Advertised metric for this range\n" | |
7a7be519 | 717 | "DoNotAdvertise this range\n") |
718e3744 | 718 | { |
a3d826f0 | 719 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 720 | int idx_ipv4_number = 2; |
721 | int idx_ipv4_prefixlen = 4; | |
722 | struct prefix_ipv4 p; | |
723 | struct in_addr area_id; | |
724 | int format; | |
718e3744 | 725 | |
d62a17ae | 726 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
727 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); | |
718e3744 | 728 | |
d62a17ae | 729 | ospf_area_range_unset(ospf, area_id, &p); |
718e3744 | 730 | |
d62a17ae | 731 | return CMD_SUCCESS; |
718e3744 | 732 | } |
733 | ||
a2c62831 | 734 | DEFUN (ospf_area_range_substitute, |
735 | ospf_area_range_substitute_cmd, | |
6147e2c6 | 736 | "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M substitute A.B.C.D/M", |
718e3744 | 737 | "OSPF area parameters\n" |
738 | "OSPF area ID in IP address format\n" | |
739 | "OSPF area ID as a decimal value\n" | |
740 | "Summarize routes matching address/mask (border routers only)\n" | |
741 | "Area range prefix\n" | |
742 | "Announce area range as another prefix\n" | |
743 | "Network prefix to be announced instead of range\n") | |
744 | { | |
a3d826f0 | 745 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 746 | int idx_ipv4_number = 1; |
747 | int idx_ipv4_prefixlen = 3; | |
748 | int idx_ipv4_prefixlen_2 = 5; | |
749 | struct prefix_ipv4 p, s; | |
750 | struct in_addr area_id; | |
751 | int format; | |
718e3744 | 752 | |
d62a17ae | 753 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
754 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); | |
755 | str2prefix_ipv4(argv[idx_ipv4_prefixlen_2]->arg, &s); | |
718e3744 | 756 | |
d62a17ae | 757 | ospf_area_range_substitute_set(ospf, area_id, &p, &s); |
758 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
759 | format); | |
718e3744 | 760 | |
d62a17ae | 761 | return CMD_SUCCESS; |
718e3744 | 762 | } |
763 | ||
a2c62831 | 764 | DEFUN (no_ospf_area_range_substitute, |
765 | no_ospf_area_range_substitute_cmd, | |
6147e2c6 | 766 | "no area <A.B.C.D|(0-4294967295)> range A.B.C.D/M substitute A.B.C.D/M", |
718e3744 | 767 | NO_STR |
768 | "OSPF area parameters\n" | |
769 | "OSPF area ID in IP address format\n" | |
770 | "OSPF area ID as a decimal value\n" | |
771 | "Summarize routes matching address/mask (border routers only)\n" | |
772 | "Area range prefix\n" | |
773 | "Announce area range as another prefix\n" | |
774 | "Network prefix to be announced instead of range\n") | |
775 | { | |
a3d826f0 | 776 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 777 | int idx_ipv4_number = 2; |
778 | int idx_ipv4_prefixlen = 4; | |
779 | int idx_ipv4_prefixlen_2 = 6; | |
780 | struct prefix_ipv4 p, s; | |
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); | |
786 | str2prefix_ipv4(argv[idx_ipv4_prefixlen_2]->arg, &s); | |
718e3744 | 787 | |
d62a17ae | 788 | ospf_area_range_substitute_unset(ospf, area_id, &p); |
718e3744 | 789 | |
d62a17ae | 790 | return CMD_SUCCESS; |
718e3744 | 791 | } |
792 | ||
6b0655a2 | 793 | |
718e3744 | 794 | /* Command Handler Logic in VLink stuff is delicate!! |
795 | ||
796 | ALTER AT YOUR OWN RISK!!!! | |
797 | ||
798 | Various dummy values are used to represent 'NoChange' state for | |
799 | VLink configuration NOT being changed by a VLink command, and | |
800 | special syntax is used within the command strings so that the | |
801 | typed in command verbs can be seen in the configuration command | |
802 | bacckend handler. This is to drastically reduce the verbeage | |
803 | required to coe up with a reasonably compatible Cisco VLink command | |
804 | ||
d62a17ae | 805 | - Matthew Grant <grantma@anathoth.gen.nz> |
718e3744 | 806 | Wed, 21 Feb 2001 15:13:52 +1300 |
807 | */ | |
808 | ||
d62a17ae | 809 | /* Configuration data for virtual links |
810 | */ | |
718e3744 | 811 | struct ospf_vl_config_data { |
d62a17ae | 812 | struct vty *vty; /* vty stuff */ |
813 | struct in_addr area_id; /* area ID from command line */ | |
814 | int area_id_fmt; /* command line area ID format */ | |
815 | struct in_addr vl_peer; /* command line vl_peer */ | |
816 | int auth_type; /* Authehntication type, if given */ | |
817 | char *auth_key; /* simple password if present */ | |
818 | int crypto_key_id; /* Cryptographic key ID */ | |
819 | char *md5_key; /* MD5 authentication key */ | |
820 | int hello_interval; /* Obvious what these are... */ | |
821 | int retransmit_interval; | |
822 | int transmit_delay; | |
823 | int dead_interval; | |
718e3744 | 824 | }; |
825 | ||
d62a17ae | 826 | static void ospf_vl_config_data_init(struct ospf_vl_config_data *vl_config, |
827 | struct vty *vty) | |
718e3744 | 828 | { |
d62a17ae | 829 | memset(vl_config, 0, sizeof(struct ospf_vl_config_data)); |
830 | vl_config->auth_type = OSPF_AUTH_CMD_NOTSEEN; | |
831 | vl_config->vty = vty; | |
718e3744 | 832 | } |
833 | ||
4dadc291 | 834 | static struct ospf_vl_data * |
d62a17ae | 835 | ospf_find_vl_data(struct ospf *ospf, struct ospf_vl_config_data *vl_config) |
836 | { | |
837 | struct ospf_area *area; | |
838 | struct ospf_vl_data *vl_data; | |
839 | struct vty *vty; | |
840 | struct in_addr area_id; | |
841 | ||
842 | vty = vl_config->vty; | |
843 | area_id = vl_config->area_id; | |
844 | ||
845 | if (area_id.s_addr == OSPF_AREA_BACKBONE) { | |
846 | vty_out(vty, | |
847 | "Configuring VLs over the backbone is not allowed\n"); | |
848 | return NULL; | |
849 | } | |
850 | area = ospf_area_get(ospf, area_id); | |
851 | ospf_area_display_format_set(ospf, area, vl_config->area_id_fmt); | |
852 | ||
853 | if (area->external_routing != OSPF_AREA_DEFAULT) { | |
854 | if (vl_config->area_id_fmt == OSPF_AREA_ID_FMT_DOTTEDQUAD) | |
855 | vty_out(vty, "Area %s is %s\n", inet_ntoa(area_id), | |
856 | area->external_routing == OSPF_AREA_NSSA | |
857 | ? "nssa" | |
858 | : "stub"); | |
859 | else | |
860 | vty_out(vty, "Area %ld is %s\n", | |
861 | (u_long)ntohl(area_id.s_addr), | |
862 | area->external_routing == OSPF_AREA_NSSA | |
863 | ? "nssa" | |
864 | : "stub"); | |
865 | return NULL; | |
866 | } | |
867 | ||
868 | if ((vl_data = ospf_vl_lookup(ospf, area, vl_config->vl_peer)) | |
869 | == NULL) { | |
870 | vl_data = ospf_vl_data_new(area, vl_config->vl_peer); | |
871 | if (vl_data->vl_oi == NULL) { | |
872 | vl_data->vl_oi = ospf_vl_new(ospf, vl_data); | |
873 | ospf_vl_add(ospf, vl_data); | |
874 | ospf_spf_calculate_schedule(ospf, | |
875 | SPF_FLAG_CONFIG_CHANGE); | |
876 | } | |
718e3744 | 877 | } |
d62a17ae | 878 | return vl_data; |
718e3744 | 879 | } |
880 | ||
881 | ||
d62a17ae | 882 | static int ospf_vl_set_security(struct ospf_vl_data *vl_data, |
883 | struct ospf_vl_config_data *vl_config) | |
884 | { | |
885 | struct crypt_key *ck; | |
886 | struct vty *vty; | |
887 | struct interface *ifp = vl_data->vl_oi->ifp; | |
888 | ||
889 | vty = vl_config->vty; | |
890 | ||
891 | if (vl_config->auth_type != OSPF_AUTH_CMD_NOTSEEN) { | |
892 | SET_IF_PARAM(IF_DEF_PARAMS(ifp), auth_type); | |
893 | IF_DEF_PARAMS(ifp)->auth_type = vl_config->auth_type; | |
718e3744 | 894 | } |
718e3744 | 895 | |
d62a17ae | 896 | if (vl_config->auth_key) { |
897 | memset(IF_DEF_PARAMS(ifp)->auth_simple, 0, | |
898 | OSPF_AUTH_SIMPLE_SIZE + 1); | |
899 | strncpy((char *)IF_DEF_PARAMS(ifp)->auth_simple, | |
900 | vl_config->auth_key, OSPF_AUTH_SIMPLE_SIZE); | |
901 | } else if (vl_config->md5_key) { | |
902 | if (ospf_crypt_key_lookup(IF_DEF_PARAMS(ifp)->auth_crypt, | |
903 | vl_config->crypto_key_id) | |
904 | != NULL) { | |
905 | vty_out(vty, "OSPF: Key %d already exists\n", | |
906 | vl_config->crypto_key_id); | |
851fcbae | 907 | return CMD_WARNING; |
d62a17ae | 908 | } |
909 | ck = ospf_crypt_key_new(); | |
910 | ck->key_id = vl_config->crypto_key_id; | |
911 | memset(ck->auth_key, 0, OSPF_AUTH_MD5_SIZE + 1); | |
912 | strncpy((char *)ck->auth_key, vl_config->md5_key, | |
913 | OSPF_AUTH_MD5_SIZE); | |
914 | ||
915 | ospf_crypt_key_add(IF_DEF_PARAMS(ifp)->auth_crypt, ck); | |
916 | } else if (vl_config->crypto_key_id != 0) { | |
917 | /* Delete a key */ | |
918 | ||
919 | if (ospf_crypt_key_lookup(IF_DEF_PARAMS(ifp)->auth_crypt, | |
920 | vl_config->crypto_key_id) | |
921 | == NULL) { | |
922 | vty_out(vty, "OSPF: Key %d does not exist\n", | |
923 | vl_config->crypto_key_id); | |
924 | return CMD_WARNING_CONFIG_FAILED; | |
925 | } | |
926 | ||
927 | ospf_crypt_key_delete(IF_DEF_PARAMS(ifp)->auth_crypt, | |
928 | vl_config->crypto_key_id); | |
929 | } | |
930 | ||
931 | return CMD_SUCCESS; | |
718e3744 | 932 | } |
933 | ||
d62a17ae | 934 | static int ospf_vl_set_timers(struct ospf_vl_data *vl_data, |
935 | struct ospf_vl_config_data *vl_config) | |
936 | { | |
937 | struct interface *ifp = vl_data->vl_oi->ifp; | |
938 | /* Virtual Link data initialised to defaults, so only set | |
939 | if a value given */ | |
940 | if (vl_config->hello_interval) { | |
941 | SET_IF_PARAM(IF_DEF_PARAMS(ifp), v_hello); | |
942 | IF_DEF_PARAMS(ifp)->v_hello = vl_config->hello_interval; | |
943 | } | |
944 | ||
945 | if (vl_config->dead_interval) { | |
946 | SET_IF_PARAM(IF_DEF_PARAMS(ifp), v_wait); | |
947 | IF_DEF_PARAMS(ifp)->v_wait = vl_config->dead_interval; | |
948 | } | |
949 | ||
950 | if (vl_config->retransmit_interval) { | |
951 | SET_IF_PARAM(IF_DEF_PARAMS(ifp), retransmit_interval); | |
952 | IF_DEF_PARAMS(ifp)->retransmit_interval = | |
953 | vl_config->retransmit_interval; | |
954 | } | |
955 | ||
956 | if (vl_config->transmit_delay) { | |
957 | SET_IF_PARAM(IF_DEF_PARAMS(ifp), transmit_delay); | |
958 | IF_DEF_PARAMS(ifp)->transmit_delay = vl_config->transmit_delay; | |
959 | } | |
960 | ||
961 | return CMD_SUCCESS; | |
718e3744 | 962 | } |
963 | ||
964 | ||
718e3744 | 965 | /* The business end of all of the above */ |
d62a17ae | 966 | static int ospf_vl_set(struct ospf *ospf, struct ospf_vl_config_data *vl_config) |
967 | { | |
968 | struct ospf_vl_data *vl_data; | |
969 | int ret; | |
718e3744 | 970 | |
d62a17ae | 971 | vl_data = ospf_find_vl_data(ospf, vl_config); |
972 | if (!vl_data) | |
973 | return CMD_WARNING_CONFIG_FAILED; | |
974 | ||
975 | /* Process this one first as it can have a fatal result, which can | |
976 | only logically occur if the virtual link exists already | |
977 | Thus a command error does not result in a change to the | |
978 | running configuration such as unexpectedly altered timer | |
979 | values etc.*/ | |
980 | ret = ospf_vl_set_security(vl_data, vl_config); | |
981 | if (ret != CMD_SUCCESS) | |
982 | return ret; | |
983 | ||
984 | /* Set any time based parameters, these area already range checked */ | |
985 | ||
986 | ret = ospf_vl_set_timers(vl_data, vl_config); | |
987 | if (ret != CMD_SUCCESS) | |
988 | return ret; | |
718e3744 | 989 | |
d62a17ae | 990 | return CMD_SUCCESS; |
718e3744 | 991 | } |
992 | ||
993 | /* This stuff exists to make specifying all the alias commands A LOT simpler | |
994 | */ | |
d62a17ae | 995 | #define VLINK_HELPSTR_IPADDR \ |
996 | "OSPF area parameters\n" \ | |
997 | "OSPF area ID in IP address format\n" \ | |
998 | "OSPF area ID as a decimal value\n" \ | |
999 | "Configure a virtual link\n" \ | |
1000 | "Router ID of the remote ABR\n" | |
1001 | ||
1002 | #define VLINK_HELPSTR_AUTHTYPE_SIMPLE \ | |
1003 | "Enable authentication on this virtual link\n" \ | |
1004 | "dummy string \n" | |
1005 | ||
1006 | #define VLINK_HELPSTR_AUTHTYPE_ALL \ | |
1007 | VLINK_HELPSTR_AUTHTYPE_SIMPLE \ | |
1008 | "Use null authentication\n" \ | |
1009 | "Use message-digest authentication\n" | |
1010 | ||
1011 | #define VLINK_HELPSTR_TIME_PARAM \ | |
1012 | "Time between HELLO packets\n" \ | |
1013 | "Seconds\n" \ | |
1014 | "Time between retransmitting lost link state advertisements\n" \ | |
1015 | "Seconds\n" \ | |
1016 | "Link state transmit delay\n" \ | |
1017 | "Seconds\n" \ | |
1018 | "Interval time after which a neighbor is declared down\n" \ | |
1019 | "Seconds\n" | |
1020 | ||
1021 | #define VLINK_HELPSTR_AUTH_SIMPLE \ | |
1022 | "Authentication password (key)\n" \ | |
baf9eaad | 1023 | "The OSPF password (key)\n" |
d62a17ae | 1024 | |
1025 | #define VLINK_HELPSTR_AUTH_MD5 \ | |
1026 | "Message digest authentication password (key)\n" \ | |
d62a17ae | 1027 | "Key ID\n" \ |
1028 | "Use MD5 algorithm\n" \ | |
baf9eaad | 1029 | "The OSPF password (key)\n" |
718e3744 | 1030 | |
a2c62831 | 1031 | DEFUN (ospf_area_vlink, |
1032 | ospf_area_vlink_cmd, | |
3d1c6dc2 | 1033 | "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 | 1034 | VLINK_HELPSTR_IPADDR |
3d1c6dc2 | 1035 | "Enable authentication on this virtual link\n" |
7a7be519 | 1036 | "Use message-digest authentication\n" |
3d1c6dc2 | 1037 | "Use null authentication\n" |
baf9eaad CS |
1038 | VLINK_HELPSTR_AUTH_MD5 |
1039 | VLINK_HELPSTR_AUTH_SIMPLE) | |
718e3744 | 1040 | { |
a3d826f0 | 1041 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1042 | int idx_ipv4_number = 1; |
1043 | int idx_ipv4 = 3; | |
1044 | struct ospf_vl_config_data vl_config; | |
1045 | char auth_key[OSPF_AUTH_SIMPLE_SIZE + 1]; | |
1046 | char md5_key[OSPF_AUTH_MD5_SIZE + 1]; | |
d62a17ae | 1047 | int ret; |
55d1da24 | 1048 | int idx = 0; |
d62a17ae | 1049 | |
1050 | ospf_vl_config_data_init(&vl_config, vty); | |
1051 | ||
1052 | /* Read off first 2 parameters and check them */ | |
1053 | ret = str2area_id(argv[idx_ipv4_number]->arg, &vl_config.area_id, | |
1054 | &vl_config.area_id_fmt); | |
1055 | if (ret < 0) { | |
1056 | vty_out(vty, "OSPF area ID is invalid\n"); | |
1057 | return CMD_WARNING_CONFIG_FAILED; | |
1058 | } | |
718e3744 | 1059 | |
d62a17ae | 1060 | ret = inet_aton(argv[idx_ipv4]->arg, &vl_config.vl_peer); |
1061 | if (!ret) { | |
1062 | vty_out(vty, "Please specify valid Router ID as a.b.c.d\n"); | |
1063 | return CMD_WARNING_CONFIG_FAILED; | |
7a7be519 | 1064 | } |
7a7be519 | 1065 | |
d62a17ae | 1066 | if (argc <= 4) { |
1067 | /* Thats all folks! - BUGS B. strikes again!!!*/ | |
7a7be519 | 1068 | |
d62a17ae | 1069 | return ospf_vl_set(ospf, &vl_config); |
1070 | } | |
1071 | ||
3d1c6dc2 CS |
1072 | if (argv_find(argv, argc, "authentication", &idx)) { |
1073 | /* authentication - this option can only occur | |
1074 | at start of command line */ | |
1075 | vl_config.auth_type = OSPF_AUTH_SIMPLE; | |
1076 | } | |
1077 | ||
3d1c6dc2 | 1078 | if (argv_find(argv, argc, "message-digest", &idx)) { |
baf9eaad | 1079 | /* authentication message-digest */ |
3d1c6dc2 CS |
1080 | vl_config.auth_type = OSPF_AUTH_CRYPTOGRAPHIC; |
1081 | } else if (argv_find(argv, argc, "null", &idx)) { | |
1082 | /* "authentication null" */ | |
1083 | vl_config.auth_type = OSPF_AUTH_NULL; | |
d62a17ae | 1084 | } |
7a7be519 | 1085 | |
3d1c6dc2 | 1086 | if (argv_find(argv, argc, "message-digest-key", &idx)) { |
3d1c6dc2 | 1087 | vl_config.md5_key = NULL; |
cbb9b53d | 1088 | vl_config.crypto_key_id = strtol(argv[idx + 1]->arg, NULL, 10); |
3d1c6dc2 CS |
1089 | if (vl_config.crypto_key_id < 0) |
1090 | return CMD_WARNING_CONFIG_FAILED; | |
1091 | ||
3d1c6dc2 | 1092 | memset(md5_key, 0, OSPF_AUTH_MD5_SIZE + 1); |
cbb9b53d | 1093 | strncpy(md5_key, argv[idx + 3]->arg, OSPF_AUTH_MD5_SIZE); |
3d1c6dc2 CS |
1094 | vl_config.md5_key = md5_key; |
1095 | } | |
1096 | ||
3d1c6dc2 | 1097 | if (argv_find(argv, argc, "authentication-key", &idx)) { |
3d1c6dc2 | 1098 | memset(auth_key, 0, OSPF_AUTH_SIMPLE_SIZE + 1); |
cbb9b53d | 1099 | strncpy(auth_key, argv[idx + 1]->arg, OSPF_AUTH_SIMPLE_SIZE); |
3d1c6dc2 CS |
1100 | vl_config.auth_key = auth_key; |
1101 | } | |
7a7be519 | 1102 | |
d62a17ae | 1103 | /* Action configuration */ |
1104 | ||
1105 | return ospf_vl_set(ospf, &vl_config); | |
7a7be519 | 1106 | } |
1107 | ||
a2c62831 | 1108 | DEFUN (no_ospf_area_vlink, |
1109 | no_ospf_area_vlink_cmd, | |
3d1c6dc2 | 1110 | "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 | 1111 | NO_STR |
7a7be519 | 1112 | VLINK_HELPSTR_IPADDR |
1113 | "Enable authentication on this virtual link\n" \ | |
3d1c6dc2 | 1114 | "Use message-digest authentication\n" \ |
7a7be519 | 1115 | "Use null authentication\n" \ |
baf9eaad CS |
1116 | VLINK_HELPSTR_AUTH_MD5 |
1117 | VLINK_HELPSTR_AUTH_SIMPLE) | |
718e3744 | 1118 | { |
a3d826f0 | 1119 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1120 | int idx_ipv4_number = 2; |
1121 | int idx_ipv4 = 4; | |
1122 | struct ospf_area *area; | |
1123 | struct ospf_vl_config_data vl_config; | |
1124 | struct ospf_vl_data *vl_data = NULL; | |
1125 | char auth_key[OSPF_AUTH_SIMPLE_SIZE + 1]; | |
3d1c6dc2 | 1126 | int idx = 0; |
d62a17ae | 1127 | int ret, format; |
1128 | ||
1129 | ospf_vl_config_data_init(&vl_config, vty); | |
1130 | ||
1131 | ret = str2area_id(argv[idx_ipv4_number]->arg, &vl_config.area_id, | |
1132 | &format); | |
1133 | if (ret < 0) { | |
1134 | vty_out(vty, "OSPF area ID is invalid\n"); | |
1135 | return CMD_WARNING_CONFIG_FAILED; | |
1136 | } | |
1137 | ||
1138 | area = ospf_area_lookup_by_area_id(ospf, vl_config.area_id); | |
1139 | if (!area) { | |
1140 | vty_out(vty, "Area does not exist\n"); | |
1141 | return CMD_WARNING_CONFIG_FAILED; | |
1142 | } | |
1143 | ||
1144 | ret = inet_aton(argv[idx_ipv4]->arg, &vl_config.vl_peer); | |
1145 | if (!ret) { | |
1146 | vty_out(vty, "Please specify valid Router ID as a.b.c.d\n"); | |
1147 | return CMD_WARNING_CONFIG_FAILED; | |
1148 | } | |
718e3744 | 1149 | |
d62a17ae | 1150 | if (argc <= 5) { |
1151 | /* Basic VLink no command */ | |
1152 | /* Thats all folks! - BUGS B. strikes again!!!*/ | |
1153 | if ((vl_data = ospf_vl_lookup(ospf, area, vl_config.vl_peer))) | |
1154 | ospf_vl_delete(ospf, vl_data); | |
1155 | ||
1156 | ospf_area_check_free(ospf, vl_config.area_id); | |
1157 | ||
1158 | return CMD_SUCCESS; | |
1159 | } | |
1160 | ||
1161 | /* If we are down here, we are reseting parameters */ | |
d62a17ae | 1162 | /* Deal with other parameters */ |
3d1c6dc2 CS |
1163 | |
1164 | if (argv_find(argv, argc, "authentication", &idx)) { | |
1165 | /* authentication - this option can only occur | |
1166 | at start of command line */ | |
1167 | vl_config.auth_type = OSPF_AUTH_NOTSET; | |
1168 | } | |
1169 | ||
3d1c6dc2 | 1170 | if (argv_find(argv, argc, "message-digest-key", &idx)) { |
3d1c6dc2 | 1171 | vl_config.md5_key = NULL; |
cbb9b53d | 1172 | vl_config.crypto_key_id = strtol(argv[idx + 1]->arg, NULL, 10); |
3d1c6dc2 CS |
1173 | if (vl_config.crypto_key_id < 0) |
1174 | return CMD_WARNING_CONFIG_FAILED; | |
d62a17ae | 1175 | } |
1176 | ||
3d1c6dc2 | 1177 | if (argv_find(argv, argc, "authentication-key", &idx)) { |
cbb9b53d | 1178 | /* Reset authentication-key to 0 */ |
3d1c6dc2 CS |
1179 | memset(auth_key, 0, OSPF_AUTH_SIMPLE_SIZE + 1); |
1180 | vl_config.auth_key = auth_key; | |
1181 | } | |
d62a17ae | 1182 | |
1183 | /* Action configuration */ | |
1184 | ||
1185 | return ospf_vl_set(ospf, &vl_config); | |
7a7be519 | 1186 | } |
1187 | ||
b1c02cec QY |
1188 | DEFUN (ospf_area_vlink_intervals, |
1189 | ospf_area_vlink_intervals_cmd, | |
1190 | "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)}", | |
1191 | VLINK_HELPSTR_IPADDR | |
1192 | VLINK_HELPSTR_TIME_PARAM) | |
1193 | { | |
a3d826f0 | 1194 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1195 | struct ospf_vl_config_data vl_config; |
1196 | int ret = 0; | |
1197 | ||
1198 | ospf_vl_config_data_init(&vl_config, vty); | |
1199 | ||
1200 | char *area_id = argv[1]->arg; | |
1201 | char *router_id = argv[3]->arg; | |
1202 | ||
1203 | ret = str2area_id(area_id, &vl_config.area_id, &vl_config.area_id_fmt); | |
1204 | if (ret < 0) { | |
1205 | vty_out(vty, "OSPF area ID is invalid\n"); | |
1206 | return CMD_WARNING_CONFIG_FAILED; | |
1207 | } | |
1208 | ||
1209 | ret = inet_aton(router_id, &vl_config.vl_peer); | |
1210 | if (!ret) { | |
1211 | vty_out(vty, "Please specify valid Router ID as a.b.c.d\n"); | |
1212 | return CMD_WARNING_CONFIG_FAILED; | |
1213 | } | |
1214 | ||
1215 | for (int idx = 4; idx < argc; idx++) { | |
1216 | if (strmatch(argv[idx]->text, "hello-interval")) | |
1217 | vl_config.hello_interval = | |
1218 | strtol(argv[++idx]->arg, NULL, 10); | |
1219 | else if (strmatch(argv[idx]->text, "retransmit-interval")) | |
1220 | vl_config.retransmit_interval = | |
1221 | strtol(argv[++idx]->arg, NULL, 10); | |
1222 | else if (strmatch(argv[idx]->text, "transmit-delay")) | |
1223 | vl_config.transmit_delay = | |
1224 | strtol(argv[++idx]->arg, NULL, 10); | |
1225 | else if (strmatch(argv[idx]->text, "dead-interval")) | |
1226 | vl_config.dead_interval = | |
1227 | strtol(argv[++idx]->arg, NULL, 10); | |
1228 | } | |
1229 | ||
1230 | /* Action configuration */ | |
1231 | return ospf_vl_set(ospf, &vl_config); | |
b1c02cec QY |
1232 | } |
1233 | ||
7a7be519 | 1234 | DEFUN (no_ospf_area_vlink_intervals, |
1235 | no_ospf_area_vlink_intervals_cmd, | |
a663a38e | 1236 | "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 | 1237 | NO_STR |
7a7be519 | 1238 | VLINK_HELPSTR_IPADDR |
7a7be519 | 1239 | VLINK_HELPSTR_TIME_PARAM) |
1240 | { | |
a3d826f0 | 1241 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1242 | struct ospf_vl_config_data vl_config; |
1243 | int ret = 0; | |
1244 | ||
1245 | ospf_vl_config_data_init(&vl_config, vty); | |
1246 | ||
1247 | char *area_id = argv[2]->arg; | |
1248 | char *router_id = argv[4]->arg; | |
1249 | ||
1250 | ret = str2area_id(area_id, &vl_config.area_id, &vl_config.area_id_fmt); | |
1251 | if (ret < 0) { | |
1252 | vty_out(vty, "OSPF area ID is invalid\n"); | |
1253 | return CMD_WARNING_CONFIG_FAILED; | |
1254 | } | |
1255 | ||
1256 | ret = inet_aton(router_id, &vl_config.vl_peer); | |
1257 | if (!ret) { | |
1258 | vty_out(vty, "Please specify valid Router ID as a.b.c.d\n"); | |
1259 | return CMD_WARNING_CONFIG_FAILED; | |
1260 | } | |
1261 | ||
1262 | for (int idx = 5; idx < argc; idx++) { | |
1263 | if (strmatch(argv[idx]->text, "hello-interval")) | |
1264 | vl_config.hello_interval = OSPF_HELLO_INTERVAL_DEFAULT; | |
1265 | else if (strmatch(argv[idx]->text, "retransmit-interval")) | |
1266 | vl_config.retransmit_interval = | |
1267 | OSPF_RETRANSMIT_INTERVAL_DEFAULT; | |
1268 | else if (strmatch(argv[idx]->text, "transmit-delay")) | |
1269 | vl_config.transmit_delay = OSPF_TRANSMIT_DELAY_DEFAULT; | |
1270 | else if (strmatch(argv[idx]->text, "dead-interval")) | |
1271 | vl_config.dead_interval = | |
1272 | OSPF_ROUTER_DEAD_INTERVAL_DEFAULT; | |
1273 | } | |
1274 | ||
1275 | /* Action configuration */ | |
1276 | return ospf_vl_set(ospf, &vl_config); | |
718e3744 | 1277 | } |
1278 | ||
a2c62831 | 1279 | DEFUN (ospf_area_shortcut, |
1280 | ospf_area_shortcut_cmd, | |
6147e2c6 | 1281 | "area <A.B.C.D|(0-4294967295)> shortcut <default|enable|disable>", |
718e3744 | 1282 | "OSPF area parameters\n" |
1283 | "OSPF area ID in IP address format\n" | |
1284 | "OSPF area ID as a decimal value\n" | |
1285 | "Configure the area's shortcutting mode\n" | |
1286 | "Set default shortcutting behavior\n" | |
1287 | "Enable shortcutting through the area\n" | |
1288 | "Disable shortcutting through the area\n") | |
1289 | { | |
a3d826f0 | 1290 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1291 | int idx_ipv4_number = 1; |
1292 | int idx_enable_disable = 3; | |
1293 | struct ospf_area *area; | |
1294 | struct in_addr area_id; | |
1295 | int mode; | |
1296 | int format; | |
1297 | ||
1298 | VTY_GET_OSPF_AREA_ID_NO_BB("shortcut", area_id, format, | |
1299 | argv[idx_ipv4_number]->arg); | |
1300 | ||
1301 | area = ospf_area_get(ospf, area_id); | |
1302 | ospf_area_display_format_set(ospf, area, format); | |
1303 | ||
1304 | if (strncmp(argv[idx_enable_disable]->arg, "de", 2) == 0) | |
1305 | mode = OSPF_SHORTCUT_DEFAULT; | |
1306 | else if (strncmp(argv[idx_enable_disable]->arg, "di", 2) == 0) | |
1307 | mode = OSPF_SHORTCUT_DISABLE; | |
1308 | else if (strncmp(argv[idx_enable_disable]->arg, "e", 1) == 0) | |
1309 | mode = OSPF_SHORTCUT_ENABLE; | |
1310 | else | |
1311 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 1312 | |
d62a17ae | 1313 | ospf_area_shortcut_set(ospf, area, mode); |
718e3744 | 1314 | |
d62a17ae | 1315 | if (ospf->abr_type != OSPF_ABR_SHORTCUT) |
1316 | vty_out(vty, | |
1317 | "Shortcut area setting will take effect " | |
1318 | "only when the router is configured as Shortcut ABR\n"); | |
718e3744 | 1319 | |
d62a17ae | 1320 | return CMD_SUCCESS; |
718e3744 | 1321 | } |
1322 | ||
a2c62831 | 1323 | DEFUN (no_ospf_area_shortcut, |
1324 | no_ospf_area_shortcut_cmd, | |
6147e2c6 | 1325 | "no area <A.B.C.D|(0-4294967295)> shortcut <enable|disable>", |
718e3744 | 1326 | NO_STR |
1327 | "OSPF area parameters\n" | |
1328 | "OSPF area ID in IP address format\n" | |
1329 | "OSPF area ID as a decimal value\n" | |
1330 | "Deconfigure the area's shortcutting mode\n" | |
1331 | "Deconfigure enabled shortcutting through the area\n" | |
1332 | "Deconfigure disabled shortcutting through the area\n") | |
1333 | { | |
a3d826f0 | 1334 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1335 | int idx_ipv4_number = 2; |
1336 | struct ospf_area *area; | |
1337 | struct in_addr area_id; | |
1338 | int format; | |
718e3744 | 1339 | |
d62a17ae | 1340 | VTY_GET_OSPF_AREA_ID_NO_BB("shortcut", area_id, format, |
1341 | argv[idx_ipv4_number]->arg); | |
718e3744 | 1342 | |
d62a17ae | 1343 | area = ospf_area_lookup_by_area_id(ospf, area_id); |
1344 | if (!area) | |
1345 | return CMD_SUCCESS; | |
718e3744 | 1346 | |
d62a17ae | 1347 | ospf_area_shortcut_unset(ospf, area); |
718e3744 | 1348 | |
d62a17ae | 1349 | return CMD_SUCCESS; |
718e3744 | 1350 | } |
1351 | ||
6b0655a2 | 1352 | |
a2c62831 | 1353 | DEFUN (ospf_area_stub, |
1354 | ospf_area_stub_cmd, | |
6147e2c6 | 1355 | "area <A.B.C.D|(0-4294967295)> stub", |
718e3744 | 1356 | "OSPF area parameters\n" |
1357 | "OSPF area ID in IP address format\n" | |
1358 | "OSPF area ID as a decimal value\n" | |
1359 | "Configure OSPF area as stub\n") | |
1360 | { | |
a3d826f0 | 1361 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1362 | int idx_ipv4_number = 1; |
1363 | struct in_addr area_id; | |
1364 | int ret, format; | |
1365 | ||
1366 | VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id, format, | |
1367 | argv[idx_ipv4_number]->arg); | |
1368 | ||
1369 | ret = ospf_area_stub_set(ospf, area_id); | |
1370 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
1371 | format); | |
1372 | if (ret == 0) { | |
1373 | vty_out(vty, | |
1374 | "First deconfigure all virtual link through this area\n"); | |
1375 | return CMD_WARNING_CONFIG_FAILED; | |
1376 | } | |
718e3744 | 1377 | |
d62a17ae | 1378 | ospf_area_no_summary_unset(ospf, area_id); |
718e3744 | 1379 | |
d62a17ae | 1380 | return CMD_SUCCESS; |
718e3744 | 1381 | } |
1382 | ||
a2c62831 | 1383 | DEFUN (ospf_area_stub_no_summary, |
1384 | ospf_area_stub_no_summary_cmd, | |
6147e2c6 | 1385 | "area <A.B.C.D|(0-4294967295)> stub no-summary", |
718e3744 | 1386 | "OSPF stub parameters\n" |
1387 | "OSPF area ID in IP address format\n" | |
1388 | "OSPF area ID as a decimal value\n" | |
1389 | "Configure OSPF area as stub\n" | |
1390 | "Do not inject inter-area routes into stub\n") | |
1391 | { | |
a3d826f0 | 1392 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1393 | int idx_ipv4_number = 1; |
1394 | struct in_addr area_id; | |
1395 | int ret, format; | |
1396 | ||
1397 | VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id, format, | |
1398 | argv[idx_ipv4_number]->arg); | |
1399 | ||
1400 | ret = ospf_area_stub_set(ospf, area_id); | |
1401 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
1402 | format); | |
1403 | if (ret == 0) { | |
1404 | vty_out(vty, | |
1405 | "%% Area cannot be stub as it contains a virtual link\n"); | |
1406 | return CMD_WARNING_CONFIG_FAILED; | |
1407 | } | |
718e3744 | 1408 | |
d62a17ae | 1409 | ospf_area_no_summary_set(ospf, area_id); |
718e3744 | 1410 | |
d62a17ae | 1411 | return CMD_SUCCESS; |
718e3744 | 1412 | } |
1413 | ||
a2c62831 | 1414 | DEFUN (no_ospf_area_stub, |
1415 | no_ospf_area_stub_cmd, | |
6147e2c6 | 1416 | "no area <A.B.C.D|(0-4294967295)> stub", |
718e3744 | 1417 | NO_STR |
1418 | "OSPF area parameters\n" | |
1419 | "OSPF area ID in IP address format\n" | |
1420 | "OSPF area ID as a decimal value\n" | |
1421 | "Configure OSPF area as stub\n") | |
1422 | { | |
a3d826f0 | 1423 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1424 | int idx_ipv4_number = 2; |
1425 | struct in_addr area_id; | |
1426 | int format; | |
718e3744 | 1427 | |
d62a17ae | 1428 | VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id, format, |
1429 | argv[idx_ipv4_number]->arg); | |
718e3744 | 1430 | |
d62a17ae | 1431 | ospf_area_stub_unset(ospf, area_id); |
1432 | ospf_area_no_summary_unset(ospf, area_id); | |
718e3744 | 1433 | |
d62a17ae | 1434 | return CMD_SUCCESS; |
718e3744 | 1435 | } |
1436 | ||
a2c62831 | 1437 | DEFUN (no_ospf_area_stub_no_summary, |
1438 | no_ospf_area_stub_no_summary_cmd, | |
6147e2c6 | 1439 | "no area <A.B.C.D|(0-4294967295)> stub no-summary", |
718e3744 | 1440 | NO_STR |
1441 | "OSPF area parameters\n" | |
1442 | "OSPF area ID in IP address format\n" | |
1443 | "OSPF area ID as a decimal value\n" | |
1444 | "Configure OSPF area as stub\n" | |
1445 | "Do not inject inter-area routes into area\n") | |
1446 | { | |
a3d826f0 | 1447 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1448 | int idx_ipv4_number = 2; |
1449 | struct in_addr area_id; | |
1450 | int format; | |
718e3744 | 1451 | |
d62a17ae | 1452 | VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id, format, |
1453 | argv[idx_ipv4_number]->arg); | |
1454 | ospf_area_no_summary_unset(ospf, area_id); | |
718e3744 | 1455 | |
d62a17ae | 1456 | return CMD_SUCCESS; |
718e3744 | 1457 | } |
1458 | ||
d62a17ae | 1459 | static int ospf_area_nssa_cmd_handler(struct vty *vty, int argc, |
1460 | struct cmd_token **argv, int nosum) | |
718e3744 | 1461 | { |
a3d826f0 | 1462 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1463 | struct in_addr area_id; |
1464 | int ret, format; | |
1465 | ||
1466 | VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id, format, argv[1]->arg); | |
1467 | ||
1468 | ret = ospf_area_nssa_set(ospf, area_id); | |
1469 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
1470 | format); | |
1471 | if (ret == 0) { | |
1472 | vty_out(vty, | |
1473 | "%% Area cannot be nssa as it contains a virtual link\n"); | |
1474 | return CMD_WARNING_CONFIG_FAILED; | |
1475 | } | |
1476 | ||
1477 | if (argc > 3) { | |
1478 | if (strncmp(argv[3]->text, "translate-c", 11) == 0) | |
1479 | ospf_area_nssa_translator_role_set( | |
1480 | ospf, area_id, OSPF_NSSA_ROLE_CANDIDATE); | |
1481 | else if (strncmp(argv[3]->text, "translate-n", 11) == 0) | |
1482 | ospf_area_nssa_translator_role_set( | |
1483 | ospf, area_id, OSPF_NSSA_ROLE_NEVER); | |
1484 | else if (strncmp(argv[3]->text, "translate-a", 11) == 0) | |
1485 | ospf_area_nssa_translator_role_set( | |
1486 | ospf, area_id, OSPF_NSSA_ROLE_ALWAYS); | |
1487 | } else { | |
1488 | ospf_area_nssa_translator_role_set(ospf, area_id, | |
1489 | OSPF_NSSA_ROLE_CANDIDATE); | |
1490 | } | |
1491 | ||
1492 | if (nosum) | |
1493 | ospf_area_no_summary_set(ospf, area_id); | |
1494 | else | |
1495 | ospf_area_no_summary_unset(ospf, area_id); | |
1496 | ||
1497 | ospf_schedule_abr_task(ospf); | |
1498 | ||
1499 | return CMD_SUCCESS; | |
718e3744 | 1500 | } |
1501 | ||
b0a053be | 1502 | DEFUN (ospf_area_nssa_translate_no_summary, |
a2c62831 | 1503 | ospf_area_nssa_translate_no_summary_cmd, |
6147e2c6 | 1504 | "area <A.B.C.D|(0-4294967295)> nssa <translate-candidate|translate-never|translate-always> no-summary", |
718e3744 | 1505 | "OSPF area parameters\n" |
1506 | "OSPF area ID in IP address format\n" | |
1507 | "OSPF area ID as a decimal value\n" | |
1508 | "Configure OSPF area as nssa\n" | |
1509 | "Configure NSSA-ABR for translate election (default)\n" | |
1510 | "Configure NSSA-ABR to never translate\n" | |
1511 | "Configure NSSA-ABR to always translate\n" | |
b0a053be | 1512 | "Do not inject inter-area routes into nssa\n") |
1513 | { | |
d62a17ae | 1514 | return ospf_area_nssa_cmd_handler(vty, argc, argv, 1); |
b0a053be | 1515 | } |
718e3744 | 1516 | |
b0a053be | 1517 | DEFUN (ospf_area_nssa_translate, |
a2c62831 | 1518 | ospf_area_nssa_translate_cmd, |
6147e2c6 | 1519 | "area <A.B.C.D|(0-4294967295)> nssa <translate-candidate|translate-never|translate-always>", |
718e3744 | 1520 | "OSPF area parameters\n" |
1521 | "OSPF area ID in IP address format\n" | |
1522 | "OSPF area ID as a decimal value\n" | |
1523 | "Configure OSPF area as nssa\n" | |
1524 | "Configure NSSA-ABR for translate election (default)\n" | |
1525 | "Configure NSSA-ABR to never translate\n" | |
1526 | "Configure NSSA-ABR to always translate\n") | |
b0a053be | 1527 | { |
d62a17ae | 1528 | return ospf_area_nssa_cmd_handler(vty, argc, argv, 0); |
b0a053be | 1529 | } |
1530 | ||
1531 | DEFUN (ospf_area_nssa, | |
1532 | ospf_area_nssa_cmd, | |
6147e2c6 | 1533 | "area <A.B.C.D|(0-4294967295)> nssa", |
b0a053be | 1534 | "OSPF area parameters\n" |
1535 | "OSPF area ID in IP address format\n" | |
1536 | "OSPF area ID as a decimal value\n" | |
1537 | "Configure OSPF area as nssa\n") | |
1538 | { | |
d62a17ae | 1539 | return ospf_area_nssa_cmd_handler(vty, argc, argv, 0); |
b0a053be | 1540 | } |
718e3744 | 1541 | |
a2c62831 | 1542 | DEFUN (ospf_area_nssa_no_summary, |
1543 | ospf_area_nssa_no_summary_cmd, | |
6147e2c6 | 1544 | "area <A.B.C.D|(0-4294967295)> nssa no-summary", |
718e3744 | 1545 | "OSPF area parameters\n" |
1546 | "OSPF area ID in IP address format\n" | |
1547 | "OSPF area ID as a decimal value\n" | |
1548 | "Configure OSPF area as nssa\n" | |
1549 | "Do not inject inter-area routes into nssa\n") | |
1550 | { | |
d62a17ae | 1551 | return ospf_area_nssa_cmd_handler(vty, argc, argv, 1); |
718e3744 | 1552 | } |
1553 | ||
a2c62831 | 1554 | DEFUN (no_ospf_area_nssa, |
1555 | no_ospf_area_nssa_cmd, | |
7a7be519 | 1556 | "no area <A.B.C.D|(0-4294967295)> nssa [<translate-candidate|translate-never|translate-always> [no-summary]]", |
718e3744 | 1557 | NO_STR |
1558 | "OSPF area parameters\n" | |
1559 | "OSPF area ID in IP address format\n" | |
1560 | "OSPF area ID as a decimal value\n" | |
7a7be519 | 1561 | "Configure OSPF area as nssa\n" |
1562 | "Configure NSSA-ABR for translate election (default)\n" | |
1563 | "Configure NSSA-ABR to never translate\n" | |
1564 | "Configure NSSA-ABR to always translate\n" | |
1565 | "Do not inject inter-area routes into nssa\n") | |
22b27e95 | 1566 | { |
a3d826f0 | 1567 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1568 | int idx_ipv4_number = 2; |
1569 | struct in_addr area_id; | |
1570 | int format; | |
718e3744 | 1571 | |
d62a17ae | 1572 | VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id, format, |
1573 | argv[idx_ipv4_number]->arg); | |
718e3744 | 1574 | |
d62a17ae | 1575 | ospf_area_nssa_unset(ospf, area_id); |
1576 | ospf_area_no_summary_unset(ospf, area_id); | |
718e3744 | 1577 | |
d62a17ae | 1578 | ospf_schedule_abr_task(ospf); |
b0a053be | 1579 | |
d62a17ae | 1580 | return CMD_SUCCESS; |
718e3744 | 1581 | } |
1582 | ||
718e3744 | 1583 | |
a2c62831 | 1584 | DEFUN (ospf_area_default_cost, |
1585 | ospf_area_default_cost_cmd, | |
6147e2c6 | 1586 | "area <A.B.C.D|(0-4294967295)> default-cost (0-16777215)", |
718e3744 | 1587 | "OSPF area parameters\n" |
1588 | "OSPF area ID in IP address format\n" | |
1589 | "OSPF area ID as a decimal value\n" | |
1590 | "Set the summary-default cost of a NSSA or stub area\n" | |
1591 | "Stub's advertised default summary cost\n") | |
1592 | { | |
a3d826f0 | 1593 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1594 | int idx_ipv4_number = 1; |
1595 | int idx_number = 3; | |
1596 | struct ospf_area *area; | |
1597 | struct in_addr area_id; | |
1598 | u_int32_t cost; | |
1599 | int format; | |
1600 | struct prefix_ipv4 p; | |
1601 | ||
1602 | VTY_GET_OSPF_AREA_ID_NO_BB("default-cost", area_id, format, | |
1603 | argv[idx_ipv4_number]->arg); | |
1604 | cost = strtoul(argv[idx_number]->arg, NULL, 10); | |
1605 | ||
1606 | area = ospf_area_get(ospf, area_id); | |
1607 | ospf_area_display_format_set(ospf, area, format); | |
1608 | ||
1609 | if (area->external_routing == OSPF_AREA_DEFAULT) { | |
1610 | vty_out(vty, "The area is neither stub, nor NSSA\n"); | |
1611 | return CMD_WARNING_CONFIG_FAILED; | |
1612 | } | |
ba682537 | 1613 | |
d62a17ae | 1614 | area->default_cost = cost; |
1615 | ||
1616 | p.family = AF_INET; | |
1617 | p.prefix.s_addr = OSPF_DEFAULT_DESTINATION; | |
1618 | p.prefixlen = 0; | |
1619 | if (IS_DEBUG_OSPF_EVENT) | |
1620 | zlog_debug( | |
1621 | "ospf_abr_announce_stub_defaults(): " | |
1622 | "announcing 0.0.0.0/0 to area %s", | |
1623 | inet_ntoa(area->area_id)); | |
1624 | ospf_abr_announce_network_to_area(&p, area->default_cost, area); | |
1625 | ||
1626 | return CMD_SUCCESS; | |
718e3744 | 1627 | } |
1628 | ||
a2c62831 | 1629 | DEFUN (no_ospf_area_default_cost, |
1630 | no_ospf_area_default_cost_cmd, | |
6147e2c6 | 1631 | "no area <A.B.C.D|(0-4294967295)> default-cost (0-16777215)", |
718e3744 | 1632 | NO_STR |
1633 | "OSPF area parameters\n" | |
1634 | "OSPF area ID in IP address format\n" | |
1635 | "OSPF area ID as a decimal value\n" | |
1636 | "Set the summary-default cost of a NSSA or stub area\n" | |
1637 | "Stub's advertised default summary cost\n") | |
1638 | { | |
a3d826f0 | 1639 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1640 | int idx_ipv4_number = 2; |
1641 | struct ospf_area *area; | |
1642 | struct in_addr area_id; | |
1643 | int format; | |
1644 | struct prefix_ipv4 p; | |
718e3744 | 1645 | |
d62a17ae | 1646 | VTY_GET_OSPF_AREA_ID_NO_BB("default-cost", area_id, format, |
1647 | argv[idx_ipv4_number]->arg); | |
718e3744 | 1648 | |
d62a17ae | 1649 | area = ospf_area_lookup_by_area_id(ospf, area_id); |
1650 | if (area == NULL) | |
1651 | return CMD_SUCCESS; | |
718e3744 | 1652 | |
d62a17ae | 1653 | if (area->external_routing == OSPF_AREA_DEFAULT) { |
1654 | vty_out(vty, "The area is neither stub, nor NSSA\n"); | |
1655 | return CMD_WARNING_CONFIG_FAILED; | |
1656 | } | |
718e3744 | 1657 | |
d62a17ae | 1658 | area->default_cost = 1; |
718e3744 | 1659 | |
d62a17ae | 1660 | p.family = AF_INET; |
1661 | p.prefix.s_addr = OSPF_DEFAULT_DESTINATION; | |
1662 | p.prefixlen = 0; | |
1663 | if (IS_DEBUG_OSPF_EVENT) | |
1664 | zlog_debug( | |
1665 | "ospf_abr_announce_stub_defaults(): " | |
1666 | "announcing 0.0.0.0/0 to area %s", | |
1667 | inet_ntoa(area->area_id)); | |
1668 | ospf_abr_announce_network_to_area(&p, area->default_cost, area); | |
ba682537 | 1669 | |
1670 | ||
d62a17ae | 1671 | ospf_area_check_free(ospf, area_id); |
718e3744 | 1672 | |
d62a17ae | 1673 | return CMD_SUCCESS; |
718e3744 | 1674 | } |
1675 | ||
a2c62831 | 1676 | DEFUN (ospf_area_export_list, |
1677 | ospf_area_export_list_cmd, | |
6147e2c6 | 1678 | "area <A.B.C.D|(0-4294967295)> export-list NAME", |
718e3744 | 1679 | "OSPF area parameters\n" |
1680 | "OSPF area ID in IP address format\n" | |
1681 | "OSPF area ID as a decimal value\n" | |
1682 | "Set the filter for networks announced to other areas\n" | |
1683 | "Name of the access-list\n") | |
1684 | { | |
a3d826f0 | 1685 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1686 | int idx_ipv4_number = 1; |
1687 | struct ospf_area *area; | |
1688 | struct in_addr area_id; | |
1689 | int format; | |
718e3744 | 1690 | |
d62a17ae | 1691 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
52930766 | 1692 | |
d62a17ae | 1693 | area = ospf_area_get(ospf, area_id); |
1694 | ospf_area_display_format_set(ospf, area, format); | |
1695 | ospf_area_export_list_set(ospf, area, argv[3]->arg); | |
718e3744 | 1696 | |
d62a17ae | 1697 | return CMD_SUCCESS; |
718e3744 | 1698 | } |
1699 | ||
a2c62831 | 1700 | DEFUN (no_ospf_area_export_list, |
1701 | no_ospf_area_export_list_cmd, | |
6147e2c6 | 1702 | "no area <A.B.C.D|(0-4294967295)> export-list NAME", |
718e3744 | 1703 | NO_STR |
1704 | "OSPF area parameters\n" | |
1705 | "OSPF area ID in IP address format\n" | |
1706 | "OSPF area ID as a decimal value\n" | |
1707 | "Unset the filter for networks announced to other areas\n" | |
1708 | "Name of the access-list\n") | |
1709 | { | |
a3d826f0 | 1710 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1711 | int idx_ipv4_number = 2; |
1712 | struct ospf_area *area; | |
1713 | struct in_addr area_id; | |
1714 | int format; | |
718e3744 | 1715 | |
d62a17ae | 1716 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
52930766 | 1717 | |
d62a17ae | 1718 | area = ospf_area_lookup_by_area_id(ospf, area_id); |
1719 | if (area == NULL) | |
1720 | return CMD_SUCCESS; | |
718e3744 | 1721 | |
d62a17ae | 1722 | ospf_area_export_list_unset(ospf, area); |
718e3744 | 1723 | |
d62a17ae | 1724 | return CMD_SUCCESS; |
718e3744 | 1725 | } |
1726 | ||
1727 | ||
a2c62831 | 1728 | DEFUN (ospf_area_import_list, |
1729 | ospf_area_import_list_cmd, | |
6147e2c6 | 1730 | "area <A.B.C.D|(0-4294967295)> import-list NAME", |
718e3744 | 1731 | "OSPF area parameters\n" |
1732 | "OSPF area ID in IP address format\n" | |
1733 | "OSPF area ID as a decimal value\n" | |
1734 | "Set the filter for networks from other areas announced to the specified one\n" | |
1735 | "Name of the access-list\n") | |
1736 | { | |
a3d826f0 | 1737 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1738 | int idx_ipv4_number = 1; |
1739 | struct ospf_area *area; | |
1740 | struct in_addr area_id; | |
1741 | int format; | |
718e3744 | 1742 | |
d62a17ae | 1743 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
52930766 | 1744 | |
d62a17ae | 1745 | area = ospf_area_get(ospf, area_id); |
1746 | ospf_area_display_format_set(ospf, area, format); | |
1747 | ospf_area_import_list_set(ospf, area, argv[3]->arg); | |
718e3744 | 1748 | |
d62a17ae | 1749 | return CMD_SUCCESS; |
718e3744 | 1750 | } |
1751 | ||
a2c62831 | 1752 | DEFUN (no_ospf_area_import_list, |
1753 | no_ospf_area_import_list_cmd, | |
6147e2c6 | 1754 | "no area <A.B.C.D|(0-4294967295)> import-list NAME", |
718e3744 | 1755 | NO_STR |
1756 | "OSPF area parameters\n" | |
1757 | "OSPF area ID in IP address format\n" | |
1758 | "OSPF area ID as a decimal value\n" | |
1759 | "Unset the filter for networks announced to other areas\n" | |
1760 | "Name of the access-list\n") | |
1761 | { | |
a3d826f0 | 1762 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1763 | int idx_ipv4_number = 2; |
1764 | struct ospf_area *area; | |
1765 | struct in_addr area_id; | |
1766 | int format; | |
718e3744 | 1767 | |
d62a17ae | 1768 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
52930766 | 1769 | |
d62a17ae | 1770 | area = ospf_area_lookup_by_area_id(ospf, area_id); |
1771 | if (area == NULL) | |
1772 | return CMD_SUCCESS; | |
718e3744 | 1773 | |
d62a17ae | 1774 | ospf_area_import_list_unset(ospf, area); |
718e3744 | 1775 | |
d62a17ae | 1776 | return CMD_SUCCESS; |
718e3744 | 1777 | } |
1778 | ||
a2c62831 | 1779 | DEFUN (ospf_area_filter_list, |
1780 | ospf_area_filter_list_cmd, | |
6147e2c6 | 1781 | "area <A.B.C.D|(0-4294967295)> filter-list prefix WORD <in|out>", |
718e3744 | 1782 | "OSPF area parameters\n" |
1783 | "OSPF area ID in IP address format\n" | |
1784 | "OSPF area ID as a decimal value\n" | |
1785 | "Filter networks between OSPF areas\n" | |
1786 | "Filter prefixes between OSPF areas\n" | |
1787 | "Name of an IP prefix-list\n" | |
1788 | "Filter networks sent to this area\n" | |
1789 | "Filter networks sent from this area\n") | |
1790 | { | |
a3d826f0 | 1791 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1792 | int idx_ipv4_number = 1; |
1793 | int idx_word = 4; | |
1794 | int idx_in_out = 5; | |
1795 | struct ospf_area *area; | |
1796 | struct in_addr area_id; | |
1797 | struct prefix_list *plist; | |
1798 | int format; | |
1799 | ||
1800 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); | |
1801 | ||
1802 | area = ospf_area_get(ospf, area_id); | |
1803 | ospf_area_display_format_set(ospf, area, format); | |
1804 | plist = prefix_list_lookup(AFI_IP, argv[idx_word]->arg); | |
1805 | if (strncmp(argv[idx_in_out]->arg, "in", 2) == 0) { | |
1806 | PREFIX_LIST_IN(area) = plist; | |
1807 | if (PREFIX_NAME_IN(area)) | |
1808 | free(PREFIX_NAME_IN(area)); | |
1809 | ||
1810 | PREFIX_NAME_IN(area) = strdup(argv[idx_word]->arg); | |
1811 | ospf_schedule_abr_task(ospf); | |
1812 | } else { | |
1813 | PREFIX_LIST_OUT(area) = plist; | |
1814 | if (PREFIX_NAME_OUT(area)) | |
1815 | free(PREFIX_NAME_OUT(area)); | |
1816 | ||
1817 | PREFIX_NAME_OUT(area) = strdup(argv[idx_word]->arg); | |
1818 | ospf_schedule_abr_task(ospf); | |
1819 | } | |
718e3744 | 1820 | |
d62a17ae | 1821 | return CMD_SUCCESS; |
718e3744 | 1822 | } |
1823 | ||
a2c62831 | 1824 | DEFUN (no_ospf_area_filter_list, |
1825 | no_ospf_area_filter_list_cmd, | |
6147e2c6 | 1826 | "no area <A.B.C.D|(0-4294967295)> filter-list prefix WORD <in|out>", |
718e3744 | 1827 | NO_STR |
1828 | "OSPF area parameters\n" | |
1829 | "OSPF area ID in IP address format\n" | |
1830 | "OSPF area ID as a decimal value\n" | |
1831 | "Filter networks between OSPF areas\n" | |
1832 | "Filter prefixes between OSPF areas\n" | |
1833 | "Name of an IP prefix-list\n" | |
1834 | "Filter networks sent to this area\n" | |
1835 | "Filter networks sent from this area\n") | |
1836 | { | |
a3d826f0 | 1837 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1838 | int idx_ipv4_number = 2; |
1839 | int idx_word = 5; | |
1840 | int idx_in_out = 6; | |
1841 | struct ospf_area *area; | |
1842 | struct in_addr area_id; | |
1843 | int format; | |
718e3744 | 1844 | |
d62a17ae | 1845 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
718e3744 | 1846 | |
d62a17ae | 1847 | if ((area = ospf_area_lookup_by_area_id(ospf, area_id)) == NULL) |
1848 | return CMD_SUCCESS; | |
718e3744 | 1849 | |
d62a17ae | 1850 | if (strncmp(argv[idx_in_out]->arg, "in", 2) == 0) { |
1851 | if (PREFIX_NAME_IN(area)) | |
1852 | if (strcmp(PREFIX_NAME_IN(area), argv[idx_word]->arg) | |
1853 | != 0) | |
1854 | return CMD_SUCCESS; | |
718e3744 | 1855 | |
d62a17ae | 1856 | PREFIX_LIST_IN(area) = NULL; |
1857 | if (PREFIX_NAME_IN(area)) | |
1858 | free(PREFIX_NAME_IN(area)); | |
718e3744 | 1859 | |
d62a17ae | 1860 | PREFIX_NAME_IN(area) = NULL; |
718e3744 | 1861 | |
d62a17ae | 1862 | ospf_schedule_abr_task(ospf); |
1863 | } else { | |
1864 | if (PREFIX_NAME_OUT(area)) | |
1865 | if (strcmp(PREFIX_NAME_OUT(area), argv[idx_word]->arg) | |
1866 | != 0) | |
1867 | return CMD_SUCCESS; | |
718e3744 | 1868 | |
d62a17ae | 1869 | PREFIX_LIST_OUT(area) = NULL; |
1870 | if (PREFIX_NAME_OUT(area)) | |
1871 | free(PREFIX_NAME_OUT(area)); | |
718e3744 | 1872 | |
d62a17ae | 1873 | PREFIX_NAME_OUT(area) = NULL; |
718e3744 | 1874 | |
d62a17ae | 1875 | ospf_schedule_abr_task(ospf); |
1876 | } | |
1877 | ||
1878 | return CMD_SUCCESS; | |
718e3744 | 1879 | } |
1880 | ||
6b0655a2 | 1881 | |
a2c62831 | 1882 | DEFUN (ospf_area_authentication_message_digest, |
1883 | ospf_area_authentication_message_digest_cmd, | |
32573073 QY |
1884 | "[no] area <A.B.C.D|(0-4294967295)> authentication message-digest", |
1885 | NO_STR | |
718e3744 | 1886 | "OSPF area parameters\n" |
2b00515a CF |
1887 | "OSPF area ID in IP address format\n" |
1888 | "OSPF area ID as a decimal value\n" | |
718e3744 | 1889 | "Enable authentication\n" |
1890 | "Use message-digest authentication\n") | |
1891 | { | |
a3d826f0 | 1892 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1893 | int idx_ipv4_number = 1; |
1894 | struct ospf_area *area; | |
1895 | struct in_addr area_id; | |
1896 | int format; | |
718e3744 | 1897 | |
d62a17ae | 1898 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
718e3744 | 1899 | |
d62a17ae | 1900 | area = ospf_area_get(ospf, area_id); |
1901 | ospf_area_display_format_set(ospf, area, format); | |
32573073 | 1902 | area->auth_type = strmatch(argv[0]->text, "no") ? OSPF_AUTH_NULL : OSPF_AUTH_CRYPTOGRAPHIC; |
718e3744 | 1903 | |
d62a17ae | 1904 | return CMD_SUCCESS; |
718e3744 | 1905 | } |
1906 | ||
a2c62831 | 1907 | DEFUN (ospf_area_authentication, |
1908 | ospf_area_authentication_cmd, | |
6147e2c6 | 1909 | "area <A.B.C.D|(0-4294967295)> authentication", |
718e3744 | 1910 | "OSPF area parameters\n" |
1911 | "OSPF area ID in IP address format\n" | |
1912 | "OSPF area ID as a decimal value\n" | |
1913 | "Enable authentication\n") | |
1914 | { | |
a3d826f0 | 1915 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1916 | int idx_ipv4_number = 1; |
1917 | struct ospf_area *area; | |
1918 | struct in_addr area_id; | |
1919 | int format; | |
718e3744 | 1920 | |
d62a17ae | 1921 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
718e3744 | 1922 | |
d62a17ae | 1923 | area = ospf_area_get(ospf, area_id); |
1924 | ospf_area_display_format_set(ospf, area, format); | |
1925 | area->auth_type = OSPF_AUTH_SIMPLE; | |
718e3744 | 1926 | |
d62a17ae | 1927 | return CMD_SUCCESS; |
718e3744 | 1928 | } |
1929 | ||
a2c62831 | 1930 | DEFUN (no_ospf_area_authentication, |
1931 | no_ospf_area_authentication_cmd, | |
6147e2c6 | 1932 | "no area <A.B.C.D|(0-4294967295)> authentication", |
718e3744 | 1933 | NO_STR |
1934 | "OSPF area parameters\n" | |
1935 | "OSPF area ID in IP address format\n" | |
1936 | "OSPF area ID as a decimal value\n" | |
1937 | "Enable authentication\n") | |
1938 | { | |
a3d826f0 | 1939 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1940 | int idx_ipv4_number = 2; |
1941 | struct ospf_area *area; | |
1942 | struct in_addr area_id; | |
1943 | int format; | |
718e3744 | 1944 | |
d62a17ae | 1945 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
718e3744 | 1946 | |
d62a17ae | 1947 | area = ospf_area_lookup_by_area_id(ospf, area_id); |
1948 | if (area == NULL) | |
1949 | return CMD_SUCCESS; | |
718e3744 | 1950 | |
d62a17ae | 1951 | area->auth_type = OSPF_AUTH_NULL; |
718e3744 | 1952 | |
d62a17ae | 1953 | ospf_area_check_free(ospf, area_id); |
1954 | ||
1955 | return CMD_SUCCESS; | |
718e3744 | 1956 | } |
1957 | ||
6b0655a2 | 1958 | |
718e3744 | 1959 | DEFUN (ospf_abr_type, |
1960 | ospf_abr_type_cmd, | |
6147e2c6 | 1961 | "ospf abr-type <cisco|ibm|shortcut|standard>", |
718e3744 | 1962 | "OSPF specific commands\n" |
1963 | "Set OSPF ABR type\n" | |
1964 | "Alternative ABR, cisco implementation\n" | |
1965 | "Alternative ABR, IBM implementation\n" | |
1966 | "Shortcut ABR\n" | |
1967 | "Standard behavior (RFC2328)\n") | |
1968 | { | |
a3d826f0 | 1969 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1970 | int idx_vendor = 2; |
1971 | u_char abr_type = OSPF_ABR_UNKNOWN; | |
1972 | ||
1973 | if (strncmp(argv[idx_vendor]->arg, "c", 1) == 0) | |
1974 | abr_type = OSPF_ABR_CISCO; | |
1975 | else if (strncmp(argv[idx_vendor]->arg, "i", 1) == 0) | |
1976 | abr_type = OSPF_ABR_IBM; | |
1977 | else if (strncmp(argv[idx_vendor]->arg, "sh", 2) == 0) | |
1978 | abr_type = OSPF_ABR_SHORTCUT; | |
1979 | else if (strncmp(argv[idx_vendor]->arg, "st", 2) == 0) | |
1980 | abr_type = OSPF_ABR_STAND; | |
1981 | else | |
1982 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 1983 | |
d62a17ae | 1984 | /* If ABR type value is changed, schedule ABR task. */ |
1985 | if (ospf->abr_type != abr_type) { | |
1986 | ospf->abr_type = abr_type; | |
1987 | ospf_schedule_abr_task(ospf); | |
1988 | } | |
1989 | ||
1990 | return CMD_SUCCESS; | |
718e3744 | 1991 | } |
1992 | ||
1993 | DEFUN (no_ospf_abr_type, | |
1994 | no_ospf_abr_type_cmd, | |
6147e2c6 | 1995 | "no ospf abr-type <cisco|ibm|shortcut|standard>", |
718e3744 | 1996 | NO_STR |
1997 | "OSPF specific commands\n" | |
1998 | "Set OSPF ABR type\n" | |
1999 | "Alternative ABR, cisco implementation\n" | |
2000 | "Alternative ABR, IBM implementation\n" | |
3a2d747c QY |
2001 | "Shortcut ABR\n" |
2002 | "Standard ABR\n") | |
718e3744 | 2003 | { |
a3d826f0 | 2004 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2005 | int idx_vendor = 3; |
2006 | u_char abr_type = OSPF_ABR_UNKNOWN; | |
2007 | ||
2008 | if (strncmp(argv[idx_vendor]->arg, "c", 1) == 0) | |
2009 | abr_type = OSPF_ABR_CISCO; | |
2010 | else if (strncmp(argv[idx_vendor]->arg, "i", 1) == 0) | |
2011 | abr_type = OSPF_ABR_IBM; | |
2012 | else if (strncmp(argv[idx_vendor]->arg, "sh", 2) == 0) | |
2013 | abr_type = OSPF_ABR_SHORTCUT; | |
2014 | else if (strncmp(argv[idx_vendor]->arg, "st", 2) == 0) | |
2015 | abr_type = OSPF_ABR_STAND; | |
2016 | else | |
2017 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 2018 | |
d62a17ae | 2019 | /* If ABR type value is changed, schedule ABR task. */ |
2020 | if (ospf->abr_type == abr_type) { | |
2021 | ospf->abr_type = OSPF_ABR_DEFAULT; | |
2022 | ospf_schedule_abr_task(ospf); | |
2023 | } | |
2024 | ||
2025 | return CMD_SUCCESS; | |
718e3744 | 2026 | } |
2027 | ||
d7e60dd7 AS |
2028 | DEFUN (ospf_log_adjacency_changes, |
2029 | ospf_log_adjacency_changes_cmd, | |
2030 | "log-adjacency-changes", | |
2031 | "Log changes in adjacency state\n") | |
2032 | { | |
a3d826f0 | 2033 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d7e60dd7 | 2034 | |
d62a17ae | 2035 | SET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES); |
2036 | UNSET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL); | |
2037 | return CMD_SUCCESS; | |
d7e60dd7 AS |
2038 | } |
2039 | ||
2040 | DEFUN (ospf_log_adjacency_changes_detail, | |
2041 | ospf_log_adjacency_changes_detail_cmd, | |
2042 | "log-adjacency-changes detail", | |
2043 | "Log changes in adjacency state\n" | |
2044 | "Log all state changes\n") | |
2045 | { | |
a3d826f0 | 2046 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d7e60dd7 | 2047 | |
d62a17ae | 2048 | SET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES); |
2049 | SET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL); | |
2050 | return CMD_SUCCESS; | |
d7e60dd7 AS |
2051 | } |
2052 | ||
2053 | DEFUN (no_ospf_log_adjacency_changes, | |
2054 | no_ospf_log_adjacency_changes_cmd, | |
2055 | "no log-adjacency-changes", | |
2056 | NO_STR | |
2057 | "Log changes in adjacency state\n") | |
2058 | { | |
a3d826f0 | 2059 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d7e60dd7 | 2060 | |
d62a17ae | 2061 | UNSET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL); |
2062 | UNSET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES); | |
2063 | return CMD_SUCCESS; | |
d7e60dd7 AS |
2064 | } |
2065 | ||
2066 | DEFUN (no_ospf_log_adjacency_changes_detail, | |
2067 | no_ospf_log_adjacency_changes_detail_cmd, | |
2068 | "no log-adjacency-changes detail", | |
2069 | NO_STR | |
2070 | "Log changes in adjacency state\n" | |
2071 | "Log all state changes\n") | |
2072 | { | |
a3d826f0 | 2073 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d7e60dd7 | 2074 | |
d62a17ae | 2075 | UNSET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL); |
2076 | return CMD_SUCCESS; | |
d7e60dd7 AS |
2077 | } |
2078 | ||
718e3744 | 2079 | DEFUN (ospf_compatible_rfc1583, |
2080 | ospf_compatible_rfc1583_cmd, | |
2081 | "compatible rfc1583", | |
2082 | "OSPF compatibility list\n" | |
2083 | "compatible with RFC 1583\n") | |
2084 | { | |
a3d826f0 | 2085 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
718e3744 | 2086 | |
d62a17ae | 2087 | if (!CHECK_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE)) { |
2088 | SET_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE); | |
2089 | ospf_spf_calculate_schedule(ospf, SPF_FLAG_CONFIG_CHANGE); | |
2090 | } | |
2091 | return CMD_SUCCESS; | |
718e3744 | 2092 | } |
2093 | ||
2094 | DEFUN (no_ospf_compatible_rfc1583, | |
2095 | no_ospf_compatible_rfc1583_cmd, | |
2096 | "no compatible rfc1583", | |
2097 | NO_STR | |
2098 | "OSPF compatibility list\n" | |
2099 | "compatible with RFC 1583\n") | |
2100 | { | |
a3d826f0 | 2101 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
718e3744 | 2102 | |
d62a17ae | 2103 | if (CHECK_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE)) { |
2104 | UNSET_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE); | |
2105 | ospf_spf_calculate_schedule(ospf, SPF_FLAG_CONFIG_CHANGE); | |
2106 | } | |
2107 | return CMD_SUCCESS; | |
718e3744 | 2108 | } |
2109 | ||
d62a17ae | 2110 | ALIAS(ospf_compatible_rfc1583, ospf_rfc1583_flag_cmd, |
2111 | "ospf rfc1583compatibility", | |
2112 | "OSPF specific commands\n" | |
2113 | "Enable the RFC1583Compatibility flag\n") | |
718e3744 | 2114 | |
d62a17ae | 2115 | ALIAS(no_ospf_compatible_rfc1583, no_ospf_rfc1583_flag_cmd, |
9d303b37 | 2116 | "no ospf rfc1583compatibility", NO_STR |
d62a17ae | 2117 | "OSPF specific commands\n" |
2118 | "Disable the RFC1583Compatibility flag\n") | |
6b0655a2 | 2119 | |
d62a17ae | 2120 | static int ospf_timers_spf_set(struct vty *vty, unsigned int delay, |
2121 | unsigned int hold, unsigned int max) | |
d24f6e2a | 2122 | { |
a3d826f0 | 2123 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
7c8ff89e | 2124 | |
d62a17ae | 2125 | ospf->spf_delay = delay; |
2126 | ospf->spf_holdtime = hold; | |
2127 | ospf->spf_max_holdtime = max; | |
2128 | ||
2129 | return CMD_SUCCESS; | |
d24f6e2a | 2130 | } |
718e3744 | 2131 | |
ac7424f9 MR |
2132 | DEFUN (ospf_timers_min_ls_interval, |
2133 | ospf_timers_min_ls_interval_cmd, | |
6147e2c6 | 2134 | "timers throttle lsa all (0-5000)", |
ac7424f9 MR |
2135 | "Adjust routing timers\n" |
2136 | "Throttling adaptive timer\n" | |
2137 | "LSA delay between transmissions\n" | |
813d4307 | 2138 | "All LSA types\n" |
ac7424f9 MR |
2139 | "Delay (msec) between sending LSAs\n") |
2140 | { | |
a3d826f0 | 2141 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2142 | int idx_number = 4; |
2143 | unsigned int interval; | |
ac7424f9 | 2144 | |
d62a17ae | 2145 | if (argc < 5) { |
2146 | vty_out(vty, "Insufficient arguments\n"); | |
2147 | return CMD_WARNING_CONFIG_FAILED; | |
2148 | } | |
ac7424f9 | 2149 | |
d62a17ae | 2150 | interval = strtoul(argv[idx_number]->arg, NULL, 10); |
ac7424f9 | 2151 | |
d62a17ae | 2152 | ospf->min_ls_interval = interval; |
ac7424f9 | 2153 | |
d62a17ae | 2154 | return CMD_SUCCESS; |
ac7424f9 MR |
2155 | } |
2156 | ||
2157 | DEFUN (no_ospf_timers_min_ls_interval, | |
2158 | no_ospf_timers_min_ls_interval_cmd, | |
7a7be519 | 2159 | "no timers throttle lsa all [(0-5000)]", |
ac7424f9 MR |
2160 | NO_STR |
2161 | "Adjust routing timers\n" | |
2162 | "Throttling adaptive timer\n" | |
813d4307 | 2163 | "LSA delay between transmissions\n" |
7a7be519 | 2164 | "All LSA types\n" |
2165 | "Delay (msec) between sending LSAs\n") | |
ac7424f9 | 2166 | { |
a3d826f0 | 2167 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2168 | ospf->min_ls_interval = OSPF_MIN_LS_INTERVAL; |
ac7424f9 | 2169 | |
d62a17ae | 2170 | return CMD_SUCCESS; |
ac7424f9 MR |
2171 | } |
2172 | ||
d24f6e2a | 2173 | DEFUN (ospf_timers_throttle_spf, |
2174 | ospf_timers_throttle_spf_cmd, | |
6147e2c6 | 2175 | "timers throttle spf (0-600000) (0-600000) (0-600000)", |
d24f6e2a | 2176 | "Adjust routing timers\n" |
2177 | "Throttling adaptive timer\n" | |
2178 | "OSPF SPF timers\n" | |
2179 | "Delay (msec) from first change received till SPF calculation\n" | |
2180 | "Initial hold time (msec) between consecutive SPF calculations\n" | |
2181 | "Maximum hold time (msec)\n") | |
2182 | { | |
d62a17ae | 2183 | int idx_number = 3; |
2184 | int idx_number_2 = 4; | |
2185 | int idx_number_3 = 5; | |
2186 | unsigned int delay, hold, max; | |
2187 | ||
2188 | if (argc < 6) { | |
2189 | vty_out(vty, "Insufficient arguments\n"); | |
2190 | return CMD_WARNING_CONFIG_FAILED; | |
2191 | } | |
2192 | ||
2193 | delay = strtoul(argv[idx_number]->arg, NULL, 10); | |
2194 | hold = strtoul(argv[idx_number_2]->arg, NULL, 10); | |
2195 | max = strtoul(argv[idx_number_3]->arg, NULL, 10); | |
2196 | ||
2197 | return ospf_timers_spf_set(vty, delay, hold, max); | |
d24f6e2a | 2198 | } |
2199 | ||
d24f6e2a | 2200 | DEFUN (no_ospf_timers_throttle_spf, |
2201 | no_ospf_timers_throttle_spf_cmd, | |
7a7be519 | 2202 | "no timers throttle spf [(0-600000)(0-600000)(0-600000)]", |
718e3744 | 2203 | NO_STR |
2204 | "Adjust routing timers\n" | |
d24f6e2a | 2205 | "Throttling adaptive timer\n" |
7a7be519 | 2206 | "OSPF SPF timers\n" |
2207 | "Delay (msec) from first change received till SPF calculation\n" | |
2208 | "Initial hold time (msec) between consecutive SPF calculations\n" | |
2209 | "Maximum hold time (msec)\n") | |
22b27e95 | 2210 | { |
d62a17ae | 2211 | return ospf_timers_spf_set(vty, OSPF_SPF_DELAY_DEFAULT, |
2212 | OSPF_SPF_HOLDTIME_DEFAULT, | |
2213 | OSPF_SPF_MAX_HOLDTIME_DEFAULT); | |
718e3744 | 2214 | } |
2215 | ||
b4a039bf | 2216 | |
0e88de35 QY |
2217 | DEFUN (ospf_timers_lsa_min_arrival, |
2218 | ospf_timers_lsa_min_arrival_cmd, | |
6147e2c6 | 2219 | "timers lsa min-arrival (0-600000)", |
b6927875 DS |
2220 | "Adjust routing timers\n" |
2221 | "OSPF LSA timers\n" | |
2222 | "Minimum delay in receiving new version of a LSA\n" | |
2223 | "Delay in milliseconds\n") | |
2224 | { | |
a3d826f0 | 2225 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
0e88de35 | 2226 | ospf->min_ls_arrival = strtoul(argv[argc - 1]->arg, NULL, 10); |
d62a17ae | 2227 | return CMD_SUCCESS; |
b6927875 DS |
2228 | } |
2229 | ||
0e88de35 QY |
2230 | DEFUN (no_ospf_timers_lsa_min_arrival, |
2231 | no_ospf_timers_lsa_min_arrival_cmd, | |
7a7be519 | 2232 | "no timers lsa min-arrival [(0-600000)]", |
b6927875 DS |
2233 | NO_STR |
2234 | "Adjust routing timers\n" | |
2235 | "OSPF LSA timers\n" | |
7a7be519 | 2236 | "Minimum delay in receiving new version of a LSA\n" |
2237 | "Delay in milliseconds\n") | |
b6927875 | 2238 | { |
a3d826f0 | 2239 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2240 | unsigned int minarrival; |
b6927875 | 2241 | |
d62a17ae | 2242 | if (argc > 4) { |
0e88de35 | 2243 | minarrival = strtoul(argv[argc - 1]->arg, NULL, 10); |
b6927875 | 2244 | |
d62a17ae | 2245 | if (ospf->min_ls_arrival != minarrival |
2246 | || minarrival == OSPF_MIN_LS_ARRIVAL) | |
2247 | return CMD_SUCCESS; | |
2248 | } | |
b6927875 | 2249 | |
d62a17ae | 2250 | ospf->min_ls_arrival = OSPF_MIN_LS_ARRIVAL; |
b6927875 | 2251 | |
d62a17ae | 2252 | return CMD_SUCCESS; |
b6927875 DS |
2253 | } |
2254 | ||
5d1a2ee8 QY |
2255 | #if CONFDATE > 20180708 |
2256 | CPP_NOTICE("ospf: `timers lsa arrival (0-1000)` deprecated 2017/07/08") | |
2257 | #endif | |
0e88de35 QY |
2258 | ALIAS_HIDDEN (ospf_timers_lsa_min_arrival, |
2259 | ospf_timers_lsa_arrival_cmd, | |
2260 | "timers lsa arrival (0-1000)", | |
2261 | "adjust routing timers\n" | |
2262 | "throttling link state advertisement delays\n" | |
2263 | "ospf minimum arrival interval delay\n" | |
2264 | "delay (msec) between accepted lsas\n"); | |
2265 | ||
5d1a2ee8 QY |
2266 | #if CONFDATE > 20180708 |
2267 | CPP_NOTICE("ospf: `no timers lsa arrival (0-1000)` deprecated 2017/07/08") | |
2268 | #endif | |
0e88de35 QY |
2269 | ALIAS_HIDDEN (no_ospf_timers_lsa_min_arrival, |
2270 | no_ospf_timers_lsa_arrival_cmd, | |
2271 | "no timers lsa arrival (0-1000)", | |
2272 | NO_STR | |
2273 | "adjust routing timers\n" | |
2274 | "throttling link state advertisement delays\n" | |
2275 | "ospf minimum arrival interval delay\n" | |
2276 | "delay (msec) between accepted lsas\n"); | |
2277 | ||
2278 | ||
a2c62831 | 2279 | DEFUN (ospf_neighbor, |
2280 | ospf_neighbor_cmd, | |
7a7be519 | 2281 | "neighbor A.B.C.D [priority (0-255) [poll-interval (1-65535)]]", |
718e3744 | 2282 | NEIGHBOR_STR |
7a7be519 | 2283 | "Neighbor IP address\n" |
2284 | "Neighbor Priority\n" | |
2285 | "Priority\n" | |
2286 | "Dead Neighbor Polling interval\n" | |
2287 | "Seconds\n") | |
718e3744 | 2288 | { |
a3d826f0 | 2289 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2290 | int idx_ipv4 = 1; |
2291 | int idx_pri = 3; | |
2292 | int idx_poll = 5; | |
2293 | struct in_addr nbr_addr; | |
2294 | unsigned int priority = OSPF_NEIGHBOR_PRIORITY_DEFAULT; | |
2295 | unsigned int interval = OSPF_POLL_INTERVAL_DEFAULT; | |
718e3744 | 2296 | |
cc9b06ad DS |
2297 | if (!inet_aton(argv[idx_ipv4]->arg, &nbr_addr)) { |
2298 | vty_out(vty, "Please specify Neighbor ID by A.B.C.D\n"); | |
2299 | return CMD_WARNING_CONFIG_FAILED; | |
2300 | } | |
718e3744 | 2301 | |
d62a17ae | 2302 | if (argc > 2) |
2303 | priority = strtoul(argv[idx_pri]->arg, NULL, 10); | |
7a7be519 | 2304 | |
d62a17ae | 2305 | if (argc > 4) |
2306 | interval = strtoul(argv[idx_poll]->arg, NULL, 10); | |
718e3744 | 2307 | |
d62a17ae | 2308 | ospf_nbr_nbma_set(ospf, nbr_addr); |
7a7be519 | 2309 | |
d62a17ae | 2310 | if (argc > 2) |
2311 | ospf_nbr_nbma_priority_set(ospf, nbr_addr, priority); | |
7a7be519 | 2312 | |
d62a17ae | 2313 | if (argc > 4) |
2314 | ospf_nbr_nbma_poll_interval_set(ospf, nbr_addr, interval); | |
718e3744 | 2315 | |
d62a17ae | 2316 | return CMD_SUCCESS; |
718e3744 | 2317 | } |
2318 | ||
a2c62831 | 2319 | DEFUN (ospf_neighbor_poll_interval, |
2320 | ospf_neighbor_poll_interval_cmd, | |
7a7be519 | 2321 | "neighbor A.B.C.D poll-interval (1-65535) [priority (0-255)]", |
718e3744 | 2322 | NEIGHBOR_STR |
2323 | "Neighbor IP address\n" | |
2324 | "Dead Neighbor Polling interval\n" | |
7a7be519 | 2325 | "Seconds\n" |
2326 | "OSPF priority of non-broadcast neighbor\n" | |
2327 | "Priority\n") | |
22b27e95 | 2328 | { |
a3d826f0 | 2329 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2330 | int idx_ipv4 = 1; |
2331 | int idx_poll = 3; | |
2332 | int idx_pri = 5; | |
2333 | struct in_addr nbr_addr; | |
2334 | unsigned int priority = OSPF_NEIGHBOR_PRIORITY_DEFAULT; | |
2335 | unsigned int interval = OSPF_POLL_INTERVAL_DEFAULT; | |
718e3744 | 2336 | |
cc9b06ad DS |
2337 | if (!inet_aton(argv[idx_ipv4]->arg, &nbr_addr)) { |
2338 | vty_out(vty, "Please specify Neighbor ID by A.B.C.D\n"); | |
2339 | return CMD_WARNING_CONFIG_FAILED; | |
2340 | } | |
718e3744 | 2341 | |
d62a17ae | 2342 | interval = strtoul(argv[idx_poll]->arg, NULL, 10); |
718e3744 | 2343 | |
d62a17ae | 2344 | if (argc > 4) |
2345 | priority = strtoul(argv[idx_pri]->arg, NULL, 10); | |
718e3744 | 2346 | |
d62a17ae | 2347 | ospf_nbr_nbma_set(ospf, nbr_addr); |
2348 | ospf_nbr_nbma_poll_interval_set(ospf, nbr_addr, interval); | |
7a7be519 | 2349 | |
d62a17ae | 2350 | if (argc > 4) |
2351 | ospf_nbr_nbma_priority_set(ospf, nbr_addr, priority); | |
718e3744 | 2352 | |
d62a17ae | 2353 | return CMD_SUCCESS; |
718e3744 | 2354 | } |
2355 | ||
a2c62831 | 2356 | DEFUN (no_ospf_neighbor, |
2357 | no_ospf_neighbor_cmd, | |
7a7be519 | 2358 | "no neighbor A.B.C.D [priority (0-255) [poll-interval (1-65525)]]", |
718e3744 | 2359 | NO_STR |
2360 | NEIGHBOR_STR | |
7a7be519 | 2361 | "Neighbor IP address\n" |
2362 | "Neighbor Priority\n" | |
2363 | "Priority\n" | |
2364 | "Dead Neighbor Polling interval\n" | |
2365 | "Seconds\n") | |
718e3744 | 2366 | { |
a3d826f0 | 2367 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2368 | int idx_ipv4 = 2; |
2369 | struct in_addr nbr_addr; | |
718e3744 | 2370 | |
cc9b06ad DS |
2371 | if (!inet_aton(argv[idx_ipv4]->arg, &nbr_addr)) { |
2372 | vty_out(vty, "Please specify Neighbor ID by A.B.C.D\n"); | |
2373 | return CMD_WARNING_CONFIG_FAILED; | |
2374 | } | |
718e3744 | 2375 | |
d62a17ae | 2376 | (void)ospf_nbr_nbma_unset(ospf, nbr_addr); |
718e3744 | 2377 | |
d62a17ae | 2378 | return CMD_SUCCESS; |
718e3744 | 2379 | } |
2380 | ||
7a7be519 | 2381 | DEFUN (no_ospf_neighbor_poll, |
2382 | no_ospf_neighbor_poll_cmd, | |
2383 | "no neighbor A.B.C.D poll-interval (1-65535) [priority (0-255)]", | |
2384 | NO_STR | |
2385 | NEIGHBOR_STR | |
2386 | "Neighbor IP address\n" | |
2387 | "Dead Neighbor Polling interval\n" | |
2388 | "Seconds\n" | |
2389 | "Neighbor Priority\n" | |
2390 | "Priority\n") | |
2391 | { | |
a3d826f0 | 2392 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2393 | int idx_ipv4 = 2; |
2394 | struct in_addr nbr_addr; | |
7a7be519 | 2395 | |
cc9b06ad DS |
2396 | if (!inet_aton(argv[idx_ipv4]->arg, &nbr_addr)) { |
2397 | vty_out(vty, "Please specify Neighbor ID by A.B.C.D\n"); | |
2398 | return CMD_WARNING_CONFIG_FAILED; | |
2399 | } | |
718e3744 | 2400 | |
d62a17ae | 2401 | (void)ospf_nbr_nbma_unset(ospf, nbr_addr); |
813d4307 | 2402 | |
d62a17ae | 2403 | return CMD_SUCCESS; |
7a7be519 | 2404 | } |
718e3744 | 2405 | |
bf2bfafd DW |
2406 | DEFUN (ospf_refresh_timer, |
2407 | ospf_refresh_timer_cmd, | |
6147e2c6 | 2408 | "refresh timer (10-1800)", |
718e3744 | 2409 | "Adjust refresh parameters\n" |
2410 | "Set refresh timer\n" | |
2411 | "Timer value in seconds\n") | |
2412 | { | |
a3d826f0 | 2413 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2414 | int idx_number = 2; |
2415 | unsigned int interval; | |
7c8ff89e | 2416 | |
d62a17ae | 2417 | interval = strtoul(argv[idx_number]->arg, NULL, 10); |
2418 | interval = (interval / OSPF_LSA_REFRESHER_GRANULARITY) | |
2419 | * OSPF_LSA_REFRESHER_GRANULARITY; | |
718e3744 | 2420 | |
d62a17ae | 2421 | ospf_timers_refresh_set(ospf, interval); |
718e3744 | 2422 | |
d62a17ae | 2423 | return CMD_SUCCESS; |
718e3744 | 2424 | } |
2425 | ||
bf2bfafd DW |
2426 | DEFUN (no_ospf_refresh_timer, |
2427 | no_ospf_refresh_timer_val_cmd, | |
7a7be519 | 2428 | "no refresh timer [(10-1800)]", |
3a2d747c | 2429 | NO_STR |
718e3744 | 2430 | "Adjust refresh parameters\n" |
2431 | "Unset refresh timer\n" | |
2432 | "Timer value in seconds\n") | |
2433 | { | |
a3d826f0 | 2434 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2435 | int idx_number = 3; |
2436 | unsigned int interval; | |
718e3744 | 2437 | |
d62a17ae | 2438 | if (argc == 1) { |
2439 | interval = strtoul(argv[idx_number]->arg, NULL, 10); | |
718e3744 | 2440 | |
d62a17ae | 2441 | if (ospf->lsa_refresh_interval != interval |
2442 | || interval == OSPF_LSA_REFRESH_INTERVAL_DEFAULT) | |
2443 | return CMD_SUCCESS; | |
2444 | } | |
2445 | ||
2446 | ospf_timers_refresh_unset(ospf); | |
2447 | ||
2448 | return CMD_SUCCESS; | |
718e3744 | 2449 | } |
2450 | ||
718e3744 | 2451 | |
a2c62831 | 2452 | DEFUN (ospf_auto_cost_reference_bandwidth, |
2453 | ospf_auto_cost_reference_bandwidth_cmd, | |
6147e2c6 | 2454 | "auto-cost reference-bandwidth (1-4294967)", |
718e3744 | 2455 | "Calculate OSPF interface cost according to bandwidth\n" |
2456 | "Use reference bandwidth method to assign OSPF cost\n" | |
2457 | "The reference bandwidth in terms of Mbits per second\n") | |
2458 | { | |
a3d826f0 | 2459 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2460 | int idx_number = 2; |
2461 | u_int32_t refbw; | |
2462 | struct listnode *node; | |
2463 | struct interface *ifp; | |
2464 | ||
2465 | refbw = strtol(argv[idx_number]->arg, NULL, 10); | |
2466 | if (refbw < 1 || refbw > 4294967) { | |
2467 | vty_out(vty, "reference-bandwidth value is invalid\n"); | |
2468 | return CMD_WARNING_CONFIG_FAILED; | |
2469 | } | |
2470 | ||
2471 | /* If reference bandwidth is changed. */ | |
2472 | if ((refbw) == ospf->ref_bandwidth) | |
2473 | return CMD_SUCCESS; | |
2474 | ||
2475 | ospf->ref_bandwidth = refbw; | |
b5a8894d | 2476 | for (ALL_LIST_ELEMENTS_RO(vrf_iflist(ospf->vrf_id), node, ifp)) |
d62a17ae | 2477 | ospf_if_recalculate_output_cost(ifp); |
2478 | ||
2479 | return CMD_SUCCESS; | |
718e3744 | 2480 | } |
2481 | ||
a2c62831 | 2482 | DEFUN (no_ospf_auto_cost_reference_bandwidth, |
2483 | no_ospf_auto_cost_reference_bandwidth_cmd, | |
7a7be519 | 2484 | "no auto-cost reference-bandwidth [(1-4294967)]", |
718e3744 | 2485 | NO_STR |
2486 | "Calculate OSPF interface cost according to bandwidth\n" | |
7a7be519 | 2487 | "Use reference bandwidth method to assign OSPF cost\n" |
2488 | "The reference bandwidth in terms of Mbits per second\n") | |
718e3744 | 2489 | { |
a3d826f0 | 2490 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2491 | struct listnode *node, *nnode; |
2492 | struct interface *ifp; | |
718e3744 | 2493 | |
d62a17ae | 2494 | if (ospf->ref_bandwidth == OSPF_DEFAULT_REF_BANDWIDTH) |
2495 | return CMD_SUCCESS; | |
2496 | ||
2497 | ospf->ref_bandwidth = OSPF_DEFAULT_REF_BANDWIDTH; | |
2498 | vty_out(vty, "%% OSPF: Reference bandwidth is changed.\n"); | |
2499 | vty_out(vty, | |
2500 | " Please ensure reference bandwidth is consistent across all routers\n"); | |
2501 | ||
b5a8894d | 2502 | for (ALL_LIST_ELEMENTS(vrf_iflist(ospf->vrf_id), node, nnode, ifp)) |
d62a17ae | 2503 | ospf_if_recalculate_output_cost(ifp); |
2504 | ||
2505 | return CMD_SUCCESS; | |
718e3744 | 2506 | } |
2507 | ||
2f8f370e DS |
2508 | DEFUN (ospf_write_multiplier, |
2509 | ospf_write_multiplier_cmd, | |
6147e2c6 | 2510 | "ospf write-multiplier (1-100)", |
e8f45e82 DS |
2511 | "OSPF specific commands\n" |
2512 | "Write multiplier\n" | |
2513 | "Maximum number of interface serviced per write\n") | |
2f8f370e | 2514 | { |
a3d826f0 | 2515 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2516 | int idx_number; |
2517 | u_int32_t write_oi_count; | |
2518 | ||
2519 | if (argc == 3) | |
2520 | idx_number = 2; | |
2521 | else | |
2522 | idx_number = 1; | |
2523 | ||
2524 | write_oi_count = strtol(argv[idx_number]->arg, NULL, 10); | |
2525 | if (write_oi_count < 1 || write_oi_count > 100) { | |
2526 | vty_out(vty, "write-multiplier value is invalid\n"); | |
2527 | return CMD_WARNING_CONFIG_FAILED; | |
2528 | } | |
2529 | ||
2530 | ospf->write_oi_count = write_oi_count; | |
2531 | return CMD_SUCCESS; | |
2f8f370e DS |
2532 | } |
2533 | ||
d62a17ae | 2534 | ALIAS(ospf_write_multiplier, write_multiplier_cmd, "write-multiplier (1-100)", |
2535 | "Write multiplier\n" | |
2536 | "Maximum number of interface serviced per write\n") | |
e8f45e82 | 2537 | |
2f8f370e DS |
2538 | DEFUN (no_ospf_write_multiplier, |
2539 | no_ospf_write_multiplier_cmd, | |
6147e2c6 | 2540 | "no ospf write-multiplier (1-100)", |
2f8f370e | 2541 | NO_STR |
e8f45e82 | 2542 | "OSPF specific commands\n" |
813d4307 DW |
2543 | "Write multiplier\n" |
2544 | "Maximum number of interface serviced per write\n") | |
2f8f370e | 2545 | { |
a3d826f0 | 2546 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
2f8f370e | 2547 | |
d62a17ae | 2548 | ospf->write_oi_count = OSPF_WRITE_INTERFACE_COUNT_DEFAULT; |
2549 | return CMD_SUCCESS; | |
2f8f370e DS |
2550 | } |
2551 | ||
d62a17ae | 2552 | ALIAS(no_ospf_write_multiplier, no_write_multiplier_cmd, |
9d303b37 | 2553 | "no write-multiplier (1-100)", NO_STR |
d62a17ae | 2554 | "Write multiplier\n" |
2555 | "Maximum number of interface serviced per write\n") | |
2556 | ||
2557 | const char *ospf_abr_type_descr_str[] = {"Unknown", "Standard (RFC2328)", | |
2558 | "Alternative IBM", "Alternative Cisco", | |
2559 | "Alternative Shortcut"}; | |
2560 | ||
2561 | const char *ospf_shortcut_mode_descr_str[] = {"Default", "Enabled", "Disabled"}; | |
2562 | ||
2563 | static void show_ip_ospf_area(struct vty *vty, struct ospf_area *area, | |
2564 | json_object *json_areas, u_char use_json) | |
2565 | { | |
2566 | json_object *json_area = NULL; | |
2567 | ||
2568 | if (use_json) | |
2569 | json_area = json_object_new_object(); | |
2570 | ||
2571 | /* Show Area ID. */ | |
2572 | if (!use_json) | |
2573 | vty_out(vty, " Area ID: %s", inet_ntoa(area->area_id)); | |
2574 | ||
2575 | /* Show Area type/mode. */ | |
2576 | if (OSPF_IS_AREA_BACKBONE(area)) { | |
2577 | if (use_json) | |
2578 | json_object_boolean_true_add(json_area, "backbone"); | |
2579 | else | |
2580 | vty_out(vty, " (Backbone)\n"); | |
2581 | } else { | |
2582 | if (use_json) { | |
2583 | if (area->external_routing == OSPF_AREA_STUB) { | |
2584 | if (area->no_summary) | |
2585 | json_object_boolean_true_add( | |
2586 | json_area, "stubNoSummary"); | |
2587 | if (area->shortcut_configured) | |
2588 | json_object_boolean_true_add( | |
2589 | json_area, "stubShortcut"); | |
2590 | } else if (area->external_routing == OSPF_AREA_NSSA) { | |
2591 | if (area->no_summary) | |
2592 | json_object_boolean_true_add( | |
2593 | json_area, "nssaNoSummary"); | |
2594 | if (area->shortcut_configured) | |
2595 | json_object_boolean_true_add( | |
2596 | json_area, "nssaShortcut"); | |
2597 | } | |
813d4307 | 2598 | |
d62a17ae | 2599 | json_object_string_add( |
2600 | json_area, "shortcuttingMode", | |
2601 | ospf_shortcut_mode_descr_str | |
2602 | [area->shortcut_configured]); | |
2603 | if (area->shortcut_capability) | |
2604 | json_object_boolean_true_add(json_area, | |
2605 | "sBitConcensus"); | |
2606 | } else { | |
2607 | if (area->external_routing == OSPF_AREA_STUB) | |
2608 | vty_out(vty, " (Stub%s%s)", | |
2609 | area->no_summary ? ", no summary" : "", | |
2610 | area->shortcut_configured ? "; " : ""); | |
2611 | else if (area->external_routing == OSPF_AREA_NSSA) | |
2612 | vty_out(vty, " (NSSA%s%s)", | |
2613 | area->no_summary ? ", no summary" : "", | |
2614 | area->shortcut_configured ? "; " : ""); | |
2615 | ||
2616 | vty_out(vty, "\n"); | |
2617 | vty_out(vty, " Shortcutting mode: %s", | |
2618 | ospf_shortcut_mode_descr_str | |
2619 | [area->shortcut_configured]); | |
2620 | vty_out(vty, ", S-bit consensus: %s\n", | |
2621 | area->shortcut_capability ? "ok" : "no"); | |
2622 | } | |
2623 | } | |
718e3744 | 2624 | |
d62a17ae | 2625 | /* Show number of interfaces */ |
2626 | if (use_json) { | |
2627 | json_object_int_add(json_area, "areaIfTotalCounter", | |
2628 | listcount(area->oiflist)); | |
2629 | json_object_int_add(json_area, "areaIfActiveCounter", | |
2630 | area->act_ints); | |
2631 | } else | |
2632 | vty_out(vty, | |
2633 | " Number of interfaces in this area: Total: %d, " | |
2634 | "Active: %d\n", | |
2635 | listcount(area->oiflist), area->act_ints); | |
2636 | ||
2637 | if (area->external_routing == OSPF_AREA_NSSA) { | |
2638 | if (use_json) { | |
2639 | json_object_boolean_true_add(json_area, "nssa"); | |
2640 | if (!IS_OSPF_ABR(area->ospf)) | |
2641 | json_object_boolean_false_add(json_area, "abr"); | |
2642 | else if (area->NSSATranslatorState) { | |
2643 | json_object_boolean_true_add(json_area, "abr"); | |
2644 | if (area->NSSATranslatorRole | |
2645 | == OSPF_NSSA_ROLE_CANDIDATE) | |
2646 | json_object_boolean_true_add( | |
2647 | json_area, | |
2648 | "nssaTranslatorElected"); | |
2649 | else if (area->NSSATranslatorRole | |
2650 | == OSPF_NSSA_ROLE_ALWAYS) | |
2651 | json_object_boolean_true_add( | |
2652 | json_area, | |
2653 | "nssaTranslatorAlways"); | |
2654 | } else { | |
2655 | json_object_boolean_true_add(json_area, "abr"); | |
2656 | if (area->NSSATranslatorRole | |
2657 | == OSPF_NSSA_ROLE_CANDIDATE) | |
2658 | json_object_boolean_false_add( | |
2659 | json_area, | |
2660 | "nssaTranslatorElected"); | |
2661 | else | |
2662 | json_object_boolean_true_add( | |
2663 | json_area, | |
2664 | "nssaTranslatorNever"); | |
2665 | } | |
2666 | } else { | |
2667 | vty_out(vty, | |
2668 | " It is an NSSA configuration. \n Elected NSSA/ABR performs type-7/type-5 LSA translation. \n"); | |
2669 | if (!IS_OSPF_ABR(area->ospf)) | |
2670 | vty_out(vty, | |
2671 | " It is not ABR, therefore not Translator. \n"); | |
2672 | else if (area->NSSATranslatorState) { | |
2673 | vty_out(vty, " We are an ABR and "); | |
2674 | if (area->NSSATranslatorRole | |
2675 | == OSPF_NSSA_ROLE_CANDIDATE) | |
2676 | vty_out(vty, | |
2677 | "the NSSA Elected Translator. \n"); | |
2678 | else if (area->NSSATranslatorRole | |
2679 | == OSPF_NSSA_ROLE_ALWAYS) | |
2680 | vty_out(vty, | |
2681 | "always an NSSA Translator. \n"); | |
2682 | } else { | |
2683 | vty_out(vty, " We are an ABR, but "); | |
2684 | if (area->NSSATranslatorRole | |
2685 | == OSPF_NSSA_ROLE_CANDIDATE) | |
2686 | vty_out(vty, | |
2687 | "not the NSSA Elected Translator. \n"); | |
2688 | else | |
2689 | vty_out(vty, | |
2690 | "never an NSSA Translator. \n"); | |
2691 | } | |
2692 | } | |
2693 | } | |
2694 | ||
2695 | /* Stub-router state for this area */ | |
2696 | if (CHECK_FLAG(area->stub_router_state, OSPF_AREA_IS_STUB_ROUTED)) { | |
2697 | char timebuf[OSPF_TIME_DUMP_SIZE]; | |
2698 | ||
2699 | if (use_json) { | |
2700 | json_object_boolean_true_add( | |
2701 | json_area, "originStubMaxDistRouterLsa"); | |
2702 | if (CHECK_FLAG(area->stub_router_state, | |
2703 | OSPF_AREA_ADMIN_STUB_ROUTED)) | |
2704 | json_object_boolean_true_add( | |
2705 | json_area, "indefiniteActiveAdmin"); | |
2706 | if (area->t_stub_router) { | |
2707 | long time_store; | |
2708 | time_store = | |
2709 | monotime_until( | |
2710 | &area->t_stub_router->u.sands, | |
2711 | NULL) | |
2712 | / 1000LL; | |
2713 | json_object_int_add( | |
2714 | json_area, | |
2715 | "activeStartupRemainderMsecs", | |
2716 | time_store); | |
2717 | } | |
2718 | } else { | |
2719 | vty_out(vty, | |
2720 | " Originating stub / maximum-distance Router-LSA\n"); | |
2721 | if (CHECK_FLAG(area->stub_router_state, | |
2722 | OSPF_AREA_ADMIN_STUB_ROUTED)) | |
2723 | vty_out(vty, | |
2724 | " Administratively activated (indefinitely)\n"); | |
2725 | if (area->t_stub_router) | |
2726 | vty_out(vty, | |
2727 | " Active from startup, %s remaining\n", | |
2728 | ospf_timer_dump(area->t_stub_router, | |
2729 | timebuf, | |
2730 | sizeof(timebuf))); | |
2731 | } | |
2732 | } | |
2733 | ||
2734 | if (use_json) { | |
2735 | /* Show number of fully adjacent neighbors. */ | |
2736 | json_object_int_add(json_area, "nbrFullAdjacentCounter", | |
2737 | area->full_nbrs); | |
2738 | ||
2739 | /* Show authentication type. */ | |
2740 | if (area->auth_type == OSPF_AUTH_NULL) | |
2741 | json_object_string_add(json_area, "authentication", | |
2742 | "authenticationNone"); | |
2743 | else if (area->auth_type == OSPF_AUTH_SIMPLE) | |
2744 | json_object_string_add(json_area, "authentication", | |
2745 | "authenticationSimplePassword"); | |
2746 | else if (area->auth_type == OSPF_AUTH_CRYPTOGRAPHIC) | |
2747 | json_object_string_add(json_area, "authentication", | |
2748 | "authenticationMessageDigest"); | |
2749 | ||
2750 | if (!OSPF_IS_AREA_BACKBONE(area)) | |
2751 | json_object_int_add(json_area, | |
2752 | "virtualAdjacenciesPassingCounter", | |
2753 | area->full_vls); | |
2754 | ||
2755 | /* Show SPF calculation times. */ | |
2756 | json_object_int_add(json_area, "spfExecutedCounter", | |
2757 | area->spf_calculation); | |
2758 | json_object_int_add(json_area, "lsaNumber", area->lsdb->total); | |
2759 | json_object_int_add( | |
2760 | json_area, "lsaRouterNumber", | |
2761 | ospf_lsdb_count(area->lsdb, OSPF_ROUTER_LSA)); | |
2762 | json_object_int_add( | |
2763 | json_area, "lsaRouterChecksum", | |
2764 | ospf_lsdb_checksum(area->lsdb, OSPF_ROUTER_LSA)); | |
2765 | json_object_int_add( | |
2766 | json_area, "lsaNetworkNumber", | |
2767 | ospf_lsdb_count(area->lsdb, OSPF_NETWORK_LSA)); | |
2768 | json_object_int_add( | |
2769 | json_area, "lsaNetworkChecksum", | |
2770 | ospf_lsdb_checksum(area->lsdb, OSPF_NETWORK_LSA)); | |
2771 | json_object_int_add( | |
2772 | json_area, "lsaSummaryNumber", | |
2773 | ospf_lsdb_count(area->lsdb, OSPF_SUMMARY_LSA)); | |
2774 | json_object_int_add( | |
2775 | json_area, "lsaSummaryChecksum", | |
2776 | ospf_lsdb_checksum(area->lsdb, OSPF_SUMMARY_LSA)); | |
2777 | json_object_int_add( | |
2778 | json_area, "lsaAsbrNumber", | |
2779 | ospf_lsdb_count(area->lsdb, OSPF_ASBR_SUMMARY_LSA)); | |
2780 | json_object_int_add( | |
2781 | json_area, "lsaAsbrChecksum", | |
2782 | ospf_lsdb_checksum(area->lsdb, OSPF_ASBR_SUMMARY_LSA)); | |
2783 | json_object_int_add( | |
2784 | json_area, "lsaNssaNumber", | |
2785 | ospf_lsdb_count(area->lsdb, OSPF_AS_NSSA_LSA)); | |
2786 | json_object_int_add( | |
2787 | json_area, "lsaNssaChecksum", | |
2788 | ospf_lsdb_checksum(area->lsdb, OSPF_AS_NSSA_LSA)); | |
2789 | } else { | |
2790 | /* Show number of fully adjacent neighbors. */ | |
2791 | vty_out(vty, | |
2792 | " Number of fully adjacent neighbors in this area:" | |
2793 | " %d\n", | |
2794 | area->full_nbrs); | |
2795 | ||
2796 | /* Show authentication type. */ | |
2797 | vty_out(vty, " Area has "); | |
2798 | if (area->auth_type == OSPF_AUTH_NULL) | |
2799 | vty_out(vty, "no authentication\n"); | |
2800 | else if (area->auth_type == OSPF_AUTH_SIMPLE) | |
2801 | vty_out(vty, "simple password authentication\n"); | |
2802 | else if (area->auth_type == OSPF_AUTH_CRYPTOGRAPHIC) | |
2803 | vty_out(vty, "message digest authentication\n"); | |
2804 | ||
2805 | if (!OSPF_IS_AREA_BACKBONE(area)) | |
2806 | vty_out(vty, | |
2807 | " Number of full virtual adjacencies going through" | |
2808 | " this area: %d\n", | |
2809 | area->full_vls); | |
2810 | ||
2811 | /* Show SPF calculation times. */ | |
2812 | vty_out(vty, " SPF algorithm executed %d times\n", | |
2813 | area->spf_calculation); | |
2814 | ||
2815 | /* Show number of LSA. */ | |
2816 | vty_out(vty, " Number of LSA %ld\n", area->lsdb->total); | |
2817 | vty_out(vty, | |
2818 | " Number of router LSA %ld. Checksum Sum 0x%08x\n", | |
2819 | ospf_lsdb_count(area->lsdb, OSPF_ROUTER_LSA), | |
2820 | ospf_lsdb_checksum(area->lsdb, OSPF_ROUTER_LSA)); | |
2821 | vty_out(vty, | |
2822 | " Number of network LSA %ld. Checksum Sum 0x%08x\n", | |
2823 | ospf_lsdb_count(area->lsdb, OSPF_NETWORK_LSA), | |
2824 | ospf_lsdb_checksum(area->lsdb, OSPF_NETWORK_LSA)); | |
2825 | vty_out(vty, | |
2826 | " Number of summary LSA %ld. Checksum Sum 0x%08x\n", | |
2827 | ospf_lsdb_count(area->lsdb, OSPF_SUMMARY_LSA), | |
2828 | ospf_lsdb_checksum(area->lsdb, OSPF_SUMMARY_LSA)); | |
2829 | vty_out(vty, | |
2830 | " Number of ASBR summary LSA %ld. Checksum Sum 0x%08x\n", | |
2831 | ospf_lsdb_count(area->lsdb, OSPF_ASBR_SUMMARY_LSA), | |
2832 | ospf_lsdb_checksum(area->lsdb, OSPF_ASBR_SUMMARY_LSA)); | |
2833 | vty_out(vty, " Number of NSSA LSA %ld. Checksum Sum 0x%08x\n", | |
2834 | ospf_lsdb_count(area->lsdb, OSPF_AS_NSSA_LSA), | |
2835 | ospf_lsdb_checksum(area->lsdb, OSPF_AS_NSSA_LSA)); | |
2836 | } | |
2837 | ||
2838 | if (use_json) { | |
2839 | json_object_int_add( | |
2840 | json_area, "lsaOpaqueLinkNumber", | |
2841 | ospf_lsdb_count(area->lsdb, OSPF_OPAQUE_LINK_LSA)); | |
2842 | json_object_int_add( | |
2843 | json_area, "lsaOpaqueLinkChecksum", | |
2844 | ospf_lsdb_checksum(area->lsdb, OSPF_OPAQUE_LINK_LSA)); | |
2845 | json_object_int_add( | |
2846 | json_area, "lsaOpaqueAreaNumber", | |
2847 | ospf_lsdb_count(area->lsdb, OSPF_OPAQUE_AREA_LSA)); | |
2848 | json_object_int_add( | |
2849 | json_area, "lsaOpaqueAreaChecksum", | |
2850 | ospf_lsdb_checksum(area->lsdb, OSPF_OPAQUE_AREA_LSA)); | |
2851 | } else { | |
2852 | vty_out(vty, | |
2853 | " Number of opaque link LSA %ld. Checksum Sum 0x%08x\n", | |
2854 | ospf_lsdb_count(area->lsdb, OSPF_OPAQUE_LINK_LSA), | |
2855 | ospf_lsdb_checksum(area->lsdb, OSPF_OPAQUE_LINK_LSA)); | |
2856 | vty_out(vty, | |
2857 | " Number of opaque area LSA %ld. Checksum Sum 0x%08x\n", | |
2858 | ospf_lsdb_count(area->lsdb, OSPF_OPAQUE_AREA_LSA), | |
2859 | ospf_lsdb_checksum(area->lsdb, OSPF_OPAQUE_AREA_LSA)); | |
2860 | } | |
718e3744 | 2861 | |
d62a17ae | 2862 | if (use_json) |
2863 | json_object_object_add(json_areas, inet_ntoa(area->area_id), | |
2864 | json_area); | |
2865 | else | |
2866 | vty_out(vty, "\n"); | |
718e3744 | 2867 | } |
2868 | ||
d62a17ae | 2869 | static int show_ip_ospf_common(struct vty *vty, struct ospf *ospf, |
2870 | u_char use_json) | |
2871 | { | |
2872 | struct listnode *node, *nnode; | |
2873 | struct ospf_area *area; | |
2874 | struct timeval result; | |
2875 | char timebuf[OSPF_TIME_DUMP_SIZE]; | |
2876 | json_object *json = NULL; | |
2877 | json_object *json_areas = NULL; | |
718e3744 | 2878 | |
d62a17ae | 2879 | if (use_json) { |
2880 | json = json_object_new_object(); | |
2881 | json_areas = json_object_new_object(); | |
2882 | } | |
2883 | ||
2884 | if (ospf->instance) { | |
2885 | if (use_json) { | |
2886 | json_object_int_add(json, "ospfInstance", | |
2887 | ospf->instance); | |
2888 | } else { | |
2889 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
2890 | } | |
2891 | } | |
2892 | ||
2893 | /* Show Router ID. */ | |
2894 | if (use_json) { | |
2895 | json_object_string_add(json, "routerId", | |
2896 | inet_ntoa(ospf->router_id)); | |
2897 | } else { | |
2898 | vty_out(vty, " OSPF Routing Process, Router ID: %s\n", | |
2899 | inet_ntoa(ospf->router_id)); | |
2900 | } | |
2901 | ||
2902 | /* Graceful shutdown */ | |
2903 | if (ospf->t_deferred_shutdown) { | |
2904 | if (use_json) { | |
2905 | long time_store; | |
2906 | time_store = | |
2907 | monotime_until( | |
2908 | &ospf->t_deferred_shutdown->u.sands, | |
2909 | NULL) | |
2910 | / 1000LL; | |
2911 | json_object_int_add(json, "deferredShutdownMsecs", | |
2912 | time_store); | |
2913 | } else { | |
2914 | vty_out(vty, | |
2915 | " Deferred shutdown in progress, %s remaining\n", | |
2916 | ospf_timer_dump(ospf->t_deferred_shutdown, | |
2917 | timebuf, sizeof(timebuf))); | |
2918 | } | |
2919 | } | |
2920 | ||
2921 | /* Show capability. */ | |
2922 | if (use_json) { | |
2923 | json_object_boolean_true_add(json, "tosRoutesOnly"); | |
2924 | json_object_boolean_true_add(json, "rfc2328Conform"); | |
2925 | if (CHECK_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE)) { | |
2926 | json_object_boolean_true_add(json, | |
2927 | "rfc1583Compatibility"); | |
2928 | } | |
2929 | } else { | |
2930 | vty_out(vty, " Supports only single TOS (TOS0) routes\n"); | |
2931 | vty_out(vty, " This implementation conforms to RFC2328\n"); | |
2932 | vty_out(vty, " RFC1583Compatibility flag is %s\n", | |
2933 | CHECK_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE) | |
2934 | ? "enabled" | |
2935 | : "disabled"); | |
2936 | } | |
2937 | ||
2938 | if (use_json) { | |
2939 | if (CHECK_FLAG(ospf->config, OSPF_OPAQUE_CAPABLE)) { | |
2940 | json_object_boolean_true_add(json, "opaqueCapable"); | |
2941 | } | |
2942 | } else { | |
2943 | vty_out(vty, " OpaqueCapability flag is %s\n", | |
2944 | CHECK_FLAG(ospf->config, OSPF_OPAQUE_CAPABLE) | |
2945 | ? "enabled" | |
2946 | : "disabled"); | |
2947 | } | |
2948 | ||
2949 | /* Show stub-router configuration */ | |
2950 | if (ospf->stub_router_startup_time != OSPF_STUB_ROUTER_UNCONFIGURED | |
2951 | || ospf->stub_router_shutdown_time | |
2952 | != OSPF_STUB_ROUTER_UNCONFIGURED) { | |
2953 | if (use_json) { | |
2954 | json_object_boolean_true_add(json, "stubAdvertisement"); | |
2955 | if (ospf->stub_router_startup_time | |
2956 | != OSPF_STUB_ROUTER_UNCONFIGURED) | |
2957 | json_object_int_add( | |
2958 | json, "postStartEnabledMsecs", | |
2959 | ospf->stub_router_startup_time / 1000); | |
2960 | if (ospf->stub_router_shutdown_time | |
2961 | != OSPF_STUB_ROUTER_UNCONFIGURED) | |
2962 | json_object_int_add( | |
2963 | json, "preShutdownEnabledMsecs", | |
2964 | ospf->stub_router_shutdown_time / 1000); | |
2965 | } else { | |
2966 | vty_out(vty, | |
2967 | " Stub router advertisement is configured\n"); | |
2968 | if (ospf->stub_router_startup_time | |
2969 | != OSPF_STUB_ROUTER_UNCONFIGURED) | |
2970 | vty_out(vty, | |
2971 | " Enabled for %us after start-up\n", | |
2972 | ospf->stub_router_startup_time); | |
2973 | if (ospf->stub_router_shutdown_time | |
2974 | != OSPF_STUB_ROUTER_UNCONFIGURED) | |
2975 | vty_out(vty, | |
2976 | " Enabled for %us prior to full shutdown\n", | |
2977 | ospf->stub_router_shutdown_time); | |
2978 | } | |
2979 | } | |
2980 | ||
2981 | /* Show SPF timers. */ | |
2982 | if (use_json) { | |
2983 | json_object_int_add(json, "spfScheduleDelayMsecs", | |
2984 | ospf->spf_delay); | |
2985 | json_object_int_add(json, "holdtimeMinMsecs", | |
2986 | ospf->spf_holdtime); | |
2987 | json_object_int_add(json, "holdtimeMaxMsecs", | |
2988 | ospf->spf_max_holdtime); | |
2989 | json_object_int_add(json, "holdtimeMultplier", | |
2990 | ospf->spf_hold_multiplier); | |
2991 | } else { | |
2992 | vty_out(vty, | |
2993 | " Initial SPF scheduling delay %d millisec(s)\n" | |
2994 | " Minimum hold time between consecutive SPFs %d millisec(s)\n" | |
2995 | " Maximum hold time between consecutive SPFs %d millisec(s)\n" | |
2996 | " Hold time multiplier is currently %d\n", | |
2997 | ospf->spf_delay, ospf->spf_holdtime, | |
2998 | ospf->spf_max_holdtime, ospf->spf_hold_multiplier); | |
2999 | } | |
3000 | ||
3001 | if (use_json) { | |
3002 | if (ospf->ts_spf.tv_sec || ospf->ts_spf.tv_usec) { | |
3003 | long time_store = 0; | |
3004 | ||
3005 | time_store = | |
3006 | monotime_since(&ospf->ts_spf, NULL) / 1000LL; | |
3007 | json_object_int_add(json, "spfLastExecutedMsecs", | |
3008 | time_store); | |
3009 | ||
3010 | time_store = (1000 * ospf->ts_spf_duration.tv_sec) | |
3011 | + (ospf->ts_spf_duration.tv_usec / 1000); | |
3012 | json_object_int_add(json, "spfLastDurationMsecs", | |
3013 | time_store); | |
3014 | } else | |
3015 | json_object_boolean_true_add(json, "spfHasNotRun"); | |
3016 | } else { | |
3017 | vty_out(vty, " SPF algorithm "); | |
3018 | if (ospf->ts_spf.tv_sec || ospf->ts_spf.tv_usec) { | |
3019 | monotime_since(&ospf->ts_spf, &result); | |
3020 | vty_out(vty, "last executed %s ago\n", | |
3021 | ospf_timeval_dump(&result, timebuf, | |
3022 | sizeof(timebuf))); | |
3023 | vty_out(vty, " Last SPF duration %s\n", | |
3024 | ospf_timeval_dump(&ospf->ts_spf_duration, | |
3025 | timebuf, sizeof(timebuf))); | |
3026 | } else | |
3027 | vty_out(vty, "has not been run\n"); | |
3028 | } | |
3029 | ||
3030 | if (use_json) { | |
3031 | if (ospf->t_spf_calc) { | |
3032 | long time_store; | |
3033 | time_store = | |
3034 | monotime_until(&ospf->t_spf_calc->u.sands, NULL) | |
3035 | / 1000LL; | |
3036 | json_object_int_add(json, "spfTimerDueInMsecs", | |
3037 | time_store); | |
3038 | } | |
3039 | ||
3040 | json_object_int_add(json, "lsaMinIntervalMsecs", | |
3041 | ospf->min_ls_interval); | |
3042 | json_object_int_add(json, "lsaMinArrivalMsecs", | |
3043 | ospf->min_ls_arrival); | |
3044 | /* Show write multiplier values */ | |
3045 | json_object_int_add(json, "writeMultiplier", | |
3046 | ospf->write_oi_count); | |
3047 | /* Show refresh parameters. */ | |
3048 | json_object_int_add(json, "refreshTimerMsecs", | |
3049 | ospf->lsa_refresh_interval * 1000); | |
3050 | } else { | |
3051 | vty_out(vty, " SPF timer %s%s\n", | |
3052 | (ospf->t_spf_calc ? "due in " : "is "), | |
3053 | ospf_timer_dump(ospf->t_spf_calc, timebuf, | |
3054 | sizeof(timebuf))); | |
3055 | ||
3056 | vty_out(vty, " LSA minimum interval %d msecs\n", | |
3057 | ospf->min_ls_interval); | |
3058 | vty_out(vty, " LSA minimum arrival %d msecs\n", | |
3059 | ospf->min_ls_arrival); | |
3060 | ||
3061 | /* Show write multiplier values */ | |
3062 | vty_out(vty, " Write Multiplier set to %d \n", | |
3063 | ospf->write_oi_count); | |
3064 | ||
3065 | /* Show refresh parameters. */ | |
3066 | vty_out(vty, " Refresh timer %d secs\n", | |
3067 | ospf->lsa_refresh_interval); | |
3068 | } | |
3069 | ||
3070 | /* Show ABR/ASBR flags. */ | |
3071 | if (CHECK_FLAG(ospf->flags, OSPF_FLAG_ABR)) { | |
3072 | if (use_json) | |
3073 | json_object_string_add( | |
3074 | json, "abrType", | |
3075 | ospf_abr_type_descr_str[ospf->abr_type]); | |
3076 | else | |
3077 | vty_out(vty, | |
3078 | " This router is an ABR, ABR type is: %s\n", | |
3079 | ospf_abr_type_descr_str[ospf->abr_type]); | |
3080 | } | |
3081 | if (CHECK_FLAG(ospf->flags, OSPF_FLAG_ASBR)) { | |
3082 | if (use_json) | |
3083 | json_object_string_add( | |
3084 | json, "asbrRouter", | |
3085 | "injectingExternalRoutingInformation"); | |
3086 | else | |
3087 | vty_out(vty, | |
3088 | " This router is an ASBR " | |
3089 | "(injecting external routing information)\n"); | |
3090 | } | |
3091 | ||
3092 | /* Show Number of AS-external-LSAs. */ | |
3093 | if (use_json) { | |
3094 | json_object_int_add( | |
3095 | json, "lsaExternalCounter", | |
3096 | ospf_lsdb_count(ospf->lsdb, OSPF_AS_EXTERNAL_LSA)); | |
3097 | json_object_int_add( | |
3098 | json, "lsaExternalChecksum", | |
3099 | ospf_lsdb_checksum(ospf->lsdb, OSPF_AS_EXTERNAL_LSA)); | |
3100 | } else { | |
3101 | vty_out(vty, | |
3102 | " Number of external LSA %ld. Checksum Sum 0x%08x\n", | |
3103 | ospf_lsdb_count(ospf->lsdb, OSPF_AS_EXTERNAL_LSA), | |
3104 | ospf_lsdb_checksum(ospf->lsdb, OSPF_AS_EXTERNAL_LSA)); | |
3105 | } | |
3106 | ||
3107 | if (use_json) { | |
3108 | json_object_int_add( | |
3109 | json, "lsaAsopaqueCounter", | |
3110 | ospf_lsdb_count(ospf->lsdb, OSPF_OPAQUE_AS_LSA)); | |
3111 | json_object_int_add( | |
3112 | json, "lsaAsOpaqueChecksum", | |
3113 | ospf_lsdb_checksum(ospf->lsdb, OSPF_OPAQUE_AS_LSA)); | |
3114 | } else { | |
3115 | vty_out(vty, | |
3116 | " Number of opaque AS LSA %ld. Checksum Sum 0x%08x\n", | |
3117 | ospf_lsdb_count(ospf->lsdb, OSPF_OPAQUE_AS_LSA), | |
3118 | ospf_lsdb_checksum(ospf->lsdb, OSPF_OPAQUE_AS_LSA)); | |
3119 | } | |
3120 | ||
3121 | /* Show number of areas attached. */ | |
3122 | if (use_json) | |
3123 | json_object_int_add(json, "attachedAreaCounter", | |
3124 | listcount(ospf->areas)); | |
3125 | else | |
3126 | vty_out(vty, " Number of areas attached to this router: %d\n", | |
3127 | listcount(ospf->areas)); | |
3128 | ||
3129 | if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES)) { | |
3130 | if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL)) { | |
3131 | if (use_json) | |
3132 | json_object_boolean_true_add( | |
3133 | json, "adjacencyChangesLoggedAll"); | |
3134 | else | |
3135 | vty_out(vty, | |
3136 | " All adjacency changes are logged\n"); | |
3137 | } else { | |
3138 | if (use_json) | |
3139 | json_object_boolean_true_add( | |
3140 | json, "adjacencyChangesLogged"); | |
3141 | else | |
3142 | vty_out(vty, " Adjacency changes are logged\n"); | |
3143 | } | |
3144 | } | |
3145 | /* Show each area status. */ | |
3146 | for (ALL_LIST_ELEMENTS(ospf->areas, node, nnode, area)) | |
3147 | show_ip_ospf_area(vty, area, json_areas, use_json); | |
3148 | ||
3149 | if (use_json) { | |
3150 | json_object_object_add(json, "areas", json_areas); | |
9d303b37 DL |
3151 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
3152 | json, JSON_C_TO_STRING_PRETTY)); | |
d62a17ae | 3153 | json_object_free(json); |
3154 | } else | |
3155 | vty_out(vty, "\n"); | |
3156 | ||
3157 | return CMD_SUCCESS; | |
718e3744 | 3158 | } |
3159 | ||
7c8ff89e DS |
3160 | DEFUN (show_ip_ospf, |
3161 | show_ip_ospf_cmd, | |
b5a8894d | 3162 | "show ip ospf [vrf <NAME|all>] [json]", |
7c8ff89e DS |
3163 | SHOW_STR |
3164 | IP_STR | |
ca08c43d | 3165 | "OSPF information\n" |
b5a8894d CS |
3166 | VRF_CMD_HELP_STR |
3167 | "All VRFs\n" | |
9973d184 | 3168 | JSON_STR) |
7c8ff89e | 3169 | { |
d62a17ae | 3170 | struct ospf *ospf; |
3171 | u_char uj = use_json(argc, argv); | |
b5a8894d CS |
3172 | struct listnode *node = NULL; |
3173 | char *vrf_name = NULL; | |
3174 | bool all_vrf = FALSE; | |
3175 | int ret = CMD_SUCCESS; | |
3176 | int inst = 0; | |
3177 | int idx_vrf = 0; | |
7c8ff89e | 3178 | |
b5a8894d | 3179 | if (listcount(om->ospf) == 0) |
d62a17ae | 3180 | return CMD_SUCCESS; |
7c8ff89e | 3181 | |
43b8d1d8 | 3182 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
b5a8894d CS |
3183 | |
3184 | /* vrf input is provided could be all or specific vrf*/ | |
3185 | if (vrf_name) { | |
3186 | if (all_vrf) { | |
3187 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
3188 | if (!ospf->oi_running) | |
3189 | continue; | |
3190 | ret = show_ip_ospf_common(vty, ospf, uj); | |
3191 | } | |
3192 | return ret; | |
3193 | } | |
3194 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
3195 | if ((ospf == NULL) || !ospf->oi_running) | |
3196 | return CMD_SUCCESS; | |
3197 | } else { | |
3198 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
3199 | /* Display default ospf (instance 0) info */ | |
3200 | if (ospf == NULL || !ospf->oi_running) | |
3201 | return CMD_SUCCESS; | |
3202 | } | |
3203 | ||
3204 | if (ospf) | |
3205 | show_ip_ospf_common(vty, ospf, uj); | |
3206 | ||
3207 | return ret; | |
7c8ff89e DS |
3208 | } |
3209 | ||
3210 | DEFUN (show_ip_ospf_instance, | |
3211 | show_ip_ospf_instance_cmd, | |
6147e2c6 | 3212 | "show ip ospf (1-65535) [json]", |
7c8ff89e DS |
3213 | SHOW_STR |
3214 | IP_STR | |
3215 | "OSPF information\n" | |
ca08c43d | 3216 | "Instance ID\n" |
9973d184 | 3217 | JSON_STR) |
7c8ff89e | 3218 | { |
d62a17ae | 3219 | int idx_number = 3; |
3220 | struct ospf *ospf; | |
3221 | u_short instance = 0; | |
3222 | u_char uj = use_json(argc, argv); | |
3223 | ||
3224 | instance = strtoul(argv[idx_number]->arg, NULL, 10); | |
ac28e4ec CS |
3225 | ospf = ospf_lookup_instance(instance); |
3226 | if (ospf == NULL) | |
3227 | return CMD_NOT_MY_INSTANCE; | |
3228 | ||
3229 | if (!ospf->oi_running) | |
d62a17ae | 3230 | return CMD_SUCCESS; |
3231 | ||
3232 | return (show_ip_ospf_common(vty, ospf, uj)); | |
3233 | } | |
3234 | ||
3235 | static void show_ip_ospf_interface_sub(struct vty *vty, struct ospf *ospf, | |
3236 | struct interface *ifp, | |
3237 | json_object *json_interface_sub, | |
3238 | u_char use_json) | |
3239 | { | |
3240 | int is_up; | |
3241 | struct ospf_neighbor *nbr; | |
3242 | struct route_node *rn; | |
3243 | uint32_t bandwidth = ifp->bandwidth ? ifp->bandwidth : ifp->speed; | |
3244 | ||
3245 | /* Is interface up? */ | |
3246 | if (use_json) { | |
3247 | is_up = if_is_operative(ifp); | |
3248 | if (is_up) | |
3249 | json_object_boolean_true_add(json_interface_sub, | |
3250 | "ifUp"); | |
3251 | else | |
3252 | json_object_boolean_false_add(json_interface_sub, | |
3253 | "ifDown"); | |
3254 | ||
3255 | json_object_int_add(json_interface_sub, "ifIndex", | |
3256 | ifp->ifindex); | |
3257 | json_object_int_add(json_interface_sub, "mtuBytes", ifp->mtu); | |
3258 | json_object_int_add(json_interface_sub, "bandwidthMbit", | |
3259 | bandwidth); | |
3260 | json_object_string_add(json_interface_sub, "ifFlags", | |
3261 | if_flag_dump(ifp->flags)); | |
3262 | } else { | |
3263 | vty_out(vty, "%s is %s\n", ifp->name, | |
3264 | ((is_up = if_is_operative(ifp)) ? "up" : "down")); | |
3265 | vty_out(vty, " ifindex %u, MTU %u bytes, BW %u Mbit %s\n", | |
3266 | ifp->ifindex, ifp->mtu, bandwidth, | |
3267 | if_flag_dump(ifp->flags)); | |
3268 | } | |
7c8ff89e | 3269 | |
d62a17ae | 3270 | /* Is interface OSPF enabled? */ |
3271 | if (use_json) { | |
3272 | if (ospf_oi_count(ifp) == 0) { | |
3273 | json_object_boolean_false_add(json_interface_sub, | |
3274 | "ospfEnabled"); | |
3275 | return; | |
3276 | } else if (!is_up) { | |
3277 | json_object_boolean_false_add(json_interface_sub, | |
3278 | "ospfRunning"); | |
3279 | return; | |
3280 | } else | |
3281 | json_object_boolean_true_add(json_interface_sub, | |
3282 | "ospfEnabled"); | |
3283 | } else { | |
3284 | if (ospf_oi_count(ifp) == 0) { | |
3285 | vty_out(vty, " OSPF not enabled on this interface\n"); | |
3286 | return; | |
3287 | } else if (!is_up) { | |
3288 | vty_out(vty, | |
3289 | " OSPF is enabled, but not running on this interface\n"); | |
3290 | return; | |
3291 | } | |
3292 | } | |
3293 | ||
3294 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { | |
3295 | struct ospf_interface *oi = rn->info; | |
3296 | ||
3297 | if (oi == NULL) | |
3298 | continue; | |
3299 | ||
3300 | if (CHECK_FLAG(oi->connected->flags, ZEBRA_IFA_UNNUMBERED)) { | |
3301 | if (use_json) | |
3302 | json_object_boolean_true_add(json_interface_sub, | |
3303 | "ifUnnumbered"); | |
3304 | else | |
3305 | vty_out(vty, " This interface is UNNUMBERED,"); | |
3306 | } else { | |
3307 | /* Show OSPF interface information. */ | |
3308 | if (use_json) { | |
3309 | json_object_string_add( | |
3310 | json_interface_sub, "ipAddress", | |
3311 | inet_ntoa(oi->address->u.prefix4)); | |
3312 | json_object_int_add(json_interface_sub, | |
3313 | "ipAddressPrefixlen", | |
3314 | oi->address->prefixlen); | |
3315 | } else | |
3316 | vty_out(vty, " Internet Address %s/%d,", | |
3317 | inet_ntoa(oi->address->u.prefix4), | |
3318 | oi->address->prefixlen); | |
3319 | ||
3320 | if (oi->connected->destination | |
3321 | || oi->type == OSPF_IFTYPE_VIRTUALLINK) { | |
3322 | struct in_addr *dest; | |
3323 | const char *dstr; | |
3324 | ||
3325 | if (CONNECTED_PEER(oi->connected) | |
3326 | || oi->type == OSPF_IFTYPE_VIRTUALLINK) | |
3327 | dstr = "Peer"; | |
3328 | else | |
3329 | dstr = "Broadcast"; | |
3330 | ||
3331 | /* For Vlinks, showing the peer address is | |
9d303b37 DL |
3332 | * probably more |
3333 | * * * * * informative than the local | |
3334 | * interface that is being used | |
3335 | * * * * */ | |
d62a17ae | 3336 | if (oi->type == OSPF_IFTYPE_VIRTUALLINK) |
3337 | dest = &oi->vl_data->peer_addr; | |
3338 | else | |
3339 | dest = &oi->connected->destination->u | |
3340 | .prefix4; | |
3341 | ||
3342 | if (use_json) { | |
3343 | json_object_string_add( | |
3344 | json_interface_sub, | |
3345 | "ospfIfType", dstr); | |
3346 | if (oi->type == OSPF_IFTYPE_VIRTUALLINK) | |
3347 | json_object_string_add( | |
3348 | json_interface_sub, | |
3349 | "vlinkPeer", | |
3350 | inet_ntoa(*dest)); | |
3351 | else | |
3352 | json_object_string_add( | |
3353 | json_interface_sub, | |
3354 | "localIfUsed", | |
3355 | inet_ntoa(*dest)); | |
3356 | } else | |
3357 | vty_out(vty, " %s %s,", dstr, | |
3358 | inet_ntoa(*dest)); | |
3359 | } | |
3360 | } | |
3361 | if (use_json) { | |
3362 | json_object_string_add(json_interface_sub, "area", | |
3363 | ospf_area_desc_string(oi->area)); | |
3364 | if (OSPF_IF_PARAM(oi, mtu_ignore)) | |
3365 | json_object_boolean_true_add( | |
3366 | json_interface_sub, | |
3367 | "mtuMismatchDetect"); | |
3368 | json_object_string_add(json_interface_sub, "routerId", | |
3369 | inet_ntoa(ospf->router_id)); | |
3370 | json_object_string_add(json_interface_sub, | |
3371 | "networkType", | |
3372 | ospf_network_type_str[oi->type]); | |
3373 | json_object_int_add(json_interface_sub, "cost", | |
3374 | oi->output_cost); | |
3375 | json_object_int_add( | |
3376 | json_interface_sub, "transmitDelayMsecs", | |
3377 | 1000 / OSPF_IF_PARAM(oi, transmit_delay)); | |
3378 | json_object_string_add(json_interface_sub, "state", | |
3379 | lookup_msg(ospf_ism_state_msg, | |
3380 | oi->state, NULL)); | |
3381 | json_object_int_add(json_interface_sub, "priority", | |
3382 | PRIORITY(oi)); | |
3383 | } else { | |
3384 | vty_out(vty, " Area %s\n", | |
3385 | ospf_area_desc_string(oi->area)); | |
3386 | ||
3387 | vty_out(vty, " MTU mismatch detection: %s\n", | |
3388 | OSPF_IF_PARAM(oi, mtu_ignore) ? "disabled" | |
3389 | : "enabled"); | |
3390 | ||
3391 | vty_out(vty, | |
3392 | " Router ID %s, Network Type %s, Cost: %d\n", | |
3393 | inet_ntoa(ospf->router_id), | |
3394 | ospf_network_type_str[oi->type], | |
3395 | oi->output_cost); | |
3396 | ||
3397 | vty_out(vty, | |
3398 | " Transmit Delay is %d sec, State %s, Priority %d\n", | |
3399 | OSPF_IF_PARAM(oi, transmit_delay), | |
3400 | lookup_msg(ospf_ism_state_msg, oi->state, NULL), | |
3401 | PRIORITY(oi)); | |
3402 | } | |
3403 | ||
3404 | /* Show DR information. */ | |
3405 | if (DR(oi).s_addr == 0) { | |
3406 | if (!use_json) | |
3407 | vty_out(vty, | |
3408 | " No backup designated router on this network\n"); | |
3409 | } else { | |
3410 | nbr = ospf_nbr_lookup_by_addr(oi->nbrs, &BDR(oi)); | |
3411 | if (nbr == NULL) { | |
3412 | if (!use_json) | |
3413 | vty_out(vty, | |
3414 | " No backup designated router on this network\n"); | |
3415 | } else { | |
3416 | if (use_json) { | |
3417 | json_object_string_add( | |
3418 | json_interface_sub, "bdrId", | |
3419 | inet_ntoa(nbr->router_id)); | |
3420 | json_object_string_add( | |
3421 | json_interface_sub, | |
3422 | "bdrAddress", | |
3423 | inet_ntoa(nbr->address.u | |
3424 | .prefix4)); | |
3425 | } else { | |
3426 | vty_out(vty, | |
3427 | " Backup Designated Router (ID) %s,", | |
3428 | inet_ntoa(nbr->router_id)); | |
3429 | vty_out(vty, " Interface Address %s\n", | |
3430 | inet_ntoa(nbr->address.u | |
3431 | .prefix4)); | |
3432 | } | |
3433 | } | |
3434 | } | |
3435 | ||
3436 | /* Next network-LSA sequence number we'll use, if we're elected | |
3437 | * DR */ | |
3438 | if (oi->params | |
3439 | && ntohl(oi->params->network_lsa_seqnum) | |
3440 | != OSPF_INITIAL_SEQUENCE_NUMBER) { | |
3441 | if (use_json) | |
3442 | json_object_int_add( | |
3443 | json_interface_sub, | |
3444 | "networkLsaSequence", | |
3445 | ntohl(oi->params->network_lsa_seqnum)); | |
3446 | else | |
3447 | vty_out(vty, | |
3448 | " Saved Network-LSA sequence number 0x%x\n", | |
3449 | ntohl(oi->params->network_lsa_seqnum)); | |
3450 | } | |
3451 | ||
3452 | if (use_json) { | |
3453 | if (OI_MEMBER_CHECK(oi, MEMBER_ALLROUTERS) | |
3454 | || OI_MEMBER_CHECK(oi, MEMBER_DROUTERS)) { | |
3455 | if (OI_MEMBER_CHECK(oi, MEMBER_ALLROUTERS)) | |
3456 | json_object_boolean_true_add( | |
3457 | json_interface_sub, | |
3458 | "mcastMemberOspfAllRouters"); | |
3459 | if (OI_MEMBER_CHECK(oi, MEMBER_DROUTERS)) | |
3460 | json_object_boolean_true_add( | |
3461 | json_interface_sub, | |
3462 | "mcastMemberOspfDesignatedRouters"); | |
3463 | } | |
3464 | } else { | |
3465 | vty_out(vty, " Multicast group memberships:"); | |
3466 | if (OI_MEMBER_CHECK(oi, MEMBER_ALLROUTERS) | |
3467 | || OI_MEMBER_CHECK(oi, MEMBER_DROUTERS)) { | |
3468 | if (OI_MEMBER_CHECK(oi, MEMBER_ALLROUTERS)) | |
3469 | vty_out(vty, " OSPFAllRouters"); | |
3470 | if (OI_MEMBER_CHECK(oi, MEMBER_DROUTERS)) | |
3471 | vty_out(vty, " OSPFDesignatedRouters"); | |
3472 | } else | |
3473 | vty_out(vty, " <None>"); | |
3474 | vty_out(vty, "\n"); | |
3475 | } | |
3476 | ||
3477 | if (use_json) { | |
3478 | if (OSPF_IF_PARAM(oi, fast_hello) == 0) | |
3479 | json_object_int_add( | |
3480 | json_interface_sub, "timerMsecs", | |
3481 | 1000 / OSPF_IF_PARAM(oi, v_hello)); | |
3482 | else | |
3483 | json_object_int_add( | |
3484 | json_interface_sub, "timerMsecs", | |
3485 | 1000 / OSPF_IF_PARAM(oi, fast_hello)); | |
3486 | json_object_int_add(json_interface_sub, | |
3487 | "timerDeadMsecs", | |
3488 | 1000 / OSPF_IF_PARAM(oi, v_wait)); | |
3489 | json_object_int_add(json_interface_sub, | |
3490 | "timerWaitMsecs", | |
3491 | 1000 / OSPF_IF_PARAM(oi, v_wait)); | |
3492 | json_object_int_add( | |
3493 | json_interface_sub, "timerRetransmit", | |
3494 | 1000 / OSPF_IF_PARAM(oi, retransmit_interval)); | |
3495 | } else { | |
3496 | vty_out(vty, " Timer intervals configured,"); | |
3497 | vty_out(vty, " Hello "); | |
3498 | if (OSPF_IF_PARAM(oi, fast_hello) == 0) | |
3499 | vty_out(vty, "%ds,", | |
3500 | OSPF_IF_PARAM(oi, v_hello)); | |
3501 | else | |
3502 | vty_out(vty, "%dms,", | |
3503 | 1000 / OSPF_IF_PARAM(oi, fast_hello)); | |
3504 | vty_out(vty, " Dead %ds, Wait %ds, Retransmit %d\n", | |
3505 | OSPF_IF_PARAM(oi, v_wait), | |
3506 | OSPF_IF_PARAM(oi, v_wait), | |
3507 | OSPF_IF_PARAM(oi, retransmit_interval)); | |
3508 | } | |
3509 | ||
3510 | if (OSPF_IF_PASSIVE_STATUS(oi) == OSPF_IF_ACTIVE) { | |
3511 | char timebuf[OSPF_TIME_DUMP_SIZE]; | |
3512 | if (use_json) { | |
3513 | long time_store = 0; | |
3514 | if (oi->t_hello) | |
3515 | time_store = | |
3516 | monotime_until( | |
3517 | &oi->t_hello->u.sands, | |
3518 | NULL) | |
3519 | / 1000LL; | |
3520 | json_object_int_add(json_interface_sub, | |
3521 | "timerHelloInMsecs", | |
3522 | time_store); | |
3523 | } else | |
3524 | vty_out(vty, " Hello due in %s\n", | |
3525 | ospf_timer_dump(oi->t_hello, timebuf, | |
3526 | sizeof(timebuf))); | |
3527 | } else /* passive-interface is set */ | |
3528 | { | |
3529 | if (use_json) | |
3530 | json_object_boolean_true_add( | |
3531 | json_interface_sub, | |
3532 | "timerPassiveIface"); | |
3533 | else | |
3534 | vty_out(vty, | |
3535 | " No Hellos (Passive interface)\n"); | |
3536 | } | |
7c8ff89e | 3537 | |
d62a17ae | 3538 | if (use_json) { |
3539 | json_object_int_add(json_interface_sub, "nbrCount", | |
3540 | ospf_nbr_count(oi, 0)); | |
3541 | json_object_int_add(json_interface_sub, | |
3542 | "nbrAdjacentCount", | |
3543 | ospf_nbr_count(oi, NSM_Full)); | |
3544 | } else | |
3545 | vty_out(vty, | |
3546 | " Neighbor Count is %d, Adjacent neighbor count is %d\n", | |
3547 | ospf_nbr_count(oi, 0), | |
3548 | ospf_nbr_count(oi, NSM_Full)); | |
3549 | ospf_bfd_interface_show(vty, ifp, json_interface_sub, use_json); | |
3550 | } | |
718e3744 | 3551 | } |
3552 | ||
d62a17ae | 3553 | static int show_ip_ospf_interface_common(struct vty *vty, struct ospf *ospf, |
3554 | int argc, struct cmd_token **argv, | |
3555 | int iface_argv, u_char use_json) | |
3556 | { | |
3557 | struct interface *ifp; | |
3558 | struct listnode *node; | |
3559 | json_object *json = NULL; | |
3560 | json_object *json_interface_sub = NULL; | |
7c8ff89e | 3561 | |
d62a17ae | 3562 | if (use_json) { |
3563 | json = json_object_new_object(); | |
3564 | } | |
3565 | ||
3566 | if (ospf->instance) { | |
3567 | if (use_json) | |
3568 | json_object_int_add(json, "ospfInstance", | |
3569 | ospf->instance); | |
3570 | else | |
3571 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
3572 | } | |
3573 | ||
3574 | if (argc == iface_argv) { | |
3575 | /* Show All Interfaces.*/ | |
b5a8894d CS |
3576 | for (ALL_LIST_ELEMENTS_RO(vrf_iflist(ospf->vrf_id), |
3577 | node, ifp)) { | |
d62a17ae | 3578 | if (ospf_oi_count(ifp)) { |
3579 | if (use_json) | |
3580 | json_interface_sub = | |
3581 | json_object_new_object(); | |
3582 | ||
3583 | show_ip_ospf_interface_sub(vty, ospf, ifp, | |
3584 | json_interface_sub, | |
3585 | use_json); | |
3586 | ||
3587 | if (use_json) | |
3588 | json_object_object_add( | |
3589 | json, ifp->name, | |
3590 | json_interface_sub); | |
3591 | } | |
3592 | } | |
3593 | } else { | |
3594 | /* Interface name is specified. */ | |
3595 | if ((ifp = if_lookup_by_name(argv[iface_argv]->arg, | |
b5a8894d | 3596 | ospf->vrf_id)) |
d62a17ae | 3597 | == NULL) { |
3598 | if (use_json) | |
3599 | json_object_boolean_true_add(json, | |
3600 | "noSuchIface"); | |
3601 | else | |
3602 | vty_out(vty, "No such interface name\n"); | |
3603 | } else { | |
3604 | if (use_json) | |
3605 | json_interface_sub = json_object_new_object(); | |
3606 | ||
3607 | show_ip_ospf_interface_sub( | |
3608 | vty, ospf, ifp, json_interface_sub, use_json); | |
3609 | ||
3610 | if (use_json) | |
3611 | json_object_object_add(json, ifp->name, | |
3612 | json_interface_sub); | |
3613 | } | |
3614 | } | |
3615 | ||
3616 | if (use_json) { | |
9d303b37 DL |
3617 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
3618 | json, JSON_C_TO_STRING_PRETTY)); | |
d62a17ae | 3619 | json_object_free(json); |
3620 | } else | |
3621 | vty_out(vty, "\n"); | |
3622 | ||
3623 | return CMD_SUCCESS; | |
718e3744 | 3624 | } |
3625 | ||
7c8ff89e DS |
3626 | DEFUN (show_ip_ospf_interface, |
3627 | show_ip_ospf_interface_cmd, | |
43b8d1d8 | 3628 | "show ip ospf [vrf <NAME|all>] interface [INTERFACE] [json]", |
7c8ff89e DS |
3629 | SHOW_STR |
3630 | IP_STR | |
3631 | "OSPF information\n" | |
b5a8894d | 3632 | VRF_CMD_HELP_STR |
43b8d1d8 | 3633 | "All VRFs\n" |
7c8ff89e | 3634 | "Interface information\n" |
7ec4159b | 3635 | "Interface name\n" |
9973d184 | 3636 | JSON_STR) |
7c8ff89e | 3637 | { |
d62a17ae | 3638 | struct ospf *ospf; |
3639 | u_char uj = use_json(argc, argv); | |
b5a8894d CS |
3640 | struct listnode *node = NULL; |
3641 | char *vrf_name = NULL; | |
3642 | bool all_vrf = FALSE; | |
3643 | int ret = CMD_SUCCESS; | |
3644 | int inst = 0; | |
3645 | int idx_vrf = 0; | |
7c8ff89e | 3646 | |
43b8d1d8 CS |
3647 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
3648 | ||
d62a17ae | 3649 | if (uj) |
3650 | argc--; | |
6be4da3d | 3651 | |
b5a8894d CS |
3652 | /* vrf input is provided could be all or specific vrf*/ |
3653 | if (vrf_name) { | |
3654 | if (all_vrf) { | |
3655 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
3656 | if (!ospf->oi_running) | |
3657 | continue; | |
3658 | ret = show_ip_ospf_interface_common(vty, | |
3659 | ospf, argc, | |
3660 | argv, 6, | |
3661 | uj); | |
3662 | } | |
3663 | return ret; | |
3664 | } | |
3665 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
3666 | if (ospf == NULL || !ospf->oi_running) | |
3667 | return CMD_SUCCESS; | |
3668 | ret = show_ip_ospf_interface_common(vty, ospf, | |
3669 | argc, argv, 6, uj); | |
3670 | ||
3671 | } else { | |
3672 | /* Display default ospf (instance 0) info */ | |
3673 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
3674 | if (ospf == NULL || !ospf->oi_running) | |
3675 | return CMD_SUCCESS; | |
3676 | ret = show_ip_ospf_interface_common(vty, ospf, | |
3677 | argc, argv, 4, uj); | |
3678 | } | |
3679 | ||
3680 | return ret; | |
7c8ff89e DS |
3681 | } |
3682 | ||
3683 | DEFUN (show_ip_ospf_instance_interface, | |
3684 | show_ip_ospf_instance_interface_cmd, | |
6147e2c6 | 3685 | "show ip ospf (1-65535) interface [INTERFACE] [json]", |
7c8ff89e DS |
3686 | SHOW_STR |
3687 | IP_STR | |
3688 | "OSPF information\n" | |
3689 | "Instance ID\n" | |
3690 | "Interface information\n" | |
7ec4159b | 3691 | "Interface name\n" |
9973d184 | 3692 | JSON_STR) |
7c8ff89e | 3693 | { |
d62a17ae | 3694 | int idx_number = 3; |
3695 | struct ospf *ospf; | |
3696 | u_short instance = 0; | |
3697 | u_char uj = use_json(argc, argv); | |
3698 | ||
3699 | instance = strtoul(argv[idx_number]->arg, NULL, 10); | |
ac28e4ec CS |
3700 | ospf = ospf_lookup_instance(instance); |
3701 | if (ospf == NULL) | |
3702 | return CMD_NOT_MY_INSTANCE; | |
3703 | ||
3704 | if (!ospf->oi_running) | |
d62a17ae | 3705 | return CMD_SUCCESS; |
3706 | ||
3707 | if (uj) | |
3708 | argc--; | |
3709 | ||
3710 | return show_ip_ospf_interface_common(vty, ospf, argc, argv, 5, uj); | |
3711 | } | |
3712 | ||
3713 | static void show_ip_ospf_neighbour_header(struct vty *vty) | |
3714 | { | |
3715 | vty_out(vty, "\n%-15s %3s %-15s %9s %-15s %-20s %5s %5s %5s\n", | |
3716 | "Neighbor ID", "Pri", "State", "Dead Time", "Address", | |
3717 | "Interface", "RXmtL", "RqstL", "DBsmL"); | |
3718 | } | |
3719 | ||
3720 | static void show_ip_ospf_neighbor_sub(struct vty *vty, | |
3721 | struct ospf_interface *oi, | |
3722 | json_object *json, u_char use_json) | |
3723 | { | |
3724 | struct route_node *rn; | |
3725 | struct ospf_neighbor *nbr; | |
3726 | char msgbuf[16]; | |
3727 | char timebuf[OSPF_TIME_DUMP_SIZE]; | |
3728 | json_object *json_neighbor = NULL; | |
3729 | ||
3730 | for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) { | |
3731 | if ((nbr = rn->info)) { | |
3732 | /* Do not show myself. */ | |
3733 | if (nbr != oi->nbr_self) { | |
3734 | /* Down state is not shown. */ | |
3735 | if (nbr->state != NSM_Down) { | |
3736 | if (use_json) { | |
3737 | json_neighbor = | |
3738 | json_object_new_object(); | |
3739 | ospf_nbr_state_message( | |
3740 | nbr, msgbuf, 16); | |
3741 | ||
3742 | long time_store; | |
3743 | ||
3744 | time_store = | |
3745 | monotime_until( | |
3746 | &nbr->t_inactivity | |
3747 | ->u | |
3748 | .sands, | |
3749 | NULL) | |
3750 | / 1000LL; | |
3751 | ||
3752 | json_object_int_add( | |
3753 | json_neighbor, | |
3754 | "priority", | |
3755 | nbr->priority); | |
3756 | json_object_string_add( | |
3757 | json_neighbor, "state", | |
3758 | msgbuf); | |
3759 | json_object_int_add( | |
3760 | json_neighbor, | |
3761 | "deadTimeMsecs", | |
3762 | time_store); | |
3763 | json_object_string_add( | |
3764 | json_neighbor, | |
3765 | "address", | |
3766 | inet_ntoa(nbr->src)); | |
3767 | json_object_string_add( | |
3768 | json_neighbor, | |
3769 | "ifaceName", | |
3770 | IF_NAME(oi)); | |
3771 | json_object_int_add( | |
3772 | json_neighbor, | |
3773 | "retransmitCounter", | |
3774 | ospf_ls_retransmit_count( | |
3775 | nbr)); | |
3776 | json_object_int_add( | |
3777 | json_neighbor, | |
3778 | "requestCounter", | |
3779 | ospf_ls_request_count( | |
3780 | nbr)); | |
3781 | json_object_int_add( | |
3782 | json_neighbor, | |
3783 | "dbSummaryCounter", | |
3784 | ospf_db_summary_count( | |
3785 | nbr)); | |
3786 | if (nbr->state == NSM_Attempt | |
3787 | && nbr->router_id.s_addr | |
3788 | == 0) | |
3789 | json_object_object_add( | |
3790 | json, | |
3791 | "neighbor", | |
3792 | json_neighbor); | |
3793 | else | |
3794 | json_object_object_add( | |
3795 | json, | |
3796 | inet_ntoa( | |
3797 | nbr->router_id), | |
3798 | json_neighbor); | |
3799 | } else { | |
3800 | ospf_nbr_state_message( | |
3801 | nbr, msgbuf, 16); | |
3802 | ||
3803 | if (nbr->state == NSM_Attempt | |
3804 | && nbr->router_id.s_addr | |
3805 | == 0) | |
3806 | vty_out(vty, | |
3807 | "%-15s %3d %-15s ", | |
3808 | "-", | |
3809 | nbr->priority, | |
3810 | msgbuf); | |
3811 | else | |
3812 | vty_out(vty, | |
3813 | "%-15s %3d %-15s ", | |
3814 | inet_ntoa( | |
3815 | nbr->router_id), | |
3816 | nbr->priority, | |
3817 | msgbuf); | |
3818 | ||
3819 | vty_out(vty, "%9s ", | |
3820 | ospf_timer_dump( | |
3821 | nbr->t_inactivity, | |
3822 | timebuf, | |
3823 | sizeof(timebuf))); | |
3824 | vty_out(vty, "%-15s ", | |
3825 | inet_ntoa(nbr->src)); | |
3826 | vty_out(vty, | |
3827 | "%-20s %5ld %5ld %5d\n", | |
3828 | IF_NAME(oi), | |
3829 | ospf_ls_retransmit_count( | |
3830 | nbr), | |
3831 | ospf_ls_request_count( | |
3832 | nbr), | |
3833 | ospf_db_summary_count( | |
3834 | nbr)); | |
3835 | } | |
3836 | } | |
3837 | } | |
3838 | } | |
3839 | } | |
3840 | } | |
3841 | ||
3842 | static int show_ip_ospf_neighbor_common(struct vty *vty, struct ospf *ospf, | |
3843 | u_char use_json) | |
3844 | { | |
3845 | struct ospf_interface *oi; | |
3846 | struct listnode *node; | |
3847 | json_object *json = NULL; | |
7c8ff89e | 3848 | |
d62a17ae | 3849 | if (use_json) |
3850 | json = json_object_new_object(); | |
d62a17ae | 3851 | |
3852 | if (ospf->instance) { | |
3853 | if (use_json) | |
3854 | json_object_int_add(json, "ospfInstance", | |
3855 | ospf->instance); | |
3856 | else | |
3857 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
3858 | } | |
7c8ff89e | 3859 | |
d62a17ae | 3860 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) |
3861 | show_ip_ospf_neighbor_sub(vty, oi, json, use_json); | |
718e3744 | 3862 | |
d62a17ae | 3863 | if (use_json) { |
9d303b37 DL |
3864 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
3865 | json, JSON_C_TO_STRING_PRETTY)); | |
d62a17ae | 3866 | json_object_free(json); |
3867 | } else | |
3868 | vty_out(vty, "\n"); | |
7c8ff89e | 3869 | |
d62a17ae | 3870 | return CMD_SUCCESS; |
718e3744 | 3871 | } |
3872 | ||
7c8ff89e DS |
3873 | DEFUN (show_ip_ospf_neighbor, |
3874 | show_ip_ospf_neighbor_cmd, | |
b5a8894d | 3875 | "show ip ospf [vrf <NAME|all>] neighbor [json]", |
718e3744 | 3876 | SHOW_STR |
3877 | IP_STR | |
3878 | "OSPF information\n" | |
b5a8894d CS |
3879 | VRF_CMD_HELP_STR |
3880 | "All VRFs\n" | |
91756b38 | 3881 | "Neighbor list\n" |
9973d184 | 3882 | JSON_STR) |
718e3744 | 3883 | { |
d62a17ae | 3884 | struct ospf *ospf; |
3885 | u_char uj = use_json(argc, argv); | |
b5a8894d CS |
3886 | struct listnode *node = NULL; |
3887 | char *vrf_name = NULL; | |
3888 | bool all_vrf = FALSE; | |
3889 | int ret = CMD_SUCCESS; | |
3890 | int inst = 0; | |
3891 | int idx_vrf = 0; | |
718e3744 | 3892 | |
43b8d1d8 | 3893 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
7c8ff89e | 3894 | |
b5a8894d CS |
3895 | if (!uj) |
3896 | show_ip_ospf_neighbour_header(vty); | |
3897 | ||
3898 | /* vrf input is provided could be all or specific vrf*/ | |
3899 | if (vrf_name) { | |
3900 | if (all_vrf) { | |
3901 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
3902 | if (!ospf->oi_running) | |
3903 | continue; | |
3904 | ret = show_ip_ospf_neighbor_common(vty, ospf, | |
3905 | uj); | |
3906 | } | |
3907 | return ret; | |
3908 | } | |
3909 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
3910 | if (ospf == NULL || !ospf->oi_running) | |
3911 | return CMD_SUCCESS; | |
3912 | } else { | |
3913 | /* Display default ospf (instance 0) info */ | |
3914 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
3915 | if (ospf == NULL || !ospf->oi_running) | |
3916 | return CMD_SUCCESS; | |
3917 | } | |
3918 | ||
3919 | if (ospf) | |
3920 | ret = show_ip_ospf_neighbor_common(vty, ospf, uj); | |
3921 | ||
3922 | return ret; | |
7c8ff89e DS |
3923 | } |
3924 | ||
3925 | ||
3926 | DEFUN (show_ip_ospf_instance_neighbor, | |
3927 | show_ip_ospf_instance_neighbor_cmd, | |
6147e2c6 | 3928 | "show ip ospf (1-65535) neighbor [json]", |
7c8ff89e DS |
3929 | SHOW_STR |
3930 | IP_STR | |
3931 | "OSPF information\n" | |
3932 | "Instance ID\n" | |
91756b38 | 3933 | "Neighbor list\n" |
9973d184 | 3934 | JSON_STR) |
7c8ff89e | 3935 | { |
d62a17ae | 3936 | int idx_number = 3; |
3937 | struct ospf *ospf; | |
3938 | u_short instance = 0; | |
3939 | u_char uj = use_json(argc, argv); | |
7c8ff89e | 3940 | |
d62a17ae | 3941 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
ac28e4ec CS |
3942 | ospf = ospf_lookup_instance(instance); |
3943 | if (ospf == NULL) | |
3944 | return CMD_NOT_MY_INSTANCE; | |
3945 | ||
3946 | if (!ospf->oi_running) | |
d62a17ae | 3947 | return CMD_SUCCESS; |
7c8ff89e | 3948 | |
b5a8894d CS |
3949 | if (!uj) |
3950 | show_ip_ospf_neighbour_header(vty); | |
3951 | ||
d62a17ae | 3952 | return show_ip_ospf_neighbor_common(vty, ospf, uj); |
7c8ff89e DS |
3953 | } |
3954 | ||
d62a17ae | 3955 | static int show_ip_ospf_neighbor_all_common(struct vty *vty, struct ospf *ospf, |
3956 | u_char use_json) | |
3957 | { | |
3958 | struct listnode *node; | |
3959 | struct ospf_interface *oi; | |
3960 | json_object *json = NULL; | |
3961 | json_object *json_neighbor_sub = NULL; | |
7c8ff89e | 3962 | |
d62a17ae | 3963 | if (use_json) { |
3964 | json = json_object_new_object(); | |
3965 | json_neighbor_sub = json_object_new_object(); | |
b5a8894d | 3966 | } |
d62a17ae | 3967 | |
3968 | if (ospf->instance) { | |
3969 | if (use_json) | |
3970 | json_object_int_add(json, "ospfInstance", | |
3971 | ospf->instance); | |
3972 | else | |
3973 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
3974 | } | |
3975 | ||
b5a8894d CS |
3976 | if (ospf->name) { |
3977 | if (use_json) { | |
3978 | json_object_int_add(json, "vrfId", | |
3979 | (ospf->vrf_id == VRF_UNKNOWN) | |
3980 | ? -1 : ospf->vrf_id); | |
3981 | json_object_string_add(json, "vrfName", | |
3982 | (ospf->vrf_id == VRF_DEFAULT) | |
3983 | ? "Default" : ospf->name); | |
3984 | } else { | |
3985 | vty_out(vty, "\nOSPF vrf: %s\n\n", | |
3986 | ospf->vrf_id == VRF_DEFAULT | |
3987 | ? "Default" : ospf->name); | |
3988 | } | |
3989 | } | |
3990 | ||
3991 | ||
d62a17ae | 3992 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) { |
3993 | struct listnode *nbr_node; | |
3994 | struct ospf_nbr_nbma *nbr_nbma; | |
3995 | ||
3996 | show_ip_ospf_neighbor_sub(vty, oi, json, use_json); | |
3997 | ||
3998 | /* print Down neighbor status */ | |
3999 | for (ALL_LIST_ELEMENTS_RO(oi->nbr_nbma, nbr_node, nbr_nbma)) { | |
4000 | if (nbr_nbma->nbr == NULL | |
4001 | || nbr_nbma->nbr->state == NSM_Down) { | |
4002 | if (use_json) { | |
4003 | json_object_int_add(json_neighbor_sub, | |
4004 | "nbrNbmaPriority", | |
4005 | nbr_nbma->priority); | |
4006 | json_object_boolean_true_add( | |
4007 | json_neighbor_sub, | |
4008 | "nbrNbmaDown"); | |
4009 | json_object_string_add( | |
4010 | json_neighbor_sub, | |
4011 | "nbrNbmaIfaceName", | |
4012 | IF_NAME(oi)); | |
4013 | json_object_int_add( | |
4014 | json_neighbor_sub, | |
4015 | "nbrNbmaRetransmitCounter", 0); | |
4016 | json_object_int_add( | |
4017 | json_neighbor_sub, | |
4018 | "nbrNbmaRequestCounter", 0); | |
4019 | json_object_int_add( | |
4020 | json_neighbor_sub, | |
4021 | "nbrNbmaDbSummaryCounter", 0); | |
4022 | json_object_object_add( | |
4023 | json, inet_ntoa(nbr_nbma->addr), | |
4024 | json_neighbor_sub); | |
4025 | } else { | |
4026 | vty_out(vty, "%-15s %3d %-15s %9s ", | |
4027 | "-", nbr_nbma->priority, "Down", | |
4028 | "-"); | |
4029 | vty_out(vty, | |
4030 | "%-15s %-20s %5d %5d %5d\n", | |
4031 | inet_ntoa(nbr_nbma->addr), | |
4032 | IF_NAME(oi), 0, 0, 0); | |
4033 | } | |
4034 | } | |
4035 | } | |
4036 | } | |
4037 | ||
4038 | if (use_json) { | |
9d303b37 DL |
4039 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
4040 | json, JSON_C_TO_STRING_PRETTY)); | |
d62a17ae | 4041 | json_object_free(json); |
4042 | } else | |
4043 | vty_out(vty, "\n"); | |
4044 | ||
4045 | return CMD_SUCCESS; | |
718e3744 | 4046 | } |
4047 | ||
7c8ff89e DS |
4048 | DEFUN (show_ip_ospf_neighbor_all, |
4049 | show_ip_ospf_neighbor_all_cmd, | |
b5a8894d | 4050 | "show ip ospf [vrf <NAME|all>] neighbor all [json]", |
718e3744 | 4051 | SHOW_STR |
4052 | IP_STR | |
4053 | "OSPF information\n" | |
b5a8894d CS |
4054 | VRF_CMD_HELP_STR |
4055 | "All VRFs\n" | |
718e3744 | 4056 | "Neighbor list\n" |
91756b38 | 4057 | "include down status neighbor\n" |
9973d184 | 4058 | JSON_STR) |
7c8ff89e | 4059 | { |
d62a17ae | 4060 | struct ospf *ospf; |
4061 | u_char uj = use_json(argc, argv); | |
b5a8894d CS |
4062 | struct listnode *node = NULL; |
4063 | char *vrf_name = NULL; | |
4064 | bool all_vrf = FALSE; | |
4065 | int ret = CMD_SUCCESS; | |
4066 | int inst = 0; | |
4067 | int idx_vrf = 0; | |
7c8ff89e | 4068 | |
43b8d1d8 | 4069 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
7c8ff89e | 4070 | |
b5a8894d CS |
4071 | if (!uj) |
4072 | show_ip_ospf_neighbour_header(vty); | |
4073 | ||
4074 | /* vrf input is provided could be all or specific vrf*/ | |
4075 | if (vrf_name) { | |
4076 | if (all_vrf) { | |
4077 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
4078 | if (!ospf->oi_running) | |
4079 | continue; | |
4080 | ret = show_ip_ospf_neighbor_all_common(vty, | |
4081 | ospf, | |
4082 | uj); | |
4083 | } | |
4084 | return ret; | |
4085 | } | |
4086 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
4087 | if (ospf == NULL || !ospf->oi_running) | |
4088 | return CMD_SUCCESS; | |
4089 | } else { | |
4090 | /* Display default ospf (instance 0) info */ | |
4091 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
4092 | if (ospf == NULL || !ospf->oi_running) | |
4093 | return CMD_SUCCESS; | |
4094 | } | |
4095 | ||
4096 | if (ospf) | |
4097 | ret = show_ip_ospf_neighbor_all_common(vty, ospf, uj); | |
4098 | ||
4099 | return ret; | |
7c8ff89e DS |
4100 | } |
4101 | ||
4102 | DEFUN (show_ip_ospf_instance_neighbor_all, | |
4103 | show_ip_ospf_instance_neighbor_all_cmd, | |
6147e2c6 | 4104 | "show ip ospf (1-65535) neighbor all [json]", |
7c8ff89e DS |
4105 | SHOW_STR |
4106 | IP_STR | |
4107 | "OSPF information\n" | |
4108 | "Instance ID\n" | |
4109 | "Neighbor list\n" | |
91756b38 | 4110 | "include down status neighbor\n" |
9973d184 | 4111 | JSON_STR) |
718e3744 | 4112 | { |
d62a17ae | 4113 | int idx_number = 3; |
4114 | struct ospf *ospf; | |
4115 | u_short instance = 0; | |
4116 | u_char uj = use_json(argc, argv); | |
7c8ff89e | 4117 | |
d62a17ae | 4118 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
ac28e4ec CS |
4119 | ospf = ospf_lookup_instance(instance); |
4120 | if (ospf == NULL) | |
4121 | return CMD_NOT_MY_INSTANCE; | |
4122 | ||
4123 | if (!ospf->oi_running) | |
d62a17ae | 4124 | return CMD_SUCCESS; |
7c8ff89e | 4125 | |
d62a17ae | 4126 | return show_ip_ospf_neighbor_all_common(vty, ospf, uj); |
7c8ff89e DS |
4127 | } |
4128 | ||
d62a17ae | 4129 | static int show_ip_ospf_neighbor_int_common(struct vty *vty, struct ospf *ospf, |
4130 | int arg_base, | |
4131 | struct cmd_token **argv, | |
4132 | u_char use_json) | |
4133 | { | |
4134 | struct interface *ifp; | |
4135 | struct route_node *rn; | |
4136 | json_object *json = NULL; | |
91756b38 | 4137 | |
d62a17ae | 4138 | if (use_json) |
4139 | json = json_object_new_object(); | |
d62a17ae | 4140 | |
4141 | if (ospf->instance) { | |
4142 | if (use_json) | |
4143 | json_object_int_add(json, "ospfInstance", | |
4144 | ospf->instance); | |
4145 | else | |
4146 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
4147 | } | |
4148 | ||
b5a8894d CS |
4149 | /*ifp = if_lookup_by_name(argv[arg_base]->arg, ospf->vrf_id);*/ |
4150 | ifp = if_lookup_by_name_all_vrf(argv[arg_base]->arg); | |
d62a17ae | 4151 | if (!ifp) { |
4152 | if (use_json) | |
4153 | json_object_boolean_true_add(json, "noSuchIface"); | |
4154 | else | |
4155 | vty_out(vty, "No such interface.\n"); | |
4156 | return CMD_WARNING; | |
4157 | } | |
4158 | ||
4159 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { | |
4160 | struct ospf_interface *oi = rn->info; | |
4161 | ||
4162 | if (oi == NULL) | |
4163 | continue; | |
4164 | ||
4165 | show_ip_ospf_neighbor_sub(vty, oi, json, use_json); | |
4166 | } | |
4167 | ||
4168 | if (use_json) { | |
9d303b37 DL |
4169 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
4170 | json, JSON_C_TO_STRING_PRETTY)); | |
d62a17ae | 4171 | json_object_free(json); |
4172 | } else | |
4173 | vty_out(vty, "\n"); | |
4174 | ||
4175 | return CMD_SUCCESS; | |
718e3744 | 4176 | } |
4177 | ||
7c8ff89e DS |
4178 | DEFUN (show_ip_ospf_neighbor_int, |
4179 | show_ip_ospf_neighbor_int_cmd, | |
b162fa78 | 4180 | "show ip ospf neighbor IFNAME [json]", |
7c8ff89e DS |
4181 | SHOW_STR |
4182 | IP_STR | |
4183 | "OSPF information\n" | |
4184 | "Neighbor list\n" | |
91756b38 | 4185 | "Interface name\n" |
9973d184 | 4186 | JSON_STR) |
7c8ff89e | 4187 | { |
d62a17ae | 4188 | struct ospf *ospf; |
b4e84315 | 4189 | int idx_ifname = 4; |
d62a17ae | 4190 | u_char uj = use_json(argc, argv); |
b5a8894d CS |
4191 | struct listnode *node = NULL; |
4192 | int ret = CMD_SUCCESS; | |
4193 | struct interface *ifp = NULL; | |
7c8ff89e | 4194 | |
b5a8894d CS |
4195 | if (!uj) |
4196 | show_ip_ospf_neighbour_header(vty); | |
7c8ff89e | 4197 | |
b5a8894d CS |
4198 | ifp = if_lookup_by_name_all_vrf(argv[idx_ifname]->arg); |
4199 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
4200 | if (!ospf->oi_running) | |
4201 | continue; | |
4202 | if (!ifp || ifp->vrf_id != ospf->vrf_id) | |
4203 | continue; | |
4204 | ret = show_ip_ospf_neighbor_int_common(vty, ospf, | |
4205 | idx_ifname, argv, uj); | |
4206 | } | |
4207 | ||
4208 | return ret; | |
7c8ff89e DS |
4209 | } |
4210 | ||
4211 | DEFUN (show_ip_ospf_instance_neighbor_int, | |
4212 | show_ip_ospf_instance_neighbor_int_cmd, | |
6147e2c6 | 4213 | "show ip ospf (1-65535) neighbor IFNAME [json]", |
7c8ff89e DS |
4214 | SHOW_STR |
4215 | IP_STR | |
4216 | "OSPF information\n" | |
4217 | "Instance ID\n" | |
4218 | "Neighbor list\n" | |
91756b38 | 4219 | "Interface name\n" |
9973d184 | 4220 | JSON_STR) |
7c8ff89e | 4221 | { |
d62a17ae | 4222 | int idx_number = 3; |
b4e84315 | 4223 | int idx_ifname = 5; |
d62a17ae | 4224 | struct ospf *ospf; |
4225 | u_short instance = 0; | |
4226 | u_char uj = use_json(argc, argv); | |
7c8ff89e | 4227 | |
b5a8894d CS |
4228 | if (!uj) |
4229 | show_ip_ospf_neighbour_header(vty); | |
4230 | ||
d62a17ae | 4231 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
ac28e4ec CS |
4232 | ospf = ospf_lookup_instance(instance); |
4233 | if (ospf == NULL) | |
4234 | return CMD_NOT_MY_INSTANCE; | |
4235 | ||
4236 | if (!ospf->oi_running) | |
d62a17ae | 4237 | return CMD_SUCCESS; |
7c8ff89e | 4238 | |
b5a8894d CS |
4239 | if (!uj) |
4240 | show_ip_ospf_neighbour_header(vty); | |
4241 | ||
b4e84315 | 4242 | return show_ip_ospf_neighbor_int_common(vty, ospf, idx_ifname, argv, uj); |
718e3744 | 4243 | } |
4244 | ||
d62a17ae | 4245 | static void show_ip_ospf_nbr_nbma_detail_sub(struct vty *vty, |
4246 | struct ospf_interface *oi, | |
4247 | struct ospf_nbr_nbma *nbr_nbma, | |
4248 | u_char use_json, json_object *json) | |
4249 | { | |
4250 | char timebuf[OSPF_TIME_DUMP_SIZE]; | |
4251 | json_object *json_sub = NULL; | |
718e3744 | 4252 | |
d62a17ae | 4253 | if (use_json) |
4254 | json_sub = json_object_new_object(); | |
4255 | else /* Show neighbor ID. */ | |
4256 | vty_out(vty, " Neighbor %s,", "-"); | |
4257 | ||
4258 | /* Show interface address. */ | |
4259 | if (use_json) | |
4260 | json_object_string_add(json_sub, "ifaceAddress", | |
4261 | inet_ntoa(nbr_nbma->addr)); | |
4262 | else | |
4263 | vty_out(vty, " interface address %s\n", | |
4264 | inet_ntoa(nbr_nbma->addr)); | |
4265 | ||
4266 | /* Show Area ID. */ | |
4267 | if (use_json) { | |
4268 | json_object_string_add(json_sub, "areaId", | |
4269 | ospf_area_desc_string(oi->area)); | |
4270 | json_object_string_add(json_sub, "iface", IF_NAME(oi)); | |
4271 | } else | |
4272 | vty_out(vty, " In the area %s via interface %s\n", | |
4273 | ospf_area_desc_string(oi->area), IF_NAME(oi)); | |
4274 | ||
4275 | /* Show neighbor priority and state. */ | |
4276 | if (use_json) { | |
4277 | json_object_int_add(json_sub, "nbrPriority", | |
4278 | nbr_nbma->priority); | |
4279 | json_object_string_add(json_sub, "nbrState", "down"); | |
4280 | } else | |
4281 | vty_out(vty, " Neighbor priority is %d, State is %s,", | |
4282 | nbr_nbma->priority, "Down"); | |
4283 | ||
4284 | /* Show state changes. */ | |
4285 | if (use_json) | |
4286 | json_object_int_add(json_sub, "stateChangeCounter", | |
4287 | nbr_nbma->state_change); | |
4288 | else | |
4289 | vty_out(vty, " %d state changes\n", nbr_nbma->state_change); | |
4290 | ||
4291 | /* Show PollInterval */ | |
4292 | if (use_json) | |
4293 | json_object_int_add(json_sub, "pollInterval", nbr_nbma->v_poll); | |
4294 | else | |
4295 | vty_out(vty, " Poll interval %d\n", nbr_nbma->v_poll); | |
4296 | ||
4297 | /* Show poll-interval timer. */ | |
4298 | if (use_json) { | |
4299 | long time_store; | |
4300 | time_store = monotime_until(&nbr_nbma->t_poll->u.sands, NULL) | |
4301 | / 1000LL; | |
4302 | json_object_int_add(json_sub, "pollIntervalTimerDueMsec", | |
4303 | time_store); | |
4304 | } else | |
4305 | vty_out(vty, " Poll timer due in %s\n", | |
4306 | ospf_timer_dump(nbr_nbma->t_poll, timebuf, | |
4307 | sizeof(timebuf))); | |
4308 | ||
4309 | /* Show poll-interval timer thread. */ | |
4310 | if (use_json) { | |
4311 | if (nbr_nbma->t_poll != NULL) | |
4312 | json_object_string_add(json_sub, | |
4313 | "pollIntervalTimerThread", "on"); | |
4314 | } else | |
4315 | vty_out(vty, " Thread Poll Timer %s\n", | |
4316 | nbr_nbma->t_poll != NULL ? "on" : "off"); | |
4317 | ||
4318 | if (use_json) | |
4319 | json_object_object_add(json, "noNbrId", json_sub); | |
4320 | } | |
4321 | ||
4322 | static void show_ip_ospf_neighbor_detail_sub(struct vty *vty, | |
4323 | struct ospf_interface *oi, | |
4324 | struct ospf_neighbor *nbr, | |
4325 | u_char use_json, json_object *json) | |
4326 | { | |
4327 | char timebuf[OSPF_TIME_DUMP_SIZE]; | |
4328 | json_object *json_sub = NULL; | |
4329 | ||
4330 | if (use_json) | |
4331 | json_sub = json_object_new_object(); | |
4332 | else { | |
4333 | /* Show neighbor ID. */ | |
4334 | if (nbr->state == NSM_Attempt && nbr->router_id.s_addr == 0) | |
4335 | vty_out(vty, " Neighbor %s,", "-"); | |
4336 | else | |
4337 | vty_out(vty, " Neighbor %s,", | |
4338 | inet_ntoa(nbr->router_id)); | |
4339 | } | |
4340 | ||
4341 | /* Show interface address. */ | |
4342 | if (use_json) | |
4343 | json_object_string_add(json_sub, "ifaceAddress", | |
4344 | inet_ntoa(nbr->address.u.prefix4)); | |
4345 | else | |
4346 | vty_out(vty, " interface address %s\n", | |
4347 | inet_ntoa(nbr->address.u.prefix4)); | |
4348 | ||
4349 | /* Show Area ID. */ | |
4350 | if (use_json) { | |
4351 | json_object_string_add(json_sub, "areaId", | |
4352 | ospf_area_desc_string(oi->area)); | |
4353 | json_object_string_add(json_sub, "ifaceName", oi->ifp->name); | |
4354 | } else | |
4355 | vty_out(vty, " In the area %s via interface %s\n", | |
4356 | ospf_area_desc_string(oi->area), oi->ifp->name); | |
4357 | ||
4358 | /* Show neighbor priority and state. */ | |
4359 | if (use_json) { | |
4360 | json_object_int_add(json_sub, "nbrPriority", nbr->priority); | |
4361 | json_object_string_add( | |
4362 | json_sub, "nbrState", | |
4363 | lookup_msg(ospf_nsm_state_msg, nbr->state, NULL)); | |
4364 | } else | |
4365 | vty_out(vty, " Neighbor priority is %d, State is %s,", | |
4366 | nbr->priority, | |
4367 | lookup_msg(ospf_nsm_state_msg, nbr->state, NULL)); | |
4368 | ||
4369 | /* Show state changes. */ | |
4370 | if (use_json) | |
4371 | json_object_int_add(json_sub, "stateChangeCounter", | |
4372 | nbr->state_change); | |
4373 | else | |
4374 | vty_out(vty, " %d state changes\n", nbr->state_change); | |
4375 | ||
4376 | if (nbr->ts_last_progress.tv_sec || nbr->ts_last_progress.tv_usec) { | |
4377 | struct timeval res; | |
4378 | long time_store; | |
4379 | ||
4380 | time_store = | |
4381 | monotime_since(&nbr->ts_last_progress, &res) / 1000LL; | |
4382 | if (use_json) { | |
4383 | json_object_int_add(json_sub, "lastPrgrsvChangeMsec", | |
4384 | time_store); | |
4385 | } else { | |
4386 | vty_out(vty, | |
4387 | " Most recent state change statistics:\n"); | |
4388 | vty_out(vty, " Progressive change %s ago\n", | |
4389 | ospf_timeval_dump(&res, timebuf, | |
4390 | sizeof(timebuf))); | |
4391 | } | |
4392 | } | |
4393 | ||
4394 | if (nbr->ts_last_regress.tv_sec || nbr->ts_last_regress.tv_usec) { | |
4395 | struct timeval res; | |
4396 | long time_store; | |
4397 | ||
4398 | time_store = | |
4399 | monotime_since(&nbr->ts_last_regress, &res) / 1000LL; | |
4400 | if (use_json) { | |
4401 | json_object_int_add(json_sub, | |
4402 | "lastRegressiveChangeMsec", | |
4403 | time_store); | |
4404 | if (nbr->last_regress_str) | |
4405 | json_object_string_add( | |
4406 | json_sub, "lastRegressiveChangeReason", | |
4407 | nbr->last_regress_str); | |
4408 | } else { | |
4409 | vty_out(vty, | |
4410 | " Regressive change %s ago, due to %s\n", | |
4411 | ospf_timeval_dump(&res, timebuf, | |
4412 | sizeof(timebuf)), | |
4413 | (nbr->last_regress_str ? nbr->last_regress_str | |
4414 | : "??")); | |
4415 | } | |
4416 | } | |
4417 | ||
4418 | /* Show Designated Rotuer ID. */ | |
4419 | if (use_json) | |
4420 | json_object_string_add(json_sub, "routerDesignatedId", | |
4421 | inet_ntoa(nbr->d_router)); | |
4422 | else | |
4423 | vty_out(vty, " DR is %s,", inet_ntoa(nbr->d_router)); | |
4424 | ||
4425 | /* Show Backup Designated Rotuer ID. */ | |
4426 | if (use_json) | |
4427 | json_object_string_add(json_sub, "routerDesignatedBackupId", | |
4428 | inet_ntoa(nbr->bd_router)); | |
4429 | else | |
4430 | vty_out(vty, " BDR is %s\n", inet_ntoa(nbr->bd_router)); | |
4431 | ||
4432 | /* Show options. */ | |
4433 | if (use_json) { | |
4434 | json_object_int_add(json_sub, "optionsCounter", nbr->options); | |
4435 | json_object_string_add(json_sub, "optionsList", | |
4436 | ospf_options_dump(nbr->options)); | |
4437 | } else | |
4438 | vty_out(vty, " Options %d %s\n", nbr->options, | |
4439 | ospf_options_dump(nbr->options)); | |
4440 | ||
4441 | /* Show Router Dead interval timer. */ | |
4442 | if (use_json) { | |
4443 | if (nbr->t_inactivity) { | |
4444 | long time_store; | |
4445 | time_store = monotime_until(&nbr->t_inactivity->u.sands, | |
4446 | NULL) | |
4447 | / 1000LL; | |
4448 | json_object_int_add(json_sub, | |
4449 | "routerDeadIntervalTimerDueMsec", | |
4450 | time_store); | |
4451 | } else | |
4452 | json_object_int_add( | |
4453 | json_sub, "routerDeadIntervalTimerDueMsec", -1); | |
4454 | } else | |
4455 | vty_out(vty, " Dead timer due in %s\n", | |
4456 | ospf_timer_dump(nbr->t_inactivity, timebuf, | |
4457 | sizeof(timebuf))); | |
4458 | ||
4459 | /* Show Database Summary list. */ | |
4460 | if (use_json) | |
4461 | json_object_int_add(json_sub, "databaseSummaryListCounter", | |
4462 | ospf_db_summary_count(nbr)); | |
4463 | else | |
4464 | vty_out(vty, " Database Summary List %d\n", | |
4465 | ospf_db_summary_count(nbr)); | |
4466 | ||
4467 | /* Show Link State Request list. */ | |
4468 | if (use_json) | |
4469 | json_object_int_add(json_sub, "linkStateRequestListCounter", | |
4470 | ospf_ls_request_count(nbr)); | |
4471 | else | |
4472 | vty_out(vty, " Link State Request List %ld\n", | |
4473 | ospf_ls_request_count(nbr)); | |
4474 | ||
4475 | /* Show Link State Retransmission list. */ | |
4476 | if (use_json) | |
4477 | json_object_int_add(json_sub, | |
4478 | "linkStateRetransmissionListCounter", | |
4479 | ospf_ls_retransmit_count(nbr)); | |
4480 | else | |
4481 | vty_out(vty, " Link State Retransmission List %ld\n", | |
4482 | ospf_ls_retransmit_count(nbr)); | |
4483 | ||
4484 | /* Show inactivity timer thread. */ | |
4485 | if (use_json) { | |
4486 | if (nbr->t_inactivity != NULL) | |
4487 | json_object_string_add(json_sub, | |
4488 | "threadInactivityTimer", "on"); | |
4489 | } else | |
4490 | vty_out(vty, " Thread Inactivity Timer %s\n", | |
4491 | nbr->t_inactivity != NULL ? "on" : "off"); | |
4492 | ||
4493 | /* Show Database Description retransmission thread. */ | |
4494 | if (use_json) { | |
4495 | if (nbr->t_db_desc != NULL) | |
4496 | json_object_string_add( | |
4497 | json_sub, | |
4498 | "threadDatabaseDescriptionRetransmission", | |
4499 | "on"); | |
4500 | } else | |
4501 | vty_out(vty, | |
4502 | " Thread Database Description Retransmision %s\n", | |
4503 | nbr->t_db_desc != NULL ? "on" : "off"); | |
4504 | ||
4505 | /* Show Link State Request Retransmission thread. */ | |
4506 | if (use_json) { | |
4507 | if (nbr->t_ls_req != NULL) | |
4508 | json_object_string_add( | |
4509 | json_sub, | |
4510 | "threadLinkStateRequestRetransmission", "on"); | |
4511 | } else | |
4512 | vty_out(vty, | |
4513 | " Thread Link State Request Retransmission %s\n", | |
4514 | nbr->t_ls_req != NULL ? "on" : "off"); | |
4515 | ||
4516 | /* Show Link State Update Retransmission thread. */ | |
4517 | if (use_json) { | |
4518 | if (nbr->t_ls_upd != NULL) | |
4519 | json_object_string_add( | |
4520 | json_sub, "threadLinkStateUpdateRetransmission", | |
4521 | "on"); | |
4522 | } else | |
4523 | vty_out(vty, | |
4524 | " Thread Link State Update Retransmission %s\n\n", | |
4525 | nbr->t_ls_upd != NULL ? "on" : "off"); | |
4526 | ||
4527 | if (use_json) { | |
4528 | if (nbr->state == NSM_Attempt && nbr->router_id.s_addr == 0) | |
4529 | json_object_object_add(json, "noNbrId", json_sub); | |
4530 | else | |
4531 | json_object_object_add(json, inet_ntoa(nbr->router_id), | |
4532 | json_sub); | |
4533 | } | |
4534 | ||
4535 | ospf_bfd_show_info(vty, nbr->bfd_info, json, use_json, 0); | |
4536 | } | |
4537 | ||
4538 | static int show_ip_ospf_neighbor_id_common(struct vty *vty, struct ospf *ospf, | |
4539 | int arg_base, | |
4540 | struct cmd_token **argv, | |
4541 | u_char use_json) | |
4542 | { | |
4543 | struct listnode *node; | |
4544 | struct ospf_neighbor *nbr; | |
4545 | struct ospf_interface *oi; | |
4546 | struct in_addr router_id; | |
4547 | int ret; | |
4548 | json_object *json = NULL; | |
4549 | ||
4550 | if (use_json) | |
4551 | json = json_object_new_object(); | |
4552 | ||
4553 | if (ospf->instance) { | |
4554 | if (use_json) | |
4555 | json_object_int_add(json, "ospfInstance", | |
4556 | ospf->instance); | |
4557 | else | |
4558 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
4559 | } | |
4560 | ||
4561 | ret = inet_aton(argv[arg_base]->arg, &router_id); | |
4562 | if (!ret) { | |
4563 | if (!use_json) | |
4564 | vty_out(vty, "Please specify Neighbor ID by A.B.C.D\n"); | |
16307668 RW |
4565 | else { |
4566 | vty_out(vty, "{}\n"); | |
4567 | json_object_free(json); | |
4568 | } | |
d62a17ae | 4569 | return CMD_WARNING; |
4570 | } | |
4571 | ||
4572 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) { | |
4573 | if ((nbr = ospf_nbr_lookup_by_routerid(oi->nbrs, &router_id))) { | |
4574 | show_ip_ospf_neighbor_detail_sub(vty, oi, nbr, use_json, | |
4575 | json); | |
4576 | } | |
4577 | } | |
4578 | ||
4579 | if (use_json) { | |
9d303b37 DL |
4580 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
4581 | json, JSON_C_TO_STRING_PRETTY)); | |
d62a17ae | 4582 | json_object_free(json); |
4583 | } else | |
4584 | vty_out(vty, "\n"); | |
4585 | ||
4586 | return CMD_SUCCESS; | |
718e3744 | 4587 | } |
4588 | ||
7c8ff89e DS |
4589 | DEFUN (show_ip_ospf_neighbor_id, |
4590 | show_ip_ospf_neighbor_id_cmd, | |
b162fa78 | 4591 | "show ip ospf neighbor A.B.C.D [json]", |
718e3744 | 4592 | SHOW_STR |
4593 | IP_STR | |
4594 | "OSPF information\n" | |
4595 | "Neighbor list\n" | |
3ac237f8 | 4596 | "Neighbor ID\n" |
9973d184 | 4597 | JSON_STR) |
718e3744 | 4598 | { |
d62a17ae | 4599 | struct ospf *ospf; |
4600 | u_char uj = use_json(argc, argv); | |
b5a8894d CS |
4601 | struct listnode *node = NULL; |
4602 | int ret = CMD_SUCCESS; | |
7c8ff89e | 4603 | |
b5a8894d CS |
4604 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { |
4605 | if (!ospf->oi_running) | |
4606 | continue; | |
4607 | ret = show_ip_ospf_neighbor_id_common(vty, ospf, 0, argv, uj); | |
4608 | } | |
7c8ff89e | 4609 | |
b5a8894d | 4610 | return ret; |
7c8ff89e DS |
4611 | } |
4612 | ||
4613 | DEFUN (show_ip_ospf_instance_neighbor_id, | |
4614 | show_ip_ospf_instance_neighbor_id_cmd, | |
6147e2c6 | 4615 | "show ip ospf (1-65535) neighbor A.B.C.D [json]", |
7c8ff89e DS |
4616 | SHOW_STR |
4617 | IP_STR | |
4618 | "OSPF information\n" | |
4619 | "Instance ID\n" | |
4620 | "Neighbor list\n" | |
3ac237f8 | 4621 | "Neighbor ID\n" |
9973d184 | 4622 | JSON_STR) |
7c8ff89e | 4623 | { |
d62a17ae | 4624 | int idx_number = 3; |
b4e84315 | 4625 | int idx_router_id = 5; |
d62a17ae | 4626 | struct ospf *ospf; |
4627 | u_short instance = 0; | |
4628 | u_char uj = use_json(argc, argv); | |
7c8ff89e | 4629 | |
d62a17ae | 4630 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
ac28e4ec CS |
4631 | ospf = ospf_lookup_instance(instance); |
4632 | if (ospf == NULL) | |
4633 | return CMD_NOT_MY_INSTANCE; | |
4634 | ||
4635 | if (!ospf->oi_running) | |
d62a17ae | 4636 | return CMD_SUCCESS; |
7c8ff89e | 4637 | |
b4e84315 | 4638 | return show_ip_ospf_neighbor_id_common(vty, ospf, idx_router_id, argv, uj); |
7c8ff89e DS |
4639 | } |
4640 | ||
d62a17ae | 4641 | static int show_ip_ospf_neighbor_detail_common(struct vty *vty, |
4642 | struct ospf *ospf, | |
4643 | u_char use_json) | |
4644 | { | |
4645 | struct ospf_interface *oi; | |
4646 | struct listnode *node; | |
4647 | json_object *json = NULL; | |
3ac237f8 | 4648 | |
d62a17ae | 4649 | if (use_json) |
4650 | json = json_object_new_object(); | |
4651 | ||
4652 | if (ospf->instance) { | |
4653 | if (use_json) | |
4654 | json_object_int_add(json, "ospfInstance", | |
4655 | ospf->instance); | |
4656 | else | |
4657 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
4658 | } | |
4659 | ||
4660 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) { | |
4661 | struct route_node *rn; | |
4662 | struct ospf_neighbor *nbr; | |
4663 | ||
4664 | for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) { | |
4665 | if ((nbr = rn->info)) { | |
4666 | if (nbr != oi->nbr_self) { | |
4667 | if (nbr->state != NSM_Down) { | |
4668 | show_ip_ospf_neighbor_detail_sub( | |
4669 | vty, oi, nbr, use_json, | |
4670 | json); | |
4671 | } | |
4672 | } | |
4673 | } | |
4674 | } | |
4675 | } | |
4676 | ||
4677 | if (use_json) { | |
9d303b37 DL |
4678 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
4679 | json, JSON_C_TO_STRING_PRETTY)); | |
d62a17ae | 4680 | json_object_free(json); |
4681 | } else | |
4682 | vty_out(vty, "\n"); | |
4683 | ||
4684 | return CMD_SUCCESS; | |
718e3744 | 4685 | } |
4686 | ||
7c8ff89e DS |
4687 | DEFUN (show_ip_ospf_neighbor_detail, |
4688 | show_ip_ospf_neighbor_detail_cmd, | |
b5a8894d | 4689 | "show ip ospf [vrf <NAME|all>] neighbor detail [json]", |
718e3744 | 4690 | SHOW_STR |
4691 | IP_STR | |
4692 | "OSPF information\n" | |
b5a8894d CS |
4693 | VRF_CMD_HELP_STR |
4694 | "All VRFs\n" | |
718e3744 | 4695 | "Neighbor list\n" |
3ac237f8 | 4696 | "detail of all neighbors\n" |
9973d184 | 4697 | JSON_STR) |
718e3744 | 4698 | { |
d62a17ae | 4699 | struct ospf *ospf; |
4700 | u_char uj = use_json(argc, argv); | |
b5a8894d CS |
4701 | struct listnode *node = NULL; |
4702 | char *vrf_name = NULL; | |
4703 | bool all_vrf = FALSE; | |
4704 | int ret = CMD_SUCCESS; | |
4705 | int inst = 0; | |
4706 | int idx_vrf = 0; | |
7c8ff89e | 4707 | |
43b8d1d8 | 4708 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
7c8ff89e | 4709 | |
b5a8894d CS |
4710 | /* vrf input is provided could be all or specific vrf*/ |
4711 | if (vrf_name) { | |
4712 | if (all_vrf) { | |
4713 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
4714 | if (!ospf->oi_running) | |
4715 | continue; | |
4716 | ret = show_ip_ospf_neighbor_detail_common(vty, | |
4717 | ospf, | |
4718 | uj); | |
4719 | } | |
4720 | return ret; | |
4721 | } | |
4722 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
4723 | if (ospf == NULL || !ospf->oi_running) | |
4724 | return CMD_SUCCESS; | |
4725 | } else { | |
4726 | /* Display default ospf (instance 0) info */ | |
4727 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
4728 | if (ospf == NULL || !ospf->oi_running) | |
4729 | return CMD_SUCCESS; | |
4730 | } | |
4731 | ||
4732 | if (ospf) | |
4733 | ret = show_ip_ospf_neighbor_detail_common(vty, ospf, uj); | |
4734 | ||
4735 | return ret; | |
7c8ff89e DS |
4736 | } |
4737 | ||
4738 | DEFUN (show_ip_ospf_instance_neighbor_detail, | |
4739 | show_ip_ospf_instance_neighbor_detail_cmd, | |
6147e2c6 | 4740 | "show ip ospf (1-65535) neighbor detail [json]", |
7c8ff89e DS |
4741 | SHOW_STR |
4742 | IP_STR | |
4743 | "OSPF information\n" | |
4744 | "Instance ID\n" | |
4745 | "Neighbor list\n" | |
3ac237f8 | 4746 | "detail of all neighbors\n" |
9973d184 | 4747 | JSON_STR) |
7c8ff89e | 4748 | { |
d62a17ae | 4749 | int idx_number = 3; |
4750 | struct ospf *ospf; | |
4751 | u_short instance = 0; | |
4752 | u_char uj = use_json(argc, argv); | |
7c8ff89e | 4753 | |
d62a17ae | 4754 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
ac28e4ec CS |
4755 | ospf = ospf_lookup_instance(instance); |
4756 | if (ospf == NULL) | |
4757 | return CMD_NOT_MY_INSTANCE; | |
4758 | ||
4759 | if (!ospf->oi_running) | |
d62a17ae | 4760 | return CMD_SUCCESS; |
7c8ff89e | 4761 | |
d62a17ae | 4762 | return show_ip_ospf_neighbor_detail_common(vty, ospf, uj); |
7c8ff89e DS |
4763 | } |
4764 | ||
d62a17ae | 4765 | static int show_ip_ospf_neighbor_detail_all_common(struct vty *vty, |
4766 | struct ospf *ospf, | |
4767 | u_char use_json) | |
4768 | { | |
4769 | struct listnode *node; | |
4770 | struct ospf_interface *oi; | |
4771 | json_object *json = NULL; | |
718e3744 | 4772 | |
d62a17ae | 4773 | if (use_json) |
4774 | json = json_object_new_object(); | |
4775 | ||
4776 | if (ospf->instance) { | |
4777 | if (use_json) | |
4778 | json_object_int_add(json, "ospfInstance", | |
4779 | ospf->instance); | |
4780 | else | |
4781 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
4782 | } | |
4783 | ||
4784 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) { | |
4785 | struct route_node *rn; | |
4786 | struct ospf_neighbor *nbr; | |
4787 | struct ospf_nbr_nbma *nbr_nbma; | |
4788 | ||
4789 | for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) | |
4790 | if ((nbr = rn->info)) | |
4791 | if (nbr != oi->nbr_self) | |
4792 | if (nbr->state != NSM_Down) | |
4793 | show_ip_ospf_neighbor_detail_sub( | |
4794 | vty, oi, rn->info, | |
4795 | use_json, json); | |
4796 | ||
4797 | if (oi->type == OSPF_IFTYPE_NBMA) { | |
4798 | struct listnode *nd; | |
4799 | ||
4800 | for (ALL_LIST_ELEMENTS_RO(oi->nbr_nbma, nd, nbr_nbma)) { | |
4801 | if (nbr_nbma->nbr == NULL | |
4802 | || nbr_nbma->nbr->state == NSM_Down) | |
4803 | show_ip_ospf_nbr_nbma_detail_sub( | |
4804 | vty, oi, nbr_nbma, use_json, | |
4805 | json); | |
4806 | } | |
4807 | } | |
4808 | } | |
4809 | ||
4810 | if (use_json) { | |
9d303b37 DL |
4811 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
4812 | json, JSON_C_TO_STRING_PRETTY)); | |
d62a17ae | 4813 | json_object_free(json); |
4814 | } else { | |
4815 | vty_out(vty, "\n"); | |
4816 | } | |
4817 | ||
4818 | return CMD_SUCCESS; | |
718e3744 | 4819 | } |
4820 | ||
7c8ff89e DS |
4821 | DEFUN (show_ip_ospf_neighbor_detail_all, |
4822 | show_ip_ospf_neighbor_detail_all_cmd, | |
b5a8894d | 4823 | "show ip ospf [vrf <NAME|all>] neighbor detail all [json]", |
718e3744 | 4824 | SHOW_STR |
4825 | IP_STR | |
4826 | "OSPF information\n" | |
b5a8894d CS |
4827 | VRF_CMD_HELP_STR |
4828 | "All VRFs\n" | |
718e3744 | 4829 | "Neighbor list\n" |
7c8ff89e | 4830 | "detail of all neighbors\n" |
3ac237f8 | 4831 | "include down status neighbor\n" |
9973d184 | 4832 | JSON_STR) |
718e3744 | 4833 | { |
d62a17ae | 4834 | struct ospf *ospf; |
4835 | u_char uj = use_json(argc, argv); | |
b5a8894d CS |
4836 | struct listnode *node = NULL; |
4837 | char *vrf_name = NULL; | |
4838 | bool all_vrf = FALSE; | |
4839 | int ret = CMD_SUCCESS; | |
4840 | int inst = 0; | |
4841 | int idx_vrf = 0; | |
7c8ff89e | 4842 | |
43b8d1d8 | 4843 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
7c8ff89e | 4844 | |
b5a8894d CS |
4845 | /* vrf input is provided could be all or specific vrf*/ |
4846 | if (vrf_name) { | |
4847 | if (all_vrf) { | |
4848 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
4849 | if (!ospf->oi_running) | |
4850 | continue; | |
4851 | ret = show_ip_ospf_neighbor_detail_all_common(vty, | |
4852 | ospf, | |
4853 | uj); | |
4854 | } | |
4855 | return ret; | |
4856 | } | |
4857 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
4858 | if (ospf == NULL || !ospf->oi_running) | |
4859 | return CMD_SUCCESS; | |
4860 | } else { | |
4861 | /* Display default ospf (instance 0) info */ | |
4862 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
4863 | if (ospf == NULL || !ospf->oi_running) | |
4864 | return CMD_SUCCESS; | |
4865 | } | |
4866 | ||
4867 | if (ospf) | |
4868 | ret = show_ip_ospf_neighbor_detail_all_common(vty, ospf, uj); | |
4869 | ||
4870 | return ret; | |
7c8ff89e DS |
4871 | } |
4872 | ||
4873 | DEFUN (show_ip_ospf_instance_neighbor_detail_all, | |
4874 | show_ip_ospf_instance_neighbor_detail_all_cmd, | |
6147e2c6 | 4875 | "show ip ospf (1-65535) neighbor detail all [json]", |
7c8ff89e DS |
4876 | SHOW_STR |
4877 | IP_STR | |
4878 | "OSPF information\n" | |
4879 | "Instance ID\n" | |
4880 | "Neighbor list\n" | |
4881 | "detail of all neighbors\n" | |
3ac237f8 | 4882 | "include down status neighbor\n" |
9973d184 | 4883 | JSON_STR) |
7c8ff89e | 4884 | { |
d62a17ae | 4885 | int idx_number = 3; |
4886 | struct ospf *ospf; | |
4887 | u_short instance = 0; | |
4888 | u_char uj = use_json(argc, argv); | |
7c8ff89e | 4889 | |
d62a17ae | 4890 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
ac28e4ec CS |
4891 | ospf = ospf_lookup_instance(instance); |
4892 | if (ospf == NULL) | |
4893 | return CMD_NOT_MY_INSTANCE; | |
4894 | ||
4895 | if (!ospf->oi_running) | |
d62a17ae | 4896 | return CMD_SUCCESS; |
7c8ff89e | 4897 | |
d62a17ae | 4898 | return show_ip_ospf_neighbor_detail_all_common(vty, ospf, uj); |
7c8ff89e DS |
4899 | } |
4900 | ||
d62a17ae | 4901 | static int show_ip_ospf_neighbor_int_detail_common(struct vty *vty, |
4902 | struct ospf *ospf, | |
4903 | int arg_base, | |
4904 | struct cmd_token **argv, | |
4905 | u_char use_json) | |
4906 | { | |
4907 | struct ospf_interface *oi; | |
4908 | struct interface *ifp; | |
4909 | struct route_node *rn, *nrn; | |
4910 | struct ospf_neighbor *nbr; | |
4911 | json_object *json = NULL; | |
718e3744 | 4912 | |
d62a17ae | 4913 | if (use_json) |
4914 | json = json_object_new_object(); | |
4915 | ||
4916 | if (ospf->instance) { | |
4917 | if (use_json) | |
4918 | json_object_int_add(json, "ospfInstance", | |
4919 | ospf->instance); | |
4920 | else | |
4921 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
4922 | } | |
4923 | ||
b5a8894d | 4924 | ifp = if_lookup_by_name_all_vrf(argv[arg_base]->arg); |
d62a17ae | 4925 | if (!ifp) { |
4926 | if (!use_json) | |
4927 | vty_out(vty, "No such interface.\n"); | |
16307668 RW |
4928 | else { |
4929 | vty_out(vty, "{}\n"); | |
4930 | json_object_free(json); | |
4931 | } | |
d62a17ae | 4932 | return CMD_WARNING; |
4933 | } | |
4934 | ||
4935 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { | |
4936 | if ((oi = rn->info)) { | |
4937 | for (nrn = route_top(oi->nbrs); nrn; | |
4938 | nrn = route_next(nrn)) { | |
4939 | if ((nbr = nrn->info)) { | |
4940 | if (nbr != oi->nbr_self) { | |
4941 | if (nbr->state != NSM_Down) | |
4942 | show_ip_ospf_neighbor_detail_sub( | |
4943 | vty, oi, nbr, | |
4944 | use_json, json); | |
4945 | } | |
4946 | } | |
4947 | } | |
4948 | } | |
4949 | } | |
4950 | ||
4951 | if (use_json) { | |
9d303b37 DL |
4952 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
4953 | json, JSON_C_TO_STRING_PRETTY)); | |
d62a17ae | 4954 | json_object_free(json); |
4955 | } else | |
4956 | vty_out(vty, "\n"); | |
4957 | ||
4958 | return CMD_SUCCESS; | |
718e3744 | 4959 | } |
4960 | ||
7c8ff89e DS |
4961 | DEFUN (show_ip_ospf_neighbor_int_detail, |
4962 | show_ip_ospf_neighbor_int_detail_cmd, | |
b162fa78 | 4963 | "show ip ospf neighbor IFNAME detail [json]", |
7c8ff89e DS |
4964 | SHOW_STR |
4965 | IP_STR | |
4966 | "OSPF information\n" | |
4967 | "Neighbor list\n" | |
4968 | "Interface name\n" | |
3ac237f8 | 4969 | "detail of all neighbors\n" |
9973d184 | 4970 | JSON_STR) |
7c8ff89e | 4971 | { |
d62a17ae | 4972 | struct ospf *ospf; |
4973 | u_char uj = use_json(argc, argv); | |
b5a8894d CS |
4974 | struct listnode *node = NULL; |
4975 | int ret = CMD_SUCCESS; | |
7c8ff89e | 4976 | |
b5a8894d CS |
4977 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { |
4978 | if (!ospf->oi_running) | |
4979 | continue; | |
4980 | ret = show_ip_ospf_neighbor_int_detail_common(vty, ospf, 0, | |
4981 | argv, uj); | |
4982 | } | |
7c8ff89e | 4983 | |
b5a8894d | 4984 | return ret; |
7c8ff89e DS |
4985 | } |
4986 | ||
4987 | DEFUN (show_ip_ospf_instance_neighbor_int_detail, | |
4988 | show_ip_ospf_instance_neighbor_int_detail_cmd, | |
6147e2c6 | 4989 | "show ip ospf (1-65535) neighbor IFNAME detail [json]", |
7c8ff89e DS |
4990 | SHOW_STR |
4991 | IP_STR | |
4992 | "OSPF information\n" | |
4993 | "Instance ID\n" | |
4994 | "Neighbor list\n" | |
4995 | "Interface name\n" | |
3ac237f8 | 4996 | "detail of all neighbors\n" |
9973d184 | 4997 | JSON_STR) |
7c8ff89e | 4998 | { |
d62a17ae | 4999 | int idx_number = 3; |
b4e84315 | 5000 | int idx_ifname = 5; |
d62a17ae | 5001 | struct ospf *ospf; |
5002 | u_short instance = 0; | |
5003 | u_char uj = use_json(argc, argv); | |
7c8ff89e | 5004 | |
d62a17ae | 5005 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
ac28e4ec CS |
5006 | ospf = ospf_lookup_instance(instance); |
5007 | if (ospf == NULL) | |
5008 | return CMD_NOT_MY_INSTANCE; | |
5009 | ||
5010 | if (!ospf->oi_running) | |
d62a17ae | 5011 | return CMD_SUCCESS; |
7c8ff89e | 5012 | |
b4e84315 | 5013 | return show_ip_ospf_neighbor_int_detail_common(vty, ospf, idx_ifname, argv, uj); |
7c8ff89e | 5014 | } |
6b0655a2 | 5015 | |
718e3744 | 5016 | /* Show functions */ |
d62a17ae | 5017 | static int show_lsa_summary(struct vty *vty, struct ospf_lsa *lsa, int self) |
5018 | { | |
5019 | struct router_lsa *rl; | |
5020 | struct summary_lsa *sl; | |
5021 | struct as_external_lsa *asel; | |
5022 | struct prefix_ipv4 p; | |
5023 | ||
5024 | if (lsa != NULL) | |
5025 | /* If self option is set, check LSA self flag. */ | |
5026 | if (self == 0 || IS_LSA_SELF(lsa)) { | |
5027 | /* LSA common part show. */ | |
5028 | vty_out(vty, "%-15s ", inet_ntoa(lsa->data->id)); | |
5029 | vty_out(vty, "%-15s %4d 0x%08lx 0x%04x", | |
5030 | inet_ntoa(lsa->data->adv_router), LS_AGE(lsa), | |
5031 | (u_long)ntohl(lsa->data->ls_seqnum), | |
5032 | ntohs(lsa->data->checksum)); | |
5033 | /* LSA specific part show. */ | |
5034 | switch (lsa->data->type) { | |
5035 | case OSPF_ROUTER_LSA: | |
5036 | rl = (struct router_lsa *)lsa->data; | |
5037 | vty_out(vty, " %-d", ntohs(rl->links)); | |
5038 | break; | |
5039 | case OSPF_SUMMARY_LSA: | |
5040 | sl = (struct summary_lsa *)lsa->data; | |
5041 | ||
5042 | p.family = AF_INET; | |
5043 | p.prefix = sl->header.id; | |
5044 | p.prefixlen = ip_masklen(sl->mask); | |
5045 | apply_mask_ipv4(&p); | |
5046 | ||
5047 | vty_out(vty, " %s/%d", inet_ntoa(p.prefix), | |
5048 | p.prefixlen); | |
5049 | break; | |
5050 | case OSPF_AS_EXTERNAL_LSA: | |
5051 | case OSPF_AS_NSSA_LSA: | |
5052 | asel = (struct as_external_lsa *)lsa->data; | |
5053 | ||
5054 | p.family = AF_INET; | |
5055 | p.prefix = asel->header.id; | |
5056 | p.prefixlen = ip_masklen(asel->mask); | |
5057 | apply_mask_ipv4(&p); | |
5058 | ||
5059 | vty_out(vty, " %s %s/%d [0x%lx]", | |
5060 | IS_EXTERNAL_METRIC(asel->e[0].tos) | |
5061 | ? "E2" | |
5062 | : "E1", | |
5063 | inet_ntoa(p.prefix), p.prefixlen, | |
5064 | (u_long)ntohl(asel->e[0].route_tag)); | |
5065 | break; | |
5066 | case OSPF_NETWORK_LSA: | |
5067 | case OSPF_ASBR_SUMMARY_LSA: | |
5068 | case OSPF_OPAQUE_LINK_LSA: | |
5069 | case OSPF_OPAQUE_AREA_LSA: | |
5070 | case OSPF_OPAQUE_AS_LSA: | |
5071 | default: | |
5072 | break; | |
5073 | } | |
5074 | vty_out(vty, "\n"); | |
5075 | } | |
718e3744 | 5076 | |
d62a17ae | 5077 | return 0; |
5078 | } | |
5079 | ||
5080 | static const char *show_database_desc[] = { | |
5081 | "unknown", | |
5082 | "Router Link States", | |
5083 | "Net Link States", | |
5084 | "Summary Link States", | |
5085 | "ASBR-Summary Link States", | |
5086 | "AS External Link States", | |
5087 | "Group Membership LSA", | |
5088 | "NSSA-external Link States", | |
5089 | "Type-8 LSA", | |
5090 | "Link-Local Opaque-LSA", | |
5091 | "Area-Local Opaque-LSA", | |
5092 | "AS-external Opaque-LSA", | |
718e3744 | 5093 | }; |
5094 | ||
d62a17ae | 5095 | static const char *show_database_header[] = { |
5096 | "", | |
5097 | "Link ID ADV Router Age Seq# CkSum Link count", | |
5098 | "Link ID ADV Router Age Seq# CkSum", | |
5099 | "Link ID ADV Router Age Seq# CkSum Route", | |
5100 | "Link ID ADV Router Age Seq# CkSum", | |
5101 | "Link ID ADV Router Age Seq# CkSum Route", | |
5102 | " --- header for Group Member ----", | |
5103 | "Link ID ADV Router Age Seq# CkSum Route", | |
5104 | " --- type-8 ---", | |
5105 | "Opaque-Type/Id ADV Router Age Seq# CkSum", | |
5106 | "Opaque-Type/Id ADV Router Age Seq# CkSum", | |
5107 | "Opaque-Type/Id ADV Router Age Seq# CkSum", | |
718e3744 | 5108 | }; |
5109 | ||
d62a17ae | 5110 | static void show_ip_ospf_database_header(struct vty *vty, struct ospf_lsa *lsa) |
5111 | { | |
5112 | struct router_lsa *rlsa = (struct router_lsa *)lsa->data; | |
5113 | ||
5114 | vty_out(vty, " LS age: %d\n", LS_AGE(lsa)); | |
5115 | vty_out(vty, " Options: 0x%-2x : %s\n", lsa->data->options, | |
5116 | ospf_options_dump(lsa->data->options)); | |
5117 | vty_out(vty, " LS Flags: 0x%-2x %s\n", lsa->flags, | |
5118 | ((lsa->flags & OSPF_LSA_LOCAL_XLT) ? "(Translated from Type-7)" | |
5119 | : "")); | |
5120 | ||
5121 | if (lsa->data->type == OSPF_ROUTER_LSA) { | |
5122 | vty_out(vty, " Flags: 0x%x", rlsa->flags); | |
5123 | ||
5124 | if (rlsa->flags) | |
5125 | vty_out(vty, " :%s%s%s%s", | |
5126 | IS_ROUTER_LSA_BORDER(rlsa) ? " ABR" : "", | |
5127 | IS_ROUTER_LSA_EXTERNAL(rlsa) ? " ASBR" : "", | |
5128 | IS_ROUTER_LSA_VIRTUAL(rlsa) ? " VL-endpoint" | |
5129 | : "", | |
5130 | IS_ROUTER_LSA_SHORTCUT(rlsa) ? " Shortcut" | |
5131 | : ""); | |
5132 | ||
5133 | vty_out(vty, "\n"); | |
5134 | } | |
5135 | vty_out(vty, " LS Type: %s\n", | |
5136 | lookup_msg(ospf_lsa_type_msg, lsa->data->type, NULL)); | |
5137 | vty_out(vty, " Link State ID: %s %s\n", inet_ntoa(lsa->data->id), | |
5138 | lookup_msg(ospf_link_state_id_type_msg, lsa->data->type, NULL)); | |
5139 | vty_out(vty, " Advertising Router: %s\n", | |
5140 | inet_ntoa(lsa->data->adv_router)); | |
5141 | vty_out(vty, " LS Seq Number: %08lx\n", | |
5142 | (u_long)ntohl(lsa->data->ls_seqnum)); | |
5143 | vty_out(vty, " Checksum: 0x%04x\n", ntohs(lsa->data->checksum)); | |
5144 | vty_out(vty, " Length: %d\n\n", ntohs(lsa->data->length)); | |
5145 | } | |
5146 | ||
5147 | const char *link_type_desc[] = { | |
5148 | "(null)", | |
5149 | "another Router (point-to-point)", | |
5150 | "a Transit Network", | |
5151 | "Stub Network", | |
5152 | "a Virtual Link", | |
718e3744 | 5153 | }; |
5154 | ||
d62a17ae | 5155 | const char *link_id_desc[] = { |
5156 | "(null)", "Neighboring Router ID", "Designated Router address", | |
5157 | "Net", "Neighboring Router ID", | |
718e3744 | 5158 | }; |
5159 | ||
d62a17ae | 5160 | const char *link_data_desc[] = { |
5161 | "(null)", "Router Interface address", "Router Interface address", | |
5162 | "Network Mask", "Router Interface address", | |
718e3744 | 5163 | }; |
5164 | ||
5165 | /* Show router-LSA each Link information. */ | |
d62a17ae | 5166 | static void show_ip_ospf_database_router_links(struct vty *vty, |
5167 | struct router_lsa *rl) | |
5168 | { | |
5169 | int len, type; | |
5170 | unsigned int i; | |
5171 | ||
5172 | len = ntohs(rl->header.length) - 4; | |
5173 | for (i = 0; i < ntohs(rl->links) && len > 0; len -= 12, i++) { | |
5174 | type = rl->link[i].type; | |
5175 | ||
5176 | vty_out(vty, " Link connected to: %s\n", | |
5177 | link_type_desc[type]); | |
5178 | vty_out(vty, " (Link ID) %s: %s\n", link_id_desc[type], | |
5179 | inet_ntoa(rl->link[i].link_id)); | |
5180 | vty_out(vty, " (Link Data) %s: %s\n", link_data_desc[type], | |
5181 | inet_ntoa(rl->link[i].link_data)); | |
5182 | vty_out(vty, " Number of TOS metrics: 0\n"); | |
5183 | vty_out(vty, " TOS 0 Metric: %d\n", | |
5184 | ntohs(rl->link[i].metric)); | |
5185 | vty_out(vty, "\n"); | |
5186 | } | |
718e3744 | 5187 | } |
5188 | ||
5189 | /* Show router-LSA detail information. */ | |
d62a17ae | 5190 | static int show_router_lsa_detail(struct vty *vty, struct ospf_lsa *lsa) |
718e3744 | 5191 | { |
d62a17ae | 5192 | if (lsa != NULL) { |
5193 | struct router_lsa *rl = (struct router_lsa *)lsa->data; | |
718e3744 | 5194 | |
d62a17ae | 5195 | show_ip_ospf_database_header(vty, lsa); |
718e3744 | 5196 | |
d62a17ae | 5197 | vty_out(vty, " Number of Links: %d\n\n", ntohs(rl->links)); |
718e3744 | 5198 | |
d62a17ae | 5199 | show_ip_ospf_database_router_links(vty, rl); |
5200 | vty_out(vty, "\n"); | |
5201 | } | |
5202 | ||
5203 | return 0; | |
718e3744 | 5204 | } |
5205 | ||
5206 | /* Show network-LSA detail information. */ | |
d62a17ae | 5207 | static int show_network_lsa_detail(struct vty *vty, struct ospf_lsa *lsa) |
718e3744 | 5208 | { |
d62a17ae | 5209 | int length, i; |
718e3744 | 5210 | |
d62a17ae | 5211 | if (lsa != NULL) { |
5212 | struct network_lsa *nl = (struct network_lsa *)lsa->data; | |
718e3744 | 5213 | |
d62a17ae | 5214 | show_ip_ospf_database_header(vty, lsa); |
718e3744 | 5215 | |
d62a17ae | 5216 | vty_out(vty, " Network Mask: /%d\n", ip_masklen(nl->mask)); |
718e3744 | 5217 | |
d62a17ae | 5218 | length = ntohs(lsa->data->length) - OSPF_LSA_HEADER_SIZE - 4; |
718e3744 | 5219 | |
d62a17ae | 5220 | for (i = 0; length > 0; i++, length -= 4) |
5221 | vty_out(vty, " Attached Router: %s\n", | |
5222 | inet_ntoa(nl->routers[i])); | |
718e3744 | 5223 | |
d62a17ae | 5224 | vty_out(vty, "\n"); |
5225 | } | |
718e3744 | 5226 | |
d62a17ae | 5227 | return 0; |
718e3744 | 5228 | } |
5229 | ||
5230 | /* Show summary-LSA detail information. */ | |
d62a17ae | 5231 | static int show_summary_lsa_detail(struct vty *vty, struct ospf_lsa *lsa) |
718e3744 | 5232 | { |
d62a17ae | 5233 | if (lsa != NULL) { |
5234 | struct summary_lsa *sl = (struct summary_lsa *)lsa->data; | |
718e3744 | 5235 | |
d62a17ae | 5236 | show_ip_ospf_database_header(vty, lsa); |
718e3744 | 5237 | |
d62a17ae | 5238 | vty_out(vty, " Network Mask: /%d\n", ip_masklen(sl->mask)); |
5239 | vty_out(vty, " TOS: 0 Metric: %d\n", | |
5240 | GET_METRIC(sl->metric)); | |
5241 | vty_out(vty, "\n"); | |
5242 | } | |
718e3744 | 5243 | |
d62a17ae | 5244 | return 0; |
718e3744 | 5245 | } |
5246 | ||
5247 | /* Show summary-ASBR-LSA detail information. */ | |
d62a17ae | 5248 | static int show_summary_asbr_lsa_detail(struct vty *vty, struct ospf_lsa *lsa) |
718e3744 | 5249 | { |
d62a17ae | 5250 | if (lsa != NULL) { |
5251 | struct summary_lsa *sl = (struct summary_lsa *)lsa->data; | |
718e3744 | 5252 | |
d62a17ae | 5253 | show_ip_ospf_database_header(vty, lsa); |
718e3744 | 5254 | |
d62a17ae | 5255 | vty_out(vty, " Network Mask: /%d\n", ip_masklen(sl->mask)); |
5256 | vty_out(vty, " TOS: 0 Metric: %d\n", | |
5257 | GET_METRIC(sl->metric)); | |
5258 | vty_out(vty, "\n"); | |
5259 | } | |
718e3744 | 5260 | |
d62a17ae | 5261 | return 0; |
718e3744 | 5262 | } |
5263 | ||
5264 | /* Show AS-external-LSA detail information. */ | |
d62a17ae | 5265 | static int show_as_external_lsa_detail(struct vty *vty, struct ospf_lsa *lsa) |
5266 | { | |
5267 | if (lsa != NULL) { | |
5268 | struct as_external_lsa *al = | |
5269 | (struct as_external_lsa *)lsa->data; | |
5270 | ||
5271 | show_ip_ospf_database_header(vty, lsa); | |
5272 | ||
5273 | vty_out(vty, " Network Mask: /%d\n", ip_masklen(al->mask)); | |
5274 | vty_out(vty, " Metric Type: %s\n", | |
5275 | IS_EXTERNAL_METRIC(al->e[0].tos) | |
5276 | ? "2 (Larger than any link state path)" | |
5277 | : "1"); | |
5278 | vty_out(vty, " TOS: 0\n"); | |
5279 | vty_out(vty, " Metric: %d\n", | |
5280 | GET_METRIC(al->e[0].metric)); | |
5281 | vty_out(vty, " Forward Address: %s\n", | |
5282 | inet_ntoa(al->e[0].fwd_addr)); | |
5283 | ||
5284 | vty_out(vty, | |
5285 | " External Route Tag: %" ROUTE_TAG_PRI "\n\n", | |
5286 | (route_tag_t)ntohl(al->e[0].route_tag)); | |
5287 | } | |
718e3744 | 5288 | |
d62a17ae | 5289 | return 0; |
718e3744 | 5290 | } |
075e12f5 | 5291 | #if 0 |
4dadc291 | 5292 | static int |
718e3744 | 5293 | show_as_external_lsa_stdvty (struct ospf_lsa *lsa) |
5294 | { | |
5295 | struct as_external_lsa *al = (struct as_external_lsa *) lsa->data; | |
5296 | ||
5297 | /* show_ip_ospf_database_header (vty, lsa); */ | |
5298 | ||
2a42e285 | 5299 | zlog_debug( " Network Mask: /%d%s", |
718e3744 | 5300 | ip_masklen (al->mask), "\n"); |
2a42e285 | 5301 | zlog_debug( " Metric Type: %s%s", |
718e3744 | 5302 | IS_EXTERNAL_METRIC (al->e[0].tos) ? |
5303 | "2 (Larger than any link state path)" : "1", "\n"); | |
2a42e285 | 5304 | zlog_debug( " TOS: 0%s", "\n"); |
5305 | zlog_debug( " Metric: %d%s", | |
718e3744 | 5306 | GET_METRIC (al->e[0].metric), "\n"); |
2a42e285 | 5307 | zlog_debug( " Forward Address: %s%s", |
718e3744 | 5308 | inet_ntoa (al->e[0].fwd_addr), "\n"); |
5309 | ||
dc9ffce8 CF |
5310 | zlog_debug( " External Route Tag: %"ROUTE_TAG_PRI"%s%s", |
5311 | (route_tag_t)ntohl (al->e[0].route_tag), "\n", "\n"); | |
718e3744 | 5312 | |
5313 | return 0; | |
5314 | } | |
075e12f5 | 5315 | #endif |
718e3744 | 5316 | /* Show AS-NSSA-LSA detail information. */ |
d62a17ae | 5317 | static int show_as_nssa_lsa_detail(struct vty *vty, struct ospf_lsa *lsa) |
5318 | { | |
5319 | if (lsa != NULL) { | |
5320 | struct as_external_lsa *al = | |
5321 | (struct as_external_lsa *)lsa->data; | |
5322 | ||
5323 | show_ip_ospf_database_header(vty, lsa); | |
5324 | ||
5325 | vty_out(vty, " Network Mask: /%d\n", ip_masklen(al->mask)); | |
5326 | vty_out(vty, " Metric Type: %s\n", | |
5327 | IS_EXTERNAL_METRIC(al->e[0].tos) | |
5328 | ? "2 (Larger than any link state path)" | |
5329 | : "1"); | |
5330 | vty_out(vty, " TOS: 0\n"); | |
5331 | vty_out(vty, " Metric: %d\n", | |
5332 | GET_METRIC(al->e[0].metric)); | |
5333 | vty_out(vty, " NSSA: Forward Address: %s\n", | |
5334 | inet_ntoa(al->e[0].fwd_addr)); | |
5335 | ||
5336 | vty_out(vty, | |
5337 | " External Route Tag: %" ROUTE_TAG_PRI "\n\n", | |
5338 | (route_tag_t)ntohl(al->e[0].route_tag)); | |
5339 | } | |
718e3744 | 5340 | |
d62a17ae | 5341 | return 0; |
718e3744 | 5342 | } |
5343 | ||
d62a17ae | 5344 | static int show_func_dummy(struct vty *vty, struct ospf_lsa *lsa) |
718e3744 | 5345 | { |
d62a17ae | 5346 | return 0; |
718e3744 | 5347 | } |
5348 | ||
d62a17ae | 5349 | static int show_opaque_lsa_detail(struct vty *vty, struct ospf_lsa *lsa) |
718e3744 | 5350 | { |
d62a17ae | 5351 | if (lsa != NULL) { |
5352 | show_ip_ospf_database_header(vty, lsa); | |
5353 | show_opaque_info_detail(vty, lsa); | |
718e3744 | 5354 | |
d62a17ae | 5355 | vty_out(vty, "\n"); |
5356 | } | |
5357 | return 0; | |
5358 | } | |
5359 | ||
5360 | int (*show_function[])(struct vty *, struct ospf_lsa *) = { | |
5361 | NULL, | |
5362 | show_router_lsa_detail, | |
5363 | show_network_lsa_detail, | |
5364 | show_summary_lsa_detail, | |
5365 | show_summary_asbr_lsa_detail, | |
5366 | show_as_external_lsa_detail, | |
5367 | show_func_dummy, | |
5368 | show_as_nssa_lsa_detail, /* almost same as external */ | |
5369 | NULL, /* type-8 */ | |
5370 | show_opaque_lsa_detail, | |
5371 | show_opaque_lsa_detail, | |
5372 | show_opaque_lsa_detail, | |
5373 | }; | |
5374 | ||
5375 | static void show_lsa_prefix_set(struct vty *vty, struct prefix_ls *lp, | |
5376 | struct in_addr *id, struct in_addr *adv_router) | |
5377 | { | |
5378 | memset(lp, 0, sizeof(struct prefix_ls)); | |
5379 | lp->family = 0; | |
5380 | if (id == NULL) | |
5381 | lp->prefixlen = 0; | |
5382 | else if (adv_router == NULL) { | |
5383 | lp->prefixlen = 32; | |
5384 | lp->id = *id; | |
5385 | } else { | |
5386 | lp->prefixlen = 64; | |
5387 | lp->id = *id; | |
5388 | lp->adv_router = *adv_router; | |
5389 | } | |
718e3744 | 5390 | } |
718e3744 | 5391 | |
d62a17ae | 5392 | static void show_lsa_detail_proc(struct vty *vty, struct route_table *rt, |
5393 | struct in_addr *id, struct in_addr *adv_router) | |
5394 | { | |
5395 | struct prefix_ls lp; | |
5396 | struct route_node *rn, *start; | |
5397 | struct ospf_lsa *lsa; | |
718e3744 | 5398 | |
d62a17ae | 5399 | show_lsa_prefix_set(vty, &lp, id, adv_router); |
5400 | start = route_node_get(rt, (struct prefix *)&lp); | |
5401 | if (start) { | |
5402 | route_lock_node(start); | |
5403 | for (rn = start; rn; rn = route_next_until(rn, start)) | |
5404 | if ((lsa = rn->info)) { | |
5405 | if (show_function[lsa->data->type] != NULL) | |
5406 | show_function[lsa->data->type](vty, | |
5407 | lsa); | |
5408 | } | |
5409 | route_unlock_node(start); | |
5410 | } | |
718e3744 | 5411 | } |
5412 | ||
5413 | /* Show detail LSA information | |
5414 | -- if id is NULL then show all LSAs. */ | |
d62a17ae | 5415 | static void show_lsa_detail(struct vty *vty, struct ospf *ospf, int type, |
5416 | struct in_addr *id, struct in_addr *adv_router) | |
5417 | { | |
5418 | struct listnode *node; | |
5419 | struct ospf_area *area; | |
5420 | ||
5421 | switch (type) { | |
5422 | case OSPF_AS_EXTERNAL_LSA: | |
5423 | case OSPF_OPAQUE_AS_LSA: | |
5424 | vty_out(vty, " %s \n\n", | |
5425 | show_database_desc[type]); | |
5426 | show_lsa_detail_proc(vty, AS_LSDB(ospf, type), id, adv_router); | |
5427 | break; | |
5428 | default: | |
5429 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) { | |
5430 | vty_out(vty, "\n %s (Area %s)\n\n", | |
5431 | show_database_desc[type], | |
5432 | ospf_area_desc_string(area)); | |
5433 | show_lsa_detail_proc(vty, AREA_LSDB(area, type), id, | |
5434 | adv_router); | |
5435 | } | |
5436 | break; | |
718e3744 | 5437 | } |
5438 | } | |
5439 | ||
d62a17ae | 5440 | static void show_lsa_detail_adv_router_proc(struct vty *vty, |
5441 | struct route_table *rt, | |
5442 | struct in_addr *adv_router) | |
5443 | { | |
5444 | struct route_node *rn; | |
5445 | struct ospf_lsa *lsa; | |
5446 | ||
5447 | for (rn = route_top(rt); rn; rn = route_next(rn)) | |
5448 | if ((lsa = rn->info)) | |
5449 | if (IPV4_ADDR_SAME(adv_router, | |
5450 | &lsa->data->adv_router)) { | |
5451 | if (CHECK_FLAG(lsa->flags, OSPF_LSA_LOCAL_XLT)) | |
5452 | continue; | |
5453 | if (show_function[lsa->data->type] != NULL) | |
5454 | show_function[lsa->data->type](vty, | |
5455 | lsa); | |
5456 | } | |
5457 | } | |
5458 | ||
718e3744 | 5459 | /* Show detail LSA information. */ |
d62a17ae | 5460 | static void show_lsa_detail_adv_router(struct vty *vty, struct ospf *ospf, |
5461 | int type, struct in_addr *adv_router) | |
5462 | { | |
5463 | struct listnode *node; | |
5464 | struct ospf_area *area; | |
5465 | ||
5466 | switch (type) { | |
5467 | case OSPF_AS_EXTERNAL_LSA: | |
5468 | case OSPF_OPAQUE_AS_LSA: | |
5469 | vty_out(vty, " %s \n\n", | |
5470 | show_database_desc[type]); | |
5471 | show_lsa_detail_adv_router_proc(vty, AS_LSDB(ospf, type), | |
5472 | adv_router); | |
5473 | break; | |
5474 | default: | |
5475 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) { | |
5476 | vty_out(vty, "\n %s (Area %s)\n\n", | |
5477 | show_database_desc[type], | |
5478 | ospf_area_desc_string(area)); | |
5479 | show_lsa_detail_adv_router_proc( | |
5480 | vty, AREA_LSDB(area, type), adv_router); | |
5481 | } | |
5482 | break; | |
5483 | } | |
5484 | } | |
5485 | ||
5486 | static void show_ip_ospf_database_summary(struct vty *vty, struct ospf *ospf, | |
5487 | int self) | |
5488 | { | |
5489 | struct ospf_lsa *lsa; | |
5490 | struct route_node *rn; | |
5491 | struct ospf_area *area; | |
5492 | struct listnode *node; | |
5493 | int type; | |
5494 | ||
5495 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) { | |
5496 | for (type = OSPF_MIN_LSA; type < OSPF_MAX_LSA; type++) { | |
5497 | switch (type) { | |
5498 | case OSPF_AS_EXTERNAL_LSA: | |
5499 | case OSPF_OPAQUE_AS_LSA: | |
5500 | continue; | |
5501 | default: | |
5502 | break; | |
5503 | } | |
5504 | if (ospf_lsdb_count_self(area->lsdb, type) > 0 | |
5505 | || (!self | |
5506 | && ospf_lsdb_count(area->lsdb, type) > 0)) { | |
5507 | vty_out(vty, " %s (Area %s)\n\n", | |
5508 | show_database_desc[type], | |
5509 | ospf_area_desc_string(area)); | |
5510 | vty_out(vty, "%s\n", | |
5511 | show_database_header[type]); | |
5512 | ||
5513 | LSDB_LOOP(AREA_LSDB(area, type), rn, lsa) | |
5514 | show_lsa_summary(vty, lsa, self); | |
5515 | ||
5516 | vty_out(vty, "\n"); | |
5517 | } | |
5518 | } | |
5519 | } | |
5520 | ||
5521 | for (type = OSPF_MIN_LSA; type < OSPF_MAX_LSA; type++) { | |
5522 | switch (type) { | |
5523 | case OSPF_AS_EXTERNAL_LSA: | |
5524 | case OSPF_OPAQUE_AS_LSA: | |
5525 | break; | |
5526 | default: | |
5527 | continue; | |
5528 | } | |
5529 | if (ospf_lsdb_count_self(ospf->lsdb, type) | |
5530 | || (!self && ospf_lsdb_count(ospf->lsdb, type))) { | |
5531 | vty_out(vty, " %s\n\n", | |
5532 | show_database_desc[type]); | |
5533 | vty_out(vty, "%s\n", show_database_header[type]); | |
5534 | ||
5535 | LSDB_LOOP(AS_LSDB(ospf, type), rn, lsa) | |
5536 | show_lsa_summary(vty, lsa, self); | |
5537 | ||
5538 | vty_out(vty, "\n"); | |
5539 | } | |
5540 | } | |
5541 | ||
5542 | vty_out(vty, "\n"); | |
5543 | } | |
5544 | ||
5545 | static void show_ip_ospf_database_maxage(struct vty *vty, struct ospf *ospf) | |
5546 | { | |
5547 | struct route_node *rn; | |
5548 | ||
5549 | vty_out(vty, "\n MaxAge Link States:\n\n"); | |
5550 | ||
5551 | for (rn = route_top(ospf->maxage_lsa); rn; rn = route_next(rn)) { | |
5552 | struct ospf_lsa *lsa; | |
5553 | ||
5554 | if ((lsa = rn->info) != NULL) { | |
5555 | vty_out(vty, "Link type: %d\n", lsa->data->type); | |
5556 | vty_out(vty, "Link State ID: %s\n", | |
5557 | inet_ntoa(lsa->data->id)); | |
5558 | vty_out(vty, "Advertising Router: %s\n", | |
5559 | inet_ntoa(lsa->data->adv_router)); | |
5560 | vty_out(vty, "LSA lock count: %d\n", lsa->lock); | |
5561 | vty_out(vty, "\n"); | |
5562 | } | |
91e6a0e5 | 5563 | } |
718e3744 | 5564 | } |
5565 | ||
718e3744 | 5566 | #define OSPF_LSA_TYPE_NSSA_DESC "NSSA external link state\n" |
5567 | #define OSPF_LSA_TYPE_NSSA_CMD_STR "|nssa-external" | |
718e3744 | 5568 | |
718e3744 | 5569 | #define OSPF_LSA_TYPE_OPAQUE_LINK_DESC "Link local Opaque-LSA\n" |
5570 | #define OSPF_LSA_TYPE_OPAQUE_AREA_DESC "Link area Opaque-LSA\n" | |
5571 | #define OSPF_LSA_TYPE_OPAQUE_AS_DESC "Link AS Opaque-LSA\n" | |
5572 | #define OSPF_LSA_TYPE_OPAQUE_CMD_STR "|opaque-link|opaque-area|opaque-as" | |
718e3744 | 5573 | |
d62a17ae | 5574 | #define OSPF_LSA_TYPES_DESC \ |
5575 | "ASBR summary link states\n" \ | |
5576 | "External link states\n" \ | |
5577 | "Network link states\n" \ | |
5578 | "Router link states\n" \ | |
5579 | "Network summary link states\n" OSPF_LSA_TYPE_NSSA_DESC \ | |
5580 | OSPF_LSA_TYPE_OPAQUE_LINK_DESC OSPF_LSA_TYPE_OPAQUE_AREA_DESC \ | |
5581 | OSPF_LSA_TYPE_OPAQUE_AS_DESC | |
5582 | ||
5583 | static int show_ip_ospf_database_common(struct vty *vty, struct ospf *ospf, | |
5584 | int arg_base, int argc, | |
5585 | struct cmd_token **argv) | |
5586 | { | |
5587 | int idx_type = 4; | |
5588 | int type, ret; | |
5589 | struct in_addr id, adv_router; | |
5590 | ||
5591 | if (ospf->instance) | |
5592 | vty_out(vty, "\nOSPF Instance: %d\n", ospf->instance); | |
5593 | ||
5594 | vty_out(vty, "\n OSPF Router with ID (%s)\n\n", | |
5595 | inet_ntoa(ospf->router_id)); | |
5596 | ||
5597 | /* Show all LSA. */ | |
5598 | if (argc == arg_base + 4) { | |
5599 | show_ip_ospf_database_summary(vty, ospf, 0); | |
5600 | return CMD_SUCCESS; | |
5601 | } | |
718e3744 | 5602 | |
d62a17ae | 5603 | /* Set database type to show. */ |
5604 | if (strncmp(argv[arg_base + idx_type]->text, "r", 1) == 0) | |
5605 | type = OSPF_ROUTER_LSA; | |
5606 | else if (strncmp(argv[arg_base + idx_type]->text, "ne", 2) == 0) | |
5607 | type = OSPF_NETWORK_LSA; | |
5608 | else if (strncmp(argv[arg_base + idx_type]->text, "ns", 2) == 0) | |
5609 | type = OSPF_AS_NSSA_LSA; | |
5610 | else if (strncmp(argv[arg_base + idx_type]->text, "su", 2) == 0) | |
5611 | type = OSPF_SUMMARY_LSA; | |
5612 | else if (strncmp(argv[arg_base + idx_type]->text, "a", 1) == 0) | |
5613 | type = OSPF_ASBR_SUMMARY_LSA; | |
5614 | else if (strncmp(argv[arg_base + idx_type]->text, "e", 1) == 0) | |
5615 | type = OSPF_AS_EXTERNAL_LSA; | |
5616 | else if (strncmp(argv[arg_base + idx_type]->text, "se", 2) == 0) { | |
5617 | show_ip_ospf_database_summary(vty, ospf, 1); | |
5618 | return CMD_SUCCESS; | |
5619 | } else if (strncmp(argv[arg_base + idx_type]->text, "m", 1) == 0) { | |
5620 | show_ip_ospf_database_maxage(vty, ospf); | |
5621 | return CMD_SUCCESS; | |
5622 | } else if (strncmp(argv[arg_base + idx_type]->text, "opaque-l", 8) == 0) | |
5623 | type = OSPF_OPAQUE_LINK_LSA; | |
5624 | else if (strncmp(argv[arg_base + idx_type]->text, "opaque-ar", 9) == 0) | |
5625 | type = OSPF_OPAQUE_AREA_LSA; | |
5626 | else if (strncmp(argv[arg_base + idx_type]->text, "opaque-as", 9) == 0) | |
5627 | type = OSPF_OPAQUE_AS_LSA; | |
5628 | else | |
718e3744 | 5629 | return CMD_WARNING; |
d62a17ae | 5630 | |
5631 | /* `show ip ospf database LSA'. */ | |
5632 | if (argc == arg_base + 5) | |
5633 | show_lsa_detail(vty, ospf, type, NULL, NULL); | |
5634 | else if (argc >= arg_base + 6) { | |
5635 | ret = inet_aton(argv[arg_base + 5]->arg, &id); | |
5636 | if (!ret) | |
5637 | return CMD_WARNING; | |
5638 | ||
5639 | /* `show ip ospf database LSA ID'. */ | |
5640 | if (argc == arg_base + 6) | |
5641 | show_lsa_detail(vty, ospf, type, &id, NULL); | |
5642 | /* `show ip ospf database LSA ID adv-router ADV_ROUTER'. */ | |
5643 | else if (argc == arg_base + 7) { | |
5644 | if (strncmp(argv[arg_base + 6]->text, "s", 1) == 0) | |
5645 | adv_router = ospf->router_id; | |
5646 | else { | |
5647 | ret = inet_aton(argv[arg_base + 7]->arg, | |
5648 | &adv_router); | |
5649 | if (!ret) | |
5650 | return CMD_WARNING; | |
5651 | } | |
5652 | show_lsa_detail(vty, ospf, type, &id, &adv_router); | |
5653 | } | |
718e3744 | 5654 | } |
718e3744 | 5655 | |
d62a17ae | 5656 | return CMD_SUCCESS; |
718e3744 | 5657 | } |
5658 | ||
7a7be519 | 5659 | DEFUN (show_ip_ospf_database_max, |
5660 | show_ip_ospf_database_max_cmd, | |
b5a8894d | 5661 | "show ip ospf [vrf <NAME|all>] database <max-age|self-originate>", |
7a7be519 | 5662 | SHOW_STR |
5663 | IP_STR | |
5664 | "OSPF information\n" | |
b5a8894d CS |
5665 | VRF_CMD_HELP_STR |
5666 | "All VRFs\n" | |
7a7be519 | 5667 | "Database summary\n" |
5668 | "LSAs in MaxAge list\n" | |
5669 | "Self-originated link states\n") | |
5670 | { | |
b5a8894d CS |
5671 | struct ospf *ospf = NULL; |
5672 | struct listnode *node = NULL; | |
5673 | char *vrf_name = NULL; | |
5674 | bool all_vrf = FALSE; | |
5675 | int ret = CMD_SUCCESS; | |
5676 | int inst = 0; | |
5677 | int idx_vrf = 0; | |
f412b39a | 5678 | |
43b8d1d8 | 5679 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
f412b39a | 5680 | |
b5a8894d CS |
5681 | if (vrf_name) { |
5682 | if (all_vrf) { | |
5683 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
5684 | if (!ospf->oi_running) | |
5685 | continue; | |
5686 | ret = show_ip_ospf_database_common(vty, ospf, | |
5687 | idx_vrf ? 2 | |
5688 | : 0, argc, | |
5689 | argv); | |
5690 | } | |
5691 | } else { | |
5692 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
5693 | if (ospf == NULL || !ospf->oi_running) | |
5694 | return CMD_SUCCESS; | |
5695 | ret = (show_ip_ospf_database_common(vty, ospf, idx_vrf ? | |
5696 | 2 : 0, argc, argv)); | |
5697 | } | |
5698 | } else { | |
5699 | /* Display default ospf (instance 0) info */ | |
5700 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
5701 | if (ospf == NULL || !ospf->oi_running) | |
5702 | return CMD_SUCCESS; | |
5703 | ret = show_ip_ospf_database_common(vty, ospf, 0, argc, argv); | |
5704 | } | |
5705 | ||
5706 | return ret; | |
7a7be519 | 5707 | } |
f412b39a | 5708 | |
f412b39a DW |
5709 | DEFUN (show_ip_ospf_instance_database, |
5710 | show_ip_ospf_instance_database_cmd, | |
43b8d1d8 | 5711 | "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 | 5712 | SHOW_STR |
5713 | IP_STR | |
5714 | "OSPF information\n" | |
7c8ff89e | 5715 | "Instance ID\n" |
b5a8894d | 5716 | VRF_CMD_HELP_STR |
7a7be519 | 5717 | "Database summary\n" |
5718 | OSPF_LSA_TYPES_DESC | |
5719 | "Link State ID (as an IP address)\n" | |
5720 | "Self-originated link states\n" | |
5721 | "Advertising Router link states\n" | |
5722 | "Advertising Router (as an IP address)\n") | |
7c8ff89e | 5723 | { |
d62a17ae | 5724 | struct ospf *ospf; |
5725 | u_short instance = 0; | |
b5a8894d CS |
5726 | struct listnode *node = NULL; |
5727 | char *vrf_name = NULL; | |
5728 | bool all_vrf = FALSE; | |
5729 | int ret = CMD_SUCCESS; | |
5730 | int inst = 0; | |
d62a17ae | 5731 | int idx = 0; |
b5a8894d | 5732 | |
d62a17ae | 5733 | if (argv_find(argv, argc, "(1-65535)", &idx)) { |
5734 | instance = strtoul(argv[idx]->arg, NULL, 10); | |
5735 | ospf = ospf_lookup_instance(instance); | |
ac28e4ec CS |
5736 | if (ospf == NULL) |
5737 | return CMD_NOT_MY_INSTANCE; | |
b5a8894d CS |
5738 | if (!ospf->oi_running) |
5739 | return CMD_SUCCESS; | |
5740 | ||
5741 | return (show_ip_ospf_database_common(vty, ospf, idx ? 1 : 0, | |
5742 | argc, argv)); | |
5743 | } else if (argv_find(argv, argc, "vrf", &idx)) { | |
5744 | vrf_name = argv[++idx]->arg; | |
5745 | all_vrf = strmatch(vrf_name, "all"); | |
d62a17ae | 5746 | } |
7c8ff89e | 5747 | |
b5a8894d CS |
5748 | if (vrf_name) { |
5749 | if (all_vrf) { | |
5750 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
5751 | if (!ospf->oi_running) | |
5752 | continue; | |
5753 | ret = (show_ip_ospf_database_common(vty, ospf, | |
5754 | idx ? 2 : 0, | |
5755 | argc, argv)); | |
5756 | } | |
5757 | } else { | |
5758 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
5759 | if ((ospf == NULL) || !ospf->oi_running) | |
5760 | return CMD_SUCCESS; | |
5761 | ret = (show_ip_ospf_database_common(vty, ospf, idx ? 2 : | |
5762 | 0, argc, argv)); | |
5763 | } | |
5764 | } else { | |
5765 | /* Display default ospf (instance 0) info */ | |
5766 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
5767 | if (ospf == NULL || !ospf->oi_running) | |
5768 | return CMD_SUCCESS; | |
5769 | ret = (show_ip_ospf_database_common(vty, ospf, 0, argc, argv)); | |
5770 | } | |
7c8ff89e | 5771 | |
b5a8894d | 5772 | return ret; |
7c8ff89e DS |
5773 | } |
5774 | ||
7a7be519 | 5775 | DEFUN (show_ip_ospf_instance_database_max, |
5776 | show_ip_ospf_instance_database_max_cmd, | |
5777 | "show ip ospf (1-65535) database <max-age|self-originate>", | |
5778 | SHOW_STR | |
5779 | IP_STR | |
5780 | "OSPF information\n" | |
5781 | "Instance ID\n" | |
5782 | "Database summary\n" | |
5783 | "LSAs in MaxAge list\n" | |
5784 | "Self-originated link states\n") | |
5785 | { | |
d62a17ae | 5786 | int idx_number = 3; |
5787 | struct ospf *ospf; | |
5788 | u_short instance = 0; | |
5789 | ||
5790 | instance = strtoul(argv[idx_number]->arg, NULL, 10); | |
5791 | ||
ac28e4ec CS |
5792 | ospf = ospf_lookup_instance(instance); |
5793 | if (ospf == NULL) | |
5794 | return CMD_NOT_MY_INSTANCE; | |
5795 | ||
5796 | if (!ospf->oi_running) | |
d62a17ae | 5797 | return CMD_SUCCESS; |
5798 | ||
5799 | return (show_ip_ospf_database_common(vty, ospf, 1, argc, argv)); | |
5800 | } | |
5801 | ||
5802 | ||
5803 | static int show_ip_ospf_database_type_adv_router_common(struct vty *vty, | |
5804 | struct ospf *ospf, | |
5805 | int arg_base, int argc, | |
5806 | struct cmd_token **argv) | |
5807 | { | |
5808 | int idx_type = 4; | |
5809 | int type, ret; | |
5810 | struct in_addr adv_router; | |
5811 | ||
5812 | if (ospf->instance) | |
5813 | vty_out(vty, "\nOSPF Instance: %d\n", ospf->instance); | |
5814 | ||
5815 | vty_out(vty, "\n OSPF Router with ID (%s)\n\n", | |
5816 | inet_ntoa(ospf->router_id)); | |
5817 | ||
5818 | /* Set database type to show. */ | |
5819 | if (strncmp(argv[arg_base + idx_type]->text, "r", 1) == 0) | |
5820 | type = OSPF_ROUTER_LSA; | |
5821 | else if (strncmp(argv[arg_base + idx_type]->text, "ne", 2) == 0) | |
5822 | type = OSPF_NETWORK_LSA; | |
5823 | else if (strncmp(argv[arg_base + idx_type]->text, "ns", 2) == 0) | |
5824 | type = OSPF_AS_NSSA_LSA; | |
5825 | else if (strncmp(argv[arg_base + idx_type]->text, "s", 1) == 0) | |
5826 | type = OSPF_SUMMARY_LSA; | |
5827 | else if (strncmp(argv[arg_base + idx_type]->text, "a", 1) == 0) | |
5828 | type = OSPF_ASBR_SUMMARY_LSA; | |
5829 | else if (strncmp(argv[arg_base + idx_type]->text, "e", 1) == 0) | |
5830 | type = OSPF_AS_EXTERNAL_LSA; | |
5831 | else if (strncmp(argv[arg_base + idx_type]->text, "opaque-l", 8) == 0) | |
5832 | type = OSPF_OPAQUE_LINK_LSA; | |
5833 | else if (strncmp(argv[arg_base + idx_type]->text, "opaque-ar", 9) == 0) | |
5834 | type = OSPF_OPAQUE_AREA_LSA; | |
5835 | else if (strncmp(argv[arg_base + idx_type]->text, "opaque-as", 9) == 0) | |
5836 | type = OSPF_OPAQUE_AS_LSA; | |
5837 | else | |
5838 | return CMD_WARNING; | |
7c8ff89e | 5839 | |
d62a17ae | 5840 | /* `show ip ospf database LSA adv-router ADV_ROUTER'. */ |
5841 | if (strncmp(argv[arg_base + 5]->text, "s", 1) == 0) | |
5842 | adv_router = ospf->router_id; | |
5843 | else { | |
5844 | ret = inet_aton(argv[arg_base + 6]->arg, &adv_router); | |
5845 | if (!ret) | |
5846 | return CMD_WARNING; | |
5847 | } | |
7c8ff89e | 5848 | |
d62a17ae | 5849 | show_lsa_detail_adv_router(vty, ospf, type, &adv_router); |
7c8ff89e | 5850 | |
d62a17ae | 5851 | return CMD_SUCCESS; |
7c8ff89e DS |
5852 | } |
5853 | ||
7c8ff89e DS |
5854 | DEFUN (show_ip_ospf_instance_database_type_adv_router, |
5855 | show_ip_ospf_instance_database_type_adv_router_cmd, | |
43b8d1d8 | 5856 | "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 |
5857 | SHOW_STR |
5858 | IP_STR | |
5859 | "OSPF information\n" | |
5860 | "Instance ID\n" | |
b5a8894d | 5861 | VRF_CMD_HELP_STR |
7c8ff89e DS |
5862 | "Database summary\n" |
5863 | OSPF_LSA_TYPES_DESC | |
5864 | "Advertising Router link states\n" | |
3a2d747c QY |
5865 | "Advertising Router (as an IP address)\n" |
5866 | "Self-originated link states\n") | |
7c8ff89e | 5867 | { |
b5a8894d | 5868 | struct ospf *ospf = NULL; |
d62a17ae | 5869 | u_short instance = 0; |
b5a8894d CS |
5870 | struct listnode *node = NULL; |
5871 | char *vrf_name = NULL; | |
5872 | bool all_vrf = FALSE; | |
5873 | int ret = CMD_SUCCESS; | |
5874 | int inst = 0; | |
43b8d1d8 | 5875 | int idx = 0, idx_vrf = 0; |
7c8ff89e | 5876 | |
d62a17ae | 5877 | if (argv_find(argv, argc, "(1-65535)", &idx)) { |
5878 | instance = strtoul(argv[idx]->arg, NULL, 10); | |
5879 | ospf = ospf_lookup_instance(instance); | |
ac28e4ec CS |
5880 | if (ospf == NULL) |
5881 | return CMD_NOT_MY_INSTANCE; | |
b5a8894d CS |
5882 | if (!ospf->oi_running) |
5883 | return CMD_SUCCESS; | |
5884 | return (show_ip_ospf_database_type_adv_router_common(vty, ospf, | |
5885 | idx ? 1 : 0, | |
5886 | argc, | |
5887 | argv)); | |
5888 | } | |
43b8d1d8 CS |
5889 | |
5890 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); | |
5891 | ||
b5a8894d CS |
5892 | if (vrf_name) { |
5893 | if (all_vrf) { | |
5894 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
5895 | if (!ospf->oi_running) | |
5896 | continue; | |
5897 | ret = show_ip_ospf_database_type_adv_router_common(vty, | |
5898 | ospf, idx ? 1 : 0, argc, argv); | |
5899 | } | |
5900 | } else { | |
5901 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
5902 | if ((ospf == NULL) || !ospf->oi_running) | |
5903 | return CMD_SUCCESS; | |
5904 | ret = show_ip_ospf_database_type_adv_router_common(vty, | |
5905 | ospf, idx ? 1 : 0, argc, argv); | |
5906 | } | |
5907 | } else { | |
5908 | /* Display default ospf (instance 0) info */ | |
5909 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
5910 | if (ospf == NULL || !ospf->oi_running) | |
5911 | return CMD_SUCCESS; | |
5912 | ret = show_ip_ospf_database_type_adv_router_common(vty, ospf, | |
5913 | idx ? 1 : 0, | |
5914 | argc, argv); | |
5915 | } | |
5916 | return ret; | |
5917 | /*return (show_ip_ospf_database_type_adv_router_common( | |
5918 | vty, ospf, idx ? 1 : 0, argc, argv));*/ | |
718e3744 | 5919 | } |
5920 | ||
718e3744 | 5921 | DEFUN (ip_ospf_authentication_args, |
5922 | ip_ospf_authentication_args_addr_cmd, | |
7a7be519 | 5923 | "ip ospf authentication <null|message-digest> [A.B.C.D]", |
718e3744 | 5924 | "IP Information\n" |
5925 | "OSPF interface commands\n" | |
5926 | "Enable authentication on this interface\n" | |
5927 | "Use null authentication\n" | |
5928 | "Use message-digest authentication\n" | |
7a7be519 | 5929 | "Address of interface\n") |
718e3744 | 5930 | { |
d62a17ae | 5931 | VTY_DECLVAR_CONTEXT(interface, ifp); |
5932 | int idx_encryption = 3; | |
5933 | int idx_ipv4 = 4; | |
5934 | struct in_addr addr; | |
5935 | int ret; | |
5936 | struct ospf_if_params *params; | |
5937 | ||
5938 | params = IF_DEF_PARAMS(ifp); | |
5939 | ||
5940 | if (argc == 5) { | |
5941 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
5942 | if (!ret) { | |
5943 | vty_out(vty, | |
5944 | "Please specify interface address by A.B.C.D\n"); | |
5945 | return CMD_WARNING_CONFIG_FAILED; | |
5946 | } | |
718e3744 | 5947 | |
d62a17ae | 5948 | params = ospf_get_if_params(ifp, addr); |
5949 | ospf_if_update_params(ifp, addr); | |
5950 | } | |
718e3744 | 5951 | |
d62a17ae | 5952 | /* Handle null authentication */ |
5953 | if (argv[idx_encryption]->arg[0] == 'n') { | |
5954 | SET_IF_PARAM(params, auth_type); | |
5955 | params->auth_type = OSPF_AUTH_NULL; | |
5956 | return CMD_SUCCESS; | |
5957 | } | |
718e3744 | 5958 | |
d62a17ae | 5959 | /* Handle message-digest authentication */ |
5960 | if (argv[idx_encryption]->arg[0] == 'm') { | |
5961 | SET_IF_PARAM(params, auth_type); | |
5962 | params->auth_type = OSPF_AUTH_CRYPTOGRAPHIC; | |
5963 | return CMD_SUCCESS; | |
5964 | } | |
718e3744 | 5965 | |
d62a17ae | 5966 | vty_out(vty, "You shouldn't get here!\n"); |
5967 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 5968 | } |
5969 | ||
718e3744 | 5970 | DEFUN (ip_ospf_authentication, |
5971 | ip_ospf_authentication_addr_cmd, | |
7a7be519 | 5972 | "ip ospf authentication [A.B.C.D]", |
718e3744 | 5973 | "IP Information\n" |
5974 | "OSPF interface commands\n" | |
5975 | "Enable authentication on this interface\n" | |
5976 | "Address of interface") | |
5977 | { | |
d62a17ae | 5978 | VTY_DECLVAR_CONTEXT(interface, ifp); |
5979 | int idx_ipv4 = 3; | |
5980 | struct in_addr addr; | |
5981 | int ret; | |
5982 | struct ospf_if_params *params; | |
5983 | ||
5984 | params = IF_DEF_PARAMS(ifp); | |
5985 | ||
5986 | if (argc == 4) { | |
5987 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
5988 | if (!ret) { | |
5989 | vty_out(vty, | |
5990 | "Please specify interface address by A.B.C.D\n"); | |
5991 | return CMD_WARNING_CONFIG_FAILED; | |
5992 | } | |
5993 | ||
5994 | params = ospf_get_if_params(ifp, addr); | |
5995 | ospf_if_update_params(ifp, addr); | |
718e3744 | 5996 | } |
5997 | ||
d62a17ae | 5998 | SET_IF_PARAM(params, auth_type); |
5999 | params->auth_type = OSPF_AUTH_SIMPLE; | |
718e3744 | 6000 | |
d62a17ae | 6001 | return CMD_SUCCESS; |
718e3744 | 6002 | } |
6003 | ||
b4a039bf DS |
6004 | DEFUN (no_ip_ospf_authentication_args, |
6005 | no_ip_ospf_authentication_args_addr_cmd, | |
7a7be519 | 6006 | "no ip ospf authentication <null|message-digest> [A.B.C.D]", |
b4a039bf DS |
6007 | NO_STR |
6008 | "IP Information\n" | |
6009 | "OSPF interface commands\n" | |
6010 | "Enable authentication on this interface\n" | |
6011 | "Use null authentication\n" | |
6012 | "Use message-digest authentication\n" | |
6013 | "Address of interface") | |
6014 | { | |
d62a17ae | 6015 | VTY_DECLVAR_CONTEXT(interface, ifp); |
6016 | int idx_encryption = 4; | |
6017 | int idx_ipv4 = 5; | |
6018 | struct in_addr addr; | |
6019 | int ret; | |
6020 | struct ospf_if_params *params; | |
6021 | struct route_node *rn; | |
6022 | int auth_type; | |
6023 | ||
6024 | params = IF_DEF_PARAMS(ifp); | |
6025 | ||
6026 | if (argc == 6) { | |
6027 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
6028 | if (!ret) { | |
6029 | vty_out(vty, | |
6030 | "Please specify interface address by A.B.C.D\n"); | |
6031 | return CMD_WARNING_CONFIG_FAILED; | |
6032 | } | |
b4a039bf | 6033 | |
d62a17ae | 6034 | params = ospf_lookup_if_params(ifp, addr); |
6035 | if (params == NULL) { | |
6036 | vty_out(vty, "Ip Address specified is unknown\n"); | |
6037 | return CMD_WARNING_CONFIG_FAILED; | |
6038 | } | |
6039 | params->auth_type = OSPF_AUTH_NOTSET; | |
6040 | UNSET_IF_PARAM(params, auth_type); | |
6041 | if (params != IF_DEF_PARAMS(ifp)) { | |
6042 | ospf_free_if_params(ifp, addr); | |
6043 | ospf_if_update_params(ifp, addr); | |
6044 | } | |
6045 | } else { | |
6046 | if (argv[idx_encryption]->arg[0] == 'n') { | |
6047 | auth_type = OSPF_AUTH_NULL; | |
6048 | } else if (argv[idx_encryption]->arg[0] == 'm') { | |
6049 | auth_type = OSPF_AUTH_CRYPTOGRAPHIC; | |
6050 | } else { | |
6051 | vty_out(vty, "Unexpected input encountered\n"); | |
6052 | return CMD_WARNING_CONFIG_FAILED; | |
6053 | } | |
6054 | /* | |
6055 | * Here we have a case where the user has entered | |
6056 | * 'no ip ospf authentication (null | message_digest )' | |
6057 | * we need to find if we have any ip addresses underneath it | |
6058 | * that | |
6059 | * correspond to the associated type. | |
6060 | */ | |
6061 | if (params->auth_type == auth_type) { | |
6062 | params->auth_type = OSPF_AUTH_NOTSET; | |
6063 | UNSET_IF_PARAM(params, auth_type); | |
6064 | } | |
6065 | ||
6066 | for (rn = route_top(IF_OIFS_PARAMS(ifp)); rn; | |
6067 | rn = route_next(rn)) { | |
6068 | if ((params = rn->info)) { | |
6069 | if (params->auth_type == auth_type) { | |
6070 | params->auth_type = OSPF_AUTH_NOTSET; | |
6071 | UNSET_IF_PARAM(params, auth_type); | |
6072 | if (params != IF_DEF_PARAMS(ifp)) { | |
6073 | ospf_free_if_params( | |
6074 | ifp, rn->p.u.prefix4); | |
6075 | ospf_if_update_params( | |
6076 | ifp, rn->p.u.prefix4); | |
6077 | } | |
6078 | } | |
6079 | } | |
b4a039bf | 6080 | } |
b4a039bf | 6081 | } |
b4a039bf | 6082 | |
d62a17ae | 6083 | return CMD_SUCCESS; |
b4a039bf DS |
6084 | } |
6085 | ||
718e3744 | 6086 | DEFUN (no_ip_ospf_authentication, |
6087 | no_ip_ospf_authentication_addr_cmd, | |
7a7be519 | 6088 | "no ip ospf authentication [A.B.C.D]", |
718e3744 | 6089 | NO_STR |
6090 | "IP Information\n" | |
6091 | "OSPF interface commands\n" | |
6092 | "Enable authentication on this interface\n" | |
6093 | "Address of interface") | |
6094 | { | |
d62a17ae | 6095 | VTY_DECLVAR_CONTEXT(interface, ifp); |
6096 | int idx_ipv4 = 4; | |
6097 | struct in_addr addr; | |
6098 | int ret; | |
6099 | struct ospf_if_params *params; | |
6100 | struct route_node *rn; | |
6101 | ||
6102 | params = IF_DEF_PARAMS(ifp); | |
6103 | ||
6104 | if (argc == 5) { | |
6105 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
6106 | if (!ret) { | |
6107 | vty_out(vty, | |
6108 | "Please specify interface address by A.B.C.D\n"); | |
6109 | return CMD_WARNING_CONFIG_FAILED; | |
6110 | } | |
718e3744 | 6111 | |
d62a17ae | 6112 | params = ospf_lookup_if_params(ifp, addr); |
6113 | if (params == NULL) { | |
6114 | vty_out(vty, "Ip Address specified is unknown\n"); | |
6115 | return CMD_WARNING_CONFIG_FAILED; | |
6116 | } | |
718e3744 | 6117 | |
d62a17ae | 6118 | params->auth_type = OSPF_AUTH_NOTSET; |
6119 | UNSET_IF_PARAM(params, auth_type); | |
6120 | if (params != IF_DEF_PARAMS(ifp)) { | |
6121 | ospf_free_if_params(ifp, addr); | |
6122 | ospf_if_update_params(ifp, addr); | |
6123 | } | |
6124 | } else { | |
6125 | /* | |
6126 | * When a user enters 'no ip ospf authentication' | |
6127 | * We should remove all authentication types from | |
6128 | * the interface. | |
6129 | */ | |
6130 | if ((params->auth_type == OSPF_AUTH_NULL) | |
6131 | || (params->auth_type == OSPF_AUTH_CRYPTOGRAPHIC) | |
6132 | || (params->auth_type == OSPF_AUTH_SIMPLE)) { | |
6133 | params->auth_type = OSPF_AUTH_NOTSET; | |
6134 | UNSET_IF_PARAM(params, auth_type); | |
6135 | } | |
813d4307 | 6136 | |
d62a17ae | 6137 | for (rn = route_top(IF_OIFS_PARAMS(ifp)); rn; |
6138 | rn = route_next(rn)) { | |
6139 | if ((params = rn->info)) { | |
6140 | ||
6141 | if ((params->auth_type == OSPF_AUTH_NULL) | |
6142 | || (params->auth_type | |
6143 | == OSPF_AUTH_CRYPTOGRAPHIC) | |
6144 | || (params->auth_type | |
6145 | == OSPF_AUTH_SIMPLE)) { | |
6146 | params->auth_type = OSPF_AUTH_NOTSET; | |
6147 | UNSET_IF_PARAM(params, auth_type); | |
6148 | if (params != IF_DEF_PARAMS(ifp)) { | |
6149 | ospf_free_if_params( | |
6150 | ifp, rn->p.u.prefix4); | |
6151 | ospf_if_update_params( | |
6152 | ifp, rn->p.u.prefix4); | |
6153 | } | |
6154 | } | |
6155 | } | |
b4a039bf | 6156 | } |
b4a039bf | 6157 | } |
d62a17ae | 6158 | |
6159 | return CMD_SUCCESS; | |
718e3744 | 6160 | } |
6161 | ||
0d829fa7 | 6162 | |
718e3744 | 6163 | DEFUN (ip_ospf_authentication_key, |
6164 | ip_ospf_authentication_key_addr_cmd, | |
7a7be519 | 6165 | "ip ospf authentication-key AUTH_KEY [A.B.C.D]", |
718e3744 | 6166 | "IP Information\n" |
6167 | "OSPF interface commands\n" | |
6168 | "Authentication password (key)\n" | |
6169 | "The OSPF password (key)\n" | |
6170 | "Address of interface") | |
6171 | { | |
d62a17ae | 6172 | VTY_DECLVAR_CONTEXT(interface, ifp); |
6173 | int idx = 0; | |
6174 | struct in_addr addr; | |
6175 | struct ospf_if_params *params; | |
718e3744 | 6176 | |
d62a17ae | 6177 | params = IF_DEF_PARAMS(ifp); |
6178 | ||
6179 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
6180 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
6181 | vty_out(vty, | |
6182 | "Please specify interface address by A.B.C.D\n"); | |
6183 | return CMD_WARNING_CONFIG_FAILED; | |
6184 | } | |
718e3744 | 6185 | |
d62a17ae | 6186 | params = ospf_get_if_params(ifp, addr); |
6187 | ospf_if_update_params(ifp, addr); | |
6188 | } | |
718e3744 | 6189 | |
d62a17ae | 6190 | memset(params->auth_simple, 0, OSPF_AUTH_SIMPLE_SIZE + 1); |
6191 | strncpy((char *)params->auth_simple, argv[3]->arg, | |
6192 | OSPF_AUTH_SIMPLE_SIZE); | |
6193 | SET_IF_PARAM(params, auth_simple); | |
718e3744 | 6194 | |
d62a17ae | 6195 | return CMD_SUCCESS; |
718e3744 | 6196 | } |
6197 | ||
7a7be519 | 6198 | DEFUN_HIDDEN (ospf_authentication_key, |
747e489c | 6199 | ospf_authentication_key_cmd, |
0d829fa7 | 6200 | "ospf authentication-key AUTH_KEY [A.B.C.D]", |
747e489c | 6201 | "OSPF interface commands\n" |
baf9eaad | 6202 | VLINK_HELPSTR_AUTH_SIMPLE |
0d829fa7 | 6203 | "Address of interface\n") |
718e3744 | 6204 | { |
d62a17ae | 6205 | return ip_ospf_authentication_key(self, vty, argc, argv); |
718e3744 | 6206 | } |
6207 | ||
7a7be519 | 6208 | DEFUN (no_ip_ospf_authentication_key, |
6209 | no_ip_ospf_authentication_key_authkey_addr_cmd, | |
6210 | "no ip ospf authentication-key [AUTH_KEY [A.B.C.D]]", | |
6211 | NO_STR | |
6212 | "IP Information\n" | |
6213 | "OSPF interface commands\n" | |
baf9eaad CS |
6214 | VLINK_HELPSTR_AUTH_SIMPLE |
6215 | "Address of interface\n") | |
7a7be519 | 6216 | { |
d62a17ae | 6217 | VTY_DECLVAR_CONTEXT(interface, ifp); |
6218 | int idx = 0; | |
6219 | struct in_addr addr; | |
6220 | struct ospf_if_params *params; | |
6221 | params = IF_DEF_PARAMS(ifp); | |
6222 | ||
6223 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
6224 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
6225 | vty_out(vty, | |
6226 | "Please specify interface address by A.B.C.D\n"); | |
6227 | return CMD_WARNING_CONFIG_FAILED; | |
6228 | } | |
7a7be519 | 6229 | |
d62a17ae | 6230 | params = ospf_lookup_if_params(ifp, addr); |
6231 | if (params == NULL) | |
6232 | return CMD_SUCCESS; | |
7a7be519 | 6233 | } |
813d4307 | 6234 | |
d62a17ae | 6235 | memset(params->auth_simple, 0, OSPF_AUTH_SIMPLE_SIZE); |
6236 | UNSET_IF_PARAM(params, auth_simple); | |
718e3744 | 6237 | |
d62a17ae | 6238 | if (params != IF_DEF_PARAMS(ifp)) { |
6239 | ospf_free_if_params(ifp, addr); | |
6240 | ospf_if_update_params(ifp, addr); | |
6241 | } | |
813d4307 | 6242 | |
d62a17ae | 6243 | return CMD_SUCCESS; |
7a7be519 | 6244 | } |
813d4307 | 6245 | |
0d829fa7 QY |
6246 | DEFUN_HIDDEN (no_ospf_authentication_key, |
6247 | no_ospf_authentication_key_authkey_addr_cmd, | |
6248 | "no ospf authentication-key [AUTH_KEY [A.B.C.D]]", | |
6249 | NO_STR | |
6250 | "OSPF interface commands\n" | |
baf9eaad CS |
6251 | VLINK_HELPSTR_AUTH_SIMPLE |
6252 | "Address of interface\n") | |
0d829fa7 | 6253 | { |
d62a17ae | 6254 | return no_ip_ospf_authentication_key(self, vty, argc, argv); |
0d829fa7 QY |
6255 | } |
6256 | ||
718e3744 | 6257 | DEFUN (ip_ospf_message_digest_key, |
537eae3f | 6258 | ip_ospf_message_digest_key_cmd, |
7a7be519 | 6259 | "ip ospf message-digest-key (1-255) md5 KEY [A.B.C.D]", |
718e3744 | 6260 | "IP Information\n" |
6261 | "OSPF interface commands\n" | |
6262 | "Message digest authentication password (key)\n" | |
6263 | "Key ID\n" | |
6264 | "Use MD5 algorithm\n" | |
fefa0d82 QY |
6265 | "The OSPF password (key)\n" |
6266 | "Address of interface\n") | |
718e3744 | 6267 | { |
d62a17ae | 6268 | VTY_DECLVAR_CONTEXT(interface, ifp); |
6269 | struct crypt_key *ck; | |
6270 | u_char key_id; | |
6271 | struct in_addr addr; | |
6272 | struct ospf_if_params *params; | |
6273 | ||
6274 | params = IF_DEF_PARAMS(ifp); | |
6275 | int idx = 0; | |
6276 | ||
6277 | argv_find(argv, argc, "(1-255)", &idx); | |
6278 | char *keyid = argv[idx]->arg; | |
6279 | argv_find(argv, argc, "KEY", &idx); | |
6280 | char *cryptkey = argv[idx]->arg; | |
6281 | ||
6282 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
6283 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
6284 | vty_out(vty, | |
6285 | "Please specify interface address by A.B.C.D\n"); | |
6286 | return CMD_WARNING_CONFIG_FAILED; | |
6287 | } | |
6288 | ||
6289 | params = ospf_get_if_params(ifp, addr); | |
6290 | ospf_if_update_params(ifp, addr); | |
718e3744 | 6291 | } |
6292 | ||
d62a17ae | 6293 | key_id = strtol(keyid, NULL, 10); |
6294 | if (ospf_crypt_key_lookup(params->auth_crypt, key_id) != NULL) { | |
6295 | vty_out(vty, "OSPF: Key %d already exists\n", key_id); | |
851fcbae | 6296 | return CMD_WARNING; |
d62a17ae | 6297 | } |
718e3744 | 6298 | |
d62a17ae | 6299 | ck = ospf_crypt_key_new(); |
6300 | ck->key_id = (u_char)key_id; | |
6301 | memset(ck->auth_key, 0, OSPF_AUTH_MD5_SIZE + 1); | |
6302 | strncpy((char *)ck->auth_key, cryptkey, OSPF_AUTH_MD5_SIZE); | |
718e3744 | 6303 | |
d62a17ae | 6304 | ospf_crypt_key_add(params->auth_crypt, ck); |
6305 | SET_IF_PARAM(params, auth_crypt); | |
718e3744 | 6306 | |
d62a17ae | 6307 | return CMD_SUCCESS; |
718e3744 | 6308 | } |
6309 | ||
7a7be519 | 6310 | DEFUN_HIDDEN (ospf_message_digest_key, |
747e489c | 6311 | ospf_message_digest_key_cmd, |
0d829fa7 | 6312 | "ospf message-digest-key (1-255) md5 KEY [A.B.C.D]", |
747e489c DW |
6313 | "OSPF interface commands\n" |
6314 | "Message digest authentication password (key)\n" | |
6315 | "Key ID\n" | |
6316 | "Use MD5 algorithm\n" | |
0d829fa7 QY |
6317 | "The OSPF password (key)\n" |
6318 | "Address of interface\n") | |
7a7be519 | 6319 | { |
d62a17ae | 6320 | return ip_ospf_message_digest_key(self, vty, argc, argv); |
7a7be519 | 6321 | } |
718e3744 | 6322 | |
537eae3f QY |
6323 | DEFUN (no_ip_ospf_message_digest_key, |
6324 | no_ip_ospf_message_digest_key_cmd, | |
0d829fa7 | 6325 | "no ip ospf message-digest-key (1-255) [md5 KEY] [A.B.C.D]", |
813d4307 DW |
6326 | NO_STR |
6327 | "IP Information\n" | |
6328 | "OSPF interface commands\n" | |
6329 | "Message digest authentication password (key)\n" | |
6330 | "Key ID\n" | |
6331 | "Use MD5 algorithm\n" | |
0d829fa7 QY |
6332 | "The OSPF password (key)\n" |
6333 | "Address of interface\n") | |
813d4307 | 6334 | { |
d62a17ae | 6335 | VTY_DECLVAR_CONTEXT(interface, ifp); |
6336 | int idx = 0; | |
6337 | struct crypt_key *ck; | |
6338 | int key_id; | |
6339 | struct in_addr addr; | |
6340 | struct ospf_if_params *params; | |
6341 | params = IF_DEF_PARAMS(ifp); | |
6342 | ||
6343 | argv_find(argv, argc, "(1-255)", &idx); | |
6344 | char *keyid = argv[idx]->arg; | |
6345 | ||
6346 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
6347 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
6348 | vty_out(vty, | |
6349 | "Please specify interface address by A.B.C.D\n"); | |
6350 | return CMD_WARNING_CONFIG_FAILED; | |
6351 | } | |
7a7be519 | 6352 | |
d62a17ae | 6353 | params = ospf_lookup_if_params(ifp, addr); |
6354 | if (params == NULL) | |
6355 | return CMD_SUCCESS; | |
7a7be519 | 6356 | } |
6357 | ||
d62a17ae | 6358 | key_id = strtol(keyid, NULL, 10); |
6359 | ck = ospf_crypt_key_lookup(params->auth_crypt, key_id); | |
6360 | if (ck == NULL) { | |
6361 | vty_out(vty, "OSPF: Key %d does not exist\n", key_id); | |
6362 | return CMD_WARNING_CONFIG_FAILED; | |
6363 | } | |
7a7be519 | 6364 | |
d62a17ae | 6365 | ospf_crypt_key_delete(params->auth_crypt, key_id); |
7a7be519 | 6366 | |
d62a17ae | 6367 | if (params != IF_DEF_PARAMS(ifp)) { |
6368 | ospf_free_if_params(ifp, addr); | |
6369 | ospf_if_update_params(ifp, addr); | |
6370 | } | |
7a7be519 | 6371 | |
d62a17ae | 6372 | return CMD_SUCCESS; |
7a7be519 | 6373 | } |
813d4307 | 6374 | |
0d829fa7 | 6375 | DEFUN_HIDDEN (no_ospf_message_digest_key, |
537eae3f | 6376 | no_ospf_message_digest_key_cmd, |
0d829fa7 QY |
6377 | "no ospf message-digest-key (1-255) [md5 KEY] [A.B.C.D]", |
6378 | NO_STR | |
6379 | "OSPF interface commands\n" | |
6380 | "Message digest authentication password (key)\n" | |
6381 | "Key ID\n" | |
6382 | "Address of interface") | |
718e3744 | 6383 | { |
d62a17ae | 6384 | return no_ip_ospf_message_digest_key(self, vty, argc, argv); |
718e3744 | 6385 | } |
6386 | ||
718e3744 | 6387 | DEFUN (ip_ospf_cost, |
5c2fc921 | 6388 | ip_ospf_cost_cmd, |
7a7be519 | 6389 | "ip ospf cost (1-65535) [A.B.C.D]", |
718e3744 | 6390 | "IP Information\n" |
6391 | "OSPF interface commands\n" | |
6392 | "Interface cost\n" | |
6393 | "Cost\n" | |
5c2fc921 | 6394 | "Address of interface\n") |
718e3744 | 6395 | { |
d62a17ae | 6396 | VTY_DECLVAR_CONTEXT(interface, ifp); |
6397 | int idx = 0; | |
35955c14 | 6398 | u_int32_t cost = OSPF_OUTPUT_COST_DEFAULT; |
d62a17ae | 6399 | struct in_addr addr; |
6400 | struct ospf_if_params *params; | |
6401 | params = IF_DEF_PARAMS(ifp); | |
6402 | ||
6403 | // get arguments | |
6404 | char *coststr = NULL, *ifaddr = NULL; | |
35955c14 | 6405 | |
c31a793b VJ |
6406 | argv_find(argv, argc, "(1-65535)", &idx); |
6407 | coststr = argv[idx]->arg; | |
d62a17ae | 6408 | cost = strtol(coststr, NULL, 10); |
6409 | ||
c31a793b | 6410 | ifaddr = argv_find(argv, argc, "A.B.C.D", &idx) ? argv[idx]->arg : NULL; |
d62a17ae | 6411 | if (ifaddr) { |
6412 | if (!inet_aton(ifaddr, &addr)) { | |
6413 | vty_out(vty, | |
6414 | "Please specify interface address by A.B.C.D\n"); | |
6415 | return CMD_WARNING_CONFIG_FAILED; | |
6416 | } | |
718e3744 | 6417 | |
d62a17ae | 6418 | params = ospf_get_if_params(ifp, addr); |
6419 | ospf_if_update_params(ifp, addr); | |
718e3744 | 6420 | } |
6421 | ||
d62a17ae | 6422 | SET_IF_PARAM(params, output_cost_cmd); |
6423 | params->output_cost_cmd = cost; | |
718e3744 | 6424 | |
d62a17ae | 6425 | ospf_if_recalculate_output_cost(ifp); |
5c2fc921 | 6426 | |
d62a17ae | 6427 | return CMD_SUCCESS; |
718e3744 | 6428 | } |
6429 | ||
7a7be519 | 6430 | DEFUN_HIDDEN (ospf_cost, |
5c2fc921 QY |
6431 | ospf_cost_cmd, |
6432 | "ospf cost (1-65535) [A.B.C.D]", | |
747e489c DW |
6433 | "OSPF interface commands\n" |
6434 | "Interface cost\n" | |
6435 | "Cost\n" | |
5c2fc921 | 6436 | "Address of interface\n") |
7a7be519 | 6437 | { |
d62a17ae | 6438 | return ip_ospf_cost(self, vty, argc, argv); |
7a7be519 | 6439 | } |
9eff36b3 | 6440 | |
718e3744 | 6441 | DEFUN (no_ip_ospf_cost, |
5c2fc921 QY |
6442 | no_ip_ospf_cost_cmd, |
6443 | "no ip ospf cost [(1-65535)] [A.B.C.D]", | |
718e3744 | 6444 | NO_STR |
718e3744 | 6445 | "OSPF interface commands\n" |
6446 | "Interface cost\n" | |
6447 | "Address of interface") | |
6448 | { | |
d62a17ae | 6449 | VTY_DECLVAR_CONTEXT(interface, ifp); |
6450 | int idx = 0; | |
6451 | struct in_addr addr; | |
6452 | struct ospf_if_params *params; | |
7a7be519 | 6453 | |
d62a17ae | 6454 | params = IF_DEF_PARAMS(ifp); |
718e3744 | 6455 | |
d62a17ae | 6456 | // get arguments |
6457 | char *ifaddr = NULL; | |
6458 | ifaddr = argv_find(argv, argc, "A.B.C.D", &idx) ? argv[idx]->arg : NULL; | |
718e3744 | 6459 | |
d62a17ae | 6460 | /* According to the semantics we are mimicking "no ip ospf cost N" is |
6461 | * always treated as "no ip ospf cost" regardless of the actual value | |
6462 | * of N already configured for the interface. Thus ignore cost. */ | |
7a7be519 | 6463 | |
d62a17ae | 6464 | if (ifaddr) { |
6465 | if (!inet_aton(ifaddr, &addr)) { | |
6466 | vty_out(vty, | |
6467 | "Please specify interface address by A.B.C.D\n"); | |
6468 | return CMD_WARNING_CONFIG_FAILED; | |
6469 | } | |
7a7be519 | 6470 | |
d62a17ae | 6471 | params = ospf_lookup_if_params(ifp, addr); |
6472 | if (params == NULL) | |
6473 | return CMD_SUCCESS; | |
6474 | } | |
7a7be519 | 6475 | |
d62a17ae | 6476 | UNSET_IF_PARAM(params, output_cost_cmd); |
7a7be519 | 6477 | |
d62a17ae | 6478 | if (params != IF_DEF_PARAMS(ifp)) { |
6479 | ospf_free_if_params(ifp, addr); | |
6480 | ospf_if_update_params(ifp, addr); | |
6481 | } | |
7a7be519 | 6482 | |
d62a17ae | 6483 | ospf_if_recalculate_output_cost(ifp); |
7a7be519 | 6484 | |
d62a17ae | 6485 | return CMD_SUCCESS; |
7a7be519 | 6486 | } |
9eff36b3 | 6487 | |
5c2fc921 QY |
6488 | DEFUN_HIDDEN (no_ospf_cost, |
6489 | no_ospf_cost_cmd, | |
6490 | "no ospf cost [(1-65535)] [A.B.C.D]", | |
6491 | NO_STR | |
6492 | "OSPF interface commands\n" | |
6493 | "Interface cost\n" | |
6494 | "Cost\n" | |
6495 | "Address of interface\n") | |
827341b7 | 6496 | { |
d62a17ae | 6497 | return no_ip_ospf_cost(self, vty, argc, argv); |
827341b7 DO |
6498 | } |
6499 | ||
d62a17ae | 6500 | static void ospf_nbr_timer_update(struct ospf_interface *oi) |
718e3744 | 6501 | { |
d62a17ae | 6502 | struct route_node *rn; |
6503 | struct ospf_neighbor *nbr; | |
718e3744 | 6504 | |
d62a17ae | 6505 | for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) |
6506 | if ((nbr = rn->info)) { | |
6507 | nbr->v_inactivity = OSPF_IF_PARAM(oi, v_wait); | |
6508 | nbr->v_db_desc = OSPF_IF_PARAM(oi, retransmit_interval); | |
6509 | nbr->v_ls_req = OSPF_IF_PARAM(oi, retransmit_interval); | |
6510 | nbr->v_ls_upd = OSPF_IF_PARAM(oi, retransmit_interval); | |
6511 | } | |
718e3744 | 6512 | } |
6513 | ||
d62a17ae | 6514 | static int ospf_vty_dead_interval_set(struct vty *vty, const char *interval_str, |
6515 | const char *nbr_str, | |
6516 | const char *fast_hello_str) | |
6517 | { | |
6518 | VTY_DECLVAR_CONTEXT(interface, ifp); | |
6519 | u_int32_t seconds; | |
6520 | u_char hellomult; | |
6521 | struct in_addr addr; | |
6522 | int ret; | |
6523 | struct ospf_if_params *params; | |
6524 | struct ospf_interface *oi; | |
6525 | struct route_node *rn; | |
718e3744 | 6526 | |
d62a17ae | 6527 | params = IF_DEF_PARAMS(ifp); |
6528 | ||
6529 | if (nbr_str) { | |
6530 | ret = inet_aton(nbr_str, &addr); | |
6531 | if (!ret) { | |
6532 | vty_out(vty, | |
6533 | "Please specify interface address by A.B.C.D\n"); | |
6534 | return CMD_WARNING_CONFIG_FAILED; | |
6535 | } | |
6536 | ||
6537 | params = ospf_get_if_params(ifp, addr); | |
6538 | ospf_if_update_params(ifp, addr); | |
6539 | } | |
6540 | ||
6541 | if (interval_str) { | |
6542 | seconds = strtoul(interval_str, NULL, 10); | |
6543 | ||
6544 | /* reset fast_hello too, just to be sure */ | |
6545 | UNSET_IF_PARAM(params, fast_hello); | |
6546 | params->fast_hello = OSPF_FAST_HELLO_DEFAULT; | |
6547 | } else if (fast_hello_str) { | |
6548 | hellomult = strtoul(fast_hello_str, NULL, 10); | |
6549 | /* 1s dead-interval with sub-second hellos desired */ | |
6550 | seconds = OSPF_ROUTER_DEAD_INTERVAL_MINIMAL; | |
6551 | SET_IF_PARAM(params, fast_hello); | |
6552 | params->fast_hello = hellomult; | |
6553 | } else { | |
6554 | vty_out(vty, | |
6555 | "Please specify dead-interval or hello-multiplier\n"); | |
6556 | return CMD_WARNING_CONFIG_FAILED; | |
6557 | } | |
6558 | ||
6559 | SET_IF_PARAM(params, v_wait); | |
6560 | params->v_wait = seconds; | |
6561 | ||
6562 | /* Update timer values in neighbor structure. */ | |
6563 | if (nbr_str) { | |
b5a8894d CS |
6564 | struct ospf *ospf = NULL; |
6565 | ||
6566 | ospf = ospf_lookup_by_vrf_id(ifp->vrf_id); | |
6567 | if (ospf) { | |
d62a17ae | 6568 | oi = ospf_if_lookup_by_local_addr(ospf, ifp, addr); |
6569 | if (oi) | |
6570 | ospf_nbr_timer_update(oi); | |
6571 | } | |
6572 | } else { | |
6573 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) | |
6574 | if ((oi = rn->info)) | |
6575 | ospf_nbr_timer_update(oi); | |
6576 | } | |
6577 | ||
6578 | return CMD_SUCCESS; | |
718e3744 | 6579 | } |
6580 | ||
f9ad937f | 6581 | DEFUN (ip_ospf_dead_interval, |
0d829fa7 | 6582 | ip_ospf_dead_interval_cmd, |
7a7be519 | 6583 | "ip ospf dead-interval (1-65535) [A.B.C.D]", |
f9ad937f | 6584 | "IP Information\n" |
6585 | "OSPF interface commands\n" | |
99a522c7 | 6586 | "Interval time after which a neighbor is declared down\n" |
f9ad937f | 6587 | "Seconds\n" |
6588 | "Address of interface\n") | |
6589 | { | |
d62a17ae | 6590 | int idx = 0; |
6591 | char *interval = argv_find(argv, argc, "(1-65535)", &idx) | |
6592 | ? argv[idx]->arg | |
6593 | : NULL; | |
6594 | char *ifaddr = | |
6595 | argv_find(argv, argc, "A.B.C.D", &idx) ? argv[idx]->arg : NULL; | |
6596 | return ospf_vty_dead_interval_set(vty, interval, ifaddr, NULL); | |
f9ad937f | 6597 | } |
6598 | ||
718e3744 | 6599 | |
7a7be519 | 6600 | DEFUN_HIDDEN (ospf_dead_interval, |
747e489c | 6601 | ospf_dead_interval_cmd, |
0d829fa7 | 6602 | "ospf dead-interval (1-65535) [A.B.C.D]", |
747e489c | 6603 | "OSPF interface commands\n" |
99a522c7 | 6604 | "Interval time after which a neighbor is declared down\n" |
0d829fa7 QY |
6605 | "Seconds\n" |
6606 | "Address of interface\n") | |
7a7be519 | 6607 | { |
d62a17ae | 6608 | return ip_ospf_dead_interval(self, vty, argc, argv); |
7a7be519 | 6609 | } |
718e3744 | 6610 | |
f9ad937f | 6611 | DEFUN (ip_ospf_dead_interval_minimal, |
6612 | ip_ospf_dead_interval_minimal_addr_cmd, | |
7a7be519 | 6613 | "ip ospf dead-interval minimal hello-multiplier (1-10) [A.B.C.D]", |
f9ad937f | 6614 | "IP Information\n" |
6615 | "OSPF interface commands\n" | |
99a522c7 | 6616 | "Interval time after which a neighbor is declared down\n" |
f9ad937f | 6617 | "Minimal 1s dead-interval with fast sub-second hellos\n" |
6618 | "Hello multiplier factor\n" | |
6619 | "Number of Hellos to send each second\n" | |
6620 | "Address of interface\n") | |
6621 | { | |
d62a17ae | 6622 | int idx_number = 5; |
6623 | int idx_ipv4 = 6; | |
6624 | if (argc == 7) | |
6625 | return ospf_vty_dead_interval_set( | |
6626 | vty, NULL, argv[idx_ipv4]->arg, argv[idx_number]->arg); | |
6627 | else | |
6628 | return ospf_vty_dead_interval_set(vty, NULL, NULL, | |
6629 | argv[idx_number]->arg); | |
f9ad937f | 6630 | } |
6631 | ||
718e3744 | 6632 | DEFUN (no_ip_ospf_dead_interval, |
0d829fa7 | 6633 | no_ip_ospf_dead_interval_cmd, |
e83a9414 | 6634 | "no ip ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]", |
718e3744 | 6635 | NO_STR |
6636 | "IP Information\n" | |
6637 | "OSPF interface commands\n" | |
99a522c7 | 6638 | "Interval time after which a neighbor is declared down\n" |
f9dfba8d | 6639 | "Seconds\n" |
718e3744 | 6640 | "Address of interface") |
6641 | { | |
d62a17ae | 6642 | VTY_DECLVAR_CONTEXT(interface, ifp); |
6643 | int idx_ipv4 = argc - 1; | |
6644 | struct in_addr addr = {.s_addr = 0L}; | |
6645 | int ret; | |
6646 | struct ospf_if_params *params; | |
6647 | struct ospf_interface *oi; | |
6648 | struct route_node *rn; | |
6649 | ||
6650 | params = IF_DEF_PARAMS(ifp); | |
6651 | ||
6652 | if (argv[idx_ipv4]->type == IPV4_TKN) { | |
6653 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
6654 | if (!ret) { | |
6655 | vty_out(vty, | |
6656 | "Please specify interface address by A.B.C.D\n"); | |
6657 | return CMD_WARNING_CONFIG_FAILED; | |
6658 | } | |
020709f9 | 6659 | |
d62a17ae | 6660 | params = ospf_lookup_if_params(ifp, addr); |
6661 | if (params == NULL) | |
6662 | return CMD_SUCCESS; | |
6663 | } | |
718e3744 | 6664 | |
d62a17ae | 6665 | UNSET_IF_PARAM(params, v_wait); |
6666 | params->v_wait = OSPF_ROUTER_DEAD_INTERVAL_DEFAULT; | |
6667 | ||
6668 | UNSET_IF_PARAM(params, fast_hello); | |
6669 | params->fast_hello = OSPF_FAST_HELLO_DEFAULT; | |
6670 | ||
6671 | if (params != IF_DEF_PARAMS(ifp)) { | |
6672 | ospf_free_if_params(ifp, addr); | |
6673 | ospf_if_update_params(ifp, addr); | |
718e3744 | 6674 | } |
6675 | ||
d62a17ae | 6676 | /* Update timer values in neighbor structure. */ |
6677 | if (argc == 1) { | |
b5a8894d | 6678 | struct ospf *ospf = NULL; |
718e3744 | 6679 | |
b5a8894d CS |
6680 | ospf = ospf_lookup_by_vrf_id(ifp->vrf_id); |
6681 | if (ospf) { | |
d62a17ae | 6682 | oi = ospf_if_lookup_by_local_addr(ospf, ifp, addr); |
6683 | if (oi) | |
6684 | ospf_nbr_timer_update(oi); | |
6685 | } | |
6686 | } else { | |
6687 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) | |
6688 | if ((oi = rn->info)) | |
6689 | ospf_nbr_timer_update(oi); | |
6690 | } | |
6691 | ||
6692 | return CMD_SUCCESS; | |
718e3744 | 6693 | } |
6694 | ||
0d829fa7 QY |
6695 | DEFUN_HIDDEN (no_ospf_dead_interval, |
6696 | no_ospf_dead_interval_cmd, | |
6697 | "no ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]", | |
6698 | NO_STR | |
6699 | "OSPF interface commands\n" | |
99a522c7 | 6700 | "Interval time after which a neighbor is declared down\n" |
0d829fa7 QY |
6701 | "Seconds\n" |
6702 | "Address of interface") | |
6703 | { | |
d62a17ae | 6704 | return no_ip_ospf_dead_interval(self, vty, argc, argv); |
0d829fa7 QY |
6705 | } |
6706 | ||
718e3744 | 6707 | DEFUN (ip_ospf_hello_interval, |
0d829fa7 | 6708 | ip_ospf_hello_interval_cmd, |
7a7be519 | 6709 | "ip ospf hello-interval (1-65535) [A.B.C.D]", |
718e3744 | 6710 | "IP Information\n" |
6711 | "OSPF interface commands\n" | |
6712 | "Time between HELLO packets\n" | |
6713 | "Seconds\n" | |
0d829fa7 | 6714 | "Address of interface\n") |
718e3744 | 6715 | { |
d62a17ae | 6716 | VTY_DECLVAR_CONTEXT(interface, ifp); |
6717 | int idx = 0; | |
6718 | struct in_addr addr; | |
6719 | struct ospf_if_params *params; | |
6720 | params = IF_DEF_PARAMS(ifp); | |
6721 | u_int32_t seconds = 0; | |
6722 | ||
6723 | argv_find(argv, argc, "(1-65535)", &idx); | |
6724 | seconds = strtol(argv[idx]->arg, NULL, 10); | |
6725 | ||
6726 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
6727 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
6728 | vty_out(vty, | |
6729 | "Please specify interface address by A.B.C.D\n"); | |
6730 | return CMD_WARNING_CONFIG_FAILED; | |
6731 | } | |
718e3744 | 6732 | |
d62a17ae | 6733 | params = ospf_get_if_params(ifp, addr); |
6734 | ospf_if_update_params(ifp, addr); | |
6735 | } | |
718e3744 | 6736 | |
d62a17ae | 6737 | SET_IF_PARAM(params, v_hello); |
6738 | params->v_hello = seconds; | |
718e3744 | 6739 | |
d62a17ae | 6740 | return CMD_SUCCESS; |
718e3744 | 6741 | } |
6742 | ||
7a7be519 | 6743 | DEFUN_HIDDEN (ospf_hello_interval, |
747e489c | 6744 | ospf_hello_interval_cmd, |
0d829fa7 | 6745 | "ospf hello-interval (1-65535) [A.B.C.D]", |
747e489c DW |
6746 | "OSPF interface commands\n" |
6747 | "Time between HELLO packets\n" | |
0d829fa7 QY |
6748 | "Seconds\n" |
6749 | "Address of interface\n") | |
7a7be519 | 6750 | { |
d62a17ae | 6751 | return ip_ospf_hello_interval(self, vty, argc, argv); |
7a7be519 | 6752 | } |
718e3744 | 6753 | |
6754 | DEFUN (no_ip_ospf_hello_interval, | |
0d829fa7 QY |
6755 | no_ip_ospf_hello_interval_cmd, |
6756 | "no ip ospf hello-interval [(1-65535) [A.B.C.D]]", | |
718e3744 | 6757 | NO_STR |
6758 | "IP Information\n" | |
6759 | "OSPF interface commands\n" | |
0d829fa7 | 6760 | "Time between HELLO packets\n" // ignored |
f9dfba8d | 6761 | "Seconds\n" |
0d829fa7 | 6762 | "Address of interface\n") |
718e3744 | 6763 | { |
d62a17ae | 6764 | VTY_DECLVAR_CONTEXT(interface, ifp); |
6765 | int idx = 0; | |
6766 | struct in_addr addr; | |
6767 | struct ospf_if_params *params; | |
df581cd3 | 6768 | |
d62a17ae | 6769 | params = IF_DEF_PARAMS(ifp); |
718e3744 | 6770 | |
d62a17ae | 6771 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { |
6772 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
6773 | vty_out(vty, | |
6774 | "Please specify interface address by A.B.C.D\n"); | |
6775 | return CMD_WARNING_CONFIG_FAILED; | |
6776 | } | |
718e3744 | 6777 | |
d62a17ae | 6778 | params = ospf_lookup_if_params(ifp, addr); |
6779 | if (params == NULL) | |
6780 | return CMD_SUCCESS; | |
6781 | } | |
718e3744 | 6782 | |
d62a17ae | 6783 | UNSET_IF_PARAM(params, v_hello); |
6784 | params->v_hello = OSPF_HELLO_INTERVAL_DEFAULT; | |
718e3744 | 6785 | |
d62a17ae | 6786 | if (params != IF_DEF_PARAMS(ifp)) { |
6787 | ospf_free_if_params(ifp, addr); | |
6788 | ospf_if_update_params(ifp, addr); | |
6789 | } | |
718e3744 | 6790 | |
d62a17ae | 6791 | return CMD_SUCCESS; |
718e3744 | 6792 | } |
6793 | ||
0d829fa7 QY |
6794 | DEFUN_HIDDEN (no_ospf_hello_interval, |
6795 | no_ospf_hello_interval_cmd, | |
6796 | "no ospf hello-interval [(1-65535) [A.B.C.D]]", | |
6797 | NO_STR | |
6798 | "OSPF interface commands\n" | |
6799 | "Time between HELLO packets\n" // ignored | |
6800 | "Seconds\n" | |
6801 | "Address of interface\n") | |
6802 | { | |
d62a17ae | 6803 | return no_ip_ospf_hello_interval(self, vty, argc, argv); |
0d829fa7 | 6804 | } |
718e3744 | 6805 | |
6806 | DEFUN (ip_ospf_network, | |
6807 | ip_ospf_network_cmd, | |
6147e2c6 | 6808 | "ip ospf network <broadcast|non-broadcast|point-to-multipoint|point-to-point>", |
718e3744 | 6809 | "IP Information\n" |
6810 | "OSPF interface commands\n" | |
6811 | "Network type\n" | |
6812 | "Specify OSPF broadcast multi-access network\n" | |
6813 | "Specify OSPF NBMA network\n" | |
6814 | "Specify OSPF point-to-multipoint network\n" | |
6815 | "Specify OSPF point-to-point network\n") | |
6816 | { | |
d62a17ae | 6817 | VTY_DECLVAR_CONTEXT(interface, ifp); |
6818 | int idx = 0; | |
6819 | int old_type = IF_DEF_PARAMS(ifp)->type; | |
6820 | struct route_node *rn; | |
718e3744 | 6821 | |
d62a17ae | 6822 | if (old_type == OSPF_IFTYPE_LOOPBACK) { |
6823 | vty_out(vty, | |
6824 | "This is a loopback interface. Can't set network type.\n"); | |
6825 | return CMD_WARNING_CONFIG_FAILED; | |
6826 | } | |
718e3744 | 6827 | |
d62a17ae | 6828 | if (argv_find(argv, argc, "broadcast", &idx)) |
6829 | IF_DEF_PARAMS(ifp)->type = OSPF_IFTYPE_BROADCAST; | |
6830 | else if (argv_find(argv, argc, "non-broadcast", &idx)) | |
6831 | IF_DEF_PARAMS(ifp)->type = OSPF_IFTYPE_NBMA; | |
6832 | else if (argv_find(argv, argc, "point-to-multipoint", &idx)) | |
6833 | IF_DEF_PARAMS(ifp)->type = OSPF_IFTYPE_POINTOMULTIPOINT; | |
6834 | else if (argv_find(argv, argc, "point-to-point", &idx)) | |
6835 | IF_DEF_PARAMS(ifp)->type = OSPF_IFTYPE_POINTOPOINT; | |
718e3744 | 6836 | |
d62a17ae | 6837 | if (IF_DEF_PARAMS(ifp)->type == old_type) |
6838 | return CMD_SUCCESS; | |
6839 | ||
6840 | SET_IF_PARAM(IF_DEF_PARAMS(ifp), type); | |
6841 | ||
6842 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { | |
6843 | struct ospf_interface *oi = rn->info; | |
6844 | ||
6845 | if (!oi) | |
6846 | continue; | |
6847 | ||
6848 | oi->type = IF_DEF_PARAMS(ifp)->type; | |
6849 | ||
6850 | if (oi->state > ISM_Down) { | |
6851 | OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceDown); | |
6852 | OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceUp); | |
6853 | } | |
7a7be519 | 6854 | } |
7a7be519 | 6855 | |
d62a17ae | 6856 | return CMD_SUCCESS; |
7a7be519 | 6857 | } |
6858 | ||
6859 | DEFUN_HIDDEN (ospf_network, | |
6860 | ospf_network_cmd, | |
e83a9414 | 6861 | "ospf network <broadcast|non-broadcast|point-to-multipoint|point-to-point>", |
7a7be519 | 6862 | "OSPF interface commands\n" |
6863 | "Network type\n" | |
6864 | "Specify OSPF broadcast multi-access network\n" | |
6865 | "Specify OSPF NBMA network\n" | |
6866 | "Specify OSPF point-to-multipoint network\n" | |
6867 | "Specify OSPF point-to-point network\n") | |
6868 | { | |
d62a17ae | 6869 | return ip_ospf_network(self, vty, argc, argv); |
7a7be519 | 6870 | } |
6871 | ||
6872 | DEFUN (no_ip_ospf_network, | |
6873 | no_ip_ospf_network_cmd, | |
6874 | "no ip ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]", | |
6875 | NO_STR | |
6876 | "IP Information\n" | |
6877 | "OSPF interface commands\n" | |
6878 | "Network type\n" | |
6879 | "Specify OSPF broadcast multi-access network\n" | |
6880 | "Specify OSPF NBMA network\n" | |
6881 | "Specify OSPF point-to-multipoint network\n" | |
6882 | "Specify OSPF point-to-point network\n") | |
22b27e95 | 6883 | { |
d62a17ae | 6884 | VTY_DECLVAR_CONTEXT(interface, ifp); |
6885 | int old_type = IF_DEF_PARAMS(ifp)->type; | |
6886 | struct route_node *rn; | |
7a7be519 | 6887 | |
d62a17ae | 6888 | IF_DEF_PARAMS(ifp)->type = ospf_default_iftype(ifp); |
7a7be519 | 6889 | |
d62a17ae | 6890 | if (IF_DEF_PARAMS(ifp)->type == old_type) |
6891 | return CMD_SUCCESS; | |
7a7be519 | 6892 | |
d62a17ae | 6893 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { |
6894 | struct ospf_interface *oi = rn->info; | |
7a7be519 | 6895 | |
d62a17ae | 6896 | if (!oi) |
6897 | continue; | |
7a7be519 | 6898 | |
d62a17ae | 6899 | oi->type = IF_DEF_PARAMS(ifp)->type; |
7a7be519 | 6900 | |
d62a17ae | 6901 | if (oi->state > ISM_Down) { |
6902 | OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceDown); | |
6903 | OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceUp); | |
6904 | } | |
7a7be519 | 6905 | } |
7a7be519 | 6906 | |
d62a17ae | 6907 | return CMD_SUCCESS; |
7a7be519 | 6908 | } |
6909 | ||
0d829fa7 QY |
6910 | DEFUN_HIDDEN (no_ospf_network, |
6911 | no_ospf_network_cmd, | |
6912 | "no ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]", | |
6913 | NO_STR | |
6914 | "OSPF interface commands\n" | |
6915 | "Network type\n" | |
6916 | "Specify OSPF broadcast multi-access network\n" | |
6917 | "Specify OSPF NBMA network\n" | |
6918 | "Specify OSPF point-to-multipoint network\n" | |
6919 | "Specify OSPF point-to-point network\n") | |
6920 | { | |
d62a17ae | 6921 | return no_ip_ospf_network(self, vty, argc, argv); |
0d829fa7 QY |
6922 | } |
6923 | ||
7a7be519 | 6924 | DEFUN (ip_ospf_priority, |
537eae3f | 6925 | ip_ospf_priority_cmd, |
7a7be519 | 6926 | "ip ospf priority (0-255) [A.B.C.D]", |
6927 | "IP Information\n" | |
6928 | "OSPF interface commands\n" | |
6929 | "Router priority\n" | |
6930 | "Priority\n" | |
6931 | "Address of interface") | |
6932 | { | |
d62a17ae | 6933 | VTY_DECLVAR_CONTEXT(interface, ifp); |
6934 | int idx = 0; | |
6935 | long priority; | |
6936 | struct route_node *rn; | |
6937 | struct in_addr addr; | |
6938 | struct ospf_if_params *params; | |
6939 | params = IF_DEF_PARAMS(ifp); | |
6940 | ||
6941 | argv_find(argv, argc, "(0-255)", &idx); | |
6942 | priority = strtol(argv[idx]->arg, NULL, 10); | |
6943 | ||
6944 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
6945 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
6946 | vty_out(vty, | |
6947 | "Please specify interface address by A.B.C.D\n"); | |
6948 | return CMD_WARNING_CONFIG_FAILED; | |
6949 | } | |
7a7be519 | 6950 | |
d62a17ae | 6951 | params = ospf_get_if_params(ifp, addr); |
6952 | ospf_if_update_params(ifp, addr); | |
7a7be519 | 6953 | } |
6954 | ||
d62a17ae | 6955 | SET_IF_PARAM(params, priority); |
6956 | params->priority = priority; | |
7a7be519 | 6957 | |
d62a17ae | 6958 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { |
6959 | struct ospf_interface *oi = rn->info; | |
7a7be519 | 6960 | |
d62a17ae | 6961 | if (!oi) |
6962 | continue; | |
7a7be519 | 6963 | |
d62a17ae | 6964 | if (PRIORITY(oi) != OSPF_IF_PARAM(oi, priority)) { |
6965 | PRIORITY(oi) = OSPF_IF_PARAM(oi, priority); | |
6966 | OSPF_ISM_EVENT_SCHEDULE(oi, ISM_NeighborChange); | |
6967 | } | |
718e3744 | 6968 | } |
718e3744 | 6969 | |
d62a17ae | 6970 | return CMD_SUCCESS; |
718e3744 | 6971 | } |
6972 | ||
7a7be519 | 6973 | DEFUN_HIDDEN (ospf_priority, |
6974 | ospf_priority_cmd, | |
0d829fa7 | 6975 | "ospf priority (0-255) [A.B.C.D]", |
7a7be519 | 6976 | "OSPF interface commands\n" |
6977 | "Router priority\n" | |
3a2d747c QY |
6978 | "Priority\n" |
6979 | "Address of interface") | |
718e3744 | 6980 | { |
d62a17ae | 6981 | return ip_ospf_priority(self, vty, argc, argv); |
718e3744 | 6982 | } |
6983 | ||
718e3744 | 6984 | DEFUN (no_ip_ospf_priority, |
537eae3f | 6985 | no_ip_ospf_priority_cmd, |
7a7be519 | 6986 | "no ip ospf priority [(0-255) [A.B.C.D]]", |
718e3744 | 6987 | NO_STR |
6988 | "IP Information\n" | |
6989 | "OSPF interface commands\n" | |
0d829fa7 | 6990 | "Router priority\n" // ignored |
813d4307 | 6991 | "Priority\n" |
718e3744 | 6992 | "Address of interface") |
6993 | { | |
d62a17ae | 6994 | VTY_DECLVAR_CONTEXT(interface, ifp); |
6995 | int idx = 0; | |
6996 | struct route_node *rn; | |
6997 | struct in_addr addr; | |
6998 | struct ospf_if_params *params; | |
6999 | ||
7000 | params = IF_DEF_PARAMS(ifp); | |
7001 | ||
7002 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
7003 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
7004 | vty_out(vty, | |
7005 | "Please specify interface address by A.B.C.D\n"); | |
7006 | return CMD_WARNING_CONFIG_FAILED; | |
7007 | } | |
7008 | ||
7009 | params = ospf_lookup_if_params(ifp, addr); | |
7010 | if (params == NULL) | |
7011 | return CMD_SUCCESS; | |
718e3744 | 7012 | } |
7013 | ||
d62a17ae | 7014 | UNSET_IF_PARAM(params, priority); |
7015 | params->priority = OSPF_ROUTER_PRIORITY_DEFAULT; | |
7016 | ||
7017 | if (params != IF_DEF_PARAMS(ifp)) { | |
7018 | ospf_free_if_params(ifp, addr); | |
7019 | ospf_if_update_params(ifp, addr); | |
718e3744 | 7020 | } |
d62a17ae | 7021 | |
7022 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { | |
7023 | struct ospf_interface *oi = rn->info; | |
7024 | ||
7025 | if (!oi) | |
7026 | continue; | |
7027 | ||
7028 | if (PRIORITY(oi) != OSPF_IF_PARAM(oi, priority)) { | |
7029 | PRIORITY(oi) = OSPF_IF_PARAM(oi, priority); | |
7030 | OSPF_ISM_EVENT_SCHEDULE(oi, ISM_NeighborChange); | |
7031 | } | |
7032 | } | |
7033 | ||
7034 | return CMD_SUCCESS; | |
718e3744 | 7035 | } |
7036 | ||
0d829fa7 | 7037 | DEFUN_HIDDEN (no_ospf_priority, |
537eae3f | 7038 | no_ospf_priority_cmd, |
0d829fa7 QY |
7039 | "no ospf priority [(0-255) [A.B.C.D]]", |
7040 | NO_STR | |
7041 | "OSPF interface commands\n" | |
7042 | "Router priority\n" | |
7043 | "Priority\n" | |
7044 | "Address of interface") | |
7045 | { | |
d62a17ae | 7046 | return no_ip_ospf_priority(self, vty, argc, argv); |
0d829fa7 | 7047 | } |
a1afa410 | 7048 | |
718e3744 | 7049 | DEFUN (ip_ospf_retransmit_interval, |
7050 | ip_ospf_retransmit_interval_addr_cmd, | |
7a7be519 | 7051 | "ip ospf retransmit-interval (3-65535) [A.B.C.D]", |
718e3744 | 7052 | "IP Information\n" |
7053 | "OSPF interface commands\n" | |
7054 | "Time between retransmitting lost link state advertisements\n" | |
7055 | "Seconds\n" | |
7056 | "Address of interface") | |
7057 | { | |
d62a17ae | 7058 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7059 | int idx = 0; | |
7060 | u_int32_t seconds; | |
7061 | struct in_addr addr; | |
7062 | struct ospf_if_params *params; | |
7063 | params = IF_DEF_PARAMS(ifp); | |
7064 | ||
7065 | argv_find(argv, argc, "(3-65535)", &idx); | |
7066 | seconds = strtol(argv[idx]->arg, NULL, 10); | |
7067 | ||
7068 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
7069 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
7070 | vty_out(vty, | |
7071 | "Please specify interface address by A.B.C.D\n"); | |
7072 | return CMD_WARNING_CONFIG_FAILED; | |
7073 | } | |
718e3744 | 7074 | |
d62a17ae | 7075 | params = ospf_get_if_params(ifp, addr); |
7076 | ospf_if_update_params(ifp, addr); | |
718e3744 | 7077 | } |
7078 | ||
d62a17ae | 7079 | SET_IF_PARAM(params, retransmit_interval); |
7080 | params->retransmit_interval = seconds; | |
718e3744 | 7081 | |
d62a17ae | 7082 | return CMD_SUCCESS; |
718e3744 | 7083 | } |
7084 | ||
7a7be519 | 7085 | DEFUN_HIDDEN (ospf_retransmit_interval, |
747e489c | 7086 | ospf_retransmit_interval_cmd, |
0d829fa7 | 7087 | "ospf retransmit-interval (3-65535) [A.B.C.D]", |
747e489c DW |
7088 | "OSPF interface commands\n" |
7089 | "Time between retransmitting lost link state advertisements\n" | |
3a2d747c QY |
7090 | "Seconds\n" |
7091 | "Address of interface") | |
7a7be519 | 7092 | { |
d62a17ae | 7093 | return ip_ospf_retransmit_interval(self, vty, argc, argv); |
7a7be519 | 7094 | } |
718e3744 | 7095 | |
7096 | DEFUN (no_ip_ospf_retransmit_interval, | |
7097 | no_ip_ospf_retransmit_interval_addr_cmd, | |
0d829fa7 | 7098 | "no ip ospf retransmit-interval [(3-65535)] [A.B.C.D]", |
718e3744 | 7099 | NO_STR |
7100 | "IP Information\n" | |
7101 | "OSPF interface commands\n" | |
3a2d747c QY |
7102 | "Time between retransmitting lost link state advertisements\n" |
7103 | "Seconds\n" | |
0d829fa7 | 7104 | "Address of interface\n") |
718e3744 | 7105 | { |
d62a17ae | 7106 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7107 | int idx = 0; | |
7108 | struct in_addr addr; | |
7109 | struct ospf_if_params *params; | |
47b91972 | 7110 | |
d62a17ae | 7111 | params = IF_DEF_PARAMS(ifp); |
718e3744 | 7112 | |
d62a17ae | 7113 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { |
7114 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
7115 | vty_out(vty, | |
7116 | "Please specify interface address by A.B.C.D\n"); | |
7117 | return CMD_WARNING_CONFIG_FAILED; | |
7118 | } | |
718e3744 | 7119 | |
d62a17ae | 7120 | params = ospf_lookup_if_params(ifp, addr); |
7121 | if (params == NULL) | |
7122 | return CMD_SUCCESS; | |
7123 | } | |
718e3744 | 7124 | |
d62a17ae | 7125 | UNSET_IF_PARAM(params, retransmit_interval); |
7126 | params->retransmit_interval = OSPF_RETRANSMIT_INTERVAL_DEFAULT; | |
718e3744 | 7127 | |
d62a17ae | 7128 | if (params != IF_DEF_PARAMS(ifp)) { |
7129 | ospf_free_if_params(ifp, addr); | |
7130 | ospf_if_update_params(ifp, addr); | |
7131 | } | |
718e3744 | 7132 | |
d62a17ae | 7133 | return CMD_SUCCESS; |
718e3744 | 7134 | } |
7135 | ||
0d829fa7 QY |
7136 | DEFUN_HIDDEN (no_ospf_retransmit_interval, |
7137 | no_ospf_retransmit_interval_cmd, | |
7138 | "no ospf retransmit-interval [(3-65535)] [A.B.C.D]", | |
7139 | NO_STR | |
7140 | "OSPF interface commands\n" | |
3a2d747c QY |
7141 | "Time between retransmitting lost link state advertisements\n" |
7142 | "Seconds\n" | |
7143 | "Address of interface\n") | |
0d829fa7 | 7144 | { |
d62a17ae | 7145 | return no_ip_ospf_retransmit_interval(self, vty, argc, argv); |
0d829fa7 | 7146 | } |
813d4307 | 7147 | |
718e3744 | 7148 | DEFUN (ip_ospf_transmit_delay, |
7149 | ip_ospf_transmit_delay_addr_cmd, | |
7a7be519 | 7150 | "ip ospf transmit-delay (1-65535) [A.B.C.D]", |
718e3744 | 7151 | "IP Information\n" |
7152 | "OSPF interface commands\n" | |
7153 | "Link state transmit delay\n" | |
7154 | "Seconds\n" | |
7155 | "Address of interface") | |
7156 | { | |
d62a17ae | 7157 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7158 | int idx = 0; | |
7159 | u_int32_t seconds; | |
7160 | struct in_addr addr; | |
7161 | struct ospf_if_params *params; | |
7162 | ||
7163 | params = IF_DEF_PARAMS(ifp); | |
7164 | argv_find(argv, argc, "(1-65535)", &idx); | |
7165 | seconds = strtol(argv[idx]->arg, NULL, 10); | |
7166 | ||
7167 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
7168 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
7169 | vty_out(vty, | |
7170 | "Please specify interface address by A.B.C.D\n"); | |
7171 | return CMD_WARNING_CONFIG_FAILED; | |
7172 | } | |
718e3744 | 7173 | |
d62a17ae | 7174 | params = ospf_get_if_params(ifp, addr); |
7175 | ospf_if_update_params(ifp, addr); | |
718e3744 | 7176 | } |
7177 | ||
d62a17ae | 7178 | SET_IF_PARAM(params, transmit_delay); |
7179 | params->transmit_delay = seconds; | |
718e3744 | 7180 | |
d62a17ae | 7181 | return CMD_SUCCESS; |
718e3744 | 7182 | } |
7183 | ||
7a7be519 | 7184 | DEFUN_HIDDEN (ospf_transmit_delay, |
747e489c | 7185 | ospf_transmit_delay_cmd, |
0d829fa7 | 7186 | "ospf transmit-delay (1-65535) [A.B.C.D]", |
747e489c DW |
7187 | "OSPF interface commands\n" |
7188 | "Link state transmit delay\n" | |
3a2d747c QY |
7189 | "Seconds\n" |
7190 | "Address of interface") | |
7a7be519 | 7191 | { |
d62a17ae | 7192 | return ip_ospf_transmit_delay(self, vty, argc, argv); |
7a7be519 | 7193 | } |
718e3744 | 7194 | |
7195 | DEFUN (no_ip_ospf_transmit_delay, | |
7196 | no_ip_ospf_transmit_delay_addr_cmd, | |
0d829fa7 | 7197 | "no ip ospf transmit-delay [(1-65535)] [A.B.C.D]", |
718e3744 | 7198 | NO_STR |
7199 | "IP Information\n" | |
7200 | "OSPF interface commands\n" | |
7201 | "Link state transmit delay\n" | |
7202 | "Address of interface") | |
7203 | { | |
d62a17ae | 7204 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7205 | int idx = 0; | |
7206 | struct in_addr addr; | |
7207 | struct ospf_if_params *params; | |
718e3744 | 7208 | |
d62a17ae | 7209 | params = IF_DEF_PARAMS(ifp); |
718e3744 | 7210 | |
d62a17ae | 7211 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { |
7212 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
7213 | vty_out(vty, | |
7214 | "Please specify interface address by A.B.C.D\n"); | |
7215 | return CMD_WARNING_CONFIG_FAILED; | |
7216 | } | |
718e3744 | 7217 | |
d62a17ae | 7218 | params = ospf_lookup_if_params(ifp, addr); |
7219 | if (params == NULL) | |
7220 | return CMD_SUCCESS; | |
7221 | } | |
718e3744 | 7222 | |
d62a17ae | 7223 | UNSET_IF_PARAM(params, transmit_delay); |
7224 | params->transmit_delay = OSPF_TRANSMIT_DELAY_DEFAULT; | |
718e3744 | 7225 | |
d62a17ae | 7226 | if (params != IF_DEF_PARAMS(ifp)) { |
7227 | ospf_free_if_params(ifp, addr); | |
7228 | ospf_if_update_params(ifp, addr); | |
7229 | } | |
7230 | ||
7231 | return CMD_SUCCESS; | |
718e3744 | 7232 | } |
7233 | ||
813d4307 | 7234 | |
0d829fa7 QY |
7235 | DEFUN_HIDDEN (no_ospf_transmit_delay, |
7236 | no_ospf_transmit_delay_cmd, | |
32573073 | 7237 | "no ospf transmit-delay [(1-65535) [A.B.C.D]]", |
0d829fa7 QY |
7238 | NO_STR |
7239 | "OSPF interface commands\n" | |
32573073 QY |
7240 | "Link state transmit delay\n" |
7241 | "Seconds\n" | |
7242 | "Address of interface") | |
813d4307 | 7243 | { |
d62a17ae | 7244 | return no_ip_ospf_transmit_delay(self, vty, argc, argv); |
813d4307 DW |
7245 | } |
7246 | ||
e723861d DS |
7247 | DEFUN (ip_ospf_area, |
7248 | ip_ospf_area_cmd, | |
52c62ab8 | 7249 | "ip ospf [(1-65535)] area <A.B.C.D|(0-4294967295)> [A.B.C.D]", |
e723861d DS |
7250 | "IP Information\n" |
7251 | "OSPF interface commands\n" | |
7a7be519 | 7252 | "Instance ID\n" |
e723861d DS |
7253 | "Enable OSPF on this interface\n" |
7254 | "OSPF area ID in IP address format\n" | |
52c62ab8 JAG |
7255 | "OSPF area ID as a decimal value\n" |
7256 | "Address of interface\n") | |
e723861d | 7257 | { |
d62a17ae | 7258 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7259 | int idx = 0; | |
7260 | int format, ret; | |
7261 | struct in_addr area_id; | |
7262 | struct in_addr addr; | |
35955c14 | 7263 | struct ospf_if_params *params = NULL; |
d62a17ae | 7264 | struct route_node *rn; |
b5a8894d | 7265 | struct ospf *ospf = NULL; |
d62a17ae | 7266 | u_short instance = 0; |
7267 | char *areaid; | |
7268 | ||
7269 | if (argv_find(argv, argc, "(1-65535)", &idx)) | |
7270 | instance = strtol(argv[idx]->arg, NULL, 10); | |
7271 | ||
7272 | argv_find(argv, argc, "area", &idx); | |
7273 | areaid = argv[idx + 1]->arg; | |
7274 | ||
b5a8894d CS |
7275 | if (ifp->vrf_id && !instance) |
7276 | ospf = ospf_lookup_by_vrf_id(ifp->vrf_id); | |
7277 | else | |
7278 | ospf = ospf_lookup_instance(instance); | |
7279 | ||
d62a17ae | 7280 | if (ospf == NULL) { |
7281 | params = IF_DEF_PARAMS(ifp); | |
7282 | if (OSPF_IF_PARAM_CONFIGURED(params, if_area)) { | |
7283 | UNSET_IF_PARAM(params, if_area); | |
b5a8894d CS |
7284 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); |
7285 | ospf_interface_area_unset(ospf, ifp); | |
d62a17ae | 7286 | ospf->if_ospf_cli_count--; |
7287 | } | |
ac28e4ec | 7288 | return CMD_NOT_MY_INSTANCE; |
d62a17ae | 7289 | } |
e723861d | 7290 | |
d62a17ae | 7291 | ret = str2area_id(areaid, &area_id, &format); |
7292 | if (ret < 0) { | |
7293 | vty_out(vty, "Please specify area by A.B.C.D|<0-4294967295>\n"); | |
7294 | return CMD_WARNING_CONFIG_FAILED; | |
7295 | } | |
7296 | if (memcmp(ifp->name, "VLINK", 5) == 0) { | |
7297 | vty_out(vty, "Cannot enable OSPF on a virtual link.\n"); | |
7298 | return CMD_WARNING_CONFIG_FAILED; | |
7299 | } | |
7300 | ||
7301 | params = IF_DEF_PARAMS(ifp); | |
7302 | if (OSPF_IF_PARAM_CONFIGURED(params, if_area) | |
7303 | && !IPV4_ADDR_SAME(¶ms->if_area, &area_id)) { | |
7304 | vty_out(vty, | |
7305 | "Must remove previous area config before changing ospf area \n"); | |
7306 | return CMD_WARNING_CONFIG_FAILED; | |
7307 | } | |
7308 | ||
7309 | // Check if we have an address arg and proccess it | |
7310 | if (argc == idx + 3) { | |
cc9b06ad DS |
7311 | if (!inet_aton(argv[idx + 2]->arg, &addr)) { |
7312 | vty_out(vty, "Please specify Intf Address by A.B.C.D\n"); | |
7313 | return CMD_WARNING_CONFIG_FAILED; | |
7314 | } | |
d62a17ae | 7315 | // update/create address-level params |
7316 | params = ospf_get_if_params((ifp), (addr)); | |
7317 | if (OSPF_IF_PARAM_CONFIGURED(params, if_area)) { | |
7318 | vty_out(vty, | |
7319 | "Must remove previous area/address config before changing ospf area"); | |
7320 | return CMD_WARNING_CONFIG_FAILED; | |
7321 | } | |
7322 | ospf_if_update_params((ifp), (addr)); | |
7323 | } | |
7324 | ||
7325 | for (rn = route_top(ospf->networks); rn; rn = route_next(rn)) { | |
7326 | if (rn->info != NULL) { | |
7327 | vty_out(vty, | |
7328 | "Please remove all network commands first.\n"); | |
7329 | return CMD_WARNING_CONFIG_FAILED; | |
7330 | } | |
7331 | } | |
7332 | ||
7333 | /* enable ospf on this interface with area_id */ | |
35955c14 CS |
7334 | if (params) { |
7335 | SET_IF_PARAM(params, if_area); | |
7336 | params->if_area = area_id; | |
7337 | params->if_area_id_fmt = format; | |
7338 | } | |
b5a8894d | 7339 | ospf_interface_area_set(ospf, ifp); |
d62a17ae | 7340 | ospf->if_ospf_cli_count++; |
7341 | ||
7342 | return CMD_SUCCESS; | |
e723861d DS |
7343 | } |
7344 | ||
7345 | DEFUN (no_ip_ospf_area, | |
7346 | no_ip_ospf_area_cmd, | |
52c62ab8 | 7347 | "no ip ospf [(1-65535)] area [<A.B.C.D|(0-4294967295)> [A.B.C.D]]", |
e723861d DS |
7348 | NO_STR |
7349 | "IP Information\n" | |
7350 | "OSPF interface commands\n" | |
3a2d747c | 7351 | "Instance ID\n" |
7a7be519 | 7352 | "Disable OSPF on this interface\n" |
7353 | "OSPF area ID in IP address format\n" | |
52c62ab8 JAG |
7354 | "OSPF area ID as a decimal value\n" |
7355 | "Address of interface\n") | |
e723861d | 7356 | { |
d62a17ae | 7357 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7358 | int idx = 0; | |
7359 | struct ospf *ospf; | |
7360 | struct ospf_if_params *params; | |
7361 | u_short instance = 0; | |
7362 | struct in_addr addr; | |
7363 | ||
7364 | if (argv_find(argv, argc, "(1-65535)", &idx)) | |
7365 | instance = strtol(argv[idx]->arg, NULL, 10); | |
7366 | ||
b5a8894d CS |
7367 | if (ifp->vrf_id && !instance) |
7368 | ospf = ospf_lookup_by_vrf_id(ifp->vrf_id); | |
7369 | else | |
7370 | ospf = ospf_lookup_instance(instance); | |
7371 | ||
ac28e4ec CS |
7372 | if (ospf == NULL) |
7373 | return CMD_NOT_MY_INSTANCE; | |
d62a17ae | 7374 | |
7375 | argv_find(argv, argc, "area", &idx); | |
7376 | ||
7377 | // Check if we have an address arg and proccess it | |
7378 | if (argc == idx + 3) { | |
cc9b06ad DS |
7379 | if (!inet_aton(argv[idx + 2]->arg, &addr)) { |
7380 | vty_out(vty, "Please specify Intf Address by A.B.C.D\n"); | |
7381 | return CMD_WARNING_CONFIG_FAILED; | |
7382 | } | |
d62a17ae | 7383 | params = ospf_lookup_if_params(ifp, addr); |
7384 | if ((params) == NULL) | |
7385 | return CMD_SUCCESS; | |
7386 | } else | |
7387 | params = IF_DEF_PARAMS(ifp); | |
7388 | ||
7389 | if (!OSPF_IF_PARAM_CONFIGURED(params, if_area)) { | |
7390 | vty_out(vty, | |
7391 | "Can't find specified interface area configuration.\n"); | |
7392 | return CMD_WARNING_CONFIG_FAILED; | |
7393 | } | |
813d4307 | 7394 | |
d62a17ae | 7395 | UNSET_IF_PARAM(params, if_area); |
7396 | if (params != IF_DEF_PARAMS((ifp))) { | |
7397 | ospf_free_if_params((ifp), (addr)); | |
7398 | ospf_if_update_params((ifp), (addr)); | |
7399 | } | |
7400 | ||
b5a8894d | 7401 | ospf_interface_area_unset(ospf, ifp); |
d62a17ae | 7402 | ospf->if_ospf_cli_count--; |
7403 | return CMD_SUCCESS; | |
813d4307 DW |
7404 | } |
7405 | ||
6f2a6703 CF |
7406 | DEFUN (ospf_redistribute_source, |
7407 | ospf_redistribute_source_cmd, | |
40d1cbfb | 7408 | "redistribute " FRR_REDIST_STR_OSPFD " [<metric (0-16777214)|metric-type (1-2)|route-map WORD>]", |
d1c65c21 | 7409 | REDIST_STR |
ab0181ee | 7410 | FRR_REDIST_HELP_STR_OSPFD |
718e3744 | 7411 | "Metric for redistributed routes\n" |
7412 | "OSPF default metric\n" | |
7413 | "OSPF exterior metric type for redistributed routes\n" | |
7111c1a0 | 7414 | "Set OSPF External Type 1/2 metrics\n" |
718e3744 | 7415 | "Route map reference\n" |
7416 | "Pointer to route-map entries\n") | |
7417 | { | |
a3d826f0 | 7418 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 7419 | int idx_protocol = 1; |
7420 | int source; | |
7421 | int type = -1; | |
7422 | int metric = -1; | |
7423 | struct ospf_redist *red; | |
7424 | int idx = 0; | |
6f2a6703 | 7425 | |
d62a17ae | 7426 | if (!ospf) |
7427 | return CMD_SUCCESS; | |
7428 | ||
7429 | /* Get distribute source. */ | |
7430 | source = proto_redistnum(AFI_IP, argv[idx_protocol]->text); | |
7431 | if (source < 0) | |
7432 | return CMD_WARNING_CONFIG_FAILED; | |
7433 | ||
7434 | red = ospf_redist_add(ospf, source, 0); | |
7435 | ||
7436 | /* Get metric value. */ | |
7437 | if (argv_find(argv, argc, "(0-16777214)", &idx)) { | |
7438 | if (!str2metric(argv[idx]->arg, &metric)) | |
7439 | return CMD_WARNING_CONFIG_FAILED; | |
7440 | } | |
7441 | /* Get metric type. */ | |
7442 | else if (argv_find(argv, argc, "(1-2)", &idx)) { | |
7443 | if (!str2metric_type(argv[idx]->arg, &type)) | |
7444 | return CMD_WARNING_CONFIG_FAILED; | |
7445 | } | |
7446 | /* Get route-map */ | |
7447 | else if (argv_find(argv, argc, "WORD", &idx)) { | |
7448 | ospf_routemap_set(red, argv[idx]->arg); | |
7449 | } else | |
7450 | ospf_routemap_unset(red); | |
7c8ff89e | 7451 | |
d62a17ae | 7452 | return ospf_redistribute_set(ospf, source, 0, type, metric); |
718e3744 | 7453 | } |
7454 | ||
718e3744 | 7455 | DEFUN (no_ospf_redistribute_source, |
7456 | no_ospf_redistribute_source_cmd, | |
40d1cbfb | 7457 | "no redistribute " FRR_REDIST_STR_OSPFD " [<metric (0-16777214)|metric-type (1-2)|route-map WORD>]", |
718e3744 | 7458 | NO_STR |
d1c65c21 | 7459 | REDIST_STR |
ab0181ee | 7460 | FRR_REDIST_HELP_STR_OSPFD |
813d4307 DW |
7461 | "Metric for redistributed routes\n" |
7462 | "OSPF default metric\n" | |
7463 | "OSPF exterior metric type for redistributed routes\n" | |
7111c1a0 | 7464 | "Set OSPF External Type 1/2 metrics\n" |
813d4307 DW |
7465 | "Route map reference\n" |
7466 | "Pointer to route-map entries\n") | |
718e3744 | 7467 | { |
a3d826f0 | 7468 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 7469 | int idx_protocol = 2; |
7470 | int source; | |
7471 | struct ospf_redist *red; | |
718e3744 | 7472 | |
d62a17ae | 7473 | source = proto_redistnum(AFI_IP, argv[idx_protocol]->text); |
7474 | if (source < 0) | |
7475 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 7476 | |
d62a17ae | 7477 | red = ospf_redist_lookup(ospf, source, 0); |
7478 | if (!red) | |
7479 | return CMD_SUCCESS; | |
7c8ff89e | 7480 | |
d62a17ae | 7481 | ospf_routemap_unset(red); |
7482 | return ospf_redistribute_unset(ospf, source, 0); | |
7c8ff89e DS |
7483 | } |
7484 | ||
7485 | DEFUN (ospf_redistribute_instance_source, | |
7486 | ospf_redistribute_instance_source_cmd, | |
1a5ce38b | 7487 | "redistribute <ospf|table> (1-65535) [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]", |
7c8ff89e DS |
7488 | REDIST_STR |
7489 | "Open Shortest Path First\n" | |
2d627ff5 DS |
7490 | "Non-main Kernel Routing Table\n" |
7491 | "Instance ID/Table ID\n" | |
7c8ff89e DS |
7492 | "Metric for redistributed routes\n" |
7493 | "OSPF default metric\n" | |
7494 | "OSPF exterior metric type for redistributed routes\n" | |
7111c1a0 | 7495 | "Set OSPF External Type 1/2 metrics\n" |
7c8ff89e DS |
7496 | "Route map reference\n" |
7497 | "Pointer to route-map entries\n") | |
7498 | { | |
a3d826f0 | 7499 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 7500 | int idx_ospf_table = 1; |
7501 | int idx_number = 2; | |
7502 | int idx = 3; | |
7503 | int source; | |
7504 | int type = -1; | |
7505 | int metric = -1; | |
7506 | u_short instance; | |
7507 | struct ospf_redist *red; | |
7c8ff89e | 7508 | |
d62a17ae | 7509 | if (!ospf) |
7510 | return CMD_SUCCESS; | |
d8f70b86 | 7511 | |
d62a17ae | 7512 | source = proto_redistnum(AFI_IP, argv[idx_ospf_table]->text); |
2d627ff5 | 7513 | |
d62a17ae | 7514 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
7c8ff89e | 7515 | |
d62a17ae | 7516 | if (!ospf) |
7517 | return CMD_SUCCESS; | |
7c8ff89e | 7518 | |
d62a17ae | 7519 | if ((source == ZEBRA_ROUTE_OSPF) && !ospf->instance) { |
7520 | vty_out(vty, | |
7521 | "Instance redistribution in non-instanced OSPF not allowed\n"); | |
7522 | return CMD_WARNING_CONFIG_FAILED; | |
7523 | } | |
7c8ff89e | 7524 | |
d62a17ae | 7525 | if ((source == ZEBRA_ROUTE_OSPF) && (ospf->instance == instance)) { |
7526 | vty_out(vty, "Same instance OSPF redistribution not allowed\n"); | |
7527 | return CMD_WARNING_CONFIG_FAILED; | |
7528 | } | |
7c8ff89e | 7529 | |
d62a17ae | 7530 | /* Get metric value. */ |
7531 | if (argv_find(argv, argc, "metric", &idx)) | |
7532 | if (!str2metric(argv[idx + 1]->arg, &metric)) | |
7533 | return CMD_WARNING_CONFIG_FAILED; | |
7c8ff89e | 7534 | |
d62a17ae | 7535 | idx = 3; |
7536 | /* Get metric type. */ | |
7537 | if (argv_find(argv, argc, "metric-type", &idx)) | |
7538 | if (!str2metric_type(argv[idx + 1]->arg, &type)) | |
7539 | return CMD_WARNING_CONFIG_FAILED; | |
7c8ff89e | 7540 | |
d62a17ae | 7541 | red = ospf_redist_add(ospf, source, instance); |
7a7be519 | 7542 | |
d62a17ae | 7543 | idx = 3; |
7544 | if (argv_find(argv, argc, "route-map", &idx)) | |
7545 | ospf_routemap_set(red, argv[idx + 1]->arg); | |
7546 | else | |
7547 | ospf_routemap_unset(red); | |
7c8ff89e | 7548 | |
d62a17ae | 7549 | return ospf_redistribute_set(ospf, source, instance, type, metric); |
7c8ff89e DS |
7550 | } |
7551 | ||
7552 | DEFUN (no_ospf_redistribute_instance_source, | |
7553 | no_ospf_redistribute_instance_source_cmd, | |
1a5ce38b | 7554 | "no redistribute <ospf|table> (1-65535) [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]", |
7c8ff89e DS |
7555 | NO_STR |
7556 | REDIST_STR | |
7557 | "Open Shortest Path First\n" | |
2d627ff5 DS |
7558 | "Non-main Kernel Routing Table\n" |
7559 | "Instance ID/Table Id\n" | |
7c8ff89e DS |
7560 | "Metric for redistributed routes\n" |
7561 | "OSPF default metric\n" | |
7562 | "OSPF exterior metric type for redistributed routes\n" | |
7111c1a0 | 7563 | "Set OSPF External Type 1/2 metrics\n" |
7c8ff89e DS |
7564 | "Route map reference\n" |
7565 | "Pointer to route-map entries\n") | |
7566 | { | |
a3d826f0 | 7567 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 7568 | int idx_ospf_table = 2; |
7569 | int idx_number = 3; | |
7570 | u_int instance; | |
7571 | struct ospf_redist *red; | |
7572 | int source; | |
7573 | ||
7574 | if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0) | |
7575 | source = ZEBRA_ROUTE_OSPF; | |
7576 | else | |
7577 | source = ZEBRA_ROUTE_TABLE; | |
7578 | ||
7579 | instance = strtoul(argv[idx_number]->arg, NULL, 10); | |
7c8ff89e | 7580 | |
d62a17ae | 7581 | if ((source == ZEBRA_ROUTE_OSPF) && !ospf->instance) { |
7582 | vty_out(vty, | |
7583 | "Instance redistribution in non-instanced OSPF not allowed\n"); | |
7584 | return CMD_WARNING_CONFIG_FAILED; | |
7585 | } | |
7586 | ||
7587 | if ((source == ZEBRA_ROUTE_OSPF) && (ospf->instance == instance)) { | |
7588 | vty_out(vty, "Same instance OSPF redistribution not allowed\n"); | |
7589 | return CMD_WARNING_CONFIG_FAILED; | |
7590 | } | |
7591 | ||
7592 | red = ospf_redist_lookup(ospf, source, instance); | |
7593 | if (!red) | |
7594 | return CMD_SUCCESS; | |
7595 | ||
7596 | ospf_routemap_unset(red); | |
7597 | return ospf_redistribute_unset(ospf, source, instance); | |
718e3744 | 7598 | } |
7599 | ||
7600 | DEFUN (ospf_distribute_list_out, | |
7601 | ospf_distribute_list_out_cmd, | |
40d1cbfb | 7602 | "distribute-list WORD out " FRR_REDIST_STR_OSPFD, |
718e3744 | 7603 | "Filter networks in routing updates\n" |
6f2a6703 CF |
7604 | "Access-list name\n" |
7605 | OUT_STR | |
ab0181ee | 7606 | FRR_REDIST_HELP_STR_OSPFD) |
718e3744 | 7607 | { |
a3d826f0 | 7608 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 7609 | int idx_word = 1; |
7610 | int source; | |
718e3744 | 7611 | |
d62a17ae | 7612 | char *proto = argv[argc - 1]->text; |
6d681bd8 | 7613 | |
d62a17ae | 7614 | /* Get distribute source. */ |
7615 | source = proto_redistnum(AFI_IP, proto); | |
7616 | if (source < 0) | |
7617 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 7618 | |
d62a17ae | 7619 | return ospf_distribute_list_out_set(ospf, source, argv[idx_word]->arg); |
718e3744 | 7620 | } |
7621 | ||
6f2a6703 CF |
7622 | DEFUN (no_ospf_distribute_list_out, |
7623 | no_ospf_distribute_list_out_cmd, | |
40d1cbfb | 7624 | "no distribute-list WORD out " FRR_REDIST_STR_OSPFD, |
6f2a6703 CF |
7625 | NO_STR |
7626 | "Filter networks in routing updates\n" | |
7627 | "Access-list name\n" | |
7628 | OUT_STR | |
ab0181ee | 7629 | FRR_REDIST_HELP_STR_OSPFD) |
718e3744 | 7630 | { |
a3d826f0 | 7631 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 7632 | int idx_word = 2; |
7633 | int source; | |
020709f9 | 7634 | |
d62a17ae | 7635 | char *proto = argv[argc - 1]->text; |
7636 | source = proto_redistnum(AFI_IP, proto); | |
7637 | if (source < 0) | |
7638 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 7639 | |
d62a17ae | 7640 | return ospf_distribute_list_out_unset(ospf, source, |
7641 | argv[idx_word]->arg); | |
718e3744 | 7642 | } |
7643 | ||
6f2a6703 CF |
7644 | /* Default information originate. */ |
7645 | DEFUN (ospf_default_information_originate, | |
7646 | ospf_default_information_originate_cmd, | |
e83a9414 | 7647 | "default-information originate [<always|metric (0-16777214)|metric-type (1-2)|route-map WORD>]", |
718e3744 | 7648 | "Control distribution of default information\n" |
7649 | "Distribute a default route\n" | |
7650 | "Always advertise default route\n" | |
6f2a6703 CF |
7651 | "OSPF default metric\n" |
7652 | "OSPF metric\n" | |
718e3744 | 7653 | "OSPF metric type for default routes\n" |
7111c1a0 | 7654 | "Set OSPF External Type 1/2 metrics\n" |
718e3744 | 7655 | "Route map reference\n" |
7656 | "Pointer to route-map entries\n") | |
7657 | { | |
a3d826f0 | 7658 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 7659 | int default_originate = DEFAULT_ORIGINATE_ZEBRA; |
7660 | int type = -1; | |
7661 | int metric = -1; | |
7662 | struct ospf_redist *red; | |
7663 | int idx = 0; | |
7664 | ||
7665 | red = ospf_redist_add(ospf, DEFAULT_ROUTE, 0); | |
7666 | ||
7667 | /* Check whether "always" was specified */ | |
7668 | if (argv_find(argv, argc, "always", &idx)) | |
7669 | default_originate = DEFAULT_ORIGINATE_ALWAYS; | |
7670 | /* Get metric value */ | |
7671 | else if (argv_find(argv, argc, "(0-16777214)", &idx)) { | |
7672 | if (!str2metric(argv[idx]->arg, &metric)) | |
7673 | return CMD_WARNING_CONFIG_FAILED; | |
7674 | } | |
7675 | /* Get metric type. */ | |
7676 | else if (argv_find(argv, argc, "(1-2)", &idx)) { | |
7677 | if (!str2metric_type(argv[idx]->arg, &type)) | |
7678 | return CMD_WARNING_CONFIG_FAILED; | |
7679 | } | |
7680 | /* Get route-map */ | |
7681 | else if (argv_find(argv, argc, "WORD", &idx)) | |
7682 | ospf_routemap_set(red, argv[idx]->arg); | |
7683 | else | |
7684 | ospf_routemap_unset(red); | |
7685 | ||
7686 | return ospf_redistribute_default_set(ospf, default_originate, type, | |
7687 | metric); | |
718e3744 | 7688 | } |
7689 | ||
7690 | DEFUN (no_ospf_default_information_originate, | |
7691 | no_ospf_default_information_originate_cmd, | |
12dcf78e | 7692 | "no default-information originate [<always|metric (0-16777214)|metric-type (1-2)|route-map WORD>]", |
718e3744 | 7693 | NO_STR |
7694 | "Control distribution of default information\n" | |
813d4307 DW |
7695 | "Distribute a default route\n" |
7696 | "Always advertise default route\n" | |
7697 | "OSPF default metric\n" | |
7698 | "OSPF metric\n" | |
7699 | "OSPF metric type for default routes\n" | |
7111c1a0 | 7700 | "Set OSPF External Type 1/2 metrics\n" |
813d4307 DW |
7701 | "Route map reference\n" |
7702 | "Pointer to route-map entries\n") | |
718e3744 | 7703 | { |
a3d826f0 | 7704 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 7705 | struct prefix_ipv4 p; |
7706 | struct ospf_external *ext; | |
7707 | struct ospf_redist *red; | |
7c8ff89e | 7708 | |
d62a17ae | 7709 | p.family = AF_INET; |
7710 | p.prefix.s_addr = 0; | |
7711 | p.prefixlen = 0; | |
718e3744 | 7712 | |
d62a17ae | 7713 | ospf_external_lsa_flush(ospf, DEFAULT_ROUTE, &p, 0); |
718e3744 | 7714 | |
d62a17ae | 7715 | if ((ext = ospf_external_lookup(DEFAULT_ROUTE, 0)) |
7716 | && EXTERNAL_INFO(ext)) { | |
7717 | ospf_external_info_delete(DEFAULT_ROUTE, 0, p); | |
7718 | ospf_external_del(DEFAULT_ROUTE, 0); | |
7719 | } | |
718e3744 | 7720 | |
d62a17ae | 7721 | red = ospf_redist_lookup(ospf, DEFAULT_ROUTE, 0); |
7722 | if (!red) | |
7723 | return CMD_SUCCESS; | |
7c8ff89e | 7724 | |
d62a17ae | 7725 | ospf_routemap_unset(red); |
7726 | return ospf_redistribute_default_unset(ospf); | |
718e3744 | 7727 | } |
7728 | ||
7729 | DEFUN (ospf_default_metric, | |
7730 | ospf_default_metric_cmd, | |
6147e2c6 | 7731 | "default-metric (0-16777214)", |
718e3744 | 7732 | "Set metric of redistributed routes\n" |
7733 | "Default metric\n") | |
7734 | { | |
a3d826f0 | 7735 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 7736 | int idx_number = 1; |
7737 | int metric = -1; | |
718e3744 | 7738 | |
d62a17ae | 7739 | if (!str2metric(argv[idx_number]->arg, &metric)) |
7740 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 7741 | |
d62a17ae | 7742 | ospf->default_metric = metric; |
718e3744 | 7743 | |
d62a17ae | 7744 | return CMD_SUCCESS; |
718e3744 | 7745 | } |
7746 | ||
7747 | DEFUN (no_ospf_default_metric, | |
7748 | no_ospf_default_metric_cmd, | |
7a7be519 | 7749 | "no default-metric [(0-16777214)]", |
718e3744 | 7750 | NO_STR |
7a7be519 | 7751 | "Set metric of redistributed routes\n" |
7752 | "Default metric\n") | |
718e3744 | 7753 | { |
a3d826f0 | 7754 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
68980084 | 7755 | |
d62a17ae | 7756 | ospf->default_metric = -1; |
68980084 | 7757 | |
d62a17ae | 7758 | return CMD_SUCCESS; |
718e3744 | 7759 | } |
7760 | ||
718e3744 | 7761 | |
7762 | DEFUN (ospf_distance, | |
7763 | ospf_distance_cmd, | |
6147e2c6 | 7764 | "distance (1-255)", |
eaa1ae0d | 7765 | "Administrative distance\n" |
718e3744 | 7766 | "OSPF Administrative distance\n") |
7767 | { | |
a3d826f0 | 7768 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 7769 | int idx_number = 1; |
68980084 | 7770 | |
d62a17ae | 7771 | ospf->distance_all = atoi(argv[idx_number]->arg); |
68980084 | 7772 | |
d62a17ae | 7773 | return CMD_SUCCESS; |
718e3744 | 7774 | } |
7775 | ||
7776 | DEFUN (no_ospf_distance, | |
7777 | no_ospf_distance_cmd, | |
6147e2c6 | 7778 | "no distance (1-255)", |
718e3744 | 7779 | NO_STR |
eaa1ae0d | 7780 | "Administrative distance\n" |
718e3744 | 7781 | "OSPF Administrative distance\n") |
7782 | { | |
a3d826f0 | 7783 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
68980084 | 7784 | |
d62a17ae | 7785 | ospf->distance_all = 0; |
68980084 | 7786 | |
d62a17ae | 7787 | return CMD_SUCCESS; |
718e3744 | 7788 | } |
7789 | ||
7790 | DEFUN (no_ospf_distance_ospf, | |
7791 | no_ospf_distance_ospf_cmd, | |
eaa1ae0d | 7792 | "no distance ospf [{intra-area [(1-255)]|inter-area [(1-255)]|external [(1-255)]}]", |
718e3744 | 7793 | NO_STR |
eaa1ae0d QY |
7794 | "Administrative distance\n" |
7795 | "OSPF administrative distance\n" | |
718e3744 | 7796 | "Intra-area routes\n" |
813d4307 | 7797 | "Distance for intra-area routes\n" |
718e3744 | 7798 | "Inter-area routes\n" |
813d4307 DW |
7799 | "Distance for inter-area routes\n" |
7800 | "External routes\n" | |
7801 | "Distance for external routes\n") | |
718e3744 | 7802 | { |
a3d826f0 | 7803 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 7804 | int idx = 0; |
718e3744 | 7805 | |
d62a17ae | 7806 | if (!ospf) |
7807 | return CMD_SUCCESS; | |
7c8ff89e | 7808 | |
d62a17ae | 7809 | if (argv_find(argv, argc, "intra-area", &idx) || argc == 3) |
7810 | idx = ospf->distance_intra = 0; | |
7811 | if (argv_find(argv, argc, "inter-area", &idx) || argc == 3) | |
7812 | idx = ospf->distance_inter = 0; | |
7813 | if (argv_find(argv, argc, "external", &idx) || argc == 3) | |
7814 | ospf->distance_external = 0; | |
718e3744 | 7815 | |
d62a17ae | 7816 | return CMD_SUCCESS; |
718e3744 | 7817 | } |
7818 | ||
6f2a6703 CF |
7819 | DEFUN (ospf_distance_ospf, |
7820 | ospf_distance_ospf_cmd, | |
eaa1ae0d QY |
7821 | "distance ospf {intra-area (1-255)|inter-area (1-255)|external (1-255)}", |
7822 | "Administrative distance\n" | |
7823 | "OSPF administrative distance\n" | |
718e3744 | 7824 | "Intra-area routes\n" |
7825 | "Distance for intra-area routes\n" | |
718e3744 | 7826 | "Inter-area routes\n" |
7827 | "Distance for inter-area routes\n" | |
7828 | "External routes\n" | |
718e3744 | 7829 | "Distance for external routes\n") |
7830 | { | |
a3d826f0 | 7831 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 7832 | int idx = 0; |
68980084 | 7833 | |
d62a17ae | 7834 | if (argv_find(argv, argc, "intra-area", &idx)) |
7835 | ospf->distance_intra = atoi(argv[idx + 1]->arg); | |
7836 | idx = 0; | |
7837 | if (argv_find(argv, argc, "inter-area", &idx)) | |
7838 | ospf->distance_inter = atoi(argv[idx + 1]->arg); | |
7839 | idx = 0; | |
7840 | if (argv_find(argv, argc, "external", &idx)) | |
7841 | ospf->distance_external = atoi(argv[idx + 1]->arg); | |
68980084 | 7842 | |
d62a17ae | 7843 | return CMD_SUCCESS; |
718e3744 | 7844 | } |
7845 | ||
d7d73ffc | 7846 | #if 0 |
718e3744 | 7847 | DEFUN (ospf_distance_source, |
7848 | ospf_distance_source_cmd, | |
6147e2c6 | 7849 | "distance (1-255) A.B.C.D/M", |
718e3744 | 7850 | "Administrative distance\n" |
7851 | "Distance value\n" | |
7852 | "IP source prefix\n") | |
7853 | { | |
cdc2d765 | 7854 | VTY_DECLVAR_CONTEXT(ospf, ospf); |
8d769265 DW |
7855 | int idx_number = 1; |
7856 | int idx_ipv4_prefixlen = 2; | |
020709f9 | 7857 | |
7c8ff89e DS |
7858 | if (!ospf) |
7859 | return CMD_SUCCESS; | |
7860 | ||
8d769265 | 7861 | ospf_distance_set (vty, ospf, argv[idx_number]->arg, argv[idx_ipv4_prefixlen]->arg, NULL); |
68980084 | 7862 | |
718e3744 | 7863 | return CMD_SUCCESS; |
7864 | } | |
7865 | ||
7866 | DEFUN (no_ospf_distance_source, | |
7867 | no_ospf_distance_source_cmd, | |
6147e2c6 | 7868 | "no distance (1-255) A.B.C.D/M", |
718e3744 | 7869 | NO_STR |
7870 | "Administrative distance\n" | |
7871 | "Distance value\n" | |
7872 | "IP source prefix\n") | |
7873 | { | |
cdc2d765 | 7874 | VTY_DECLVAR_CONTEXT(ospf, ospf); |
8d769265 DW |
7875 | int idx_number = 2; |
7876 | int idx_ipv4_prefixlen = 3; | |
020709f9 | 7877 | |
7c8ff89e DS |
7878 | if (!ospf) |
7879 | return CMD_SUCCESS; | |
7880 | ||
8d769265 | 7881 | ospf_distance_unset (vty, ospf, argv[idx_number]->arg, argv[idx_ipv4_prefixlen]->arg, NULL); |
020709f9 | 7882 | |
718e3744 | 7883 | return CMD_SUCCESS; |
7884 | } | |
7885 | ||
7886 | DEFUN (ospf_distance_source_access_list, | |
7887 | ospf_distance_source_access_list_cmd, | |
6147e2c6 | 7888 | "distance (1-255) A.B.C.D/M WORD", |
718e3744 | 7889 | "Administrative distance\n" |
7890 | "Distance value\n" | |
7891 | "IP source prefix\n" | |
7892 | "Access list name\n") | |
7893 | { | |
cdc2d765 | 7894 | VTY_DECLVAR_CONTEXT(ospf, ospf); |
8d769265 DW |
7895 | int idx_number = 1; |
7896 | int idx_ipv4_prefixlen = 2; | |
7897 | int idx_word = 3; | |
020709f9 | 7898 | |
7c8ff89e DS |
7899 | if (!ospf) |
7900 | return CMD_SUCCESS; | |
7901 | ||
8d769265 | 7902 | ospf_distance_set (vty, ospf, argv[idx_number]->arg, argv[idx_ipv4_prefixlen]->arg, argv[idx_word]->arg); |
020709f9 | 7903 | |
718e3744 | 7904 | return CMD_SUCCESS; |
7905 | } | |
7906 | ||
7907 | DEFUN (no_ospf_distance_source_access_list, | |
7908 | no_ospf_distance_source_access_list_cmd, | |
6147e2c6 | 7909 | "no distance (1-255) A.B.C.D/M WORD", |
718e3744 | 7910 | NO_STR |
7911 | "Administrative distance\n" | |
7912 | "Distance value\n" | |
7913 | "IP source prefix\n" | |
7914 | "Access list name\n") | |
7915 | { | |
cdc2d765 | 7916 | VTY_DECLVAR_CONTEXT(ospf, ospf); |
8d769265 DW |
7917 | int idx_number = 2; |
7918 | int idx_ipv4_prefixlen = 3; | |
7919 | int idx_word = 4; | |
020709f9 | 7920 | |
7c8ff89e DS |
7921 | if (!ospf) |
7922 | return CMD_SUCCESS; | |
7923 | ||
8d769265 | 7924 | ospf_distance_unset (vty, ospf, argv[idx_number]->arg, argv[idx_ipv4_prefixlen]->arg, argv[idx_word]->arg); |
020709f9 | 7925 | |
718e3744 | 7926 | return CMD_SUCCESS; |
7927 | } | |
d7d73ffc | 7928 | #endif |
718e3744 | 7929 | |
ba682537 | 7930 | DEFUN (ip_ospf_mtu_ignore, |
7931 | ip_ospf_mtu_ignore_addr_cmd, | |
7a7be519 | 7932 | "ip ospf mtu-ignore [A.B.C.D]", |
ba682537 | 7933 | "IP Information\n" |
7934 | "OSPF interface commands\n" | |
99a522c7 | 7935 | "Disable MTU mismatch detection on this interface\n" |
ba682537 | 7936 | "Address of interface") |
7937 | { | |
d62a17ae | 7938 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7939 | int idx_ipv4 = 3; | |
7940 | struct in_addr addr; | |
7941 | int ret; | |
7942 | ||
7943 | struct ospf_if_params *params; | |
7944 | params = IF_DEF_PARAMS(ifp); | |
7945 | ||
7946 | if (argc == 4) { | |
7947 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
7948 | if (!ret) { | |
7949 | vty_out(vty, | |
7950 | "Please specify interface address by A.B.C.D\n"); | |
7951 | return CMD_WARNING_CONFIG_FAILED; | |
7952 | } | |
7953 | params = ospf_get_if_params(ifp, addr); | |
7954 | ospf_if_update_params(ifp, addr); | |
7955 | } | |
7956 | params->mtu_ignore = 1; | |
7957 | if (params->mtu_ignore != OSPF_MTU_IGNORE_DEFAULT) | |
7958 | SET_IF_PARAM(params, mtu_ignore); | |
7959 | else { | |
7960 | UNSET_IF_PARAM(params, mtu_ignore); | |
7961 | if (params != IF_DEF_PARAMS(ifp)) { | |
7962 | ospf_free_if_params(ifp, addr); | |
7963 | ospf_if_update_params(ifp, addr); | |
7964 | } | |
7965 | } | |
7966 | return CMD_SUCCESS; | |
ba682537 | 7967 | } |
7968 | ||
ba682537 | 7969 | DEFUN (no_ip_ospf_mtu_ignore, |
7970 | no_ip_ospf_mtu_ignore_addr_cmd, | |
7a7be519 | 7971 | "no ip ospf mtu-ignore [A.B.C.D]", |
ba682537 | 7972 | "IP Information\n" |
7973 | "OSPF interface commands\n" | |
99a522c7 | 7974 | "Disable MTU mismatch detection on this interface\n" |
ba682537 | 7975 | "Address of interface") |
7976 | { | |
d62a17ae | 7977 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7978 | int idx_ipv4 = 4; | |
7979 | struct in_addr addr; | |
7980 | int ret; | |
7981 | ||
7982 | struct ospf_if_params *params; | |
7983 | params = IF_DEF_PARAMS(ifp); | |
7984 | ||
7985 | if (argc == 5) { | |
7986 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
7987 | if (!ret) { | |
7988 | vty_out(vty, | |
7989 | "Please specify interface address by A.B.C.D\n"); | |
7990 | return CMD_WARNING_CONFIG_FAILED; | |
7991 | } | |
7992 | params = ospf_get_if_params(ifp, addr); | |
7993 | ospf_if_update_params(ifp, addr); | |
7994 | } | |
7995 | params->mtu_ignore = 0; | |
7996 | if (params->mtu_ignore != OSPF_MTU_IGNORE_DEFAULT) | |
7997 | SET_IF_PARAM(params, mtu_ignore); | |
7998 | else { | |
7999 | UNSET_IF_PARAM(params, mtu_ignore); | |
8000 | if (params != IF_DEF_PARAMS(ifp)) { | |
8001 | ospf_free_if_params(ifp, addr); | |
8002 | ospf_if_update_params(ifp, addr); | |
8003 | } | |
8004 | } | |
8005 | return CMD_SUCCESS; | |
ba682537 | 8006 | } |
8007 | ||
6b0655a2 | 8008 | |
88d6cf37 | 8009 | DEFUN (ospf_max_metric_router_lsa_admin, |
8010 | ospf_max_metric_router_lsa_admin_cmd, | |
8011 | "max-metric router-lsa administrative", | |
8012 | "OSPF maximum / infinite-distance metric\n" | |
8013 | "Advertise own Router-LSA with infinite distance (stub router)\n" | |
8014 | "Administratively applied, for an indefinite period\n") | |
8015 | { | |
a3d826f0 | 8016 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 8017 | struct listnode *ln; |
8018 | struct ospf_area *area; | |
7c8ff89e | 8019 | |
d62a17ae | 8020 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, ln, area)) { |
8021 | SET_FLAG(area->stub_router_state, OSPF_AREA_ADMIN_STUB_ROUTED); | |
4ba4fc85 | 8022 | |
d62a17ae | 8023 | if (!CHECK_FLAG(area->stub_router_state, |
8024 | OSPF_AREA_IS_STUB_ROUTED)) | |
8025 | ospf_router_lsa_update_area(area); | |
8026 | } | |
4ba4fc85 | 8027 | |
d62a17ae | 8028 | /* Allows for areas configured later to get the property */ |
8029 | ospf->stub_router_admin_set = OSPF_STUB_ROUTER_ADMINISTRATIVE_SET; | |
8030 | ||
8031 | return CMD_SUCCESS; | |
88d6cf37 | 8032 | } |
8033 | ||
8034 | DEFUN (no_ospf_max_metric_router_lsa_admin, | |
8035 | no_ospf_max_metric_router_lsa_admin_cmd, | |
8036 | "no max-metric router-lsa administrative", | |
8037 | NO_STR | |
8038 | "OSPF maximum / infinite-distance metric\n" | |
8039 | "Advertise own Router-LSA with infinite distance (stub router)\n" | |
8040 | "Administratively applied, for an indefinite period\n") | |
8041 | { | |
a3d826f0 | 8042 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 8043 | struct listnode *ln; |
8044 | struct ospf_area *area; | |
8045 | ||
8046 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, ln, area)) { | |
8047 | UNSET_FLAG(area->stub_router_state, | |
8048 | OSPF_AREA_ADMIN_STUB_ROUTED); | |
8049 | ||
8050 | /* Don't trample on the start-up stub timer */ | |
8051 | if (CHECK_FLAG(area->stub_router_state, | |
8052 | OSPF_AREA_IS_STUB_ROUTED) | |
8053 | && !area->t_stub_router) { | |
8054 | UNSET_FLAG(area->stub_router_state, | |
8055 | OSPF_AREA_IS_STUB_ROUTED); | |
8056 | ospf_router_lsa_update_area(area); | |
8057 | } | |
8058 | } | |
8059 | ospf->stub_router_admin_set = OSPF_STUB_ROUTER_ADMINISTRATIVE_UNSET; | |
8060 | return CMD_SUCCESS; | |
88d6cf37 | 8061 | } |
8062 | ||
8063 | DEFUN (ospf_max_metric_router_lsa_startup, | |
8064 | ospf_max_metric_router_lsa_startup_cmd, | |
6147e2c6 | 8065 | "max-metric router-lsa on-startup (5-86400)", |
88d6cf37 | 8066 | "OSPF maximum / infinite-distance metric\n" |
8067 | "Advertise own Router-LSA with infinite distance (stub router)\n" | |
8068 | "Automatically advertise stub Router-LSA on startup of OSPF\n" | |
8069 | "Time (seconds) to advertise self as stub-router\n") | |
8070 | { | |
a3d826f0 | 8071 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 8072 | int idx_number = 3; |
8073 | unsigned int seconds; | |
8074 | ||
b5a8894d | 8075 | if (argc < 4) { |
d62a17ae | 8076 | vty_out(vty, "%% Must supply stub-router period"); |
8077 | return CMD_WARNING_CONFIG_FAILED; | |
8078 | } | |
8079 | ||
8080 | seconds = strtoul(argv[idx_number]->arg, NULL, 10); | |
8081 | ||
8082 | ospf->stub_router_startup_time = seconds; | |
8083 | ||
8084 | return CMD_SUCCESS; | |
88d6cf37 | 8085 | } |
8086 | ||
8087 | DEFUN (no_ospf_max_metric_router_lsa_startup, | |
8088 | no_ospf_max_metric_router_lsa_startup_cmd, | |
7a7be519 | 8089 | "no max-metric router-lsa on-startup [(5-86400)]", |
88d6cf37 | 8090 | NO_STR |
8091 | "OSPF maximum / infinite-distance metric\n" | |
8092 | "Advertise own Router-LSA with infinite distance (stub router)\n" | |
813d4307 DW |
8093 | "Automatically advertise stub Router-LSA on startup of OSPF\n" |
8094 | "Time (seconds) to advertise self as stub-router\n") | |
88d6cf37 | 8095 | { |
a3d826f0 | 8096 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 8097 | struct listnode *ln; |
8098 | struct ospf_area *area; | |
8099 | ||
8100 | ospf->stub_router_startup_time = OSPF_STUB_ROUTER_UNCONFIGURED; | |
8101 | ||
8102 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, ln, area)) { | |
8103 | SET_FLAG(area->stub_router_state, | |
8104 | OSPF_AREA_WAS_START_STUB_ROUTED); | |
8105 | OSPF_TIMER_OFF(area->t_stub_router); | |
8106 | ||
8107 | /* Don't trample on admin stub routed */ | |
8108 | if (!CHECK_FLAG(area->stub_router_state, | |
8109 | OSPF_AREA_ADMIN_STUB_ROUTED)) { | |
8110 | UNSET_FLAG(area->stub_router_state, | |
8111 | OSPF_AREA_IS_STUB_ROUTED); | |
8112 | ospf_router_lsa_update_area(area); | |
8113 | } | |
8114 | } | |
8115 | return CMD_SUCCESS; | |
88d6cf37 | 8116 | } |
8117 | ||
a1afa410 | 8118 | |
88d6cf37 | 8119 | DEFUN (ospf_max_metric_router_lsa_shutdown, |
8120 | ospf_max_metric_router_lsa_shutdown_cmd, | |
6147e2c6 | 8121 | "max-metric router-lsa on-shutdown (5-100)", |
88d6cf37 | 8122 | "OSPF maximum / infinite-distance metric\n" |
8123 | "Advertise own Router-LSA with infinite distance (stub router)\n" | |
8124 | "Advertise stub-router prior to full shutdown of OSPF\n" | |
8125 | "Time (seconds) to wait till full shutdown\n") | |
8126 | { | |
a3d826f0 | 8127 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 8128 | int idx_number = 3; |
8129 | unsigned int seconds; | |
8130 | ||
b5a8894d | 8131 | if (argc < 4) { |
d62a17ae | 8132 | vty_out(vty, "%% Must supply stub-router shutdown period"); |
8133 | return CMD_WARNING_CONFIG_FAILED; | |
8134 | } | |
8135 | ||
8136 | seconds = strtoul(argv[idx_number]->arg, NULL, 10); | |
8137 | ||
8138 | ospf->stub_router_shutdown_time = seconds; | |
8139 | ||
8140 | return CMD_SUCCESS; | |
88d6cf37 | 8141 | } |
8142 | ||
8143 | DEFUN (no_ospf_max_metric_router_lsa_shutdown, | |
8144 | no_ospf_max_metric_router_lsa_shutdown_cmd, | |
7a7be519 | 8145 | "no max-metric router-lsa on-shutdown [(5-100)]", |
88d6cf37 | 8146 | NO_STR |
8147 | "OSPF maximum / infinite-distance metric\n" | |
8148 | "Advertise own Router-LSA with infinite distance (stub router)\n" | |
813d4307 DW |
8149 | "Advertise stub-router prior to full shutdown of OSPF\n" |
8150 | "Time (seconds) to wait till full shutdown\n") | |
88d6cf37 | 8151 | { |
a3d826f0 | 8152 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
7c8ff89e | 8153 | |
d62a17ae | 8154 | ospf->stub_router_shutdown_time = OSPF_STUB_ROUTER_UNCONFIGURED; |
8155 | ||
8156 | return CMD_SUCCESS; | |
88d6cf37 | 8157 | } |
8158 | ||
d62a17ae | 8159 | static void config_write_stub_router(struct vty *vty, struct ospf *ospf) |
8160 | { | |
8161 | struct listnode *ln; | |
8162 | struct ospf_area *area; | |
8163 | ||
8164 | if (ospf->stub_router_startup_time != OSPF_STUB_ROUTER_UNCONFIGURED) | |
8165 | vty_out(vty, " max-metric router-lsa on-startup %u\n", | |
8166 | ospf->stub_router_startup_time); | |
8167 | if (ospf->stub_router_shutdown_time != OSPF_STUB_ROUTER_UNCONFIGURED) | |
8168 | vty_out(vty, " max-metric router-lsa on-shutdown %u\n", | |
8169 | ospf->stub_router_shutdown_time); | |
8170 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, ln, area)) { | |
8171 | if (CHECK_FLAG(area->stub_router_state, | |
8172 | OSPF_AREA_ADMIN_STUB_ROUTED)) { | |
8173 | vty_out(vty, " max-metric router-lsa administrative\n"); | |
8174 | break; | |
8175 | } | |
8176 | } | |
8177 | return; | |
8178 | } | |
8179 | ||
b5a8894d CS |
8180 | static void show_ip_ospf_route_network(struct vty *vty, struct ospf *ospf, |
8181 | struct route_table *rt) | |
d62a17ae | 8182 | { |
8183 | struct route_node *rn; | |
8184 | struct ospf_route * or ; | |
8185 | struct listnode *pnode, *pnnode; | |
8186 | struct ospf_path *path; | |
8187 | ||
8188 | vty_out(vty, "============ OSPF network routing table ============\n"); | |
8189 | ||
8190 | for (rn = route_top(rt); rn; rn = route_next(rn)) | |
8191 | if ((or = rn->info) != NULL) { | |
8192 | char buf1[19]; | |
8193 | snprintf(buf1, 19, "%s/%d", inet_ntoa(rn->p.u.prefix4), | |
8194 | rn->p.prefixlen); | |
8195 | ||
8196 | switch (or->path_type) { | |
8197 | case OSPF_PATH_INTER_AREA: | |
8198 | if (or->type == OSPF_DESTINATION_NETWORK) | |
8199 | vty_out(vty, | |
8200 | "N IA %-18s [%d] area: %s\n", | |
8201 | buf1, or->cost, | |
8202 | inet_ntoa(or->u.std.area_id)); | |
8203 | else if (or->type == OSPF_DESTINATION_DISCARD) | |
8204 | vty_out(vty, | |
8205 | "D IA %-18s Discard entry\n", | |
8206 | buf1); | |
8207 | break; | |
8208 | case OSPF_PATH_INTRA_AREA: | |
8209 | vty_out(vty, "N %-18s [%d] area: %s\n", | |
8210 | buf1, or->cost, | |
8211 | inet_ntoa(or->u.std.area_id)); | |
8212 | break; | |
8213 | default: | |
8214 | break; | |
8215 | } | |
8216 | ||
8217 | if (or->type == OSPF_DESTINATION_NETWORK) | |
8218 | for (ALL_LIST_ELEMENTS(or->paths, pnode, pnnode, | |
8219 | path)) { | |
8220 | if (if_lookup_by_index(path->ifindex, | |
b5a8894d | 8221 | ospf->vrf_id)) { |
d62a17ae | 8222 | if (path->nexthop.s_addr == 0) |
8223 | vty_out(vty, | |
8224 | "%24s directly attached to %s\n", | |
8225 | "", | |
8226 | ifindex2ifname( | |
8227 | path->ifindex, | |
b5a8894d | 8228 | ospf->vrf_id)); |
d62a17ae | 8229 | else |
8230 | vty_out(vty, | |
8231 | "%24s via %s, %s\n", | |
8232 | "", | |
8233 | inet_ntoa( | |
8234 | path->nexthop), | |
8235 | ifindex2ifname( | |
8236 | path->ifindex, | |
b5a8894d | 8237 | ospf->vrf_id)); |
d62a17ae | 8238 | } |
8239 | } | |
8240 | } | |
8241 | vty_out(vty, "\n"); | |
8242 | } | |
8243 | ||
b5a8894d CS |
8244 | static void show_ip_ospf_route_router(struct vty *vty, struct ospf *ospf, |
8245 | struct route_table *rtrs) | |
d62a17ae | 8246 | { |
8247 | struct route_node *rn; | |
8248 | struct ospf_route * or ; | |
8249 | struct listnode *pnode; | |
8250 | struct listnode *node; | |
8251 | struct ospf_path *path; | |
8252 | ||
c0f3f7cd | 8253 | vty_out(vty, "============ OSPF router routing table =============\n"); |
d62a17ae | 8254 | for (rn = route_top(rtrs); rn; rn = route_next(rn)) |
8255 | if (rn->info) { | |
8256 | int flag = 0; | |
8257 | ||
8258 | vty_out(vty, "R %-15s ", | |
8259 | inet_ntoa(rn->p.u.prefix4)); | |
8260 | ||
8261 | for (ALL_LIST_ELEMENTS_RO((struct list *)rn->info, node, | |
8262 | or)) { | |
8263 | if (flag++) | |
8264 | vty_out(vty, "%24s", ""); | |
8265 | ||
8266 | /* Show path. */ | |
8267 | vty_out(vty, "%s [%d] area: %s", | |
8268 | (or->path_type == OSPF_PATH_INTER_AREA | |
8269 | ? "IA" | |
8270 | : " "), | |
8271 | or->cost, inet_ntoa(or->u.std.area_id)); | |
8272 | /* Show flags. */ | |
8273 | vty_out(vty, "%s%s\n", | |
8274 | (or->u.std.flags & ROUTER_LSA_BORDER | |
8275 | ? ", ABR" | |
8276 | : ""), | |
8277 | (or->u.std.flags & ROUTER_LSA_EXTERNAL | |
8278 | ? ", ASBR" | |
8279 | : "")); | |
8280 | ||
8281 | for (ALL_LIST_ELEMENTS_RO(or->paths, pnode, | |
8282 | path)) { | |
8283 | if (if_lookup_by_index(path->ifindex, | |
b5a8894d | 8284 | ospf->vrf_id)) { |
d62a17ae | 8285 | if (path->nexthop.s_addr == 0) |
8286 | vty_out(vty, | |
8287 | "%24s directly attached to %s\n", | |
8288 | "", | |
8289 | ifindex2ifname( | |
8290 | path->ifindex, | |
b5a8894d | 8291 | ospf->vrf_id)); |
d62a17ae | 8292 | else |
8293 | vty_out(vty, | |
8294 | "%24s via %s, %s\n", | |
8295 | "", | |
8296 | inet_ntoa( | |
8297 | path->nexthop), | |
8298 | ifindex2ifname( | |
8299 | path->ifindex, | |
b5a8894d | 8300 | ospf->vrf_id)); |
d62a17ae | 8301 | } |
8302 | } | |
8303 | } | |
8304 | } | |
8305 | vty_out(vty, "\n"); | |
8306 | } | |
8307 | ||
b5a8894d CS |
8308 | static void show_ip_ospf_route_external(struct vty *vty, struct ospf *ospf, |
8309 | struct route_table *rt) | |
d62a17ae | 8310 | { |
8311 | struct route_node *rn; | |
8312 | struct ospf_route *er; | |
8313 | struct listnode *pnode, *pnnode; | |
8314 | struct ospf_path *path; | |
8315 | ||
8316 | vty_out(vty, "============ OSPF external routing table ===========\n"); | |
8317 | for (rn = route_top(rt); rn; rn = route_next(rn)) | |
8318 | if ((er = rn->info) != NULL) { | |
8319 | char buf1[19]; | |
8320 | snprintf(buf1, 19, "%s/%d", inet_ntoa(rn->p.u.prefix4), | |
8321 | rn->p.prefixlen); | |
8322 | ||
8323 | switch (er->path_type) { | |
8324 | case OSPF_PATH_TYPE1_EXTERNAL: | |
8325 | vty_out(vty, | |
8326 | "N E1 %-18s [%d] tag: %" ROUTE_TAG_PRI | |
8327 | "\n", | |
8328 | buf1, er->cost, er->u.ext.tag); | |
8329 | break; | |
8330 | case OSPF_PATH_TYPE2_EXTERNAL: | |
8331 | vty_out(vty, | |
8332 | "N E2 %-18s [%d/%d] tag: %" ROUTE_TAG_PRI | |
8333 | "\n", | |
8334 | buf1, er->cost, er->u.ext.type2_cost, | |
8335 | er->u.ext.tag); | |
8336 | break; | |
8337 | } | |
8338 | ||
8339 | for (ALL_LIST_ELEMENTS(er->paths, pnode, pnnode, | |
8340 | path)) { | |
8341 | if (if_lookup_by_index(path->ifindex, | |
b5a8894d | 8342 | ospf->vrf_id)) { |
d62a17ae | 8343 | if (path->nexthop.s_addr == 0) |
8344 | vty_out(vty, | |
8345 | "%24s directly attached to %s\n", | |
8346 | "", | |
8347 | ifindex2ifname( | |
8348 | path->ifindex, | |
b5a8894d | 8349 | ospf->vrf_id)); |
d62a17ae | 8350 | else |
8351 | vty_out(vty, | |
8352 | "%24s via %s, %s\n", | |
8353 | "", | |
8354 | inet_ntoa( | |
8355 | path->nexthop), | |
8356 | ifindex2ifname( | |
8357 | path->ifindex, | |
b5a8894d | 8358 | ospf->vrf_id)); |
d62a17ae | 8359 | } |
54bedb55 | 8360 | } |
d62a17ae | 8361 | } |
8362 | vty_out(vty, "\n"); | |
718e3744 | 8363 | } |
8364 | ||
d62a17ae | 8365 | static int show_ip_ospf_border_routers_common(struct vty *vty, |
8366 | struct ospf *ospf) | |
718e3744 | 8367 | { |
d62a17ae | 8368 | if (ospf->instance) |
8369 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
718e3744 | 8370 | |
d62a17ae | 8371 | if (ospf->new_table == NULL) { |
8372 | vty_out(vty, "No OSPF routing information exist\n"); | |
8373 | return CMD_SUCCESS; | |
8374 | } | |
718e3744 | 8375 | |
d62a17ae | 8376 | /* Show Network routes. |
8377 | show_ip_ospf_route_network (vty, ospf->new_table); */ | |
718e3744 | 8378 | |
d62a17ae | 8379 | /* Show Router routes. */ |
b5a8894d | 8380 | show_ip_ospf_route_router(vty, ospf, ospf->new_rtrs); |
718e3744 | 8381 | |
d62a17ae | 8382 | vty_out(vty, "\n"); |
7c8ff89e | 8383 | |
d62a17ae | 8384 | return CMD_SUCCESS; |
718e3744 | 8385 | } |
718e3744 | 8386 | |
7c8ff89e DS |
8387 | DEFUN (show_ip_ospf_border_routers, |
8388 | show_ip_ospf_border_routers_cmd, | |
b5a8894d | 8389 | "show ip ospf [vrf <NAME|all>] border-routers", |
718e3744 | 8390 | SHOW_STR |
8391 | IP_STR | |
8392 | "OSPF information\n" | |
b5a8894d CS |
8393 | VRF_CMD_HELP_STR |
8394 | "All VRFs\n" | |
7c8ff89e | 8395 | "Show all the ABR's and ASBR's\n") |
718e3744 | 8396 | { |
b5a8894d CS |
8397 | struct ospf *ospf = NULL; |
8398 | struct listnode *node = NULL; | |
8399 | char *vrf_name = NULL; | |
8400 | bool all_vrf = FALSE; | |
8401 | int ret = CMD_SUCCESS; | |
8402 | int inst = 0; | |
8403 | int idx_vrf = 0; | |
68980084 | 8404 | |
43b8d1d8 | 8405 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
7c8ff89e | 8406 | |
b5a8894d CS |
8407 | if (vrf_name) { |
8408 | if (all_vrf) { | |
8409 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
8410 | if (!ospf->oi_running) | |
8411 | continue; | |
b5a8894d CS |
8412 | |
8413 | ret = show_ip_ospf_border_routers_common(vty, | |
8414 | ospf); | |
8415 | } | |
8416 | } else { | |
8417 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
8418 | if (ospf == NULL || !ospf->oi_running) | |
8419 | return CMD_SUCCESS; | |
8420 | ||
b5a8894d CS |
8421 | ret = show_ip_ospf_border_routers_common(vty, ospf); |
8422 | } | |
8423 | } else { | |
8424 | /* Display default ospf (instance 0) info */ | |
8425 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
8426 | if (ospf == NULL || !ospf->oi_running) | |
8427 | return CMD_SUCCESS; | |
b5a8894d CS |
8428 | ret = show_ip_ospf_border_routers_common(vty, ospf); |
8429 | } | |
8430 | ||
8431 | return ret; | |
7c8ff89e DS |
8432 | } |
8433 | ||
8434 | DEFUN (show_ip_ospf_instance_border_routers, | |
8435 | show_ip_ospf_instance_border_routers_cmd, | |
6147e2c6 | 8436 | "show ip ospf (1-65535) border-routers", |
7c8ff89e DS |
8437 | SHOW_STR |
8438 | IP_STR | |
8439 | "OSPF information\n" | |
8440 | "Instance ID\n" | |
8441 | "Show all the ABR's and ASBR's\n") | |
8442 | { | |
d62a17ae | 8443 | int idx_number = 3; |
8444 | struct ospf *ospf; | |
8445 | u_short instance = 0; | |
7c8ff89e | 8446 | |
d62a17ae | 8447 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
ac28e4ec CS |
8448 | ospf = ospf_lookup_instance(instance); |
8449 | if (ospf == NULL) | |
8450 | return CMD_NOT_MY_INSTANCE; | |
8451 | ||
8452 | if (!ospf->oi_running) | |
d62a17ae | 8453 | return CMD_SUCCESS; |
7c8ff89e | 8454 | |
d62a17ae | 8455 | return show_ip_ospf_border_routers_common(vty, ospf); |
7c8ff89e DS |
8456 | } |
8457 | ||
d62a17ae | 8458 | static int show_ip_ospf_route_common(struct vty *vty, struct ospf *ospf) |
7c8ff89e | 8459 | { |
d62a17ae | 8460 | if (ospf->instance) |
8461 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
718e3744 | 8462 | |
d62a17ae | 8463 | if (ospf->new_table == NULL) { |
8464 | vty_out(vty, "No OSPF routing information exist\n"); | |
8465 | return CMD_SUCCESS; | |
8466 | } | |
718e3744 | 8467 | |
d62a17ae | 8468 | /* Show Network routes. */ |
b5a8894d | 8469 | show_ip_ospf_route_network(vty, ospf, ospf->new_table); |
718e3744 | 8470 | |
d62a17ae | 8471 | /* Show Router routes. */ |
b5a8894d | 8472 | show_ip_ospf_route_router(vty, ospf, ospf->new_rtrs); |
718e3744 | 8473 | |
d62a17ae | 8474 | /* Show AS External routes. */ |
b5a8894d | 8475 | show_ip_ospf_route_external(vty, ospf, ospf->old_external_route); |
718e3744 | 8476 | |
d62a17ae | 8477 | vty_out(vty, "\n"); |
7c8ff89e | 8478 | |
d62a17ae | 8479 | return CMD_SUCCESS; |
718e3744 | 8480 | } |
8481 | ||
7c8ff89e DS |
8482 | DEFUN (show_ip_ospf_route, |
8483 | show_ip_ospf_route_cmd, | |
b5a8894d CS |
8484 | "show ip ospf [vrf <NAME|all>] route", |
8485 | SHOW_STR | |
8486 | IP_STR | |
8487 | "OSPF information\n" | |
8488 | VRF_CMD_HELP_STR | |
8489 | "All VRFs\n" | |
8490 | "OSPF routing table\n") | |
8491 | { | |
8492 | struct ospf *ospf = NULL; | |
8493 | struct listnode *node = NULL; | |
8494 | char *vrf_name = NULL; | |
8495 | bool all_vrf = FALSE; | |
8496 | int ret = CMD_SUCCESS; | |
8497 | int inst = 0; | |
8498 | int idx_vrf = 0; | |
7c8ff89e | 8499 | |
43b8d1d8 | 8500 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
7c8ff89e | 8501 | |
b5a8894d CS |
8502 | /* vrf input is provided could be all or specific vrf*/ |
8503 | if (vrf_name) { | |
8504 | if (all_vrf) { | |
8505 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
8506 | if (!ospf->oi_running) | |
8507 | continue; | |
8508 | ret = show_ip_ospf_route_common(vty, ospf); | |
8509 | } | |
8510 | return ret; | |
8511 | } | |
8512 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
8513 | if (ospf == NULL || !ospf->oi_running) | |
8514 | return CMD_SUCCESS; | |
8515 | } else { | |
8516 | /* Display default ospf (instance 0) info */ | |
8517 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
8518 | if (ospf == NULL || !ospf->oi_running) | |
8519 | return CMD_SUCCESS; | |
8520 | } | |
8521 | ||
8522 | if (ospf) | |
8523 | ret = show_ip_ospf_route_common(vty, ospf); | |
8524 | ||
8525 | return ret; | |
7c8ff89e DS |
8526 | } |
8527 | ||
8528 | DEFUN (show_ip_ospf_instance_route, | |
8529 | show_ip_ospf_instance_route_cmd, | |
6147e2c6 | 8530 | "show ip ospf (1-65535) route", |
7c8ff89e DS |
8531 | SHOW_STR |
8532 | IP_STR | |
8533 | "OSPF information\n" | |
8534 | "Instance ID\n" | |
8535 | "OSPF routing table\n") | |
8536 | { | |
d62a17ae | 8537 | int idx_number = 3; |
8538 | struct ospf *ospf; | |
8539 | u_short instance = 0; | |
7c8ff89e | 8540 | |
d62a17ae | 8541 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
ac28e4ec CS |
8542 | ospf = ospf_lookup_instance(instance); |
8543 | if (ospf == NULL) | |
8544 | return CMD_NOT_MY_INSTANCE; | |
8545 | ||
8546 | if (!ospf->oi_running) | |
d62a17ae | 8547 | return CMD_SUCCESS; |
7c8ff89e | 8548 | |
d62a17ae | 8549 | return show_ip_ospf_route_common(vty, ospf); |
7c8ff89e | 8550 | } |
6b0655a2 | 8551 | |
b5a8894d CS |
8552 | |
8553 | DEFUN (show_ip_ospf_vrfs, | |
8554 | show_ip_ospf_vrfs_cmd, | |
8555 | "show ip ospf vrfs [json]", | |
8556 | SHOW_STR | |
8557 | IP_STR | |
8558 | "OSPF information\n" | |
8559 | "Show OSPF VRFs \n" | |
8560 | JSON_STR) | |
8561 | { | |
8562 | u_char uj = use_json(argc, argv); | |
8563 | json_object *json = NULL; | |
8564 | json_object *json_vrfs = NULL; | |
8565 | struct ospf *ospf = NULL; | |
8566 | struct listnode *node = NULL; | |
8567 | int count = 0; | |
8568 | static char header[] = "Name Id RouterId "; | |
8569 | ||
8570 | if (uj) { | |
8571 | json = json_object_new_object(); | |
8572 | json_vrfs = json_object_new_object(); | |
8573 | } | |
8574 | ||
8575 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
8576 | json_object *json_vrf = NULL; | |
8577 | const char *name = NULL; | |
8578 | int vrf_id_ui = 0; | |
8579 | ||
8580 | count++; | |
8581 | ||
8582 | if (!uj && count == 1) | |
8583 | vty_out(vty, "%s\n", header); | |
8584 | if (uj) | |
8585 | json_vrf = json_object_new_object(); | |
8586 | ||
8587 | if (ospf->vrf_id == 0) | |
8588 | name = VRF_DEFAULT_NAME; | |
8589 | else | |
8590 | name = ospf->name; | |
8591 | ||
8592 | vrf_id_ui = (ospf->vrf_id == VRF_UNKNOWN) ? -1 : ospf->vrf_id; | |
8593 | ||
8594 | if (uj) { | |
8595 | json_object_int_add(json_vrf, "vrfId", vrf_id_ui); | |
8596 | json_object_string_add(json_vrf, "routerId", | |
8597 | inet_ntoa(ospf->router_id)); | |
8598 | ||
8599 | json_object_object_add(json_vrfs, name, json_vrf); | |
8600 | ||
8601 | } else { | |
8602 | vty_out(vty, "%-25s %-5d %-16s \n", | |
8603 | name, ospf->vrf_id, inet_ntoa(ospf->router_id)); | |
8604 | } | |
8605 | } | |
8606 | ||
8607 | if (uj) { | |
8608 | json_object_object_add(json, "vrfs", json_vrfs); | |
8609 | json_object_int_add(json, "totalVrfs", count); | |
8610 | ||
8611 | vty_out(vty, "%s\n", json_object_to_json_string_ext(json, | |
8612 | JSON_C_TO_STRING_PRETTY)); | |
8613 | json_object_free(json); | |
8614 | } else { | |
8615 | if (count) | |
8616 | vty_out(vty, "\nTotal number of OSPF VRFs (including default): %d\n", | |
8617 | count); | |
8618 | } | |
8619 | ||
8620 | return CMD_SUCCESS; | |
8621 | } | |
8622 | ||
d62a17ae | 8623 | const char *ospf_abr_type_str[] = {"unknown", "standard", "ibm", "cisco", |
8624 | "shortcut"}; | |
718e3744 | 8625 | |
d62a17ae | 8626 | const char *ospf_shortcut_mode_str[] = {"default", "enable", "disable"}; |
718e3744 | 8627 | |
d62a17ae | 8628 | const char *ospf_int_type_str[] = {"unknown", /* should never be used. */ |
8629 | "point-to-point", "broadcast", | |
8630 | "non-broadcast", "point-to-multipoint", | |
8631 | "virtual-link", /* should never be used. */ | |
8632 | "loopback"}; | |
718e3744 | 8633 | |
43b8d1d8 | 8634 | static int config_write_interface_one(struct vty *vty, struct ospf *ospf) |
d62a17ae | 8635 | { |
8636 | struct listnode *n1, *n2; | |
8637 | struct interface *ifp; | |
8638 | struct crypt_key *ck; | |
d62a17ae | 8639 | struct route_node *rn = NULL; |
8640 | struct ospf_if_params *params; | |
43b8d1d8 | 8641 | int write = 0; |
d62a17ae | 8642 | |
43b8d1d8 | 8643 | for (ALL_LIST_ELEMENTS_RO(vrf_iflist(ospf->vrf_id), n1, ifp)) { |
35955c14 CS |
8644 | struct vrf *vrf = NULL; |
8645 | ||
43b8d1d8 CS |
8646 | if (memcmp(ifp->name, "VLINK", 5) == 0) |
8647 | continue; | |
d62a17ae | 8648 | |
43b8d1d8 CS |
8649 | if (ifp->ifindex == IFINDEX_DELETED) |
8650 | continue; | |
d62a17ae | 8651 | |
35955c14 CS |
8652 | vrf = vrf_lookup_by_id(ifp->vrf_id); |
8653 | ||
43b8d1d8 | 8654 | vty_frame(vty, "!\n"); |
35955c14 CS |
8655 | if (ifp->vrf_id == VRF_DEFAULT || vrf == NULL) |
8656 | vty_frame(vty, "interface %s\n", ifp->name); | |
8657 | else | |
8658 | vty_frame(vty, "interface %s vrf %s\n", | |
8659 | ifp->name, vrf->name); | |
43b8d1d8 CS |
8660 | if (ifp->desc) |
8661 | vty_out(vty, " description %s\n", ifp->desc); | |
d62a17ae | 8662 | |
43b8d1d8 CS |
8663 | write++; |
8664 | ||
8665 | params = IF_DEF_PARAMS(ifp); | |
8666 | ||
8667 | do { | |
8668 | /* Interface Network print. */ | |
8669 | if (OSPF_IF_PARAM_CONFIGURED(params, type) | |
8670 | && params->type != OSPF_IFTYPE_LOOPBACK) { | |
8671 | if (params->type != ospf_default_iftype(ifp)) { | |
8672 | vty_out(vty, " ip ospf network %s", | |
8673 | ospf_int_type_str | |
8674 | [params->type]); | |
8675 | if (params != IF_DEF_PARAMS(ifp)) | |
8676 | vty_out(vty, " %s", | |
d62a17ae | 8677 | inet_ntoa( |
43b8d1d8 CS |
8678 | rn->p.u.prefix4)); |
8679 | vty_out(vty, "\n"); | |
d62a17ae | 8680 | } |
43b8d1d8 | 8681 | } |
d62a17ae | 8682 | |
43b8d1d8 CS |
8683 | /* OSPF interface authentication print */ |
8684 | if (OSPF_IF_PARAM_CONFIGURED(params, auth_type) | |
8685 | && params->auth_type != OSPF_AUTH_NOTSET) { | |
8686 | const char *auth_str; | |
d62a17ae | 8687 | |
43b8d1d8 CS |
8688 | /* Translation tables are not that much help |
8689 | * here due to syntax | |
8690 | * of the simple option */ | |
8691 | switch (params->auth_type) { | |
d62a17ae | 8692 | |
43b8d1d8 CS |
8693 | case OSPF_AUTH_NULL: |
8694 | auth_str = " null"; | |
8695 | break; | |
d62a17ae | 8696 | |
43b8d1d8 CS |
8697 | case OSPF_AUTH_SIMPLE: |
8698 | auth_str = ""; | |
8699 | break; | |
d62a17ae | 8700 | |
43b8d1d8 CS |
8701 | case OSPF_AUTH_CRYPTOGRAPHIC: |
8702 | auth_str = " message-digest"; | |
8703 | break; | |
b5a8894d | 8704 | |
43b8d1d8 CS |
8705 | default: |
8706 | auth_str = ""; | |
8707 | break; | |
d62a17ae | 8708 | } |
8709 | ||
43b8d1d8 CS |
8710 | vty_out(vty, " ip ospf authentication%s", |
8711 | auth_str); | |
8712 | if (params != IF_DEF_PARAMS(ifp)) | |
8713 | vty_out(vty, " %s", | |
8714 | inet_ntoa(rn->p.u.prefix4)); | |
8715 | vty_out(vty, "\n"); | |
8716 | } | |
d62a17ae | 8717 | |
43b8d1d8 CS |
8718 | /* Simple Authentication Password print. */ |
8719 | if (OSPF_IF_PARAM_CONFIGURED(params, auth_simple) | |
8720 | && params->auth_simple[0] != '\0') { | |
8721 | vty_out(vty, " ip ospf authentication-key %s", | |
8722 | params->auth_simple); | |
8723 | if (params != IF_DEF_PARAMS(ifp)) | |
8724 | vty_out(vty, " %s", | |
8725 | inet_ntoa(rn->p.u.prefix4)); | |
8726 | vty_out(vty, "\n"); | |
8727 | } | |
d62a17ae | 8728 | |
43b8d1d8 | 8729 | /* Cryptographic Authentication Key print. */ |
35955c14 CS |
8730 | if (params && params->auth_crypt) { |
8731 | for (ALL_LIST_ELEMENTS_RO(params->auth_crypt, | |
8732 | n2, ck)) { | |
8733 | vty_out(vty, | |
8734 | " ip ospf message-digest-key %d md5 %s", | |
8735 | ck->key_id, ck->auth_key); | |
8736 | if (params != IF_DEF_PARAMS(ifp)) | |
8737 | vty_out(vty, " %s", | |
8738 | inet_ntoa(rn->p.u.prefix4)); | |
8739 | vty_out(vty, "\n"); | |
8740 | } | |
43b8d1d8 | 8741 | } |
d62a17ae | 8742 | |
43b8d1d8 CS |
8743 | /* Interface Output Cost print. */ |
8744 | if (OSPF_IF_PARAM_CONFIGURED(params, | |
8745 | output_cost_cmd)) { | |
8746 | vty_out(vty, " ip ospf cost %u", | |
8747 | params->output_cost_cmd); | |
8748 | if (params != IF_DEF_PARAMS(ifp)) | |
8749 | vty_out(vty, " %s", | |
8750 | inet_ntoa(rn->p.u.prefix4)); | |
8751 | vty_out(vty, "\n"); | |
8752 | } | |
d62a17ae | 8753 | |
43b8d1d8 CS |
8754 | /* Hello Interval print. */ |
8755 | if (OSPF_IF_PARAM_CONFIGURED(params, v_hello) | |
8756 | && params->v_hello != OSPF_HELLO_INTERVAL_DEFAULT) { | |
8757 | vty_out(vty, " ip ospf hello-interval %u", | |
8758 | params->v_hello); | |
8759 | if (params != IF_DEF_PARAMS(ifp)) | |
8760 | vty_out(vty, " %s", | |
8761 | inet_ntoa(rn->p.u.prefix4)); | |
8762 | vty_out(vty, "\n"); | |
8763 | } | |
d62a17ae | 8764 | |
8765 | ||
43b8d1d8 CS |
8766 | /* Router Dead Interval print. */ |
8767 | if (OSPF_IF_PARAM_CONFIGURED(params, v_wait) | |
8768 | && params->v_wait | |
8769 | != OSPF_ROUTER_DEAD_INTERVAL_DEFAULT) { | |
8770 | vty_out(vty, " ip ospf dead-interval "); | |
d62a17ae | 8771 | |
43b8d1d8 CS |
8772 | /* fast hello ? */ |
8773 | if (OSPF_IF_PARAM_CONFIGURED(params, | |
8774 | fast_hello)) | |
8775 | vty_out(vty, | |
8776 | "minimal hello-multiplier %d", | |
8777 | params->fast_hello); | |
8778 | else | |
8779 | vty_out(vty, "%u", params->v_wait); | |
d62a17ae | 8780 | |
43b8d1d8 CS |
8781 | if (params != IF_DEF_PARAMS(ifp)) |
8782 | vty_out(vty, " %s", | |
8783 | inet_ntoa(rn->p.u.prefix4)); | |
8784 | vty_out(vty, "\n"); | |
8785 | } | |
d62a17ae | 8786 | |
43b8d1d8 CS |
8787 | /* Router Priority print. */ |
8788 | if (OSPF_IF_PARAM_CONFIGURED(params, priority) | |
8789 | && params->priority | |
8790 | != OSPF_ROUTER_PRIORITY_DEFAULT) { | |
8791 | vty_out(vty, " ip ospf priority %u", | |
8792 | params->priority); | |
8793 | if (params != IF_DEF_PARAMS(ifp)) | |
8794 | vty_out(vty, " %s", | |
8795 | inet_ntoa(rn->p.u.prefix4)); | |
8796 | vty_out(vty, "\n"); | |
8797 | } | |
d62a17ae | 8798 | |
43b8d1d8 CS |
8799 | /* Retransmit Interval print. */ |
8800 | if (OSPF_IF_PARAM_CONFIGURED(params, | |
8801 | retransmit_interval) | |
8802 | && params->retransmit_interval | |
8803 | != OSPF_RETRANSMIT_INTERVAL_DEFAULT) { | |
8804 | vty_out(vty, " ip ospf retransmit-interval %u", | |
8805 | params->retransmit_interval); | |
8806 | if (params != IF_DEF_PARAMS(ifp)) | |
8807 | vty_out(vty, " %s", | |
8808 | inet_ntoa(rn->p.u.prefix4)); | |
8809 | vty_out(vty, "\n"); | |
8810 | } | |
d62a17ae | 8811 | |
43b8d1d8 CS |
8812 | /* Transmit Delay print. */ |
8813 | if (OSPF_IF_PARAM_CONFIGURED(params, transmit_delay) | |
8814 | && params->transmit_delay | |
8815 | != OSPF_TRANSMIT_DELAY_DEFAULT) { | |
8816 | vty_out(vty, " ip ospf transmit-delay %u", | |
8817 | params->transmit_delay); | |
8818 | if (params != IF_DEF_PARAMS(ifp)) | |
8819 | vty_out(vty, " %s", | |
8820 | inet_ntoa(rn->p.u.prefix4)); | |
8821 | vty_out(vty, "\n"); | |
8822 | } | |
d62a17ae | 8823 | |
43b8d1d8 CS |
8824 | /* Area print. */ |
8825 | if (OSPF_IF_PARAM_CONFIGURED(params, if_area)) { | |
8826 | if (ospf->instance) | |
8827 | vty_out(vty, " ip ospf %d", | |
8828 | ospf->instance); | |
8829 | else | |
8830 | vty_out(vty, " ip ospf"); | |
d62a17ae | 8831 | |
d62a17ae | 8832 | |
43b8d1d8 CS |
8833 | size_t buflen = MAX(strlen("4294967295"), |
8834 | strlen("255.255.255.255")); | |
8835 | char buf[buflen]; | |
d62a17ae | 8836 | |
43b8d1d8 CS |
8837 | area_id2str(buf, sizeof(buf), |
8838 | ¶ms->if_area, | |
8839 | params->if_area_id_fmt); | |
8840 | vty_out(vty, " area %s", buf); | |
8841 | if (params != IF_DEF_PARAMS(ifp)) | |
8842 | vty_out(vty, " %s", | |
8843 | inet_ntoa(rn->p.u.prefix4)); | |
8844 | vty_out(vty, "\n"); | |
8845 | } | |
d62a17ae | 8846 | |
43b8d1d8 CS |
8847 | /* bfd print. */ |
8848 | ospf_bfd_write_config(vty, params); | |
d62a17ae | 8849 | |
43b8d1d8 CS |
8850 | /* MTU ignore print. */ |
8851 | if (OSPF_IF_PARAM_CONFIGURED(params, mtu_ignore) | |
8852 | && params->mtu_ignore != OSPF_MTU_IGNORE_DEFAULT) { | |
8853 | if (params->mtu_ignore == 0) | |
8854 | vty_out(vty, " no ip ospf mtu-ignore"); | |
8855 | else | |
8856 | vty_out(vty, " ip ospf mtu-ignore"); | |
8857 | if (params != IF_DEF_PARAMS(ifp)) | |
8858 | vty_out(vty, " %s", | |
8859 | inet_ntoa(rn->p.u.prefix4)); | |
8860 | vty_out(vty, "\n"); | |
8861 | } | |
d62a17ae | 8862 | |
a8b828f3 | 8863 | |
43b8d1d8 CS |
8864 | while (1) { |
8865 | if (rn == NULL) | |
8866 | rn = route_top(IF_OIFS_PARAMS(ifp)); | |
8867 | else | |
8868 | rn = route_next(rn); | |
d62a17ae | 8869 | |
43b8d1d8 CS |
8870 | if (rn == NULL) |
8871 | break; | |
8872 | params = rn->info; | |
8873 | if (params != NULL) | |
8874 | break; | |
8875 | } | |
8876 | } while (rn); | |
8877 | ||
8878 | ospf_opaque_config_write_if(vty, ifp); | |
8879 | ||
8880 | vty_endframe(vty, NULL); | |
b5a8894d | 8881 | } |
d62a17ae | 8882 | return write; |
718e3744 | 8883 | } |
8884 | ||
43b8d1d8 CS |
8885 | /* Configuration write function for ospfd. */ |
8886 | static int config_write_interface(struct vty *vty) | |
8887 | { | |
8888 | int write = 0; | |
8889 | struct ospf *ospf = NULL; | |
8890 | struct listnode *node = NULL; | |
8891 | ||
8892 | /* Traverse all ospf [vrf] instances */ | |
8893 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) | |
8894 | write += config_write_interface_one(vty, ospf); | |
8895 | ||
8896 | return write; | |
8897 | } | |
8898 | ||
d62a17ae | 8899 | static int config_write_network_area(struct vty *vty, struct ospf *ospf) |
718e3744 | 8900 | { |
d62a17ae | 8901 | struct route_node *rn; |
8902 | u_char buf[INET_ADDRSTRLEN]; | |
718e3744 | 8903 | |
d62a17ae | 8904 | /* `network area' print. */ |
8905 | for (rn = route_top(ospf->networks); rn; rn = route_next(rn)) | |
8906 | if (rn->info) { | |
8907 | struct ospf_network *n = rn->info; | |
718e3744 | 8908 | |
d62a17ae | 8909 | memset(buf, 0, INET_ADDRSTRLEN); |
718e3744 | 8910 | |
d62a17ae | 8911 | /* Create Area ID string by specified Area ID format. */ |
8912 | if (n->area_id_fmt == OSPF_AREA_ID_FMT_DOTTEDQUAD) | |
8913 | strncpy((char *)buf, inet_ntoa(n->area_id), | |
8914 | INET_ADDRSTRLEN); | |
8915 | else | |
8916 | sprintf((char *)buf, "%lu", | |
8917 | (unsigned long int)ntohl( | |
8918 | n->area_id.s_addr)); | |
718e3744 | 8919 | |
d62a17ae | 8920 | /* Network print. */ |
8921 | vty_out(vty, " network %s/%d area %s\n", | |
8922 | inet_ntoa(rn->p.u.prefix4), rn->p.prefixlen, | |
8923 | buf); | |
8924 | } | |
718e3744 | 8925 | |
d62a17ae | 8926 | return 0; |
718e3744 | 8927 | } |
8928 | ||
d62a17ae | 8929 | static int config_write_ospf_area(struct vty *vty, struct ospf *ospf) |
718e3744 | 8930 | { |
d62a17ae | 8931 | struct listnode *node; |
8932 | struct ospf_area *area; | |
8933 | u_char buf[INET_ADDRSTRLEN]; | |
718e3744 | 8934 | |
d62a17ae | 8935 | /* Area configuration print. */ |
8936 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) { | |
8937 | struct route_node *rn1; | |
718e3744 | 8938 | |
d62a17ae | 8939 | area_id2str((char *)buf, INET_ADDRSTRLEN, &area->area_id, |
8940 | area->area_id_fmt); | |
718e3744 | 8941 | |
d62a17ae | 8942 | if (area->auth_type != OSPF_AUTH_NULL) { |
8943 | if (area->auth_type == OSPF_AUTH_SIMPLE) | |
8944 | vty_out(vty, " area %s authentication\n", buf); | |
8945 | else | |
8946 | vty_out(vty, | |
8947 | " area %s authentication message-digest\n", | |
8948 | buf); | |
8949 | } | |
718e3744 | 8950 | |
d62a17ae | 8951 | if (area->shortcut_configured != OSPF_SHORTCUT_DEFAULT) |
8952 | vty_out(vty, " area %s shortcut %s\n", buf, | |
8953 | ospf_shortcut_mode_str | |
8954 | [area->shortcut_configured]); | |
8955 | ||
8956 | if ((area->external_routing == OSPF_AREA_STUB) | |
8957 | || (area->external_routing == OSPF_AREA_NSSA)) { | |
8958 | if (area->external_routing == OSPF_AREA_STUB) | |
8959 | vty_out(vty, " area %s stub", buf); | |
8960 | else if (area->external_routing == OSPF_AREA_NSSA) { | |
8961 | vty_out(vty, " area %s nssa", buf); | |
8962 | switch (area->NSSATranslatorRole) { | |
8963 | case OSPF_NSSA_ROLE_NEVER: | |
8964 | vty_out(vty, " translate-never"); | |
8965 | break; | |
8966 | case OSPF_NSSA_ROLE_ALWAYS: | |
8967 | vty_out(vty, " translate-always"); | |
8968 | break; | |
8969 | case OSPF_NSSA_ROLE_CANDIDATE: | |
8970 | default: | |
8971 | vty_out(vty, " translate-candidate"); | |
8972 | } | |
8973 | } | |
718e3744 | 8974 | |
d62a17ae | 8975 | if (area->no_summary) |
8976 | vty_out(vty, " no-summary"); | |
718e3744 | 8977 | |
d62a17ae | 8978 | vty_out(vty, "\n"); |
718e3744 | 8979 | |
d62a17ae | 8980 | if (area->default_cost != 1) |
8981 | vty_out(vty, " area %s default-cost %d\n", buf, | |
8982 | area->default_cost); | |
8983 | } | |
718e3744 | 8984 | |
d62a17ae | 8985 | for (rn1 = route_top(area->ranges); rn1; rn1 = route_next(rn1)) |
8986 | if (rn1->info) { | |
8987 | struct ospf_area_range *range = rn1->info; | |
718e3744 | 8988 | |
d62a17ae | 8989 | vty_out(vty, " area %s range %s/%d", buf, |
8990 | inet_ntoa(rn1->p.u.prefix4), | |
8991 | rn1->p.prefixlen); | |
718e3744 | 8992 | |
d62a17ae | 8993 | if (range->cost_config |
8994 | != OSPF_AREA_RANGE_COST_UNSPEC) | |
8995 | vty_out(vty, " cost %d", | |
8996 | range->cost_config); | |
718e3744 | 8997 | |
d62a17ae | 8998 | if (!CHECK_FLAG(range->flags, |
8999 | OSPF_AREA_RANGE_ADVERTISE)) | |
9000 | vty_out(vty, " not-advertise"); | |
718e3744 | 9001 | |
d62a17ae | 9002 | if (CHECK_FLAG(range->flags, |
9003 | OSPF_AREA_RANGE_SUBSTITUTE)) | |
9004 | vty_out(vty, " substitute %s/%d", | |
9005 | inet_ntoa(range->subst_addr), | |
9006 | range->subst_masklen); | |
9007 | ||
9008 | vty_out(vty, "\n"); | |
9009 | } | |
9010 | ||
9011 | if (EXPORT_NAME(area)) | |
9012 | vty_out(vty, " area %s export-list %s\n", buf, | |
9013 | EXPORT_NAME(area)); | |
9014 | ||
9015 | if (IMPORT_NAME(area)) | |
9016 | vty_out(vty, " area %s import-list %s\n", buf, | |
9017 | IMPORT_NAME(area)); | |
9018 | ||
9019 | if (PREFIX_NAME_IN(area)) | |
9020 | vty_out(vty, " area %s filter-list prefix %s in\n", buf, | |
9021 | PREFIX_NAME_IN(area)); | |
9022 | ||
9023 | if (PREFIX_NAME_OUT(area)) | |
9024 | vty_out(vty, " area %s filter-list prefix %s out\n", | |
9025 | buf, PREFIX_NAME_OUT(area)); | |
9026 | } | |
9027 | ||
9028 | return 0; | |
718e3744 | 9029 | } |
9030 | ||
d62a17ae | 9031 | static int config_write_ospf_nbr_nbma(struct vty *vty, struct ospf *ospf) |
718e3744 | 9032 | { |
d62a17ae | 9033 | struct ospf_nbr_nbma *nbr_nbma; |
9034 | struct route_node *rn; | |
718e3744 | 9035 | |
d62a17ae | 9036 | /* Static Neighbor configuration print. */ |
9037 | for (rn = route_top(ospf->nbr_nbma); rn; rn = route_next(rn)) | |
9038 | if ((nbr_nbma = rn->info)) { | |
9039 | vty_out(vty, " neighbor %s", inet_ntoa(nbr_nbma->addr)); | |
718e3744 | 9040 | |
d62a17ae | 9041 | if (nbr_nbma->priority |
9042 | != OSPF_NEIGHBOR_PRIORITY_DEFAULT) | |
9043 | vty_out(vty, " priority %d", | |
9044 | nbr_nbma->priority); | |
718e3744 | 9045 | |
d62a17ae | 9046 | if (nbr_nbma->v_poll != OSPF_POLL_INTERVAL_DEFAULT) |
9047 | vty_out(vty, " poll-interval %d", | |
9048 | nbr_nbma->v_poll); | |
9049 | ||
9050 | vty_out(vty, "\n"); | |
9051 | } | |
9052 | ||
9053 | return 0; | |
9054 | } | |
9055 | ||
9056 | static int config_write_virtual_link(struct vty *vty, struct ospf *ospf) | |
9057 | { | |
9058 | struct listnode *node; | |
9059 | struct ospf_vl_data *vl_data; | |
9060 | char buf[INET_ADDRSTRLEN]; | |
9061 | ||
9062 | /* Virtual-Link print */ | |
9063 | for (ALL_LIST_ELEMENTS_RO(ospf->vlinks, node, vl_data)) { | |
9064 | struct listnode *n2; | |
9065 | struct crypt_key *ck; | |
9066 | struct ospf_interface *oi; | |
9067 | ||
9068 | if (vl_data != NULL) { | |
9069 | memset(buf, 0, INET_ADDRSTRLEN); | |
9070 | ||
9071 | area_id2str(buf, sizeof(buf), &vl_data->vl_area_id, | |
9072 | vl_data->vl_area_id_fmt); | |
9073 | oi = vl_data->vl_oi; | |
9074 | ||
9075 | /* timers */ | |
9076 | if (OSPF_IF_PARAM(oi, v_hello) | |
9077 | != OSPF_HELLO_INTERVAL_DEFAULT | |
9078 | || OSPF_IF_PARAM(oi, v_wait) | |
9079 | != OSPF_ROUTER_DEAD_INTERVAL_DEFAULT | |
9080 | || OSPF_IF_PARAM(oi, retransmit_interval) | |
9081 | != OSPF_RETRANSMIT_INTERVAL_DEFAULT | |
9082 | || OSPF_IF_PARAM(oi, transmit_delay) | |
9083 | != OSPF_TRANSMIT_DELAY_DEFAULT) | |
9084 | vty_out(vty, | |
9085 | " area %s virtual-link %s hello-interval %d retransmit-interval %d transmit-delay %d dead-interval %d\n", | |
9086 | buf, inet_ntoa(vl_data->vl_peer), | |
9087 | OSPF_IF_PARAM(oi, v_hello), | |
9088 | OSPF_IF_PARAM(oi, retransmit_interval), | |
9089 | OSPF_IF_PARAM(oi, transmit_delay), | |
9090 | OSPF_IF_PARAM(oi, v_wait)); | |
9091 | else | |
9092 | vty_out(vty, " area %s virtual-link %s\n", buf, | |
9093 | inet_ntoa(vl_data->vl_peer)); | |
9094 | /* Auth key */ | |
9095 | if (IF_DEF_PARAMS(vl_data->vl_oi->ifp)->auth_simple[0] | |
9096 | != '\0') | |
9097 | vty_out(vty, | |
9098 | " area %s virtual-link %s authentication-key %s\n", | |
9099 | buf, inet_ntoa(vl_data->vl_peer), | |
9100 | IF_DEF_PARAMS(vl_data->vl_oi->ifp) | |
9101 | ->auth_simple); | |
9102 | /* md5 keys */ | |
9103 | for (ALL_LIST_ELEMENTS_RO( | |
9104 | IF_DEF_PARAMS(vl_data->vl_oi->ifp) | |
9105 | ->auth_crypt, | |
9106 | n2, ck)) | |
9107 | vty_out(vty, | |
9108 | " area %s virtual-link %s" | |
9109 | " message-digest-key %d md5 %s\n", | |
9110 | buf, inet_ntoa(vl_data->vl_peer), | |
9111 | ck->key_id, ck->auth_key); | |
9112 | } | |
9113 | } | |
9114 | ||
9115 | return 0; | |
718e3744 | 9116 | } |
9117 | ||
6b0655a2 | 9118 | |
d62a17ae | 9119 | static int config_write_ospf_redistribute(struct vty *vty, struct ospf *ospf) |
718e3744 | 9120 | { |
d62a17ae | 9121 | int type; |
718e3744 | 9122 | |
d62a17ae | 9123 | /* redistribute print. */ |
9124 | for (type = 0; type < ZEBRA_ROUTE_MAX; type++) { | |
9125 | struct list *red_list; | |
9126 | struct listnode *node; | |
9127 | struct ospf_redist *red; | |
718e3744 | 9128 | |
d62a17ae | 9129 | red_list = ospf->redist[type]; |
9130 | if (!red_list) | |
9131 | continue; | |
7c8ff89e | 9132 | |
d62a17ae | 9133 | for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) { |
9134 | vty_out(vty, " redistribute %s", | |
9135 | zebra_route_string(type)); | |
9136 | if (red->instance) | |
9137 | vty_out(vty, " %d", red->instance); | |
7c8ff89e | 9138 | |
d62a17ae | 9139 | if (red->dmetric.value >= 0) |
9140 | vty_out(vty, " metric %d", red->dmetric.value); | |
7c8ff89e | 9141 | |
d62a17ae | 9142 | if (red->dmetric.type == EXTERNAL_METRIC_TYPE_1) |
9143 | vty_out(vty, " metric-type 1"); | |
7c8ff89e | 9144 | |
d62a17ae | 9145 | if (ROUTEMAP_NAME(red)) |
9146 | vty_out(vty, " route-map %s", | |
9147 | ROUTEMAP_NAME(red)); | |
7c8ff89e | 9148 | |
d62a17ae | 9149 | vty_out(vty, "\n"); |
9150 | } | |
9151 | } | |
718e3744 | 9152 | |
d62a17ae | 9153 | return 0; |
718e3744 | 9154 | } |
9155 | ||
d62a17ae | 9156 | static int config_write_ospf_default_metric(struct vty *vty, struct ospf *ospf) |
718e3744 | 9157 | { |
d62a17ae | 9158 | if (ospf->default_metric != -1) |
9159 | vty_out(vty, " default-metric %d\n", ospf->default_metric); | |
9160 | return 0; | |
718e3744 | 9161 | } |
9162 | ||
d62a17ae | 9163 | static int config_write_ospf_distribute(struct vty *vty, struct ospf *ospf) |
9164 | { | |
9165 | int type; | |
9166 | struct ospf_redist *red; | |
718e3744 | 9167 | |
d62a17ae | 9168 | if (ospf) { |
9169 | /* distribute-list print. */ | |
9170 | for (type = 0; type < ZEBRA_ROUTE_MAX; type++) | |
9171 | if (DISTRIBUTE_NAME(ospf, type)) | |
9172 | vty_out(vty, " distribute-list %s out %s\n", | |
9173 | DISTRIBUTE_NAME(ospf, type), | |
9174 | zebra_route_string(type)); | |
7c8ff89e | 9175 | |
d62a17ae | 9176 | /* default-information print. */ |
9177 | if (ospf->default_originate != DEFAULT_ORIGINATE_NONE) { | |
9178 | vty_out(vty, " default-information originate"); | |
9179 | if (ospf->default_originate == DEFAULT_ORIGINATE_ALWAYS) | |
9180 | vty_out(vty, " always"); | |
718e3744 | 9181 | |
d62a17ae | 9182 | red = ospf_redist_lookup(ospf, DEFAULT_ROUTE, 0); |
9183 | if (red) { | |
9184 | if (red->dmetric.value >= 0) | |
9185 | vty_out(vty, " metric %d", | |
9186 | red->dmetric.value); | |
9187 | if (red->dmetric.type == EXTERNAL_METRIC_TYPE_1) | |
9188 | vty_out(vty, " metric-type 1"); | |
718e3744 | 9189 | |
d62a17ae | 9190 | if (ROUTEMAP_NAME(red)) |
9191 | vty_out(vty, " route-map %s", | |
9192 | ROUTEMAP_NAME(red)); | |
9193 | } | |
9194 | ||
9195 | vty_out(vty, "\n"); | |
9196 | } | |
9197 | } | |
9198 | ||
9199 | return 0; | |
718e3744 | 9200 | } |
9201 | ||
d62a17ae | 9202 | static int config_write_ospf_distance(struct vty *vty, struct ospf *ospf) |
9203 | { | |
9204 | struct route_node *rn; | |
9205 | struct ospf_distance *odistance; | |
9206 | ||
9207 | if (ospf->distance_all) | |
9208 | vty_out(vty, " distance %d\n", ospf->distance_all); | |
9209 | ||
9210 | if (ospf->distance_intra || ospf->distance_inter | |
9211 | || ospf->distance_external) { | |
9212 | vty_out(vty, " distance ospf"); | |
9213 | ||
9214 | if (ospf->distance_intra) | |
9215 | vty_out(vty, " intra-area %d", ospf->distance_intra); | |
9216 | if (ospf->distance_inter) | |
9217 | vty_out(vty, " inter-area %d", ospf->distance_inter); | |
9218 | if (ospf->distance_external) | |
9219 | vty_out(vty, " external %d", ospf->distance_external); | |
9220 | ||
9221 | vty_out(vty, "\n"); | |
9222 | } | |
9223 | ||
9224 | for (rn = route_top(ospf->distance_table); rn; rn = route_next(rn)) | |
9225 | if ((odistance = rn->info) != NULL) { | |
9226 | vty_out(vty, " distance %d %s/%d %s\n", | |
9227 | odistance->distance, inet_ntoa(rn->p.u.prefix4), | |
9228 | rn->p.prefixlen, | |
9229 | odistance->access_list ? odistance->access_list | |
9230 | : ""); | |
9231 | } | |
9232 | return 0; | |
718e3744 | 9233 | } |
9234 | ||
43b8d1d8 | 9235 | static int ospf_config_write_one(struct vty *vty, struct ospf *ospf) |
d62a17ae | 9236 | { |
d62a17ae | 9237 | struct interface *ifp; |
9238 | struct ospf_interface *oi; | |
43b8d1d8 | 9239 | struct listnode *node = NULL; |
d62a17ae | 9240 | int write = 0; |
9241 | ||
43b8d1d8 CS |
9242 | /* `router ospf' print. */ |
9243 | if (ospf->instance && ospf->name) { | |
9244 | vty_out(vty, "router ospf %d vrf %s\n", | |
9245 | ospf->instance, ospf->name); | |
9246 | } else if (ospf->instance) { | |
9247 | vty_out(vty, "router ospf %d\n", | |
9248 | ospf->instance); | |
9249 | } else if (ospf->name) { | |
9250 | vty_out(vty, "router ospf vrf %s\n", | |
9251 | ospf->name); | |
9252 | } else | |
9253 | vty_out(vty, "router ospf\n"); | |
9254 | ||
9255 | if (!ospf->networks) { | |
9256 | write++; | |
b5a8894d | 9257 | return write; |
43b8d1d8 | 9258 | } |
d62a17ae | 9259 | |
43b8d1d8 CS |
9260 | /* Router ID print. */ |
9261 | if (ospf->router_id_static.s_addr != 0) | |
9262 | vty_out(vty, " ospf router-id %s\n", | |
9263 | inet_ntoa(ospf->router_id_static)); | |
d62a17ae | 9264 | |
43b8d1d8 CS |
9265 | /* ABR type print. */ |
9266 | if (ospf->abr_type != OSPF_ABR_DEFAULT) | |
9267 | vty_out(vty, " ospf abr-type %s\n", | |
9268 | ospf_abr_type_str[ospf->abr_type]); | |
b5a8894d | 9269 | |
43b8d1d8 CS |
9270 | /* log-adjacency-changes flag print. */ |
9271 | if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES)) { | |
9272 | if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL)) | |
9273 | vty_out(vty, " log-adjacency-changes detail\n"); | |
9274 | else if (!DFLT_OSPF_LOG_ADJACENCY_CHANGES) | |
9275 | vty_out(vty, " log-adjacency-changes\n"); | |
9276 | } else if (DFLT_OSPF_LOG_ADJACENCY_CHANGES) { | |
9277 | vty_out(vty, " no log-adjacency-changes\n"); | |
9278 | } | |
b5a8894d | 9279 | |
43b8d1d8 CS |
9280 | /* RFC1583 compatibility flag print -- Compatible with CISCO |
9281 | * 12.1. */ | |
9282 | if (CHECK_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE)) | |
9283 | vty_out(vty, " compatible rfc1583\n"); | |
d62a17ae | 9284 | |
43b8d1d8 CS |
9285 | /* auto-cost reference-bandwidth configuration. */ |
9286 | if (ospf->ref_bandwidth != OSPF_DEFAULT_REF_BANDWIDTH) { | |
9287 | vty_out(vty, | |
9288 | "! Important: ensure reference bandwidth " | |
9289 | "is consistent across all routers\n"); | |
9290 | vty_out(vty, " auto-cost reference-bandwidth %d\n", | |
9291 | ospf->ref_bandwidth); | |
9292 | } | |
d62a17ae | 9293 | |
43b8d1d8 CS |
9294 | /* SPF timers print. */ |
9295 | if (ospf->spf_delay != OSPF_SPF_DELAY_DEFAULT | |
9296 | || ospf->spf_holdtime != OSPF_SPF_HOLDTIME_DEFAULT | |
9297 | || ospf->spf_max_holdtime != OSPF_SPF_MAX_HOLDTIME_DEFAULT) | |
9298 | vty_out(vty, " timers throttle spf %d %d %d\n", | |
9299 | ospf->spf_delay, ospf->spf_holdtime, | |
9300 | ospf->spf_max_holdtime); | |
9301 | ||
9302 | /* LSA timers print. */ | |
9303 | if (ospf->min_ls_interval != OSPF_MIN_LS_INTERVAL) | |
9304 | vty_out(vty, " timers throttle lsa all %d\n", | |
9305 | ospf->min_ls_interval); | |
9306 | if (ospf->min_ls_arrival != OSPF_MIN_LS_ARRIVAL) | |
9307 | vty_out(vty, " timers lsa min-arrival %d\n", | |
9308 | ospf->min_ls_arrival); | |
9309 | ||
9310 | /* Write multiplier print. */ | |
9311 | if (ospf->write_oi_count != OSPF_WRITE_INTERFACE_COUNT_DEFAULT) | |
9312 | vty_out(vty, " ospf write-multiplier %d\n", | |
9313 | ospf->write_oi_count); | |
d62a17ae | 9314 | |
43b8d1d8 CS |
9315 | /* Max-metric router-lsa print */ |
9316 | config_write_stub_router(vty, ospf); | |
d62a17ae | 9317 | |
43b8d1d8 CS |
9318 | /* SPF refresh parameters print. */ |
9319 | if (ospf->lsa_refresh_interval | |
9320 | != OSPF_LSA_REFRESH_INTERVAL_DEFAULT) | |
9321 | vty_out(vty, " refresh timer %d\n", | |
9322 | ospf->lsa_refresh_interval); | |
d62a17ae | 9323 | |
43b8d1d8 CS |
9324 | /* Redistribute information print. */ |
9325 | config_write_ospf_redistribute(vty, ospf); | |
d62a17ae | 9326 | |
43b8d1d8 CS |
9327 | /* passive-interface print. */ |
9328 | if (ospf->passive_interface_default == OSPF_IF_PASSIVE) | |
9329 | vty_out(vty, " passive-interface default\n"); | |
d62a17ae | 9330 | |
f1a03930 | 9331 | for (ALL_LIST_ELEMENTS_RO(vrf_iflist(ospf->vrf_id), node, ifp)) |
43b8d1d8 CS |
9332 | if (OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(ifp), |
9333 | passive_interface) | |
9334 | && IF_DEF_PARAMS(ifp)->passive_interface | |
9335 | != ospf->passive_interface_default) { | |
9336 | vty_out(vty, " %spassive-interface %s\n", | |
9337 | IF_DEF_PARAMS(ifp)->passive_interface | |
9338 | ? "" | |
9339 | : "no ", | |
9340 | ifp->name); | |
9341 | } | |
9342 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) { | |
9343 | if (!OSPF_IF_PARAM_CONFIGURED(oi->params, | |
9344 | passive_interface)) | |
9345 | continue; | |
9346 | if (OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(oi->ifp), | |
9347 | passive_interface)) { | |
9348 | if (oi->params->passive_interface | |
9349 | == IF_DEF_PARAMS(oi->ifp) | |
9350 | ->passive_interface) | |
9351 | continue; | |
9352 | } else if (oi->params->passive_interface | |
9353 | == ospf->passive_interface_default) | |
9354 | continue; | |
d62a17ae | 9355 | |
43b8d1d8 CS |
9356 | vty_out(vty, " %spassive-interface %s %s\n", |
9357 | oi->params->passive_interface ? "" : "no ", | |
9358 | oi->ifp->name, | |
9359 | inet_ntoa(oi->address->u.prefix4)); | |
9360 | } | |
d62a17ae | 9361 | |
43b8d1d8 CS |
9362 | /* Network area print. */ |
9363 | config_write_network_area(vty, ospf); | |
d62a17ae | 9364 | |
43b8d1d8 CS |
9365 | /* Area config print. */ |
9366 | config_write_ospf_area(vty, ospf); | |
d62a17ae | 9367 | |
43b8d1d8 CS |
9368 | /* static neighbor print. */ |
9369 | config_write_ospf_nbr_nbma(vty, ospf); | |
9370 | ||
9371 | /* Virtual-Link print. */ | |
9372 | config_write_virtual_link(vty, ospf); | |
9373 | ||
9374 | /* Default metric configuration. */ | |
9375 | config_write_ospf_default_metric(vty, ospf); | |
9376 | ||
9377 | /* Distribute-list and default-information print. */ | |
9378 | config_write_ospf_distribute(vty, ospf); | |
9379 | ||
9380 | /* Distance configuration. */ | |
9381 | config_write_ospf_distance(vty, ospf); | |
9382 | ||
9383 | ospf_opaque_config_write_router(vty, ospf); | |
9384 | ||
9385 | write++; | |
9386 | return write; | |
9387 | } | |
9388 | ||
9389 | /* OSPF configuration write function. */ | |
9390 | static int ospf_config_write(struct vty *vty) | |
9391 | { | |
9392 | struct ospf *ospf; | |
9393 | struct listnode *ospf_node = NULL; | |
9394 | int write = 0; | |
9395 | ||
9396 | if (listcount(om->ospf) == 0) | |
9397 | return write; | |
9398 | ||
9399 | for (ALL_LIST_ELEMENTS_RO(om->ospf, ospf_node, ospf)) { | |
9400 | if (ospf->oi_running) | |
9401 | write += ospf_config_write_one(vty, ospf); | |
b5a8894d | 9402 | } |
d62a17ae | 9403 | return write; |
9404 | } | |
9405 | ||
9406 | void ospf_vty_show_init(void) | |
9407 | { | |
9408 | /* "show ip ospf" commands. */ | |
9409 | install_element(VIEW_NODE, &show_ip_ospf_cmd); | |
9410 | ||
9411 | install_element(VIEW_NODE, &show_ip_ospf_instance_cmd); | |
9412 | ||
9413 | /* "show ip ospf database" commands. */ | |
9414 | install_element(VIEW_NODE, &show_ip_ospf_database_max_cmd); | |
9415 | ||
9416 | install_element(VIEW_NODE, | |
9417 | &show_ip_ospf_instance_database_type_adv_router_cmd); | |
9418 | install_element(VIEW_NODE, &show_ip_ospf_instance_database_cmd); | |
9419 | install_element(VIEW_NODE, &show_ip_ospf_instance_database_max_cmd); | |
9420 | ||
9421 | /* "show ip ospf interface" commands. */ | |
9422 | install_element(VIEW_NODE, &show_ip_ospf_interface_cmd); | |
9423 | ||
9424 | install_element(VIEW_NODE, &show_ip_ospf_instance_interface_cmd); | |
9425 | ||
9426 | /* "show ip ospf neighbor" commands. */ | |
9427 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_int_detail_cmd); | |
9428 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_int_cmd); | |
9429 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_id_cmd); | |
9430 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_detail_all_cmd); | |
9431 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_detail_cmd); | |
9432 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_cmd); | |
9433 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_all_cmd); | |
9434 | ||
9435 | install_element(VIEW_NODE, | |
9436 | &show_ip_ospf_instance_neighbor_int_detail_cmd); | |
9437 | install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_int_cmd); | |
9438 | install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_id_cmd); | |
9439 | install_element(VIEW_NODE, | |
9440 | &show_ip_ospf_instance_neighbor_detail_all_cmd); | |
9441 | install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_detail_cmd); | |
9442 | install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_cmd); | |
9443 | install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_all_cmd); | |
9444 | ||
9445 | /* "show ip ospf route" commands. */ | |
9446 | install_element(VIEW_NODE, &show_ip_ospf_route_cmd); | |
9447 | install_element(VIEW_NODE, &show_ip_ospf_border_routers_cmd); | |
9448 | ||
9449 | install_element(VIEW_NODE, &show_ip_ospf_instance_route_cmd); | |
9450 | install_element(VIEW_NODE, &show_ip_ospf_instance_border_routers_cmd); | |
b5a8894d CS |
9451 | |
9452 | /* "show ip ospf vrfs" commands. */ | |
9453 | install_element(VIEW_NODE, &show_ip_ospf_vrfs_cmd); | |
718e3744 | 9454 | } |
9455 | ||
6b0655a2 | 9456 | |
718e3744 | 9457 | /* ospfd's interface node. */ |
d62a17ae | 9458 | static struct cmd_node interface_node = {INTERFACE_NODE, "%s(config-if)# ", 1}; |
718e3744 | 9459 | |
9460 | /* Initialization of OSPF interface. */ | |
d62a17ae | 9461 | static void ospf_vty_if_init(void) |
9462 | { | |
9463 | /* Install interface node. */ | |
9464 | install_node(&interface_node, config_write_interface); | |
9465 | if_cmd_init(); | |
9466 | ||
9467 | /* "ip ospf authentication" commands. */ | |
9468 | install_element(INTERFACE_NODE, &ip_ospf_authentication_args_addr_cmd); | |
9469 | install_element(INTERFACE_NODE, &ip_ospf_authentication_addr_cmd); | |
9470 | install_element(INTERFACE_NODE, | |
9471 | &no_ip_ospf_authentication_args_addr_cmd); | |
9472 | install_element(INTERFACE_NODE, &no_ip_ospf_authentication_addr_cmd); | |
9473 | install_element(INTERFACE_NODE, &ip_ospf_authentication_key_addr_cmd); | |
9474 | install_element(INTERFACE_NODE, | |
9475 | &no_ip_ospf_authentication_key_authkey_addr_cmd); | |
9476 | install_element(INTERFACE_NODE, | |
9477 | &no_ospf_authentication_key_authkey_addr_cmd); | |
9478 | ||
9479 | /* "ip ospf message-digest-key" commands. */ | |
9480 | install_element(INTERFACE_NODE, &ip_ospf_message_digest_key_cmd); | |
9481 | install_element(INTERFACE_NODE, &no_ip_ospf_message_digest_key_cmd); | |
9482 | ||
9483 | /* "ip ospf cost" commands. */ | |
9484 | install_element(INTERFACE_NODE, &ip_ospf_cost_cmd); | |
9485 | install_element(INTERFACE_NODE, &no_ip_ospf_cost_cmd); | |
9486 | ||
9487 | /* "ip ospf mtu-ignore" commands. */ | |
9488 | install_element(INTERFACE_NODE, &ip_ospf_mtu_ignore_addr_cmd); | |
9489 | install_element(INTERFACE_NODE, &no_ip_ospf_mtu_ignore_addr_cmd); | |
9490 | ||
9491 | /* "ip ospf dead-interval" commands. */ | |
9492 | install_element(INTERFACE_NODE, &ip_ospf_dead_interval_cmd); | |
9493 | install_element(INTERFACE_NODE, | |
9494 | &ip_ospf_dead_interval_minimal_addr_cmd); | |
9495 | install_element(INTERFACE_NODE, &no_ip_ospf_dead_interval_cmd); | |
9496 | ||
9497 | /* "ip ospf hello-interval" commands. */ | |
9498 | install_element(INTERFACE_NODE, &ip_ospf_hello_interval_cmd); | |
9499 | install_element(INTERFACE_NODE, &no_ip_ospf_hello_interval_cmd); | |
9500 | ||
9501 | /* "ip ospf network" commands. */ | |
9502 | install_element(INTERFACE_NODE, &ip_ospf_network_cmd); | |
9503 | install_element(INTERFACE_NODE, &no_ip_ospf_network_cmd); | |
9504 | ||
9505 | /* "ip ospf priority" commands. */ | |
9506 | install_element(INTERFACE_NODE, &ip_ospf_priority_cmd); | |
9507 | install_element(INTERFACE_NODE, &no_ip_ospf_priority_cmd); | |
9508 | ||
9509 | /* "ip ospf retransmit-interval" commands. */ | |
9510 | install_element(INTERFACE_NODE, &ip_ospf_retransmit_interval_addr_cmd); | |
9511 | install_element(INTERFACE_NODE, | |
9512 | &no_ip_ospf_retransmit_interval_addr_cmd); | |
9513 | ||
9514 | /* "ip ospf transmit-delay" commands. */ | |
9515 | install_element(INTERFACE_NODE, &ip_ospf_transmit_delay_addr_cmd); | |
9516 | install_element(INTERFACE_NODE, &no_ip_ospf_transmit_delay_addr_cmd); | |
9517 | ||
9518 | /* "ip ospf area" commands. */ | |
9519 | install_element(INTERFACE_NODE, &ip_ospf_area_cmd); | |
9520 | install_element(INTERFACE_NODE, &no_ip_ospf_area_cmd); | |
9521 | ||
9522 | /* These commands are compatibitliy for previous version. */ | |
9523 | install_element(INTERFACE_NODE, &ospf_authentication_key_cmd); | |
9524 | install_element(INTERFACE_NODE, &ospf_message_digest_key_cmd); | |
9525 | install_element(INTERFACE_NODE, &no_ospf_message_digest_key_cmd); | |
9526 | install_element(INTERFACE_NODE, &ospf_dead_interval_cmd); | |
9527 | install_element(INTERFACE_NODE, &no_ospf_dead_interval_cmd); | |
9528 | install_element(INTERFACE_NODE, &ospf_hello_interval_cmd); | |
9529 | install_element(INTERFACE_NODE, &no_ospf_hello_interval_cmd); | |
9530 | install_element(INTERFACE_NODE, &ospf_cost_cmd); | |
9531 | install_element(INTERFACE_NODE, &no_ospf_cost_cmd); | |
9532 | install_element(INTERFACE_NODE, &ospf_network_cmd); | |
9533 | install_element(INTERFACE_NODE, &no_ospf_network_cmd); | |
9534 | install_element(INTERFACE_NODE, &ospf_priority_cmd); | |
9535 | install_element(INTERFACE_NODE, &no_ospf_priority_cmd); | |
9536 | install_element(INTERFACE_NODE, &ospf_retransmit_interval_cmd); | |
9537 | install_element(INTERFACE_NODE, &no_ospf_retransmit_interval_cmd); | |
9538 | install_element(INTERFACE_NODE, &ospf_transmit_delay_cmd); | |
9539 | install_element(INTERFACE_NODE, &no_ospf_transmit_delay_cmd); | |
9540 | } | |
9541 | ||
9542 | static void ospf_vty_zebra_init(void) | |
9543 | { | |
9544 | install_element(OSPF_NODE, &ospf_redistribute_source_cmd); | |
9545 | install_element(OSPF_NODE, &no_ospf_redistribute_source_cmd); | |
9546 | install_element(OSPF_NODE, &ospf_redistribute_instance_source_cmd); | |
9547 | install_element(OSPF_NODE, &no_ospf_redistribute_instance_source_cmd); | |
9548 | ||
9549 | install_element(OSPF_NODE, &ospf_distribute_list_out_cmd); | |
9550 | install_element(OSPF_NODE, &no_ospf_distribute_list_out_cmd); | |
9551 | ||
9552 | install_element(OSPF_NODE, &ospf_default_information_originate_cmd); | |
9553 | install_element(OSPF_NODE, &no_ospf_default_information_originate_cmd); | |
9554 | ||
9555 | install_element(OSPF_NODE, &ospf_default_metric_cmd); | |
9556 | install_element(OSPF_NODE, &no_ospf_default_metric_cmd); | |
9557 | ||
9558 | install_element(OSPF_NODE, &ospf_distance_cmd); | |
9559 | install_element(OSPF_NODE, &no_ospf_distance_cmd); | |
9560 | install_element(OSPF_NODE, &no_ospf_distance_ospf_cmd); | |
9561 | install_element(OSPF_NODE, &ospf_distance_ospf_cmd); | |
718e3744 | 9562 | #if 0 |
9563 | install_element (OSPF_NODE, &ospf_distance_source_cmd); | |
9564 | install_element (OSPF_NODE, &no_ospf_distance_source_cmd); | |
9565 | install_element (OSPF_NODE, &ospf_distance_source_access_list_cmd); | |
9566 | install_element (OSPF_NODE, &no_ospf_distance_source_access_list_cmd); | |
9567 | #endif /* 0 */ | |
9568 | } | |
9569 | ||
d62a17ae | 9570 | static struct cmd_node ospf_node = {OSPF_NODE, "%s(config-router)# ", 1}; |
718e3744 | 9571 | |
d62a17ae | 9572 | static void ospf_interface_clear(struct interface *ifp) |
09f35f8c | 9573 | { |
d62a17ae | 9574 | if (!if_is_operative(ifp)) |
9575 | return; | |
09f35f8c | 9576 | |
d62a17ae | 9577 | if (IS_DEBUG_OSPF(ism, ISM_EVENTS)) |
9578 | zlog_debug("ISM[%s]: clear by reset", ifp->name); | |
09f35f8c | 9579 | |
d62a17ae | 9580 | ospf_if_reset(ifp); |
09f35f8c DS |
9581 | } |
9582 | ||
9583 | DEFUN (clear_ip_ospf_interface, | |
9584 | clear_ip_ospf_interface_cmd, | |
9585 | "clear ip ospf interface [IFNAME]", | |
9586 | CLEAR_STR | |
9587 | IP_STR | |
9588 | "OSPF information\n" | |
9589 | "Interface information\n" | |
9590 | "Interface name\n") | |
9591 | { | |
d62a17ae | 9592 | int idx_ifname = 4; |
9593 | struct interface *ifp; | |
b5a8894d CS |
9594 | struct listnode *node, *n1; |
9595 | struct ospf *ospf = NULL; | |
09f35f8c | 9596 | |
d62a17ae | 9597 | if (argc == 4) /* Clear all the ospfv2 interfaces. */ |
9598 | { | |
b5a8894d CS |
9599 | for (ALL_LIST_ELEMENTS_RO(om->ospf, n1, ospf)) { |
9600 | for (ALL_LIST_ELEMENTS_RO(vrf_iflist(ospf->vrf_id), | |
9601 | node, ifp)) | |
9602 | ospf_interface_clear(ifp); | |
9603 | } | |
9604 | } else { | |
9605 | /* Interface name is specified. */ | |
9606 | ifp = if_lookup_by_name_all_vrf(argv[idx_ifname]->arg); | |
9607 | if (ifp == NULL) | |
d62a17ae | 9608 | vty_out(vty, "No such interface name\n"); |
9609 | else | |
9610 | ospf_interface_clear(ifp); | |
9611 | } | |
9612 | ||
9613 | return CMD_SUCCESS; | |
09f35f8c DS |
9614 | } |
9615 | ||
d62a17ae | 9616 | void ospf_vty_clear_init(void) |
09f35f8c | 9617 | { |
d62a17ae | 9618 | install_element(ENABLE_NODE, &clear_ip_ospf_interface_cmd); |
09f35f8c DS |
9619 | } |
9620 | ||
6b0655a2 | 9621 | |
718e3744 | 9622 | /* Install OSPF related vty commands. */ |
d62a17ae | 9623 | void ospf_vty_init(void) |
9624 | { | |
9625 | /* Install ospf top node. */ | |
9626 | install_node(&ospf_node, ospf_config_write); | |
9627 | ||
9628 | /* "router ospf" commands. */ | |
9629 | install_element(CONFIG_NODE, &router_ospf_cmd); | |
9630 | install_element(CONFIG_NODE, &no_router_ospf_cmd); | |
9631 | ||
9632 | ||
9633 | install_default(OSPF_NODE); | |
9634 | ||
9635 | /* "ospf router-id" commands. */ | |
9636 | install_element(OSPF_NODE, &ospf_router_id_cmd); | |
9637 | install_element(OSPF_NODE, &ospf_router_id_old_cmd); | |
9638 | install_element(OSPF_NODE, &no_ospf_router_id_cmd); | |
9639 | ||
9640 | /* "passive-interface" commands. */ | |
9641 | install_element(OSPF_NODE, &ospf_passive_interface_addr_cmd); | |
9642 | install_element(OSPF_NODE, &no_ospf_passive_interface_addr_cmd); | |
9643 | ||
9644 | /* "ospf abr-type" commands. */ | |
9645 | install_element(OSPF_NODE, &ospf_abr_type_cmd); | |
9646 | install_element(OSPF_NODE, &no_ospf_abr_type_cmd); | |
9647 | ||
9648 | /* "ospf log-adjacency-changes" commands. */ | |
9649 | install_element(OSPF_NODE, &ospf_log_adjacency_changes_cmd); | |
9650 | install_element(OSPF_NODE, &ospf_log_adjacency_changes_detail_cmd); | |
9651 | install_element(OSPF_NODE, &no_ospf_log_adjacency_changes_cmd); | |
9652 | install_element(OSPF_NODE, &no_ospf_log_adjacency_changes_detail_cmd); | |
9653 | ||
9654 | /* "ospf rfc1583-compatible" commands. */ | |
9655 | install_element(OSPF_NODE, &ospf_compatible_rfc1583_cmd); | |
9656 | install_element(OSPF_NODE, &no_ospf_compatible_rfc1583_cmd); | |
9657 | install_element(OSPF_NODE, &ospf_rfc1583_flag_cmd); | |
9658 | install_element(OSPF_NODE, &no_ospf_rfc1583_flag_cmd); | |
9659 | ||
9660 | /* "network area" commands. */ | |
9661 | install_element(OSPF_NODE, &ospf_network_area_cmd); | |
9662 | install_element(OSPF_NODE, &no_ospf_network_area_cmd); | |
9663 | ||
9664 | /* "area authentication" commands. */ | |
9665 | install_element(OSPF_NODE, | |
9666 | &ospf_area_authentication_message_digest_cmd); | |
9667 | install_element(OSPF_NODE, &ospf_area_authentication_cmd); | |
9668 | install_element(OSPF_NODE, &no_ospf_area_authentication_cmd); | |
9669 | ||
9670 | /* "area range" commands. */ | |
9671 | install_element(OSPF_NODE, &ospf_area_range_cmd); | |
9672 | install_element(OSPF_NODE, &ospf_area_range_cost_cmd); | |
9673 | install_element(OSPF_NODE, &ospf_area_range_not_advertise_cmd); | |
9674 | install_element(OSPF_NODE, &no_ospf_area_range_cmd); | |
9675 | install_element(OSPF_NODE, &ospf_area_range_substitute_cmd); | |
9676 | install_element(OSPF_NODE, &no_ospf_area_range_substitute_cmd); | |
9677 | ||
9678 | /* "area virtual-link" commands. */ | |
9679 | install_element(OSPF_NODE, &ospf_area_vlink_cmd); | |
9680 | install_element(OSPF_NODE, &ospf_area_vlink_intervals_cmd); | |
9681 | install_element(OSPF_NODE, &no_ospf_area_vlink_cmd); | |
9682 | install_element(OSPF_NODE, &no_ospf_area_vlink_intervals_cmd); | |
9683 | ||
9684 | ||
9685 | /* "area stub" commands. */ | |
9686 | install_element(OSPF_NODE, &ospf_area_stub_no_summary_cmd); | |
9687 | install_element(OSPF_NODE, &ospf_area_stub_cmd); | |
9688 | install_element(OSPF_NODE, &no_ospf_area_stub_no_summary_cmd); | |
9689 | install_element(OSPF_NODE, &no_ospf_area_stub_cmd); | |
9690 | ||
9691 | /* "area nssa" commands. */ | |
9692 | install_element(OSPF_NODE, &ospf_area_nssa_cmd); | |
9693 | install_element(OSPF_NODE, &ospf_area_nssa_translate_no_summary_cmd); | |
9694 | install_element(OSPF_NODE, &ospf_area_nssa_translate_cmd); | |
9695 | install_element(OSPF_NODE, &ospf_area_nssa_no_summary_cmd); | |
9696 | install_element(OSPF_NODE, &no_ospf_area_nssa_cmd); | |
9697 | ||
9698 | install_element(OSPF_NODE, &ospf_area_default_cost_cmd); | |
9699 | install_element(OSPF_NODE, &no_ospf_area_default_cost_cmd); | |
9700 | ||
9701 | install_element(OSPF_NODE, &ospf_area_shortcut_cmd); | |
9702 | install_element(OSPF_NODE, &no_ospf_area_shortcut_cmd); | |
9703 | ||
9704 | install_element(OSPF_NODE, &ospf_area_export_list_cmd); | |
9705 | install_element(OSPF_NODE, &no_ospf_area_export_list_cmd); | |
9706 | ||
9707 | install_element(OSPF_NODE, &ospf_area_filter_list_cmd); | |
9708 | install_element(OSPF_NODE, &no_ospf_area_filter_list_cmd); | |
9709 | ||
9710 | install_element(OSPF_NODE, &ospf_area_import_list_cmd); | |
9711 | install_element(OSPF_NODE, &no_ospf_area_import_list_cmd); | |
9712 | ||
9713 | /* SPF timer commands */ | |
9714 | install_element(OSPF_NODE, &ospf_timers_throttle_spf_cmd); | |
9715 | install_element(OSPF_NODE, &no_ospf_timers_throttle_spf_cmd); | |
9716 | ||
9717 | /* LSA timers commands */ | |
9718 | install_element(OSPF_NODE, &ospf_timers_min_ls_interval_cmd); | |
9719 | install_element(OSPF_NODE, &no_ospf_timers_min_ls_interval_cmd); | |
0e88de35 QY |
9720 | install_element(OSPF_NODE, &ospf_timers_lsa_min_arrival_cmd); |
9721 | install_element(OSPF_NODE, &no_ospf_timers_lsa_min_arrival_cmd); | |
9722 | install_element(OSPF_NODE, &ospf_timers_lsa_arrival_cmd); | |
9723 | install_element(OSPF_NODE, &no_ospf_timers_lsa_arrival_cmd); | |
d62a17ae | 9724 | |
9725 | /* refresh timer commands */ | |
9726 | install_element(OSPF_NODE, &ospf_refresh_timer_cmd); | |
9727 | install_element(OSPF_NODE, &no_ospf_refresh_timer_val_cmd); | |
9728 | ||
9729 | /* max-metric commands */ | |
9730 | install_element(OSPF_NODE, &ospf_max_metric_router_lsa_admin_cmd); | |
9731 | install_element(OSPF_NODE, &no_ospf_max_metric_router_lsa_admin_cmd); | |
9732 | install_element(OSPF_NODE, &ospf_max_metric_router_lsa_startup_cmd); | |
9733 | install_element(OSPF_NODE, &no_ospf_max_metric_router_lsa_startup_cmd); | |
9734 | install_element(OSPF_NODE, &ospf_max_metric_router_lsa_shutdown_cmd); | |
9735 | install_element(OSPF_NODE, &no_ospf_max_metric_router_lsa_shutdown_cmd); | |
9736 | ||
9737 | /* reference bandwidth commands */ | |
9738 | install_element(OSPF_NODE, &ospf_auto_cost_reference_bandwidth_cmd); | |
9739 | install_element(OSPF_NODE, &no_ospf_auto_cost_reference_bandwidth_cmd); | |
9740 | ||
9741 | /* "neighbor" commands. */ | |
9742 | install_element(OSPF_NODE, &ospf_neighbor_cmd); | |
9743 | install_element(OSPF_NODE, &ospf_neighbor_poll_interval_cmd); | |
9744 | install_element(OSPF_NODE, &no_ospf_neighbor_cmd); | |
9745 | install_element(OSPF_NODE, &no_ospf_neighbor_poll_cmd); | |
9746 | ||
9747 | /* write multiplier commands */ | |
9748 | install_element(OSPF_NODE, &ospf_write_multiplier_cmd); | |
9749 | install_element(OSPF_NODE, &write_multiplier_cmd); | |
9750 | install_element(OSPF_NODE, &no_ospf_write_multiplier_cmd); | |
9751 | install_element(OSPF_NODE, &no_write_multiplier_cmd); | |
9752 | ||
9753 | /* Init interface related vty commands. */ | |
9754 | ospf_vty_if_init(); | |
9755 | ||
9756 | /* Init zebra related vty commands. */ | |
9757 | ospf_vty_zebra_init(); | |
718e3744 | 9758 | } |