]>
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 | ||
52d0c099 CS |
174 | static void ospf_show_vrf_name(struct ospf *ospf, struct vty *vty, |
175 | json_object *json) | |
176 | { | |
177 | if (ospf->name) { | |
178 | if (json) | |
179 | json_object_string_add(json, "vrfName", ospf->name); | |
180 | else | |
181 | vty_out(vty, "VRF Name: %s\n", ospf->name); | |
182 | } | |
183 | ||
184 | } | |
185 | ||
43b8d1d8 CS |
186 | #ifndef VTYSH_EXTRACT_PL |
187 | #include "ospf_vty_clippy.c" | |
188 | #endif | |
189 | ||
190 | DEFUN_NOSH (router_ospf, | |
191 | router_ospf_cmd, | |
192 | "router ospf [{(1-65535)|vrf NAME}]", | |
193 | "Enable a routing process\n" | |
194 | "Start OSPF configuration\n" | |
195 | "Instance ID\n" | |
196 | VRF_CMD_HELP_STR) | |
197 | { | |
198 | struct ospf *ospf = NULL; | |
199 | int ret = CMD_SUCCESS; | |
200 | u_short instance = 0; | |
201 | ||
202 | ospf = ospf_cmd_lookup_ospf(vty, argv, argc, 1, &instance); | |
203 | if (!ospf) | |
204 | return CMD_WARNING_CONFIG_FAILED; | |
d62a17ae | 205 | |
d62a17ae | 206 | /* The following logic to set the vty qobj index is in place to be able |
207 | to ignore the commands which dont belong to this instance. */ | |
64ac44f6 | 208 | if (ospf->instance != instance) { |
d62a17ae | 209 | VTY_PUSH_CONTEXT_NULL(OSPF_NODE); |
64ac44f6 CS |
210 | ret = CMD_NOT_MY_INSTANCE; |
211 | } else { | |
b5a8894d CS |
212 | if (ospf->vrf_id != VRF_UNKNOWN) |
213 | ospf->oi_running = 1; | |
d62a17ae | 214 | if (IS_DEBUG_OSPF_EVENT) |
b5a8894d CS |
215 | zlog_debug("Config command 'router ospf %d' received, vrf %s id %d oi_running %u", |
216 | instance, ospf->name ? ospf->name : "NIL", | |
217 | ospf->vrf_id, ospf->oi_running); | |
d62a17ae | 218 | VTY_PUSH_CONTEXT(OSPF_NODE, ospf); |
219 | ospf_router_id_update(ospf); | |
220 | } | |
221 | ||
64ac44f6 | 222 | return ret; |
718e3744 | 223 | } |
224 | ||
225 | DEFUN (no_router_ospf, | |
226 | no_router_ospf_cmd, | |
43b8d1d8 | 227 | "no router ospf [{(1-65535)|vrf NAME}]", |
718e3744 | 228 | NO_STR |
229 | "Enable a routing process\n" | |
7a7be519 | 230 | "Start OSPF configuration\n" |
b5a8894d CS |
231 | "Instance ID\n" |
232 | VRF_CMD_HELP_STR) | |
718e3744 | 233 | { |
d62a17ae | 234 | struct ospf *ospf; |
235 | u_short instance = 0; | |
b5a8894d | 236 | |
43b8d1d8 CS |
237 | ospf = ospf_cmd_lookup_ospf(vty, argv, argc, 0, &instance); |
238 | if (ospf == NULL) { | |
239 | if (instance) | |
b5a8894d | 240 | return CMD_NOT_MY_INSTANCE; |
43b8d1d8 CS |
241 | else |
242 | return CMD_WARNING; | |
b5a8894d | 243 | } |
d62a17ae | 244 | ospf_finish(ospf); |
718e3744 | 245 | |
d62a17ae | 246 | return CMD_SUCCESS; |
718e3744 | 247 | } |
248 | ||
7c8ff89e | 249 | |
43b8d1d8 | 250 | DEFPY (ospf_router_id, |
718e3744 | 251 | ospf_router_id_cmd, |
252 | "ospf router-id A.B.C.D", | |
253 | "OSPF specific commands\n" | |
254 | "router-id for the OSPF process\n" | |
255 | "OSPF router-id in IP address format\n") | |
256 | { | |
a3d826f0 | 257 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
43b8d1d8 | 258 | |
d62a17ae | 259 | struct listnode *node; |
260 | struct ospf_area *area; | |
d62a17ae | 261 | |
262 | ospf->router_id_static = router_id; | |
263 | ||
264 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) | |
265 | if (area->full_nbrs) { | |
266 | vty_out(vty, | |
267 | "For this router-id change to take effect," | |
268 | " save config and restart ospfd\n"); | |
269 | return CMD_SUCCESS; | |
270 | } | |
271 | ||
272 | ospf_router_id_update(ospf); | |
273 | ||
274 | return CMD_SUCCESS; | |
718e3744 | 275 | } |
276 | ||
7a7be519 | 277 | DEFUN_HIDDEN (ospf_router_id_old, |
747e489c DW |
278 | ospf_router_id_old_cmd, |
279 | "router-id A.B.C.D", | |
280 | "router-id for the OSPF process\n" | |
281 | "OSPF router-id in IP address format\n") | |
7a7be519 | 282 | { |
a3d826f0 | 283 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 284 | int idx_ipv4 = 1; |
285 | struct listnode *node; | |
286 | struct ospf_area *area; | |
287 | struct in_addr router_id; | |
288 | int ret; | |
289 | ||
290 | ret = inet_aton(argv[idx_ipv4]->arg, &router_id); | |
291 | if (!ret) { | |
292 | vty_out(vty, "Please specify Router ID by A.B.C.D\n"); | |
293 | return CMD_WARNING_CONFIG_FAILED; | |
294 | } | |
7a7be519 | 295 | |
d62a17ae | 296 | ospf->router_id_static = router_id; |
297 | ||
298 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) | |
299 | if (area->full_nbrs) { | |
300 | vty_out(vty, | |
301 | "For this router-id change to take effect," | |
302 | " save config and restart ospfd\n"); | |
303 | return CMD_SUCCESS; | |
304 | } | |
305 | ||
306 | ospf_router_id_update(ospf); | |
307 | ||
308 | return CMD_SUCCESS; | |
7a7be519 | 309 | } |
747e489c | 310 | |
43b8d1d8 | 311 | DEFPY (no_ospf_router_id, |
718e3744 | 312 | no_ospf_router_id_cmd, |
7a7be519 | 313 | "no ospf router-id [A.B.C.D]", |
718e3744 | 314 | NO_STR |
315 | "OSPF specific commands\n" | |
7a7be519 | 316 | "router-id for the OSPF process\n" |
317 | "OSPF router-id in IP address format\n") | |
718e3744 | 318 | { |
a3d826f0 | 319 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 320 | struct listnode *node; |
321 | struct ospf_area *area; | |
68980084 | 322 | |
43b8d1d8 CS |
323 | if (router_id_str) { |
324 | if (!IPV4_ADDR_SAME(&ospf->router_id_static, &router_id)) { | |
325 | vty_out(vty, "%% OSPF router-id doesn't match\n"); | |
326 | return CMD_WARNING_CONFIG_FAILED; | |
327 | } | |
328 | } | |
329 | ||
d62a17ae | 330 | ospf->router_id_static.s_addr = 0; |
718e3744 | 331 | |
d62a17ae | 332 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) |
333 | if (area->full_nbrs) { | |
334 | vty_out(vty, | |
335 | "For this router-id change to take effect," | |
336 | " save config and restart ospfd\n"); | |
337 | return CMD_SUCCESS; | |
338 | } | |
2c19a6ec | 339 | |
d62a17ae | 340 | ospf_router_id_update(ospf); |
718e3744 | 341 | |
d62a17ae | 342 | return CMD_SUCCESS; |
718e3744 | 343 | } |
344 | ||
718e3744 | 345 | |
d62a17ae | 346 | static void ospf_passive_interface_default(struct ospf *ospf, u_char newval) |
347 | { | |
f4e14fdb | 348 | struct vrf *vrf = vrf_lookup_by_id(ospf->vrf_id); |
d62a17ae | 349 | struct listnode *ln; |
350 | struct interface *ifp; | |
351 | struct ospf_interface *oi; | |
352 | ||
353 | ospf->passive_interface_default = newval; | |
354 | ||
451fda4f | 355 | FOR_ALL_INTERFACES (vrf, ifp) { |
9d303b37 DL |
356 | if (ifp && OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(ifp), |
357 | passive_interface)) | |
d62a17ae | 358 | UNSET_IF_PARAM(IF_DEF_PARAMS(ifp), passive_interface); |
359 | } | |
360 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, ln, oi)) { | |
361 | if (OSPF_IF_PARAM_CONFIGURED(oi->params, passive_interface)) | |
362 | UNSET_IF_PARAM(oi->params, passive_interface); | |
363 | /* update multicast memberships */ | |
364 | ospf_if_set_multicast(oi); | |
365 | } | |
366 | } | |
367 | ||
368 | static void ospf_passive_interface_update_addr(struct ospf *ospf, | |
369 | struct interface *ifp, | |
370 | struct ospf_if_params *params, | |
371 | u_char value, | |
372 | struct in_addr addr) | |
373 | { | |
374 | u_char dflt; | |
375 | ||
376 | params->passive_interface = value; | |
377 | if (params != IF_DEF_PARAMS(ifp)) { | |
378 | if (OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(ifp), | |
379 | passive_interface)) | |
380 | dflt = IF_DEF_PARAMS(ifp)->passive_interface; | |
381 | else | |
382 | dflt = ospf->passive_interface_default; | |
383 | ||
384 | if (value != dflt) | |
385 | SET_IF_PARAM(params, passive_interface); | |
386 | else | |
387 | UNSET_IF_PARAM(params, passive_interface); | |
388 | ||
389 | ospf_free_if_params(ifp, addr); | |
390 | ospf_if_update_params(ifp, addr); | |
391 | } | |
392 | } | |
393 | ||
394 | static void ospf_passive_interface_update(struct ospf *ospf, | |
395 | struct interface *ifp, | |
396 | struct ospf_if_params *params, | |
397 | u_char value) | |
398 | { | |
399 | params->passive_interface = value; | |
400 | if (params == IF_DEF_PARAMS(ifp)) { | |
401 | if (value != ospf->passive_interface_default) | |
402 | SET_IF_PARAM(params, passive_interface); | |
403 | else | |
404 | UNSET_IF_PARAM(params, passive_interface); | |
405 | } | |
7ffa8fa2 PJ |
406 | } |
407 | ||
a2c62831 | 408 | DEFUN (ospf_passive_interface, |
409 | ospf_passive_interface_addr_cmd, | |
7a7be519 | 410 | "passive-interface <IFNAME [A.B.C.D]|default>", |
718e3744 | 411 | "Suppress routing updates on an interface\n" |
7a7be519 | 412 | "Interface's name\n" |
3a2d747c | 413 | "IPv4 address\n" |
7a7be519 | 414 | "Suppress routing updates on interfaces by default\n") |
718e3744 | 415 | { |
a3d826f0 | 416 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 417 | int idx_ipv4 = 2; |
418 | struct interface *ifp; | |
419 | struct in_addr addr = {.s_addr = INADDR_ANY}; | |
420 | int ret; | |
421 | struct ospf_if_params *params; | |
422 | struct route_node *rn; | |
423 | ||
424 | if (strmatch(argv[1]->text, "default")) { | |
425 | ospf_passive_interface_default(ospf, OSPF_IF_PASSIVE); | |
426 | return CMD_SUCCESS; | |
427 | } | |
428 | ||
bcc24579 | 429 | ifp = if_get_by_name(argv[1]->arg, ospf->vrf_id, 0); |
b5a8894d CS |
430 | if (ifp == NULL) { |
431 | vty_out(vty, "interface %s not found.\n", | |
432 | (char *)argv[1]->arg); | |
433 | return CMD_WARNING; | |
434 | } | |
d62a17ae | 435 | |
436 | params = IF_DEF_PARAMS(ifp); | |
437 | ||
438 | if (argc == 3) { | |
439 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
440 | if (!ret) { | |
441 | vty_out(vty, | |
442 | "Please specify interface address by A.B.C.D\n"); | |
443 | return CMD_WARNING_CONFIG_FAILED; | |
444 | } | |
445 | ||
446 | params = ospf_get_if_params(ifp, addr); | |
447 | ospf_if_update_params(ifp, addr); | |
448 | ospf_passive_interface_update_addr(ospf, ifp, params, | |
449 | OSPF_IF_PASSIVE, addr); | |
450 | } | |
451 | ||
452 | ospf_passive_interface_update(ospf, ifp, params, OSPF_IF_PASSIVE); | |
453 | ||
454 | /* XXX We should call ospf_if_set_multicast on exactly those | |
455 | * interfaces for which the passive property changed. It is too much | |
456 | * work to determine this set, so we do this for every interface. | |
457 | * This is safe and reasonable because ospf_if_set_multicast uses a | |
458 | * record of joined groups to avoid systems calls if the desired | |
459 | * memberships match the current memership. | |
460 | */ | |
461 | ||
462 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { | |
463 | struct ospf_interface *oi = rn->info; | |
464 | ||
9d303b37 DL |
465 | if (oi && (OSPF_IF_PARAM(oi, passive_interface) |
466 | == OSPF_IF_PASSIVE)) | |
d62a17ae | 467 | ospf_if_set_multicast(oi); |
468 | } | |
469 | /* | |
470 | * XXX It is not clear what state transitions the interface needs to | |
471 | * undergo when going from active to passive. Fixing this will | |
472 | * require precise identification of interfaces having such a | |
473 | * transition. | |
474 | */ | |
475 | ||
476 | return CMD_SUCCESS; | |
718e3744 | 477 | } |
478 | ||
a2c62831 | 479 | DEFUN (no_ospf_passive_interface, |
480 | no_ospf_passive_interface_addr_cmd, | |
7a7be519 | 481 | "no passive-interface <IFNAME [A.B.C.D]|default>", |
718e3744 | 482 | NO_STR |
483 | "Allow routing updates on an interface\n" | |
7a7be519 | 484 | "Interface's name\n" |
3a2d747c | 485 | "IPv4 address\n" |
7a7be519 | 486 | "Allow routing updates on interfaces by default\n") |
718e3744 | 487 | { |
a3d826f0 | 488 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 489 | int idx_ipv4 = 3; |
490 | struct interface *ifp; | |
491 | struct in_addr addr = {.s_addr = INADDR_ANY}; | |
492 | struct ospf_if_params *params; | |
493 | int ret; | |
494 | struct route_node *rn; | |
495 | ||
496 | if (strmatch(argv[2]->text, "default")) { | |
497 | ospf_passive_interface_default(ospf, OSPF_IF_ACTIVE); | |
498 | return CMD_SUCCESS; | |
43540886 AS |
499 | } |
500 | ||
bcc24579 | 501 | ifp = if_get_by_name(argv[2]->arg, ospf->vrf_id, 0); |
b5a8894d CS |
502 | if (ifp == NULL) { |
503 | vty_out(vty, "interface %s not found.\n", | |
504 | (char *)argv[1]->arg); | |
505 | return CMD_WARNING; | |
506 | } | |
ba6454ec | 507 | |
d62a17ae | 508 | params = IF_DEF_PARAMS(ifp); |
509 | ||
510 | if (argc == 4) { | |
511 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
512 | if (!ret) { | |
513 | vty_out(vty, | |
514 | "Please specify interface address by A.B.C.D\n"); | |
515 | return CMD_WARNING_CONFIG_FAILED; | |
516 | } | |
517 | ||
518 | params = ospf_lookup_if_params(ifp, addr); | |
519 | if (params == NULL) | |
520 | return CMD_SUCCESS; | |
521 | ospf_passive_interface_update_addr(ospf, ifp, params, | |
522 | OSPF_IF_ACTIVE, addr); | |
523 | } | |
524 | ospf_passive_interface_update(ospf, ifp, params, OSPF_IF_ACTIVE); | |
525 | ||
526 | /* XXX We should call ospf_if_set_multicast on exactly those | |
527 | * interfaces for which the passive property changed. It is too much | |
528 | * work to determine this set, so we do this for every interface. | |
529 | * This is safe and reasonable because ospf_if_set_multicast uses a | |
530 | * record of joined groups to avoid systems calls if the desired | |
531 | * memberships match the current memership. | |
532 | */ | |
533 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { | |
534 | struct ospf_interface *oi = rn->info; | |
535 | ||
536 | if (oi | |
537 | && (OSPF_IF_PARAM(oi, passive_interface) == OSPF_IF_ACTIVE)) | |
538 | ospf_if_set_multicast(oi); | |
539 | } | |
540 | ||
541 | return CMD_SUCCESS; | |
718e3744 | 542 | } |
543 | ||
718e3744 | 544 | |
a2c62831 | 545 | DEFUN (ospf_network_area, |
546 | ospf_network_area_cmd, | |
6147e2c6 | 547 | "network A.B.C.D/M area <A.B.C.D|(0-4294967295)>", |
718e3744 | 548 | "Enable routing on an IP network\n" |
549 | "OSPF network prefix\n" | |
550 | "Set the OSPF area ID\n" | |
551 | "OSPF area ID in IP address format\n" | |
552 | "OSPF area ID as a decimal value\n") | |
553 | { | |
a3d826f0 | 554 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 555 | int idx_ipv4_prefixlen = 1; |
556 | int idx_ipv4_number = 3; | |
557 | struct prefix_ipv4 p; | |
558 | struct in_addr area_id; | |
559 | int ret, format; | |
560 | ||
561 | if (ospf->instance) { | |
562 | vty_out(vty, | |
563 | "The network command is not supported in multi-instance ospf\n"); | |
564 | return CMD_WARNING_CONFIG_FAILED; | |
565 | } | |
718e3744 | 566 | |
d62a17ae | 567 | if (ospf->if_ospf_cli_count > 0) { |
568 | vty_out(vty, | |
569 | "Please remove all ip ospf area x.x.x.x commands first.\n"); | |
570 | return CMD_WARNING_CONFIG_FAILED; | |
571 | } | |
572 | ||
573 | /* Get network prefix and Area ID. */ | |
574 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); | |
575 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); | |
576 | ||
577 | ret = ospf_network_set(ospf, &p, area_id, format); | |
578 | if (ret == 0) { | |
579 | vty_out(vty, "There is already same network statement.\n"); | |
851fcbae | 580 | return CMD_WARNING; |
d62a17ae | 581 | } |
582 | ||
583 | return CMD_SUCCESS; | |
718e3744 | 584 | } |
585 | ||
a2c62831 | 586 | DEFUN (no_ospf_network_area, |
587 | no_ospf_network_area_cmd, | |
6147e2c6 | 588 | "no network A.B.C.D/M area <A.B.C.D|(0-4294967295)>", |
718e3744 | 589 | NO_STR |
590 | "Enable routing on an IP network\n" | |
591 | "OSPF network prefix\n" | |
592 | "Set the OSPF area ID\n" | |
593 | "OSPF area ID in IP address format\n" | |
594 | "OSPF area ID as a decimal value\n") | |
595 | { | |
a3d826f0 | 596 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 597 | int idx_ipv4_prefixlen = 2; |
598 | int idx_ipv4_number = 4; | |
599 | struct prefix_ipv4 p; | |
600 | struct in_addr area_id; | |
601 | int ret, format; | |
602 | ||
603 | if (ospf->instance) { | |
604 | vty_out(vty, | |
605 | "The network command is not supported in multi-instance ospf\n"); | |
606 | return CMD_WARNING_CONFIG_FAILED; | |
607 | } | |
718e3744 | 608 | |
d62a17ae | 609 | /* Get network prefix and Area ID. */ |
610 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); | |
611 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); | |
612 | ||
613 | ret = ospf_network_unset(ospf, &p, area_id); | |
614 | if (ret == 0) { | |
615 | vty_out(vty, | |
616 | "Can't find specified network area configuration.\n"); | |
617 | return CMD_WARNING_CONFIG_FAILED; | |
618 | } | |
619 | ||
620 | return CMD_SUCCESS; | |
718e3744 | 621 | } |
622 | ||
a2c62831 | 623 | DEFUN (ospf_area_range, |
624 | ospf_area_range_cmd, | |
7a7be519 | 625 | "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M [advertise [cost (0-16777215)]]", |
718e3744 | 626 | "OSPF area parameters\n" |
627 | "OSPF area ID in IP address format\n" | |
628 | "OSPF area ID as a decimal value\n" | |
629 | "Summarize routes matching address/mask (border routers only)\n" | |
7a7be519 | 630 | "Area range prefix\n" |
631 | "Advertise this range (default)\n" | |
632 | "User specified metric for this range\n" | |
633 | "Advertised metric for this range\n") | |
718e3744 | 634 | { |
a3d826f0 | 635 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 636 | int idx_ipv4_number = 1; |
637 | int idx_ipv4_prefixlen = 3; | |
638 | int idx_cost = 6; | |
639 | struct prefix_ipv4 p; | |
640 | struct in_addr area_id; | |
641 | int format; | |
642 | u_int32_t cost; | |
643 | ||
644 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); | |
645 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); | |
646 | ||
647 | ospf_area_range_set(ospf, area_id, &p, OSPF_AREA_RANGE_ADVERTISE); | |
648 | if (argc > 5) { | |
649 | cost = strtoul(argv[idx_cost]->arg, NULL, 10); | |
650 | ospf_area_range_cost_set(ospf, area_id, &p, cost); | |
651 | } | |
718e3744 | 652 | |
d62a17ae | 653 | return CMD_SUCCESS; |
718e3744 | 654 | } |
655 | ||
7a7be519 | 656 | DEFUN (ospf_area_range_cost, |
657 | ospf_area_range_cost_cmd, | |
658 | "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M cost (0-16777215)", | |
659 | "OSPF area parameters\n" | |
660 | "OSPF area ID in IP address format\n" | |
661 | "OSPF area ID as a decimal value\n" | |
662 | "Summarize routes matching address/mask (border routers only)\n" | |
663 | "Area range prefix\n" | |
664 | "User specified metric for this range\n" | |
665 | "Advertised metric for this range\n") | |
666 | { | |
a3d826f0 | 667 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 668 | int idx_ipv4_number = 1; |
669 | int idx_ipv4_prefixlen = 3; | |
670 | int idx_cost = 5; | |
671 | struct prefix_ipv4 p; | |
672 | struct in_addr area_id; | |
673 | int format; | |
674 | u_int32_t cost; | |
7a7be519 | 675 | |
d62a17ae | 676 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
677 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); | |
7a7be519 | 678 | |
d62a17ae | 679 | ospf_area_range_set(ospf, area_id, &p, OSPF_AREA_RANGE_ADVERTISE); |
680 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
681 | format); | |
718e3744 | 682 | |
d62a17ae | 683 | cost = strtoul(argv[idx_cost]->arg, NULL, 10); |
684 | ospf_area_range_cost_set(ospf, area_id, &p, cost); | |
718e3744 | 685 | |
d62a17ae | 686 | return CMD_SUCCESS; |
7a7be519 | 687 | } |
718e3744 | 688 | |
a2c62831 | 689 | DEFUN (ospf_area_range_not_advertise, |
690 | ospf_area_range_not_advertise_cmd, | |
6147e2c6 | 691 | "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M not-advertise", |
718e3744 | 692 | "OSPF area parameters\n" |
693 | "OSPF area ID in IP address format\n" | |
694 | "OSPF area ID as a decimal value\n" | |
695 | "Summarize routes matching address/mask (border routers only)\n" | |
696 | "Area range prefix\n" | |
697 | "DoNotAdvertise this range\n") | |
698 | { | |
a3d826f0 | 699 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 700 | int idx_ipv4_number = 1; |
701 | int idx_ipv4_prefixlen = 3; | |
702 | struct prefix_ipv4 p; | |
703 | struct in_addr area_id; | |
704 | int format; | |
718e3744 | 705 | |
d62a17ae | 706 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
707 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); | |
718e3744 | 708 | |
d62a17ae | 709 | ospf_area_range_set(ospf, area_id, &p, 0); |
710 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
711 | format); | |
718e3744 | 712 | |
d62a17ae | 713 | return CMD_SUCCESS; |
718e3744 | 714 | } |
715 | ||
a2c62831 | 716 | DEFUN (no_ospf_area_range, |
717 | no_ospf_area_range_cmd, | |
3a2d747c | 718 | "no area <A.B.C.D|(0-4294967295)> range A.B.C.D/M [<cost (0-16777215)|advertise [cost (0-16777215)]|not-advertise>]", |
718e3744 | 719 | NO_STR |
720 | "OSPF area parameters\n" | |
721 | "OSPF area ID in IP address format\n" | |
722 | "OSPF area ID as a decimal value\n" | |
723 | "Summarize routes matching address/mask (border routers only)\n" | |
7a7be519 | 724 | "Area range prefix\n" |
3a2d747c QY |
725 | "User specified metric for this range\n" |
726 | "Advertised metric for this range\n" | |
7a7be519 | 727 | "Advertise this range (default)\n" |
3a2d747c QY |
728 | "User specified metric for this range\n" |
729 | "Advertised metric for this range\n" | |
7a7be519 | 730 | "DoNotAdvertise this range\n") |
718e3744 | 731 | { |
a3d826f0 | 732 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 733 | int idx_ipv4_number = 2; |
734 | int idx_ipv4_prefixlen = 4; | |
735 | struct prefix_ipv4 p; | |
736 | struct in_addr area_id; | |
737 | int format; | |
718e3744 | 738 | |
d62a17ae | 739 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
740 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); | |
718e3744 | 741 | |
d62a17ae | 742 | ospf_area_range_unset(ospf, area_id, &p); |
718e3744 | 743 | |
d62a17ae | 744 | return CMD_SUCCESS; |
718e3744 | 745 | } |
746 | ||
a2c62831 | 747 | DEFUN (ospf_area_range_substitute, |
748 | ospf_area_range_substitute_cmd, | |
6147e2c6 | 749 | "area <A.B.C.D|(0-4294967295)> range A.B.C.D/M substitute A.B.C.D/M", |
718e3744 | 750 | "OSPF area parameters\n" |
751 | "OSPF area ID in IP address format\n" | |
752 | "OSPF area ID as a decimal value\n" | |
753 | "Summarize routes matching address/mask (border routers only)\n" | |
754 | "Area range prefix\n" | |
755 | "Announce area range as another prefix\n" | |
756 | "Network prefix to be announced instead of range\n") | |
757 | { | |
a3d826f0 | 758 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 759 | int idx_ipv4_number = 1; |
760 | int idx_ipv4_prefixlen = 3; | |
761 | int idx_ipv4_prefixlen_2 = 5; | |
762 | struct prefix_ipv4 p, s; | |
763 | struct in_addr area_id; | |
764 | int format; | |
718e3744 | 765 | |
d62a17ae | 766 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
767 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); | |
768 | str2prefix_ipv4(argv[idx_ipv4_prefixlen_2]->arg, &s); | |
718e3744 | 769 | |
d62a17ae | 770 | ospf_area_range_substitute_set(ospf, area_id, &p, &s); |
771 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
772 | format); | |
718e3744 | 773 | |
d62a17ae | 774 | return CMD_SUCCESS; |
718e3744 | 775 | } |
776 | ||
a2c62831 | 777 | DEFUN (no_ospf_area_range_substitute, |
778 | no_ospf_area_range_substitute_cmd, | |
6147e2c6 | 779 | "no area <A.B.C.D|(0-4294967295)> range A.B.C.D/M substitute A.B.C.D/M", |
718e3744 | 780 | NO_STR |
781 | "OSPF area parameters\n" | |
782 | "OSPF area ID in IP address format\n" | |
783 | "OSPF area ID as a decimal value\n" | |
784 | "Summarize routes matching address/mask (border routers only)\n" | |
785 | "Area range prefix\n" | |
786 | "Announce area range as another prefix\n" | |
787 | "Network prefix to be announced instead of range\n") | |
788 | { | |
a3d826f0 | 789 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 790 | int idx_ipv4_number = 2; |
791 | int idx_ipv4_prefixlen = 4; | |
792 | int idx_ipv4_prefixlen_2 = 6; | |
793 | struct prefix_ipv4 p, s; | |
794 | struct in_addr area_id; | |
795 | int format; | |
718e3744 | 796 | |
d62a17ae | 797 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
798 | str2prefix_ipv4(argv[idx_ipv4_prefixlen]->arg, &p); | |
799 | str2prefix_ipv4(argv[idx_ipv4_prefixlen_2]->arg, &s); | |
718e3744 | 800 | |
d62a17ae | 801 | ospf_area_range_substitute_unset(ospf, area_id, &p); |
718e3744 | 802 | |
d62a17ae | 803 | return CMD_SUCCESS; |
718e3744 | 804 | } |
805 | ||
6b0655a2 | 806 | |
718e3744 | 807 | /* Command Handler Logic in VLink stuff is delicate!! |
808 | ||
809 | ALTER AT YOUR OWN RISK!!!! | |
810 | ||
811 | Various dummy values are used to represent 'NoChange' state for | |
812 | VLink configuration NOT being changed by a VLink command, and | |
813 | special syntax is used within the command strings so that the | |
814 | typed in command verbs can be seen in the configuration command | |
815 | bacckend handler. This is to drastically reduce the verbeage | |
816 | required to coe up with a reasonably compatible Cisco VLink command | |
817 | ||
d62a17ae | 818 | - Matthew Grant <grantma@anathoth.gen.nz> |
718e3744 | 819 | Wed, 21 Feb 2001 15:13:52 +1300 |
820 | */ | |
821 | ||
d62a17ae | 822 | /* Configuration data for virtual links |
823 | */ | |
718e3744 | 824 | struct ospf_vl_config_data { |
d62a17ae | 825 | struct vty *vty; /* vty stuff */ |
826 | struct in_addr area_id; /* area ID from command line */ | |
827 | int area_id_fmt; /* command line area ID format */ | |
828 | struct in_addr vl_peer; /* command line vl_peer */ | |
829 | int auth_type; /* Authehntication type, if given */ | |
830 | char *auth_key; /* simple password if present */ | |
831 | int crypto_key_id; /* Cryptographic key ID */ | |
832 | char *md5_key; /* MD5 authentication key */ | |
833 | int hello_interval; /* Obvious what these are... */ | |
834 | int retransmit_interval; | |
835 | int transmit_delay; | |
836 | int dead_interval; | |
718e3744 | 837 | }; |
838 | ||
d62a17ae | 839 | static void ospf_vl_config_data_init(struct ospf_vl_config_data *vl_config, |
840 | struct vty *vty) | |
718e3744 | 841 | { |
d62a17ae | 842 | memset(vl_config, 0, sizeof(struct ospf_vl_config_data)); |
843 | vl_config->auth_type = OSPF_AUTH_CMD_NOTSEEN; | |
844 | vl_config->vty = vty; | |
718e3744 | 845 | } |
846 | ||
4dadc291 | 847 | static struct ospf_vl_data * |
d62a17ae | 848 | ospf_find_vl_data(struct ospf *ospf, struct ospf_vl_config_data *vl_config) |
849 | { | |
850 | struct ospf_area *area; | |
851 | struct ospf_vl_data *vl_data; | |
852 | struct vty *vty; | |
853 | struct in_addr area_id; | |
854 | ||
855 | vty = vl_config->vty; | |
856 | area_id = vl_config->area_id; | |
857 | ||
858 | if (area_id.s_addr == OSPF_AREA_BACKBONE) { | |
859 | vty_out(vty, | |
860 | "Configuring VLs over the backbone is not allowed\n"); | |
861 | return NULL; | |
862 | } | |
863 | area = ospf_area_get(ospf, area_id); | |
864 | ospf_area_display_format_set(ospf, area, vl_config->area_id_fmt); | |
865 | ||
866 | if (area->external_routing != OSPF_AREA_DEFAULT) { | |
867 | if (vl_config->area_id_fmt == OSPF_AREA_ID_FMT_DOTTEDQUAD) | |
868 | vty_out(vty, "Area %s is %s\n", inet_ntoa(area_id), | |
869 | area->external_routing == OSPF_AREA_NSSA | |
870 | ? "nssa" | |
871 | : "stub"); | |
872 | else | |
873 | vty_out(vty, "Area %ld is %s\n", | |
874 | (u_long)ntohl(area_id.s_addr), | |
875 | area->external_routing == OSPF_AREA_NSSA | |
876 | ? "nssa" | |
877 | : "stub"); | |
878 | return NULL; | |
879 | } | |
880 | ||
881 | if ((vl_data = ospf_vl_lookup(ospf, area, vl_config->vl_peer)) | |
882 | == NULL) { | |
883 | vl_data = ospf_vl_data_new(area, vl_config->vl_peer); | |
884 | if (vl_data->vl_oi == NULL) { | |
885 | vl_data->vl_oi = ospf_vl_new(ospf, vl_data); | |
886 | ospf_vl_add(ospf, vl_data); | |
887 | ospf_spf_calculate_schedule(ospf, | |
888 | SPF_FLAG_CONFIG_CHANGE); | |
889 | } | |
718e3744 | 890 | } |
d62a17ae | 891 | return vl_data; |
718e3744 | 892 | } |
893 | ||
894 | ||
d62a17ae | 895 | static int ospf_vl_set_security(struct ospf_vl_data *vl_data, |
896 | struct ospf_vl_config_data *vl_config) | |
897 | { | |
898 | struct crypt_key *ck; | |
899 | struct vty *vty; | |
900 | struct interface *ifp = vl_data->vl_oi->ifp; | |
901 | ||
902 | vty = vl_config->vty; | |
903 | ||
904 | if (vl_config->auth_type != OSPF_AUTH_CMD_NOTSEEN) { | |
905 | SET_IF_PARAM(IF_DEF_PARAMS(ifp), auth_type); | |
906 | IF_DEF_PARAMS(ifp)->auth_type = vl_config->auth_type; | |
718e3744 | 907 | } |
718e3744 | 908 | |
d62a17ae | 909 | if (vl_config->auth_key) { |
910 | memset(IF_DEF_PARAMS(ifp)->auth_simple, 0, | |
911 | OSPF_AUTH_SIMPLE_SIZE + 1); | |
912 | strncpy((char *)IF_DEF_PARAMS(ifp)->auth_simple, | |
913 | vl_config->auth_key, OSPF_AUTH_SIMPLE_SIZE); | |
914 | } else if (vl_config->md5_key) { | |
915 | if (ospf_crypt_key_lookup(IF_DEF_PARAMS(ifp)->auth_crypt, | |
916 | vl_config->crypto_key_id) | |
917 | != NULL) { | |
918 | vty_out(vty, "OSPF: Key %d already exists\n", | |
919 | vl_config->crypto_key_id); | |
851fcbae | 920 | return CMD_WARNING; |
d62a17ae | 921 | } |
922 | ck = ospf_crypt_key_new(); | |
923 | ck->key_id = vl_config->crypto_key_id; | |
924 | memset(ck->auth_key, 0, OSPF_AUTH_MD5_SIZE + 1); | |
925 | strncpy((char *)ck->auth_key, vl_config->md5_key, | |
926 | OSPF_AUTH_MD5_SIZE); | |
927 | ||
928 | ospf_crypt_key_add(IF_DEF_PARAMS(ifp)->auth_crypt, ck); | |
929 | } else if (vl_config->crypto_key_id != 0) { | |
930 | /* Delete a key */ | |
931 | ||
932 | if (ospf_crypt_key_lookup(IF_DEF_PARAMS(ifp)->auth_crypt, | |
933 | vl_config->crypto_key_id) | |
934 | == NULL) { | |
935 | vty_out(vty, "OSPF: Key %d does not exist\n", | |
936 | vl_config->crypto_key_id); | |
937 | return CMD_WARNING_CONFIG_FAILED; | |
938 | } | |
939 | ||
940 | ospf_crypt_key_delete(IF_DEF_PARAMS(ifp)->auth_crypt, | |
941 | vl_config->crypto_key_id); | |
942 | } | |
943 | ||
944 | return CMD_SUCCESS; | |
718e3744 | 945 | } |
946 | ||
d62a17ae | 947 | static int ospf_vl_set_timers(struct ospf_vl_data *vl_data, |
948 | struct ospf_vl_config_data *vl_config) | |
949 | { | |
950 | struct interface *ifp = vl_data->vl_oi->ifp; | |
951 | /* Virtual Link data initialised to defaults, so only set | |
952 | if a value given */ | |
953 | if (vl_config->hello_interval) { | |
954 | SET_IF_PARAM(IF_DEF_PARAMS(ifp), v_hello); | |
955 | IF_DEF_PARAMS(ifp)->v_hello = vl_config->hello_interval; | |
956 | } | |
957 | ||
958 | if (vl_config->dead_interval) { | |
959 | SET_IF_PARAM(IF_DEF_PARAMS(ifp), v_wait); | |
960 | IF_DEF_PARAMS(ifp)->v_wait = vl_config->dead_interval; | |
961 | } | |
962 | ||
963 | if (vl_config->retransmit_interval) { | |
964 | SET_IF_PARAM(IF_DEF_PARAMS(ifp), retransmit_interval); | |
965 | IF_DEF_PARAMS(ifp)->retransmit_interval = | |
966 | vl_config->retransmit_interval; | |
967 | } | |
968 | ||
969 | if (vl_config->transmit_delay) { | |
970 | SET_IF_PARAM(IF_DEF_PARAMS(ifp), transmit_delay); | |
971 | IF_DEF_PARAMS(ifp)->transmit_delay = vl_config->transmit_delay; | |
972 | } | |
973 | ||
974 | return CMD_SUCCESS; | |
718e3744 | 975 | } |
976 | ||
977 | ||
718e3744 | 978 | /* The business end of all of the above */ |
d62a17ae | 979 | static int ospf_vl_set(struct ospf *ospf, struct ospf_vl_config_data *vl_config) |
980 | { | |
981 | struct ospf_vl_data *vl_data; | |
982 | int ret; | |
718e3744 | 983 | |
d62a17ae | 984 | vl_data = ospf_find_vl_data(ospf, vl_config); |
985 | if (!vl_data) | |
986 | return CMD_WARNING_CONFIG_FAILED; | |
987 | ||
988 | /* Process this one first as it can have a fatal result, which can | |
989 | only logically occur if the virtual link exists already | |
990 | Thus a command error does not result in a change to the | |
991 | running configuration such as unexpectedly altered timer | |
992 | values etc.*/ | |
993 | ret = ospf_vl_set_security(vl_data, vl_config); | |
994 | if (ret != CMD_SUCCESS) | |
995 | return ret; | |
996 | ||
997 | /* Set any time based parameters, these area already range checked */ | |
998 | ||
999 | ret = ospf_vl_set_timers(vl_data, vl_config); | |
1000 | if (ret != CMD_SUCCESS) | |
1001 | return ret; | |
718e3744 | 1002 | |
d62a17ae | 1003 | return CMD_SUCCESS; |
718e3744 | 1004 | } |
1005 | ||
1006 | /* This stuff exists to make specifying all the alias commands A LOT simpler | |
1007 | */ | |
d62a17ae | 1008 | #define VLINK_HELPSTR_IPADDR \ |
1009 | "OSPF area parameters\n" \ | |
1010 | "OSPF area ID in IP address format\n" \ | |
1011 | "OSPF area ID as a decimal value\n" \ | |
1012 | "Configure a virtual link\n" \ | |
1013 | "Router ID of the remote ABR\n" | |
1014 | ||
1015 | #define VLINK_HELPSTR_AUTHTYPE_SIMPLE \ | |
1016 | "Enable authentication on this virtual link\n" \ | |
1017 | "dummy string \n" | |
1018 | ||
1019 | #define VLINK_HELPSTR_AUTHTYPE_ALL \ | |
1020 | VLINK_HELPSTR_AUTHTYPE_SIMPLE \ | |
1021 | "Use null authentication\n" \ | |
1022 | "Use message-digest authentication\n" | |
1023 | ||
1024 | #define VLINK_HELPSTR_TIME_PARAM \ | |
1025 | "Time between HELLO packets\n" \ | |
1026 | "Seconds\n" \ | |
1027 | "Time between retransmitting lost link state advertisements\n" \ | |
1028 | "Seconds\n" \ | |
1029 | "Link state transmit delay\n" \ | |
1030 | "Seconds\n" \ | |
1031 | "Interval time after which a neighbor is declared down\n" \ | |
1032 | "Seconds\n" | |
1033 | ||
1034 | #define VLINK_HELPSTR_AUTH_SIMPLE \ | |
1035 | "Authentication password (key)\n" \ | |
baf9eaad | 1036 | "The OSPF password (key)\n" |
d62a17ae | 1037 | |
1038 | #define VLINK_HELPSTR_AUTH_MD5 \ | |
1039 | "Message digest authentication password (key)\n" \ | |
d62a17ae | 1040 | "Key ID\n" \ |
1041 | "Use MD5 algorithm\n" \ | |
baf9eaad | 1042 | "The OSPF password (key)\n" |
718e3744 | 1043 | |
a2c62831 | 1044 | DEFUN (ospf_area_vlink, |
1045 | ospf_area_vlink_cmd, | |
3d1c6dc2 | 1046 | "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 | 1047 | VLINK_HELPSTR_IPADDR |
3d1c6dc2 | 1048 | "Enable authentication on this virtual link\n" |
7a7be519 | 1049 | "Use message-digest authentication\n" |
3d1c6dc2 | 1050 | "Use null authentication\n" |
baf9eaad CS |
1051 | VLINK_HELPSTR_AUTH_MD5 |
1052 | VLINK_HELPSTR_AUTH_SIMPLE) | |
718e3744 | 1053 | { |
a3d826f0 | 1054 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1055 | int idx_ipv4_number = 1; |
1056 | int idx_ipv4 = 3; | |
1057 | struct ospf_vl_config_data vl_config; | |
1058 | char auth_key[OSPF_AUTH_SIMPLE_SIZE + 1]; | |
1059 | char md5_key[OSPF_AUTH_MD5_SIZE + 1]; | |
d62a17ae | 1060 | int ret; |
55d1da24 | 1061 | int idx = 0; |
d62a17ae | 1062 | |
1063 | ospf_vl_config_data_init(&vl_config, vty); | |
1064 | ||
1065 | /* Read off first 2 parameters and check them */ | |
1066 | ret = str2area_id(argv[idx_ipv4_number]->arg, &vl_config.area_id, | |
1067 | &vl_config.area_id_fmt); | |
1068 | if (ret < 0) { | |
1069 | vty_out(vty, "OSPF area ID is invalid\n"); | |
1070 | return CMD_WARNING_CONFIG_FAILED; | |
1071 | } | |
718e3744 | 1072 | |
d62a17ae | 1073 | ret = inet_aton(argv[idx_ipv4]->arg, &vl_config.vl_peer); |
1074 | if (!ret) { | |
1075 | vty_out(vty, "Please specify valid Router ID as a.b.c.d\n"); | |
1076 | return CMD_WARNING_CONFIG_FAILED; | |
7a7be519 | 1077 | } |
7a7be519 | 1078 | |
d62a17ae | 1079 | if (argc <= 4) { |
1080 | /* Thats all folks! - BUGS B. strikes again!!!*/ | |
7a7be519 | 1081 | |
d62a17ae | 1082 | return ospf_vl_set(ospf, &vl_config); |
1083 | } | |
1084 | ||
3d1c6dc2 CS |
1085 | if (argv_find(argv, argc, "authentication", &idx)) { |
1086 | /* authentication - this option can only occur | |
1087 | at start of command line */ | |
1088 | vl_config.auth_type = OSPF_AUTH_SIMPLE; | |
1089 | } | |
1090 | ||
3d1c6dc2 | 1091 | if (argv_find(argv, argc, "message-digest", &idx)) { |
baf9eaad | 1092 | /* authentication message-digest */ |
3d1c6dc2 CS |
1093 | vl_config.auth_type = OSPF_AUTH_CRYPTOGRAPHIC; |
1094 | } else if (argv_find(argv, argc, "null", &idx)) { | |
1095 | /* "authentication null" */ | |
1096 | vl_config.auth_type = OSPF_AUTH_NULL; | |
d62a17ae | 1097 | } |
7a7be519 | 1098 | |
3d1c6dc2 | 1099 | if (argv_find(argv, argc, "message-digest-key", &idx)) { |
3d1c6dc2 | 1100 | vl_config.md5_key = NULL; |
cbb9b53d | 1101 | vl_config.crypto_key_id = strtol(argv[idx + 1]->arg, NULL, 10); |
3d1c6dc2 CS |
1102 | if (vl_config.crypto_key_id < 0) |
1103 | return CMD_WARNING_CONFIG_FAILED; | |
1104 | ||
3d1c6dc2 | 1105 | memset(md5_key, 0, OSPF_AUTH_MD5_SIZE + 1); |
cbb9b53d | 1106 | strncpy(md5_key, argv[idx + 3]->arg, OSPF_AUTH_MD5_SIZE); |
3d1c6dc2 CS |
1107 | vl_config.md5_key = md5_key; |
1108 | } | |
1109 | ||
3d1c6dc2 | 1110 | if (argv_find(argv, argc, "authentication-key", &idx)) { |
3d1c6dc2 | 1111 | memset(auth_key, 0, OSPF_AUTH_SIMPLE_SIZE + 1); |
cbb9b53d | 1112 | strncpy(auth_key, argv[idx + 1]->arg, OSPF_AUTH_SIMPLE_SIZE); |
3d1c6dc2 CS |
1113 | vl_config.auth_key = auth_key; |
1114 | } | |
7a7be519 | 1115 | |
d62a17ae | 1116 | /* Action configuration */ |
1117 | ||
1118 | return ospf_vl_set(ospf, &vl_config); | |
7a7be519 | 1119 | } |
1120 | ||
a2c62831 | 1121 | DEFUN (no_ospf_area_vlink, |
1122 | no_ospf_area_vlink_cmd, | |
3d1c6dc2 | 1123 | "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 | 1124 | NO_STR |
7a7be519 | 1125 | VLINK_HELPSTR_IPADDR |
1126 | "Enable authentication on this virtual link\n" \ | |
3d1c6dc2 | 1127 | "Use message-digest authentication\n" \ |
7a7be519 | 1128 | "Use null authentication\n" \ |
baf9eaad CS |
1129 | VLINK_HELPSTR_AUTH_MD5 |
1130 | VLINK_HELPSTR_AUTH_SIMPLE) | |
718e3744 | 1131 | { |
a3d826f0 | 1132 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1133 | int idx_ipv4_number = 2; |
1134 | int idx_ipv4 = 4; | |
1135 | struct ospf_area *area; | |
1136 | struct ospf_vl_config_data vl_config; | |
1137 | struct ospf_vl_data *vl_data = NULL; | |
1138 | char auth_key[OSPF_AUTH_SIMPLE_SIZE + 1]; | |
3d1c6dc2 | 1139 | int idx = 0; |
d62a17ae | 1140 | int ret, format; |
1141 | ||
1142 | ospf_vl_config_data_init(&vl_config, vty); | |
1143 | ||
1144 | ret = str2area_id(argv[idx_ipv4_number]->arg, &vl_config.area_id, | |
1145 | &format); | |
1146 | if (ret < 0) { | |
1147 | vty_out(vty, "OSPF area ID is invalid\n"); | |
1148 | return CMD_WARNING_CONFIG_FAILED; | |
1149 | } | |
1150 | ||
1151 | area = ospf_area_lookup_by_area_id(ospf, vl_config.area_id); | |
1152 | if (!area) { | |
1153 | vty_out(vty, "Area does not exist\n"); | |
1154 | return CMD_WARNING_CONFIG_FAILED; | |
1155 | } | |
1156 | ||
1157 | ret = inet_aton(argv[idx_ipv4]->arg, &vl_config.vl_peer); | |
1158 | if (!ret) { | |
1159 | vty_out(vty, "Please specify valid Router ID as a.b.c.d\n"); | |
1160 | return CMD_WARNING_CONFIG_FAILED; | |
1161 | } | |
718e3744 | 1162 | |
d62a17ae | 1163 | if (argc <= 5) { |
1164 | /* Basic VLink no command */ | |
1165 | /* Thats all folks! - BUGS B. strikes again!!!*/ | |
1166 | if ((vl_data = ospf_vl_lookup(ospf, area, vl_config.vl_peer))) | |
1167 | ospf_vl_delete(ospf, vl_data); | |
1168 | ||
1169 | ospf_area_check_free(ospf, vl_config.area_id); | |
1170 | ||
1171 | return CMD_SUCCESS; | |
1172 | } | |
1173 | ||
1174 | /* If we are down here, we are reseting parameters */ | |
d62a17ae | 1175 | /* Deal with other parameters */ |
3d1c6dc2 CS |
1176 | |
1177 | if (argv_find(argv, argc, "authentication", &idx)) { | |
1178 | /* authentication - this option can only occur | |
1179 | at start of command line */ | |
1180 | vl_config.auth_type = OSPF_AUTH_NOTSET; | |
1181 | } | |
1182 | ||
3d1c6dc2 | 1183 | if (argv_find(argv, argc, "message-digest-key", &idx)) { |
3d1c6dc2 | 1184 | vl_config.md5_key = NULL; |
cbb9b53d | 1185 | vl_config.crypto_key_id = strtol(argv[idx + 1]->arg, NULL, 10); |
3d1c6dc2 CS |
1186 | if (vl_config.crypto_key_id < 0) |
1187 | return CMD_WARNING_CONFIG_FAILED; | |
d62a17ae | 1188 | } |
1189 | ||
3d1c6dc2 | 1190 | if (argv_find(argv, argc, "authentication-key", &idx)) { |
cbb9b53d | 1191 | /* Reset authentication-key to 0 */ |
3d1c6dc2 CS |
1192 | memset(auth_key, 0, OSPF_AUTH_SIMPLE_SIZE + 1); |
1193 | vl_config.auth_key = auth_key; | |
1194 | } | |
d62a17ae | 1195 | |
1196 | /* Action configuration */ | |
1197 | ||
1198 | return ospf_vl_set(ospf, &vl_config); | |
7a7be519 | 1199 | } |
1200 | ||
b1c02cec QY |
1201 | DEFUN (ospf_area_vlink_intervals, |
1202 | ospf_area_vlink_intervals_cmd, | |
1203 | "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)}", | |
1204 | VLINK_HELPSTR_IPADDR | |
1205 | VLINK_HELPSTR_TIME_PARAM) | |
1206 | { | |
a3d826f0 | 1207 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1208 | struct ospf_vl_config_data vl_config; |
1209 | int ret = 0; | |
1210 | ||
1211 | ospf_vl_config_data_init(&vl_config, vty); | |
1212 | ||
1213 | char *area_id = argv[1]->arg; | |
1214 | char *router_id = argv[3]->arg; | |
1215 | ||
1216 | ret = str2area_id(area_id, &vl_config.area_id, &vl_config.area_id_fmt); | |
1217 | if (ret < 0) { | |
1218 | vty_out(vty, "OSPF area ID is invalid\n"); | |
1219 | return CMD_WARNING_CONFIG_FAILED; | |
1220 | } | |
1221 | ||
1222 | ret = inet_aton(router_id, &vl_config.vl_peer); | |
1223 | if (!ret) { | |
1224 | vty_out(vty, "Please specify valid Router ID as a.b.c.d\n"); | |
1225 | return CMD_WARNING_CONFIG_FAILED; | |
1226 | } | |
1227 | ||
1228 | for (int idx = 4; idx < argc; idx++) { | |
1229 | if (strmatch(argv[idx]->text, "hello-interval")) | |
1230 | vl_config.hello_interval = | |
1231 | strtol(argv[++idx]->arg, NULL, 10); | |
1232 | else if (strmatch(argv[idx]->text, "retransmit-interval")) | |
1233 | vl_config.retransmit_interval = | |
1234 | strtol(argv[++idx]->arg, NULL, 10); | |
1235 | else if (strmatch(argv[idx]->text, "transmit-delay")) | |
1236 | vl_config.transmit_delay = | |
1237 | strtol(argv[++idx]->arg, NULL, 10); | |
1238 | else if (strmatch(argv[idx]->text, "dead-interval")) | |
1239 | vl_config.dead_interval = | |
1240 | strtol(argv[++idx]->arg, NULL, 10); | |
1241 | } | |
1242 | ||
1243 | /* Action configuration */ | |
1244 | return ospf_vl_set(ospf, &vl_config); | |
b1c02cec QY |
1245 | } |
1246 | ||
7a7be519 | 1247 | DEFUN (no_ospf_area_vlink_intervals, |
1248 | no_ospf_area_vlink_intervals_cmd, | |
a663a38e | 1249 | "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 | 1250 | NO_STR |
7a7be519 | 1251 | VLINK_HELPSTR_IPADDR |
7a7be519 | 1252 | VLINK_HELPSTR_TIME_PARAM) |
1253 | { | |
a3d826f0 | 1254 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1255 | struct ospf_vl_config_data vl_config; |
1256 | int ret = 0; | |
1257 | ||
1258 | ospf_vl_config_data_init(&vl_config, vty); | |
1259 | ||
1260 | char *area_id = argv[2]->arg; | |
1261 | char *router_id = argv[4]->arg; | |
1262 | ||
1263 | ret = str2area_id(area_id, &vl_config.area_id, &vl_config.area_id_fmt); | |
1264 | if (ret < 0) { | |
1265 | vty_out(vty, "OSPF area ID is invalid\n"); | |
1266 | return CMD_WARNING_CONFIG_FAILED; | |
1267 | } | |
1268 | ||
1269 | ret = inet_aton(router_id, &vl_config.vl_peer); | |
1270 | if (!ret) { | |
1271 | vty_out(vty, "Please specify valid Router ID as a.b.c.d\n"); | |
1272 | return CMD_WARNING_CONFIG_FAILED; | |
1273 | } | |
1274 | ||
1275 | for (int idx = 5; idx < argc; idx++) { | |
1276 | if (strmatch(argv[idx]->text, "hello-interval")) | |
1277 | vl_config.hello_interval = OSPF_HELLO_INTERVAL_DEFAULT; | |
1278 | else if (strmatch(argv[idx]->text, "retransmit-interval")) | |
1279 | vl_config.retransmit_interval = | |
1280 | OSPF_RETRANSMIT_INTERVAL_DEFAULT; | |
1281 | else if (strmatch(argv[idx]->text, "transmit-delay")) | |
1282 | vl_config.transmit_delay = OSPF_TRANSMIT_DELAY_DEFAULT; | |
1283 | else if (strmatch(argv[idx]->text, "dead-interval")) | |
1284 | vl_config.dead_interval = | |
1285 | OSPF_ROUTER_DEAD_INTERVAL_DEFAULT; | |
1286 | } | |
1287 | ||
1288 | /* Action configuration */ | |
1289 | return ospf_vl_set(ospf, &vl_config); | |
718e3744 | 1290 | } |
1291 | ||
a2c62831 | 1292 | DEFUN (ospf_area_shortcut, |
1293 | ospf_area_shortcut_cmd, | |
6147e2c6 | 1294 | "area <A.B.C.D|(0-4294967295)> shortcut <default|enable|disable>", |
718e3744 | 1295 | "OSPF area parameters\n" |
1296 | "OSPF area ID in IP address format\n" | |
1297 | "OSPF area ID as a decimal value\n" | |
1298 | "Configure the area's shortcutting mode\n" | |
1299 | "Set default shortcutting behavior\n" | |
1300 | "Enable shortcutting through the area\n" | |
1301 | "Disable shortcutting through the area\n") | |
1302 | { | |
a3d826f0 | 1303 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1304 | int idx_ipv4_number = 1; |
1305 | int idx_enable_disable = 3; | |
1306 | struct ospf_area *area; | |
1307 | struct in_addr area_id; | |
1308 | int mode; | |
1309 | int format; | |
1310 | ||
1311 | VTY_GET_OSPF_AREA_ID_NO_BB("shortcut", area_id, format, | |
1312 | argv[idx_ipv4_number]->arg); | |
1313 | ||
1314 | area = ospf_area_get(ospf, area_id); | |
1315 | ospf_area_display_format_set(ospf, area, format); | |
1316 | ||
1317 | if (strncmp(argv[idx_enable_disable]->arg, "de", 2) == 0) | |
1318 | mode = OSPF_SHORTCUT_DEFAULT; | |
1319 | else if (strncmp(argv[idx_enable_disable]->arg, "di", 2) == 0) | |
1320 | mode = OSPF_SHORTCUT_DISABLE; | |
1321 | else if (strncmp(argv[idx_enable_disable]->arg, "e", 1) == 0) | |
1322 | mode = OSPF_SHORTCUT_ENABLE; | |
1323 | else | |
1324 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 1325 | |
d62a17ae | 1326 | ospf_area_shortcut_set(ospf, area, mode); |
718e3744 | 1327 | |
d62a17ae | 1328 | if (ospf->abr_type != OSPF_ABR_SHORTCUT) |
1329 | vty_out(vty, | |
1330 | "Shortcut area setting will take effect " | |
1331 | "only when the router is configured as Shortcut ABR\n"); | |
718e3744 | 1332 | |
d62a17ae | 1333 | return CMD_SUCCESS; |
718e3744 | 1334 | } |
1335 | ||
a2c62831 | 1336 | DEFUN (no_ospf_area_shortcut, |
1337 | no_ospf_area_shortcut_cmd, | |
6147e2c6 | 1338 | "no area <A.B.C.D|(0-4294967295)> shortcut <enable|disable>", |
718e3744 | 1339 | NO_STR |
1340 | "OSPF area parameters\n" | |
1341 | "OSPF area ID in IP address format\n" | |
1342 | "OSPF area ID as a decimal value\n" | |
1343 | "Deconfigure the area's shortcutting mode\n" | |
1344 | "Deconfigure enabled shortcutting through the area\n" | |
1345 | "Deconfigure disabled shortcutting through the area\n") | |
1346 | { | |
a3d826f0 | 1347 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1348 | int idx_ipv4_number = 2; |
1349 | struct ospf_area *area; | |
1350 | struct in_addr area_id; | |
1351 | int format; | |
718e3744 | 1352 | |
d62a17ae | 1353 | VTY_GET_OSPF_AREA_ID_NO_BB("shortcut", area_id, format, |
1354 | argv[idx_ipv4_number]->arg); | |
718e3744 | 1355 | |
d62a17ae | 1356 | area = ospf_area_lookup_by_area_id(ospf, area_id); |
1357 | if (!area) | |
1358 | return CMD_SUCCESS; | |
718e3744 | 1359 | |
d62a17ae | 1360 | ospf_area_shortcut_unset(ospf, area); |
718e3744 | 1361 | |
d62a17ae | 1362 | return CMD_SUCCESS; |
718e3744 | 1363 | } |
1364 | ||
6b0655a2 | 1365 | |
a2c62831 | 1366 | DEFUN (ospf_area_stub, |
1367 | ospf_area_stub_cmd, | |
6147e2c6 | 1368 | "area <A.B.C.D|(0-4294967295)> stub", |
718e3744 | 1369 | "OSPF area parameters\n" |
1370 | "OSPF area ID in IP address format\n" | |
1371 | "OSPF area ID as a decimal value\n" | |
1372 | "Configure OSPF area as stub\n") | |
1373 | { | |
a3d826f0 | 1374 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1375 | int idx_ipv4_number = 1; |
1376 | struct in_addr area_id; | |
1377 | int ret, format; | |
1378 | ||
1379 | VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id, format, | |
1380 | argv[idx_ipv4_number]->arg); | |
1381 | ||
1382 | ret = ospf_area_stub_set(ospf, area_id); | |
1383 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
1384 | format); | |
1385 | if (ret == 0) { | |
1386 | vty_out(vty, | |
1387 | "First deconfigure all virtual link through this area\n"); | |
1388 | return CMD_WARNING_CONFIG_FAILED; | |
1389 | } | |
718e3744 | 1390 | |
d62a17ae | 1391 | ospf_area_no_summary_unset(ospf, area_id); |
718e3744 | 1392 | |
d62a17ae | 1393 | return CMD_SUCCESS; |
718e3744 | 1394 | } |
1395 | ||
a2c62831 | 1396 | DEFUN (ospf_area_stub_no_summary, |
1397 | ospf_area_stub_no_summary_cmd, | |
6147e2c6 | 1398 | "area <A.B.C.D|(0-4294967295)> stub no-summary", |
718e3744 | 1399 | "OSPF stub parameters\n" |
1400 | "OSPF area ID in IP address format\n" | |
1401 | "OSPF area ID as a decimal value\n" | |
1402 | "Configure OSPF area as stub\n" | |
1403 | "Do not inject inter-area routes into stub\n") | |
1404 | { | |
a3d826f0 | 1405 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1406 | int idx_ipv4_number = 1; |
1407 | struct in_addr area_id; | |
1408 | int ret, format; | |
1409 | ||
1410 | VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id, format, | |
1411 | argv[idx_ipv4_number]->arg); | |
1412 | ||
1413 | ret = ospf_area_stub_set(ospf, area_id); | |
1414 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
1415 | format); | |
1416 | if (ret == 0) { | |
1417 | vty_out(vty, | |
1418 | "%% Area cannot be stub as it contains a virtual link\n"); | |
1419 | return CMD_WARNING_CONFIG_FAILED; | |
1420 | } | |
718e3744 | 1421 | |
d62a17ae | 1422 | ospf_area_no_summary_set(ospf, area_id); |
718e3744 | 1423 | |
d62a17ae | 1424 | return CMD_SUCCESS; |
718e3744 | 1425 | } |
1426 | ||
a2c62831 | 1427 | DEFUN (no_ospf_area_stub, |
1428 | no_ospf_area_stub_cmd, | |
6147e2c6 | 1429 | "no area <A.B.C.D|(0-4294967295)> stub", |
718e3744 | 1430 | NO_STR |
1431 | "OSPF area parameters\n" | |
1432 | "OSPF area ID in IP address format\n" | |
1433 | "OSPF area ID as a decimal value\n" | |
1434 | "Configure OSPF area as stub\n") | |
1435 | { | |
a3d826f0 | 1436 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1437 | int idx_ipv4_number = 2; |
1438 | struct in_addr area_id; | |
1439 | int format; | |
718e3744 | 1440 | |
d62a17ae | 1441 | VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id, format, |
1442 | argv[idx_ipv4_number]->arg); | |
718e3744 | 1443 | |
d62a17ae | 1444 | ospf_area_stub_unset(ospf, area_id); |
1445 | ospf_area_no_summary_unset(ospf, area_id); | |
718e3744 | 1446 | |
d62a17ae | 1447 | return CMD_SUCCESS; |
718e3744 | 1448 | } |
1449 | ||
a2c62831 | 1450 | DEFUN (no_ospf_area_stub_no_summary, |
1451 | no_ospf_area_stub_no_summary_cmd, | |
6147e2c6 | 1452 | "no area <A.B.C.D|(0-4294967295)> stub no-summary", |
718e3744 | 1453 | NO_STR |
1454 | "OSPF area parameters\n" | |
1455 | "OSPF area ID in IP address format\n" | |
1456 | "OSPF area ID as a decimal value\n" | |
1457 | "Configure OSPF area as stub\n" | |
1458 | "Do not inject inter-area routes into area\n") | |
1459 | { | |
a3d826f0 | 1460 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1461 | int idx_ipv4_number = 2; |
1462 | struct in_addr area_id; | |
1463 | int format; | |
718e3744 | 1464 | |
d62a17ae | 1465 | VTY_GET_OSPF_AREA_ID_NO_BB("stub", area_id, format, |
1466 | argv[idx_ipv4_number]->arg); | |
1467 | ospf_area_no_summary_unset(ospf, area_id); | |
718e3744 | 1468 | |
d62a17ae | 1469 | return CMD_SUCCESS; |
718e3744 | 1470 | } |
1471 | ||
d62a17ae | 1472 | static int ospf_area_nssa_cmd_handler(struct vty *vty, int argc, |
7ef56a73 CS |
1473 | struct cmd_token **argv, int cfg_nosum, |
1474 | int nosum) | |
718e3744 | 1475 | { |
a3d826f0 | 1476 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1477 | struct in_addr area_id; |
1478 | int ret, format; | |
1479 | ||
1480 | VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id, format, argv[1]->arg); | |
1481 | ||
1482 | ret = ospf_area_nssa_set(ospf, area_id); | |
1483 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
1484 | format); | |
1485 | if (ret == 0) { | |
1486 | vty_out(vty, | |
1487 | "%% Area cannot be nssa as it contains a virtual link\n"); | |
1488 | return CMD_WARNING_CONFIG_FAILED; | |
1489 | } | |
1490 | ||
1491 | if (argc > 3) { | |
1492 | if (strncmp(argv[3]->text, "translate-c", 11) == 0) | |
1493 | ospf_area_nssa_translator_role_set( | |
1494 | ospf, area_id, OSPF_NSSA_ROLE_CANDIDATE); | |
1495 | else if (strncmp(argv[3]->text, "translate-n", 11) == 0) | |
1496 | ospf_area_nssa_translator_role_set( | |
1497 | ospf, area_id, OSPF_NSSA_ROLE_NEVER); | |
1498 | else if (strncmp(argv[3]->text, "translate-a", 11) == 0) | |
1499 | ospf_area_nssa_translator_role_set( | |
1500 | ospf, area_id, OSPF_NSSA_ROLE_ALWAYS); | |
1501 | } else { | |
1502 | ospf_area_nssa_translator_role_set(ospf, area_id, | |
1503 | OSPF_NSSA_ROLE_CANDIDATE); | |
1504 | } | |
1505 | ||
7ef56a73 CS |
1506 | if (cfg_nosum) { |
1507 | if (nosum) | |
1508 | ospf_area_no_summary_set(ospf, area_id); | |
1509 | else | |
1510 | ospf_area_no_summary_unset(ospf, area_id); | |
1511 | } | |
d62a17ae | 1512 | |
1513 | ospf_schedule_abr_task(ospf); | |
1514 | ||
1515 | return CMD_SUCCESS; | |
718e3744 | 1516 | } |
1517 | ||
718e3744 | 1518 | |
b0a053be | 1519 | DEFUN (ospf_area_nssa_translate, |
a2c62831 | 1520 | ospf_area_nssa_translate_cmd, |
6147e2c6 | 1521 | "area <A.B.C.D|(0-4294967295)> nssa <translate-candidate|translate-never|translate-always>", |
718e3744 | 1522 | "OSPF area parameters\n" |
1523 | "OSPF area ID in IP address format\n" | |
1524 | "OSPF area ID as a decimal value\n" | |
1525 | "Configure OSPF area as nssa\n" | |
1526 | "Configure NSSA-ABR for translate election (default)\n" | |
1527 | "Configure NSSA-ABR to never translate\n" | |
1528 | "Configure NSSA-ABR to always translate\n") | |
b0a053be | 1529 | { |
7ef56a73 | 1530 | return ospf_area_nssa_cmd_handler(vty, argc, argv, 0, 0); |
b0a053be | 1531 | } |
1532 | ||
1533 | DEFUN (ospf_area_nssa, | |
1534 | ospf_area_nssa_cmd, | |
6147e2c6 | 1535 | "area <A.B.C.D|(0-4294967295)> nssa", |
b0a053be | 1536 | "OSPF area parameters\n" |
1537 | "OSPF area ID in IP address format\n" | |
1538 | "OSPF area ID as a decimal value\n" | |
1539 | "Configure OSPF area as nssa\n") | |
1540 | { | |
7ef56a73 | 1541 | return ospf_area_nssa_cmd_handler(vty, argc, argv, 1, 0); |
b0a053be | 1542 | } |
718e3744 | 1543 | |
a2c62831 | 1544 | DEFUN (ospf_area_nssa_no_summary, |
1545 | ospf_area_nssa_no_summary_cmd, | |
6147e2c6 | 1546 | "area <A.B.C.D|(0-4294967295)> nssa no-summary", |
718e3744 | 1547 | "OSPF area parameters\n" |
1548 | "OSPF area ID in IP address format\n" | |
1549 | "OSPF area ID as a decimal value\n" | |
1550 | "Configure OSPF area as nssa\n" | |
1551 | "Do not inject inter-area routes into nssa\n") | |
1552 | { | |
7ef56a73 CS |
1553 | int idx_ipv4_number = 1; |
1554 | struct in_addr area_id; | |
1555 | int format; | |
1556 | ||
1557 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
1558 | VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id, format, | |
1559 | argv[idx_ipv4_number]->arg); | |
1560 | ||
1561 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
1562 | format); | |
1563 | ospf_area_nssa_no_summary_set(ospf, area_id); | |
1564 | ||
1565 | ospf_schedule_abr_task(ospf); | |
1566 | ||
1567 | return CMD_SUCCESS; | |
1568 | } | |
1569 | ||
1570 | DEFUN (no_ospf_area_nssa_no_summary, | |
1571 | no_ospf_area_nssa_no_summary_cmd, | |
1572 | "no area <A.B.C.D|(0-4294967295)> nssa no-summary", | |
1573 | NO_STR | |
1574 | "OSPF area parameters\n" | |
1575 | "OSPF area ID in IP address format\n" | |
1576 | "OSPF area ID as a decimal value\n" | |
1577 | "Configure OSPF area as nssa\n" | |
1578 | "Do not inject inter-area routes into nssa\n") | |
1579 | { | |
1580 | int idx_ipv4_number = 2; | |
1581 | struct in_addr area_id; | |
1582 | int format; | |
1583 | ||
1584 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); | |
1585 | ||
1586 | VTY_GET_OSPF_AREA_ID_NO_BB("nssa", area_id, format, | |
1587 | argv[idx_ipv4_number]->arg); | |
1588 | ||
1589 | ospf_area_display_format_set(ospf, ospf_area_get(ospf, area_id), | |
1590 | format); | |
1591 | ospf_area_no_summary_unset(ospf, area_id); | |
1592 | ||
1593 | ospf_schedule_abr_task(ospf); | |
1594 | ||
1595 | return CMD_SUCCESS; | |
718e3744 | 1596 | } |
1597 | ||
a2c62831 | 1598 | DEFUN (no_ospf_area_nssa, |
1599 | no_ospf_area_nssa_cmd, | |
7ef56a73 | 1600 | "no area <A.B.C.D|(0-4294967295)> nssa [<translate-candidate|translate-never|translate-always>]", |
718e3744 | 1601 | NO_STR |
1602 | "OSPF area parameters\n" | |
1603 | "OSPF area ID in IP address format\n" | |
1604 | "OSPF area ID as a decimal value\n" | |
7a7be519 | 1605 | "Configure OSPF area as nssa\n" |
1606 | "Configure NSSA-ABR for translate election (default)\n" | |
1607 | "Configure NSSA-ABR to never translate\n" | |
7ef56a73 | 1608 | "Configure NSSA-ABR to always translate\n") |
22b27e95 | 1609 | { |
a3d826f0 | 1610 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1611 | int idx_ipv4_number = 2; |
1612 | struct in_addr area_id; | |
1613 | int format; | |
718e3744 | 1614 | |
d62a17ae | 1615 | VTY_GET_OSPF_AREA_ID_NO_BB("NSSA", area_id, format, |
1616 | argv[idx_ipv4_number]->arg); | |
718e3744 | 1617 | |
7ef56a73 | 1618 | ospf_area_nssa_unset(ospf, area_id, argc); |
718e3744 | 1619 | |
d62a17ae | 1620 | ospf_schedule_abr_task(ospf); |
b0a053be | 1621 | |
d62a17ae | 1622 | return CMD_SUCCESS; |
718e3744 | 1623 | } |
1624 | ||
718e3744 | 1625 | |
a2c62831 | 1626 | DEFUN (ospf_area_default_cost, |
1627 | ospf_area_default_cost_cmd, | |
6147e2c6 | 1628 | "area <A.B.C.D|(0-4294967295)> default-cost (0-16777215)", |
718e3744 | 1629 | "OSPF area parameters\n" |
1630 | "OSPF area ID in IP address format\n" | |
1631 | "OSPF area ID as a decimal value\n" | |
1632 | "Set the summary-default cost of a NSSA or stub area\n" | |
1633 | "Stub's advertised default summary cost\n") | |
1634 | { | |
a3d826f0 | 1635 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1636 | int idx_ipv4_number = 1; |
1637 | int idx_number = 3; | |
1638 | struct ospf_area *area; | |
1639 | struct in_addr area_id; | |
1640 | u_int32_t cost; | |
1641 | int format; | |
1642 | struct prefix_ipv4 p; | |
1643 | ||
1644 | VTY_GET_OSPF_AREA_ID_NO_BB("default-cost", area_id, format, | |
1645 | argv[idx_ipv4_number]->arg); | |
1646 | cost = strtoul(argv[idx_number]->arg, NULL, 10); | |
1647 | ||
1648 | area = ospf_area_get(ospf, area_id); | |
1649 | ospf_area_display_format_set(ospf, area, format); | |
1650 | ||
1651 | if (area->external_routing == OSPF_AREA_DEFAULT) { | |
1652 | vty_out(vty, "The area is neither stub, nor NSSA\n"); | |
1653 | return CMD_WARNING_CONFIG_FAILED; | |
1654 | } | |
ba682537 | 1655 | |
d62a17ae | 1656 | area->default_cost = cost; |
1657 | ||
1658 | p.family = AF_INET; | |
1659 | p.prefix.s_addr = OSPF_DEFAULT_DESTINATION; | |
1660 | p.prefixlen = 0; | |
1661 | if (IS_DEBUG_OSPF_EVENT) | |
1662 | zlog_debug( | |
1663 | "ospf_abr_announce_stub_defaults(): " | |
1664 | "announcing 0.0.0.0/0 to area %s", | |
1665 | inet_ntoa(area->area_id)); | |
1666 | ospf_abr_announce_network_to_area(&p, area->default_cost, area); | |
1667 | ||
1668 | return CMD_SUCCESS; | |
718e3744 | 1669 | } |
1670 | ||
a2c62831 | 1671 | DEFUN (no_ospf_area_default_cost, |
1672 | no_ospf_area_default_cost_cmd, | |
6147e2c6 | 1673 | "no area <A.B.C.D|(0-4294967295)> default-cost (0-16777215)", |
718e3744 | 1674 | NO_STR |
1675 | "OSPF area parameters\n" | |
1676 | "OSPF area ID in IP address format\n" | |
1677 | "OSPF area ID as a decimal value\n" | |
1678 | "Set the summary-default cost of a NSSA or stub area\n" | |
1679 | "Stub's advertised default summary cost\n") | |
1680 | { | |
a3d826f0 | 1681 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1682 | int idx_ipv4_number = 2; |
1683 | struct ospf_area *area; | |
1684 | struct in_addr area_id; | |
1685 | int format; | |
1686 | struct prefix_ipv4 p; | |
718e3744 | 1687 | |
d62a17ae | 1688 | VTY_GET_OSPF_AREA_ID_NO_BB("default-cost", area_id, format, |
1689 | argv[idx_ipv4_number]->arg); | |
718e3744 | 1690 | |
d62a17ae | 1691 | area = ospf_area_lookup_by_area_id(ospf, area_id); |
1692 | if (area == NULL) | |
1693 | return CMD_SUCCESS; | |
718e3744 | 1694 | |
d62a17ae | 1695 | if (area->external_routing == OSPF_AREA_DEFAULT) { |
1696 | vty_out(vty, "The area is neither stub, nor NSSA\n"); | |
1697 | return CMD_WARNING_CONFIG_FAILED; | |
1698 | } | |
718e3744 | 1699 | |
d62a17ae | 1700 | area->default_cost = 1; |
718e3744 | 1701 | |
d62a17ae | 1702 | p.family = AF_INET; |
1703 | p.prefix.s_addr = OSPF_DEFAULT_DESTINATION; | |
1704 | p.prefixlen = 0; | |
1705 | if (IS_DEBUG_OSPF_EVENT) | |
1706 | zlog_debug( | |
1707 | "ospf_abr_announce_stub_defaults(): " | |
1708 | "announcing 0.0.0.0/0 to area %s", | |
1709 | inet_ntoa(area->area_id)); | |
1710 | ospf_abr_announce_network_to_area(&p, area->default_cost, area); | |
ba682537 | 1711 | |
1712 | ||
d62a17ae | 1713 | ospf_area_check_free(ospf, area_id); |
718e3744 | 1714 | |
d62a17ae | 1715 | return CMD_SUCCESS; |
718e3744 | 1716 | } |
1717 | ||
a2c62831 | 1718 | DEFUN (ospf_area_export_list, |
1719 | ospf_area_export_list_cmd, | |
6147e2c6 | 1720 | "area <A.B.C.D|(0-4294967295)> export-list NAME", |
718e3744 | 1721 | "OSPF area parameters\n" |
1722 | "OSPF area ID in IP address format\n" | |
1723 | "OSPF area ID as a decimal value\n" | |
1724 | "Set the filter for networks announced to other areas\n" | |
1725 | "Name of the access-list\n") | |
1726 | { | |
a3d826f0 | 1727 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1728 | int idx_ipv4_number = 1; |
1729 | struct ospf_area *area; | |
1730 | struct in_addr area_id; | |
1731 | int format; | |
718e3744 | 1732 | |
d62a17ae | 1733 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
52930766 | 1734 | |
d62a17ae | 1735 | area = ospf_area_get(ospf, area_id); |
1736 | ospf_area_display_format_set(ospf, area, format); | |
1737 | ospf_area_export_list_set(ospf, area, argv[3]->arg); | |
718e3744 | 1738 | |
d62a17ae | 1739 | return CMD_SUCCESS; |
718e3744 | 1740 | } |
1741 | ||
a2c62831 | 1742 | DEFUN (no_ospf_area_export_list, |
1743 | no_ospf_area_export_list_cmd, | |
6147e2c6 | 1744 | "no area <A.B.C.D|(0-4294967295)> export-list NAME", |
718e3744 | 1745 | NO_STR |
1746 | "OSPF area parameters\n" | |
1747 | "OSPF area ID in IP address format\n" | |
1748 | "OSPF area ID as a decimal value\n" | |
1749 | "Unset the filter for networks announced to other areas\n" | |
1750 | "Name of the access-list\n") | |
1751 | { | |
a3d826f0 | 1752 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1753 | int idx_ipv4_number = 2; |
1754 | struct ospf_area *area; | |
1755 | struct in_addr area_id; | |
1756 | int format; | |
718e3744 | 1757 | |
d62a17ae | 1758 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
52930766 | 1759 | |
d62a17ae | 1760 | area = ospf_area_lookup_by_area_id(ospf, area_id); |
1761 | if (area == NULL) | |
1762 | return CMD_SUCCESS; | |
718e3744 | 1763 | |
d62a17ae | 1764 | ospf_area_export_list_unset(ospf, area); |
718e3744 | 1765 | |
d62a17ae | 1766 | return CMD_SUCCESS; |
718e3744 | 1767 | } |
1768 | ||
1769 | ||
a2c62831 | 1770 | DEFUN (ospf_area_import_list, |
1771 | ospf_area_import_list_cmd, | |
6147e2c6 | 1772 | "area <A.B.C.D|(0-4294967295)> import-list NAME", |
718e3744 | 1773 | "OSPF area parameters\n" |
1774 | "OSPF area ID in IP address format\n" | |
1775 | "OSPF area ID as a decimal value\n" | |
1776 | "Set the filter for networks from other areas announced to the specified one\n" | |
1777 | "Name of the access-list\n") | |
1778 | { | |
a3d826f0 | 1779 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1780 | int idx_ipv4_number = 1; |
1781 | struct ospf_area *area; | |
1782 | struct in_addr area_id; | |
1783 | int format; | |
718e3744 | 1784 | |
d62a17ae | 1785 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
52930766 | 1786 | |
d62a17ae | 1787 | area = ospf_area_get(ospf, area_id); |
1788 | ospf_area_display_format_set(ospf, area, format); | |
1789 | ospf_area_import_list_set(ospf, area, argv[3]->arg); | |
718e3744 | 1790 | |
d62a17ae | 1791 | return CMD_SUCCESS; |
718e3744 | 1792 | } |
1793 | ||
a2c62831 | 1794 | DEFUN (no_ospf_area_import_list, |
1795 | no_ospf_area_import_list_cmd, | |
6147e2c6 | 1796 | "no area <A.B.C.D|(0-4294967295)> import-list NAME", |
718e3744 | 1797 | NO_STR |
1798 | "OSPF area parameters\n" | |
1799 | "OSPF area ID in IP address format\n" | |
1800 | "OSPF area ID as a decimal value\n" | |
1801 | "Unset the filter for networks announced to other areas\n" | |
1802 | "Name of the access-list\n") | |
1803 | { | |
a3d826f0 | 1804 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1805 | int idx_ipv4_number = 2; |
1806 | struct ospf_area *area; | |
1807 | struct in_addr area_id; | |
1808 | int format; | |
718e3744 | 1809 | |
d62a17ae | 1810 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
52930766 | 1811 | |
d62a17ae | 1812 | area = ospf_area_lookup_by_area_id(ospf, area_id); |
1813 | if (area == NULL) | |
1814 | return CMD_SUCCESS; | |
718e3744 | 1815 | |
d62a17ae | 1816 | ospf_area_import_list_unset(ospf, area); |
718e3744 | 1817 | |
d62a17ae | 1818 | return CMD_SUCCESS; |
718e3744 | 1819 | } |
1820 | ||
a2c62831 | 1821 | DEFUN (ospf_area_filter_list, |
1822 | ospf_area_filter_list_cmd, | |
6147e2c6 | 1823 | "area <A.B.C.D|(0-4294967295)> filter-list prefix WORD <in|out>", |
718e3744 | 1824 | "OSPF area parameters\n" |
1825 | "OSPF area ID in IP address format\n" | |
1826 | "OSPF area ID as a decimal value\n" | |
1827 | "Filter networks between OSPF areas\n" | |
1828 | "Filter prefixes between OSPF areas\n" | |
1829 | "Name of an IP prefix-list\n" | |
1830 | "Filter networks sent to this area\n" | |
1831 | "Filter networks sent from this area\n") | |
1832 | { | |
a3d826f0 | 1833 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1834 | int idx_ipv4_number = 1; |
1835 | int idx_word = 4; | |
1836 | int idx_in_out = 5; | |
1837 | struct ospf_area *area; | |
1838 | struct in_addr area_id; | |
1839 | struct prefix_list *plist; | |
1840 | int format; | |
1841 | ||
1842 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); | |
1843 | ||
1844 | area = ospf_area_get(ospf, area_id); | |
1845 | ospf_area_display_format_set(ospf, area, format); | |
1846 | plist = prefix_list_lookup(AFI_IP, argv[idx_word]->arg); | |
1847 | if (strncmp(argv[idx_in_out]->arg, "in", 2) == 0) { | |
1848 | PREFIX_LIST_IN(area) = plist; | |
1849 | if (PREFIX_NAME_IN(area)) | |
1850 | free(PREFIX_NAME_IN(area)); | |
1851 | ||
1852 | PREFIX_NAME_IN(area) = strdup(argv[idx_word]->arg); | |
1853 | ospf_schedule_abr_task(ospf); | |
1854 | } else { | |
1855 | PREFIX_LIST_OUT(area) = plist; | |
1856 | if (PREFIX_NAME_OUT(area)) | |
1857 | free(PREFIX_NAME_OUT(area)); | |
1858 | ||
1859 | PREFIX_NAME_OUT(area) = strdup(argv[idx_word]->arg); | |
1860 | ospf_schedule_abr_task(ospf); | |
1861 | } | |
718e3744 | 1862 | |
d62a17ae | 1863 | return CMD_SUCCESS; |
718e3744 | 1864 | } |
1865 | ||
a2c62831 | 1866 | DEFUN (no_ospf_area_filter_list, |
1867 | no_ospf_area_filter_list_cmd, | |
6147e2c6 | 1868 | "no area <A.B.C.D|(0-4294967295)> filter-list prefix WORD <in|out>", |
718e3744 | 1869 | NO_STR |
1870 | "OSPF area parameters\n" | |
1871 | "OSPF area ID in IP address format\n" | |
1872 | "OSPF area ID as a decimal value\n" | |
1873 | "Filter networks between OSPF areas\n" | |
1874 | "Filter prefixes between OSPF areas\n" | |
1875 | "Name of an IP prefix-list\n" | |
1876 | "Filter networks sent to this area\n" | |
1877 | "Filter networks sent from this area\n") | |
1878 | { | |
a3d826f0 | 1879 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1880 | int idx_ipv4_number = 2; |
1881 | int idx_word = 5; | |
1882 | int idx_in_out = 6; | |
1883 | struct ospf_area *area; | |
1884 | struct in_addr area_id; | |
1885 | int format; | |
718e3744 | 1886 | |
d62a17ae | 1887 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
718e3744 | 1888 | |
d62a17ae | 1889 | if ((area = ospf_area_lookup_by_area_id(ospf, area_id)) == NULL) |
1890 | return CMD_SUCCESS; | |
718e3744 | 1891 | |
d62a17ae | 1892 | if (strncmp(argv[idx_in_out]->arg, "in", 2) == 0) { |
1893 | if (PREFIX_NAME_IN(area)) | |
1894 | if (strcmp(PREFIX_NAME_IN(area), argv[idx_word]->arg) | |
1895 | != 0) | |
1896 | return CMD_SUCCESS; | |
718e3744 | 1897 | |
d62a17ae | 1898 | PREFIX_LIST_IN(area) = NULL; |
1899 | if (PREFIX_NAME_IN(area)) | |
1900 | free(PREFIX_NAME_IN(area)); | |
718e3744 | 1901 | |
d62a17ae | 1902 | PREFIX_NAME_IN(area) = NULL; |
718e3744 | 1903 | |
d62a17ae | 1904 | ospf_schedule_abr_task(ospf); |
1905 | } else { | |
1906 | if (PREFIX_NAME_OUT(area)) | |
1907 | if (strcmp(PREFIX_NAME_OUT(area), argv[idx_word]->arg) | |
1908 | != 0) | |
1909 | return CMD_SUCCESS; | |
718e3744 | 1910 | |
d62a17ae | 1911 | PREFIX_LIST_OUT(area) = NULL; |
1912 | if (PREFIX_NAME_OUT(area)) | |
1913 | free(PREFIX_NAME_OUT(area)); | |
718e3744 | 1914 | |
d62a17ae | 1915 | PREFIX_NAME_OUT(area) = NULL; |
718e3744 | 1916 | |
d62a17ae | 1917 | ospf_schedule_abr_task(ospf); |
1918 | } | |
1919 | ||
1920 | return CMD_SUCCESS; | |
718e3744 | 1921 | } |
1922 | ||
6b0655a2 | 1923 | |
a2c62831 | 1924 | DEFUN (ospf_area_authentication_message_digest, |
1925 | ospf_area_authentication_message_digest_cmd, | |
32573073 QY |
1926 | "[no] area <A.B.C.D|(0-4294967295)> authentication message-digest", |
1927 | NO_STR | |
718e3744 | 1928 | "OSPF area parameters\n" |
2b00515a CF |
1929 | "OSPF area ID in IP address format\n" |
1930 | "OSPF area ID as a decimal value\n" | |
718e3744 | 1931 | "Enable authentication\n" |
1932 | "Use message-digest authentication\n") | |
1933 | { | |
a3d826f0 | 1934 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1935 | int idx_ipv4_number = 1; |
1936 | struct ospf_area *area; | |
1937 | struct in_addr area_id; | |
1938 | int format; | |
718e3744 | 1939 | |
d62a17ae | 1940 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
718e3744 | 1941 | |
d62a17ae | 1942 | area = ospf_area_get(ospf, area_id); |
1943 | ospf_area_display_format_set(ospf, area, format); | |
32573073 | 1944 | area->auth_type = strmatch(argv[0]->text, "no") ? OSPF_AUTH_NULL : OSPF_AUTH_CRYPTOGRAPHIC; |
718e3744 | 1945 | |
d62a17ae | 1946 | return CMD_SUCCESS; |
718e3744 | 1947 | } |
1948 | ||
a2c62831 | 1949 | DEFUN (ospf_area_authentication, |
1950 | ospf_area_authentication_cmd, | |
6147e2c6 | 1951 | "area <A.B.C.D|(0-4294967295)> authentication", |
718e3744 | 1952 | "OSPF area parameters\n" |
1953 | "OSPF area ID in IP address format\n" | |
1954 | "OSPF area ID as a decimal value\n" | |
1955 | "Enable authentication\n") | |
1956 | { | |
a3d826f0 | 1957 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1958 | int idx_ipv4_number = 1; |
1959 | struct ospf_area *area; | |
1960 | struct in_addr area_id; | |
1961 | int format; | |
718e3744 | 1962 | |
d62a17ae | 1963 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
718e3744 | 1964 | |
d62a17ae | 1965 | area = ospf_area_get(ospf, area_id); |
1966 | ospf_area_display_format_set(ospf, area, format); | |
1967 | area->auth_type = OSPF_AUTH_SIMPLE; | |
718e3744 | 1968 | |
d62a17ae | 1969 | return CMD_SUCCESS; |
718e3744 | 1970 | } |
1971 | ||
a2c62831 | 1972 | DEFUN (no_ospf_area_authentication, |
1973 | no_ospf_area_authentication_cmd, | |
6147e2c6 | 1974 | "no area <A.B.C.D|(0-4294967295)> authentication", |
718e3744 | 1975 | NO_STR |
1976 | "OSPF area parameters\n" | |
1977 | "OSPF area ID in IP address format\n" | |
1978 | "OSPF area ID as a decimal value\n" | |
1979 | "Enable authentication\n") | |
1980 | { | |
a3d826f0 | 1981 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 1982 | int idx_ipv4_number = 2; |
1983 | struct ospf_area *area; | |
1984 | struct in_addr area_id; | |
1985 | int format; | |
718e3744 | 1986 | |
d62a17ae | 1987 | VTY_GET_OSPF_AREA_ID(area_id, format, argv[idx_ipv4_number]->arg); |
718e3744 | 1988 | |
d62a17ae | 1989 | area = ospf_area_lookup_by_area_id(ospf, area_id); |
1990 | if (area == NULL) | |
1991 | return CMD_SUCCESS; | |
718e3744 | 1992 | |
d62a17ae | 1993 | area->auth_type = OSPF_AUTH_NULL; |
718e3744 | 1994 | |
d62a17ae | 1995 | ospf_area_check_free(ospf, area_id); |
1996 | ||
1997 | return CMD_SUCCESS; | |
718e3744 | 1998 | } |
1999 | ||
6b0655a2 | 2000 | |
718e3744 | 2001 | DEFUN (ospf_abr_type, |
2002 | ospf_abr_type_cmd, | |
6147e2c6 | 2003 | "ospf abr-type <cisco|ibm|shortcut|standard>", |
718e3744 | 2004 | "OSPF specific commands\n" |
2005 | "Set OSPF ABR type\n" | |
2006 | "Alternative ABR, cisco implementation\n" | |
2007 | "Alternative ABR, IBM implementation\n" | |
2008 | "Shortcut ABR\n" | |
2009 | "Standard behavior (RFC2328)\n") | |
2010 | { | |
a3d826f0 | 2011 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2012 | int idx_vendor = 2; |
2013 | u_char abr_type = OSPF_ABR_UNKNOWN; | |
2014 | ||
2015 | if (strncmp(argv[idx_vendor]->arg, "c", 1) == 0) | |
2016 | abr_type = OSPF_ABR_CISCO; | |
2017 | else if (strncmp(argv[idx_vendor]->arg, "i", 1) == 0) | |
2018 | abr_type = OSPF_ABR_IBM; | |
2019 | else if (strncmp(argv[idx_vendor]->arg, "sh", 2) == 0) | |
2020 | abr_type = OSPF_ABR_SHORTCUT; | |
2021 | else if (strncmp(argv[idx_vendor]->arg, "st", 2) == 0) | |
2022 | abr_type = OSPF_ABR_STAND; | |
2023 | else | |
2024 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 2025 | |
d62a17ae | 2026 | /* If ABR type value is changed, schedule ABR task. */ |
2027 | if (ospf->abr_type != abr_type) { | |
2028 | ospf->abr_type = abr_type; | |
2029 | ospf_schedule_abr_task(ospf); | |
2030 | } | |
2031 | ||
2032 | return CMD_SUCCESS; | |
718e3744 | 2033 | } |
2034 | ||
2035 | DEFUN (no_ospf_abr_type, | |
2036 | no_ospf_abr_type_cmd, | |
6147e2c6 | 2037 | "no ospf abr-type <cisco|ibm|shortcut|standard>", |
718e3744 | 2038 | NO_STR |
2039 | "OSPF specific commands\n" | |
2040 | "Set OSPF ABR type\n" | |
2041 | "Alternative ABR, cisco implementation\n" | |
2042 | "Alternative ABR, IBM implementation\n" | |
3a2d747c QY |
2043 | "Shortcut ABR\n" |
2044 | "Standard ABR\n") | |
718e3744 | 2045 | { |
a3d826f0 | 2046 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2047 | int idx_vendor = 3; |
2048 | u_char abr_type = OSPF_ABR_UNKNOWN; | |
2049 | ||
2050 | if (strncmp(argv[idx_vendor]->arg, "c", 1) == 0) | |
2051 | abr_type = OSPF_ABR_CISCO; | |
2052 | else if (strncmp(argv[idx_vendor]->arg, "i", 1) == 0) | |
2053 | abr_type = OSPF_ABR_IBM; | |
2054 | else if (strncmp(argv[idx_vendor]->arg, "sh", 2) == 0) | |
2055 | abr_type = OSPF_ABR_SHORTCUT; | |
2056 | else if (strncmp(argv[idx_vendor]->arg, "st", 2) == 0) | |
2057 | abr_type = OSPF_ABR_STAND; | |
2058 | else | |
2059 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 2060 | |
d62a17ae | 2061 | /* If ABR type value is changed, schedule ABR task. */ |
2062 | if (ospf->abr_type == abr_type) { | |
2063 | ospf->abr_type = OSPF_ABR_DEFAULT; | |
2064 | ospf_schedule_abr_task(ospf); | |
2065 | } | |
2066 | ||
2067 | return CMD_SUCCESS; | |
718e3744 | 2068 | } |
2069 | ||
d7e60dd7 AS |
2070 | DEFUN (ospf_log_adjacency_changes, |
2071 | ospf_log_adjacency_changes_cmd, | |
2072 | "log-adjacency-changes", | |
2073 | "Log changes in adjacency state\n") | |
2074 | { | |
a3d826f0 | 2075 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d7e60dd7 | 2076 | |
d62a17ae | 2077 | SET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES); |
2078 | UNSET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL); | |
2079 | return CMD_SUCCESS; | |
d7e60dd7 AS |
2080 | } |
2081 | ||
2082 | DEFUN (ospf_log_adjacency_changes_detail, | |
2083 | ospf_log_adjacency_changes_detail_cmd, | |
2084 | "log-adjacency-changes detail", | |
2085 | "Log changes in adjacency state\n" | |
2086 | "Log all state changes\n") | |
2087 | { | |
a3d826f0 | 2088 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d7e60dd7 | 2089 | |
d62a17ae | 2090 | SET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES); |
2091 | SET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL); | |
2092 | return CMD_SUCCESS; | |
d7e60dd7 AS |
2093 | } |
2094 | ||
2095 | DEFUN (no_ospf_log_adjacency_changes, | |
2096 | no_ospf_log_adjacency_changes_cmd, | |
2097 | "no log-adjacency-changes", | |
2098 | NO_STR | |
2099 | "Log changes in adjacency state\n") | |
2100 | { | |
a3d826f0 | 2101 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d7e60dd7 | 2102 | |
d62a17ae | 2103 | UNSET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL); |
2104 | UNSET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES); | |
2105 | return CMD_SUCCESS; | |
d7e60dd7 AS |
2106 | } |
2107 | ||
2108 | DEFUN (no_ospf_log_adjacency_changes_detail, | |
2109 | no_ospf_log_adjacency_changes_detail_cmd, | |
2110 | "no log-adjacency-changes detail", | |
2111 | NO_STR | |
2112 | "Log changes in adjacency state\n" | |
2113 | "Log all state changes\n") | |
2114 | { | |
a3d826f0 | 2115 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d7e60dd7 | 2116 | |
d62a17ae | 2117 | UNSET_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL); |
2118 | return CMD_SUCCESS; | |
d7e60dd7 AS |
2119 | } |
2120 | ||
718e3744 | 2121 | DEFUN (ospf_compatible_rfc1583, |
2122 | ospf_compatible_rfc1583_cmd, | |
2123 | "compatible rfc1583", | |
2124 | "OSPF compatibility list\n" | |
2125 | "compatible with RFC 1583\n") | |
2126 | { | |
a3d826f0 | 2127 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
718e3744 | 2128 | |
d62a17ae | 2129 | if (!CHECK_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE)) { |
2130 | SET_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE); | |
2131 | ospf_spf_calculate_schedule(ospf, SPF_FLAG_CONFIG_CHANGE); | |
2132 | } | |
2133 | return CMD_SUCCESS; | |
718e3744 | 2134 | } |
2135 | ||
2136 | DEFUN (no_ospf_compatible_rfc1583, | |
2137 | no_ospf_compatible_rfc1583_cmd, | |
2138 | "no compatible rfc1583", | |
2139 | NO_STR | |
2140 | "OSPF compatibility list\n" | |
2141 | "compatible with RFC 1583\n") | |
2142 | { | |
a3d826f0 | 2143 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
718e3744 | 2144 | |
d62a17ae | 2145 | if (CHECK_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE)) { |
2146 | UNSET_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE); | |
2147 | ospf_spf_calculate_schedule(ospf, SPF_FLAG_CONFIG_CHANGE); | |
2148 | } | |
2149 | return CMD_SUCCESS; | |
718e3744 | 2150 | } |
2151 | ||
d62a17ae | 2152 | ALIAS(ospf_compatible_rfc1583, ospf_rfc1583_flag_cmd, |
2153 | "ospf rfc1583compatibility", | |
2154 | "OSPF specific commands\n" | |
2155 | "Enable the RFC1583Compatibility flag\n") | |
718e3744 | 2156 | |
d62a17ae | 2157 | ALIAS(no_ospf_compatible_rfc1583, no_ospf_rfc1583_flag_cmd, |
9d303b37 | 2158 | "no ospf rfc1583compatibility", NO_STR |
d62a17ae | 2159 | "OSPF specific commands\n" |
2160 | "Disable the RFC1583Compatibility flag\n") | |
6b0655a2 | 2161 | |
d62a17ae | 2162 | static int ospf_timers_spf_set(struct vty *vty, unsigned int delay, |
2163 | unsigned int hold, unsigned int max) | |
d24f6e2a | 2164 | { |
a3d826f0 | 2165 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
7c8ff89e | 2166 | |
d62a17ae | 2167 | ospf->spf_delay = delay; |
2168 | ospf->spf_holdtime = hold; | |
2169 | ospf->spf_max_holdtime = max; | |
2170 | ||
2171 | return CMD_SUCCESS; | |
d24f6e2a | 2172 | } |
718e3744 | 2173 | |
ac7424f9 MR |
2174 | DEFUN (ospf_timers_min_ls_interval, |
2175 | ospf_timers_min_ls_interval_cmd, | |
6147e2c6 | 2176 | "timers throttle lsa all (0-5000)", |
ac7424f9 MR |
2177 | "Adjust routing timers\n" |
2178 | "Throttling adaptive timer\n" | |
2179 | "LSA delay between transmissions\n" | |
813d4307 | 2180 | "All LSA types\n" |
ac7424f9 MR |
2181 | "Delay (msec) between sending LSAs\n") |
2182 | { | |
a3d826f0 | 2183 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2184 | int idx_number = 4; |
2185 | unsigned int interval; | |
ac7424f9 | 2186 | |
d62a17ae | 2187 | if (argc < 5) { |
2188 | vty_out(vty, "Insufficient arguments\n"); | |
2189 | return CMD_WARNING_CONFIG_FAILED; | |
2190 | } | |
ac7424f9 | 2191 | |
d62a17ae | 2192 | interval = strtoul(argv[idx_number]->arg, NULL, 10); |
ac7424f9 | 2193 | |
d62a17ae | 2194 | ospf->min_ls_interval = interval; |
ac7424f9 | 2195 | |
d62a17ae | 2196 | return CMD_SUCCESS; |
ac7424f9 MR |
2197 | } |
2198 | ||
2199 | DEFUN (no_ospf_timers_min_ls_interval, | |
2200 | no_ospf_timers_min_ls_interval_cmd, | |
7a7be519 | 2201 | "no timers throttle lsa all [(0-5000)]", |
ac7424f9 MR |
2202 | NO_STR |
2203 | "Adjust routing timers\n" | |
2204 | "Throttling adaptive timer\n" | |
813d4307 | 2205 | "LSA delay between transmissions\n" |
7a7be519 | 2206 | "All LSA types\n" |
2207 | "Delay (msec) between sending LSAs\n") | |
ac7424f9 | 2208 | { |
a3d826f0 | 2209 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2210 | ospf->min_ls_interval = OSPF_MIN_LS_INTERVAL; |
ac7424f9 | 2211 | |
d62a17ae | 2212 | return CMD_SUCCESS; |
ac7424f9 MR |
2213 | } |
2214 | ||
d24f6e2a | 2215 | DEFUN (ospf_timers_throttle_spf, |
2216 | ospf_timers_throttle_spf_cmd, | |
6147e2c6 | 2217 | "timers throttle spf (0-600000) (0-600000) (0-600000)", |
d24f6e2a | 2218 | "Adjust routing timers\n" |
2219 | "Throttling adaptive timer\n" | |
2220 | "OSPF SPF timers\n" | |
2221 | "Delay (msec) from first change received till SPF calculation\n" | |
2222 | "Initial hold time (msec) between consecutive SPF calculations\n" | |
2223 | "Maximum hold time (msec)\n") | |
2224 | { | |
d62a17ae | 2225 | int idx_number = 3; |
2226 | int idx_number_2 = 4; | |
2227 | int idx_number_3 = 5; | |
2228 | unsigned int delay, hold, max; | |
2229 | ||
2230 | if (argc < 6) { | |
2231 | vty_out(vty, "Insufficient arguments\n"); | |
2232 | return CMD_WARNING_CONFIG_FAILED; | |
2233 | } | |
2234 | ||
2235 | delay = strtoul(argv[idx_number]->arg, NULL, 10); | |
2236 | hold = strtoul(argv[idx_number_2]->arg, NULL, 10); | |
2237 | max = strtoul(argv[idx_number_3]->arg, NULL, 10); | |
2238 | ||
2239 | return ospf_timers_spf_set(vty, delay, hold, max); | |
d24f6e2a | 2240 | } |
2241 | ||
d24f6e2a | 2242 | DEFUN (no_ospf_timers_throttle_spf, |
2243 | no_ospf_timers_throttle_spf_cmd, | |
7a7be519 | 2244 | "no timers throttle spf [(0-600000)(0-600000)(0-600000)]", |
718e3744 | 2245 | NO_STR |
2246 | "Adjust routing timers\n" | |
d24f6e2a | 2247 | "Throttling adaptive timer\n" |
7a7be519 | 2248 | "OSPF SPF timers\n" |
2249 | "Delay (msec) from first change received till SPF calculation\n" | |
2250 | "Initial hold time (msec) between consecutive SPF calculations\n" | |
2251 | "Maximum hold time (msec)\n") | |
22b27e95 | 2252 | { |
d62a17ae | 2253 | return ospf_timers_spf_set(vty, OSPF_SPF_DELAY_DEFAULT, |
2254 | OSPF_SPF_HOLDTIME_DEFAULT, | |
2255 | OSPF_SPF_MAX_HOLDTIME_DEFAULT); | |
718e3744 | 2256 | } |
2257 | ||
b4a039bf | 2258 | |
0e88de35 QY |
2259 | DEFUN (ospf_timers_lsa_min_arrival, |
2260 | ospf_timers_lsa_min_arrival_cmd, | |
6147e2c6 | 2261 | "timers lsa min-arrival (0-600000)", |
b6927875 DS |
2262 | "Adjust routing timers\n" |
2263 | "OSPF LSA timers\n" | |
2264 | "Minimum delay in receiving new version of a LSA\n" | |
2265 | "Delay in milliseconds\n") | |
2266 | { | |
a3d826f0 | 2267 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
0e88de35 | 2268 | ospf->min_ls_arrival = strtoul(argv[argc - 1]->arg, NULL, 10); |
d62a17ae | 2269 | return CMD_SUCCESS; |
b6927875 DS |
2270 | } |
2271 | ||
0e88de35 QY |
2272 | DEFUN (no_ospf_timers_lsa_min_arrival, |
2273 | no_ospf_timers_lsa_min_arrival_cmd, | |
7a7be519 | 2274 | "no timers lsa min-arrival [(0-600000)]", |
b6927875 DS |
2275 | NO_STR |
2276 | "Adjust routing timers\n" | |
2277 | "OSPF LSA timers\n" | |
7a7be519 | 2278 | "Minimum delay in receiving new version of a LSA\n" |
2279 | "Delay in milliseconds\n") | |
b6927875 | 2280 | { |
a3d826f0 | 2281 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2282 | unsigned int minarrival; |
b6927875 | 2283 | |
d62a17ae | 2284 | if (argc > 4) { |
0e88de35 | 2285 | minarrival = strtoul(argv[argc - 1]->arg, NULL, 10); |
b6927875 | 2286 | |
d62a17ae | 2287 | if (ospf->min_ls_arrival != minarrival |
2288 | || minarrival == OSPF_MIN_LS_ARRIVAL) | |
2289 | return CMD_SUCCESS; | |
2290 | } | |
b6927875 | 2291 | |
d62a17ae | 2292 | ospf->min_ls_arrival = OSPF_MIN_LS_ARRIVAL; |
b6927875 | 2293 | |
d62a17ae | 2294 | return CMD_SUCCESS; |
b6927875 DS |
2295 | } |
2296 | ||
5d1a2ee8 QY |
2297 | #if CONFDATE > 20180708 |
2298 | CPP_NOTICE("ospf: `timers lsa arrival (0-1000)` deprecated 2017/07/08") | |
2299 | #endif | |
0e88de35 QY |
2300 | ALIAS_HIDDEN (ospf_timers_lsa_min_arrival, |
2301 | ospf_timers_lsa_arrival_cmd, | |
2302 | "timers lsa arrival (0-1000)", | |
2303 | "adjust routing timers\n" | |
2304 | "throttling link state advertisement delays\n" | |
2305 | "ospf minimum arrival interval delay\n" | |
2306 | "delay (msec) between accepted lsas\n"); | |
2307 | ||
5d1a2ee8 QY |
2308 | #if CONFDATE > 20180708 |
2309 | CPP_NOTICE("ospf: `no timers lsa arrival (0-1000)` deprecated 2017/07/08") | |
2310 | #endif | |
0e88de35 QY |
2311 | ALIAS_HIDDEN (no_ospf_timers_lsa_min_arrival, |
2312 | no_ospf_timers_lsa_arrival_cmd, | |
2313 | "no timers lsa arrival (0-1000)", | |
2314 | NO_STR | |
2315 | "adjust routing timers\n" | |
2316 | "throttling link state advertisement delays\n" | |
2317 | "ospf minimum arrival interval delay\n" | |
2318 | "delay (msec) between accepted lsas\n"); | |
2319 | ||
2320 | ||
a2c62831 | 2321 | DEFUN (ospf_neighbor, |
2322 | ospf_neighbor_cmd, | |
7a7be519 | 2323 | "neighbor A.B.C.D [priority (0-255) [poll-interval (1-65535)]]", |
718e3744 | 2324 | NEIGHBOR_STR |
7a7be519 | 2325 | "Neighbor IP address\n" |
2326 | "Neighbor Priority\n" | |
2327 | "Priority\n" | |
2328 | "Dead Neighbor Polling interval\n" | |
2329 | "Seconds\n") | |
718e3744 | 2330 | { |
a3d826f0 | 2331 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2332 | int idx_ipv4 = 1; |
2333 | int idx_pri = 3; | |
2334 | int idx_poll = 5; | |
2335 | struct in_addr nbr_addr; | |
2336 | unsigned int priority = OSPF_NEIGHBOR_PRIORITY_DEFAULT; | |
2337 | unsigned int interval = OSPF_POLL_INTERVAL_DEFAULT; | |
718e3744 | 2338 | |
cc9b06ad DS |
2339 | if (!inet_aton(argv[idx_ipv4]->arg, &nbr_addr)) { |
2340 | vty_out(vty, "Please specify Neighbor ID by A.B.C.D\n"); | |
2341 | return CMD_WARNING_CONFIG_FAILED; | |
2342 | } | |
718e3744 | 2343 | |
d62a17ae | 2344 | if (argc > 2) |
2345 | priority = strtoul(argv[idx_pri]->arg, NULL, 10); | |
7a7be519 | 2346 | |
d62a17ae | 2347 | if (argc > 4) |
2348 | interval = strtoul(argv[idx_poll]->arg, NULL, 10); | |
718e3744 | 2349 | |
d62a17ae | 2350 | ospf_nbr_nbma_set(ospf, nbr_addr); |
7a7be519 | 2351 | |
d62a17ae | 2352 | if (argc > 2) |
2353 | ospf_nbr_nbma_priority_set(ospf, nbr_addr, priority); | |
7a7be519 | 2354 | |
d62a17ae | 2355 | if (argc > 4) |
2356 | ospf_nbr_nbma_poll_interval_set(ospf, nbr_addr, interval); | |
718e3744 | 2357 | |
d62a17ae | 2358 | return CMD_SUCCESS; |
718e3744 | 2359 | } |
2360 | ||
a2c62831 | 2361 | DEFUN (ospf_neighbor_poll_interval, |
2362 | ospf_neighbor_poll_interval_cmd, | |
7a7be519 | 2363 | "neighbor A.B.C.D poll-interval (1-65535) [priority (0-255)]", |
718e3744 | 2364 | NEIGHBOR_STR |
2365 | "Neighbor IP address\n" | |
2366 | "Dead Neighbor Polling interval\n" | |
7a7be519 | 2367 | "Seconds\n" |
2368 | "OSPF priority of non-broadcast neighbor\n" | |
2369 | "Priority\n") | |
22b27e95 | 2370 | { |
a3d826f0 | 2371 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2372 | int idx_ipv4 = 1; |
2373 | int idx_poll = 3; | |
2374 | int idx_pri = 5; | |
2375 | struct in_addr nbr_addr; | |
2376 | unsigned int priority = OSPF_NEIGHBOR_PRIORITY_DEFAULT; | |
2377 | unsigned int interval = OSPF_POLL_INTERVAL_DEFAULT; | |
718e3744 | 2378 | |
cc9b06ad DS |
2379 | if (!inet_aton(argv[idx_ipv4]->arg, &nbr_addr)) { |
2380 | vty_out(vty, "Please specify Neighbor ID by A.B.C.D\n"); | |
2381 | return CMD_WARNING_CONFIG_FAILED; | |
2382 | } | |
718e3744 | 2383 | |
d62a17ae | 2384 | interval = strtoul(argv[idx_poll]->arg, NULL, 10); |
718e3744 | 2385 | |
d62a17ae | 2386 | if (argc > 4) |
2387 | priority = strtoul(argv[idx_pri]->arg, NULL, 10); | |
718e3744 | 2388 | |
d62a17ae | 2389 | ospf_nbr_nbma_set(ospf, nbr_addr); |
2390 | ospf_nbr_nbma_poll_interval_set(ospf, nbr_addr, interval); | |
7a7be519 | 2391 | |
d62a17ae | 2392 | if (argc > 4) |
2393 | ospf_nbr_nbma_priority_set(ospf, nbr_addr, priority); | |
718e3744 | 2394 | |
d62a17ae | 2395 | return CMD_SUCCESS; |
718e3744 | 2396 | } |
2397 | ||
a2c62831 | 2398 | DEFUN (no_ospf_neighbor, |
2399 | no_ospf_neighbor_cmd, | |
7a7be519 | 2400 | "no neighbor A.B.C.D [priority (0-255) [poll-interval (1-65525)]]", |
718e3744 | 2401 | NO_STR |
2402 | NEIGHBOR_STR | |
7a7be519 | 2403 | "Neighbor IP address\n" |
2404 | "Neighbor Priority\n" | |
2405 | "Priority\n" | |
2406 | "Dead Neighbor Polling interval\n" | |
2407 | "Seconds\n") | |
718e3744 | 2408 | { |
a3d826f0 | 2409 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2410 | int idx_ipv4 = 2; |
2411 | struct in_addr nbr_addr; | |
718e3744 | 2412 | |
cc9b06ad DS |
2413 | if (!inet_aton(argv[idx_ipv4]->arg, &nbr_addr)) { |
2414 | vty_out(vty, "Please specify Neighbor ID by A.B.C.D\n"); | |
2415 | return CMD_WARNING_CONFIG_FAILED; | |
2416 | } | |
718e3744 | 2417 | |
d62a17ae | 2418 | (void)ospf_nbr_nbma_unset(ospf, nbr_addr); |
718e3744 | 2419 | |
d62a17ae | 2420 | return CMD_SUCCESS; |
718e3744 | 2421 | } |
2422 | ||
7a7be519 | 2423 | DEFUN (no_ospf_neighbor_poll, |
2424 | no_ospf_neighbor_poll_cmd, | |
2425 | "no neighbor A.B.C.D poll-interval (1-65535) [priority (0-255)]", | |
2426 | NO_STR | |
2427 | NEIGHBOR_STR | |
2428 | "Neighbor IP address\n" | |
2429 | "Dead Neighbor Polling interval\n" | |
2430 | "Seconds\n" | |
2431 | "Neighbor Priority\n" | |
2432 | "Priority\n") | |
2433 | { | |
a3d826f0 | 2434 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2435 | int idx_ipv4 = 2; |
2436 | struct in_addr nbr_addr; | |
7a7be519 | 2437 | |
cc9b06ad DS |
2438 | if (!inet_aton(argv[idx_ipv4]->arg, &nbr_addr)) { |
2439 | vty_out(vty, "Please specify Neighbor ID by A.B.C.D\n"); | |
2440 | return CMD_WARNING_CONFIG_FAILED; | |
2441 | } | |
718e3744 | 2442 | |
d62a17ae | 2443 | (void)ospf_nbr_nbma_unset(ospf, nbr_addr); |
813d4307 | 2444 | |
d62a17ae | 2445 | return CMD_SUCCESS; |
7a7be519 | 2446 | } |
718e3744 | 2447 | |
bf2bfafd DW |
2448 | DEFUN (ospf_refresh_timer, |
2449 | ospf_refresh_timer_cmd, | |
6147e2c6 | 2450 | "refresh timer (10-1800)", |
718e3744 | 2451 | "Adjust refresh parameters\n" |
2452 | "Set refresh timer\n" | |
2453 | "Timer value in seconds\n") | |
2454 | { | |
a3d826f0 | 2455 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2456 | int idx_number = 2; |
2457 | unsigned int interval; | |
7c8ff89e | 2458 | |
d62a17ae | 2459 | interval = strtoul(argv[idx_number]->arg, NULL, 10); |
2460 | interval = (interval / OSPF_LSA_REFRESHER_GRANULARITY) | |
2461 | * OSPF_LSA_REFRESHER_GRANULARITY; | |
718e3744 | 2462 | |
d62a17ae | 2463 | ospf_timers_refresh_set(ospf, interval); |
718e3744 | 2464 | |
d62a17ae | 2465 | return CMD_SUCCESS; |
718e3744 | 2466 | } |
2467 | ||
bf2bfafd DW |
2468 | DEFUN (no_ospf_refresh_timer, |
2469 | no_ospf_refresh_timer_val_cmd, | |
7a7be519 | 2470 | "no refresh timer [(10-1800)]", |
3a2d747c | 2471 | NO_STR |
718e3744 | 2472 | "Adjust refresh parameters\n" |
2473 | "Unset refresh timer\n" | |
2474 | "Timer value in seconds\n") | |
2475 | { | |
a3d826f0 | 2476 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2477 | int idx_number = 3; |
2478 | unsigned int interval; | |
718e3744 | 2479 | |
d62a17ae | 2480 | if (argc == 1) { |
2481 | interval = strtoul(argv[idx_number]->arg, NULL, 10); | |
718e3744 | 2482 | |
d62a17ae | 2483 | if (ospf->lsa_refresh_interval != interval |
2484 | || interval == OSPF_LSA_REFRESH_INTERVAL_DEFAULT) | |
2485 | return CMD_SUCCESS; | |
2486 | } | |
2487 | ||
2488 | ospf_timers_refresh_unset(ospf); | |
2489 | ||
2490 | return CMD_SUCCESS; | |
718e3744 | 2491 | } |
2492 | ||
718e3744 | 2493 | |
a2c62831 | 2494 | DEFUN (ospf_auto_cost_reference_bandwidth, |
2495 | ospf_auto_cost_reference_bandwidth_cmd, | |
6147e2c6 | 2496 | "auto-cost reference-bandwidth (1-4294967)", |
718e3744 | 2497 | "Calculate OSPF interface cost according to bandwidth\n" |
2498 | "Use reference bandwidth method to assign OSPF cost\n" | |
2499 | "The reference bandwidth in terms of Mbits per second\n") | |
2500 | { | |
a3d826f0 | 2501 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
f4e14fdb | 2502 | struct vrf *vrf = vrf_lookup_by_id(ospf->vrf_id); |
d62a17ae | 2503 | int idx_number = 2; |
2504 | u_int32_t refbw; | |
d62a17ae | 2505 | struct interface *ifp; |
2506 | ||
2507 | refbw = strtol(argv[idx_number]->arg, NULL, 10); | |
2508 | if (refbw < 1 || refbw > 4294967) { | |
2509 | vty_out(vty, "reference-bandwidth value is invalid\n"); | |
2510 | return CMD_WARNING_CONFIG_FAILED; | |
2511 | } | |
2512 | ||
2513 | /* If reference bandwidth is changed. */ | |
2514 | if ((refbw) == ospf->ref_bandwidth) | |
2515 | return CMD_SUCCESS; | |
2516 | ||
2517 | ospf->ref_bandwidth = refbw; | |
451fda4f | 2518 | FOR_ALL_INTERFACES (vrf, ifp) |
d62a17ae | 2519 | ospf_if_recalculate_output_cost(ifp); |
2520 | ||
2521 | return CMD_SUCCESS; | |
718e3744 | 2522 | } |
2523 | ||
a2c62831 | 2524 | DEFUN (no_ospf_auto_cost_reference_bandwidth, |
2525 | no_ospf_auto_cost_reference_bandwidth_cmd, | |
7a7be519 | 2526 | "no auto-cost reference-bandwidth [(1-4294967)]", |
718e3744 | 2527 | NO_STR |
2528 | "Calculate OSPF interface cost according to bandwidth\n" | |
7a7be519 | 2529 | "Use reference bandwidth method to assign OSPF cost\n" |
2530 | "The reference bandwidth in terms of Mbits per second\n") | |
718e3744 | 2531 | { |
a3d826f0 | 2532 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
f4e14fdb | 2533 | struct vrf *vrf = vrf_lookup_by_id(ospf->vrf_id); |
d62a17ae | 2534 | struct interface *ifp; |
718e3744 | 2535 | |
d62a17ae | 2536 | if (ospf->ref_bandwidth == OSPF_DEFAULT_REF_BANDWIDTH) |
2537 | return CMD_SUCCESS; | |
2538 | ||
2539 | ospf->ref_bandwidth = OSPF_DEFAULT_REF_BANDWIDTH; | |
2540 | vty_out(vty, "%% OSPF: Reference bandwidth is changed.\n"); | |
2541 | vty_out(vty, | |
2542 | " Please ensure reference bandwidth is consistent across all routers\n"); | |
2543 | ||
451fda4f | 2544 | FOR_ALL_INTERFACES (vrf, ifp) |
d62a17ae | 2545 | ospf_if_recalculate_output_cost(ifp); |
2546 | ||
2547 | return CMD_SUCCESS; | |
718e3744 | 2548 | } |
2549 | ||
2f8f370e DS |
2550 | DEFUN (ospf_write_multiplier, |
2551 | ospf_write_multiplier_cmd, | |
6147e2c6 | 2552 | "ospf write-multiplier (1-100)", |
e8f45e82 DS |
2553 | "OSPF specific commands\n" |
2554 | "Write multiplier\n" | |
2555 | "Maximum number of interface serviced per write\n") | |
2f8f370e | 2556 | { |
a3d826f0 | 2557 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 2558 | int idx_number; |
2559 | u_int32_t write_oi_count; | |
2560 | ||
2561 | if (argc == 3) | |
2562 | idx_number = 2; | |
2563 | else | |
2564 | idx_number = 1; | |
2565 | ||
2566 | write_oi_count = strtol(argv[idx_number]->arg, NULL, 10); | |
2567 | if (write_oi_count < 1 || write_oi_count > 100) { | |
2568 | vty_out(vty, "write-multiplier value is invalid\n"); | |
2569 | return CMD_WARNING_CONFIG_FAILED; | |
2570 | } | |
2571 | ||
2572 | ospf->write_oi_count = write_oi_count; | |
2573 | return CMD_SUCCESS; | |
2f8f370e DS |
2574 | } |
2575 | ||
d62a17ae | 2576 | ALIAS(ospf_write_multiplier, write_multiplier_cmd, "write-multiplier (1-100)", |
2577 | "Write multiplier\n" | |
2578 | "Maximum number of interface serviced per write\n") | |
e8f45e82 | 2579 | |
2f8f370e DS |
2580 | DEFUN (no_ospf_write_multiplier, |
2581 | no_ospf_write_multiplier_cmd, | |
6147e2c6 | 2582 | "no ospf write-multiplier (1-100)", |
2f8f370e | 2583 | NO_STR |
e8f45e82 | 2584 | "OSPF specific commands\n" |
813d4307 DW |
2585 | "Write multiplier\n" |
2586 | "Maximum number of interface serviced per write\n") | |
2f8f370e | 2587 | { |
a3d826f0 | 2588 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
2f8f370e | 2589 | |
d62a17ae | 2590 | ospf->write_oi_count = OSPF_WRITE_INTERFACE_COUNT_DEFAULT; |
2591 | return CMD_SUCCESS; | |
2f8f370e DS |
2592 | } |
2593 | ||
d62a17ae | 2594 | ALIAS(no_ospf_write_multiplier, no_write_multiplier_cmd, |
9d303b37 | 2595 | "no write-multiplier (1-100)", NO_STR |
d62a17ae | 2596 | "Write multiplier\n" |
2597 | "Maximum number of interface serviced per write\n") | |
2598 | ||
2599 | const char *ospf_abr_type_descr_str[] = {"Unknown", "Standard (RFC2328)", | |
2600 | "Alternative IBM", "Alternative Cisco", | |
2601 | "Alternative Shortcut"}; | |
2602 | ||
2603 | const char *ospf_shortcut_mode_descr_str[] = {"Default", "Enabled", "Disabled"}; | |
2604 | ||
2605 | static void show_ip_ospf_area(struct vty *vty, struct ospf_area *area, | |
2606 | json_object *json_areas, u_char use_json) | |
2607 | { | |
2608 | json_object *json_area = NULL; | |
2609 | ||
2610 | if (use_json) | |
2611 | json_area = json_object_new_object(); | |
2612 | ||
2613 | /* Show Area ID. */ | |
2614 | if (!use_json) | |
2615 | vty_out(vty, " Area ID: %s", inet_ntoa(area->area_id)); | |
2616 | ||
2617 | /* Show Area type/mode. */ | |
2618 | if (OSPF_IS_AREA_BACKBONE(area)) { | |
2619 | if (use_json) | |
2620 | json_object_boolean_true_add(json_area, "backbone"); | |
2621 | else | |
2622 | vty_out(vty, " (Backbone)\n"); | |
2623 | } else { | |
2624 | if (use_json) { | |
2625 | if (area->external_routing == OSPF_AREA_STUB) { | |
2626 | if (area->no_summary) | |
2627 | json_object_boolean_true_add( | |
2628 | json_area, "stubNoSummary"); | |
2629 | if (area->shortcut_configured) | |
2630 | json_object_boolean_true_add( | |
2631 | json_area, "stubShortcut"); | |
2632 | } else if (area->external_routing == OSPF_AREA_NSSA) { | |
2633 | if (area->no_summary) | |
2634 | json_object_boolean_true_add( | |
2635 | json_area, "nssaNoSummary"); | |
2636 | if (area->shortcut_configured) | |
2637 | json_object_boolean_true_add( | |
2638 | json_area, "nssaShortcut"); | |
2639 | } | |
813d4307 | 2640 | |
d62a17ae | 2641 | json_object_string_add( |
2642 | json_area, "shortcuttingMode", | |
2643 | ospf_shortcut_mode_descr_str | |
2644 | [area->shortcut_configured]); | |
2645 | if (area->shortcut_capability) | |
2646 | json_object_boolean_true_add(json_area, | |
2647 | "sBitConcensus"); | |
2648 | } else { | |
2649 | if (area->external_routing == OSPF_AREA_STUB) | |
2650 | vty_out(vty, " (Stub%s%s)", | |
2651 | area->no_summary ? ", no summary" : "", | |
2652 | area->shortcut_configured ? "; " : ""); | |
2653 | else if (area->external_routing == OSPF_AREA_NSSA) | |
2654 | vty_out(vty, " (NSSA%s%s)", | |
2655 | area->no_summary ? ", no summary" : "", | |
2656 | area->shortcut_configured ? "; " : ""); | |
2657 | ||
2658 | vty_out(vty, "\n"); | |
2659 | vty_out(vty, " Shortcutting mode: %s", | |
2660 | ospf_shortcut_mode_descr_str | |
2661 | [area->shortcut_configured]); | |
2662 | vty_out(vty, ", S-bit consensus: %s\n", | |
2663 | area->shortcut_capability ? "ok" : "no"); | |
2664 | } | |
2665 | } | |
718e3744 | 2666 | |
d62a17ae | 2667 | /* Show number of interfaces */ |
2668 | if (use_json) { | |
2669 | json_object_int_add(json_area, "areaIfTotalCounter", | |
2670 | listcount(area->oiflist)); | |
2671 | json_object_int_add(json_area, "areaIfActiveCounter", | |
2672 | area->act_ints); | |
2673 | } else | |
2674 | vty_out(vty, | |
2675 | " Number of interfaces in this area: Total: %d, " | |
2676 | "Active: %d\n", | |
2677 | listcount(area->oiflist), area->act_ints); | |
2678 | ||
2679 | if (area->external_routing == OSPF_AREA_NSSA) { | |
2680 | if (use_json) { | |
2681 | json_object_boolean_true_add(json_area, "nssa"); | |
2682 | if (!IS_OSPF_ABR(area->ospf)) | |
2683 | json_object_boolean_false_add(json_area, "abr"); | |
2684 | else if (area->NSSATranslatorState) { | |
2685 | json_object_boolean_true_add(json_area, "abr"); | |
2686 | if (area->NSSATranslatorRole | |
2687 | == OSPF_NSSA_ROLE_CANDIDATE) | |
2688 | json_object_boolean_true_add( | |
2689 | json_area, | |
2690 | "nssaTranslatorElected"); | |
2691 | else if (area->NSSATranslatorRole | |
2692 | == OSPF_NSSA_ROLE_ALWAYS) | |
2693 | json_object_boolean_true_add( | |
2694 | json_area, | |
2695 | "nssaTranslatorAlways"); | |
2696 | } else { | |
2697 | json_object_boolean_true_add(json_area, "abr"); | |
2698 | if (area->NSSATranslatorRole | |
2699 | == OSPF_NSSA_ROLE_CANDIDATE) | |
2700 | json_object_boolean_false_add( | |
2701 | json_area, | |
2702 | "nssaTranslatorElected"); | |
2703 | else | |
2704 | json_object_boolean_true_add( | |
2705 | json_area, | |
2706 | "nssaTranslatorNever"); | |
2707 | } | |
2708 | } else { | |
2709 | vty_out(vty, | |
2710 | " It is an NSSA configuration. \n Elected NSSA/ABR performs type-7/type-5 LSA translation. \n"); | |
2711 | if (!IS_OSPF_ABR(area->ospf)) | |
2712 | vty_out(vty, | |
2713 | " It is not ABR, therefore not Translator. \n"); | |
2714 | else if (area->NSSATranslatorState) { | |
2715 | vty_out(vty, " We are an ABR and "); | |
2716 | if (area->NSSATranslatorRole | |
2717 | == OSPF_NSSA_ROLE_CANDIDATE) | |
2718 | vty_out(vty, | |
2719 | "the NSSA Elected Translator. \n"); | |
2720 | else if (area->NSSATranslatorRole | |
2721 | == OSPF_NSSA_ROLE_ALWAYS) | |
2722 | vty_out(vty, | |
2723 | "always an NSSA Translator. \n"); | |
2724 | } else { | |
2725 | vty_out(vty, " We are an ABR, but "); | |
2726 | if (area->NSSATranslatorRole | |
2727 | == OSPF_NSSA_ROLE_CANDIDATE) | |
2728 | vty_out(vty, | |
2729 | "not the NSSA Elected Translator. \n"); | |
2730 | else | |
2731 | vty_out(vty, | |
2732 | "never an NSSA Translator. \n"); | |
2733 | } | |
2734 | } | |
2735 | } | |
2736 | ||
2737 | /* Stub-router state for this area */ | |
2738 | if (CHECK_FLAG(area->stub_router_state, OSPF_AREA_IS_STUB_ROUTED)) { | |
2739 | char timebuf[OSPF_TIME_DUMP_SIZE]; | |
2740 | ||
2741 | if (use_json) { | |
2742 | json_object_boolean_true_add( | |
2743 | json_area, "originStubMaxDistRouterLsa"); | |
2744 | if (CHECK_FLAG(area->stub_router_state, | |
2745 | OSPF_AREA_ADMIN_STUB_ROUTED)) | |
2746 | json_object_boolean_true_add( | |
2747 | json_area, "indefiniteActiveAdmin"); | |
2748 | if (area->t_stub_router) { | |
2749 | long time_store; | |
2750 | time_store = | |
2751 | monotime_until( | |
2752 | &area->t_stub_router->u.sands, | |
2753 | NULL) | |
2754 | / 1000LL; | |
2755 | json_object_int_add( | |
2756 | json_area, | |
2757 | "activeStartupRemainderMsecs", | |
2758 | time_store); | |
2759 | } | |
2760 | } else { | |
2761 | vty_out(vty, | |
2762 | " Originating stub / maximum-distance Router-LSA\n"); | |
2763 | if (CHECK_FLAG(area->stub_router_state, | |
2764 | OSPF_AREA_ADMIN_STUB_ROUTED)) | |
2765 | vty_out(vty, | |
2766 | " Administratively activated (indefinitely)\n"); | |
2767 | if (area->t_stub_router) | |
2768 | vty_out(vty, | |
2769 | " Active from startup, %s remaining\n", | |
2770 | ospf_timer_dump(area->t_stub_router, | |
2771 | timebuf, | |
2772 | sizeof(timebuf))); | |
2773 | } | |
2774 | } | |
2775 | ||
2776 | if (use_json) { | |
2777 | /* Show number of fully adjacent neighbors. */ | |
2778 | json_object_int_add(json_area, "nbrFullAdjacentCounter", | |
2779 | area->full_nbrs); | |
2780 | ||
2781 | /* Show authentication type. */ | |
2782 | if (area->auth_type == OSPF_AUTH_NULL) | |
2783 | json_object_string_add(json_area, "authentication", | |
2784 | "authenticationNone"); | |
2785 | else if (area->auth_type == OSPF_AUTH_SIMPLE) | |
2786 | json_object_string_add(json_area, "authentication", | |
2787 | "authenticationSimplePassword"); | |
2788 | else if (area->auth_type == OSPF_AUTH_CRYPTOGRAPHIC) | |
2789 | json_object_string_add(json_area, "authentication", | |
2790 | "authenticationMessageDigest"); | |
2791 | ||
2792 | if (!OSPF_IS_AREA_BACKBONE(area)) | |
2793 | json_object_int_add(json_area, | |
2794 | "virtualAdjacenciesPassingCounter", | |
2795 | area->full_vls); | |
2796 | ||
2797 | /* Show SPF calculation times. */ | |
2798 | json_object_int_add(json_area, "spfExecutedCounter", | |
2799 | area->spf_calculation); | |
2800 | json_object_int_add(json_area, "lsaNumber", area->lsdb->total); | |
2801 | json_object_int_add( | |
2802 | json_area, "lsaRouterNumber", | |
2803 | ospf_lsdb_count(area->lsdb, OSPF_ROUTER_LSA)); | |
2804 | json_object_int_add( | |
2805 | json_area, "lsaRouterChecksum", | |
2806 | ospf_lsdb_checksum(area->lsdb, OSPF_ROUTER_LSA)); | |
2807 | json_object_int_add( | |
2808 | json_area, "lsaNetworkNumber", | |
2809 | ospf_lsdb_count(area->lsdb, OSPF_NETWORK_LSA)); | |
2810 | json_object_int_add( | |
2811 | json_area, "lsaNetworkChecksum", | |
2812 | ospf_lsdb_checksum(area->lsdb, OSPF_NETWORK_LSA)); | |
2813 | json_object_int_add( | |
2814 | json_area, "lsaSummaryNumber", | |
2815 | ospf_lsdb_count(area->lsdb, OSPF_SUMMARY_LSA)); | |
2816 | json_object_int_add( | |
2817 | json_area, "lsaSummaryChecksum", | |
2818 | ospf_lsdb_checksum(area->lsdb, OSPF_SUMMARY_LSA)); | |
2819 | json_object_int_add( | |
2820 | json_area, "lsaAsbrNumber", | |
2821 | ospf_lsdb_count(area->lsdb, OSPF_ASBR_SUMMARY_LSA)); | |
2822 | json_object_int_add( | |
2823 | json_area, "lsaAsbrChecksum", | |
2824 | ospf_lsdb_checksum(area->lsdb, OSPF_ASBR_SUMMARY_LSA)); | |
2825 | json_object_int_add( | |
2826 | json_area, "lsaNssaNumber", | |
2827 | ospf_lsdb_count(area->lsdb, OSPF_AS_NSSA_LSA)); | |
2828 | json_object_int_add( | |
2829 | json_area, "lsaNssaChecksum", | |
2830 | ospf_lsdb_checksum(area->lsdb, OSPF_AS_NSSA_LSA)); | |
2831 | } else { | |
2832 | /* Show number of fully adjacent neighbors. */ | |
2833 | vty_out(vty, | |
2834 | " Number of fully adjacent neighbors in this area:" | |
2835 | " %d\n", | |
2836 | area->full_nbrs); | |
2837 | ||
2838 | /* Show authentication type. */ | |
2839 | vty_out(vty, " Area has "); | |
2840 | if (area->auth_type == OSPF_AUTH_NULL) | |
2841 | vty_out(vty, "no authentication\n"); | |
2842 | else if (area->auth_type == OSPF_AUTH_SIMPLE) | |
2843 | vty_out(vty, "simple password authentication\n"); | |
2844 | else if (area->auth_type == OSPF_AUTH_CRYPTOGRAPHIC) | |
2845 | vty_out(vty, "message digest authentication\n"); | |
2846 | ||
2847 | if (!OSPF_IS_AREA_BACKBONE(area)) | |
2848 | vty_out(vty, | |
2849 | " Number of full virtual adjacencies going through" | |
2850 | " this area: %d\n", | |
2851 | area->full_vls); | |
2852 | ||
2853 | /* Show SPF calculation times. */ | |
2854 | vty_out(vty, " SPF algorithm executed %d times\n", | |
2855 | area->spf_calculation); | |
2856 | ||
2857 | /* Show number of LSA. */ | |
2858 | vty_out(vty, " Number of LSA %ld\n", area->lsdb->total); | |
2859 | vty_out(vty, | |
2860 | " Number of router LSA %ld. Checksum Sum 0x%08x\n", | |
2861 | ospf_lsdb_count(area->lsdb, OSPF_ROUTER_LSA), | |
2862 | ospf_lsdb_checksum(area->lsdb, OSPF_ROUTER_LSA)); | |
2863 | vty_out(vty, | |
2864 | " Number of network LSA %ld. Checksum Sum 0x%08x\n", | |
2865 | ospf_lsdb_count(area->lsdb, OSPF_NETWORK_LSA), | |
2866 | ospf_lsdb_checksum(area->lsdb, OSPF_NETWORK_LSA)); | |
2867 | vty_out(vty, | |
2868 | " Number of summary LSA %ld. Checksum Sum 0x%08x\n", | |
2869 | ospf_lsdb_count(area->lsdb, OSPF_SUMMARY_LSA), | |
2870 | ospf_lsdb_checksum(area->lsdb, OSPF_SUMMARY_LSA)); | |
2871 | vty_out(vty, | |
2872 | " Number of ASBR summary LSA %ld. Checksum Sum 0x%08x\n", | |
2873 | ospf_lsdb_count(area->lsdb, OSPF_ASBR_SUMMARY_LSA), | |
2874 | ospf_lsdb_checksum(area->lsdb, OSPF_ASBR_SUMMARY_LSA)); | |
2875 | vty_out(vty, " Number of NSSA LSA %ld. Checksum Sum 0x%08x\n", | |
2876 | ospf_lsdb_count(area->lsdb, OSPF_AS_NSSA_LSA), | |
2877 | ospf_lsdb_checksum(area->lsdb, OSPF_AS_NSSA_LSA)); | |
2878 | } | |
2879 | ||
2880 | if (use_json) { | |
2881 | json_object_int_add( | |
2882 | json_area, "lsaOpaqueLinkNumber", | |
2883 | ospf_lsdb_count(area->lsdb, OSPF_OPAQUE_LINK_LSA)); | |
2884 | json_object_int_add( | |
2885 | json_area, "lsaOpaqueLinkChecksum", | |
2886 | ospf_lsdb_checksum(area->lsdb, OSPF_OPAQUE_LINK_LSA)); | |
2887 | json_object_int_add( | |
2888 | json_area, "lsaOpaqueAreaNumber", | |
2889 | ospf_lsdb_count(area->lsdb, OSPF_OPAQUE_AREA_LSA)); | |
2890 | json_object_int_add( | |
2891 | json_area, "lsaOpaqueAreaChecksum", | |
2892 | ospf_lsdb_checksum(area->lsdb, OSPF_OPAQUE_AREA_LSA)); | |
2893 | } else { | |
2894 | vty_out(vty, | |
2895 | " Number of opaque link LSA %ld. Checksum Sum 0x%08x\n", | |
2896 | ospf_lsdb_count(area->lsdb, OSPF_OPAQUE_LINK_LSA), | |
2897 | ospf_lsdb_checksum(area->lsdb, OSPF_OPAQUE_LINK_LSA)); | |
2898 | vty_out(vty, | |
2899 | " Number of opaque area LSA %ld. Checksum Sum 0x%08x\n", | |
2900 | ospf_lsdb_count(area->lsdb, OSPF_OPAQUE_AREA_LSA), | |
2901 | ospf_lsdb_checksum(area->lsdb, OSPF_OPAQUE_AREA_LSA)); | |
2902 | } | |
718e3744 | 2903 | |
d62a17ae | 2904 | if (use_json) |
2905 | json_object_object_add(json_areas, inet_ntoa(area->area_id), | |
2906 | json_area); | |
2907 | else | |
2908 | vty_out(vty, "\n"); | |
718e3744 | 2909 | } |
2910 | ||
d62a17ae | 2911 | static int show_ip_ospf_common(struct vty *vty, struct ospf *ospf, |
2912 | u_char use_json) | |
2913 | { | |
2914 | struct listnode *node, *nnode; | |
2915 | struct ospf_area *area; | |
2916 | struct timeval result; | |
2917 | char timebuf[OSPF_TIME_DUMP_SIZE]; | |
2918 | json_object *json = NULL; | |
2919 | json_object *json_areas = NULL; | |
718e3744 | 2920 | |
d62a17ae | 2921 | if (use_json) { |
2922 | json = json_object_new_object(); | |
2923 | json_areas = json_object_new_object(); | |
2924 | } | |
2925 | ||
2926 | if (ospf->instance) { | |
2927 | if (use_json) { | |
2928 | json_object_int_add(json, "ospfInstance", | |
2929 | ospf->instance); | |
2930 | } else { | |
2931 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
2932 | } | |
2933 | } | |
2934 | ||
52d0c099 | 2935 | ospf_show_vrf_name(ospf, vty, json); |
87bd50e8 | 2936 | |
d62a17ae | 2937 | /* Show Router ID. */ |
2938 | if (use_json) { | |
2939 | json_object_string_add(json, "routerId", | |
2940 | inet_ntoa(ospf->router_id)); | |
2941 | } else { | |
2942 | vty_out(vty, " OSPF Routing Process, Router ID: %s\n", | |
2943 | inet_ntoa(ospf->router_id)); | |
2944 | } | |
2945 | ||
2946 | /* Graceful shutdown */ | |
2947 | if (ospf->t_deferred_shutdown) { | |
2948 | if (use_json) { | |
2949 | long time_store; | |
2950 | time_store = | |
2951 | monotime_until( | |
2952 | &ospf->t_deferred_shutdown->u.sands, | |
2953 | NULL) | |
2954 | / 1000LL; | |
2955 | json_object_int_add(json, "deferredShutdownMsecs", | |
2956 | time_store); | |
2957 | } else { | |
2958 | vty_out(vty, | |
2959 | " Deferred shutdown in progress, %s remaining\n", | |
2960 | ospf_timer_dump(ospf->t_deferred_shutdown, | |
2961 | timebuf, sizeof(timebuf))); | |
2962 | } | |
2963 | } | |
2964 | ||
2965 | /* Show capability. */ | |
2966 | if (use_json) { | |
2967 | json_object_boolean_true_add(json, "tosRoutesOnly"); | |
2968 | json_object_boolean_true_add(json, "rfc2328Conform"); | |
2969 | if (CHECK_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE)) { | |
2970 | json_object_boolean_true_add(json, | |
2971 | "rfc1583Compatibility"); | |
2972 | } | |
2973 | } else { | |
2974 | vty_out(vty, " Supports only single TOS (TOS0) routes\n"); | |
2975 | vty_out(vty, " This implementation conforms to RFC2328\n"); | |
2976 | vty_out(vty, " RFC1583Compatibility flag is %s\n", | |
2977 | CHECK_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE) | |
2978 | ? "enabled" | |
2979 | : "disabled"); | |
2980 | } | |
2981 | ||
2982 | if (use_json) { | |
2983 | if (CHECK_FLAG(ospf->config, OSPF_OPAQUE_CAPABLE)) { | |
2984 | json_object_boolean_true_add(json, "opaqueCapable"); | |
2985 | } | |
2986 | } else { | |
2987 | vty_out(vty, " OpaqueCapability flag is %s\n", | |
2988 | CHECK_FLAG(ospf->config, OSPF_OPAQUE_CAPABLE) | |
2989 | ? "enabled" | |
2990 | : "disabled"); | |
2991 | } | |
2992 | ||
2993 | /* Show stub-router configuration */ | |
2994 | if (ospf->stub_router_startup_time != OSPF_STUB_ROUTER_UNCONFIGURED | |
2995 | || ospf->stub_router_shutdown_time | |
2996 | != OSPF_STUB_ROUTER_UNCONFIGURED) { | |
2997 | if (use_json) { | |
2998 | json_object_boolean_true_add(json, "stubAdvertisement"); | |
2999 | if (ospf->stub_router_startup_time | |
3000 | != OSPF_STUB_ROUTER_UNCONFIGURED) | |
3001 | json_object_int_add( | |
3002 | json, "postStartEnabledMsecs", | |
3003 | ospf->stub_router_startup_time / 1000); | |
3004 | if (ospf->stub_router_shutdown_time | |
3005 | != OSPF_STUB_ROUTER_UNCONFIGURED) | |
3006 | json_object_int_add( | |
3007 | json, "preShutdownEnabledMsecs", | |
3008 | ospf->stub_router_shutdown_time / 1000); | |
3009 | } else { | |
3010 | vty_out(vty, | |
3011 | " Stub router advertisement is configured\n"); | |
3012 | if (ospf->stub_router_startup_time | |
3013 | != OSPF_STUB_ROUTER_UNCONFIGURED) | |
3014 | vty_out(vty, | |
3015 | " Enabled for %us after start-up\n", | |
3016 | ospf->stub_router_startup_time); | |
3017 | if (ospf->stub_router_shutdown_time | |
3018 | != OSPF_STUB_ROUTER_UNCONFIGURED) | |
3019 | vty_out(vty, | |
3020 | " Enabled for %us prior to full shutdown\n", | |
3021 | ospf->stub_router_shutdown_time); | |
3022 | } | |
3023 | } | |
3024 | ||
3025 | /* Show SPF timers. */ | |
3026 | if (use_json) { | |
3027 | json_object_int_add(json, "spfScheduleDelayMsecs", | |
3028 | ospf->spf_delay); | |
3029 | json_object_int_add(json, "holdtimeMinMsecs", | |
3030 | ospf->spf_holdtime); | |
3031 | json_object_int_add(json, "holdtimeMaxMsecs", | |
3032 | ospf->spf_max_holdtime); | |
3033 | json_object_int_add(json, "holdtimeMultplier", | |
3034 | ospf->spf_hold_multiplier); | |
3035 | } else { | |
3036 | vty_out(vty, | |
3037 | " Initial SPF scheduling delay %d millisec(s)\n" | |
3038 | " Minimum hold time between consecutive SPFs %d millisec(s)\n" | |
3039 | " Maximum hold time between consecutive SPFs %d millisec(s)\n" | |
3040 | " Hold time multiplier is currently %d\n", | |
3041 | ospf->spf_delay, ospf->spf_holdtime, | |
3042 | ospf->spf_max_holdtime, ospf->spf_hold_multiplier); | |
3043 | } | |
3044 | ||
3045 | if (use_json) { | |
3046 | if (ospf->ts_spf.tv_sec || ospf->ts_spf.tv_usec) { | |
3047 | long time_store = 0; | |
3048 | ||
3049 | time_store = | |
3050 | monotime_since(&ospf->ts_spf, NULL) / 1000LL; | |
3051 | json_object_int_add(json, "spfLastExecutedMsecs", | |
3052 | time_store); | |
3053 | ||
3054 | time_store = (1000 * ospf->ts_spf_duration.tv_sec) | |
3055 | + (ospf->ts_spf_duration.tv_usec / 1000); | |
3056 | json_object_int_add(json, "spfLastDurationMsecs", | |
3057 | time_store); | |
3058 | } else | |
3059 | json_object_boolean_true_add(json, "spfHasNotRun"); | |
3060 | } else { | |
3061 | vty_out(vty, " SPF algorithm "); | |
3062 | if (ospf->ts_spf.tv_sec || ospf->ts_spf.tv_usec) { | |
3063 | monotime_since(&ospf->ts_spf, &result); | |
3064 | vty_out(vty, "last executed %s ago\n", | |
3065 | ospf_timeval_dump(&result, timebuf, | |
3066 | sizeof(timebuf))); | |
3067 | vty_out(vty, " Last SPF duration %s\n", | |
3068 | ospf_timeval_dump(&ospf->ts_spf_duration, | |
3069 | timebuf, sizeof(timebuf))); | |
3070 | } else | |
3071 | vty_out(vty, "has not been run\n"); | |
3072 | } | |
3073 | ||
3074 | if (use_json) { | |
3075 | if (ospf->t_spf_calc) { | |
3076 | long time_store; | |
3077 | time_store = | |
3078 | monotime_until(&ospf->t_spf_calc->u.sands, NULL) | |
3079 | / 1000LL; | |
3080 | json_object_int_add(json, "spfTimerDueInMsecs", | |
3081 | time_store); | |
3082 | } | |
3083 | ||
3084 | json_object_int_add(json, "lsaMinIntervalMsecs", | |
3085 | ospf->min_ls_interval); | |
3086 | json_object_int_add(json, "lsaMinArrivalMsecs", | |
3087 | ospf->min_ls_arrival); | |
3088 | /* Show write multiplier values */ | |
3089 | json_object_int_add(json, "writeMultiplier", | |
3090 | ospf->write_oi_count); | |
3091 | /* Show refresh parameters. */ | |
3092 | json_object_int_add(json, "refreshTimerMsecs", | |
3093 | ospf->lsa_refresh_interval * 1000); | |
3094 | } else { | |
3095 | vty_out(vty, " SPF timer %s%s\n", | |
3096 | (ospf->t_spf_calc ? "due in " : "is "), | |
3097 | ospf_timer_dump(ospf->t_spf_calc, timebuf, | |
3098 | sizeof(timebuf))); | |
3099 | ||
3100 | vty_out(vty, " LSA minimum interval %d msecs\n", | |
3101 | ospf->min_ls_interval); | |
3102 | vty_out(vty, " LSA minimum arrival %d msecs\n", | |
3103 | ospf->min_ls_arrival); | |
3104 | ||
3105 | /* Show write multiplier values */ | |
3106 | vty_out(vty, " Write Multiplier set to %d \n", | |
3107 | ospf->write_oi_count); | |
3108 | ||
3109 | /* Show refresh parameters. */ | |
3110 | vty_out(vty, " Refresh timer %d secs\n", | |
3111 | ospf->lsa_refresh_interval); | |
3112 | } | |
3113 | ||
3114 | /* Show ABR/ASBR flags. */ | |
3115 | if (CHECK_FLAG(ospf->flags, OSPF_FLAG_ABR)) { | |
3116 | if (use_json) | |
3117 | json_object_string_add( | |
3118 | json, "abrType", | |
3119 | ospf_abr_type_descr_str[ospf->abr_type]); | |
3120 | else | |
3121 | vty_out(vty, | |
3122 | " This router is an ABR, ABR type is: %s\n", | |
3123 | ospf_abr_type_descr_str[ospf->abr_type]); | |
3124 | } | |
3125 | if (CHECK_FLAG(ospf->flags, OSPF_FLAG_ASBR)) { | |
3126 | if (use_json) | |
3127 | json_object_string_add( | |
3128 | json, "asbrRouter", | |
3129 | "injectingExternalRoutingInformation"); | |
3130 | else | |
3131 | vty_out(vty, | |
3132 | " This router is an ASBR " | |
3133 | "(injecting external routing information)\n"); | |
3134 | } | |
3135 | ||
3136 | /* Show Number of AS-external-LSAs. */ | |
3137 | if (use_json) { | |
3138 | json_object_int_add( | |
3139 | json, "lsaExternalCounter", | |
3140 | ospf_lsdb_count(ospf->lsdb, OSPF_AS_EXTERNAL_LSA)); | |
3141 | json_object_int_add( | |
3142 | json, "lsaExternalChecksum", | |
3143 | ospf_lsdb_checksum(ospf->lsdb, OSPF_AS_EXTERNAL_LSA)); | |
3144 | } else { | |
3145 | vty_out(vty, | |
3146 | " Number of external LSA %ld. Checksum Sum 0x%08x\n", | |
3147 | ospf_lsdb_count(ospf->lsdb, OSPF_AS_EXTERNAL_LSA), | |
3148 | ospf_lsdb_checksum(ospf->lsdb, OSPF_AS_EXTERNAL_LSA)); | |
3149 | } | |
3150 | ||
3151 | if (use_json) { | |
3152 | json_object_int_add( | |
3153 | json, "lsaAsopaqueCounter", | |
3154 | ospf_lsdb_count(ospf->lsdb, OSPF_OPAQUE_AS_LSA)); | |
3155 | json_object_int_add( | |
3156 | json, "lsaAsOpaqueChecksum", | |
3157 | ospf_lsdb_checksum(ospf->lsdb, OSPF_OPAQUE_AS_LSA)); | |
3158 | } else { | |
3159 | vty_out(vty, | |
3160 | " Number of opaque AS LSA %ld. Checksum Sum 0x%08x\n", | |
3161 | ospf_lsdb_count(ospf->lsdb, OSPF_OPAQUE_AS_LSA), | |
3162 | ospf_lsdb_checksum(ospf->lsdb, OSPF_OPAQUE_AS_LSA)); | |
3163 | } | |
3164 | ||
3165 | /* Show number of areas attached. */ | |
3166 | if (use_json) | |
3167 | json_object_int_add(json, "attachedAreaCounter", | |
3168 | listcount(ospf->areas)); | |
3169 | else | |
3170 | vty_out(vty, " Number of areas attached to this router: %d\n", | |
3171 | listcount(ospf->areas)); | |
3172 | ||
3173 | if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES)) { | |
3174 | if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL)) { | |
3175 | if (use_json) | |
3176 | json_object_boolean_true_add( | |
3177 | json, "adjacencyChangesLoggedAll"); | |
3178 | else | |
3179 | vty_out(vty, | |
3180 | " All adjacency changes are logged\n"); | |
3181 | } else { | |
3182 | if (use_json) | |
3183 | json_object_boolean_true_add( | |
3184 | json, "adjacencyChangesLogged"); | |
3185 | else | |
3186 | vty_out(vty, " Adjacency changes are logged\n"); | |
3187 | } | |
3188 | } | |
3189 | /* Show each area status. */ | |
3190 | for (ALL_LIST_ELEMENTS(ospf->areas, node, nnode, area)) | |
3191 | show_ip_ospf_area(vty, area, json_areas, use_json); | |
3192 | ||
3193 | if (use_json) { | |
3194 | json_object_object_add(json, "areas", json_areas); | |
9d303b37 DL |
3195 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
3196 | json, JSON_C_TO_STRING_PRETTY)); | |
d62a17ae | 3197 | json_object_free(json); |
3198 | } else | |
3199 | vty_out(vty, "\n"); | |
3200 | ||
3201 | return CMD_SUCCESS; | |
718e3744 | 3202 | } |
3203 | ||
7c8ff89e DS |
3204 | DEFUN (show_ip_ospf, |
3205 | show_ip_ospf_cmd, | |
b5a8894d | 3206 | "show ip ospf [vrf <NAME|all>] [json]", |
7c8ff89e DS |
3207 | SHOW_STR |
3208 | IP_STR | |
ca08c43d | 3209 | "OSPF information\n" |
b5a8894d CS |
3210 | VRF_CMD_HELP_STR |
3211 | "All VRFs\n" | |
9973d184 | 3212 | JSON_STR) |
7c8ff89e | 3213 | { |
d62a17ae | 3214 | struct ospf *ospf; |
3215 | u_char uj = use_json(argc, argv); | |
b5a8894d CS |
3216 | struct listnode *node = NULL; |
3217 | char *vrf_name = NULL; | |
3218 | bool all_vrf = FALSE; | |
3219 | int ret = CMD_SUCCESS; | |
3220 | int inst = 0; | |
3221 | int idx_vrf = 0; | |
7c8ff89e | 3222 | |
b5a8894d | 3223 | if (listcount(om->ospf) == 0) |
d62a17ae | 3224 | return CMD_SUCCESS; |
7c8ff89e | 3225 | |
43b8d1d8 | 3226 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
b5a8894d CS |
3227 | |
3228 | /* vrf input is provided could be all or specific vrf*/ | |
3229 | if (vrf_name) { | |
3230 | if (all_vrf) { | |
3231 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
3232 | if (!ospf->oi_running) | |
3233 | continue; | |
3234 | ret = show_ip_ospf_common(vty, ospf, uj); | |
3235 | } | |
3236 | return ret; | |
3237 | } | |
3238 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
3239 | if ((ospf == NULL) || !ospf->oi_running) | |
3240 | return CMD_SUCCESS; | |
3241 | } else { | |
3242 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
3243 | /* Display default ospf (instance 0) info */ | |
3244 | if (ospf == NULL || !ospf->oi_running) | |
3245 | return CMD_SUCCESS; | |
3246 | } | |
3247 | ||
3248 | if (ospf) | |
3249 | show_ip_ospf_common(vty, ospf, uj); | |
3250 | ||
3251 | return ret; | |
7c8ff89e DS |
3252 | } |
3253 | ||
3254 | DEFUN (show_ip_ospf_instance, | |
3255 | show_ip_ospf_instance_cmd, | |
6147e2c6 | 3256 | "show ip ospf (1-65535) [json]", |
7c8ff89e DS |
3257 | SHOW_STR |
3258 | IP_STR | |
3259 | "OSPF information\n" | |
ca08c43d | 3260 | "Instance ID\n" |
9973d184 | 3261 | JSON_STR) |
7c8ff89e | 3262 | { |
d62a17ae | 3263 | int idx_number = 3; |
3264 | struct ospf *ospf; | |
3265 | u_short instance = 0; | |
3266 | u_char uj = use_json(argc, argv); | |
3267 | ||
3268 | instance = strtoul(argv[idx_number]->arg, NULL, 10); | |
ac28e4ec CS |
3269 | ospf = ospf_lookup_instance(instance); |
3270 | if (ospf == NULL) | |
3271 | return CMD_NOT_MY_INSTANCE; | |
3272 | ||
3273 | if (!ospf->oi_running) | |
d62a17ae | 3274 | return CMD_SUCCESS; |
3275 | ||
3276 | return (show_ip_ospf_common(vty, ospf, uj)); | |
3277 | } | |
3278 | ||
3279 | static void show_ip_ospf_interface_sub(struct vty *vty, struct ospf *ospf, | |
3280 | struct interface *ifp, | |
3281 | json_object *json_interface_sub, | |
3282 | u_char use_json) | |
3283 | { | |
3284 | int is_up; | |
3285 | struct ospf_neighbor *nbr; | |
3286 | struct route_node *rn; | |
3287 | uint32_t bandwidth = ifp->bandwidth ? ifp->bandwidth : ifp->speed; | |
3288 | ||
3289 | /* Is interface up? */ | |
3290 | if (use_json) { | |
3291 | is_up = if_is_operative(ifp); | |
3292 | if (is_up) | |
3293 | json_object_boolean_true_add(json_interface_sub, | |
3294 | "ifUp"); | |
3295 | else | |
3296 | json_object_boolean_false_add(json_interface_sub, | |
3297 | "ifDown"); | |
3298 | ||
3299 | json_object_int_add(json_interface_sub, "ifIndex", | |
3300 | ifp->ifindex); | |
3301 | json_object_int_add(json_interface_sub, "mtuBytes", ifp->mtu); | |
3302 | json_object_int_add(json_interface_sub, "bandwidthMbit", | |
3303 | bandwidth); | |
3304 | json_object_string_add(json_interface_sub, "ifFlags", | |
3305 | if_flag_dump(ifp->flags)); | |
3306 | } else { | |
3307 | vty_out(vty, "%s is %s\n", ifp->name, | |
3308 | ((is_up = if_is_operative(ifp)) ? "up" : "down")); | |
3309 | vty_out(vty, " ifindex %u, MTU %u bytes, BW %u Mbit %s\n", | |
3310 | ifp->ifindex, ifp->mtu, bandwidth, | |
3311 | if_flag_dump(ifp->flags)); | |
3312 | } | |
7c8ff89e | 3313 | |
d62a17ae | 3314 | /* Is interface OSPF enabled? */ |
3315 | if (use_json) { | |
3316 | if (ospf_oi_count(ifp) == 0) { | |
3317 | json_object_boolean_false_add(json_interface_sub, | |
3318 | "ospfEnabled"); | |
3319 | return; | |
3320 | } else if (!is_up) { | |
3321 | json_object_boolean_false_add(json_interface_sub, | |
3322 | "ospfRunning"); | |
3323 | return; | |
3324 | } else | |
3325 | json_object_boolean_true_add(json_interface_sub, | |
3326 | "ospfEnabled"); | |
3327 | } else { | |
3328 | if (ospf_oi_count(ifp) == 0) { | |
3329 | vty_out(vty, " OSPF not enabled on this interface\n"); | |
3330 | return; | |
3331 | } else if (!is_up) { | |
3332 | vty_out(vty, | |
3333 | " OSPF is enabled, but not running on this interface\n"); | |
3334 | return; | |
3335 | } | |
3336 | } | |
3337 | ||
3338 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { | |
3339 | struct ospf_interface *oi = rn->info; | |
3340 | ||
3341 | if (oi == NULL) | |
3342 | continue; | |
3343 | ||
3344 | if (CHECK_FLAG(oi->connected->flags, ZEBRA_IFA_UNNUMBERED)) { | |
3345 | if (use_json) | |
3346 | json_object_boolean_true_add(json_interface_sub, | |
3347 | "ifUnnumbered"); | |
3348 | else | |
3349 | vty_out(vty, " This interface is UNNUMBERED,"); | |
3350 | } else { | |
3351 | /* Show OSPF interface information. */ | |
3352 | if (use_json) { | |
3353 | json_object_string_add( | |
3354 | json_interface_sub, "ipAddress", | |
3355 | inet_ntoa(oi->address->u.prefix4)); | |
3356 | json_object_int_add(json_interface_sub, | |
3357 | "ipAddressPrefixlen", | |
3358 | oi->address->prefixlen); | |
3359 | } else | |
3360 | vty_out(vty, " Internet Address %s/%d,", | |
3361 | inet_ntoa(oi->address->u.prefix4), | |
3362 | oi->address->prefixlen); | |
3363 | ||
3364 | if (oi->connected->destination | |
3365 | || oi->type == OSPF_IFTYPE_VIRTUALLINK) { | |
3366 | struct in_addr *dest; | |
3367 | const char *dstr; | |
3368 | ||
3369 | if (CONNECTED_PEER(oi->connected) | |
3370 | || oi->type == OSPF_IFTYPE_VIRTUALLINK) | |
3371 | dstr = "Peer"; | |
3372 | else | |
3373 | dstr = "Broadcast"; | |
3374 | ||
3375 | /* For Vlinks, showing the peer address is | |
9d303b37 DL |
3376 | * probably more |
3377 | * * * * * informative than the local | |
3378 | * interface that is being used | |
3379 | * * * * */ | |
d62a17ae | 3380 | if (oi->type == OSPF_IFTYPE_VIRTUALLINK) |
3381 | dest = &oi->vl_data->peer_addr; | |
3382 | else | |
3383 | dest = &oi->connected->destination->u | |
3384 | .prefix4; | |
3385 | ||
3386 | if (use_json) { | |
3387 | json_object_string_add( | |
3388 | json_interface_sub, | |
3389 | "ospfIfType", dstr); | |
3390 | if (oi->type == OSPF_IFTYPE_VIRTUALLINK) | |
3391 | json_object_string_add( | |
3392 | json_interface_sub, | |
3393 | "vlinkPeer", | |
3394 | inet_ntoa(*dest)); | |
3395 | else | |
3396 | json_object_string_add( | |
3397 | json_interface_sub, | |
3398 | "localIfUsed", | |
3399 | inet_ntoa(*dest)); | |
3400 | } else | |
3401 | vty_out(vty, " %s %s,", dstr, | |
3402 | inet_ntoa(*dest)); | |
3403 | } | |
3404 | } | |
3405 | if (use_json) { | |
3406 | json_object_string_add(json_interface_sub, "area", | |
3407 | ospf_area_desc_string(oi->area)); | |
3408 | if (OSPF_IF_PARAM(oi, mtu_ignore)) | |
3409 | json_object_boolean_true_add( | |
3410 | json_interface_sub, | |
3411 | "mtuMismatchDetect"); | |
3412 | json_object_string_add(json_interface_sub, "routerId", | |
3413 | inet_ntoa(ospf->router_id)); | |
3414 | json_object_string_add(json_interface_sub, | |
3415 | "networkType", | |
3416 | ospf_network_type_str[oi->type]); | |
3417 | json_object_int_add(json_interface_sub, "cost", | |
3418 | oi->output_cost); | |
3419 | json_object_int_add( | |
3420 | json_interface_sub, "transmitDelayMsecs", | |
3421 | 1000 / OSPF_IF_PARAM(oi, transmit_delay)); | |
3422 | json_object_string_add(json_interface_sub, "state", | |
3423 | lookup_msg(ospf_ism_state_msg, | |
3424 | oi->state, NULL)); | |
3425 | json_object_int_add(json_interface_sub, "priority", | |
3426 | PRIORITY(oi)); | |
3427 | } else { | |
3428 | vty_out(vty, " Area %s\n", | |
3429 | ospf_area_desc_string(oi->area)); | |
3430 | ||
3431 | vty_out(vty, " MTU mismatch detection: %s\n", | |
3432 | OSPF_IF_PARAM(oi, mtu_ignore) ? "disabled" | |
3433 | : "enabled"); | |
3434 | ||
3435 | vty_out(vty, | |
3436 | " Router ID %s, Network Type %s, Cost: %d\n", | |
3437 | inet_ntoa(ospf->router_id), | |
3438 | ospf_network_type_str[oi->type], | |
3439 | oi->output_cost); | |
3440 | ||
3441 | vty_out(vty, | |
3442 | " Transmit Delay is %d sec, State %s, Priority %d\n", | |
3443 | OSPF_IF_PARAM(oi, transmit_delay), | |
3444 | lookup_msg(ospf_ism_state_msg, oi->state, NULL), | |
3445 | PRIORITY(oi)); | |
3446 | } | |
3447 | ||
3448 | /* Show DR information. */ | |
3449 | if (DR(oi).s_addr == 0) { | |
3450 | if (!use_json) | |
3451 | vty_out(vty, | |
3452 | " No backup designated router on this network\n"); | |
3453 | } else { | |
3454 | nbr = ospf_nbr_lookup_by_addr(oi->nbrs, &BDR(oi)); | |
3455 | if (nbr == NULL) { | |
3456 | if (!use_json) | |
3457 | vty_out(vty, | |
3458 | " No backup designated router on this network\n"); | |
3459 | } else { | |
3460 | if (use_json) { | |
3461 | json_object_string_add( | |
3462 | json_interface_sub, "bdrId", | |
3463 | inet_ntoa(nbr->router_id)); | |
3464 | json_object_string_add( | |
3465 | json_interface_sub, | |
3466 | "bdrAddress", | |
3467 | inet_ntoa(nbr->address.u | |
3468 | .prefix4)); | |
3469 | } else { | |
3470 | vty_out(vty, | |
3471 | " Backup Designated Router (ID) %s,", | |
3472 | inet_ntoa(nbr->router_id)); | |
3473 | vty_out(vty, " Interface Address %s\n", | |
3474 | inet_ntoa(nbr->address.u | |
3475 | .prefix4)); | |
3476 | } | |
3477 | } | |
3478 | } | |
3479 | ||
3480 | /* Next network-LSA sequence number we'll use, if we're elected | |
3481 | * DR */ | |
3482 | if (oi->params | |
3483 | && ntohl(oi->params->network_lsa_seqnum) | |
3484 | != OSPF_INITIAL_SEQUENCE_NUMBER) { | |
3485 | if (use_json) | |
3486 | json_object_int_add( | |
3487 | json_interface_sub, | |
3488 | "networkLsaSequence", | |
3489 | ntohl(oi->params->network_lsa_seqnum)); | |
3490 | else | |
3491 | vty_out(vty, | |
3492 | " Saved Network-LSA sequence number 0x%x\n", | |
3493 | ntohl(oi->params->network_lsa_seqnum)); | |
3494 | } | |
3495 | ||
3496 | if (use_json) { | |
3497 | if (OI_MEMBER_CHECK(oi, MEMBER_ALLROUTERS) | |
3498 | || OI_MEMBER_CHECK(oi, MEMBER_DROUTERS)) { | |
3499 | if (OI_MEMBER_CHECK(oi, MEMBER_ALLROUTERS)) | |
3500 | json_object_boolean_true_add( | |
3501 | json_interface_sub, | |
3502 | "mcastMemberOspfAllRouters"); | |
3503 | if (OI_MEMBER_CHECK(oi, MEMBER_DROUTERS)) | |
3504 | json_object_boolean_true_add( | |
3505 | json_interface_sub, | |
3506 | "mcastMemberOspfDesignatedRouters"); | |
3507 | } | |
3508 | } else { | |
3509 | vty_out(vty, " Multicast group memberships:"); | |
3510 | if (OI_MEMBER_CHECK(oi, MEMBER_ALLROUTERS) | |
3511 | || OI_MEMBER_CHECK(oi, MEMBER_DROUTERS)) { | |
3512 | if (OI_MEMBER_CHECK(oi, MEMBER_ALLROUTERS)) | |
3513 | vty_out(vty, " OSPFAllRouters"); | |
3514 | if (OI_MEMBER_CHECK(oi, MEMBER_DROUTERS)) | |
3515 | vty_out(vty, " OSPFDesignatedRouters"); | |
3516 | } else | |
3517 | vty_out(vty, " <None>"); | |
3518 | vty_out(vty, "\n"); | |
3519 | } | |
3520 | ||
3521 | if (use_json) { | |
3522 | if (OSPF_IF_PARAM(oi, fast_hello) == 0) | |
3523 | json_object_int_add( | |
3524 | json_interface_sub, "timerMsecs", | |
3525 | 1000 / OSPF_IF_PARAM(oi, v_hello)); | |
3526 | else | |
3527 | json_object_int_add( | |
3528 | json_interface_sub, "timerMsecs", | |
3529 | 1000 / OSPF_IF_PARAM(oi, fast_hello)); | |
3530 | json_object_int_add(json_interface_sub, | |
3531 | "timerDeadMsecs", | |
3532 | 1000 / OSPF_IF_PARAM(oi, v_wait)); | |
3533 | json_object_int_add(json_interface_sub, | |
3534 | "timerWaitMsecs", | |
3535 | 1000 / OSPF_IF_PARAM(oi, v_wait)); | |
3536 | json_object_int_add( | |
3537 | json_interface_sub, "timerRetransmit", | |
3538 | 1000 / OSPF_IF_PARAM(oi, retransmit_interval)); | |
3539 | } else { | |
3540 | vty_out(vty, " Timer intervals configured,"); | |
3541 | vty_out(vty, " Hello "); | |
3542 | if (OSPF_IF_PARAM(oi, fast_hello) == 0) | |
3543 | vty_out(vty, "%ds,", | |
3544 | OSPF_IF_PARAM(oi, v_hello)); | |
3545 | else | |
3546 | vty_out(vty, "%dms,", | |
3547 | 1000 / OSPF_IF_PARAM(oi, fast_hello)); | |
3548 | vty_out(vty, " Dead %ds, Wait %ds, Retransmit %d\n", | |
3549 | OSPF_IF_PARAM(oi, v_wait), | |
3550 | OSPF_IF_PARAM(oi, v_wait), | |
3551 | OSPF_IF_PARAM(oi, retransmit_interval)); | |
3552 | } | |
3553 | ||
3554 | if (OSPF_IF_PASSIVE_STATUS(oi) == OSPF_IF_ACTIVE) { | |
3555 | char timebuf[OSPF_TIME_DUMP_SIZE]; | |
3556 | if (use_json) { | |
3557 | long time_store = 0; | |
3558 | if (oi->t_hello) | |
3559 | time_store = | |
3560 | monotime_until( | |
3561 | &oi->t_hello->u.sands, | |
3562 | NULL) | |
3563 | / 1000LL; | |
3564 | json_object_int_add(json_interface_sub, | |
3565 | "timerHelloInMsecs", | |
3566 | time_store); | |
3567 | } else | |
3568 | vty_out(vty, " Hello due in %s\n", | |
3569 | ospf_timer_dump(oi->t_hello, timebuf, | |
3570 | sizeof(timebuf))); | |
3571 | } else /* passive-interface is set */ | |
3572 | { | |
3573 | if (use_json) | |
3574 | json_object_boolean_true_add( | |
3575 | json_interface_sub, | |
3576 | "timerPassiveIface"); | |
3577 | else | |
3578 | vty_out(vty, | |
3579 | " No Hellos (Passive interface)\n"); | |
3580 | } | |
7c8ff89e | 3581 | |
d62a17ae | 3582 | if (use_json) { |
3583 | json_object_int_add(json_interface_sub, "nbrCount", | |
3584 | ospf_nbr_count(oi, 0)); | |
3585 | json_object_int_add(json_interface_sub, | |
3586 | "nbrAdjacentCount", | |
3587 | ospf_nbr_count(oi, NSM_Full)); | |
3588 | } else | |
3589 | vty_out(vty, | |
3590 | " Neighbor Count is %d, Adjacent neighbor count is %d\n", | |
3591 | ospf_nbr_count(oi, 0), | |
3592 | ospf_nbr_count(oi, NSM_Full)); | |
3593 | ospf_bfd_interface_show(vty, ifp, json_interface_sub, use_json); | |
3594 | } | |
718e3744 | 3595 | } |
3596 | ||
d62a17ae | 3597 | static int show_ip_ospf_interface_common(struct vty *vty, struct ospf *ospf, |
3598 | int argc, struct cmd_token **argv, | |
3599 | int iface_argv, u_char use_json) | |
3600 | { | |
3601 | struct interface *ifp; | |
f4e14fdb | 3602 | struct vrf *vrf = vrf_lookup_by_id(ospf->vrf_id); |
d62a17ae | 3603 | json_object *json = NULL; |
3604 | json_object *json_interface_sub = NULL; | |
7c8ff89e | 3605 | |
d62a17ae | 3606 | if (use_json) { |
3607 | json = json_object_new_object(); | |
3608 | } | |
3609 | ||
3610 | if (ospf->instance) { | |
3611 | if (use_json) | |
3612 | json_object_int_add(json, "ospfInstance", | |
3613 | ospf->instance); | |
3614 | else | |
3615 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
3616 | } | |
3617 | ||
3618 | if (argc == iface_argv) { | |
3619 | /* Show All Interfaces.*/ | |
451fda4f | 3620 | FOR_ALL_INTERFACES (vrf, ifp) { |
d62a17ae | 3621 | if (ospf_oi_count(ifp)) { |
3622 | if (use_json) | |
3623 | json_interface_sub = | |
3624 | json_object_new_object(); | |
3625 | ||
3626 | show_ip_ospf_interface_sub(vty, ospf, ifp, | |
3627 | json_interface_sub, | |
3628 | use_json); | |
3629 | ||
3630 | if (use_json) | |
3631 | json_object_object_add( | |
3632 | json, ifp->name, | |
3633 | json_interface_sub); | |
3634 | } | |
3635 | } | |
3636 | } else { | |
3637 | /* Interface name is specified. */ | |
3638 | if ((ifp = if_lookup_by_name(argv[iface_argv]->arg, | |
b5a8894d | 3639 | ospf->vrf_id)) |
d62a17ae | 3640 | == NULL) { |
3641 | if (use_json) | |
3642 | json_object_boolean_true_add(json, | |
3643 | "noSuchIface"); | |
3644 | else | |
3645 | vty_out(vty, "No such interface name\n"); | |
3646 | } else { | |
3647 | if (use_json) | |
3648 | json_interface_sub = json_object_new_object(); | |
3649 | ||
3650 | show_ip_ospf_interface_sub( | |
3651 | vty, ospf, ifp, json_interface_sub, use_json); | |
3652 | ||
3653 | if (use_json) | |
3654 | json_object_object_add(json, ifp->name, | |
3655 | json_interface_sub); | |
3656 | } | |
3657 | } | |
3658 | ||
3659 | if (use_json) { | |
9d303b37 DL |
3660 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
3661 | json, JSON_C_TO_STRING_PRETTY)); | |
d62a17ae | 3662 | json_object_free(json); |
3663 | } else | |
3664 | vty_out(vty, "\n"); | |
3665 | ||
3666 | return CMD_SUCCESS; | |
718e3744 | 3667 | } |
3668 | ||
c9339663 CS |
3669 | static void show_ip_ospf_interface_traffic_sub(struct vty *vty, |
3670 | struct ospf_interface *oi, | |
3671 | json_object *json_interface_sub, | |
3672 | u_char use_json) | |
3673 | { | |
3674 | if (use_json) { | |
3675 | json_object_int_add(json_interface_sub, | |
3676 | "ifIndex", | |
3677 | oi->ifp->ifindex); | |
3678 | json_object_int_add(json_interface_sub, | |
3679 | "helloIn", | |
3680 | oi->hello_in); | |
3681 | json_object_int_add(json_interface_sub, | |
3682 | "helloOut", | |
3683 | oi->hello_out); | |
3684 | json_object_int_add(json_interface_sub, | |
3685 | "dbDescIn", | |
3686 | oi->db_desc_in); | |
3687 | json_object_int_add(json_interface_sub, | |
3688 | "dbDescOut", | |
3689 | oi->db_desc_out); | |
3690 | json_object_int_add(json_interface_sub, | |
3691 | "lsReqIn", | |
3692 | oi->ls_req_in); | |
3693 | json_object_int_add(json_interface_sub, | |
3694 | "lsReqOut", | |
3695 | oi->ls_req_out); | |
3696 | json_object_int_add(json_interface_sub, | |
3697 | "lsUpdIn", | |
3698 | oi->ls_upd_in); | |
3699 | json_object_int_add(json_interface_sub, | |
3700 | "lsUpdOut", | |
3701 | oi->ls_upd_out); | |
3702 | json_object_int_add(json_interface_sub, | |
3703 | "lsAckIn", | |
3704 | oi->ls_ack_in); | |
3705 | json_object_int_add(json_interface_sub, | |
3706 | "lsAckOut", | |
3707 | oi->ls_ack_out); | |
3708 | } else { | |
3709 | vty_out(vty, | |
3710 | "%-10s %8u/%-8u %7u/%-7u %7u/%-7u %7u/%-7u %7u/%-7u\n", | |
3711 | oi->ifp->name, oi->hello_in, | |
3712 | oi->hello_out, | |
3713 | oi->db_desc_in, oi->db_desc_out, | |
3714 | oi->ls_req_in, oi->ls_req_out, | |
3715 | oi->ls_upd_in, oi->ls_upd_out, | |
3716 | oi->ls_ack_in, oi->ls_ack_out); | |
3717 | } | |
3718 | } | |
3719 | ||
3720 | /* OSPFv2 Packet Counters */ | |
3721 | static int show_ip_ospf_interface_traffic_common(struct vty *vty, | |
3722 | struct ospf *ospf, | |
3723 | char *intf_name, | |
3724 | int display_once, | |
3725 | u_char use_json) | |
3726 | { | |
3727 | struct vrf *vrf = NULL; | |
3728 | struct interface *ifp = NULL; | |
3729 | json_object *json = NULL; | |
3730 | json_object *json_interface_sub = NULL; | |
3731 | ||
3732 | if (!use_json && !display_once) { | |
3733 | vty_out(vty, "\n"); | |
3734 | vty_out(vty, "%-12s%-17s%-17s%-17s%-17s%-17s\n", | |
3735 | "Interface", " HELLO", " DB-Desc", " LS-Req", | |
3736 | " LS-Update", " LS-Ack"); | |
3737 | vty_out(vty, "%-10s%-18s%-18s%-17s%-17s%-17s\n", "", | |
3738 | " Rx/Tx", " Rx/Tx", " Rx/Tx", " Rx/Tx", " Rx/Tx"); | |
3739 | vty_out(vty, | |
3740 | "--------------------------------------------------------------------------------------------\n"); | |
3741 | } else if (use_json) { | |
3742 | json = json_object_new_object(); | |
3743 | } | |
3744 | ||
3745 | if (intf_name == NULL) { | |
3746 | vrf = vrf_lookup_by_id(ospf->vrf_id); | |
3747 | FOR_ALL_INTERFACES (vrf, ifp) { | |
3748 | struct route_node *rn; | |
3749 | struct ospf_interface *oi; | |
3750 | ||
3751 | if (ospf_oi_count(ifp) == 0) | |
3752 | continue; | |
3753 | ||
3754 | for (rn = route_top(IF_OIFS(ifp)); rn; | |
3755 | rn = route_next(rn)) { | |
3756 | oi = rn->info; | |
3757 | ||
3758 | if (oi == NULL) | |
3759 | continue; | |
3760 | ||
3761 | if (use_json) { | |
3762 | json_interface_sub = | |
3763 | json_object_new_object(); | |
3764 | } | |
3765 | ||
3766 | show_ip_ospf_interface_traffic_sub(vty, oi, | |
3767 | json_interface_sub, | |
3768 | use_json); | |
3769 | if (use_json) { | |
3770 | json_object_object_add(json, ifp->name, | |
3771 | json_interface_sub); | |
3772 | } | |
3773 | } | |
3774 | } | |
3775 | } else { | |
3776 | /* Interface name is specified. */ | |
3777 | ifp = if_lookup_by_name(intf_name, ospf->vrf_id); | |
3778 | if (ifp != NULL) { | |
3779 | struct route_node *rn; | |
3780 | struct ospf_interface *oi; | |
3781 | ||
3782 | if (ospf_oi_count(ifp) == 0) { | |
3783 | vty_out(vty, " OSPF not enabled on this interface %s\n", | |
3784 | ifp->name); | |
3785 | return CMD_SUCCESS; | |
3786 | } | |
3787 | ||
3788 | for (rn = route_top(IF_OIFS(ifp)); rn; | |
3789 | rn = route_next(rn)) { | |
3790 | oi = rn->info; | |
3791 | ||
3792 | if (use_json) { | |
3793 | json_interface_sub = | |
3794 | json_object_new_object(); | |
3795 | } | |
3796 | ||
3797 | show_ip_ospf_interface_traffic_sub(vty, oi, | |
3798 | json_interface_sub, | |
3799 | use_json); | |
3800 | if (use_json) { | |
3801 | json_object_object_add(json, ifp->name, | |
3802 | json_interface_sub); | |
3803 | } | |
3804 | } | |
3805 | } | |
3806 | } | |
3807 | ||
3808 | if (use_json) { | |
3809 | vty_out(vty, "%s\n", json_object_to_json_string_ext( | |
3810 | json, JSON_C_TO_STRING_PRETTY)); | |
3811 | json_object_free(json); | |
3812 | } | |
3813 | ||
3814 | return CMD_SUCCESS; | |
3815 | } | |
3816 | ||
7c8ff89e DS |
3817 | DEFUN (show_ip_ospf_interface, |
3818 | show_ip_ospf_interface_cmd, | |
43b8d1d8 | 3819 | "show ip ospf [vrf <NAME|all>] interface [INTERFACE] [json]", |
7c8ff89e DS |
3820 | SHOW_STR |
3821 | IP_STR | |
3822 | "OSPF information\n" | |
b5a8894d | 3823 | VRF_CMD_HELP_STR |
43b8d1d8 | 3824 | "All VRFs\n" |
7c8ff89e | 3825 | "Interface information\n" |
7ec4159b | 3826 | "Interface name\n" |
9973d184 | 3827 | JSON_STR) |
7c8ff89e | 3828 | { |
d62a17ae | 3829 | struct ospf *ospf; |
3830 | u_char uj = use_json(argc, argv); | |
b5a8894d CS |
3831 | struct listnode *node = NULL; |
3832 | char *vrf_name = NULL; | |
3833 | bool all_vrf = FALSE; | |
3834 | int ret = CMD_SUCCESS; | |
3835 | int inst = 0; | |
3836 | int idx_vrf = 0; | |
7c8ff89e | 3837 | |
43b8d1d8 CS |
3838 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
3839 | ||
d62a17ae | 3840 | if (uj) |
3841 | argc--; | |
6be4da3d | 3842 | |
b5a8894d CS |
3843 | /* vrf input is provided could be all or specific vrf*/ |
3844 | if (vrf_name) { | |
3845 | if (all_vrf) { | |
3846 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
3847 | if (!ospf->oi_running) | |
3848 | continue; | |
3849 | ret = show_ip_ospf_interface_common(vty, | |
3850 | ospf, argc, | |
3851 | argv, 6, | |
3852 | uj); | |
3853 | } | |
3854 | return ret; | |
3855 | } | |
3856 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
3857 | if (ospf == NULL || !ospf->oi_running) | |
3858 | return CMD_SUCCESS; | |
3859 | ret = show_ip_ospf_interface_common(vty, ospf, | |
3860 | argc, argv, 6, uj); | |
3861 | ||
3862 | } else { | |
3863 | /* Display default ospf (instance 0) info */ | |
3864 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
3865 | if (ospf == NULL || !ospf->oi_running) | |
3866 | return CMD_SUCCESS; | |
3867 | ret = show_ip_ospf_interface_common(vty, ospf, | |
3868 | argc, argv, 4, uj); | |
3869 | } | |
3870 | ||
3871 | return ret; | |
7c8ff89e DS |
3872 | } |
3873 | ||
3874 | DEFUN (show_ip_ospf_instance_interface, | |
3875 | show_ip_ospf_instance_interface_cmd, | |
6147e2c6 | 3876 | "show ip ospf (1-65535) interface [INTERFACE] [json]", |
7c8ff89e DS |
3877 | SHOW_STR |
3878 | IP_STR | |
3879 | "OSPF information\n" | |
3880 | "Instance ID\n" | |
3881 | "Interface information\n" | |
7ec4159b | 3882 | "Interface name\n" |
9973d184 | 3883 | JSON_STR) |
7c8ff89e | 3884 | { |
d62a17ae | 3885 | int idx_number = 3; |
3886 | struct ospf *ospf; | |
3887 | u_short instance = 0; | |
3888 | u_char uj = use_json(argc, argv); | |
3889 | ||
3890 | instance = strtoul(argv[idx_number]->arg, NULL, 10); | |
ac28e4ec CS |
3891 | ospf = ospf_lookup_instance(instance); |
3892 | if (ospf == NULL) | |
3893 | return CMD_NOT_MY_INSTANCE; | |
3894 | ||
3895 | if (!ospf->oi_running) | |
d62a17ae | 3896 | return CMD_SUCCESS; |
3897 | ||
3898 | if (uj) | |
3899 | argc--; | |
3900 | ||
3901 | return show_ip_ospf_interface_common(vty, ospf, argc, argv, 5, uj); | |
3902 | } | |
3903 | ||
c9339663 CS |
3904 | DEFUN (show_ip_ospf_interface_traffic, |
3905 | show_ip_ospf_interface_traffic_cmd, | |
3906 | "show ip ospf [vrf <NAME|all>] interface traffic [INTERFACE] [json]", | |
3907 | SHOW_STR | |
3908 | IP_STR | |
3909 | "OSPF information\n" | |
3910 | VRF_CMD_HELP_STR | |
3911 | "All VRFs\n" | |
3912 | "Interface information\n" | |
3913 | "Protocol Packet counters\n" | |
3914 | "Interface name\n" | |
3915 | JSON_STR) | |
3916 | { | |
3917 | struct ospf *ospf = NULL; | |
3918 | struct listnode *node = NULL; | |
3919 | char *vrf_name = NULL, *intf_name = NULL; | |
3920 | bool all_vrf = FALSE; | |
3921 | int inst = 0; | |
3922 | int idx_vrf = 0, idx_intf = 0; | |
3923 | u_char uj = use_json(argc, argv); | |
3924 | int ret = CMD_SUCCESS; | |
3925 | int display_once = 0; | |
3926 | ||
3927 | if (uj) | |
3928 | argc--; | |
3929 | ||
3930 | ||
3931 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); | |
3932 | ||
3933 | if (argv_find(argv, argc, "INTERFACE", &idx_intf)) | |
3934 | intf_name = argv[idx_intf]->arg; | |
3935 | ||
3936 | if (vrf_name) { | |
3937 | if (all_vrf) { | |
3938 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
3939 | if (!ospf->oi_running) | |
3940 | continue; | |
3941 | ||
3942 | ret = show_ip_ospf_interface_traffic_common(vty, | |
3943 | ospf, intf_name, | |
3944 | display_once, | |
3945 | uj); | |
3946 | display_once = 1; | |
3947 | } | |
3948 | return ret; | |
3949 | } | |
3950 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
3951 | if (ospf == NULL || !ospf->oi_running) | |
3952 | return CMD_SUCCESS; | |
3953 | ret = show_ip_ospf_interface_traffic_common(vty, ospf, | |
3954 | intf_name, | |
3955 | display_once, uj); | |
3956 | } else { | |
3957 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
3958 | if (ospf == NULL || !ospf->oi_running) | |
3959 | return CMD_SUCCESS; | |
3960 | ret = show_ip_ospf_interface_traffic_common(vty, ospf, | |
3961 | intf_name, | |
3962 | display_once, uj); | |
3963 | } | |
3964 | ||
3965 | return ret; | |
3966 | } | |
3967 | ||
3968 | ||
d62a17ae | 3969 | static void show_ip_ospf_neighbour_header(struct vty *vty) |
3970 | { | |
3971 | vty_out(vty, "\n%-15s %3s %-15s %9s %-15s %-20s %5s %5s %5s\n", | |
3972 | "Neighbor ID", "Pri", "State", "Dead Time", "Address", | |
3973 | "Interface", "RXmtL", "RqstL", "DBsmL"); | |
3974 | } | |
3975 | ||
3976 | static void show_ip_ospf_neighbor_sub(struct vty *vty, | |
3977 | struct ospf_interface *oi, | |
3978 | json_object *json, u_char use_json) | |
3979 | { | |
3980 | struct route_node *rn; | |
3981 | struct ospf_neighbor *nbr; | |
3982 | char msgbuf[16]; | |
3983 | char timebuf[OSPF_TIME_DUMP_SIZE]; | |
3984 | json_object *json_neighbor = NULL; | |
3985 | ||
3986 | for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) { | |
3987 | if ((nbr = rn->info)) { | |
3988 | /* Do not show myself. */ | |
3989 | if (nbr != oi->nbr_self) { | |
3990 | /* Down state is not shown. */ | |
3991 | if (nbr->state != NSM_Down) { | |
3992 | if (use_json) { | |
3993 | json_neighbor = | |
3994 | json_object_new_object(); | |
3995 | ospf_nbr_state_message( | |
3996 | nbr, msgbuf, 16); | |
3997 | ||
3998 | long time_store; | |
3999 | ||
4000 | time_store = | |
4001 | monotime_until( | |
4002 | &nbr->t_inactivity | |
4003 | ->u | |
4004 | .sands, | |
4005 | NULL) | |
4006 | / 1000LL; | |
4007 | ||
4008 | json_object_int_add( | |
4009 | json_neighbor, | |
4010 | "priority", | |
4011 | nbr->priority); | |
4012 | json_object_string_add( | |
4013 | json_neighbor, "state", | |
4014 | msgbuf); | |
4015 | json_object_int_add( | |
4016 | json_neighbor, | |
4017 | "deadTimeMsecs", | |
4018 | time_store); | |
4019 | json_object_string_add( | |
4020 | json_neighbor, | |
4021 | "address", | |
4022 | inet_ntoa(nbr->src)); | |
4023 | json_object_string_add( | |
4024 | json_neighbor, | |
4025 | "ifaceName", | |
4026 | IF_NAME(oi)); | |
4027 | json_object_int_add( | |
4028 | json_neighbor, | |
4029 | "retransmitCounter", | |
4030 | ospf_ls_retransmit_count( | |
4031 | nbr)); | |
4032 | json_object_int_add( | |
4033 | json_neighbor, | |
4034 | "requestCounter", | |
4035 | ospf_ls_request_count( | |
4036 | nbr)); | |
4037 | json_object_int_add( | |
4038 | json_neighbor, | |
4039 | "dbSummaryCounter", | |
4040 | ospf_db_summary_count( | |
4041 | nbr)); | |
4042 | if (nbr->state == NSM_Attempt | |
4043 | && nbr->router_id.s_addr | |
4044 | == 0) | |
4045 | json_object_object_add( | |
4046 | json, | |
4047 | "neighbor", | |
4048 | json_neighbor); | |
4049 | else | |
4050 | json_object_object_add( | |
4051 | json, | |
4052 | inet_ntoa( | |
4053 | nbr->router_id), | |
4054 | json_neighbor); | |
4055 | } else { | |
4056 | ospf_nbr_state_message( | |
4057 | nbr, msgbuf, 16); | |
4058 | ||
4059 | if (nbr->state == NSM_Attempt | |
4060 | && nbr->router_id.s_addr | |
4061 | == 0) | |
4062 | vty_out(vty, | |
4063 | "%-15s %3d %-15s ", | |
4064 | "-", | |
4065 | nbr->priority, | |
4066 | msgbuf); | |
4067 | else | |
4068 | vty_out(vty, | |
4069 | "%-15s %3d %-15s ", | |
4070 | inet_ntoa( | |
4071 | nbr->router_id), | |
4072 | nbr->priority, | |
4073 | msgbuf); | |
4074 | ||
4075 | vty_out(vty, "%9s ", | |
4076 | ospf_timer_dump( | |
4077 | nbr->t_inactivity, | |
4078 | timebuf, | |
4079 | sizeof(timebuf))); | |
4080 | vty_out(vty, "%-15s ", | |
4081 | inet_ntoa(nbr->src)); | |
4082 | vty_out(vty, | |
4083 | "%-20s %5ld %5ld %5d\n", | |
4084 | IF_NAME(oi), | |
4085 | ospf_ls_retransmit_count( | |
4086 | nbr), | |
4087 | ospf_ls_request_count( | |
4088 | nbr), | |
4089 | ospf_db_summary_count( | |
4090 | nbr)); | |
4091 | } | |
4092 | } | |
4093 | } | |
4094 | } | |
4095 | } | |
4096 | } | |
4097 | ||
4098 | static int show_ip_ospf_neighbor_common(struct vty *vty, struct ospf *ospf, | |
4099 | u_char use_json) | |
4100 | { | |
4101 | struct ospf_interface *oi; | |
4102 | struct listnode *node; | |
4103 | json_object *json = NULL; | |
7c8ff89e | 4104 | |
d62a17ae | 4105 | if (use_json) |
4106 | json = json_object_new_object(); | |
d62a17ae | 4107 | |
4108 | if (ospf->instance) { | |
4109 | if (use_json) | |
4110 | json_object_int_add(json, "ospfInstance", | |
4111 | ospf->instance); | |
4112 | else | |
4113 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
4114 | } | |
7c8ff89e | 4115 | |
52d0c099 | 4116 | ospf_show_vrf_name(ospf, vty, json); |
87bd50e8 | 4117 | |
d62a17ae | 4118 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) |
4119 | show_ip_ospf_neighbor_sub(vty, oi, json, use_json); | |
718e3744 | 4120 | |
d62a17ae | 4121 | if (use_json) { |
9d303b37 DL |
4122 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
4123 | json, JSON_C_TO_STRING_PRETTY)); | |
d62a17ae | 4124 | json_object_free(json); |
4125 | } else | |
4126 | vty_out(vty, "\n"); | |
7c8ff89e | 4127 | |
d62a17ae | 4128 | return CMD_SUCCESS; |
718e3744 | 4129 | } |
4130 | ||
7c8ff89e DS |
4131 | DEFUN (show_ip_ospf_neighbor, |
4132 | show_ip_ospf_neighbor_cmd, | |
b5a8894d | 4133 | "show ip ospf [vrf <NAME|all>] neighbor [json]", |
718e3744 | 4134 | SHOW_STR |
4135 | IP_STR | |
4136 | "OSPF information\n" | |
b5a8894d CS |
4137 | VRF_CMD_HELP_STR |
4138 | "All VRFs\n" | |
91756b38 | 4139 | "Neighbor list\n" |
9973d184 | 4140 | JSON_STR) |
718e3744 | 4141 | { |
d62a17ae | 4142 | struct ospf *ospf; |
4143 | u_char uj = use_json(argc, argv); | |
b5a8894d CS |
4144 | struct listnode *node = NULL; |
4145 | char *vrf_name = NULL; | |
4146 | bool all_vrf = FALSE; | |
4147 | int ret = CMD_SUCCESS; | |
4148 | int inst = 0; | |
4149 | int idx_vrf = 0; | |
718e3744 | 4150 | |
43b8d1d8 | 4151 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
7c8ff89e | 4152 | |
b5a8894d CS |
4153 | if (!uj) |
4154 | show_ip_ospf_neighbour_header(vty); | |
4155 | ||
4156 | /* vrf input is provided could be all or specific vrf*/ | |
4157 | if (vrf_name) { | |
4158 | if (all_vrf) { | |
4159 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
4160 | if (!ospf->oi_running) | |
4161 | continue; | |
4162 | ret = show_ip_ospf_neighbor_common(vty, ospf, | |
4163 | uj); | |
4164 | } | |
4165 | return ret; | |
4166 | } | |
4167 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
4168 | if (ospf == NULL || !ospf->oi_running) | |
4169 | return CMD_SUCCESS; | |
4170 | } else { | |
4171 | /* Display default ospf (instance 0) info */ | |
4172 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
4173 | if (ospf == NULL || !ospf->oi_running) | |
4174 | return CMD_SUCCESS; | |
4175 | } | |
4176 | ||
4177 | if (ospf) | |
4178 | ret = show_ip_ospf_neighbor_common(vty, ospf, uj); | |
4179 | ||
4180 | return ret; | |
7c8ff89e DS |
4181 | } |
4182 | ||
4183 | ||
4184 | DEFUN (show_ip_ospf_instance_neighbor, | |
4185 | show_ip_ospf_instance_neighbor_cmd, | |
6147e2c6 | 4186 | "show ip ospf (1-65535) neighbor [json]", |
7c8ff89e DS |
4187 | SHOW_STR |
4188 | IP_STR | |
4189 | "OSPF information\n" | |
4190 | "Instance ID\n" | |
91756b38 | 4191 | "Neighbor list\n" |
9973d184 | 4192 | JSON_STR) |
7c8ff89e | 4193 | { |
d62a17ae | 4194 | int idx_number = 3; |
4195 | struct ospf *ospf; | |
4196 | u_short instance = 0; | |
4197 | u_char uj = use_json(argc, argv); | |
7c8ff89e | 4198 | |
d62a17ae | 4199 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
ac28e4ec CS |
4200 | ospf = ospf_lookup_instance(instance); |
4201 | if (ospf == NULL) | |
4202 | return CMD_NOT_MY_INSTANCE; | |
4203 | ||
4204 | if (!ospf->oi_running) | |
d62a17ae | 4205 | return CMD_SUCCESS; |
7c8ff89e | 4206 | |
b5a8894d CS |
4207 | if (!uj) |
4208 | show_ip_ospf_neighbour_header(vty); | |
4209 | ||
d62a17ae | 4210 | return show_ip_ospf_neighbor_common(vty, ospf, uj); |
7c8ff89e DS |
4211 | } |
4212 | ||
d62a17ae | 4213 | static int show_ip_ospf_neighbor_all_common(struct vty *vty, struct ospf *ospf, |
4214 | u_char use_json) | |
4215 | { | |
4216 | struct listnode *node; | |
4217 | struct ospf_interface *oi; | |
4218 | json_object *json = NULL; | |
4219 | json_object *json_neighbor_sub = NULL; | |
7c8ff89e | 4220 | |
d62a17ae | 4221 | if (use_json) { |
4222 | json = json_object_new_object(); | |
4223 | json_neighbor_sub = json_object_new_object(); | |
b5a8894d | 4224 | } |
d62a17ae | 4225 | |
4226 | if (ospf->instance) { | |
4227 | if (use_json) | |
4228 | json_object_int_add(json, "ospfInstance", | |
4229 | ospf->instance); | |
4230 | else | |
4231 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
4232 | } | |
4233 | ||
b5a8894d CS |
4234 | if (ospf->name) { |
4235 | if (use_json) { | |
4236 | json_object_int_add(json, "vrfId", | |
4237 | (ospf->vrf_id == VRF_UNKNOWN) | |
4238 | ? -1 : ospf->vrf_id); | |
4239 | json_object_string_add(json, "vrfName", | |
4240 | (ospf->vrf_id == VRF_DEFAULT) | |
4241 | ? "Default" : ospf->name); | |
4242 | } else { | |
4243 | vty_out(vty, "\nOSPF vrf: %s\n\n", | |
4244 | ospf->vrf_id == VRF_DEFAULT | |
4245 | ? "Default" : ospf->name); | |
4246 | } | |
4247 | } | |
4248 | ||
4249 | ||
d62a17ae | 4250 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) { |
4251 | struct listnode *nbr_node; | |
4252 | struct ospf_nbr_nbma *nbr_nbma; | |
4253 | ||
4254 | show_ip_ospf_neighbor_sub(vty, oi, json, use_json); | |
4255 | ||
4256 | /* print Down neighbor status */ | |
4257 | for (ALL_LIST_ELEMENTS_RO(oi->nbr_nbma, nbr_node, nbr_nbma)) { | |
4258 | if (nbr_nbma->nbr == NULL | |
4259 | || nbr_nbma->nbr->state == NSM_Down) { | |
4260 | if (use_json) { | |
4261 | json_object_int_add(json_neighbor_sub, | |
4262 | "nbrNbmaPriority", | |
4263 | nbr_nbma->priority); | |
4264 | json_object_boolean_true_add( | |
4265 | json_neighbor_sub, | |
4266 | "nbrNbmaDown"); | |
4267 | json_object_string_add( | |
4268 | json_neighbor_sub, | |
4269 | "nbrNbmaIfaceName", | |
4270 | IF_NAME(oi)); | |
4271 | json_object_int_add( | |
4272 | json_neighbor_sub, | |
4273 | "nbrNbmaRetransmitCounter", 0); | |
4274 | json_object_int_add( | |
4275 | json_neighbor_sub, | |
4276 | "nbrNbmaRequestCounter", 0); | |
4277 | json_object_int_add( | |
4278 | json_neighbor_sub, | |
4279 | "nbrNbmaDbSummaryCounter", 0); | |
4280 | json_object_object_add( | |
4281 | json, inet_ntoa(nbr_nbma->addr), | |
4282 | json_neighbor_sub); | |
4283 | } else { | |
4284 | vty_out(vty, "%-15s %3d %-15s %9s ", | |
4285 | "-", nbr_nbma->priority, "Down", | |
4286 | "-"); | |
4287 | vty_out(vty, | |
4288 | "%-15s %-20s %5d %5d %5d\n", | |
4289 | inet_ntoa(nbr_nbma->addr), | |
4290 | IF_NAME(oi), 0, 0, 0); | |
4291 | } | |
4292 | } | |
4293 | } | |
4294 | } | |
4295 | ||
4296 | if (use_json) { | |
9d303b37 DL |
4297 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
4298 | json, JSON_C_TO_STRING_PRETTY)); | |
d62a17ae | 4299 | json_object_free(json); |
4300 | } else | |
4301 | vty_out(vty, "\n"); | |
4302 | ||
4303 | return CMD_SUCCESS; | |
718e3744 | 4304 | } |
4305 | ||
7c8ff89e DS |
4306 | DEFUN (show_ip_ospf_neighbor_all, |
4307 | show_ip_ospf_neighbor_all_cmd, | |
b5a8894d | 4308 | "show ip ospf [vrf <NAME|all>] neighbor all [json]", |
718e3744 | 4309 | SHOW_STR |
4310 | IP_STR | |
4311 | "OSPF information\n" | |
b5a8894d CS |
4312 | VRF_CMD_HELP_STR |
4313 | "All VRFs\n" | |
718e3744 | 4314 | "Neighbor list\n" |
91756b38 | 4315 | "include down status neighbor\n" |
9973d184 | 4316 | JSON_STR) |
7c8ff89e | 4317 | { |
d62a17ae | 4318 | struct ospf *ospf; |
4319 | u_char uj = use_json(argc, argv); | |
b5a8894d CS |
4320 | struct listnode *node = NULL; |
4321 | char *vrf_name = NULL; | |
4322 | bool all_vrf = FALSE; | |
4323 | int ret = CMD_SUCCESS; | |
4324 | int inst = 0; | |
4325 | int idx_vrf = 0; | |
7c8ff89e | 4326 | |
43b8d1d8 | 4327 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
7c8ff89e | 4328 | |
b5a8894d CS |
4329 | if (!uj) |
4330 | show_ip_ospf_neighbour_header(vty); | |
4331 | ||
4332 | /* vrf input is provided could be all or specific vrf*/ | |
4333 | if (vrf_name) { | |
4334 | if (all_vrf) { | |
4335 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
4336 | if (!ospf->oi_running) | |
4337 | continue; | |
4338 | ret = show_ip_ospf_neighbor_all_common(vty, | |
4339 | ospf, | |
4340 | uj); | |
4341 | } | |
4342 | return ret; | |
4343 | } | |
4344 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
4345 | if (ospf == NULL || !ospf->oi_running) | |
4346 | return CMD_SUCCESS; | |
4347 | } else { | |
4348 | /* Display default ospf (instance 0) info */ | |
4349 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
4350 | if (ospf == NULL || !ospf->oi_running) | |
4351 | return CMD_SUCCESS; | |
4352 | } | |
4353 | ||
4354 | if (ospf) | |
4355 | ret = show_ip_ospf_neighbor_all_common(vty, ospf, uj); | |
4356 | ||
4357 | return ret; | |
7c8ff89e DS |
4358 | } |
4359 | ||
4360 | DEFUN (show_ip_ospf_instance_neighbor_all, | |
4361 | show_ip_ospf_instance_neighbor_all_cmd, | |
6147e2c6 | 4362 | "show ip ospf (1-65535) neighbor all [json]", |
7c8ff89e DS |
4363 | SHOW_STR |
4364 | IP_STR | |
4365 | "OSPF information\n" | |
4366 | "Instance ID\n" | |
4367 | "Neighbor list\n" | |
91756b38 | 4368 | "include down status neighbor\n" |
9973d184 | 4369 | JSON_STR) |
718e3744 | 4370 | { |
d62a17ae | 4371 | int idx_number = 3; |
4372 | struct ospf *ospf; | |
4373 | u_short instance = 0; | |
4374 | u_char uj = use_json(argc, argv); | |
7c8ff89e | 4375 | |
d62a17ae | 4376 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
ac28e4ec CS |
4377 | ospf = ospf_lookup_instance(instance); |
4378 | if (ospf == NULL) | |
4379 | return CMD_NOT_MY_INSTANCE; | |
4380 | ||
4381 | if (!ospf->oi_running) | |
d62a17ae | 4382 | return CMD_SUCCESS; |
7c8ff89e | 4383 | |
d62a17ae | 4384 | return show_ip_ospf_neighbor_all_common(vty, ospf, uj); |
7c8ff89e DS |
4385 | } |
4386 | ||
d62a17ae | 4387 | static int show_ip_ospf_neighbor_int_common(struct vty *vty, struct ospf *ospf, |
4388 | int arg_base, | |
4389 | struct cmd_token **argv, | |
4390 | u_char use_json) | |
4391 | { | |
4392 | struct interface *ifp; | |
4393 | struct route_node *rn; | |
4394 | json_object *json = NULL; | |
91756b38 | 4395 | |
d62a17ae | 4396 | if (use_json) |
4397 | json = json_object_new_object(); | |
d62a17ae | 4398 | |
4399 | if (ospf->instance) { | |
4400 | if (use_json) | |
4401 | json_object_int_add(json, "ospfInstance", | |
4402 | ospf->instance); | |
4403 | else | |
4404 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
4405 | } | |
4406 | ||
52d0c099 | 4407 | ospf_show_vrf_name(ospf, vty, json); |
87bd50e8 | 4408 | |
b5a8894d CS |
4409 | /*ifp = if_lookup_by_name(argv[arg_base]->arg, ospf->vrf_id);*/ |
4410 | ifp = if_lookup_by_name_all_vrf(argv[arg_base]->arg); | |
d62a17ae | 4411 | if (!ifp) { |
4412 | if (use_json) | |
4413 | json_object_boolean_true_add(json, "noSuchIface"); | |
4414 | else | |
4415 | vty_out(vty, "No such interface.\n"); | |
4416 | return CMD_WARNING; | |
4417 | } | |
4418 | ||
4419 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { | |
4420 | struct ospf_interface *oi = rn->info; | |
4421 | ||
4422 | if (oi == NULL) | |
4423 | continue; | |
4424 | ||
4425 | show_ip_ospf_neighbor_sub(vty, oi, json, use_json); | |
4426 | } | |
4427 | ||
4428 | if (use_json) { | |
9d303b37 DL |
4429 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
4430 | json, JSON_C_TO_STRING_PRETTY)); | |
d62a17ae | 4431 | json_object_free(json); |
4432 | } else | |
4433 | vty_out(vty, "\n"); | |
4434 | ||
4435 | return CMD_SUCCESS; | |
718e3744 | 4436 | } |
4437 | ||
7c8ff89e DS |
4438 | DEFUN (show_ip_ospf_neighbor_int, |
4439 | show_ip_ospf_neighbor_int_cmd, | |
b162fa78 | 4440 | "show ip ospf neighbor IFNAME [json]", |
7c8ff89e DS |
4441 | SHOW_STR |
4442 | IP_STR | |
4443 | "OSPF information\n" | |
4444 | "Neighbor list\n" | |
91756b38 | 4445 | "Interface name\n" |
9973d184 | 4446 | JSON_STR) |
7c8ff89e | 4447 | { |
d62a17ae | 4448 | struct ospf *ospf; |
b4e84315 | 4449 | int idx_ifname = 4; |
d62a17ae | 4450 | u_char uj = use_json(argc, argv); |
b5a8894d CS |
4451 | struct listnode *node = NULL; |
4452 | int ret = CMD_SUCCESS; | |
4453 | struct interface *ifp = NULL; | |
7c8ff89e | 4454 | |
b5a8894d CS |
4455 | if (!uj) |
4456 | show_ip_ospf_neighbour_header(vty); | |
7c8ff89e | 4457 | |
b5a8894d CS |
4458 | ifp = if_lookup_by_name_all_vrf(argv[idx_ifname]->arg); |
4459 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
4460 | if (!ospf->oi_running) | |
4461 | continue; | |
4462 | if (!ifp || ifp->vrf_id != ospf->vrf_id) | |
4463 | continue; | |
4464 | ret = show_ip_ospf_neighbor_int_common(vty, ospf, | |
4465 | idx_ifname, argv, uj); | |
4466 | } | |
4467 | ||
4468 | return ret; | |
7c8ff89e DS |
4469 | } |
4470 | ||
4471 | DEFUN (show_ip_ospf_instance_neighbor_int, | |
4472 | show_ip_ospf_instance_neighbor_int_cmd, | |
6147e2c6 | 4473 | "show ip ospf (1-65535) neighbor IFNAME [json]", |
7c8ff89e DS |
4474 | SHOW_STR |
4475 | IP_STR | |
4476 | "OSPF information\n" | |
4477 | "Instance ID\n" | |
4478 | "Neighbor list\n" | |
91756b38 | 4479 | "Interface name\n" |
9973d184 | 4480 | JSON_STR) |
7c8ff89e | 4481 | { |
d62a17ae | 4482 | int idx_number = 3; |
b4e84315 | 4483 | int idx_ifname = 5; |
d62a17ae | 4484 | struct ospf *ospf; |
4485 | u_short instance = 0; | |
4486 | u_char uj = use_json(argc, argv); | |
7c8ff89e | 4487 | |
b5a8894d CS |
4488 | if (!uj) |
4489 | show_ip_ospf_neighbour_header(vty); | |
4490 | ||
d62a17ae | 4491 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
ac28e4ec CS |
4492 | ospf = ospf_lookup_instance(instance); |
4493 | if (ospf == NULL) | |
4494 | return CMD_NOT_MY_INSTANCE; | |
4495 | ||
4496 | if (!ospf->oi_running) | |
d62a17ae | 4497 | return CMD_SUCCESS; |
7c8ff89e | 4498 | |
b5a8894d CS |
4499 | if (!uj) |
4500 | show_ip_ospf_neighbour_header(vty); | |
4501 | ||
b4e84315 | 4502 | return show_ip_ospf_neighbor_int_common(vty, ospf, idx_ifname, argv, uj); |
718e3744 | 4503 | } |
4504 | ||
d62a17ae | 4505 | static void show_ip_ospf_nbr_nbma_detail_sub(struct vty *vty, |
4506 | struct ospf_interface *oi, | |
4507 | struct ospf_nbr_nbma *nbr_nbma, | |
4508 | u_char use_json, json_object *json) | |
4509 | { | |
4510 | char timebuf[OSPF_TIME_DUMP_SIZE]; | |
4511 | json_object *json_sub = NULL; | |
718e3744 | 4512 | |
d62a17ae | 4513 | if (use_json) |
4514 | json_sub = json_object_new_object(); | |
4515 | else /* Show neighbor ID. */ | |
4516 | vty_out(vty, " Neighbor %s,", "-"); | |
4517 | ||
4518 | /* Show interface address. */ | |
4519 | if (use_json) | |
4520 | json_object_string_add(json_sub, "ifaceAddress", | |
4521 | inet_ntoa(nbr_nbma->addr)); | |
4522 | else | |
4523 | vty_out(vty, " interface address %s\n", | |
4524 | inet_ntoa(nbr_nbma->addr)); | |
4525 | ||
4526 | /* Show Area ID. */ | |
4527 | if (use_json) { | |
4528 | json_object_string_add(json_sub, "areaId", | |
4529 | ospf_area_desc_string(oi->area)); | |
4530 | json_object_string_add(json_sub, "iface", IF_NAME(oi)); | |
4531 | } else | |
4532 | vty_out(vty, " In the area %s via interface %s\n", | |
4533 | ospf_area_desc_string(oi->area), IF_NAME(oi)); | |
4534 | ||
4535 | /* Show neighbor priority and state. */ | |
4536 | if (use_json) { | |
4537 | json_object_int_add(json_sub, "nbrPriority", | |
4538 | nbr_nbma->priority); | |
4539 | json_object_string_add(json_sub, "nbrState", "down"); | |
4540 | } else | |
4541 | vty_out(vty, " Neighbor priority is %d, State is %s,", | |
4542 | nbr_nbma->priority, "Down"); | |
4543 | ||
4544 | /* Show state changes. */ | |
4545 | if (use_json) | |
4546 | json_object_int_add(json_sub, "stateChangeCounter", | |
4547 | nbr_nbma->state_change); | |
4548 | else | |
4549 | vty_out(vty, " %d state changes\n", nbr_nbma->state_change); | |
4550 | ||
4551 | /* Show PollInterval */ | |
4552 | if (use_json) | |
4553 | json_object_int_add(json_sub, "pollInterval", nbr_nbma->v_poll); | |
4554 | else | |
4555 | vty_out(vty, " Poll interval %d\n", nbr_nbma->v_poll); | |
4556 | ||
4557 | /* Show poll-interval timer. */ | |
4558 | if (use_json) { | |
4559 | long time_store; | |
4560 | time_store = monotime_until(&nbr_nbma->t_poll->u.sands, NULL) | |
4561 | / 1000LL; | |
4562 | json_object_int_add(json_sub, "pollIntervalTimerDueMsec", | |
4563 | time_store); | |
4564 | } else | |
4565 | vty_out(vty, " Poll timer due in %s\n", | |
4566 | ospf_timer_dump(nbr_nbma->t_poll, timebuf, | |
4567 | sizeof(timebuf))); | |
4568 | ||
4569 | /* Show poll-interval timer thread. */ | |
4570 | if (use_json) { | |
4571 | if (nbr_nbma->t_poll != NULL) | |
4572 | json_object_string_add(json_sub, | |
4573 | "pollIntervalTimerThread", "on"); | |
4574 | } else | |
4575 | vty_out(vty, " Thread Poll Timer %s\n", | |
4576 | nbr_nbma->t_poll != NULL ? "on" : "off"); | |
4577 | ||
4578 | if (use_json) | |
4579 | json_object_object_add(json, "noNbrId", json_sub); | |
4580 | } | |
4581 | ||
4582 | static void show_ip_ospf_neighbor_detail_sub(struct vty *vty, | |
4583 | struct ospf_interface *oi, | |
4584 | struct ospf_neighbor *nbr, | |
4585 | u_char use_json, json_object *json) | |
4586 | { | |
4587 | char timebuf[OSPF_TIME_DUMP_SIZE]; | |
4588 | json_object *json_sub = NULL; | |
4589 | ||
4590 | if (use_json) | |
4591 | json_sub = json_object_new_object(); | |
4592 | else { | |
4593 | /* Show neighbor ID. */ | |
4594 | if (nbr->state == NSM_Attempt && nbr->router_id.s_addr == 0) | |
4595 | vty_out(vty, " Neighbor %s,", "-"); | |
4596 | else | |
4597 | vty_out(vty, " Neighbor %s,", | |
4598 | inet_ntoa(nbr->router_id)); | |
4599 | } | |
4600 | ||
4601 | /* Show interface address. */ | |
4602 | if (use_json) | |
4603 | json_object_string_add(json_sub, "ifaceAddress", | |
4604 | inet_ntoa(nbr->address.u.prefix4)); | |
4605 | else | |
4606 | vty_out(vty, " interface address %s\n", | |
4607 | inet_ntoa(nbr->address.u.prefix4)); | |
4608 | ||
4609 | /* Show Area ID. */ | |
4610 | if (use_json) { | |
4611 | json_object_string_add(json_sub, "areaId", | |
4612 | ospf_area_desc_string(oi->area)); | |
4613 | json_object_string_add(json_sub, "ifaceName", oi->ifp->name); | |
4614 | } else | |
4615 | vty_out(vty, " In the area %s via interface %s\n", | |
4616 | ospf_area_desc_string(oi->area), oi->ifp->name); | |
4617 | ||
4618 | /* Show neighbor priority and state. */ | |
4619 | if (use_json) { | |
4620 | json_object_int_add(json_sub, "nbrPriority", nbr->priority); | |
4621 | json_object_string_add( | |
4622 | json_sub, "nbrState", | |
4623 | lookup_msg(ospf_nsm_state_msg, nbr->state, NULL)); | |
4624 | } else | |
4625 | vty_out(vty, " Neighbor priority is %d, State is %s,", | |
4626 | nbr->priority, | |
4627 | lookup_msg(ospf_nsm_state_msg, nbr->state, NULL)); | |
4628 | ||
4629 | /* Show state changes. */ | |
4630 | if (use_json) | |
4631 | json_object_int_add(json_sub, "stateChangeCounter", | |
4632 | nbr->state_change); | |
4633 | else | |
4634 | vty_out(vty, " %d state changes\n", nbr->state_change); | |
4635 | ||
4636 | if (nbr->ts_last_progress.tv_sec || nbr->ts_last_progress.tv_usec) { | |
4637 | struct timeval res; | |
4638 | long time_store; | |
4639 | ||
4640 | time_store = | |
4641 | monotime_since(&nbr->ts_last_progress, &res) / 1000LL; | |
4642 | if (use_json) { | |
4643 | json_object_int_add(json_sub, "lastPrgrsvChangeMsec", | |
4644 | time_store); | |
4645 | } else { | |
4646 | vty_out(vty, | |
4647 | " Most recent state change statistics:\n"); | |
4648 | vty_out(vty, " Progressive change %s ago\n", | |
4649 | ospf_timeval_dump(&res, timebuf, | |
4650 | sizeof(timebuf))); | |
4651 | } | |
4652 | } | |
4653 | ||
4654 | if (nbr->ts_last_regress.tv_sec || nbr->ts_last_regress.tv_usec) { | |
4655 | struct timeval res; | |
4656 | long time_store; | |
4657 | ||
4658 | time_store = | |
4659 | monotime_since(&nbr->ts_last_regress, &res) / 1000LL; | |
4660 | if (use_json) { | |
4661 | json_object_int_add(json_sub, | |
4662 | "lastRegressiveChangeMsec", | |
4663 | time_store); | |
4664 | if (nbr->last_regress_str) | |
4665 | json_object_string_add( | |
4666 | json_sub, "lastRegressiveChangeReason", | |
4667 | nbr->last_regress_str); | |
4668 | } else { | |
4669 | vty_out(vty, | |
4670 | " Regressive change %s ago, due to %s\n", | |
4671 | ospf_timeval_dump(&res, timebuf, | |
4672 | sizeof(timebuf)), | |
4673 | (nbr->last_regress_str ? nbr->last_regress_str | |
4674 | : "??")); | |
4675 | } | |
4676 | } | |
4677 | ||
4678 | /* Show Designated Rotuer ID. */ | |
4679 | if (use_json) | |
4680 | json_object_string_add(json_sub, "routerDesignatedId", | |
4681 | inet_ntoa(nbr->d_router)); | |
4682 | else | |
4683 | vty_out(vty, " DR is %s,", inet_ntoa(nbr->d_router)); | |
4684 | ||
4685 | /* Show Backup Designated Rotuer ID. */ | |
4686 | if (use_json) | |
4687 | json_object_string_add(json_sub, "routerDesignatedBackupId", | |
4688 | inet_ntoa(nbr->bd_router)); | |
4689 | else | |
4690 | vty_out(vty, " BDR is %s\n", inet_ntoa(nbr->bd_router)); | |
4691 | ||
4692 | /* Show options. */ | |
4693 | if (use_json) { | |
4694 | json_object_int_add(json_sub, "optionsCounter", nbr->options); | |
4695 | json_object_string_add(json_sub, "optionsList", | |
4696 | ospf_options_dump(nbr->options)); | |
4697 | } else | |
4698 | vty_out(vty, " Options %d %s\n", nbr->options, | |
4699 | ospf_options_dump(nbr->options)); | |
4700 | ||
4701 | /* Show Router Dead interval timer. */ | |
4702 | if (use_json) { | |
4703 | if (nbr->t_inactivity) { | |
4704 | long time_store; | |
4705 | time_store = monotime_until(&nbr->t_inactivity->u.sands, | |
4706 | NULL) | |
4707 | / 1000LL; | |
4708 | json_object_int_add(json_sub, | |
4709 | "routerDeadIntervalTimerDueMsec", | |
4710 | time_store); | |
4711 | } else | |
4712 | json_object_int_add( | |
4713 | json_sub, "routerDeadIntervalTimerDueMsec", -1); | |
4714 | } else | |
4715 | vty_out(vty, " Dead timer due in %s\n", | |
4716 | ospf_timer_dump(nbr->t_inactivity, timebuf, | |
4717 | sizeof(timebuf))); | |
4718 | ||
4719 | /* Show Database Summary list. */ | |
4720 | if (use_json) | |
4721 | json_object_int_add(json_sub, "databaseSummaryListCounter", | |
4722 | ospf_db_summary_count(nbr)); | |
4723 | else | |
4724 | vty_out(vty, " Database Summary List %d\n", | |
4725 | ospf_db_summary_count(nbr)); | |
4726 | ||
4727 | /* Show Link State Request list. */ | |
4728 | if (use_json) | |
4729 | json_object_int_add(json_sub, "linkStateRequestListCounter", | |
4730 | ospf_ls_request_count(nbr)); | |
4731 | else | |
4732 | vty_out(vty, " Link State Request List %ld\n", | |
4733 | ospf_ls_request_count(nbr)); | |
4734 | ||
4735 | /* Show Link State Retransmission list. */ | |
4736 | if (use_json) | |
4737 | json_object_int_add(json_sub, | |
4738 | "linkStateRetransmissionListCounter", | |
4739 | ospf_ls_retransmit_count(nbr)); | |
4740 | else | |
4741 | vty_out(vty, " Link State Retransmission List %ld\n", | |
4742 | ospf_ls_retransmit_count(nbr)); | |
4743 | ||
4744 | /* Show inactivity timer thread. */ | |
4745 | if (use_json) { | |
4746 | if (nbr->t_inactivity != NULL) | |
4747 | json_object_string_add(json_sub, | |
4748 | "threadInactivityTimer", "on"); | |
4749 | } else | |
4750 | vty_out(vty, " Thread Inactivity Timer %s\n", | |
4751 | nbr->t_inactivity != NULL ? "on" : "off"); | |
4752 | ||
4753 | /* Show Database Description retransmission thread. */ | |
4754 | if (use_json) { | |
4755 | if (nbr->t_db_desc != NULL) | |
4756 | json_object_string_add( | |
4757 | json_sub, | |
4758 | "threadDatabaseDescriptionRetransmission", | |
4759 | "on"); | |
4760 | } else | |
4761 | vty_out(vty, | |
4762 | " Thread Database Description Retransmision %s\n", | |
4763 | nbr->t_db_desc != NULL ? "on" : "off"); | |
4764 | ||
4765 | /* Show Link State Request Retransmission thread. */ | |
4766 | if (use_json) { | |
4767 | if (nbr->t_ls_req != NULL) | |
4768 | json_object_string_add( | |
4769 | json_sub, | |
4770 | "threadLinkStateRequestRetransmission", "on"); | |
4771 | } else | |
4772 | vty_out(vty, | |
4773 | " Thread Link State Request Retransmission %s\n", | |
4774 | nbr->t_ls_req != NULL ? "on" : "off"); | |
4775 | ||
4776 | /* Show Link State Update Retransmission thread. */ | |
4777 | if (use_json) { | |
4778 | if (nbr->t_ls_upd != NULL) | |
4779 | json_object_string_add( | |
4780 | json_sub, "threadLinkStateUpdateRetransmission", | |
4781 | "on"); | |
4782 | } else | |
4783 | vty_out(vty, | |
4784 | " Thread Link State Update Retransmission %s\n\n", | |
4785 | nbr->t_ls_upd != NULL ? "on" : "off"); | |
4786 | ||
4787 | if (use_json) { | |
4788 | if (nbr->state == NSM_Attempt && nbr->router_id.s_addr == 0) | |
4789 | json_object_object_add(json, "noNbrId", json_sub); | |
4790 | else | |
4791 | json_object_object_add(json, inet_ntoa(nbr->router_id), | |
4792 | json_sub); | |
4793 | } | |
4794 | ||
4795 | ospf_bfd_show_info(vty, nbr->bfd_info, json, use_json, 0); | |
4796 | } | |
4797 | ||
4798 | static int show_ip_ospf_neighbor_id_common(struct vty *vty, struct ospf *ospf, | |
4799 | int arg_base, | |
4800 | struct cmd_token **argv, | |
4801 | u_char use_json) | |
4802 | { | |
4803 | struct listnode *node; | |
4804 | struct ospf_neighbor *nbr; | |
4805 | struct ospf_interface *oi; | |
4806 | struct in_addr router_id; | |
4807 | int ret; | |
4808 | json_object *json = NULL; | |
4809 | ||
4810 | if (use_json) | |
4811 | json = json_object_new_object(); | |
4812 | ||
4813 | if (ospf->instance) { | |
4814 | if (use_json) | |
4815 | json_object_int_add(json, "ospfInstance", | |
4816 | ospf->instance); | |
4817 | else | |
4818 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
4819 | } | |
4820 | ||
52d0c099 | 4821 | ospf_show_vrf_name(ospf, vty, json); |
87bd50e8 | 4822 | |
d62a17ae | 4823 | ret = inet_aton(argv[arg_base]->arg, &router_id); |
4824 | if (!ret) { | |
4825 | if (!use_json) | |
4826 | vty_out(vty, "Please specify Neighbor ID by A.B.C.D\n"); | |
16307668 RW |
4827 | else { |
4828 | vty_out(vty, "{}\n"); | |
4829 | json_object_free(json); | |
4830 | } | |
d62a17ae | 4831 | return CMD_WARNING; |
4832 | } | |
4833 | ||
4834 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) { | |
4835 | if ((nbr = ospf_nbr_lookup_by_routerid(oi->nbrs, &router_id))) { | |
4836 | show_ip_ospf_neighbor_detail_sub(vty, oi, nbr, use_json, | |
4837 | json); | |
4838 | } | |
4839 | } | |
4840 | ||
4841 | if (use_json) { | |
9d303b37 DL |
4842 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
4843 | json, JSON_C_TO_STRING_PRETTY)); | |
d62a17ae | 4844 | json_object_free(json); |
4845 | } else | |
4846 | vty_out(vty, "\n"); | |
4847 | ||
4848 | return CMD_SUCCESS; | |
718e3744 | 4849 | } |
4850 | ||
7c8ff89e DS |
4851 | DEFUN (show_ip_ospf_neighbor_id, |
4852 | show_ip_ospf_neighbor_id_cmd, | |
b162fa78 | 4853 | "show ip ospf neighbor A.B.C.D [json]", |
718e3744 | 4854 | SHOW_STR |
4855 | IP_STR | |
4856 | "OSPF information\n" | |
4857 | "Neighbor list\n" | |
3ac237f8 | 4858 | "Neighbor ID\n" |
9973d184 | 4859 | JSON_STR) |
718e3744 | 4860 | { |
d62a17ae | 4861 | struct ospf *ospf; |
4862 | u_char uj = use_json(argc, argv); | |
b5a8894d CS |
4863 | struct listnode *node = NULL; |
4864 | int ret = CMD_SUCCESS; | |
7c8ff89e | 4865 | |
b5a8894d CS |
4866 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { |
4867 | if (!ospf->oi_running) | |
4868 | continue; | |
4869 | ret = show_ip_ospf_neighbor_id_common(vty, ospf, 0, argv, uj); | |
4870 | } | |
7c8ff89e | 4871 | |
b5a8894d | 4872 | return ret; |
7c8ff89e DS |
4873 | } |
4874 | ||
4875 | DEFUN (show_ip_ospf_instance_neighbor_id, | |
4876 | show_ip_ospf_instance_neighbor_id_cmd, | |
6147e2c6 | 4877 | "show ip ospf (1-65535) neighbor A.B.C.D [json]", |
7c8ff89e DS |
4878 | SHOW_STR |
4879 | IP_STR | |
4880 | "OSPF information\n" | |
4881 | "Instance ID\n" | |
4882 | "Neighbor list\n" | |
3ac237f8 | 4883 | "Neighbor ID\n" |
9973d184 | 4884 | JSON_STR) |
7c8ff89e | 4885 | { |
d62a17ae | 4886 | int idx_number = 3; |
b4e84315 | 4887 | int idx_router_id = 5; |
d62a17ae | 4888 | struct ospf *ospf; |
4889 | u_short instance = 0; | |
4890 | u_char uj = use_json(argc, argv); | |
7c8ff89e | 4891 | |
d62a17ae | 4892 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
ac28e4ec CS |
4893 | ospf = ospf_lookup_instance(instance); |
4894 | if (ospf == NULL) | |
4895 | return CMD_NOT_MY_INSTANCE; | |
4896 | ||
4897 | if (!ospf->oi_running) | |
d62a17ae | 4898 | return CMD_SUCCESS; |
7c8ff89e | 4899 | |
b4e84315 | 4900 | return show_ip_ospf_neighbor_id_common(vty, ospf, idx_router_id, argv, uj); |
7c8ff89e DS |
4901 | } |
4902 | ||
d62a17ae | 4903 | static int show_ip_ospf_neighbor_detail_common(struct vty *vty, |
4904 | struct ospf *ospf, | |
4905 | u_char use_json) | |
4906 | { | |
4907 | struct ospf_interface *oi; | |
4908 | struct listnode *node; | |
4909 | json_object *json = NULL; | |
3ac237f8 | 4910 | |
d62a17ae | 4911 | if (use_json) |
4912 | json = json_object_new_object(); | |
4913 | ||
4914 | if (ospf->instance) { | |
4915 | if (use_json) | |
4916 | json_object_int_add(json, "ospfInstance", | |
4917 | ospf->instance); | |
4918 | else | |
4919 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
4920 | } | |
4921 | ||
52d0c099 | 4922 | ospf_show_vrf_name(ospf, vty, json); |
87bd50e8 | 4923 | |
d62a17ae | 4924 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) { |
4925 | struct route_node *rn; | |
4926 | struct ospf_neighbor *nbr; | |
4927 | ||
4928 | for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) { | |
4929 | if ((nbr = rn->info)) { | |
4930 | if (nbr != oi->nbr_self) { | |
4931 | if (nbr->state != NSM_Down) { | |
4932 | show_ip_ospf_neighbor_detail_sub( | |
4933 | vty, oi, nbr, use_json, | |
4934 | json); | |
4935 | } | |
4936 | } | |
4937 | } | |
4938 | } | |
4939 | } | |
4940 | ||
4941 | if (use_json) { | |
9d303b37 DL |
4942 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
4943 | json, JSON_C_TO_STRING_PRETTY)); | |
d62a17ae | 4944 | json_object_free(json); |
4945 | } else | |
4946 | vty_out(vty, "\n"); | |
4947 | ||
4948 | return CMD_SUCCESS; | |
718e3744 | 4949 | } |
4950 | ||
7c8ff89e DS |
4951 | DEFUN (show_ip_ospf_neighbor_detail, |
4952 | show_ip_ospf_neighbor_detail_cmd, | |
b5a8894d | 4953 | "show ip ospf [vrf <NAME|all>] neighbor detail [json]", |
718e3744 | 4954 | SHOW_STR |
4955 | IP_STR | |
4956 | "OSPF information\n" | |
b5a8894d CS |
4957 | VRF_CMD_HELP_STR |
4958 | "All VRFs\n" | |
718e3744 | 4959 | "Neighbor list\n" |
3ac237f8 | 4960 | "detail of all neighbors\n" |
9973d184 | 4961 | JSON_STR) |
718e3744 | 4962 | { |
d62a17ae | 4963 | struct ospf *ospf; |
4964 | u_char uj = use_json(argc, argv); | |
b5a8894d CS |
4965 | struct listnode *node = NULL; |
4966 | char *vrf_name = NULL; | |
4967 | bool all_vrf = FALSE; | |
4968 | int ret = CMD_SUCCESS; | |
4969 | int inst = 0; | |
4970 | int idx_vrf = 0; | |
7c8ff89e | 4971 | |
43b8d1d8 | 4972 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
7c8ff89e | 4973 | |
b5a8894d CS |
4974 | /* vrf input is provided could be all or specific vrf*/ |
4975 | if (vrf_name) { | |
4976 | if (all_vrf) { | |
4977 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
4978 | if (!ospf->oi_running) | |
4979 | continue; | |
4980 | ret = show_ip_ospf_neighbor_detail_common(vty, | |
4981 | ospf, | |
4982 | uj); | |
4983 | } | |
4984 | return ret; | |
4985 | } | |
4986 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
4987 | if (ospf == NULL || !ospf->oi_running) | |
4988 | return CMD_SUCCESS; | |
4989 | } else { | |
4990 | /* Display default ospf (instance 0) info */ | |
4991 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
4992 | if (ospf == NULL || !ospf->oi_running) | |
4993 | return CMD_SUCCESS; | |
4994 | } | |
4995 | ||
4996 | if (ospf) | |
4997 | ret = show_ip_ospf_neighbor_detail_common(vty, ospf, uj); | |
4998 | ||
4999 | return ret; | |
7c8ff89e DS |
5000 | } |
5001 | ||
5002 | DEFUN (show_ip_ospf_instance_neighbor_detail, | |
5003 | show_ip_ospf_instance_neighbor_detail_cmd, | |
6147e2c6 | 5004 | "show ip ospf (1-65535) neighbor detail [json]", |
7c8ff89e DS |
5005 | SHOW_STR |
5006 | IP_STR | |
5007 | "OSPF information\n" | |
5008 | "Instance ID\n" | |
5009 | "Neighbor list\n" | |
3ac237f8 | 5010 | "detail of all neighbors\n" |
9973d184 | 5011 | JSON_STR) |
7c8ff89e | 5012 | { |
d62a17ae | 5013 | int idx_number = 3; |
5014 | struct ospf *ospf; | |
5015 | u_short instance = 0; | |
5016 | u_char uj = use_json(argc, argv); | |
7c8ff89e | 5017 | |
d62a17ae | 5018 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
ac28e4ec CS |
5019 | ospf = ospf_lookup_instance(instance); |
5020 | if (ospf == NULL) | |
5021 | return CMD_NOT_MY_INSTANCE; | |
5022 | ||
5023 | if (!ospf->oi_running) | |
d62a17ae | 5024 | return CMD_SUCCESS; |
7c8ff89e | 5025 | |
d62a17ae | 5026 | return show_ip_ospf_neighbor_detail_common(vty, ospf, uj); |
7c8ff89e DS |
5027 | } |
5028 | ||
d62a17ae | 5029 | static int show_ip_ospf_neighbor_detail_all_common(struct vty *vty, |
5030 | struct ospf *ospf, | |
5031 | u_char use_json) | |
5032 | { | |
5033 | struct listnode *node; | |
5034 | struct ospf_interface *oi; | |
5035 | json_object *json = NULL; | |
718e3744 | 5036 | |
d62a17ae | 5037 | if (use_json) |
5038 | json = json_object_new_object(); | |
5039 | ||
5040 | if (ospf->instance) { | |
5041 | if (use_json) | |
5042 | json_object_int_add(json, "ospfInstance", | |
5043 | ospf->instance); | |
5044 | else | |
5045 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
5046 | } | |
5047 | ||
52d0c099 | 5048 | ospf_show_vrf_name(ospf, vty, json); |
87bd50e8 | 5049 | |
d62a17ae | 5050 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) { |
5051 | struct route_node *rn; | |
5052 | struct ospf_neighbor *nbr; | |
5053 | struct ospf_nbr_nbma *nbr_nbma; | |
5054 | ||
5055 | for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) | |
5056 | if ((nbr = rn->info)) | |
5057 | if (nbr != oi->nbr_self) | |
5058 | if (nbr->state != NSM_Down) | |
5059 | show_ip_ospf_neighbor_detail_sub( | |
5060 | vty, oi, rn->info, | |
5061 | use_json, json); | |
5062 | ||
5063 | if (oi->type == OSPF_IFTYPE_NBMA) { | |
5064 | struct listnode *nd; | |
5065 | ||
5066 | for (ALL_LIST_ELEMENTS_RO(oi->nbr_nbma, nd, nbr_nbma)) { | |
5067 | if (nbr_nbma->nbr == NULL | |
5068 | || nbr_nbma->nbr->state == NSM_Down) | |
5069 | show_ip_ospf_nbr_nbma_detail_sub( | |
5070 | vty, oi, nbr_nbma, use_json, | |
5071 | json); | |
5072 | } | |
5073 | } | |
5074 | } | |
5075 | ||
5076 | if (use_json) { | |
9d303b37 DL |
5077 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
5078 | json, JSON_C_TO_STRING_PRETTY)); | |
d62a17ae | 5079 | json_object_free(json); |
5080 | } else { | |
5081 | vty_out(vty, "\n"); | |
5082 | } | |
5083 | ||
5084 | return CMD_SUCCESS; | |
718e3744 | 5085 | } |
5086 | ||
7c8ff89e DS |
5087 | DEFUN (show_ip_ospf_neighbor_detail_all, |
5088 | show_ip_ospf_neighbor_detail_all_cmd, | |
b5a8894d | 5089 | "show ip ospf [vrf <NAME|all>] neighbor detail all [json]", |
718e3744 | 5090 | SHOW_STR |
5091 | IP_STR | |
5092 | "OSPF information\n" | |
b5a8894d CS |
5093 | VRF_CMD_HELP_STR |
5094 | "All VRFs\n" | |
718e3744 | 5095 | "Neighbor list\n" |
7c8ff89e | 5096 | "detail of all neighbors\n" |
3ac237f8 | 5097 | "include down status neighbor\n" |
9973d184 | 5098 | JSON_STR) |
718e3744 | 5099 | { |
d62a17ae | 5100 | struct ospf *ospf; |
5101 | u_char uj = use_json(argc, argv); | |
b5a8894d CS |
5102 | struct listnode *node = NULL; |
5103 | char *vrf_name = NULL; | |
5104 | bool all_vrf = FALSE; | |
5105 | int ret = CMD_SUCCESS; | |
5106 | int inst = 0; | |
5107 | int idx_vrf = 0; | |
7c8ff89e | 5108 | |
43b8d1d8 | 5109 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
7c8ff89e | 5110 | |
b5a8894d CS |
5111 | /* vrf input is provided could be all or specific vrf*/ |
5112 | if (vrf_name) { | |
5113 | if (all_vrf) { | |
5114 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
5115 | if (!ospf->oi_running) | |
5116 | continue; | |
5117 | ret = show_ip_ospf_neighbor_detail_all_common(vty, | |
5118 | ospf, | |
5119 | uj); | |
5120 | } | |
5121 | return ret; | |
5122 | } | |
5123 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
5124 | if (ospf == NULL || !ospf->oi_running) | |
5125 | return CMD_SUCCESS; | |
5126 | } else { | |
5127 | /* Display default ospf (instance 0) info */ | |
5128 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
5129 | if (ospf == NULL || !ospf->oi_running) | |
5130 | return CMD_SUCCESS; | |
5131 | } | |
5132 | ||
5133 | if (ospf) | |
5134 | ret = show_ip_ospf_neighbor_detail_all_common(vty, ospf, uj); | |
5135 | ||
5136 | return ret; | |
7c8ff89e DS |
5137 | } |
5138 | ||
5139 | DEFUN (show_ip_ospf_instance_neighbor_detail_all, | |
5140 | show_ip_ospf_instance_neighbor_detail_all_cmd, | |
6147e2c6 | 5141 | "show ip ospf (1-65535) neighbor detail all [json]", |
7c8ff89e DS |
5142 | SHOW_STR |
5143 | IP_STR | |
5144 | "OSPF information\n" | |
5145 | "Instance ID\n" | |
5146 | "Neighbor list\n" | |
5147 | "detail of all neighbors\n" | |
3ac237f8 | 5148 | "include down status neighbor\n" |
9973d184 | 5149 | JSON_STR) |
7c8ff89e | 5150 | { |
d62a17ae | 5151 | int idx_number = 3; |
5152 | struct ospf *ospf; | |
5153 | u_short instance = 0; | |
5154 | u_char uj = use_json(argc, argv); | |
7c8ff89e | 5155 | |
d62a17ae | 5156 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
ac28e4ec CS |
5157 | ospf = ospf_lookup_instance(instance); |
5158 | if (ospf == NULL) | |
5159 | return CMD_NOT_MY_INSTANCE; | |
5160 | ||
5161 | if (!ospf->oi_running) | |
d62a17ae | 5162 | return CMD_SUCCESS; |
7c8ff89e | 5163 | |
d62a17ae | 5164 | return show_ip_ospf_neighbor_detail_all_common(vty, ospf, uj); |
7c8ff89e DS |
5165 | } |
5166 | ||
d62a17ae | 5167 | static int show_ip_ospf_neighbor_int_detail_common(struct vty *vty, |
5168 | struct ospf *ospf, | |
5169 | int arg_base, | |
5170 | struct cmd_token **argv, | |
5171 | u_char use_json) | |
5172 | { | |
5173 | struct ospf_interface *oi; | |
5174 | struct interface *ifp; | |
5175 | struct route_node *rn, *nrn; | |
5176 | struct ospf_neighbor *nbr; | |
5177 | json_object *json = NULL; | |
718e3744 | 5178 | |
d62a17ae | 5179 | if (use_json) |
5180 | json = json_object_new_object(); | |
5181 | ||
5182 | if (ospf->instance) { | |
5183 | if (use_json) | |
5184 | json_object_int_add(json, "ospfInstance", | |
5185 | ospf->instance); | |
5186 | else | |
5187 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
5188 | } | |
5189 | ||
b5a8894d | 5190 | ifp = if_lookup_by_name_all_vrf(argv[arg_base]->arg); |
d62a17ae | 5191 | if (!ifp) { |
5192 | if (!use_json) | |
5193 | vty_out(vty, "No such interface.\n"); | |
16307668 RW |
5194 | else { |
5195 | vty_out(vty, "{}\n"); | |
5196 | json_object_free(json); | |
5197 | } | |
d62a17ae | 5198 | return CMD_WARNING; |
5199 | } | |
5200 | ||
5201 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { | |
5202 | if ((oi = rn->info)) { | |
5203 | for (nrn = route_top(oi->nbrs); nrn; | |
5204 | nrn = route_next(nrn)) { | |
5205 | if ((nbr = nrn->info)) { | |
5206 | if (nbr != oi->nbr_self) { | |
5207 | if (nbr->state != NSM_Down) | |
5208 | show_ip_ospf_neighbor_detail_sub( | |
5209 | vty, oi, nbr, | |
5210 | use_json, json); | |
5211 | } | |
5212 | } | |
5213 | } | |
5214 | } | |
5215 | } | |
5216 | ||
5217 | if (use_json) { | |
9d303b37 DL |
5218 | vty_out(vty, "%s\n", json_object_to_json_string_ext( |
5219 | json, JSON_C_TO_STRING_PRETTY)); | |
d62a17ae | 5220 | json_object_free(json); |
5221 | } else | |
5222 | vty_out(vty, "\n"); | |
5223 | ||
5224 | return CMD_SUCCESS; | |
718e3744 | 5225 | } |
5226 | ||
7c8ff89e DS |
5227 | DEFUN (show_ip_ospf_neighbor_int_detail, |
5228 | show_ip_ospf_neighbor_int_detail_cmd, | |
b162fa78 | 5229 | "show ip ospf neighbor IFNAME detail [json]", |
7c8ff89e DS |
5230 | SHOW_STR |
5231 | IP_STR | |
5232 | "OSPF information\n" | |
5233 | "Neighbor list\n" | |
5234 | "Interface name\n" | |
3ac237f8 | 5235 | "detail of all neighbors\n" |
9973d184 | 5236 | JSON_STR) |
7c8ff89e | 5237 | { |
d62a17ae | 5238 | struct ospf *ospf; |
5239 | u_char uj = use_json(argc, argv); | |
b5a8894d CS |
5240 | struct listnode *node = NULL; |
5241 | int ret = CMD_SUCCESS; | |
7c8ff89e | 5242 | |
b5a8894d CS |
5243 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { |
5244 | if (!ospf->oi_running) | |
5245 | continue; | |
5246 | ret = show_ip_ospf_neighbor_int_detail_common(vty, ospf, 0, | |
5247 | argv, uj); | |
5248 | } | |
7c8ff89e | 5249 | |
b5a8894d | 5250 | return ret; |
7c8ff89e DS |
5251 | } |
5252 | ||
5253 | DEFUN (show_ip_ospf_instance_neighbor_int_detail, | |
5254 | show_ip_ospf_instance_neighbor_int_detail_cmd, | |
6147e2c6 | 5255 | "show ip ospf (1-65535) neighbor IFNAME detail [json]", |
7c8ff89e DS |
5256 | SHOW_STR |
5257 | IP_STR | |
5258 | "OSPF information\n" | |
5259 | "Instance ID\n" | |
5260 | "Neighbor list\n" | |
5261 | "Interface name\n" | |
3ac237f8 | 5262 | "detail of all neighbors\n" |
9973d184 | 5263 | JSON_STR) |
7c8ff89e | 5264 | { |
d62a17ae | 5265 | int idx_number = 3; |
b4e84315 | 5266 | int idx_ifname = 5; |
d62a17ae | 5267 | struct ospf *ospf; |
5268 | u_short instance = 0; | |
5269 | u_char uj = use_json(argc, argv); | |
7c8ff89e | 5270 | |
d62a17ae | 5271 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
ac28e4ec CS |
5272 | ospf = ospf_lookup_instance(instance); |
5273 | if (ospf == NULL) | |
5274 | return CMD_NOT_MY_INSTANCE; | |
5275 | ||
5276 | if (!ospf->oi_running) | |
d62a17ae | 5277 | return CMD_SUCCESS; |
7c8ff89e | 5278 | |
b4e84315 | 5279 | return show_ip_ospf_neighbor_int_detail_common(vty, ospf, idx_ifname, argv, uj); |
7c8ff89e | 5280 | } |
6b0655a2 | 5281 | |
718e3744 | 5282 | /* Show functions */ |
d62a17ae | 5283 | static int show_lsa_summary(struct vty *vty, struct ospf_lsa *lsa, int self) |
5284 | { | |
5285 | struct router_lsa *rl; | |
5286 | struct summary_lsa *sl; | |
5287 | struct as_external_lsa *asel; | |
5288 | struct prefix_ipv4 p; | |
5289 | ||
5290 | if (lsa != NULL) | |
5291 | /* If self option is set, check LSA self flag. */ | |
5292 | if (self == 0 || IS_LSA_SELF(lsa)) { | |
5293 | /* LSA common part show. */ | |
5294 | vty_out(vty, "%-15s ", inet_ntoa(lsa->data->id)); | |
5295 | vty_out(vty, "%-15s %4d 0x%08lx 0x%04x", | |
5296 | inet_ntoa(lsa->data->adv_router), LS_AGE(lsa), | |
5297 | (u_long)ntohl(lsa->data->ls_seqnum), | |
5298 | ntohs(lsa->data->checksum)); | |
5299 | /* LSA specific part show. */ | |
5300 | switch (lsa->data->type) { | |
5301 | case OSPF_ROUTER_LSA: | |
5302 | rl = (struct router_lsa *)lsa->data; | |
5303 | vty_out(vty, " %-d", ntohs(rl->links)); | |
5304 | break; | |
5305 | case OSPF_SUMMARY_LSA: | |
5306 | sl = (struct summary_lsa *)lsa->data; | |
5307 | ||
5308 | p.family = AF_INET; | |
5309 | p.prefix = sl->header.id; | |
5310 | p.prefixlen = ip_masklen(sl->mask); | |
5311 | apply_mask_ipv4(&p); | |
5312 | ||
5313 | vty_out(vty, " %s/%d", inet_ntoa(p.prefix), | |
5314 | p.prefixlen); | |
5315 | break; | |
5316 | case OSPF_AS_EXTERNAL_LSA: | |
5317 | case OSPF_AS_NSSA_LSA: | |
5318 | asel = (struct as_external_lsa *)lsa->data; | |
5319 | ||
5320 | p.family = AF_INET; | |
5321 | p.prefix = asel->header.id; | |
5322 | p.prefixlen = ip_masklen(asel->mask); | |
5323 | apply_mask_ipv4(&p); | |
5324 | ||
5325 | vty_out(vty, " %s %s/%d [0x%lx]", | |
5326 | IS_EXTERNAL_METRIC(asel->e[0].tos) | |
5327 | ? "E2" | |
5328 | : "E1", | |
5329 | inet_ntoa(p.prefix), p.prefixlen, | |
5330 | (u_long)ntohl(asel->e[0].route_tag)); | |
5331 | break; | |
5332 | case OSPF_NETWORK_LSA: | |
5333 | case OSPF_ASBR_SUMMARY_LSA: | |
5334 | case OSPF_OPAQUE_LINK_LSA: | |
5335 | case OSPF_OPAQUE_AREA_LSA: | |
5336 | case OSPF_OPAQUE_AS_LSA: | |
5337 | default: | |
5338 | break; | |
5339 | } | |
5340 | vty_out(vty, "\n"); | |
5341 | } | |
718e3744 | 5342 | |
d62a17ae | 5343 | return 0; |
5344 | } | |
5345 | ||
5346 | static const char *show_database_desc[] = { | |
5347 | "unknown", | |
5348 | "Router Link States", | |
5349 | "Net Link States", | |
5350 | "Summary Link States", | |
5351 | "ASBR-Summary Link States", | |
5352 | "AS External Link States", | |
5353 | "Group Membership LSA", | |
5354 | "NSSA-external Link States", | |
5355 | "Type-8 LSA", | |
5356 | "Link-Local Opaque-LSA", | |
5357 | "Area-Local Opaque-LSA", | |
5358 | "AS-external Opaque-LSA", | |
718e3744 | 5359 | }; |
5360 | ||
d62a17ae | 5361 | static const char *show_database_header[] = { |
5362 | "", | |
5363 | "Link ID ADV Router Age Seq# CkSum Link count", | |
5364 | "Link ID ADV Router Age Seq# CkSum", | |
5365 | "Link ID ADV Router Age Seq# CkSum Route", | |
5366 | "Link ID ADV Router Age Seq# CkSum", | |
5367 | "Link ID ADV Router Age Seq# CkSum Route", | |
5368 | " --- header for Group Member ----", | |
5369 | "Link ID ADV Router Age Seq# CkSum Route", | |
5370 | " --- type-8 ---", | |
5371 | "Opaque-Type/Id ADV Router Age Seq# CkSum", | |
5372 | "Opaque-Type/Id ADV Router Age Seq# CkSum", | |
5373 | "Opaque-Type/Id ADV Router Age Seq# CkSum", | |
718e3744 | 5374 | }; |
5375 | ||
d62a17ae | 5376 | static void show_ip_ospf_database_header(struct vty *vty, struct ospf_lsa *lsa) |
5377 | { | |
5378 | struct router_lsa *rlsa = (struct router_lsa *)lsa->data; | |
5379 | ||
5380 | vty_out(vty, " LS age: %d\n", LS_AGE(lsa)); | |
5381 | vty_out(vty, " Options: 0x%-2x : %s\n", lsa->data->options, | |
5382 | ospf_options_dump(lsa->data->options)); | |
5383 | vty_out(vty, " LS Flags: 0x%-2x %s\n", lsa->flags, | |
5384 | ((lsa->flags & OSPF_LSA_LOCAL_XLT) ? "(Translated from Type-7)" | |
5385 | : "")); | |
5386 | ||
5387 | if (lsa->data->type == OSPF_ROUTER_LSA) { | |
5388 | vty_out(vty, " Flags: 0x%x", rlsa->flags); | |
5389 | ||
5390 | if (rlsa->flags) | |
5391 | vty_out(vty, " :%s%s%s%s", | |
5392 | IS_ROUTER_LSA_BORDER(rlsa) ? " ABR" : "", | |
5393 | IS_ROUTER_LSA_EXTERNAL(rlsa) ? " ASBR" : "", | |
5394 | IS_ROUTER_LSA_VIRTUAL(rlsa) ? " VL-endpoint" | |
5395 | : "", | |
5396 | IS_ROUTER_LSA_SHORTCUT(rlsa) ? " Shortcut" | |
5397 | : ""); | |
5398 | ||
5399 | vty_out(vty, "\n"); | |
5400 | } | |
5401 | vty_out(vty, " LS Type: %s\n", | |
5402 | lookup_msg(ospf_lsa_type_msg, lsa->data->type, NULL)); | |
5403 | vty_out(vty, " Link State ID: %s %s\n", inet_ntoa(lsa->data->id), | |
5404 | lookup_msg(ospf_link_state_id_type_msg, lsa->data->type, NULL)); | |
5405 | vty_out(vty, " Advertising Router: %s\n", | |
5406 | inet_ntoa(lsa->data->adv_router)); | |
5407 | vty_out(vty, " LS Seq Number: %08lx\n", | |
5408 | (u_long)ntohl(lsa->data->ls_seqnum)); | |
5409 | vty_out(vty, " Checksum: 0x%04x\n", ntohs(lsa->data->checksum)); | |
5410 | vty_out(vty, " Length: %d\n\n", ntohs(lsa->data->length)); | |
5411 | } | |
5412 | ||
5413 | const char *link_type_desc[] = { | |
5414 | "(null)", | |
5415 | "another Router (point-to-point)", | |
5416 | "a Transit Network", | |
5417 | "Stub Network", | |
5418 | "a Virtual Link", | |
718e3744 | 5419 | }; |
5420 | ||
d62a17ae | 5421 | const char *link_id_desc[] = { |
5422 | "(null)", "Neighboring Router ID", "Designated Router address", | |
5423 | "Net", "Neighboring Router ID", | |
718e3744 | 5424 | }; |
5425 | ||
d62a17ae | 5426 | const char *link_data_desc[] = { |
5427 | "(null)", "Router Interface address", "Router Interface address", | |
5428 | "Network Mask", "Router Interface address", | |
718e3744 | 5429 | }; |
5430 | ||
5431 | /* Show router-LSA each Link information. */ | |
d62a17ae | 5432 | static void show_ip_ospf_database_router_links(struct vty *vty, |
5433 | struct router_lsa *rl) | |
5434 | { | |
5435 | int len, type; | |
5436 | unsigned int i; | |
5437 | ||
5438 | len = ntohs(rl->header.length) - 4; | |
5439 | for (i = 0; i < ntohs(rl->links) && len > 0; len -= 12, i++) { | |
5440 | type = rl->link[i].type; | |
5441 | ||
5442 | vty_out(vty, " Link connected to: %s\n", | |
5443 | link_type_desc[type]); | |
5444 | vty_out(vty, " (Link ID) %s: %s\n", link_id_desc[type], | |
5445 | inet_ntoa(rl->link[i].link_id)); | |
5446 | vty_out(vty, " (Link Data) %s: %s\n", link_data_desc[type], | |
5447 | inet_ntoa(rl->link[i].link_data)); | |
5448 | vty_out(vty, " Number of TOS metrics: 0\n"); | |
5449 | vty_out(vty, " TOS 0 Metric: %d\n", | |
5450 | ntohs(rl->link[i].metric)); | |
5451 | vty_out(vty, "\n"); | |
5452 | } | |
718e3744 | 5453 | } |
5454 | ||
5455 | /* Show router-LSA detail information. */ | |
d62a17ae | 5456 | static int show_router_lsa_detail(struct vty *vty, struct ospf_lsa *lsa) |
718e3744 | 5457 | { |
d62a17ae | 5458 | if (lsa != NULL) { |
5459 | struct router_lsa *rl = (struct router_lsa *)lsa->data; | |
718e3744 | 5460 | |
d62a17ae | 5461 | show_ip_ospf_database_header(vty, lsa); |
718e3744 | 5462 | |
d62a17ae | 5463 | vty_out(vty, " Number of Links: %d\n\n", ntohs(rl->links)); |
718e3744 | 5464 | |
d62a17ae | 5465 | show_ip_ospf_database_router_links(vty, rl); |
5466 | vty_out(vty, "\n"); | |
5467 | } | |
5468 | ||
5469 | return 0; | |
718e3744 | 5470 | } |
5471 | ||
5472 | /* Show network-LSA detail information. */ | |
d62a17ae | 5473 | static int show_network_lsa_detail(struct vty *vty, struct ospf_lsa *lsa) |
718e3744 | 5474 | { |
d62a17ae | 5475 | int length, i; |
718e3744 | 5476 | |
d62a17ae | 5477 | if (lsa != NULL) { |
5478 | struct network_lsa *nl = (struct network_lsa *)lsa->data; | |
718e3744 | 5479 | |
d62a17ae | 5480 | show_ip_ospf_database_header(vty, lsa); |
718e3744 | 5481 | |
d62a17ae | 5482 | vty_out(vty, " Network Mask: /%d\n", ip_masklen(nl->mask)); |
718e3744 | 5483 | |
d62a17ae | 5484 | length = ntohs(lsa->data->length) - OSPF_LSA_HEADER_SIZE - 4; |
718e3744 | 5485 | |
d62a17ae | 5486 | for (i = 0; length > 0; i++, length -= 4) |
5487 | vty_out(vty, " Attached Router: %s\n", | |
5488 | inet_ntoa(nl->routers[i])); | |
718e3744 | 5489 | |
d62a17ae | 5490 | vty_out(vty, "\n"); |
5491 | } | |
718e3744 | 5492 | |
d62a17ae | 5493 | return 0; |
718e3744 | 5494 | } |
5495 | ||
5496 | /* Show summary-LSA detail information. */ | |
d62a17ae | 5497 | static int show_summary_lsa_detail(struct vty *vty, struct ospf_lsa *lsa) |
718e3744 | 5498 | { |
d62a17ae | 5499 | if (lsa != NULL) { |
5500 | struct summary_lsa *sl = (struct summary_lsa *)lsa->data; | |
718e3744 | 5501 | |
d62a17ae | 5502 | show_ip_ospf_database_header(vty, lsa); |
718e3744 | 5503 | |
d62a17ae | 5504 | vty_out(vty, " Network Mask: /%d\n", ip_masklen(sl->mask)); |
5505 | vty_out(vty, " TOS: 0 Metric: %d\n", | |
5506 | GET_METRIC(sl->metric)); | |
5507 | vty_out(vty, "\n"); | |
5508 | } | |
718e3744 | 5509 | |
d62a17ae | 5510 | return 0; |
718e3744 | 5511 | } |
5512 | ||
5513 | /* Show summary-ASBR-LSA detail information. */ | |
d62a17ae | 5514 | static int show_summary_asbr_lsa_detail(struct vty *vty, struct ospf_lsa *lsa) |
718e3744 | 5515 | { |
d62a17ae | 5516 | if (lsa != NULL) { |
5517 | struct summary_lsa *sl = (struct summary_lsa *)lsa->data; | |
718e3744 | 5518 | |
d62a17ae | 5519 | show_ip_ospf_database_header(vty, lsa); |
718e3744 | 5520 | |
d62a17ae | 5521 | vty_out(vty, " Network Mask: /%d\n", ip_masklen(sl->mask)); |
5522 | vty_out(vty, " TOS: 0 Metric: %d\n", | |
5523 | GET_METRIC(sl->metric)); | |
5524 | vty_out(vty, "\n"); | |
5525 | } | |
718e3744 | 5526 | |
d62a17ae | 5527 | return 0; |
718e3744 | 5528 | } |
5529 | ||
5530 | /* Show AS-external-LSA detail information. */ | |
d62a17ae | 5531 | static int show_as_external_lsa_detail(struct vty *vty, struct ospf_lsa *lsa) |
5532 | { | |
5533 | if (lsa != NULL) { | |
5534 | struct as_external_lsa *al = | |
5535 | (struct as_external_lsa *)lsa->data; | |
5536 | ||
5537 | show_ip_ospf_database_header(vty, lsa); | |
5538 | ||
5539 | vty_out(vty, " Network Mask: /%d\n", ip_masklen(al->mask)); | |
5540 | vty_out(vty, " Metric Type: %s\n", | |
5541 | IS_EXTERNAL_METRIC(al->e[0].tos) | |
5542 | ? "2 (Larger than any link state path)" | |
5543 | : "1"); | |
5544 | vty_out(vty, " TOS: 0\n"); | |
5545 | vty_out(vty, " Metric: %d\n", | |
5546 | GET_METRIC(al->e[0].metric)); | |
5547 | vty_out(vty, " Forward Address: %s\n", | |
5548 | inet_ntoa(al->e[0].fwd_addr)); | |
5549 | ||
5550 | vty_out(vty, | |
5551 | " External Route Tag: %" ROUTE_TAG_PRI "\n\n", | |
5552 | (route_tag_t)ntohl(al->e[0].route_tag)); | |
5553 | } | |
718e3744 | 5554 | |
d62a17ae | 5555 | return 0; |
718e3744 | 5556 | } |
075e12f5 | 5557 | #if 0 |
4dadc291 | 5558 | static int |
718e3744 | 5559 | show_as_external_lsa_stdvty (struct ospf_lsa *lsa) |
5560 | { | |
5561 | struct as_external_lsa *al = (struct as_external_lsa *) lsa->data; | |
5562 | ||
5563 | /* show_ip_ospf_database_header (vty, lsa); */ | |
5564 | ||
2a42e285 | 5565 | zlog_debug( " Network Mask: /%d%s", |
718e3744 | 5566 | ip_masklen (al->mask), "\n"); |
2a42e285 | 5567 | zlog_debug( " Metric Type: %s%s", |
718e3744 | 5568 | IS_EXTERNAL_METRIC (al->e[0].tos) ? |
5569 | "2 (Larger than any link state path)" : "1", "\n"); | |
2a42e285 | 5570 | zlog_debug( " TOS: 0%s", "\n"); |
5571 | zlog_debug( " Metric: %d%s", | |
718e3744 | 5572 | GET_METRIC (al->e[0].metric), "\n"); |
2a42e285 | 5573 | zlog_debug( " Forward Address: %s%s", |
718e3744 | 5574 | inet_ntoa (al->e[0].fwd_addr), "\n"); |
5575 | ||
dc9ffce8 CF |
5576 | zlog_debug( " External Route Tag: %"ROUTE_TAG_PRI"%s%s", |
5577 | (route_tag_t)ntohl (al->e[0].route_tag), "\n", "\n"); | |
718e3744 | 5578 | |
5579 | return 0; | |
5580 | } | |
075e12f5 | 5581 | #endif |
718e3744 | 5582 | /* Show AS-NSSA-LSA detail information. */ |
d62a17ae | 5583 | static int show_as_nssa_lsa_detail(struct vty *vty, struct ospf_lsa *lsa) |
5584 | { | |
5585 | if (lsa != NULL) { | |
5586 | struct as_external_lsa *al = | |
5587 | (struct as_external_lsa *)lsa->data; | |
5588 | ||
5589 | show_ip_ospf_database_header(vty, lsa); | |
5590 | ||
5591 | vty_out(vty, " Network Mask: /%d\n", ip_masklen(al->mask)); | |
5592 | vty_out(vty, " Metric Type: %s\n", | |
5593 | IS_EXTERNAL_METRIC(al->e[0].tos) | |
5594 | ? "2 (Larger than any link state path)" | |
5595 | : "1"); | |
5596 | vty_out(vty, " TOS: 0\n"); | |
5597 | vty_out(vty, " Metric: %d\n", | |
5598 | GET_METRIC(al->e[0].metric)); | |
5599 | vty_out(vty, " NSSA: Forward Address: %s\n", | |
5600 | inet_ntoa(al->e[0].fwd_addr)); | |
5601 | ||
5602 | vty_out(vty, | |
5603 | " External Route Tag: %" ROUTE_TAG_PRI "\n\n", | |
5604 | (route_tag_t)ntohl(al->e[0].route_tag)); | |
5605 | } | |
718e3744 | 5606 | |
d62a17ae | 5607 | return 0; |
718e3744 | 5608 | } |
5609 | ||
d62a17ae | 5610 | static int show_func_dummy(struct vty *vty, struct ospf_lsa *lsa) |
718e3744 | 5611 | { |
d62a17ae | 5612 | return 0; |
718e3744 | 5613 | } |
5614 | ||
d62a17ae | 5615 | static int show_opaque_lsa_detail(struct vty *vty, struct ospf_lsa *lsa) |
718e3744 | 5616 | { |
d62a17ae | 5617 | if (lsa != NULL) { |
5618 | show_ip_ospf_database_header(vty, lsa); | |
5619 | show_opaque_info_detail(vty, lsa); | |
718e3744 | 5620 | |
d62a17ae | 5621 | vty_out(vty, "\n"); |
5622 | } | |
5623 | return 0; | |
5624 | } | |
5625 | ||
5626 | int (*show_function[])(struct vty *, struct ospf_lsa *) = { | |
5627 | NULL, | |
5628 | show_router_lsa_detail, | |
5629 | show_network_lsa_detail, | |
5630 | show_summary_lsa_detail, | |
5631 | show_summary_asbr_lsa_detail, | |
5632 | show_as_external_lsa_detail, | |
5633 | show_func_dummy, | |
5634 | show_as_nssa_lsa_detail, /* almost same as external */ | |
5635 | NULL, /* type-8 */ | |
5636 | show_opaque_lsa_detail, | |
5637 | show_opaque_lsa_detail, | |
5638 | show_opaque_lsa_detail, | |
5639 | }; | |
5640 | ||
5641 | static void show_lsa_prefix_set(struct vty *vty, struct prefix_ls *lp, | |
5642 | struct in_addr *id, struct in_addr *adv_router) | |
5643 | { | |
5644 | memset(lp, 0, sizeof(struct prefix_ls)); | |
5645 | lp->family = 0; | |
5646 | if (id == NULL) | |
5647 | lp->prefixlen = 0; | |
5648 | else if (adv_router == NULL) { | |
5649 | lp->prefixlen = 32; | |
5650 | lp->id = *id; | |
5651 | } else { | |
5652 | lp->prefixlen = 64; | |
5653 | lp->id = *id; | |
5654 | lp->adv_router = *adv_router; | |
5655 | } | |
718e3744 | 5656 | } |
718e3744 | 5657 | |
d62a17ae | 5658 | static void show_lsa_detail_proc(struct vty *vty, struct route_table *rt, |
5659 | struct in_addr *id, struct in_addr *adv_router) | |
5660 | { | |
5661 | struct prefix_ls lp; | |
5662 | struct route_node *rn, *start; | |
5663 | struct ospf_lsa *lsa; | |
718e3744 | 5664 | |
d62a17ae | 5665 | show_lsa_prefix_set(vty, &lp, id, adv_router); |
5666 | start = route_node_get(rt, (struct prefix *)&lp); | |
5667 | if (start) { | |
5668 | route_lock_node(start); | |
5669 | for (rn = start; rn; rn = route_next_until(rn, start)) | |
5670 | if ((lsa = rn->info)) { | |
5671 | if (show_function[lsa->data->type] != NULL) | |
5672 | show_function[lsa->data->type](vty, | |
5673 | lsa); | |
5674 | } | |
5675 | route_unlock_node(start); | |
5676 | } | |
718e3744 | 5677 | } |
5678 | ||
5679 | /* Show detail LSA information | |
5680 | -- if id is NULL then show all LSAs. */ | |
d62a17ae | 5681 | static void show_lsa_detail(struct vty *vty, struct ospf *ospf, int type, |
5682 | struct in_addr *id, struct in_addr *adv_router) | |
5683 | { | |
5684 | struct listnode *node; | |
5685 | struct ospf_area *area; | |
5686 | ||
5687 | switch (type) { | |
5688 | case OSPF_AS_EXTERNAL_LSA: | |
5689 | case OSPF_OPAQUE_AS_LSA: | |
5690 | vty_out(vty, " %s \n\n", | |
5691 | show_database_desc[type]); | |
5692 | show_lsa_detail_proc(vty, AS_LSDB(ospf, type), id, adv_router); | |
5693 | break; | |
5694 | default: | |
5695 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) { | |
5696 | vty_out(vty, "\n %s (Area %s)\n\n", | |
5697 | show_database_desc[type], | |
5698 | ospf_area_desc_string(area)); | |
5699 | show_lsa_detail_proc(vty, AREA_LSDB(area, type), id, | |
5700 | adv_router); | |
5701 | } | |
5702 | break; | |
718e3744 | 5703 | } |
5704 | } | |
5705 | ||
d62a17ae | 5706 | static void show_lsa_detail_adv_router_proc(struct vty *vty, |
5707 | struct route_table *rt, | |
5708 | struct in_addr *adv_router) | |
5709 | { | |
5710 | struct route_node *rn; | |
5711 | struct ospf_lsa *lsa; | |
5712 | ||
5713 | for (rn = route_top(rt); rn; rn = route_next(rn)) | |
5714 | if ((lsa = rn->info)) | |
5715 | if (IPV4_ADDR_SAME(adv_router, | |
5716 | &lsa->data->adv_router)) { | |
5717 | if (CHECK_FLAG(lsa->flags, OSPF_LSA_LOCAL_XLT)) | |
5718 | continue; | |
5719 | if (show_function[lsa->data->type] != NULL) | |
5720 | show_function[lsa->data->type](vty, | |
5721 | lsa); | |
5722 | } | |
5723 | } | |
5724 | ||
718e3744 | 5725 | /* Show detail LSA information. */ |
d62a17ae | 5726 | static void show_lsa_detail_adv_router(struct vty *vty, struct ospf *ospf, |
5727 | int type, struct in_addr *adv_router) | |
5728 | { | |
5729 | struct listnode *node; | |
5730 | struct ospf_area *area; | |
5731 | ||
5732 | switch (type) { | |
5733 | case OSPF_AS_EXTERNAL_LSA: | |
5734 | case OSPF_OPAQUE_AS_LSA: | |
5735 | vty_out(vty, " %s \n\n", | |
5736 | show_database_desc[type]); | |
5737 | show_lsa_detail_adv_router_proc(vty, AS_LSDB(ospf, type), | |
5738 | adv_router); | |
5739 | break; | |
5740 | default: | |
5741 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) { | |
5742 | vty_out(vty, "\n %s (Area %s)\n\n", | |
5743 | show_database_desc[type], | |
5744 | ospf_area_desc_string(area)); | |
5745 | show_lsa_detail_adv_router_proc( | |
5746 | vty, AREA_LSDB(area, type), adv_router); | |
5747 | } | |
5748 | break; | |
5749 | } | |
5750 | } | |
5751 | ||
5752 | static void show_ip_ospf_database_summary(struct vty *vty, struct ospf *ospf, | |
5753 | int self) | |
5754 | { | |
5755 | struct ospf_lsa *lsa; | |
5756 | struct route_node *rn; | |
5757 | struct ospf_area *area; | |
5758 | struct listnode *node; | |
5759 | int type; | |
5760 | ||
5761 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) { | |
5762 | for (type = OSPF_MIN_LSA; type < OSPF_MAX_LSA; type++) { | |
5763 | switch (type) { | |
5764 | case OSPF_AS_EXTERNAL_LSA: | |
5765 | case OSPF_OPAQUE_AS_LSA: | |
5766 | continue; | |
5767 | default: | |
5768 | break; | |
5769 | } | |
5770 | if (ospf_lsdb_count_self(area->lsdb, type) > 0 | |
5771 | || (!self | |
5772 | && ospf_lsdb_count(area->lsdb, type) > 0)) { | |
5773 | vty_out(vty, " %s (Area %s)\n\n", | |
5774 | show_database_desc[type], | |
5775 | ospf_area_desc_string(area)); | |
5776 | vty_out(vty, "%s\n", | |
5777 | show_database_header[type]); | |
5778 | ||
5779 | LSDB_LOOP(AREA_LSDB(area, type), rn, lsa) | |
5780 | show_lsa_summary(vty, lsa, self); | |
5781 | ||
5782 | vty_out(vty, "\n"); | |
5783 | } | |
5784 | } | |
5785 | } | |
5786 | ||
5787 | for (type = OSPF_MIN_LSA; type < OSPF_MAX_LSA; type++) { | |
5788 | switch (type) { | |
5789 | case OSPF_AS_EXTERNAL_LSA: | |
5790 | case OSPF_OPAQUE_AS_LSA: | |
5791 | break; | |
5792 | default: | |
5793 | continue; | |
5794 | } | |
5795 | if (ospf_lsdb_count_self(ospf->lsdb, type) | |
5796 | || (!self && ospf_lsdb_count(ospf->lsdb, type))) { | |
5797 | vty_out(vty, " %s\n\n", | |
5798 | show_database_desc[type]); | |
5799 | vty_out(vty, "%s\n", show_database_header[type]); | |
5800 | ||
5801 | LSDB_LOOP(AS_LSDB(ospf, type), rn, lsa) | |
5802 | show_lsa_summary(vty, lsa, self); | |
5803 | ||
5804 | vty_out(vty, "\n"); | |
5805 | } | |
5806 | } | |
5807 | ||
5808 | vty_out(vty, "\n"); | |
5809 | } | |
5810 | ||
5811 | static void show_ip_ospf_database_maxage(struct vty *vty, struct ospf *ospf) | |
5812 | { | |
5813 | struct route_node *rn; | |
5814 | ||
5815 | vty_out(vty, "\n MaxAge Link States:\n\n"); | |
5816 | ||
5817 | for (rn = route_top(ospf->maxage_lsa); rn; rn = route_next(rn)) { | |
5818 | struct ospf_lsa *lsa; | |
5819 | ||
5820 | if ((lsa = rn->info) != NULL) { | |
5821 | vty_out(vty, "Link type: %d\n", lsa->data->type); | |
5822 | vty_out(vty, "Link State ID: %s\n", | |
5823 | inet_ntoa(lsa->data->id)); | |
5824 | vty_out(vty, "Advertising Router: %s\n", | |
5825 | inet_ntoa(lsa->data->adv_router)); | |
5826 | vty_out(vty, "LSA lock count: %d\n", lsa->lock); | |
5827 | vty_out(vty, "\n"); | |
5828 | } | |
91e6a0e5 | 5829 | } |
718e3744 | 5830 | } |
5831 | ||
718e3744 | 5832 | #define OSPF_LSA_TYPE_NSSA_DESC "NSSA external link state\n" |
5833 | #define OSPF_LSA_TYPE_NSSA_CMD_STR "|nssa-external" | |
718e3744 | 5834 | |
718e3744 | 5835 | #define OSPF_LSA_TYPE_OPAQUE_LINK_DESC "Link local Opaque-LSA\n" |
5836 | #define OSPF_LSA_TYPE_OPAQUE_AREA_DESC "Link area Opaque-LSA\n" | |
5837 | #define OSPF_LSA_TYPE_OPAQUE_AS_DESC "Link AS Opaque-LSA\n" | |
5838 | #define OSPF_LSA_TYPE_OPAQUE_CMD_STR "|opaque-link|opaque-area|opaque-as" | |
718e3744 | 5839 | |
d62a17ae | 5840 | #define OSPF_LSA_TYPES_DESC \ |
5841 | "ASBR summary link states\n" \ | |
5842 | "External link states\n" \ | |
5843 | "Network link states\n" \ | |
5844 | "Router link states\n" \ | |
5845 | "Network summary link states\n" OSPF_LSA_TYPE_NSSA_DESC \ | |
5846 | OSPF_LSA_TYPE_OPAQUE_LINK_DESC OSPF_LSA_TYPE_OPAQUE_AREA_DESC \ | |
5847 | OSPF_LSA_TYPE_OPAQUE_AS_DESC | |
5848 | ||
5849 | static int show_ip_ospf_database_common(struct vty *vty, struct ospf *ospf, | |
5850 | int arg_base, int argc, | |
5851 | struct cmd_token **argv) | |
5852 | { | |
5853 | int idx_type = 4; | |
5854 | int type, ret; | |
5855 | struct in_addr id, adv_router; | |
5856 | ||
5857 | if (ospf->instance) | |
5858 | vty_out(vty, "\nOSPF Instance: %d\n", ospf->instance); | |
5859 | ||
52d0c099 | 5860 | ospf_show_vrf_name(ospf, vty, NULL); |
87bd50e8 | 5861 | |
d62a17ae | 5862 | vty_out(vty, "\n OSPF Router with ID (%s)\n\n", |
5863 | inet_ntoa(ospf->router_id)); | |
5864 | ||
5865 | /* Show all LSA. */ | |
5866 | if (argc == arg_base + 4) { | |
5867 | show_ip_ospf_database_summary(vty, ospf, 0); | |
5868 | return CMD_SUCCESS; | |
5869 | } | |
718e3744 | 5870 | |
d62a17ae | 5871 | /* Set database type to show. */ |
5872 | if (strncmp(argv[arg_base + idx_type]->text, "r", 1) == 0) | |
5873 | type = OSPF_ROUTER_LSA; | |
5874 | else if (strncmp(argv[arg_base + idx_type]->text, "ne", 2) == 0) | |
5875 | type = OSPF_NETWORK_LSA; | |
5876 | else if (strncmp(argv[arg_base + idx_type]->text, "ns", 2) == 0) | |
5877 | type = OSPF_AS_NSSA_LSA; | |
5878 | else if (strncmp(argv[arg_base + idx_type]->text, "su", 2) == 0) | |
5879 | type = OSPF_SUMMARY_LSA; | |
5880 | else if (strncmp(argv[arg_base + idx_type]->text, "a", 1) == 0) | |
5881 | type = OSPF_ASBR_SUMMARY_LSA; | |
5882 | else if (strncmp(argv[arg_base + idx_type]->text, "e", 1) == 0) | |
5883 | type = OSPF_AS_EXTERNAL_LSA; | |
5884 | else if (strncmp(argv[arg_base + idx_type]->text, "se", 2) == 0) { | |
5885 | show_ip_ospf_database_summary(vty, ospf, 1); | |
5886 | return CMD_SUCCESS; | |
5887 | } else if (strncmp(argv[arg_base + idx_type]->text, "m", 1) == 0) { | |
5888 | show_ip_ospf_database_maxage(vty, ospf); | |
5889 | return CMD_SUCCESS; | |
5890 | } else if (strncmp(argv[arg_base + idx_type]->text, "opaque-l", 8) == 0) | |
5891 | type = OSPF_OPAQUE_LINK_LSA; | |
5892 | else if (strncmp(argv[arg_base + idx_type]->text, "opaque-ar", 9) == 0) | |
5893 | type = OSPF_OPAQUE_AREA_LSA; | |
5894 | else if (strncmp(argv[arg_base + idx_type]->text, "opaque-as", 9) == 0) | |
5895 | type = OSPF_OPAQUE_AS_LSA; | |
5896 | else | |
718e3744 | 5897 | return CMD_WARNING; |
d62a17ae | 5898 | |
5899 | /* `show ip ospf database LSA'. */ | |
5900 | if (argc == arg_base + 5) | |
5901 | show_lsa_detail(vty, ospf, type, NULL, NULL); | |
5902 | else if (argc >= arg_base + 6) { | |
5903 | ret = inet_aton(argv[arg_base + 5]->arg, &id); | |
5904 | if (!ret) | |
5905 | return CMD_WARNING; | |
5906 | ||
5907 | /* `show ip ospf database LSA ID'. */ | |
5908 | if (argc == arg_base + 6) | |
5909 | show_lsa_detail(vty, ospf, type, &id, NULL); | |
5910 | /* `show ip ospf database LSA ID adv-router ADV_ROUTER'. */ | |
5911 | else if (argc == arg_base + 7) { | |
5912 | if (strncmp(argv[arg_base + 6]->text, "s", 1) == 0) | |
5913 | adv_router = ospf->router_id; | |
5914 | else { | |
5915 | ret = inet_aton(argv[arg_base + 7]->arg, | |
5916 | &adv_router); | |
5917 | if (!ret) | |
5918 | return CMD_WARNING; | |
5919 | } | |
5920 | show_lsa_detail(vty, ospf, type, &id, &adv_router); | |
5921 | } | |
718e3744 | 5922 | } |
718e3744 | 5923 | |
d62a17ae | 5924 | return CMD_SUCCESS; |
718e3744 | 5925 | } |
5926 | ||
7a7be519 | 5927 | DEFUN (show_ip_ospf_database_max, |
5928 | show_ip_ospf_database_max_cmd, | |
b5a8894d | 5929 | "show ip ospf [vrf <NAME|all>] database <max-age|self-originate>", |
7a7be519 | 5930 | SHOW_STR |
5931 | IP_STR | |
5932 | "OSPF information\n" | |
b5a8894d CS |
5933 | VRF_CMD_HELP_STR |
5934 | "All VRFs\n" | |
7a7be519 | 5935 | "Database summary\n" |
5936 | "LSAs in MaxAge list\n" | |
5937 | "Self-originated link states\n") | |
5938 | { | |
b5a8894d CS |
5939 | struct ospf *ospf = NULL; |
5940 | struct listnode *node = NULL; | |
5941 | char *vrf_name = NULL; | |
5942 | bool all_vrf = FALSE; | |
5943 | int ret = CMD_SUCCESS; | |
5944 | int inst = 0; | |
5945 | int idx_vrf = 0; | |
f412b39a | 5946 | |
43b8d1d8 | 5947 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
f412b39a | 5948 | |
b5a8894d CS |
5949 | if (vrf_name) { |
5950 | if (all_vrf) { | |
5951 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
5952 | if (!ospf->oi_running) | |
5953 | continue; | |
5954 | ret = show_ip_ospf_database_common(vty, ospf, | |
5955 | idx_vrf ? 2 | |
5956 | : 0, argc, | |
5957 | argv); | |
5958 | } | |
5959 | } else { | |
5960 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
5961 | if (ospf == NULL || !ospf->oi_running) | |
5962 | return CMD_SUCCESS; | |
5963 | ret = (show_ip_ospf_database_common(vty, ospf, idx_vrf ? | |
5964 | 2 : 0, argc, argv)); | |
5965 | } | |
5966 | } else { | |
5967 | /* Display default ospf (instance 0) info */ | |
5968 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
5969 | if (ospf == NULL || !ospf->oi_running) | |
5970 | return CMD_SUCCESS; | |
5971 | ret = show_ip_ospf_database_common(vty, ospf, 0, argc, argv); | |
5972 | } | |
5973 | ||
5974 | return ret; | |
7a7be519 | 5975 | } |
f412b39a | 5976 | |
f412b39a DW |
5977 | DEFUN (show_ip_ospf_instance_database, |
5978 | show_ip_ospf_instance_database_cmd, | |
43b8d1d8 | 5979 | "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 | 5980 | SHOW_STR |
5981 | IP_STR | |
5982 | "OSPF information\n" | |
7c8ff89e | 5983 | "Instance ID\n" |
b5a8894d | 5984 | VRF_CMD_HELP_STR |
7a7be519 | 5985 | "Database summary\n" |
5986 | OSPF_LSA_TYPES_DESC | |
5987 | "Link State ID (as an IP address)\n" | |
5988 | "Self-originated link states\n" | |
5989 | "Advertising Router link states\n" | |
5990 | "Advertising Router (as an IP address)\n") | |
7c8ff89e | 5991 | { |
d62a17ae | 5992 | struct ospf *ospf; |
5993 | u_short instance = 0; | |
b5a8894d CS |
5994 | struct listnode *node = NULL; |
5995 | char *vrf_name = NULL; | |
5996 | bool all_vrf = FALSE; | |
5997 | int ret = CMD_SUCCESS; | |
5998 | int inst = 0; | |
d62a17ae | 5999 | int idx = 0; |
b5a8894d | 6000 | |
d62a17ae | 6001 | if (argv_find(argv, argc, "(1-65535)", &idx)) { |
6002 | instance = strtoul(argv[idx]->arg, NULL, 10); | |
6003 | ospf = ospf_lookup_instance(instance); | |
ac28e4ec CS |
6004 | if (ospf == NULL) |
6005 | return CMD_NOT_MY_INSTANCE; | |
b5a8894d CS |
6006 | if (!ospf->oi_running) |
6007 | return CMD_SUCCESS; | |
6008 | ||
6009 | return (show_ip_ospf_database_common(vty, ospf, idx ? 1 : 0, | |
6010 | argc, argv)); | |
6011 | } else if (argv_find(argv, argc, "vrf", &idx)) { | |
6012 | vrf_name = argv[++idx]->arg; | |
6013 | all_vrf = strmatch(vrf_name, "all"); | |
d62a17ae | 6014 | } |
7c8ff89e | 6015 | |
b5a8894d CS |
6016 | if (vrf_name) { |
6017 | if (all_vrf) { | |
6018 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
6019 | if (!ospf->oi_running) | |
6020 | continue; | |
6021 | ret = (show_ip_ospf_database_common(vty, ospf, | |
6022 | idx ? 2 : 0, | |
6023 | argc, argv)); | |
6024 | } | |
6025 | } else { | |
6026 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
6027 | if ((ospf == NULL) || !ospf->oi_running) | |
6028 | return CMD_SUCCESS; | |
6029 | ret = (show_ip_ospf_database_common(vty, ospf, idx ? 2 : | |
6030 | 0, argc, argv)); | |
6031 | } | |
6032 | } else { | |
6033 | /* Display default ospf (instance 0) info */ | |
6034 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
6035 | if (ospf == NULL || !ospf->oi_running) | |
6036 | return CMD_SUCCESS; | |
6037 | ret = (show_ip_ospf_database_common(vty, ospf, 0, argc, argv)); | |
6038 | } | |
7c8ff89e | 6039 | |
b5a8894d | 6040 | return ret; |
7c8ff89e DS |
6041 | } |
6042 | ||
7a7be519 | 6043 | DEFUN (show_ip_ospf_instance_database_max, |
6044 | show_ip_ospf_instance_database_max_cmd, | |
6045 | "show ip ospf (1-65535) database <max-age|self-originate>", | |
6046 | SHOW_STR | |
6047 | IP_STR | |
6048 | "OSPF information\n" | |
6049 | "Instance ID\n" | |
6050 | "Database summary\n" | |
6051 | "LSAs in MaxAge list\n" | |
6052 | "Self-originated link states\n") | |
6053 | { | |
d62a17ae | 6054 | int idx_number = 3; |
6055 | struct ospf *ospf; | |
6056 | u_short instance = 0; | |
6057 | ||
6058 | instance = strtoul(argv[idx_number]->arg, NULL, 10); | |
6059 | ||
ac28e4ec CS |
6060 | ospf = ospf_lookup_instance(instance); |
6061 | if (ospf == NULL) | |
6062 | return CMD_NOT_MY_INSTANCE; | |
6063 | ||
6064 | if (!ospf->oi_running) | |
d62a17ae | 6065 | return CMD_SUCCESS; |
6066 | ||
6067 | return (show_ip_ospf_database_common(vty, ospf, 1, argc, argv)); | |
6068 | } | |
6069 | ||
6070 | ||
6071 | static int show_ip_ospf_database_type_adv_router_common(struct vty *vty, | |
6072 | struct ospf *ospf, | |
6073 | int arg_base, int argc, | |
6074 | struct cmd_token **argv) | |
6075 | { | |
6076 | int idx_type = 4; | |
6077 | int type, ret; | |
6078 | struct in_addr adv_router; | |
6079 | ||
6080 | if (ospf->instance) | |
6081 | vty_out(vty, "\nOSPF Instance: %d\n", ospf->instance); | |
6082 | ||
52d0c099 | 6083 | ospf_show_vrf_name(ospf, vty, NULL); |
87bd50e8 | 6084 | |
d62a17ae | 6085 | vty_out(vty, "\n OSPF Router with ID (%s)\n\n", |
6086 | inet_ntoa(ospf->router_id)); | |
6087 | ||
6088 | /* Set database type to show. */ | |
6089 | if (strncmp(argv[arg_base + idx_type]->text, "r", 1) == 0) | |
6090 | type = OSPF_ROUTER_LSA; | |
6091 | else if (strncmp(argv[arg_base + idx_type]->text, "ne", 2) == 0) | |
6092 | type = OSPF_NETWORK_LSA; | |
6093 | else if (strncmp(argv[arg_base + idx_type]->text, "ns", 2) == 0) | |
6094 | type = OSPF_AS_NSSA_LSA; | |
6095 | else if (strncmp(argv[arg_base + idx_type]->text, "s", 1) == 0) | |
6096 | type = OSPF_SUMMARY_LSA; | |
6097 | else if (strncmp(argv[arg_base + idx_type]->text, "a", 1) == 0) | |
6098 | type = OSPF_ASBR_SUMMARY_LSA; | |
6099 | else if (strncmp(argv[arg_base + idx_type]->text, "e", 1) == 0) | |
6100 | type = OSPF_AS_EXTERNAL_LSA; | |
6101 | else if (strncmp(argv[arg_base + idx_type]->text, "opaque-l", 8) == 0) | |
6102 | type = OSPF_OPAQUE_LINK_LSA; | |
6103 | else if (strncmp(argv[arg_base + idx_type]->text, "opaque-ar", 9) == 0) | |
6104 | type = OSPF_OPAQUE_AREA_LSA; | |
6105 | else if (strncmp(argv[arg_base + idx_type]->text, "opaque-as", 9) == 0) | |
6106 | type = OSPF_OPAQUE_AS_LSA; | |
6107 | else | |
6108 | return CMD_WARNING; | |
7c8ff89e | 6109 | |
d62a17ae | 6110 | /* `show ip ospf database LSA adv-router ADV_ROUTER'. */ |
6111 | if (strncmp(argv[arg_base + 5]->text, "s", 1) == 0) | |
6112 | adv_router = ospf->router_id; | |
6113 | else { | |
6114 | ret = inet_aton(argv[arg_base + 6]->arg, &adv_router); | |
6115 | if (!ret) | |
6116 | return CMD_WARNING; | |
6117 | } | |
7c8ff89e | 6118 | |
d62a17ae | 6119 | show_lsa_detail_adv_router(vty, ospf, type, &adv_router); |
7c8ff89e | 6120 | |
d62a17ae | 6121 | return CMD_SUCCESS; |
7c8ff89e DS |
6122 | } |
6123 | ||
7c8ff89e DS |
6124 | DEFUN (show_ip_ospf_instance_database_type_adv_router, |
6125 | show_ip_ospf_instance_database_type_adv_router_cmd, | |
43b8d1d8 | 6126 | "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 |
6127 | SHOW_STR |
6128 | IP_STR | |
6129 | "OSPF information\n" | |
6130 | "Instance ID\n" | |
b5a8894d | 6131 | VRF_CMD_HELP_STR |
7c8ff89e DS |
6132 | "Database summary\n" |
6133 | OSPF_LSA_TYPES_DESC | |
6134 | "Advertising Router link states\n" | |
3a2d747c QY |
6135 | "Advertising Router (as an IP address)\n" |
6136 | "Self-originated link states\n") | |
7c8ff89e | 6137 | { |
b5a8894d | 6138 | struct ospf *ospf = NULL; |
d62a17ae | 6139 | u_short instance = 0; |
b5a8894d CS |
6140 | struct listnode *node = NULL; |
6141 | char *vrf_name = NULL; | |
6142 | bool all_vrf = FALSE; | |
6143 | int ret = CMD_SUCCESS; | |
6144 | int inst = 0; | |
43b8d1d8 | 6145 | int idx = 0, idx_vrf = 0; |
7c8ff89e | 6146 | |
d62a17ae | 6147 | if (argv_find(argv, argc, "(1-65535)", &idx)) { |
6148 | instance = strtoul(argv[idx]->arg, NULL, 10); | |
6149 | ospf = ospf_lookup_instance(instance); | |
ac28e4ec CS |
6150 | if (ospf == NULL) |
6151 | return CMD_NOT_MY_INSTANCE; | |
b5a8894d CS |
6152 | if (!ospf->oi_running) |
6153 | return CMD_SUCCESS; | |
6154 | return (show_ip_ospf_database_type_adv_router_common(vty, ospf, | |
6155 | idx ? 1 : 0, | |
6156 | argc, | |
6157 | argv)); | |
6158 | } | |
43b8d1d8 CS |
6159 | |
6160 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); | |
6161 | ||
b5a8894d CS |
6162 | if (vrf_name) { |
6163 | if (all_vrf) { | |
6164 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
6165 | if (!ospf->oi_running) | |
6166 | continue; | |
6167 | ret = show_ip_ospf_database_type_adv_router_common(vty, | |
6168 | ospf, idx ? 1 : 0, argc, argv); | |
6169 | } | |
6170 | } else { | |
6171 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
6172 | if ((ospf == NULL) || !ospf->oi_running) | |
6173 | return CMD_SUCCESS; | |
6174 | ret = show_ip_ospf_database_type_adv_router_common(vty, | |
6175 | ospf, idx ? 1 : 0, argc, argv); | |
6176 | } | |
6177 | } else { | |
6178 | /* Display default ospf (instance 0) info */ | |
6179 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
6180 | if (ospf == NULL || !ospf->oi_running) | |
6181 | return CMD_SUCCESS; | |
6182 | ret = show_ip_ospf_database_type_adv_router_common(vty, ospf, | |
6183 | idx ? 1 : 0, | |
6184 | argc, argv); | |
6185 | } | |
6186 | return ret; | |
6187 | /*return (show_ip_ospf_database_type_adv_router_common( | |
6188 | vty, ospf, idx ? 1 : 0, argc, argv));*/ | |
718e3744 | 6189 | } |
6190 | ||
718e3744 | 6191 | DEFUN (ip_ospf_authentication_args, |
6192 | ip_ospf_authentication_args_addr_cmd, | |
7a7be519 | 6193 | "ip ospf authentication <null|message-digest> [A.B.C.D]", |
718e3744 | 6194 | "IP Information\n" |
6195 | "OSPF interface commands\n" | |
6196 | "Enable authentication on this interface\n" | |
6197 | "Use null authentication\n" | |
6198 | "Use message-digest authentication\n" | |
7a7be519 | 6199 | "Address of interface\n") |
718e3744 | 6200 | { |
d62a17ae | 6201 | VTY_DECLVAR_CONTEXT(interface, ifp); |
6202 | int idx_encryption = 3; | |
6203 | int idx_ipv4 = 4; | |
6204 | struct in_addr addr; | |
6205 | int ret; | |
6206 | struct ospf_if_params *params; | |
6207 | ||
6208 | params = IF_DEF_PARAMS(ifp); | |
6209 | ||
6210 | if (argc == 5) { | |
6211 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
6212 | if (!ret) { | |
6213 | vty_out(vty, | |
6214 | "Please specify interface address by A.B.C.D\n"); | |
6215 | return CMD_WARNING_CONFIG_FAILED; | |
6216 | } | |
718e3744 | 6217 | |
d62a17ae | 6218 | params = ospf_get_if_params(ifp, addr); |
6219 | ospf_if_update_params(ifp, addr); | |
6220 | } | |
718e3744 | 6221 | |
d62a17ae | 6222 | /* Handle null authentication */ |
6223 | if (argv[idx_encryption]->arg[0] == 'n') { | |
6224 | SET_IF_PARAM(params, auth_type); | |
6225 | params->auth_type = OSPF_AUTH_NULL; | |
6226 | return CMD_SUCCESS; | |
6227 | } | |
718e3744 | 6228 | |
d62a17ae | 6229 | /* Handle message-digest authentication */ |
6230 | if (argv[idx_encryption]->arg[0] == 'm') { | |
6231 | SET_IF_PARAM(params, auth_type); | |
6232 | params->auth_type = OSPF_AUTH_CRYPTOGRAPHIC; | |
6233 | return CMD_SUCCESS; | |
6234 | } | |
718e3744 | 6235 | |
d62a17ae | 6236 | vty_out(vty, "You shouldn't get here!\n"); |
6237 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 6238 | } |
6239 | ||
718e3744 | 6240 | DEFUN (ip_ospf_authentication, |
6241 | ip_ospf_authentication_addr_cmd, | |
7a7be519 | 6242 | "ip ospf authentication [A.B.C.D]", |
718e3744 | 6243 | "IP Information\n" |
6244 | "OSPF interface commands\n" | |
6245 | "Enable authentication on this interface\n" | |
efd7904e | 6246 | "Address of interface\n") |
718e3744 | 6247 | { |
d62a17ae | 6248 | VTY_DECLVAR_CONTEXT(interface, ifp); |
6249 | int idx_ipv4 = 3; | |
6250 | struct in_addr addr; | |
6251 | int ret; | |
6252 | struct ospf_if_params *params; | |
6253 | ||
6254 | params = IF_DEF_PARAMS(ifp); | |
6255 | ||
6256 | if (argc == 4) { | |
6257 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
6258 | if (!ret) { | |
6259 | vty_out(vty, | |
6260 | "Please specify interface address by A.B.C.D\n"); | |
6261 | return CMD_WARNING_CONFIG_FAILED; | |
6262 | } | |
6263 | ||
6264 | params = ospf_get_if_params(ifp, addr); | |
6265 | ospf_if_update_params(ifp, addr); | |
718e3744 | 6266 | } |
6267 | ||
d62a17ae | 6268 | SET_IF_PARAM(params, auth_type); |
6269 | params->auth_type = OSPF_AUTH_SIMPLE; | |
718e3744 | 6270 | |
d62a17ae | 6271 | return CMD_SUCCESS; |
718e3744 | 6272 | } |
6273 | ||
b4a039bf DS |
6274 | DEFUN (no_ip_ospf_authentication_args, |
6275 | no_ip_ospf_authentication_args_addr_cmd, | |
7a7be519 | 6276 | "no ip ospf authentication <null|message-digest> [A.B.C.D]", |
b4a039bf DS |
6277 | NO_STR |
6278 | "IP Information\n" | |
6279 | "OSPF interface commands\n" | |
6280 | "Enable authentication on this interface\n" | |
6281 | "Use null authentication\n" | |
6282 | "Use message-digest authentication\n" | |
efd7904e | 6283 | "Address of interface\n") |
b4a039bf | 6284 | { |
d62a17ae | 6285 | VTY_DECLVAR_CONTEXT(interface, ifp); |
6286 | int idx_encryption = 4; | |
6287 | int idx_ipv4 = 5; | |
6288 | struct in_addr addr; | |
6289 | int ret; | |
6290 | struct ospf_if_params *params; | |
6291 | struct route_node *rn; | |
6292 | int auth_type; | |
6293 | ||
6294 | params = IF_DEF_PARAMS(ifp); | |
6295 | ||
6296 | if (argc == 6) { | |
6297 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
6298 | if (!ret) { | |
6299 | vty_out(vty, | |
6300 | "Please specify interface address by A.B.C.D\n"); | |
6301 | return CMD_WARNING_CONFIG_FAILED; | |
6302 | } | |
b4a039bf | 6303 | |
d62a17ae | 6304 | params = ospf_lookup_if_params(ifp, addr); |
6305 | if (params == NULL) { | |
6306 | vty_out(vty, "Ip Address specified is unknown\n"); | |
6307 | return CMD_WARNING_CONFIG_FAILED; | |
6308 | } | |
6309 | params->auth_type = OSPF_AUTH_NOTSET; | |
6310 | UNSET_IF_PARAM(params, auth_type); | |
6311 | if (params != IF_DEF_PARAMS(ifp)) { | |
6312 | ospf_free_if_params(ifp, addr); | |
6313 | ospf_if_update_params(ifp, addr); | |
6314 | } | |
6315 | } else { | |
6316 | if (argv[idx_encryption]->arg[0] == 'n') { | |
6317 | auth_type = OSPF_AUTH_NULL; | |
6318 | } else if (argv[idx_encryption]->arg[0] == 'm') { | |
6319 | auth_type = OSPF_AUTH_CRYPTOGRAPHIC; | |
6320 | } else { | |
6321 | vty_out(vty, "Unexpected input encountered\n"); | |
6322 | return CMD_WARNING_CONFIG_FAILED; | |
6323 | } | |
6324 | /* | |
6325 | * Here we have a case where the user has entered | |
6326 | * 'no ip ospf authentication (null | message_digest )' | |
6327 | * we need to find if we have any ip addresses underneath it | |
6328 | * that | |
6329 | * correspond to the associated type. | |
6330 | */ | |
6331 | if (params->auth_type == auth_type) { | |
6332 | params->auth_type = OSPF_AUTH_NOTSET; | |
6333 | UNSET_IF_PARAM(params, auth_type); | |
6334 | } | |
6335 | ||
6336 | for (rn = route_top(IF_OIFS_PARAMS(ifp)); rn; | |
6337 | rn = route_next(rn)) { | |
6338 | if ((params = rn->info)) { | |
6339 | if (params->auth_type == auth_type) { | |
6340 | params->auth_type = OSPF_AUTH_NOTSET; | |
6341 | UNSET_IF_PARAM(params, auth_type); | |
6342 | if (params != IF_DEF_PARAMS(ifp)) { | |
6343 | ospf_free_if_params( | |
6344 | ifp, rn->p.u.prefix4); | |
6345 | ospf_if_update_params( | |
6346 | ifp, rn->p.u.prefix4); | |
6347 | } | |
6348 | } | |
6349 | } | |
b4a039bf | 6350 | } |
b4a039bf | 6351 | } |
b4a039bf | 6352 | |
d62a17ae | 6353 | return CMD_SUCCESS; |
b4a039bf DS |
6354 | } |
6355 | ||
718e3744 | 6356 | DEFUN (no_ip_ospf_authentication, |
6357 | no_ip_ospf_authentication_addr_cmd, | |
7a7be519 | 6358 | "no ip ospf authentication [A.B.C.D]", |
718e3744 | 6359 | NO_STR |
6360 | "IP Information\n" | |
6361 | "OSPF interface commands\n" | |
6362 | "Enable authentication on this interface\n" | |
efd7904e | 6363 | "Address of interface\n") |
718e3744 | 6364 | { |
d62a17ae | 6365 | VTY_DECLVAR_CONTEXT(interface, ifp); |
6366 | int idx_ipv4 = 4; | |
6367 | struct in_addr addr; | |
6368 | int ret; | |
6369 | struct ospf_if_params *params; | |
6370 | struct route_node *rn; | |
6371 | ||
6372 | params = IF_DEF_PARAMS(ifp); | |
6373 | ||
6374 | if (argc == 5) { | |
6375 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
6376 | if (!ret) { | |
6377 | vty_out(vty, | |
6378 | "Please specify interface address by A.B.C.D\n"); | |
6379 | return CMD_WARNING_CONFIG_FAILED; | |
6380 | } | |
718e3744 | 6381 | |
d62a17ae | 6382 | params = ospf_lookup_if_params(ifp, addr); |
6383 | if (params == NULL) { | |
6384 | vty_out(vty, "Ip Address specified is unknown\n"); | |
6385 | return CMD_WARNING_CONFIG_FAILED; | |
6386 | } | |
718e3744 | 6387 | |
d62a17ae | 6388 | params->auth_type = OSPF_AUTH_NOTSET; |
6389 | UNSET_IF_PARAM(params, auth_type); | |
6390 | if (params != IF_DEF_PARAMS(ifp)) { | |
6391 | ospf_free_if_params(ifp, addr); | |
6392 | ospf_if_update_params(ifp, addr); | |
6393 | } | |
6394 | } else { | |
6395 | /* | |
6396 | * When a user enters 'no ip ospf authentication' | |
6397 | * We should remove all authentication types from | |
6398 | * the interface. | |
6399 | */ | |
6400 | if ((params->auth_type == OSPF_AUTH_NULL) | |
6401 | || (params->auth_type == OSPF_AUTH_CRYPTOGRAPHIC) | |
6402 | || (params->auth_type == OSPF_AUTH_SIMPLE)) { | |
6403 | params->auth_type = OSPF_AUTH_NOTSET; | |
6404 | UNSET_IF_PARAM(params, auth_type); | |
6405 | } | |
813d4307 | 6406 | |
d62a17ae | 6407 | for (rn = route_top(IF_OIFS_PARAMS(ifp)); rn; |
6408 | rn = route_next(rn)) { | |
6409 | if ((params = rn->info)) { | |
6410 | ||
6411 | if ((params->auth_type == OSPF_AUTH_NULL) | |
6412 | || (params->auth_type | |
6413 | == OSPF_AUTH_CRYPTOGRAPHIC) | |
6414 | || (params->auth_type | |
6415 | == OSPF_AUTH_SIMPLE)) { | |
6416 | params->auth_type = OSPF_AUTH_NOTSET; | |
6417 | UNSET_IF_PARAM(params, auth_type); | |
6418 | if (params != IF_DEF_PARAMS(ifp)) { | |
6419 | ospf_free_if_params( | |
6420 | ifp, rn->p.u.prefix4); | |
6421 | ospf_if_update_params( | |
6422 | ifp, rn->p.u.prefix4); | |
6423 | } | |
6424 | } | |
6425 | } | |
b4a039bf | 6426 | } |
b4a039bf | 6427 | } |
d62a17ae | 6428 | |
6429 | return CMD_SUCCESS; | |
718e3744 | 6430 | } |
6431 | ||
0d829fa7 | 6432 | |
718e3744 | 6433 | DEFUN (ip_ospf_authentication_key, |
6434 | ip_ospf_authentication_key_addr_cmd, | |
7a7be519 | 6435 | "ip ospf authentication-key AUTH_KEY [A.B.C.D]", |
718e3744 | 6436 | "IP Information\n" |
6437 | "OSPF interface commands\n" | |
6438 | "Authentication password (key)\n" | |
6439 | "The OSPF password (key)\n" | |
efd7904e | 6440 | "Address of interface\n") |
718e3744 | 6441 | { |
d62a17ae | 6442 | VTY_DECLVAR_CONTEXT(interface, ifp); |
6443 | int idx = 0; | |
6444 | struct in_addr addr; | |
6445 | struct ospf_if_params *params; | |
718e3744 | 6446 | |
d62a17ae | 6447 | params = IF_DEF_PARAMS(ifp); |
6448 | ||
6449 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
6450 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
6451 | vty_out(vty, | |
6452 | "Please specify interface address by A.B.C.D\n"); | |
6453 | return CMD_WARNING_CONFIG_FAILED; | |
6454 | } | |
718e3744 | 6455 | |
d62a17ae | 6456 | params = ospf_get_if_params(ifp, addr); |
6457 | ospf_if_update_params(ifp, addr); | |
6458 | } | |
718e3744 | 6459 | |
d62a17ae | 6460 | memset(params->auth_simple, 0, OSPF_AUTH_SIMPLE_SIZE + 1); |
6461 | strncpy((char *)params->auth_simple, argv[3]->arg, | |
6462 | OSPF_AUTH_SIMPLE_SIZE); | |
6463 | SET_IF_PARAM(params, auth_simple); | |
718e3744 | 6464 | |
d62a17ae | 6465 | return CMD_SUCCESS; |
718e3744 | 6466 | } |
6467 | ||
7a7be519 | 6468 | DEFUN_HIDDEN (ospf_authentication_key, |
747e489c | 6469 | ospf_authentication_key_cmd, |
0d829fa7 | 6470 | "ospf authentication-key AUTH_KEY [A.B.C.D]", |
747e489c | 6471 | "OSPF interface commands\n" |
baf9eaad | 6472 | VLINK_HELPSTR_AUTH_SIMPLE |
0d829fa7 | 6473 | "Address of interface\n") |
718e3744 | 6474 | { |
d62a17ae | 6475 | return ip_ospf_authentication_key(self, vty, argc, argv); |
718e3744 | 6476 | } |
6477 | ||
7a7be519 | 6478 | DEFUN (no_ip_ospf_authentication_key, |
6479 | no_ip_ospf_authentication_key_authkey_addr_cmd, | |
6480 | "no ip ospf authentication-key [AUTH_KEY [A.B.C.D]]", | |
6481 | NO_STR | |
6482 | "IP Information\n" | |
6483 | "OSPF interface commands\n" | |
baf9eaad CS |
6484 | VLINK_HELPSTR_AUTH_SIMPLE |
6485 | "Address of interface\n") | |
7a7be519 | 6486 | { |
d62a17ae | 6487 | VTY_DECLVAR_CONTEXT(interface, ifp); |
6488 | int idx = 0; | |
6489 | struct in_addr addr; | |
6490 | struct ospf_if_params *params; | |
6491 | params = IF_DEF_PARAMS(ifp); | |
6492 | ||
6493 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
6494 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
6495 | vty_out(vty, | |
6496 | "Please specify interface address by A.B.C.D\n"); | |
6497 | return CMD_WARNING_CONFIG_FAILED; | |
6498 | } | |
7a7be519 | 6499 | |
d62a17ae | 6500 | params = ospf_lookup_if_params(ifp, addr); |
6501 | if (params == NULL) | |
6502 | return CMD_SUCCESS; | |
7a7be519 | 6503 | } |
813d4307 | 6504 | |
d62a17ae | 6505 | memset(params->auth_simple, 0, OSPF_AUTH_SIMPLE_SIZE); |
6506 | UNSET_IF_PARAM(params, auth_simple); | |
718e3744 | 6507 | |
d62a17ae | 6508 | if (params != IF_DEF_PARAMS(ifp)) { |
6509 | ospf_free_if_params(ifp, addr); | |
6510 | ospf_if_update_params(ifp, addr); | |
6511 | } | |
813d4307 | 6512 | |
d62a17ae | 6513 | return CMD_SUCCESS; |
7a7be519 | 6514 | } |
813d4307 | 6515 | |
0d829fa7 QY |
6516 | DEFUN_HIDDEN (no_ospf_authentication_key, |
6517 | no_ospf_authentication_key_authkey_addr_cmd, | |
6518 | "no ospf authentication-key [AUTH_KEY [A.B.C.D]]", | |
6519 | NO_STR | |
6520 | "OSPF interface commands\n" | |
baf9eaad CS |
6521 | VLINK_HELPSTR_AUTH_SIMPLE |
6522 | "Address of interface\n") | |
0d829fa7 | 6523 | { |
d62a17ae | 6524 | return no_ip_ospf_authentication_key(self, vty, argc, argv); |
0d829fa7 QY |
6525 | } |
6526 | ||
718e3744 | 6527 | DEFUN (ip_ospf_message_digest_key, |
537eae3f | 6528 | ip_ospf_message_digest_key_cmd, |
7a7be519 | 6529 | "ip ospf message-digest-key (1-255) md5 KEY [A.B.C.D]", |
718e3744 | 6530 | "IP Information\n" |
6531 | "OSPF interface commands\n" | |
6532 | "Message digest authentication password (key)\n" | |
6533 | "Key ID\n" | |
6534 | "Use MD5 algorithm\n" | |
fefa0d82 QY |
6535 | "The OSPF password (key)\n" |
6536 | "Address of interface\n") | |
718e3744 | 6537 | { |
d62a17ae | 6538 | VTY_DECLVAR_CONTEXT(interface, ifp); |
6539 | struct crypt_key *ck; | |
6540 | u_char key_id; | |
6541 | struct in_addr addr; | |
6542 | struct ospf_if_params *params; | |
6543 | ||
6544 | params = IF_DEF_PARAMS(ifp); | |
6545 | int idx = 0; | |
6546 | ||
6547 | argv_find(argv, argc, "(1-255)", &idx); | |
6548 | char *keyid = argv[idx]->arg; | |
6549 | argv_find(argv, argc, "KEY", &idx); | |
6550 | char *cryptkey = argv[idx]->arg; | |
6551 | ||
6552 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
6553 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
6554 | vty_out(vty, | |
6555 | "Please specify interface address by A.B.C.D\n"); | |
6556 | return CMD_WARNING_CONFIG_FAILED; | |
6557 | } | |
6558 | ||
6559 | params = ospf_get_if_params(ifp, addr); | |
6560 | ospf_if_update_params(ifp, addr); | |
718e3744 | 6561 | } |
6562 | ||
d62a17ae | 6563 | key_id = strtol(keyid, NULL, 10); |
6564 | if (ospf_crypt_key_lookup(params->auth_crypt, key_id) != NULL) { | |
6565 | vty_out(vty, "OSPF: Key %d already exists\n", key_id); | |
851fcbae | 6566 | return CMD_WARNING; |
d62a17ae | 6567 | } |
718e3744 | 6568 | |
d62a17ae | 6569 | ck = ospf_crypt_key_new(); |
6570 | ck->key_id = (u_char)key_id; | |
6571 | memset(ck->auth_key, 0, OSPF_AUTH_MD5_SIZE + 1); | |
6572 | strncpy((char *)ck->auth_key, cryptkey, OSPF_AUTH_MD5_SIZE); | |
718e3744 | 6573 | |
d62a17ae | 6574 | ospf_crypt_key_add(params->auth_crypt, ck); |
6575 | SET_IF_PARAM(params, auth_crypt); | |
718e3744 | 6576 | |
d62a17ae | 6577 | return CMD_SUCCESS; |
718e3744 | 6578 | } |
6579 | ||
7a7be519 | 6580 | DEFUN_HIDDEN (ospf_message_digest_key, |
747e489c | 6581 | ospf_message_digest_key_cmd, |
0d829fa7 | 6582 | "ospf message-digest-key (1-255) md5 KEY [A.B.C.D]", |
747e489c DW |
6583 | "OSPF interface commands\n" |
6584 | "Message digest authentication password (key)\n" | |
6585 | "Key ID\n" | |
6586 | "Use MD5 algorithm\n" | |
0d829fa7 QY |
6587 | "The OSPF password (key)\n" |
6588 | "Address of interface\n") | |
7a7be519 | 6589 | { |
d62a17ae | 6590 | return ip_ospf_message_digest_key(self, vty, argc, argv); |
7a7be519 | 6591 | } |
718e3744 | 6592 | |
537eae3f QY |
6593 | DEFUN (no_ip_ospf_message_digest_key, |
6594 | no_ip_ospf_message_digest_key_cmd, | |
0d829fa7 | 6595 | "no ip ospf message-digest-key (1-255) [md5 KEY] [A.B.C.D]", |
813d4307 DW |
6596 | NO_STR |
6597 | "IP Information\n" | |
6598 | "OSPF interface commands\n" | |
6599 | "Message digest authentication password (key)\n" | |
6600 | "Key ID\n" | |
6601 | "Use MD5 algorithm\n" | |
0d829fa7 QY |
6602 | "The OSPF password (key)\n" |
6603 | "Address of interface\n") | |
813d4307 | 6604 | { |
d62a17ae | 6605 | VTY_DECLVAR_CONTEXT(interface, ifp); |
6606 | int idx = 0; | |
6607 | struct crypt_key *ck; | |
6608 | int key_id; | |
6609 | struct in_addr addr; | |
6610 | struct ospf_if_params *params; | |
6611 | params = IF_DEF_PARAMS(ifp); | |
6612 | ||
6613 | argv_find(argv, argc, "(1-255)", &idx); | |
6614 | char *keyid = argv[idx]->arg; | |
6615 | ||
6616 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
6617 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
6618 | vty_out(vty, | |
6619 | "Please specify interface address by A.B.C.D\n"); | |
6620 | return CMD_WARNING_CONFIG_FAILED; | |
6621 | } | |
7a7be519 | 6622 | |
d62a17ae | 6623 | params = ospf_lookup_if_params(ifp, addr); |
6624 | if (params == NULL) | |
6625 | return CMD_SUCCESS; | |
7a7be519 | 6626 | } |
6627 | ||
d62a17ae | 6628 | key_id = strtol(keyid, NULL, 10); |
6629 | ck = ospf_crypt_key_lookup(params->auth_crypt, key_id); | |
6630 | if (ck == NULL) { | |
6631 | vty_out(vty, "OSPF: Key %d does not exist\n", key_id); | |
6632 | return CMD_WARNING_CONFIG_FAILED; | |
6633 | } | |
7a7be519 | 6634 | |
d62a17ae | 6635 | ospf_crypt_key_delete(params->auth_crypt, key_id); |
7a7be519 | 6636 | |
d62a17ae | 6637 | if (params != IF_DEF_PARAMS(ifp)) { |
6638 | ospf_free_if_params(ifp, addr); | |
6639 | ospf_if_update_params(ifp, addr); | |
6640 | } | |
7a7be519 | 6641 | |
d62a17ae | 6642 | return CMD_SUCCESS; |
7a7be519 | 6643 | } |
813d4307 | 6644 | |
0d829fa7 | 6645 | DEFUN_HIDDEN (no_ospf_message_digest_key, |
537eae3f | 6646 | no_ospf_message_digest_key_cmd, |
0d829fa7 QY |
6647 | "no ospf message-digest-key (1-255) [md5 KEY] [A.B.C.D]", |
6648 | NO_STR | |
6649 | "OSPF interface commands\n" | |
6650 | "Message digest authentication password (key)\n" | |
6651 | "Key ID\n" | |
efd7904e RW |
6652 | "Use MD5 algorithm\n" |
6653 | "The OSPF password (key)\n" | |
6654 | "Address of interface\n") | |
718e3744 | 6655 | { |
d62a17ae | 6656 | return no_ip_ospf_message_digest_key(self, vty, argc, argv); |
718e3744 | 6657 | } |
6658 | ||
718e3744 | 6659 | DEFUN (ip_ospf_cost, |
5c2fc921 | 6660 | ip_ospf_cost_cmd, |
7a7be519 | 6661 | "ip ospf cost (1-65535) [A.B.C.D]", |
718e3744 | 6662 | "IP Information\n" |
6663 | "OSPF interface commands\n" | |
6664 | "Interface cost\n" | |
6665 | "Cost\n" | |
5c2fc921 | 6666 | "Address of interface\n") |
718e3744 | 6667 | { |
d62a17ae | 6668 | VTY_DECLVAR_CONTEXT(interface, ifp); |
6669 | int idx = 0; | |
35955c14 | 6670 | u_int32_t cost = OSPF_OUTPUT_COST_DEFAULT; |
d62a17ae | 6671 | struct in_addr addr; |
6672 | struct ospf_if_params *params; | |
6673 | params = IF_DEF_PARAMS(ifp); | |
6674 | ||
6675 | // get arguments | |
6676 | char *coststr = NULL, *ifaddr = NULL; | |
35955c14 | 6677 | |
c31a793b VJ |
6678 | argv_find(argv, argc, "(1-65535)", &idx); |
6679 | coststr = argv[idx]->arg; | |
d62a17ae | 6680 | cost = strtol(coststr, NULL, 10); |
6681 | ||
c31a793b | 6682 | ifaddr = argv_find(argv, argc, "A.B.C.D", &idx) ? argv[idx]->arg : NULL; |
d62a17ae | 6683 | if (ifaddr) { |
6684 | if (!inet_aton(ifaddr, &addr)) { | |
6685 | vty_out(vty, | |
6686 | "Please specify interface address by A.B.C.D\n"); | |
6687 | return CMD_WARNING_CONFIG_FAILED; | |
6688 | } | |
718e3744 | 6689 | |
d62a17ae | 6690 | params = ospf_get_if_params(ifp, addr); |
6691 | ospf_if_update_params(ifp, addr); | |
718e3744 | 6692 | } |
6693 | ||
d62a17ae | 6694 | SET_IF_PARAM(params, output_cost_cmd); |
6695 | params->output_cost_cmd = cost; | |
718e3744 | 6696 | |
d62a17ae | 6697 | ospf_if_recalculate_output_cost(ifp); |
5c2fc921 | 6698 | |
d62a17ae | 6699 | return CMD_SUCCESS; |
718e3744 | 6700 | } |
6701 | ||
7a7be519 | 6702 | DEFUN_HIDDEN (ospf_cost, |
5c2fc921 QY |
6703 | ospf_cost_cmd, |
6704 | "ospf cost (1-65535) [A.B.C.D]", | |
747e489c DW |
6705 | "OSPF interface commands\n" |
6706 | "Interface cost\n" | |
6707 | "Cost\n" | |
5c2fc921 | 6708 | "Address of interface\n") |
7a7be519 | 6709 | { |
d62a17ae | 6710 | return ip_ospf_cost(self, vty, argc, argv); |
7a7be519 | 6711 | } |
9eff36b3 | 6712 | |
718e3744 | 6713 | DEFUN (no_ip_ospf_cost, |
5c2fc921 QY |
6714 | no_ip_ospf_cost_cmd, |
6715 | "no ip ospf cost [(1-65535)] [A.B.C.D]", | |
718e3744 | 6716 | NO_STR |
efd7904e | 6717 | "IP Information\n" |
718e3744 | 6718 | "OSPF interface commands\n" |
6719 | "Interface cost\n" | |
efd7904e RW |
6720 | "Cost\n" |
6721 | "Address of interface\n") | |
718e3744 | 6722 | { |
d62a17ae | 6723 | VTY_DECLVAR_CONTEXT(interface, ifp); |
6724 | int idx = 0; | |
6725 | struct in_addr addr; | |
6726 | struct ospf_if_params *params; | |
7a7be519 | 6727 | |
d62a17ae | 6728 | params = IF_DEF_PARAMS(ifp); |
718e3744 | 6729 | |
d62a17ae | 6730 | // get arguments |
6731 | char *ifaddr = NULL; | |
6732 | ifaddr = argv_find(argv, argc, "A.B.C.D", &idx) ? argv[idx]->arg : NULL; | |
718e3744 | 6733 | |
d62a17ae | 6734 | /* According to the semantics we are mimicking "no ip ospf cost N" is |
6735 | * always treated as "no ip ospf cost" regardless of the actual value | |
6736 | * of N already configured for the interface. Thus ignore cost. */ | |
7a7be519 | 6737 | |
d62a17ae | 6738 | if (ifaddr) { |
6739 | if (!inet_aton(ifaddr, &addr)) { | |
6740 | vty_out(vty, | |
6741 | "Please specify interface address by A.B.C.D\n"); | |
6742 | return CMD_WARNING_CONFIG_FAILED; | |
6743 | } | |
7a7be519 | 6744 | |
d62a17ae | 6745 | params = ospf_lookup_if_params(ifp, addr); |
6746 | if (params == NULL) | |
6747 | return CMD_SUCCESS; | |
6748 | } | |
7a7be519 | 6749 | |
d62a17ae | 6750 | UNSET_IF_PARAM(params, output_cost_cmd); |
7a7be519 | 6751 | |
d62a17ae | 6752 | if (params != IF_DEF_PARAMS(ifp)) { |
6753 | ospf_free_if_params(ifp, addr); | |
6754 | ospf_if_update_params(ifp, addr); | |
6755 | } | |
7a7be519 | 6756 | |
d62a17ae | 6757 | ospf_if_recalculate_output_cost(ifp); |
7a7be519 | 6758 | |
d62a17ae | 6759 | return CMD_SUCCESS; |
7a7be519 | 6760 | } |
9eff36b3 | 6761 | |
5c2fc921 QY |
6762 | DEFUN_HIDDEN (no_ospf_cost, |
6763 | no_ospf_cost_cmd, | |
6764 | "no ospf cost [(1-65535)] [A.B.C.D]", | |
6765 | NO_STR | |
6766 | "OSPF interface commands\n" | |
6767 | "Interface cost\n" | |
6768 | "Cost\n" | |
6769 | "Address of interface\n") | |
827341b7 | 6770 | { |
d62a17ae | 6771 | return no_ip_ospf_cost(self, vty, argc, argv); |
827341b7 DO |
6772 | } |
6773 | ||
d62a17ae | 6774 | static void ospf_nbr_timer_update(struct ospf_interface *oi) |
718e3744 | 6775 | { |
d62a17ae | 6776 | struct route_node *rn; |
6777 | struct ospf_neighbor *nbr; | |
718e3744 | 6778 | |
d62a17ae | 6779 | for (rn = route_top(oi->nbrs); rn; rn = route_next(rn)) |
6780 | if ((nbr = rn->info)) { | |
6781 | nbr->v_inactivity = OSPF_IF_PARAM(oi, v_wait); | |
6782 | nbr->v_db_desc = OSPF_IF_PARAM(oi, retransmit_interval); | |
6783 | nbr->v_ls_req = OSPF_IF_PARAM(oi, retransmit_interval); | |
6784 | nbr->v_ls_upd = OSPF_IF_PARAM(oi, retransmit_interval); | |
6785 | } | |
718e3744 | 6786 | } |
6787 | ||
d62a17ae | 6788 | static int ospf_vty_dead_interval_set(struct vty *vty, const char *interval_str, |
6789 | const char *nbr_str, | |
6790 | const char *fast_hello_str) | |
6791 | { | |
6792 | VTY_DECLVAR_CONTEXT(interface, ifp); | |
6793 | u_int32_t seconds; | |
6794 | u_char hellomult; | |
6795 | struct in_addr addr; | |
6796 | int ret; | |
6797 | struct ospf_if_params *params; | |
6798 | struct ospf_interface *oi; | |
6799 | struct route_node *rn; | |
718e3744 | 6800 | |
d62a17ae | 6801 | params = IF_DEF_PARAMS(ifp); |
6802 | ||
6803 | if (nbr_str) { | |
6804 | ret = inet_aton(nbr_str, &addr); | |
6805 | if (!ret) { | |
6806 | vty_out(vty, | |
6807 | "Please specify interface address by A.B.C.D\n"); | |
6808 | return CMD_WARNING_CONFIG_FAILED; | |
6809 | } | |
6810 | ||
6811 | params = ospf_get_if_params(ifp, addr); | |
6812 | ospf_if_update_params(ifp, addr); | |
6813 | } | |
6814 | ||
6815 | if (interval_str) { | |
6816 | seconds = strtoul(interval_str, NULL, 10); | |
6817 | ||
6818 | /* reset fast_hello too, just to be sure */ | |
6819 | UNSET_IF_PARAM(params, fast_hello); | |
6820 | params->fast_hello = OSPF_FAST_HELLO_DEFAULT; | |
6821 | } else if (fast_hello_str) { | |
6822 | hellomult = strtoul(fast_hello_str, NULL, 10); | |
6823 | /* 1s dead-interval with sub-second hellos desired */ | |
6824 | seconds = OSPF_ROUTER_DEAD_INTERVAL_MINIMAL; | |
6825 | SET_IF_PARAM(params, fast_hello); | |
6826 | params->fast_hello = hellomult; | |
6827 | } else { | |
6828 | vty_out(vty, | |
6829 | "Please specify dead-interval or hello-multiplier\n"); | |
6830 | return CMD_WARNING_CONFIG_FAILED; | |
6831 | } | |
6832 | ||
6833 | SET_IF_PARAM(params, v_wait); | |
6834 | params->v_wait = seconds; | |
6835 | ||
6836 | /* Update timer values in neighbor structure. */ | |
6837 | if (nbr_str) { | |
b5a8894d CS |
6838 | struct ospf *ospf = NULL; |
6839 | ||
6840 | ospf = ospf_lookup_by_vrf_id(ifp->vrf_id); | |
6841 | if (ospf) { | |
d62a17ae | 6842 | oi = ospf_if_lookup_by_local_addr(ospf, ifp, addr); |
6843 | if (oi) | |
6844 | ospf_nbr_timer_update(oi); | |
6845 | } | |
6846 | } else { | |
6847 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) | |
6848 | if ((oi = rn->info)) | |
6849 | ospf_nbr_timer_update(oi); | |
6850 | } | |
6851 | ||
6852 | return CMD_SUCCESS; | |
718e3744 | 6853 | } |
6854 | ||
f9ad937f | 6855 | DEFUN (ip_ospf_dead_interval, |
0d829fa7 | 6856 | ip_ospf_dead_interval_cmd, |
7a7be519 | 6857 | "ip ospf dead-interval (1-65535) [A.B.C.D]", |
f9ad937f | 6858 | "IP Information\n" |
6859 | "OSPF interface commands\n" | |
99a522c7 | 6860 | "Interval time after which a neighbor is declared down\n" |
f9ad937f | 6861 | "Seconds\n" |
6862 | "Address of interface\n") | |
6863 | { | |
d62a17ae | 6864 | int idx = 0; |
6865 | char *interval = argv_find(argv, argc, "(1-65535)", &idx) | |
6866 | ? argv[idx]->arg | |
6867 | : NULL; | |
6868 | char *ifaddr = | |
6869 | argv_find(argv, argc, "A.B.C.D", &idx) ? argv[idx]->arg : NULL; | |
6870 | return ospf_vty_dead_interval_set(vty, interval, ifaddr, NULL); | |
f9ad937f | 6871 | } |
6872 | ||
718e3744 | 6873 | |
7a7be519 | 6874 | DEFUN_HIDDEN (ospf_dead_interval, |
747e489c | 6875 | ospf_dead_interval_cmd, |
0d829fa7 | 6876 | "ospf dead-interval (1-65535) [A.B.C.D]", |
747e489c | 6877 | "OSPF interface commands\n" |
99a522c7 | 6878 | "Interval time after which a neighbor is declared down\n" |
0d829fa7 QY |
6879 | "Seconds\n" |
6880 | "Address of interface\n") | |
7a7be519 | 6881 | { |
d62a17ae | 6882 | return ip_ospf_dead_interval(self, vty, argc, argv); |
7a7be519 | 6883 | } |
718e3744 | 6884 | |
f9ad937f | 6885 | DEFUN (ip_ospf_dead_interval_minimal, |
6886 | ip_ospf_dead_interval_minimal_addr_cmd, | |
7a7be519 | 6887 | "ip ospf dead-interval minimal hello-multiplier (1-10) [A.B.C.D]", |
f9ad937f | 6888 | "IP Information\n" |
6889 | "OSPF interface commands\n" | |
99a522c7 | 6890 | "Interval time after which a neighbor is declared down\n" |
f9ad937f | 6891 | "Minimal 1s dead-interval with fast sub-second hellos\n" |
6892 | "Hello multiplier factor\n" | |
6893 | "Number of Hellos to send each second\n" | |
6894 | "Address of interface\n") | |
6895 | { | |
d62a17ae | 6896 | int idx_number = 5; |
6897 | int idx_ipv4 = 6; | |
6898 | if (argc == 7) | |
6899 | return ospf_vty_dead_interval_set( | |
6900 | vty, NULL, argv[idx_ipv4]->arg, argv[idx_number]->arg); | |
6901 | else | |
6902 | return ospf_vty_dead_interval_set(vty, NULL, NULL, | |
6903 | argv[idx_number]->arg); | |
f9ad937f | 6904 | } |
6905 | ||
718e3744 | 6906 | DEFUN (no_ip_ospf_dead_interval, |
0d829fa7 | 6907 | no_ip_ospf_dead_interval_cmd, |
e83a9414 | 6908 | "no ip ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]", |
718e3744 | 6909 | NO_STR |
6910 | "IP Information\n" | |
6911 | "OSPF interface commands\n" | |
99a522c7 | 6912 | "Interval time after which a neighbor is declared down\n" |
f9dfba8d | 6913 | "Seconds\n" |
efd7904e RW |
6914 | "Minimal 1s dead-interval with fast sub-second hellos\n" |
6915 | "Hello multiplier factor\n" | |
6916 | "Number of Hellos to send each second\n" | |
6917 | "Address of interface\n") | |
718e3744 | 6918 | { |
d62a17ae | 6919 | VTY_DECLVAR_CONTEXT(interface, ifp); |
6920 | int idx_ipv4 = argc - 1; | |
6921 | struct in_addr addr = {.s_addr = 0L}; | |
6922 | int ret; | |
6923 | struct ospf_if_params *params; | |
6924 | struct ospf_interface *oi; | |
6925 | struct route_node *rn; | |
6926 | ||
6927 | params = IF_DEF_PARAMS(ifp); | |
6928 | ||
6929 | if (argv[idx_ipv4]->type == IPV4_TKN) { | |
6930 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
6931 | if (!ret) { | |
6932 | vty_out(vty, | |
6933 | "Please specify interface address by A.B.C.D\n"); | |
6934 | return CMD_WARNING_CONFIG_FAILED; | |
6935 | } | |
020709f9 | 6936 | |
d62a17ae | 6937 | params = ospf_lookup_if_params(ifp, addr); |
6938 | if (params == NULL) | |
6939 | return CMD_SUCCESS; | |
6940 | } | |
718e3744 | 6941 | |
d62a17ae | 6942 | UNSET_IF_PARAM(params, v_wait); |
6943 | params->v_wait = OSPF_ROUTER_DEAD_INTERVAL_DEFAULT; | |
6944 | ||
6945 | UNSET_IF_PARAM(params, fast_hello); | |
6946 | params->fast_hello = OSPF_FAST_HELLO_DEFAULT; | |
6947 | ||
6948 | if (params != IF_DEF_PARAMS(ifp)) { | |
6949 | ospf_free_if_params(ifp, addr); | |
6950 | ospf_if_update_params(ifp, addr); | |
718e3744 | 6951 | } |
6952 | ||
d62a17ae | 6953 | /* Update timer values in neighbor structure. */ |
6954 | if (argc == 1) { | |
b5a8894d | 6955 | struct ospf *ospf = NULL; |
718e3744 | 6956 | |
b5a8894d CS |
6957 | ospf = ospf_lookup_by_vrf_id(ifp->vrf_id); |
6958 | if (ospf) { | |
d62a17ae | 6959 | oi = ospf_if_lookup_by_local_addr(ospf, ifp, addr); |
6960 | if (oi) | |
6961 | ospf_nbr_timer_update(oi); | |
6962 | } | |
6963 | } else { | |
6964 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) | |
6965 | if ((oi = rn->info)) | |
6966 | ospf_nbr_timer_update(oi); | |
6967 | } | |
6968 | ||
6969 | return CMD_SUCCESS; | |
718e3744 | 6970 | } |
6971 | ||
0d829fa7 QY |
6972 | DEFUN_HIDDEN (no_ospf_dead_interval, |
6973 | no_ospf_dead_interval_cmd, | |
6974 | "no ospf dead-interval [<(1-65535)|minimal hello-multiplier (1-10)> [A.B.C.D]]", | |
6975 | NO_STR | |
6976 | "OSPF interface commands\n" | |
99a522c7 | 6977 | "Interval time after which a neighbor is declared down\n" |
0d829fa7 | 6978 | "Seconds\n" |
efd7904e RW |
6979 | "Minimal 1s dead-interval with fast sub-second hellos\n" |
6980 | "Hello multiplier factor\n" | |
6981 | "Number of Hellos to send each second\n" | |
6982 | "Address of interface\n") | |
0d829fa7 | 6983 | { |
d62a17ae | 6984 | return no_ip_ospf_dead_interval(self, vty, argc, argv); |
0d829fa7 QY |
6985 | } |
6986 | ||
718e3744 | 6987 | DEFUN (ip_ospf_hello_interval, |
0d829fa7 | 6988 | ip_ospf_hello_interval_cmd, |
7a7be519 | 6989 | "ip ospf hello-interval (1-65535) [A.B.C.D]", |
718e3744 | 6990 | "IP Information\n" |
6991 | "OSPF interface commands\n" | |
6992 | "Time between HELLO packets\n" | |
6993 | "Seconds\n" | |
0d829fa7 | 6994 | "Address of interface\n") |
718e3744 | 6995 | { |
d62a17ae | 6996 | VTY_DECLVAR_CONTEXT(interface, ifp); |
6997 | int idx = 0; | |
6998 | struct in_addr addr; | |
6999 | struct ospf_if_params *params; | |
7000 | params = IF_DEF_PARAMS(ifp); | |
7001 | u_int32_t seconds = 0; | |
7002 | ||
7003 | argv_find(argv, argc, "(1-65535)", &idx); | |
7004 | seconds = strtol(argv[idx]->arg, NULL, 10); | |
7005 | ||
7006 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
7007 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
7008 | vty_out(vty, | |
7009 | "Please specify interface address by A.B.C.D\n"); | |
7010 | return CMD_WARNING_CONFIG_FAILED; | |
7011 | } | |
718e3744 | 7012 | |
d62a17ae | 7013 | params = ospf_get_if_params(ifp, addr); |
7014 | ospf_if_update_params(ifp, addr); | |
7015 | } | |
718e3744 | 7016 | |
d62a17ae | 7017 | SET_IF_PARAM(params, v_hello); |
7018 | params->v_hello = seconds; | |
718e3744 | 7019 | |
d62a17ae | 7020 | return CMD_SUCCESS; |
718e3744 | 7021 | } |
7022 | ||
7a7be519 | 7023 | DEFUN_HIDDEN (ospf_hello_interval, |
747e489c | 7024 | ospf_hello_interval_cmd, |
0d829fa7 | 7025 | "ospf hello-interval (1-65535) [A.B.C.D]", |
747e489c DW |
7026 | "OSPF interface commands\n" |
7027 | "Time between HELLO packets\n" | |
0d829fa7 QY |
7028 | "Seconds\n" |
7029 | "Address of interface\n") | |
7a7be519 | 7030 | { |
d62a17ae | 7031 | return ip_ospf_hello_interval(self, vty, argc, argv); |
7a7be519 | 7032 | } |
718e3744 | 7033 | |
7034 | DEFUN (no_ip_ospf_hello_interval, | |
0d829fa7 QY |
7035 | no_ip_ospf_hello_interval_cmd, |
7036 | "no ip ospf hello-interval [(1-65535) [A.B.C.D]]", | |
718e3744 | 7037 | NO_STR |
7038 | "IP Information\n" | |
7039 | "OSPF interface commands\n" | |
0d829fa7 | 7040 | "Time between HELLO packets\n" // ignored |
f9dfba8d | 7041 | "Seconds\n" |
0d829fa7 | 7042 | "Address of interface\n") |
718e3744 | 7043 | { |
d62a17ae | 7044 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7045 | int idx = 0; | |
7046 | struct in_addr addr; | |
7047 | struct ospf_if_params *params; | |
df581cd3 | 7048 | |
d62a17ae | 7049 | params = IF_DEF_PARAMS(ifp); |
718e3744 | 7050 | |
d62a17ae | 7051 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { |
7052 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
7053 | vty_out(vty, | |
7054 | "Please specify interface address by A.B.C.D\n"); | |
7055 | return CMD_WARNING_CONFIG_FAILED; | |
7056 | } | |
718e3744 | 7057 | |
d62a17ae | 7058 | params = ospf_lookup_if_params(ifp, addr); |
7059 | if (params == NULL) | |
7060 | return CMD_SUCCESS; | |
7061 | } | |
718e3744 | 7062 | |
d62a17ae | 7063 | UNSET_IF_PARAM(params, v_hello); |
7064 | params->v_hello = OSPF_HELLO_INTERVAL_DEFAULT; | |
718e3744 | 7065 | |
d62a17ae | 7066 | if (params != IF_DEF_PARAMS(ifp)) { |
7067 | ospf_free_if_params(ifp, addr); | |
7068 | ospf_if_update_params(ifp, addr); | |
7069 | } | |
718e3744 | 7070 | |
d62a17ae | 7071 | return CMD_SUCCESS; |
718e3744 | 7072 | } |
7073 | ||
0d829fa7 QY |
7074 | DEFUN_HIDDEN (no_ospf_hello_interval, |
7075 | no_ospf_hello_interval_cmd, | |
7076 | "no ospf hello-interval [(1-65535) [A.B.C.D]]", | |
7077 | NO_STR | |
7078 | "OSPF interface commands\n" | |
7079 | "Time between HELLO packets\n" // ignored | |
7080 | "Seconds\n" | |
7081 | "Address of interface\n") | |
7082 | { | |
d62a17ae | 7083 | return no_ip_ospf_hello_interval(self, vty, argc, argv); |
0d829fa7 | 7084 | } |
718e3744 | 7085 | |
7086 | DEFUN (ip_ospf_network, | |
7087 | ip_ospf_network_cmd, | |
6147e2c6 | 7088 | "ip ospf network <broadcast|non-broadcast|point-to-multipoint|point-to-point>", |
718e3744 | 7089 | "IP Information\n" |
7090 | "OSPF interface commands\n" | |
7091 | "Network type\n" | |
7092 | "Specify OSPF broadcast multi-access network\n" | |
7093 | "Specify OSPF NBMA network\n" | |
7094 | "Specify OSPF point-to-multipoint network\n" | |
7095 | "Specify OSPF point-to-point network\n") | |
7096 | { | |
d62a17ae | 7097 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7098 | int idx = 0; | |
7099 | int old_type = IF_DEF_PARAMS(ifp)->type; | |
7100 | struct route_node *rn; | |
718e3744 | 7101 | |
d62a17ae | 7102 | if (old_type == OSPF_IFTYPE_LOOPBACK) { |
7103 | vty_out(vty, | |
7104 | "This is a loopback interface. Can't set network type.\n"); | |
7105 | return CMD_WARNING_CONFIG_FAILED; | |
7106 | } | |
718e3744 | 7107 | |
d62a17ae | 7108 | if (argv_find(argv, argc, "broadcast", &idx)) |
7109 | IF_DEF_PARAMS(ifp)->type = OSPF_IFTYPE_BROADCAST; | |
7110 | else if (argv_find(argv, argc, "non-broadcast", &idx)) | |
7111 | IF_DEF_PARAMS(ifp)->type = OSPF_IFTYPE_NBMA; | |
7112 | else if (argv_find(argv, argc, "point-to-multipoint", &idx)) | |
7113 | IF_DEF_PARAMS(ifp)->type = OSPF_IFTYPE_POINTOMULTIPOINT; | |
7114 | else if (argv_find(argv, argc, "point-to-point", &idx)) | |
7115 | IF_DEF_PARAMS(ifp)->type = OSPF_IFTYPE_POINTOPOINT; | |
718e3744 | 7116 | |
d62a17ae | 7117 | if (IF_DEF_PARAMS(ifp)->type == old_type) |
7118 | return CMD_SUCCESS; | |
7119 | ||
7120 | SET_IF_PARAM(IF_DEF_PARAMS(ifp), type); | |
7121 | ||
7122 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { | |
7123 | struct ospf_interface *oi = rn->info; | |
7124 | ||
7125 | if (!oi) | |
7126 | continue; | |
7127 | ||
7128 | oi->type = IF_DEF_PARAMS(ifp)->type; | |
7129 | ||
7130 | if (oi->state > ISM_Down) { | |
7131 | OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceDown); | |
7132 | OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceUp); | |
7133 | } | |
7a7be519 | 7134 | } |
7a7be519 | 7135 | |
d62a17ae | 7136 | return CMD_SUCCESS; |
7a7be519 | 7137 | } |
7138 | ||
7139 | DEFUN_HIDDEN (ospf_network, | |
7140 | ospf_network_cmd, | |
e83a9414 | 7141 | "ospf network <broadcast|non-broadcast|point-to-multipoint|point-to-point>", |
7a7be519 | 7142 | "OSPF interface commands\n" |
7143 | "Network type\n" | |
7144 | "Specify OSPF broadcast multi-access network\n" | |
7145 | "Specify OSPF NBMA network\n" | |
7146 | "Specify OSPF point-to-multipoint network\n" | |
7147 | "Specify OSPF point-to-point network\n") | |
7148 | { | |
d62a17ae | 7149 | return ip_ospf_network(self, vty, argc, argv); |
7a7be519 | 7150 | } |
7151 | ||
7152 | DEFUN (no_ip_ospf_network, | |
7153 | no_ip_ospf_network_cmd, | |
7154 | "no ip ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]", | |
7155 | NO_STR | |
7156 | "IP Information\n" | |
7157 | "OSPF interface commands\n" | |
7158 | "Network type\n" | |
7159 | "Specify OSPF broadcast multi-access network\n" | |
7160 | "Specify OSPF NBMA network\n" | |
7161 | "Specify OSPF point-to-multipoint network\n" | |
7162 | "Specify OSPF point-to-point network\n") | |
22b27e95 | 7163 | { |
d62a17ae | 7164 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7165 | int old_type = IF_DEF_PARAMS(ifp)->type; | |
7166 | struct route_node *rn; | |
7a7be519 | 7167 | |
d62a17ae | 7168 | IF_DEF_PARAMS(ifp)->type = ospf_default_iftype(ifp); |
7a7be519 | 7169 | |
d62a17ae | 7170 | if (IF_DEF_PARAMS(ifp)->type == old_type) |
7171 | return CMD_SUCCESS; | |
7a7be519 | 7172 | |
d62a17ae | 7173 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { |
7174 | struct ospf_interface *oi = rn->info; | |
7a7be519 | 7175 | |
d62a17ae | 7176 | if (!oi) |
7177 | continue; | |
7a7be519 | 7178 | |
d62a17ae | 7179 | oi->type = IF_DEF_PARAMS(ifp)->type; |
7a7be519 | 7180 | |
d62a17ae | 7181 | if (oi->state > ISM_Down) { |
7182 | OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceDown); | |
7183 | OSPF_ISM_EVENT_EXECUTE(oi, ISM_InterfaceUp); | |
7184 | } | |
7a7be519 | 7185 | } |
7a7be519 | 7186 | |
d62a17ae | 7187 | return CMD_SUCCESS; |
7a7be519 | 7188 | } |
7189 | ||
0d829fa7 QY |
7190 | DEFUN_HIDDEN (no_ospf_network, |
7191 | no_ospf_network_cmd, | |
7192 | "no ospf network [<broadcast|non-broadcast|point-to-multipoint|point-to-point>]", | |
7193 | NO_STR | |
7194 | "OSPF interface commands\n" | |
7195 | "Network type\n" | |
7196 | "Specify OSPF broadcast multi-access network\n" | |
7197 | "Specify OSPF NBMA network\n" | |
7198 | "Specify OSPF point-to-multipoint network\n" | |
7199 | "Specify OSPF point-to-point network\n") | |
7200 | { | |
d62a17ae | 7201 | return no_ip_ospf_network(self, vty, argc, argv); |
0d829fa7 QY |
7202 | } |
7203 | ||
7a7be519 | 7204 | DEFUN (ip_ospf_priority, |
537eae3f | 7205 | ip_ospf_priority_cmd, |
7a7be519 | 7206 | "ip ospf priority (0-255) [A.B.C.D]", |
7207 | "IP Information\n" | |
7208 | "OSPF interface commands\n" | |
7209 | "Router priority\n" | |
7210 | "Priority\n" | |
efd7904e | 7211 | "Address of interface\n") |
7a7be519 | 7212 | { |
d62a17ae | 7213 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7214 | int idx = 0; | |
7215 | long priority; | |
7216 | struct route_node *rn; | |
7217 | struct in_addr addr; | |
7218 | struct ospf_if_params *params; | |
7219 | params = IF_DEF_PARAMS(ifp); | |
7220 | ||
7221 | argv_find(argv, argc, "(0-255)", &idx); | |
7222 | priority = strtol(argv[idx]->arg, NULL, 10); | |
7223 | ||
7224 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
7225 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
7226 | vty_out(vty, | |
7227 | "Please specify interface address by A.B.C.D\n"); | |
7228 | return CMD_WARNING_CONFIG_FAILED; | |
7229 | } | |
7a7be519 | 7230 | |
d62a17ae | 7231 | params = ospf_get_if_params(ifp, addr); |
7232 | ospf_if_update_params(ifp, addr); | |
7a7be519 | 7233 | } |
7234 | ||
d62a17ae | 7235 | SET_IF_PARAM(params, priority); |
7236 | params->priority = priority; | |
7a7be519 | 7237 | |
d62a17ae | 7238 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { |
7239 | struct ospf_interface *oi = rn->info; | |
7a7be519 | 7240 | |
d62a17ae | 7241 | if (!oi) |
7242 | continue; | |
7a7be519 | 7243 | |
d62a17ae | 7244 | if (PRIORITY(oi) != OSPF_IF_PARAM(oi, priority)) { |
7245 | PRIORITY(oi) = OSPF_IF_PARAM(oi, priority); | |
7246 | OSPF_ISM_EVENT_SCHEDULE(oi, ISM_NeighborChange); | |
7247 | } | |
718e3744 | 7248 | } |
718e3744 | 7249 | |
d62a17ae | 7250 | return CMD_SUCCESS; |
718e3744 | 7251 | } |
7252 | ||
7a7be519 | 7253 | DEFUN_HIDDEN (ospf_priority, |
7254 | ospf_priority_cmd, | |
0d829fa7 | 7255 | "ospf priority (0-255) [A.B.C.D]", |
7a7be519 | 7256 | "OSPF interface commands\n" |
7257 | "Router priority\n" | |
3a2d747c | 7258 | "Priority\n" |
efd7904e | 7259 | "Address of interface\n") |
718e3744 | 7260 | { |
d62a17ae | 7261 | return ip_ospf_priority(self, vty, argc, argv); |
718e3744 | 7262 | } |
7263 | ||
718e3744 | 7264 | DEFUN (no_ip_ospf_priority, |
537eae3f | 7265 | no_ip_ospf_priority_cmd, |
7a7be519 | 7266 | "no ip ospf priority [(0-255) [A.B.C.D]]", |
718e3744 | 7267 | NO_STR |
7268 | "IP Information\n" | |
7269 | "OSPF interface commands\n" | |
0d829fa7 | 7270 | "Router priority\n" // ignored |
813d4307 | 7271 | "Priority\n" |
efd7904e | 7272 | "Address of interface\n") |
718e3744 | 7273 | { |
d62a17ae | 7274 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7275 | int idx = 0; | |
7276 | struct route_node *rn; | |
7277 | struct in_addr addr; | |
7278 | struct ospf_if_params *params; | |
7279 | ||
7280 | params = IF_DEF_PARAMS(ifp); | |
7281 | ||
7282 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
7283 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
7284 | vty_out(vty, | |
7285 | "Please specify interface address by A.B.C.D\n"); | |
7286 | return CMD_WARNING_CONFIG_FAILED; | |
7287 | } | |
7288 | ||
7289 | params = ospf_lookup_if_params(ifp, addr); | |
7290 | if (params == NULL) | |
7291 | return CMD_SUCCESS; | |
718e3744 | 7292 | } |
7293 | ||
d62a17ae | 7294 | UNSET_IF_PARAM(params, priority); |
7295 | params->priority = OSPF_ROUTER_PRIORITY_DEFAULT; | |
7296 | ||
7297 | if (params != IF_DEF_PARAMS(ifp)) { | |
7298 | ospf_free_if_params(ifp, addr); | |
7299 | ospf_if_update_params(ifp, addr); | |
718e3744 | 7300 | } |
d62a17ae | 7301 | |
7302 | for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { | |
7303 | struct ospf_interface *oi = rn->info; | |
7304 | ||
7305 | if (!oi) | |
7306 | continue; | |
7307 | ||
7308 | if (PRIORITY(oi) != OSPF_IF_PARAM(oi, priority)) { | |
7309 | PRIORITY(oi) = OSPF_IF_PARAM(oi, priority); | |
7310 | OSPF_ISM_EVENT_SCHEDULE(oi, ISM_NeighborChange); | |
7311 | } | |
7312 | } | |
7313 | ||
7314 | return CMD_SUCCESS; | |
718e3744 | 7315 | } |
7316 | ||
0d829fa7 | 7317 | DEFUN_HIDDEN (no_ospf_priority, |
537eae3f | 7318 | no_ospf_priority_cmd, |
0d829fa7 QY |
7319 | "no ospf priority [(0-255) [A.B.C.D]]", |
7320 | NO_STR | |
7321 | "OSPF interface commands\n" | |
7322 | "Router priority\n" | |
7323 | "Priority\n" | |
efd7904e | 7324 | "Address of interface\n") |
0d829fa7 | 7325 | { |
d62a17ae | 7326 | return no_ip_ospf_priority(self, vty, argc, argv); |
0d829fa7 | 7327 | } |
a1afa410 | 7328 | |
718e3744 | 7329 | DEFUN (ip_ospf_retransmit_interval, |
7330 | ip_ospf_retransmit_interval_addr_cmd, | |
7a7be519 | 7331 | "ip ospf retransmit-interval (3-65535) [A.B.C.D]", |
718e3744 | 7332 | "IP Information\n" |
7333 | "OSPF interface commands\n" | |
7334 | "Time between retransmitting lost link state advertisements\n" | |
7335 | "Seconds\n" | |
efd7904e | 7336 | "Address of interface\n") |
718e3744 | 7337 | { |
d62a17ae | 7338 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7339 | int idx = 0; | |
7340 | u_int32_t seconds; | |
7341 | struct in_addr addr; | |
7342 | struct ospf_if_params *params; | |
7343 | params = IF_DEF_PARAMS(ifp); | |
7344 | ||
7345 | argv_find(argv, argc, "(3-65535)", &idx); | |
7346 | seconds = strtol(argv[idx]->arg, NULL, 10); | |
7347 | ||
7348 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
7349 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
7350 | vty_out(vty, | |
7351 | "Please specify interface address by A.B.C.D\n"); | |
7352 | return CMD_WARNING_CONFIG_FAILED; | |
7353 | } | |
718e3744 | 7354 | |
d62a17ae | 7355 | params = ospf_get_if_params(ifp, addr); |
7356 | ospf_if_update_params(ifp, addr); | |
718e3744 | 7357 | } |
7358 | ||
d62a17ae | 7359 | SET_IF_PARAM(params, retransmit_interval); |
7360 | params->retransmit_interval = seconds; | |
718e3744 | 7361 | |
d62a17ae | 7362 | return CMD_SUCCESS; |
718e3744 | 7363 | } |
7364 | ||
7a7be519 | 7365 | DEFUN_HIDDEN (ospf_retransmit_interval, |
747e489c | 7366 | ospf_retransmit_interval_cmd, |
0d829fa7 | 7367 | "ospf retransmit-interval (3-65535) [A.B.C.D]", |
747e489c DW |
7368 | "OSPF interface commands\n" |
7369 | "Time between retransmitting lost link state advertisements\n" | |
3a2d747c | 7370 | "Seconds\n" |
efd7904e | 7371 | "Address of interface\n") |
7a7be519 | 7372 | { |
d62a17ae | 7373 | return ip_ospf_retransmit_interval(self, vty, argc, argv); |
7a7be519 | 7374 | } |
718e3744 | 7375 | |
7376 | DEFUN (no_ip_ospf_retransmit_interval, | |
7377 | no_ip_ospf_retransmit_interval_addr_cmd, | |
0d829fa7 | 7378 | "no ip ospf retransmit-interval [(3-65535)] [A.B.C.D]", |
718e3744 | 7379 | NO_STR |
7380 | "IP Information\n" | |
7381 | "OSPF interface commands\n" | |
3a2d747c QY |
7382 | "Time between retransmitting lost link state advertisements\n" |
7383 | "Seconds\n" | |
0d829fa7 | 7384 | "Address of interface\n") |
718e3744 | 7385 | { |
d62a17ae | 7386 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7387 | int idx = 0; | |
7388 | struct in_addr addr; | |
7389 | struct ospf_if_params *params; | |
47b91972 | 7390 | |
d62a17ae | 7391 | params = IF_DEF_PARAMS(ifp); |
718e3744 | 7392 | |
d62a17ae | 7393 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { |
7394 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
7395 | vty_out(vty, | |
7396 | "Please specify interface address by A.B.C.D\n"); | |
7397 | return CMD_WARNING_CONFIG_FAILED; | |
7398 | } | |
718e3744 | 7399 | |
d62a17ae | 7400 | params = ospf_lookup_if_params(ifp, addr); |
7401 | if (params == NULL) | |
7402 | return CMD_SUCCESS; | |
7403 | } | |
718e3744 | 7404 | |
d62a17ae | 7405 | UNSET_IF_PARAM(params, retransmit_interval); |
7406 | params->retransmit_interval = OSPF_RETRANSMIT_INTERVAL_DEFAULT; | |
718e3744 | 7407 | |
d62a17ae | 7408 | if (params != IF_DEF_PARAMS(ifp)) { |
7409 | ospf_free_if_params(ifp, addr); | |
7410 | ospf_if_update_params(ifp, addr); | |
7411 | } | |
718e3744 | 7412 | |
d62a17ae | 7413 | return CMD_SUCCESS; |
718e3744 | 7414 | } |
7415 | ||
0d829fa7 QY |
7416 | DEFUN_HIDDEN (no_ospf_retransmit_interval, |
7417 | no_ospf_retransmit_interval_cmd, | |
7418 | "no ospf retransmit-interval [(3-65535)] [A.B.C.D]", | |
7419 | NO_STR | |
7420 | "OSPF interface commands\n" | |
3a2d747c QY |
7421 | "Time between retransmitting lost link state advertisements\n" |
7422 | "Seconds\n" | |
7423 | "Address of interface\n") | |
0d829fa7 | 7424 | { |
d62a17ae | 7425 | return no_ip_ospf_retransmit_interval(self, vty, argc, argv); |
0d829fa7 | 7426 | } |
813d4307 | 7427 | |
718e3744 | 7428 | DEFUN (ip_ospf_transmit_delay, |
7429 | ip_ospf_transmit_delay_addr_cmd, | |
7a7be519 | 7430 | "ip ospf transmit-delay (1-65535) [A.B.C.D]", |
718e3744 | 7431 | "IP Information\n" |
7432 | "OSPF interface commands\n" | |
7433 | "Link state transmit delay\n" | |
7434 | "Seconds\n" | |
efd7904e | 7435 | "Address of interface\n") |
718e3744 | 7436 | { |
d62a17ae | 7437 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7438 | int idx = 0; | |
7439 | u_int32_t seconds; | |
7440 | struct in_addr addr; | |
7441 | struct ospf_if_params *params; | |
7442 | ||
7443 | params = IF_DEF_PARAMS(ifp); | |
7444 | argv_find(argv, argc, "(1-65535)", &idx); | |
7445 | seconds = strtol(argv[idx]->arg, NULL, 10); | |
7446 | ||
7447 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { | |
7448 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
7449 | vty_out(vty, | |
7450 | "Please specify interface address by A.B.C.D\n"); | |
7451 | return CMD_WARNING_CONFIG_FAILED; | |
7452 | } | |
718e3744 | 7453 | |
d62a17ae | 7454 | params = ospf_get_if_params(ifp, addr); |
7455 | ospf_if_update_params(ifp, addr); | |
718e3744 | 7456 | } |
7457 | ||
d62a17ae | 7458 | SET_IF_PARAM(params, transmit_delay); |
7459 | params->transmit_delay = seconds; | |
718e3744 | 7460 | |
d62a17ae | 7461 | return CMD_SUCCESS; |
718e3744 | 7462 | } |
7463 | ||
7a7be519 | 7464 | DEFUN_HIDDEN (ospf_transmit_delay, |
747e489c | 7465 | ospf_transmit_delay_cmd, |
0d829fa7 | 7466 | "ospf transmit-delay (1-65535) [A.B.C.D]", |
747e489c DW |
7467 | "OSPF interface commands\n" |
7468 | "Link state transmit delay\n" | |
3a2d747c | 7469 | "Seconds\n" |
efd7904e | 7470 | "Address of interface\n") |
7a7be519 | 7471 | { |
d62a17ae | 7472 | return ip_ospf_transmit_delay(self, vty, argc, argv); |
7a7be519 | 7473 | } |
718e3744 | 7474 | |
7475 | DEFUN (no_ip_ospf_transmit_delay, | |
7476 | no_ip_ospf_transmit_delay_addr_cmd, | |
0d829fa7 | 7477 | "no ip ospf transmit-delay [(1-65535)] [A.B.C.D]", |
718e3744 | 7478 | NO_STR |
7479 | "IP Information\n" | |
7480 | "OSPF interface commands\n" | |
7481 | "Link state transmit delay\n" | |
efd7904e RW |
7482 | "Seconds\n" |
7483 | "Address of interface\n") | |
718e3744 | 7484 | { |
d62a17ae | 7485 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7486 | int idx = 0; | |
7487 | struct in_addr addr; | |
7488 | struct ospf_if_params *params; | |
718e3744 | 7489 | |
d62a17ae | 7490 | params = IF_DEF_PARAMS(ifp); |
718e3744 | 7491 | |
d62a17ae | 7492 | if (argv_find(argv, argc, "A.B.C.D", &idx)) { |
7493 | if (!inet_aton(argv[idx]->arg, &addr)) { | |
7494 | vty_out(vty, | |
7495 | "Please specify interface address by A.B.C.D\n"); | |
7496 | return CMD_WARNING_CONFIG_FAILED; | |
7497 | } | |
718e3744 | 7498 | |
d62a17ae | 7499 | params = ospf_lookup_if_params(ifp, addr); |
7500 | if (params == NULL) | |
7501 | return CMD_SUCCESS; | |
7502 | } | |
718e3744 | 7503 | |
d62a17ae | 7504 | UNSET_IF_PARAM(params, transmit_delay); |
7505 | params->transmit_delay = OSPF_TRANSMIT_DELAY_DEFAULT; | |
718e3744 | 7506 | |
d62a17ae | 7507 | if (params != IF_DEF_PARAMS(ifp)) { |
7508 | ospf_free_if_params(ifp, addr); | |
7509 | ospf_if_update_params(ifp, addr); | |
7510 | } | |
7511 | ||
7512 | return CMD_SUCCESS; | |
718e3744 | 7513 | } |
7514 | ||
813d4307 | 7515 | |
0d829fa7 QY |
7516 | DEFUN_HIDDEN (no_ospf_transmit_delay, |
7517 | no_ospf_transmit_delay_cmd, | |
32573073 | 7518 | "no ospf transmit-delay [(1-65535) [A.B.C.D]]", |
0d829fa7 QY |
7519 | NO_STR |
7520 | "OSPF interface commands\n" | |
32573073 QY |
7521 | "Link state transmit delay\n" |
7522 | "Seconds\n" | |
efd7904e | 7523 | "Address of interface\n") |
813d4307 | 7524 | { |
d62a17ae | 7525 | return no_ip_ospf_transmit_delay(self, vty, argc, argv); |
813d4307 DW |
7526 | } |
7527 | ||
e723861d DS |
7528 | DEFUN (ip_ospf_area, |
7529 | ip_ospf_area_cmd, | |
52c62ab8 | 7530 | "ip ospf [(1-65535)] area <A.B.C.D|(0-4294967295)> [A.B.C.D]", |
e723861d DS |
7531 | "IP Information\n" |
7532 | "OSPF interface commands\n" | |
7a7be519 | 7533 | "Instance ID\n" |
e723861d DS |
7534 | "Enable OSPF on this interface\n" |
7535 | "OSPF area ID in IP address format\n" | |
52c62ab8 JAG |
7536 | "OSPF area ID as a decimal value\n" |
7537 | "Address of interface\n") | |
e723861d | 7538 | { |
d62a17ae | 7539 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7540 | int idx = 0; | |
7541 | int format, ret; | |
7542 | struct in_addr area_id; | |
7543 | struct in_addr addr; | |
35955c14 | 7544 | struct ospf_if_params *params = NULL; |
d62a17ae | 7545 | struct route_node *rn; |
b5a8894d | 7546 | struct ospf *ospf = NULL; |
d62a17ae | 7547 | u_short instance = 0; |
7548 | char *areaid; | |
7549 | ||
7550 | if (argv_find(argv, argc, "(1-65535)", &idx)) | |
7551 | instance = strtol(argv[idx]->arg, NULL, 10); | |
7552 | ||
7553 | argv_find(argv, argc, "area", &idx); | |
7554 | areaid = argv[idx + 1]->arg; | |
7555 | ||
b5a8894d CS |
7556 | if (ifp->vrf_id && !instance) |
7557 | ospf = ospf_lookup_by_vrf_id(ifp->vrf_id); | |
7558 | else | |
7559 | ospf = ospf_lookup_instance(instance); | |
7560 | ||
d62a17ae | 7561 | if (ospf == NULL) { |
7562 | params = IF_DEF_PARAMS(ifp); | |
7563 | if (OSPF_IF_PARAM_CONFIGURED(params, if_area)) { | |
7564 | UNSET_IF_PARAM(params, if_area); | |
b5a8894d CS |
7565 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); |
7566 | ospf_interface_area_unset(ospf, ifp); | |
d62a17ae | 7567 | ospf->if_ospf_cli_count--; |
7568 | } | |
ac28e4ec | 7569 | return CMD_NOT_MY_INSTANCE; |
d62a17ae | 7570 | } |
e723861d | 7571 | |
d62a17ae | 7572 | ret = str2area_id(areaid, &area_id, &format); |
7573 | if (ret < 0) { | |
7574 | vty_out(vty, "Please specify area by A.B.C.D|<0-4294967295>\n"); | |
7575 | return CMD_WARNING_CONFIG_FAILED; | |
7576 | } | |
7577 | if (memcmp(ifp->name, "VLINK", 5) == 0) { | |
7578 | vty_out(vty, "Cannot enable OSPF on a virtual link.\n"); | |
7579 | return CMD_WARNING_CONFIG_FAILED; | |
7580 | } | |
7581 | ||
7582 | params = IF_DEF_PARAMS(ifp); | |
7583 | if (OSPF_IF_PARAM_CONFIGURED(params, if_area) | |
7584 | && !IPV4_ADDR_SAME(¶ms->if_area, &area_id)) { | |
7585 | vty_out(vty, | |
7586 | "Must remove previous area config before changing ospf area \n"); | |
7587 | return CMD_WARNING_CONFIG_FAILED; | |
7588 | } | |
7589 | ||
7590 | // Check if we have an address arg and proccess it | |
7591 | if (argc == idx + 3) { | |
cc9b06ad DS |
7592 | if (!inet_aton(argv[idx + 2]->arg, &addr)) { |
7593 | vty_out(vty, "Please specify Intf Address by A.B.C.D\n"); | |
7594 | return CMD_WARNING_CONFIG_FAILED; | |
7595 | } | |
d62a17ae | 7596 | // update/create address-level params |
7597 | params = ospf_get_if_params((ifp), (addr)); | |
7598 | if (OSPF_IF_PARAM_CONFIGURED(params, if_area)) { | |
7599 | vty_out(vty, | |
7600 | "Must remove previous area/address config before changing ospf area"); | |
7601 | return CMD_WARNING_CONFIG_FAILED; | |
7602 | } | |
7603 | ospf_if_update_params((ifp), (addr)); | |
7604 | } | |
7605 | ||
7606 | for (rn = route_top(ospf->networks); rn; rn = route_next(rn)) { | |
7607 | if (rn->info != NULL) { | |
7608 | vty_out(vty, | |
7609 | "Please remove all network commands first.\n"); | |
7610 | return CMD_WARNING_CONFIG_FAILED; | |
7611 | } | |
7612 | } | |
7613 | ||
7614 | /* enable ospf on this interface with area_id */ | |
35955c14 CS |
7615 | if (params) { |
7616 | SET_IF_PARAM(params, if_area); | |
7617 | params->if_area = area_id; | |
7618 | params->if_area_id_fmt = format; | |
7619 | } | |
b5a8894d | 7620 | ospf_interface_area_set(ospf, ifp); |
d62a17ae | 7621 | ospf->if_ospf_cli_count++; |
7622 | ||
7623 | return CMD_SUCCESS; | |
e723861d DS |
7624 | } |
7625 | ||
7626 | DEFUN (no_ip_ospf_area, | |
7627 | no_ip_ospf_area_cmd, | |
52c62ab8 | 7628 | "no ip ospf [(1-65535)] area [<A.B.C.D|(0-4294967295)> [A.B.C.D]]", |
e723861d DS |
7629 | NO_STR |
7630 | "IP Information\n" | |
7631 | "OSPF interface commands\n" | |
3a2d747c | 7632 | "Instance ID\n" |
7a7be519 | 7633 | "Disable OSPF on this interface\n" |
7634 | "OSPF area ID in IP address format\n" | |
52c62ab8 JAG |
7635 | "OSPF area ID as a decimal value\n" |
7636 | "Address of interface\n") | |
e723861d | 7637 | { |
d62a17ae | 7638 | VTY_DECLVAR_CONTEXT(interface, ifp); |
7639 | int idx = 0; | |
7640 | struct ospf *ospf; | |
7641 | struct ospf_if_params *params; | |
7642 | u_short instance = 0; | |
7643 | struct in_addr addr; | |
7644 | ||
7645 | if (argv_find(argv, argc, "(1-65535)", &idx)) | |
7646 | instance = strtol(argv[idx]->arg, NULL, 10); | |
7647 | ||
b5a8894d CS |
7648 | if (ifp->vrf_id && !instance) |
7649 | ospf = ospf_lookup_by_vrf_id(ifp->vrf_id); | |
7650 | else | |
7651 | ospf = ospf_lookup_instance(instance); | |
7652 | ||
ac28e4ec CS |
7653 | if (ospf == NULL) |
7654 | return CMD_NOT_MY_INSTANCE; | |
d62a17ae | 7655 | |
7656 | argv_find(argv, argc, "area", &idx); | |
7657 | ||
7658 | // Check if we have an address arg and proccess it | |
7659 | if (argc == idx + 3) { | |
cc9b06ad DS |
7660 | if (!inet_aton(argv[idx + 2]->arg, &addr)) { |
7661 | vty_out(vty, "Please specify Intf Address by A.B.C.D\n"); | |
7662 | return CMD_WARNING_CONFIG_FAILED; | |
7663 | } | |
d62a17ae | 7664 | params = ospf_lookup_if_params(ifp, addr); |
7665 | if ((params) == NULL) | |
7666 | return CMD_SUCCESS; | |
7667 | } else | |
7668 | params = IF_DEF_PARAMS(ifp); | |
7669 | ||
7670 | if (!OSPF_IF_PARAM_CONFIGURED(params, if_area)) { | |
7671 | vty_out(vty, | |
7672 | "Can't find specified interface area configuration.\n"); | |
7673 | return CMD_WARNING_CONFIG_FAILED; | |
7674 | } | |
813d4307 | 7675 | |
d62a17ae | 7676 | UNSET_IF_PARAM(params, if_area); |
7677 | if (params != IF_DEF_PARAMS((ifp))) { | |
7678 | ospf_free_if_params((ifp), (addr)); | |
7679 | ospf_if_update_params((ifp), (addr)); | |
7680 | } | |
7681 | ||
b5a8894d | 7682 | ospf_interface_area_unset(ospf, ifp); |
d62a17ae | 7683 | ospf->if_ospf_cli_count--; |
7684 | return CMD_SUCCESS; | |
813d4307 DW |
7685 | } |
7686 | ||
6f2a6703 CF |
7687 | DEFUN (ospf_redistribute_source, |
7688 | ospf_redistribute_source_cmd, | |
40d1cbfb | 7689 | "redistribute " FRR_REDIST_STR_OSPFD " [<metric (0-16777214)|metric-type (1-2)|route-map WORD>]", |
d1c65c21 | 7690 | REDIST_STR |
ab0181ee | 7691 | FRR_REDIST_HELP_STR_OSPFD |
718e3744 | 7692 | "Metric for redistributed routes\n" |
7693 | "OSPF default metric\n" | |
7694 | "OSPF exterior metric type for redistributed routes\n" | |
7111c1a0 | 7695 | "Set OSPF External Type 1/2 metrics\n" |
718e3744 | 7696 | "Route map reference\n" |
7697 | "Pointer to route-map entries\n") | |
7698 | { | |
a3d826f0 | 7699 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 7700 | int idx_protocol = 1; |
7701 | int source; | |
7702 | int type = -1; | |
7703 | int metric = -1; | |
7704 | struct ospf_redist *red; | |
7705 | int idx = 0; | |
6f2a6703 | 7706 | |
d62a17ae | 7707 | if (!ospf) |
7708 | return CMD_SUCCESS; | |
7709 | ||
7710 | /* Get distribute source. */ | |
7711 | source = proto_redistnum(AFI_IP, argv[idx_protocol]->text); | |
7712 | if (source < 0) | |
7713 | return CMD_WARNING_CONFIG_FAILED; | |
7714 | ||
7715 | red = ospf_redist_add(ospf, source, 0); | |
7716 | ||
7717 | /* Get metric value. */ | |
7718 | if (argv_find(argv, argc, "(0-16777214)", &idx)) { | |
7719 | if (!str2metric(argv[idx]->arg, &metric)) | |
7720 | return CMD_WARNING_CONFIG_FAILED; | |
7721 | } | |
7722 | /* Get metric type. */ | |
7723 | else if (argv_find(argv, argc, "(1-2)", &idx)) { | |
7724 | if (!str2metric_type(argv[idx]->arg, &type)) | |
7725 | return CMD_WARNING_CONFIG_FAILED; | |
7726 | } | |
7727 | /* Get route-map */ | |
7728 | else if (argv_find(argv, argc, "WORD", &idx)) { | |
7729 | ospf_routemap_set(red, argv[idx]->arg); | |
7730 | } else | |
7731 | ospf_routemap_unset(red); | |
7c8ff89e | 7732 | |
d62a17ae | 7733 | return ospf_redistribute_set(ospf, source, 0, type, metric); |
718e3744 | 7734 | } |
7735 | ||
718e3744 | 7736 | DEFUN (no_ospf_redistribute_source, |
7737 | no_ospf_redistribute_source_cmd, | |
40d1cbfb | 7738 | "no redistribute " FRR_REDIST_STR_OSPFD " [<metric (0-16777214)|metric-type (1-2)|route-map WORD>]", |
718e3744 | 7739 | NO_STR |
d1c65c21 | 7740 | REDIST_STR |
ab0181ee | 7741 | FRR_REDIST_HELP_STR_OSPFD |
813d4307 DW |
7742 | "Metric for redistributed routes\n" |
7743 | "OSPF default metric\n" | |
7744 | "OSPF exterior metric type for redistributed routes\n" | |
7111c1a0 | 7745 | "Set OSPF External Type 1/2 metrics\n" |
813d4307 DW |
7746 | "Route map reference\n" |
7747 | "Pointer to route-map entries\n") | |
718e3744 | 7748 | { |
a3d826f0 | 7749 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 7750 | int idx_protocol = 2; |
7751 | int source; | |
7752 | struct ospf_redist *red; | |
718e3744 | 7753 | |
d62a17ae | 7754 | source = proto_redistnum(AFI_IP, argv[idx_protocol]->text); |
7755 | if (source < 0) | |
7756 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 7757 | |
d62a17ae | 7758 | red = ospf_redist_lookup(ospf, source, 0); |
7759 | if (!red) | |
7760 | return CMD_SUCCESS; | |
7c8ff89e | 7761 | |
d62a17ae | 7762 | ospf_routemap_unset(red); |
7763 | return ospf_redistribute_unset(ospf, source, 0); | |
7c8ff89e DS |
7764 | } |
7765 | ||
7766 | DEFUN (ospf_redistribute_instance_source, | |
7767 | ospf_redistribute_instance_source_cmd, | |
1a5ce38b | 7768 | "redistribute <ospf|table> (1-65535) [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]", |
7c8ff89e DS |
7769 | REDIST_STR |
7770 | "Open Shortest Path First\n" | |
2d627ff5 DS |
7771 | "Non-main Kernel Routing Table\n" |
7772 | "Instance ID/Table ID\n" | |
7c8ff89e DS |
7773 | "Metric for redistributed routes\n" |
7774 | "OSPF default metric\n" | |
7775 | "OSPF exterior metric type for redistributed routes\n" | |
7111c1a0 | 7776 | "Set OSPF External Type 1/2 metrics\n" |
7c8ff89e DS |
7777 | "Route map reference\n" |
7778 | "Pointer to route-map entries\n") | |
7779 | { | |
a3d826f0 | 7780 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 7781 | int idx_ospf_table = 1; |
7782 | int idx_number = 2; | |
7783 | int idx = 3; | |
7784 | int source; | |
7785 | int type = -1; | |
7786 | int metric = -1; | |
7787 | u_short instance; | |
7788 | struct ospf_redist *red; | |
7c8ff89e | 7789 | |
d62a17ae | 7790 | if (!ospf) |
7791 | return CMD_SUCCESS; | |
d8f70b86 | 7792 | |
d62a17ae | 7793 | source = proto_redistnum(AFI_IP, argv[idx_ospf_table]->text); |
2d627ff5 | 7794 | |
d62a17ae | 7795 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
7c8ff89e | 7796 | |
d62a17ae | 7797 | if (!ospf) |
7798 | return CMD_SUCCESS; | |
7c8ff89e | 7799 | |
d62a17ae | 7800 | if ((source == ZEBRA_ROUTE_OSPF) && !ospf->instance) { |
7801 | vty_out(vty, | |
7802 | "Instance redistribution in non-instanced OSPF not allowed\n"); | |
7803 | return CMD_WARNING_CONFIG_FAILED; | |
7804 | } | |
7c8ff89e | 7805 | |
d62a17ae | 7806 | if ((source == ZEBRA_ROUTE_OSPF) && (ospf->instance == instance)) { |
7807 | vty_out(vty, "Same instance OSPF redistribution not allowed\n"); | |
7808 | return CMD_WARNING_CONFIG_FAILED; | |
7809 | } | |
7c8ff89e | 7810 | |
d62a17ae | 7811 | /* Get metric value. */ |
7812 | if (argv_find(argv, argc, "metric", &idx)) | |
7813 | if (!str2metric(argv[idx + 1]->arg, &metric)) | |
7814 | return CMD_WARNING_CONFIG_FAILED; | |
7c8ff89e | 7815 | |
d62a17ae | 7816 | idx = 3; |
7817 | /* Get metric type. */ | |
7818 | if (argv_find(argv, argc, "metric-type", &idx)) | |
7819 | if (!str2metric_type(argv[idx + 1]->arg, &type)) | |
7820 | return CMD_WARNING_CONFIG_FAILED; | |
7c8ff89e | 7821 | |
d62a17ae | 7822 | red = ospf_redist_add(ospf, source, instance); |
7a7be519 | 7823 | |
d62a17ae | 7824 | idx = 3; |
7825 | if (argv_find(argv, argc, "route-map", &idx)) | |
7826 | ospf_routemap_set(red, argv[idx + 1]->arg); | |
7827 | else | |
7828 | ospf_routemap_unset(red); | |
7c8ff89e | 7829 | |
d62a17ae | 7830 | return ospf_redistribute_set(ospf, source, instance, type, metric); |
7c8ff89e DS |
7831 | } |
7832 | ||
7833 | DEFUN (no_ospf_redistribute_instance_source, | |
7834 | no_ospf_redistribute_instance_source_cmd, | |
1a5ce38b | 7835 | "no redistribute <ospf|table> (1-65535) [{metric (0-16777214)|metric-type (1-2)|route-map WORD}]", |
7c8ff89e DS |
7836 | NO_STR |
7837 | REDIST_STR | |
7838 | "Open Shortest Path First\n" | |
2d627ff5 DS |
7839 | "Non-main Kernel Routing Table\n" |
7840 | "Instance ID/Table Id\n" | |
7c8ff89e DS |
7841 | "Metric for redistributed routes\n" |
7842 | "OSPF default metric\n" | |
7843 | "OSPF exterior metric type for redistributed routes\n" | |
7111c1a0 | 7844 | "Set OSPF External Type 1/2 metrics\n" |
7c8ff89e DS |
7845 | "Route map reference\n" |
7846 | "Pointer to route-map entries\n") | |
7847 | { | |
a3d826f0 | 7848 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 7849 | int idx_ospf_table = 2; |
7850 | int idx_number = 3; | |
7851 | u_int instance; | |
7852 | struct ospf_redist *red; | |
7853 | int source; | |
7854 | ||
7855 | if (strncmp(argv[idx_ospf_table]->arg, "o", 1) == 0) | |
7856 | source = ZEBRA_ROUTE_OSPF; | |
7857 | else | |
7858 | source = ZEBRA_ROUTE_TABLE; | |
7859 | ||
7860 | instance = strtoul(argv[idx_number]->arg, NULL, 10); | |
7c8ff89e | 7861 | |
d62a17ae | 7862 | if ((source == ZEBRA_ROUTE_OSPF) && !ospf->instance) { |
7863 | vty_out(vty, | |
7864 | "Instance redistribution in non-instanced OSPF not allowed\n"); | |
7865 | return CMD_WARNING_CONFIG_FAILED; | |
7866 | } | |
7867 | ||
7868 | if ((source == ZEBRA_ROUTE_OSPF) && (ospf->instance == instance)) { | |
7869 | vty_out(vty, "Same instance OSPF redistribution not allowed\n"); | |
7870 | return CMD_WARNING_CONFIG_FAILED; | |
7871 | } | |
7872 | ||
7873 | red = ospf_redist_lookup(ospf, source, instance); | |
7874 | if (!red) | |
7875 | return CMD_SUCCESS; | |
7876 | ||
7877 | ospf_routemap_unset(red); | |
7878 | return ospf_redistribute_unset(ospf, source, instance); | |
718e3744 | 7879 | } |
7880 | ||
7881 | DEFUN (ospf_distribute_list_out, | |
7882 | ospf_distribute_list_out_cmd, | |
40d1cbfb | 7883 | "distribute-list WORD out " FRR_REDIST_STR_OSPFD, |
718e3744 | 7884 | "Filter networks in routing updates\n" |
6f2a6703 CF |
7885 | "Access-list name\n" |
7886 | OUT_STR | |
ab0181ee | 7887 | FRR_REDIST_HELP_STR_OSPFD) |
718e3744 | 7888 | { |
a3d826f0 | 7889 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 7890 | int idx_word = 1; |
7891 | int source; | |
718e3744 | 7892 | |
d62a17ae | 7893 | char *proto = argv[argc - 1]->text; |
6d681bd8 | 7894 | |
d62a17ae | 7895 | /* Get distribute source. */ |
7896 | source = proto_redistnum(AFI_IP, proto); | |
7897 | if (source < 0) | |
7898 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 7899 | |
d62a17ae | 7900 | return ospf_distribute_list_out_set(ospf, source, argv[idx_word]->arg); |
718e3744 | 7901 | } |
7902 | ||
6f2a6703 CF |
7903 | DEFUN (no_ospf_distribute_list_out, |
7904 | no_ospf_distribute_list_out_cmd, | |
40d1cbfb | 7905 | "no distribute-list WORD out " FRR_REDIST_STR_OSPFD, |
6f2a6703 CF |
7906 | NO_STR |
7907 | "Filter networks in routing updates\n" | |
7908 | "Access-list name\n" | |
7909 | OUT_STR | |
ab0181ee | 7910 | FRR_REDIST_HELP_STR_OSPFD) |
718e3744 | 7911 | { |
a3d826f0 | 7912 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 7913 | int idx_word = 2; |
7914 | int source; | |
020709f9 | 7915 | |
d62a17ae | 7916 | char *proto = argv[argc - 1]->text; |
7917 | source = proto_redistnum(AFI_IP, proto); | |
7918 | if (source < 0) | |
7919 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 7920 | |
d62a17ae | 7921 | return ospf_distribute_list_out_unset(ospf, source, |
7922 | argv[idx_word]->arg); | |
718e3744 | 7923 | } |
7924 | ||
6f2a6703 CF |
7925 | /* Default information originate. */ |
7926 | DEFUN (ospf_default_information_originate, | |
7927 | ospf_default_information_originate_cmd, | |
e83a9414 | 7928 | "default-information originate [<always|metric (0-16777214)|metric-type (1-2)|route-map WORD>]", |
718e3744 | 7929 | "Control distribution of default information\n" |
7930 | "Distribute a default route\n" | |
7931 | "Always advertise default route\n" | |
6f2a6703 CF |
7932 | "OSPF default metric\n" |
7933 | "OSPF metric\n" | |
718e3744 | 7934 | "OSPF metric type for default routes\n" |
7111c1a0 | 7935 | "Set OSPF External Type 1/2 metrics\n" |
718e3744 | 7936 | "Route map reference\n" |
7937 | "Pointer to route-map entries\n") | |
7938 | { | |
a3d826f0 | 7939 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 7940 | int default_originate = DEFAULT_ORIGINATE_ZEBRA; |
7941 | int type = -1; | |
7942 | int metric = -1; | |
7943 | struct ospf_redist *red; | |
7944 | int idx = 0; | |
7945 | ||
7946 | red = ospf_redist_add(ospf, DEFAULT_ROUTE, 0); | |
7947 | ||
7948 | /* Check whether "always" was specified */ | |
7949 | if (argv_find(argv, argc, "always", &idx)) | |
7950 | default_originate = DEFAULT_ORIGINATE_ALWAYS; | |
7951 | /* Get metric value */ | |
7952 | else if (argv_find(argv, argc, "(0-16777214)", &idx)) { | |
7953 | if (!str2metric(argv[idx]->arg, &metric)) | |
7954 | return CMD_WARNING_CONFIG_FAILED; | |
7955 | } | |
7956 | /* Get metric type. */ | |
7957 | else if (argv_find(argv, argc, "(1-2)", &idx)) { | |
7958 | if (!str2metric_type(argv[idx]->arg, &type)) | |
7959 | return CMD_WARNING_CONFIG_FAILED; | |
7960 | } | |
7961 | /* Get route-map */ | |
7962 | else if (argv_find(argv, argc, "WORD", &idx)) | |
7963 | ospf_routemap_set(red, argv[idx]->arg); | |
7964 | else | |
7965 | ospf_routemap_unset(red); | |
7966 | ||
7967 | return ospf_redistribute_default_set(ospf, default_originate, type, | |
7968 | metric); | |
718e3744 | 7969 | } |
7970 | ||
7971 | DEFUN (no_ospf_default_information_originate, | |
7972 | no_ospf_default_information_originate_cmd, | |
12dcf78e | 7973 | "no default-information originate [<always|metric (0-16777214)|metric-type (1-2)|route-map WORD>]", |
718e3744 | 7974 | NO_STR |
7975 | "Control distribution of default information\n" | |
813d4307 DW |
7976 | "Distribute a default route\n" |
7977 | "Always advertise default route\n" | |
7978 | "OSPF default metric\n" | |
7979 | "OSPF metric\n" | |
7980 | "OSPF metric type for default routes\n" | |
7111c1a0 | 7981 | "Set OSPF External Type 1/2 metrics\n" |
813d4307 DW |
7982 | "Route map reference\n" |
7983 | "Pointer to route-map entries\n") | |
718e3744 | 7984 | { |
a3d826f0 | 7985 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 7986 | struct prefix_ipv4 p; |
7987 | struct ospf_external *ext; | |
7988 | struct ospf_redist *red; | |
7c8ff89e | 7989 | |
d62a17ae | 7990 | p.family = AF_INET; |
7991 | p.prefix.s_addr = 0; | |
7992 | p.prefixlen = 0; | |
718e3744 | 7993 | |
d62a17ae | 7994 | ospf_external_lsa_flush(ospf, DEFAULT_ROUTE, &p, 0); |
718e3744 | 7995 | |
d62a17ae | 7996 | if ((ext = ospf_external_lookup(DEFAULT_ROUTE, 0)) |
7997 | && EXTERNAL_INFO(ext)) { | |
7998 | ospf_external_info_delete(DEFAULT_ROUTE, 0, p); | |
7999 | ospf_external_del(DEFAULT_ROUTE, 0); | |
8000 | } | |
718e3744 | 8001 | |
d62a17ae | 8002 | red = ospf_redist_lookup(ospf, DEFAULT_ROUTE, 0); |
8003 | if (!red) | |
8004 | return CMD_SUCCESS; | |
7c8ff89e | 8005 | |
d62a17ae | 8006 | ospf_routemap_unset(red); |
8007 | return ospf_redistribute_default_unset(ospf); | |
718e3744 | 8008 | } |
8009 | ||
8010 | DEFUN (ospf_default_metric, | |
8011 | ospf_default_metric_cmd, | |
6147e2c6 | 8012 | "default-metric (0-16777214)", |
718e3744 | 8013 | "Set metric of redistributed routes\n" |
8014 | "Default metric\n") | |
8015 | { | |
a3d826f0 | 8016 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 8017 | int idx_number = 1; |
8018 | int metric = -1; | |
718e3744 | 8019 | |
d62a17ae | 8020 | if (!str2metric(argv[idx_number]->arg, &metric)) |
8021 | return CMD_WARNING_CONFIG_FAILED; | |
718e3744 | 8022 | |
d62a17ae | 8023 | ospf->default_metric = metric; |
718e3744 | 8024 | |
d62a17ae | 8025 | return CMD_SUCCESS; |
718e3744 | 8026 | } |
8027 | ||
8028 | DEFUN (no_ospf_default_metric, | |
8029 | no_ospf_default_metric_cmd, | |
7a7be519 | 8030 | "no default-metric [(0-16777214)]", |
718e3744 | 8031 | NO_STR |
7a7be519 | 8032 | "Set metric of redistributed routes\n" |
8033 | "Default metric\n") | |
718e3744 | 8034 | { |
a3d826f0 | 8035 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
68980084 | 8036 | |
d62a17ae | 8037 | ospf->default_metric = -1; |
68980084 | 8038 | |
d62a17ae | 8039 | return CMD_SUCCESS; |
718e3744 | 8040 | } |
8041 | ||
718e3744 | 8042 | |
8043 | DEFUN (ospf_distance, | |
8044 | ospf_distance_cmd, | |
6147e2c6 | 8045 | "distance (1-255)", |
eaa1ae0d | 8046 | "Administrative distance\n" |
718e3744 | 8047 | "OSPF Administrative distance\n") |
8048 | { | |
a3d826f0 | 8049 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 8050 | int idx_number = 1; |
68980084 | 8051 | |
d62a17ae | 8052 | ospf->distance_all = atoi(argv[idx_number]->arg); |
68980084 | 8053 | |
d62a17ae | 8054 | return CMD_SUCCESS; |
718e3744 | 8055 | } |
8056 | ||
8057 | DEFUN (no_ospf_distance, | |
8058 | no_ospf_distance_cmd, | |
6147e2c6 | 8059 | "no distance (1-255)", |
718e3744 | 8060 | NO_STR |
eaa1ae0d | 8061 | "Administrative distance\n" |
718e3744 | 8062 | "OSPF Administrative distance\n") |
8063 | { | |
a3d826f0 | 8064 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
68980084 | 8065 | |
d62a17ae | 8066 | ospf->distance_all = 0; |
68980084 | 8067 | |
d62a17ae | 8068 | return CMD_SUCCESS; |
718e3744 | 8069 | } |
8070 | ||
8071 | DEFUN (no_ospf_distance_ospf, | |
8072 | no_ospf_distance_ospf_cmd, | |
eaa1ae0d | 8073 | "no distance ospf [{intra-area [(1-255)]|inter-area [(1-255)]|external [(1-255)]}]", |
718e3744 | 8074 | NO_STR |
eaa1ae0d QY |
8075 | "Administrative distance\n" |
8076 | "OSPF administrative distance\n" | |
718e3744 | 8077 | "Intra-area routes\n" |
813d4307 | 8078 | "Distance for intra-area routes\n" |
718e3744 | 8079 | "Inter-area routes\n" |
813d4307 DW |
8080 | "Distance for inter-area routes\n" |
8081 | "External routes\n" | |
8082 | "Distance for external routes\n") | |
718e3744 | 8083 | { |
a3d826f0 | 8084 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 8085 | int idx = 0; |
718e3744 | 8086 | |
d62a17ae | 8087 | if (!ospf) |
8088 | return CMD_SUCCESS; | |
7c8ff89e | 8089 | |
d62a17ae | 8090 | if (argv_find(argv, argc, "intra-area", &idx) || argc == 3) |
8091 | idx = ospf->distance_intra = 0; | |
8092 | if (argv_find(argv, argc, "inter-area", &idx) || argc == 3) | |
8093 | idx = ospf->distance_inter = 0; | |
8094 | if (argv_find(argv, argc, "external", &idx) || argc == 3) | |
8095 | ospf->distance_external = 0; | |
718e3744 | 8096 | |
d62a17ae | 8097 | return CMD_SUCCESS; |
718e3744 | 8098 | } |
8099 | ||
6f2a6703 CF |
8100 | DEFUN (ospf_distance_ospf, |
8101 | ospf_distance_ospf_cmd, | |
eaa1ae0d QY |
8102 | "distance ospf {intra-area (1-255)|inter-area (1-255)|external (1-255)}", |
8103 | "Administrative distance\n" | |
8104 | "OSPF administrative distance\n" | |
718e3744 | 8105 | "Intra-area routes\n" |
8106 | "Distance for intra-area routes\n" | |
718e3744 | 8107 | "Inter-area routes\n" |
8108 | "Distance for inter-area routes\n" | |
8109 | "External routes\n" | |
718e3744 | 8110 | "Distance for external routes\n") |
8111 | { | |
a3d826f0 | 8112 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 8113 | int idx = 0; |
68980084 | 8114 | |
d62a17ae | 8115 | if (argv_find(argv, argc, "intra-area", &idx)) |
8116 | ospf->distance_intra = atoi(argv[idx + 1]->arg); | |
8117 | idx = 0; | |
8118 | if (argv_find(argv, argc, "inter-area", &idx)) | |
8119 | ospf->distance_inter = atoi(argv[idx + 1]->arg); | |
8120 | idx = 0; | |
8121 | if (argv_find(argv, argc, "external", &idx)) | |
8122 | ospf->distance_external = atoi(argv[idx + 1]->arg); | |
68980084 | 8123 | |
d62a17ae | 8124 | return CMD_SUCCESS; |
718e3744 | 8125 | } |
8126 | ||
d7d73ffc | 8127 | #if 0 |
718e3744 | 8128 | DEFUN (ospf_distance_source, |
8129 | ospf_distance_source_cmd, | |
6147e2c6 | 8130 | "distance (1-255) A.B.C.D/M", |
718e3744 | 8131 | "Administrative distance\n" |
8132 | "Distance value\n" | |
8133 | "IP source prefix\n") | |
8134 | { | |
cdc2d765 | 8135 | VTY_DECLVAR_CONTEXT(ospf, ospf); |
8d769265 DW |
8136 | int idx_number = 1; |
8137 | int idx_ipv4_prefixlen = 2; | |
020709f9 | 8138 | |
7c8ff89e DS |
8139 | if (!ospf) |
8140 | return CMD_SUCCESS; | |
8141 | ||
8d769265 | 8142 | ospf_distance_set (vty, ospf, argv[idx_number]->arg, argv[idx_ipv4_prefixlen]->arg, NULL); |
68980084 | 8143 | |
718e3744 | 8144 | return CMD_SUCCESS; |
8145 | } | |
8146 | ||
8147 | DEFUN (no_ospf_distance_source, | |
8148 | no_ospf_distance_source_cmd, | |
6147e2c6 | 8149 | "no distance (1-255) A.B.C.D/M", |
718e3744 | 8150 | NO_STR |
8151 | "Administrative distance\n" | |
8152 | "Distance value\n" | |
8153 | "IP source prefix\n") | |
8154 | { | |
cdc2d765 | 8155 | VTY_DECLVAR_CONTEXT(ospf, ospf); |
8d769265 DW |
8156 | int idx_number = 2; |
8157 | int idx_ipv4_prefixlen = 3; | |
020709f9 | 8158 | |
7c8ff89e DS |
8159 | if (!ospf) |
8160 | return CMD_SUCCESS; | |
8161 | ||
8d769265 | 8162 | ospf_distance_unset (vty, ospf, argv[idx_number]->arg, argv[idx_ipv4_prefixlen]->arg, NULL); |
020709f9 | 8163 | |
718e3744 | 8164 | return CMD_SUCCESS; |
8165 | } | |
8166 | ||
8167 | DEFUN (ospf_distance_source_access_list, | |
8168 | ospf_distance_source_access_list_cmd, | |
6147e2c6 | 8169 | "distance (1-255) A.B.C.D/M WORD", |
718e3744 | 8170 | "Administrative distance\n" |
8171 | "Distance value\n" | |
8172 | "IP source prefix\n" | |
8173 | "Access list name\n") | |
8174 | { | |
cdc2d765 | 8175 | VTY_DECLVAR_CONTEXT(ospf, ospf); |
8d769265 DW |
8176 | int idx_number = 1; |
8177 | int idx_ipv4_prefixlen = 2; | |
8178 | int idx_word = 3; | |
020709f9 | 8179 | |
7c8ff89e DS |
8180 | if (!ospf) |
8181 | return CMD_SUCCESS; | |
8182 | ||
8d769265 | 8183 | ospf_distance_set (vty, ospf, argv[idx_number]->arg, argv[idx_ipv4_prefixlen]->arg, argv[idx_word]->arg); |
020709f9 | 8184 | |
718e3744 | 8185 | return CMD_SUCCESS; |
8186 | } | |
8187 | ||
8188 | DEFUN (no_ospf_distance_source_access_list, | |
8189 | no_ospf_distance_source_access_list_cmd, | |
6147e2c6 | 8190 | "no distance (1-255) A.B.C.D/M WORD", |
718e3744 | 8191 | NO_STR |
8192 | "Administrative distance\n" | |
8193 | "Distance value\n" | |
8194 | "IP source prefix\n" | |
8195 | "Access list name\n") | |
8196 | { | |
cdc2d765 | 8197 | VTY_DECLVAR_CONTEXT(ospf, ospf); |
8d769265 DW |
8198 | int idx_number = 2; |
8199 | int idx_ipv4_prefixlen = 3; | |
8200 | int idx_word = 4; | |
020709f9 | 8201 | |
7c8ff89e DS |
8202 | if (!ospf) |
8203 | return CMD_SUCCESS; | |
8204 | ||
8d769265 | 8205 | ospf_distance_unset (vty, ospf, argv[idx_number]->arg, argv[idx_ipv4_prefixlen]->arg, argv[idx_word]->arg); |
020709f9 | 8206 | |
718e3744 | 8207 | return CMD_SUCCESS; |
8208 | } | |
d7d73ffc | 8209 | #endif |
718e3744 | 8210 | |
ba682537 | 8211 | DEFUN (ip_ospf_mtu_ignore, |
8212 | ip_ospf_mtu_ignore_addr_cmd, | |
7a7be519 | 8213 | "ip ospf mtu-ignore [A.B.C.D]", |
ba682537 | 8214 | "IP Information\n" |
8215 | "OSPF interface commands\n" | |
99a522c7 | 8216 | "Disable MTU mismatch detection on this interface\n" |
efd7904e | 8217 | "Address of interface\n") |
ba682537 | 8218 | { |
d62a17ae | 8219 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8220 | int idx_ipv4 = 3; | |
8221 | struct in_addr addr; | |
8222 | int ret; | |
8223 | ||
8224 | struct ospf_if_params *params; | |
8225 | params = IF_DEF_PARAMS(ifp); | |
8226 | ||
8227 | if (argc == 4) { | |
8228 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
8229 | if (!ret) { | |
8230 | vty_out(vty, | |
8231 | "Please specify interface address by A.B.C.D\n"); | |
8232 | return CMD_WARNING_CONFIG_FAILED; | |
8233 | } | |
8234 | params = ospf_get_if_params(ifp, addr); | |
8235 | ospf_if_update_params(ifp, addr); | |
8236 | } | |
8237 | params->mtu_ignore = 1; | |
8238 | if (params->mtu_ignore != OSPF_MTU_IGNORE_DEFAULT) | |
8239 | SET_IF_PARAM(params, mtu_ignore); | |
8240 | else { | |
8241 | UNSET_IF_PARAM(params, mtu_ignore); | |
8242 | if (params != IF_DEF_PARAMS(ifp)) { | |
8243 | ospf_free_if_params(ifp, addr); | |
8244 | ospf_if_update_params(ifp, addr); | |
8245 | } | |
8246 | } | |
8247 | return CMD_SUCCESS; | |
ba682537 | 8248 | } |
8249 | ||
ba682537 | 8250 | DEFUN (no_ip_ospf_mtu_ignore, |
8251 | no_ip_ospf_mtu_ignore_addr_cmd, | |
7a7be519 | 8252 | "no ip ospf mtu-ignore [A.B.C.D]", |
efd7904e | 8253 | NO_STR |
ba682537 | 8254 | "IP Information\n" |
8255 | "OSPF interface commands\n" | |
99a522c7 | 8256 | "Disable MTU mismatch detection on this interface\n" |
efd7904e | 8257 | "Address of interface\n") |
ba682537 | 8258 | { |
d62a17ae | 8259 | VTY_DECLVAR_CONTEXT(interface, ifp); |
8260 | int idx_ipv4 = 4; | |
8261 | struct in_addr addr; | |
8262 | int ret; | |
8263 | ||
8264 | struct ospf_if_params *params; | |
8265 | params = IF_DEF_PARAMS(ifp); | |
8266 | ||
8267 | if (argc == 5) { | |
8268 | ret = inet_aton(argv[idx_ipv4]->arg, &addr); | |
8269 | if (!ret) { | |
8270 | vty_out(vty, | |
8271 | "Please specify interface address by A.B.C.D\n"); | |
8272 | return CMD_WARNING_CONFIG_FAILED; | |
8273 | } | |
8274 | params = ospf_get_if_params(ifp, addr); | |
8275 | ospf_if_update_params(ifp, addr); | |
8276 | } | |
8277 | params->mtu_ignore = 0; | |
8278 | if (params->mtu_ignore != OSPF_MTU_IGNORE_DEFAULT) | |
8279 | SET_IF_PARAM(params, mtu_ignore); | |
8280 | else { | |
8281 | UNSET_IF_PARAM(params, mtu_ignore); | |
8282 | if (params != IF_DEF_PARAMS(ifp)) { | |
8283 | ospf_free_if_params(ifp, addr); | |
8284 | ospf_if_update_params(ifp, addr); | |
8285 | } | |
8286 | } | |
8287 | return CMD_SUCCESS; | |
ba682537 | 8288 | } |
8289 | ||
6b0655a2 | 8290 | |
88d6cf37 | 8291 | DEFUN (ospf_max_metric_router_lsa_admin, |
8292 | ospf_max_metric_router_lsa_admin_cmd, | |
8293 | "max-metric router-lsa administrative", | |
8294 | "OSPF maximum / infinite-distance metric\n" | |
8295 | "Advertise own Router-LSA with infinite distance (stub router)\n" | |
8296 | "Administratively applied, for an indefinite period\n") | |
8297 | { | |
a3d826f0 | 8298 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 8299 | struct listnode *ln; |
8300 | struct ospf_area *area; | |
7c8ff89e | 8301 | |
d62a17ae | 8302 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, ln, area)) { |
8303 | SET_FLAG(area->stub_router_state, OSPF_AREA_ADMIN_STUB_ROUTED); | |
4ba4fc85 | 8304 | |
d62a17ae | 8305 | if (!CHECK_FLAG(area->stub_router_state, |
8306 | OSPF_AREA_IS_STUB_ROUTED)) | |
8307 | ospf_router_lsa_update_area(area); | |
8308 | } | |
4ba4fc85 | 8309 | |
d62a17ae | 8310 | /* Allows for areas configured later to get the property */ |
8311 | ospf->stub_router_admin_set = OSPF_STUB_ROUTER_ADMINISTRATIVE_SET; | |
8312 | ||
8313 | return CMD_SUCCESS; | |
88d6cf37 | 8314 | } |
8315 | ||
8316 | DEFUN (no_ospf_max_metric_router_lsa_admin, | |
8317 | no_ospf_max_metric_router_lsa_admin_cmd, | |
8318 | "no max-metric router-lsa administrative", | |
8319 | NO_STR | |
8320 | "OSPF maximum / infinite-distance metric\n" | |
8321 | "Advertise own Router-LSA with infinite distance (stub router)\n" | |
8322 | "Administratively applied, for an indefinite period\n") | |
8323 | { | |
a3d826f0 | 8324 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 8325 | struct listnode *ln; |
8326 | struct ospf_area *area; | |
8327 | ||
8328 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, ln, area)) { | |
8329 | UNSET_FLAG(area->stub_router_state, | |
8330 | OSPF_AREA_ADMIN_STUB_ROUTED); | |
8331 | ||
8332 | /* Don't trample on the start-up stub timer */ | |
8333 | if (CHECK_FLAG(area->stub_router_state, | |
8334 | OSPF_AREA_IS_STUB_ROUTED) | |
8335 | && !area->t_stub_router) { | |
8336 | UNSET_FLAG(area->stub_router_state, | |
8337 | OSPF_AREA_IS_STUB_ROUTED); | |
8338 | ospf_router_lsa_update_area(area); | |
8339 | } | |
8340 | } | |
8341 | ospf->stub_router_admin_set = OSPF_STUB_ROUTER_ADMINISTRATIVE_UNSET; | |
8342 | return CMD_SUCCESS; | |
88d6cf37 | 8343 | } |
8344 | ||
8345 | DEFUN (ospf_max_metric_router_lsa_startup, | |
8346 | ospf_max_metric_router_lsa_startup_cmd, | |
6147e2c6 | 8347 | "max-metric router-lsa on-startup (5-86400)", |
88d6cf37 | 8348 | "OSPF maximum / infinite-distance metric\n" |
8349 | "Advertise own Router-LSA with infinite distance (stub router)\n" | |
8350 | "Automatically advertise stub Router-LSA on startup of OSPF\n" | |
8351 | "Time (seconds) to advertise self as stub-router\n") | |
8352 | { | |
a3d826f0 | 8353 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 8354 | int idx_number = 3; |
8355 | unsigned int seconds; | |
8356 | ||
b5a8894d | 8357 | if (argc < 4) { |
d62a17ae | 8358 | vty_out(vty, "%% Must supply stub-router period"); |
8359 | return CMD_WARNING_CONFIG_FAILED; | |
8360 | } | |
8361 | ||
8362 | seconds = strtoul(argv[idx_number]->arg, NULL, 10); | |
8363 | ||
8364 | ospf->stub_router_startup_time = seconds; | |
8365 | ||
8366 | return CMD_SUCCESS; | |
88d6cf37 | 8367 | } |
8368 | ||
8369 | DEFUN (no_ospf_max_metric_router_lsa_startup, | |
8370 | no_ospf_max_metric_router_lsa_startup_cmd, | |
7a7be519 | 8371 | "no max-metric router-lsa on-startup [(5-86400)]", |
88d6cf37 | 8372 | NO_STR |
8373 | "OSPF maximum / infinite-distance metric\n" | |
8374 | "Advertise own Router-LSA with infinite distance (stub router)\n" | |
813d4307 DW |
8375 | "Automatically advertise stub Router-LSA on startup of OSPF\n" |
8376 | "Time (seconds) to advertise self as stub-router\n") | |
88d6cf37 | 8377 | { |
a3d826f0 | 8378 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 8379 | struct listnode *ln; |
8380 | struct ospf_area *area; | |
8381 | ||
8382 | ospf->stub_router_startup_time = OSPF_STUB_ROUTER_UNCONFIGURED; | |
8383 | ||
8384 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, ln, area)) { | |
8385 | SET_FLAG(area->stub_router_state, | |
8386 | OSPF_AREA_WAS_START_STUB_ROUTED); | |
8387 | OSPF_TIMER_OFF(area->t_stub_router); | |
8388 | ||
8389 | /* Don't trample on admin stub routed */ | |
8390 | if (!CHECK_FLAG(area->stub_router_state, | |
8391 | OSPF_AREA_ADMIN_STUB_ROUTED)) { | |
8392 | UNSET_FLAG(area->stub_router_state, | |
8393 | OSPF_AREA_IS_STUB_ROUTED); | |
8394 | ospf_router_lsa_update_area(area); | |
8395 | } | |
8396 | } | |
8397 | return CMD_SUCCESS; | |
88d6cf37 | 8398 | } |
8399 | ||
a1afa410 | 8400 | |
88d6cf37 | 8401 | DEFUN (ospf_max_metric_router_lsa_shutdown, |
8402 | ospf_max_metric_router_lsa_shutdown_cmd, | |
6147e2c6 | 8403 | "max-metric router-lsa on-shutdown (5-100)", |
88d6cf37 | 8404 | "OSPF maximum / infinite-distance metric\n" |
8405 | "Advertise own Router-LSA with infinite distance (stub router)\n" | |
8406 | "Advertise stub-router prior to full shutdown of OSPF\n" | |
8407 | "Time (seconds) to wait till full shutdown\n") | |
8408 | { | |
a3d826f0 | 8409 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
d62a17ae | 8410 | int idx_number = 3; |
8411 | unsigned int seconds; | |
8412 | ||
b5a8894d | 8413 | if (argc < 4) { |
d62a17ae | 8414 | vty_out(vty, "%% Must supply stub-router shutdown period"); |
8415 | return CMD_WARNING_CONFIG_FAILED; | |
8416 | } | |
8417 | ||
8418 | seconds = strtoul(argv[idx_number]->arg, NULL, 10); | |
8419 | ||
8420 | ospf->stub_router_shutdown_time = seconds; | |
8421 | ||
8422 | return CMD_SUCCESS; | |
88d6cf37 | 8423 | } |
8424 | ||
8425 | DEFUN (no_ospf_max_metric_router_lsa_shutdown, | |
8426 | no_ospf_max_metric_router_lsa_shutdown_cmd, | |
7a7be519 | 8427 | "no max-metric router-lsa on-shutdown [(5-100)]", |
88d6cf37 | 8428 | NO_STR |
8429 | "OSPF maximum / infinite-distance metric\n" | |
8430 | "Advertise own Router-LSA with infinite distance (stub router)\n" | |
813d4307 DW |
8431 | "Advertise stub-router prior to full shutdown of OSPF\n" |
8432 | "Time (seconds) to wait till full shutdown\n") | |
88d6cf37 | 8433 | { |
a3d826f0 | 8434 | VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); |
7c8ff89e | 8435 | |
d62a17ae | 8436 | ospf->stub_router_shutdown_time = OSPF_STUB_ROUTER_UNCONFIGURED; |
8437 | ||
8438 | return CMD_SUCCESS; | |
88d6cf37 | 8439 | } |
8440 | ||
d62a17ae | 8441 | static void config_write_stub_router(struct vty *vty, struct ospf *ospf) |
8442 | { | |
8443 | struct listnode *ln; | |
8444 | struct ospf_area *area; | |
8445 | ||
8446 | if (ospf->stub_router_startup_time != OSPF_STUB_ROUTER_UNCONFIGURED) | |
8447 | vty_out(vty, " max-metric router-lsa on-startup %u\n", | |
8448 | ospf->stub_router_startup_time); | |
8449 | if (ospf->stub_router_shutdown_time != OSPF_STUB_ROUTER_UNCONFIGURED) | |
8450 | vty_out(vty, " max-metric router-lsa on-shutdown %u\n", | |
8451 | ospf->stub_router_shutdown_time); | |
8452 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, ln, area)) { | |
8453 | if (CHECK_FLAG(area->stub_router_state, | |
8454 | OSPF_AREA_ADMIN_STUB_ROUTED)) { | |
8455 | vty_out(vty, " max-metric router-lsa administrative\n"); | |
8456 | break; | |
8457 | } | |
8458 | } | |
8459 | return; | |
8460 | } | |
8461 | ||
b5a8894d CS |
8462 | static void show_ip_ospf_route_network(struct vty *vty, struct ospf *ospf, |
8463 | struct route_table *rt) | |
d62a17ae | 8464 | { |
8465 | struct route_node *rn; | |
8466 | struct ospf_route * or ; | |
8467 | struct listnode *pnode, *pnnode; | |
8468 | struct ospf_path *path; | |
8469 | ||
8470 | vty_out(vty, "============ OSPF network routing table ============\n"); | |
8471 | ||
8472 | for (rn = route_top(rt); rn; rn = route_next(rn)) | |
8473 | if ((or = rn->info) != NULL) { | |
8474 | char buf1[19]; | |
8475 | snprintf(buf1, 19, "%s/%d", inet_ntoa(rn->p.u.prefix4), | |
8476 | rn->p.prefixlen); | |
8477 | ||
8478 | switch (or->path_type) { | |
8479 | case OSPF_PATH_INTER_AREA: | |
8480 | if (or->type == OSPF_DESTINATION_NETWORK) | |
8481 | vty_out(vty, | |
8482 | "N IA %-18s [%d] area: %s\n", | |
8483 | buf1, or->cost, | |
8484 | inet_ntoa(or->u.std.area_id)); | |
8485 | else if (or->type == OSPF_DESTINATION_DISCARD) | |
8486 | vty_out(vty, | |
8487 | "D IA %-18s Discard entry\n", | |
8488 | buf1); | |
8489 | break; | |
8490 | case OSPF_PATH_INTRA_AREA: | |
8491 | vty_out(vty, "N %-18s [%d] area: %s\n", | |
8492 | buf1, or->cost, | |
8493 | inet_ntoa(or->u.std.area_id)); | |
8494 | break; | |
8495 | default: | |
8496 | break; | |
8497 | } | |
8498 | ||
8499 | if (or->type == OSPF_DESTINATION_NETWORK) | |
8500 | for (ALL_LIST_ELEMENTS(or->paths, pnode, pnnode, | |
8501 | path)) { | |
8502 | if (if_lookup_by_index(path->ifindex, | |
b5a8894d | 8503 | ospf->vrf_id)) { |
d62a17ae | 8504 | if (path->nexthop.s_addr == 0) |
8505 | vty_out(vty, | |
8506 | "%24s directly attached to %s\n", | |
8507 | "", | |
8508 | ifindex2ifname( | |
8509 | path->ifindex, | |
b5a8894d | 8510 | ospf->vrf_id)); |
d62a17ae | 8511 | else |
8512 | vty_out(vty, | |
8513 | "%24s via %s, %s\n", | |
8514 | "", | |
8515 | inet_ntoa( | |
8516 | path->nexthop), | |
8517 | ifindex2ifname( | |
8518 | path->ifindex, | |
b5a8894d | 8519 | ospf->vrf_id)); |
d62a17ae | 8520 | } |
8521 | } | |
8522 | } | |
8523 | vty_out(vty, "\n"); | |
8524 | } | |
8525 | ||
b5a8894d CS |
8526 | static void show_ip_ospf_route_router(struct vty *vty, struct ospf *ospf, |
8527 | struct route_table *rtrs) | |
d62a17ae | 8528 | { |
8529 | struct route_node *rn; | |
8530 | struct ospf_route * or ; | |
8531 | struct listnode *pnode; | |
8532 | struct listnode *node; | |
8533 | struct ospf_path *path; | |
8534 | ||
c0f3f7cd | 8535 | vty_out(vty, "============ OSPF router routing table =============\n"); |
d62a17ae | 8536 | for (rn = route_top(rtrs); rn; rn = route_next(rn)) |
8537 | if (rn->info) { | |
8538 | int flag = 0; | |
8539 | ||
8540 | vty_out(vty, "R %-15s ", | |
8541 | inet_ntoa(rn->p.u.prefix4)); | |
8542 | ||
8543 | for (ALL_LIST_ELEMENTS_RO((struct list *)rn->info, node, | |
8544 | or)) { | |
8545 | if (flag++) | |
8546 | vty_out(vty, "%24s", ""); | |
8547 | ||
8548 | /* Show path. */ | |
8549 | vty_out(vty, "%s [%d] area: %s", | |
8550 | (or->path_type == OSPF_PATH_INTER_AREA | |
8551 | ? "IA" | |
8552 | : " "), | |
8553 | or->cost, inet_ntoa(or->u.std.area_id)); | |
8554 | /* Show flags. */ | |
8555 | vty_out(vty, "%s%s\n", | |
8556 | (or->u.std.flags & ROUTER_LSA_BORDER | |
8557 | ? ", ABR" | |
8558 | : ""), | |
8559 | (or->u.std.flags & ROUTER_LSA_EXTERNAL | |
8560 | ? ", ASBR" | |
8561 | : "")); | |
8562 | ||
8563 | for (ALL_LIST_ELEMENTS_RO(or->paths, pnode, | |
8564 | path)) { | |
8565 | if (if_lookup_by_index(path->ifindex, | |
b5a8894d | 8566 | ospf->vrf_id)) { |
d62a17ae | 8567 | if (path->nexthop.s_addr == 0) |
8568 | vty_out(vty, | |
8569 | "%24s directly attached to %s\n", | |
8570 | "", | |
8571 | ifindex2ifname( | |
8572 | path->ifindex, | |
b5a8894d | 8573 | ospf->vrf_id)); |
d62a17ae | 8574 | else |
8575 | vty_out(vty, | |
8576 | "%24s via %s, %s\n", | |
8577 | "", | |
8578 | inet_ntoa( | |
8579 | path->nexthop), | |
8580 | ifindex2ifname( | |
8581 | path->ifindex, | |
b5a8894d | 8582 | ospf->vrf_id)); |
d62a17ae | 8583 | } |
8584 | } | |
8585 | } | |
8586 | } | |
8587 | vty_out(vty, "\n"); | |
8588 | } | |
8589 | ||
b5a8894d CS |
8590 | static void show_ip_ospf_route_external(struct vty *vty, struct ospf *ospf, |
8591 | struct route_table *rt) | |
d62a17ae | 8592 | { |
8593 | struct route_node *rn; | |
8594 | struct ospf_route *er; | |
8595 | struct listnode *pnode, *pnnode; | |
8596 | struct ospf_path *path; | |
8597 | ||
8598 | vty_out(vty, "============ OSPF external routing table ===========\n"); | |
8599 | for (rn = route_top(rt); rn; rn = route_next(rn)) | |
8600 | if ((er = rn->info) != NULL) { | |
8601 | char buf1[19]; | |
8602 | snprintf(buf1, 19, "%s/%d", inet_ntoa(rn->p.u.prefix4), | |
8603 | rn->p.prefixlen); | |
8604 | ||
8605 | switch (er->path_type) { | |
8606 | case OSPF_PATH_TYPE1_EXTERNAL: | |
8607 | vty_out(vty, | |
8608 | "N E1 %-18s [%d] tag: %" ROUTE_TAG_PRI | |
8609 | "\n", | |
8610 | buf1, er->cost, er->u.ext.tag); | |
8611 | break; | |
8612 | case OSPF_PATH_TYPE2_EXTERNAL: | |
8613 | vty_out(vty, | |
8614 | "N E2 %-18s [%d/%d] tag: %" ROUTE_TAG_PRI | |
8615 | "\n", | |
8616 | buf1, er->cost, er->u.ext.type2_cost, | |
8617 | er->u.ext.tag); | |
8618 | break; | |
8619 | } | |
8620 | ||
8621 | for (ALL_LIST_ELEMENTS(er->paths, pnode, pnnode, | |
8622 | path)) { | |
8623 | if (if_lookup_by_index(path->ifindex, | |
b5a8894d | 8624 | ospf->vrf_id)) { |
d62a17ae | 8625 | if (path->nexthop.s_addr == 0) |
8626 | vty_out(vty, | |
8627 | "%24s directly attached to %s\n", | |
8628 | "", | |
8629 | ifindex2ifname( | |
8630 | path->ifindex, | |
b5a8894d | 8631 | ospf->vrf_id)); |
d62a17ae | 8632 | else |
8633 | vty_out(vty, | |
8634 | "%24s via %s, %s\n", | |
8635 | "", | |
8636 | inet_ntoa( | |
8637 | path->nexthop), | |
8638 | ifindex2ifname( | |
8639 | path->ifindex, | |
b5a8894d | 8640 | ospf->vrf_id)); |
d62a17ae | 8641 | } |
54bedb55 | 8642 | } |
d62a17ae | 8643 | } |
8644 | vty_out(vty, "\n"); | |
718e3744 | 8645 | } |
8646 | ||
d62a17ae | 8647 | static int show_ip_ospf_border_routers_common(struct vty *vty, |
8648 | struct ospf *ospf) | |
718e3744 | 8649 | { |
d62a17ae | 8650 | if (ospf->instance) |
8651 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
718e3744 | 8652 | |
52d0c099 | 8653 | ospf_show_vrf_name(ospf, vty, NULL); |
87bd50e8 | 8654 | |
d62a17ae | 8655 | if (ospf->new_table == NULL) { |
8656 | vty_out(vty, "No OSPF routing information exist\n"); | |
8657 | return CMD_SUCCESS; | |
8658 | } | |
718e3744 | 8659 | |
d62a17ae | 8660 | /* Show Network routes. |
8661 | show_ip_ospf_route_network (vty, ospf->new_table); */ | |
718e3744 | 8662 | |
d62a17ae | 8663 | /* Show Router routes. */ |
b5a8894d | 8664 | show_ip_ospf_route_router(vty, ospf, ospf->new_rtrs); |
718e3744 | 8665 | |
d62a17ae | 8666 | vty_out(vty, "\n"); |
7c8ff89e | 8667 | |
d62a17ae | 8668 | return CMD_SUCCESS; |
718e3744 | 8669 | } |
718e3744 | 8670 | |
7c8ff89e DS |
8671 | DEFUN (show_ip_ospf_border_routers, |
8672 | show_ip_ospf_border_routers_cmd, | |
b5a8894d | 8673 | "show ip ospf [vrf <NAME|all>] border-routers", |
718e3744 | 8674 | SHOW_STR |
8675 | IP_STR | |
8676 | "OSPF information\n" | |
b5a8894d CS |
8677 | VRF_CMD_HELP_STR |
8678 | "All VRFs\n" | |
7c8ff89e | 8679 | "Show all the ABR's and ASBR's\n") |
718e3744 | 8680 | { |
b5a8894d CS |
8681 | struct ospf *ospf = NULL; |
8682 | struct listnode *node = NULL; | |
8683 | char *vrf_name = NULL; | |
8684 | bool all_vrf = FALSE; | |
8685 | int ret = CMD_SUCCESS; | |
8686 | int inst = 0; | |
8687 | int idx_vrf = 0; | |
68980084 | 8688 | |
43b8d1d8 | 8689 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
7c8ff89e | 8690 | |
b5a8894d CS |
8691 | if (vrf_name) { |
8692 | if (all_vrf) { | |
8693 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
8694 | if (!ospf->oi_running) | |
8695 | continue; | |
b5a8894d CS |
8696 | |
8697 | ret = show_ip_ospf_border_routers_common(vty, | |
8698 | ospf); | |
8699 | } | |
8700 | } else { | |
8701 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
8702 | if (ospf == NULL || !ospf->oi_running) | |
8703 | return CMD_SUCCESS; | |
8704 | ||
b5a8894d CS |
8705 | ret = show_ip_ospf_border_routers_common(vty, ospf); |
8706 | } | |
8707 | } else { | |
8708 | /* Display default ospf (instance 0) info */ | |
8709 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
8710 | if (ospf == NULL || !ospf->oi_running) | |
8711 | return CMD_SUCCESS; | |
b5a8894d CS |
8712 | ret = show_ip_ospf_border_routers_common(vty, ospf); |
8713 | } | |
8714 | ||
8715 | return ret; | |
7c8ff89e DS |
8716 | } |
8717 | ||
8718 | DEFUN (show_ip_ospf_instance_border_routers, | |
8719 | show_ip_ospf_instance_border_routers_cmd, | |
6147e2c6 | 8720 | "show ip ospf (1-65535) border-routers", |
7c8ff89e DS |
8721 | SHOW_STR |
8722 | IP_STR | |
8723 | "OSPF information\n" | |
8724 | "Instance ID\n" | |
8725 | "Show all the ABR's and ASBR's\n") | |
8726 | { | |
d62a17ae | 8727 | int idx_number = 3; |
8728 | struct ospf *ospf; | |
8729 | u_short instance = 0; | |
7c8ff89e | 8730 | |
d62a17ae | 8731 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
ac28e4ec CS |
8732 | ospf = ospf_lookup_instance(instance); |
8733 | if (ospf == NULL) | |
8734 | return CMD_NOT_MY_INSTANCE; | |
8735 | ||
8736 | if (!ospf->oi_running) | |
d62a17ae | 8737 | return CMD_SUCCESS; |
7c8ff89e | 8738 | |
d62a17ae | 8739 | return show_ip_ospf_border_routers_common(vty, ospf); |
7c8ff89e DS |
8740 | } |
8741 | ||
d62a17ae | 8742 | static int show_ip_ospf_route_common(struct vty *vty, struct ospf *ospf) |
7c8ff89e | 8743 | { |
d62a17ae | 8744 | if (ospf->instance) |
8745 | vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); | |
718e3744 | 8746 | |
52d0c099 | 8747 | ospf_show_vrf_name(ospf, vty, NULL); |
87bd50e8 | 8748 | |
d62a17ae | 8749 | if (ospf->new_table == NULL) { |
8750 | vty_out(vty, "No OSPF routing information exist\n"); | |
8751 | return CMD_SUCCESS; | |
8752 | } | |
718e3744 | 8753 | |
d62a17ae | 8754 | /* Show Network routes. */ |
b5a8894d | 8755 | show_ip_ospf_route_network(vty, ospf, ospf->new_table); |
718e3744 | 8756 | |
d62a17ae | 8757 | /* Show Router routes. */ |
b5a8894d | 8758 | show_ip_ospf_route_router(vty, ospf, ospf->new_rtrs); |
718e3744 | 8759 | |
d62a17ae | 8760 | /* Show AS External routes. */ |
b5a8894d | 8761 | show_ip_ospf_route_external(vty, ospf, ospf->old_external_route); |
718e3744 | 8762 | |
d62a17ae | 8763 | vty_out(vty, "\n"); |
7c8ff89e | 8764 | |
d62a17ae | 8765 | return CMD_SUCCESS; |
718e3744 | 8766 | } |
8767 | ||
7c8ff89e DS |
8768 | DEFUN (show_ip_ospf_route, |
8769 | show_ip_ospf_route_cmd, | |
b5a8894d CS |
8770 | "show ip ospf [vrf <NAME|all>] route", |
8771 | SHOW_STR | |
8772 | IP_STR | |
8773 | "OSPF information\n" | |
8774 | VRF_CMD_HELP_STR | |
8775 | "All VRFs\n" | |
8776 | "OSPF routing table\n") | |
8777 | { | |
8778 | struct ospf *ospf = NULL; | |
8779 | struct listnode *node = NULL; | |
8780 | char *vrf_name = NULL; | |
8781 | bool all_vrf = FALSE; | |
8782 | int ret = CMD_SUCCESS; | |
8783 | int inst = 0; | |
8784 | int idx_vrf = 0; | |
7c8ff89e | 8785 | |
43b8d1d8 | 8786 | OSPF_FIND_VRF_ARGS(argv, argc, idx_vrf, vrf_name, all_vrf); |
7c8ff89e | 8787 | |
b5a8894d CS |
8788 | /* vrf input is provided could be all or specific vrf*/ |
8789 | if (vrf_name) { | |
8790 | if (all_vrf) { | |
8791 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
8792 | if (!ospf->oi_running) | |
8793 | continue; | |
8794 | ret = show_ip_ospf_route_common(vty, ospf); | |
8795 | } | |
8796 | return ret; | |
8797 | } | |
8798 | ospf = ospf_lookup_by_inst_name(inst, vrf_name); | |
8799 | if (ospf == NULL || !ospf->oi_running) | |
8800 | return CMD_SUCCESS; | |
8801 | } else { | |
8802 | /* Display default ospf (instance 0) info */ | |
8803 | ospf = ospf_lookup_by_vrf_id(VRF_DEFAULT); | |
8804 | if (ospf == NULL || !ospf->oi_running) | |
8805 | return CMD_SUCCESS; | |
8806 | } | |
8807 | ||
8808 | if (ospf) | |
8809 | ret = show_ip_ospf_route_common(vty, ospf); | |
8810 | ||
8811 | return ret; | |
7c8ff89e DS |
8812 | } |
8813 | ||
8814 | DEFUN (show_ip_ospf_instance_route, | |
8815 | show_ip_ospf_instance_route_cmd, | |
6147e2c6 | 8816 | "show ip ospf (1-65535) route", |
7c8ff89e DS |
8817 | SHOW_STR |
8818 | IP_STR | |
8819 | "OSPF information\n" | |
8820 | "Instance ID\n" | |
8821 | "OSPF routing table\n") | |
8822 | { | |
d62a17ae | 8823 | int idx_number = 3; |
8824 | struct ospf *ospf; | |
8825 | u_short instance = 0; | |
7c8ff89e | 8826 | |
d62a17ae | 8827 | instance = strtoul(argv[idx_number]->arg, NULL, 10); |
ac28e4ec CS |
8828 | ospf = ospf_lookup_instance(instance); |
8829 | if (ospf == NULL) | |
8830 | return CMD_NOT_MY_INSTANCE; | |
8831 | ||
8832 | if (!ospf->oi_running) | |
d62a17ae | 8833 | return CMD_SUCCESS; |
7c8ff89e | 8834 | |
d62a17ae | 8835 | return show_ip_ospf_route_common(vty, ospf); |
7c8ff89e | 8836 | } |
6b0655a2 | 8837 | |
b5a8894d CS |
8838 | |
8839 | DEFUN (show_ip_ospf_vrfs, | |
8840 | show_ip_ospf_vrfs_cmd, | |
8841 | "show ip ospf vrfs [json]", | |
8842 | SHOW_STR | |
8843 | IP_STR | |
8844 | "OSPF information\n" | |
8845 | "Show OSPF VRFs \n" | |
8846 | JSON_STR) | |
8847 | { | |
8848 | u_char uj = use_json(argc, argv); | |
8849 | json_object *json = NULL; | |
8850 | json_object *json_vrfs = NULL; | |
8851 | struct ospf *ospf = NULL; | |
8852 | struct listnode *node = NULL; | |
8853 | int count = 0; | |
8854 | static char header[] = "Name Id RouterId "; | |
8855 | ||
8856 | if (uj) { | |
8857 | json = json_object_new_object(); | |
8858 | json_vrfs = json_object_new_object(); | |
8859 | } | |
8860 | ||
8861 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { | |
8862 | json_object *json_vrf = NULL; | |
8863 | const char *name = NULL; | |
8864 | int vrf_id_ui = 0; | |
8865 | ||
8866 | count++; | |
8867 | ||
8868 | if (!uj && count == 1) | |
8869 | vty_out(vty, "%s\n", header); | |
8870 | if (uj) | |
8871 | json_vrf = json_object_new_object(); | |
8872 | ||
8873 | if (ospf->vrf_id == 0) | |
8874 | name = VRF_DEFAULT_NAME; | |
8875 | else | |
8876 | name = ospf->name; | |
8877 | ||
8878 | vrf_id_ui = (ospf->vrf_id == VRF_UNKNOWN) ? -1 : ospf->vrf_id; | |
8879 | ||
8880 | if (uj) { | |
8881 | json_object_int_add(json_vrf, "vrfId", vrf_id_ui); | |
8882 | json_object_string_add(json_vrf, "routerId", | |
8883 | inet_ntoa(ospf->router_id)); | |
8884 | ||
8885 | json_object_object_add(json_vrfs, name, json_vrf); | |
8886 | ||
8887 | } else { | |
8888 | vty_out(vty, "%-25s %-5d %-16s \n", | |
8889 | name, ospf->vrf_id, inet_ntoa(ospf->router_id)); | |
8890 | } | |
8891 | } | |
8892 | ||
8893 | if (uj) { | |
8894 | json_object_object_add(json, "vrfs", json_vrfs); | |
8895 | json_object_int_add(json, "totalVrfs", count); | |
8896 | ||
8897 | vty_out(vty, "%s\n", json_object_to_json_string_ext(json, | |
8898 | JSON_C_TO_STRING_PRETTY)); | |
8899 | json_object_free(json); | |
8900 | } else { | |
8901 | if (count) | |
8902 | vty_out(vty, "\nTotal number of OSPF VRFs (including default): %d\n", | |
8903 | count); | |
8904 | } | |
8905 | ||
8906 | return CMD_SUCCESS; | |
8907 | } | |
8908 | ||
d62a17ae | 8909 | const char *ospf_abr_type_str[] = {"unknown", "standard", "ibm", "cisco", |
8910 | "shortcut"}; | |
718e3744 | 8911 | |
d62a17ae | 8912 | const char *ospf_shortcut_mode_str[] = {"default", "enable", "disable"}; |
718e3744 | 8913 | |
d62a17ae | 8914 | const char *ospf_int_type_str[] = {"unknown", /* should never be used. */ |
8915 | "point-to-point", "broadcast", | |
8916 | "non-broadcast", "point-to-multipoint", | |
8917 | "virtual-link", /* should never be used. */ | |
8918 | "loopback"}; | |
718e3744 | 8919 | |
43b8d1d8 | 8920 | static int config_write_interface_one(struct vty *vty, struct ospf *ospf) |
d62a17ae | 8921 | { |
f4e14fdb RW |
8922 | struct vrf *vrf = vrf_lookup_by_id(ospf->vrf_id); |
8923 | struct listnode *node; | |
d62a17ae | 8924 | struct interface *ifp; |
8925 | struct crypt_key *ck; | |
d62a17ae | 8926 | struct route_node *rn = NULL; |
8927 | struct ospf_if_params *params; | |
43b8d1d8 | 8928 | int write = 0; |
d62a17ae | 8929 | |
451fda4f | 8930 | FOR_ALL_INTERFACES (vrf, ifp) { |
35955c14 CS |
8931 | struct vrf *vrf = NULL; |
8932 | ||
43b8d1d8 CS |
8933 | if (memcmp(ifp->name, "VLINK", 5) == 0) |
8934 | continue; | |
d62a17ae | 8935 | |
35955c14 CS |
8936 | vrf = vrf_lookup_by_id(ifp->vrf_id); |
8937 | ||
43b8d1d8 | 8938 | vty_frame(vty, "!\n"); |
35955c14 CS |
8939 | if (ifp->vrf_id == VRF_DEFAULT || vrf == NULL) |
8940 | vty_frame(vty, "interface %s\n", ifp->name); | |
8941 | else | |
8942 | vty_frame(vty, "interface %s vrf %s\n", | |
8943 | ifp->name, vrf->name); | |
43b8d1d8 CS |
8944 | if (ifp->desc) |
8945 | vty_out(vty, " description %s\n", ifp->desc); | |
d62a17ae | 8946 | |
43b8d1d8 CS |
8947 | write++; |
8948 | ||
8949 | params = IF_DEF_PARAMS(ifp); | |
8950 | ||
8951 | do { | |
8952 | /* Interface Network print. */ | |
8953 | if (OSPF_IF_PARAM_CONFIGURED(params, type) | |
8954 | && params->type != OSPF_IFTYPE_LOOPBACK) { | |
8955 | if (params->type != ospf_default_iftype(ifp)) { | |
8956 | vty_out(vty, " ip ospf network %s", | |
8957 | ospf_int_type_str | |
8958 | [params->type]); | |
8959 | if (params != IF_DEF_PARAMS(ifp)) | |
8960 | vty_out(vty, " %s", | |
d62a17ae | 8961 | inet_ntoa( |
43b8d1d8 CS |
8962 | rn->p.u.prefix4)); |
8963 | vty_out(vty, "\n"); | |
d62a17ae | 8964 | } |
43b8d1d8 | 8965 | } |
d62a17ae | 8966 | |
43b8d1d8 CS |
8967 | /* OSPF interface authentication print */ |
8968 | if (OSPF_IF_PARAM_CONFIGURED(params, auth_type) | |
8969 | && params->auth_type != OSPF_AUTH_NOTSET) { | |
8970 | const char *auth_str; | |
d62a17ae | 8971 | |
43b8d1d8 CS |
8972 | /* Translation tables are not that much help |
8973 | * here due to syntax | |
8974 | * of the simple option */ | |
8975 | switch (params->auth_type) { | |
d62a17ae | 8976 | |
43b8d1d8 CS |
8977 | case OSPF_AUTH_NULL: |
8978 | auth_str = " null"; | |
8979 | break; | |
d62a17ae | 8980 | |
43b8d1d8 CS |
8981 | case OSPF_AUTH_SIMPLE: |
8982 | auth_str = ""; | |
8983 | break; | |
d62a17ae | 8984 | |
43b8d1d8 CS |
8985 | case OSPF_AUTH_CRYPTOGRAPHIC: |
8986 | auth_str = " message-digest"; | |
8987 | break; | |
b5a8894d | 8988 | |
43b8d1d8 CS |
8989 | default: |
8990 | auth_str = ""; | |
8991 | break; | |
d62a17ae | 8992 | } |
8993 | ||
43b8d1d8 CS |
8994 | vty_out(vty, " ip ospf authentication%s", |
8995 | auth_str); | |
8996 | if (params != IF_DEF_PARAMS(ifp)) | |
8997 | vty_out(vty, " %s", | |
8998 | inet_ntoa(rn->p.u.prefix4)); | |
8999 | vty_out(vty, "\n"); | |
9000 | } | |
d62a17ae | 9001 | |
43b8d1d8 CS |
9002 | /* Simple Authentication Password print. */ |
9003 | if (OSPF_IF_PARAM_CONFIGURED(params, auth_simple) | |
9004 | && params->auth_simple[0] != '\0') { | |
9005 | vty_out(vty, " ip ospf authentication-key %s", | |
9006 | params->auth_simple); | |
9007 | if (params != IF_DEF_PARAMS(ifp)) | |
9008 | vty_out(vty, " %s", | |
9009 | inet_ntoa(rn->p.u.prefix4)); | |
9010 | vty_out(vty, "\n"); | |
9011 | } | |
d62a17ae | 9012 | |
43b8d1d8 | 9013 | /* Cryptographic Authentication Key print. */ |
35955c14 CS |
9014 | if (params && params->auth_crypt) { |
9015 | for (ALL_LIST_ELEMENTS_RO(params->auth_crypt, | |
f4e14fdb | 9016 | node, ck)) { |
35955c14 CS |
9017 | vty_out(vty, |
9018 | " ip ospf message-digest-key %d md5 %s", | |
9019 | ck->key_id, ck->auth_key); | |
9020 | if (params != IF_DEF_PARAMS(ifp)) | |
9021 | vty_out(vty, " %s", | |
9022 | inet_ntoa(rn->p.u.prefix4)); | |
9023 | vty_out(vty, "\n"); | |
9024 | } | |
43b8d1d8 | 9025 | } |
d62a17ae | 9026 | |
43b8d1d8 CS |
9027 | /* Interface Output Cost print. */ |
9028 | if (OSPF_IF_PARAM_CONFIGURED(params, | |
9029 | output_cost_cmd)) { | |
9030 | vty_out(vty, " ip ospf cost %u", | |
9031 | params->output_cost_cmd); | |
9032 | if (params != IF_DEF_PARAMS(ifp)) | |
9033 | vty_out(vty, " %s", | |
9034 | inet_ntoa(rn->p.u.prefix4)); | |
9035 | vty_out(vty, "\n"); | |
9036 | } | |
d62a17ae | 9037 | |
43b8d1d8 CS |
9038 | /* Hello Interval print. */ |
9039 | if (OSPF_IF_PARAM_CONFIGURED(params, v_hello) | |
9040 | && params->v_hello != OSPF_HELLO_INTERVAL_DEFAULT) { | |
9041 | vty_out(vty, " ip ospf hello-interval %u", | |
9042 | params->v_hello); | |
9043 | if (params != IF_DEF_PARAMS(ifp)) | |
9044 | vty_out(vty, " %s", | |
9045 | inet_ntoa(rn->p.u.prefix4)); | |
9046 | vty_out(vty, "\n"); | |
9047 | } | |
d62a17ae | 9048 | |
9049 | ||
43b8d1d8 CS |
9050 | /* Router Dead Interval print. */ |
9051 | if (OSPF_IF_PARAM_CONFIGURED(params, v_wait) | |
9052 | && params->v_wait | |
9053 | != OSPF_ROUTER_DEAD_INTERVAL_DEFAULT) { | |
9054 | vty_out(vty, " ip ospf dead-interval "); | |
d62a17ae | 9055 | |
43b8d1d8 CS |
9056 | /* fast hello ? */ |
9057 | if (OSPF_IF_PARAM_CONFIGURED(params, | |
9058 | fast_hello)) | |
9059 | vty_out(vty, | |
9060 | "minimal hello-multiplier %d", | |
9061 | params->fast_hello); | |
9062 | else | |
9063 | vty_out(vty, "%u", params->v_wait); | |
d62a17ae | 9064 | |
43b8d1d8 CS |
9065 | if (params != IF_DEF_PARAMS(ifp)) |
9066 | vty_out(vty, " %s", | |
9067 | inet_ntoa(rn->p.u.prefix4)); | |
9068 | vty_out(vty, "\n"); | |
9069 | } | |
d62a17ae | 9070 | |
43b8d1d8 CS |
9071 | /* Router Priority print. */ |
9072 | if (OSPF_IF_PARAM_CONFIGURED(params, priority) | |
9073 | && params->priority | |
9074 | != OSPF_ROUTER_PRIORITY_DEFAULT) { | |
9075 | vty_out(vty, " ip ospf priority %u", | |
9076 | params->priority); | |
9077 | if (params != IF_DEF_PARAMS(ifp)) | |
9078 | vty_out(vty, " %s", | |
9079 | inet_ntoa(rn->p.u.prefix4)); | |
9080 | vty_out(vty, "\n"); | |
9081 | } | |
d62a17ae | 9082 | |
43b8d1d8 CS |
9083 | /* Retransmit Interval print. */ |
9084 | if (OSPF_IF_PARAM_CONFIGURED(params, | |
9085 | retransmit_interval) | |
9086 | && params->retransmit_interval | |
9087 | != OSPF_RETRANSMIT_INTERVAL_DEFAULT) { | |
9088 | vty_out(vty, " ip ospf retransmit-interval %u", | |
9089 | params->retransmit_interval); | |
9090 | if (params != IF_DEF_PARAMS(ifp)) | |
9091 | vty_out(vty, " %s", | |
9092 | inet_ntoa(rn->p.u.prefix4)); | |
9093 | vty_out(vty, "\n"); | |
9094 | } | |
d62a17ae | 9095 | |
43b8d1d8 CS |
9096 | /* Transmit Delay print. */ |
9097 | if (OSPF_IF_PARAM_CONFIGURED(params, transmit_delay) | |
9098 | && params->transmit_delay | |
9099 | != OSPF_TRANSMIT_DELAY_DEFAULT) { | |
9100 | vty_out(vty, " ip ospf transmit-delay %u", | |
9101 | params->transmit_delay); | |
9102 | if (params != IF_DEF_PARAMS(ifp)) | |
9103 | vty_out(vty, " %s", | |
9104 | inet_ntoa(rn->p.u.prefix4)); | |
9105 | vty_out(vty, "\n"); | |
9106 | } | |
d62a17ae | 9107 | |
43b8d1d8 CS |
9108 | /* Area print. */ |
9109 | if (OSPF_IF_PARAM_CONFIGURED(params, if_area)) { | |
9110 | if (ospf->instance) | |
9111 | vty_out(vty, " ip ospf %d", | |
9112 | ospf->instance); | |
9113 | else | |
9114 | vty_out(vty, " ip ospf"); | |
d62a17ae | 9115 | |
d62a17ae | 9116 | |
43b8d1d8 CS |
9117 | size_t buflen = MAX(strlen("4294967295"), |
9118 | strlen("255.255.255.255")); | |
9119 | char buf[buflen]; | |
d62a17ae | 9120 | |
43b8d1d8 CS |
9121 | area_id2str(buf, sizeof(buf), |
9122 | ¶ms->if_area, | |
9123 | params->if_area_id_fmt); | |
9124 | vty_out(vty, " area %s", buf); | |
9125 | if (params != IF_DEF_PARAMS(ifp)) | |
9126 | vty_out(vty, " %s", | |
9127 | inet_ntoa(rn->p.u.prefix4)); | |
9128 | vty_out(vty, "\n"); | |
9129 | } | |
d62a17ae | 9130 | |
43b8d1d8 CS |
9131 | /* bfd print. */ |
9132 | ospf_bfd_write_config(vty, params); | |
d62a17ae | 9133 | |
43b8d1d8 CS |
9134 | /* MTU ignore print. */ |
9135 | if (OSPF_IF_PARAM_CONFIGURED(params, mtu_ignore) | |
9136 | && params->mtu_ignore != OSPF_MTU_IGNORE_DEFAULT) { | |
9137 | if (params->mtu_ignore == 0) | |
9138 | vty_out(vty, " no ip ospf mtu-ignore"); | |
9139 | else | |
9140 | vty_out(vty, " ip ospf mtu-ignore"); | |
9141 | if (params != IF_DEF_PARAMS(ifp)) | |
9142 | vty_out(vty, " %s", | |
9143 | inet_ntoa(rn->p.u.prefix4)); | |
9144 | vty_out(vty, "\n"); | |
9145 | } | |
d62a17ae | 9146 | |
a8b828f3 | 9147 | |
43b8d1d8 CS |
9148 | while (1) { |
9149 | if (rn == NULL) | |
9150 | rn = route_top(IF_OIFS_PARAMS(ifp)); | |
9151 | else | |
9152 | rn = route_next(rn); | |
d62a17ae | 9153 | |
43b8d1d8 CS |
9154 | if (rn == NULL) |
9155 | break; | |
9156 | params = rn->info; | |
9157 | if (params != NULL) | |
9158 | break; | |
9159 | } | |
9160 | } while (rn); | |
9161 | ||
9162 | ospf_opaque_config_write_if(vty, ifp); | |
9163 | ||
9164 | vty_endframe(vty, NULL); | |
b5a8894d | 9165 | } |
d62a17ae | 9166 | return write; |
718e3744 | 9167 | } |
9168 | ||
43b8d1d8 CS |
9169 | /* Configuration write function for ospfd. */ |
9170 | static int config_write_interface(struct vty *vty) | |
9171 | { | |
9172 | int write = 0; | |
9173 | struct ospf *ospf = NULL; | |
9174 | struct listnode *node = NULL; | |
9175 | ||
9176 | /* Traverse all ospf [vrf] instances */ | |
9177 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) | |
9178 | write += config_write_interface_one(vty, ospf); | |
9179 | ||
9180 | return write; | |
9181 | } | |
9182 | ||
d62a17ae | 9183 | static int config_write_network_area(struct vty *vty, struct ospf *ospf) |
718e3744 | 9184 | { |
d62a17ae | 9185 | struct route_node *rn; |
9186 | u_char buf[INET_ADDRSTRLEN]; | |
718e3744 | 9187 | |
d62a17ae | 9188 | /* `network area' print. */ |
9189 | for (rn = route_top(ospf->networks); rn; rn = route_next(rn)) | |
9190 | if (rn->info) { | |
9191 | struct ospf_network *n = rn->info; | |
718e3744 | 9192 | |
d62a17ae | 9193 | memset(buf, 0, INET_ADDRSTRLEN); |
718e3744 | 9194 | |
d62a17ae | 9195 | /* Create Area ID string by specified Area ID format. */ |
9196 | if (n->area_id_fmt == OSPF_AREA_ID_FMT_DOTTEDQUAD) | |
9197 | strncpy((char *)buf, inet_ntoa(n->area_id), | |
9198 | INET_ADDRSTRLEN); | |
9199 | else | |
9200 | sprintf((char *)buf, "%lu", | |
9201 | (unsigned long int)ntohl( | |
9202 | n->area_id.s_addr)); | |
718e3744 | 9203 | |
d62a17ae | 9204 | /* Network print. */ |
9205 | vty_out(vty, " network %s/%d area %s\n", | |
9206 | inet_ntoa(rn->p.u.prefix4), rn->p.prefixlen, | |
9207 | buf); | |
9208 | } | |
718e3744 | 9209 | |
d62a17ae | 9210 | return 0; |
718e3744 | 9211 | } |
9212 | ||
d62a17ae | 9213 | static int config_write_ospf_area(struct vty *vty, struct ospf *ospf) |
718e3744 | 9214 | { |
d62a17ae | 9215 | struct listnode *node; |
9216 | struct ospf_area *area; | |
9217 | u_char buf[INET_ADDRSTRLEN]; | |
718e3744 | 9218 | |
d62a17ae | 9219 | /* Area configuration print. */ |
9220 | for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) { | |
9221 | struct route_node *rn1; | |
718e3744 | 9222 | |
d62a17ae | 9223 | area_id2str((char *)buf, INET_ADDRSTRLEN, &area->area_id, |
9224 | area->area_id_fmt); | |
718e3744 | 9225 | |
d62a17ae | 9226 | if (area->auth_type != OSPF_AUTH_NULL) { |
9227 | if (area->auth_type == OSPF_AUTH_SIMPLE) | |
9228 | vty_out(vty, " area %s authentication\n", buf); | |
9229 | else | |
9230 | vty_out(vty, | |
9231 | " area %s authentication message-digest\n", | |
9232 | buf); | |
9233 | } | |
718e3744 | 9234 | |
d62a17ae | 9235 | if (area->shortcut_configured != OSPF_SHORTCUT_DEFAULT) |
9236 | vty_out(vty, " area %s shortcut %s\n", buf, | |
9237 | ospf_shortcut_mode_str | |
9238 | [area->shortcut_configured]); | |
9239 | ||
9240 | if ((area->external_routing == OSPF_AREA_STUB) | |
9241 | || (area->external_routing == OSPF_AREA_NSSA)) { | |
7ef56a73 | 9242 | if (area->external_routing == OSPF_AREA_STUB) { |
d62a17ae | 9243 | vty_out(vty, " area %s stub", buf); |
7ef56a73 CS |
9244 | if (area->no_summary) |
9245 | vty_out(vty, " no-summary\n"); | |
9246 | vty_out(vty, "\n"); | |
9247 | } else if (area->external_routing == OSPF_AREA_NSSA) { | |
d62a17ae | 9248 | switch (area->NSSATranslatorRole) { |
9249 | case OSPF_NSSA_ROLE_NEVER: | |
7ef56a73 CS |
9250 | vty_out(vty, |
9251 | " area %s nssa translate-never\n", | |
9252 | buf); | |
d62a17ae | 9253 | break; |
9254 | case OSPF_NSSA_ROLE_ALWAYS: | |
7ef56a73 CS |
9255 | vty_out(vty, |
9256 | " area %s nssa translate-always\n", | |
9257 | buf); | |
d62a17ae | 9258 | break; |
d62a17ae | 9259 | } |
7ef56a73 CS |
9260 | if (area->no_summary) |
9261 | vty_out(vty, | |
9262 | " area %s nssa no-summary\n", | |
9263 | buf); | |
d62a17ae | 9264 | } |
718e3744 | 9265 | |
d62a17ae | 9266 | if (area->default_cost != 1) |
9267 | vty_out(vty, " area %s default-cost %d\n", buf, | |
9268 | area->default_cost); | |
9269 | } | |
718e3744 | 9270 | |
d62a17ae | 9271 | for (rn1 = route_top(area->ranges); rn1; rn1 = route_next(rn1)) |
9272 | if (rn1->info) { | |
9273 | struct ospf_area_range *range = rn1->info; | |
718e3744 | 9274 | |
d62a17ae | 9275 | vty_out(vty, " area %s range %s/%d", buf, |
9276 | inet_ntoa(rn1->p.u.prefix4), | |
9277 | rn1->p.prefixlen); | |
718e3744 | 9278 | |
d62a17ae | 9279 | if (range->cost_config |
9280 | != OSPF_AREA_RANGE_COST_UNSPEC) | |
9281 | vty_out(vty, " cost %d", | |
9282 | range->cost_config); | |
718e3744 | 9283 | |
d62a17ae | 9284 | if (!CHECK_FLAG(range->flags, |
9285 | OSPF_AREA_RANGE_ADVERTISE)) | |
9286 | vty_out(vty, " not-advertise"); | |
718e3744 | 9287 | |
d62a17ae | 9288 | if (CHECK_FLAG(range->flags, |
9289 | OSPF_AREA_RANGE_SUBSTITUTE)) | |
9290 | vty_out(vty, " substitute %s/%d", | |
9291 | inet_ntoa(range->subst_addr), | |
9292 | range->subst_masklen); | |
9293 | ||
9294 | vty_out(vty, "\n"); | |
9295 | } | |
9296 | ||
9297 | if (EXPORT_NAME(area)) | |
9298 | vty_out(vty, " area %s export-list %s\n", buf, | |
9299 | EXPORT_NAME(area)); | |
9300 | ||
9301 | if (IMPORT_NAME(area)) | |
9302 | vty_out(vty, " area %s import-list %s\n", buf, | |
9303 | IMPORT_NAME(area)); | |
9304 | ||
9305 | if (PREFIX_NAME_IN(area)) | |
9306 | vty_out(vty, " area %s filter-list prefix %s in\n", buf, | |
9307 | PREFIX_NAME_IN(area)); | |
9308 | ||
9309 | if (PREFIX_NAME_OUT(area)) | |
9310 | vty_out(vty, " area %s filter-list prefix %s out\n", | |
9311 | buf, PREFIX_NAME_OUT(area)); | |
9312 | } | |
9313 | ||
9314 | return 0; | |
718e3744 | 9315 | } |
9316 | ||
d62a17ae | 9317 | static int config_write_ospf_nbr_nbma(struct vty *vty, struct ospf *ospf) |
718e3744 | 9318 | { |
d62a17ae | 9319 | struct ospf_nbr_nbma *nbr_nbma; |
9320 | struct route_node *rn; | |
718e3744 | 9321 | |
d62a17ae | 9322 | /* Static Neighbor configuration print. */ |
9323 | for (rn = route_top(ospf->nbr_nbma); rn; rn = route_next(rn)) | |
9324 | if ((nbr_nbma = rn->info)) { | |
9325 | vty_out(vty, " neighbor %s", inet_ntoa(nbr_nbma->addr)); | |
718e3744 | 9326 | |
d62a17ae | 9327 | if (nbr_nbma->priority |
9328 | != OSPF_NEIGHBOR_PRIORITY_DEFAULT) | |
9329 | vty_out(vty, " priority %d", | |
9330 | nbr_nbma->priority); | |
718e3744 | 9331 | |
d62a17ae | 9332 | if (nbr_nbma->v_poll != OSPF_POLL_INTERVAL_DEFAULT) |
9333 | vty_out(vty, " poll-interval %d", | |
9334 | nbr_nbma->v_poll); | |
9335 | ||
9336 | vty_out(vty, "\n"); | |
9337 | } | |
9338 | ||
9339 | return 0; | |
9340 | } | |
9341 | ||
9342 | static int config_write_virtual_link(struct vty *vty, struct ospf *ospf) | |
9343 | { | |
9344 | struct listnode *node; | |
9345 | struct ospf_vl_data *vl_data; | |
9346 | char buf[INET_ADDRSTRLEN]; | |
9347 | ||
9348 | /* Virtual-Link print */ | |
9349 | for (ALL_LIST_ELEMENTS_RO(ospf->vlinks, node, vl_data)) { | |
9350 | struct listnode *n2; | |
9351 | struct crypt_key *ck; | |
9352 | struct ospf_interface *oi; | |
9353 | ||
9354 | if (vl_data != NULL) { | |
9355 | memset(buf, 0, INET_ADDRSTRLEN); | |
9356 | ||
9357 | area_id2str(buf, sizeof(buf), &vl_data->vl_area_id, | |
9358 | vl_data->vl_area_id_fmt); | |
9359 | oi = vl_data->vl_oi; | |
9360 | ||
9361 | /* timers */ | |
9362 | if (OSPF_IF_PARAM(oi, v_hello) | |
9363 | != OSPF_HELLO_INTERVAL_DEFAULT | |
9364 | || OSPF_IF_PARAM(oi, v_wait) | |
9365 | != OSPF_ROUTER_DEAD_INTERVAL_DEFAULT | |
9366 | || OSPF_IF_PARAM(oi, retransmit_interval) | |
9367 | != OSPF_RETRANSMIT_INTERVAL_DEFAULT | |
9368 | || OSPF_IF_PARAM(oi, transmit_delay) | |
9369 | != OSPF_TRANSMIT_DELAY_DEFAULT) | |
9370 | vty_out(vty, | |
9371 | " area %s virtual-link %s hello-interval %d retransmit-interval %d transmit-delay %d dead-interval %d\n", | |
9372 | buf, inet_ntoa(vl_data->vl_peer), | |
9373 | OSPF_IF_PARAM(oi, v_hello), | |
9374 | OSPF_IF_PARAM(oi, retransmit_interval), | |
9375 | OSPF_IF_PARAM(oi, transmit_delay), | |
9376 | OSPF_IF_PARAM(oi, v_wait)); | |
9377 | else | |
9378 | vty_out(vty, " area %s virtual-link %s\n", buf, | |
9379 | inet_ntoa(vl_data->vl_peer)); | |
9380 | /* Auth key */ | |
9381 | if (IF_DEF_PARAMS(vl_data->vl_oi->ifp)->auth_simple[0] | |
9382 | != '\0') | |
9383 | vty_out(vty, | |
9384 | " area %s virtual-link %s authentication-key %s\n", | |
9385 | buf, inet_ntoa(vl_data->vl_peer), | |
9386 | IF_DEF_PARAMS(vl_data->vl_oi->ifp) | |
9387 | ->auth_simple); | |
9388 | /* md5 keys */ | |
9389 | for (ALL_LIST_ELEMENTS_RO( | |
9390 | IF_DEF_PARAMS(vl_data->vl_oi->ifp) | |
9391 | ->auth_crypt, | |
9392 | n2, ck)) | |
9393 | vty_out(vty, | |
9394 | " area %s virtual-link %s" | |
9395 | " message-digest-key %d md5 %s\n", | |
9396 | buf, inet_ntoa(vl_data->vl_peer), | |
9397 | ck->key_id, ck->auth_key); | |
9398 | } | |
9399 | } | |
9400 | ||
9401 | return 0; | |
718e3744 | 9402 | } |
9403 | ||
6b0655a2 | 9404 | |
d62a17ae | 9405 | static int config_write_ospf_redistribute(struct vty *vty, struct ospf *ospf) |
718e3744 | 9406 | { |
d62a17ae | 9407 | int type; |
718e3744 | 9408 | |
d62a17ae | 9409 | /* redistribute print. */ |
9410 | for (type = 0; type < ZEBRA_ROUTE_MAX; type++) { | |
9411 | struct list *red_list; | |
9412 | struct listnode *node; | |
9413 | struct ospf_redist *red; | |
718e3744 | 9414 | |
d62a17ae | 9415 | red_list = ospf->redist[type]; |
9416 | if (!red_list) | |
9417 | continue; | |
7c8ff89e | 9418 | |
d62a17ae | 9419 | for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) { |
9420 | vty_out(vty, " redistribute %s", | |
9421 | zebra_route_string(type)); | |
9422 | if (red->instance) | |
9423 | vty_out(vty, " %d", red->instance); | |
7c8ff89e | 9424 | |
d62a17ae | 9425 | if (red->dmetric.value >= 0) |
9426 | vty_out(vty, " metric %d", red->dmetric.value); | |
7c8ff89e | 9427 | |
d62a17ae | 9428 | if (red->dmetric.type == EXTERNAL_METRIC_TYPE_1) |
9429 | vty_out(vty, " metric-type 1"); | |
7c8ff89e | 9430 | |
d62a17ae | 9431 | if (ROUTEMAP_NAME(red)) |
9432 | vty_out(vty, " route-map %s", | |
9433 | ROUTEMAP_NAME(red)); | |
7c8ff89e | 9434 | |
d62a17ae | 9435 | vty_out(vty, "\n"); |
9436 | } | |
9437 | } | |
718e3744 | 9438 | |
d62a17ae | 9439 | return 0; |
718e3744 | 9440 | } |
9441 | ||
d62a17ae | 9442 | static int config_write_ospf_default_metric(struct vty *vty, struct ospf *ospf) |
718e3744 | 9443 | { |
d62a17ae | 9444 | if (ospf->default_metric != -1) |
9445 | vty_out(vty, " default-metric %d\n", ospf->default_metric); | |
9446 | return 0; | |
718e3744 | 9447 | } |
9448 | ||
d62a17ae | 9449 | static int config_write_ospf_distribute(struct vty *vty, struct ospf *ospf) |
9450 | { | |
9451 | int type; | |
9452 | struct ospf_redist *red; | |
718e3744 | 9453 | |
d62a17ae | 9454 | if (ospf) { |
9455 | /* distribute-list print. */ | |
9456 | for (type = 0; type < ZEBRA_ROUTE_MAX; type++) | |
9457 | if (DISTRIBUTE_NAME(ospf, type)) | |
9458 | vty_out(vty, " distribute-list %s out %s\n", | |
9459 | DISTRIBUTE_NAME(ospf, type), | |
9460 | zebra_route_string(type)); | |
7c8ff89e | 9461 | |
d62a17ae | 9462 | /* default-information print. */ |
9463 | if (ospf->default_originate != DEFAULT_ORIGINATE_NONE) { | |
9464 | vty_out(vty, " default-information originate"); | |
9465 | if (ospf->default_originate == DEFAULT_ORIGINATE_ALWAYS) | |
9466 | vty_out(vty, " always"); | |
718e3744 | 9467 | |
d62a17ae | 9468 | red = ospf_redist_lookup(ospf, DEFAULT_ROUTE, 0); |
9469 | if (red) { | |
9470 | if (red->dmetric.value >= 0) | |
9471 | vty_out(vty, " metric %d", | |
9472 | red->dmetric.value); | |
9473 | if (red->dmetric.type == EXTERNAL_METRIC_TYPE_1) | |
9474 | vty_out(vty, " metric-type 1"); | |
718e3744 | 9475 | |
d62a17ae | 9476 | if (ROUTEMAP_NAME(red)) |
9477 | vty_out(vty, " route-map %s", | |
9478 | ROUTEMAP_NAME(red)); | |
9479 | } | |
9480 | ||
9481 | vty_out(vty, "\n"); | |
9482 | } | |
9483 | } | |
9484 | ||
9485 | return 0; | |
718e3744 | 9486 | } |
9487 | ||
d62a17ae | 9488 | static int config_write_ospf_distance(struct vty *vty, struct ospf *ospf) |
9489 | { | |
9490 | struct route_node *rn; | |
9491 | struct ospf_distance *odistance; | |
9492 | ||
9493 | if (ospf->distance_all) | |
9494 | vty_out(vty, " distance %d\n", ospf->distance_all); | |
9495 | ||
9496 | if (ospf->distance_intra || ospf->distance_inter | |
9497 | || ospf->distance_external) { | |
9498 | vty_out(vty, " distance ospf"); | |
9499 | ||
9500 | if (ospf->distance_intra) | |
9501 | vty_out(vty, " intra-area %d", ospf->distance_intra); | |
9502 | if (ospf->distance_inter) | |
9503 | vty_out(vty, " inter-area %d", ospf->distance_inter); | |
9504 | if (ospf->distance_external) | |
9505 | vty_out(vty, " external %d", ospf->distance_external); | |
9506 | ||
9507 | vty_out(vty, "\n"); | |
9508 | } | |
9509 | ||
9510 | for (rn = route_top(ospf->distance_table); rn; rn = route_next(rn)) | |
9511 | if ((odistance = rn->info) != NULL) { | |
9512 | vty_out(vty, " distance %d %s/%d %s\n", | |
9513 | odistance->distance, inet_ntoa(rn->p.u.prefix4), | |
9514 | rn->p.prefixlen, | |
9515 | odistance->access_list ? odistance->access_list | |
9516 | : ""); | |
9517 | } | |
9518 | return 0; | |
718e3744 | 9519 | } |
9520 | ||
43b8d1d8 | 9521 | static int ospf_config_write_one(struct vty *vty, struct ospf *ospf) |
d62a17ae | 9522 | { |
f4e14fdb | 9523 | struct vrf *vrf = vrf_lookup_by_id(ospf->vrf_id); |
d62a17ae | 9524 | struct interface *ifp; |
9525 | struct ospf_interface *oi; | |
43b8d1d8 | 9526 | struct listnode *node = NULL; |
d62a17ae | 9527 | int write = 0; |
9528 | ||
43b8d1d8 CS |
9529 | /* `router ospf' print. */ |
9530 | if (ospf->instance && ospf->name) { | |
9531 | vty_out(vty, "router ospf %d vrf %s\n", | |
9532 | ospf->instance, ospf->name); | |
9533 | } else if (ospf->instance) { | |
9534 | vty_out(vty, "router ospf %d\n", | |
9535 | ospf->instance); | |
9536 | } else if (ospf->name) { | |
9537 | vty_out(vty, "router ospf vrf %s\n", | |
9538 | ospf->name); | |
9539 | } else | |
9540 | vty_out(vty, "router ospf\n"); | |
9541 | ||
9542 | if (!ospf->networks) { | |
9543 | write++; | |
b5a8894d | 9544 | return write; |
43b8d1d8 | 9545 | } |
d62a17ae | 9546 | |
43b8d1d8 CS |
9547 | /* Router ID print. */ |
9548 | if (ospf->router_id_static.s_addr != 0) | |
9549 | vty_out(vty, " ospf router-id %s\n", | |
9550 | inet_ntoa(ospf->router_id_static)); | |
d62a17ae | 9551 | |
43b8d1d8 CS |
9552 | /* ABR type print. */ |
9553 | if (ospf->abr_type != OSPF_ABR_DEFAULT) | |
9554 | vty_out(vty, " ospf abr-type %s\n", | |
9555 | ospf_abr_type_str[ospf->abr_type]); | |
b5a8894d | 9556 | |
43b8d1d8 CS |
9557 | /* log-adjacency-changes flag print. */ |
9558 | if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_CHANGES)) { | |
9559 | if (CHECK_FLAG(ospf->config, OSPF_LOG_ADJACENCY_DETAIL)) | |
9560 | vty_out(vty, " log-adjacency-changes detail\n"); | |
9561 | else if (!DFLT_OSPF_LOG_ADJACENCY_CHANGES) | |
9562 | vty_out(vty, " log-adjacency-changes\n"); | |
9563 | } else if (DFLT_OSPF_LOG_ADJACENCY_CHANGES) { | |
9564 | vty_out(vty, " no log-adjacency-changes\n"); | |
9565 | } | |
b5a8894d | 9566 | |
43b8d1d8 CS |
9567 | /* RFC1583 compatibility flag print -- Compatible with CISCO |
9568 | * 12.1. */ | |
9569 | if (CHECK_FLAG(ospf->config, OSPF_RFC1583_COMPATIBLE)) | |
9570 | vty_out(vty, " compatible rfc1583\n"); | |
d62a17ae | 9571 | |
43b8d1d8 CS |
9572 | /* auto-cost reference-bandwidth configuration. */ |
9573 | if (ospf->ref_bandwidth != OSPF_DEFAULT_REF_BANDWIDTH) { | |
9574 | vty_out(vty, | |
9575 | "! Important: ensure reference bandwidth " | |
9576 | "is consistent across all routers\n"); | |
9577 | vty_out(vty, " auto-cost reference-bandwidth %d\n", | |
9578 | ospf->ref_bandwidth); | |
9579 | } | |
d62a17ae | 9580 | |
43b8d1d8 CS |
9581 | /* SPF timers print. */ |
9582 | if (ospf->spf_delay != OSPF_SPF_DELAY_DEFAULT | |
9583 | || ospf->spf_holdtime != OSPF_SPF_HOLDTIME_DEFAULT | |
9584 | || ospf->spf_max_holdtime != OSPF_SPF_MAX_HOLDTIME_DEFAULT) | |
9585 | vty_out(vty, " timers throttle spf %d %d %d\n", | |
9586 | ospf->spf_delay, ospf->spf_holdtime, | |
9587 | ospf->spf_max_holdtime); | |
9588 | ||
9589 | /* LSA timers print. */ | |
9590 | if (ospf->min_ls_interval != OSPF_MIN_LS_INTERVAL) | |
9591 | vty_out(vty, " timers throttle lsa all %d\n", | |
9592 | ospf->min_ls_interval); | |
9593 | if (ospf->min_ls_arrival != OSPF_MIN_LS_ARRIVAL) | |
9594 | vty_out(vty, " timers lsa min-arrival %d\n", | |
9595 | ospf->min_ls_arrival); | |
9596 | ||
9597 | /* Write multiplier print. */ | |
9598 | if (ospf->write_oi_count != OSPF_WRITE_INTERFACE_COUNT_DEFAULT) | |
9599 | vty_out(vty, " ospf write-multiplier %d\n", | |
9600 | ospf->write_oi_count); | |
d62a17ae | 9601 | |
43b8d1d8 CS |
9602 | /* Max-metric router-lsa print */ |
9603 | config_write_stub_router(vty, ospf); | |
d62a17ae | 9604 | |
43b8d1d8 CS |
9605 | /* SPF refresh parameters print. */ |
9606 | if (ospf->lsa_refresh_interval | |
9607 | != OSPF_LSA_REFRESH_INTERVAL_DEFAULT) | |
9608 | vty_out(vty, " refresh timer %d\n", | |
9609 | ospf->lsa_refresh_interval); | |
d62a17ae | 9610 | |
43b8d1d8 CS |
9611 | /* Redistribute information print. */ |
9612 | config_write_ospf_redistribute(vty, ospf); | |
d62a17ae | 9613 | |
43b8d1d8 CS |
9614 | /* passive-interface print. */ |
9615 | if (ospf->passive_interface_default == OSPF_IF_PASSIVE) | |
9616 | vty_out(vty, " passive-interface default\n"); | |
d62a17ae | 9617 | |
451fda4f | 9618 | FOR_ALL_INTERFACES (vrf, ifp) |
43b8d1d8 CS |
9619 | if (OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(ifp), |
9620 | passive_interface) | |
9621 | && IF_DEF_PARAMS(ifp)->passive_interface | |
9622 | != ospf->passive_interface_default) { | |
9623 | vty_out(vty, " %spassive-interface %s\n", | |
9624 | IF_DEF_PARAMS(ifp)->passive_interface | |
9625 | ? "" | |
9626 | : "no ", | |
9627 | ifp->name); | |
9628 | } | |
9629 | for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) { | |
9630 | if (!OSPF_IF_PARAM_CONFIGURED(oi->params, | |
9631 | passive_interface)) | |
9632 | continue; | |
9633 | if (OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(oi->ifp), | |
9634 | passive_interface)) { | |
9635 | if (oi->params->passive_interface | |
9636 | == IF_DEF_PARAMS(oi->ifp) | |
9637 | ->passive_interface) | |
9638 | continue; | |
9639 | } else if (oi->params->passive_interface | |
9640 | == ospf->passive_interface_default) | |
9641 | continue; | |
d62a17ae | 9642 | |
43b8d1d8 CS |
9643 | vty_out(vty, " %spassive-interface %s %s\n", |
9644 | oi->params->passive_interface ? "" : "no ", | |
9645 | oi->ifp->name, | |
9646 | inet_ntoa(oi->address->u.prefix4)); | |
9647 | } | |
d62a17ae | 9648 | |
43b8d1d8 CS |
9649 | /* Network area print. */ |
9650 | config_write_network_area(vty, ospf); | |
d62a17ae | 9651 | |
43b8d1d8 CS |
9652 | /* Area config print. */ |
9653 | config_write_ospf_area(vty, ospf); | |
d62a17ae | 9654 | |
43b8d1d8 CS |
9655 | /* static neighbor print. */ |
9656 | config_write_ospf_nbr_nbma(vty, ospf); | |
9657 | ||
9658 | /* Virtual-Link print. */ | |
9659 | config_write_virtual_link(vty, ospf); | |
9660 | ||
9661 | /* Default metric configuration. */ | |
9662 | config_write_ospf_default_metric(vty, ospf); | |
9663 | ||
9664 | /* Distribute-list and default-information print. */ | |
9665 | config_write_ospf_distribute(vty, ospf); | |
9666 | ||
9667 | /* Distance configuration. */ | |
9668 | config_write_ospf_distance(vty, ospf); | |
9669 | ||
9670 | ospf_opaque_config_write_router(vty, ospf); | |
9671 | ||
9672 | write++; | |
9673 | return write; | |
9674 | } | |
9675 | ||
9676 | /* OSPF configuration write function. */ | |
9677 | static int ospf_config_write(struct vty *vty) | |
9678 | { | |
9679 | struct ospf *ospf; | |
9680 | struct listnode *ospf_node = NULL; | |
9681 | int write = 0; | |
9682 | ||
9683 | if (listcount(om->ospf) == 0) | |
9684 | return write; | |
9685 | ||
9686 | for (ALL_LIST_ELEMENTS_RO(om->ospf, ospf_node, ospf)) { | |
9687 | if (ospf->oi_running) | |
9688 | write += ospf_config_write_one(vty, ospf); | |
b5a8894d | 9689 | } |
d62a17ae | 9690 | return write; |
9691 | } | |
9692 | ||
9693 | void ospf_vty_show_init(void) | |
9694 | { | |
9695 | /* "show ip ospf" commands. */ | |
9696 | install_element(VIEW_NODE, &show_ip_ospf_cmd); | |
9697 | ||
9698 | install_element(VIEW_NODE, &show_ip_ospf_instance_cmd); | |
9699 | ||
9700 | /* "show ip ospf database" commands. */ | |
9701 | install_element(VIEW_NODE, &show_ip_ospf_database_max_cmd); | |
9702 | ||
9703 | install_element(VIEW_NODE, | |
9704 | &show_ip_ospf_instance_database_type_adv_router_cmd); | |
9705 | install_element(VIEW_NODE, &show_ip_ospf_instance_database_cmd); | |
9706 | install_element(VIEW_NODE, &show_ip_ospf_instance_database_max_cmd); | |
9707 | ||
9708 | /* "show ip ospf interface" commands. */ | |
9709 | install_element(VIEW_NODE, &show_ip_ospf_interface_cmd); | |
9710 | ||
9711 | install_element(VIEW_NODE, &show_ip_ospf_instance_interface_cmd); | |
c9339663 CS |
9712 | /* "show ip ospf interface traffic */ |
9713 | install_element(VIEW_NODE, &show_ip_ospf_interface_traffic_cmd); | |
d62a17ae | 9714 | |
9715 | /* "show ip ospf neighbor" commands. */ | |
9716 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_int_detail_cmd); | |
9717 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_int_cmd); | |
9718 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_id_cmd); | |
9719 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_detail_all_cmd); | |
9720 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_detail_cmd); | |
9721 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_cmd); | |
9722 | install_element(VIEW_NODE, &show_ip_ospf_neighbor_all_cmd); | |
9723 | ||
9724 | install_element(VIEW_NODE, | |
9725 | &show_ip_ospf_instance_neighbor_int_detail_cmd); | |
9726 | install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_int_cmd); | |
9727 | install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_id_cmd); | |
9728 | install_element(VIEW_NODE, | |
9729 | &show_ip_ospf_instance_neighbor_detail_all_cmd); | |
9730 | install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_detail_cmd); | |
9731 | install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_cmd); | |
9732 | install_element(VIEW_NODE, &show_ip_ospf_instance_neighbor_all_cmd); | |
9733 | ||
9734 | /* "show ip ospf route" commands. */ | |
9735 | install_element(VIEW_NODE, &show_ip_ospf_route_cmd); | |
9736 | install_element(VIEW_NODE, &show_ip_ospf_border_routers_cmd); | |
9737 | ||
9738 | install_element(VIEW_NODE, &show_ip_ospf_instance_route_cmd); | |
9739 | install_element(VIEW_NODE, &show_ip_ospf_instance_border_routers_cmd); | |
b5a8894d CS |
9740 | |
9741 | /* "show ip ospf vrfs" commands. */ | |
9742 | install_element(VIEW_NODE, &show_ip_ospf_vrfs_cmd); | |
718e3744 | 9743 | } |
9744 | ||
6b0655a2 | 9745 | |
718e3744 | 9746 | /* ospfd's interface node. */ |
d62a17ae | 9747 | static struct cmd_node interface_node = {INTERFACE_NODE, "%s(config-if)# ", 1}; |
718e3744 | 9748 | |
9749 | /* Initialization of OSPF interface. */ | |
d62a17ae | 9750 | static void ospf_vty_if_init(void) |
9751 | { | |
9752 | /* Install interface node. */ | |
9753 | install_node(&interface_node, config_write_interface); | |
9754 | if_cmd_init(); | |
9755 | ||
9756 | /* "ip ospf authentication" commands. */ | |
9757 | install_element(INTERFACE_NODE, &ip_ospf_authentication_args_addr_cmd); | |
9758 | install_element(INTERFACE_NODE, &ip_ospf_authentication_addr_cmd); | |
9759 | install_element(INTERFACE_NODE, | |
9760 | &no_ip_ospf_authentication_args_addr_cmd); | |
9761 | install_element(INTERFACE_NODE, &no_ip_ospf_authentication_addr_cmd); | |
9762 | install_element(INTERFACE_NODE, &ip_ospf_authentication_key_addr_cmd); | |
9763 | install_element(INTERFACE_NODE, | |
9764 | &no_ip_ospf_authentication_key_authkey_addr_cmd); | |
9765 | install_element(INTERFACE_NODE, | |
9766 | &no_ospf_authentication_key_authkey_addr_cmd); | |
9767 | ||
9768 | /* "ip ospf message-digest-key" commands. */ | |
9769 | install_element(INTERFACE_NODE, &ip_ospf_message_digest_key_cmd); | |
9770 | install_element(INTERFACE_NODE, &no_ip_ospf_message_digest_key_cmd); | |
9771 | ||
9772 | /* "ip ospf cost" commands. */ | |
9773 | install_element(INTERFACE_NODE, &ip_ospf_cost_cmd); | |
9774 | install_element(INTERFACE_NODE, &no_ip_ospf_cost_cmd); | |
9775 | ||
9776 | /* "ip ospf mtu-ignore" commands. */ | |
9777 | install_element(INTERFACE_NODE, &ip_ospf_mtu_ignore_addr_cmd); | |
9778 | install_element(INTERFACE_NODE, &no_ip_ospf_mtu_ignore_addr_cmd); | |
9779 | ||
9780 | /* "ip ospf dead-interval" commands. */ | |
9781 | install_element(INTERFACE_NODE, &ip_ospf_dead_interval_cmd); | |
9782 | install_element(INTERFACE_NODE, | |
9783 | &ip_ospf_dead_interval_minimal_addr_cmd); | |
9784 | install_element(INTERFACE_NODE, &no_ip_ospf_dead_interval_cmd); | |
9785 | ||
9786 | /* "ip ospf hello-interval" commands. */ | |
9787 | install_element(INTERFACE_NODE, &ip_ospf_hello_interval_cmd); | |
9788 | install_element(INTERFACE_NODE, &no_ip_ospf_hello_interval_cmd); | |
9789 | ||
9790 | /* "ip ospf network" commands. */ | |
9791 | install_element(INTERFACE_NODE, &ip_ospf_network_cmd); | |
9792 | install_element(INTERFACE_NODE, &no_ip_ospf_network_cmd); | |
9793 | ||
9794 | /* "ip ospf priority" commands. */ | |
9795 | install_element(INTERFACE_NODE, &ip_ospf_priority_cmd); | |
9796 | install_element(INTERFACE_NODE, &no_ip_ospf_priority_cmd); | |
9797 | ||
9798 | /* "ip ospf retransmit-interval" commands. */ | |
9799 | install_element(INTERFACE_NODE, &ip_ospf_retransmit_interval_addr_cmd); | |
9800 | install_element(INTERFACE_NODE, | |
9801 | &no_ip_ospf_retransmit_interval_addr_cmd); | |
9802 | ||
9803 | /* "ip ospf transmit-delay" commands. */ | |
9804 | install_element(INTERFACE_NODE, &ip_ospf_transmit_delay_addr_cmd); | |
9805 | install_element(INTERFACE_NODE, &no_ip_ospf_transmit_delay_addr_cmd); | |
9806 | ||
9807 | /* "ip ospf area" commands. */ | |
9808 | install_element(INTERFACE_NODE, &ip_ospf_area_cmd); | |
9809 | install_element(INTERFACE_NODE, &no_ip_ospf_area_cmd); | |
9810 | ||
9811 | /* These commands are compatibitliy for previous version. */ | |
9812 | install_element(INTERFACE_NODE, &ospf_authentication_key_cmd); | |
9813 | install_element(INTERFACE_NODE, &ospf_message_digest_key_cmd); | |
9814 | install_element(INTERFACE_NODE, &no_ospf_message_digest_key_cmd); | |
9815 | install_element(INTERFACE_NODE, &ospf_dead_interval_cmd); | |
9816 | install_element(INTERFACE_NODE, &no_ospf_dead_interval_cmd); | |
9817 | install_element(INTERFACE_NODE, &ospf_hello_interval_cmd); | |
9818 | install_element(INTERFACE_NODE, &no_ospf_hello_interval_cmd); | |
9819 | install_element(INTERFACE_NODE, &ospf_cost_cmd); | |
9820 | install_element(INTERFACE_NODE, &no_ospf_cost_cmd); | |
9821 | install_element(INTERFACE_NODE, &ospf_network_cmd); | |
9822 | install_element(INTERFACE_NODE, &no_ospf_network_cmd); | |
9823 | install_element(INTERFACE_NODE, &ospf_priority_cmd); | |
9824 | install_element(INTERFACE_NODE, &no_ospf_priority_cmd); | |
9825 | install_element(INTERFACE_NODE, &ospf_retransmit_interval_cmd); | |
9826 | install_element(INTERFACE_NODE, &no_ospf_retransmit_interval_cmd); | |
9827 | install_element(INTERFACE_NODE, &ospf_transmit_delay_cmd); | |
9828 | install_element(INTERFACE_NODE, &no_ospf_transmit_delay_cmd); | |
9829 | } | |
9830 | ||
9831 | static void ospf_vty_zebra_init(void) | |
9832 | { | |
9833 | install_element(OSPF_NODE, &ospf_redistribute_source_cmd); | |
9834 | install_element(OSPF_NODE, &no_ospf_redistribute_source_cmd); | |
9835 | install_element(OSPF_NODE, &ospf_redistribute_instance_source_cmd); | |
9836 | install_element(OSPF_NODE, &no_ospf_redistribute_instance_source_cmd); | |
9837 | ||
9838 | install_element(OSPF_NODE, &ospf_distribute_list_out_cmd); | |
9839 | install_element(OSPF_NODE, &no_ospf_distribute_list_out_cmd); | |
9840 | ||
9841 | install_element(OSPF_NODE, &ospf_default_information_originate_cmd); | |
9842 | install_element(OSPF_NODE, &no_ospf_default_information_originate_cmd); | |
9843 | ||
9844 | install_element(OSPF_NODE, &ospf_default_metric_cmd); | |
9845 | install_element(OSPF_NODE, &no_ospf_default_metric_cmd); | |
9846 | ||
9847 | install_element(OSPF_NODE, &ospf_distance_cmd); | |
9848 | install_element(OSPF_NODE, &no_ospf_distance_cmd); | |
9849 | install_element(OSPF_NODE, &no_ospf_distance_ospf_cmd); | |
9850 | install_element(OSPF_NODE, &ospf_distance_ospf_cmd); | |
718e3744 | 9851 | #if 0 |
9852 | install_element (OSPF_NODE, &ospf_distance_source_cmd); | |
9853 | install_element (OSPF_NODE, &no_ospf_distance_source_cmd); | |
9854 | install_element (OSPF_NODE, &ospf_distance_source_access_list_cmd); | |
9855 | install_element (OSPF_NODE, &no_ospf_distance_source_access_list_cmd); | |
9856 | #endif /* 0 */ | |
9857 | } | |
9858 | ||
d62a17ae | 9859 | static struct cmd_node ospf_node = {OSPF_NODE, "%s(config-router)# ", 1}; |
718e3744 | 9860 | |
d62a17ae | 9861 | static void ospf_interface_clear(struct interface *ifp) |
09f35f8c | 9862 | { |
d62a17ae | 9863 | if (!if_is_operative(ifp)) |
9864 | return; | |
09f35f8c | 9865 | |
d62a17ae | 9866 | if (IS_DEBUG_OSPF(ism, ISM_EVENTS)) |
9867 | zlog_debug("ISM[%s]: clear by reset", ifp->name); | |
09f35f8c | 9868 | |
d62a17ae | 9869 | ospf_if_reset(ifp); |
09f35f8c DS |
9870 | } |
9871 | ||
9872 | DEFUN (clear_ip_ospf_interface, | |
9873 | clear_ip_ospf_interface_cmd, | |
9874 | "clear ip ospf interface [IFNAME]", | |
9875 | CLEAR_STR | |
9876 | IP_STR | |
9877 | "OSPF information\n" | |
9878 | "Interface information\n" | |
9879 | "Interface name\n") | |
9880 | { | |
d62a17ae | 9881 | int idx_ifname = 4; |
9882 | struct interface *ifp; | |
f4e14fdb | 9883 | struct listnode *node; |
b5a8894d | 9884 | struct ospf *ospf = NULL; |
09f35f8c | 9885 | |
d62a17ae | 9886 | if (argc == 4) /* Clear all the ospfv2 interfaces. */ |
9887 | { | |
f4e14fdb RW |
9888 | for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { |
9889 | struct vrf *vrf = vrf_lookup_by_id(ospf->vrf_id); | |
451fda4f | 9890 | FOR_ALL_INTERFACES (vrf, ifp) |
b5a8894d CS |
9891 | ospf_interface_clear(ifp); |
9892 | } | |
9893 | } else { | |
9894 | /* Interface name is specified. */ | |
9895 | ifp = if_lookup_by_name_all_vrf(argv[idx_ifname]->arg); | |
9896 | if (ifp == NULL) | |
d62a17ae | 9897 | vty_out(vty, "No such interface name\n"); |
9898 | else | |
9899 | ospf_interface_clear(ifp); | |
9900 | } | |
9901 | ||
9902 | return CMD_SUCCESS; | |
09f35f8c DS |
9903 | } |
9904 | ||
d62a17ae | 9905 | void ospf_vty_clear_init(void) |
09f35f8c | 9906 | { |
d62a17ae | 9907 | install_element(ENABLE_NODE, &clear_ip_ospf_interface_cmd); |
09f35f8c DS |
9908 | } |
9909 | ||
6b0655a2 | 9910 | |
718e3744 | 9911 | /* Install OSPF related vty commands. */ |
d62a17ae | 9912 | void ospf_vty_init(void) |
9913 | { | |
9914 | /* Install ospf top node. */ | |
9915 | install_node(&ospf_node, ospf_config_write); | |
9916 | ||
9917 | /* "router ospf" commands. */ | |
9918 | install_element(CONFIG_NODE, &router_ospf_cmd); | |
9919 | install_element(CONFIG_NODE, &no_router_ospf_cmd); | |
9920 | ||
9921 | ||
9922 | install_default(OSPF_NODE); | |
9923 | ||
9924 | /* "ospf router-id" commands. */ | |
9925 | install_element(OSPF_NODE, &ospf_router_id_cmd); | |
9926 | install_element(OSPF_NODE, &ospf_router_id_old_cmd); | |
9927 | install_element(OSPF_NODE, &no_ospf_router_id_cmd); | |
9928 | ||
9929 | /* "passive-interface" commands. */ | |
9930 | install_element(OSPF_NODE, &ospf_passive_interface_addr_cmd); | |
9931 | install_element(OSPF_NODE, &no_ospf_passive_interface_addr_cmd); | |
9932 | ||
9933 | /* "ospf abr-type" commands. */ | |
9934 | install_element(OSPF_NODE, &ospf_abr_type_cmd); | |
9935 | install_element(OSPF_NODE, &no_ospf_abr_type_cmd); | |
9936 | ||
9937 | /* "ospf log-adjacency-changes" commands. */ | |
9938 | install_element(OSPF_NODE, &ospf_log_adjacency_changes_cmd); | |
9939 | install_element(OSPF_NODE, &ospf_log_adjacency_changes_detail_cmd); | |
9940 | install_element(OSPF_NODE, &no_ospf_log_adjacency_changes_cmd); | |
9941 | install_element(OSPF_NODE, &no_ospf_log_adjacency_changes_detail_cmd); | |
9942 | ||
9943 | /* "ospf rfc1583-compatible" commands. */ | |
9944 | install_element(OSPF_NODE, &ospf_compatible_rfc1583_cmd); | |
9945 | install_element(OSPF_NODE, &no_ospf_compatible_rfc1583_cmd); | |
9946 | install_element(OSPF_NODE, &ospf_rfc1583_flag_cmd); | |
9947 | install_element(OSPF_NODE, &no_ospf_rfc1583_flag_cmd); | |
9948 | ||
9949 | /* "network area" commands. */ | |
9950 | install_element(OSPF_NODE, &ospf_network_area_cmd); | |
9951 | install_element(OSPF_NODE, &no_ospf_network_area_cmd); | |
9952 | ||
9953 | /* "area authentication" commands. */ | |
9954 | install_element(OSPF_NODE, | |
9955 | &ospf_area_authentication_message_digest_cmd); | |
9956 | install_element(OSPF_NODE, &ospf_area_authentication_cmd); | |
9957 | install_element(OSPF_NODE, &no_ospf_area_authentication_cmd); | |
9958 | ||
9959 | /* "area range" commands. */ | |
9960 | install_element(OSPF_NODE, &ospf_area_range_cmd); | |
9961 | install_element(OSPF_NODE, &ospf_area_range_cost_cmd); | |
9962 | install_element(OSPF_NODE, &ospf_area_range_not_advertise_cmd); | |
9963 | install_element(OSPF_NODE, &no_ospf_area_range_cmd); | |
9964 | install_element(OSPF_NODE, &ospf_area_range_substitute_cmd); | |
9965 | install_element(OSPF_NODE, &no_ospf_area_range_substitute_cmd); | |
9966 | ||
9967 | /* "area virtual-link" commands. */ | |
9968 | install_element(OSPF_NODE, &ospf_area_vlink_cmd); | |
9969 | install_element(OSPF_NODE, &ospf_area_vlink_intervals_cmd); | |
9970 | install_element(OSPF_NODE, &no_ospf_area_vlink_cmd); | |
9971 | install_element(OSPF_NODE, &no_ospf_area_vlink_intervals_cmd); | |
9972 | ||
9973 | ||
9974 | /* "area stub" commands. */ | |
9975 | install_element(OSPF_NODE, &ospf_area_stub_no_summary_cmd); | |
9976 | install_element(OSPF_NODE, &ospf_area_stub_cmd); | |
9977 | install_element(OSPF_NODE, &no_ospf_area_stub_no_summary_cmd); | |
9978 | install_element(OSPF_NODE, &no_ospf_area_stub_cmd); | |
9979 | ||
9980 | /* "area nssa" commands. */ | |
9981 | install_element(OSPF_NODE, &ospf_area_nssa_cmd); | |
d62a17ae | 9982 | install_element(OSPF_NODE, &ospf_area_nssa_translate_cmd); |
9983 | install_element(OSPF_NODE, &ospf_area_nssa_no_summary_cmd); | |
7ef56a73 | 9984 | install_element(OSPF_NODE, &no_ospf_area_nssa_no_summary_cmd); |
d62a17ae | 9985 | install_element(OSPF_NODE, &no_ospf_area_nssa_cmd); |
9986 | ||
9987 | install_element(OSPF_NODE, &ospf_area_default_cost_cmd); | |
9988 | install_element(OSPF_NODE, &no_ospf_area_default_cost_cmd); | |
9989 | ||
9990 | install_element(OSPF_NODE, &ospf_area_shortcut_cmd); | |
9991 | install_element(OSPF_NODE, &no_ospf_area_shortcut_cmd); | |
9992 | ||
9993 | install_element(OSPF_NODE, &ospf_area_export_list_cmd); | |
9994 | install_element(OSPF_NODE, &no_ospf_area_export_list_cmd); | |
9995 | ||
9996 | install_element(OSPF_NODE, &ospf_area_filter_list_cmd); | |
9997 | install_element(OSPF_NODE, &no_ospf_area_filter_list_cmd); | |
9998 | ||
9999 | install_element(OSPF_NODE, &ospf_area_import_list_cmd); | |
10000 | install_element(OSPF_NODE, &no_ospf_area_import_list_cmd); | |
10001 | ||
10002 | /* SPF timer commands */ | |
10003 | install_element(OSPF_NODE, &ospf_timers_throttle_spf_cmd); | |
10004 | install_element(OSPF_NODE, &no_ospf_timers_throttle_spf_cmd); | |
10005 | ||
10006 | /* LSA timers commands */ | |
10007 | install_element(OSPF_NODE, &ospf_timers_min_ls_interval_cmd); | |
10008 | install_element(OSPF_NODE, &no_ospf_timers_min_ls_interval_cmd); | |
0e88de35 QY |
10009 | install_element(OSPF_NODE, &ospf_timers_lsa_min_arrival_cmd); |
10010 | install_element(OSPF_NODE, &no_ospf_timers_lsa_min_arrival_cmd); | |
10011 | install_element(OSPF_NODE, &ospf_timers_lsa_arrival_cmd); | |
10012 | install_element(OSPF_NODE, &no_ospf_timers_lsa_arrival_cmd); | |
d62a17ae | 10013 | |
10014 | /* refresh timer commands */ | |
10015 | install_element(OSPF_NODE, &ospf_refresh_timer_cmd); | |
10016 | install_element(OSPF_NODE, &no_ospf_refresh_timer_val_cmd); | |
10017 | ||
10018 | /* max-metric commands */ | |
10019 | install_element(OSPF_NODE, &ospf_max_metric_router_lsa_admin_cmd); | |
10020 | install_element(OSPF_NODE, &no_ospf_max_metric_router_lsa_admin_cmd); | |
10021 | install_element(OSPF_NODE, &ospf_max_metric_router_lsa_startup_cmd); | |
10022 | install_element(OSPF_NODE, &no_ospf_max_metric_router_lsa_startup_cmd); | |
10023 | install_element(OSPF_NODE, &ospf_max_metric_router_lsa_shutdown_cmd); | |
10024 | install_element(OSPF_NODE, &no_ospf_max_metric_router_lsa_shutdown_cmd); | |
10025 | ||
10026 | /* reference bandwidth commands */ | |
10027 | install_element(OSPF_NODE, &ospf_auto_cost_reference_bandwidth_cmd); | |
10028 | install_element(OSPF_NODE, &no_ospf_auto_cost_reference_bandwidth_cmd); | |
10029 | ||
10030 | /* "neighbor" commands. */ | |
10031 | install_element(OSPF_NODE, &ospf_neighbor_cmd); | |
10032 | install_element(OSPF_NODE, &ospf_neighbor_poll_interval_cmd); | |
10033 | install_element(OSPF_NODE, &no_ospf_neighbor_cmd); | |
10034 | install_element(OSPF_NODE, &no_ospf_neighbor_poll_cmd); | |
10035 | ||
10036 | /* write multiplier commands */ | |
10037 | install_element(OSPF_NODE, &ospf_write_multiplier_cmd); | |
10038 | install_element(OSPF_NODE, &write_multiplier_cmd); | |
10039 | install_element(OSPF_NODE, &no_ospf_write_multiplier_cmd); | |
10040 | install_element(OSPF_NODE, &no_write_multiplier_cmd); | |
10041 | ||
10042 | /* Init interface related vty commands. */ | |
10043 | ospf_vty_if_init(); | |
10044 | ||
10045 | /* Init zebra related vty commands. */ | |
10046 | ospf_vty_zebra_init(); | |
718e3744 | 10047 | } |