]>
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 | ||
b5a8894d CS |
416 | ifp = if_get_by_name(argv[1]->arg, ospf->vrf_id); |
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 | ||
b5a8894d CS |
488 | ifp = if_get_by_name(argv[2]->arg, ospf->vrf_id); |
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; | |
6398 | u_int32_t cost; | |
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; | |
c31a793b VJ |
6405 | argv_find(argv, argc, "(1-65535)", &idx); |
6406 | coststr = argv[idx]->arg; | |
d62a17ae | 6407 | cost = strtol(coststr, NULL, 10); |
6408 | ||
c31a793b | 6409 | ifaddr = argv_find(argv, argc, "A.B.C.D", &idx) ? argv[idx]->arg : NULL; |
d62a17ae | 6410 | if (ifaddr) { |
6411 | if (!inet_aton(ifaddr, &addr)) { | |
6412 | vty_out(vty, | |
6413 | "Please specify interface address by A.B.C.D\n"); | |
6414 | return CMD_WARNING_CONFIG_FAILED; | |
6415 | } | |
718e3744 | 6416 | |
d62a17ae | 6417 | params = ospf_get_if_params(ifp, addr); |
6418 | ospf_if_update_params(ifp, addr); | |
718e3744 | 6419 | } |
6420 | ||
d62a17ae | 6421 | SET_IF_PARAM(params, output_cost_cmd); |
6422 | params->output_cost_cmd = cost; | |
718e3744 | 6423 | |
d62a17ae | 6424 | ospf_if_recalculate_output_cost(ifp); |
5c2fc921 | 6425 | |
d62a17ae | 6426 | return CMD_SUCCESS; |
718e3744 | 6427 | } |
6428 | ||
7a7be519 | 6429 | DEFUN_HIDDEN (ospf_cost, |
5c2fc921 QY |
6430 | ospf_cost_cmd, |
6431 | "ospf cost (1-65535) [A.B.C.D]", | |
747e489c DW |
6432 | "OSPF interface commands\n" |
6433 | "Interface cost\n" | |
6434 | "Cost\n" | |
5c2fc921 | 6435 | "Address of interface\n") |
7a7be519 | 6436 | { |
d62a17ae | 6437 | return ip_ospf_cost(self, vty, argc, argv); |
7a7be519 | 6438 | } |
9eff36b3 | 6439 | |
718e3744 | 6440 | DEFUN (no_ip_ospf_cost, |
5c2fc921 QY |
6441 | no_ip_ospf_cost_cmd, |
6442 | "no ip ospf cost [(1-65535)] [A.B.C.D]", | |
718e3744 | 6443 | NO_STR |
718e3744 | 6444 | "OSPF interface commands\n" |
6445 | "Interface cost\n" | |
6446 | "Address of interface") | |
6447 | { | |
d62a17ae | 6448 | VTY_DECLVAR_CONTEXT(interface, ifp); |
6449 | int idx = 0; | |
6450 | struct in_addr addr; | |
6451 | struct ospf_if_params *params; | |
7a7be519 | 6452 | |
d62a17ae | 6453 | params = IF_DEF_PARAMS(ifp); |
718e3744 | 6454 | |
d62a17ae | 6455 | // get arguments |
6456 | char *ifaddr = NULL; | |
6457 | ifaddr = argv_find(argv, argc, "A.B.C.D", &idx) ? argv[idx]->arg : NULL; | |
718e3744 | 6458 | |
d62a17ae | 6459 | /* According to the semantics we are mimicking "no ip ospf cost N" is |
6460 | * always treated as "no ip ospf cost" regardless of the actual value | |
6461 | * of N already configured for the interface. Thus ignore cost. */ | |
7a7be519 | 6462 | |
d62a17ae | 6463 | if (ifaddr) { |
6464 | if (!inet_aton(ifaddr, &addr)) { | |
6465 | vty_out(vty, | |
6466 | "Please specify interface address by A.B.C.D\n"); | |
6467 | return CMD_WARNING_CONFIG_FAILED; | |
6468 | } | |
7a7be519 | 6469 | |
d62a17ae | 6470 | params = ospf_lookup_if_params(ifp, addr); |
6471 | if (params == NULL) | |
6472 | return CMD_SUCCESS; | |
6473 | } | |
7a7be519 | 6474 | |
d62a17ae | 6475 | UNSET_IF_PARAM(params, output_cost_cmd); |
7a7be519 | 6476 | |
d62a17ae | 6477 | if (params != IF_DEF_PARAMS(ifp)) { |
6478 | ospf_free_if_params(ifp, addr); | |
6479 | ospf_if_update_params(ifp, addr); | |
6480 | } | |
7a7be519 | 6481 | |
d62a17ae | 6482 | ospf_if_recalculate_output_cost(ifp); |
7a7be519 | 6483 | |
d62a17ae | 6484 | return CMD_SUCCESS; |
7a7be519 | 6485 | } |
9eff36b3 | 6486 | |
5c2fc921 QY |
6487 | DEFUN_HIDDEN (no_ospf_cost, |
6488 | no_ospf_cost_cmd, | |
6489 | "no ospf cost [(1-65535)] [A.B.C.D]", | |
6490 | NO_STR | |
6491 | "OSPF interface commands\n" | |
6492 | "Interface cost\n" | |
6493 | "Cost\n" | |
6494 | "Address of interface\n") | |
827341b7 | 6495 | { |
d62a17ae | 6496 | return no_ip_ospf_cost(self, vty, argc, argv); |
827341b7 DO |
6497 | } |
6498 | ||
d62a17ae | 6499 | static void ospf_nbr_timer_update(struct ospf_interface *oi) |
718e3744 | 6500 | { |
d62a17ae | 6501 | struct route_node *rn; |
6502 | struct ospf_neighbor *nbr; | |
718e3744 | 6503 | |
d62a17ae | 6504 | for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) |
6505 | if ((nbr = rn->info)) { | |
6506 | nbr->v_inactivity = OSPF_IF_PARAM(oi, v_wait); | |
6507 | nbr->v_db_desc = OSPF_IF_PARAM(oi, retransmit_interval); | |
6508 | nbr->v_ls_req = OSPF_IF_PARAM(oi, retransmit_interval); | |
6509 | nbr->v_ls_upd = OSPF_IF_PARAM(oi, retransmit_interval); | |
6510 | } | |
718e3744 | 6511 | } |
6512 | ||
d62a17ae | 6513 | static int ospf_vty_dead_interval_set(struct vty *vty, const char *interval_str, |
6514 | const char *nbr_str, | |
6515 | const char *fast_hello_str) | |
6516 | { | |
6517 | VTY_DECLVAR_CONTEXT(interface, ifp); | |
6518 | u_int32_t seconds; | |
6519 | u_char hellomult; | |
6520 | struct in_addr addr; | |
6521 | int ret; | |
6522 | struct ospf_if_params *params; | |
6523 | struct ospf_interface *oi; | |
6524 | struct route_node *rn; | |
718e3744 | 6525 | |
d62a17ae | 6526 | params = IF_DEF_PARAMS(ifp); |
6527 | ||
6528 | if (nbr_str) { | |
6529 | ret = inet_aton(nbr_str, &addr); | |
6530 | if (!ret) { | |
6531 | vty_out(vty, | |
6532 | "Please specify interface address by A.B.C.D\n"); | |
6533 | return CMD_WARNING_CONFIG_FAILED; | |
6534 | } | |
6535 | ||
6536 | params = ospf_get_if_params(ifp, addr); | |
6537 | ospf_if_update_params(ifp, addr); | |
6538 | } | |
6539 | ||
6540 | if (interval_str) { | |
6541 | seconds = strtoul(interval_str, NULL, 10); | |
6542 | ||
6543 | /* reset fast_hello too, just to be sure */ | |
6544 | UNSET_IF_PARAM(params, fast_hello); | |
6545 | params->fast_hello = OSPF_FAST_HELLO_DEFAULT; | |
6546 | } else if (fast_hello_str) { | |
6547 | hellomult = strtoul(fast_hello_str, NULL, 10); | |
6548 | /* 1s dead-interval with sub-second hellos desired */ | |
6549 | seconds = OSPF_ROUTER_DEAD_INTERVAL_MINIMAL; | |
6550 | SET_IF_PARAM(params, fast_hello); | |
6551 | params->fast_hello = hellomult; | |
6552 | } else { | |
6553 | vty_out(vty, | |
6554 | "Please specify dead-interval or hello-multiplier\n"); | |
6555 | return CMD_WARNING_CONFIG_FAILED; | |
6556 | } | |
6557 | ||
6558 | SET_IF_PARAM(params, v_wait); | |
6559 | params->v_wait = seconds; | |
6560 | ||
6561 | /* Update timer values in neighbor structure. */ | |
6562 | if (nbr_str) { | |
b5a8894d CS |
6563 | struct ospf *ospf = NULL; |
6564 | ||
6565 | ospf = ospf_lookup_by_vrf_id(ifp->vrf_id); | |
6566 | if (ospf) { | |
d62a17ae | 6567 | oi = ospf_if_lookup_by_local_addr(ospf, ifp, addr); |
6568 | if (oi) | |
6569 | ospf_nbr_timer_update(oi); | |
6570 | } | |
6571 | } else { | |
6572 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) | |
6573 | if ((oi = rn->info)) | |
6574 | ospf_nbr_timer_update(oi); | |
6575 | } | |
6576 | ||
6577 | return CMD_SUCCESS; | |
718e3744 | 6578 | } |
6579 | ||
f9ad937f | 6580 | DEFUN (ip_ospf_dead_interval, |
0d829fa7 | 6581 | ip_ospf_dead_interval_cmd, |
7a7be519 | 6582 | "ip ospf dead-interval (1-65535) [A.B.C.D]", |
f9ad937f | 6583 | "IP Information\n" |
6584 | "OSPF interface commands\n" | |
99a522c7 | 6585 | "Interval time after which a neighbor is declared down\n" |
f9ad937f | 6586 | "Seconds\n" |
6587 | "Address of interface\n") | |
6588 | { | |
d62a17ae | 6589 | int idx = 0; |
6590 | char *interval = argv_find(argv, argc, "(1-65535)", &idx) | |
6591 | ? argv[idx]->arg | |
6592 | : NULL; | |
6593 | char *ifaddr = | |
6594 | argv_find(argv, argc, "A.B.C.D", &idx) ? argv[idx]->arg : NULL; | |
6595 | return ospf_vty_dead_interval_set(vty, interval, ifaddr, NULL); | |
f9ad937f | 6596 | } |
6597 | ||
718e3744 | 6598 | |
7a7be519 | 6599 | DEFUN_HIDDEN (ospf_dead_interval, |
747e489c | 6600 | ospf_dead_interval_cmd, |
0d829fa7 | 6601 | "ospf dead-interval (1-65535) [A.B.C.D]", |
747e489c | 6602 | "OSPF interface commands\n" |
99a522c7 | 6603 | "Interval time after which a neighbor is declared down\n" |
0d829fa7 QY |
6604 | "Seconds\n" |
6605 | "Address of interface\n") | |
7a7be519 | 6606 | { |
d62a17ae | 6607 | return ip_ospf_dead_interval(self, vty, argc, argv); |
7a7be519 | 6608 | } |
718e3744 | 6609 | |
f9ad937f | 6610 | DEFUN (ip_ospf_dead_interval_minimal, |
6611 | ip_ospf_dead_interval_minimal_addr_cmd, | |
7a7be519 | 6612 | "ip ospf dead-interval minimal hello-multiplier (1-10) [A.B.C.D]", |
f9ad937f | 6613 | "IP Information\n" |
6614 | "OSPF interface commands\n" | |
99a522c7 | 6615 | "Interval time after which a neighbor is declared down\n" |
f9ad937f | 6616 | "Minimal 1s dead-interval with fast sub-second hellos\n" |
6617 | "Hello multiplier factor\n" | |
6618 | "Number of Hellos to send each second\n" | |
6619 | "Address of interface\n") | |
6620 | { | |
d62a17ae | 6621 | int idx_number = 5; |
6622 | int idx_ipv4 = 6; | |
6623 | if (argc == 7) | |
6624 | return ospf_vty_dead_interval_set( | |
6625 | vty, NULL, argv[idx_ipv4]->arg, argv[idx_number]->arg); | |
6626 | else | |
6627 | return ospf_vty_dead_interval_set(vty, NULL, NULL, | |
6628 | argv[idx_number]->arg); | |
f9ad937f | 6629 | } |
6630 | ||
718e3744 | 6631 | DEFUN (no_ip_ospf_dead_interval, |
0d829fa7 | 6632 | no_ip_ospf_dead_interval_cmd, |
e83a9414 | 6633 | "no ip ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]", |
718e3744 | 6634 | NO_STR |
6635 | "IP Information\n" | |
6636 | "OSPF interface commands\n" | |
99a522c7 | 6637 | "Interval time after which a neighbor is declared down\n" |
f9dfba8d | 6638 | "Seconds\n" |
718e3744 | 6639 | "Address of interface") |
6640 | { | |
d62a17ae | 6641 | VTY_DECLVAR_CONTEXT(interface, ifp); |
6642 | int idx_ipv4 = argc - 1; | |
6643 | struct in_addr addr = {.s_addr = 0L}; | |
6644 | int ret; | |
6645 | struct ospf_if_params *params; | |
6646 | struct ospf_interface *oi; | |
6647 | struct route_node *rn; | |
6648 | ||
6649 | params = IF_DEF_PARAMS(ifp); | |
6650 | ||
6651 | if (argv[idx_ipv4]->type == IPV4_TKN) { | |
6652 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
6653 | if (!ret) { | |
6654 | vty_out(vty, | |
6655 | "Please specify interface address by A.B.C.D\n"); | |
6656 | return CMD_WARNING_CONFIG_FAILED; | |
6657 | } | |
020709f9 | 6658 | |
d62a17ae | 6659 | params = ospf_lookup_if_params(ifp, addr); |
6660 | if (params == NULL) | |
6661 | return CMD_SUCCESS; | |
6662 | } | |
718e3744 | 6663 | |
d62a17ae | 6664 | UNSET_IF_PARAM(params, v_wait); |
6665 | params->v_wait = OSPF_ROUTER_DEAD_INTERVAL_DEFAULT; | |
6666 | ||
6667 | UNSET_IF_PARAM(params, fast_hello); | |
6668 | params->fast_hello = OSPF_FAST_HELLO_DEFAULT; | |
6669 | ||
6670 | if (params != IF_DEF_PARAMS(ifp)) { | |
6671 | ospf_free_if_params(ifp, addr); | |
6672 | ospf_if_update_params(ifp, addr); | |
718e3744 | 6673 | } |
6674 | ||
d62a17ae | 6675 | /* Update timer values in neighbor structure. */ |
6676 | if (argc == 1) { | |
b5a8894d | 6677 | struct ospf *ospf = NULL; |
718e3744 | 6678 | |
b5a8894d CS |
6679 | ospf = ospf_lookup_by_vrf_id(ifp->vrf_id); |
6680 | if (ospf) { | |
d62a17ae | 6681 | oi = ospf_if_lookup_by_local_addr(ospf, ifp, addr); |
6682 | if (oi) | |
6683 | ospf_nbr_timer_update(oi); | |
6684 | } | |
6685 | } else { | |
6686 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) | |
6687 | if ((oi = rn->info)) | |
6688 | ospf_nbr_timer_update(oi); | |
6689 | } | |
6690 | ||
6691 | return CMD_SUCCESS; | |
718e3744 | 6692 | } |
6693 | ||
0d829fa7 QY |
6694 | DEFUN_HIDDEN (no_ospf_dead_interval, |
6695 | no_ospf_dead_interval_cmd, | |
6696 | "no ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]", | |
6697 | NO_STR | |
6698 | "OSPF interface commands\n" | |
99a522c7 | 6699 | "Interval time after which a neighbor is declared down\n" |
0d829fa7 QY |
6700 | "Seconds\n" |
6701 | "Address of interface") | |
6702 | { | |
d62a17ae | 6703 | return no_ip_ospf_dead_interval(self, vty, argc, argv); |
0d829fa7 QY |
6704 | } |
6705 | ||
718e3744 | 6706 | DEFUN (ip_ospf_hello_interval, |
0d829fa7 | 6707 | ip_ospf_hello_interval_cmd, |
7a7be519 | 6708 | "ip ospf hello-interval (1-65535) [A.B.C.D]", |
718e3744 | 6709 | "IP Information\n" |
6710 | "OSPF interface commands\n" | |
6711 | "Time between HELLO packets\n" | |
6712 | "Seconds\n" | |
0d829fa7 | 6713 | "Address of interface\n") |
718e3744 | 6714 | { |
d62a17ae | 6715 | VTY_DECLVAR_CONTEXT(interface, ifp); |
6716 | int idx = 0; | |
6717 | struct in_addr addr; | |
6718 | struct ospf_if_params *params; | |
6719 | params = IF_DEF_PARAMS(ifp); | |
6720 | u_int32_t seconds = 0; | |
6721 | ||
6722 | argv_find(argv, argc, "(1-65535)", &idx); | |
6723 | seconds = strtol(argv[idx]->arg, NULL, 10); | |
6724 | ||
6725 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
6726 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
6727 | vty_out(vty, | |
6728 | "Please specify interface address by A.B.C.D\n"); | |
6729 | return CMD_WARNING_CONFIG_FAILED; | |
6730 | } | |
718e3744 | 6731 | |
d62a17ae | 6732 | params = ospf_get_if_params(ifp, addr); |
6733 | ospf_if_update_params(ifp, addr); | |
6734 | } | |
718e3744 | 6735 | |
d62a17ae | 6736 | SET_IF_PARAM(params, v_hello); |
6737 | params->v_hello = seconds; | |
718e3744 | 6738 | |
d62a17ae | 6739 | return CMD_SUCCESS; |
718e3744 | 6740 | } |
6741 | ||
7a7be519 | 6742 | DEFUN_HIDDEN (ospf_hello_interval, |
747e489c | 6743 | ospf_hello_interval_cmd, |
0d829fa7 | 6744 | "ospf hello-interval (1-65535) [A.B.C.D]", |
747e489c DW |
6745 | "OSPF interface commands\n" |
6746 | "Time between HELLO packets\n" | |
0d829fa7 QY |
6747 | "Seconds\n" |
6748 | "Address of interface\n") | |
7a7be519 | 6749 | { |
d62a17ae | 6750 | return ip_ospf_hello_interval(self, vty, argc, argv); |
7a7be519 | 6751 | } |
718e3744 | 6752 | |
6753 | DEFUN (no_ip_ospf_hello_interval, | |
0d829fa7 QY |
6754 | no_ip_ospf_hello_interval_cmd, |
6755 | "no ip ospf hello-interval [(1-65535) [A.B.C.D]]", | |
718e3744 | 6756 | NO_STR |
6757 | "IP Information\n" | |
6758 | "OSPF interface commands\n" | |
0d829fa7 | 6759 | "Time between HELLO packets\n" // ignored |
f9dfba8d | 6760 | "Seconds\n" |
0d829fa7 | 6761 | "Address of interface\n") |
718e3744 | 6762 | { |
d62a17ae | 6763 | VTY_DECLVAR_CONTEXT(interface, ifp); |
6764 | int idx = 0; | |
6765 | struct in_addr addr; | |
6766 | struct ospf_if_params *params; | |
df581cd3 | 6767 | |
d62a17ae | 6768 | params = IF_DEF_PARAMS(ifp); |
718e3744 | 6769 | |
d62a17ae | 6770 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { |
6771 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
6772 | vty_out(vty, | |
6773 | "Please specify interface address by A.B.C.D\n"); | |
6774 | return CMD_WARNING_CONFIG_FAILED; | |
6775 | } | |
718e3744 | 6776 | |
d62a17ae | 6777 | params = ospf_lookup_if_params(ifp, addr); |
6778 | if (params == NULL) | |
6779 | return CMD_SUCCESS; | |
6780 | } | |
718e3744 | 6781 | |
d62a17ae | 6782 | UNSET_IF_PARAM(params, v_hello); |
6783 | params->v_hello = OSPF_HELLO_INTERVAL_DEFAULT; | |
718e3744 | 6784 | |
d62a17ae | 6785 | if (params != IF_DEF_PARAMS(ifp)) { |
6786 | ospf_free_if_params(ifp, addr); | |
6787 | ospf_if_update_params(ifp, addr); | |
6788 | } | |
718e3744 | 6789 | |
d62a17ae | 6790 | return CMD_SUCCESS; |
718e3744 | 6791 | } |
6792 | ||
0d829fa7 QY |
6793 | DEFUN_HIDDEN (no_ospf_hello_interval, |
6794 | no_ospf_hello_interval_cmd, | |
6795 | "no ospf hello-interval [(1-65535) [A.B.C.D]]", | |
6796 | NO_STR | |
6797 | "OSPF interface commands\n" | |
6798 | "Time between HELLO packets\n" // ignored | |
6799 | "Seconds\n" | |
6800 | "Address of interface\n") | |
6801 | { | |
d62a17ae | 6802 | return no_ip_ospf_hello_interval(self, vty, argc, argv); |
0d829fa7 | 6803 | } |
718e3744 | 6804 | |
6805 | DEFUN (ip_ospf_network, | |
6806 | ip_ospf_network_cmd, | |
6147e2c6 | 6807 | "ip ospf network <broadcast|non-broadcast|point-to-multipoint|point-to-point>", |
718e3744 | 6808 | "IP Information\n" |
6809 | "OSPF interface commands\n" | |
6810 | "Network type\n" | |
6811 | "Specify OSPF broadcast multi-access network\n" | |
6812 | "Specify OSPF NBMA network\n" | |
6813 | "Specify OSPF point-to-multipoint network\n" | |
6814 | "Specify OSPF point-to-point network\n") | |
6815 | { | |
d62a17ae | 6816 | VTY_DECLVAR_CONTEXT(interface, ifp); |
6817 | int idx = 0; | |
6818 | int old_type = IF_DEF_PARAMS(ifp)->type; | |
6819 | struct route_node *rn; | |
718e3744 | 6820 | |
d62a17ae | 6821 | if (old_type == OSPF_IFTYPE_LOOPBACK) { |
6822 | vty_out(vty, | |
6823 | "This is a loopback interface. Can't set network type.\n"); | |
6824 | return CMD_WARNING_CONFIG_FAILED; | |
6825 | } | |
718e3744 | 6826 | |
d62a17ae | 6827 | if (argv_find(argv, argc, "broadcast", &idx)) |
6828 | IF_DEF_PARAMS(ifp)->type = OSPF_IFTYPE_BROADCAST; | |
6829 | else if (argv_find(argv, argc, "non-broadcast", &idx)) | |
6830 | IF_DEF_PARAMS(ifp)->type = OSPF_IFTYPE_NBMA; | |
6831 | else if (argv_find(argv, argc, "point-to-multipoint", &idx)) | |
6832 | IF_DEF_PARAMS(ifp)->type = OSPF_IFTYPE_POINTOMULTIPOINT; | |
6833 | else if (argv_find(argv, argc, "point-to-point", &idx)) | |
6834 | IF_DEF_PARAMS(ifp)->type = OSPF_IFTYPE_POINTOPOINT; | |
718e3744 | 6835 | |
d62a17ae | 6836 | if (IF_DEF_PARAMS(ifp)->type == old_type) |
6837 | return CMD_SUCCESS; | |
6838 | ||
6839 | SET_IF_PARAM(IF_DEF_PARAMS(ifp), type); | |
6840 | ||
6841 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { | |
6842 | struct ospf_interface *oi = rn->info; | |
6843 | ||
6844 | if (!oi) | |
6845 | continue; | |
6846 | ||
6847 | oi->type = IF_DEF_PARAMS(ifp)->type; | |
6848 | ||
6849 | if (oi->state > ISM_Down) { | |
6850 | OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceDown); | |
6851 | OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceUp); | |
6852 | } | |
7a7be519 | 6853 | } |
7a7be519 | 6854 | |
d62a17ae | 6855 | return CMD_SUCCESS; |
7a7be519 | 6856 | } |
6857 | ||
6858 | DEFUN_HIDDEN (ospf_network, | |
6859 | ospf_network_cmd, | |
e83a9414 | 6860 | "ospf network <broadcast|non-broadcast|point-to-multipoint|point-to-point>", |
7a7be519 | 6861 | "OSPF interface commands\n" |
6862 | "Network type\n" | |
6863 | "Specify OSPF broadcast multi-access network\n" | |
6864 | "Specify OSPF NBMA network\n" | |
6865 | "Specify OSPF point-to-multipoint network\n" | |
6866 | "Specify OSPF point-to-point network\n") | |
6867 | { | |
d62a17ae | 6868 | return ip_ospf_network(self, vty, argc, argv); |
7a7be519 | 6869 | } |
6870 | ||
6871 | DEFUN (no_ip_ospf_network, | |
6872 | no_ip_ospf_network_cmd, | |
6873 | "no ip ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]", | |
6874 | NO_STR | |
6875 | "IP Information\n" | |
6876 | "OSPF interface commands\n" | |
6877 | "Network type\n" | |
6878 | "Specify OSPF broadcast multi-access network\n" | |
6879 | "Specify OSPF NBMA network\n" | |
6880 | "Specify OSPF point-to-multipoint network\n" | |
6881 | "Specify OSPF point-to-point network\n") | |
22b27e95 | 6882 | { |
d62a17ae | 6883 | VTY_DECLVAR_CONTEXT(interface, ifp); |
6884 | int old_type = IF_DEF_PARAMS(ifp)->type; | |
6885 | struct route_node *rn; | |
7a7be519 | 6886 | |
d62a17ae | 6887 | IF_DEF_PARAMS(ifp)->type = ospf_default_iftype(ifp); |
7a7be519 | 6888 | |
d62a17ae | 6889 | if (IF_DEF_PARAMS(ifp)->type == old_type) |
6890 | return CMD_SUCCESS; | |
7a7be519 | 6891 | |
d62a17ae | 6892 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { |
6893 | struct ospf_interface *oi = rn->info; | |
7a7be519 | 6894 | |
d62a17ae | 6895 | if (!oi) |
6896 | continue; | |
7a7be519 | 6897 | |
d62a17ae | 6898 | oi->type = IF_DEF_PARAMS(ifp)->type; |
7a7be519 | 6899 | |
d62a17ae | 6900 | if (oi->state > ISM_Down) { |
6901 | OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceDown); | |
6902 | OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceUp); | |
6903 | } | |
7a7be519 | 6904 | } |
7a7be519 | 6905 | |
d62a17ae | 6906 | return CMD_SUCCESS; |
7a7be519 | 6907 | } |
6908 | ||
0d829fa7 QY |
6909 | DEFUN_HIDDEN (no_ospf_network, |
6910 | no_ospf_network_cmd, | |
6911 | "no ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]", | |
6912 | NO_STR | |
6913 | "OSPF interface commands\n" | |
6914 | "Network type\n" | |
6915 | "Specify OSPF broadcast multi-access network\n" | |
6916 | "Specify OSPF NBMA network\n" | |
6917 | "Specify OSPF point-to-multipoint network\n" | |
6918 | "Specify OSPF point-to-point network\n") | |
6919 | { | |
d62a17ae | 6920 | return no_ip_ospf_network(self, vty, argc, argv); |
0d829fa7 QY |
6921 | } |
6922 | ||
7a7be519 | 6923 | DEFUN (ip_ospf_priority, |
537eae3f | 6924 | ip_ospf_priority_cmd, |
7a7be519 | 6925 | "ip ospf priority (0-255) [A.B.C.D]", |
6926 | "IP Information\n" | |
6927 | "OSPF interface commands\n" | |
6928 | "Router priority\n" | |
6929 | "Priority\n" | |
6930 | "Address of interface") | |
6931 | { | |
d62a17ae | 6932 | VTY_DECLVAR_CONTEXT(interface, ifp); |
6933 | int idx = 0; | |
6934 | long priority; | |
6935 | struct route_node *rn; | |
6936 | struct in_addr addr; | |
6937 | struct ospf_if_params *params; | |
6938 | params = IF_DEF_PARAMS(ifp); | |
6939 | ||
6940 | argv_find(argv, argc, "(0-255)", &idx); | |
6941 | priority = strtol(argv[idx]->arg, NULL, 10); | |
6942 | ||
6943 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
6944 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
6945 | vty_out(vty, | |
6946 | "Please specify interface address by A.B.C.D\n"); | |
6947 | return CMD_WARNING_CONFIG_FAILED; | |
6948 | } | |
7a7be519 | 6949 | |
d62a17ae | 6950 | params = ospf_get_if_params(ifp, addr); |
6951 | ospf_if_update_params(ifp, addr); | |
7a7be519 | 6952 | } |
6953 | ||
d62a17ae | 6954 | SET_IF_PARAM(params, priority); |
6955 | params->priority = priority; | |
7a7be519 | 6956 | |
d62a17ae | 6957 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { |
6958 | struct ospf_interface *oi = rn->info; | |
7a7be519 | 6959 | |
d62a17ae | 6960 | if (!oi) |
6961 | continue; | |
7a7be519 | 6962 | |
d62a17ae | 6963 | if (PRIORITY(oi) != OSPF_IF_PARAM(oi, priority)) { |
6964 | PRIORITY(oi) = OSPF_IF_PARAM(oi, priority); | |
6965 | OSPF_ISM_EVENT_SCHEDULE(oi, ISM_NeighborChange); | |
6966 | } | |
718e3744 | 6967 | } |
718e3744 | 6968 | |
d62a17ae | 6969 | return CMD_SUCCESS; |
718e3744 | 6970 | } |
6971 | ||
7a7be519 | 6972 | DEFUN_HIDDEN (ospf_priority, |
6973 | ospf_priority_cmd, | |
0d829fa7 | 6974 | "ospf priority (0-255) [A.B.C.D]", |
7a7be519 | 6975 | "OSPF interface commands\n" |
6976 | "Router priority\n" | |
3a2d747c QY |
6977 | "Priority\n" |
6978 | "Address of interface") | |
718e3744 | 6979 | { |
d62a17ae | 6980 | return ip_ospf_priority(self, vty, argc, argv); |
718e3744 | 6981 | } |
6982 | ||
718e3744 | 6983 | DEFUN (no_ip_ospf_priority, |
537eae3f | 6984 | no_ip_ospf_priority_cmd, |
7a7be519 | 6985 | "no ip ospf priority [(0-255) [A.B.C.D]]", |
718e3744 | 6986 | NO_STR |
6987 | "IP Information\n" | |
6988 | "OSPF interface commands\n" | |
0d829fa7 | 6989 | "Router priority\n" // ignored |
813d4307 | 6990 | "Priority\n" |
718e3744 | 6991 | "Address of interface") |
6992 | { | |
d62a17ae | 6993 | VTY_DECLVAR_CONTEXT(interface, ifp); |
6994 | int idx = 0; | |
6995 | struct route_node *rn; | |
6996 | struct in_addr addr; | |
6997 | struct ospf_if_params *params; | |
6998 | ||
6999 | params = IF_DEF_PARAMS(ifp); | |
7000 | ||
7001 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
7002 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
7003 | vty_out(vty, | |
7004 | "Please specify interface address by A.B.C.D\n"); | |
7005 | return CMD_WARNING_CONFIG_FAILED; | |
7006 | } | |
7007 | ||
7008 | params = ospf_lookup_if_params(ifp, addr); | |
7009 | if (params == NULL) | |
7010 | return CMD_SUCCESS; | |
718e3744 | 7011 | } |
7012 | ||
d62a17ae | 7013 | UNSET_IF_PARAM(params, priority); |
7014 | params->priority = OSPF_ROUTER_PRIORITY_DEFAULT; | |
7015 | ||
7016 | if (params != IF_DEF_PARAMS(ifp)) { | |
7017 | ospf_free_if_params(ifp, addr); | |
7018 | ospf_if_update_params(ifp, addr); | |
718e3744 | 7019 | } |
d62a17ae | 7020 | |
7021 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { | |
7022 | struct ospf_interface *oi = rn->info; | |
7023 | ||
7024 | if (!oi) | |
7025 | continue; | |
7026 | ||
7027 | if (PRIORITY(oi) != OSPF_IF_PARAM(oi, priority)) { | |
7028 | PRIORITY(oi) = OSPF_IF_PARAM(oi, priority); | |
7029 | OSPF_ISM_EVENT_SCHEDULE(oi, ISM_NeighborChange); | |
7030 | } | |
7031 | } | |
7032 | ||
7033 | return CMD_SUCCESS; | |
718e3744 | 7034 | } |
7035 | ||
0d829fa7 | 7036 | DEFUN_HIDDEN (no_ospf_priority, |
537eae3f | 7037 | no_ospf_priority_cmd, |
0d829fa7 QY |
7038 | "no ospf priority [(0-255) [A.B.C.D]]", |
7039 | NO_STR | |
7040 | "OSPF interface commands\n" | |
7041 | "Router priority\n" | |
7042 | "Priority\n" | |
7043 | "Address of interface") | |
7044 | { | |
d62a17ae | 7045 | return no_ip_ospf_priority(self, vty, argc, argv); |
0d829fa7 | 7046 | } |
a1afa410 | 7047 | |
718e3744 | 7048 | DEFUN (ip_ospf_retransmit_interval, |
7049 | ip_ospf_retransmit_interval_addr_cmd, | |
7a7be519 | 7050 | "ip ospf retransmit-interval (3-65535) [A.B.C.D]", |
718e3744 | 7051 | "IP Information\n" |
7052 | "OSPF interface commands\n" | |
7053 | "Time between retransmitting lost link state advertisements\n" | |
7054 | "Seconds\n" | |
7055 | "Address of interface") | |
7056 | { | |
d62a17ae | 7057 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7058 | int idx = 0; | |
7059 | u_int32_t seconds; | |
7060 | struct in_addr addr; | |
7061 | struct ospf_if_params *params; | |
7062 | params = IF_DEF_PARAMS(ifp); | |
7063 | ||
7064 | argv_find(argv, argc, "(3-65535)", &idx); | |
7065 | seconds = strtol(argv[idx]->arg, NULL, 10); | |
7066 | ||
7067 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
7068 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
7069 | vty_out(vty, | |
7070 | "Please specify interface address by A.B.C.D\n"); | |
7071 | return CMD_WARNING_CONFIG_FAILED; | |
7072 | } | |
718e3744 | 7073 | |
d62a17ae | 7074 | params = ospf_get_if_params(ifp, addr); |
7075 | ospf_if_update_params(ifp, addr); | |
718e3744 | 7076 | } |
7077 | ||
d62a17ae | 7078 | SET_IF_PARAM(params, retransmit_interval); |
7079 | params->retransmit_interval = seconds; | |
718e3744 | 7080 | |
d62a17ae | 7081 | return CMD_SUCCESS; |
718e3744 | 7082 | } |
7083 | ||
7a7be519 | 7084 | DEFUN_HIDDEN (ospf_retransmit_interval, |
747e489c | 7085 | ospf_retransmit_interval_cmd, |
0d829fa7 | 7086 | "ospf retransmit-interval (3-65535) [A.B.C.D]", |
747e489c DW |
7087 | "OSPF interface commands\n" |
7088 | "Time between retransmitting lost link state advertisements\n" | |
3a2d747c QY |
7089 | "Seconds\n" |
7090 | "Address of interface") | |
7a7be519 | 7091 | { |
d62a17ae | 7092 | return ip_ospf_retransmit_interval(self, vty, argc, argv); |
7a7be519 | 7093 | } |
718e3744 | 7094 | |
7095 | DEFUN (no_ip_ospf_retransmit_interval, | |
7096 | no_ip_ospf_retransmit_interval_addr_cmd, | |
0d829fa7 | 7097 | "no ip ospf retransmit-interval [(3-65535)] [A.B.C.D]", |
718e3744 | 7098 | NO_STR |
7099 | "IP Information\n" | |
7100 | "OSPF interface commands\n" | |
3a2d747c QY |
7101 | "Time between retransmitting lost link state advertisements\n" |
7102 | "Seconds\n" | |
0d829fa7 | 7103 | "Address of interface\n") |
718e3744 | 7104 | { |
d62a17ae | 7105 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7106 | int idx = 0; | |
7107 | struct in_addr addr; | |
7108 | struct ospf_if_params *params; | |
47b91972 | 7109 | |
d62a17ae | 7110 | params = IF_DEF_PARAMS(ifp); |
718e3744 | 7111 | |
d62a17ae | 7112 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { |
7113 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
7114 | vty_out(vty, | |
7115 | "Please specify interface address by A.B.C.D\n"); | |
7116 | return CMD_WARNING_CONFIG_FAILED; | |
7117 | } | |
718e3744 | 7118 | |
d62a17ae | 7119 | params = ospf_lookup_if_params(ifp, addr); |
7120 | if (params == NULL) | |
7121 | return CMD_SUCCESS; | |
7122 | } | |
718e3744 | 7123 | |
d62a17ae | 7124 | UNSET_IF_PARAM(params, retransmit_interval); |
7125 | params->retransmit_interval = OSPF_RETRANSMIT_INTERVAL_DEFAULT; | |
718e3744 | 7126 | |
d62a17ae | 7127 | if (params != IF_DEF_PARAMS(ifp)) { |
7128 | ospf_free_if_params(ifp, addr); | |
7129 | ospf_if_update_params(ifp, addr); | |
7130 | } | |
718e3744 | 7131 | |
d62a17ae | 7132 | return CMD_SUCCESS; |
718e3744 | 7133 | } |
7134 | ||
0d829fa7 QY |
7135 | DEFUN_HIDDEN (no_ospf_retransmit_interval, |
7136 | no_ospf_retransmit_interval_cmd, | |
7137 | "no ospf retransmit-interval [(3-65535)] [A.B.C.D]", | |
7138 | NO_STR | |
7139 | "OSPF interface commands\n" | |
3a2d747c QY |
7140 | "Time between retransmitting lost link state advertisements\n" |
7141 | "Seconds\n" | |
7142 | "Address of interface\n") | |
0d829fa7 | 7143 | { |
d62a17ae | 7144 | return no_ip_ospf_retransmit_interval(self, vty, argc, argv); |
0d829fa7 | 7145 | } |
813d4307 | 7146 | |
718e3744 | 7147 | DEFUN (ip_ospf_transmit_delay, |
7148 | ip_ospf_transmit_delay_addr_cmd, | |
7a7be519 | 7149 | "ip ospf transmit-delay (1-65535) [A.B.C.D]", |
718e3744 | 7150 | "IP Information\n" |
7151 | "OSPF interface commands\n" | |
7152 | "Link state transmit delay\n" | |
7153 | "Seconds\n" | |
7154 | "Address of interface") | |
7155 | { | |
d62a17ae | 7156 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7157 | int idx = 0; | |
7158 | u_int32_t seconds; | |
7159 | struct in_addr addr; | |
7160 | struct ospf_if_params *params; | |
7161 | ||
7162 | params = IF_DEF_PARAMS(ifp); | |
7163 | argv_find(argv, argc, "(1-65535)", &idx); | |
7164 | seconds = strtol(argv[idx]->arg, NULL, 10); | |
7165 | ||
7166 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
7167 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
7168 | vty_out(vty, | |
7169 | "Please specify interface address by A.B.C.D\n"); | |
7170 | return CMD_WARNING_CONFIG_FAILED; | |
7171 | } | |
718e3744 | 7172 | |
d62a17ae | 7173 | params = ospf_get_if_params(ifp, addr); |
7174 | ospf_if_update_params(ifp, addr); | |
718e3744 | 7175 | } |
7176 | ||
d62a17ae | 7177 | SET_IF_PARAM(params, transmit_delay); |
7178 | params->transmit_delay = seconds; | |
718e3744 | 7179 | |
d62a17ae | 7180 | return CMD_SUCCESS; |
718e3744 | 7181 | } |
7182 | ||
7a7be519 | 7183 | DEFUN_HIDDEN (ospf_transmit_delay, |
747e489c | 7184 | ospf_transmit_delay_cmd, |
0d829fa7 | 7185 | "ospf transmit-delay (1-65535) [A.B.C.D]", |
747e489c DW |
7186 | "OSPF interface commands\n" |
7187 | "Link state transmit delay\n" | |
3a2d747c QY |
7188 | "Seconds\n" |
7189 | "Address of interface") | |
7a7be519 | 7190 | { |
d62a17ae | 7191 | return ip_ospf_transmit_delay(self, vty, argc, argv); |
7a7be519 | 7192 | } |
718e3744 | 7193 | |
7194 | DEFUN (no_ip_ospf_transmit_delay, | |
7195 | no_ip_ospf_transmit_delay_addr_cmd, | |
0d829fa7 | 7196 | "no ip ospf transmit-delay [(1-65535)] [A.B.C.D]", |
718e3744 | 7197 | NO_STR |
7198 | "IP Information\n" | |
7199 | "OSPF interface commands\n" | |
7200 | "Link state transmit delay\n" | |
7201 | "Address of interface") | |
7202 | { | |
d62a17ae | 7203 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7204 | int idx = 0; | |
7205 | struct in_addr addr; | |
7206 | struct ospf_if_params *params; | |
718e3744 | 7207 | |
d62a17ae | 7208 | params = IF_DEF_PARAMS(ifp); |
718e3744 | 7209 | |
d62a17ae | 7210 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { |
7211 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
7212 | vty_out(vty, | |
7213 | "Please specify interface address by A.B.C.D\n"); | |
7214 | return CMD_WARNING_CONFIG_FAILED; | |
7215 | } | |
718e3744 | 7216 | |
d62a17ae | 7217 | params = ospf_lookup_if_params(ifp, addr); |
7218 | if (params == NULL) | |
7219 | return CMD_SUCCESS; | |
7220 | } | |
718e3744 | 7221 | |
d62a17ae | 7222 | UNSET_IF_PARAM(params, transmit_delay); |
7223 | params->transmit_delay = OSPF_TRANSMIT_DELAY_DEFAULT; | |
718e3744 | 7224 | |
d62a17ae | 7225 | if (params != IF_DEF_PARAMS(ifp)) { |
7226 | ospf_free_if_params(ifp, addr); | |
7227 | ospf_if_update_params(ifp, addr); | |
7228 | } | |
7229 | ||
7230 | return CMD_SUCCESS; | |
718e3744 | 7231 | } |
7232 | ||
813d4307 | 7233 | |
0d829fa7 QY |
7234 | DEFUN_HIDDEN (no_ospf_transmit_delay, |
7235 | no_ospf_transmit_delay_cmd, | |
32573073 | 7236 | "no ospf transmit-delay [(1-65535) [A.B.C.D]]", |
0d829fa7 QY |
7237 | NO_STR |
7238 | "OSPF interface commands\n" | |
32573073 QY |
7239 | "Link state transmit delay\n" |
7240 | "Seconds\n" | |
7241 | "Address of interface") | |
813d4307 | 7242 | { |
d62a17ae | 7243 | return no_ip_ospf_transmit_delay(self, vty, argc, argv); |
813d4307 DW |
7244 | } |
7245 | ||
e723861d DS |
7246 | DEFUN (ip_ospf_area, |
7247 | ip_ospf_area_cmd, | |
52c62ab8 | 7248 | "ip ospf [(1-65535)] area <A.B.C.D|(0-4294967295)> [A.B.C.D]", |
e723861d DS |
7249 | "IP Information\n" |
7250 | "OSPF interface commands\n" | |
7a7be519 | 7251 | "Instance ID\n" |
e723861d DS |
7252 | "Enable OSPF on this interface\n" |
7253 | "OSPF area ID in IP address format\n" | |
52c62ab8 JAG |
7254 | "OSPF area ID as a decimal value\n" |
7255 | "Address of interface\n") | |
e723861d | 7256 | { |
d62a17ae | 7257 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7258 | int idx = 0; | |
7259 | int format, ret; | |
7260 | struct in_addr area_id; | |
7261 | struct in_addr addr; | |
7262 | struct ospf_if_params *params; | |
7263 | struct route_node *rn; | |
b5a8894d | 7264 | struct ospf *ospf = NULL; |
d62a17ae | 7265 | u_short instance = 0; |
7266 | char *areaid; | |
7267 | ||
7268 | if (argv_find(argv, argc, "(1-65535)", &idx)) | |
7269 | instance = strtol(argv[idx]->arg, NULL, 10); | |
7270 | ||
7271 | argv_find(argv, argc, "area", &idx); | |
7272 | areaid = argv[idx + 1]->arg; | |
7273 | ||
b5a8894d CS |
7274 | if (ifp->vrf_id && !instance) |
7275 | ospf = ospf_lookup_by_vrf_id(ifp->vrf_id); | |
7276 | else | |
7277 | ospf = ospf_lookup_instance(instance); | |
7278 | ||
d62a17ae | 7279 | if (ospf == NULL) { |
7280 | params = IF_DEF_PARAMS(ifp); | |
7281 | if (OSPF_IF_PARAM_CONFIGURED(params, if_area)) { | |
7282 | UNSET_IF_PARAM(params, if_area); | |
b5a8894d CS |
7283 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); |
7284 | ospf_interface_area_unset(ospf, ifp); | |
d62a17ae | 7285 | ospf->if_ospf_cli_count--; |
7286 | } | |
ac28e4ec | 7287 | return CMD_NOT_MY_INSTANCE; |
d62a17ae | 7288 | } |
e723861d | 7289 | |
d62a17ae | 7290 | ret = str2area_id(areaid, &area_id, &format); |
7291 | if (ret < 0) { | |
7292 | vty_out(vty, "Please specify area by A.B.C.D|<0-4294967295>\n"); | |
7293 | return CMD_WARNING_CONFIG_FAILED; | |
7294 | } | |
7295 | if (memcmp(ifp->name, "VLINK", 5) == 0) { | |
7296 | vty_out(vty, "Cannot enable OSPF on a virtual link.\n"); | |
7297 | return CMD_WARNING_CONFIG_FAILED; | |
7298 | } | |
7299 | ||
7300 | params = IF_DEF_PARAMS(ifp); | |
7301 | if (OSPF_IF_PARAM_CONFIGURED(params, if_area) | |
7302 | && !IPV4_ADDR_SAME(¶ms->if_area, &area_id)) { | |
7303 | vty_out(vty, | |
7304 | "Must remove previous area config before changing ospf area \n"); | |
7305 | return CMD_WARNING_CONFIG_FAILED; | |
7306 | } | |
7307 | ||
7308 | // Check if we have an address arg and proccess it | |
7309 | if (argc == idx + 3) { | |
cc9b06ad DS |
7310 | if (!inet_aton(argv[idx + 2]->arg, &addr)) { |
7311 | vty_out(vty, "Please specify Intf Address by A.B.C.D\n"); | |
7312 | return CMD_WARNING_CONFIG_FAILED; | |
7313 | } | |
d62a17ae | 7314 | // update/create address-level params |
7315 | params = ospf_get_if_params((ifp), (addr)); | |
7316 | if (OSPF_IF_PARAM_CONFIGURED(params, if_area)) { | |
7317 | vty_out(vty, | |
7318 | "Must remove previous area/address config before changing ospf area"); | |
7319 | return CMD_WARNING_CONFIG_FAILED; | |
7320 | } | |
7321 | ospf_if_update_params((ifp), (addr)); | |
7322 | } | |
7323 | ||
7324 | for (rn = route_top(ospf->networks); rn; rn = route_next(rn)) { | |
7325 | if (rn->info != NULL) { | |
7326 | vty_out(vty, | |
7327 | "Please remove all network commands first.\n"); | |
7328 | return CMD_WARNING_CONFIG_FAILED; | |
7329 | } | |
7330 | } | |
7331 | ||
7332 | /* enable ospf on this interface with area_id */ | |
7333 | SET_IF_PARAM(params, if_area); | |
7334 | params->if_area = area_id; | |
5ed0add5 | 7335 | params->if_area_id_fmt = format; |
b5a8894d | 7336 | ospf_interface_area_set(ospf, ifp); |
d62a17ae | 7337 | ospf->if_ospf_cli_count++; |
7338 | ||
7339 | return CMD_SUCCESS; | |
e723861d DS |
7340 | } |
7341 | ||
7342 | DEFUN (no_ip_ospf_area, | |
7343 | no_ip_ospf_area_cmd, | |
52c62ab8 | 7344 | "no ip ospf [(1-65535)] area [<A.B.C.D|(0-4294967295)> [A.B.C.D]]", |
e723861d DS |
7345 | NO_STR |
7346 | "IP Information\n" | |
7347 | "OSPF interface commands\n" | |
3a2d747c | 7348 | "Instance ID\n" |
7a7be519 | 7349 | "Disable OSPF on this interface\n" |
7350 | "OSPF area ID in IP address format\n" | |
52c62ab8 JAG |
7351 | "OSPF area ID as a decimal value\n" |
7352 | "Address of interface\n") | |
e723861d | 7353 | { |
d62a17ae | 7354 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7355 | int idx = 0; | |
7356 | struct ospf *ospf; | |
7357 | struct ospf_if_params *params; | |
7358 | u_short instance = 0; | |
7359 | struct in_addr addr; | |
7360 | ||
7361 | if (argv_find(argv, argc, "(1-65535)", &idx)) | |
7362 | instance = strtol(argv[idx]->arg, NULL, 10); | |
7363 | ||
b5a8894d CS |
7364 | if (ifp->vrf_id && !instance) |
7365 | ospf = ospf_lookup_by_vrf_id(ifp->vrf_id); | |
7366 | else | |
7367 | ospf = ospf_lookup_instance(instance); | |
7368 | ||
ac28e4ec CS |
7369 | if (ospf == NULL) |
7370 | return CMD_NOT_MY_INSTANCE; | |
d62a17ae | 7371 | |
7372 | argv_find(argv, argc, "area", &idx); | |
7373 | ||
7374 | // Check if we have an address arg and proccess it | |
7375 | if (argc == idx + 3) { | |
cc9b06ad DS |
7376 | if (!inet_aton(argv[idx + 2]->arg, &addr)) { |
7377 | vty_out(vty, "Please specify Intf Address by A.B.C.D\n"); | |
7378 | return CMD_WARNING_CONFIG_FAILED; | |
7379 | } | |
d62a17ae | 7380 | params = ospf_lookup_if_params(ifp, addr); |
7381 | if ((params) == NULL) | |
7382 | return CMD_SUCCESS; | |
7383 | } else | |
7384 | params = IF_DEF_PARAMS(ifp); | |
7385 | ||
7386 | if (!OSPF_IF_PARAM_CONFIGURED(params, if_area)) { | |
7387 | vty_out(vty, | |
7388 | "Can't find specified interface area configuration.\n"); | |
7389 | return CMD_WARNING_CONFIG_FAILED; | |
7390 | } | |
813d4307 | 7391 | |
d62a17ae | 7392 | UNSET_IF_PARAM(params, if_area); |
7393 | if (params != IF_DEF_PARAMS((ifp))) { | |
7394 | ospf_free_if_params((ifp), (addr)); | |
7395 | ospf_if_update_params((ifp), (addr)); | |
7396 | } | |
7397 | ||
b5a8894d | 7398 | ospf_interface_area_unset(ospf, ifp); |
d62a17ae | 7399 | ospf->if_ospf_cli_count--; |
7400 | return CMD_SUCCESS; | |
813d4307 DW |
7401 | } |
7402 | ||
6f2a6703 CF |
7403 | DEFUN (ospf_redistribute_source, |
7404 | ospf_redistribute_source_cmd, | |
40d1cbfb | 7405 | "redistribute " FRR_REDIST_STR_OSPFD " [<metric (0-16777214)|metric-type (1-2)|route-map WORD>]", |
d1c65c21 | 7406 | REDIST_STR |
ab0181ee | 7407 | FRR_REDIST_HELP_STR_OSPFD |
718e3744 | 7408 | "Metric for redistributed routes\n" |
7409 | "OSPF default metric\n" | |
7410 | "OSPF exterior metric type for redistributed routes\n" | |
7111c1a0 | 7411 | "Set OSPF External Type 1/2 metrics\n" |
718e3744 | 7412 | "Route map reference\n" |
7413 | "Pointer to route-map entries\n") | |
7414 | { | |
a3d826f0 | 7415 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 7416 | int idx_protocol = 1; |
7417 | int source; | |
7418 | int type = -1; | |
7419 | int metric = -1; | |
7420 | struct ospf_redist *red; | |
7421 | int idx = 0; | |
6f2a6703 | 7422 | |
d62a17ae | 7423 | if (!ospf) |
7424 | return CMD_SUCCESS; | |
7425 | ||
7426 | /* Get distribute source. */ | |
7427 | source = proto_redistnum(AFI_IP, argv[idx_protocol]->text); | |
7428 | if (source < 0) | |
7429 | return CMD_WARNING_CONFIG_FAILED; | |
7430 | ||
7431 | red = ospf_redist_add(ospf, source, 0); | |
7432 | ||
7433 | /* Get metric value. */ | |
7434 | if (argv_find(argv, argc, "(0-16777214)", &idx)) { | |
7435 | if (!str2metric(argv[idx]->arg, &metric)) | |
7436 | return CMD_WARNING_CONFIG_FAILED; | |
7437 | } | |
7438 | /* Get metric type. */ | |
7439 | else if (argv_find(argv, argc, "(1-2)", &idx)) { | |
7440 | if (!str2metric_type(argv[idx]->arg, &type)) | |
7441 | return CMD_WARNING_CONFIG_FAILED; | |
7442 | } | |
7443 | /* Get route-map */ | |
7444 | else if (argv_find(argv, argc, "WORD", &idx)) { | |
7445 | ospf_routemap_set(red, argv[idx]->arg); | |
7446 | } else | |
7447 | ospf_routemap_unset(red); | |
7c8ff89e | 7448 | |
d62a17ae | 7449 | return ospf_redistribute_set(ospf, source, 0, type, metric); |
718e3744 | 7450 | } |
7451 | ||
718e3744 | 7452 | DEFUN (no_ospf_redistribute_source, |
7453 | no_ospf_redistribute_source_cmd, | |
40d1cbfb | 7454 | "no redistribute " FRR_REDIST_STR_OSPFD " [<metric (0-16777214)|metric-type (1-2)|route-map WORD>]", |
718e3744 | 7455 | NO_STR |
d1c65c21 | 7456 | REDIST_STR |
ab0181ee | 7457 | FRR_REDIST_HELP_STR_OSPFD |
813d4307 DW |
7458 | "Metric for redistributed routes\n" |
7459 | "OSPF default metric\n" | |
7460 | "OSPF exterior metric type for redistributed routes\n" | |
7111c1a0 | 7461 | "Set OSPF External Type 1/2 metrics\n" |
813d4307 DW |
7462 | "Route map reference\n" |
7463 | "Pointer to route-map entries\n") | |
718e3744 | 7464 | { |
a3d826f0 | 7465 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 7466 | int idx_protocol = 2; |
7467 | int source; | |
7468 | struct ospf_redist *red; | |
718e3744 | 7469 | |
d62a17ae | 7470 | source = proto_redistnum(AFI_IP, argv[idx_protocol]->text); |
7471 | if (source < 0) | |
7472 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 7473 | |
d62a17ae | 7474 | red = ospf_redist_lookup(ospf, source, 0); |
7475 | if (!red) | |
7476 | return CMD_SUCCESS; | |
7c8ff89e | 7477 | |
d62a17ae | 7478 | ospf_routemap_unset(red); |
7479 | return ospf_redistribute_unset(ospf, source, 0); | |
7c8ff89e DS |
7480 | } |
7481 | ||
7482 | DEFUN (ospf_redistribute_instance_source, | |
7483 | ospf_redistribute_instance_source_cmd, | |
1a5ce38b | 7484 | "redistribute <ospf|table> (1-65535) [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]", |
7c8ff89e DS |
7485 | REDIST_STR |
7486 | "Open Shortest Path First\n" | |
2d627ff5 DS |
7487 | "Non-main Kernel Routing Table\n" |
7488 | "Instance ID/Table ID\n" | |
7c8ff89e DS |
7489 | "Metric for redistributed routes\n" |
7490 | "OSPF default metric\n" | |
7491 | "OSPF exterior metric type for redistributed routes\n" | |
7111c1a0 | 7492 | "Set OSPF External Type 1/2 metrics\n" |
7c8ff89e DS |
7493 | "Route map reference\n" |
7494 | "Pointer to route-map entries\n") | |
7495 | { | |
a3d826f0 | 7496 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 7497 | int idx_ospf_table = 1; |
7498 | int idx_number = 2; | |
7499 | int idx = 3; | |
7500 | int source; | |
7501 | int type = -1; | |
7502 | int metric = -1; | |
7503 | u_short instance; | |
7504 | struct ospf_redist *red; | |
7c8ff89e | 7505 | |
d62a17ae | 7506 | if (!ospf) |
7507 | return CMD_SUCCESS; | |
d8f70b86 | 7508 | |
d62a17ae | 7509 | source = proto_redistnum(AFI_IP, argv[idx_ospf_table]->text); |
2d627ff5 | 7510 | |
d62a17ae | 7511 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
7c8ff89e | 7512 | |
d62a17ae | 7513 | if (!ospf) |
7514 | return CMD_SUCCESS; | |
7c8ff89e | 7515 | |
d62a17ae | 7516 | if ((source == ZEBRA_ROUTE_OSPF) && !ospf->instance) { |
7517 | vty_out(vty, | |
7518 | "Instance redistribution in non-instanced OSPF not allowed\n"); | |
7519 | return CMD_WARNING_CONFIG_FAILED; | |
7520 | } | |
7c8ff89e | 7521 | |
d62a17ae | 7522 | if ((source == ZEBRA_ROUTE_OSPF) && (ospf->instance == instance)) { |
7523 | vty_out(vty, "Same instance OSPF redistribution not allowed\n"); | |
7524 | return CMD_WARNING_CONFIG_FAILED; | |
7525 | } | |
7c8ff89e | 7526 | |
d62a17ae | 7527 | /* Get metric value. */ |
7528 | if (argv_find(argv, argc, "metric", &idx)) | |
7529 | if (!str2metric(argv[idx + 1]->arg, &metric)) | |
7530 | return CMD_WARNING_CONFIG_FAILED; | |
7c8ff89e | 7531 | |
d62a17ae | 7532 | idx = 3; |
7533 | /* Get metric type. */ | |
7534 | if (argv_find(argv, argc, "metric-type", &idx)) | |
7535 | if (!str2metric_type(argv[idx + 1]->arg, &type)) | |
7536 | return CMD_WARNING_CONFIG_FAILED; | |
7c8ff89e | 7537 | |
d62a17ae | 7538 | red = ospf_redist_add(ospf, source, instance); |
7a7be519 | 7539 | |
d62a17ae | 7540 | idx = 3; |
7541 | if (argv_find(argv, argc, "route-map", &idx)) | |
7542 | ospf_routemap_set(red, argv[idx + 1]->arg); | |
7543 | else | |
7544 | ospf_routemap_unset(red); | |
7c8ff89e | 7545 | |
d62a17ae | 7546 | return ospf_redistribute_set(ospf, source, instance, type, metric); |
7c8ff89e DS |
7547 | } |
7548 | ||
7549 | DEFUN (no_ospf_redistribute_instance_source, | |
7550 | no_ospf_redistribute_instance_source_cmd, | |
1a5ce38b | 7551 | "no redistribute <ospf|table> (1-65535) [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]", |
7c8ff89e DS |
7552 | NO_STR |
7553 | REDIST_STR | |
7554 | "Open Shortest Path First\n" | |
2d627ff5 DS |
7555 | "Non-main Kernel Routing Table\n" |
7556 | "Instance ID/Table Id\n" | |
7c8ff89e DS |
7557 | "Metric for redistributed routes\n" |
7558 | "OSPF default metric\n" | |
7559 | "OSPF exterior metric type for redistributed routes\n" | |
7111c1a0 | 7560 | "Set OSPF External Type 1/2 metrics\n" |
7c8ff89e DS |
7561 | "Route map reference\n" |
7562 | "Pointer to route-map entries\n") | |
7563 | { | |
a3d826f0 | 7564 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 7565 | int idx_ospf_table = 2; |
7566 | int idx_number = 3; | |
7567 | u_int instance; | |
7568 | struct ospf_redist *red; | |
7569 | int source; | |
7570 | ||
7571 | if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0) | |
7572 | source = ZEBRA_ROUTE_OSPF; | |
7573 | else | |
7574 | source = ZEBRA_ROUTE_TABLE; | |
7575 | ||
7576 | instance = strtoul(argv[idx_number]->arg, NULL, 10); | |
7c8ff89e | 7577 | |
d62a17ae | 7578 | if ((source == ZEBRA_ROUTE_OSPF) && !ospf->instance) { |
7579 | vty_out(vty, | |
7580 | "Instance redistribution in non-instanced OSPF not allowed\n"); | |
7581 | return CMD_WARNING_CONFIG_FAILED; | |
7582 | } | |
7583 | ||
7584 | if ((source == ZEBRA_ROUTE_OSPF) && (ospf->instance == instance)) { | |
7585 | vty_out(vty, "Same instance OSPF redistribution not allowed\n"); | |
7586 | return CMD_WARNING_CONFIG_FAILED; | |
7587 | } | |
7588 | ||
7589 | red = ospf_redist_lookup(ospf, source, instance); | |
7590 | if (!red) | |
7591 | return CMD_SUCCESS; | |
7592 | ||
7593 | ospf_routemap_unset(red); | |
7594 | return ospf_redistribute_unset(ospf, source, instance); | |
718e3744 | 7595 | } |
7596 | ||
7597 | DEFUN (ospf_distribute_list_out, | |
7598 | ospf_distribute_list_out_cmd, | |
40d1cbfb | 7599 | "distribute-list WORD out " FRR_REDIST_STR_OSPFD, |
718e3744 | 7600 | "Filter networks in routing updates\n" |
6f2a6703 CF |
7601 | "Access-list name\n" |
7602 | OUT_STR | |
ab0181ee | 7603 | FRR_REDIST_HELP_STR_OSPFD) |
718e3744 | 7604 | { |
a3d826f0 | 7605 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 7606 | int idx_word = 1; |
7607 | int source; | |
718e3744 | 7608 | |
d62a17ae | 7609 | char *proto = argv[argc - 1]->text; |
6d681bd8 | 7610 | |
d62a17ae | 7611 | /* Get distribute source. */ |
7612 | source = proto_redistnum(AFI_IP, proto); | |
7613 | if (source < 0) | |
7614 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 7615 | |
d62a17ae | 7616 | return ospf_distribute_list_out_set(ospf, source, argv[idx_word]->arg); |
718e3744 | 7617 | } |
7618 | ||
6f2a6703 CF |
7619 | DEFUN (no_ospf_distribute_list_out, |
7620 | no_ospf_distribute_list_out_cmd, | |
40d1cbfb | 7621 | "no distribute-list WORD out " FRR_REDIST_STR_OSPFD, |
6f2a6703 CF |
7622 | NO_STR |
7623 | "Filter networks in routing updates\n" | |
7624 | "Access-list name\n" | |
7625 | OUT_STR | |
ab0181ee | 7626 | FRR_REDIST_HELP_STR_OSPFD) |
718e3744 | 7627 | { |
a3d826f0 | 7628 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 7629 | int idx_word = 2; |
7630 | int source; | |
020709f9 | 7631 | |
d62a17ae | 7632 | char *proto = argv[argc - 1]->text; |
7633 | source = proto_redistnum(AFI_IP, proto); | |
7634 | if (source < 0) | |
7635 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 7636 | |
d62a17ae | 7637 | return ospf_distribute_list_out_unset(ospf, source, |
7638 | argv[idx_word]->arg); | |
718e3744 | 7639 | } |
7640 | ||
6f2a6703 CF |
7641 | /* Default information originate. */ |
7642 | DEFUN (ospf_default_information_originate, | |
7643 | ospf_default_information_originate_cmd, | |
e83a9414 | 7644 | "default-information originate [<always|metric (0-16777214)|metric-type (1-2)|route-map WORD>]", |
718e3744 | 7645 | "Control distribution of default information\n" |
7646 | "Distribute a default route\n" | |
7647 | "Always advertise default route\n" | |
6f2a6703 CF |
7648 | "OSPF default metric\n" |
7649 | "OSPF metric\n" | |
718e3744 | 7650 | "OSPF metric type for default routes\n" |
7111c1a0 | 7651 | "Set OSPF External Type 1/2 metrics\n" |
718e3744 | 7652 | "Route map reference\n" |
7653 | "Pointer to route-map entries\n") | |
7654 | { | |
a3d826f0 | 7655 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 7656 | int default_originate = DEFAULT_ORIGINATE_ZEBRA; |
7657 | int type = -1; | |
7658 | int metric = -1; | |
7659 | struct ospf_redist *red; | |
7660 | int idx = 0; | |
7661 | ||
7662 | red = ospf_redist_add(ospf, DEFAULT_ROUTE, 0); | |
7663 | ||
7664 | /* Check whether "always" was specified */ | |
7665 | if (argv_find(argv, argc, "always", &idx)) | |
7666 | default_originate = DEFAULT_ORIGINATE_ALWAYS; | |
7667 | /* Get metric value */ | |
7668 | else if (argv_find(argv, argc, "(0-16777214)", &idx)) { | |
7669 | if (!str2metric(argv[idx]->arg, &metric)) | |
7670 | return CMD_WARNING_CONFIG_FAILED; | |
7671 | } | |
7672 | /* Get metric type. */ | |
7673 | else if (argv_find(argv, argc, "(1-2)", &idx)) { | |
7674 | if (!str2metric_type(argv[idx]->arg, &type)) | |
7675 | return CMD_WARNING_CONFIG_FAILED; | |
7676 | } | |
7677 | /* Get route-map */ | |
7678 | else if (argv_find(argv, argc, "WORD", &idx)) | |
7679 | ospf_routemap_set(red, argv[idx]->arg); | |
7680 | else | |
7681 | ospf_routemap_unset(red); | |
7682 | ||
7683 | return ospf_redistribute_default_set(ospf, default_originate, type, | |
7684 | metric); | |
718e3744 | 7685 | } |
7686 | ||
7687 | DEFUN (no_ospf_default_information_originate, | |
7688 | no_ospf_default_information_originate_cmd, | |
12dcf78e | 7689 | "no default-information originate [<always|metric (0-16777214)|metric-type (1-2)|route-map WORD>]", |
718e3744 | 7690 | NO_STR |
7691 | "Control distribution of default information\n" | |
813d4307 DW |
7692 | "Distribute a default route\n" |
7693 | "Always advertise default route\n" | |
7694 | "OSPF default metric\n" | |
7695 | "OSPF metric\n" | |
7696 | "OSPF metric type for default routes\n" | |
7111c1a0 | 7697 | "Set OSPF External Type 1/2 metrics\n" |
813d4307 DW |
7698 | "Route map reference\n" |
7699 | "Pointer to route-map entries\n") | |
718e3744 | 7700 | { |
a3d826f0 | 7701 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 7702 | struct prefix_ipv4 p; |
7703 | struct ospf_external *ext; | |
7704 | struct ospf_redist *red; | |
7c8ff89e | 7705 | |
d62a17ae | 7706 | p.family = AF_INET; |
7707 | p.prefix.s_addr = 0; | |
7708 | p.prefixlen = 0; | |
718e3744 | 7709 | |
d62a17ae | 7710 | ospf_external_lsa_flush(ospf, DEFAULT_ROUTE, &p, 0); |
718e3744 | 7711 | |
d62a17ae | 7712 | if ((ext = ospf_external_lookup(DEFAULT_ROUTE, 0)) |
7713 | && EXTERNAL_INFO(ext)) { | |
7714 | ospf_external_info_delete(DEFAULT_ROUTE, 0, p); | |
7715 | ospf_external_del(DEFAULT_ROUTE, 0); | |
7716 | } | |
718e3744 | 7717 | |
d62a17ae | 7718 | red = ospf_redist_lookup(ospf, DEFAULT_ROUTE, 0); |
7719 | if (!red) | |
7720 | return CMD_SUCCESS; | |
7c8ff89e | 7721 | |
d62a17ae | 7722 | ospf_routemap_unset(red); |
7723 | return ospf_redistribute_default_unset(ospf); | |
718e3744 | 7724 | } |
7725 | ||
7726 | DEFUN (ospf_default_metric, | |
7727 | ospf_default_metric_cmd, | |
6147e2c6 | 7728 | "default-metric (0-16777214)", |
718e3744 | 7729 | "Set metric of redistributed routes\n" |
7730 | "Default metric\n") | |
7731 | { | |
a3d826f0 | 7732 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 7733 | int idx_number = 1; |
7734 | int metric = -1; | |
718e3744 | 7735 | |
d62a17ae | 7736 | if (!str2metric(argv[idx_number]->arg, &metric)) |
7737 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 7738 | |
d62a17ae | 7739 | ospf->default_metric = metric; |
718e3744 | 7740 | |
d62a17ae | 7741 | return CMD_SUCCESS; |
718e3744 | 7742 | } |
7743 | ||
7744 | DEFUN (no_ospf_default_metric, | |
7745 | no_ospf_default_metric_cmd, | |
7a7be519 | 7746 | "no default-metric [(0-16777214)]", |
718e3744 | 7747 | NO_STR |
7a7be519 | 7748 | "Set metric of redistributed routes\n" |
7749 | "Default metric\n") | |
718e3744 | 7750 | { |
a3d826f0 | 7751 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
68980084 | 7752 | |
d62a17ae | 7753 | ospf->default_metric = -1; |
68980084 | 7754 | |
d62a17ae | 7755 | return CMD_SUCCESS; |
718e3744 | 7756 | } |
7757 | ||
718e3744 | 7758 | |
7759 | DEFUN (ospf_distance, | |
7760 | ospf_distance_cmd, | |
6147e2c6 | 7761 | "distance (1-255)", |
eaa1ae0d | 7762 | "Administrative distance\n" |
718e3744 | 7763 | "OSPF Administrative distance\n") |
7764 | { | |
a3d826f0 | 7765 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 7766 | int idx_number = 1; |
68980084 | 7767 | |
d62a17ae | 7768 | ospf->distance_all = atoi(argv[idx_number]->arg); |
68980084 | 7769 | |
d62a17ae | 7770 | return CMD_SUCCESS; |
718e3744 | 7771 | } |
7772 | ||
7773 | DEFUN (no_ospf_distance, | |
7774 | no_ospf_distance_cmd, | |
6147e2c6 | 7775 | "no distance (1-255)", |
718e3744 | 7776 | NO_STR |
eaa1ae0d | 7777 | "Administrative distance\n" |
718e3744 | 7778 | "OSPF Administrative distance\n") |
7779 | { | |
a3d826f0 | 7780 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
68980084 | 7781 | |
d62a17ae | 7782 | ospf->distance_all = 0; |
68980084 | 7783 | |
d62a17ae | 7784 | return CMD_SUCCESS; |
718e3744 | 7785 | } |
7786 | ||
7787 | DEFUN (no_ospf_distance_ospf, | |
7788 | no_ospf_distance_ospf_cmd, | |
eaa1ae0d | 7789 | "no distance ospf [{intra-area [(1-255)]|inter-area [(1-255)]|external [(1-255)]}]", |
718e3744 | 7790 | NO_STR |
eaa1ae0d QY |
7791 | "Administrative distance\n" |
7792 | "OSPF administrative distance\n" | |
718e3744 | 7793 | "Intra-area routes\n" |
813d4307 | 7794 | "Distance for intra-area routes\n" |
718e3744 | 7795 | "Inter-area routes\n" |
813d4307 DW |
7796 | "Distance for inter-area routes\n" |
7797 | "External routes\n" | |
7798 | "Distance for external routes\n") | |
718e3744 | 7799 | { |
a3d826f0 | 7800 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 7801 | int idx = 0; |
718e3744 | 7802 | |
d62a17ae | 7803 | if (!ospf) |
7804 | return CMD_SUCCESS; | |
7c8ff89e | 7805 | |
d62a17ae | 7806 | if (argv_find(argv, argc, "intra-area", &idx) || argc == 3) |
7807 | idx = ospf->distance_intra = 0; | |
7808 | if (argv_find(argv, argc, "inter-area", &idx) || argc == 3) | |
7809 | idx = ospf->distance_inter = 0; | |
7810 | if (argv_find(argv, argc, "external", &idx) || argc == 3) | |
7811 | ospf->distance_external = 0; | |
718e3744 | 7812 | |
d62a17ae | 7813 | return CMD_SUCCESS; |
718e3744 | 7814 | } |
7815 | ||
6f2a6703 CF |
7816 | DEFUN (ospf_distance_ospf, |
7817 | ospf_distance_ospf_cmd, | |
eaa1ae0d QY |
7818 | "distance ospf {intra-area (1-255)|inter-area (1-255)|external (1-255)}", |
7819 | "Administrative distance\n" | |
7820 | "OSPF administrative distance\n" | |
718e3744 | 7821 | "Intra-area routes\n" |
7822 | "Distance for intra-area routes\n" | |
718e3744 | 7823 | "Inter-area routes\n" |
7824 | "Distance for inter-area routes\n" | |
7825 | "External routes\n" | |
718e3744 | 7826 | "Distance for external routes\n") |
7827 | { | |
a3d826f0 | 7828 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 7829 | int idx = 0; |
68980084 | 7830 | |
d62a17ae | 7831 | if (argv_find(argv, argc, "intra-area", &idx)) |
7832 | ospf->distance_intra = atoi(argv[idx + 1]->arg); | |
7833 | idx = 0; | |
7834 | if (argv_find(argv, argc, "inter-area", &idx)) | |
7835 | ospf->distance_inter = atoi(argv[idx + 1]->arg); | |
7836 | idx = 0; | |
7837 | if (argv_find(argv, argc, "external", &idx)) | |
7838 | ospf->distance_external = atoi(argv[idx + 1]->arg); | |
68980084 | 7839 | |
d62a17ae | 7840 | return CMD_SUCCESS; |
718e3744 | 7841 | } |
7842 | ||
d7d73ffc | 7843 | #if 0 |
718e3744 | 7844 | DEFUN (ospf_distance_source, |
7845 | ospf_distance_source_cmd, | |
6147e2c6 | 7846 | "distance (1-255) A.B.C.D/M", |
718e3744 | 7847 | "Administrative distance\n" |
7848 | "Distance value\n" | |
7849 | "IP source prefix\n") | |
7850 | { | |
cdc2d765 | 7851 | VTY_DECLVAR_CONTEXT(ospf, ospf); |
8d769265 DW |
7852 | int idx_number = 1; |
7853 | int idx_ipv4_prefixlen = 2; | |
020709f9 | 7854 | |
7c8ff89e DS |
7855 | if (!ospf) |
7856 | return CMD_SUCCESS; | |
7857 | ||
8d769265 | 7858 | ospf_distance_set (vty, ospf, argv[idx_number]->arg, argv[idx_ipv4_prefixlen]->arg, NULL); |
68980084 | 7859 | |
718e3744 | 7860 | return CMD_SUCCESS; |
7861 | } | |
7862 | ||
7863 | DEFUN (no_ospf_distance_source, | |
7864 | no_ospf_distance_source_cmd, | |
6147e2c6 | 7865 | "no distance (1-255) A.B.C.D/M", |
718e3744 | 7866 | NO_STR |
7867 | "Administrative distance\n" | |
7868 | "Distance value\n" | |
7869 | "IP source prefix\n") | |
7870 | { | |
cdc2d765 | 7871 | VTY_DECLVAR_CONTEXT(ospf, ospf); |
8d769265 DW |
7872 | int idx_number = 2; |
7873 | int idx_ipv4_prefixlen = 3; | |
020709f9 | 7874 | |
7c8ff89e DS |
7875 | if (!ospf) |
7876 | return CMD_SUCCESS; | |
7877 | ||
8d769265 | 7878 | ospf_distance_unset (vty, ospf, argv[idx_number]->arg, argv[idx_ipv4_prefixlen]->arg, NULL); |
020709f9 | 7879 | |
718e3744 | 7880 | return CMD_SUCCESS; |
7881 | } | |
7882 | ||
7883 | DEFUN (ospf_distance_source_access_list, | |
7884 | ospf_distance_source_access_list_cmd, | |
6147e2c6 | 7885 | "distance (1-255) A.B.C.D/M WORD", |
718e3744 | 7886 | "Administrative distance\n" |
7887 | "Distance value\n" | |
7888 | "IP source prefix\n" | |
7889 | "Access list name\n") | |
7890 | { | |
cdc2d765 | 7891 | VTY_DECLVAR_CONTEXT(ospf, ospf); |
8d769265 DW |
7892 | int idx_number = 1; |
7893 | int idx_ipv4_prefixlen = 2; | |
7894 | int idx_word = 3; | |
020709f9 | 7895 | |
7c8ff89e DS |
7896 | if (!ospf) |
7897 | return CMD_SUCCESS; | |
7898 | ||
8d769265 | 7899 | ospf_distance_set (vty, ospf, argv[idx_number]->arg, argv[idx_ipv4_prefixlen]->arg, argv[idx_word]->arg); |
020709f9 | 7900 | |
718e3744 | 7901 | return CMD_SUCCESS; |
7902 | } | |
7903 | ||
7904 | DEFUN (no_ospf_distance_source_access_list, | |
7905 | no_ospf_distance_source_access_list_cmd, | |
6147e2c6 | 7906 | "no distance (1-255) A.B.C.D/M WORD", |
718e3744 | 7907 | NO_STR |
7908 | "Administrative distance\n" | |
7909 | "Distance value\n" | |
7910 | "IP source prefix\n" | |
7911 | "Access list name\n") | |
7912 | { | |
cdc2d765 | 7913 | VTY_DECLVAR_CONTEXT(ospf, ospf); |
8d769265 DW |
7914 | int idx_number = 2; |
7915 | int idx_ipv4_prefixlen = 3; | |
7916 | int idx_word = 4; | |
020709f9 | 7917 | |
7c8ff89e DS |
7918 | if (!ospf) |
7919 | return CMD_SUCCESS; | |
7920 | ||
8d769265 | 7921 | ospf_distance_unset (vty, ospf, argv[idx_number]->arg, argv[idx_ipv4_prefixlen]->arg, argv[idx_word]->arg); |
020709f9 | 7922 | |
718e3744 | 7923 | return CMD_SUCCESS; |
7924 | } | |
d7d73ffc | 7925 | #endif |
718e3744 | 7926 | |
ba682537 | 7927 | DEFUN (ip_ospf_mtu_ignore, |
7928 | ip_ospf_mtu_ignore_addr_cmd, | |
7a7be519 | 7929 | "ip ospf mtu-ignore [A.B.C.D]", |
ba682537 | 7930 | "IP Information\n" |
7931 | "OSPF interface commands\n" | |
99a522c7 | 7932 | "Disable MTU mismatch detection on this interface\n" |
ba682537 | 7933 | "Address of interface") |
7934 | { | |
d62a17ae | 7935 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7936 | int idx_ipv4 = 3; | |
7937 | struct in_addr addr; | |
7938 | int ret; | |
7939 | ||
7940 | struct ospf_if_params *params; | |
7941 | params = IF_DEF_PARAMS(ifp); | |
7942 | ||
7943 | if (argc == 4) { | |
7944 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
7945 | if (!ret) { | |
7946 | vty_out(vty, | |
7947 | "Please specify interface address by A.B.C.D\n"); | |
7948 | return CMD_WARNING_CONFIG_FAILED; | |
7949 | } | |
7950 | params = ospf_get_if_params(ifp, addr); | |
7951 | ospf_if_update_params(ifp, addr); | |
7952 | } | |
7953 | params->mtu_ignore = 1; | |
7954 | if (params->mtu_ignore != OSPF_MTU_IGNORE_DEFAULT) | |
7955 | SET_IF_PARAM(params, mtu_ignore); | |
7956 | else { | |
7957 | UNSET_IF_PARAM(params, mtu_ignore); | |
7958 | if (params != IF_DEF_PARAMS(ifp)) { | |
7959 | ospf_free_if_params(ifp, addr); | |
7960 | ospf_if_update_params(ifp, addr); | |
7961 | } | |
7962 | } | |
7963 | return CMD_SUCCESS; | |
ba682537 | 7964 | } |
7965 | ||
ba682537 | 7966 | DEFUN (no_ip_ospf_mtu_ignore, |
7967 | no_ip_ospf_mtu_ignore_addr_cmd, | |
7a7be519 | 7968 | "no ip ospf mtu-ignore [A.B.C.D]", |
ba682537 | 7969 | "IP Information\n" |
7970 | "OSPF interface commands\n" | |
99a522c7 | 7971 | "Disable MTU mismatch detection on this interface\n" |
ba682537 | 7972 | "Address of interface") |
7973 | { | |
d62a17ae | 7974 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7975 | int idx_ipv4 = 4; | |
7976 | struct in_addr addr; | |
7977 | int ret; | |
7978 | ||
7979 | struct ospf_if_params *params; | |
7980 | params = IF_DEF_PARAMS(ifp); | |
7981 | ||
7982 | if (argc == 5) { | |
7983 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
7984 | if (!ret) { | |
7985 | vty_out(vty, | |
7986 | "Please specify interface address by A.B.C.D\n"); | |
7987 | return CMD_WARNING_CONFIG_FAILED; | |
7988 | } | |
7989 | params = ospf_get_if_params(ifp, addr); | |
7990 | ospf_if_update_params(ifp, addr); | |
7991 | } | |
7992 | params->mtu_ignore = 0; | |
7993 | if (params->mtu_ignore != OSPF_MTU_IGNORE_DEFAULT) | |
7994 | SET_IF_PARAM(params, mtu_ignore); | |
7995 | else { | |
7996 | UNSET_IF_PARAM(params, mtu_ignore); | |
7997 | if (params != IF_DEF_PARAMS(ifp)) { | |
7998 | ospf_free_if_params(ifp, addr); | |
7999 | ospf_if_update_params(ifp, addr); | |
8000 | } | |
8001 | } | |
8002 | return CMD_SUCCESS; | |
ba682537 | 8003 | } |
8004 | ||
6b0655a2 | 8005 | |
88d6cf37 | 8006 | DEFUN (ospf_max_metric_router_lsa_admin, |
8007 | ospf_max_metric_router_lsa_admin_cmd, | |
8008 | "max-metric router-lsa administrative", | |
8009 | "OSPF maximum / infinite-distance metric\n" | |
8010 | "Advertise own Router-LSA with infinite distance (stub router)\n" | |
8011 | "Administratively applied, for an indefinite period\n") | |
8012 | { | |
a3d826f0 | 8013 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 8014 | struct listnode *ln; |
8015 | struct ospf_area *area; | |
7c8ff89e | 8016 | |
d62a17ae | 8017 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, ln, area)) { |
8018 | SET_FLAG(area->stub_router_state, OSPF_AREA_ADMIN_STUB_ROUTED); | |
4ba4fc85 | 8019 | |
d62a17ae | 8020 | if (!CHECK_FLAG(area->stub_router_state, |
8021 | OSPF_AREA_IS_STUB_ROUTED)) | |
8022 | ospf_router_lsa_update_area(area); | |
8023 | } | |
4ba4fc85 | 8024 | |
d62a17ae | 8025 | /* Allows for areas configured later to get the property */ |
8026 | ospf->stub_router_admin_set = OSPF_STUB_ROUTER_ADMINISTRATIVE_SET; | |
8027 | ||
8028 | return CMD_SUCCESS; | |
88d6cf37 | 8029 | } |
8030 | ||
8031 | DEFUN (no_ospf_max_metric_router_lsa_admin, | |
8032 | no_ospf_max_metric_router_lsa_admin_cmd, | |
8033 | "no max-metric router-lsa administrative", | |
8034 | NO_STR | |
8035 | "OSPF maximum / infinite-distance metric\n" | |
8036 | "Advertise own Router-LSA with infinite distance (stub router)\n" | |
8037 | "Administratively applied, for an indefinite period\n") | |
8038 | { | |
a3d826f0 | 8039 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 8040 | struct listnode *ln; |
8041 | struct ospf_area *area; | |
8042 | ||
8043 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, ln, area)) { | |
8044 | UNSET_FLAG(area->stub_router_state, | |
8045 | OSPF_AREA_ADMIN_STUB_ROUTED); | |
8046 | ||
8047 | /* Don't trample on the start-up stub timer */ | |
8048 | if (CHECK_FLAG(area->stub_router_state, | |
8049 | OSPF_AREA_IS_STUB_ROUTED) | |
8050 | && !area->t_stub_router) { | |
8051 | UNSET_FLAG(area->stub_router_state, | |
8052 | OSPF_AREA_IS_STUB_ROUTED); | |
8053 | ospf_router_lsa_update_area(area); | |
8054 | } | |
8055 | } | |
8056 | ospf->stub_router_admin_set = OSPF_STUB_ROUTER_ADMINISTRATIVE_UNSET; | |
8057 | return CMD_SUCCESS; | |
88d6cf37 | 8058 | } |
8059 | ||
8060 | DEFUN (ospf_max_metric_router_lsa_startup, | |
8061 | ospf_max_metric_router_lsa_startup_cmd, | |
6147e2c6 | 8062 | "max-metric router-lsa on-startup (5-86400)", |
88d6cf37 | 8063 | "OSPF maximum / infinite-distance metric\n" |
8064 | "Advertise own Router-LSA with infinite distance (stub router)\n" | |
8065 | "Automatically advertise stub Router-LSA on startup of OSPF\n" | |
8066 | "Time (seconds) to advertise self as stub-router\n") | |
8067 | { | |
a3d826f0 | 8068 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 8069 | int idx_number = 3; |
8070 | unsigned int seconds; | |
8071 | ||
b5a8894d | 8072 | if (argc < 4) { |
d62a17ae | 8073 | vty_out(vty, "%% Must supply stub-router period"); |
8074 | return CMD_WARNING_CONFIG_FAILED; | |
8075 | } | |
8076 | ||
8077 | seconds = strtoul(argv[idx_number]->arg, NULL, 10); | |
8078 | ||
8079 | ospf->stub_router_startup_time = seconds; | |
8080 | ||
8081 | return CMD_SUCCESS; | |
88d6cf37 | 8082 | } |
8083 | ||
8084 | DEFUN (no_ospf_max_metric_router_lsa_startup, | |
8085 | no_ospf_max_metric_router_lsa_startup_cmd, | |
7a7be519 | 8086 | "no max-metric router-lsa on-startup [(5-86400)]", |
88d6cf37 | 8087 | NO_STR |
8088 | "OSPF maximum / infinite-distance metric\n" | |
8089 | "Advertise own Router-LSA with infinite distance (stub router)\n" | |
813d4307 DW |
8090 | "Automatically advertise stub Router-LSA on startup of OSPF\n" |
8091 | "Time (seconds) to advertise self as stub-router\n") | |
88d6cf37 | 8092 | { |
a3d826f0 | 8093 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 8094 | struct listnode *ln; |
8095 | struct ospf_area *area; | |
8096 | ||
8097 | ospf->stub_router_startup_time = OSPF_STUB_ROUTER_UNCONFIGURED; | |
8098 | ||
8099 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, ln, area)) { | |
8100 | SET_FLAG(area->stub_router_state, | |
8101 | OSPF_AREA_WAS_START_STUB_ROUTED); | |
8102 | OSPF_TIMER_OFF(area->t_stub_router); | |
8103 | ||
8104 | /* Don't trample on admin stub routed */ | |
8105 | if (!CHECK_FLAG(area->stub_router_state, | |
8106 | OSPF_AREA_ADMIN_STUB_ROUTED)) { | |
8107 | UNSET_FLAG(area->stub_router_state, | |
8108 | OSPF_AREA_IS_STUB_ROUTED); | |
8109 | ospf_router_lsa_update_area(area); | |
8110 | } | |
8111 | } | |
8112 | return CMD_SUCCESS; | |
88d6cf37 | 8113 | } |
8114 | ||
a1afa410 | 8115 | |
88d6cf37 | 8116 | DEFUN (ospf_max_metric_router_lsa_shutdown, |
8117 | ospf_max_metric_router_lsa_shutdown_cmd, | |
6147e2c6 | 8118 | "max-metric router-lsa on-shutdown (5-100)", |
88d6cf37 | 8119 | "OSPF maximum / infinite-distance metric\n" |
8120 | "Advertise own Router-LSA with infinite distance (stub router)\n" | |
8121 | "Advertise stub-router prior to full shutdown of OSPF\n" | |
8122 | "Time (seconds) to wait till full shutdown\n") | |
8123 | { | |
a3d826f0 | 8124 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 8125 | int idx_number = 3; |
8126 | unsigned int seconds; | |
8127 | ||
b5a8894d | 8128 | if (argc < 4) { |
d62a17ae | 8129 | vty_out(vty, "%% Must supply stub-router shutdown period"); |
8130 | return CMD_WARNING_CONFIG_FAILED; | |
8131 | } | |
8132 | ||
8133 | seconds = strtoul(argv[idx_number]->arg, NULL, 10); | |
8134 | ||
8135 | ospf->stub_router_shutdown_time = seconds; | |
8136 | ||
8137 | return CMD_SUCCESS; | |
88d6cf37 | 8138 | } |
8139 | ||
8140 | DEFUN (no_ospf_max_metric_router_lsa_shutdown, | |
8141 | no_ospf_max_metric_router_lsa_shutdown_cmd, | |
7a7be519 | 8142 | "no max-metric router-lsa on-shutdown [(5-100)]", |
88d6cf37 | 8143 | NO_STR |
8144 | "OSPF maximum / infinite-distance metric\n" | |
8145 | "Advertise own Router-LSA with infinite distance (stub router)\n" | |
813d4307 DW |
8146 | "Advertise stub-router prior to full shutdown of OSPF\n" |
8147 | "Time (seconds) to wait till full shutdown\n") | |
88d6cf37 | 8148 | { |
a3d826f0 | 8149 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
7c8ff89e | 8150 | |
d62a17ae | 8151 | ospf->stub_router_shutdown_time = OSPF_STUB_ROUTER_UNCONFIGURED; |
8152 | ||
8153 | return CMD_SUCCESS; | |
88d6cf37 | 8154 | } |
8155 | ||
d62a17ae | 8156 | static void config_write_stub_router(struct vty *vty, struct ospf *ospf) |
8157 | { | |
8158 | struct listnode *ln; | |
8159 | struct ospf_area *area; | |
8160 | ||
8161 | if (ospf->stub_router_startup_time != OSPF_STUB_ROUTER_UNCONFIGURED) | |
8162 | vty_out(vty, " max-metric router-lsa on-startup %u\n", | |
8163 | ospf->stub_router_startup_time); | |
8164 | if (ospf->stub_router_shutdown_time != OSPF_STUB_ROUTER_UNCONFIGURED) | |
8165 | vty_out(vty, " max-metric router-lsa on-shutdown %u\n", | |
8166 | ospf->stub_router_shutdown_time); | |
8167 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, ln, area)) { | |
8168 | if (CHECK_FLAG(area->stub_router_state, | |
8169 | OSPF_AREA_ADMIN_STUB_ROUTED)) { | |
8170 | vty_out(vty, " max-metric router-lsa administrative\n"); | |
8171 | break; | |
8172 | } | |
8173 | } | |
8174 | return; | |
8175 | } | |
8176 | ||
b5a8894d CS |
8177 | static void show_ip_ospf_route_network(struct vty *vty, struct ospf *ospf, |
8178 | struct route_table *rt) | |
d62a17ae | 8179 | { |
8180 | struct route_node *rn; | |
8181 | struct ospf_route * or ; | |
8182 | struct listnode *pnode, *pnnode; | |
8183 | struct ospf_path *path; | |
8184 | ||
8185 | vty_out(vty, "============ OSPF network routing table ============\n"); | |
8186 | ||
8187 | for (rn = route_top(rt); rn; rn = route_next(rn)) | |
8188 | if ((or = rn->info) != NULL) { | |
8189 | char buf1[19]; | |
8190 | snprintf(buf1, 19, "%s/%d", inet_ntoa(rn->p.u.prefix4), | |
8191 | rn->p.prefixlen); | |
8192 | ||
8193 | switch (or->path_type) { | |
8194 | case OSPF_PATH_INTER_AREA: | |
8195 | if (or->type == OSPF_DESTINATION_NETWORK) | |
8196 | vty_out(vty, | |
8197 | "N IA %-18s [%d] area: %s\n", | |
8198 | buf1, or->cost, | |
8199 | inet_ntoa(or->u.std.area_id)); | |
8200 | else if (or->type == OSPF_DESTINATION_DISCARD) | |
8201 | vty_out(vty, | |
8202 | "D IA %-18s Discard entry\n", | |
8203 | buf1); | |
8204 | break; | |
8205 | case OSPF_PATH_INTRA_AREA: | |
8206 | vty_out(vty, "N %-18s [%d] area: %s\n", | |
8207 | buf1, or->cost, | |
8208 | inet_ntoa(or->u.std.area_id)); | |
8209 | break; | |
8210 | default: | |
8211 | break; | |
8212 | } | |
8213 | ||
8214 | if (or->type == OSPF_DESTINATION_NETWORK) | |
8215 | for (ALL_LIST_ELEMENTS(or->paths, pnode, pnnode, | |
8216 | path)) { | |
8217 | if (if_lookup_by_index(path->ifindex, | |
b5a8894d | 8218 | ospf->vrf_id)) { |
d62a17ae | 8219 | if (path->nexthop.s_addr == 0) |
8220 | vty_out(vty, | |
8221 | "%24s directly attached to %s\n", | |
8222 | "", | |
8223 | ifindex2ifname( | |
8224 | path->ifindex, | |
b5a8894d | 8225 | ospf->vrf_id)); |
d62a17ae | 8226 | else |
8227 | vty_out(vty, | |
8228 | "%24s via %s, %s\n", | |
8229 | "", | |
8230 | inet_ntoa( | |
8231 | path->nexthop), | |
8232 | ifindex2ifname( | |
8233 | path->ifindex, | |
b5a8894d | 8234 | ospf->vrf_id)); |
d62a17ae | 8235 | } |
8236 | } | |
8237 | } | |
8238 | vty_out(vty, "\n"); | |
8239 | } | |
8240 | ||
b5a8894d CS |
8241 | static void show_ip_ospf_route_router(struct vty *vty, struct ospf *ospf, |
8242 | struct route_table *rtrs) | |
d62a17ae | 8243 | { |
8244 | struct route_node *rn; | |
8245 | struct ospf_route * or ; | |
8246 | struct listnode *pnode; | |
8247 | struct listnode *node; | |
8248 | struct ospf_path *path; | |
8249 | ||
c0f3f7cd | 8250 | vty_out(vty, "============ OSPF router routing table =============\n"); |
d62a17ae | 8251 | for (rn = route_top(rtrs); rn; rn = route_next(rn)) |
8252 | if (rn->info) { | |
8253 | int flag = 0; | |
8254 | ||
8255 | vty_out(vty, "R %-15s ", | |
8256 | inet_ntoa(rn->p.u.prefix4)); | |
8257 | ||
8258 | for (ALL_LIST_ELEMENTS_RO((struct list *)rn->info, node, | |
8259 | or)) { | |
8260 | if (flag++) | |
8261 | vty_out(vty, "%24s", ""); | |
8262 | ||
8263 | /* Show path. */ | |
8264 | vty_out(vty, "%s [%d] area: %s", | |
8265 | (or->path_type == OSPF_PATH_INTER_AREA | |
8266 | ? "IA" | |
8267 | : " "), | |
8268 | or->cost, inet_ntoa(or->u.std.area_id)); | |
8269 | /* Show flags. */ | |
8270 | vty_out(vty, "%s%s\n", | |
8271 | (or->u.std.flags & ROUTER_LSA_BORDER | |
8272 | ? ", ABR" | |
8273 | : ""), | |
8274 | (or->u.std.flags & ROUTER_LSA_EXTERNAL | |
8275 | ? ", ASBR" | |
8276 | : "")); | |
8277 | ||
8278 | for (ALL_LIST_ELEMENTS_RO(or->paths, pnode, | |
8279 | path)) { | |
8280 | if (if_lookup_by_index(path->ifindex, | |
b5a8894d | 8281 | ospf->vrf_id)) { |
d62a17ae | 8282 | if (path->nexthop.s_addr == 0) |
8283 | vty_out(vty, | |
8284 | "%24s directly attached to %s\n", | |
8285 | "", | |
8286 | ifindex2ifname( | |
8287 | path->ifindex, | |
b5a8894d | 8288 | ospf->vrf_id)); |
d62a17ae | 8289 | else |
8290 | vty_out(vty, | |
8291 | "%24s via %s, %s\n", | |
8292 | "", | |
8293 | inet_ntoa( | |
8294 | path->nexthop), | |
8295 | ifindex2ifname( | |
8296 | path->ifindex, | |
b5a8894d | 8297 | ospf->vrf_id)); |
d62a17ae | 8298 | } |
8299 | } | |
8300 | } | |
8301 | } | |
8302 | vty_out(vty, "\n"); | |
8303 | } | |
8304 | ||
b5a8894d CS |
8305 | static void show_ip_ospf_route_external(struct vty *vty, struct ospf *ospf, |
8306 | struct route_table *rt) | |
d62a17ae | 8307 | { |
8308 | struct route_node *rn; | |
8309 | struct ospf_route *er; | |
8310 | struct listnode *pnode, *pnnode; | |
8311 | struct ospf_path *path; | |
8312 | ||
8313 | vty_out(vty, "============ OSPF external routing table ===========\n"); | |
8314 | for (rn = route_top(rt); rn; rn = route_next(rn)) | |
8315 | if ((er = rn->info) != NULL) { | |
8316 | char buf1[19]; | |
8317 | snprintf(buf1, 19, "%s/%d", inet_ntoa(rn->p.u.prefix4), | |
8318 | rn->p.prefixlen); | |
8319 | ||
8320 | switch (er->path_type) { | |
8321 | case OSPF_PATH_TYPE1_EXTERNAL: | |
8322 | vty_out(vty, | |
8323 | "N E1 %-18s [%d] tag: %" ROUTE_TAG_PRI | |
8324 | "\n", | |
8325 | buf1, er->cost, er->u.ext.tag); | |
8326 | break; | |
8327 | case OSPF_PATH_TYPE2_EXTERNAL: | |
8328 | vty_out(vty, | |
8329 | "N E2 %-18s [%d/%d] tag: %" ROUTE_TAG_PRI | |
8330 | "\n", | |
8331 | buf1, er->cost, er->u.ext.type2_cost, | |
8332 | er->u.ext.tag); | |
8333 | break; | |
8334 | } | |
8335 | ||
8336 | for (ALL_LIST_ELEMENTS(er->paths, pnode, pnnode, | |
8337 | path)) { | |
8338 | if (if_lookup_by_index(path->ifindex, | |
b5a8894d | 8339 | ospf->vrf_id)) { |
d62a17ae | 8340 | if (path->nexthop.s_addr == 0) |
8341 | vty_out(vty, | |
8342 | "%24s directly attached to %s\n", | |
8343 | "", | |
8344 | ifindex2ifname( | |
8345 | path->ifindex, | |
b5a8894d | 8346 | ospf->vrf_id)); |
d62a17ae | 8347 | else |
8348 | vty_out(vty, | |
8349 | "%24s via %s, %s\n", | |
8350 | "", | |
8351 | inet_ntoa( | |
8352 | path->nexthop), | |
8353 | ifindex2ifname( | |
8354 | path->ifindex, | |
b5a8894d | 8355 | ospf->vrf_id)); |
d62a17ae | 8356 | } |
54bedb55 | 8357 | } |
d62a17ae | 8358 | } |
8359 | vty_out(vty, "\n"); | |
718e3744 | 8360 | } |
8361 | ||
d62a17ae | 8362 | static int show_ip_ospf_border_routers_common(struct vty *vty, |
8363 | struct ospf *ospf) | |
718e3744 | 8364 | { |
d62a17ae | 8365 | if (ospf->instance) |
8366 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
718e3744 | 8367 | |
d62a17ae | 8368 | if (ospf->new_table == NULL) { |
8369 | vty_out(vty, "No OSPF routing information exist\n"); | |
8370 | return CMD_SUCCESS; | |
8371 | } | |
718e3744 | 8372 | |
d62a17ae | 8373 | /* Show Network routes. |
8374 | show_ip_ospf_route_network (vty, ospf->new_table); */ | |
718e3744 | 8375 | |
d62a17ae | 8376 | /* Show Router routes. */ |
b5a8894d | 8377 | show_ip_ospf_route_router(vty, ospf, ospf->new_rtrs); |
718e3744 | 8378 | |
d62a17ae | 8379 | vty_out(vty, "\n"); |
7c8ff89e | 8380 | |
d62a17ae | 8381 | return CMD_SUCCESS; |
718e3744 | 8382 | } |
718e3744 | 8383 | |
7c8ff89e DS |
8384 | DEFUN (show_ip_ospf_border_routers, |
8385 | show_ip_ospf_border_routers_cmd, | |
b5a8894d | 8386 | "show ip ospf [vrf <NAME|all>] border-routers", |
718e3744 | 8387 | SHOW_STR |
8388 | IP_STR | |
8389 | "OSPF information\n" | |
b5a8894d CS |
8390 | VRF_CMD_HELP_STR |
8391 | "All VRFs\n" | |
7c8ff89e | 8392 | "Show all the ABR's and ASBR's\n") |
718e3744 | 8393 | { |
b5a8894d CS |
8394 | struct ospf *ospf = NULL; |
8395 | struct listnode *node = NULL; | |
8396 | char *vrf_name = NULL; | |
8397 | bool all_vrf = FALSE; | |
8398 | int ret = CMD_SUCCESS; | |
8399 | int inst = 0; | |
8400 | int idx_vrf = 0; | |
68980084 | 8401 | |
43b8d1d8 | 8402 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
7c8ff89e | 8403 | |
b5a8894d CS |
8404 | if (vrf_name) { |
8405 | if (all_vrf) { | |
8406 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
8407 | if (!ospf->oi_running) | |
8408 | continue; | |
b5a8894d CS |
8409 | |
8410 | ret = show_ip_ospf_border_routers_common(vty, | |
8411 | ospf); | |
8412 | } | |
8413 | } else { | |
8414 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
8415 | if (ospf == NULL || !ospf->oi_running) | |
8416 | return CMD_SUCCESS; | |
8417 | ||
b5a8894d CS |
8418 | ret = show_ip_ospf_border_routers_common(vty, ospf); |
8419 | } | |
8420 | } else { | |
8421 | /* Display default ospf (instance 0) info */ | |
8422 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
8423 | if (ospf == NULL || !ospf->oi_running) | |
8424 | return CMD_SUCCESS; | |
b5a8894d CS |
8425 | ret = show_ip_ospf_border_routers_common(vty, ospf); |
8426 | } | |
8427 | ||
8428 | return ret; | |
7c8ff89e DS |
8429 | } |
8430 | ||
8431 | DEFUN (show_ip_ospf_instance_border_routers, | |
8432 | show_ip_ospf_instance_border_routers_cmd, | |
6147e2c6 | 8433 | "show ip ospf (1-65535) border-routers", |
7c8ff89e DS |
8434 | SHOW_STR |
8435 | IP_STR | |
8436 | "OSPF information\n" | |
8437 | "Instance ID\n" | |
8438 | "Show all the ABR's and ASBR's\n") | |
8439 | { | |
d62a17ae | 8440 | int idx_number = 3; |
8441 | struct ospf *ospf; | |
8442 | u_short instance = 0; | |
7c8ff89e | 8443 | |
d62a17ae | 8444 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
ac28e4ec CS |
8445 | ospf = ospf_lookup_instance(instance); |
8446 | if (ospf == NULL) | |
8447 | return CMD_NOT_MY_INSTANCE; | |
8448 | ||
8449 | if (!ospf->oi_running) | |
d62a17ae | 8450 | return CMD_SUCCESS; |
7c8ff89e | 8451 | |
d62a17ae | 8452 | return show_ip_ospf_border_routers_common(vty, ospf); |
7c8ff89e DS |
8453 | } |
8454 | ||
d62a17ae | 8455 | static int show_ip_ospf_route_common(struct vty *vty, struct ospf *ospf) |
7c8ff89e | 8456 | { |
d62a17ae | 8457 | if (ospf->instance) |
8458 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
718e3744 | 8459 | |
d62a17ae | 8460 | if (ospf->new_table == NULL) { |
8461 | vty_out(vty, "No OSPF routing information exist\n"); | |
8462 | return CMD_SUCCESS; | |
8463 | } | |
718e3744 | 8464 | |
d62a17ae | 8465 | /* Show Network routes. */ |
b5a8894d | 8466 | show_ip_ospf_route_network(vty, ospf, ospf->new_table); |
718e3744 | 8467 | |
d62a17ae | 8468 | /* Show Router routes. */ |
b5a8894d | 8469 | show_ip_ospf_route_router(vty, ospf, ospf->new_rtrs); |
718e3744 | 8470 | |
d62a17ae | 8471 | /* Show AS External routes. */ |
b5a8894d | 8472 | show_ip_ospf_route_external(vty, ospf, ospf->old_external_route); |
718e3744 | 8473 | |
d62a17ae | 8474 | vty_out(vty, "\n"); |
7c8ff89e | 8475 | |
d62a17ae | 8476 | return CMD_SUCCESS; |
718e3744 | 8477 | } |
8478 | ||
7c8ff89e DS |
8479 | DEFUN (show_ip_ospf_route, |
8480 | show_ip_ospf_route_cmd, | |
b5a8894d CS |
8481 | "show ip ospf [vrf <NAME|all>] route", |
8482 | SHOW_STR | |
8483 | IP_STR | |
8484 | "OSPF information\n" | |
8485 | VRF_CMD_HELP_STR | |
8486 | "All VRFs\n" | |
8487 | "OSPF routing table\n") | |
8488 | { | |
8489 | struct ospf *ospf = NULL; | |
8490 | struct listnode *node = NULL; | |
8491 | char *vrf_name = NULL; | |
8492 | bool all_vrf = FALSE; | |
8493 | int ret = CMD_SUCCESS; | |
8494 | int inst = 0; | |
8495 | int idx_vrf = 0; | |
7c8ff89e | 8496 | |
43b8d1d8 | 8497 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
7c8ff89e | 8498 | |
b5a8894d CS |
8499 | /* vrf input is provided could be all or specific vrf*/ |
8500 | if (vrf_name) { | |
8501 | if (all_vrf) { | |
8502 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
8503 | if (!ospf->oi_running) | |
8504 | continue; | |
8505 | ret = show_ip_ospf_route_common(vty, ospf); | |
8506 | } | |
8507 | return ret; | |
8508 | } | |
8509 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
8510 | if (ospf == NULL || !ospf->oi_running) | |
8511 | return CMD_SUCCESS; | |
8512 | } else { | |
8513 | /* Display default ospf (instance 0) info */ | |
8514 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
8515 | if (ospf == NULL || !ospf->oi_running) | |
8516 | return CMD_SUCCESS; | |
8517 | } | |
8518 | ||
8519 | if (ospf) | |
8520 | ret = show_ip_ospf_route_common(vty, ospf); | |
8521 | ||
8522 | return ret; | |
7c8ff89e DS |
8523 | } |
8524 | ||
8525 | DEFUN (show_ip_ospf_instance_route, | |
8526 | show_ip_ospf_instance_route_cmd, | |
6147e2c6 | 8527 | "show ip ospf (1-65535) route", |
7c8ff89e DS |
8528 | SHOW_STR |
8529 | IP_STR | |
8530 | "OSPF information\n" | |
8531 | "Instance ID\n" | |
8532 | "OSPF routing table\n") | |
8533 | { | |
d62a17ae | 8534 | int idx_number = 3; |
8535 | struct ospf *ospf; | |
8536 | u_short instance = 0; | |
7c8ff89e | 8537 | |
d62a17ae | 8538 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
ac28e4ec CS |
8539 | ospf = ospf_lookup_instance(instance); |
8540 | if (ospf == NULL) | |
8541 | return CMD_NOT_MY_INSTANCE; | |
8542 | ||
8543 | if (!ospf->oi_running) | |
d62a17ae | 8544 | return CMD_SUCCESS; |
7c8ff89e | 8545 | |
d62a17ae | 8546 | return show_ip_ospf_route_common(vty, ospf); |
7c8ff89e | 8547 | } |
6b0655a2 | 8548 | |
b5a8894d CS |
8549 | |
8550 | DEFUN (show_ip_ospf_vrfs, | |
8551 | show_ip_ospf_vrfs_cmd, | |
8552 | "show ip ospf vrfs [json]", | |
8553 | SHOW_STR | |
8554 | IP_STR | |
8555 | "OSPF information\n" | |
8556 | "Show OSPF VRFs \n" | |
8557 | JSON_STR) | |
8558 | { | |
8559 | u_char uj = use_json(argc, argv); | |
8560 | json_object *json = NULL; | |
8561 | json_object *json_vrfs = NULL; | |
8562 | struct ospf *ospf = NULL; | |
8563 | struct listnode *node = NULL; | |
8564 | int count = 0; | |
8565 | static char header[] = "Name Id RouterId "; | |
8566 | ||
8567 | if (uj) { | |
8568 | json = json_object_new_object(); | |
8569 | json_vrfs = json_object_new_object(); | |
8570 | } | |
8571 | ||
8572 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
8573 | json_object *json_vrf = NULL; | |
8574 | const char *name = NULL; | |
8575 | int vrf_id_ui = 0; | |
8576 | ||
8577 | count++; | |
8578 | ||
8579 | if (!uj && count == 1) | |
8580 | vty_out(vty, "%s\n", header); | |
8581 | if (uj) | |
8582 | json_vrf = json_object_new_object(); | |
8583 | ||
8584 | if (ospf->vrf_id == 0) | |
8585 | name = VRF_DEFAULT_NAME; | |
8586 | else | |
8587 | name = ospf->name; | |
8588 | ||
8589 | vrf_id_ui = (ospf->vrf_id == VRF_UNKNOWN) ? -1 : ospf->vrf_id; | |
8590 | ||
8591 | if (uj) { | |
8592 | json_object_int_add(json_vrf, "vrfId", vrf_id_ui); | |
8593 | json_object_string_add(json_vrf, "routerId", | |
8594 | inet_ntoa(ospf->router_id)); | |
8595 | ||
8596 | json_object_object_add(json_vrfs, name, json_vrf); | |
8597 | ||
8598 | } else { | |
8599 | vty_out(vty, "%-25s %-5d %-16s \n", | |
8600 | name, ospf->vrf_id, inet_ntoa(ospf->router_id)); | |
8601 | } | |
8602 | } | |
8603 | ||
8604 | if (uj) { | |
8605 | json_object_object_add(json, "vrfs", json_vrfs); | |
8606 | json_object_int_add(json, "totalVrfs", count); | |
8607 | ||
8608 | vty_out(vty, "%s\n", json_object_to_json_string_ext(json, | |
8609 | JSON_C_TO_STRING_PRETTY)); | |
8610 | json_object_free(json); | |
8611 | } else { | |
8612 | if (count) | |
8613 | vty_out(vty, "\nTotal number of OSPF VRFs (including default): %d\n", | |
8614 | count); | |
8615 | } | |
8616 | ||
8617 | return CMD_SUCCESS; | |
8618 | } | |
8619 | ||
d62a17ae | 8620 | const char *ospf_abr_type_str[] = {"unknown", "standard", "ibm", "cisco", |
8621 | "shortcut"}; | |
718e3744 | 8622 | |
d62a17ae | 8623 | const char *ospf_shortcut_mode_str[] = {"default", "enable", "disable"}; |
718e3744 | 8624 | |
d62a17ae | 8625 | const char *ospf_int_type_str[] = {"unknown", /* should never be used. */ |
8626 | "point-to-point", "broadcast", | |
8627 | "non-broadcast", "point-to-multipoint", | |
8628 | "virtual-link", /* should never be used. */ | |
8629 | "loopback"}; | |
718e3744 | 8630 | |
43b8d1d8 | 8631 | static int config_write_interface_one(struct vty *vty, struct ospf *ospf) |
d62a17ae | 8632 | { |
8633 | struct listnode *n1, *n2; | |
8634 | struct interface *ifp; | |
8635 | struct crypt_key *ck; | |
d62a17ae | 8636 | struct route_node *rn = NULL; |
8637 | struct ospf_if_params *params; | |
43b8d1d8 | 8638 | int write = 0; |
d62a17ae | 8639 | |
43b8d1d8 CS |
8640 | for (ALL_LIST_ELEMENTS_RO(vrf_iflist(ospf->vrf_id), n1, ifp)) { |
8641 | if (memcmp(ifp->name, "VLINK", 5) == 0) | |
8642 | continue; | |
d62a17ae | 8643 | |
43b8d1d8 CS |
8644 | if (ifp->ifindex == IFINDEX_DELETED) |
8645 | continue; | |
d62a17ae | 8646 | |
43b8d1d8 CS |
8647 | vty_frame(vty, "!\n"); |
8648 | vty_frame(vty, "interface %s\n", ifp->name); | |
8649 | if (ifp->desc) | |
8650 | vty_out(vty, " description %s\n", ifp->desc); | |
d62a17ae | 8651 | |
43b8d1d8 CS |
8652 | write++; |
8653 | ||
8654 | params = IF_DEF_PARAMS(ifp); | |
8655 | ||
8656 | do { | |
8657 | /* Interface Network print. */ | |
8658 | if (OSPF_IF_PARAM_CONFIGURED(params, type) | |
8659 | && params->type != OSPF_IFTYPE_LOOPBACK) { | |
8660 | if (params->type != ospf_default_iftype(ifp)) { | |
8661 | vty_out(vty, " ip ospf network %s", | |
8662 | ospf_int_type_str | |
8663 | [params->type]); | |
8664 | if (params != IF_DEF_PARAMS(ifp)) | |
8665 | vty_out(vty, " %s", | |
d62a17ae | 8666 | inet_ntoa( |
43b8d1d8 CS |
8667 | rn->p.u.prefix4)); |
8668 | vty_out(vty, "\n"); | |
d62a17ae | 8669 | } |
43b8d1d8 | 8670 | } |
d62a17ae | 8671 | |
43b8d1d8 CS |
8672 | /* OSPF interface authentication print */ |
8673 | if (OSPF_IF_PARAM_CONFIGURED(params, auth_type) | |
8674 | && params->auth_type != OSPF_AUTH_NOTSET) { | |
8675 | const char *auth_str; | |
d62a17ae | 8676 | |
43b8d1d8 CS |
8677 | /* Translation tables are not that much help |
8678 | * here due to syntax | |
8679 | * of the simple option */ | |
8680 | switch (params->auth_type) { | |
d62a17ae | 8681 | |
43b8d1d8 CS |
8682 | case OSPF_AUTH_NULL: |
8683 | auth_str = " null"; | |
8684 | break; | |
d62a17ae | 8685 | |
43b8d1d8 CS |
8686 | case OSPF_AUTH_SIMPLE: |
8687 | auth_str = ""; | |
8688 | break; | |
d62a17ae | 8689 | |
43b8d1d8 CS |
8690 | case OSPF_AUTH_CRYPTOGRAPHIC: |
8691 | auth_str = " message-digest"; | |
8692 | break; | |
b5a8894d | 8693 | |
43b8d1d8 CS |
8694 | default: |
8695 | auth_str = ""; | |
8696 | break; | |
d62a17ae | 8697 | } |
8698 | ||
43b8d1d8 CS |
8699 | vty_out(vty, " ip ospf authentication%s", |
8700 | auth_str); | |
8701 | if (params != IF_DEF_PARAMS(ifp)) | |
8702 | vty_out(vty, " %s", | |
8703 | inet_ntoa(rn->p.u.prefix4)); | |
8704 | vty_out(vty, "\n"); | |
8705 | } | |
d62a17ae | 8706 | |
43b8d1d8 CS |
8707 | /* Simple Authentication Password print. */ |
8708 | if (OSPF_IF_PARAM_CONFIGURED(params, auth_simple) | |
8709 | && params->auth_simple[0] != '\0') { | |
8710 | vty_out(vty, " ip ospf authentication-key %s", | |
8711 | params->auth_simple); | |
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 | /* Cryptographic Authentication Key print. */ |
8719 | for (ALL_LIST_ELEMENTS_RO(params->auth_crypt, n2, ck)) { | |
8720 | vty_out(vty, | |
8721 | " ip ospf message-digest-key %d md5 %s", | |
8722 | ck->key_id, ck->auth_key); | |
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 CS |
8729 | /* Interface Output Cost print. */ |
8730 | if (OSPF_IF_PARAM_CONFIGURED(params, | |
8731 | output_cost_cmd)) { | |
8732 | vty_out(vty, " ip ospf cost %u", | |
8733 | params->output_cost_cmd); | |
8734 | if (params != IF_DEF_PARAMS(ifp)) | |
8735 | vty_out(vty, " %s", | |
8736 | inet_ntoa(rn->p.u.prefix4)); | |
8737 | vty_out(vty, "\n"); | |
8738 | } | |
d62a17ae | 8739 | |
43b8d1d8 CS |
8740 | /* Hello Interval print. */ |
8741 | if (OSPF_IF_PARAM_CONFIGURED(params, v_hello) | |
8742 | && params->v_hello != OSPF_HELLO_INTERVAL_DEFAULT) { | |
8743 | vty_out(vty, " ip ospf hello-interval %u", | |
8744 | params->v_hello); | |
8745 | if (params != IF_DEF_PARAMS(ifp)) | |
8746 | vty_out(vty, " %s", | |
8747 | inet_ntoa(rn->p.u.prefix4)); | |
8748 | vty_out(vty, "\n"); | |
8749 | } | |
d62a17ae | 8750 | |
8751 | ||
43b8d1d8 CS |
8752 | /* Router Dead Interval print. */ |
8753 | if (OSPF_IF_PARAM_CONFIGURED(params, v_wait) | |
8754 | && params->v_wait | |
8755 | != OSPF_ROUTER_DEAD_INTERVAL_DEFAULT) { | |
8756 | vty_out(vty, " ip ospf dead-interval "); | |
d62a17ae | 8757 | |
43b8d1d8 CS |
8758 | /* fast hello ? */ |
8759 | if (OSPF_IF_PARAM_CONFIGURED(params, | |
8760 | fast_hello)) | |
8761 | vty_out(vty, | |
8762 | "minimal hello-multiplier %d", | |
8763 | params->fast_hello); | |
8764 | else | |
8765 | vty_out(vty, "%u", params->v_wait); | |
d62a17ae | 8766 | |
43b8d1d8 CS |
8767 | if (params != IF_DEF_PARAMS(ifp)) |
8768 | vty_out(vty, " %s", | |
8769 | inet_ntoa(rn->p.u.prefix4)); | |
8770 | vty_out(vty, "\n"); | |
8771 | } | |
d62a17ae | 8772 | |
43b8d1d8 CS |
8773 | /* Router Priority print. */ |
8774 | if (OSPF_IF_PARAM_CONFIGURED(params, priority) | |
8775 | && params->priority | |
8776 | != OSPF_ROUTER_PRIORITY_DEFAULT) { | |
8777 | vty_out(vty, " ip ospf priority %u", | |
8778 | params->priority); | |
8779 | if (params != IF_DEF_PARAMS(ifp)) | |
8780 | vty_out(vty, " %s", | |
8781 | inet_ntoa(rn->p.u.prefix4)); | |
8782 | vty_out(vty, "\n"); | |
8783 | } | |
d62a17ae | 8784 | |
43b8d1d8 CS |
8785 | /* Retransmit Interval print. */ |
8786 | if (OSPF_IF_PARAM_CONFIGURED(params, | |
8787 | retransmit_interval) | |
8788 | && params->retransmit_interval | |
8789 | != OSPF_RETRANSMIT_INTERVAL_DEFAULT) { | |
8790 | vty_out(vty, " ip ospf retransmit-interval %u", | |
8791 | params->retransmit_interval); | |
8792 | if (params != IF_DEF_PARAMS(ifp)) | |
8793 | vty_out(vty, " %s", | |
8794 | inet_ntoa(rn->p.u.prefix4)); | |
8795 | vty_out(vty, "\n"); | |
8796 | } | |
d62a17ae | 8797 | |
43b8d1d8 CS |
8798 | /* Transmit Delay print. */ |
8799 | if (OSPF_IF_PARAM_CONFIGURED(params, transmit_delay) | |
8800 | && params->transmit_delay | |
8801 | != OSPF_TRANSMIT_DELAY_DEFAULT) { | |
8802 | vty_out(vty, " ip ospf transmit-delay %u", | |
8803 | params->transmit_delay); | |
8804 | if (params != IF_DEF_PARAMS(ifp)) | |
8805 | vty_out(vty, " %s", | |
8806 | inet_ntoa(rn->p.u.prefix4)); | |
8807 | vty_out(vty, "\n"); | |
8808 | } | |
d62a17ae | 8809 | |
43b8d1d8 CS |
8810 | /* Area print. */ |
8811 | if (OSPF_IF_PARAM_CONFIGURED(params, if_area)) { | |
8812 | if (ospf->instance) | |
8813 | vty_out(vty, " ip ospf %d", | |
8814 | ospf->instance); | |
8815 | else | |
8816 | vty_out(vty, " ip ospf"); | |
d62a17ae | 8817 | |
d62a17ae | 8818 | |
43b8d1d8 CS |
8819 | size_t buflen = MAX(strlen("4294967295"), |
8820 | strlen("255.255.255.255")); | |
8821 | char buf[buflen]; | |
d62a17ae | 8822 | |
43b8d1d8 CS |
8823 | area_id2str(buf, sizeof(buf), |
8824 | ¶ms->if_area, | |
8825 | params->if_area_id_fmt); | |
8826 | vty_out(vty, " area %s", buf); | |
8827 | if (params != IF_DEF_PARAMS(ifp)) | |
8828 | vty_out(vty, " %s", | |
8829 | inet_ntoa(rn->p.u.prefix4)); | |
8830 | vty_out(vty, "\n"); | |
8831 | } | |
d62a17ae | 8832 | |
43b8d1d8 CS |
8833 | /* bfd print. */ |
8834 | ospf_bfd_write_config(vty, params); | |
d62a17ae | 8835 | |
43b8d1d8 CS |
8836 | /* MTU ignore print. */ |
8837 | if (OSPF_IF_PARAM_CONFIGURED(params, mtu_ignore) | |
8838 | && params->mtu_ignore != OSPF_MTU_IGNORE_DEFAULT) { | |
8839 | if (params->mtu_ignore == 0) | |
8840 | vty_out(vty, " no ip ospf mtu-ignore"); | |
8841 | else | |
8842 | vty_out(vty, " ip ospf mtu-ignore"); | |
8843 | if (params != IF_DEF_PARAMS(ifp)) | |
8844 | vty_out(vty, " %s", | |
8845 | inet_ntoa(rn->p.u.prefix4)); | |
8846 | vty_out(vty, "\n"); | |
8847 | } | |
d62a17ae | 8848 | |
a8b828f3 | 8849 | |
43b8d1d8 CS |
8850 | while (1) { |
8851 | if (rn == NULL) | |
8852 | rn = route_top(IF_OIFS_PARAMS(ifp)); | |
8853 | else | |
8854 | rn = route_next(rn); | |
d62a17ae | 8855 | |
43b8d1d8 CS |
8856 | if (rn == NULL) |
8857 | break; | |
8858 | params = rn->info; | |
8859 | if (params != NULL) | |
8860 | break; | |
8861 | } | |
8862 | } while (rn); | |
8863 | ||
8864 | ospf_opaque_config_write_if(vty, ifp); | |
8865 | ||
8866 | vty_endframe(vty, NULL); | |
b5a8894d | 8867 | } |
d62a17ae | 8868 | return write; |
718e3744 | 8869 | } |
8870 | ||
43b8d1d8 CS |
8871 | /* Configuration write function for ospfd. */ |
8872 | static int config_write_interface(struct vty *vty) | |
8873 | { | |
8874 | int write = 0; | |
8875 | struct ospf *ospf = NULL; | |
8876 | struct listnode *node = NULL; | |
8877 | ||
8878 | /* Traverse all ospf [vrf] instances */ | |
8879 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) | |
8880 | write += config_write_interface_one(vty, ospf); | |
8881 | ||
8882 | return write; | |
8883 | } | |
8884 | ||
d62a17ae | 8885 | static int config_write_network_area(struct vty *vty, struct ospf *ospf) |
718e3744 | 8886 | { |
d62a17ae | 8887 | struct route_node *rn; |
8888 | u_char buf[INET_ADDRSTRLEN]; | |
718e3744 | 8889 | |
d62a17ae | 8890 | /* `network area' print. */ |
8891 | for (rn = route_top(ospf->networks); rn; rn = route_next(rn)) | |
8892 | if (rn->info) { | |
8893 | struct ospf_network *n = rn->info; | |
718e3744 | 8894 | |
d62a17ae | 8895 | memset(buf, 0, INET_ADDRSTRLEN); |
718e3744 | 8896 | |
d62a17ae | 8897 | /* Create Area ID string by specified Area ID format. */ |
8898 | if (n->area_id_fmt == OSPF_AREA_ID_FMT_DOTTEDQUAD) | |
8899 | strncpy((char *)buf, inet_ntoa(n->area_id), | |
8900 | INET_ADDRSTRLEN); | |
8901 | else | |
8902 | sprintf((char *)buf, "%lu", | |
8903 | (unsigned long int)ntohl( | |
8904 | n->area_id.s_addr)); | |
718e3744 | 8905 | |
d62a17ae | 8906 | /* Network print. */ |
8907 | vty_out(vty, " network %s/%d area %s\n", | |
8908 | inet_ntoa(rn->p.u.prefix4), rn->p.prefixlen, | |
8909 | buf); | |
8910 | } | |
718e3744 | 8911 | |
d62a17ae | 8912 | return 0; |
718e3744 | 8913 | } |
8914 | ||
d62a17ae | 8915 | static int config_write_ospf_area(struct vty *vty, struct ospf *ospf) |
718e3744 | 8916 | { |
d62a17ae | 8917 | struct listnode *node; |
8918 | struct ospf_area *area; | |
8919 | u_char buf[INET_ADDRSTRLEN]; | |
718e3744 | 8920 | |
d62a17ae | 8921 | /* Area configuration print. */ |
8922 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) { | |
8923 | struct route_node *rn1; | |
718e3744 | 8924 | |
d62a17ae | 8925 | area_id2str((char *)buf, INET_ADDRSTRLEN, &area->area_id, |
8926 | area->area_id_fmt); | |
718e3744 | 8927 | |
d62a17ae | 8928 | if (area->auth_type != OSPF_AUTH_NULL) { |
8929 | if (area->auth_type == OSPF_AUTH_SIMPLE) | |
8930 | vty_out(vty, " area %s authentication\n", buf); | |
8931 | else | |
8932 | vty_out(vty, | |
8933 | " area %s authentication message-digest\n", | |
8934 | buf); | |
8935 | } | |
718e3744 | 8936 | |
d62a17ae | 8937 | if (area->shortcut_configured != OSPF_SHORTCUT_DEFAULT) |
8938 | vty_out(vty, " area %s shortcut %s\n", buf, | |
8939 | ospf_shortcut_mode_str | |
8940 | [area->shortcut_configured]); | |
8941 | ||
8942 | if ((area->external_routing == OSPF_AREA_STUB) | |
8943 | || (area->external_routing == OSPF_AREA_NSSA)) { | |
8944 | if (area->external_routing == OSPF_AREA_STUB) | |
8945 | vty_out(vty, " area %s stub", buf); | |
8946 | else if (area->external_routing == OSPF_AREA_NSSA) { | |
8947 | vty_out(vty, " area %s nssa", buf); | |
8948 | switch (area->NSSATranslatorRole) { | |
8949 | case OSPF_NSSA_ROLE_NEVER: | |
8950 | vty_out(vty, " translate-never"); | |
8951 | break; | |
8952 | case OSPF_NSSA_ROLE_ALWAYS: | |
8953 | vty_out(vty, " translate-always"); | |
8954 | break; | |
8955 | case OSPF_NSSA_ROLE_CANDIDATE: | |
8956 | default: | |
8957 | vty_out(vty, " translate-candidate"); | |
8958 | } | |
8959 | } | |
718e3744 | 8960 | |
d62a17ae | 8961 | if (area->no_summary) |
8962 | vty_out(vty, " no-summary"); | |
718e3744 | 8963 | |
d62a17ae | 8964 | vty_out(vty, "\n"); |
718e3744 | 8965 | |
d62a17ae | 8966 | if (area->default_cost != 1) |
8967 | vty_out(vty, " area %s default-cost %d\n", buf, | |
8968 | area->default_cost); | |
8969 | } | |
718e3744 | 8970 | |
d62a17ae | 8971 | for (rn1 = route_top(area->ranges); rn1; rn1 = route_next(rn1)) |
8972 | if (rn1->info) { | |
8973 | struct ospf_area_range *range = rn1->info; | |
718e3744 | 8974 | |
d62a17ae | 8975 | vty_out(vty, " area %s range %s/%d", buf, |
8976 | inet_ntoa(rn1->p.u.prefix4), | |
8977 | rn1->p.prefixlen); | |
718e3744 | 8978 | |
d62a17ae | 8979 | if (range->cost_config |
8980 | != OSPF_AREA_RANGE_COST_UNSPEC) | |
8981 | vty_out(vty, " cost %d", | |
8982 | range->cost_config); | |
718e3744 | 8983 | |
d62a17ae | 8984 | if (!CHECK_FLAG(range->flags, |
8985 | OSPF_AREA_RANGE_ADVERTISE)) | |
8986 | vty_out(vty, " not-advertise"); | |
718e3744 | 8987 | |
d62a17ae | 8988 | if (CHECK_FLAG(range->flags, |
8989 | OSPF_AREA_RANGE_SUBSTITUTE)) | |
8990 | vty_out(vty, " substitute %s/%d", | |
8991 | inet_ntoa(range->subst_addr), | |
8992 | range->subst_masklen); | |
8993 | ||
8994 | vty_out(vty, "\n"); | |
8995 | } | |
8996 | ||
8997 | if (EXPORT_NAME(area)) | |
8998 | vty_out(vty, " area %s export-list %s\n", buf, | |
8999 | EXPORT_NAME(area)); | |
9000 | ||
9001 | if (IMPORT_NAME(area)) | |
9002 | vty_out(vty, " area %s import-list %s\n", buf, | |
9003 | IMPORT_NAME(area)); | |
9004 | ||
9005 | if (PREFIX_NAME_IN(area)) | |
9006 | vty_out(vty, " area %s filter-list prefix %s in\n", buf, | |
9007 | PREFIX_NAME_IN(area)); | |
9008 | ||
9009 | if (PREFIX_NAME_OUT(area)) | |
9010 | vty_out(vty, " area %s filter-list prefix %s out\n", | |
9011 | buf, PREFIX_NAME_OUT(area)); | |
9012 | } | |
9013 | ||
9014 | return 0; | |
718e3744 | 9015 | } |
9016 | ||
d62a17ae | 9017 | static int config_write_ospf_nbr_nbma(struct vty *vty, struct ospf *ospf) |
718e3744 | 9018 | { |
d62a17ae | 9019 | struct ospf_nbr_nbma *nbr_nbma; |
9020 | struct route_node *rn; | |
718e3744 | 9021 | |
d62a17ae | 9022 | /* Static Neighbor configuration print. */ |
9023 | for (rn = route_top(ospf->nbr_nbma); rn; rn = route_next(rn)) | |
9024 | if ((nbr_nbma = rn->info)) { | |
9025 | vty_out(vty, " neighbor %s", inet_ntoa(nbr_nbma->addr)); | |
718e3744 | 9026 | |
d62a17ae | 9027 | if (nbr_nbma->priority |
9028 | != OSPF_NEIGHBOR_PRIORITY_DEFAULT) | |
9029 | vty_out(vty, " priority %d", | |
9030 | nbr_nbma->priority); | |
718e3744 | 9031 | |
d62a17ae | 9032 | if (nbr_nbma->v_poll != OSPF_POLL_INTERVAL_DEFAULT) |
9033 | vty_out(vty, " poll-interval %d", | |
9034 | nbr_nbma->v_poll); | |
9035 | ||
9036 | vty_out(vty, "\n"); | |
9037 | } | |
9038 | ||
9039 | return 0; | |
9040 | } | |
9041 | ||
9042 | static int config_write_virtual_link(struct vty *vty, struct ospf *ospf) | |
9043 | { | |
9044 | struct listnode *node; | |
9045 | struct ospf_vl_data *vl_data; | |
9046 | char buf[INET_ADDRSTRLEN]; | |
9047 | ||
9048 | /* Virtual-Link print */ | |
9049 | for (ALL_LIST_ELEMENTS_RO(ospf->vlinks, node, vl_data)) { | |
9050 | struct listnode *n2; | |
9051 | struct crypt_key *ck; | |
9052 | struct ospf_interface *oi; | |
9053 | ||
9054 | if (vl_data != NULL) { | |
9055 | memset(buf, 0, INET_ADDRSTRLEN); | |
9056 | ||
9057 | area_id2str(buf, sizeof(buf), &vl_data->vl_area_id, | |
9058 | vl_data->vl_area_id_fmt); | |
9059 | oi = vl_data->vl_oi; | |
9060 | ||
9061 | /* timers */ | |
9062 | if (OSPF_IF_PARAM(oi, v_hello) | |
9063 | != OSPF_HELLO_INTERVAL_DEFAULT | |
9064 | || OSPF_IF_PARAM(oi, v_wait) | |
9065 | != OSPF_ROUTER_DEAD_INTERVAL_DEFAULT | |
9066 | || OSPF_IF_PARAM(oi, retransmit_interval) | |
9067 | != OSPF_RETRANSMIT_INTERVAL_DEFAULT | |
9068 | || OSPF_IF_PARAM(oi, transmit_delay) | |
9069 | != OSPF_TRANSMIT_DELAY_DEFAULT) | |
9070 | vty_out(vty, | |
9071 | " area %s virtual-link %s hello-interval %d retransmit-interval %d transmit-delay %d dead-interval %d\n", | |
9072 | buf, inet_ntoa(vl_data->vl_peer), | |
9073 | OSPF_IF_PARAM(oi, v_hello), | |
9074 | OSPF_IF_PARAM(oi, retransmit_interval), | |
9075 | OSPF_IF_PARAM(oi, transmit_delay), | |
9076 | OSPF_IF_PARAM(oi, v_wait)); | |
9077 | else | |
9078 | vty_out(vty, " area %s virtual-link %s\n", buf, | |
9079 | inet_ntoa(vl_data->vl_peer)); | |
9080 | /* Auth key */ | |
9081 | if (IF_DEF_PARAMS(vl_data->vl_oi->ifp)->auth_simple[0] | |
9082 | != '\0') | |
9083 | vty_out(vty, | |
9084 | " area %s virtual-link %s authentication-key %s\n", | |
9085 | buf, inet_ntoa(vl_data->vl_peer), | |
9086 | IF_DEF_PARAMS(vl_data->vl_oi->ifp) | |
9087 | ->auth_simple); | |
9088 | /* md5 keys */ | |
9089 | for (ALL_LIST_ELEMENTS_RO( | |
9090 | IF_DEF_PARAMS(vl_data->vl_oi->ifp) | |
9091 | ->auth_crypt, | |
9092 | n2, ck)) | |
9093 | vty_out(vty, | |
9094 | " area %s virtual-link %s" | |
9095 | " message-digest-key %d md5 %s\n", | |
9096 | buf, inet_ntoa(vl_data->vl_peer), | |
9097 | ck->key_id, ck->auth_key); | |
9098 | } | |
9099 | } | |
9100 | ||
9101 | return 0; | |
718e3744 | 9102 | } |
9103 | ||
6b0655a2 | 9104 | |
d62a17ae | 9105 | static int config_write_ospf_redistribute(struct vty *vty, struct ospf *ospf) |
718e3744 | 9106 | { |
d62a17ae | 9107 | int type; |
718e3744 | 9108 | |
d62a17ae | 9109 | /* redistribute print. */ |
9110 | for (type = 0; type < ZEBRA_ROUTE_MAX; type++) { | |
9111 | struct list *red_list; | |
9112 | struct listnode *node; | |
9113 | struct ospf_redist *red; | |
718e3744 | 9114 | |
d62a17ae | 9115 | red_list = ospf->redist[type]; |
9116 | if (!red_list) | |
9117 | continue; | |
7c8ff89e | 9118 | |
d62a17ae | 9119 | for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) { |
9120 | vty_out(vty, " redistribute %s", | |
9121 | zebra_route_string(type)); | |
9122 | if (red->instance) | |
9123 | vty_out(vty, " %d", red->instance); | |
7c8ff89e | 9124 | |
d62a17ae | 9125 | if (red->dmetric.value >= 0) |
9126 | vty_out(vty, " metric %d", red->dmetric.value); | |
7c8ff89e | 9127 | |
d62a17ae | 9128 | if (red->dmetric.type == EXTERNAL_METRIC_TYPE_1) |
9129 | vty_out(vty, " metric-type 1"); | |
7c8ff89e | 9130 | |
d62a17ae | 9131 | if (ROUTEMAP_NAME(red)) |
9132 | vty_out(vty, " route-map %s", | |
9133 | ROUTEMAP_NAME(red)); | |
7c8ff89e | 9134 | |
d62a17ae | 9135 | vty_out(vty, "\n"); |
9136 | } | |
9137 | } | |
718e3744 | 9138 | |
d62a17ae | 9139 | return 0; |
718e3744 | 9140 | } |
9141 | ||
d62a17ae | 9142 | static int config_write_ospf_default_metric(struct vty *vty, struct ospf *ospf) |
718e3744 | 9143 | { |
d62a17ae | 9144 | if (ospf->default_metric != -1) |
9145 | vty_out(vty, " default-metric %d\n", ospf->default_metric); | |
9146 | return 0; | |
718e3744 | 9147 | } |
9148 | ||
d62a17ae | 9149 | static int config_write_ospf_distribute(struct vty *vty, struct ospf *ospf) |
9150 | { | |
9151 | int type; | |
9152 | struct ospf_redist *red; | |
718e3744 | 9153 | |
d62a17ae | 9154 | if (ospf) { |
9155 | /* distribute-list print. */ | |
9156 | for (type = 0; type < ZEBRA_ROUTE_MAX; type++) | |
9157 | if (DISTRIBUTE_NAME(ospf, type)) | |
9158 | vty_out(vty, " distribute-list %s out %s\n", | |
9159 | DISTRIBUTE_NAME(ospf, type), | |
9160 | zebra_route_string(type)); | |
7c8ff89e | 9161 | |
d62a17ae | 9162 | /* default-information print. */ |
9163 | if (ospf->default_originate != DEFAULT_ORIGINATE_NONE) { | |
9164 | vty_out(vty, " default-information originate"); | |
9165 | if (ospf->default_originate == DEFAULT_ORIGINATE_ALWAYS) | |
9166 | vty_out(vty, " always"); | |
718e3744 | 9167 | |
d62a17ae | 9168 | red = ospf_redist_lookup(ospf, DEFAULT_ROUTE, 0); |
9169 | if (red) { | |
9170 | if (red->dmetric.value >= 0) | |
9171 | vty_out(vty, " metric %d", | |
9172 | red->dmetric.value); | |
9173 | if (red->dmetric.type == EXTERNAL_METRIC_TYPE_1) | |
9174 | vty_out(vty, " metric-type 1"); | |
718e3744 | 9175 | |
d62a17ae | 9176 | if (ROUTEMAP_NAME(red)) |
9177 | vty_out(vty, " route-map %s", | |
9178 | ROUTEMAP_NAME(red)); | |
9179 | } | |
9180 | ||
9181 | vty_out(vty, "\n"); | |
9182 | } | |
9183 | } | |
9184 | ||
9185 | return 0; | |
718e3744 | 9186 | } |
9187 | ||
d62a17ae | 9188 | static int config_write_ospf_distance(struct vty *vty, struct ospf *ospf) |
9189 | { | |
9190 | struct route_node *rn; | |
9191 | struct ospf_distance *odistance; | |
9192 | ||
9193 | if (ospf->distance_all) | |
9194 | vty_out(vty, " distance %d\n", ospf->distance_all); | |
9195 | ||
9196 | if (ospf->distance_intra || ospf->distance_inter | |
9197 | || ospf->distance_external) { | |
9198 | vty_out(vty, " distance ospf"); | |
9199 | ||
9200 | if (ospf->distance_intra) | |
9201 | vty_out(vty, " intra-area %d", ospf->distance_intra); | |
9202 | if (ospf->distance_inter) | |
9203 | vty_out(vty, " inter-area %d", ospf->distance_inter); | |
9204 | if (ospf->distance_external) | |
9205 | vty_out(vty, " external %d", ospf->distance_external); | |
9206 | ||
9207 | vty_out(vty, "\n"); | |
9208 | } | |
9209 | ||
9210 | for (rn = route_top(ospf->distance_table); rn; rn = route_next(rn)) | |
9211 | if ((odistance = rn->info) != NULL) { | |
9212 | vty_out(vty, " distance %d %s/%d %s\n", | |
9213 | odistance->distance, inet_ntoa(rn->p.u.prefix4), | |
9214 | rn->p.prefixlen, | |
9215 | odistance->access_list ? odistance->access_list | |
9216 | : ""); | |
9217 | } | |
9218 | return 0; | |
718e3744 | 9219 | } |
9220 | ||
43b8d1d8 | 9221 | static int ospf_config_write_one(struct vty *vty, struct ospf *ospf) |
d62a17ae | 9222 | { |
d62a17ae | 9223 | struct interface *ifp; |
9224 | struct ospf_interface *oi; | |
43b8d1d8 | 9225 | struct listnode *node = NULL; |
d62a17ae | 9226 | int write = 0; |
9227 | ||
43b8d1d8 CS |
9228 | /* `router ospf' print. */ |
9229 | if (ospf->instance && ospf->name) { | |
9230 | vty_out(vty, "router ospf %d vrf %s\n", | |
9231 | ospf->instance, ospf->name); | |
9232 | } else if (ospf->instance) { | |
9233 | vty_out(vty, "router ospf %d\n", | |
9234 | ospf->instance); | |
9235 | } else if (ospf->name) { | |
9236 | vty_out(vty, "router ospf vrf %s\n", | |
9237 | ospf->name); | |
9238 | } else | |
9239 | vty_out(vty, "router ospf\n"); | |
9240 | ||
9241 | if (!ospf->networks) { | |
9242 | write++; | |
b5a8894d | 9243 | return write; |
43b8d1d8 | 9244 | } |
d62a17ae | 9245 | |
43b8d1d8 CS |
9246 | /* Router ID print. */ |
9247 | if (ospf->router_id_static.s_addr != 0) | |
9248 | vty_out(vty, " ospf router-id %s\n", | |
9249 | inet_ntoa(ospf->router_id_static)); | |
d62a17ae | 9250 | |
43b8d1d8 CS |
9251 | /* ABR type print. */ |
9252 | if (ospf->abr_type != OSPF_ABR_DEFAULT) | |
9253 | vty_out(vty, " ospf abr-type %s\n", | |
9254 | ospf_abr_type_str[ospf->abr_type]); | |
b5a8894d | 9255 | |
43b8d1d8 CS |
9256 | /* log-adjacency-changes flag print. */ |
9257 | if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES)) { | |
9258 | if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL)) | |
9259 | vty_out(vty, " log-adjacency-changes detail\n"); | |
9260 | else if (!DFLT_OSPF_LOG_ADJACENCY_CHANGES) | |
9261 | vty_out(vty, " log-adjacency-changes\n"); | |
9262 | } else if (DFLT_OSPF_LOG_ADJACENCY_CHANGES) { | |
9263 | vty_out(vty, " no log-adjacency-changes\n"); | |
9264 | } | |
b5a8894d | 9265 | |
43b8d1d8 CS |
9266 | /* RFC1583 compatibility flag print -- Compatible with CISCO |
9267 | * 12.1. */ | |
9268 | if (CHECK_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE)) | |
9269 | vty_out(vty, " compatible rfc1583\n"); | |
d62a17ae | 9270 | |
43b8d1d8 CS |
9271 | /* auto-cost reference-bandwidth configuration. */ |
9272 | if (ospf->ref_bandwidth != OSPF_DEFAULT_REF_BANDWIDTH) { | |
9273 | vty_out(vty, | |
9274 | "! Important: ensure reference bandwidth " | |
9275 | "is consistent across all routers\n"); | |
9276 | vty_out(vty, " auto-cost reference-bandwidth %d\n", | |
9277 | ospf->ref_bandwidth); | |
9278 | } | |
d62a17ae | 9279 | |
43b8d1d8 CS |
9280 | /* SPF timers print. */ |
9281 | if (ospf->spf_delay != OSPF_SPF_DELAY_DEFAULT | |
9282 | || ospf->spf_holdtime != OSPF_SPF_HOLDTIME_DEFAULT | |
9283 | || ospf->spf_max_holdtime != OSPF_SPF_MAX_HOLDTIME_DEFAULT) | |
9284 | vty_out(vty, " timers throttle spf %d %d %d\n", | |
9285 | ospf->spf_delay, ospf->spf_holdtime, | |
9286 | ospf->spf_max_holdtime); | |
9287 | ||
9288 | /* LSA timers print. */ | |
9289 | if (ospf->min_ls_interval != OSPF_MIN_LS_INTERVAL) | |
9290 | vty_out(vty, " timers throttle lsa all %d\n", | |
9291 | ospf->min_ls_interval); | |
9292 | if (ospf->min_ls_arrival != OSPF_MIN_LS_ARRIVAL) | |
9293 | vty_out(vty, " timers lsa min-arrival %d\n", | |
9294 | ospf->min_ls_arrival); | |
9295 | ||
9296 | /* Write multiplier print. */ | |
9297 | if (ospf->write_oi_count != OSPF_WRITE_INTERFACE_COUNT_DEFAULT) | |
9298 | vty_out(vty, " ospf write-multiplier %d\n", | |
9299 | ospf->write_oi_count); | |
d62a17ae | 9300 | |
43b8d1d8 CS |
9301 | /* Max-metric router-lsa print */ |
9302 | config_write_stub_router(vty, ospf); | |
d62a17ae | 9303 | |
43b8d1d8 CS |
9304 | /* SPF refresh parameters print. */ |
9305 | if (ospf->lsa_refresh_interval | |
9306 | != OSPF_LSA_REFRESH_INTERVAL_DEFAULT) | |
9307 | vty_out(vty, " refresh timer %d\n", | |
9308 | ospf->lsa_refresh_interval); | |
d62a17ae | 9309 | |
43b8d1d8 CS |
9310 | /* Redistribute information print. */ |
9311 | config_write_ospf_redistribute(vty, ospf); | |
d62a17ae | 9312 | |
43b8d1d8 CS |
9313 | /* passive-interface print. */ |
9314 | if (ospf->passive_interface_default == OSPF_IF_PASSIVE) | |
9315 | vty_out(vty, " passive-interface default\n"); | |
d62a17ae | 9316 | |
43b8d1d8 CS |
9317 | for (ALL_LIST_ELEMENTS_RO(om->iflist, node, ifp)) |
9318 | if (OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(ifp), | |
9319 | passive_interface) | |
9320 | && IF_DEF_PARAMS(ifp)->passive_interface | |
9321 | != ospf->passive_interface_default) { | |
9322 | vty_out(vty, " %spassive-interface %s\n", | |
9323 | IF_DEF_PARAMS(ifp)->passive_interface | |
9324 | ? "" | |
9325 | : "no ", | |
9326 | ifp->name); | |
9327 | } | |
9328 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) { | |
9329 | if (!OSPF_IF_PARAM_CONFIGURED(oi->params, | |
9330 | passive_interface)) | |
9331 | continue; | |
9332 | if (OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(oi->ifp), | |
9333 | passive_interface)) { | |
9334 | if (oi->params->passive_interface | |
9335 | == IF_DEF_PARAMS(oi->ifp) | |
9336 | ->passive_interface) | |
9337 | continue; | |
9338 | } else if (oi->params->passive_interface | |
9339 | == ospf->passive_interface_default) | |
9340 | continue; | |
d62a17ae | 9341 | |
43b8d1d8 CS |
9342 | vty_out(vty, " %spassive-interface %s %s\n", |
9343 | oi->params->passive_interface ? "" : "no ", | |
9344 | oi->ifp->name, | |
9345 | inet_ntoa(oi->address->u.prefix4)); | |
9346 | } | |
d62a17ae | 9347 | |
43b8d1d8 CS |
9348 | /* Network area print. */ |
9349 | config_write_network_area(vty, ospf); | |
d62a17ae | 9350 | |
43b8d1d8 CS |
9351 | /* Area config print. */ |
9352 | config_write_ospf_area(vty, ospf); | |
d62a17ae | 9353 | |
43b8d1d8 CS |
9354 | /* static neighbor print. */ |
9355 | config_write_ospf_nbr_nbma(vty, ospf); | |
9356 | ||
9357 | /* Virtual-Link print. */ | |
9358 | config_write_virtual_link(vty, ospf); | |
9359 | ||
9360 | /* Default metric configuration. */ | |
9361 | config_write_ospf_default_metric(vty, ospf); | |
9362 | ||
9363 | /* Distribute-list and default-information print. */ | |
9364 | config_write_ospf_distribute(vty, ospf); | |
9365 | ||
9366 | /* Distance configuration. */ | |
9367 | config_write_ospf_distance(vty, ospf); | |
9368 | ||
9369 | ospf_opaque_config_write_router(vty, ospf); | |
9370 | ||
9371 | write++; | |
9372 | return write; | |
9373 | } | |
9374 | ||
9375 | /* OSPF configuration write function. */ | |
9376 | static int ospf_config_write(struct vty *vty) | |
9377 | { | |
9378 | struct ospf *ospf; | |
9379 | struct listnode *ospf_node = NULL; | |
9380 | int write = 0; | |
9381 | ||
9382 | if (listcount(om->ospf) == 0) | |
9383 | return write; | |
9384 | ||
9385 | for (ALL_LIST_ELEMENTS_RO(om->ospf, ospf_node, ospf)) { | |
9386 | if (ospf->oi_running) | |
9387 | write += ospf_config_write_one(vty, ospf); | |
b5a8894d | 9388 | } |
d62a17ae | 9389 | return write; |
9390 | } | |
9391 | ||
9392 | void ospf_vty_show_init(void) | |
9393 | { | |
9394 | /* "show ip ospf" commands. */ | |
9395 | install_element(VIEW_NODE, &show_ip_ospf_cmd); | |
9396 | ||
9397 | install_element(VIEW_NODE, &show_ip_ospf_instance_cmd); | |
9398 | ||
9399 | /* "show ip ospf database" commands. */ | |
9400 | install_element(VIEW_NODE, &show_ip_ospf_database_max_cmd); | |
9401 | ||
9402 | install_element(VIEW_NODE, | |
9403 | &show_ip_ospf_instance_database_type_adv_router_cmd); | |
9404 | install_element(VIEW_NODE, &show_ip_ospf_instance_database_cmd); | |
9405 | install_element(VIEW_NODE, &show_ip_ospf_instance_database_max_cmd); | |
9406 | ||
9407 | /* "show ip ospf interface" commands. */ | |
9408 | install_element(VIEW_NODE, &show_ip_ospf_interface_cmd); | |
9409 | ||
9410 | install_element(VIEW_NODE, &show_ip_ospf_instance_interface_cmd); | |
9411 | ||
9412 | /* "show ip ospf neighbor" commands. */ | |
9413 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_int_detail_cmd); | |
9414 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_int_cmd); | |
9415 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_id_cmd); | |
9416 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_detail_all_cmd); | |
9417 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_detail_cmd); | |
9418 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_cmd); | |
9419 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_all_cmd); | |
9420 | ||
9421 | install_element(VIEW_NODE, | |
9422 | &show_ip_ospf_instance_neighbor_int_detail_cmd); | |
9423 | install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_int_cmd); | |
9424 | install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_id_cmd); | |
9425 | install_element(VIEW_NODE, | |
9426 | &show_ip_ospf_instance_neighbor_detail_all_cmd); | |
9427 | install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_detail_cmd); | |
9428 | install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_cmd); | |
9429 | install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_all_cmd); | |
9430 | ||
9431 | /* "show ip ospf route" commands. */ | |
9432 | install_element(VIEW_NODE, &show_ip_ospf_route_cmd); | |
9433 | install_element(VIEW_NODE, &show_ip_ospf_border_routers_cmd); | |
9434 | ||
9435 | install_element(VIEW_NODE, &show_ip_ospf_instance_route_cmd); | |
9436 | install_element(VIEW_NODE, &show_ip_ospf_instance_border_routers_cmd); | |
b5a8894d CS |
9437 | |
9438 | /* "show ip ospf vrfs" commands. */ | |
9439 | install_element(VIEW_NODE, &show_ip_ospf_vrfs_cmd); | |
718e3744 | 9440 | } |
9441 | ||
6b0655a2 | 9442 | |
718e3744 | 9443 | /* ospfd's interface node. */ |
d62a17ae | 9444 | static struct cmd_node interface_node = {INTERFACE_NODE, "%s(config-if)# ", 1}; |
718e3744 | 9445 | |
9446 | /* Initialization of OSPF interface. */ | |
d62a17ae | 9447 | static void ospf_vty_if_init(void) |
9448 | { | |
9449 | /* Install interface node. */ | |
9450 | install_node(&interface_node, config_write_interface); | |
9451 | if_cmd_init(); | |
9452 | ||
9453 | /* "ip ospf authentication" commands. */ | |
9454 | install_element(INTERFACE_NODE, &ip_ospf_authentication_args_addr_cmd); | |
9455 | install_element(INTERFACE_NODE, &ip_ospf_authentication_addr_cmd); | |
9456 | install_element(INTERFACE_NODE, | |
9457 | &no_ip_ospf_authentication_args_addr_cmd); | |
9458 | install_element(INTERFACE_NODE, &no_ip_ospf_authentication_addr_cmd); | |
9459 | install_element(INTERFACE_NODE, &ip_ospf_authentication_key_addr_cmd); | |
9460 | install_element(INTERFACE_NODE, | |
9461 | &no_ip_ospf_authentication_key_authkey_addr_cmd); | |
9462 | install_element(INTERFACE_NODE, | |
9463 | &no_ospf_authentication_key_authkey_addr_cmd); | |
9464 | ||
9465 | /* "ip ospf message-digest-key" commands. */ | |
9466 | install_element(INTERFACE_NODE, &ip_ospf_message_digest_key_cmd); | |
9467 | install_element(INTERFACE_NODE, &no_ip_ospf_message_digest_key_cmd); | |
9468 | ||
9469 | /* "ip ospf cost" commands. */ | |
9470 | install_element(INTERFACE_NODE, &ip_ospf_cost_cmd); | |
9471 | install_element(INTERFACE_NODE, &no_ip_ospf_cost_cmd); | |
9472 | ||
9473 | /* "ip ospf mtu-ignore" commands. */ | |
9474 | install_element(INTERFACE_NODE, &ip_ospf_mtu_ignore_addr_cmd); | |
9475 | install_element(INTERFACE_NODE, &no_ip_ospf_mtu_ignore_addr_cmd); | |
9476 | ||
9477 | /* "ip ospf dead-interval" commands. */ | |
9478 | install_element(INTERFACE_NODE, &ip_ospf_dead_interval_cmd); | |
9479 | install_element(INTERFACE_NODE, | |
9480 | &ip_ospf_dead_interval_minimal_addr_cmd); | |
9481 | install_element(INTERFACE_NODE, &no_ip_ospf_dead_interval_cmd); | |
9482 | ||
9483 | /* "ip ospf hello-interval" commands. */ | |
9484 | install_element(INTERFACE_NODE, &ip_ospf_hello_interval_cmd); | |
9485 | install_element(INTERFACE_NODE, &no_ip_ospf_hello_interval_cmd); | |
9486 | ||
9487 | /* "ip ospf network" commands. */ | |
9488 | install_element(INTERFACE_NODE, &ip_ospf_network_cmd); | |
9489 | install_element(INTERFACE_NODE, &no_ip_ospf_network_cmd); | |
9490 | ||
9491 | /* "ip ospf priority" commands. */ | |
9492 | install_element(INTERFACE_NODE, &ip_ospf_priority_cmd); | |
9493 | install_element(INTERFACE_NODE, &no_ip_ospf_priority_cmd); | |
9494 | ||
9495 | /* "ip ospf retransmit-interval" commands. */ | |
9496 | install_element(INTERFACE_NODE, &ip_ospf_retransmit_interval_addr_cmd); | |
9497 | install_element(INTERFACE_NODE, | |
9498 | &no_ip_ospf_retransmit_interval_addr_cmd); | |
9499 | ||
9500 | /* "ip ospf transmit-delay" commands. */ | |
9501 | install_element(INTERFACE_NODE, &ip_ospf_transmit_delay_addr_cmd); | |
9502 | install_element(INTERFACE_NODE, &no_ip_ospf_transmit_delay_addr_cmd); | |
9503 | ||
9504 | /* "ip ospf area" commands. */ | |
9505 | install_element(INTERFACE_NODE, &ip_ospf_area_cmd); | |
9506 | install_element(INTERFACE_NODE, &no_ip_ospf_area_cmd); | |
9507 | ||
9508 | /* These commands are compatibitliy for previous version. */ | |
9509 | install_element(INTERFACE_NODE, &ospf_authentication_key_cmd); | |
9510 | install_element(INTERFACE_NODE, &ospf_message_digest_key_cmd); | |
9511 | install_element(INTERFACE_NODE, &no_ospf_message_digest_key_cmd); | |
9512 | install_element(INTERFACE_NODE, &ospf_dead_interval_cmd); | |
9513 | install_element(INTERFACE_NODE, &no_ospf_dead_interval_cmd); | |
9514 | install_element(INTERFACE_NODE, &ospf_hello_interval_cmd); | |
9515 | install_element(INTERFACE_NODE, &no_ospf_hello_interval_cmd); | |
9516 | install_element(INTERFACE_NODE, &ospf_cost_cmd); | |
9517 | install_element(INTERFACE_NODE, &no_ospf_cost_cmd); | |
9518 | install_element(INTERFACE_NODE, &ospf_network_cmd); | |
9519 | install_element(INTERFACE_NODE, &no_ospf_network_cmd); | |
9520 | install_element(INTERFACE_NODE, &ospf_priority_cmd); | |
9521 | install_element(INTERFACE_NODE, &no_ospf_priority_cmd); | |
9522 | install_element(INTERFACE_NODE, &ospf_retransmit_interval_cmd); | |
9523 | install_element(INTERFACE_NODE, &no_ospf_retransmit_interval_cmd); | |
9524 | install_element(INTERFACE_NODE, &ospf_transmit_delay_cmd); | |
9525 | install_element(INTERFACE_NODE, &no_ospf_transmit_delay_cmd); | |
9526 | } | |
9527 | ||
9528 | static void ospf_vty_zebra_init(void) | |
9529 | { | |
9530 | install_element(OSPF_NODE, &ospf_redistribute_source_cmd); | |
9531 | install_element(OSPF_NODE, &no_ospf_redistribute_source_cmd); | |
9532 | install_element(OSPF_NODE, &ospf_redistribute_instance_source_cmd); | |
9533 | install_element(OSPF_NODE, &no_ospf_redistribute_instance_source_cmd); | |
9534 | ||
9535 | install_element(OSPF_NODE, &ospf_distribute_list_out_cmd); | |
9536 | install_element(OSPF_NODE, &no_ospf_distribute_list_out_cmd); | |
9537 | ||
9538 | install_element(OSPF_NODE, &ospf_default_information_originate_cmd); | |
9539 | install_element(OSPF_NODE, &no_ospf_default_information_originate_cmd); | |
9540 | ||
9541 | install_element(OSPF_NODE, &ospf_default_metric_cmd); | |
9542 | install_element(OSPF_NODE, &no_ospf_default_metric_cmd); | |
9543 | ||
9544 | install_element(OSPF_NODE, &ospf_distance_cmd); | |
9545 | install_element(OSPF_NODE, &no_ospf_distance_cmd); | |
9546 | install_element(OSPF_NODE, &no_ospf_distance_ospf_cmd); | |
9547 | install_element(OSPF_NODE, &ospf_distance_ospf_cmd); | |
718e3744 | 9548 | #if 0 |
9549 | install_element (OSPF_NODE, &ospf_distance_source_cmd); | |
9550 | install_element (OSPF_NODE, &no_ospf_distance_source_cmd); | |
9551 | install_element (OSPF_NODE, &ospf_distance_source_access_list_cmd); | |
9552 | install_element (OSPF_NODE, &no_ospf_distance_source_access_list_cmd); | |
9553 | #endif /* 0 */ | |
9554 | } | |
9555 | ||
d62a17ae | 9556 | static struct cmd_node ospf_node = {OSPF_NODE, "%s(config-router)# ", 1}; |
718e3744 | 9557 | |
d62a17ae | 9558 | static void ospf_interface_clear(struct interface *ifp) |
09f35f8c | 9559 | { |
d62a17ae | 9560 | if (!if_is_operative(ifp)) |
9561 | return; | |
09f35f8c | 9562 | |
d62a17ae | 9563 | if (IS_DEBUG_OSPF(ism, ISM_EVENTS)) |
9564 | zlog_debug("ISM[%s]: clear by reset", ifp->name); | |
09f35f8c | 9565 | |
d62a17ae | 9566 | ospf_if_reset(ifp); |
09f35f8c DS |
9567 | } |
9568 | ||
9569 | DEFUN (clear_ip_ospf_interface, | |
9570 | clear_ip_ospf_interface_cmd, | |
9571 | "clear ip ospf interface [IFNAME]", | |
9572 | CLEAR_STR | |
9573 | IP_STR | |
9574 | "OSPF information\n" | |
9575 | "Interface information\n" | |
9576 | "Interface name\n") | |
9577 | { | |
d62a17ae | 9578 | int idx_ifname = 4; |
9579 | struct interface *ifp; | |
b5a8894d CS |
9580 | struct listnode *node, *n1; |
9581 | struct ospf *ospf = NULL; | |
09f35f8c | 9582 | |
d62a17ae | 9583 | if (argc == 4) /* Clear all the ospfv2 interfaces. */ |
9584 | { | |
b5a8894d CS |
9585 | for (ALL_LIST_ELEMENTS_RO(om->ospf, n1, ospf)) { |
9586 | for (ALL_LIST_ELEMENTS_RO(vrf_iflist(ospf->vrf_id), | |
9587 | node, ifp)) | |
9588 | ospf_interface_clear(ifp); | |
9589 | } | |
9590 | } else { | |
9591 | /* Interface name is specified. */ | |
9592 | ifp = if_lookup_by_name_all_vrf(argv[idx_ifname]->arg); | |
9593 | if (ifp == NULL) | |
d62a17ae | 9594 | vty_out(vty, "No such interface name\n"); |
9595 | else | |
9596 | ospf_interface_clear(ifp); | |
9597 | } | |
9598 | ||
9599 | return CMD_SUCCESS; | |
09f35f8c DS |
9600 | } |
9601 | ||
d62a17ae | 9602 | void ospf_vty_clear_init(void) |
09f35f8c | 9603 | { |
d62a17ae | 9604 | install_element(ENABLE_NODE, &clear_ip_ospf_interface_cmd); |
09f35f8c DS |
9605 | } |
9606 | ||
6b0655a2 | 9607 | |
718e3744 | 9608 | /* Install OSPF related vty commands. */ |
d62a17ae | 9609 | void ospf_vty_init(void) |
9610 | { | |
9611 | /* Install ospf top node. */ | |
9612 | install_node(&ospf_node, ospf_config_write); | |
9613 | ||
9614 | /* "router ospf" commands. */ | |
9615 | install_element(CONFIG_NODE, &router_ospf_cmd); | |
9616 | install_element(CONFIG_NODE, &no_router_ospf_cmd); | |
9617 | ||
9618 | ||
9619 | install_default(OSPF_NODE); | |
9620 | ||
9621 | /* "ospf router-id" commands. */ | |
9622 | install_element(OSPF_NODE, &ospf_router_id_cmd); | |
9623 | install_element(OSPF_NODE, &ospf_router_id_old_cmd); | |
9624 | install_element(OSPF_NODE, &no_ospf_router_id_cmd); | |
9625 | ||
9626 | /* "passive-interface" commands. */ | |
9627 | install_element(OSPF_NODE, &ospf_passive_interface_addr_cmd); | |
9628 | install_element(OSPF_NODE, &no_ospf_passive_interface_addr_cmd); | |
9629 | ||
9630 | /* "ospf abr-type" commands. */ | |
9631 | install_element(OSPF_NODE, &ospf_abr_type_cmd); | |
9632 | install_element(OSPF_NODE, &no_ospf_abr_type_cmd); | |
9633 | ||
9634 | /* "ospf log-adjacency-changes" commands. */ | |
9635 | install_element(OSPF_NODE, &ospf_log_adjacency_changes_cmd); | |
9636 | install_element(OSPF_NODE, &ospf_log_adjacency_changes_detail_cmd); | |
9637 | install_element(OSPF_NODE, &no_ospf_log_adjacency_changes_cmd); | |
9638 | install_element(OSPF_NODE, &no_ospf_log_adjacency_changes_detail_cmd); | |
9639 | ||
9640 | /* "ospf rfc1583-compatible" commands. */ | |
9641 | install_element(OSPF_NODE, &ospf_compatible_rfc1583_cmd); | |
9642 | install_element(OSPF_NODE, &no_ospf_compatible_rfc1583_cmd); | |
9643 | install_element(OSPF_NODE, &ospf_rfc1583_flag_cmd); | |
9644 | install_element(OSPF_NODE, &no_ospf_rfc1583_flag_cmd); | |
9645 | ||
9646 | /* "network area" commands. */ | |
9647 | install_element(OSPF_NODE, &ospf_network_area_cmd); | |
9648 | install_element(OSPF_NODE, &no_ospf_network_area_cmd); | |
9649 | ||
9650 | /* "area authentication" commands. */ | |
9651 | install_element(OSPF_NODE, | |
9652 | &ospf_area_authentication_message_digest_cmd); | |
9653 | install_element(OSPF_NODE, &ospf_area_authentication_cmd); | |
9654 | install_element(OSPF_NODE, &no_ospf_area_authentication_cmd); | |
9655 | ||
9656 | /* "area range" commands. */ | |
9657 | install_element(OSPF_NODE, &ospf_area_range_cmd); | |
9658 | install_element(OSPF_NODE, &ospf_area_range_cost_cmd); | |
9659 | install_element(OSPF_NODE, &ospf_area_range_not_advertise_cmd); | |
9660 | install_element(OSPF_NODE, &no_ospf_area_range_cmd); | |
9661 | install_element(OSPF_NODE, &ospf_area_range_substitute_cmd); | |
9662 | install_element(OSPF_NODE, &no_ospf_area_range_substitute_cmd); | |
9663 | ||
9664 | /* "area virtual-link" commands. */ | |
9665 | install_element(OSPF_NODE, &ospf_area_vlink_cmd); | |
9666 | install_element(OSPF_NODE, &ospf_area_vlink_intervals_cmd); | |
9667 | install_element(OSPF_NODE, &no_ospf_area_vlink_cmd); | |
9668 | install_element(OSPF_NODE, &no_ospf_area_vlink_intervals_cmd); | |
9669 | ||
9670 | ||
9671 | /* "area stub" commands. */ | |
9672 | install_element(OSPF_NODE, &ospf_area_stub_no_summary_cmd); | |
9673 | install_element(OSPF_NODE, &ospf_area_stub_cmd); | |
9674 | install_element(OSPF_NODE, &no_ospf_area_stub_no_summary_cmd); | |
9675 | install_element(OSPF_NODE, &no_ospf_area_stub_cmd); | |
9676 | ||
9677 | /* "area nssa" commands. */ | |
9678 | install_element(OSPF_NODE, &ospf_area_nssa_cmd); | |
9679 | install_element(OSPF_NODE, &ospf_area_nssa_translate_no_summary_cmd); | |
9680 | install_element(OSPF_NODE, &ospf_area_nssa_translate_cmd); | |
9681 | install_element(OSPF_NODE, &ospf_area_nssa_no_summary_cmd); | |
9682 | install_element(OSPF_NODE, &no_ospf_area_nssa_cmd); | |
9683 | ||
9684 | install_element(OSPF_NODE, &ospf_area_default_cost_cmd); | |
9685 | install_element(OSPF_NODE, &no_ospf_area_default_cost_cmd); | |
9686 | ||
9687 | install_element(OSPF_NODE, &ospf_area_shortcut_cmd); | |
9688 | install_element(OSPF_NODE, &no_ospf_area_shortcut_cmd); | |
9689 | ||
9690 | install_element(OSPF_NODE, &ospf_area_export_list_cmd); | |
9691 | install_element(OSPF_NODE, &no_ospf_area_export_list_cmd); | |
9692 | ||
9693 | install_element(OSPF_NODE, &ospf_area_filter_list_cmd); | |
9694 | install_element(OSPF_NODE, &no_ospf_area_filter_list_cmd); | |
9695 | ||
9696 | install_element(OSPF_NODE, &ospf_area_import_list_cmd); | |
9697 | install_element(OSPF_NODE, &no_ospf_area_import_list_cmd); | |
9698 | ||
9699 | /* SPF timer commands */ | |
9700 | install_element(OSPF_NODE, &ospf_timers_throttle_spf_cmd); | |
9701 | install_element(OSPF_NODE, &no_ospf_timers_throttle_spf_cmd); | |
9702 | ||
9703 | /* LSA timers commands */ | |
9704 | install_element(OSPF_NODE, &ospf_timers_min_ls_interval_cmd); | |
9705 | install_element(OSPF_NODE, &no_ospf_timers_min_ls_interval_cmd); | |
0e88de35 QY |
9706 | install_element(OSPF_NODE, &ospf_timers_lsa_min_arrival_cmd); |
9707 | install_element(OSPF_NODE, &no_ospf_timers_lsa_min_arrival_cmd); | |
9708 | install_element(OSPF_NODE, &ospf_timers_lsa_arrival_cmd); | |
9709 | install_element(OSPF_NODE, &no_ospf_timers_lsa_arrival_cmd); | |
d62a17ae | 9710 | |
9711 | /* refresh timer commands */ | |
9712 | install_element(OSPF_NODE, &ospf_refresh_timer_cmd); | |
9713 | install_element(OSPF_NODE, &no_ospf_refresh_timer_val_cmd); | |
9714 | ||
9715 | /* max-metric commands */ | |
9716 | install_element(OSPF_NODE, &ospf_max_metric_router_lsa_admin_cmd); | |
9717 | install_element(OSPF_NODE, &no_ospf_max_metric_router_lsa_admin_cmd); | |
9718 | install_element(OSPF_NODE, &ospf_max_metric_router_lsa_startup_cmd); | |
9719 | install_element(OSPF_NODE, &no_ospf_max_metric_router_lsa_startup_cmd); | |
9720 | install_element(OSPF_NODE, &ospf_max_metric_router_lsa_shutdown_cmd); | |
9721 | install_element(OSPF_NODE, &no_ospf_max_metric_router_lsa_shutdown_cmd); | |
9722 | ||
9723 | /* reference bandwidth commands */ | |
9724 | install_element(OSPF_NODE, &ospf_auto_cost_reference_bandwidth_cmd); | |
9725 | install_element(OSPF_NODE, &no_ospf_auto_cost_reference_bandwidth_cmd); | |
9726 | ||
9727 | /* "neighbor" commands. */ | |
9728 | install_element(OSPF_NODE, &ospf_neighbor_cmd); | |
9729 | install_element(OSPF_NODE, &ospf_neighbor_poll_interval_cmd); | |
9730 | install_element(OSPF_NODE, &no_ospf_neighbor_cmd); | |
9731 | install_element(OSPF_NODE, &no_ospf_neighbor_poll_cmd); | |
9732 | ||
9733 | /* write multiplier commands */ | |
9734 | install_element(OSPF_NODE, &ospf_write_multiplier_cmd); | |
9735 | install_element(OSPF_NODE, &write_multiplier_cmd); | |
9736 | install_element(OSPF_NODE, &no_ospf_write_multiplier_cmd); | |
9737 | install_element(OSPF_NODE, &no_write_multiplier_cmd); | |
9738 | ||
9739 | /* Init interface related vty commands. */ | |
9740 | ospf_vty_if_init(); | |
9741 | ||
9742 | /* Init zebra related vty commands. */ | |
9743 | ospf_vty_zebra_init(); | |
718e3744 | 9744 | } |